@twobirds/microcomponents 0.2.0 → 0.2.2

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 (38) hide show
  1. package/README.md +27 -38
  2. package/dist/MC.min.js +1 -1
  3. package/dist/autoload.min.js +1 -1
  4. package/dist/core/MC.d.ts +5 -2
  5. package/dist/core/MC.d.ts.map +1 -1
  6. package/dist/core/MC.js +52 -4
  7. package/dist/core/elements.d.ts +186 -100
  8. package/dist/core/elements.d.ts.map +1 -1
  9. package/dist/core/elements.js +186 -17
  10. package/dist/core/mcGuards.d.ts +1 -0
  11. package/dist/core/mcGuards.d.ts.map +1 -1
  12. package/dist/core/mcGuards.js +0 -10
  13. package/dist/elements.min.js +1 -1
  14. package/dist/events.min.js +1 -1
  15. package/dist/formValues.min.js +1 -1
  16. package/dist/microcomponents.d.ts +2 -2
  17. package/dist/microcomponents.d.ts.map +1 -1
  18. package/dist/microcomponents.js +2 -2
  19. package/dist/microcomponents.min.js +1 -1
  20. package/dist/observables.min.js +1 -1
  21. package/dist/state/formValues.d.ts +111 -66
  22. package/dist/state/formValues.d.ts.map +1 -1
  23. package/dist/state/formValues.js +132 -68
  24. package/dist/state/observables.d.ts +68 -83
  25. package/dist/state/observables.d.ts.map +1 -1
  26. package/dist/state/observables.js +124 -84
  27. package/dist/utils/autoload.d.ts.map +1 -0
  28. package/dist/{core → utils}/autoload.js +2 -2
  29. package/dist/{core → utils}/events.d.ts +22 -0
  30. package/dist/utils/events.d.ts.map +1 -0
  31. package/dist/{core → utils}/events.js +26 -1
  32. package/dist/utils/helpers.d.ts +105 -20
  33. package/dist/utils/helpers.d.ts.map +1 -1
  34. package/dist/utils/helpers.js +210 -25
  35. package/package.json +12 -11
  36. package/dist/core/autoload.d.ts.map +0 -1
  37. package/dist/core/events.d.ts.map +0 -1
  38. /package/dist/{core → utils}/autoload.d.ts +0 -0
@@ -1,48 +1,217 @@
1
1
  /**
2
- * @module Web Components
3
- *
2
+ * # Custom Elements
3
+ * ---
4
4
  * Defines micro component integration with native web components and the CustomElementRegistry.
5
- *
6
5
  * This module provides utilities for defining custom HTML elements using the native Web Components API.
7
6
  *
8
7
  * ---
9
- *
10
8
  * The {@link defineCE} function handles registration of custom elements with the CustomElementRegistry,
11
9
  * automatically attaching the provided class as a DC instance ( micro component ) to the native web component created.
12
10
  * This class and any DC instances added to the web component later will receive all web component native events.
13
11
  * Only the class that defines the WC also defines its observed attributes, but all inner DCs get the changed event.
14
- *
15
12
  * The {@link getCE} function is just a wrapper for customElements.get()
16
13
  *
17
- * @example
14
+ * ## Hints:
15
+ * - Your micro component must extend DC, since it is a DOM element
16
+ * - Method names that look like event handlers are DOM - or custom event handlers ( 'onClick()', 'oneSomething()' )
17
+ * - Event handlers defined as methods will be assigned to the DOM automatically
18
+ * - Micro components trigger an `init` event on themself after the constructor has run. The method `.oneInit()` catches this lifecycle event.
18
19
  *
19
- * code:
20
- * ```javascript
21
- * // create a custom micro component class
22
- * class MyComponent extends DC{
20
+ * ---
21
+ *
22
+ * @module elements
23
+ *
24
+ * ## Examples:
25
+ *
26
+ * @example define a custom component, minimum code
23
27
  *
28
+ * javascript:
29
+ * ```javascript
30
+ * class MyElement extends DC {
24
31
  * constructor( target ){
25
- * super( target );
32
+ * super(target);
26
33
  * }
27
- *
28
34
  * }
29
35
  *
30
- * defineCE( 'my-component', MyComponent );
36
+ * defineCE( 'my-element', MyElement );
31
37
  * ```
32
38
  *
33
39
  * afterwards you can use ...
40
+ *
41
+ * html:
34
42
  * ```HTML
35
- * <my-component></my-component>
43
+ * <my-element></my-element>
36
44
  * ```
37
45
  * ... in your template.
38
46
  *
39
- * Or you can construct it programmatically:
47
+ * Or you can construct it programmatically using {@link getCE}:
48
+ *
49
+ * javascript:
40
50
  * ```javascript
41
- * const myComponentClass = getCE('my-component');
51
+ * const MyElementClass = getCE('my-element');
42
52
  * const body = document.body;
43
- * body.append( new myComponentClass() );
53
+ * body.append( new MyElementClass() );
54
+ * ```
55
+ *
56
+ * ---
57
+ * @example define a custom component with standard and/or custom event handlers
58
+ *
59
+ * javascript:
60
+ * ```javascript
61
+ * class MyElement extends DC {
62
+ *
63
+ * constructor( target ){
64
+ * super(target);
65
+ * }
66
+ *
67
+ * // DOM web component event handler
68
+ * onConnected() {
69
+ * this.innerHTML = '<p>Hi!</p>';
70
+ * }
71
+ *
72
+ * // DOM standard event handler
73
+ * onClick(){
74
+ * this.trigger('something', { data: 'do something' } );
75
+ * }
76
+ *
77
+ * // DOM custom event handler
78
+ * oneSomething(ev){
79
+ * // do only once! Subsequent clicks will not trigger this handler
80
+ * console.log('something happens here:', ev.detail.data );
81
+ * }
82
+ * }
83
+ * defineCE( 'my-element', MyElement );
84
+ * ```
85
+ *
86
+ * ## Static properties
87
+ *
88
+ * DC classes support some static properties that configure the custom element
89
+ * before any instance is constructed. These are applied automatically by `defineCE`
90
+ * during element creation.
91
+ *
92
+ * ---
93
+ * @example static tag
94
+ * - replaces the default `target` element with a semantic HTML element:
95
+ *
96
+ * html before:
97
+ * ```html
98
+ * <shop-header></shop-header>
99
+ * ```
100
+ * javascript:
101
+ * ```javascript
102
+ * class ShopHeader extends DC {
103
+ * static tag = 'header';
104
+ * constructor(target) {
105
+ * super(target);
106
+ * }
107
+ * }
108
+ * defineCE('shop-header', ShopHeader);
109
+ * ```
110
+ *
111
+ * html after:
112
+ * ```html
113
+ * <header></header>
114
+ * ```
115
+ *
116
+ * The resulting DOM node is a `<header>` element instead of a generic template.
117
+ *
118
+ * ---
119
+ * @example static assets
120
+ * - declares companion files for auto-load and bundling by convention:
121
+ *
122
+ * javascript:
123
+ * ```javascript
124
+ * class CartContainerCheckout extends DC {
125
+ * static assets = ['targetHtml', 'targetCss'];
126
+ * constructor(target) {
127
+ * super(target);
128
+ * }
129
+ * oneAssets() {
130
+ * this.setupBehaviour();
131
+ * }
132
+ * }
133
+ * defineCE('cart-container-checkout', CartContainerCheckout);
134
+ * ```
135
+ *
136
+ * The framework resolves `targetHtml` → `checkout.target.html` and
137
+ * `targetCss` → `checkout.target.css`, injects them into the element, and fires
138
+ * the `_mcAssets` event so that `oneAssets()` runs.
139
+ *
140
+ * ---
141
+ * @example static attributes
142
+ * - sets HTML attributes on every instance:
143
+ *
144
+ * javascript:
145
+ * ```javascript
146
+ * class ProductCard extends DC {
147
+ * static attributes = { role: 'listitem' };
148
+ * constructor(target, data) {
149
+ * super(target);
150
+ * }
151
+ * }
152
+ * defineCE('product-card', ProductCard);
44
153
  * ```
154
+ *
155
+ * Every `<product-card>` element carries the attribute `role="listitem"` automatically:
156
+ *
157
+ * html after:
158
+ * ```html
159
+ * <product-card role="listitem"></product-card>
160
+ * ```
161
+ *
45
162
  * ---
163
+ * @example
164
+ * - All three can be combined in one class:
165
+ *
166
+ * javascript:
167
+ * ```javascript
168
+ * class ShopCatalog extends DC {
169
+ * static tag = 'section';
170
+ * static attributes = { role: 'list', 'aria-label': 'products' };
171
+ * static assets = ['targetHtml', 'targetCss'];
172
+ * constructor(target) {
173
+ * super(target);
174
+ * }
175
+ * }
176
+ * defineCE('shop-catalog', ShopCatalog);
177
+ * ```
178
+ *
179
+ * Produces a `<section role="list" aria-label="products">` host element.
180
+ *
181
+ * ---
182
+ * @example Creating a user defined built-in element (customized built-in element)
183
+ * **Hint:**
184
+ * - This is **DEPRECATED** in the standard. See [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements#customized_built-in_elements). Use this only if you know what you are doing.
185
+ * - This can be archieved in a safe way using the `static tag: 'aside';` property on your class.
186
+ *
187
+ * javascript:
188
+ * ```javascript
189
+ * class MyButton extends DC {
190
+ * constructor(target) {
191
+ * super(target);
192
+ * }
193
+ * onConnected() {
194
+ * this.textContent = 'Click me!';
195
+ * }
196
+ * }
197
+ * defineCE('my-button', MyButton, [], 'button');
198
+ * ```
199
+ *
200
+ * afterwards you can use it in your template with the `is` attribute:
201
+ *
202
+ * html:
203
+ * ```html
204
+ * <button is="my-button"></button>
205
+ * ```
206
+ *
207
+ *
208
+ * Or you can construct it programmatically using {@link getCE}:
209
+ * javascript:
210
+ * ```javascript
211
+ * const MyButtonClass = getCE('my-button');
212
+ * const body = document.body;
213
+ * body.append( new MyButtonClass() );
214
+ * ```
46
215
  */
47
216
  import { kebabToPascal } from '../utils/helpers.js';
48
217
  import { McBase, DC } from './MC.js';
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  @module Guards
3
+ @hidden
3
4
 
4
5
  Type guards for microcomponent hosts.
5
6
 
