@twobirds/microcomponents 0.0.48 → 0.0.51

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 (130) hide show
  1. package/assets/Grandparent.css +13 -0
  2. package/assets/documentation/MC.md +380 -166
  3. package/assets/test.html +5 -1
  4. package/dist/MC.d.ts +1 -0
  5. package/dist/MC.d.ts.map +1 -1
  6. package/dist/MC.min.js +44 -0
  7. package/dist/MC.ts +65 -0
  8. package/dist/elements.min.js +1 -1
  9. package/dist/elements.ts +10 -10
  10. package/dist/formValues.d.ts +3 -2
  11. package/dist/formValues.d.ts.map +1 -1
  12. package/dist/formValues.ts +205 -203
  13. package/dist/formvValues.min.js +1 -1
  14. package/dist/helpers.d.ts +1 -0
  15. package/dist/helpers.d.ts.map +1 -1
  16. package/dist/helpers.ts +9 -0
  17. package/dist/microcomponents.min.js +1 -1
  18. package/dist/observables.d.ts +1 -1
  19. package/dist/observables.d.ts.map +1 -1
  20. package/dist/observables.min.js +1 -1
  21. package/dist/observables.ts +64 -31
  22. package/dist/selectors.min.js +1 -1
  23. package/dist/test.ts +8 -5
  24. package/package.json +1 -1
  25. package/public/assets/search.js +1 -1
  26. package/public/classes/MC.DC.html +13 -13
  27. package/public/classes/MC.MC.html +7 -7
  28. package/public/classes/MC.McBase.html +4 -4
  29. package/public/classes/MC.McEvent.html +13 -13
  30. package/public/classes/formValues.FormValues.html +86 -0
  31. package/public/functions/MC.addListener.html +2 -1
  32. package/public/functions/{formValues.formValues.html → MC.autoload.html} +18 -17
  33. package/public/functions/MC.removeListener.html +2 -1
  34. package/public/functions/elements.defineCE.html +1 -1
  35. package/public/functions/elements.getCE.html +1 -1
  36. package/public/functions/observables.observe.html +3 -3
  37. package/public/functions/selectors._d.html +1 -1
  38. package/public/functions/selectors._t.html +1 -1
  39. package/public/interfaces/MC.HTMLMcElement.html +2 -2
  40. package/public/interfaces/selectors.DSelector.html +55 -55
  41. package/public/interfaces/selectors.TSelector.html +37 -37
  42. package/public/modules/MC.html +3 -1
  43. package/public/modules/elements.html +1 -1
  44. package/public/modules/formValues.html +4 -4
  45. package/public/modules/observables.html +1 -1
  46. package/public/modules/selectors.html +1 -1
  47. package/public/types/observables.Observable.html +1 -1
  48. package/public/types/selectors.selection.html +1 -1
  49. package/public/types/selectors.singleSelector.html +1 -1
  50. package/src/MC.ts +65 -0
  51. package/src/elements.ts +10 -10
  52. package/src/formValues.ts +205 -203
  53. package/src/helpers.ts +9 -0
  54. package/src/observables.ts +64 -31
  55. package/src/test/Child.ts +21 -0
  56. package/src/test/Grandchild.ts +21 -0
  57. package/src/test/Grandparent.css +11 -0
  58. package/src/test/Grandparent.ts +21 -0
  59. package/src/test/Greatgrandchild.ts +42 -0
  60. package/src/test/Parent.ts +21 -0
  61. package/src/test/Testform.css +47 -0
  62. package/src/test/Testform.html +56 -0
  63. package/src/test/Testform.json +27 -0
  64. package/src/test/Testform.ts +159 -0
  65. package/src/test.ts +8 -5
  66. package/webpack.config.js +135 -61
  67. package/public/3d.html +0 -42
  68. package/public/MC.js +0 -271
  69. package/public/MC.js.map +0 -1
  70. package/public/MC.min.js +0 -407
  71. package/public/McEvent.js +0 -71
  72. package/public/McEvent.js.map +0 -1
  73. package/public/MicroComponents.svg +0 -15
  74. package/public/autoloader.js +0 -53
  75. package/public/autoloader.js.map +0 -1
  76. package/public/documentation/MC.md +0 -256
  77. package/public/documentation/ajaxian-1.png +0 -0
  78. package/public/documentation/ajaxian-2.png +0 -0
  79. package/public/documentation/ajaxian-3.png +0 -0
  80. package/public/documentation/comparision.md +0 -0
  81. package/public/documentation/elements.md +0 -276
  82. package/public/documentation/functional_requirements.md +0 -8
  83. package/public/documentation/history.md +0 -436
  84. package/public/documentation/how_tos.md +0 -0
  85. package/public/documentation/introduction.md +0 -0
  86. package/public/documentation/magic.md +0 -29
  87. package/public/documentation/proposal_draft.md +0 -37
  88. package/public/documentation/rnd0023-1.jpg +0 -0
  89. package/public/documentation/rnd0023-2.jpg +0 -0
  90. package/public/documentation/rnd0023-3.jpg +0 -0
  91. package/public/documentation/tB_react.md +0 -207
  92. package/public/documentation/usage.md +0 -142
  93. package/public/documentation/why.md +0 -25
  94. package/public/elements.js +0 -48
  95. package/public/elements.js.map +0 -1
  96. package/public/elements.min.js +0 -1
  97. package/public/fiddle/MicroComponents.svg +0 -15
  98. package/public/fiddle/fiddle.css +0 -0
  99. package/public/fiddle/fiddle.js +0 -0
  100. package/public/fiddle/index.html +0 -0
  101. package/public/formValues.js +0 -196
  102. package/public/formValues.js.map +0 -1
  103. package/public/formvValues.min.js +0 -1
  104. package/public/helpers.js +0 -105
  105. package/public/helpers.js.map +0 -1
  106. package/public/microcomponents.es3.js +0 -303
  107. package/public/microcomponents.es3.js.map +0 -1
  108. package/public/microcomponents.js +0 -9
  109. package/public/microcomponents.js.map +0 -1
  110. package/public/microcomponents.min.js +0 -1
  111. package/public/my-tag.css +0 -19
  112. package/public/observables.js +0 -239
  113. package/public/observables.js.map +0 -1
  114. package/public/observables.min.js +0 -1
  115. package/public/selectors.js +0 -971
  116. package/public/selectors.js.map +0 -1
  117. package/public/selectors.min.js +0 -1
  118. package/public/src/MC.ts +0 -413
  119. package/public/src/McEvent.ts +0 -96
  120. package/public/src/autoloader.ts +0 -98
  121. package/public/src/elements.ts +0 -76
  122. package/public/src/formValues.ts +0 -275
  123. package/public/src/helpers.ts +0 -140
  124. package/public/src/microcomponents.ts +0 -8
  125. package/public/src/observables.ts +0 -372
  126. package/public/src/selectors.ts +0 -1634
  127. package/public/src/test.ts +0 -174
  128. package/public/test.html +0 -23
  129. package/public/test.js +0 -79
  130. package/public/test.js.map +0 -1
