@t007/utils 0.0.2 → 0.0.3
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/dist/index.cjs +12 -6
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +12 -6
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -56,14 +56,20 @@ function isSameURL(src1, src2) {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
// src/core/dom.ts
|
|
59
|
-
function createEl(tag, props
|
|
60
|
-
return assignEl(
|
|
59
|
+
function createEl(tag, props, dataset, styles, el = tag ? document?.createElement(tag) : null) {
|
|
60
|
+
return assignEl(el, props, dataset, styles), el;
|
|
61
61
|
}
|
|
62
|
-
function assignEl(el, props
|
|
62
|
+
function assignEl(el, props, dataset, styles) {
|
|
63
63
|
if (!el) return;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
if (props) {
|
|
65
|
+
for (const k of Object.keys(props)) if (props[k] !== void 0) el[k] = props[k];
|
|
66
|
+
}
|
|
67
|
+
if (dataset) {
|
|
68
|
+
for (const k of Object.keys(dataset)) if (dataset[k] !== void 0) el.dataset[k] = String(dataset[k]);
|
|
69
|
+
}
|
|
70
|
+
if (styles) {
|
|
71
|
+
for (const k of Object.keys(styles)) if (styles[k] !== void 0) el.style[k] = styles[k];
|
|
72
|
+
}
|
|
67
73
|
}
|
|
68
74
|
function loadResource(src, type = "style", { module: module2, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts = 3, retryKey = false } = {}, w = window) {
|
|
69
75
|
w.t007._resourceCache ??= {};
|
package/dist/index.d.cts
CHANGED
|
@@ -70,7 +70,7 @@ type LoadResourceOptions = Partial<{
|
|
|
70
70
|
declare function createEl<K extends keyof HTMLElementTagNameMap>(tag: K, props?: Partial<HTMLElementTagNameMap[K]>, dataset?: Dataset, styles?: Style): HTMLElementTagNameMap[K];
|
|
71
71
|
declare function createEl(tag: string, props?: Partial<HTMLElement>, dataset?: Dataset, styles?: Style): HTMLElement | null;
|
|
72
72
|
declare function assignEl<K extends keyof HTMLElementTagNameMap>(el?: HTMLElementTagNameMap[K], props?: Partial<HTMLElementTagNameMap[K]>, dataset?: Dataset, styles?: Style): void;
|
|
73
|
-
declare function assignEl(el?: HTMLElement, props?: Partial<HTMLElement>, dataset?: Dataset, styles?: Style): void;
|
|
73
|
+
declare function assignEl(el?: HTMLElement | null, props?: Partial<HTMLElement>, dataset?: Dataset, styles?: Style): void;
|
|
74
74
|
declare function loadResource(src: string, type?: ResourceType, { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts, retryKey }?: LoadResourceOptions, w?: Window & typeof globalThis): Promise<HTMLElement | void>;
|
|
75
75
|
|
|
76
76
|
declare function onAllMethods(owner: any, callback: (method: string, owner: any) => void): void;
|
package/dist/index.d.ts
CHANGED
|
@@ -70,7 +70,7 @@ type LoadResourceOptions = Partial<{
|
|
|
70
70
|
declare function createEl<K extends keyof HTMLElementTagNameMap>(tag: K, props?: Partial<HTMLElementTagNameMap[K]>, dataset?: Dataset, styles?: Style): HTMLElementTagNameMap[K];
|
|
71
71
|
declare function createEl(tag: string, props?: Partial<HTMLElement>, dataset?: Dataset, styles?: Style): HTMLElement | null;
|
|
72
72
|
declare function assignEl<K extends keyof HTMLElementTagNameMap>(el?: HTMLElementTagNameMap[K], props?: Partial<HTMLElementTagNameMap[K]>, dataset?: Dataset, styles?: Style): void;
|
|
73
|
-
declare function assignEl(el?: HTMLElement, props?: Partial<HTMLElement>, dataset?: Dataset, styles?: Style): void;
|
|
73
|
+
declare function assignEl(el?: HTMLElement | null, props?: Partial<HTMLElement>, dataset?: Dataset, styles?: Style): void;
|
|
74
74
|
declare function loadResource(src: string, type?: ResourceType, { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts, retryKey }?: LoadResourceOptions, w?: Window & typeof globalThis): Promise<HTMLElement | void>;
|
|
75
75
|
|
|
76
76
|
declare function onAllMethods(owner: any, callback: (method: string, owner: any) => void): void;
|
package/dist/index.js
CHANGED
|
@@ -18,14 +18,20 @@ function isSameURL(src1, src2) {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
// src/core/dom.ts
|
|
21
|
-
function createEl(tag, props
|
|
22
|
-
return assignEl(
|
|
21
|
+
function createEl(tag, props, dataset, styles, el = tag ? document?.createElement(tag) : null) {
|
|
22
|
+
return assignEl(el, props, dataset, styles), el;
|
|
23
23
|
}
|
|
24
|
-
function assignEl(el, props
|
|
24
|
+
function assignEl(el, props, dataset, styles) {
|
|
25
25
|
if (!el) return;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
if (props) {
|
|
27
|
+
for (const k of Object.keys(props)) if (props[k] !== void 0) el[k] = props[k];
|
|
28
|
+
}
|
|
29
|
+
if (dataset) {
|
|
30
|
+
for (const k of Object.keys(dataset)) if (dataset[k] !== void 0) el.dataset[k] = String(dataset[k]);
|
|
31
|
+
}
|
|
32
|
+
if (styles) {
|
|
33
|
+
for (const k of Object.keys(styles)) if (styles[k] !== void 0) el.style[k] = styles[k];
|
|
34
|
+
}
|
|
29
35
|
}
|
|
30
36
|
function loadResource(src, type = "style", { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts = 3, retryKey = false } = {}, w = window) {
|
|
31
37
|
w.t007._resourceCache ??= {};
|
package/package.json
CHANGED