vendor: 5,378 bytes, lines 1-187
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, idPrefix:writable */ 15/* exported locationHref, subframeEnabled, expressionsPlugin, idPrefix */ 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 idPrefix = ''; 35var expressionsPlugin; 36var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent); 37var cachedColors = {}; 38var bmRnd; 39var bmPow = Math.pow; 40var bmSqrt = Math.sqrt; 41var bmFloor = Math.floor; 42var bmMax = Math.max; 43var bmMin = Math.min; 44 45var BMMath = {}; 46(function () { 47 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']; 48 var i; 49 var len = propertyNames.length; 50 for (i = 0; i < len; i += 1) { 51 BMMath[propertyNames[i]] = Math[propertyNames[i]]; 52 } 53}()); 54 55function ProjectInterface() { return {}; } 56 57BMMath.random = Math.random; 58BMMath.abs = function (val) { 59 var tOfVal = typeof val; 60 if (tOfVal === 'object' && val.length) { 61 var absArr = createSizedArray(val.length); 62 var i; 63 var len = val.length; 64 for (i = 0; i < len; i += 1) { 65 absArr[i] = Math.abs(val[i]); 66 } 67 return absArr; 68 } 69 return Math.abs(val); 70}; 71var defaultCurveSegments = 150; 72var degToRads = Math.PI / 180; 73var roundCorner = 0.5519; 74 75function roundValues(flag) { 76 if (flag) { 77 bmRnd = Math.round; 78 } else { 79 bmRnd = function (val) { 80 return val; 81 }; 82 } 83} 84roundValues(false); 85 86function styleDiv(element) { 87 element.style.position = 'absolute'; 88 element.style.top = 0; 89 element.style.left = 0; 90 element.style.display = 'block'; 91 element.style.transformOrigin = '0 0'; 92 element.style.webkitTransformOrigin = '0 0'; 93 element.style.backfaceVisibility = 'visible'; 94 element.style.webkitBackfaceVisibility = 'visible'; 95 element.style.transformStyle = 'preserve-3d'; 96 element.style.webkitTransformStyle = 'preserve-3d'; 97 element.style.mozTransformStyle = 'preserve-3d'; 98} 99 100function BMEnterFrameEvent(type, currentTime, totalTime, frameMultiplier) { 101 this.type = type; 102 this.currentTime = currentTime; 103 this.totalTime = totalTime; 104 this.direction = frameMultiplier < 0 ? -1 : 1; 105} 106 107function BMCompleteEvent(type, frameMultiplier) { 108 this.type = type; 109 this.direction = frameMultiplier < 0 ? -1 : 1; 110} 111 112function BMCompleteLoopEvent(type, totalLoops, currentLoop, frameMultiplier) { 113 this.type = type; 114 this.currentLoop = currentLoop; 115 this.totalLoops = totalLoops; 116 this.direction = frameMultiplier < 0 ? -1 : 1; 117} 118 119function BMSegmentStartEvent(type, firstFrame, totalFrames) { 120 this.type = type; 121 this.firstFrame = firstFrame; 122 this.totalFrames = totalFrames; 123} 124 125function BMDestroyEvent(type, target) { 126 this.type = type; 127 this.target = target; 128} 129 130function BMRenderFrameErrorEvent(nativeError, currentTime) { 131 this.type = 'renderFrameError'; 132 this.nativeError = nativeError; 133 this.currentTime = currentTime; 134} 135 136function BMConfigErrorEvent(nativeError) { 137 this.type = 'configError'; 138 this.nativeError = nativeError; 139} 140 141function BMAnimationConfigErrorEvent(type, nativeError) { 142 this.type = type; 143 this.nativeError = nativeError; 144} 145 146var createElementID = (function () { 147 var _count = 0; 148 return function createID() { 149 _count += 1; 150 return idPrefix + '__lottie_element_' + _count; 151 }; 152}()); 153 154function HSVtoRGB(h, s, v) { 155 var r; 156 var g; 157 var b; 158 var i; 159 var f; 160 var p; 161 var q; 162 var t; 163 i = Math.floor(h * 6); 164 f = h * 6 - i; 165 p = v * (1 - s); 166 q = v * (1 - f * s); 167 t = v * (1 - (1 - f) * s); 168 switch (i % 6) { 169 case 0: r = v; g = t; b = p; break; 170 case 1: r = q; g = v; b = p; break; 171 case 2: r = p; g = v; b = t; break; 172 case 3: r = p; g = q; b = v; break; 173 case 4: r = t; g = p; b = v; break; 174 case 5: r = v; g = p; b = q; break; 175 default: break; 176 } 177 return [r, 178 g, 179 b]; 180} 181 182function RGBtoHSV(r, g, b) { 183 var max = Math.max(r, g, b); 184 var min = Math.min(r, g, b); 185 var d = max - min; 186 var h; 187 var s = (max === 0 ? 0 : d / max);
vendor: 4,233 bytes, lines 188-368
188 var v = max / 255; 189 190 switch (max) { 191 case min: h = 0; break; 192 case r: h = (g - b) + d * (g < b ? 6 : 0); h /= 6 * d; break; 193 case g: h = (b - r) + d * 2; h /= 6 * d; break; 194 case b: h = (r - g) + d * 4; h /= 6 * d; break; 195 default: break; 196 } 197 198 return [ 199 h, 200 s, 201 v, 202 ]; 203} 204 205function addSaturationToRGB(color, offset) { 206 var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255); 207 hsv[1] += offset; 208 if (hsv[1] > 1) { 209 hsv[1] = 1; 210 } else if (hsv[1] <= 0) { 211 hsv[1] = 0; 212 } 213 return HSVtoRGB(hsv[0], hsv[1], hsv[2]); 214} 215 216function addBrightnessToRGB(color, offset) { 217 var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255); 218 hsv[2] += offset; 219 if (hsv[2] > 1) { 220 hsv[2] = 1; 221 } else if (hsv[2] < 0) { 222 hsv[2] = 0; 223 } 224 return HSVtoRGB(hsv[0], hsv[1], hsv[2]); 225} 226 227function addHueToRGB(color, offset) { 228 var hsv = RGBtoHSV(color[0] * 255, color[1] * 255, color[2] * 255); 229 hsv[0] += offset / 360; 230 if (hsv[0] > 1) { 231 hsv[0] -= 1; 232 } else if (hsv[0] < 0) { 233 hsv[0] += 1; 234 } 235 return HSVtoRGB(hsv[0], hsv[1], hsv[2]); 236} 237 238var rgbToHex = (function () { 239 var colorMap = []; 240 var i; 241 var hex; 242 for (i = 0; i < 256; i += 1) { 243 hex = i.toString(16); 244 colorMap[i] = hex.length === 1 ? '0' + hex : hex; 245 } 246 247 return function (r, g, b) { 248 if (r < 0) { 249 r = 0; 250 } 251 if (g < 0) { 252 g = 0; 253 } 254 if (b < 0) { 255 b = 0; 256 } 257 return '#' + colorMap[r] + colorMap[g] + colorMap[b]; 258 }; 259}()); 260 261function BaseEvent() {} 262BaseEvent.prototype = { 263 triggerEvent: function (eventName, args) { 264 if (this._cbs[eventName]) { 265 var callbacks = this._cbs[eventName]; 266 for (var i = 0; i < callbacks.length; i += 1) { 267 callbacks[i](args); 268 } 269 } 270 }, 271 addEventListener: function (eventName, callback) { 272 if (!this._cbs[eventName]) { 273 this._cbs[eventName] = []; 274 } 275 this._cbs[eventName].push(callback); 276 277 return function () { 278 this.removeEventListener(eventName, callback); 279 }.bind(this); 280 }, 281 removeEventListener: function (eventName, callback) { 282 if (!callback) { 283 this._cbs[eventName] = null; 284 } else if (this._cbs[eventName]) { 285 var i = 0; 286 var len = this._cbs[eventName].length; 287 while (i < len) { 288 if (this._cbs[eventName][i] === callback) { 289 this._cbs[eventName].splice(i, 1); 290 i -= 1; 291 len -= 1; 292 } 293 i += 1; 294 } 295 if (!this._cbs[eventName].length) { 296 this._cbs[eventName] = null; 297 } 298 } 299 }, 300}; 301 302/* exported createTypedArray, createSizedArray */ 303 304var createTypedArray = (function () { 305 function createRegularArray(type, len) { 306 var i = 0; 307 var arr = []; 308 var value; 309 switch (type) { 310 case 'int16': 311 case 'uint8c': 312 value = 1; 313 break; 314 default: 315 value = 1.1; 316 break; 317 } 318 for (i = 0; i < len; i += 1) { 319 arr.push(value); 320 } 321 return arr; 322 } 323 function createTypedArrayFactory(type, len) { 324 if (type === 'float32') { 325 return new Float32Array(len); 326 } if (type === 'int16') { 327 return new Int16Array(len); 328 } if (type === 'uint8c') { 329 return new Uint8ClampedArray(len); 330 } 331 return createRegularArray(type, len); 332 } 333 if (typeof Uint8ClampedArray === 'function' && typeof Float32Array === 'function') { 334 return createTypedArrayFactory; 335 } 336 return createRegularArray; 337}()); 338 339function createSizedArray(len) { 340 return Array.apply(null, { length: len }); 341} 342 343/* global svgNS */ 344/* exported createNS */ 345 346function createNS(type) { 347 // return {appendChild:function(){},setAttribute:function(){},style:{}} 348 return document.createElementNS(svgNS, type); 349} 350 351/* exported createTag */ 352 353function createTag(type) { 354 // return {appendChild:function(){},setAttribute:function(){},style:{}} 355 return document.createElement(type); 356} 357 358function DynamicPropertyContainer() {} 359DynamicPropertyContainer.prototype = { 360 addDynamicProperty: function (prop) { 361 if (this.dynamicProperties.indexOf(prop) === -1) { 362 this.dynamicProperties.push(prop); 363 this.container.addDynamicProperty(this); 364 this._isAnimated = true; 365 } 366 }, 367 iterateDynamicProperties: function () { 368 this._mdf = false;
vendor: 11,688 bytes, lines 369-791
369 var i; 370 var len = this.dynamicProperties.length; 371 for (i = 0; i < len; i += 1) { 372 this.dynamicProperties[i].getValue(); 373 if (this.dynamicProperties[i]._mdf) { 374 this._mdf = true; 375 } 376 } 377 }, 378 initDynamicPropertyContainer: function (container) { 379 this.container = container; 380 this.dynamicProperties = []; 381 this._mdf = false; 382 this._isAnimated = false; 383 }, 384}; 385 386/* exported getBlendMode */ 387 388var getBlendMode = (function () { 389 var blendModeEnums = { 390 0: 'source-over', 391 1: 'multiply', 392 2: 'screen', 393 3: 'overlay', 394 4: 'darken', 395 5: 'lighten', 396 6: 'color-dodge', 397 7: 'color-burn', 398 8: 'hard-light', 399 9: 'soft-light', 400 10: 'difference', 401 11: 'exclusion', 402 12: 'hue', 403 13: 'saturation', 404 14: 'color', 405 15: 'luminosity', 406 }; 407 408 return function (mode) { 409 return blendModeEnums[mode] || ''; 410 }; 411}()); 412 413/* exported lineCapEnum, lineJoinEnum */ 414 415var lineCapEnum = { 416 1: 'butt', 417 2: 'round', 418 3: 'square', 419}; 420 421var lineJoinEnum = { 422 1: 'miter', 423 2: 'round', 424 3: 'bevel', 425}; 426 427/* global createTypedArray */ 428 429/*! 430 Transformation Matrix v2.0 431 (c) Epistemex 2014-2015 432 www.epistemex.com 433 By Ken Fyrstenberg 434 Contributions by leeoniya. 435 License: MIT, header required. 436 */ 437 438/** 439 * 2D transformation matrix object initialized with identity matrix. 440 * 441 * The matrix can synchronize a canvas context by supplying the context 442 * as an argument, or later apply current absolute transform to an 443 * existing context. 444 * 445 * All values are handled as floating point values. 446 * 447 * @param {CanvasRenderingContext2D} [context] - Optional context to sync with Matrix 448 * @prop {number} a - scale x 449 * @prop {number} b - shear y 450 * @prop {number} c - shear x 451 * @prop {number} d - scale y 452 * @prop {number} e - translate x 453 * @prop {number} f - translate y 454 * @prop {CanvasRenderingContext2D|null} [context=null] - set or get current canvas context 455 * @constructor 456 */ 457 458var Matrix = (function () { 459 var _cos = Math.cos; 460 var _sin = Math.sin; 461 var _tan = Math.tan; 462 var _rnd = Math.round; 463 464 function reset() { 465 this.props[0] = 1; 466 this.props[1] = 0; 467 this.props[2] = 0; 468 this.props[3] = 0; 469 this.props[4] = 0; 470 this.props[5] = 1; 471 this.props[6] = 0; 472 this.props[7] = 0; 473 this.props[8] = 0; 474 this.props[9] = 0; 475 this.props[10] = 1; 476 this.props[11] = 0; 477 this.props[12] = 0; 478 this.props[13] = 0; 479 this.props[14] = 0; 480 this.props[15] = 1; 481 return this; 482 } 483 484 function rotate(angle) { 485 if (angle === 0) { 486 return this; 487 } 488 var mCos = _cos(angle); 489 var mSin = _sin(angle); 490 return this._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); 491 } 492 493 function rotateX(angle) { 494 if (angle === 0) { 495 return this; 496 } 497 var mCos = _cos(angle); 498 var mSin = _sin(angle); 499 return this._t(1, 0, 0, 0, 0, mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1); 500 } 501 502 function rotateY(angle) { 503 if (angle === 0) { 504 return this; 505 } 506 var mCos = _cos(angle); 507 var mSin = _sin(angle); 508 return this._t(mCos, 0, mSin, 0, 0, 1, 0, 0, -mSin, 0, mCos, 0, 0, 0, 0, 1); 509 } 510 511 function rotateZ(angle) { 512 if (angle === 0) { 513 return this; 514 } 515 var mCos = _cos(angle); 516 var mSin = _sin(angle); 517 return this._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); 518 } 519 520 function shear(sx, sy) { 521 return this._t(1, sy, sx, 1, 0, 0); 522 } 523 524 function skew(ax, ay) { 525 return this.shear(_tan(ax), _tan(ay)); 526 } 527 528 function skewFromAxis(ax, angle) { 529 var mCos = _cos(angle); 530 var mSin = _sin(angle); 531 return this._t(mCos, mSin, 0, 0, -mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1) 532 ._t(1, 0, 0, 0, _tan(ax), 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1) 533 ._t(mCos, -mSin, 0, 0, mSin, mCos, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); 534 // return this._t(mCos, mSin, -mSin, mCos, 0, 0)._t(1, 0, _tan(ax), 1, 0, 0)._t(mCos, -mSin, mSin, mCos, 0, 0); 535 } 536 537 function scale(sx, sy, sz) { 538 if (!sz && sz !== 0) { 539 sz = 1; 540 } 541 if (sx === 1 && sy === 1 && sz === 1) { 542 return this; 543 } 544 return this._t(sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, sz, 0, 0, 0, 0, 1); 545 } 546 547 function setTransform(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) { 548 this.props[0] = a; 549 this.props[1] = b; 550 this.props[2] = c; 551 this.props[3] = d; 552 this.props[4] = e; 553 this.props[5] = f; 554 this.props[6] = g; 555 this.props[7] = h; 556 this.props[8] = i; 557 this.props[9] = j; 558 this.props[10] = k; 559 this.props[11] = l; 560 this.props[12] = m; 561 this.props[13] = n; 562 this.props[14] = o; 563 this.props[15] = p; 564 return this; 565 } 566 567 function translate(tx, ty, tz) { 568 tz = tz || 0; 569 if (tx !== 0 || ty !== 0 || tz !== 0) { 570 return this._t(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, tx, ty, tz, 1); 571 } 572 return this; 573 } 574 575 function transform(a2, b2, c2, d2, e2, f2, g2, h2, i2, j2, k2, l2, m2, n2, o2, p2) { 576 var _p = this.props; 577 578 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) { 579 // NOTE: commenting this condition because TurboFan deoptimizes code when present 580 // if(m2 !== 0 || n2 !== 0 || o2 !== 0){ 581 _p[12] = _p[12] * a2 + _p[15] * m2; 582 _p[13] = _p[13] * f2 + _p[15] * n2; 583 _p[14] = _p[14] * k2 + _p[15] * o2; 584 _p[15] *= p2; 585 // } 586 this._identityCalculated = false; 587 return this; 588 } 589 590 var a1 = _p[0]; 591 var b1 = _p[1]; 592 var c1 = _p[2]; 593 var d1 = _p[3]; 594 var e1 = _p[4]; 595 var f1 = _p[5]; 596 var g1 = _p[6]; 597 var h1 = _p[7]; 598 var i1 = _p[8]; 599 var j1 = _p[9]; 600 var k1 = _p[10]; 601 var l1 = _p[11]; 602 var m1 = _p[12]; 603 var n1 = _p[13]; 604 var o1 = _p[14]; 605 var p1 = _p[15]; 606 607 /* matrix order (canvas compatible): 608 * ace 609 * bdf 610 * 001 611 */ 612 _p[0] = a1 * a2 + b1 * e2 + c1 * i2 + d1 * m2; 613 _p[1] = a1 * b2 + b1 * f2 + c1 * j2 + d1 * n2; 614 _p[2] = a1 * c2 + b1 * g2 + c1 * k2 + d1 * o2; 615 _p[3] = a1 * d2 + b1 * h2 + c1 * l2 + d1 * p2; 616 617 _p[4] = e1 * a2 + f1 * e2 + g1 * i2 + h1 * m2; 618 _p[5] = e1 * b2 + f1 * f2 + g1 * j2 + h1 * n2; 619 _p[6] = e1 * c2 + f1 * g2 + g1 * k2 + h1 * o2; 620 _p[7] = e1 * d2 + f1 * h2 + g1 * l2 + h1 * p2; 621 622 _p[8] = i1 * a2 + j1 * e2 + k1 * i2 + l1 * m2; 623 _p[9] = i1 * b2 + j1 * f2 + k1 * j2 + l1 * n2; 624 _p[10] = i1 * c2 + j1 * g2 + k1 * k2 + l1 * o2; 625 _p[11] = i1 * d2 + j1 * h2 + k1 * l2 + l1 * p2; 626 627 _p[12] = m1 * a2 + n1 * e2 + o1 * i2 + p1 * m2; 628 _p[13] = m1 * b2 + n1 * f2 + o1 * j2 + p1 * n2; 629 _p[14] = m1 * c2 + n1 * g2 + o1 * k2 + p1 * o2; 630 _p[15] = m1 * d2 + n1 * h2 + o1 * l2 + p1 * p2; 631 632 this._identityCalculated = false; 633 return this; 634 } 635 636 function isIdentity() { 637 if (!this._identityCalculated) { 638 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); 639 this._identityCalculated = true; 640 } 641 return this._identity; 642 } 643 644 function equals(matr) { 645 var i = 0; 646 while (i < 16) { 647 if (matr.props[i] !== this.props[i]) { 648 return false; 649 } 650 i += 1; 651 } 652 return true; 653 } 654 655 function clone(matr) { 656 var i; 657 for (i = 0; i < 16; i += 1) { 658 matr.props[i] = this.props[i]; 659 } 660 return matr; 661 } 662 663 function cloneFromProps(props) { 664 var i; 665 for (i = 0; i < 16; i += 1) { 666 this.props[i] = props[i]; 667 } 668 } 669 670 function applyToPoint(x, y, z) { 671 return { 672 x: x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12], 673 y: x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13], 674 z: x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14], 675 }; 676 /* return { 677 x: x * me.a + y * me.c + me.e, 678 y: x * me.b + y * me.d + me.f 679 }; */ 680 } 681 function applyToX(x, y, z) { 682 return x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12]; 683 } 684 function applyToY(x, y, z) { 685 return x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13]; 686 } 687 function applyToZ(x, y, z) { 688 return x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14]; 689 } 690 691 function getInverseMatrix() { 692 var determinant = this.props[0] * this.props[5] - this.props[1] * this.props[4]; 693 var a = this.props[5] / determinant; 694 var b = -this.props[1] / determinant; 695 var c = -this.props[4] / determinant; 696 var d = this.props[0] / determinant; 697 var e = (this.props[4] * this.props[13] - this.props[5] * this.props[12]) / determinant; 698 var f = -(this.props[0] * this.props[13] - this.props[1] * this.props[12]) / determinant; 699 var inverseMatrix = new Matrix(); 700 inverseMatrix.props[0] = a; 701 inverseMatrix.props[1] = b; 702 inverseMatrix.props[4] = c; 703 inverseMatrix.props[5] = d; 704 inverseMatrix.props[12] = e; 705 inverseMatrix.props[13] = f; 706 return inverseMatrix; 707 } 708 709 function inversePoint(pt) { 710 var inverseMatrix = this.getInverseMatrix(); 711 return inverseMatrix.applyToPointArray(pt[0], pt[1], pt[2] || 0); 712 } 713 714 function inversePoints(pts) { 715 var i; 716 var len = pts.length; 717 var retPts = []; 718 for (i = 0; i < len; i += 1) { 719 retPts[i] = inversePoint(pts[i]); 720 } 721 return retPts; 722 } 723 724 function applyToTriplePoints(pt1, pt2, pt3) { 725 var arr = createTypedArray('float32', 6); 726 if (this.isIdentity()) { 727 arr[0] = pt1[0]; 728 arr[1] = pt1[1]; 729 arr[2] = pt2[0]; 730 arr[3] = pt2[1]; 731 arr[4] = pt3[0]; 732 arr[5] = pt3[1]; 733 } else { 734 var p0 = this.props[0]; 735 var p1 = this.props[1]; 736 var p4 = this.props[4]; 737 var p5 = this.props[5]; 738 var p12 = this.props[12]; 739 var p13 = this.props[13]; 740 arr[0] = pt1[0] * p0 + pt1[1] * p4 + p12; 741 arr[1] = pt1[0] * p1 + pt1[1] * p5 + p13; 742 arr[2] = pt2[0] * p0 + pt2[1] * p4 + p12; 743 arr[3] = pt2[0] * p1 + pt2[1] * p5 + p13; 744 arr[4] = pt3[0] * p0 + pt3[1] * p4 + p12; 745 arr[5] = pt3[0] * p1 + pt3[1] * p5 + p13; 746 } 747 return arr; 748 } 749 750 function applyToPointArray(x, y, z) { 751 var arr; 752 if (this.isIdentity()) { 753 arr = [x, y, z]; 754 } else { 755 arr = [ 756 x * this.props[0] + y * this.props[4] + z * this.props[8] + this.props[12], 757 x * this.props[1] + y * this.props[5] + z * this.props[9] + this.props[13], 758 x * this.props[2] + y * this.props[6] + z * this.props[10] + this.props[14], 759 ]; 760 } 761 return arr; 762 } 763 764 function applyToPointStringified(x, y) { 765 if (this.isIdentity()) { 766 return x + ',' + y; 767 } 768 var _p = this.props; 769 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; 770 } 771 772 function toCSS() { 773 // 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. 774 /* if(this.isIdentity()) { 775 return ''; 776 } */ 777 var i = 0; 778 var props = this.props; 779 var cssValue = 'matrix3d('; 780 var v = 10000; 781 while (i < 16) { 782 cssValue += _rnd(props[i] * v) / v; 783 cssValue += i === 15 ? ')' : ','; 784 i += 1; 785 } 786 return cssValue; 787 } 788 789 function roundMatrixProperty(val) { 790 var v = 10000; 791 if ((val < 0.000001 && val > 0) || (val > -0.000001 && val < 0)) {
792 return _rnd(val * v) / v; 793 } 794 return val; 795 } 796 797 function to2dCSS() { 798 // 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. 799 /* if(this.isIdentity()) { 800 return ''; 801 } */ 802 var props = this.props; 803 var _a = roundMatrixProperty(props[0]); 804 var _b = roundMatrixProperty(props[1]); 805 var _c = roundMatrixProperty(props[4]); 806 var _d = roundMatrixProperty(props[5]); 807 var _e = roundMatrixProperty(props[12]); 808 var _f = roundMatrixProperty(props[13]); 809 return 'matrix(' + _a + ',' + _b + ',' + _c + ',' + _d + ',' + _e + ',' + _f + ')'; 810 } 811 812 return function () { 813 this.reset = reset; 814 this.rotate = rotate; 815 this.rotateX = rotateX; 816 this.rotateY = rotateY; 817 this.rotateZ = rotateZ; 818 this.skew = skew; 819 this.skewFromAxis = skewFromAxis; 820 this.shear = shear; 821 this.scale = scale; 822 this.setTransform = setTransform; 823 this.translate = translate; 824 this.transform = transform; 825 this.applyToPoint = applyToPoint; 826 this.applyToX = applyToX; 827 this.applyToY = applyToY; 828 this.applyToZ = applyToZ; 829 this.applyToPointArray = applyToPointArray; 830 this.applyToTriplePoints = applyToTriplePoints; 831 this.applyToPointStringified = applyToPointStringified; 832 this.toCSS = toCSS; 833 this.to2dCSS = to2dCSS; 834 this.clone = clone; 835 this.cloneFromProps = cloneFromProps; 836 this.equals = equals; 837 this.inversePoints = inversePoints; 838 this.inversePoint = inversePoint; 839 this.getInverseMatrix = getInverseMatrix; 840 this._t = this.transform; 841 this.isIdentity = isIdentity; 842 this._identity = true; 843 this._identityCalculated = false; 844 845 this.props = createTypedArray('float32', 16); 846 this.reset(); 847 }; 848}()); 849 850/* eslint-disable */ 851/* 852 Copyright 2014 David Bau. 853 854 Permission is hereby granted, free of charge, to any person obtaining 855 a copy of this software and associated documentation files (the 856 "Software"), to deal in the Software without restriction, including 857 without limitation the rights to use, copy, modify, merge, publish, 858 distribute, sublicense, and/or sell copies of the Software, and to 859 permit persons to whom the Software is furnished to do so, subject to 860 the following conditions: 861 862 The above copyright notice and this permission notice shall be 863 included in all copies or substantial portions of the Software. 864 865 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 866 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 867 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 868 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 869 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 870 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 871 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 872 873 */ 874 875(function
vendor: 7,580 bytes, lines 875-1080
875(pool, math) { 876// 877// The following constants are related to IEEE 754 limits. 878// 879 var global = this, 880 width = 256, // each RC4 output is 0 <= x < 256 881 chunks = 6, // at least six RC4 outputs for each double 882 digits = 52, // there are 52 significant digits in a double 883 rngname = 'random', // rngname: name for Math.random and Math.seedrandom 884 startdenom = math.pow(width, chunks), 885 significance = math.pow(2, digits), 886 overflow = significance * 2, 887 mask = width - 1, 888 nodecrypto; // node.js crypto module, initialized at the bottom. 889 890// 891// seedrandom() 892// This is the seedrandom function described above. 893// 894 function seedrandom(seed, options, callback) { 895 var key = []; 896 options = (options === true) ? { entropy: true } : (options || {}); 897 898 // Flatten the seed string or build one from local entropy if needed. 899 var shortseed = mixkey(flatten( 900 options.entropy ? [seed, tostring(pool)] : 901 (seed === null) ? autoseed() : seed, 3), key); 902 903 // Use the seed to initialize an ARC4 generator. 904 var arc4 = new ARC4(key); 905 906 // This function returns a random double in [0, 1) that contains 907 // randomness in every bit of the mantissa of the IEEE 754 value. 908 var prng = function() { 909 var n = arc4.g(chunks), // Start with a numerator n < 2 ^ 48 910 d = startdenom, // and denominator d = 2 ^ 48. 911 x = 0; // and no 'extra last byte'. 912 while (n < significance) { // Fill up all significant digits by 913 n = (n + x) * width; // shifting numerator and 914 d *= width; // denominator and generating a 915 x = arc4.g(1); // new least-significant-byte. 916 } 917 while (n >= overflow) { // To avoid rounding up, before adding 918 n /= 2; // last byte, shift everything 919 d /= 2; // right using integer math until 920 x >>>= 1; // we have exactly the desired bits. 921 } 922 return (n + x) / d; // Form the number within [0, 1). 923 }; 924 925 prng.int32 = function() { return arc4.g(4) | 0; }; 926 prng.quick = function() { return arc4.g(4) / 0x100000000; }; 927 prng.double = prng; 928 929 // Mix the randomness into accumulated entropy. 930 mixkey(tostring(arc4.S), pool); 931 932 // Calling convention: what to return as a function of prng, seed, is_math. 933 return (options.pass || callback || 934 function(prng, seed, is_math_call, state) { 935 if (state) { 936 // Load the arc4 state from the given state if it has an S array. 937 if (state.S) { copy(state, arc4); } 938 // Only provide the .state method if requested via options.state. 939 prng.state = function() { return copy(arc4, {}); }; 940 } 941 942 // If called as a method of Math (Math.seedrandom()), mutate 943 // Math.random because that is how seedrandom.js has worked since v1.0. 944 if (is_math_call) { math[rngname] = prng; return seed; } 945 946 // Otherwise, it is a newer calling convention, so return the 947 // prng directly. 948 else return prng; 949 })( 950 prng, 951 shortseed, 952 'global' in options ? options.global : (this == math), 953 options.state); 954 } 955 math['seed' + rngname] = seedrandom; 956 957// 958// ARC4 959// 960// An ARC4 implementation. The constructor takes a key in the form of 961// an array of at most (width) integers that should be 0 <= x < (width). 962// 963// The g(count) method returns a pseudorandom integer that concatenates 964// the next (count) outputs from ARC4. Its return value is a number x 965// that is in the range 0 <= x < (width ^ count). 966// 967 function ARC4(key) { 968 var t, keylen = key.length, 969 me = this, i = 0, j = me.i = me.j = 0, s = me.S = []; 970 971 // The empty key [] is treated as [0]. 972 if (!keylen) { key = [keylen++]; } 973 974 // Set up S using the standard key scheduling algorithm. 975 while (i < width) { 976 s[i] = i++; 977 } 978 for (i = 0; i < width; i++) { 979 s[i] = s[j = mask & (j + key[i % keylen] + (t = s[i]))]; 980 s[j] = t; 981 } 982 983 // The "g" method returns the next (count) outputs as one number. 984 me.g = function(count) { 985 // Using instance members instead of closure state nearly doubles speed. 986 var t, r = 0, 987 i = me.i, j = me.j, s = me.S; 988 while (count--) { 989 t = s[i = mask & (i + 1)]; 990 r = r * width + s[mask & ((s[i] = s[j = mask & (j + t)]) + (s[j] = t))]; 991 } 992 me.i = i; me.j = j; 993 return r; 994 // For robust unpredictability, the function call below automatically 995 // discards an initial batch of values. This is called RC4-drop[256]. 996 // See http://google.com/search?q=rsa+fluhrer+response&btnI 997 }; 998 } 999 1000// 1001// copy() 1002// Copies internal state of ARC4 to or from a plain object. 1003// 1004 function copy(f, t) { 1005 t.i = f.i; 1006 t.j = f.j; 1007 t.S = f.S.slice(); 1008 return t; 1009 } 1010 1011// 1012// flatten() 1013// Converts an object tree to nested arrays of strings. 1014// 1015 function flatten(obj, depth) { 1016 var result = [], typ = (typeof obj), prop; 1017 if (depth && typ == 'object') { 1018 for (prop in obj) { 1019 try { result.push(flatten(obj[prop], depth - 1)); } catch (e) {} 1020 } 1021 } 1022 return (result.length ? result : typ == 'string' ? obj : obj + '\0'); 1023 } 1024 1025// 1026// mixkey() 1027// Mixes a string seed into a key that is an array of integers, and 1028// returns a shortened string seed that is equivalent to the result key. 1029// 1030 function mixkey(seed, key) { 1031 var stringseed = seed + '', smear, j = 0; 1032 while (j < stringseed.length) { 1033 key[mask & j] = 1034 mask & ((smear ^= key[mask & j] * 19) + stringseed.charCodeAt(j++)); 1035 } 1036 return tostring(key); 1037 } 1038 1039// 1040// autoseed() 1041// Returns an object for autoseeding, using window.crypto and Node crypto 1042// module if available. 1043// 1044 function autoseed() { 1045 try { 1046 if (nodecrypto) { return tostring(nodecrypto.randomBytes(width)); } 1047 var out = new Uint8Array(width); 1048 (global.crypto || global.msCrypto).getRandomValues(out); 1049 return tostring(out); 1050 } catch (e) { 1051 var browser = global.navigator, 1052 plugins = browser && browser.plugins; 1053 return [+new Date(), global, plugins, global.screen, tostring(pool)]; 1054 } 1055 } 1056 1057// 1058// tostring() 1059// Converts an array of charcodes to a string 1060// 1061 function tostring(a) { 1062 return String.fromCharCode.apply(0, a); 1063 } 1064 1065// 1066// When seedrandom.js is loaded, we immediately mix a few bits 1067// from the built-in RNG into the entropy pool. Because we do 1068// not want to interfere with deterministic PRNG state later, 1069// seedrandom will not call math.random on its own again after 1070// initialization. 1071// 1072 mixkey(math.random(), pool); 1073 1074// 1075// Nodejs and AMD support: export the implementation as a module using 1076// either convention. 1077// 1078 1079// End anonymous scope, and pass initial values. 1080}
vendor: 41,215 bytes, lines 1080-2368
1080)( 1081 [], // pool: entropy pool starts empty 1082 BMMath // math: package containing random, pow, and seedrandom 1083); 1084/* eslint-disable */ 1085var BezierFactory = (function () { 1086 /** 1087 * BezierEasing - use bezier curve for transition easing function 1088 * by Gaëtan Renaudeau 2014 - 2015 – MIT License 1089 * 1090 * Credits: is based on Firefox's nsSMILKeySpline.cpp 1091 * Usage: 1092 * var spline = BezierEasing([ 0.25, 0.1, 0.25, 1.0 ]) 1093 * spline.get(x) => returns the easing value | x must be in [0, 1] range 1094 * 1095 */ 1096 1097 var ob = {}; 1098 ob.getBezierEasing = getBezierEasing; 1099 var beziers = {}; 1100 1101 function getBezierEasing(a, b, c, d, nm) { 1102 var str = nm || ('bez_' + a + '_' + b + '_' + c + '_' + d).replace(/\./g, 'p'); 1103 if (beziers[str]) { 1104 return beziers[str]; 1105 } 1106 var bezEasing = new BezierEasing([a, b, c, d]); 1107 beziers[str] = bezEasing; 1108 return bezEasing; 1109 } 1110 1111 // These values are established by empiricism with tests (tradeoff: performance VS precision) 1112 var NEWTON_ITERATIONS = 4; 1113 var NEWTON_MIN_SLOPE = 0.001; 1114 var SUBDIVISION_PRECISION = 0.0000001; 1115 var SUBDIVISION_MAX_ITERATIONS = 10; 1116 1117 var kSplineTableSize = 11; 1118 var kSampleStepSize = 1.0 / (kSplineTableSize - 1.0); 1119 1120 var float32ArraySupported = typeof Float32Array === 'function'; 1121 1122 function A(aA1, aA2) { return 1.0 - 3.0 * aA2 + 3.0 * aA1; } 1123 function B(aA1, aA2) { return 3.0 * aA2 - 6.0 * aA1; } 1124 function C(aA1) { return 3.0 * aA1; } 1125 1126 // Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2. 1127 function calcBezier(aT, aA1, aA2) { 1128 return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT; 1129 } 1130 1131 // Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2. 1132 function getSlope(aT, aA1, aA2) { 1133 return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1); 1134 } 1135 1136 function binarySubdivide(aX, aA, aB, mX1, mX2) { 1137 var currentX, 1138 currentT, 1139 i = 0; 1140 do { 1141 currentT = aA + (aB - aA) / 2.0; 1142 currentX = calcBezier(currentT, mX1, mX2) - aX; 1143 if (currentX > 0.0) { 1144 aB = currentT; 1145 } else { 1146 aA = currentT; 1147 } 1148 } while (Math.abs(currentX) > SUBDIVISION_PRECISION && ++i < SUBDIVISION_MAX_ITERATIONS); 1149 return currentT; 1150 } 1151 1152 function newtonRaphsonIterate(aX, aGuessT, mX1, mX2) { 1153 for (var i = 0; i < NEWTON_ITERATIONS; ++i) { 1154 var currentSlope = getSlope(aGuessT, mX1, mX2); 1155 if (currentSlope === 0.0) return aGuessT; 1156 var currentX = calcBezier(aGuessT, mX1, mX2) - aX; 1157 aGuessT -= currentX / currentSlope; 1158 } 1159 return aGuessT; 1160 } 1161 1162 /** 1163 * points is an array of [ mX1, mY1, mX2, mY2 ] 1164 */ 1165 function BezierEasing(points) { 1166 this._p = points; 1167 this._mSampleValues = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize); 1168 this._precomputed = false; 1169 1170 this.get = this.get.bind(this); 1171 } 1172 1173 BezierEasing.prototype = { 1174 1175 get: function (x) { 1176 var mX1 = this._p[0], 1177 mY1 = this._p[1], 1178 mX2 = this._p[2], 1179 mY2 = this._p[3]; 1180 if (!this._precomputed) this._precompute(); 1181 if (mX1 === mY1 && mX2 === mY2) return x; // linear 1182 // Because JavaScript number are imprecise, we should guarantee the extremes are right. 1183 if (x === 0) return 0; 1184 if (x === 1) return 1; 1185 return calcBezier(this._getTForX(x), mY1, mY2); 1186 }, 1187 1188 // Private part 1189 1190 _precompute: function () { 1191 var mX1 = this._p[0], 1192 mY1 = this._p[1], 1193 mX2 = this._p[2], 1194 mY2 = this._p[3]; 1195 this._precomputed = true; 1196 if (mX1 !== mY1 || mX2 !== mY2) { this._calcSampleValues(); } 1197 }, 1198 1199 _calcSampleValues: function () { 1200 var mX1 = this._p[0], 1201 mX2 = this._p[2]; 1202 for (var i = 0; i < kSplineTableSize; ++i) { 1203 this._mSampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2); 1204 } 1205 }, 1206 1207 /** 1208 * getTForX chose the fastest heuristic to determine the percentage value precisely from a given X projection. 1209 */ 1210 _getTForX: function (aX) { 1211 var mX1 = this._p[0], 1212 mX2 = this._p[2], 1213 mSampleValues = this._mSampleValues; 1214 1215 var intervalStart = 0.0; 1216 var currentSample = 1; 1217 var lastSample = kSplineTableSize - 1; 1218 1219 for (; currentSample !== lastSample && mSampleValues[currentSample] <= aX; ++currentSample) { 1220 intervalStart += kSampleStepSize; 1221 } 1222 --currentSample; 1223 1224 // Interpolate to provide an initial guess for t 1225 var dist = (aX - mSampleValues[currentSample]) / (mSampleValues[currentSample + 1] - mSampleValues[currentSample]); 1226 var guessForT = intervalStart + dist * kSampleStepSize; 1227 1228 var initialSlope = getSlope(guessForT, mX1, mX2); 1229 if (initialSlope >= NEWTON_MIN_SLOPE) { 1230 return newtonRaphsonIterate(aX, guessForT, mX1, mX2); 1231 } if (initialSlope === 0.0) { 1232 return guessForT; 1233 } 1234 return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize, mX1, mX2); 1235 }, 1236 }; 1237 1238 return ob; 1239}()); 1240 1241(function () { 1242 var lastTime = 0; 1243 var vendors = ['ms', 'moz', 'webkit', 'o']; 1244 for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { // eslint-disable-line no-plusplus 1245 window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame']; 1246 window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] || window[vendors[x] + 'CancelRequestAnimationFrame']; 1247 } 1248 if (!window.requestAnimationFrame) { 1249 window.requestAnimationFrame = function (callback) { 1250 var currTime = new Date().getTime(); 1251 var timeToCall = Math.max(0, 16 - (currTime - lastTime)); 1252 var id = setTimeout(function () { 1253 callback(currTime + timeToCall); 1254 }, 1255 timeToCall); 1256 lastTime = currTime + timeToCall; 1257 return id; 1258 }; 1259 } 1260 if (!window.cancelAnimationFrame) { 1261 window.cancelAnimationFrame = function (id) { 1262 clearTimeout(id); 1263 }; 1264 } 1265}()); 1266 1267/* exported extendPrototype, getDescriptor, createProxyFunction */ 1268 1269function extendPrototype(sources, destination) { 1270 var i; 1271 var len = sources.length; 1272 var sourcePrototype; 1273 for (i = 0; i < len; i += 1) { 1274 sourcePrototype = sources[i].prototype; 1275 for (var attr in sourcePrototype) { 1276 if (Object.prototype.hasOwnProperty.call(sourcePrototype, attr)) destination.prototype[attr] = sourcePrototype[attr]; 1277 } 1278 } 1279} 1280 1281function getDescriptor(object, prop) { 1282 return Object.getOwnPropertyDescriptor(object, prop); 1283} 1284 1285function createProxyFunction(prototype) { 1286 function ProxyFunction() {} 1287 ProxyFunction.prototype = prototype; 1288 return ProxyFunction; 1289} 1290 1291/* global segmentsLengthPool, defaultCurveSegments, createSizedArray, bmPow, bmSqrt, bmFloor, createTypedArray, bezierLengthPool */ 1292/* exported bez */ 1293 1294function bezFunction() { 1295 var math = Math; 1296 1297 function pointOnLine2D(x1, y1, x2, y2, x3, y3) { 1298 var det1 = (x1 * y2) + (y1 * x3) + (x2 * y3) - (x3 * y2) - (y3 * x1) - (x2 * y1); 1299 return det1 > -0.001 && det1 < 0.001; 1300 } 1301 1302 function pointOnLine3D(x1, y1, z1, x2, y2, z2, x3, y3, z3) { 1303 if (z1 === 0 && z2 === 0 && z3 === 0) { 1304 return pointOnLine2D(x1, y1, x2, y2, x3, y3); 1305 } 1306 var dist1 = math.sqrt(math.pow(x2 - x1, 2) + math.pow(y2 - y1, 2) + math.pow(z2 - z1, 2)); 1307 var dist2 = math.sqrt(math.pow(x3 - x1, 2) + math.pow(y3 - y1, 2) + math.pow(z3 - z1, 2)); 1308 var dist3 = math.sqrt(math.pow(x3 - x2, 2) + math.pow(y3 - y2, 2) + math.pow(z3 - z2, 2)); 1309 var diffDist; 1310 if (dist1 > dist2) { 1311 if (dist1 > dist3) { 1312 diffDist = dist1 - dist2 - dist3; 1313 } else { 1314 diffDist = dist3 - dist2 - dist1; 1315 } 1316 } else if (dist3 > dist2) { 1317 diffDist = dist3 - dist2 - dist1; 1318 } else { 1319 diffDist = dist2 - dist1 - dist3; 1320 } 1321 return diffDist > -0.0001 && diffDist < 0.0001; 1322 } 1323 1324 var getBezierLength = (function () { 1325 return function (pt1, pt2, pt3, pt4) { 1326 var curveSegments = defaultCurveSegments; 1327 var k; 1328 var i; 1329 var len; 1330 var ptCoord; 1331 var perc; 1332 var addedLength = 0; 1333 var ptDistance; 1334 var point = []; 1335 var lastPoint = []; 1336 var lengthData = bezierLengthPool.newElement(); 1337 len = pt3.length; 1338 for (k = 0; k < curveSegments; k += 1) { 1339 perc = k / (curveSegments - 1); 1340 ptDistance = 0; 1341 for (i = 0; i < len; i += 1) { 1342 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]; 1343 point[i] = ptCoord; 1344 if (lastPoint[i] !== null) { 1345 ptDistance += bmPow(point[i] - lastPoint[i], 2); 1346 } 1347 lastPoint[i] = point[i]; 1348 } 1349 if (ptDistance) { 1350 ptDistance = bmSqrt(ptDistance); 1351 addedLength += ptDistance; 1352 } 1353 lengthData.percents[k] = perc; 1354 lengthData.lengths[k] = addedLength; 1355 } 1356 lengthData.addedLength = addedLength; 1357 return lengthData; 1358 }; 1359 }()); 1360 1361 function getSegmentsLength(shapeData) { 1362 var segmentsLength = segmentsLengthPool.newElement(); 1363 var closed = shapeData.c; 1364 var pathV = shapeData.v; 1365 var pathO = shapeData.o; 1366 var pathI = shapeData.i; 1367 var i; 1368 var len = shapeData._length; 1369 var lengths = segmentsLength.lengths; 1370 var totalLength = 0; 1371 for (i = 0; i < len - 1; i += 1) { 1372 lengths[i] = getBezierLength(pathV[i], pathV[i + 1], pathO[i], pathI[i + 1]); 1373 totalLength += lengths[i].addedLength; 1374 } 1375 if (closed && len) { 1376 lengths[i] = getBezierLength(pathV[i], pathV[0], pathO[i], pathI[0]); 1377 totalLength += lengths[i].addedLength; 1378 } 1379 segmentsLength.totalLength = totalLength; 1380 return segmentsLength; 1381 } 1382 1383 function BezierData(length) { 1384 this.segmentLength = 0; 1385 this.points = new Array(length); 1386 } 1387 1388 function PointData(partial, point) { 1389 this.partialLength = partial; 1390 this.point = point; 1391 } 1392 1393 var buildBezierData = (function () { 1394 var storedData = {}; 1395 1396 return function (pt1, pt2, pt3, pt4) { 1397 var bezierName = (pt1[0] + '_' + pt1[1] + '_' + pt2[0] + '_' + pt2[1] + '_' + pt3[0] + '_' + pt3[1] + '_' + pt4[0] + '_' + pt4[1]).replace(/\./g, 'p'); 1398 if (!storedData[bezierName]) { 1399 var curveSegments = defaultCurveSegments; 1400 var k; 1401 var i; 1402 var len; 1403 var ptCoord; 1404 var perc; 1405 var addedLength = 0; 1406 var ptDistance; 1407 var point; 1408 var lastPoint = null; 1409 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])) { 1410 curveSegments = 2; 1411 } 1412 var bezierData = new BezierData(curveSegments); 1413 len = pt3.length; 1414 for (k = 0; k < curveSegments; k += 1) { 1415 point = createSizedArray(len); 1416 perc = k / (curveSegments - 1); 1417 ptDistance = 0; 1418 for (i = 0; i < len; i += 1) { 1419 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]; 1420 point[i] = ptCoord; 1421 if (lastPoint !== null) { 1422 ptDistance += bmPow(point[i] - lastPoint[i], 2); 1423 } 1424 } 1425 ptDistance = bmSqrt(ptDistance); 1426 addedLength += ptDistance; 1427 bezierData.points[k] = new PointData(ptDistance, point); 1428 lastPoint = point; 1429 } 1430 bezierData.segmentLength = addedLength; 1431 storedData[bezierName] = bezierData; 1432 } 1433 return storedData[bezierName]; 1434 }; 1435 }()); 1436 1437 function getDistancePerc(perc, bezierData) { 1438 var percents = bezierData.percents; 1439 var lengths = bezierData.lengths; 1440 var len = percents.length; 1441 var initPos = bmFloor((len - 1) * perc); 1442 var lengthPos = perc * bezierData.addedLength; 1443 var lPerc = 0; 1444 if (initPos === len - 1 || initPos === 0 || lengthPos === lengths[initPos]) { 1445 return percents[initPos]; 1446 } 1447 var dir = lengths[initPos] > lengthPos ? -1 : 1; 1448 var flag = true; 1449 while (flag) { 1450 if (lengths[initPos] <= lengthPos && lengths[initPos + 1] > lengthPos) { 1451 lPerc = (lengthPos - lengths[initPos]) / (lengths[initPos + 1] - lengths[initPos]); 1452 flag = false; 1453 } else { 1454 initPos += dir; 1455 } 1456 if (initPos < 0 || initPos >= len - 1) { 1457 // FIX for TypedArrays that don't store floating point values with enough accuracy 1458 if (initPos === len - 1) { 1459 return percents[initPos]; 1460 } 1461 flag = false; 1462 } 1463 } 1464 return percents[initPos] + (percents[initPos + 1] - percents[initPos]) * lPerc; 1465 } 1466 1467 function getPointInSegment(pt1, pt2, pt3, pt4, percent, bezierData) { 1468 var t1 = getDistancePerc(percent, bezierData); 1469 var u1 = 1 - t1; 1470 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; 1471 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; 1472 return [ptX, ptY]; 1473 } 1474 1475 var bezierSegmentPoints = createTypedArray('float32', 8); 1476 1477 function getNewSegment(pt1, pt2, pt3, pt4, startPerc, endPerc, bezierData) { 1478 if (startPerc < 0) { 1479 startPerc = 0; 1480 } else if (startPerc > 1) { 1481 startPerc = 1; 1482 } 1483 var t0 = getDistancePerc(startPerc, bezierData); 1484 endPerc = endPerc > 1 ? 1 : endPerc; 1485 var t1 = getDistancePerc(endPerc, bezierData); 1486 var i; 1487 var len = pt1.length; 1488 var u0 = 1 - t0; 1489 var u1 = 1 - t1; 1490 var u0u0u0 = u0 * u0 * u0; 1491 var t0u0u0_3 = t0 * u0 * u0 * 3; // eslint-disable-line camelcase 1492 var t0t0u0_3 = t0 * t0 * u0 * 3; // eslint-disable-line camelcase 1493 var t0t0t0 = t0 * t0 * t0; 1494 // 1495 var u0u0u1 = u0 * u0 * u1; 1496 var t0u0u1_3 = t0 * u0 * u1 + u0 * t0 * u1 + u0 * u0 * t1; // eslint-disable-line camelcase 1497 var t0t0u1_3 = t0 * t0 * u1 + u0 * t0 * t1 + t0 * u0 * t1; // eslint-disable-line camelcase 1498 var t0t0t1 = t0 * t0 * t1; 1499 // 1500 var u0u1u1 = u0 * u1 * u1; 1501 var t0u1u1_3 = t0 * u1 * u1 + u0 * t1 * u1 + u0 * u1 * t1; // eslint-disable-line camelcase 1502 var t0t1u1_3 = t0 * t1 * u1 + u0 * t1 * t1 + t0 * u1 * t1; // eslint-disable-line camelcase 1503 var t0t1t1 = t0 * t1 * t1; 1504 // 1505 var u1u1u1 = u1 * u1 * u1; 1506 var t1u1u1_3 = t1 * u1 * u1 + u1 * t1 * u1 + u1 * u1 * t1; // eslint-disable-line camelcase 1507 var t1t1u1_3 = t1 * t1 * u1 + u1 * t1 * t1 + t1 * u1 * t1; // eslint-disable-line camelcase 1508 var t1t1t1 = t1 * t1 * t1; 1509 for (i = 0; i < len; i += 1) { 1510 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 1511 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 1512 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 1513 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 1514 } 1515 1516 return bezierSegmentPoints; 1517 } 1518 1519 return { 1520 getSegmentsLength: getSegmentsLength, 1521 getNewSegment: getNewSegment, 1522 getPointInSegment: getPointInSegment, 1523 buildBezierData: buildBezierData, 1524 pointOnLine2D: pointOnLine2D, 1525 pointOnLine3D: pointOnLine3D, 1526 }; 1527} 1528 1529var bez = bezFunction(); 1530 1531/* exported dataManager */ 1532 1533function dataFunctionManager() { 1534 // var tCanvasHelper = createTag('canvas').getContext('2d'); 1535 1536 function completeLayers(layers, comps, fontManager) { 1537 var layerData; 1538 var i; 1539 var len = layers.length; 1540 var j; 1541 var jLen; 1542 var k; 1543 var kLen; 1544 for (i = 0; i < len; i += 1) { 1545 layerData = layers[i]; 1546 if (('ks' in layerData) && !layerData.completed) { 1547 layerData.completed = true; 1548 if (layerData.tt) { 1549 layers[i - 1].td = layerData.tt; 1550 } 1551 if (layerData.hasMask) { 1552 var maskProps = layerData.masksProperties; 1553 jLen = maskProps.length; 1554 for (j = 0; j < jLen; j += 1) { 1555 if (maskProps[j].pt.k.i) { 1556 convertPathsToAbsoluteValues(maskProps[j].pt.k); 1557 } else { 1558 kLen = maskProps[j].pt.k.length; 1559 for (k = 0; k < kLen; k += 1) { 1560 if (maskProps[j].pt.k[k].s) { 1561 convertPathsToAbsoluteValues(maskProps[j].pt.k[k].s[0]); 1562 } 1563 if (maskProps[j].pt.k[k].e) { 1564 convertPathsToAbsoluteValues(maskProps[j].pt.k[k].e[0]); 1565 } 1566 } 1567 } 1568 } 1569 } 1570 if (layerData.ty === 0) { 1571 layerData.layers = findCompLayers(layerData.refId, comps); 1572 completeLayers(layerData.layers, comps, fontManager); 1573 } else if (layerData.ty === 4) { 1574 completeShapes(layerData.shapes); 1575 } else if (layerData.ty === 5) { 1576 completeText(layerData, fontManager); 1577 } 1578 } 1579 } 1580 } 1581 1582 function findCompLayers(id, comps) { 1583 var i = 0; 1584 var len = comps.length; 1585 while (i < len) { 1586 if (comps[i].id === id) { 1587 if (!comps[i].layers.__used) { 1588 comps[i].layers.__used = true; 1589 return comps[i].layers; 1590 } 1591 return JSON.parse(JSON.stringify(comps[i].layers)); 1592 } 1593 i += 1; 1594 } 1595 return null; 1596 } 1597 1598 function completeShapes(arr) { 1599 var i; 1600 var len = arr.length; 1601 var j; 1602 var jLen; 1603 for (i = len - 1; i >= 0; i -= 1) { 1604 if (arr[i].ty === 'sh') { 1605 if (arr[i].ks.k.i) { 1606 convertPathsToAbsoluteValues(arr[i].ks.k); 1607 } else { 1608 jLen = arr[i].ks.k.length; 1609 for (j = 0; j < jLen; j += 1) { 1610 if (arr[i].ks.k[j].s) { 1611 convertPathsToAbsoluteValues(arr[i].ks.k[j].s[0]); 1612 } 1613 if (arr[i].ks.k[j].e) { 1614 convertPathsToAbsoluteValues(arr[i].ks.k[j].e[0]); 1615 } 1616 } 1617 } 1618 } else if (arr[i].ty === 'gr') { 1619 completeShapes(arr[i].it); 1620 } 1621 } 1622 } 1623 1624 function convertPathsToAbsoluteValues(path) { 1625 var i; 1626 var len = path.i.length; 1627 for (i = 0; i < len; i += 1) { 1628 path.i[i][0] += path.v[i][0]; 1629 path.i[i][1] += path.v[i][1]; 1630 path.o[i][0] += path.v[i][0]; 1631 path.o[i][1] += path.v[i][1]; 1632 } 1633 } 1634 1635 function checkVersion(minimum, animVersionString) { 1636 var animVersion = animVersionString ? animVersionString.split('.') : [100, 100, 100]; 1637 if (minimum[0] > animVersion[0]) { 1638 return true; 1639 } if (animVersion[0] > minimum[0]) { 1640 return false; 1641 } 1642 if (minimum[1] > animVersion[1]) { 1643 return true; 1644 } if (animVersion[1] > minimum[1]) { 1645 return false; 1646 } 1647 if (minimum[2] > animVersion[2]) { 1648 return true; 1649 } if (animVersion[2] > minimum[2]) { 1650 return false; 1651 } 1652 return null; 1653 } 1654 1655 var checkText = (function () { 1656 var minimumVersion = [4, 4, 14]; 1657 1658 function updateTextLayer(textLayer) { 1659 var documentData = textLayer.t.d; 1660 textLayer.t.d = { 1661 k: [ 1662 { 1663 s: documentData, 1664 t: 0, 1665 }, 1666 ], 1667 }; 1668 } 1669 1670 function iterateLayers(layers) { 1671 var i; 1672 var len = layers.length; 1673 for (i = 0; i < len; i += 1) { 1674 if (layers[i].ty === 5) { 1675 updateTextLayer(layers[i]); 1676 } 1677 } 1678 } 1679 1680 return function (animationData) { 1681 if (checkVersion(minimumVersion, animationData.v)) { 1682 iterateLayers(animationData.layers); 1683 if (animationData.assets) { 1684 var i; 1685 var len = animationData.assets.length; 1686 for (i = 0; i < len; i += 1) { 1687 if (animationData.assets[i].layers) { 1688 iterateLayers(animationData.assets[i].layers); 1689 } 1690 } 1691 } 1692 } 1693 }; 1694 }()); 1695 1696 var checkChars = (function () { 1697 var minimumVersion = [4, 7, 99]; 1698 return function (animationData) { 1699 if (animationData.chars && !checkVersion(minimumVersion, animationData.v)) { 1700 var i; 1701 var len = animationData.chars.length; 1702 var j; 1703 var jLen; 1704 var pathData; 1705 var paths; 1706 for (i = 0; i < len; i += 1) { 1707 if (animationData.chars[i].data && animationData.chars[i].data.shapes) { 1708 paths = animationData.chars[i].data.shapes[0].it; 1709 jLen = paths.length; 1710 1711 for (j = 0; j < jLen; j += 1) { 1712 pathData = paths[j].ks.k; 1713 if (!pathData.__converted) { 1714 convertPathsToAbsoluteValues(paths[j].ks.k); 1715 pathData.__converted = true; 1716 } 1717 } 1718 } 1719 } 1720 } 1721 }; 1722 }()); 1723 1724 var checkColors = (function () { 1725 var minimumVersion = [4, 1, 9]; 1726 1727 function iterateShapes(shapes) { 1728 var i; 1729 var len = shapes.length; 1730 var j; 1731 var jLen; 1732 for (i = 0; i < len; i += 1) { 1733 if (shapes[i].ty === 'gr') { 1734 iterateShapes(shapes[i].it); 1735 } else if (shapes[i].ty === 'fl' || shapes[i].ty === 'st') { 1736 if (shapes[i].c.k && shapes[i].c.k[0].i) { 1737 jLen = shapes[i].c.k.length; 1738 for (j = 0; j < jLen; j += 1) { 1739 if (shapes[i].c.k[j].s) { 1740 shapes[i].c.k[j].s[0] /= 255; 1741 shapes[i].c.k[j].s[1] /= 255; 1742 shapes[i].c.k[j].s[2] /= 255; 1743 shapes[i].c.k[j].s[3] /= 255; 1744 } 1745 if (shapes[i].c.k[j].e) { 1746 shapes[i].c.k[j].e[0] /= 255; 1747 shapes[i].c.k[j].e[1] /= 255; 1748 shapes[i].c.k[j].e[2] /= 255; 1749 shapes[i].c.k[j].e[3] /= 255; 1750 } 1751 } 1752 } else { 1753 shapes[i].c.k[0] /= 255; 1754 shapes[i].c.k[1] /= 255; 1755 shapes[i].c.k[2] /= 255; 1756 shapes[i].c.k[3] /= 255; 1757 } 1758 } 1759 } 1760 } 1761 1762 function iterateLayers(layers) { 1763 var i; 1764 var len = layers.length; 1765 for (i = 0; i < len; i += 1) { 1766 if (layers[i].ty === 4) { 1767 iterateShapes(layers[i].shapes); 1768 } 1769 } 1770 } 1771 1772 return function (animationData) { 1773 if (checkVersion(minimumVersion, animationData.v)) { 1774 iterateLayers(animationData.layers); 1775 if (animationData.assets) { 1776 var i; 1777 var len = animationData.assets.length; 1778 for (i = 0; i < len; i += 1) { 1779 if (animationData.assets[i].layers) { 1780 iterateLayers(animationData.assets[i].layers); 1781 } 1782 } 1783 } 1784 } 1785 }; 1786 }()); 1787 1788 var checkShapes = (function () { 1789 var minimumVersion = [4, 4, 18]; 1790 1791 function completeClosingShapes(arr) { 1792 var i; 1793 var len = arr.length; 1794 var j; 1795 var jLen; 1796 for (i = len - 1; i >= 0; i -= 1) { 1797 if (arr[i].ty === 'sh') { 1798 if (arr[i].ks.k.i) { 1799 arr[i].ks.k.c = arr[i].closed; 1800 } else { 1801 jLen = arr[i].ks.k.length; 1802 for (j = 0; j < jLen; j += 1) { 1803 if (arr[i].ks.k[j].s) { 1804 arr[i].ks.k[j].s[0].c = arr[i].closed; 1805 } 1806 if (arr[i].ks.k[j].e) { 1807 arr[i].ks.k[j].e[0].c = arr[i].closed; 1808 } 1809 } 1810 } 1811 } else if (arr[i].ty === 'gr') { 1812 completeClosingShapes(arr[i].it); 1813 } 1814 } 1815 } 1816 1817 function iterateLayers(layers) { 1818 var layerData; 1819 var i; 1820 var len = layers.length; 1821 var j; 1822 var jLen; 1823 var k; 1824 var kLen; 1825 for (i = 0; i < len; i += 1) { 1826 layerData = layers[i]; 1827 if (layerData.hasMask) { 1828 var maskProps = layerData.masksProperties; 1829 jLen = maskProps.length; 1830 for (j = 0; j < jLen; j += 1) { 1831 if (maskProps[j].pt.k.i) { 1832 maskProps[j].pt.k.c = maskProps[j].cl; 1833 } else { 1834 kLen = maskProps[j].pt.k.length; 1835 for (k = 0; k < kLen; k += 1) { 1836 if (maskProps[j].pt.k[k].s) { 1837 maskProps[j].pt.k[k].s[0].c = maskProps[j].cl; 1838 } 1839 if (maskProps[j].pt.k[k].e) { 1840 maskProps[j].pt.k[k].e[0].c = maskProps[j].cl; 1841 } 1842 } 1843 } 1844 } 1845 } 1846 if (layerData.ty === 4) { 1847 completeClosingShapes(layerData.shapes); 1848 } 1849 } 1850 } 1851 1852 return function (animationData) { 1853 if (checkVersion(minimumVersion, animationData.v)) { 1854 iterateLayers(animationData.layers); 1855 if (animationData.assets) { 1856 var i; 1857 var len = animationData.assets.length; 1858 for (i = 0; i < len; i += 1) { 1859 if (animationData.assets[i].layers) { 1860 iterateLayers(animationData.assets[i].layers); 1861 } 1862 } 1863 } 1864 } 1865 }; 1866 }()); 1867 1868 function completeData(animationData, fontManager) { 1869 if (animationData.__complete) { 1870 return; 1871 } 1872 checkColors(animationData); 1873 checkText(animationData); 1874 checkChars(animationData); 1875 checkShapes(animationData); 1876 completeLayers(animationData.layers, animationData.assets, fontManager); 1877 animationData.__complete = true; 1878 } 1879 1880 function completeText(data) { 1881 if (data.t.a.length === 0 && !('m' in data.t.p)) { 1882 data.singleShape = true; 1883 } 1884 } 1885 1886 var moduleOb = {}; 1887 moduleOb.completeData = completeData; 1888 moduleOb.checkColors = checkColors; 1889 moduleOb.checkChars = checkChars; 1890 moduleOb.checkShapes = checkShapes; 1891 moduleOb.completeLayers = completeLayers; 1892 1893 return moduleOb; 1894} 1895 1896var dataManager = dataFunctionManager(); 1897 1898/* exported getFontProperties */ 1899 1900function getFontProperties(fontData) { 1901 var styles = fontData.fStyle ? fontData.fStyle.split(' ') : []; 1902 1903 var fWeight = 'normal'; var 1904 fStyle = 'normal'; 1905 var len = styles.length; 1906 var styleName; 1907 for (var i = 0; i < len; i += 1) { 1908 styleName = styles[i].toLowerCase(); 1909 switch (styleName) { 1910 case 'italic': 1911 fStyle = 'italic'; 1912 break; 1913 case 'bold': 1914 fWeight = '700'; 1915 break; 1916 case 'black': 1917 fWeight = '900'; 1918 break; 1919 case 'medium': 1920 fWeight = '500'; 1921 break; 1922 case 'regular': 1923 case 'normal': 1924 fWeight = '400'; 1925 break; 1926 case 'light': 1927 case 'thin': 1928 fWeight = '200'; 1929 break; 1930 default: 1931 break; 1932 } 1933 } 1934 1935 return { 1936 style: fStyle, 1937 weight: fontData.fWeight || fWeight, 1938 }; 1939} 1940 1941/* global createNS, createTag, getFontProperties */ 1942/* exported FontManager */ 1943 1944var FontManager = (function () { 1945 var maxWaitingTime = 5000; 1946 var emptyChar = { 1947 w: 0, 1948 size: 0, 1949 shapes: [], 1950 }; 1951 var combinedCharacters = []; 1952 // Hindi characters 1953 combinedCharacters = combinedCharacters.concat([2304, 2305, 2306, 2307, 2362, 2363, 2364, 2364, 2366, 1954 2367, 2368, 2369, 2370, 2371, 2372, 2373, 2374, 2375, 2376, 2377, 2378, 2379, 1955 2380, 2381, 2382, 2383, 2387, 2388, 2389, 2390, 2391, 2402, 2403]); 1956 1957 function trimFontOptions(font) { 1958 var familyArray = font.split(','); 1959 var i; 1960 var len = familyArray.length; 1961 var enabledFamilies = []; 1962 for (i = 0; i < len; i += 1) { 1963 if (familyArray[i] !== 'sans-serif' && familyArray[i] !== 'monospace') { 1964 enabledFamilies.push(familyArray[i]); 1965 } 1966 } 1967 return enabledFamilies.join(','); 1968 } 1969 1970 function setUpNode(font, family) { 1971 var parentNode = createTag('span'); 1972 // Node is invisible to screen readers. 1973 parentNode.setAttribute('aria-hidden', true); 1974 parentNode.style.fontFamily = family; 1975 var node = createTag('span'); 1976 // Characters that vary significantly among different fonts 1977 node.innerText = 'giItT1WQy@!-/#'; 1978 // Visible - so we can measure it - but not on the screen 1979 parentNode.style.position = 'absolute'; 1980 parentNode.style.left = '-10000px'; 1981 parentNode.style.top = '-10000px'; 1982 // Large font size makes even subtle changes obvious 1983 parentNode.style.fontSize = '300px'; 1984 // Reset any font properties 1985 parentNode.style.fontVariant = 'normal'; 1986 parentNode.style.fontStyle = 'normal'; 1987 parentNode.style.fontWeight = 'normal'; 1988 parentNode.style.letterSpacing = '0'; 1989 parentNode.appendChild(node); 1990 document.body.appendChild(parentNode); 1991 1992 // Remember width with no applied web font 1993 var width = node.offsetWidth; 1994 node.style.fontFamily = trimFontOptions(font) + ', ' + family; 1995 return { node: node, w: width, parent: parentNode }; 1996 } 1997 1998 function checkLoadedFonts() { 1999 var i; 2000 var len = this.fonts.length; 2001 var node; 2002 var w; 2003 var loadedCount = len; 2004 for (i = 0; i < len; i += 1) { 2005 if (this.fonts[i].loaded) { 2006 loadedCount -= 1; 2007 } else if (this.fonts[i].fOrigin === 'n' || this.fonts[i].origin === 0) { 2008 this.fonts[i].loaded = true; 2009 } else { 2010 node = this.fonts[i].monoCase.node; 2011 w = this.fonts[i].monoCase.w; 2012 if (node.offsetWidth !== w) { 2013 loadedCount -= 1; 2014 this.fonts[i].loaded = true; 2015 } else { 2016 node = this.fonts[i].sansCase.node; 2017 w = this.fonts[i].sansCase.w; 2018 if (node.offsetWidth !== w) { 2019 loadedCount -= 1; 2020 this.fonts[i].loaded = true; 2021 } 2022 } 2023 if (this.fonts[i].loaded) { 2024 this.fonts[i].sansCase.parent.parentNode.removeChild(this.fonts[i].sansCase.parent); 2025 this.fonts[i].monoCase.parent.parentNode.removeChild(this.fonts[i].monoCase.parent); 2026 } 2027 } 2028 } 2029 2030 if (loadedCount !== 0 && Date.now() - this.initTime < maxWaitingTime) { 2031 setTimeout(this.checkLoadedFontsBinded, 20); 2032 } else { 2033 setTimeout(this.setIsLoadedBinded, 10); 2034 } 2035 } 2036 2037 function createHelper(def, fontData) { 2038 var tHelper = createNS('text'); 2039 tHelper.style.fontSize = '100px'; 2040 // tHelper.style.fontFamily = fontData.fFamily; 2041 2042 var fontProps = getFontProperties(fontData); 2043 tHelper.setAttribute('font-family', fontData.fFamily); 2044 tHelper.setAttribute('font-style', fontProps.style); 2045 tHelper.setAttribute('font-weight', fontProps.weight); 2046 tHelper.textContent = '1'; 2047 if (fontData.fClass) { 2048 tHelper.style.fontFamily = 'inherit'; 2049 tHelper.setAttribute('class', fontData.fClass); 2050 } else { 2051 tHelper.style.fontFamily = fontData.fFamily; 2052 } 2053 def.appendChild(tHelper); 2054 var tCanvasHelper = createTag('canvas').getContext('2d'); 2055 tCanvasHelper.font = fontData.fWeight + ' ' + fontData.fStyle + ' 100px ' + fontData.fFamily; 2056 // tCanvasHelper.font = ' 100px '+ fontData.fFamily; 2057 return tHelper; 2058 } 2059 2060 function addFonts(fontData, defs) { 2061 if (!fontData) { 2062 this.isLoaded = true; 2063 return; 2064 } 2065 if (this.chars) { 2066 this.isLoaded = true; 2067 this.fonts = fontData.list; 2068 return; 2069 } 2070 2071 var fontArr = fontData.list; 2072 var i; 2073 var len = fontArr.length; 2074 var _pendingFonts = len; 2075 for (i = 0; i < len; i += 1) { 2076 var shouldLoadFont = true; 2077 var loadedSelector; 2078 var j; 2079 fontArr[i].loaded = false; 2080 fontArr[i].monoCase = setUpNode(fontArr[i].fFamily, 'monospace'); 2081 fontArr[i].sansCase = setUpNode(fontArr[i].fFamily, 'sans-serif'); 2082 if (!fontArr[i].fPath) { 2083 fontArr[i].loaded = true; 2084 _pendingFonts -= 1; 2085 } else if (fontArr[i].fOrigin === 'p' || fontArr[i].origin === 3) { 2086 loadedSelector = document.querySelectorAll('style[f-forigin="p"][f-family="' + fontArr[i].fFamily + '"], style[f-origin="3"][f-family="' + fontArr[i].fFamily + '"]'); 2087 2088 if (loadedSelector.length > 0) { 2089 shouldLoadFont = false; 2090 } 2091 2092 if (shouldLoadFont) { 2093 var s = createTag('style'); 2094 s.setAttribute('f-forigin', fontArr[i].fOrigin); 2095 s.setAttribute('f-origin', fontArr[i].origin); 2096 s.setAttribute('f-family', fontArr[i].fFamily); 2097 s.type = 'text/css'; 2098 s.innerText = '@font-face {font-family: ' + fontArr[i].fFamily + "; font-style: normal; src: url('" + fontArr[i].fPath + "');}"; 2099 defs.appendChild(s); 2100 } 2101 } else if (fontArr[i].fOrigin === 'g' || fontArr[i].origin === 1) { 2102 loadedSelector = document.querySelectorAll('link[f-forigin="g"], link[f-origin="1"]'); 2103 2104 for (j = 0; j < loadedSelector.length; j += 1) { 2105 if (loadedSelector[j].href.indexOf(fontArr[i].fPath) !== -1) { 2106 // Font is already loaded 2107 shouldLoadFont = false; 2108 } 2109 } 2110 2111 if (shouldLoadFont) { 2112 var l = createTag('link'); 2113 l.setAttribute('f-forigin', fontArr[i].fOrigin); 2114 l.setAttribute('f-origin', fontArr[i].origin); 2115 l.type = 'text/css'; 2116 l.rel = 'stylesheet'; 2117 l.href = fontArr[i].fPath; 2118 document.body.appendChild(l); 2119 } 2120 } else if (fontArr[i].fOrigin === 't' || fontArr[i].origin === 2) { 2121 loadedSelector = document.querySelectorAll('script[f-forigin="t"], script[f-origin="2"]'); 2122 2123 for (j = 0; j < loadedSelector.length; j += 1) { 2124 if (fontArr[i].fPath === loadedSelector[j].src) { 2125 // Font is already loaded 2126 shouldLoadFont = false; 2127 } 2128 } 2129 2130 if (shouldLoadFont) { 2131 var sc = createTag('link'); 2132 sc.setAttribute('f-forigin', fontArr[i].fOrigin); 2133 sc.setAttribute('f-origin', fontArr[i].origin); 2134 sc.setAttribute('rel', 'stylesheet'); 2135 sc.setAttribute('href', fontArr[i].fPath); 2136 defs.appendChild(sc); 2137 } 2138 } 2139 fontArr[i].helper = createHelper(defs, fontArr[i]); 2140 fontArr[i].cache = {}; 2141 this.fonts.push(fontArr[i]); 2142 } 2143 if (_pendingFonts === 0) { 2144 this.isLoaded = true; 2145 } else { 2146 // On some cases even if the font is loaded, it won't load correctly when measuring text on canvas. 2147 // Adding this timeout seems to fix it 2148 setTimeout(this.checkLoadedFonts.bind(this), 100); 2149 } 2150 } 2151 2152 function addChars(chars) { 2153 if (!chars) { 2154 return; 2155 } 2156 if (!this.chars) { 2157 this.chars = []; 2158 } 2159 var i; 2160 var len = chars.length; 2161 var j; 2162 var jLen = this.chars.length; 2163 var found; 2164 for (i = 0; i < len; i += 1) { 2165 j = 0; 2166 found = false; 2167 while (j < jLen) { 2168 if (this.chars[j].style === chars[i].style && this.chars[j].fFamily === chars[i].fFamily && this.chars[j].ch === chars[i].ch) { 2169 found = true; 2170 } 2171 j += 1; 2172 } 2173 if (!found) { 2174 this.chars.push(chars[i]); 2175 jLen += 1; 2176 } 2177 } 2178 } 2179 2180 function getCharData(char, style, font) { 2181 var i = 0; 2182 var len = this.chars.length; 2183 while (i < len) { 2184 if (this.chars[i].ch === char && this.chars[i].style === style && this.chars[i].fFamily === font) { 2185 return this.chars[i]; 2186 } 2187 i += 1; 2188 } 2189 if (((typeof char === 'string' && char.charCodeAt(0) !== 13) || !char) 2190 && console 2191 && console.warn // eslint-disable-line no-console 2192 && !this._warned 2193 ) { 2194 this._warned = true; 2195 console.warn('Missing character from exported characters list: ', char, style, font); // eslint-disable-line no-console 2196 } 2197 return emptyChar; 2198 } 2199 2200 function measureText(char, fontName, size) { 2201 var fontData = this.getFontByName(fontName); 2202 var index = char.charCodeAt(0); 2203 if (!fontData.cache[index + 1]) { 2204 var tHelper = fontData.helper; 2205 // Canvas version 2206 // fontData.cache[index] = tHelper.measureText(char).width / 100; 2207 // SVG version 2208 // console.log(tHelper.getBBox().width) 2209 if (char === ' ') { 2210 tHelper.textContent = '|' + char + '|'; 2211 var doubleSize = tHelper.getComputedTextLength(); 2212 tHelper.textContent = '||'; 2213 var singleSize = tHelper.getComputedTextLength(); 2214 fontData.cache[index + 1] = (doubleSize - singleSize) / 100; 2215 } else { 2216 tHelper.textContent = char; 2217 fontData.cache[index + 1] = (tHelper.getComputedTextLength()) / 100; 2218 } 2219 } 2220 return fontData.cache[index + 1] * size; 2221 } 2222 2223 function getFontByName(name) { 2224 var i = 0; 2225 var len = this.fonts.length; 2226 while (i < len) { 2227 if (this.fonts[i].fName === name) { 2228 return this.fonts[i]; 2229 } 2230 i += 1; 2231 } 2232 return this.fonts[0]; 2233 } 2234 2235 function getCombinedCharacterCodes() { 2236 return combinedCharacters; 2237 } 2238 2239 function setIsLoaded() { 2240 this.isLoaded = true; 2241 } 2242 2243 var Font = function () { 2244 this.fonts = []; 2245 this.chars = null; 2246 this.typekitLoaded = 0; 2247 this.isLoaded = false; 2248 this._warned = false; 2249 this.initTime = Date.now(); 2250 this.setIsLoadedBinded = this.setIsLoaded.bind(this); 2251 this.checkLoadedFontsBinded = this.checkLoadedFonts.bind(this); 2252 }; 2253 // TODO: for now I'm adding these methods to the Class and not the prototype. Think of a better way to implement it. 2254 Font.getCombinedCharacterCodes = getCombinedCharacterCodes; 2255 2256 var fontPrototype = { 2257 addChars: addChars, 2258 addFonts: addFonts, 2259 getCharData: getCharData, 2260 getFontByName: getFontByName, 2261 measureText: measureText, 2262 checkLoadedFonts: checkLoadedFonts, 2263 setIsLoaded: setIsLoaded, 2264 }; 2265 2266 Font.prototype = fontPrototype; 2267 2268 return Font; 2269}()); 2270 2271/* global initialDefaultFrame, BezierFactory, degToRads, bez, createTypedArray */ 2272/* exported PropertyFactory */ 2273 2274var PropertyFactory = (function () { 2275 var initFrame = initialDefaultFrame; 2276 var mathAbs = Math.abs; 2277 2278 function interpolateValue(frameNum, caching) { 2279 var offsetTime = this.offsetTime; 2280 var newValue; 2281 if (this.propType === 'multidimensional') { 2282 newValue = createTypedArray('float32', this.pv.length); 2283 } 2284 var iterationIndex = caching.lastIndex; 2285 var i = iterationIndex; 2286 var len = this.keyframes.length - 1; 2287 var flag = true; 2288 var keyData; 2289 var nextKeyData; 2290 2291 while (flag) { 2292 keyData = this.keyframes[i]; 2293 nextKeyData = this.keyframes[i + 1]; 2294 if (i === len - 1 && frameNum >= nextKeyData.t - offsetTime) { 2295 if (keyData.h) { 2296 keyData = nextKeyData; 2297 } 2298 iterationIndex = 0; 2299 break; 2300 } 2301 if ((nextKeyData.t - offsetTime) > frameNum) { 2302 iterationIndex = i; 2303 break; 2304 } 2305 if (i < len - 1) { 2306 i += 1; 2307 } else { 2308 iterationIndex = 0; 2309 flag = false; 2310 } 2311 } 2312 2313 var k; 2314 var kLen; 2315 var perc; 2316 var jLen; 2317 var j; 2318 var fnc; 2319 var nextKeyTime = nextKeyData.t - offsetTime; 2320 var keyTime = keyData.t - offsetTime; 2321 var endValue; 2322 if (keyData.to) { 2323 if (!keyData.bezierData) { 2324 keyData.bezierData = bez.buildBezierData(keyData.s, nextKeyData.s || keyData.e, keyData.to, keyData.ti); 2325 } 2326 var bezierData = keyData.bezierData; 2327 if (frameNum >= nextKeyTime || frameNum < keyTime) { 2328 var ind = frameNum >= nextKeyTime ? bezierData.points.length - 1 : 0; 2329 kLen = bezierData.points[ind].point.length; 2330 for (k = 0; k < kLen; k += 1) { 2331 newValue[k] = bezierData.points[ind].point[k]; 2332 } 2333 // caching._lastKeyframeIndex = -1; 2334 } else { 2335 if (keyData.__fnct) { 2336 fnc = keyData.__fnct; 2337 } else { 2338 fnc = BezierFactory.getBezierEasing(keyData.o.x, keyData.o.y, keyData.i.x, keyData.i.y, keyData.n).get; 2339 keyData.__fnct = fnc; 2340 } 2341 perc = fnc((frameNum - keyTime) / (nextKeyTime - keyTime)); 2342 var distanceInLine = bezierData.segmentLength * perc; 2343 2344 var segmentPerc; 2345 var addedLength = (caching.lastFrame < frameNum && caching._lastKeyframeIndex === i) ? caching._lastAddedLength : 0; 2346 j = (caching.lastFrame < frameNum && caching._lastKeyframeIndex === i) ? caching._lastPoint : 0; 2347 flag = true; 2348 jLen = bezierData.points.length; 2349 while (flag) { 2350 addedLength += bezierData.points[j].partialLength; 2351 if (distanceInLine === 0 || perc === 0 || j === bezierData.points.length - 1) { 2352 kLen = bezierData.points[j].point.length; 2353 for (k = 0; k < kLen; k += 1) { 2354 newValue[k] = bezierData.points[j].point[k]; 2355 } 2356 break; 2357 } else if (distanceInLine >= addedLength && distanceInLine < addedLength + bezierData.points[j + 1].partialLength) { 2358 segmentPerc = (distanceInLine - addedLength) / bezierData.points[j + 1].partialLength; 2359 kLen = bezierData.points[j].point.length; 2360 for (k = 0; k < kLen; k += 1) { 2361 newValue[k] = bezierData.points[j].point[k] + (bezierData.points[j + 1].point[k] - bezierData.points[j].point[k]) * segmentPerc; 2362 } 2363 break; 2364 } 2365 if (j < jLen - 1) { 2366 j += 1; 2367 } else { 2368 flag = false;
vendor: 4,502 bytes, lines 2369-2509
2369 } 2370 } 2371 caching._lastPoint = j; 2372 caching._lastAddedLength = addedLength - bezierData.points[j].partialLength; 2373 caching._lastKeyframeIndex = i; 2374 } 2375 } else { 2376 var outX; 2377 var outY; 2378 var inX; 2379 var inY; 2380 var keyValue; 2381 len = keyData.s.length; 2382 endValue = nextKeyData.s || keyData.e; 2383 if (this.sh && keyData.h !== 1) { 2384 if (frameNum >= nextKeyTime) { 2385 newValue[0] = endValue[0]; 2386 newValue[1] = endValue[1]; 2387 newValue[2] = endValue[2]; 2388 } else if (frameNum <= keyTime) { 2389 newValue[0] = keyData.s[0]; 2390 newValue[1] = keyData.s[1]; 2391 newValue[2] = keyData.s[2]; 2392 } else { 2393 var quatStart = createQuaternion(keyData.s); 2394 var quatEnd = createQuaternion(endValue); 2395 var time = (frameNum - keyTime) / (nextKeyTime - keyTime); 2396 quaternionToEuler(newValue, slerp(quatStart, quatEnd, time)); 2397 } 2398 } else { 2399 for (i = 0; i < len; i += 1) { 2400 if (keyData.h !== 1) { 2401 if (frameNum >= nextKeyTime) { 2402 perc = 1; 2403 } else if (frameNum < keyTime) { 2404 perc = 0; 2405 } else { 2406 if (keyData.o.x.constructor === Array) { 2407 if (!keyData.__fnct) { 2408 keyData.__fnct = []; 2409 } 2410 if (!keyData.__fnct[i]) { 2411 outX = (typeof keyData.o.x[i] === 'undefined') ? keyData.o.x[0] : keyData.o.x[i]; 2412 outY = (typeof keyData.o.y[i] === 'undefined') ? keyData.o.y[0] : keyData.o.y[i]; 2413 inX = (typeof keyData.i.x[i] === 'undefined') ? keyData.i.x[0] : keyData.i.x[i]; 2414 inY = (typeof keyData.i.y[i] === 'undefined') ? keyData.i.y[0] : keyData.i.y[i]; 2415 fnc = BezierFactory.getBezierEasing(outX, outY, inX, inY).get; 2416 keyData.__fnct[i] = fnc; 2417 } else { 2418 fnc = keyData.__fnct[i]; 2419 } 2420 } else if (!keyData.__fnct) { 2421 outX = keyData.o.x; 2422 outY = keyData.o.y; 2423 inX = keyData.i.x; 2424 inY = keyData.i.y; 2425 fnc = BezierFactory.getBezierEasing(outX, outY, inX, inY).get; 2426 keyData.__fnct = fnc; 2427 } else { 2428 fnc = keyData.__fnct; 2429 } 2430 perc = fnc((frameNum - keyTime) / (nextKeyTime - keyTime)); 2431 } 2432 } 2433 2434 endValue = nextKeyData.s || keyData.e; 2435 keyValue = keyData.h === 1 ? keyData.s[i] : keyData.s[i] + (endValue[i] - keyData.s[i]) * perc; 2436 2437 if (this.propType === 'multidimensional') { 2438 newValue[i] = keyValue; 2439 } else { 2440 newValue = keyValue; 2441 } 2442 } 2443 } 2444 } 2445 caching.lastIndex = iterationIndex; 2446 return newValue; 2447 } 2448 2449 // based on @Toji's https://github.com/toji/gl-matrix/ 2450 function slerp(a, b, t) { 2451 var out = []; 2452 var ax = a[0]; 2453 var ay = a[1]; 2454 var az = a[2]; 2455 var aw = a[3]; 2456 var bx = b[0]; 2457 var by = b[1]; 2458 var bz = b[2]; 2459 var bw = b[3]; 2460 2461 var omega; 2462 var cosom; 2463 var sinom; 2464 var scale0; 2465 var scale1; 2466 2467 cosom = ax * bx + ay * by + az * bz + aw * bw; 2468 if (cosom < 0.0) { 2469 cosom = -cosom; 2470 bx = -bx; 2471 by = -by; 2472 bz = -bz; 2473 bw = -bw; 2474 } 2475 if ((1.0 - cosom) > 0.000001) { 2476 omega = Math.acos(cosom); 2477 sinom = Math.sin(omega); 2478 scale0 = Math.sin((1.0 - t) * omega) / sinom; 2479 scale1 = Math.sin(t * omega) / sinom; 2480 } else { 2481 scale0 = 1.0 - t; 2482 scale1 = t; 2483 } 2484 out[0] = scale0 * ax + scale1 * bx; 2485 out[1] = scale0 * ay + scale1 * by; 2486 out[2] = scale0 * az + scale1 * bz; 2487 out[3] = scale0 * aw + scale1 * bw; 2488 2489 return out; 2490 } 2491 2492 function quaternionToEuler(out, quat) { 2493 var qx = quat[0]; 2494 var qy = quat[1]; 2495 var qz = quat[2]; 2496 var qw = quat[3]; 2497 var heading = Math.atan2(2 * qy * qw - 2 * qx * qz, 1 - 2 * qy * qy - 2 * qz * qz); 2498 var attitude = Math.asin(2 * qx * qy + 2 * qz * qw); 2499 var bank = Math.atan2(2 * qx * qw - 2 * qy * qz, 1 - 2 * qx * qx - 2 * qz * qz); 2500 out[0] = heading / degToRads; 2501 out[1] = attitude / degToRads; 2502 out[2] = bank / degToRads; 2503 } 2504 2505 function createQuaternion(values) { 2506 var heading = values[0] * degToRads; 2507 var attitude = values[1] * degToRads; 2508 var bank = values[2] * degToRads; 2509 var c1 = Math.cos(heading / 2);
vendor: 16,687 bytes, lines 2510-2986
2510 var c2 = Math.cos(attitude / 2); 2511 var c3 = Math.cos(bank / 2); 2512 var s1 = Math.sin(heading / 2); 2513 var s2 = Math.sin(attitude / 2); 2514 var s3 = Math.sin(bank / 2); 2515 var w = c1 * c2 * c3 - s1 * s2 * s3; 2516 var x = s1 * s2 * c3 + c1 * c2 * s3; 2517 var y = s1 * c2 * c3 + c1 * s2 * s3; 2518 var z = c1 * s2 * c3 - s1 * c2 * s3; 2519 2520 return [x, y, z, w]; 2521 } 2522 2523 function getValueAtCurrentTime() { 2524 var frameNum = this.comp.renderedFrame - this.offsetTime; 2525 var initTime = this.keyframes[0].t - this.offsetTime; 2526 var endTime = this.keyframes[this.keyframes.length - 1].t - this.offsetTime; 2527 if (!(frameNum === this._caching.lastFrame || (this._caching.lastFrame !== initFrame && ((this._caching.lastFrame >= endTime && frameNum >= endTime) || (this._caching.lastFrame < initTime && frameNum < initTime))))) { 2528 if (this._caching.lastFrame >= frameNum) { 2529 this._caching._lastKeyframeIndex = -1; 2530 this._caching.lastIndex = 0; 2531 } 2532 2533 var renderResult = this.interpolateValue(frameNum, this._caching); 2534 this.pv = renderResult; 2535 } 2536 this._caching.lastFrame = frameNum; 2537 return this.pv; 2538 } 2539 2540 function setVValue(val) { 2541 var multipliedValue; 2542 if (this.propType === 'unidimensional') { 2543 multipliedValue = val * this.mult; 2544 if (mathAbs(this.v - multipliedValue) > 0.00001) { 2545 this.v = multipliedValue; 2546 this._mdf = true; 2547 } 2548 } else { 2549 var i = 0; 2550 var len = this.v.length; 2551 while (i < len) { 2552 multipliedValue = val[i] * this.mult; 2553 if (mathAbs(this.v[i] - multipliedValue) > 0.00001) { 2554 this.v[i] = multipliedValue; 2555 this._mdf = true; 2556 } 2557 i += 1; 2558 } 2559 } 2560 } 2561 2562 function processEffectsSequence() { 2563 if (this.elem.globalData.frameId === this.frameId || !this.effectsSequence.length) { 2564 return; 2565 } 2566 if (this.lock) { 2567 this.setVValue(this.pv); 2568 return; 2569 } 2570 this.lock = true; 2571 this._mdf = this._isFirstFrame; 2572 var i; 2573 var len = this.effectsSequence.length; 2574 var finalValue = this.kf ? this.pv : this.data.k; 2575 for (i = 0; i < len; i += 1) { 2576 finalValue = this.effectsSequence[i](finalValue); 2577 } 2578 this.setVValue(finalValue); 2579 this._isFirstFrame = false; 2580 this.lock = false; 2581 this.frameId = this.elem.globalData.frameId; 2582 } 2583 2584 function addEffect(effectFunction) { 2585 this.effectsSequence.push(effectFunction); 2586 this.container.addDynamicProperty(this); 2587 } 2588 2589 function ValueProperty(elem, data, mult, container) { 2590 this.propType = 'unidimensional'; 2591 this.mult = mult || 1; 2592 this.data = data; 2593 this.v = mult ? data.k * mult : data.k; 2594 this.pv = data.k; 2595 this._mdf = false; 2596 this.elem = elem; 2597 this.container = container; 2598 this.comp = elem.comp; 2599 this.k = false; 2600 this.kf = false; 2601 this.vel = 0; 2602 this.effectsSequence = []; 2603 this._isFirstFrame = true; 2604 this.getValue = processEffectsSequence; 2605 this.setVValue = setVValue; 2606 this.addEffect = addEffect; 2607 } 2608 2609 function MultiDimensionalProperty(elem, data, mult, container) { 2610 this.propType = 'multidimensional'; 2611 this.mult = mult || 1; 2612 this.data = data; 2613 this._mdf = false; 2614 this.elem = elem; 2615 this.container = container; 2616 this.comp = elem.comp; 2617 this.k = false; 2618 this.kf = false; 2619 this.frameId = -1; 2620 var i; 2621 var len = data.k.length; 2622 this.v = createTypedArray('float32', len); 2623 this.pv = createTypedArray('float32', len); 2624 this.vel = createTypedArray('float32', len); 2625 for (i = 0; i < len; i += 1) { 2626 this.v[i] = data.k[i] * this.mult; 2627 this.pv[i] = data.k[i]; 2628 } 2629 this._isFirstFrame = true; 2630 this.effectsSequence = []; 2631 this.getValue = processEffectsSequence; 2632 this.setVValue = setVValue; 2633 this.addEffect = addEffect; 2634 } 2635 2636 function KeyframedValueProperty(elem, data, mult, container) { 2637 this.propType = 'unidimensional'; 2638 this.keyframes = data.k; 2639 this.offsetTime = elem.data.st; 2640 this.frameId = -1; 2641 this._caching = { 2642 lastFrame: initFrame, lastIndex: 0, value: 0, _lastKeyframeIndex: -1, 2643 }; 2644 this.k = true; 2645 this.kf = true; 2646 this.data = data; 2647 this.mult = mult || 1; 2648 this.elem = elem; 2649 this.container = container; 2650 this.comp = elem.comp; 2651 this.v = initFrame; 2652 this.pv = initFrame; 2653 this._isFirstFrame = true; 2654 this.getValue = processEffectsSequence; 2655 this.setVValue = setVValue; 2656 this.interpolateValue = interpolateValue; 2657 this.effectsSequence = [getValueAtCurrentTime.bind(this)]; 2658 this.addEffect = addEffect; 2659 } 2660 2661 function KeyframedMultidimensionalProperty(elem, data, mult, container) { 2662 this.propType = 'multidimensional'; 2663 var i; 2664 var len = data.k.length; 2665 var s; 2666 var e; 2667 var to; 2668 var ti; 2669 for (i = 0; i < len - 1; i += 1) { 2670 if (data.k[i].to && data.k[i].s && data.k[i + 1] && data.k[i + 1].s) { 2671 s = data.k[i].s; 2672 e = data.k[i + 1].s; 2673 to = data.k[i].to; 2674 ti = data.k[i].ti; 2675 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]))) { 2676 data.k[i].to = null; 2677 data.k[i].ti = null; 2678 } 2679 if (s[0] === e[0] && s[1] === e[1] && to[0] === 0 && to[1] === 0 && ti[0] === 0 && ti[1] === 0) { 2680 if (s.length === 2 || (s[2] === e[2] && to[2] === 0 && ti[2] === 0)) { 2681 data.k[i].to = null; 2682 data.k[i].ti = null; 2683 } 2684 } 2685 } 2686 } 2687 this.effectsSequence = [getValueAtCurrentTime.bind(this)]; 2688 this.data = data; 2689 this.keyframes = data.k; 2690 this.offsetTime = elem.data.st; 2691 this.k = true; 2692 this.kf = true; 2693 this._isFirstFrame = true; 2694 this.mult = mult || 1; 2695 this.elem = elem; 2696 this.container = container; 2697 this.comp = elem.comp; 2698 this.getValue = processEffectsSequence; 2699 this.setVValue = setVValue; 2700 this.interpolateValue = interpolateValue; 2701 this.frameId = -1; 2702 var arrLen = data.k[0].s.length; 2703 this.v = createTypedArray('float32', arrLen); 2704 this.pv = createTypedArray('float32', arrLen); 2705 for (i = 0; i < arrLen; i += 1) { 2706 this.v[i] = initFrame; 2707 this.pv[i] = initFrame; 2708 } 2709 this._caching = { lastFrame: initFrame, lastIndex: 0, value: createTypedArray('float32', arrLen) }; 2710 this.addEffect = addEffect; 2711 } 2712 2713 function getProp(elem, data, type, mult, container) { 2714 var p; 2715 if (!data.k.length) { 2716 p = new ValueProperty(elem, data, mult, container); 2717 } else if (typeof (data.k[0]) === 'number') { 2718 p = new MultiDimensionalProperty(elem, data, mult, container); 2719 } else { 2720 switch (type) { 2721 case 0: 2722 p = new KeyframedValueProperty(elem, data, mult, container); 2723 break; 2724 case 1: 2725 p = new KeyframedMultidimensionalProperty(elem, data, mult, container); 2726 break; 2727 default: 2728 break; 2729 } 2730 } 2731 if (p.effectsSequence.length) { 2732 container.addDynamicProperty(p); 2733 } 2734 return p; 2735 } 2736 2737 var ob = { 2738 getProp: getProp, 2739 }; 2740 return ob; 2741}()); 2742 2743/* global Matrix, degToRads, PropertyFactory, extendPrototype, DynamicPropertyContainer */ 2744/* exported TransformPropertyFactory */ 2745 2746var TransformPropertyFactory = (function () { 2747 var defaultVector = [0, 0]; 2748 2749 function applyToMatrix(mat) { 2750 var _mdf = this._mdf; 2751 this.iterateDynamicProperties(); 2752 this._mdf = this._mdf || _mdf; 2753 if (this.a) { 2754 mat.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]); 2755 } 2756 if (this.s) { 2757 mat.scale(this.s.v[0], this.s.v[1], this.s.v[2]); 2758 } 2759 if (this.sk) { 2760 mat.skewFromAxis(-this.sk.v, this.sa.v); 2761 } 2762 if (this.r) { 2763 mat.rotate(-this.r.v); 2764 } else { 2765 mat.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2]) 2766 .rotateY(this.or.v[1]) 2767 .rotateX(this.or.v[0]); 2768 } 2769 if (this.data.p.s) { 2770 if (this.data.p.z) { 2771 mat.translate(this.px.v, this.py.v, -this.pz.v); 2772 } else { 2773 mat.translate(this.px.v, this.py.v, 0); 2774 } 2775 } else { 2776 mat.translate(this.p.v[0], this.p.v[1], -this.p.v[2]); 2777 } 2778 } 2779 function processKeys(forceRender) { 2780 if (this.elem.globalData.frameId === this.frameId) { 2781 return; 2782 } 2783 if (this._isDirty) { 2784 this.precalculateMatrix(); 2785 this._isDirty = false; 2786 } 2787 2788 this.iterateDynamicProperties(); 2789 2790 if (this._mdf || forceRender) { 2791 var frameRate; 2792 this.v.cloneFromProps(this.pre.props); 2793 if (this.appliedTransformations < 1) { 2794 this.v.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]); 2795 } 2796 if (this.appliedTransformations < 2) { 2797 this.v.scale(this.s.v[0], this.s.v[1], this.s.v[2]); 2798 } 2799 if (this.sk && this.appliedTransformations < 3) { 2800 this.v.skewFromAxis(-this.sk.v, this.sa.v); 2801 } 2802 if (this.r && this.appliedTransformations < 4) { 2803 this.v.rotate(-this.r.v); 2804 } else if (!this.r && this.appliedTransformations < 4) { 2805 this.v.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2]) 2806 .rotateY(this.or.v[1]) 2807 .rotateX(this.or.v[0]); 2808 } 2809 if (this.autoOriented) { 2810 var v1; 2811 var v2; 2812 frameRate = this.elem.globalData.frameRate; 2813 if (this.p && this.p.keyframes && this.p.getValueAtTime) { 2814 if (this.p._caching.lastFrame + this.p.offsetTime <= this.p.keyframes[0].t) { 2815 v1 = this.p.getValueAtTime((this.p.keyframes[0].t + 0.01) / frameRate, 0); 2816 v2 = this.p.getValueAtTime(this.p.keyframes[0].t / frameRate, 0); 2817 } else if (this.p._caching.lastFrame + this.p.offsetTime >= this.p.keyframes[this.p.keyframes.length - 1].t) { 2818 v1 = this.p.getValueAtTime((this.p.keyframes[this.p.keyframes.length - 1].t / frameRate), 0); 2819 v2 = this.p.getValueAtTime((this.p.keyframes[this.p.keyframes.length - 1].t - 0.05) / frameRate, 0); 2820 } else { 2821 v1 = this.p.pv; 2822 v2 = this.p.getValueAtTime((this.p._caching.lastFrame + this.p.offsetTime - 0.01) / frameRate, this.p.offsetTime); 2823 } 2824 } else if (this.px && this.px.keyframes && this.py.keyframes && this.px.getValueAtTime && this.py.getValueAtTime) { 2825 v1 = []; 2826 v2 = []; 2827 var px = this.px; 2828 var py = this.py; 2829 if (px._caching.lastFrame + px.offsetTime <= px.keyframes[0].t) { 2830 v1[0] = px.getValueAtTime((px.keyframes[0].t + 0.01) / frameRate, 0); 2831 v1[1] = py.getValueAtTime((py.keyframes[0].t + 0.01) / frameRate, 0); 2832 v2[0] = px.getValueAtTime((px.keyframes[0].t) / frameRate, 0); 2833 v2[1] = py.getValueAtTime((py.keyframes[0].t) / frameRate, 0); 2834 } else if (px._caching.lastFrame + px.offsetTime >= px.keyframes[px.keyframes.length - 1].t) { 2835 v1[0] = px.getValueAtTime((px.keyframes[px.keyframes.length - 1].t / frameRate), 0); 2836 v1[1] = py.getValueAtTime((py.keyframes[py.keyframes.length - 1].t / frameRate), 0); 2837 v2[0] = px.getValueAtTime((px.keyframes[px.keyframes.length - 1].t - 0.01) / frameRate, 0); 2838 v2[1] = py.getValueAtTime((py.keyframes[py.keyframes.length - 1].t - 0.01) / frameRate, 0); 2839 } else { 2840 v1 = [px.pv, py.pv]; 2841 v2[0] = px.getValueAtTime((px._caching.lastFrame + px.offsetTime - 0.01) / frameRate, px.offsetTime); 2842 v2[1] = py.getValueAtTime((py._caching.lastFrame + py.offsetTime - 0.01) / frameRate, py.offsetTime); 2843 } 2844 } else { 2845 v2 = defaultVector; 2846 v1 = v2; 2847 } 2848 this.v.rotate(-Math.atan2(v1[1] - v2[1], v1[0] - v2[0])); 2849 } 2850 if (this.data.p && this.data.p.s) { 2851 if (this.data.p.z) { 2852 this.v.translate(this.px.v, this.py.v, -this.pz.v); 2853 } else { 2854 this.v.translate(this.px.v, this.py.v, 0); 2855 } 2856 } else { 2857 this.v.translate(this.p.v[0], this.p.v[1], -this.p.v[2]); 2858 } 2859 } 2860 this.frameId = this.elem.globalData.frameId; 2861 } 2862 2863 function precalculateMatrix() { 2864 if (!this.a.k) { 2865 this.pre.translate(-this.a.v[0], -this.a.v[1], this.a.v[2]); 2866 this.appliedTransformations = 1; 2867 } else { 2868 return; 2869 } 2870 if (!this.s.effectsSequence.length) { 2871 this.pre.scale(this.s.v[0], this.s.v[1], this.s.v[2]); 2872 this.appliedTransformations = 2; 2873 } else { 2874 return; 2875 } 2876 if (this.sk) { 2877 if (!this.sk.effectsSequence.length && !this.sa.effectsSequence.length) { 2878 this.pre.skewFromAxis(-this.sk.v, this.sa.v); 2879 this.appliedTransformations = 3; 2880 } else { 2881 return; 2882 } 2883 } 2884 if (this.r) { 2885 if (!this.r.effectsSequence.length) { 2886 this.pre.rotate(-this.r.v); 2887 this.appliedTransformations = 4; 2888 } 2889 } else if (!this.rz.effectsSequence.length && !this.ry.effectsSequence.length && !this.rx.effectsSequence.length && !this.or.effectsSequence.length) { 2890 this.pre.rotateZ(-this.rz.v).rotateY(this.ry.v).rotateX(this.rx.v).rotateZ(-this.or.v[2]) 2891 .rotateY(this.or.v[1]) 2892 .rotateX(this.or.v[0]); 2893 this.appliedTransformations = 4; 2894 } 2895 } 2896 2897 function autoOrient() { 2898 // 2899 // var prevP = this.getValueAtTime(); 2900 } 2901 2902 function addDynamicProperty(prop) { 2903 this._addDynamicProperty(prop); 2904 this.elem.addDynamicProperty(prop); 2905 this._isDirty = true; 2906 } 2907 2908 function TransformProperty(elem, data, container) { 2909 this.elem = elem; 2910 this.frameId = -1; 2911 this.propType = 'transform'; 2912 this.data = data; 2913 this.v = new Matrix(); 2914 // Precalculated matrix with non animated properties 2915 this.pre = new Matrix(); 2916 this.appliedTransformations = 0; 2917 this.initDynamicPropertyContainer(container || elem); 2918 if (data.p && data.p.s) { 2919 this.px = PropertyFactory.getProp(elem, data.p.x, 0, 0, this); 2920 this.py = PropertyFactory.getProp(elem, data.p.y, 0, 0, this); 2921 if (data.p.z) { 2922 this.pz = PropertyFactory.getProp(elem, data.p.z, 0, 0, this); 2923 } 2924 } else { 2925 this.p = PropertyFactory.getProp(elem, data.p || { k: [0, 0, 0] }, 1, 0, this); 2926 } 2927 if (data.rx) { 2928 this.rx = PropertyFactory.getProp(elem, data.rx, 0, degToRads, this); 2929 this.ry = PropertyFactory.getProp(elem, data.ry, 0, degToRads, this); 2930 this.rz = PropertyFactory.getProp(elem, data.rz, 0, degToRads, this); 2931 if (data.or.k[0].ti) { 2932 var i; 2933 var len = data.or.k.length; 2934 for (i = 0; i < len; i += 1) { 2935 data.or.k[i].to = null; 2936 data.or.k[i].ti = null; 2937 } 2938 } 2939 this.or = PropertyFactory.getProp(elem, data.or, 1, degToRads, this); 2940 // sh Indicates it needs to be capped between -180 and 180 2941 this.or.sh = true; 2942 } else { 2943 this.r = PropertyFactory.getProp(elem, data.r || { k: 0 }, 0, degToRads, this); 2944 } 2945 if (data.sk) { 2946 this.sk = PropertyFactory.getProp(elem, data.sk, 0, degToRads, this); 2947 this.sa = PropertyFactory.getProp(elem, data.sa, 0, degToRads, this); 2948 } 2949 this.a = PropertyFactory.getProp(elem, data.a || { k: [0, 0, 0] }, 1, 0, this); 2950 this.s = PropertyFactory.getProp(elem, data.s || { k: [100, 100, 100] }, 1, 0.01, this); 2951 // 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. 2952 if (data.o) { 2953 this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, elem); 2954 } else { 2955 this.o = { _mdf: false, v: 1 }; 2956 } 2957 this._isDirty = true; 2958 if (!this.dynamicProperties.length) { 2959 this.getValue(true); 2960 } 2961 } 2962 2963 TransformProperty.prototype = { 2964 applyToMatrix: applyToMatrix, 2965 getValue: processKeys, 2966 precalculateMatrix: precalculateMatrix, 2967 autoOrient: autoOrient, 2968 }; 2969 2970 extendPrototype([DynamicPropertyContainer], TransformProperty); 2971 TransformProperty.prototype.addDynamicProperty = addDynamicProperty; 2972 TransformProperty.prototype._addDynamicProperty = DynamicPropertyContainer.prototype.addDynamicProperty; 2973 2974 function getTransformProperty(elem, data, container) { 2975 return new TransformProperty(elem, data, container); 2976 } 2977 2978 return { 2979 getTransformProperty: getTransformProperty, 2980 }; 2981}()); 2982 2983/* global createSizedArray, createSizedArray, pointPool */ 2984 2985function ShapePath() { 2986 this.c = false;
vendor: 1,036 bytes, lines 2987-3023
2987 this._length = 0; 2988 this._maxLength = 8; 2989 this.v = createSizedArray(this._maxLength); 2990 this.o = createSizedArray(this._maxLength); 2991 this.i = createSizedArray(this._maxLength); 2992} 2993 2994ShapePath.prototype.setPathData = function (closed, len) { 2995 this.c = closed; 2996 this.setLength(len); 2997 var i = 0; 2998 while (i < len) { 2999 this.v[i] = pointPool.newElement(); 3000 this.o[i] = pointPool.newElement(); 3001 this.i[i] = pointPool.newElement(); 3002 i += 1; 3003 } 3004}; 3005 3006ShapePath.prototype.setLength = function (len) { 3007 while (this._maxLength < len) { 3008 this.doubleArrayLength(); 3009 } 3010 this._length = len; 3011}; 3012 3013ShapePath.prototype.doubleArrayLength = function () { 3014 this.v = this.v.concat(createSizedArray(this._maxLength)); 3015 this.i = this.i.concat(createSizedArray(this._maxLength)); 3016 this.o = this.o.concat(createSizedArray(this._maxLength)); 3017 this._maxLength *= 2; 3018}; 3019 3020ShapePath.prototype.setXYAt = function (x, y, type, pos, replace) { 3021 var arr; 3022 this._length = Math.max(this._length, pos + 1); 3023 if (this._length >= this._maxLength) {
vendor: 4,993 bytes, lines 3024-3182
3024 this.doubleArrayLength(); 3025 } 3026 switch (type) { 3027 case 'v': 3028 arr = this.v; 3029 break; 3030 case 'i': 3031 arr = this.i; 3032 break; 3033 case 'o': 3034 arr = this.o; 3035 break; 3036 default: 3037 arr = []; 3038 break; 3039 } 3040 if (!arr[pos] || (arr[pos] && !replace)) { 3041 arr[pos] = pointPool.newElement(); 3042 } 3043 arr[pos][0] = x; 3044 arr[pos][1] = y; 3045}; 3046 3047ShapePath.prototype.setTripleAt = function (vX, vY, oX, oY, iX, iY, pos, replace) { 3048 this.setXYAt(vX, vY, 'v', pos, replace); 3049 this.setXYAt(oX, oY, 'o', pos, replace); 3050 this.setXYAt(iX, iY, 'i', pos, replace); 3051}; 3052 3053ShapePath.prototype.reverse = function () { 3054 var newPath = new ShapePath(); 3055 newPath.setPathData(this.c, this._length); 3056 var vertices = this.v; 3057 var outPoints = this.o; 3058 var inPoints = this.i; 3059 var init = 0; 3060 if (this.c) { 3061 newPath.setTripleAt(vertices[0][0], vertices[0][1], inPoints[0][0], inPoints[0][1], outPoints[0][0], outPoints[0][1], 0, false); 3062 init = 1; 3063 } 3064 var cnt = this._length - 1; 3065 var len = this._length; 3066 3067 var i; 3068 for (i = init; i < len; i += 1) { 3069 newPath.setTripleAt(vertices[cnt][0], vertices[cnt][1], inPoints[cnt][0], inPoints[cnt][1], outPoints[cnt][0], outPoints[cnt][1], i, false); 3070 cnt -= 1; 3071 } 3072 return newPath; 3073}; 3074 3075/* global extendPrototype, roundCorner, BezierFactory, shapePool, degToRads, 3076 shapeCollectionPool, PropertyFactory, bmMin, DynamicPropertyContainer */ 3077/* exported ShapePropertyFactory */ 3078 3079var ShapePropertyFactory = (function () { 3080 var initFrame = -999999; 3081 3082 function interpolateShape(frameNum, previousValue, caching) { 3083 var iterationIndex = caching.lastIndex; 3084 var keyPropS; 3085 var keyPropE; 3086 var isHold; 3087 var j; 3088 var k; 3089 var jLen; 3090 var kLen; 3091 var perc; 3092 var vertexValue; 3093 var kf = this.keyframes; 3094 if (frameNum < kf[0].t - this.offsetTime) { 3095 keyPropS = kf[0].s[0]; 3096 isHold = true; 3097 iterationIndex = 0; 3098 } else if (frameNum >= kf[kf.length - 1].t - this.offsetTime) { 3099 keyPropS = kf[kf.length - 1].s ? kf[kf.length - 1].s[0] : kf[kf.length - 2].e[0]; 3100 /* if(kf[kf.length - 1].s){ 3101 keyPropS = kf[kf.length - 1].s[0]; 3102 }else{ 3103 keyPropS = kf[kf.length - 2].e[0]; 3104 } */ 3105 isHold = true; 3106 } else { 3107 var i = iterationIndex; 3108 var len = kf.length - 1; 3109 var flag = true; 3110 var keyData; 3111 var nextKeyData; 3112 while (flag) { 3113 keyData = kf[i]; 3114 nextKeyData = kf[i + 1]; 3115 if ((nextKeyData.t - this.offsetTime) > frameNum) { 3116 break; 3117 } 3118 if (i < len - 1) { 3119 i += 1; 3120 } else { 3121 flag = false; 3122 } 3123 } 3124 isHold = keyData.h === 1; 3125 iterationIndex = i; 3126 if (!isHold) { 3127 if (frameNum >= nextKeyData.t - this.offsetTime) { 3128 perc = 1; 3129 } else if (frameNum < keyData.t - this.offsetTime) { 3130 perc = 0; 3131 } else { 3132 var fnc; 3133 if (keyData.__fnct) { 3134 fnc = keyData.__fnct; 3135 } else { 3136 fnc = BezierFactory.getBezierEasing(keyData.o.x, keyData.o.y, keyData.i.x, keyData.i.y).get; 3137 keyData.__fnct = fnc; 3138 } 3139 perc = fnc((frameNum - (keyData.t - this.offsetTime)) / ((nextKeyData.t - this.offsetTime) - (keyData.t - this.offsetTime))); 3140 } 3141 keyPropE = nextKeyData.s ? nextKeyData.s[0] : keyData.e[0]; 3142 } 3143 keyPropS = keyData.s[0]; 3144 } 3145 jLen = previousValue._length; 3146 kLen = keyPropS.i[0].length; 3147 caching.lastIndex = iterationIndex; 3148 3149 for (j = 0; j < jLen; j += 1) { 3150 for (k = 0; k < kLen; k += 1) { 3151 vertexValue = isHold ? keyPropS.i[j][k] : keyPropS.i[j][k] + (keyPropE.i[j][k] - keyPropS.i[j][k]) * perc; 3152 previousValue.i[j][k] = vertexValue; 3153 vertexValue = isHold ? keyPropS.o[j][k] : keyPropS.o[j][k] + (keyPropE.o[j][k] - keyPropS.o[j][k]) * perc; 3154 previousValue.o[j][k] = vertexValue; 3155 vertexValue = isHold ? keyPropS.v[j][k] : keyPropS.v[j][k] + (keyPropE.v[j][k] - keyPropS.v[j][k]) * perc; 3156 previousValue.v[j][k] = vertexValue; 3157 } 3158 } 3159 } 3160 3161 function interpolateShapeCurrentTime() { 3162 var frameNum = this.comp.renderedFrame - this.offsetTime; 3163 var initTime = this.keyframes[0].t - this.offsetTime; 3164 var endTime = this.keyframes[this.keyframes.length - 1].t - this.offsetTime; 3165 var lastFrame = this._caching.lastFrame; 3166 if (!(lastFrame !== initFrame && ((lastFrame < initTime && frameNum < initTime) || (lastFrame > endTime && frameNum > endTime)))) { 3167 /// / 3168 this._caching.lastIndex = lastFrame < frameNum ? this._caching.lastIndex : 0; 3169 this.interpolateShape(frameNum, this.pv, this._caching); 3170 /// / 3171 } 3172 this._caching.lastFrame = frameNum; 3173 return this.pv; 3174 } 3175 3176 function resetShape() { 3177 this.paths = this.localShapeCollection; 3178 } 3179 3180 function shapesEqual(shape1, shape2) { 3181 if (shape1._length !== shape2._length || shape1.c !== shape2.c) { 3182 return false;
vendor: 15,754 bytes, lines 3183-3591
3183 } 3184 var i; 3185 var len = shape1._length; 3186 for (i = 0; i < len; i += 1) { 3187 if (shape1.v[i][0] !== shape2.v[i][0] 3188 || shape1.v[i][1] !== shape2.v[i][1] 3189 || shape1.o[i][0] !== shape2.o[i][0] 3190 || shape1.o[i][1] !== shape2.o[i][1] 3191 || shape1.i[i][0] !== shape2.i[i][0] 3192 || shape1.i[i][1] !== shape2.i[i][1]) { 3193 return false; 3194 } 3195 } 3196 return true; 3197 } 3198 3199 function setVValue(newPath) { 3200 if (!shapesEqual(this.v, newPath)) { 3201 this.v = shapePool.clone(newPath); 3202 this.localShapeCollection.releaseShapes(); 3203 this.localShapeCollection.addShape(this.v); 3204 this._mdf = true; 3205 this.paths = this.localShapeCollection; 3206 } 3207 } 3208 3209 function processEffectsSequence() { 3210 if (this.elem.globalData.frameId === this.frameId) { 3211 return; 3212 } if (!this.effectsSequence.length) { 3213 this._mdf = false; 3214 return; 3215 } 3216 if (this.lock) { 3217 this.setVValue(this.pv); 3218 return; 3219 } 3220 this.lock = true; 3221 this._mdf = false; 3222 var finalValue; 3223 if (this.kf) { 3224 finalValue = this.pv; 3225 } else if (this.data.ks) { 3226 finalValue = this.data.ks.k; 3227 } else { 3228 finalValue = this.data.pt.k; 3229 } 3230 var i; 3231 var len = this.effectsSequence.length; 3232 for (i = 0; i < len; i += 1) { 3233 finalValue = this.effectsSequence[i](finalValue); 3234 } 3235 this.setVValue(finalValue); 3236 this.lock = false; 3237 this.frameId = this.elem.globalData.frameId; 3238 } 3239 3240 function ShapeProperty(elem, data, type) { 3241 this.propType = 'shape'; 3242 this.comp = elem.comp; 3243 this.container = elem; 3244 this.elem = elem; 3245 this.data = data; 3246 this.k = false; 3247 this.kf = false; 3248 this._mdf = false; 3249 var pathData = type === 3 ? data.pt.k : data.ks.k; 3250 this.v = shapePool.clone(pathData); 3251 this.pv = shapePool.clone(this.v); 3252 this.localShapeCollection = shapeCollectionPool.newShapeCollection(); 3253 this.paths = this.localShapeCollection; 3254 this.paths.addShape(this.v); 3255 this.reset = resetShape; 3256 this.effectsSequence = []; 3257 } 3258 3259 function addEffect(effectFunction) { 3260 this.effectsSequence.push(effectFunction); 3261 this.container.addDynamicProperty(this); 3262 } 3263 3264 ShapeProperty.prototype.interpolateShape = interpolateShape; 3265 ShapeProperty.prototype.getValue = processEffectsSequence; 3266 ShapeProperty.prototype.setVValue = setVValue; 3267 ShapeProperty.prototype.addEffect = addEffect; 3268 3269 function KeyframedShapeProperty(elem, data, type) { 3270 this.propType = 'shape'; 3271 this.comp = elem.comp; 3272 this.elem = elem; 3273 this.container = elem; 3274 this.offsetTime = elem.data.st; 3275 this.keyframes = type === 3 ? data.pt.k : data.ks.k; 3276 this.k = true; 3277 this.kf = true; 3278 var len = this.keyframes[0].s[0].i.length; 3279 this.v = shapePool.newElement(); 3280 this.v.setPathData(this.keyframes[0].s[0].c, len); 3281 this.pv = shapePool.clone(this.v); 3282 this.localShapeCollection = shapeCollectionPool.newShapeCollection(); 3283 this.paths = this.localShapeCollection; 3284 this.paths.addShape(this.v); 3285 this.lastFrame = initFrame; 3286 this.reset = resetShape; 3287 this._caching = { lastFrame: initFrame, lastIndex: 0 }; 3288 this.effectsSequence = [interpolateShapeCurrentTime.bind(this)]; 3289 } 3290 KeyframedShapeProperty.prototype.getValue = processEffectsSequence; 3291 KeyframedShapeProperty.prototype.interpolateShape = interpolateShape; 3292 KeyframedShapeProperty.prototype.setVValue = setVValue; 3293 KeyframedShapeProperty.prototype.addEffect = addEffect; 3294 3295 var EllShapeProperty = (function () { 3296 var cPoint = roundCorner; 3297 3298 function EllShapePropertyFactory(elem, data) { 3299 /* this.v = { 3300 v: createSizedArray(4), 3301 i: createSizedArray(4), 3302 o: createSizedArray(4), 3303 c: true 3304 }; */ 3305 this.v = shapePool.newElement(); 3306 this.v.setPathData(true, 4); 3307 this.localShapeCollection = shapeCollectionPool.newShapeCollection(); 3308 this.paths = this.localShapeCollection; 3309 this.localShapeCollection.addShape(this.v); 3310 this.d = data.d; 3311 this.elem = elem; 3312 this.comp = elem.comp; 3313 this.frameId = -1; 3314 this.initDynamicPropertyContainer(elem); 3315 this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this); 3316 this.s = PropertyFactory.getProp(elem, data.s, 1, 0, this); 3317 if (this.dynamicProperties.length) { 3318 this.k = true; 3319 } else { 3320 this.k = false; 3321 this.convertEllToPath(); 3322 } 3323 } 3324 3325 EllShapePropertyFactory.prototype = { 3326 reset: resetShape, 3327 getValue: function () { 3328 if (this.elem.globalData.frameId === this.frameId) { 3329 return; 3330 } 3331 this.frameId = this.elem.globalData.frameId; 3332 this.iterateDynamicProperties(); 3333 3334 if (this._mdf) { 3335 this.convertEllToPath(); 3336 } 3337 }, 3338 convertEllToPath: function () { 3339 var p0 = this.p.v[0]; 3340 var p1 = this.p.v[1]; 3341 var s0 = this.s.v[0] / 2; 3342 var s1 = this.s.v[1] / 2; 3343 var _cw = this.d !== 3; 3344 var _v = this.v; 3345 _v.v[0][0] = p0; 3346 _v.v[0][1] = p1 - s1; 3347 _v.v[1][0] = _cw ? p0 + s0 : p0 - s0; 3348 _v.v[1][1] = p1; 3349 _v.v[2][0] = p0; 3350 _v.v[2][1] = p1 + s1; 3351 _v.v[3][0] = _cw ? p0 - s0 : p0 + s0; 3352 _v.v[3][1] = p1; 3353 _v.i[0][0] = _cw ? p0 - s0 * cPoint : p0 + s0 * cPoint; 3354 _v.i[0][1] = p1 - s1; 3355 _v.i[1][0] = _cw ? p0 + s0 : p0 - s0; 3356 _v.i[1][1] = p1 - s1 * cPoint; 3357 _v.i[2][0] = _cw ? p0 + s0 * cPoint : p0 - s0 * cPoint; 3358 _v.i[2][1] = p1 + s1; 3359 _v.i[3][0] = _cw ? p0 - s0 : p0 + s0; 3360 _v.i[3][1] = p1 + s1 * cPoint; 3361 _v.o[0][0] = _cw ? p0 + s0 * cPoint : p0 - s0 * cPoint; 3362 _v.o[0][1] = p1 - s1; 3363 _v.o[1][0] = _cw ? p0 + s0 : p0 - s0; 3364 _v.o[1][1] = p1 + s1 * cPoint; 3365 _v.o[2][0] = _cw ? p0 - s0 * cPoint : p0 + s0 * cPoint; 3366 _v.o[2][1] = p1 + s1; 3367 _v.o[3][0] = _cw ? p0 - s0 : p0 + s0; 3368 _v.o[3][1] = p1 - s1 * cPoint; 3369 }, 3370 }; 3371 3372 extendPrototype([DynamicPropertyContainer], EllShapePropertyFactory); 3373 3374 return EllShapePropertyFactory; 3375 }()); 3376 3377 var StarShapeProperty = (function () { 3378 function StarShapePropertyFactory(elem, data) { 3379 this.v = shapePool.newElement(); 3380 this.v.setPathData(true, 0); 3381 this.elem = elem; 3382 this.comp = elem.comp; 3383 this.data = data; 3384 this.frameId = -1; 3385 this.d = data.d; 3386 this.initDynamicPropertyContainer(elem); 3387 if (data.sy === 1) { 3388 this.ir = PropertyFactory.getProp(elem, data.ir, 0, 0, this); 3389 this.is = PropertyFactory.getProp(elem, data.is, 0, 0.01, this); 3390 this.convertToPath = this.convertStarToPath; 3391 } else { 3392 this.convertToPath = this.convertPolygonToPath; 3393 } 3394 this.pt = PropertyFactory.getProp(elem, data.pt, 0, 0, this); 3395 this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this); 3396 this.r = PropertyFactory.getProp(elem, data.r, 0, degToRads, this); 3397 this.or = PropertyFactory.getProp(elem, data.or, 0, 0, this); 3398 this.os = PropertyFactory.getProp(elem, data.os, 0, 0.01, this); 3399 this.localShapeCollection = shapeCollectionPool.newShapeCollection(); 3400 this.localShapeCollection.addShape(this.v); 3401 this.paths = this.localShapeCollection; 3402 if (this.dynamicProperties.length) { 3403 this.k = true; 3404 } else { 3405 this.k = false; 3406 this.convertToPath(); 3407 } 3408 } 3409 3410 StarShapePropertyFactory.prototype = { 3411 reset: resetShape, 3412 getValue: function () { 3413 if (this.elem.globalData.frameId === this.frameId) { 3414 return; 3415 } 3416 this.frameId = this.elem.globalData.frameId; 3417 this.iterateDynamicProperties(); 3418 if (this._mdf) { 3419 this.convertToPath(); 3420 } 3421 }, 3422 convertStarToPath: function () { 3423 var numPts = Math.floor(this.pt.v) * 2; 3424 var angle = (Math.PI * 2) / numPts; 3425 /* this.v.v.length = numPts; 3426 this.v.i.length = numPts; 3427 this.v.o.length = numPts; */ 3428 var longFlag = true; 3429 var longRad = this.or.v; 3430 var shortRad = this.ir.v; 3431 var longRound = this.os.v; 3432 var shortRound = this.is.v; 3433 var longPerimSegment = (2 * Math.PI * longRad) / (numPts * 2); 3434 var shortPerimSegment = (2 * Math.PI * shortRad) / (numPts * 2); 3435 var i; 3436 var rad; 3437 var roundness; 3438 var perimSegment; 3439 var currentAng = -Math.PI / 2; 3440 currentAng += this.r.v; 3441 var dir = this.data.d === 3 ? -1 : 1; 3442 this.v._length = 0; 3443 for (i = 0; i < numPts; i += 1) { 3444 rad = longFlag ? longRad : shortRad; 3445 roundness = longFlag ? longRound : shortRound; 3446 perimSegment = longFlag ? longPerimSegment : shortPerimSegment; 3447 var x = rad * Math.cos(currentAng); 3448 var y = rad * Math.sin(currentAng); 3449 var ox = x === 0 && y === 0 ? 0 : y / Math.sqrt(x * x + y * y); 3450 var oy = x === 0 && y === 0 ? 0 : -x / Math.sqrt(x * x + y * y); 3451 x += +this.p.v[0]; 3452 y += +this.p.v[1]; 3453 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); 3454 3455 /* this.v.v[i] = [x,y]; 3456 this.v.i[i] = [x+ox*perimSegment*roundness*dir,y+oy*perimSegment*roundness*dir]; 3457 this.v.o[i] = [x-ox*perimSegment*roundness*dir,y-oy*perimSegment*roundness*dir]; 3458 this.v._length = numPts; */ 3459 longFlag = !longFlag; 3460 currentAng += angle * dir; 3461 } 3462 }, 3463 convertPolygonToPath: function () { 3464 var numPts = Math.floor(this.pt.v); 3465 var angle = (Math.PI * 2) / numPts; 3466 var rad = this.or.v; 3467 var roundness = this.os.v; 3468 var perimSegment = (2 * Math.PI * rad) / (numPts * 4); 3469 var i; 3470 var currentAng = -Math.PI * 0.5; 3471 var dir = this.data.d === 3 ? -1 : 1; 3472 currentAng += this.r.v; 3473 this.v._length = 0; 3474 for (i = 0; i < numPts; i += 1) { 3475 var x = rad * Math.cos(currentAng); 3476 var y = rad * Math.sin(currentAng); 3477 var ox = x === 0 && y === 0 ? 0 : y / Math.sqrt(x * x + y * y); 3478 var oy = x === 0 && y === 0 ? 0 : -x / Math.sqrt(x * x + y * y); 3479 x += +this.p.v[0]; 3480 y += +this.p.v[1]; 3481 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); 3482 currentAng += angle * dir; 3483 } 3484 this.paths.length = 0; 3485 this.paths[0] = this.v; 3486 }, 3487 3488 }; 3489 extendPrototype([DynamicPropertyContainer], StarShapePropertyFactory); 3490 3491 return StarShapePropertyFactory; 3492 }()); 3493 3494 var RectShapeProperty = (function () { 3495 function RectShapePropertyFactory(elem, data) { 3496 this.v = shapePool.newElement(); 3497 this.v.c = true; 3498 this.localShapeCollection = shapeCollectionPool.newShapeCollection(); 3499 this.localShapeCollection.addShape(this.v); 3500 this.paths = this.localShapeCollection; 3501 this.elem = elem; 3502 this.comp = elem.comp; 3503 this.frameId = -1; 3504 this.d = data.d; 3505 this.initDynamicPropertyContainer(elem); 3506 this.p = PropertyFactory.getProp(elem, data.p, 1, 0, this); 3507 this.s = PropertyFactory.getProp(elem, data.s, 1, 0, this); 3508 this.r = PropertyFactory.getProp(elem, data.r, 0, 0, this); 3509 if (this.dynamicProperties.length) { 3510 this.k = true; 3511 } else { 3512 this.k = false; 3513 this.convertRectToPath(); 3514 } 3515 } 3516 3517 RectShapePropertyFactory.prototype = { 3518 convertRectToPath: function () { 3519 var p0 = this.p.v[0]; 3520 var p1 = this.p.v[1]; 3521 var v0 = this.s.v[0] / 2; 3522 var v1 = this.s.v[1] / 2; 3523 var round = bmMin(v0, v1, this.r.v); 3524 var cPoint = round * (1 - roundCorner); 3525 this.v._length = 0; 3526 3527 if (this.d === 2 || this.d === 1) { 3528 this.v.setTripleAt(p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + cPoint, 0, true); 3529 this.v.setTripleAt(p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - cPoint, p0 + v0, p1 + v1 - round, 1, true); 3530 if (round !== 0) { 3531 this.v.setTripleAt(p0 + v0 - round, p1 + v1, p0 + v0 - round, p1 + v1, p0 + v0 - cPoint, p1 + v1, 2, true); 3532 this.v.setTripleAt(p0 - v0 + round, p1 + v1, p0 - v0 + cPoint, p1 + v1, p0 - v0 + round, p1 + v1, 3, true); 3533 this.v.setTripleAt(p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - cPoint, 4, true); 3534 this.v.setTripleAt(p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + cPoint, p0 - v0, p1 - v1 + round, 5, true); 3535 this.v.setTripleAt(p0 - v0 + round, p1 - v1, p0 - v0 + round, p1 - v1, p0 - v0 + cPoint, p1 - v1, 6, true); 3536 this.v.setTripleAt(p0 + v0 - round, p1 - v1, p0 + v0 - cPoint, p1 - v1, p0 + v0 - round, p1 - v1, 7, true); 3537 } else { 3538 this.v.setTripleAt(p0 - v0, p1 + v1, p0 - v0 + cPoint, p1 + v1, p0 - v0, p1 + v1, 2); 3539 this.v.setTripleAt(p0 - v0, p1 - v1, p0 - v0, p1 - v1 + cPoint, p0 - v0, p1 - v1, 3); 3540 } 3541 } else { 3542 this.v.setTripleAt(p0 + v0, p1 - v1 + round, p0 + v0, p1 - v1 + cPoint, p0 + v0, p1 - v1 + round, 0, true); 3543 if (round !== 0) { 3544 this.v.setTripleAt(p0 + v0 - round, p1 - v1, p0 + v0 - round, p1 - v1, p0 + v0 - cPoint, p1 - v1, 1, true); 3545 this.v.setTripleAt(p0 - v0 + round, p1 - v1, p0 - v0 + cPoint, p1 - v1, p0 - v0 + round, p1 - v1, 2, true); 3546 this.v.setTripleAt(p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + round, p0 - v0, p1 - v1 + cPoint, 3, true); 3547 this.v.setTripleAt(p0 - v0, p1 + v1 - round, p0 - v0, p1 + v1 - cPoint, p0 - v0, p1 + v1 - round, 4, true); 3548 this.v.setTripleAt(p0 - v0 + round, p1 + v1, p0 - v0 + round, p1 + v1, p0 - v0 + cPoint, p1 + v1, 5, true); 3549 this.v.setTripleAt(p0 + v0 - round, p1 + v1, p0 + v0 - cPoint, p1 + v1, p0 + v0 - round, p1 + v1, 6, true); 3550 this.v.setTripleAt(p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - round, p0 + v0, p1 + v1 - cPoint, 7, true); 3551 } else { 3552 this.v.setTripleAt(p0 - v0, p1 - v1, p0 - v0 + cPoint, p1 - v1, p0 - v0, p1 - v1, 1, true); 3553 this.v.setTripleAt(p0 - v0, p1 + v1, p0 - v0, p1 + v1 - cPoint, p0 - v0, p1 + v1, 2, true); 3554 this.v.setTripleAt(p0 + v0, p1 + v1, p0 + v0 - cPoint, p1 + v1, p0 + v0, p1 + v1, 3, true); 3555 } 3556 } 3557 }, 3558 getValue: function () { 3559 if (this.elem.globalData.frameId === this.frameId) { 3560 return; 3561 } 3562 this.frameId = this.elem.globalData.frameId; 3563 this.iterateDynamicProperties(); 3564 if (this._mdf) { 3565 this.convertRectToPath(); 3566 } 3567 }, 3568 reset: resetShape, 3569 }; 3570 extendPrototype([DynamicPropertyContainer], RectShapePropertyFactory); 3571 3572 return RectShapePropertyFactory; 3573 }()); 3574 3575 function getShapeProp(elem, data, type) { 3576 var prop; 3577 if (type === 3 || type === 4) { 3578 var dataProp = type === 3 ? data.pt : data.ks; 3579 var keys = dataProp.k; 3580 if (keys.length) { 3581 prop = new KeyframedShapeProperty(elem, data, type); 3582 } else { 3583 prop = new ShapeProperty(elem, data, type); 3584 } 3585 } else if (type === 5) { 3586 prop = new RectShapeProperty(elem, data); 3587 } else if (type === 6) { 3588 prop = new EllShapeProperty(elem, data); 3589 } else if (type === 7) { 3590 prop = new StarShapeProperty(elem, data); 3591 }
vendor: 2,350 bytes, lines 3592-3674
3592 if (prop.k) { 3593 elem.addDynamicProperty(prop); 3594 } 3595 return prop; 3596 } 3597 3598 function getConstructorFunction() { 3599 return ShapeProperty; 3600 } 3601 3602 function getKeyframedConstructorFunction() { 3603 return KeyframedShapeProperty; 3604 } 3605 3606 var ob = {}; 3607 ob.getShapeProp = getShapeProp; 3608 ob.getConstructorFunction = getConstructorFunction; 3609 ob.getKeyframedConstructorFunction = getKeyframedConstructorFunction; 3610 return ob; 3611}()); 3612 3613/* global shapeCollectionPool, initialDefaultFrame, extendPrototype, DynamicPropertyContainer */ 3614/* exported ShapeModifiers */ 3615 3616var ShapeModifiers = (function () { 3617 var ob = {}; 3618 var modifiers = {}; 3619 ob.registerModifier = registerModifier; 3620 ob.getModifier = getModifier; 3621 3622 function registerModifier(nm, factory) { 3623 if (!modifiers[nm]) { 3624 modifiers[nm] = factory; 3625 } 3626 } 3627 3628 function getModifier(nm, elem, data) { 3629 return new modifiers[nm](elem, data); 3630 } 3631 3632 return ob; 3633}()); 3634 3635function ShapeModifier() {} 3636ShapeModifier.prototype.initModifierProperties = function () {}; 3637ShapeModifier.prototype.addShapeToModifier = function () {}; 3638ShapeModifier.prototype.addShape = function (data) { 3639 if (!this.closed) { 3640 // 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. 3641 data.sh.container.addDynamicProperty(data.sh); 3642 var shapeData = { shape: data.sh, data: data, localShapeCollection: shapeCollectionPool.newShapeCollection() }; 3643 this.shapes.push(shapeData); 3644 this.addShapeToModifier(shapeData); 3645 if (this._isAnimated) { 3646 data.setAsAnimated(); 3647 } 3648 } 3649}; 3650ShapeModifier.prototype.init = function (elem, data) { 3651 this.shapes = []; 3652 this.elem = elem; 3653 this.initDynamicPropertyContainer(elem); 3654 this.initModifierProperties(elem, data); 3655 this.frameId = initialDefaultFrame; 3656 this.closed = false; 3657 this.k = false; 3658 if (this.dynamicProperties.length) { 3659 this.k = true; 3660 } else { 3661 this.getValue(true); 3662 } 3663}; 3664ShapeModifier.prototype.processKeys = function () { 3665 if (this.elem.globalData.frameId === this.frameId) { 3666 return; 3667 } 3668 this.frameId = this.elem.globalData.frameId; 3669 this.iterateDynamicProperties(); 3670}; 3671 3672extendPrototype([DynamicPropertyContainer], ShapeModifier); 3673 3674/* global extendPrototype, ShapeModifier, PropertyFactory, segmentsLengthPool, bez, shapePool, ShapeModifiers */
vendor: 11,784 bytes, lines 3674-4022
3674 3675 3676function TrimModifier() { 3677} 3678extendPrototype([ShapeModifier], TrimModifier); 3679TrimModifier.prototype.initModifierProperties = function (elem, data) { 3680 this.s = PropertyFactory.getProp(elem, data.s, 0, 0.01, this); 3681 this.e = PropertyFactory.getProp(elem, data.e, 0, 0.01, this); 3682 this.o = PropertyFactory.getProp(elem, data.o, 0, 0, this); 3683 this.sValue = 0; 3684 this.eValue = 0; 3685 this.getValue = this.processKeys; 3686 this.m = data.m; 3687 this._isAnimated = !!this.s.effectsSequence.length || !!this.e.effectsSequence.length || !!this.o.effectsSequence.length; 3688}; 3689 3690TrimModifier.prototype.addShapeToModifier = function (shapeData) { 3691 shapeData.pathsData = []; 3692}; 3693 3694TrimModifier.prototype.calculateShapeEdges = function (s, e, shapeLength, addedLength, totalModifierLength) { 3695 var segments = []; 3696 if (e <= 1) { 3697 segments.push({ 3698 s: s, 3699 e: e, 3700 }); 3701 } else if (s >= 1) { 3702 segments.push({ 3703 s: s - 1, 3704 e: e - 1, 3705 }); 3706 } else { 3707 segments.push({ 3708 s: s, 3709 e: 1, 3710 }); 3711 segments.push({ 3712 s: 0, 3713 e: e - 1, 3714 }); 3715 } 3716 var shapeSegments = []; 3717 var i; 3718 var len = segments.length; 3719 var segmentOb; 3720 for (i = 0; i < len; i += 1) { 3721 segmentOb = segments[i]; 3722 if (!(segmentOb.e * totalModifierLength < addedLength || segmentOb.s * totalModifierLength > addedLength + shapeLength)) { 3723 var shapeS; 3724 var shapeE; 3725 if (segmentOb.s * totalModifierLength <= addedLength) { 3726 shapeS = 0; 3727 } else { 3728 shapeS = (segmentOb.s * totalModifierLength - addedLength) / shapeLength; 3729 } 3730 if (segmentOb.e * totalModifierLength >= addedLength + shapeLength) { 3731 shapeE = 1; 3732 } else { 3733 shapeE = ((segmentOb.e * totalModifierLength - addedLength) / shapeLength); 3734 } 3735 shapeSegments.push([shapeS, shapeE]); 3736 } 3737 } 3738 if (!shapeSegments.length) { 3739 shapeSegments.push([0, 0]); 3740 } 3741 return shapeSegments; 3742}; 3743 3744TrimModifier.prototype.releasePathsData = function (pathsData) { 3745 var i; 3746 var len = pathsData.length; 3747 for (i = 0; i < len; i += 1) { 3748 segmentsLengthPool.release(pathsData[i]); 3749 } 3750 pathsData.length = 0; 3751 return pathsData; 3752}; 3753 3754TrimModifier.prototype.processShapes = function (_isFirstFrame) { 3755 var s; 3756 var e; 3757 if (this._mdf || _isFirstFrame) { 3758 var o = (this.o.v % 360) / 360; 3759 if (o < 0) { 3760 o += 1; 3761 } 3762 if (this.s.v > 1) { 3763 s = 1 + o; 3764 } else if (this.s.v < 0) { 3765 s = 0 + o; 3766 } else { 3767 s = this.s.v + o; 3768 } 3769 if (this.e.v > 1) { 3770 e = 1 + o; 3771 } else if (this.e.v < 0) { 3772 e = 0 + o; 3773 } else { 3774 e = this.e.v + o; 3775 } 3776 3777 if (s > e) { 3778 var _s = s; 3779 s = e; 3780 e = _s; 3781 } 3782 s = Math.round(s * 10000) * 0.0001; 3783 e = Math.round(e * 10000) * 0.0001; 3784 this.sValue = s; 3785 this.eValue = e; 3786 } else { 3787 s = this.sValue; 3788 e = this.eValue; 3789 } 3790 var shapePaths; 3791 var i; 3792 var len = this.shapes.length; 3793 var j; 3794 var jLen; 3795 var pathsData; 3796 var pathData; 3797 var totalShapeLength; 3798 var totalModifierLength = 0; 3799 3800 if (e === s) { 3801 for (i = 0; i < len; i += 1) { 3802 this.shapes[i].localShapeCollection.releaseShapes(); 3803 this.shapes[i].shape._mdf = true; 3804 this.shapes[i].shape.paths = this.shapes[i].localShapeCollection; 3805 if (this._mdf) { 3806 this.shapes[i].pathsData.length = 0; 3807 } 3808 } 3809 } else if (!((e === 1 && s === 0) || (e === 0 && s === 1))) { 3810 var segments = []; 3811 var shapeData; 3812 var localShapeCollection; 3813 for (i = 0; i < len; i += 1) { 3814 shapeData = this.shapes[i]; 3815 // if shape hasn't changed and trim properties haven't changed, cached previous path can be used 3816 if (!shapeData.shape._mdf && !this._mdf && !_isFirstFrame && this.m !== 2) { 3817 shapeData.shape.paths = shapeData.localShapeCollection; 3818 } else { 3819 shapePaths = shapeData.shape.paths; 3820 jLen = shapePaths._length; 3821 totalShapeLength = 0; 3822 if (!shapeData.shape._mdf && shapeData.pathsData.length) { 3823 totalShapeLength = shapeData.totalShapeLength; 3824 } else { 3825 pathsData = this.releasePathsData(shapeData.pathsData); 3826 for (j = 0; j < jLen; j += 1) { 3827 pathData = bez.getSegmentsLength(shapePaths.shapes[j]); 3828 pathsData.push(pathData); 3829 totalShapeLength += pathData.totalLength; 3830 } 3831 shapeData.totalShapeLength = totalShapeLength; 3832 shapeData.pathsData = pathsData; 3833 } 3834 3835 totalModifierLength += totalShapeLength; 3836 shapeData.shape._mdf = true; 3837 } 3838 } 3839 var shapeS = s; 3840 var shapeE = e; 3841 var addedLength = 0; 3842 var edges; 3843 for (i = len - 1; i >= 0; i -= 1) { 3844 shapeData = this.shapes[i]; 3845 if (shapeData.shape._mdf) { 3846 localShapeCollection = shapeData.localShapeCollection; 3847 localShapeCollection.releaseShapes(); 3848 // if m === 2 means paths are trimmed individually so edges need to be found for this specific shape relative to whoel group 3849 if (this.m === 2 && len > 1) { 3850 edges = this.calculateShapeEdges(s, e, shapeData.totalShapeLength, addedLength, totalModifierLength); 3851 addedLength += shapeData.totalShapeLength; 3852 } else { 3853 edges = [[shapeS, shapeE]]; 3854 } 3855 jLen = edges.length; 3856 for (j = 0; j < jLen; j += 1) { 3857 shapeS = edges[j][0]; 3858 shapeE = edges[j][1]; 3859 segments.length = 0; 3860 if (shapeE <= 1) { 3861 segments.push({ 3862 s: shapeData.totalShapeLength * shapeS, 3863 e: shapeData.totalShapeLength * shapeE, 3864 }); 3865 } else if (shapeS >= 1) { 3866 segments.push({ 3867 s: shapeData.totalShapeLength * (shapeS - 1), 3868 e: shapeData.totalShapeLength * (shapeE - 1), 3869 }); 3870 } else { 3871 segments.push({ 3872 s: shapeData.totalShapeLength * shapeS, 3873 e: shapeData.totalShapeLength, 3874 }); 3875 segments.push({ 3876 s: 0, 3877 e: shapeData.totalShapeLength * (shapeE - 1), 3878 }); 3879 } 3880 var newShapesData = this.addShapes(shapeData, segments[0]); 3881 if (segments[0].s !== segments[0].e) { 3882 if (segments.length > 1) { 3883 var lastShapeInCollection = shapeData.shape.paths.shapes[shapeData.shape.paths._length - 1]; 3884 if (lastShapeInCollection.c) { 3885 var lastShape = newShapesData.pop(); 3886 this.addPaths(newShapesData, localShapeCollection); 3887 newShapesData = this.addShapes(shapeData, segments[1], lastShape); 3888 } else { 3889 this.addPaths(newShapesData, localShapeCollection); 3890 newShapesData = this.addShapes(shapeData, segments[1]); 3891 } 3892 } 3893 this.addPaths(newShapesData, localShapeCollection); 3894 } 3895 } 3896 shapeData.shape.paths = localShapeCollection; 3897 } 3898 } 3899 } else if (this._mdf) { 3900 for (i = 0; i < len; i += 1) { 3901 // Releasign Trim Cached paths data when no trim applied in case shapes are modified inbetween. 3902 // Don't remove this even if it's losing cached info. 3903 this.shapes[i].pathsData.length = 0; 3904 this.shapes[i].shape._mdf = true; 3905 } 3906 } 3907}; 3908 3909TrimModifier.prototype.addPaths = function (newPaths, localShapeCollection) { 3910 var i; 3911 var len = newPaths.length; 3912 for (i = 0; i < len; i += 1) { 3913 localShapeCollection.addShape(newPaths[i]); 3914 } 3915}; 3916 3917TrimModifier.prototype.addSegment = function (pt1, pt2, pt3, pt4, shapePath, pos, newShape) { 3918 shapePath.setXYAt(pt2[0], pt2[1], 'o', pos); 3919 shapePath.setXYAt(pt3[0], pt3[1], 'i', pos + 1); 3920 if (newShape) { 3921 shapePath.setXYAt(pt1[0], pt1[1], 'v', pos); 3922 } 3923 shapePath.setXYAt(pt4[0], pt4[1], 'v', pos + 1); 3924}; 3925 3926TrimModifier.prototype.addSegmentFromArray = function (points, shapePath, pos, newShape) { 3927 shapePath.setXYAt(points[1], points[5], 'o', pos); 3928 shapePath.setXYAt(points[2], points[6], 'i', pos + 1); 3929 if (newShape) { 3930 shapePath.setXYAt(points[0], points[4], 'v', pos); 3931 } 3932 shapePath.setXYAt(points[3], points[7], 'v', pos + 1); 3933}; 3934 3935TrimModifier.prototype.addShapes = function (shapeData, shapeSegment, shapePath) { 3936 var pathsData = shapeData.pathsData; 3937 var shapePaths = shapeData.shape.paths.shapes; 3938 var i; 3939 var len = shapeData.shape.paths._length; 3940 var j; 3941 var jLen; 3942 var addedLength = 0; 3943 var currentLengthData; 3944 var segmentCount; 3945 var lengths; 3946 var segment; 3947 var shapes = []; 3948 var initPos; 3949 var newShape = true; 3950 if (!shapePath) { 3951 shapePath = shapePool.newElement(); 3952 segmentCount = 0; 3953 initPos = 0; 3954 } else { 3955 segmentCount = shapePath._length; 3956 initPos = shapePath._length; 3957 } 3958 shapes.push(shapePath); 3959 for (i = 0; i < len; i += 1) { 3960 lengths = pathsData[i].lengths; 3961 shapePath.c = shapePaths[i].c; 3962 jLen = shapePaths[i].c ? lengths.length : lengths.length + 1; 3963 for (j = 1; j < jLen; j += 1) { 3964 currentLengthData = lengths[j - 1]; 3965 if (addedLength + currentLengthData.addedLength < shapeSegment.s) { 3966 addedLength += currentLengthData.addedLength; 3967 shapePath.c = false; 3968 } else if (addedLength > shapeSegment.e) { 3969 shapePath.c = false; 3970 break; 3971 } else { 3972 if (shapeSegment.s <= addedLength && shapeSegment.e >= addedLength + currentLengthData.addedLength) { 3973 this.addSegment(shapePaths[i].v[j - 1], shapePaths[i].o[j - 1], shapePaths[i].i[j], shapePaths[i].v[j], shapePath, segmentCount, newShape); 3974 newShape = false; 3975 } else { 3976 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]); 3977 this.addSegmentFromArray(segment, shapePath, segmentCount, newShape); 3978 // this.addSegment(segment.pt1, segment.pt3, segment.pt4, segment.pt2, shapePath, segmentCount, newShape); 3979 newShape = false; 3980 shapePath.c = false; 3981 } 3982 addedLength += currentLengthData.addedLength; 3983 segmentCount += 1; 3984 } 3985 } 3986 if (shapePaths[i].c && lengths.length) { 3987 currentLengthData = lengths[j - 1]; 3988 if (addedLength <= shapeSegment.e) { 3989 var segmentLength = lengths[j - 1].addedLength; 3990 if (shapeSegment.s <= addedLength && shapeSegment.e >= addedLength + segmentLength) { 3991 this.addSegment(shapePaths[i].v[j - 1], shapePaths[i].o[j - 1], shapePaths[i].i[0], shapePaths[i].v[0], shapePath, segmentCount, newShape); 3992 newShape = false; 3993 } else { 3994 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]); 3995 this.addSegmentFromArray(segment, shapePath, segmentCount, newShape); 3996 // this.addSegment(segment.pt1, segment.pt3, segment.pt4, segment.pt2, shapePath, segmentCount, newShape); 3997 newShape = false; 3998 shapePath.c = false; 3999 } 4000 } else { 4001 shapePath.c = false; 4002 } 4003 addedLength += currentLengthData.addedLength; 4004 segmentCount += 1; 4005 } 4006 if (shapePath._length) { 4007 shapePath.setXYAt(shapePath.v[initPos][0], shapePath.v[initPos][1], 'i', initPos); 4008 shapePath.setXYAt(shapePath.v[shapePath._length - 1][0], shapePath.v[shapePath._length - 1][1], 'o', shapePath._length - 1); 4009 } 4010 if (addedLength > shapeSegment.e) { 4011 break; 4012 } 4013 if (i < len - 1) { 4014 shapePath = shapePool.newElement(); 4015 newShape = true; 4016 shapes.push(shapePath); 4017 segmentCount = 0; 4018 } 4019 } 4020 return shapes; 4021}; 4022
vendor: 3,846 bytes, lines 4023-4132
4023ShapeModifiers.registerModifier('tm', TrimModifier); 4024 4025/* global extendPrototype, ShapeModifier, PropertyFactory, shapePool, roundCorner, ShapeModifiers */ 4026 4027function RoundCornersModifier() {} 4028extendPrototype([ShapeModifier], RoundCornersModifier); 4029RoundCornersModifier.prototype.initModifierProperties = function (elem, data) { 4030 this.getValue = this.processKeys; 4031 this.rd = PropertyFactory.getProp(elem, data.r, 0, null, this); 4032 this._isAnimated = !!this.rd.effectsSequence.length; 4033}; 4034 4035RoundCornersModifier.prototype.processPath = function (path, round) { 4036 var clonedPath = shapePool.newElement(); 4037 clonedPath.c = path.c; 4038 var i; 4039 var len = path._length; 4040 var currentV; 4041 var currentI; 4042 var currentO; 4043 var closerV; 4044 var distance; 4045 var newPosPerc; 4046 var index = 0; 4047 var vX; 4048 var vY; 4049 var oX; 4050 var oY; 4051 var iX; 4052 var iY; 4053 for (i = 0; i < len; i += 1) { 4054 currentV = path.v[i]; 4055 currentO = path.o[i]; 4056 currentI = path.i[i]; 4057 if (currentV[0] === currentO[0] && currentV[1] === currentO[1] && currentV[0] === currentI[0] && currentV[1] === currentI[1]) { 4058 if ((i === 0 || i === len - 1) && !path.c) { 4059 clonedPath.setTripleAt(currentV[0], currentV[1], currentO[0], currentO[1], currentI[0], currentI[1], index); 4060 /* clonedPath.v[index] = currentV; 4061 clonedPath.o[index] = currentO; 4062 clonedPath.i[index] = currentI; */ 4063 index += 1; 4064 } else { 4065 if (i === 0) { 4066 closerV = path.v[len - 1]; 4067 } else { 4068 closerV = path.v[i - 1]; 4069 } 4070 distance = Math.sqrt(Math.pow(currentV[0] - closerV[0], 2) + Math.pow(currentV[1] - closerV[1], 2)); 4071 newPosPerc = distance ? Math.min(distance / 2, round) / distance : 0; 4072 iX = currentV[0] + (closerV[0] - currentV[0]) * newPosPerc; 4073 vX = iX; 4074 iY = currentV[1] - (currentV[1] - closerV[1]) * newPosPerc; 4075 vY = iY; 4076 oX = vX - (vX - currentV[0]) * roundCorner; 4077 oY = vY - (vY - currentV[1]) * roundCorner; 4078 clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, index); 4079 index += 1; 4080 4081 if (i === len - 1) { 4082 closerV = path.v[0]; 4083 } else { 4084 closerV = path.v[i + 1]; 4085 } 4086 distance = Math.sqrt(Math.pow(currentV[0] - closerV[0], 2) + Math.pow(currentV[1] - closerV[1], 2)); 4087 newPosPerc = distance ? Math.min(distance / 2, round) / distance : 0; 4088 oX = currentV[0] + (closerV[0] - currentV[0]) * newPosPerc; 4089 vX = oX; 4090 oY = currentV[1] + (closerV[1] - currentV[1]) * newPosPerc; 4091 vY = oY; 4092 iX = vX - (vX - currentV[0]) * roundCorner; 4093 iY = vY - (vY - currentV[1]) * roundCorner; 4094 clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, index); 4095 index += 1; 4096 } 4097 } else { 4098 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); 4099 index += 1; 4100 } 4101 } 4102 return clonedPath; 4103}; 4104 4105RoundCornersModifier.prototype.processShapes = function (_isFirstFrame) { 4106 var shapePaths; 4107 var i; 4108 var len = this.shapes.length; 4109 var j; 4110 var jLen; 4111 var rd = this.rd.v; 4112 4113 if (rd !== 0) { 4114 var shapeData; 4115 var localShapeCollection; 4116 for (i = 0; i < len; i += 1) { 4117 shapeData = this.shapes[i]; 4118 localShapeCollection = shapeData.localShapeCollection; 4119 if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) { 4120 localShapeCollection.releaseShapes(); 4121 shapeData.shape._mdf = true; 4122 shapePaths = shapeData.shape.paths.shapes; 4123 jLen = shapeData.shape.paths._length; 4124 for (j = 0; j < jLen; j += 1) { 4125 localShapeCollection.addShape(this.processPath(shapePaths[j], rd)); 4126 } 4127 } 4128 shapeData.shape.paths = shapeData.localShapeCollection; 4129 } 4130 } 4131 if (!this.dynamicProperties.length) { 4132 this._mdf = false;
vendor: 5,008 bytes, lines 4133-4275
4133 } 4134}; 4135 4136ShapeModifiers.registerModifier('rd', RoundCornersModifier); 4137 4138/* global extendPrototype, ShapeModifier, PropertyFactory, shapePool, ShapeModifiers */ 4139 4140function PuckerAndBloatModifier() {} 4141extendPrototype([ShapeModifier], PuckerAndBloatModifier); 4142PuckerAndBloatModifier.prototype.initModifierProperties = function (elem, data) { 4143 this.getValue = this.processKeys; 4144 this.amount = PropertyFactory.getProp(elem, data.a, 0, null, this); 4145 this._isAnimated = !!this.amount.effectsSequence.length; 4146}; 4147 4148PuckerAndBloatModifier.prototype.processPath = function (path, amount) { 4149 var percent = amount / 100; 4150 var centerPoint = [0, 0]; 4151 var pathLength = path._length; 4152 var i = 0; 4153 for (i = 0; i < pathLength; i += 1) { 4154 centerPoint[0] += path.v[i][0]; 4155 centerPoint[1] += path.v[i][1]; 4156 } 4157 centerPoint[0] /= pathLength; 4158 centerPoint[1] /= pathLength; 4159 var clonedPath = shapePool.newElement(); 4160 clonedPath.c = path.c; 4161 var vX; 4162 var vY; 4163 var oX; 4164 var oY; 4165 var iX; 4166 var iY; 4167 for (i = 0; i < pathLength; i += 1) { 4168 vX = path.v[i][0] + (centerPoint[0] - path.v[i][0]) * percent; 4169 vY = path.v[i][1] + (centerPoint[1] - path.v[i][1]) * percent; 4170 oX = path.o[i][0] + (centerPoint[0] - path.o[i][0]) * -percent; 4171 oY = path.o[i][1] + (centerPoint[1] - path.o[i][1]) * -percent; 4172 iX = path.i[i][0] + (centerPoint[0] - path.i[i][0]) * -percent; 4173 iY = path.i[i][1] + (centerPoint[1] - path.i[i][1]) * -percent; 4174 clonedPath.setTripleAt(vX, vY, oX, oY, iX, iY, i); 4175 } 4176 return clonedPath; 4177}; 4178 4179PuckerAndBloatModifier.prototype.processShapes = function (_isFirstFrame) { 4180 var shapePaths; 4181 var i; 4182 var len = this.shapes.length; 4183 var j; 4184 var jLen; 4185 var amount = this.amount.v; 4186 4187 if (amount !== 0) { 4188 var shapeData; 4189 var localShapeCollection; 4190 for (i = 0; i < len; i += 1) { 4191 shapeData = this.shapes[i]; 4192 localShapeCollection = shapeData.localShapeCollection; 4193 if (!(!shapeData.shape._mdf && !this._mdf && !_isFirstFrame)) { 4194 localShapeCollection.releaseShapes(); 4195 shapeData.shape._mdf = true; 4196 shapePaths = shapeData.shape.paths.shapes; 4197 jLen = shapeData.shape.paths._length; 4198 for (j = 0; j < jLen; j += 1) { 4199 localShapeCollection.addShape(this.processPath(shapePaths[j], amount)); 4200 } 4201 } 4202 shapeData.shape.paths = shapeData.localShapeCollection; 4203 } 4204 } 4205 if (!this.dynamicProperties.length) { 4206 this._mdf = false; 4207 } 4208}; 4209ShapeModifiers.registerModifier('pb', PuckerAndBloatModifier); 4210 4211/* global extendPrototype, ShapeModifier, TransformPropertyFactory, PropertyFactory, Matrix, ShapeModifiers */ 4212 4213function RepeaterModifier() {} 4214extendPrototype([ShapeModifier], RepeaterModifier); 4215 4216RepeaterModifier.prototype.initModifierProperties = function (elem, data) { 4217 this.getValue = this.processKeys; 4218 this.c = PropertyFactory.getProp(elem, data.c, 0, null, this); 4219 this.o = PropertyFactory.getProp(elem, data.o, 0, null, this); 4220 this.tr = TransformPropertyFactory.getTransformProperty(elem, data.tr, this); 4221 this.so = PropertyFactory.getProp(elem, data.tr.so, 0, 0.01, this); 4222 this.eo = PropertyFactory.getProp(elem, data.tr.eo, 0, 0.01, this); 4223 this.data = data; 4224 if (!this.dynamicProperties.length) { 4225 this.getValue(true); 4226 } 4227 this._isAnimated = !!this.dynamicProperties.length; 4228 this.pMatrix = new Matrix(); 4229 this.rMatrix = new Matrix(); 4230 this.sMatrix = new Matrix(); 4231 this.tMatrix = new Matrix(); 4232 this.matrix = new Matrix(); 4233}; 4234 4235RepeaterModifier.prototype.applyTransforms = function (pMatrix, rMatrix, sMatrix, transform, perc, inv) { 4236 var dir = inv ? -1 : 1; 4237 var scaleX = transform.s.v[0] + (1 - transform.s.v[0]) * (1 - perc); 4238 var scaleY = transform.s.v[1] + (1 - transform.s.v[1]) * (1 - perc); 4239 pMatrix.translate(transform.p.v[0] * dir * perc, transform.p.v[1] * dir * perc, transform.p.v[2]); 4240 rMatrix.translate(-transform.a.v[0], -transform.a.v[1], transform.a.v[2]); 4241 rMatrix.rotate(-transform.r.v * dir * perc); 4242 rMatrix.translate(transform.a.v[0], transform.a.v[1], transform.a.v[2]); 4243 sMatrix.translate(-transform.a.v[0], -transform.a.v[1], transform.a.v[2]); 4244 sMatrix.scale(inv ? 1 / scaleX : scaleX, inv ? 1 / scaleY : scaleY); 4245 sMatrix.translate(transform.a.v[0], transform.a.v[1], transform.a.v[2]); 4246}; 4247 4248RepeaterModifier.prototype.init = function (elem, arr, pos, elemsData) { 4249 this.elem = elem; 4250 this.arr = arr; 4251 this.pos = pos; 4252 this.elemsData = elemsData; 4253 this._currentCopies = 0; 4254 this._elements = []; 4255 this._groups = []; 4256 this.frameId = -1; 4257 this.initDynamicPropertyContainer(elem); 4258 this.initModifierProperties(elem, arr[pos]); 4259 while (pos > 0) { 4260 pos -= 1; 4261 // this._elements.unshift(arr.splice(pos,1)[0]); 4262 this._elements.unshift(arr[pos]); 4263 } 4264 if (this.dynamicProperties.length) { 4265 this.k = true; 4266 } else { 4267 this.getValue(true); 4268 } 4269}; 4270 4271RepeaterModifier.prototype.resetElements = function (elements) { 4272 var i; 4273 var len = elements.length; 4274 for (i = 0; i < len; i += 1) { 4275 elements[i]._processed = false;
vendor: 4,386 bytes, lines 4276-4399
4276 if (elements[i].ty === 'gr') { 4277 this.resetElements(elements[i].it); 4278 } 4279 } 4280}; 4281 4282RepeaterModifier.prototype.cloneElements = function (elements) { 4283 var newElements = JSON.parse(JSON.stringify(elements)); 4284 this.resetElements(newElements); 4285 return newElements; 4286}; 4287 4288RepeaterModifier.prototype.changeGroupRender = function (elements, renderFlag) { 4289 var i; 4290 var len = elements.length; 4291 for (i = 0; i < len; i += 1) { 4292 elements[i]._render = renderFlag; 4293 if (elements[i].ty === 'gr') { 4294 this.changeGroupRender(elements[i].it, renderFlag); 4295 } 4296 } 4297}; 4298 4299RepeaterModifier.prototype.processShapes = function (_isFirstFrame) { 4300 var items; 4301 var itemsTransform; 4302 var i; 4303 var dir; 4304 var cont; 4305 var hasReloaded = false; 4306 if (this._mdf || _isFirstFrame) { 4307 var copies = Math.ceil(this.c.v); 4308 if (this._groups.length < copies) { 4309 while (this._groups.length < copies) { 4310 var group = { 4311 it: this.cloneElements(this._elements), 4312 ty: 'gr', 4313 }; 4314 group.it.push({ 4315 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', 4316 }); 4317 4318 this.arr.splice(0, 0, group); 4319 this._groups.splice(0, 0, group); 4320 this._currentCopies += 1; 4321 } 4322 this.elem.reloadShapes(); 4323 hasReloaded = true; 4324 } 4325 cont = 0; 4326 var renderFlag; 4327 for (i = 0; i <= this._groups.length - 1; i += 1) { 4328 renderFlag = cont < copies; 4329 this._groups[i]._render = renderFlag; 4330 this.changeGroupRender(this._groups[i].it, renderFlag); 4331 if (!renderFlag) { 4332 var elems = this.elemsData[i].it; 4333 var transformData = elems[elems.length - 1]; 4334 if (transformData.transform.op.v !== 0) { 4335 transformData.transform.op._mdf = true; 4336 transformData.transform.op.v = 0; 4337 } else { 4338 transformData.transform.op._mdf = false; 4339 } 4340 } 4341 cont += 1; 4342 } 4343 4344 this._currentCopies = copies; 4345 /// / 4346 4347 var offset = this.o.v; 4348 var offsetModulo = offset % 1; 4349 var roundOffset = offset > 0 ? Math.floor(offset) : Math.ceil(offset); 4350 var pProps = this.pMatrix.props; 4351 var rProps = this.rMatrix.props; 4352 var sProps = this.sMatrix.props; 4353 this.pMatrix.reset(); 4354 this.rMatrix.reset(); 4355 this.sMatrix.reset(); 4356 this.tMatrix.reset(); 4357 this.matrix.reset(); 4358 var iteration = 0; 4359 4360 if (offset > 0) { 4361 while (iteration < roundOffset) { 4362 this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, false); 4363 iteration += 1; 4364 } 4365 if (offsetModulo) { 4366 this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, offsetModulo, false); 4367 iteration += offsetModulo; 4368 } 4369 } else if (offset < 0) { 4370 while (iteration > roundOffset) { 4371 this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, true); 4372 iteration -= 1; 4373 } 4374 if (offsetModulo) { 4375 this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, -offsetModulo, true); 4376 iteration -= offsetModulo; 4377 } 4378 } 4379 i = this.data.m === 1 ? 0 : this._currentCopies - 1; 4380 dir = this.data.m === 1 ? 1 : -1; 4381 cont = this._currentCopies; 4382 var j; 4383 var jLen; 4384 while (cont) { 4385 items = this.elemsData[i].it; 4386 itemsTransform = items[items.length - 1].transform.mProps.v.props; 4387 jLen = itemsTransform.length; 4388 items[items.length - 1].transform.mProps._mdf = true; 4389 items[items.length - 1].transform.op._mdf = true; 4390 items[items.length - 1].transform.op.v = this._currentCopies === 1 4391 ? this.so.v 4392 : this.so.v + (this.eo.v - this.so.v) * (i / (this._currentCopies - 1)); 4393 4394 if (iteration !== 0) { 4395 if ((i !== 0 && dir === 1) || (i !== this._currentCopies - 1 && dir === -1)) { 4396 this.applyTransforms(this.pMatrix, this.rMatrix, this.sMatrix, this.tr, 1, false); 4397 } 4398 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]); 4399 this.matrix.transform(sProps[0], sProps[1], sProps[2], sPro
vendor: 22,616 bytes, lines 4399-5203
4399ps[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]); 4400 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]); 4401 4402 for (j = 0; j < jLen; j += 1) { 4403 itemsTransform[j] = this.matrix.props[j]; 4404 } 4405 this.matrix.reset(); 4406 } else { 4407 this.matrix.reset(); 4408 for (j = 0; j < jLen; j += 1) { 4409 itemsTransform[j] = this.matrix.props[j]; 4410 } 4411 } 4412 iteration += 1; 4413 cont -= 1; 4414 i += dir; 4415 } 4416 } else { 4417 cont = this._currentCopies; 4418 i = 0; 4419 dir = 1; 4420 while (cont) { 4421 items = this.elemsData[i].it; 4422 itemsTransform = items[items.length - 1].transform.mProps.v.props; 4423 items[items.length - 1].transform.mProps._mdf = false; 4424 items[items.length - 1].transform.op._mdf = false; 4425 cont -= 1; 4426 i += dir; 4427 } 4428 } 4429 return hasReloaded; 4430}; 4431 4432RepeaterModifier.prototype.addShape = function () {}; 4433 4434ShapeModifiers.registerModifier('rp', RepeaterModifier); 4435 4436/* global createSizedArray, shapePool */ 4437 4438function ShapeCollection() { 4439 this._length = 0; 4440 this._maxLength = 4; 4441 this.shapes = createSizedArray(this._maxLength); 4442} 4443 4444ShapeCollection.prototype.addShape = function (shapeData) { 4445 if (this._length === this._maxLength) { 4446 this.shapes = this.shapes.concat(createSizedArray(this._maxLength)); 4447 this._maxLength *= 2; 4448 } 4449 this.shapes[this._length] = shapeData; 4450 this._length += 1; 4451}; 4452 4453ShapeCollection.prototype.releaseShapes = function () { 4454 var i; 4455 for (i = 0; i < this._length; i += 1) { 4456 shapePool.release(this.shapes[i]); 4457 } 4458 this._length = 0; 4459}; 4460 4461/* global createSizedArray, createTypedArray, PropertyFactory, extendPrototype, DynamicPropertyContainer */ 4462 4463function DashProperty(elem, data, renderer, container) { 4464 this.elem = elem; 4465 this.frameId = -1; 4466 this.dataProps = createSizedArray(data.length); 4467 this.renderer = renderer; 4468 this.k = false; 4469 this.dashStr = ''; 4470 this.dashArray = createTypedArray('float32', data.length ? data.length - 1 : 0); 4471 this.dashoffset = createTypedArray('float32', 1); 4472 this.initDynamicPropertyContainer(container); 4473 var i; 4474 var len = data.length || 0; 4475 var prop; 4476 for (i = 0; i < len; i += 1) { 4477 prop = PropertyFactory.getProp(elem, data[i].v, 0, 0, this); 4478 this.k = prop.k || this.k; 4479 this.dataProps[i] = { n: data[i].n, p: prop }; 4480 } 4481 if (!this.k) { 4482 this.getValue(true); 4483 } 4484 this._isAnimated = this.k; 4485} 4486 4487DashProperty.prototype.getValue = function (forceRender) { 4488 if (this.elem.globalData.frameId === this.frameId && !forceRender) { 4489 return; 4490 } 4491 this.frameId = this.elem.globalData.frameId; 4492 this.iterateDynamicProperties(); 4493 this._mdf = this._mdf || forceRender; 4494 if (this._mdf) { 4495 var i = 0; 4496 var len = this.dataProps.length; 4497 if (this.renderer === 'svg') { 4498 this.dashStr = ''; 4499 } 4500 for (i = 0; i < len; i += 1) { 4501 if (this.dataProps[i].n !== 'o') { 4502 if (this.renderer === 'svg') { 4503 this.dashStr += ' ' + this.dataProps[i].p.v; 4504 } else { 4505 this.dashArray[i] = this.dataProps[i].p.v; 4506 } 4507 } else { 4508 this.dashoffset[0] = this.dataProps[i].p.v; 4509 } 4510 } 4511 } 4512}; 4513extendPrototype([DynamicPropertyContainer], DashProperty); 4514 4515/* global createTypedArray, PropertyFactory, extendPrototype, DynamicPropertyContainer */ 4516function GradientProperty(elem, data, container) { 4517 this.data = data; 4518 this.c = createTypedArray('uint8c', data.p * 4); 4519 var cLength = data.k.k[0].s ? (data.k.k[0].s.length - data.p * 4) : data.k.k.length - data.p * 4; 4520 this.o = createTypedArray('float32', cLength); 4521 this._cmdf = false; 4522 this._omdf = false; 4523 this._collapsable = this.checkCollapsable(); 4524 this._hasOpacity = cLength; 4525 this.initDynamicPropertyContainer(container); 4526 this.prop = PropertyFactory.getProp(elem, data.k, 1, null, this); 4527 this.k = this.prop.k; 4528 this.getValue(true); 4529} 4530 4531GradientProperty.prototype.comparePoints = function (values, points) { 4532 var i = 0; 4533 var len = this.o.length / 2; 4534 var diff; 4535 while (i < len) { 4536 diff = Math.abs(values[i * 4] - values[points * 4 + i * 2]); 4537 if (diff > 0.01) { 4538 return false; 4539 } 4540 i += 1; 4541 } 4542 return true; 4543}; 4544 4545GradientProperty.prototype.checkCollapsable = function () { 4546 if (this.o.length / 2 !== this.c.length / 4) { 4547 return false; 4548 } 4549 if (this.data.k.k[0].s) { 4550 var i = 0; 4551 var len = this.data.k.k.length; 4552 while (i < len) { 4553 if (!this.comparePoints(this.data.k.k[i].s, this.data.p)) { 4554 return false; 4555 } 4556 i += 1; 4557 } 4558 } else if (!this.comparePoints(this.data.k.k, this.data.p)) { 4559 return false; 4560 } 4561 return true; 4562}; 4563 4564GradientProperty.prototype.getValue = function (forceRender) { 4565 this.prop.getValue(); 4566 this._mdf = false; 4567 this._cmdf = false; 4568 this._omdf = false; 4569 if (this.prop._mdf || forceRender) { 4570 var i; 4571 var len = this.data.p * 4; 4572 var mult; 4573 var val; 4574 for (i = 0; i < len; i += 1) { 4575 mult = i % 4 === 0 ? 100 : 255; 4576 val = Math.round(this.prop.v[i] * mult); 4577 if (this.c[i] !== val) { 4578 this.c[i] = val; 4579 this._cmdf = !forceRender; 4580 } 4581 } 4582 if (this.o.length) { 4583 len = this.prop.v.length; 4584 for (i = this.data.p * 4; i < len; i += 1) { 4585 mult = i % 2 === 0 ? 100 : 1; 4586 val = i % 2 === 0 ? Math.round(this.prop.v[i] * 100) : this.prop.v[i]; 4587 if (this.o[i - this.data.p * 4] !== val) { 4588 this.o[i - this.data.p * 4] = val; 4589 this._omdf = !forceRender; 4590 } 4591 } 4592 } 4593 this._mdf = !forceRender; 4594 } 4595}; 4596 4597extendPrototype([DynamicPropertyContainer], GradientProperty); 4598 4599/* exported buildShapeString */ 4600 4601var buildShapeString = function (pathNodes, length, closed, mat) { 4602 if (length === 0) { 4603 return ''; 4604 } 4605 var _o = pathNodes.o; 4606 var _i = pathNodes.i; 4607 var _v = pathNodes.v; 4608 var i; 4609 var shapeString = ' M' + mat.applyToPointStringified(_v[0][0], _v[0][1]); 4610 for (i = 1; i < length; i += 1) { 4611 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]); 4612 } 4613 if (closed && length) { 4614 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]); 4615 shapeString += 'z'; 4616 } 4617 return shapeString; 4618}; 4619 4620/* global Howl */ 4621/* exported audioControllerFactory */ 4622 4623var audioControllerFactory = (function () { 4624 function AudioController(audioFactory) { 4625 this.audios = []; 4626 this.audioFactory = audioFactory; 4627 this._volume = 1; 4628 this._isMuted = false; 4629 } 4630 4631 AudioController.prototype = { 4632 addAudio: function (audio) { 4633 this.audios.push(audio); 4634 }, 4635 pause: function () { 4636 var i; 4637 var len = this.audios.length; 4638 for (i = 0; i < len; i += 1) { 4639 this.audios[i].pause(); 4640 } 4641 }, 4642 resume: function () { 4643 var i; 4644 var len = this.audios.length; 4645 for (i = 0; i < len; i += 1) { 4646 this.audios[i].resume(); 4647 } 4648 }, 4649 setRate: function (rateValue) { 4650 var i; 4651 var len = this.audios.length; 4652 for (i = 0; i < len; i += 1) { 4653 this.audios[i].setRate(rateValue); 4654 } 4655 }, 4656 createAudio: function (assetPath) { 4657 if (this.audioFactory) { 4658 return this.audioFactory(assetPath); 4659 } if (Howl) { 4660 return new Howl({ 4661 src: [assetPath], 4662 }); 4663 } 4664 return { 4665 isPlaying: false, 4666 play: function () { this.isPlaying = true; }, 4667 seek: function () { this.isPlaying = false; }, 4668 playing: function () {}, 4669 rate: function () {}, 4670 setVolume: function () {}, 4671 }; 4672 }, 4673 setAudioFactory: function (audioFactory) { 4674 this.audioFactory = audioFactory; 4675 }, 4676 setVolume: function (value) { 4677 this._volume = value; 4678 this._updateVolume(); 4679 }, 4680 mute: function () { 4681 this._isMuted = true; 4682 this._updateVolume(); 4683 }, 4684 unmute: function () { 4685 this._isMuted = false; 4686 this._updateVolume(); 4687 }, 4688 getVolume: function () { 4689 return this._volume; 4690 }, 4691 _updateVolume: function () { 4692 var i; 4693 var len = this.audios.length; 4694 for (i = 0; i < len; i += 1) { 4695 this.audios[i].volume(this._volume * (this._isMuted ? 0 : 1)); 4696 } 4697 }, 4698 }; 4699 4700 return function () { 4701 return new AudioController(); 4702 }; 4703}()); 4704 4705/* global createTag, createNS, isSafari, assetLoader */ 4706/* exported ImagePreloader */ 4707 4708var ImagePreloader = (function () { 4709 var proxyImage = (function () { 4710 var canvas = createTag('canvas'); 4711 canvas.width = 1; 4712 canvas.height = 1; 4713 var ctx = canvas.getContext('2d'); 4714 ctx.fillStyle = 'rgba(0,0,0,0)'; 4715 ctx.fillRect(0, 0, 1, 1); 4716 return canvas; 4717 }()); 4718 4719 function imageLoaded() { 4720 this.loadedAssets += 1; 4721 if (this.loadedAssets === this.totalImages && this.loadedFootagesCount === this.totalFootages) { 4722 if (this.imagesLoadedCb) { 4723 this.imagesLoadedCb(null); 4724 } 4725 } 4726 } 4727 function footageLoaded() { 4728 this.loadedFootagesCount += 1; 4729 if (this.loadedAssets === this.totalImages && this.loadedFootagesCount === this.totalFootages) { 4730 if (this.imagesLoadedCb) { 4731 this.imagesLoadedCb(null); 4732 } 4733 } 4734 } 4735 4736 function getAssetsPath(assetData, assetsPath, originalPath) { 4737 var path = ''; 4738 if (assetData.e) { 4739 path = assetData.p; 4740 } else if (assetsPath) { 4741 var imagePath = assetData.p; 4742 if (imagePath.indexOf('images/') !== -1) { 4743 imagePath = imagePath.split('/')[1]; 4744 } 4745 path = assetsPath + imagePath; 4746 } else { 4747 path = originalPath; 4748 path += assetData.u ? assetData.u : ''; 4749 path += assetData.p; 4750 } 4751 return path; 4752 } 4753 4754 function testImageLoaded(img) { 4755 var _count = 0; 4756 var intervalId = setInterval(function () { 4757 var box = img.getBBox(); 4758 if (box.width || _count > 500) { 4759 this._imageLoaded(); 4760 clearInterval(intervalId); 4761 } 4762 _count += 1; 4763 }.bind(this), 50); 4764 } 4765 4766 function createImageData(assetData) { 4767 var path = getAssetsPath(assetData, this.assetsPath, this.path); 4768 var img = createNS('image'); 4769 if (isSafari) { 4770 this.testImageLoaded(img); 4771 } else { 4772 img.addEventListener('load', this._imageLoaded, false); 4773 } 4774 img.addEventListener('error', function () { 4775 ob.img = proxyImage; 4776 this._imageLoaded(); 4777 }.bind(this), false); 4778 img.setAttributeNS('http://www.w3.org/1999/xlink', 'href', path); 4779 if (this._elementHelper.append) { 4780 this._elementHelper.append(img); 4781 } else { 4782 this._elementHelper.appendChild(img); 4783 } 4784 var ob = { 4785 img: img, 4786 assetData: assetData, 4787 }; 4788 return ob; 4789 } 4790 4791 function createImgData(assetData) { 4792 var path = getAssetsPath(assetData, this.assetsPath, this.path); 4793 var img = createTag('img'); 4794 img.crossOrigin = 'anonymous'; 4795 img.addEventListener('load', this._imageLoaded, false); 4796 img.addEventListener('error', function () { 4797 ob.img = proxyImage; 4798 this._imageLoaded(); 4799 }.bind(this), false); 4800 img.src = path; 4801 var ob = { 4802 img: img, 4803 assetData: assetData, 4804 }; 4805 return ob; 4806 } 4807 4808 function createFootageData(data) { 4809 var ob = { 4810 assetData: data, 4811 }; 4812 var path = getAssetsPath(data, this.assetsPath, this.path); 4813 assetLoader.load(path, function (footageData) { 4814 ob.img = footageData; 4815 this._footageLoaded(); 4816 }.bind(this), function () { 4817 ob.img = {}; 4818 this._footageLoaded(); 4819 }.bind(this)); 4820 return ob; 4821 } 4822 4823 function loadAssets(assets, cb) { 4824 this.imagesLoadedCb = cb; 4825 var i; 4826 var len = assets.length; 4827 for (i = 0; i < len; i += 1) { 4828 if (!assets[i].layers) { 4829 if (!assets[i].t || assets[i].t === 'seq') { 4830 this.totalImages += 1; 4831 this.images.push(this._createImageData(assets[i])); 4832 } else if (assets[i].t === 3) { 4833 this.totalFootages += 1; 4834 this.images.push(this.createFootageData(assets[i])); 4835 } 4836 } 4837 } 4838 } 4839 4840 function setPath(path) { 4841 this.path = path || ''; 4842 } 4843 4844 function setAssetsPath(path) { 4845 this.assetsPath = path || ''; 4846 } 4847 4848 function getAsset(assetData) { 4849 var i = 0; 4850 var len = this.images.length; 4851 while (i < len) { 4852 if (this.images[i].assetData === assetData) { 4853 return this.images[i].img; 4854 } 4855 i += 1; 4856 } 4857 return null; 4858 } 4859 4860 function destroy() { 4861 this.imagesLoadedCb = null; 4862 this.images.length = 0; 4863 } 4864 4865 function loadedImages() { 4866 return this.totalImages === this.loadedAssets; 4867 } 4868 4869 function loadedFootages() { 4870 return this.totalFootages === this.loadedFootagesCount; 4871 } 4872 4873 function setCacheType(type, elementHelper) { 4874 if (type === 'svg') { 4875 this._elementHelper = elementHelper; 4876 this._createImageData = this.createImageData.bind(this); 4877 } else { 4878 this._createImageData = this.createImgData.bind(this); 4879 } 4880 } 4881 4882 function ImagePreloaderFactory() { 4883 this._imageLoaded = imageLoaded.bind(this); 4884 this._footageLoaded = footageLoaded.bind(this); 4885 this.testImageLoaded = testImageLoaded.bind(this); 4886 this.createFootageData = createFootageData.bind(this); 4887 this.assetsPath = ''; 4888 this.path = ''; 4889 this.totalImages = 0; 4890 this.totalFootages = 0; 4891 this.loadedAssets = 0; 4892 this.loadedFootagesCount = 0; 4893 this.imagesLoadedCb = null; 4894 this.images = []; 4895 } 4896 4897 ImagePreloaderFactory.prototype = { 4898 loadAssets: loadAssets, 4899 setAssetsPath: setAssetsPath, 4900 setPath: setPath, 4901 loadedImages: loadedImages, 4902 loadedFootages: loadedFootages, 4903 destroy: destroy, 4904 getAsset: getAsset, 4905 createImgData: createImgData, 4906 createImageData: createImageData, 4907 imageLoaded: imageLoaded, 4908 footageLoaded: footageLoaded, 4909 setCacheType: setCacheType, 4910 }; 4911 4912 return ImagePreloaderFactory; 4913}()); 4914 4915/* exported featureSupport */ 4916 4917var featureSupport = (function () { 4918 var ob = { 4919 maskType: true, 4920 }; 4921 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)) { 4922 ob.maskType = false; 4923 } 4924 return ob; 4925}()); 4926 4927/* global createNS */ 4928/* exported filtersFactory */ 4929 4930var filtersFactory = (function () { 4931 var ob = {}; 4932 ob.createFilter = createFilter; 4933 ob.createAlphaToLuminanceFilter = createAlphaToLuminanceFilter; 4934 4935 function createFilter(filId, skipCoordinates) { 4936 var fil = createNS('filter'); 4937 fil.setAttribute('id', filId); 4938 if (skipCoordinates !== true) { 4939 fil.setAttribute('filterUnits', 'objectBoundingBox'); 4940 fil.setAttribute('x', '0%'); 4941 fil.setAttribute('y', '0%'); 4942 fil.setAttribute('width', '100%'); 4943 fil.setAttribute('height', '100%'); 4944 } 4945 return fil; 4946 } 4947 4948 function createAlphaToLuminanceFilter() { 4949 var feColorMatrix = createNS('feColorMatrix'); 4950 feColorMatrix.setAttribute('type', 'matrix'); 4951 feColorMatrix.setAttribute('color-interpolation-filters', 'sRGB'); 4952 feColorMatrix.setAttribute('values', '0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 1'); 4953 return feColorMatrix; 4954 } 4955 4956 return ob; 4957}()); 4958 4959/* exported assetLoader */ 4960 4961var assetLoader = (function () { 4962 function formatResponse(xhr) { 4963 if (xhr.response && typeof xhr.response === 'object') { 4964 return xhr.response; 4965 } if (xhr.response && typeof xhr.response === 'string') { 4966 return JSON.parse(xhr.response); 4967 } if (xhr.responseText) { 4968 return JSON.parse(xhr.responseText); 4969 } 4970 return null; 4971 } 4972 4973 function loadAsset(path, callback, errorCallback) { 4974 var response; 4975 var xhr = new XMLHttpRequest(); 4976 // set responseType after calling open or IE will break. 4977 try { 4978 // This crashes on Android WebView prior to KitKat 4979 xhr.responseType = 'json'; 4980 } catch (err) {} // eslint-disable-line no-empty 4981 xhr.onreadystatechange = function () { 4982 if (xhr.readyState === 4) { 4983 if (xhr.status === 200) { 4984 response = formatResponse(xhr); 4985 callback(response); 4986 } else { 4987 try { 4988 response = formatResponse(xhr); 4989 callback(response); 4990 } catch (err) { 4991 if (errorCallback) { 4992 errorCallback(err); 4993 } 4994 } 4995 } 4996 } 4997 }; 4998 xhr.open('GET', path, true); 4999 xhr.send(); 5000 } 5001 return { 5002 load: loadAsset, 5003 }; 5004}()); 5005 5006/* global createSizedArray, PropertyFactory, TextAnimatorDataProperty, bez, addHueToRGB, 5007 addSaturationToRGB, addBrightnessToRGB, LetterProps, Matrix, extendPrototype, DynamicPropertyContainer */ 5008 5009function TextAnimatorProperty(textData, renderType, elem) { 5010 this._isFirstFrame = true; 5011 this._hasMaskedPath = false; 5012 this._frameId = -1; 5013 this._textData = textData; 5014 this._renderType = renderType; 5015 this._elem = elem; 5016 this._animatorsData = createSizedArray(this._textData.a.length); 5017 this._pathData = {}; 5018 this._moreOptions = { 5019 alignment: {}, 5020 }; 5021 this.renderedLetters = []; 5022 this.lettersChangedFlag = false; 5023 this.initDynamicPropertyContainer(elem); 5024} 5025 5026TextAnimatorProperty.prototype.searchProperties = function () { 5027 var i; 5028 var len = this._textData.a.length; 5029 var animatorProps; 5030 var getProp = PropertyFactory.getProp; 5031 for (i = 0; i < len; i += 1) { 5032 animatorProps = this._textData.a[i]; 5033 this._animatorsData[i] = new TextAnimatorDataProperty(this._elem, animatorProps, this); 5034 } 5035 if (this._textData.p && 'm' in this._textData.p) { 5036 this._pathData = { 5037 f: getProp(this._elem, this._textData.p.f, 0, 0, this), 5038 l: getProp(this._elem, this._textData.p.l, 0, 0, this), 5039 r: this._textData.p.r, 5040 m: this._elem.maskManager.getMaskProperty(this._textData.p.m), 5041 }; 5042 this._hasMaskedPath = true; 5043 } else { 5044 this._hasMaskedPath = false; 5045 } 5046 this._moreOptions.alignment = getProp(this._elem, this._textData.m.a, 1, 0, this); 5047}; 5048 5049TextAnimatorProperty.prototype.getMeasures = function (documentData, lettersChangedFlag) { 5050 this.lettersChangedFlag = lettersChangedFlag; 5051 if (!this._mdf && !this._isFirstFrame && !lettersChangedFlag && (!this._hasMaskedPath || !this._pathData.m._mdf)) { 5052 return; 5053 } 5054 this._isFirstFrame = false; 5055 var alignment = this._moreOptions.alignment.v; 5056 var animators = this._animatorsData; 5057 var textData = this._textData; 5058 var matrixHelper = this.mHelper; 5059 var renderType = this._renderType; 5060 var renderedLettersCount = this.renderedLetters.length; 5061 var xPos; 5062 var yPos; 5063 var i; 5064 var len; 5065 var letters = documentData.l; 5066 var pathInfo; 5067 var currentLength; 5068 var currentPoint; 5069 var segmentLength; 5070 var flag; 5071 var pointInd; 5072 var segmentInd; 5073 var prevPoint; 5074 var points; 5075 var segments; 5076 var partialLength; 5077 var totalLength; 5078 var perc; 5079 var tanAngle; 5080 var mask; 5081 if (this._hasMaskedPath) { 5082 mask = this._pathData.m; 5083 if (!this._pathData.n || this._pathData._mdf) { 5084 var paths = mask.v; 5085 if (this._pathData.r) { 5086 paths = paths.reverse(); 5087 } 5088 // TODO: release bezier data cached from previous pathInfo: this._pathData.pi 5089 pathInfo = { 5090 tLength: 0, 5091 segments: [], 5092 }; 5093 len = paths._length - 1; 5094 var bezierData; 5095 totalLength = 0; 5096 for (i = 0; i < len; i += 1) { 5097 bezierData = bez.buildBezierData(paths.v[i], 5098 paths.v[i + 1], 5099 [paths.o[i][0] - paths.v[i][0], paths.o[i][1] - paths.v[i][1]], 5100 [paths.i[i + 1][0] - paths.v[i + 1][0], paths.i[i + 1][1] - paths.v[i + 1][1]]); 5101 pathInfo.tLength += bezierData.segmentLength; 5102 pathInfo.segments.push(bezierData); 5103 totalLength += bezierData.segmentLength; 5104 } 5105 i = len; 5106 if (mask.v.c) { 5107 bezierData = bez.buildBezierData(paths.v[i], 5108 paths.v[0], 5109 [paths.o[i][0] - paths.v[i][0], paths.o[i][1] - paths.v[i][1]], 5110 [paths.i[0][0] - paths.v[0][0], paths.i[0][1] - paths.v[0][1]]); 5111 pathInfo.tLength += bezierData.segmentLength; 5112 pathInfo.segments.push(bezierData); 5113 totalLength += bezierData.segmentLength; 5114 } 5115 this._pathData.pi = pathInfo; 5116 } 5117 pathInfo = this._pathData.pi; 5118 5119 currentLength = this._pathData.f.v; 5120 segmentInd = 0; 5121 pointInd = 1; 5122 segmentLength = 0; 5123 flag = true; 5124 segments = pathInfo.segments; 5125 if (currentLength < 0 && mask.v.c) { 5126 if (pathInfo.tLength < Math.abs(currentLength)) { 5127 currentLength = -Math.abs(currentLength) % pathInfo.tLength; 5128 } 5129 segmentInd = segments.length - 1; 5130 points = segments[segmentInd].points; 5131 pointInd = points.length - 1; 5132 while (currentLength < 0) { 5133 currentLength += points[pointInd].partialLength; 5134 pointInd -= 1; 5135 if (pointInd < 0) { 5136 segmentInd -= 1; 5137 points = segments[segmentInd].points; 5138 pointInd = points.length - 1; 5139 } 5140 } 5141 } 5142 points = segments[segmentInd].points; 5143 prevPoint = points[pointInd - 1]; 5144 currentPoint = points[pointInd]; 5145 partialLength = currentPoint.partialLength; 5146 } 5147 5148 len = letters.length; 5149 xPos = 0; 5150 yPos = 0; 5151 var yOff = documentData.finalSize * 1.2 * 0.714; 5152 var firstLine = true; 5153 var animatorProps; 5154 var animatorSelector; 5155 var j; 5156 var jLen; 5157 var letterValue; 5158 5159 jLen = animators.length; 5160 5161 var mult; 5162 var ind = -1; 5163 var offf; 5164 var xPathPos; 5165 var yPathPos; 5166 var initPathPos = currentLength; 5167 var initSegmentInd = segmentInd; 5168 var initPointInd = pointInd; 5169 var currentLine = -1; 5170 var elemOpacity; 5171 var sc; 5172 var sw; 5173 var fc; 5174 var k; 5175 var letterSw; 5176 var letterSc; 5177 var letterFc; 5178 var letterM = ''; 5179 var letterP = this.defaultPropsArray; 5180 var letterO; 5181 5182 // 5183 if (documentData.j === 2 || documentData.j === 1) { 5184 var animatorJustifyOffset = 0; 5185 var animatorFirstCharOffset = 0; 5186 var justifyOffsetMult = documentData.j === 2 ? -0.5 : -1; 5187 var lastIndex = 0; 5188 var isNewLine = true; 5189 5190 for (i = 0; i < len; i += 1) { 5191 if (letters[i].n) { 5192 if (animatorJustifyOffset) { 5193 animatorJustifyOffset += animatorFirstCharOffset; 5194 } 5195 while (lastIndex < i) { 5196 letters[lastIndex].animatorJustifyOffset = animatorJustifyOffset; 5197 lastIndex += 1; 5198 } 5199 animatorJustifyOffset = 0; 5200 isNewLine = true; 5201 } else { 5202 for (j = 0; j < jLen; j += 1) { 5203 animatorProps = animators[j].a;
vendor: 22,599 bytes, lines 5204-5828
5204 if (animatorProps.t.propType) { 5205 if (isNewLine && documentData.j === 2) { 5206 animatorFirstCharOffset += animatorProps.t.v * justifyOffsetMult; 5207 } 5208 animatorSelector = animators[j].s; 5209 mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars); 5210 if (mult.length) { 5211 animatorJustifyOffset += animatorProps.t.v * mult[0] * justifyOffsetMult; 5212 } else { 5213 animatorJustifyOffset += animatorProps.t.v * mult * justifyOffsetMult; 5214 } 5215 } 5216 } 5217 isNewLine = false; 5218 } 5219 } 5220 if (animatorJustifyOffset) { 5221 animatorJustifyOffset += animatorFirstCharOffset; 5222 } 5223 while (lastIndex < i) { 5224 letters[lastIndex].animatorJustifyOffset = animatorJustifyOffset; 5225 lastIndex += 1; 5226 } 5227 } 5228 // 5229 5230 for (i = 0; i < len; i += 1) { 5231 matrixHelper.reset(); 5232 elemOpacity = 1; 5233 if (letters[i].n) { 5234 xPos = 0; 5235 yPos += documentData.yOffset; 5236 yPos += firstLine ? 1 : 0; 5237 currentLength = initPathPos; 5238 firstLine = false; 5239 if (this._hasMaskedPath) { 5240 segmentInd = initSegmentInd; 5241 pointInd = initPointInd; 5242 points = segments[segmentInd].points; 5243 prevPoint = points[pointInd - 1]; 5244 currentPoint = points[pointInd]; 5245 partialLength = currentPoint.partialLength; 5246 segmentLength = 0; 5247 } 5248 letterM = ''; 5249 letterFc = ''; 5250 letterSw = ''; 5251 letterO = ''; 5252 letterP = this.defaultPropsArray; 5253 } else { 5254 if (this._hasMaskedPath) { 5255 if (currentLine !== letters[i].line) { 5256 switch (documentData.j) { 5257 case 1: 5258 currentLength += totalLength - documentData.lineWidths[letters[i].line]; 5259 break; 5260 case 2: 5261 currentLength += (totalLength - documentData.lineWidths[letters[i].line]) / 2; 5262 break; 5263 default: 5264 break; 5265 } 5266 currentLine = letters[i].line; 5267 } 5268 if (ind !== letters[i].ind) { 5269 if (letters[ind]) { 5270 currentLength += letters[ind].extra; 5271 } 5272 currentLength += letters[i].an / 2; 5273 ind = letters[i].ind; 5274 } 5275 currentLength += (alignment[0] * letters[i].an) * 0.005; 5276 var animatorOffset = 0; 5277 for (j = 0; j < jLen; j += 1) { 5278 animatorProps = animators[j].a; 5279 if (animatorProps.p.propType) { 5280 animatorSelector = animators[j].s; 5281 mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars); 5282 if (mult.length) { 5283 animatorOffset += animatorProps.p.v[0] * mult[0]; 5284 } else { 5285 animatorOffset += animatorProps.p.v[0] * mult; 5286 } 5287 } 5288 if (animatorProps.a.propType) { 5289 animatorSelector = animators[j].s; 5290 mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars); 5291 if (mult.length) { 5292 animatorOffset += animatorProps.a.v[0] * mult[0]; 5293 } else { 5294 animatorOffset += animatorProps.a.v[0] * mult; 5295 } 5296 } 5297 } 5298 flag = true; 5299 while (flag) { 5300 if (segmentLength + partialLength >= currentLength + animatorOffset || !points) { 5301 perc = (currentLength + animatorOffset - segmentLength) / currentPoint.partialLength; 5302 xPathPos = prevPoint.point[0] + (currentPoint.point[0] - prevPoint.point[0]) * perc; 5303 yPathPos = prevPoint.point[1] + (currentPoint.point[1] - prevPoint.point[1]) * perc; 5304 matrixHelper.translate((-alignment[0] * letters[i].an) * 0.005, -(alignment[1] * yOff) * 0.01); 5305 flag = false; 5306 } else if (points) { 5307 segmentLength += currentPoint.partialLength; 5308 pointInd += 1; 5309 if (pointInd >= points.length) { 5310 pointInd = 0; 5311 segmentInd += 1; 5312 if (!segments[segmentInd]) { 5313 if (mask.v.c) { 5314 pointInd = 0; 5315 segmentInd = 0; 5316 points = segments[segmentInd].points; 5317 } else { 5318 segmentLength -= currentPoint.partialLength; 5319 points = null; 5320 } 5321 } else { 5322 points = segments[segmentInd].points; 5323 } 5324 } 5325 if (points) { 5326 prevPoint = currentPoint; 5327 currentPoint = points[pointInd]; 5328 partialLength = currentPoint.partialLength; 5329 } 5330 } 5331 } 5332 offf = letters[i].an / 2 - letters[i].add; 5333 matrixHelper.translate(-offf, 0, 0); 5334 } else { 5335 offf = letters[i].an / 2 - letters[i].add; 5336 matrixHelper.translate(-offf, 0, 0); 5337 5338 // Grouping alignment 5339 matrixHelper.translate((-alignment[0] * letters[i].an) * 0.005, (-alignment[1] * yOff) * 0.01, 0); 5340 } 5341 5342 for (j = 0; j < jLen; j += 1) { 5343 animatorProps = animators[j].a; 5344 if (animatorProps.t.propType) { 5345 animatorSelector = animators[j].s; 5346 mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars); 5347 // This condition is to prevent applying tracking to first character in each line. Might be better to use a boolean "isNewLine" 5348 if (xPos !== 0 || documentData.j !== 0) { 5349 if (this._hasMaskedPath) { 5350 if (mult.length) { 5351 currentLength += animatorProps.t.v * mult[0]; 5352 } else { 5353 currentLength += animatorProps.t.v * mult; 5354 } 5355 } else if (mult.length) { 5356 xPos += animatorProps.t.v * mult[0]; 5357 } else { 5358 xPos += animatorProps.t.v * mult; 5359 } 5360 } 5361 } 5362 } 5363 if (documentData.strokeWidthAnim) { 5364 sw = documentData.sw || 0; 5365 } 5366 if (documentData.strokeColorAnim) { 5367 if (documentData.sc) { 5368 sc = [documentData.sc[0], documentData.sc[1], documentData.sc[2]]; 5369 } else { 5370 sc = [0, 0, 0]; 5371 } 5372 } 5373 if (documentData.fillColorAnim && documentData.fc) { 5374 fc = [documentData.fc[0], documentData.fc[1], documentData.fc[2]]; 5375 } 5376 for (j = 0; j < jLen; j += 1) { 5377 animatorProps = animators[j].a; 5378 if (animatorProps.a.propType) { 5379 animatorSelector = animators[j].s; 5380 mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars); 5381 5382 if (mult.length) { 5383 matrixHelper.translate(-animatorProps.a.v[0] * mult[0], -animatorProps.a.v[1] * mult[1], animatorProps.a.v[2] * mult[2]); 5384 } else { 5385 matrixHelper.translate(-animatorProps.a.v[0] * mult, -animatorProps.a.v[1] * mult, animatorProps.a.v[2] * mult); 5386 } 5387 } 5388 } 5389 for (j = 0; j < jLen; j += 1) { 5390 animatorProps = animators[j].a; 5391 if (animatorProps.s.propType) { 5392 animatorSelector = animators[j].s; 5393 mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars); 5394 if (mult.length) { 5395 matrixHelper.scale(1 + ((animatorProps.s.v[0] - 1) * mult[0]), 1 + ((animatorProps.s.v[1] - 1) * mult[1]), 1); 5396 } else { 5397 matrixHelper.scale(1 + ((animatorProps.s.v[0] - 1) * mult), 1 + ((animatorProps.s.v[1] - 1) * mult), 1); 5398 } 5399 } 5400 } 5401 for (j = 0; j < jLen; j += 1) { 5402 animatorProps = animators[j].a; 5403 animatorSelector = animators[j].s; 5404 mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars); 5405 if (animatorProps.sk.propType) { 5406 if (mult.length) { 5407 matrixHelper.skewFromAxis(-animatorProps.sk.v * mult[0], animatorProps.sa.v * mult[1]); 5408 } else { 5409 matrixHelper.skewFromAxis(-animatorProps.sk.v * mult, animatorProps.sa.v * mult); 5410 } 5411 } 5412 if (animatorProps.r.propType) { 5413 if (mult.length) { 5414 matrixHelper.rotateZ(-animatorProps.r.v * mult[2]); 5415 } else { 5416 matrixHelper.rotateZ(-animatorProps.r.v * mult); 5417 } 5418 } 5419 if (animatorProps.ry.propType) { 5420 if (mult.length) { 5421 matrixHelper.rotateY(animatorProps.ry.v * mult[1]); 5422 } else { 5423 matrixHelper.rotateY(animatorProps.ry.v * mult); 5424 } 5425 } 5426 if (animatorProps.rx.propType) { 5427 if (mult.length) { 5428 matrixHelper.rotateX(animatorProps.rx.v * mult[0]); 5429 } else { 5430 matrixHelper.rotateX(animatorProps.rx.v * mult); 5431 } 5432 } 5433 if (animatorProps.o.propType) { 5434 if (mult.length) { 5435 elemOpacity += ((animatorProps.o.v) * mult[0] - elemOpacity) * mult[0]; 5436 } else { 5437 elemOpacity += ((animatorProps.o.v) * mult - elemOpacity) * mult; 5438 } 5439 } 5440 if (documentData.strokeWidthAnim && animatorProps.sw.propType) { 5441 if (mult.length) { 5442 sw += animatorProps.sw.v * mult[0]; 5443 } else { 5444 sw += animatorProps.sw.v * mult; 5445 } 5446 } 5447 if (documentData.strokeColorAnim && animatorProps.sc.propType) { 5448 for (k = 0; k < 3; k += 1) { 5449 if (mult.length) { 5450 sc[k] += (animatorProps.sc.v[k] - sc[k]) * mult[0]; 5451 } else { 5452 sc[k] += (animatorProps.sc.v[k] - sc[k]) * mult; 5453 } 5454 } 5455 } 5456 if (documentData.fillColorAnim && documentData.fc) { 5457 if (animatorProps.fc.propType) { 5458 for (k = 0; k < 3; k += 1) { 5459 if (mult.length) { 5460 fc[k] += (animatorProps.fc.v[k] - fc[k]) * mult[0]; 5461 } else { 5462 fc[k] += (animatorProps.fc.v[k] - fc[k]) * mult; 5463 } 5464 } 5465 } 5466 if (animatorProps.fh.propType) { 5467 if (mult.length) { 5468 fc = addHueToRGB(fc, animatorProps.fh.v * mult[0]); 5469 } else { 5470 fc = addHueToRGB(fc, animatorProps.fh.v * mult); 5471 } 5472 } 5473 if (animatorProps.fs.propType) { 5474 if (mult.length) { 5475 fc = addSaturationToRGB(fc, animatorProps.fs.v * mult[0]); 5476 } else { 5477 fc = addSaturationToRGB(fc, animatorProps.fs.v * mult); 5478 } 5479 } 5480 if (animatorProps.fb.propType) { 5481 if (mult.length) { 5482 fc = addBrightnessToRGB(fc, animatorProps.fb.v * mult[0]); 5483 } else { 5484 fc = addBrightnessToRGB(fc, animatorProps.fb.v * mult); 5485 } 5486 } 5487 } 5488 } 5489 5490 for (j = 0; j < jLen; j += 1) { 5491 animatorProps = animators[j].a; 5492 5493 if (animatorProps.p.propType) { 5494 animatorSelector = animators[j].s; 5495 mult = animatorSelector.getMult(letters[i].anIndexes[j], textData.a[j].s.totalChars); 5496 if (this._hasMaskedPath) { 5497 if (mult.length) { 5498 matrixHelper.translate(0, animatorProps.p.v[1] * mult[0], -animatorProps.p.v[2] * mult[1]); 5499 } else { 5500 matrixHelper.translate(0, animatorProps.p.v[1] * mult, -animatorProps.p.v[2] * mult); 5501 } 5502 } else if (mult.length) { 5503 matrixHelper.translate(animatorProps.p.v[0] * mult[0], animatorProps.p.v[1] * mult[1], -animatorProps.p.v[2] * mult[2]); 5504 } else { 5505 matrixHelper.translate(animatorProps.p.v[0] * mult, animatorProps.p.v[1] * mult, -animatorProps.p.v[2] * mult); 5506 } 5507 } 5508 } 5509 if (documentData.strokeWidthAnim) { 5510 letterSw = sw < 0 ? 0 : sw; 5511 } 5512 if (documentData.strokeColorAnim) { 5513 letterSc = 'rgb(' + Math.round(sc[0] * 255) + ',' + Math.round(sc[1] * 255) + ',' + Math.round(sc[2] * 255) + ')'; 5514 } 5515 if (documentData.fillColorAnim && documentData.fc) { 5516 letterFc = 'rgb(' + Math.round(fc[0] * 255) + ',' + Math.round(fc[1] * 255) + ',' + Math.round(fc[2] * 255) + ')'; 5517 } 5518 5519 if (this._hasMaskedPath) { 5520 matrixHelper.translate(0, -documentData.ls); 5521 5522 matrixHelper.translate(0, (alignment[1] * yOff) * 0.01 + yPos, 0); 5523 if (textData.p.p) { 5524 tanAngle = (currentPoint.point[1] - prevPoint.point[1]) / (currentPoint.point[0] - prevPoint.point[0]); 5525 var rot = (Math.atan(tanAngle) * 180) / Math.PI; 5526 if (currentPoint.point[0] < prevPoint.point[0]) { 5527 rot += 180; 5528 } 5529 matrixHelper.rotate((-rot * Math.PI) / 180); 5530 } 5531 matrixHelper.translate(xPathPos, yPathPos, 0); 5532 currentLength -= (alignment[0] * letters[i].an) * 0.005; 5533 if (letters[i + 1] && ind !== letters[i + 1].ind) { 5534 currentLength += letters[i].an / 2; 5535 currentLength += (documentData.tr * 0.001) * documentData.finalSize; 5536 } 5537 } else { 5538 matrixHelper.translate(xPos, yPos, 0); 5539 5540 if (documentData.ps) { 5541 // matrixHelper.translate(documentData.ps[0],documentData.ps[1],0); 5542 matrixHelper.translate(documentData.ps[0], documentData.ps[1] + documentData.ascent, 0); 5543 } 5544 switch (documentData.j) { 5545 case 1: 5546 matrixHelper.translate(letters[i].animatorJustifyOffset + documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[letters[i].line]), 0, 0); 5547 break; 5548 case 2: 5549 matrixHelper.translate(letters[i].animatorJustifyOffset + documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[letters[i].line]) / 2, 0, 0); 5550 break; 5551 default: 5552 break; 5553 } 5554 matrixHelper.translate(0, -documentData.ls); 5555 matrixHelper.translate(offf, 0, 0); 5556 matrixHelper.translate((alignment[0] * letters[i].an) * 0.005, (alignment[1] * yOff) * 0.01, 0); 5557 xPos += letters[i].l + (documentData.tr * 0.001) * documentData.finalSize; 5558 } 5559 if (renderType === 'html') { 5560 letterM = matrixHelper.toCSS(); 5561 } else if (renderType === 'svg') { 5562 letterM = matrixHelper.to2dCSS(); 5563 } else { 5564 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]]; 5565 } 5566 letterO = elemOpacity; 5567 } 5568 5569 if (renderedLettersCount <= i) { 5570 letterValue = new LetterProps(letterO, letterSw, letterSc, letterFc, letterM, letterP); 5571 this.renderedLetters.push(letterValue); 5572 renderedLettersCount += 1; 5573 this.lettersChangedFlag = true; 5574 } else { 5575 letterValue = this.renderedLetters[i]; 5576 this.lettersChangedFlag = letterValue.update(letterO, letterSw, letterSc, letterFc, letterM, letterP) || this.lettersChangedFlag; 5577 } 5578 } 5579}; 5580 5581TextAnimatorProperty.prototype.getValue = function () { 5582 if (this._elem.globalData.frameId === this._frameId) { 5583 return; 5584 } 5585 this._frameId = this._elem.globalData.frameId; 5586 this.iterateDynamicProperties(); 5587}; 5588 5589TextAnimatorProperty.prototype.mHelper = new Matrix(); 5590TextAnimatorProperty.prototype.defaultPropsArray = []; 5591extendPrototype([DynamicPropertyContainer], TextAnimatorProperty); 5592 5593/* global PropertyFactory, degToRads, TextSelectorProp */ 5594/* exported TextAnimatorDataProperty */ 5595 5596function TextAnimatorDataProperty(elem, animatorProps, container) { 5597 var defaultData = { propType: false }; 5598 var getProp = PropertyFactory.getProp; 5599 var textAnimatorAnimatables = animatorProps.a; 5600 this.a = { 5601 r: textAnimatorAnimatables.r ? getProp(elem, textAnimatorAnimatables.r, 0, degToRads, container) : defaultData, 5602 rx: textAnimatorAnimatables.rx ? getProp(elem, textAnimatorAnimatables.rx, 0, degToRads, container) : defaultData, 5603 ry: textAnimatorAnimatables.ry ? getProp(elem, textAnimatorAnimatables.ry, 0, degToRads, container) : defaultData, 5604 sk: textAnimatorAnimatables.sk ? getProp(elem, textAnimatorAnimatables.sk, 0, degToRads, container) : defaultData, 5605 sa: textAnimatorAnimatables.sa ? getProp(elem, textAnimatorAnimatables.sa, 0, degToRads, container) : defaultData, 5606 s: textAnimatorAnimatables.s ? getProp(elem, textAnimatorAnimatables.s, 1, 0.01, container) : defaultData, 5607 a: textAnimatorAnimatables.a ? getProp(elem, textAnimatorAnimatables.a, 1, 0, container) : defaultData, 5608 o: textAnimatorAnimatables.o ? getProp(elem, textAnimatorAnimatables.o, 0, 0.01, container) : defaultData, 5609 p: textAnimatorAnimatables.p ? getProp(elem, textAnimatorAnimatables.p, 1, 0, container) : defaultData, 5610 sw: textAnimatorAnimatables.sw ? getProp(elem, textAnimatorAnimatables.sw, 0, 0, container) : defaultData, 5611 sc: textAnimatorAnimatables.sc ? getProp(elem, textAnimatorAnimatables.sc, 1, 0, container) : defaultData, 5612 fc: textAnimatorAnimatables.fc ? getProp(elem, textAnimatorAnimatables.fc, 1, 0, container) : defaultData, 5613 fh: textAnimatorAnimatables.fh ? getProp(elem, textAnimatorAnimatables.fh, 0, 0, container) : defaultData, 5614 fs: textAnimatorAnimatables.fs ? getProp(elem, textAnimatorAnimatables.fs, 0, 0.01, container) : defaultData, 5615 fb: textAnimatorAnimatables.fb ? getProp(elem, textAnimatorAnimatables.fb, 0, 0.01, container) : defaultData, 5616 t: textAnimatorAnimatables.t ? getProp(elem, textAnimatorAnimatables.t, 0, 0, container) : defaultData, 5617 }; 5618 5619 this.s = TextSelectorProp.getTextSelectorProp(elem, animatorProps.s, container); 5620 this.s.t = animatorProps.s.t; 5621} 5622 5623function LetterProps(o, sw, sc, fc, m, p) { 5624 this.o = o; 5625 this.sw = sw; 5626 this.sc = sc; 5627 this.fc = fc; 5628 this.m = m; 5629 this.p = p; 5630 this._mdf = { 5631 o: true, 5632 sw: !!sw, 5633 sc: !!sc, 5634 fc: !!fc, 5635 m: true, 5636 p: true, 5637 }; 5638} 5639 5640LetterProps.prototype.update = function (o, sw, sc, fc, m, p) { 5641 this._mdf.o = false; 5642 this._mdf.sw = false; 5643 this._mdf.sc = false; 5644 this._mdf.fc = false; 5645 this._mdf.m = false; 5646 this._mdf.p = false; 5647 var updated = false; 5648 5649 if (this.o !== o) { 5650 this.o = o; 5651 this._mdf.o = true; 5652 updated = true; 5653 } 5654 if (this.sw !== sw) { 5655 this.sw = sw; 5656 this._mdf.sw = true; 5657 updated = true; 5658 } 5659 if (this.sc !== sc) { 5660 this.sc = sc; 5661 this._mdf.sc = true; 5662 updated = true; 5663 } 5664 if (this.fc !== fc) { 5665 this.fc = fc; 5666 this._mdf.fc = true; 5667 updated = true; 5668 } 5669 if (this.m !== m) { 5670 this.m = m; 5671 this._mdf.m = true; 5672 updated = true; 5673 } 5674 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])) { 5675 this.p = p; 5676 this._mdf.p = true; 5677 updated = true; 5678 } 5679 return updated; 5680}; 5681 5682/* global FontManager, initialDefaultFrame, getFontProperties */ 5683/* exported TextProperty */ 5684 5685function TextProperty(elem, data) { 5686 this._frameId = initialDefaultFrame; 5687 this.pv = ''; 5688 this.v = ''; 5689 this.kf = false; 5690 this._isFirstFrame = true; 5691 this._mdf = false; 5692 this.data = data; 5693 this.elem = elem; 5694 this.comp = this.elem.comp; 5695 this.keysIndex = 0; 5696 this.canResize = false; 5697 this.minimumFontSize = 1; 5698 this.effectsSequence = []; 5699 this.currentData = { 5700 ascent: 0, 5701 boxWidth: this.defaultBoxWidth, 5702 f: '', 5703 fStyle: '', 5704 fWeight: '', 5705 fc: '', 5706 j: '', 5707 justifyOffset: '', 5708 l: [], 5709 lh: 0, 5710 lineWidths: [], 5711 ls: '', 5712 of: '', 5713 s: '', 5714 sc: '', 5715 sw: 0, 5716 t: 0, 5717 tr: 0, 5718 sz: 0, 5719 ps: null, 5720 fillColorAnim: false, 5721 strokeColorAnim: false, 5722 strokeWidthAnim: false, 5723 yOffset: 0, 5724 finalSize: 0, 5725 finalText: [], 5726 finalLineHeight: 0, 5727 __complete: false, 5728 5729 }; 5730 this.copyData(this.currentData, this.data.d.k[0].s); 5731 5732 if (!this.searchProperty()) { 5733 this.completeTextData(this.currentData); 5734 } 5735} 5736 5737TextProperty.prototype.defaultBoxWidth = [0, 0]; 5738 5739TextProperty.prototype.copyData = function (obj, data) { 5740 for (var s in data) { 5741 if (Object.prototype.hasOwnProperty.call(data, s)) { 5742 obj[s] = data[s]; 5743 } 5744 } 5745 return obj; 5746}; 5747 5748TextProperty.prototype.setCurrentData = function (data) { 5749 if (!data.__complete) { 5750 this.completeTextData(data); 5751 } 5752 this.currentData = data; 5753 this.currentData.boxWidth = this.currentData.boxWidth || this.defaultBoxWidth; 5754 this._mdf = true; 5755}; 5756 5757TextProperty.prototype.searchProperty = function () { 5758 return this.searchKeyframes(); 5759}; 5760 5761TextProperty.prototype.searchKeyframes = function () { 5762 this.kf = this.data.d.k.length > 1; 5763 if (this.kf) { 5764 this.addEffect(this.getKeyframeValue.bind(this)); 5765 } 5766 return this.kf; 5767}; 5768 5769TextProperty.prototype.addEffect = function (effectFunction) { 5770 this.effectsSequence.push(effectFunction); 5771 this.elem.addDynamicProperty(this); 5772}; 5773 5774TextProperty.prototype.getValue = function (_finalValue) { 5775 if ((this.elem.globalData.frameId === this.frameId || !this.effectsSequence.length) && !_finalValue) { 5776 return; 5777 } 5778 this.currentData.t = this.data.d.k[this.keysIndex].s.t; 5779 var currentValue = this.currentData; 5780 var currentIndex = this.keysIndex; 5781 if (this.lock) { 5782 this.setCurrentData(this.currentData); 5783 return; 5784 } 5785 this.lock = true; 5786 this._mdf = false; 5787 var i; var 5788 len = this.effectsSequence.length; 5789 var finalValue = _finalValue || this.data.d.k[this.keysIndex].s; 5790 for (i = 0; i < len; i += 1) { 5791 // Checking if index changed to prevent creating a new object every time the expression updates. 5792 if (currentIndex !== this.keysIndex) { 5793 finalValue = this.effectsSequence[i](finalValue, finalValue.t); 5794 } else { 5795 finalValue = this.effectsSequence[i](this.currentData, finalValue.t); 5796 } 5797 } 5798 if (currentValue !== finalValue) { 5799 this.setCurrentData(finalValue); 5800 } 5801 this.v = this.currentData; 5802 this.pv = this.v; 5803 this.lock = false; 5804 this.frameId = this.elem.globalData.frameId; 5805}; 5806 5807TextProperty.prototype.getKeyframeValue = function () { 5808 var textKeys = this.data.d.k; 5809 var frameNum = this.elem.comp.renderedFrame; 5810 var i = 0; var 5811 len = textKeys.length; 5812 while (i <= len - 1) { 5813 if (i === len - 1 || textKeys[i + 1].t > frameNum) { 5814 break; 5815 } 5816 i += 1; 5817 } 5818 if (this.keysIndex !== i) { 5819 this.keysIndex = i; 5820 } 5821 return this.data.d.k[this.keysIndex].s; 5822}; 5823 5824TextProperty.prototype.buildFinalText = function (text) { 5825 var combinedCharacters = FontManager.getCombinedCharacterCodes(); 5826 var charactersArray = []; 5827 var i = 0; var 5828 len = text.length;
vendor: 4,111 bytes, lines 5829-5943
5829 var charCode; 5830 while (i < len) { 5831 charCode = text.charCodeAt(i); 5832 if (combinedCharacters.indexOf(charCode) !== -1) { 5833 charactersArray[charactersArray.length - 1] += text.charAt(i); 5834 } else if (charCode >= 0xD800 && charCode <= 0xDBFF) { 5835 charCode = text.charCodeAt(i + 1); 5836 if (charCode >= 0xDC00 && charCode <= 0xDFFF) { 5837 charactersArray.push(text.substr(i, 2)); 5838 i += 1; 5839 } else { 5840 charactersArray.push(text.charAt(i)); 5841 } 5842 } else { 5843 charactersArray.push(text.charAt(i)); 5844 } 5845 i += 1; 5846 } 5847 return charactersArray; 5848}; 5849 5850TextProperty.prototype.completeTextData = function (documentData) { 5851 documentData.__complete = true; 5852 var fontManager = this.elem.globalData.fontManager; 5853 var data = this.data; 5854 var letters = []; 5855 var i; var 5856 len; 5857 var newLineFlag; var index = 0; var 5858 val; 5859 var anchorGrouping = data.m.g; 5860 var currentSize = 0; var currentPos = 0; var currentLine = 0; var 5861 lineWidths = []; 5862 var lineWidth = 0; 5863 var maxLineWidth = 0; 5864 var j; var 5865 jLen; 5866 var fontData = fontManager.getFontByName(documentData.f); 5867 var charData; var 5868 cLength = 0; 5869 5870 var fontProps = getFontProperties(fontData); 5871 documentData.fWeight = fontProps.weight; 5872 documentData.fStyle = fontProps.style; 5873 documentData.finalSize = documentData.s; 5874 documentData.finalText = this.buildFinalText(documentData.t); 5875 len = documentData.finalText.length; 5876 documentData.finalLineHeight = documentData.lh; 5877 var trackingOffset = (documentData.tr / 1000) * documentData.finalSize; 5878 var charCode; 5879 if (documentData.sz) { 5880 var flag = true; 5881 var boxWidth = documentData.sz[0]; 5882 var boxHeight = documentData.sz[1]; 5883 var currentHeight; var 5884 finalText; 5885 while (flag) { 5886 finalText = this.buildFinalText(documentData.t); 5887 currentHeight = 0; 5888 lineWidth = 0; 5889 len = finalText.length; 5890 trackingOffset = (documentData.tr / 1000) * documentData.finalSize; 5891 var lastSpaceIndex = -1; 5892 for (i = 0; i < len; i += 1) { 5893 charCode = finalText[i].charCodeAt(0); 5894 newLineFlag = false; 5895 if (finalText[i] === ' ') { 5896 lastSpaceIndex = i; 5897 } else if (charCode === 13 || charCode === 3) { 5898 lineWidth = 0; 5899 newLineFlag = true; 5900 currentHeight += documentData.finalLineHeight || documentData.finalSize * 1.2; 5901 } 5902 if (fontManager.chars) { 5903 charData = fontManager.getCharData(finalText[i], fontData.fStyle, fontData.fFamily); 5904 cLength = newLineFlag ? 0 : (charData.w * documentData.finalSize) / 100; 5905 } else { 5906 // tCanvasHelper.font = documentData.s + 'px '+ fontData.fFamily; 5907 cLength = fontManager.measureText(finalText[i], documentData.f, documentData.finalSize); 5908 } 5909 if (lineWidth + cLength > boxWidth && finalText[i] !== ' ') { 5910 if (lastSpaceIndex === -1) { 5911 len += 1; 5912 } else { 5913 i = lastSpaceIndex; 5914 } 5915 currentHeight += documentData.finalLineHeight || documentData.finalSize * 1.2; 5916 finalText.splice(i, lastSpaceIndex === i ? 1 : 0, '\r'); 5917 // finalText = finalText.substr(0,i) + "\r" + finalText.substr(i === lastSpaceIndex ? i + 1 : i); 5918 lastSpaceIndex = -1; 5919 lineWidth = 0; 5920 } else { 5921 lineWidth += cLength; 5922 lineWidth += trackingOffset; 5923 } 5924 } 5925 currentHeight += (fontData.ascent * documentData.finalSize) / 100; 5926 if (this.canResize && documentData.finalSize > this.minimumFontSize && boxHeight < currentHeight) { 5927 documentData.finalSize -= 1; 5928 documentData.finalLineHeight = (documentData.finalSize * documentData.lh) / documentData.s; 5929 } else { 5930 documentData.finalText = finalText; 5931 len = documentData.finalText.length; 5932 flag = false; 5933 } 5934 } 5935 } 5936 lineWidth = -trackingOffset; 5937 cLength = 0; 5938 var uncollapsedSpaces = 0; 5939 var currentChar; 5940 for (i = 0; i < len; i += 1) { 5941 newLineFlag = false; 5942 currentChar = documentData.finalText[i]; 5943 charCode = currentChar.charCodeAt(0);
vendor: 5,076 bytes, lines 5944-6089
5944 if (charCode === 13 || charCode === 3) { 5945 uncollapsedSpaces = 0; 5946 lineWidths.push(lineWidth); 5947 maxLineWidth = lineWidth > maxLineWidth ? lineWidth : maxLineWidth; 5948 lineWidth = -2 * trackingOffset; 5949 val = ''; 5950 newLineFlag = true; 5951 currentLine += 1; 5952 } else { 5953 val = currentChar; 5954 } 5955 if (fontManager.chars) { 5956 charData = fontManager.getCharData(currentChar, fontData.fStyle, fontManager.getFontByName(documentData.f).fFamily); 5957 cLength = newLineFlag ? 0 : (charData.w * documentData.finalSize) / 100; 5958 } else { 5959 // var charWidth = fontManager.measureText(val, documentData.f, documentData.finalSize); 5960 // tCanvasHelper.font = documentData.finalSize + 'px '+ fontManager.getFontByName(documentData.f).fFamily; 5961 cLength = fontManager.measureText(val, documentData.f, documentData.finalSize); 5962 } 5963 5964 // 5965 if (currentChar === ' ') { 5966 uncollapsedSpaces += cLength + trackingOffset; 5967 } else { 5968 lineWidth += cLength + trackingOffset + uncollapsedSpaces; 5969 uncollapsedSpaces = 0; 5970 } 5971 letters.push({ 5972 l: cLength, an: cLength, add: currentSize, n: newLineFlag, anIndexes: [], val: val, line: currentLine, animatorJustifyOffset: 0, 5973 }); 5974 if (anchorGrouping == 2) { // eslint-disable-line eqeqeq 5975 currentSize += cLength; 5976 if (val === '' || val === ' ' || i === len - 1) { 5977 if (val === '' || val === ' ') { 5978 currentSize -= cLength; 5979 } 5980 while (currentPos <= i) { 5981 letters[currentPos].an = currentSize; 5982 letters[currentPos].ind = index; 5983 letters[currentPos].extra = cLength; 5984 currentPos += 1; 5985 } 5986 index += 1; 5987 currentSize = 0; 5988 } 5989 } else if (anchorGrouping == 3) { // eslint-disable-line eqeqeq 5990 currentSize += cLength; 5991 if (val === '' || i === len - 1) { 5992 if (val === '') { 5993 currentSize -= cLength; 5994 } 5995 while (currentPos <= i) { 5996 letters[currentPos].an = currentSize; 5997 letters[currentPos].ind = index; 5998 letters[currentPos].extra = cLength; 5999 currentPos += 1; 6000 } 6001 currentSize = 0; 6002 index += 1; 6003 } 6004 } else { 6005 letters[index].ind = index; 6006 letters[index].extra = 0; 6007 index += 1; 6008 } 6009 } 6010 documentData.l = letters; 6011 maxLineWidth = lineWidth > maxLineWidth ? lineWidth : maxLineWidth; 6012 lineWidths.push(lineWidth); 6013 if (documentData.sz) { 6014 documentData.boxWidth = documentData.sz[0]; 6015 documentData.justifyOffset = 0; 6016 } else { 6017 documentData.boxWidth = maxLineWidth; 6018 switch (documentData.j) { 6019 case 1: 6020 documentData.justifyOffset = -documentData.boxWidth; 6021 break; 6022 case 2: 6023 documentData.justifyOffset = -documentData.boxWidth / 2; 6024 break; 6025 default: 6026 documentData.justifyOffset = 0; 6027 } 6028 } 6029 documentData.lineWidths = lineWidths; 6030 6031 var animators = data.a; var animatorData; var 6032 letterData; 6033 jLen = animators.length; 6034 var based; var ind; var 6035 indexes = []; 6036 for (j = 0; j < jLen; j += 1) { 6037 animatorData = animators[j]; 6038 if (animatorData.a.sc) { 6039 documentData.strokeColorAnim = true; 6040 } 6041 if (animatorData.a.sw) { 6042 documentData.strokeWidthAnim = true; 6043 } 6044 if (animatorData.a.fc || animatorData.a.fh || animatorData.a.fs || animatorData.a.fb) { 6045 documentData.fillColorAnim = true; 6046 } 6047 ind = 0; 6048 based = animatorData.s.b; 6049 for (i = 0; i < len; i += 1) { 6050 letterData = letters[i]; 6051 letterData.anIndexes[j] = ind; 6052 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 6053 if (animatorData.s.rn === 1) { 6054 indexes.push(ind); 6055 } 6056 ind += 1; 6057 } 6058 } 6059 data.a[j].s.totalChars = ind; 6060 var currentInd = -1; var 6061 newInd; 6062 if (animatorData.s.rn === 1) { 6063 for (i = 0; i < len; i += 1) { 6064 letterData = letters[i]; 6065 if (currentInd != letterData.anIndexes[j]) { // eslint-disable-line eqeqeq 6066 currentInd = letterData.anIndexes[j]; 6067 newInd = indexes.splice(Math.floor(Math.random() * indexes.length), 1)[0]; 6068 } 6069 letterData.anIndexes[j] = newInd; 6070 } 6071 } 6072 } 6073 documentData.yOffset = documentData.finalLineHeight || documentData.finalSize * 1.2; 6074 documentData.ls = documentData.ls || 0; 6075 documentData.ascent = (fontData.ascent * documentData.finalSize) / 100; 6076}; 6077 6078TextProperty.prototype.updateDocumentData = function (newData, index) { 6079 index = index === undefined ? this.keysIndex : index; 6080 var dData = this.copyData({}, this.data.d.k[index].s); 6081 dData = this.copyData(dData, newData); 6082 this.data.d.k[index].s = dData; 6083 this.recalculate(index); 6084 this.elem.addDynamicProperty(this); 6085}; 6086 6087TextProperty.prototype.recalculate = function (index) { 6088 var dData = this.data.d.k[index].s; 6089 dData.__complete = false;
vendor: 21,722 bytes, lines 6090-6859
6090 this.keysIndex = 0; 6091 this._isFirstFrame = true; 6092 this.getValue(dData); 6093}; 6094 6095TextProperty.prototype.canResizeFont = function (_canResize) { 6096 this.canResize = _canResize; 6097 this.recalculate(this.keysIndex); 6098 this.elem.addDynamicProperty(this); 6099}; 6100 6101TextProperty.prototype.setMinimumFontSize = function (_fontValue) { 6102 this.minimumFontSize = Math.floor(_fontValue) || 1; 6103 this.recalculate(this.keysIndex); 6104 this.elem.addDynamicProperty(this); 6105}; 6106 6107/* global extendPrototype, BezierFactory, PropertyFactory, DynamicPropertyContainer */ 6108/* exported TextSelectorProp */ 6109 6110var TextSelectorProp = (function () { 6111 var max = Math.max; 6112 var min = Math.min; 6113 var floor = Math.floor; 6114 6115 function TextSelectorPropFactory(elem, data) { 6116 this._currentTextLength = -1; 6117 this.k = false; 6118 this.data = data; 6119 this.elem = elem; 6120 this.comp = elem.comp; 6121 this.finalS = 0; 6122 this.finalE = 0; 6123 this.initDynamicPropertyContainer(elem); 6124 this.s = PropertyFactory.getProp(elem, data.s || { k: 0 }, 0, 0, this); 6125 if ('e' in data) { 6126 this.e = PropertyFactory.getProp(elem, data.e, 0, 0, this); 6127 } else { 6128 this.e = { v: 100 }; 6129 } 6130 this.o = PropertyFactory.getProp(elem, data.o || { k: 0 }, 0, 0, this); 6131 this.xe = PropertyFactory.getProp(elem, data.xe || { k: 0 }, 0, 0, this); 6132 this.ne = PropertyFactory.getProp(elem, data.ne || { k: 0 }, 0, 0, this); 6133 this.a = PropertyFactory.getProp(elem, data.a, 0, 0.01, this); 6134 if (!this.dynamicProperties.length) { 6135 this.getValue(); 6136 } 6137 } 6138 6139 TextSelectorPropFactory.prototype = { 6140 getMult: function (ind) { 6141 if (this._currentTextLength !== this.elem.textProperty.currentData.l.length) { 6142 this.getValue(); 6143 } 6144 // var easer = bez.getEasingCurve(this.ne.v/100,0,1-this.xe.v/100,1); 6145 var x1 = 0; 6146 var y1 = 0; 6147 var x2 = 1; 6148 var y2 = 1; 6149 if (this.ne.v > 0) { 6150 x1 = this.ne.v / 100.0; 6151 } else { 6152 y1 = -this.ne.v / 100.0; 6153 } 6154 if (this.xe.v > 0) { 6155 x2 = 1.0 - this.xe.v / 100.0; 6156 } else { 6157 y2 = 1.0 + this.xe.v / 100.0; 6158 } 6159 var easer = BezierFactory.getBezierEasing(x1, y1, x2, y2).get; 6160 6161 var mult = 0; 6162 var s = this.finalS; 6163 var e = this.finalE; 6164 var type = this.data.sh; 6165 if (type === 2) { 6166 if (e === s) { 6167 mult = ind >= e ? 1 : 0; 6168 } else { 6169 mult = max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1)); 6170 } 6171 mult = easer(mult); 6172 } else if (type === 3) { 6173 if (e === s) { 6174 mult = ind >= e ? 0 : 1; 6175 } else { 6176 mult = 1 - max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1)); 6177 } 6178 6179 mult = easer(mult); 6180 } else if (type === 4) { 6181 if (e === s) { 6182 mult = 0; 6183 } else { 6184 mult = max(0, min(0.5 / (e - s) + (ind - s) / (e - s), 1)); 6185 if (mult < 0.5) { 6186 mult *= 2; 6187 } else { 6188 mult = 1 - 2 * (mult - 0.5); 6189 } 6190 } 6191 mult = easer(mult); 6192 } else if (type === 5) { 6193 if (e === s) { 6194 mult = 0; 6195 } else { 6196 var tot = e - s; 6197 /* ind += 0.5; 6198 mult = -4/(tot*tot)*(ind*ind)+(4/tot)*ind; */ 6199 ind = min(max(0, ind + 0.5 - s), e - s); 6200 var x = -tot / 2 + ind; 6201 var a = tot / 2; 6202 mult = Math.sqrt(1 - (x * x) / (a * a)); 6203 } 6204 mult = easer(mult); 6205 } else if (type === 6) { 6206 if (e === s) { 6207 mult = 0; 6208 } else { 6209 ind = min(max(0, ind + 0.5 - s), e - s); 6210 mult = (1 + (Math.cos((Math.PI + Math.PI * 2 * (ind) / (e - s))))) / 2; // eslint-disable-line 6211 } 6212 mult = easer(mult); 6213 } else { 6214 if (ind >= floor(s)) { 6215 if (ind - s < 0) { 6216 mult = max(0, min(min(e, 1) - (s - ind), 1)); 6217 } else { 6218 mult = max(0, min(e - ind, 1)); 6219 } 6220 } 6221 mult = easer(mult); 6222 } 6223 return mult * this.a.v; 6224 }, 6225 getValue: function (newCharsFlag) { 6226 this.iterateDynamicProperties(); 6227 this._mdf = newCharsFlag || this._mdf; 6228 this._currentTextLength = this.elem.textProperty.currentData.l.length || 0; 6229 if (newCharsFlag && this.data.r === 2) { 6230 this.e.v = this._currentTextLength; 6231 } 6232 var divisor = this.data.r === 2 ? 1 : 100 / this.data.totalChars; 6233 var o = this.o.v / divisor; 6234 var s = this.s.v / divisor + o; 6235 var e = (this.e.v / divisor) + o; 6236 if (s > e) { 6237 var _s = s; 6238 s = e; 6239 e = _s; 6240 } 6241 this.finalS = s; 6242 this.finalE = e; 6243 }, 6244 }; 6245 extendPrototype([DynamicPropertyContainer], TextSelectorPropFactory); 6246 6247 function getTextSelectorProp(elem, data, arr) { 6248 return new TextSelectorPropFactory(elem, data, arr); 6249 } 6250 6251 return { 6252 getTextSelectorProp: getTextSelectorProp, 6253 }; 6254}()); 6255 6256/* global createSizedArray, pooling */ 6257/* exported poolFactory */ 6258 6259var poolFactory = (function () { 6260 return function (initialLength, _create, _release) { 6261 var _length = 0; 6262 var _maxLength = initialLength; 6263 var pool = createSizedArray(_maxLength); 6264 6265 var ob = { 6266 newElement: newElement, 6267 release: release, 6268 }; 6269 6270 function newElement() { 6271 var element; 6272 if (_length) { 6273 _length -= 1; 6274 element = pool[_length]; 6275 } else { 6276 element = _create(); 6277 } 6278 return element; 6279 } 6280 6281 function release(element) { 6282 if (_length === _maxLength) { 6283 pool = pooling.double(pool); 6284 _maxLength *= 2; 6285 } 6286 if (_release) { 6287 _release(element); 6288 } 6289 pool[_length] = element; 6290 _length += 1; 6291 } 6292 6293 return ob; 6294 }; 6295}()); 6296 6297/* global createSizedArray */ 6298/* exported pooling */ 6299 6300var pooling = (function () { 6301 function double(arr) { 6302 return arr.concat(createSizedArray(arr.length)); 6303 } 6304 6305 return { 6306 double: double, 6307 }; 6308}()); 6309 6310/* global createTypedArray, poolFactory */ 6311/* exported pointPool */ 6312 6313var pointPool = (function () { 6314 function create() { 6315 return createTypedArray('float32', 2); 6316 } 6317 return poolFactory(8, create); 6318}()); 6319 6320/* global ShapePath, pointPool, poolFactory */ 6321/* exported shapePool */ 6322 6323var shapePool = (function () { 6324 function create() { 6325 return new ShapePath(); 6326 } 6327 6328 function release(shapePath) { 6329 var len = shapePath._length; 6330 var i; 6331 for (i = 0; i < len; i += 1) { 6332 pointPool.release(shapePath.v[i]); 6333 pointPool.release(shapePath.i[i]); 6334 pointPool.release(shapePath.o[i]); 6335 shapePath.v[i] = null; 6336 shapePath.i[i] = null; 6337 shapePath.o[i] = null; 6338 } 6339 shapePath._length = 0; 6340 shapePath.c = false; 6341 } 6342 6343 function clone(shape) { 6344 var cloned = factory.newElement(); 6345 var i; 6346 var len = shape._length === undefined ? shape.v.length : shape._length; 6347 cloned.setLength(len); 6348 cloned.c = shape.c; 6349 6350 for (i = 0; i < len; i += 1) { 6351 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); 6352 } 6353 return cloned; 6354 } 6355 6356 var factory = poolFactory(4, create, release); 6357 factory.clone = clone; 6358 6359 return factory; 6360}()); 6361 6362/* global createSizedArray, ShapeCollection, shapePool, pooling */ 6363/* exported shapeCollectionPool */ 6364 6365var shapeCollectionPool = (function () { 6366 var ob = { 6367 newShapeCollection: newShapeCollection, 6368 release: release, 6369 }; 6370 6371 var _length = 0; 6372 var _maxLength = 4; 6373 var pool = createSizedArray(_maxLength); 6374 6375 function newShapeCollection() { 6376 var shapeCollection; 6377 if (_length) { 6378 _length -= 1; 6379 shapeCollection = pool[_length]; 6380 } else { 6381 shapeCollection = new ShapeCollection(); 6382 } 6383 return shapeCollection; 6384 } 6385 6386 function release(shapeCollection) { 6387 var i; 6388 var len = shapeCollection._length; 6389 for (i = 0; i < len; i += 1) { 6390 shapePool.release(shapeCollection.shapes[i]); 6391 } 6392 shapeCollection._length = 0; 6393 6394 if (_length === _maxLength) { 6395 pool = pooling.double(pool); 6396 _maxLength *= 2; 6397 } 6398 pool[_length] = shapeCollection; 6399 _length += 1; 6400 } 6401 6402 return ob; 6403}()); 6404 6405/* global poolFactory, bezierLengthPool */ 6406/* exported segmentsLengthPool */ 6407 6408var segmentsLengthPool = (function () { 6409 function create() { 6410 return { 6411 lengths: [], 6412 totalLength: 0, 6413 }; 6414 } 6415 6416 function release(element) { 6417 var i; 6418 var len = element.lengths.length; 6419 for (i = 0; i < len; i += 1) { 6420 bezierLengthPool.release(element.lengths[i]); 6421 } 6422 element.lengths.length = 0; 6423 } 6424 6425 return poolFactory(8, create, release); 6426}()); 6427 6428/* global createTypedArray, defaultCurveSegments, poolFactory */ 6429/* exported bezierLengthPool */ 6430 6431var bezierLengthPool = (function () { 6432 function create() { 6433 return { 6434 addedLength: 0, 6435 percents: createTypedArray('float32', defaultCurveSegments), 6436 lengths: createTypedArray('float32', defaultCurveSegments), 6437 }; 6438 } 6439 return poolFactory(8, create); 6440}()); 6441 6442/* exported markerParser */ 6443 6444var markerParser = ( 6445 6446 function () { 6447 function parsePayloadLines(payload) { 6448 var lines = payload.split('\r\n'); 6449 var keys = {}; 6450 var line; 6451 var keysCount = 0; 6452 for (var i = 0; i < lines.length; i += 1) { 6453 line = lines[i].split(':'); 6454 if (line.length === 2) { 6455 keys[line[0]] = line[1].trim(); 6456 keysCount += 1; 6457 } 6458 } 6459 if (keysCount === 0) { 6460 throw new Error(); 6461 } 6462 return keys; 6463 } 6464 6465 return function (_markers) { 6466 var markers = []; 6467 for (var i = 0; i < _markers.length; i += 1) { 6468 var _marker = _markers[i]; 6469 var markerData = { 6470 time: _marker.tm, 6471 duration: _marker.dr, 6472 }; 6473 try { 6474 markerData.payload = JSON.parse(_markers[i].cm); 6475 } catch (_) { 6476 try { 6477 markerData.payload = parsePayloadLines(_markers[i].cm); 6478 } catch (__) { 6479 markerData.payload = { 6480 name: _markers[i], 6481 }; 6482 } 6483 } 6484 markers.push(markerData); 6485 } 6486 return markers; 6487 }; 6488 }()); 6489 6490/* global AudioElement, FootageElement, FontManager */ 6491 6492function BaseRenderer() {} 6493BaseRenderer.prototype.checkLayers = function (num) { 6494 var i; 6495 var len = this.layers.length; 6496 var data; 6497 this.completeLayers = true; 6498 for (i = len - 1; i >= 0; i -= 1) { 6499 if (!this.elements[i]) { 6500 data = this.layers[i]; 6501 if (data.ip - data.st <= (num - this.layers[i].st) && data.op - data.st > (num - this.layers[i].st)) { 6502 this.buildItem(i); 6503 } 6504 } 6505 this.completeLayers = this.elements[i] ? this.completeLayers : false; 6506 } 6507 this.checkPendingElements(); 6508}; 6509 6510BaseRenderer.prototype.createItem = function (layer) { 6511 switch (layer.ty) { 6512 case 2: 6513 return this.createImage(layer); 6514 case 0: 6515 return this.createComp(layer); 6516 case 1: 6517 return this.createSolid(layer); 6518 case 3: 6519 return this.createNull(layer); 6520 case 4: 6521 return this.createShape(layer); 6522 case 5: 6523 return this.createText(layer); 6524 case 6: 6525 return this.createAudio(layer); 6526 case 13: 6527 return this.createCamera(layer); 6528 case 15: 6529 return this.createFootage(layer); 6530 default: 6531 return this.createNull(layer); 6532 } 6533}; 6534 6535BaseRenderer.prototype.createCamera = function () { 6536 throw new Error('You\'re using a 3d camera. Try the html renderer.'); 6537}; 6538 6539BaseRenderer.prototype.createAudio = function (data) { 6540 return new AudioElement(data, this.globalData, this); 6541}; 6542 6543BaseRenderer.prototype.createFootage = function (data) { 6544 return new FootageElement(data, this.globalData, this); 6545}; 6546 6547BaseRenderer.prototype.buildAllItems = function () { 6548 var i; 6549 var len = this.layers.length; 6550 for (i = 0; i < len; i += 1) { 6551 this.buildItem(i); 6552 } 6553 this.checkPendingElements(); 6554}; 6555 6556BaseRenderer.prototype.includeLayers = function (newLayers) { 6557 this.completeLayers = false; 6558 var i; 6559 var len = newLayers.length; 6560 var j; 6561 var jLen = this.layers.length; 6562 for (i = 0; i < len; i += 1) { 6563 j = 0; 6564 while (j < jLen) { 6565 if (this.layers[j].id === newLayers[i].id) { 6566 this.layers[j] = newLayers[i]; 6567 break; 6568 } 6569 j += 1; 6570 } 6571 } 6572}; 6573 6574BaseRenderer.prototype.setProjectInterface = function (pInterface) { 6575 this.globalData.projectInterface = pInterface; 6576}; 6577 6578BaseRenderer.prototype.initItems = function () { 6579 if (!this.globalData.progressiveLoad) { 6580 this.buildAllItems(); 6581 } 6582}; 6583BaseRenderer.prototype.buildElementParenting = function (element, parentName, hierarchy) { 6584 var elements = this.elements; 6585 var layers = this.layers; 6586 var i = 0; 6587 var len = layers.length; 6588 while (i < len) { 6589 if (layers[i].ind == parentName) { // eslint-disable-line eqeqeq 6590 if (!elements[i] || elements[i] === true) { 6591 this.buildItem(i); 6592 this.addPendingElement(element); 6593 } else { 6594 hierarchy.push(elements[i]); 6595 elements[i].setAsParent(); 6596 if (layers[i].parent !== undefined) { 6597 this.buildElementParenting(element, layers[i].parent, hierarchy); 6598 } else { 6599 element.setHierarchy(hierarchy); 6600 } 6601 } 6602 } 6603 i += 1; 6604 } 6605}; 6606 6607BaseRenderer.prototype.addPendingElement = function (element) { 6608 this.pendingElements.push(element); 6609}; 6610 6611BaseRenderer.prototype.searchExtraCompositions = function (assets) { 6612 var i; 6613 var len = assets.length; 6614 for (i = 0; i < len; i += 1) { 6615 if (assets[i].xt) { 6616 var comp = this.createComp(assets[i]); 6617 comp.initExpressions(); 6618 this.globalData.projectInterface.registerComposition(comp); 6619 } 6620 } 6621}; 6622 6623BaseRenderer.prototype.setupGlobalData = function (animData, fontsContainer) { 6624 this.globalData.fontManager = new FontManager(); 6625 this.globalData.fontManager.addChars(animData.chars); 6626 this.globalData.fontManager.addFonts(animData.fonts, fontsContainer); 6627 this.globalData.getAssetData = this.animationItem.getAssetData.bind(this.animationItem); 6628 this.globalData.getAssetsPath = this.animationItem.getAssetsPath.bind(this.animationItem); 6629 this.globalData.imageLoader = this.animationItem.imagePreloader; 6630 this.globalData.audioController = this.animationItem.audioController; 6631 this.globalData.frameId = 0; 6632 this.globalData.frameRate = animData.fr; 6633 this.globalData.nm = animData.nm; 6634 this.globalData.compSize = { 6635 w: animData.w, 6636 h: animData.h, 6637 }; 6638}; 6639 6640/* global createElementID, extendPrototype, BaseRenderer, NullElement, SVGShapeElement, SVGTextLottieElement, 6641IImageElement, SVGCompElement, ISolidElement, createNS, locationHref, createSizedArray, expressionsPlugin */ 6642 6643function SVGRenderer(animationItem, config) { 6644 this.animationItem = animationItem; 6645 this.layers = null; 6646 this.renderedFrame = -1; 6647 this.svgElement = createNS('svg'); 6648 var ariaLabel = ''; 6649 if (config && config.title) { 6650 var titleElement = createNS('title'); 6651 var titleId = createElementID(); 6652 titleElement.setAttribute('id', titleId); 6653 titleElement.textContent = config.title; 6654 this.svgElement.appendChild(titleElement); 6655 ariaLabel += titleId; 6656 } 6657 if (config && config.description) { 6658 var descElement = createNS('desc'); 6659 var descId = createElementID(); 6660 descElement.setAttribute('id', descId); 6661 descElement.textContent = config.description; 6662 this.svgElement.appendChild(descElement); 6663 ariaLabel += ' ' + descId; 6664 } 6665 if (ariaLabel) { 6666 this.svgElement.setAttribute('aria-labelledby', ariaLabel); 6667 } 6668 var defs = createNS('defs'); 6669 this.svgElement.appendChild(defs); 6670 var maskElement = createNS('g'); 6671 this.svgElement.appendChild(maskElement); 6672 this.layerElement = maskElement; 6673 this.renderConfig = { 6674 preserveAspectRatio: (config && config.preserveAspectRatio) || 'xMidYMid meet', 6675 imagePreserveAspectRatio: (config && config.imagePreserveAspectRatio) || 'xMidYMid slice', 6676 progressiveLoad: (config && config.progressiveLoad) || false, 6677 hideOnTransparent: !((config && config.hideOnTransparent === false)), 6678 viewBoxOnly: (config && config.viewBoxOnly) || false, 6679 viewBoxSize: (config && config.viewBoxSize) || false, 6680 className: (config && config.className) || '', 6681 id: (config && config.id) || '', 6682 focusable: config && config.focusable, 6683 filterSize: { 6684 width: (config && config.filterSize && config.filterSize.width) || '100%', 6685 height: (config && config.filterSize && config.filterSize.height) || '100%', 6686 x: (config && config.filterSize && config.filterSize.x) || '0%', 6687 y: (config && config.filterSize && config.filterSize.y) || '0%', 6688 }, 6689 }; 6690 6691 this.globalData = { 6692 _mdf: false, 6693 frameNum: -1, 6694 defs: defs, 6695 renderConfig: this.renderConfig, 6696 }; 6697 this.elements = []; 6698 this.pendingElements = []; 6699 this.destroyed = false; 6700 this.rendererType = 'svg'; 6701} 6702 6703extendPrototype([BaseRenderer], SVGRenderer); 6704 6705SVGRenderer.prototype.createNull = function (data) { 6706 return new NullElement(data, this.globalData, this); 6707}; 6708 6709SVGRenderer.prototype.createShape = function (data) { 6710 return new SVGShapeElement(data, this.globalData, this); 6711}; 6712 6713SVGRenderer.prototype.createText = function (data) { 6714 return new SVGTextLottieElement(data, this.globalData, this); 6715}; 6716 6717SVGRenderer.prototype.createImage = function (data) { 6718 return new IImageElement(data, this.globalData, this); 6719}; 6720 6721SVGRenderer.prototype.createComp = function (data) { 6722 return new SVGCompElement(data, this.globalData, this); 6723}; 6724 6725SVGRenderer.prototype.createSolid = function (data) { 6726 return new ISolidElement(data, this.globalData, this); 6727}; 6728 6729SVGRenderer.prototype.configAnimation = function (animData) { 6730 this.svgElement.setAttribute('xmlns', 'http://www.w3.org/2000/svg'); 6731 if (this.renderConfig.viewBoxSize) { 6732 this.svgElement.setAttribute('viewBox', this.renderConfig.viewBoxSize); 6733 } else { 6734 this.svgElement.setAttribute('viewBox', '0 0 ' + animData.w + ' ' + animData.h); 6735 } 6736 6737 if (!this.renderConfig.viewBoxOnly) { 6738 this.svgElement.setAttribute('width', animData.w); 6739 this.svgElement.setAttribute('height', animData.h); 6740 this.svgElement.style.width = '100%'; 6741 this.svgElement.style.height = '100%'; 6742 this.svgElement.style.transform = 'translate3d(0,0,0)'; 6743 } 6744 if (this.renderConfig.className) { 6745 this.svgElement.setAttribute('class', this.renderConfig.className); 6746 } 6747 if (this.renderConfig.id) { 6748 this.svgElement.setAttribute('id', this.renderConfig.id); 6749 } 6750 if (this.renderConfig.focusable !== undefined) { 6751 this.svgElement.setAttribute('focusable', this.renderConfig.focusable); 6752 } 6753 this.svgElement.setAttribute('preserveAspectRatio', this.renderConfig.preserveAspectRatio); 6754 // this.layerElement.style.transform = 'translate3d(0,0,0)'; 6755 // this.layerElement.style.transformOrigin = this.layerElement.style.mozTransformOrigin = this.layerElement.style.webkitTransformOrigin = this.layerElement.style['-webkit-transform'] = "0px 0px 0px"; 6756 this.animationItem.wrapper.appendChild(this.svgElement); 6757 // Mask animation 6758 var defs = this.globalData.defs; 6759 6760 this.setupGlobalData(animData, defs); 6761 this.globalData.progressiveLoad = this.renderConfig.progressiveLoad; 6762 this.data = animData; 6763 6764 var maskElement = createNS('clipPath'); 6765 var rect = createNS('rect'); 6766 rect.setAttribute('width', animData.w); 6767 rect.setAttribute('height', animData.h); 6768 rect.setAttribute('x', 0); 6769 rect.setAttribute('y', 0); 6770 var maskId = createElementID(); 6771 maskElement.setAttribute('id', maskId); 6772 maskElement.appendChild(rect); 6773 this.layerElement.setAttribute('clip-path', 'url(' + locationHref + '#' + maskId + ')'); 6774 6775 defs.appendChild(maskElement); 6776 this.layers = animData.layers; 6777 this.elements = createSizedArray(animData.layers.length); 6778}; 6779 6780SVGRenderer.prototype.destroy = function () { 6781 if (this.animationItem.wrapper) { 6782 this.animationItem.wrapper.innerText = ''; 6783 } 6784 this.layerElement = null; 6785 this.globalData.defs = null; 6786 var i; 6787 var len = this.layers ? this.layers.length : 0; 6788 for (i = 0; i < len; i += 1) { 6789 if (this.elements[i]) { 6790 this.elements[i].destroy(); 6791 } 6792 } 6793 this.elements.length = 0; 6794 this.destroyed = true; 6795 this.animationItem = null; 6796}; 6797 6798SVGRenderer.prototype.updateContainerSize = function () { 6799}; 6800 6801SVGRenderer.prototype.buildItem = function (pos) { 6802 var elements = this.elements; 6803 if (elements[pos] || this.layers[pos].ty === 99) { 6804 return; 6805 } 6806 elements[pos] = true; 6807 var element = this.createItem(this.layers[pos]); 6808 6809 elements[pos] = element; 6810 if (expressionsPlugin) { 6811 if (this.layers[pos].ty === 0) { 6812 this.globalData.projectInterface.registerComposition(element); 6813 } 6814 element.initExpressions(); 6815 } 6816 this.appendElementInPos(element, pos); 6817 if (this.layers[pos].tt) { 6818 if (!this.elements[pos - 1] || this.elements[pos - 1] === true) { 6819 this.buildItem(pos - 1); 6820 this.addPendingElement(element); 6821 } else { 6822 element.setMatte(elements[pos - 1].layerId); 6823 } 6824 } 6825}; 6826 6827SVGRenderer.prototype.checkPendingElements = function () { 6828 while (this.pendingElements.length) { 6829 var element = this.pendingElements.pop(); 6830 element.checkParenting(); 6831 if (element.data.tt) { 6832 var i = 0; 6833 var len = this.elements.length; 6834 while (i < len) { 6835 if (this.elements[i] === element) { 6836 element.setMatte(this.elements[i - 1].layerId); 6837 break; 6838 } 6839 i += 1; 6840 } 6841 } 6842 } 6843}; 6844 6845SVGRenderer.prototype.renderFrame = function (num) { 6846 if (this.renderedFrame === num || this.destroyed) { 6847 return; 6848 } 6849 if (num === null) { 6850 num = this.renderedFrame; 6851 } else { 6852 this.renderedFrame = num; 6853 } 6854 // console.log('-------'); 6855 // console.log('FRAME ',num); 6856 this.globalData.frameNum = num; 6857 this.globalData.frameId += 1; 6858 this.globalData.projectInterface.currentFrame = num; 6859 this.globalData._mdf = false;
vendor: 4,812 bytes, lines 6860-6997
6860 var i; 6861 var len = this.layers.length; 6862 if (!this.completeLayers) { 6863 this.checkLayers(num); 6864 } 6865 for (i = len - 1; i >= 0; i -= 1) { 6866 if (this.completeLayers || this.elements[i]) { 6867 this.elements[i].prepareFrame(num - this.layers[i].st); 6868 } 6869 } 6870 if (this.globalData._mdf) { 6871 for (i = 0; i < len; i += 1) { 6872 if (this.completeLayers || this.elements[i]) { 6873 this.elements[i].renderFrame(); 6874 } 6875 } 6876 } 6877}; 6878 6879SVGRenderer.prototype.appendElementInPos = function (element, pos) { 6880 var newElement = element.getBaseElement(); 6881 if (!newElement) { 6882 return; 6883 } 6884 var i = 0; 6885 var nextElement; 6886 while (i < pos) { 6887 if (this.elements[i] && this.elements[i] !== true && this.elements[i].getBaseElement()) { 6888 nextElement = this.elements[i].getBaseElement(); 6889 } 6890 i += 1; 6891 } 6892 if (nextElement) { 6893 this.layerElement.insertBefore(newElement, nextElement); 6894 } else { 6895 this.layerElement.appendChild(newElement); 6896 } 6897}; 6898 6899SVGRenderer.prototype.hide = function () { 6900 this.layerElement.style.display = 'none'; 6901}; 6902 6903SVGRenderer.prototype.show = function () { 6904 this.layerElement.style.display = 'block'; 6905}; 6906 6907/* global CVContextData, Matrix, extendPrototype, BaseRenderer, CVShapeElement, CVTextElement, 6908CVImageElement, CVCompElement, CVSolidElement, SVGRenderer, createTag, createSizedArray */ 6909 6910function CanvasRenderer(animationItem, config) { 6911 this.animationItem = animationItem; 6912 this.renderConfig = { 6913 clearCanvas: (config && config.clearCanvas !== undefined) ? config.clearCanvas : true, 6914 context: (config && config.context) || null, 6915 progressiveLoad: (config && config.progressiveLoad) || false, 6916 preserveAspectRatio: (config && config.preserveAspectRatio) || 'xMidYMid meet', 6917 imagePreserveAspectRatio: (config && config.imagePreserveAspectRatio) || 'xMidYMid slice', 6918 className: (config && config.className) || '', 6919 id: (config && config.id) || '', 6920 }; 6921 this.renderConfig.dpr = (config && config.dpr) || 1; 6922 if (this.animationItem.wrapper) { 6923 this.renderConfig.dpr = (config && config.dpr) || window.devicePixelRatio || 1; 6924 } 6925 this.renderedFrame = -1; 6926 this.globalData = { 6927 frameNum: -1, 6928 _mdf: false, 6929 renderConfig: this.renderConfig, 6930 currentGlobalAlpha: -1, 6931 }; 6932 this.contextData = new CVContextData(); 6933 this.elements = []; 6934 this.pendingElements = []; 6935 this.transformMat = new Matrix(); 6936 this.completeLayers = false; 6937 this.rendererType = 'canvas'; 6938} 6939extendPrototype([BaseRenderer], CanvasRenderer); 6940 6941CanvasRenderer.prototype.createShape = function (data) { 6942 return new CVShapeElement(data, this.globalData, this); 6943}; 6944 6945CanvasRenderer.prototype.createText = function (data) { 6946 return new CVTextElement(data, this.globalData, this); 6947}; 6948 6949CanvasRenderer.prototype.createImage = function (data) { 6950 return new CVImageElement(data, this.globalData, this); 6951}; 6952 6953CanvasRenderer.prototype.createComp = function (data) { 6954 return new CVCompElement(data, this.globalData, this); 6955}; 6956 6957CanvasRenderer.prototype.createSolid = function (data) { 6958 return new CVSolidElement(data, this.globalData, this); 6959}; 6960 6961CanvasRenderer.prototype.createNull = SVGRenderer.prototype.createNull; 6962 6963CanvasRenderer.prototype.ctxTransform = function (props) { 6964 if (props[0] === 1 && props[1] === 0 && props[4] === 0 && props[5] === 1 && props[12] === 0 && props[13] === 0) { 6965 return; 6966 } 6967 if (!this.renderConfig.clearCanvas) { 6968 this.canvasContext.transform(props[0], props[1], props[4], props[5], props[12], props[13]); 6969 return; 6970 } 6971 this.transformMat.cloneFromProps(props); 6972 var cProps = this.contextData.cTr.props; 6973 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]); 6974 // 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]); 6975 this.contextData.cTr.cloneFromProps(this.transformMat.props); 6976 var trProps = this.contextData.cTr.props; 6977 this.canvasContext.setTransform(trProps[0], trProps[1], trProps[4], trProps[5], trProps[12], trProps[13]); 6978}; 6979 6980CanvasRenderer.prototype.ctxOpacity = function (op) { 6981 /* if(op === 1){ 6982 return; 6983 } */ 6984 if (!this.renderConfig.clearCanvas) { 6985 this.canvasContext.globalAlpha *= op < 0 ? 0 : op; 6986 this.globalData.currentGlobalAlpha = this.contextData.cO; 6987 return; 6988 } 6989 this.contextData.cO *= op < 0 ? 0 : op; 6990 if (this.globalData.currentGlobalAlpha !== this.contextData.cO) { 6991 this.canvasContext.globalAlpha = this.contextData.cO; 6992 this.globalData.currentGlobalAlpha = this.contextData.cO; 6993 } 6994}; 6995 6996CanvasRenderer.prototype.reset = function () { 6997 if (!this.renderConfig.clearCanvas) {
6998 this.canvasContext.restore(); 6999 return; 7000 } 7001 this.contextData.reset(); 7002}; 7003 7004CanvasRenderer.prototype.save = function (actionFlag) { 7005 if (!this.renderConfig.clearCanvas) { 7006 this.canvasContext.save(); 7007 return; 7008 } 7009 if (actionFlag) { 7010 this.canvasContext.save(); 7011 } 7012 var props = this.contextData.cTr.props; 7013 if (this.contextData._length <= this.contextData.cArrPos) { 7014 this.contextData.duplicate(); 7015 } 7016 var i; 7017 var arr = this.contextData.saved[this.contextData.cArrPos]; 7018 for (i = 0; i < 16; i += 1) { 7019 arr[i] = props[i]; 7020 } 7021 this.contextData.savedOp[this.contextData.cArrPos] = this.contextData.cO; 7022 this.contextData.cArrPos += 1; 7023}; 7024 7025CanvasRenderer.prototype.restore = function (actionFlag) { 7026 if (!this.renderConfig.clearCanvas) { 7027 this.canvasContext.restore(); 7028 return; 7029 } 7030 if (actionFlag) { 7031 this.canvasContext.restore(); 7032 this.globalData.blendMode = 'source-over'; 7033 } 7034 this.contextData.cArrPos -= 1; 7035 var popped = this.contextData.saved[this.contextData.cArrPos]; 7036 var i; 7037 var arr = this.contextData.cTr.props; 7038 for (i = 0; i < 16; i += 1) { 7039 arr[i] = popped[i]; 7040 } 7041 this.canvasContext.setTransform(popped[0], popped[1], popped[4], popped[5], popped[12], popped[13]); 7042 popped = this.contextData.savedOp[this.contextData.cArrPos]; 7043 this.contextData.cO = popped; 7044 if (this.globalData.currentGlobalAlpha !== popped) { 7045 this.canvasContext.globalAlpha = popped; 7046 this.globalData.currentGlobalAlpha = popped; 7047 } 7048}; 7049 7050CanvasRenderer.prototype.configAnimation = function (animData) { 7051 if (this.animationItem.wrapper) { 7052 this.animationItem.container = createTag('canvas'); 7053 var containerStyle = this.animationItem.container.style; 7054 containerStyle.width = '100%'; 7055 containerStyle.height = '100%'; 7056 var origin = '0px 0px 0px'; 7057 containerStyle.transformOrigin = origin; 7058 containerStyle.mozTransformOrigin = origin; 7059 containerStyle.webkitTransformOrigin = origin; 7060 containerStyle['-webkit-transform'] = origin; 7061 this.animationItem.wrapper.appendChild(this.animationItem.container); 7062 this.canvasContext = this.animationItem.container.getContext('2d'); 7063 if (this.renderConfig.className) { 7064 this.animationItem.container.setAttribute('class', this.renderConfig.className); 7065 } 7066 if (this.renderConfig.id) { 7067 this.animationItem.container.setAttribute('id', this.renderConfig.id); 7068 } 7069 } else { 7070 this.canvasContext = this.renderConfig.context; 7071 } 7072 this.data = animData; 7073 this.layers = animData.layers; 7074 this.transformCanvas = { 7075 w: animData.w, 7076 h: animData.h, 7077 sx: 0, 7078 sy: 0, 7079 tx: 0, 7080 ty: 0, 7081 }; 7082 this.setupGlobalData(animData, document.body); 7083 this.globalData.canvasContext = this.canvasContext; 7084 this.globalData.renderer = this; 7085 this.globalData.isDashed = false; 7086 this.globalData.progressiveLoad = this.renderConfig.progressiveLoad; 7087 this.globalData.transformCanvas = this.transformCanvas; 7088 this.elements = createSizedArray(animData.layers.length); 7089 7090 this.updateContainerSize(); 7091}; 7092 7093CanvasRenderer.prototype.updateContainerSize = function () { 7094 this.reset(); 7095 var elementWidth; 7096 var elementHeight; 7097 if (this.animationItem.wrapper && this.animationItem.container) { 7098 elementWidth = this.animationItem.wrapper.offsetWidth; 7099 elementHeight = this.animationItem.wrapper.offsetHeight; 7100 this.animationItem.container.setAttribute('width', elementWidth * this.renderConfig.dpr); 7101 this.animationItem.container.setAttribute('height', elementHeight * this.renderConfig.dpr); 7102 } else { 7103 elementWidth = this.canvasContext.canvas.width * this.renderConfig.dpr; 7104 elementHeight = this.canvasContext.canvas.height * this.renderConfig.dpr; 7105 } 7106 var elementRel; 7107 var animationRel; 7108 if (this.renderConfig.preserveAspectRatio.indexOf('meet') !== -1 || this.renderConfig.preserveAspectRatio.indexOf('slice') !== -1) { 7109 var par = this.renderConfig.preserveAspectRatio.split(' '); 7110 var fillType = par[1] || 'meet'; 7111 var pos = par[0] || 'xMidYMid'; 7112 var xPos = pos.substr(0, 4); 7113 var yPos = pos.substr(4); 7114 elementRel = elementWidth / elementHeight; 7115 animationRel = this.transformCanvas.w / this.transformCanvas.h; 7116 if ((animationRel > elementRel && fillType === 'meet') || (animationRel < elementRel && fillType === 'slice')) { 7117 this.transformCanvas.sx = elementWidth / (this.transformCanvas.w / this.renderConfig.dpr); 7118 this.transformCanvas.sy = elementWidth / (this.transformCanvas.w / this.renderConfig.dpr); 7119 } else { 7120 this.transformCanvas.sx = elementHeight / (this.transformCanvas.h / this.renderConfig.dpr); 7121 this.transformCanvas.sy = elementHeight / (this.transformCanvas.h / this.renderConfig.dpr); 7122 } 7123 7124 if (xPos === 'xMid' && ((animationRel < elementRel && fillType === 'meet') || (animationRel > elementRel && fillType === 'slice'))) { 7125 this.transformCanvas.tx = ((elementWidth - this.transformCanvas.w * (elementHeight / this.transformCanvas.h)) / 2) * this.renderConfig.dpr; 7126 } else if (xPos === 'xMax' && ((animationRel < elementRel && fillType === 'meet') || (animationRel > elementRel && fillType === 'slice'))) { 7127 this.transformCanvas.tx = (elementWidth - this.transformCanvas.w * (elementHeight / this.transformCanvas.h)) * this.renderConfig.dpr; 7128 } else { 7129 this.transformCanvas.tx = 0; 7130 } 7131 if (yPos === 'YMid' && ((animationRel > elementRel && fillType === 'meet') || (animationRel < elementRel && fillType === 'slice'))) {
vendor: 9,499 bytes, lines 7132-7416
7132 this.transformCanvas.ty = ((elementHeight - this.transformCanvas.h * (elementWidth / this.transformCanvas.w)) / 2) * this.renderConfig.dpr; 7133 } else if (yPos === 'YMax' && ((animationRel > elementRel && fillType === 'meet') || (animationRel < elementRel && fillType === 'slice'))) { 7134 this.transformCanvas.ty = ((elementHeight - this.transformCanvas.h * (elementWidth / this.transformCanvas.w))) * this.renderConfig.dpr; 7135 } else { 7136 this.transformCanvas.ty = 0; 7137 } 7138 } else if (this.renderConfig.preserveAspectRatio === 'none') { 7139 this.transformCanvas.sx = elementWidth / (this.transformCanvas.w / this.renderConfig.dpr); 7140 this.transformCanvas.sy = elementHeight / (this.transformCanvas.h / this.renderConfig.dpr); 7141 this.transformCanvas.tx = 0; 7142 this.transformCanvas.ty = 0; 7143 } else { 7144 this.transformCanvas.sx = this.renderConfig.dpr; 7145 this.transformCanvas.sy = this.renderConfig.dpr; 7146 this.transformCanvas.tx = 0; 7147 this.transformCanvas.ty = 0; 7148 } 7149 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]; 7150 /* var i, len = this.elements.length; 7151 for(i=0;i<len;i+=1){ 7152 if(this.elements[i] && this.elements[i].data.ty === 0){ 7153 this.elements[i].resize(this.globalData.transformCanvas); 7154 } 7155 } */ 7156 this.ctxTransform(this.transformCanvas.props); 7157 this.canvasContext.beginPath(); 7158 this.canvasContext.rect(0, 0, this.transformCanvas.w, this.transformCanvas.h); 7159 this.canvasContext.closePath(); 7160 this.canvasContext.clip(); 7161 7162 this.renderFrame(this.renderedFrame, true); 7163}; 7164 7165CanvasRenderer.prototype.destroy = function () { 7166 if (this.renderConfig.clearCanvas && this.animationItem.wrapper) { 7167 this.animationItem.wrapper.innerText = ''; 7168 } 7169 var i; 7170 var len = this.layers ? this.layers.length : 0; 7171 for (i = len - 1; i >= 0; i -= 1) { 7172 if (this.elements[i]) { 7173 this.elements[i].destroy(); 7174 } 7175 } 7176 this.elements.length = 0; 7177 this.globalData.canvasContext = null; 7178 this.animationItem.container = null; 7179 this.destroyed = true; 7180}; 7181 7182CanvasRenderer.prototype.renderFrame = function (num, forceRender) { 7183 if ((this.renderedFrame === num && this.renderConfig.clearCanvas === true && !forceRender) || this.destroyed || num === -1) { 7184 return; 7185 } 7186 this.renderedFrame = num; 7187 this.globalData.frameNum = num - this.animationItem._isFirstFrame; 7188 this.globalData.frameId += 1; 7189 this.globalData._mdf = !this.renderConfig.clearCanvas || forceRender; 7190 this.globalData.projectInterface.currentFrame = num; 7191 7192 // console.log('--------'); 7193 // console.log('NEW: ',num); 7194 var i; 7195 var len = this.layers.length; 7196 if (!this.completeLayers) { 7197 this.checkLayers(num); 7198 } 7199 7200 for (i = 0; i < len; i += 1) { 7201 if (this.completeLayers || this.elements[i]) { 7202 this.elements[i].prepareFrame(num - this.layers[i].st); 7203 } 7204 } 7205 if (this.globalData._mdf) { 7206 if (this.renderConfig.clearCanvas === true) { 7207 this.canvasContext.clearRect(0, 0, this.transformCanvas.w, this.transformCanvas.h); 7208 } else { 7209 this.save(); 7210 } 7211 for (i = len - 1; i >= 0; i -= 1) { 7212 if (this.completeLayers || this.elements[i]) { 7213 this.elements[i].renderFrame(); 7214 } 7215 } 7216 if (this.renderConfig.clearCanvas !== true) { 7217 this.restore(); 7218 } 7219 } 7220}; 7221 7222CanvasRenderer.prototype.buildItem = function (pos) { 7223 var elements = this.elements; 7224 if (elements[pos] || this.layers[pos].ty === 99) { 7225 return; 7226 } 7227 var element = this.createItem(this.layers[pos], this, this.globalData); 7228 elements[pos] = element; 7229 element.initExpressions(); 7230 /* if(this.layers[pos].ty === 0){ 7231 element.resize(this.globalData.transformCanvas); 7232 } */ 7233}; 7234 7235CanvasRenderer.prototype.checkPendingElements = function () { 7236 while (this.pendingElements.length) { 7237 var element = this.pendingElements.pop(); 7238 element.checkParenting(); 7239 } 7240}; 7241 7242CanvasRenderer.prototype.hide = function () { 7243 this.animationItem.container.style.display = 'none'; 7244}; 7245 7246CanvasRenderer.prototype.show = function () { 7247 this.animationItem.container.style.display = 'block'; 7248}; 7249 7250/* global extendPrototype, BaseRenderer, SVGRenderer, SVGShapeElement, HShapeElement, SVGTextLottieElement, 7251HTextElement, HCameraElement, IImageElement, HImageElement, SVGCompElement, HCompElement, ISolidElement, 7252HSolidElement, styleDiv, createTag, createNS */ 7253 7254function HybridRenderer(animationItem, config) { 7255 this.animationItem = animationItem; 7256 this.layers = null; 7257 this.renderedFrame = -1; 7258 this.renderConfig = { 7259 className: (config && config.className) || '', 7260 imagePreserveAspectRatio: (config && config.imagePreserveAspectRatio) || 'xMidYMid slice', 7261 hideOnTransparent: !(config && config.hideOnTransparent === false), 7262 filterSize: { 7263 width: (config && config.filterSize && config.filterSize.width) || '400%', 7264 height: (config && config.filterSize && config.filterSize.height) || '400%', 7265 x: (config && config.filterSize && config.filterSize.x) || '-100%', 7266 y: (config && config.filterSize && config.filterSize.y) || '-100%', 7267 }, 7268 }; 7269 this.globalData = { 7270 _mdf: false, 7271 frameNum: -1, 7272 renderConfig: this.renderConfig, 7273 }; 7274 this.pendingElements = []; 7275 this.elements = []; 7276 this.threeDElements = []; 7277 this.destroyed = false; 7278 this.camera = null; 7279 this.supports3d = true; 7280 this.rendererType = 'html'; 7281} 7282 7283extendPrototype([BaseRenderer], HybridRenderer); 7284 7285HybridRenderer.prototype.buildItem = SVGRenderer.prototype.buildItem; 7286 7287HybridRenderer.prototype.checkPendingElements = function () { 7288 while (this.pendingElements.length) { 7289 var element = this.pendingElements.pop(); 7290 element.checkParenting(); 7291 } 7292}; 7293 7294HybridRenderer.prototype.appendElementInPos = function (element, pos) { 7295 var newDOMElement = element.getBaseElement(); 7296 if (!newDOMElement) { 7297 return; 7298 } 7299 var layer = this.layers[pos]; 7300 if (!layer.ddd || !this.supports3d) { 7301 if (this.threeDElements) { 7302 this.addTo3dContainer(newDOMElement, pos); 7303 } else { 7304 var i = 0; 7305 var nextDOMElement; 7306 var nextLayer; 7307 var tmpDOMElement; 7308 while (i < pos) { 7309 if (this.elements[i] && this.elements[i] !== true && this.elements[i].getBaseElement) { 7310 nextLayer = this.elements[i]; 7311 tmpDOMElement = this.layers[i].ddd ? this.getThreeDContainerByPos(i) : nextLayer.getBaseElement(); 7312 nextDOMElement = tmpDOMElement || nextDOMElement; 7313 } 7314 i += 1; 7315 } 7316 if (nextDOMElement) { 7317 if (!layer.ddd || !this.supports3d) { 7318 this.layerElement.insertBefore(newDOMElement, nextDOMElement); 7319 } 7320 } else if (!layer.ddd || !this.supports3d) { 7321 this.layerElement.appendChild(newDOMElement); 7322 } 7323 } 7324 } else { 7325 this.addTo3dContainer(newDOMElement, pos); 7326 } 7327}; 7328 7329HybridRenderer.prototype.createShape = function (data) { 7330 if (!this.supports3d) { 7331 return new SVGShapeElement(data, this.globalData, this); 7332 } 7333 return new HShapeElement(data, this.globalData, this); 7334}; 7335 7336HybridRenderer.prototype.createText = function (data) { 7337 if (!this.supports3d) { 7338 return new SVGTextLottieElement(data, this.globalData, this); 7339 } 7340 return new HTextElement(data, this.globalData, this); 7341}; 7342 7343HybridRenderer.prototype.createCamera = function (data) { 7344 this.camera = new HCameraElement(data, this.globalData, this); 7345 return this.camera; 7346}; 7347 7348HybridRenderer.prototype.createImage = function (data) { 7349 if (!this.supports3d) { 7350 return new IImageElement(data, this.globalData, this); 7351 } 7352 return new HImageElement(data, this.globalData, this); 7353}; 7354 7355HybridRenderer.prototype.createComp = function (data) { 7356 if (!this.supports3d) { 7357 return new SVGCompElement(data, this.globalData, this); 7358 } 7359 return new HCompElement(data, this.globalData, this); 7360}; 7361 7362HybridRenderer.prototype.createSolid = function (data) { 7363 if (!this.supports3d) { 7364 return new ISolidElement(data, this.globalData, this); 7365 } 7366 return new HSolidElement(data, this.globalData, this); 7367}; 7368 7369HybridRenderer.prototype.createNull = SVGRenderer.prototype.createNull; 7370 7371HybridRenderer.prototype.getThreeDContainerByPos = function (pos) { 7372 var i = 0; 7373 var len = this.threeDElements.length; 7374 while (i < len) { 7375 if (this.threeDElements[i].startPos <= pos && this.threeDElements[i].endPos >= pos) { 7376 return this.threeDElements[i].perspectiveElem; 7377 } 7378 i += 1; 7379 } 7380 return null; 7381}; 7382 7383HybridRenderer.prototype.createThreeDContainer = function (pos, type) { 7384 var perspectiveElem = createTag('div'); 7385 var style; 7386 var containerStyle; 7387 styleDiv(perspectiveElem); 7388 var container = createTag('div'); 7389 styleDiv(container); 7390 if (type === '3d') { 7391 style = perspectiveElem.style; 7392 style.width = this.globalData.compSize.w + 'px'; 7393 style.height = this.globalData.compSize.h + 'px'; 7394 var center = '50% 50%'; 7395 style.webkitTransformOrigin = center; 7396 style.mozTransformOrigin = center; 7397 style.transformOrigin = center; 7398 containerStyle = container.style; 7399 var matrix = 'matrix3d(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)'; 7400 containerStyle.transform = matrix; 7401 containerStyle.webkitTransform = matrix; 7402 } 7403 7404 perspectiveElem.appendChild(container); 7405 // this.resizerElem.appendChild(perspectiveElem); 7406 var threeDContainerData = { 7407 container: container, 7408 perspectiveElem: perspectiveElem, 7409 startPos: pos, 7410 endPos: pos, 7411 type: type, 7412 }; 7413 this.threeDElements.push(threeDContainerData); 7414 return threeDContainerData; 7415}; 7416
vendor: 36,008 bytes, lines 7417-8550
7417HybridRenderer.prototype.build3dContainers = function () { 7418 var i; 7419 var len = this.layers.length; 7420 var lastThreeDContainerData; 7421 var currentContainer = ''; 7422 for (i = 0; i < len; i += 1) { 7423 if (this.layers[i].ddd && this.layers[i].ty !== 3) { 7424 if (currentContainer !== '3d') { 7425 currentContainer = '3d'; 7426 lastThreeDContainerData = this.createThreeDContainer(i, '3d'); 7427 } 7428 lastThreeDContainerData.endPos = Math.max(lastThreeDContainerData.endPos, i); 7429 } else { 7430 if (currentContainer !== '2d') { 7431 currentContainer = '2d'; 7432 lastThreeDContainerData = this.createThreeDContainer(i, '2d'); 7433 } 7434 lastThreeDContainerData.endPos = Math.max(lastThreeDContainerData.endPos, i); 7435 } 7436 } 7437 len = this.threeDElements.length; 7438 for (i = len - 1; i >= 0; i -= 1) { 7439 this.resizerElem.appendChild(this.threeDElements[i].perspectiveElem); 7440 } 7441}; 7442 7443HybridRenderer.prototype.addTo3dContainer = function (elem, pos) { 7444 var i = 0; 7445 var len = this.threeDElements.length; 7446 while (i < len) { 7447 if (pos <= this.threeDElements[i].endPos) { 7448 var j = this.threeDElements[i].startPos; 7449 var nextElement; 7450 while (j < pos) { 7451 if (this.elements[j] && this.elements[j].getBaseElement) { 7452 nextElement = this.elements[j].getBaseElement(); 7453 } 7454 j += 1; 7455 } 7456 if (nextElement) { 7457 this.threeDElements[i].container.insertBefore(elem, nextElement); 7458 } else { 7459 this.threeDElements[i].container.appendChild(elem); 7460 } 7461 break; 7462 } 7463 i += 1; 7464 } 7465}; 7466 7467HybridRenderer.prototype.configAnimation = function (animData) { 7468 var resizerElem = createTag('div'); 7469 var wrapper = this.animationItem.wrapper; 7470 var style = resizerElem.style; 7471 style.width = animData.w + 'px'; 7472 style.height = animData.h + 'px'; 7473 this.resizerElem = resizerElem; 7474 styleDiv(resizerElem); 7475 style.transformStyle = 'flat'; 7476 style.mozTransformStyle = 'flat'; 7477 style.webkitTransformStyle = 'flat'; 7478 if (this.renderConfig.className) { 7479 resizerElem.setAttribute('class', this.renderConfig.className); 7480 } 7481 wrapper.appendChild(resizerElem); 7482 7483 style.overflow = 'hidden'; 7484 var svg = createNS('svg'); 7485 svg.setAttribute('width', '1'); 7486 svg.setAttribute('height', '1'); 7487 styleDiv(svg); 7488 this.resizerElem.appendChild(svg); 7489 var defs = createNS('defs'); 7490 svg.appendChild(defs); 7491 this.data = animData; 7492 // Mask animation 7493 this.setupGlobalData(animData, svg); 7494 this.globalData.defs = defs; 7495 this.layers = animData.layers; 7496 this.layerElement = this.resizerElem; 7497 this.build3dContainers(); 7498 this.updateContainerSize(); 7499}; 7500 7501HybridRenderer.prototype.destroy = function () { 7502 if (this.animationItem.wrapper) { 7503 this.animationItem.wrapper.innerText = ''; 7504 } 7505 this.animationItem.container = null; 7506 this.globalData.defs = null; 7507 var i; 7508 var len = this.layers ? this.layers.length : 0; 7509 for (i = 0; i < len; i += 1) { 7510 this.elements[i].destroy(); 7511 } 7512 this.elements.length = 0; 7513 this.destroyed = true; 7514 this.animationItem = null; 7515}; 7516 7517HybridRenderer.prototype.updateContainerSize = function () { 7518 var elementWidth = this.animationItem.wrapper.offsetWidth; 7519 var elementHeight = this.animationItem.wrapper.offsetHeight; 7520 var elementRel = elementWidth / elementHeight; 7521 var animationRel = this.globalData.compSize.w / this.globalData.compSize.h; 7522 var sx; 7523 var sy; 7524 var tx; 7525 var ty; 7526 if (animationRel > elementRel) { 7527 sx = elementWidth / (this.globalData.compSize.w); 7528 sy = elementWidth / (this.globalData.compSize.w); 7529 tx = 0; 7530 ty = ((elementHeight - this.globalData.compSize.h * (elementWidth / this.globalData.compSize.w)) / 2); 7531 } else { 7532 sx = elementHeight / (this.globalData.compSize.h); 7533 sy = elementHeight / (this.globalData.compSize.h); 7534 tx = (elementWidth - this.globalData.compSize.w * (elementHeight / this.globalData.compSize.h)) / 2; 7535 ty = 0; 7536 } 7537 var style = this.resizerElem.style; 7538 style.webkitTransform = 'matrix3d(' + sx + ',0,0,0,0,' + sy + ',0,0,0,0,1,0,' + tx + ',' + ty + ',0,1)'; 7539 style.transform = style.webkitTransform; 7540}; 7541 7542HybridRenderer.prototype.renderFrame = SVGRenderer.prototype.renderFrame; 7543 7544HybridRenderer.prototype.hide = function () { 7545 this.resizerElem.style.display = 'none'; 7546}; 7547 7548HybridRenderer.prototype.show = function () { 7549 this.resizerElem.style.display = 'block'; 7550}; 7551 7552HybridRenderer.prototype.initItems = function () { 7553 this.buildAllItems(); 7554 if (this.camera) { 7555 this.camera.setup(); 7556 } else { 7557 var cWidth = this.globalData.compSize.w; 7558 var cHeight = this.globalData.compSize.h; 7559 var i; 7560 var len = this.threeDElements.length; 7561 for (i = 0; i < len; i += 1) { 7562 var style = this.threeDElements[i].perspectiveElem.style; 7563 style.webkitPerspective = Math.sqrt(Math.pow(cWidth, 2) + Math.pow(cHeight, 2)) + 'px'; 7564 style.perspective = style.webkitPerspective; 7565 } 7566 } 7567}; 7568 7569HybridRenderer.prototype.searchExtraCompositions = function (assets) { 7570 var i; 7571 var len = assets.length; 7572 var floatingContainer = createTag('div'); 7573 for (i = 0; i < len; i += 1) { 7574 if (assets[i].xt) { 7575 var comp = this.createComp(assets[i], floatingContainer, this.globalData.comp, null); 7576 comp.initExpressions(); 7577 this.globalData.projectInterface.registerComposition(comp); 7578 } 7579 } 7580}; 7581 7582/* global createSizedArray, createElementID, PropertyFactory, ShapePropertyFactory, createNS, locationHref */ 7583 7584function MaskElement(data, element, globalData) { 7585 this.data = data; 7586 this.element = element; 7587 this.globalData = globalData; 7588 this.storedData = []; 7589 this.masksProperties = this.data.masksProperties || []; 7590 this.maskElement = null; 7591 var defs = this.globalData.defs; 7592 var i; 7593 var len = this.masksProperties ? this.masksProperties.length : 0; 7594 this.viewData = createSizedArray(len); 7595 this.solidPath = ''; 7596 7597 var path; 7598 var properties = this.masksProperties; 7599 var count = 0; 7600 var currentMasks = []; 7601 var j; 7602 var jLen; 7603 var layerId = createElementID(); 7604 var rect; 7605 var expansor; 7606 var feMorph; 7607 var x; 7608 var maskType = 'clipPath'; 7609 var maskRef = 'clip-path'; 7610 for (i = 0; i < len; i += 1) { 7611 if ((properties[i].mode !== 'a' && properties[i].mode !== 'n') || properties[i].inv || properties[i].o.k !== 100 || properties[i].o.x) { 7612 maskType = 'mask'; 7613 maskRef = 'mask'; 7614 } 7615 7616 if ((properties[i].mode === 's' || properties[i].mode === 'i') && count === 0) { 7617 rect = createNS('rect'); 7618 rect.setAttribute('fill', '#ffffff'); 7619 rect.setAttribute('width', this.element.comp.data.w || 0); 7620 rect.setAttribute('height', this.element.comp.data.h || 0); 7621 currentMasks.push(rect); 7622 } else { 7623 rect = null; 7624 } 7625 7626 path = createNS('path'); 7627 if (properties[i].mode === 'n') { 7628 // TODO move this to a factory or to a constructor 7629 this.viewData[i] = { 7630 op: PropertyFactory.getProp(this.element, properties[i].o, 0, 0.01, this.element), 7631 prop: ShapePropertyFactory.getShapeProp(this.element, properties[i], 3), 7632 elem: path, 7633 lastPath: '', 7634 }; 7635 defs.appendChild(path); 7636 } else { 7637 count += 1; 7638 7639 path.setAttribute('fill', properties[i].mode === 's' ? '#000000' : '#ffffff'); 7640 path.setAttribute('clip-rule', 'nonzero'); 7641 var filterID; 7642 7643 if (properties[i].x.k !== 0) { 7644 maskType = 'mask'; 7645 maskRef = 'mask'; 7646 x = PropertyFactory.getProp(this.element, properties[i].x, 0, null, this.element); 7647 filterID = createElementID(); 7648 expansor = createNS('filter'); 7649 expansor.setAttribute('id', filterID); 7650 feMorph = createNS('feMorphology'); 7651 feMorph.setAttribute('operator', 'erode'); 7652 feMorph.setAttribute('in', 'SourceGraphic'); 7653 feMorph.setAttribute('radius', '0'); 7654 expansor.appendChild(feMorph); 7655 defs.appendChild(expansor); 7656 path.setAttribute('stroke', properties[i].mode === 's' ? '#000000' : '#ffffff'); 7657 } else { 7658 feMorph = null; 7659 x = null; 7660 } 7661 7662 // TODO move this to a factory or to a constructor 7663 this.storedData[i] = { 7664 elem: path, 7665 x: x, 7666 expan: feMorph, 7667 lastPath: '', 7668 lastOperator: '', 7669 filterId: filterID, 7670 lastRadius: 0, 7671 }; 7672 if (properties[i].mode === 'i') { 7673 jLen = currentMasks.length; 7674 var g = createNS('g'); 7675 for (j = 0; j < jLen; j += 1) { 7676 g.appendChild(currentMasks[j]); 7677 } 7678 var mask = createNS('mask'); 7679 mask.setAttribute('mask-type', 'alpha'); 7680 mask.setAttribute('id', layerId + '_' + count); 7681 mask.appendChild(path); 7682 defs.appendChild(mask); 7683 g.setAttribute('mask', 'url(' + locationHref + '#' + layerId + '_' + count + ')'); 7684 7685 currentMasks.length = 0; 7686 currentMasks.push(g); 7687 } else { 7688 currentMasks.push(path); 7689 } 7690 if (properties[i].inv && !this.solidPath) { 7691 this.solidPath = this.createLayerSolidPath(); 7692 } 7693 // TODO move this to a factory or to a constructor 7694 this.viewData[i] = { 7695 elem: path, 7696 lastPath: '', 7697 op: PropertyFactory.getProp(this.element, properties[i].o, 0, 0.01, this.element), 7698 prop: ShapePropertyFactory.getShapeProp(this.element, properties[i], 3), 7699 invRect: rect, 7700 }; 7701 if (!this.viewData[i].prop.k) { 7702 this.drawPath(properties[i], this.viewData[i].prop.v, this.viewData[i]); 7703 } 7704 } 7705 } 7706 7707 this.maskElement = createNS(maskType); 7708 7709 len = currentMasks.length; 7710 for (i = 0; i < len; i += 1) { 7711 this.maskElement.appendChild(currentMasks[i]); 7712 } 7713 7714 if (count > 0) { 7715 this.maskElement.setAttribute('id', layerId); 7716 this.element.maskedElement.setAttribute(maskRef, 'url(' + locationHref + '#' + layerId + ')'); 7717 defs.appendChild(this.maskElement); 7718 } 7719 if (this.viewData.length) { 7720 this.element.addRenderableComponent(this); 7721 } 7722} 7723 7724MaskElement.prototype.getMaskProperty = function (pos) { 7725 return this.viewData[pos].prop; 7726}; 7727 7728MaskElement.prototype.renderFrame = function (isFirstFrame) { 7729 var finalMat = this.element.finalTransform.mat; 7730 var i; 7731 var len = this.masksProperties.length; 7732 for (i = 0; i < len; i += 1) { 7733 if (this.viewData[i].prop._mdf || isFirstFrame) { 7734 this.drawPath(this.masksProperties[i], this.viewData[i].prop.v, this.viewData[i]); 7735 } 7736 if (this.viewData[i].op._mdf || isFirstFrame) { 7737 this.viewData[i].elem.setAttribute('fill-opacity', this.viewData[i].op.v); 7738 } 7739 if (this.masksProperties[i].mode !== 'n') { 7740 if (this.viewData[i].invRect && (this.element.finalTransform.mProp._mdf || isFirstFrame)) { 7741 this.viewData[i].invRect.setAttribute('transform', finalMat.getInverseMatrix().to2dCSS()); 7742 } 7743 if (this.storedData[i].x && (this.storedData[i].x._mdf || isFirstFrame)) { 7744 var feMorph = this.storedData[i].expan; 7745 if (this.storedData[i].x.v < 0) { 7746 if (this.storedData[i].lastOperator !== 'erode') { 7747 this.storedData[i].lastOperator = 'erode'; 7748 this.storedData[i].elem.setAttribute('filter', 'url(' + locationHref + '#' + this.storedData[i].filterId + ')'); 7749 } 7750 feMorph.setAttribute('radius', -this.storedData[i].x.v); 7751 } else { 7752 if (this.storedData[i].lastOperator !== 'dilate') { 7753 this.storedData[i].lastOperator = 'dilate'; 7754 this.storedData[i].elem.setAttribute('filter', null); 7755 } 7756 this.storedData[i].elem.setAttribute('stroke-width', this.storedData[i].x.v * 2); 7757 } 7758 } 7759 } 7760 } 7761}; 7762 7763MaskElement.prototype.getMaskelement = function () { 7764 return this.maskElement; 7765}; 7766 7767MaskElement.prototype.createLayerSolidPath = function () { 7768 var path = 'M0,0 '; 7769 path += ' h' + this.globalData.compSize.w; 7770 path += ' v' + this.globalData.compSize.h; 7771 path += ' h-' + this.globalData.compSize.w; 7772 path += ' v-' + this.globalData.compSize.h + ' '; 7773 return path; 7774}; 7775 7776MaskElement.prototype.drawPath = function (pathData, pathNodes, viewData) { 7777 var pathString = ' M' + pathNodes.v[0][0] + ',' + pathNodes.v[0][1]; 7778 var i; 7779 var len; 7780 len = pathNodes._length; 7781 for (i = 1; i < len; i += 1) { 7782 // 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]; 7783 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]; 7784 } 7785 // 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]; 7786 if (pathNodes.c && len > 1) { 7787 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]; 7788 } 7789 // pathNodes.__renderedString = pathString; 7790 7791 if (viewData.lastPath !== pathString) { 7792 var pathShapeValue = ''; 7793 if (viewData.elem) { 7794 if (pathNodes.c) { 7795 pathShapeValue = pathData.inv ? this.solidPath + pathString : pathString; 7796 } 7797 viewData.elem.setAttribute('d', pathShapeValue); 7798 } 7799 viewData.lastPath = pathString; 7800 } 7801}; 7802 7803MaskElement.prototype.destroy = function () { 7804 this.element = null; 7805 this.globalData = null; 7806 this.maskElement = null; 7807 this.data = null; 7808 this.masksProperties = null; 7809}; 7810 7811/** 7812 * @file 7813 * Handles AE's layer parenting property. 7814 * 7815 */ 7816 7817function HierarchyElement() {} 7818 7819HierarchyElement.prototype = { 7820 /** 7821 * @function 7822 * Initializes hierarchy properties 7823 * 7824 */ 7825 initHierarchy: function () { 7826 // element's parent list 7827 this.hierarchy = []; 7828 // if element is parent of another layer _isParent will be true 7829 this._isParent = false; 7830 this.checkParenting(); 7831 }, 7832 /** 7833 * @function 7834 * Sets layer's hierarchy. 7835 * @param {array} hierarch 7836 * layer's parent list 7837 * 7838 */ 7839 setHierarchy: function (hierarchy) { 7840 this.hierarchy = hierarchy; 7841 }, 7842 /** 7843 * @function 7844 * Sets layer as parent. 7845 * 7846 */ 7847 setAsParent: function () { 7848 this._isParent = true; 7849 }, 7850 /** 7851 * @function 7852 * Searches layer's parenting chain 7853 * 7854 */ 7855 checkParenting: function () { 7856 if (this.data.parent !== undefined) { 7857 this.comp.buildElementParenting(this, this.data.parent, []); 7858 } 7859 }, 7860}; 7861 7862/** 7863 * @file 7864 * Handles element's layer frame update. 7865 * Checks layer in point and out point 7866 * 7867 */ 7868 7869function FrameElement() {} 7870 7871FrameElement.prototype = { 7872 /** 7873 * @function 7874 * Initializes frame related properties. 7875 * 7876 */ 7877 initFrame: function () { 7878 // set to true when inpoint is rendered 7879 this._isFirstFrame = false; 7880 // list of animated properties 7881 this.dynamicProperties = []; 7882 // If layer has been modified in current tick this will be true 7883 this._mdf = false; 7884 }, 7885 /** 7886 * @function 7887 * Calculates all dynamic values 7888 * 7889 * @param {number} num 7890 * current frame number in Layer's time 7891 * @param {boolean} isVisible 7892 * if layers is currently in range 7893 * 7894 */ 7895 prepareProperties: function (num, isVisible) { 7896 var i; 7897 var len = this.dynamicProperties.length; 7898 for (i = 0; i < len; i += 1) { 7899 if (isVisible || (this._isParent && this.dynamicProperties[i].propType === 'transform')) { 7900 this.dynamicProperties[i].getValue(); 7901 if (this.dynamicProperties[i]._mdf) { 7902 this.globalData._mdf = true; 7903 this._mdf = true; 7904 } 7905 } 7906 } 7907 }, 7908 addDynamicProperty: function (prop) { 7909 if (this.dynamicProperties.indexOf(prop) === -1) { 7910 this.dynamicProperties.push(prop); 7911 } 7912 }, 7913}; 7914 7915/* global TransformPropertyFactory, Matrix */ 7916 7917function TransformElement() {} 7918 7919TransformElement.prototype = { 7920 initTransform: function () { 7921 this.finalTransform = { 7922 mProp: this.data.ks ? TransformPropertyFactory.getTransformProperty(this, this.data.ks, this) : { o: 0 }, 7923 _matMdf: false, 7924 _opMdf: false, 7925 mat: new Matrix(), 7926 }; 7927 if (this.data.ao) { 7928 this.finalTransform.mProp.autoOriented = true; 7929 } 7930 7931 // TODO: check TYPE 11: Guided elements 7932 if (this.data.ty !== 11) { 7933 // this.createElements(); 7934 } 7935 }, 7936 renderTransform: function () { 7937 this.finalTransform._opMdf = this.finalTransform.mProp.o._mdf || this._isFirstFrame; 7938 this.finalTransform._matMdf = this.finalTransform.mProp._mdf || this._isFirstFrame; 7939 7940 if (this.hierarchy) { 7941 var mat; 7942 var finalMat = this.finalTransform.mat; 7943 var i = 0; 7944 var len = this.hierarchy.length; 7945 // Checking if any of the transformation matrices in the hierarchy chain has changed. 7946 if (!this.finalTransform._matMdf) { 7947 while (i < len) { 7948 if (this.hierarchy[i].finalTransform.mProp._mdf) { 7949 this.finalTransform._matMdf = true; 7950 break; 7951 } 7952 i += 1; 7953 } 7954 } 7955 7956 if (this.finalTransform._matMdf) { 7957 mat = this.finalTransform.mProp.v.props; 7958 finalMat.cloneFromProps(mat); 7959 for (i = 0; i < len; i += 1) { 7960 mat = this.hierarchy[i].finalTransform.mProp.v.props; 7961 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]); 7962 } 7963 } 7964 } 7965 }, 7966 globalToLocal: function (pt) { 7967 var transforms = []; 7968 transforms.push(this.finalTransform); 7969 var flag = true; 7970 var comp = this.comp; 7971 while (flag) { 7972 if (comp.finalTransform) { 7973 if (comp.data.hasMask) { 7974 transforms.splice(0, 0, comp.finalTransform); 7975 } 7976 comp = comp.comp; 7977 } else { 7978 flag = false; 7979 } 7980 } 7981 var i; 7982 var len = transforms.length; 7983 var ptNew; 7984 for (i = 0; i < len; i += 1) { 7985 ptNew = transforms[i].mat.applyToPointArray(0, 0, 0); 7986 // ptNew = transforms[i].mat.applyToPointArray(pt[0],pt[1],pt[2]); 7987 pt = [pt[0] - ptNew[0], pt[1] - ptNew[1], 0]; 7988 } 7989 return pt; 7990 }, 7991 mHelper: new Matrix(), 7992}; 7993 7994function RenderableElement() { 7995 7996} 7997 7998RenderableElement.prototype = { 7999 initRenderable: function () { 8000 // layer's visibility related to inpoint and outpoint. Rename isVisible to isInRange 8001 this.isInRange = false; 8002 // layer's display state 8003 this.hidden = false; 8004 // If layer's transparency equals 0, it can be hidden 8005 this.isTransparent = false; 8006 // list of animated components 8007 this.renderableComponents = []; 8008 }, 8009 addRenderableComponent: function (component) { 8010 if (this.renderableComponents.indexOf(component) === -1) { 8011 this.renderableComponents.push(component); 8012 } 8013 }, 8014 removeRenderableComponent: function (component) { 8015 if (this.renderableComponents.indexOf(component) !== -1) { 8016 this.renderableComponents.splice(this.renderableComponents.indexOf(component), 1); 8017 } 8018 }, 8019 prepareRenderableFrame: function (num) { 8020 this.checkLayerLimits(num); 8021 }, 8022 checkTransparency: function () { 8023 if (this.finalTransform.mProp.o.v <= 0) { 8024 if (!this.isTransparent && this.globalData.renderConfig.hideOnTransparent) { 8025 this.isTransparent = true; 8026 this.hide(); 8027 } 8028 } else if (this.isTransparent) { 8029 this.isTransparent = false; 8030 this.show(); 8031 } 8032 }, 8033 /** 8034 * @function 8035 * Initializes frame related properties. 8036 * 8037 * @param {number} num 8038 * current frame number in Layer's time 8039 * 8040 */ 8041 checkLayerLimits: function (num) { 8042 if (this.data.ip - this.data.st <= num && this.data.op - this.data.st > num) { 8043 if (this.isInRange !== true) { 8044 this.globalData._mdf = true; 8045 this._mdf = true; 8046 this.isInRange = true; 8047 this.show(); 8048 } 8049 } else if (this.isInRange !== false) { 8050 this.globalData._mdf = true; 8051 this.isInRange = false; 8052 this.hide(); 8053 } 8054 }, 8055 renderRenderable: function () { 8056 var i; 8057 var len = this.renderableComponents.length; 8058 for (i = 0; i < len; i += 1) { 8059 this.renderableComponents[i].renderFrame(this._isFirstFrame); 8060 } 8061 /* this.maskManager.renderFrame(this.finalTransform.mat); 8062 this.renderableEffectsManager.renderFrame(this._isFirstFrame); */ 8063 }, 8064 sourceRectAtTime: function () { 8065 return { 8066 top: 0, 8067 left: 0, 8068 width: 100, 8069 height: 100, 8070 }; 8071 }, 8072 getLayerSize: function () { 8073 if (this.data.ty === 5) { 8074 return { w: this.data.textData.width, h: this.data.textData.height }; 8075 } 8076 return { w: this.data.width, h: this.data.height }; 8077 }, 8078}; 8079 8080/* global extendPrototype, RenderableElement, createProxyFunction */ 8081 8082function RenderableDOMElement() {} 8083 8084(function () { 8085 var _prototype = { 8086 initElement: function (data, globalData, comp) { 8087 this.initFrame(); 8088 this.initBaseData(data, globalData, comp); 8089 this.initTransform(data, globalData, comp); 8090 this.initHierarchy(); 8091 this.initRenderable(); 8092 this.initRendererElement(); 8093 this.createContainerElements(); 8094 this.createRenderableComponents(); 8095 this.createContent(); 8096 this.hide(); 8097 }, 8098 hide: function () { 8099 if (!this.hidden && (!this.isInRange || this.isTransparent)) { 8100 var elem = this.baseElement || this.layerElement; 8101 elem.style.display = 'none'; 8102 this.hidden = true; 8103 } 8104 }, 8105 show: function () { 8106 if (this.isInRange && !this.isTransparent) { 8107 if (!this.data.hd) { 8108 var elem = this.baseElement || this.layerElement; 8109 elem.style.display = 'block'; 8110 } 8111 this.hidden = false; 8112 this._isFirstFrame = true; 8113 } 8114 }, 8115 renderFrame: function () { 8116 // If it is exported as hidden (data.hd === true) no need to render 8117 // If it is not visible no need to render 8118 if (this.data.hd || this.hidden) { 8119 return; 8120 } 8121 this.renderTransform(); 8122 this.renderRenderable(); 8123 this.renderElement(); 8124 this.renderInnerContent(); 8125 if (this._isFirstFrame) { 8126 this._isFirstFrame = false; 8127 } 8128 }, 8129 renderInnerContent: function () {}, 8130 prepareFrame: function (num) { 8131 this._mdf = false; 8132 this.prepareRenderableFrame(num); 8133 this.prepareProperties(num, this.isInRange); 8134 this.checkTransparency(); 8135 }, 8136 destroy: function () { 8137 this.innerElem = null; 8138 this.destroyBaseElement(); 8139 }, 8140 }; 8141 extendPrototype([RenderableElement, createProxyFunction(_prototype)], RenderableDOMElement); 8142}()); 8143 8144/* exported ProcessedElement */ 8145 8146function ProcessedElement(element, position) { 8147 this.elem = element; 8148 this.pos = position; 8149} 8150 8151/* global createNS */ 8152 8153function SVGStyleData(data, level) { 8154 this.data = data; 8155 this.type = data.ty; 8156 this.d = ''; 8157 this.lvl = level; 8158 this._mdf = false; 8159 this.closed = data.hd === true; 8160 this.pElem = createNS('path'); 8161 this.msElem = null; 8162} 8163 8164SVGStyleData.prototype.reset = function () { 8165 this.d = ''; 8166 this._mdf = false; 8167}; 8168 8169function SVGShapeData(transformers, level, shape) { 8170 this.caches = []; 8171 this.styles = []; 8172 this.transformers = transformers; 8173 this.lStr = ''; 8174 this.sh = shape; 8175 this.lvl = level; 8176 // TODO find if there are some cases where _isAnimated can be false. 8177 // For now, since shapes add up with other shapes. They have to be calculated every time. 8178 // One way of finding out is checking if all styles associated to this shape depend only of this shape 8179 this._isAnimated = !!shape.k; 8180 // TODO: commenting this for now since all shapes are animated 8181 var i = 0; 8182 var len = transformers.length; 8183 while (i < len) { 8184 if (transformers[i].mProps.dynamicProperties.length) { 8185 this._isAnimated = true; 8186 break; 8187 } 8188 i += 1; 8189 } 8190} 8191 8192SVGShapeData.prototype.setAsAnimated = function () { 8193 this._isAnimated = true; 8194}; 8195 8196/* exported SVGTransformData */ 8197 8198function SVGTransformData(mProps, op, container) { 8199 this.transform = { 8200 mProps: mProps, 8201 op: op, 8202 container: container, 8203 }; 8204 this.elements = []; 8205 this._isAnimated = this.transform.mProps.dynamicProperties.length || this.transform.op.effectsSequence.length; 8206} 8207 8208/* global DashProperty, PropertyFactory, extendPrototype, DynamicPropertyContainer */ 8209 8210function SVGStrokeStyleData(elem, data, styleOb) { 8211 this.initDynamicPropertyContainer(elem); 8212 this.getValue = this.iterateDynamicProperties; 8213 this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this); 8214 this.w = PropertyFactory.getProp(elem, data.w, 0, null, this); 8215 this.d = new DashProperty(elem, data.d || {}, 'svg', this); 8216 this.c = PropertyFactory.getProp(elem, data.c, 1, 255, this); 8217 this.style = styleOb; 8218 this._isAnimated = !!this._isAnimated; 8219} 8220 8221extendPrototype([DynamicPropertyContainer], SVGStrokeStyleData); 8222 8223/* global PropertyFactory, extendPrototype, DynamicPropertyContainer */ 8224 8225function SVGFillStyleData(elem, data, styleOb) { 8226 this.initDynamicPropertyContainer(elem); 8227 this.getValue = this.iterateDynamicProperties; 8228 this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this); 8229 this.c = PropertyFactory.getProp(elem, data.c, 1, 255, this); 8230 this.style = styleOb; 8231} 8232 8233extendPrototype([DynamicPropertyContainer], SVGFillStyleData); 8234 8235/* global PropertyFactory, degToRads, GradientProperty, createElementID, createNS, locationHref, 8236extendPrototype, DynamicPropertyContainer, lineCapEnum, lineJoinEnum */ 8237 8238function SVGGradientFillStyleData(elem, data, styleOb) { 8239 this.initDynamicPropertyContainer(elem); 8240 this.getValue = this.iterateDynamicProperties; 8241 this.initGradientData(elem, data, styleOb); 8242} 8243 8244SVGGradientFillStyleData.prototype.initGradientData = function (elem, data, styleOb) { 8245 this.o = PropertyFactory.getProp(elem, data.o, 0, 0.01, this); 8246 this.s = PropertyFactory.getProp(elem, data.s, 1, null, this); 8247 this.e = PropertyFactory.getProp(elem, data.e, 1, null, this); 8248 this.h = PropertyFactory.getProp(elem, data.h || { k: 0 }, 0, 0.01, this); 8249 this.a = PropertyFactory.getProp(elem, data.a || { k: 0 }, 0, degToRads, this); 8250 this.g = new GradientProperty(elem, data.g, this); 8251 this.style = styleOb; 8252 this.stops = []; 8253 this.setGradientData(styleOb.pElem, data); 8254 this.setGradientOpacity(data, styleOb); 8255 this._isAnimated = !!this._isAnimated; 8256}; 8257 8258SVGGradientFillStyleData.prototype.setGradientData = function (pathElement, data) { 8259 var gradientId = createElementID(); 8260 var gfill = createNS(data.t === 1 ? 'linearGradient' : 'radialGradient'); 8261 gfill.setAttribute('id', gradientId); 8262 gfill.setAttribute('spreadMethod', 'pad'); 8263 gfill.setAttribute('gradientUnits', 'userSpaceOnUse'); 8264 var stops = []; 8265 var stop; 8266 var j; 8267 var jLen; 8268 jLen = data.g.p * 4; 8269 for (j = 0; j < jLen; j += 4) { 8270 stop = createNS('stop'); 8271 gfill.appendChild(stop); 8272 stops.push(stop); 8273 } 8274 pathElement.setAttribute(data.ty === 'gf' ? 'fill' : 'stroke', 'url(' + locationHref + '#' + gradientId + ')'); 8275 this.gf = gfill; 8276 this.cst = stops; 8277}; 8278 8279SVGGradientFillStyleData.prototype.setGradientOpacity = function (data, styleOb) { 8280 if (this.g._hasOpacity && !this.g._collapsable) { 8281 var stop; 8282 var j; 8283 var jLen; 8284 var mask = createNS('mask'); 8285 var maskElement = createNS('path'); 8286 mask.appendChild(maskElement); 8287 var opacityId = createElementID(); 8288 var maskId = createElementID(); 8289 mask.setAttribute('id', maskId); 8290 var opFill = createNS(data.t === 1 ? 'linearGradient' : 'radialGradient'); 8291 opFill.setAttribute('id', opacityId); 8292 opFill.setAttribute('spreadMethod', 'pad'); 8293 opFill.setAttribute('gradientUnits', 'userSpaceOnUse'); 8294 jLen = data.g.k.k[0].s ? data.g.k.k[0].s.length : data.g.k.k.length; 8295 var stops = this.stops; 8296 for (j = data.g.p * 4; j < jLen; j += 2) { 8297 stop = createNS('stop'); 8298 stop.setAttribute('stop-color', 'rgb(255,255,255)'); 8299 opFill.appendChild(stop); 8300 stops.push(stop); 8301 } 8302 maskElement.setAttribute(data.ty === 'gf' ? 'fill' : 'stroke', 'url(' + locationHref + '#' + opacityId + ')'); 8303 if (data.ty === 'gs') { 8304 maskElement.setAttribute('stroke-linecap', lineCapEnum[data.lc || 2]); 8305 maskElement.setAttribute('stroke-linejoin', lineJoinEnum[data.lj || 2]); 8306 if (data.lj === 1) { 8307 maskElement.setAttribute('stroke-miterlimit', data.ml); 8308 } 8309 } 8310 this.of = opFill; 8311 this.ms = mask; 8312 this.ost = stops; 8313 this.maskId = maskId; 8314 styleOb.msElem = maskElement; 8315 } 8316}; 8317 8318extendPrototype([DynamicPropertyContainer], SVGGradientFillStyleData); 8319 8320/* global PropertyFactory, DashProperty, extendPrototype, SVGGradientFillStyleData, DynamicPropertyContainer */ 8321 8322function SVGGradientStrokeStyleData(elem, data, styleOb) { 8323 this.initDynamicPropertyContainer(elem); 8324 this.getValue = this.iterateDynamicProperties; 8325 this.w = PropertyFactory.getProp(elem, data.w, 0, null, this); 8326 this.d = new DashProperty(elem, data.d || {}, 'svg', this); 8327 this.initGradientData(elem, data, styleOb); 8328 this._isAnimated = !!this._isAnimated; 8329} 8330 8331extendPrototype([SVGGradientFillStyleData, DynamicPropertyContainer], SVGGradientStrokeStyleData); 8332 8333/* global createNS */ 8334/* exported ShapeGroupData */ 8335 8336function ShapeGroupData() { 8337 this.it = []; 8338 this.prevViewData = []; 8339 this.gr = createNS('g'); 8340} 8341 8342/* global Matrix, buildShapeString, bmFloor */ 8343/* exported SVGElementsRenderer */ 8344 8345var SVGElementsRenderer = (function () { 8346 var _identityMatrix = new Matrix(); 8347 var _matrixHelper = new Matrix(); 8348 8349 var ob = { 8350 createRenderFunction: createRenderFunction, 8351 }; 8352 8353 function createRenderFunction(data) { 8354 switch (data.ty) { 8355 case 'fl': 8356 return renderFill; 8357 case 'gf': 8358 return renderGradient; 8359 case 'gs': 8360 return renderGradientStroke; 8361 case 'st': 8362 return renderStroke; 8363 case 'sh': 8364 case 'el': 8365 case 'rc': 8366 case 'sr': 8367 return renderPath; 8368 case 'tr': 8369 return renderContentTransform; 8370 default: 8371 return null; 8372 } 8373 } 8374 8375 function renderContentTransform(styleData, itemData, isFirstFrame) { 8376 if (isFirstFrame || itemData.transform.op._mdf) { 8377 itemData.transform.container.setAttribute('opacity', itemData.transform.op.v); 8378 } 8379 if (isFirstFrame || itemData.transform.mProps._mdf) { 8380 itemData.transform.container.setAttribute('transform', itemData.transform.mProps.v.to2dCSS()); 8381 } 8382 } 8383 8384 function renderPath(styleData, itemData, isFirstFrame) { 8385 var j; 8386 var jLen; 8387 var pathStringTransformed; 8388 var redraw; 8389 var pathNodes; 8390 var l; 8391 var lLen = itemData.styles.length; 8392 var lvl = itemData.lvl; 8393 var paths; 8394 var mat; 8395 var props; 8396 var iterations; 8397 var k; 8398 for (l = 0; l < lLen; l += 1) { 8399 redraw = itemData.sh._mdf || isFirstFrame; 8400 if (itemData.styles[l].lvl < lvl) { 8401 mat = _matrixHelper.reset(); 8402 iterations = lvl - itemData.styles[l].lvl; 8403 k = itemData.transformers.length - 1; 8404 while (!redraw && iterations > 0) { 8405 redraw = itemData.transformers[k].mProps._mdf || redraw; 8406 iterations -= 1; 8407 k -= 1; 8408 } 8409 if (redraw) { 8410 iterations = lvl - itemData.styles[l].lvl; 8411 k = itemData.transformers.length - 1; 8412 while (iterations > 0) { 8413 props = itemData.transformers[k].mProps.v.props; 8414 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]); 8415 iterations -= 1; 8416 k -= 1; 8417 } 8418 } 8419 } else { 8420 mat = _identityMatrix; 8421 } 8422 paths = itemData.sh.paths; 8423 jLen = paths._length; 8424 if (redraw) { 8425 pathStringTransformed = ''; 8426 for (j = 0; j < jLen; j += 1) { 8427 pathNodes = paths.shapes[j]; 8428 if (pathNodes && pathNodes._length) { 8429 pathStringTransformed += buildShapeString(pathNodes, pathNodes._length, pathNodes.c, mat); 8430 } 8431 } 8432 itemData.caches[l] = pathStringTransformed; 8433 } else { 8434 pathStringTransformed = itemData.caches[l]; 8435 } 8436 itemData.styles[l].d += styleData.hd === true ? '' : pathStringTransformed; 8437 itemData.styles[l]._mdf = redraw || itemData.styles[l]._mdf; 8438 } 8439 } 8440 8441 function renderFill(styleData, itemData, isFirstFrame) { 8442 var styleElem = itemData.style; 8443 8444 if (itemData.c._mdf || isFirstFrame) { 8445 styleElem.pElem.setAttribute('fill', 'rgb(' + bmFloor(itemData.c.v[0]) + ',' + bmFloor(itemData.c.v[1]) + ',' + bmFloor(itemData.c.v[2]) + ')'); 8446 } 8447 if (itemData.o._mdf || isFirstFrame) { 8448 styleElem.pElem.setAttribute('fill-opacity', itemData.o.v); 8449 } 8450 } 8451 8452 function renderGradientStroke(styleData, itemData, isFirstFrame) { 8453 renderGradient(styleData, itemData, isFirstFrame); 8454 renderStroke(styleData, itemData, isFirstFrame); 8455 } 8456 8457 function renderGradient(styleData, itemData, isFirstFrame) { 8458 var gfill = itemData.gf; 8459 var hasOpacity = itemData.g._hasOpacity; 8460 var pt1 = itemData.s.v; 8461 var pt2 = itemData.e.v; 8462 8463 if (itemData.o._mdf || isFirstFrame) { 8464 var attr = styleData.ty === 'gf' ? 'fill-opacity' : 'stroke-opacity'; 8465 itemData.style.pElem.setAttribute(attr, itemData.o.v); 8466 } 8467 if (itemData.s._mdf || isFirstFrame) { 8468 var attr1 = styleData.t === 1 ? 'x1' : 'cx'; 8469 var attr2 = attr1 === 'x1' ? 'y1' : 'cy'; 8470 gfill.setAttribute(attr1, pt1[0]); 8471 gfill.setAttribute(attr2, pt1[1]); 8472 if (hasOpacity && !itemData.g._collapsable) { 8473 itemData.of.setAttribute(attr1, pt1[0]); 8474 itemData.of.setAttribute(attr2, pt1[1]); 8475 } 8476 } 8477 var stops; 8478 var i; 8479 var len; 8480 var stop; 8481 if (itemData.g._cmdf || isFirstFrame) { 8482 stops = itemData.cst; 8483 var cValues = itemData.g.c; 8484 len = stops.length; 8485 for (i = 0; i < len; i += 1) { 8486 stop = stops[i]; 8487 stop.setAttribute('offset', cValues[i * 4] + '%'); 8488 stop.setAttribute('stop-color', 'rgb(' + cValues[i * 4 + 1] + ',' + cValues[i * 4 + 2] + ',' + cValues[i * 4 + 3] + ')'); 8489 } 8490 } 8491 if (hasOpacity && (itemData.g._omdf || isFirstFrame)) { 8492 var oValues = itemData.g.o; 8493 if (itemData.g._collapsable) { 8494 stops = itemData.cst; 8495 } else { 8496 stops = itemData.ost; 8497 } 8498 len = stops.length; 8499 for (i = 0; i < len; i += 1) { 8500 stop = stops[i]; 8501 if (!itemData.g._collapsable) { 8502 stop.setAttribute('offset', oValues[i * 2] + '%'); 8503 } 8504 stop.setAttribute('stop-opacity', oValues[i * 2 + 1]); 8505 } 8506 } 8507 if (styleData.t === 1) { 8508 if (itemData.e._mdf || isFirstFrame) { 8509 gfill.setAttribute('x2', pt2[0]); 8510 gfill.setAttribute('y2', pt2[1]); 8511 if (hasOpacity && !itemData.g._collapsable) { 8512 itemData.of.setAttribute('x2', pt2[0]); 8513 itemData.of.setAttribute('y2', pt2[1]); 8514 } 8515 } 8516 } else { 8517 var rad; 8518 if (itemData.s._mdf || itemData.e._mdf || isFirstFrame) { 8519 rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2)); 8520 gfill.setAttribute('r', rad); 8521 if (hasOpacity && !itemData.g._collapsable) { 8522 itemData.of.setAttribute('r', rad); 8523 } 8524 } 8525 if (itemData.e._mdf || itemData.h._mdf || itemData.a._mdf || isFirstFrame) { 8526 if (!rad) { 8527 rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2)); 8528 } 8529 var ang = Math.atan2(pt2[1] - pt1[1], pt2[0] - pt1[0]); 8530 8531 var percent = itemData.h.v; 8532 if (percent >= 1) { 8533 percent = 0.99; 8534 } else if (percent <= -1) { 8535 percent = -0.99; 8536 } 8537 var dist = rad * percent; 8538 var x = Math.cos(ang + itemData.a.v) * dist + pt1[0]; 8539 var y = Math.sin(ang + itemData.a.v) * dist + pt1[1]; 8540 gfill.setAttribute('fx', x); 8541 gfill.setAttribute('fy', y); 8542 if (hasOpacity && !itemData.g._collapsable) { 8543 itemData.of.setAttribute('fx', x); 8544 itemData.of.setAttribute('fy', y); 8545 } 8546 } 8547 // gfill.setAttribute('fy','200'); 8548 } 8549 } 8550
vendor: 4,321 bytes, lines 8551-8694
8551 function renderStroke(styleData, itemData, isFirstFrame) { 8552 var styleElem = itemData.style; 8553 var d = itemData.d; 8554 if (d && (d._mdf || isFirstFrame) && d.dashStr) { 8555 styleElem.pElem.setAttribute('stroke-dasharray', d.dashStr); 8556 styleElem.pElem.setAttribute('stroke-dashoffset', d.dashoffset[0]); 8557 } 8558 if (itemData.c && (itemData.c._mdf || isFirstFrame)) { 8559 styleElem.pElem.setAttribute('stroke', 'rgb(' + bmFloor(itemData.c.v[0]) + ',' + bmFloor(itemData.c.v[1]) + ',' + bmFloor(itemData.c.v[2]) + ')'); 8560 } 8561 if (itemData.o._mdf || isFirstFrame) { 8562 styleElem.pElem.setAttribute('stroke-opacity', itemData.o.v); 8563 } 8564 if (itemData.w._mdf || isFirstFrame) { 8565 styleElem.pElem.setAttribute('stroke-width', itemData.w.v); 8566 if (styleElem.msElem) { 8567 styleElem.msElem.setAttribute('stroke-width', itemData.w.v); 8568 } 8569 } 8570 } 8571 8572 return ob; 8573}()); 8574 8575/* global Matrix */ 8576 8577function ShapeTransformManager() { 8578 this.sequences = {}; 8579 this.sequenceList = []; 8580 this.transform_key_count = 0; 8581} 8582 8583ShapeTransformManager.prototype = { 8584 addTransformSequence: function (transforms) { 8585 var i; 8586 var len = transforms.length; 8587 var key = '_'; 8588 for (i = 0; i < len; i += 1) { 8589 key += transforms[i].transform.key + '_'; 8590 } 8591 var sequence = this.sequences[key]; 8592 if (!sequence) { 8593 sequence = { 8594 transforms: [].concat(transforms), 8595 finalTransform: new Matrix(), 8596 _mdf: false, 8597 }; 8598 this.sequences[key] = sequence; 8599 this.sequenceList.push(sequence); 8600 } 8601 return sequence; 8602 }, 8603 processSequence: function (sequence, isFirstFrame) { 8604 var i = 0; 8605 var len = sequence.transforms.length; 8606 var _mdf = isFirstFrame; 8607 while (i < len && !isFirstFrame) { 8608 if (sequence.transforms[i].transform.mProps._mdf) { 8609 _mdf = true; 8610 break; 8611 } 8612 i += 1; 8613 } 8614 if (_mdf) { 8615 var props; 8616 sequence.finalTransform.reset(); 8617 for (i = len - 1; i >= 0; i -= 1) { 8618 props = sequence.transforms[i].transform.mProps.v.props; 8619 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]); 8620 } 8621 } 8622 sequence._mdf = _mdf; 8623 }, 8624 processSequences: function (isFirstFrame) { 8625 var i; 8626 var len = this.sequenceList.length; 8627 for (i = 0; i < len; i += 1) { 8628 this.processSequence(this.sequenceList[i], isFirstFrame); 8629 } 8630 }, 8631 getNewKey: function () { 8632 this.transform_key_count += 1; 8633 return '_' + this.transform_key_count; 8634 }, 8635}; 8636 8637/* global ShapePropertyFactory, SVGShapeData */ 8638 8639function CVShapeData(element, data, styles, transformsManager) { 8640 this.styledShapes = []; 8641 this.tr = [0, 0, 0, 0, 0, 0]; 8642 var ty = 4; 8643 if (data.ty === 'rc') { 8644 ty = 5; 8645 } else if (data.ty === 'el') { 8646 ty = 6; 8647 } else if (data.ty === 'sr') { 8648 ty = 7; 8649 } 8650 this.sh = ShapePropertyFactory.getShapeProp(element, data, ty, element); 8651 var i; 8652 var len = styles.length; 8653 var styledShape; 8654 for (i = 0; i < len; i += 1) { 8655 if (!styles[i].closed) { 8656 styledShape = { 8657 transforms: transformsManager.addTransformSequence(styles[i].transforms), 8658 trNodes: [], 8659 }; 8660 this.styledShapes.push(styledShape); 8661 styles[i].elements.push(styledShape); 8662 } 8663 } 8664} 8665 8666CVShapeData.prototype.setAsAnimated = SVGShapeData.prototype.setAsAnimated; 8667 8668/* global LayerExpressionInterface, EffectsExpressionInterface, CompExpressionInterface, ShapeExpressionInterface, 8669TextExpressionInterface, getBlendMode,createElementID, EffectsManager */ 8670 8671function BaseElement() { 8672} 8673 8674BaseElement.prototype = { 8675 checkMasks: function () { 8676 if (!this.data.hasMask) { 8677 return false; 8678 } 8679 var i = 0; 8680 var len = this.data.masksProperties.length; 8681 while (i < len) { 8682 if ((this.data.masksProperties[i].mode !== 'n' && this.data.masksProperties[i].cl !== false)) { 8683 return true; 8684 } 8685 i += 1; 8686 } 8687 return false; 8688 }, 8689 initExpressions: function () { 8690 this.layerInterface = LayerExpressionInterface(this); 8691 if (this.data.hasMask && this.maskManager) { 8692 this.layerInterface.registerMaskInterface(this.maskManager); 8693 } 8694 var effectsInterface = EffectsExpressionInterface.createEffe
vendor: 9,554 bytes, lines 8694-8961
8694ctsInterface(this, this.layerInterface); 8695 this.layerInterface.registerEffectsInterface(effectsInterface); 8696 8697 if (this.data.ty === 0 || this.data.xt) { 8698 this.compInterface = CompExpressionInterface(this); 8699 } else if (this.data.ty === 4) { 8700 this.layerInterface.shapeInterface = ShapeExpressionInterface(this.shapesData, this.itemsData, this.layerInterface); 8701 this.layerInterface.content = this.layerInterface.shapeInterface; 8702 } else if (this.data.ty === 5) { 8703 this.layerInterface.textInterface = TextExpressionInterface(this); 8704 this.layerInterface.text = this.layerInterface.textInterface; 8705 } 8706 }, 8707 setBlendMode: function () { 8708 var blendModeValue = getBlendMode(this.data.bm); 8709 var elem = this.baseElement || this.layerElement; 8710 8711 elem.style['mix-blend-mode'] = blendModeValue; 8712 }, 8713 initBaseData: function (data, globalData, comp) { 8714 this.globalData = globalData; 8715 this.comp = comp; 8716 this.data = data; 8717 this.layerId = createElementID(); 8718 8719 // Stretch factor for old animations missing this property. 8720 if (!this.data.sr) { 8721 this.data.sr = 1; 8722 } 8723 // effects manager 8724 this.effectsManager = new EffectsManager(this.data, this, this.dynamicProperties); 8725 }, 8726 getType: function () { 8727 return this.type; 8728 }, 8729 sourceRectAtTime: function () {}, 8730}; 8731 8732/* global extendPrototype, BaseElement, TransformElement, HierarchyElement, FrameElement */ 8733 8734function NullElement(data, globalData, comp) { 8735 this.initFrame(); 8736 this.initBaseData(data, globalData, comp); 8737 this.initFrame(); 8738 this.initTransform(data, globalData, comp); 8739 this.initHierarchy(); 8740} 8741 8742NullElement.prototype.prepareFrame = function (num) { 8743 this.prepareProperties(num, true); 8744}; 8745 8746NullElement.prototype.renderFrame = function () { 8747}; 8748 8749NullElement.prototype.getBaseElement = function () { 8750 return null; 8751}; 8752 8753NullElement.prototype.destroy = function () { 8754}; 8755 8756NullElement.prototype.sourceRectAtTime = function () { 8757}; 8758 8759NullElement.prototype.hide = function () { 8760}; 8761 8762extendPrototype([BaseElement, TransformElement, HierarchyElement, FrameElement], NullElement); 8763 8764/* global filtersFactory, featureSupport, filtersFactory, createElementID, createNS, MaskElement, SVGEffects, locationHref */ 8765 8766function SVGBaseElement() { 8767} 8768 8769SVGBaseElement.prototype = { 8770 initRendererElement: function () { 8771 this.layerElement = createNS('g'); 8772 }, 8773 createContainerElements: function () { 8774 this.matteElement = createNS('g'); 8775 this.transformedElement = this.layerElement; 8776 this.maskedElement = this.layerElement; 8777 this._sizeChanged = false; 8778 var layerElementParent = null; 8779 // If this layer acts as a mask for the following layer 8780 var filId; 8781 var fil; 8782 var gg; 8783 if (this.data.td) { 8784 if (this.data.td == 3 || this.data.td == 1) { // eslint-disable-line eqeqeq 8785 var masker = createNS('mask'); 8786 masker.setAttribute('id', this.layerId); 8787 masker.setAttribute('mask-type', this.data.td == 3 ? 'luminance' : 'alpha'); // eslint-disable-line eqeqeq 8788 masker.appendChild(this.layerElement); 8789 layerElementParent = masker; 8790 this.globalData.defs.appendChild(masker); 8791 // This is only for IE and Edge when mask if of type alpha 8792 if (!featureSupport.maskType && this.data.td == 1) { // eslint-disable-line eqeqeq 8793 masker.setAttribute('mask-type', 'luminance'); 8794 filId = createElementID(); 8795 fil = filtersFactory.createFilter(filId); 8796 this.globalData.defs.appendChild(fil); 8797 fil.appendChild(filtersFactory.createAlphaToLuminanceFilter()); 8798 gg = createNS('g'); 8799 gg.appendChild(this.layerElement); 8800 layerElementParent = gg; 8801 masker.appendChild(gg); 8802 gg.setAttribute('filter', 'url(' + locationHref + '#' + filId + ')'); 8803 } 8804 } else if (this.data.td == 2) { // eslint-disable-line eqeqeq 8805 var maskGroup = createNS('mask'); 8806 maskGroup.setAttribute('id', this.layerId); 8807 maskGroup.setAttribute('mask-type', 'alpha'); 8808 var maskGrouper = createNS('g'); 8809 maskGroup.appendChild(maskGrouper); 8810 filId = createElementID(); 8811 fil = filtersFactory.createFilter(filId); 8812 /// / 8813 8814 // This solution doesn't work on Android when meta tag with viewport attribute is set 8815 /* var feColorMatrix = createNS('feColorMatrix'); 8816 feColorMatrix.setAttribute('type', 'matrix'); 8817 feColorMatrix.setAttribute('color-interpolation-filters', 'sRGB'); 8818 feColorMatrix.setAttribute('values','1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 -1 1'); 8819 fil.appendChild(feColorMatrix); */ 8820 /// / 8821 var feCTr = createNS('feComponentTransfer'); 8822 feCTr.setAttribute('in', 'SourceGraphic'); 8823 fil.appendChild(feCTr); 8824 var feFunc = createNS('feFuncA'); 8825 feFunc.setAttribute('type', 'table'); 8826 feFunc.setAttribute('tableValues', '1.0 0.0'); 8827 feCTr.appendChild(feFunc); 8828 /// / 8829 this.globalData.defs.appendChild(fil); 8830 var alphaRect = createNS('rect'); 8831 alphaRect.setAttribute('width', this.comp.data.w); 8832 alphaRect.setAttribute('height', this.comp.data.h); 8833 alphaRect.setAttribute('x', '0'); 8834 alphaRect.setAttribute('y', '0'); 8835 alphaRect.setAttribute('fill', '#ffffff'); 8836 alphaRect.setAttribute('opacity', '0'); 8837 maskGrouper.setAttribute('filter', 'url(' + locationHref + '#' + filId + ')'); 8838 maskGrouper.appendChild(alphaRect); 8839 maskGrouper.appendChild(this.layerElement); 8840 layerElementParent = maskGrouper; 8841 if (!featureSupport.maskType) { 8842 maskGroup.setAttribute('mask-type', 'luminance'); 8843 fil.appendChild(filtersFactory.createAlphaToLuminanceFilter()); 8844 gg = createNS('g'); 8845 maskGrouper.appendChild(alphaRect); 8846 gg.appendChild(this.layerElement); 8847 layerElementParent = gg; 8848 maskGrouper.appendChild(gg); 8849 } 8850 this.globalData.defs.appendChild(maskGroup); 8851 } 8852 } else if (this.data.tt) { 8853 this.matteElement.appendChild(this.layerElement); 8854 layerElementParent = this.matteElement; 8855 this.baseElement = this.matteElement; 8856 } else { 8857 this.baseElement = this.layerElement; 8858 } 8859 if (this.data.ln) { 8860 this.layerElement.setAttribute('id', this.data.ln); 8861 } 8862 if (this.data.cl) { 8863 this.layerElement.setAttribute('class', this.data.cl); 8864 } 8865 // Clipping compositions to hide content that exceeds boundaries. If collapsed transformations is on, component should not be clipped 8866 if (this.data.ty === 0 && !this.data.hd) { 8867 var cp = createNS('clipPath'); 8868 var pt = createNS('path'); 8869 pt.setAttribute('d', 'M0,0 L' + this.data.w + ',0 L' + this.data.w + ',' + this.data.h + ' L0,' + this.data.h + 'z'); 8870 var clipId = createElementID(); 8871 cp.setAttribute('id', clipId); 8872 cp.appendChild(pt); 8873 this.globalData.defs.appendChild(cp); 8874 8875 if (this.checkMasks()) { 8876 var cpGroup = createNS('g'); 8877 cpGroup.setAttribute('clip-path', 'url(' + locationHref + '#' + clipId + ')'); 8878 cpGroup.appendChild(this.layerElement); 8879 this.transformedElement = cpGroup; 8880 if (layerElementParent) { 8881 layerElementParent.appendChild(this.transformedElement); 8882 } else { 8883 this.baseElement = this.transformedElement; 8884 } 8885 } else { 8886 this.layerElement.setAttribute('clip-path', 'url(' + locationHref + '#' + clipId + ')'); 8887 } 8888 } 8889 if (this.data.bm !== 0) { 8890 this.setBlendMode(); 8891 } 8892 }, 8893 renderElement: function () { 8894 if (this.finalTransform._matMdf) { 8895 this.transformedElement.setAttribute('transform', this.finalTransform.mat.to2dCSS()); 8896 } 8897 if (this.finalTransform._opMdf) { 8898 this.transformedElement.setAttribute('opacity', this.finalTransform.mProp.o.v); 8899 } 8900 }, 8901 destroyBaseElement: function () { 8902 this.layerElement = null; 8903 this.matteElement = null; 8904 this.maskManager.destroy(); 8905 }, 8906 getBaseElement: function () { 8907 if (this.data.hd) { 8908 return null; 8909 } 8910 return this.baseElement; 8911 }, 8912 createRenderableComponents: function () { 8913 this.maskManager = new MaskElement(this.data, this, this.globalData); 8914 this.renderableEffectsManager = new SVGEffects(this); 8915 }, 8916 setMatte: function (id) { 8917 if (!this.matteElement) { 8918 return; 8919 } 8920 this.matteElement.setAttribute('mask', 'url(' + locationHref + '#' + id + ')'); 8921 }, 8922}; 8923 8924/* global ProcessedElement */ 8925 8926function IShapeElement() { 8927} 8928 8929IShapeElement.prototype = { 8930 addShapeToModifiers: function (data) { 8931 var i; 8932 var len = this.shapeModifiers.length; 8933 for (i = 0; i < len; i += 1) { 8934 this.shapeModifiers[i].addShape(data); 8935 } 8936 }, 8937 isShapeInAnimatedModifiers: function (data) { 8938 var i = 0; 8939 var len = this.shapeModifiers.length; 8940 while (i < len) { 8941 if (this.shapeModifiers[i].isAnimatedWithShape(data)) { 8942 return true; 8943 } 8944 } 8945 return false; 8946 }, 8947 renderModifiers: function () { 8948 if (!this.shapeModifiers.length) { 8949 return; 8950 } 8951 var i; 8952 var len = this.shapes.length; 8953 for (i = 0; i < len; i += 1) { 8954 this.shapes[i].sh.reset(); 8955 } 8956 8957 len = this.shapeModifiers.length; 8958 var shouldBreakProcess; 8959 for (i = len - 1; i >= 0; i -= 1) { 8960 shouldBreakProcess = this.shapeModifiers[i].processShapes(this._isFirstFrame); 8961 // workaround to fix cases where a repeater resets the shape so the following processes get called twice
vendor: 4,662 bytes, lines 8962-9118
8962 // TODO: find a better solution for this 8963 if (shouldBreakProcess) { 8964 break; 8965 } 8966 } 8967 }, 8968 8969 searchProcessedElement: function (elem) { 8970 var elements = this.processedElements; 8971 var i = 0; 8972 var len = elements.length; 8973 while (i < len) { 8974 if (elements[i].elem === elem) { 8975 return elements[i].pos; 8976 } 8977 i += 1; 8978 } 8979 return 0; 8980 }, 8981 addProcessedElement: function (elem, pos) { 8982 var elements = this.processedElements; 8983 var i = elements.length; 8984 while (i) { 8985 i -= 1; 8986 if (elements[i].elem === elem) { 8987 elements[i].pos = pos; 8988 return; 8989 } 8990 } 8991 elements.push(new ProcessedElement(elem, pos)); 8992 }, 8993 prepareFrame: function (num) { 8994 this.prepareRenderableFrame(num); 8995 this.prepareProperties(num, this.isInRange); 8996 }, 8997}; 8998 8999/* global TextProperty, TextAnimatorProperty, buildShapeString, LetterProps */ 9000 9001function ITextElement() { 9002} 9003 9004ITextElement.prototype.initElement = function (data, globalData, comp) { 9005 this.lettersChangedFlag = true; 9006 this.initFrame(); 9007 this.initBaseData(data, globalData, comp); 9008 this.textProperty = new TextProperty(this, data.t, this.dynamicProperties); 9009 this.textAnimator = new TextAnimatorProperty(data.t, this.renderType, this); 9010 this.initTransform(data, globalData, comp); 9011 this.initHierarchy(); 9012 this.initRenderable(); 9013 this.initRendererElement(); 9014 this.createContainerElements(); 9015 this.createRenderableComponents(); 9016 this.createContent(); 9017 this.hide(); 9018 this.textAnimator.searchProperties(this.dynamicProperties); 9019}; 9020 9021ITextElement.prototype.prepareFrame = function (num) { 9022 this._mdf = false; 9023 this.prepareRenderableFrame(num); 9024 this.prepareProperties(num, this.isInRange); 9025 if (this.textProperty._mdf || this.textProperty._isFirstFrame) { 9026 this.buildNewText(); 9027 this.textProperty._isFirstFrame = false; 9028 this.textProperty._mdf = false; 9029 } 9030}; 9031 9032ITextElement.prototype.createPathShape = function (matrixHelper, shapes) { 9033 var j; 9034 var jLen = shapes.length; 9035 var pathNodes; 9036 var shapeStr = ''; 9037 for (j = 0; j < jLen; j += 1) { 9038 pathNodes = shapes[j].ks.k; 9039 shapeStr += buildShapeString(pathNodes, pathNodes.i.length, true, matrixHelper); 9040 } 9041 return shapeStr; 9042}; 9043 9044ITextElement.prototype.updateDocumentData = function (newData, index) { 9045 this.textProperty.updateDocumentData(newData, index); 9046}; 9047 9048ITextElement.prototype.canResizeFont = function (_canResize) { 9049 this.textProperty.canResizeFont(_canResize); 9050}; 9051 9052ITextElement.prototype.setMinimumFontSize = function (_fontSize) { 9053 this.textProperty.setMinimumFontSize(_fontSize); 9054}; 9055 9056ITextElement.prototype.applyTextPropertiesToMatrix = function (documentData, matrixHelper, lineNumber, xPos, yPos) { 9057 if (documentData.ps) { 9058 matrixHelper.translate(documentData.ps[0], documentData.ps[1] + documentData.ascent, 0); 9059 } 9060 matrixHelper.translate(0, -documentData.ls, 0); 9061 switch (documentData.j) { 9062 case 1: 9063 matrixHelper.translate(documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[lineNumber]), 0, 0); 9064 break; 9065 case 2: 9066 matrixHelper.translate(documentData.justifyOffset + (documentData.boxWidth - documentData.lineWidths[lineNumber]) / 2, 0, 0); 9067 break; 9068 default: 9069 break; 9070 } 9071 matrixHelper.translate(xPos, yPos, 0); 9072}; 9073 9074ITextElement.prototype.buildColor = function (colorData) { 9075 return 'rgb(' + Math.round(colorData[0] * 255) + ',' + Math.round(colorData[1] * 255) + ',' + Math.round(colorData[2] * 255) + ')'; 9076}; 9077 9078ITextElement.prototype.emptyProp = new LetterProps(); 9079 9080ITextElement.prototype.destroy = function () { 9081 9082}; 9083 9084/* global extendPrototype, BaseElement, TransformElement, HierarchyElement, FrameElement, RenderableDOMElement */ 9085 9086function ICompElement() {} 9087 9088extendPrototype([BaseElement, TransformElement, HierarchyElement, FrameElement, RenderableDOMElement], ICompElement); 9089 9090ICompElement.prototype.initElement = function (data, globalData, comp) { 9091 this.initFrame(); 9092 this.initBaseData(data, globalData, comp); 9093 this.initTransform(data, globalData, comp); 9094 this.initRenderable(); 9095 this.initHierarchy(); 9096 this.initRendererElement(); 9097 this.createContainerElements(); 9098 this.createRenderableComponents(); 9099 if (this.data.xt || !globalData.progressiveLoad) { 9100 this.buildAllItems(); 9101 } 9102 this.hide(); 9103}; 9104 9105/* ICompElement.prototype.hide = function(){ 9106 if(!this.hidden){ 9107 this.hideElement(); 9108 var i,len = this.elements.length; 9109 for( i = 0; i < len; i+=1 ){ 9110 if(this.elements[i]){ 9111 this.elements[i].hide(); 9112 } 9113 } 9114 } 9115}; */ 9116 9117ICompElement.prototype.prepareFrame = function (num) { 9118 this._mdf = false;
vendor: 24,044 bytes, lines 9119-9851
9119 this.prepareRenderableFrame(num); 9120 this.prepareProperties(num, this.isInRange); 9121 if (!this.isInRange && !this.data.xt) { 9122 return; 9123 } 9124 9125 if (!this.tm._placeholder) { 9126 var timeRemapped = this.tm.v; 9127 if (timeRemapped === this.data.op) { 9128 timeRemapped = this.data.op - 1; 9129 } 9130 this.renderedFrame = timeRemapped; 9131 } else { 9132 this.renderedFrame = num / this.data.sr; 9133 } 9134 var i; 9135 var len = this.elements.length; 9136 if (!this.completeLayers) { 9137 this.checkLayers(this.renderedFrame); 9138 } 9139 // This iteration needs to be backwards because of how expressions connect between each other 9140 for (i = len - 1; i >= 0; i -= 1) { 9141 if (this.completeLayers || this.elements[i]) { 9142 this.elements[i].prepareFrame(this.renderedFrame - this.layers[i].st); 9143 if (this.elements[i]._mdf) { 9144 this._mdf = true; 9145 } 9146 } 9147 } 9148}; 9149 9150ICompElement.prototype.renderInnerContent = function () { 9151 var i; 9152 var len = this.layers.length; 9153 for (i = 0; i < len; i += 1) { 9154 if (this.completeLayers || this.elements[i]) { 9155 this.elements[i].renderFrame(); 9156 } 9157 } 9158}; 9159 9160ICompElement.prototype.setElements = function (elems) { 9161 this.elements = elems; 9162}; 9163 9164ICompElement.prototype.getElements = function () { 9165 return this.elements; 9166}; 9167 9168ICompElement.prototype.destroyElements = function () { 9169 var i; 9170 var len = this.layers.length; 9171 for (i = 0; i < len; i += 1) { 9172 if (this.elements[i]) { 9173 this.elements[i].destroy(); 9174 } 9175 } 9176}; 9177 9178ICompElement.prototype.destroy = function () { 9179 this.destroyElements(); 9180 this.destroyBaseElement(); 9181}; 9182 9183/* global extendPrototype, BaseElement, TransformElement, SVGBaseElement, HierarchyElement, FrameElement, RenderableDOMElement, createNS */ 9184 9185function IImageElement(data, globalData, comp) { 9186 this.assetData = globalData.getAssetData(data.refId); 9187 this.initElement(data, globalData, comp); 9188 this.sourceRect = { 9189 top: 0, left: 0, width: this.assetData.w, height: this.assetData.h, 9190 }; 9191} 9192 9193extendPrototype([BaseElement, TransformElement, SVGBaseElement, HierarchyElement, FrameElement, RenderableDOMElement], IImageElement); 9194 9195IImageElement.prototype.createContent = function () { 9196 var assetPath = this.globalData.getAssetsPath(this.assetData); 9197 9198 this.innerElem = createNS('image'); 9199 this.innerElem.setAttribute('width', this.assetData.w + 'px'); 9200 this.innerElem.setAttribute('height', this.assetData.h + 'px'); 9201 this.innerElem.setAttribute('preserveAspectRatio', this.assetData.pr || this.globalData.renderConfig.imagePreserveAspectRatio); 9202 this.innerElem.setAttributeNS('http://www.w3.org/1999/xlink', 'href', assetPath); 9203 9204 this.layerElement.appendChild(this.innerElem); 9205}; 9206 9207IImageElement.prototype.sourceRectAtTime = function () { 9208 return this.sourceRect; 9209}; 9210 9211/* global extendPrototype, IImageElement, createNS */ 9212 9213function ISolidElement(data, globalData, comp) { 9214 this.initElement(data, globalData, comp); 9215} 9216extendPrototype([IImageElement], ISolidElement); 9217 9218ISolidElement.prototype.createContent = function () { 9219 var rect = createNS('rect'); 9220 /// /rect.style.width = this.data.sw; 9221 /// /rect.style.height = this.data.sh; 9222 /// /rect.style.fill = this.data.sc; 9223 rect.setAttribute('width', this.data.sw); 9224 rect.setAttribute('height', this.data.sh); 9225 rect.setAttribute('fill', this.data.sc); 9226 this.layerElement.appendChild(rect); 9227}; 9228 9229/* global PropertyFactory, extendPrototype, RenderableElement, BaseElement, FrameElement */ 9230 9231function AudioElement(data, globalData, comp) { 9232 this.initFrame(); 9233 this.initRenderable(); 9234 this.assetData = globalData.getAssetData(data.refId); 9235 this.initBaseData(data, globalData, comp); 9236 this._isPlaying = false; 9237 this._canPlay = false; 9238 var assetPath = this.globalData.getAssetsPath(this.assetData); 9239 this.audio = this.globalData.audioController.createAudio(assetPath); 9240 this._currentTime = 0; 9241 this.globalData.audioController.addAudio(this); 9242 this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : { _placeholder: true }; 9243} 9244 9245AudioElement.prototype.prepareFrame = function (num) { 9246 this.prepareRenderableFrame(num, true); 9247 this.prepareProperties(num, true); 9248 if (!this.tm._placeholder) { 9249 var timeRemapped = this.tm.v; 9250 this._currentTime = timeRemapped; 9251 } else { 9252 this._currentTime = num / this.data.sr; 9253 } 9254}; 9255 9256extendPrototype([RenderableElement, BaseElement, FrameElement], AudioElement); 9257 9258AudioElement.prototype.renderFrame = function () { 9259 if (this.isInRange && this._canPlay) { 9260 if (!this._isPlaying) { 9261 this.audio.play(); 9262 this.audio.seek(this._currentTime / this.globalData.frameRate); 9263 this._isPlaying = true; 9264 } else if (!this.audio.playing() 9265 || Math.abs(this._currentTime / this.globalData.frameRate - this.audio.seek()) > 0.1 9266 ) { 9267 this.audio.seek(this._currentTime / this.globalData.frameRate); 9268 } 9269 } 9270}; 9271 9272AudioElement.prototype.show = function () { 9273 // this.audio.play() 9274}; 9275 9276AudioElement.prototype.hide = function () { 9277 this.audio.pause(); 9278 this._isPlaying = false; 9279}; 9280 9281AudioElement.prototype.pause = function () { 9282 this.audio.pause(); 9283 this._isPlaying = false; 9284 this._canPlay = false; 9285}; 9286 9287AudioElement.prototype.resume = function () { 9288 this._canPlay = true; 9289}; 9290 9291AudioElement.prototype.setRate = function (rateValue) { 9292 this.audio.rate(rateValue); 9293}; 9294 9295AudioElement.prototype.volume = function (volumeValue) { 9296 this.audio.volume(volumeValue); 9297}; 9298 9299AudioElement.prototype.getBaseElement = function () { 9300 return null; 9301}; 9302 9303AudioElement.prototype.destroy = function () { 9304}; 9305 9306AudioElement.prototype.sourceRectAtTime = function () { 9307}; 9308 9309AudioElement.prototype.initExpressions = function () { 9310}; 9311 9312/* global extendPrototype, RenderableElement, BaseElement, FrameElement, FootageInterface */ 9313 9314function FootageElement(data, globalData, comp) { 9315 this.initFrame(); 9316 this.initRenderable(); 9317 this.assetData = globalData.getAssetData(data.refId); 9318 this.footageData = globalData.imageLoader.getAsset(this.assetData); 9319 this.initBaseData(data, globalData, comp); 9320} 9321 9322FootageElement.prototype.prepareFrame = function () { 9323}; 9324 9325extendPrototype([RenderableElement, BaseElement, FrameElement], FootageElement); 9326 9327FootageElement.prototype.getBaseElement = function () { 9328 return null; 9329}; 9330 9331FootageElement.prototype.renderFrame = function () { 9332}; 9333 9334FootageElement.prototype.destroy = function () { 9335}; 9336 9337FootageElement.prototype.initExpressions = function () { 9338 this.layerInterface = FootageInterface(this); 9339}; 9340 9341FootageElement.prototype.getFootageData = function () { 9342 return this.footageData; 9343}; 9344 9345/* global createSizedArray, PropertyFactory, extendPrototype, SVGRenderer, ICompElement, SVGBaseElement */ 9346 9347function SVGCompElement(data, globalData, comp) { 9348 this.layers = data.layers; 9349 this.supports3d = true; 9350 this.completeLayers = false; 9351 this.pendingElements = []; 9352 this.elements = this.layers ? createSizedArray(this.layers.length) : []; 9353 // this.layerElement = createNS('g'); 9354 this.initElement(data, globalData, comp); 9355 this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : { _placeholder: true }; 9356} 9357 9358extendPrototype([SVGRenderer, ICompElement, SVGBaseElement], SVGCompElement); 9359 9360/* global extendPrototype, BaseElement, TransformElement, SVGBaseElement, HierarchyElement, FrameElement, 9361RenderableDOMElement, ITextElement, createSizedArray, createNS */ 9362 9363function SVGTextLottieElement(data, globalData, comp) { 9364 this.textSpans = []; 9365 this.renderType = 'svg'; 9366 this.initElement(data, globalData, comp); 9367} 9368 9369extendPrototype([BaseElement, TransformElement, SVGBaseElement, HierarchyElement, FrameElement, RenderableDOMElement, ITextElement], SVGTextLottieElement); 9370 9371SVGTextLottieElement.prototype.createContent = function () { 9372 if (this.data.singleShape && !this.globalData.fontManager.chars) { 9373 this.textContainer = createNS('text'); 9374 } 9375}; 9376 9377SVGTextLottieElement.prototype.buildTextContents = function (textArray) { 9378 var i = 0; 9379 var len = textArray.length; 9380 var textContents = []; 9381 var currentTextContent = ''; 9382 while (i < len) { 9383 if (textArray[i] === String.fromCharCode(13) || textArray[i] === String.fromCharCode(3)) { 9384 textContents.push(currentTextContent); 9385 currentTextContent = ''; 9386 } else { 9387 currentTextContent += textArray[i]; 9388 } 9389 i += 1; 9390 } 9391 textContents.push(currentTextContent); 9392 return textContents; 9393}; 9394 9395SVGTextLottieElement.prototype.buildNewText = function () { 9396 var i; 9397 var len; 9398 9399 var documentData = this.textProperty.currentData; 9400 this.renderedLetters = createSizedArray(documentData ? documentData.l.length : 0); 9401 if (documentData.fc) { 9402 this.layerElement.setAttribute('fill', this.buildColor(documentData.fc)); 9403 } else { 9404 this.layerElement.setAttribute('fill', 'rgba(0,0,0,0)'); 9405 } 9406 if (documentData.sc) { 9407 this.layerElement.setAttribute('stroke', this.buildColor(documentData.sc)); 9408 this.layerElement.setAttribute('stroke-width', documentData.sw); 9409 } 9410 this.layerElement.setAttribute('font-size', documentData.finalSize); 9411 var fontData = this.globalData.fontManager.getFontByName(documentData.f); 9412 if (fontData.fClass) { 9413 this.layerElement.setAttribute('class', fontData.fClass); 9414 } else { 9415 this.layerElement.setAttribute('font-family', fontData.fFamily); 9416 var fWeight = documentData.fWeight; 9417 var fStyle = documentData.fStyle; 9418 this.layerElement.setAttribute('font-style', fStyle); 9419 this.layerElement.setAttribute('font-weight', fWeight); 9420 } 9421 this.layerElement.setAttribute('aria-label', documentData.t); 9422 9423 var letters = documentData.l || []; 9424 var usesGlyphs = !!this.globalData.fontManager.chars; 9425 len = letters.length; 9426 9427 var tSpan; 9428 var matrixHelper = this.mHelper; 9429 var shapes; 9430 var shapeStr = ''; 9431 var singleShape = this.data.singleShape; 9432 var xPos = 0; 9433 var yPos = 0; 9434 var firstLine = true; 9435 var trackingOffset = documentData.tr * 0.001 * documentData.finalSize; 9436 if (singleShape && !usesGlyphs && !documentData.sz) { 9437 var tElement = this.textContainer; 9438 var justify = 'start'; 9439 switch (documentData.j) { 9440 case 1: 9441 justify = 'end'; 9442 break; 9443 case 2: 9444 justify = 'middle'; 9445 break; 9446 default: 9447 justify = 'start'; 9448 break; 9449 } 9450 tElement.setAttribute('text-anchor', justify); 9451 tElement.setAttribute('letter-spacing', trackingOffset); 9452 var textContent = this.buildTextContents(documentData.finalText); 9453 len = textContent.length; 9454 yPos = documentData.ps ? documentData.ps[1] + documentData.ascent : 0; 9455 for (i = 0; i < len; i += 1) { 9456 tSpan = this.textSpans[i] || createNS('tspan'); 9457 tSpan.textContent = textContent[i]; 9458 tSpan.setAttribute('x', 0); 9459 tSpan.setAttribute('y', yPos); 9460 tSpan.style.display = 'inherit'; 9461 tElement.appendChild(tSpan); 9462 this.textSpans[i] = tSpan; 9463 yPos += documentData.finalLineHeight; 9464 } 9465 9466 this.layerElement.appendChild(tElement); 9467 } else { 9468 var cachedSpansLength = this.textSpans.length; 9469 var shapeData; 9470 var charData; 9471 for (i = 0; i < len; i += 1) { 9472 if (!usesGlyphs || !singleShape || i === 0) { 9473 tSpan = cachedSpansLength > i ? this.textSpans[i] : createNS(usesGlyphs ? 'path' : 'text'); 9474 if (cachedSpansLength <= i) { 9475 tSpan.setAttribute('stroke-linecap', 'butt'); 9476 tSpan.setAttribute('stroke-linejoin', 'round'); 9477 tSpan.setAttribute('stroke-miterlimit', '4'); 9478 this.textSpans[i] = tSpan; 9479 this.layerElement.appendChild(tSpan); 9480 } 9481 tSpan.style.display = 'inherit'; 9482 } 9483 9484 matrixHelper.reset(); 9485 matrixHelper.scale(documentData.finalSize / 100, documentData.finalSize / 100); 9486 if (singleShape) { 9487 if (letters[i].n) { 9488 xPos = -trackingOffset; 9489 yPos += documentData.yOffset; 9490 yPos += firstLine ? 1 : 0; 9491 firstLine = false; 9492 } 9493 this.applyTextPropertiesToMatrix(documentData, matrixHelper, letters[i].line, xPos, yPos); 9494 xPos += letters[i].l || 0; 9495 // xPos += letters[i].val === ' ' ? 0 : trackingOffset; 9496 xPos += trackingOffset; 9497 } 9498 if (usesGlyphs) { 9499 charData = this.globalData.fontManager.getCharData(documentData.finalText[i], fontData.fStyle, this.globalData.fontManager.getFontByName(documentData.f).fFamily); 9500 shapeData = (charData && charData.data) || {}; 9501 shapes = shapeData.shapes ? shapeData.shapes[0].it : []; 9502 if (!singleShape) { 9503 tSpan.setAttribute('d', this.createPathShape(matrixHelper, shapes)); 9504 } else { 9505 shapeStr += this.createPathShape(matrixHelper, shapes); 9506 } 9507 } else { 9508 if (singleShape) { 9509 tSpan.setAttribute('transform', 'translate(' + matrixHelper.props[12] + ',' + matrixHelper.props[13] + ')'); 9510 } 9511 tSpan.textContent = letters[i].val; 9512 tSpan.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:space', 'preserve'); 9513 } 9514 // 9515 } 9516 if (singleShape && tSpan) { 9517 tSpan.setAttribute('d', shapeStr); 9518 } 9519 } 9520 while (i < this.textSpans.length) { 9521 this.textSpans[i].style.display = 'none'; 9522 i += 1; 9523 } 9524 9525 this._sizeChanged = true; 9526}; 9527 9528SVGTextLottieElement.prototype.sourceRectAtTime = function () { 9529 this.prepareFrame(this.comp.renderedFrame - this.data.st); 9530 this.renderInnerContent(); 9531 if (this._sizeChanged) { 9532 this._sizeChanged = false; 9533 var textBox = this.layerElement.getBBox(); 9534 this.bbox = { 9535 top: textBox.y, 9536 left: textBox.x, 9537 width: textBox.width, 9538 height: textBox.height, 9539 }; 9540 } 9541 return this.bbox; 9542}; 9543 9544SVGTextLottieElement.prototype.renderInnerContent = function () { 9545 if (!this.data.singleShape) { 9546 this.textAnimator.getMeasures(this.textProperty.currentData, this.lettersChangedFlag); 9547 if (this.lettersChangedFlag || this.textAnimator.lettersChangedFlag) { 9548 this._sizeChanged = true; 9549 var i; 9550 var len; 9551 var renderedLetters = this.textAnimator.renderedLetters; 9552 9553 var letters = this.textProperty.currentData.l; 9554 9555 len = letters.length; 9556 var renderedLetter; 9557 var textSpan; 9558 for (i = 0; i < len; i += 1) { 9559 if (!letters[i].n) { 9560 renderedLetter = renderedLetters[i]; 9561 textSpan = this.textSpans[i]; 9562 if (renderedLetter._mdf.m) { 9563 textSpan.setAttribute('transform', renderedLetter.m); 9564 } 9565 if (renderedLetter._mdf.o) { 9566 textSpan.setAttribute('opacity', renderedLetter.o); 9567 } 9568 if (renderedLetter._mdf.sw) { 9569 textSpan.setAttribute('stroke-width', renderedLetter.sw); 9570 } 9571 if (renderedLetter._mdf.sc) { 9572 textSpan.setAttribute('stroke', renderedLetter.sc); 9573 } 9574 if (renderedLetter._mdf.fc) { 9575 textSpan.setAttribute('fill', renderedLetter.fc); 9576 } 9577 } 9578 } 9579 } 9580 } 9581}; 9582 9583/* global extendPrototype, BaseElement, TransformElement, SVGBaseElement, IShapeElement, HierarchyElement, 9584FrameElement, RenderableDOMElement, Matrix, SVGStyleData, SVGStrokeStyleData, SVGFillStyleData, 9585SVGGradientFillStyleData, SVGGradientStrokeStyleData, locationHref, getBlendMode, ShapeGroupData, 9586TransformPropertyFactory, SVGTransformData, ShapePropertyFactory, SVGShapeData, SVGElementsRenderer, ShapeModifiers, 9587lineCapEnum, lineJoinEnum */ 9588 9589function SVGShapeElement(data, globalData, comp) { 9590 // List of drawable elements 9591 this.shapes = []; 9592 // Full shape data 9593 this.shapesData = data.shapes; 9594 // List of styles that will be applied to shapes 9595 this.stylesList = []; 9596 // List of modifiers that will be applied to shapes 9597 this.shapeModifiers = []; 9598 // List of items in shape tree 9599 this.itemsData = []; 9600 // List of items in previous shape tree 9601 this.processedElements = []; 9602 // List of animated components 9603 this.animatedContents = []; 9604 this.initElement(data, globalData, comp); 9605 // Moving any property that doesn't get too much access after initialization because of v8 way of handling more than 10 properties. 9606 // List of elements that have been created 9607 this.prevViewData = []; 9608 // Moving any property that doesn't get too much access after initialization because of v8 way of handling more than 10 properties. 9609} 9610 9611extendPrototype([BaseElement, TransformElement, SVGBaseElement, IShapeElement, HierarchyElement, FrameElement, RenderableDOMElement], SVGShapeElement); 9612 9613SVGShapeElement.prototype.initSecondaryElement = function () { 9614}; 9615 9616SVGShapeElement.prototype.identityMatrix = new Matrix(); 9617 9618SVGShapeElement.prototype.buildExpressionInterface = function () {}; 9619 9620SVGShapeElement.prototype.createContent = function () { 9621 this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, this.layerElement, 0, [], true); 9622 this.filterUniqueShapes(); 9623}; 9624 9625/* 9626This method searches for multiple shapes that affect a single element and one of them is animated 9627*/ 9628SVGShapeElement.prototype.filterUniqueShapes = function () { 9629 var i; 9630 var len = this.shapes.length; 9631 var shape; 9632 var j; 9633 var jLen = this.stylesList.length; 9634 var style; 9635 var tempShapes = []; 9636 var areAnimated = false; 9637 for (j = 0; j < jLen; j += 1) { 9638 style = this.stylesList[j]; 9639 areAnimated = false; 9640 tempShapes.length = 0; 9641 for (i = 0; i < len; i += 1) { 9642 shape = this.shapes[i]; 9643 if (shape.styles.indexOf(style) !== -1) { 9644 tempShapes.push(shape); 9645 areAnimated = shape._isAnimated || areAnimated; 9646 } 9647 } 9648 if (tempShapes.length > 1 && areAnimated) { 9649 this.setShapesAsAnimated(tempShapes); 9650 } 9651 } 9652}; 9653 9654SVGShapeElement.prototype.setShapesAsAnimated = function (shapes) { 9655 var i; 9656 var len = shapes.length; 9657 for (i = 0; i < len; i += 1) { 9658 shapes[i].setAsAnimated(); 9659 } 9660}; 9661 9662SVGShapeElement.prototype.createStyleElement = function (data, level) { 9663 // TODO: prevent drawing of hidden styles 9664 var elementData; 9665 var styleOb = new SVGStyleData(data, level); 9666 9667 var pathElement = styleOb.pElem; 9668 if (data.ty === 'st') { 9669 elementData = new SVGStrokeStyleData(this, data, styleOb); 9670 } else if (data.ty === 'fl') { 9671 elementData = new SVGFillStyleData(this, data, styleOb); 9672 } else if (data.ty === 'gf' || data.ty === 'gs') { 9673 var GradientConstructor = data.ty === 'gf' ? SVGGradientFillStyleData : SVGGradientStrokeStyleData; 9674 elementData = new GradientConstructor(this, data, styleOb); 9675 this.globalData.defs.appendChild(elementData.gf); 9676 if (elementData.maskId) { 9677 this.globalData.defs.appendChild(elementData.ms); 9678 this.globalData.defs.appendChild(elementData.of); 9679 pathElement.setAttribute('mask', 'url(' + locationHref + '#' + elementData.maskId + ')'); 9680 } 9681 } 9682 9683 if (data.ty === 'st' || data.ty === 'gs') { 9684 pathElement.setAttribute('stroke-linecap', lineCapEnum[data.lc || 2]); 9685 pathElement.setAttribute('stroke-linejoin', lineJoinEnum[data.lj || 2]); 9686 pathElement.setAttribute('fill-opacity', '0'); 9687 if (data.lj === 1) { 9688 pathElement.setAttribute('stroke-miterlimit', data.ml); 9689 } 9690 } 9691 9692 if (data.r === 2) { 9693 pathElement.setAttribute('fill-rule', 'evenodd'); 9694 } 9695 9696 if (data.ln) { 9697 pathElement.setAttribute('id', data.ln); 9698 } 9699 if (data.cl) { 9700 pathElement.setAttribute('class', data.cl); 9701 } 9702 if (data.bm) { 9703 pathElement.style['mix-blend-mode'] = getBlendMode(data.bm); 9704 } 9705 this.stylesList.push(styleOb); 9706 this.addToAnimatedContents(data, elementData); 9707 return elementData; 9708}; 9709 9710SVGShapeElement.prototype.createGroupElement = function (data) { 9711 var elementData = new ShapeGroupData(); 9712 if (data.ln) { 9713 elementData.gr.setAttribute('id', data.ln); 9714 } 9715 if (data.cl) { 9716 elementData.gr.setAttribute('class', data.cl); 9717 } 9718 if (data.bm) { 9719 elementData.gr.style['mix-blend-mode'] = getBlendMode(data.bm); 9720 } 9721 return elementData; 9722}; 9723 9724SVGShapeElement.prototype.createTransformElement = function (data, container) { 9725 var transformProperty = TransformPropertyFactory.getTransformProperty(this, data, this); 9726 var elementData = new SVGTransformData(transformProperty, transformProperty.o, container); 9727 this.addToAnimatedContents(data, elementData); 9728 return elementData; 9729}; 9730 9731SVGShapeElement.prototype.createShapeElement = function (data, ownTransformers, level) { 9732 var ty = 4; 9733 if (data.ty === 'rc') { 9734 ty = 5; 9735 } else if (data.ty === 'el') { 9736 ty = 6; 9737 } else if (data.ty === 'sr') { 9738 ty = 7; 9739 } 9740 var shapeProperty = ShapePropertyFactory.getShapeProp(this, data, ty, this); 9741 var elementData = new SVGShapeData(ownTransformers, level, shapeProperty); 9742 this.shapes.push(elementData); 9743 this.addShapeToModifiers(elementData); 9744 this.addToAnimatedContents(data, elementData); 9745 return elementData; 9746}; 9747 9748SVGShapeElement.prototype.addToAnimatedContents = function (data, element) { 9749 var i = 0; 9750 var len = this.animatedContents.length; 9751 while (i < len) { 9752 if (this.animatedContents[i].element === element) { 9753 return; 9754 } 9755 i += 1; 9756 } 9757 this.animatedContents.push({ 9758 fn: SVGElementsRenderer.createRenderFunction(data), 9759 element: element, 9760 data: data, 9761 }); 9762}; 9763 9764SVGShapeElement.prototype.setElementStyles = function (elementData) { 9765 var arr = elementData.styles; 9766 var j; 9767 var jLen = this.stylesList.length; 9768 for (j = 0; j < jLen; j += 1) { 9769 if (!this.stylesList[j].closed) { 9770 arr.push(this.stylesList[j]); 9771 } 9772 } 9773}; 9774 9775SVGShapeElement.prototype.reloadShapes = function () { 9776 this._isFirstFrame = true; 9777 var i; 9778 var len = this.itemsData.length; 9779 for (i = 0; i < len; i += 1) { 9780 this.prevViewData[i] = this.itemsData[i]; 9781 } 9782 this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, this.layerElement, 0, [], true); 9783 this.filterUniqueShapes(); 9784 len = this.dynamicProperties.length; 9785 for (i = 0; i < len; i += 1) { 9786 this.dynamicProperties[i].getValue(); 9787 } 9788 this.renderModifiers(); 9789}; 9790 9791SVGShapeElement.prototype.searchShapes = function (arr, itemsData, prevViewData, container, level, transformers, render) { 9792 var ownTransformers = [].concat(transformers); 9793 var i; 9794 var len = arr.length - 1; 9795 var j; 9796 var jLen; 9797 var ownStyles = []; 9798 var ownModifiers = []; 9799 var currentTransform; 9800 var modifier; 9801 var processedPos; 9802 for (i = len; i >= 0; i -= 1) { 9803 processedPos = this.searchProcessedElement(arr[i]); 9804 if (!processedPos) { 9805 arr[i]._render = render; 9806 } else { 9807 itemsData[i] = prevViewData[processedPos - 1]; 9808 } 9809 if (arr[i].ty === 'fl' || arr[i].ty === 'st' || arr[i].ty === 'gf' || arr[i].ty === 'gs') { 9810 if (!processedPos) { 9811 itemsData[i] = this.createStyleElement(arr[i], level); 9812 } else { 9813 itemsData[i].style.closed = false; 9814 } 9815 if (arr[i]._render) { 9816 container.appendChild(itemsData[i].style.pElem); 9817 } 9818 ownStyles.push(itemsData[i].style); 9819 } else if (arr[i].ty === 'gr') { 9820 if (!processedPos) { 9821 itemsData[i] = this.createGroupElement(arr[i]); 9822 } else { 9823 jLen = itemsData[i].it.length; 9824 for (j = 0; j < jLen; j += 1) { 9825 itemsData[i].prevViewData[j] = itemsData[i].it[j]; 9826 } 9827 } 9828 this.searchShapes(arr[i].it, itemsData[i].it, itemsData[i].prevViewData, itemsData[i].gr, level + 1, ownTransformers, render); 9829 if (arr[i]._render) { 9830 container.appendChild(itemsData[i].gr); 9831 } 9832 } else if (arr[i].ty === 'tr') { 9833 if (!processedPos) { 9834 itemsData[i] = this.createTransformElement(arr[i], container); 9835 } 9836 currentTransform = itemsData[i].transform; 9837 ownTransformers.push(currentTransform); 9838 } else if (arr[i].ty === 'sh' || arr[i].ty === 'rc' || arr[i].ty === 'el' || arr[i].ty === 'sr') { 9839 if (!processedPos) { 9840 itemsData[i] = this.createShapeElement(arr[i], ownTransformers, level); 9841 } 9842 this.setElementStyles(itemsData[i]); 9843 } else if (arr[i].ty === 'tm' || arr[i].ty === 'rd' || arr[i].ty === 'ms' || arr[i].ty === 'pb') { 9844 if (!processedPos) { 9845 modifier = ShapeModifiers.getModifier(arr[i].ty); 9846 modifier.init(this, arr[i]); 9847 itemsData[i] = modifier; 9848 this.shapeModifiers.push(modifier); 9849 } else { 9850 modifier = itemsData[i]; 9851 modifier.closed = false;
vendor: 24,553 bytes, lines 9852-10431
9852 } 9853 ownModifiers.push(modifier); 9854 } else if (arr[i].ty === 'rp') { 9855 if (!processedPos) { 9856 modifier = ShapeModifiers.getModifier(arr[i].ty); 9857 itemsData[i] = modifier; 9858 modifier.init(this, arr, i, itemsData); 9859 this.shapeModifiers.push(modifier); 9860 render = false; 9861 } else { 9862 modifier = itemsData[i]; 9863 modifier.closed = true; 9864 } 9865 ownModifiers.push(modifier); 9866 } 9867 this.addProcessedElement(arr[i], i + 1); 9868 } 9869 len = ownStyles.length; 9870 for (i = 0; i < len; i += 1) { 9871 ownStyles[i].closed = true; 9872 } 9873 len = ownModifiers.length; 9874 for (i = 0; i < len; i += 1) { 9875 ownModifiers[i].closed = true; 9876 } 9877}; 9878 9879SVGShapeElement.prototype.renderInnerContent = function () { 9880 this.renderModifiers(); 9881 var i; 9882 var len = this.stylesList.length; 9883 for (i = 0; i < len; i += 1) { 9884 this.stylesList[i].reset(); 9885 } 9886 this.renderShape(); 9887 9888 for (i = 0; i < len; i += 1) { 9889 if (this.stylesList[i]._mdf || this._isFirstFrame) { 9890 if (this.stylesList[i].msElem) { 9891 this.stylesList[i].msElem.setAttribute('d', this.stylesList[i].d); 9892 // Adding M0 0 fixes same mask bug on all browsers 9893 this.stylesList[i].d = 'M0 0' + this.stylesList[i].d; 9894 } 9895 this.stylesList[i].pElem.setAttribute('d', this.stylesList[i].d || 'M0 0'); 9896 } 9897 } 9898}; 9899 9900SVGShapeElement.prototype.renderShape = function () { 9901 var i; 9902 var len = this.animatedContents.length; 9903 var animatedContent; 9904 for (i = 0; i < len; i += 1) { 9905 animatedContent = this.animatedContents[i]; 9906 if ((this._isFirstFrame || animatedContent.element._isAnimated) && animatedContent.data !== true) { 9907 animatedContent.fn(animatedContent.data, animatedContent.element, this._isFirstFrame); 9908 } 9909 } 9910}; 9911 9912SVGShapeElement.prototype.destroy = function () { 9913 this.destroyBaseElement(); 9914 this.shapesData = null; 9915 this.itemsData = null; 9916}; 9917 9918/* global createNS */ 9919 9920function SVGTintFilter(filter, filterManager) { 9921 this.filterManager = filterManager; 9922 var feColorMatrix = createNS('feColorMatrix'); 9923 feColorMatrix.setAttribute('type', 'matrix'); 9924 feColorMatrix.setAttribute('color-interpolation-filters', 'linearRGB'); 9925 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'); 9926 feColorMatrix.setAttribute('result', 'f1'); 9927 filter.appendChild(feColorMatrix); 9928 feColorMatrix = createNS('feColorMatrix'); 9929 feColorMatrix.setAttribute('type', 'matrix'); 9930 feColorMatrix.setAttribute('color-interpolation-filters', 'sRGB'); 9931 feColorMatrix.setAttribute('values', '1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0'); 9932 feColorMatrix.setAttribute('result', 'f2'); 9933 filter.appendChild(feColorMatrix); 9934 this.matrixFilter = feColorMatrix; 9935 if (filterManager.effectElements[2].p.v !== 100 || filterManager.effectElements[2].p.k) { 9936 var feMerge = createNS('feMerge'); 9937 filter.appendChild(feMerge); 9938 var feMergeNode; 9939 feMergeNode = createNS('feMergeNode'); 9940 feMergeNode.setAttribute('in', 'SourceGraphic'); 9941 feMerge.appendChild(feMergeNode); 9942 feMergeNode = createNS('feMergeNode'); 9943 feMergeNode.setAttribute('in', 'f2'); 9944 feMerge.appendChild(feMergeNode); 9945 } 9946} 9947 9948SVGTintFilter.prototype.renderFrame = function (forceRender) { 9949 if (forceRender || this.filterManager._mdf) { 9950 var colorBlack = this.filterManager.effectElements[0].p.v; 9951 var colorWhite = this.filterManager.effectElements[1].p.v; 9952 var opacity = this.filterManager.effectElements[2].p.v / 100; 9953 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'); 9954 } 9955}; 9956 9957/* global createNS */ 9958 9959function SVGFillFilter(filter, filterManager) { 9960 this.filterManager = filterManager; 9961 var feColorMatrix = createNS('feColorMatrix'); 9962 feColorMatrix.setAttribute('type', 'matrix'); 9963 feColorMatrix.setAttribute('color-interpolation-filters', 'sRGB'); 9964 feColorMatrix.setAttribute('values', '1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0'); 9965 filter.appendChild(feColorMatrix); 9966 this.matrixFilter = feColorMatrix; 9967} 9968SVGFillFilter.prototype.renderFrame = function (forceRender) { 9969 if (forceRender || this.filterManager._mdf) { 9970 var color = this.filterManager.effectElements[2].p.v; 9971 var opacity = this.filterManager.effectElements[6].p.v; 9972 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'); 9973 } 9974}; 9975 9976/* global createNS */ 9977 9978function SVGGaussianBlurEffect(filter, filterManager) { 9979 // Outset the filter region by 100% on all sides to accommodate blur expansion. 9980 filter.setAttribute('x', '-100%'); 9981 filter.setAttribute('y', '-100%'); 9982 filter.setAttribute('width', '300%'); 9983 filter.setAttribute('height', '300%'); 9984 9985 this.filterManager = filterManager; 9986 var feGaussianBlur = createNS('feGaussianBlur'); 9987 filter.appendChild(feGaussianBlur); 9988 this.feGaussianBlur = feGaussianBlur; 9989} 9990 9991SVGGaussianBlurEffect.prototype.renderFrame = function (forceRender) { 9992 if (forceRender || this.filterManager._mdf) { 9993 // Empirical value, matching AE's blur appearance. 9994 var kBlurrinessToSigma = 0.3; 9995 var sigma = this.filterManager.effectElements[0].p.v * kBlurrinessToSigma; 9996 9997 // Dimensions mapping: 9998 // 9999 // 1 -> horizontal & vertical 10000 // 2 -> horizontal only 10001 // 3 -> vertical only 10002 // 10003 var dimensions = this.filterManager.effectElements[1].p.v; 10004 var sigmaX = (dimensions == 3) ? 0 : sigma; // eslint-disable-line eqeqeq 10005 var sigmaY = (dimensions == 2) ? 0 : sigma; // eslint-disable-line eqeqeq 10006 10007 this.feGaussianBlur.setAttribute('stdDeviation', sigmaX + ' ' + sigmaY); 10008 10009 // Repeat edges mapping: 10010 // 10011 // 0 -> off -> duplicate 10012 // 1 -> on -> wrap 10013 var edgeMode = (this.filterManager.effectElements[2].p.v == 1) ? 'wrap' : 'duplicate'; // eslint-disable-line eqeqeq 10014 this.feGaussianBlur.setAttribute('edgeMode', edgeMode); 10015 } 10016}; 10017 10018/* global createNS, createElementID, locationHref, bmFloor */ 10019 10020function SVGStrokeEffect(elem, filterManager) { 10021 this.initialized = false; 10022 this.filterManager = filterManager; 10023 this.elem = elem; 10024 this.paths = []; 10025} 10026 10027SVGStrokeEffect.prototype.initialize = function () { 10028 var elemChildren = this.elem.layerElement.children || this.elem.layerElement.childNodes; 10029 var path; 10030 var groupPath; 10031 var i; 10032 var len; 10033 if (this.filterManager.effectElements[1].p.v === 1) { 10034 len = this.elem.maskManager.masksProperties.length; 10035 i = 0; 10036 } else { 10037 i = this.filterManager.effectElements[0].p.v - 1; 10038 len = i + 1; 10039 } 10040 groupPath = createNS('g'); 10041 groupPath.setAttribute('fill', 'none'); 10042 groupPath.setAttribute('stroke-linecap', 'round'); 10043 groupPath.setAttribute('stroke-dashoffset', 1); 10044 for (i; i < len; i += 1) { 10045 path = createNS('path'); 10046 groupPath.appendChild(path); 10047 this.paths.push({ p: path, m: i }); 10048 } 10049 if (this.filterManager.effectElements[10].p.v === 3) { 10050 var mask = createNS('mask'); 10051 var id = createElementID(); 10052 mask.setAttribute('id', id); 10053 mask.setAttribute('mask-type', 'alpha'); 10054 mask.appendChild(groupPath); 10055 this.elem.globalData.defs.appendChild(mask); 10056 var g = createNS('g'); 10057 g.setAttribute('mask', 'url(' + locationHref + '#' + id + ')'); 10058 while (elemChildren[0]) { 10059 g.appendChild(elemChildren[0]); 10060 } 10061 this.elem.layerElement.appendChild(g); 10062 this.masker = mask; 10063 groupPath.setAttribute('stroke', '#fff'); 10064 } else if (this.filterManager.effectElements[10].p.v === 1 || this.filterManager.effectElements[10].p.v === 2) { 10065 if (this.filterManager.effectElements[10].p.v === 2) { 10066 elemChildren = this.elem.layerElement.children || this.elem.layerElement.childNodes; 10067 while (elemChildren.length) { 10068 this.elem.layerElement.removeChild(elemChildren[0]); 10069 } 10070 } 10071 this.elem.layerElement.appendChild(groupPath); 10072 this.elem.layerElement.removeAttribute('mask'); 10073 groupPath.setAttribute('stroke', '#fff'); 10074 } 10075 this.initialized = true; 10076 this.pathMasker = groupPath; 10077}; 10078 10079SVGStrokeEffect.prototype.renderFrame = function (forceRender) { 10080 if (!this.initialized) { 10081 this.initialize(); 10082 } 10083 var i; 10084 var len = this.paths.length; 10085 var mask; 10086 var path; 10087 for (i = 0; i < len; i += 1) { 10088 if (this.paths[i].m !== -1) { 10089 mask = this.elem.maskManager.viewData[this.paths[i].m]; 10090 path = this.paths[i].p; 10091 if (forceRender || this.filterManager._mdf || mask.prop._mdf) { 10092 path.setAttribute('d', mask.lastPath); 10093 } 10094 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) { 10095 var dasharrayValue; 10096 if (this.filterManager.effectElements[7].p.v !== 0 || this.filterManager.effectElements[8].p.v !== 100) { 10097 var s = Math.min(this.filterManager.effectElements[7].p.v, this.filterManager.effectElements[8].p.v) * 0.01; 10098 var e = Math.max(this.filterManager.effectElements[7].p.v, this.filterManager.effectElements[8].p.v) * 0.01; 10099 var l = path.getTotalLength(); 10100 dasharrayValue = '0 0 0 ' + l * s + ' '; 10101 var lineLength = l * (e - s); 10102 var segment = 1 + this.filterManager.effectElements[4].p.v * 2 * this.filterManager.effectElements[9].p.v * 0.01; 10103 var units = Math.floor(lineLength / segment); 10104 var j; 10105 for (j = 0; j < units; j += 1) { 10106 dasharrayValue += '1 ' + this.filterManager.effectElements[4].p.v * 2 * this.filterManager.effectElements[9].p.v * 0.01 + ' '; 10107 } 10108 dasharrayValue += '0 ' + l * 10 + ' 0 0'; 10109 } else { 10110 dasharrayValue = '1 ' + this.filterManager.effectElements[4].p.v * 2 * this.filterManager.effectElements[9].p.v * 0.01; 10111 } 10112 path.setAttribute('stroke-dasharray', dasharrayValue); 10113 } 10114 } 10115 } 10116 if (forceRender || this.filterManager.effectElements[4].p._mdf) { 10117 this.pathMasker.setAttribute('stroke-width', this.filterManager.effectElements[4].p.v * 2); 10118 } 10119 10120 if (forceRender || this.filterManager.effectElements[6].p._mdf) { 10121 this.pathMasker.setAttribute('opacity', this.filterManager.effectElements[6].p.v); 10122 } 10123 if (this.filterManager.effectElements[10].p.v === 1 || this.filterManager.effectElements[10].p.v === 2) { 10124 if (forceRender || this.filterManager.effectElements[3].p._mdf) { 10125 var color = this.filterManager.effectElements[3].p.v; 10126 this.pathMasker.setAttribute('stroke', 'rgb(' + bmFloor(color[0] * 255) + ',' + bmFloor(color[1] * 255) + ',' + bmFloor(color[2] * 255) + ')'); 10127 } 10128 } 10129}; 10130 10131/* global createNS */ 10132 10133function SVGTritoneFilter(filter, filterManager) { 10134 this.filterManager = filterManager; 10135 var feColorMatrix = createNS('feColorMatrix'); 10136 feColorMatrix.setAttribute('type', 'matrix'); 10137 feColorMatrix.setAttribute('color-interpolation-filters', 'linearRGB'); 10138 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'); 10139 feColorMatrix.setAttribute('result', 'f1'); 10140 filter.appendChild(feColorMatrix); 10141 var feComponentTransfer = createNS('feComponentTransfer'); 10142 feComponentTransfer.setAttribute('color-interpolation-filters', 'sRGB'); 10143 filter.appendChild(feComponentTransfer); 10144 this.matrixFilter = feComponentTransfer; 10145 var feFuncR = createNS('feFuncR'); 10146 feFuncR.setAttribute('type', 'table'); 10147 feComponentTransfer.appendChild(feFuncR); 10148 this.feFuncR = feFuncR; 10149 var feFuncG = createNS('feFuncG'); 10150 feFuncG.setAttribute('type', 'table'); 10151 feComponentTransfer.appendChild(feFuncG); 10152 this.feFuncG = feFuncG; 10153 var feFuncB = createNS('feFuncB'); 10154 feFuncB.setAttribute('type', 'table'); 10155 feComponentTransfer.appendChild(feFuncB); 10156 this.feFuncB = feFuncB; 10157} 10158 10159SVGTritoneFilter.prototype.renderFrame = function (forceRender) { 10160 if (forceRender || this.filterManager._mdf) { 10161 var color1 = this.filterManager.effectElements[0].p.v; 10162 var color2 = this.filterManager.effectElements[1].p.v; 10163 var color3 = this.filterManager.effectElements[2].p.v; 10164 var tableR = color3[0] + ' ' + color2[0] + ' ' + color1[0]; 10165 var tableG = color3[1] + ' ' + color2[1] + ' ' + color1[1]; 10166 var tableB = color3[2] + ' ' + color2[2] + ' ' + color1[2]; 10167 this.feFuncR.setAttribute('tableValues', tableR); 10168 this.feFuncG.setAttribute('tableValues', tableG); 10169 this.feFuncB.setAttribute('tableValues', tableB); 10170 // var opacity = this.filterManager.effectElements[2].p.v/100; 10171 // 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'); 10172 } 10173}; 10174 10175/* global createNS */ 10176 10177function SVGProLevelsFilter(filter, filterManager) { 10178 this.filterManager = filterManager; 10179 var effectElements = this.filterManager.effectElements; 10180 var feComponentTransfer = createNS('feComponentTransfer'); 10181 10182 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) { 10183 this.feFuncR = this.createFeFunc('feFuncR', feComponentTransfer); 10184 } 10185 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) { 10186 this.feFuncG = this.createFeFunc('feFuncG', feComponentTransfer); 10187 } 10188 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) { 10189 this.feFuncB = this.createFeFunc('feFuncB', feComponentTransfer); 10190 } 10191 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) { 10192 this.feFuncA = this.createFeFunc('feFuncA', feComponentTransfer); 10193 } 10194 10195 if (this.feFuncR || this.feFuncG || this.feFuncB || this.feFuncA) { 10196 feComponentTransfer.setAttribute('color-interpolation-filters', 'sRGB'); 10197 filter.appendChild(feComponentTransfer); 10198 feComponentTransfer = createNS('feComponentTransfer'); 10199 } 10200 10201 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) { 10202 feComponentTransfer.setAttribute('color-interpolation-filters', 'sRGB'); 10203 filter.appendChild(feComponentTransfer); 10204 this.feFuncRComposed = this.createFeFunc('feFuncR', feComponentTransfer); 10205 this.feFuncGComposed = this.createFeFunc('feFuncG', feComponentTransfer); 10206 this.feFuncBComposed = this.createFeFunc('feFuncB', feComponentTransfer); 10207 } 10208} 10209 10210SVGProLevelsFilter.prototype.createFeFunc = function (type, feComponentTransfer) { 10211 var feFunc = createNS(type); 10212 feFunc.setAttribute('type', 'table'); 10213 feComponentTransfer.appendChild(feFunc); 10214 return feFunc; 10215}; 10216 10217SVGProLevelsFilter.prototype.getTableValue = function (inputBlack, inputWhite, gamma, outputBlack, outputWhite) { 10218 var cnt = 0; 10219 var segments = 256; 10220 var perc; 10221 var min = Math.min(inputBlack, inputWhite); 10222 var max = Math.max(inputBlack, inputWhite); 10223 var table = Array.call(null, { length: segments }); 10224 var colorValue; 10225 var pos = 0; 10226 var outputDelta = outputWhite - outputBlack; 10227 var inputDelta = inputWhite - inputBlack; 10228 while (cnt <= 256) { 10229 perc = cnt / 256; 10230 if (perc <= min) { 10231 colorValue = inputDelta < 0 ? outputWhite : outputBlack; 10232 } else if (perc >= max) { 10233 colorValue = inputDelta < 0 ? outputBlack : outputWhite; 10234 } else { 10235 colorValue = (outputBlack + outputDelta * Math.pow((perc - inputBlack) / inputDelta, 1 / gamma)); 10236 } 10237 table[pos] = colorValue; 10238 pos += 1; 10239 cnt += 256 / (segments - 1); 10240 } 10241 return table.join(' '); 10242}; 10243 10244SVGProLevelsFilter.prototype.renderFrame = function (forceRender) { 10245 if (forceRender || this.filterManager._mdf) { 10246 var val; 10247 var effectElements = this.filterManager.effectElements; 10248 if (this.feFuncRComposed && (forceRender || effectElements[3].p._mdf || effectElements[4].p._mdf || effectElements[5].p._mdf || effectElements[6].p._mdf || effectElements[7].p._mdf)) { 10249 val = this.getTableValue(effectElements[3].p.v, effectElements[4].p.v, effectElements[5].p.v, effectElements[6].p.v, effectElements[7].p.v); 10250 this.feFuncRComposed.setAttribute('tableValues', val); 10251 this.feFuncGComposed.setAttribute('tableValues', val); 10252 this.feFuncBComposed.setAttribute('tableValues', val); 10253 } 10254 10255 if (this.feFuncR && (forceRender || effectElements[10].p._mdf || effectElements[11].p._mdf || effectElements[12].p._mdf || effectElements[13].p._mdf || effectElements[14].p._mdf)) { 10256 val = this.getTableValue(effectElements[10].p.v, effectElements[11].p.v, effectElements[12].p.v, effectElements[13].p.v, effectElements[14].p.v); 10257 this.feFuncR.setAttribute('tableValues', val); 10258 } 10259 10260 if (this.feFuncG && (forceRender || effectElements[17].p._mdf || effectElements[18].p._mdf || effectElements[19].p._mdf || effectElements[20].p._mdf || effectElements[21].p._mdf)) { 10261 val = this.getTableValue(effectElements[17].p.v, effectElements[18].p.v, effectElements[19].p.v, effectElements[20].p.v, effectElements[21].p.v); 10262 this.feFuncG.setAttribute('tableValues', val); 10263 } 10264 10265 if (this.feFuncB && (forceRender || effectElements[24].p._mdf || effectElements[25].p._mdf || effectElements[26].p._mdf || effectElements[27].p._mdf || effectElements[28].p._mdf)) { 10266 val = this.getTableValue(effectElements[24].p.v, effectElements[25].p.v, effectElements[26].p.v, effectElements[27].p.v, effectElements[28].p.v); 10267 this.feFuncB.setAttribute('tableValues', val); 10268 } 10269 10270 if (this.feFuncA && (forceRender || effectElements[31].p._mdf || effectElements[32].p._mdf || effectElements[33].p._mdf || effectElements[34].p._mdf || effectElements[35].p._mdf)) { 10271 val = this.getTableValue(effectElements[31].p.v, effectElements[32].p.v, effectElements[33].p.v, effectElements[34].p.v, effectElements[35].p.v); 10272 this.feFuncA.setAttribute('tableValues', val); 10273 } 10274 } 10275}; 10276 10277/* global createNS, rgbToHex, degToRads */ 10278 10279function SVGDropShadowEffect(filter, filterManager) { 10280 var filterSize = filterManager.container.globalData.renderConfig.filterSize; 10281 filter.setAttribute('x', filterSize.x); 10282 filter.setAttribute('y', filterSize.y); 10283 filter.setAttribute('width', filterSize.width); 10284 filter.setAttribute('height', filterSize.height); 10285 this.filterManager = filterManager; 10286 10287 var feGaussianBlur = createNS('feGaussianBlur'); 10288 feGaussianBlur.setAttribute('in', 'SourceAlpha'); 10289 feGaussianBlur.setAttribute('result', 'drop_shadow_1'); 10290 feGaussianBlur.setAttribute('stdDeviation', '0'); 10291 this.feGaussianBlur = feGaussianBlur; 10292 filter.appendChild(feGaussianBlur); 10293 10294 var feOffset = createNS('feOffset'); 10295 feOffset.setAttribute('dx', '25'); 10296 feOffset.setAttribute('dy', '0'); 10297 feOffset.setAttribute('in', 'drop_shadow_1'); 10298 feOffset.setAttribute('result', 'drop_shadow_2'); 10299 this.feOffset = feOffset; 10300 filter.appendChild(feOffset); 10301 var feFlood = createNS('feFlood'); 10302 feFlood.setAttribute('flood-color', '#00ff00'); 10303 feFlood.setAttribute('flood-opacity', '1'); 10304 feFlood.setAttribute('result', 'drop_shadow_3'); 10305 this.feFlood = feFlood; 10306 filter.appendChild(feFlood); 10307 10308 var feComposite = createNS('feComposite'); 10309 feComposite.setAttribute('in', 'drop_shadow_3'); 10310 feComposite.setAttribute('in2', 'drop_shadow_2'); 10311 feComposite.setAttribute('operator', 'in'); 10312 feComposite.setAttribute('result', 'drop_shadow_4'); 10313 filter.appendChild(feComposite); 10314 10315 var feMerge = createNS('feMerge'); 10316 filter.appendChild(feMerge); 10317 var feMergeNode; 10318 feMergeNode = createNS('feMergeNode'); 10319 feMerge.appendChild(feMergeNode); 10320 feMergeNode = createNS('feMergeNode'); 10321 feMergeNode.setAttribute('in', 'SourceGraphic'); 10322 this.feMergeNode = feMergeNode; 10323 this.feMerge = feMerge; 10324 this.originalNodeAdded = false; 10325 feMerge.appendChild(feMergeNode); 10326} 10327 10328SVGDropShadowEffect.prototype.renderFrame = function (forceRender) { 10329 if (forceRender || this.filterManager._mdf) { 10330 if (forceRender || this.filterManager.effectElements[4].p._mdf) { 10331 this.feGaussianBlur.setAttribute('stdDeviation', this.filterManager.effectElements[4].p.v / 4); 10332 } 10333 if (forceRender || this.filterManager.effectElements[0].p._mdf) { 10334 var col = this.filterManager.effectElements[0].p.v; 10335 this.feFlood.setAttribute('flood-color', rgbToHex(Math.round(col[0] * 255), Math.round(col[1] * 255), Math.round(col[2] * 255))); 10336 } 10337 if (forceRender || this.filterManager.effectElements[1].p._mdf) { 10338 this.feFlood.setAttribute('flood-opacity', this.filterManager.effectElements[1].p.v / 255); 10339 } 10340 if (forceRender || this.filterManager.effectElements[2].p._mdf || this.filterManager.effectElements[3].p._mdf) { 10341 var distance = this.filterManager.effectElements[3].p.v; 10342 var angle = (this.filterManager.effectElements[2].p.v - 90) * degToRads; 10343 var x = distance * Math.cos(angle); 10344 var y = distance * Math.sin(angle); 10345 this.feOffset.setAttribute('dx', x); 10346 this.feOffset.setAttribute('dy', y); 10347 } 10348 /* if(forceRender || this.filterManager.effectElements[5].p._mdf){ 10349 if(this.filterManager.effectElements[5].p.v === 1 && this.originalNodeAdded) { 10350 this.feMerge.removeChild(this.feMergeNode); 10351 this.originalNodeAdded = false; 10352 } else if(this.filterManager.effectElements[5].p.v === 0 && !this.originalNodeAdded) { 10353 this.feMerge.appendChild(this.feMergeNode); 10354 this.originalNodeAdded = true; 10355 } 10356 } */ 10357 } 10358}; 10359 10360/* global createElementID, createNS */ 10361 10362var _svgMatteSymbols = []; 10363 10364function SVGMatte3Effect(filterElem, filterManager, elem) { 10365 this.initialized = false; 10366 this.filterManager = filterManager; 10367 this.filterElem = filterElem; 10368 this.elem = elem; 10369 elem.matteElement = createNS('g'); 10370 elem.matteElement.appendChild(elem.layerElement); 10371 elem.matteElement.appendChild(elem.transformedElement); 10372 elem.baseElement = elem.matteElement; 10373} 10374 10375SVGMatte3Effect.prototype.findSymbol = function (mask) { 10376 var i = 0; 10377 var len = _svgMatteSymbols.length; 10378 while (i < len) { 10379 if (_svgMatteSymbols[i] === mask) { 10380 return _svgMatteSymbols[i]; 10381 } 10382 i += 1; 10383 } 10384 return null; 10385}; 10386 10387SVGMatte3Effect.prototype.replaceInParent = function (mask, symbolId) { 10388 var parentNode = mask.layerElement.parentNode; 10389 if (!parentNode) { 10390 return; 10391 } 10392 var children = parentNode.children; 10393 var i = 0; 10394 var len = children.length; 10395 while (i < len) { 10396 if (children[i] === mask.layerElement) { 10397 break; 10398 } 10399 i += 1; 10400 } 10401 var nextChild; 10402 if (i <= len - 2) { 10403 nextChild = children[i + 1]; 10404 } 10405 var useElem = createNS('use'); 10406 useElem.setAttribute('href', '#' + symbolId); 10407 if (nextChild) { 10408 parentNode.insertBefore(useElem, nextChild); 10409 } else { 10410 parentNode.appendChild(useElem); 10411 } 10412}; 10413 10414SVGMatte3Effect.prototype.setElementAsMask = function (elem, mask) { 10415 if (!this.findSymbol(mask)) { 10416 var symbolId = createElementID(); 10417 var masker = createNS('mask'); 10418 masker.setAttribute('id', mask.layerId); 10419 masker.setAttribute('mask-type', 'alpha'); 10420 _svgMatteSymbols.push(mask); 10421 var defs = elem.globalData.defs; 10422 defs.appendChild(masker); 10423 var symbol = createNS('symbol'); 10424 symbol.setAttribute('id', symbolId); 10425 this.replaceInParent(mask, symbolId); 10426 symbol.appendChild(mask.layerElement); 10427 defs.appendChild(symbol); 10428 var useElem = createNS('use'); 10429 useElem.setAttribute('href', '#' + symbolId); 10430 masker.appendChild(useElem); 10431 mask.data.hd = false;
10432 mask.show(); 10433 } 10434 elem.setMatte(mask.layerId); 10435}; 10436 10437SVGMatte3Effect.prototype.initialize = function () { 10438 var ind = this.filterManager.effectElements[0].p.v; 10439 var elements = this.elem.comp.elements; 10440 var i = 0; 10441 var len = elements.length; 10442 while (i < len) { 10443 if (elements[i] && elements[i].data.ind === ind) { 10444 this.setElementAsMask(this.elem, elements[i]); 10445 } 10446 i += 1; 10447 } 10448 this.initialized = true; 10449}; 10450 10451SVGMatte3Effect.prototype.renderFrame = function () { 10452 if (!this.initialized) { 10453 this.initialize(); 10454 } 10455}; 10456 10457/* global createElementID, filtersFactory, SVGTintFilter, SVGFillFilter, SVGStrokeEffect, SVGTritoneFilter, 10458SVGProLevelsFilter, SVGDropShadowEffect, SVGMatte3Effect, SVGGaussianBlurEffect, locationHref */ 10459 10460function SVGEffects(elem) { 10461 var i; 10462 var len = elem.data.ef ? elem.data.ef.length : 0; 10463 var filId = createElementID(); 10464 var fil = filtersFactory.createFilter(filId, true); 10465 var count = 0; 10466 this.filters = []; 10467 var filterManager; 10468 for (i = 0; i < len; i += 1) { 10469 filterManager = null; 10470 if (elem.data.ef[i].ty === 20) { 10471 count += 1; 10472 filterManager = new SVGTintFilter(fil, elem.effectsManager.effectElements[i]); 10473 } else if (elem.data.ef[i].ty === 21) { 10474 count += 1; 10475 filterManager = new SVGFillFilter(fil, elem.effectsManager.effectElements[i]); 10476 } else if (elem.data.ef[i].ty === 22) { 10477 filterManager = new SVGStrokeEffect(elem, elem.effectsManager.effectElements[i]); 10478 } else if (elem.data.ef[i].ty === 23) { 10479 count += 1; 10480 filterManager = new SVGTritoneFilter(fil, elem.effectsManager.effectElements[i]); 10481 } else if (elem.data.ef[i].ty === 24) { 10482 count += 1; 10483 filterManager = new SVGProLevelsFilter(fil, elem.effectsManager.effectElements[i]); 10484 } else if (elem.data.ef[i].ty === 25) { 10485 count += 1; 10486 filterManager = new SVGDropShadowEffect(fil, elem.effectsManager.effectElements[i]); 10487 } else if (elem.data.ef[i].ty === 28) { 10488 // count += 1; 10489 filterManager = new SVGMatte3Effect(fil, elem.effectsManager.effectElements[i], elem); 10490 } else if (elem.data.ef[i].ty === 29) { 10491 count += 1; 10492 filterManager = new SVGGaussianBlurEffect(fil, elem.effectsManager.effectElements[i]); 10493 } 10494 if (filterManager) { 10495 this.filters.push(filterManager); 10496 } 10497 } 10498 if (count) { 10499 elem.globalData.defs.appendChild(fil); 10500 elem.layerElement.setAttribute('filter', 'url(' + locationHref + '#' + filId + ')'); 10501 } 10502 if (this.filters.length) { 10503 elem.addRenderableComponent(this); 10504 } 10505} 10506 10507SVGEffects.prototype.renderFrame = function (_isFirstFrame) { 10508 var i; 10509 var len = this.filters.length; 10510 for (i = 0; i < len; i += 1) { 10511 this.filters[i].renderFrame(_isFirstFrame); 10512 } 10513}; 10514 10515/* global Matrix, createTypedArray */ 10516 10517function CVContextData() { 10518 this.saved = []; 10519 this.cArrPos = 0; 10520 this.cTr = new Matrix(); 10521 this.cO = 1; 10522 var i; 10523 var len = 15; 10524 this.savedOp = createTypedArray('float32', len); 10525 for (i = 0; i < len; i += 1) { 10526 this.saved[i] = createTypedArray('float32', 16); 10527 } 10528 this._length = len; 10529} 10530 10531CVContextData.prototype.duplicate = function () { 10532 var newLength = this._length * 2; 10533 var currentSavedOp = this.savedOp; 10534 this.savedOp = createTypedArray('float32', newLength); 10535 this.savedOp.set(currentSavedOp); 10536 var i = 0; 10537 for (i = this._length; i < newLength; i += 1) { 10538 this.saved[i] = createTypedArray('float32', 16); 10539 } 10540 this._length = newLength; 10541}; 10542 10543CVContextData.prototype.reset = function () { 10544 this.cArrPos = 0; 10545 this.cTr.reset(); 10546 this.cO = 1; 10547}; 10548 10549/* global CVEffects, getBlendMode, CVMaskElement, Matrix */ 10550 10551function CVBaseElement() { 10552} 10553 10554CVBaseElement.prototype = { 10555 createElements: function () {}, 10556 initRendererElement: function () {}, 10557 createContainerElements: function () { 10558 this.canvasContext = this.globalData.canvasContext; 10559 this.renderableEffectsManager = new CVEffects(this); 10560 }, 10561 createContent: function () {}, 10562 setBlendMode: function () { 10563 var globalData = this.globalData; 10564 if (globalData.blendMode !== this.data.bm) { 10565 globalData.blendMode = this.data.bm;
vendor: 17,536 bytes, lines 10566-11087
10566 var blendModeValue = getBlendMode(this.data.bm); 10567 globalData.canvasContext.globalCompositeOperation = blendModeValue; 10568 } 10569 }, 10570 createRenderableComponents: function () { 10571 this.maskManager = new CVMaskElement(this.data, this); 10572 }, 10573 hideElement: function () { 10574 if (!this.hidden && (!this.isInRange || this.isTransparent)) { 10575 this.hidden = true; 10576 } 10577 }, 10578 showElement: function () { 10579 if (this.isInRange && !this.isTransparent) { 10580 this.hidden = false; 10581 this._isFirstFrame = true; 10582 this.maskManager._isFirstFrame = true; 10583 } 10584 }, 10585 renderFrame: function () { 10586 if (this.hidden || this.data.hd) { 10587 return; 10588 } 10589 this.renderTransform(); 10590 this.renderRenderable(); 10591 this.setBlendMode(); 10592 var forceRealStack = this.data.ty === 0; 10593 this.globalData.renderer.save(forceRealStack); 10594 this.globalData.renderer.ctxTransform(this.finalTransform.mat.props); 10595 this.globalData.renderer.ctxOpacity(this.finalTransform.mProp.o.v); 10596 this.renderInnerContent(); 10597 this.globalData.renderer.restore(forceRealStack); 10598 if (this.maskManager.hasMasks) { 10599 this.globalData.renderer.restore(true); 10600 } 10601 if (this._isFirstFrame) { 10602 this._isFirstFrame = false; 10603 } 10604 }, 10605 destroy: function () { 10606 this.canvasContext = null; 10607 this.data = null; 10608 this.globalData = null; 10609 this.maskManager.destroy(); 10610 }, 10611 mHelper: new Matrix(), 10612}; 10613CVBaseElement.prototype.hide = CVBaseElement.prototype.hideElement; 10614CVBaseElement.prototype.show = CVBaseElement.prototype.showElement; 10615 10616/* global extendPrototype, BaseElement, TransformElement, CVBaseElement,HierarchyElement, FrameElement, 10617RenderableElement, SVGShapeElement, IImageElement, createTag */ 10618 10619function CVImageElement(data, globalData, comp) { 10620 this.assetData = globalData.getAssetData(data.refId); 10621 this.img = globalData.imageLoader.getAsset(this.assetData); 10622 this.initElement(data, globalData, comp); 10623} 10624extendPrototype([BaseElement, TransformElement, CVBaseElement, HierarchyElement, FrameElement, RenderableElement], CVImageElement); 10625 10626CVImageElement.prototype.initElement = SVGShapeElement.prototype.initElement; 10627CVImageElement.prototype.prepareFrame = IImageElement.prototype.prepareFrame; 10628 10629CVImageElement.prototype.createContent = function () { 10630 if (this.img.width && (this.assetData.w !== this.img.width || this.assetData.h !== this.img.height)) { 10631 var canvas = createTag('canvas'); 10632 canvas.width = this.assetData.w; 10633 canvas.height = this.assetData.h; 10634 var ctx = canvas.getContext('2d'); 10635 10636 var imgW = this.img.width; 10637 var imgH = this.img.height; 10638 var imgRel = imgW / imgH; 10639 var canvasRel = this.assetData.w / this.assetData.h; 10640 var widthCrop; 10641 var heightCrop; 10642 var par = this.assetData.pr || this.globalData.renderConfig.imagePreserveAspectRatio; 10643 if ((imgRel > canvasRel && par === 'xMidYMid slice') || (imgRel < canvasRel && par !== 'xMidYMid slice')) { 10644 heightCrop = imgH; 10645 widthCrop = heightCrop * canvasRel; 10646 } else { 10647 widthCrop = imgW; 10648 heightCrop = widthCrop / canvasRel; 10649 } 10650 ctx.drawImage(this.img, (imgW - widthCrop) / 2, (imgH - heightCrop) / 2, widthCrop, heightCrop, 0, 0, this.assetData.w, this.assetData.h); 10651 this.img = canvas; 10652 } 10653}; 10654 10655CVImageElement.prototype.renderInnerContent = function () { 10656 this.canvasContext.drawImage(this.img, 0, 0); 10657}; 10658 10659CVImageElement.prototype.destroy = function () { 10660 this.img = null; 10661}; 10662 10663/* global createSizedArray, PropertyFactory, extendPrototype, CanvasRenderer, ICompElement, CVBaseElement */ 10664 10665function CVCompElement(data, globalData, comp) { 10666 this.completeLayers = false; 10667 this.layers = data.layers; 10668 this.pendingElements = []; 10669 this.elements = createSizedArray(this.layers.length); 10670 this.initElement(data, globalData, comp); 10671 this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : { _placeholder: true }; 10672} 10673 10674extendPrototype([CanvasRenderer, ICompElement, CVBaseElement], CVCompElement); 10675 10676CVCompElement.prototype.renderInnerContent = function () { 10677 var ctx = this.canvasContext; 10678 ctx.beginPath(); 10679 ctx.moveTo(0, 0); 10680 ctx.lineTo(this.data.w, 0); 10681 ctx.lineTo(this.data.w, this.data.h); 10682 ctx.lineTo(0, this.data.h); 10683 ctx.lineTo(0, 0); 10684 ctx.clip(); 10685 var i; 10686 var len = this.layers.length; 10687 for (i = len - 1; i >= 0; i -= 1) { 10688 if (this.completeLayers || this.elements[i]) { 10689 this.elements[i].renderFrame(); 10690 } 10691 } 10692}; 10693 10694CVCompElement.prototype.destroy = function () { 10695 var i; 10696 var len = this.layers.length; 10697 for (i = len - 1; i >= 0; i -= 1) { 10698 if (this.elements[i]) { 10699 this.elements[i].destroy(); 10700 } 10701 } 10702 this.layers = null; 10703 this.elements = null; 10704}; 10705 10706/* global createSizedArray, ShapePropertyFactory, MaskElement */ 10707 10708function CVMaskElement(data, element) { 10709 this.data = data; 10710 this.element = element; 10711 this.masksProperties = this.data.masksProperties || []; 10712 this.viewData = createSizedArray(this.masksProperties.length); 10713 var i; 10714 var len = this.masksProperties.length; 10715 var hasMasks = false; 10716 for (i = 0; i < len; i += 1) { 10717 if (this.masksProperties[i].mode !== 'n') { 10718 hasMasks = true; 10719 } 10720 this.viewData[i] = ShapePropertyFactory.getShapeProp(this.element, this.masksProperties[i], 3); 10721 } 10722 this.hasMasks = hasMasks; 10723 if (hasMasks) { 10724 this.element.addRenderableComponent(this); 10725 } 10726} 10727 10728CVMaskElement.prototype.renderFrame = function () { 10729 if (!this.hasMasks) { 10730 return; 10731 } 10732 var transform = this.element.finalTransform.mat; 10733 var ctx = this.element.canvasContext; 10734 var i; 10735 var len = this.masksProperties.length; 10736 var pt; 10737 var pts; 10738 var data; 10739 ctx.beginPath(); 10740 for (i = 0; i < len; i += 1) { 10741 if (this.masksProperties[i].mode !== 'n') { 10742 if (this.masksProperties[i].inv) { 10743 ctx.moveTo(0, 0); 10744 ctx.lineTo(this.element.globalData.compSize.w, 0); 10745 ctx.lineTo(this.element.globalData.compSize.w, this.element.globalData.compSize.h); 10746 ctx.lineTo(0, this.element.globalData.compSize.h); 10747 ctx.lineTo(0, 0); 10748 } 10749 data = this.viewData[i].v; 10750 pt = transform.applyToPointArray(data.v[0][0], data.v[0][1], 0); 10751 ctx.moveTo(pt[0], pt[1]); 10752 var j; 10753 var jLen = data._length; 10754 for (j = 1; j < jLen; j += 1) { 10755 pts = transform.applyToTriplePoints(data.o[j - 1], data.i[j], data.v[j]); 10756 ctx.bezierCurveTo(pts[0], pts[1], pts[2], pts[3], pts[4], pts[5]); 10757 } 10758 pts = transform.applyToTriplePoints(data.o[j - 1], data.i[0], data.v[0]); 10759 ctx.bezierCurveTo(pts[0], pts[1], pts[2], pts[3], pts[4], pts[5]); 10760 } 10761 } 10762 this.element.globalData.renderer.save(true); 10763 ctx.clip(); 10764}; 10765 10766CVMaskElement.prototype.getMaskProperty = MaskElement.prototype.getMaskProperty; 10767 10768CVMaskElement.prototype.destroy = function () { 10769 this.element = null; 10770}; 10771 10772/* global ShapeTransformManager, extendPrototype, BaseElement, TransformElement, CVBaseElement, IShapeElement, 10773HierarchyElement, FrameElement, RenderableElement, RenderableDOMElement, PropertyFactory, degToRads, GradientProperty, 10774DashProperty, TransformPropertyFactory, CVShapeData, ShapeModifiers, bmFloor, lineCapEnum, lineJoinEnum */ 10775 10776function CVShapeElement(data, globalData, comp) { 10777 this.shapes = []; 10778 this.shapesData = data.shapes; 10779 this.stylesList = []; 10780 this.itemsData = []; 10781 this.prevViewData = []; 10782 this.shapeModifiers = []; 10783 this.processedElements = []; 10784 this.transformsManager = new ShapeTransformManager(); 10785 this.initElement(data, globalData, comp); 10786} 10787 10788extendPrototype([BaseElement, TransformElement, CVBaseElement, IShapeElement, HierarchyElement, FrameElement, RenderableElement], CVShapeElement); 10789 10790CVShapeElement.prototype.initElement = RenderableDOMElement.prototype.initElement; 10791 10792CVShapeElement.prototype.transformHelper = { opacity: 1, _opMdf: false }; 10793 10794CVShapeElement.prototype.dashResetter = []; 10795 10796CVShapeElement.prototype.createContent = function () { 10797 this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, true, []); 10798}; 10799 10800CVShapeElement.prototype.createStyleElement = function (data, transforms) { 10801 var styleElem = { 10802 data: data, 10803 type: data.ty, 10804 preTransforms: this.transformsManager.addTransformSequence(transforms), 10805 transforms: [], 10806 elements: [], 10807 closed: data.hd === true, 10808 }; 10809 var elementData = {}; 10810 if (data.ty === 'fl' || data.ty === 'st') { 10811 elementData.c = PropertyFactory.getProp(this, data.c, 1, 255, this); 10812 if (!elementData.c.k) { 10813 styleElem.co = 'rgb(' + bmFloor(elementData.c.v[0]) + ',' + bmFloor(elementData.c.v[1]) + ',' + bmFloor(elementData.c.v[2]) + ')'; 10814 } 10815 } else if (data.ty === 'gf' || data.ty === 'gs') { 10816 elementData.s = PropertyFactory.getProp(this, data.s, 1, null, this); 10817 elementData.e = PropertyFactory.getProp(this, data.e, 1, null, this); 10818 elementData.h = PropertyFactory.getProp(this, data.h || { k: 0 }, 0, 0.01, this); 10819 elementData.a = PropertyFactory.getProp(this, data.a || { k: 0 }, 0, degToRads, this); 10820 elementData.g = new GradientProperty(this, data.g, this); 10821 } 10822 elementData.o = PropertyFactory.getProp(this, data.o, 0, 0.01, this); 10823 if (data.ty === 'st' || data.ty === 'gs') { 10824 styleElem.lc = lineCapEnum[data.lc || 2]; 10825 styleElem.lj = lineJoinEnum[data.lj || 2]; 10826 if (data.lj == 1) { // eslint-disable-line eqeqeq 10827 styleElem.ml = data.ml; 10828 } 10829 elementData.w = PropertyFactory.getProp(this, data.w, 0, null, this); 10830 if (!elementData.w.k) { 10831 styleElem.wi = elementData.w.v; 10832 } 10833 if (data.d) { 10834 var d = new DashProperty(this, data.d, 'canvas', this); 10835 elementData.d = d; 10836 if (!elementData.d.k) { 10837 styleElem.da = elementData.d.dashArray; 10838 styleElem.do = elementData.d.dashoffset[0]; 10839 } 10840 } 10841 } else { 10842 styleElem.r = data.r === 2 ? 'evenodd' : 'nonzero'; 10843 } 10844 this.stylesList.push(styleElem); 10845 elementData.style = styleElem; 10846 return elementData; 10847}; 10848 10849CVShapeElement.prototype.createGroupElement = function () { 10850 var elementData = { 10851 it: [], 10852 prevViewData: [], 10853 }; 10854 return elementData; 10855}; 10856 10857CVShapeElement.prototype.createTransformElement = function (data) { 10858 var elementData = { 10859 transform: { 10860 opacity: 1, 10861 _opMdf: false, 10862 key: this.transformsManager.getNewKey(), 10863 op: PropertyFactory.getProp(this, data.o, 0, 0.01, this), 10864 mProps: TransformPropertyFactory.getTransformProperty(this, data, this), 10865 }, 10866 }; 10867 return elementData; 10868}; 10869 10870CVShapeElement.prototype.createShapeElement = function (data) { 10871 var elementData = new CVShapeData(this, data, this.stylesList, this.transformsManager); 10872 10873 this.shapes.push(elementData); 10874 this.addShapeToModifiers(elementData); 10875 return elementData; 10876}; 10877 10878CVShapeElement.prototype.reloadShapes = function () { 10879 this._isFirstFrame = true; 10880 var i; 10881 var len = this.itemsData.length; 10882 for (i = 0; i < len; i += 1) { 10883 this.prevViewData[i] = this.itemsData[i]; 10884 } 10885 this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, true, []); 10886 len = this.dynamicProperties.length; 10887 for (i = 0; i < len; i += 1) { 10888 this.dynamicProperties[i].getValue(); 10889 } 10890 this.renderModifiers(); 10891 this.transformsManager.processSequences(this._isFirstFrame); 10892}; 10893 10894CVShapeElement.prototype.addTransformToStyleList = function (transform) { 10895 var i; 10896 var len = this.stylesList.length; 10897 for (i = 0; i < len; i += 1) { 10898 if (!this.stylesList[i].closed) { 10899 this.stylesList[i].transforms.push(transform); 10900 } 10901 } 10902}; 10903 10904CVShapeElement.prototype.removeTransformFromStyleList = function () { 10905 var i; 10906 var len = this.stylesList.length; 10907 for (i = 0; i < len; i += 1) { 10908 if (!this.stylesList[i].closed) { 10909 this.stylesList[i].transforms.pop(); 10910 } 10911 } 10912}; 10913 10914CVShapeElement.prototype.closeStyles = function (styles) { 10915 var i; 10916 var len = styles.length; 10917 for (i = 0; i < len; i += 1) { 10918 styles[i].closed = true; 10919 } 10920}; 10921 10922CVShapeElement.prototype.searchShapes = function (arr, itemsData, prevViewData, shouldRender, transforms) { 10923 var i; 10924 var len = arr.length - 1; 10925 var j; 10926 var jLen; 10927 var ownStyles = []; 10928 var ownModifiers = []; 10929 var processedPos; 10930 var modifier; 10931 var currentTransform; 10932 var ownTransforms = [].concat(transforms); 10933 for (i = len; i >= 0; i -= 1) { 10934 processedPos = this.searchProcessedElement(arr[i]); 10935 if (!processedPos) { 10936 arr[i]._shouldRender = shouldRender; 10937 } else { 10938 itemsData[i] = prevViewData[processedPos - 1]; 10939 } 10940 if (arr[i].ty === 'fl' || arr[i].ty === 'st' || arr[i].ty === 'gf' || arr[i].ty === 'gs') { 10941 if (!processedPos) { 10942 itemsData[i] = this.createStyleElement(arr[i], ownTransforms); 10943 } else { 10944 itemsData[i].style.closed = false; 10945 } 10946 10947 ownStyles.push(itemsData[i].style); 10948 } else if (arr[i].ty === 'gr') { 10949 if (!processedPos) { 10950 itemsData[i] = this.createGroupElement(arr[i]); 10951 } else { 10952 jLen = itemsData[i].it.length; 10953 for (j = 0; j < jLen; j += 1) { 10954 itemsData[i].prevViewData[j] = itemsData[i].it[j]; 10955 } 10956 } 10957 this.searchShapes(arr[i].it, itemsData[i].it, itemsData[i].prevViewData, shouldRender, ownTransforms); 10958 } else if (arr[i].ty === 'tr') { 10959 if (!processedPos) { 10960 currentTransform = this.createTransformElement(arr[i]); 10961 itemsData[i] = currentTransform; 10962 } 10963 ownTransforms.push(itemsData[i]); 10964 this.addTransformToStyleList(itemsData[i]); 10965 } else if (arr[i].ty === 'sh' || arr[i].ty === 'rc' || arr[i].ty === 'el' || arr[i].ty === 'sr') { 10966 if (!processedPos) { 10967 itemsData[i] = this.createShapeElement(arr[i]); 10968 } 10969 } else if (arr[i].ty === 'tm' || arr[i].ty === 'rd' || arr[i].ty === 'pb') { 10970 if (!processedPos) { 10971 modifier = ShapeModifiers.getModifier(arr[i].ty); 10972 modifier.init(this, arr[i]); 10973 itemsData[i] = modifier; 10974 this.shapeModifiers.push(modifier); 10975 } else { 10976 modifier = itemsData[i]; 10977 modifier.closed = false; 10978 } 10979 ownModifiers.push(modifier); 10980 } else if (arr[i].ty === 'rp') { 10981 if (!processedPos) { 10982 modifier = ShapeModifiers.getModifier(arr[i].ty); 10983 itemsData[i] = modifier; 10984 modifier.init(this, arr, i, itemsData); 10985 this.shapeModifiers.push(modifier); 10986 shouldRender = false; 10987 } else { 10988 modifier = itemsData[i]; 10989 modifier.closed = true; 10990 } 10991 ownModifiers.push(modifier); 10992 } 10993 this.addProcessedElement(arr[i], i + 1); 10994 } 10995 this.removeTransformFromStyleList(); 10996 this.closeStyles(ownStyles); 10997 len = ownModifiers.length; 10998 for (i = 0; i < len; i += 1) { 10999 ownModifiers[i].closed = true; 11000 } 11001}; 11002 11003CVShapeElement.prototype.renderInnerContent = function () { 11004 this.transformHelper.opacity = 1; 11005 this.transformHelper._opMdf = false; 11006 this.renderModifiers(); 11007 this.transformsManager.processSequences(this._isFirstFrame); 11008 this.renderShape(this.transformHelper, this.shapesData, this.itemsData, true); 11009}; 11010 11011CVShapeElement.prototype.renderShapeTransform = function (parentTransform, groupTransform) { 11012 if (parentTransform._opMdf || groupTransform.op._mdf || this._isFirstFrame) { 11013 groupTransform.opacity = parentTransform.opacity; 11014 groupTransform.opacity *= groupTransform.op.v; 11015 groupTransform._opMdf = true; 11016 } 11017}; 11018 11019CVShapeElement.prototype.drawLayer = function () { 11020 var i; 11021 var len = this.stylesList.length; 11022 var j; 11023 var jLen; 11024 var k; 11025 var kLen; 11026 var elems; 11027 var nodes; 11028 var renderer = this.globalData.renderer; 11029 var ctx = this.globalData.canvasContext; 11030 var type; 11031 var currentStyle; 11032 for (i = 0; i < len; i += 1) { 11033 currentStyle = this.stylesList[i]; 11034 type = currentStyle.type; 11035 11036 // Skipping style when 11037 // Stroke width equals 0 11038 // style should not be rendered (extra unused repeaters) 11039 // current opacity equals 0 11040 // global opacity equals 0 11041 if (!(((type === 'st' || type === 'gs') && currentStyle.wi === 0) || !currentStyle.data._shouldRender || currentStyle.coOp === 0 || this.globalData.currentGlobalAlpha === 0)) { 11042 renderer.save(); 11043 elems = currentStyle.elements; 11044 if (type === 'st' || type === 'gs') { 11045 ctx.strokeStyle = type === 'st' ? currentStyle.co : currentStyle.grd; 11046 ctx.lineWidth = currentStyle.wi; 11047 ctx.lineCap = currentStyle.lc; 11048 ctx.lineJoin = currentStyle.lj; 11049 ctx.miterLimit = currentStyle.ml || 0; 11050 } else { 11051 ctx.fillStyle = type === 'fl' ? currentStyle.co : currentStyle.grd; 11052 } 11053 renderer.ctxOpacity(currentStyle.coOp); 11054 if (type !== 'st' && type !== 'gs') { 11055 ctx.beginPath(); 11056 } 11057 renderer.ctxTransform(currentStyle.preTransforms.finalTransform.props); 11058 jLen = elems.length; 11059 for (j = 0; j < jLen; j += 1) { 11060 if (type === 'st' || type === 'gs') { 11061 ctx.beginPath(); 11062 if (currentStyle.da) { 11063 ctx.setLineDash(currentStyle.da); 11064 ctx.lineDashOffset = currentStyle.do; 11065 } 11066 } 11067 nodes = elems[j].trNodes; 11068 kLen = nodes.length; 11069 11070 for (k = 0; k < kLen; k += 1) { 11071 if (nodes[k].t === 'm') { 11072 ctx.moveTo(nodes[k].p[0], nodes[k].p[1]); 11073 } else if (nodes[k].t === 'c') { 11074 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]); 11075 } else { 11076 ctx.closePath(); 11077 } 11078 } 11079 if (type === 'st' || type === 'gs') { 11080 ctx.stroke(); 11081 if (currentStyle.da) { 11082 ctx.setLineDash(this.dashResetter); 11083 } 11084 } 11085 } 11086 if (type !== 'st' && type !== 'gs') { 11087 ctx.f
vendor: 5,722 bytes, lines 11087-11259
11087ill(currentStyle.r); 11088 } 11089 renderer.restore(); 11090 } 11091 } 11092}; 11093 11094CVShapeElement.prototype.renderShape = function (parentTransform, items, data, isMain) { 11095 var i; 11096 var len = items.length - 1; 11097 var groupTransform; 11098 groupTransform = parentTransform; 11099 for (i = len; i >= 0; i -= 1) { 11100 if (items[i].ty === 'tr') { 11101 groupTransform = data[i].transform; 11102 this.renderShapeTransform(parentTransform, groupTransform); 11103 } else if (items[i].ty === 'sh' || items[i].ty === 'el' || items[i].ty === 'rc' || items[i].ty === 'sr') { 11104 this.renderPath(items[i], data[i]); 11105 } else if (items[i].ty === 'fl') { 11106 this.renderFill(items[i], data[i], groupTransform); 11107 } else if (items[i].ty === 'st') { 11108 this.renderStroke(items[i], data[i], groupTransform); 11109 } else if (items[i].ty === 'gf' || items[i].ty === 'gs') { 11110 this.renderGradientFill(items[i], data[i], groupTransform); 11111 } else if (items[i].ty === 'gr') { 11112 this.renderShape(groupTransform, items[i].it, data[i].it); 11113 } else if (items[i].ty === 'tm') { 11114 // 11115 } 11116 } 11117 if (isMain) { 11118 this.drawLayer(); 11119 } 11120}; 11121 11122CVShapeElement.prototype.renderStyledShape = function (styledShape, shape) { 11123 if (this._isFirstFrame || shape._mdf || styledShape.transforms._mdf) { 11124 var shapeNodes = styledShape.trNodes; 11125 var paths = shape.paths; 11126 var i; 11127 var len; 11128 var j; 11129 var jLen = paths._length; 11130 shapeNodes.length = 0; 11131 var groupTransformMat = styledShape.transforms.finalTransform; 11132 for (j = 0; j < jLen; j += 1) { 11133 var pathNodes = paths.shapes[j]; 11134 if (pathNodes && pathNodes.v) { 11135 len = pathNodes._length; 11136 for (i = 1; i < len; i += 1) { 11137 if (i === 1) { 11138 shapeNodes.push({ 11139 t: 'm', 11140 p: groupTransformMat.applyToPointArray(pathNodes.v[0][0], pathNodes.v[0][1], 0), 11141 }); 11142 } 11143 shapeNodes.push({ 11144 t: 'c', 11145 pts: groupTransformMat.applyToTriplePoints(pathNodes.o[i - 1], pathNodes.i[i], pathNodes.v[i]), 11146 }); 11147 } 11148 if (len === 1) { 11149 shapeNodes.push({ 11150 t: 'm', 11151 p: groupTransformMat.applyToPointArray(pathNodes.v[0][0], pathNodes.v[0][1], 0), 11152 }); 11153 } 11154 if (pathNodes.c && len) { 11155 shapeNodes.push({ 11156 t: 'c', 11157 pts: groupTransformMat.applyToTriplePoints(pathNodes.o[i - 1], pathNodes.i[0], pathNodes.v[0]), 11158 }); 11159 shapeNodes.push({ 11160 t: 'z', 11161 }); 11162 } 11163 } 11164 } 11165 styledShape.trNodes = shapeNodes; 11166 } 11167}; 11168 11169CVShapeElement.prototype.renderPath = function (pathData, itemData) { 11170 if (pathData.hd !== true && pathData._shouldRender) { 11171 var i; 11172 var len = itemData.styledShapes.length; 11173 for (i = 0; i < len; i += 1) { 11174 this.renderStyledShape(itemData.styledShapes[i], itemData.sh); 11175 } 11176 } 11177}; 11178 11179CVShapeElement.prototype.renderFill = function (styleData, itemData, groupTransform) { 11180 var styleElem = itemData.style; 11181 11182 if (itemData.c._mdf || this._isFirstFrame) { 11183 styleElem.co = 'rgb(' 11184 + bmFloor(itemData.c.v[0]) + ',' 11185 + bmFloor(itemData.c.v[1]) + ',' 11186 + bmFloor(itemData.c.v[2]) + ')'; 11187 } 11188 if (itemData.o._mdf || groupTransform._opMdf || this._isFirstFrame) { 11189 styleElem.coOp = itemData.o.v * groupTransform.opacity; 11190 } 11191}; 11192 11193CVShapeElement.prototype.renderGradientFill = function (styleData, itemData, groupTransform) { 11194 var styleElem = itemData.style; 11195 var grd; 11196 if (!styleElem.grd || itemData.g._mdf || itemData.s._mdf || itemData.e._mdf || (styleData.t !== 1 && (itemData.h._mdf || itemData.a._mdf))) { 11197 var ctx = this.globalData.canvasContext; 11198 var pt1 = itemData.s.v; 11199 var pt2 = itemData.e.v; 11200 if (styleData.t === 1) { 11201 grd = ctx.createLinearGradient(pt1[0], pt1[1], pt2[0], pt2[1]); 11202 } else { 11203 var rad = Math.sqrt(Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2)); 11204 var ang = Math.atan2(pt2[1] - pt1[1], pt2[0] - pt1[0]); 11205 11206 var percent = itemData.h.v; 11207 if (percent >= 1) { 11208 percent = 0.99; 11209 } else if (percent <= -1) { 11210 percent = -0.99; 11211 } 11212 var dist = rad * percent; 11213 var x = Math.cos(ang + itemData.a.v) * dist + pt1[0]; 11214 var y = Math.sin(ang + itemData.a.v) * dist + pt1[1]; 11215 grd = ctx.createRadialGradient(x, y, 0, pt1[0], pt1[1], rad); 11216 } 11217 11218 var i; 11219 var len = styleData.g.p; 11220 var cValues = itemData.g.c; 11221 var opacity = 1; 11222 11223 for (i = 0; i < len; i += 1) { 11224 if (itemData.g._hasOpacity && itemData.g._collapsable) { 11225 opacity = itemData.g.o[i * 2 + 1]; 11226 } 11227 grd.addColorStop(cValues[i * 4] / 100, 'rgba(' + cValues[i * 4 + 1] + ',' + cValues[i * 4 + 2] + ',' + cValues[i * 4 + 3] + ',' + opacity + ')'); 11228 } 11229 styleElem.grd = grd; 11230 } 11231 styleElem.coOp = itemData.o.v * groupTransform.opacity; 11232}; 11233 11234CVShapeElement.prototype.renderStroke = function (styleData, itemData, groupTransform) { 11235 var styleElem = itemData.style; 11236 var d = itemData.d; 11237 if (d && (d._mdf || this._isFirstFrame)) { 11238 styleElem.da = d.dashArray; 11239 styleElem.do = d.dashoffset[0]; 11240 } 11241 if (itemData.c._mdf || this._isFirstFrame) { 11242 styleElem.co = 'rgb(' + bmFloor(itemData.c.v[0]) + ',' + bmFloor(itemData.c.v[1]) + ',' + bmFloor(itemData.c.v[2]) + ')'; 11243 } 11244 if (itemData.o._mdf || groupTransform._opMdf || this._isFirstFrame) { 11245 styleElem.coOp = itemData.o.v * groupTransform.opacity; 11246 } 11247 if (itemData.w._mdf || this._isFirstFrame) { 11248 styleElem.wi = itemData.w.v; 11249 } 11250}; 11251 11252CVShapeElement.prototype.destroy = function () { 11253 this.shapesData = null; 11254 this.globalData = null; 11255 this.canvasContext = null; 11256 this.stylesList.length = 0; 11257 this.itemsData.length = 0; 11258}; 11259
vendor: 25,792 bytes, lines 11260-11980
11260/* global extendPrototype, BaseElement, TransformElement, CVBaseElement, HierarchyElement, FrameElement, RenderableElement, 11261SVGShapeElement, IImageElement */ 11262 11263function CVSolidElement(data, globalData, comp) { 11264 this.initElement(data, globalData, comp); 11265} 11266extendPrototype([BaseElement, TransformElement, CVBaseElement, HierarchyElement, FrameElement, RenderableElement], CVSolidElement); 11267 11268CVSolidElement.prototype.initElement = SVGShapeElement.prototype.initElement; 11269CVSolidElement.prototype.prepareFrame = IImageElement.prototype.prepareFrame; 11270 11271CVSolidElement.prototype.renderInnerContent = function () { 11272 var ctx = this.canvasContext; 11273 ctx.fillStyle = this.data.sc; 11274 ctx.fillRect(0, 0, this.data.sw, this.data.sh); 11275 // 11276}; 11277 11278/* global extendPrototype, BaseElement, TransformElement, CVBaseElement, HierarchyElement, FrameElement, 11279RenderableElement, ITextElement, createTag, createSizedArray */ 11280 11281function CVTextElement(data, globalData, comp) { 11282 this.textSpans = []; 11283 this.yOffset = 0; 11284 this.fillColorAnim = false; 11285 this.strokeColorAnim = false; 11286 this.strokeWidthAnim = false; 11287 this.stroke = false; 11288 this.fill = false; 11289 this.justifyOffset = 0; 11290 this.currentRender = null; 11291 this.renderType = 'canvas'; 11292 this.values = { 11293 fill: 'rgba(0,0,0,0)', 11294 stroke: 'rgba(0,0,0,0)', 11295 sWidth: 0, 11296 fValue: '', 11297 }; 11298 this.initElement(data, globalData, comp); 11299} 11300extendPrototype([BaseElement, TransformElement, CVBaseElement, HierarchyElement, FrameElement, RenderableElement, ITextElement], CVTextElement); 11301 11302CVTextElement.prototype.tHelper = createTag('canvas').getContext('2d'); 11303 11304CVTextElement.prototype.buildNewText = function () { 11305 var documentData = this.textProperty.currentData; 11306 this.renderedLetters = createSizedArray(documentData.l ? documentData.l.length : 0); 11307 11308 var hasFill = false; 11309 if (documentData.fc) { 11310 hasFill = true; 11311 this.values.fill = this.buildColor(documentData.fc); 11312 } else { 11313 this.values.fill = 'rgba(0,0,0,0)'; 11314 } 11315 this.fill = hasFill; 11316 var hasStroke = false; 11317 if (documentData.sc) { 11318 hasStroke = true; 11319 this.values.stroke = this.buildColor(documentData.sc); 11320 this.values.sWidth = documentData.sw; 11321 } 11322 var fontData = this.globalData.fontManager.getFontByName(documentData.f); 11323 var i; 11324 var len; 11325 var letters = documentData.l; 11326 var matrixHelper = this.mHelper; 11327 this.stroke = hasStroke; 11328 this.values.fValue = documentData.finalSize + 'px ' + this.globalData.fontManager.getFontByName(documentData.f).fFamily; 11329 len = documentData.finalText.length; 11330 // this.tHelper.font = this.values.fValue; 11331 var charData; 11332 var shapeData; 11333 var k; 11334 var kLen; 11335 var shapes; 11336 var j; 11337 var jLen; 11338 var pathNodes; 11339 var commands; 11340 var pathArr; 11341 var singleShape = this.data.singleShape; 11342 var trackingOffset = documentData.tr * 0.001 * documentData.finalSize; 11343 var xPos = 0; 11344 var yPos = 0; 11345 var firstLine = true; 11346 var cnt = 0; 11347 for (i = 0; i < len; i += 1) { 11348 charData = this.globalData.fontManager.getCharData(documentData.finalText[i], fontData.fStyle, this.globalData.fontManager.getFontByName(documentData.f).fFamily); 11349 shapeData = (charData && charData.data) || {}; 11350 matrixHelper.reset(); 11351 if (singleShape && letters[i].n) { 11352 xPos = -trackingOffset; 11353 yPos += documentData.yOffset; 11354 yPos += firstLine ? 1 : 0; 11355 firstLine = false; 11356 } 11357 11358 shapes = shapeData.shapes ? shapeData.shapes[0].it : []; 11359 jLen = shapes.length; 11360 matrixHelper.scale(documentData.finalSize / 100, documentData.finalSize / 100); 11361 if (singleShape) { 11362 this.applyTextPropertiesToMatrix(documentData, matrixHelper, letters[i].line, xPos, yPos); 11363 } 11364 commands = createSizedArray(jLen); 11365 for (j = 0; j < jLen; j += 1) { 11366 kLen = shapes[j].ks.k.i.length; 11367 pathNodes = shapes[j].ks.k; 11368 pathArr = []; 11369 for (k = 1; k < kLen; k += 1) { 11370 if (k === 1) { 11371 pathArr.push(matrixHelper.applyToX(pathNodes.v[0][0], pathNodes.v[0][1], 0), matrixHelper.applyToY(pathNodes.v[0][0], pathNodes.v[0][1], 0)); 11372 } 11373 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)); 11374 } 11375 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)); 11376 commands[j] = pathArr; 11377 } 11378 if (singleShape) { 11379 xPos += letters[i].l; 11380 xPos += trackingOffset; 11381 } 11382 if (this.textSpans[cnt]) { 11383 this.textSpans[cnt].elem = commands; 11384 } else { 11385 this.textSpans[cnt] = { elem: commands }; 11386 } 11387 cnt += 1; 11388 } 11389}; 11390 11391CVTextElement.prototype.renderInnerContent = function () { 11392 var ctx = this.canvasContext; 11393 ctx.font = this.values.fValue; 11394 ctx.lineCap = 'butt'; 11395 ctx.lineJoin = 'miter'; 11396 ctx.miterLimit = 4; 11397 11398 if (!this.data.singleShape) { 11399 this.textAnimator.getMeasures(this.textProperty.currentData, this.lettersChangedFlag); 11400 } 11401 11402 var i; 11403 var len; 11404 var j; 11405 var jLen; 11406 var k; 11407 var kLen; 11408 var renderedLetters = this.textAnimator.renderedLetters; 11409 11410 var letters = this.textProperty.currentData.l; 11411 11412 len = letters.length; 11413 var renderedLetter; 11414 var lastFill = null; 11415 var lastStroke = null; 11416 var lastStrokeW = null; 11417 var commands; 11418 var pathArr; 11419 for (i = 0; i < len; i += 1) { 11420 if (!letters[i].n) { 11421 renderedLetter = renderedLetters[i]; 11422 if (renderedLetter) { 11423 this.globalData.renderer.save(); 11424 this.globalData.renderer.ctxTransform(renderedLetter.p); 11425 this.globalData.renderer.ctxOpacity(renderedLetter.o); 11426 } 11427 if (this.fill) { 11428 if (renderedLetter && renderedLetter.fc) { 11429 if (lastFill !== renderedLetter.fc) { 11430 lastFill = renderedLetter.fc; 11431 ctx.fillStyle = renderedLetter.fc; 11432 } 11433 } else if (lastFill !== this.values.fill) { 11434 lastFill = this.values.fill; 11435 ctx.fillStyle = this.values.fill; 11436 } 11437 commands = this.textSpans[i].elem; 11438 jLen = commands.length; 11439 this.globalData.canvasContext.beginPath(); 11440 for (j = 0; j < jLen; j += 1) { 11441 pathArr = commands[j]; 11442 kLen = pathArr.length; 11443 this.globalData.canvasContext.moveTo(pathArr[0], pathArr[1]); 11444 for (k = 2; k < kLen; k += 6) { 11445 this.globalData.canvasContext.bezierCurveTo(pathArr[k], pathArr[k + 1], pathArr[k + 2], pathArr[k + 3], pathArr[k + 4], pathArr[k + 5]); 11446 } 11447 } 11448 this.globalData.canvasContext.closePath(); 11449 this.globalData.canvasContext.fill(); 11450 /// ctx.fillText(this.textSpans[i].val,0,0); 11451 } 11452 if (this.stroke) { 11453 if (renderedLetter && renderedLetter.sw) { 11454 if (lastStrokeW !== renderedLetter.sw) { 11455 lastStrokeW = renderedLetter.sw; 11456 ctx.lineWidth = renderedLetter.sw; 11457 } 11458 } else if (lastStrokeW !== this.values.sWidth) { 11459 lastStrokeW = this.values.sWidth; 11460 ctx.lineWidth = this.values.sWidth; 11461 } 11462 if (renderedLetter && renderedLetter.sc) { 11463 if (lastStroke !== renderedLetter.sc) { 11464 lastStroke = renderedLetter.sc; 11465 ctx.strokeStyle = renderedLetter.sc; 11466 } 11467 } else if (lastStroke !== this.values.stroke) { 11468 lastStroke = this.values.stroke; 11469 ctx.strokeStyle = this.values.stroke; 11470 } 11471 commands = this.textSpans[i].elem; 11472 jLen = commands.length; 11473 this.globalData.canvasContext.beginPath(); 11474 for (j = 0; j < jLen; j += 1) { 11475 pathArr = commands[j]; 11476 kLen = pathArr.length; 11477 this.globalData.canvasContext.moveTo(pathArr[0], pathArr[1]); 11478 for (k = 2; k < kLen; k += 6) { 11479 this.globalData.canvasContext.bezierCurveTo(pathArr[k], pathArr[k + 1], pathArr[k + 2], pathArr[k + 3], pathArr[k + 4], pathArr[k + 5]); 11480 } 11481 } 11482 this.globalData.canvasContext.closePath(); 11483 this.globalData.canvasContext.stroke(); 11484 /// ctx.strokeText(letters[i].val,0,0); 11485 } 11486 if (renderedLetter) { 11487 this.globalData.renderer.restore(); 11488 } 11489 } 11490 } 11491}; 11492 11493function CVEffects() { 11494 11495} 11496CVEffects.prototype.renderFrame = function () {}; 11497 11498/* global createTag, createNS, styleDiv, CVEffects, MaskElement, SVGBaseElement, HybridRenderer */ 11499 11500function HBaseElement() {} 11501HBaseElement.prototype = { 11502 checkBlendMode: function () {}, 11503 initRendererElement: function () { 11504 this.baseElement = createTag(this.data.tg || 'div'); 11505 if (this.data.hasMask) { 11506 this.svgElement = createNS('svg'); 11507 this.layerElement = createNS('g'); 11508 this.maskedElement = this.layerElement; 11509 this.svgElement.appendChild(this.layerElement); 11510 this.baseElement.appendChild(this.svgElement); 11511 } else { 11512 this.layerElement = this.baseElement; 11513 } 11514 styleDiv(this.baseElement); 11515 }, 11516 createContainerElements: function () { 11517 this.renderableEffectsManager = new CVEffects(this); 11518 this.transformedElement = this.baseElement; 11519 this.maskedElement = this.layerElement; 11520 if (this.data.ln) { 11521 this.layerElement.setAttribute('id', this.data.ln); 11522 } 11523 if (this.data.cl) { 11524 this.layerElement.setAttribute('class', this.data.cl); 11525 } 11526 if (this.data.bm !== 0) { 11527 this.setBlendMode(); 11528 } 11529 }, 11530 renderElement: function () { 11531 var transformedElementStyle = this.transformedElement ? this.transformedElement.style : {}; 11532 if (this.finalTransform._matMdf) { 11533 var matrixValue = this.finalTransform.mat.toCSS(); 11534 transformedElementStyle.transform = matrixValue; 11535 transformedElementStyle.webkitTransform = matrixValue; 11536 } 11537 if (this.finalTransform._opMdf) { 11538 transformedElementStyle.opacity = this.finalTransform.mProp.o.v; 11539 } 11540 }, 11541 renderFrame: function () { 11542 // If it is exported as hidden (data.hd === true) no need to render 11543 // If it is not visible no need to render 11544 if (this.data.hd || this.hidden) { 11545 return; 11546 } 11547 this.renderTransform(); 11548 this.renderRenderable(); 11549 this.renderElement(); 11550 this.renderInnerContent(); 11551 if (this._isFirstFrame) { 11552 this._isFirstFrame = false; 11553 } 11554 }, 11555 destroy: function () { 11556 this.layerElement = null; 11557 this.transformedElement = null; 11558 if (this.matteElement) { 11559 this.matteElement = null; 11560 } 11561 if (this.maskManager) { 11562 this.maskManager.destroy(); 11563 this.maskManager = null; 11564 } 11565 }, 11566 createRenderableComponents: function () { 11567 this.maskManager = new MaskElement(this.data, this, this.globalData); 11568 }, 11569 addEffects: function () { 11570 }, 11571 setMatte: function () {}, 11572}; 11573HBaseElement.prototype.getBaseElement = SVGBaseElement.prototype.getBaseElement; 11574HBaseElement.prototype.destroyBaseElement = HBaseElement.prototype.destroy; 11575HBaseElement.prototype.buildElementParenting = HybridRenderer.prototype.buildElementParenting; 11576 11577/* global extendPrototype, BaseElement, TransformElement, HBaseElement, HierarchyElement, FrameElement, 11578RenderableDOMElement, createNS, createTag */ 11579 11580function HSolidElement(data, globalData, comp) { 11581 this.initElement(data, globalData, comp); 11582} 11583extendPrototype([BaseElement, TransformElement, HBaseElement, HierarchyElement, FrameElement, RenderableDOMElement], HSolidElement); 11584 11585HSolidElement.prototype.createContent = function () { 11586 var rect; 11587 if (this.data.hasMask) { 11588 rect = createNS('rect'); 11589 rect.setAttribute('width', this.data.sw); 11590 rect.setAttribute('height', this.data.sh); 11591 rect.setAttribute('fill', this.data.sc); 11592 this.svgElement.setAttribute('width', this.data.sw); 11593 this.svgElement.setAttribute('height', this.data.sh); 11594 } else { 11595 rect = createTag('div'); 11596 rect.style.width = this.data.sw + 'px'; 11597 rect.style.height = this.data.sh + 'px'; 11598 rect.style.backgroundColor = this.data.sc; 11599 } 11600 this.layerElement.appendChild(rect); 11601}; 11602 11603/* global createSizedArray, PropertyFactory, extendPrototype, HybridRenderer, ICompElement, HBaseElement */ 11604 11605function HCompElement(data, globalData, comp) { 11606 this.layers = data.layers; 11607 this.supports3d = !data.hasMask; 11608 this.completeLayers = false; 11609 this.pendingElements = []; 11610 this.elements = this.layers ? createSizedArray(this.layers.length) : []; 11611 this.initElement(data, globalData, comp); 11612 this.tm = data.tm ? PropertyFactory.getProp(this, data.tm, 0, globalData.frameRate, this) : { _placeholder: true }; 11613} 11614 11615extendPrototype([HybridRenderer, ICompElement, HBaseElement], HCompElement); 11616HCompElement.prototype._createBaseContainerElements = HCompElement.prototype.createContainerElements; 11617 11618HCompElement.prototype.createContainerElements = function () { 11619 this._createBaseContainerElements(); 11620 // divElement.style.clip = 'rect(0px, '+this.data.w+'px, '+this.data.h+'px, 0px)'; 11621 if (this.data.hasMask) { 11622 this.svgElement.setAttribute('width', this.data.w); 11623 this.svgElement.setAttribute('height', this.data.h); 11624 this.transformedElement = this.baseElement; 11625 } else { 11626 this.transformedElement = this.layerElement; 11627 } 11628}; 11629 11630HCompElement.prototype.addTo3dContainer = function (elem, pos) { 11631 var j = 0; 11632 var nextElement; 11633 while (j < pos) { 11634 if (this.elements[j] && this.elements[j].getBaseElement) { 11635 nextElement = this.elements[j].getBaseElement(); 11636 } 11637 j += 1; 11638 } 11639 if (nextElement) { 11640 this.layerElement.insertBefore(elem, nextElement); 11641 } else { 11642 this.layerElement.appendChild(elem); 11643 } 11644}; 11645 11646/* global createNS, extendPrototype, BaseElement, TransformElement, HSolidElement, SVGShapeElement, HBaseElement, 11647HierarchyElement, FrameElement, RenderableElement, createNS, bmMin, bmSqrt, bmMin, bmMax, bmPow */ 11648 11649function HShapeElement(data, globalData, comp) { 11650 // List of drawable elements 11651 this.shapes = []; 11652 // Full shape data 11653 this.shapesData = data.shapes; 11654 // List of styles that will be applied to shapes 11655 this.stylesList = []; 11656 // List of modifiers that will be applied to shapes 11657 this.shapeModifiers = []; 11658 // List of items in shape tree 11659 this.itemsData = []; 11660 // List of items in previous shape tree 11661 this.processedElements = []; 11662 // List of animated components 11663 this.animatedContents = []; 11664 this.shapesContainer = createNS('g'); 11665 this.initElement(data, globalData, comp); 11666 // Moving any property that doesn't get too much access after initialization because of v8 way of handling more than 10 properties. 11667 // List of elements that have been created 11668 this.prevViewData = []; 11669 this.currentBBox = { 11670 x: 999999, 11671 y: -999999, 11672 h: 0, 11673 w: 0, 11674 }; 11675} 11676extendPrototype([BaseElement, TransformElement, HSolidElement, SVGShapeElement, HBaseElement, HierarchyElement, FrameElement, RenderableElement], HShapeElement); 11677HShapeElement.prototype._renderShapeFrame = HShapeElement.prototype.renderInnerContent; 11678 11679HShapeElement.prototype.createContent = function () { 11680 var cont; 11681 this.baseElement.style.fontSize = 0; 11682 if (this.data.hasMask) { 11683 this.layerElement.appendChild(this.shapesContainer); 11684 cont = this.svgElement; 11685 } else { 11686 cont = createNS('svg'); 11687 var size = this.comp.data ? this.comp.data : this.globalData.compSize; 11688 cont.setAttribute('width', size.w); 11689 cont.setAttribute('height', size.h); 11690 cont.appendChild(this.shapesContainer); 11691 this.layerElement.appendChild(cont); 11692 } 11693 11694 this.searchShapes(this.shapesData, this.itemsData, this.prevViewData, this.shapesContainer, 0, [], true); 11695 this.filterUniqueShapes(); 11696 this.shapeCont = cont; 11697}; 11698 11699HShapeElement.prototype.getTransformedPoint = function (transformers, point) { 11700 var i; 11701 var len = transformers.length; 11702 for (i = 0; i < len; i += 1) { 11703 point = transformers[i].mProps.v.applyToPointArray(point[0], point[1], 0); 11704 } 11705 return point; 11706}; 11707 11708HShapeElement.prototype.calculateShapeBoundingBox = function (item, boundingBox) { 11709 var shape = item.sh.v; 11710 var transformers = item.transformers; 11711 var i; 11712 var len = shape._length; 11713 var vPoint; 11714 var oPoint; 11715 var nextIPoint; 11716 var nextVPoint; 11717 if (len <= 1) { 11718 return; 11719 } 11720 for (i = 0; i < len - 1; i += 1) { 11721 vPoint = this.getTransformedPoint(transformers, shape.v[i]); 11722 oPoint = this.getTransformedPoint(transformers, shape.o[i]); 11723 nextIPoint = this.getTransformedPoint(transformers, shape.i[i + 1]); 11724 nextVPoint = this.getTransformedPoint(transformers, shape.v[i + 1]); 11725 this.checkBounds(vPoint, oPoint, nextIPoint, nextVPoint, boundingBox); 11726 } 11727 if (shape.c) { 11728 vPoint = this.getTransformedPoint(transformers, shape.v[i]); 11729 oPoint = this.getTransformedPoint(transformers, shape.o[i]); 11730 nextIPoint = this.getTransformedPoint(transformers, shape.i[0]); 11731 nextVPoint = this.getTransformedPoint(transformers, shape.v[0]); 11732 this.checkBounds(vPoint, oPoint, nextIPoint, nextVPoint, boundingBox); 11733 } 11734}; 11735 11736HShapeElement.prototype.checkBounds = function (vPoint, oPoint, nextIPoint, nextVPoint, boundingBox) { 11737 this.getBoundsOfCurve(vPoint, oPoint, nextIPoint, nextVPoint); 11738 var bounds = this.shapeBoundingBox; 11739 boundingBox.x = bmMin(bounds.left, boundingBox.x); 11740 boundingBox.xMax = bmMax(bounds.right, boundingBox.xMax); 11741 boundingBox.y = bmMin(bounds.top, boundingBox.y); 11742 boundingBox.yMax = bmMax(bounds.bottom, boundingBox.yMax); 11743}; 11744 11745HShapeElement.prototype.shapeBoundingBox = { 11746 left: 0, 11747 right: 0, 11748 top: 0, 11749 bottom: 0, 11750}; 11751 11752HShapeElement.prototype.tempBoundingBox = { 11753 x: 0, 11754 xMax: 0, 11755 y: 0, 11756 yMax: 0, 11757 width: 0, 11758 height: 0, 11759}; 11760 11761HShapeElement.prototype.getBoundsOfCurve = function (p0, p1, p2, p3) { 11762 var bounds = [[p0[0], p3[0]], [p0[1], p3[1]]]; 11763 11764 for (var a, b, c, t, b2ac, t1, t2, i = 0; i < 2; ++i) { // eslint-disable-line no-plusplus 11765 b = 6 * p0[i] - 12 * p1[i] + 6 * p2[i]; 11766 a = -3 * p0[i] + 9 * p1[i] - 9 * p2[i] + 3 * p3[i]; 11767 c = 3 * p1[i] - 3 * p0[i]; 11768 11769 b |= 0; // eslint-disable-line no-bitwise 11770 a |= 0; // eslint-disable-line no-bitwise 11771 c |= 0; // eslint-disable-line no-bitwise 11772 11773 if (a === 0 && b === 0) { 11774 // 11775 } else if (a === 0) { 11776 t = -c / b; 11777 11778 if (t > 0 && t < 1) { 11779 bounds[i].push(this.calculateF(t, p0, p1, p2, p3, i)); 11780 } 11781 } else { 11782 b2ac = b * b - 4 * c * a; 11783 11784 if (b2ac >= 0) { 11785 t1 = (-b + bmSqrt(b2ac)) / (2 * a); 11786 if (t1 > 0 && t1 < 1) bounds[i].push(this.calculateF(t1, p0, p1, p2, p3, i)); 11787 t2 = (-b - bmSqrt(b2ac)) / (2 * a); 11788 if (t2 > 0 && t2 < 1) bounds[i].push(this.calculateF(t2, p0, p1, p2, p3, i)); 11789 } 11790 } 11791 } 11792 11793 this.shapeBoundingBox.left = bmMin.apply(null, bounds[0]); 11794 this.shapeBoundingBox.top = bmMin.apply(null, bounds[1]); 11795 this.shapeBoundingBox.right = bmMax.apply(null, bounds[0]); 11796 this.shapeBoundingBox.bottom = bmMax.apply(null, bounds[1]); 11797}; 11798 11799HShapeElement.prototype.calculateF = function (t, p0, p1, p2, p3, i) { 11800 return bmPow(1 - t, 3) * p0[i] 11801 + 3 * bmPow(1 - t, 2) * t * p1[i] 11802 + 3 * (1 - t) * bmPow(t, 2) * p2[i] 11803 + bmPow(t, 3) * p3[i]; 11804}; 11805 11806HShapeElement.prototype.calculateBoundingBox = function (itemsData, boundingBox) { 11807 var i; 11808 var len = itemsData.length; 11809 for (i = 0; i < len; i += 1) { 11810 if (itemsData[i] && itemsData[i].sh) { 11811 this.calculateShapeBoundingBox(itemsData[i], boundingBox); 11812 } else if (itemsData[i] && itemsData[i].it) { 11813 this.calculateBoundingBox(itemsData[i].it, boundingBox); 11814 } 11815 } 11816}; 11817 11818HShapeElement.prototype.currentBoxContains = function (box) { 11819 return this.currentBBox.x <= box.x 11820 && this.currentBBox.y <= box.y 11821 && this.currentBBox.width + this.currentBBox.x >= box.x + box.width 11822 && this.currentBBox.height + this.currentBBox.y >= box.y + box.height; 11823}; 11824 11825HShapeElement.prototype.renderInnerContent = function () { 11826 this._renderShapeFrame(); 11827 11828 if (!this.hidden && (this._isFirstFrame || this._mdf)) { 11829 var tempBoundingBox = this.tempBoundingBox; 11830 var max = 999999; 11831 tempBoundingBox.x = max; 11832 tempBoundingBox.xMax = -max; 11833 tempBoundingBox.y = max; 11834 tempBoundingBox.yMax = -max; 11835 this.calculateBoundingBox(this.itemsData, tempBoundingBox); 11836 tempBoundingBox.width = tempBoundingBox.xMax < tempBoundingBox.x ? 0 : tempBoundingBox.xMax - tempBoundingBox.x; 11837 tempBoundingBox.height = tempBoundingBox.yMax < tempBoundingBox.y ? 0 : tempBoundingBox.yMax - tempBoundingBox.y; 11838 // var tempBoundingBox = this.shapeCont.getBBox(); 11839 if (this.currentBoxContains(tempBoundingBox)) { 11840 return; 11841 } 11842 var changed = false; 11843 if (this.currentBBox.w !== tempBoundingBox.width) { 11844 this.currentBBox.w = tempBoundingBox.width; 11845 this.shapeCont.setAttribute('width', tempBoundingBox.width); 11846 changed = true; 11847 } 11848 if (this.currentBBox.h !== tempBoundingBox.height) { 11849 this.currentBBox.h = tempBoundingBox.height; 11850 this.shapeCont.setAttribute('height', tempBoundingBox.height); 11851 changed = true; 11852 } 11853 if (changed || this.currentBBox.x !== tempBoundingBox.x || this.currentBBox.y !== tempBoundingBox.y) { 11854 this.currentBBox.w = tempBoundingBox.width; 11855 this.currentBBox.h = tempBoundingBox.height; 11856 this.currentBBox.x = tempBoundingBox.x; 11857 this.currentBBox.y = tempBoundingBox.y; 11858 11859 this.shapeCont.setAttribute('viewBox', this.currentBBox.x + ' ' + this.currentBBox.y + ' ' + this.currentBBox.w + ' ' + this.currentBBox.h); 11860 var shapeStyle = this.shapeCont.style; 11861 var shapeTransform = 'translate(' + this.currentBBox.x + 'px,' + this.currentBBox.y + 'px)'; 11862 shapeStyle.transform = shapeTransform; 11863 shapeStyle.webkitTransform = shapeTransform; 11864 } 11865 } 11866}; 11867 11868/* global extendPrototype, BaseElement, TransformElement, HBaseElement, HierarchyElement, FrameElement, 11869RenderableDOMElement, ITextElement, createSizedArray, createTag, styleDiv, createNS, lineJoinEnum, lineCapEnum */ 11870 11871function HTextElement(data, globalData, comp) { 11872 this.textSpans = []; 11873 this.textPaths = []; 11874 this.currentBBox = { 11875 x: 999999, 11876 y: -999999, 11877 h: 0, 11878 w: 0, 11879 }; 11880 this.renderType = 'svg'; 11881 this.isMasked = false; 11882 this.initElement(data, globalData, comp); 11883} 11884extendPrototype([BaseElement, TransformElement, HBaseElement, HierarchyElement, FrameElement, RenderableDOMElement, ITextElement], HTextElement); 11885 11886HTextElement.prototype.createContent = function () { 11887 this.isMasked = this.checkMasks(); 11888 if (this.isMasked) { 11889 this.renderType = 'svg'; 11890 this.compW = this.comp.data.w; 11891 this.compH = this.comp.data.h; 11892 this.svgElement.setAttribute('width', this.compW); 11893 this.svgElement.setAttribute('height', this.compH); 11894 var g = createNS('g'); 11895 this.maskedElement.appendChild(g); 11896 this.innerElem = g; 11897 } else { 11898 this.renderType = 'html'; 11899 this.innerElem = this.layerElement; 11900 } 11901 11902 this.checkParenting(); 11903}; 11904 11905HTextElement.prototype.buildNewText = function () { 11906 var documentData = this.textProperty.currentData; 11907 this.renderedLetters = createSizedArray(documentData.l ? documentData.l.length : 0); 11908 var innerElemStyle = this.innerElem.style; 11909 var textColor = documentData.fc ? this.buildColor(documentData.fc) : 'rgba(0,0,0,0)'; 11910 innerElemStyle.fill = textColor; 11911 innerElemStyle.color = textColor; 11912 if (documentData.sc) { 11913 innerElemStyle.stroke = this.buildColor(documentData.sc); 11914 innerElemStyle.strokeWidth = documentData.sw + 'px'; 11915 } 11916 var fontData = this.globalData.fontManager.getFontByName(documentData.f); 11917 if (!this.globalData.fontManager.chars) { 11918 innerElemStyle.fontSize = documentData.finalSize + 'px'; 11919 innerElemStyle.lineHeight = documentData.finalSize + 'px'; 11920 if (fontData.fClass) { 11921 this.innerElem.className = fontData.fClass; 11922 } else { 11923 innerElemStyle.fontFamily = fontData.fFamily; 11924 var fWeight = documentData.fWeight; 11925 var fStyle = documentData.fStyle; 11926 innerElemStyle.fontStyle = fStyle; 11927 innerElemStyle.fontWeight = fWeight; 11928 } 11929 } 11930 var i; 11931 var len; 11932 11933 var letters = documentData.l; 11934 len = letters.length; 11935 var tSpan; 11936 var tParent; 11937 var tCont; 11938 var matrixHelper = this.mHelper; 11939 var shapes; 11940 var shapeStr = ''; 11941 var cnt = 0; 11942 for (i = 0; i < len; i += 1) { 11943 if (this.globalData.fontManager.chars) { 11944 if (!this.textPaths[cnt]) { 11945 tSpan = createNS('path'); 11946 tSpan.setAttribute('stroke-linecap', lineCapEnum[1]); 11947 tSpan.setAttribute('stroke-linejoin', lineJoinEnum[2]); 11948 tSpan.setAttribute('stroke-miterlimit', '4'); 11949 } else { 11950 tSpan = this.textPaths[cnt]; 11951 } 11952 if (!this.isMasked) { 11953 if (this.textSpans[cnt]) { 11954 tParent = this.textSpans[cnt]; 11955 tCont = tParent.children[0]; 11956 } else { 11957 tParent = createTag('div'); 11958 tParent.style.lineHeight = 0; 11959 tCont = createNS('svg'); 11960 tCont.appendChild(tSpan); 11961 styleDiv(tParent); 11962 } 11963 } 11964 } else if (!this.isMasked) { 11965 if (this.textSpans[cnt]) { 11966 tParent = this.textSpans[cnt]; 11967 tSpan = this.textPaths[cnt]; 11968 } else { 11969 tParent = createTag('span'); 11970 styleDiv(tParent); 11971 tSpan = createTag('span'); 11972 styleDiv(tSpan); 11973 tParent.appendChild(tSpan); 11974 } 11975 } else { 11976 tSpan = this.textPaths[cnt] ? this.textPaths[cnt] : createNS('text'); 11977 } 11978 // tSpan.setAttribute('visibility', 'hidden'); 11979 if (this.globalData.fontManager.chars) { 11980 var charData = this.globalData.fontManager.getCharData(documentData.finalText[i], fontData.fStyle, this.globalData.fontManager.getFontByName(
vendor: 4,730 bytes, lines 11980-12110
11980documentData.f).fFamily); 11981 var shapeData; 11982 if (charData) { 11983 shapeData = charData.data; 11984 } else { 11985 shapeData = null; 11986 } 11987 matrixHelper.reset(); 11988 if (shapeData && shapeData.shapes) { 11989 shapes = shapeData.shapes[0].it; 11990 matrixHelper.scale(documentData.finalSize / 100, documentData.finalSize / 100); 11991 shapeStr = this.createPathShape(matrixHelper, shapes); 11992 tSpan.setAttribute('d', shapeStr); 11993 } 11994 if (!this.isMasked) { 11995 this.innerElem.appendChild(tParent); 11996 if (shapeData && shapeData.shapes) { 11997 // document.body.appendChild is needed to get exact measure of shape 11998 document.body.appendChild(tCont); 11999 var boundingBox = tCont.getBBox(); 12000 tCont.setAttribute('width', boundingBox.width + 2); 12001 tCont.setAttribute('height', boundingBox.height + 2); 12002 tCont.setAttribute('viewBox', (boundingBox.x - 1) + ' ' + (boundingBox.y - 1) + ' ' + (boundingBox.width + 2) + ' ' + (boundingBox.height + 2)); 12003 var tContStyle = tCont.style; 12004 var tContTranslation = 'translate(' + (boundingBox.x - 1) + 'px,' + (boundingBox.y - 1) + 'px)'; 12005 tContStyle.transform = tContTranslation; 12006 tContStyle.webkitTransform = tContTranslation; 12007 12008 letters[i].yOffset = boundingBox.y - 1; 12009 } else { 12010 tCont.setAttribute('width', 1); 12011 tCont.setAttribute('height', 1); 12012 } 12013 tParent.appendChild(tCont); 12014 } else { 12015 this.innerElem.appendChild(tSpan); 12016 } 12017 } else { 12018 tSpan.textContent = letters[i].val; 12019 tSpan.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:space', 'preserve'); 12020 if (!this.isMasked) { 12021 this.innerElem.appendChild(tParent); 12022 // 12023 var tStyle = tSpan.style; 12024 var tSpanTranslation = 'translate3d(0,' + -documentData.finalSize / 1.2 + 'px,0)'; 12025 tStyle.transform = tSpanTranslation; 12026 tStyle.webkitTransform = tSpanTranslation; 12027 } else { 12028 this.innerElem.appendChild(tSpan); 12029 } 12030 } 12031 // 12032 if (!this.isMasked) { 12033 this.textSpans[cnt] = tParent; 12034 } else { 12035 this.textSpans[cnt] = tSpan; 12036 } 12037 this.textSpans[cnt].style.display = 'block'; 12038 this.textPaths[cnt] = tSpan; 12039 cnt += 1; 12040 } 12041 while (cnt < this.textSpans.length) { 12042 this.textSpans[cnt].style.display = 'none'; 12043 cnt += 1; 12044 } 12045}; 12046 12047HTextElement.prototype.renderInnerContent = function () { 12048 var svgStyle; 12049 if (this.data.singleShape) { 12050 if (!this._isFirstFrame && !this.lettersChangedFlag) { 12051 return; 12052 } if (this.isMasked && this.finalTransform._matMdf) { 12053 // Todo Benchmark if using this is better than getBBox 12054 this.svgElement.setAttribute('viewBox', -this.finalTransform.mProp.p.v[0] + ' ' + -this.finalTransform.mProp.p.v[1] + ' ' + this.compW + ' ' + this.compH); 12055 svgStyle = this.svgElement.style; 12056 var translation = 'translate(' + -this.finalTransform.mProp.p.v[0] + 'px,' + -this.finalTransform.mProp.p.v[1] + 'px)'; 12057 svgStyle.transform = translation; 12058 svgStyle.webkitTransform = translation; 12059 } 12060 } 12061 12062 this.textAnimator.getMeasures(this.textProperty.currentData, this.lettersChangedFlag); 12063 if (!this.lettersChangedFlag && !this.textAnimator.lettersChangedFlag) { 12064 return; 12065 } 12066 var i; 12067 var len; 12068 var count = 0; 12069 var renderedLetters = this.textAnimator.renderedLetters; 12070 12071 var letters = this.textProperty.currentData.l; 12072 12073 len = letters.length; 12074 var renderedLetter; 12075 var textSpan; 12076 var textPath; 12077 for (i = 0; i < len; i += 1) { 12078 if (letters[i].n) { 12079 count += 1; 12080 } else { 12081 textSpan = this.textSpans[i]; 12082 textPath = this.textPaths[i]; 12083 renderedLetter = renderedLetters[count]; 12084 count += 1; 12085 if (renderedLetter._mdf.m) { 12086 if (!this.isMasked) { 12087 textSpan.style.webkitTransform = renderedLetter.m; 12088 textSpan.style.transform = renderedLetter.m; 12089 } else { 12090 textSpan.setAttribute('transform', renderedLetter.m); 12091 } 12092 } 12093 /// /textSpan.setAttribute('opacity',renderedLetter.o); 12094 textSpan.style.opacity = renderedLetter.o; 12095 if (renderedLetter.sw && renderedLetter._mdf.sw) { 12096 textPath.setAttribute('stroke-width', renderedLetter.sw); 12097 } 12098 if (renderedLetter.sc && renderedLetter._mdf.sc) { 12099 textPath.setAttribute('stroke', renderedLetter.sc); 12100 } 12101 if (renderedLetter.fc && renderedLetter._mdf.fc) { 12102 textPath.setAttribute('fill', renderedLetter.fc); 12103 textPath.style.color = renderedLetter.fc; 12104 } 12105 } 12106 } 12107 12108 if (this.innerElem.getBBox && !this.hidden && (this._isFirstFrame || this._mdf)) { 12109 var boundingBox = this.innerElem.getBBox(); 12110
vendor: 13,297 bytes, lines 12111-12517
12111 if (this.currentBBox.w !== boundingBox.width) { 12112 this.currentBBox.w = boundingBox.width; 12113 this.svgElement.setAttribute('width', boundingBox.width); 12114 } 12115 if (this.currentBBox.h !== boundingBox.height) { 12116 this.currentBBox.h = boundingBox.height; 12117 this.svgElement.setAttribute('height', boundingBox.height); 12118 } 12119 12120 var margin = 1; 12121 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)) { 12122 this.currentBBox.w = boundingBox.width + margin * 2; 12123 this.currentBBox.h = boundingBox.height + margin * 2; 12124 this.currentBBox.x = boundingBox.x - margin; 12125 this.currentBBox.y = boundingBox.y - margin; 12126 12127 this.svgElement.setAttribute('viewBox', this.currentBBox.x + ' ' + this.currentBBox.y + ' ' + this.currentBBox.w + ' ' + this.currentBBox.h); 12128 svgStyle = this.svgElement.style; 12129 var svgTransform = 'translate(' + this.currentBBox.x + 'px,' + this.currentBBox.y + 'px)'; 12130 svgStyle.transform = svgTransform; 12131 svgStyle.webkitTransform = svgTransform; 12132 } 12133 } 12134}; 12135 12136/* global extendPrototype, BaseElement, TransformElement, HBaseElement, HSolidElement, HierarchyElement, 12137FrameElement, RenderableElement, createNS */ 12138 12139function HImageElement(data, globalData, comp) { 12140 this.assetData = globalData.getAssetData(data.refId); 12141 this.initElement(data, globalData, comp); 12142} 12143 12144extendPrototype([BaseElement, TransformElement, HBaseElement, HSolidElement, HierarchyElement, FrameElement, RenderableElement], HImageElement); 12145 12146HImageElement.prototype.createContent = function () { 12147 var assetPath = this.globalData.getAssetsPath(this.assetData); 12148 var img = new Image(); 12149 12150 if (this.data.hasMask) { 12151 this.imageElem = createNS('image'); 12152 this.imageElem.setAttribute('width', this.assetData.w + 'px'); 12153 this.imageElem.setAttribute('height', this.assetData.h + 'px'); 12154 this.imageElem.setAttributeNS('http://www.w3.org/1999/xlink', 'href', assetPath); 12155 this.layerElement.appendChild(this.imageElem); 12156 this.baseElement.setAttribute('width', this.assetData.w); 12157 this.baseElement.setAttribute('height', this.assetData.h); 12158 } else { 12159 this.layerElement.appendChild(img); 12160 } 12161 img.crossOrigin = 'anonymous'; 12162 img.src = assetPath; 12163 if (this.data.ln) { 12164 this.baseElement.setAttribute('id', this.data.ln); 12165 } 12166}; 12167 12168/* global PropertyFactory, degToRads, Matrix, extendPrototype, BaseElement, FrameElement, HierarchyElement */ 12169 12170function HCameraElement(data, globalData, comp) { 12171 this.initFrame(); 12172 this.initBaseData(data, globalData, comp); 12173 this.initHierarchy(); 12174 var getProp = PropertyFactory.getProp; 12175 this.pe = getProp(this, data.pe, 0, 0, this); 12176 if (data.ks.p.s) { 12177 this.px = getProp(this, data.ks.p.x, 1, 0, this); 12178 this.py = getProp(this, data.ks.p.y, 1, 0, this); 12179 this.pz = getProp(this, data.ks.p.z, 1, 0, this); 12180 } else { 12181 this.p = getProp(this, data.ks.p, 1, 0, this); 12182 } 12183 if (data.ks.a) { 12184 this.a = getProp(this, data.ks.a, 1, 0, this); 12185 } 12186 if (data.ks.or.k.length && data.ks.or.k[0].to) { 12187 var i; 12188 var len = data.ks.or.k.length; 12189 for (i = 0; i < len; i += 1) { 12190 data.ks.or.k[i].to = null; 12191 data.ks.or.k[i].ti = null; 12192 } 12193 } 12194 this.or = getProp(this, data.ks.or, 1, degToRads, this); 12195 this.or.sh = true; 12196 this.rx = getProp(this, data.ks.rx, 0, degToRads, this); 12197 this.ry = getProp(this, data.ks.ry, 0, degToRads, this); 12198 this.rz = getProp(this, data.ks.rz, 0, degToRads, this); 12199 this.mat = new Matrix(); 12200 this._prevMat = new Matrix(); 12201 this._isFirstFrame = true; 12202 12203 // TODO: find a better way to make the HCamera element to be compatible with the LayerInterface and TransformInterface. 12204 this.finalTransform = { 12205 mProp: this, 12206 }; 12207} 12208extendPrototype([BaseElement, FrameElement, HierarchyElement], HCameraElement); 12209 12210HCameraElement.prototype.setup = function () { 12211 var i; 12212 var len = this.comp.threeDElements.length; 12213 var comp; 12214 var perspectiveStyle; 12215 var containerStyle; 12216 for (i = 0; i < len; i += 1) { 12217 // [perspectiveElem,container] 12218 comp = this.comp.threeDElements[i]; 12219 if (comp.type === '3d') { 12220 perspectiveStyle = comp.perspectiveElem.style; 12221 containerStyle = comp.container.style; 12222 var perspective = this.pe.v + 'px'; 12223 var origin = '0px 0px 0px'; 12224 var matrix = 'matrix3d(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1)'; 12225 perspectiveStyle.perspective = perspective; 12226 perspectiveStyle.webkitPerspective = perspective; 12227 containerStyle.transformOrigin = origin; 12228 containerStyle.mozTransformOrigin = origin; 12229 containerStyle.webkitTransformOrigin = origin; 12230 perspectiveStyle.transform = matrix; 12231 perspectiveStyle.webkitTransform = matrix; 12232 } 12233 } 12234}; 12235 12236HCameraElement.prototype.createElements = function () { 12237}; 12238 12239HCameraElement.prototype.hide = function () { 12240}; 12241 12242HCameraElement.prototype.renderFrame = function () { 12243 var _mdf = this._isFirstFrame; 12244 var i; 12245 var len; 12246 if (this.hierarchy) { 12247 len = this.hierarchy.length; 12248 for (i = 0; i < len; i += 1) { 12249 _mdf = this.hierarchy[i].finalTransform.mProp._mdf || _mdf; 12250 } 12251 } 12252 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)) { 12253 this.mat.reset(); 12254 12255 if (this.hierarchy) { 12256 len = this.hierarchy.length - 1; 12257 for (i = len; i >= 0; i -= 1) { 12258 var mTransf = this.hierarchy[i].finalTransform.mProp; 12259 this.mat.translate(-mTransf.p.v[0], -mTransf.p.v[1], mTransf.p.v[2]); 12260 this.mat.rotateX(-mTransf.or.v[0]).rotateY(-mTransf.or.v[1]).rotateZ(mTransf.or.v[2]); 12261 this.mat.rotateX(-mTransf.rx.v).rotateY(-mTransf.ry.v).rotateZ(mTransf.rz.v); 12262 this.mat.scale(1 / mTransf.s.v[0], 1 / mTransf.s.v[1], 1 / mTransf.s.v[2]); 12263 this.mat.translate(mTransf.a.v[0], mTransf.a.v[1], mTransf.a.v[2]); 12264 } 12265 } 12266 if (this.p) { 12267 this.mat.translate(-this.p.v[0], -this.p.v[1], this.p.v[2]); 12268 } else { 12269 this.mat.translate(-this.px.v, -this.py.v, this.pz.v); 12270 } 12271 if (this.a) { 12272 var diffVector; 12273 if (this.p) { 12274 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]]; 12275 } else { 12276 diffVector = [this.px.v - this.a.v[0], this.py.v - this.a.v[1], this.pz.v - this.a.v[2]]; 12277 } 12278 var mag = Math.sqrt(Math.pow(diffVector[0], 2) + Math.pow(diffVector[1], 2) + Math.pow(diffVector[2], 2)); 12279 // var lookDir = getNormalizedPoint(getDiffVector(this.a.v,this.p.v)); 12280 var lookDir = [diffVector[0] / mag, diffVector[1] / mag, diffVector[2] / mag]; 12281 var lookLengthOnXZ = Math.sqrt(lookDir[2] * lookDir[2] + lookDir[0] * lookDir[0]); 12282 var mRotationX = (Math.atan2(lookDir[1], lookLengthOnXZ)); 12283 var mRotationY = (Math.atan2(lookDir[0], -lookDir[2])); 12284 this.mat.rotateY(mRotationY).rotateX(-mRotationX); 12285 } 12286 this.mat.rotateX(-this.rx.v).rotateY(-this.ry.v).rotateZ(this.rz.v); 12287 this.mat.rotateX(-this.or.v[0]).rotateY(-this.or.v[1]).rotateZ(this.or.v[2]); 12288 this.mat.translate(this.globalData.compSize.w / 2, this.globalData.compSize.h / 2, 0); 12289 this.mat.translate(0, 0, this.pe.v); 12290 12291 var hasMatrixChanged = !this._prevMat.equals(this.mat); 12292 if ((hasMatrixChanged || this.pe._mdf) && this.comp.threeDElements) { 12293 len = this.comp.threeDElements.length; 12294 var comp; 12295 var perspectiveStyle; 12296 var containerStyle; 12297 for (i = 0; i < len; i += 1) { 12298 comp = this.comp.threeDElements[i]; 12299 if (comp.type === '3d') { 12300 if (hasMatrixChanged) { 12301 var matValue = this.mat.toCSS(); 12302 containerStyle = comp.container.style; 12303 containerStyle.transform = matValue; 12304 containerStyle.webkitTransform = matValue; 12305 } 12306 if (this.pe._mdf) { 12307 perspectiveStyle = comp.perspectiveElem.style; 12308 perspectiveStyle.perspective = this.pe.v + 'px'; 12309 perspectiveStyle.webkitPerspective = this.pe.v + 'px'; 12310 } 12311 } 12312 } 12313 this.mat.clone(this._prevMat); 12314 } 12315 } 12316 this._isFirstFrame = false; 12317}; 12318 12319HCameraElement.prototype.prepareFrame = function (num) { 12320 this.prepareProperties(num, true); 12321}; 12322 12323HCameraElement.prototype.destroy = function () { 12324}; 12325HCameraElement.prototype.getBaseElement = function () { return null; }; 12326 12327function HEffects() { 12328} 12329HEffects.prototype.renderFrame = function () {}; 12330 12331/* global createTag, AnimationItem */ 12332/* exported animationManager */ 12333 12334var animationManager = (function () { 12335 var moduleOb = {}; 12336 var registeredAnimations = []; 12337 var initTime = 0; 12338 var len = 0; 12339 var playingAnimationsNum = 0; 12340 var _stopped = true; 12341 var _isFrozen = false; 12342 12343 function removeElement(ev) { 12344 var i = 0; 12345 var animItem = ev.target; 12346 while (i < len) { 12347 if (registeredAnimations[i].animation === animItem) { 12348 registeredAnimations.splice(i, 1); 12349 i -= 1; 12350 len -= 1; 12351 if (!animItem.isPaused) { 12352 subtractPlayingCount(); 12353 } 12354 } 12355 i += 1; 12356 } 12357 } 12358 12359 function registerAnimation(element, animationData) { 12360 if (!element) { 12361 return null; 12362 } 12363 var i = 0; 12364 while (i < len) { 12365 if (registeredAnimations[i].elem === element && registeredAnimations[i].elem !== null) { 12366 return registeredAnimations[i].animation; 12367 } 12368 i += 1; 12369 } 12370 var animItem = new AnimationItem(); 12371 setupAnimation(animItem, element); 12372 animItem.setData(element, animationData); 12373 return animItem; 12374 } 12375 12376 function getRegisteredAnimations() { 12377 var i; 12378 var lenAnims = registeredAnimations.length; 12379 var animations = []; 12380 for (i = 0; i < lenAnims; i += 1) { 12381 animations.push(registeredAnimations[i].animation); 12382 } 12383 return animations; 12384 } 12385 12386 function addPlayingCount() { 12387 playingAnimationsNum += 1; 12388 activate(); 12389 } 12390 12391 function subtractPlayingCount() { 12392 playingAnimationsNum -= 1; 12393 } 12394 12395 function setupAnimation(animItem, element) { 12396 animItem.addEventListener('destroy', removeElement); 12397 animItem.addEventListener('_active', addPlayingCount); 12398 animItem.addEventListener('_idle', subtractPlayingCount); 12399 registeredAnimations.push({ elem: element, animation: animItem }); 12400 len += 1; 12401 } 12402 12403 function loadAnimation(params) { 12404 var animItem = new AnimationItem(); 12405 setupAnimation(animItem, null); 12406 animItem.setParams(params); 12407 return animItem; 12408 } 12409 12410 function setSpeed(val, animation) { 12411 var i; 12412 for (i = 0; i < len; i += 1) { 12413 registeredAnimations[i].animation.setSpeed(val, animation); 12414 } 12415 } 12416 12417 function setDirection(val, animation) { 12418 var i; 12419 for (i = 0; i < len; i += 1) { 12420 registeredAnimations[i].animation.setDirection(val, animation); 12421 } 12422 } 12423 12424 function play(animation) { 12425 var i; 12426 for (i = 0; i < len; i += 1) { 12427 registeredAnimations[i].animation.play(animation); 12428 } 12429 } 12430 function resume(nowTime) { 12431 var elapsedTime = nowTime - initTime; 12432 var i; 12433 for (i = 0; i < len; i += 1) { 12434 registeredAnimations[i].animation.advanceTime(elapsedTime); 12435 } 12436 initTime = nowTime; 12437 if (playingAnimationsNum && !_isFrozen) { 12438 window.requestAnimationFrame(resume); 12439 } else { 12440 _stopped = true; 12441 } 12442 } 12443 12444 function first(nowTime) { 12445 initTime = nowTime; 12446 window.requestAnimationFrame(resume); 12447 } 12448 12449 function pause(animation) { 12450 var i; 12451 for (i = 0; i < len; i += 1) { 12452 registeredAnimations[i].animation.pause(animation); 12453 } 12454 } 12455 12456 function goToAndStop(value, isFrame, animation) { 12457 var i; 12458 for (i = 0; i < len; i += 1) { 12459 registeredAnimations[i].animation.goToAndStop(value, isFrame, animation); 12460 } 12461 } 12462 12463 function stop(animation) { 12464 var i; 12465 for (i = 0; i < len; i += 1) { 12466 registeredAnimations[i].animation.stop(animation); 12467 } 12468 } 12469 12470 function togglePause(animation) { 12471 var i; 12472 for (i = 0; i < len; i += 1) { 12473 registeredAnimations[i].animation.togglePause(animation); 12474 } 12475 } 12476 12477 function destroy(animation) { 12478 var i; 12479 for (i = (len - 1); i >= 0; i -= 1) { 12480 registeredAnimations[i].animation.destroy(animation); 12481 } 12482 } 12483 12484 function searchAnimations(animationData, standalone, renderer) { 12485 var animElements = [].concat([].slice.call(document.getElementsByClassName('lottie')), 12486 [].slice.call(document.getElementsByClassName('bodymovin'))); 12487 var i; 12488 var lenAnims = animElements.length; 12489 for (i = 0; i < lenAnims; i += 1) { 12490 if (renderer) { 12491 animElements[i].setAttribute('data-bm-type', renderer); 12492 } 12493 registerAnimation(animElements[i], animationData); 12494 } 12495 if (standalone && lenAnims === 0) { 12496 if (!renderer) { 12497 renderer = 'svg'; 12498 } 12499 var body = document.getElementsByTagName('body')[0]; 12500 body.innerText = ''; 12501 var div = createTag('div'); 12502 div.style.width = '100%'; 12503 div.style.height = '100%'; 12504 div.setAttribute('data-bm-type', renderer); 12505 body.appendChild(div); 12506 registerAnimation(div, animationData); 12507 } 12508 } 12509 12510 function resize() { 12511 var i; 12512 for (i = 0; i < len; i += 1) { 12513 registeredAnimations[i].animation.resize(); 12514 } 12515 } 12516 12517 function activate() {
vendor: 6,465 bytes, lines 12518-12707
12518 if (!_isFrozen && playingAnimationsNum) { 12519 if (_stopped) { 12520 window.requestAnimationFrame(first); 12521 _stopped = false; 12522 } 12523 } 12524 } 12525 12526 function freeze() { 12527 _isFrozen = true; 12528 } 12529 12530 function unfreeze() { 12531 _isFrozen = false; 12532 activate(); 12533 } 12534 12535 function setVolume(val, animation) { 12536 var i; 12537 for (i = 0; i < len; i += 1) { 12538 registeredAnimations[i].animation.setVolume(val, animation); 12539 } 12540 } 12541 12542 function mute(animation) { 12543 var i; 12544 for (i = 0; i < len; i += 1) { 12545 registeredAnimations[i].animation.mute(animation); 12546 } 12547 } 12548 12549 function unmute(animation) { 12550 var i; 12551 for (i = 0; i < len; i += 1) { 12552 registeredAnimations[i].animation.unmute(animation); 12553 } 12554 } 12555 12556 moduleOb.registerAnimation = registerAnimation; 12557 moduleOb.loadAnimation = loadAnimation; 12558 moduleOb.setSpeed = setSpeed; 12559 moduleOb.setDirection = setDirection; 12560 moduleOb.play = play; 12561 moduleOb.pause = pause; 12562 moduleOb.stop = stop; 12563 moduleOb.togglePause = togglePause; 12564 moduleOb.searchAnimations = searchAnimations; 12565 moduleOb.resize = resize; 12566 // moduleOb.start = start; 12567 moduleOb.goToAndStop = goToAndStop; 12568 moduleOb.destroy = destroy; 12569 moduleOb.freeze = freeze; 12570 moduleOb.unfreeze = unfreeze; 12571 moduleOb.setVolume = setVolume; 12572 moduleOb.mute = mute; 12573 moduleOb.unmute = unmute; 12574 moduleOb.getRegisteredAnimations = getRegisteredAnimations; 12575 return moduleOb; 12576}()); 12577 12578/* global createElementID, subframeEnabled, ProjectInterface, ImagePreloader, audioControllerFactory, extendPrototype, BaseEvent, 12579CanvasRenderer, SVGRenderer, HybridRenderer, assetLoader, dataManager, expressionsPlugin, BMEnterFrameEvent, BMCompleteLoopEvent, 12580BMCompleteEvent, BMSegmentStartEvent, BMDestroyEvent, BMEnterFrameEvent, BMCompleteLoopEvent, BMCompleteEvent, BMSegmentStartEvent, 12581BMDestroyEvent, BMRenderFrameErrorEvent, BMConfigErrorEvent, markerParser */ 12582 12583var AnimationItem = function () { 12584 this._cbs = []; 12585 this.name = ''; 12586 this.path = ''; 12587 this.isLoaded = false; 12588 this.currentFrame = 0; 12589 this.currentRawFrame = 0; 12590 this.firstFrame = 0; 12591 this.totalFrames = 0; 12592 this.frameRate = 0; 12593 this.frameMult = 0; 12594 this.playSpeed = 1; 12595 this.playDirection = 1; 12596 this.playCount = 0; 12597 this.animationData = {}; 12598 this.assets = []; 12599 this.isPaused = true; 12600 this.autoplay = false; 12601 this.loop = true; 12602 this.renderer = null; 12603 this.animationID = createElementID(); 12604 this.assetsPath = ''; 12605 this.timeCompleted = 0; 12606 this.segmentPos = 0; 12607 this.isSubframeEnabled = subframeEnabled; 12608 this.segments = []; 12609 this._idle = true; 12610 this._completedLoop = false; 12611 this.projectInterface = ProjectInterface(); 12612 this.imagePreloader = new ImagePreloader(); 12613 this.audioController = audioControllerFactory(); 12614 this.markers = []; 12615}; 12616 12617extendPrototype([BaseEvent], AnimationItem); 12618 12619AnimationItem.prototype.setParams = function (params) { 12620 if (params.wrapper || params.container) { 12621 this.wrapper = params.wrapper || params.container; 12622 } 12623 var animType = 'svg'; 12624 if (params.animType) { 12625 animType = params.animType; 12626 } else if (params.renderer) { 12627 animType = params.renderer; 12628 } 12629 switch (animType) { 12630 case 'canvas': 12631 this.renderer = new CanvasRenderer(this, params.rendererSettings); 12632 break; 12633 case 'svg': 12634 this.renderer = new SVGRenderer(this, params.rendererSettings); 12635 break; 12636 default: 12637 this.renderer = new HybridRenderer(this, params.rendererSettings); 12638 break; 12639 } 12640 this.imagePreloader.setCacheType(animType, this.renderer.globalData.defs); 12641 this.renderer.setProjectInterface(this.projectInterface); 12642 this.animType = animType; 12643 if (params.loop === '' 12644 || params.loop === null 12645 || params.loop === undefined 12646 || params.loop === true) { 12647 this.loop = true; 12648 } else if (params.loop === false) { 12649 this.loop = false; 12650 } else { 12651 this.loop = parseInt(params.loop, 10); 12652 } 12653 this.autoplay = 'autoplay' in params ? params.autoplay : true; 12654 this.name = params.name ? params.name : ''; 12655 this.autoloadSegments = Object.prototype.hasOwnProperty.call(params, 'autoloadSegments') ? params.autoloadSegments : true; 12656 this.assetsPath = params.assetsPath; 12657 this.initialSegment = params.initialSegment; 12658 if (params.audioFactory) { 12659 this.audioController.setAudioFactory(params.audioFactory); 12660 } 12661 if (params.animationData) { 12662 this.configAnimation(params.animationData); 12663 } else if (params.path) { 12664 if (params.path.lastIndexOf('\\') !== -1) { 12665 this.path = params.path.substr(0, params.path.lastIndexOf('\\') + 1); 12666 } else { 12667 this.path = params.path.substr(0, params.path.lastIndexOf('/') + 1); 12668 } 12669 this.fileName = params.path.substr(params.path.lastIndexOf('/') + 1); 12670 this.fileName = this.fileName.substr(0, this.fileName.lastIndexOf('.json')); 12671 12672 assetLoader.load(params.path, this.configAnimation.bind(this), function () { 12673 this.trigger('data_failed'); 12674 }.bind(this)); 12675 } 12676}; 12677 12678AnimationItem.prototype.setData = function (wrapper, animationData) { 12679 if (animationData) { 12680 if (typeof animationData !== 'object') { 12681 animationData = JSON.parse(animationData); 12682 } 12683 } 12684 var params = { 12685 wrapper: wrapper, 12686 animationData: animationData, 12687 }; 12688 var wrapperAttributes = wrapper.attributes; 12689 12690 params.path = wrapperAttributes.getNamedItem('data-animation-path') // eslint-disable-line no-nested-ternary 12691 ? wrapperAttributes.getNamedItem('data-animation-path').value 12692 : wrapperAttributes.getNamedItem('data-bm-path') // eslint-disable-line no-nested-ternary 12693 ? wrapperAttributes.getNamedItem('data-bm-path').value 12694 : wrapperAttributes.getNamedItem('bm-path') 12695 ? wrapperAttributes.getNamedItem('bm-path').value 12696 : ''; 12697 params.animType = wrapperAttributes.getNamedItem('data-anim-type') // eslint-disable-line no-nested-ternary 12698 ? wrapperAttributes.getNamedItem('data-anim-type').value 12699 : wrapperAttributes.getNamedItem('data-bm-type') // eslint-disable-line no-nested-ternary 12700 ? wrapperAttributes.getNamedItem('data-bm-type').value 12701 : wrapperAttributes.getNamedItem('bm-type') // eslint-disable-line no-nested-ternary 12702 ? wrapperAttributes.getNamedItem('bm-type').value 12703 : wrapperAttributes.getNamedItem('data-bm-renderer') // eslint-disable-line no-nested-ternary 12704 ? wrapperAttributes.getNamedItem('data-bm-renderer').value 12705 : wrapperAttributes.getNamedItem('bm-renderer') 12706 ? wrapperAttributes.getNamedItem('bm-renderer').value 12707 :
vendor: 2,122 bytes, lines 12707-12750
12707 'canvas'; 12708 12709 var loop = wrapperAttributes.getNamedItem('data-anim-loop') // eslint-disable-line no-nested-ternary 12710 ? wrapperAttributes.getNamedItem('data-anim-loop').value 12711 : wrapperAttributes.getNamedItem('data-bm-loop') // eslint-disable-line no-nested-ternary 12712 ? wrapperAttributes.getNamedItem('data-bm-loop').value 12713 : wrapperAttributes.getNamedItem('bm-loop') 12714 ? wrapperAttributes.getNamedItem('bm-loop').value 12715 : ''; 12716 if (loop === 'false') { 12717 params.loop = false; 12718 } else if (loop === 'true') { 12719 params.loop = true; 12720 } else if (loop !== '') { 12721 params.loop = parseInt(loop, 10); 12722 } 12723 var autoplay = wrapperAttributes.getNamedItem('data-anim-autoplay') // eslint-disable-line no-nested-ternary 12724 ? wrapperAttributes.getNamedItem('data-anim-autoplay').value 12725 : wrapperAttributes.getNamedItem('data-bm-autoplay') // eslint-disable-line no-nested-ternary 12726 ? wrapperAttributes.getNamedItem('data-bm-autoplay').value 12727 : wrapperAttributes.getNamedItem('bm-autoplay') 12728 ? wrapperAttributes.getNamedItem('bm-autoplay').value 12729 : true; 12730 params.autoplay = autoplay !== 'false'; 12731 12732 params.name = wrapperAttributes.getNamedItem('data-name') // eslint-disable-line no-nested-ternary 12733 ? wrapperAttributes.getNamedItem('data-name').value 12734 : wrapperAttributes.getNamedItem('data-bm-name') // eslint-disable-line no-nested-ternary 12735 ? wrapperAttributes.getNamedItem('data-bm-name').value 12736 : wrapperAttributes.getNamedItem('bm-name') 12737 ? wrapperAttributes.getNamedItem('bm-name').value 12738 : ''; 12739 var prerender = wrapperAttributes.getNamedItem('data-anim-prerender') // eslint-disable-line no-nested-ternary 12740 ? wrapperAttributes.getNamedItem('data-anim-prerender').value 12741 : wrapperAttributes.getNamedItem('data-bm-prerender') // eslint-disable-line no-nested-ternary 12742 ? wrapperAttributes.getNamedItem('data-bm-prerender').value 12743 : wrapperAttributes.getNamedItem('bm-prerender') 12744 ? wrapperAttributes.getNamedItem('bm-prerender').value 12745 : ''; 12746 12747 if (prerender === 'false') { 12748 params.prerender = false; 12749 } 12750
vendor: 9,582 bytes, lines 12750-13083
12750this.setParams(params); 12751}; 12752 12753AnimationItem.prototype.includeLayers = function (data) { 12754 if (data.op > this.animationData.op) { 12755 this.animationData.op = data.op; 12756 this.totalFrames = Math.floor(data.op - this.animationData.ip); 12757 } 12758 var layers = this.animationData.layers; 12759 var i; 12760 var len = layers.length; 12761 var newLayers = data.layers; 12762 var j; 12763 var jLen = newLayers.length; 12764 for (j = 0; j < jLen; j += 1) { 12765 i = 0; 12766 while (i < len) { 12767 if (layers[i].id === newLayers[j].id) { 12768 layers[i] = newLayers[j]; 12769 break; 12770 } 12771 i += 1; 12772 } 12773 } 12774 if (data.chars || data.fonts) { 12775 this.renderer.globalData.fontManager.addChars(data.chars); 12776 this.renderer.globalData.fontManager.addFonts(data.fonts, this.renderer.globalData.defs); 12777 } 12778 if (data.assets) { 12779 len = data.assets.length; 12780 for (i = 0; i < len; i += 1) { 12781 this.animationData.assets.push(data.assets[i]); 12782 } 12783 } 12784 this.animationData.__complete = false; 12785 dataManager.completeData(this.animationData, this.renderer.globalData.fontManager); 12786 this.renderer.includeLayers(data.layers); 12787 if (expressionsPlugin) { 12788 expressionsPlugin.initExpressions(this); 12789 } 12790 this.loadNextSegment(); 12791}; 12792 12793AnimationItem.prototype.loadNextSegment = function () { 12794 var segments = this.animationData.segments; 12795 if (!segments || segments.length === 0 || !this.autoloadSegments) { 12796 this.trigger('data_ready'); 12797 this.timeCompleted = this.totalFrames; 12798 return; 12799 } 12800 var segment = segments.shift(); 12801 this.timeCompleted = segment.time * this.frameRate; 12802 var segmentPath = this.path + this.fileName + '_' + this.segmentPos + '.json'; 12803 this.segmentPos += 1; 12804 assetLoader.load(segmentPath, this.includeLayers.bind(this), function () { 12805 this.trigger('data_failed'); 12806 }.bind(this)); 12807}; 12808 12809AnimationItem.prototype.loadSegments = function () { 12810 var segments = this.animationData.segments; 12811 if (!segments) { 12812 this.timeCompleted = this.totalFrames; 12813 } 12814 this.loadNextSegment(); 12815}; 12816 12817AnimationItem.prototype.imagesLoaded = function () { 12818 this.trigger('loaded_images'); 12819 this.checkLoaded(); 12820}; 12821 12822AnimationItem.prototype.preloadImages = function () { 12823 this.imagePreloader.setAssetsPath(this.assetsPath); 12824 this.imagePreloader.setPath(this.path); 12825 this.imagePreloader.loadAssets(this.animationData.assets, this.imagesLoaded.bind(this)); 12826}; 12827 12828AnimationItem.prototype.configAnimation = function (animData) { 12829 if (!this.renderer) { 12830 return; 12831 } 12832 try { 12833 this.animationData = animData; 12834 12835 if (this.initialSegment) { 12836 this.totalFrames = Math.floor(this.initialSegment[1] - this.initialSegment[0]); 12837 this.firstFrame = Math.round(this.initialSegment[0]); 12838 } else { 12839 this.totalFrames = Math.floor(this.animationData.op - this.animationData.ip); 12840 this.firstFrame = Math.round(this.animationData.ip); 12841 } 12842 this.renderer.configAnimation(animData); 12843 if (!animData.assets) { 12844 animData.assets = []; 12845 } 12846 12847 this.assets = this.animationData.assets; 12848 this.frameRate = this.animationData.fr; 12849 this.frameMult = this.animationData.fr / 1000; 12850 this.renderer.searchExtraCompositions(animData.assets); 12851 this.markers = markerParser(animData.markers || []); 12852 this.trigger('config_ready'); 12853 this.preloadImages(); 12854 this.loadSegments(); 12855 this.updaFrameModifier(); 12856 this.waitForFontsLoaded(); 12857 if (this.isPaused) { 12858 this.audioController.pause(); 12859 } 12860 } catch (error) { 12861 this.triggerConfigError(error); 12862 } 12863}; 12864 12865AnimationItem.prototype.waitForFontsLoaded = function () { 12866 if (!this.renderer) { 12867 return; 12868 } 12869 if (this.renderer.globalData.fontManager.isLoaded) { 12870 this.checkLoaded(); 12871 } else { 12872 setTimeout(this.waitForFontsLoaded.bind(this), 20); 12873 } 12874}; 12875 12876AnimationItem.prototype.checkLoaded = function () { 12877 if (!this.isLoaded 12878 && this.renderer.globalData.fontManager.isLoaded 12879 && (this.imagePreloader.loadedImages() || this.renderer.rendererType !== 'canvas') 12880 && (this.imagePreloader.loadedFootages()) 12881 ) { 12882 this.isLoaded = true; 12883 dataManager.completeData(this.animationData, this.renderer.globalData.fontManager); 12884 if (expressionsPlugin) { 12885 expressionsPlugin.initExpressions(this); 12886 } 12887 this.renderer.initItems(); 12888 setTimeout(function () { 12889 this.trigger('DOMLoaded'); 12890 }.bind(this), 0); 12891 this.gotoFrame(); 12892 if (this.autoplay) { 12893 this.play(); 12894 } 12895 } 12896}; 12897 12898AnimationItem.prototype.resize = function () { 12899 this.renderer.updateContainerSize(); 12900}; 12901 12902AnimationItem.prototype.setSubframe = function (flag) { 12903 this.isSubframeEnabled = !!flag; 12904}; 12905 12906AnimationItem.prototype.gotoFrame = function () { 12907 this.currentFrame = this.isSubframeEnabled ? this.currentRawFrame : ~~this.currentRawFrame; // eslint-disable-line no-bitwise 12908 12909 if (this.timeCompleted !== this.totalFrames && this.currentFrame > this.timeCompleted) { 12910 this.currentFrame = this.timeCompleted; 12911 } 12912 this.trigger('enterFrame'); 12913 this.renderFrame(); 12914}; 12915 12916AnimationItem.prototype.renderFrame = function () { 12917 if (this.isLoaded === false || !this.renderer) { 12918 return; 12919 } 12920 try { 12921 this.renderer.renderFrame(this.currentFrame + this.firstFrame); 12922 } catch (error) { 12923 this.triggerRenderFrameError(error); 12924 } 12925}; 12926 12927AnimationItem.prototype.play = function (name) { 12928 if (name && this.name !== name) { 12929 return; 12930 } 12931 if (this.isPaused === true) { 12932 this.isPaused = false; 12933 this.audioController.resume(); 12934 if (this._idle) { 12935 this._idle = false; 12936 this.trigger('_active'); 12937 } 12938 } 12939}; 12940 12941AnimationItem.prototype.pause = function (name) { 12942 if (name && this.name !== name) { 12943 return; 12944 } 12945 if (this.isPaused === false) { 12946 this.isPaused = true; 12947 this._idle = true; 12948 this.trigger('_idle'); 12949 this.audioController.pause(); 12950 } 12951}; 12952 12953AnimationItem.prototype.togglePause = function (name) { 12954 if (name && this.name !== name) { 12955 return; 12956 } 12957 if (this.isPaused === true) { 12958 this.play(); 12959 } else { 12960 this.pause(); 12961 } 12962}; 12963 12964AnimationItem.prototype.stop = function (name) { 12965 if (name && this.name !== name) { 12966 return; 12967 } 12968 this.pause(); 12969 this.playCount = 0; 12970 this._completedLoop = false; 12971 this.setCurrentRawFrameValue(0); 12972}; 12973 12974AnimationItem.prototype.getMarkerData = function (markerName) { 12975 var marker; 12976 for (var i = 0; i < this.markers.length; i += 1) { 12977 marker = this.markers[i]; 12978 if (marker.payload && marker.payload.name === markerName) { 12979 return marker; 12980 } 12981 } 12982 return null; 12983}; 12984 12985AnimationItem.prototype.goToAndStop = function (value, isFrame, name) { 12986 if (name && this.name !== name) { 12987 return; 12988 } 12989 var numValue = Number(value); 12990 if (isNaN(numValue)) { 12991 var marker = this.getMarkerData(value); 12992 if (marker) { 12993 this.goToAndStop(marker.time, true); 12994 } 12995 } else if (isFrame) { 12996 this.setCurrentRawFrameValue(value); 12997 } else { 12998 this.setCurrentRawFrameValue(value * this.frameModifier); 12999 } 13000 this.pause(); 13001}; 13002 13003AnimationItem.prototype.goToAndPlay = function (value, isFrame, name) { 13004 if (name && this.name !== name) { 13005 return; 13006 } 13007 var numValue = Number(value); 13008 if (isNaN(numValue)) { 13009 var marker = this.getMarkerData(value); 13010 if (marker) { 13011 if (!marker.duration) { 13012 this.goToAndStop(marker.time, true); 13013 } else { 13014 this.playSegments([marker.time, marker.time + marker.duration], true); 13015 } 13016 } 13017 } else { 13018 this.goToAndStop(numValue, isFrame, name); 13019 } 13020 this.play(); 13021}; 13022 13023AnimationItem.prototype.advanceTime = function (value) { 13024 if (this.isPaused === true || this.isLoaded === false) { 13025 return; 13026 } 13027 var nextValue = this.currentRawFrame + value * this.frameModifier; 13028 var _isComplete = false; 13029 // Checking if nextValue > totalFrames - 1 for addressing non looping and looping animations. 13030 // If animation won't loop, it should stop at totalFrames - 1. If it will loop it should complete the last frame and then loop. 13031 if (nextValue >= this.totalFrames - 1 && this.frameModifier > 0) { 13032 if (!this.loop || this.playCount === this.loop) { 13033 if (!this.checkSegments(nextValue > this.totalFrames ? nextValue % this.totalFrames : 0)) { 13034 _isComplete = true; 13035 nextValue = this.totalFrames - 1; 13036 } 13037 } else if (nextValue >= this.totalFrames) { 13038 this.playCount += 1; 13039 if (!this.checkSegments(nextValue % this.totalFrames)) { 13040 this.setCurrentRawFrameValue(nextValue % this.totalFrames); 13041 this._completedLoop = true; 13042 this.trigger('loopComplete'); 13043 } 13044 } else { 13045 this.setCurrentRawFrameValue(nextValue); 13046 } 13047 } else if (nextValue < 0) { 13048 if (!this.checkSegments(nextValue % this.totalFrames)) { 13049 if (this.loop && !(this.playCount-- <= 0 && this.loop !== true)) { // eslint-disable-line no-plusplus 13050 this.setCurrentRawFrameValue(this.totalFrames + (nextValue % this.totalFrames)); 13051 if (!this._completedLoop) { 13052 this._completedLoop = true; 13053 } else { 13054 this.trigger('loopComplete'); 13055 } 13056 } else { 13057 _isComplete = true; 13058 nextValue = 0; 13059 } 13060 } 13061 } else { 13062 this.setCurrentRawFrameValue(nextValue); 13063 } 13064 if (_isComplete) { 13065 this.setCurrentRawFrameValue(nextValue); 13066 this.pause(); 13067 this.trigger('complete'); 13068 } 13069}; 13070 13071AnimationItem.prototype.adjustSegment = function (arr, offset) { 13072 this.playCount = 0; 13073 if (arr[1] < arr[0]) { 13074 if (this.frameModifier > 0) { 13075 if (this.playSpeed < 0) { 13076 this.setSpeed(-this.playSpeed); 13077 } else { 13078 this.setDirection(-1); 13079 } 13080 } 13081 this.totalFrames = arr[0] - arr[1]; 13082 this.timeCompleted = this.totalFrames; 13083 this.firstFrame = arr[1];
vendor: 49,847 bytes, lines 13084-14734
13084 this.setCurrentRawFrameValue(this.totalFrames - 0.001 - offset); 13085 } else if (arr[1] > arr[0]) { 13086 if (this.frameModifier < 0) { 13087 if (this.playSpeed < 0) { 13088 this.setSpeed(-this.playSpeed); 13089 } else { 13090 this.setDirection(1); 13091 } 13092 } 13093 this.totalFrames = arr[1] - arr[0]; 13094 this.timeCompleted = this.totalFrames; 13095 this.firstFrame = arr[0]; 13096 this.setCurrentRawFrameValue(0.001 + offset); 13097 } 13098 this.trigger('segmentStart'); 13099}; 13100AnimationItem.prototype.setSegment = function (init, end) { 13101 var pendingFrame = -1; 13102 if (this.isPaused) { 13103 if (this.currentRawFrame + this.firstFrame < init) { 13104 pendingFrame = init; 13105 } else if (this.currentRawFrame + this.firstFrame > end) { 13106 pendingFrame = end - init; 13107 } 13108 } 13109 13110 this.firstFrame = init; 13111 this.totalFrames = end - init; 13112 this.timeCompleted = this.totalFrames; 13113 if (pendingFrame !== -1) { 13114 this.goToAndStop(pendingFrame, true); 13115 } 13116}; 13117 13118AnimationItem.prototype.playSegments = function (arr, forceFlag) { 13119 if (forceFlag) { 13120 this.segments.length = 0; 13121 } 13122 if (typeof arr[0] === 'object') { 13123 var i; 13124 var len = arr.length; 13125 for (i = 0; i < len; i += 1) { 13126 this.segments.push(arr[i]); 13127 } 13128 } else { 13129 this.segments.push(arr); 13130 } 13131 if (this.segments.length && forceFlag) { 13132 this.adjustSegment(this.segments.shift(), 0); 13133 } 13134 if (this.isPaused) { 13135 this.play(); 13136 } 13137}; 13138 13139AnimationItem.prototype.resetSegments = function (forceFlag) { 13140 this.segments.length = 0; 13141 this.segments.push([this.animationData.ip, this.animationData.op]); 13142 // this.segments.push([this.animationData.ip*this.frameRate,Math.floor(this.animationData.op - this.animationData.ip+this.animationData.ip*this.frameRate)]); 13143 if (forceFlag) { 13144 this.checkSegments(0); 13145 } 13146}; 13147AnimationItem.prototype.checkSegments = function (offset) { 13148 if (this.segments.length) { 13149 this.adjustSegment(this.segments.shift(), offset); 13150 return true; 13151 } 13152 return false; 13153}; 13154 13155AnimationItem.prototype.destroy = function (name) { 13156 if ((name && this.name !== name) || !this.renderer) { 13157 return; 13158 } 13159 this.renderer.destroy(); 13160 this.imagePreloader.destroy(); 13161 this.trigger('destroy'); 13162 this._cbs = null; 13163 this.onEnterFrame = null; 13164 this.onLoopComplete = null; 13165 this.onComplete = null; 13166 this.onSegmentStart = null; 13167 this.onDestroy = null; 13168 this.renderer = null; 13169 this.renderer = null; 13170 this.imagePreloader = null; 13171 this.projectInterface = null; 13172}; 13173 13174AnimationItem.prototype.setCurrentRawFrameValue = function (value) { 13175 this.currentRawFrame = value; 13176 this.gotoFrame(); 13177}; 13178 13179AnimationItem.prototype.setSpeed = function (val) { 13180 this.playSpeed = val; 13181 this.updaFrameModifier(); 13182}; 13183 13184AnimationItem.prototype.setDirection = function (val) { 13185 this.playDirection = val < 0 ? -1 : 1; 13186 this.updaFrameModifier(); 13187}; 13188 13189AnimationItem.prototype.setVolume = function (val, name) { 13190 if (name && this.name !== name) { 13191 return; 13192 } 13193 this.audioController.setVolume(val); 13194}; 13195 13196AnimationItem.prototype.getVolume = function () { 13197 return this.audioController.getVolume(); 13198}; 13199 13200AnimationItem.prototype.mute = function (name) { 13201 if (name && this.name !== name) { 13202 return; 13203 } 13204 this.audioController.mute(); 13205}; 13206 13207AnimationItem.prototype.unmute = function (name) { 13208 if (name && this.name !== name) { 13209 return; 13210 } 13211 this.audioController.unmute(); 13212}; 13213 13214AnimationItem.prototype.updaFrameModifier = function () { 13215 this.frameModifier = this.frameMult * this.playSpeed * this.playDirection; 13216 this.audioController.setRate(this.playSpeed * this.playDirection); 13217}; 13218 13219AnimationItem.prototype.getPath = function () { 13220 return this.path; 13221}; 13222 13223AnimationItem.prototype.getAssetsPath = function (assetData) { 13224 var path = ''; 13225 if (assetData.e) { 13226 path = assetData.p; 13227 } else if (this.assetsPath) { 13228 var imagePath = assetData.p; 13229 if (imagePath.indexOf('images/') !== -1) { 13230 imagePath = imagePath.split('/')[1]; 13231 } 13232 path = this.assetsPath + imagePath; 13233 } else { 13234 path = this.path; 13235 path += assetData.u ? assetData.u : ''; 13236 path += assetData.p; 13237 } 13238 return path; 13239}; 13240 13241AnimationItem.prototype.getAssetData = function (id) { 13242 var i = 0; 13243 var len = this.assets.length; 13244 while (i < len) { 13245 if (id === this.assets[i].id) { 13246 return this.assets[i]; 13247 } 13248 i += 1; 13249 } 13250 return null; 13251}; 13252 13253AnimationItem.prototype.hide = function () { 13254 this.renderer.hide(); 13255}; 13256 13257AnimationItem.prototype.show = function () { 13258 this.renderer.show(); 13259}; 13260 13261AnimationItem.prototype.getDuration = function (isFrame) { 13262 return isFrame ? this.totalFrames : this.totalFrames / this.frameRate; 13263}; 13264 13265AnimationItem.prototype.trigger = function (name) { 13266 if (this._cbs && this._cbs[name]) { 13267 switch (name) { 13268 case 'enterFrame': 13269 this.triggerEvent(name, new BMEnterFrameEvent(name, this.currentFrame, this.totalFrames, this.frameModifier)); 13270 break; 13271 case 'loopComplete': 13272 this.triggerEvent(name, new BMCompleteLoopEvent(name, this.loop, this.playCount, this.frameMult)); 13273 break; 13274 case 'complete': 13275 this.triggerEvent(name, new BMCompleteEvent(name, this.frameMult)); 13276 break; 13277 case 'segmentStart': 13278 this.triggerEvent(name, new BMSegmentStartEvent(name, this.firstFrame, this.totalFrames)); 13279 break; 13280 case 'destroy': 13281 this.triggerEvent(name, new BMDestroyEvent(name, this)); 13282 break; 13283 default: 13284 this.triggerEvent(name); 13285 } 13286 } 13287 if (name === 'enterFrame' && this.onEnterFrame) { 13288 this.onEnterFrame.call(this, new BMEnterFrameEvent(name, this.currentFrame, this.totalFrames, this.frameMult)); 13289 } 13290 if (name === 'loopComplete' && this.onLoopComplete) { 13291 this.onLoopComplete.call(this, new BMCompleteLoopEvent(name, this.loop, this.playCount, this.frameMult)); 13292 } 13293 if (name === 'complete' && this.onComplete) { 13294 this.onComplete.call(this, new BMCompleteEvent(name, this.frameMult)); 13295 } 13296 if (name === 'segmentStart' && this.onSegmentStart) { 13297 this.onSegmentStart.call(this, new BMSegmentStartEvent(name, this.firstFrame, this.totalFrames)); 13298 } 13299 if (name === 'destroy' && this.onDestroy) { 13300 this.onDestroy.call(this, new BMDestroyEvent(name, this)); 13301 } 13302}; 13303 13304AnimationItem.prototype.triggerRenderFrameError = function (nativeError) { 13305 var error = new BMRenderFrameErrorEvent(nativeError, this.currentFrame); 13306 this.triggerEvent('error', error); 13307 13308 if (this.onError) { 13309 this.onError.call(this, error); 13310 } 13311}; 13312 13313AnimationItem.prototype.triggerConfigError = function (nativeError) { 13314 var error = new BMConfigErrorEvent(nativeError, this.currentFrame); 13315 this.triggerEvent('error', error); 13316 13317 if (this.onError) { 13318 this.onError.call(this, error); 13319 } 13320}; 13321 13322/* global CompExpressionInterface, expressionsPlugin: writable */ 13323/* exported expressionsPlugin */ 13324 13325var Expressions = (function () { 13326 var ob = {}; 13327 ob.initExpressions = initExpressions; 13328 13329 function initExpressions(animation) { 13330 var stackCount = 0; 13331 var registers = []; 13332 13333 function pushExpression() { 13334 stackCount += 1; 13335 } 13336 13337 function popExpression() { 13338 stackCount -= 1; 13339 if (stackCount === 0) { 13340 releaseInstances(); 13341 } 13342 } 13343 13344 function registerExpressionProperty(expression) { 13345 if (registers.indexOf(expression) === -1) { 13346 registers.push(expression); 13347 } 13348 } 13349 13350 function releaseInstances() { 13351 var i; 13352 var len = registers.length; 13353 for (i = 0; i < len; i += 1) { 13354 registers[i].release(); 13355 } 13356 registers.length = 0; 13357 } 13358 13359 animation.renderer.compInterface = CompExpressionInterface(animation.renderer); 13360 animation.renderer.globalData.projectInterface.registerComposition(animation.renderer); 13361 animation.renderer.globalData.pushExpression = pushExpression; 13362 animation.renderer.globalData.popExpression = popExpression; 13363 animation.renderer.globalData.registerExpressionProperty = registerExpressionProperty; 13364 } 13365 return ob; 13366}()); 13367 13368expressionsPlugin = Expressions; 13369 13370/* eslint-disable camelcase, no-unused-vars */ 13371/* global BMMath, BezierFactory, createTypedArray, degToRads, shapePool */ 13372 13373var ExpressionManager = (function () { 13374 'use strict'; 13375 13376 var ob = {}; 13377 var Math = BMMath; 13378 var window = null; 13379 var document = null; 13380 var XMLHttpRequest = null; 13381 var fetch = null; 13382 13383 function $bm_isInstanceOfArray(arr) { 13384 return arr.constructor === Array || arr.constructor === Float32Array; 13385 } 13386 13387 function isNumerable(tOfV, v) { 13388 return tOfV === 'number' || tOfV === 'boolean' || tOfV === 'string' || v instanceof Number; 13389 } 13390 13391 function $bm_neg(a) { 13392 var tOfA = typeof a; 13393 if (tOfA === 'number' || tOfA === 'boolean' || a instanceof Number) { 13394 return -a; 13395 } 13396 if ($bm_isInstanceOfArray(a)) { 13397 var i; 13398 var lenA = a.length; 13399 var retArr = []; 13400 for (i = 0; i < lenA; i += 1) { 13401 retArr[i] = -a[i]; 13402 } 13403 return retArr; 13404 } 13405 if (a.propType) { 13406 return a.v; 13407 } 13408 return -a; 13409 } 13410 13411 var easeInBez = BezierFactory.getBezierEasing(0.333, 0, 0.833, 0.833, 'easeIn').get; 13412 var easeOutBez = BezierFactory.getBezierEasing(0.167, 0.167, 0.667, 1, 'easeOut').get; 13413 var easeInOutBez = BezierFactory.getBezierEasing(0.33, 0, 0.667, 1, 'easeInOut').get; 13414 13415 function sum(a, b) { 13416 var tOfA = typeof a; 13417 var tOfB = typeof b; 13418 if (tOfA === 'string' || tOfB === 'string') { 13419 return a + b; 13420 } 13421 if (isNumerable(tOfA, a) && isNumerable(tOfB, b)) { 13422 return a + b; 13423 } 13424 if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) { 13425 a = a.slice(0); 13426 a[0] += b; 13427 return a; 13428 } 13429 if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) { 13430 b = b.slice(0); 13431 b[0] = a + b[0]; 13432 return b; 13433 } 13434 if ($bm_isInstanceOfArray(a) && $bm_isInstanceOfArray(b)) { 13435 var i = 0; 13436 var lenA = a.length; 13437 var lenB = b.length; 13438 var retArr = []; 13439 while (i < lenA || i < lenB) { 13440 if ((typeof a[i] === 'number' || a[i] instanceof Number) && (typeof b[i] === 'number' || b[i] instanceof Number)) { 13441 retArr[i] = a[i] + b[i]; 13442 } else { 13443 retArr[i] = b[i] === undefined ? a[i] : a[i] || b[i]; 13444 } 13445 i += 1; 13446 } 13447 return retArr; 13448 } 13449 return 0; 13450 } 13451 var add = sum; 13452 13453 function sub(a, b) { 13454 var tOfA = typeof a; 13455 var tOfB = typeof b; 13456 if (isNumerable(tOfA, a) && isNumerable(tOfB, b)) { 13457 if (tOfA === 'string') { 13458 a = parseInt(a, 10); 13459 } 13460 if (tOfB === 'string') { 13461 b = parseInt(b, 10); 13462 } 13463 return a - b; 13464 } 13465 if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) { 13466 a = a.slice(0); 13467 a[0] -= b; 13468 return a; 13469 } 13470 if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) { 13471 b = b.slice(0); 13472 b[0] = a - b[0]; 13473 return b; 13474 } 13475 if ($bm_isInstanceOfArray(a) && $bm_isInstanceOfArray(b)) { 13476 var i = 0; 13477 var lenA = a.length; 13478 var lenB = b.length; 13479 var retArr = []; 13480 while (i < lenA || i < lenB) { 13481 if ((typeof a[i] === 'number' || a[i] instanceof Number) && (typeof b[i] === 'number' || b[i] instanceof Number)) { 13482 retArr[i] = a[i] - b[i]; 13483 } else { 13484 retArr[i] = b[i] === undefined ? a[i] : a[i] || b[i]; 13485 } 13486 i += 1; 13487 } 13488 return retArr; 13489 } 13490 return 0; 13491 } 13492 13493 function mul(a, b) { 13494 var tOfA = typeof a; 13495 var tOfB = typeof b; 13496 var arr; 13497 if (isNumerable(tOfA, a) && isNumerable(tOfB, b)) { 13498 return a * b; 13499 } 13500 13501 var i; 13502 var len; 13503 if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) { 13504 len = a.length; 13505 arr = createTypedArray('float32', len); 13506 for (i = 0; i < len; i += 1) { 13507 arr[i] = a[i] * b; 13508 } 13509 return arr; 13510 } 13511 if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) { 13512 len = b.length; 13513 arr = createTypedArray('float32', len); 13514 for (i = 0; i < len; i += 1) { 13515 arr[i] = a * b[i]; 13516 } 13517 return arr; 13518 } 13519 return 0; 13520 } 13521 13522 function div(a, b) { 13523 var tOfA = typeof a; 13524 var tOfB = typeof b; 13525 var arr; 13526 if (isNumerable(tOfA, a) && isNumerable(tOfB, b)) { 13527 return a / b; 13528 } 13529 var i; 13530 var len; 13531 if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) { 13532 len = a.length; 13533 arr = createTypedArray('float32', len); 13534 for (i = 0; i < len; i += 1) { 13535 arr[i] = a[i] / b; 13536 } 13537 return arr; 13538 } 13539 if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) { 13540 len = b.length; 13541 arr = createTypedArray('float32', len); 13542 for (i = 0; i < len; i += 1) { 13543 arr[i] = a / b[i]; 13544 } 13545 return arr; 13546 } 13547 return 0; 13548 } 13549 function mod(a, b) { 13550 if (typeof a === 'string') { 13551 a = parseInt(a, 10); 13552 } 13553 if (typeof b === 'string') { 13554 b = parseInt(b, 10); 13555 } 13556 return a % b; 13557 } 13558 var $bm_sum = sum; 13559 var $bm_sub = sub; 13560 var $bm_mul = mul; 13561 var $bm_div = div; 13562 var $bm_mod = mod; 13563 13564 function clamp(num, min, max) { 13565 if (min > max) { 13566 var mm = max; 13567 max = min; 13568 min = mm; 13569 } 13570 return Math.min(Math.max(num, min), max); 13571 } 13572 13573 function radiansToDegrees(val) { 13574 return val / degToRads; 13575 } 13576 var radians_to_degrees = radiansToDegrees; 13577 13578 function degreesToRadians(val) { 13579 return val * degToRads; 13580 } 13581 var degrees_to_radians = radiansToDegrees; 13582 13583 var helperLengthArray = [0, 0, 0, 0, 0, 0]; 13584 13585 function length(arr1, arr2) { 13586 if (typeof arr1 === 'number' || arr1 instanceof Number) { 13587 arr2 = arr2 || 0; 13588 return Math.abs(arr1 - arr2); 13589 } 13590 if (!arr2) { 13591 arr2 = helperLengthArray; 13592 } 13593 var i; 13594 var len = Math.min(arr1.length, arr2.length); 13595 var addedLength = 0; 13596 for (i = 0; i < len; i += 1) { 13597 addedLength += Math.pow(arr2[i] - arr1[i], 2); 13598 } 13599 return Math.sqrt(addedLength); 13600 } 13601 13602 function normalize(vec) { 13603 return div(vec, length(vec)); 13604 } 13605 13606 function rgbToHsl(val) { 13607 var r = val[0]; var g = val[1]; var b = val[2]; 13608 var max = Math.max(r, g, b); 13609 var min = Math.min(r, g, b); 13610 var h; 13611 var s; 13612 var l = (max + min) / 2; 13613 13614 if (max === min) { 13615 h = 0; // achromatic 13616 s = 0; // achromatic 13617 } else { 13618 var d = max - min; 13619 s = l > 0.5 ? d / (2 - max - min) : d / (max + min); 13620 switch (max) { 13621 case r: h = (g - b) / d + (g < b ? 6 : 0); break; 13622 case g: h = (b - r) / d + 2; break; 13623 case b: h = (r - g) / d + 4; break; 13624 default: break; 13625 } 13626 h /= 6; 13627 } 13628 13629 return [h, s, l, val[3]]; 13630 } 13631 13632 function hue2rgb(p, q, t) { 13633 if (t < 0) t += 1; 13634 if (t > 1) t -= 1; 13635 if (t < 1 / 6) return p + (q - p) * 6 * t; 13636 if (t < 1 / 2) return q; 13637 if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6; 13638 return p; 13639 } 13640 13641 function hslToRgb(val) { 13642 var h = val[0]; 13643 var s = val[1]; 13644 var l = val[2]; 13645 13646 var r; 13647 var g; 13648 var b; 13649 13650 if (s === 0) { 13651 r = l; // achromatic 13652 b = l; // achromatic 13653 g = l; // achromatic 13654 } else { 13655 var q = l < 0.5 ? l * (1 + s) : l + s - l * s; 13656 var p = 2 * l - q; 13657 r = hue2rgb(p, q, h + 1 / 3); 13658 g = hue2rgb(p, q, h); 13659 b = hue2rgb(p, q, h - 1 / 3); 13660 } 13661 13662 return [r, g, b, val[3]]; 13663 } 13664 13665 function linear(t, tMin, tMax, value1, value2) { 13666 if (value1 === undefined || value2 === undefined) { 13667 value1 = tMin; 13668 value2 = tMax; 13669 tMin = 0; 13670 tMax = 1; 13671 } 13672 if (tMax < tMin) { 13673 var _tMin = tMax; 13674 tMax = tMin; 13675 tMin = _tMin; 13676 } 13677 if (t <= tMin) { 13678 return value1; 13679 } if (t >= tMax) { 13680 return value2; 13681 } 13682 var perc = tMax === tMin ? 0 : (t - tMin) / (tMax - tMin); 13683 if (!value1.length) { 13684 return value1 + (value2 - value1) * perc; 13685 } 13686 var i; 13687 var len = value1.length; 13688 var arr = createTypedArray('float32', len); 13689 for (i = 0; i < len; i += 1) { 13690 arr[i] = value1[i] + (value2[i] - value1[i]) * perc; 13691 } 13692 return arr; 13693 } 13694 function random(min, max) { 13695 if (max === undefined) { 13696 if (min === undefined) { 13697 min = 0; 13698 max = 1; 13699 } else { 13700 max = min; 13701 min = undefined; 13702 } 13703 } 13704 if (max.length) { 13705 var i; 13706 var len = max.length; 13707 if (!min) { 13708 min = createTypedArray('float32', len); 13709 } 13710 var arr = createTypedArray('float32', len); 13711 var rnd = BMMath.random(); 13712 for (i = 0; i < len; i += 1) { 13713 arr[i] = min[i] + rnd * (max[i] - min[i]); 13714 } 13715 return arr; 13716 } 13717 if (min === undefined) { 13718 min = 0; 13719 } 13720 var rndm = BMMath.random(); 13721 return min + rndm * (max - min); 13722 } 13723 13724 function createPath(points, inTangents, outTangents, closed) { 13725 var i; 13726 var len = points.length; 13727 var path = shapePool.newElement(); 13728 path.setPathData(!!closed, len); 13729 var arrPlaceholder = [0, 0]; 13730 var inVertexPoint; 13731 var outVertexPoint; 13732 for (i = 0; i < len; i += 1) { 13733 inVertexPoint = (inTangents && inTangents[i]) ? inTangents[i] : arrPlaceholder; 13734 outVertexPoint = (outTangents && outTangents[i]) ? outTangents[i] : arrPlaceholder; 13735 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); 13736 } 13737 return path; 13738 } 13739 13740 function initiateExpression(elem, data, property) { 13741 var val = data.x; 13742 var needsVelocity = /velocity(?![\w\d])/.test(val); 13743 var _needsRandom = val.indexOf('random') !== -1; 13744 var elemType = elem.data.ty; 13745 var transform; 13746 var $bm_transform; 13747 var content; 13748 var effect; 13749 var thisProperty = property; 13750 thisProperty.valueAtTime = thisProperty.getValueAtTime; 13751 Object.defineProperty(thisProperty, 'value', { 13752 get: function () { 13753 return thisProperty.v; 13754 }, 13755 }); 13756 elem.comp.frameDuration = 1 / elem.comp.globalData.frameRate; 13757 elem.comp.displayStartTime = 0; 13758 var inPoint = elem.data.ip / elem.comp.globalData.frameRate; 13759 var outPoint = elem.data.op / elem.comp.globalData.frameRate; 13760 var width = elem.data.sw ? elem.data.sw : 0; 13761 var height = elem.data.sh ? elem.data.sh : 0; 13762 var name = elem.data.nm; 13763 var loopIn; 13764 var loop_in; 13765 var loopOut; 13766 var loop_out; 13767 var smooth; 13768 var toWorld; 13769 var fromWorld; 13770 var fromComp; 13771 var toComp; 13772 var fromCompToSurface; 13773 var position; 13774 var rotation; 13775 var anchorPoint; 13776 var scale; 13777 var thisLayer; 13778 var thisComp; 13779 var mask; 13780 var valueAtTime; 13781 var velocityAtTime; 13782 13783 var scoped_bm_rt; 13784 // val = val.replace(/(\\?"|')((http)(s)?(:\/))?\/.*?(\\?"|')/g, "\"\""); // deter potential network calls 13785 var expression_function = eval('[function _expression_function(){' + val + ';scoped_bm_rt=$bm_rt}]')[0]; // eslint-disable-line no-eval 13786 var numKeys = property.kf ? data.k.length : 0; 13787 13788 var active = !this.data || this.data.hd !== true; 13789 13790 var wiggle = function wiggle(freq, amp) { 13791 var iWiggle; 13792 var j; 13793 var lenWiggle = this.pv.length ? this.pv.length : 1; 13794 var addedAmps = createTypedArray('float32', lenWiggle); 13795 freq = 5; 13796 var iterations = Math.floor(time * freq); 13797 iWiggle = 0; 13798 j = 0; 13799 while (iWiggle < iterations) { 13800 // var rnd = BMMath.random(); 13801 for (j = 0; j < lenWiggle; j += 1) { 13802 addedAmps[j] += -amp + amp * 2 * BMMath.random(); 13803 // addedAmps[j] += -amp + amp*2*rnd; 13804 } 13805 iWiggle += 1; 13806 } 13807 // var rnd2 = BMMath.random(); 13808 var periods = time * freq; 13809 var perc = periods - Math.floor(periods); 13810 var arr = createTypedArray('float32', lenWiggle); 13811 if (lenWiggle > 1) { 13812 for (j = 0; j < lenWiggle; j += 1) { 13813 arr[j] = this.pv[j] + addedAmps[j] + (-amp + amp * 2 * BMMath.random()) * perc; 13814 // arr[j] = this.pv[j] + addedAmps[j] + (-amp + amp*2*rnd)*perc; 13815 // arr[i] = this.pv[i] + addedAmp + amp1*perc + amp2*(1-perc); 13816 } 13817 return arr; 13818 } 13819 return this.pv + addedAmps[0] + (-amp + amp * 2 * BMMath.random()) * perc; 13820 }.bind(this); 13821 13822 if (thisProperty.loopIn) { 13823 loopIn = thisProperty.loopIn.bind(thisProperty); 13824 loop_in = loopIn; 13825 } 13826 13827 if (thisProperty.loopOut) { 13828 loopOut = thisProperty.loopOut.bind(thisProperty); 13829 loop_out = loopOut; 13830 } 13831 13832 if (thisProperty.smooth) { 13833 smooth = thisProperty.smooth.bind(thisProperty); 13834 } 13835 13836 function loopInDuration(type, duration) { 13837 return loopIn(type, duration, true); 13838 } 13839 13840 function loopOutDuration(type, duration) { 13841 return loopOut(type, duration, true); 13842 } 13843 13844 if (this.getValueAtTime) { 13845 valueAtTime = this.getValueAtTime.bind(this); 13846 } 13847 13848 if (this.getVelocityAtTime) { 13849 velocityAtTime = this.getVelocityAtTime.bind(this); 13850 } 13851 13852 var comp = elem.comp.globalData.projectInterface.bind(elem.comp.globalData.projectInterface); 13853 13854 function lookAt(elem1, elem2) { 13855 var fVec = [elem2[0] - elem1[0], elem2[1] - elem1[1], elem2[2] - elem1[2]]; 13856 var pitch = Math.atan2(fVec[0], Math.sqrt(fVec[1] * fVec[1] + fVec[2] * fVec[2])) / degToRads; 13857 var yaw = -Math.atan2(fVec[1], fVec[2]) / degToRads; 13858 return [yaw, pitch, 0]; 13859 } 13860 13861 function easeOut(t, tMin, tMax, val1, val2) { 13862 return applyEase(easeOutBez, t, tMin, tMax, val1, val2); 13863 } 13864 13865 function easeIn(t, tMin, tMax, val1, val2) { 13866 return applyEase(easeInBez, t, tMin, tMax, val1, val2); 13867 } 13868 13869 function ease(t, tMin, tMax, val1, val2) { 13870 return applyEase(easeInOutBez, t, tMin, tMax, val1, val2); 13871 } 13872 13873 function applyEase(fn, t, tMin, tMax, val1, val2) { 13874 if (val1 === undefined) { 13875 val1 = tMin; 13876 val2 = tMax; 13877 } else { 13878 t = (t - tMin) / (tMax - tMin); 13879 } 13880 if (t > 1) { 13881 t = 1; 13882 } else if (t < 0) { 13883 t = 0; 13884 } 13885 var mult = fn(t); 13886 if ($bm_isInstanceOfArray(val1)) { 13887 var iKey; 13888 var lenKey = val1.length; 13889 var arr = createTypedArray('float32', lenKey); 13890 for (iKey = 0; iKey < lenKey; iKey += 1) { 13891 arr[iKey] = (val2[iKey] - val1[iKey]) * mult + val1[iKey]; 13892 } 13893 return arr; 13894 } 13895 return (val2 - val1) * mult + val1; 13896 } 13897 13898 function nearestKey(time) { 13899 var iKey; 13900 var lenKey = data.k.length; 13901 var index; 13902 var keyTime; 13903 if (!data.k.length || typeof (data.k[0]) === 'number') { 13904 index = 0; 13905 keyTime = 0; 13906 } else { 13907 index = -1; 13908 time *= elem.comp.globalData.frameRate; 13909 if (time < data.k[0].t) { 13910 index = 1; 13911 keyTime = data.k[0].t; 13912 } else { 13913 for (iKey = 0; iKey < lenKey - 1; iKey += 1) { 13914 if (time === data.k[iKey].t) { 13915 index = iKey + 1; 13916 keyTime = data.k[iKey].t; 13917 break; 13918 } else if (time > data.k[iKey].t && time < data.k[iKey + 1].t) { 13919 if (time - data.k[iKey].t > data.k[iKey + 1].t - time) { 13920 index = iKey + 2; 13921 keyTime = data.k[iKey + 1].t; 13922 } else { 13923 index = iKey + 1; 13924 keyTime = data.k[iKey].t; 13925 } 13926 break; 13927 } 13928 } 13929 if (index === -1) { 13930 index = iKey + 1; 13931 keyTime = data.k[iKey].t; 13932 } 13933 } 13934 } 13935 var obKey = {}; 13936 obKey.index = index; 13937 obKey.time = keyTime / elem.comp.globalData.frameRate; 13938 return obKey; 13939 } 13940 13941 function key(ind) { 13942 var obKey; 13943 var iKey; 13944 var lenKey; 13945 if (!data.k.length || typeof (data.k[0]) === 'number') { 13946 throw new Error('The property has no keyframe at index ' + ind); 13947 } 13948 ind -= 1; 13949 obKey = { 13950 time: data.k[ind].t / elem.comp.globalData.frameRate, 13951 value: [], 13952 }; 13953 var arr = Object.prototype.hasOwnProperty.call(data.k[ind], 's') ? data.k[ind].s : data.k[ind - 1].e; 13954 13955 lenKey = arr.length; 13956 for (iKey = 0; iKey < lenKey; iKey += 1) { 13957 obKey[iKey] = arr[iKey]; 13958 obKey.value[iKey] = arr[iKey]; 13959 } 13960 return obKey; 13961 } 13962 13963 function framesToTime(frames, fps) { 13964 if (!fps) { 13965 fps = elem.comp.globalData.frameRate; 13966 } 13967 return frames / fps; 13968 } 13969 13970 function timeToFrames(t, fps) { 13971 if (!t && t !== 0) { 13972 t = time; 13973 } 13974 if (!fps) { 13975 fps = elem.comp.globalData.frameRate; 13976 } 13977 return t * fps; 13978 } 13979 13980 function seedRandom(seed) { 13981 BMMath.seedrandom(randSeed + seed); 13982 } 13983 13984 function sourceRectAtTime() { 13985 return elem.sourceRectAtTime(); 13986 } 13987 13988 function substring(init, end) { 13989 if (typeof value === 'string') { 13990 if (end === undefined) { 13991 return value.substring(init); 13992 } 13993 return value.substring(init, end); 13994 } 13995 return ''; 13996 } 13997 13998 function substr(init, end) { 13999 if (typeof value === 'string') { 14000 if (end === undefined) { 14001 return value.substr(init); 14002 } 14003 return value.substr(init, end); 14004 } 14005 return ''; 14006 } 14007 14008 function posterizeTime(framesPerSecond) { 14009 time = framesPerSecond === 0 ? 0 : Math.floor(time * framesPerSecond) / framesPerSecond; 14010 value = valueAtTime(time); 14011 } 14012 14013 var time; 14014 var velocity; 14015 var value; 14016 var text; 14017 var textIndex; 14018 var textTotal; 14019 var selectorValue; 14020 var index = elem.data.ind; 14021 var hasParent = !!(elem.hierarchy && elem.hierarchy.length); 14022 var parent; 14023 var randSeed = Math.floor(Math.random() * 1000000); 14024 var globalData = elem.globalData; 14025 function executeExpression(_value) { 14026 // globalData.pushExpression(); 14027 value = _value; 14028 if (_needsRandom) { 14029 seedRandom(randSeed); 14030 } 14031 if (this.frameExpressionId === elem.globalData.frameId && this.propType !== 'textSelector') { 14032 return value; 14033 } 14034 if (this.propType === 'textSelector') { 14035 textIndex = this.textIndex; 14036 textTotal = this.textTotal; 14037 selectorValue = this.selectorValue; 14038 } 14039 if (!thisLayer) { 14040 text = elem.layerInterface.text; 14041 thisLayer = elem.layerInterface; 14042 thisComp = elem.comp.compInterface; 14043 toWorld = thisLayer.toWorld.bind(thisLayer); 14044 fromWorld = thisLayer.fromWorld.bind(thisLayer); 14045 fromComp = thisLayer.fromComp.bind(thisLayer); 14046 toComp = thisLayer.toComp.bind(thisLayer); 14047 mask = thisLayer.mask ? thisLayer.mask.bind(thisLayer) : null; 14048 fromCompToSurface = fromComp; 14049 } 14050 if (!transform) { 14051 transform = elem.layerInterface('ADBE Transform Group'); 14052 $bm_transform = transform; 14053 if (transform) { 14054 anchorPoint = transform.anchorPoint; 14055 /* position = transform.position; 14056 rotation = transform.rotation; 14057 scale = transform.scale; */ 14058 } 14059 } 14060 14061 if (elemType === 4 && !content) { 14062 content = thisLayer('ADBE Root Vectors Group'); 14063 } 14064 if (!effect) { 14065 effect = thisLayer(4); 14066 } 14067 hasParent = !!(elem.hierarchy && elem.hierarchy.length); 14068 if (hasParent && !parent) { 14069 parent = elem.hierarchy[0].layerInterface; 14070 } 14071 time = this.comp.renderedFrame / this.comp.globalData.frameRate; 14072 if (needsVelocity) { 14073 velocity = velocityAtTime(time); 14074 } 14075 expression_function(); 14076 this.frameExpressionId = elem.globalData.frameId; 14077 14078 // TODO: Check if it's possible to return on ShapeInterface the .v value 14079 if (scoped_bm_rt.propType === 'shape') { 14080 scoped_bm_rt = scoped_bm_rt.v; 14081 } 14082 // globalData.popExpression(); 14083 return scoped_bm_rt; 14084 } 14085 return executeExpression; 14086 } 14087 14088 ob.initiateExpression = initiateExpression; 14089 return ob; 14090}()); 14091 14092/* global ExpressionManager, createTypedArray */ 14093/* exported expressionHelpers */ 14094 14095var expressionHelpers = (function () { 14096 function searchExpressions(elem, data, prop) { 14097 if (data.x) { 14098 prop.k = true; 14099 prop.x = true; 14100 prop.initiateExpression = ExpressionManager.initiateExpression; 14101 prop.effectsSequence.push(prop.initiateExpression(elem, data, prop).bind(prop)); 14102 } 14103 } 14104 14105 function getValueAtTime(frameNum) { 14106 frameNum *= this.elem.globalData.frameRate; 14107 frameNum -= this.offsetTime; 14108 if (frameNum !== this._cachingAtTime.lastFrame) { 14109 this._cachingAtTime.lastIndex = this._cachingAtTime.lastFrame < frameNum ? this._cachingAtTime.lastIndex : 0; 14110 this._cachingAtTime.value = this.interpolateValue(frameNum, this._cachingAtTime); 14111 this._cachingAtTime.lastFrame = frameNum; 14112 } 14113 return this._cachingAtTime.value; 14114 } 14115 14116 function getSpeedAtTime(frameNum) { 14117 var delta = -0.01; 14118 var v1 = this.getValueAtTime(frameNum); 14119 var v2 = this.getValueAtTime(frameNum + delta); 14120 var speed = 0; 14121 if (v1.length) { 14122 var i; 14123 for (i = 0; i < v1.length; i += 1) { 14124 speed += Math.pow(v2[i] - v1[i], 2); 14125 } 14126 speed = Math.sqrt(speed) * 100; 14127 } else { 14128 speed = 0; 14129 } 14130 return speed; 14131 } 14132 14133 function getVelocityAtTime(frameNum) { 14134 if (this.vel !== undefined) { 14135 return this.vel; 14136 } 14137 var delta = -0.001; 14138 // frameNum += this.elem.data.st; 14139 var v1 = this.getValueAtTime(frameNum); 14140 var v2 = this.getValueAtTime(frameNum + delta); 14141 var velocity; 14142 if (v1.length) { 14143 velocity = createTypedArray('float32', v1.length); 14144 var i; 14145 for (i = 0; i < v1.length; i += 1) { 14146 // removing frameRate 14147 // if needed, don't add it here 14148 // velocity[i] = this.elem.globalData.frameRate*((v2[i] - v1[i])/delta); 14149 velocity[i] = (v2[i] - v1[i]) / delta; 14150 } 14151 } else { 14152 velocity = (v2 - v1) / delta; 14153 } 14154 return velocity; 14155 } 14156 14157 function getStaticValueAtTime() { 14158 return this.pv; 14159 } 14160 14161 function setGroupProperty(propertyGroup) { 14162 this.propertyGroup = propertyGroup; 14163 } 14164 14165 return { 14166 searchExpressions: searchExpressions, 14167 getSpeedAtTime: getSpeedAtTime, 14168 getVelocityAtTime: getVelocityAtTime, 14169 getValueAtTime: getValueAtTime, 14170 getStaticValueAtTime: getStaticValueAtTime, 14171 setGroupProperty: setGroupProperty, 14172 }; 14173}()); 14174 14175/* global createTypedArray, Matrix, TransformPropertyFactory, expressionHelpers, PropertyFactory, expressionHelpers, 14176initialDefaultFrame, shapePool, ShapePropertyFactory, bez, extendPrototype, ExpressionManager, createSizedArray */ 14177 14178(function addPropertyDecorator() { 14179 function loopOut(type, duration, durationFlag) { 14180 if (!this.k || !this.keyframes) { 14181 return this.pv; 14182 } 14183 type = type ? type.toLowerCase() : ''; 14184 var currentFrame = this.comp.renderedFrame; 14185 var keyframes = this.keyframes; 14186 var lastKeyFrame = keyframes[keyframes.length - 1].t; 14187 if (currentFrame <= lastKeyFrame) { 14188 return this.pv; 14189 } 14190 var cycleDuration; 14191 var firstKeyFrame; 14192 if (!durationFlag) { 14193 if (!duration || duration > keyframes.length - 1) { 14194 duration = keyframes.length - 1; 14195 } 14196 firstKeyFrame = keyframes[keyframes.length - 1 - duration].t; 14197 cycleDuration = lastKeyFrame - firstKeyFrame; 14198 } else { 14199 if (!duration) { 14200 cycleDuration = Math.max(0, lastKeyFrame - this.elem.data.ip); 14201 } else { 14202 cycleDuration = Math.abs(lastKeyFrame - this.elem.comp.globalData.frameRate * duration); 14203 } 14204 firstKeyFrame = lastKeyFrame - cycleDuration; 14205 } 14206 var i; 14207 var len; 14208 var ret; 14209 if (type === 'pingpong') { 14210 var iterations = Math.floor((currentFrame - firstKeyFrame) / cycleDuration); 14211 if (iterations % 2 !== 0) { 14212 return this.getValueAtTime(((cycleDuration - (currentFrame - firstKeyFrame) % cycleDuration + firstKeyFrame)) / this.comp.globalData.frameRate, 0); // eslint-disable-line 14213 } 14214 } else if (type === 'offset') { 14215 var initV = this.getValueAtTime(firstKeyFrame / this.comp.globalData.frameRate, 0); 14216 var endV = this.getValueAtTime(lastKeyFrame / this.comp.globalData.frameRate, 0); 14217 var current = this.getValueAtTime(((currentFrame - firstKeyFrame) % cycleDuration + firstKeyFrame) / this.comp.globalData.frameRate, 0); // eslint-disable-line 14218 var repeats = Math.floor((currentFrame - firstKeyFrame) / cycleDuration); 14219 if (this.pv.length) { 14220 ret = new Array(initV.length); 14221 len = ret.length; 14222 for (i = 0; i < len; i += 1) { 14223 ret[i] = (endV[i] - initV[i]) * repeats + current[i]; 14224 } 14225 return ret; 14226 } 14227 return (endV - initV) * repeats + current; 14228 } else if (type === 'continue') { 14229 var lastValue = this.getValueAtTime(lastKeyFrame / this.comp.globalData.frameRate, 0); 14230 var nextLastValue = this.getValueAtTime((lastKeyFrame - 0.001) / this.comp.globalData.frameRate, 0); 14231 if (this.pv.length) { 14232 ret = new Array(lastValue.length); 14233 len = ret.length; 14234 for (i = 0; i < len; i += 1) { 14235 ret[i] = lastValue[i] + (lastValue[i] - nextLastValue[i]) * ((currentFrame - lastKeyFrame) / this.comp.globalData.frameRate) / 0.0005; // eslint-disable-line 14236 } 14237 return ret; 14238 } 14239 return lastValue + (lastValue - nextLastValue) * (((currentFrame - lastKeyFrame)) / 0.001); 14240 } 14241 return this.getValueAtTime((((currentFrame - firstKeyFrame) % cycleDuration + firstKeyFrame)) / this.comp.globalData.frameRate, 0); // eslint-disable-line 14242 14243 } 14244 14245 function loopIn(type, duration, durationFlag) { 14246 if (!this.k) { 14247 return this.pv; 14248 } 14249 type = type ? type.toLowerCase() : ''; 14250 var currentFrame = this.comp.renderedFrame; 14251 var keyframes = this.keyframes; 14252 var firstKeyFrame = keyframes[0].t; 14253 if (currentFrame >= firstKeyFrame) { 14254 return this.pv; 14255 } 14256 var cycleDuration; 14257 var lastKeyFrame; 14258 if (!durationFlag) { 14259 if (!duration || duration > keyframes.length - 1) { 14260 duration = keyframes.length - 1; 14261 } 14262 lastKeyFrame = keyframes[duration].t; 14263 cycleDuration = lastKeyFrame - firstKeyFrame; 14264 } else { 14265 if (!duration) { 14266 cycleDuration = Math.max(0, this.elem.data.op - firstKeyFrame); 14267 } else { 14268 cycleDuration = Math.abs(this.elem.comp.globalData.frameRate * duration); 14269 } 14270 lastKeyFrame = firstKeyFrame + cycleDuration; 14271 } 14272 var i; 14273 var len; 14274 var ret; 14275 if (type === 'pingpong') { 14276 var iterations = Math.floor((firstKeyFrame - currentFrame) / cycleDuration); 14277 if (iterations % 2 === 0) { 14278 return this.getValueAtTime((((firstKeyFrame - currentFrame) % cycleDuration + firstKeyFrame)) / this.comp.globalData.frameRate, 0); // eslint-disable-line 14279 } 14280 } else if (type === 'offset') { 14281 var initV = this.getValueAtTime(firstKeyFrame / this.comp.globalData.frameRate, 0); 14282 var endV = this.getValueAtTime(lastKeyFrame / this.comp.globalData.frameRate, 0); 14283 var current = this.getValueAtTime((cycleDuration - ((firstKeyFrame - currentFrame) % cycleDuration) + firstKeyFrame) / this.comp.globalData.frameRate, 0); 14284 var repeats = Math.floor((firstKeyFrame - currentFrame) / cycleDuration) + 1; 14285 if (this.pv.length) { 14286 ret = new Array(initV.length); 14287 len = ret.length; 14288 for (i = 0; i < len; i += 1) { 14289 ret[i] = current[i] - (endV[i] - initV[i]) * repeats; 14290 } 14291 return ret; 14292 } 14293 return current - (endV - initV) * repeats; 14294 } else if (type === 'continue') { 14295 var firstValue = this.getValueAtTime(firstKeyFrame / this.comp.globalData.frameRate, 0); 14296 var nextFirstValue = this.getValueAtTime((firstKeyFrame + 0.001) / this.comp.globalData.frameRate, 0); 14297 if (this.pv.length) { 14298 ret = new Array(firstValue.length); 14299 len = ret.length; 14300 for (i = 0; i < len; i += 1) { 14301 ret[i] = firstValue[i] + ((firstValue[i] - nextFirstValue[i]) * (firstKeyFrame - currentFrame)) / 0.001; 14302 } 14303 return ret; 14304 } 14305 return firstValue + ((firstValue - nextFirstValue) * (firstKeyFrame - currentFrame)) / 0.001; 14306 } 14307 return this.getValueAtTime(((cycleDuration - ((firstKeyFrame - currentFrame) % cycleDuration + firstKeyFrame))) / this.comp.globalData.frameRate, 0); // eslint-disable-line 14308 14309 } 14310 14311 function smooth(width, samples) { 14312 if (!this.k) { 14313 return this.pv; 14314 } 14315 width = (width || 0.4) * 0.5; 14316 samples = Math.floor(samples || 5); 14317 if (samples <= 1) { 14318 return this.pv; 14319 } 14320 var currentTime = this.comp.renderedFrame / this.comp.globalData.frameRate; 14321 var initFrame = currentTime - width; 14322 var endFrame = currentTime + width; 14323 var sampleFrequency = samples > 1 ? (endFrame - initFrame) / (samples - 1) : 1; 14324 var i = 0; 14325 var j = 0; 14326 var value; 14327 if (this.pv.length) { 14328 value = createTypedArray('float32', this.pv.length); 14329 } else { 14330 value = 0; 14331 } 14332 var sampleValue; 14333 while (i < samples) { 14334 sampleValue = this.getValueAtTime(initFrame + i * sampleFrequency); 14335 if (this.pv.length) { 14336 for (j = 0; j < this.pv.length; j += 1) { 14337 value[j] += sampleValue[j]; 14338 } 14339 } else { 14340 value += sampleValue; 14341 } 14342 i += 1; 14343 } 14344 if (this.pv.length) { 14345 for (j = 0; j < this.pv.length; j += 1) { 14346 value[j] /= samples; 14347 } 14348 } else { 14349 value /= samples; 14350 } 14351 return value; 14352 } 14353 14354 function getTransformValueAtTime(time) { 14355 if (!this._transformCachingAtTime) { 14356 this._transformCachingAtTime = { 14357 v: new Matrix(), 14358 }; 14359 } 14360 /// / 14361 var matrix = this._transformCachingAtTime.v; 14362 matrix.cloneFromProps(this.pre.props); 14363 if (this.appliedTransformations < 1) { 14364 var anchor = this.a.getValueAtTime(time); 14365 matrix.translate( 14366 -anchor[0] * this.a.mult, 14367 -anchor[1] * this.a.mult, 14368 anchor[2] * this.a.mult 14369 ); 14370 } 14371 if (this.appliedTransformations < 2) { 14372 var scale = this.s.getValueAtTime(time); 14373 matrix.scale( 14374 scale[0] * this.s.mult, 14375 scale[1] * this.s.mult, 14376 scale[2] * this.s.mult 14377 ); 14378 } 14379 if (this.sk && this.appliedTransformations < 3) { 14380 var skew = this.sk.getValueAtTime(time); 14381 var skewAxis = this.sa.getValueAtTime(time); 14382 matrix.skewFromAxis(-skew * this.sk.mult, skewAxis * this.sa.mult); 14383 } 14384 if (this.r && this.appliedTransformations < 4) { 14385 var rotation = this.r.getValueAtTime(time); 14386 matrix.rotate(-rotation * this.r.mult); 14387 } else if (!this.r && this.appliedTransformations < 4) { 14388 var rotationZ = this.rz.getValueAtTime(time); 14389 var rotationY = this.ry.getValueAtTime(time); 14390 var rotationX = this.rx.getValueAtTime(time); 14391 var orientation = this.or.getValueAtTime(time); 14392 matrix.rotateZ(-rotationZ * this.rz.mult) 14393 .rotateY(rotationY * this.ry.mult) 14394 .rotateX(rotationX * this.rx.mult) 14395 .rotateZ(-orientation[2] * this.or.mult) 14396 .rotateY(orientation[1] * this.or.mult) 14397 .rotateX(orientation[0] * this.or.mult); 14398 } 14399 if (this.data.p && this.data.p.s) { 14400 var positionX = this.px.getValueAtTime(time); 14401 var positionY = this.py.getValueAtTime(time); 14402 if (this.data.p.z) { 14403 var positionZ = this.pz.getValueAtTime(time); 14404 matrix.translate( 14405 positionX * this.px.mult, 14406 positionY * this.py.mult, 14407 -positionZ * this.pz.mult 14408 ); 14409 } else { 14410 matrix.translate(positionX * this.px.mult, positionY * this.py.mult, 0); 14411 } 14412 } else { 14413 var position = this.p.getValueAtTime(time); 14414 matrix.translate( 14415 position[0] * this.p.mult, 14416 position[1] * this.p.mult, 14417 -position[2] * this.p.mult 14418 ); 14419 } 14420 return matrix; 14421 /// / 14422 } 14423 14424 function getTransformStaticValueAtTime() { 14425 return this.v.clone(new Matrix()); 14426 } 14427 14428 var getTransformProperty = TransformPropertyFactory.getTransformProperty; 14429 TransformPropertyFactory.getTransformProperty = function (elem, data, container) { 14430 var prop = getTransformProperty(elem, data, container); 14431 if (prop.dynamicProperties.length) { 14432 prop.getValueAtTime = getTransformValueAtTime.bind(prop); 14433 } else { 14434 prop.getValueAtTime = getTransformStaticValueAtTime.bind(prop); 14435 } 14436 prop.setGroupProperty = expressionHelpers.setGroupProperty; 14437 return prop; 14438 }; 14439 14440 var propertyGetProp = PropertyFactory.getProp; 14441 PropertyFactory.getProp = function (elem, data, type, mult, container) { 14442 var prop = propertyGetProp(elem, data, type, mult, container); 14443 // prop.getVelocityAtTime = getVelocityAtTime; 14444 // prop.loopOut = loopOut; 14445 // prop.loopIn = loopIn; 14446 if (prop.kf) { 14447 prop.getValueAtTime = expressionHelpers.getValueAtTime.bind(prop); 14448 } else { 14449 prop.getValueAtTime = expressionHelpers.getStaticValueAtTime.bind(prop); 14450 } 14451 prop.setGroupProperty = expressionHelpers.setGroupProperty; 14452 prop.loopOut = loopOut; 14453 prop.loopIn = loopIn; 14454 prop.smooth = smooth; 14455 prop.getVelocityAtTime = expressionHelpers.getVelocityAtTime.bind(prop); 14456 prop.getSpeedAtTime = expressionHelpers.getSpeedAtTime.bind(prop); 14457 prop.numKeys = data.a === 1 ? data.k.length : 0; 14458 prop.propertyIndex = data.ix; 14459 var value = 0; 14460 if (type !== 0) { 14461 value = createTypedArray('float32', data.a === 1 ? data.k[0].s.length : data.k.length); 14462 } 14463 prop._cachingAtTime = { 14464 lastFrame: initialDefaultFrame, 14465 lastIndex: 0, 14466 value: value, 14467 }; 14468 expressionHelpers.searchExpressions(elem, data, prop); 14469 if (prop.k) { 14470 container.addDynamicProperty(prop); 14471 } 14472 14473 return prop; 14474 }; 14475 14476 function getShapeValueAtTime(frameNum) { 14477 // For now this caching object is created only when needed instead of creating it when the shape is initialized. 14478 if (!this._cachingAtTime) { 14479 this._cachingAtTime = { 14480 shapeValue: shapePool.clone(this.pv), 14481 lastIndex: 0, 14482 lastTime: initialDefaultFrame, 14483 }; 14484 } 14485 14486 frameNum *= this.elem.globalData.frameRate; 14487 frameNum -= this.offsetTime; 14488 if (frameNum !== this._cachingAtTime.lastTime) { 14489 this._cachingAtTime.lastIndex = this._cachingAtTime.lastTime < frameNum ? this._caching.lastIndex : 0; 14490 this._cachingAtTime.lastTime = frameNum; 14491 this.interpolateShape(frameNum, this._cachingAtTime.shapeValue, this._cachingAtTime); 14492 } 14493 return this._cachingAtTime.shapeValue; 14494 } 14495 14496 var ShapePropertyConstructorFunction = ShapePropertyFactory.getConstructorFunction(); 14497 var KeyframedShapePropertyConstructorFunction = ShapePropertyFactory.getKeyframedConstructorFunction(); 14498 14499 function ShapeExpressions() {} 14500 ShapeExpressions.prototype = { 14501 vertices: function (prop, time) { 14502 if (this.k) { 14503 this.getValue(); 14504 } 14505 var shapePath = this.v; 14506 if (time !== undefined) { 14507 shapePath = this.getValueAtTime(time, 0); 14508 } 14509 var i; 14510 var len = shapePath._length; 14511 var vertices = shapePath[prop]; 14512 var points = shapePath.v; 14513 var arr = createSizedArray(len); 14514 for (i = 0; i < len; i += 1) { 14515 if (prop === 'i' || prop === 'o') { 14516 arr[i] = [vertices[i][0] - points[i][0], vertices[i][1] - points[i][1]]; 14517 } else { 14518 arr[i] = [vertices[i][0], vertices[i][1]]; 14519 } 14520 } 14521 return arr; 14522 }, 14523 points: function (time) { 14524 return this.vertices('v', time); 14525 }, 14526 inTangents: function (time) { 14527 return this.vertices('i', time); 14528 }, 14529 outTangents: function (time) { 14530 return this.vertices('o', time); 14531 }, 14532 isClosed: function () { 14533 return this.v.c; 14534 }, 14535 pointOnPath: function (perc, time) { 14536 var shapePath = this.v; 14537 if (time !== undefined) { 14538 shapePath = this.getValueAtTime(time, 0); 14539 } 14540 if (!this._segmentsLength) { 14541 this._segmentsLength = bez.getSegmentsLength(shapePath); 14542 } 14543 14544 var segmentsLength = this._segmentsLength; 14545 var lengths = segmentsLength.lengths; 14546 var lengthPos = segmentsLength.totalLength * perc; 14547 var i = 0; 14548 var len = lengths.length; 14549 var accumulatedLength = 0; 14550 var pt; 14551 while (i < len) { 14552 if (accumulatedLength + lengths[i].addedLength > lengthPos) { 14553 var initIndex = i; 14554 var endIndex = (shapePath.c && i === len - 1) ? 0 : i + 1; 14555 var segmentPerc = (lengthPos - accumulatedLength) / lengths[i].addedLength; 14556 pt = bez.getPointInSegment(shapePath.v[initIndex], shapePath.v[endIndex], shapePath.o[initIndex], shapePath.i[endIndex], segmentPerc, lengths[i]); 14557 break; 14558 } else { 14559 accumulatedLength += lengths[i].addedLength; 14560 } 14561 i += 1; 14562 } 14563 if (!pt) { 14564 pt = shapePath.c ? [shapePath.v[0][0], shapePath.v[0][1]] : [shapePath.v[shapePath._length - 1][0], shapePath.v[shapePath._length - 1][1]]; 14565 } 14566 return pt; 14567 }, 14568 vectorOnPath: function (perc, time, vectorType) { 14569 // perc doesn't use triple equality because it can be a Number object as well as a primitive. 14570 if (perc == 1) { // eslint-disable-line eqeqeq 14571 perc = this.v.c; 14572 } else if (perc == 0) { // eslint-disable-line eqeqeq 14573 perc = 0.999; 14574 } 14575 var pt1 = this.pointOnPath(perc, time); 14576 var pt2 = this.pointOnPath(perc + 0.001, time); 14577 var xLength = pt2[0] - pt1[0]; 14578 var yLength = pt2[1] - pt1[1]; 14579 var magnitude = Math.sqrt(Math.pow(xLength, 2) + Math.pow(yLength, 2)); 14580 if (magnitude === 0) { 14581 return [0, 0]; 14582 } 14583 var unitVector = vectorType === 'tangent' ? [xLength / magnitude, yLength / magnitude] : [-yLength / magnitude, xLength / magnitude]; 14584 return unitVector; 14585 }, 14586 tangentOnPath: function (perc, time) { 14587 return this.vectorOnPath(perc, time, 'tangent'); 14588 }, 14589 normalOnPath: function (perc, time) { 14590 return this.vectorOnPath(perc, time, 'normal'); 14591 }, 14592 setGroupProperty: expressionHelpers.setGroupProperty, 14593 getValueAtTime: expressionHelpers.getStaticValueAtTime, 14594 }; 14595 extendPrototype([ShapeExpressions], ShapePropertyConstructorFunction); 14596 extendPrototype([ShapeExpressions], KeyframedShapePropertyConstructorFunction); 14597 KeyframedShapePropertyConstructorFunction.prototype.getValueAtTime = getShapeValueAtTime; 14598 KeyframedShapePropertyConstructorFunction.prototype.initiateExpression = ExpressionManager.initiateExpression; 14599 14600 var propertyGetShapeProp = ShapePropertyFactory.getShapeProp; 14601 ShapePropertyFactory.getShapeProp = function (elem, data, type, arr, trims) { 14602 var prop = propertyGetShapeProp(elem, data, type, arr, trims); 14603 prop.propertyIndex = data.ix; 14604 prop.lock = false; 14605 if (type === 3) { 14606 expressionHelpers.searchExpressions(elem, data.pt, prop); 14607 } else if (type === 4) { 14608 expressionHelpers.searchExpressions(elem, data.ks, prop); 14609 } 14610 if (prop.k) { 14611 elem.addDynamicProperty(prop); 14612 } 14613 return prop; 14614 }; 14615}()); 14616 14617/* global ExpressionManager, TextProperty */ 14618 14619(function addDecorator() { 14620 function searchExpressions() { 14621 if (this.data.d.x) { 14622 this.calculateExpression = ExpressionManager.initiateExpression.bind(this)(this.elem, this.data.d, this); 14623 this.addEffect(this.getExpressionValue.bind(this)); 14624 return true; 14625 } 14626 return null; 14627 } 14628 14629 TextProperty.prototype.getExpressionValue = function (currentValue, text) { 14630 var newValue = this.calculateExpression(text); 14631 if (currentValue.t !== newValue) { 14632 var newData = {}; 14633 this.copyData(newData, currentValue); 14634 newData.t = newValue.toString(); 14635 newData.__complete = false; 14636 return newData; 14637 } 14638 return currentValue; 14639 }; 14640 14641 TextProperty.prototype.searchProperty = function () { 14642 var isKeyframed = this.searchKeyframes(); 14643 var hasExpressions = this.searchExpressions(); 14644 this.kf = isKeyframed || hasExpressions; 14645 return this.kf; 14646 }; 14647 14648 TextProperty.prototype.searchExpressions = searchExpressions; 14649}()); 14650 14651/* global propertyGroupFactory, PropertyInterface */ 14652/* exported ShapePathInterface */ 14653 14654var ShapePathInterface = ( 14655 14656 function () { 14657 return function pathInterfaceFactory(shape, view, propertyGroup) { 14658 var prop = view.sh; 14659 14660 function interfaceFunction(val) { 14661 if (val === 'Shape' || val === 'shape' || val === 'Path' || val === 'path' || val === 'ADBE Vector Shape' || val === 2) { 14662 return interfaceFunction.path; 14663 } 14664 return null; 14665 } 14666 14667 var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup); 14668 prop.setGroupProperty(PropertyInterface('Path', _propertyGroup)); 14669 Object.defineProperties(interfaceFunction, { 14670 path: { 14671 get: function () { 14672 if (prop.k) { 14673 prop.getValue(); 14674 } 14675 return prop; 14676 }, 14677 }, 14678 shape: { 14679 get: function () { 14680 if (prop.k) { 14681 prop.getValue(); 14682 } 14683 return prop; 14684 }, 14685 }, 14686 _name: { value: shape.nm }, 14687 ix: { value: shape.ix }, 14688 propertyIndex: { value: shape.ix }, 14689 mn: { value: shape.mn }, 14690 propertyGroup: { value: propertyGroup }, 14691 }); 14692 return interfaceFunction; 14693 }; 14694 }() 14695); 14696 14697/* exported propertyGroupFactory */ 14698 14699var propertyGroupFactory = (function () { 14700 return function (interfaceFunction, parentPropertyGroup) { 14701 return function (val) { 14702 val = val === undefined ? 1 : val; 14703 if (val <= 0) { 14704 return interfaceFunction; 14705 } 14706 return parentPropertyGroup(val - 1); 14707 }; 14708 }; 14709}()); 14710 14711/* exported PropertyInterface */ 14712 14713var PropertyInterface = (function () { 14714 return function (propertyName, propertyGroup) { 14715 var interfaceFunction = { 14716 _name: propertyName, 14717 }; 14718 14719 function _propertyGroup(val) { 14720 val = val === undefined ? 1 : val; 14721 if (val <= 0) { 14722 return interfaceFunction; 14723 } 14724 return propertyGroup(val - 1); 14725 } 14726 14727 return _propertyGroup; 14728 }; 14729}()); 14730 14731/* global ExpressionPropertyInterface, PropertyInterface, propertyGroupFactory, ShapePathInterface */ 14732/* exported ShapeExpressionInterface */ 14733 14734var
vendor: 19,033 bytes, lines 14734-15270
14734 ShapeExpressionInterface = (function () { 14735 function iterateElements(shapes, view, propertyGroup) { 14736 var arr = []; 14737 var i; 14738 var len = shapes ? shapes.length : 0; 14739 for (i = 0; i < len; i += 1) { 14740 if (shapes[i].ty === 'gr') { 14741 arr.push(groupInterfaceFactory(shapes[i], view[i], propertyGroup)); 14742 } else if (shapes[i].ty === 'fl') { 14743 arr.push(fillInterfaceFactory(shapes[i], view[i], propertyGroup)); 14744 } else if (shapes[i].ty === 'st') { 14745 arr.push(strokeInterfaceFactory(shapes[i], view[i], propertyGroup)); 14746 } else if (shapes[i].ty === 'tm') { 14747 arr.push(trimInterfaceFactory(shapes[i], view[i], propertyGroup)); 14748 } else if (shapes[i].ty === 'tr') { 14749 // arr.push(transformInterfaceFactory(shapes[i],view[i],propertyGroup)); 14750 } else if (shapes[i].ty === 'el') { 14751 arr.push(ellipseInterfaceFactory(shapes[i], view[i], propertyGroup)); 14752 } else if (shapes[i].ty === 'sr') { 14753 arr.push(starInterfaceFactory(shapes[i], view[i], propertyGroup)); 14754 } else if (shapes[i].ty === 'sh') { 14755 arr.push(ShapePathInterface(shapes[i], view[i], propertyGroup)); 14756 } else if (shapes[i].ty === 'rc') { 14757 arr.push(rectInterfaceFactory(shapes[i], view[i], propertyGroup)); 14758 } else if (shapes[i].ty === 'rd') { 14759 arr.push(roundedInterfaceFactory(shapes[i], view[i], propertyGroup)); 14760 } else if (shapes[i].ty === 'rp') { 14761 arr.push(repeaterInterfaceFactory(shapes[i], view[i], propertyGroup)); 14762 } else if (shapes[i].ty === 'gf') { 14763 arr.push(gradientFillInterfaceFactory(shapes[i], view[i], propertyGroup)); 14764 } else { 14765 arr.push(defaultInterfaceFactory(shapes[i], view[i], propertyGroup)); 14766 } 14767 } 14768 return arr; 14769 } 14770 14771 function contentsInterfaceFactory(shape, view, propertyGroup) { 14772 var interfaces; 14773 var interfaceFunction = function _interfaceFunction(value) { 14774 var i = 0; 14775 var len = interfaces.length; 14776 while (i < len) { 14777 if (interfaces[i]._name === value || interfaces[i].mn === value || interfaces[i].propertyIndex === value || interfaces[i].ix === value || interfaces[i].ind === value) { 14778 return interfaces[i]; 14779 } 14780 i += 1; 14781 } 14782 if (typeof value === 'number') { 14783 return interfaces[value - 1]; 14784 } 14785 return null; 14786 }; 14787 14788 interfaceFunction.propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup); 14789 interfaces = iterateElements(shape.it, view.it, interfaceFunction.propertyGroup); 14790 interfaceFunction.numProperties = interfaces.length; 14791 var transformInterface = transformInterfaceFactory(shape.it[shape.it.length - 1], view.it[view.it.length - 1], interfaceFunction.propertyGroup); 14792 interfaceFunction.transform = transformInterface; 14793 interfaceFunction.propertyIndex = shape.cix; 14794 interfaceFunction._name = shape.nm; 14795 14796 return interfaceFunction; 14797 } 14798 14799 function groupInterfaceFactory(shape, view, propertyGroup) { 14800 var interfaceFunction = function _interfaceFunction(value) { 14801 switch (value) { 14802 case 'ADBE Vectors Group': 14803 case 'Contents': 14804 case 2: 14805 return interfaceFunction.content; 14806 // Not necessary for now. Keeping them here in case a new case appears 14807 // case 'ADBE Vector Transform Group': 14808 // case 3: 14809 default: 14810 return interfaceFunction.transform; 14811 } 14812 }; 14813 interfaceFunction.propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup); 14814 var content = contentsInterfaceFactory(shape, view, interfaceFunction.propertyGroup); 14815 var transformInterface = transformInterfaceFactory(shape.it[shape.it.length - 1], view.it[view.it.length - 1], interfaceFunction.propertyGroup); 14816 interfaceFunction.content = content; 14817 interfaceFunction.transform = transformInterface; 14818 Object.defineProperty(interfaceFunction, '_name', { 14819 get: function () { 14820 return shape.nm; 14821 }, 14822 }); 14823 // interfaceFunction.content = interfaceFunction; 14824 interfaceFunction.numProperties = shape.np; 14825 interfaceFunction.propertyIndex = shape.ix; 14826 interfaceFunction.nm = shape.nm; 14827 interfaceFunction.mn = shape.mn; 14828 return interfaceFunction; 14829 } 14830 14831 function fillInterfaceFactory(shape, view, propertyGroup) { 14832 function interfaceFunction(val) { 14833 if (val === 'Color' || val === 'color') { 14834 return interfaceFunction.color; 14835 } if (val === 'Opacity' || val === 'opacity') { 14836 return interfaceFunction.opacity; 14837 } 14838 return null; 14839 } 14840 Object.defineProperties(interfaceFunction, { 14841 color: { 14842 get: ExpressionPropertyInterface(view.c), 14843 }, 14844 opacity: { 14845 get: ExpressionPropertyInterface(view.o), 14846 }, 14847 _name: { value: shape.nm }, 14848 mn: { value: shape.mn }, 14849 }); 14850 14851 view.c.setGroupProperty(PropertyInterface('Color', propertyGroup)); 14852 view.o.setGroupProperty(PropertyInterface('Opacity', propertyGroup)); 14853 return interfaceFunction; 14854 } 14855 14856 function gradientFillInterfaceFactory(shape, view, propertyGroup) { 14857 function interfaceFunction(val) { 14858 if (val === 'Start Point' || val === 'start point') { 14859 return interfaceFunction.startPoint; 14860 } 14861 if (val === 'End Point' || val === 'end point') { 14862 return interfaceFunction.endPoint; 14863 } 14864 if (val === 'Opacity' || val === 'opacity') { 14865 return interfaceFunction.opacity; 14866 } 14867 return null; 14868 } 14869 Object.defineProperties(interfaceFunction, { 14870 startPoint: { 14871 get: ExpressionPropertyInterface(view.s), 14872 }, 14873 endPoint: { 14874 get: ExpressionPropertyInterface(view.e), 14875 }, 14876 opacity: { 14877 get: ExpressionPropertyInterface(view.o), 14878 }, 14879 type: { 14880 get: function () { 14881 return 'a'; 14882 }, 14883 }, 14884 _name: { value: shape.nm }, 14885 mn: { value: shape.mn }, 14886 }); 14887 14888 view.s.setGroupProperty(PropertyInterface('Start Point', propertyGroup)); 14889 view.e.setGroupProperty(PropertyInterface('End Point', propertyGroup)); 14890 view.o.setGroupProperty(PropertyInterface('Opacity', propertyGroup)); 14891 return interfaceFunction; 14892 } 14893 function defaultInterfaceFactory() { 14894 function interfaceFunction() { 14895 return null; 14896 } 14897 return interfaceFunction; 14898 } 14899 14900 function strokeInterfaceFactory(shape, view, propertyGroup) { 14901 var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup); 14902 var _dashPropertyGroup = propertyGroupFactory(dashOb, _propertyGroup); 14903 function addPropertyToDashOb(i) { 14904 Object.defineProperty(dashOb, shape.d[i].nm, { 14905 get: ExpressionPropertyInterface(view.d.dataProps[i].p), 14906 }); 14907 } 14908 var i; 14909 var len = shape.d ? shape.d.length : 0; 14910 var dashOb = {}; 14911 for (i = 0; i < len; i += 1) { 14912 addPropertyToDashOb(i); 14913 view.d.dataProps[i].p.setGroupProperty(_dashPropertyGroup); 14914 } 14915 14916 function interfaceFunction(val) { 14917 if (val === 'Color' || val === 'color') { 14918 return interfaceFunction.color; 14919 } if (val === 'Opacity' || val === 'opacity') { 14920 return interfaceFunction.opacity; 14921 } if (val === 'Stroke Width' || val === 'stroke width') { 14922 return interfaceFunction.strokeWidth; 14923 } 14924 return null; 14925 } 14926 Object.defineProperties(interfaceFunction, { 14927 color: { 14928 get: ExpressionPropertyInterface(view.c), 14929 }, 14930 opacity: { 14931 get: ExpressionPropertyInterface(view.o), 14932 }, 14933 strokeWidth: { 14934 get: ExpressionPropertyInterface(view.w), 14935 }, 14936 dash: { 14937 get: function () { 14938 return dashOb; 14939 }, 14940 }, 14941 _name: { value: shape.nm }, 14942 mn: { value: shape.mn }, 14943 }); 14944 14945 view.c.setGroupProperty(PropertyInterface('Color', _propertyGroup)); 14946 view.o.setGroupProperty(PropertyInterface('Opacity', _propertyGroup)); 14947 view.w.setGroupProperty(PropertyInterface('Stroke Width', _propertyGroup)); 14948 return interfaceFunction; 14949 } 14950 14951 function trimInterfaceFactory(shape, view, propertyGroup) { 14952 function interfaceFunction(val) { 14953 if (val === shape.e.ix || val === 'End' || val === 'end') { 14954 return interfaceFunction.end; 14955 } 14956 if (val === shape.s.ix) { 14957 return interfaceFunction.start; 14958 } 14959 if (val === shape.o.ix) { 14960 return interfaceFunction.offset; 14961 } 14962 return null; 14963 } 14964 14965 var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup); 14966 interfaceFunction.propertyIndex = shape.ix; 14967 14968 view.s.setGroupProperty(PropertyInterface('Start', _propertyGroup)); 14969 view.e.setGroupProperty(PropertyInterface('End', _propertyGroup)); 14970 view.o.setGroupProperty(PropertyInterface('Offset', _propertyGroup)); 14971 interfaceFunction.propertyIndex = shape.ix; 14972 interfaceFunction.propertyGroup = propertyGroup; 14973 14974 Object.defineProperties(interfaceFunction, { 14975 start: { 14976 get: ExpressionPropertyInterface(view.s), 14977 }, 14978 end: { 14979 get: ExpressionPropertyInterface(view.e), 14980 }, 14981 offset: { 14982 get: ExpressionPropertyInterface(view.o), 14983 }, 14984 _name: { value: shape.nm }, 14985 }); 14986 interfaceFunction.mn = shape.mn; 14987 return interfaceFunction; 14988 } 14989 14990 function transformInterfaceFactory(shape, view, propertyGroup) { 14991 function interfaceFunction(value) { 14992 if (shape.a.ix === value || value === 'Anchor Point') { 14993 return interfaceFunction.anchorPoint; 14994 } 14995 if (shape.o.ix === value || value === 'Opacity') { 14996 return interfaceFunction.opacity; 14997 } 14998 if (shape.p.ix === value || value === 'Position') { 14999 return interfaceFunction.position; 15000 } 15001 if (shape.r.ix === value || value === 'Rotation' || value === 'ADBE Vector Rotation') { 15002 return interfaceFunction.rotation; 15003 } 15004 if (shape.s.ix === value || value === 'Scale') { 15005 return interfaceFunction.scale; 15006 } 15007 if ((shape.sk && shape.sk.ix === value) || value === 'Skew') { 15008 return interfaceFunction.skew; 15009 } 15010 if ((shape.sa && shape.sa.ix === value) || value === 'Skew Axis') { 15011 return interfaceFunction.skewAxis; 15012 } 15013 return null; 15014 } 15015 var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup); 15016 view.transform.mProps.o.setGroupProperty(PropertyInterface('Opacity', _propertyGroup)); 15017 view.transform.mProps.p.setGroupProperty(PropertyInterface('Position', _propertyGroup)); 15018 view.transform.mProps.a.setGroupProperty(PropertyInterface('Anchor Point', _propertyGroup)); 15019 view.transform.mProps.s.setGroupProperty(PropertyInterface('Scale', _propertyGroup)); 15020 view.transform.mProps.r.setGroupProperty(PropertyInterface('Rotation', _propertyGroup)); 15021 if (view.transform.mProps.sk) { 15022 view.transform.mProps.sk.setGroupProperty(PropertyInterface('Skew', _propertyGroup)); 15023 view.transform.mProps.sa.setGroupProperty(PropertyInterface('Skew Angle', _propertyGroup)); 15024 } 15025 view.transform.op.setGroupProperty(PropertyInterface('Opacity', _propertyGroup)); 15026 Object.defineProperties(interfaceFunction, { 15027 opacity: { 15028 get: ExpressionPropertyInterface(view.transform.mProps.o), 15029 }, 15030 position: { 15031 get: ExpressionPropertyInterface(view.transform.mProps.p), 15032 }, 15033 anchorPoint: { 15034 get: ExpressionPropertyInterface(view.transform.mProps.a), 15035 }, 15036 scale: { 15037 get: ExpressionPropertyInterface(view.transform.mProps.s), 15038 }, 15039 rotation: { 15040 get: ExpressionPropertyInterface(view.transform.mProps.r), 15041 }, 15042 skew: { 15043 get: ExpressionPropertyInterface(view.transform.mProps.sk), 15044 }, 15045 skewAxis: { 15046 get: ExpressionPropertyInterface(view.transform.mProps.sa), 15047 }, 15048 _name: { value: shape.nm }, 15049 }); 15050 interfaceFunction.ty = 'tr'; 15051 interfaceFunction.mn = shape.mn; 15052 interfaceFunction.propertyGroup = propertyGroup; 15053 return interfaceFunction; 15054 } 15055 15056 function ellipseInterfaceFactory(shape, view, propertyGroup) { 15057 function interfaceFunction(value) { 15058 if (shape.p.ix === value) { 15059 return interfaceFunction.position; 15060 } 15061 if (shape.s.ix === value) { 15062 return interfaceFunction.size; 15063 } 15064 return null; 15065 } 15066 var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup); 15067 interfaceFunction.propertyIndex = shape.ix; 15068 var prop = view.sh.ty === 'tm' ? view.sh.prop : view.sh; 15069 prop.s.setGroupProperty(PropertyInterface('Size', _propertyGroup)); 15070 prop.p.setGroupProperty(PropertyInterface('Position', _propertyGroup)); 15071 15072 Object.defineProperties(interfaceFunction, { 15073 size: { 15074 get: ExpressionPropertyInterface(prop.s), 15075 }, 15076 position: { 15077 get: ExpressionPropertyInterface(prop.p), 15078 }, 15079 _name: { value: shape.nm }, 15080 }); 15081 interfaceFunction.mn = shape.mn; 15082 return interfaceFunction; 15083 } 15084 15085 function starInterfaceFactory(shape, view, propertyGroup) { 15086 function interfaceFunction(value) { 15087 if (shape.p.ix === value) { 15088 return interfaceFunction.position; 15089 } 15090 if (shape.r.ix === value) { 15091 return interfaceFunction.rotation; 15092 } 15093 if (shape.pt.ix === value) { 15094 return interfaceFunction.points; 15095 } 15096 if (shape.or.ix === value || value === 'ADBE Vector Star Outer Radius') { 15097 return interfaceFunction.outerRadius; 15098 } 15099 if (shape.os.ix === value) { 15100 return interfaceFunction.outerRoundness; 15101 } 15102 if (shape.ir && (shape.ir.ix === value || value === 'ADBE Vector Star Inner Radius')) { 15103 return interfaceFunction.innerRadius; 15104 } 15105 if (shape.is && shape.is.ix === value) { 15106 return interfaceFunction.innerRoundness; 15107 } 15108 return null; 15109 } 15110 15111 var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup); 15112 var prop = view.sh.ty === 'tm' ? view.sh.prop : view.sh; 15113 interfaceFunction.propertyIndex = shape.ix; 15114 prop.or.setGroupProperty(PropertyInterface('Outer Radius', _propertyGroup)); 15115 prop.os.setGroupProperty(PropertyInterface('Outer Roundness', _propertyGroup)); 15116 prop.pt.setGroupProperty(PropertyInterface('Points', _propertyGroup)); 15117 prop.p.setGroupProperty(PropertyInterface('Position', _propertyGroup)); 15118 prop.r.setGroupProperty(PropertyInterface('Rotation', _propertyGroup)); 15119 if (shape.ir) { 15120 prop.ir.setGroupProperty(PropertyInterface('Inner Radius', _propertyGroup)); 15121 prop.is.setGroupProperty(PropertyInterface('Inner Roundness', _propertyGroup)); 15122 } 15123 15124 Object.defineProperties(interfaceFunction, { 15125 position: { 15126 get: ExpressionPropertyInterface(prop.p), 15127 }, 15128 rotation: { 15129 get: ExpressionPropertyInterface(prop.r), 15130 }, 15131 points: { 15132 get: ExpressionPropertyInterface(prop.pt), 15133 }, 15134 outerRadius: { 15135 get: ExpressionPropertyInterface(prop.or), 15136 }, 15137 outerRoundness: { 15138 get: ExpressionPropertyInterface(prop.os), 15139 }, 15140 innerRadius: { 15141 get: ExpressionPropertyInterface(prop.ir), 15142 }, 15143 innerRoundness: { 15144 get: ExpressionPropertyInterface(prop.is), 15145 }, 15146 _name: { value: shape.nm }, 15147 }); 15148 interfaceFunction.mn = shape.mn; 15149 return interfaceFunction; 15150 } 15151 15152 function rectInterfaceFactory(shape, view, propertyGroup) { 15153 function interfaceFunction(value) { 15154 if (shape.p.ix === value) { 15155 return interfaceFunction.position; 15156 } 15157 if (shape.r.ix === value) { 15158 return interfaceFunction.roundness; 15159 } 15160 if (shape.s.ix === value || value === 'Size' || value === 'ADBE Vector Rect Size') { 15161 return interfaceFunction.size; 15162 } 15163 return null; 15164 } 15165 var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup); 15166 15167 var prop = view.sh.ty === 'tm' ? view.sh.prop : view.sh; 15168 interfaceFunction.propertyIndex = shape.ix; 15169 prop.p.setGroupProperty(PropertyInterface('Position', _propertyGroup)); 15170 prop.s.setGroupProperty(PropertyInterface('Size', _propertyGroup)); 15171 prop.r.setGroupProperty(PropertyInterface('Rotation', _propertyGroup)); 15172 15173 Object.defineProperties(interfaceFunction, { 15174 position: { 15175 get: ExpressionPropertyInterface(prop.p), 15176 }, 15177 roundness: { 15178 get: ExpressionPropertyInterface(prop.r), 15179 }, 15180 size: { 15181 get: ExpressionPropertyInterface(prop.s), 15182 }, 15183 _name: { value: shape.nm }, 15184 }); 15185 interfaceFunction.mn = shape.mn; 15186 return interfaceFunction; 15187 } 15188 15189 function roundedInterfaceFactory(shape, view, propertyGroup) { 15190 function interfaceFunction(value) { 15191 if (shape.r.ix === value || value === 'Round Corners 1') { 15192 return interfaceFunction.radius; 15193 } 15194 return null; 15195 } 15196 15197 var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup); 15198 var prop = view; 15199 interfaceFunction.propertyIndex = shape.ix; 15200 prop.rd.setGroupProperty(PropertyInterface('Radius', _propertyGroup)); 15201 15202 Object.defineProperties(interfaceFunction, { 15203 radius: { 15204 get: ExpressionPropertyInterface(prop.rd), 15205 }, 15206 _name: { value: shape.nm }, 15207 }); 15208 interfaceFunction.mn = shape.mn; 15209 return interfaceFunction; 15210 } 15211 15212 function repeaterInterfaceFactory(shape, view, propertyGroup) { 15213 function interfaceFunction(value) { 15214 if (shape.c.ix === value || value === 'Copies') { 15215 return interfaceFunction.copies; 15216 } if (shape.o.ix === value || value === 'Offset') { 15217 return interfaceFunction.offset; 15218 } 15219 return null; 15220 } 15221 15222 var _propertyGroup = propertyGroupFactory(interfaceFunction, propertyGroup); 15223 var prop = view; 15224 interfaceFunction.propertyIndex = shape.ix; 15225 prop.c.setGroupProperty(PropertyInterface('Copies', _propertyGroup)); 15226 prop.o.setGroupProperty(PropertyInterface('Offset', _propertyGroup)); 15227 Object.defineProperties(interfaceFunction, { 15228 copies: { 15229 get: ExpressionPropertyInterface(prop.c), 15230 }, 15231 offset: { 15232 get: ExpressionPropertyInterface(prop.o), 15233 }, 15234 _name: { value: shape.nm }, 15235 }); 15236 interfaceFunction.mn = shape.mn; 15237 return interfaceFunction; 15238 } 15239 15240 return function (shapes, view, propertyGroup) { 15241 var interfaces; 15242 function _interfaceFunction(value) { 15243 if (typeof value === 'number') { 15244 value = value === undefined ? 1 : value; 15245 if (value === 0) { 15246 return propertyGroup; 15247 } 15248 return interfaces[value - 1]; 15249 } 15250 var i = 0; 15251 var len = interfaces.length; 15252 while (i < len) { 15253 if (interfaces[i]._name === value) { 15254 return interfaces[i]; 15255 } 15256 i += 1; 15257 } 15258 return null; 15259 } 15260 function parentGroupWrapper() { 15261 return propertyGroup; 15262 } 15263 _interfaceFunction.propertyGroup = propertyGroupFactory(_interfaceFunction, parentGroupWrapper); 15264 interfaces = iterateElements(shapes, view, _interfaceFunction.propertyGroup); 15265 _interfaceFunction.numProperties = interfaces.length; 15266 _interfaceFunction._name = 'Contents'; 15267 return _interfaceFunction; 15268 }; 15269}()); 15270
vendor: 29,754 bytes, lines 15271-16259
15271/* exported TextExpressionInterface */ 15272 15273var TextExpressionInterface = (function () { 15274 return function (elem) { 15275 var _prevValue; 15276 var _sourceText; 15277 function _thisLayerFunction(name) { 15278 switch (name) { 15279 case 'ADBE Text Document': 15280 return _thisLayerFunction.sourceText; 15281 default: 15282 return null; 15283 } 15284 } 15285 Object.defineProperty(_thisLayerFunction, 'sourceText', { 15286 get: function () { 15287 elem.textProperty.getValue(); 15288 var stringValue = elem.textProperty.currentData.t; 15289 if (stringValue !== _prevValue) { 15290 elem.textProperty.currentData.t = _prevValue; 15291 _sourceText = new String(stringValue); // eslint-disable-line no-new-wrappers 15292 // If stringValue is an empty string, eval returns undefined, so it has to be returned as a String primitive 15293 _sourceText.value = stringValue || new String(stringValue); // eslint-disable-line no-new-wrappers 15294 } 15295 return _sourceText; 15296 }, 15297 }); 15298 return _thisLayerFunction; 15299 }; 15300}()); 15301 15302/* global Matrix, MaskManagerInterface, TransformExpressionInterface, getDescriptor */ 15303/* exported LayerExpressionInterface */ 15304 15305var LayerExpressionInterface = (function () { 15306 function getMatrix(time) { 15307 var toWorldMat = new Matrix(); 15308 if (time !== undefined) { 15309 var propMatrix = this._elem.finalTransform.mProp.getValueAtTime(time); 15310 propMatrix.clone(toWorldMat); 15311 } else { 15312 var transformMat = this._elem.finalTransform.mProp; 15313 transformMat.applyToMatrix(toWorldMat); 15314 } 15315 return toWorldMat; 15316 } 15317 15318 function toWorldVec(arr, time) { 15319 var toWorldMat = this.getMatrix(time); 15320 toWorldMat.props[12] = 0; 15321 toWorldMat.props[13] = 0; 15322 toWorldMat.props[14] = 0; 15323 return this.applyPoint(toWorldMat, arr); 15324 } 15325 15326 function toWorld(arr, time) { 15327 var toWorldMat = this.getMatrix(time); 15328 return this.applyPoint(toWorldMat, arr); 15329 } 15330 15331 function fromWorldVec(arr, time) { 15332 var toWorldMat = this.getMatrix(time); 15333 toWorldMat.props[12] = 0; 15334 toWorldMat.props[13] = 0; 15335 toWorldMat.props[14] = 0; 15336 return this.invertPoint(toWorldMat, arr); 15337 } 15338 15339 function fromWorld(arr, time) { 15340 var toWorldMat = this.getMatrix(time); 15341 return this.invertPoint(toWorldMat, arr); 15342 } 15343 15344 function applyPoint(matrix, arr) { 15345 if (this._elem.hierarchy && this._elem.hierarchy.length) { 15346 var i; 15347 var len = this._elem.hierarchy.length; 15348 for (i = 0; i < len; i += 1) { 15349 this._elem.hierarchy[i].finalTransform.mProp.applyToMatrix(matrix); 15350 } 15351 } 15352 return matrix.applyToPointArray(arr[0], arr[1], arr[2] || 0); 15353 } 15354 15355 function invertPoint(matrix, arr) { 15356 if (this._elem.hierarchy && this._elem.hierarchy.length) { 15357 var i; 15358 var len = this._elem.hierarchy.length; 15359 for (i = 0; i < len; i += 1) { 15360 this._elem.hierarchy[i].finalTransform.mProp.applyToMatrix(matrix); 15361 } 15362 } 15363 return matrix.inversePoint(arr); 15364 } 15365 15366 function fromComp(arr) { 15367 var toWorldMat = new Matrix(); 15368 toWorldMat.reset(); 15369 this._elem.finalTransform.mProp.applyToMatrix(toWorldMat); 15370 if (this._elem.hierarchy && this._elem.hierarchy.length) { 15371 var i; 15372 var len = this._elem.hierarchy.length; 15373 for (i = 0; i < len; i += 1) { 15374 this._elem.hierarchy[i].finalTransform.mProp.applyToMatrix(toWorldMat); 15375 } 15376 return toWorldMat.inversePoint(arr); 15377 } 15378 return toWorldMat.inversePoint(arr); 15379 } 15380 15381 function sampleImage() { 15382 return [1, 1, 1, 1]; 15383 } 15384 15385 return function (elem) { 15386 var transformInterface; 15387 15388 function _registerMaskInterface(maskManager) { 15389 _thisLayerFunction.mask = new MaskManagerInterface(maskManager, elem); 15390 } 15391 function _registerEffectsInterface(effects) { 15392 _thisLayerFunction.effect = effects; 15393 } 15394 15395 function _thisLayerFunction(name) { 15396 switch (name) { 15397 case 'ADBE Root Vectors Group': 15398 case 'Contents': 15399 case 2: 15400 return _thisLayerFunction.shapeInterface; 15401 case 1: 15402 case 6: 15403 case 'Transform': 15404 case 'transform': 15405 case 'ADBE Transform Group': 15406 return transformInterface; 15407 case 4: 15408 case 'ADBE Effect Parade': 15409 case 'effects': 15410 case 'Effects': 15411 return _thisLayerFunction.effect; 15412 case 'ADBE Text Properties': 15413 return _thisLayerFunction.textInterface; 15414 default: 15415 return null; 15416 } 15417 } 15418 _thisLayerFunction.getMatrix = getMatrix; 15419 _thisLayerFunction.invertPoint = invertPoint; 15420 _thisLayerFunction.applyPoint = applyPoint; 15421 _thisLayerFunction.toWorld = toWorld; 15422 _thisLayerFunction.toWorldVec = toWorldVec; 15423 _thisLayerFunction.fromWorld = fromWorld; 15424 _thisLayerFunction.fromWorldVec = fromWorldVec; 15425 _thisLayerFunction.toComp = toWorld; 15426 _thisLayerFunction.fromComp = fromComp; 15427 _thisLayerFunction.sampleImage = sampleImage; 15428 _thisLayerFunction.sourceRectAtTime = elem.sourceRectAtTime.bind(elem); 15429 _thisLayerFunction._elem = elem; 15430 transformInterface = TransformExpressionInterface(elem.finalTransform.mProp); 15431 var anchorPointDescriptor = getDescriptor(transformInterface, 'anchorPoint'); 15432 Object.defineProperties(_thisLayerFunction, { 15433 hasParent: { 15434 get: function () { 15435 return elem.hierarchy.length; 15436 }, 15437 }, 15438 parent: { 15439 get: function () { 15440 return elem.hierarchy[0].layerInterface; 15441 }, 15442 }, 15443 rotation: getDescriptor(transformInterface, 'rotation'), 15444 scale: getDescriptor(transformInterface, 'scale'), 15445 position: getDescriptor(transformInterface, 'position'), 15446 opacity: getDescriptor(transformInterface, 'opacity'), 15447 anchorPoint: anchorPointDescriptor, 15448 anchor_point: anchorPointDescriptor, 15449 transform: { 15450 get: function () { 15451 return transformInterface; 15452 }, 15453 }, 15454 active: { 15455 get: function () { 15456 return elem.isInRange; 15457 }, 15458 }, 15459 }); 15460 15461 _thisLayerFunction.startTime = elem.data.st; 15462 _thisLayerFunction.index = elem.data.ind; 15463 _thisLayerFunction.source = elem.data.refId; 15464 _thisLayerFunction.height = elem.data.ty === 0 ? elem.data.h : 100; 15465 _thisLayerFunction.width = elem.data.ty === 0 ? elem.data.w : 100; 15466 _thisLayerFunction.inPoint = elem.data.ip / elem.comp.globalData.frameRate; 15467 _thisLayerFunction.outPoint = elem.data.op / elem.comp.globalData.frameRate; 15468 _thisLayerFunction._name = elem.data.nm; 15469 15470 _thisLayerFunction.registerMaskInterface = _registerMaskInterface; 15471 _thisLayerFunction.registerEffectsInterface = _registerEffectsInterface; 15472 return _thisLayerFunction; 15473 }; 15474}()); 15475 15476/* global */ 15477/* exported FootageInterface */ 15478 15479var FootageInterface = (function () { 15480 var outlineInterfaceFactory = (function (elem) { 15481 var currentPropertyName = ''; 15482 var currentProperty = elem.getFootageData(); 15483 function init() { 15484 currentPropertyName = ''; 15485 currentProperty = elem.getFootageData(); 15486 return searchProperty; 15487 } 15488 function searchProperty(value) { 15489 if (currentProperty[value]) { 15490 currentPropertyName = value; 15491 currentProperty = currentProperty[value]; 15492 if (typeof currentProperty === 'object') { 15493 return searchProperty; 15494 } 15495 return currentProperty; 15496 } 15497 var propertyNameIndex = value.indexOf(currentPropertyName); 15498 if (propertyNameIndex !== -1) { 15499 var index = parseInt(value.substr(propertyNameIndex + currentPropertyName.length), 10); 15500 currentProperty = currentProperty[index]; 15501 if (typeof currentProperty === 'object') { 15502 return searchProperty; 15503 } 15504 return currentProperty; 15505 } 15506 return ''; 15507 } 15508 return init; 15509 }); 15510 15511 var dataInterfaceFactory = function (elem) { 15512 function interfaceFunction(value) { 15513 if (value === 'Outline') { 15514 return interfaceFunction.outlineInterface(); 15515 } 15516 return null; 15517 } 15518 15519 interfaceFunction._name = 'Outline'; 15520 interfaceFunction.outlineInterface = outlineInterfaceFactory(elem); 15521 return interfaceFunction; 15522 }; 15523 15524 return function (elem) { 15525 function _interfaceFunction(value) { 15526 if (value === 'Data') { 15527 return _interfaceFunction.dataInterface; 15528 } 15529 return null; 15530 } 15531 15532 _interfaceFunction._name = 'Data'; 15533 _interfaceFunction.dataInterface = dataInterfaceFactory(elem); 15534 return _interfaceFunction; 15535 }; 15536}()); 15537 15538/* exported CompExpressionInterface */ 15539 15540var CompExpressionInterface = (function () { 15541 return function (comp) { 15542 function _thisLayerFunction(name) { 15543 var i = 0; 15544 var len = comp.layers.length; 15545 while (i < len) { 15546 if (comp.layers[i].nm === name || comp.layers[i].ind === name) { 15547 return comp.elements[i].layerInterface; 15548 } 15549 i += 1; 15550 } 15551 return null; 15552 // return {active:false}; 15553 } 15554 Object.defineProperty(_thisLayerFunction, '_name', { value: comp.data.nm }); 15555 _thisLayerFunction.layer = _thisLayerFunction; 15556 _thisLayerFunction.pixelAspect = 1; 15557 _thisLayerFunction.height = comp.data.h || comp.globalData.compSize.h; 15558 _thisLayerFunction.width = comp.data.w || comp.globalData.compSize.w; 15559 _thisLayerFunction.pixelAspect = 1; 15560 _thisLayerFunction.frameDuration = 1 / comp.globalData.frameRate; 15561 _thisLayerFunction.displayStartTime = 0; 15562 _thisLayerFunction.numLayers = comp.layers.length; 15563 return _thisLayerFunction; 15564 }; 15565}()); 15566 15567/* global ExpressionPropertyInterface */ 15568/* exported TransformExpressionInterface */ 15569 15570var TransformExpressionInterface = (function () { 15571 return function (transform) { 15572 function _thisFunction(name) { 15573 switch (name) { 15574 case 'scale': 15575 case 'Scale': 15576 case 'ADBE Scale': 15577 case 6: 15578 return _thisFunction.scale; 15579 case 'rotation': 15580 case 'Rotation': 15581 case 'ADBE Rotation': 15582 case 'ADBE Rotate Z': 15583 case 10: 15584 return _thisFunction.rotation; 15585 case 'ADBE Rotate X': 15586 return _thisFunction.xRotation; 15587 case 'ADBE Rotate Y': 15588 return _thisFunction.yRotation; 15589 case 'position': 15590 case 'Position': 15591 case 'ADBE Position': 15592 case 2: 15593 return _thisFunction.position; 15594 case 'ADBE Position_0': 15595 return _thisFunction.xPosition; 15596 case 'ADBE Position_1': 15597 return _thisFunction.yPosition; 15598 case 'ADBE Position_2': 15599 return _thisFunction.zPosition; 15600 case 'anchorPoint': 15601 case 'AnchorPoint': 15602 case 'Anchor Point': 15603 case 'ADBE AnchorPoint': 15604 case 1: 15605 return _thisFunction.anchorPoint; 15606 case 'opacity': 15607 case 'Opacity': 15608 case 11: 15609 return _thisFunction.opacity; 15610 default: 15611 return null; 15612 } 15613 } 15614 Object.defineProperty(_thisFunction, 'rotation', { 15615 get: ExpressionPropertyInterface(transform.r || transform.rz), 15616 }); 15617 15618 Object.defineProperty(_thisFunction, 'zRotation', { 15619 get: ExpressionPropertyInterface(transform.rz || transform.r), 15620 }); 15621 15622 Object.defineProperty(_thisFunction, 'xRotation', { 15623 get: ExpressionPropertyInterface(transform.rx), 15624 }); 15625 15626 Object.defineProperty(_thisFunction, 'yRotation', { 15627 get: ExpressionPropertyInterface(transform.ry), 15628 }); 15629 Object.defineProperty(_thisFunction, 'scale', { 15630 get: ExpressionPropertyInterface(transform.s), 15631 }); 15632 var _px; 15633 var _py; 15634 var _pz; 15635 var _transformFactory; 15636 if (transform.p) { 15637 _transformFactory = ExpressionPropertyInterface(transform.p); 15638 } else { 15639 _px = ExpressionPropertyInterface(transform.px); 15640 _py = ExpressionPropertyInterface(transform.py); 15641 if (transform.pz) { 15642 _pz = ExpressionPropertyInterface(transform.pz); 15643 } 15644 } 15645 Object.defineProperty(_thisFunction, 'position', { 15646 get: function () { 15647 if (transform.p) { 15648 return _transformFactory(); 15649 } 15650 return [ 15651 _px(), 15652 _py(), 15653 _pz ? _pz() : 0]; 15654 }, 15655 }); 15656 15657 Object.defineProperty(_thisFunction, 'xPosition', { 15658 get: ExpressionPropertyInterface(transform.px), 15659 }); 15660 15661 Object.defineProperty(_thisFunction, 'yPosition', { 15662 get: ExpressionPropertyInterface(transform.py), 15663 }); 15664 15665 Object.defineProperty(_thisFunction, 'zPosition', { 15666 get: ExpressionPropertyInterface(transform.pz), 15667 }); 15668 15669 Object.defineProperty(_thisFunction, 'anchorPoint', { 15670 get: ExpressionPropertyInterface(transform.a), 15671 }); 15672 15673 Object.defineProperty(_thisFunction, 'opacity', { 15674 get: ExpressionPropertyInterface(transform.o), 15675 }); 15676 15677 Object.defineProperty(_thisFunction, 'skew', { 15678 get: ExpressionPropertyInterface(transform.sk), 15679 }); 15680 15681 Object.defineProperty(_thisFunction, 'skewAxis', { 15682 get: ExpressionPropertyInterface(transform.sa), 15683 }); 15684 15685 Object.defineProperty(_thisFunction, 'orientation', { 15686 get: ExpressionPropertyInterface(transform.or), 15687 }); 15688 15689 return _thisFunction; 15690 }; 15691}()); 15692 15693/* exported ProjectInterface */ 15694 15695var ProjectInterface = (function () { 15696 function registerComposition(comp) { 15697 this.compositions.push(comp); 15698 } 15699 15700 return function () { 15701 function _thisProjectFunction(name) { 15702 var i = 0; 15703 var len = this.compositions.length; 15704 while (i < len) { 15705 if (this.compositions[i].data && this.compositions[i].data.nm === name) { 15706 if (this.compositions[i].prepareFrame && this.compositions[i].data.xt) { 15707 this.compositions[i].prepareFrame(this.currentFrame); 15708 } 15709 return this.compositions[i].compInterface; 15710 } 15711 i += 1; 15712 } 15713 return null; 15714 } 15715 15716 _thisProjectFunction.compositions = []; 15717 _thisProjectFunction.currentFrame = 0; 15718 15719 _thisProjectFunction.registerComposition = registerComposition; 15720 15721 return _thisProjectFunction; 15722 }; 15723}()); 15724 15725/* global propertyGroupFactory, ExpressionPropertyInterface, PropertyInterface */ 15726/* exported EffectsExpressionInterface */ 15727 15728var EffectsExpressionInterface = (function () { 15729 var ob = { 15730 createEffectsInterface: createEffectsInterface, 15731 }; 15732 15733 function createEffectsInterface(elem, propertyGroup) { 15734 if (elem.effectsManager) { 15735 var effectElements = []; 15736 var effectsData = elem.data.ef; 15737 var i; 15738 var len = elem.effectsManager.effectElements.length; 15739 for (i = 0; i < len; i += 1) { 15740 effectElements.push(createGroupInterface(effectsData[i], elem.effectsManager.effectElements[i], propertyGroup, elem)); 15741 } 15742 15743 var effects = elem.data.ef || []; 15744 var groupInterface = function (name) { 15745 i = 0; 15746 len = effects.length; 15747 while (i < len) { 15748 if (name === effects[i].nm || name === effects[i].mn || name === effects[i].ix) { 15749 return effectElements[i]; 15750 } 15751 i += 1; 15752 } 15753 return null; 15754 }; 15755 Object.defineProperty(groupInterface, 'numProperties', { 15756 get: function () { 15757 return effects.length; 15758 }, 15759 }); 15760 return groupInterface; 15761 } 15762 return null; 15763 } 15764 15765 function createGroupInterface(data, elements, propertyGroup, elem) { 15766 function groupInterface(name) { 15767 var effects = data.ef; 15768 var i = 0; 15769 var len = effects.length; 15770 while (i < len) { 15771 if (name === effects[i].nm || name === effects[i].mn || name === effects[i].ix) { 15772 if (effects[i].ty === 5) { 15773 return effectElements[i]; 15774 } 15775 return effectElements[i](); 15776 } 15777 i += 1; 15778 } 15779 throw new Error(); 15780 } 15781 var _propertyGroup = propertyGroupFactory(groupInterface, propertyGroup); 15782 15783 var effectElements = []; 15784 var i; 15785 var len = data.ef.length; 15786 for (i = 0; i < len; i += 1) { 15787 if (data.ef[i].ty === 5) { 15788 effectElements.push(createGroupInterface(data.ef[i], elements.effectElements[i], elements.effectElements[i].propertyGroup, elem)); 15789 } else { 15790 effectElements.push(createValueInterface(elements.effectElements[i], data.ef[i].ty, elem, _propertyGroup)); 15791 } 15792 } 15793 15794 if (data.mn === 'ADBE Color Control') { 15795 Object.defineProperty(groupInterface, 'color', { 15796 get: function () { 15797 return effectElements[0](); 15798 }, 15799 }); 15800 } 15801 Object.defineProperties(groupInterface, { 15802 numProperties: { 15803 get: function () { 15804 return data.np; 15805 }, 15806 }, 15807 _name: { value: data.nm }, 15808 propertyGroup: { value: _propertyGroup }, 15809 }); 15810 groupInterface.enabled = data.en !== 0; 15811 groupInterface.active = groupInterface.enabled; 15812 return groupInterface; 15813 } 15814 15815 function createValueInterface(element, type, elem, propertyGroup) { 15816 var expressionProperty = ExpressionPropertyInterface(element.p); 15817 function interfaceFunction() { 15818 if (type === 10) { 15819 return elem.comp.compInterface(element.p.v); 15820 } 15821 return expressionProperty(); 15822 } 15823 15824 if (element.p.setGroupProperty) { 15825 element.p.setGroupProperty(PropertyInterface('', propertyGroup)); 15826 } 15827 15828 return interfaceFunction; 15829 } 15830 15831 return ob; 15832}()); 15833 15834/* global createSizedArray */ 15835/* exported MaskManagerInterface */ 15836 15837var MaskManagerInterface = (function () { 15838 function MaskInterface(mask, data) { 15839 this._mask = mask; 15840 this._data = data; 15841 } 15842 Object.defineProperty(MaskInterface.prototype, 'maskPath', { 15843 get: function () { 15844 if (this._mask.prop.k) { 15845 this._mask.prop.getValue(); 15846 } 15847 return this._mask.prop; 15848 }, 15849 }); 15850 Object.defineProperty(MaskInterface.prototype, 'maskOpacity', { 15851 get: function () { 15852 if (this._mask.op.k) { 15853 this._mask.op.getValue(); 15854 } 15855 return this._mask.op.v * 100; 15856 }, 15857 }); 15858 15859 var MaskManager = function (maskManager) { 15860 var _masksInterfaces = createSizedArray(maskManager.viewData.length); 15861 var i; 15862 var len = maskManager.viewData.length; 15863 for (i = 0; i < len; i += 1) { 15864 _masksInterfaces[i] = new MaskInterface(maskManager.viewData[i], maskManager.masksProperties[i]); 15865 } 15866 15867 var maskFunction = function (name) { 15868 i = 0; 15869 while (i < len) { 15870 if (maskManager.masksProperties[i].nm === name) { 15871 return _masksInterfaces[i]; 15872 } 15873 i += 1; 15874 } 15875 return null; 15876 }; 15877 return maskFunction; 15878 }; 15879 return MaskManager; 15880}()); 15881 15882/* global createTypedArray */ 15883/* exported ExpressionPropertyInterface */ 15884 15885var ExpressionPropertyInterface = (function () { 15886 var defaultUnidimensionalValue = { pv: 0, v: 0, mult: 1 }; 15887 var defaultMultidimensionalValue = { pv: [0, 0, 0], v: [0, 0, 0], mult: 1 }; 15888 15889 function completeProperty(expressionValue, property, type) { 15890 Object.defineProperty(expressionValue, 'velocity', { 15891 get: function () { 15892 return property.getVelocityAtTime(property.comp.currentFrame); 15893 }, 15894 }); 15895 expressionValue.numKeys = property.keyframes ? property.keyframes.length : 0; 15896 expressionValue.key = function (pos) { 15897 if (!expressionValue.numKeys) { 15898 return 0; 15899 } 15900 var value = ''; 15901 if ('s' in property.keyframes[pos - 1]) { 15902 value = property.keyframes[pos - 1].s; 15903 } else if ('e' in property.keyframes[pos - 2]) { 15904 value = property.keyframes[pos - 2].e; 15905 } else { 15906 value = property.keyframes[pos - 2].s; 15907 } 15908 var valueProp = type === 'unidimensional' ? new Number(value) : Object.assign({}, value); // eslint-disable-line no-new-wrappers 15909 valueProp.time = property.keyframes[pos - 1].t / property.elem.comp.globalData.frameRate; 15910 valueProp.value = type === 'unidimensional' ? value[0] : value; 15911 return valueProp; 15912 }; 15913 expressionValue.valueAtTime = property.getValueAtTime; 15914 expressionValue.speedAtTime = property.getSpeedAtTime; 15915 expressionValue.velocityAtTime = property.getVelocityAtTime; 15916 expressionValue.propertyGroup = property.propertyGroup; 15917 } 15918 15919 function UnidimensionalPropertyInterface(property) { 15920 if (!property || !('pv' in property)) { 15921 property = defaultUnidimensionalValue; 15922 } 15923 var mult = 1 / property.mult; 15924 var val = property.pv * mult; 15925 var expressionValue = new Number(val); // eslint-disable-line no-new-wrappers 15926 expressionValue.value = val; 15927 completeProperty(expressionValue, property, 'unidimensional'); 15928 15929 return function () { 15930 if (property.k) { 15931 property.getValue(); 15932 } 15933 val = property.v * mult; 15934 if (expressionValue.value !== val) { 15935 expressionValue = new Number(val); // eslint-disable-line no-new-wrappers 15936 expressionValue.value = val; 15937 completeProperty(expressionValue, property, 'unidimensional'); 15938 } 15939 return expressionValue; 15940 }; 15941 } 15942 15943 function MultidimensionalPropertyInterface(property) { 15944 if (!property || !('pv' in property)) { 15945 property = defaultMultidimensionalValue; 15946 } 15947 var mult = 1 / property.mult; 15948 var len = (property.data && property.data.l) || property.pv.length; 15949 var expressionValue = createTypedArray('float32', len); 15950 var arrValue = createTypedArray('float32', len); 15951 expressionValue.value = arrValue; 15952 completeProperty(expressionValue, property, 'multidimensional'); 15953 15954 return function () { 15955 if (property.k) { 15956 property.getValue(); 15957 } 15958 for (var i = 0; i < len; i += 1) { 15959 arrValue[i] = property.v[i] * mult; 15960 expressionValue[i] = arrValue[i]; 15961 } 15962 return expressionValue; 15963 }; 15964 } 15965 15966 // TODO: try to avoid using this getter 15967 function defaultGetter() { 15968 return defaultUnidimensionalValue; 15969 } 15970 15971 return function (property) { 15972 if (!property) { 15973 return defaultGetter; 15974 } if (property.propType === 'unidimensional') { 15975 return UnidimensionalPropertyInterface(property); 15976 } 15977 return MultidimensionalPropertyInterface(property); 15978 }; 15979}()); 15980 15981/* global expressionHelpers, TextSelectorProp, ExpressionManager */ 15982/* exported TextExpressionSelectorPropFactory */ 15983 15984var TextExpressionSelectorPropFactory = (function () { // eslint-disable-line no-unused-vars 15985 function getValueProxy(index, total) { 15986 this.textIndex = index + 1; 15987 this.textTotal = total; 15988 this.v = this.getValue() * this.mult; 15989 return this.v; 15990 } 15991 15992 return function (elem, data) { 15993 this.pv = 1; 15994 this.comp = elem.comp; 15995 this.elem = elem; 15996 this.mult = 0.01; 15997 this.propType = 'textSelector'; 15998 this.textTotal = data.totalChars; 15999 this.selectorValue = 100; 16000 this.lastValue = [1, 1, 1]; 16001 this.k = true; 16002 this.x = true; 16003 this.getValue = ExpressionManager.initiateExpression.bind(this)(elem, data, this); 16004 this.getMult = getValueProxy; 16005 this.getVelocityAtTime = expressionHelpers.getVelocityAtTime; 16006 if (this.kf) { 16007 this.getValueAtTime = expressionHelpers.getValueAtTime.bind(this); 16008 } else { 16009 this.getValueAtTime = expressionHelpers.getStaticValueAtTime.bind(this); 16010 } 16011 this.setGroupProperty = expressionHelpers.setGroupProperty; 16012 }; 16013}()); 16014 16015var propertyGetTextProp = TextSelectorProp.getTextSelectorProp; 16016TextSelectorProp.getTextSelectorProp = function (elem, data, arr) { 16017 if (data.t === 1) { 16018 return new TextExpressionSelectorPropFactory(elem, data, arr); // eslint-disable-line no-undef 16019 } 16020 return propertyGetTextProp(elem, data, arr); 16021}; 16022 16023/* global PropertyFactory */ 16024/* exported SliderEffect, AngleEffect, ColorEffect, PointEffect, LayerIndexEffect, MaskIndexEffect, CheckboxEffect, NoValueEffect */ 16025 16026function SliderEffect(data, elem, container) { 16027 this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container); 16028} 16029function AngleEffect(data, elem, container) { 16030 this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container); 16031} 16032function ColorEffect(data, elem, container) { 16033 this.p = PropertyFactory.getProp(elem, data.v, 1, 0, container); 16034} 16035function PointEffect(data, elem, container) { 16036 this.p = PropertyFactory.getProp(elem, data.v, 1, 0, container); 16037} 16038function LayerIndexEffect(data, elem, container) { 16039 this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container); 16040} 16041function MaskIndexEffect(data, elem, container) { 16042 this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container); 16043} 16044function CheckboxEffect(data, elem, container) { 16045 this.p = PropertyFactory.getProp(elem, data.v, 0, 0, container); 16046} 16047function NoValueEffect() { 16048 this.p = {}; 16049} 16050 16051/* global extendPrototype, SliderEffect, AngleEffect, ColorEffect, PointEffect, CheckboxEffect, LayerIndexEffect, 16052MaskIndexEffect, NoValueEffect, DynamicPropertyContainer */ 16053 16054function EffectsManager(data, element) { 16055 var effects = data.ef || []; 16056 this.effectElements = []; 16057 var i; 16058 var len = effects.length; 16059 var effectItem; 16060 for (i = 0; i < len; i += 1) { 16061 effectItem = new GroupEffect(effects[i], element); 16062 this.effectElements.push(effectItem); 16063 } 16064} 16065 16066function GroupEffect(data, element) { 16067 this.init(data, element); 16068} 16069 16070extendPrototype([DynamicPropertyContainer], GroupEffect); 16071 16072GroupEffect.prototype.getValue = GroupEffect.prototype.iterateDynamicProperties; 16073 16074GroupEffect.prototype.init = function (data, element) { 16075 this.data = data; 16076 this.effectElements = []; 16077 this.initDynamicPropertyContainer(element); 16078 var i; 16079 var len = this.data.ef.length; 16080 var eff; 16081 var effects = this.data.ef; 16082 for (i = 0; i < len; i += 1) { 16083 eff = null; 16084 switch (effects[i].ty) { 16085 case 0: 16086 eff = new SliderEffect(effects[i], element, this); 16087 break; 16088 case 1: 16089 eff = new AngleEffect(effects[i], element, this); 16090 break; 16091 case 2: 16092 eff = new ColorEffect(effects[i], element, this); 16093 break; 16094 case 3: 16095 eff = new PointEffect(effects[i], element, this); 16096 break; 16097 case 4: 16098 case 7: 16099 eff = new CheckboxEffect(effects[i], element, this); 16100 break; 16101 case 10: 16102 eff = new LayerIndexEffect(effects[i], element, this); 16103 break; 16104 case 11: 16105 eff = new MaskIndexEffect(effects[i], element, this); 16106 break; 16107 case 5: 16108 eff = new EffectsManager(effects[i], element, this); 16109 break; 16110 // case 6: 16111 default: 16112 eff = new NoValueEffect(effects[i], element, this); 16113 break; 16114 } 16115 if (eff) { 16116 this.effectElements.push(eff); 16117 } 16118 } 16119}; 16120 16121 16122var lottie = {}; 16123 16124function setLocationHref(href) { 16125 locationHref = href; 16126} 16127 16128function searchAnimations() { 16129 if (standalone === true) { 16130 animationManager.searchAnimations(animationData, standalone, renderer); 16131 } else { 16132 animationManager.searchAnimations(); 16133 } 16134} 16135 16136function setSubframeRendering(flag) { 16137 subframeEnabled = flag; 16138} 16139 16140function setIDPrefix(prefix) { 16141 idPrefix = prefix; 16142} 16143 16144function loadAnimation(params) { 16145 if (standalone === true) { 16146 params.animationData = JSON.parse(animationData); 16147 } 16148 return animationManager.loadAnimation(params); 16149} 16150 16151function setQuality(value) { 16152 if (typeof value === 'string') { 16153 switch (value) { 16154 case 'high': 16155 defaultCurveSegments = 200; 16156 break; 16157 default: 16158 case 'medium': 16159 defaultCurveSegments = 50; 16160 break; 16161 case 'low': 16162 defaultCurveSegments = 10; 16163 break; 16164 } 16165 } else if (!isNaN(value) && value > 1) { 16166 defaultCurveSegments = value; 16167 } 16168 if (defaultCurveSegments >= 50) { 16169 roundValues(false); 16170 } else { 16171 roundValues(true); 16172 } 16173} 16174 16175function inBrowser() { 16176 return typeof navigator !== 'undefined'; 16177} 16178 16179function installPlugin(type, plugin) { 16180 if (type === 'expressions') { 16181 expressionsPlugin = plugin; 16182 } 16183} 16184 16185function getFactory(name) { 16186 switch (name) { 16187 case 'propertyFactory': 16188 return PropertyFactory; 16189 case 'shapePropertyFactory': 16190 return ShapePropertyFactory; 16191 case 'matrix': 16192 return Matrix; 16193 default: 16194 return null; 16195 } 16196} 16197 16198lottie.play = animationManager.play; 16199lottie.pause = animationManager.pause; 16200lottie.setLocationHref = setLocationHref; 16201lottie.togglePause = animationManager.togglePause; 16202lottie.setSpeed = animationManager.setSpeed; 16203lottie.setDirection = animationManager.setDirection; 16204lottie.stop = animationManager.stop; 16205lottie.searchAnimations = searchAnimations; 16206lottie.registerAnimation = animationManager.registerAnimation; 16207lottie.loadAnimation = loadAnimation; 16208lottie.setSubframeRendering = setSubframeRendering; 16209lottie.resize = animationManager.resize; 16210// lottie.start = start; 16211lottie.goToAndStop = animationManager.goToAndStop; 16212lottie.destroy = animationManager.destroy; 16213lottie.setQuality = setQuality; 16214lottie.inBrowser = inBrowser; 16215lottie.installPlugin = installPlugin; 16216lottie.freeze = animationManager.freeze; 16217lottie.unfreeze = animationManager.unfreeze; 16218lottie.setVolume = animationManager.setVolume; 16219lottie.mute = animationManager.mute; 16220lottie.unmute = animationManager.unmute; 16221lottie.getRegisteredAnimations = animationManager.getRegisteredAnimations; 16222lottie.setIDPrefix = setIDPrefix; 16223lottie.__getFactory = getFactory; 16224lottie.version = '5.7.12'; 16225 16226function checkReady() { 16227 if (document.readyState === 'complete') { 16228 clearInterval(readyStateCheckInterval); 16229 searchAnimations(); 16230 } 16231} 16232 16233function getQueryVariable(variable) { 16234 var vars = queryString.split('&'); 16235 for (var i = 0; i < vars.length; i += 1) { 16236 var pair = vars[i].split('='); 16237 if (decodeURIComponent(pair[0]) == variable) { // eslint-disable-line eqeqeq 16238 return decodeURIComponent(pair[1]); 16239 } 16240 } 16241 return null; 16242} 16243var standalone = '__[STANDALONE]__'; 16244var animationData = '__[ANIMATIONDATA]__'; 16245var renderer = ''; 16246var queryString; 16247if (standalone) { 16248 var scripts = document.getElementsByTagName('script'); 16249 var index = scripts.length - 1; 16250 var myScript = scripts[index] || { 16251 src: '', 16252 }; 16253 queryString = myScript.src.replace(/^[^\?]+\??/, ''); // eslint-disable-line no-useless-escape 16254 renderer = getQueryVariable('renderer'); 16255} 16256var readyStateCheckInterval = setInterval(checkReady, 100); 16257 16258return lottie; 16259}));
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.