@twobirds/microcomponents 0.0.34 → 0.0.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -27
- package/assets/documentation/{MicroComponents.md → MC.md} +17 -17
- package/assets/documentation/comparision.md +0 -0
- package/assets/documentation/elements.md +276 -0
- package/assets/documentation/magic.md +10 -68
- package/assets/my-tag.css +6 -2
- package/dist/MC.d.ts +3 -4
- package/dist/MC.d.ts.map +1 -1
- package/dist/MC.min.js +89 -66
- package/dist/MC.ts +213 -178
- package/dist/autoloader.ts +1 -1
- package/dist/{customElements.d.ts → elements.d.ts} +1 -1
- package/dist/elements.d.ts.map +1 -0
- package/dist/elements.min.js +1 -0
- package/dist/{customElements.ts → elements.ts} +23 -14
- package/dist/helpers.d.ts +6 -4
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.ts +95 -128
- package/dist/microcomponents.d.ts +3 -3
- package/dist/microcomponents.d.ts.map +1 -1
- package/dist/microcomponents.min.js +1 -1
- package/dist/microcomponents.ts +3 -3
- package/dist/{customObservables.d.ts → observables.d.ts} +3 -3
- package/dist/observables.d.ts.map +1 -0
- package/dist/observables.min.js +1 -0
- package/dist/observables.ts +353 -0
- package/dist/{customSelectors.d.ts → selectors.d.ts} +1 -1
- package/dist/selectors.d.ts.map +1 -0
- package/dist/selectors.min.js +1 -0
- package/dist/test.ts +135 -156
- package/klemmstein.png +0 -0
- package/package.json +52 -52
- package/public/MC.js +90 -67
- package/public/MC.js.map +1 -1
- package/public/MC.min.js +89 -66
- package/public/assets/search.js +1 -1
- package/public/autoloader.js +1 -1
- package/public/autoloader.js.map +1 -1
- package/public/classes/{DC.html → MC.DC.html} +60 -59
- package/public/classes/{MC.html → MC.MC.html} +41 -35
- package/public/classes/{McBase.html → MC.McBase.html} +28 -20
- package/public/classes/{McEvent.html → MC.McEvent.html} +48 -42
- package/public/documentation/{MicroComponents.md → MC.md} +17 -17
- package/public/documentation/comparision.md +0 -0
- package/public/documentation/elements.md +276 -0
- package/public/documentation/magic.md +10 -68
- package/public/{customElements.js → elements.js} +9 -10
- package/public/elements.js.map +1 -0
- package/public/elements.min.js +1 -0
- package/public/functions/{addListener.html → MC.addListener.html} +18 -12
- package/public/functions/{removeListener.html → MC.removeListener.html} +18 -12
- package/public/functions/elements.defineCE.html +78 -0
- package/public/functions/elements.getCE.html +63 -0
- package/public/functions/formValues.formValues.html +68 -0
- package/public/functions/observables.observe.html +65 -0
- package/public/functions/selectors._d.html +69 -0
- package/public/functions/selectors._t.html +69 -0
- package/public/helpers.js +66 -89
- package/public/helpers.js.map +1 -1
- package/public/index.html +48 -33
- package/public/interfaces/{HTMLMcElement.html → MC.HTMLMcElement.html} +601 -595
- package/public/interfaces/selectors.DSelector.html +1013 -0
- package/public/interfaces/selectors.TSelector.html +712 -0
- package/public/microcomponents.js +3 -3
- package/public/microcomponents.js.map +1 -1
- package/public/microcomponents.min.js +1 -1
- package/public/modules/MC.html +78 -0
- package/public/modules/elements.html +62 -0
- package/public/modules/formValues.html +60 -0
- package/public/modules/observables.html +65 -0
- package/public/modules/selectors.html +76 -0
- package/public/modules.html +11 -23
- package/public/my-tag.css +6 -2
- package/public/observables.js +259 -0
- package/public/observables.js.map +1 -0
- package/public/observables.min.js +1 -0
- package/public/{customSelectors.js → selectors.js} +1 -1
- package/public/selectors.js.map +1 -0
- package/public/selectors.min.js +1 -0
- package/public/src/MC.ts +413 -0
- package/public/src/McEvent.ts +96 -0
- package/public/src/autoloader.ts +98 -0
- package/{src/customElements.ts → public/src/elements.ts} +23 -14
- package/public/src/formValues.ts +275 -0
- package/public/src/helpers.ts +140 -0
- package/public/src/microcomponents.ts +8 -0
- package/public/src/observables.ts +353 -0
- package/public/src/test.ts +190 -0
- package/public/test.js +93 -118
- package/public/test.js.map +1 -1
- package/public/types/observables.Observable.html +91 -0
- package/public/types/selectors.selection.html +58 -0
- package/public/types/selectors.singleSelector.html +58 -0
- package/src/MC.ts +213 -178
- package/src/autoloader.ts +1 -1
- package/src/elements.ts +76 -0
- package/src/helpers.ts +95 -128
- package/src/microcomponents.ts +3 -3
- package/src/observables.ts +353 -0
- package/src/selectors.ts +1634 -0
- package/src/test.ts +135 -156
- package/typedoc.json +1 -1
- package/webpack.config.js +9 -9
- package/dist/customElements.d.ts.map +0 -1
- package/dist/customElements.min.js +0 -1
- package/dist/customObservables.d.ts.map +0 -1
- package/dist/customObservables.min.js +0 -1
- package/dist/customObservables.ts +0 -348
- package/dist/customSelectors.d.ts.map +0 -1
- package/dist/customSelectors.min.js +0 -1
- package/public/customElements.js.map +0 -1
- package/public/customElements.min.js +0 -1
- package/public/customObservables.js +0 -256
- package/public/customObservables.js.map +0 -1
- package/public/customObservables.min.js +0 -1
- package/public/customSelectors.js.map +0 -1
- package/public/customSelectors.min.js +0 -1
- package/src/customObservables.ts +0 -348
- /package/dist/{customSelectors.ts → selectors.ts} +0 -0
- /package/{src/customSelectors.ts → public/src/selectors.ts} +0 -0
package/src/test.ts
CHANGED
|
@@ -1,211 +1,190 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
LooseObject,
|
|
5
|
+
MC,
|
|
6
|
+
DC,
|
|
7
|
+
McEvent,
|
|
8
|
+
defineCE,
|
|
9
|
+
getCE,
|
|
10
|
+
observe,
|
|
11
|
+
Observable,
|
|
12
|
+
} from './microcomponents.js';
|
|
13
|
+
|
|
14
|
+
//import { MC, DC, McEvent } from "./MC.js";
|
|
15
|
+
//import { defineCE, getCE } from "./elements.js";
|
|
16
|
+
//import { observe } from "./observables.js";
|
|
8
17
|
|
|
9
18
|
//MC.debug = true;
|
|
10
19
|
|
|
11
|
-
class
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
sum(...numbers: number[]): number {
|
|
15
|
-
return numbers.reduce((acc: number, curr: number) => acc + curr, 0);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
20
|
+
class Translator extends DC {
|
|
21
|
+
#translations: LooseObject = {};
|
|
18
22
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
super(target);
|
|
22
|
-
}
|
|
23
|
+
Language: unknown = 'en';
|
|
24
|
+
Translation: unknown = {};
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
constructor(
|
|
27
|
+
target: HTMLElement | ShadowRoot | DocumentFragment,
|
|
28
|
+
translations: LooseObject,
|
|
29
|
+
translationTargetObject: HTMLElement
|
|
30
|
+
) {
|
|
31
|
+
super(target as HTMLElement);
|
|
32
|
+
let that = this; // minifier help
|
|
29
33
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
+
// state
|
|
35
|
+
that.Language = 'en';
|
|
36
|
+
that.Translation = {};
|
|
34
37
|
|
|
35
|
-
|
|
36
|
-
let logger = this.target?.target?._mc?.logger;
|
|
37
|
-
logger?.log("onCustomEvent", ev);
|
|
38
|
-
}
|
|
38
|
+
observe(that);
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
_mc = that._mc!,
|
|
43
|
-
logger = this.target?.target?._mc?.logger;
|
|
40
|
+
// setup
|
|
41
|
+
that.#translations = translations;
|
|
44
42
|
|
|
45
|
-
//
|
|
43
|
+
// state
|
|
44
|
+
(that.Language as Observable).observe((lang) => {
|
|
45
|
+
if (that.#translations.hasOwnProperty(lang)) {
|
|
46
|
+
that.Translation = { lang: that.#translations[lang] }; // set translation
|
|
47
|
+
}
|
|
48
|
+
});
|
|
46
49
|
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
+
(that.Translation as Observable).bind(translationTargetObject);
|
|
50
51
|
|
|
51
|
-
|
|
52
|
+
this.target.setAttribute('language', 'en');
|
|
52
53
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
stdOut: typeof console = console;
|
|
56
|
-
|
|
57
|
-
constructor(target: HTMLElement, logger: typeof console, prefix: string) {
|
|
58
|
-
// logger must implement the console interface
|
|
59
|
-
super(target);
|
|
60
|
-
|
|
61
|
-
let that = this; // scoping and minifier help
|
|
62
|
-
|
|
63
|
-
that.prefix = prefix;
|
|
64
|
-
|
|
65
|
-
// instance that handles logging, depency injection
|
|
66
|
-
that.stdOut = logger;
|
|
54
|
+
(this.Language as Observable).notify();
|
|
67
55
|
}
|
|
68
56
|
|
|
69
|
-
|
|
70
|
-
|
|
57
|
+
oneInit() {
|
|
58
|
+
//(this.Language as Observable).notify(); // trigger translation
|
|
71
59
|
}
|
|
72
60
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
61
|
+
onAttributeChanged(ev: McEvent) {
|
|
62
|
+
if (!ev.data.newValue) return;
|
|
63
|
+
|
|
64
|
+
let that = this;
|
|
65
|
+
|
|
66
|
+
switch (ev.data.name) {
|
|
67
|
+
case 'language':
|
|
68
|
+
that.Language = ev.data.newValue;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
78
71
|
}
|
|
79
72
|
}
|
|
80
73
|
|
|
81
74
|
defineCE(
|
|
82
75
|
// equivalent to custom element registry .define()
|
|
83
|
-
|
|
76
|
+
'my-tag',
|
|
84
77
|
class MyTag extends DC {
|
|
78
|
+
#template: string = '<button>{lang.click} {counter}</button>';
|
|
85
79
|
|
|
86
|
-
|
|
80
|
+
#languages = {
|
|
81
|
+
en: {
|
|
82
|
+
click: 'click me',
|
|
83
|
+
},
|
|
84
|
+
de: {
|
|
85
|
+
click: 'klick mich',
|
|
86
|
+
},
|
|
87
|
+
};
|
|
87
88
|
|
|
88
|
-
|
|
89
|
+
Dom: LooseObject = {};
|
|
89
90
|
|
|
90
|
-
constructor(target: HTMLElement
|
|
91
|
+
constructor(target: HTMLElement) {
|
|
91
92
|
super(target);
|
|
92
93
|
|
|
93
94
|
let that = this; // minifier help
|
|
94
95
|
|
|
95
|
-
//
|
|
96
|
-
|
|
97
|
-
that.Counter = 0;
|
|
98
|
-
|
|
99
|
-
// convert all props defined so far into custom observables
|
|
100
|
-
observe(that);
|
|
101
|
-
|
|
102
|
-
DC.add(target, "logger", new Logger(target, console, "[logger]"));
|
|
96
|
+
// hide
|
|
97
|
+
target.setAttribute('style', 'display:none');
|
|
103
98
|
|
|
104
99
|
// render
|
|
105
|
-
target.innerHTML =
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
//this.target._mc?.logger.info("onConnected handler", ev);
|
|
100
|
+
target.innerHTML = this.#template;
|
|
101
|
+
|
|
102
|
+
// add public translator
|
|
103
|
+
DC.add(
|
|
104
|
+
target,
|
|
105
|
+
'translator',
|
|
106
|
+
new Translator(target, that.#languages, target)
|
|
107
|
+
);
|
|
114
108
|
}
|
|
115
109
|
|
|
116
|
-
|
|
117
|
-
let
|
|
118
|
-
//logger?.info("onAttributeChanged handler", ev);
|
|
119
|
-
}
|
|
110
|
+
oneInit(ev: McEvent) {
|
|
111
|
+
let that = this;
|
|
120
112
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
*/
|
|
124
|
-
oneClick(ev: typeof McEvent) {
|
|
125
|
-
let logger = this.target._mc?.logger;
|
|
113
|
+
// state
|
|
114
|
+
that.Dom = { counter: 0 };
|
|
126
115
|
|
|
127
|
-
|
|
116
|
+
// state: convert all props defined so far into observables
|
|
117
|
+
observe(that);
|
|
128
118
|
|
|
129
|
-
|
|
119
|
+
// bind Dom to target
|
|
120
|
+
(that.Dom as Observable).bind(that.target);
|
|
130
121
|
|
|
131
|
-
|
|
122
|
+
// show
|
|
123
|
+
setTimeout(() => that.target.removeAttribute('style'), 100);
|
|
132
124
|
}
|
|
133
125
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
logger?.info("onClick handler", ev);
|
|
138
|
-
|
|
139
|
-
this.Counter++;
|
|
126
|
+
onAttributeChanged(ev: McEvent) {
|
|
127
|
+
//console.log(ev);
|
|
128
|
+
this.target._mc.translator.Language = ev.data.newValue;
|
|
140
129
|
}
|
|
141
130
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
oneInit(ev: typeof McEvent) {
|
|
146
|
-
let that = this,
|
|
147
|
-
_mc = that._mc;
|
|
148
|
-
|
|
149
|
-
let logger = that.target._mc.logger;
|
|
150
|
-
|
|
151
|
-
//logger.warn("oneInit handler", ev);
|
|
152
|
-
|
|
153
|
-
// add a private event target
|
|
154
|
-
_mc.customEventTarget = new EvTarget(that);
|
|
155
|
-
|
|
156
|
-
// add a private adder
|
|
157
|
-
_mc.Adder = new Adder();
|
|
158
|
-
|
|
159
|
-
// add callback for this.Counter changes
|
|
160
|
-
( that.Counter as any).observe((value: number) => {
|
|
161
|
-
logger.log("Counter has changed to: " + value);
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
//logger.log("add 1,2,3 =", _mc.Adder.sum(1, 2, 3));
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
onDoSomething(ev: typeof McEvent) {
|
|
168
|
-
let logger = this.target._mc?.logger;
|
|
169
|
-
logger?.log(".onDoSomething(ev): something done...", ev);
|
|
131
|
+
onClick(ev: McEvent) {
|
|
132
|
+
this.Dom.counter++;
|
|
133
|
+
(this.target as HTMLElement).classList.add('clicked');
|
|
170
134
|
}
|
|
171
135
|
},
|
|
172
|
-
[
|
|
136
|
+
['language']
|
|
173
137
|
);
|
|
174
138
|
|
|
175
|
-
let MyTag: CustomElementConstructor = getCE(
|
|
139
|
+
let MyTag: CustomElementConstructor = getCE('my-tag')!,
|
|
176
140
|
fragment = new DocumentFragment();
|
|
177
141
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
142
|
+
/*
|
|
143
|
+
stress test
|
|
144
|
+
*/
|
|
145
|
+
|
|
146
|
+
let start = new Date().getTime();
|
|
147
|
+
|
|
148
|
+
// create 100 elements
|
|
149
|
+
for (let x = 0; x < 100; x++) {
|
|
150
|
+
fragment.append(new MyTag());
|
|
183
151
|
}
|
|
184
|
-
document.body.appendChild( fragment );
|
|
185
152
|
|
|
186
|
-
|
|
187
|
-
'%c \n\nStress Test:\n\n %cInstancing 1000 classes and putting them in the DOM took (ms):',
|
|
188
|
-
"font-weight: bold; color: black;",
|
|
189
|
-
"color: black;"
|
|
190
|
-
);
|
|
191
|
-
console.timeEnd("Instancing");
|
|
153
|
+
let end = new Date().getTime();
|
|
192
154
|
|
|
193
|
-
|
|
155
|
+
// and put them into the DOM
|
|
156
|
+
document.body.appendChild(fragment);
|
|
194
157
|
|
|
195
|
-
//
|
|
158
|
+
//document.querySelectorAll('my-tag').forEach((e) => e.remove());
|
|
196
159
|
|
|
197
|
-
|
|
160
|
+
/*
|
|
161
|
+
console test
|
|
162
|
+
*/
|
|
198
163
|
|
|
199
|
-
|
|
164
|
+
setTimeout(() => {
|
|
165
|
+
console.clear();
|
|
200
166
|
|
|
201
|
-
console.log(
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
167
|
+
console.log(
|
|
168
|
+
'%c \n\nStress Test:\n\n %cInstancing 100 web components: %c %s ms.',
|
|
169
|
+
'font-weight: bold; color: black;',
|
|
170
|
+
'font-weight: normal;',
|
|
171
|
+
'font-weight: bold; color: blue;',
|
|
172
|
+
end - start
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
document.body.appendChild(new MyTag());
|
|
176
|
+
|
|
177
|
+
let element = document.querySelector('my-tag');
|
|
178
|
+
|
|
179
|
+
console.log(
|
|
180
|
+
"\n\n%cInspect this tag:%c \n( ...to see the inner structure in the '._mc' property )\n\n %O %c %s",
|
|
181
|
+
'font-weight: bold;',
|
|
182
|
+
'font-weight: normal;',
|
|
183
|
+
element,
|
|
184
|
+
'font-weight: bold;',
|
|
185
|
+
'\n\nLook up code in the debugger: test.js\n\n'
|
|
186
|
+
);
|
|
209
187
|
|
|
210
|
-
// will trigger the event on all micro components contained in <my-tag>
|
|
211
|
-
DC.trigger(element,
|
|
188
|
+
// will trigger the event on all micro components contained in <my-tag>
|
|
189
|
+
DC.trigger(element, 'doSomething');
|
|
190
|
+
}, 500);
|
package/typedoc.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"entryPoints": ["src/
|
|
2
|
+
"entryPoints": ["src/MC.ts","src/elements.ts","src/observables.ts","src/formValues.ts","src/selectors.ts"],
|
|
3
3
|
"out": "./public/",
|
|
4
4
|
"readme": "README.md",
|
|
5
5
|
"name": "Micro Components",
|
package/webpack.config.js
CHANGED
|
@@ -40,13 +40,13 @@ module.exports = [
|
|
|
40
40
|
},
|
|
41
41
|
},
|
|
42
42
|
{
|
|
43
|
-
entry: "./build/
|
|
43
|
+
entry: "./build/elements.js",
|
|
44
44
|
mode: "production",
|
|
45
45
|
output: {
|
|
46
46
|
path: path.resolve(__dirname, "dist"),
|
|
47
|
-
filename: "
|
|
47
|
+
filename: "elements.min.js",
|
|
48
48
|
libraryTarget: "umd",
|
|
49
|
-
library: "
|
|
49
|
+
library: "elements",
|
|
50
50
|
globalObject: "this",
|
|
51
51
|
},
|
|
52
52
|
module: {
|
|
@@ -78,13 +78,13 @@ module.exports = [
|
|
|
78
78
|
},
|
|
79
79
|
},
|
|
80
80
|
{
|
|
81
|
-
entry: "./build/
|
|
81
|
+
entry: "./build/selectors.js",
|
|
82
82
|
mode: "production",
|
|
83
83
|
output: {
|
|
84
84
|
path: path.resolve(__dirname, "dist"),
|
|
85
|
-
filename: "
|
|
85
|
+
filename: "selectors.min.js",
|
|
86
86
|
libraryTarget: "umd",
|
|
87
|
-
library: "
|
|
87
|
+
library: "selectors",
|
|
88
88
|
globalObject: "this",
|
|
89
89
|
},
|
|
90
90
|
module: {
|
|
@@ -154,13 +154,13 @@ module.exports = [
|
|
|
154
154
|
},
|
|
155
155
|
},
|
|
156
156
|
{
|
|
157
|
-
entry: "./build/
|
|
157
|
+
entry: "./build/observables.js",
|
|
158
158
|
mode: "production",
|
|
159
159
|
output: {
|
|
160
160
|
path: path.resolve(__dirname, "dist"),
|
|
161
|
-
filename: "
|
|
161
|
+
filename: "observables.min.js",
|
|
162
162
|
libraryTarget: "umd",
|
|
163
|
-
library: "
|
|
163
|
+
library: "observables",
|
|
164
164
|
globalObject: "this",
|
|
165
165
|
},
|
|
166
166
|
module: {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"customElements.d.ts","sourceRoot":"","sources":["../src/customElements.ts"],"names":[],"mappings":"AA+BA,wBAAgB,QAAQ,CAAE,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE;IAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,GAAG,CAAA;CAAE,EAAE,kBAAkB,GAAE,MAAM,EAAO,QA+B3H;AAED,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,wBAAwB,GAAG,SAAS,CAE3E"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.customElements=t():e.customElements=t()}(this,(()=>(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{defineCE:()=>h,getCE:()=>y});var r=new Function("try {return this===window;}catch(e){ return false;}");let n=new Set;r()&&Object.keys(HTMLElement.prototype).filter((e=>/^on/.test(e))).forEach((e=>n.add(e)));class o{#e;#t=!1;#r=!1;constructor(e,t={},r="l"){this.#e=e,this.data=t,this.bubble=r}get type(){return this.#e}get stopped(){return this.#t}get immediateStopped(){return this.#r}stopPropagation(){this.#t=!0}stopImmediatePropagation(){this.stopPropagation(),this.#r=!0}}var i=new Function("try {return this===window;}catch(e){ return false;}");let c=new Set;function s(e,t){let r=[];return e.forEach((e=>{if(e&&e instanceof HTMLElement){const n=e?._mc;!t&&n?r=r.concat(Object.values(e._mc)):t&&n&&n[t]&&r.push(n[t])}})),r}function a(e,t,r=!0){let n=[];for(;e;){if(e._mc&&(t?t&&e._mc[t]&&n.push(e._mc[t]):n=n.concat(Object.values(e._mc)),r))return n;e=e.parentNode}return n}function u(e){return e&&e instanceof HTMLElement}function l(e,t,r={}){let n=e;if(!n._mc){let t=g?.debug;g.debug=!1,n._mc=new g(e),g.debug=t,delete n._mc._mc}const o=n._mc;return t.length&&!o[t]&&(o[t]=r,e instanceof HTMLElement&&e.setAttribute("_mc","")),r}function d(e,t){if(!t)return;const r=e?._mc||{};r&&r[t]&&delete r[t],!Object.keys(r).length&&e instanceof HTMLElement&&e.hasAttribute("_mc")&&e.removeAttribute("_mc")}function p(e,t,r={}){let n=e?._mc;n&&[...Object.values(n)].forEach((e=>{e?.trigger&&"function"==typeof e?.trigger&&e?.trigger(t,r)}))}i()&&Object.keys(HTMLElement.prototype).filter((e=>/^on/.test(e))).forEach((e=>c.add(e)));class f{#n;constructor(e){var t;this.#n=new WeakRef(e||{}),(t=this).constructor!==g&&setTimeout((()=>{t.trigger("Init"),setTimeout((()=>{let e=Object.keys(t?._mc);e.length&&e?.forEach((e=>{let r=t?._mc?.[e];r.oneInit&&"function"==typeof r.oneInit&&r.oneInit(new o("Init"))}))}),0)}),0),function(e){if(!i()||e.constructor===g)return;const t=e.target;if(t instanceof HTMLElement){let r=e;Object.getOwnPropertyNames(r.constructor.prototype).filter((e=>/^on[A-Z]|one[A-Z]/.test(e)&&"function"==typeof r.constructor.prototype[e])).forEach((n=>{let o=/^one/.test(n),i=n.replace(/^on[e]{0,1}/,""),s=i.toLowerCase();o&&Object.defineProperty(e,"on"+i,{configurable:!0,enumerable:!1,writable:!0,value:e=>{r.constructor.prototype[n].bind(r)(e)}}),c.has("on"+s)&&function(e,t,r,n=!1,o=!1){let i={once:!1};n&&(i.capture=n),o&&(i.once=o),e.addEventListener(t,r,i)}(t,s,(e=>{r.trigger(i,e)}),!1,o)}))}}(this)}get target(){return this.#n.deref()}}class m extends f{_mc={};constructor(e){super(e)}static trigger=p;trigger(e,t={},r){let n=this;if(r=r||"l",n.constructor!==m&&n.constructor!==g){if(n instanceof m||n instanceof g){const n=this,c="string"!=typeof e?e:new o(e,t,r),s="on"+c.type[0].toUpperCase()+c.type.slice(1);if(c.bubble.indexOf("l")>-1&&(c.immediateStopped||"function"!=typeof n[s]||(n[s](c),n.hasOwnProperty(s)&&delete n[s])),c.stopped||"l"===c.bubble)return n;i()&&/[ud]/.test(c.bubble)&&n instanceof m&&setTimeout((()=>{-1===c.bubble.indexOf("l")&&(c.bubble+="l"),c.bubble.indexOf("u")>-1&&n.parent().forEach((e=>{e instanceof m&&e.trigger(c)})),c.bubble.indexOf("d")>-1&&n.children().forEach((e=>{e instanceof m&&e.trigger(c)}))}),0)}}else[...Object.getOwnPropertyNames(n)].forEach((o=>{n[o]?.trigger&&"function"==typeof n[o]?.trigger&&n[o]?.trigger(e,t,r)}))}}class g extends f{_mc={};constructor(e){super(e)}static debug=!1;static add=l;static remove=d;static trigger=p;trigger(e,t={},r){m.prototype.trigger.call(this,e,t,r)}parent(e=""){let t=this.target;return u(t)?a(t.parentNode,e,!0):[]}ancestors(e=""){let t=this?.target;return u(t)?a(this.target.parentNode,e,!1):[]}children(e=""){let t=this?.target;if(!u(t))return[];const r=Math.random().toString().replace(".",""),n='[_mc]:not([temp_id="'+r+'"] [_mc] [_mc])';t.setAttribute("temp_id",r);const o=s([...t.querySelectorAll(n)],e);return t.removeAttribute("temp_id"),o}descendants(e=""){let t=this?.target;return u(t)?s([...t.querySelectorAll("*[_mc]")],e):[]}}class b extends HTMLElement{constructor(){super()}connectedCallback(){g.trigger(this,"Connected")}disconnectedCallback(){g.trigger(this,"Disconnected")}adoptedCallback(){g.trigger(this,"Adopted")}attributeChangedCallback(e,t,r){g.trigger(this,"AttributeChanged",{name:e,oldValue:t,newValue:r})}}function h(e,t,r=[]){if(customElements.get(e))return void console.warn(`IGNORED: Custom element "${e}" is already defined!`);if(!e.includes("-"))throw new Error('createCustomElement: tagName must contain at least one hyphen ("-").');let n=e.split("-").map((e=>e.charAt(0).toUpperCase()+e.slice(1))).join("");customElements.define(e,function(e,t){return Object.defineProperty(t,"name",{value:e})}(n,class extends b{instance;constructor(e){super();let r=new t(this,e);g.add(this,n,r)}static get observedAttributes(){return r}}))}function y(e){return customElements.get(e)}return t})()));
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"customObservables.d.ts","sourceRoot":"","sources":["../src/customObservables.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAG3C,eAAO,MAAM,OAAO,WAAa,WAAW,iBAAiB,MAAM,SA8UlE,CAAA;AAED,KAAK,QAAQ,GAAG,CAAE,KAAK,EAAE,GAAG,KAAM,IAAI,CAAC;AAEvC,MAAM,MAAM,UAAU,GAAG;IACrB,OAAO,EAAE,CAAC,EAAE,EAAE,QAAQ,KAAK,IAAI,CAAC;IAChC,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,IAAI,EAAE,CAAC,MAAM,EAAE,WAAW,GAAG,UAAU,KAAK,IAAI,CAAC;CACpD,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.customObservables=t():e.customObservables=t()}(this,(()=>(()=>{"use strict";var e={d:(t,r)=>{for(var o in r)e.o(r,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:r[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};function r(e){return null!=e&&"object"==typeof e}function o(e,t){let r;return()=>{clearTimeout(r),r=setTimeout((function(){e(...arguments)}),t)}}function n(e,t){const o=Object.keys(e),c=Object.keys(t);if(o.length!==c.length)return!1;for(const c of o){const o=e[c],a=t[c],u=r(o)&&r(a);if(u&&!n(o,a)||!u&&o!==a)return!1}return!0}function c(e,t,o=null,n){let a=e.split(".");n||(n=t);let u=a.shift(),s=a.join(".");null!==o&&u.length&&void 0===t[u]&&(t[u]={});let l=t[u];return 0===s.length?null!==o?(t[u]=o,n):t[u]:r(t[u])?c(s,t[u],o,n):o?n:l[u]}function a(e,t){var o=Array.from(arguments);if(o.length){if(1===o.length)return o[1];if(o.length>2){for(;o.length>1;)o[0]=a(o[0],o[1]),o.splice(1,1);return o[0]}if("string"==typeof e){var n=e.match(/\{[^\{\}]*\}/g);n&&n.forEach((function(r){var o=c(r.substr(1,r.length-2),t);void 0!==o&&(e=e.replace(r,o))}))}else if(r(e))switch(e.constructor){case Object:Object.keys(e).forEach((function(r){e.hasOwnProperty(r)&&(e[r]=a(e[r],t))}));break;case Array:e.forEach((function(r,o,n){n[o]=a(e[o],t)}))}return e}console.error("no arguments give to parse")}e.r(t),e.d(t,{observe:()=>u});const u=(e,t)=>{(t?[t]:[...Object.getOwnPropertyNames(e)]).forEach((t=>{if("_"===t[0]||void 0===e?.[t])return;let c,u=e[t];if(!u.prototype)switch(typeof u){case"string":c=String;break;case"number":c=Number;break;case"boolean":c=Boolean;break;case"object":c=u instanceof Array?Array:Object;break;default:return}let s=class extends c{constructor(e){super(e),this.constructor.callbacks=[],r(e)&&(this.constructor.bound=[],Object.getOwnPropertyNames(e).forEach((t=>{this[t]=e[t]})))}observe(e){return this.constructor.callbacks.push(e),this}bind(e){const t=this,o=r(t.valueOf()),n=t.constructor.bound;if(o){function c(e){if(e.nodeType&&3===e.nodeType){var r=Array.from(e.nodeValue&&e.nodeValue.match(/\{[^\{\}]*\}/g)||[]);if(r.length>0){var u=(s=e.nodeValue||"",function(t){var n,c=!1;return r&&(o?r.forEach((function(e){u.values[e]!==t[e]&&(u.values[e]=t[e],c=!0)})):(u.values=t,c=!0)),c&&(n=s,e.nodeValue=o?a(n,u.values):n.replace(/\{.*\}/g,u.values)),t});u.values=o?{}:void 0,r=Array.from(r).map((e=>e.replace(/[\{\}]/g,"").trim()));let t=o?{}:void 0;r.forEach((function(e){o&&(t[e]="")})),n.push(u)}Array.from(e.childNodes).forEach((function(e){c(e)})),t.notify()}var s;e.nodeType&&1===e.nodeType&&(Array.from(e.attributes).forEach((function(t){var r=Array.from(t.value&&t.value.match(/\{[^\{\}]*\}/g)||[]);if(r.length>0){var o=function(t){return function(n){var c,u=!1;return r&&r.forEach((function(e){o.values[e]!==n[e]&&(o.values[e]=n[e],u=!0)})),u&&(c=t,e.nodeValue=a(c,o.values)),n}}(t.value||"");o.values={},r=Array.from(r).map((e=>e.replace(/[\{\}]/g,"").trim()));let c={};r.forEach((function(e){c[e]=""})),n.push(o)}})),Array.from(e.childNodes).forEach((function(e){c(e)})),t.notify()),e.nodeType&&11===e.nodeType&&Array.from(e.childNodes).forEach((function(e){c(e)}))}c(e),n.length>0&&t.notify()}else console.warn("IGNORED - cannot bind a non-Object to the dom, IS:",typeof t.valueOf());return this}notify(){let e=this,t=r(e.valueOf())&&e.valueOf()instanceof Array==0?structuredClone(Object.assign({},e)):e.valueOf();return e.constructor.callbacks.forEach((e=>{e(t)})),r(e.valueOf())&&e.constructor.bound.forEach((e=>{e(t)})),this}},l=new s(u);Object.defineProperty(e,t,{enumerable:!0,get(){if(r(l.valueOf())){let e=structuredClone(Object.assign({},l));setTimeout(o((function(){n(structuredClone(Object.assign({},l)),e)||l.notify()}),0),0)}return l},set(e){if(typeof e==typeof l.valueOf())if(r(l.valueOf())&&l.valueOf()instanceof Array==0){let t=structuredClone(Object.assign({},l));e=structuredClone(Object.assign({},e));let r=l.constructor?.hasFormHandler??!1,c=l.constructor.callbacks,a=l.constructor.bound;l=new s(structuredClone(Object.assign({},e))),l.constructor.callbacks=r,l.constructor.callbacks=c,l.constructor.bound=a,setTimeout(o((function(){n(structuredClone(Object.assign({},l)),t)||l.notify()}),0),0)}else{let t=l.valueOf(),r=l.constructor.callbacks;l=new s(e),l.constructor.callbacks=r,e!==t&&l.notify()}else console.warn("IGNORED - cannot change observable types, IS:",typeof l.valueOf(),"- CANNOT BECOME:",typeof e)}}),e[t]=u}))};return t})()));
|