PageSourceSearch

https://sabteahval.ir/UI/Styles/sabtahval1401/AddOn/Scripts/counterUp.js

js sabteahval.ir collected 2026-09-24 19:59:47 UTC 13,002 bytes, 294 lines download raw bytes

1(function (global, factory) {
2    typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3        typeof define === 'function' && define.amd ? define(['exports'], factory) :
4            (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.countUp = {}));
5})(this, (function (exports) {
6    'use strict';
7
8    var __assign = (undefined && undefined.__assign) || function () {
9        __assign = Object.assign || function (t) {
10            for (var s, i = 1, n = arguments.length; i < n; i++) {
11                s = arguments[i];
12                for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
13                    t[p] = s[p];
14            }
15            return t;
16        };
17        return __assign.apply(this, arguments);
18    };
19    // playground: stackblitz.com/edit/countup-typescript
20    var CountUp = /** @class */ (function () {
21        function CountUp(target, endVal, options) {
22            var _this = this;
23            this.endVal = endVal;
24            this.options = options;
25            this.version = '2.3.2';
26            this.defaults = {
27                startVal: 0,
28                decimalPlaces: 0,
29                duration: 2,
30                useEasing: true,
31                useGrouping: true,
32                smartEasingThreshold: 999,
33                smartEasingAmount: 333,
34                separator: ',',
35                decimal: '.',
36                prefix: '',
37                suffix: '',
38                enableScrollSpy: false,
39                scrollSpyDelay: 200,
40                scrollSpyOnce: false,
41            };
42            this.finalEndVal = null; // for smart easing
43            this.useEasing = true;
44            this.countDown = false;
45            this.error = '';
46            this.startVal = 0;
47            this.paused = true;
48            this.once = false;
49            this.count = function (timestamp) {
50                if (!_this.startTime) {
51                    _this.startTime = timestamp;
52                }
53                var progress = timestamp - _this.startTime;
54                _this.remaining = _this.duration - progress;
55                // to ease or not to ease
56                if (_this.useEasing) {
57                    if (_this.countDown) {
58                        _this.frameVal = _this.startVal - _this.easingFn(progress, 0, _this.startVal - _this.endVal, _this.duration);
59                    }
60                    else {
61                        _this.frameVal = _this.easingFn(progress, _this.startVal, _this.endVal - _this.startVal, _this.duration);
62                    }
63                }
64                else {
65                    _this.frameVal = _this.startVal + (_this.endVal - _this.startVal) * (progress / _this.duration);
66                }
67                // don't go past endVal since progress can exceed duration in the last frame
68                var wentPast = _this.countDown ? _this.frameVal < _this.endVal : _this.frameVal > _this.endVal;
69                _this.frameVal = wentPast ? _this.endVal : _this.frameVal;
70                // decimal
71                _this.frameVal = Number(_this.frameVal.toFixed(_this.options.decimalPlaces));
72                // format and print value
73                _this.printValue(_this.frameVal);
74                // whether to continue
75                if (progress < _this.duration) {
76                    _this.rAF = requestAnimationFrame(_this.count);
77                }
78                else if (_this.finalEndVal !== null) {
79                    // smart easing
80                    _this.update(_this.finalEndVal);
81                }
82                else {
83                    if (_this.callback) {
84                        _this.callback();
85                    }
86                }
87            };
88            // default format and easing functions
89            this.formatNumber = function (num) {
90                var neg = (num < 0) ? '-' : '';
91                var result, x1, x2, x3;
92                result = Math.abs(num).toFixed(_this.options.decimalPlaces);
93                result += '';
94                var x = result.split('.');
95                x1 = x[0];
96                x2 = x.length > 1 ? _this.options.decimal + x[1] : '';
97                if (_this.options.useGrouping) {
98                    x3 = '';
99                    for (var i = 0, len = x1.length; i < len; ++i) {
100                        if (i !== 0 && (i % 3) === 0) {
101                            x3 = _this.options.separator + x3;
102                        }
103                        x3 = x1[len - i - 1] + x3;
104                    }
105                    x1 = x3;
106                }
107                // optional numeral substitution
108                if (_this.options.numerals && _this.options.numerals.length) {
109                    x1 = x1.replace(/[0-9]/g, function (w) { return _this.options.numerals[+w]; });
110                    x2 = x2.replace(/[0-9]/g, function (w) { return _this.options.numerals[+w]; });
111                }
112                return neg + _this.options.prefix + x1 + x2 + _this.options.suffix;
113            };
114            // t: current time, b: beginning value, c: change in value, d: duration
115            this.easeOutExpo = function (t, b, c, d) {
116                return c * (-Math.pow(2, -10 * t / d) + 1) * 1024 / 1023 + b;
117            };
118            this.options = __assign(__assign({}, this.defaults), options);
119            this.formattingFn = (this.options.formattingFn) ?
120                this.options.formattingFn : this.formatNumber;
121            this.easingFn = (this.options.easingFn) ?
122                this.options.easingFn : this.easeOutExpo;
123            this.startVal = this.validateValue(this.options.startVal);
124            this.frameVal = this.startVal;
125            this.endVal = this.validateValue(endVal);
126            this.options.decimalPlaces = Math.max(this.options.decimalPlaces);
127            this.resetDuration();
128            this.options.separator = String(this.options.separator);
129            this.useEasing = this.options.useEasing;
130            if (this.options.separator === '') {
131                this.options.useGrouping = false;
132            }
133            this.el = (typeof target === 'string') ? document.getElementById(target) : target;
134            if (this.el) {
135                this.printValue(this.startVal);
136            }
137            else {
138                this.error = '[CountUp] target is null or undefined';
139            }
140            // scroll spy
141            if (typeof window !== 'undefined' && this.options.enableScrollSpy) {
142                if (!this.error) {
143                    // set up global array of onscroll functions to handle multiple instances
144                    window['onScrollFns'] = window['onScrollFns'] || [];
145                    window['onScrollFns'].push(function () { return _this.handleScroll(_this); });
146                    window.onscroll = function () {
147                        window['onScrollFns'].forEach(function (fn) { return fn(); });
148                    };
149                    this.handleScroll(this);
150                }
151                else {
152                    console.error(this.error, target);
153                }
154            }
155        }
156        CountUp.prototype.handleScroll = function (self) {
157            if (!self || !window || self.once)
158                return;
159            var bottomOfScroll = window.innerHeight + window.scrollY;
160            var rect = self.el.getBoundingClientRect();
161            var bottomOfEl = rect.top + rect.height + window.pageYOffset;
162            if (bottomOfEl < bottomOfScroll && bottomOfEl > window.scrollY && self.paused) {
163                // in view
164                self.paused = false;
165                setTimeout(function () { return self.start(); }, self.options.scrollSpyDelay);
166                if (self.options.scrollSpyOnce)
167                    self.once = true;
168            }
169            else if (window.scrollY > bottomOfEl && !self.paused) {
170                // scrolled past
171                self.reset();
172            }
173        };
174        /**
175         * Smart easing works by breaking the animation into 2 parts, the second part being the
176         * smartEasingAmount and first part being the total amount minus the smartEasingAmount. It works
177         * by disabling easing for the first part and enabling it on the second part. It is used if
178         * usingEasing is true and the total animation amount exceeds the smartEasingThreshold.
179         */
180        CountUp.prototype.determineDirectionAndSmartEasing = function () {
181            var end = (this.finalEndVal) ? this.finalEndVal : this.endVal;
182            this.countDown = (this.startVal > end);
183            var animateAmount = end - this.startVal;
184            if (Math.abs(animateAmount) > this.options.smartEasingThreshold && this.options.useEasing) {
185                this.finalEndVal = end;
186                var up = (this.countDown) ? 1 : -1;
187                this.endVal = end + (up * this.options.smartEasingAmount);
188                this.duration = this.duration / 2;
189            }
190            else {
191                this.endVal = end;
192                this.finalEndVal = null;
193            }
194            if (this.finalEndVal !== null) {
195                // setting finalEndVal indicates smart easing
196                this.useEasing = false;
197            }
198            else {
199                this.useEasing = this.options.useEasing;
200            }
201        };
202        // start animation
203        CountUp.prototype.start = function (callback) {
204            if (this.error) {
205                return;
206            }
207            this.callback = callback;
208            if (this.duration > 0) {
209                this.determineDirectionAndSmartEasing();
210                this.paused = false;
211                this.rAF = requestAnimationFrame(this.count);
212            }
213            else {
214                this.printValue(this.endVal);
215            }
216        };
217        // pause/resume animation
218        CountUp.prototype.pauseResume = function () {
219            if (!this.paused) {
220                cancelAnimationFrame(this.rAF);
221            }
222            else {
223                this.startTime = null;
224                this.duration = this.remaining;
225                this.startVal = this.frameVal;
226                this.determineDirectionAndSmartEasing();
227                this.rAF = requestAnimationFrame(this.count);
228            }
229            this.paused = !this.paused;
230        };
231        // reset to startVal so animation can be run again
232        CountUp.prototype.reset = function () {
233            cancelAnimationFrame(this.rAF);
234            this.paused = true;
235            this.resetDuration();
236            this.startVal = this.validateValue(this.options.startVal);
237            this.frameVal = this.startVal;
238            this.printValue(this.startVal);
239        };
240        // pass a new endVal and start animation
241        CountUp.prototype.update = function (newEndVal) {
242            cancelAnimationFrame(this.rAF);
243            this.startTime = null;
244            this.endVal = this.validateValue(newEndVal);
245            if (this.endVal === this.frameVal) {
246                return;
247            }
248            this.startVal = this.frameVal;
249            if (this.finalEndVal == null) {
250                this.resetDuration();
251            }
252            this.finalEndVal = null;
253            this.determineDirectionAndSmartEasing();
254            this.rAF = requestAnimationFrame(this.count);
255        };
256        CountUp.prototype.printValue = function (val) {
257            var result = this.formattingFn(val);
258            if (this.el.tagName === 'INPUT') {
259                var input = this.el;
260                input.value = result;
261            }
262            else if (this.el.tagName === 'text' || this.el.tagName === 'tspan') {
263                this.el.textContent = result;
264            }
265            else {
266                this.el.innerHTML = result;
267            }
268        };
269        CountUp.prototype.ensureNumber = function (n) {
270            return (typeof n === 'number' && !isNaN(n));
271        };
272        CountUp.prototype.validateValue = function (value) {
273            var newValue = Number(value);
274            if (!this.ensureNumber(newValue)) {
275                this.error = "[CountUp] invalid start or end value: ".concat(value);
276                return null;
277            }
278            else {
279                return newValue;
280            }
281        };
282        CountUp.prototype.resetDuration = function () {
283            this.startTime = null;
284            this.duration = Number(this.options.duration) * 1000;
285            this.remaining = this.duration;
286        };
287        return CountUp;
288    }());
289
290    exports.CountUp = CountUp;
291
292    Object.defineProperty(exports, '__esModule', { value: true });
293
294}));

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.