@kizmann/pico-js 2.0.7 → 2.0.9
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} +101 -76
- package/src/dom/{DomFinder.js → DomFinder.ts} +103 -139
- 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} +70 -87
- 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} +187 -152
- 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} +21 -21
- package/src/utils/{Mixed.js → Mixed.ts} +104 -61
- 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} +89 -77
- 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} +1 -1
- package/types/dom/DomAttribute.d.ts +16 -27
- package/types/dom/DomBuilder.d.ts +6 -9
- package/types/dom/DomEvent.d.ts +19 -24
- package/types/dom/DomFinder.d.ts +38 -61
- 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 -35
- 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 -101
- 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 +9 -9
- package/types/utils/Mixed.d.ts +19 -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 +45 -38
- 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,27 +1,31 @@
|
|
|
1
|
-
import { Arr, Hash, Mix, Obj, Dom, Run } from "../index.esm.
|
|
2
|
-
import { PicoDom } from "../utils/Dom.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { Arr, Hash, Mix, Obj, Dom, Run } from "../index.esm.ts";
|
|
2
|
+
import { PicoDom, PicoDomInterface } from "../utils/Dom.ts";
|
|
3
|
+
import PicoDomFinder from "./DomFinder.js";
|
|
4
|
+
import PicoDomRectangle from "./DomRectangle.js";
|
|
5
|
+
|
|
6
|
+
export interface PicoDomEvent extends PicoDomInterface,
|
|
7
|
+
PicoDomFinder,
|
|
8
|
+
PicoDomRectangle
|
|
8
9
|
{
|
|
9
|
-
|
|
10
|
+
//
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* @memberof PicoDom
|
|
14
|
-
* @extends {PicoDom}
|
|
15
15
|
*/
|
|
16
|
-
export class
|
|
16
|
+
export class PicoDomEvent
|
|
17
17
|
{
|
|
18
|
+
/**
|
|
19
|
+
* @type {any[]}
|
|
20
|
+
*/
|
|
21
|
+
static $events : any[] = [];
|
|
18
22
|
|
|
19
23
|
/**
|
|
20
24
|
* Bind event listener
|
|
21
25
|
*
|
|
22
26
|
* @example Dom.bind(el, "click", cb)
|
|
23
27
|
*
|
|
24
|
-
* @param {
|
|
28
|
+
* @param {any} el Target element
|
|
25
29
|
* @param {string} event Event name
|
|
26
30
|
* @param {function} cb Callback fn
|
|
27
31
|
* @param {string} [selector] Event selector
|
|
@@ -29,7 +33,7 @@ export class PicoDomEventInstance
|
|
|
29
33
|
* @param {any} [options] Listener options
|
|
30
34
|
* @returns {PicoDom} Current instance
|
|
31
35
|
*/
|
|
32
|
-
bind(el, event, cb, selector = null, pause = false, options = {})
|
|
36
|
+
bind(el : any, event : string, cb : Function, selector : string = null, pause : boolean = false, options : any = {}) : PicoDom
|
|
33
37
|
{
|
|
34
38
|
if ( Mix.isPrim(options) ) {
|
|
35
39
|
options = { id: options };
|
|
@@ -39,9 +43,14 @@ export class PicoDomEventInstance
|
|
|
39
43
|
el, event, cb, selector, pause, options
|
|
40
44
|
});
|
|
41
45
|
|
|
42
|
-
|
|
46
|
+
console.log(this.els, el);
|
|
47
|
+
try {
|
|
48
|
+
el.addEventListener(event, cb, options);
|
|
49
|
+
} catch (e) {
|
|
50
|
+
console.log('ERRROR', this.els, el, e);
|
|
51
|
+
}
|
|
43
52
|
|
|
44
|
-
return this;
|
|
53
|
+
return <PicoDom> <unknown> this;
|
|
45
54
|
}
|
|
46
55
|
|
|
47
56
|
/**
|
|
@@ -49,13 +58,13 @@ export class PicoDomEventInstance
|
|
|
49
58
|
*
|
|
50
59
|
* @example Dom.unbind(el, "click")
|
|
51
60
|
*
|
|
52
|
-
* @param {
|
|
61
|
+
* @param {any} el Target element
|
|
53
62
|
* @param {string} event Event name
|
|
54
63
|
* @param {string} [selector] Event selector
|
|
55
64
|
* @param {any} [options] Listener options
|
|
56
65
|
* @returns {PicoDom} Current instance
|
|
57
66
|
*/
|
|
58
|
-
unbind(el, event, selector = null, options = {})
|
|
67
|
+
unbind(el : any, event : string, selector : string = null, options : any = {}) : PicoDom
|
|
59
68
|
{
|
|
60
69
|
if ( Mix.isPrim(options) ) {
|
|
61
70
|
options = { id: options };
|
|
@@ -66,20 +75,20 @@ export class PicoDomEventInstance
|
|
|
66
75
|
});
|
|
67
76
|
|
|
68
77
|
if ( indexes.length === 0 ) {
|
|
69
|
-
return;
|
|
78
|
+
return <PicoDom> <unknown> this;
|
|
70
79
|
}
|
|
71
80
|
|
|
72
|
-
let args = (val) => {
|
|
81
|
+
let args = (val : any) => {
|
|
73
82
|
return [event, val.cb, val.options];
|
|
74
83
|
};
|
|
75
84
|
|
|
76
|
-
Arr.each(indexes.reverse(), (index) => {
|
|
85
|
+
Arr.each(indexes.reverse(), (index : any) => {
|
|
77
86
|
el.removeEventListener(...args(Dom.$events[index]));
|
|
78
87
|
});
|
|
79
88
|
|
|
80
89
|
Arr.splices(Dom.$events, indexes);
|
|
81
90
|
|
|
82
|
-
return this;
|
|
91
|
+
return <PicoDom> <unknown> this;
|
|
83
92
|
}
|
|
84
93
|
|
|
85
94
|
/**
|
|
@@ -88,32 +97,36 @@ export class PicoDomEventInstance
|
|
|
88
97
|
* @example Dom.find("div").on("click", cb)
|
|
89
98
|
*
|
|
90
99
|
* @param {any} event Event name
|
|
91
|
-
* @param {
|
|
100
|
+
* @param {Function} cb Callback fn
|
|
92
101
|
* @param {any} [options] Listener options
|
|
93
102
|
* @param {boolean} [pause] Pause listener
|
|
94
103
|
* @param {string} [selector] Event selector
|
|
95
104
|
* @returns {PicoDom} Current instance
|
|
96
105
|
*/
|
|
97
|
-
on(event, cb, options = {}, pause = false, selector = null)
|
|
106
|
+
on(event : any, cb : Function, options : any = {}, pause : boolean = false, selector : string = null) : PicoDom
|
|
98
107
|
{
|
|
99
108
|
if ( Mix.isPrim(options) ) {
|
|
100
109
|
options = { id: options };
|
|
101
110
|
}
|
|
102
111
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
// }
|
|
112
|
+
const args = [
|
|
113
|
+
cb, options, pause, selector
|
|
114
|
+
];
|
|
107
115
|
|
|
108
|
-
|
|
116
|
+
if ( Mix.isArr(event) ) {
|
|
117
|
+
// @ts-ignore
|
|
118
|
+
return (Arr.each(event, (e : any) => this.on(e, ...args)), this);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
let fn = (e : any) => {
|
|
109
122
|
cb.call(e.target, e, e.target);
|
|
110
123
|
};
|
|
111
124
|
|
|
112
|
-
this.each((el) => {
|
|
125
|
+
this.each((el : any) => {
|
|
113
126
|
this.bind(el, event, fn, selector, pause, options);
|
|
114
127
|
});
|
|
115
128
|
|
|
116
|
-
return this;
|
|
129
|
+
return <PicoDom> <unknown> this;
|
|
117
130
|
}
|
|
118
131
|
|
|
119
132
|
/**
|
|
@@ -126,26 +139,30 @@ export class PicoDomEventInstance
|
|
|
126
139
|
* @param {any} [options] Listener options
|
|
127
140
|
* @returns {PicoDom} Current instance
|
|
128
141
|
*/
|
|
129
|
-
off(event, selector = null, options = {})
|
|
142
|
+
off(event : any, selector : string = null, options : any = {}) : PicoDom
|
|
130
143
|
{
|
|
131
144
|
if ( Mix.isPrim(options) ) {
|
|
132
145
|
options = { id: options };
|
|
133
146
|
}
|
|
134
147
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
148
|
+
const args = [
|
|
149
|
+
selector, options
|
|
150
|
+
];
|
|
151
|
+
|
|
152
|
+
if ( Mix.isArr(event) ) {
|
|
153
|
+
// @ts-ignore
|
|
154
|
+
return (Arr.each(event, (e : any) => this.off(e, ...args)), this);
|
|
155
|
+
}
|
|
139
156
|
|
|
140
157
|
if ( Mix.isObj(selector) ) {
|
|
141
158
|
(options = selector, selector = null);
|
|
142
159
|
}
|
|
143
160
|
|
|
144
|
-
this.each((el) => {
|
|
161
|
+
this.each((el : any) => {
|
|
145
162
|
this.unbind(el, event, selector, options);
|
|
146
163
|
});
|
|
147
164
|
|
|
148
|
-
return this;
|
|
165
|
+
return <PicoDom> <unknown> this;
|
|
149
166
|
}
|
|
150
167
|
|
|
151
168
|
/**
|
|
@@ -156,17 +173,17 @@ export class PicoDomEventInstance
|
|
|
156
173
|
* @param {any} [options] Listener options
|
|
157
174
|
* @returns {PicoDom} Current instance
|
|
158
175
|
*/
|
|
159
|
-
optoff(options = {})
|
|
176
|
+
optoff(options : any = {}) : PicoDom
|
|
160
177
|
{
|
|
161
|
-
Run.
|
|
178
|
+
Run.async(() => {
|
|
162
179
|
Arr.filterRemove(Dom.$events, { options });
|
|
163
180
|
});
|
|
164
181
|
|
|
165
|
-
this.each((el) => {
|
|
182
|
+
this.each((el : any) => {
|
|
166
183
|
el && el.removeAllListeners();
|
|
167
184
|
});
|
|
168
185
|
|
|
169
|
-
return this;
|
|
186
|
+
return <PicoDom> <unknown> this;
|
|
170
187
|
}
|
|
171
188
|
|
|
172
189
|
/**
|
|
@@ -175,19 +192,20 @@ export class PicoDomEventInstance
|
|
|
175
192
|
* @example Dom.find("div").once("click", cb)
|
|
176
193
|
*
|
|
177
194
|
* @param {any} event Event name
|
|
178
|
-
* @param {
|
|
195
|
+
* @param {Function} cb Callback fn
|
|
179
196
|
* @param {any} [options] Listener options
|
|
180
197
|
* @returns {PicoDom} Current instance
|
|
181
198
|
*/
|
|
182
|
-
once(event, cb, options = {})
|
|
199
|
+
once(event : any, cb : Function, options : any = {}) : PicoDom
|
|
183
200
|
{
|
|
184
201
|
options.id = Hash.make(24);
|
|
185
202
|
|
|
186
203
|
this.on(event, (e) => {
|
|
187
|
-
cb(e);
|
|
204
|
+
cb(e);
|
|
205
|
+
this.off(event, options);
|
|
188
206
|
}, options);
|
|
189
207
|
|
|
190
|
-
return this;
|
|
208
|
+
return <PicoDom> <unknown> this;
|
|
191
209
|
}
|
|
192
210
|
|
|
193
211
|
/**
|
|
@@ -197,14 +215,14 @@ export class PicoDomEventInstance
|
|
|
197
215
|
*
|
|
198
216
|
* @param {any} event Event name
|
|
199
217
|
* @param {string} selector Event selector
|
|
200
|
-
* @param {
|
|
218
|
+
* @param {Function} cb Callback fn
|
|
201
219
|
* @param {any} [options] Listener options
|
|
202
220
|
* @param {boolean} [pause] Pause listener
|
|
203
221
|
* @returns {PicoDom} Current instance
|
|
204
222
|
*/
|
|
205
|
-
live(event, selector, cb, options = {}, pause = false)
|
|
223
|
+
live(event : any, selector : string, cb : Function, options : any = {}, pause : boolean = false) : PicoDom
|
|
206
224
|
{
|
|
207
|
-
let fn = function (event) {
|
|
225
|
+
let fn = function (event : any) {
|
|
208
226
|
|
|
209
227
|
let target = Dom.getNodeEvent(selector, event);
|
|
210
228
|
|
|
@@ -217,7 +235,7 @@ export class PicoDomEventInstance
|
|
|
217
235
|
|
|
218
236
|
this.on(event, fn, options, pause, selector);
|
|
219
237
|
|
|
220
|
-
return this;
|
|
238
|
+
return <PicoDom> <unknown> this;
|
|
221
239
|
}
|
|
222
240
|
|
|
223
241
|
/**
|
|
@@ -229,55 +247,62 @@ export class PicoDomEventInstance
|
|
|
229
247
|
* @param {object} [detail] Event detail
|
|
230
248
|
* @returns {PicoDom} Current instance
|
|
231
249
|
*/
|
|
232
|
-
fire(event, detail = {})
|
|
250
|
+
fire(event : string, detail : any = {}) : PicoDom
|
|
233
251
|
{
|
|
234
252
|
let callback = new CustomEvent(event, { detail });
|
|
235
253
|
|
|
236
|
-
this.each((el) => {
|
|
254
|
+
this.each((el : any) => {
|
|
237
255
|
el.dispatchEvent(callback);
|
|
238
256
|
});
|
|
239
257
|
|
|
258
|
+
return <PicoDom> <unknown> this;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
pointerdown(button : number = 1)
|
|
262
|
+
{
|
|
263
|
+
const rect = this.rect();
|
|
264
|
+
|
|
265
|
+
const [x, y] = [
|
|
266
|
+
rect.left + rect.width / 2,
|
|
267
|
+
rect.top + rect.height / 2,
|
|
268
|
+
];
|
|
269
|
+
|
|
270
|
+
const event = new PointerEvent('pointerdown', {
|
|
271
|
+
view: window,
|
|
272
|
+
bubbles: true,
|
|
273
|
+
cancelable: true,
|
|
274
|
+
buttons: 1,
|
|
275
|
+
clientX: x, clientY: y
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
this.each((el : any) => {
|
|
279
|
+
el.dispatchEvent(event);
|
|
280
|
+
});
|
|
281
|
+
|
|
240
282
|
return this;
|
|
241
283
|
}
|
|
242
284
|
|
|
243
285
|
}
|
|
244
286
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
*/
|
|
248
|
-
PicoDomEventInstance.prototype.one = function (...args) {
|
|
287
|
+
// @ts-ignore
|
|
288
|
+
PicoDomEvent.prototype.one = function (...args : Parameters<typeof PicoDomEvent.prototype.once>) {
|
|
249
289
|
console.warn('Dom.one() is deprecated, use Dom.once() instead.');
|
|
250
290
|
return this.once(...args);
|
|
251
291
|
};
|
|
252
292
|
|
|
253
|
-
|
|
254
|
-
|
|
293
|
+
// @ts-ignore
|
|
294
|
+
PicoDomEvent.prototype.delayed = function () {
|
|
255
295
|
console.error('Dom.delayed() is not implemented anymore.');
|
|
256
296
|
};
|
|
257
297
|
|
|
258
|
-
|
|
298
|
+
// @ts-ignore
|
|
299
|
+
PicoDomEvent.prototype.pause = function () {
|
|
259
300
|
console.error('Dom.pause() is not implemented anymore.');
|
|
260
301
|
};
|
|
261
302
|
|
|
262
|
-
|
|
303
|
+
// @ts-ignore
|
|
304
|
+
PicoDomEvent.prototype.unpause = function () {
|
|
263
305
|
console.error('Dom.unpause() is not implemented anymore.');
|
|
264
306
|
};
|
|
265
307
|
|
|
266
|
-
|
|
267
|
-
* @param {typeof PicoDom} self
|
|
268
|
-
* @returns {typeof PicoDom}
|
|
269
|
-
*/
|
|
270
|
-
export const PicoDomEventPlugin = function (self) {
|
|
271
|
-
|
|
272
|
-
Obj.each(Mix.class(PicoDomEventStatic), (fn, id) => {
|
|
273
|
-
self[id] = fn;
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
Obj.each(Mix.proto(PicoDomEventInstance), (fn, id) => {
|
|
277
|
-
self.prototype[id] = fn;
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
// self.init.push(PicoDomEventInstance.constructor);
|
|
281
|
-
|
|
282
|
-
return self;
|
|
283
|
-
}
|
|
308
|
+
export default PicoDomEvent;
|