@twobirds/microcomponents 0.0.82 → 0.0.84

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 (268) hide show
  1. package/assets/documentation/MC.md +0 -1
  2. package/assets/test/test.html +1 -1
  3. package/dist/MC.d.ts +11 -10
  4. package/dist/MC.d.ts.map +1 -1
  5. package/dist/MC.js +137 -200
  6. package/dist/MC.min.js +157 -296
  7. package/dist/MC.ts +202 -337
  8. package/dist/elements.d.ts +1 -1
  9. package/dist/elements.d.ts.map +1 -1
  10. package/dist/elements.js +26 -6
  11. package/dist/elements.min.js +1 -1
  12. package/dist/elements.ts +50 -7
  13. package/dist/formValues.js +2 -2
  14. package/dist/formValues.min.js +1 -1
  15. package/dist/formValues.ts +3 -3
  16. package/dist/microcomponents.d.ts +0 -1
  17. package/dist/microcomponents.d.ts.map +1 -1
  18. package/dist/microcomponents.js +0 -1
  19. package/dist/microcomponents.min.js +1 -1
  20. package/dist/microcomponents.ts +1 -1
  21. package/dist/observables.d.ts.map +1 -1
  22. package/dist/observables.js +52 -57
  23. package/dist/observables.min.js +1 -1
  24. package/dist/observables.ts +68 -73
  25. package/package.json +6 -5
  26. package/public/MC.d.ts +11 -10
  27. package/public/MC.d.ts.map +1 -1
  28. package/public/MC.js +137 -200
  29. package/public/MC.js.map +1 -1
  30. package/public/MC.min.js +157 -296
  31. package/public/MC.ts +202 -337
  32. package/public/documentation/MC.md +0 -1
  33. package/public/elements.d.ts +1 -1
  34. package/public/elements.d.ts.map +1 -1
  35. package/public/elements.js +26 -6
  36. package/public/elements.js.map +1 -1
  37. package/public/elements.min.js +1 -1
  38. package/public/elements.ts +50 -7
  39. package/public/formValues.js +2 -2
  40. package/public/formValues.js.map +1 -1
  41. package/public/formValues.min.js +1 -1
  42. package/public/formValues.ts +3 -3
  43. package/public/microcomponents.d.ts +0 -1
  44. package/public/microcomponents.d.ts.map +1 -1
  45. package/public/microcomponents.js +0 -1
  46. package/public/microcomponents.js.map +1 -1
  47. package/public/microcomponents.min.js +1 -1
  48. package/public/microcomponents.ts +1 -1
  49. package/public/observables.d.ts.map +1 -1
  50. package/public/observables.js +52 -57
  51. package/public/observables.js.map +1 -1
  52. package/public/observables.min.js +1 -1
  53. package/public/observables.ts +68 -73
  54. package/public/{test/selectors.ts → selectors._ts} +2 -367
  55. package/public/src/MC.d.ts +37 -0
  56. package/public/src/MC.d.ts.map +1 -0
  57. package/public/src/MC.js +316 -0
  58. package/public/src/MC.js.map +1 -0
  59. package/public/src/MC.ts +202 -337
  60. package/public/src/elements.d.ts +5 -0
  61. package/public/src/elements.d.ts.map +1 -0
  62. package/public/src/elements.js +68 -0
  63. package/public/src/elements.js.map +1 -0
  64. package/public/src/elements.ts +50 -7
  65. package/public/src/formValues.d.ts +3 -0
  66. package/public/src/formValues.d.ts.map +1 -0
  67. package/public/src/formValues.js +162 -0
  68. package/public/src/formValues.js.map +1 -0
  69. package/public/src/formValues.ts +3 -3
  70. package/public/src/helpers.d.ts +14 -0
  71. package/public/src/helpers.d.ts.map +1 -0
  72. package/public/src/helpers.js +113 -0
  73. package/public/src/microcomponents.d.ts +6 -0
  74. package/public/src/microcomponents.d.ts.map +1 -0
  75. package/public/src/microcomponents.js +7 -0
  76. package/public/src/microcomponents.js.map +1 -0
  77. package/public/src/microcomponents.ts +1 -1
  78. package/public/src/observables.d.ts +11 -0
  79. package/public/src/observables.d.ts.map +1 -0
  80. package/public/src/observables.js +244 -0
  81. package/public/src/observables.js.map +1 -0
  82. package/public/src/observables.ts +68 -73
  83. package/public/{selectors.ts → src/selectors._ts} +2 -367
  84. package/public/src/test/grandparent.css +11 -0
  85. package/public/src/test/test/child.d.ts +2 -0
  86. package/public/src/test/test/child.d.ts.map +1 -0
  87. package/public/src/test/test/child.js +15 -0
  88. package/public/src/test/test/child.js.map +1 -0
  89. package/public/src/test/test/child.ts +21 -0
  90. package/public/src/test/test/grandchild.d.ts +2 -0
  91. package/public/src/test/test/grandchild.d.ts.map +1 -0
  92. package/public/src/test/test/grandchild.js +15 -0
  93. package/public/src/test/test/grandchild.js.map +1 -0
  94. package/public/src/test/test/grandchild.ts +21 -0
  95. package/public/src/test/test/grandparent.d.ts +2 -0
  96. package/public/src/test/test/grandparent.d.ts.map +1 -0
  97. package/public/src/test/test/grandparent.js +1 -0
  98. package/public/src/test/test/grandparent.js.map +1 -0
  99. package/public/src/test/test/grandparent.ts +29 -0
  100. package/public/src/test/test/greatgrandchild.d.ts +2 -0
  101. package/public/src/test/test/greatgrandchild.d.ts.map +1 -0
  102. package/public/src/test/test/greatgrandchild.js +29 -0
  103. package/public/src/test/test/greatgrandchild.js.map +1 -0
  104. package/public/src/test/test/greatgrandchild.ts +42 -0
  105. package/public/src/test/test/parent.d.ts +2 -0
  106. package/public/src/test/test/parent.d.ts.map +1 -0
  107. package/public/src/test/test/parent.js +15 -0
  108. package/public/src/test/test/parent.js.map +1 -0
  109. package/public/src/test/test/parent.ts +21 -0
  110. package/public/src/test/test/testform.d.ts +2 -0
  111. package/public/src/test/test/testform.d.ts.map +1 -0
  112. package/public/src/test/test/testform.js +1 -0
  113. package/public/src/test/test/testform.js.map +1 -0
  114. package/public/src/test/test/testform.ts +153 -0
  115. package/public/src/test/test/testfunction.d.ts +3 -0
  116. package/public/src/test/test/testfunction.d.ts.map +1 -0
  117. package/public/src/test/test/testfunction.js +7 -0
  118. package/public/src/test/test/testfunction.js.map +1 -0
  119. package/public/src/test/test/testfunction.ts +12 -0
  120. package/public/src/test/test/testmc.d.ts +3 -0
  121. package/public/src/test/test/testmc.d.ts.map +1 -0
  122. package/public/src/test/test/testmc.js +10 -0
  123. package/public/src/test/test/testmc.js.map +1 -0
  124. package/public/src/test/test/testmc.ts +16 -0
  125. package/public/src/test/test/testsimpleclass.d.ts +3 -0
  126. package/public/src/test/test/testsimpleclass.d.ts.map +1 -0
  127. package/public/src/test/test/testsimpleclass.js +9 -0
  128. package/public/src/test/test/testsimpleclass.js.map +1 -0
  129. package/public/src/test/test/testsimpleclass.ts +15 -0
  130. package/public/src/test/test.d.ts +2 -0
  131. package/public/src/test/test.d.ts.map +1 -0
  132. package/public/src/test/test.js +80 -0
  133. package/public/src/test/test.js.map +1 -0
  134. package/public/src/test/test.ts +188 -0
  135. package/public/src/test/testform.css +47 -0
  136. package/public/src/test/testform.html +56 -0
  137. package/public/src/test/testform.json +27 -0
  138. package/public/test/MC.d.ts +11 -10
  139. package/public/test/MC.d.ts.map +1 -1
  140. package/public/test/MC.js +137 -200
  141. package/public/test/MC.min.js +377 -0
  142. package/public/test/MC.ts +202 -337
  143. package/public/test/elements.d.ts +1 -1
  144. package/public/test/elements.d.ts.map +1 -1
  145. package/public/test/elements.js +26 -6
  146. package/public/test/elements.min.js +1 -0
  147. package/public/test/elements.ts +50 -7
  148. package/public/test/formValues.js +2 -2
  149. package/public/test/formValues.min.js +1 -0
  150. package/public/test/formValues.ts +3 -3
  151. package/public/test/grandparent.css +1 -3
  152. package/public/test/microcomponents.d.ts +0 -1
  153. package/public/test/microcomponents.d.ts.map +1 -1
  154. package/public/test/microcomponents.js +0 -1
  155. package/public/test/microcomponents.min.js +1 -1
  156. package/public/test/microcomponents.ts +1 -1
  157. package/public/test/observables.d.ts.map +1 -1
  158. package/public/test/observables.js +52 -57
  159. package/public/test/observables.min.js +1 -0
  160. package/public/test/observables.ts +68 -73
  161. package/public/test/test/child.ts +21 -0
  162. package/public/test/test/grandchild.ts +21 -0
  163. package/public/test/test/grandparent.d.ts.map +1 -1
  164. package/public/test/test/grandparent.js +1 -1
  165. package/public/test/test/grandparent.js.map +1 -1
  166. package/public/test/test/grandparent.ts +29 -0
  167. package/public/test/test/greatgrandchild.ts +42 -0
  168. package/public/test/test/parent.ts +21 -0
  169. package/public/test/test/testform.js +1 -1
  170. package/public/test/test/testform.js.map +1 -1
  171. package/public/test/test/testform.ts +153 -0
  172. package/public/test/test/testfunction.d.ts +3 -0
  173. package/public/test/test/testfunction.d.ts.map +1 -0
  174. package/public/test/test/testfunction.js +7 -0
  175. package/public/test/test/testfunction.js.map +1 -0
  176. package/public/test/test/testfunction.ts +12 -0
  177. package/public/test/test/testmc.d.ts +2 -5
  178. package/public/test/test/testmc.d.ts.map +1 -1
  179. package/public/test/test/testmc.js +4 -4
  180. package/public/test/test/testmc.js.map +1 -1
  181. package/public/test/test/testmc.ts +16 -0
  182. package/public/test/test/testsimpleclass.d.ts +3 -0
  183. package/public/test/test/testsimpleclass.d.ts.map +1 -0
  184. package/public/test/test/testsimpleclass.js +9 -0
  185. package/public/test/test/testsimpleclass.js.map +1 -0
  186. package/public/test/test/testsimpleclass.ts +15 -0
  187. package/public/test/test.html +1 -1
  188. package/public/test/test.js +5 -6
  189. package/public/test/test.js.map +1 -1
  190. package/public/test/test.ts +188 -0
  191. package/public/test/testform.css +47 -0
  192. package/public/test/testform.html +56 -0
  193. package/public/test/testform.json +3 -3
  194. package/public/typedoc/assets/navigation.js +1 -1
  195. package/public/typedoc/assets/search.js +1 -1
  196. package/public/typedoc/classes/MC.DC.html +6 -4
  197. package/public/typedoc/classes/MC.MC.html +3 -4
  198. package/public/typedoc/classes/MC.McBase.html +2 -2
  199. package/public/typedoc/functions/MC.autoload.html +1 -1
  200. package/public/typedoc/functions/MC.off.html +1 -0
  201. package/public/typedoc/functions/MC.on.html +1 -0
  202. package/public/typedoc/functions/MC.one.html +1 -0
  203. package/public/typedoc/functions/elements.defineCE.html +1 -1
  204. package/public/typedoc/functions/elements.getCE.html +1 -1
  205. package/public/typedoc/functions/formValues.formValues.html +1 -1
  206. package/public/typedoc/functions/observables.observe.html +1 -1
  207. package/public/typedoc/interfaces/MC.HTMLMcElement.html +2 -2
  208. package/public/typedoc/modules/MC.html +7 -6
  209. package/public/typedoc/modules/elements.html +1 -1
  210. package/public/typedoc/modules/formValues.html +1 -1
  211. package/public/typedoc/modules/observables.html +1 -1
  212. package/public/typedoc/types/observables.Observable.html +1 -1
  213. package/src/MC.ts +202 -337
  214. package/src/elements.ts +50 -7
  215. package/src/formValues.ts +3 -3
  216. package/src/microcomponents.ts +1 -1
  217. package/src/observables.ts +68 -73
  218. package/{dist/selectors.ts → src/selectors._ts} +2 -367
  219. package/src/test/test/grandparent.ts +12 -4
  220. package/src/test/test/testform.ts +13 -11
  221. package/src/test/test/testfunction.ts +12 -0
  222. package/src/test/test/testmc.ts +13 -9
  223. package/src/test/test/testsimpleclass.ts +15 -0
  224. package/src/test/test.ts +8 -20
  225. package/tasks.md +36 -0
  226. package/tsconfig.json +2 -2
  227. package/typedoc.json +1 -1
  228. package/webpack.config.js +2 -2
  229. package/dist/McEvent.d.ts +0 -15
  230. package/dist/McEvent.d.ts.map +0 -1
  231. package/dist/McEvent.js +0 -71
  232. package/dist/selectors.d.ts +0 -108
  233. package/dist/selectors.d.ts.map +0 -1
  234. package/dist/selectors.js +0 -971
  235. package/dist/selectors.min.js +0 -1
  236. package/public/McEvent.d.ts +0 -15
  237. package/public/McEvent.d.ts.map +0 -1
  238. package/public/McEvent.js +0 -71
  239. package/public/McEvent.js.map +0 -1
  240. package/public/selectors.d.ts +0 -108
  241. package/public/selectors.d.ts.map +0 -1
  242. package/public/selectors.js +0 -971
  243. package/public/selectors.js.map +0 -1
  244. package/public/selectors.min.js +0 -1
  245. package/public/src/selectors.ts +0 -1634
  246. package/public/test/MC.js.map +0 -1
  247. package/public/test/McEvent.d.ts +0 -15
  248. package/public/test/McEvent.d.ts.map +0 -1
  249. package/public/test/McEvent.js +0 -71
  250. package/public/test/McEvent.js.map +0 -1
  251. package/public/test/McEvent.ts +0 -96
  252. package/public/test/elements.js.map +0 -1
  253. package/public/test/formValues.js.map +0 -1
  254. package/public/test/microcomponents.js.map +0 -1
  255. package/public/test/observables.js.map +0 -1
  256. package/public/test/selectors.d.ts +0 -108
  257. package/public/test/selectors.d.ts.map +0 -1
  258. package/public/test/selectors.js +0 -971
  259. package/public/test/selectors.js.map +0 -1
  260. package/public/typedoc/classes/MC.McEvent.html +0 -9
  261. package/public/typedoc/functions/MC.addListener.html +0 -1
  262. package/public/typedoc/functions/MC.removeListener.html +0 -1
  263. package/src/McEvent.ts +0 -96
  264. package/src/selectors.ts +0 -1634
  265. /package/{dist/McEvent.ts → public/McEvent._ts} +0 -0
  266. /package/public/{McEvent.ts → src/McEvent._ts} +0 -0
  267. /package/public/{test → src}/helpers.js.map +0 -0
  268. /package/{public/src/McEvent.ts → src/McEvent._ts} +0 -0