@@ -1,971 +0,0 @@
1
- import { addListener, removeListener } from './MC.js';
2
- const isObject = (value) => {
3
- return value != null && typeof value === 'object';
4
- };
5
- const words = (classes) => {
6
- let classSet = new Set();
7
- classes.forEach(c => {
8
- c = c.trim();
9
- c.split(' ').forEach(e => {
10
- if (e !== '') {
11
- classSet.add(e);
12
- }
13
- });
14
- });
15
- classes = Array.from(classSet);
16
- return classes;
17
- };
18
- const getInputName = (e) => {
19
- let ret = e instanceof HTMLInputElement
20
- ? 'input'
21
- : e instanceof HTMLSelectElement
22
- ? 'select'
23
- : e instanceof HTMLTextAreaElement
24
- ? 'textarea'
25
- : '';
26
- return ret;
27
- };
28
- const getInputHandlers = (e) => {
29
- let inputList = $d('input,select,textarea', e).array, handlers = {};
30
- inputList.forEach((i) => {
31
- const name = i.getAttribute('name') || 'undefined';
32
- if (name) {
33
- let h;
34
- switch (getInputName(i)) {
35
- case 'input':
36
- h = new InputHandler(i, e);
37
- Object.defineProperty(handlers, name, {
38
- enumerable: true,
39
- configurable: true,
40
- get: () => { return h.val; },
41
- set: (value) => { h.val = value; }
42
- });
43
- break;
44
- case 'select':
45
- h = new SelectHandler(i);
46
- Object.defineProperty(handlers, name, {
47
- enumerable: true,
48
- configurable: true,
49
- get: () => { return h.val; },
50
- set: (value) => { h.val = value; }
51
- });
52
- break;
53
- case 'textarea':
54
- h = new TextAreaHandler(i);
55
- Object.defineProperty(handlers, name, {
56
- enumerable: true,
57
- configurable: true,
58
- get: () => { return h.val; },
59
- set: (value) => { h.val = value; }
60
- });
61
- break;
62
- default:
63
- console.warn('handler missing:', name, 'for', i);
64
- break;
65
- }
66
- }
67
- });
68
- return handlers;
69
- };
70
- class InputBase {
71
- constructor(e) {
72
- }
73
- }
74
- class InputHandler extends InputBase {
75
- #e;
76
- #type;
77
- #radioBase;
78
- constructor(e, radioBase) {
79
- super(e);
80
- this.#e = e;
81
- this.#type = e.type;
82
- this.#radioBase = radioBase;
83
- }
84
- get val() {
85
- let that = this, type = that.#type, ret;
86
- switch (type) {
87
- case 'radio':
88
- const check = $d(`input[type="radio"][name="${this.#e.getAttribute('name')}"]`, this.#radioBase)
89
- .filter(e => e.checked);
90
- if (!check.length)
91
- return '';
92
- ret = check.array[0];
93
- return ret.value;
94
- case 'checkbox':
95
- return that.#e.checked;
96
- default:
97
- return that.#e.value;
98
- break;
99
- }
100
- return '';
101
- }
102
- set val(value) {
103
- let that = this, type = that.#type, ret;
104
- switch (type) {
105
- case 'radio':
106
- const selection = `input[type="radio"][name="${this.#e.getAttribute('name')}"]`, radios = $d(selection, this.#radioBase);
107
- if (!radios.length)
108
- return;
109
- if (value === '') {
110
- radios.forEach(r => { if (r.checked)
111
- r.checked = false; });
112
- return;
113
- }
114
- const setRadioElement = radios.filter(r => r.getAttribute('value') === value);
115
- if (!setRadioElement.length)
116
- return;
117
- setRadioElement.array[0].checked = true;
118
- return;
119
- break;
120
- case 'checkbox':
121
- that.#e.checked = value;
122
- break;
123
- default:
124
- that.#e.value = value;
125
- break;
126
- }
127
- return;
128
- }
129
- }
130
- class SelectHandler extends InputBase {
131
- #e;
132
- #multi = false;
133
- constructor(e) {
134
- super(e);
135
- this.#e = e;
136
- this.#multi = e.type === 'select-multiple';
137
- }
138
- get val() {
139
- const that = this, ret = [];
140
- const options = $d(that.#e.querySelectorAll('option'))
141
- .filter(o => o.selected)
142
- .forEach(o => { if (o.selected)
143
- ret.push(o.value); });
144
- if (this.#multi)
145
- return ret;
146
- return ret.length ? ret[0] : '';
147
- }
148
- set val(value) {
149
- const that = this;
150
- value = typeof value === 'string' ? [value] : value;
151
- const options = $d(that.#e.querySelectorAll('option'))
152
- .forEach(o => {
153
- if (value.indexOf(o.value) > -1) {
154
- o.setAttribute('selected', true);
155
- o.selected = true;
156
- }
157
- else {
158
- o.removeAttribute('selected');
159
- o.selected = false;
160
- }
161
- });
162
- return;
163
- }
164
- }
165
- class TextAreaHandler extends InputBase {
166
- #e;
167
- constructor(e) {
168
- super(e);
169
- this.#e = e;
170
- }
171
- get val() {
172
- return this.#e.value;
173
- }
174
- set val(value) {
175
- this.#e.value = value;
176
- return;
177
- }
178
- }
179
- class DomSelector {
180
- #set = new Set();
181
- get set() {
182
- return this.#set;
183
- }
184
- get array() {
185
- return Array.from(this.#set);
186
- }
187
- set set(set) {
188
- this.#set = set;
189
- return;
190
- }
191
- get length() {
192
- return this.#set.size;
193
- }
194
- constructor(selection, element = document.body) {
195
- let that = this, undefinedTags = new Set();
196
- if (!selection) {
197
- return that;
198
- }
199
- }
200
- $t(nameSpace) {
201
- let result = new TbSelector();
202
- this.#set.forEach((e) => {
203
- if (e._mc) {
204
- Object.values(e._mc).forEach((mc) => {
205
- result.set.add(mc);
206
- });
207
- }
208
- });
209
- if (nameSpace) {
210
- result.filter(mc => mc.nameSpace === nameSpace);
211
- }
212
- return result;
213
- }
214
- add(selection, target) {
215
- let that = this;
216
- $d(selection, target).forEach(element => {
217
- that.#set.add(element);
218
- });
219
- return that;
220
- }
221
- addClass(...classes) {
222
- classes = words(classes);
223
- this.forEach(element => {
224
- element.classList.add(...classes);
225
- });
226
- return this;
227
- }
228
- after(selection, target) {
229
- let that = this, after = $d(selection, target);
230
- ;
231
- if (!after.length)
232
- return that;
233
- after
234
- .first()
235
- .forEach(element => {
236
- that.array.reverse().forEach((e) => {
237
- e.after(element);
238
- });
239
- });
240
- return that;
241
- }
242
- append(selection, target) {
243
- let that = this, addTo = that.array['0'], append = $d(selection, target);
244
- if (addTo) {
245
- append.forEach((e) => {
246
- addTo.append(e);
247
- });
248
- }
249
- return that;
250
- }
251
- appendTo(selection, target) {
252
- let that = this, appendTo = $d(selection, target).array['0'];
253
- if (appendTo) {
254
- that.forEach((e) => {
255
- appendTo.append(e);
256
- });
257
- }
258
- return that;
259
- }
260
- attr(first, second) {
261
- let that = this, attributes = {};
262
- if (!that.length)
263
- return that;
264
- if (!arguments.length) {
265
- Array.from([...that.set][0].attributes).forEach((attribute) => {
266
- attributes[attribute.name] = attribute.value;
267
- });
268
- return attributes;
269
- }
270
- if (typeof first === 'string') {
271
- if (second === undefined) {
272
- return [...that.set][0].getAttribute(first);
273
- }
274
- if (second === null) {
275
- [...that.set].forEach((e) => {
276
- e.removeAttribute(first);
277
- });
278
- return that;
279
- }
280
- if (typeof second === 'object') {
281
- second = JSON.stringify(second);
282
- }
283
- [...that.set].forEach((e) => {
284
- e.setAttribute(first, second);
285
- });
286
- return that;
287
- }
288
- if (typeof first === 'object') {
289
- [...that.set].forEach((e) => {
290
- Object.keys(first).forEach((key) => {
291
- $d(e).attr(key, first.key);
292
- });
293
- });
294
- return that;
295
- }
296
- return that;
297
- }
298
- before(selection, target) {
299
- let that = this, before = $d(selection, target);
300
- ;
301
- if (!before.length)
302
- return that;
303
- before
304
- .first()
305
- .forEach(element => {
306
- that.forEach((e) => {
307
- e.before(element);
308
- });
309
- });
310
- return that;
311
- }
312
- children(selection, rootNode) {
313
- let that = this, set = new Set();
314
- that.#set.forEach((e) => {
315
- Array.from(e.children).forEach((c) => {
316
- set.add(c);
317
- });
318
- });
319
- that = $d([...set]);
320
- if (selection) {
321
- let compare = $d(selection, rootNode);
322
- that.filter((e) => compare.has(e));
323
- }
324
- return that;
325
- }
326
- descendants(selection, rootNode) {
327
- let that = this, set = new Set();
328
- that.#set.forEach((e) => {
329
- e.querySelectorAll('*').forEach((h) => {
330
- set.add(h);
331
- });
332
- });
333
- that = $d([...set]);
334
- if (selection) {
335
- let compare = $d(selection, rootNode);
336
- that.filter((e) => compare.has(e));
337
- }
338
- return that;
339
- }
340
- empty() {
341
- return this.filter((e) => false);
342
- }
343
- first(selection, rootNode) {
344
- let that = this, set = new Set(), compare = false;
345
- ;
346
- if (selection) {
347
- compare = $d(selection, rootNode);
348
- }
349
- that.#set.forEach((e) => {
350
- if (e.parentNode) {
351
- set.add(e.parentNode.children[0]);
352
- }
353
- });
354
- that = $d([...set]);
355
- if (selection) {
356
- that.filter((e) => compare.has(e));
357
- }
358
- return that;
359
- }
360
- has(element) {
361
- return this.#set.has(element);
362
- }
363
- hasClass(...classes) {
364
- classes = words(classes);
365
- return this.every(e => {
366
- return Array.from(e.classList).every(c => e.contains(c));
367
- });
368
- }
369
- html(html) {
370
- let that = this;
371
- if (html) {
372
- that.forEach((e) => {
373
- !e.parentNode
374
- ? (() => {
375
- console.warn('Cannot access the .innerHTML of a HTMLElement that hasnt been inserted yet', e);
376
- console.trace(e, this);
377
- console.info('If you called this from inside a Web Component constructor, consider using the %c[connected] event callback!', 'color: blue;');
378
- })()
379
- : e.innerHTML = html;
380
- });
381
- return that;
382
- }
383
- return that.array[0].innerHTML;
384
- }
385
- last(selection, rootNode) {
386
- let that = this, set = new Set();
387
- that.#set.forEach((e) => {
388
- let siblings = e.parentNode?.children;
389
- if (siblings) {
390
- set.add(Array.from(siblings).at(-1));
391
- }
392
- });
393
- that = $d([...set]);
394
- if (selection) {
395
- let compare = $d(selection, rootNode);
396
- that.filter((e) => compare.has(e));
397
- }
398
- return that;
399
- }
400
- next(selection, rootNode) {
401
- let that = this, set = new Set();
402
- that.#set.forEach((e) => {
403
- let siblings = e.parentNode?.children;
404
- if (siblings) {
405
- let arr = Array.from(siblings), pos = arr.indexOf(e) + 1;
406
- if (pos < arr.length) {
407
- set.add(arr.at(pos));
408
- }
409
- }
410
- });
411
- that = $d([...set]);
412
- if (selection) {
413
- let compare = $d(selection, rootNode);
414
- that.filter((e) => compare.has(e));
415
- }
416
- return that;
417
- }
418
- normalize() {
419
- let that = this;
420
- that.#set.forEach((e) => { e.normalize(); });
421
- return that;
422
- }
423
- off(eventName, cb) {
424
- let that = this, eventNames = eventName.indexOf(' ') > -1
425
- ? eventName.split(' ')
426
- : [eventName];
427
- that.array.forEach((e) => {
428
- eventNames.forEach(function (n) {
429
- removeListener(e, n, cb);
430
- });
431
- });
432
- return that;
433
- }
434
- on(eventName, cb, capture = false, once = false) {
435
- let that = this, eventNames = eventName.indexOf(' ') > -1
436
- ? eventName.split(' ').filter((s) => s !== '')
437
- : [eventName];
438
- function wrapper() { wrapper.cb.apply(that, Array.from(arguments)); }
439
- ;
440
- wrapper.cb = cb;
441
- that.forEach((e) => {
442
- eventNames.forEach(function (n) {
443
- addListener(e, n, wrapper, capture, once);
444
- });
445
- });
446
- return wrapper;
447
- }
448
- one(eventName, cb, capture = false) {
449
- let that = this, eventNames = eventName.indexOf(' ') > -1
450
- ? eventName.split(' ').filter((s) => s !== '')
451
- : [eventName];
452
- function wrapper() { wrapper.cb.apply(that, Array.from(arguments)); }
453
- ;
454
- wrapper.cb = cb;
455
- that.forEach((e) => {
456
- eventNames.forEach(function (n) {
457
- addListener(e, n, wrapper, capture, true);
458
- });
459
- });
460
- return wrapper;
461
- }
462
- parent(selection, rootNode) {
463
- let that = this, set = new Set();
464
- that.#set.forEach((e) => {
465
- if (e.parentNode && e.parentNode.tagName !== 'HTML') {
466
- set.add(e.parentNode);
467
- }
468
- });
469
- that = $d([...set]);
470
- if (selection) {
471
- let compare = $d(selection, rootNode);
472
- that.filter((e) => compare.has(e));
473
- }
474
- return that;
475
- }
476
- parents(selection, rootNode) {
477
- let that = this, set = new Set();
478
- that.#set.forEach((e) => {
479
- let current = e;
480
- while (current.parentNode && current.parentNode.tagName !== 'HTML') {
481
- current = current.parentNode;
482
- set.add(current);
483
- }
484
- });
485
- that = $d([...set]);
486
- if (selection) {
487
- let compare = $d(selection, rootNode);
488
- that.filter((e) => compare.has(e));
489
- }
490
- return that;
491
- }
492
- prepend(selection, target) {
493
- let that = this, addTo = that.array['0'], prepend = $d(selection, target);
494
- if (addTo) {
495
- prepend.forEach((e) => {
496
- addTo.prepend(e);
497
- });
498
- }
499
- return that;
500
- }
501
- prev(selection, rootNode) {
502
- let that = this, set = new Set();
503
- that.#set.forEach((e) => {
504
- let siblings = e.parentNode?.children;
505
- if (siblings) {
506
- let arr = Array.from(siblings), pos = arr.indexOf(e) - 1;
507
- if (pos > -1) {
508
- set.add(arr.at(pos));
509
- }
510
- }
511
- });
512
- that = $d([...set]);
513
- if (selection) {
514
- let compare = $d(selection, rootNode);
515
- that.filter((e) => compare.has(e));
516
- }
517
- return that;
518
- }
519
- removeClass(...classes) {
520
- classes = words(classes);
521
- this.forEach(element => {
522
- element.classList.remove(...classes);
523
- });
524
- return this;
525
- }
526
- text(text) {
527
- let that = this;
528
- if (text) {
529
- that.forEach((e) => {
530
- !e.parentNode
531
- ? (() => {
532
- console.warn('Cannot access the .textContent of a HTMLElement that hasnt been inserted yet', e);
533
- console.trace(e, this);
534
- console.info('If you called this from inside a Web Component constructor, consider using the %c[connected] event callback!', 'color: blue;');
535
- })()
536
- : e.innerText = text;
537
- });
538
- return that;
539
- }
540
- let t = that.array[0].innerText;
541
- return t ?? '';
542
- }
543
- toggleClass(...classes) {
544
- classes = words(classes);
545
- this.forEach(element => {
546
- element.classList.toggle(...classes);
547
- });
548
- return this;
549
- }
550
- trigger(eventName, data = {}, bubbles = false, cancelable = false, composed = false) {
551
- let that = this, ev, options = { bubbles, cancelable, composed }, eventNames = eventName.indexOf(' ') > -1
552
- ? eventName.split(' ')
553
- : [eventName];
554
- that.#set.forEach((e) => {
555
- eventNames.forEach(function (n) {
556
- ev = new Event(n, options);
557
- ev.data = data;
558
- e.dispatchEvent(ev);
559
- });
560
- });
561
- return that;
562
- }
563
- val(p1, p2) {
564
- if (!this.length)
565
- return this;
566
- const that = this;
567
- let result, handlers = getInputHandlers(that.array[0]);
568
- if (!p1) {
569
- result = Object.assign({}, handlers);
570
- }
571
- else {
572
- if (isObject(p1)) {
573
- Object.assign(handlers, p1);
574
- result = that;
575
- }
576
- else if (typeof p1 === 'string') {
577
- if (p2 === undefined) {
578
- result = handlers[p1];
579
- }
580
- else {
581
- handlers[p1] = p2;
582
- result = that;
583
- }
584
- }
585
- }
586
- return result;
587
- }
588
- values(values) {
589
- const that = this, holder = {};
590
- let data = {};
591
- if (!that.length) {
592
- console.warn('no dom selection to search inputs in');
593
- return {};
594
- }
595
- let handlers = getInputHandlers(that.array[0]);
596
- Object.keys(handlers).forEach((key) => {
597
- data[key] = handlers[key];
598
- });
599
- if (Object.keys(data).length === 0) {
600
- console.warn('no inputs in this dom selection', that.array[0], data);
601
- }
602
- if (values) {
603
- Object
604
- .keys(values)
605
- .forEach(key => {
606
- if (handlers.hasOwnProperty(key)) {
607
- console.log('key found', key);
608
- handlers[key] = values[key];
609
- }
610
- });
611
- }
612
- return structuredClone(Object.assign(handlers));
613
- }
614
- at(index) {
615
- return $d(this.array.at(index));
616
- }
617
- concat(items) {
618
- let that = this, arr = items instanceof DomSelector
619
- ? items.array
620
- : items;
621
- arr.forEach((e) => {
622
- that.#set.add(e);
623
- });
624
- return that;
625
- }
626
- entries() {
627
- return this.array.entries();
628
- }
629
- every(predicate, thisArg) {
630
- return this.array.every(predicate, thisArg);
631
- }
632
- filter(predicate, thisArg) {
633
- this.#set = new Set(this.array.filter(predicate, thisArg));
634
- return this;
635
- }
636
- forEach(predicate, thisArg) {
637
- this.array.forEach(predicate, thisArg);
638
- return this;
639
- }
640
- includes(item) {
641
- return this.array.indexOf(item, 0) !== -1;
642
- }
643
- indexOf(item, start) {
644
- return this.array.indexOf(item, start);
645
- }
646
- map(predicate, thisArg) {
647
- return this.array.map(predicate, thisArg);
648
- }
649
- pop() {
650
- return this.array.pop();
651
- }
652
- push(...items) {
653
- items.forEach((item) => {
654
- this.#set.add(item);
655
- });
656
- return this;
657
- }
658
- shift() {
659
- let that = this, element = that.#set.size ? that.array[0] : undefined;
660
- if (element) {
661
- that.#set.delete(element);
662
- }
663
- return element;
664
- }
665
- slice(start, end) {
666
- return $d(this.array.slice(start, end));
667
- }
668
- some(predicate, thisArg) {
669
- return this.array.some(predicate, thisArg);
670
- }
671
- splice(start, deleteCount, ...items) {
672
- let that = this, arr = that.array;
673
- arr.splice(start, deleteCount, ...items);
674
- return $d(arr);
675
- }
676
- }
677
- ;
678
- class TbSelector {
679
- #set = new Set();
680
- get set() {
681
- return this.#set;
682
- }
683
- get array() {
684
- return Array.from(this.#set);
685
- }
686
- set set(set) {
687
- this.#set = set;
688
- return;
689
- }
690
- get length() {
691
- return this.#set.size;
692
- }
693
- set length(value) {
694
- }
695
- constructor(selection, element = document.body) {
696
- if (!selection) {
697
- return this;
698
- }
699
- $d(selection, element).forEach((e) => {
700
- $t(e).forEach((t) => {
701
- this.#set.add(t);
702
- });
703
- });
704
- }
705
- $d(selection, element = document.body) {
706
- let result = new DomSelector(), set = new Set(), compare = !!selection || false, compareSelection = new Set();
707
- if (compare) {
708
- compareSelection = $d(selection, element).set;
709
- }
710
- this.#set.forEach((e) => {
711
- if (!compare || compareSelection.has(e._tg)) {
712
- set.add(e._tg);
713
- }
714
- });
715
- result.set = set;
716
- return result;
717
- }
718
- children(nameSpace) {
719
- let that = this, set = new Set();
720
- that.#set.forEach((e) => {
721
- e.children(nameSpace).forEach((tb) => {
722
- set.add(tb);
723
- });
724
- });
725
- that.#set = set;
726
- return that;
727
- }
728
- descendants(nameSpace) {
729
- let that = this, set = new Set();
730
- that.#set.forEach((e) => {
731
- e.descendants(nameSpace).forEach((tb) => {
732
- set.add(tb);
733
- });
734
- });
735
- that.#set = set;
736
- return that;
737
- }
738
- first(nameSpace) {
739
- let that = this, set = new Set();
740
- that.#set.forEach((e) => {
741
- e
742
- .parent()
743
- .children()
744
- .$d()
745
- .first()
746
- .$t()
747
- .forEach((tb) => {
748
- set.add(tb);
749
- });
750
- });
751
- that.#set = set;
752
- if (nameSpace) {
753
- that.filter((tb) => tb.nameSpace = nameSpace);
754
- }
755
- return that;
756
- }
757
- has(element) {
758
- return this.#set.has(element);
759
- }
760
- last(nameSpace) {
761
- let that = this, set = new Set();
762
- that.#set.forEach((e) => {
763
- e
764
- .parent()
765
- .children()
766
- .$d()
767
- .last()
768
- .$t()
769
- .forEach((tb) => {
770
- set.add(tb);
771
- });
772
- });
773
- that.#set = set;
774
- if (nameSpace) {
775
- that.filter((e) => e.nameSpace = nameSpace);
776
- }
777
- return that;
778
- }
779
- next(nameSpace) {
780
- let that = this, set = new Set();
781
- that.#set.forEach((e) => {
782
- let elements = new Set(), element;
783
- element = e._tg;
784
- while (element.nextElementSibling !== null) {
785
- element = element.nextElementSibling;
786
- elements.add(element);
787
- }
788
- $t([...elements])
789
- .$d()
790
- .first()
791
- .$t()
792
- .forEach((tb) => {
793
- set.add(tb);
794
- });
795
- });
796
- that.#set = set;
797
- if (nameSpace) {
798
- that.filter((e) => e.nameSpace = nameSpace);
799
- }
800
- return that;
801
- }
802
- ns(nameSpace) {
803
- return this.filter((tb) => tb.nameSpace === nameSpace);
804
- }
805
- off(name, cb) {
806
- let that = this, eventNames = name.indexOf(' ') > -1
807
- ? name.split(' ').filter((s) => s !== '')
808
- : [name];
809
- that.$d().array.forEach((e) => {
810
- eventNames.forEach(function (n) {
811
- removeListener(e, `[TB]${n}`, cb);
812
- });
813
- });
814
- return that;
815
- }
816
- on(name, cb, once = false) {
817
- let that = this, eventNames = name.indexOf(' ') > -1
818
- ? name.split(' ').filter((s) => s !== '')
819
- : [name];
820
- function wrapper() { wrapper.cb.apply(that, Array.from(arguments)); }
821
- ;
822
- wrapper.cb = cb;
823
- that.forEach((tb) => {
824
- eventNames.forEach(function (n) {
825
- addListener(tb._tg, `[TB]${n}`, wrapper, false, once);
826
- });
827
- });
828
- return wrapper;
829
- }
830
- one(name, cb) {
831
- let that = this, eventNames = name.indexOf(' ') > -1
832
- ? name.split(' ').filter((s) => s !== '')
833
- : [name];
834
- function wrapper() { wrapper.cb.apply(that, Array.from(arguments)); }
835
- ;
836
- wrapper.cb = cb;
837
- that.forEach((tb) => {
838
- eventNames.forEach(function (n) {
839
- addListener(tb._tg, `[TB]${n}`, wrapper, false, true);
840
- });
841
- });
842
- return wrapper;
843
- }
844
- parent(nameSpace) {
845
- let that = this, set = new Set();
846
- that.#set.forEach((e) => {
847
- e.parent(nameSpace).forEach((tb) => {
848
- set.add(tb);
849
- });
850
- });
851
- that.#set = set;
852
- return that;
853
- }
854
- parents(nameSpace) {
855
- let that = this, set = new Set();
856
- that.#set.forEach((e) => {
857
- e.parents(nameSpace).forEach((tb) => {
858
- set.add(tb);
859
- });
860
- });
861
- that.#set = set;
862
- return that;
863
- }
864
- prev(nameSpace) {
865
- let that = this, set = new Set();
866
- that.#set.forEach((e) => {
867
- let elements = new Set(), element;
868
- element = e._tg;
869
- while (element.previousElementSibling !== null) {
870
- element = element.previousElementSibling;
871
- elements.add(element);
872
- }
873
- $t([...elements])
874
- .$d()
875
- .last()
876
- .$t()
877
- .forEach((tb) => {
878
- set.add(tb);
879
- });
880
- });
881
- that.#set = set;
882
- if (nameSpace) {
883
- that.filter((e) => e.nameSpace = nameSpace);
884
- }
885
- return that;
886
- }
887
- trigger(ev, data = {}, bubble = 'l') {
888
- let that = this;
889
- that.forEach((tb) => {
890
- tb.trigger(ev, data, bubble);
891
- });
892
- return that;
893
- }
894
- at(index) {
895
- return $t(this.array.at(index));
896
- }
897
- concat(items) {
898
- let that = this;
899
- items.forEach((tb) => {
900
- that.#set.add(tb);
901
- });
902
- return that;
903
- }
904
- entries() {
905
- return this.array.entries();
906
- }
907
- every(predicate, thisArg) {
908
- return this.array.every(predicate, thisArg);
909
- }
910
- filter(predicate, thisArg) {
911
- return $t(this.array.filter(predicate, thisArg));
912
- }
913
- forEach(predicate, thisArg) {
914
- let that = this;
915
- that.array.forEach(predicate, thisArg);
916
- return that;
917
- }
918
- includes(item) {
919
- return this.array.indexOf(item) !== -1;
920
- }
921
- indexOf(item, start) {
922
- return this.array.indexOf(item, start);
923
- }
924
- map(predicate, thisArg) {
925
- return this.array.map(predicate, thisArg);
926
- }
927
- pop() {
928
- let that = this, arr = that.array, result = arr.pop();
929
- that.#set = new Set(arr);
930
- return result;
931
- }
932
- push(item) {
933
- let that = this;
934
- that.#set.add(item);
935
- return that;
936
- }
937
- shift() {
938
- let that = this, first = this.array.shift();
939
- that.#set.delete(first);
940
- return first;
941
- }
942
- slice(start, end) {
943
- return $t(this.array.slice(start, end));
944
- }
945
- some(predicate, thisArg) {
946
- return this.array.some(predicate, thisArg);
947
- }
948
- splice(start, deleteCount, ...items) {
949
- let that = this, arr = that.array, result = arr.splice(start, deleteCount, ...items);
950
- return $t(result);
951
- }
952
- }
953
- ;
954
- export const $d = (selection, element = document) => {
955
- let set = new Set();
956
- if (selection instanceof Array) {
957
- selection.forEach(value => {
958
- $d(value, element).forEach(n => {
959
- set.add(n);
960
- });
961
- });
962
- return new DomSelector([...set]);
963
- }
964
- else {
965
- return new DomSelector(selection, element);
966
- }
967
- };
968
- export const $t = (selection, element = document) => {
969
- return $d(selection, element).$t();
970
- };
971
- //# sourceMappingURL=selectors.js.map