@twobirds/microcomponents 0.1.20 → 0.1.23

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 (66) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +97 -102
  3. package/dist/MC.min.js +1 -342
  4. package/dist/autoload.min.js +1 -0
  5. package/dist/core/MC.d.ts +401 -0
  6. package/dist/core/MC.d.ts.map +1 -0
  7. package/dist/core/MC.js +471 -0
  8. package/dist/core/autoload.d.ts +54 -0
  9. package/dist/core/autoload.d.ts.map +1 -0
  10. package/dist/core/autoload.js +158 -0
  11. package/dist/core/elements.d.ts +232 -0
  12. package/dist/core/elements.d.ts.map +1 -0
  13. package/dist/core/elements.js +123 -0
  14. package/dist/core/events.d.ts +231 -0
  15. package/dist/core/events.d.ts.map +1 -0
  16. package/dist/core/events.js +228 -0
  17. package/dist/core/mcGuards.d.ts +49 -0
  18. package/dist/core/mcGuards.d.ts.map +1 -0
  19. package/dist/core/mcGuards.js +19 -0
  20. package/dist/elements.min.js +1 -1
  21. package/dist/events.min.js +1 -0
  22. package/dist/formValues.min.js +1 -1
  23. package/dist/mcGuards.min.js +1 -0
  24. package/dist/microcomponents.d.ts +8 -5
  25. package/dist/microcomponents.d.ts.map +1 -1
  26. package/dist/microcomponents.js +8 -5
  27. package/dist/microcomponents.min.js +1 -1
  28. package/dist/observables.min.js +1 -1
  29. package/dist/state/formValues.d.ts +70 -0
  30. package/dist/state/formValues.d.ts.map +1 -0
  31. package/dist/state/formValues.js +334 -0
  32. package/dist/state/observables.d.ts +276 -0
  33. package/dist/state/observables.d.ts.map +1 -0
  34. package/dist/state/observables.js +382 -0
  35. package/dist/state/placeholders.d.ts +62 -0
  36. package/dist/state/placeholders.d.ts.map +1 -0
  37. package/dist/state/placeholders.js +181 -0
  38. package/dist/types/mcTypes.d.ts +201 -0
  39. package/dist/types/mcTypes.d.ts.map +1 -0
  40. package/dist/types/mcTypes.js +9 -0
  41. package/dist/utils/helpers.d.ts +195 -0
  42. package/dist/utils/helpers.d.ts.map +1 -0
  43. package/dist/utils/helpers.js +340 -0
  44. package/package.json +95 -61
  45. package/dist/MC.d.ts +0 -39
  46. package/dist/MC.d.ts.map +0 -1
  47. package/dist/MC.js +0 -299
  48. package/dist/MC.ts +0 -457
  49. package/dist/MicroComponents.svg +0 -15
  50. package/dist/elements.d.ts +0 -5
  51. package/dist/elements.d.ts.map +0 -1
  52. package/dist/elements.js +0 -50
  53. package/dist/elements.ts +0 -94
  54. package/dist/formValues.d.ts +0 -3
  55. package/dist/formValues.d.ts.map +0 -1
  56. package/dist/formValues.js +0 -158
  57. package/dist/formValues.ts +0 -213
  58. package/dist/helpers.d.ts +0 -14
  59. package/dist/helpers.d.ts.map +0 -1
  60. package/dist/helpers.js +0 -111
  61. package/dist/helpers.ts +0 -138
  62. package/dist/microcomponents.ts +0 -6
  63. package/dist/observables.d.ts +0 -11
  64. package/dist/observables.d.ts.map +0 -1
  65. package/dist/observables.js +0 -228
  66. package/dist/observables.ts +0 -338
