lexgui 8.2.2 → 8.2.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.
@@ -1,331 +1,354 @@
1
- // This is a generated file. Do not edit.
2
- import { LX } from '../core/Namespace.js';
3
-
4
- // DocMaker.ts @jxarco
5
- if (!LX) {
6
- throw ('Missing LX namespace!');
7
- }
8
- LX.extensions.push('DocMaker');
9
- const CPP_KEY_WORDS = ['int', 'float', 'double', 'bool', 'char', 'wchar_t', 'const', 'static_cast', 'dynamic_cast', 'new', 'delete', 'void', 'true',
10
- 'false', 'auto', 'struct', 'typedef', 'nullptr', 'NULL', 'unsigned', 'namespace', 'auto'];
11
- const CLASS_WORDS = ['uint32_t', 'uint64_t', 'uint8_t'];
12
- const STATEMENT_WORDS = ['for', 'if', 'else', 'return', 'continue', 'break', 'case', 'switch', 'while', 'import', 'from', 'await'];
13
- const JS_KEY_WORDS = ['var', 'let', 'const', 'static', 'function', 'null', 'undefined', 'new', 'delete', 'true', 'false', 'NaN', 'this'];
14
- const HTML_ATTRIBUTES = ['html', 'charset', 'rel', 'src', 'href', 'crossorigin', 'type', 'lang'];
15
- const HTML_TAGS = ['DOCTYPE', 'html', 'head', 'body', 'title', 'base', 'link', 'meta', 'style', 'main', 'section', 'nav', 'article', 'aside',
16
- 'header', 'footer', 'address', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'hr', 'pre', 'blockquote', 'ol', 'ul', 'li', 'dl', 'dt', 'dd', 'figure',
17
- 'figcaption', 'div', 'a', 'abbr', 'b', 'bdi', 'bdo', 'br', 'cite', 'code', 'data', 'dfn', 'em', 'i', 'kbd', 'mark', 'q', 'rp', 'rt', 'ruby', 's',
18
- 'samp', 'small', 'span', 'strong', 'sub', 'sup', 'time', 'u', 'var', 'wbr', 'img', 'audio', 'video', 'source', 'track', 'picture', 'map', 'area',
19
- 'canvas', 'iframe', 'embed', 'object', 'param', 'form', 'label', 'input', 'button', 'select', 'datalist', 'optgroup', 'option', 'textarea',
20
- 'output', 'progress', 'meter', 'fieldset', 'legend', 'table', 'caption', 'colgroup', 'col', 'tbody', 'thead', 'tfoot', 'tr', 'td', 'th',
21
- 'details', 'summary', 'dialog', 'script', 'noscript', 'template'];
22
- class DocMaker {
23
- root;
24
- _listQueued = undefined;
25
- constructor(element) {
26
- this.root = element ?? document.body;
27
- }
28
- setDomTarget(element) {
29
- this.root = element;
30
- }
31
- lineBreak(target) {
32
- target = target ?? this.root;
33
- target.appendChild(document.createElement('br'));
34
- }
35
- header(string, type, id) {
36
- console.assert(string !== undefined && type !== undefined);
37
- let header = document.createElement(type);
38
- header.innerHTML = string;
39
- if (id)
40
- header.id = id;
41
- this.root.appendChild(header);
42
- }
43
- paragraph(string, sup = false, className) {
44
- console.assert(string !== undefined);
45
- let paragraph = document.createElement(sup ? 'sup' : 'p');
46
- paragraph.className = 'leading-relaxed ' + (className ?? '');
47
- paragraph.innerHTML = string;
48
- this.root.appendChild(paragraph);
49
- }
50
- code(text, language = 'js') {
51
- console.assert(text !== undefined);
52
- text.replaceAll('<', '&lt;');
53
- text.replaceAll('>', '&gt;');
54
- let highlight = '';
55
- let content = '';
56
- const getHTML = (h, c) => {
57
- return `<span class="${h}">${c}</span>`;
58
- };
59
- for (let i = 0; i < text.length; ++i) {
60
- const char = text[i];
61
- const string = text.substr(i);
62
- const endLineIdx = string.indexOf('\n');
63
- const line = string.substring(0, endLineIdx > -1 ? endLineIdx : undefined);
64
- if (char == '@') {
65
- const str = line.substr(1);
66
- if (!(str.indexOf('@') > -1) && !(str.indexOf('[') > -1)) {
67
- continue;
68
- }
69
- let html = null;
70
- const tagIndex = str.indexOf('@');
71
- const skipTag = str[tagIndex - 1] == '|';
72
- // Highlight is specified
73
- if (text[i + 1] == '[') {
74
- highlight = str.substr(1, 3);
75
- content = str.substring(5, tagIndex);
76
- if (skipTag) {
77
- const newString = str.substring(6 + content.length);
78
- const preContent = content;
79
- const postContent = newString.substring(0, newString.indexOf('@'));
80
- const finalContent = preContent.substring(0, preContent.length - 1) + '@' + postContent;
81
- html = getHTML(highlight, finalContent);
82
- const ogContent = preContent + '@' + postContent;
83
- text = text.replace(`@[${highlight}]${ogContent}@`, html);
84
- }
85
- else {
86
- html = getHTML(highlight, content);
87
- text = text.replace(`@[${highlight}]${content}@`, html);
88
- }
89
- }
90
- else {
91
- content = str.substring(0, tagIndex);
92
- if (skipTag) {
93
- const preContent = str.substring(0, str.indexOf('@') - 1);
94
- content = str.substring(preContent.length + 1);
95
- content = preContent + content.substring(0, content.substring(1).indexOf('@') + 1);
96
- text = text.substr(0, i) + '@' + content + '@' + text.substr(i + content.length + 3);
97
- }
98
- if (language == 'cpp' && CPP_KEY_WORDS.includes(content)) {
99
- highlight = 'kwd';
100
- }
101
- else if (language == 'js' && JS_KEY_WORDS.includes(content)) {
102
- highlight = 'kwd';
103
- }
104
- else if (CLASS_WORDS.includes(content)) {
105
- highlight = 'cls';
106
- }
107
- else if (STATEMENT_WORDS.includes(content)) {
108
- highlight = 'lit';
109
- }
110
- else if (HTML_TAGS.includes(content)) {
111
- highlight = 'tag';
112
- }
113
- else if (HTML_ATTRIBUTES.includes(content)) {
114
- highlight = 'atn';
115
- }
116
- else if ((content[0] == '"' && content[content.length - 1] == '"')
117
- || (content[0] == "'" && content[content.length - 1] == "'")
118
- || (content[0] == '`' && content[content.length - 1] == '`')) {
119
- highlight = 'str';
120
- }
121
- else if (!Number.isNaN(parseFloat(content))) {
122
- highlight = 'dec';
123
- }
124
- else {
125
- console.error('ERROR[Code Parsing]: Unknown highlight type: ' + content);
126
- return;
127
- }
128
- html = getHTML(highlight, content);
129
- text = text.replace(`@${content}@`, html);
130
- }
131
- i += html.length - 1;
132
- }
133
- }
134
- let container = document.createElement('div');
135
- container.className = 'code-container';
136
- let pre = document.createElement('pre');
137
- let code = document.createElement('code');
138
- code.innerHTML = text;
139
- let button = document.createElement('button');
140
- button.title = 'Copy code sample';
141
- button.appendChild(LX.makeIcon('Copy'));
142
- button.addEventListener('click', this._copySnippet.bind(this, button));
143
- container.appendChild(button);
144
- pre.appendChild(code);
145
- container.appendChild(pre);
146
- this.root.appendChild(container);
147
- }
148
- list(list, type, target) {
149
- const validTypes = ['bullet', 'numbered'];
150
- console.assert(list && list.length > 0 && validTypes.includes(type), 'Invalid list type or empty list' + type);
151
- const typeString = type == 'bullet' ? 'ul' : 'ol';
152
- let ul = document.createElement(typeString);
153
- target = target ?? this.root;
154
- target.appendChild(ul);
155
- for (var el of list) {
156
- if (el.constructor === Array) {
157
- this.list(el, type, ul);
158
- return;
159
- }
160
- let li = document.createElement('li');
161
- li.className = 'leading-loose';
162
- li.innerHTML = el;
163
- ul.appendChild(li);
164
- }
165
- }
166
- bulletList(list) {
167
- this.list(list, 'bullet');
168
- }
169
- numberedList(list) {
170
- this.list(list, 'numbered');
171
- }
172
- startCodeBulletList() {
173
- let ul = document.createElement('ul');
174
- this._listQueued = ul;
175
- }
176
- endCodeBulletList() {
177
- if (this._listQueued === undefined)
178
- return;
179
- console.assert(this._listQueued !== undefined);
180
- this.root.appendChild(this._listQueued);
181
- this._listQueued = undefined;
182
- }
183
- codeListItem(item, target) {
184
- target = target ?? this._listQueued;
185
- let split = item.constructor === Array;
186
- if (split && item[0].constructor === Array) {
187
- this.codeBulletList(item, target);
188
- return;
189
- }
190
- let li = document.createElement('li');
191
- li.className = 'leading-loose';
192
- li.innerHTML = split
193
- ? (item.length == 2
194
- ? this.iCode(item[0]) + ': ' + item[1]
195
- : this.iCode(item[0] + " <span class='desc'>(" + item[1] + ')</span>') + ': ' + item[2])
196
- : this.iCode(item);
197
- target?.appendChild(li);
198
- }
199
- codeBulletList(list, target) {
200
- console.assert(list !== undefined && list.length > 0);
201
- let ul = document.createElement('ul');
202
- for (var el of list) {
203
- this.codeListItem(el, ul);
204
- }
205
- if (target) {
206
- target.appendChild(ul);
207
- }
208
- else {
209
- this.root.appendChild(ul);
210
- }
211
- }
212
- image(src, caption = '', parent) {
213
- let img = document.createElement('img');
214
- img.src = src;
215
- img.alt = caption;
216
- img.className = 'my-1';
217
- parent = parent ?? this.root;
218
- parent.appendChild(img);
219
- }
220
- images(sources, captions = [], width, height) {
221
- const mobile = navigator && /Android|iPhone/i.test(navigator.userAgent);
222
- if (!mobile) {
223
- let div = document.createElement('div');
224
- div.style.width = width ?? 'auto';
225
- div.style.height = height ?? '256px';
226
- div.className = 'flex flex-row justify-center';
227
- for (let i = 0; i < sources.length; ++i) {
228
- this.image(sources[i], captions[i], div);
229
- }
230
- this.root.appendChild(div);
231
- }
232
- else {
233
- for (let i = 0; i < sources.length; ++i) {
234
- this.image(sources[i], captions[i]);
235
- }
236
- }
237
- }
238
- video(src, caption = '', controls = true, autoplay = false) {
239
- let video = document.createElement('video');
240
- video.src = src;
241
- video.controls = controls;
242
- video.autoplay = autoplay;
243
- if (autoplay) {
244
- video.muted = true;
245
- }
246
- video.loop = true;
247
- video.alt = caption;
248
- this.root.appendChild(video);
249
- }
250
- note(text, warning = false, title, icon) {
251
- console.assert(text !== undefined);
252
- const note = LX.makeContainer([], 'border-color rounded-xl overflow-hidden text-sm text-secondary-foreground my-6', '', this.root);
253
- let header = document.createElement('div');
254
- header.className = 'flex bg-muted font-semibold px-3 py-2 gap-2 text-secondary-foreground';
255
- header.appendChild(LX.makeIcon(icon ?? (warning ? 'MessageSquareWarning' : 'NotepadText')));
256
- header.innerHTML += title ?? (warning ? 'Important' : 'Note');
257
- note.appendChild(header);
258
- // Node body
259
- LX.makeContainer([], 'leading-6 p-3', text, note);
260
- }
261
- classCtor(name, params, language = 'js') {
262
- let paramsHTML = '';
263
- for (var p of params) {
264
- const str1 = p[0]; // cpp: param js: name
265
- const str2 = p[1]; // cpp: defaultValue js: type
266
- if (language == 'cpp') {
267
- paramsHTML += str1 + (str2 ? " = <span class='desc'>" + str2 + '</span>' : '')
268
- + (params.indexOf(p) != (params.length - 1) ? ', ' : '');
269
- }
270
- else if (language == 'js') {
271
- paramsHTML += str1 + ": <span class='desc'>" + str2 + '</span>'
272
- + (params.indexOf(p) != (params.length - 1) ? ', ' : '');
273
- }
274
- }
275
- let pr = document.createElement('p');
276
- pr.innerHTML = this.iCode("<span class='constructor'>" + name + '(' + paramsHTML + ')' + '</span>');
277
- this.root.appendChild(pr);
278
- }
279
- classMethod(name, desc, params, ret) {
280
- this.startCodeBulletList();
281
- let paramsHTML = '';
282
- for (var p of params) {
283
- const name = p[0];
284
- const type = p[1];
285
- paramsHTML += name + ": <span class='desc'>" + type + '</span>'
286
- + (params.indexOf(p) != (params.length - 1) ? ', ' : '');
287
- }
288
- let li = document.createElement('li');
289
- li.innerHTML = this.iCode("<span class='method'>" + name + ' (' + paramsHTML + ')' + (ret ? (': ' + ret) : '') + '</span>');
290
- this._listQueued?.appendChild(li);
291
- this.endCodeBulletList();
292
- this.paragraph(desc);
293
- return li.parentElement;
294
- }
295
- iLink(text, href) {
296
- console.assert(text !== undefined && href !== undefined);
297
- return `<a class="font-semibold underline-offset-4 hover:underline" href="${href}">${text}</a>`;
298
- }
299
- iPage(text, page) {
300
- console.assert(text !== undefined && page !== undefined);
301
- const startPage = page.replace('.html', '');
302
- const g = globalThis;
303
- if (g.setPath && g.loadPage) {
304
- const tabName = g.setPath(startPage);
305
- return `<a onclick="loadPage('${page}', true, '${tabName}')">${text}</a>`;
306
- }
307
- else {
308
- console.warn('[DocMaker] Create globalThis.setPath and globalThis.loadPage to use inline pages!');
309
- }
310
- }
311
- iCode(text, codeClass) {
312
- console.assert(text !== undefined);
313
- return `<code class="inline ${codeClass ?? ''}">${text}</code>`;
314
- }
315
- _copySnippet(b) {
316
- b.innerHTML = '';
317
- b.appendChild(LX.makeIcon('Check'));
318
- b.classList.add('copied');
319
- setTimeout(() => {
320
- b.innerHTML = '';
321
- b.appendChild(LX.makeIcon('Copy'));
322
- b.classList.remove('copied');
323
- }, 2000);
324
- navigator.clipboard.writeText(b.dataset['snippet'] ?? b.parentElement.innerText);
325
- console.log('Copied!');
326
- }
327
- }
328
- LX.DocMaker = DocMaker;
329
-
330
- export { DocMaker };
331
- //# sourceMappingURL=DocMaker.js.map
1
+ // This is a generated file. Do not edit.
2
+ import { LX } from '../core/Namespace.js';
3
+
4
+ // DocMaker.ts @jxarco
5
+ if (!LX) {
6
+ throw ('Missing LX namespace!');
7
+ }
8
+ LX.extensions.push('DocMaker');
9
+ const CPP_KEY_WORDS = ['int', 'float', 'double', 'bool', 'char', 'wchar_t', 'const', 'static_cast', 'dynamic_cast', 'new', 'delete', 'void', 'true',
10
+ 'false', 'auto', 'struct', 'typedef', 'nullptr', 'NULL', 'unsigned', 'namespace', 'auto'];
11
+ const CLASS_WORDS = ['uint32_t', 'uint64_t', 'uint8_t'];
12
+ const STATEMENT_WORDS = ['for', 'if', 'else', 'return', 'continue', 'break', 'case', 'switch', 'while', 'import', 'from', 'await'];
13
+ const JS_KEY_WORDS = ['var', 'let', 'const', 'static', 'function', 'null', 'undefined', 'new', 'delete', 'true', 'false', 'NaN', 'this'];
14
+ const HTML_ATTRIBUTES = ['html', 'charset', 'rel', 'src', 'href', 'crossorigin', 'type', 'lang'];
15
+ const HTML_TAGS = ['DOCTYPE', 'html', 'head', 'body', 'title', 'base', 'link', 'meta', 'style', 'main', 'section', 'nav', 'article', 'aside',
16
+ 'header', 'footer', 'address', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'hr', 'pre', 'blockquote', 'ol', 'ul', 'li', 'dl', 'dt', 'dd', 'figure',
17
+ 'figcaption', 'div', 'a', 'abbr', 'b', 'bdi', 'bdo', 'br', 'cite', 'code', 'data', 'dfn', 'em', 'i', 'kbd', 'mark', 'q', 'rp', 'rt', 'ruby', 's',
18
+ 'samp', 'small', 'span', 'strong', 'sub', 'sup', 'time', 'u', 'var', 'wbr', 'img', 'audio', 'video', 'source', 'track', 'picture', 'map', 'area',
19
+ 'canvas', 'iframe', 'embed', 'object', 'param', 'form', 'label', 'input', 'button', 'select', 'datalist', 'optgroup', 'option', 'textarea',
20
+ 'output', 'progress', 'meter', 'fieldset', 'legend', 'table', 'caption', 'colgroup', 'col', 'tbody', 'thead', 'tfoot', 'tr', 'td', 'th',
21
+ 'details', 'summary', 'dialog', 'script', 'noscript', 'template'];
22
+ class DocMaker {
23
+ root;
24
+ _listQueued = undefined;
25
+ _lastDomTarget = undefined;
26
+ constructor(element) {
27
+ this.root = element ?? document.body;
28
+ }
29
+ setDomTarget(element) {
30
+ this.root = element;
31
+ }
32
+ lineBreak(target) {
33
+ target = target ?? this.root;
34
+ target.appendChild(document.createElement('br'));
35
+ }
36
+ header(string, type, id, options = {}) {
37
+ console.assert(string !== undefined && type !== undefined);
38
+ if (options.collapsable) {
39
+ const collapsible = LX.makeElement('div', LX.mergeClass('my-4 px-6 cursor-pointer', options.className), `<${type} id="${id ?? ''}">${string}</${type}>`, this.root);
40
+ const collapsibleContent = LX.makeContainer(['100%', 'auto'], 'px-4', '', this.root);
41
+ LX.listen(collapsible, "click", () => collapsible.querySelector('a.collapser').click());
42
+ this._lastDomTarget = this.root;
43
+ this.setDomTarget(collapsibleContent);
44
+ if (options.collapsableContentCallback) {
45
+ options.collapsableContentCallback();
46
+ }
47
+ LX.makeCollapsible(collapsible, collapsibleContent, null, { collapsed: options.collapsed ?? false });
48
+ this.setDomTarget(this._lastDomTarget);
49
+ delete this._lastDomTarget;
50
+ return collapsible;
51
+ }
52
+ const header = document.createElement(type);
53
+ header.className = options.className ?? '';
54
+ header.innerHTML = string;
55
+ if (id)
56
+ header.id = id;
57
+ this.root.appendChild(header);
58
+ return header;
59
+ }
60
+ paragraph(string, sup = false, className = '') {
61
+ console.assert(string !== undefined);
62
+ let paragraph = document.createElement(sup ? 'sup' : 'p');
63
+ paragraph.className = LX.mergeClass('leading-relaxed', className);
64
+ paragraph.innerHTML = string;
65
+ this.root.appendChild(paragraph);
66
+ return paragraph;
67
+ }
68
+ code(text, language = 'js') {
69
+ console.assert(text !== undefined);
70
+ text.replaceAll('<', '&lt;');
71
+ text.replaceAll('>', '&gt;');
72
+ let highlight = '';
73
+ let content = '';
74
+ const getHTML = (h, c) => {
75
+ return `<span class="${h}">${c}</span>`;
76
+ };
77
+ for (let i = 0; i < text.length; ++i) {
78
+ const char = text[i];
79
+ const string = text.substring(i);
80
+ const endLineIdx = string.indexOf('\n');
81
+ const line = string.substring(0, endLineIdx > -1 ? endLineIdx : undefined);
82
+ if (char == '@') {
83
+ const str = line.substring(1);
84
+ if (!(str.indexOf('@') > -1) && !(str.indexOf('[') > -1)) {
85
+ continue;
86
+ }
87
+ let html = null;
88
+ const tagIndex = str.indexOf('@');
89
+ const skipTag = str[tagIndex - 1] == '|';
90
+ // Highlight is specified
91
+ if (text[i + 1] == '[') {
92
+ highlight = str.substring(1, 4);
93
+ content = str.substring(5, tagIndex);
94
+ if (skipTag) {
95
+ const newString = str.substring(6 + content.length);
96
+ const preContent = content;
97
+ const postContent = newString.substring(0, newString.indexOf('@'));
98
+ const finalContent = preContent.substring(0, preContent.length - 1) + '@' + postContent;
99
+ html = getHTML(highlight, finalContent);
100
+ const ogContent = preContent + '@' + postContent;
101
+ text = text.replace(`@[${highlight}]${ogContent}@`, html);
102
+ }
103
+ else {
104
+ html = getHTML(highlight, content);
105
+ text = text.replace(`@[${highlight}]${content}@`, html);
106
+ }
107
+ }
108
+ else {
109
+ content = str.substring(0, tagIndex);
110
+ if (skipTag) {
111
+ const preContent = str.substring(0, str.indexOf('@') - 1);
112
+ content = str.substring(preContent.length + 1);
113
+ content = preContent + content.substring(0, content.substring(1).indexOf('@') + 1);
114
+ text = text.substr(0, i) + '@' + content + '@' + text.substr(i + content.length + 3);
115
+ }
116
+ if (language == 'cpp' && CPP_KEY_WORDS.includes(content)) {
117
+ highlight = 'kwd';
118
+ }
119
+ else if (language == 'js' && JS_KEY_WORDS.includes(content)) {
120
+ highlight = 'kwd';
121
+ }
122
+ else if (CLASS_WORDS.includes(content)) {
123
+ highlight = 'cls';
124
+ }
125
+ else if (STATEMENT_WORDS.includes(content)) {
126
+ highlight = 'lit';
127
+ }
128
+ else if (HTML_TAGS.includes(content)) {
129
+ highlight = 'tag';
130
+ }
131
+ else if (HTML_ATTRIBUTES.includes(content)) {
132
+ highlight = 'atn';
133
+ }
134
+ else if ((content[0] == '"' && content[content.length - 1] == '"')
135
+ || (content[0] == "'" && content[content.length - 1] == "'")
136
+ || (content[0] == '`' && content[content.length - 1] == '`')) {
137
+ highlight = 'str';
138
+ }
139
+ else if (!Number.isNaN(parseFloat(content))) {
140
+ highlight = 'dec';
141
+ }
142
+ else {
143
+ console.error('ERROR[Code Parsing]: Unknown highlight type: ' + content);
144
+ return;
145
+ }
146
+ html = getHTML(highlight, content);
147
+ text = text.replace(`@${content}@`, html);
148
+ }
149
+ i += html.length - 1;
150
+ }
151
+ }
152
+ let container = document.createElement('div');
153
+ container.className = 'code-container';
154
+ let pre = document.createElement('pre');
155
+ let code = document.createElement('code');
156
+ code.innerHTML = text;
157
+ let button = document.createElement('button');
158
+ button.title = 'Copy code sample';
159
+ button.appendChild(LX.makeIcon('Copy'));
160
+ button.addEventListener('click', this._copySnippet.bind(this, button));
161
+ container.appendChild(button);
162
+ pre.appendChild(code);
163
+ container.appendChild(pre);
164
+ this.root.appendChild(container);
165
+ return container;
166
+ }
167
+ list(list, type, target, className = '') {
168
+ const validTypes = ['bullet', 'numbered'];
169
+ console.assert(list && list.length > 0 && validTypes.includes(type), 'Invalid list type or empty list' + type);
170
+ const typeString = type == 'bullet' ? 'ul' : 'ol';
171
+ let ul = document.createElement(typeString);
172
+ ul.className = className;
173
+ target = target ?? this.root;
174
+ target.appendChild(ul);
175
+ for (var el of list) {
176
+ if (el.constructor === Array) {
177
+ this.list(el, type, ul);
178
+ return;
179
+ }
180
+ let li = document.createElement('li');
181
+ li.className = 'leading-loose';
182
+ li.innerHTML = el;
183
+ ul.appendChild(li);
184
+ }
185
+ return ul;
186
+ }
187
+ bulletList(list) {
188
+ return this.list(list, 'bullet');
189
+ }
190
+ numberedList(list) {
191
+ return this.list(list, 'numbered');
192
+ }
193
+ startCodeBulletList() {
194
+ let ul = document.createElement('ul');
195
+ this._listQueued = ul;
196
+ return ul;
197
+ }
198
+ endCodeBulletList() {
199
+ if (this._listQueued === undefined)
200
+ return;
201
+ console.assert(this._listQueued !== undefined);
202
+ this.root.appendChild(this._listQueued);
203
+ this._listQueued = undefined;
204
+ }
205
+ codeListItem(item, target) {
206
+ target = target ?? this._listQueued;
207
+ let split = item.constructor === Array;
208
+ if (split && item[0].constructor === Array) {
209
+ this.codeBulletList(item, target);
210
+ return;
211
+ }
212
+ let li = document.createElement('li');
213
+ li.className = 'leading-loose';
214
+ li.innerHTML = split
215
+ ? (item.length == 2
216
+ ? this.iCode(item[0]) + ': ' + item[1]
217
+ : this.iCode(item[0] + " <span class='desc'>(" + item[1] + ')</span>') + ': ' + item[2])
218
+ : this.iCode(item);
219
+ target?.appendChild(li);
220
+ }
221
+ codeBulletList(list, target) {
222
+ console.assert(list !== undefined && list.length > 0);
223
+ let ul = document.createElement('ul');
224
+ for (var el of list) {
225
+ this.codeListItem(el, ul);
226
+ }
227
+ if (target) {
228
+ target.appendChild(ul);
229
+ }
230
+ else {
231
+ this.root.appendChild(ul);
232
+ }
233
+ return ul;
234
+ }
235
+ image(src, caption = '', parent, className = '') {
236
+ let img = document.createElement('img');
237
+ img.src = src;
238
+ img.alt = caption;
239
+ img.className = LX.mergeClass('my-1', className);
240
+ parent = parent ?? this.root;
241
+ parent.appendChild(img);
242
+ return img;
243
+ }
244
+ images(sources, captions = [], width, height) {
245
+ const mobile = navigator && /Android|iPhone/i.test(navigator.userAgent);
246
+ const div = document.createElement('div');
247
+ if (!mobile) {
248
+ div.style.width = width ?? 'auto';
249
+ div.style.height = height ?? '256px';
250
+ div.className = 'flex flex-row justify-center';
251
+ }
252
+ for (let i = 0; i < sources.length; ++i) {
253
+ this.image(sources[i], captions[i], div);
254
+ }
255
+ this.root.appendChild(div);
256
+ return div;
257
+ }
258
+ video(src, caption = '', controls = true, autoplay = false, className = '') {
259
+ let video = document.createElement('video');
260
+ video.className = className;
261
+ video.src = src;
262
+ video.controls = controls;
263
+ video.autoplay = autoplay;
264
+ if (autoplay) {
265
+ video.muted = true;
266
+ }
267
+ video.loop = true;
268
+ video.alt = caption;
269
+ this.root.appendChild(video);
270
+ return video;
271
+ }
272
+ note(text, warning = false, title, icon, className = '') {
273
+ console.assert(text !== undefined);
274
+ const note = LX.makeContainer([], LX.mergeClass('border-color rounded-xl overflow-hidden text-sm text-secondary-foreground my-6', className), '', this.root);
275
+ const header = document.createElement('div');
276
+ header.className = 'flex bg-muted font-semibold px-3 py-2 gap-2 text-secondary-foreground';
277
+ header.appendChild(LX.makeIcon(icon ?? (warning ? 'MessageSquareWarning' : 'NotepadText')));
278
+ header.innerHTML += title ?? (warning ? 'Important' : 'Note');
279
+ note.appendChild(header);
280
+ // Node body
281
+ return LX.makeContainer([], 'leading-6 p-3', text, note);
282
+ }
283
+ classCtor(name, params, language = 'js') {
284
+ let paramsHTML = '';
285
+ for (var p of params) {
286
+ const str1 = p[0]; // cpp: param js: name
287
+ const str2 = p[1]; // cpp: defaultValue js: type
288
+ if (language == 'cpp') {
289
+ paramsHTML += str1 + (str2 ? " = <span class='desc'>" + str2 + '</span>' : '')
290
+ + (params.indexOf(p) != (params.length - 1) ? ', ' : '');
291
+ }
292
+ else if (language == 'js') {
293
+ paramsHTML += str1 + ": <span class='desc'>" + str2 + '</span>'
294
+ + (params.indexOf(p) != (params.length - 1) ? ', ' : '');
295
+ }
296
+ }
297
+ let pr = document.createElement('p');
298
+ pr.innerHTML = this.iCode("<span class='constructor'>" + name + '(' + paramsHTML + ')' + '</span>');
299
+ this.root.appendChild(pr);
300
+ return pr;
301
+ }
302
+ classMethod(name, desc, params, ret) {
303
+ this.startCodeBulletList();
304
+ let paramsHTML = '';
305
+ for (var p of params) {
306
+ const name = p[0];
307
+ const type = p[1];
308
+ paramsHTML += name + ": <span class='desc'>" + type + '</span>'
309
+ + (params.indexOf(p) != (params.length - 1) ? ', ' : '');
310
+ }
311
+ let li = document.createElement('li');
312
+ li.innerHTML = this.iCode("<span class='method'>" + name + ' (' + paramsHTML + ')' + (ret ? (': ' + ret) : '') + '</span>');
313
+ this._listQueued?.appendChild(li);
314
+ this.endCodeBulletList();
315
+ this.paragraph(desc);
316
+ return li.parentElement;
317
+ }
318
+ iLink(text, href) {
319
+ console.assert(text !== undefined && href !== undefined);
320
+ return `<a class="font-semibold underline-offset-4 hover:underline" href="${href}">${text}</a>`;
321
+ }
322
+ iPage(text, page) {
323
+ console.assert(text !== undefined && page !== undefined);
324
+ const startPage = page.replace('.html', '');
325
+ const g = globalThis;
326
+ if (g.setPath && g.loadPage) {
327
+ const tabName = g.setPath(startPage);
328
+ return `<a onclick="loadPage('${page}', true, '${tabName}')">${text}</a>`;
329
+ }
330
+ else {
331
+ console.warn('[DocMaker] Create globalThis.setPath and globalThis.loadPage to use inline pages!');
332
+ }
333
+ }
334
+ iCode(text, codeClass) {
335
+ console.assert(text !== undefined);
336
+ return `<code class="inline ${codeClass ?? ''}">${text}</code>`;
337
+ }
338
+ _copySnippet(b) {
339
+ b.innerHTML = '';
340
+ b.appendChild(LX.makeIcon('Check'));
341
+ b.classList.add('copied');
342
+ setTimeout(() => {
343
+ b.innerHTML = '';
344
+ b.appendChild(LX.makeIcon('Copy'));
345
+ b.classList.remove('copied');
346
+ }, 2000);
347
+ navigator.clipboard.writeText(b.dataset['snippet'] ?? b.parentElement.innerText);
348
+ console.log('Copied!');
349
+ }
350
+ }
351
+ LX.DocMaker = DocMaker;
352
+
353
+ export { DocMaker };
354
+ //# sourceMappingURL=DocMaker.js.map