light-odometer 0.0.8 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -0
- package/dist/main.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,3 +5,74 @@ Do not use this, use [@mtmarco87](https://github.com/mtmarco87)'s package instea
|
|
|
5
5
|
Huge props to him for this TypeScript refactor !
|
|
6
6
|
|
|
7
7
|
No theme is shipped here, no docs either.
|
|
8
|
+
|
|
9
|
+
## What's changed ?
|
|
10
|
+
For a quick overview in a real-world usage, see https://github.com/EDM115/website/blob/master/app/components/ui/Odometer.vue
|
|
11
|
+
|
|
12
|
+
- Removal of all built artifacts, themes, demo, screenshots and CoffeeScript code
|
|
13
|
+
- Switch from Rollup to tsdown (Rolldown)
|
|
14
|
+
- Added linting and formatting (OxLint + ESLint Stylistic)
|
|
15
|
+
- Keep only the ESM build and switch to a default export
|
|
16
|
+
- Better TS config and stricter types (no more `any` nor `as`)
|
|
17
|
+
- Target ES2016 instead of ES2015
|
|
18
|
+
- Remove compatibility layers (Internet Explorer, jQuery)
|
|
19
|
+
- Stabilize and simplify the interfaces
|
|
20
|
+
- Use overall more optimized methods
|
|
21
|
+
- Renamed from `TmOdometer` to `LightOdometer`
|
|
22
|
+
- No more const functions
|
|
23
|
+
- SSR friendly (you can import it top-level without blowing up) and use safe fallbacks fror browser-land functions
|
|
24
|
+
- Multiple performance improvements
|
|
25
|
+
- `value` is now stripped from spaces
|
|
26
|
+
- Each instance can now have an `id`
|
|
27
|
+
- Ability to customize the framerate
|
|
28
|
+
```ts
|
|
29
|
+
const odo = new LightOdometer({ ..., framerate: 20 }) // default is 30, going above isn't recommended
|
|
30
|
+
// use countFramerate if you use the `count` mode instead of `slide`
|
|
31
|
+
```
|
|
32
|
+
- Ability to render once and destroy the instance
|
|
33
|
+
```ts
|
|
34
|
+
const odo = new LightOdometer({ ..., value: 0 })
|
|
35
|
+
odo.animateOnceAndDisconnect(12345)
|
|
36
|
+
```
|
|
37
|
+
- Expose `duration` as a CSS property to sync up JS and CSS animations
|
|
38
|
+
```ts
|
|
39
|
+
const odo = new LightOdometer({ ..., duration: 5000 })
|
|
40
|
+
console.log(getComputedStyle(odo.el).getPropertyValue("--odometer-duration")) // "5000ms"
|
|
41
|
+
```
|
|
42
|
+
- Get and mutate instance and global options
|
|
43
|
+
```ts
|
|
44
|
+
const odo = new LightOdometer({ ... })
|
|
45
|
+
console.log(odo.getOptions().duration)
|
|
46
|
+
odo.setOptions({ duration: 2000 })
|
|
47
|
+
|
|
48
|
+
console.log(LightOdometer.getGlobalOptions.selector)
|
|
49
|
+
LightOdometer.setGlobalOptions({ selector: ".my-odometer" })
|
|
50
|
+
```
|
|
51
|
+
- Add per-instance subscriptable animation start/end events. They give back the instance id, el, instance, value, oldValue, options
|
|
52
|
+
```ts
|
|
53
|
+
const odo = new LightOdometer({ ... })
|
|
54
|
+
console.log(odo.isAnimating)
|
|
55
|
+
|
|
56
|
+
function onStart(e: Event) {
|
|
57
|
+
const { detail } = e as CustomEvent<LightOdometerEventDetail>
|
|
58
|
+
// detail.id, detail.value, detail.instance.isAnimating, ...
|
|
59
|
+
console.log(`started animating to ${detail.value}`)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function onDone(e: Event) {
|
|
63
|
+
const { detail } = e as CustomEvent<LightOdometerEventDetail>
|
|
64
|
+
console.log(`finished animating to ${detail.value}`)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
odo.on("odometerstart", onStart)
|
|
68
|
+
odo.on("odometerdone", onDone)
|
|
69
|
+
|
|
70
|
+
// later
|
|
71
|
+
odo.off("odometerstart", onStart)
|
|
72
|
+
odo.off("odometerdone", onDone)
|
|
73
|
+
```
|
|
74
|
+
- Print the instance in a JSON-friendly string
|
|
75
|
+
```ts
|
|
76
|
+
const odo = new LightOdometer({ ... })
|
|
77
|
+
console.log(odo.toString()) // {"id":2,"value":157,"options":{"id":2,"value":0,"animation":"slide","duration":8000,"format":"( ddd)","framerate":20},"globalOptions":{},"watchMutations":false,"transitionEndBound":true,"destroyed":false,"format":{"repeating":" ","precision":0},"isAnimating":false}
|
|
78
|
+
```
|
package/dist/main.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=/^\(?([^)]*)\)?(?:(.)(d+))?$/,t=2e3;function n(e){"@babel/helpers - typeof";return n=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},n(e)}function r(e,t){if(n(e)!=`object`||!e)return e;var r=e[Symbol.toPrimitive];if(r!==void 0){var i=r.call(e,t||`default`);if(n(i)!=`object`)return i;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function i(e){var t=r(e,`string`);return n(t)==`symbol`?t:t+``}function a(e,t,n){return(t=i(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function s(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?o(Object(n),!0).forEach(function(t){a(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):o(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function c(e){let t=document.createElement(`div`);if(t.innerHTML=e,!(t.firstElementChild instanceof HTMLElement))throw Error(`Invalid HTML: No valid root element found.`);return t.firstElementChild}function l(e,t){let n=t.split(` `);for(let t of n)e.classList.remove(t);return e.className}function u(e,t){let n=t.split(` `);for(let t of n)t&&e.classList.add(t);return e.className}function d(e,t,n){let r=new CustomEvent(t,{bubbles:!0,cancelable:!0,detail:n});e.dispatchEvent(r)}function f(){return typeof performance<`u`&&typeof performance.now==`function`?performance.now():Date.now()}function p(e,t){return t!=null||(t=0),t?(e*=10**t,e+=.5,e=Math.floor(e),e/=10**t):Math.round(e)}function m(e){return e<0?Math.ceil(e):Math.floor(e)}function h(){return typeof window<`u`&&typeof document<`u`}function g(e){return h()&&typeof requestAnimationFrame==`function`?requestAnimationFrame(e):setTimeout(()=>e(f()),16)}function _(e){e!=null&&(h()&&typeof cancelAnimationFrame==`function`&&typeof e==`number`?cancelAnimationFrame(e):clearTimeout(e))}function v(e){h()&&(document.readyState===`complete`||document.readyState===`interactive`?setTimeout(e,0):document.addEventListener(`DOMContentLoaded`,e,{once:!0}))}function y(e){h()&&setTimeout(()=>{window.odometerOptions&&(e.options=s(s({},e.options),window.odometerOptions))},0)}function b(e){v(()=>{e.options.auto!==!1&&e.init()})}var x,S=class n{get isAnimating(){return this._isAnimating}constructor(e){var r,i,o,c;if(a(this,`_isAnimating`,!1),a(this,`options`,void 0),a(this,`el`,void 0),a(this,`value`,0),a(this,`inside`,void 0),a(this,`observer`,void 0),a(this,`watchMutations`,!1),a(this,`transitionEndBound`,!1),a(this,`destroyed`,!1),a(this,`format`,{repeating:``,precision:0}),a(this,`MAX_VALUES`,void 0),a(this,`digits`,[]),a(this,`ribbons`,{}),a(this,`_rafId`,void 0),a(this,`_countRafId`,void 0),a(this,`_msPerFrame`,void 0),a(this,`_countMsPerFrame`,void 0),a(this,`_onTransitionEnd`,void 0),this.options=e,this.el=this.options.el,this.el.odometer){var l,u,d;let e=this.el.odometer;e.options=s(s({},e.options),this.options),(l=e.options).duration!=null||(l.duration=t);let n=(u=e.options.framerate)==null?30:u,r=(d=e.options.countFramerate)==null?20:d;return e._msPerFrame=1e3/n,e._countMsPerFrame=1e3/r,e.MAX_VALUES=e.options.duration/e._msPerFrame/2|0,e.resetFormat(),this.options.value==null?h()&&e.render():e.update(this.options.value),e}this.el.odometer=this,this.options=s(s({},n.options),this.options),(r=this.options).duration!=null||(r.duration=t);let f=(i=this.options.framerate)==null?30:i,p=(o=this.options.countFramerate)==null?20:o;this._msPerFrame=1e3/f,this._countMsPerFrame=1e3/p,this.MAX_VALUES=this.options.duration/this._msPerFrame/2|0,this.resetFormat(),this.value=this.cleanValue((c=this.options.value)==null?``:c),h()&&(this.renderInside(),this.render());try{for(let e of[`innerHTML`,`innerText`,`textContent`])Object.defineProperty(this.el,e,{get:()=>{if(e===`innerHTML`){var t,n;return(t=(n=this.inside)==null?void 0:n.outerHTML)==null?``:t}else{var r,i,a,o;return(r=(i=(a=this.inside)==null?void 0:a.innerText)==null?(o=this.inside)==null?void 0:o.textContent:i)==null?``:r}},set:e=>this.update(e)})}catch(e){h()&&this.watchForMutations()}}renderInside(){h()&&(this.inside=document.createElement(`div`),this.inside.className=`odometer-inside`,this.el.textContent=``,this.el.appendChild(this.inside))}watchForMutations(){try{this.observer!=null||(this.observer=new MutationObserver(e=>{let t=this.el.innerText||``;this.renderInside(),this.render(this.value),this.update(t)})),this.watchMutations=!0,this.startWatchingMutations()}catch(e){}}startWatchingMutations(){if(this.watchMutations&&h()){var e;(e=this.observer)==null||e.observe(this.el,{childList:!0})}}stopWatchingMutations(){var e;(e=this.observer)==null||e.disconnect()}cleanValue(e){if(typeof e==`string`){var t;e=e.replace((t=this.format.radix)==null?`.`:t,`<radix>`),e=e.replace(/[.,\s\u00A0\u202F]/g,``),e=e.replace(`<radix>`,`.`),e=parseFloat(e)||0}return p(e,this.format.precision)}bindTransitionEnd(){if(this.transitionEndBound)return;this.transitionEndBound=!0;let e=!1;this._onTransitionEnd=()=>e?!0:(e=!0,setTimeout(()=>{this.render(),e=!1,this._isAnimating=!1,d(this.el,`odometerdone`,{id:this.options.id,el:this.el,instance:this,value:this.value,options:this.getOptions()})},0),!0),this.el.addEventListener(`transitionend`,this._onTransitionEnd,!1)}resetFormat(){var t;let n=(t=this.options.format)==null?`(,ddd).dd`:t;n=n||`d`;let r=e.exec(n);if(!r)throw Error(`LightOdometer: Unparsable digit format`);let[i,a,o,s]=r,c=(s==null?void 0:s.length)||0;this.format={repeating:a,radix:o,precision:c}}render(e){var n;if(h()){e!=null||(e=this.value),this.stopWatchingMutations(),this.resetFormat(),this.inside.textContent=``;for(let e of Array.from(this.el.classList))/^odometer(-|$)/.test(e)&&this.el.classList.remove(e);this.el.classList.add(`odometer`,`odometer-auto-theme`),this.el.style.setProperty(`--odometer-duration`,`${(n=this.options.duration)==null?t:n}ms`),this.ribbons={},this.formatDigits(e),this.startWatchingMutations()}}formatDigits(e){if(this.digits=[],this.options.formatFunction){let t=this.options.formatFunction(e);for(let e of t.split(``).toReversed())if(/\d/.test(e)){let t=this.renderDigit(),n=t.querySelector(`.odometer-value`);n.textContent=e,u(n,`odometer-first-value odometer-last-value`),this.digits.push(t),this.insertDigit(t)}else this.addSpacer(e)}else{let t=this.preservePrecision(e),n=!this.format.precision;for(let e of t.split(``).toReversed())e===`.`&&(n=!0),this.addDigit(e,n)}}preservePrecision(e){let t=e.toString();if(this.format.precision){let e=t.split(`.`);e.length===1&&(t+=`.`,e[1]=``);for(let n=0;n<this.format.precision;n++)e[1][n]||(t+=`0`)}return t}update(e){if(!h())return this.value=this.cleanValue(e),this.value;e=this.cleanValue(e);let t=e-this.value;return t?(l(this.el,`odometer-animating-up odometer-animating-down odometer-animating`),t>0?u(this.el,`odometer-animating-up`):u(this.el,`odometer-animating-down`),this._isAnimating=!0,d(this.el,`odometerstart`,{id:this.options.id,el:this.el,instance:this,value:e,oldValue:this.value,options:this.getOptions()}),this.stopWatchingMutations(),this.animate(e),this.startWatchingMutations(),setTimeout(()=>{this.el.offsetHeight,u(this.el,`odometer-animating`)},0),this.value=e,this.value):this.value}renderDigit(){return c(`<span class="odometer-digit"><span class="odometer-digit-spacer">8</span><span class="odometer-digit-inner"><span class="odometer-ribbon"><span class="odometer-ribbon-inner"><span class="odometer-value"></span></span></span></span></span>`)}insertDigit(e,t){return t?this.inside.insertBefore(e,t):this.inside.children.length?this.inside.insertBefore(e,this.inside.children[0]):this.inside.appendChild(e)}addSpacer(e,t,n){let r=c(`<span class="odometer-formatting-mark"></span>`);return r.textContent=e,n&&u(r,n),this.insertDigit(r,t)}addDigit(e,t){if(t!=null||(t=!0),e===`-`)return this.addSpacer(e,null,`odometer-negation-mark`);if(e===`.`){var n;return this.addSpacer((n=this.format.radix)==null?`.`:n,null,`odometer-radix-mark`)}if(t){let e=!1;for(;;){if(!this.format.repeating.length){if(e)throw Error(`Bad odometer format without digits`);this.resetFormat(),e=!0}let t=this.format.repeating[this.format.repeating.length-1];if(this.format.repeating=this.format.repeating.substring(0,this.format.repeating.length-1),t===`d`)break;this.addSpacer(t)}}let r=this.renderDigit(),i=r.querySelector(`.odometer-value`);return i.textContent=e,u(i,`odometer-first-value odometer-last-value`),this.digits.push(r),this.insertDigit(r)}animate(e){this.options.animation===`count`?this.animateCount(e):this.animateSlide(e)}animateCount(e){if(!h())return;let t=e-this.value;if(!t)return;let n=f(),r=n,i=this.value,a=()=>{if(f()-n>(this.options.duration||0)){this.value=e,this.render(),this._isAnimating=!1,d(this.el,`odometerdone`,{id:this.options.id,el:this.el,instance:this,value:this.value,options:this.getOptions()});return}let o=f()-r;if(o>this._countMsPerFrame){r=f();let e=o/(this.options.duration||0),n=t*e;i+=n,this.render(Math.round(i))}this._countRafId=g(a)};this._countRafId=g(a)}getDigitCount(...e){for(let t=0;t<e.length;t++)e[t]=Math.abs(e[t]);let t=Math.max(...e);return Math.ceil(Math.log(t+1)/Math.log(10))}getFractionalDigitCount(...e){let t=/^-?\d*\.(\d*?)0*$/;for(let n=0;n<e.length;n++){let r=e[n].toString(),i=t.exec(r);e[n]=i?i[1].length:0}return Math.max(...e)}resetDigits(){this.digits=[],this.ribbons={},this.inside.textContent=``,this.resetFormat()}createRange(e,t,n){let r=e<t,i=Math.abs(t-e)+(n?1:0);return Array.from({length:i},(t,n)=>r?e+n:e-n)}animateSlide(e){if(!h())return;let t=this.value,n=this.format.precision;n&&(e*=10**n,t*=10**n);let r=e-t;if(!r)return;this.bindTransitionEnd();let i=[],a=this.getDigitCount(t,e),o=0,s=t;for(let n=0;n<a;n++){s=m(t/10**(a-n-1));let r=m(e/10**(a-n-1)),c=r-s,l;if(Math.abs(c)>this.MAX_VALUES){l=[];let e=this.MAX_VALUES*(1+o*.5),t=c/e,n=s;for(;c>0&&n<r||c<0&&n>r;)l.push(Math.round(n)),n+=t;l[l.length-1]!==r&&l.push(r),o++}else l=this.createRange(s,r,!0);for(let e=0;e<l.length;e++)l[e]=Math.abs(l[e]%10);i.push(l)}this.resetDigits();let c=i.toReversed();for(let e=0;e<c.length;e++){let t=c[e];if(this.digits[e]||this.addDigit(` `,e>=n),this.ribbons[e]===void 0){let t=this.digits[e].querySelector(`.odometer-ribbon-inner`);t&&(this.ribbons[e]=t)}this.ribbons[e].textContent=``,r<0&&(t=t.toReversed());for(let n=0;n<t.length;n++){let r=t[n],i=document.createElement(`div`);i.className=`odometer-value`,i.textContent=r.toString(),this.ribbons[e].appendChild(i),n===t.length-1&&u(i,`odometer-last-value`),n===0&&u(i,`odometer-first-value`)}}s<0&&this.addDigit(`-`);let l=this.inside.querySelector(`.odometer-radix-mark`);if(l&&l.parentNode.removeChild(l),n){var d;this.addSpacer((d=this.format.radix)==null?`.`:d,this.digits[n-1],`odometer-radix-mark`)}}static init(){if(!h())return[];let e=document.querySelectorAll(n.options.selector||`.odometer`);return Array.from(e,e=>{var t;return e.odometer=new n({el:e,value:(t=e.innerText)==null?e.textContent:t})})}setOptions(e){var n,r,i;if(!e||typeof e!=`object`)return;`el`in e&&delete e.el;let a=Object.prototype.hasOwnProperty.call(e,`value`),o=Object.prototype.hasOwnProperty.call(e,`format`)||Object.prototype.hasOwnProperty.call(e,`formatFunction`),c=Object.prototype.hasOwnProperty.call(e,`duration`)||Object.prototype.hasOwnProperty.call(e,`framerate`)||Object.prototype.hasOwnProperty.call(e,`countFramerate`);this.options=s(s({},this.options),e),(n=this.options).duration!=null||(n.duration=t);let l=(r=this.options.framerate)==null?30:r,u=(i=this.options.countFramerate)==null?20:i;if(this._msPerFrame=1e3/l,this._countMsPerFrame=1e3/u,this.MAX_VALUES=this.options.duration/this._msPerFrame/2|0,h()&&this.el.style.setProperty(`--odometer-duration`,`${this.options.duration}ms`),o&&this.resetFormat(),a){var d;this.update((d=this.options.value)==null?0:d);return}(o||c)&&h()&&(this.stopWatchingMutations(),this.render(),this.startWatchingMutations())}static setGlobalOptions(e){n.options=s(s({},n.options),e)}on(e,t){this.el.addEventListener(e,t)}off(e,t){this.el.removeEventListener(e,t)}getOptions(){return s({},this.options)}static getGlobalOptions(){return s({},n.options)}animateOnceAndDisconnect(e){var n;e!=null&&this.update(e);let r=()=>this.disconnect(),i=e=>{this.el.removeEventListener(`odometerdone`,i),r()};this.el.addEventListener(`odometerdone`,i,{once:!0}),setTimeout(r,((n=this.options.duration)==null?t:n)+100)}disconnect(){this.destroyed||(this.stopWatchingMutations(),_(this._rafId),_(this._countRafId),this._onTransitionEnd&&(this.el.removeEventListener(`transitionend`,this._onTransitionEnd),this._onTransitionEnd=void 0),this.transitionEndBound=!1,this.destroyed=!0)}toString(){let e={id:this.options.id,value:this.value,options:this.getOptions(),globalOptions:n.getGlobalOptions(),watchMutations:this.watchMutations,transitionEndBound:this.transitionEndBound,destroyed:this.destroyed,format:this.format,isAnimating:this.isAnimating};return JSON.stringify(e)}};a(S,`options`,typeof window<`u`?(x=window.odometerOptions)==null?{}:x:{}),y(S),b(S);var C=S;export{C as default};
|
|
1
|
+
const e=/^\(?([^)]*)\)?(?:(.)(d+))?$/,t=2e3;function n(e){"@babel/helpers - typeof";return n=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},n(e)}function r(e,t){if(n(e)!=`object`||!e)return e;var r=e[Symbol.toPrimitive];if(r!==void 0){var i=r.call(e,t||`default`);if(n(i)!=`object`)return i;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function i(e){var t=r(e,`string`);return n(t)==`symbol`?t:t+``}function a(e,t,n){return(t=i(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function o(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function s(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?o(Object(n),!0).forEach(function(t){a(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):o(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function c(e){let t=document.createElement(`div`);if(t.innerHTML=e,!(t.firstElementChild instanceof HTMLElement))throw Error(`Invalid HTML: No valid root element found.`);return t.firstElementChild}function l(e,t){let n=t.split(` `);for(let t of n)e.classList.remove(t);return e.className}function u(e,t){let n=t.split(` `);for(let t of n)t&&e.classList.add(t);return e.className}function d(e,t,n){let r=new CustomEvent(t,{bubbles:!0,cancelable:!0,detail:n});e.dispatchEvent(r)}function f(){return typeof performance<`u`&&typeof performance.now==`function`?performance.now():Date.now()}function p(e,t){return t!=null||(t=0),t?(e*=10**t,e+=.5,e=Math.floor(e),e/=10**t):Math.round(e)}function m(e){return e<0?Math.ceil(e):Math.floor(e)}function h(){return typeof window<`u`&&typeof document<`u`}function g(e){return h()&&typeof requestAnimationFrame==`function`?requestAnimationFrame(e):setTimeout(()=>e(f()),16)}function _(e){e!=null&&(h()&&typeof cancelAnimationFrame==`function`&&typeof e==`number`?cancelAnimationFrame(e):clearTimeout(e))}function v(e){h()&&(document.readyState===`complete`||document.readyState===`interactive`?setTimeout(e,0):document.addEventListener(`DOMContentLoaded`,e,{once:!0}))}function y(e){h()&&setTimeout(()=>{window.odometerOptions&&(e.options=s(s({},e.options),window.odometerOptions))},0)}function b(e){v(()=>{e.options.auto!==!1&&e.init()})}function x(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.includes(r))continue;n[r]=e[r]}return n}function S(e,t){if(e==null)return{};var n,r,i=x(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.includes(n)||{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}const C=[`el`];var w,T=class n{get isAnimating(){return this._isAnimating}constructor(e){var r,i,o,c;if(a(this,`_isAnimating`,!1),a(this,`options`,void 0),a(this,`el`,void 0),a(this,`value`,0),a(this,`inside`,void 0),a(this,`observer`,void 0),a(this,`watchMutations`,!1),a(this,`transitionEndBound`,!1),a(this,`destroyed`,!1),a(this,`format`,{repeating:``,precision:0}),a(this,`MAX_VALUES`,void 0),a(this,`digits`,[]),a(this,`ribbons`,{}),a(this,`_rafId`,void 0),a(this,`_countRafId`,void 0),a(this,`_msPerFrame`,void 0),a(this,`_countMsPerFrame`,void 0),a(this,`_onTransitionEnd`,void 0),this.options=e,this.el=this.options.el,this.el.odometer){var l,u,d;let e=this.el.odometer;e.options=s(s({},e.options),this.options),(l=e.options).duration!=null||(l.duration=t);let n=(u=e.options.framerate)==null?30:u,r=(d=e.options.countFramerate)==null?20:d;return e._msPerFrame=1e3/n,e._countMsPerFrame=1e3/r,e.MAX_VALUES=e.options.duration/e._msPerFrame/2|0,e.resetFormat(),this.options.value==null?h()&&e.render():e.update(this.options.value),e}this.el.odometer=this,this.options=s(s({},n.options),this.options),(r=this.options).duration!=null||(r.duration=t);let f=(i=this.options.framerate)==null?30:i,p=(o=this.options.countFramerate)==null?20:o;this._msPerFrame=1e3/f,this._countMsPerFrame=1e3/p,this.MAX_VALUES=this.options.duration/this._msPerFrame/2|0,this.resetFormat(),this.value=this.cleanValue((c=this.options.value)==null?``:c),h()&&(this.renderInside(),this.render());try{for(let e of[`innerHTML`,`innerText`,`textContent`])Object.defineProperty(this.el,e,{get:()=>{if(e===`innerHTML`){var t,n;return(t=(n=this.inside)==null?void 0:n.outerHTML)==null?``:t}else{var r,i,a,o;return(r=(i=(a=this.inside)==null?void 0:a.innerText)==null?(o=this.inside)==null?void 0:o.textContent:i)==null?``:r}},set:e=>this.update(e)})}catch(e){h()&&this.watchForMutations()}}renderInside(){h()&&(this.inside=document.createElement(`div`),this.inside.className=`odometer-inside`,this.el.textContent=``,this.el.appendChild(this.inside))}watchForMutations(){try{this.observer!=null||(this.observer=new MutationObserver(e=>{let t=this.el.innerText||``;this.renderInside(),this.render(this.value),this.update(t)})),this.watchMutations=!0,this.startWatchingMutations()}catch(e){}}startWatchingMutations(){if(this.watchMutations&&h()){var e;(e=this.observer)==null||e.observe(this.el,{childList:!0})}}stopWatchingMutations(){var e;(e=this.observer)==null||e.disconnect()}cleanValue(e){if(typeof e==`string`){var t;e=e.replace((t=this.format.radix)==null?`.`:t,`<radix>`),e=e.replace(/[.,\s\u00A0\u202F]/g,``),e=e.replace(`<radix>`,`.`),e=parseFloat(e)||0}return p(e,this.format.precision)}bindTransitionEnd(){if(this.transitionEndBound)return;this.transitionEndBound=!0;let e=!1;this._onTransitionEnd=()=>e?!0:(e=!0,setTimeout(()=>{this.render(),e=!1,this._isAnimating=!1,d(this.el,`odometerdone`,{id:this.options.id,el:this.el,instance:this,value:this.value,options:this.getOptions()})},0),!0),this.el.addEventListener(`transitionend`,this._onTransitionEnd,!1)}resetFormat(){var t;let n=(t=this.options.format)==null?`(,ddd).dd`:t;n=n||`d`;let r=e.exec(n);if(!r)throw Error(`LightOdometer: Unparsable digit format`);let[i,a,o,s]=r,c=(s==null?void 0:s.length)||0;this.format={repeating:a,radix:o,precision:c}}render(e){var n;if(h()){e!=null||(e=this.value),this.stopWatchingMutations(),this.resetFormat(),this.inside.textContent=``;for(let e of Array.from(this.el.classList))/^odometer(-|$)/.test(e)&&this.el.classList.remove(e);this.el.classList.add(`odometer`,`odometer-auto-theme`),this.el.style.setProperty(`--odometer-duration`,`${(n=this.options.duration)==null?t:n}ms`),this.ribbons={},this.formatDigits(e),this.startWatchingMutations()}}formatDigits(e){if(this.digits=[],this.options.formatFunction){let t=this.options.formatFunction(e);for(let e of t.split(``).toReversed())if(/\d/.test(e)){let t=this.renderDigit(),n=t.querySelector(`.odometer-value`);n.textContent=e,u(n,`odometer-first-value odometer-last-value`),this.digits.push(t),this.insertDigit(t)}else this.addSpacer(e)}else{let t=this.preservePrecision(e),n=!this.format.precision;for(let e of t.split(``).toReversed())e===`.`&&(n=!0),this.addDigit(e,n)}}preservePrecision(e){let t=e.toString();if(this.format.precision){let e=t.split(`.`);e.length===1&&(t+=`.`,e[1]=``);for(let n=0;n<this.format.precision;n++)e[1][n]||(t+=`0`)}return t}update(e){if(!h())return this.value=this.cleanValue(e),this.value;e=this.cleanValue(e);let t=e-this.value;return t?(l(this.el,`odometer-animating-up odometer-animating-down odometer-animating`),t>0?u(this.el,`odometer-animating-up`):u(this.el,`odometer-animating-down`),this._isAnimating=!0,d(this.el,`odometerstart`,{id:this.options.id,el:this.el,instance:this,value:e,oldValue:this.value,options:this.getOptions()}),this.stopWatchingMutations(),this.animate(e),this.startWatchingMutations(),setTimeout(()=>{this.el.offsetHeight,u(this.el,`odometer-animating`)},0),this.value=e,this.value):this.value}renderDigit(){return c(`<span class="odometer-digit"><span class="odometer-digit-spacer">8</span><span class="odometer-digit-inner"><span class="odometer-ribbon"><span class="odometer-ribbon-inner"><span class="odometer-value"></span></span></span></span></span>`)}insertDigit(e,t){return t?this.inside.insertBefore(e,t):this.inside.children.length?this.inside.insertBefore(e,this.inside.children[0]):this.inside.appendChild(e)}addSpacer(e,t,n){let r=c(`<span class="odometer-formatting-mark"></span>`);return r.textContent=e,n&&u(r,n),this.insertDigit(r,t)}addDigit(e,t){if(t!=null||(t=!0),e===`-`)return this.addSpacer(e,null,`odometer-negation-mark`);if(e===`.`){var n;return this.addSpacer((n=this.format.radix)==null?`.`:n,null,`odometer-radix-mark`)}if(t){let e=!1;for(;;){if(!this.format.repeating.length){if(e)throw Error(`Bad odometer format without digits`);this.resetFormat(),e=!0}let t=this.format.repeating[this.format.repeating.length-1];if(this.format.repeating=this.format.repeating.substring(0,this.format.repeating.length-1),t===`d`)break;this.addSpacer(t)}}let r=this.renderDigit(),i=r.querySelector(`.odometer-value`);return i.textContent=e,u(i,`odometer-first-value odometer-last-value`),this.digits.push(r),this.insertDigit(r)}animate(e){this.options.animation===`count`?this.animateCount(e):this.animateSlide(e)}animateCount(e){if(!h())return;let t=e-this.value;if(!t)return;let n=f(),r=n,i=this.value,a=()=>{if(f()-n>(this.options.duration||0)){this.value=e,this.render(),this._isAnimating=!1,d(this.el,`odometerdone`,{id:this.options.id,el:this.el,instance:this,value:this.value,options:this.getOptions()});return}let o=f()-r;if(o>this._countMsPerFrame){r=f();let e=o/(this.options.duration||0),n=t*e;i+=n,this.render(Math.round(i))}this._countRafId=g(a)};this._countRafId=g(a)}getDigitCount(...e){for(let t=0;t<e.length;t++)e[t]=Math.abs(e[t]);let t=Math.max(...e);return Math.ceil(Math.log(t+1)/Math.log(10))}getFractionalDigitCount(...e){let t=/^-?\d*\.(\d*?)0*$/;for(let n=0;n<e.length;n++){let r=e[n].toString(),i=t.exec(r);e[n]=i?i[1].length:0}return Math.max(...e)}resetDigits(){this.digits=[],this.ribbons={},this.inside.textContent=``,this.resetFormat()}createRange(e,t,n){let r=e<t,i=Math.abs(t-e)+(n?1:0);return Array.from({length:i},(t,n)=>r?e+n:e-n)}animateSlide(e){if(!h())return;let t=this.value,n=this.format.precision;n&&(e*=10**n,t*=10**n);let r=e-t;if(!r)return;this.bindTransitionEnd();let i=[],a=this.getDigitCount(t,e),o=0,s=t;for(let n=0;n<a;n++){s=m(t/10**(a-n-1));let r=m(e/10**(a-n-1)),c=r-s,l;if(Math.abs(c)>this.MAX_VALUES){l=[];let e=this.MAX_VALUES*(1+o*.5),t=c/e,n=s;for(;c>0&&n<r||c<0&&n>r;)l.push(Math.round(n)),n+=t;l[l.length-1]!==r&&l.push(r),o++}else l=this.createRange(s,r,!0);for(let e=0;e<l.length;e++)l[e]=Math.abs(l[e]%10);i.push(l)}this.resetDigits();let c=i.toReversed();for(let e=0;e<c.length;e++){let t=c[e];if(this.digits[e]||this.addDigit(` `,e>=n),this.ribbons[e]===void 0){let t=this.digits[e].querySelector(`.odometer-ribbon-inner`);t&&(this.ribbons[e]=t)}this.ribbons[e].textContent=``,r<0&&(t=t.toReversed());for(let n=0;n<t.length;n++){let r=t[n],i=document.createElement(`div`);i.className=`odometer-value`,i.textContent=r.toString(),this.ribbons[e].appendChild(i),n===t.length-1&&u(i,`odometer-last-value`),n===0&&u(i,`odometer-first-value`)}}s<0&&this.addDigit(`-`);let l=this.inside.querySelector(`.odometer-radix-mark`);if(l&&l.parentNode.removeChild(l),n){var d;this.addSpacer((d=this.format.radix)==null?`.`:d,this.digits[n-1],`odometer-radix-mark`)}}static init(){if(!h())return[];let e=document.querySelectorAll(n.options.selector||`.odometer`);return Array.from(e,e=>{var t;return e.odometer=new n({el:e,value:(t=e.innerText)==null?e.textContent:t})})}setOptions(e){var n,r,i;if(!e||typeof e!=`object`)return;`el`in e&&delete e.el;let a=Object.prototype.hasOwnProperty.call(e,`value`),o=Object.prototype.hasOwnProperty.call(e,`format`)||Object.prototype.hasOwnProperty.call(e,`formatFunction`),c=Object.prototype.hasOwnProperty.call(e,`duration`)||Object.prototype.hasOwnProperty.call(e,`framerate`)||Object.prototype.hasOwnProperty.call(e,`countFramerate`);this.options=s(s({},this.options),e),(n=this.options).duration!=null||(n.duration=t);let l=(r=this.options.framerate)==null?30:r,u=(i=this.options.countFramerate)==null?20:i;if(this._msPerFrame=1e3/l,this._countMsPerFrame=1e3/u,this.MAX_VALUES=this.options.duration/this._msPerFrame/2|0,h()&&this.el.style.setProperty(`--odometer-duration`,`${this.options.duration}ms`),o&&this.resetFormat(),a){var d;this.update((d=this.options.value)==null?0:d);return}(o||c)&&h()&&(this.stopWatchingMutations(),this.render(),this.startWatchingMutations())}static setGlobalOptions(e){n.options=s(s({},n.options),e)}on(e,t){this.el.addEventListener(e,t)}off(e,t){this.el.removeEventListener(e,t)}getOptions(){return s({},this.options)}static getGlobalOptions(){return s({},n.options)}animateOnceAndDisconnect(e){var n;e!=null&&this.update(e);let r=()=>this.disconnect(),i=e=>{this.el.removeEventListener(`odometerdone`,i),r()};this.el.addEventListener(`odometerdone`,i,{once:!0}),setTimeout(r,((n=this.options.duration)==null?t:n)+100)}disconnect(){this.destroyed||(this.stopWatchingMutations(),_(this._rafId),_(this._countRafId),this._onTransitionEnd&&(this.el.removeEventListener(`transitionend`,this._onTransitionEnd),this._onTransitionEnd=void 0),this.transitionEndBound=!1,this.destroyed=!0)}toString(){let e=s({},this.getOptions()),{el:t}=e,r=S(e,C),i={id:this.options.id,value:this.value,options:r,globalOptions:n.getGlobalOptions(),watchMutations:this.watchMutations,transitionEndBound:this.transitionEndBound,destroyed:this.destroyed,format:this.format,isAnimating:this.isAnimating};return JSON.stringify(i)}};a(T,`options`,typeof window<`u`?(w=window.odometerOptions)==null?{}:w:{}),y(T),b(T);var E=T;export{E as default};
|