MCPcopy
hub / github.com/greensock/GSAP / _addComplexStringPropTween

Function _addComplexStringPropTween

esm/gsap-core.js:2705–2774  ·  view source on GitHub ↗
(target, prop, start, end, setter, stringFilter, funcParam)

Source from the content-addressed store, hash-verified

2703});
2704
2705var _addComplexStringPropTween = function _addComplexStringPropTween(target, prop, start, end, setter, stringFilter, funcParam) {
2706 //note: we call _addComplexStringPropTween.call(tweenInstance...) to ensure that it's scoped properly. We may call it from within a plugin too, thus "this" would refer to the plugin.
2707 var pt = new PropTween(this._pt, target, prop, 0, 1, _renderComplexString, null, setter),
2708 index = 0,
2709 matchIndex = 0,
2710 result,
2711 startNums,
2712 color,
2713 endNum,
2714 chunk,
2715 startNum,
2716 hasRandom,
2717 a;
2718 pt.b = start;
2719 pt.e = end;
2720 start += ""; //ensure values are strings
2721
2722 end += "";
2723
2724 if (hasRandom = ~end.indexOf("random(")) {
2725 end = _replaceRandom(end);
2726 }
2727
2728 if (stringFilter) {
2729 a = [start, end];
2730 stringFilter(a, target, prop); //pass an array with the starting and ending values and let the filter do whatever it needs to the values.
2731
2732 start = a[0];
2733 end = a[1];
2734 }
2735
2736 startNums = start.match(_complexStringNumExp) || [];
2737
2738 while (result = _complexStringNumExp.exec(end)) {
2739 endNum = result[0];
2740 chunk = end.substring(index, result.index);
2741
2742 if (color) {
2743 color = (color + 1) % 5;
2744 } else if (chunk.substr(-5) === "rgba(") {
2745 color = 1;
2746 }
2747
2748 if (endNum !== startNums[matchIndex++]) {
2749 startNum = parseFloat(startNums[matchIndex - 1]) || 0; //these nested PropTweens are handled in a special way - we'll never actually call a render or setter method on them. We'll just loop through them in the parent complex string PropTween's render method.
2750
2751 pt._pt = {
2752 _next: pt._pt,
2753 p: chunk || matchIndex === 1 ? chunk : ",",
2754 //note: SVG spec allows omission of comma/space when a negative sign is wedged between two numbers, like 2.5-5.3 instead of 2.5,-5.3 but when tweening, the negative value may switch to positive, so we insert the comma just in case.
2755 s: startNum,
2756 c: endNum.charAt(1) === "=" ? _parseRelative(startNum, endNum) - startNum : parseFloat(endNum) - startNum,
2757 m: color && color < 4 ? Math.round : 0
2758 };
2759 index = _complexStringNumExp.lastIndex;
2760 }
2761 }
2762

Callers

nothing calls this directly

Calls 2

_replaceRandomFunction · 0.70
_parseRelativeFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…