vivth 1.5.2 → 1.5.4

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/README.md CHANGED
@@ -198,6 +198,7 @@ npm i vivth
198
198
  - [neutral.E](#e)
199
199
  - [neutral.NewStyleSheetAsync](#newstylesheetasync)
200
200
  - [neutral.NewStyleSheetSync](#newstylesheetsync)
201
+ - [neutral.WC_DefineCustomElement](#wc_definecustomelement)
201
202
  - [neutral.WC_TagName_type](#wc_tagname_type)
202
203
  - [neutral.EnsureValidTag](#ensurevalidtag)
203
204
  - [neutral.IsInViewPortSignal](#isinviewportsignal)
@@ -3923,9 +3924,9 @@ f.forInSignals((key, signal) => {
3923
3924
 
3924
3925
  #### reference: `WalkThrough`
3925
3926
 
3926
- - collection of static `methods` to walktrhough things, instead of regular looping;
3927
- - usefull to iterator that might be modified during iteration;
3928
- - mostlikely to be less performant, but with better result clarity;
3927
+ - collection of static `methods` to walkthrough things, instead of regular looping;
3928
+ - useful for iterators that might be modified during iteration;
3929
+ - most likely to be less performant, but with better result clarity;
3929
3930
 
3930
3931
  #### reference: `WalkThrough.set`
3931
3932
 
@@ -3935,7 +3936,7 @@ f.forInSignals((key, signal) => {
3935
3936
  /**
3936
3937
  * @template VAL
3937
3938
  * @param {Set<VAL>} setInstance
3938
- * @param {(value:VAL)=>void} callback
3939
+ * @param {(value: VAL) => void} callback
3939
3940
  * @returns {void}
3940
3941
  */
3941
3942
  ```
@@ -3957,7 +3958,7 @@ WalkThrough.set(setOfSomething, (value) => {
3957
3958
  /**
3958
3959
  * @template KEY, VAL
3959
3960
  * @param {Map<KEY, VAL>} mapInstance
3960
- * @param {(res:[key: KEY, value: VAL]) => void} callback
3961
+ * @param {(entry: [key: KEY, value: VAL]) => void} callback
3961
3962
  * @returns {void}
3962
3963
  */
3963
3964
  ```
@@ -3979,7 +3980,7 @@ WalkThrough.map(mapOfSomething, ([key, value]) => {
3979
3980
  /**
3980
3981
  * @template VAL
3981
3982
  * @param {VAL[]} arrayInstance
3982
- * @param {(res:[value: VAL, index: number]) => void} callback
3983
+ * @param {(entry: [index: number, value: VAL]) => void} callback
3983
3984
  * @returns {void}
3984
3985
  */
3985
3986
  ```
@@ -3988,7 +3989,7 @@ WalkThrough.map(mapOfSomething, ([key, value]) => {
3988
3989
 
3989
3990
  ```js
3990
3991
  import { WalkThrough } from "vivth/neutral";
3991
- WalkThrough.array(arrayOfSomething, ([value, index]) => {
3992
+ WalkThrough.array(arrayOfSomething, ([index, value]) => {
3992
3993
  // code
3993
3994
  });
3994
3995
  ```
@@ -6722,15 +6723,13 @@ const esWatcherInstance = this.registerObjectWithAutoCleanup(
6722
6723
  #### reference: `WC_createElement_bind`
6723
6724
 
6724
6725
  - typesafe factory generator for creating element of `WC_extendsA`/`WC_extendsB` class;
6725
- - this function is returned by static method `.define`;
6726
- > - bind it with static property;
6727
6726
  - uses `lit-html` under the hood;
6728
6727
 
6729
6728
  ```js
6730
6729
  /**
6731
6730
  * @template {(new (...args: any[]) => HTMLElement) & {
6732
6731
  * tagName: string;
6733
- * extendIs: string;
6732
+ * extendIsValue: string;
6734
6733
  * observedAttributes?: readonly string[];
6735
6734
  * namedSlots?: readonly string[];
6736
6735
  * props?: Record<string, keyof TypeMap|(new (...args:any[])=>any)>;
@@ -6758,9 +6757,7 @@ const esWatcherInstance = this.registerObjectWithAutoCleanup(
6758
6757
  - <i>example</i>:
6759
6758
 
6760
6759
  ```js
6761
- // webcomponent context via `WC_extends`
6762
- static createElement = this.define(...args);
6763
- //
6760
+
6764
6761
  ```
6765
6762
 
6766
6763
  \*) <sub>[go to list of exported API and typehelpers](#list-of-exported-api-and-typehelpers)</sub>
@@ -7103,6 +7100,43 @@ text.nodeValue = "hello world";
7103
7100
 
7104
7101
  ---
7105
7102
 
7103
+ <h2 id="wc_definecustomelement">neutral.WC_DefineCustomElement</h2>
7104
+
7105
+ #### reference: `WC_DefineCustomElement`
7106
+
7107
+ - helper funtion for wecomponent instantiator;
7108
+ - it uses WC_createElement_bind, which uses `lit-html`;
7109
+ - alternatively, if you want to create a baseline component that are not to be , you can just
7110
+
7111
+ ```js
7112
+ /**
7113
+ * @template {new (...args: any[]) => HTMLElement} BASE_CONSTRUCTOR
7114
+ * @template {{
7115
+ * class?:string;
7116
+ * style?:string;
7117
+ * observedAttributes?: readonly string[];
7118
+ * namedSlots?: readonly string[];
7119
+ * props?: Record<string, keyof TypeMap|(new (...args:any[])=>any)>;
7120
+ * }} STANDARD
7121
+ * @template {(BASE_CONSTRUCTOR) & {
7122
+ * tagName: string;
7123
+ * extendIsValue: string;
7124
+ * observedAttributes?: STANDARD["observedAttributes"];
7125
+ * namedSlots?: STANDARD["namedSlots"];
7126
+ * props?: STANDARD["props"];
7127
+ * }} CREATEARGS
7128
+ * @template {string} TAG
7129
+ * @param {WC_TagName_type<TAG>} tagName
7130
+ * @param {CREATEARGS} classRef
7131
+ * @param {ElementDefinitionOptions} elementDefinitionOptions
7132
+ * @returns {ReturnType<typeof WC_createElement_bind<CREATEARGS>>}
7133
+ */
7134
+ ```
7135
+
7136
+ \*) <sub>[go to list of exported API and typehelpers](#list-of-exported-api-and-typehelpers)</sub>
7137
+
7138
+ ---
7139
+
7106
7140
  <h2 id="wc_tagname_type">neutral.WC_TagName_type</h2>
7107
7141
 
7108
7142
  - jsdoc types:
@@ -7379,7 +7413,7 @@ text.nodeValue = "hello world";
7379
7413
  * }} STANDARD
7380
7414
  * @template {(BASE_CONSTRUCTOR) & {
7381
7415
  * tagName: string;
7382
- * extendIs: string;
7416
+ * extendIsValue: string;
7383
7417
  * observedAttributes?: STANDARD["observedAttributes"];
7384
7418
  * namedSlots?: STANDARD["namedSlots"];
7385
7419
  * props?: STANDARD["props"];
@@ -7418,7 +7452,7 @@ text.nodeValue = "hello world";
7418
7452
  * })=>OBJ;
7419
7453
  * }) & {
7420
7454
  * tagName:string;
7421
- * extendIs:string;
7455
+ * extendIsValue:string;
7422
7456
  * namedSlots: STANDARD["namedSlots"];
7423
7457
  * observedAttributes: STANDARD["observedAttributes"];
7424
7458
  * createNamedSlot: typeof WC_createNamedSlot<STANDARD>;
@@ -7441,7 +7475,9 @@ text.nodeValue = "hello world";
7441
7475
 
7442
7476
  ```js
7443
7477
  export MyWebComponent extends WC_extendsA(HTMLElement, {...options}){
7444
- static create = this.define('my-webcomponent');
7478
+ static create = WC_DefineCustomElement('my-webcomponent', this);
7479
+ // you can skip the defining with WC_DefineCustomElement if the class are meant to be extended abstract;
7480
+ // or if you want to opt out from using `lit-html` template;
7445
7481
  }
7446
7482
  ```
7447
7483
 
@@ -7564,7 +7600,7 @@ text.nodeValue = "hello world";
7564
7600
  * }} STANDARD
7565
7601
  * @template {(BASE_CONSTRUCTOR) & {
7566
7602
  * tagName: string;
7567
- * extendIs: string;
7603
+ * extendIsValue: string;
7568
7604
  * observedAttributes?: STANDARD["observedAttributes"];
7569
7605
  * namedSlots?: STANDARD["namedSlots"];
7570
7606
  * props?: STANDARD["props"];
@@ -7605,7 +7641,7 @@ text.nodeValue = "hello world";
7605
7641
  * })=>OBJ;
7606
7642
  * }) & {
7607
7643
  * tagName:string;
7608
- * extendIs:string;
7644
+ * extendIsValue:string;
7609
7645
  * namedSlots: STANDARD["namedSlots"];
7610
7646
  * observedAttributes: STANDARD["observedAttributes"];
7611
7647
  * createNamedSlot: typeof WC_createNamedSlot<STANDARD>;
@@ -7624,6 +7660,16 @@ text.nodeValue = "hello world";
7624
7660
  */
7625
7661
  ```
7626
7662
 
7663
+ - <i>example</i>:
7664
+
7665
+ ```js
7666
+ export MyWebComponent extends WC_extendsA(HTMLElement, {...options}){
7667
+ static create = WC_DefineCustomElement('my-webcomponent', this);
7668
+ // you can skip the defining if the class are meant to be extended abstract;
7669
+ // or if you want to opt out from using `lit-html` template;
7670
+ }
7671
+ ```
7672
+
7627
7673
  #### reference: `WC_extendsB_instance.props`
7628
7674
 
7629
7675
  - props objects from define -> createElement;
@@ -105,6 +105,7 @@ export { CSS } from "../../../src/web/common/CSS.mjs";
105
105
  export { E } from "../../../src/web/common/E.mjs";
106
106
  export { NewStyleSheetAsync } from "../../../src/web/common/NewStyleSheetAsync.mjs";
107
107
  export { NewStyleSheetSync } from "../../../src/web/common/NewStyleSheetSync.mjs";
108
+ export { WC_DefineCustomElement } from "../../../src/web/common/WC_DefineCustomElement.mjs";
108
109
  export { IsInViewPortSignal } from "../../../src/web/signals/IsInViewPortSignal.mjs";
109
110
  export { ObserverSignal } from "../../../src/web/signals/ObserverSignal.mjs";
110
111
  export { WC_litRef } from "../../../src/web/signals/WC_litRef.mjs";
@@ -67,6 +67,7 @@ export { CSS } from "../../../src/web/common/CSS.mjs";
67
67
  export { E } from "../../../src/web/common/E.mjs";
68
68
  export { NewStyleSheetAsync } from "../../../src/web/common/NewStyleSheetAsync.mjs";
69
69
  export { NewStyleSheetSync } from "../../../src/web/common/NewStyleSheetSync.mjs";
70
+ export { WC_DefineCustomElement } from "../../../src/web/common/WC_DefineCustomElement.mjs";
70
71
  export { IsInViewPortSignal } from "../../../src/web/signals/IsInViewPortSignal.mjs";
71
72
  export { ObserverSignal } from "../../../src/web/signals/ObserverSignal.mjs";
72
73
  export { WC_litRef } from "../../../src/web/signals/WC_litRef.mjs";
@@ -1,28 +1,29 @@
1
1
  /**
2
2
  * @description
3
- * - collection of static `methods` to walktrhough things, instead of regular looping;
4
- * - usefull to iterator that might be modified during iteration;
5
- * - mostlikely to be less performant, but with better result clarity;
3
+ * - collection of static `methods` to walkthrough things, instead of regular looping;
4
+ * - useful for iterators that might be modified during iteration;
5
+ * - most likely to be less performant, but with better result clarity;
6
6
  */
7
7
  export class WalkThrough {
8
8
  /**
9
- * @param {Iterator<any, any, any>} iterator
10
- * @param {(...any:any[])=>void} callback
9
+ * @template T
10
+ * @param {Iterator<T, any, any>} iterator
11
+ * @param {(value: T) => void} callback
11
12
  * @returns {void}
12
13
  */
13
- static #handler: (iterator: Iterator<any, any, any>, callback: (...any: any[]) => void) => void;
14
+ static #handler<T>(iterator: Iterator<T, any, any>, callback: (value: T) => void): void;
14
15
  /**
15
16
  * @description
16
17
  * - method helper to WalkThrough `Set`;
17
18
  * @template VAL
18
19
  * @param {Set<VAL>} setInstance
19
- * @param {(value:VAL)=>void} callback
20
+ * @param {(value: VAL) => void} callback
20
21
  * @returns {void}
21
22
  * @example
22
23
  * import { WalkThrough } from 'vivth/neutral';
23
24
  *
24
25
  * WalkThrough.set(setOfSomething, (value) => {
25
- * // code
26
+ * // code
26
27
  * })
27
28
  */
28
29
  static set<VAL>(setInstance: Set<VAL>, callback: (value: VAL) => void): void;
@@ -31,29 +32,29 @@ export class WalkThrough {
31
32
  * - method helper to WalkThrough `Map`;
32
33
  * @template KEY, VAL
33
34
  * @param {Map<KEY, VAL>} mapInstance
34
- * @param {(res:[key: KEY, value: VAL]) => void} callback
35
+ * @param {(entry: [key: KEY, value: VAL]) => void} callback
35
36
  * @returns {void}
36
37
  * @example
37
38
  * import { WalkThrough } from 'vivth/neutral';
38
39
  *
39
40
  * WalkThrough.map(mapOfSomething, ([key, value]) => {
40
- * // code
41
+ * // code
41
42
  * })
42
43
  */
43
- static map<KEY, VAL>(mapInstance: Map<KEY, VAL>, callback: (res: [key: KEY, value: VAL]) => void): void;
44
+ static map<KEY, VAL>(mapInstance: Map<KEY, VAL>, callback: (entry: [key: KEY, value: VAL]) => void): void;
44
45
  /**
45
46
  * @description
46
47
  * - method helper to WalkThrough `Array`;
47
48
  * @template VAL
48
49
  * @param {VAL[]} arrayInstance
49
- * @param {(res:[value: VAL, index: number]) => void} callback
50
+ * @param {(entry: [index: number, value: VAL]) => void} callback
50
51
  * @returns {void}
51
52
  * @example
52
53
  * import { WalkThrough } from 'vivth/neutral';
53
54
  *
54
- * WalkThrough.array(arrayOfSomething, ([value, index]) => {
55
- * // code
55
+ * WalkThrough.array(arrayOfSomething, ([index, value]) => {
56
+ * // code
56
57
  * })
57
58
  */
58
- static array<VAL>(arrayInstance: VAL[], callback: (res: [value: VAL, index: number]) => void): void;
59
+ static array<VAL>(arrayInstance: VAL[], callback: (entry: [index: number, value: VAL]) => void): void;
59
60
  }
@@ -29,7 +29,7 @@
29
29
  * }} STANDARD
30
30
  * @template {(BASE_CONSTRUCTOR) & {
31
31
  * tagName: string;
32
- * extendIs: string;
32
+ * extendIsValue: string;
33
33
  * observedAttributes?: STANDARD["observedAttributes"];
34
34
  * namedSlots?: STANDARD["namedSlots"];
35
35
  * props?: STANDARD["props"];
@@ -68,7 +68,7 @@
68
68
  * })=>OBJ;
69
69
  * }) & {
70
70
  * tagName:string;
71
- * extendIs:string;
71
+ * extendIsValue:string;
72
72
  * namedSlots: STANDARD["namedSlots"];
73
73
  * observedAttributes: STANDARD["observedAttributes"];
74
74
  * createNamedSlot: typeof WC_createNamedSlot<STANDARD>;
@@ -86,7 +86,9 @@
86
86
  * @returns {RET}
87
87
  * @example
88
88
  * export MyWebComponent extends WC_extendsA(HTMLElement, {...options}){
89
- * static create = this.define('my-webcomponent');
89
+ * static create = WC_DefineCustomElement('my-webcomponent', this);
90
+ * // you can skip the defining with WC_DefineCustomElement if the class are meant to be extended abstract;
91
+ * // or if you want to opt out from using `lit-html` template;
90
92
  * }
91
93
  */
92
94
  export function WC_extendsA<BASE_CONSTRUCTOR extends new (...args: any[]) => HTMLElement, STANDARD extends {
@@ -97,7 +99,7 @@ export function WC_extendsA<BASE_CONSTRUCTOR extends new (...args: any[]) => HTM
97
99
  props?: Record<string, keyof TypeMap | (new (...args: any[]) => any)>;
98
100
  }, CREATEARGS extends (BASE_CONSTRUCTOR) & {
99
101
  tagName: string;
100
- extendIs: string;
102
+ extendIsValue: string;
101
103
  observedAttributes?: STANDARD["observedAttributes"];
102
104
  namedSlots?: STANDARD["namedSlots"];
103
105
  props?: STANDARD["props"];
@@ -121,7 +123,7 @@ export function WC_extendsA<BASE_CONSTRUCTOR extends new (...args: any[]) => HTM
121
123
  }) => OBJ;
122
124
  }) & {
123
125
  tagName: string;
124
- extendIs: string;
126
+ extendIsValue: string;
125
127
  namedSlots: STANDARD["namedSlots"];
126
128
  observedAttributes: STANDARD["observedAttributes"];
127
129
  createNamedSlot: typeof WC_createNamedSlot<STANDARD>;
@@ -29,7 +29,7 @@
29
29
  * }} STANDARD
30
30
  * @template {(BASE_CONSTRUCTOR) & {
31
31
  * tagName: string;
32
- * extendIs: string;
32
+ * extendIsValue: string;
33
33
  * observedAttributes?: STANDARD["observedAttributes"];
34
34
  * namedSlots?: STANDARD["namedSlots"];
35
35
  * props?: STANDARD["props"];
@@ -70,7 +70,7 @@
70
70
  * })=>OBJ;
71
71
  * }) & {
72
72
  * tagName:string;
73
- * extendIs:string;
73
+ * extendIsValue:string;
74
74
  * namedSlots: STANDARD["namedSlots"];
75
75
  * observedAttributes: STANDARD["observedAttributes"];
76
76
  * createNamedSlot: typeof WC_createNamedSlot<STANDARD>;
@@ -86,6 +86,12 @@
86
86
  * @param {BASE_CONSTRUCTOR} Base
87
87
  * @param {STANDARD} [staticMember]
88
88
  * @returns {RET}
89
+ * @example
90
+ * export MyWebComponent extends WC_extendsA(HTMLElement, {...options}){
91
+ * static create = WC_DefineCustomElement('my-webcomponent', this);
92
+ * // you can skip the defining if the class are meant to be extended abstract;
93
+ * // or if you want to opt out from using `lit-html` template;
94
+ * }
89
95
  */
90
96
  export function WC_extendsB<BASE_CONSTRUCTOR extends new (...args: any[]) => HTMLElement, STANDARD extends {
91
97
  class?: string;
@@ -95,7 +101,7 @@ export function WC_extendsB<BASE_CONSTRUCTOR extends new (...args: any[]) => HTM
95
101
  props?: Record<string, keyof TypeMap | (new (...args: any[]) => any)>;
96
102
  }, CREATEARGS extends (BASE_CONSTRUCTOR) & {
97
103
  tagName: string;
98
- extendIs: string;
104
+ extendIsValue: string;
99
105
  observedAttributes?: STANDARD["observedAttributes"];
100
106
  namedSlots?: STANDARD["namedSlots"];
101
107
  props?: STANDARD["props"];
@@ -121,7 +127,7 @@ export function WC_extendsB<BASE_CONSTRUCTOR extends new (...args: any[]) => HTM
121
127
  }) => OBJ;
122
128
  }) & {
123
129
  tagName: string;
124
- extendIs: string;
130
+ extendIsValue: string;
125
131
  namedSlots: STANDARD["namedSlots"];
126
132
  observedAttributes: STANDARD["observedAttributes"];
127
133
  createNamedSlot: typeof WC_createNamedSlot<STANDARD>;
@@ -1,12 +1,10 @@
1
1
  /**
2
2
  * @description
3
3
  * - typesafe factory generator for creating element of `WC_extendsA`/`WC_extendsB` class;
4
- * - this function is returned by static method `.define`;
5
- * >- bind it with static property;
6
4
  * - uses `lit-html` under the hood;
7
5
  * @template {(new (...args: any[]) => HTMLElement) & {
8
6
  * tagName: string;
9
- * extendIs: string;
7
+ * extendIsValue: string;
10
8
  * observedAttributes?: readonly string[];
11
9
  * namedSlots?: readonly string[];
12
10
  * props?: Record<string, keyof TypeMap|(new (...args:any[])=>any)>;
@@ -29,17 +27,14 @@
29
27
  * },
30
28
  * )=>InstanceType<BASE_CONSTRUCTOR>}
31
29
  * @example
32
- * // webcomponent context via `WC_extends`
33
- * static createElement = this.define(...args);
34
- * //
35
30
  */
36
31
  export function WC_createElement_bind<BASE_CONSTRUCTOR extends (new (...args: any[]) => HTMLElement) & {
37
32
  tagName: string;
38
- extendIs: string;
33
+ extendIsValue: string;
39
34
  observedAttributes?: readonly string[];
40
35
  namedSlots?: readonly string[];
41
36
  props?: Record<string, keyof TypeMap | (new (...args: any[]) => any)>;
42
- }>({ tagName, extendIs, namedSlots }: BASE_CONSTRUCTOR): (param?: {
37
+ }>({ tagName, extendIsValue, namedSlots }: BASE_CONSTRUCTOR): (param?: {
43
38
  attrs?: BASE_CONSTRUCTOR["observedAttributes"] extends readonly string[] ? Partial<Record<ArrayToKeys<BASE_CONSTRUCTOR["observedAttributes"]>, string>> : undefined;
44
39
  props?: { [K in keyof NonNullable<BASE_CONSTRUCTOR["props"]>]: NonNullable<BASE_CONSTRUCTOR["props"]>[K] extends keyof TypeMap ? TypeMap[NonNullable<BASE_CONSTRUCTOR["props"]>[K]] : InstanceType<NonNullable<BASE_CONSTRUCTOR["props"]>[K]>; };
45
40
  children?: (slotName: Record<ArrayToKeys<BASE_CONSTRUCTOR["namedSlots"]>, string>) => TemplateResult;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @import {WC_TagName_type} from '../common/WC_TagName_type.mjs'
3
+ */
4
+ /**
5
+ * @typedef {typeof import('../../function/IsTypeOf.mjs').TypeMap} TypeMap
6
+ */
7
+ /**
8
+ * @description
9
+ * - helper funtion for wecomponent instantiator;
10
+ * - it uses WC_createElement_bind, which uses `lit-html`;
11
+ * - alternatively, if you want to create a baseline component that are not to be , you can just
12
+ * @template {new (...args: any[]) => HTMLElement} BASE_CONSTRUCTOR
13
+ * @template {{
14
+ * class?:string;
15
+ * style?:string;
16
+ * observedAttributes?: readonly string[];
17
+ * namedSlots?: readonly string[];
18
+ * props?: Record<string, keyof TypeMap|(new (...args:any[])=>any)>;
19
+ * }} STANDARD
20
+ * @template {(BASE_CONSTRUCTOR) & {
21
+ * tagName: string;
22
+ * extendIsValue: string;
23
+ * observedAttributes?: STANDARD["observedAttributes"];
24
+ * namedSlots?: STANDARD["namedSlots"];
25
+ * props?: STANDARD["props"];
26
+ * }} CREATEARGS
27
+ * @template {string} TAG
28
+ * @param {WC_TagName_type<TAG>} tagName
29
+ * @param {CREATEARGS} classRef
30
+ * @param {ElementDefinitionOptions} elementDefinitionOptions
31
+ * @returns {ReturnType<typeof WC_createElement_bind<CREATEARGS>>}
32
+ */
33
+ export function WC_DefineCustomElement<BASE_CONSTRUCTOR extends new (...args: any[]) => HTMLElement, STANDARD extends {
34
+ class?: string;
35
+ style?: string;
36
+ observedAttributes?: readonly string[];
37
+ namedSlots?: readonly string[];
38
+ props?: Record<string, keyof TypeMap | (new (...args: any[]) => any)>;
39
+ }, CREATEARGS extends (BASE_CONSTRUCTOR) & {
40
+ tagName: string;
41
+ extendIsValue: string;
42
+ observedAttributes?: STANDARD["observedAttributes"];
43
+ namedSlots?: STANDARD["namedSlots"];
44
+ props?: STANDARD["props"];
45
+ }, TAG extends string>(tagName: WC_TagName_type<TAG>, classRef: CREATEARGS, elementDefinitionOptions: ElementDefinitionOptions): ReturnType<typeof WC_createElement_bind<CREATEARGS>>;
46
+ export type TypeMap = typeof import("../../function/IsTypeOf.mjs").TypeMap;
47
+ import type { WC_TagName_type } from '../common/WC_TagName_type.mjs';
48
+ import { WC_createElement_bind } from '../bindings/WC_createElement_bind.mjs';
@@ -215,6 +215,7 @@ export { CSS } from '../../../src/web/common/CSS.mjs';
215
215
  export { E } from '../../../src/web/common/E.mjs';
216
216
  export { NewStyleSheetAsync } from '../../../src/web/common/NewStyleSheetAsync.mjs';
217
217
  export { NewStyleSheetSync } from '../../../src/web/common/NewStyleSheetSync.mjs';
218
+ export { WC_DefineCustomElement } from '../../../src/web/common/WC_DefineCustomElement.mjs';
218
219
  /**
219
220
  * @template {string} TAG
220
221
  * @typedef {import('../../../src/web/common/WC_TagName_type.mjs').WC_TagName_type<TAG>} WC_TagName_type
@@ -177,6 +177,7 @@ export { CSS } from '../../../src/web/common/CSS.mjs';
177
177
  export { E } from '../../../src/web/common/E.mjs';
178
178
  export { NewStyleSheetAsync } from '../../../src/web/common/NewStyleSheetAsync.mjs';
179
179
  export { NewStyleSheetSync } from '../../../src/web/common/NewStyleSheetSync.mjs';
180
+ export { WC_DefineCustomElement } from '../../../src/web/common/WC_DefineCustomElement.mjs';
180
181
  /**
181
182
  * @template {string} TAG
182
183
  * @typedef {import('../../../src/web/common/WC_TagName_type.mjs').WC_TagName_type<TAG>} WC_TagName_type
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vivth",
3
- "version": "1.5.2",
3
+ "version": "1.5.4",
4
4
  "description": "library primitives",
5
5
  "devDependencies": {
6
6
  "@types/bun": "^1.3.3",
@@ -2,72 +2,77 @@
2
2
 
3
3
  /**
4
4
  * @description
5
- * - collection of static `methods` to walktrhough things, instead of regular looping;
6
- * - usefull to iterator that might be modified during iteration;
7
- * - mostlikely to be less performant, but with better result clarity;
5
+ * - collection of static `methods` to walkthrough things, instead of regular looping;
6
+ * - useful for iterators that might be modified during iteration;
7
+ * - most likely to be less performant, but with better result clarity;
8
8
  */
9
9
  export class WalkThrough {
10
10
  /**
11
- * @param {Iterator<any, any, any>} iterator
12
- * @param {(...any:any[])=>void} callback
11
+ * @template T
12
+ * @param {Iterator<T, any, any>} iterator
13
+ * @param {(value: T) => void} callback
13
14
  * @returns {void}
14
15
  */
15
- static #handler = (iterator, callback) => {
16
+ static #handler(iterator, callback) {
16
17
  let result = iterator.next();
17
18
  while (!result.done) {
18
19
  callback(result.value);
19
20
  result = iterator.next();
20
21
  }
21
- };
22
+ }
23
+
22
24
  /**
23
25
  * @description
24
26
  * - method helper to WalkThrough `Set`;
25
27
  * @template VAL
26
28
  * @param {Set<VAL>} setInstance
27
- * @param {(value:VAL)=>void} callback
29
+ * @param {(value: VAL) => void} callback
28
30
  * @returns {void}
29
31
  * @example
30
32
  * import { WalkThrough } from 'vivth/neutral';
31
33
  *
32
34
  * WalkThrough.set(setOfSomething, (value) => {
33
- * // code
35
+ * // code
34
36
  * })
35
37
  */
36
38
  static set(setInstance, callback) {
37
39
  WalkThrough.#handler(setInstance.values(), callback);
38
40
  }
41
+
39
42
  /**
40
43
  * @description
41
44
  * - method helper to WalkThrough `Map`;
42
45
  * @template KEY, VAL
43
46
  * @param {Map<KEY, VAL>} mapInstance
44
- * @param {(res:[key: KEY, value: VAL]) => void} callback
47
+ * @param {(entry: [key: KEY, value: VAL]) => void} callback
45
48
  * @returns {void}
46
49
  * @example
47
50
  * import { WalkThrough } from 'vivth/neutral';
48
51
  *
49
52
  * WalkThrough.map(mapOfSomething, ([key, value]) => {
50
- * // code
53
+ * // code
51
54
  * })
52
55
  */
53
56
  static map(mapInstance, callback) {
54
57
  WalkThrough.#handler(mapInstance.entries(), callback);
55
58
  }
59
+
56
60
  /**
57
61
  * @description
58
62
  * - method helper to WalkThrough `Array`;
59
63
  * @template VAL
60
64
  * @param {VAL[]} arrayInstance
61
- * @param {(res:[value: VAL, index: number]) => void} callback
65
+ * @param {(entry: [index: number, value: VAL]) => void} callback
62
66
  * @returns {void}
63
67
  * @example
64
68
  * import { WalkThrough } from 'vivth/neutral';
65
69
  *
66
- * WalkThrough.array(arrayOfSomething, ([value, index]) => {
67
- * // code
70
+ * WalkThrough.array(arrayOfSomething, ([index, value]) => {
71
+ * // code
68
72
  * })
69
73
  */
70
74
  static array(arrayInstance, callback) {
71
- WalkThrough.#handler(arrayInstance.values(), callback);
75
+ // Changed .values() to .entries() to match your [index, value] requirement
76
+ WalkThrough.#handler(arrayInstance.entries(), callback);
72
77
  }
73
78
  }
@@ -39,7 +39,7 @@ import { WC_createNamedSlot } from './bindings/WC_createNamedSlot.mjs';
39
39
  * }} STANDARD
40
40
  * @template {(BASE_CONSTRUCTOR) & {
41
41
  * tagName: string;
42
- * extendIs: string;
42
+ * extendIsValue: string;
43
43
  * observedAttributes?: STANDARD["observedAttributes"];
44
44
  * namedSlots?: STANDARD["namedSlots"];
45
45
  * props?: STANDARD["props"];
@@ -78,7 +78,7 @@ import { WC_createNamedSlot } from './bindings/WC_createNamedSlot.mjs';
78
78
  * })=>OBJ;
79
79
  * }) & {
80
80
  * tagName:string;
81
- * extendIs:string;
81
+ * extendIsValue:string;
82
82
  * namedSlots: STANDARD["namedSlots"];
83
83
  * observedAttributes: STANDARD["observedAttributes"];
84
84
  * createNamedSlot: typeof WC_createNamedSlot<STANDARD>;
@@ -96,7 +96,9 @@ import { WC_createNamedSlot } from './bindings/WC_createNamedSlot.mjs';
96
96
  * @returns {RET}
97
97
  * @example
98
98
  * export MyWebComponent extends WC_extendsA(HTMLElement, {...options}){
99
- * static create = this.define('my-webcomponent');
99
+ * static create = WC_DefineCustomElement('my-webcomponent', this);
100
+ * // you can skip the defining with WC_DefineCustomElement if the class are meant to be extended abstract;
101
+ * // or if you want to opt out from using `lit-html` template;
100
102
  * }
101
103
  */
102
104
  export function WC_extendsA(Base, staticMember = /** @type {any} */ ({})) {
@@ -38,7 +38,7 @@ import { WC_createNamedSlot } from './bindings/WC_createNamedSlot.mjs';
38
38
  * }} STANDARD
39
39
  * @template {(BASE_CONSTRUCTOR) & {
40
40
  * tagName: string;
41
- * extendIs: string;
41
+ * extendIsValue: string;
42
42
  * observedAttributes?: STANDARD["observedAttributes"];
43
43
  * namedSlots?: STANDARD["namedSlots"];
44
44
  * props?: STANDARD["props"];
@@ -79,7 +79,7 @@ import { WC_createNamedSlot } from './bindings/WC_createNamedSlot.mjs';
79
79
  * })=>OBJ;
80
80
  * }) & {
81
81
  * tagName:string;
82
- * extendIs:string;
82
+ * extendIsValue:string;
83
83
  * namedSlots: STANDARD["namedSlots"];
84
84
  * observedAttributes: STANDARD["observedAttributes"];
85
85
  * createNamedSlot: typeof WC_createNamedSlot<STANDARD>;
@@ -95,6 +95,12 @@ import { WC_createNamedSlot } from './bindings/WC_createNamedSlot.mjs';
95
95
  * @param {BASE_CONSTRUCTOR} Base
96
96
  * @param {STANDARD} [staticMember]
97
97
  * @returns {RET}
98
+ * @example
99
+ * export MyWebComponent extends WC_extendsA(HTMLElement, {...options}){
100
+ * static create = WC_DefineCustomElement('my-webcomponent', this);
101
+ * // you can skip the defining if the class are meant to be extended abstract;
102
+ * // or if you want to opt out from using `lit-html` template;
103
+ * }
98
104
  */
99
105
  export function WC_extendsB(Base, staticMember = /** @type {any} */ ({})) {
100
106
  const { class: class_ = '', style = '', observedAttributes = [], namedSlots = [] } = staticMember;
@@ -30,12 +30,10 @@ const getChildrenData = (namedSlots, childrenDataArgsPlaceholder) => {
30
30
  /**
31
31
  * @description
32
32
  * - typesafe factory generator for creating element of `WC_extendsA`/`WC_extendsB` class;
33
- * - this function is returned by static method `.define`;
34
- * >- bind it with static property;
35
33
  * - uses `lit-html` under the hood;
36
34
  * @template {(new (...args: any[]) => HTMLElement) & {
37
35
  * tagName: string;
38
- * extendIs: string;
36
+ * extendIsValue: string;
39
37
  * observedAttributes?: readonly string[];
40
38
  * namedSlots?: readonly string[];
41
39
  * props?: Record<string, keyof TypeMap|(new (...args:any[])=>any)>;
@@ -58,11 +56,8 @@ const getChildrenData = (namedSlots, childrenDataArgsPlaceholder) => {
58
56
  * },
59
57
  * )=>InstanceType<BASE_CONSTRUCTOR>}
60
58
  * @example
61
- * // webcomponent context via `WC_extends`
62
- * static createElement = this.define(...args);
63
- * //
64
59
  */
65
- export function WC_createElement_bind({ tagName, extendIs, namedSlots = [] }) {
60
+ export function WC_createElement_bind({ tagName, extendIsValue, namedSlots = [] }) {
66
61
  /**
67
62
  * @type {Record<string, string>|undefined}
68
63
  */
@@ -72,13 +67,13 @@ export function WC_createElement_bind({ tagName, extendIs, namedSlots = [] }) {
72
67
  * @type {InstanceType<BASE_CONSTRUCTOR>}
73
68
  */
74
69
  let element;
75
- if (!extendIs) {
70
+ if (!extendIsValue) {
76
71
  // @ts-expect-error
77
72
  element = document.createElement(tagName);
78
73
  } else {
79
74
  // @ts-expect-error
80
75
  element = document.createElement(tagName, {
81
- is: extendIs,
76
+ is: extendIsValue,
82
77
  });
83
78
  }
84
79
  if (attrs) {
@@ -0,0 +1,46 @@
1
+ // @ts-check
2
+
3
+ import { WC_createElement_bind } from '../bindings/WC_createElement_bind.mjs';
4
+
5
+ /**
6
+ * @import {WC_TagName_type} from '../common/WC_TagName_type.mjs'
7
+ */
8
+ /**
9
+ * @typedef {typeof import('../../function/IsTypeOf.mjs').TypeMap} TypeMap
10
+ */
11
+ /**
12
+ * @description
13
+ * - helper funtion for wecomponent instantiator;
14
+ * - it uses WC_createElement_bind, which uses `lit-html`;
15
+ * - alternatively, if you want to create a baseline component that are not to be , you can just
16
+ * @template {new (...args: any[]) => HTMLElement} BASE_CONSTRUCTOR
17
+ * @template {{
18
+ * class?:string;
19
+ * style?:string;
20
+ * observedAttributes?: readonly string[];
21
+ * namedSlots?: readonly string[];
22
+ * props?: Record<string, keyof TypeMap|(new (...args:any[])=>any)>;
23
+ * }} STANDARD
24
+ * @template {(BASE_CONSTRUCTOR) & {
25
+ * tagName: string;
26
+ * extendIsValue: string;
27
+ * observedAttributes?: STANDARD["observedAttributes"];
28
+ * namedSlots?: STANDARD["namedSlots"];
29
+ * props?: STANDARD["props"];
30
+ * }} CREATEARGS
31
+ * @template {string} TAG
32
+ * @param {WC_TagName_type<TAG>} tagName
33
+ * @param {CREATEARGS} classRef
34
+ * @param {ElementDefinitionOptions} elementDefinitionOptions
35
+ * @returns {ReturnType<typeof WC_createElement_bind<CREATEARGS>>}
36
+ */
37
+ export function WC_DefineCustomElement(tagName, classRef, elementDefinitionOptions) {
38
+ if (elementDefinitionOptions && elementDefinitionOptions.extends) {
39
+ classRef.tagName = elementDefinitionOptions.extends;
40
+ classRef.extendIsValue = tagName;
41
+ } else {
42
+ classRef.tagName = tagName;
43
+ }
44
+ customElements.define(tagName, classRef, elementDefinitionOptions);
45
+ return WC_createElement_bind(classRef);
46
+ }