Web Interface For Lite Argus Control modules
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
2.8 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*!
  2. * VERSION: 1.6.0
  3. * DATE: 2018-08-27
  4. * UPDATES AND DOCS AT: http://greensock.com
  5. *
  6. * @license Copyright (c) 2008-2019, GreenSock. All rights reserved.
  7. * This work is subject to the terms at http://greensock.com/standard-license or for
  8. * Club GreenSock members, the software agreement that was issued with your membership.
  9. *
  10. * @author: Jack Doyle, jack@greensock.com
  11. **/
  12. /* eslint-disable */
  13. import { _gsScope } from "./TweenLite.js";
  14. export var RoundPropsPlugin = _gsScope._gsDefine.plugin({
  15. propName: "roundProps",
  16. version: "1.7.0",
  17. priority: -1,
  18. API: 2,
  19. //called when the tween renders for the first time. This is where initial values should be recorded and any setup routines should run.
  20. init: function(target, value, tween) {
  21. this._tween = tween;
  22. return true;
  23. }
  24. }),
  25. _getRoundFunc = function(v) { //pass in 0.1 get a function that'll round to the nearest tenth, or 5 to round to the closest 5, or 0.001 to the closest 1000th, etc.
  26. var p = v < 1 ? Math.pow(10, (v + "").length - 2) : 1; //to avoid floating point math errors (like 24 * 0.1 == 2.4000000000000004), we chop off at a specific number of decimal places (much faster than toFixed()
  27. return function(n) {
  28. return ((Math.round(n / v) * v * p) | 0) / p;
  29. };
  30. },
  31. _roundLinkedList = function(node, mod) {
  32. while (node) {
  33. if (!node.f && !node.blob) {
  34. node.m = mod || Math.round;
  35. }
  36. node = node._next;
  37. }
  38. },
  39. p = RoundPropsPlugin.prototype;
  40. p._onInitAllProps = function() {
  41. var tween = this._tween,
  42. rp = tween.vars.roundProps,
  43. lookup = {},
  44. rpt = tween._propLookup.roundProps,
  45. pt, next, i, p;
  46. if (typeof(rp) === "object" && !rp.push) {
  47. for (p in rp) {
  48. lookup[p] = _getRoundFunc(rp[p]);
  49. }
  50. } else {
  51. if (typeof(rp) === "string") {
  52. rp = rp.split(",");
  53. }
  54. i = rp.length;
  55. while (--i > -1) {
  56. lookup[rp[i]] = Math.round;
  57. }
  58. }
  59. for (p in lookup) {
  60. pt = tween._firstPT;
  61. while (pt) {
  62. next = pt._next; //record here, because it may get removed
  63. if (pt.pg) {
  64. pt.t._mod(lookup);
  65. } else if (pt.n === p) {
  66. if (pt.f === 2 && pt.t) { //a blob (text containing multiple numeric values)
  67. _roundLinkedList(pt.t._firstPT, lookup[p]);
  68. } else {
  69. this._add(pt.t, p, pt.s, pt.c, lookup[p]);
  70. //remove from linked list
  71. if (next) {
  72. next._prev = pt._prev;
  73. }
  74. if (pt._prev) {
  75. pt._prev._next = next;
  76. } else if (tween._firstPT === pt) {
  77. tween._firstPT = next;
  78. }
  79. pt._next = pt._prev = null;
  80. tween._propLookup[p] = rpt;
  81. }
  82. }
  83. pt = next;
  84. }
  85. }
  86. return false;
  87. };
  88. p._add = function(target, p, s, c, mod) {
  89. this._addTween(target, p, s, s + c, p, mod || Math.round);
  90. this._overwriteProps.push(p);
  91. };
  92. export { RoundPropsPlugin as default };