ExpressionManager.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. /* eslint-disable camelcase */
  2. import {
  3. degToRads,
  4. BMMath,
  5. } from '../common';
  6. import {
  7. createTypedArray,
  8. } from '../helpers/arrays';
  9. import BezierFactory from '../../3rd_party/BezierEaser';
  10. import shapePool from '../pooling/shape_pool';
  11. import seedrandom from '../../3rd_party/seedrandom';
  12. import propTypes from '../helpers/propTypes';
  13. const ExpressionManager = (function () {
  14. 'use strict';
  15. var ob = {};
  16. var Math = BMMath;
  17. var window = null;
  18. var document = null;
  19. var XMLHttpRequest = null;
  20. var fetch = null;
  21. var frames = null;
  22. var _lottieGlobal = {};
  23. seedrandom(BMMath);
  24. function resetFrame() {
  25. _lottieGlobal = {};
  26. }
  27. function $bm_isInstanceOfArray(arr) {
  28. return arr.constructor === Array || arr.constructor === Float32Array;
  29. }
  30. function isNumerable(tOfV, v) {
  31. return tOfV === 'number' || v instanceof Number || tOfV === 'boolean' || tOfV === 'string';
  32. }
  33. function $bm_neg(a) {
  34. var tOfA = typeof a;
  35. if (tOfA === 'number' || a instanceof Number || tOfA === 'boolean') {
  36. return -a;
  37. }
  38. if ($bm_isInstanceOfArray(a)) {
  39. var i;
  40. var lenA = a.length;
  41. var retArr = [];
  42. for (i = 0; i < lenA; i += 1) {
  43. retArr[i] = -a[i];
  44. }
  45. return retArr;
  46. }
  47. if (a.propType) {
  48. return a.v;
  49. }
  50. return -a;
  51. }
  52. var easeInBez = BezierFactory.getBezierEasing(0.333, 0, 0.833, 0.833, 'easeIn').get;
  53. var easeOutBez = BezierFactory.getBezierEasing(0.167, 0.167, 0.667, 1, 'easeOut').get;
  54. var easeInOutBez = BezierFactory.getBezierEasing(0.33, 0, 0.667, 1, 'easeInOut').get;
  55. function sum(a, b) {
  56. var tOfA = typeof a;
  57. var tOfB = typeof b;
  58. if ((isNumerable(tOfA, a) && isNumerable(tOfB, b)) || tOfA === 'string' || tOfB === 'string') {
  59. return a + b;
  60. }
  61. if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) {
  62. a = a.slice(0);
  63. a[0] += b;
  64. return a;
  65. }
  66. if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) {
  67. b = b.slice(0);
  68. b[0] = a + b[0];
  69. return b;
  70. }
  71. if ($bm_isInstanceOfArray(a) && $bm_isInstanceOfArray(b)) {
  72. var i = 0;
  73. var lenA = a.length;
  74. var lenB = b.length;
  75. var retArr = [];
  76. while (i < lenA || i < lenB) {
  77. if ((typeof a[i] === 'number' || a[i] instanceof Number) && (typeof b[i] === 'number' || b[i] instanceof Number)) {
  78. retArr[i] = a[i] + b[i];
  79. } else {
  80. retArr[i] = b[i] === undefined ? a[i] : a[i] || b[i];
  81. }
  82. i += 1;
  83. }
  84. return retArr;
  85. }
  86. return 0;
  87. }
  88. var add = sum;
  89. function sub(a, b) {
  90. var tOfA = typeof a;
  91. var tOfB = typeof b;
  92. if (isNumerable(tOfA, a) && isNumerable(tOfB, b)) {
  93. if (tOfA === 'string') {
  94. a = parseInt(a, 10);
  95. }
  96. if (tOfB === 'string') {
  97. b = parseInt(b, 10);
  98. }
  99. return a - b;
  100. }
  101. if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) {
  102. a = a.slice(0);
  103. a[0] -= b;
  104. return a;
  105. }
  106. if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) {
  107. b = b.slice(0);
  108. b[0] = a - b[0];
  109. return b;
  110. }
  111. if ($bm_isInstanceOfArray(a) && $bm_isInstanceOfArray(b)) {
  112. var i = 0;
  113. var lenA = a.length;
  114. var lenB = b.length;
  115. var retArr = [];
  116. while (i < lenA || i < lenB) {
  117. if ((typeof a[i] === 'number' || a[i] instanceof Number) && (typeof b[i] === 'number' || b[i] instanceof Number)) {
  118. retArr[i] = a[i] - b[i];
  119. } else {
  120. retArr[i] = b[i] === undefined ? a[i] : a[i] || b[i];
  121. }
  122. i += 1;
  123. }
  124. return retArr;
  125. }
  126. return 0;
  127. }
  128. function mul(a, b) {
  129. var tOfA = typeof a;
  130. var tOfB = typeof b;
  131. var arr;
  132. if (isNumerable(tOfA, a) && isNumerable(tOfB, b)) {
  133. return a * b;
  134. }
  135. var i;
  136. var len;
  137. if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) {
  138. len = a.length;
  139. arr = createTypedArray('float32', len);
  140. for (i = 0; i < len; i += 1) {
  141. arr[i] = a[i] * b;
  142. }
  143. return arr;
  144. }
  145. if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) {
  146. len = b.length;
  147. arr = createTypedArray('float32', len);
  148. for (i = 0; i < len; i += 1) {
  149. arr[i] = a * b[i];
  150. }
  151. return arr;
  152. }
  153. return 0;
  154. }
  155. function div(a, b) {
  156. var tOfA = typeof a;
  157. var tOfB = typeof b;
  158. var arr;
  159. if (isNumerable(tOfA, a) && isNumerable(tOfB, b)) {
  160. return a / b;
  161. }
  162. var i;
  163. var len;
  164. if ($bm_isInstanceOfArray(a) && isNumerable(tOfB, b)) {
  165. len = a.length;
  166. arr = createTypedArray('float32', len);
  167. for (i = 0; i < len; i += 1) {
  168. arr[i] = a[i] / b;
  169. }
  170. return arr;
  171. }
  172. if (isNumerable(tOfA, a) && $bm_isInstanceOfArray(b)) {
  173. len = b.length;
  174. arr = createTypedArray('float32', len);
  175. for (i = 0; i < len; i += 1) {
  176. arr[i] = a / b[i];
  177. }
  178. return arr;
  179. }
  180. return 0;
  181. }
  182. function mod(a, b) {
  183. if (typeof a === 'string') {
  184. a = parseInt(a, 10);
  185. }
  186. if (typeof b === 'string') {
  187. b = parseInt(b, 10);
  188. }
  189. return a % b;
  190. }
  191. var $bm_sum = sum;
  192. var $bm_sub = sub;
  193. var $bm_mul = mul;
  194. var $bm_div = div;
  195. var $bm_mod = mod;
  196. function clamp(num, min, max) {
  197. if (min > max) {
  198. var mm = max;
  199. max = min;
  200. min = mm;
  201. }
  202. return Math.min(Math.max(num, min), max);
  203. }
  204. function radiansToDegrees(val) {
  205. return val / degToRads;
  206. }
  207. var radians_to_degrees = radiansToDegrees;
  208. function degreesToRadians(val) {
  209. return val * degToRads;
  210. }
  211. var degrees_to_radians = radiansToDegrees;
  212. var helperLengthArray = [0, 0, 0, 0, 0, 0];
  213. function length(arr1, arr2) {
  214. if (typeof arr1 === 'number' || arr1 instanceof Number) {
  215. arr2 = arr2 || 0;
  216. return Math.abs(arr1 - arr2);
  217. }
  218. if (!arr2) {
  219. arr2 = helperLengthArray;
  220. }
  221. var i;
  222. var len = Math.min(arr1.length, arr2.length);
  223. var addedLength = 0;
  224. for (i = 0; i < len; i += 1) {
  225. addedLength += Math.pow(arr2[i] - arr1[i], 2);
  226. }
  227. return Math.sqrt(addedLength);
  228. }
  229. function normalize(vec) {
  230. return div(vec, length(vec));
  231. }
  232. function rgbToHsl(val) {
  233. var r = val[0]; var g = val[1]; var b = val[2];
  234. var max = Math.max(r, g, b);
  235. var min = Math.min(r, g, b);
  236. var h;
  237. var s;
  238. var l = (max + min) / 2;
  239. if (max === min) {
  240. h = 0; // achromatic
  241. s = 0; // achromatic
  242. } else {
  243. var d = max - min;
  244. s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
  245. switch (max) {
  246. case r: h = (g - b) / d + (g < b ? 6 : 0); break;
  247. case g: h = (b - r) / d + 2; break;
  248. case b: h = (r - g) / d + 4; break;
  249. default: break;
  250. }
  251. h /= 6;
  252. }
  253. return [h, s, l, val[3]];
  254. }
  255. function hue2rgb(p, q, t) {
  256. if (t < 0) t += 1;
  257. if (t > 1) t -= 1;
  258. if (t < 1 / 6) return p + (q - p) * 6 * t;
  259. if (t < 1 / 2) return q;
  260. if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
  261. return p;
  262. }
  263. function hslToRgb(val) {
  264. var h = val[0];
  265. var s = val[1];
  266. var l = val[2];
  267. var r;
  268. var g;
  269. var b;
  270. if (s === 0) {
  271. r = l; // achromatic
  272. b = l; // achromatic
  273. g = l; // achromatic
  274. } else {
  275. var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
  276. var p = 2 * l - q;
  277. r = hue2rgb(p, q, h + 1 / 3);
  278. g = hue2rgb(p, q, h);
  279. b = hue2rgb(p, q, h - 1 / 3);
  280. }
  281. return [r, g, b, val[3]];
  282. }
  283. function linear(t, tMin, tMax, value1, value2) {
  284. if (value1 === undefined || value2 === undefined) {
  285. value1 = tMin;
  286. value2 = tMax;
  287. tMin = 0;
  288. tMax = 1;
  289. }
  290. if (tMax < tMin) {
  291. var _tMin = tMax;
  292. tMax = tMin;
  293. tMin = _tMin;
  294. }
  295. if (t <= tMin) {
  296. return value1;
  297. } if (t >= tMax) {
  298. return value2;
  299. }
  300. var perc = tMax === tMin ? 0 : (t - tMin) / (tMax - tMin);
  301. if (!value1.length) {
  302. return value1 + (value2 - value1) * perc;
  303. }
  304. var i;
  305. var len = value1.length;
  306. var arr = createTypedArray('float32', len);
  307. for (i = 0; i < len; i += 1) {
  308. arr[i] = value1[i] + (value2[i] - value1[i]) * perc;
  309. }
  310. return arr;
  311. }
  312. function random(min, max) {
  313. if (max === undefined) {
  314. if (min === undefined) {
  315. min = 0;
  316. max = 1;
  317. } else {
  318. max = min;
  319. min = undefined;
  320. }
  321. }
  322. if (max.length) {
  323. var i;
  324. var len = max.length;
  325. if (!min) {
  326. min = createTypedArray('float32', len);
  327. }
  328. var arr = createTypedArray('float32', len);
  329. var rnd = BMMath.random();
  330. for (i = 0; i < len; i += 1) {
  331. arr[i] = min[i] + rnd * (max[i] - min[i]);
  332. }
  333. return arr;
  334. }
  335. if (min === undefined) {
  336. min = 0;
  337. }
  338. var rndm = BMMath.random();
  339. return min + rndm * (max - min);
  340. }
  341. function createPath(points, inTangents, outTangents, closed) {
  342. var i;
  343. var len = points.length;
  344. var path = shapePool.newElement();
  345. path.setPathData(!!closed, len);
  346. var arrPlaceholder = [0, 0];
  347. var inVertexPoint;
  348. var outVertexPoint;
  349. for (i = 0; i < len; i += 1) {
  350. inVertexPoint = (inTangents && inTangents[i]) ? inTangents[i] : arrPlaceholder;
  351. outVertexPoint = (outTangents && outTangents[i]) ? outTangents[i] : arrPlaceholder;
  352. 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);
  353. }
  354. return path;
  355. }
  356. function initiateExpression(elem, data, property) {
  357. // Bail out if we don't want expressions
  358. function noOp(_value) {
  359. return _value;
  360. }
  361. if (!elem.globalData.renderConfig.runExpressions) {
  362. return noOp;
  363. }
  364. var val = data.x;
  365. var needsVelocity = /velocity(?![\w\d])/.test(val);
  366. var _needsRandom = val.indexOf('random') !== -1;
  367. var elemType = elem.data.ty;
  368. var transform;
  369. var $bm_transform;
  370. var content;
  371. var effect;
  372. var thisProperty = property;
  373. thisProperty._name = elem.data.nm;
  374. thisProperty.valueAtTime = thisProperty.getValueAtTime;
  375. Object.defineProperty(thisProperty, 'value', {
  376. get: function () {
  377. return thisProperty.v;
  378. },
  379. });
  380. elem.comp.frameDuration = 1 / elem.comp.globalData.frameRate;
  381. elem.comp.displayStartTime = 0;
  382. var inPoint = elem.data.ip / elem.comp.globalData.frameRate;
  383. var outPoint = elem.data.op / elem.comp.globalData.frameRate;
  384. var width = elem.data.sw ? elem.data.sw : 0;
  385. var height = elem.data.sh ? elem.data.sh : 0;
  386. var name = elem.data.nm;
  387. var loopIn;
  388. var loop_in;
  389. var loopOut;
  390. var loop_out;
  391. var smooth;
  392. var toWorld;
  393. var fromWorld;
  394. var fromComp;
  395. var toComp;
  396. var fromCompToSurface;
  397. var position;
  398. var rotation;
  399. var anchorPoint;
  400. var scale;
  401. var thisLayer;
  402. var thisComp;
  403. var mask;
  404. var valueAtTime;
  405. var velocityAtTime;
  406. var scoped_bm_rt;
  407. // val = val.replace(/(\\?"|')((http)(s)?(:\/))?\/.*?(\\?"|')/g, "\"\""); // deter potential network calls
  408. var expression_function = eval('[function _expression_function(){' + val + ';scoped_bm_rt=$bm_rt}]')[0]; // eslint-disable-line no-eval
  409. var numKeys = property.kf ? data.k.length : 0;
  410. var active = !this.data || this.data.hd !== true;
  411. var wiggle = function wiggle(freq, amp) {
  412. var iWiggle;
  413. var j;
  414. var lenWiggle = this.pv.length ? this.pv.length : 1;
  415. var addedAmps = createTypedArray('float32', lenWiggle);
  416. freq = 5;
  417. var iterations = Math.floor(time * freq);
  418. iWiggle = 0;
  419. j = 0;
  420. while (iWiggle < iterations) {
  421. // var rnd = BMMath.random();
  422. for (j = 0; j < lenWiggle; j += 1) {
  423. addedAmps[j] += -amp + amp * 2 * BMMath.random();
  424. // addedAmps[j] += -amp + amp*2*rnd;
  425. }
  426. iWiggle += 1;
  427. }
  428. // var rnd2 = BMMath.random();
  429. var periods = time * freq;
  430. var perc = periods - Math.floor(periods);
  431. var arr = createTypedArray('float32', lenWiggle);
  432. if (lenWiggle > 1) {
  433. for (j = 0; j < lenWiggle; j += 1) {
  434. arr[j] = this.pv[j] + addedAmps[j] + (-amp + amp * 2 * BMMath.random()) * perc;
  435. // arr[j] = this.pv[j] + addedAmps[j] + (-amp + amp*2*rnd)*perc;
  436. // arr[i] = this.pv[i] + addedAmp + amp1*perc + amp2*(1-perc);
  437. }
  438. return arr;
  439. }
  440. return this.pv + addedAmps[0] + (-amp + amp * 2 * BMMath.random()) * perc;
  441. }.bind(this);
  442. if (thisProperty.loopIn) {
  443. loopIn = thisProperty.loopIn.bind(thisProperty);
  444. loop_in = loopIn;
  445. }
  446. if (thisProperty.loopOut) {
  447. loopOut = thisProperty.loopOut.bind(thisProperty);
  448. loop_out = loopOut;
  449. }
  450. if (thisProperty.smooth) {
  451. smooth = thisProperty.smooth.bind(thisProperty);
  452. }
  453. function loopInDuration(type, duration) {
  454. return loopIn(type, duration, true);
  455. }
  456. function loopOutDuration(type, duration) {
  457. return loopOut(type, duration, true);
  458. }
  459. if (this.getValueAtTime) {
  460. valueAtTime = this.getValueAtTime.bind(this);
  461. }
  462. if (this.getVelocityAtTime) {
  463. velocityAtTime = this.getVelocityAtTime.bind(this);
  464. }
  465. var comp = elem.comp.globalData.projectInterface.bind(elem.comp.globalData.projectInterface);
  466. function lookAt(elem1, elem2) {
  467. var fVec = [elem2[0] - elem1[0], elem2[1] - elem1[1], elem2[2] - elem1[2]];
  468. var pitch = Math.atan2(fVec[0], Math.sqrt(fVec[1] * fVec[1] + fVec[2] * fVec[2])) / degToRads;
  469. var yaw = -Math.atan2(fVec[1], fVec[2]) / degToRads;
  470. return [yaw, pitch, 0];
  471. }
  472. function easeOut(t, tMin, tMax, val1, val2) {
  473. return applyEase(easeOutBez, t, tMin, tMax, val1, val2);
  474. }
  475. function easeIn(t, tMin, tMax, val1, val2) {
  476. return applyEase(easeInBez, t, tMin, tMax, val1, val2);
  477. }
  478. function ease(t, tMin, tMax, val1, val2) {
  479. return applyEase(easeInOutBez, t, tMin, tMax, val1, val2);
  480. }
  481. function applyEase(fn, t, tMin, tMax, val1, val2) {
  482. if (val1 === undefined) {
  483. val1 = tMin;
  484. val2 = tMax;
  485. } else {
  486. t = (t - tMin) / (tMax - tMin);
  487. }
  488. if (t > 1) {
  489. t = 1;
  490. } else if (t < 0) {
  491. t = 0;
  492. }
  493. var mult = fn(t);
  494. if ($bm_isInstanceOfArray(val1)) {
  495. var iKey;
  496. var lenKey = val1.length;
  497. var arr = createTypedArray('float32', lenKey);
  498. for (iKey = 0; iKey < lenKey; iKey += 1) {
  499. arr[iKey] = (val2[iKey] - val1[iKey]) * mult + val1[iKey];
  500. }
  501. return arr;
  502. }
  503. return (val2 - val1) * mult + val1;
  504. }
  505. function nearestKey(time) {
  506. var iKey;
  507. var lenKey = data.k.length;
  508. var index;
  509. var keyTime;
  510. if (!data.k.length || typeof (data.k[0]) === 'number') {
  511. index = 0;
  512. keyTime = 0;
  513. } else {
  514. index = -1;
  515. time *= elem.comp.globalData.frameRate;
  516. if (time < data.k[0].t) {
  517. index = 1;
  518. keyTime = data.k[0].t;
  519. } else {
  520. for (iKey = 0; iKey < lenKey - 1; iKey += 1) {
  521. if (time === data.k[iKey].t) {
  522. index = iKey + 1;
  523. keyTime = data.k[iKey].t;
  524. break;
  525. } else if (time > data.k[iKey].t && time < data.k[iKey + 1].t) {
  526. if (time - data.k[iKey].t > data.k[iKey + 1].t - time) {
  527. index = iKey + 2;
  528. keyTime = data.k[iKey + 1].t;
  529. } else {
  530. index = iKey + 1;
  531. keyTime = data.k[iKey].t;
  532. }
  533. break;
  534. }
  535. }
  536. if (index === -1) {
  537. index = iKey + 1;
  538. keyTime = data.k[iKey].t;
  539. }
  540. }
  541. }
  542. var obKey = {};
  543. obKey.index = index;
  544. obKey.time = keyTime / elem.comp.globalData.frameRate;
  545. return obKey;
  546. }
  547. function key(ind) {
  548. var obKey;
  549. var iKey;
  550. var lenKey;
  551. if (!data.k.length || typeof (data.k[0]) === 'number') {
  552. throw new Error('The property has no keyframe at index ' + ind);
  553. }
  554. ind -= 1;
  555. obKey = {
  556. time: data.k[ind].t / elem.comp.globalData.frameRate,
  557. value: [],
  558. };
  559. var arr = Object.prototype.hasOwnProperty.call(data.k[ind], 's') ? data.k[ind].s : data.k[ind - 1].e;
  560. lenKey = arr.length;
  561. for (iKey = 0; iKey < lenKey; iKey += 1) {
  562. obKey[iKey] = arr[iKey];
  563. obKey.value[iKey] = arr[iKey];
  564. }
  565. return obKey;
  566. }
  567. function framesToTime(fr, fps) {
  568. if (!fps) {
  569. fps = elem.comp.globalData.frameRate;
  570. }
  571. return fr / fps;
  572. }
  573. function timeToFrames(t, fps) {
  574. if (!t && t !== 0) {
  575. t = time;
  576. }
  577. if (!fps) {
  578. fps = elem.comp.globalData.frameRate;
  579. }
  580. return t * fps;
  581. }
  582. function seedRandom(seed) {
  583. BMMath.seedrandom(randSeed + seed);
  584. }
  585. function sourceRectAtTime() {
  586. return elem.sourceRectAtTime();
  587. }
  588. function substring(init, end) {
  589. if (typeof value === 'string') {
  590. if (end === undefined) {
  591. return value.substring(init);
  592. }
  593. return value.substring(init, end);
  594. }
  595. return '';
  596. }
  597. function substr(init, end) {
  598. if (typeof value === 'string') {
  599. if (end === undefined) {
  600. return value.substr(init);
  601. }
  602. return value.substr(init, end);
  603. }
  604. return '';
  605. }
  606. function posterizeTime(framesPerSecond) {
  607. time = framesPerSecond === 0 ? 0 : Math.floor(time * framesPerSecond) / framesPerSecond;
  608. value = valueAtTime(time);
  609. }
  610. var time;
  611. var velocity;
  612. var value;
  613. var text;
  614. var textIndex;
  615. var textTotal;
  616. var selectorValue;
  617. var index = elem.data.ind;
  618. var hasParent = !!(elem.hierarchy && elem.hierarchy.length);
  619. var parent;
  620. var randSeed = Math.floor(Math.random() * 1000000);
  621. var globalData = elem.globalData;
  622. function executeExpression(_value) {
  623. // globalData.pushExpression();
  624. value = _value;
  625. if (this.frameExpressionId === elem.globalData.frameId && this.propType !== 'textSelector') {
  626. return value;
  627. }
  628. if (this.propType === 'textSelector') {
  629. textIndex = this.textIndex;
  630. textTotal = this.textTotal;
  631. selectorValue = this.selectorValue;
  632. }
  633. if (!thisLayer) {
  634. text = elem.layerInterface.text;
  635. thisLayer = elem.layerInterface;
  636. thisComp = elem.comp.compInterface;
  637. toWorld = thisLayer.toWorld.bind(thisLayer);
  638. fromWorld = thisLayer.fromWorld.bind(thisLayer);
  639. fromComp = thisLayer.fromComp.bind(thisLayer);
  640. toComp = thisLayer.toComp.bind(thisLayer);
  641. mask = thisLayer.mask ? thisLayer.mask.bind(thisLayer) : null;
  642. fromCompToSurface = fromComp;
  643. }
  644. if (!transform) {
  645. transform = elem.layerInterface('ADBE Transform Group');
  646. $bm_transform = transform;
  647. if (transform) {
  648. anchorPoint = transform.anchorPoint;
  649. /* position = transform.position;
  650. rotation = transform.rotation;
  651. scale = transform.scale; */
  652. }
  653. }
  654. if (elemType === 4 && !content) {
  655. content = thisLayer('ADBE Root Vectors Group');
  656. }
  657. if (!effect) {
  658. effect = thisLayer(4);
  659. }
  660. hasParent = !!(elem.hierarchy && elem.hierarchy.length);
  661. if (hasParent && !parent) {
  662. parent = elem.hierarchy[0].layerInterface;
  663. }
  664. time = this.comp.renderedFrame / this.comp.globalData.frameRate;
  665. if (_needsRandom) {
  666. seedRandom(randSeed + time);
  667. }
  668. if (needsVelocity) {
  669. velocity = velocityAtTime(time);
  670. }
  671. expression_function();
  672. this.frameExpressionId = elem.globalData.frameId;
  673. // TODO: Check if it's possible to return on ShapeInterface the .v value
  674. // Changed this to a ternary operation because Rollup failed compiling it correctly
  675. scoped_bm_rt = scoped_bm_rt.propType === propTypes.SHAPE
  676. ? scoped_bm_rt.v
  677. : scoped_bm_rt;
  678. return scoped_bm_rt;
  679. }
  680. // Bundlers will see these as dead code and unless we reference them
  681. executeExpression.__preventDeadCodeRemoval = [$bm_transform, anchorPoint, time, velocity, inPoint, outPoint, width, height, name, loop_in, loop_out, smooth, toComp, fromCompToSurface, toWorld, fromWorld, mask, position, rotation, scale, thisComp, numKeys, active, wiggle, loopInDuration, loopOutDuration, comp, lookAt, easeOut, easeIn, ease, nearestKey, key, text, textIndex, textTotal, selectorValue, framesToTime, timeToFrames, sourceRectAtTime, substring, substr, posterizeTime, index, globalData];
  682. return executeExpression;
  683. }
  684. ob.initiateExpression = initiateExpression;
  685. ob.__preventDeadCodeRemoval = [window, document, XMLHttpRequest, fetch, frames, $bm_neg, add, $bm_sum, $bm_sub, $bm_mul, $bm_div, $bm_mod, clamp, radians_to_degrees, degreesToRadians, degrees_to_radians, normalize, rgbToHsl, hslToRgb, linear, random, createPath, _lottieGlobal];
  686. ob.resetFrame = resetFrame;
  687. return ob;
  688. }());
  689. export default ExpressionManager;