@kizmann/pico-js 2.0.8 → 2.0.10
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/pico-js.browser.js +1 -1
- package/dist/pico-js.browser.js.map +1 -1
- package/dist/pico-js.esm.js +1 -1
- package/dist/pico-js.esm.js.map +1 -1
- package/package.json +4 -6
- package/src/dom/{DomAttribute.js → DomAttribute.ts} +40 -63
- package/src/dom/{DomBuilder.js → DomBuilder.ts} +27 -44
- package/src/dom/{DomEvent.js → DomEvent.ts} +74 -78
- package/src/dom/{DomFinder.js → DomFinder.ts} +89 -129
- package/src/dom/DomForm.ts +38 -0
- package/src/dom/{DomGlobal.js → DomGlobal.ts} +34 -51
- package/src/dom/{DomInview.js → DomInview.ts} +37 -57
- package/src/dom/DomMeta.ts +48 -0
- package/src/dom/DomObserver.ts +17 -0
- package/src/dom/{DomPopover.js → DomPopover.ts} +20 -39
- package/src/dom/{DomRectangle.js → DomRectangle.ts} +67 -88
- package/src/format/{FormatFile.js → FormatFile.ts} +12 -23
- package/src/format/{FormatOption.js → FormatOption.ts} +15 -24
- package/src/format/{FormatParam.js → FormatParam.ts} +14 -25
- package/src/format/{FormatParser.js → FormatParser.ts} +29 -39
- package/src/format/{FormatUrl.js → FormatUrl.ts} +9 -21
- package/src/index.browser.ts +32 -0
- package/src/index.esm.ts +64 -0
- package/src/now/{NowDefault.js → NowDefault.ts} +86 -121
- package/src/now/{NowFormat.js → NowFormat.ts} +23 -28
- package/src/now/{NowGrid.js → NowGrid.ts} +41 -58
- package/src/now/{NowHuman.js → NowHuman.ts} +18 -27
- package/src/now/{NowMatch.js → NowMatch.ts} +22 -28
- package/src/now/{NowRange.js → NowRange.ts} +13 -22
- package/src/now/{NowWalker.js → NowWalker.ts} +65 -71
- package/src/tool/{scope.js → scope.ts} +41 -11
- package/src/utils/{Array.js → Array.ts} +146 -160
- package/src/utils/{Cookie.js → Cookie.ts} +15 -12
- package/src/utils/{Data.js → Data.ts} +17 -17
- package/src/utils/Dom.ts +204 -0
- package/src/utils/Format.ts +48 -0
- package/src/utils/{Hash.js → Hash.ts} +20 -20
- package/src/utils/{Locale.js → Locale.ts} +22 -22
- package/src/utils/{Mixed.js → Mixed.ts} +70 -58
- package/src/utils/{Now.js → Now.ts} +68 -69
- package/src/utils/{Number.js → Number.ts} +34 -36
- package/src/utils/{Object.js → Object.ts} +68 -122
- package/src/utils/{Route.js → Route.ts} +11 -9
- package/src/utils/{Runner.js → Runner.ts} +65 -47
- package/src/utils/{Signal.js → Signal.ts} +35 -22
- package/src/utils/{String.js → String.ts} +79 -69
- package/src/wip/{Element.js → Element.ts} +2 -2
- package/src/wip/{Map.js → Map.ts} +131 -101
- package/types/dom/DomAttribute.d.ts +16 -27
- package/types/dom/DomBuilder.d.ts +6 -9
- package/types/dom/DomEvent.d.ts +19 -25
- package/types/dom/DomFinder.d.ts +35 -58
- package/types/dom/DomForm.d.ts +7 -10
- package/types/dom/DomGlobal.d.ts +8 -15
- package/types/dom/DomInview.d.ts +9 -19
- package/types/dom/DomMeta.d.ts +9 -16
- package/types/dom/DomObserver.d.ts +4 -8
- package/types/dom/DomPopover.d.ts +8 -11
- package/types/dom/DomRectangle.d.ts +21 -40
- package/types/format/FormatFile.d.ts +5 -8
- package/types/format/FormatOption.d.ts +6 -8
- package/types/format/FormatParam.d.ts +6 -9
- package/types/format/FormatParser.d.ts +10 -18
- package/types/format/FormatUrl.d.ts +5 -8
- package/types/index.esm.d.ts +25 -37
- package/types/now/NowDefault.d.ts +30 -99
- package/types/now/NowFormat.d.ts +8 -21
- package/types/now/NowGrid.d.ts +24 -46
- package/types/now/NowHuman.d.ts +10 -11
- package/types/now/NowMatch.d.ts +6 -4
- package/types/now/NowRange.d.ts +5 -8
- package/types/now/NowWalker.d.ts +6 -4
- package/types/tool/scope.d.ts +11 -3
- package/types/utils/Array.d.ts +83 -104
- package/types/utils/Cookie.d.ts +11 -8
- package/types/utils/Data.d.ts +7 -7
- package/types/utils/Dom.d.ts +63 -96
- package/types/utils/Format.d.ts +15 -28
- package/types/utils/Hash.d.ts +21 -21
- package/types/utils/Locale.d.ts +10 -10
- package/types/utils/Mixed.d.ts +18 -32
- package/types/utils/Now.d.ts +51 -56
- package/types/utils/Number.d.ts +9 -20
- package/types/utils/Object.d.ts +21 -36
- package/types/utils/Route.d.ts +5 -2
- package/types/utils/Runner.d.ts +41 -24
- package/types/utils/Signal.d.ts +16 -16
- package/types/utils/String.d.ts +40 -76
- package/src/dom/DomForm.js +0 -59
- package/src/dom/DomMeta.js +0 -68
- package/src/dom/DomObserver.js +0 -38
- package/src/index.browser.js +0 -36
- package/src/index.esm.js +0 -80
- package/src/utils/Dom.js +0 -214
- package/src/utils/Format.js +0 -62
- package/types/wip/Element.d.ts +0 -119
- package/types/wip/Map.d.ts +0 -254
|
@@ -1,14 +1,32 @@
|
|
|
1
|
-
import { Arr, Mix, Obj } from "../index.esm.
|
|
1
|
+
import { Arr, Mix, Obj } from "../index.esm.ts";
|
|
2
2
|
|
|
3
3
|
export class PicoRunner
|
|
4
4
|
{
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* @type {any}
|
|
7
|
+
*/
|
|
8
|
+
static $idler : any = null;
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
/**
|
|
11
|
+
* @type {number}
|
|
12
|
+
*/
|
|
13
|
+
static $timer : number = 0;
|
|
8
14
|
|
|
9
|
-
|
|
15
|
+
/**
|
|
16
|
+
* @type {any[]}
|
|
17
|
+
*/
|
|
18
|
+
static $buffer : any[] = [];
|
|
10
19
|
|
|
11
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Run interval and return clear function
|
|
22
|
+
*
|
|
23
|
+
* @example Run.interval(cb, 100)
|
|
24
|
+
*
|
|
25
|
+
* @param {Function} fn Callback function
|
|
26
|
+
* @param {number} [intval] Callback interval
|
|
27
|
+
* @returns {Function} Noop clear function
|
|
28
|
+
*/
|
|
29
|
+
static interval(fn : Function, intval : number = 0) : Function
|
|
12
30
|
{
|
|
13
31
|
const idle = setInterval(() => {
|
|
14
32
|
fn();
|
|
@@ -23,12 +41,12 @@ export class PicoRunner
|
|
|
23
41
|
* @example Run.clear(timer)
|
|
24
42
|
*
|
|
25
43
|
* @param {any} timer Timer ID, array of IDs, or function
|
|
26
|
-
* @returns {
|
|
44
|
+
* @returns {PicoRunner} Static class
|
|
27
45
|
*/
|
|
28
|
-
static clear(timer)
|
|
46
|
+
static clear(timer : any) : PicoRunner
|
|
29
47
|
{
|
|
30
48
|
if ( Mix.isArr(timer) ) {
|
|
31
|
-
return Arr.each(timer, (t) => this.clear(t), this);
|
|
49
|
+
return Arr.each(timer, (t : any) => this.clear(t), this);
|
|
32
50
|
}
|
|
33
51
|
|
|
34
52
|
if ( Mix.isFunc(timer) ) {
|
|
@@ -44,10 +62,10 @@ export class PicoRunner
|
|
|
44
62
|
/**
|
|
45
63
|
* Request idle callback with fallback
|
|
46
64
|
*
|
|
47
|
-
* @param {
|
|
48
|
-
* @returns {
|
|
65
|
+
* @param {Function} cb Callback function
|
|
66
|
+
* @returns {PicoRunner} Static class
|
|
49
67
|
*/
|
|
50
|
-
static tryin(cb)
|
|
68
|
+
static tryin(cb : Function) : PicoRunner
|
|
51
69
|
{
|
|
52
70
|
try {
|
|
53
71
|
cb();
|
|
@@ -66,11 +84,11 @@ export class PicoRunner
|
|
|
66
84
|
* @param {function} fn Condition function
|
|
67
85
|
* @param {number} [intval] Interval ms
|
|
68
86
|
* @param {number} [limit] Max iterations
|
|
69
|
-
* @returns {
|
|
87
|
+
* @returns {Function} Clear function
|
|
70
88
|
*/
|
|
71
|
-
static wait(fn, intval = 0, limit = 500)
|
|
89
|
+
static wait(fn : Function, intval : number = 0, limit : number = 500) : Function
|
|
72
90
|
{
|
|
73
|
-
let idler, timer;
|
|
91
|
+
let idler : any, timer : any;
|
|
74
92
|
|
|
75
93
|
timer = setTimeout(() => {
|
|
76
94
|
this.clear([idler, timer]);
|
|
@@ -88,11 +106,10 @@ export class PicoRunner
|
|
|
88
106
|
*
|
|
89
107
|
* @example Run.frame(cb)
|
|
90
108
|
*
|
|
91
|
-
* @param {
|
|
92
|
-
* @
|
|
93
|
-
* @returns {function} Noop clear function
|
|
109
|
+
* @param {Function} fn Callback function
|
|
110
|
+
* @returns {Function} Noop clear function
|
|
94
111
|
*/
|
|
95
|
-
static frame(fn
|
|
112
|
+
static frame(fn : Function) : Function
|
|
96
113
|
{
|
|
97
114
|
const frame = requestAnimationFrame(() => {
|
|
98
115
|
fn();
|
|
@@ -106,10 +123,10 @@ export class PicoRunner
|
|
|
106
123
|
*
|
|
107
124
|
* @example Run.async(cb)
|
|
108
125
|
*
|
|
109
|
-
* @param {
|
|
110
|
-
* @returns {
|
|
126
|
+
* @param {Function} fn Callback function
|
|
127
|
+
* @returns {Function} Noop clear function
|
|
111
128
|
*/
|
|
112
|
-
static async(fn)
|
|
129
|
+
static async(fn : Function) : Function
|
|
113
130
|
{
|
|
114
131
|
const idle = setTimeout(() => {
|
|
115
132
|
fn()
|
|
@@ -123,11 +140,11 @@ export class PicoRunner
|
|
|
123
140
|
*
|
|
124
141
|
* @example Run.delay(cb, 100)
|
|
125
142
|
*
|
|
126
|
-
* @param {
|
|
143
|
+
* @param {Function} fn Callback function
|
|
127
144
|
* @param {number} [delay] Delay ms
|
|
128
|
-
* @returns {
|
|
145
|
+
* @returns {Function} Clear function
|
|
129
146
|
*/
|
|
130
|
-
static delay(fn, delay = 0)
|
|
147
|
+
static delay(fn : Function, delay : number = 0) : Function
|
|
131
148
|
{
|
|
132
149
|
let idler = setTimeout(() => {
|
|
133
150
|
fn();
|
|
@@ -141,22 +158,22 @@ export class PicoRunner
|
|
|
141
158
|
*
|
|
142
159
|
* @example const fn = Run.debounce(cb, 100)
|
|
143
160
|
*
|
|
144
|
-
* @param {
|
|
161
|
+
* @param {Function} cb Callback to run
|
|
145
162
|
* @param {number} [timeout] Wait ms
|
|
146
|
-
* @returns {
|
|
163
|
+
* @returns {Function} Debounced fn
|
|
147
164
|
*/
|
|
148
|
-
static debounce(cb, timeout = 100)
|
|
165
|
+
static debounce(cb : Function, timeout : number = 100) : Function
|
|
149
166
|
{
|
|
150
167
|
let idler = null;
|
|
151
168
|
|
|
152
|
-
return (...args) => {
|
|
169
|
+
return (...args : any[]) => {
|
|
153
170
|
|
|
154
171
|
if ( idler ) {
|
|
155
172
|
clearTimeout(idler);
|
|
156
173
|
}
|
|
157
174
|
|
|
158
175
|
idler = setTimeout(() => {
|
|
159
|
-
this.frame(cb
|
|
176
|
+
this.frame(() => cb(...args));
|
|
160
177
|
}, timeout);
|
|
161
178
|
};
|
|
162
179
|
}
|
|
@@ -166,15 +183,15 @@ export class PicoRunner
|
|
|
166
183
|
*
|
|
167
184
|
* @example const fn = Run.throttle(cb, 100)
|
|
168
185
|
*
|
|
169
|
-
* @param {
|
|
186
|
+
* @param {Function} cb Callback to run
|
|
170
187
|
* @param {number} [timeout] Wait ms
|
|
171
|
-
* @returns {
|
|
188
|
+
* @returns {Function} Throttled fn
|
|
172
189
|
*/
|
|
173
|
-
static throttle(cb, timeout = 100)
|
|
190
|
+
static throttle(cb : Function, timeout : number = 100) : Function
|
|
174
191
|
{
|
|
175
|
-
let queued, idler = null;
|
|
192
|
+
let queued : any, idler : any = null;
|
|
176
193
|
|
|
177
|
-
return (...args) => {
|
|
194
|
+
return (...args : any[]) => {
|
|
178
195
|
|
|
179
196
|
if ( idler ) {
|
|
180
197
|
clearTimeout(idler);
|
|
@@ -188,7 +205,7 @@ export class PicoRunner
|
|
|
188
205
|
return;
|
|
189
206
|
}
|
|
190
207
|
|
|
191
|
-
(this.frame(cb
|
|
208
|
+
(this.frame(() => cb(...args)), queued = true);
|
|
192
209
|
};
|
|
193
210
|
}
|
|
194
211
|
|
|
@@ -197,16 +214,16 @@ export class PicoRunner
|
|
|
197
214
|
*
|
|
198
215
|
* @example const fn = Run.framerate(cb, 30)
|
|
199
216
|
*
|
|
200
|
-
* @param {
|
|
217
|
+
* @param {Function} cb Callback to run
|
|
201
218
|
* @param {number} [fps] Max frames per sec
|
|
202
219
|
* @param {boolean} [finish] Finish last frame
|
|
203
|
-
* @returns {
|
|
220
|
+
* @returns {Function} Rate-limited fn
|
|
204
221
|
*/
|
|
205
|
-
static framerate(cb, fps = 30, finish = true)
|
|
222
|
+
static framerate(cb : Function, fps : number = 30, finish : boolean = true) : Function
|
|
206
223
|
{
|
|
207
|
-
let timer, last = 0, hertz = 1000 / fps;
|
|
224
|
+
let timer : any, last = 0, hertz = 1000 / fps;
|
|
208
225
|
|
|
209
|
-
const fn = (...args) => {
|
|
226
|
+
const fn = (...args : any) => {
|
|
210
227
|
|
|
211
228
|
clearTimeout(timer);
|
|
212
229
|
|
|
@@ -225,12 +242,12 @@ export class PicoRunner
|
|
|
225
242
|
*
|
|
226
243
|
* @example el.onwheel = Run.framebuffer(cb,"wheel")
|
|
227
244
|
*
|
|
228
|
-
* @param {
|
|
245
|
+
* @param {Function} cb Callback to run
|
|
229
246
|
* @param {string} key Buffer key
|
|
230
247
|
* @param {number} [priority] Sort priority
|
|
231
|
-
* @returns {
|
|
248
|
+
* @returns {Function} Buffered handler
|
|
232
249
|
*/
|
|
233
|
-
static framebuffer(cb, key, priority = 1000)
|
|
250
|
+
static framebuffer(cb : Function, key : string, priority : number = 1000) : Function
|
|
234
251
|
{
|
|
235
252
|
const item = {
|
|
236
253
|
key, cb, priority, args: [], active: false
|
|
@@ -238,7 +255,7 @@ export class PicoRunner
|
|
|
238
255
|
|
|
239
256
|
Arr.add(this.$buffer, item);
|
|
240
257
|
|
|
241
|
-
return (e, ...args) => {
|
|
258
|
+
return (e : any, ...args : any) => {
|
|
242
259
|
|
|
243
260
|
if ( /^drag/.test(e.type) ) {
|
|
244
261
|
e.preventDefault();
|
|
@@ -259,7 +276,7 @@ export class PicoRunner
|
|
|
259
276
|
*
|
|
260
277
|
* @returns {void} No return value
|
|
261
278
|
*/
|
|
262
|
-
static runFramebuffer()
|
|
279
|
+
static runFramebuffer() : void
|
|
263
280
|
{
|
|
264
281
|
if ( this.$idler ) {
|
|
265
282
|
clearTimeout(this.$idler);
|
|
@@ -289,8 +306,9 @@ export class PicoRunner
|
|
|
289
306
|
|
|
290
307
|
buffer = Arr.sort(buffer, 'priority');
|
|
291
308
|
|
|
292
|
-
Arr.each(buffer.reverse(), (item) => {
|
|
293
|
-
item.cb(...item.args);
|
|
309
|
+
Arr.each(buffer.reverse(), (item : any) => {
|
|
310
|
+
item.cb(...item.args);
|
|
311
|
+
item.active = false;
|
|
294
312
|
});
|
|
295
313
|
}
|
|
296
314
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Str, Event, For, Mix, Arr } from "../index.esm.
|
|
1
|
+
import { Str, Event, For, Mix, Arr } from "../index.esm.ts";
|
|
2
2
|
|
|
3
3
|
export class PicoSignal
|
|
4
4
|
{
|
|
@@ -10,16 +10,21 @@ export class PicoSignal
|
|
|
10
10
|
* @example Event.bind("x", cb) // => Event
|
|
11
11
|
* @example Event.bind(["a","b"], cb) // => Event
|
|
12
12
|
*
|
|
13
|
-
* @param {
|
|
14
|
-
* @param {
|
|
13
|
+
* @param {string|string[]} event Event name(s)
|
|
14
|
+
* @param {Function} cb Event callback
|
|
15
15
|
* @param {any} [options] Listener options
|
|
16
16
|
* @param {boolean} [paused] Start paused
|
|
17
|
-
* @returns {
|
|
17
|
+
* @returns {PicoSignal} Event class
|
|
18
18
|
*/
|
|
19
|
-
static bind(event, cb, options = {}, paused = false)
|
|
19
|
+
static bind(event : string | string[], cb : Function, options : any = {}, paused : boolean = false) : PicoSignal
|
|
20
20
|
{
|
|
21
|
+
const args : any[] = [
|
|
22
|
+
cb, options, paused
|
|
23
|
+
];
|
|
24
|
+
|
|
21
25
|
if ( Mix.isArr(event) ) {
|
|
22
|
-
|
|
26
|
+
// @ts-ignore
|
|
27
|
+
return Arr.each(event, (e : any) => this.bind(e, ...args), this);
|
|
23
28
|
}
|
|
24
29
|
|
|
25
30
|
if ( Mix.isPrim(options) ) {
|
|
@@ -39,14 +44,18 @@ export class PicoSignal
|
|
|
39
44
|
* @example Event.unbind("x") // => Event
|
|
40
45
|
* @example Event.unbind(["a","b"]) // => Event
|
|
41
46
|
*
|
|
42
|
-
* @param {
|
|
47
|
+
* @param {string|string[]} event Event name(s)
|
|
43
48
|
* @param {any} [options] Listener options
|
|
44
|
-
* @returns {
|
|
49
|
+
* @returns {PicoSignal} Event class
|
|
45
50
|
*/
|
|
46
|
-
static unbind(event, options = {})
|
|
51
|
+
static unbind(event : string | string[], options : any = {}) : PicoSignal
|
|
47
52
|
{
|
|
53
|
+
const args : any[] = [
|
|
54
|
+
options,
|
|
55
|
+
];
|
|
56
|
+
|
|
48
57
|
if ( Mix.isArr(event) ) {
|
|
49
|
-
return Arr.each(event, (e) => this.unbind(e, ...
|
|
58
|
+
return Arr.each(event, (e : any) => this.unbind(e, ...args), this);
|
|
50
59
|
}
|
|
51
60
|
|
|
52
61
|
if ( Mix.isPrim(options) ) {
|
|
@@ -67,16 +76,16 @@ export class PicoSignal
|
|
|
67
76
|
*
|
|
68
77
|
* @param {string} event Event name
|
|
69
78
|
* @param {...any} args Event args
|
|
70
|
-
* @returns {
|
|
79
|
+
* @returns {PicoSignal} Event class
|
|
71
80
|
*/
|
|
72
|
-
static fire(event, ...args)
|
|
81
|
+
static fire(event : string, ...args : Parameters<any>) : PicoSignal
|
|
73
82
|
{
|
|
74
83
|
let events = this.$events.filter((item) => {
|
|
75
84
|
return item.event === event;
|
|
76
85
|
});
|
|
77
86
|
|
|
78
|
-
Arr.each(events, (e) => {
|
|
79
|
-
if ( !
|
|
87
|
+
Arr.each(events, (e : any) => {
|
|
88
|
+
if ( !e.paused ) {
|
|
80
89
|
e.cb.call({}, ...args);
|
|
81
90
|
}
|
|
82
91
|
});
|
|
@@ -89,14 +98,18 @@ export class PicoSignal
|
|
|
89
98
|
*
|
|
90
99
|
* @example Event.pause("x") // => Event
|
|
91
100
|
*
|
|
92
|
-
* @param {
|
|
101
|
+
* @param {string|string[]} event Event name(s)
|
|
93
102
|
* @param {any} [options] Listener options
|
|
94
|
-
* @returns {
|
|
103
|
+
* @returns {PicoSignal} Event class
|
|
95
104
|
*/
|
|
96
|
-
static pause(event, options = {})
|
|
105
|
+
static pause(event : string | string[], options : any = {}) : PicoSignal
|
|
97
106
|
{
|
|
107
|
+
const args : any[] = [
|
|
108
|
+
options,
|
|
109
|
+
];
|
|
110
|
+
|
|
98
111
|
if ( Mix.isArr(event) ) {
|
|
99
|
-
return Arr.each(event, (e) => this.pause(e, ...
|
|
112
|
+
return Arr.each(event, (e : any) => this.pause(e, ...args), this);
|
|
100
113
|
}
|
|
101
114
|
|
|
102
115
|
let value = Arr.find(this.$events, {
|
|
@@ -115,14 +128,14 @@ export class PicoSignal
|
|
|
115
128
|
*
|
|
116
129
|
* @example Event.unpause("x") // => Event
|
|
117
130
|
*
|
|
118
|
-
* @param {
|
|
131
|
+
* @param {string|string[]} event Event name(s)
|
|
119
132
|
* @param {any} [options] Listener options
|
|
120
|
-
* @returns {
|
|
133
|
+
* @returns {PicoSignal} Event class
|
|
121
134
|
*/
|
|
122
|
-
static unpause(event, options = {})
|
|
135
|
+
static unpause(event : string | string[], options : any = {}) : PicoSignal
|
|
123
136
|
{
|
|
124
137
|
if ( Mix.isArr(event) ) {
|
|
125
|
-
return Arr.each(event, (e) => this.pause(e, ...arguments), this);
|
|
138
|
+
return Arr.each(event, (e : any) => this.pause(e, ...arguments), this);
|
|
126
139
|
}
|
|
127
140
|
|
|
128
141
|
let value = Arr.find(this.$events, {
|