@@ -1,158 +0,0 @@
1
- 'use strict';
2
- import { copyGettersSetters } from './helpers.js';
3
- import { DC } from './MC.js';
4
- import { observe } from './observables.js';
5
- const getInputName = (e) => {
6
- return e.tagName.toLowerCase();
7
- };
8
- class InputBase {
9
- constructor(e) { }
10
- }
11
- class RadioHandler extends InputBase {
12
- #e;
13
- constructor(e) {
14
- super(e);
15
- this.#e = e;
16
- }
17
- get val() {
18
- let ret = new FormData(this.#e.form).get(this.#e.name);
19
- return ret;
20
- }
21
- set val(value) {
22
- let arr = [
23
- ...this.#e.form.querySelectorAll(`input[type="radio"][name="${this.#e.name}"]`),
24
- ];
25
- arr.filter((e) => e.getAttribute('value') === value).shift().checked =
26
- true;
27
- }
28
- }
29
- class CheckboxHandler extends InputBase {
30
- #e;
31
- constructor(e) {
32
- super(e);
33
- this.#e = e;
34
- }
35
- get val() {
36
- return this.#e.checked;
37
- }
38
- set val(value) {
39
- this.#e.checked = value;
40
- }
41
- }
42
- class InputHandler extends InputBase {
43
- #e;
44
- constructor(e) {
45
- super(e);
46
- this.#e = e;
47
- }
48
- get val() {
49
- return this.#e.value;
50
- }
51
- set val(value) {
52
- this.#e.value = value;
53
- }
54
- }
55
- class SelectHandler extends InputBase {
56
- #e;
57
- #multi = false;
58
- constructor(e) {
59
- super(e);
60
- this.#e = e;
61
- this.#multi = e.multiple;
62
- }
63
- get val() {
64
- const that = this, ret = [];
65
- [...that.#e.querySelectorAll('option')]
66
- .filter((o) => o.selected)
67
- .forEach((o) => {
68
- ret.push(o.value);
69
- });
70
- if (this.#multi)
71
- return ret;
72
- return ret.length ? ret[0] : '';
73
- }
74
- set val(value) {
75
- const that = this;
76
- value = typeof value === 'string' ? [value] : value;
77
- [...that.#e.querySelectorAll('option')].forEach((o) => {
78
- if (value.indexOf(o.value) > -1) {
79
- o.selected = true;
80
- }
81
- else {
82
- o.selected = false;
83
- }
84
- });
85
- }
86
- }
87
- class TextAreaHandler extends InputBase {
88
- #e;
89
- constructor(e) {
90
- super(e);
91
- this.#e = e;
92
- }
93
- get val() {
94
- return this.#e.value || '';
95
- }
96
- set val(value) {
97
- this.#e.value = value;
98
- }
99
- }
100
- const getInputHandlers = (e) => {
101
- let inputList = [...(e || document).querySelectorAll('input,select,textarea')], handlers = {};
102
- inputList.forEach((input) => {
103
- const name = input.getAttribute('name');
104
- if (name) {
105
- let handler = false;
106
- switch (getInputName(input)) {
107
- case 'input':
108
- switch (input.type) {
109
- case 'radio':
110
- handler = new RadioHandler(input);
111
- break;
112
- case 'checkbox':
113
- handler = new CheckboxHandler(input);
114
- break;
115
- default:
116
- handler = new InputHandler(input);
117
- }
118
- break;
119
- case 'select':
120
- handler = new SelectHandler(input);
121
- break;
122
- case 'textarea':
123
- handler = new TextAreaHandler(input);
124
- break;
125
- default:
126
- console.warn('handler missing:', name, 'for', input.tagName.toLowerCase(), input);
127
- break;
128
- }
129
- if (handler) {
130
- DC.add(input, name, handler);
131
- Object.defineProperty(handlers, name, {
132
- enumerable: true,
133
- configurable: true,
134
- get: () => {
135
- return handler.val;
136
- },
137
- set: (value) => {
138
- if (handler.val !== value) {
139
- handler.val = value;
140
- }
141
- },
142
- });
143
- }
144
- }
145
- });
146
- return handlers;
147
- };
148
- export function formValues(targetObject, propertyName, dom) {
149
- let handlers = getInputHandlers(dom);
150
- targetObject[propertyName] = Object.assign({}, handlers);
151
- observe(targetObject, propertyName);
152
- copyGettersSetters(handlers, targetObject[propertyName]);
153
- [...dom.querySelectorAll('input, textarea, select')].forEach((input) => {
154
- input.addEventListener('input', (ev) => {
155
- targetObject[propertyName].notify();
156
- });
157
- });
158
- }
@@ -1,213 +0,0 @@
1
- 'use strict';
2
-
3
- import { LooseObject, copyGettersSetters } from './helpers.js';
4
- import { DC, on } from './MC.js';
5
- import { observe } from './observables.js';
6
-
7
- type inputTypes = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
8
-
9
- const getInputName = (e: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement): string => {
10
- return e.tagName.toLowerCase();
11
- };
12
-
13
- abstract class InputBase {
14
- constructor(e: inputTypes) {}
15
-
16
- abstract get val(): any;
17
-
18
- abstract set val(value: any);
19
- }
20
-
21
- class RadioHandler extends InputBase {
22
- #e: HTMLInputElement;
23
-
24
- constructor(e: HTMLInputElement) {
25
- super(e);
26
- this.#e = e;
27
- }
28
-
29
- get val(): string {
30
- let ret = new FormData(this.#e.form as HTMLFormElement).get(this.#e.name);
31
-
32
- //console.log('radio[', this.#e.name, '] = "' + ret + '"');
33
- return ret as string;
34
- }
35
-
36
- set val(value: string) {
37
- let arr = [
38
- ...(this.#e.form as HTMLFormElement).querySelectorAll(
39
- `input[type="radio"][name="${this.#e.name}"]`
40
- ),
41
- ] as HTMLInputElement[];
42
-
43
- (arr.filter((e) => e.getAttribute('value') === value).shift() as HTMLInputElement).checked =
44
- true;
45
- }
46
- }
47
-
48
- class CheckboxHandler extends InputBase {
49
- #e: HTMLInputElement;
50
-
51
- constructor(e: HTMLInputElement) {
52
- super(e);
53
- this.#e = e;
54
- }
55
-
56
- get val(): boolean {
57
- return this.#e.checked;
58
- }
59
-
60
- set val(value: boolean) {
61
- this.#e.checked = value;
62
- }
63
- }
64
-
65
- class InputHandler extends InputBase {
66
- #e: HTMLInputElement;
67
-
68
- constructor(e: HTMLInputElement) {
69
- super(e);
70
- this.#e = e;
71
- }
72
-
73
- get val(): string {
74
- return this.#e.value;
75
- }
76
-
77
- set val(value: string) {
78
- this.#e.value = value;
79
- }
80
- }
81
-
82
- class SelectHandler extends InputBase {
83
- #e: HTMLSelectElement;
84
- #multi: boolean = false;
85
-
86
- constructor(e: HTMLSelectElement) {
87
- super(e);
88
- this.#e = e;
89
- this.#multi = e.multiple;
90
- }
91
-
92
- get val(): string[] | string {
93
- const that = this,
94
- ret: string[] = [];
95
-
96
- // get all options
97
- [...that.#e.querySelectorAll('option')]
98
- .filter((o) => o.selected)
99
- .forEach((o) => {
100
- ret.push(o.value);
101
- });
102
-
103
- if (this.#multi) return ret;
104
- return ret.length ? ret[0] : '';
105
- }
106
-
107
- set val(value: string[] | string) {
108
- const that = this;
109
-
110
- value = typeof value === 'string' ? [value] : value;
111
-
112
- // set all options
113
- [...that.#e.querySelectorAll('option')].forEach((o) => {
114
- if (value.indexOf(o.value) > -1) {
115
- o.selected = true;
116
- } else {
117
- o.selected = false;
118
- }
119
- });
120
- }
121
- }
122
-
123
- class TextAreaHandler extends InputBase {
124
- #e: HTMLTextAreaElement;
125
- constructor(e: HTMLTextAreaElement) {
126
- super(e);
127
- this.#e = e;
128
- }
129
-
130
- get val(): string {
131
- return this.#e.value || '';
132
- }
133
-
134
- set val(value: string) {
135
- this.#e.value = value;
136
- }
137
- }
138
-
139
- const getInputHandlers = (e: HTMLElement | ShadowRoot): LooseObject => {
140
- let inputList = [...(e || document).querySelectorAll('input,select,textarea')],
141
- handlers: LooseObject = {};
142
-
143
- inputList.forEach((input) => {
144
- const name: string | null = (input as inputTypes).getAttribute('name');
145
- if (name) {
146
- let handler: any = false;
147
- switch (getInputName(input as inputTypes)) {
148
- case 'input':
149
- switch ((input as HTMLInputElement).type) {
150
- case 'radio':
151
- handler = new RadioHandler(input as HTMLInputElement);
152
- break;
153
- case 'checkbox':
154
- handler = new CheckboxHandler(input as HTMLInputElement);
155
- break;
156
- default:
157
- handler = new InputHandler(input as HTMLInputElement);
158
- }
159
- break;
160
- case 'select':
161
- handler = new SelectHandler(input as HTMLSelectElement);
162
- break;
163
- case 'textarea':
164
- handler = new TextAreaHandler(input as HTMLTextAreaElement);
165
- break;
166
- default:
167
- console.warn('handler missing:', name, 'for', input.tagName.toLowerCase(), input);
168
- break;
169
- }
170
-
171
- if (handler) {
172
- DC.add(input as HTMLElement, name, handler);
173
- Object.defineProperty(handlers, name, {
174
- enumerable: true,
175
- configurable: true,
176
- get: (): any => {
177
- return handler.val;
178
- },
179
- set: (value: any) => {
180
- if (handler.val !== value) {
181
- handler.val = value;
182
- }
183
- },
184
- });
185
- }
186
- }
187
- });
188
-
189
- return handlers;
190
- };
191
-
192
- export function formValues(
193
- targetObject: LooseObject,
194
- propertyName: string,
195
- dom: HTMLElement | ShadowRoot
196
- ) {
197
- let handlers = getInputHandlers(dom);
198
-
199
- targetObject[propertyName] = Object.assign({}, handlers);
200
-
201
- observe(targetObject, propertyName);
202
-
203
- copyGettersSetters(handlers, targetObject[propertyName]);
204
-
205
- //Object.seal(targetObject[propertyName]); // object structure may not be changed from now on
206
-
207
- [...dom.querySelectorAll('input, textarea, select')].forEach((input) => {
208
- input.addEventListener('input', (ev) => {
209
- //console.log('input event', input, ev);
210
- targetObject[propertyName].notify();
211
- });
212
- });
213
- }
package/dist/helpers.d.ts DELETED
@@ -1,14 +0,0 @@
1
- export interface LooseObject {
2
- [key: string | symbol]: any;
3
- }
4
- export declare function isNativeObject(value: any): boolean;
5
- export declare function sortObject(o: LooseObject): LooseObject;
6
- export declare function flattenObject(o: LooseObject, doSort?: boolean): LooseObject;
7
- export declare function deepEqual(o1: LooseObject, o2: LooseObject): boolean;
8
- export declare function nameSpace(ns: string | string[], obj?: LooseObject): any;
9
- export declare function parse(what: string | object | any[], parseThis: object): any;
10
- export declare function kebabToPascal(str: string): string;
11
- export declare function debounce(func: Function, milliseconds: number): Function;
12
- export declare function htmlToElements(html: string): HTMLElement[];
13
- export declare function copyGettersSetters(source: LooseObject, target: LooseObject): void;
14
- //# sourceMappingURL=helpers.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["helpers.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,WAAW;IAC3B,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;CAC5B;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAElD;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,WAAW,GAAG,WAAW,CAatD;AAED,wBAAgB,aAAa,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,GAAE,OAAc,GAAG,WAAW,CAgBjF;AAED,wBAAgB,SAAS,CAAC,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,WAAW,GAAG,OAAO,CAEnE;AAED,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,GAAG,GAAE,WAAgB,GAAG,GAAG,CAW3E;AAED,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,EAAE,EAAE,SAAS,EAAE,MAAM,OAsCrE;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,UAKxC;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,GAAG,QAAQ,CASvE;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,EAAE,CAU1D;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,QAO1E"}
package/dist/helpers.js DELETED
@@ -1,111 +0,0 @@
1
- 'use strict';
2
- export function isNativeObject(value) {
3
- return value && value['constructor'] && value.constructor === Object;
4
- }
5
- export function sortObject(o) {
6
- let result = {}, keys = [...Object.keys(o)].sort();
7
- keys.forEach((key) => {
8
- if (isNativeObject(o[key])) {
9
- result[key] = sortObject(o[key]);
10
- }
11
- else {
12
- result[key] = o[key];
13
- }
14
- });
15
- return result;
16
- }
17
- export function flattenObject(o, doSort = true) {
18
- let result = {};
19
- [...Object.getOwnPropertyNames(o)].forEach((propName) => {
20
- if (o[propName] instanceof Object) {
21
- const temp = flattenObject(o[propName], false);
22
- result[propName] = {};
23
- for (const j in temp) {
24
- result[propName + '.' + j] = temp[j];
25
- }
26
- }
27
- else {
28
- result[propName] = o[propName];
29
- }
30
- });
31
- return doSort ? sortObject(result) : result;
32
- }
33
- export function deepEqual(o1, o2) {
34
- return JSON.stringify(flattenObject(o1)) === JSON.stringify(flattenObject(o2));
35
- }
36
- export function nameSpace(ns, obj = {}) {
37
- let nsa = ns.constructor === String ? ns.split('.') : ns;
38
- if (!obj || !nsa[0] || !obj[nsa[0]]) {
39
- console.warn('ns', nsa[0], 'not in', obj);
40
- return;
41
- }
42
- if (obj[nsa[0]].constructor === Object && nsa.length > 1) {
43
- return nameSpace(nsa.splice(1), obj[nsa[0]]);
44
- }
45
- return obj[nsa[0]];
46
- }
47
- export function parse(what, parseThis) {
48
- var args = Array.from(arguments);
49
- if (args.length > 2) {
50
- while (args.length > 1) {
51
- args[0] = parse(args[0], args[1]);
52
- args.splice(1, 1);
53
- }
54
- return args[0];
55
- }
56
- if (typeof what === 'string') {
57
- what.match(/\{[^\{\}]*\}/g)?.forEach(function (pPropname) {
58
- var propname = pPropname.substring(1, pPropname.length - 1), value = nameSpace(propname, parseThis);
59
- if (typeof value !== 'undefined') {
60
- what = what.replace(pPropname, value);
61
- }
62
- });
63
- }
64
- else if (isNativeObject(what)) {
65
- switch (what.constructor) {
66
- case Object:
67
- Object.keys(what).forEach(function (pKey) {
68
- if (what.hasOwnProperty(pKey)) {
69
- what[pKey] = parse(what[pKey], parseThis);
70
- }
71
- });
72
- break;
73
- case Array:
74
- what.forEach(function (pValue, pKey, original) {
75
- original[pKey] = parse(what[pKey], parseThis);
76
- });
77
- break;
78
- }
79
- }
80
- return what;
81
- }
82
- export function kebabToPascal(str) {
83
- return str
84
- .split('-')
85
- .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
86
- .join('');
87
- }
88
- export function debounce(func, milliseconds) {
89
- let timeout;
90
- return () => {
91
- clearTimeout(timeout);
92
- timeout = setTimeout(function () {
93
- func(...arguments);
94
- }, milliseconds);
95
- };
96
- }
97
- export function htmlToElements(html) {
98
- let template = document.createElement('template');
99
- html = html.replace(/<([A-Za-z0-9\-]*)([^>\/]*)(\/>)/gi, '<$1$2></$1>');
100
- template.innerHTML = html;
101
- template.content.normalize();
102
- return Array.from(template.content.childNodes);
103
- }
104
- export function copyGettersSetters(source, target) {
105
- const descriptors = Object.getOwnPropertyDescriptors(source);
106
- for (const [key, descriptor] of Object.entries(descriptors)) {
107
- if ('get' in descriptor || 'set' in descriptor) {
108
- Object.defineProperty(target, key, descriptor);
109
- }
110
- }
111
- }
package/dist/helpers.ts DELETED
@@ -1,138 +0,0 @@
1
- 'use strict';
2
-
3
- export interface LooseObject {
4
- [key: string | symbol]: any;
5
- }
6
-
7
- export function isNativeObject(value: any): boolean {
8
- return value && value['constructor'] && value.constructor === Object;
9
- }
10
-
11
- export function sortObject(o: LooseObject): LooseObject {
12
- let result: LooseObject = {},
13
- keys = [...Object.keys(o)].sort();
14
-
15
- keys.forEach((key) => {
16
- if (isNativeObject(o[key])) {
17
- result[key] = sortObject(o[key]);
18
- } else {
19
- result[key] = o[key];
20
- }
21
- });
22
-
23
- return result;
24
- }
25
-
26
- export function flattenObject(o: LooseObject, doSort: boolean = true): LooseObject {
27
- let result: LooseObject = {};
28
-
29
- [...Object.getOwnPropertyNames(o)].forEach((propName) => {
30
- if (o[propName] instanceof Object) {
31
- const temp = flattenObject(o[propName], false);
32
- result[propName] = {};
33
- for (const j in temp) {
34
- result[propName + '.' + j] = temp[j];
35
- }
36
- } else {
37
- result[propName] = o[propName];
38
- }
39
- });
40
-
41
- return doSort ? sortObject(result) : result;
42
- }
43
-
44
- export function deepEqual(o1: LooseObject, o2: LooseObject): boolean {
45
- return JSON.stringify(flattenObject(o1)) === JSON.stringify(flattenObject(o2));
46
- }
47
-
48
- export function nameSpace(ns: string | string[], obj: LooseObject = {}): any {
49
- let nsa = ns.constructor === String ? ns.split('.') : ns;
50
-
51
- if (!obj || !nsa[0] || !obj[nsa[0]]) {
52
- console.warn('ns', nsa[0], 'not in', obj);
53
- return;
54
- }
55
- if (obj[nsa[0]].constructor === Object && nsa.length > 1) {
56
- return nameSpace((nsa as string[]).splice(1), obj[nsa[0]]);
57
- }
58
- return obj[nsa[0]];
59
- }
60
-
61
- export function parse(what: string | object | any[], parseThis: object) {
62
- var args = Array.from(arguments);
63
-
64
- if (args.length > 2) {
65
- while (args.length > 1) {
66
- args[0] = parse(args[0], args[1]);
67
- args.splice(1, 1);
68
- }
69
- return args[0];
70
- }
71
-
72
- if (typeof what === 'string') {
73
- what.match(/\{[^\{\}]*\}/g)?.forEach(function (pPropname) {
74
- var propname = pPropname.substring(1, pPropname.length - 1),
75
- value = nameSpace(propname, parseThis);
76
- //console.log(propname, value);
77
- if (typeof value !== 'undefined') {
78
- what = (what as string).replace(pPropname, value);
79
- }
80
- });
81
- } else if (isNativeObject(what)) {
82
- switch (what.constructor) {
83
- case Object:
84
- Object.keys(what).forEach(function (pKey) {
85
- if (what.hasOwnProperty(pKey)) {
86
- (what as LooseObject)[pKey] = parse((what as LooseObject)[pKey], parseThis);
87
- }
88
- });
89
- break;
90
- case Array:
91
- (what as Array<any>).forEach(function (pValue, pKey, original) {
92
- original[pKey] = parse((what as any)[pKey], parseThis);
93
- });
94
- break;
95
- }
96
- }
97
-
98
- return what;
99
- }
100
-
101
- export function kebabToPascal(str: string) {
102
- return str
103
- .split('-') // Split by hyphens
104
- .map((word) => word.charAt(0).toUpperCase() + word.slice(1)) // Capitalize each part
105
- .join(''); // Join without spaces
106
- }
107
-
108
- export function debounce(func: Function, milliseconds: number): Function {
109
- let timeout: any;
110
- return () => {
111
- clearTimeout(timeout);
112
-
113
- timeout = setTimeout(function () {
114
- func(...arguments);
115
- }, milliseconds);
116
- };
117
- }
118
-
119
- export function htmlToElements(html: string): HTMLElement[] {
120
- let template = document.createElement('template');
121
-
122
- html = html.replace(/<([A-Za-z0-9\-]*)([^>\/]*)(\/>)/gi, '<$1$2></$1>'); // replace XHTML closing tags by full closing tags
123
-
124
- template.innerHTML = html;
125
-
126
- template.content.normalize();
127
-
128
- return Array.from(template.content.childNodes) as HTMLElement[];
129
- }
130
-
131
- export function copyGettersSetters(source: LooseObject, target: LooseObject) {
132
- const descriptors = Object.getOwnPropertyDescriptors(source);
133
- for (const [key, descriptor] of Object.entries(descriptors)) {
134
- if ('get' in descriptor || 'set' in descriptor) {
135
- Object.defineProperty(target, key, descriptor);
136
- }
137
- }
138
- }
@@ -1,6 +0,0 @@
1
- 'use strict';
2
- export * from './helpers.js';
3
- export * from './MC.js';
4
- export * from './elements.js';
5
- export * from './observables.js';
6
- export * from './formValues.js';
@@ -1,11 +0,0 @@
1
- import { LooseObject } from './helpers.js';
2
- type Callback = (value: any) => void;
3
- export type Observable = {
4
- observe: (cb: Callback) => void;
5
- notify: () => void;
6
- bind: (target: HTMLElement | DocumentFragment | ShadowRoot) => void;
7
- callbacks: Array<Function>;
8
- };
9
- export declare const observe: (target: LooseObject, propertyName?: string) => LooseObject;
10
- export {};
11
- //# sourceMappingURL=observables.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"observables.d.ts","sourceRoot":"","sources":["observables.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAA0D,MAAM,cAAc,CAAC;AAQnG,KAAK,QAAQ,GAAG,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;AAiJrC,MAAM,MAAM,UAAU,GAAG;IACxB,OAAO,EAAE,CAAC,EAAE,EAAE,QAAQ,KAAK,IAAI,CAAC;IAChC,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,IAAI,EAAE,CAAC,MAAM,EAAE,WAAW,GAAG,gBAAgB,GAAG,UAAU,KAAK,IAAI,CAAC;IACpE,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;CAC3B,CAAC;AAsGF,eAAO,MAAM,OAAO,WAAY,WAAW,iBAAiB,MAAM,KAAG,WA2EpE,CAAC"}