@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.
Files changed (125) hide show
  1. package/README.md +27 -7
  2. package/dist/pico-js.browser.js +2 -0
  3. package/dist/pico-js.browser.js.map +1 -0
  4. package/dist/pico-js.esm.js +2 -0
  5. package/dist/pico-js.esm.js.map +1 -0
  6. package/package.json +20 -7
  7. package/src/dom/DomAttribute.js +374 -0
  8. package/src/dom/DomBuilder.js +152 -0
  9. package/src/dom/DomEvent.js +253 -0
  10. package/src/dom/DomFinder.js +669 -0
  11. package/src/dom/DomForm.js +57 -0
  12. package/src/dom/DomGlobal.js +193 -0
  13. package/src/dom/DomInview.js +332 -0
  14. package/src/dom/DomMeta.js +66 -0
  15. package/src/dom/DomObserver.js +57 -0
  16. package/src/dom/DomRectangle.js +657 -0
  17. package/src/format/FormatFile.js +54 -0
  18. package/src/format/FormatOption.js +108 -0
  19. package/src/format/FormatParam.js +107 -0
  20. package/src/format/FormatParser.js +156 -0
  21. package/src/format/FormatUrl.js +75 -0
  22. package/src/index.browser.js +10 -0
  23. package/src/index.esm.js +138 -0
  24. package/src/now/NowDefault.js +533 -0
  25. package/src/now/NowFormat.js +196 -0
  26. package/src/now/NowGrid.js +251 -0
  27. package/src/now/NowHuman.js +118 -0
  28. package/src/now/NowMatch.js +175 -0
  29. package/src/now/NowRange.js +70 -0
  30. package/src/now/NowWalker.js +544 -0
  31. package/src/tool/scope.js +103 -0
  32. package/src/utils/Array.js +986 -0
  33. package/src/utils/Cookie.js +184 -0
  34. package/src/utils/Data.js +200 -0
  35. package/src/utils/Dom.js +208 -0
  36. package/src/utils/Event.js +140 -0
  37. package/src/utils/Format.js +62 -0
  38. package/src/utils/Hash.js +164 -0
  39. package/src/utils/Locale.js +229 -0
  40. package/src/utils/Mixed.js +887 -0
  41. package/src/utils/Now.js +234 -0
  42. package/src/utils/Number.js +238 -0
  43. package/src/utils/Object.js +655 -0
  44. package/src/utils/Route.js +67 -0
  45. package/src/utils/Runner.js +327 -0
  46. package/src/utils/String.js +618 -0
  47. package/src/{library/element.js → wip/Element.js} +90 -16
  48. package/src/{library/map.js → wip/Map.js} +256 -40
  49. package/types/dom/DomAttribute.d.ts +137 -0
  50. package/types/dom/DomBuilder.d.ts +67 -0
  51. package/types/dom/DomEvent.d.ts +103 -0
  52. package/types/dom/DomFinder.d.ts +321 -0
  53. package/types/dom/DomForm.d.ts +21 -0
  54. package/types/dom/DomGlobal.d.ts +79 -0
  55. package/types/dom/DomInview.d.ts +114 -0
  56. package/types/dom/DomMeta.d.ts +29 -0
  57. package/types/dom/DomObserver.d.ts +21 -0
  58. package/types/dom/DomRectangle.d.ts +270 -0
  59. package/types/format/FormatFile.d.ts +18 -0
  60. package/types/format/FormatOption.d.ts +40 -0
  61. package/types/format/FormatParam.d.ts +39 -0
  62. package/types/format/FormatParser.d.ts +46 -0
  63. package/types/format/FormatUrl.d.ts +17 -0
  64. package/types/index.browser.d.ts +1 -0
  65. package/types/index.esm.d.ts +52 -0
  66. package/types/now/NowDefault.d.ts +183 -0
  67. package/types/now/NowFormat.d.ts +70 -0
  68. package/types/now/NowGrid.d.ts +107 -0
  69. package/types/now/NowHuman.d.ts +37 -0
  70. package/types/now/NowMatch.d.ts +108 -0
  71. package/types/now/NowRange.d.ts +21 -0
  72. package/types/now/NowWalker.d.ts +301 -0
  73. package/types/tool/scope.d.ts +24 -0
  74. package/types/utils/Array.d.ts +480 -0
  75. package/types/utils/Cookie.d.ts +60 -0
  76. package/types/utils/Data.d.ts +91 -0
  77. package/types/utils/Dom.d.ts +138 -0
  78. package/types/utils/Event.d.ts +58 -0
  79. package/types/utils/Format.d.ts +37 -0
  80. package/types/utils/Hash.d.ts +81 -0
  81. package/types/utils/Locale.d.ts +115 -0
  82. package/types/utils/Mixed.d.ts +469 -0
  83. package/types/utils/Now.d.ts +125 -0
  84. package/types/utils/Number.d.ts +127 -0
  85. package/types/utils/Object.d.ts +255 -0
  86. package/types/utils/Route.d.ts +37 -0
  87. package/types/utils/Runner.d.ts +139 -0
  88. package/types/utils/String.d.ts +330 -0
  89. package/types/wip/Element.d.ts +119 -0
  90. package/types/wip/Map.d.ts +254 -0
  91. package/dist/.ignore.js +0 -0
  92. package/dist/pico-js.js +0 -2
  93. package/dist/pico-js.js.map +0 -1
  94. package/src/element/default.js +0 -46
  95. package/src/element/example.js +0 -58
  96. package/src/index.js +0 -90
  97. package/src/library/cookie.js +0 -123
  98. package/src/library/data.js +0 -111
  99. package/src/library/event.js +0 -91
  100. package/src/library/locale.js +0 -84
  101. package/src/library/queue.js +0 -64
  102. package/src/library/route.js +0 -28
  103. package/src/utility/any.js +0 -369
  104. package/src/utility/array.js +0 -410
  105. package/src/utility/dom.js +0 -1425
  106. package/src/utility/now.js +0 -544
  107. package/src/utility/number.js +0 -128
  108. package/src/utility/object.js +0 -429
  109. package/src/utility/string.js +0 -328
  110. package/types/index.d.ts +0 -77
  111. package/types/library/cookie.d.ts +0 -10
  112. package/types/library/data.d.ts +0 -15
  113. package/types/library/element.d.ts +0 -22
  114. package/types/library/event.d.ts +0 -13
  115. package/types/library/locale.d.ts +0 -14
  116. package/types/library/map.d.ts +0 -43
  117. package/types/library/queue.d.ts +0 -18
  118. package/types/library/route.d.ts +0 -11
  119. package/types/utility/any.d.ts +0 -35
  120. package/types/utility/array.d.ts +0 -46
  121. package/types/utility/dom.d.ts +0 -101
  122. package/types/utility/now.d.ts +0 -79
  123. package/types/utility/number.d.ts +0 -17
  124. package/types/utility/object.d.ts +0 -29
  125. package/types/utility/string.d.ts +0 -26
