@xtia/jel 0.3.1 → 0.3.2
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 +12 -11
- package/index.js +30 -19
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ type JelEntity<API, EventDataMap> = API & {
|
|
|
11
11
|
on<E extends keyof EventDataMap>(eventId: E, handler: (this: JelEntity<API, EventDataMap>, data: EventDataMap[E]) => void): void;
|
|
12
12
|
readonly [componentDataSymbol]: JelComponentData;
|
|
13
13
|
};
|
|
14
|
+
type CSSValue = string | number;
|
|
14
15
|
type StylesDescriptor = Partial<{
|
|
15
16
|
[key in keyof CSSStyleDeclaration]: CSSValue;
|
|
16
17
|
}>;
|
|
@@ -24,15 +25,7 @@ interface ElementDescriptor {
|
|
|
24
25
|
style?: StylesDescriptor;
|
|
25
26
|
cssVariables?: Record<string, CSSValue>;
|
|
26
27
|
}
|
|
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;
|
|
28
|
+
type StyleAccessor = StylesDescriptor & ((styles: StylesDescriptor) => void) & ((property: string, value: CSSValue) => void);
|
|
36
29
|
type ElementAPI<T extends HTMLElement> = {
|
|
37
30
|
readonly element: T;
|
|
38
31
|
content: DOMContent;
|
|
@@ -40,11 +33,11 @@ type ElementAPI<T extends HTMLElement> = {
|
|
|
40
33
|
attribs: {
|
|
41
34
|
[key: string]: string | null;
|
|
42
35
|
};
|
|
43
|
-
style:
|
|
36
|
+
style: StyleAccessor;
|
|
44
37
|
innerHTML: string;
|
|
45
38
|
setCSSVariable(table: Record<string, CSSValue>): void;
|
|
46
39
|
setCSSVariable(variableName: string, value: CSSValue): void;
|
|
47
|
-
qsa(selector: string): DomEntity<any>[];
|
|
40
|
+
qsa(selector: string): (Element | DomEntity<any>)[];
|
|
48
41
|
append(...content: DOMContent[]): void;
|
|
49
42
|
remove(): void;
|
|
50
43
|
getRect(): DOMRect;
|
|
@@ -62,6 +55,14 @@ type ElementAPI<T extends HTMLElement> = {
|
|
|
62
55
|
getContext(contextId: "webgl2", options?: WebGLContextAttributes): WebGL2RenderingContext | null;
|
|
63
56
|
getContext(contextId: string, options?: any): RenderingContext | null;
|
|
64
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]>;
|
|
60
|
+
} & {
|
|
61
|
+
[T in keyof HTMLElementTagNameMap]: (content?: DOMContent) => DomEntity<HTMLElementTagNameMap[T]>;
|
|
62
|
+
});
|
|
63
|
+
type JelComponentData = {
|
|
64
|
+
dom: DOMContent;
|
|
65
|
+
};
|
|
65
66
|
type OptionalKeys<T> = {
|
|
66
67
|
[K in keyof T]-?: {} extends Pick<T, K> ? K : never;
|
|
67
68
|
}[keyof T];
|
package/index.js
CHANGED
|
@@ -13,20 +13,25 @@ var __assign = (this && this.__assign) || function () {
|
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
exports.$ = void 0;
|
|
15
15
|
exports.definePart = definePart;
|
|
16
|
-
var
|
|
16
|
+
var styleProxy = {
|
|
17
17
|
get: function (style, prop) {
|
|
18
|
-
return style[prop];
|
|
18
|
+
return style()[prop];
|
|
19
19
|
},
|
|
20
20
|
set: function (style, prop, value) {
|
|
21
|
-
style[prop] = value;
|
|
21
|
+
style()[prop] = value;
|
|
22
22
|
return true;
|
|
23
23
|
},
|
|
24
|
-
apply: function (
|
|
25
|
-
var
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
apply: function (getStyle, _, _a) {
|
|
25
|
+
var stylesOrProp = _a[0], value = _a[1];
|
|
26
|
+
var style = getStyle();
|
|
27
|
+
if (typeof stylesOrProp == "object") {
|
|
28
|
+
Object.entries(stylesOrProp).forEach(function (_a) {
|
|
29
|
+
var prop = _a[0], val = _a[1];
|
|
30
|
+
return style[prop] = val;
|
|
31
|
+
});
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
style.setProperty(stylesOrProp, value);
|
|
30
35
|
},
|
|
31
36
|
};
|
|
32
37
|
function createElement(tag, descriptor) {
|
|
@@ -61,16 +66,10 @@ function createElement(tag, descriptor) {
|
|
|
61
66
|
if (descriptor.content !== undefined)
|
|
62
67
|
recursiveAppend(ent.element, descriptor.content);
|
|
63
68
|
if (descriptor.style) {
|
|
64
|
-
|
|
65
|
-
var prop = _a[0], val = _a[1];
|
|
66
|
-
ent.element.style[prop] = val;
|
|
67
|
-
});
|
|
69
|
+
ent.style(descriptor.style);
|
|
68
70
|
}
|
|
69
71
|
if (descriptor.cssVariables) {
|
|
70
|
-
|
|
71
|
-
var prop = _a[0], val = _a[1];
|
|
72
|
-
ent.element.style.setProperty("--" + prop, val);
|
|
73
|
-
});
|
|
72
|
+
ent.setCSSVariable(descriptor.cssVariables);
|
|
74
73
|
}
|
|
75
74
|
if (descriptor.on) {
|
|
76
75
|
Object.entries(descriptor.on).forEach(function (_a) {
|
|
@@ -191,7 +190,9 @@ function getWrappedElement(element) {
|
|
|
191
190
|
},
|
|
192
191
|
_a.classes = element.classList,
|
|
193
192
|
_a.qsa = function (selector) {
|
|
194
|
-
|
|
193
|
+
var results = [];
|
|
194
|
+
element.querySelectorAll(selector).forEach(function (el) { return results.push(el instanceof HTMLElement ? getWrappedElement(el) : el); });
|
|
195
|
+
return results;
|
|
195
196
|
},
|
|
196
197
|
_a.getRect = function () {
|
|
197
198
|
return element.getBoundingClientRect();
|
|
@@ -254,7 +255,17 @@ function getWrappedElement(element) {
|
|
|
254
255
|
enumerable: false,
|
|
255
256
|
configurable: true
|
|
256
257
|
}),
|
|
257
|
-
|
|
258
|
+
Object.defineProperty(_a, "height", {
|
|
259
|
+
get: function () {
|
|
260
|
+
return element.width;
|
|
261
|
+
},
|
|
262
|
+
set: function (v) {
|
|
263
|
+
element.height = v;
|
|
264
|
+
},
|
|
265
|
+
enumerable: false,
|
|
266
|
+
configurable: true
|
|
267
|
+
}),
|
|
268
|
+
_a.style = new Proxy(function () { return element.style; }, styleProxy),
|
|
258
269
|
_a);
|
|
259
270
|
elementWrapCache.set(element, domEntity_1);
|
|
260
271
|
}
|