@@ -73,19 +73,18 @@
<countdown [config]="{ stopTime: 1493313440499 }">
-
+
+
diff --git a/src/app/components/demo.component.scss b/src/app/components/demo.component.scss
index d8cca05..e884609 100644
--- a/src/app/components/demo.component.scss
+++ b/src/app/components/demo.component.scss
@@ -4,11 +4,27 @@
width: 6px;
}
&::-webkit-scrollbar-track {
- -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
+ box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3);
border-radius: 10px;
}
&::-webkit-scrollbar-thumb {
border-radius: 10px;
- -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.5);
+ box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.5);
+ }
+}
+
+.custom-style {
+ font-size: 18px;
+ .item {
+ padding-left: 4px;
+ &:nth-child(1) {
+ color: rgb(199, 66, 0);
+ }
+ &:nth-child(2) {
+ color: rgb(45, 0, 170);
+ }
+ &:nth-child(3) {
+ color: rgb(207, 7, 147);
+ }
}
}
diff --git a/src/app/components/demo.component.ts b/src/app/components/demo.component.ts
index 2454888..ea9e620 100644
--- a/src/app/components/demo.component.ts
+++ b/src/app/components/demo.component.ts
@@ -1,13 +1,10 @@
-import {
- Component,
- OnInit,
- ViewEncapsulation,
- AfterViewInit,
- ViewChild,
- ElementRef,
-} from '@angular/core';
-import { ToastrService } from 'ngx-toastr';
-import { CountdownComponent } from 'ngx-countdown';
+// tslint:disable: member-ordering
+import { Component, ViewEncapsulation, ViewChild, Inject, LOCALE_ID } from '@angular/core';
+import { formatDate } from '@angular/common';
+import { CountdownComponent, CountdownConfig, CountdownEvent } from 'ngx-countdown';
+import { format } from 'date-fns';
+
+const MINIUES = 1000 * 60;
@Component({
selector: 'demo',
@@ -16,31 +13,59 @@ import { CountdownComponent } from 'ngx-countdown';
encapsulation: ViewEncapsulation.None,
})
export class DemoComponent {
- constructor(private ts: ToastrService) {}
-
+ @ViewChild('countdown', { static: false }) private counter: CountdownComponent;
+ stopConfig: CountdownConfig = { stopTime: new Date().getTime() + 1000 * 30 };
notify: string;
- config: any = { leftTime: 10, notify: [2, 5] };
- onStart() {
- this.notify = '开始鸟';
- }
- onFinished() {
- this.notify = '结束了!';
- }
- onNotify(time: number) {
- this.notify = `在${time}ms时通知了一下`;
- }
+ config: CountdownConfig = { leftTime: 10, notify: [2, 5] };
+ customFormat: CountdownConfig = {
+ leftTime: 65,
+ formatDate: ({ date, formatStr, timezone }) => {
+ let f = formatStr;
+ if (date > MINIUES) {
+ f = 'm分s秒';
+ } else if (date === MINIUES) {
+ f = 'm分';
+ } else {
+ f = 's秒';
+ }
+ return formatDate(date, f, this.locale, timezone || '+0000');
+ },
+ };
+ dateFnsConfig: CountdownConfig = {
+ leftTime: 60 * 60 * 24 * 365 * (2050 - 1970),
+ format: 'yyyy-MM-dd E HH:mm:ss a',
+ formatDate: ({ date, formatStr }) => format(date, formatStr),
+ };
+ prettyConfig: CountdownConfig = {
+ leftTime: 60,
+ format: 'HH:mm:ss',
+ prettyText: text => {
+ return text
+ .split(':')
+ .map(v => `
${v}`)
+ .join('');
+ },
+ };
+
+ constructor(@Inject(LOCALE_ID) private locale: string) {}
- stopConfig: any = { stopTime: new Date().getTime() + 1000 * 30 };
resetStop() {
this.stopConfig = { stopTime: new Date().getTime() + 1000 * 30 };
}
- onEvent(value: any) {
- console.log('event', value);
- }
-
- @ViewChild('countdown') counter: CountdownComponent;
resetTimer() {
this.counter.restart();
}
+
+ handleEvent(e: CountdownEvent) {
+ console.log(e);
+ }
+
+ handleEvent2(e: CountdownEvent) {
+ this.notify = e.action.toUpperCase();
+ if (e.action === 'notify') {
+ this.notify += ` - ${e.left} ms`;
+ }
+ console.log(e);
+ }
}
diff --git a/src/app/components/layout.component.ts b/src/app/components/layout.component.ts
index 5d9e149..9cfd1f2 100644
--- a/src/app/components/layout.component.ts
+++ b/src/app/components/layout.component.ts
@@ -3,29 +3,34 @@ import { Component } from '@angular/core';
selector: 'demo-layout',
template: `
Simple, easy and performance countdown for angular
- `,
+ `,
})
export class LayoutComponent {}
diff --git a/src/app/components/nothing.component.html b/src/app/components/nothing.component.html
index b4bc41d..cab1630 100644
--- a/src/app/components/nothing.component.html
+++ b/src/app/components/nothing.component.html
@@ -1,2 +1,4 @@
-
本页由于无任何组件使用到Countdown,因此,Timer将会自动停止运行。
-
确认这一点,可以在Chrome-Profiles中观察到。
+
+ Since there are no any countdown component on this page, Timer will automatically stop running.
+
+
Confirm this and you can observe it in Chrome-Profiles.
diff --git a/src/app/components/tpl.component.html b/src/app/components/tpl.component.html
deleted file mode 100644
index bcf342a..0000000
--- a/src/app/components/tpl.component.html
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/app/components/tpl.component.scss b/src/app/components/tpl.component.scss
deleted file mode 100644
index e2718ba..0000000
--- a/src/app/components/tpl.component.scss
+++ /dev/null
@@ -1,3 +0,0 @@
-img {
- max-width: 100%;
-}
diff --git a/src/app/components/tpl.component.ts b/src/app/components/tpl.component.ts
deleted file mode 100644
index 6150474..0000000
--- a/src/app/components/tpl.component.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-import { Component, ViewEncapsulation } from '@angular/core';
-
-@Component({
- selector: 'demo-tpl',
- templateUrl: './tpl.component.html',
- styleUrls: ['./tpl.component.scss'],
- encapsulation: ViewEncapsulation.None,
-})
-export class TplComponent {}
diff --git a/src/app/tpl/flip/flip.component.html b/src/app/tpl/flip/flip.component.html
deleted file mode 100644
index 6ba09ad..0000000
--- a/src/app/tpl/flip/flip.component.html
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
code
diff --git a/src/app/tpl/flip/flip.component.scss b/src/app/tpl/flip/flip.component.scss
deleted file mode 100644
index c067ead..0000000
--- a/src/app/tpl/flip/flip.component.scss
+++ /dev/null
@@ -1,90 +0,0 @@
-.flip-cd {
- .time {
- border-radius: 5px;
- box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.5);
- display: inline-block;
- text-align: center;
- position: relative;
- height: 95px;
- width: 65px;
- perspective: 479px;
- backface-visibility: hidden;
- transform: translateZ(0);
- transform: translate3d(0, 0, 0);
- }
- .count {
- background: #202020;
- color: #f8f8f8;
- display: block;
- font-family: 'Oswald', sans-serif;
- font-size: 3.3em;
- line-height: 1.8em;
- overflow: hidden;
- position: absolute;
- text-align: center;
- text-shadow: 0 0 10px rgba(0, 0, 0, 0.8);
- top: 0;
- width: 100%;
- transform: translateZ(0);
- transform-style: flat;
- &.top {
- border-top: 1px solid rgba(255, 255, 255, 0.2);
- border-bottom: 1px solid rgba(255, 255, 255, 0.1);
- border-radius: 5px 5px 0 0;
- height: 50%;
- transform-origin: 50% 100%;
- }
- &.bottom {
- background-image: linear-gradient(rgba(255, 255, 255, 0.1), transparent);
- border-top: 1px solid #000;
- border-bottom: 1px solid #000;
- border-radius: 0 0 5px 5px;
- line-height: 0;
- height: 50%;
- top: 50%;
- transform-origin: 50% 0;
- }
- &.curr {
- &.top {
- transform: rotateX(0deg);
- z-index: 3;
- }
- }
- &.next {
- &.bottom {
- transform: rotateX(90deg);
- z-index: 2;
- }
- }
- }
- .label {
- font-size: normal;
- margin-top: 5px;
- display: block;
- position: absolute;
- top: 95px;
- width: 100%;
- }
- .hand {
- display: block;
- height: 100%;
- width: 100%;
- margin: 0 !important;
- }
- .flip {
- .count {
- &.curr {
- &.top {
- transition: all 250ms ease-in-out;
- transform: rotateX(-90deg);
- }
- }
- &.next {
- &.bottom {
- transition: all 250ms ease-in-out 250ms;
- transform: rotateX(0deg);
- }
- }
- }
- }
-}
diff --git a/src/app/tpl/flip/flip.component.ts b/src/app/tpl/flip/flip.component.ts
deleted file mode 100644
index 2f59a8b..0000000
--- a/src/app/tpl/flip/flip.component.ts
+++ /dev/null
@@ -1,38 +0,0 @@
-import { Component, ViewEncapsulation } from '@angular/core';
-import { Config } from 'ngx-countdown';
-
-@Component({
- selector: 'demo-tpl-flip',
- templateUrl: './flip.component.html',
- styleUrls: ['./flip.component.scss'],
- encapsulation: ViewEncapsulation.None,
-})
-export class TplFlipComponent {
- config: Config = {
- leftTime: 60 * 60 * 24 * 7,
- repaint: function() {
- // 这里不可以使用箭头函数,因为对于箭头函数this是强制性的,为了让重绘有更大的权限,必须是function
- const me: any = this;
- let content: string;
-
- me.hands.forEach((hand: any) => {
- if (hand.lastValue !== hand.value) {
- content = '';
- const cur = me.toDigitals(hand.value + 1, hand.bits).join(''),
- next = me.toDigitals(hand.value, hand.bits).join('');
-
- hand.node.innerHTML = `
-
${cur}
-
${next}
-
${next}
-
${cur}
- `;
- hand.node.parentElement.className = 'time';
- setTimeout(() => {
- hand.node.parentElement.className = 'time flip';
- });
- }
- });
- },
- };
-}
diff --git a/src/index.html b/src/index.html
index 210edc3..5a12dc6 100644
--- a/src/index.html
+++ b/src/index.html
@@ -1,24 +1,21 @@
-
+
+
+
+
ngx-countdown | Simple, easy and performance countdown for angular
+
+
+
+
+
+
-
-
-
ngx-countdown | Simple, easy and performance countdown for angular
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
diff --git a/src/polyfills.ts b/src/polyfills.ts
index 20d4075..2f258e5 100644
--- a/src/polyfills.ts
+++ b/src/polyfills.ts
@@ -11,66 +11,52 @@
* automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
* Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
*
- * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html
+ * Learn more in https://angular.io/guide/browser-support
*/
/***************************************************************************************************
* BROWSER POLYFILLS
*/
-/** IE9, IE10 and IE11 requires all of the following polyfills. **/
-// import 'core-js/es6/symbol';
-// import 'core-js/es6/object';
-// import 'core-js/es6/function';
-// import 'core-js/es6/parse-int';
-// import 'core-js/es6/parse-float';
-// import 'core-js/es6/number';
-// import 'core-js/es6/math';
-// import 'core-js/es6/string';
-// import 'core-js/es6/date';
-// import 'core-js/es6/array';
-// import 'core-js/es6/regexp';
-// import 'core-js/es6/map';
-// import 'core-js/es6/weak-map';
-// import 'core-js/es6/set';
-
/** IE10 and IE11 requires the following for NgClass support on SVG elements */
// import 'classlist.js'; // Run `npm install --save classlist.js`.
-/** IE10 and IE11 requires the following for the Reflect API. */
-// import 'core-js/es6/reflect';
-
-
-/** Evergreen browsers require these. **/
-// Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove.
-import 'core-js/es7/reflect';
-
-
/**
- * Required to support Web Animations `@angular/platform-browser/animations`.
- * Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation
- **/
+ * Web Animations `@angular/platform-browser/animations`
+ * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
+ * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
+ */
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.
-
+/**
+ * By default, zone.js will patch all possible macroTask and DomEvents
+ * user can disable parts of macroTask/DomEvents patch by setting following flags
+ * because those flags need to be set before `zone.js` being loaded, and webpack
+ * will put import in the top of bundle, so user need to create a separate file
+ * in this directory (for example: zone-flags.ts), and put the following flags
+ * into that file, and then add the following code before importing zone.js.
+ * import './zone-flags.ts';
+ *
+ * The flags allowed in zone-flags.ts are listed here.
+ *
+ * The following flags will work for all browsers.
+ *
+ * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
+ * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
+ * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
+ *
+ * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
+ * with the following flag, it will bypass `zone.js` patch for IE/Edge
+ *
+ * (window as any).__Zone_enable_cross_context_check = true;
+ *
+ */
/***************************************************************************************************
- * Zone JS is required by Angular itself.
+ * Zone JS is required by default for Angular itself.
*/
-import 'zone.js/dist/zone'; // Included with Angular CLI.
-
-
+import 'zone.js/dist/zone'; // Included with Angular CLI.
/***************************************************************************************************
* APPLICATION IMPORTS
*/
-
-/**
- * Date, currency, decimal and percent pipes.
- * Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10
- */
-// import 'intl'; // Run `npm install --save intl`.
-/**
- * Need to import at least one locale-data with intl.
- */
-// import 'intl/locale-data/jsonp/en';
diff --git a/src/tsconfig.json b/src/tsconfig.json
index b38e846..4f690e6 100644
--- a/src/tsconfig.json
+++ b/src/tsconfig.json
@@ -1,22 +1,17 @@
{
- "extends": "../tsconfig.json",
- "compilerOptions": {
- "sourceMap": false,
- "outDir": "../out-tsc/app",
- "baseUrl": "./",
- "module": "es2015",
- "types": [],
- "paths": {
- "ngx-countdown": [
- "../lib/index"
- ],
- "ngx-countdown/*": [
- "../lib/*"
- ]
- }
- },
- "exclude": [
- "test.ts",
- "**/*.spec.ts"
- ]
+ "extends": "../tsconfig.json",
+ "compilerOptions": {
+ "outDir": "./out-tsc/app",
+ "types": []
+ },
+ "files": [
+ "./main.ts",
+ "./polyfills.ts"
+ ],
+ "include": [
+ "**/*.ts"
+ ],
+ "exclude": [
+ "**/*.spec.ts"
+ ]
}
diff --git a/tsconfig.json b/tsconfig.json
index f9211db..7a7e941 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,19 +1,29 @@
{
"compileOnSave": false,
"compilerOptions": {
+ "baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
- "moduleResolution": "node",
- "emitDecoratorMetadata": true,
+ "downlevelIteration": true,
"experimentalDecorators": true,
- "target": "es5",
- "typeRoots": ["node_modules/@types"],
- "lib": ["es2017", "dom"],
- "baseUrl": "./",
+ "module": "esnext",
+ "moduleResolution": "node",
+ "importHelpers": true,
+ "target": "es2015",
+ "typeRoots": [
+ "node_modules/@types"
+ ],
+ "lib": [
+ "es2018",
+ "dom"
+ ],
"paths": {
- "ngx-countdown": ["./lib/src/countdown.module"],
- "ngx-countdown/*": ["./lib/*"]
+ "ngx-countdown": ["./lib/src/index"]
}
+ },
+ "angularCompilerOptions": {
+ "fullTemplateTypeCheck": true,
+ "strictInjectionParameters": true
}
}
diff --git a/tslint.json b/tslint.json
index 0255a3d..afb19dd 100644
--- a/tslint.json
+++ b/tslint.json
@@ -1,91 +1,105 @@
{
- "rulesDirectory": ["node_modules/codelyzer"],
+ "extends": [
+ "tslint:latest",
+ "tslint-config-prettier"
+ ],
+ "rulesDirectory": [
+ "codelyzer"
+ ],
"rules": {
- "callable-types": true,
- "class-name": true,
- "comment-format": [true, "check-space"],
- "curly": false,
- "eofline": true,
- "forin": true,
- "import-blacklist": [true],
- "import-spacing": true,
- "indent": [true, "spaces"],
- "interface-over-type-literal": true,
- "label-position": true,
- "max-line-length": [false, 140],
- "member-access": false,
- "member-ordering": [false],
- "no-arg": true,
- "no-bitwise": true,
- "no-console": [true, "debug", "info", "time", "timeEnd", "trace"],
- "no-construct": true,
- "no-debugger": true,
- "no-duplicate-variable": true,
- "no-empty": false,
- "no-empty-interface": true,
- "no-eval": true,
- "no-inferrable-types": [true, "ignore-params"],
- "no-shadowed-variable": true,
- "no-string-literal": false,
- "no-string-throw": true,
- "no-switch-case-fall-through": true,
- "no-trailing-whitespace": true,
- "no-unused-expression": true,
- "no-use-before-declare": true,
- "no-var-keyword": true,
- "object-literal-sort-keys": false,
- "one-line": [
+ // Angular parts
+ "array-type": false,
+ "arrow-parens": false,
+ "deprecation": {
+ "severity": "warn"
+ },
+ "component-class-suffix": [true, "Component", "Widget"],
+ "contextual-lifecycle": true,
+ "directive-class-suffix": true,
+ "directive-selector": [
false,
- "check-open-brace",
- "check-catch",
- "check-else",
- "check-whitespace"
+ "attribute",
+ "app",
+ "camelCase"
],
- "prefer-const": true,
- "quotemark": [true, "single"],
- "radix": true,
- "semicolon": [true, "always"],
- "triple-equals": [true, "allow-null-check"],
- "typedef-whitespace": [
+ "component-selector": [
+ false,
+ "element",
+ "app",
+ "kebab-case"
+ ],
+ "import-blacklist": [
+ true,
+ "rxjs/Rx"
+ ],
+ "interface-name": [true, "never-prefix"],
+ "max-classes-per-file": false,
+ "max-line-length": [
+ false,
+ 140
+ ],
+ "member-access": false,
+ "member-ordering": [
true,
{
- "call-signature": "nospace",
- "index-signature": "nospace",
- "parameter": "nospace",
- "property-declaration": "nospace",
- "variable-declaration": "nospace"
+ "order": [
+ "static-field",
+ "instance-field",
+ "static-method",
+ "instance-method"
+ ]
}
],
- "typeof-compare": true,
- "unified-signatures": true,
- "variable-name": false,
- "whitespace": [
+ "no-consecutive-blank-lines": false,
+ "no-console": [
true,
- "check-branch",
- "check-decl",
- "check-operator",
- "check-separator",
- "check-type"
+ "debug",
+ "info",
+ "time",
+ "timeEnd",
+ "trace"
+ ],
+ "no-empty": false,
+ "no-inferrable-types": [
+ false,
+ "ignore-params"
+ ],
+ "no-non-null-assertion": false,
+ "no-redundant-jsdoc": true,
+ "no-switch-case-fall-through": true,
+ "no-use-before-declare": false,
+ "no-var-requires": false,
+ "object-literal-key-quotes": [
+ false,
+ "as-needed"
],
-
- "directive-selector": [false, "attribute", "app", "camelCase"],
- "component-selector": [false, "element", "app", "kebab-case"],
- "use-input-property-decorator": true,
- "use-output-property-decorator": true,
- "use-host-property-decorator": false,
- "no-input-rename": true,
- "no-output-rename": true,
- "use-life-cycle-interface": true,
+ "object-literal-sort-keys": false,
+ "ordered-imports": false,
+ "quotemark": [
+ false,
+ "single"
+ ],
+ "trailing-comma": false,
+ "no-conflicting-lifecycle": true,
+ "no-host-metadata-property": false,
+ "no-input-rename": false,
+ "no-inputs-metadata-property": true,
+ "no-output-native": false,
+ "no-output-on-prefix": true,
+ "no-output-rename": false,
+ "no-outputs-metadata-property": true,
+ "template-banana-in-box": true,
+ "template-no-negated-async": true,
+ "use-lifecycle-interface": true,
"use-pipe-transform-interface": true,
- "component-class-suffix": true,
- "directive-class-suffix": true,
- "no-access-missing-member": true,
- "templates-use-public": true,
- "invoke-injectable": true
- },
- "linterOptions": {
- "exclude": [
- "lib/**/*.spec.ts"
- ]
+ // Custom parts
+ "curly": false,
+ "variable-name": false,
+ "no-submodule-imports": false,
+ "no-implicit-dependencies": false,
+ "no-object-literal-type-assertion": false,
+ "no-bitwise": false,
+ "no-this-assignment": false,
+ "prefer-conditional-expression": false
}
}