@twobirds/microcomponents 0.0.20 → 0.0.22

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 (122) hide show
  1. package/.gitlab-ci.yml +1 -0
  2. package/README.md +33 -14
  3. package/assets/documentation/MicroComponents.md +228 -0
  4. package/assets/my-tag.css +4 -0
  5. package/assets/test.html +5 -1
  6. package/dist/MC.d.ts +32 -0
  7. package/dist/MC.d.ts.map +1 -0
  8. package/dist/MC.min.js +414 -0
  9. package/dist/MC.ts +350 -0
  10. package/dist/MCbundle.d.ts +8 -0
  11. package/dist/MCbundle.d.ts.map +1 -0
  12. package/dist/MCbundle.min.js +1 -0
  13. package/dist/MCbundle.ts +8 -0
  14. package/dist/McEvent.d.ts +15 -0
  15. package/dist/McEvent.d.ts.map +1 -0
  16. package/dist/McEvent.ts +96 -0
  17. package/dist/autoloader.d.ts +2 -0
  18. package/dist/autoloader.d.ts.map +1 -0
  19. package/dist/autoloader.ts +98 -0
  20. package/dist/customElements.d.ts +5 -0
  21. package/dist/customElements.d.ts.map +1 -0
  22. package/dist/customElements.min.js +1 -0
  23. package/dist/customElements.ts +67 -0
  24. package/dist/customObservables.d.ts +3 -0
  25. package/dist/customObservables.d.ts.map +1 -0
  26. package/dist/customObservables.min.js +1 -0
  27. package/dist/customObservables.ts +340 -0
  28. package/dist/customSelectors.d.ts +108 -0
  29. package/dist/customSelectors.d.ts.map +1 -0
  30. package/dist/customSelectors.min.js +1 -0
  31. package/dist/customSelectors.ts +1634 -0
  32. package/dist/formValues.d.ts +4 -0
  33. package/dist/formValues.d.ts.map +1 -0
  34. package/dist/formValues.ts +275 -0
  35. package/dist/formvValues.min.js +1 -0
  36. package/dist/helpers.d.ts +11 -0
  37. package/dist/helpers.d.ts.map +1 -0
  38. package/dist/helpers.ts +173 -0
  39. package/dist/microcomponents.es3.d.ts +1 -20
  40. package/dist/microcomponents.es3.d.ts.map +1 -1
  41. package/dist/test.d.ts +2 -0
  42. package/dist/test.d.ts.map +1 -0
  43. package/package.json +11 -7
  44. package/public/MC.js +273 -0
  45. package/public/MC.min.js +414 -0
  46. package/public/MCbundle.js +8 -0
  47. package/public/MCbundle.min.js +1 -0
  48. package/public/McEvent.js +74 -0
  49. package/public/MicroComponents.svg +15 -0
  50. package/public/assets/search.js +1 -1
  51. package/public/autoloader.js +57 -0
  52. package/public/classes/MC.DC.html +247 -0
  53. package/public/classes/MC.MC.html +150 -0
  54. package/public/classes/MC.McBase.html +123 -0
  55. package/public/classes/MCbundle.McEvent.html +184 -0
  56. package/public/customElements.js +48 -0
  57. package/public/customElements.min.js +1 -0
  58. package/public/customObservables.js +255 -0
  59. package/public/customObservables.min.js +1 -0
  60. package/public/customSelectors.js +1088 -0
  61. package/public/customSelectors.min.js +1 -0
  62. package/public/documentation/MicroComponents.md +228 -0
  63. package/public/formValues.js +211 -0
  64. package/public/formvValues.min.js +1 -0
  65. package/public/functions/MC.addListener.html +73 -0
  66. package/public/functions/MC.removeListener.html +69 -0
  67. package/public/functions/MCbundle._d.html +85 -0
  68. package/public/functions/MCbundle._t.html +85 -0
  69. package/public/functions/MCbundle.debounce.html +85 -0
  70. package/public/functions/MCbundle.deepEqual.html +85 -0
  71. package/public/functions/MCbundle.defineCE.html +98 -0
  72. package/public/functions/MCbundle.formValues.html +89 -0
  73. package/public/functions/MCbundle.getCE.html +83 -0
  74. package/public/functions/MCbundle.htmlToElements.html +83 -0
  75. package/public/functions/MCbundle.isObject.html +83 -0
  76. package/public/functions/MCbundle.kebabToPascal.html +83 -0
  77. package/public/functions/MCbundle.makeCO.html +85 -0
  78. package/public/functions/MCbundle.nameSpace.html +89 -0
  79. package/public/functions/MCbundle.parse.html +85 -0
  80. package/public/helpers.js +128 -0
  81. package/public/index.html +22 -13
  82. package/public/interfaces/MC.HTMLMcElement.html +3605 -0
  83. package/public/interfaces/MCbundle.DSelector.html +1010 -0
  84. package/public/interfaces/MCbundle.LooseObject.html +80 -0
  85. package/public/interfaces/MCbundle.TSelector.html +709 -0
  86. package/public/microcomponents.es3.js +348 -0
  87. package/public/modules/MC.html +84 -0
  88. package/public/modules/MCbundle.html +133 -0
  89. package/public/modules.html +4 -4
  90. package/public/my-tag.css +4 -0
  91. package/public/test.html +5 -1
  92. package/public/test.js +100 -202
  93. package/public/types/MCbundle.selection.html +74 -0
  94. package/public/types/MCbundle.singleSelector.html +74 -0
  95. package/src/MC.ts +350 -0
  96. package/src/MCbundle.ts +8 -0
  97. package/src/McEvent.ts +96 -0
  98. package/src/autoloader.ts +98 -0
  99. package/src/customElements.ts +67 -0
  100. package/src/customObservables.ts +340 -0
  101. package/src/customSelectors.ts +1634 -0
  102. package/src/formValues.ts +275 -0
  103. package/src/helpers.ts +173 -0
  104. package/src/microcomponents.es3.js +353 -82
  105. package/src/test.js +137 -218
  106. package/tsconfig.json +2 -2
  107. package/typedoc.json +1 -1
  108. package/webpack.config.js +233 -0
  109. package/dist/microcomponents.d.ts +0 -26
  110. package/dist/microcomponents.d.ts.map +0 -1
  111. package/dist/microcomponents.es3.js +0 -96
  112. package/dist/microcomponents.es3.min.js +0 -15
  113. package/dist/microcomponents.js +0 -176
  114. package/dist/microcomponents.min.js +0 -38
  115. package/dist/microcomponents.ts +0 -216
  116. package/public/classes/microcomponents.MC.html +0 -313
  117. package/public/classes/microcomponents_es3.MC.html +0 -336
  118. package/public/functions/microcomponents_es3.__isEmpty.html +0 -60
  119. package/public/microcomponents.js +0 -176
  120. package/public/modules/microcomponents.html +0 -57
  121. package/public/modules/microcomponents_es3.html +0 -60
  122. package/src/microcomponents.ts +0 -216
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+
3
+ import { DC } from './MC.js';
4
+ import { kebabToPascal } from './helpers.js';
5
+
6
+ class CeBaseClass extends HTMLElement {
7
+ constructor() {
8
+ super();
9
+ }
10
+
11
+ connectedCallback() {
12
+ (DC as any).trigger(this, 'Connected');
13
+ }
14
+
15
+ disconnectedCallback() {
16
+ (DC as any).trigger(this, 'Disconnected');
17
+ }
18
+
19
+ adoptedCallback() {
20
+ (DC as any).trigger(this, 'Adopted');
21
+ }
22
+
23
+ attributeChangedCallback(name: string, oldValue: any, newValue: any) {
24
+ (DC as any).trigger(this, 'AttributeChanged', { name, oldValue, newValue });
25
+ }
26
+ }
27
+
28
+ function createNamedClass(name: string, ClassBody: { new (...args: any[]): any } ) {
29
+ return Object.defineProperty( ClassBody, 'name', { value: name });
30
+ }
31
+
32
+ export function defineCE( tagName: string, DefinitionClass: { new (...args: any[]): any }, observedAttributes: string[] = []){
33
+ if (customElements.get(tagName)) {
34
+ console.warn(`IGNORED: Custom element "${tagName}" is already defined!`);
35
+ return;
36
+ }
37
+
38
+ if (!tagName.includes('-')) {
39
+ throw new Error('createCustomElement: tagName must contain at least one hyphen ("-").');
40
+ }
41
+
42
+ let name = kebabToPascal(tagName);
43
+
44
+ customElements.define(
45
+ tagName,
46
+ createNamedClass(
47
+ name,
48
+ class extends CeBaseClass {
49
+ instance: any;
50
+
51
+ constructor( data?: any ) {
52
+ super();
53
+ let instance = new DefinitionClass(this, data);
54
+ ( DC as any ).add(this, name, instance );
55
+ }
56
+
57
+ static get observedAttributes() {
58
+ return observedAttributes;
59
+ }
60
+ }
61
+ )
62
+ );
63
+ };
64
+
65
+ export function getCE(tagName: string): CustomElementConstructor | undefined {
66
+ return customElements.get(tagName);
67
+ }
@@ -0,0 +1,3 @@
1
+ import { LooseObject } from './helpers.js';
2
+ export declare const makeCO: (target: LooseObject, propertyName?: string) => void;
3
+ //# sourceMappingURL=customObservables.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"customObservables.d.ts","sourceRoot":"","sources":["../src/customObservables.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAG3C,eAAO,MAAM,MAAM,WAAa,WAAW,iBAAiB,MAAM,SA8UjE,CAAA"}
@@ -0,0 +1 @@
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.customObservables=t():e.customObservables=t()}(this,(()=>(()=>{"use strict";var e={d:(t,r)=>{for(var o in r)e.o(r,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:r[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function r(e){return null!=e&&"object"==typeof e}function o(e,t){let r;return()=>{clearTimeout(r),r=setTimeout((function(){e(...arguments)}),t)}}function n(e,t){const o=Object.keys(e),c=Object.keys(t);if(o.length!==c.length)return!1;for(const c of o){const o=e[c],a=t[c],u=r(o)&&r(a);if(u&&!n(o,a)||!u&&o!==a)return!1}return!0}function c(e,t,o=null,n){let a=e.split(".");n||(n=t);let u=a.shift(),s=a.join(".");null!==o&&u.length&&void 0===t[u]&&(t[u]={});let l=t[u];return 0===s.length?null!==o?(t[u]=o,n):t[u]:r(t[u])?c(s,t[u],o,n):o?n:l[u]}function a(e,t){var o=Array.from(arguments);if(o.length){if(1===o.length)return o[1];if(o.length>2){for(;o.length>1;)o[0]=a(o[0],o[1]),o.splice(1,1);return o[0]}if("string"==typeof e){var n=e.match(/\{[^\{\}]*\}/g);n&&n.forEach((function(r){var o=c(r.substr(1,r.length-2),t);void 0!==o&&(e=e.replace(r,o))}))}else if(r(e))switch(e.constructor){case Object:Object.keys(e).forEach((function(r){e.hasOwnProperty(r)&&(e[r]=a(e[r],t))}));break;case Array:e.forEach((function(r,o,n){n[o]=a(e[o],t)}))}return e}console.error("no arguments give to parse")}e.r(t),e.d(t,{makeCO:()=>u});const u=(e,t)=>{(t?[t]:[...Object.getOwnPropertyNames(e)]).forEach((t=>{if("_"===t[0]||void 0===e?.[t])return;let c,u=e[t];if(!u.prototype)switch(typeof u){case"string":c=String;break;case"number":c=Number;break;case"boolean":c=Boolean;break;case"object":c=u instanceof Array?Array:Object;break;default:return}let s=class extends c{constructor(e){super(e),this.constructor.callbacks=[],r(e)&&(this.constructor.bound=[],Object.getOwnPropertyNames(e).forEach((t=>{this[t]=e[t]})))}observe(e){return this.constructor.callbacks.push(e),this}bind(e){const t=this,o=r(t.valueOf()),n=t.constructor.bound;if(o){function c(e){if(e.nodeType&&3===e.nodeType){var r=Array.from(e.nodeValue&&e.nodeValue.match(/\{[^\{\}]*\}/g)||[]);if(r.length>0){var u=(s=e.nodeValue||"",function(t){var n,c=!1;return r&&(o?r.forEach((function(e){u.values[e]!==t[e]&&(u.values[e]=t[e],c=!0)})):(u.values=t,c=!0)),c&&(n=s,e.nodeValue=o?a(n,u.values):n.replace(/\{.*\}/g,u.values)),t});u.values=o?{}:void 0,r=Array.from(r).map((e=>e.replace(/[\{\}]/g,"").trim()));let t=o?{}:void 0;r.forEach((function(e){o&&(t[e]="")})),n.push(u)}Array.from(e.childNodes).forEach((function(e){c(e)})),t.notify()}var s;e.nodeType&&1===e.nodeType&&(Array.from(e.attributes).forEach((function(t){var r=Array.from(t.value&&t.value.match(/\{[^\{\}]*\}/g)||[]);if(r.length>0){var o=function(t){return function(n){var c,u=!1;return r&&r.forEach((function(e){o.values[e]!==n[e]&&(o.values[e]=n[e],u=!0)})),u&&(c=t,e.nodeValue=a(c,o.values)),n}}(t.value||"");o.values={},r=Array.from(r).map((e=>e.replace(/[\{\}]/g,"").trim()));let c={};r.forEach((function(e){c[e]=""})),n.push(o)}})),Array.from(e.childNodes).forEach((function(e){c(e)})),t.notify()),e.nodeType&&11===e.nodeType&&Array.from(e.childNodes).forEach((function(e){c(e)}))}c(e),n.length>0&&t.notify()}else console.warn("IGNORED - cannot bind a non-Object to the dom, IS:",typeof t.valueOf());return this}notify(){let e=this,t=r(e.valueOf())&&e.valueOf()instanceof Array==0?structuredClone(Object.assign({},e)):e.valueOf();return e.constructor.callbacks.forEach((e=>{e(t)})),r(e.valueOf())&&e.constructor.bound.forEach((e=>{e(t)})),this}},l=new s(u);Object.defineProperty(e,t,{enumerable:!0,get(){if(r(l.valueOf())){let e=structuredClone(Object.assign({},l));setTimeout(o((function(){n(structuredClone(Object.assign({},l)),e)||l.notify()}),0),0)}return l},set(e){if(typeof e==typeof l.valueOf())if(r(l.valueOf())&&l.valueOf()instanceof Array==0){let t=structuredClone(Object.assign({},l));e=structuredClone(Object.assign({},e));let r=l.constructor?.hasFormHandler??!1,c=l.constructor.callbacks,a=l.constructor.bound;l=new s(structuredClone(Object.assign({},e))),l.constructor.callbacks=r,l.constructor.callbacks=c,l.constructor.bound=a,setTimeout(o((function(){n(structuredClone(Object.assign({},l)),t)||l.notify()}),0),0)}else{let t=l.valueOf(),r=l.constructor.callbacks;l=new s(e),l.constructor.callbacks=r,e!==t&&l.notify()}else console.warn("IGNORED - cannot change observable types, IS:",typeof l.valueOf(),"- CANNOT BECOME:",typeof e)}}),e[t]=u}))};return t})()));
@@ -0,0 +1,340 @@
1
+ "use strict";
2
+
3
+ import { LooseObject } from './helpers.js';
4
+ import { isObject, parse, debounce, deepEqual } from './helpers.js';
5
+
6
+ export const makeCO = ( target: LooseObject, propertyName?: string ) => {
7
+
8
+ let keys = !propertyName ? [ ...Object.getOwnPropertyNames(target) ] : [ propertyName ];
9
+
10
+ keys.forEach( (key) => {
11
+ // console.log( 'co propname', key, typeof target[key], target[key] );
12
+ if ( key[0] === '_' || target?.[key] === undefined ) return;
13
+ let
14
+ val: any = target[key],
15
+ Constructor: any
16
+ ;
17
+
18
+ if ( !val.prototype ){
19
+ switch ( typeof val ){
20
+ case "string":
21
+ Constructor = String;
22
+ break;
23
+ case "number":
24
+ Constructor = Number;
25
+ break;
26
+ case "boolean":
27
+ Constructor = Boolean;
28
+ break;
29
+ case "object":
30
+ if ( val instanceof Array){
31
+ Constructor = Array;
32
+ } else {
33
+ Constructor = Object;
34
+ }
35
+ break;
36
+ default:
37
+ return;
38
+ }
39
+
40
+ }
41
+
42
+ let Observable = class extends Constructor{
43
+
44
+ constructor( val: any ){
45
+ super( val );
46
+ (this.constructor as LooseObject).callbacks = [];
47
+ if ( isObject(val) ){ // you cannot bind native values to the dom
48
+ (this.constructor as LooseObject).bound = [];
49
+ Object.getOwnPropertyNames( val ).forEach( (key) => {
50
+ this[key] = val[key];
51
+ });
52
+ }
53
+ }
54
+
55
+ observe( f: Function ){
56
+ //console.log('observe');
57
+ (this.constructor as any).callbacks.push( f );
58
+ return this;
59
+ }
60
+
61
+ bind( target: HTMLElement | ShadowRoot ){
62
+
63
+ const
64
+ that = this,
65
+ iso = isObject( that.valueOf() ),
66
+ bound = (that.constructor as any).bound
67
+ ;
68
+
69
+ //console.log('bind', iso, target);
70
+
71
+ if ( iso ){
72
+ // console.log('bind...', that.valueOf(), target );
73
+
74
+ function walk( element: Node ){
75
+ //console.log('-walk:', element, element.childNodes );
76
+
77
+ if ( !!element['nodeType'] && element.nodeType === 3 ){ // text node
78
+ //console.log('--type: textNode(3)');
79
+
80
+ var placeholders = Array.from( element.nodeValue && element.nodeValue.match( /\{[^\{\}]*\}/g ) || []);
81
+
82
+ if ( placeholders.length > 0 ){
83
+ //console.log('--placeholders:', placeholders);
84
+ var f=(function( template: string ){
85
+ //console.log('template', template);
86
+ return function( values: any ){
87
+ var t,
88
+ changed = false;
89
+
90
+ //console.log( 'placeholders:', placeholders, 'values:', values);
91
+ if ( placeholders ){
92
+ if ( iso ){
93
+ placeholders.forEach(function(placeholder){
94
+ if ( ( f as LooseObject).values[placeholder] !== values[placeholder] ){
95
+ (f as LooseObject).values[placeholder] = values[placeholder];
96
+ changed = true;
97
+ }
98
+ });
99
+ } else { // it is a simple value
100
+ (f as LooseObject).values = values;
101
+ changed = true;
102
+ };
103
+ }
104
+ if (changed){ // only reflow if changed
105
+ t = template;
106
+ //console.log('--template parse', t, (f as LooseObject).values );
107
+ if ( iso ){
108
+ element.nodeValue = parse(
109
+ t,
110
+ (f as LooseObject).values
111
+ );
112
+ } else { // it is a simple value -> replace every placeholder whatever the name wi
113
+ element.nodeValue = t.replace( /\{.*\}/g ,(f as LooseObject).values );
114
+ };
115
+ }
116
+ return values;
117
+ };
118
+ })( element.nodeValue || '' );
119
+
120
+ (f as LooseObject).values = iso ? {} : undefined;
121
+ placeholders = Array.from( placeholders ).map((pKey) => pKey.replace(/[\{\}]/g, '').trim());
122
+
123
+ let initial: any = iso ? {} : undefined;
124
+ placeholders.forEach(function(pKey){
125
+ if ( iso ){
126
+ initial[pKey] = "";
127
+ }
128
+ });
129
+
130
+ bound.push(f);
131
+ // console.log( `--bound textNode`, placeholders, f );
132
+ //(observableFunction as Function)(initial);
133
+ }
134
+
135
+ //console.log('--childNodes:', element.childNodes );
136
+ Array.from( element.childNodes )
137
+ .forEach(function( childNode ){
138
+ walk( childNode );
139
+ });
140
+
141
+ that.notify();
142
+ }
143
+
144
+ if ( !!element['nodeType'] && element.nodeType === 1 ){ // HTML element
145
+ //console.log('--type: HTMLElement(1)');
146
+ Array.from( (element as HTMLElement).attributes )
147
+ .forEach(
148
+ function( attributeNode ){
149
+ var placeholders = Array.from( attributeNode.value && attributeNode.value.match( /\{[^\{\}]*\}/g ) || []);
150
+
151
+ if ( placeholders.length > 0 ){
152
+ //console.log( `--[${attributeNode.value}] placeholders:`, placeholders );
153
+
154
+ var f=(function( template: string ){
155
+ return function( values: any ){
156
+ var t,
157
+ changed = false;
158
+
159
+ //console.log( 'placeholders:', placeholders, 'values:', values);
160
+ if ( placeholders ){
161
+ placeholders.forEach(function(pKey){
162
+ if ( ( f as LooseObject).values[pKey] !== values[pKey] ){
163
+ (f as LooseObject).values[pKey] = values[pKey];
164
+ changed = true;
165
+ }
166
+ });
167
+ }
168
+ if (changed){ // only reflow if changed
169
+ t = template;
170
+ element.nodeValue = parse(
171
+ t,
172
+ (f as LooseObject).values
173
+ );
174
+ }
175
+ return values;
176
+ };
177
+ })( attributeNode.value || '' );
178
+
179
+ (f as LooseObject).values = {};
180
+ placeholders = Array.from( placeholders ).map((pKey) => pKey.replace(/[\{\}]/g, '').trim());
181
+ let initial: LooseObject = {};
182
+ placeholders.forEach(function(pKey){
183
+ initial[pKey] = "";
184
+ });
185
+
186
+ bound.push(f);
187
+ // console.log( `--bound element attribute`, placeholders, f );
188
+ // console.log( `--bound`, observableFunction.bound );
189
+ //(observableFunction as Function)(initial);
190
+ }
191
+ }
192
+ );
193
+
194
+ //console.log('--childNodes:', element.childNodes );
195
+ Array.from( element.childNodes )
196
+ .forEach(function( childNode ){
197
+ walk( childNode );
198
+ });
199
+
200
+ that.notify();
201
+
202
+ }
203
+
204
+ if ( !!element['nodeType'] && element.nodeType === 11 ){ // shadowRoot node
205
+ // console.log( element, element.childNodes );
206
+ Array.from( element.childNodes )
207
+ .forEach(function( childNode ){
208
+ walk( childNode );
209
+ });
210
+ }
211
+ }
212
+
213
+ walk( target );
214
+
215
+ if ( bound.length > 0 ){
216
+ that.notify();
217
+ }
218
+ } else {
219
+ console.warn( 'IGNORED - cannot bind a non-Object to the dom, IS:', typeof that.valueOf() );
220
+ }
221
+
222
+ return this;
223
+ }
224
+
225
+ notify(){
226
+ let
227
+ that = this,
228
+ data = isObject( that.valueOf() ) && ( that.valueOf() instanceof Array ) === false
229
+ ? structuredClone( Object.assign({}, that) )
230
+ : that.valueOf()
231
+ ;
232
+
233
+ // console.log('notify', that.constructor, (that.constructor as any).callbacks.length, (that.constructor as any)?.bound?.length, data );
234
+ (that.constructor as any).callbacks.forEach( (f: Function) => {
235
+ // console.log( 'callback', f, data);
236
+ f( data );
237
+ });
238
+ if ( isObject( that.valueOf() ) ){
239
+ // console.log('bound', this.constructor);
240
+ (that.constructor as any).bound.forEach( (f: Function) => {
241
+ // console.log( 'bound', f, data);
242
+ f( data );
243
+ });
244
+ }
245
+ return this;
246
+ }
247
+ }
248
+
249
+ //(Observable.constructor as LooseObject).callbacks = [];
250
+ let o = new Observable( val );
251
+
252
+ Object.defineProperty(
253
+ target,
254
+ key,
255
+ {
256
+ enumerable: true,
257
+ get(){
258
+ if ( isObject( o.valueOf() ) ){
259
+ let check = structuredClone( Object.assign( {}, o ) );
260
+ setTimeout(
261
+ debounce(
262
+ function checkChanges(){
263
+ let state = structuredClone( Object.assign( {}, o ) );
264
+ //console.log( 'check changes', state, check );
265
+ if ( !deepEqual( state, check ) ){
266
+ //console.log( '-> not equal!' );
267
+ o.notify();
268
+ }
269
+ },
270
+ 0
271
+ ),
272
+ 0
273
+ );
274
+ }
275
+ return o;
276
+ },
277
+ set( val: any ){
278
+ //console.log( 'SET:', isObject( val.valueOf() ), 'set:', val, 'to', isObject( o.valueOf() ), o, );
279
+ if ( typeof val === typeof o.valueOf() ){
280
+
281
+ let iso = isObject( o.valueOf() ) && ( o.valueOf() instanceof Array ) === false;
282
+ //let iso = o.constructor.prototype.__proto__.constructor === Object;
283
+ //console.log('target iso:', iso);
284
+ if ( iso ){
285
+ let
286
+ old = structuredClone( Object.assign( {}, o ) )
287
+ ;
288
+
289
+ val = structuredClone( Object.assign( {}, val ) );
290
+
291
+ let
292
+ hasFormHandler = (o.constructor as LooseObject)?.hasFormHandler ?? false,
293
+ callbacks = (o.constructor as LooseObject).callbacks,
294
+ bound = (o.constructor as LooseObject).bound
295
+ ;
296
+
297
+ o = new Observable( structuredClone( Object.assign( {}, val ) ) );
298
+
299
+ //console.log('after set o=', o, 'check', old);
300
+ (o.constructor as LooseObject).callbacks = hasFormHandler;
301
+ (o.constructor as LooseObject).callbacks = callbacks;
302
+ (o.constructor as LooseObject).bound = bound;
303
+
304
+ setTimeout( // check for changes
305
+ debounce(
306
+ function checkChanges(){
307
+ let state = structuredClone( Object.assign( {}, o ) );
308
+ //console.log( 'check changes', state, check );
309
+ if ( !deepEqual( state, old ) ){
310
+ //console.log( '-> not equal!' );
311
+ o.notify();
312
+ }
313
+ },
314
+ 0
315
+ ),
316
+ 0
317
+ );
318
+ } else { // simple native var
319
+ let
320
+ old = o.valueOf(),
321
+ callbacks = (o.constructor as LooseObject).callbacks
322
+ ;
323
+ o = new Observable( val );
324
+ (o.constructor as LooseObject).callbacks = callbacks;
325
+ if ( val !== old ){
326
+ o.notify();
327
+ }
328
+ }
329
+ } else {
330
+ console.warn( 'IGNORED - cannot change observable types, IS:', typeof o.valueOf(), '- CANNOT BECOME:', typeof val );
331
+ }
332
+ }
333
+ }
334
+ );
335
+
336
+ target[key] = val;
337
+
338
+ });
339
+
340
+ }
@@ -0,0 +1,108 @@
1
+ import { MC, DC } from './MC.js';
2
+ import { LooseObject } from './helpers.js';
3
+ declare class DomSelector {
4
+ #private;
5
+ get set(): Set<HTMLElement>;
6
+ get array(): HTMLElement[];
7
+ set set(set: Set<HTMLElement>);
8
+ get length(): number;
9
+ constructor(selection?: selection, element?: any);
10
+ $t(nameSpace?: string): TSelector;
11
+ add(selection: selection, target?: HTMLElement): DSelector;
12
+ addClass(...classes: string[]): DSelector;
13
+ after(selection: selection, target?: HTMLElement): DSelector;
14
+ append(selection: selection, target?: HTMLElement): DSelector;
15
+ appendTo(selection: selection, target?: HTMLElement): DSelector;
16
+ attr(): LooseObject;
17
+ attr(obj: LooseObject): DSelector;
18
+ attr(name: string): string | null;
19
+ attr(first?: string | LooseObject, second?: string | object | null): DSelector;
20
+ before(selection: selection, target?: HTMLElement): DSelector;
21
+ children(selection?: selection, rootNode?: HTMLElement): DSelector;
22
+ descendants(selection?: selection, rootNode?: HTMLElement): DSelector;
23
+ empty(): DSelector;
24
+ first(selection?: selection, rootNode?: HTMLElement): DSelector;
25
+ has(element: HTMLElement): boolean;
26
+ hasClass(...classes: string[]): boolean;
27
+ html(html?: string): string | DSelector;
28
+ last(selection?: selection, rootNode?: HTMLElement): DSelector;
29
+ next(selection?: selection, rootNode?: HTMLElement): DSelector;
30
+ normalize(): DSelector;
31
+ off(eventName: string, cb: Function): DSelector;
32
+ on(eventName: string, cb: Function, capture?: boolean, once?: boolean): Function;
33
+ one(eventName: string, cb: Function, capture?: boolean): Function;
34
+ parent(selection?: selection, rootNode?: HTMLElement): DSelector;
35
+ parents(selection?: selection, rootNode?: HTMLElement): DSelector;
36
+ prepend(selection: selection, target?: HTMLElement): DSelector;
37
+ prev(selection?: selection, rootNode?: HTMLElement): DSelector;
38
+ removeClass(...classes: string[]): DSelector;
39
+ text(text?: string): string | DSelector;
40
+ toggleClass(...classes: string[]): DSelector;
41
+ trigger(eventName: string, data?: any, bubbles?: boolean, cancelable?: boolean, composed?: boolean): DSelector;
42
+ val(p1?: any, p2?: any): any;
43
+ values(values?: LooseObject): LooseObject;
44
+ at(index: number): DSelector;
45
+ concat(items: DSelector | any[]): DSelector;
46
+ entries(): IterableIterator<[number, any]>;
47
+ every(predicate: (value: any, index: number, array: any[]) => unknown, thisArg?: any): boolean;
48
+ filter(predicate: (value: any, index: number, array: any[]) => unknown, thisArg?: any): DSelector;
49
+ forEach(predicate: (value: any, index: number, array: any[]) => unknown, thisArg?: any): DSelector;
50
+ includes(item: HTMLElement): boolean;
51
+ indexOf(item: HTMLElement, start?: number): number;
52
+ map(predicate: (value: any, index: number, array: any[]) => unknown, thisArg?: any): Array<any>;
53
+ pop(): HTMLElement;
54
+ push(...items: HTMLElement[]): DSelector;
55
+ shift(): HTMLElement | undefined;
56
+ slice(start: number, end?: number): DSelector;
57
+ some(predicate: (value: any, index: number, array: any[]) => unknown, thisArg?: any): boolean;
58
+ splice(start: number, deleteCount?: number | undefined): DSelector;
59
+ }
60
+ export interface DSelector extends DomSelector {
61
+ }
62
+ declare class TbSelector {
63
+ #private;
64
+ get set(): Set<any>;
65
+ get array(): any[];
66
+ set set(set: Set<any>);
67
+ get length(): number;
68
+ set length(value: number);
69
+ constructor(selection?: selection, element?: HTMLElement);
70
+ $d(selection?: selection, element?: HTMLElement): DSelector;
71
+ children(nameSpace?: string): TSelector;
72
+ descendants(nameSpace?: string): TSelector;
73
+ first(nameSpace?: string): TSelector;
74
+ has(element: any): boolean;
75
+ last(nameSpace?: string): TSelector;
76
+ next(nameSpace?: string): TSelector;
77
+ ns(nameSpace: string): TSelector;
78
+ off(name: string, cb: Function): TSelector;
79
+ on(name: string, cb: Function, once?: boolean): Function;
80
+ one(name: string, cb: Function): Function;
81
+ parent(nameSpace?: string): TSelector;
82
+ parents(nameSpace?: string): TSelector;
83
+ prev(nameSpace?: string): TSelector;
84
+ trigger(ev: string, data?: any, bubble?: string): TSelector;
85
+ at(index: number): TSelector;
86
+ concat(items: TSelector): TSelector;
87
+ entries(): IterableIterator<[number, any]>;
88
+ every(predicate: (value: any, index: number, array: any[]) => unknown, thisArg?: any): boolean;
89
+ filter(predicate: (value: any, index: number, array: any[]) => unknown, thisArg?: any): TSelector;
90
+ forEach(predicate: (value: any, index: number, array: any[]) => unknown, thisArg?: any): TSelector;
91
+ includes(item: any): boolean;
92
+ indexOf(item: any, start?: number): number;
93
+ map(predicate: (value: any, index: number, array: any[]) => unknown, thisArg?: any): Array<any>;
94
+ pop(): any;
95
+ push(item: any): TSelector;
96
+ shift(): any | undefined;
97
+ slice(start: number, end?: number): TSelector;
98
+ some(predicate: (value: any, index: number, array: any[]) => unknown, thisArg?: any): boolean;
99
+ splice(start: number, deleteCount?: number | undefined): TSelector;
100
+ }
101
+ export interface TSelector extends TbSelector {
102
+ }
103
+ export declare const $d: (selection: selection, element?: any) => DSelector;
104
+ export declare const $t: (selection?: selection, element?: any) => TSelector;
105
+ export type singleSelector = string | ShadowRoot | HTMLElement | HTMLElement[] | HTMLCollection | NodeList | DSelector | MC | DC | TSelector | undefined;
106
+ export type selection = singleSelector | singleSelector[];
107
+ export {};
108
+ //# sourceMappingURL=customSelectors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"customSelectors.d.ts","sourceRoot":"","sources":["../src/customSelectors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,EAAE,EAA8C,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAqR3C,cAAM,WAAW;;IAIhB,IAAW,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,CAEjC;IAED,IAAW,KAAK,IAAI,WAAW,EAA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0 +1 @@
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.customSelectors=t():e.customSelectors=t()}(this,(()=>(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{$d:()=>E,$t:()=>m});var r=new Function("try {return this===window;}catch(e){ return false;}");let n=new Set;r()&&Object.keys(HTMLElement.prototype).filter((e=>/^on/.test(e))).forEach((e=>n.add(e)));var a=new Function("try {return this===window;}catch(e){ return false;}");let s=new Set;function i(e,t,r,n=!1,a=!1){let s={once:!1};n&&(s.capture=n),a&&(s.once=a),e.addEventListener(t,r,s)}function o(e,t,r){e.removeEventListener(t,r)}a()&&Object.keys(HTMLElement.prototype).filter((e=>/^on/.test(e))).forEach((e=>s.add(e)));const c=e=>{let t=new Set;return e.forEach((e=>{(e=e.trim()).split(" ").forEach((e=>{""!==e&&t.add(e)}))})),Array.from(t)},l=e=>{let t=E("input,select,textarea",e).array,r={};return t.forEach((t=>{const n=t.getAttribute("name")||"undefined";if(n){let a;switch((e=>e instanceof HTMLInputElement?"input":e instanceof HTMLSelectElement?"select":e instanceof HTMLTextAreaElement?"textarea":"")(t)){case"input":a=new f(t,e),Object.defineProperty(r,n,{enumerable:!0,configurable:!0,get:()=>a.val,set:e=>{a.val=e}});break;case"select":a=new u(t),Object.defineProperty(r,n,{enumerable:!0,configurable:!0,get:()=>a.val,set:e=>{a.val=e}});break;case"textarea":a=new d(t),Object.defineProperty(r,n,{enumerable:!0,configurable:!0,get:()=>a.val,set:e=>{a.val=e}});break;default:console.warn("handler missing:",n,"for",t)}}})),r};class h{constructor(e){}}class f extends h{#e;#t;#r;constructor(e,t){super(e),this.#e=e,this.#t=e.type,this.#r=t}get val(){let e,t=this;switch(t.#t){case"radio":const r=E(`input[type="radio"][name="${this.#e.getAttribute("name")}"]`,this.#r).filter((e=>e.checked));return r.length?(e=r.array[0],e.value):"";case"checkbox":return t.#e.checked;default:return t.#e.value}return""}set val(e){let t=this;switch(t.#t){case"radio":const r=`input[type="radio"][name="${this.#e.getAttribute("name")}"]`,n=E(r,this.#r);if(!n.length)return;if(""===e)return void n.forEach((e=>{e.checked&&(e.checked=!1)}));const a=n.filter((t=>t.getAttribute("value")===e));if(!a.length)return;return void(a.array[0].checked=!0);case"checkbox":t.#e.checked=e;break;default:t.#e.value=e}}}class u extends h{#e;#n=!1;constructor(e){super(e),this.#e=e,this.#n="select-multiple"===e.type}get val(){const e=[];return E(this.#e.querySelectorAll("option")).filter((e=>e.selected)).forEach((t=>{t.selected&&e.push(t.value)})),this.#n?e:e.length?e[0]:""}set val(e){e="string"==typeof e?[e]:e,E(this.#e.querySelectorAll("option")).forEach((t=>{e.indexOf(t.value)>-1?(t.setAttribute("selected",!0),t.selected=!0):(t.removeAttribute("selected"),t.selected=!1)}))}}class d extends h{#e;constructor(e){super(e),this.#e=e}get val(){return this.#e.value}set val(e){this.#e.value=e}}class p{#a=new Set;get set(){return this.#a}get array(){return Array.from(this.#a)}set set(e){this.#a=e}get length(){return this.#a.size}constructor(e,t=document.body){if(new Set,!e)return this}$t(e){let t=new y;return this.#a.forEach((e=>{e._mc&&Object.values(e._mc).forEach((e=>{t.set.add(e)}))})),e&&t.filter((t=>t.nameSpace===e)),t}add(e,t){let r=this;return E(e,t).forEach((e=>{r.#a.add(e)})),r}addClass(...e){return e=c(e),this.forEach((t=>{t.classList.add(...e)})),this}after(e,t){let r=this,n=E(e,t);return n.length?(n.first().forEach((e=>{r.array.reverse().forEach((t=>{t.after(e)}))})),r):r}append(e,t){let r=this.array[0],n=E(e,t);return r&&n.forEach((e=>{r.append(e)})),this}appendTo(e,t){let r=E(e,t).array[0];return r&&this.forEach((e=>{r.append(e)})),this}attr(e,t){let r=this,n={};return r.length?arguments.length?"string"==typeof e?void 0===t?[...r.set][0].getAttribute(e):null===t?([...r.set].forEach((t=>{t.removeAttribute(e)})),r):("object"==typeof t&&(t=JSON.stringify(t)),[...r.set].forEach((r=>{r.setAttribute(e,t)})),r):"object"==typeof e?([...r.set].forEach((t=>{Object.keys(e).forEach((r=>{E(t).attr(r,e.key)}))})),r):r:(Array.from([...r.set][0].attributes).forEach((e=>{n[e.name]=e.value})),n):r}before(e,t){let r=this,n=E(e,t);return n.length?(n.first().forEach((e=>{r.forEach((t=>{t.before(e)}))})),r):r}children(e,t){let r=this,n=new Set;if(r.#a.forEach((e=>{Array.from(e.children).forEach((e=>{n.add(e)}))})),r=E([...n]),e){let n=E(e,t);r.filter((e=>n.has(e)))}return r}descendants(e,t){let r=this,n=new Set;if(r.#a.forEach((e=>{e.querySelectorAll("*").forEach((e=>{n.add(e)}))})),r=E([...n]),e){let n=E(e,t);r.filter((e=>n.has(e)))}return r}empty(){return this.filter((e=>!1))}first(e,t){let r=this,n=new Set,a=!1;return e&&(a=E(e,t)),r.#a.forEach((e=>{e.parentNode&&n.add(e.parentNode.children[0])})),r=E([...n]),e&&r.filter((e=>a.has(e))),r}has(e){return this.#a.has(e)}hasClass(...e){return e=c(e),this.every((e=>Array.from(e.classList).every((t=>e.contains(t)))))}html(e){let t=this;return e?(t.forEach((t=>{t.parentNode?t.innerHTML=e:(()=>{console.warn("Cannot access the .innerHTML of a HTMLElement that hasnt been inserted yet",t),console.trace(t,this),console.info("If you called this from inside a Web Component constructor, consider using the %c[connected] event callback!","color: blue;")})()})),t):t.array[0].innerHTML}last(e,t){let r=this,n=new Set;if(r.#a.forEach((e=>{let t=e.parentNode?.children;t&&n.add(Array.from(t).at(-1))})),r=E([...n]),e){let n=E(e,t);r.filter((e=>n.has(e)))}return r}next(e,t){let r=this,n=new Set;if(r.#a.forEach((e=>{let t=e.parentNode?.children;if(t){let r=Array.from(t),a=r.indexOf(e)+1;a<r.length&&n.add(r.at(a))}})),r=E([...n]),e){let n=E(e,t);r.filter((e=>n.has(e)))}return r}normalize(){return this.#a.forEach((e=>{e.normalize()})),this}off(e,t){let r=e.indexOf(" ")>-1?e.split(" "):[e];return this.array.forEach((e=>{r.forEach((function(r){o(e,r,t)}))})),this}on(e,t,r=!1,n=!1){let a=this,s=e.indexOf(" ")>-1?e.split(" ").filter((e=>""!==e)):[e];function o(){o.cb.apply(a,Array.from(arguments))}return o.cb=t,a.forEach((e=>{s.forEach((function(t){i(e,t,o,r,n)}))})),o}one(e,t,r=!1){let n=this,a=e.indexOf(" ")>-1?e.split(" ").filter((e=>""!==e)):[e];function s(){s.cb.apply(n,Array.from(arguments))}return s.cb=t,n.forEach((e=>{a.forEach((function(t){i(e,t,s,r,!0)}))})),s}parent(e,t){let r=this,n=new Set;if(r.#a.forEach((e=>{e.parentNode&&"HTML"!==e.parentNode.tagName&&n.add(e.parentNode)})),r=E([...n]),e){let n=E(e,t);r.filter((e=>n.has(e)))}return r}parents(e,t){let r=this,n=new Set;if(r.#a.forEach((e=>{let t=e;for(;t.parentNode&&"HTML"!==t.parentNode.tagName;)t=t.parentNode,n.add(t)})),r=E([...n]),e){let n=E(e,t);r.filter((e=>n.has(e)))}return r}prepend(e,t){let r=this.array[0],n=E(e,t);return r&&n.forEach((e=>{r.prepend(e)})),this}prev(e,t){let r=this,n=new Set;if(r.#a.forEach((e=>{let t=e.parentNode?.children;if(t){let r=Array.from(t),a=r.indexOf(e)-1;a>-1&&n.add(r.at(a))}})),r=E([...n]),e){let n=E(e,t);r.filter((e=>n.has(e)))}return r}removeClass(...e){return e=c(e),this.forEach((t=>{t.classList.remove(...e)})),this}text(e){let t=this;return e?(t.forEach((t=>{t.parentNode?t.innerText=e:(()=>{console.warn("Cannot access the .textContent of a HTMLElement that hasnt been inserted yet",t),console.trace(t,this),console.info("If you called this from inside a Web Component constructor, consider using the %c[connected] event callback!","color: blue;")})()})),t):t.array[0].innerText??""}toggleClass(...e){return e=c(e),this.forEach((t=>{t.classList.toggle(...e)})),this}trigger(e,t={},r=!1,n=!1,a=!1){let s,i={bubbles:r,cancelable:n,composed:a},o=e.indexOf(" ")>-1?e.split(" "):[e];return this.#a.forEach((e=>{o.forEach((function(r){s=new Event(r,i),s.data=t,e.dispatchEvent(s)}))})),this}val(e,t){if(!this.length)return this;const r=this;let n,a=l(r.array[0]);var s;return e?null!=(s=e)&&"object"==typeof s?(Object.assign(a,e),n=r):"string"==typeof e&&(void 0===t?n=a[e]:(a[e]=t,n=r)):n=Object.assign({},a),n}values(e){const t=this;let r={};if(!t.length)return console.warn("no dom selection to search inputs in"),{};let n=l(t.array[0]);return Object.keys(n).forEach((e=>{r[e]=n[e]})),0===Object.keys(r).length&&console.warn("no inputs in this dom selection",t.array[0],r),e&&Object.keys(e).forEach((t=>{n.hasOwnProperty(t)&&(console.log("key found",t),n[t]=e[t])})),structuredClone(Object.assign(n))}at(e){return E(this.array.at(e))}concat(e){let t=this;return(e instanceof p?e.array:e).forEach((e=>{t.#a.add(e)})),t}entries(){return this.array.entries()}every(e,t){return this.array.every(e,t)}filter(e,t){return this.#a=new Set(this.array.filter(e,t)),this}forEach(e,t){return this.array.forEach(e,t),this}includes(e){return-1!==this.array.indexOf(e,0)}indexOf(e,t){return this.array.indexOf(e,t)}map(e,t){return this.array.map(e,t)}pop(){return this.array.pop()}push(...e){return e.forEach((e=>{this.#a.add(e)})),this}shift(){let e=this,t=e.#a.size?e.array[0]:void 0;return t&&e.#a.delete(t),t}slice(e,t){return E(this.array.slice(e,t))}some(e,t){return this.array.some(e,t)}splice(e,t,...r){let n=this.array;return n.splice(e,t,...r),E(n)}}class y{#a=new Set;get set(){return this.#a}get array(){return Array.from(this.#a)}set set(e){this.#a=e}get length(){return this.#a.size}set length(e){}constructor(e,t=document.body){if(!e)return this;E(e,t).forEach((e=>{m(e).forEach((e=>{this.#a.add(e)}))}))}$d(e,t=document.body){let r=new p,n=new Set,a=!!e||!1,s=new Set;return a&&(s=E(e,t).set),this.#a.forEach((e=>{a&&!s.has(e._tg)||n.add(e._tg)})),r.set=n,r}children(e){let t=this,r=new Set;return t.#a.forEach((t=>{t.children(e).forEach((e=>{r.add(e)}))})),t.#a=r,t}descendants(e){let t=this,r=new Set;return t.#a.forEach((t=>{t.descendants(e).forEach((e=>{r.add(e)}))})),t.#a=r,t}first(e){let t=this,r=new Set;return t.#a.forEach((e=>{e.parent().children().$d().first().$t().forEach((e=>{r.add(e)}))})),t.#a=r,e&&t.filter((t=>t.nameSpace=e)),t}has(e){return this.#a.has(e)}last(e){let t=this,r=new Set;return t.#a.forEach((e=>{e.parent().children().$d().last().$t().forEach((e=>{r.add(e)}))})),t.#a=r,e&&t.filter((t=>t.nameSpace=e)),t}next(e){let t=this,r=new Set;return t.#a.forEach((e=>{let t,n=new Set;for(t=e._tg;null!==t.nextElementSibling;)t=t.nextElementSibling,n.add(t);m([...n]).$d().first().$t().forEach((e=>{r.add(e)}))})),t.#a=r,e&&t.filter((t=>t.nameSpace=e)),t}ns(e){return this.filter((t=>t.nameSpace===e))}off(e,t){let r=e.indexOf(" ")>-1?e.split(" ").filter((e=>""!==e)):[e];return this.$d().array.forEach((e=>{r.forEach((function(r){o(e,`[TB]${r}`,t)}))})),this}on(e,t,r=!1){let n=this,a=e.indexOf(" ")>-1?e.split(" ").filter((e=>""!==e)):[e];function s(){s.cb.apply(n,Array.from(arguments))}return s.cb=t,n.forEach((e=>{a.forEach((function(t){i(e._tg,`[TB]${t}`,s,!1,r)}))})),s}one(e,t){let r=this,n=e.indexOf(" ")>-1?e.split(" ").filter((e=>""!==e)):[e];function a(){a.cb.apply(r,Array.from(arguments))}return a.cb=t,r.forEach((e=>{n.forEach((function(t){i(e._tg,`[TB]${t}`,a,!1,!0)}))})),a}parent(e){let t=this,r=new Set;return t.#a.forEach((t=>{t.parent(e).forEach((e=>{r.add(e)}))})),t.#a=r,t}parents(e){let t=this,r=new Set;return t.#a.forEach((t=>{t.parents(e).forEach((e=>{r.add(e)}))})),t.#a=r,t}prev(e){let t=this,r=new Set;return t.#a.forEach((e=>{let t,n=new Set;for(t=e._tg;null!==t.previousElementSibling;)t=t.previousElementSibling,n.add(t);m([...n]).$d().last().$t().forEach((e=>{r.add(e)}))})),t.#a=r,e&&t.filter((t=>t.nameSpace=e)),t}trigger(e,t={},r="l"){return this.forEach((n=>{n.trigger(e,t,r)})),this}at(e){return m(this.array.at(e))}concat(e){let t=this;return e.forEach((e=>{t.#a.add(e)})),t}entries(){return this.array.entries()}every(e,t){return this.array.every(e,t)}filter(e,t){return m(this.array.filter(e,t))}forEach(e,t){return this.array.forEach(e,t),this}includes(e){return-1!==this.array.indexOf(e)}indexOf(e,t){return this.array.indexOf(e,t)}map(e,t){return this.array.map(e,t)}pop(){let e=this.array,t=e.pop();return this.#a=new Set(e),t}push(e){return this.#a.add(e),this}shift(){let e=this.array.shift();return this.#a.delete(e),e}slice(e,t){return m(this.array.slice(e,t))}some(e,t){return this.array.some(e,t)}splice(e,t,...r){let n=this.array.splice(e,t,...r);return m(n)}}const E=(e,t=document)=>{let r=new Set;return e instanceof Array?(e.forEach((e=>{E(e,t).forEach((e=>{r.add(e)}))})),new p([...r])):new p(e,t)},m=(e,t=document)=>E(e,t).$t();return t})()));