@@ -1,5 +1,5 @@
1
1
  export declare function defineCE(tagName: string, DefinitionClass: {
2
2
  new (...args: any[]): any;
3
- }, observedAttributes?: string[]): void;
3
+ } | Function, observedAttributes?: string[]): void;
4
4
  export declare function getCE(tagName: string): CustomElementConstructor | undefined;
5
5
  //# sourceMappingURL=elements.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"elements.d.ts","sourceRoot":"","sources":["../src/elements.ts"],"names":[],"mappings":"AAkCA,wBAAgB,QAAQ,CACvB,OAAO,EAAE,MAAM,EACf,eAAe,EAAE;IAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,GAAG,CAAA;CAAE,EAC9C,kBAAkB,GAAE,MAAM,EAAO,QAkCjC;AAED,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,wBAAwB,GAAG,SAAS,CAE3E"}
1
+ {"version":3,"file":"elements.d.ts","sourceRoot":"","sources":["../src/elements.ts"],"names":[],"mappings":"AAoDA,wBAAgB,QAAQ,CACvB,OAAO,EAAE,MAAM,EACf,eAAe,EAAE;IAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,GAAG,CAAA;CAAE,GAAG,QAAQ,EACzD,kBAAkB,GAAE,MAAM,EAAO,QA2DjC;AAED,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,wBAAwB,GAAG,SAAS,CAE3E"}
@@ -1,26 +1,36 @@
1
1
  'use strict';
2
- import { DC } from './MC.js';
2
+ import { DC, McBase } from './MC.js';
3
3
  import { kebabToPascal } from './helpers.js';
