elegance-js 2.1.23 → 2.1.26

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.
Files changed (103) hide show
  1. package/dist/client/effect.d.ts +27 -0
  2. package/dist/client/effect.js +37 -0
  3. package/dist/client/eventListener.d.ts +39 -0
  4. package/dist/client/eventListener.js +52 -0
  5. package/dist/client/loadHook.d.ts +34 -0
  6. package/dist/client/loadHook.js +52 -0
  7. package/dist/client/observer.d.ts +36 -0
  8. package/dist/client/observer.js +66 -0
  9. package/dist/client/runtime.d.ts +105 -0
  10. package/dist/client/runtime.js +620 -0
  11. package/dist/client/state.d.ts +40 -0
  12. package/dist/client/state.js +110 -0
  13. package/dist/compilation/compiler.d.ts +155 -0
  14. package/dist/compilation/compiler.js +1153 -0
  15. package/dist/components/ClientComponent.d.ts +22 -0
  16. package/dist/components/ClientComponent.js +55 -0
  17. package/dist/components/Link.d.ts +16 -1
  18. package/dist/components/Link.js +22 -0
  19. package/dist/components/Portal.d.ts +2 -0
  20. package/dist/components/Portal.js +2 -0
  21. package/dist/elements/element.d.ts +87 -0
  22. package/dist/elements/element.js +33 -0
  23. package/dist/elements/element_list.d.ts +7 -0
  24. package/dist/elements/element_list.js +65 -0
  25. package/dist/elements/raw.d.ts +14 -0
  26. package/dist/elements/raw.js +78 -0
  27. package/dist/elements/specific_props.d.ts +750 -0
  28. package/dist/global.d.ts +221 -327
  29. package/dist/index.d.ts +15 -3
  30. package/dist/index.js +11 -0
  31. package/dist/server/layout.d.ts +34 -3
  32. package/dist/server/layout.js +6 -0
  33. package/dist/server/log.d.ts +12 -0
  34. package/dist/server/log.js +64 -0
  35. package/dist/server/page.d.ts +32 -0
  36. package/dist/server/page.js +6 -0
  37. package/dist/server/runtime.d.ts +6 -0
  38. package/dist/server/runtime.js +72 -0
  39. package/dist/server/server.d.ts +103 -11
  40. package/dist/server/server.js +709 -0
  41. package/package.json +13 -13
  42. package/scripts/bootstrap.js +37 -273
  43. package/scripts/bootstrap_files/elegance.txt +40 -0
  44. package/scripts/bootstrap_files/index.txt +3 -0
  45. package/scripts/bootstrap_files/layout.txt +46 -0
  46. package/scripts/bootstrap_files/middleware.txt +18 -0
  47. package/scripts/bootstrap_files/page.txt +123 -0
  48. package/scripts/bootstrap_files/route.txt +6 -0
  49. package/scripts/elegance_dev.ts +40 -0
  50. package/scripts/elegance_prod.ts +40 -0
  51. package/scripts/elegance_static.ts +24 -0
  52. package/scripts/prod.js +9 -26
  53. package/scripts/run.js +13 -0
  54. package/scripts/static.js +13 -0
  55. package/dist/build.d.ts +0 -2
  56. package/dist/build.mjs +0 -202
  57. package/dist/client/client.d.ts +0 -1
  58. package/dist/client/client.mjs +0 -574
  59. package/dist/client/processPageElements.d.ts +0 -1
  60. package/dist/client/processPageElements.mjs +0 -117
  61. package/dist/client/render.d.ts +0 -1
  62. package/dist/client/render.mjs +0 -40
  63. package/dist/client/watcher.d.ts +0 -1
  64. package/dist/client/watcher.mjs +0 -26
  65. package/dist/compilation/compilation.d.ts +0 -139
  66. package/dist/compilation/compilation.mjs +0 -751
  67. package/dist/compilation/compiler_process.d.ts +0 -3
  68. package/dist/compilation/compiler_process.mjs +0 -102
  69. package/dist/compilation/dynamic_compiler.d.ts +0 -10
  70. package/dist/compilation/dynamic_compiler.mjs +0 -93
  71. package/dist/compile_docs.mjs +0 -34
  72. package/dist/components/Link.mjs +0 -65
  73. package/dist/global.mjs +0 -0
  74. package/dist/helpers/ObjectAttributeType.d.ts +0 -7
  75. package/dist/helpers/ObjectAttributeType.mjs +0 -11
  76. package/dist/helpers/camelToKebab.d.ts +0 -1
  77. package/dist/helpers/camelToKebab.mjs +0 -6
  78. package/dist/index.mjs +0 -3
  79. package/dist/internal/deprecate.d.ts +0 -1
  80. package/dist/internal/deprecate.mjs +0 -7
  81. package/dist/log.d.ts +0 -10
  82. package/dist/log.mjs +0 -38
  83. package/dist/server/generateHTMLTemplate.d.ts +0 -12
  84. package/dist/server/generateHTMLTemplate.mjs +0 -41
  85. package/dist/server/layout.mjs +0 -19
  86. package/dist/server/loadHook.d.ts +0 -30
  87. package/dist/server/loadHook.mjs +0 -50
  88. package/dist/server/observe.d.ts +0 -19
  89. package/dist/server/observe.mjs +0 -16
  90. package/dist/server/render.d.ts +0 -5
  91. package/dist/server/render.mjs +0 -61
  92. package/dist/server/server.mjs +0 -429
  93. package/dist/server/state.d.ts +0 -61
  94. package/dist/server/state.mjs +0 -146
  95. package/dist/shared/bindServerElements.mjs +0 -3
  96. package/dist/shared/serverElements.d.ts +0 -11
  97. package/dist/shared/serverElements.mjs +0 -164
  98. package/scripts/dev.js +0 -33
  99. package/scripts/export.js +0 -20
  100. package/scripts/ts-arc-dev.js +0 -9
  101. package/scripts/ts-arc-prod.js +0 -9
  102. /package/dist/{compile_docs.d.ts → elements/specific_props.js} +0 -0
  103. /package/dist/{shared/bindServerElements.d.ts → global.js} +0 -0
