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