4
4
  class CeBaseClass extends HTMLElement {
5
5
  constructor() {
6
6
  super();
7
7
  }
8
8
  connectedCallback() {
9
- DC.trigger(this, 'Connected');
9
+ this.dispatchEvent(new CustomEvent('_mcConnected'));
10
+ }
11
+ connectedMoveCallback() {
12
+ this.dispatchEvent(new CustomEvent('_mcConnectedMove'));
10
13
  }
11
14
  disconnectedCallback() {
12
- DC.trigger(this, 'Disconnected');
15
+ this.dispatchEvent(new CustomEvent('_mcDisconnected'));
13
16
  }
14
17
  adoptedCallback() {
15
- DC.trigger(this, 'Adopted');
18
+ this.dispatchEvent(new CustomEvent('_mcAdopted'));
16
19
  }
17
20
  attributeChangedCallback(name, oldValue, newValue) {
18
- DC.trigger(this, 'AttributeChanged', { name, oldValue, newValue });
21
+ this.dispatchEvent(new CustomEvent('_mcAttributeChanged', { detail: { name, oldValue, newValue } }));
22
+ }
23
+ formResetCallback() {
24
+ this.dispatchEvent(new CustomEvent('_mcFormReset'));
19
25
  }
20
26
  }
21
27
  function createNamedClass(name, ClassBody) {
22
28
  return Object.defineProperty(ClassBody, 'name', { value: name });
23
29
  }
30
+ function isClass(func) {
31
+ return typeof func === 'function'
32
+ && /^class\s/.test(Function.prototype.toString.call(func));
33
+ }
24
34
  export function defineCE(tagName, DefinitionClass, observedAttributes = []) {
25
35
  if (customElements.get(tagName)) {
26
36
  console.warn(`IGNORED: Custom element "${tagName}" is already defined!`);
@@ -30,11 +40,21 @@ export function defineCE(tagName, DefinitionClass, observedAttributes = []) {
30
40
  throw new Error('createCustomElement: tagName must contain at least one hyphen ("-").');
31
41
  }
32
42
  let name = kebabToPascal(tagName);
43
+ if (!isClass(DefinitionClass.prototype.constructor)) {
44
+ customElements.define(tagName, DefinitionClass);
45
+ return;
46
+ }
47
+ if (!(DefinitionClass.prototype instanceof McBase)) {
48
+ customElements.define(tagName, DefinitionClass);
49
+ return;
50
+ }
33
51
  customElements.define(tagName, createNamedClass(name, class extends CeBaseClass {
34
52
  instance;
35
53
  constructor(data) {
36
54
  super();
37
- let instance = new DefinitionClass(this, data);
55
+ const instance = isClass(DefinitionClass)
56
+ ? new DefinitionClass(this, data)
57
+ : DefinitionClass;
38
58
  DC.add(this, name, instance);
39
59
  }
40
60
  static get observedAttributes() {
@@ -0,0 +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:()=>b,getCE:()=>h});var n=new Function("try {return this===window;}catch(e){ return false;}");function r(t,e){let n=[];return t.forEach((t=>{if(t&&t instanceof HTMLElement){const r=t?._mc;!e&&r?n=n.concat(Object.values(t._mc)):e&&r&&r[e]&&n.push(r[e])}})),n}function o(t,e,n=!0){let r=[];for(;t;){if(t._mc&&(e?e&&t._mc[e]&&r.push(t._mc[e]):r=r.concat(Object.values(t._mc)),n))return r;t=t.parentNode}return r}function c(t){return t&&t instanceof HTMLElement}function s(t,e,n={}){let r=t;if(!r._mc){let e=m?.debug;m.debug=!1,r._mc=new m(t),m.debug=e,delete r._mc._mc}const o=r._mc;return e.length&&!o[e]&&(o[e]=n,t instanceof HTMLElement&&!t.getAttribute("data-mc")&&t.setAttribute("data-mc","")),n}function a(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 i(t){return"_mc"+t[0].toUpperCase()+t.substring(1)}function u(t,e,n,r=!1){t.addEventListener(i(e),n,{capture:!1,once:r})}function l(t,e,n={},r="l"){const o="string"==typeof e?new CustomEvent(i(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&&m.trigger(t,e)}))}),0)}(t,o)}class d{_target;constructor(t,e=!1){var r;this._target=new WeakRef(t||{}),(r=this).constructor!==m&&setTimeout((()=>{r.trigger("Init")}),0),function(t){if(!n()||t.constructor===m)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(),s=e=>{n[t](e)};e["on"+c]?e.addEventListener(c,s):u(e,o,s,r)}))}}(this)}get target(){return this._target.deref()}}class m extends d{constructor(t,e=!1){super(t)}static add=s;static remove=a;static trigger=l;off(t,e){!function(t,e,n){t.removeEventListener(i(e),n)}(this.target,t,e)}on(t,e){u(this.target,t,e)}one(t,e){!function(t,e,n){u(t,e,n,!0)}(this.target,t,e)}trigger(t,e={},n="l"){}parent(t=""){let e=this.target;return c(e)?o(e.parentNode,t,!0):[]}ancestors(t=""){let e=this?.target;return c(e)?o(this.target.parentNode,t,!1):[]}children(t=""){let e=this?.target;return c(e)?r([...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);return t.removeAttribute("temp_id"),r}(e)],t):[]}descendants(t=""){let e=this?.target;return c(e)?r([...e.querySelectorAll("*[data-mc]")],t):[]}}new Set;class f 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 p(t){return"function"==typeof t&&/^class\s/.test(Function.prototype.toString.call(t))}function b(t,e,n=[]){if(customElements.get(t))return void console.warn(`IGNORED: Custom element "${t}" is already defined!`);if(!t.includes("-"))throw new Error('createCustomElement: tagName must contain at least one hyphen ("-").');let r=t.split("-").map((t=>t.charAt(0).toUpperCase()+t.slice(1))).join("");p(e.prototype.constructor)&&e.prototype instanceof d?customElements.define(t,function(t,e){return Object.defineProperty(e,"name",{value:t})}(r,class extends f{instance;constructor(t){super();const n=p(e)?new e(this,t):e;m.add(this,r,n)}static get observedAttributes(){return n}})):customElements.define(t,e)}function h(t){return customElements.get(t)}return e})()));
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- import { DC } from './MC.js';
3
+ import { DC, McBase } from './MC.js';
4
4
  import { kebabToPascal } from './helpers.js';
5
5
 
6
6
  class CeBaseClass extends HTMLElement {
@@ -9,19 +9,32 @@ class CeBaseClass extends HTMLElement {
9
9
  }
10
10
 
11
11
  connectedCallback() {
12
- (DC as any).trigger(this, 'Connected');
12
+ this.dispatchEvent( new CustomEvent('_mcConnected') );
13
+ }
14
+
15
+ connectedMoveCallback() {
16
+ this.dispatchEvent( new CustomEvent('_mcConnectedMove') );
13
17
  }
14
18
 
15
19
  disconnectedCallback() {
16
- (DC as any).trigger(this, 'Disconnected');
20
+ this.dispatchEvent( new CustomEvent('_mcDisconnected') );
17
21
  }
18
22
 
19
23
  adoptedCallback() {
20
- (DC as any).trigger(this, 'Adopted');
24
+ this.dispatchEvent( new CustomEvent('_mcAdopted') );
21
25
  }
22
26
 
23
27
  attributeChangedCallback(name: string, oldValue: any, newValue: any) {
24
- (DC as any).trigger(this, 'AttributeChanged', { name, oldValue, newValue });
28
+ this.dispatchEvent(
29
+ new CustomEvent(
30
+ '_mcAttributeChanged',
31
+ { detail: { name, oldValue, newValue } }
32
+ )
33
+ );
34
+ }
35
+
36
+ formResetCallback(){
37
+ this.dispatchEvent( new CustomEvent('_mcFormReset') );
25
38
  }
26
39
  }
27
40
 
@@ -32,9 +45,14 @@ function createNamedClass(
32
45
  return Object.defineProperty(ClassBody, 'name', { value: name });
33
46
  }
34
47
 
