juxscript 1.1.4 → 1.1.6
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 +10 -10
- package/index.d.ts.map +1 -0
- package/lib/components/alert.d.ts +32 -0
- package/lib/components/alert.d.ts.map +1 -0
- package/lib/components/alert.js +153 -0
- package/lib/components/alert.ts +200 -0
- package/lib/components/app.d.ts +89 -0
- package/lib/components/app.d.ts.map +1 -0
- package/lib/components/app.js +175 -0
- package/lib/components/app.ts +247 -0
- package/lib/components/badge.d.ts +27 -0
- package/lib/components/badge.d.ts.map +1 -0
- package/lib/components/badge.js +70 -0
- package/lib/components/badge.ts +101 -0
- package/lib/components/base/BaseComponent.d.ts +142 -0
- package/lib/components/base/BaseComponent.d.ts.map +1 -0
- package/lib/components/base/BaseComponent.js +363 -0
- package/lib/components/base/BaseComponent.ts +421 -0
- package/lib/components/base/FormInput.d.ts +73 -0
- package/lib/components/base/FormInput.d.ts.map +1 -0
- package/lib/components/base/FormInput.js +163 -0
- package/lib/components/base/FormInput.ts +227 -0
- package/lib/components/button.d.ts +48 -0
- package/lib/components/button.d.ts.map +1 -0
- package/lib/components/button.js +121 -0
- package/lib/components/button.ts +178 -0
- package/lib/components/card.d.ts +34 -0
- package/lib/components/card.d.ts.map +1 -0
- package/lib/components/card.js +127 -0
- package/lib/components/card.ts +173 -0
- package/lib/components/chart.d.ts +45 -0
- package/lib/components/chart.d.ts.map +1 -0
- package/lib/components/chart.js +186 -0
- package/lib/components/chart.ts +231 -0
- package/lib/components/checkbox.d.ts +31 -0
- package/lib/components/checkbox.d.ts.map +1 -0
- package/lib/components/checkbox.js +185 -0
- package/lib/components/checkbox.ts +242 -0
- package/lib/components/code.d.ts +24 -0
- package/lib/components/code.d.ts.map +1 -0
- package/lib/components/code.js +88 -0
- package/lib/components/code.ts +123 -0
- package/lib/components/container.d.ts +42 -0
- package/lib/components/container.d.ts.map +1 -0
- package/lib/components/container.js +93 -0
- package/lib/components/container.ts +140 -0
- package/lib/components/data.d.ts +36 -0
- package/lib/components/data.d.ts.map +1 -0
- package/lib/components/data.js +110 -0
- package/lib/components/data.ts +135 -0
- package/lib/components/datepicker.d.ts +38 -0
- package/lib/components/datepicker.d.ts.map +1 -0
- package/lib/components/datepicker.js +177 -0
- package/lib/components/datepicker.ts +234 -0
- package/lib/components/dialog.d.ts +38 -0
- package/lib/components/dialog.d.ts.map +1 -0
- package/lib/components/dialog.js +126 -0
- package/lib/components/dialog.ts +172 -0
- package/lib/components/divider.d.ts +30 -0
- package/lib/components/divider.d.ts.map +1 -0
- package/lib/components/divider.js +69 -0
- package/lib/components/divider.ts +100 -0
- package/lib/components/dropdown.d.ts +39 -0
- package/lib/components/dropdown.d.ts.map +1 -0
- package/lib/components/dropdown.js +133 -0
- package/lib/components/dropdown.ts +186 -0
- package/lib/components/element.d.ts +50 -0
- package/lib/components/element.d.ts.map +1 -0
- package/lib/components/element.js +206 -0
- package/lib/components/element.ts +267 -0
- package/lib/components/fileupload.d.ts +40 -0
- package/lib/components/fileupload.d.ts.map +1 -0
- package/lib/components/fileupload.js +241 -0
- package/lib/components/fileupload.ts +309 -0
- package/lib/components/grid.d.ts +87 -0
- package/lib/components/grid.d.ts.map +1 -0
- package/lib/components/grid.js +205 -0
- package/lib/components/grid.ts +291 -0
- package/lib/components/guard.d.ts +41 -0
- package/lib/components/guard.d.ts.map +1 -0
- package/lib/components/guard.js +56 -0
- package/lib/components/guard.ts +92 -0
- package/lib/components/heading.d.ts +24 -0
- package/lib/components/heading.d.ts.map +1 -0
- package/lib/components/heading.js +67 -0
- package/lib/components/heading.ts +96 -0
- package/lib/components/helpers.d.ts +9 -0
- package/lib/components/helpers.d.ts.map +1 -0
- package/lib/components/helpers.js +30 -0
- package/lib/components/helpers.ts +41 -0
- package/lib/components/hero.d.ts +45 -0
- package/lib/components/hero.d.ts.map +1 -0
- package/lib/components/hero.js +165 -0
- package/lib/components/hero.ts +224 -0
- package/lib/components/icon.d.ts +35 -0
- package/lib/components/icon.d.ts.map +1 -0
- package/lib/components/icon.js +132 -0
- package/lib/components/icon.ts +178 -0
- package/lib/components/icons.d.ts +25 -0
- package/lib/components/icons.d.ts.map +1 -0
- package/lib/components/icons.js +440 -0
- package/lib/components/icons.ts +464 -0
- package/lib/components/include.d.ts +120 -0
- package/lib/components/include.d.ts.map +1 -0
- package/lib/components/include.js +350 -0
- package/lib/components/include.ts +410 -0
- package/lib/components/input.d.ts +83 -0
- package/lib/components/input.d.ts.map +1 -0
- package/lib/components/input.js +348 -0
- package/lib/components/input.ts +457 -0
- package/lib/components/list.d.ts +82 -0
- package/lib/components/list.d.ts.map +1 -0
- package/lib/components/list.js +311 -0
- package/lib/components/list.ts +419 -0
- package/lib/components/loading.d.ts +24 -0
- package/lib/components/loading.d.ts.map +1 -0
- package/lib/components/loading.js +73 -0
- package/lib/components/loading.ts +100 -0
- package/lib/components/menu.d.ts +37 -0
- package/lib/components/menu.d.ts.map +1 -0
- package/lib/components/menu.js +202 -0
- package/lib/components/menu.ts +275 -0
- package/lib/components/modal.d.ts +51 -0
- package/lib/components/modal.d.ts.map +1 -0
- package/lib/components/modal.js +227 -0
- package/lib/components/modal.ts +284 -0
- package/lib/components/nav.d.ts +45 -0
- package/lib/components/nav.d.ts.map +1 -0
- package/lib/components/nav.js +190 -0
- package/lib/components/nav.ts +257 -0
- package/lib/components/paragraph.d.ts +21 -0
- package/lib/components/paragraph.d.ts.map +1 -0
- package/lib/components/paragraph.js +70 -0
- package/lib/components/paragraph.ts +97 -0
- package/lib/components/progress.d.ts +39 -0
- package/lib/components/progress.d.ts.map +1 -0
- package/lib/components/progress.js +113 -0
- package/lib/components/progress.ts +159 -0
- package/lib/components/radio.d.ts +41 -0
- package/lib/components/radio.d.ts.map +1 -0
- package/lib/components/radio.js +203 -0
- package/lib/components/radio.ts +278 -0
- package/lib/components/req.d.ts +155 -0
- package/lib/components/req.d.ts.map +1 -0
- package/lib/components/req.js +253 -0
- package/lib/components/req.ts +303 -0
- package/lib/components/script.d.ts +14 -0
- package/lib/components/script.d.ts.map +1 -0
- package/lib/components/script.js +33 -0
- package/lib/components/script.ts +41 -0
- package/lib/components/select.d.ts +40 -0
- package/lib/components/select.d.ts.map +1 -0
- package/lib/components/select.js +183 -0
- package/lib/components/select.ts +252 -0
- package/lib/components/sidebar.d.ts +48 -0
- package/lib/components/sidebar.d.ts.map +1 -0
- package/lib/components/sidebar.js +207 -0
- package/lib/components/sidebar.ts +275 -0
- package/lib/components/style.d.ts +14 -0
- package/lib/components/style.d.ts.map +1 -0
- package/lib/components/style.js +33 -0
- package/lib/components/style.ts +41 -0
- package/lib/components/switch.d.ts +32 -0
- package/lib/components/switch.d.ts.map +1 -0
- package/lib/components/switch.js +186 -0
- package/lib/components/switch.ts +246 -0
- package/lib/components/table.d.ts +137 -0
- package/lib/components/table.d.ts.map +1 -0
- package/lib/components/table.js +1045 -0
- package/lib/components/table.ts +1249 -0
- package/lib/components/tabs.d.ts +36 -0
- package/lib/components/tabs.d.ts.map +1 -0
- package/lib/components/tabs.js +198 -0
- package/lib/components/tabs.ts +250 -0
- package/lib/components/theme-toggle.d.ts +44 -0
- package/lib/components/theme-toggle.d.ts.map +1 -0
- package/lib/components/theme-toggle.js +215 -0
- package/lib/components/theme-toggle.ts +293 -0
- package/lib/components/tooltip.d.ts +30 -0
- package/lib/components/tooltip.d.ts.map +1 -0
- package/lib/components/tooltip.js +109 -0
- package/lib/components/tooltip.ts +144 -0
- package/lib/components/view.d.ts +48 -0
- package/lib/components/view.d.ts.map +1 -0
- package/lib/components/view.js +149 -0
- package/lib/components/view.ts +190 -0
- package/lib/components/write.d.ts +107 -0
- package/lib/components/write.d.ts.map +1 -0
- package/lib/components/write.js +222 -0
- package/lib/components/write.ts +272 -0
- package/lib/layouts/default.css +260 -0
- package/lib/layouts/figma.css +334 -0
- package/lib/reactivity/state.d.ts +36 -0
- package/lib/reactivity/state.d.ts.map +1 -0
- package/lib/reactivity/state.js +67 -0
- package/lib/reactivity/state.ts +78 -0
- package/lib/utils/fetch.d.ts +176 -0
- package/lib/utils/fetch.d.ts.map +1 -0
- package/lib/utils/fetch.js +427 -0
- package/lib/utils/fetch.ts +553 -0
- package/machinery/compiler3.js +78 -0
- package/machinery/doc-generator.js +136 -0
- package/machinery/imports.js +155 -0
- package/machinery/ts-shim.js +46 -0
- package/package.json +9 -15
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Write - Simple content writer with no component tracking
|
|
3
|
+
* Perfect for quick HTML output without ID management
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Write content directly to a target element
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* // Write text (defaults to body)
|
|
10
|
+
* jux.write('Hello World!').render();
|
|
11
|
+
*
|
|
12
|
+
* // Write to specific target
|
|
13
|
+
* jux.write('Content').render('#container');
|
|
14
|
+
*
|
|
15
|
+
* // Write HTML
|
|
16
|
+
* jux.write('<strong>Bold text</strong>').html(true).render('#container');
|
|
17
|
+
*
|
|
18
|
+
* // Write with styling
|
|
19
|
+
* jux.write('Styled text').style('color: red;').render('#container');
|
|
20
|
+
*/
|
|
21
|
+
export class Write {
|
|
22
|
+
constructor(content, options = {}) {
|
|
23
|
+
this.content = content;
|
|
24
|
+
this.options = {
|
|
25
|
+
tagType: 'div',
|
|
26
|
+
className: '',
|
|
27
|
+
style: '',
|
|
28
|
+
attributes: {},
|
|
29
|
+
html: false,
|
|
30
|
+
...options
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/* ═════════════════════════════════════════════════════════════════
|
|
34
|
+
* FLUENT API
|
|
35
|
+
* ═════════════════════════════════════════════════════════════════ */
|
|
36
|
+
/**
|
|
37
|
+
* Set HTML mode (treat content as HTML)
|
|
38
|
+
*/
|
|
39
|
+
html(enabled = true) {
|
|
40
|
+
this.options.html = enabled;
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Set tag type
|
|
45
|
+
*/
|
|
46
|
+
tagType(value) {
|
|
47
|
+
this.options.tagType = value;
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Set CSS class
|
|
52
|
+
*/
|
|
53
|
+
className(value) {
|
|
54
|
+
this.options.className = value;
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Set inline styles
|
|
59
|
+
*/
|
|
60
|
+
style(value) {
|
|
61
|
+
this.options.style = value;
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Set custom attributes
|
|
66
|
+
*/
|
|
67
|
+
attrs(attributes) {
|
|
68
|
+
this.options.attributes = attributes;
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
/* ═════════════════════════════════════════════════════════════════
|
|
72
|
+
* RENDER METHODS
|
|
73
|
+
* ═════════════════════════════════════════════════════════════════ */
|
|
74
|
+
/**
|
|
75
|
+
* Render content to target element
|
|
76
|
+
*/
|
|
77
|
+
render(targetSelector) {
|
|
78
|
+
const target = this._getTarget(targetSelector);
|
|
79
|
+
if (!target)
|
|
80
|
+
return this;
|
|
81
|
+
const element = this._createElement();
|
|
82
|
+
target.appendChild(element);
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Replace target content (clear first, then render)
|
|
87
|
+
*/
|
|
88
|
+
replace(targetSelector) {
|
|
89
|
+
const target = this._getTarget(targetSelector);
|
|
90
|
+
if (!target)
|
|
91
|
+
return this;
|
|
92
|
+
target.innerHTML = '';
|
|
93
|
+
const element = this._createElement();
|
|
94
|
+
target.appendChild(element);
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Render before target element
|
|
99
|
+
*/
|
|
100
|
+
before(targetSelector) {
|
|
101
|
+
const target = document.querySelector(targetSelector);
|
|
102
|
+
if (!target || !(target instanceof HTMLElement)) {
|
|
103
|
+
console.warn(`Write: Target element "${targetSelector}" not found`);
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
const element = this._createElement();
|
|
107
|
+
target.parentNode?.insertBefore(element, target);
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Render after target element
|
|
112
|
+
*/
|
|
113
|
+
after(targetSelector) {
|
|
114
|
+
const target = document.querySelector(targetSelector);
|
|
115
|
+
if (!target || !(target instanceof HTMLElement)) {
|
|
116
|
+
console.warn(`Write: Target element "${targetSelector}" not found`);
|
|
117
|
+
return this;
|
|
118
|
+
}
|
|
119
|
+
const element = this._createElement();
|
|
120
|
+
target.parentNode?.insertBefore(element, target.nextSibling);
|
|
121
|
+
return this;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Prepend to target (insert as first child)
|
|
125
|
+
*/
|
|
126
|
+
prepend(targetSelector) {
|
|
127
|
+
const target = this._getTarget(targetSelector);
|
|
128
|
+
if (!target)
|
|
129
|
+
return this;
|
|
130
|
+
const element = this._createElement();
|
|
131
|
+
target.insertBefore(element, target.firstChild);
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Append to target (alias for render)
|
|
136
|
+
*/
|
|
137
|
+
append(targetSelector) {
|
|
138
|
+
return this.render(targetSelector);
|
|
139
|
+
}
|
|
140
|
+
/* ═════════════════════════════════════════════════════════════════
|
|
141
|
+
* PRIVATE HELPERS
|
|
142
|
+
* ═════════════════════════════════════════════════════════════════ */
|
|
143
|
+
_getTarget(selector) {
|
|
144
|
+
const targetSelector = selector || 'body';
|
|
145
|
+
const target = document.querySelector(targetSelector);
|
|
146
|
+
if (!target || !(target instanceof HTMLElement)) {
|
|
147
|
+
console.warn(`Write: Target element "${targetSelector}" not found`);
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
return target;
|
|
151
|
+
}
|
|
152
|
+
_createElement() {
|
|
153
|
+
const element = document.createElement(this.options.tagType);
|
|
154
|
+
// Set content (text or HTML)
|
|
155
|
+
if (this.options.html) {
|
|
156
|
+
element.innerHTML = this.content;
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
element.textContent = this.content;
|
|
160
|
+
}
|
|
161
|
+
// Apply className
|
|
162
|
+
if (this.options.className) {
|
|
163
|
+
element.className = this.options.className;
|
|
164
|
+
}
|
|
165
|
+
// Apply inline styles
|
|
166
|
+
if (this.options.style) {
|
|
167
|
+
element.setAttribute('style', this.options.style);
|
|
168
|
+
}
|
|
169
|
+
// Apply custom attributes
|
|
170
|
+
if (this.options.attributes) {
|
|
171
|
+
Object.entries(this.options.attributes).forEach(([key, value]) => {
|
|
172
|
+
element.setAttribute(key, value);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
return element;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Factory function - simple, no overloads
|
|
180
|
+
*/
|
|
181
|
+
export function write(content, options = {}) {
|
|
182
|
+
return new Write(content, options);
|
|
183
|
+
}
|
|
184
|
+
/* ═════════════════════════════════════════════════════════════════
|
|
185
|
+
* SHORTHAND HELPERS
|
|
186
|
+
* ═════════════════════════════════════════════════════════════════ */
|
|
187
|
+
/**
|
|
188
|
+
* Write text (explicit)
|
|
189
|
+
*/
|
|
190
|
+
export function writeText(content, options = {}) {
|
|
191
|
+
return new Write(content, { ...options, html: false });
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Write HTML (explicit)
|
|
195
|
+
*/
|
|
196
|
+
export function writeHtml(content, options = {}) {
|
|
197
|
+
return new Write(content, { ...options, html: true });
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Write paragraph
|
|
201
|
+
*/
|
|
202
|
+
export function writeParagraph(content, options = {}) {
|
|
203
|
+
return new Write(content, { ...options, tagType: 'p' });
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Write heading
|
|
207
|
+
*/
|
|
208
|
+
export function writeHeading(content, level = 2, options = {}) {
|
|
209
|
+
return new Write(content, { ...options, tagType: `h${level}` });
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Write span
|
|
213
|
+
*/
|
|
214
|
+
export function writeSpan(content, options = {}) {
|
|
215
|
+
return new Write(content, { ...options, tagType: 'span' });
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Write div (explicit)
|
|
219
|
+
*/
|
|
220
|
+
export function writeDiv(content, options = {}) {
|
|
221
|
+
return new Write(content, { ...options, tagType: 'div' });
|
|
222
|
+
}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Write - Simple content writer with no component tracking
|
|
3
|
+
* Perfect for quick HTML output without ID management
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface WriteOptions {
|
|
7
|
+
tagType?: string;
|
|
8
|
+
className?: string;
|
|
9
|
+
style?: string;
|
|
10
|
+
attributes?: Record<string, string>;
|
|
11
|
+
html?: boolean; // If true, treat content as HTML; if false, treat as text
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Write content directly to a target element
|
|
16
|
+
*
|
|
17
|
+
* Usage:
|
|
18
|
+
* // Write text (defaults to body)
|
|
19
|
+
* jux.write('Hello World!').render();
|
|
20
|
+
*
|
|
21
|
+
* // Write to specific target
|
|
22
|
+
* jux.write('Content').render('#container');
|
|
23
|
+
*
|
|
24
|
+
* // Write HTML
|
|
25
|
+
* jux.write('<strong>Bold text</strong>').html(true).render('#container');
|
|
26
|
+
*
|
|
27
|
+
* // Write with styling
|
|
28
|
+
* jux.write('Styled text').style('color: red;').render('#container');
|
|
29
|
+
*/
|
|
30
|
+
export class Write {
|
|
31
|
+
private content: string;
|
|
32
|
+
private options: WriteOptions;
|
|
33
|
+
|
|
34
|
+
constructor(content: string, options: WriteOptions = {}) {
|
|
35
|
+
this.content = content;
|
|
36
|
+
this.options = {
|
|
37
|
+
tagType: 'div',
|
|
38
|
+
className: '',
|
|
39
|
+
style: '',
|
|
40
|
+
attributes: {},
|
|
41
|
+
html: false,
|
|
42
|
+
...options
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/* ═════════════════════════════════════════════════════════════════
|
|
47
|
+
* FLUENT API
|
|
48
|
+
* ═════════════════════════════════════════════════════════════════ */
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Set HTML mode (treat content as HTML)
|
|
52
|
+
*/
|
|
53
|
+
html(enabled: boolean = true): this {
|
|
54
|
+
this.options.html = enabled;
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Set tag type
|
|
60
|
+
*/
|
|
61
|
+
tagType(value: string): this {
|
|
62
|
+
this.options.tagType = value;
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Set CSS class
|
|
68
|
+
*/
|
|
69
|
+
className(value: string): this {
|
|
70
|
+
this.options.className = value;
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Set inline styles
|
|
76
|
+
*/
|
|
77
|
+
style(value: string): this {
|
|
78
|
+
this.options.style = value;
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Set custom attributes
|
|
84
|
+
*/
|
|
85
|
+
attrs(attributes: Record<string, string>): this {
|
|
86
|
+
this.options.attributes = attributes;
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/* ═════════════════════════════════════════════════════════════════
|
|
91
|
+
* RENDER METHODS
|
|
92
|
+
* ═════════════════════════════════════════════════════════════════ */
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Render content to target element
|
|
96
|
+
*/
|
|
97
|
+
render(targetSelector?: string): this {
|
|
98
|
+
const target = this._getTarget(targetSelector);
|
|
99
|
+
if (!target) return this;
|
|
100
|
+
|
|
101
|
+
const element = this._createElement();
|
|
102
|
+
target.appendChild(element);
|
|
103
|
+
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Replace target content (clear first, then render)
|
|
109
|
+
*/
|
|
110
|
+
replace(targetSelector?: string): this {
|
|
111
|
+
const target = this._getTarget(targetSelector);
|
|
112
|
+
if (!target) return this;
|
|
113
|
+
|
|
114
|
+
target.innerHTML = '';
|
|
115
|
+
const element = this._createElement();
|
|
116
|
+
target.appendChild(element);
|
|
117
|
+
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Render before target element
|
|
123
|
+
*/
|
|
124
|
+
before(targetSelector: string): this {
|
|
125
|
+
const target = document.querySelector(targetSelector);
|
|
126
|
+
if (!target || !(target instanceof HTMLElement)) {
|
|
127
|
+
console.warn(`Write: Target element "${targetSelector}" not found`);
|
|
128
|
+
return this;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const element = this._createElement();
|
|
132
|
+
target.parentNode?.insertBefore(element, target);
|
|
133
|
+
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Render after target element
|
|
139
|
+
*/
|
|
140
|
+
after(targetSelector: string): this {
|
|
141
|
+
const target = document.querySelector(targetSelector);
|
|
142
|
+
if (!target || !(target instanceof HTMLElement)) {
|
|
143
|
+
console.warn(`Write: Target element "${targetSelector}" not found`);
|
|
144
|
+
return this;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const element = this._createElement();
|
|
148
|
+
target.parentNode?.insertBefore(element, target.nextSibling);
|
|
149
|
+
|
|
150
|
+
return this;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Prepend to target (insert as first child)
|
|
155
|
+
*/
|
|
156
|
+
prepend(targetSelector?: string): this {
|
|
157
|
+
const target = this._getTarget(targetSelector);
|
|
158
|
+
if (!target) return this;
|
|
159
|
+
|
|
160
|
+
const element = this._createElement();
|
|
161
|
+
target.insertBefore(element, target.firstChild);
|
|
162
|
+
|
|
163
|
+
return this;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Append to target (alias for render)
|
|
168
|
+
*/
|
|
169
|
+
append(targetSelector?: string): this {
|
|
170
|
+
return this.render(targetSelector);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/* ═════════════════════════════════════════════════════════════════
|
|
174
|
+
* PRIVATE HELPERS
|
|
175
|
+
* ═════════════════════════════════════════════════════════════════ */
|
|
176
|
+
|
|
177
|
+
private _getTarget(selector?: string): HTMLElement | null {
|
|
178
|
+
const targetSelector = selector || 'body';
|
|
179
|
+
const target = document.querySelector(targetSelector);
|
|
180
|
+
|
|
181
|
+
if (!target || !(target instanceof HTMLElement)) {
|
|
182
|
+
console.warn(`Write: Target element "${targetSelector}" not found`);
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return target;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
private _createElement(): HTMLElement {
|
|
190
|
+
const element = document.createElement(this.options.tagType!);
|
|
191
|
+
|
|
192
|
+
// Set content (text or HTML)
|
|
193
|
+
if (this.options.html) {
|
|
194
|
+
element.innerHTML = this.content;
|
|
195
|
+
} else {
|
|
196
|
+
element.textContent = this.content;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Apply className
|
|
200
|
+
if (this.options.className) {
|
|
201
|
+
element.className = this.options.className;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Apply inline styles
|
|
205
|
+
if (this.options.style) {
|
|
206
|
+
element.setAttribute('style', this.options.style);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// Apply custom attributes
|
|
210
|
+
if (this.options.attributes) {
|
|
211
|
+
Object.entries(this.options.attributes).forEach(([key, value]) => {
|
|
212
|
+
element.setAttribute(key, value);
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return element;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Factory function - simple, no overloads
|
|
222
|
+
*/
|
|
223
|
+
export function write(content: string, options: WriteOptions = {}): Write {
|
|
224
|
+
return new Write(content, options);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/* ═════════════════════════════════════════════════════════════════
|
|
228
|
+
* SHORTHAND HELPERS
|
|
229
|
+
* ═════════════════════════════════════════════════════════════════ */
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Write text (explicit)
|
|
233
|
+
*/
|
|
234
|
+
export function writeText(content: string, options: Omit<WriteOptions, 'html'> = {}): Write {
|
|
235
|
+
return new Write(content, { ...options, html: false });
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Write HTML (explicit)
|
|
240
|
+
*/
|
|
241
|
+
export function writeHtml(content: string, options: Omit<WriteOptions, 'html'> = {}): Write {
|
|
242
|
+
return new Write(content, { ...options, html: true });
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Write paragraph
|
|
247
|
+
*/
|
|
248
|
+
export function writeParagraph(content: string, options: Omit<WriteOptions, 'tagType'> = {}): Write {
|
|
249
|
+
return new Write(content, { ...options, tagType: 'p' });
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Write heading
|
|
254
|
+
*/
|
|
255
|
+
export function writeHeading(content: string, level: 1 | 2 | 3 | 4 | 5 | 6 = 2, options: Omit<WriteOptions, 'tagType'> = {}): Write {
|
|
256
|
+
return new Write(content, { ...options, tagType: `h${level}` });
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Write span
|
|
261
|
+
*/
|
|
262
|
+
export function writeSpan(content: string, options: Omit<WriteOptions, 'tagType'> = {}): Write {
|
|
263
|
+
return new Write(content, { ...options, tagType: 'span' });
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Write div (explicit)
|
|
268
|
+
*/
|
|
269
|
+
export function writeDiv(content: string, options: Omit<WriteOptions, 'tagType'> = {}): Write {
|
|
270
|
+
return new Write(content, { ...options, tagType: 'div' });
|
|
271
|
+
}
|
|
272
|
+
|