@twobirds/microcomponents 0.0.82 → 0.0.83

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 (233) hide show
  1. package/assets/documentation/MC.md +0 -1
  2. package/dist/MC.d.ts +3 -3
  3. package/dist/MC.d.ts.map +1 -1
  4. package/dist/MC.js +43 -74
  5. package/dist/MC.min.js +43 -74
  6. package/dist/MC.ts +67 -143
  7. package/dist/elements.d.ts +1 -1
  8. package/dist/elements.d.ts.map +1 -1
  9. package/dist/elements.js +16 -2
  10. package/dist/elements.min.js +1 -1
  11. package/dist/elements.ts +33 -3
  12. package/dist/formValues.min.js +1 -1
  13. package/dist/microcomponents.min.js +1 -1
  14. package/dist/observables.d.ts.map +1 -1
  15. package/dist/observables.js +40 -47
  16. package/dist/observables.min.js +1 -1
  17. package/dist/observables.ts +54 -59
  18. package/dist/selectors.d.ts +2 -4
  19. package/dist/selectors.d.ts.map +1 -1
  20. package/dist/selectors.js +2 -214
  21. package/dist/selectors.min.js +1 -1
  22. package/dist/selectors.ts +2 -367
  23. package/package.json +6 -5
  24. package/public/MC.d.ts +3 -3
  25. package/public/MC.d.ts.map +1 -1
  26. package/public/MC.js +43 -74
  27. package/public/MC.js.map +1 -1
  28. package/public/MC.min.js +43 -74
  29. package/public/MC.ts +67 -143
  30. package/public/documentation/MC.md +0 -1
  31. package/public/elements.d.ts +1 -1
  32. package/public/elements.d.ts.map +1 -1
  33. package/public/elements.js +16 -2
  34. package/public/elements.js.map +1 -1
  35. package/public/elements.min.js +1 -1
  36. package/public/elements.ts +33 -3
  37. package/public/formValues.min.js +1 -1
  38. package/public/microcomponents.min.js +1 -1
  39. package/public/observables.d.ts.map +1 -1
  40. package/public/observables.js +40 -47
  41. package/public/observables.js.map +1 -1
  42. package/public/observables.min.js +1 -1
  43. package/public/observables.ts +54 -59
  44. package/public/selectors.d.ts +2 -4
  45. package/public/selectors.d.ts.map +1 -1
  46. package/public/selectors.js +2 -214
  47. package/public/selectors.js.map +1 -1
  48. package/public/selectors.min.js +1 -1
  49. package/public/selectors.ts +2 -367
  50. package/public/src/MC.d.ts +36 -0
  51. package/public/src/MC.d.ts.map +1 -0
  52. package/public/src/MC.js +348 -0
  53. package/public/src/MC.js.map +1 -0
  54. package/public/src/MC.ts +67 -143
  55. package/public/src/McEvent.d.ts +15 -0
  56. package/public/src/McEvent.d.ts.map +1 -0
  57. package/public/src/McEvent.js +71 -0
  58. package/public/src/elements.d.ts +5 -0
  59. package/public/src/elements.d.ts.map +1 -0
  60. package/public/src/elements.js +62 -0
  61. package/public/src/elements.js.map +1 -0
  62. package/public/src/elements.ts +33 -3
  63. package/public/src/formValues.d.ts +3 -0
  64. package/public/src/formValues.d.ts.map +1 -0
  65. package/public/src/formValues.js +162 -0
  66. package/public/src/helpers.d.ts +14 -0
  67. package/public/src/helpers.d.ts.map +1 -0
  68. package/public/src/helpers.js +113 -0
  69. package/public/src/microcomponents.d.ts +7 -0
  70. package/public/src/microcomponents.d.ts.map +1 -0
  71. package/public/src/microcomponents.js +8 -0
  72. package/public/src/observables.d.ts +11 -0
  73. package/public/src/observables.d.ts.map +1 -0
  74. package/public/src/observables.js +242 -0
  75. package/public/src/observables.js.map +1 -0
  76. package/public/src/observables.ts +54 -59
  77. package/public/src/selectors.d.ts +106 -0
  78. package/public/src/selectors.d.ts.map +1 -0
  79. package/public/src/selectors.js +759 -0
  80. package/public/src/selectors.js.map +1 -0
  81. package/public/src/selectors.ts +2 -367
  82. package/public/src/test/grandparent.css +11 -0
  83. package/public/src/test/test/child.d.ts +2 -0
  84. package/public/src/test/test/child.d.ts.map +1 -0
  85. package/public/src/test/test/child.js +15 -0
  86. package/public/src/test/test/child.js.map +1 -0
  87. package/public/src/test/test/child.ts +21 -0
  88. package/public/src/test/test/grandchild.d.ts +2 -0
  89. package/public/src/test/test/grandchild.d.ts.map +1 -0
  90. package/public/src/test/test/grandchild.js +15 -0
  91. package/public/src/test/test/grandchild.js.map +1 -0
  92. package/public/src/test/test/grandchild.ts +21 -0
  93. package/public/src/test/test/grandparent.d.ts +2 -0
  94. package/public/src/test/test/grandparent.d.ts.map +1 -0
  95. package/public/src/test/test/grandparent.js +1 -0
  96. package/public/src/test/test/grandparent.js.map +1 -0
  97. package/public/src/test/test/grandparent.ts +21 -0
  98. package/public/src/test/test/greatgrandchild.d.ts +2 -0
  99. package/public/src/test/test/greatgrandchild.d.ts.map +1 -0
  100. package/public/src/test/test/greatgrandchild.js +29 -0
  101. package/public/src/test/test/greatgrandchild.js.map +1 -0
  102. package/public/src/test/test/greatgrandchild.ts +42 -0
  103. package/public/src/test/test/parent.d.ts +2 -0
  104. package/public/src/test/test/parent.d.ts.map +1 -0
  105. package/public/src/test/test/parent.js +15 -0
  106. package/public/src/test/test/parent.js.map +1 -0
  107. package/public/src/test/test/parent.ts +21 -0
  108. package/public/src/test/test/testform.d.ts +2 -0
  109. package/public/src/test/test/testform.d.ts.map +1 -0
  110. package/public/src/test/test/testform.js +1 -0
  111. package/public/src/test/test/testform.js.map +1 -0
  112. package/public/src/test/test/testform.ts +155 -0
  113. package/public/src/test/test/testfunction.d.ts +3 -0
  114. package/public/src/test/test/testfunction.d.ts.map +1 -0
  115. package/public/src/test/test/testfunction.js +7 -0
  116. package/public/src/test/test/testfunction.js.map +1 -0
  117. package/public/src/test/test/testfunction.ts +12 -0
  118. package/public/src/test/test/testmc.d.ts +3 -0
  119. package/public/src/test/test/testmc.d.ts.map +1 -0
  120. package/public/src/test/test/testmc.js +10 -0
  121. package/public/src/test/test/testmc.js.map +1 -0
  122. package/public/src/test/test/testmc.ts +16 -0
  123. package/public/src/test/test/testsimpleclass.d.ts +3 -0
  124. package/public/src/test/test/testsimpleclass.d.ts.map +1 -0
  125. package/public/src/test/test/testsimpleclass.js +9 -0
  126. package/public/src/test/test/testsimpleclass.js.map +1 -0
  127. package/public/src/test/test/testsimpleclass.ts +15 -0
  128. package/public/src/test/test.d.ts +2 -0
  129. package/public/src/test/test.d.ts.map +1 -0
  130. package/public/src/test/test.js +79 -0
  131. package/public/src/test/test.js.map +1 -0
  132. package/public/src/test/test.ts +188 -0
  133. package/public/src/test/testform.css +47 -0
  134. package/public/src/test/testform.html +56 -0
  135. package/public/src/test/testform.json +27 -0
  136. package/public/test/MC.d.ts +3 -3
  137. package/public/test/MC.d.ts.map +1 -1
  138. package/public/test/MC.js +43 -74
  139. package/public/test/MC.min.js +485 -0
  140. package/public/test/MC.ts +67 -143
  141. package/public/test/elements.d.ts +1 -1
  142. package/public/test/elements.d.ts.map +1 -1
  143. package/public/test/elements.js +16 -2
  144. package/public/test/elements.min.js +1 -0
  145. package/public/test/elements.ts +33 -3
  146. package/public/test/formValues.min.js +1 -0
  147. package/public/test/grandparent.css +1 -3
  148. package/public/test/microcomponents.min.js +1 -1
  149. package/public/test/observables.d.ts.map +1 -1
  150. package/public/test/observables.js +40 -47
  151. package/public/test/observables.min.js +1 -0
  152. package/public/test/observables.ts +54 -59
  153. package/public/test/selectors.d.ts +2 -4
  154. package/public/test/selectors.d.ts.map +1 -1
  155. package/public/test/selectors.js +2 -214
  156. package/public/test/selectors.min.js +1 -0
  157. package/public/test/selectors.ts +2 -367
  158. package/public/test/test/child.ts +21 -0
  159. package/public/test/test/grandchild.ts +21 -0
  160. package/public/test/test/grandparent.js +1 -1
  161. package/public/test/test/grandparent.ts +21 -0
  162. package/public/test/test/greatgrandchild.ts +42 -0
  163. package/public/test/test/parent.ts +21 -0
  164. package/public/test/test/testform.js +1 -1
  165. package/public/test/test/testform.js.map +1 -1
  166. package/public/test/test/testform.ts +155 -0
  167. package/public/test/test/testfunction.d.ts +3 -0
  168. package/public/test/test/testfunction.d.ts.map +1 -0
  169. package/public/test/test/testfunction.js +7 -0
  170. package/public/test/test/testfunction.js.map +1 -0
  171. package/public/test/test/testfunction.ts +12 -0
  172. package/public/test/test/testmc.d.ts +2 -5
  173. package/public/test/test/testmc.d.ts.map +1 -1
  174. package/public/test/test/testmc.js +4 -4
  175. package/public/test/test/testmc.js.map +1 -1
  176. package/public/test/test/testmc.ts +16 -0
  177. package/public/test/test/testsimpleclass.d.ts +3 -0
  178. package/public/test/test/testsimpleclass.d.ts.map +1 -0
  179. package/public/test/test/testsimpleclass.js +9 -0
  180. package/public/test/test/testsimpleclass.js.map +1 -0
  181. package/public/test/test/testsimpleclass.ts +15 -0
  182. package/public/test/test.js +0 -2
  183. package/public/test/test.js.map +1 -1
  184. package/public/test/test.ts +188 -0
  185. package/public/test/testform.css +47 -0
  186. package/public/test/testform.html +56 -0
  187. package/public/test/testform.json +3 -3
  188. package/public/typedoc/assets/navigation.js +1 -1
  189. package/public/typedoc/assets/search.js +1 -1
  190. package/public/typedoc/classes/MC.DC.html +5 -5
  191. package/public/typedoc/classes/MC.MC.html +5 -5
  192. package/public/typedoc/classes/MC.McBase.html +4 -3
  193. package/public/typedoc/classes/MC.McEvent.html +2 -2
  194. package/public/typedoc/functions/MC.addListener.html +1 -1
  195. package/public/typedoc/functions/MC.autoload.html +1 -1
  196. package/public/typedoc/functions/MC.removeListener.html +1 -1
  197. package/public/typedoc/functions/elements.defineCE.html +1 -1
  198. package/public/typedoc/functions/elements.getCE.html +1 -1
  199. package/public/typedoc/functions/formValues.formValues.html +1 -1
  200. package/public/typedoc/functions/observables.observe.html +1 -1
  201. package/public/typedoc/functions/selectors._d.html +1 -0
  202. package/public/typedoc/functions/selectors._t.html +1 -0
  203. package/public/typedoc/interfaces/MC.HTMLMcElement.html +2 -2
  204. package/public/typedoc/interfaces/selectors.DSelector.html +48 -0
  205. package/public/typedoc/interfaces/selectors.TSelector.html +34 -0
  206. package/public/typedoc/modules/MC.html +1 -1
  207. package/public/typedoc/modules/elements.html +1 -1
  208. package/public/typedoc/modules/formValues.html +1 -1
  209. package/public/typedoc/modules/observables.html +1 -1
  210. package/public/typedoc/modules/selectors.html +7 -0
  211. package/public/typedoc/modules.html +1 -0
  212. package/public/typedoc/types/observables.Observable.html +1 -1
  213. package/public/typedoc/types/selectors.selection.html +1 -0
  214. package/public/typedoc/types/selectors.singleSelector.html +1 -0
  215. package/src/MC.ts +67 -143
  216. package/src/elements.ts +33 -3
  217. package/src/observables.ts +54 -59
  218. package/src/selectors.ts +2 -367
  219. package/src/test/test/testform.ts +7 -3
  220. package/src/test/test/testfunction.ts +12 -0
  221. package/src/test/test/testmc.ts +13 -9
  222. package/src/test/test/testsimpleclass.ts +15 -0
  223. package/src/test/test.ts +0 -12
  224. package/tasks.md +36 -0
  225. package/typedoc.json +1 -1
  226. package/public/test/MC.js.map +0 -1
  227. package/public/test/elements.js.map +0 -1
  228. package/public/test/observables.js.map +0 -1
  229. package/public/test/selectors.js.map +0 -1
  230. /package/public/{test → src}/McEvent.js.map +0 -0
  231. /package/public/{test → src}/formValues.js.map +0 -0
  232. /package/public/{test → src}/helpers.js.map +0 -0
  233. /package/public/{test → src}/microcomponents.js.map +0 -0
