@twobirds/microcomponents 0.0.66 → 0.0.68

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 (202) hide show
  1. package/.vscode/settings.json +1 -1
  2. package/README.md +11 -7
  3. package/assets/documentation/formvalues.md +26 -0
  4. package/assets/{test.html → test/test.html} +7 -7
  5. package/dist/microcomponents.d.ts +0 -1
  6. package/dist/microcomponents.d.ts.map +1 -1
  7. package/dist/microcomponents.min.js +1 -1
  8. package/dist/microcomponents.ts +1 -1
  9. package/package.json +5 -4
  10. package/public/MC.d.ts +36 -0
  11. package/public/MC.d.ts.map +1 -0
  12. package/public/MC.ts +605 -0
  13. package/public/McEvent.d.ts +15 -0
  14. package/public/McEvent.d.ts.map +1 -0
  15. package/public/McEvent.ts +96 -0
  16. package/public/MicroComponents.svg +15 -0
  17. package/public/documentation/MC.md +588 -0
  18. package/public/documentation/ajaxian-1.png +0 -0
  19. package/public/documentation/ajaxian-2.png +0 -0
  20. package/public/documentation/ajaxian-3.png +0 -0
  21. package/public/documentation/elements.md +278 -0
  22. package/public/documentation/formvalues.md +26 -0
  23. package/public/documentation/functional_requirements.md +8 -0
  24. package/public/documentation/history.md +436 -0
  25. package/public/documentation/magic.md +29 -0
  26. package/public/documentation/observables.md +107 -0
  27. package/public/documentation/rnd0023-1.jpg +0 -0
  28. package/public/documentation/rnd0023-2.jpg +0 -0
  29. package/public/documentation/rnd0023-3.jpg +0 -0
  30. package/public/documentation/tB_react.md +207 -0
  31. package/public/documentation/usage.md +142 -0
  32. package/public/documentation/why.md +25 -0
  33. package/public/elements.d.ts +5 -0
  34. package/public/elements.d.ts.map +1 -0
  35. package/public/elements.ts +76 -0
  36. package/public/fiddle/MicroComponents.svg +15 -0
  37. package/public/fiddle/fiddle.css +0 -0
  38. package/public/fiddle/fiddle.js +0 -0
  39. package/public/fiddle/index.html +0 -0
  40. package/public/formValues.d.ts +3 -0
  41. package/public/formValues.d.ts.map +1 -0
  42. package/public/formValues.ts +233 -0
  43. package/public/helpers.d.ts +14 -0
  44. package/public/helpers.d.ts.map +1 -0
  45. package/public/helpers.ts +149 -0
  46. package/public/microcomponents.d.ts +7 -0
  47. package/public/microcomponents.d.ts.map +1 -0
  48. package/public/microcomponents.es3.d.ts +2 -0
  49. package/public/microcomponents.es3.d.ts.map +1 -0
  50. package/public/microcomponents.js +0 -1
  51. package/public/microcomponents.js.map +1 -1
  52. package/public/microcomponents.min.js +1 -1
  53. package/public/microcomponents.ts +8 -0
  54. package/public/observables.d.ts +10 -0
  55. package/public/observables.d.ts.map +1 -0
  56. package/public/observables.ts +401 -0
  57. package/public/selectors.d.ts +108 -0
  58. package/public/selectors.d.ts.map +1 -0
  59. package/public/selectors.ts +1634 -0
  60. package/public/src/MC.ts +605 -0
  61. package/public/src/McEvent.ts +96 -0
  62. package/public/src/elements.ts +76 -0
  63. package/public/src/formValues.ts +233 -0
  64. package/public/src/helpers.ts +149 -0
  65. package/public/src/microcomponents.ts +8 -0
  66. package/public/src/observables.ts +401 -0
  67. package/public/src/selectors.ts +1634 -0
  68. package/public/src/test.ts +193 -0
  69. package/public/test/MC.d.ts +36 -0
  70. package/public/test/MC.d.ts.map +1 -0
  71. package/public/test/MC.js +378 -0
  72. package/public/test/MC.js.map +1 -0
  73. package/public/test/MC.ts +605 -0
  74. package/public/test/McEvent.d.ts +15 -0
  75. package/public/test/McEvent.d.ts.map +1 -0
  76. package/public/test/McEvent.js +71 -0
  77. package/public/test/McEvent.js.map +1 -0
  78. package/public/test/McEvent.ts +96 -0
  79. package/public/test/MicroComponents.svg +15 -0
  80. package/public/test/elements.d.ts +5 -0
  81. package/public/test/elements.d.ts.map +1 -0
  82. package/public/test/elements.js +48 -0
  83. package/public/test/elements.js.map +1 -0
  84. package/public/test/elements.ts +76 -0
  85. package/public/test/formValues.d.ts +3 -0
  86. package/public/test/formValues.d.ts.map +1 -0
  87. package/public/test/formValues.js +168 -0
  88. package/public/test/formValues.js.map +1 -0
  89. package/public/test/formValues.ts +233 -0
  90. package/public/test/grandparent.css +13 -0
  91. package/public/test/helpers.d.ts +14 -0
  92. package/public/test/helpers.d.ts.map +1 -0
  93. package/public/test/helpers.js +113 -0
  94. package/public/test/helpers.js.map +1 -0
  95. package/public/test/helpers.ts +149 -0
  96. package/public/test/microcomponents.d.ts +7 -0
  97. package/public/test/microcomponents.d.ts.map +1 -0
  98. package/public/test/microcomponents.es3.d.ts +2 -0
  99. package/public/test/microcomponents.es3.d.ts.map +1 -0
  100. package/public/test/microcomponents.es3.js +303 -0
  101. package/public/test/microcomponents.es3.js.map +1 -0
  102. package/public/test/microcomponents.js +8 -0
  103. package/public/test/microcomponents.js.map +1 -0
  104. package/public/test/microcomponents.min.js +1 -0
  105. package/public/test/microcomponents.ts +8 -0
  106. package/public/test/my-tag.css +19 -0
  107. package/public/test/observables.d.ts +10 -0
  108. package/public/test/observables.d.ts.map +1 -0
  109. package/public/test/observables.js +250 -0
  110. package/public/test/observables.js.map +1 -0
  111. package/public/test/observables.ts +401 -0
  112. package/public/test/selectors.d.ts +108 -0
  113. package/public/test/selectors.d.ts.map +1 -0
  114. package/public/test/selectors.js +971 -0
  115. package/public/test/selectors.js.map +1 -0
  116. package/public/test/selectors.ts +1634 -0
  117. package/public/test/test/child.d.ts +2 -0
  118. package/public/test/test/child.d.ts.map +1 -0
  119. package/public/test/test/child.js +15 -0
  120. package/public/test/test/child.js.map +1 -0
  121. package/public/test/test/grandchild.d.ts +2 -0
  122. package/public/test/test/grandchild.d.ts.map +1 -0
  123. package/public/test/test/grandchild.js +15 -0
  124. package/public/test/test/grandchild.js.map +1 -0
  125. package/public/test/test/grandparent.d.ts +2 -0
  126. package/public/test/test/grandparent.d.ts.map +1 -0
  127. package/public/test/test/grandparent.js +1 -0
  128. package/public/test/test/grandparent.js.map +1 -0
  129. package/public/test/test/greatgrandchild.d.ts +2 -0
  130. package/public/test/test/greatgrandchild.d.ts.map +1 -0
  131. package/public/test/test/greatgrandchild.js +29 -0
  132. package/public/test/test/greatgrandchild.js.map +1 -0
  133. package/public/test/test/parent.d.ts +2 -0
  134. package/public/test/test/parent.d.ts.map +1 -0
  135. package/public/test/test/parent.js +15 -0
  136. package/public/test/test/parent.js.map +1 -0
  137. package/public/test/test/testform.d.ts +2 -0
  138. package/public/test/test/testform.d.ts.map +1 -0
  139. package/public/test/test/testform.js +1 -0
  140. package/public/test/test/testform.js.map +1 -0
  141. package/public/test/test/testmc.d.ts +6 -0
  142. package/public/test/test/testmc.d.ts.map +1 -0
  143. package/public/test/test/testmc.js +10 -0
  144. package/public/test/test/testmc.js.map +1 -0
  145. package/public/test/test.d.ts +2 -0
  146. package/public/test/test.d.ts.map +1 -0
  147. package/public/test/test.html +27 -0
  148. package/public/test/test.ts +193 -0
  149. package/public/typedoc/.nojekyll +1 -0
  150. package/public/{classes → typedoc/classes}/MC.DC.html +2 -2
  151. package/public/{classes → typedoc/classes}/MC.MC.html +2 -2
  152. package/public/{classes → typedoc/classes}/MC.McBase.html +2 -2
  153. package/public/{classes → typedoc/classes}/MC.McEvent.html +2 -2
  154. package/public/{functions → typedoc/functions}/MC.addListener.html +1 -1
  155. package/public/{functions → typedoc/functions}/MC.autoload.html +1 -1
  156. package/public/{functions → typedoc/functions}/MC.removeListener.html +1 -1
  157. package/public/{functions → typedoc/functions}/elements.defineCE.html +1 -1
  158. package/public/{functions → typedoc/functions}/elements.getCE.html +1 -1
  159. package/public/{functions → typedoc/functions}/formValues.formValues.html +1 -1
  160. package/public/{functions → typedoc/functions}/observables.observe.html +1 -1
  161. package/public/{functions → typedoc/functions}/selectors._d.html +1 -1
  162. package/public/{functions → typedoc/functions}/selectors._t.html +1 -1
  163. package/public/{index.html → typedoc/index.html} +9 -7
  164. package/public/{interfaces → typedoc/interfaces}/MC.HTMLMcElement.html +2 -2
  165. package/public/{interfaces → typedoc/interfaces}/selectors.DSelector.html +2 -2
  166. package/public/{interfaces → typedoc/interfaces}/selectors.TSelector.html +2 -2
  167. package/public/typedoc/media/MicroComponents.svg +15 -0
  168. package/public/{modules → typedoc/modules}/MC.html +1 -1
  169. package/public/{modules → typedoc/modules}/elements.html +1 -1
  170. package/public/{modules → typedoc/modules}/formValues.html +1 -1
  171. package/public/{modules → typedoc/modules}/observables.html +1 -1
  172. package/public/{modules → typedoc/modules}/selectors.html +1 -1
  173. package/public/{types → typedoc/types}/observables.Observable.html +1 -1
  174. package/public/{types → typedoc/types}/selectors.selection.html +1 -1
  175. package/public/{types → typedoc/types}/selectors.singleSelector.html +1 -1
  176. package/src/microcomponents.ts +1 -1
  177. package/src/test/{child.ts → test/child.ts} +1 -1
  178. package/src/test/{grandchild.ts → test/grandchild.ts} +1 -1
  179. package/src/test/{grandparent.ts → test/grandparent.ts} +1 -1
  180. package/src/test/{greatgrandchild.ts → test/greatgrandchild.ts} +1 -1
  181. package/src/test/{parent.ts → test/parent.ts} +1 -1
  182. package/src/test/{testform.ts → test/testform.ts} +1 -1
  183. package/src/test/test/testmc.ts +12 -0
  184. package/tsconfig.json +2 -2
  185. package/typedoc.json +1 -1
  186. package/webpack.config.js +4 -4
  187. package/assets/3d.html +0 -42
  188. package/src/test/testmc.ts +0 -18
  189. /package/{public/media → assets/test}/MicroComponents.svg +0 -0
  190. /package/assets/{grandparent.css → test/grandparent.css} +0 -0
  191. /package/assets/{my-tag.css → test/my-tag.css} +0 -0
  192. /package/public/{test.js → test/test.js} +0 -0
  193. /package/public/{test.js.map → test/test.js.map} +0 -0
  194. /package/public/{assets → typedoc/assets}/highlight.css +0 -0
  195. /package/public/{assets → typedoc/assets}/icons.js +0 -0
  196. /package/public/{assets → typedoc/assets}/icons.svg +0 -0
  197. /package/public/{assets → typedoc/assets}/main.js +0 -0
  198. /package/public/{assets → typedoc/assets}/navigation.js +0 -0
  199. /package/public/{assets → typedoc/assets}/search.js +0 -0
  200. /package/public/{assets → typedoc/assets}/style.css +0 -0
  201. /package/public/{hierarchy.html → typedoc/hierarchy.html} +0 -0
  202. /package/public/{modules.html → typedoc/modules.html} +0 -0
