@xtia/jel 0.3.1 → 0.4.0
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/index.d.ts +41 -37
- package/index.js +159 -178
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1,50 +1,45 @@
|
|
|
1
1
|
export type ElementClassDescriptor = string | Record<string, boolean> | ElementClassDescriptor[];
|
|
2
|
-
export type DOMContent = number | null | string | Element | JelEntity<object
|
|
3
|
-
export type DomEntity<T extends HTMLElement> = JelEntity<ElementAPI<T
|
|
4
|
-
type
|
|
5
|
-
type
|
|
6
|
-
on?:
|
|
7
|
-
[EventID in keyof EventDataMap]
|
|
8
|
-
}
|
|
2
|
+
export type DOMContent = number | null | string | Element | JelEntity<object> | Text | DOMContent[];
|
|
3
|
+
export type DomEntity<T extends HTMLElement> = JelEntity<ElementAPI<T>>;
|
|
4
|
+
type PartConstructor<Spec, API extends object | void, EventDataMap> = (spec: Spec & EventSpec<EventDataMap>) => JelEntity<EventHost<API, EventDataMap>>;
|
|
5
|
+
type EventSpec<EventDataMap> = EventDataMap extends object ? {
|
|
6
|
+
on?: {
|
|
7
|
+
[EventID in keyof EventDataMap]+?: (data: EventDataMap[EventID]) => void;
|
|
8
|
+
};
|
|
9
|
+
} : {};
|
|
10
|
+
type JelEntity<API extends object | void> = (API extends void ? {} : API) & {
|
|
11
|
+
readonly [entityDataSymbol]: JelEntityData;
|
|
9
12
|
};
|
|
10
|
-
type
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
type CSSValue = string | number | null;
|
|
14
|
+
type StylesDescriptor = {
|
|
15
|
+
[K in keyof CSSStyleDeclaration as [
|
|
16
|
+
K,
|
|
17
|
+
CSSStyleDeclaration[K]
|
|
18
|
+
] extends [string, string] ? K : never]+?: CSSValue;
|
|
13
19
|
};
|
|
14
|
-
type
|
|
15
|
-
[key in keyof CSSStyleDeclaration]: CSSValue;
|
|
16
|
-
}>;
|
|
20
|
+
type StyleAccessor = StylesDescriptor & ((styles: StylesDescriptor) => void) & ((property: keyof StylesDescriptor, value: CSSValue) => void);
|
|
17
21
|
interface ElementDescriptor {
|
|
18
22
|
classes?: ElementClassDescriptor;
|
|
19
23
|
content?: DOMContent;
|
|
20
24
|
attribs?: Record<string, string | number | boolean>;
|
|
21
|
-
on?:
|
|
22
|
-
[E in keyof HTMLElementEventMap]
|
|
23
|
-
}
|
|
25
|
+
on?: {
|
|
26
|
+
[E in keyof HTMLElementEventMap]+?: (event: HTMLElementEventMap[E]) => void;
|
|
27
|
+
};
|
|
24
28
|
style?: StylesDescriptor;
|
|
25
29
|
cssVariables?: Record<string, CSSValue>;
|
|
26
30
|
}
|
|
27
|
-
type
|
|
28
|
-
[T in keyof HTMLElementTagNameMap]: (descriptor: ElementDescriptor) => DomEntity<HTMLElementTagNameMap[T]>;
|
|
29
|
-
} & {
|
|
30
|
-
[T in keyof HTMLElementTagNameMap]: (content?: DOMContent) => DomEntity<HTMLElementTagNameMap[T]>;
|
|
31
|
-
});
|
|
32
|
-
type JelComponentData = {
|
|
33
|
-
dom: DOMContent;
|
|
34
|
-
};
|
|
35
|
-
type CSSValue = string | number;
|
|
36
|
-
type ElementAPI<T extends HTMLElement> = {
|
|
31
|
+
type ElementAPI<T extends HTMLElement> = EventHost<{
|
|
37
32
|
readonly element: T;
|
|
38
33
|
content: DOMContent;
|
|
39
34
|
classes: DOMTokenList;
|
|
40
35
|
attribs: {
|
|
41
36
|
[key: string]: string | null;
|
|
42
37
|
};
|
|
43
|
-
style:
|
|
38
|
+
style: StyleAccessor;
|
|
44
39
|
innerHTML: string;
|
|
45
40
|
setCSSVariable(table: Record<string, CSSValue>): void;
|
|
46
41
|
setCSSVariable(variableName: string, value: CSSValue): void;
|
|
47
|
-
qsa(selector: string): DomEntity<
|
|
42
|
+
qsa(selector: string): (Element | DomEntity<HTMLElement>)[];
|
|
48
43
|
append(...content: DOMContent[]): void;
|
|
49
44
|
remove(): void;
|
|
50
45
|
getRect(): DOMRect;
|
|
@@ -56,20 +51,29 @@ type ElementAPI<T extends HTMLElement> = {
|
|
|
56
51
|
} : T extends HTMLCanvasElement ? {
|
|
57
52
|
width: number;
|
|
58
53
|
height: number;
|
|
59
|
-
getContext
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
54
|
+
getContext: HTMLCanvasElement["getContext"];
|
|
55
|
+
} : {}), HTMLElementEventMap>;
|
|
56
|
+
type DomHelper = ((<T extends keyof HTMLElementTagNameMap>(tagName: T, descriptor: ElementDescriptor) => DomEntity<HTMLElementTagNameMap[T]>) & (<T extends keyof HTMLElementTagNameMap>(selector: `${T}#${string}`, content?: DOMContent) => DomEntity<HTMLElementTagNameMap[T]>) & (<T extends keyof HTMLElementTagNameMap>(selector: `${T}.${string}`, content?: DOMContent) => DomEntity<HTMLElementTagNameMap[T]>) & (<T extends keyof HTMLElementTagNameMap>(selector: T, content?: DOMContent) => DomEntity<HTMLElementTagNameMap[T]>) & (<T extends HTMLElement>(element: T) => DomEntity<T>) & {
|
|
57
|
+
[T in keyof HTMLElementTagNameMap]: (descriptor: ElementDescriptor) => DomEntity<HTMLElementTagNameMap[T]>;
|
|
58
|
+
} & {
|
|
59
|
+
[T in keyof HTMLElementTagNameMap]: (content?: DOMContent) => DomEntity<HTMLElementTagNameMap[T]>;
|
|
60
|
+
});
|
|
61
|
+
type JelEntityData = {
|
|
62
|
+
dom: DOMContent;
|
|
63
|
+
};
|
|
65
64
|
type OptionalKeys<T> = {
|
|
66
65
|
[K in keyof T]-?: {} extends Pick<T, K> ? K : never;
|
|
67
66
|
}[keyof T];
|
|
68
67
|
type Optionals<T> = {
|
|
69
68
|
[K in OptionalKeys<T>]-?: Exclude<T[K], undefined>;
|
|
70
69
|
};
|
|
70
|
+
type ForbidKey<K extends string | symbol> = Record<string | symbol, any> & Partial<Record<K, never>>;
|
|
71
|
+
type EventHost<API extends object | void, EventDataMap> = (API extends object ? API : {}) & {
|
|
72
|
+
on<E extends keyof EventDataMap>(eventId: E, handler: (this: JelEntity<EventHost<API, EventDataMap>>, data: EventDataMap[E]) => void): void;
|
|
73
|
+
};
|
|
71
74
|
export declare const $: DomHelper;
|
|
72
|
-
declare const
|
|
73
|
-
|
|
74
|
-
export declare function
|
|
75
|
+
declare const entityDataSymbol: unique symbol;
|
|
76
|
+
export declare function createEntity<API extends object>(content: DOMContent, api: API extends DOMContent ? never : API): JelEntity<API>;
|
|
77
|
+
export declare function createEntity(content: DOMContent, api?: undefined): JelEntity<undefined>;
|
|
78
|
+
export declare function definePart<Spec extends ForbidKey<"on">, API extends ForbidKey<"on"> | void = void, EventDataMap extends Record<string, any> = {}>(defaultOptions: Optionals<Spec>, init: (spec: Required<Spec>, append: (content: DOMContent) => void, trigger: <K extends keyof EventDataMap>(eventId: K, eventData: EventDataMap[K]) => void) => API): PartConstructor<Spec, API, EventDataMap>;
|
|
75
79
|
export {};
|
package/index.js
CHANGED
|
@@ -1,57 +1,49 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
exports.$ = void 0;
|
|
4
|
+
exports.createEntity = createEntity;
|
|
15
5
|
exports.definePart = definePart;
|
|
16
|
-
|
|
17
|
-
get
|
|
18
|
-
return
|
|
6
|
+
const styleProxy = {
|
|
7
|
+
get(getStyle, prop) {
|
|
8
|
+
return getStyle()[prop];
|
|
19
9
|
},
|
|
20
|
-
set
|
|
21
|
-
|
|
10
|
+
set(getStyle, prop, value) {
|
|
11
|
+
getStyle()[prop] = value;
|
|
22
12
|
return true;
|
|
23
13
|
},
|
|
24
|
-
apply
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return
|
|
29
|
-
}
|
|
14
|
+
apply(getStyle, _, [stylesOrProp, value]) {
|
|
15
|
+
const style = getStyle();
|
|
16
|
+
if (typeof stylesOrProp == "object") {
|
|
17
|
+
Object.entries(stylesOrProp).forEach(([prop, val]) => style[prop] = val);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
style[stylesOrProp] = value;
|
|
30
21
|
},
|
|
22
|
+
deleteProperty(getStyle, prop) {
|
|
23
|
+
getStyle()[prop] = null;
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
31
26
|
};
|
|
32
|
-
function createElement(tag, descriptor) {
|
|
33
|
-
if (descriptor === void 0) { descriptor = {}; }
|
|
27
|
+
function createElement(tag, descriptor = {}) {
|
|
34
28
|
if (isContent(descriptor))
|
|
35
29
|
descriptor = { content: descriptor };
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
const ent = getWrappedElement(document.createElement(tag));
|
|
31
|
+
const applyClasses = (classes) => {
|
|
38
32
|
if (Array.isArray(classes)) {
|
|
39
|
-
return classes.forEach(
|
|
33
|
+
return classes.forEach(c => applyClasses(c));
|
|
40
34
|
}
|
|
41
35
|
if (typeof classes == "string") {
|
|
42
|
-
classes.trim().split(/\s+/).forEach(
|
|
36
|
+
classes.trim().split(/\s+/).forEach(c => ent.classes.add(c));
|
|
43
37
|
return;
|
|
44
38
|
}
|
|
45
|
-
Object.entries(classes).forEach(
|
|
46
|
-
var className = _a[0], state = _a[1];
|
|
39
|
+
Object.entries(classes).forEach(([className, state]) => {
|
|
47
40
|
if (state)
|
|
48
41
|
applyClasses(className);
|
|
49
42
|
});
|
|
50
43
|
};
|
|
51
44
|
applyClasses(descriptor.classes || []);
|
|
52
45
|
if (descriptor.attribs) {
|
|
53
|
-
Object.entries(descriptor.attribs).forEach(
|
|
54
|
-
var k = _a[0], v = _a[1];
|
|
46
|
+
Object.entries(descriptor.attribs).forEach(([k, v]) => {
|
|
55
47
|
if (v === false) {
|
|
56
48
|
return;
|
|
57
49
|
}
|
|
@@ -61,50 +53,33 @@ function createElement(tag, descriptor) {
|
|
|
61
53
|
if (descriptor.content !== undefined)
|
|
62
54
|
recursiveAppend(ent.element, descriptor.content);
|
|
63
55
|
if (descriptor.style) {
|
|
64
|
-
|
|
65
|
-
var prop = _a[0], val = _a[1];
|
|
66
|
-
ent.element.style[prop] = val;
|
|
67
|
-
});
|
|
56
|
+
ent.style(descriptor.style);
|
|
68
57
|
}
|
|
69
58
|
if (descriptor.cssVariables) {
|
|
70
|
-
|
|
71
|
-
var prop = _a[0], val = _a[1];
|
|
72
|
-
ent.element.style.setProperty("--" + prop, val);
|
|
73
|
-
});
|
|
59
|
+
ent.setCSSVariable(descriptor.cssVariables);
|
|
74
60
|
}
|
|
75
61
|
if (descriptor.on) {
|
|
76
|
-
Object.entries(descriptor.on).forEach(
|
|
77
|
-
var eventName = _a[0], handler = _a[1];
|
|
78
|
-
return ent.on(eventName, handler);
|
|
79
|
-
});
|
|
62
|
+
Object.entries(descriptor.on).forEach(([eventName, handler]) => ent.on(eventName, handler));
|
|
80
63
|
}
|
|
81
64
|
return ent;
|
|
82
65
|
}
|
|
83
66
|
;
|
|
84
|
-
var isContent = function (value) {
|
|
85
|
-
return ["string", "number"].includes(typeof value)
|
|
86
|
-
|| value instanceof Element
|
|
87
|
-
|| value instanceof Text
|
|
88
|
-
|| Array.isArray(value)
|
|
89
|
-
|| !value;
|
|
90
|
-
};
|
|
91
67
|
exports.$ = new Proxy(createElement, {
|
|
92
|
-
apply
|
|
93
|
-
var
|
|
94
|
-
var selectorOrTagName = _a[0], contentOrDescriptor = _a[1];
|
|
68
|
+
apply(create, _, [selectorOrTagName, contentOrDescriptor]) {
|
|
69
|
+
var _a;
|
|
95
70
|
if (selectorOrTagName instanceof HTMLElement)
|
|
96
71
|
return getWrappedElement(selectorOrTagName);
|
|
97
|
-
|
|
72
|
+
const tagName = ((_a = selectorOrTagName.match(/^[^.#]*/)) === null || _a === void 0 ? void 0 : _a[0]) || "";
|
|
98
73
|
if (!tagName)
|
|
99
74
|
throw new Error("Invalid tag");
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
classes
|
|
75
|
+
const matches = selectorOrTagName.slice(tagName.length).match(/[.#][^.#]+/g);
|
|
76
|
+
const classes = {};
|
|
77
|
+
const descriptor = {
|
|
78
|
+
classes,
|
|
104
79
|
content: contentOrDescriptor,
|
|
105
80
|
};
|
|
106
|
-
matches === null || matches === void 0 ? void 0 : matches.forEach(
|
|
107
|
-
|
|
81
|
+
matches === null || matches === void 0 ? void 0 : matches.forEach((m) => {
|
|
82
|
+
const value = m.slice(1);
|
|
108
83
|
if (m[0] == ".") {
|
|
109
84
|
classes[value] = true;
|
|
110
85
|
}
|
|
@@ -114,38 +89,38 @@ exports.$ = new Proxy(createElement, {
|
|
|
114
89
|
});
|
|
115
90
|
return create(tagName, descriptor);
|
|
116
91
|
},
|
|
117
|
-
get
|
|
118
|
-
return
|
|
92
|
+
get(create, tagName) {
|
|
93
|
+
return (descriptorOrContent) => {
|
|
119
94
|
return create(tagName, descriptorOrContent);
|
|
120
95
|
};
|
|
121
96
|
}
|
|
122
97
|
});
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
get:
|
|
98
|
+
const entityDataSymbol = Symbol("jelComponentData");
|
|
99
|
+
const elementWrapCache = new WeakMap();
|
|
100
|
+
const attribsProxy = {
|
|
101
|
+
get: (element, key) => {
|
|
127
102
|
return element.getAttribute(key);
|
|
128
103
|
},
|
|
129
|
-
set:
|
|
104
|
+
set: (element, key, value) => {
|
|
130
105
|
element.setAttribute(key, value);
|
|
131
106
|
return true;
|
|
132
107
|
},
|
|
133
|
-
has:
|
|
108
|
+
has: (element, key) => {
|
|
134
109
|
return element.hasAttribute(key);
|
|
135
110
|
},
|
|
136
|
-
ownKeys:
|
|
111
|
+
ownKeys: (element) => {
|
|
137
112
|
return element.getAttributeNames();
|
|
138
113
|
},
|
|
139
114
|
};
|
|
140
|
-
|
|
115
|
+
const recursiveAppend = (parent, c) => {
|
|
141
116
|
if (c === null)
|
|
142
117
|
return;
|
|
143
118
|
if (Array.isArray(c)) {
|
|
144
|
-
c.forEach(
|
|
119
|
+
c.forEach(item => recursiveAppend(parent, item));
|
|
145
120
|
return;
|
|
146
121
|
}
|
|
147
122
|
if (isJelEntity(c)) {
|
|
148
|
-
recursiveAppend(parent, c[
|
|
123
|
+
recursiveAppend(parent, c[entityDataSymbol].dom);
|
|
149
124
|
return;
|
|
150
125
|
}
|
|
151
126
|
if (typeof c == "number")
|
|
@@ -153,158 +128,164 @@ var recursiveAppend = function (parent, c) {
|
|
|
153
128
|
parent.append(c);
|
|
154
129
|
};
|
|
155
130
|
function getWrappedElement(element) {
|
|
156
|
-
var _a;
|
|
157
131
|
if (!elementWrapCache.has(element)) {
|
|
158
|
-
|
|
159
|
-
|
|
132
|
+
const setCSSVariable = (k, v) => {
|
|
133
|
+
if (v === null) {
|
|
134
|
+
element.style.removeProperty("--" + k);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
element.style.setProperty("--" + k, v);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
const domEntity = {
|
|
141
|
+
[entityDataSymbol]: {
|
|
160
142
|
dom: element,
|
|
161
143
|
},
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}),
|
|
167
|
-
_a.on = function (eventId, handler) {
|
|
168
|
-
element.addEventListener(eventId, function (eventData) {
|
|
169
|
-
handler.call(domEntity_1, eventData);
|
|
144
|
+
get element() { return element; },
|
|
145
|
+
on(eventId, handler) {
|
|
146
|
+
element.addEventListener(eventId, eventData => {
|
|
147
|
+
handler.call(domEntity, eventData);
|
|
170
148
|
});
|
|
171
149
|
},
|
|
172
|
-
|
|
173
|
-
var content = [];
|
|
174
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
175
|
-
content[_i] = arguments[_i];
|
|
176
|
-
}
|
|
150
|
+
append(...content) {
|
|
177
151
|
recursiveAppend(element, content);
|
|
178
152
|
},
|
|
179
|
-
|
|
153
|
+
remove() {
|
|
180
154
|
element.remove();
|
|
181
155
|
},
|
|
182
|
-
|
|
156
|
+
setCSSVariable(variableNameOrTable, value) {
|
|
183
157
|
if (typeof variableNameOrTable == "object") {
|
|
184
|
-
Object.entries(variableNameOrTable).forEach(
|
|
185
|
-
var k = _a[0], v = _a[1];
|
|
186
|
-
element.style.setProperty("--" + k, v);
|
|
187
|
-
});
|
|
158
|
+
Object.entries(variableNameOrTable).forEach(([k, v]) => setCSSVariable(k, v));
|
|
188
159
|
return;
|
|
189
160
|
}
|
|
190
|
-
|
|
161
|
+
setCSSVariable(variableNameOrTable, value);
|
|
191
162
|
},
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
163
|
+
classes: element.classList,
|
|
164
|
+
qsa(selector) {
|
|
165
|
+
const results = [];
|
|
166
|
+
element.querySelectorAll(selector).forEach((el) => results.push(el instanceof HTMLElement ? getWrappedElement(el) : el));
|
|
167
|
+
return results;
|
|
195
168
|
},
|
|
196
|
-
|
|
169
|
+
getRect() {
|
|
197
170
|
return element.getBoundingClientRect();
|
|
198
171
|
},
|
|
199
|
-
|
|
172
|
+
focus() {
|
|
200
173
|
element.focus();
|
|
201
174
|
},
|
|
202
|
-
|
|
175
|
+
blur() {
|
|
203
176
|
element.blur();
|
|
204
177
|
},
|
|
205
|
-
|
|
178
|
+
select() {
|
|
206
179
|
element.select();
|
|
207
180
|
},
|
|
208
|
-
|
|
181
|
+
getContext(mode, options) {
|
|
209
182
|
return element.getContext(mode, options);
|
|
210
183
|
},
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
},
|
|
251
|
-
set: function (v) {
|
|
252
|
-
element.width = v;
|
|
253
|
-
},
|
|
254
|
-
enumerable: false,
|
|
255
|
-
configurable: true
|
|
256
|
-
}),
|
|
257
|
-
_a.style = new Proxy(element.style, elementProxy),
|
|
258
|
-
_a);
|
|
259
|
-
elementWrapCache.set(element, domEntity_1);
|
|
184
|
+
get content() {
|
|
185
|
+
return [].slice.call(element.children).map((child) => {
|
|
186
|
+
if (child instanceof HTMLElement)
|
|
187
|
+
return getWrappedElement(child);
|
|
188
|
+
return child;
|
|
189
|
+
});
|
|
190
|
+
},
|
|
191
|
+
set content(v) {
|
|
192
|
+
element.innerHTML = "";
|
|
193
|
+
recursiveAppend(element, v);
|
|
194
|
+
},
|
|
195
|
+
attribs: new Proxy(element, attribsProxy),
|
|
196
|
+
get innerHTML() {
|
|
197
|
+
return element.innerHTML;
|
|
198
|
+
},
|
|
199
|
+
set innerHTML(v) {
|
|
200
|
+
element.innerHTML = v;
|
|
201
|
+
},
|
|
202
|
+
get value() {
|
|
203
|
+
return element.value;
|
|
204
|
+
},
|
|
205
|
+
set value(v) {
|
|
206
|
+
element.value = v;
|
|
207
|
+
},
|
|
208
|
+
get width() {
|
|
209
|
+
return element.width;
|
|
210
|
+
},
|
|
211
|
+
set width(v) {
|
|
212
|
+
element.width = v;
|
|
213
|
+
},
|
|
214
|
+
get height() {
|
|
215
|
+
return element.width;
|
|
216
|
+
},
|
|
217
|
+
set height(v) {
|
|
218
|
+
element.height = v;
|
|
219
|
+
},
|
|
220
|
+
style: new Proxy(() => element.style, styleProxy),
|
|
221
|
+
};
|
|
222
|
+
elementWrapCache.set(element, domEntity);
|
|
260
223
|
}
|
|
261
224
|
return elementWrapCache.get(element);
|
|
262
225
|
}
|
|
226
|
+
const isContent = (value) => {
|
|
227
|
+
if (value === undefined)
|
|
228
|
+
return false;
|
|
229
|
+
return typeof value == "string"
|
|
230
|
+
|| typeof value == "number"
|
|
231
|
+
|| !value
|
|
232
|
+
|| value instanceof Element
|
|
233
|
+
|| value instanceof Text
|
|
234
|
+
|| entityDataSymbol in value
|
|
235
|
+
|| Array.isArray(value);
|
|
236
|
+
};
|
|
263
237
|
function isJelEntity(content) {
|
|
264
|
-
return typeof content == "object" && !!content &&
|
|
238
|
+
return typeof content == "object" && !!content && entityDataSymbol in content;
|
|
239
|
+
}
|
|
240
|
+
function createEntity(content, api) {
|
|
241
|
+
if (isContent(api)) {
|
|
242
|
+
throw new TypeError("API object is already valid content");
|
|
243
|
+
}
|
|
244
|
+
return Object.create(api !== null && api !== void 0 ? api : {}, {
|
|
245
|
+
[entityDataSymbol]: {
|
|
246
|
+
value: {
|
|
247
|
+
dom: content
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
});
|
|
265
251
|
}
|
|
252
|
+
;
|
|
266
253
|
function definePart(defaultOptions, init) {
|
|
267
|
-
return (
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
var addEventListener = function (eventId, fn) {
|
|
254
|
+
return ((spec) => {
|
|
255
|
+
const fullSpec = Object.assign(Object.assign({}, defaultOptions), spec);
|
|
256
|
+
const eventHandlers = {};
|
|
257
|
+
const addEventListener = (eventId, fn) => {
|
|
272
258
|
if (!eventHandlers[eventId])
|
|
273
259
|
eventHandlers[eventId] = [];
|
|
274
260
|
eventHandlers[eventId].push(fn);
|
|
275
261
|
};
|
|
276
262
|
if (fullSpec.on)
|
|
277
|
-
Object.entries(fullSpec.on).forEach(
|
|
278
|
-
var eventId = _a[0], handler = _a[1];
|
|
263
|
+
Object.entries(fullSpec.on).forEach(([eventId, handler]) => {
|
|
279
264
|
addEventListener(eventId, handler);
|
|
280
265
|
});
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
266
|
+
let entity;
|
|
267
|
+
const content = [];
|
|
268
|
+
const append = (c) => {
|
|
284
269
|
if (entity)
|
|
285
270
|
throw new Error("Component root content can only be added during initialisation");
|
|
286
271
|
content.push(c);
|
|
287
272
|
};
|
|
288
|
-
|
|
273
|
+
const trigger = (eventId, data) => {
|
|
289
274
|
var _a;
|
|
290
|
-
(_a = eventHandlers[eventId]) === null || _a === void 0 ? void 0 : _a.forEach(
|
|
275
|
+
(_a = eventHandlers[eventId]) === null || _a === void 0 ? void 0 : _a.forEach(fn => fn.call(entity, data));
|
|
291
276
|
};
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
277
|
+
const api = init(fullSpec, append, trigger);
|
|
278
|
+
Object.defineProperties(api, {
|
|
279
|
+
[entityDataSymbol]: {
|
|
295
280
|
value: {
|
|
296
281
|
dom: content
|
|
297
282
|
}
|
|
298
283
|
},
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
dom: content,
|
|
305
|
-
},
|
|
306
|
-
_b.on = addEventListener,
|
|
307
|
-
_b);
|
|
284
|
+
on: {
|
|
285
|
+
get: () => addEventListener
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
entity = api;
|
|
308
289
|
return entity;
|
|
309
290
|
});
|
|
310
291
|
}
|