@@ -1 +1 @@
1
- {"version":3,"file":"mcGuards.d.ts","sourceRoot":"","sources":["../../src/core/mcGuards.ts"],"names":[],"mappings":"AAAA;;;;;;;;;EASE;AAEF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgCE;AACF,wBAAgB,OAAO,CAAC,CAAC,SAAS,WAAW,EAAE,CAAC,SAAS,MAAM,UAAU,GAAG,MAAM,EACjF,OAAO,EAAE,CAAC,EACV,GAAG,EAAE,CAAC,GACJ,OAAO,IAAI,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC;AAC7C,wBAAgB,OAAO,CAAC,CAAC,SAAS,MAAM,UAAU,GAAG,MAAM,EAC1D,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,CAAC,GACJ,OAAO,IAAI,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC;AACvD,wBAAgB,OAAO,CAAC,CAAC,SAAS,WAAW,EAAE,OAAO,EAAE,CAAC,GAAG,OAAO,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC;AACjF,wBAAgB,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI,MAAM,CAAC"}
1
+ {"version":3,"file":"mcGuards.d.ts","sourceRoot":"","sources":["../../src/core/mcGuards.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AACF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAElD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAgCE;AACF,wBAAgB,OAAO,CAAC,CAAC,SAAS,WAAW,EAAE,CAAC,SAAS,MAAM,UAAU,GAAG,MAAM,EACjF,OAAO,EAAE,CAAC,EACV,GAAG,EAAE,CAAC,GACJ,OAAO,IAAI,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC;AAC7C,wBAAgB,OAAO,CAAC,CAAC,SAAS,MAAM,UAAU,GAAG,MAAM,EAC1D,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,CAAC,GACJ,OAAO,IAAI,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC;AACvD,wBAAgB,OAAO,CAAC,CAAC,SAAS,WAAW,EAAE,OAAO,EAAE,CAAC,GAAG,OAAO,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC;AACjF,wBAAgB,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI,MAAM,CAAC"}
@@ -1,13 +1,3 @@
1
- /**
2
- @module Guards
3
-
4
- Type guards for microcomponent hosts.
5
-
6
- This module deliberately contains nothing but the guard: it imports types only,
7
- executes no module-level code, and never touches the DC/autoload machinery in
8
- MC.ts — so re-query sites all over an app can import the predicate and a
9
- bundler can tree-shake everything else away.
10
- */
11
1
  export function isMcDOM(element, key) {
12
2
  return (
13
3
  // `typeof` first: in DOM-less runtimes (server-side MC) the global does
@@ -1 +1 @@
1
- function e(e){return e.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``)}function t(e,t){let n=t.toLowerCase();return`on`+n in e?n:`_mc`+t[0].toUpperCase()+t.substring(1)}function n(e,r,i){if(e){if(typeof e==`string`){document.querySelectorAll(e).forEach(e=>n(e,r,i));return}e.removeEventListener(t(e,r),i)}}function r(e,n,i,a=!1){if(e){if(typeof e==`string`){document.querySelectorAll(e).forEach(e=>r(e,n,i));return}return e.addEventListener(t(e,n),i,{capture:!1,once:a}),i}}function i(e,t,n){if(e){if(typeof e==`string`){document.querySelectorAll(e).forEach(e=>i(e,t,n));return}return r(e,t,n,!0),n}}var a=class{stopped=!1;constructor(){}stop(){this.stopped=!0}};function o(e,n,r={},i=`l`,s){if(!e)return;if(typeof e==`string`){document.querySelectorAll(e).forEach(e=>o(e,n,r,i));return}let c=/^_mc/.test(n)?n:t(e,n),l=s||new a,u=new CustomEvent(c,{detail:{data:r,control:l},bubbles:!1});l.stopped||/l/.test(i)&&(e.dispatchEvent(u),l.stopped)||/[ud]/.test(i)&&queueMicrotask(()=>{if(i.indexOf(`u`)>-1&&o(e.parentElement,c,r,`lu`,l),i.indexOf(`d`)>-1)for(let t of e.children)o(t,c,r,`ld`)})}function s(e,t){return typeof HTMLElement<`u`&&e instanceof HTMLElement&&`_mc`in e&&(t===void 0||t in e._mc)}function c(e,t,n={}){let r=e;`_mc`in e||(r._mc=new h(e));let i=r._mc;return t.length&&!i[t]&&(i[t]=n,e instanceof HTMLElement&&!e.getAttribute(`data-mc`)&&e.setAttribute(`data-mc`,``)),r}function l(e,t){if(!t)return;let n=e._mc;n&&(n[t]&&delete n[t],!Object.keys(n).length&&e instanceof HTMLElement&&e.hasAttribute(`data-mc`)&&e.removeAttribute(`data-mc`))}function u(e){queueMicrotask(()=>{e.trigger(`Init`)})}function d(e){let t=e.target,n=Object.getPrototypeOf(e),i=e,a=Object.getOwnPropertyNames(n).filter(e=>/^(on[A-Z]|one[A-Z])/.test(e)&&typeof n[e]==`function`);for(let e of a){let n=/^one/.test(e);r(t,e.replace(/^one?/,``),t=>i[e](t),n)}}function f(e){return Array.from(e.querySelectorAll(`[data-mc]:not(:scope [data-mc] [data-mc])`)).filter(e=>e instanceof HTMLElement&&`_mc`in e).map(e=>e._mc)}function p(e,t){let n=e.parentElement?.closest(`[data-mc]`);for(;n instanceof HTMLElement;){if(`_mc`in n){let e=n._mc;if(t===void 0||t in e)return e}n=n.parentElement?.closest(`[data-mc]`)}return null}var m=class{_target;constructor(e){this._target=new WeakRef(e||{}),this instanceof h&&(d(this),u(this))}get target(){return this._target.deref()}},h=class extends m{constructor(e){super(e)}static add(e,t,n={}){return c(e,t,n)}static remove(e,t){l(e,t)}static get(e,t,n){if(!s(e))return;let r=e._mc[t];return r instanceof n?r:void 0}off(e,t){n(this.target,e,t)}on(e,t){return r(this.target,e,t)}one(e,t){return i(this.target,e,t)}trigger(e,t={},n=`l`,r){o(this.target,e,t,n,r)}ancestors(e){let t=[],n=p(this.target,e);for(;n;)t.push(n),n=p(n.target,e);return t}closest(e){return p(this.target,e)}children(e){let t=f(this.target);return e===void 0?t:t.filter(t=>e in t)}descendants(e){return Array.from(this.target.querySelectorAll(`[data-mc]`)).filter(e=>e instanceof HTMLElement&&`_mc`in e).map(e=>e._mc).filter(t=>e===void 0||e in t)}};function g(e,t){return Object.defineProperty(t,"name",{value:e})}function _(e){return class extends e{constructor(...e){super(...e)}}}function v(t,n,r=[],i){if(customElements.get(t)){console.warn(`IGNORED: Custom element "${t}" is already defined!`);return}if(!t.includes(`-`))throw Error(`createCustomElement: tagName must contain at least one hyphen ("-").`);let a=HTMLElement;i&&(a=document.createElement(i).constructor);let o=e(t);if(!(n.prototype instanceof m))return customElements.define(t,n),n;let s=g(o,class extends _(a){constructor(e){super(),h.add(this,o,new n(this,e))}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(e,t,n){this.dispatchEvent(new CustomEvent(`_mcAttributeChanged`,{detail:{name:e,oldValue:t,newValue:n}}))}formResetCallback(){this.dispatchEvent(new CustomEvent(`_mcFormReset`))}static get observedAttributes(){return[...r]}});return customElements.define(t,s,{extends:i}),s}function y(e){return customElements.get(e)}export{v as defineCE,y as getCE};
1
+ function e(e,t){let n=t.toLowerCase();return`on`+n in e?n:`_mc`+t[0].toUpperCase()+t.substring(1)}function t(n,r,i){if(n){if(typeof n==`string`){document.querySelectorAll(n).forEach(e=>t(e,r,i));return}n.removeEventListener(e(n,r),i)}}function n(t,r,i,a=!1){if(t){if(typeof t==`string`){document.querySelectorAll(t).forEach(e=>n(e,r,i));return}return t.addEventListener(e(t,r),i,{capture:!1,once:a}),i}}function r(e,t,i){if(e){if(typeof e==`string`){document.querySelectorAll(e).forEach(e=>r(e,t,i));return}return n(e,t,i,!0),i}}var i=class{stopped=!1;constructor(){}stop(){this.stopped=!0}};function a(t,n,r={},o=`l`,s){if(!t)return;if(typeof t==`string`){document.querySelectorAll(t).forEach(e=>a(e,n,r,o));return}let c=/^_mc/.test(n)?n:e(t,n),l=s||new i,u=new CustomEvent(c,{detail:{data:r,control:l},bubbles:!1});l.stopped||/l/.test(o)&&(t.dispatchEvent(u),l.stopped)||/[ud]/.test(o)&&queueMicrotask(()=>{if(o.indexOf(`u`)>-1&&a(t.parentElement,c,r,`lu`,l),o.indexOf(`d`)>-1)for(let e of t.children)a(e,c,r,`ld`)})}function o(e){return e.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``)}function s(e,t){let n=new CSSStyleSheet;return n.replaceSync(t),e.adoptedStyleSheets.push(n),n}function c(e,t){let n=e.target,r=n.shadowRoot;!r&&Object.keys(t).some(e=>e.indexOf(`shadow`)===0)&&(r=n.attachShadow({mode:`open`})),Object.keys(t).forEach(i=>{switch(i){case`css`:s(document,t[i]);break;case`targetCss`:s(document,t[i]);break;case`shadowCss`:s(r,t[i]);break;case`shadowHtml`:r.innerHTML=t[i],u(r,e);break;case`targetHtml`:n.innerHTML=t[i],u(n,e);break}})}function l(e,t){let n=t=>{let n=t.match(/^([a-z]+)([A-Z][a-z]*)$/);return n?`./${e.replace(/-/g,`/`)}.${n[1]}.${n[2].toLowerCase()}`:`./${e.replace(/-/g,`/`)}.${t.toLowerCase()}`};return Promise.all(t.map(async e=>{let t=n(e);try{let n=await fetch(t);if(!n.ok)return`file not found: ${t}`;if(t.endsWith(`json`)){let r=await n.text();try{return JSON.parse(r)}catch{return console.error(`could not JSON.parse() asset '${e}' from ${t}:\n`,r),null}}return n.text()}catch{return`file not found: ${t}`}}))}function u(e,t){let r=[...e.querySelectorAll(`*`)];for(let e of r){if(!(e instanceof HTMLElement))continue;let r=[...e.attributes];for(let i of r){let r=i.name.toLowerCase();if(!(`on`+r in e))continue;let o=i.value.trim().split(`|`);if(o.length<2)continue;let[s,c,l]=o;e.removeAttribute(i.name);let u;if(l)try{u=JSON.parse(l)}catch{u=l}s===`this`||s===``?n(e,r,()=>t.trigger(c,u)):n(e,r,()=>a(s,c,u))}}}function d(e,t){return typeof HTMLElement<`u`&&e instanceof HTMLElement&&`_mc`in e&&(t===void 0||t in e._mc)}function f(e,t,n={}){let r=e;`_mc`in e||(r._mc=new y(e));let i=r._mc;return t.length&&!i[t]&&(i[t]=n,e instanceof HTMLElement&&!e.getAttribute(`data-mc`)&&e.setAttribute(`data-mc`,``)),r}function p(e,t){if(!t)return;let n=e._mc;n&&(n[t]&&delete n[t],!Object.keys(n).length&&e instanceof HTMLElement&&e.hasAttribute(`data-mc`)&&e.removeAttribute(`data-mc`))}function m(e){queueMicrotask(()=>{e.trigger(`Init`,null)})}function h(e){let t=e.target,r=Object.getPrototypeOf(e),i=e,a=Object.getOwnPropertyNames(r).filter(e=>/^(on[A-Z]|one[A-Z])/.test(e)&&typeof r[e]==`function`);for(let e of a){let r=/^one/.test(e);n(t,e.replace(/^one?/,``),t=>i[e](t),r)}}function g(e){return Array.from(e.querySelectorAll(`[data-mc]:not(:scope [data-mc] [data-mc])`)).filter(e=>e instanceof HTMLElement&&`_mc`in e).map(e=>e._mc)}function _(e,t){let n=e.parentElement?.closest(`[data-mc]`);for(;n instanceof HTMLElement;){if(`_mc`in n){let e=n._mc;if(t===void 0||t in e)return e}n=n.parentElement?.closest(`[data-mc]`)}return null}var v=class{_target;constructor(e){if(this._target=new WeakRef(e||{}),this instanceof y&&this.constructor!==y){h(this);let e=this.constructor.tag;(e===void 0||e.toUpperCase()===this.target.tagName)&&m(this)}}get target(){return this._target.deref()}},y=class e extends v{static tag;static assets=[];static attributes={};constructor(t){super(t);let n=this.constructor,r=this.target.tagName.toLowerCase();if(n.tag!==void 0&&r!==n.tag&&n.tag!==``){let t=document.createElement(n.tag);t.classList.add(r),e.add(t,n.name,new n(t)),r.includes(`-`)&&!this.target.isConnected?this.on(`connected`,()=>this.target.replaceWith(t)):this.target.replaceWith(t);return}if(n.assets.length&&l(r,n.assets).then(e=>{let t=Object.fromEntries(n.assets.map((t,n)=>[t,e[n]]));c(this,t),this.trigger(`assets`,t)}),n.tag===``){this.target.remove();return}let i=n.attributes;n.attributes&&Object.keys(n.attributes).forEach(e=>{this.target.setAttribute(e,i[e])})}static add(e,t,n={}){return f(e,t,n)}static remove(e,t){p(e,t)}static get(e,t,n){if(!d(e))return;let r=e._mc[t];return r instanceof n?r:void 0}off(e,n){t(this.target,e,n)}on(e,t){return n(this.target,e,t)}one(e,t){return r(this.target,e,t)}trigger(e,t={},n=`l`,r){a(this.target,e,t,n,r)}ancestors(e){let t=[],n=_(this.target,e);for(;n;)t.push(n),n=_(n.target,e);return t}closest(e){return _(this.target,e)}children(e){let t=g(this.target);return e===void 0?t:t.filter(t=>e in t)}descendants(e){return Array.from(this.target.querySelectorAll(`[data-mc]`)).filter(e=>e instanceof HTMLElement&&`_mc`in e).map(e=>e._mc).filter(t=>e===void 0||e in t)}};function b(e,t){return Object.defineProperty(t,"name",{value:e})}function x(e){return class extends e{constructor(...e){super(...e)}}}function S(e,t,n=[],r){if(customElements.get(e)){console.warn(`IGNORED: Custom element "${e}" is already defined!`);return}if(!e.includes(`-`))throw Error(`createCustomElement: tagName must contain at least one hyphen ("-").`);let i=HTMLElement;r&&(i=document.createElement(r).constructor);let a=o(e);if(!(t.prototype instanceof v))return customElements.define(e,t),t;let s=b(a,class extends x(i){constructor(e){super(),y.add(this,a,new t(this,e))}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(e,t,n){this.dispatchEvent(new CustomEvent(`_mcAttributeChanged`,{detail:{name:e,oldValue:t,newValue:n}}))}formResetCallback(){this.dispatchEvent(new CustomEvent(`_mcFormReset`))}static get observedAttributes(){return[...n]}});return customElements.define(e,s,{extends:r}),s}function C(e){return customElements.get(e)}export{S as defineCE,C as getCE};
@@ -1 +1 @@
1
- function e(e,t){let n=t.toLowerCase();return`on`+n in e?n:`_mc`+t[0].toUpperCase()+t.substring(1)}function t(e){return`_mc`+e[0].toUpperCase()+e.substring(1)}function n(t,r,i){if(t){if(typeof t==`string`){document.querySelectorAll(t).forEach(e=>n(e,r,i));return}t.removeEventListener(e(t,r),i)}}function r(t,n,i,a=!1){if(t){if(typeof t==`string`){document.querySelectorAll(t).forEach(e=>r(e,n,i));return}return t.addEventListener(e(t,n),i,{capture:!1,once:a}),i}}function i(e,t,n){if(e){if(typeof e==`string`){document.querySelectorAll(e).forEach(e=>i(e,t,n));return}return r(e,t,n,!0),n}}var a=class{stopped=!1;constructor(){}stop(){this.stopped=!0}};function o(t,n,r={},i=`l`,s){if(!t)return;if(typeof t==`string`){document.querySelectorAll(t).forEach(e=>o(e,n,r,i));return}let c=/^_mc/.test(n)?n:e(t,n),l=s||new a,u=new CustomEvent(c,{detail:{data:r,control:l},bubbles:!1});l.stopped||/l/.test(i)&&(t.dispatchEvent(u),l.stopped)||/[ud]/.test(i)&&queueMicrotask(()=>{if(i.indexOf(`u`)>-1&&o(t.parentElement,c,r,`lu`,l),i.indexOf(`d`)>-1)for(let e of t.children)o(e,c,r,`ld`)})}export{a as BubbleController,t as getMcEventName,n as off,r as on,i as one,o as trigger};
1
+ function e(e){return`_mc`+e[0].toUpperCase()+e.substring(1)}function t(e,t){let n=t.toLowerCase();return`on`+n in e?n:`_mc`+t[0].toUpperCase()+t.substring(1)}function n(e,r,i){if(e){if(typeof e==`string`){document.querySelectorAll(e).forEach(e=>n(e,r,i));return}e.removeEventListener(t(e,r),i)}}function r(e,n,i,a=!1){if(e){if(typeof e==`string`){document.querySelectorAll(e).forEach(e=>r(e,n,i));return}return e.addEventListener(t(e,n),i,{capture:!1,once:a}),i}}function i(e,t,n){if(e){if(typeof e==`string`){document.querySelectorAll(e).forEach(e=>i(e,t,n));return}return r(e,t,n,!0),n}}var a=class{stopped=!1;constructor(){}stop(){this.stopped=!0}};function o(e,n,r={},i=`l`,s){if(!e)return;if(typeof e==`string`){document.querySelectorAll(e).forEach(e=>o(e,n,r,i));return}let c=/^_mc/.test(n)?n:t(e,n),l=s||new a,u=new CustomEvent(c,{detail:{data:r,control:l},bubbles:!1});l.stopped||/l/.test(i)&&(e.dispatchEvent(u),l.stopped)||/[ud]/.test(i)&&queueMicrotask(()=>{if(i.indexOf(`u`)>-1&&o(e.parentElement,c,r,`lu`,l),i.indexOf(`d`)>-1)for(let t of e.children)o(t,c,r,`ld`)})}export{a as BubbleController,e as getMcEventName,n as off,r as on,i as one,o as trigger,t as trueEventName};
@@ -1 +1 @@
1
- function e(){return typeof window<`u`&&window.document!==void 0}function t(e){return typeof e==`object`&&!!e&&e.constructor===Object}function n(e){let r={},i=Object.keys(e).sort();for(let a=0;a<i.length;a++){let o=i[a],s=e[o];t(s)?r[o]=n(s):r[o]=s}return r}function r(e,t=!0){let i={},a=e,o=Object.getOwnPropertyNames(e);for(let e=0;e<o.length;e++){let t=o[e],n=a[t];if(n instanceof Object){let e=r(n,!1);for(let n in e)i[t+`.`+n]=e[n]}else i[t]=n}return t?n(i):i}function i(e,t){if(e===t||e!==e&&t!==t)return!0;if(typeof e!=`object`||!e||typeof t!=`object`||!t||e.constructor!==t.constructor)return!1;if(e instanceof Date)return e.getTime()===t.getTime();if(e instanceof RegExp)return e.toString()===t.toString();if(Array.isArray(e)){let n=t;if(e.length!==n.length)return!1;for(let t=0;t<e.length;t++)if(!i(e[t],n[t]))return!1;return!0}let n=e,r=t,a=Object.keys(n);if(a.length!==Object.keys(r).length)return!1;for(let e=0;e<a.length;e++){let t=a[e];if(!Object.prototype.hasOwnProperty.call(r,t)||!i(n[t],r[t]))return!1}return!0}function a(e,t){let n=t.toLowerCase();return`on`+n in e?n:`_mc`+t[0].toUpperCase()+t.substring(1)}function o(e,t){let n=Object.getOwnPropertyDescriptors(e);for(let[e,r]of Object.entries(n))(`get`in r||`set`in r)&&Object.defineProperty(t,e,r)}function s(e,t,n){if(e){if(typeof e==`string`){document.querySelectorAll(e).forEach(e=>s(e,t,n));return}e.removeEventListener(a(e,t),n)}}function c(e,t,n,r=!1){if(e){if(typeof e==`string`){document.querySelectorAll(e).forEach(e=>c(e,t,n));return}return e.addEventListener(a(e,t),n,{capture:!1,once:r}),n}}function l(e,t,n){if(e){if(typeof e==`string`){document.querySelectorAll(e).forEach(e=>l(e,t,n));return}return c(e,t,n,!0),n}}var u=class{stopped=!1;constructor(){}stop(){this.stopped=!0}};function d(e,t,n={},r=`l`,i){if(!e)return;if(typeof e==`string`){document.querySelectorAll(e).forEach(e=>d(e,t,n,r));return}let o=/^_mc/.test(t)?t:a(e,t),s=i||new u,c=new CustomEvent(o,{detail:{data:n,control:s},bubbles:!1});s.stopped||/l/.test(r)&&(e.dispatchEvent(c),s.stopped)||/[ud]/.test(r)&&queueMicrotask(()=>{if(r.indexOf(`u`)>-1&&d(e.parentElement,o,n,`lu`,s),r.indexOf(`d`)>-1)for(let t of e.children)d(t,o,n,`ld`)})}function f(e,t){return typeof HTMLElement<`u`&&e instanceof HTMLElement&&`_mc`in e&&(t===void 0||t in e._mc)}function p(e,t,n={}){let r=e;`_mc`in e||(r._mc=new b(e));let i=r._mc;return t.length&&!i[t]&&(i[t]=n,e instanceof HTMLElement&&!e.getAttribute(`data-mc`)&&e.setAttribute(`data-mc`,``)),r}function m(e,t){if(!t)return;let n=e._mc;n&&(n[t]&&delete n[t],!Object.keys(n).length&&e instanceof HTMLElement&&e.hasAttribute(`data-mc`)&&e.removeAttribute(`data-mc`))}function h(e){queueMicrotask(()=>{e.trigger(`Init`)})}function g(e){let t=e.target,n=Object.getPrototypeOf(e),r=e,i=Object.getOwnPropertyNames(n).filter(e=>/^(on[A-Z]|one[A-Z])/.test(e)&&typeof n[e]==`function`);for(let e of i){let n=/^one/.test(e);c(t,e.replace(/^one?/,``),t=>r[e](t),n)}}function _(e){return Array.from(e.querySelectorAll(`[data-mc]:not(:scope [data-mc] [data-mc])`)).filter(e=>e instanceof HTMLElement&&`_mc`in e).map(e=>e._mc)}function v(e,t){let n=e.parentElement?.closest(`[data-mc]`);for(;n instanceof HTMLElement;){if(`_mc`in n){let e=n._mc;if(t===void 0||t in e)return e}n=n.parentElement?.closest(`[data-mc]`)}return null}var y=class{_target;constructor(e){this._target=new WeakRef(e||{}),this instanceof b&&(g(this),h(this))}get target(){return this._target.deref()}},b=class extends y{constructor(e){super(e)}static add(e,t,n={}){return p(e,t,n)}static remove(e,t){m(e,t)}static get(e,t,n){if(!f(e))return;let r=e._mc[t];return r instanceof n?r:void 0}off(e,t){s(this.target,e,t)}on(e,t){return c(this.target,e,t)}one(e,t){return l(this.target,e,t)}trigger(e,t={},n=`l`,r){d(this.target,e,t,n,r)}ancestors(e){let t=[],n=v(this.target,e);for(;n;)t.push(n),n=v(n.target,e);return t}closest(e){return v(this.target,e)}children(e){let t=_(this.target);return e===void 0?t:t.filter(t=>e in t)}descendants(e){return Array.from(this.target.querySelectorAll(`[data-mc]`)).filter(e=>e instanceof HTMLElement&&`_mc`in e).map(e=>e._mc).filter(t=>e===void 0||e in t)}};function x(e){let t=new Set,n=/\{[^\{\}]*\}/g;return(e.getAttributeNames?e.getAttributeNames():[]).filter(t=>e.getAttribute(t)?.match(n)).forEach(r=>{new Set(e.getAttribute(r)?.match(n)).forEach(e=>t.add(e.replace(/[\{\}]/g,``)))}),[...e.childNodes].filter(e=>e.nodeType===3&&(e.nodeValue||``).match(n)).forEach(e=>{(e?.nodeValue||``).match(n).forEach(e=>t.add(e.replace(/[\{\}]/g,``)))}),[...t]}var S=[`INPUT`,`SELECT`,`TEXTAREA`],C=class extends b{data={};oldDisplay=``;constructor(e){super(e),x(e).forEach(e=>this.data[e]=``),j(this),this.#attachCallbacks()}#attachCallbacks(){let e=this.target,t=!1;(e.getAttributeNames?e.getAttributeNames():[]).filter(t=>e.getAttribute(t)?.match(/\{[^\{\}]*\}/g)).forEach(t=>{let n=new Set(e.getAttribute(t)?.match(/\{[^\{\}]*\}/g));this.data.subscribe((r=>i=>{let a=r;n.forEach(e=>{a=a.replace(e,String(i[e.replace(/[\{\}]/g,``)]))}),e.setAttribute(t,a)})(e.getAttribute(t)??``))}),[...e.childNodes].filter(e=>e.nodeType===3&&(e.nodeValue||``).match(/\{[^\{\}]*\}/g)).forEach(n=>{t=!0;let r=new Set((n.nodeValue??``).match(/\{[^\{\}]*\}/g));this.data.subscribe((t=>i=>{let a=t;r.forEach(e=>{a=a.replace(e,String(i[e.replace(/[\{\}]/g,``)]))}),this.oldDisplay?e.style=this.oldDisplay:e.removeAttribute(`style`),delete this.oldDisplay,n.nodeValue=a})(n.nodeValue??``)),this.oldDisplay=e.getAttribute(`style`)||``,t&&!S.includes(e.tagName)&&e.tagName!==`FIELDSET`&&(e.style.display=`none`)})}onData(e){let t={};Object.keys(e.detail.data).forEach(n=>{this.data.hasOwnProperty(n)&&(t[n]=e.detail.data[n])}),JSON.stringify(t)!==JSON.stringify(this.data)&&Object.assign(this.data,t)}};function w(e){return[e,...e.querySelectorAll(`*`)].filter(e=>!!x(e).length).filter(e=>e?.tagName!==`STYLE`).reverse()}function T(e){w(e).forEach(e=>{e?._mc?._placeholders||b.add(e,`_placeholders`,new C(e))})}function E(e){return typeof e==`object`&&!!e}var D={};function O(t){let n=t.constructor,i=n.name,a=class extends n{#notify=!0;#callbacks=[];constructor(e){super(e);let t=this.constructor;t.callbacks=[],E(e)&&Object.getOwnPropertyNames(e).forEach(t=>{this[t]=e[t]})}get callbacks(){return this.#callbacks}set callbacks(e){this.#callbacks=e}[Symbol.toPrimitive](e){let t=this.valueOf();return e===`string`?String(t):e===`number`?Number(t):t}subscribe(e){return this.#callbacks.push(e),this}unsubscribe(e){return this.#callbacks=this.#callbacks.filter(t=>t!==e),this}bind(t){if(e()){if(E(this.valueOf())){T(t);let e=[t,...t.querySelectorAll(`[data-mc]`)].filter(e=>!!e?._mc?._placeholders);this.#callbacks.push(function(t){let n=r(t);e.forEach(e=>{e&&d(e,`data`,n)})}),this.notify()}else console.warn(`IGNORED - cannot bind a non-Object to the dom, IS:`,typeof this.valueOf(),this);return this}}notify(e){let t=E(this.valueOf())&&!(this.valueOf()instanceof Array)?structuredClone(Object.assign({},this)):this.valueOf();return e!==void 0&&(this.#notify=e),this.#notify&&this.#callbacks.forEach(e=>{e(t)}),this}};return D[i]=a,a}function k(e){return D[e.constructor.name]||O(e)}function A(e){return(typeof e==`object`||typeof e==`function`)&&e!==null&&`subscribe`in e}function j(e,t){let n=e;return(t?[t]:[...Object.getOwnPropertyNames(e)]).forEach(t=>{let r=n[t];if(Object.prototype.hasOwnProperty.call(e,t)&&typeof r!=`function`&&!A(r)){if(t[0]===`_`||r===void 0)return;let a=r,s=new(k(a))(a),c=function(){queueMicrotask(function(){s.notify()})};Object.defineProperty(e,t,{enumerable:!0,get(){if(E(s.valueOf())){let e=structuredClone(Object.assign({},s));queueMicrotask(function(){i(structuredClone(Object.assign({},s)),e)||c()})}return s},set(e){if(typeof e==typeof s.valueOf())if(E(s.valueOf())&&!(s.valueOf()instanceof Array))A(s)||(s=new(k(e))(structuredClone(Object.assign({},e))),o(e,s)),Object.assign(s,e),s.notify();else{let t=s.valueOf(),n=s.callbacks;e!==t&&(s=new(k(e))(e),s.callbacks=n,c())}else console.warn(`IGNORED - cannot change observable types, IS:`,typeof s.valueOf(),s,`- CANNOT BECOME:`,typeof e)}}),n[t]=a}}),e}var M=e=>e.tagName.toLowerCase(),N=class{constructor(e){}},P=class extends N{#e;constructor(e){super(e),this.#e=e}get val(){return this.#e.form?new FormData(this.#e.form).get(this.#e.name)??null:null}set val(e){let t=[...this.#e.form?.querySelectorAll(`input[type="radio"][name="${this.#e.name}"]`)??[]];t.filter(t=>t.getAttribute(`value`)===e).shift().checked=!0}},F=class extends N{#e;constructor(e){super(e),this.#e=e}get val(){return this.#e.checked}set val(e){this.#e.checked=e}},I=class extends N{#e;constructor(e){super(e),this.#e=e}get val(){return this.#e.value}set val(e){this.#e.value=e}},L=class extends N{#e;#multi=!1;constructor(e){super(e),this.#e=e,this.#multi=e.multiple}get val(){let e=[];return[...this.#e.querySelectorAll(`option`)].filter(e=>e.selected).forEach(t=>{e.push(t.value)}),this.#multi?e.join(`,`):e[0]}set val(e){e=typeof e==`string`?[e]:e,[...this.#e.querySelectorAll(`option`)].forEach(t=>{e.indexOf(t.value)>-1?t.selected=!0:t.selected=!1})}},R=class extends N{#e;constructor(e){super(e),this.#e=e}get val(){return this.#e.value||``}set val(e){this.#e.value=e}},z=e=>{let t=[...(e||document).querySelectorAll(`input,select,textarea`)],n={};return t.forEach(e=>{let t=e.getAttribute(`name`);if(t){let r=!1;switch(M(e)){case`input`:switch(e.type){case`radio`:r=new P(e);break;case`checkbox`:r=new F(e);break;default:r=new I(e)}break;case`select`:r=new L(e);break;case`textarea`:r=new R(e);break}if(r){let i=r;b.add(e,t,i),Object.defineProperty(n,t,{enumerable:!0,configurable:!0,get:()=>i.val,set:e=>{i.val!==e&&(i.val=e)}})}}}),n};function B(t,n,r){if(!e())return;let i=z(r),a=t;a[n]=Object.assign({},i),j(t,n);let s=a[n];o(i,s),[...r.querySelectorAll(`input, textarea, select`)].forEach(e=>{e.addEventListener(`input`,()=>{s.notify()})})}export{B as formValues};
1
+ function e(e,t){let n=t.toLowerCase();return`on`+n in e?n:`_mc`+t[0].toUpperCase()+t.substring(1)}function t(n,r,i){if(n){if(typeof n==`string`){document.querySelectorAll(n).forEach(e=>t(e,r,i));return}n.removeEventListener(e(n,r),i)}}function n(t,r,i,a=!1){if(t){if(typeof t==`string`){document.querySelectorAll(t).forEach(e=>n(e,r,i));return}return t.addEventListener(e(t,r),i,{capture:!1,once:a}),i}}function r(e,t,i){if(e){if(typeof e==`string`){document.querySelectorAll(e).forEach(e=>r(e,t,i));return}return n(e,t,i,!0),i}}var i=class{stopped=!1;constructor(){}stop(){this.stopped=!0}};function a(t,n,r={},o=`l`,s){if(!t)return;if(typeof t==`string`){document.querySelectorAll(t).forEach(e=>a(e,n,r,o));return}let c=/^_mc/.test(n)?n:e(t,n),l=s||new i,u=new CustomEvent(c,{detail:{data:r,control:l},bubbles:!1});l.stopped||/l/.test(o)&&(t.dispatchEvent(u),l.stopped)||/[ud]/.test(o)&&queueMicrotask(()=>{if(o.indexOf(`u`)>-1&&a(t.parentElement,c,r,`lu`,l),o.indexOf(`d`)>-1)for(let e of t.children)a(e,c,r,`ld`)})}function o(){return typeof window<`u`&&window.document!==void 0}function s(e){return typeof e==`object`&&!!e&&e.constructor===Object}function c(e){let t={},n=Object.keys(e).sort();for(let r=0;r<n.length;r++){let i=n[r],a=e[i];s(a)?t[i]=c(a):t[i]=a}return t}function l(e,t=!0){let n={},r=e,i=Object.getOwnPropertyNames(e);for(let e=0;e<i.length;e++){let t=i[e],a=r[t];if(a instanceof Object){let e=l(a,!1);for(let r in e)n[t+`.`+r]=e[r]}else n[t]=a}return t?c(n):n}function u(e,t){if(e===t||e!==e&&t!==t)return!0;if(typeof e!=`object`||!e||typeof t!=`object`||!t||e.constructor!==t.constructor)return!1;if(e instanceof Date)return e.getTime()===t.getTime();if(e instanceof RegExp)return e.toString()===t.toString();if(Array.isArray(e)){let n=t;if(e.length!==n.length)return!1;for(let t=0;t<e.length;t++)if(!u(e[t],n[t]))return!1;return!0}let n=e,r=t,i=Object.keys(n);if(i.length!==Object.keys(r).length)return!1;for(let e=0;e<i.length;e++){let t=i[e];if(!Object.prototype.hasOwnProperty.call(r,t)||!u(n[t],r[t]))return!1}return!0}function d(e,t){let n=Object.getOwnPropertyDescriptors(e);for(let[e,r]of Object.entries(n))(`get`in r||`set`in r)&&Object.defineProperty(t,e,r)}function f(e,t){let n=new CSSStyleSheet;return n.replaceSync(t),e.adoptedStyleSheets.push(n),n}function p(e,t){let n=e.target,r=n.shadowRoot;!r&&Object.keys(t).some(e=>e.indexOf(`shadow`)===0)&&(r=n.attachShadow({mode:`open`})),Object.keys(t).forEach(i=>{switch(i){case`css`:f(document,t[i]);break;case`targetCss`:f(document,t[i]);break;case`shadowCss`:f(r,t[i]);break;case`shadowHtml`:r.innerHTML=t[i],h(r,e);break;case`targetHtml`:n.innerHTML=t[i],h(n,e);break}})}function m(e,t){let n=t=>{let n=t.match(/^([a-z]+)([A-Z][a-z]*)$/);return n?`./${e.replace(/-/g,`/`)}.${n[1]}.${n[2].toLowerCase()}`:`./${e.replace(/-/g,`/`)}.${t.toLowerCase()}`};return Promise.all(t.map(async e=>{let t=n(e);try{let n=await fetch(t);if(!n.ok)return`file not found: ${t}`;if(t.endsWith(`json`)){let r=await n.text();try{return JSON.parse(r)}catch{return console.error(`could not JSON.parse() asset '${e}' from ${t}:\n`,r),null}}return n.text()}catch{return`file not found: ${t}`}}))}function h(e,t){let r=[...e.querySelectorAll(`*`)];for(let e of r){if(!(e instanceof HTMLElement))continue;let r=[...e.attributes];for(let i of r){let r=i.name.toLowerCase();if(!(`on`+r in e))continue;let o=i.value.trim().split(`|`);if(o.length<2)continue;let[s,c,l]=o;e.removeAttribute(i.name);let u;if(l)try{u=JSON.parse(l)}catch{u=l}s===`this`||s===``?n(e,r,()=>t.trigger(c,u)):n(e,r,()=>a(s,c,u))}}}function g(e,t){return typeof HTMLElement<`u`&&e instanceof HTMLElement&&`_mc`in e&&(t===void 0||t in e._mc)}function _(e,t,n={}){let r=e;`_mc`in e||(r._mc=new w(e));let i=r._mc;return t.length&&!i[t]&&(i[t]=n,e instanceof HTMLElement&&!e.getAttribute(`data-mc`)&&e.setAttribute(`data-mc`,``)),r}function v(e,t){if(!t)return;let n=e._mc;n&&(n[t]&&delete n[t],!Object.keys(n).length&&e instanceof HTMLElement&&e.hasAttribute(`data-mc`)&&e.removeAttribute(`data-mc`))}function y(e){queueMicrotask(()=>{e.trigger(`Init`,null)})}function b(e){let t=e.target,r=Object.getPrototypeOf(e),i=e,a=Object.getOwnPropertyNames(r).filter(e=>/^(on[A-Z]|one[A-Z])/.test(e)&&typeof r[e]==`function`);for(let e of a){let r=/^one/.test(e);n(t,e.replace(/^one?/,``),t=>i[e](t),r)}}function x(e){return Array.from(e.querySelectorAll(`[data-mc]:not(:scope [data-mc] [data-mc])`)).filter(e=>e instanceof HTMLElement&&`_mc`in e).map(e=>e._mc)}function S(e,t){let n=e.parentElement?.closest(`[data-mc]`);for(;n instanceof HTMLElement;){if(`_mc`in n){let e=n._mc;if(t===void 0||t in e)return e}n=n.parentElement?.closest(`[data-mc]`)}return null}var C=class{_target;constructor(e){if(this._target=new WeakRef(e||{}),this instanceof w&&this.constructor!==w){b(this);let e=this.constructor.tag;(e===void 0||e.toUpperCase()===this.target.tagName)&&y(this)}}get target(){return this._target.deref()}},w=class e extends C{static tag;static assets=[];static attributes={};constructor(t){super(t);let n=this.constructor,r=this.target.tagName.toLowerCase();if(n.tag!==void 0&&r!==n.tag&&n.tag!==``){let t=document.createElement(n.tag);t.classList.add(r),e.add(t,n.name,new n(t)),r.includes(`-`)&&!this.target.isConnected?this.on(`connected`,()=>this.target.replaceWith(t)):this.target.replaceWith(t);return}if(n.assets.length&&m(r,n.assets).then(e=>{let t=Object.fromEntries(n.assets.map((t,n)=>[t,e[n]]));p(this,t),this.trigger(`assets`,t)}),n.tag===``){this.target.remove();return}let i=n.attributes;n.attributes&&Object.keys(n.attributes).forEach(e=>{this.target.setAttribute(e,i[e])})}static add(e,t,n={}){return _(e,t,n)}static remove(e,t){v(e,t)}static get(e,t,n){if(!g(e))return;let r=e._mc[t];return r instanceof n?r:void 0}off(e,n){t(this.target,e,n)}on(e,t){return n(this.target,e,t)}one(e,t){return r(this.target,e,t)}trigger(e,t={},n=`l`,r){a(this.target,e,t,n,r)}ancestors(e){let t=[],n=S(this.target,e);for(;n;)t.push(n),n=S(n.target,e);return t}closest(e){return S(this.target,e)}children(e){let t=x(this.target);return e===void 0?t:t.filter(t=>e in t)}descendants(e){return Array.from(this.target.querySelectorAll(`[data-mc]`)).filter(e=>e instanceof HTMLElement&&`_mc`in e).map(e=>e._mc).filter(t=>e===void 0||e in t)}};function T(e){let t=new Set,n=/\{[^\{\}]*\}/g;return(e.getAttributeNames?e.getAttributeNames():[]).filter(t=>e.getAttribute(t)?.match(n)).forEach(r=>{new Set(e.getAttribute(r)?.match(n)).forEach(e=>t.add(e.replace(/[\{\}]/g,``)))}),[...e.childNodes].filter(e=>e.nodeType===3&&(e.nodeValue||``).match(n)).forEach(e=>{(e?.nodeValue||``).match(n).forEach(e=>t.add(e.replace(/[\{\}]/g,``)))}),[...t]}var E=[`INPUT`,`SELECT`,`TEXTAREA`],D=class extends w{data={};oldDisplay=``;constructor(e){super(e),T(e).forEach(e=>this.data[e]=``),F(this),this.#e()}#e(){let e=this.target,t=!1;(e.getAttributeNames?e.getAttributeNames():[]).filter(t=>e.getAttribute(t)?.match(/\{[^\{\}]*\}/g)).forEach(t=>{let n=new Set(e.getAttribute(t)?.match(/\{[^\{\}]*\}/g));this.data.subscribe((r=>i=>{let a=r;n.forEach(e=>{a=a.replace(e,String(i[e.replace(/[\{\}]/g,``)]))}),e.setAttribute(t,a)})(e.getAttribute(t)??``))}),[...e.childNodes].filter(e=>e.nodeType===3&&(e.nodeValue||``).match(/\{[^\{\}]*\}/g)).forEach(n=>{t=!0;let r=new Set((n.nodeValue??``).match(/\{[^\{\}]*\}/g));this.data.subscribe((t=>i=>{let a=t;r.forEach(e=>{a=a.replace(e,String(i[e.replace(/[\{\}]/g,``)]))}),this.oldDisplay?e.style=this.oldDisplay:e.removeAttribute(`style`),delete this.oldDisplay,n.nodeValue=a})(n.nodeValue??``)),this.oldDisplay=e.getAttribute(`style`)||``,t&&!E.includes(e.tagName)&&e.tagName!==`FIELDSET`&&(e.style.display=`none`)})}onData(e){let t={};Object.keys(e.detail.data).forEach(n=>{this.data.hasOwnProperty(n)&&(t[n]=e.detail.data[n])}),JSON.stringify(t)!==JSON.stringify(this.data)&&Object.assign(this.data,t)}};function O(e){return[e,...e.querySelectorAll(`*`)].filter(e=>!!T(e).length).filter(e=>e?.tagName!==`STYLE`).reverse()}function k(e){O(e).forEach(e=>{e?._mc?._placeholders||w.add(e,`_placeholders`,new D(e))})}function A(e){return typeof e==`object`&&!!e}var j={};function M(e){let t=e.constructor,n=t.name,r=class extends t{#e=!0;#t=[];constructor(e){super(e);let t=this.constructor;t.callbacks=[],A(e)&&Object.getOwnPropertyNames(e).forEach(t=>{this[t]=e[t]})}get callbacks(){return this.#t}set callbacks(e){this.#t=e}[Symbol.toPrimitive](e){let t=this.valueOf();return e===`string`?String(t):e===`number`?Number(t):t}subscribe(e){return this.#t.push(e),this}unsubscribe(e){return this.#t=this.#t.filter(t=>t!==e),this}bind(e){if(o()){if(A(this.valueOf())){k(e);let t=[e,...e.querySelectorAll(`[data-mc]`)].filter(e=>!!e?._mc?._placeholders);this.#t.push(function(e){let n=l(e);t.forEach(e=>{e&&a(e,`data`,n)})}),this.notify()}else console.warn(`IGNORED - cannot bind a non-Object to the dom, IS:`,typeof this.valueOf(),this);return this}}notify(e){let t=A(this.valueOf())&&!(this.valueOf()instanceof Array)?structuredClone(Object.assign({},this)):this.valueOf();return e!==void 0&&(this.#e=e),this.#e&&this.#t.forEach(e=>{e(t)}),this}};return j[n]=r,r}function N(e){return j[e.constructor.name]||M(e)}function P(e){return(typeof e==`object`||typeof e==`function`)&&e!==null&&`subscribe`in e}function F(e,t){let n=e;return(t?[t]:[...Object.getOwnPropertyNames(e)]).forEach(t=>{let r=n[t];if(Object.prototype.hasOwnProperty.call(e,t)&&typeof r!=`function`&&!P(r)){if(t[0]===`_`||r===void 0)return;let i=r,a=new(N(i))(i),o=function(){queueMicrotask(function(){a.notify()})};Object.defineProperty(e,t,{enumerable:!0,get(){if(A(a.valueOf())){let e=structuredClone(Object.assign({},a));queueMicrotask(function(){u(structuredClone(Object.assign({},a)),e)||o()})}return a},set(e){if(typeof e==typeof a.valueOf())if(A(a.valueOf())&&!(a.valueOf()instanceof Array))P(a)||(a=new(N(e))(structuredClone(Object.assign({},e))),d(e,a)),Object.assign(a,e),a.notify();else{let t=a.valueOf(),n=a.callbacks;e!==t&&(a=new(N(e))(e),a.callbacks=n,o())}else console.warn(`IGNORED - cannot change observable types, IS:`,typeof a.valueOf(),a,`- CANNOT BECOME:`,typeof e)}}),n[t]=i}}),e}function I(e){let t=Object.getPrototypeOf(e.prototype);function n(e,t){let n=e[t];P(n)||F(e,t)}Object.hasOwn(t,`notify`)||Object.assign(t,{notify:function(e){return n(this,e),this[e].notify(),this},subscribe:function(e,t){return n(this,e),this[e].subscribe(t),this},bind:function(e,t){return n(this,e),this[e].bind(t),this}})}I(w);var L=e=>e.tagName.toLowerCase(),R=class{constructor(e){}},z=class extends R{#e;constructor(e){super(e),this.#e=e}get val(){return this.#e.form?new FormData(this.#e.form).get(this.#e.name)??null:null}set val(e){let t=[...this.#e.form?.querySelectorAll(`input[type="radio"][name="${this.#e.name}"]`)??[]];t.filter(t=>t.getAttribute(`value`)===e).shift().checked=!0}},B=class extends R{#e;constructor(e){super(e),this.#e=e}get val(){return this.#e.checked}set val(e){this.#e.checked=e}},V=class extends R{#e;constructor(e){super(e),this.#e=e}get val(){return this.#e.value}set val(e){this.#e.value=e}},H=class extends R{#e;#t=!1;constructor(e){super(e),this.#e=e,this.#t=e.multiple}get val(){let e=[];return[...this.#e.querySelectorAll(`option`)].filter(e=>e.selected).forEach(t=>{e.push(t.value)}),this.#t?e:e[0]}set val(e){e=typeof e==`string`?[e]:e,[...this.#e.querySelectorAll(`option`)].forEach(t=>{e.indexOf(t.value)>-1?t.selected=!0:t.selected=!1})}},U=class extends R{#e;constructor(e){super(e),this.#e=e}get val(){return this.#e.value||``}set val(e){this.#e.value=e}},W=e=>{let t=[...(e||document).querySelectorAll(`input,select,textarea`)],n={};return t.forEach(e=>{let t=e.getAttribute(`name`);if(t){let r=!1;switch(L(e)){case`input`:switch(e.type){case`radio`:r=new z(e);break;case`checkbox`:r=new B(e);break;default:r=new V(e)}break;case`select`:r=new H(e);break;case`textarea`:r=new U(e);break}if(r){let i=r;w.add(e,t,i),Object.defineProperty(n,t,{enumerable:!0,configurable:!0,get:()=>i.val,set:e=>{i.val!==e&&(i.val=e)}})}}}),n};function G(e,t,n){if(!o())return;let r=W(n),i=e;i[t]=Object.assign({},r),F(e,t);let a=i[t];d(r,a),[...n.querySelectorAll(`input, textarea, select`)].forEach(e=>{e.addEventListener(`input`,()=>{a.notify()})})}function K(e){let t=Object.getPrototypeOf(e.prototype);Object.hasOwn(t,`formValues`)||Object.assign(t,{formValues:function(e,t){return G(this,t,e),this}})}export{K as formValuePlugin,G as formValues};
@@ -1,8 +1,8 @@
1
1
  export * from './utils/helpers.js';
2
2
  export * from './core/mcGuards.js';
3
3
  export * from './core/MC.js';
4
- export * from './core/autoload.js';
5
- export * from './core/events.js';
4
+ export * from './utils/autoload.js';
5
+ export * from './utils/events.js';
6
6
  export * from './core/elements.js';
7
7
  export * from './state/observables.js';
8
8
  export * from './state/formValues.js';
@@ -1 +1 @@
1
- {"version":3,"file":"microcomponents.d.ts","sourceRoot":"","sources":["../src/microcomponents.ts"],"names":[],"mappings":"AACA,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"microcomponents.d.ts","sourceRoot":"","sources":["../src/microcomponents.ts"],"names":[],"mappings":"AACA,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC"}
@@ -2,8 +2,8 @@
2
2
  export * from './utils/helpers.js';
3
3
  export * from './core/mcGuards.js';
4
4
  export * from './core/MC.js';
5
- export * from './core/autoload.js';
6
- export * from './core/events.js';
5
+ export * from './utils/autoload.js';
6
+ export * from './utils/events.js';
7
7
  export * from './core/elements.js';
8
8
  export * from './state/observables.js';
9
9
  export * from './state/formValues.js';
@@ -1 +1 @@
1
- function e(){return typeof window<`u`&&window.document!==void 0}function t(e){return typeof e==`object`&&!!e&&e.constructor===Object}function n(e){let r={},i=Object.keys(e).sort();for(let a=0;a<i.length;a++){let o=i[a],s=e[o];t(s)?r[o]=n(s):r[o]=s}return r}function r(e,t=!0){let i={},a=e,o=Object.getOwnPropertyNames(e);for(let e=0;e<o.length;e++){let t=o[e],n=a[t];if(n instanceof Object){let e=r(n,!1);for(let n in e)i[t+`.`+n]=e[n]}else i[t]=n}return t?n(i):i}function i(e,t){if(e===t||e!==e&&t!==t)return!0;if(typeof e!=`object`||!e||typeof t!=`object`||!t||e.constructor!==t.constructor)return!1;if(e instanceof Date)return e.getTime()===t.getTime();if(e instanceof RegExp)return e.toString()===t.toString();if(Array.isArray(e)){let n=t;if(e.length!==n.length)return!1;for(let t=0;t<e.length;t++)if(!i(e[t],n[t]))return!1;return!0}let n=e,r=t,a=Object.keys(n);if(a.length!==Object.keys(r).length)return!1;for(let e=0;e<a.length;e++){let t=a[e];if(!Object.prototype.hasOwnProperty.call(r,t)||!i(n[t],r[t]))return!1}return!0}function a(e,n={}){let r=n,i=typeof e==`string`?e.split(`.`):e;if(!(!r||!i[0]||!r[i[0]])){if(i.length>1){let e=r[i[0]];return t(e)?a(i.slice(1),e):void 0}return r[i[0]]}}function o(e,n,...r){let i=[e,n,...r];if(i.length>2){for(;i.length>1;)i[0]=o(i[0],i[1]),i.splice(1,1);return i[0]}if(typeof e==`string`){let t=e;return e.match(/\{[^\{\}]*\}/g)?.forEach(e=>{let r=a(e.substring(1,e.length-1),n);r!==void 0&&(t=t.replace(e,String(r)))}),t}else if(t(e)){let t=e;Object.keys(t).forEach(e=>{Object.prototype.hasOwnProperty.call(t,e)&&(t[e]=o(t[e],n))})}return e}function s(e){return e.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``)}function c(e,t){let n;return(...r)=>{clearTimeout(n),n=setTimeout(()=>{e(...r)},t)}}function l(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 u(e,t){let n=t.toLowerCase();return`on`+n in e?n:`_mc`+t[0].toUpperCase()+t.substring(1)}function d(e,t){let n=Object.getOwnPropertyDescriptors(e);for(let[e,r]of Object.entries(n))(`get`in r||`set`in r)&&Object.defineProperty(t,e,r)}function f(e,t){return typeof HTMLElement<`u`&&e instanceof HTMLElement&&`_mc`in e&&(t===void 0||t in e._mc)}function p(e){return`_mc`+e[0].toUpperCase()+e.substring(1)}function m(e,t,n){if(e){if(typeof e==`string`){document.querySelectorAll(e).forEach(e=>m(e,t,n));return}e.removeEventListener(u(e,t),n)}}function h(e,t,n,r=!1){if(e){if(typeof e==`string`){document.querySelectorAll(e).forEach(e=>h(e,t,n));return}return e.addEventListener(u(e,t),n,{capture:!1,once:r}),n}}function g(e,t,n){if(e){if(typeof e==`string`){document.querySelectorAll(e).forEach(e=>g(e,t,n));return}return h(e,t,n,!0),n}}var _=class{stopped=!1;constructor(){}stop(){this.stopped=!0}};function v(e,t,n={},r=`l`,i){if(!e)return;if(typeof e==`string`){document.querySelectorAll(e).forEach(e=>v(e,t,n,r));return}let a=/^_mc/.test(t)?t:u(e,t),o=i||new _,s=new CustomEvent(a,{detail:{data:n,control:o},bubbles:!1});o.stopped||/l/.test(r)&&(e.dispatchEvent(s),o.stopped)||/[ud]/.test(r)&&queueMicrotask(()=>{if(r.indexOf(`u`)>-1&&v(e.parentElement,a,n,`lu`,o),r.indexOf(`d`)>-1)for(let t of e.children)v(t,a,n,`ld`)})}function y(e,t,n={}){let r=e;`_mc`in e||(r._mc=new D(e));let i=r._mc;return t.length&&!i[t]&&(i[t]=n,e instanceof HTMLElement&&!e.getAttribute(`data-mc`)&&e.setAttribute(`data-mc`,``)),r}function b(e,t){if(!t)return;let n=e._mc;n&&(n[t]&&delete n[t],!Object.keys(n).length&&e instanceof HTMLElement&&e.hasAttribute(`data-mc`)&&e.removeAttribute(`data-mc`))}function x(e){queueMicrotask(()=>{e.trigger(`Init`)})}function S(e){let t=e.target,n=Object.getPrototypeOf(e),r=e,i=Object.getOwnPropertyNames(n).filter(e=>/^(on[A-Z]|one[A-Z])/.test(e)&&typeof n[e]==`function`);for(let e of i){let n=/^one/.test(e);h(t,e.replace(/^one?/,``),t=>r[e](t),n)}}function C(e){return Array.from(e.querySelectorAll(`[data-mc]:not(:scope [data-mc] [data-mc])`)).filter(e=>e instanceof HTMLElement&&`_mc`in e).map(e=>e._mc)}function w(e,t){let n=e.parentElement?.closest(`[data-mc]`);for(;n instanceof HTMLElement;){if(`_mc`in n){let e=n._mc;if(t===void 0||t in e)return e}n=n.parentElement?.closest(`[data-mc]`)}return null}var T=class{_target;constructor(e){this._target=new WeakRef(e||{}),this instanceof D&&(S(this),x(this))}get target(){return this._target.deref()}},E=class extends T{constructor(e){super(e)}},D=class extends T{constructor(e){super(e)}static add(e,t,n={}){return y(e,t,n)}static remove(e,t){b(e,t)}static get(e,t,n){if(!f(e))return;let r=e._mc[t];return r instanceof n?r:void 0}off(e,t){m(this.target,e,t)}on(e,t){return h(this.target,e,t)}one(e,t){return g(this.target,e,t)}trigger(e,t={},n=`l`,r){v(this.target,e,t,n,r)}ancestors(e){let t=[],n=w(this.target,e);for(;n;)t.push(n),n=w(n.target,e);return t}closest(e){return w(this.target,e)}children(e){let t=C(this.target);return e===void 0?t:t.filter(t=>e in t)}descendants(e){return Array.from(this.target.querySelectorAll(`[data-mc]`)).filter(e=>e instanceof HTMLElement&&`_mc`in e).map(e=>e._mc).filter(t=>e===void 0||e in t)}},O=new Set;function k(e){return()=>{let t=Array.from(document.querySelectorAll(`[data-mc*="${e}"]`)).filter(e=>e instanceof HTMLElement);if(t.length===0)return;let n=customElements.get(e);for(let r of t){try{D.add(r,n.name,new n(r))}catch{if(`create`in n&&typeof n.create==`function`){let e=n.create(r);if(!f(e))throw`create() of Class ${n.name} did not return a McHost.`;e.setAttribute(`data-mc`,r.getAttribute(`data-mc`)??``),r.replaceWith(e),r=e}else throw`Class ${n.name} doesn't have a callable constructor AND class doesn't have a static .create() method.`}let t=r.getAttribute(`data-mc`).split(` `).filter(t=>t!==e&&t!==``).join(` `).trim();r.setAttribute(`data-mc`,t)}}}function A(e){if(O.has(e))return;O.add(e);let t=`./`+e.split(`-`).join(`/`)+`.js`,n=document.createElement(`script`);n.setAttribute(`src`,t),n.setAttribute(`blocking`,`render`),n.async=!0,n.setAttribute(`type`,`module`),n.setAttribute(`data-name`,e),n.setAttribute(`loading`,``),customElements.whenDefined(e).then(k(e)),n.addEventListener(`load`,t=>{O.delete(e),document.head.querySelector(`script[data-name="${e}"]`)?.remove()}),n.addEventListener(`error`,e=>{console.error(`could not load DC code from`,t)}),document.head.append(n)}function j(){[...document.querySelectorAll(`:not(:defined)`)].filter(e=>!!e&&!customElements.get(e.tagName.toLowerCase())&&!O.has(e.tagName.toLowerCase())).forEach(e=>{A(e.tagName.toLowerCase())}),[...document.querySelectorAll(`[data-mc]:not([data-mc=""]`)].filter(e=>!!e).forEach(e=>{(e.getAttribute(`data-mc`)?.split(` `).filter(e=>e!==``))?.forEach(e=>{let t=customElements.get(e);!O.has(e)&&!t?A(e):t&&k(e)()})})}var M=null,N=function(e=!0){return e?M?!0:(M=new MutationObserver(j),setTimeout(()=>{M.observe(document.body,{childList:!0,subtree:!0}),j()},5),window.autoload??=N,!0):(M&&=(M.disconnect(),null),!1)};N.state=O;function P(e,t){return Object.defineProperty(t,"name",{value:e})}function F(e){return class extends e{constructor(...e){super(...e)}}}function I(e,t,n=[],r){if(customElements.get(e)){console.warn(`IGNORED: Custom element "${e}" is already defined!`);return}if(!e.includes(`-`))throw Error(`createCustomElement: tagName must contain at least one hyphen ("-").`);let i=HTMLElement;r&&(i=document.createElement(r).constructor);let a=s(e);if(!(t.prototype instanceof T))return customElements.define(e,t),t;let o=P(a,class extends F(i){constructor(e){super(),D.add(this,a,new t(this,e))}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(e,t,n){this.dispatchEvent(new CustomEvent(`_mcAttributeChanged`,{detail:{name:e,oldValue:t,newValue:n}}))}formResetCallback(){this.dispatchEvent(new CustomEvent(`_mcFormReset`))}static get observedAttributes(){return[...n]}});return customElements.define(e,o,{extends:r}),o}function L(e){return customElements.get(e)}function R(e){let t=new Set,n=/\{[^\{\}]*\}/g;return(e.getAttributeNames?e.getAttributeNames():[]).filter(t=>e.getAttribute(t)?.match(n)).forEach(r=>{new Set(e.getAttribute(r)?.match(n)).forEach(e=>t.add(e.replace(/[\{\}]/g,``)))}),[...e.childNodes].filter(e=>e.nodeType===3&&(e.nodeValue||``).match(n)).forEach(e=>{(e?.nodeValue||``).match(n).forEach(e=>t.add(e.replace(/[\{\}]/g,``)))}),[...t]}var z=[`INPUT`,`SELECT`,`TEXTAREA`],B=class extends D{data={};oldDisplay=``;constructor(e){super(e),R(e).forEach(e=>this.data[e]=``),J(this),this.#attachCallbacks()}#attachCallbacks(){let e=this.target,t=!1;(e.getAttributeNames?e.getAttributeNames():[]).filter(t=>e.getAttribute(t)?.match(/\{[^\{\}]*\}/g)).forEach(t=>{let n=new Set(e.getAttribute(t)?.match(/\{[^\{\}]*\}/g));this.data.subscribe((r=>i=>{let a=r;n.forEach(e=>{a=a.replace(e,String(i[e.replace(/[\{\}]/g,``)]))}),e.setAttribute(t,a)})(e.getAttribute(t)??``))}),[...e.childNodes].filter(e=>e.nodeType===3&&(e.nodeValue||``).match(/\{[^\{\}]*\}/g)).forEach(n=>{t=!0;let r=new Set((n.nodeValue??``).match(/\{[^\{\}]*\}/g));this.data.subscribe((t=>i=>{let a=t;r.forEach(e=>{a=a.replace(e,String(i[e.replace(/[\{\}]/g,``)]))}),this.oldDisplay?e.style=this.oldDisplay:e.removeAttribute(`style`),delete this.oldDisplay,n.nodeValue=a})(n.nodeValue??``)),this.oldDisplay=e.getAttribute(`style`)||``,t&&!z.includes(e.tagName)&&e.tagName!==`FIELDSET`&&(e.style.display=`none`)})}onData(e){let t={};Object.keys(e.detail.data).forEach(n=>{this.data.hasOwnProperty(n)&&(t[n]=e.detail.data[n])}),JSON.stringify(t)!==JSON.stringify(this.data)&&Object.assign(this.data,t)}};function V(e){return[e,...e.querySelectorAll(`*`)].filter(e=>!!R(e).length).filter(e=>e?.tagName!==`STYLE`).reverse()}function H(e){V(e).forEach(e=>{e?._mc?._placeholders||D.add(e,`_placeholders`,new B(e))})}function U(e){return typeof e==`object`&&!!e}var W={};function G(t){let n=t.constructor,i=n.name,a=class extends n{#notify=!0;#callbacks=[];constructor(e){super(e);let t=this.constructor;t.callbacks=[],U(e)&&Object.getOwnPropertyNames(e).forEach(t=>{this[t]=e[t]})}get callbacks(){return this.#callbacks}set callbacks(e){this.#callbacks=e}[Symbol.toPrimitive](e){let t=this.valueOf();return e===`string`?String(t):e===`number`?Number(t):t}subscribe(e){return this.#callbacks.push(e),this}unsubscribe(e){return this.#callbacks=this.#callbacks.filter(t=>t!==e),this}bind(t){if(e()){if(U(this.valueOf())){H(t);let e=[t,...t.querySelectorAll(`[data-mc]`)].filter(e=>!!e?._mc?._placeholders);this.#callbacks.push(function(t){let n=r(t);e.forEach(e=>{e&&v(e,`data`,n)})}),this.notify()}else console.warn(`IGNORED - cannot bind a non-Object to the dom, IS:`,typeof this.valueOf(),this);return this}}notify(e){let t=U(this.valueOf())&&!(this.valueOf()instanceof Array)?structuredClone(Object.assign({},this)):this.valueOf();return e!==void 0&&(this.#notify=e),this.#notify&&this.#callbacks.forEach(e=>{e(t)}),this}};return W[i]=a,a}function K(e){return W[e.constructor.name]||G(e)}function q(e){return(typeof e==`object`||typeof e==`function`)&&e!==null&&`subscribe`in e}function J(e,t){let n=e;return(t?[t]:[...Object.getOwnPropertyNames(e)]).forEach(t=>{let r=n[t];if(Object.prototype.hasOwnProperty.call(e,t)&&typeof r!=`function`&&!q(r)){if(t[0]===`_`||r===void 0)return;let a=r,o=new(K(a))(a),s=function(){queueMicrotask(function(){o.notify()})};Object.defineProperty(e,t,{enumerable:!0,get(){if(U(o.valueOf())){let e=structuredClone(Object.assign({},o));queueMicrotask(function(){i(structuredClone(Object.assign({},o)),e)||s()})}return o},set(e){if(typeof e==typeof o.valueOf())if(U(o.valueOf())&&!(o.valueOf()instanceof Array))q(o)||(o=new(K(e))(structuredClone(Object.assign({},e))),d(e,o)),Object.assign(o,e),o.notify();else{let t=o.valueOf(),n=o.callbacks;e!==t&&(o=new(K(e))(e),o.callbacks=n,s())}else console.warn(`IGNORED - cannot change observable types, IS:`,typeof o.valueOf(),o,`- CANNOT BECOME:`,typeof e)}}),n[t]=a}}),e}var Y=e=>e.tagName.toLowerCase(),X=class{constructor(e){}},Z=class extends X{#e;constructor(e){super(e),this.#e=e}get val(){return this.#e.form?new FormData(this.#e.form).get(this.#e.name)??null:null}set val(e){let t=[...this.#e.form?.querySelectorAll(`input[type="radio"][name="${this.#e.name}"]`)??[]];t.filter(t=>t.getAttribute(`value`)===e).shift().checked=!0}},Q=class extends X{#e;constructor(e){super(e),this.#e=e}get val(){return this.#e.checked}set val(e){this.#e.checked=e}},$=class extends X{#e;constructor(e){super(e),this.#e=e}get val(){return this.#e.value}set val(e){this.#e.value=e}},ee=class extends X{#e;#multi=!1;constructor(e){super(e),this.#e=e,this.#multi=e.multiple}get val(){let e=[];return[...this.#e.querySelectorAll(`option`)].filter(e=>e.selected).forEach(t=>{e.push(t.value)}),this.#multi?e.join(`,`):e[0]}set val(e){e=typeof e==`string`?[e]:e,[...this.#e.querySelectorAll(`option`)].forEach(t=>{e.indexOf(t.value)>-1?t.selected=!0:t.selected=!1})}},te=class extends X{#e;constructor(e){super(e),this.#e=e}get val(){return this.#e.value||``}set val(e){this.#e.value=e}},ne=e=>{let t=[...(e||document).querySelectorAll(`input,select,textarea`)],n={};return t.forEach(e=>{let t=e.getAttribute(`name`);if(t){let r=!1;switch(Y(e)){case`input`:switch(e.type){case`radio`:r=new Z(e);break;case`checkbox`:r=new Q(e);break;default:r=new $(e)}break;case`select`:r=new ee(e);break;case`textarea`:r=new te(e);break}if(r){let i=r;D.add(e,t,i),Object.defineProperty(n,t,{enumerable:!0,configurable:!0,get:()=>i.val,set:e=>{i.val!==e&&(i.val=e)}})}}}),n};function re(t,n,r){if(!e())return;let i=ne(r),a=t;a[n]=Object.assign({},i),J(t,n);let o=a[n];d(i,o),[...r.querySelectorAll(`input, textarea, select`)].forEach(e=>{e.addEventListener(`input`,()=>{o.notify()})})}export{_ as BubbleController,D as DC,E as MC,T as McBase,N as autoload,d as copyGettersSetters,c as debounce,i as deepEqual,I as defineCE,r as flattenObject,re as formValues,L as getCE,p as getMcEventName,l as htmlToElements,q as isAlreadyObserved,e as isBrowser,f as isMcDOM,t as isNativeObject,s as kebabToPascal,a as nameSpace,J as observe,m as off,h as on,g as one,o as parse,n as sortObject,v as trigger,u as trueEventName};
1
+ function e(e){return`_mc`+e[0].toUpperCase()+e.substring(1)}function t(e,t){let n=t.toLowerCase();return`on`+n in e?n:`_mc`+t[0].toUpperCase()+t.substring(1)}function n(e,r,i){if(e){if(typeof e==`string`){document.querySelectorAll(e).forEach(e=>n(e,r,i));return}e.removeEventListener(t(e,r),i)}}function r(e,n,i,a=!1){if(e){if(typeof e==`string`){document.querySelectorAll(e).forEach(e=>r(e,n,i));return}return e.addEventListener(t(e,n),i,{capture:!1,once:a}),i}}function i(e,t,n){if(e){if(typeof e==`string`){document.querySelectorAll(e).forEach(e=>i(e,t,n));return}return r(e,t,n,!0),n}}var a=class{stopped=!1;constructor(){}stop(){this.stopped=!0}};function o(e,n,r={},i=`l`,s){if(!e)return;if(typeof e==`string`){document.querySelectorAll(e).forEach(e=>o(e,n,r,i));return}let c=/^_mc/.test(n)?n:t(e,n),l=s||new a,u=new CustomEvent(c,{detail:{data:r,control:l},bubbles:!1});l.stopped||/l/.test(i)&&(e.dispatchEvent(u),l.stopped)||/[ud]/.test(i)&&queueMicrotask(()=>{if(i.indexOf(`u`)>-1&&o(e.parentElement,c,r,`lu`,l),i.indexOf(`d`)>-1)for(let t of e.children)o(t,c,r,`ld`)})}function s(){return typeof window<`u`&&window.document!==void 0}function c(e){return typeof e==`object`&&!!e&&e.constructor===Object}function l(e){let t={},n=Object.keys(e).sort();for(let r=0;r<n.length;r++){let i=n[r],a=e[i];c(a)?t[i]=l(a):t[i]=a}return t}function u(e,t=!0){let n={},r=e,i=Object.getOwnPropertyNames(e);for(let e=0;e<i.length;e++){let t=i[e],a=r[t];if(a instanceof Object){let e=u(a,!1);for(let r in e)n[t+`.`+r]=e[r]}else n[t]=a}return t?l(n):n}function d(e,t){if(e===t||e!==e&&t!==t)return!0;if(typeof e!=`object`||!e||typeof t!=`object`||!t||e.constructor!==t.constructor)return!1;if(e instanceof Date)return e.getTime()===t.getTime();if(e instanceof RegExp)return e.toString()===t.toString();if(Array.isArray(e)){let n=t;if(e.length!==n.length)return!1;for(let t=0;t<e.length;t++)if(!d(e[t],n[t]))return!1;return!0}let n=e,r=t,i=Object.keys(n);if(i.length!==Object.keys(r).length)return!1;for(let e=0;e<i.length;e++){let t=i[e];if(!Object.prototype.hasOwnProperty.call(r,t)||!d(n[t],r[t]))return!1}return!0}function f(e,t={}){let n=t,r=typeof e==`string`?e.split(`.`):e;if(!(!n||!r[0]||!n[r[0]])){if(r.length>1){let e=n[r[0]];return c(e)?f(r.slice(1),e):void 0}return n[r[0]]}}function p(e,t,...n){let r=[e,t,...n];if(r.length>2){for(;r.length>1;)r[0]=p(r[0],r[1]),r.splice(1,1);return r[0]}if(typeof e==`string`){let n=e;return e.match(/\{[^\{\}]*\}/g)?.forEach(e=>{let r=f(e.substring(1,e.length-1),t);r!==void 0&&(n=n.replace(e,String(r)))}),n}else if(c(e)){let n=e;Object.keys(n).forEach(e=>{Object.prototype.hasOwnProperty.call(n,e)&&(n[e]=p(n[e],t))})}return e}function m(e){return e.split(`-`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``)}function h(e,t){let n;return(...r)=>{clearTimeout(n),n=setTimeout(()=>{e(...r)},t)}}function g(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 _(e,t){let n=Object.getOwnPropertyDescriptors(e);for(let[e,r]of Object.entries(n))(`get`in r||`set`in r)&&Object.defineProperty(t,e,r)}function v(e,t){let n=new CSSStyleSheet;return n.replaceSync(t),e.adoptedStyleSheets.push(n),n}function y(e,t){let n=e.target,r=n.shadowRoot;!r&&Object.keys(t).some(e=>e.indexOf(`shadow`)===0)&&(r=n.attachShadow({mode:`open`})),Object.keys(t).forEach(i=>{switch(i){case`css`:v(document,t[i]);break;case`targetCss`:v(document,t[i]);break;case`shadowCss`:v(r,t[i]);break;case`shadowHtml`:r.innerHTML=t[i],x(r,e);break;case`targetHtml`:n.innerHTML=t[i],x(n,e);break}})}function b(e,t){let n=t=>{let n=t.match(/^([a-z]+)([A-Z][a-z]*)$/);return n?`./${e.replace(/-/g,`/`)}.${n[1]}.${n[2].toLowerCase()}`:`./${e.replace(/-/g,`/`)}.${t.toLowerCase()}`};return Promise.all(t.map(async e=>{let t=n(e);try{let n=await fetch(t);if(!n.ok)return`file not found: ${t}`;if(t.endsWith(`json`)){let r=await n.text();try{return JSON.parse(r)}catch{return console.error(`could not JSON.parse() asset '${e}' from ${t}:\n`,r),null}}return n.text()}catch{return`file not found: ${t}`}}))}function x(e,t){let n=[...e.querySelectorAll(`*`)];for(let e of n){if(!(e instanceof HTMLElement))continue;let n=[...e.attributes];for(let i of n){let n=i.name.toLowerCase();if(!(`on`+n in e))continue;let a=i.value.trim().split(`|`);if(a.length<2)continue;let[s,c,l]=a;e.removeAttribute(i.name);let u;if(l)try{u=JSON.parse(l)}catch{u=l}s===`this`||s===``?r(e,n,()=>t.trigger(c,u)):r(e,n,()=>o(s,c,u))}}}function S(e,t){return typeof HTMLElement<`u`&&e instanceof HTMLElement&&`_mc`in e&&(t===void 0||t in e._mc)}function C(e,t,n={}){let r=e;`_mc`in e||(r._mc=new j(e));let i=r._mc;return t.length&&!i[t]&&(i[t]=n,e instanceof HTMLElement&&!e.getAttribute(`data-mc`)&&e.setAttribute(`data-mc`,``)),r}function w(e,t){if(!t)return;let n=e._mc;n&&(n[t]&&delete n[t],!Object.keys(n).length&&e instanceof HTMLElement&&e.hasAttribute(`data-mc`)&&e.removeAttribute(`data-mc`))}function T(e){queueMicrotask(()=>{e.trigger(`Init`,null)})}function E(e){let t=e.target,n=Object.getPrototypeOf(e),i=e,a=Object.getOwnPropertyNames(n).filter(e=>/^(on[A-Z]|one[A-Z])/.test(e)&&typeof n[e]==`function`);for(let e of a){let n=/^one/.test(e);r(t,e.replace(/^one?/,``),t=>i[e](t),n)}}function D(e){return Array.from(e.querySelectorAll(`[data-mc]:not(:scope [data-mc] [data-mc])`)).filter(e=>e instanceof HTMLElement&&`_mc`in e).map(e=>e._mc)}function O(e,t){let n=e.parentElement?.closest(`[data-mc]`);for(;n instanceof HTMLElement;){if(`_mc`in n){let e=n._mc;if(t===void 0||t in e)return e}n=n.parentElement?.closest(`[data-mc]`)}return null}var k=class{_target;constructor(e){if(this._target=new WeakRef(e||{}),this instanceof j&&this.constructor!==j){E(this);let e=this.constructor.tag;(e===void 0||e.toUpperCase()===this.target.tagName)&&T(this)}}get target(){return this._target.deref()}},A=class extends k{constructor(e){super(e)}},j=class e extends k{static tag;static assets=[];static attributes={};constructor(t){super(t);let n=this.constructor,r=this.target.tagName.toLowerCase();if(n.tag!==void 0&&r!==n.tag&&n.tag!==``){let t=document.createElement(n.tag);t.classList.add(r),e.add(t,n.name,new n(t)),r.includes(`-`)&&!this.target.isConnected?this.on(`connected`,()=>this.target.replaceWith(t)):this.target.replaceWith(t);return}if(n.assets.length&&b(r,n.assets).then(e=>{let t=Object.fromEntries(n.assets.map((t,n)=>[t,e[n]]));y(this,t),this.trigger(`assets`,t)}),n.tag===``){this.target.remove();return}let i=n.attributes;n.attributes&&Object.keys(n.attributes).forEach(e=>{this.target.setAttribute(e,i[e])})}static add(e,t,n={}){return C(e,t,n)}static remove(e,t){w(e,t)}static get(e,t,n){if(!S(e))return;let r=e._mc[t];return r instanceof n?r:void 0}off(e,t){n(this.target,e,t)}on(e,t){return r(this.target,e,t)}one(e,t){return i(this.target,e,t)}trigger(e,t={},n=`l`,r){o(this.target,e,t,n,r)}ancestors(e){let t=[],n=O(this.target,e);for(;n;)t.push(n),n=O(n.target,e);return t}closest(e){return O(this.target,e)}children(e){let t=D(this.target);return e===void 0?t:t.filter(t=>e in t)}descendants(e){return Array.from(this.target.querySelectorAll(`[data-mc]`)).filter(e=>e instanceof HTMLElement&&`_mc`in e).map(e=>e._mc).filter(t=>e===void 0||e in t)}},M=new Set;function N(e){return()=>{let t=Array.from(document.querySelectorAll(`[data-mc*="${e}"]`)).filter(e=>e instanceof HTMLElement);if(t.length===0)return;let n=customElements.get(e);for(let r of t){try{j.add(r,n.name,new n(r))}catch{if(`create`in n&&typeof n.create==`function`){let e=n.create(r);if(!S(e))throw`create() of Class ${n.name} did not return a McHost.`;e.setAttribute(`data-mc`,r.getAttribute(`data-mc`)??``),r.replaceWith(e),r=e}else throw`Class ${n.name} doesn't have a callable constructor AND class doesn't have a static .create() method.`}let t=r.getAttribute(`data-mc`).split(` `).filter(t=>t!==e&&t!==``).join(` `).trim();r.setAttribute(`data-mc`,t)}}}function P(e){if(M.has(e))return;M.add(e);let t=`./`+e.split(`-`).join(`/`)+`.js`,n=document.createElement(`script`);n.setAttribute(`src`,t),n.setAttribute(`blocking`,`render`),n.async=!0,n.setAttribute(`type`,`module`),n.setAttribute(`data-name`,e),n.setAttribute(`loading`,``),customElements.whenDefined(e).then(N(e)),n.addEventListener(`load`,t=>{M.delete(e),document.head.querySelector(`script[data-name="${e}"]`)?.remove()}),n.addEventListener(`error`,e=>{console.error(`could not load DC code from`,t)}),document.head.append(n)}function F(){[...document.querySelectorAll(`:not(:defined)`)].filter(e=>!!e&&!customElements.get(e.tagName.toLowerCase())&&!M.has(e.tagName.toLowerCase())).forEach(e=>{P(e.tagName.toLowerCase())}),[...document.querySelectorAll(`[data-mc]:not([data-mc=""]`)].filter(e=>!!e).forEach(e=>{(e.getAttribute(`data-mc`)?.split(` `).filter(e=>e!==``))?.forEach(e=>{let t=customElements.get(e);!M.has(e)&&!t?P(e):t&&N(e)()})})}var I=null,L=function(e=!0){return e?I?!0:(I=new MutationObserver(F),setTimeout(()=>{I.observe(document.body,{childList:!0,subtree:!0}),F()},5),window.autoload??=L,!0):(I&&=(I.disconnect(),null),!1)};L.state=M;function ee(e,t){return Object.defineProperty(t,"name",{value:e})}function te(e){return class extends e{constructor(...e){super(...e)}}}function ne(e,t,n=[],r){if(customElements.get(e)){console.warn(`IGNORED: Custom element "${e}" is already defined!`);return}if(!e.includes(`-`))throw Error(`createCustomElement: tagName must contain at least one hyphen ("-").`);let i=HTMLElement;r&&(i=document.createElement(r).constructor);let a=m(e);if(!(t.prototype instanceof k))return customElements.define(e,t),t;let o=ee(a,class extends te(i){constructor(e){super(),j.add(this,a,new t(this,e))}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(e,t,n){this.dispatchEvent(new CustomEvent(`_mcAttributeChanged`,{detail:{name:e,oldValue:t,newValue:n}}))}formResetCallback(){this.dispatchEvent(new CustomEvent(`_mcFormReset`))}static get observedAttributes(){return[...n]}});return customElements.define(e,o,{extends:r}),o}function R(e){return customElements.get(e)}function z(e){let t=new Set,n=/\{[^\{\}]*\}/g;return(e.getAttributeNames?e.getAttributeNames():[]).filter(t=>e.getAttribute(t)?.match(n)).forEach(r=>{new Set(e.getAttribute(r)?.match(n)).forEach(e=>t.add(e.replace(/[\{\}]/g,``)))}),[...e.childNodes].filter(e=>e.nodeType===3&&(e.nodeValue||``).match(n)).forEach(e=>{(e?.nodeValue||``).match(n).forEach(e=>t.add(e.replace(/[\{\}]/g,``)))}),[...t]}var B=[`INPUT`,`SELECT`,`TEXTAREA`],V=class extends j{data={};oldDisplay=``;constructor(e){super(e),z(e).forEach(e=>this.data[e]=``),Y(this),this.#e()}#e(){let e=this.target,t=!1;(e.getAttributeNames?e.getAttributeNames():[]).filter(t=>e.getAttribute(t)?.match(/\{[^\{\}]*\}/g)).forEach(t=>{let n=new Set(e.getAttribute(t)?.match(/\{[^\{\}]*\}/g));this.data.subscribe((r=>i=>{let a=r;n.forEach(e=>{a=a.replace(e,String(i[e.replace(/[\{\}]/g,``)]))}),e.setAttribute(t,a)})(e.getAttribute(t)??``))}),[...e.childNodes].filter(e=>e.nodeType===3&&(e.nodeValue||``).match(/\{[^\{\}]*\}/g)).forEach(n=>{t=!0;let r=new Set((n.nodeValue??``).match(/\{[^\{\}]*\}/g));this.data.subscribe((t=>i=>{let a=t;r.forEach(e=>{a=a.replace(e,String(i[e.replace(/[\{\}]/g,``)]))}),this.oldDisplay?e.style=this.oldDisplay:e.removeAttribute(`style`),delete this.oldDisplay,n.nodeValue=a})(n.nodeValue??``)),this.oldDisplay=e.getAttribute(`style`)||``,t&&!B.includes(e.tagName)&&e.tagName!==`FIELDSET`&&(e.style.display=`none`)})}onData(e){let t={};Object.keys(e.detail.data).forEach(n=>{this.data.hasOwnProperty(n)&&(t[n]=e.detail.data[n])}),JSON.stringify(t)!==JSON.stringify(this.data)&&Object.assign(this.data,t)}};function H(e){return[e,...e.querySelectorAll(`*`)].filter(e=>!!z(e).length).filter(e=>e?.tagName!==`STYLE`).reverse()}function U(e){H(e).forEach(e=>{e?._mc?._placeholders||j.add(e,`_placeholders`,new V(e))})}function W(e){return typeof e==`object`&&!!e}var G={};function K(e){let t=e.constructor,n=t.name,r=class extends t{#e=!0;#t=[];constructor(e){super(e);let t=this.constructor;t.callbacks=[],W(e)&&Object.getOwnPropertyNames(e).forEach(t=>{this[t]=e[t]})}get callbacks(){return this.#t}set callbacks(e){this.#t=e}[Symbol.toPrimitive](e){let t=this.valueOf();return e===`string`?String(t):e===`number`?Number(t):t}subscribe(e){return this.#t.push(e),this}unsubscribe(e){return this.#t=this.#t.filter(t=>t!==e),this}bind(e){if(s()){if(W(this.valueOf())){U(e);let t=[e,...e.querySelectorAll(`[data-mc]`)].filter(e=>!!e?._mc?._placeholders);this.#t.push(function(e){let n=u(e);t.forEach(e=>{e&&o(e,`data`,n)})}),this.notify()}else console.warn(`IGNORED - cannot bind a non-Object to the dom, IS:`,typeof this.valueOf(),this);return this}}notify(e){let t=W(this.valueOf())&&!(this.valueOf()instanceof Array)?structuredClone(Object.assign({},this)):this.valueOf();return e!==void 0&&(this.#e=e),this.#e&&this.#t.forEach(e=>{e(t)}),this}};return G[n]=r,r}function q(e){return G[e.constructor.name]||K(e)}function J(e){return(typeof e==`object`||typeof e==`function`)&&e!==null&&`subscribe`in e}function Y(e,t){let n=e;return(t?[t]:[...Object.getOwnPropertyNames(e)]).forEach(t=>{let r=n[t];if(Object.prototype.hasOwnProperty.call(e,t)&&typeof r!=`function`&&!J(r)){if(t[0]===`_`||r===void 0)return;let i=r,a=new(q(i))(i),o=function(){queueMicrotask(function(){a.notify()})};Object.defineProperty(e,t,{enumerable:!0,get(){if(W(a.valueOf())){let e=structuredClone(Object.assign({},a));queueMicrotask(function(){d(structuredClone(Object.assign({},a)),e)||o()})}return a},set(e){if(typeof e==typeof a.valueOf())if(W(a.valueOf())&&!(a.valueOf()instanceof Array))J(a)||(a=new(q(e))(structuredClone(Object.assign({},e))),_(e,a)),Object.assign(a,e),a.notify();else{let t=a.valueOf(),n=a.callbacks;e!==t&&(a=new(q(e))(e),a.callbacks=n,o())}else console.warn(`IGNORED - cannot change observable types, IS:`,typeof a.valueOf(),a,`- CANNOT BECOME:`,typeof e)}}),n[t]=i}}),e}function X(e){let t=Object.getPrototypeOf(e.prototype);function n(e,t){let n=e[t];J(n)||Y(e,t)}Object.hasOwn(t,`notify`)||Object.assign(t,{notify:function(e){return n(this,e),this[e].notify(),this},subscribe:function(e,t){return n(this,e),this[e].subscribe(t),this},bind:function(e,t){return n(this,e),this[e].bind(t),this}})}X(j);var re=e=>e.tagName.toLowerCase(),Z=class{constructor(e){}},Q=class extends Z{#e;constructor(e){super(e),this.#e=e}get val(){return this.#e.form?new FormData(this.#e.form).get(this.#e.name)??null:null}set val(e){let t=[...this.#e.form?.querySelectorAll(`input[type="radio"][name="${this.#e.name}"]`)??[]];t.filter(t=>t.getAttribute(`value`)===e).shift().checked=!0}},ie=class extends Z{#e;constructor(e){super(e),this.#e=e}get val(){return this.#e.checked}set val(e){this.#e.checked=e}},ae=class extends Z{#e;constructor(e){super(e),this.#e=e}get val(){return this.#e.value}set val(e){this.#e.value=e}},oe=class extends Z{#e;#t=!1;constructor(e){super(e),this.#e=e,this.#t=e.multiple}get val(){let e=[];return[...this.#e.querySelectorAll(`option`)].filter(e=>e.selected).forEach(t=>{e.push(t.value)}),this.#t?e:e[0]}set val(e){e=typeof e==`string`?[e]:e,[...this.#e.querySelectorAll(`option`)].forEach(t=>{e.indexOf(t.value)>-1?t.selected=!0:t.selected=!1})}},se=class extends Z{#e;constructor(e){super(e),this.#e=e}get val(){return this.#e.value||``}set val(e){this.#e.value=e}},ce=e=>{let t=[...(e||document).querySelectorAll(`input,select,textarea`)],n={};return t.forEach(e=>{let t=e.getAttribute(`name`);if(t){let r=!1;switch(re(e)){case`input`:switch(e.type){case`radio`:r=new Q(e);break;case`checkbox`:r=new ie(e);break;default:r=new ae(e)}break;case`select`:r=new oe(e);break;case`textarea`:r=new se(e);break}if(r){let i=r;j.add(e,t,i),Object.defineProperty(n,t,{enumerable:!0,configurable:!0,get:()=>i.val,set:e=>{i.val!==e&&(i.val=e)}})}}}),n};function $(e,t,n){if(!s())return;let r=ce(n),i=e;i[t]=Object.assign({},r),Y(e,t);let a=i[t];_(r,a),[...n.querySelectorAll(`input, textarea, select`)].forEach(e=>{e.addEventListener(`input`,()=>{a.notify()})})}function le(e){let t=Object.getPrototypeOf(e.prototype);Object.hasOwn(t,`formValues`)||Object.assign(t,{formValues:function(e,t){return $(this,t,e),this}})}export{a as BubbleController,j as DC,A as MC,k as McBase,L as autoload,x as bindTemplateEvents,_ as copyGettersSetters,h as debounce,d as deepEqual,ne as defineCE,u as flattenObject,le as formValuePlugin,$ as formValues,R as getCE,e as getMcEventName,g as htmlToElements,v as injectCSS,J as isAlreadyObserved,s as isBrowser,S as isMcDOM,c as isNativeObject,m as kebabToPascal,b as loadAssets,f as nameSpace,Y as observe,X as observePlugin,n as off,r as on,i as one,p as parse,y as processAssets,l as sortObject,o as trigger,t as trueEventName};
@@ -1 +1 @@
1
- function e(){return typeof window<`u`&&window.document!==void 0}function t(e){return typeof e==`object`&&!!e&&e.constructor===Object}function n(e){let r={},i=Object.keys(e).sort();for(let a=0;a<i.length;a++){let o=i[a],s=e[o];t(s)?r[o]=n(s):r[o]=s}return r}function r(e,t=!0){let i={},a=e,o=Object.getOwnPropertyNames(e);for(let e=0;e<o.length;e++){let t=o[e],n=a[t];if(n instanceof Object){let e=r(n,!1);for(let n in e)i[t+`.`+n]=e[n]}else i[t]=n}return t?n(i):i}function i(e,t){if(e===t||e!==e&&t!==t)return!0;if(typeof e!=`object`||!e||typeof t!=`object`||!t||e.constructor!==t.constructor)return!1;if(e instanceof Date)return e.getTime()===t.getTime();if(e instanceof RegExp)return e.toString()===t.toString();if(Array.isArray(e)){let n=t;if(e.length!==n.length)return!1;for(let t=0;t<e.length;t++)if(!i(e[t],n[t]))return!1;return!0}let n=e,r=t,a=Object.keys(n);if(a.length!==Object.keys(r).length)return!1;for(let e=0;e<a.length;e++){let t=a[e];if(!Object.prototype.hasOwnProperty.call(r,t)||!i(n[t],r[t]))return!1}return!0}function a(e,t){let n=t.toLowerCase();return`on`+n in e?n:`_mc`+t[0].toUpperCase()+t.substring(1)}function o(e,t){let n=Object.getOwnPropertyDescriptors(e);for(let[e,r]of Object.entries(n))(`get`in r||`set`in r)&&Object.defineProperty(t,e,r)}function s(e,t,n){if(e){if(typeof e==`string`){document.querySelectorAll(e).forEach(e=>s(e,t,n));return}e.removeEventListener(a(e,t),n)}}function c(e,t,n,r=!1){if(e){if(typeof e==`string`){document.querySelectorAll(e).forEach(e=>c(e,t,n));return}return e.addEventListener(a(e,t),n,{capture:!1,once:r}),n}}function l(e,t,n){if(e){if(typeof e==`string`){document.querySelectorAll(e).forEach(e=>l(e,t,n));return}return c(e,t,n,!0),n}}var u=class{stopped=!1;constructor(){}stop(){this.stopped=!0}};function d(e,t,n={},r=`l`,i){if(!e)return;if(typeof e==`string`){document.querySelectorAll(e).forEach(e=>d(e,t,n,r));return}let o=/^_mc/.test(t)?t:a(e,t),s=i||new u,c=new CustomEvent(o,{detail:{data:n,control:s},bubbles:!1});s.stopped||/l/.test(r)&&(e.dispatchEvent(c),s.stopped)||/[ud]/.test(r)&&queueMicrotask(()=>{if(r.indexOf(`u`)>-1&&d(e.parentElement,o,n,`lu`,s),r.indexOf(`d`)>-1)for(let t of e.children)d(t,o,n,`ld`)})}function f(e,t){return typeof HTMLElement<`u`&&e instanceof HTMLElement&&`_mc`in e&&(t===void 0||t in e._mc)}function p(e,t,n={}){let r=e;`_mc`in e||(r._mc=new b(e));let i=r._mc;return t.length&&!i[t]&&(i[t]=n,e instanceof HTMLElement&&!e.getAttribute(`data-mc`)&&e.setAttribute(`data-mc`,``)),r}function m(e,t){if(!t)return;let n=e._mc;n&&(n[t]&&delete n[t],!Object.keys(n).length&&e instanceof HTMLElement&&e.hasAttribute(`data-mc`)&&e.removeAttribute(`data-mc`))}function h(e){queueMicrotask(()=>{e.trigger(`Init`)})}function g(e){let t=e.target,n=Object.getPrototypeOf(e),r=e,i=Object.getOwnPropertyNames(n).filter(e=>/^(on[A-Z]|one[A-Z])/.test(e)&&typeof n[e]==`function`);for(let e of i){let n=/^one/.test(e);c(t,e.replace(/^one?/,``),t=>r[e](t),n)}}function _(e){return Array.from(e.querySelectorAll(`[data-mc]:not(:scope [data-mc] [data-mc])`)).filter(e=>e instanceof HTMLElement&&`_mc`in e).map(e=>e._mc)}function v(e,t){let n=e.parentElement?.closest(`[data-mc]`);for(;n instanceof HTMLElement;){if(`_mc`in n){let e=n._mc;if(t===void 0||t in e)return e}n=n.parentElement?.closest(`[data-mc]`)}return null}var y=class{_target;constructor(e){this._target=new WeakRef(e||{}),this instanceof b&&(g(this),h(this))}get target(){return this._target.deref()}},b=class extends y{constructor(e){super(e)}static add(e,t,n={}){return p(e,t,n)}static remove(e,t){m(e,t)}static get(e,t,n){if(!f(e))return;let r=e._mc[t];return r instanceof n?r:void 0}off(e,t){s(this.target,e,t)}on(e,t){return c(this.target,e,t)}one(e,t){return l(this.target,e,t)}trigger(e,t={},n=`l`,r){d(this.target,e,t,n,r)}ancestors(e){let t=[],n=v(this.target,e);for(;n;)t.push(n),n=v(n.target,e);return t}closest(e){return v(this.target,e)}children(e){let t=_(this.target);return e===void 0?t:t.filter(t=>e in t)}descendants(e){return Array.from(this.target.querySelectorAll(`[data-mc]`)).filter(e=>e instanceof HTMLElement&&`_mc`in e).map(e=>e._mc).filter(t=>e===void 0||e in t)}};function x(e){let t=new Set,n=/\{[^\{\}]*\}/g;return(e.getAttributeNames?e.getAttributeNames():[]).filter(t=>e.getAttribute(t)?.match(n)).forEach(r=>{new Set(e.getAttribute(r)?.match(n)).forEach(e=>t.add(e.replace(/[\{\}]/g,``)))}),[...e.childNodes].filter(e=>e.nodeType===3&&(e.nodeValue||``).match(n)).forEach(e=>{(e?.nodeValue||``).match(n).forEach(e=>t.add(e.replace(/[\{\}]/g,``)))}),[...t]}var S=[`INPUT`,`SELECT`,`TEXTAREA`],C=class extends b{data={};oldDisplay=``;constructor(e){super(e),x(e).forEach(e=>this.data[e]=``),j(this),this.#attachCallbacks()}#attachCallbacks(){let e=this.target,t=!1;(e.getAttributeNames?e.getAttributeNames():[]).filter(t=>e.getAttribute(t)?.match(/\{[^\{\}]*\}/g)).forEach(t=>{let n=new Set(e.getAttribute(t)?.match(/\{[^\{\}]*\}/g));this.data.subscribe((r=>i=>{let a=r;n.forEach(e=>{a=a.replace(e,String(i[e.replace(/[\{\}]/g,``)]))}),e.setAttribute(t,a)})(e.getAttribute(t)??``))}),[...e.childNodes].filter(e=>e.nodeType===3&&(e.nodeValue||``).match(/\{[^\{\}]*\}/g)).forEach(n=>{t=!0;let r=new Set((n.nodeValue??``).match(/\{[^\{\}]*\}/g));this.data.subscribe((t=>i=>{let a=t;r.forEach(e=>{a=a.replace(e,String(i[e.replace(/[\{\}]/g,``)]))}),this.oldDisplay?e.style=this.oldDisplay:e.removeAttribute(`style`),delete this.oldDisplay,n.nodeValue=a})(n.nodeValue??``)),this.oldDisplay=e.getAttribute(`style`)||``,t&&!S.includes(e.tagName)&&e.tagName!==`FIELDSET`&&(e.style.display=`none`)})}onData(e){let t={};Object.keys(e.detail.data).forEach(n=>{this.data.hasOwnProperty(n)&&(t[n]=e.detail.data[n])}),JSON.stringify(t)!==JSON.stringify(this.data)&&Object.assign(this.data,t)}};function w(e){return[e,...e.querySelectorAll(`*`)].filter(e=>!!x(e).length).filter(e=>e?.tagName!==`STYLE`).reverse()}function T(e){w(e).forEach(e=>{e?._mc?._placeholders||b.add(e,`_placeholders`,new C(e))})}function E(e){return typeof e==`object`&&!!e}var D={};function O(t){let n=t.constructor,i=n.name,a=class extends n{#notify=!0;#callbacks=[];constructor(e){super(e);let t=this.constructor;t.callbacks=[],E(e)&&Object.getOwnPropertyNames(e).forEach(t=>{this[t]=e[t]})}get callbacks(){return this.#callbacks}set callbacks(e){this.#callbacks=e}[Symbol.toPrimitive](e){let t=this.valueOf();return e===`string`?String(t):e===`number`?Number(t):t}subscribe(e){return this.#callbacks.push(e),this}unsubscribe(e){return this.#callbacks=this.#callbacks.filter(t=>t!==e),this}bind(t){if(e()){if(E(this.valueOf())){T(t);let e=[t,...t.querySelectorAll(`[data-mc]`)].filter(e=>!!e?._mc?._placeholders);this.#callbacks.push(function(t){let n=r(t);e.forEach(e=>{e&&d(e,`data`,n)})}),this.notify()}else console.warn(`IGNORED - cannot bind a non-Object to the dom, IS:`,typeof this.valueOf(),this);return this}}notify(e){let t=E(this.valueOf())&&!(this.valueOf()instanceof Array)?structuredClone(Object.assign({},this)):this.valueOf();return e!==void 0&&(this.#notify=e),this.#notify&&this.#callbacks.forEach(e=>{e(t)}),this}};return D[i]=a,a}function k(e){return D[e.constructor.name]||O(e)}function A(e){return(typeof e==`object`||typeof e==`function`)&&e!==null&&`subscribe`in e}function j(e,t){let n=e;return(t?[t]:[...Object.getOwnPropertyNames(e)]).forEach(t=>{let r=n[t];if(Object.prototype.hasOwnProperty.call(e,t)&&typeof r!=`function`&&!A(r)){if(t[0]===`_`||r===void 0)return;let a=r,s=new(k(a))(a),c=function(){queueMicrotask(function(){s.notify()})};Object.defineProperty(e,t,{enumerable:!0,get(){if(E(s.valueOf())){let e=structuredClone(Object.assign({},s));queueMicrotask(function(){i(structuredClone(Object.assign({},s)),e)||c()})}return s},set(e){if(typeof e==typeof s.valueOf())if(E(s.valueOf())&&!(s.valueOf()instanceof Array))A(s)||(s=new(k(e))(structuredClone(Object.assign({},e))),o(e,s)),Object.assign(s,e),s.notify();else{let t=s.valueOf(),n=s.callbacks;e!==t&&(s=new(k(e))(e),s.callbacks=n,c())}else console.warn(`IGNORED - cannot change observable types, IS:`,typeof s.valueOf(),s,`- CANNOT BECOME:`,typeof e)}}),n[t]=a}}),e}export{A as isAlreadyObserved,j as observe};
1
+ function e(e,t){let n=t.toLowerCase();return`on`+n in e?n:`_mc`+t[0].toUpperCase()+t.substring(1)}function t(n,r,i){if(n){if(typeof n==`string`){document.querySelectorAll(n).forEach(e=>t(e,r,i));return}n.removeEventListener(e(n,r),i)}}function n(t,r,i,a=!1){if(t){if(typeof t==`string`){document.querySelectorAll(t).forEach(e=>n(e,r,i));return}return t.addEventListener(e(t,r),i,{capture:!1,once:a}),i}}function r(e,t,i){if(e){if(typeof e==`string`){document.querySelectorAll(e).forEach(e=>r(e,t,i));return}return n(e,t,i,!0),i}}var i=class{stopped=!1;constructor(){}stop(){this.stopped=!0}};function a(t,n,r={},o=`l`,s){if(!t)return;if(typeof t==`string`){document.querySelectorAll(t).forEach(e=>a(e,n,r,o));return}let c=/^_mc/.test(n)?n:e(t,n),l=s||new i,u=new CustomEvent(c,{detail:{data:r,control:l},bubbles:!1});l.stopped||/l/.test(o)&&(t.dispatchEvent(u),l.stopped)||/[ud]/.test(o)&&queueMicrotask(()=>{if(o.indexOf(`u`)>-1&&a(t.parentElement,c,r,`lu`,l),o.indexOf(`d`)>-1)for(let e of t.children)a(e,c,r,`ld`)})}function o(){return typeof window<`u`&&window.document!==void 0}function s(e){return typeof e==`object`&&!!e&&e.constructor===Object}function c(e){let t={},n=Object.keys(e).sort();for(let r=0;r<n.length;r++){let i=n[r],a=e[i];s(a)?t[i]=c(a):t[i]=a}return t}function l(e,t=!0){let n={},r=e,i=Object.getOwnPropertyNames(e);for(let e=0;e<i.length;e++){let t=i[e],a=r[t];if(a instanceof Object){let e=l(a,!1);for(let r in e)n[t+`.`+r]=e[r]}else n[t]=a}return t?c(n):n}function u(e,t){if(e===t||e!==e&&t!==t)return!0;if(typeof e!=`object`||!e||typeof t!=`object`||!t||e.constructor!==t.constructor)return!1;if(e instanceof Date)return e.getTime()===t.getTime();if(e instanceof RegExp)return e.toString()===t.toString();if(Array.isArray(e)){let n=t;if(e.length!==n.length)return!1;for(let t=0;t<e.length;t++)if(!u(e[t],n[t]))return!1;return!0}let n=e,r=t,i=Object.keys(n);if(i.length!==Object.keys(r).length)return!1;for(let e=0;e<i.length;e++){let t=i[e];if(!Object.prototype.hasOwnProperty.call(r,t)||!u(n[t],r[t]))return!1}return!0}function d(e,t){let n=Object.getOwnPropertyDescriptors(e);for(let[e,r]of Object.entries(n))(`get`in r||`set`in r)&&Object.defineProperty(t,e,r)}function f(e,t){let n=new CSSStyleSheet;return n.replaceSync(t),e.adoptedStyleSheets.push(n),n}function p(e,t){let n=e.target,r=n.shadowRoot;!r&&Object.keys(t).some(e=>e.indexOf(`shadow`)===0)&&(r=n.attachShadow({mode:`open`})),Object.keys(t).forEach(i=>{switch(i){case`css`:f(document,t[i]);break;case`targetCss`:f(document,t[i]);break;case`shadowCss`:f(r,t[i]);break;case`shadowHtml`:r.innerHTML=t[i],h(r,e);break;case`targetHtml`:n.innerHTML=t[i],h(n,e);break}})}function m(e,t){let n=t=>{let n=t.match(/^([a-z]+)([A-Z][a-z]*)$/);return n?`./${e.replace(/-/g,`/`)}.${n[1]}.${n[2].toLowerCase()}`:`./${e.replace(/-/g,`/`)}.${t.toLowerCase()}`};return Promise.all(t.map(async e=>{let t=n(e);try{let n=await fetch(t);if(!n.ok)return`file not found: ${t}`;if(t.endsWith(`json`)){let r=await n.text();try{return JSON.parse(r)}catch{return console.error(`could not JSON.parse() asset '${e}' from ${t}:\n`,r),null}}return n.text()}catch{return`file not found: ${t}`}}))}function h(e,t){let r=[...e.querySelectorAll(`*`)];for(let e of r){if(!(e instanceof HTMLElement))continue;let r=[...e.attributes];for(let i of r){let r=i.name.toLowerCase();if(!(`on`+r in e))continue;let o=i.value.trim().split(`|`);if(o.length<2)continue;let[s,c,l]=o;e.removeAttribute(i.name);let u;if(l)try{u=JSON.parse(l)}catch{u=l}s===`this`||s===``?n(e,r,()=>t.trigger(c,u)):n(e,r,()=>a(s,c,u))}}}function g(e,t){return typeof HTMLElement<`u`&&e instanceof HTMLElement&&`_mc`in e&&(t===void 0||t in e._mc)}function _(e,t,n={}){let r=e;`_mc`in e||(r._mc=new w(e));let i=r._mc;return t.length&&!i[t]&&(i[t]=n,e instanceof HTMLElement&&!e.getAttribute(`data-mc`)&&e.setAttribute(`data-mc`,``)),r}function v(e,t){if(!t)return;let n=e._mc;n&&(n[t]&&delete n[t],!Object.keys(n).length&&e instanceof HTMLElement&&e.hasAttribute(`data-mc`)&&e.removeAttribute(`data-mc`))}function y(e){queueMicrotask(()=>{e.trigger(`Init`,null)})}function b(e){let t=e.target,r=Object.getPrototypeOf(e),i=e,a=Object.getOwnPropertyNames(r).filter(e=>/^(on[A-Z]|one[A-Z])/.test(e)&&typeof r[e]==`function`);for(let e of a){let r=/^one/.test(e);n(t,e.replace(/^one?/,``),t=>i[e](t),r)}}function x(e){return Array.from(e.querySelectorAll(`[data-mc]:not(:scope [data-mc] [data-mc])`)).filter(e=>e instanceof HTMLElement&&`_mc`in e).map(e=>e._mc)}function S(e,t){let n=e.parentElement?.closest(`[data-mc]`);for(;n instanceof HTMLElement;){if(`_mc`in n){let e=n._mc;if(t===void 0||t in e)return e}n=n.parentElement?.closest(`[data-mc]`)}return null}var C=class{_target;constructor(e){if(this._target=new WeakRef(e||{}),this instanceof w&&this.constructor!==w){b(this);let e=this.constructor.tag;(e===void 0||e.toUpperCase()===this.target.tagName)&&y(this)}}get target(){return this._target.deref()}},w=class e extends C{static tag;static assets=[];static attributes={};constructor(t){super(t);let n=this.constructor,r=this.target.tagName.toLowerCase();if(n.tag!==void 0&&r!==n.tag&&n.tag!==``){let t=document.createElement(n.tag);t.classList.add(r),e.add(t,n.name,new n(t)),r.includes(`-`)&&!this.target.isConnected?this.on(`connected`,()=>this.target.replaceWith(t)):this.target.replaceWith(t);return}if(n.assets.length&&m(r,n.assets).then(e=>{let t=Object.fromEntries(n.assets.map((t,n)=>[t,e[n]]));p(this,t),this.trigger(`assets`,t)}),n.tag===``){this.target.remove();return}let i=n.attributes;n.attributes&&Object.keys(n.attributes).forEach(e=>{this.target.setAttribute(e,i[e])})}static add(e,t,n={}){return _(e,t,n)}static remove(e,t){v(e,t)}static get(e,t,n){if(!g(e))return;let r=e._mc[t];return r instanceof n?r:void 0}off(e,n){t(this.target,e,n)}on(e,t){return n(this.target,e,t)}one(e,t){return r(this.target,e,t)}trigger(e,t={},n=`l`,r){a(this.target,e,t,n,r)}ancestors(e){let t=[],n=S(this.target,e);for(;n;)t.push(n),n=S(n.target,e);return t}closest(e){return S(this.target,e)}children(e){let t=x(this.target);return e===void 0?t:t.filter(t=>e in t)}descendants(e){return Array.from(this.target.querySelectorAll(`[data-mc]`)).filter(e=>e instanceof HTMLElement&&`_mc`in e).map(e=>e._mc).filter(t=>e===void 0||e in t)}};function T(e){let t=new Set,n=/\{[^\{\}]*\}/g;return(e.getAttributeNames?e.getAttributeNames():[]).filter(t=>e.getAttribute(t)?.match(n)).forEach(r=>{new Set(e.getAttribute(r)?.match(n)).forEach(e=>t.add(e.replace(/[\{\}]/g,``)))}),[...e.childNodes].filter(e=>e.nodeType===3&&(e.nodeValue||``).match(n)).forEach(e=>{(e?.nodeValue||``).match(n).forEach(e=>t.add(e.replace(/[\{\}]/g,``)))}),[...t]}var E=[`INPUT`,`SELECT`,`TEXTAREA`],D=class extends w{data={};oldDisplay=``;constructor(e){super(e),T(e).forEach(e=>this.data[e]=``),F(this),this.#e()}#e(){let e=this.target,t=!1;(e.getAttributeNames?e.getAttributeNames():[]).filter(t=>e.getAttribute(t)?.match(/\{[^\{\}]*\}/g)).forEach(t=>{let n=new Set(e.getAttribute(t)?.match(/\{[^\{\}]*\}/g));this.data.subscribe((r=>i=>{let a=r;n.forEach(e=>{a=a.replace(e,String(i[e.replace(/[\{\}]/g,``)]))}),e.setAttribute(t,a)})(e.getAttribute(t)??``))}),[...e.childNodes].filter(e=>e.nodeType===3&&(e.nodeValue||``).match(/\{[^\{\}]*\}/g)).forEach(n=>{t=!0;let r=new Set((n.nodeValue??``).match(/\{[^\{\}]*\}/g));this.data.subscribe((t=>i=>{let a=t;r.forEach(e=>{a=a.replace(e,String(i[e.replace(/[\{\}]/g,``)]))}),this.oldDisplay?e.style=this.oldDisplay:e.removeAttribute(`style`),delete this.oldDisplay,n.nodeValue=a})(n.nodeValue??``)),this.oldDisplay=e.getAttribute(`style`)||``,t&&!E.includes(e.tagName)&&e.tagName!==`FIELDSET`&&(e.style.display=`none`)})}onData(e){let t={};Object.keys(e.detail.data).forEach(n=>{this.data.hasOwnProperty(n)&&(t[n]=e.detail.data[n])}),JSON.stringify(t)!==JSON.stringify(this.data)&&Object.assign(this.data,t)}};function O(e){return[e,...e.querySelectorAll(`*`)].filter(e=>!!T(e).length).filter(e=>e?.tagName!==`STYLE`).reverse()}function k(e){O(e).forEach(e=>{e?._mc?._placeholders||w.add(e,`_placeholders`,new D(e))})}function A(e){return typeof e==`object`&&!!e}var j={};function M(e){let t=e.constructor,n=t.name,r=class extends t{#e=!0;#t=[];constructor(e){super(e);let t=this.constructor;t.callbacks=[],A(e)&&Object.getOwnPropertyNames(e).forEach(t=>{this[t]=e[t]})}get callbacks(){return this.#t}set callbacks(e){this.#t=e}[Symbol.toPrimitive](e){let t=this.valueOf();return e===`string`?String(t):e===`number`?Number(t):t}subscribe(e){return this.#t.push(e),this}unsubscribe(e){return this.#t=this.#t.filter(t=>t!==e),this}bind(e){if(o()){if(A(this.valueOf())){k(e);let t=[e,...e.querySelectorAll(`[data-mc]`)].filter(e=>!!e?._mc?._placeholders);this.#t.push(function(e){let n=l(e);t.forEach(e=>{e&&a(e,`data`,n)})}),this.notify()}else console.warn(`IGNORED - cannot bind a non-Object to the dom, IS:`,typeof this.valueOf(),this);return this}}notify(e){let t=A(this.valueOf())&&!(this.valueOf()instanceof Array)?structuredClone(Object.assign({},this)):this.valueOf();return e!==void 0&&(this.#e=e),this.#e&&this.#t.forEach(e=>{e(t)}),this}};return j[n]=r,r}function N(e){return j[e.constructor.name]||M(e)}function P(e){return(typeof e==`object`||typeof e==`function`)&&e!==null&&`subscribe`in e}function F(e,t){let n=e;return(t?[t]:[...Object.getOwnPropertyNames(e)]).forEach(t=>{let r=n[t];if(Object.prototype.hasOwnProperty.call(e,t)&&typeof r!=`function`&&!P(r)){if(t[0]===`_`||r===void 0)return;let i=r,a=new(N(i))(i),o=function(){queueMicrotask(function(){a.notify()})};Object.defineProperty(e,t,{enumerable:!0,get(){if(A(a.valueOf())){let e=structuredClone(Object.assign({},a));queueMicrotask(function(){u(structuredClone(Object.assign({},a)),e)||o()})}return a},set(e){if(typeof e==typeof a.valueOf())if(A(a.valueOf())&&!(a.valueOf()instanceof Array))P(a)||(a=new(N(e))(structuredClone(Object.assign({},e))),d(e,a)),Object.assign(a,e),a.notify();else{let t=a.valueOf(),n=a.callbacks;e!==t&&(a=new(N(e))(e),a.callbacks=n,o())}else console.warn(`IGNORED - cannot change observable types, IS:`,typeof a.valueOf(),a,`- CANNOT BECOME:`,typeof e)}}),n[t]=i}}),e}function I(e){let t=Object.getPrototypeOf(e.prototype);function n(e,t){let n=e[t];P(n)||F(e,t)}Object.hasOwn(t,`notify`)||Object.assign(t,{notify:function(e){return n(this,e),this[e].notify(),this},subscribe:function(e,t){return n(this,e),this[e].subscribe(t),this},bind:function(e,t){return n(this,e),this[e].bind(t),this}})}export{P as isAlreadyObserved,F as observe,I as observePlugin};