@xtia/jel 0.3.0 → 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/README.md +3 -3
- package/index.d.ts +24 -11
- package/index.js +62 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -89,7 +89,7 @@ Element classes can be specified as string, `{ [className]: boolean }` and arbit
|
|
|
89
89
|
function renderFancyButton(
|
|
90
90
|
caption: DOMContent,
|
|
91
91
|
onClick: () => void,
|
|
92
|
-
classes:
|
|
92
|
+
classes: ElementClassDescriptor = []
|
|
93
93
|
) {
|
|
94
94
|
return $.button({
|
|
95
95
|
content: caption,
|
|
@@ -118,8 +118,8 @@ Jel wraps its elements in an interface for common operations plus an `append()`
|
|
|
118
118
|
For other operations the element is accessible via `ent.element`:
|
|
119
119
|
|
|
120
120
|
```ts
|
|
121
|
-
const
|
|
122
|
-
|
|
121
|
+
const div = $.div();
|
|
122
|
+
div.element.requestFullscreen();
|
|
123
123
|
```
|
|
124
124
|
|
|
125
125
|
## Shorthand
|
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,16 +33,36 @@ 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;
|
|
43
|
+
getRect(): DOMRect;
|
|
44
|
+
focus(): void;
|
|
45
|
+
blur(): void;
|
|
50
46
|
} & (T extends HTMLInputElement ? {
|
|
51
47
|
value: string;
|
|
48
|
+
select(): void;
|
|
49
|
+
} : T extends HTMLCanvasElement ? {
|
|
50
|
+
width: number;
|
|
51
|
+
height: number;
|
|
52
|
+
getContext(contextId: "2d", options?: CanvasRenderingContext2DSettings): CanvasRenderingContext2D | null;
|
|
53
|
+
getContext(contextId: "bitmaprenderer", options?: ImageBitmapRenderingContextSettings): ImageBitmapRenderingContext | null;
|
|
54
|
+
getContext(contextId: "webgl", options?: WebGLContextAttributes): WebGLRenderingContext | null;
|
|
55
|
+
getContext(contextId: "webgl2", options?: WebGLContextAttributes): WebGL2RenderingContext | null;
|
|
56
|
+
getContext(contextId: string, options?: any): RenderingContext | null;
|
|
52
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
|
+
};
|
|
53
66
|
type OptionalKeys<T> = {
|
|
54
67
|
[K in keyof T]-?: {} extends Pick<T, K> ? K : never;
|
|
55
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) {
|
|
@@ -129,7 +128,13 @@ var attribsProxy = {
|
|
|
129
128
|
set: function (element, key, value) {
|
|
130
129
|
element.setAttribute(key, value);
|
|
131
130
|
return true;
|
|
132
|
-
}
|
|
131
|
+
},
|
|
132
|
+
has: function (element, key) {
|
|
133
|
+
return element.hasAttribute(key);
|
|
134
|
+
},
|
|
135
|
+
ownKeys: function (element) {
|
|
136
|
+
return element.getAttributeNames();
|
|
137
|
+
},
|
|
133
138
|
};
|
|
134
139
|
var recursiveAppend = function (parent, c) {
|
|
135
140
|
if (c === null)
|
|
@@ -185,7 +190,24 @@ function getWrappedElement(element) {
|
|
|
185
190
|
},
|
|
186
191
|
_a.classes = element.classList,
|
|
187
192
|
_a.qsa = function (selector) {
|
|
188
|
-
|
|
193
|
+
var results = [];
|
|
194
|
+
element.querySelectorAll(selector).forEach(function (el) { return results.push(el instanceof HTMLElement ? getWrappedElement(el) : el); });
|
|
195
|
+
return results;
|
|
196
|
+
},
|
|
197
|
+
_a.getRect = function () {
|
|
198
|
+
return element.getBoundingClientRect();
|
|
199
|
+
},
|
|
200
|
+
_a.focus = function () {
|
|
201
|
+
element.focus();
|
|
202
|
+
},
|
|
203
|
+
_a.blur = function () {
|
|
204
|
+
element.blur();
|
|
205
|
+
},
|
|
206
|
+
_a.select = function () {
|
|
207
|
+
element.select();
|
|
208
|
+
},
|
|
209
|
+
_a.getContext = function (mode, options) {
|
|
210
|
+
return element.getContext(mode, options);
|
|
189
211
|
},
|
|
190
212
|
Object.defineProperty(_a, "content", {
|
|
191
213
|
get: function () {
|
|
@@ -223,7 +245,27 @@ function getWrappedElement(element) {
|
|
|
223
245
|
enumerable: false,
|
|
224
246
|
configurable: true
|
|
225
247
|
}),
|
|
226
|
-
|
|
248
|
+
Object.defineProperty(_a, "width", {
|
|
249
|
+
get: function () {
|
|
250
|
+
return element.width;
|
|
251
|
+
},
|
|
252
|
+
set: function (v) {
|
|
253
|
+
element.width = v;
|
|
254
|
+
},
|
|
255
|
+
enumerable: false,
|
|
256
|
+
configurable: true
|
|
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),
|
|
227
269
|
_a);
|
|
228
270
|
elementWrapCache.set(element, domEntity_1);
|
|
229
271
|
}
|