juxscript 1.1.254 → 1.1.255
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.
|
@@ -1,23 +1,33 @@
|
|
|
1
|
+
interface TagOptions {
|
|
2
|
+
content?: string;
|
|
3
|
+
class?: string;
|
|
4
|
+
style?: string;
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
}
|
|
1
7
|
declare class Tag {
|
|
2
8
|
id: string;
|
|
3
|
-
content: string;
|
|
4
|
-
options: Record<string, any>;
|
|
5
9
|
tagName: string;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
opts: TagOptions;
|
|
11
|
+
private _element;
|
|
12
|
+
constructor(id: string, tagName: string, options?: TagOptions);
|
|
13
|
+
content(value: string): this;
|
|
14
|
+
class(value: string): this;
|
|
15
|
+
style(value: string): this;
|
|
16
|
+
render(target?: string | HTMLElement): this;
|
|
17
|
+
getElement(): HTMLElement | null;
|
|
9
18
|
}
|
|
10
|
-
export declare function tag(
|
|
11
|
-
export declare function div(
|
|
12
|
-
export declare function span(
|
|
13
|
-
export declare function p(
|
|
14
|
-
export declare function code(
|
|
15
|
-
export declare function pre(
|
|
16
|
-
export declare function h1(
|
|
17
|
-
export declare function h2(
|
|
18
|
-
export declare function h3(
|
|
19
|
-
export declare function h4(
|
|
20
|
-
export declare function h5(
|
|
21
|
-
export declare function h6(
|
|
19
|
+
export declare function tag(id: string, tagName: string, options?: TagOptions): Tag;
|
|
20
|
+
export declare function div(id: string, options?: TagOptions): Tag;
|
|
21
|
+
export declare function span(id: string, options?: TagOptions): Tag;
|
|
22
|
+
export declare function p(id: string, options?: TagOptions): Tag;
|
|
23
|
+
export declare function code(id: string, options?: TagOptions): Tag;
|
|
24
|
+
export declare function pre(id: string, options?: TagOptions): Tag;
|
|
25
|
+
export declare function h1(id: string, options?: TagOptions): Tag;
|
|
26
|
+
export declare function h2(id: string, options?: TagOptions): Tag;
|
|
27
|
+
export declare function h3(id: string, options?: TagOptions): Tag;
|
|
28
|
+
export declare function h4(id: string, options?: TagOptions): Tag;
|
|
29
|
+
export declare function h5(id: string, options?: TagOptions): Tag;
|
|
30
|
+
export declare function h6(id: string, options?: TagOptions): Tag;
|
|
31
|
+
export { Tag, TagOptions };
|
|
22
32
|
export default tag;
|
|
23
33
|
//# sourceMappingURL=tag.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tag.d.ts","sourceRoot":"","sources":["../../../lib/components/tag.ts"],"names":[],"mappings":"AAEA,cAAM,GAAG;IACL,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"tag.d.ts","sourceRoot":"","sources":["../../../lib/components/tag.ts"],"names":[],"mappings":"AAEA,UAAU,UAAU;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACtB;AAED,cAAM,GAAG;IACL,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,UAAU,CAAC;IACjB,OAAO,CAAC,QAAQ,CAA4B;gBAEhC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,UAAe;IAOjE,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAC5B,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAC1B,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAE1B,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,WAAW;IAuBpC,UAAU,IAAI,WAAW,GAAG,IAAI;CACnC;AAED,wBAAgB,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,UAAe,OAIxE;AAED,wBAAgB,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,UAAe,OAAqC;AAC7F,wBAAgB,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,UAAe,OAAsC;AAC/F,wBAAgB,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,UAAe,OAAmC;AACzF,wBAAgB,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,UAAe,OAAsC;AAC/F,wBAAgB,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,UAAe,OAAqC;AAC7F,wBAAgB,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,UAAe,OAAoC;AAC3F,wBAAgB,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,UAAe,OAAoC;AAC3F,wBAAgB,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,UAAe,OAAoC;AAC3F,wBAAgB,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,UAAe,OAAoC;AAC3F,wBAAgB,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,UAAe,OAAoC;AAC3F,wBAAgB,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,GAAE,UAAe,OAAoC;AAE3F,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC;AAC3B,eAAe,GAAG,CAAC"}
|
|
@@ -1,40 +1,56 @@
|
|
|
1
1
|
import generateId from '../utils/idgen.js';
|
|
2
2
|
class Tag {
|
|
3
|
-
constructor(
|
|
4
|
-
this.
|
|
5
|
-
this.
|
|
6
|
-
this.
|
|
7
|
-
this.
|
|
3
|
+
constructor(id, tagName, options = {}) {
|
|
4
|
+
this._element = null;
|
|
5
|
+
this.id = id || generateId();
|
|
6
|
+
this.tagName = tagName;
|
|
7
|
+
this.opts = options;
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
// Fluent API
|
|
10
|
+
content(value) { this.opts.content = value; if (this._element)
|
|
11
|
+
this._element.textContent = value; return this; }
|
|
12
|
+
class(value) { this.opts.class = value; return this; }
|
|
13
|
+
style(value) { this.opts.style = value; if (this._element)
|
|
14
|
+
this._element.setAttribute('style', value); return this; }
|
|
15
|
+
render(target) {
|
|
13
16
|
const el = document.createElement(this.tagName);
|
|
14
17
|
el.id = this.id;
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
if (this.opts.content)
|
|
19
|
+
el.textContent = this.opts.content;
|
|
20
|
+
if (this.opts.class)
|
|
21
|
+
el.className = this.opts.class;
|
|
22
|
+
if (this.opts.style)
|
|
23
|
+
el.setAttribute('style', this.opts.style);
|
|
24
|
+
// Apply any extra attributes
|
|
25
|
+
for (const [key, value] of Object.entries(this.opts)) {
|
|
26
|
+
if (['content', 'class', 'style'].includes(key))
|
|
27
|
+
continue;
|
|
17
28
|
el.setAttribute(key, String(value));
|
|
18
29
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
30
|
+
this._element = el;
|
|
31
|
+
const container = target
|
|
32
|
+
? (typeof target === 'string' ? document.getElementById(target) || document.querySelector(target) : target)
|
|
33
|
+
: document.getElementById('app');
|
|
34
|
+
container?.appendChild(el);
|
|
35
|
+
return this;
|
|
22
36
|
}
|
|
37
|
+
getElement() { return this._element; }
|
|
23
38
|
}
|
|
24
|
-
export function tag(
|
|
25
|
-
const t = new Tag(
|
|
39
|
+
export function tag(id, tagName, options = {}) {
|
|
40
|
+
const t = new Tag(id, tagName, options);
|
|
26
41
|
t.render();
|
|
27
42
|
return t;
|
|
28
43
|
}
|
|
29
|
-
export function div(
|
|
30
|
-
export function span(
|
|
31
|
-
export function p(
|
|
32
|
-
export function code(
|
|
33
|
-
export function pre(
|
|
34
|
-
export function h1(
|
|
35
|
-
export function h2(
|
|
36
|
-
export function h3(
|
|
37
|
-
export function h4(
|
|
38
|
-
export function h5(
|
|
39
|
-
export function h6(
|
|
44
|
+
export function div(id, options = {}) { return tag(id, 'div', options); }
|
|
45
|
+
export function span(id, options = {}) { return tag(id, 'span', options); }
|
|
46
|
+
export function p(id, options = {}) { return tag(id, 'p', options); }
|
|
47
|
+
export function code(id, options = {}) { return tag(id, 'code', options); }
|
|
48
|
+
export function pre(id, options = {}) { return tag(id, 'pre', options); }
|
|
49
|
+
export function h1(id, options = {}) { return tag(id, 'h1', options); }
|
|
50
|
+
export function h2(id, options = {}) { return tag(id, 'h2', options); }
|
|
51
|
+
export function h3(id, options = {}) { return tag(id, 'h3', options); }
|
|
52
|
+
export function h4(id, options = {}) { return tag(id, 'h4', options); }
|
|
53
|
+
export function h5(id, options = {}) { return tag(id, 'h5', options); }
|
|
54
|
+
export function h6(id, options = {}) { return tag(id, 'h6', options); }
|
|
55
|
+
export { Tag };
|
|
40
56
|
export default tag;
|