@@ -1,1425 +0,0 @@
1
- import Arr from './array.js';
2
- import Obj from './object.js';
3
- import Str from './string.js';
4
- import Num from './number.js';
5
- import Any from './any.js';
6
-
7
- export class Dom
8
- {
9
- el = null;
10
-
11
- static events = [];
12
-
13
- static datas = [];
14
-
15
- constructor(el)
16
- {
17
- if ( el instanceof NodeList ) {
18
- el = Array.prototype.slice.call(el);
19
- }
20
-
21
- this.el = el;
22
- }
23
-
24
- static ready(callback, delay = 0, count = 0)
25
- {
26
- let ready = document.readyState !== 'loading';
27
-
28
- if ( delay === 0 && (ready === false && count >= delay) ) {
29
- Dom.find(document).on('DOMContentLoaded', callback);
30
- return this;
31
- }
32
-
33
- if ( delay !== 0 && (ready === false || count <= delay) ) {
34
- setTimeout(() => Dom.ready(callback, delay, count + 50), 50);
35
- return this;
36
- }
37
-
38
- callback();
39
-
40
- return this;
41
- }
42
-
43
- static complete(callback, delay = 0, count = 0)
44
- {
45
- let ready = document.readyState === 'complete' ||
46
- document.readyState === 'interactive';
47
-
48
- if ( delay === 0 && (ready === false || count < delay) ) {
49
- Dom.find(document).on('load', callback);
50
- return this;
51
- }
52
-
53
- if ( delay !== 0 && (ready === false || count < delay) ) {
54
- setTimeout(() => Dom.ready(callback, delay, count + 50), 50);
55
- return this;
56
- }
57
-
58
- callback();
59
-
60
- return this;
61
- }
62
-
63
- static required(callback, globals = [], timer = 100) {
64
-
65
- let matches = Arr.each(globals, (key) => {
66
- return Obj.has(window, key);
67
- });
68
-
69
- if ( Arr.has(matches, false) ) {
70
- setTimeout(() => Dom.required(callback, globals, timer), timer);
71
- return this;
72
- }
73
-
74
- callback();
75
-
76
- return this;
77
- }
78
-
79
- static find(element)
80
- {
81
- let el = typeof element !== 'string' ?
82
- element : document.querySelectorAll(element);
83
-
84
- return new Dom(el);
85
- }
86
-
87
- static make(element, options = {})
88
- {
89
- let el = typeof element !== 'string' ?
90
- element : document.createElement(element);
91
-
92
- Obj.assign(el, options);
93
-
94
- return new Dom(el);
95
- }
96
-
97
- static location(posx, posy)
98
- {
99
- let el = null;
100
-
101
- if ( document.elementsFromPoint !== undefined ) {
102
- el = document.elementsFromPoint(posx, posy);
103
- }
104
-
105
- if ( document.msElementsFromPoint !== undefined ) {
106
- el = document.msElementsFromPoint(posx, posy);
107
- }
108
-
109
- return new Dom(el);
110
- }
111
-
112
- static title(text = null, glue = ' - ')
113
- {
114
- document.title = window.baseTitle !== undefined ?
115
- text + glue + window.baseTitle : text;
116
-
117
- return this;
118
- }
119
-
120
- length()
121
- {
122
- return Any.isArray(this.el) ?
123
- this.el.length : (Any.isEmpty(this.el) ? 0 : 1);
124
- }
125
-
126
- empty()
127
- {
128
- return this.length() === 0 || this.el === null;
129
- }
130
-
131
- visible()
132
- {
133
- return this.get(0) && this.get(0).is(':visible');
134
- }
135
-
136
- inviewHeight(boundry = window)
137
- {
138
- let parent = Dom.find(boundry);
139
-
140
- let viewport = {
141
- width: parent.width(),
142
- height: parent.height(),
143
- };
144
-
145
- let element = {
146
- width: this.width(),
147
- height: this.height(),
148
- };
149
-
150
- let scroll = this.scroll(),
151
- offset = this.offset();
152
-
153
- let [top, bottom] = [
154
- scroll.top + parent.offset('top'), offset.top + element.height
155
- ];
156
-
157
- return Math.max(0, Math.min(bottom, viewport.height + top) -
158
- Math.max(offset.top, top))
159
- }
160
-
161
- inviewX(ratio = 0)
162
- {
163
- let viewport = {
164
- width: Dom.find(window).width(),
165
- height: Dom.find(window).height(),
166
- };
167
-
168
- let element = {
169
- width: this.width(),
170
- height: this.height(),
171
- };
172
-
173
- let scroll = this.scroll(),
174
- offset = this.offset();
175
-
176
- let left = offset.left + (ratio * element.width) -
177
- viewport.width;
178
-
179
- let right = offset.left + element.width -
180
- (ratio * element.width);
181
-
182
- return left <= scroll.left && scroll.left <= right;
183
- }
184
-
185
- inviewY(ratio = 0)
186
- {
187
- let viewport = {
188
- width: Dom.find(window).width(),
189
- height: Dom.find(window).height(),
190
- };
191
-
192
- let element = {
193
- width: this.width(),
194
- height: this.height(),
195
- };
196
-
197
- let scroll = this.scroll(),
198
- offset = this.offset();
199
-
200
- let top = offset.top + (ratio * element.height) -
201
- viewport.height;
202
-
203
- let bottom = offset.top + element.height -
204
- (ratio * element.height);
205
-
206
- return top <= scroll.top && scroll.top <= bottom;
207
- }
208
-
209
- static inviewMaxY(options, callback = null)
210
- {
211
- let defaults = {
212
- el: '[data-inview]', parent: document.body, multiple: false, safezone: null,
213
- };
214
-
215
- if ( Any.isString(options) ) {
216
- options = { el: options };
217
- }
218
-
219
- let boundry = Dom.find(options.parent)
220
- .closestScrollable(window);
221
-
222
- options = Obj.assign({}, defaults, options);
223
-
224
- let safeback = (item) => {
225
- return Math.min(Dom.find(item.el).height() * 0.5, Dom.find(boundry).height() * 0.2);
226
- };
227
-
228
- let safezone = options.safezone;
229
-
230
- if ( Any.isNull(safezone) ) {
231
- safezone = safeback;
232
- }
233
-
234
- if ( ! Any.isFunction(safezone) ) {
235
- safezone = () => options.safezone;
236
- }
237
-
238
- let [items, attr] = [
239
- [], options.el.replace(/^\[([^="]+)]$/, '$1')
240
- ];
241
-
242
- let parent = Dom.find(options.parent).find(options.el);
243
-
244
- parent.each((el) => {
245
- items.push({
246
- el, attr: Dom.find(el).attr(attr), height: Dom.find(el).inviewHeight(boundry)
247
- });
248
- });
249
-
250
- let results = Arr.filter(items, (item) => {
251
- return Math.max(0, item.height - safezone(item)) !== 0;
252
- });
253
-
254
- results = Arr.sort(results, (a, b) => {
255
- return a.height >= b.height ? -1 : 1;
256
- });
257
-
258
- Arr.each(results, (item, index) => {
259
- Any.isFunction(callback) && callback.call({}, item, index);
260
- });
261
-
262
- return options.multiple ? Arr.extract(results, 'el') :
263
- Obj.get(results, '0.el');
264
- }
265
-
266
- is(selector)
267
- {
268
- return this.matches(selector);
269
- }
270
-
271
- isParent(selector)
272
- {
273
- let el = this.parent();
274
-
275
- if ( Any.isEmpty(el) === true ) {
276
- return false;
277
- }
278
-
279
- return Any.isString(selector) ?
280
- Dom.find(el).matches(selector) : this.get(0) === selector;
281
- }
282
-
283
- first(offset = 0)
284
- {
285
- let els = Any.isArray(this.el) ?
286
- this.el : [this.el];
287
-
288
- return els[offset];
289
- }
290
-
291
- last(offset = 1)
292
- {
293
- let els = Any.isArray(this.el) ?
294
- this.el : [this.el];
295
-
296
- return els[els.length - offset];
297
- }
298
-
299
- get(index = -1)
300
- {
301
- let els = Any.isArray(this.el) ?
302
- this.el : [this.el];
303
-
304
- return index !== -1 ? els[index] || null : els;
305
- }
306
-
307
- getNot(el)
308
- {
309
- for ( let node of this.el ) {
310
- if ( node !== el ) {
311
- return Dom.find(node);
312
- }
313
- }
314
-
315
- return null;
316
- }
317
-
318
- each(callback)
319
- {
320
- return Any.isArray(this.el) ? Arr.each(this.el, callback) :
321
- callback(this.el, 0);
322
- }
323
-
324
- matches(selector)
325
- {
326
- let source = this.get(0), target = null;
327
-
328
- Dom.find(selector).each((el) => {
329
- if ( el === source) target = el;
330
- });
331
-
332
- return target !== null;
333
- }
334
-
335
- closest(selector)
336
- {
337
- if ( this.get(0) === selector ) {
338
- return selector;
339
- }
340
-
341
- for (let el = this.get(0); el !== null && el.parentNode !== undefined; el = el.parentNode) {
342
- if ( Dom.find(el).is(selector) ) {
343
- return el;
344
- }
345
- }
346
-
347
- return null;
348
- }
349
-
350
- closestScrollable(fallback = document.body)
351
- {
352
- for (let el = this.get(0); el !== null && el.parentNode !== undefined; el = el.parentNode) {
353
- if ( el.scrollHeight > el.clientHeight + 1 ) {
354
- return el;
355
- }
356
- }
357
-
358
- return fallback;
359
- }
360
-
361
- contains(selector)
362
- {
363
- if ( Any.isString(selector) === true ) {
364
- return this.find(selector).get(0) !== null;
365
- }
366
-
367
- if ( selector instanceof Element === false ) {
368
- return false;
369
- }
370
-
371
- return this.get(0).contains(selector);
372
- }
373
-
374
- inside(selector)
375
- {
376
- return this.closest(selector) !== null;
377
- }
378
-
379
- parent()
380
- {
381
- let el = this.get(0);
382
-
383
- if ( el === null || el.parentNode === undefined ) {
384
- return Dom.find(null);
385
- }
386
-
387
- return Dom.find(el.parentNode);
388
- }
389
-
390
- child(selector)
391
- {
392
- let nodes = this.get(0).childNodes;
393
-
394
- nodes = Array.prototype.slice.call(nodes);
395
-
396
- Arr.each(nodes, (node, index) => {
397
- if ( node.nodeType === 3 ) {
398
- nodes = Arr.splice(nodes, index);
399
- }
400
- });
401
-
402
- if ( selector === null ) {
403
- return Dom.find(nodes[0] || null);
404
- }
405
-
406
- Arr.each(nodes, (node, index) => {
407
- if ( Any.isEmpty(node) || Dom.find(node).is(selector) === false ) {
408
- nodes = Arr.splice(nodes, index);
409
- }
410
- });
411
-
412
- return Dom.find(nodes[0] || null);
413
- }
414
-
415
- childs(selector = null, filter = true)
416
- {
417
- let nodes = this.get(0).childNodes;
418
-
419
- nodes = Array.prototype.slice.call(nodes);
420
-
421
- Arr.each(nodes, (node, index) => {
422
- if ( node.nodeType === 3 && filter === true ) {
423
- nodes = Arr.splice(nodes, index);
424
- }
425
- });
426
-
427
- if ( selector === null ) {
428
- return Dom.find(nodes);
429
- }
430
-
431
- Arr.each(nodes, (node, index) => {
432
- if ( Any.isEmpty(node) || Dom.find(node).is(selector) === false ) {
433
- nodes = Arr.splice(nodes, index);
434
- }
435
- });
436
-
437
- return Dom.find(nodes);
438
- }
439
-
440
- find(selector)
441
- {
442
- let el = this.get(0);
443
-
444
- if ( Any.isEmpty(el) === true ) {
445
- return Dom.find(null);
446
- }
447
-
448
- if ( el instanceof Window ) {
449
- el = document;
450
- }
451
-
452
- let nodes = el.querySelectorAll(selector);
453
-
454
- nodes = Array.prototype.slice.call(nodes);
455
-
456
- Arr.each(nodes, (node, index) => {
457
- if ( node.nodeType === 3 ) {
458
- nodes = Arr.splice(nodes, index);
459
- }
460
- });
461
-
462
- return Dom.find(nodes);
463
- }
464
-
465
- where(selector)
466
- {
467
- let nodes = this.get();
468
-
469
- Arr.each(nodes, (el, index) => {
470
- if ( Any.isEmpty(el) || Dom.find(el).is(selector) === false ) {
471
- nodes = Arr.splice(nodes, index);
472
- }
473
- });
474
-
475
- return Dom.find(nodes);
476
- }
477
-
478
- not(selector)
479
- {
480
- let nodes = this.get();
481
-
482
- Arr.each(nodes, (el, index) => {
483
- if ( Any.isEmpty(el) || Dom.find(el).is(selector) === true ) {
484
- nodes = Arr.splice(nodes, index);
485
- }
486
- });
487
-
488
- return Dom.find(nodes);
489
- }
490
-
491
- prepend(val)
492
- {
493
- this.each((el) => el.prepend(val));
494
-
495
- return this;
496
- }
497
-
498
- prependTo(el)
499
- {
500
- Dom.find(el).each((val) => val.prepend(this.el));
501
-
502
- return this;
503
- }
504
-
505
- append(val)
506
- {
507
- this.each((el) => {
508
- if ( el.append !== undefined ) {
509
- el.append(val);
510
- }
511
- });
512
-
513
- return this;
514
- }
515
-
516
- appendTo(el)
517
- {
518
- Dom.find(el).each((val) => {
519
- if ( val.append !== undefined ) {
520
- val.append(this.el);
521
- }
522
- });
523
-
524
- return this;
525
- }
526
-
527
- replace(el)
528
- {
529
- // Append node to element
530
- this.parent().get(0).insertBefore(el, this.get(0));
531
-
532
- // Remove existing element
533
- this.parent().get(0).removeChild(this.get(0));
534
-
535
- return this;
536
- }
537
-
538
- previous()
539
- {
540
- if ( this.empty() === true ) {
541
- return Dom.find(null);
542
- }
543
-
544
- for (let el = this.get(0).previousSibling; el !== null; el = el.previousSibling) {
545
- if ( el.nodeType === 1 ) {
546
- return Dom.find(el);
547
- }
548
- }
549
-
550
- return Dom.find(null);
551
- }
552
-
553
- next()
554
- {
555
- if ( this.empty() === true ) {
556
- return Dom.find(null);
557
- }
558
-
559
- for (let el = this.get(0).nextSibling; el !== null; el = el.nextSibling) {
560
- if ( el.nodeType === 1 ) {
561
- return Dom.find(el);
562
- }
563
- }
564
-
565
- return Dom.find(null);
566
- }
567
-
568
- loaded(callback)
569
- {
570
- let el = this.get(0), timeout = null;
571
-
572
- if ( ! el ) {
573
- return this;
574
- }
575
-
576
- timeout = setInterval(() => {
577
-
578
- if ( ! el.complete || el.naturalWidth === 0 ) {
579
- return;
580
- }
581
-
582
- callback(el);
583
- clearInterval(timeout);
584
-
585
- }, 100);
586
-
587
- return this;
588
- }
589
-
590
- bind(event, callback)
591
- {
592
- this.each((el) => el[event] = (e) => callback.call(el, e));
593
-
594
- return this;
595
- }
596
-
597
- unbind(event)
598
- {
599
- this.each((el) => delete el[event]);
600
- }
601
-
602
- on(event, callback, options = {}, paused = false)
603
- {
604
- if ( Any.isArray(event) === true ) {
605
-
606
- Arr.each(event, (e) => {
607
- this.on(e, callback, options);
608
- });
609
-
610
- return this;
611
- }
612
-
613
- let func = (e) => {
614
- callback.call(e.target, e, e.target);
615
- };
616
-
617
- let selector = null;
618
-
619
- this.each((el) => {
620
-
621
- Dom.events = Arr.push(Dom.events, {
622
- el, event, options, selector, paused, func
623
- });
624
-
625
- el.addEventListener(event, func, options);
626
- });
627
-
628
- return this;
629
- }
630
-
631
- live(event, selector, callback, options = {}, paused = false)
632
- {
633
- if ( Any.isArray(event) === true ) {
634
-
635
- Arr.each(event, (e) => {
636
- this.live(e, selector, callback, options);
637
- });
638
-
639
- return this;
640
- }
641
-
642
- let func = (e) => {
643
-
644
- let target = e.srcElement || e.target;
645
-
646
- if ( event.match(/^(drag[a-z]*|drop$)/) ) {
647
- target = Dom.location(e.clientX, e.clientY).get(0);
648
- }
649
-
650
- if ( ! Dom.find(target).inside(selector) ) {
651
- return;
652
- }
653
-
654
- callback.call(target, e, Dom.find(target).closest(selector));
655
- };
656
-
657
- this.each((el) => {
658
-
659
- Dom.events = Arr.push(Dom.events, {
660
- el, event, options, selector, paused, func
661
- });
662
-
663
- el.addEventListener(event, func, options);
664
- });
665
-
666
- return this;
667
- }
668
-
669
- one(event, callback, options = {})
670
- {
671
- this.on(event, (e) => {
672
- callback(e); this.off(event);
673
- }, options);
674
-
675
- return this;
676
- }
677
-
678
- fire(event)
679
- {
680
- let callback = new Event(event);
681
-
682
- this.each((el) => {
683
- el.dispatchEvent(callback);
684
- });
685
-
686
- return this;
687
- }
688
-
689
- delayed(event, callback, delay = 0, options = {})
690
- {
691
- this.on(event, Any.debounce(callback, delay), options);
692
-
693
- return this;
694
- }
695
-
696
- off(event, selector = null, options = {})
697
- {
698
- if ( Any.isArray(event) === true ) {
699
-
700
- Arr.each(event, (e) => {
701
- this.off(e, selector);
702
- });
703
-
704
- return this;
705
- }
706
-
707
- this.each((el) => {
708
-
709
- let indexes = Arr.filterIndex(Dom.events, {
710
- el, event, selector, options
711
- });
712
-
713
- if ( indexes.length === 0 ) {
714
- return;
715
- }
716
-
717
- Arr.each(indexes.reverse(), (index) => {
718
-
719
- el.removeEventListener(event, Dom.events[index].func,
720
- Dom.events[index].options);
721
-
722
- Arr.removeIndex(Dom.events, index);
723
- });
724
- });
725
-
726
- return this;
727
- }
728
-
729
- unpause(event, selector = null, options = {})
730
- {
731
- if ( Any.isArray(event) === true ) {
732
-
733
- Arr.each(event, (e) => {
734
- this.unpause(e, selector, options);
735
- });
736
-
737
- return this;
738
- }
739
-
740
- this.each((el) => {
741
-
742
- let val = Arr.find(Dom.events, {
743
- el, event, selector, options
744
- });
745
-
746
- if ( val === null ) {
747
- return;
748
- }
749
-
750
- val.paused = true;
751
-
752
- el.addEventListener(event, val.func, val.options);
753
- });
754
-
755
- return this;
756
- }
757
-
758
- pause(event, selector = null, options = {})
759
- {
760
- if ( Any.isArray(event) === true ) {
761
-
762
- Arr.each(event, (e) => {
763
- this.pause(e, selector, options);
764
- });
765
-
766
- return this;
767
- }
768
-
769
- this.each((el) => {
770
-
771
- let val = Arr.find(Dom.events, {
772
- el, event, selector, options
773
- });
774
-
775
- if ( val === null ) {
776
- return;
777
- }
778
-
779
- val.paused = true;
780
-
781
- el.removeEventListener(event, val.func, val.options);
782
- });
783
-
784
- return this;
785
- }
786
-
787
- observer(callback, initial = true)
788
- {
789
- if ( initial === true ) {
790
- this.each((el) => callback(el, {}));
791
- }
792
-
793
- let observer = new MutationObserver((mutation) => {
794
- this.each((el) => callback(el, mutation));
795
- });
796
-
797
- return (el, options) => {
798
- observer.observe(Dom.find(el).get(0), options);
799
- };
800
- }
801
-
802
- observerResize(callback, initial = true)
803
- {
804
- if ( initial === true ) {
805
- this.each((el) => callback(el));
806
- }
807
-
808
- let observer = new ResizeObserver(() => {
809
- this.each((el) => callback(el));
810
- });
811
-
812
- return (el) => {
813
- observer.observe(Dom.find(el).get(0));
814
- }
815
- }
816
-
817
- data(key = undefined, val = undefined, fallback = null)
818
- {
819
- let match = Arr.find(Dom.datas, { el: this.get(0) },
820
- { el: this.get(0) });
821
-
822
- if ( key === undefined ) {
823
- return match;
824
- }
825
-
826
- if ( val === undefined ) {
827
- return Obj.get(match, key, fallback);
828
- }
829
-
830
- Arr.replace(Dom.datas, Obj.set(match, key, val),
831
- { el: this.get(0) });
832
-
833
- return this;
834
- }
835
-
836
- value(val = undefined)
837
- {
838
- if ( val === undefined ) {
839
- return this.get(0).value;
840
- }
841
-
842
- this.each((el) => el.value = val);
843
-
844
- return this;
845
- }
846
-
847
- html(html)
848
- {
849
- this.each((el) => el.innerHTML = html);
850
-
851
- return this;
852
- }
853
-
854
- computed(key = null, fallback = null)
855
- {
856
- let el = this.get(0);
857
-
858
- if ( el === null || el === window || el === document) {
859
- return key !== null ? fallback : {};
860
- }
861
-
862
- let computed = getComputedStyle(el);
863
-
864
- return key !== null ? Obj.get(computed, key, fallback) : computed;
865
- }
866
-
867
- css(vals = undefined)
868
- {
869
- if ( vals === null ) {
870
- return this.attr('style', null);
871
- }
872
-
873
- let styles = Str.objectify(this.attr('style') || '');
874
-
875
- if ( vals === undefined ) {
876
- return styles;
877
- }
878
-
879
- this.attr('style', Obj.assign({}, styles, Str.objectify(vals)));
880
- }
881
-
882
- class(vals)
883
- {
884
- if ( Any.isString(vals) ) {
885
- vals = vals.split(' ');
886
- }
887
-
888
- if ( ! Any.isArray(vals) ) {
889
- vals = [vals];
890
- }
891
-
892
- this.attr('class', vals.join(' '));
893
- }
894
-
895
- hasClass(vals)
896
- {
897
- let cls = this.attr('class') || [];
898
-
899
- if ( Any.isString(vals) ) {
900
- vals = vals.split(' ');
901
- }
902
-
903
- if ( Any.isString(cls) ) {
904
- cls = cls.split(' ');
905
- }
906
-
907
- if ( ! Any.isArray(vals) ) {
908
- vals = [vals];
909
- }
910
-
911
- if ( ! Any.isArray(cls) ) {
912
- cls = [cls];
913
- }
914
-
915
- return Arr.intersect(vals, cls).length !== 0;
916
- }
917
-
918
- addClass(vals)
919
- {
920
- if ( this.length() > 1 ) {
921
- return this.each((el) => Dom.find(el).addClass(vals));
922
- }
923
-
924
- let cls = this.attr('class') || [];
925
-
926
- if ( Any.isString(vals) ) {
927
- vals = vals.split(' ');
928
- }
929
-
930
- if ( Any.isString(cls) ) {
931
- cls = cls.split(' ');
932
- }
933
-
934
- if ( ! Any.isArray(vals) ) {
935
- vals = [vals];
936
- }
937
-
938
- if ( ! Any.isArray(cls) ) {
939
- cls = [cls];
940
- }
941
-
942
- Arr.each(vals, (val) => {
943
- Arr.add(cls, val);
944
- });
945
-
946
- this.attr('class', cls.join(' '));
947
- }
948
-
949
- removeClass(vals)
950
- {
951
- if ( this.length() > 1 ) {
952
- return this.each((el) => Dom.find(el).removeClass(vals));
953
- }
954
-
955
- let cls = this.attr('class') || [];
956
-
957
- if ( Any.isString(vals) ) {
958
- vals = vals.split(' ');
959
- }
960
-
961
- if ( Any.isString(cls) ) {
962
- cls = cls.split(' ');
963
- }
964
-
965
- if ( ! Any.isArray(vals) ) {
966
- vals = [vals];
967
- }
968
-
969
- if ( ! Any.isArray(cls) ) {
970
- cls = [cls];
971
- }
972
-
973
- Arr.each(vals, (val) => {
974
- Arr.remove(cls, val);
975
- });
976
-
977
- this.attr('class', cls.join(' '));
978
- }
979
-
980
- toggleClass(vals)
981
- {
982
- if ( this.length() > 1 ) {
983
- return this.each((el) => Dom.find(el).toggleClass(vals));
984
- }
985
-
986
- this.hasClass(vals) ? this.removeClass(vals) : this.addClass(vals);
987
-
988
- return this;
989
- }
990
-
991
- stateClass(vals, state = true)
992
- {
993
- if ( this.length() > 1 ) {
994
- return this.each((el) => Dom.find(el).stateClass(vals, state));
995
- }
996
-
997
- state ? this.addClass(vals) : this.removeClass(vals);
998
-
999
- return this;
1000
- }
1001
-
1002
- attr(attr, val = undefined)
1003
- {
1004
- if ( this.empty() ) {
1005
- return null;
1006
- }
1007
-
1008
- if ( Any.isPlain(attr) ) {
1009
- return Obj.each(attr, (value, key) =>
1010
- this.attr(key, value));
1011
- }
1012
-
1013
- let res = this.get(0).getAttribute(attr);
1014
-
1015
- if ( val === undefined ) {
1016
- return res;
1017
- }
1018
-
1019
- if ( val === null ) {
1020
- this.get(0).removeAttribute(attr);
1021
- return res;
1022
- }
1023
-
1024
- if ( Any.isPlain(val) ) {
1025
- val = Str.options(val);
1026
- }
1027
-
1028
- this.get(0).setAttribute(attr, val);
1029
- return res;
1030
- }
1031
-
1032
- actual(callback, val = null)
1033
- {
1034
- let style = this.attr('style');
1035
-
1036
- this.attr('style', val);
1037
-
1038
- let result = callback.call(this.get(0), this.get(0));
1039
-
1040
- this.attr('style', style);
1041
-
1042
- return result;
1043
- }
1044
-
1045
- loopParent(callback, target = null)
1046
- {
1047
- for (let el = this.get(0); el !== null && el.parentNode !== undefined; el = el.parentNode) {
1048
-
1049
- if ( Dom.find(el).computed('position') === 'fixed' ) {
1050
- return true;
1051
- }
1052
-
1053
- if ( Dom.find(el).is(target) === true ) {
1054
- return true;
1055
- }
1056
-
1057
- callback.call({}, el);
1058
- }
1059
-
1060
- return false;
1061
- }
1062
-
1063
- loopOffsetParent(callback, target = document.body)
1064
- {
1065
- for (let el = this.get(0); el !== null && el.offsetParent !== undefined; el = el.offsetParent) {
1066
-
1067
- if ( Dom.find(el).is(target) === true ) {
1068
- return true;
1069
- }
1070
-
1071
- callback.call({}, el);
1072
- }
1073
-
1074
- return false;
1075
- }
1076
-
1077
- offset(key = null, boundry = null)
1078
- {
1079
- let source = {
1080
- top: 0, left: 0, bottom: 0, right: 0
1081
- };
1082
-
1083
- this.loopOffsetParent((el) => {
1084
-
1085
- if ( el.offsetTop ) {
1086
- source.top += Num.float(el.offsetTop);
1087
- }
1088
-
1089
- if ( el.offsetLeft ) {
1090
- source.left += Num.float(el.offsetLeft);
1091
- }
1092
-
1093
- });
1094
-
1095
- source.bottom = Dom.find(document.body).scrollHeight() -
1096
- source.top - this.height();
1097
-
1098
- source.right = Dom.find(document.body).scrollWidth() -
1099
- source.left - this.width();
1100
-
1101
- let target = {
1102
- top: 0, left: 0, bottom: 0, right: 0
1103
- };
1104
-
1105
- Dom.find(boundry).loopOffsetParent((el) => {
1106
-
1107
- if ( el.offsetTop ) {
1108
- target.top += Num.float(el.offsetTop);
1109
- }
1110
-
1111
- if ( el.offsetLeft ) {
1112
- target.left += Num.float(el.offsetLeft);
1113
- }
1114
-
1115
- });
1116
-
1117
- target.bottom = Dom.find(document.body).scrollHeight() -
1118
- target.top - Dom.find(boundry || document.body).scrollHeight();
1119
-
1120
- target.right = Dom.find(document.body).scrollWidth() -
1121
- target.left - Dom.find(boundry || document.body).scrollWidth();
1122
-
1123
- let offset = {
1124
- top: source.top - target.top,
1125
- bottom: source.bottom - target.bottom,
1126
- left: source.left - target.left,
1127
- right: source.right - target.right
1128
- };
1129
-
1130
- return key !== null ? Obj.get(offset, key, 0) : offset;
1131
- }
1132
-
1133
- offsetTop(boundry = null)
1134
- {
1135
- return this.offset('top', boundry);
1136
- }
1137
-
1138
- offsetBottom(boundry = null)
1139
- {
1140
- return this.offset('bottom', boundry);
1141
- }
1142
-
1143
- offsetLeft(boundry = null)
1144
- {
1145
- return this.offset('left', boundry);
1146
- }
1147
-
1148
- offsetRight(boundry = null)
1149
- {
1150
- return this.offset('right', boundry);
1151
- }
1152
-
1153
- scroll(key = null, boundry = null)
1154
- {
1155
- let source = {
1156
- top: 0, left: 0
1157
- };
1158
-
1159
- this.loopParent((el) => {
1160
-
1161
- if ( el.scrollTop !== undefined ) {
1162
- source.top += Num.float(el.scrollTop);
1163
- }
1164
-
1165
- if ( el.scrollTop === undefined && el.pageYOffset !== undefined ) {
1166
- source.top += Num.float(el.pageYOffset);
1167
- }
1168
-
1169
- if ( el.scrollTop !== undefined ) {
1170
- source.left += Num.float(el.scrollLeft);
1171
- }
1172
-
1173
- if ( el.scrollTop === undefined && el.pageXOffset !== undefined ) {
1174
- source.left += Num.float(el.pageXOffset);
1175
- }
1176
-
1177
- });
1178
-
1179
- let target = {
1180
- top: 0, left: 0
1181
- };
1182
-
1183
- Dom.find(boundry).loopParent((el) => {
1184
-
1185
- if ( el.scrollTop !== undefined ) {
1186
- target.top += Num.float(el.scrollTop);
1187
- }
1188
-
1189
- if ( el.scrollTop === undefined && el.pageYOffset !== undefined ) {
1190
- target.top += Num.float(el.pageYOffset);
1191
- }
1192
-
1193
- if ( el.scrollTop !== undefined ) {
1194
- target.left += Num.float(el.scrollLeft);
1195
- }
1196
-
1197
- if ( el.scrollTop === undefined && el.pageXOffset !== undefined ) {
1198
- target.left += Num.float(el.pageXOffset);
1199
- }
1200
-
1201
- });
1202
-
1203
- let scroll = {
1204
- top: source.top - target.top,
1205
- left: source.left - target.left
1206
- };
1207
-
1208
- return key !== null ? Obj.get(scroll, key, 0) : scroll;
1209
- }
1210
-
1211
- scrollTop(val = null, boundry = null)
1212
- {
1213
- if ( val === null ) {
1214
- return this.scroll('top', boundry);
1215
- }
1216
-
1217
- this.each((el) => el.scrollTop = val);
1218
-
1219
- return this;
1220
- }
1221
-
1222
- scrollTopGlobal()
1223
- {
1224
- return this.scroll('top', document.body);
1225
- }
1226
-
1227
- scrollLeft(val = null, boundry = null)
1228
- {
1229
- if ( val === null ) {
1230
- return this.scroll('left', boundry);
1231
- }
1232
-
1233
- this.each((el) => el.scrollLeft = val);
1234
-
1235
- return this;
1236
- }
1237
-
1238
- scrollLeftGlobal()
1239
- {
1240
- return this.scroll('left', document.body);
1241
- }
1242
-
1243
- margin(key = null)
1244
- {
1245
- let computedStyle = this.computed();
1246
-
1247
- let margin = {
1248
- top: Num.float(computedStyle.marginTop),
1249
- left: Num.float(computedStyle.marginLeft),
1250
- bottom: Num.float(computedStyle.marginBottom),
1251
- right: Num.float(computedStyle.marginRight),
1252
- } ;
1253
-
1254
- return key !== null ? Obj.get(margin, key, 0) : margin;
1255
- }
1256
-
1257
- padding(key = null)
1258
- {
1259
- let computedStyle = this.computed();
1260
-
1261
- let padding = {
1262
- top: Num.float(computedStyle.paddingTop),
1263
- left: Num.float(computedStyle.paddingLeft),
1264
- bottom: Num.float(computedStyle.paddingBottom),
1265
- right: Num.float(computedStyle.paddingRight),
1266
- };
1267
-
1268
- return key !== null ? Obj.get(padding, key, 0) : padding;
1269
- }
1270
-
1271
- height()
1272
- {
1273
- let el = this.get(0);
1274
-
1275
- if ( Any.isEmpty(el) ) {
1276
- return 0;
1277
- }
1278
-
1279
- if ( el === window ) {
1280
- return el.innerHeight;
1281
- }
1282
-
1283
- return el.offsetHeight;
1284
- }
1285
-
1286
- clientHeight()
1287
- {
1288
- return Any.integer(this.computed('height', '0px').replace("px", ""));
1289
- }
1290
-
1291
- scrollHeight()
1292
- {
1293
- let el = this.get(0);
1294
-
1295
- if ( Any.isEmpty(el) ) {
1296
- return 0;
1297
- }
1298
-
1299
- return el.scrollHeight;
1300
- }
1301
-
1302
- innerHeight()
1303
- {
1304
- let el = this.get(0);
1305
-
1306
- if ( Any.isEmpty(el) ) {
1307
- return 0;
1308
- }
1309
-
1310
- return this.height() - this.padding('top') -
1311
- this.padding('bottom');
1312
- }
1313
-
1314
- realHeight(styles = {})
1315
- {
1316
- let height = 'auto';
1317
-
1318
- this.actual(() => height = this.height(), styles);
1319
-
1320
- return height;
1321
- }
1322
-
1323
- evaluateHeight(target = null, auto = true)
1324
- {
1325
- if ( Any.isString(target) ) {
1326
- target = Dom.find(target);
1327
- }
1328
-
1329
- if ( target === null ) {
1330
- target = this.parent();
1331
- }
1332
-
1333
- let height = 'auto';
1334
-
1335
- this.actual(() => {
1336
- height = target.innerHeight();
1337
- }, { display: 'none' });
1338
-
1339
- if ( auto === true ) {
1340
- this.css({ height: height + 'px' });
1341
- }
1342
-
1343
- return height;
1344
- }
1345
-
1346
- width()
1347
- {
1348
- let el = this.get(0);
1349
-
1350
- if ( Any.isEmpty(el) ) {
1351
- return 0;
1352
- }
1353
-
1354
- if ( el === window ) {
1355
- return el.innerWidth;
1356
- }
1357
-
1358
- return el.offsetWidth;
1359
- }
1360
-
1361
- clientWidth()
1362
- {
1363
- let el = this.get(0);
1364
-
1365
- if ( Any.isEmpty(el) ) {
1366
- return 0;
1367
- }
1368
-
1369
- return Any.integer(this.computed('width', '0px').replace("px", ""));
1370
- }
1371
-
1372
- scrollWidth()
1373
- {
1374
- let el = this.get(0);
1375
-
1376
- if ( Any.isEmpty(el) ) {
1377
- return 0;
1378
- }
1379
-
1380
- return el.scrollWidth;
1381
- }
1382
-
1383
- innerWidth()
1384
- {
1385
- let el = this.get(0);
1386
-
1387
- if ( Any.isEmpty(el) ) {
1388
- return 0;
1389
- }
1390
-
1391
- return this.width() - this.padding('left') -
1392
- this.padding('right');
1393
- }
1394
-
1395
- realWidth(styles = {})
1396
- {
1397
- let width = 0;
1398
-
1399
- this.actual(() => width = this.width(), styles);
1400
-
1401
- return width;
1402
- }
1403
-
1404
- evaluateWidth(target = null, auto = true)
1405
- {
1406
- if ( target === null ) {
1407
- target = this.parent();
1408
- }
1409
-
1410
- let width = 'auto';
1411
-
1412
- this.actual(() => {
1413
- width = target.innerWidth();
1414
- }, { display: 'none' });
1415
-
1416
- if ( auto === true ) {
1417
- this.css({ width: width + 'px' });
1418
- }
1419
-
1420
- return width;
1421
- }
1422
-
1423
- }
1424
-
1425
- export default Dom;