@twobirds/microcomponents 0.0.34 → 0.0.37
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/dist/MC.d.ts +2 -3
- package/dist/MC.d.ts.map +1 -1
- package/dist/MC.min.js +45 -43
- package/dist/MC.ts +173 -175
- 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 +354 -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 +133 -157
- package/klemmstein.png +0 -0
- package/package.json +52 -52
- package/public/MC.js +46 -44
- package/public/MC.js.map +1 -1
- package/public/MC.min.js +45 -43
- 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/observables.js +255 -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 +376 -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 +354 -0
- package/public/src/test.ts +187 -0
- package/public/test.js +99 -115
- 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 +173 -175
- 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 +354 -0
- package/src/selectors.ts +1634 -0
- package/src/test.ts +133 -157
- 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,187 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
HTMLMcElement,
|
|
5
|
+
LooseObject,
|
|
6
|
+
MC,
|
|
7
|
+
DC,
|
|
8
|
+
McEvent,
|
|
9
|
+
defineCE,
|
|
10
|
+
getCE,
|
|
11
|
+
observe,
|
|
12
|
+
Observable,
|
|
13
|
+
} from './microcomponents.js';
|
|
14
|
+
|
|
15
|
+
//import { MC, DC, McEvent } from "./MC.js";
|
|
16
|
+
//import { defineCE, getCE } from "./elements.js";
|
|
17
|
+
//import { observe } from "./observables.js";
|
|
8
18
|
|
|
9
19
|
//MC.debug = true;
|
|
10
20
|
|
|
11
|
-
class
|
|
12
|
-
|
|
21
|
+
class Translator extends DC {
|
|
22
|
+
#translations: LooseObject = {};
|
|
13
23
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
}
|
|
24
|
+
Language: unknown = 'en';
|
|
25
|
+
Translation: unknown = {};
|
|
18
26
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
27
|
+
constructor(
|
|
28
|
+
target: HTMLElement | ShadowRoot | DocumentFragment,
|
|
29
|
+
translations: LooseObject,
|
|
30
|
+
translationTargetObject: HTMLElement
|
|
31
|
+
) {
|
|
32
|
+
super(target as HTMLElement);
|
|
33
|
+
let that = this; // minifier help
|
|
23
34
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
}
|
|
35
|
+
// state
|
|
36
|
+
that.Language = 'en';
|
|
37
|
+
that.Translation = {};
|
|
29
38
|
|
|
30
|
-
|
|
31
|
-
constructor(target: any) {
|
|
32
|
-
super(target);
|
|
33
|
-
}
|
|
39
|
+
observe(that);
|
|
34
40
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
logger?.log("onCustomEvent", ev);
|
|
38
|
-
}
|
|
41
|
+
// setup
|
|
42
|
+
that.#translations = translations;
|
|
39
43
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
// state
|
|
45
|
+
(that.Language as Observable).observe((lang) => {
|
|
46
|
+
if (that.#translations.hasOwnProperty(lang)) {
|
|
47
|
+
that.Translation = { lang: that.#translations[lang] }; // set translation
|
|
48
|
+
}
|
|
49
|
+
});
|
|
44
50
|
|
|
45
|
-
|
|
51
|
+
(that.Translation as Observable).bind(target);
|
|
46
52
|
|
|
47
|
-
|
|
53
|
+
this.target.setAttribute('language', 'en');
|
|
48
54
|
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
class Logger extends DC {
|
|
52
|
-
|
|
53
|
-
prefix: string = "";
|
|
54
55
|
|
|
55
|
-
|
|
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;
|
|
56
|
+
oneInit() {
|
|
57
|
+
(this.Language as Observable).notify(); // trigger translation
|
|
67
58
|
}
|
|
68
59
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
60
|
+
onAttributeChanged(ev: McEvent) {
|
|
61
|
+
if (!ev.data.newValue) return;
|
|
72
62
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
63
|
+
let that = this;
|
|
64
|
+
|
|
65
|
+
switch (ev.data.name) {
|
|
66
|
+
case 'language':
|
|
67
|
+
that.Language = ev.data.newValue;
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
78
70
|
}
|
|
79
71
|
}
|
|
80
72
|
|
|
81
73
|
defineCE(
|
|
82
74
|
// equivalent to custom element registry .define()
|
|
83
|
-
|
|
75
|
+
'my-tag',
|
|
84
76
|
class MyTag extends DC {
|
|
77
|
+
#template: string = '{lang.click} {counter}';
|
|
85
78
|
|
|
86
|
-
|
|
79
|
+
#languages = {
|
|
80
|
+
en: {
|
|
81
|
+
click: 'click me',
|
|
82
|
+
},
|
|
83
|
+
de: {
|
|
84
|
+
click: 'klick mich',
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
87
|
|
|
88
|
-
|
|
88
|
+
Dom: LooseObject = {};
|
|
89
89
|
|
|
90
|
-
constructor(target: HTMLElement
|
|
90
|
+
constructor(target: HTMLElement) {
|
|
91
91
|
super(target);
|
|
92
92
|
|
|
93
93
|
let that = this; // minifier help
|
|
94
94
|
|
|
95
|
-
// state observables
|
|
96
|
-
that.In = data;
|
|
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]"));
|
|
103
|
-
|
|
104
95
|
// render
|
|
105
|
-
target.innerHTML =
|
|
96
|
+
target.innerHTML = this.#template;
|
|
97
|
+
|
|
98
|
+
// add public translator
|
|
99
|
+
DC.add(
|
|
100
|
+
target,
|
|
101
|
+
'translator',
|
|
102
|
+
new Translator(target, that.#languages, target)
|
|
103
|
+
);
|
|
106
104
|
}
|
|
107
105
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
*/
|
|
106
|
+
oneInit(ev: McEvent) {
|
|
107
|
+
let that = this;
|
|
111
108
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
onAttributeChanged(ev: typeof McEvent) {
|
|
117
|
-
let logger = this.target._mc?.logger;
|
|
118
|
-
//logger?.info("onAttributeChanged handler", ev);
|
|
119
|
-
}
|
|
109
|
+
// state
|
|
110
|
+
that.Dom = { counter: 0 };
|
|
120
111
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
*/
|
|
124
|
-
oneClick(ev: typeof McEvent) {
|
|
125
|
-
let logger = this.target._mc?.logger;
|
|
126
|
-
|
|
127
|
-
logger.info("oneClick handler", ev);
|
|
128
|
-
|
|
129
|
-
this._mc.customEventTarget.trigger("customEvent");
|
|
112
|
+
// state: convert all props defined so far into observables
|
|
113
|
+
observe(that);
|
|
130
114
|
|
|
131
|
-
|
|
115
|
+
// bind Dom to target
|
|
116
|
+
(that.Dom as Observable).bind(that.target);
|
|
132
117
|
}
|
|
133
118
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
logger?.info("onClick handler", ev);
|
|
138
|
-
|
|
139
|
-
this.Counter++;
|
|
119
|
+
onAttributeChanged(ev: McEvent) {
|
|
120
|
+
//console.log(ev);
|
|
121
|
+
this.target._mc.translator.Language = ev.data.newValue;
|
|
140
122
|
}
|
|
141
123
|
|
|
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);
|
|
124
|
+
onClick(ev: McEvent) {
|
|
125
|
+
this.Dom.counter++;
|
|
170
126
|
}
|
|
171
127
|
},
|
|
172
|
-
[
|
|
128
|
+
['language']
|
|
173
129
|
);
|
|
174
130
|
|
|
175
|
-
let MyTag: CustomElementConstructor = getCE(
|
|
131
|
+
let MyTag: CustomElementConstructor = getCE('my-tag')!,
|
|
176
132
|
fragment = new DocumentFragment();
|
|
177
133
|
|
|
178
|
-
|
|
179
|
-
|
|
134
|
+
/*
|
|
135
|
+
stress test
|
|
136
|
+
*/
|
|
137
|
+
|
|
138
|
+
/*
|
|
139
|
+
let start = new Date().getTime();
|
|
140
|
+
|
|
180
141
|
// create 1000 elements
|
|
181
|
-
for (
|
|
182
|
-
|
|
142
|
+
for (let x = 0; x < 1000; x++) {
|
|
143
|
+
let mt = new MyTag('my-data');
|
|
144
|
+
fragment.append(mt);
|
|
183
145
|
}
|
|
184
|
-
document.body.appendChild( fragment );
|
|
185
146
|
|
|
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");
|
|
147
|
+
let end = new Date().getTime();
|
|
192
148
|
|
|
193
|
-
|
|
149
|
+
// and put them into the DOM
|
|
150
|
+
document.body.appendChild(fragment);
|
|
194
151
|
|
|
195
|
-
|
|
152
|
+
document.querySelectorAll('my-tag').forEach((e) => e.remove());
|
|
153
|
+
*/
|
|
196
154
|
|
|
197
|
-
|
|
155
|
+
/*
|
|
156
|
+
console test
|
|
157
|
+
*/
|
|
198
158
|
|
|
199
|
-
|
|
159
|
+
setTimeout(() => {
|
|
160
|
+
console.clear();
|
|
200
161
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
);
|
|
162
|
+
/*
|
|
163
|
+
console.log(
|
|
164
|
+
'%c \n\nStress Test:\n\n %cInstancing 1000 web components: %c %s ms.',
|
|
165
|
+
'font-weight: bold; color: black;',
|
|
166
|
+
'font-weight: normal;',
|
|
167
|
+
'font-weight: bold; color: blue;',
|
|
168
|
+
0
|
|
169
|
+
);
|
|
170
|
+
*/
|
|
171
|
+
|
|
172
|
+
document.body.appendChild(new MyTag());
|
|
173
|
+
|
|
174
|
+
let element = document.querySelector('my-tag');
|
|
175
|
+
|
|
176
|
+
console.log(
|
|
177
|
+
"\n\n%cInspect this tag:%c \n( ...to see the inner structure in the '._mc' property )\n\n %O %c %s",
|
|
178
|
+
'font-weight: bold;',
|
|
179
|
+
'font-weight: normal;',
|
|
180
|
+
element,
|
|
181
|
+
'font-weight: bold;',
|
|
182
|
+
'\n\nLook up code in the debugger: test.js\n\n'
|
|
183
|
+
);
|
|
209
184
|
|
|
210
|
-
// will trigger the event on all micro components contained in <my-tag>
|
|
211
|
-
DC.trigger(element,
|
|
185
|
+
// will trigger the event on all micro components contained in <my-tag>
|
|
186
|
+
DC.trigger(element, 'doSomething');
|
|
187
|
+
}, 20);
|
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})()));
|