48
+ function isClass(func: any) {
49
+ return typeof func === 'function'
50
+ && /^class\s/.test(Function.prototype.toString.call(func));
51
+ }
52
+
35
53
  export function defineCE(
36
54
  tagName: string,
37
- DefinitionClass: { new (...args: any[]): any },
55
+ DefinitionClass: { new (...args: any[]): any } | Function,
38
56
  observedAttributes: string[] = []
39
57
  ) {
40
58
  if (customElements.get(tagName)) {
@@ -50,6 +68,27 @@ export function defineCE(
50
68
 
51
69
  let name = kebabToPascal(tagName);
52
70
 
71
+ // not a class, but a function
72
+ if ( !isClass( DefinitionClass.prototype.constructor ) ){
73
+ customElements.define(
74
+ tagName,
75
+ // @ts-ignore
76
+ DefinitionClass
77
+ );
78
+ return;
79
+ }
80
+
81
+ // a class, but not a MC
82
+ if ( !( DefinitionClass.prototype instanceof McBase ) ){
83
+ customElements.define(
84
+ tagName,
85
+ // @ts-ignore
86
+ DefinitionClass
87
+ );
88
+ return;
89
+ }
90
+
91
+ // a MC
53
92
  customElements.define(
54
93
  tagName,
55
94
  createNamedClass(
@@ -59,7 +98,11 @@ export function defineCE(
59
98
 
60
99
  constructor(data?: any) {
61
100
  super();
62
- let instance = new DefinitionClass(this, data);
101
+ // @ts-ignore
102
+ const instance = isClass( DefinitionClass )
103
+ // @ts-ignore
104
+ ? new DefinitionClass(this, data)
105
+ : DefinitionClass;
63
106
  DC.add(this, name, instance);
64
107
  }
65
108
 
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
  import { copyGettersSetters } from './helpers.js';
3
- import { DC, addListener } from './MC.js';
3
+ import { DC } from './MC.js';
4
4
  import { observe } from './observables.js';
5
5
  const getInputName = (e) => {
6
6
  return e.tagName.toLowerCase();
@@ -154,7 +154,7 @@ export function formValues(targetObject, propertyName, dom) {
154
154
  observe(targetObject, propertyName);
155
155
  copyGettersSetters(handlers, targetObject[propertyName]);
156
156
  [...dom.querySelectorAll('input, textarea, select')].forEach((input) => {
157
- addListener(input, 'input', (ev) => {
157
+ input.addEventListener('input', (ev) => {
158
158
  targetObject[propertyName].notify();
159
159
  });
160
160
  });
@@ -0,0 +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 a;(a=t[n])&&a.constructor&&a.constructor===Object?e[n]=r(t[n]):e[n]=t[n]})),e}function n(t,e=!0){let a={};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)a[e+"."+t]=r[t]}else a[e]=t[e]})),e?r(a):a}function a(t,e){return JSON.stringify(n(t))===JSON.stringify(n(e))}function s(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:()=>C});var o=new Function("try {return this===window;}catch(e){ return false;}");function i(t,e){let r=[];return t.forEach((t=>{if(t&&t instanceof HTMLElement){const n=t?._mc;!e&&n?r=r.concat(Object.values(t._mc)):e&&n&&n[e]&&r.push(n[e])}})),r}function l(t,e,r=!0){let n=[];for(;t;){if(t._mc&&(e?e&&t._mc[e]&&n.push(t._mc[e]):n=n.concat(Object.values(t._mc)),r))return n;t=t.parentNode}return n}function u(t){return t&&t instanceof HTMLElement}function f(t,e,r={}){let n=t;if(!n._mc){let e=g?.debug;g.debug=!1,n._mc=new g(t),g.debug=e,delete n._mc._mc}const a=n._mc;return e.length&&!a[e]&&(a[e]=r,t instanceof HTMLElement&&!t.getAttribute("data-mc")&&t.setAttribute("data-mc","")),r}function d(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 h(t){return"_mc"+t[0].toUpperCase()+t.substring(1)}function b(t,e,r,n=!1){t.addEventListener(h(e),r,{capture:!1,once:n})}function p(t,e,r={},n="l"){const a="string"==typeof e?new CustomEvent(h(e),{detail:{data:r,bubble:n}}):e;n.length&&n.indexOf("l")>-1&&t.dispatchEvent(a),/[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&&g.trigger(t,e)}))}),0)}(t,a)}class m{_target;constructor(t,e=!1){var r;this._target=new WeakRef(t||{}),(r=this).constructor!==g&&setTimeout((()=>{r.trigger("Init")}),0),function(t){if(!o()||t.constructor===g)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),a=t.replace(/^on[e]{0,1}/,""),s=a.toLowerCase(),c=e=>{r[t](e)};e["on"+s]?e.addEventListener(s,c):b(e,a,c,n)}))}}(this)}get target(){return this._target.deref()}}class g extends m{constructor(t,e=!1){super(t)}static add=f;static remove=d;static trigger=p;off(t,e){!function(t,e,r){t.removeEventListener(h(e),r)}(this.target,t,e)}on(t,e){b(this.target,t,e)}one(t,e){!function(t,e,r){b(t,e,r,!0)}(this.target,t,e)}trigger(t,e={},r="l"){}parent(t=""){let e=this.target;return u(e)?l(e.parentNode,t,!0):[]}ancestors(t=""){let e=this?.target;return u(e)?l(this.target.parentNode,t,!1):[]}children(t=""){let e=this?.target;return u(e)?i([...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);return t.removeAttribute("temp_id"),n}(e)],t):[]}descendants(t=""){let e=this?.target;return u(e)?i([...e.querySelectorAll("*[data-mc]")],t):[]}}function y(t){return null!=t&&"object"==typeof t}function v(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 O=[HTMLInputElement,HTMLSelectElement,HTMLTextAreaElement];class E extends g{data={};oldDisplay="";constructor(t){super(t),v(t).forEach((t=>this.data[t]="")),j(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),a=>{let s=n;r.forEach((t=>{s=s.replace(t,a[t.replace(/[\{\}]/g,"")])})),t.setAttribute(e,s)}))})),[...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=>a=>{let s=e;n.forEach((t=>{s=s.replace(t,a[t.replace(/[\{\}]/g,"")])})),this.oldDisplay?t.style=this.oldDisplay:t.removeAttribute("style"),delete this.oldDisplay,r.nodeValue=s})(r.nodeValue)),this.oldDisplay=t.getAttribute("style")||"",e&&!O.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 w={};function A(t){let e=t.constructor.name;return w[e]||function(t){const e=t.constructor,r=e.name;let a=class extends e{#e=!0;#r=[];constructor(t){super(t),this.constructor.callbacks=[],y(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(y(this.valueOf())){!function(t){var e;(e=t,[e].concat([...e.querySelectorAll("*")]).filter((t=>!!v(t).length)).filter((t=>"STYLE"!==t?.tagName)).reverse()).forEach((t=>{t?._mc?._placeholders||g.add(t,"_placeholders",new E(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&&p(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=y(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 w[r]=a,a}(t)}const j=(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(A(r))(r);Object.defineProperty(t,e,{enumerable:!0,get(){if(y(n.valueOf())){let t=structuredClone(Object.assign({},n));setTimeout(s((function(){a(structuredClone(Object.assign({},n)),t)||n.notify()}),0),0)}return n},set(t){if(typeof t==typeof n.valueOf())if(y(n.valueOf())&&n.valueOf()instanceof Array==0){let e=structuredClone(Object.assign({},n));void 0===n?.constructor?.prototype?.observe&&(n=new(A(t))(structuredClone(Object.assign({},t))),c(t,n),n.seal()),Object.assign(n,t),setTimeout(s((function(){a(structuredClone(Object.assign({},n)),e)||n.notify()}),0),0)}else{let e=n.valueOf(),r=n.callbacks;t!==e&&(n=new(A(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 S{constructor(t){}}class _ extends S{#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 k extends S{#n;constructor(t){super(t),this.#n=t}get val(){return this.#n.checked}set val(t){this.#n.checked=t}}class N extends S{#n;constructor(t){super(t),this.#n=t}get val(){return this.#n.value}set val(t){this.#n.value=t}}class x extends S{#n;#a=!1;constructor(t){super(t),this.#n=t,this.#a=t.multiple}get val(){const t=[];return[...this.#n.querySelectorAll("option")].filter((t=>t.selected)).forEach((e=>{t.push(e.value)})),this.#a?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 T extends S{#n;constructor(t){super(t),this.#n=t}get val(){return this.#n.value||""}set val(t){this.#n.value=t}}const L=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 _(t);break;case"checkbox":n=new k(t);break;default:n=new N(t)}break;case"select":n=new x(t);break;case"textarea":n=new T(t);break;default:console.warn("handler missing:",e,"for",t.tagName.toLowerCase(),t)}n&&(g.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 C(t,e,r){let n=L(r);t[e]=Object.assign({},n),j(t,e),c(n,t[e]),[...r.querySelectorAll("input, textarea, select")].forEach((r=>{r.addEventListener("input",(r=>{t[e].notify()}))}))}return e})()));
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  import { LooseObject, copyGettersSetters } from './helpers.js';
4
- import { DC, addListener } from './MC.js';
4
+ import { DC, on } from './MC.js';
5
5
  import { observe } from './observables.js';
6
6
 
7
7
  type inputTypes = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
@@ -216,8 +216,8 @@ export function formValues(
216
216
  copyGettersSetters(handlers, targetObject[propertyName]);
217
217
 
218
218
  [...dom.querySelectorAll('input, textarea, select')].forEach((input) => {
219
- addListener(input as inputTypes, 'input', (ev: Event) => {
220
- //console.log('keyup', ev);
219
+ input.addEventListener('input', (ev) => {
220
+ //console.log('input event', input, ev);
221
221
  targetObject[propertyName].notify();
222
222
  });
223
223
  });
@@ -4,10 +4,8 @@ test-child,
4
4
  test-grandchild,
5
5
  test-greatgrandchild {
6
6
  display: inline-block;
7
- padding: 2px;
7
+ padding: 1px;
8
8
  margin: 1px;
9
9
  border: 1px solid darkslategray;
10
10
  border-radius: 2px;
11
11
  }
12
-
13
- /*# sourceMappingURL=GrandParent.css.map */
@@ -1,6 +1,5 @@
1
1
  export * from './helpers.js';
2
2
  export * from './MC.js';
3
- export * from './McEvent.js';
4
3
  export * from './elements.js';
5
4
  export * from './observables.js';
6
5
  export * from './formValues.js';
@@ -1 +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"}
1
+ {"version":3,"file":"microcomponents.d.ts","sourceRoot":"","sources":["../src/microcomponents.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AAExB,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AAEjC,cAAc,iBAAiB,CAAC"}
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  export * from './helpers.js';
3
3
  export * from './MC.js';
4
- export * from './McEvent.js';
5
4
  export * from './elements.js';
6
5
  export * from './observables.js';
7
6
  export * from './formValues.js';
@@ -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((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:()=>v,autoload:()=>D,copyGettersSetters:()=>d,debounce:()=>l,deepEqual:()=>c,defineCE:()=>q,flattenObject:()=>o,formValues:()=>X,getCE:()=>$,htmlToElements:()=>u,isNativeObject:()=>r,kebabToPascal:()=>i,nameSpace:()=>s,observe:()=>Z,parse:()=>a,removeListener:()=>E,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 v(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 E(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)&&v(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",""),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 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));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=>!N.has(e)));r?.forEach((e=>{const t=L(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 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),window.autoload=window.autoload||D,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]="")),Z(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={};function R(e){let t=e.constructor.name;return J[t]||function(e){const t=e.constructor,r=t.name;let n=class extends t{#c=!0;#s=[];constructor(e){super(e),this.constructor.callbacks=[],I(e)&&Object.getOwnPropertyNames(e).forEach((t=>{this[t]=e[t]}))}get callbacks(){return this.#s}set callbacks(e){this.#s=e}observe(e){return this.#s.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.#s.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.#s.forEach((e=>{e(r)})),t}};return J[r]=n,n}(e)}const Z=(e,t)=>((t?[t]:[...Object.getOwnPropertyNames(e)]).forEach((t=>{if(e.hasOwnProperty(t)&&"function"!=typeof e[t]&&!e?.[t]?.constructor?.prototype?.observe){if("_"===t[0]||void 0===e?.[t])return e;let r=e[t],n=new(R(r))(r);Object.defineProperty(e,t,{enumerable:!0,get(){if(I(n.valueOf())){let e=structuredClone(Object.assign({},n));setTimeout(l((function(){c(structuredClone(Object.assign({},n)),e)||n.notify()}),0),0)}return n},set(e){if(typeof e==typeof n.valueOf())if(I(n.valueOf())&&n.valueOf()instanceof Array==0){let t=structuredClone(Object.assign({},n));void 0===n?.constructor?.prototype?.observe&&(n=new(R(e))(structuredClone(Object.assign({},e))),d(e,n),n.seal()),Object.assign(n,e),setTimeout(l((function(){c(structuredClone(Object.assign({},n)),t)||n.notify()}),0),0)}else{let t=n.valueOf(),r=n.callbacks;e!==t&&(n=new(R(e))(e),n.callbacks=r,n.notify())}else console.warn("IGNORED - cannot change observable types, IS:",typeof n.valueOf(),n,"- CANNOT BECOME:",typeof e)}}),e[t]=r}})),e);class z{constructor(e){}}class B extends z{#a;constructor(e){super(e),this.#a=e}get val(){return new FormData(this.#a.form).get(this.#a.name)}set val(e){[...this.#a.form.querySelectorAll(`input[type="radio"][name="${this.#a.name}"]`)].filter((t=>t.getAttribute("value")===e)).shift().checked=!0}}class U extends z{#a;constructor(e){super(e),this.#a=e}get val(){return this.#a.checked}set val(e){this.#a.checked=e}}class W extends z{#a;constructor(e){super(e),this.#a=e}get val(){return this.#a.value}set val(e){this.#a.value=e}}class Y extends z{#a;#i=!1;constructor(e){super(e),this.#a=e,this.#i=e.multiple}get val(){const e=[];return[...this.#a.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.#a.querySelectorAll("option")].forEach((t=>{e.indexOf(t.value)>-1?t.selected=!0:t.selected=!1}))}}class K extends z{#a;constructor(e){super(e),this.#a=e}get val(){return this.#a.value||""}set val(e){this.#a.value=e}}const Q=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 U(e);break;default:n=new W(e)}break;case"select":n=new Y(e);break;case"textarea":n=new K(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 X(e,t,r){let n=Q(r);e[t]=Object.assign({},n),Z(e,t),d(n,e[t]),[...r.querySelectorAll("input, textarea, select")].forEach((r=>{v(r,"input",(r=>{e[t].notify()}))}))}return t})()));
1
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.microcomponents=e():t.microcomponents=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={};function n(t){return t&&t.constructor&&t.constructor===Object}function r(t){let e={};return[...Object.keys(t)].sort().forEach((o=>{n(t[o])?e[o]=r(t[o]):e[o]=t[o]})),e}function o(t,e=!0){let n={};return[...Object.getOwnPropertyNames(t)].forEach((e=>{if(t[e]&&t[e].constructor&&t[e].constructor===Object){const r=o(t[e],!1);for(const t in r)n[e+"."+t]=r[t]}else n[e]=t[e]})),e?r(n):n}function c(t,e){return JSON.stringify(o(t))===JSON.stringify(o(e))}function s(t,e={}){let n=t.constructor===String?t.split("."):t;if(e&&n[0]&&e[n[0]])return e[n[0]].constructor===Object&&n.length>1?s(n.splice(1),e[n[0]]):e[n[0]];console.warn("ns",n[0],"not in",e)}function a(t,e){var r=Array.from(arguments);if(r.length>2){for(;r.length>1;)r[0]=a(r[0],r[1]),r.splice(1,1);return r[0]}if("string"==typeof t)t.match(/\{[^\{\}]*\}/g)?.forEach((function(n){var r=s(n.substring(1,n.length-1),e);void 0!==r&&(t=t.replace(n,r))}));else if(n(t))switch(t.constructor){case Object:Object.keys(t).forEach((function(n){t.hasOwnProperty(n)&&(t[n]=a(t[n],e))}));break;case Array:t.forEach((function(n,r,o){o[r]=a(t[r],e)}))}return t}function i(t){return t.split("-").map((t=>t.charAt(0).toUpperCase()+t.slice(1))).join("")}function l(t,e){let n;return()=>{clearTimeout(n),n=setTimeout((function(){t(...arguments)}),e)}}function u(t){let e=document.createElement("template");return t=t.replace(/<([A-Za-z0-9\-]*)([^>\/]*)(\/>)/gi,"<$1$2></$1>"),e.innerHTML=t,e.content.normalize(),Array.from(e.content.childNodes)}function d(t,e){const n=Object.getOwnPropertyDescriptors(t);for(const[t,r]of Object.entries(n))("get"in r||"set"in r)&&Object.defineProperty(e,t,r)}t.r(e),t.d(e,{DC:()=>C,MC:()=>j,McBase:()=>A,autoload:()=>x,copyGettersSetters:()=>d,debounce:()=>l,deepEqual:()=>c,defineCE:()=>D,flattenObject:()=>o,formValues:()=>K,getCE:()=>q,htmlToElements:()=>u,isNativeObject:()=>n,kebabToPascal:()=>i,nameSpace:()=>s,observe:()=>G,off:()=>v,on:()=>E,one:()=>O,parse:()=>a,sortObject:()=>r,trigger:()=>w});var f=new Function("try {return this===window;}catch(e){ return false;}");function h(t,e){let n=[];return t.forEach((t=>{if(t&&t instanceof HTMLElement){const r=t?._mc;!e&&r?n=n.concat(Object.values(t._mc)):e&&r&&r[e]&&n.push(r[e])}})),n}function m(t,e,n=!0){let r=[];for(;t;){if(t._mc&&(e?e&&t._mc[e]&&r.push(t._mc[e]):r=r.concat(Object.values(t._mc)),n))return r;t=t.parentNode}return r}function p(t){return t&&t instanceof HTMLElement}function b(t,e,n={}){let r=t;if(!r._mc){let e=C?.debug;C.debug=!1,r._mc=new C(t),C.debug=e,delete r._mc._mc}const o=r._mc;return e.length&&!o[e]&&(o[e]=n,t instanceof HTMLElement&&!t.getAttribute("data-mc")&&t.setAttribute("data-mc","")),n}function g(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 y(t){return"_mc"+t[0].toUpperCase()+t.substring(1)}function v(t,e,n){t.removeEventListener(y(e),n)}function E(t,e,n,r=!1){t.addEventListener(y(e),n,{capture:!1,once:r})}function O(t,e,n){E(t,e,n,!0)}function w(t,e,n={},r="l"){const o="string"==typeof e?new CustomEvent(y(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&&C.trigger(t,e)}))}),0)}(t,o)}class A{_target;constructor(t,e=!1){var n;this._target=new WeakRef(t||{}),(n=this).constructor!==C&&setTimeout((()=>{n.trigger("Init")}),0),function(t){if(!f()||t.constructor===C)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(),s=e=>{n[t](e)};e["on"+c]?e.addEventListener(c,s):E(e,o,s,r)}))}}(this)}get target(){return this._target.deref()}}class j extends A{constructor(t){super(t)}static trigger=w;trigger(t,e={},n="l"){}}class C extends A{constructor(t,e=!1){super(t)}static add=b;static remove=g;static trigger=w;off(t,e){v(this.target,t,e)}on(t,e){E(this.target,t,e)}one(t,e){O(this.target,t,e)}trigger(t,e={},n="l"){}parent(t=""){let e=this.target;return p(e)?m(e.parentNode,t,!0):[]}ancestors(t=""){let e=this?.target;return p(e)?m(this.target.parentNode,t,!1):[]}children(t=""){let e=this?.target;return p(e)?h([...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);return t.removeAttribute("temp_id"),r}(e)],t):[]}descendants(t=""){let e=this?.target;return p(e)?h([...e.querySelectorAll("*[data-mc]")],t):[]}}const S=new Set;function k(t){return()=>{const e=Array.from(document.querySelectorAll(`[data-mc*="${t}"]`)).filter((t=>t instanceof HTMLElement));if(0===e.length)return;const n=customElements.get(t);e.forEach((e=>{C.add(e,n.name,new n(e));const r=e.getAttribute("data-mc").split(" ").filter((e=>e!==t&&""!==e)).join(" ").trim();e.setAttribute("data-mc",r)}))}}function _(t){if(S.has(t))return;S.add(t);const e="./"+t.split("-").join("/")+".js",n=document.createElement("script");n.setAttribute("src",e),n.setAttribute("blocking","render"),n.async=!0,n.setAttribute("type","module"),n.setAttribute("data-name",t),n.setAttribute("loading",""),customElements.whenDefined(t).then(k(t)),n.addEventListener("load",(e=>{S.delete(t),document.head.querySelector(`script[data-name="${t}"]`)?.remove()})),n.addEventListener("error",(t=>{console.error("could not load DC code from",e)})),document.head.append(n)}function N(){[...document.querySelectorAll(":not(:defined)")].filter((t=>!!t&&!customElements.get(t.tagName.toLowerCase())&&!S.has(t.tagName.toLowerCase()))).forEach((t=>{_(t.tagName.toLowerCase())})),[...document.querySelectorAll('[data-mc]:not([data-mc=""]')].filter((t=>!!t)).forEach((t=>{const e=t.getAttribute("data-mc")?.split(" ").filter((t=>""!==t));e?.forEach((t=>{const e=customElements.get(t);S.has(t)||e?e&&k(t)():_(t)}))}))}let T=!1,L=null;function x(t=!0){return t?(T=t,L=new MutationObserver(N),setTimeout((()=>{L.observe(document.body,{childList:!0,subtree:!0}),N()}),5),window.autoload=window.autoload||x,T):(L?.disconnect(),L=null,T)}x.state=S;class M 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 P(t){return"function"==typeof t&&/^class\s/.test(Function.prototype.toString.call(t))}function D(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=i(t);P(e.prototype.constructor)&&e.prototype instanceof A?customElements.define(t,function(t,e){return Object.defineProperty(e,"name",{value:t})}(r,class extends M{instance;constructor(t){super();const n=P(e)?new e(this,t):e;C.add(this,r,n)}static get observedAttributes(){return n}})):customElements.define(t,e)}function q(t){return customElements.get(t)}function H(t){return null!=t&&"object"==typeof t}function V(t){let e=new Set,n=/\{[^\{\}]*\}/g;return(t.getAttributeNames?t.getAttributeNames():[]).filter((e=>t.getAttribute(e)?.match(n))).forEach((e=>{let r=new Set(t.getAttribute(e)?.match(n));r.forEach((t=>r.add(t.replace(/[\{\}]/g,""))))})),[...t.childNodes].filter((t=>3===t.nodeType&&(t.nodeValue||"").match(n))).forEach((t=>{(t.nodeValue||"").match(n).forEach((t=>{e.add(t.replace(/[\{\}]/g,""))}))})),[...e].map((t=>t.replace(/[\{\}]/g,"")))}const I=[HTMLInputElement,HTMLSelectElement,HTMLTextAreaElement];class $ extends C{data={};oldDisplay="";constructor(t){super(t),V(t).forEach((t=>this.data[t]="")),G(this),this.#t()}#t(){let t=this.target,e=!1;(t.getAttributeNames?t.getAttributeNames():[]).filter((e=>t.getAttribute(e)?.match(/\{[^\{\}]*\}/g))).forEach((e=>{let n=new Set(t.getAttribute(e)?.match(/\{[^\{\}]*\}/g));var r;this.data.observe((r=t.getAttribute(e),o=>{let c=r;n.forEach((t=>{c=c.replace(t,o[t.replace(/[\{\}]/g,"")])})),t.setAttribute(e,c)}))})),[...t.childNodes].filter((t=>3===t.nodeType&&(t.nodeValue||"").match(/\{[^\{\}]*\}/g))).forEach((n=>{e=!0;let r=new Set(n.nodeValue.match(/\{[^\{\}]*\}/g));this.data.observe((e=>o=>{let c=e;r.forEach((t=>{c=c.replace(t,o[t.replace(/[\{\}]/g,"")])})),this.oldDisplay?t.style=this.oldDisplay:t.removeAttribute("style"),delete this.oldDisplay,n.nodeValue=c})(n.nodeValue)),this.oldDisplay=t.getAttribute("style")||"",e&&!I.includes(t.constructor)&&"FIELDSET"!==t.tagName&&(t.style.display="none")}))}onData(t){let e={};Object.keys(t.detail.data).forEach((n=>{this.data.hasOwnProperty(n)&&(e[n]=t.detail.data[n])})),JSON.stringify(e)!==JSON.stringify(this.data)&&Object.assign(this.data,e)}}const R={};function F(t){let e=t.constructor.name;return R[e]||function(t){const e=t.constructor,n=e.name;let r=class extends e{#e=!0;#n=[];constructor(t){super(t),this.constructor.callbacks=[],H(t)&&Object.getOwnPropertyNames(t).forEach((e=>{this[e]=t[e]}))}get callbacks(){return this.#n}set callbacks(t){this.#n=t}observe(t){return this.#n.push(t),this}bind(t){if(H(this.valueOf())){!function(t){var e;(e=t,[e].concat([...e.querySelectorAll("*")]).filter((t=>!!V(t).length)).filter((t=>"STYLE"!==t?.tagName)).reverse()).forEach((t=>{t?._mc?._placeholders||C.add(t,"_placeholders",new $(t))}))}(t);const e=[t,...t.querySelectorAll("[data-mc]")].filter((t=>!!t?._mc?._placeholders)),n=function(t){let n=o(t);e.forEach((t=>{t&&w(t,"data",n)}))};this.#n.push(n),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=H(this.valueOf())&&this.valueOf()instanceof Array==0?structuredClone(Object.assign({},this)):this.valueOf();return void 0!==t&&(this.#e=t),this.#n.forEach((t=>{t(e)})),this}};return R[n]=r,r}(t)}const G=(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 n=t[e],r=new(F(n))(n);Object.defineProperty(t,e,{enumerable:!0,get(){if(H(r.valueOf())){let t=structuredClone(Object.assign({},r));setTimeout(l((function(){c(structuredClone(Object.assign({},r)),t)||r.notify()}),0),0)}return r},set(t){if(typeof t==typeof r.valueOf())if(H(r.valueOf())&&r.valueOf()instanceof Array==0){let e=structuredClone(Object.assign({},r));void 0===r?.constructor?.prototype?.observe&&(r=new(F(t))(structuredClone(Object.assign({},t))),d(t,r),r.seal()),Object.assign(r,t),setTimeout(l((function(){c(structuredClone(Object.assign({},r)),e)||r.notify()}),0),0)}else{let e=r.valueOf(),n=r.callbacks;t!==e&&(r=new(F(t))(t),r.callbacks=n,r.notify())}else console.warn("IGNORED - cannot change observable types, IS:",typeof r.valueOf(),r,"- CANNOT BECOME:",typeof t)}}),t[e]=n}})),t);class J{constructor(t){}}class Z extends J{#r;constructor(t){super(t),this.#r=t}get val(){return new FormData(this.#r.form).get(this.#r.name)}set val(t){[...this.#r.form.querySelectorAll(`input[type="radio"][name="${this.#r.name}"]`)].filter((e=>e.getAttribute("value")===t)).shift().checked=!0}}class z extends J{#r;constructor(t){super(t),this.#r=t}get val(){return this.#r.checked}set val(t){this.#r.checked=t}}class B extends J{#r;constructor(t){super(t),this.#r=t}get val(){return this.#r.value}set val(t){this.#r.value=t}}class U extends J{#r;#o=!1;constructor(t){super(t),this.#r=t,this.#o=t.multiple}get val(){const t=[];return[...this.#r.querySelectorAll("option")].filter((t=>t.selected)).forEach((e=>{t.push(e.value)})),this.#o?t:t.length?t[0]:""}set val(t){t="string"==typeof t?[t]:t,[...this.#r.querySelectorAll("option")].forEach((e=>{t.indexOf(e.value)>-1?e.selected=!0:e.selected=!1}))}}class W extends J{#r;constructor(t){super(t),this.#r=t}get val(){return this.#r.value||""}set val(t){this.#r.value=t}}const Y=t=>{let e=[...(t||document).querySelectorAll("input,select,textarea")],n={};return e.forEach((t=>{const e=t.getAttribute("name");if(e){let r=!1;switch((t=>t.tagName.toLowerCase())(t)){case"input":switch(t.type){case"radio":r=new Z(t);break;case"checkbox":r=new z(t);break;default:r=new B(t)}break;case"select":r=new U(t);break;case"textarea":r=new W(t);break;default:console.warn("handler missing:",e,"for",t.tagName.toLowerCase(),t)}r&&(C.add(t,e,r),Object.defineProperty(n,e,{enumerable:!0,configurable:!0,get:()=>r.val,set:t=>{r.val!==t&&(r.val=t)}}))}})),n};function K(t,e,n){let r=Y(n);t[e]=Object.assign({},r),G(t,e),d(r,t[e]),[...n.querySelectorAll("input, textarea, select")].forEach((n=>{n.addEventListener("input",(n=>{t[e].notify()}))}))}return e})()));
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  export * from './helpers.js';
3
3
  export * from './MC.js';
4
- export * from './McEvent.js';
4
+ //export * from './McEvent.js';
5
5
  export * from './elements.js';
6
6
  export * from './observables.js';
7
7
  //export * from './selectors.js';
@@ -1 +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,KAAM,IAAI,CAAC;IACrE,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;CAC3B,CAAC;AAoHF,eAAO,MAAM,OAAO,WACX,WAAW,iBACJ,MAAM,KACnB,WAuGF,CAAC"}
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;AAuKrC,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,KAAM,IAAI,CAAC;IACrE,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;CAC3B,CAAC;AAyHF,eAAO,MAAM,OAAO,WACX,WAAW,iBACJ,MAAM,KACnB,WAuGF,CAAC"}
@@ -1,17 +1,16 @@
1
1
  'use strict';
2
2
  import { debounce, deepEqual, flattenObject, copyGettersSetters, } from './helpers.js';
3
- import { DC } from './MC.js';
3
+ import { DC, trigger } from './MC.js';
4
4
  function isObservableObject(value) {
5
5
  return value != null && typeof value === 'object';
6
6
  }
7
7
  function getPlaceholders(target) {
8
8
  let placeholders = new Set(), regEx = /\{[^\{\}]*\}/g;
9
- target
10
- .getAttributeNames()
9
+ (!!target.getAttributeNames ? target.getAttributeNames() : [])
11
10
  .filter((attr) => target.getAttribute(attr)?.match(regEx))
12
11
  .forEach((attr) => {
13
- let phs = new Set(target.getAttribute(attr)?.match(regEx));
14
- phs.forEach((placeholder) => placeholders.add(placeholder.replace(/[\{\}]/g, '')));
12
+ let placeholders = new Set(target.getAttribute(attr)?.match(regEx));
13
+ placeholders.forEach((placeholder) => placeholders.add(placeholder.replace(/[\{\}]/g, '')));
15
14
  });
16
15
  [...target.childNodes]
17
16
  .filter((childNode) => {
@@ -33,22 +32,19 @@ class Placeholders extends DC {
33
32
  oldDisplay = '';
34
33
  constructor(target) {
35
34
  super(target);
36
- let that = this;
37
- getPlaceholders(target).forEach((property) => (that.data[property] = ''));
38
- observe(that);
39
- that.#attachCallbacks();
40
- delete that._mc;
35
+ getPlaceholders(target).forEach((property) => (this.data[property] = ''));
36
+ observe(this);
37
+ this.#attachCallbacks();
41
38
  }
42
39
  #attachCallbacks() {
43
- let that = this, target = that.target, hide = false;
44
- target
45
- .getAttributeNames()
40
+ let target = this.target, hide = false;
41
+ (!!target.getAttributeNames ? target.getAttributeNames() : [])
46
42
  .filter((attr) => target.getAttribute(attr)?.match(/\{[^\{\}]*\}/g))
47
43
  .forEach((attr) => {
48
- let phs = new Set(target.getAttribute(attr)?.match(/\{[^\{\}]*\}/g));
49
- that.data.observe(((template) => (data) => {
44
+ let placeholders = new Set(target.getAttribute(attr)?.match(/\{[^\{\}]*\}/g));
45
+ this.data.observe(((template) => (data) => {
50
46
  let result = template;
51
- phs.forEach((placeholder) => {
47
+ placeholders.forEach((placeholder) => {
52
48
  result = result.replace(placeholder, data[placeholder.replace(/[\{\}]/g, '')]);
53
49
  });
54
50
  target.setAttribute(attr, result);
@@ -61,26 +57,22 @@ class Placeholders extends DC {
61
57
  })
62
58
  .forEach((childNode) => {
63
59
  hide = true;
64
- let phs = new Set(childNode.nodeValue.match(/\{[^\{\}]*\}/g));
65
- that.data.observe(((template) => (data) => {
60
+ let placeholders = new Set(childNode.nodeValue.match(/\{[^\{\}]*\}/g));
61
+ this.data.observe(((template) => (data) => {
66
62
  let result = template;
67
- phs.forEach((placeholder) => {
63
+ placeholders.forEach((placeholder) => {
68
64
  result = result.replace(placeholder, data[placeholder.replace(/[\{\}]/g, '')]);
69
65
  });
70
- if (Object.keys(data).some((key) => {
71
- return !!data[key];
72
- })) {
73
- if (!!that.oldDisplay) {
74
- target.style = that.oldDisplay;
75
- }
76
- else {
77
- target.removeAttribute('style');
78
- }
79
- delete that.oldDisplay;
66
+ if (!!this.oldDisplay) {
67
+ target.style = this.oldDisplay;
80
68
  }
69
+ else {
70
+ target.removeAttribute('style');
71
+ }
72
+ delete this.oldDisplay;
81
73
  childNode.nodeValue = result;
82
74
  })(childNode.nodeValue));
83
- that.oldDisplay = target.getAttribute('style)') || '';
75
+ this.oldDisplay = target.getAttribute('style') || '';
84
76
  if (hide &&
85
77
  !inputs.includes(target.constructor) &&
86
78
  target.tagName !== 'FIELDSET') {
@@ -89,20 +81,21 @@ class Placeholders extends DC {
89
81
  });
90
82
  }
91
83
  onData(ev) {
92
- let that = this, data = {};
93
- Object.keys(ev.data).forEach((key) => {
94
- if (that.data.hasOwnProperty(key))
95
- data[key] = ev.data[key];
84
+ let data = {};
85
+ Object.keys(ev.detail.data).forEach((key) => {
86
+ if (this.data.hasOwnProperty(key))
87
+ data[key] = ev.detail.data[key];
96
88
  });
97
- if (JSON.stringify(data) !== JSON.stringify(that.data))
98
- Object.assign(that.data, data);
89
+ if (JSON.stringify(data) !== JSON.stringify(this.data))
90
+ Object.assign(this.data, data);
99
91
  }
100
92
  }
101
93
  function getPlaceholderElements(target) {
102
- let elements = (target instanceof HTMLElement ? [target] : [])
94
+ let elements = [target]
103
95
  .concat([...target.querySelectorAll('*')])
104
96
  .filter((e) => !!getPlaceholders(e).length)
105
- .filter((e) => e.tagName !== 'STYLE');
97
+ .filter((e) => e?.tagName !== 'STYLE')
98
+ .reverse();
106
99
  return elements;
107
100
  }
108
101
  function makePlaceholders(element) {
@@ -133,45 +126,47 @@ function makeObservable(val) {
133
126
  set callbacks(callbacks) {
134
127
  this.#callbacks = callbacks;
135
128
  }
136
- observe(f) {
137
- this.#callbacks.push(f);
129
+ observe(callback) {
130
+ this.#callbacks.push(callback);
138
131
  return this;
139
132
  }
140
133
  bind(target) {
141
- const that = this, iso = isObservableObject(that.valueOf());
134
+ const iso = isObservableObject(this.valueOf());
142
135
  if (iso) {
143
136
  makePlaceholders(target);
144
137
  const placeholders = [
145
- ...target.querySelectorAll('[_mc]'),
146
- ].filter((e) => !!e?._mc?._placeholders);
138
+ target,
139
+ ...target.querySelectorAll('[data-mc]'),
140
+ ]
141
+ .filter((e) => !!e?._mc?._placeholders);
147
142
  const func = function callback(data) {
148
- let d = flattenObject(data);
149
- placeholders.forEach((e) => {
150
- if (!e)
143
+ let flattenedData = flattenObject(data);
144
+ placeholders.forEach((node) => {
145
+ if (!node)
151
146
  return;
152
- e._mc.trigger('data', d);
147
+ trigger(node, 'data', flattenedData);
153
148
  });
154
149
  };
155
- that.#callbacks.push(func);
156
- that.notify();
150
+ this.#callbacks.push(func);
151
+ this.notify();
157
152
  }
158
153
  else {
159
- console.warn('IGNORED - cannot bind a non-Object to the dom, IS:', typeof that.valueOf(), that);
154
+ console.warn('IGNORED - cannot bind a non-Object to the dom, IS:', typeof this.valueOf(), this);
160
155
  }
161
156
  return this;
162
157
  }
163
158
  notify(notify) {
164
- let that = this, data = isObservableObject(that.valueOf()) &&
165
- that.valueOf() instanceof Array === false
166
- ? structuredClone(Object.assign({}, that))
167
- : that.valueOf();
159
+ let data = isObservableObject(this.valueOf()) &&
160
+ this.valueOf() instanceof Array === false
161
+ ? structuredClone(Object.assign({}, this))
162
+ : this.valueOf();
168
163
  if (notify !== undefined) {
169
- that.#notify = notify;
164
+ this.#notify = notify;
170
165
  }
171
- that.#callbacks.forEach((f) => {
166
+ this.#callbacks.forEach((f) => {
172
167
  f(data);
173
168
  });
174
- return that;
169
+ return this;
175
170
  }
176
171
  };
177
172
  classRepo[ConstructorName] = ObservableClass;
@@ -0,0 +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.observables=e():t.observables=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 o;(o=t[n])&&o.constructor&&o.constructor===Object?e[n]=r(t[n]):e[n]=t[n]})),e}function n(t,e=!0){let o={};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)o[e+"."+t]=r[t]}else o[e]=t[e]})),e?r(o):o}function o(t,e){return JSON.stringify(n(t))===JSON.stringify(n(e))}function c(t,e){let r;return()=>{clearTimeout(r),r=setTimeout((function(){t(...arguments)}),e)}}t.r(e),t.d(e,{observe:()=>A});var a=new Function("try {return this===window;}catch(e){ return false;}");function s(t,e){let r=[];return t.forEach((t=>{if(t&&t instanceof HTMLElement){const n=t?._mc;!e&&n?r=r.concat(Object.values(t._mc)):e&&n&&n[e]&&r.push(n[e])}})),r}function i(t,e,r=!0){let n=[];for(;t;){if(t._mc&&(e?e&&t._mc[e]&&n.push(t._mc[e]):n=n.concat(Object.values(t._mc)),r))return n;t=t.parentNode}return n}function l(t){return t&&t instanceof HTMLElement}function u(t,e,r={}){let n=t;if(!n._mc){let e=g?.debug;g.debug=!1,n._mc=new g(t),g.debug=e,delete n._mc._mc}const o=n._mc;return e.length&&!o[e]&&(o[e]=r,t instanceof HTMLElement&&!t.getAttribute("data-mc")&&t.setAttribute("data-mc","")),r}function f(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 d(t){return"_mc"+t[0].toUpperCase()+t.substring(1)}function b(t,e,r,n=!1){t.addEventListener(d(e),r,{capture:!1,once:n})}function h(t,e,r={},n="l"){const o="string"==typeof e?new CustomEvent(d(e),{detail:{data:r,bubble:n}}):e;n.length&&n.indexOf("l")>-1&&t.dispatchEvent(o),/[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&&g.trigger(t,e)}))}),0)}(t,o)}class p{_target;constructor(t,e=!1){var r;this._target=new WeakRef(t||{}),(r=this).constructor!==g&&setTimeout((()=>{r.trigger("Init")}),0),function(t){if(!a()||t.constructor===g)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),o=t.replace(/^on[e]{0,1}/,""),c=o.toLowerCase(),a=e=>{r[t](e)};e["on"+c]?e.addEventListener(c,a):b(e,o,a,n)}))}}(this)}get target(){return this._target.deref()}}class g extends p{constructor(t,e=!1){super(t)}static add=u;static remove=f;static trigger=h;off(t,e){!function(t,e,r){t.removeEventListener(d(e),r)}(this.target,t,e)}on(t,e){b(this.target,t,e)}one(t,e){!function(t,e,r){b(t,e,r,!0)}(this.target,t,e)}trigger(t,e={},r="l"){}parent(t=""){let e=this.target;return l(e)?i(e.parentNode,t,!0):[]}ancestors(t=""){let e=this?.target;return l(e)?i(this.target.parentNode,t,!1):[]}children(t=""){let e=this?.target;return l(e)?s([...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);return t.removeAttribute("temp_id"),n}(e)],t):[]}descendants(t=""){let e=this?.target;return l(e)?s([...e.querySelectorAll("*[data-mc]")],t):[]}}function m(t){return null!=t&&"object"==typeof t}function y(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 O=[HTMLInputElement,HTMLSelectElement,HTMLTextAreaElement];class v extends g{data={};oldDisplay="";constructor(t){super(t),y(t).forEach((t=>this.data[t]="")),A(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),o=>{let c=n;r.forEach((t=>{c=c.replace(t,o[t.replace(/[\{\}]/g,"")])})),t.setAttribute(e,c)}))})),[...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=>o=>{let c=e;n.forEach((t=>{c=c.replace(t,o[t.replace(/[\{\}]/g,"")])})),this.oldDisplay?t.style=this.oldDisplay:t.removeAttribute("style"),delete this.oldDisplay,r.nodeValue=c})(r.nodeValue)),this.oldDisplay=t.getAttribute("style")||"",e&&!O.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 E={};function j(t){let e=t.constructor.name;return E[e]||function(t){const e=t.constructor,r=e.name;let o=class extends e{#e=!0;#r=[];constructor(t){super(t),this.constructor.callbacks=[],m(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(m(this.valueOf())){!function(t){var e;(e=t,[e].concat([...e.querySelectorAll("*")]).filter((t=>!!y(t).length)).filter((t=>"STYLE"!==t?.tagName)).reverse()).forEach((t=>{t?._mc?._placeholders||g.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=m(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 E[r]=o,o}(t)}const A=(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(j(r))(r);Object.defineProperty(t,e,{enumerable:!0,get(){if(m(n.valueOf())){let t=structuredClone(Object.assign({},n));setTimeout(c((function(){o(structuredClone(Object.assign({},n)),t)||n.notify()}),0),0)}return n},set(t){if(typeof t==typeof n.valueOf())if(m(n.valueOf())&&n.valueOf()instanceof Array==0){let e=structuredClone(Object.assign({},n));void 0===n?.constructor?.prototype?.observe&&(n=new(j(t))(structuredClone(Object.assign({},t))),function(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,n),n.seal()),Object.assign(n,t),setTimeout(c((function(){o(structuredClone(Object.assign({},n)),e)||n.notify()}),0),0)}else{let e=n.valueOf(),r=n.callbacks;t!==e&&(n=new(j(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);return e})()));