@@ -1,574 +0,0 @@
1
- "use strict";
2
- (() => {
3
- // src/shared/serverElements.ts
4
- var createBuildableElement = (tag) => {
5
- return (options, ...children) => ({
6
- tag,
7
- options: options || {},
8
- children
9
- });
10
- };
11
- var createChildrenlessBuildableElement = (tag) => {
12
- return (options) => ({
13
- tag,
14
- options: options || {},
15
- children: null
16
- });
17
- };
18
- var childrenlessElementTags = [
19
- "area",
20
- "base",
21
- "br",
22
- "col",
23
- "embed",
24
- "hr",
25
- "img",
26
- "input",
27
- "link",
28
- "meta",
29
- "source",
30
- "track",
31
- "path",
32
- "rect"
33
- ];
34
- var elementTags = [
35
- "a",
36
- "address",
37
- "article",
38
- "aside",
39
- "audio",
40
- "blockquote",
41
- "body",
42
- "button",
43
- "canvas",
44
- "caption",
45
- "colgroup",
46
- "data",
47
- "datalist",
48
- "dd",
49
- "del",
50
- "details",
51
- "dialog",
52
- "div",
53
- "dl",
54
- "dt",
55
- "fieldset",
56
- "figcaption",
57
- "figure",
58
- "footer",
59
- "form",
60
- "h1",
61
- "h2",
62
- "h3",
63
- "h4",
64
- "h5",
65
- "h6",
66
- "head",
67
- "header",
68
- "hgroup",
69
- "html",
70
- "iframe",
71
- "ins",
72
- "label",
73
- "legend",
74
- "li",
75
- "main",
76
- "map",
77
- "meter",
78
- "nav",
79
- "noscript",
80
- "object",
81
- "ol",
82
- "optgroup",
83
- "option",
84
- "output",
85
- "p",
86
- "picture",
87
- "pre",
88
- "progress",
89
- "q",
90
- "section",
91
- "select",
92
- "summary",
93
- "table",
94
- "tbody",
95
- "td",
96
- "template",
97
- "textarea",
98
- "tfoot",
99
- "th",
100
- "thead",
101
- "time",
102
- "tr",
103
- "ul",
104
- "video",
105
- "span",
106
- "script",
107
- "abbr",
108
- "b",
109
- "bdi",
110
- "bdo",
111
- "cite",
112
- "code",
113
- "dfn",
114
- "em",
115
- "i",
116
- "kbd",
117
- "mark",
118
- "rp",
119
- "rt",
120
- "ruby",
121
- "s",
122
- "samp",
123
- "small",
124
- "strong",
125
- "sub",
126
- "sup",
127
- "u",
128
- "wbr",
129
- "title",
130
- "svg"
131
- ];
132
- var elements = {};
133
- var childrenlessElements = {};
134
- for (const element of elementTags) {
135
- elements[element] = createBuildableElement(element);
136
- }
137
- for (const element of childrenlessElementTags) {
138
- childrenlessElements[element] = createChildrenlessBuildableElement(element);
139
- }
140
- var allElements = {
141
- ...elements,
142
- ...childrenlessElements
143
- };
144
-
145
- // src/shared/bindServerElements.ts
146
- Object.assign(globalThis, elements);
147
- Object.assign(globalThis, childrenlessElements);
148
-
149
- // src/client/client.ts
150
- console.log("Elegance.JS is loading..");
151
- var pd = {};
152
- var ld = {};
153
- Object.assign(window, {
154
- observe: (subjects, updateCallback) => {
155
- return {
156
- subjects,
157
- updateCallback,
158
- isAttribute: true,
159
- type: 2 /* OBSERVER */
160
- };
161
- },
162
- eventListener: (subjects, eventListener) => {
163
- return {
164
- subjects,
165
- eventListener,
166
- isAttribute: true,
167
- type: 1 /* STATE */
168
- };
169
- }
170
- });
171
- var domParser = new DOMParser();
172
- var xmlSerializer = new XMLSerializer();
173
- var pageStringCache = /* @__PURE__ */ new Map();
174
- var loc = window.location;
175
- var doc = document;
176
- var cleanupProcedures = [];
177
- var sanitizePathname = (pn) => {
178
- if (!pn.endsWith("/") || pn === "/") return pn;
179
- return pn.slice(0, -1);
180
- };
181
- var currentPage = sanitizePathname(loc.pathname);
182
- var createStateManager = (subjects, bindLevel) => {
183
- const state = {
184
- subjects: subjects.map((subject) => {
185
- const s = {
186
- ...subject,
187
- observers: /* @__PURE__ */ new Map()
188
- };
189
- s.signal = () => {
190
- for (const observer of s.observers.values()) {
191
- try {
192
- observer(s.value);
193
- } catch (e) {
194
- console.error(e);
195
- continue;
196
- }
197
- }
198
- };
199
- return s;
200
- }),
201
- destroy: (s) => {
202
- state.subjects.splice(state.subjects.indexOf(s), 1);
203
- },
204
- get: (id) => {
205
- const subject = state.subjects.find((s) => s.id === id);
206
- if (subject) return subject;
207
- if (bindLevel === 2 /* SCOPED */) return void 0;
208
- const parts = window.location.pathname.split("/").filter(Boolean);
209
- const paths = [
210
- ...parts.map((_, i) => "/" + parts.slice(0, i + 1).join("/")),
211
- "/"
212
- ].reverse();
213
- for (const item of paths) {
214
- const sanitized = sanitizePathname(item);
215
- const data = ld[sanitized];
216
- if (!data) continue;
217
- const entry = data.stateManager.get(id);
218
- if (entry) return entry;
219
- }
220
- return void 0;
221
- },
222
- /**
223
- Bind is deprecated, but kept as a paramater to not upset legacy code.
224
- */
225
- getAll: (refs) => refs?.map((ref) => {
226
- return state.get(ref.id);
227
- }),
228
- observe: (subject, observer, key) => {
229
- subject.observers.delete(key);
230
- subject.observers.set(key, observer);
231
- },
232
- unobserve: (subject, key) => {
233
- subject.observers.delete(key);
234
- }
235
- };
236
- return state;
237
- };
238
- var initPageData = (data, currentPage2, previousPage, bindLevel) => {
239
- if (!data) {
240
- console.error("Data for page " + currentPage2 + " is null.");
241
- return;
242
- }
243
- let state = data?.stateManager;
244
- if (!state) {
245
- state = createStateManager(data.state || [], bindLevel);
246
- data.stateManager = state;
247
- }
248
- for (const subject of state.subjects) {
249
- if (!subject.observers) subject.observers = /* @__PURE__ */ new Map();
250
- }
251
- for (const ooa of data.ooa || []) {
252
- const els = doc.querySelectorAll(`[key="${ooa.key}"]`);
253
- let values = {};
254
- for (const { id } of ooa.refs) {
255
- const subject = state.get(id);
256
- values[subject.id] = subject.value;
257
- const updateFunction = (value) => {
258
- values[id] = value;
259
- try {
260
- const newValue = ooa.update(...Object.values(values));
261
- let attribute = ooa.attribute === "class" ? "className" : ooa.attribute;
262
- for (const el of Array.from(els)) {
263
- el[attribute] = newValue;
264
- }
265
- } catch (e) {
266
- console.error(e);
267
- return;
268
- }
269
- };
270
- updateFunction(subject.value);
271
- try {
272
- state.observe(subject, updateFunction, ooa.key);
273
- } catch (e) {
274
- console.error(e);
275
- return;
276
- }
277
- }
278
- }
279
- for (const soa of data.soa || []) {
280
- const el = doc.querySelector(`[key="${soa.key}"]`);
281
- if (!el) {
282
- console.error("Could not find SOA element for SOA:", soa);
283
- continue;
284
- }
285
- const subject = state.get(soa.id);
286
- if (typeof subject.value === "function") {
287
- try {
288
- el[soa.attribute] = (event) => subject.value(state, event);
289
- } catch (e) {
290
- console.error(e);
291
- return;
292
- }
293
- } else {
294
- el[soa.attribute] = subject.value;
295
- }
296
- }
297
- const loadHooks = data.lh;
298
- for (const loadHook of loadHooks || []) {
299
- const wasInScope = previousPage ? previousPage.startsWith(currentPage2) : false;
300
- if (wasInScope && bindLevel !== 1 /* STRICT */) {
301
- continue;
302
- }
303
- const fn = loadHook.fn;
304
- try {
305
- let cleanupFunction;
306
- if (fn.constructor.name === "AsyncFunction") {
307
- const res = fn(state);
308
- res.then((cleanupFunction2) => {
309
- if (cleanupFunction2) {
310
- cleanupProcedures.push({
311
- cleanupFunction: cleanupFunction2,
312
- page: `${currentPage2}`,
313
- loadHook,
314
- bindLevel
315
- });
316
- }
317
- });
318
- } else {
319
- cleanupFunction = fn(state);
320
- if (cleanupFunction) {
321
- cleanupProcedures.push({
322
- cleanupFunction,
323
- page: `${currentPage2}`,
324
- loadHook,
325
- bindLevel
326
- });
327
- }
328
- }
329
- } catch (e) {
330
- console.error(e);
331
- return;
332
- }
333
- }
334
- };
335
- var loadPage = async (previousPage = null) => {
336
- const fixedUrl = new URL(loc.href);
337
- fixedUrl.pathname = sanitizePathname(fixedUrl.pathname);
338
- const pathname = fixedUrl.pathname;
339
- currentPage = pathname;
340
- pageStringCache.set(
341
- currentPage,
342
- xmlSerializer.serializeToString(doc)
343
- );
344
- history.replaceState(null, "", fixedUrl.href);
345
- {
346
- const parts = window.location.pathname.split("/").filter(Boolean);
347
- const paths = [
348
- ...parts.map((_, i) => "/" + parts.slice(0, i + 1).join("/")),
349
- "/"
350
- ];
351
- for (const path of paths) {
352
- const layoutDataScript = document.querySelector(`script[data-layout="true"][data-pathname="${path}"]`);
353
- if (!layoutDataScript) {
354
- continue;
355
- }
356
- const { data } = await import(layoutDataScript.src);
357
- if (!ld[pathname]) ld[pathname] = data;
358
- {
359
- const dataScript = document.querySelector(`script[data-hook="true"][data-pathname="${sanitizePathname(pathname)}"]`);
360
- if (dataScript) dataScript.remove();
361
- }
362
- initPageData(ld[pathname], path, previousPage, 2 /* SCOPED */);
363
- }
364
- }
365
- {
366
- const pageDataScript = document.head.querySelector(`script[data-page="true"][data-pathname="${sanitizePathname(pathname)}"]`);
367
- const { data } = await import(pageDataScript.src);
368
- if (!pd[pathname]) pd[pathname] = data;
369
- {
370
- const dataScript = document.querySelector(`script[data-hook="true"][data-pathname="${sanitizePathname(pathname)}"]`);
371
- if (dataScript) dataScript.remove();
372
- }
373
- initPageData(pd[pathname], currentPage, previousPage, 1 /* STRICT */);
374
- }
375
- console.info(
376
- `Loading finished, cleanupProcedures are currently:`,
377
- cleanupProcedures
378
- );
379
- };
380
- var fetchPage = async (targetURL) => {
381
- const pathname = sanitizePathname(targetURL.pathname);
382
- if (pageStringCache.has(pathname)) {
383
- return domParser.parseFromString(pageStringCache.get(pathname), "text/html");
384
- }
385
- const res = await fetch(targetURL);
386
- const newDOM = domParser.parseFromString(await res.text(), "text/html");
387
- {
388
- const dataScripts = Array.from(newDOM.querySelectorAll('script[data-module="true"]'));
389
- const currentScripts = Array.from(document.head.querySelectorAll('script[data-module="true"]'));
390
- for (const dataScript of dataScripts) {
391
- const existing = currentScripts.find((s) => s.src === dataScript.src);
392
- if (existing) {
393
- continue;
394
- }
395
- document.head.appendChild(dataScript);
396
- }
397
- }
398
- {
399
- const pageDataScript = newDOM.querySelector('script[data-page="true"]');
400
- if (!pageDataScript) {
401
- return;
402
- }
403
- if (!pd[pathname]) {
404
- await import(pageDataScript.src);
405
- }
406
- }
407
- {
408
- const layoutDataScripts = Array.from(newDOM.querySelectorAll('script[data-layout="true"]'));
409
- for (const script of layoutDataScripts) {
410
- const url = new URL(script.src, window.location.origin);
411
- const dir = url.pathname.substring(0, url.pathname.lastIndexOf("/")) || "/";
412
- const pathname2 = sanitizePathname(dir);
413
- if (!ld[pathname2]) {
414
- await import(script.src);
415
- }
416
- }
417
- }
418
- pageStringCache.set(pathname, xmlSerializer.serializeToString(newDOM));
419
- return newDOM;
420
- };
421
- var navigateLocally = async (target, pushState = true) => {
422
- const targetURL = new URL(target);
423
- const pathname = sanitizePathname(targetURL.pathname);
424
- console.log(
425
- `%c${currentPage} -> ${targetURL.pathname}`,
426
- "font-size: 18px; font-weight: 600; color: lightgreen;"
427
- );
428
- let newPage = await fetchPage(targetURL);
429
- if (!newPage) return;
430
- if (pathname === currentPage) return;
431
- for (const cleanupProcedure of [...cleanupProcedures]) {
432
- const isInScope = pathname.startsWith(cleanupProcedure.page);
433
- if (!isInScope || cleanupProcedure.bindLevel === 1 /* STRICT */) {
434
- try {
435
- cleanupProcedure.cleanupFunction();
436
- } catch (e) {
437
- console.error(e);
438
- return;
439
- }
440
- cleanupProcedures.splice(cleanupProcedures.indexOf(cleanupProcedure), 1);
441
- }
442
- }
443
- let oldPageLatest = doc.body;
444
- let newPageLatest = newPage.body;
445
- {
446
- const newPageLayouts = Array.from(newPage.querySelectorAll("template[layout-id]"));
447
- const oldPageLayouts = Array.from(doc.querySelectorAll("template[layout-id]"));
448
- const size = Math.min(newPageLayouts.length, oldPageLayouts.length);
449
- for (let i = 0; i < size; i++) {
450
- const newPageLayout = newPageLayouts[i];
451
- const oldPageLayout = oldPageLayouts[i];
452
- const newLayoutId = newPageLayout.getAttribute("layout-id");
453
- const oldLayoutId = oldPageLayout.getAttribute("layout-id");
454
- if (newLayoutId !== oldLayoutId) {
455
- break;
456
- }
457
- oldPageLatest = oldPageLayout.nextElementSibling;
458
- newPageLatest = newPageLayout.nextElementSibling;
459
- }
460
- }
461
- oldPageLatest.replaceWith(newPageLatest);
462
- {
463
- doc.head.querySelector("title")?.replaceWith(
464
- newPage.head.querySelector("title") ?? ""
465
- );
466
- const update = (targetList, matchAgainst, action) => {
467
- for (const target2 of targetList) {
468
- const matching = matchAgainst.find((n) => n.isEqualNode(target2));
469
- if (matching) {
470
- continue;
471
- }
472
- action(target2);
473
- }
474
- };
475
- const oldTags = Array.from([
476
- ...Array.from(document.head.querySelectorAll("link")),
477
- ...Array.from(document.head.querySelectorAll("meta")),
478
- ...Array.from(document.head.querySelectorAll("script")),
479
- ...Array.from(document.head.querySelectorAll("base")),
480
- ...Array.from(document.head.querySelectorAll("style"))
481
- ]);
482
- const newTags = Array.from([
483
- ...Array.from(newPage.head.querySelectorAll("link")),
484
- ...Array.from(newPage.head.querySelectorAll("meta")),
485
- ...Array.from(newPage.head.querySelectorAll("script")),
486
- ...Array.from(newPage.head.querySelectorAll("base")),
487
- ...Array.from(newPage.head.querySelectorAll("style"))
488
- ]);
489
- update(newTags, oldTags, (node) => document.head.appendChild(node));
490
- update(oldTags, newTags, (node) => node.remove());
491
- }
492
- if (pushState) history.pushState(null, "", targetURL.href);
493
- await loadPage(currentPage);
494
- currentPage = pathname;
495
- if (targetURL.hash) {
496
- doc.getElementById(targetURL.hash.slice(1))?.scrollIntoView();
497
- }
498
- };
499
- window.onpopstate = async (event) => {
500
- event.preventDefault();
501
- const target = event.target;
502
- await navigateLocally(target.location.href, false);
503
- history.replaceState(null, "", target.location.href);
504
- };
505
- var renderRecursively = (element, attributes) => {
506
- if (typeof element === "boolean") {
507
- return null;
508
- }
509
- if (typeof element === "number" || typeof element === "string") {
510
- return document.createTextNode(element.toString());
511
- }
512
- if (Array.isArray(element)) {
513
- const fragment = document.createDocumentFragment();
514
- element.forEach((item) => {
515
- const childNode = renderRecursively(item, attributes);
516
- if (childNode) fragment.appendChild(childNode);
517
- });
518
- return fragment;
519
- }
520
- const domElement = document.createElement(element.tag);
521
- if (typeof element.options !== "object" && element.options !== void 0) {
522
- const childNode = renderRecursively(element.options, attributes);
523
- if (childNode) domElement.appendChild(childNode);
524
- } else if (typeof element.options === "object") {
525
- const { tag, options, children } = element.options;
526
- if (tag !== void 0 || options !== void 0 || children !== void 0) {
527
- const childNode = renderRecursively(element.options, attributes);
528
- if (childNode) domElement.appendChild(childNode);
529
- } else {
530
- for (const [attrName, attrValue] of Object.entries(element.options)) {
531
- if (typeof attrValue === "object") {
532
- const { isAttribute } = attrValue;
533
- if (isAttribute === void 0 || isAttribute === false) {
534
- console.error("Objects are not valid option property values.");
535
- throw "";
536
- }
537
- attributes.push({
538
- ...attrValue,
539
- field: attrName,
540
- element: domElement
541
- });
542
- continue;
543
- }
544
- domElement.setAttribute(attrName.toLowerCase(), attrValue);
545
- }
546
- }
547
- }
548
- if (element.children !== null) {
549
- if (Array.isArray(element.children)) {
550
- element.children.forEach((child) => {
551
- const childNode = renderRecursively(child, attributes);
552
- if (childNode) domElement.appendChild(childNode);
553
- });
554
- } else {
555
- const childNode = renderRecursively(element.children, attributes);
556
- if (childNode) domElement.appendChild(childNode);
557
- }
558
- }
559
- return domElement;
560
- };
561
- globalThis.client = {
562
- navigateLocally,
563
- fetchPage,
564
- currentPage,
565
- sanitizePathname,
566
- getReference: (id) => document.querySelector(`[ref="${id}"]`),
567
- renderRecursively
568
- };
569
- try {
570
- loadPage();
571
- } catch (e) {
572
- console.error(e);
573
- }
574
- })();
@@ -1 +0,0 @@
1
- export declare const processPageElements: (element: Child, objectAttributes: Array<any>, parent: Child) => Child;
@@ -1,117 +0,0 @@
1
- import { ObjectAttributeType } from "../helpers/ObjectAttributeType";
2
- let elementKey = 0;
3
- const processOptionAsObjectAttribute = (element, optionName, optionValue, objectAttributes) => {
4
- const lcOptionName = optionName.toLowerCase();
5
- const options = element.options;
6
- let key = options.key;
7
- if (key == void 0) {
8
- elementKey -= 1;
9
- key = elementKey;
10
- options.key = key;
11
- }
12
- if (!optionValue.type) {
13
- throw `ObjectAttributeType is missing from object attribute. ${element.tag}: ${optionName}/${optionValue}`;
14
- }
15
- let optionFinal = lcOptionName;
16
- switch (optionValue.type) {
17
- case ObjectAttributeType.STATE:
18
- const SOA = optionValue;
19
- if (typeof SOA.value === "function") {
20
- delete options[optionName];
21
- break;
22
- }
23
- if (lcOptionName === "innertext" || lcOptionName === "innerhtml") {
24
- element.children = [SOA.value];
25
- delete options[optionName];
26
- } else {
27
- delete options[optionName];
28
- options[lcOptionName] = SOA.value;
29
- }
30
- break;
31
- case ObjectAttributeType.OBSERVER:
32
- const OOA = optionValue;
33
- const firstValue = OOA.update(...OOA.initialValues);
34
- if (lcOptionName === "innertext" || lcOptionName === "innerhtml") {
35
- element.children = [firstValue];
36
- delete options[optionName];
37
- } else {
38
- delete options[optionName];
39
- options[lcOptionName] = firstValue;
40
- }
41
- optionFinal = optionName;
42
- break;
43
- case ObjectAttributeType.REFERENCE:
44
- options["ref"] = optionValue.value;
45
- break;
46
- }
47
- objectAttributes.push({ ...optionValue, key, attribute: optionFinal });
48
- };
49
- const processPageElements = (element, objectAttributes, parent) => {
50
- if (typeof element === "boolean" || typeof element === "number" || Array.isArray(element)) return element;
51
- if (typeof element === "string") {
52
- return element;
53
- }
54
- const processElementOptionsAsChildAndReturn = () => {
55
- const children = element.children;
56
- element.children = [
57
- element.options,
58
- ...children
59
- ];
60
- element.options = {};
61
- for (let i = 0; i < children.length + 1; i++) {
62
- const child = element.children[i];
63
- const processedChild = processPageElements(child, objectAttributes, element);
64
- element.children[i] = processedChild;
65
- }
66
- return {
67
- ...element,
68
- options: {}
69
- };
70
- };
71
- if (typeof element.options !== "object") {
72
- return processElementOptionsAsChildAndReturn();
73
- }
74
- const {
75
- tag: elementTag,
76
- options: elementOptions,
77
- children: elementChildren
78
- } = element.options;
79
- if (elementTag && elementOptions && elementChildren) {
80
- return processElementOptionsAsChildAndReturn();
81
- }
82
- const options = element.options;
83
- for (const [optionName, optionValue] of Object.entries(options)) {
84
- const lcOptionName = optionName.toLowerCase();
85
- if (typeof optionValue !== "object") {
86
- if (lcOptionName === "innertext") {
87
- delete options[optionName];
88
- if (element.children === null) {
89
- throw `Cannot use innerText or innerHTML on childrenless elements.`;
90
- }
91
- element.children = [optionValue, ...element.children];
92
- continue;
93
- } else if (lcOptionName === "innerhtml") {
94
- if (element.children === null) {
95
- throw `Cannot use innerText or innerHTML on childrenless elements.`;
96
- }
97
- delete options[optionName];
98
- element.children = [optionValue];
99
- continue;
100
- }
101
- continue;
102
- }
103
- ;
104
- processOptionAsObjectAttribute(element, optionName, optionValue, objectAttributes);
105
- }
106
- if (element.children) {
107
- for (let i = 0; i < element.children.length; i++) {
108
- const child = element.children[i];
109
- const processedChild = processPageElements(child, objectAttributes, element);
110
- element.children[i] = processedChild;
111
- }
112
- }
113
- return element;
114
- };
115
- export {
116
- processPageElements
117
- };
@@ -1 +0,0 @@
1
- export declare const renderRecursively: (element: Child) => HTMLElement | DocumentFragment | Text | null;