@xtia/jel 0.4.2 → 0.4.4
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 +19 -14
- package/index.js +18 -17
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
export type ElementClassDescriptor = string | Record<string, boolean> | ElementClassDescriptor[];
|
|
2
2
|
export type DOMContent = number | null | string | Element | JelEntity<object> | Text | DOMContent[];
|
|
3
3
|
export type DomEntity<T extends HTMLElement> = JelEntity<ElementAPI<T>>;
|
|
4
|
-
export type AppendableDomEntity = DomEntity<AppendableElement>;
|
|
5
|
-
type AppendableElement = HTMLElementTagNameMap[Exclude<keyof HTMLElementTagNameMap, ContentlessTag>];
|
|
6
4
|
type PartConstructor<Spec, API extends object | void, EventDataMap> = (spec: Spec & EventSpec<EventDataMap>) => JelEntity<EventHost<API, EventDataMap>>;
|
|
7
5
|
type EventSpec<EventDataMap> = EventDataMap extends object ? {
|
|
8
6
|
on?: {
|
|
@@ -20,9 +18,11 @@ type StylesDescriptor = {
|
|
|
20
18
|
] extends [string, string] ? K : never]+?: CSSValue;
|
|
21
19
|
};
|
|
22
20
|
type StyleAccessor = StylesDescriptor & ((styles: StylesDescriptor) => void) & ((property: keyof StylesDescriptor, value: CSSValue) => void);
|
|
23
|
-
type ContentlessTag = "area" | "
|
|
21
|
+
type ContentlessTag = "area" | "br" | "hr" | "iframe" | "input" | "textarea" | "img" | "canvas" | "link" | "meta";
|
|
24
22
|
type TagWithHref = "a" | "link";
|
|
25
|
-
type TagWithSrc = "img" | "script" | "iframe";
|
|
23
|
+
type TagWithSrc = "img" | "script" | "iframe" | "video" | "audio";
|
|
24
|
+
type TagWithValue = "input" | "textarea";
|
|
25
|
+
type ContentlessElement = HTMLElementTagNameMap[ContentlessTag];
|
|
26
26
|
type ElementDescriptor<Tag extends string> = {
|
|
27
27
|
classes?: ElementClassDescriptor;
|
|
28
28
|
attribs?: Record<string, string | number | boolean>;
|
|
@@ -31,13 +31,13 @@ type ElementDescriptor<Tag extends string> = {
|
|
|
31
31
|
};
|
|
32
32
|
style?: StylesDescriptor;
|
|
33
33
|
cssVariables?: Record<string, CSSValue>;
|
|
34
|
-
} & (Tag extends
|
|
34
|
+
} & (Tag extends TagWithValue ? {
|
|
35
35
|
value?: string | number;
|
|
36
|
-
} : Tag extends ContentlessTag ? {} : {
|
|
36
|
+
} : {}) & (Tag extends ContentlessTag ? {} : {
|
|
37
37
|
content?: DOMContent;
|
|
38
38
|
}) & (Tag extends TagWithSrc ? {
|
|
39
39
|
src?: string;
|
|
40
|
-
} : Tag extends TagWithHref ? {
|
|
40
|
+
} : {}) & (Tag extends TagWithHref ? {
|
|
41
41
|
href?: string;
|
|
42
42
|
} : {});
|
|
43
43
|
type ElementAPI<T extends HTMLElement> = EventHost<{
|
|
@@ -47,28 +47,33 @@ type ElementAPI<T extends HTMLElement> = EventHost<{
|
|
|
47
47
|
[key: string]: string | null;
|
|
48
48
|
};
|
|
49
49
|
style: StyleAccessor;
|
|
50
|
-
innerHTML: string;
|
|
51
50
|
setCSSVariable(table: Record<string, CSSValue>): void;
|
|
52
51
|
setCSSVariable(variableName: string, value: CSSValue): void;
|
|
53
52
|
qsa(selector: string): (Element | DomEntity<HTMLElement>)[];
|
|
54
|
-
append(...content: DOMContent[]): void;
|
|
55
53
|
remove(): void;
|
|
56
54
|
getRect(): DOMRect;
|
|
57
55
|
focus(): void;
|
|
58
56
|
blur(): void;
|
|
59
|
-
} & (T extends
|
|
57
|
+
} & (T extends ContentlessElement ? {} : {
|
|
58
|
+
append(...content: DOMContent[]): void;
|
|
59
|
+
innerHTML: string;
|
|
60
60
|
content: DOMContent;
|
|
61
|
-
}
|
|
61
|
+
}) & (T extends HTMLElementTagNameMap[TagWithValue] ? {
|
|
62
62
|
value: string;
|
|
63
63
|
select(): void;
|
|
64
|
-
} : T extends HTMLCanvasElement ? {
|
|
64
|
+
} : {}) & (T extends HTMLCanvasElement ? {
|
|
65
65
|
width: number;
|
|
66
66
|
height: number;
|
|
67
67
|
getContext: HTMLCanvasElement["getContext"];
|
|
68
|
-
} : T extends HTMLElementTagNameMap[TagWithSrc] ? {
|
|
68
|
+
} : {}) & (T extends HTMLElementTagNameMap[TagWithSrc] ? {
|
|
69
69
|
src: string;
|
|
70
|
-
} : T extends HTMLElementTagNameMap[TagWithHref] ? {
|
|
70
|
+
} : {}) & (T extends HTMLElementTagNameMap[TagWithHref] ? {
|
|
71
71
|
href: string;
|
|
72
|
+
} : {}) & (T extends HTMLMediaElement ? {
|
|
73
|
+
play(): void;
|
|
74
|
+
pause(): void;
|
|
75
|
+
currentTime: number;
|
|
76
|
+
readonly paused: boolean;
|
|
72
77
|
} : {}), HTMLElementEventMap>;
|
|
73
78
|
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>) & {
|
|
74
79
|
[T in keyof HTMLElementTagNameMap]: (descriptor: ElementDescriptor<T>) => DomEntity<HTMLElementTagNameMap[T]>;
|
package/index.js
CHANGED
|
@@ -158,9 +158,7 @@ function getWrappedElement(element) {
|
|
|
158
158
|
append(...content) {
|
|
159
159
|
recursiveAppend(element, content);
|
|
160
160
|
},
|
|
161
|
-
remove()
|
|
162
|
-
element.remove();
|
|
163
|
-
},
|
|
161
|
+
remove: () => element.remove(),
|
|
164
162
|
setCSSVariable(variableNameOrTable, value) {
|
|
165
163
|
if (typeof variableNameOrTable == "object") {
|
|
166
164
|
Object.entries(variableNameOrTable).forEach(([k, v]) => setCSSVariable(k, v));
|
|
@@ -168,24 +166,17 @@ function getWrappedElement(element) {
|
|
|
168
166
|
}
|
|
169
167
|
setCSSVariable(variableNameOrTable, value);
|
|
170
168
|
},
|
|
171
|
-
classes: element.classList,
|
|
172
169
|
qsa(selector) {
|
|
173
170
|
const results = [];
|
|
174
171
|
element.querySelectorAll(selector).forEach((el) => results.push(el instanceof HTMLElement ? getWrappedElement(el) : el));
|
|
175
172
|
return results;
|
|
176
173
|
},
|
|
177
|
-
getRect()
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
blur() {
|
|
184
|
-
element.blur();
|
|
185
|
-
},
|
|
186
|
-
select() {
|
|
187
|
-
element.select();
|
|
188
|
-
},
|
|
174
|
+
getRect: () => element.getBoundingClientRect(),
|
|
175
|
+
focus: () => element.focus(),
|
|
176
|
+
blur: () => element.blur(),
|
|
177
|
+
select: () => element.select(),
|
|
178
|
+
play: () => element.play(),
|
|
179
|
+
pause: () => element.pause(),
|
|
189
180
|
getContext(mode, options) {
|
|
190
181
|
return element.getContext(mode, options);
|
|
191
182
|
},
|
|
@@ -232,12 +223,22 @@ function getWrappedElement(element) {
|
|
|
232
223
|
element.width = v;
|
|
233
224
|
},
|
|
234
225
|
get height() {
|
|
235
|
-
return element.
|
|
226
|
+
return element.height;
|
|
236
227
|
},
|
|
237
228
|
set height(v) {
|
|
238
229
|
element.height = v;
|
|
239
230
|
},
|
|
231
|
+
get currentTime() {
|
|
232
|
+
return element.currentTime;
|
|
233
|
+
},
|
|
234
|
+
set currentTime(v) {
|
|
235
|
+
element.currentTime = v;
|
|
236
|
+
},
|
|
237
|
+
get paused() {
|
|
238
|
+
return element.paused;
|
|
239
|
+
},
|
|
240
240
|
style: new Proxy(() => element.style, styleProxy),
|
|
241
|
+
classes: element.classList,
|
|
241
242
|
};
|
|
242
243
|
elementWrapCache.set(element, domEntity);
|
|
243
244
|
}
|