@twobirds/microcomponents 0.0.86 → 0.0.89

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/README.md +32 -12
  2. package/assets/documentation/MC.md +23 -42
  3. package/assets/test/grandparent.css +3 -0
  4. package/dist/MC.d.ts +5 -5
  5. package/dist/MC.d.ts.map +1 -1
  6. package/dist/MC.js +10 -17
  7. package/dist/MC.min.js +10 -17
  8. package/dist/MC.ts +13 -22
  9. package/dist/elements.min.js +1 -1
  10. package/dist/formValues.min.js +1 -1
  11. package/dist/microcomponents.min.js +1 -1
  12. package/dist/observables.min.js +1 -1
  13. package/package.json +1 -1
  14. package/public/MC.d.ts +5 -5
  15. package/public/MC.d.ts.map +1 -1
  16. package/public/MC.js +10 -17
  17. package/public/MC.js.map +1 -1
  18. package/public/MC.min.js +10 -17
  19. package/public/MC.ts +13 -22
  20. package/public/documentation/MC.md +23 -42
  21. package/public/elements.min.js +1 -1
  22. package/public/formValues.min.js +1 -1
  23. package/public/microcomponents.min.js +1 -1
  24. package/public/observables.min.js +1 -1
  25. package/public/src/MC.d.ts +5 -5
  26. package/public/src/MC.d.ts.map +1 -1
  27. package/public/src/MC.js +10 -17
  28. package/public/src/MC.js.map +1 -1
  29. package/public/src/MC.ts +13 -22
  30. package/public/src/test/grandparent.css +3 -0
  31. package/public/src/test/test/grandparent.js +1 -1
  32. package/public/src/test/test/testform.js +1 -1
  33. package/public/src/test/test.js +1 -1
  34. package/public/src/test/test.js.map +1 -1
  35. package/public/src/test/test.ts +4 -5
  36. package/public/test/MC.d.ts +5 -5
  37. package/public/test/MC.d.ts.map +1 -1
  38. package/public/test/MC.js +10 -17
  39. package/public/test/MC.min.js +10 -17
  40. package/public/test/MC.ts +13 -22
  41. package/public/test/elements.min.js +1 -1
  42. package/public/test/formValues.min.js +1 -1
  43. package/public/test/grandparent.css +3 -0
  44. package/public/test/microcomponents.min.js +1 -1
  45. package/public/test/observables.min.js +1 -1
  46. package/public/test/test/grandparent.js +1 -1
  47. package/public/test/test/testform.js +1 -1
  48. package/public/test/test.js +1 -1
  49. package/public/test/test.js.map +1 -1
  50. package/public/test/test.ts +4 -5
  51. package/public/typedoc/assets/search.js +1 -1
  52. package/public/typedoc/classes/MC.DC.html +3 -3
  53. package/public/typedoc/classes/MC.MC.html +2 -2
  54. package/public/typedoc/classes/MC.McBase.html +2 -2
  55. package/public/typedoc/functions/MC.autoload.html +1 -1
  56. package/public/typedoc/functions/MC.off.html +1 -1
  57. package/public/typedoc/functions/MC.on.html +1 -1
  58. package/public/typedoc/functions/MC.one.html +1 -1
  59. package/public/typedoc/functions/MC.trigger.html +1 -1
  60. package/public/typedoc/functions/elements.defineCE.html +1 -1
  61. package/public/typedoc/functions/elements.getCE.html +1 -1
  62. package/public/typedoc/functions/formValues.formValues.html +1 -1
  63. package/public/typedoc/functions/observables.observe.html +1 -1
  64. package/public/typedoc/index.html +24 -13
  65. package/public/typedoc/interfaces/MC.HTMLMcElement.html +2 -2
  66. package/public/typedoc/modules/MC.html +1 -1
  67. package/public/typedoc/modules/elements.html +1 -1
  68. package/public/typedoc/modules/formValues.html +1 -1
  69. package/public/typedoc/modules/observables.html +1 -1
  70. package/public/typedoc/types/observables.Observable.html +1 -1
  71. package/src/MC.ts +13 -22
  72. package/src/test/grandparent.css +3 -0
  73. package/src/test/test.ts +4 -5
  74. package/public/McEvent._ts +0 -96
  75. package/public/src/McEvent._ts +0 -96
  76. package/src/McEvent._ts +0 -96
package/README.md CHANGED
@@ -2,25 +2,43 @@
2
2
 
3
3
  ## MICRO COMPONENTS
4
4
 
5
- **This code aims at improving Javascript modularity and encapsulation**.
5
+ **MCs are function blocks that you attach to DOM nodes.** These are re-usable in any framework, and you can have any number of MCs in one DOM node.
6
6
 
7
- Micro Components are built on **OOP** for structure, so you should embrace **DRY, KISS and SOLID** principles. That said, OOP is not a religion here, in fact you can do FP also. MCs provide a structure for your code, no more. It is agnostic as to what code you put in this structure.
7
+ There are helpers for the following functionalities:
8
8
 
9
- Its basic principle is **composition over inheritance**. So: using OOP its recommended you do not extend your own classes, as it is not needed.
9
+ - **Web Components:** create native web components. Their functionality is comprised of a set of inner MCs.
10
+ - **State** is done by observable objects that you can attach callbacks to. This also allows for 1-way binding to DOM placeholders, and it can be extended to allow for complex data driven state machines.
11
+ - **Form Handling** allows for 2-way binding from an observable form object to DOM form input elements.
12
+ - **Communication** between DOM micro components is ensured via direct selected or directional bubbling CustomEvent's.
13
+ - **Autoloading** allows for build-free websites that dynamically load JS requirements into DOM HTMLElements.
10
14
 
11
- Also it helps to embrace **DIY** (Do It Yourself) **over Toolchains**, but this is up to your personal preference.
15
+ The destinct difference to to other frameworks is **portability** and **modularization**.
12
16
 
13
- You can use **Vanilla JS or Typescript** or both in your project. For example you could use plain JS for rapid prototyping functionalities, then convert to TS for production.
17
+ ## Goal
14
18
 
15
- ## Think **Building Blocks**
19
+ This code aims at improving Javascript modularity and encapsulation. Micro Components are built on **OOP** for structure, so you should embrace **DRY, KISS and SOLID** principles.
20
+
21
+ MCs provide a runtime app structure that is directly linked to the browser DOM. That is you don't need web components, you can attach MCs to plain HTMLElements. Having said this: the library also allows for standard web component programming, acting as a framework.
16
22
 
17
23
  In general this is a **HTML / Web Standards first** system. There is almost no abstraction, especially not for templating, except state binding to the DOM via simple placeholders.
18
24
 
