@kizmann/pico-js 1.0.13 → 2.0.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/README.md +27 -7
- package/dist/pico-js.browser.js +2 -0
- package/dist/pico-js.browser.js.map +1 -0
- package/dist/pico-js.esm.js +2 -0
- package/dist/pico-js.esm.js.map +1 -0
- package/package.json +20 -7
- package/src/dom/DomAttribute.js +374 -0
- package/src/dom/DomBuilder.js +152 -0
- package/src/dom/DomEvent.js +253 -0
- package/src/dom/DomFinder.js +669 -0
- package/src/dom/DomForm.js +57 -0
- package/src/dom/DomGlobal.js +193 -0
- package/src/dom/DomInview.js +332 -0
- package/src/dom/DomMeta.js +66 -0
- package/src/dom/DomObserver.js +57 -0
- package/src/dom/DomRectangle.js +657 -0
- package/src/format/FormatFile.js +54 -0
- package/src/format/FormatOption.js +108 -0
- package/src/format/FormatParam.js +107 -0
- package/src/format/FormatParser.js +156 -0
- package/src/format/FormatUrl.js +75 -0
- package/src/index.browser.js +10 -0
- package/src/index.esm.js +138 -0
- package/src/now/NowDefault.js +533 -0
- package/src/now/NowFormat.js +196 -0
- package/src/now/NowGrid.js +251 -0
- package/src/now/NowHuman.js +118 -0
- package/src/now/NowMatch.js +175 -0
- package/src/now/NowRange.js +70 -0
- package/src/now/NowWalker.js +544 -0
- package/src/tool/scope.js +103 -0
- package/src/utils/Array.js +986 -0
- package/src/utils/Cookie.js +184 -0
- package/src/utils/Data.js +200 -0
- package/src/utils/Dom.js +208 -0
- package/src/utils/Event.js +140 -0
- package/src/utils/Format.js +62 -0
- package/src/utils/Hash.js +164 -0
- package/src/utils/Locale.js +229 -0
- package/src/utils/Mixed.js +887 -0
- package/src/utils/Now.js +234 -0
- package/src/utils/Number.js +238 -0
- package/src/utils/Object.js +655 -0
- package/src/utils/Route.js +67 -0
- package/src/utils/Runner.js +327 -0
- package/src/utils/String.js +618 -0
- package/src/{library/element.js → wip/Element.js} +90 -16
- package/src/{library/map.js → wip/Map.js} +256 -40
- package/types/dom/DomAttribute.d.ts +137 -0
- package/types/dom/DomBuilder.d.ts +67 -0
- package/types/dom/DomEvent.d.ts +103 -0
- package/types/dom/DomFinder.d.ts +321 -0
- package/types/dom/DomForm.d.ts +21 -0
- package/types/dom/DomGlobal.d.ts +79 -0
- package/types/dom/DomInview.d.ts +114 -0
- package/types/dom/DomMeta.d.ts +29 -0
- package/types/dom/DomObserver.d.ts +21 -0
- package/types/dom/DomRectangle.d.ts +270 -0
- package/types/format/FormatFile.d.ts +18 -0
- package/types/format/FormatOption.d.ts +40 -0
- package/types/format/FormatParam.d.ts +39 -0
- package/types/format/FormatParser.d.ts +46 -0
- package/types/format/FormatUrl.d.ts +17 -0
- package/types/index.browser.d.ts +1 -0
- package/types/index.esm.d.ts +52 -0
- package/types/now/NowDefault.d.ts +183 -0
- package/types/now/NowFormat.d.ts +70 -0
- package/types/now/NowGrid.d.ts +107 -0
- package/types/now/NowHuman.d.ts +37 -0
- package/types/now/NowMatch.d.ts +108 -0
- package/types/now/NowRange.d.ts +21 -0
- package/types/now/NowWalker.d.ts +301 -0
- package/types/tool/scope.d.ts +24 -0
- package/types/utils/Array.d.ts +480 -0
- package/types/utils/Cookie.d.ts +60 -0
- package/types/utils/Data.d.ts +91 -0
- package/types/utils/Dom.d.ts +138 -0
- package/types/utils/Event.d.ts +58 -0
- package/types/utils/Format.d.ts +37 -0
- package/types/utils/Hash.d.ts +81 -0
- package/types/utils/Locale.d.ts +115 -0
- package/types/utils/Mixed.d.ts +469 -0
- package/types/utils/Now.d.ts +125 -0
- package/types/utils/Number.d.ts +127 -0
- package/types/utils/Object.d.ts +255 -0
- package/types/utils/Route.d.ts +37 -0
- package/types/utils/Runner.d.ts +139 -0
- package/types/utils/String.d.ts +330 -0
- package/types/wip/Element.d.ts +119 -0
- package/types/wip/Map.d.ts +254 -0
- package/dist/.ignore.js +0 -0
- package/dist/pico-js.js +0 -2
- package/dist/pico-js.js.map +0 -1
- package/src/element/default.js +0 -46
- package/src/element/example.js +0 -58
- package/src/index.js +0 -90
- package/src/library/cookie.js +0 -123
- package/src/library/data.js +0 -111
- package/src/library/event.js +0 -91
- package/src/library/locale.js +0 -84
- package/src/library/queue.js +0 -64
- package/src/library/route.js +0 -28
- package/src/utility/any.js +0 -369
- package/src/utility/array.js +0 -410
- package/src/utility/dom.js +0 -1425
- package/src/utility/now.js +0 -544
- package/src/utility/number.js +0 -128
- package/src/utility/object.js +0 -429
- package/src/utility/string.js +0 -328
- package/types/index.d.ts +0 -77
- package/types/library/cookie.d.ts +0 -10
- package/types/library/data.d.ts +0 -15
- package/types/library/element.d.ts +0 -22
- package/types/library/event.d.ts +0 -13
- package/types/library/locale.d.ts +0 -14
- package/types/library/map.d.ts +0 -43
- package/types/library/queue.d.ts +0 -18
- package/types/library/route.d.ts +0 -11
- package/types/utility/any.d.ts +0 -35
- package/types/utility/array.d.ts +0 -46
- package/types/utility/dom.d.ts +0 -101
- package/types/utility/now.d.ts +0 -79
- package/types/utility/number.d.ts +0 -17
- package/types/utility/object.d.ts +0 -29
- package/types/utility/string.d.ts +0 -26
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Str, Obj, Dom,
|
|
1
|
+
import { Str, Obj, Dom, Mix, Arr } from "#src/index.esm.js";
|
|
2
2
|
|
|
3
|
-
export class
|
|
3
|
+
export class PicoElement
|
|
4
4
|
{
|
|
5
5
|
/**
|
|
6
6
|
* Prefix for attribute selector.
|
|
@@ -27,15 +27,29 @@ export class Element
|
|
|
27
27
|
*/
|
|
28
28
|
static invi = [];
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Listen to scroll events
|
|
32
|
+
*
|
|
33
|
+
* @example PicoElement.listen()
|
|
34
|
+
*
|
|
35
|
+
* @returns {void} No return value
|
|
36
|
+
*/
|
|
30
37
|
static listen()
|
|
31
38
|
{
|
|
32
39
|
// Apply dom scroll event
|
|
33
|
-
document.addEventListener("scroll",
|
|
40
|
+
document.addEventListener("scroll", PicoElement.scroll);
|
|
34
41
|
|
|
35
42
|
// Apply initial scroll event
|
|
36
|
-
|
|
43
|
+
PicoElement.scroll();
|
|
37
44
|
}
|
|
38
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Handle scroll visibility
|
|
48
|
+
*
|
|
49
|
+
* @example PicoElement.scroll()
|
|
50
|
+
*
|
|
51
|
+
* @returns {void} No return value
|
|
52
|
+
*/
|
|
39
53
|
static scroll()
|
|
40
54
|
{
|
|
41
55
|
Arr.each(this.invi, (item, index) => {
|
|
@@ -51,7 +65,13 @@ export class Element
|
|
|
51
65
|
}
|
|
52
66
|
|
|
53
67
|
/**
|
|
54
|
-
*
|
|
68
|
+
* Register element alias
|
|
69
|
+
*
|
|
70
|
+
* @example PicoElement.alias("tab", Tab)
|
|
71
|
+
*
|
|
72
|
+
* @param {string} key Alias key
|
|
73
|
+
* @param {any} instance Class instance
|
|
74
|
+
* @returns {this} Current class
|
|
55
75
|
*/
|
|
56
76
|
static alias(key, instance)
|
|
57
77
|
{
|
|
@@ -60,6 +80,16 @@ export class Element
|
|
|
60
80
|
return this;
|
|
61
81
|
}
|
|
62
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Bind element to selector
|
|
85
|
+
*
|
|
86
|
+
* @example PicoElement.bind("tab", ".tabs")
|
|
87
|
+
*
|
|
88
|
+
* @param {string} key Alias key
|
|
89
|
+
* @param {any} selector Dom selector
|
|
90
|
+
* @param {any} [options] Init options
|
|
91
|
+
* @returns {this} Current class
|
|
92
|
+
*/
|
|
63
93
|
static bind(key, selector, options = {})
|
|
64
94
|
{
|
|
65
95
|
let el = Dom.find(selector), prefix = this.getPrefix(key);
|
|
@@ -70,7 +100,7 @@ export class Element
|
|
|
70
100
|
let instance = Obj.get(this.inis,
|
|
71
101
|
key, null);
|
|
72
102
|
|
|
73
|
-
if (
|
|
103
|
+
if ( Mix.isEmpty(instance) ) {
|
|
74
104
|
return console.error(`Element "${key}" is not defined.`);
|
|
75
105
|
}
|
|
76
106
|
|
|
@@ -80,7 +110,7 @@ export class Element
|
|
|
80
110
|
el.get(0), options
|
|
81
111
|
);
|
|
82
112
|
|
|
83
|
-
|
|
113
|
+
PicoElement.runs.push({
|
|
84
114
|
el: el.get(0), prefix: prefix, deamon: cb
|
|
85
115
|
});
|
|
86
116
|
|
|
@@ -97,6 +127,16 @@ export class Element
|
|
|
97
127
|
return this;
|
|
98
128
|
}
|
|
99
129
|
|
|
130
|
+
/**
|
|
131
|
+
* Unbind element from selector
|
|
132
|
+
*
|
|
133
|
+
* @example PicoElement.unbind("tab", ".tabs")
|
|
134
|
+
*
|
|
135
|
+
* @param {string} key Alias key
|
|
136
|
+
* @param {any} selector Dom selector
|
|
137
|
+
* @param {any} [options] Init options
|
|
138
|
+
* @returns {this} Current class
|
|
139
|
+
*/
|
|
100
140
|
static unbind(key, selector, options = {})
|
|
101
141
|
{
|
|
102
142
|
let el = Dom.find(selector), prefix = this.getPrefix(key);
|
|
@@ -104,7 +144,7 @@ export class Element
|
|
|
104
144
|
let instance = Obj.get(this.inis,
|
|
105
145
|
key, null);
|
|
106
146
|
|
|
107
|
-
if (
|
|
147
|
+
if ( Mix.isEmpty(instance) ) {
|
|
108
148
|
return console.error(`Element "${key}" is not defined.`);
|
|
109
149
|
}
|
|
110
150
|
|
|
@@ -122,14 +162,20 @@ export class Element
|
|
|
122
162
|
// Unbind option
|
|
123
163
|
callback.call({}, el, options);
|
|
124
164
|
|
|
125
|
-
Arr.remove(
|
|
165
|
+
Arr.remove(PicoElement.runs, { el: el.get(0) });
|
|
126
166
|
|
|
127
167
|
return this;
|
|
128
168
|
}
|
|
129
169
|
|
|
130
170
|
|
|
131
171
|
/**
|
|
132
|
-
*
|
|
172
|
+
* Observe DOM changes
|
|
173
|
+
*
|
|
174
|
+
* @example PicoElement.observe("tab")
|
|
175
|
+
*
|
|
176
|
+
* @param {string} key Alias key
|
|
177
|
+
* @param {boolean} [plain] Plain options
|
|
178
|
+
* @returns {this} Current class
|
|
133
179
|
*/
|
|
134
180
|
static observe(key, plain = false)
|
|
135
181
|
{
|
|
@@ -144,7 +190,7 @@ export class Element
|
|
|
144
190
|
|
|
145
191
|
let callback = () => {
|
|
146
192
|
|
|
147
|
-
let mounted =
|
|
193
|
+
let mounted = PicoElement.getPrefix(key);
|
|
148
194
|
|
|
149
195
|
let deamons = Arr.filter(this.runs,
|
|
150
196
|
{ prefix: selector });
|
|
@@ -155,7 +201,7 @@ export class Element
|
|
|
155
201
|
Dom.find(el).attr(selector)
|
|
156
202
|
);
|
|
157
203
|
|
|
158
|
-
if ( plain &&
|
|
204
|
+
if ( plain && Mix.isEmpty(options) ) {
|
|
159
205
|
options = { _plain: Dom.find(el).attr(selector) };
|
|
160
206
|
}
|
|
161
207
|
|
|
@@ -178,7 +224,7 @@ export class Element
|
|
|
178
224
|
Dom.find(el).attr(selector)
|
|
179
225
|
);
|
|
180
226
|
|
|
181
|
-
if ( plain &&
|
|
227
|
+
if ( plain && Mix.isEmpty(options) ) {
|
|
182
228
|
options = { _plain: Dom.find(el).attr(selector) };
|
|
183
229
|
}
|
|
184
230
|
|
|
@@ -201,11 +247,29 @@ export class Element
|
|
|
201
247
|
return this;
|
|
202
248
|
}
|
|
203
249
|
|
|
250
|
+
/**
|
|
251
|
+
* Bind element on inview
|
|
252
|
+
*
|
|
253
|
+
* @example PicoElement.bindInview(el, cb)
|
|
254
|
+
*
|
|
255
|
+
* @param {Element} el Target element
|
|
256
|
+
* @param {function} cb Callback fn
|
|
257
|
+
* @returns {void} No return value
|
|
258
|
+
*/
|
|
204
259
|
static bindInview(el, cb)
|
|
205
260
|
{
|
|
206
261
|
Arr.add(this.invi, { el, cb }, { el });
|
|
207
262
|
}
|
|
208
263
|
|
|
264
|
+
/**
|
|
265
|
+
* Unbind element on inview
|
|
266
|
+
*
|
|
267
|
+
* @example PicoElement.unbindInview(el, cb)
|
|
268
|
+
*
|
|
269
|
+
* @param {Element} el Target element
|
|
270
|
+
* @param {function} cb Callback fn
|
|
271
|
+
* @returns {void} No return value
|
|
272
|
+
*/
|
|
209
273
|
static unbindInview(el, cb)
|
|
210
274
|
{
|
|
211
275
|
Arr.remove(this.invi, { el, cb }, { el });
|
|
@@ -214,7 +278,12 @@ export class Element
|
|
|
214
278
|
|
|
215
279
|
|
|
216
280
|
/**
|
|
217
|
-
*
|
|
281
|
+
* Get attribute prefix
|
|
282
|
+
*
|
|
283
|
+
* @example PicoElement.getPrefix("tab") // => "js-tab"
|
|
284
|
+
*
|
|
285
|
+
* @param {string} [key] Alias key
|
|
286
|
+
* @returns {string} Attribute prefix
|
|
218
287
|
*/
|
|
219
288
|
static getPrefix(key)
|
|
220
289
|
{
|
|
@@ -222,7 +291,12 @@ export class Element
|
|
|
222
291
|
}
|
|
223
292
|
|
|
224
293
|
/**
|
|
225
|
-
* Set prefix
|
|
294
|
+
* Set attribute prefix
|
|
295
|
+
*
|
|
296
|
+
* @example PicoElement.setPrefix("pi")
|
|
297
|
+
*
|
|
298
|
+
* @param {string} prefix New prefix
|
|
299
|
+
* @returns {void} No return value
|
|
226
300
|
*/
|
|
227
301
|
static setPrefix(prefix)
|
|
228
302
|
{
|
|
@@ -231,4 +305,4 @@ export class Element
|
|
|
231
305
|
|
|
232
306
|
}
|
|
233
307
|
|
|
234
|
-
export default
|
|
308
|
+
export default PicoElement;
|