@oscarpalmer/timer 0.15.0 → 0.16.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/dist/timer.cjs +6 -27
- package/dist/timer.iife.js +1 -1
- package/dist/timer.js +6 -29
- package/package.json +1 -1
- package/src/index.d.ts +6 -6
- package/src/index.js +12 -20
package/dist/timer.cjs
CHANGED
|
@@ -2,7 +2,6 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
5
|
var __export = (target, all) => {
|
|
7
6
|
for (var name in all)
|
|
8
7
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -16,10 +15,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
15
|
return to;
|
|
17
16
|
};
|
|
18
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var __publicField = (obj, key, value) => {
|
|
20
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
21
|
-
return value;
|
|
22
|
-
};
|
|
23
18
|
|
|
24
19
|
// src/index.js
|
|
25
20
|
var src_exports = {};
|
|
@@ -68,6 +63,12 @@ function run(timed) {
|
|
|
68
63
|
timed.state.frame = request(step);
|
|
69
64
|
}
|
|
70
65
|
var Timed = class {
|
|
66
|
+
get active() {
|
|
67
|
+
return this.state.active;
|
|
68
|
+
}
|
|
69
|
+
get finished() {
|
|
70
|
+
return !this.active && this.state.finished;
|
|
71
|
+
}
|
|
71
72
|
/**
|
|
72
73
|
* @param {RepeatedCallback} callback
|
|
73
74
|
* @param {number} time
|
|
@@ -75,21 +76,6 @@ var Timed = class {
|
|
|
75
76
|
* @param {AfterCallback|undefined} afterCallback
|
|
76
77
|
*/
|
|
77
78
|
constructor(callback, time, count, afterCallback) {
|
|
78
|
-
/**
|
|
79
|
-
* @readonly
|
|
80
|
-
* @type {{after: AfterCallback | undefined; default: RepeatedCallback}}
|
|
81
|
-
*/
|
|
82
|
-
__publicField(this, "callbacks");
|
|
83
|
-
/**
|
|
84
|
-
* @readonly
|
|
85
|
-
* @type {{count: number; time: number}}
|
|
86
|
-
*/
|
|
87
|
-
__publicField(this, "configuration");
|
|
88
|
-
/**
|
|
89
|
-
* @readonly
|
|
90
|
-
* @type {{active: boolean; finished: boolean; frame?: DOMHighResTimeStamp}}
|
|
91
|
-
*/
|
|
92
|
-
__publicField(this, "state");
|
|
93
79
|
const isRepeated = this instanceof Repeated;
|
|
94
80
|
const type = isRepeated ? "repeated" : "waited";
|
|
95
81
|
if (typeof callback !== "function") {
|
|
@@ -121,13 +107,6 @@ var Timed = class {
|
|
|
121
107
|
frame: null
|
|
122
108
|
};
|
|
123
109
|
}
|
|
124
|
-
/** */
|
|
125
|
-
get active() {
|
|
126
|
-
return this.state.active;
|
|
127
|
-
}
|
|
128
|
-
get finished() {
|
|
129
|
-
return !this.active && this.state.finished;
|
|
130
|
-
}
|
|
131
110
|
restart() {
|
|
132
111
|
this.stop();
|
|
133
112
|
run(this);
|
package/dist/timer.iife.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var Timer=(()=>{var
|
|
1
|
+
var Timer=(()=>{var c=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var g=(t,e)=>{for(var s in e)c(t,s,{get:e[s],enumerable:!0})},y=(t,e,s,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of w(e))!b.call(t,i)&&i!==s&&c(t,i,{get:()=>e[i],enumerable:!(n=v(e,i))||n.enumerable});return t};var x=t=>y(c({},"__esModule",{value:!0}),t);var E={};g(E,{Repeated:()=>r,Waited:()=>f,repeat:()=>T,wait:()=>A});var h=Math.round(16.666666666666668),l=globalThis.requestAnimationFrame??function(t){return setTimeout?.(()=>{t(Date.now())},h)};function p(t){t.state.active=!0,t.state.finished=!1;let e=t instanceof r,s=0,n;function i(a){if(!t.state.active)return;n??(n=a);let o=a-n,d=o-h,m=o+h;if(d<t.configuration.time&&t.configuration.time<m)if(t.state.active&&t.callbacks.default(e?s:void 0),s+=1,e&&s<t.configuration.count)n=void 0;else{t.state.finished=!0,t.stop();return}t.state.frame=l(i)}t.state.frame=l(i)}var u=class{get active(){return this.state.active}get finished(){return!this.active&&this.state.finished}constructor(e,s,n,i){let a=this instanceof r,o=a?"repeated":"waited";if(typeof e!="function")throw new TypeError(`A ${o} timer must have a callback function`);if(typeof s!="number"||s<0)throw new TypeError(`A ${o} timer must have a non-negative number as its time`);if(a&&(typeof n!="number"||n<2))throw new TypeError("A repeated timer must have a number above 1 as its repeat count");if(a&&i!==void 0&&typeof i!="function")throw new TypeError("A repeated timer's after-callback must be a function");this.configuration={count:n,time:s},this.callbacks={after:i,default:e},this.state={active:!1,finished:!1,frame:null}}restart(){return this.stop(),p(this),this}start(){return this.state.active||p(this),this}stop(){return this.state.active=!1,this.state.frame===void 0?this:((globalThis.cancelAnimationFrame??clearTimeout)?.(this.state.frame),this.callbacks.after?.(this.finished),this.state.frame=void 0,this)}},r=class extends u{},f=class extends u{constructor(e,s){super(e,s,1,null)}};function T(t,e,s,n){return new r(t,e,s,n).start()}function A(t,e){return new f(t,e).start()}return x(E);})();
|
package/dist/timer.js
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) => {
|
|
4
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
-
return value;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
1
|
// src/index.js
|
|
9
2
|
var milliseconds = Math.round(1e3 / 60);
|
|
10
3
|
var request = globalThis.requestAnimationFrame ?? function(callback) {
|
|
@@ -44,6 +37,12 @@ function run(timed) {
|
|
|
44
37
|
timed.state.frame = request(step);
|
|
45
38
|
}
|
|
46
39
|
var Timed = class {
|
|
40
|
+
get active() {
|
|
41
|
+
return this.state.active;
|
|
42
|
+
}
|
|
43
|
+
get finished() {
|
|
44
|
+
return !this.active && this.state.finished;
|
|
45
|
+
}
|
|
47
46
|
/**
|
|
48
47
|
* @param {RepeatedCallback} callback
|
|
49
48
|
* @param {number} time
|
|
@@ -51,21 +50,6 @@ var Timed = class {
|
|
|
51
50
|
* @param {AfterCallback|undefined} afterCallback
|
|
52
51
|
*/
|
|
53
52
|
constructor(callback, time, count, afterCallback) {
|
|
54
|
-
/**
|
|
55
|
-
* @readonly
|
|
56
|
-
* @type {{after: AfterCallback | undefined; default: RepeatedCallback}}
|
|
57
|
-
*/
|
|
58
|
-
__publicField(this, "callbacks");
|
|
59
|
-
/**
|
|
60
|
-
* @readonly
|
|
61
|
-
* @type {{count: number; time: number}}
|
|
62
|
-
*/
|
|
63
|
-
__publicField(this, "configuration");
|
|
64
|
-
/**
|
|
65
|
-
* @readonly
|
|
66
|
-
* @type {{active: boolean; finished: boolean; frame?: DOMHighResTimeStamp}}
|
|
67
|
-
*/
|
|
68
|
-
__publicField(this, "state");
|
|
69
53
|
const isRepeated = this instanceof Repeated;
|
|
70
54
|
const type = isRepeated ? "repeated" : "waited";
|
|
71
55
|
if (typeof callback !== "function") {
|
|
@@ -97,13 +81,6 @@ var Timed = class {
|
|
|
97
81
|
frame: null
|
|
98
82
|
};
|
|
99
83
|
}
|
|
100
|
-
/** */
|
|
101
|
-
get active() {
|
|
102
|
-
return this.state.active;
|
|
103
|
-
}
|
|
104
|
-
get finished() {
|
|
105
|
-
return !this.active && this.state.finished;
|
|
106
|
-
}
|
|
107
84
|
restart() {
|
|
108
85
|
this.stop();
|
|
109
86
|
run(this);
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -9,21 +9,21 @@ export type AfterCallback = (finished: boolean) => void;
|
|
|
9
9
|
export type RepeatedCallback = (index: number) => void;
|
|
10
10
|
declare class Timed {
|
|
11
11
|
constructor(callback: RepeatedCallback, time: number, count: number, afterCallback: AfterCallback | undefined);
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
default: RepeatedCallback;
|
|
15
|
-
};
|
|
12
|
+
get active(): boolean;
|
|
13
|
+
get finished(): boolean;
|
|
16
14
|
readonly configuration: {
|
|
17
15
|
count: number;
|
|
18
16
|
time: number;
|
|
19
17
|
};
|
|
18
|
+
readonly callbacks: {
|
|
19
|
+
after: AfterCallback | undefined;
|
|
20
|
+
default: RepeatedCallback;
|
|
21
|
+
};
|
|
20
22
|
readonly state: {
|
|
21
23
|
active: boolean;
|
|
22
24
|
finished: boolean;
|
|
23
25
|
frame?: DOMHighResTimeStamp;
|
|
24
26
|
};
|
|
25
|
-
get active(): boolean;
|
|
26
|
-
get finished(): boolean;
|
|
27
27
|
restart(): Timed;
|
|
28
28
|
start(): Timed;
|
|
29
29
|
stop(): Timed;
|
package/src/index.js
CHANGED
|
@@ -72,26 +72,6 @@ function run(timed) {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
class Timed {
|
|
75
|
-
/**
|
|
76
|
-
* @readonly
|
|
77
|
-
* @type {{after: AfterCallback | undefined; default: RepeatedCallback}}
|
|
78
|
-
*/
|
|
79
|
-
callbacks;
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* @readonly
|
|
83
|
-
* @type {{count: number; time: number}}
|
|
84
|
-
*/
|
|
85
|
-
configuration;
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* @readonly
|
|
89
|
-
* @type {{active: boolean; finished: boolean; frame?: DOMHighResTimeStamp}}
|
|
90
|
-
*/
|
|
91
|
-
state;
|
|
92
|
-
|
|
93
|
-
/** */
|
|
94
|
-
|
|
95
75
|
get active() {
|
|
96
76
|
return this.state.active;
|
|
97
77
|
}
|
|
@@ -137,13 +117,25 @@ class Timed {
|
|
|
137
117
|
);
|
|
138
118
|
}
|
|
139
119
|
|
|
120
|
+
/**
|
|
121
|
+
* @readonly
|
|
122
|
+
* @type {{count: number; time: number}}
|
|
123
|
+
*/
|
|
140
124
|
this.configuration = {count, time};
|
|
141
125
|
|
|
126
|
+
/**
|
|
127
|
+
* @readonly
|
|
128
|
+
* @type {{after: AfterCallback | undefined; default: RepeatedCallback}}
|
|
129
|
+
*/
|
|
142
130
|
this.callbacks = {
|
|
143
131
|
after: afterCallback,
|
|
144
132
|
default: callback,
|
|
145
133
|
};
|
|
146
134
|
|
|
135
|
+
/**
|
|
136
|
+
* @readonly
|
|
137
|
+
* @type {{active: boolean; finished: boolean; frame?: DOMHighResTimeStamp}}
|
|
138
|
+
*/
|
|
147
139
|
this.state = {
|
|
148
140
|
active: false,
|
|
149
141
|
finished: false,
|