@@ -0,0 +1,233 @@
1
+ 'use strict';
2
+
3
+ import { LooseObject, copyGettersSetters } from './helpers.js';
4
+ import { DC, addListener } from './MC.js';
5
+ import { observe } from './observables.js';
6
+
7
+ type inputTypes = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
8
+
9
+ const getInputName = (
10
+ e: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement
11
+ ): string => {
12
+ return e.tagName.toLowerCase();
13
+ };
14
+
15
+ abstract class InputBase {
16
+ constructor(e: inputTypes) {}
17
+
18
+ abstract get val(): any;
19
+
20
+ abstract set val(value: any);
21
+ }
22
+
23
+ class RadioHandler extends InputBase {
24
+ #e: HTMLInputElement;
25
+
26
+ constructor(e: HTMLInputElement) {
27
+ super(e);
28
+ this.#e = e;
29
+ }
30
+
31
+ get val(): string {
32
+ let ret = new FormData(this.#e.form as HTMLFormElement).get(this.#e.name);
33
+
34
+ //console.log('radio[', this.#e.name, '] = "' + ret + '"');
35
+ return ret as string;
36
+ }
37
+
38
+ set val(value: string) {
39
+ let arr = [
40
+ ...(this.#e.form as HTMLFormElement).querySelectorAll(
41
+ `input[type="radio"][name="${this.#e.name}"]`
42
+ ),
43
+ ] as HTMLInputElement[];
44
+
45
+ (
46
+ arr
47
+ .filter((e) => e.getAttribute('value') === value)
48
+ .shift() as HTMLInputElement
49
+ ).checked = true;
50
+ }
51
+ }
52
+
53
+ class CheckboxHandler extends InputBase {
54
+ #e: HTMLInputElement;
55
+
56
+ constructor(e: HTMLInputElement) {
57
+ super(e);
58
+ this.#e = e;
59
+ }
60
+
61
+ get val(): boolean {
62
+ return this.#e.checked;
63
+ }
64
+
65
+ set val(value: boolean) {
66
+ this.#e.checked = value;
67
+ }
68
+ }
69
+
70
+ class InputHandler extends InputBase {
71
+ #e: HTMLInputElement;
72
+
73
+ constructor(e: HTMLInputElement) {
74
+ super(e);
75
+ this.#e = e;
76
+ }
77
+
78
+ get val(): string {
79
+ return this.#e.value;
80
+ }
81
+
82
+ set val(value: string) {
83
+ this.#e.value = value;
84
+ }
85
+ }
86
+
87
+ class SelectHandler extends InputBase {
88
+ #e: HTMLSelectElement;
89
+ #multi: boolean = false;
90
+
91
+ constructor(e: HTMLSelectElement) {
92
+ super(e);
93
+ this.#e = e;
94
+ this.#multi = e.multiple;
95
+ }
96
+
97
+ get val(): string[] | string {
98
+ const that = this,
99
+ ret: string[] = [];
100
+
101
+ // get all options
102
+ [...that.#e.querySelectorAll('option')]
103
+ .filter((o) => o.selected)
104
+ .forEach((o) => {
105
+ ret.push(o.value);
106
+ });
107
+
108
+ if (this.#multi) return ret;
109
+ return ret.length ? ret[0] : '';
110
+ }
111
+
112
+ set val(value: string[] | string) {
113
+ const that = this;
114
+
115
+ value = typeof value === 'string' ? [value] : value;
116
+
117
+ // set all options
118
+ [...that.#e.querySelectorAll('option')].forEach((o) => {
119
+ if (value.indexOf(o.value) > -1) {
120
+ o.selected = true;
121
+ } else {
122
+ o.selected = false;
123
+ }
124
+ });
125
+ }
126
+ }
127
+
128
+ class TextAreaHandler extends InputBase {
129
+ #e: HTMLTextAreaElement;
130
+ constructor(e: HTMLTextAreaElement) {
131
+ super(e);
132
+ this.#e = e;
133
+ }
134
+
135
+ get val(): string {
136
+ return this.#e.value || '';
137
+ }
138
+
139
+ set val(value: string) {
140
+ this.#e.value = value;
141
+ }
142
+ }
143
+
144
+ const getInputHandlers = (e: HTMLElement | ShadowRoot): LooseObject => {
145
+ let inputList = [
146
+ ...(e || document).querySelectorAll('input,select,textarea'),
147
+ ],
148
+ handlers: LooseObject = {};
149
+
150
+ inputList.forEach((i) => {
151
+ const name: string | null = (i as inputTypes).getAttribute('name');
152
+ if (name) {
153
+ let handler: any = false;
154
+ switch (getInputName(i as inputTypes)) {
155
+ case 'input':
156
+ switch ((i as HTMLInputElement).type) {
157
+ case 'radio':
158
+ handler = new RadioHandler(i as HTMLInputElement);
159
+ break;
160
+ case 'checkbox':
161
+ handler = new CheckboxHandler(i as HTMLInputElement);
162
+ break;
163
+ default:
164
+ handler = new InputHandler(i as HTMLInputElement);
165
+ }
166
+ break;
167
+ case 'select':
168
+ handler = new SelectHandler(i as HTMLSelectElement);
169
+ break;
170
+ case 'textarea':
171
+ handler = new TextAreaHandler(i as HTMLTextAreaElement);
172
+ break;
173
+ default:
174
+ console.warn(
175
+ 'handler missing:',
176
+ name,
177
+ 'for',
178
+ i.tagName.toLowerCase(),
179
+ i
180
+ );
181
+ break;
182
+ }
183
+
184
+ if (handler) {
185
+ DC.add(i, name, handler);
186
+ Object.defineProperty(handlers, name, {
187
+ enumerable: true,
188
+ configurable: true,
189
+ get: (): any => {
190
+ return handler.val;
191
+ },
192
+ set: (value: any) => {
193
+ if (handler.val !== value) {
194
+ handler.val = value;
195
+ }
196
+ },
197
+ });
198
+ }
199
+ }
200
+ });
201
+
202
+ return handlers;
203
+ };
204
+
205
+ export function formValues(
206
+ targetObject: LooseObject,
207
+ propertyName: string,
208
+ dom: HTMLElement | ShadowRoot
209
+ ) {
210
+ let handlers = getInputHandlers(dom);
211
+
212
+ targetObject[propertyName] = Object.assign({}, handlers);
213
+
214
+ observe(targetObject, propertyName);
215
+
216
+ copyGettersSetters(handlers, targetObject[propertyName]);
217
+
218
+ [...dom.querySelectorAll('input, textarea, select')].forEach((input) => {
219
+ addListener(input as inputTypes, 'keyup', (ev: Event) => {
220
+ //console.log('keyup', ev);
221
+ targetObject[propertyName].notify();
222
+ });
223
+ addListener(input as HTMLElement, 'change', (ev: Event) => {
224
+ //console.log('change', ev);
225
+ targetObject[propertyName].notify();
226
+ });
227
+ addListener(input as inputTypes, 'select', (ev: Event) => {
228
+ //console.log('select', ev);
229
+ targetObject[propertyName].notify();
230
+ });
231
+ });
232
+ }
233
+
@@ -0,0 +1,14 @@
1
+ export interface LooseObject {
2
+ [key: string | symbol]: any;
3
+ }
4
+ export declare function isNativeObject(value: any): boolean;
5
+ export declare function sortObject(o: LooseObject): LooseObject;
6
+ export declare function flattenObject(o: LooseObject, doSort?: boolean): LooseObject;
7
+ export declare function deepEqual(o1: LooseObject, o2: LooseObject): boolean;
8
+ export declare function nameSpace(ns: string | string[], obj?: LooseObject): any;
9
+ export declare function parse(what: string | Object | any[], parseThis: Object): any;
10
+ export declare function kebabToPascal(str: string): string;
11
+ export declare function debounce(func: Function, milliseconds: number): Function;
12
+ export declare function htmlToElements(html: string): HTMLElement[];
13
+ export declare function copyGettersSetters(source: LooseObject, target: LooseObject): void;
14
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,WAAW;IAC3B,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;CAC5B;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAElD;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,WAAW,GAAG,WAAW,CAatD;AAED,wBAAgB,aAAa,CAC5B,CAAC,EAAE,WAAW,EACd,MAAM,GAAE,OAAc,GACpB,WAAW,CAmBb;AAED,wBAAgB,SAAS,CAAC,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,WAAW,GAAG,OAAO,CAInE;AAED,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,GAAG,GAAE,WAAgB,GAAG,GAAG,CAW3E;AAED,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,EAAE,EAAE,SAAS,EAAE,MAAM,OAyCrE;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,UAKxC;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,GAAG,QAAQ,CASvE;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,EAAE,CAU1D;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,QAO1E"}
@@ -0,0 +1,149 @@
1
+ 'use strict';
2
+
3
+ export interface LooseObject {
4
+ [key: string | symbol]: any;
5
+ }
6
+
7
+ export function isNativeObject(value: any): boolean {
8
+ return value && value['constructor'] && value.constructor === Object;
9
+ }
10
+
11
+ export function sortObject(o: LooseObject): LooseObject {
12
+ let result: LooseObject = {},
13
+ keys = [...Object.keys(o)].sort();
14
+
15
+ keys.forEach((key) => {
16
+ if (isNativeObject(o[key])) {
17
+ result[key] = sortObject(o[key]);
18
+ } else {
19
+ result[key] = o[key];
20
+ }
21
+ });
22
+
23
+ return result;
24
+ }
25
+
26
+ export function flattenObject(
27
+ o: LooseObject,
28
+ doSort: boolean = true
29
+ ): LooseObject {
30
+ let result: LooseObject = {};
31
+
32
+ [...Object.getOwnPropertyNames(o)].forEach((propName) => {
33
+ if (
34
+ o[propName] &&
35
+ o[propName]['constructor'] &&
36
+ o[propName].constructor === Object
37
+ ) {
38
+ const temp = flattenObject(o[propName], false);
39
+ for (const j in temp) {
40
+ result[propName + '.' + j] = temp[j];
41
+ }
42
+ } else {
43
+ result[propName] = o[propName];
44
+ }
45
+ });
46
+
47
+ return doSort ? sortObject(result) : result;
48
+ }
49
+
50
+ export function deepEqual(o1: LooseObject, o2: LooseObject): boolean {
51
+ return (
52
+ JSON.stringify(flattenObject(o1)) === JSON.stringify(flattenObject(o2))
53
+ );
54
+ }
55
+
56
+ export function nameSpace(ns: string | string[], obj: LooseObject = {}): any {
57
+ let nsa = ns.constructor === String ? ns.split('.') : ns;
58
+
59
+ if (!obj || !nsa[0] || !obj[nsa[0]]) {
60
+ console.warn('ns', nsa[0], 'not in', obj);
61
+ return;
62
+ }
63
+ if (obj[nsa[0]].constructor === Object && nsa.length > 1) {
64
+ return nameSpace((nsa as string[]).splice(1), obj[nsa[0]]);
65
+ }
66
+ return obj[nsa[0]];
67
+ }
68
+
69
+ export function parse(what: string | Object | any[], parseThis: Object) {
70
+ var args = Array.from(arguments);
71
+
72
+ if (args.length > 2) {
73
+ while (args.length > 1) {
74
+ args[0] = parse(args[0], args[1]);
75
+ args.splice(1, 1);
76
+ }
77
+ return args[0];
78
+ }
79
+
80
+ if (typeof what === 'string') {
81
+ what.match(/\{[^\{\}]*\}/g)?.forEach(function (pPropname) {
82
+ var propname = pPropname.substring(1, pPropname.length - 1),
83
+ value = nameSpace(propname, parseThis);
84
+ //console.log(propname, value);
85
+ if (typeof value !== 'undefined') {
86
+ what = (what as string).replace(pPropname, value);
87
+ }
88
+ });
89
+ } else if (isNativeObject(what)) {
90
+ switch (what.constructor) {
91
+ case Object:
92
+ Object.keys(what).forEach(function (pKey) {
93
+ if (what.hasOwnProperty(pKey)) {
94
+ (what as LooseObject)[pKey] = parse(
95
+ (what as LooseObject)[pKey],
96
+ parseThis
97
+ );
98
+ }
99
+ });
100
+ break;
101
+ case Array:
102
+ (what as Array<any>).forEach(function (pValue, pKey, original) {
103
+ original[pKey] = parse((what as any)[pKey], parseThis);
104
+ });
105
+ break;
106
+ }
107
+ }
108
+
109
+ return what;
110
+ }
111
+
112
+ export function kebabToPascal(str: string) {
113
+ return str
114
+ .split('-') // Split by hyphens
115
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1)) // Capitalize each part
116
+ .join(''); // Join without spaces
117
+ }
118
+
119
+ export function debounce(func: Function, milliseconds: number): Function {
120
+ let timeout: any;
121
+ return () => {
122
+ clearTimeout(timeout);
123
+
124
+ timeout = setTimeout(function () {
125
+ func(...arguments);
126
+ }, milliseconds);
127
+ };
128
+ }
129
+
130
+ export function htmlToElements(html: string): HTMLElement[] {
131
+ let template = document.createElement('template');
132
+
133
+ html = html.replace(/<([A-Za-z0-9\-]*)([^>\/]*)(\/>)/gi, '<$1$2></$1>'); // replace XHTML closing tags by full closing tags
134
+
135
+ template.innerHTML = html;
136
+
137
+ template.content.normalize();
138
+
139
+ return Array.from(template.content.childNodes) as HTMLElement[];
140
+ }
141
+
142
+ export function copyGettersSetters(source: LooseObject, target: LooseObject) {
143
+ const descriptors = Object.getOwnPropertyDescriptors(source);
144
+ for (const [key, descriptor] of Object.entries(descriptors)) {
145
+ if ('get' in descriptor || 'set' in descriptor) {
146
+ Object.defineProperty(target, key, descriptor);
147
+ }
148
+ }
149
+ }
@@ -0,0 +1,7 @@
1
+ export * from './helpers.js';
2
+ export * from './MC.js';
3
+ export * from './McEvent.js';
4
+ export * from './elements.js';
5
+ export * from './observables.js';
6
+ export * from './formValues.js';
7
+ //# sourceMappingURL=microcomponents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"microcomponents.d.ts","sourceRoot":"","sources":["../src/microcomponents.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AAEjC,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,2 @@
1
+ declare function findNodesWithMcAttribute(rootNode: any, childrenOnly: any): any[];
2
+ //# sourceMappingURL=microcomponents.es3.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"microcomponents.es3.d.ts","sourceRoot":"","sources":["../src/microcomponents.es3.js"],"names":[],"mappings":"AAgWA,mFAwBC"}
@@ -4,6 +4,5 @@ export * from './MC.js';
4
4
  export * from './McEvent.js';
