@twobirds/microcomponents 0.0.26 → 0.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/MC.d.ts +4 -1
- package/dist/MC.d.ts.map +1 -1
- package/dist/MC.min.js +74 -37
- package/dist/MC.ts +95 -51
- package/dist/customElements.min.js +1 -1
- package/dist/microcomponents.min.js +1 -1
- package/dist/test.ts +0 -3
- package/package.json +1 -1
- package/public/MC.js +74 -37
- package/public/MC.js.map +1 -1
- package/public/MC.min.js +74 -37
- package/public/assets/search.js +1 -1
- package/public/classes/DC.html +40 -54
- package/public/classes/MC.html +42 -23
- package/public/classes/McBase.html +7 -18
- package/public/classes/McEvent.html +13 -13
- package/public/customElements.min.js +1 -1
- package/public/functions/addListener.html +1 -1
- package/public/functions/removeListener.html +1 -1
- package/public/interfaces/HTMLMcElement.html +2 -2
- package/public/microcomponents.min.js +1 -1
- package/public/test.js +0 -2
- package/public/test.js.map +1 -1
- package/src/MC.ts +95 -51
- package/src/test.ts +0 -3
package/dist/MC.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export interface HTMLMcElement extends HTMLElement {
|
|
|
5
5
|
}
|
|
6
6
|
declare function addListener(domNode: Node, eventName: string, handler: EventListenerOrEventListenerObject | null, capture?: boolean, once?: boolean): void;
|
|
7
7
|
declare function removeListener(domNode: Node, eventName: string, handler: EventListenerOrEventListenerObject | null): void;
|
|
8
|
+
declare function trigger(target: unknown, ev: McEvent | string, data?: any): void;
|
|
8
9
|
declare class McBase {
|
|
9
10
|
#private;
|
|
10
11
|
constructor(target: {
|
|
@@ -14,7 +15,9 @@ declare class McBase {
|
|
|
14
15
|
}
|
|
15
16
|
declare class MC extends McBase {
|
|
16
17
|
constructor(target: any);
|
|
18
|
+
static trigger: typeof trigger;
|
|
17
19
|
trigger(ev: McEvent | string, data?: any, bubble?: string): this | undefined;
|
|
20
|
+
autoAttachListeners(): void;
|
|
18
21
|
}
|
|
19
22
|
declare class DC extends McBase {
|
|
20
23
|
constructor(target: HTMLElement);
|
|
@@ -26,11 +29,11 @@ declare class DC extends McBase {
|
|
|
26
29
|
[key: string]: any;
|
|
27
30
|
};
|
|
28
31
|
trigger(ev: McEvent | string, data?: any, bubble?: string): void;
|
|
32
|
+
autoAttachListeners(): void;
|
|
29
33
|
parent(search?: string): any[];
|
|
30
34
|
ancestors(search?: string): any[];
|
|
31
35
|
children(search?: string): any[];
|
|
32
36
|
descendants(search?: string): any[];
|
|
33
|
-
autoAttachListeners(): void;
|
|
34
37
|
}
|
|
35
38
|
export { addListener, removeListener, McBase, MC, DC, McEvent };
|
|
36
39
|
//# sourceMappingURL=MC.d.ts.map
|
package/dist/MC.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MC.d.ts","sourceRoot":"","sources":["../src/MC.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAWvC,MAAM,WAAW,aAAc,SAAQ,WAAW;IACjD,GAAG,EAAE,WAAW,CAAC;CACjB;AA6CD,iBAAS,WAAW,CAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,kCAAkC,GAAG,IAAI,EAAE,OAAO,GAAE,OAAe,EAAE,IAAI,GAAE,OAAe,QAe1J;AAED,iBAAS,cAAc,CAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,kCAAkC,GAAG,IAAI,QAE5G;
|
|
1
|
+
{"version":3,"file":"MC.d.ts","sourceRoot":"","sources":["../src/MC.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAWvC,MAAM,WAAW,aAAc,SAAQ,WAAW;IACjD,GAAG,EAAE,WAAW,CAAC;CACjB;AA6CD,iBAAS,WAAW,CAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,kCAAkC,GAAG,IAAI,EAAE,OAAO,GAAE,OAAe,EAAE,IAAI,GAAE,OAAe,QAe1J;AAED,iBAAS,cAAc,CAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,kCAAkC,GAAG,IAAI,QAE5G;AA+CD,iBAAS,OAAO,CAAE,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,OAAO,GAAG,MAAM,EAAE,IAAI,GAAE,GAAQ,QAUtE;AAED,cAAM,MAAM;;gBAME,MAAM,EAAE;QAAE,CAAC,GAAG,EAAC,MAAM,GAAG,GAAG,CAAA;KAAE;IAY1C,IAAI,MAAM,IAAI,GAAG,CAEhB;CAED;AAED,cAAM,EAAG,SAAQ,MAAM;gBAEV,MAAM,EAAE,GAAG;IA8BpB,MAAM,CAAC,OAAO,iBAAW;IAE5B,OAAO,CAAE,EAAE,EAAE,OAAO,GAAG,MAAM,EAAE,IAAI,GAAE,GAAQ,EAAE,MAAM,CAAC,EAAE,MAAM;IAiF9D,mBAAmB;CA2CnB;AAED,cAAM,EAAG,SAAQ,MAAM;gBAEV,MAAM,EAAE,WAAW;IAkC/B,MAAM,CAAC,KAAK,EAAE,OAAO,CAAS;IAE9B,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAO;IAC3B,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAU;IACjC,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAW;IAEnC,IAAI,GAAG,IAAI;QAAE,CAAC,GAAG,EAAC,MAAM,GAAG,GAAG,CAAA;KAAE,CAE/B;IAED,OAAO,CAAE,EAAE,EAAE,OAAO,GAAG,MAAM,EAAE,IAAI,GAAE,GAAQ,EAAE,MAAM,CAAC,EAAE,MAAM;IAI9D,mBAAmB;IAInB,MAAM,CAAC,MAAM,GAAE,MAAW,GAAG,GAAG,EAAE;IAMlC,SAAS,CAAC,MAAM,GAAE,MAAW,GAAG,GAAG,EAAE;IAMrC,QAAQ,CAAC,MAAM,GAAE,MAAW,GAAG,GAAG,EAAE;IAYpC,WAAW,CAAC,MAAM,GAAE,MAAW,GAAG,GAAG,EAAE;CAOvC;AAED,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC"}
|
package/dist/MC.min.js
CHANGED
|
@@ -237,6 +237,7 @@ function trigger(target, ev, data = {}) {
|
|
|
237
237
|
if (!_mc)
|
|
238
238
|
return;
|
|
239
239
|
[...Object.values(_mc)].forEach((mc) => {
|
|
240
|
+
//console.log( 'mc [', mc.constructor.name, ']', mc.constructor.prototype?.oneInit );
|
|
240
241
|
if (mc?.trigger && typeof mc?.trigger === 'function') {
|
|
241
242
|
mc?.trigger(ev, data);
|
|
242
243
|
}
|
|
@@ -265,12 +266,28 @@ class MC extends McBase {
|
|
|
265
266
|
super(target);
|
|
266
267
|
let that = this;
|
|
267
268
|
setTimeout(() => {
|
|
268
|
-
that.trigger('
|
|
269
|
+
that.trigger('Init');
|
|
270
|
+
setTimeout(() => {
|
|
271
|
+
let keys = Object.keys(that?._mc);
|
|
272
|
+
if (keys.length) {
|
|
273
|
+
//console.log( 'inner Inits on [', that.constructor.name, ']', keys );
|
|
274
|
+
keys?.forEach((key) => {
|
|
275
|
+
let mc = that?._mc?.[key];
|
|
276
|
+
//console.log( key, typeof mc?.oneInit, mc );
|
|
277
|
+
if (mc?.oneInit && typeof mc?.oneInit == 'function') {
|
|
278
|
+
mc.oneInit(new McEvent('Init'));
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
;
|
|
283
|
+
}, 0);
|
|
269
284
|
}, 0);
|
|
285
|
+
this.autoAttachListeners();
|
|
270
286
|
}
|
|
287
|
+
static trigger = trigger;
|
|
271
288
|
trigger(ev, data = {}, bubble) {
|
|
272
289
|
let that = this;
|
|
273
|
-
//
|
|
290
|
+
//console.log( that, '.trigger(', ev, data, bubble, ')' );
|
|
274
291
|
bubble = bubble || 'l';
|
|
275
292
|
// run all triggers
|
|
276
293
|
if (that.constructor === MC || that.constructor === DC) {
|
|
@@ -328,15 +345,64 @@ class MC extends McBase {
|
|
|
328
345
|
}
|
|
329
346
|
}
|
|
330
347
|
}
|
|
348
|
+
autoAttachListeners() {
|
|
349
|
+
if (!MC_isBrowser())
|
|
350
|
+
return;
|
|
351
|
+
const target = this.target;
|
|
352
|
+
if (target instanceof HTMLElement) {
|
|
353
|
+
let that = this;
|
|
354
|
+
Object
|
|
355
|
+
.getOwnPropertyNames(that.constructor.prototype)
|
|
356
|
+
.filter(key => /^on[A-Z]|one[A-Z]/.test(key) && typeof that.constructor.prototype[key] === 'function')
|
|
357
|
+
.forEach(key => {
|
|
358
|
+
let once = /^one/.test(key), withoutOnOne = key.replace(/^on[e]{0,1}/, ''), // preserves upper/lowercase for non-native events
|
|
359
|
+
nativeEventName = withoutOnOne.toLowerCase(), listener = (ev) => { that.trigger(withoutOnOne, ev); };
|
|
360
|
+
;
|
|
361
|
+
if (once) {
|
|
362
|
+
// console.log( '...is only called once', that.constructor.prototype[key] );
|
|
363
|
+
Object.defineProperty(this, 'on' + withoutOnOne, {
|
|
364
|
+
configurable: true,
|
|
365
|
+
enumerable: false,
|
|
366
|
+
writable: true,
|
|
367
|
+
value: (ev) => {
|
|
368
|
+
// console.log( 'onceHandler execute:', that.constructor.prototype[key] );
|
|
369
|
+
(that.constructor.prototype[key]).bind(that)(ev);
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
if (MC_nativeEventNames.has('on' + nativeEventName)) { // native event defined in HTMLElement
|
|
374
|
+
// console.log('added as native listener', target, nativeEventName );
|
|
375
|
+
addListener(target, nativeEventName, listener, false, once);
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
}
|
|
331
380
|
}
|
|
332
381
|
;
|
|
333
382
|
class DC extends McBase {
|
|
334
383
|
constructor(target) {
|
|
335
384
|
super(target);
|
|
336
|
-
let that = this;
|
|
385
|
+
let that = this, isDomMcInstance = that.constructor === DC;
|
|
337
386
|
setTimeout(() => {
|
|
338
|
-
that.trigger('
|
|
387
|
+
that.trigger('Init');
|
|
388
|
+
if (!isDomMcInstance) {
|
|
389
|
+
setTimeout(() => {
|
|
390
|
+
let keys = Object.keys(that?._mc);
|
|
391
|
+
if (keys.length) {
|
|
392
|
+
//console.log( 'inner Inits on [', that.constructor.name, ']', keys );
|
|
393
|
+
keys?.forEach((key) => {
|
|
394
|
+
let mc = that?._mc?.[key];
|
|
395
|
+
//console.log( key, typeof mc?.oneInit, mc );
|
|
396
|
+
if (mc?.oneInit && typeof mc?.oneInit == 'function') {
|
|
397
|
+
mc.oneInit(new McEvent('Init'));
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
;
|
|
402
|
+
}, 0);
|
|
403
|
+
}
|
|
339
404
|
}, 0);
|
|
405
|
+
this.autoAttachListeners();
|
|
340
406
|
}
|
|
341
407
|
static debug = false;
|
|
342
408
|
static add = add;
|
|
@@ -349,6 +415,10 @@ class DC extends McBase {
|
|
|
349
415
|
MC.prototype.trigger.call(this, ev, data, bubble);
|
|
350
416
|
}
|
|
351
417
|
;
|
|
418
|
+
autoAttachListeners() {
|
|
419
|
+
MC.prototype.autoAttachListeners.call(this);
|
|
420
|
+
}
|
|
421
|
+
;
|
|
352
422
|
parent(search = '') {
|
|
353
423
|
let target = this.target;
|
|
354
424
|
if (!MC_isDOM(target))
|
|
@@ -380,39 +450,6 @@ class DC extends McBase {
|
|
|
380
450
|
const myDomElements = target.querySelectorAll('*[_mc]');
|
|
381
451
|
return MC_getMicroComponents([...myDomElements], search);
|
|
382
452
|
}
|
|
383
|
-
autoAttachListeners() {
|
|
384
|
-
if (!MC_isBrowser())
|
|
385
|
-
return;
|
|
386
|
-
const target = this.target;
|
|
387
|
-
if (target instanceof HTMLElement) {
|
|
388
|
-
let that = this;
|
|
389
|
-
Object
|
|
390
|
-
.getOwnPropertyNames(that.constructor.prototype)
|
|
391
|
-
.filter(key => /^on[A-Z]|one[A-Z]/.test(key) && typeof that.constructor.prototype[key] === 'function')
|
|
392
|
-
.forEach(key => {
|
|
393
|
-
let once = /^one/.test(key), withoutOnOne = key.replace(/^on[e]{0,1}/, ''), // preserves upper/lowercase for non-native events
|
|
394
|
-
nativeEventName = withoutOnOne.toLowerCase(), listener = (ev) => { that.trigger(withoutOnOne, ev); };
|
|
395
|
-
;
|
|
396
|
-
// console.log('autoAttach', nativeEventName, withoutOnOne, once, listener);
|
|
397
|
-
if (once) {
|
|
398
|
-
// console.log( '...is only called once', that.constructor.prototype[key] );
|
|
399
|
-
Object.defineProperty(this, 'on' + withoutOnOne, {
|
|
400
|
-
configurable: true,
|
|
401
|
-
enumerable: false,
|
|
402
|
-
writable: true,
|
|
403
|
-
value: (ev) => {
|
|
404
|
-
// console.log( 'onceHandler execute:', that.constructor.prototype[key] );
|
|
405
|
-
(that.constructor.prototype[key]).bind(that)(ev);
|
|
406
|
-
}
|
|
407
|
-
});
|
|
408
|
-
}
|
|
409
|
-
if (MC_nativeEventNames.has('on' + nativeEventName)) { // native event defined in HTMLElement
|
|
410
|
-
// console.log('added as native listener', target, nativeEventName );
|
|
411
|
-
addListener(target, nativeEventName, listener, false, once);
|
|
412
|
-
}
|
|
413
|
-
});
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
453
|
}
|
|
417
454
|
;
|
|
418
455
|
|
package/dist/MC.ts
CHANGED
|
@@ -128,7 +128,8 @@ function remove( target: HTMLMcElement, key: string) {
|
|
|
128
128
|
function trigger( target: unknown, ev: McEvent | string, data: any = {}) {
|
|
129
129
|
let _mc = (target as any)?._mc;
|
|
130
130
|
if ( !_mc ) return;
|
|
131
|
-
[ ...Object.values( _mc ) ].forEach( (mc) => {
|
|
131
|
+
[ ...Object.values( _mc ) ].forEach( (mc: any) => {
|
|
132
|
+
//console.log( 'mc [', mc.constructor.name, ']', mc.constructor.prototype?.oneInit );
|
|
132
133
|
if ( (mc as any)?.trigger && typeof (mc as any)?.trigger === 'function' ){
|
|
133
134
|
(mc as any)?.trigger( ev, data );
|
|
134
135
|
}
|
|
@@ -168,16 +169,36 @@ class MC extends McBase {
|
|
|
168
169
|
|
|
169
170
|
setTimeout(
|
|
170
171
|
() => {
|
|
171
|
-
that.trigger('
|
|
172
|
+
that.trigger('Init');
|
|
173
|
+
setTimeout(
|
|
174
|
+
() => {
|
|
175
|
+
let keys = Object.keys( (that as any)?._mc );
|
|
176
|
+
if ( keys.length ){
|
|
177
|
+
//console.log( 'inner Inits on [', that.constructor.name, ']', keys );
|
|
178
|
+
keys?.forEach( (key: string) => {
|
|
179
|
+
let mc = (that as any)?._mc?.[key];
|
|
180
|
+
//console.log( key, typeof mc?.oneInit, mc );
|
|
181
|
+
if ( mc?.oneInit && typeof mc?.oneInit == 'function' ){
|
|
182
|
+
mc.oneInit( new McEvent('Init') );
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
, 0
|
|
188
|
+
);
|
|
172
189
|
}
|
|
173
190
|
,0
|
|
174
191
|
);
|
|
192
|
+
|
|
193
|
+
this.autoAttachListeners();
|
|
175
194
|
}
|
|
176
195
|
|
|
196
|
+
static trigger = trigger;
|
|
197
|
+
|
|
177
198
|
trigger( ev: McEvent | string, data: any = {}, bubble?: string ) {
|
|
178
199
|
let that = this;
|
|
179
200
|
|
|
180
|
-
//
|
|
201
|
+
//console.log( that, '.trigger(', ev, data, bubble, ')' );
|
|
181
202
|
bubble = bubble || 'l';
|
|
182
203
|
|
|
183
204
|
// run all triggers
|
|
@@ -255,6 +276,49 @@ class MC extends McBase {
|
|
|
255
276
|
|
|
256
277
|
}
|
|
257
278
|
|
|
279
|
+
autoAttachListeners(){
|
|
280
|
+
if ( !isBrowser() ) return;
|
|
281
|
+
|
|
282
|
+
const target = this.target;
|
|
283
|
+
|
|
284
|
+
if ( target instanceof HTMLElement ){
|
|
285
|
+
let that: LooseObject = this;
|
|
286
|
+
Object
|
|
287
|
+
.getOwnPropertyNames( that.constructor.prototype )
|
|
288
|
+
.filter( key => /^on[A-Z]|one[A-Z]/.test(key) && typeof that.constructor.prototype[key] === 'function' )
|
|
289
|
+
.forEach( key => {
|
|
290
|
+
let
|
|
291
|
+
once = /^one/.test(key),
|
|
292
|
+
withoutOnOne = key.replace( /^on[e]{0,1}/, '' ), // preserves upper/lowercase for non-native events
|
|
293
|
+
nativeEventName = withoutOnOne.toLowerCase(),
|
|
294
|
+
listener = ( ev: McEvent | Event | CustomEvent ) => { that.trigger( withoutOnOne, ev ); };
|
|
295
|
+
;
|
|
296
|
+
|
|
297
|
+
if ( once ){
|
|
298
|
+
// console.log( '...is only called once', that.constructor.prototype[key] );
|
|
299
|
+
Object.defineProperty(
|
|
300
|
+
this,
|
|
301
|
+
'on' + withoutOnOne,
|
|
302
|
+
{
|
|
303
|
+
configurable: true,
|
|
304
|
+
enumerable: false,
|
|
305
|
+
writable: true,
|
|
306
|
+
value: (ev: any) => {
|
|
307
|
+
// console.log( 'onceHandler execute:', that.constructor.prototype[key] );
|
|
308
|
+
( that.constructor.prototype[key] ).bind(that)(ev);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if ( nativeEventNames.has( 'on' + nativeEventName ) ){ // native event defined in HTMLElement
|
|
315
|
+
// console.log('added as native listener', target, nativeEventName );
|
|
316
|
+
addListener( target, nativeEventName, listener, false, once );
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
258
322
|
};
|
|
259
323
|
|
|
260
324
|
class DC extends McBase {
|
|
@@ -262,14 +326,35 @@ class DC extends McBase {
|
|
|
262
326
|
constructor(target: HTMLElement ) {
|
|
263
327
|
super(target);
|
|
264
328
|
|
|
265
|
-
let that = this
|
|
329
|
+
let that = this,
|
|
330
|
+
isDomMcInstance = that.constructor === DC;
|
|
266
331
|
|
|
267
332
|
setTimeout(
|
|
268
333
|
() => {
|
|
269
|
-
that.trigger('
|
|
334
|
+
that.trigger('Init');
|
|
335
|
+
if ( !isDomMcInstance ) {
|
|
336
|
+
setTimeout(
|
|
337
|
+
() => {
|
|
338
|
+
let keys = Object.keys( (that as any)?._mc );
|
|
339
|
+
if ( keys.length ){
|
|
340
|
+
//console.log( 'inner Inits on [', that.constructor.name, ']', keys );
|
|
341
|
+
keys?.forEach( (key: string) => {
|
|
342
|
+
let mc = (that as any)?._mc?.[key];
|
|
343
|
+
//console.log( key, typeof mc?.oneInit, mc );
|
|
344
|
+
if ( mc?.oneInit && typeof mc?.oneInit == 'function' ){
|
|
345
|
+
mc.oneInit( new McEvent('Init') );
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
, 0
|
|
351
|
+
);
|
|
352
|
+
}
|
|
270
353
|
}
|
|
271
|
-
,0
|
|
354
|
+
, 0
|
|
272
355
|
);
|
|
356
|
+
|
|
357
|
+
this.autoAttachListeners();
|
|
273
358
|
}
|
|
274
359
|
|
|
275
360
|
static debug: boolean = false;
|
|
@@ -286,6 +371,10 @@ class DC extends McBase {
|
|
|
286
371
|
MC.prototype.trigger.call( this, ev, data, bubble );
|
|
287
372
|
};
|
|
288
373
|
|
|
374
|
+
autoAttachListeners() {
|
|
375
|
+
MC.prototype.autoAttachListeners.call( this );
|
|
376
|
+
};
|
|
377
|
+
|
|
289
378
|
parent(search: string = ''): any[] {
|
|
290
379
|
let target: HTMLElement = (this as any).target;
|
|
291
380
|
if (!isDOM(target)) return [];
|
|
@@ -317,51 +406,6 @@ class DC extends McBase {
|
|
|
317
406
|
return getMicroComponents([...myDomElements], search);
|
|
318
407
|
}
|
|
319
408
|
|
|
320
|
-
autoAttachListeners(){
|
|
321
|
-
if ( !isBrowser() ) return;
|
|
322
|
-
|
|
323
|
-
const target = this.target;
|
|
324
|
-
|
|
325
|
-
if ( target instanceof HTMLElement ){
|
|
326
|
-
let that: LooseObject = this;
|
|
327
|
-
Object
|
|
328
|
-
.getOwnPropertyNames( that.constructor.prototype )
|
|
329
|
-
.filter( key => /^on[A-Z]|one[A-Z]/.test(key) && typeof that.constructor.prototype[key] === 'function' )
|
|
330
|
-
.forEach( key => {
|
|
331
|
-
let
|
|
332
|
-
once = /^one/.test(key),
|
|
333
|
-
withoutOnOne = key.replace( /^on[e]{0,1}/, '' ), // preserves upper/lowercase for non-native events
|
|
334
|
-
nativeEventName = withoutOnOne.toLowerCase(),
|
|
335
|
-
listener = ( ev: McEvent | Event | CustomEvent ) => { that.trigger( withoutOnOne, ev ); };
|
|
336
|
-
;
|
|
337
|
-
|
|
338
|
-
// console.log('autoAttach', nativeEventName, withoutOnOne, once, listener);
|
|
339
|
-
|
|
340
|
-
if ( once ){
|
|
341
|
-
// console.log( '...is only called once', that.constructor.prototype[key] );
|
|
342
|
-
Object.defineProperty(
|
|
343
|
-
this,
|
|
344
|
-
'on' + withoutOnOne,
|
|
345
|
-
{
|
|
346
|
-
configurable: true,
|
|
347
|
-
enumerable: false,
|
|
348
|
-
writable: true,
|
|
349
|
-
value: (ev: any) => {
|
|
350
|
-
// console.log( 'onceHandler execute:', that.constructor.prototype[key] );
|
|
351
|
-
( that.constructor.prototype[key] ).bind(that)(ev);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
);
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
if ( nativeEventNames.has( 'on' + nativeEventName ) ){ // native event defined in HTMLElement
|
|
358
|
-
// console.log('added as native listener', target, nativeEventName );
|
|
359
|
-
addListener( target, nativeEventName, listener, false, once );
|
|
360
|
-
}
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
409
|
};
|
|
366
410
|
|
|
367
411
|
export { addListener, removeListener, McBase, MC, DC, McEvent };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.customElements=e():t.customElements=e()}(this,(()=>(()=>{"use strict";var t={d:(e,
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.customElements=e():t.customElements=e()}(this,(()=>(()=>{"use strict";var t={d:(e,n)=>{for(var r in n)t.o(n,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{defineCE:()=>b,getCE:()=>y});var n=new Function("try {return this===window;}catch(e){ return false;}");let r=new Set;n()&&Object.keys(HTMLElement.prototype).filter((t=>/^on/.test(t))).forEach((t=>r.add(t)));class o{#t;#e=!1;#n=!1;constructor(t,e={},n="l"){this.#t=t,this.data=e,this.bubble=n}get type(){return this.#t}get stopped(){return this.#e}get immediateStopped(){return this.#n}stopPropagation(){this.#e=!0}stopImmediatePropagation(){this.stopPropagation(),this.#n=!0}}var i=new Function("try {return this===window;}catch(e){ return false;}");let s=new Set;function c(t,e){let n=[];return t.forEach((t=>{if(t&&t instanceof HTMLElement){const r=t?._mc;!e&&r?n=n.concat(Object.values(t._mc)):e&&r&&r[e]&&n.push(r[e])}})),n}function a(t,e,n=!0){let r=[];for(;t;){if(t._mc&&(e?e&&t._mc[e]&&r.push(t._mc[e]):r=r.concat(Object.values(t._mc)),n))return r;t=t.parentNode}return r}function u(t){return t&&t instanceof HTMLElement}function l(t,e,n={}){let r=t;if(!r._mc){let e=g?.debug;g.debug=!1,r._mc=new g(t),g.debug=e}const o=r._mc;return e.length&&!o[e]&&(o[e]=n,t instanceof HTMLElement&&t.setAttribute("_mc","")),n}function p(t,e){if(!e)return;const n=t?._mc||{};n&&n[e]&&delete n[e],!Object.keys(n).length&&t instanceof HTMLElement&&t.hasAttribute("_mc")&&t.removeAttribute("_mc")}function d(t,e,n={}){let r=t?._mc;r&&[...Object.values(r)].forEach((t=>{t?.trigger&&"function"==typeof t?.trigger&&t?.trigger(e,n)}))}i()&&Object.keys(HTMLElement.prototype).filter((t=>/^on/.test(t))).forEach((t=>s.add(t)));class f{#r;#o={};constructor(t){this.#r=new WeakRef(t),this.constructor!==g&&Object.defineProperty(this,"_mc",{get(){return this.#o}})}get target(){return this.#r.deref()}}class m extends f{constructor(t){super(t);let e=this;setTimeout((()=>{e.trigger("Init"),setTimeout((()=>{let t=Object.keys(e?._mc);t.length&&t?.forEach((t=>{let n=e?._mc?.[t];n?.oneInit&&"function"==typeof n?.oneInit&&n.oneInit(new o("Init"))}))}),0)}),0),this.autoAttachListeners()}static trigger=d;trigger(t,e={},n){let r=this;if(n=n||"l",r.constructor!==m&&r.constructor!==g){if(r instanceof m||r instanceof g){const r=this,s="string"!=typeof t?t:new o(t,e,n),c="on"+s.type[0].toUpperCase()+s.type.slice(1);if(s.bubble.indexOf("l")>-1&&(s.immediateStopped||"function"!=typeof r[c]||(r[c](s),r.hasOwnProperty(c)&&delete r[c])),s.stopped||"l"===s.bubble)return r;i()&&/[ud]/.test(s.bubble)&&r instanceof m&&setTimeout((()=>{-1===s.bubble.indexOf("l")&&(s.bubble+="l"),s.bubble.indexOf("u")>-1&&r.parent().forEach((t=>{t instanceof m&&t.trigger(s)})),s.bubble.indexOf("d")>-1&&r.children().forEach((t=>{t instanceof m&&t.trigger(s)}))}),0)}}else[...Object.getOwnPropertyNames(r)].forEach((o=>{r[o]?.trigger&&"function"==typeof r[o]?.trigger&&r[o]?.trigger(t,e,n)}))}autoAttachListeners(){if(!i())return;const t=this.target;if(t instanceof HTMLElement){let e=this;Object.getOwnPropertyNames(e.constructor.prototype).filter((t=>/^on[A-Z]|one[A-Z]/.test(t)&&"function"==typeof e.constructor.prototype[t])).forEach((n=>{let r=/^one/.test(n),o=n.replace(/^on[e]{0,1}/,""),i=o.toLowerCase();r&&Object.defineProperty(this,"on"+o,{configurable:!0,enumerable:!1,writable:!0,value:t=>{e.constructor.prototype[n].bind(e)(t)}}),s.has("on"+i)&&function(t,e,n,r=!1,o=!1){let i={once:!1};r&&(i.capture=r),o&&(i.once=o),t.addEventListener(e,n,i)}(t,i,(t=>{e.trigger(o,t)}),!1,r)}))}}}class g extends f{constructor(t){super(t);let e=this,n=e.constructor===g;setTimeout((()=>{e.trigger("Init"),n||setTimeout((()=>{let t=Object.keys(e?._mc);t.length&&t?.forEach((t=>{let n=e?._mc?.[t];n?.oneInit&&"function"==typeof n?.oneInit&&n.oneInit(new o("Init"))}))}),0)}),0),this.autoAttachListeners()}static debug=!1;static add=l;static remove=p;static trigger=d;get _mc(){return this._mc}trigger(t,e={},n){m.prototype.trigger.call(this,t,e,n)}autoAttachListeners(){m.prototype.autoAttachListeners.call(this)}parent(t=""){let e=this.target;return u(e)?a(e.parentNode,t,!0):[]}ancestors(t=""){let e=this?.target;return u(e)?a(this.target.parentNode,t,!1):[]}children(t=""){let e=this?.target;if(!u(e))return[];const n=Math.random().toString().replace(".",""),r='[_mc]:not([temp_id="'+n+'"] [_mc] [_mc])';e.setAttribute("temp_id",n);const o=c([...e.querySelectorAll(r)],t);return e.removeAttribute("temp_id"),o}descendants(t=""){let e=this?.target;return u(e)?c([...e.querySelectorAll("*[_mc]")],t):[]}}class h extends HTMLElement{constructor(){super()}connectedCallback(){g.trigger(this,"Connected")}disconnectedCallback(){g.trigger(this,"Disconnected")}adoptedCallback(){g.trigger(this,"Adopted")}attributeChangedCallback(t,e,n){g.trigger(this,"AttributeChanged",{name:t,oldValue:e,newValue:n})}}function b(t,e,n=[]){if(customElements.get(t))return void console.warn(`IGNORED: Custom element "${t}" is already defined!`);if(!t.includes("-"))throw new Error('createCustomElement: tagName must contain at least one hyphen ("-").');let r=t.split("-").map((t=>t.charAt(0).toUpperCase()+t.slice(1))).join("");customElements.define(t,function(t,e){return Object.defineProperty(e,"name",{value:t})}(r,class extends h{instance;constructor(t){super();let n=new e(this,t);g.add(this,r,n)}static get observedAttributes(){return n}}))}function y(t){return customElements.get(t)}return e})()));
|
|
@@ -1 +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.microcomponents=t():e.microcomponents=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={};function r(e){return null!=e&&"object"==typeof e}function n(e){return e.split("-").map((e=>e.charAt(0).toUpperCase()+e.slice(1))).join("")}function s(e,t){let r;return()=>{clearTimeout(r),r=setTimeout((function(){e(...arguments)}),t)}}function a(e,t){const n=Object.keys(e),s=Object.keys(t);if(n.length!==s.length)return!1;for(const s of n){const n=e[s],o=t[s],i=r(n)&&r(o);if(i&&!a(n,o)||!i&&n!==o)return!1}return!0}function o(e,t,n=null,s){let a=e.split(".");s||(s=t);let i=a.shift(),c=a.join(".");null!==n&&i.length&&void 0===t[i]&&(t[i]={});let l=t[i];return 0===c.length?null!==n?(t[i]=n,s):t[i]:r(t[i])?o(c,t[i],n,s):n?s:l[i]}function i(e,t){var n=Array.from(arguments);if(n.length){if(1===n.length)return n[1];if(n.length>2){for(;n.length>1;)n[0]=i(n[0],n[1]),n.splice(1,1);return n[0]}if("string"==typeof e){var s=e.match(/\{[^\{\}]*\}/g);s&&s.forEach((function(r){var n=o(r.substr(1,r.length-2),t);void 0!==n&&(e=e.replace(r,n))}))}else if(r(e))switch(e.constructor){case Object:Object.keys(e).forEach((function(r){e.hasOwnProperty(r)&&(e[r]=i(e[r],t))}));break;case Array:e.forEach((function(r,n,s){s[n]=i(e[n],t)}))}return e}console.error("no arguments give to parse")}function c(e){let t=document.createElement("template");return e=e.replace(/<([A-Za-z0-9\-]*)([^>\/]*)(\/>)/gi,"<$1$2></$1>"),t.innerHTML=e,t.content.normalize(),Array.from(t.content.childNodes)}e.r(t),e.d(t,{$d:()=>B,$t:()=>q,DC:()=>S,MC:()=>A,McBase:()=>w,McEvent:()=>h,addListener:()=>b,debounce:()=>s,deepEqual:()=>a,defineCE:()=>k,formValues:()=>F,getCE:()=>x,htmlToElements:()=>c,isObject:()=>r,kebabToPascal:()=>n,makeCO:()=>T,nameSpace:()=>o,parse:()=>i,removeListener:()=>g});var l=new Function("try {return this===window;}catch(e){ return false;}");let u=new Set;l()&&Object.keys(HTMLElement.prototype).filter((e=>/^on/.test(e))).forEach((e=>u.add(e)));class h{#e;#t=!1;#r=!1;constructor(e,t={},r="l"){this.#e=e,this.data=t,this.bubble=r}get type(){return this.#e}get stopped(){return this.#t}get immediateStopped(){return this.#r}stopPropagation(){this.#t=!0}stopImmediatePropagation(){this.stopPropagation(),this.#r=!0}}var f=new Function("try {return this===window;}catch(e){ return false;}");let d=new Set;function p(e,t){let r=[];return e.forEach((e=>{if(e&&e instanceof HTMLElement){const n=e?._mc;!t&&n?r=r.concat(Object.values(e._mc)):t&&n&&n[t]&&r.push(n[t])}})),r}function m(e,t,r=!0){let n=[];for(;e;){if(e._mc&&(t?t&&e._mc[t]&&n.push(e._mc[t]):n=n.concat(Object.values(e._mc)),r))return n;e=e.parentNode}return n}function y(e){return e&&e instanceof HTMLElement}function b(e,t,r,n=!1,s=!1){let a={once:!1};n&&(a.capture=n),s&&(a.once=s),e.addEventListener(t,r,a)}function g(e,t,r){e.removeEventListener(t,r)}function E(e,t,r={}){let n=e;if(!n._mc){let t=S?.debug;S.debug=!1,n._mc=new S(e),S.debug=t}const s=n._mc;return t.length&&!s[t]&&(s[t]=r,e instanceof HTMLElement&&e.setAttribute("_mc","")),r}function v(e,t){if(!t)return;const r=e?._mc||{};r&&r[t]&&delete r[t],!Object.keys(r).length&&e instanceof HTMLElement&&e.hasAttribute("_mc")&&e.removeAttribute("_mc")}function O(e,t,r={}){let n=e?._mc;n&&[...Object.values(n)].forEach((e=>{e?.trigger&&"function"==typeof e?.trigger&&e?.trigger(t,r)}))}f()&&Object.keys(HTMLElement.prototype).filter((e=>/^on/.test(e))).forEach((e=>d.add(e)));class w{#n;#s={};constructor(e){this.#n=new WeakRef(e),this.constructor!==S&&Object.defineProperty(this,"_mc",{get(){return this.#s}})}get target(){return this.#n.deref()}}class A extends w{constructor(e){super(e);let t=this;setTimeout((()=>{t.trigger("init")}),0)}trigger(e,t={},r){let n=this;if(r=r||"l",n.constructor!==A&&n.constructor!==S){if(n instanceof A||n instanceof S){const n=this,s="string"!=typeof e?e:new h(e,t,r),a="on"+s.type[0].toUpperCase()+s.type.slice(1);if(s.bubble.indexOf("l")>-1&&(s.immediateStopped||"function"!=typeof n[a]||(n[a](s),n.hasOwnProperty(a)&&delete n[a])),s.stopped||"l"===s.bubble)return n;f()&&/[ud]/.test(s.bubble)&&n instanceof A&&setTimeout((()=>{-1===s.bubble.indexOf("l")&&(s.bubble+="l"),s.bubble.indexOf("u")>-1&&n.parent().forEach((e=>{e instanceof A&&e.trigger(s)})),s.bubble.indexOf("d")>-1&&n.children().forEach((e=>{e instanceof A&&e.trigger(s)}))}),0)}}else[...Object.getOwnPropertyNames(n)].forEach((s=>{n[s]?.trigger&&"function"==typeof n[s]?.trigger&&n[s]?.trigger(e,t,r)}))}}class S extends w{constructor(e){super(e);let t=this;setTimeout((()=>{t.trigger("init")}),0)}static debug=!1;static add=E;static remove=v;static trigger=O;get _mc(){return this._mc}trigger(e,t={},r){A.prototype.trigger.call(this,e,t,r)}parent(e=""){let t=this.target;return y(t)?m(t.parentNode,e,!0):[]}ancestors(e=""){let t=this?.target;return y(t)?m(this.target.parentNode,e,!1):[]}children(e=""){let t=this?.target;if(!y(t))return[];const r=Math.random().toString().replace(".",""),n='[_mc]:not([temp_id="'+r+'"] [_mc] [_mc])';t.setAttribute("temp_id",r);const s=p([...t.querySelectorAll(n)],e);return t.removeAttribute("temp_id"),s}descendants(e=""){let t=this?.target;return y(t)?p([...t.querySelectorAll("*[_mc]")],e):[]}autoAttachListeners(){if(!f())return;const e=this.target;if(e instanceof HTMLElement){let t=this;Object.getOwnPropertyNames(t.constructor.prototype).filter((e=>/^on[A-Z]|one[A-Z]/.test(e)&&"function"==typeof t.constructor.prototype[e])).forEach((r=>{let n=/^one/.test(r),s=r.replace(/^on[e]{0,1}/,""),a=s.toLowerCase();n&&Object.defineProperty(this,"on"+s,{configurable:!0,enumerable:!1,writable:!0,value:e=>{t.constructor.prototype[r].bind(t)(e)}}),d.has("on"+a)&&b(e,a,(e=>{t.trigger(s,e)}),!1,n)}))}}}class j extends HTMLElement{constructor(){super()}connectedCallback(){S.trigger(this,"Connected")}disconnectedCallback(){S.trigger(this,"Disconnected")}adoptedCallback(){S.trigger(this,"Adopted")}attributeChangedCallback(e,t,r){S.trigger(this,"AttributeChanged",{name:e,oldValue:t,newValue:r})}}function k(e,t,r=[]){if(customElements.get(e))return void console.warn(`IGNORED: Custom element "${e}" is already defined!`);if(!e.includes("-"))throw new Error('createCustomElement: tagName must contain at least one hyphen ("-").');let s=n(e);customElements.define(e,function(e,t){return Object.defineProperty(t,"name",{value:e})}(s,class extends j{instance;constructor(e){super();let r=new t(this,e);S.add(this,s,r)}static get observedAttributes(){return r}}))}function x(e){return customElements.get(e)}const T=(e,t)=>{(t?[t]:[...Object.getOwnPropertyNames(e)]).forEach((t=>{if("_"===t[0]||void 0===e?.[t])return;let n,o=e[t];if(!o.prototype)switch(typeof o){case"string":n=String;break;case"number":n=Number;break;case"boolean":n=Boolean;break;case"object":n=o instanceof Array?Array:Object;break;default:return}let c=class extends n{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,n=r(t.valueOf()),s=t.constructor.bound;if(n){function a(e){if(e.nodeType&&3===e.nodeType){var r=Array.from(e.nodeValue&&e.nodeValue.match(/\{[^\{\}]*\}/g)||[]);if(r.length>0){var o=(c=e.nodeValue||"",function(t){var s,a=!1;return r&&(n?r.forEach((function(e){o.values[e]!==t[e]&&(o.values[e]=t[e],a=!0)})):(o.values=t,a=!0)),a&&(s=c,e.nodeValue=n?i(s,o.values):s.replace(/\{.*\}/g,o.values)),t});o.values=n?{}:void 0,r=Array.from(r).map((e=>e.replace(/[\{\}]/g,"").trim()));let t=n?{}:void 0;r.forEach((function(e){n&&(t[e]="")})),s.push(o)}Array.from(e.childNodes).forEach((function(e){a(e)})),t.notify()}var c;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 n=function(t){return function(s){var a,o=!1;return r&&r.forEach((function(e){n.values[e]!==s[e]&&(n.values[e]=s[e],o=!0)})),o&&(a=t,e.nodeValue=i(a,n.values)),s}}(t.value||"");n.values={},r=Array.from(r).map((e=>e.replace(/[\{\}]/g,"").trim()));let a={};r.forEach((function(e){a[e]=""})),s.push(n)}})),Array.from(e.childNodes).forEach((function(e){a(e)})),t.notify()),e.nodeType&&11===e.nodeType&&Array.from(e.childNodes).forEach((function(e){a(e)}))}a(e),s.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 c(o);Object.defineProperty(e,t,{enumerable:!0,get(){if(r(l.valueOf())){let e=structuredClone(Object.assign({},l));setTimeout(s((function(){a(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,n=l.constructor.callbacks,o=l.constructor.bound;l=new c(structuredClone(Object.assign({},e))),l.constructor.callbacks=r,l.constructor.callbacks=n,l.constructor.bound=o,setTimeout(s((function(){a(structuredClone(Object.assign({},l)),t)||l.notify()}),0),0)}else{let t=l.valueOf(),r=l.constructor.callbacks;l=new c(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]=o}))},C=e=>{let t=new Set;return e.forEach((e=>{(e=e.trim()).split(" ").forEach((e=>{""!==e&&t.add(e)}))})),Array.from(t)},_=e=>{let t=B("input,select,textarea",e).array,r={};return t.forEach((t=>{const n=t.getAttribute("name")||"undefined";if(n){let s;switch((e=>e instanceof HTMLInputElement?"input":e instanceof HTMLSelectElement?"select":e instanceof HTMLTextAreaElement?"textarea":"")(t)){case"input":s=new L(t,e),Object.defineProperty(r,n,{enumerable:!0,configurable:!0,get:()=>s.val,set:e=>{s.val=e}});break;case"select":s=new M(t),Object.defineProperty(r,n,{enumerable:!0,configurable:!0,get:()=>s.val,set:e=>{s.val=e}});break;case"textarea":s=new P(t),Object.defineProperty(r,n,{enumerable:!0,configurable:!0,get:()=>s.val,set:e=>{s.val=e}});break;default:console.warn("handler missing:",n,"for",t)}}})),r};class N{constructor(e){}}class L extends N{#a;#e;#o;constructor(e,t){super(e),this.#a=e,this.#e=e.type,this.#o=t}get val(){let e,t=this;switch(t.#e){case"radio":const r=B(`input[type="radio"][name="${this.#a.getAttribute("name")}"]`,this.#o).filter((e=>e.checked));return r.length?(e=r.array[0],e.value):"";case"checkbox":return t.#a.checked;default:return t.#a.value}return""}set val(e){let t=this;switch(t.#e){case"radio":const r=`input[type="radio"][name="${this.#a.getAttribute("name")}"]`,n=B(r,this.#o);if(!n.length)return;if(""===e)return void n.forEach((e=>{e.checked&&(e.checked=!1)}));const s=n.filter((t=>t.getAttribute("value")===e));if(!s.length)return;return void(s.array[0].checked=!0);case"checkbox":t.#a.checked=e;break;default:t.#a.value=e}}}class M extends N{#a;#i=!1;constructor(e){super(e),this.#a=e,this.#i="select-multiple"===e.type}get val(){const e=[];return B(this.#a.querySelectorAll("option")).filter((e=>e.selected)).forEach((t=>{t.selected&&e.push(t.value)})),this.#i?e:e.length?e[0]:""}set val(e){e="string"==typeof e?[e]:e,B(this.#a.querySelectorAll("option")).forEach((t=>{e.indexOf(t.value)>-1?(t.setAttribute("selected",!0),t.selected=!0):(t.removeAttribute("selected"),t.selected=!1)}))}}class P extends N{#a;constructor(e){super(e),this.#a=e}get val(){return this.#a.value}set val(e){this.#a.value=e}}class H{#c=new Set;get set(){return this.#c}get array(){return Array.from(this.#c)}set set(e){this.#c=e}get length(){return this.#c.size}constructor(e,t=document.body){if(new Set,!e)return this}$t(e){let t=new $;return this.#c.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 B(e,t).forEach((e=>{r.#c.add(e)})),r}addClass(...e){return e=C(e),this.forEach((t=>{t.classList.add(...e)})),this}after(e,t){let r=this,n=B(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=B(e,t);return r&&n.forEach((e=>{r.append(e)})),this}appendTo(e,t){let r=B(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=>{B(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=B(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.#c.forEach((e=>{Array.from(e.children).forEach((e=>{n.add(e)}))})),r=B([...n]),e){let n=B(e,t);r.filter((e=>n.has(e)))}return r}descendants(e,t){let r=this,n=new Set;if(r.#c.forEach((e=>{e.querySelectorAll("*").forEach((e=>{n.add(e)}))})),r=B([...n]),e){let n=B(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,s=!1;return e&&(s=B(e,t)),r.#c.forEach((e=>{e.parentNode&&n.add(e.parentNode.children[0])})),r=B([...n]),e&&r.filter((e=>s.has(e))),r}has(e){return this.#c.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.#c.forEach((e=>{let t=e.parentNode?.children;t&&n.add(Array.from(t).at(-1))})),r=B([...n]),e){let n=B(e,t);r.filter((e=>n.has(e)))}return r}next(e,t){let r=this,n=new Set;if(r.#c.forEach((e=>{let t=e.parentNode?.children;if(t){let r=Array.from(t),s=r.indexOf(e)+1;s<r.length&&n.add(r.at(s))}})),r=B([...n]),e){let n=B(e,t);r.filter((e=>n.has(e)))}return r}normalize(){return this.#c.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){g(e,r,t)}))})),this}on(e,t,r=!1,n=!1){let s=this,a=e.indexOf(" ")>-1?e.split(" ").filter((e=>""!==e)):[e];function o(){o.cb.apply(s,Array.from(arguments))}return o.cb=t,s.forEach((e=>{a.forEach((function(t){b(e,t,o,r,n)}))})),o}one(e,t,r=!1){let n=this,s=e.indexOf(" ")>-1?e.split(" ").filter((e=>""!==e)):[e];function a(){a.cb.apply(n,Array.from(arguments))}return a.cb=t,n.forEach((e=>{s.forEach((function(t){b(e,t,a,r,!0)}))})),a}parent(e,t){let r=this,n=new Set;if(r.#c.forEach((e=>{e.parentNode&&"HTML"!==e.parentNode.tagName&&n.add(e.parentNode)})),r=B([...n]),e){let n=B(e,t);r.filter((e=>n.has(e)))}return r}parents(e,t){let r=this,n=new Set;if(r.#c.forEach((e=>{let t=e;for(;t.parentNode&&"HTML"!==t.parentNode.tagName;)t=t.parentNode,n.add(t)})),r=B([...n]),e){let n=B(e,t);r.filter((e=>n.has(e)))}return r}prepend(e,t){let r=this.array[0],n=B(e,t);return r&&n.forEach((e=>{r.prepend(e)})),this}prev(e,t){let r=this,n=new Set;if(r.#c.forEach((e=>{let t=e.parentNode?.children;if(t){let r=Array.from(t),s=r.indexOf(e)-1;s>-1&&n.add(r.at(s))}})),r=B([...n]),e){let n=B(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,s=!1){let a,o={bubbles:r,cancelable:n,composed:s},i=e.indexOf(" ")>-1?e.split(" "):[e];return this.#c.forEach((e=>{i.forEach((function(r){a=new Event(r,o),a.data=t,e.dispatchEvent(a)}))})),this}val(e,t){if(!this.length)return this;const r=this;let n,s=_(r.array[0]);var a;return e?null!=(a=e)&&"object"==typeof a?(Object.assign(s,e),n=r):"string"==typeof e&&(void 0===t?n=s[e]:(s[e]=t,n=r)):n=Object.assign({},s),n}values(e){const t=this;let r={};if(!t.length)return console.warn("no dom selection to search inputs in"),{};let n=_(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 B(this.array.at(e))}concat(e){let t=this;return(e instanceof H?e.array:e).forEach((e=>{t.#c.add(e)})),t}entries(){return this.array.entries()}every(e,t){return this.array.every(e,t)}filter(e,t){return this.#c=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.#c.add(e)})),this}shift(){let e=this,t=e.#c.size?e.array[0]:void 0;return t&&e.#c.delete(t),t}slice(e,t){return B(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),B(n)}}class ${#c=new Set;get set(){return this.#c}get array(){return Array.from(this.#c)}set set(e){this.#c=e}get length(){return this.#c.size}set length(e){}constructor(e,t=document.body){if(!e)return this;B(e,t).forEach((e=>{q(e).forEach((e=>{this.#c.add(e)}))}))}$d(e,t=document.body){let r=new H,n=new Set,s=!!e||!1,a=new Set;return s&&(a=B(e,t).set),this.#c.forEach((e=>{s&&!a.has(e._tg)||n.add(e._tg)})),r.set=n,r}children(e){let t=this,r=new Set;return t.#c.forEach((t=>{t.children(e).forEach((e=>{r.add(e)}))})),t.#c=r,t}descendants(e){let t=this,r=new Set;return t.#c.forEach((t=>{t.descendants(e).forEach((e=>{r.add(e)}))})),t.#c=r,t}first(e){let t=this,r=new Set;return t.#c.forEach((e=>{e.parent().children().$d().first().$t().forEach((e=>{r.add(e)}))})),t.#c=r,e&&t.filter((t=>t.nameSpace=e)),t}has(e){return this.#c.has(e)}last(e){let t=this,r=new Set;return t.#c.forEach((e=>{e.parent().children().$d().last().$t().forEach((e=>{r.add(e)}))})),t.#c=r,e&&t.filter((t=>t.nameSpace=e)),t}next(e){let t=this,r=new Set;return t.#c.forEach((e=>{let t,n=new Set;for(t=e._tg;null!==t.nextElementSibling;)t=t.nextElementSibling,n.add(t);q([...n]).$d().first().$t().forEach((e=>{r.add(e)}))})),t.#c=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){g(e,`[TB]${r}`,t)}))})),this}on(e,t,r=!1){let n=this,s=e.indexOf(" ")>-1?e.split(" ").filter((e=>""!==e)):[e];function a(){a.cb.apply(n,Array.from(arguments))}return a.cb=t,n.forEach((e=>{s.forEach((function(t){b(e._tg,`[TB]${t}`,a,!1,r)}))})),a}one(e,t){let r=this,n=e.indexOf(" ")>-1?e.split(" ").filter((e=>""!==e)):[e];function s(){s.cb.apply(r,Array.from(arguments))}return s.cb=t,r.forEach((e=>{n.forEach((function(t){b(e._tg,`[TB]${t}`,s,!1,!0)}))})),s}parent(e){let t=this,r=new Set;return t.#c.forEach((t=>{t.parent(e).forEach((e=>{r.add(e)}))})),t.#c=r,t}parents(e){let t=this,r=new Set;return t.#c.forEach((t=>{t.parents(e).forEach((e=>{r.add(e)}))})),t.#c=r,t}prev(e){let t=this,r=new Set;return t.#c.forEach((e=>{let t,n=new Set;for(t=e._tg;null!==t.previousElementSibling;)t=t.previousElementSibling,n.add(t);q([...n]).$d().last().$t().forEach((e=>{r.add(e)}))})),t.#c=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 q(this.array.at(e))}concat(e){let t=this;return e.forEach((e=>{t.#c.add(e)})),t}entries(){return this.array.entries()}every(e,t){return this.array.every(e,t)}filter(e,t){return q(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.#c=new Set(e),t}push(e){return this.#c.add(e),this}shift(){let e=this.array.shift();return this.#c.delete(e),e}slice(e,t){return q(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 q(n)}}const B=(e,t=document)=>{let r=new Set;return e instanceof Array?(e.forEach((e=>{B(e,t).forEach((e=>{r.add(e)}))})),new H([...r])):new H(e,t)},q=(e,t=document)=>B(e,t).$t();class I{constructor(e){}}class V extends I{#a;#e;#o;constructor(e,t){super(e),this.#a=e,this.#e=e.type,this.#o=t}get val(){let e,t=this;switch(t.#e){case"radio":const r=[...(this.#o||document).querySelectorAll(`input[type="radio"][name="${this.#a.getAttribute("name")}"]`)].filter((e=>e.checked));return r.length?(e=r?.[0],e.value):"";case"checkbox":return t.#a.checked;default:return t.#a.value}return""}set val(e){let t=this;switch(t.#e){case"radio":const r=[...(this.#o||document).querySelectorAll(`input[type="radio"][name="${this.#a.getAttribute("name")}"]`)];if(!r.length)return;if(""===e)return void r.forEach((e=>{e.checked&&(e.checked=!1)}));const n=r.filter((t=>t.getAttribute("value")===e));if(!n.length)return;return void((n?.[0]).checked=!0);case"checkbox":t.#a.checked=e;break;default:t.#a.value=e}}}class z extends I{#a;#i=!1;constructor(e){super(e),this.#a=e,this.#i="select-multiple"===e.type}get val(){const e=[];return[...this.#a.querySelectorAll("option")].filter((e=>e.selected)).forEach((t=>{t.selected&&e.push(t.value)})),this.#i?e:e.length?e[0]:""}set val(e){e="string"==typeof e?[e]:e,[...this.#a.querySelectorAll("option")].forEach((t=>{e.indexOf(t.value)>-1?(t.setAttribute("selected","selected"),t.selected=!0):(t.removeAttribute("selected"),t.selected=!1)}))}}class D extends I{#a;constructor(e){super(e),this.#a=e}get val(){return this.#a.value}set val(e){this.#a.value=e}}const F=(e,t={},r,n)=>{let s=(e=>{let t=[...(e||document).querySelectorAll("input,select,textarea")],r={};return t.forEach((t=>{const n=t.getAttribute("name")||"undefined";if(n){let s;switch((e=>e instanceof HTMLInputElement?"input":e instanceof HTMLSelectElement?"select":e instanceof HTMLTextAreaElement?"textarea":"")(t)){case"input":s=new V(t,e),Object.defineProperty(r,n,{enumerable:!0,configurable:!0,get:()=>s.val,set:e=>{s.val=e}});break;case"select":s=new z(t),Object.defineProperty(r,n,{enumerable:!0,configurable:!0,get:()=>s.val,set:e=>{s.val=e}});break;case"textarea":s=new D(t),Object.defineProperty(r,n,{enumerable:!0,configurable:!0,get:()=>s.val,set:e=>{s.val=e}});break;default:console.warn("handler missing:",n,"for",t)}}})),r})(e);function a(e){Object.keys(e).forEach((t=>{s.hasOwnProperty(t)&&e.hasOwnProperty(t)&&(s[t]=e[t])}))}if(Object.keys(t).length>0&&a(t),void 0!==n){let t=r[n];t.constructor?.hasFormHandler||(t.constructor.hasFormHandler=!0,t.observe(a)),r[n].observe((()=>{})),[...e.querySelectorAll("input, textarea, select")].forEach((e=>{b(e,"keyup",(()=>{r[n]=structuredClone(Object.assign(s))})),b(e,"change",(()=>{r[n]=structuredClone(Object.assign(s))})),e instanceof HTMLSelectElement&&b(e,"select",(()=>{r[n]=structuredClone(Object.assign(s))}))}))}return n?r[n]:Object.assign({},s)};return t})()));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.microcomponents=t():e.microcomponents=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={};function r(e){return null!=e&&"object"==typeof e}function n(e){return e.split("-").map((e=>e.charAt(0).toUpperCase()+e.slice(1))).join("")}function s(e,t){let r;return()=>{clearTimeout(r),r=setTimeout((function(){e(...arguments)}),t)}}function a(e,t){const n=Object.keys(e),s=Object.keys(t);if(n.length!==s.length)return!1;for(const s of n){const n=e[s],o=t[s],i=r(n)&&r(o);if(i&&!a(n,o)||!i&&n!==o)return!1}return!0}function o(e,t,n=null,s){let a=e.split(".");s||(s=t);let i=a.shift(),c=a.join(".");null!==n&&i.length&&void 0===t[i]&&(t[i]={});let l=t[i];return 0===c.length?null!==n?(t[i]=n,s):t[i]:r(t[i])?o(c,t[i],n,s):n?s:l[i]}function i(e,t){var n=Array.from(arguments);if(n.length){if(1===n.length)return n[1];if(n.length>2){for(;n.length>1;)n[0]=i(n[0],n[1]),n.splice(1,1);return n[0]}if("string"==typeof e){var s=e.match(/\{[^\{\}]*\}/g);s&&s.forEach((function(r){var n=o(r.substr(1,r.length-2),t);void 0!==n&&(e=e.replace(r,n))}))}else if(r(e))switch(e.constructor){case Object:Object.keys(e).forEach((function(r){e.hasOwnProperty(r)&&(e[r]=i(e[r],t))}));break;case Array:e.forEach((function(r,n,s){s[n]=i(e[n],t)}))}return e}console.error("no arguments give to parse")}function c(e){let t=document.createElement("template");return e=e.replace(/<([A-Za-z0-9\-]*)([^>\/]*)(\/>)/gi,"<$1$2></$1>"),t.innerHTML=e,t.content.normalize(),Array.from(t.content.childNodes)}e.r(t),e.d(t,{$d:()=>I,$t:()=>B,DC:()=>S,MC:()=>A,McBase:()=>w,McEvent:()=>h,addListener:()=>b,debounce:()=>s,deepEqual:()=>a,defineCE:()=>k,formValues:()=>F,getCE:()=>x,htmlToElements:()=>c,isObject:()=>r,kebabToPascal:()=>n,makeCO:()=>T,nameSpace:()=>o,parse:()=>i,removeListener:()=>g});var l=new Function("try {return this===window;}catch(e){ return false;}");let u=new Set;l()&&Object.keys(HTMLElement.prototype).filter((e=>/^on/.test(e))).forEach((e=>u.add(e)));class h{#e;#t=!1;#r=!1;constructor(e,t={},r="l"){this.#e=e,this.data=t,this.bubble=r}get type(){return this.#e}get stopped(){return this.#t}get immediateStopped(){return this.#r}stopPropagation(){this.#t=!0}stopImmediatePropagation(){this.stopPropagation(),this.#r=!0}}var f=new Function("try {return this===window;}catch(e){ return false;}");let d=new Set;function p(e,t){let r=[];return e.forEach((e=>{if(e&&e instanceof HTMLElement){const n=e?._mc;!t&&n?r=r.concat(Object.values(e._mc)):t&&n&&n[t]&&r.push(n[t])}})),r}function m(e,t,r=!0){let n=[];for(;e;){if(e._mc&&(t?t&&e._mc[t]&&n.push(e._mc[t]):n=n.concat(Object.values(e._mc)),r))return n;e=e.parentNode}return n}function y(e){return e&&e instanceof HTMLElement}function b(e,t,r,n=!1,s=!1){let a={once:!1};n&&(a.capture=n),s&&(a.once=s),e.addEventListener(t,r,a)}function g(e,t,r){e.removeEventListener(t,r)}function E(e,t,r={}){let n=e;if(!n._mc){let t=S?.debug;S.debug=!1,n._mc=new S(e),S.debug=t}const s=n._mc;return t.length&&!s[t]&&(s[t]=r,e instanceof HTMLElement&&e.setAttribute("_mc","")),r}function v(e,t){if(!t)return;const r=e?._mc||{};r&&r[t]&&delete r[t],!Object.keys(r).length&&e instanceof HTMLElement&&e.hasAttribute("_mc")&&e.removeAttribute("_mc")}function O(e,t,r={}){let n=e?._mc;n&&[...Object.values(n)].forEach((e=>{e?.trigger&&"function"==typeof e?.trigger&&e?.trigger(t,r)}))}f()&&Object.keys(HTMLElement.prototype).filter((e=>/^on/.test(e))).forEach((e=>d.add(e)));class w{#n;#s={};constructor(e){this.#n=new WeakRef(e),this.constructor!==S&&Object.defineProperty(this,"_mc",{get(){return this.#s}})}get target(){return this.#n.deref()}}class A extends w{constructor(e){super(e);let t=this;setTimeout((()=>{t.trigger("Init"),setTimeout((()=>{let e=Object.keys(t?._mc);e.length&&e?.forEach((e=>{let r=t?._mc?.[e];r?.oneInit&&"function"==typeof r?.oneInit&&r.oneInit(new h("Init"))}))}),0)}),0),this.autoAttachListeners()}static trigger=O;trigger(e,t={},r){let n=this;if(r=r||"l",n.constructor!==A&&n.constructor!==S){if(n instanceof A||n instanceof S){const n=this,s="string"!=typeof e?e:new h(e,t,r),a="on"+s.type[0].toUpperCase()+s.type.slice(1);if(s.bubble.indexOf("l")>-1&&(s.immediateStopped||"function"!=typeof n[a]||(n[a](s),n.hasOwnProperty(a)&&delete n[a])),s.stopped||"l"===s.bubble)return n;f()&&/[ud]/.test(s.bubble)&&n instanceof A&&setTimeout((()=>{-1===s.bubble.indexOf("l")&&(s.bubble+="l"),s.bubble.indexOf("u")>-1&&n.parent().forEach((e=>{e instanceof A&&e.trigger(s)})),s.bubble.indexOf("d")>-1&&n.children().forEach((e=>{e instanceof A&&e.trigger(s)}))}),0)}}else[...Object.getOwnPropertyNames(n)].forEach((s=>{n[s]?.trigger&&"function"==typeof n[s]?.trigger&&n[s]?.trigger(e,t,r)}))}autoAttachListeners(){if(!f())return;const e=this.target;if(e instanceof HTMLElement){let t=this;Object.getOwnPropertyNames(t.constructor.prototype).filter((e=>/^on[A-Z]|one[A-Z]/.test(e)&&"function"==typeof t.constructor.prototype[e])).forEach((r=>{let n=/^one/.test(r),s=r.replace(/^on[e]{0,1}/,""),a=s.toLowerCase();n&&Object.defineProperty(this,"on"+s,{configurable:!0,enumerable:!1,writable:!0,value:e=>{t.constructor.prototype[r].bind(t)(e)}}),d.has("on"+a)&&b(e,a,(e=>{t.trigger(s,e)}),!1,n)}))}}}class S extends w{constructor(e){super(e);let t=this,r=t.constructor===S;setTimeout((()=>{t.trigger("Init"),r||setTimeout((()=>{let e=Object.keys(t?._mc);e.length&&e?.forEach((e=>{let r=t?._mc?.[e];r?.oneInit&&"function"==typeof r?.oneInit&&r.oneInit(new h("Init"))}))}),0)}),0),this.autoAttachListeners()}static debug=!1;static add=E;static remove=v;static trigger=O;get _mc(){return this._mc}trigger(e,t={},r){A.prototype.trigger.call(this,e,t,r)}autoAttachListeners(){A.prototype.autoAttachListeners.call(this)}parent(e=""){let t=this.target;return y(t)?m(t.parentNode,e,!0):[]}ancestors(e=""){let t=this?.target;return y(t)?m(this.target.parentNode,e,!1):[]}children(e=""){let t=this?.target;if(!y(t))return[];const r=Math.random().toString().replace(".",""),n='[_mc]:not([temp_id="'+r+'"] [_mc] [_mc])';t.setAttribute("temp_id",r);const s=p([...t.querySelectorAll(n)],e);return t.removeAttribute("temp_id"),s}descendants(e=""){let t=this?.target;return y(t)?p([...t.querySelectorAll("*[_mc]")],e):[]}}class j extends HTMLElement{constructor(){super()}connectedCallback(){S.trigger(this,"Connected")}disconnectedCallback(){S.trigger(this,"Disconnected")}adoptedCallback(){S.trigger(this,"Adopted")}attributeChangedCallback(e,t,r){S.trigger(this,"AttributeChanged",{name:e,oldValue:t,newValue:r})}}function k(e,t,r=[]){if(customElements.get(e))return void console.warn(`IGNORED: Custom element "${e}" is already defined!`);if(!e.includes("-"))throw new Error('createCustomElement: tagName must contain at least one hyphen ("-").');let s=n(e);customElements.define(e,function(e,t){return Object.defineProperty(t,"name",{value:e})}(s,class extends j{instance;constructor(e){super();let r=new t(this,e);S.add(this,s,r)}static get observedAttributes(){return r}}))}function x(e){return customElements.get(e)}const T=(e,t)=>{(t?[t]:[...Object.getOwnPropertyNames(e)]).forEach((t=>{if("_"===t[0]||void 0===e?.[t])return;let n,o=e[t];if(!o.prototype)switch(typeof o){case"string":n=String;break;case"number":n=Number;break;case"boolean":n=Boolean;break;case"object":n=o instanceof Array?Array:Object;break;default:return}let c=class extends n{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,n=r(t.valueOf()),s=t.constructor.bound;if(n){function a(e){if(e.nodeType&&3===e.nodeType){var r=Array.from(e.nodeValue&&e.nodeValue.match(/\{[^\{\}]*\}/g)||[]);if(r.length>0){var o=(c=e.nodeValue||"",function(t){var s,a=!1;return r&&(n?r.forEach((function(e){o.values[e]!==t[e]&&(o.values[e]=t[e],a=!0)})):(o.values=t,a=!0)),a&&(s=c,e.nodeValue=n?i(s,o.values):s.replace(/\{.*\}/g,o.values)),t});o.values=n?{}:void 0,r=Array.from(r).map((e=>e.replace(/[\{\}]/g,"").trim()));let t=n?{}:void 0;r.forEach((function(e){n&&(t[e]="")})),s.push(o)}Array.from(e.childNodes).forEach((function(e){a(e)})),t.notify()}var c;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 n=function(t){return function(s){var a,o=!1;return r&&r.forEach((function(e){n.values[e]!==s[e]&&(n.values[e]=s[e],o=!0)})),o&&(a=t,e.nodeValue=i(a,n.values)),s}}(t.value||"");n.values={},r=Array.from(r).map((e=>e.replace(/[\{\}]/g,"").trim()));let a={};r.forEach((function(e){a[e]=""})),s.push(n)}})),Array.from(e.childNodes).forEach((function(e){a(e)})),t.notify()),e.nodeType&&11===e.nodeType&&Array.from(e.childNodes).forEach((function(e){a(e)}))}a(e),s.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 c(o);Object.defineProperty(e,t,{enumerable:!0,get(){if(r(l.valueOf())){let e=structuredClone(Object.assign({},l));setTimeout(s((function(){a(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,n=l.constructor.callbacks,o=l.constructor.bound;l=new c(structuredClone(Object.assign({},e))),l.constructor.callbacks=r,l.constructor.callbacks=n,l.constructor.bound=o,setTimeout(s((function(){a(structuredClone(Object.assign({},l)),t)||l.notify()}),0),0)}else{let t=l.valueOf(),r=l.constructor.callbacks;l=new c(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]=o}))},_=e=>{let t=new Set;return e.forEach((e=>{(e=e.trim()).split(" ").forEach((e=>{""!==e&&t.add(e)}))})),Array.from(t)},C=e=>{let t=I("input,select,textarea",e).array,r={};return t.forEach((t=>{const n=t.getAttribute("name")||"undefined";if(n){let s;switch((e=>e instanceof HTMLInputElement?"input":e instanceof HTMLSelectElement?"select":e instanceof HTMLTextAreaElement?"textarea":"")(t)){case"input":s=new N(t,e),Object.defineProperty(r,n,{enumerable:!0,configurable:!0,get:()=>s.val,set:e=>{s.val=e}});break;case"select":s=new M(t),Object.defineProperty(r,n,{enumerable:!0,configurable:!0,get:()=>s.val,set:e=>{s.val=e}});break;case"textarea":s=new P(t),Object.defineProperty(r,n,{enumerable:!0,configurable:!0,get:()=>s.val,set:e=>{s.val=e}});break;default:console.warn("handler missing:",n,"for",t)}}})),r};class L{constructor(e){}}class N extends L{#a;#e;#o;constructor(e,t){super(e),this.#a=e,this.#e=e.type,this.#o=t}get val(){let e,t=this;switch(t.#e){case"radio":const r=I(`input[type="radio"][name="${this.#a.getAttribute("name")}"]`,this.#o).filter((e=>e.checked));return r.length?(e=r.array[0],e.value):"";case"checkbox":return t.#a.checked;default:return t.#a.value}return""}set val(e){let t=this;switch(t.#e){case"radio":const r=`input[type="radio"][name="${this.#a.getAttribute("name")}"]`,n=I(r,this.#o);if(!n.length)return;if(""===e)return void n.forEach((e=>{e.checked&&(e.checked=!1)}));const s=n.filter((t=>t.getAttribute("value")===e));if(!s.length)return;return void(s.array[0].checked=!0);case"checkbox":t.#a.checked=e;break;default:t.#a.value=e}}}class M extends L{#a;#i=!1;constructor(e){super(e),this.#a=e,this.#i="select-multiple"===e.type}get val(){const e=[];return I(this.#a.querySelectorAll("option")).filter((e=>e.selected)).forEach((t=>{t.selected&&e.push(t.value)})),this.#i?e:e.length?e[0]:""}set val(e){e="string"==typeof e?[e]:e,I(this.#a.querySelectorAll("option")).forEach((t=>{e.indexOf(t.value)>-1?(t.setAttribute("selected",!0),t.selected=!0):(t.removeAttribute("selected"),t.selected=!1)}))}}class P extends L{#a;constructor(e){super(e),this.#a=e}get val(){return this.#a.value}set val(e){this.#a.value=e}}class H{#c=new Set;get set(){return this.#c}get array(){return Array.from(this.#c)}set set(e){this.#c=e}get length(){return this.#c.size}constructor(e,t=document.body){if(new Set,!e)return this}$t(e){let t=new $;return this.#c.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 I(e,t).forEach((e=>{r.#c.add(e)})),r}addClass(...e){return e=_(e),this.forEach((t=>{t.classList.add(...e)})),this}after(e,t){let r=this,n=I(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=I(e,t);return r&&n.forEach((e=>{r.append(e)})),this}appendTo(e,t){let r=I(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=>{I(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=I(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.#c.forEach((e=>{Array.from(e.children).forEach((e=>{n.add(e)}))})),r=I([...n]),e){let n=I(e,t);r.filter((e=>n.has(e)))}return r}descendants(e,t){let r=this,n=new Set;if(r.#c.forEach((e=>{e.querySelectorAll("*").forEach((e=>{n.add(e)}))})),r=I([...n]),e){let n=I(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,s=!1;return e&&(s=I(e,t)),r.#c.forEach((e=>{e.parentNode&&n.add(e.parentNode.children[0])})),r=I([...n]),e&&r.filter((e=>s.has(e))),r}has(e){return this.#c.has(e)}hasClass(...e){return e=_(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.#c.forEach((e=>{let t=e.parentNode?.children;t&&n.add(Array.from(t).at(-1))})),r=I([...n]),e){let n=I(e,t);r.filter((e=>n.has(e)))}return r}next(e,t){let r=this,n=new Set;if(r.#c.forEach((e=>{let t=e.parentNode?.children;if(t){let r=Array.from(t),s=r.indexOf(e)+1;s<r.length&&n.add(r.at(s))}})),r=I([...n]),e){let n=I(e,t);r.filter((e=>n.has(e)))}return r}normalize(){return this.#c.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){g(e,r,t)}))})),this}on(e,t,r=!1,n=!1){let s=this,a=e.indexOf(" ")>-1?e.split(" ").filter((e=>""!==e)):[e];function o(){o.cb.apply(s,Array.from(arguments))}return o.cb=t,s.forEach((e=>{a.forEach((function(t){b(e,t,o,r,n)}))})),o}one(e,t,r=!1){let n=this,s=e.indexOf(" ")>-1?e.split(" ").filter((e=>""!==e)):[e];function a(){a.cb.apply(n,Array.from(arguments))}return a.cb=t,n.forEach((e=>{s.forEach((function(t){b(e,t,a,r,!0)}))})),a}parent(e,t){let r=this,n=new Set;if(r.#c.forEach((e=>{e.parentNode&&"HTML"!==e.parentNode.tagName&&n.add(e.parentNode)})),r=I([...n]),e){let n=I(e,t);r.filter((e=>n.has(e)))}return r}parents(e,t){let r=this,n=new Set;if(r.#c.forEach((e=>{let t=e;for(;t.parentNode&&"HTML"!==t.parentNode.tagName;)t=t.parentNode,n.add(t)})),r=I([...n]),e){let n=I(e,t);r.filter((e=>n.has(e)))}return r}prepend(e,t){let r=this.array[0],n=I(e,t);return r&&n.forEach((e=>{r.prepend(e)})),this}prev(e,t){let r=this,n=new Set;if(r.#c.forEach((e=>{let t=e.parentNode?.children;if(t){let r=Array.from(t),s=r.indexOf(e)-1;s>-1&&n.add(r.at(s))}})),r=I([...n]),e){let n=I(e,t);r.filter((e=>n.has(e)))}return r}removeClass(...e){return e=_(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=_(e),this.forEach((t=>{t.classList.toggle(...e)})),this}trigger(e,t={},r=!1,n=!1,s=!1){let a,o={bubbles:r,cancelable:n,composed:s},i=e.indexOf(" ")>-1?e.split(" "):[e];return this.#c.forEach((e=>{i.forEach((function(r){a=new Event(r,o),a.data=t,e.dispatchEvent(a)}))})),this}val(e,t){if(!this.length)return this;const r=this;let n,s=C(r.array[0]);var a;return e?null!=(a=e)&&"object"==typeof a?(Object.assign(s,e),n=r):"string"==typeof e&&(void 0===t?n=s[e]:(s[e]=t,n=r)):n=Object.assign({},s),n}values(e){const t=this;let r={};if(!t.length)return console.warn("no dom selection to search inputs in"),{};let n=C(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 I(this.array.at(e))}concat(e){let t=this;return(e instanceof H?e.array:e).forEach((e=>{t.#c.add(e)})),t}entries(){return this.array.entries()}every(e,t){return this.array.every(e,t)}filter(e,t){return this.#c=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.#c.add(e)})),this}shift(){let e=this,t=e.#c.size?e.array[0]:void 0;return t&&e.#c.delete(t),t}slice(e,t){return I(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),I(n)}}class ${#c=new Set;get set(){return this.#c}get array(){return Array.from(this.#c)}set set(e){this.#c=e}get length(){return this.#c.size}set length(e){}constructor(e,t=document.body){if(!e)return this;I(e,t).forEach((e=>{B(e).forEach((e=>{this.#c.add(e)}))}))}$d(e,t=document.body){let r=new H,n=new Set,s=!!e||!1,a=new Set;return s&&(a=I(e,t).set),this.#c.forEach((e=>{s&&!a.has(e._tg)||n.add(e._tg)})),r.set=n,r}children(e){let t=this,r=new Set;return t.#c.forEach((t=>{t.children(e).forEach((e=>{r.add(e)}))})),t.#c=r,t}descendants(e){let t=this,r=new Set;return t.#c.forEach((t=>{t.descendants(e).forEach((e=>{r.add(e)}))})),t.#c=r,t}first(e){let t=this,r=new Set;return t.#c.forEach((e=>{e.parent().children().$d().first().$t().forEach((e=>{r.add(e)}))})),t.#c=r,e&&t.filter((t=>t.nameSpace=e)),t}has(e){return this.#c.has(e)}last(e){let t=this,r=new Set;return t.#c.forEach((e=>{e.parent().children().$d().last().$t().forEach((e=>{r.add(e)}))})),t.#c=r,e&&t.filter((t=>t.nameSpace=e)),t}next(e){let t=this,r=new Set;return t.#c.forEach((e=>{let t,n=new Set;for(t=e._tg;null!==t.nextElementSibling;)t=t.nextElementSibling,n.add(t);B([...n]).$d().first().$t().forEach((e=>{r.add(e)}))})),t.#c=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){g(e,`[TB]${r}`,t)}))})),this}on(e,t,r=!1){let n=this,s=e.indexOf(" ")>-1?e.split(" ").filter((e=>""!==e)):[e];function a(){a.cb.apply(n,Array.from(arguments))}return a.cb=t,n.forEach((e=>{s.forEach((function(t){b(e._tg,`[TB]${t}`,a,!1,r)}))})),a}one(e,t){let r=this,n=e.indexOf(" ")>-1?e.split(" ").filter((e=>""!==e)):[e];function s(){s.cb.apply(r,Array.from(arguments))}return s.cb=t,r.forEach((e=>{n.forEach((function(t){b(e._tg,`[TB]${t}`,s,!1,!0)}))})),s}parent(e){let t=this,r=new Set;return t.#c.forEach((t=>{t.parent(e).forEach((e=>{r.add(e)}))})),t.#c=r,t}parents(e){let t=this,r=new Set;return t.#c.forEach((t=>{t.parents(e).forEach((e=>{r.add(e)}))})),t.#c=r,t}prev(e){let t=this,r=new Set;return t.#c.forEach((e=>{let t,n=new Set;for(t=e._tg;null!==t.previousElementSibling;)t=t.previousElementSibling,n.add(t);B([...n]).$d().last().$t().forEach((e=>{r.add(e)}))})),t.#c=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 B(this.array.at(e))}concat(e){let t=this;return e.forEach((e=>{t.#c.add(e)})),t}entries(){return this.array.entries()}every(e,t){return this.array.every(e,t)}filter(e,t){return B(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.#c=new Set(e),t}push(e){return this.#c.add(e),this}shift(){let e=this.array.shift();return this.#c.delete(e),e}slice(e,t){return B(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 B(n)}}const I=(e,t=document)=>{let r=new Set;return e instanceof Array?(e.forEach((e=>{I(e,t).forEach((e=>{r.add(e)}))})),new H([...r])):new H(e,t)},B=(e,t=document)=>I(e,t).$t();class q{constructor(e){}}class V extends q{#a;#e;#o;constructor(e,t){super(e),this.#a=e,this.#e=e.type,this.#o=t}get val(){let e,t=this;switch(t.#e){case"radio":const r=[...(this.#o||document).querySelectorAll(`input[type="radio"][name="${this.#a.getAttribute("name")}"]`)].filter((e=>e.checked));return r.length?(e=r?.[0],e.value):"";case"checkbox":return t.#a.checked;default:return t.#a.value}return""}set val(e){let t=this;switch(t.#e){case"radio":const r=[...(this.#o||document).querySelectorAll(`input[type="radio"][name="${this.#a.getAttribute("name")}"]`)];if(!r.length)return;if(""===e)return void r.forEach((e=>{e.checked&&(e.checked=!1)}));const n=r.filter((t=>t.getAttribute("value")===e));if(!n.length)return;return void((n?.[0]).checked=!0);case"checkbox":t.#a.checked=e;break;default:t.#a.value=e}}}class z extends q{#a;#i=!1;constructor(e){super(e),this.#a=e,this.#i="select-multiple"===e.type}get val(){const e=[];return[...this.#a.querySelectorAll("option")].filter((e=>e.selected)).forEach((t=>{t.selected&&e.push(t.value)})),this.#i?e:e.length?e[0]:""}set val(e){e="string"==typeof e?[e]:e,[...this.#a.querySelectorAll("option")].forEach((t=>{e.indexOf(t.value)>-1?(t.setAttribute("selected","selected"),t.selected=!0):(t.removeAttribute("selected"),t.selected=!1)}))}}class D extends q{#a;constructor(e){super(e),this.#a=e}get val(){return this.#a.value}set val(e){this.#a.value=e}}const F=(e,t={},r,n)=>{let s=(e=>{let t=[...(e||document).querySelectorAll("input,select,textarea")],r={};return t.forEach((t=>{const n=t.getAttribute("name")||"undefined";if(n){let s;switch((e=>e instanceof HTMLInputElement?"input":e instanceof HTMLSelectElement?"select":e instanceof HTMLTextAreaElement?"textarea":"")(t)){case"input":s=new V(t,e),Object.defineProperty(r,n,{enumerable:!0,configurable:!0,get:()=>s.val,set:e=>{s.val=e}});break;case"select":s=new z(t),Object.defineProperty(r,n,{enumerable:!0,configurable:!0,get:()=>s.val,set:e=>{s.val=e}});break;case"textarea":s=new D(t),Object.defineProperty(r,n,{enumerable:!0,configurable:!0,get:()=>s.val,set:e=>{s.val=e}});break;default:console.warn("handler missing:",n,"for",t)}}})),r})(e);function a(e){Object.keys(e).forEach((t=>{s.hasOwnProperty(t)&&e.hasOwnProperty(t)&&(s[t]=e[t])}))}if(Object.keys(t).length>0&&a(t),void 0!==n){let t=r[n];t.constructor?.hasFormHandler||(t.constructor.hasFormHandler=!0,t.observe(a)),r[n].observe((()=>{})),[...e.querySelectorAll("input, textarea, select")].forEach((e=>{b(e,"keyup",(()=>{r[n]=structuredClone(Object.assign(s))})),b(e,"change",(()=>{r[n]=structuredClone(Object.assign(s))})),e instanceof HTMLSelectElement&&b(e,"select",(()=>{r[n]=structuredClone(Object.assign(s))}))}))}return n?r[n]:Object.assign({},s)};return t})()));
|
package/dist/test.ts
CHANGED