@@ -0,0 +1,759 @@
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
+ class DomSelector {
19
+ #set = new Set();
20
+ get set() {
21
+ return this.#set;
22
+ }
23
+ get array() {
24
+ return Array.from(this.#set);
25
+ }
26
+ set set(set) {
27
+ this.#set = set;
28
+ return;
29
+ }
30
+ get length() {
31
+ return this.#set.size;
32
+ }
33
+ constructor(selection, element = document.body) {
34
+ let that = this, undefinedTags = new Set();
35
+ if (!selection) {
36
+ return that;
37
+ }
38
+ }
39
+ $t(nameSpace) {
40
+ let result = new TbSelector();
41
+ this.#set.forEach((e) => {
42
+ if (e._mc) {
43
+ Object.values(e._mc).forEach((mc) => {
44
+ result.set.add(mc);
45
+ });
46
+ }
47
+ });
48
+ if (nameSpace) {
49
+ result.filter(mc => mc.nameSpace === nameSpace);
50
+ }
51
+ return result;
52
+ }
53
+ add(selection, target) {
54
+ let that = this;
55
+ $d(selection, target).forEach(element => {
56
+ that.#set.add(element);
57
+ });
58
+ return that;
59
+ }
60
+ addClass(...classes) {
61
+ classes = words(classes);
62
+ this.forEach(element => {
63
+ element.classList.add(...classes);
64
+ });
65
+ return this;
66
+ }
67
+ after(selection, target) {
68
+ let that = this, after = $d(selection, target);
69
+ ;
70
+ if (!after.length)
71
+ return that;
72
+ after
73
+ .first()
74
+ .forEach(element => {
75
+ that.array.reverse().forEach((e) => {
76
+ e.after(element);
77
+ });
78
+ });
79
+ return that;
80
+ }
81
+ append(selection, target) {
82
+ let that = this, addTo = that.array['0'], append = $d(selection, target);
83
+ if (addTo) {
84
+ append.forEach((e) => {
85
+ addTo.append(e);
86
+ });
87
+ }
88
+ return that;
89
+ }
90
+ appendTo(selection, target) {
91
+ let that = this, appendTo = $d(selection, target).array['0'];
92
+ if (appendTo) {
93
+ that.forEach((e) => {
94
+ appendTo.append(e);
95
+ });
96
+ }
97
+ return that;
98
+ }
99
+ attr(first, second) {
100
+ let that = this, attributes = {};
101
+ if (!that.length)
102
+ return that;
103
+ if (!arguments.length) {
104
+ Array.from([...that.set][0].attributes).forEach((attribute) => {
105
+ attributes[attribute.name] = attribute.value;
106
+ });
107
+ return attributes;
108
+ }
109
+ if (typeof first === 'string') {
110
+ if (second === undefined) {
111
+ return [...that.set][0].getAttribute(first);
112
+ }
113
+ if (second === null) {
114
+ [...that.set].forEach((e) => {
115
+ e.removeAttribute(first);
116
+ });
117
+ return that;
118
+ }
119
+ if (typeof second === 'object') {
120
+ second = JSON.stringify(second);
121
+ }
122
+ [...that.set].forEach((e) => {
123
+ e.setAttribute(first, second);
124
+ });
125
+ return that;
126
+ }
127
+ if (typeof first === 'object') {
128
+ [...that.set].forEach((e) => {
129
+ Object.keys(first).forEach((key) => {
130
+ $d(e).attr(key, first.key);
131
+ });
132
+ });
133
+ return that;
134
+ }
135
+ return that;
136
+ }
137
+ before(selection, target) {
138
+ let that = this, before = $d(selection, target);
139
+ ;
140
+ if (!before.length)
141
+ return that;
142
+ before
143
+ .first()
144
+ .forEach(element => {
145
+ that.forEach((e) => {
146
+ e.before(element);
147
+ });
148
+ });
149
+ return that;
150
+ }
151
+ children(selection, rootNode) {
152
+ let that = this, set = new Set();
153
+ that.#set.forEach((e) => {
154
+ Array.from(e.children).forEach((c) => {
155
+ set.add(c);
156
+ });
157
+ });
158
+ that = $d([...set]);
159
+ if (selection) {
160
+ let compare = $d(selection, rootNode);
161
+ that.filter((e) => compare.has(e));
162
+ }
163
+ return that;
164
+ }
165
+ descendants(selection, rootNode) {
166
+ let that = this, set = new Set();
167
+ that.#set.forEach((e) => {
168
+ e.querySelectorAll('*').forEach((h) => {
169
+ set.add(h);
170
+ });
171
+ });
172
+ that = $d([...set]);
173
+ if (selection) {
174
+ let compare = $d(selection, rootNode);
175
+ that.filter((e) => compare.has(e));
176
+ }
177
+ return that;
178
+ }
179
+ empty() {
180
+ return this.filter((e) => false);
181
+ }
182
+ first(selection, rootNode) {
183
+ let that = this, set = new Set(), compare = false;
184
+ ;
185
+ if (selection) {
186
+ compare = $d(selection, rootNode);
187
+ }
188
+ that.#set.forEach((e) => {
189
+ if (e.parentNode) {
190
+ set.add(e.parentNode.children[0]);
191
+ }
192
+ });
193
+ that = $d([...set]);
194
+ if (selection) {
195
+ that.filter((e) => compare.has(e));
196
+ }
197
+ return that;
198
+ }
199
+ has(element) {
200
+ return this.#set.has(element);
201
+ }
202
+ hasClass(...classes) {
203
+ classes = words(classes);
204
+ return this.every(e => {
205
+ return Array.from(e.classList).every(c => e.contains(c));
206
+ });
207
+ }
208
+ html(html) {
209
+ let that = this;
210
+ if (html) {
211
+ that.forEach((e) => {
212
+ !e.parentNode
213
+ ? (() => {
214
+ console.warn('Cannot access the .innerHTML of a HTMLElement that hasnt been inserted yet', e);
215
+ console.trace(e, this);
216
+ console.info('If you called this from inside a Web Component constructor, consider using the %c[connected] event callback!', 'color: blue;');
217
+ })()
218
+ : e.innerHTML = html;
219
+ });
220
+ return that;
221
+ }
222
+ return that.array[0].innerHTML;
223
+ }
224
+ last(selection, rootNode) {
225
+ let that = this, set = new Set();
226
+ that.#set.forEach((e) => {
227
+ let siblings = e.parentNode?.children;
228
+ if (siblings) {
229
+ set.add(Array.from(siblings).at(-1));
230
+ }
231
+ });
232
+ that = $d([...set]);
233
+ if (selection) {
234
+ let compare = $d(selection, rootNode);
235
+ that.filter((e) => compare.has(e));
236
+ }
237
+ return that;
238
+ }
239
+ next(selection, rootNode) {
240
+ let that = this, set = new Set();
241
+ that.#set.forEach((e) => {
242
+ let siblings = e.parentNode?.children;
243
+ if (siblings) {
244
+ let arr = Array.from(siblings), pos = arr.indexOf(e) + 1;
245
+ if (pos < arr.length) {
246
+ set.add(arr.at(pos));
247
+ }
248
+ }
249
+ });
250
+ that = $d([...set]);
251
+ if (selection) {
252
+ let compare = $d(selection, rootNode);
253
+ that.filter((e) => compare.has(e));
254
+ }
255
+ return that;
256
+ }
257
+ normalize() {
258
+ let that = this;
259
+ that.#set.forEach((e) => { e.normalize(); });
260
+ return that;
261
+ }
262
+ off(eventName, cb) {
263
+ let that = this, eventNames = eventName.indexOf(' ') > -1
264
+ ? eventName.split(' ')
265
+ : [eventName];
266
+ that.array.forEach((e) => {
267
+ eventNames.forEach(function (n) {
268
+ removeListener(e, n, cb);
269
+ });
270
+ });
271
+ return that;
272
+ }
273
+ on(eventName, cb, capture = false, once = false) {
274
+ let that = this, eventNames = eventName.indexOf(' ') > -1
275
+ ? eventName.split(' ').filter((s) => s !== '')
276
+ : [eventName];
277
+ function wrapper() { wrapper.cb.apply(that, Array.from(arguments)); }
278
+ ;
279
+ wrapper.cb = cb;
280
+ that.forEach((e) => {
281
+ eventNames.forEach(function (n) {
282
+ addListener(e, n, wrapper, capture, once);
283
+ });
284
+ });
285
+ return wrapper;
286
+ }
287
+ one(eventName, cb, capture = false) {
288
+ let that = this, eventNames = eventName.indexOf(' ') > -1
289
+ ? eventName.split(' ').filter((s) => s !== '')
290
+ : [eventName];
291
+ function wrapper() { wrapper.cb.apply(that, Array.from(arguments)); }
292
+ ;
293
+ wrapper.cb = cb;
294
+ that.forEach((e) => {
295
+ eventNames.forEach(function (n) {
296
+ addListener(e, n, wrapper, capture, true);
297
+ });
298
+ });
299
+ return wrapper;
300
+ }
301
+ parent(selection, rootNode) {
302
+ let that = this, set = new Set();
303
+ that.#set.forEach((e) => {
304
+ if (e.parentNode && e.parentNode.tagName !== 'HTML') {
305
+ set.add(e.parentNode);
306
+ }
307
+ });
308
+ that = $d([...set]);
309
+ if (selection) {
310
+ let compare = $d(selection, rootNode);
311
+ that.filter((e) => compare.has(e));
312
+ }
313
+ return that;
314
+ }
315
+ ancestors(selection, rootNode) {
316
+ let that = this, set = new Set();
317
+ that.#set.forEach((e) => {
318
+ let current = e;
319
+ while (current.parentNode && current.parentNode.tagName !== 'HTML') {
320
+ current = current.parentNode;
321
+ set.add(current);
322
+ }
323
+ });
324
+ that = $d([...set]);
325
+ if (selection) {
326
+ let compare = $d(selection, rootNode);
327
+ that.filter((e) => compare.has(e));
328
+ }
329
+ return that;
330
+ }
331
+ prepend(selection, target) {
332
+ let that = this, addTo = that.array['0'], prepend = $d(selection, target);
333
+ if (addTo) {
334
+ prepend.forEach((e) => {
335
+ addTo.prepend(e);
336
+ });
337
+ }
338
+ return that;
339
+ }
340
+ prev(selection, rootNode) {
341
+ let that = this, set = new Set();
342
+ that.#set.forEach((e) => {
343
+ let siblings = e.parentNode?.children;
344
+ if (siblings) {
345
+ let arr = Array.from(siblings), pos = arr.indexOf(e) - 1;
346
+ if (pos > -1) {
347
+ set.add(arr.at(pos));
348
+ }
349
+ }
350
+ });
351
+ that = $d([...set]);
352
+ if (selection) {
353
+ let compare = $d(selection, rootNode);
354
+ that.filter((e) => compare.has(e));
355
+ }
356
+ return that;
357
+ }
358
+ removeClass(...classes) {
359
+ classes = words(classes);
360
+ this.forEach(element => {
361
+ element.classList.remove(...classes);
362
+ });
363
+ return this;
364
+ }
365
+ text(text) {
366
+ let that = this;
367
+ if (text) {
368
+ that.forEach((e) => {
369
+ !e.parentNode
370
+ ? (() => {
371
+ console.warn('Cannot access the .textContent of a HTMLElement that hasnt been inserted yet', e);
372
+ console.trace(e, this);
373
+ console.info('If you called this from inside a Web Component constructor, consider using the %c[connected] event callback!', 'color: blue;');
374
+ })()
375
+ : e.innerText = text;
376
+ });
377
+ return that;
378
+ }
379
+ let t = that.array[0].innerText;
380
+ return t ?? '';
381
+ }
382
+ toggleClass(...classes) {
383
+ classes = words(classes);
384
+ this.forEach(element => {
385
+ element.classList.toggle(...classes);
386
+ });
387
+ return this;
388
+ }
389
+ trigger(eventName, data = {}, bubbles = false, cancelable = false, composed = false) {
390
+ let that = this, ev, options = { bubbles, cancelable, composed }, eventNames = eventName.indexOf(' ') > -1
391
+ ? eventName.split(' ')
392
+ : [eventName];
393
+ that.#set.forEach((e) => {
394
+ eventNames.forEach(function (n) {
395
+ ev = new Event(n, options);
396
+ ev.data = data;
397
+ e.dispatchEvent(ev);
398
+ });
399
+ });
400
+ return that;
401
+ }
402
+ at(index) {
403
+ return $d(this.array.at(index));
404
+ }
405
+ concat(items) {
406
+ let that = this, arr = items instanceof DomSelector
407
+ ? items.array
408
+ : items;
409
+ arr.forEach((e) => {
410
+ that.#set.add(e);
411
+ });
412
+ return that;
413
+ }
414
+ entries() {
415
+ return this.array.entries();
416
+ }
417
+ every(predicate, thisArg) {
418
+ return this.array.every(predicate, thisArg);
419
+ }
420
+ filter(predicate, thisArg) {
421
+ this.#set = new Set(this.array.filter(predicate, thisArg));
422
+ return this;
423
+ }
424
+ forEach(predicate, thisArg) {
425
+ this.array.forEach(predicate, thisArg);
426
+ return this;
427
+ }
428
+ includes(item) {
429
+ return this.array.indexOf(item, 0) !== -1;
430
+ }
431
+ indexOf(item, start) {
432
+ return this.array.indexOf(item, start);
433
+ }
434
+ map(predicate, thisArg) {
435
+ return this.array.map(predicate, thisArg);
436
+ }
437
+ pop() {
438
+ return this.array.pop();
439
+ }
440
+ push(...items) {
441
+ items.forEach((item) => {
442
+ this.#set.add(item);
443
+ });
444
+ return this;
445
+ }
446
+ shift() {
447
+ let that = this, element = that.#set.size ? that.array[0] : undefined;
448
+ if (element) {
449
+ that.#set.delete(element);
450
+ }
451
+ return element;
452
+ }
453
+ slice(start, end) {
454
+ return $d(this.array.slice(start, end));
455
+ }
456
+ some(predicate, thisArg) {
457
+ return this.array.some(predicate, thisArg);
458
+ }
459
+ splice(start, deleteCount, ...items) {
460
+ let that = this, arr = that.array;
461
+ arr.splice(start, deleteCount, ...items);
462
+ return $d(arr);
463
+ }
464
+ }
465
+ ;
466
+ class TbSelector {
467
+ #set = new Set();
468
+ get set() {
469
+ return this.#set;
470
+ }
471
+ get array() {
472
+ return Array.from(this.#set);
473
+ }
474
+ set set(set) {
475
+ this.#set = set;
476
+ return;
477
+ }
478
+ get length() {
479
+ return this.#set.size;
480
+ }
481
+ set length(value) {
482
+ }
483
+ constructor(selection, element = document.body) {
484
+ if (!selection) {
485
+ return this;
486
+ }
487
+ $d(selection, element).forEach((e) => {
488
+ $t(e).forEach((t) => {
489
+ this.#set.add(t);
490
+ });
491
+ });
492
+ }
493
+ $d(selection, element = document.body) {
494
+ let result = new DomSelector(), set = new Set(), compare = !!selection || false, compareSelection = new Set();
495
+ if (compare) {
496
+ compareSelection = $d(selection, element).set;
497
+ }
498
+ this.#set.forEach((e) => {
499
+ if (!compare || compareSelection.has(e._tg)) {
500
+ set.add(e._tg);
501
+ }
502
+ });
503
+ result.set = set;
504
+ return result;
505
+ }
506
+ children(nameSpace) {
507
+ let that = this, set = new Set();
508
+ that.#set.forEach((e) => {
509
+ e.children(nameSpace).forEach((tb) => {
510
+ set.add(tb);
511
+ });
512
+ });
513
+ that.#set = set;
514
+ return that;
515
+ }
516
+ descendants(nameSpace) {
517
+ let that = this, set = new Set();
518
+ that.#set.forEach((e) => {
519
+ e.descendants(nameSpace).forEach((tb) => {
520
+ set.add(tb);
521
+ });
522
+ });
523
+ that.#set = set;
524
+ return that;
525
+ }
526
+ first(nameSpace) {
527
+ let that = this, set = new Set();
528
+ that.#set.forEach((e) => {
529
+ e
530
+ .parent()
531
+ .children()
532
+ .$d()
533
+ .first()
534
+ .$t()
535
+ .forEach((tb) => {
536
+ set.add(tb);
537
+ });
538
+ });
539
+ that.#set = set;
540
+ if (nameSpace) {
541
+ that.filter((tb) => tb.nameSpace = nameSpace);
542
+ }
543
+ return that;
544
+ }
545
+ has(element) {
546
+ return this.#set.has(element);
547
+ }
548
+ last(nameSpace) {
549
+ let that = this, set = new Set();
550
+ that.#set.forEach((e) => {
551
+ e
552
+ .parent()
553
+ .children()
554
+ .$d()
555
+ .last()
556
+ .$t()
557
+ .forEach((tb) => {
558
+ set.add(tb);
559
+ });
560
+ });
561
+ that.#set = set;
562
+ if (nameSpace) {
563
+ that.filter((e) => e.nameSpace = nameSpace);
564
+ }
565
+ return that;
566
+ }
567
+ next(nameSpace) {
568
+ let that = this, set = new Set();
569
+ that.#set.forEach((e) => {
570
+ let elements = new Set(), element;
571
+ element = e._tg;
572
+ while (element.nextElementSibling !== null) {
573
+ element = element.nextElementSibling;
574
+ elements.add(element);
575
+ }
576
+ $t([...elements])
577
+ .$d()
578
+ .first()
579
+ .$t()
580
+ .forEach((tb) => {
581
+ set.add(tb);
582
+ });
583
+ });
584
+ that.#set = set;
585
+ if (nameSpace) {
586
+ that.filter((e) => e.nameSpace = nameSpace);
587
+ }
588
+ return that;
589
+ }
590
+ ns(nameSpace) {
591
+ return this.filter((tb) => tb.nameSpace === nameSpace);
592
+ }
593
+ off(name, cb) {
594
+ let that = this, eventNames = name.indexOf(' ') > -1
595
+ ? name.split(' ').filter((s) => s !== '')
596
+ : [name];
597
+ that.$d().array.forEach((e) => {
598
+ eventNames.forEach(function (n) {
599
+ removeListener(e, `[TB]${n}`, cb);
600
+ });
601
+ });
602
+ return that;
603
+ }
604
+ on(name, cb, once = false) {
605
+ let that = this, eventNames = name.indexOf(' ') > -1
606
+ ? name.split(' ').filter((s) => s !== '')
607
+ : [name];
608
+ function wrapper() { wrapper.cb.apply(that, Array.from(arguments)); }
609
+ ;
610
+ wrapper.cb = cb;
611
+ that.forEach((tb) => {
612
+ eventNames.forEach(function (n) {
613
+ addListener(tb._tg, `[TB]${n}`, wrapper, false, once);
614
+ });
615
+ });
616
+ return wrapper;
617
+ }
618
+ one(name, cb) {
619
+ let that = this, eventNames = name.indexOf(' ') > -1
620
+ ? name.split(' ').filter((s) => s !== '')
621
+ : [name];
622
+ function wrapper() { wrapper.cb.apply(that, Array.from(arguments)); }
623
+ ;
624
+ wrapper.cb = cb;
625
+ that.forEach((tb) => {
626
+ eventNames.forEach(function (n) {
627
+ addListener(tb._tg, `[TB]${n}`, wrapper, false, true);
628
+ });
629
+ });
630
+ return wrapper;
631
+ }
632
+ parent(nameSpace) {
633
+ let that = this, set = new Set();
634
+ that.#set.forEach((e) => {
635
+ e.parent(nameSpace).forEach((tb) => {
636
+ set.add(tb);
637
+ });
638
+ });
639
+ that.#set = set;
640
+ return that;
641
+ }
642
+ ancestors(nameSpace) {
643
+ let that = this, set = new Set();
644
+ that.#set.forEach((e) => {
645
+ e.parents(nameSpace).forEach((tb) => {
646
+ set.add(tb);
647
+ });
648
+ });
649
+ that.#set = set;
650
+ return that;
651
+ }
652
+ prev(nameSpace) {
653
+ let that = this, set = new Set();
654
+ that.#set.forEach((e) => {
655
+ let elements = new Set(), element;
656
+ element = e._tg;
657
+ while (element.previousElementSibling !== null) {
658
+ element = element.previousElementSibling;
659
+ elements.add(element);
660
+ }
661
+ $t([...elements])
662
+ .$d()
663
+ .last()
664
+ .$t()
665
+ .forEach((tb) => {
666
+ set.add(tb);
667
+ });
668
+ });
669
+ that.#set = set;
670
+ if (nameSpace) {
671
+ that.filter((e) => e.nameSpace = nameSpace);
672
+ }
673
+ return that;
674
+ }
675
+ trigger(ev, data = {}, bubble = 'l') {
676
+ let that = this;
677
+ that.forEach((tb) => {
678
+ tb.trigger(ev, data, bubble);
679
+ });
680
+ return that;
681
+ }
682
+ at(index) {
683
+ return $t(this.array.at(index));
684
+ }
685
+ concat(items) {
686
+ let that = this;
687
+ items.forEach((tb) => {
688
+ that.#set.add(tb);
689
+ });
690
+ return that;
691
+ }
692
+ entries() {
693
+ return this.array.entries();
694
+ }
695
+ every(predicate, thisArg) {
696
+ return this.array.every(predicate, thisArg);
697
+ }
698
+ filter(predicate, thisArg) {
699
+ return $t(this.array.filter(predicate, thisArg));
700
+ }
701
+ forEach(predicate, thisArg) {
702
+ let that = this;
703
+ that.array.forEach(predicate, thisArg);
704
+ return that;
705
+ }
706
+ includes(item) {
707
+ return this.array.indexOf(item) !== -1;
708
+ }
709
+ indexOf(item, start) {
710
+ return this.array.indexOf(item, start);
711
+ }
712
+ map(predicate, thisArg) {
713
+ return this.array.map(predicate, thisArg);
714
+ }
715
+ pop() {
716
+ let that = this, arr = that.array, result = arr.pop();
717
+ that.#set = new Set(arr);
718
+ return result;
719
+ }
720
+ push(item) {
721
+ let that = this;
722
+ that.#set.add(item);
723
+ return that;
724
+ }
725
+ shift() {
726
+ let that = this, first = this.array.shift();
727
+ that.#set.delete(first);
728
+ return first;
729
+ }
730
+ slice(start, end) {
731
+ return $t(this.array.slice(start, end));
732
+ }
733
+ some(predicate, thisArg) {
734
+ return this.array.some(predicate, thisArg);
735
+ }
736
+ splice(start, deleteCount, ...items) {
737
+ let that = this, arr = that.array, result = arr.splice(start, deleteCount, ...items);
738
+ return $t(result);
739
+ }
740
+ }
741
+ ;
742
+ export const $d = (selection, element = document) => {
743
+ let set = new Set();
744
+ if (selection instanceof Array) {
745
+ selection.forEach(value => {
746
+ $d(value, element).forEach(n => {
747
+ set.add(n);
748
+ });
749
+ });
750
+ return new DomSelector([...set]);
751
+ }
752
+ else {
753
+ return new DomSelector(selection, element);
754
+ }
755
+ };
756
+ export const $t = (selection, element = document) => {
757
+ return $d(selection, element).$t();
758
+ };
759
+ //# sourceMappingURL=selectors.js.map