5
5
  export * from './elements.js';
6
6
  export * from './observables.js';
7
- export * from './selectors.js';
8
7
  export * from './formValues.js';
9
8
  //# sourceMappingURL=microcomponents.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"microcomponents.js","sourceRoot":"","sources":["../src/microcomponents.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC"}
1
+ {"version":3,"file":"microcomponents.js","sourceRoot":"","sources":["../src/microcomponents.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AAEjC,cAAc,iBAAiB,CAAC"}
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.microcomponents=t():e.microcomponents=t()}(this,(()=>(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function r(e){return e&&e.constructor&&e.constructor===Object}function n(e){let t={};return[...Object.keys(e)].sort().forEach((a=>{r(e[a])?t[a]=n(e[a]):t[a]=e[a]})),t}function a(e,t=!0){let r={};return[...Object.getOwnPropertyNames(e)].forEach((t=>{if(e[t]&&e[t].constructor&&e[t].constructor===Object){const n=a(e[t],!1);for(const e in n)r[t+"."+e]=n[e]}else r[t]=e[t]})),t?n(r):r}function s(e,t){return JSON.stringify(a(e))===JSON.stringify(a(t))}function o(e,t={}){let r=e.constructor===String?e.split("."):e;if(t&&r[0]&&t[r[0]])return t[r[0]].constructor===Object&&r.length>1?o(r.splice(1),t[r[0]]):t[r[0]];console.warn("ns",r[0],"not in",t)}function c(e,t){var n=Array.from(arguments);if(n.length>2){for(;n.length>1;)n[0]=c(n[0],n[1]),n.splice(1,1);return n[0]}if("string"==typeof e)e.match(/\{[^\{\}]*\}/g)?.forEach((function(r){var n=o(r.substring(1,r.length-1),t);void 0!==n&&(e=e.replace(r,n))}));else if(r(e))switch(e.constructor){case Object:Object.keys(e).forEach((function(r){e.hasOwnProperty(r)&&(e[r]=c(e[r],t))}));break;case Array:e.forEach((function(r,n,a){a[n]=c(e[n],t)}))}return e}function i(e){return e.split("-").map((e=>e.charAt(0).toUpperCase()+e.slice(1))).join("")}function l(e,t){let r;return()=>{clearTimeout(r),r=setTimeout((function(){e(...arguments)}),t)}}function u(e){let t=document.createElement("template");return e=e.replace(/<([A-Za-z0-9\-]*)([^>\/]*)(\/>)/gi,"<$1$2></$1>"),t.innerHTML=e,t.content.normalize(),Array.from(t.content.childNodes)}function f(e,t){const r=Object.getOwnPropertyDescriptors(e);for(const[e,n]of Object.entries(r))("get"in n||"set"in n)&&Object.defineProperty(t,e,n)}e.r(t),e.d(t,{$d:()=>Q,$t:()=>X,DC:()=>k,MC:()=>x,McBase:()=>_,McEvent:()=>p,addListener:()=>v,autoload:()=>H,copyGettersSetters:()=>f,debounce:()=>l,deepEqual:()=>s,defineCE:()=>q,flattenObject:()=>a,formValues:()=>ce,getCE:()=>D,htmlToElements:()=>u,isNativeObject:()=>r,kebabToPascal:()=>i,nameSpace:()=>o,observe:()=>J,parse:()=>c,removeListener:()=>w,sortObject:()=>n});var h=new Function("try {return this===window;}catch(e){ return false;}");let d=new Set;h()&&Object.keys(HTMLElement.prototype).filter((e=>/^on/.test(e))).forEach((e=>d.add(e)));class p{#e;#t=!1;#r=!1;constructor(e,t={},r="l"){this.#e=e,this.data=t,this.bubble=r}get type(){return this.#e}get stopped(){return this.#t}get immediateStopped(){return this.#r}stopPropagation(){this.#t=!0}stopImmediatePropagation(){this.stopPropagation(),this.#r=!0}}var m=new Function("try {return this===window;}catch(e){ return false;}");let b=new Set;function g(e,t){let r=[];return e.forEach((e=>{if(e&&e instanceof HTMLElement){const n=e?._mc;!t&&n?r=r.concat(Object.values(e._mc)):t&&n&&n[t]&&r.push(n[t])}})),r}function y(e,t,r=!0){let n=[];for(;e;){if(e._mc&&(t?t&&e._mc[t]&&n.push(e._mc[t]):n=n.concat(Object.values(e._mc)),r))return n;e=e.parentNode}return n}function E(e){return e&&e instanceof HTMLElement}function v(e,t,r,n=!1,a=!1){let s={once:!1};n&&(s.capture=n),a&&(s.once=a),e.addEventListener(t,r,s)}function w(e,t,r){e.removeEventListener(t,r)}function O(e,t,r={}){let n=e;if(!n._mc){let t=k?.debug;k.debug=!1,n._mc=new k(e),k.debug=t,delete n._mc._mc}const a=n._mc;return t.length&&!a[t]&&(a[t]=r,e instanceof HTMLElement&&!e.getAttribute("_mc")&&e.setAttribute("_mc","")),r}function A(e,t){if(!t)return;const r=e?._mc||{};r&&r[t]&&delete r[t],!Object.keys(r).length&&e instanceof HTMLElement&&e.hasAttribute("_mc")&&e.removeAttribute("_mc")}function S(e,t,r={},n="l"){let a=e?._mc;if(!a)return;let s=t instanceof p?new p(t.type,t.data,"l"):new p(t,r,"l"),o="string"!=typeof t?t:new p(t,r,n);[...Object.values(a)].forEach((e=>{e?.trigger&&"function"==typeof e?.trigger&&e?.trigger(s)})),/[ud]/.test(o.bubble)&&j(e,o)}function j(e,t){/[ud]/.test(t.bubble)&&setTimeout((()=>{if(-1===t.bubble.indexOf("l")&&(t.bubble+="l"),t.bubble.indexOf("u")>-1){let r=y(e,"",!0)?.[0].target;r&&k.trigger(r,t)}t.bubble.indexOf("d")>-1&&new Set(e._mc.children().map((e=>e?.target))).forEach((e=>{e&&k.trigger(e,t)}))}),0)}m()&&Object.keys(HTMLElement.prototype).filter((e=>/^on/.test(e))).forEach((e=>b.add(e)));class _{#n;constructor(e,t=!1){var r;this.#n=new WeakRef(e||{}),(r=this).constructor!==k&&setTimeout((()=>{r.trigger("Init")}),0),function(e){if(!m()||e.constructor===k)return;const t=e.target;if(t instanceof HTMLElement){let r=e;Object.getOwnPropertyNames(r.constructor.prototype).filter((e=>/^on[A-Z]|one[A-Z]/.test(e)&&"function"==typeof r.constructor.prototype[e])).forEach((n=>{let a=/^one/.test(n),s=n.replace(/^on[e]{0,1}/,""),o=s.toLowerCase();a&&Object.defineProperty(e,"on"+s,{configurable:!0,enumerable:!1,writable:!0,value:e=>{r.constructor.prototype[n].bind(r)(e)}}),b.has("on"+o)&&v(t,o,(e=>{r.trigger(s,e)}),!1,a)}))}}(this)}get target(){return this.#n.deref()}}class x extends _{_mc={};constructor(e){super(e)}static trigger=S;trigger(e,t={},r="l"){let n=this;if(n.constructor===x||n.constructor===k){let a=e instanceof p?new p(e.type,e.data,"l"):new p(e,t,"l"),s="string"!=typeof e?e:new p(e,t,r);return[...Object.getOwnPropertyNames(n)].forEach((e=>{n[e]?.trigger&&"function"==typeof n[e]?.trigger&&n[e]?.trigger(a)})),void(/[ud]/.test(s.bubble)&&j(n.target,s))}if(n instanceof x||n instanceof k){const n=this,a="string"!=typeof e?e:new p(e,t,r),s="on"+a.type[0].toUpperCase()+a.type.slice(1);if(a.bubble.indexOf("l")>-1&&(a.immediateStopped||"function"!=typeof n[s]||(n[s](a),n.hasOwnProperty(s)&&delete n[s])),a.stopped||"l"===a.bubble)return n;/[ud]/.test(a.bubble)&&j(n.target,a)}}}class k extends _{_mc={};constructor(e,t=!1){super(e)}static add=O;static remove=A;static trigger=S;trigger(e,t={},r){x.prototype.trigger.call(this,e,t,r)}parent(e=""){let t=this.target;return E(t)?y(t.parentNode,e,!0):[]}ancestors(e=""){let t=this?.target;return E(t)?y(this.target.parentNode,e,!1):[]}children(e=""){let t=this?.target;if(!E(t))return[];const r=Math.random().toString().replace(".",""),n='[_mc]:not([temp_id="'+r+'"] [_mc] [_mc])';t.setAttribute("temp_id",r);const a=g([...t.querySelectorAll(n)],e);return t.removeAttribute("temp_id"),a}descendants(e=""){let t=this?.target;return E(t)?g([...t.querySelectorAll("*[_mc]")],e):[]}}const T=new Map,C=new Map;function N(e){const t="./"+e.split("-").join("/")+".js",r=document.createElement("script");return r.setAttribute("src",t),r.setAttribute("blocking","render"),r.async=!0,r.setAttribute("type","module"),r.setAttribute("name",e),r.setAttribute("loading",""),v(r,"load",(e=>{r.removeAttribute("loading"),r.setAttribute("loaded","")})),v(r,"error",(e=>{console.error("could not load Custom Element code from",t)})),r}function L(){[...document.querySelectorAll(":not(:defined)")].filter((e=>!!e&&!customElements.get(e.tagName.toLowerCase())&&!T.has(e.tagName.toLowerCase()))).forEach((e=>{const t=e.tagName.toLowerCase(),r=(t.split("-").join("/"),N(t));v(r,"load",(()=>{T.set(t,customElements.get(e.tagName.toLowerCase()))})),T.set(t,"loading"),document.head.append(r)})),[...document.querySelectorAll('[_mc]:not([_mc=""]')].filter((e=>!!e)).forEach((e=>{const t=e.getAttribute("_mc")?.split(" ").filter((e=>!!e))||[],r=t.filter((e=>!C.has(e)));r?.forEach((e=>{const t=N(e);v(t,"load",(()=>{return t=document.head.querySelector(`script[name="${e}"]`),void setTimeout((function(){const e=t.getAttribute("src"),r=t.getAttribute("name"),n=document.createElement("script");n.async=!0,n.setAttribute("type","module");const a=`\n\n\t\t\timport _ from "${e}";\n\t\t\timport {DC} from "./microcomponents.js";\n\n\t\t\tconst elements = Array.from(document.querySelectorAll('[_mc*="${r}"]')).filter( element => element instanceof HTMLElement );\n\n\t\t\telements.forEach((element) => {\n\t\t\t\t// add class to MCs repository\n\t\t\t\tautoload.state.MCs.set( '${r}', _ );\n\t\t\t\t// add instance to HTMLElement \n\t\t\t\tDC.add(element, _.name, new _(element));\n\t\t\t\t// remove instance name from elements "_mc" attribute\n\t\t\t\telement.setAttribute('_mc', element.getAttribute('_mc').replace('${r}', '').replace( /ww/g, ' ').trim()); \n\t\t\t});\n\n\t\t\tsetTimeout( () => {\n\t\t\t\tdocument.body.querySelector('script[name="${r}]"')?.remove();\n\t\t\t},0);\n\n\t\t`;n.innerHTML=a,document.body.append(n)}),0);var t})),C.set(e,"loading"),document.head.append(t)}));const n=t.filter((e=>C.has(e)&&!C.get(e).length));n?.forEach((t=>{setTimeout((()=>{k.add(e,t,new(H.state.MCs.get(t))(e)),e.getAttribute("_mc").replace("${elementName}","").replace(/\w\w/g," ").trim(),e.setAttribute("_mc")}),5)}))}))}let M=!1,$=null;function H(e=!0){return e?(M=e,$=new MutationObserver(L),setTimeout((()=>{$.observe(document.body,{childList:!0,subtree:!0}),L()}),5),M):($?.disconnect(),$=null,M)}H.state={CEs:T,MCs:C};class P extends HTMLElement{constructor(){super()}connectedCallback(){k.trigger(this,"Connected")}disconnectedCallback(){k.trigger(this,"Disconnected")}adoptedCallback(){k.trigger(this,"Adopted")}attributeChangedCallback(e,t,r){k.trigger(this,"AttributeChanged",{name:e,oldValue:t,newValue:r})}}function q(e,t,r=[]){if(customElements.get(e))return void console.warn(`IGNORED: Custom element "${e}" is already defined!`);if(!e.includes("-"))throw new Error('createCustomElement: tagName must contain at least one hyphen ("-").');let n=i(e);customElements.define(e,function(e,t){return Object.defineProperty(t,"name",{value:e})}(n,class extends P{instance;constructor(e){super();let r=new t(this,e);k.add(this,n,r)}static get observedAttributes(){return r}}))}function D(e){return customElements.get(e)}function I(e){return null!=e&&"object"==typeof e}function B(e){let t=new Set,r=/\{[^\{\}]*\}/g;return e.getAttributeNames().filter((t=>e.getAttribute(t)?.match(r))).forEach((n=>{new Set(e.getAttribute(n)?.match(r)).forEach((e=>t.add(e.replace(/[\{\}]/g,""))))})),[...e.childNodes].filter((e=>3===e.nodeType&&(e.nodeValue||"").match(r))).forEach((e=>{(e.nodeValue||"").match(r).forEach((e=>{t.add(e.replace(/[\{\}]/g,""))}))})),[...t].map((e=>e.replace(/[\{\}]/g,"")))}const V=[HTMLInputElement,HTMLSelectElement,HTMLTextAreaElement];class z extends k{data={};oldDisplay="";constructor(e){super(e);let t=this;B(e).forEach((e=>t.data[e]="")),J(t),t.#a(),delete t._mc}#a(){let e=this,t=e.target,r=!1;t.getAttributeNames().filter((e=>t.getAttribute(e)?.match(/\{[^\{\}]*\}/g))).forEach((r=>{let n=new Set(t.getAttribute(r)?.match(/\{[^\{\}]*\}/g));var a;e.data.observe((a=t.getAttribute(r),e=>{let s=a;n.forEach((t=>{s=s.replace(t,e[t.replace(/[\{\}]/g,"")])})),t.setAttribute(r,s)}))})),[...t.childNodes].filter((e=>3===e.nodeType&&(e.nodeValue||"").match(/\{[^\{\}]*\}/g))).forEach((n=>{r=!0;let a=new Set(n.nodeValue.match(/\{[^\{\}]*\}/g));var s;e.data.observe((s=n.nodeValue,r=>{let o=s;a.forEach((e=>{o=o.replace(e,r[e.replace(/[\{\}]/g,"")])})),Object.keys(r).some((e=>!!r[e]))&&(e.oldDisplay?t.style=e.oldDisplay:t.removeAttribute("style"),delete e.oldDisplay),n.nodeValue=o})),e.oldDisplay=t.getAttribute("style)")||"",r&&!V.includes(t.constructor)&&"FIELDSET"!==t.tagName&&(t.style.display="none")}))}onData(e){let t=this,r={};Object.keys(e.data).forEach((n=>{t.data.hasOwnProperty(n)&&(r[n]=e.data[n])})),JSON.stringify(r)!==JSON.stringify(t.data)&&Object.assign(t.data,r)}}const J=(e,t)=>((t?[t]:[...Object.getOwnPropertyNames(e)]).forEach((t=>{if("_"===t[0]||void 0===e?.[t])return e;let r,n=e[t];if(!n.prototype)switch(typeof n){case"string":r=String;break;case"number":r=Number;break;case"boolean":r=Boolean;break;case"object":r=n instanceof Array?Array:Object;break;default:return}let o=class extends r{#s=!0;constructor(e){super(e),this.constructor.callbacks=[],I(e)&&Object.getOwnPropertyNames(e).forEach((t=>{this[t]=e[t]}))}observe(e){return this.constructor.callbacks.push(e),this}bind(e){const t=this;if(I(t.valueOf())){!function(e){var t;(t=e,(t instanceof HTMLElement?[t]:[]).concat([...t.querySelectorAll("*")]).filter((e=>!!B(e).length)).filter((e=>"STYLE"!==e.tagName))).forEach((e=>{e?._mc?._placeholders||k.add(e,"_placeholders",new z(e))}))}(e);const r=[...e.querySelectorAll("[_mc]")].filter((e=>!!e?._mc?._placeholders)),n=function(e){let t=a(e);r.forEach((e=>{e&&e._mc.trigger("data",t)}))};t.constructor.callbacks.push(n),t.notify()}else console.warn("IGNORED - cannot bind a non-Object to the dom, IS:",typeof t.valueOf(),t);return this}notify(e){let t=this,r=I(t.valueOf())&&t.valueOf()instanceof Array==0?structuredClone(Object.assign({},t)):t.valueOf();return void 0!==e&&(t.#s=e),t.constructor.callbacks.forEach((e=>{e(r)})),t}},c=new o(n);Object.defineProperty(e,t,{enumerable:!0,get(){if(I(c.valueOf())){let e=structuredClone(Object.assign({},c));setTimeout(l((function(){s(structuredClone(Object.assign({},c)),e)||c.notify()}),0),0)}return c},set(e){if(typeof e==typeof c.valueOf())if(I(c.valueOf())&&c.valueOf()instanceof Array==0){let t=structuredClone(Object.assign({},c));c instanceof o==0&&(c=new o(structuredClone(Object.assign({},e))),f(e,c),c.seal()),Object.assign(c,e),setTimeout(l((function(){s(structuredClone(Object.assign({},c)),t)||c.notify()}),0),0)}else{let t=c.valueOf(),r=c.constructor.callbacks;c=new o(e),c.constructor.callbacks=r,e!==t&&c.notify()}else console.warn("IGNORED - cannot change observable types, IS:",typeof c.valueOf(),c,"- CANNOT BECOME:",typeof e)}}),e[t]=n})),e),F=e=>{let t=new Set;return e.forEach((e=>{(e=e.trim()).split(" ").forEach((e=>{""!==e&&t.add(e)}))})),Array.from(t)},G=e=>{let t=Q("input,select,textarea",e).array,r={};return t.forEach((t=>{const n=t.getAttribute("name")||"undefined";if(n){let a;switch((e=>e instanceof HTMLInputElement?"input":e instanceof HTMLSelectElement?"select":e instanceof HTMLTextAreaElement?"textarea":"")(t)){case"input":a=new W(t,e),Object.defineProperty(r,n,{enumerable:!0,configurable:!0,get:()=>a.val,set:e=>{a.val=e}});break;case"select":a=new Z(t),Object.defineProperty(r,n,{enumerable:!0,configurable:!0,get:()=>a.val,set:e=>{a.val=e}});break;case"textarea":a=new U(t),Object.defineProperty(r,n,{enumerable:!0,configurable:!0,get:()=>a.val,set:e=>{a.val=e}});break;default:console.warn("handler missing:",n,"for",t)}}})),r};class R{constructor(e){}}class W extends R{#o;#e;#c;constructor(e,t){super(e),this.#o=e,this.#e=e.type,this.#c=t}get val(){let e,t=this;switch(t.#e){case"radio":const r=Q(`input[type="radio"][name="${this.#o.getAttribute("name")}"]`,this.#c).filter((e=>e.checked));return r.length?(e=r.array[0],e.value):"";case"checkbox":return t.#o.checked;default:return t.#o.value}return""}set val(e){let t=this;switch(t.#e){case"radio":const r=`input[type="radio"][name="${this.#o.getAttribute("name")}"]`,n=Q(r,this.#c);if(!n.length)return;if(""===e)return void n.forEach((e=>{e.checked&&(e.checked=!1)}));const a=n.filter((t=>t.getAttribute("value")===e));if(!a.length)return;return void(a.array[0].checked=!0);case"checkbox":t.#o.checked=e;break;default:t.#o.value=e}}}class Z extends R{#o;#i=!1;constructor(e){super(e),this.#o=e,this.#i="select-multiple"===e.type}get val(){const e=[];return Q(this.#o.querySelectorAll("option")).filter((e=>e.selected)).forEach((t=>{t.selected&&e.push(t.value)})),this.#i?e:e.length?e[0]:""}set val(e){e="string"==typeof e?[e]:e,Q(this.#o.querySelectorAll("option")).forEach((t=>{e.indexOf(t.value)>-1?(t.setAttribute("selected",!0),t.selected=!0):(t.removeAttribute("selected"),t.selected=!1)}))}}class U extends R{#o;constructor(e){super(e),this.#o=e}get val(){return this.#o.value}set val(e){this.#o.value=e}}class Y{#l=new Set;get set(){return this.#l}get array(){return Array.from(this.#l)}set set(e){this.#l=e}get length(){return this.#l.size}constructor(e,t=document.body){if(new Set,!e)return this}$t(e){let t=new K;return this.#l.forEach((e=>{e._mc&&Object.values(e._mc).forEach((e=>{t.set.add(e)}))})),e&&t.filter((t=>t.nameSpace===e)),t}add(e,t){let r=this;return Q(e,t).forEach((e=>{r.#l.add(e)})),r}addClass(...e){return e=F(e),this.forEach((t=>{t.classList.add(...e)})),this}after(e,t){let r=this,n=Q(e,t);return n.length?(n.first().forEach((e=>{r.array.reverse().forEach((t=>{t.after(e)}))})),r):r}append(e,t){let r=this.array[0],n=Q(e,t);return r&&n.forEach((e=>{r.append(e)})),this}appendTo(e,t){let r=Q(e,t).array[0];return r&&this.forEach((e=>{r.append(e)})),this}attr(e,t){let r=this,n={};return r.length?arguments.length?"string"==typeof e?void 0===t?[...r.set][0].getAttribute(e):null===t?([...r.set].forEach((t=>{t.removeAttribute(e)})),r):("object"==typeof t&&(t=JSON.stringify(t)),[...r.set].forEach((r=>{r.setAttribute(e,t)})),r):"object"==typeof e?([...r.set].forEach((t=>{Object.keys(e).forEach((r=>{Q(t).attr(r,e.key)}))})),r):r:(Array.from([...r.set][0].attributes).forEach((e=>{n[e.name]=e.value})),n):r}before(e,t){let r=this,n=Q(e,t);return n.length?(n.first().forEach((e=>{r.forEach((t=>{t.before(e)}))})),r):r}children(e,t){let r=this,n=new Set;if(r.#l.forEach((e=>{Array.from(e.children).forEach((e=>{n.add(e)}))})),r=Q([...n]),e){let n=Q(e,t);r.filter((e=>n.has(e)))}return r}descendants(e,t){let r=this,n=new Set;if(r.#l.forEach((e=>{e.querySelectorAll("*").forEach((e=>{n.add(e)}))})),r=Q([...n]),e){let n=Q(e,t);r.filter((e=>n.has(e)))}return r}empty(){return this.filter((e=>!1))}first(e,t){let r=this,n=new Set,a=!1;return e&&(a=Q(e,t)),r.#l.forEach((e=>{e.parentNode&&n.add(e.parentNode.children[0])})),r=Q([...n]),e&&r.filter((e=>a.has(e))),r}has(e){return this.#l.has(e)}hasClass(...e){return e=F(e),this.every((e=>Array.from(e.classList).every((t=>e.contains(t)))))}html(e){let t=this;return e?(t.forEach((t=>{t.parentNode?t.innerHTML=e:(()=>{console.warn("Cannot access the .innerHTML of a HTMLElement that hasnt been inserted yet",t),console.trace(t,this),console.info("If you called this from inside a Web Component constructor, consider using the %c[connected] event callback!","color: blue;")})()})),t):t.array[0].innerHTML}last(e,t){let r=this,n=new Set;if(r.#l.forEach((e=>{let t=e.parentNode?.children;t&&n.add(Array.from(t).at(-1))})),r=Q([...n]),e){let n=Q(e,t);r.filter((e=>n.has(e)))}return r}next(e,t){let r=this,n=new Set;if(r.#l.forEach((e=>{let t=e.parentNode?.children;if(t){let r=Array.from(t),a=r.indexOf(e)+1;a<r.length&&n.add(r.at(a))}})),r=Q([...n]),e){let n=Q(e,t);r.filter((e=>n.has(e)))}return r}normalize(){return this.#l.forEach((e=>{e.normalize()})),this}off(e,t){let r=e.indexOf(" ")>-1?e.split(" "):[e];return this.array.forEach((e=>{r.forEach((function(r){w(e,r,t)}))})),this}on(e,t,r=!1,n=!1){let a=this,s=e.indexOf(" ")>-1?e.split(" ").filter((e=>""!==e)):[e];function o(){o.cb.apply(a,Array.from(arguments))}return o.cb=t,a.forEach((e=>{s.forEach((function(t){v(e,t,o,r,n)}))})),o}one(e,t,r=!1){let n=this,a=e.indexOf(" ")>-1?e.split(" ").filter((e=>""!==e)):[e];function s(){s.cb.apply(n,Array.from(arguments))}return s.cb=t,n.forEach((e=>{a.forEach((function(t){v(e,t,s,r,!0)}))})),s}parent(e,t){let r=this,n=new Set;if(r.#l.forEach((e=>{e.parentNode&&"HTML"!==e.parentNode.tagName&&n.add(e.parentNode)})),r=Q([...n]),e){let n=Q(e,t);r.filter((e=>n.has(e)))}return r}parents(e,t){let r=this,n=new Set;if(r.#l.forEach((e=>{let t=e;for(;t.parentNode&&"HTML"!==t.parentNode.tagName;)t=t.parentNode,n.add(t)})),r=Q([...n]),e){let n=Q(e,t);r.filter((e=>n.has(e)))}return r}prepend(e,t){let r=this.array[0],n=Q(e,t);return r&&n.forEach((e=>{r.prepend(e)})),this}prev(e,t){let r=this,n=new Set;if(r.#l.forEach((e=>{let t=e.parentNode?.children;if(t){let r=Array.from(t),a=r.indexOf(e)-1;a>-1&&n.add(r.at(a))}})),r=Q([...n]),e){let n=Q(e,t);r.filter((e=>n.has(e)))}return r}removeClass(...e){return e=F(e),this.forEach((t=>{t.classList.remove(...e)})),this}text(e){let t=this;return e?(t.forEach((t=>{t.parentNode?t.innerText=e:(()=>{console.warn("Cannot access the .textContent of a HTMLElement that hasnt been inserted yet",t),console.trace(t,this),console.info("If you called this from inside a Web Component constructor, consider using the %c[connected] event callback!","color: blue;")})()})),t):t.array[0].innerText??""}toggleClass(...e){return e=F(e),this.forEach((t=>{t.classList.toggle(...e)})),this}trigger(e,t={},r=!1,n=!1,a=!1){let s,o={bubbles:r,cancelable:n,composed:a},c=e.indexOf(" ")>-1?e.split(" "):[e];return this.#l.forEach((e=>{c.forEach((function(r){s=new Event(r,o),s.data=t,e.dispatchEvent(s)}))})),this}val(e,t){if(!this.length)return this;const r=this;let n,a=G(r.array[0]);var s;return e?null!=(s=e)&&"object"==typeof s?(Object.assign(a,e),n=r):"string"==typeof e&&(void 0===t?n=a[e]:(a[e]=t,n=r)):n=Object.assign({},a),n}values(e){const t=this;let r={};if(!t.length)return console.warn("no dom selection to search inputs in"),{};let n=G(t.array[0]);return Object.keys(n).forEach((e=>{r[e]=n[e]})),0===Object.keys(r).length&&console.warn("no inputs in this dom selection",t.array[0],r),e&&Object.keys(e).forEach((t=>{n.hasOwnProperty(t)&&(console.log("key found",t),n[t]=e[t])})),structuredClone(Object.assign(n))}at(e){return Q(this.array.at(e))}concat(e){let t=this;return(e instanceof Y?e.array:e).forEach((e=>{t.#l.add(e)})),t}entries(){return this.array.entries()}every(e,t){return this.array.every(e,t)}filter(e,t){return this.#l=new Set(this.array.filter(e,t)),this}forEach(e,t){return this.array.forEach(e,t),this}includes(e){return-1!==this.array.indexOf(e,0)}indexOf(e,t){return this.array.indexOf(e,t)}map(e,t){return this.array.map(e,t)}pop(){return this.array.pop()}push(...e){return e.forEach((e=>{this.#l.add(e)})),this}shift(){let e=this,t=e.#l.size?e.array[0]:void 0;return t&&e.#l.delete(t),t}slice(e,t){return Q(this.array.slice(e,t))}some(e,t){return this.array.some(e,t)}splice(e,t,...r){let n=this.array;return n.splice(e,t,...r),Q(n)}}class K{#l=new Set;get set(){return this.#l}get array(){return Array.from(this.#l)}set set(e){this.#l=e}get length(){return this.#l.size}set length(e){}constructor(e,t=document.body){if(!e)return this;Q(e,t).forEach((e=>{X(e).forEach((e=>{this.#l.add(e)}))}))}$d(e,t=document.body){let r=new Y,n=new Set,a=!!e||!1,s=new Set;return a&&(s=Q(e,t).set),this.#l.forEach((e=>{a&&!s.has(e._tg)||n.add(e._tg)})),r.set=n,r}children(e){let t=this,r=new Set;return t.#l.forEach((t=>{t.children(e).forEach((e=>{r.add(e)}))})),t.#l=r,t}descendants(e){let t=this,r=new Set;return t.#l.forEach((t=>{t.descendants(e).forEach((e=>{r.add(e)}))})),t.#l=r,t}first(e){let t=this,r=new Set;return t.#l.forEach((e=>{e.parent().children().$d().first().$t().forEach((e=>{r.add(e)}))})),t.#l=r,e&&t.filter((t=>t.nameSpace=e)),t}has(e){return this.#l.has(e)}last(e){let t=this,r=new Set;return t.#l.forEach((e=>{e.parent().children().$d().last().$t().forEach((e=>{r.add(e)}))})),t.#l=r,e&&t.filter((t=>t.nameSpace=e)),t}next(e){let t=this,r=new Set;return t.#l.forEach((e=>{let t,n=new Set;for(t=e._tg;null!==t.nextElementSibling;)t=t.nextElementSibling,n.add(t);X([...n]).$d().first().$t().forEach((e=>{r.add(e)}))})),t.#l=r,e&&t.filter((t=>t.nameSpace=e)),t}ns(e){return this.filter((t=>t.nameSpace===e))}off(e,t){let r=e.indexOf(" ")>-1?e.split(" ").filter((e=>""!==e)):[e];return this.$d().array.forEach((e=>{r.forEach((function(r){w(e,`[TB]${r}`,t)}))})),this}on(e,t,r=!1){let n=this,a=e.indexOf(" ")>-1?e.split(" ").filter((e=>""!==e)):[e];function s(){s.cb.apply(n,Array.from(arguments))}return s.cb=t,n.forEach((e=>{a.forEach((function(t){v(e._tg,`[TB]${t}`,s,!1,r)}))})),s}one(e,t){let r=this,n=e.indexOf(" ")>-1?e.split(" ").filter((e=>""!==e)):[e];function a(){a.cb.apply(r,Array.from(arguments))}return a.cb=t,r.forEach((e=>{n.forEach((function(t){v(e._tg,`[TB]${t}`,a,!1,!0)}))})),a}parent(e){let t=this,r=new Set;return t.#l.forEach((t=>{t.parent(e).forEach((e=>{r.add(e)}))})),t.#l=r,t}parents(e){let t=this,r=new Set;return t.#l.forEach((t=>{t.parents(e).forEach((e=>{r.add(e)}))})),t.#l=r,t}prev(e){let t=this,r=new Set;return t.#l.forEach((e=>{let t,n=new Set;for(t=e._tg;null!==t.previousElementSibling;)t=t.previousElementSibling,n.add(t);X([...n]).$d().last().$t().forEach((e=>{r.add(e)}))})),t.#l=r,e&&t.filter((t=>t.nameSpace=e)),t}trigger(e,t={},r="l"){return this.forEach((n=>{n.trigger(e,t,r)})),this}at(e){return X(this.array.at(e))}concat(e){let t=this;return e.forEach((e=>{t.#l.add(e)})),t}entries(){return this.array.entries()}every(e,t){return this.array.every(e,t)}filter(e,t){return X(this.array.filter(e,t))}forEach(e,t){return this.array.forEach(e,t),this}includes(e){return-1!==this.array.indexOf(e)}indexOf(e,t){return this.array.indexOf(e,t)}map(e,t){return this.array.map(e,t)}pop(){let e=this.array,t=e.pop();return this.#l=new Set(e),t}push(e){return this.#l.add(e),this}shift(){let e=this.array.shift();return this.#l.delete(e),e}slice(e,t){return X(this.array.slice(e,t))}some(e,t){return this.array.some(e,t)}splice(e,t,...r){let n=this.array.splice(e,t,...r);return X(n)}}const Q=(e,t=document)=>{let r=new Set;return e instanceof Array?(e.forEach((e=>{Q(e,t).forEach((e=>{r.add(e)}))})),new Y([...r])):new Y(e,t)},X=(e,t=document)=>Q(e,t).$t();class ee{constructor(e){}}class te extends ee{#o;constructor(e){super(e),this.#o=e}get val(){return new FormData(this.#o.form).get(this.#o.name)}set val(e){[...this.#o.form.querySelectorAll(`input[type="radio"][name="${this.#o.name}"]`)].filter((t=>t.getAttribute("value")===e)).shift().checked=!0}}class re extends ee{#o;constructor(e){super(e),this.#o=e}get val(){return this.#o.checked}set val(e){this.#o.checked=e}}class ne extends ee{#o;constructor(e){super(e),this.#o=e}get val(){return this.#o.value}set val(e){this.#o.value=e}}class ae extends ee{#o;#i=!1;constructor(e){super(e),this.#o=e,this.#i=e.multiple}get val(){const e=[];return[...this.#o.querySelectorAll("option")].filter((e=>e.selected)).forEach((t=>{e.push(t.value)})),this.#i?e:e.length?e[0]:""}set val(e){e="string"==typeof e?[e]:e,[...this.#o.querySelectorAll("option")].forEach((t=>{e.indexOf(t.value)>-1?t.selected=!0:t.selected=!1}))}}class se extends ee{#o;constructor(e){super(e),this.#o=e}get val(){return this.#o.value||""}set val(e){this.#o.value=e}}const oe=e=>{let t=[...(e||document).querySelectorAll("input,select,textarea")],r={};return t.forEach((e=>{const t=e.getAttribute("name");if(t){let n=!1;switch((e=>e.tagName.toLowerCase())(e)){case"input":switch(e.type){case"radio":n=new te(e);break;case"checkbox":n=new re(e);break;default:n=new ne(e)}break;case"select":n=new ae(e);break;case"textarea":n=new se(e);break;default:console.warn("handler missing:",t,"for",e.tagName.toLowerCase(),e)}n&&(k.add(e,t,n),Object.defineProperty(r,t,{enumerable:!0,configurable:!0,get:()=>n.val,set:e=>{n.val!==e&&(n.val=e)}}))}})),r};function ce(e,t,r){let n=oe(r);e[t]=Object.assign({},n),J(e,t),f(n,e[t]),[...r.querySelectorAll("input, textarea, select")].forEach((r=>{v(r,"keyup",(r=>{e[t].notify()})),v(r,"change",(r=>{e[t].notify()})),v(r,"select",(r=>{e[t].notify()}))}))}return t})()));
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.microcomponents=t():e.microcomponents=t()}(this,(()=>(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function r(e){return e&&e.constructor&&e.constructor===Object}function n(e){let t={};return[...Object.keys(e)].sort().forEach((o=>{r(e[o])?t[o]=n(e[o]):t[o]=e[o]})),t}function o(e,t=!0){let r={};return[...Object.getOwnPropertyNames(e)].forEach((t=>{if(e[t]&&e[t].constructor&&e[t].constructor===Object){const n=o(e[t],!1);for(const e in n)r[t+"."+e]=n[e]}else r[t]=e[t]})),t?n(r):r}function c(e,t){return JSON.stringify(o(e))===JSON.stringify(o(t))}function s(e,t={}){let r=e.constructor===String?e.split("."):e;if(t&&r[0]&&t[r[0]])return t[r[0]].constructor===Object&&r.length>1?s(r.splice(1),t[r[0]]):t[r[0]];console.warn("ns",r[0],"not in",t)}function a(e,t){var n=Array.from(arguments);if(n.length>2){for(;n.length>1;)n[0]=a(n[0],n[1]),n.splice(1,1);return n[0]}if("string"==typeof e)e.match(/\{[^\{\}]*\}/g)?.forEach((function(r){var n=s(r.substring(1,r.length-1),t);void 0!==n&&(e=e.replace(r,n))}));else if(r(e))switch(e.constructor){case Object:Object.keys(e).forEach((function(r){e.hasOwnProperty(r)&&(e[r]=a(e[r],t))}));break;case Array:e.forEach((function(r,n,o){o[n]=a(e[n],t)}))}return e}function i(e){return e.split("-").map((e=>e.charAt(0).toUpperCase()+e.slice(1))).join("")}function l(e,t){let r;return()=>{clearTimeout(r),r=setTimeout((function(){e(...arguments)}),t)}}function u(e){let t=document.createElement("template");return e=e.replace(/<([A-Za-z0-9\-]*)([^>\/]*)(\/>)/gi,"<$1$2></$1>"),t.innerHTML=e,t.content.normalize(),Array.from(t.content.childNodes)}function d(e,t){const r=Object.getOwnPropertyDescriptors(e);for(const[e,n]of Object.entries(r))("get"in n||"set"in n)&&Object.defineProperty(t,e,n)}e.r(t),e.d(t,{DC:()=>k,MC:()=>C,McBase:()=>S,McEvent:()=>p,addListener:()=>E,autoload:()=>D,copyGettersSetters:()=>d,debounce:()=>l,deepEqual:()=>c,defineCE:()=>q,flattenObject:()=>o,formValues:()=>K,getCE:()=>$,htmlToElements:()=>u,isNativeObject:()=>r,kebabToPascal:()=>i,nameSpace:()=>s,observe:()=>J,parse:()=>a,removeListener:()=>v,sortObject:()=>n});var f=new Function("try {return this===window;}catch(e){ return false;}");let m=new Set;f()&&Object.keys(HTMLElement.prototype).filter((e=>/^on/.test(e))).forEach((e=>m.add(e)));class p{#e;#t=!1;#r=!1;constructor(e,t={},r="l"){this.#e=e,this.data=t,this.bubble=r}get type(){return this.#e}get stopped(){return this.#t}get immediateStopped(){return this.#r}stopPropagation(){this.#t=!0}stopImmediatePropagation(){this.stopPropagation(),this.#r=!0}}var b=new Function("try {return this===window;}catch(e){ return false;}");let g=new Set;function h(e,t){let r=[];return e.forEach((e=>{if(e&&e instanceof HTMLElement){const n=e?._mc;!t&&n?r=r.concat(Object.values(e._mc)):t&&n&&n[t]&&r.push(n[t])}})),r}function y(e,t,r=!0){let n=[];for(;e;){if(e._mc&&(t?t&&e._mc[t]&&n.push(e._mc[t]):n=n.concat(Object.values(e._mc)),r))return n;e=e.parentNode}return n}function O(e){return e&&e instanceof HTMLElement}function E(e,t,r,n=!1,o=!1){let c={once:!1};n&&(c.capture=n),o&&(c.once=o),e.addEventListener(t,r,c)}function v(e,t,r){e.removeEventListener(t,r)}function w(e,t,r={}){let n=e;if(!n._mc){let t=k?.debug;k.debug=!1,n._mc=new k(e),k.debug=t,delete n._mc._mc}const o=n._mc;return t.length&&!o[t]&&(o[t]=r,e instanceof HTMLElement&&!e.getAttribute("_mc")&&e.setAttribute("_mc","")),r}function A(e,t){if(!t)return;const r=e?._mc||{};r&&r[t]&&delete r[t],!Object.keys(r).length&&e instanceof HTMLElement&&e.hasAttribute("_mc")&&e.removeAttribute("_mc")}function j(e,t,r={},n="l"){let o=e?._mc;if(!o)return;let c=t instanceof p?new p(t.type,t.data,"l"):new p(t,r,"l"),s="string"!=typeof t?t:new p(t,r,n);[...Object.values(o)].forEach((e=>{e?.trigger&&"function"==typeof e?.trigger&&e?.trigger(c)})),/[ud]/.test(s.bubble)&&_(e,s)}function _(e,t){/[ud]/.test(t.bubble)&&setTimeout((()=>{if(-1===t.bubble.indexOf("l")&&(t.bubble+="l"),t.bubble.indexOf("u")>-1){let r=y(e,"",!0)?.[0].target;r&&k.trigger(r,t)}t.bubble.indexOf("d")>-1&&new Set(e._mc.children().map((e=>e?.target))).forEach((e=>{e&&k.trigger(e,t)}))}),0)}b()&&Object.keys(HTMLElement.prototype).filter((e=>/^on/.test(e))).forEach((e=>g.add(e)));class S{#n;constructor(e,t=!1){var r;this.#n=new WeakRef(e||{}),(r=this).constructor!==k&&setTimeout((()=>{r.trigger("Init")}),0),function(e){if(!b()||e.constructor===k)return;const t=e.target;if(t instanceof HTMLElement){let r=e;Object.getOwnPropertyNames(r.constructor.prototype).filter((e=>/^on[A-Z]|one[A-Z]/.test(e)&&"function"==typeof r.constructor.prototype[e])).forEach((n=>{let o=/^one/.test(n),c=n.replace(/^on[e]{0,1}/,""),s=c.toLowerCase();o&&Object.defineProperty(e,"on"+c,{configurable:!0,enumerable:!1,writable:!0,value:e=>{r.constructor.prototype[n].bind(r)(e)}}),g.has("on"+s)&&E(t,s,(e=>{r.trigger(c,e)}),!1,o)}))}}(this)}get target(){return this.#n.deref()}}class C extends S{_mc={};constructor(e){super(e)}static trigger=j;trigger(e,t={},r="l"){let n=this;if(n.constructor===C||n.constructor===k){let o=e instanceof p?new p(e.type,e.data,"l"):new p(e,t,"l"),c="string"!=typeof e?e:new p(e,t,r);return[...Object.getOwnPropertyNames(n)].forEach((e=>{n[e]?.trigger&&"function"==typeof n[e]?.trigger&&n[e]?.trigger(o)})),void(/[ud]/.test(c.bubble)&&_(n.target,c))}if(n instanceof C||n instanceof k){const n=this,o="string"!=typeof e?e:new p(e,t,r),c="on"+o.type[0].toUpperCase()+o.type.slice(1);if(o.bubble.indexOf("l")>-1&&(o.immediateStopped||"function"!=typeof n[c]||(n[c](o),n.hasOwnProperty(c)&&delete n[c])),o.stopped||"l"===o.bubble)return n;/[ud]/.test(o.bubble)&&_(n.target,o)}}}class k extends S{_mc={};constructor(e,t=!1){super(e)}static add=w;static remove=A;static trigger=j;trigger(e,t={},r){C.prototype.trigger.call(this,e,t,r)}parent(e=""){let t=this.target;return O(t)?y(t.parentNode,e,!0):[]}ancestors(e=""){let t=this?.target;return O(t)?y(this.target.parentNode,e,!1):[]}children(e=""){let t=this?.target;if(!O(t))return[];const r=Math.random().toString().replace(".",""),n='[_mc]:not([temp_id="'+r+'"] [_mc] [_mc])';t.setAttribute("temp_id",r);const o=h([...t.querySelectorAll(n)],e);return t.removeAttribute("temp_id"),o}descendants(e=""){let t=this?.target;return O(t)?h([...t.querySelectorAll("*[_mc]")],e):[]}}const T=new Map,N=new Map;function L(e){const t="./"+e.split("-").join("/")+".js",r=document.createElement("script");return r.setAttribute("src",t),r.setAttribute("blocking","render"),r.async=!0,r.setAttribute("type","module"),r.setAttribute("name",e),r.setAttribute("loading",""),E(r,"load",(e=>{r.removeAttribute("loading"),r.setAttribute("loaded","")})),E(r,"error",(e=>{console.error("could not load Custom Element code from",t)})),r}function M(){[...document.querySelectorAll(":not(:defined)")].filter((e=>!!e&&!customElements.get(e.tagName.toLowerCase())&&!T.has(e.tagName.toLowerCase()))).forEach((e=>{const t=e.tagName.toLowerCase(),r=(t.split("-").join("/"),L(t));E(r,"load",(()=>{T.set(t,customElements.get(e.tagName.toLowerCase()))})),T.set(t,"loading"),document.head.append(r)})),[...document.querySelectorAll('[_mc]:not([_mc=""]')].filter((e=>!!e)).forEach((e=>{const t=e.getAttribute("_mc")?.split(" ").filter((e=>!!e))||[],r=t.filter((e=>!N.has(e)));r?.forEach((e=>{const t=L(e);E(t,"load",(()=>{return t=document.head.querySelector(`script[name="${e}"]`),void setTimeout((function(){const e=t.getAttribute("src"),r=t.getAttribute("name"),n=document.createElement("script");n.async=!0,n.setAttribute("type","module");const o=`\n\n\t\t\timport _ from "${e}";\n\t\t\timport {DC} from "./microcomponents.js";\n\n\t\t\tconst elements = Array.from(document.querySelectorAll('[_mc*="${r}"]')).filter( element => element instanceof HTMLElement );\n\n\t\t\telements.forEach((element) => {\n\t\t\t\t// add class to MCs repository\n\t\t\t\tautoload.state.MCs.set( '${r}', _ );\n\t\t\t\t// add instance to HTMLElement \n\t\t\t\tDC.add(element, _.name, new _(element));\n\t\t\t\t// remove instance name from elements "_mc" attribute\n\t\t\t\telement.setAttribute('_mc', element.getAttribute('_mc').replace('${r}', '').replace( /ww/g, ' ').trim()); \n\t\t\t});\n\n\t\t\tsetTimeout( () => {\n\t\t\t\tdocument.body.querySelector('script[name="${r}]"')?.remove();\n\t\t\t},0);\n\n\t\t`;n.innerHTML=o,document.body.append(n)}),0);var t})),N.set(e,"loading"),document.head.append(t)}));const n=t.filter((e=>N.has(e)&&!N.get(e).length));n?.forEach((t=>{setTimeout((()=>{k.add(e,t,new(D.state.MCs.get(t))(e)),e.getAttribute("_mc").replace("${elementName}","").replace(/\w\w/g," ").trim(),e.setAttribute("_mc")}),5)}))}))}let x=!1,P=null;function D(e=!0){return e?(x=e,P=new MutationObserver(M),setTimeout((()=>{P.observe(document.body,{childList:!0,subtree:!0}),M()}),5),x):(P?.disconnect(),P=null,x)}D.state={CEs:T,MCs:N};class H extends HTMLElement{constructor(){super()}connectedCallback(){k.trigger(this,"Connected")}disconnectedCallback(){k.trigger(this,"Disconnected")}adoptedCallback(){k.trigger(this,"Adopted")}attributeChangedCallback(e,t,r){k.trigger(this,"AttributeChanged",{name:e,oldValue:t,newValue:r})}}function q(e,t,r=[]){if(customElements.get(e))return void console.warn(`IGNORED: Custom element "${e}" is already defined!`);if(!e.includes("-"))throw new Error('createCustomElement: tagName must contain at least one hyphen ("-").');let n=i(e);customElements.define(e,function(e,t){return Object.defineProperty(t,"name",{value:e})}(n,class extends H{instance;constructor(e){super();let r=new t(this,e);k.add(this,n,r)}static get observedAttributes(){return r}}))}function $(e){return customElements.get(e)}function I(e){return null!=e&&"object"==typeof e}function V(e){let t=new Set,r=/\{[^\{\}]*\}/g;return e.getAttributeNames().filter((t=>e.getAttribute(t)?.match(r))).forEach((n=>{new Set(e.getAttribute(n)?.match(r)).forEach((e=>t.add(e.replace(/[\{\}]/g,""))))})),[...e.childNodes].filter((e=>3===e.nodeType&&(e.nodeValue||"").match(r))).forEach((e=>{(e.nodeValue||"").match(r).forEach((e=>{t.add(e.replace(/[\{\}]/g,""))}))})),[...t].map((e=>e.replace(/[\{\}]/g,"")))}const F=[HTMLInputElement,HTMLSelectElement,HTMLTextAreaElement];class G extends k{data={};oldDisplay="";constructor(e){super(e);let t=this;V(e).forEach((e=>t.data[e]="")),J(t),t.#o(),delete t._mc}#o(){let e=this,t=e.target,r=!1;t.getAttributeNames().filter((e=>t.getAttribute(e)?.match(/\{[^\{\}]*\}/g))).forEach((r=>{let n=new Set(t.getAttribute(r)?.match(/\{[^\{\}]*\}/g));var o;e.data.observe((o=t.getAttribute(r),e=>{let c=o;n.forEach((t=>{c=c.replace(t,e[t.replace(/[\{\}]/g,"")])})),t.setAttribute(r,c)}))})),[...t.childNodes].filter((e=>3===e.nodeType&&(e.nodeValue||"").match(/\{[^\{\}]*\}/g))).forEach((n=>{r=!0;let o=new Set(n.nodeValue.match(/\{[^\{\}]*\}/g));var c;e.data.observe((c=n.nodeValue,r=>{let s=c;o.forEach((e=>{s=s.replace(e,r[e.replace(/[\{\}]/g,"")])})),Object.keys(r).some((e=>!!r[e]))&&(e.oldDisplay?t.style=e.oldDisplay:t.removeAttribute("style"),delete e.oldDisplay),n.nodeValue=s})),e.oldDisplay=t.getAttribute("style)")||"",r&&!F.includes(t.constructor)&&"FIELDSET"!==t.tagName&&(t.style.display="none")}))}onData(e){let t=this,r={};Object.keys(e.data).forEach((n=>{t.data.hasOwnProperty(n)&&(r[n]=e.data[n])})),JSON.stringify(r)!==JSON.stringify(t.data)&&Object.assign(t.data,r)}}const J=(e,t)=>((t?[t]:[...Object.getOwnPropertyNames(e)]).forEach((t=>{if("_"===t[0]||void 0===e?.[t])return e;let r,n=e[t];if(!n.prototype)switch(typeof n){case"string":r=String;break;case"number":r=Number;break;case"boolean":r=Boolean;break;case"object":r=n instanceof Array?Array:Object;break;default:return}let s=class extends r{#c=!0;constructor(e){super(e),this.constructor.callbacks=[],I(e)&&Object.getOwnPropertyNames(e).forEach((t=>{this[t]=e[t]}))}observe(e){return this.constructor.callbacks.push(e),this}bind(e){const t=this;if(I(t.valueOf())){!function(e){var t;(t=e,(t instanceof HTMLElement?[t]:[]).concat([...t.querySelectorAll("*")]).filter((e=>!!V(e).length)).filter((e=>"STYLE"!==e.tagName))).forEach((e=>{e?._mc?._placeholders||k.add(e,"_placeholders",new G(e))}))}(e);const r=[...e.querySelectorAll("[_mc]")].filter((e=>!!e?._mc?._placeholders)),n=function(e){let t=o(e);r.forEach((e=>{e&&e._mc.trigger("data",t)}))};t.constructor.callbacks.push(n),t.notify()}else console.warn("IGNORED - cannot bind a non-Object to the dom, IS:",typeof t.valueOf(),t);return this}notify(e){let t=this,r=I(t.valueOf())&&t.valueOf()instanceof Array==0?structuredClone(Object.assign({},t)):t.valueOf();return void 0!==e&&(t.#c=e),t.constructor.callbacks.forEach((e=>{e(r)})),t}},a=new s(n);Object.defineProperty(e,t,{enumerable:!0,get(){if(I(a.valueOf())){let e=structuredClone(Object.assign({},a));setTimeout(l((function(){c(structuredClone(Object.assign({},a)),e)||a.notify()}),0),0)}return a},set(e){if(typeof e==typeof a.valueOf())if(I(a.valueOf())&&a.valueOf()instanceof Array==0){let t=structuredClone(Object.assign({},a));a instanceof s==0&&(a=new s(structuredClone(Object.assign({},e))),d(e,a),a.seal()),Object.assign(a,e),setTimeout(l((function(){c(structuredClone(Object.assign({},a)),t)||a.notify()}),0),0)}else{let t=a.valueOf(),r=a.constructor.callbacks;a=new s(e),a.constructor.callbacks=r,e!==t&&a.notify()}else console.warn("IGNORED - cannot change observable types, IS:",typeof a.valueOf(),a,"- CANNOT BECOME:",typeof e)}}),e[t]=n})),e);class R{constructor(e){}}class B extends R{#s;constructor(e){super(e),this.#s=e}get val(){return new FormData(this.#s.form).get(this.#s.name)}set val(e){[...this.#s.form.querySelectorAll(`input[type="radio"][name="${this.#s.name}"]`)].filter((t=>t.getAttribute("value")===e)).shift().checked=!0}}class Z extends R{#s;constructor(e){super(e),this.#s=e}get val(){return this.#s.checked}set val(e){this.#s.checked=e}}class z extends R{#s;constructor(e){super(e),this.#s=e}get val(){return this.#s.value}set val(e){this.#s.value=e}}class U extends R{#s;#a=!1;constructor(e){super(e),this.#s=e,this.#a=e.multiple}get val(){const e=[];return[...this.#s.querySelectorAll("option")].filter((e=>e.selected)).forEach((t=>{e.push(t.value)})),this.#a?e:e.length?e[0]:""}set val(e){e="string"==typeof e?[e]:e,[...this.#s.querySelectorAll("option")].forEach((t=>{e.indexOf(t.value)>-1?t.selected=!0:t.selected=!1}))}}class W extends R{#s;constructor(e){super(e),this.#s=e}get val(){return this.#s.value||""}set val(e){this.#s.value=e}}const Y=e=>{let t=[...(e||document).querySelectorAll("input,select,textarea")],r={};return t.forEach((e=>{const t=e.getAttribute("name");if(t){let n=!1;switch((e=>e.tagName.toLowerCase())(e)){case"input":switch(e.type){case"radio":n=new B(e);break;case"checkbox":n=new Z(e);break;default:n=new z(e)}break;case"select":n=new U(e);break;case"textarea":n=new W(e);break;default:console.warn("handler missing:",t,"for",e.tagName.toLowerCase(),e)}n&&(k.add(e,t,n),Object.defineProperty(r,t,{enumerable:!0,configurable:!0,get:()=>n.val,set:e=>{n.val!==e&&(n.val=e)}}))}})),r};function K(e,t,r){let n=Y(r);e[t]=Object.assign({},n),J(e,t),d(n,e[t]),[...r.querySelectorAll("input, textarea, select")].forEach((r=>{E(r,"keyup",(r=>{e[t].notify()})),E(r,"change",(r=>{e[t].notify()})),E(r,"select",(r=>{e[t].notify()}))}))}return t})()));
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ export * from './helpers.js';
3
+ export * from './MC.js';
4
+ export * from './McEvent.js';
5
+ export * from './elements.js';
6
+ export * from './observables.js';
7
+ //export * from './selectors.js';
8
+ export * from './formValues.js';
@@ -0,0 +1,10 @@
1
+ import { LooseObject } from './helpers.js';
2
+ type Callback = (value: any) => void;
3
+ export type Observable = {
4
+ observe: (cb: Callback) => void;
5
+ notify: () => void;
6
+ bind: (target: HTMLElement | DocumentFragment | ShadowRoot) => void;
7
+ };
8
+ export declare const observe: (target: LooseObject, propertyName?: string) => LooseObject;
9
+ export {};
10
+ //# sourceMappingURL=observables.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"observables.d.ts","sourceRoot":"","sources":["../src/observables.ts"],"names":[],"mappings":"AAEA,OAAO,EACN,WAAW,EAKX,MAAM,cAAc,CAAC;AAQtB,KAAK,QAAQ,GAAG,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;AAiLrC,MAAM,MAAM,UAAU,GAAG;IACxB,OAAO,EAAE,CAAC,EAAE,EAAE,QAAQ,KAAK,IAAI,CAAC;IAChC,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,IAAI,EAAE,CAAC,MAAM,EAAE,WAAW,GAAG,gBAAgB,GAAG,UAAU,KAAK,IAAI,CAAC;CACpE,CAAC;AAEF,eAAO,MAAM,OAAO,WACX,WAAW,iBACJ,MAAM,KACnB,WAsMF,CAAC"}