19
- When coding with this system, you create classes that extend either the **[MC](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/MC.md?ref_type=heads#mc-class-extends-mcbase)** or **[DC](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/MC.md?ref_type=heads#dc-class-extends-mcbase)** superclasses provided here. These classes provide the structure you need to build your wonderland.
25
+ It has no interference with other frameworks, since it creates a second layer that hovers above the DOM. So what you intended to work as an add-on to React, is usable e.g. in Angular also.
26
+
27
+ And, of course, you can use it as your main framework using its custom web component functionality.
28
+
29
+ Its basic principle is **composition over inheritance**. So: using when using it for app coding it is recommended you do not extend your own classes, as it is not needed and induces problems.
30
+
31
+ Also it helps to embrace **DIY** (**D**o **I**t **Y**ourself) **over Toolchains**, but this is up to your personal preference.
32
+
33
+ You can use **Vanilla JS or Typescript** or both in parallel in your project. For example you could use plain JS for rapid prototyping functionalities, then convert to TS for production.
20
34
 
21
- You **attach instances of your classes to any HTMLElement**, and there can be as many as you want connected to a single HTML tag. In an almost literal sense they work like childrens building blocks, where a chest full of unassuming parts lets you compose whatever functionality lies in your imagination.
35
+ Most of all this system by design **allows for outsourcing without sharing the main development system**. It is absolutely granular as it enforces **DRY** (**D**on't **R**epeat **Y**ourself).
22
36
 
23
- Also you can easily **define JS custom elements**. Since these are just another instance of a DC internally, you can enhance them even at runtime, as they are displayed in the browser.
37
+ Finally it allows for a clear distinction between `Junior`, `Senior` and `Architect` roles in a project. No more hiring junior programmers with 5 years experience in 50 tools under their belt. A junior in this system is somebody who likes HTML, CSS and JS/TS - nothing more. Teaching all of this system starting at zero takes 1 day. The rest is finger muscle memory and learning/knowing web standards.
38
+
39
+ ## Think **Building Blocks**
40
+
41
+ You **attach instances of your classes to any HTMLElement**, and you can **attach as many as you want to a single HTMLElement**. In an almost literal sense they work like childrens building blocks, where a chest full of unassuming parts lets you compose whatever functionality lies in your imagination.
24
42
 
25
43
  ## Principles
26
44
 
@@ -61,7 +79,7 @@ To see what can be done, go to [additional concepts](https://gitlab.com/twoBirds
61
79
 
62
80
  ## Simple Usage Example
63
81
 
64
- **Hint:** this only shows how Micro Components are stored in the DOM structure, for details about functionality refer to above links!
82
+ **Hint: the following code only shows how Micro Components are stored in the DOM structure**, for details about functionality refer to above links!
65
83
 
66
84
  **Micro Components** can be added to to a DOM element like this:
67
85
 
@@ -113,7 +131,7 @@ The `_mc` **property** is the only interference with the DOM, so any other syste
113
131
 
114
132
  ## Distinct differences to other frameworks
115
133
 
116
- There are a few potentially unique aspects of this micro components system that might differentiate it from other frameworks:
134
+ There are a few potentially unique aspects of this micro components system that might differentiate it from other framework or library:
117
135
 
118
136
  - **Pure OOP Approach**: The system explicitly positions itself as a strict object-oriented alternative to the functional approaches that dominate many modern frameworks.
119
137
 
@@ -121,7 +139,7 @@ There are a few potentially unique aspects of this micro components system that
121
139
  - **Minimal Interference**: The system has minimal DOM interference, only adding _mc property to DOM nodes that contain code. This makes it unusually compatible with other frameworks or libraries.
122
140
 
123
141
 
124
- - **Hierarchical Component Traversal**: The built-in parent/child/ancestor/descendant traversal methods provide a clean way to navigate component relationships.
142
+ - **Hierarchical Component Traversal**: The built-in ancestor/closest/child/descendant traversal methods provide a clean way to navigate component relationships.
125
143
 
126
144
 
127
145
  - **Direct DOM Integration**: Unlike virtual DOM-based frameworks, this approach works directly with the actual DOM while still providing component encapsulation.
@@ -133,6 +151,7 @@ There are a few potentially unique aspects of this micro components system that
133
151
  The strongest argument might be for developers who prefer OOP, want minimal framework lock-in, and need a lightweight solution that works well with existing code or other libraries.
134
152
 
135
153
  ## Contact
154
+
136
155
  Feel free to contact me for any questions or inquiries:
137
156
 
138
157
  email [Frank Thürigen](mailto:fthuerigen@gmail.com?subject=Micro%20Components)
@@ -140,6 +159,7 @@ email [Frank Thürigen](mailto:fthuerigen@gmail.com?subject=Micro%20Components)
140
159
  You can [fund this](https://www.gofundme.com/f/nachhaltige-programmierung).
141
160
 
142
161
  ## Disclaimer
162
+
143
163
  I decided to extract this functionality from the [twoBirds framework](https://www.npmjs.com/package/twobirds-core), because it is a useful tool in itself and it is framework agnostic. It relies solely on the standard DOM and native javascript or typescript.
144
164
 
145
165
  Later this will be backported into twoBirds as a dependency, and twoBirds will become completely modularized on the base of MCs.
@@ -60,7 +60,7 @@ Plain JavaScript objects or class instances (extending `MC` or `DC`) that encaps
60
60
 
61
61
  ### `_mc` Property
62
62
 
63
- A special property attached to `HTMLElement` instances (when using `DC.add`) or parent `MC`/`DC` instances. It acts as an object container (`{ key: mcInstance, ... }`) holding one or more named microcomponent instances.
63
+ A special property attached to `HTMLElement` instances when using `DC.add`. It acts as an object container (`{ key: mcInstance, ... }`) holding one or more named microcomponent instances.
64
64
 
65
65
  - On HTMLElements, the presence of attached components is also marked by a `_mc` attribute for CSS selection and discovery. This attribute is added by `DC.add` and removed by `DC.remove` when the `_mc` object becomes empty.
66
66
 
@@ -101,7 +101,7 @@ The names maps like this:
101
101
 
102
102
  - **Bubbling:** Events triggered via `dcInstance.trigger` can bubble:
103
103
  - `'l'`: Local only (default). Handlers on the target element's/instance's MCs are executed.
104
- - `'u'`: Upwards. Event propagates to MCs on parent elements (DOM tree).
104
+ - `'u'`: Upwards. Event propagates to MCs on closest elements (DOM tree).
105
105
  - `'d'`: Downwards. Event propagates to MCs on descendant elements (DOM tree).
106
106
  - Any combination of the characters 'l','u', 'd' are possible (e.g., `'lu'`, `'ldu'`).
107
107
  - Bubbling (`u`/`d`) occurs asynchronously via `setTimeout`.
@@ -113,7 +113,7 @@ The names maps like this:
113
113
 
114
114
  ### DOM Traversal
115
115
 
116
- The `DC` class provides methods (`parent`, `ancestors`, `children`, `descendants`) to find related `DC` instances attached to elements elsewhere in the DOM hierarchy, skipping over elements without attached microcomponents.
116
+ The `DC` class provides methods (`closest`, `ancestors`, `children`, `descendants`) to find related `DC` instances attached to elements elsewhere in the DOM hierarchy, skipping over elements without attached microcomponents.
117
117
 
118
118
  ### Autoloading Concept
119
119
 
@@ -121,7 +121,7 @@ An optional feature (`autoload()`) that automatically detects specific HTML tags
121
121
 
122
122
  ### Important Rule
123
123
 
124
- **Your own application code MUST NOT overwrite the core properties and methods provided by the `McBase`, `MC`, and `DC` classes (like `_mc`, `target`, `trigger`, `parent`, etc.). Doing so may break framework functionality.**
124
+ **Your own application code MUST NOT overwrite the core properties and methods provided by the `McBase`, `MC`, and `DC` classes (like `_mc`, `target`, `trigger`, `closest`, etc.). Doing so may break framework functionality.**
125
125
 
126
126
  ## Classes
127
127
 
@@ -158,10 +158,10 @@ Class for DOM-aware components. Extends `McBase`. **Client-side only.**
158
158
  - **Instance Properties**:
159
159
  - `.target`: (Inherited from `McBase`) Refers to the DOM HTMLElement this `DC` instance is attached to (via `DC.add`).
160
160
  - **Instance Methods**:
161
- - `.parent()`: Gets MC instances from the closest parent element that has attached MCs.
162
- - `.ancestors()`: Gets MC instances from all ancestor elements with attached MCs.
163
- - `.children()`: Gets MC instances from direct child elements with attached MCs.
164
- - `.descendants()`: Gets MC instances from all descendant elements with attached MCs.
161
+ - `.closest()`: Gets MC instances from the closest HTMLElement that has MCs attached.
162
+ - `.ancestors()`: Gets MC instances from all ancestor HTMLElements with MCs attached MCs.
163
+ - `.children()`: Gets MC instances from direct child HTMLElements with MCs attached.
164
+ - `.descendants()`: Gets MC instances from all descendant HTMLElements with MCs attached.
165
165
  - `.trigger(eventName, data, bubble)`: Triggers an event on this `DC` instance. Can initiate DOM bubbling (`'l'`, `'u'`, `'d'`).
166
166
 
167
167
  ## Examples
@@ -171,9 +171,9 @@ Class for DOM-aware components. Extends `McBase`. **Client-side only.**
171
171
  1. Define your component classes extending `MC` or `DC`. These contain plain data, observable state, event callbacks and optional internal MCs.
172
172
  2. Attach defined top-level `DC` instances to HTMLElements using `DC.add()`.
173
173
  3. Then...
174
- - Select and access other MCs using DOM traversal methods (`ancestors()`, `children()`, etc.)
175
- - Dynamically attach event handlers (`on`, `one`, `off`).
176
- - Communicate with other components via Events (`trigger`).
174
+ - Select and access other MCs using DOM traversal methods (`ancestors()`, `closest()`, `children()`, `descendants()` )
175
+ - Dynamically attach event handlers (`on()`, `one()`, `off()`).
176
+ - Communicate with other components via Events (`trigger()`).
177
177
 
178
178
  ### Attach Micro Components (`DC.add`)
179
179
 
@@ -182,50 +182,31 @@ Use the static `DC.add()` method to attach a component (usually a `DC` instance)
182
182
  ```javascript
183
183
  const myElement = document.getElementById('myDiv');
184
184
 
185
- // Define an inner MC (doesn't need DOM access itself)
186
- class MyInnerClass extends MC {
187
-
188
- constructor(target) {
189
- // target will be the parent MyPublicClass instance
190
- super(target);
191
- console.log('Inner MC target:', this.target);
192
- }
193
-
194
- doSomethingInner() {
195
- console.log('Inner action!');
196
- }
197
-
198
- }
199
-
200
- // Define an outer DC (needs DOM access or is top-level)
201
- class MyPublicClass extends DC {
185
+ // Define a public DC class
186
+ class MyClass extends DC {
202
187
 
203
188
  constructor(target) {
204
189
  // target will be myElement
205
190
  super(target);
206
191
  console.log('Outer DC target:', this.target);
207
- // Add an inner MC instance, nested within this DC instance
208
- this.myInner = new MyInnerClass(this); // 'this' becomes the target for MyInnerClass
209
192
  }
210
193
 
211
- doSomethingOuter() {
194
+ doSomething() {
212
195
  console.log('Outer action!');
213
196
  }
214
197
 
215
198
  onClick(event) {
216
199
  console.log('Div clicked!', event);
217
- // Access nested MC
218
- this.myInner.doSomethingInner();
219
200
  }
220
201
  }
221
202
 
222
- // Attach the outer DC instance to the DOM element
223
- // The key 'myComponent' is used to access it later via myElement._mc.myComponent
224
- DC.add(myElement, 'myComponent', new MyPublicClass(myElement));
203
+ // Attach the DC instance to the DOM element
204
+ // The key 'MyClass' is used to access it later via myElement._mc.myComponent
205
+ DC.add(myElement, 'MyClass', new MyClass(myElement));
225
206
 
226
207
  // Hint: After adding, myElement now has:
227
- // 1. A property: myElement._mc = { myComponent: instanceOfMyPublicClass }
228
- // 2. An attribute: <div id="myDiv" _mc>...</div>
208
+ // 1. A property: myElement._mc = { MyClass: <instanceOfMyClass> }
209
+ // 2. An attribute: <div id="myDiv" data-mc>...</div>
229
210
  ```
230
211
 
231
212
  ### Remove Micro Components (DC.remove)
@@ -313,16 +294,16 @@ class MyTriggeringComponent extends DC {
313
294
  }
314
295
  ```
315
296
 
316
- ### Navigating Parent/Ancestor MCs
297
+ ### Navigating closest/Ancestor MCs
317
298
 
318
- Use .parent() and .ancestors() (available on DC instances) to find components attached to elements higher up the DOM tree.
299
+ Use .closest() and .ancestors() (available on DC instances) to find components attached to elements higher up the DOM tree.
319
300
 
320
301
  These methods skip elements that don't have any MCs attached.
321
302
 
322
303
  ```javascript
323
304
  // Inside a method of a DC instance:
324
- const parentMcs = this.parent(); // Array of MC instances on the closest parent element that contains MCs
325
- console.log(parentMcs);
305
+ const closestMcs = this.closest(); // Array of MC instances on the closest parent element that contains MCs
306
+ console.log(closestMcs);
326
307
 
327
308
  const allAncestorMcs = this.ancestors(); // Array of all MC instances on all ancestor elements with MCs
328
309
  console.log(allAncestorMcs);
@@ -3,6 +3,9 @@ test-parent,
3
3
  test-child,
4
4
  test-grandchild,
5
5
  test-greatgrandchild {
6
+ user-select: none;
7
+ caret-color: transparent;
8
+
6
9
  display: inline-block;
7
10
  padding: 2px;
8
11
  margin: 1px;
package/dist/MC.d.ts CHANGED
@@ -3,8 +3,8 @@ export interface HTMLMcElement extends HTMLElement {
3
3
  _mc: LooseObject;
4
4
  }
5
5
  declare function off(domNode: Node, eventName: string, handler: EventListenerOrEventListenerObject): void;
6
- declare function on(domNode: Node, eventName: string, handler: EventListenerOrEventListenerObject, once?: boolean): void;
7
- declare function one(domNode: Node, eventName: string, handler: EventListenerOrEventListenerObject): void;
6
+ declare function on(domNode: Node, eventName: string, handler: EventListenerOrEventListenerObject, once?: boolean): EventListenerOrEventListenerObject;
7
+ declare function one(domNode: Node, eventName: string, handler: EventListenerOrEventListenerObject): EventListenerOrEventListenerObject;
8
8
  declare function trigger(domNode: HTMLElement, event: CustomEvent | string, data?: any, bubble?: string): void;
9
9
  declare class McBase {
10
10
  private _target;
@@ -21,11 +21,11 @@ declare class DC extends McBase {
21
21
  static add: Function;
22
22
  static remove: Function;
23
23
  off(eventName: string, handler: EventListenerOrEventListenerObject): void;
24
- on(eventName: string, handler: EventListenerOrEventListenerObject): void;
25
- one(eventName: string, handler: EventListenerOrEventListenerObject): void;
24
+ on(eventName: string, handler: EventListenerOrEventListenerObject): EventListenerOrEventListenerObject;
25
+ one(eventName: string, handler: EventListenerOrEventListenerObject): EventListenerOrEventListenerObject;
26
26
  trigger(eventName: string, data?: any, bubble?: string): void;
27
- parent(): DC | null;
28
27
  ancestors(): DC[] | null;
28
+ closest(): DC | null;
29
29
  children(): DC[] | null;
30
30
  descendants(): DC[] | null;
31
31
  }
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;AAiB3C,MAAM,WAAW,aAAc,SAAQ,WAAW;IACjD,GAAG,EAAE,WAAW,CAAC;CACjB;AAmED,iBAAS,GAAG,CAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,kCAAkC,QAE1F;AAED,iBAAS,EAAE,CAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,kCAAkC,EAAE,IAAI,GAAE,OAAe,QAEhH;AAED,iBAAS,GAAG,CAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,kCAAkC,QAE1F;AAGD,iBAAS,OAAO,CACf,OAAO,EAAE,WAAW,EACpB,KAAK,EAAE,WAAW,GAAG,MAAM,EAC3B,IAAI,GAAE,GAAQ,EACd,MAAM,GAAE,MAAY,QAepB;AA+ED,cAAM,MAAM;IACX,OAAO,CAAC,OAAO,CAAe;gBAElB,MAAM,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE;IAU3C,IAAI,MAAM,IAAI,GAAG,CAEhB;CAED;AAED,cAAM,EAAG,SAAQ,MAAM;gBACV,MAAM,CAAC,EAAE,GAAG;CAGxB;AAED,cAAM,EAAG,SAAQ,MAAM;gBACV,MAAM,EAAE,WAAW,EAAE,KAAK,GAAE,OAAe;IAIvD,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAO;IAC3B,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAU;IAGjC,GAAG,CAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,kCAAkC;IAInE,EAAE,CAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,kCAAkC;IAIlE,GAAG,CAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,kCAAkC;IAInE,OAAO,CAAE,SAAS,EAAE,MAAM,EAAE,IAAI,GAAE,GAAQ,EAAE,MAAM,GAAE,MAAY;IAKhE,MAAM,IAAI,EAAE,GAAG,IAAI;IAOnB,SAAS,IAAI,EAAE,EAAE,GAAG,IAAI;IAgBxB,QAAQ,IAAI,EAAE,EAAE,GAAG,IAAI;IAMvB,WAAW,IAAI,EAAE,EAAE,GAAG,IAAI;CAS1B;AAiHD,iBAAS,QAAQ,CAAC,MAAM,GAAE,OAAc,GAAG,OAAO,CAmBjD;AAID,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC"}
1
+ {"version":3,"file":"MC.d.ts","sourceRoot":"","sources":["../src/MC.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAM3C,MAAM,WAAW,aAAc,SAAQ,WAAW;IACjD,GAAG,EAAE,WAAW,CAAC;CACjB;AAmED,iBAAS,GAAG,CAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,kCAAkC,QAE1F;AAED,iBAAS,EAAE,CAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,kCAAkC,EAAE,IAAI,GAAE,OAAe,GAAI,kCAAkC,CAGtJ;AAED,iBAAS,GAAG,CAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,kCAAkC,GAAI,kCAAkC,CAGhI;AAGD,iBAAS,OAAO,CACf,OAAO,EAAE,WAAW,EACpB,KAAK,EAAE,WAAW,GAAG,MAAM,EAC3B,IAAI,GAAE,GAAQ,EACd,MAAM,GAAE,MAAY,QAepB;AA+ED,cAAM,MAAM;IACX,OAAO,CAAC,OAAO,CAAe;gBAElB,MAAM,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE;IAU3C,IAAI,MAAM,IAAI,GAAG,CAEhB;CAED;AAED,cAAM,EAAG,SAAQ,MAAM;gBACV,MAAM,CAAC,EAAE,GAAG;CAGxB;AAED,cAAM,EAAG,SAAQ,MAAM;gBACV,MAAM,EAAE,WAAW,EAAE,KAAK,GAAE,OAAe;IAIvD,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAO;IAC3B,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAU;IAGjC,GAAG,CAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,kCAAkC;IAInE,EAAE,CAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,kCAAkC;IAIlE,GAAG,CAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,kCAAkC;IAInE,OAAO,CAAE,SAAS,EAAE,MAAM,EAAE,IAAI,GAAE,GAAQ,EAAE,MAAM,GAAE,MAAY;IAKhE,SAAS,IAAI,EAAE,EAAE,GAAG,IAAI;IAgBxB,OAAO,IAAI,EAAE,GAAG,IAAI;IAOpB,QAAQ,IAAI,EAAE,EAAE,GAAG,IAAI;IAMvB,WAAW,IAAI,EAAE,EAAE,GAAG,IAAI;CAS1B;AAiHD,iBAAS,QAAQ,CAAC,MAAM,GAAE,OAAc,GAAG,OAAO,CAmBjD;AAID,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC"}
package/dist/MC.js CHANGED
@@ -1,14 +1,5 @@
1
1
  'use strict';
2
2
  const isBrowser = new Function('try {return this===window;}catch(e){ return false;}');
3
- function getNativeEventNames(domNode) {
4
- let nativeEventNames = [];
5
- if (isBrowser()) {
6
- Object.keys(HTMLElement.prototype)
7
- .filter((key) => /^on/.test(key))
8
- .forEach((eventName) => nativeEventNames.push(eventName));
9
- }
10
- return nativeEventNames;
11
- }
12
3
  function isDOM(element) {
13
4
  return element && element instanceof HTMLElement;
14
5
  }
@@ -55,9 +46,11 @@ function off(domNode, eventName, handler) {
55
46
  }
56
47
  function on(domNode, eventName, handler, once = false) {
57
48
  domNode.addEventListener(getMcEventName(eventName), handler, { capture: false, once });
49
+ return handler;
58
50
  }
59
51
  function one(domNode, eventName, handler) {
60
52
  on(domNode, eventName, handler, true);
53
+ return handler;
61
54
  }
62
55
  function trigger(domNode, event, data = {}, bubble = 'l') {
63
56
  const ev = typeof event === 'string'
@@ -152,20 +145,14 @@ class DC extends McBase {
152
145
  off(this.target, eventName, handler);
153
146
  }
154
147
  on(eventName, handler) {
155
- on(this.target, eventName, handler);
148
+ return on(this.target, eventName, handler);
156
149
  }
157
150
  one(eventName, handler) {
158
- one(this.target, eventName, handler);
151
+ return one(this.target, eventName, handler);
159
152
  }
160
153
  trigger(eventName, data = {}, bubble = 'l') {
161
154
  trigger(this.target, eventName, data, bubble);
162
155
  }
163
- parent() {
164
- let target = this.target;
165
- if (!isDOM(target))
166
- return null;
167
- return target.closest('[data-mc]')?._mc || null;
168
- }
169
156
  ancestors() {
170
157
  let currentNode = this?.target, result = [];
171
158
  if (!isDOM(currentNode))
@@ -177,6 +164,12 @@ class DC extends McBase {
177
164
  }
178
165
  return result.length ? result : null;
179
166
  }
167
+ closest() {
168
+ let target = this.target;
169
+ if (!isDOM(target))
170
+ return null;
171
+ return target.closest('[data-mc]')?._mc || null;
172
+ }
180
173
  children() {
181
174
  let target = this?.target;
182
175
  if (!isDOM(target))
package/dist/MC.min.js CHANGED
@@ -57,15 +57,6 @@ __webpack_require__.r(__webpack_exports__);
57
57
  /* harmony export */ });
58
58
 
59
59
  const isBrowser = new Function('try {return this===window;}catch(e){ return false;}');
60
- function getNativeEventNames(domNode) {
61
- let nativeEventNames = [];
62
- if (isBrowser()) {
63
- Object.keys(HTMLElement.prototype)
64
- .filter((key) => /^on/.test(key))
65
- .forEach((eventName) => nativeEventNames.push(eventName));
66
- }
67
- return nativeEventNames;
68
- }
69
60
  function isDOM(element) {
70
61
  return element && element instanceof HTMLElement;
71
62
  }
@@ -112,9 +103,11 @@ function off(domNode, eventName, handler) {
112
103
  }
113
104
  function on(domNode, eventName, handler, once = false) {
114
105
  domNode.addEventListener(getMcEventName(eventName), handler, { capture: false, once });
106
+ return handler;
115
107
  }
116
108
  function one(domNode, eventName, handler) {
117
109
  on(domNode, eventName, handler, true);
110
+ return handler;
118
111
  }
119
112
  function trigger(domNode, event, data = {}, bubble = 'l') {
120
113
  const ev = typeof event === 'string'
@@ -209,20 +202,14 @@ class DC extends McBase {
209
202
  off(this.target, eventName, handler);
210
203
  }
211
204
  on(eventName, handler) {
212
- on(this.target, eventName, handler);
205
+ return on(this.target, eventName, handler);
213
206
  }
214
207
  one(eventName, handler) {
215
- one(this.target, eventName, handler);
208
+ return one(this.target, eventName, handler);
216
209
  }
217
210
  trigger(eventName, data = {}, bubble = 'l') {
218
211
  trigger(this.target, eventName, data, bubble);
219
212
  }
220
- parent() {
221
- let target = this.target;
222
- if (!isDOM(target))
223
- return null;
224
- return target.closest('[data-mc]')?._mc || null;
225
- }
226
213
  ancestors() {
227
214
  let currentNode = this?.target, result = [];
228
215
  if (!isDOM(currentNode))
@@ -234,6 +221,12 @@ class DC extends McBase {
234
221
  }
235
222
  return result.length ? result : null;
236
223
  }
224
+ closest() {
225
+ let target = this.target;
226
+ if (!isDOM(target))
227
+ return null;
228
+ return target.closest('[data-mc]')?._mc || null;
229
+ }
237
230
  children() {
238
231
  let target = this?.target;
239
232
  if (!isDOM(target))
package/dist/MC.ts CHANGED
@@ -6,17 +6,6 @@ const isBrowser = new Function(
6
6
  'try {return this===window;}catch(e){ return false;}'
7
7
  );
8
8
 
9
- // get HTMLElement native event names
10
- function getNativeEventNames( domNode: HTMLElement ): string[] {
11
- let nativeEventNames: Array<string> = [];
12
- if (isBrowser()) {
13
- Object.keys(HTMLElement.prototype)
14
- .filter((key) => /^on/.test(key))
15
- .forEach((eventName) => nativeEventNames.push(eventName));
16
- }
17
- return nativeEventNames;
18
- }
19
-
20
9
  export interface HTMLMcElement extends HTMLElement {
21
10
  _mc: LooseObject;
22
11
  }
@@ -90,12 +79,14 @@ function off( domNode: Node, eventName: string, handler: EventListenerOrEventLis
90
79
  domNode.removeEventListener( getMcEventName(eventName), handler );
91
80
  }
92
81
 
93
- function on( domNode: Node, eventName: string, handler: EventListenerOrEventListenerObject, once: boolean = false ) {
82
+ function on( domNode: Node, eventName: string, handler: EventListenerOrEventListenerObject, once: boolean = false ): EventListenerOrEventListenerObject {
94
83
  domNode.addEventListener( getMcEventName(eventName), handler, { capture: false, once });
84
+ return handler;
95
85
  }
96
86
 
97
- function one( domNode: Node, eventName: string, handler: EventListenerOrEventListenerObject ) {
87
+ function one( domNode: Node, eventName: string, handler: EventListenerOrEventListenerObject ): EventListenerOrEventListenerObject {
98
88
  on(domNode, eventName, handler, true );
89
+ return handler;
99
90
  }
100
91
 
101
92
  // create and dispatch custom event
@@ -236,11 +227,11 @@ class DC extends McBase {
236
227
  }
237
228
 
238
229
  on( eventName: string, handler: EventListenerOrEventListenerObject ) {
239
- on( this.target, eventName, handler );
230
+ return on( this.target, eventName, handler );
240
231
  }
241
232
 
242
233
  one( eventName: string, handler: EventListenerOrEventListenerObject ) {
243
- one( this.target, eventName, handler );
234
+ return one( this.target, eventName, handler );
244
235
  }
245
236
 
246
237
  trigger( eventName: string, data: any = {}, bubble: string = 'l') {
@@ -248,13 +239,6 @@ class DC extends McBase {
248
239
  }
249
240
 
250
241
  /* DOM traversal */
251
- parent(): DC | null {
252
- let
253
- target: HTMLElement = (this as DC).target;
254
- if (!isDOM(target)) return null;
255
- return (target.closest('[data-mc]') as HTMLMcElement)?._mc as DC || null;
256
- }
257
-
258
242
  ancestors(): DC[] | null {
259
243
  let
260
244
  currentNode: HTMLElement | null = (this as DC)?.target as HTMLMcElement,
@@ -271,6 +255,13 @@ class DC extends McBase {
271
255
  return result.length ? result : null;
272
256
  }
273
257
 
258
+ closest(): DC | null {
259
+ let
260
+ target: HTMLElement = (this as DC).target;
261
+ if (!isDOM(target)) return null;
262
+ return (target.closest('[data-mc]') as HTMLMcElement)?._mc as DC || null;
263
+ }
264
+
274
265
  children(): DC[] | null {
275
266
  let target: any = (this as any)?.target;
276
267
  if (!isDOM(target)) return null;
@@ -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.elements=e():t.elements=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:()=>m,getCE:()=>f});const n=new Function("try {return this===window;}catch(e){ return false;}");function r(t){return t&&t instanceof HTMLElement}function o(t,e,n={}){let r=t;r._mc||(r._mc=new l(t));const o=r._mc;return e.length&&!o[e]&&(o[e]=n,t instanceof HTMLElement&&!t.getAttribute("data-mc")&&t.setAttribute("data-mc","")),r}function c(t,e){if(!e)return;const n=t?._mc||{};n&&n[e]&&delete n[e],!Object.keys(n).length&&t instanceof HTMLElement&&t.hasAttribute("data-mc")&&t.removeAttribute("data-mc")}function s(t){return"_mc"+t[0].toUpperCase()+t.substring(1)}function a(t,e,n,r=!1){t.addEventListener(s(e),n,{capture:!1,once:r})}class i{_target;constructor(t){var e;this._target=new WeakRef(t||{}),e=this,setTimeout((()=>{e.constructor!==l&&e.trigger("Init")}),0),function(t){if(!n()||t.constructor===l)return;const e=t.target;if(e instanceof HTMLElement){let n=t;Object.getOwnPropertyNames(n.constructor.prototype).filter((t=>/^on[A-Z]|one[A-Z]/.test(t)&&"function"==typeof n.constructor.prototype[t])).forEach((t=>{let r=/^one/.test(t),o=t.replace(/^on[e]{0,1}/,""),c=o.toLowerCase();if("on"+c in e){let r=e=>{n[t](e)};e.addEventListener(c,r)}else a(e,o,(e=>{n[t](e)}),r)}))}}(this)}get target(){return this._target.deref()}}class l extends i{constructor(t,e=!1){super(t)}static add=o;static remove=c;off(t,e){!function(t,e,n){t.removeEventListener(s(e),n)}(this.target,t,e)}on(t,e){a(this.target,t,e)}one(t,e){!function(t,e,n){a(t,e,n,!0)}(this.target,t,e)}trigger(t,e={},n="l"){!function(t,e,n={},r="l"){const o="string"==typeof e?new CustomEvent(s(e),{detail:{data:n,bubble:r}}):e;r.length&&r.indexOf("l")>-1&&t.dispatchEvent(o),/[u|d]/.test(r)&&function(t,e){setTimeout((()=>{-1===e.detail.bubble.indexOf("l")&&(e.detail.bubble+="l"),e.detail.bubble.indexOf("u")>-1&&t.closest("[data-mc]")?.dispatchEvent(e),e.detail.bubble.indexOf("d")>-1&&new Set(t._mc.children().map((t=>t?.target))).forEach((t=>{t&&t._mc.trigger(t,e)}))}),0)}(t,o)}(this.target,t,e,n)}parent(){let t=this.target;return r(t)&&t.closest("[data-mc]")?._mc||null}ancestors(){let t=this?.target,e=[];if(!r(t))return[];for(;t=t.closest("[data-mc]");)t?._mc&&e.push(t?._mc);return e.length?e:null}children(){let t=this?.target;return r(t)?function(t){const e=Math.random().toString().replace(".",""),n='[data-mc]:not([temp_id="'+e+'"] [data-mc] [data-mc])';t.setAttribute("temp_id",e);const r=[...t.querySelectorAll(n)].filter((t=>!!t._mc)).map((t=>t._mc));return t.removeAttribute("temp_id"),r.length?r:null}(t):null}descendants(){const t=this?.target;if(!r(t))return[];const e=[...t.querySelectorAll("[data-mc]")].filter((t=>!!t._mc)).map((t=>t._mc));return e.length?e:null}}new Set;class u extends HTMLElement{constructor(){super()}connectedCallback(){this.dispatchEvent(new CustomEvent("_mcConnected"))}connectedMoveCallback(){this.dispatchEvent(new CustomEvent("_mcConnectedMove"))}disconnectedCallback(){this.dispatchEvent(new CustomEvent("_mcDisconnected"))}adoptedCallback(){this.dispatchEvent(new CustomEvent("_mcAdopted"))}attributeChangedCallback(t,e,n){this.dispatchEvent(new CustomEvent("_mcAttributeChanged",{detail:{name:t,oldValue:e,newValue:n}}))}formResetCallback(){this.dispatchEvent(new CustomEvent("_mcFormReset"))}}function d(t){return"function"==typeof t&&/^class\s/.test(Function.prototype.toString.call(t))}function m(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("");d(e.prototype.constructor)&&e.prototype instanceof i?customElements.define(t,function(t,e){return Object.defineProperty(e,"name",{value:t})}(r,class extends u{instance;constructor(t){super();const n=d(e)?new e(this,t):e;l.add(this,r,n)}static get observedAttributes(){return n}})):customElements.define(t,e)}function f(t){return customElements.get(t)}return 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.elements=e():t.elements=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:()=>m,getCE:()=>f});const n=new Function("try {return this===window;}catch(e){ return false;}");function r(t){return t&&t instanceof HTMLElement}function o(t,e,n={}){let r=t;r._mc||(r._mc=new l(t));const o=r._mc;return e.length&&!o[e]&&(o[e]=n,t instanceof HTMLElement&&!t.getAttribute("data-mc")&&t.setAttribute("data-mc","")),r}function c(t,e){if(!e)return;const n=t?._mc||{};n&&n[e]&&delete n[e],!Object.keys(n).length&&t instanceof HTMLElement&&t.hasAttribute("data-mc")&&t.removeAttribute("data-mc")}function s(t){return"_mc"+t[0].toUpperCase()+t.substring(1)}function i(t,e,n,r=!1){return t.addEventListener(s(e),n,{capture:!1,once:r}),n}class a{_target;constructor(t){var e;this._target=new WeakRef(t||{}),e=this,setTimeout((()=>{e.constructor!==l&&e.trigger("Init")}),0),function(t){if(!n()||t.constructor===l)return;const e=t.target;if(e instanceof HTMLElement){let n=t;Object.getOwnPropertyNames(n.constructor.prototype).filter((t=>/^on[A-Z]|one[A-Z]/.test(t)&&"function"==typeof n.constructor.prototype[t])).forEach((t=>{let r=/^one/.test(t),o=t.replace(/^on[e]{0,1}/,""),c=o.toLowerCase();if("on"+c in e){let r=e=>{n[t](e)};e.addEventListener(c,r)}else i(e,o,(e=>{n[t](e)}),r)}))}}(this)}get target(){return this._target.deref()}}class l extends a{constructor(t,e=!1){super(t)}static add=o;static remove=c;off(t,e){!function(t,e,n){t.removeEventListener(s(e),n)}(this.target,t,e)}on(t,e){return i(this.target,t,e)}one(t,e){return function(t,e,n){return i(t,e,n,!0),n}(this.target,t,e)}trigger(t,e={},n="l"){!function(t,e,n={},r="l"){const o="string"==typeof e?new CustomEvent(s(e),{detail:{data:n,bubble:r}}):e;r.length&&r.indexOf("l")>-1&&t.dispatchEvent(o),/[u|d]/.test(r)&&function(t,e){setTimeout((()=>{-1===e.detail.bubble.indexOf("l")&&(e.detail.bubble+="l"),e.detail.bubble.indexOf("u")>-1&&t.closest("[data-mc]")?.dispatchEvent(e),e.detail.bubble.indexOf("d")>-1&&new Set(t._mc.children().map((t=>t?.target))).forEach((t=>{t&&t._mc.trigger(t,e)}))}),0)}(t,o)}(this.target,t,e,n)}ancestors(){let t=this?.target,e=[];if(!r(t))return[];for(;t=t.closest("[data-mc]");)t?._mc&&e.push(t?._mc);return e.length?e:null}closest(){let t=this.target;return r(t)&&t.closest("[data-mc]")?._mc||null}children(){let t=this?.target;return r(t)?function(t){const e=Math.random().toString().replace(".",""),n='[data-mc]:not([temp_id="'+e+'"] [data-mc] [data-mc])';t.setAttribute("temp_id",e);const r=[...t.querySelectorAll(n)].filter((t=>!!t._mc)).map((t=>t._mc));return t.removeAttribute("temp_id"),r.length?r:null}(t):null}descendants(){const t=this?.target;if(!r(t))return[];const e=[...t.querySelectorAll("[data-mc]")].filter((t=>!!t._mc)).map((t=>t._mc));return e.length?e:null}}new Set;class u extends HTMLElement{constructor(){super()}connectedCallback(){this.dispatchEvent(new CustomEvent("_mcConnected"))}connectedMoveCallback(){this.dispatchEvent(new CustomEvent("_mcConnectedMove"))}disconnectedCallback(){this.dispatchEvent(new CustomEvent("_mcDisconnected"))}adoptedCallback(){this.dispatchEvent(new CustomEvent("_mcAdopted"))}attributeChangedCallback(t,e,n){this.dispatchEvent(new CustomEvent("_mcAttributeChanged",{detail:{name:t,oldValue:e,newValue:n}}))}formResetCallback(){this.dispatchEvent(new CustomEvent("_mcFormReset"))}}function d(t){return"function"==typeof t&&/^class\s/.test(Function.prototype.toString.call(t))}function m(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("");d(e.prototype.constructor)&&e.prototype instanceof a?customElements.define(t,function(t,e){return Object.defineProperty(e,"name",{value:t})}(r,class extends u{instance;constructor(t){super();const n=d(e)?new e(this,t):e;l.add(this,r,n)}static get observedAttributes(){return n}})):customElements.define(t,e)}function f(t){return customElements.get(t)}return e})()));
@@ -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.formValues=e():t.formValues=e()}(this,(()=>(()=>{"use strict";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},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={};function r(t){let e={};return[...Object.keys(t)].sort().forEach((n=>{var s;(s=t[n])&&s.constructor&&s.constructor===Object?e[n]=r(t[n]):e[n]=t[n]})),e}function n(t,e=!0){let s={};return[...Object.getOwnPropertyNames(t)].forEach((e=>{if(t[e]&&t[e].constructor&&t[e].constructor===Object){const r=n(t[e],!1);for(const t in r)s[e+"."+t]=r[t]}else s[e]=t[e]})),e?r(s):s}function s(t,e){return JSON.stringify(n(t))===JSON.stringify(n(e))}function a(t,e){let r;return()=>{clearTimeout(r),r=setTimeout((function(){t(...arguments)}),e)}}function c(t,e){const r=Object.getOwnPropertyDescriptors(t);for(const[t,n]of Object.entries(r))("get"in n||"set"in n)&&Object.defineProperty(e,t,n)}t.r(e),t.d(e,{formValues:()=>T});const o=new Function("try {return this===window;}catch(e){ return false;}");function l(t){return t&&t instanceof HTMLElement}function i(t,e,r={}){let n=t;n._mc||(n._mc=new m(t));const s=n._mc;return e.length&&!s[e]&&(s[e]=r,t instanceof HTMLElement&&!t.getAttribute("data-mc")&&t.setAttribute("data-mc","")),n}function u(t,e){if(!e)return;const r=t?._mc||{};r&&r[e]&&delete r[e],!Object.keys(r).length&&t instanceof HTMLElement&&t.hasAttribute("data-mc")&&t.removeAttribute("data-mc")}function f(t){return"_mc"+t[0].toUpperCase()+t.substring(1)}function d(t,e,r,n=!1){t.addEventListener(f(e),r,{capture:!1,once:n})}function h(t,e,r={},n="l"){const s="string"==typeof e?new CustomEvent(f(e),{detail:{data:r,bubble:n}}):e;n.length&&n.indexOf("l")>-1&&t.dispatchEvent(s),/[u|d]/.test(n)&&function(t,e){setTimeout((()=>{-1===e.detail.bubble.indexOf("l")&&(e.detail.bubble+="l"),e.detail.bubble.indexOf("u")>-1&&t.closest("[data-mc]")?.dispatchEvent(e),e.detail.bubble.indexOf("d")>-1&&new Set(t._mc.children().map((t=>t?.target))).forEach((t=>{t&&t._mc.trigger(t,e)}))}),0)}(t,s)}class b{_target;constructor(t){var e;this._target=new WeakRef(t||{}),e=this,setTimeout((()=>{e.constructor!==m&&e.trigger("Init")}),0),function(t){if(!o()||t.constructor===m)return;const e=t.target;if(e instanceof HTMLElement){let r=t;Object.getOwnPropertyNames(r.constructor.prototype).filter((t=>/^on[A-Z]|one[A-Z]/.test(t)&&"function"==typeof r.constructor.prototype[t])).forEach((t=>{let n=/^one/.test(t),s=t.replace(/^on[e]{0,1}/,""),a=s.toLowerCase();if("on"+a in e){let n=e=>{r[t](e)};e.addEventListener(a,n)}else d(e,s,(e=>{r[t](e)}),n)}))}}(this)}get target(){return this._target.deref()}}class m extends b{constructor(t,e=!1){super(t)}static add=i;static remove=u;off(t,e){!function(t,e,r){t.removeEventListener(f(e),r)}(this.target,t,e)}on(t,e){d(this.target,t,e)}one(t,e){!function(t,e,r){d(t,e,r,!0)}(this.target,t,e)}trigger(t,e={},r="l"){h(this.target,t,e,r)}parent(){let t=this.target;return l(t)&&t.closest("[data-mc]")?._mc||null}ancestors(){let t=this?.target,e=[];if(!l(t))return[];for(;t=t.closest("[data-mc]");)t?._mc&&e.push(t?._mc);return e.length?e:null}children(){let t=this?.target;return l(t)?function(t){const e=Math.random().toString().replace(".",""),r='[data-mc]:not([temp_id="'+e+'"] [data-mc] [data-mc])';t.setAttribute("temp_id",e);const n=[...t.querySelectorAll(r)].filter((t=>!!t._mc)).map((t=>t._mc));return t.removeAttribute("temp_id"),n.length?n:null}(t):null}descendants(){const t=this?.target;if(!l(t))return[];const e=[...t.querySelectorAll("[data-mc]")].filter((t=>!!t._mc)).map((t=>t._mc));return e.length?e:null}}function p(t){return null!=t&&"object"==typeof t}function g(t){let e=new Set,r=/\{[^\{\}]*\}/g;return(t.getAttributeNames?t.getAttributeNames():[]).filter((e=>t.getAttribute(e)?.match(r))).forEach((e=>{let n=new Set(t.getAttribute(e)?.match(r));n.forEach((t=>n.add(t.replace(/[\{\}]/g,""))))})),[...t.childNodes].filter((t=>3===t.nodeType&&(t.nodeValue||"").match(r))).forEach((t=>{(t.nodeValue||"").match(r).forEach((t=>{e.add(t.replace(/[\{\}]/g,""))}))})),[...e].map((t=>t.replace(/[\{\}]/g,"")))}new Set;const y=[HTMLInputElement,HTMLSelectElement,HTMLTextAreaElement];class v extends m{data={};oldDisplay="";constructor(t){super(t),g(t).forEach((t=>this.data[t]="")),w(this),this.#t()}#t(){let t=this.target,e=!1;(t.getAttributeNames?t.getAttributeNames():[]).filter((e=>t.getAttribute(e)?.match(/\{[^\{\}]*\}/g))).forEach((e=>{let r=new Set(t.getAttribute(e)?.match(/\{[^\{\}]*\}/g));var n;this.data.observe((n=t.getAttribute(e),s=>{let a=n;r.forEach((t=>{a=a.replace(t,s[t.replace(/[\{\}]/g,"")])})),t.setAttribute(e,a)}))})),[...t.childNodes].filter((t=>3===t.nodeType&&(t.nodeValue||"").match(/\{[^\{\}]*\}/g))).forEach((r=>{e=!0;let n=new Set(r.nodeValue.match(/\{[^\{\}]*\}/g));this.data.observe((e=>s=>{let a=e;n.forEach((t=>{a=a.replace(t,s[t.replace(/[\{\}]/g,"")])})),this.oldDisplay?t.style=this.oldDisplay:t.removeAttribute("style"),delete this.oldDisplay,r.nodeValue=a})(r.nodeValue)),this.oldDisplay=t.getAttribute("style")||"",e&&!y.includes(t.constructor)&&"FIELDSET"!==t.tagName&&(t.style.display="none")}))}onData(t){let e={};Object.keys(t.detail.data).forEach((r=>{this.data.hasOwnProperty(r)&&(e[r]=t.detail.data[r])})),JSON.stringify(e)!==JSON.stringify(this.data)&&Object.assign(this.data,e)}}const O={};function E(t){let e=t.constructor.name;return O[e]||function(t){const e=t.constructor,r=e.name;let s=class extends e{#e=!0;#r=[];constructor(t){super(t),this.constructor.callbacks=[],p(t)&&Object.getOwnPropertyNames(t).forEach((e=>{this[e]=t[e]}))}get callbacks(){return this.#r}set callbacks(t){this.#r=t}observe(t){return this.#r.push(t),this}bind(t){if(p(this.valueOf())){!function(t){var e;(e=t,[e].concat([...e.querySelectorAll("*")]).filter((t=>!!g(t).length)).filter((t=>"STYLE"!==t?.tagName)).reverse()).forEach((t=>{t?._mc?._placeholders||m.add(t,"_placeholders",new v(t))}))}(t);const e=[t,...t.querySelectorAll("[data-mc]")].filter((t=>!!t?._mc?._placeholders)),r=function(t){let r=n(t);e.forEach((t=>{t&&h(t,"data",r)}))};this.#r.push(r),this.notify()}else console.warn("IGNORED - cannot bind a non-Object to the dom, IS:",typeof this.valueOf(),this);return this}notify(t){let e=p(this.valueOf())&&this.valueOf()instanceof Array==0?structuredClone(Object.assign({},this)):this.valueOf();return void 0!==t&&(this.#e=t),this.#r.forEach((t=>{t(e)})),this}};return O[r]=s,s}(t)}const w=(t,e)=>((e?[e]:[...Object.getOwnPropertyNames(t)]).forEach((e=>{if(t.hasOwnProperty(e)&&"function"!=typeof t[e]&&!t?.[e]?.constructor?.prototype?.observe){if("_"===e[0]||void 0===t?.[e])return t;let r=t[e],n=new(E(r))(r);Object.defineProperty(t,e,{enumerable:!0,get(){if(p(n.valueOf())){let t=structuredClone(Object.assign({},n));setTimeout(a((function(){s(structuredClone(Object.assign({},n)),t)||n.notify()}),0),0)}return n},set(t){if(typeof t==typeof n.valueOf())if(p(n.valueOf())&&n.valueOf()instanceof Array==0){let e=structuredClone(Object.assign({},n));void 0===n?.constructor?.prototype?.observe&&(n=new(E(t))(structuredClone(Object.assign({},t))),c(t,n),n.seal()),Object.assign(n,t),setTimeout(a((function(){s(structuredClone(Object.assign({},n)),e)||n.notify()}),0),0)}else{let e=n.valueOf(),r=n.callbacks;t!==e&&(n=new(E(t))(t),n.callbacks=r,n.notify())}else console.warn("IGNORED - cannot change observable types, IS:",typeof n.valueOf(),n,"- CANNOT BECOME:",typeof t)}}),t[e]=r}})),t);class A{constructor(t){}}class j extends A{#n;constructor(t){super(t),this.#n=t}get val(){return new FormData(this.#n.form).get(this.#n.name)}set val(t){[...this.#n.form.querySelectorAll(`input[type="radio"][name="${this.#n.name}"]`)].filter((e=>e.getAttribute("value")===t)).shift().checked=!0}}class S extends A{#n;constructor(t){super(t),this.#n=t}get val(){return this.#n.checked}set val(t){this.#n.checked=t}}class _ extends A{#n;constructor(t){super(t),this.#n=t}get val(){return this.#n.value}set val(t){this.#n.value=t}}class k extends A{#n;#s=!1;constructor(t){super(t),this.#n=t,this.#s=t.multiple}get val(){const t=[];return[...this.#n.querySelectorAll("option")].filter((t=>t.selected)).forEach((e=>{t.push(e.value)})),this.#s?t:t.length?t[0]:""}set val(t){t="string"==typeof t?[t]:t,[...this.#n.querySelectorAll("option")].forEach((e=>{t.indexOf(e.value)>-1?e.selected=!0:e.selected=!1}))}}class x extends A{#n;constructor(t){super(t),this.#n=t}get val(){return this.#n.value||""}set val(t){this.#n.value=t}}const N=t=>{let e=[...(t||document).querySelectorAll("input,select,textarea")],r={};return e.forEach((t=>{const e=t.getAttribute("name");if(e){let n=!1;switch((t=>t.tagName.toLowerCase())(t)){case"input":switch(t.type){case"radio":n=new j(t);break;case"checkbox":n=new S(t);break;default:n=new _(t)}break;case"select":n=new k(t);break;case"textarea":n=new x(t);break;default:console.warn("handler missing:",e,"for",t.tagName.toLowerCase(),t)}n&&(m.add(t,e,n),Object.defineProperty(r,e,{enumerable:!0,configurable:!0,get:()=>n.val,set:t=>{n.val!==t&&(n.val=t)}}))}})),r};function T(t,e,r){let n=N(r);t[e]=Object.assign({},n),w(t,e),c(n,t[e]),[...r.querySelectorAll("input, textarea, select")].forEach((r=>{r.addEventListener("input",(r=>{t[e].notify()}))}))}return 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.formValues=e():t.formValues=e()}(this,(()=>(()=>{"use strict";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},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={};function r(t){let e={};return[...Object.keys(t)].sort().forEach((n=>{var s;(s=t[n])&&s.constructor&&s.constructor===Object?e[n]=r(t[n]):e[n]=t[n]})),e}function n(t,e=!0){let s={};return[...Object.getOwnPropertyNames(t)].forEach((e=>{if(t[e]&&t[e].constructor&&t[e].constructor===Object){const r=n(t[e],!1);for(const t in r)s[e+"."+t]=r[t]}else s[e]=t[e]})),e?r(s):s}function s(t,e){return JSON.stringify(n(t))===JSON.stringify(n(e))}function a(t,e){let r;return()=>{clearTimeout(r),r=setTimeout((function(){t(...arguments)}),e)}}function c(t,e){const r=Object.getOwnPropertyDescriptors(t);for(const[t,n]of Object.entries(r))("get"in n||"set"in n)&&Object.defineProperty(e,t,n)}t.r(e),t.d(e,{formValues:()=>T});const o=new Function("try {return this===window;}catch(e){ return false;}");function l(t){return t&&t instanceof HTMLElement}function i(t,e,r={}){let n=t;n._mc||(n._mc=new m(t));const s=n._mc;return e.length&&!s[e]&&(s[e]=r,t instanceof HTMLElement&&!t.getAttribute("data-mc")&&t.setAttribute("data-mc","")),n}function u(t,e){if(!e)return;const r=t?._mc||{};r&&r[e]&&delete r[e],!Object.keys(r).length&&t instanceof HTMLElement&&t.hasAttribute("data-mc")&&t.removeAttribute("data-mc")}function f(t){return"_mc"+t[0].toUpperCase()+t.substring(1)}function d(t,e,r,n=!1){return t.addEventListener(f(e),r,{capture:!1,once:n}),r}function h(t,e,r={},n="l"){const s="string"==typeof e?new CustomEvent(f(e),{detail:{data:r,bubble:n}}):e;n.length&&n.indexOf("l")>-1&&t.dispatchEvent(s),/[u|d]/.test(n)&&function(t,e){setTimeout((()=>{-1===e.detail.bubble.indexOf("l")&&(e.detail.bubble+="l"),e.detail.bubble.indexOf("u")>-1&&t.closest("[data-mc]")?.dispatchEvent(e),e.detail.bubble.indexOf("d")>-1&&new Set(t._mc.children().map((t=>t?.target))).forEach((t=>{t&&t._mc.trigger(t,e)}))}),0)}(t,s)}class b{_target;constructor(t){var e;this._target=new WeakRef(t||{}),e=this,setTimeout((()=>{e.constructor!==m&&e.trigger("Init")}),0),function(t){if(!o()||t.constructor===m)return;const e=t.target;if(e instanceof HTMLElement){let r=t;Object.getOwnPropertyNames(r.constructor.prototype).filter((t=>/^on[A-Z]|one[A-Z]/.test(t)&&"function"==typeof r.constructor.prototype[t])).forEach((t=>{let n=/^one/.test(t),s=t.replace(/^on[e]{0,1}/,""),a=s.toLowerCase();if("on"+a in e){let n=e=>{r[t](e)};e.addEventListener(a,n)}else d(e,s,(e=>{r[t](e)}),n)}))}}(this)}get target(){return this._target.deref()}}class m extends b{constructor(t,e=!1){super(t)}static add=i;static remove=u;off(t,e){!function(t,e,r){t.removeEventListener(f(e),r)}(this.target,t,e)}on(t,e){return d(this.target,t,e)}one(t,e){return function(t,e,r){return d(t,e,r,!0),r}(this.target,t,e)}trigger(t,e={},r="l"){h(this.target,t,e,r)}ancestors(){let t=this?.target,e=[];if(!l(t))return[];for(;t=t.closest("[data-mc]");)t?._mc&&e.push(t?._mc);return e.length?e:null}closest(){let t=this.target;return l(t)&&t.closest("[data-mc]")?._mc||null}children(){let t=this?.target;return l(t)?function(t){const e=Math.random().toString().replace(".",""),r='[data-mc]:not([temp_id="'+e+'"] [data-mc] [data-mc])';t.setAttribute("temp_id",e);const n=[...t.querySelectorAll(r)].filter((t=>!!t._mc)).map((t=>t._mc));return t.removeAttribute("temp_id"),n.length?n:null}(t):null}descendants(){const t=this?.target;if(!l(t))return[];const e=[...t.querySelectorAll("[data-mc]")].filter((t=>!!t._mc)).map((t=>t._mc));return e.length?e:null}}function p(t){return null!=t&&"object"==typeof t}function g(t){let e=new Set,r=/\{[^\{\}]*\}/g;return(t.getAttributeNames?t.getAttributeNames():[]).filter((e=>t.getAttribute(e)?.match(r))).forEach((e=>{let n=new Set(t.getAttribute(e)?.match(r));n.forEach((t=>n.add(t.replace(/[\{\}]/g,""))))})),[...t.childNodes].filter((t=>3===t.nodeType&&(t.nodeValue||"").match(r))).forEach((t=>{(t.nodeValue||"").match(r).forEach((t=>{e.add(t.replace(/[\{\}]/g,""))}))})),[...e].map((t=>t.replace(/[\{\}]/g,"")))}new Set;const y=[HTMLInputElement,HTMLSelectElement,HTMLTextAreaElement];class v extends m{data={};oldDisplay="";constructor(t){super(t),g(t).forEach((t=>this.data[t]="")),w(this),this.#t()}#t(){let t=this.target,e=!1;(t.getAttributeNames?t.getAttributeNames():[]).filter((e=>t.getAttribute(e)?.match(/\{[^\{\}]*\}/g))).forEach((e=>{let r=new Set(t.getAttribute(e)?.match(/\{[^\{\}]*\}/g));var n;this.data.observe((n=t.getAttribute(e),s=>{let a=n;r.forEach((t=>{a=a.replace(t,s[t.replace(/[\{\}]/g,"")])})),t.setAttribute(e,a)}))})),[...t.childNodes].filter((t=>3===t.nodeType&&(t.nodeValue||"").match(/\{[^\{\}]*\}/g))).forEach((r=>{e=!0;let n=new Set(r.nodeValue.match(/\{[^\{\}]*\}/g));this.data.observe((e=>s=>{let a=e;n.forEach((t=>{a=a.replace(t,s[t.replace(/[\{\}]/g,"")])})),this.oldDisplay?t.style=this.oldDisplay:t.removeAttribute("style"),delete this.oldDisplay,r.nodeValue=a})(r.nodeValue)),this.oldDisplay=t.getAttribute("style")||"",e&&!y.includes(t.constructor)&&"FIELDSET"!==t.tagName&&(t.style.display="none")}))}onData(t){let e={};Object.keys(t.detail.data).forEach((r=>{this.data.hasOwnProperty(r)&&(e[r]=t.detail.data[r])})),JSON.stringify(e)!==JSON.stringify(this.data)&&Object.assign(this.data,e)}}const O={};function E(t){let e=t.constructor.name;return O[e]||function(t){const e=t.constructor,r=e.name;let s=class extends e{#e=!0;#r=[];constructor(t){super(t),this.constructor.callbacks=[],p(t)&&Object.getOwnPropertyNames(t).forEach((e=>{this[e]=t[e]}))}get callbacks(){return this.#r}set callbacks(t){this.#r=t}observe(t){return this.#r.push(t),this}bind(t){if(p(this.valueOf())){!function(t){var e;(e=t,[e].concat([...e.querySelectorAll("*")]).filter((t=>!!g(t).length)).filter((t=>"STYLE"!==t?.tagName)).reverse()).forEach((t=>{t?._mc?._placeholders||m.add(t,"_placeholders",new v(t))}))}(t);const e=[t,...t.querySelectorAll("[data-mc]")].filter((t=>!!t?._mc?._placeholders)),r=function(t){let r=n(t);e.forEach((t=>{t&&h(t,"data",r)}))};this.#r.push(r),this.notify()}else console.warn("IGNORED - cannot bind a non-Object to the dom, IS:",typeof this.valueOf(),this);return this}notify(t){let e=p(this.valueOf())&&this.valueOf()instanceof Array==0?structuredClone(Object.assign({},this)):this.valueOf();return void 0!==t&&(this.#e=t),this.#r.forEach((t=>{t(e)})),this}};return O[r]=s,s}(t)}const w=(t,e)=>((e?[e]:[...Object.getOwnPropertyNames(t)]).forEach((e=>{if(t.hasOwnProperty(e)&&"function"!=typeof t[e]&&!t?.[e]?.constructor?.prototype?.observe){if("_"===e[0]||void 0===t?.[e])return t;let r=t[e],n=new(E(r))(r);Object.defineProperty(t,e,{enumerable:!0,get(){if(p(n.valueOf())){let t=structuredClone(Object.assign({},n));setTimeout(a((function(){s(structuredClone(Object.assign({},n)),t)||n.notify()}),0),0)}return n},set(t){if(typeof t==typeof n.valueOf())if(p(n.valueOf())&&n.valueOf()instanceof Array==0){let e=structuredClone(Object.assign({},n));void 0===n?.constructor?.prototype?.observe&&(n=new(E(t))(structuredClone(Object.assign({},t))),c(t,n),n.seal()),Object.assign(n,t),setTimeout(a((function(){s(structuredClone(Object.assign({},n)),e)||n.notify()}),0),0)}else{let e=n.valueOf(),r=n.callbacks;t!==e&&(n=new(E(t))(t),n.callbacks=r,n.notify())}else console.warn("IGNORED - cannot change observable types, IS:",typeof n.valueOf(),n,"- CANNOT BECOME:",typeof t)}}),t[e]=r}})),t);class A{constructor(t){}}class j extends A{#n;constructor(t){super(t),this.#n=t}get val(){return new FormData(this.#n.form).get(this.#n.name)}set val(t){[...this.#n.form.querySelectorAll(`input[type="radio"][name="${this.#n.name}"]`)].filter((e=>e.getAttribute("value")===t)).shift().checked=!0}}class S extends A{#n;constructor(t){super(t),this.#n=t}get val(){return this.#n.checked}set val(t){this.#n.checked=t}}class _ extends A{#n;constructor(t){super(t),this.#n=t}get val(){return this.#n.value}set val(t){this.#n.value=t}}class k extends A{#n;#s=!1;constructor(t){super(t),this.#n=t,this.#s=t.multiple}get val(){const t=[];return[...this.#n.querySelectorAll("option")].filter((t=>t.selected)).forEach((e=>{t.push(e.value)})),this.#s?t:t.length?t[0]:""}set val(t){t="string"==typeof t?[t]:t,[...this.#n.querySelectorAll("option")].forEach((e=>{t.indexOf(e.value)>-1?e.selected=!0:e.selected=!1}))}}class x extends A{#n;constructor(t){super(t),this.#n=t}get val(){return this.#n.value||""}set val(t){this.#n.value=t}}const N=t=>{let e=[...(t||document).querySelectorAll("input,select,textarea")],r={};return e.forEach((t=>{const e=t.getAttribute("name");if(e){let n=!1;switch((t=>t.tagName.toLowerCase())(t)){case"input":switch(t.type){case"radio":n=new j(t);break;case"checkbox":n=new S(t);break;default:n=new _(t)}break;case"select":n=new k(t);break;case"textarea":n=new x(t);break;default:console.warn("handler missing:",e,"for",t.tagName.toLowerCase(),t)}n&&(m.add(t,e,n),Object.defineProperty(r,e,{enumerable:!0,configurable:!0,get:()=>n.val,set:t=>{n.val!==t&&(n.val=t)}}))}})),r};function T(t,e,r){let n=N(r);t[e]=Object.assign({},n),w(t,e),c(n,t[e]),[...r.querySelectorAll("input, textarea, select")].forEach((r=>{r.addEventListener("input",(r=>{t[e].notify()}))}))}return e})()));