Админка
This commit is contained in:
1 parent
6d3adbb54c
commit
0e64eede38
301 files changed
+296588
-14
No files matched your search
+21
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021 Cristopher
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
<h1 align='center'>
|
||||
Vue3 Autocounter
|
||||
</h1>
|
||||
|
||||
<p align='center'>
|
||||
<a href="https://vue3autocounter.cristopherps.dev/" target="_blank">
|
||||
<img src="https://cristopherps.com/assets/vue3-autocounter.gif" width="700">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<p align='center'>
|
||||
<a href="https://vue3autocounter.cristopherps.dev/" target="_blank">
|
||||
View Demo
|
||||
</a> | <a href="https://vue3autocounter.cristopherps.dev/docs" target="_blank">
|
||||
Full Docs
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<p align='center'>
|
||||
<img src="https://img.shields.io/badge/JavaScript-F7DF1E?style=for-the-badge&logo=javascript&logoColor=black"/>
|
||||
<img src="https://img.shields.io/badge/TypeScript-007ACC?style=for-the-badge&logo=typescript&logoColor=white"/>
|
||||
<img src="https://img.shields.io/badge/Vue.js-35495E?style=for-the-badge&logo=vue.js&logoColor=4FC08D"/>
|
||||
<img src="https://img.shields.io/badge/npm-CB3837?style=for-the-badge&logo=npm&logoColor=white"/>
|
||||
</p>
|
||||
|
||||
<p align='center'>
|
||||
<img src="https://img.shields.io/npm/dt/vue3-autocounter?style=for-the-badge"/>
|
||||
<img src="https://img.shields.io/npm/v/vue3-autocounter?style=for-the-badge"/>
|
||||
<img src="https://img.shields.io/github/license/ps-cristopher/vue3-autocounter?style=for-the-badge"/>
|
||||
<img src="https://img.shields.io/github/languages/top/ps-cristopher/vue3-autocounter?style=for-the-badge"/>
|
||||
<img src="https://img.shields.io/github/stars/ps-cristopher/vue3-autocounter?style=for-the-badge"/>
|
||||
</p>
|
||||
|
||||
<p align='center'>
|
||||
<a href="https://twitter.com/ps_cristopher" target="_blank">
|
||||
<img src="https://img.shields.io/twitter/follow/ps_cristopher?style=social"/>
|
||||
</a>
|
||||
<a href="https://github.com/ps-cristopher" target="_blank">
|
||||
<img src="https://img.shields.io/github/followers/ps-cristopher?label=%40ps-cristopher&style=social"/>
|
||||
</a>
|
||||
</p>
|
||||
|
||||
## Description
|
||||
A lightweight Vue 3 component made with TypeScript, you can use it to create an animation that shows an automatic count for any quantity with a specified duration, it can be used for counting up and down.
|
||||
|
||||
## Installation
|
||||
You can install it easily with NPM.
|
||||
|
||||
```sh
|
||||
npm install vue3-autocounter
|
||||
```
|
||||
|
||||
## Usage
|
||||
Add the vue3-autocounter to your main.js for a global import:
|
||||
|
||||
```javascript
|
||||
import { createApp } from 'vue';
|
||||
import Vue3Autocounter from 'vue3-autocounter';
|
||||
import App from './App.vue';
|
||||
|
||||
createApp(App)
|
||||
.component('vue3-autocounter', Vue3Autocounter)
|
||||
.mount('#app');
|
||||
```
|
||||
|
||||
If you prefer yo can import it directly in your Single File Component:
|
||||
|
||||
```javascript
|
||||
import { defineComponent } from 'vue';
|
||||
import Vue3autocounter from 'vue3-autocounter';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'Demo',
|
||||
components: {
|
||||
'vue3-autocounter': Vue3autocounter
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
Finally you can use it on your template:
|
||||
|
||||
|
||||
```html
|
||||
<template>
|
||||
<vue3-autocounter ref='counter' :startAmount='0' :endAmount='2021' :duration='3' prefix='$' suffix='USD' separator=',' decimalSeparator='.' :decimals='2' :autoinit='true' @finished='alert(`Counting finished!`)'/>
|
||||
</template>
|
||||
```
|
||||
|
||||
Go to <a href="https://vue3autocounter.cristopherps.dev/docs"> full documentation </a> with properties, events and methods specifications.
|
||||
|
||||
## Support
|
||||
Send me an email to
|
||||
<a href="mailto:info@cristopherps.com">info@cristopherps.com</a>.
|
||||
You can also send me a direct message on twitter
|
||||
<a href="https://twitter.com/ps_cristopher">@ps_cristopher</a>.
|
||||
|
||||
## Contributing
|
||||
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
|
||||
|
||||
## Contributors
|
||||
<p align="center">
|
||||
<a href="https://github.com/ps-cristopher/vue3-autocounter/graphs/contributors">
|
||||
<img src="https://contrib.rocks/image?repo=ps-cristopher/vue3-autocounter" />
|
||||
</a>
|
||||
</p>
|
||||
|
||||
Made with [contributors-img](https://contrib.rocks).
|
||||
|
||||
## License
|
||||
[MIT](https://choosealicense.com/licenses/mit/) License © 2021 [Cristopher PS](https://github.com/ps-cristopher)
|
||||
+207
@@ -0,0 +1,207 @@
|
||||
import { defineComponent, openBlock, createBlock, toDisplayString } from 'vue';
|
||||
|
||||
var script = defineComponent({
|
||||
name: "Vue3Autocounter",
|
||||
interval: null,
|
||||
props: {
|
||||
startAmount: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
endAmount: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
required: true
|
||||
},
|
||||
duration: {
|
||||
type: Number,
|
||||
default: 3,
|
||||
|
||||
validator(duration) {
|
||||
return duration >= 1;
|
||||
}
|
||||
|
||||
},
|
||||
autoinit: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
prefix: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
suffix: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
separator: {
|
||||
type: String,
|
||||
default: ','
|
||||
},
|
||||
decimalSeparator: {
|
||||
type: String,
|
||||
default: '.'
|
||||
},
|
||||
decimals: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
|
||||
validator(decimals) {
|
||||
return decimals >= 0;
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
timestamp: 0,
|
||||
startTimestamp: 0,
|
||||
currentAmount: 0,
|
||||
currentStartAmount: 0,
|
||||
currentDuration: 0,
|
||||
paused: false,
|
||||
remaining: 0,
|
||||
animationFrame: 0
|
||||
};
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.currentAmount = this.startAmount;
|
||||
this.currentStartAmount = this.startAmount;
|
||||
this.currentDuration = this.duration * 1000;
|
||||
this.remaining = this.duration * 1000;
|
||||
if (this.autoinit) this.start();else this.paused = true;
|
||||
this.$emit('mounted');
|
||||
},
|
||||
|
||||
unmounted() {
|
||||
this.cancelAnimation();
|
||||
},
|
||||
|
||||
watch: {
|
||||
startAmount() {
|
||||
this.reset();
|
||||
},
|
||||
|
||||
endAmount() {
|
||||
this.reset();
|
||||
},
|
||||
|
||||
duration() {
|
||||
this.reset();
|
||||
}
|
||||
|
||||
},
|
||||
computed: {
|
||||
isCountingUp() {
|
||||
return this.endAmount > this.startAmount;
|
||||
},
|
||||
|
||||
displayedAmount() {
|
||||
return `${this.prefix}${this.formatedAmount}${this.suffix}`;
|
||||
},
|
||||
|
||||
formatedAmount() {
|
||||
const regex = /(\d+)(\d{3})/;
|
||||
let numberString = this.currentAmount.toFixed(this.decimals);
|
||||
numberString += '';
|
||||
let numberArray = numberString.split('.');
|
||||
let numbers = numberArray[0];
|
||||
let decimals = numberArray.length > 1 ? this.decimalSeparator + numberArray[1] : '';
|
||||
let isNumber = !isNaN(parseFloat(this.separator));
|
||||
|
||||
if (this.separator && !isNumber) {
|
||||
while (regex.test(numbers)) numbers = numbers.replace(regex, '$1' + this.separator + '$2');
|
||||
}
|
||||
|
||||
return numbers + decimals;
|
||||
}
|
||||
|
||||
},
|
||||
methods: {
|
||||
start() {
|
||||
this.cancelAnimation();
|
||||
this.currentStartAmount = this.startAmount;
|
||||
this.startTimestamp = null;
|
||||
this.currentDuration = this.duration * 1000;
|
||||
this.paused = false;
|
||||
this.animationFrame = window.requestAnimationFrame(this.counting);
|
||||
},
|
||||
|
||||
pause() {
|
||||
if (this.paused) return;
|
||||
this.cancelAnimation();
|
||||
this.paused = true;
|
||||
},
|
||||
|
||||
resume() {
|
||||
if (!this.paused) return;
|
||||
this.startTimestamp = null;
|
||||
this.currentDuration = +this.remaining;
|
||||
this.currentStartAmount = +this.currentAmount;
|
||||
this.animationFrame = window.requestAnimationFrame(this.counting);
|
||||
this.paused = false;
|
||||
},
|
||||
|
||||
reset() {
|
||||
this.paused = false;
|
||||
this.startTimestamp = null;
|
||||
this.cancelAnimation();
|
||||
this.currentAmount = this.startAmount;
|
||||
if (this.autoinit) this.start();else this.paused = true;
|
||||
},
|
||||
|
||||
counting(timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
if (!this.startTimestamp) this.startTimestamp = timestamp;
|
||||
let progress = timestamp - this.startTimestamp;
|
||||
this.remaining = this.currentDuration - progress;
|
||||
|
||||
if (!this.isCountingUp) {
|
||||
this.currentAmount = this.currentStartAmount - (this.currentStartAmount - this.endAmount) * (progress / this.currentDuration);
|
||||
this.currentAmount = this.currentAmount < this.endAmount ? this.endAmount : this.currentAmount;
|
||||
} else {
|
||||
this.currentAmount = this.currentStartAmount + (this.endAmount - this.currentStartAmount) * (progress / this.currentDuration);
|
||||
this.currentAmount = this.currentAmount > this.endAmount ? this.endAmount : this.currentAmount;
|
||||
}
|
||||
|
||||
if (progress < this.currentDuration) this.animationFrame = window.requestAnimationFrame(this.counting);else {
|
||||
setTimeout(() => {
|
||||
this.$emit('finished');
|
||||
}, 1000);
|
||||
}
|
||||
},
|
||||
|
||||
cancelAnimation() {
|
||||
if (this.animationFrame) window.cancelAnimationFrame(this.animationFrame);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
function render(_ctx, _cache, $props, $setup, $data, $options) {
|
||||
return openBlock(), createBlock("span", null, toDisplayString(_ctx.displayedAmount), 1);
|
||||
}
|
||||
|
||||
script.render = render;
|
||||
|
||||
// Import vue component
|
||||
|
||||
// Default export is installable instance of component.
|
||||
// IIFE injects install function into component, allowing component
|
||||
// to be registered via Vue.use() as well as Vue.component(),
|
||||
var entry_esm = /*#__PURE__*/(() => {
|
||||
// Assign InstallableComponent type
|
||||
const installable = script; // Attach install function executed by Vue.use()
|
||||
|
||||
installable.install = app => {
|
||||
app.component('Vue3Autocounter', installable);
|
||||
};
|
||||
|
||||
return installable;
|
||||
})(); // It's possible to expose named exports when writing components that can
|
||||
// also be used as directives, etc. - eg. import { RollupDemoDirective } from 'rollup-demo';
|
||||
// export const RollupDemoDirective = directive;
|
||||
|
||||
export default entry_esm;
|
||||
+1
@@ -0,0 +1 @@
|
||||
var Vue3Autocounter=function(t){"use strict";function n(t,n){return function(t){if(Array.isArray(t))return t}(t)||function(t,n){if("undefined"==typeof Symbol||!(Symbol.iterator in Object(t)))return;var r=[],i=!0,e=!1,u=void 0;try{for(var a,o=t[Symbol.iterator]();!(i=(a=o.next()).done)&&(r.push(a.value),!n||r.length!==n);i=!0);}catch(t){e=!0,u=t}finally{try{i||null==o.return||o.return()}finally{if(e)throw u}}return r}(t,n)||function(t,n){if(!t)return;if("string"==typeof t)return r(t,n);var i=Object.prototype.toString.call(t).slice(8,-1);"Object"===i&&t.constructor&&(i=t.constructor.name);if("Map"===i||"Set"===i)return Array.from(t);if("Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i))return r(t,n)}(t,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function r(t,n){(null==n||n>t.length)&&(n=t.length);for(var r=0,i=new Array(n);r<n;r++)i[r]=t[r];return i}var i=t.defineComponent({name:"Vue3Autocounter",interval:null,props:{startAmount:{type:Number,default:0},endAmount:{type:Number,default:0,required:!0},duration:{type:Number,default:3,validator:function(t){return t>=1}},autoinit:{type:Boolean,default:!0},prefix:{type:String,default:""},suffix:{type:String,default:""},separator:{type:String,default:","},decimalSeparator:{type:String,default:"."},decimals:{type:Number,default:0,validator:function(t){return t>=0}}},data:function(){return{timestamp:0,startTimestamp:0,currentAmount:0,currentStartAmount:0,currentDuration:0,paused:!1,remaining:0,animationFrame:0}},mounted:function(){this.currentAmount=this.startAmount,this.currentStartAmount=this.startAmount,this.currentDuration=1e3*this.duration,this.remaining=1e3*this.duration,this.autoinit?this.start():this.paused=!0,this.$emit("mounted")},unmounted:function(){this.cancelAnimation()},watch:{startAmount:function(){this.reset()},endAmount:function(){this.reset()},duration:function(){this.reset()}},computed:{isCountingUp:function(){return this.endAmount>this.startAmount},displayedAmount:function(){return"".concat(this.prefix).concat(this.formatedAmount).concat(this.suffix)},formatedAmount:function(){var t=/(\d+)(\d{3})/,n=this.currentAmount.toFixed(this.decimals),r=(n+="").split("."),i=r[0],e=r.length>1?this.decimalSeparator+r[1]:"",u=!isNaN(parseFloat(this.separator));if(this.separator&&!u)for(;t.test(i);)i=i.replace(t,"$1"+this.separator+"$2");return i+e}},methods:{start:function(){this.cancelAnimation(),this.currentStartAmount=this.startAmount,this.startTimestamp=null,this.currentDuration=1e3*this.duration,this.paused=!1,this.animationFrame=window.requestAnimationFrame(this.counting)},pause:function(){this.paused||(this.cancelAnimation(),this.paused=!0)},resume:function(){this.paused&&(this.startTimestamp=null,this.currentDuration=+this.remaining,this.currentStartAmount=+this.currentAmount,this.animationFrame=window.requestAnimationFrame(this.counting),this.paused=!1)},reset:function(){this.paused=!1,this.startTimestamp=null,this.cancelAnimation(),this.currentAmount=this.startAmount,this.autoinit?this.start():this.paused=!0},counting:function(t){var n=this;this.timestamp=t,this.startTimestamp||(this.startTimestamp=t);var r=t-this.startTimestamp;this.remaining=this.currentDuration-r,this.isCountingUp?(this.currentAmount=this.currentStartAmount+(this.endAmount-this.currentStartAmount)*(r/this.currentDuration),this.currentAmount=this.currentAmount>this.endAmount?this.endAmount:this.currentAmount):(this.currentAmount=this.currentStartAmount-(this.currentStartAmount-this.endAmount)*(r/this.currentDuration),this.currentAmount=this.currentAmount<this.endAmount?this.endAmount:this.currentAmount),r<this.currentDuration?this.animationFrame=window.requestAnimationFrame(this.counting):setTimeout((function(){n.$emit("finished")}),1e3)},cancelAnimation:function(){this.animationFrame&&window.cancelAnimationFrame(this.animationFrame)}}});i.render=function(n,r,i,e,u,a){return t.openBlock(),t.createBlock("span",null,t.toDisplayString(n.displayedAmount),1)};var e=function(){var t=i;return t.install=function(n){n.component("Vue3Autocounter",t)},t}(),u=Object.freeze({__proto__:null,default:e});return Object.entries(u).forEach((function(t){var r=n(t,2),i=r[0],u=r[1];"default"!==i&&(e[i]=u)})),e}(Vue);
|
||||
+245
@@ -0,0 +1,245 @@
|
||||
'use strict';var vue=require('vue');function _slicedToArray(arr, i) {
|
||||
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
||||
}
|
||||
|
||||
function _arrayWithHoles(arr) {
|
||||
if (Array.isArray(arr)) return arr;
|
||||
}
|
||||
|
||||
function _iterableToArrayLimit(arr, i) {
|
||||
if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
|
||||
var _arr = [];
|
||||
var _n = true;
|
||||
var _d = false;
|
||||
var _e = undefined;
|
||||
|
||||
try {
|
||||
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
|
||||
_arr.push(_s.value);
|
||||
|
||||
if (i && _arr.length === i) break;
|
||||
}
|
||||
} catch (err) {
|
||||
_d = true;
|
||||
_e = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_n && _i["return"] != null) _i["return"]();
|
||||
} finally {
|
||||
if (_d) throw _e;
|
||||
}
|
||||
}
|
||||
|
||||
return _arr;
|
||||
}
|
||||
|
||||
function _unsupportedIterableToArray(o, minLen) {
|
||||
if (!o) return;
|
||||
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
||||
var n = Object.prototype.toString.call(o).slice(8, -1);
|
||||
if (n === "Object" && o.constructor) n = o.constructor.name;
|
||||
if (n === "Map" || n === "Set") return Array.from(o);
|
||||
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
||||
}
|
||||
|
||||
function _arrayLikeToArray(arr, len) {
|
||||
if (len == null || len > arr.length) len = arr.length;
|
||||
|
||||
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
||||
|
||||
return arr2;
|
||||
}
|
||||
|
||||
function _nonIterableRest() {
|
||||
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
||||
}var script = vue.defineComponent({
|
||||
name: "Vue3Autocounter",
|
||||
interval: null,
|
||||
props: {
|
||||
startAmount: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
endAmount: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
required: true
|
||||
},
|
||||
duration: {
|
||||
type: Number,
|
||||
default: 3,
|
||||
validator: function validator(duration) {
|
||||
return duration >= 1;
|
||||
}
|
||||
},
|
||||
autoinit: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
prefix: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
suffix: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
separator: {
|
||||
type: String,
|
||||
default: ','
|
||||
},
|
||||
decimalSeparator: {
|
||||
type: String,
|
||||
default: '.'
|
||||
},
|
||||
decimals: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
validator: function validator(decimals) {
|
||||
return decimals >= 0;
|
||||
}
|
||||
}
|
||||
},
|
||||
data: function data() {
|
||||
return {
|
||||
timestamp: 0,
|
||||
startTimestamp: 0,
|
||||
currentAmount: 0,
|
||||
currentStartAmount: 0,
|
||||
currentDuration: 0,
|
||||
paused: false,
|
||||
remaining: 0,
|
||||
animationFrame: 0
|
||||
};
|
||||
},
|
||||
mounted: function mounted() {
|
||||
this.currentAmount = this.startAmount;
|
||||
this.currentStartAmount = this.startAmount;
|
||||
this.currentDuration = this.duration * 1000;
|
||||
this.remaining = this.duration * 1000;
|
||||
if (this.autoinit) this.start();else this.paused = true;
|
||||
this.$emit('mounted');
|
||||
},
|
||||
unmounted: function unmounted() {
|
||||
this.cancelAnimation();
|
||||
},
|
||||
watch: {
|
||||
startAmount: function startAmount() {
|
||||
this.reset();
|
||||
},
|
||||
endAmount: function endAmount() {
|
||||
this.reset();
|
||||
},
|
||||
duration: function duration() {
|
||||
this.reset();
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
isCountingUp: function isCountingUp() {
|
||||
return this.endAmount > this.startAmount;
|
||||
},
|
||||
displayedAmount: function displayedAmount() {
|
||||
return "".concat(this.prefix).concat(this.formatedAmount).concat(this.suffix);
|
||||
},
|
||||
formatedAmount: function formatedAmount() {
|
||||
var regex = /(\d+)(\d{3})/;
|
||||
var numberString = this.currentAmount.toFixed(this.decimals);
|
||||
numberString += '';
|
||||
var numberArray = numberString.split('.');
|
||||
var numbers = numberArray[0];
|
||||
var decimals = numberArray.length > 1 ? this.decimalSeparator + numberArray[1] : '';
|
||||
var isNumber = !isNaN(parseFloat(this.separator));
|
||||
|
||||
if (this.separator && !isNumber) {
|
||||
while (regex.test(numbers)) {
|
||||
numbers = numbers.replace(regex, '$1' + this.separator + '$2');
|
||||
}
|
||||
}
|
||||
|
||||
return numbers + decimals;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
start: function start() {
|
||||
this.cancelAnimation();
|
||||
this.currentStartAmount = this.startAmount;
|
||||
this.startTimestamp = null;
|
||||
this.currentDuration = this.duration * 1000;
|
||||
this.paused = false;
|
||||
this.animationFrame = window.requestAnimationFrame(this.counting);
|
||||
},
|
||||
pause: function pause() {
|
||||
if (this.paused) return;
|
||||
this.cancelAnimation();
|
||||
this.paused = true;
|
||||
},
|
||||
resume: function resume() {
|
||||
if (!this.paused) return;
|
||||
this.startTimestamp = null;
|
||||
this.currentDuration = +this.remaining;
|
||||
this.currentStartAmount = +this.currentAmount;
|
||||
this.animationFrame = window.requestAnimationFrame(this.counting);
|
||||
this.paused = false;
|
||||
},
|
||||
reset: function reset() {
|
||||
this.paused = false;
|
||||
this.startTimestamp = null;
|
||||
this.cancelAnimation();
|
||||
this.currentAmount = this.startAmount;
|
||||
if (this.autoinit) this.start();else this.paused = true;
|
||||
},
|
||||
counting: function counting(timestamp) {
|
||||
var _this = this;
|
||||
|
||||
this.timestamp = timestamp;
|
||||
if (!this.startTimestamp) this.startTimestamp = timestamp;
|
||||
var progress = timestamp - this.startTimestamp;
|
||||
this.remaining = this.currentDuration - progress;
|
||||
|
||||
if (!this.isCountingUp) {
|
||||
this.currentAmount = this.currentStartAmount - (this.currentStartAmount - this.endAmount) * (progress / this.currentDuration);
|
||||
this.currentAmount = this.currentAmount < this.endAmount ? this.endAmount : this.currentAmount;
|
||||
} else {
|
||||
this.currentAmount = this.currentStartAmount + (this.endAmount - this.currentStartAmount) * (progress / this.currentDuration);
|
||||
this.currentAmount = this.currentAmount > this.endAmount ? this.endAmount : this.currentAmount;
|
||||
}
|
||||
|
||||
if (progress < this.currentDuration) this.animationFrame = window.requestAnimationFrame(this.counting);else {
|
||||
setTimeout(function () {
|
||||
_this.$emit('finished');
|
||||
}, 1000);
|
||||
}
|
||||
},
|
||||
cancelAnimation: function cancelAnimation() {
|
||||
if (this.animationFrame) window.cancelAnimationFrame(this.animationFrame);
|
||||
}
|
||||
}
|
||||
});function render(_ctx, _cache, $props, $setup, $data, $options) {
|
||||
return vue.openBlock(), vue.createBlock("span", null, vue.toDisplayString(_ctx.displayedAmount), 1);
|
||||
}script.render = render;// Import vue component
|
||||
|
||||
// Default export is installable instance of component.
|
||||
// IIFE injects install function into component, allowing component
|
||||
// to be registered via Vue.use() as well as Vue.component(),
|
||||
var component = /*#__PURE__*/(function () {
|
||||
// Assign InstallableComponent type
|
||||
var installable = script; // Attach install function executed by Vue.use()
|
||||
|
||||
installable.install = function (app) {
|
||||
app.component('Vue3Autocounter', installable);
|
||||
};
|
||||
|
||||
return installable;
|
||||
})(); // It's possible to expose named exports when writing components that can
|
||||
// also be used as directives, etc. - eg. import { RollupDemoDirective } from 'rollup-demo';
|
||||
// export const RollupDemoDirective = directive;
|
||||
var namedExports=/*#__PURE__*/Object.freeze({__proto__:null,'default': component});// only expose one global var, with named exports exposed as properties of
|
||||
// that global var (eg. plugin.namedExport)
|
||||
|
||||
Object.entries(namedExports).forEach(function (_ref) {
|
||||
var _ref2 = _slicedToArray(_ref, 2),
|
||||
exportName = _ref2[0],
|
||||
exported = _ref2[1];
|
||||
|
||||
if (exportName !== 'default') component[exportName] = exported;
|
||||
});module.exports=component;
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
{
|
||||
"name": "vue3-autocounter",
|
||||
"keywords": [
|
||||
"vue3-autocounter",
|
||||
"autocounter",
|
||||
"vue3",
|
||||
"vue",
|
||||
"vuejs",
|
||||
"counter",
|
||||
"counting",
|
||||
"counto",
|
||||
"countup",
|
||||
"countdown",
|
||||
"vue-animation",
|
||||
"vue-component"
|
||||
],
|
||||
"version": "1.0.6",
|
||||
"description": "A lightweight Vue 3 component made with TypeScript, you can use it to create an animation that shows an automatic count for any quantity with a specified duration, it can be used for counting up and down.",
|
||||
"author": "Cristopher PS <info@cristopherps.com>",
|
||||
"main": "dist/vue3-autocounter.ssr.js",
|
||||
"browser": "dist/vue3-autocounter.esm.js",
|
||||
"module": "dist/vue3-autocounter.esm.js",
|
||||
"unpkg": "dist/vue3-autocounter.min.js",
|
||||
"types": "vue3-autocounter.d.ts",
|
||||
"files": [
|
||||
"dist/*",
|
||||
"vue3-autocounter.d.ts",
|
||||
"src/**/*.vue"
|
||||
],
|
||||
"sideEffects": false,
|
||||
"scripts": {
|
||||
"serve": "vue-cli-service serve dev/serve.ts",
|
||||
"build": "cross-env NODE_ENV=production rollup --config build/rollup.config.js",
|
||||
"build:ssr": "cross-env NODE_ENV=production rollup --config build/rollup.config.js --format cjs",
|
||||
"build:es": "cross-env NODE_ENV=production rollup --config build/rollup.config.js --format es",
|
||||
"build:unpkg": "cross-env NODE_ENV=production rollup --config build/rollup.config.js --format iife"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.12.10",
|
||||
"@babel/preset-env": "^7.12.11",
|
||||
"@babel/preset-typescript": "^7.12.7",
|
||||
"@rollup/plugin-alias": "^3.1.1",
|
||||
"@rollup/plugin-babel": "^5.2.2",
|
||||
"@rollup/plugin-commonjs": "^17.0.0",
|
||||
"@rollup/plugin-node-resolve": "^11.0.1",
|
||||
"@rollup/plugin-replace": "^2.3.4",
|
||||
"@vue/cli-plugin-babel": "^4.5.10",
|
||||
"@vue/cli-plugin-typescript": "^4.5.10",
|
||||
"@vue/cli-service": "^4.5.10",
|
||||
"@vue/compiler-sfc": "^3.0.5",
|
||||
"cross-env": "^7.0.3",
|
||||
"minimist": "^1.2.5",
|
||||
"postcss": "^8.2.3",
|
||||
"rollup": "^2.36.1",
|
||||
"rollup-plugin-postcss": "^4.0.0",
|
||||
"rollup-plugin-terser": "^7.0.2",
|
||||
"rollup-plugin-vue": "^6.0.0",
|
||||
"typescript": "^3.8.3",
|
||||
"vue": "^3.0.5"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"vue": "^3.0.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
}
|
||||
+178
@@ -0,0 +1,178 @@
|
||||
<template>
|
||||
<span>{{displayedAmount}}</span>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from "vue";
|
||||
|
||||
interface Data {
|
||||
timestamp: number,
|
||||
startTimestamp: number,
|
||||
currentStartAmount: number,
|
||||
currentAmount: number,
|
||||
currentDuration: number,
|
||||
paused: boolean,
|
||||
remaining: number,
|
||||
animationFrame: number
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
name: "Vue3Autocounter",
|
||||
interval: null,
|
||||
props: {
|
||||
startAmount: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
endAmount: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
required: true
|
||||
},
|
||||
duration: {
|
||||
type: Number,
|
||||
default: 3,
|
||||
validator(duration: number): boolean {
|
||||
return duration >= 1;
|
||||
}
|
||||
},
|
||||
autoinit: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
prefix: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
suffix: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
separator: {
|
||||
type: String,
|
||||
default: ','
|
||||
},
|
||||
decimalSeparator: {
|
||||
type: String,
|
||||
default: '.'
|
||||
},
|
||||
decimals: {
|
||||
type: Number,
|
||||
default: 0,
|
||||
validator(decimals: number): boolean {
|
||||
return decimals >= 0;
|
||||
}
|
||||
}
|
||||
},
|
||||
data(): Data {
|
||||
return {
|
||||
timestamp: 0,
|
||||
startTimestamp: 0,
|
||||
currentAmount: 0,
|
||||
currentStartAmount: 0,
|
||||
currentDuration: 0,
|
||||
paused: false,
|
||||
remaining: 0,
|
||||
animationFrame: 0
|
||||
};
|
||||
},
|
||||
mounted (): void {
|
||||
this.currentAmount = this.startAmount;
|
||||
this.currentStartAmount = this.startAmount;
|
||||
this.currentDuration = this.duration * 1000;
|
||||
this.remaining = this.duration * 1000;
|
||||
if (this.autoinit) this.start();
|
||||
else this.paused = true;
|
||||
this.$emit('mounted');
|
||||
},
|
||||
unmounted(): void {
|
||||
this.cancelAnimation();
|
||||
},
|
||||
watch: {
|
||||
startAmount(): void {
|
||||
this.reset();
|
||||
},
|
||||
endAmount(): void {
|
||||
this.reset();
|
||||
},
|
||||
duration(): void {
|
||||
this.reset();
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
isCountingUp(): boolean {
|
||||
return this.endAmount > this.startAmount;
|
||||
},
|
||||
displayedAmount(): string {
|
||||
return `${this.prefix}${this.formatedAmount}${this.suffix}`;
|
||||
},
|
||||
formatedAmount(): string {
|
||||
const regex = /(\d+)(\d{3})/;
|
||||
|
||||
let numberString: string = this.currentAmount.toFixed(this.decimals);
|
||||
numberString += '';
|
||||
let numberArray:Array<string> = numberString.split('.');
|
||||
let numbers: string = numberArray[0];
|
||||
let decimals: string = numberArray.length > 1 ? this.decimalSeparator + numberArray[1] : '';
|
||||
let isNumber = !isNaN(parseFloat(this.separator));
|
||||
|
||||
if (this.separator && !isNumber) {
|
||||
while (regex.test(numbers)) numbers = numbers.replace(regex, '$1' + this.separator + '$2');
|
||||
}
|
||||
|
||||
return numbers + decimals;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
start(): void {
|
||||
this.cancelAnimation();
|
||||
this.currentStartAmount = this.startAmount;
|
||||
this.startTimestamp = null;
|
||||
this.currentDuration = this.duration * 1000;
|
||||
this.paused = false;
|
||||
this.animationFrame = window.requestAnimationFrame(this.counting);
|
||||
},
|
||||
pause(): void {
|
||||
if (this.paused) return;
|
||||
this.cancelAnimation();
|
||||
this.paused = true;
|
||||
},
|
||||
resume(): void {
|
||||
if (!this.paused) return;
|
||||
this.startTimestamp = null;
|
||||
this.currentDuration = +this.remaining;
|
||||
this.currentStartAmount = +this.currentAmount;
|
||||
this.animationFrame = window.requestAnimationFrame(this.counting);
|
||||
this.paused = false;
|
||||
},
|
||||
reset(): void {
|
||||
this.paused = false;
|
||||
this.startTimestamp = null;
|
||||
this.cancelAnimation();
|
||||
this.currentAmount = this.startAmount;
|
||||
if (this.autoinit) this.start();
|
||||
else this.paused = true;
|
||||
},
|
||||
counting(timestamp: number): void {
|
||||
this.timestamp = timestamp;
|
||||
if (!this.startTimestamp) this.startTimestamp = timestamp;
|
||||
let progress: number = timestamp - this.startTimestamp;
|
||||
this.remaining = this.currentDuration - progress;
|
||||
|
||||
if (!this.isCountingUp) {
|
||||
this.currentAmount = this.currentStartAmount - ((this.currentStartAmount - this.endAmount) * (progress / this.currentDuration));
|
||||
this.currentAmount = this.currentAmount < this.endAmount ? this.endAmount : this.currentAmount;
|
||||
} else {
|
||||
this.currentAmount = this.currentStartAmount + (this.endAmount - this.currentStartAmount) * (progress / this.currentDuration);
|
||||
this.currentAmount = this.currentAmount > this.endAmount ? this.endAmount : this.currentAmount;
|
||||
}
|
||||
|
||||
if (progress < this.currentDuration) this.animationFrame = window.requestAnimationFrame(this.counting);
|
||||
else this.$emit('finished');
|
||||
},
|
||||
cancelAnimation(): void {
|
||||
if (this.animationFrame) window.cancelAnimationFrame(this.animationFrame);
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import { DefineComponent, Plugin } from 'vue';
|
||||
|
||||
declare const Vue3Autocounter: DefineComponent<{}, {}, any> & { install: Exclude<Plugin['install'], undefined> };
|
||||
export default Vue3Autocounter;
|
||||
Reference in new issue
Block a user