valyrian.js 7.2.10 → 7.2.12

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 (64) hide show
  1. package/dist/dataset/index.d.ts +2 -2
  2. package/dist/dataset/index.d.ts.map +1 -1
  3. package/dist/dataset/index.js +21 -21
  4. package/dist/dataset/index.js.map +2 -2
  5. package/dist/dataset/index.mjs +22 -22
  6. package/dist/dataset/index.mjs.map +2 -2
  7. package/dist/hooks/index.d.ts.map +1 -1
  8. package/dist/hooks/index.js +17 -32
  9. package/dist/hooks/index.js.map +3 -3
  10. package/dist/hooks/index.mjs +17 -32
  11. package/dist/hooks/index.mjs.map +3 -3
  12. package/dist/index.d.ts +49 -53
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +378 -326
  15. package/dist/index.js.map +3 -3
  16. package/dist/index.min.js +1 -1
  17. package/dist/index.min.js.map +1 -1
  18. package/dist/index.mjs +378 -326
  19. package/dist/index.mjs.map +3 -3
  20. package/dist/node/index.js +115 -88
  21. package/dist/node/index.js.map +2 -2
  22. package/dist/node/index.mjs +115 -88
  23. package/dist/node/index.mjs.map +2 -2
  24. package/dist/node/utils/tree-adapter.d.ts +5 -0
  25. package/dist/node/utils/tree-adapter.d.ts.map +1 -1
  26. package/dist/proxy-signal/index.js +10 -10
  27. package/dist/proxy-signal/index.js.map +2 -2
  28. package/dist/proxy-signal/index.mjs +10 -10
  29. package/dist/proxy-signal/index.mjs.map +2 -2
  30. package/dist/request/index.js +16 -16
  31. package/dist/request/index.js.map +2 -2
  32. package/dist/request/index.mjs +16 -16
  33. package/dist/request/index.mjs.map +2 -2
  34. package/dist/router/index.d.ts.map +1 -1
  35. package/dist/router/index.js +21 -20
  36. package/dist/router/index.js.map +2 -2
  37. package/dist/router/index.mjs +21 -20
  38. package/dist/router/index.mjs.map +2 -2
  39. package/dist/signal/index.d.ts +7 -18
  40. package/dist/signal/index.d.ts.map +1 -1
  41. package/dist/signal/index.js +29 -48
  42. package/dist/signal/index.js.map +3 -3
  43. package/dist/signal/index.mjs +31 -50
  44. package/dist/signal/index.mjs.map +3 -3
  45. package/dist/store/index.js +2 -2
  46. package/dist/store/index.js.map +2 -2
  47. package/dist/store/index.mjs +2 -2
  48. package/dist/store/index.mjs.map +2 -2
  49. package/lib/dataset/index.ts +25 -25
  50. package/lib/hooks/index.ts +25 -54
  51. package/lib/index.ts +465 -715
  52. package/lib/node/index.ts +2 -2
  53. package/lib/node/utils/icons.ts +5 -5
  54. package/lib/node/utils/inline.ts +17 -17
  55. package/lib/node/utils/sw.ts +3 -3
  56. package/lib/node/utils/tree-adapter.ts +95 -62
  57. package/lib/proxy-signal/index.ts +10 -10
  58. package/lib/request/index.ts +16 -16
  59. package/lib/router/index.ts +21 -20
  60. package/lib/signal/index.ts +56 -131
  61. package/lib/store/index.ts +2 -2
  62. package/package.json +10 -3
  63. package/lib/index.d.ts +0 -0
  64. package/lib/interfaces.ts.bak +0 -141
package/lib/node/index.ts CHANGED
@@ -11,8 +11,8 @@ global.FormData = FormData as any;
11
11
  global.document = document as any;
12
12
 
13
13
  function render(...args: any[]) {
14
- let Component = () => args;
15
- let result = mount("div", Component);
14
+ const Component = () => args;
15
+ const result = mount("div", Component);
16
16
  unmount();
17
17
  return result;
18
18
  }
@@ -33,7 +33,7 @@ interface IconsOptions {
33
33
  }
34
34
 
35
35
  export async function icons(source: string, configuration?: IconsOptions) {
36
- let options = {
36
+ const options = {
37
37
  ...icons.options,
38
38
  ...(configuration || {})
39
39
  };
@@ -49,20 +49,20 @@ export async function icons(source: string, configuration?: IconsOptions) {
49
49
  const { favicons } = await import("favicons");
50
50
 
51
51
  try {
52
- let response = await favicons(source, options);
52
+ const response = await favicons(source, options);
53
53
 
54
54
  if (options.iconsPath) {
55
- for (let i in response.images) {
55
+ for (const i in response.images) {
56
56
  fs.writeFileSync(options.iconsPath + response.images[i].name, response.images[i].contents);
57
57
  }
58
58
 
59
- for (let i in response.files) {
59
+ for (const i in response.files) {
60
60
  fs.writeFileSync(options.iconsPath + response.files[i].name, response.files[i].contents);
61
61
  }
62
62
  }
63
63
 
64
64
  if (options.linksViewPath) {
65
- let html = `
65
+ const html = `
66
66
  function Links(){
67
67
  return ${htmlToHyperscript(response.html.join(""))};
68
68
  }
@@ -12,13 +12,13 @@ export async function inline(
12
12
  options: Record<string, any> = {}
13
13
  ) {
14
14
  if (typeof file === "string") {
15
- let ext = file.split(".").pop();
15
+ const ext = file.split(".").pop();
16
16
  if (ext && /(js|cjs|jsx|mjs|ts|tsx)/.test(ext)) {
17
17
  if (/(ts|tsx)/.test(ext) && !options.noValidate) {
18
- let declarationDir = options.declarationDir;
19
- let emitDeclaration = !!declarationDir;
18
+ const declarationDir = options.declarationDir;
19
+ const emitDeclaration = !!declarationDir;
20
20
 
21
- let tscProgOptions = {
21
+ const tscProgOptions = {
22
22
  basePath: process.cwd(), // always required, used for relative paths
23
23
  configFilePath: "tsconfig.json", // config to inherit from (optional)
24
24
  files: [file],
@@ -53,7 +53,7 @@ export async function inline(
53
53
  tsc.build(tscProgOptions);
54
54
  }
55
55
 
56
- let esbuildOptions = {
56
+ const esbuildOptions = {
57
57
  entryPoints: [file],
58
58
  bundle: "bundle" in options ? options.bundle : true,
59
59
  sourcemap: "external",
@@ -72,14 +72,14 @@ export async function inline(
72
72
  ...(options.esbuild || {})
73
73
  };
74
74
 
75
- let result = await esbuild.build(esbuildOptions);
75
+ const result = await esbuild.build(esbuildOptions);
76
76
  if (result.outputFiles?.length !== 2) {
77
77
  throw new Error(result.errors.join("\n"));
78
78
  }
79
79
 
80
80
  if (options.compact) {
81
81
  const terser = await import("terser");
82
- let result2 = await terser.minify(result.outputFiles[1].text, {
82
+ const result2 = await terser.minify(result.outputFiles[1].text, {
83
83
  sourceMap: {
84
84
  content: result.outputFiles[0].text.toString()
85
85
  },
@@ -97,16 +97,16 @@ export async function inline(
97
97
  throw new Error("Unknown error");
98
98
  }
99
99
 
100
- let mapBase64 = Buffer.from(result2.map.toString()).toString("base64");
101
- let suffix = `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${mapBase64}`;
100
+ const mapBase64 = Buffer.from(result2.map.toString()).toString("base64");
101
+ const suffix = `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${mapBase64}`;
102
102
  return { raw: result2.code, map: suffix, file };
103
103
  } else {
104
- let mapBase64 = Buffer.from(result.outputFiles[0].text.toString()).toString("base64");
105
- let suffix = `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${mapBase64}`;
104
+ const mapBase64 = Buffer.from(result.outputFiles[0].text.toString()).toString("base64");
105
+ const suffix = `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${mapBase64}`;
106
106
  return { raw: result.outputFiles[1].text, map: suffix, file };
107
107
  }
108
108
  } else if (ext && /(css|scss|styl)/.test(ext)) {
109
- let result = await new CleanCSS({
109
+ const result = await new CleanCSS({
110
110
  sourceMap: true,
111
111
  level: {
112
112
  1: {
@@ -133,18 +133,18 @@ inline.uncss = async function (
133
133
  css: string,
134
134
  options: Record<string, any> = {}
135
135
  ) {
136
- let html = await Promise.all(renderedHtml);
136
+ const html = await Promise.all(renderedHtml);
137
137
 
138
- let contents = html.map((item) => {
138
+ const contents = html.map((item) => {
139
139
  return {
140
140
  raw: item,
141
141
  extension: "html"
142
142
  };
143
143
  });
144
144
 
145
- let purgecss = new PurgeCSS();
145
+ const purgecss = new PurgeCSS();
146
146
 
147
- let output = await purgecss.purge({
147
+ const output = await purgecss.purge({
148
148
  fontFace: true,
149
149
  keyframes: true,
150
150
  variables: true,
@@ -154,7 +154,7 @@ inline.uncss = async function (
154
154
  css: [{ raw: css }]
155
155
  });
156
156
 
157
- let cleanCss = await new CleanCSS({
157
+ const cleanCss = await new CleanCSS({
158
158
  sourceMap: false,
159
159
  level: {
160
160
  1: {
@@ -2,9 +2,9 @@ import fs from "fs";
2
2
  import path from "path";
3
3
 
4
4
  export function sw(file: string, options = {}) {
5
- let swfiletemplate = path.resolve(__dirname, "./node.sw.tpl");
6
- let swTpl = fs.readFileSync(swfiletemplate, "utf8");
7
- let opt = Object.assign(
5
+ const swfiletemplate = path.resolve(__dirname, "./node.sw.tpl");
6
+ const swTpl = fs.readFileSync(swfiletemplate, "utf8");
7
+ const opt = Object.assign(
8
8
  {
9
9
  version: "v1::",
10
10
  name: "Valyrian.js",
@@ -56,26 +56,30 @@ export class Node implements Node {
56
56
  constructor() {}
57
57
 
58
58
  appendChild<T extends Node>(node: T): T {
59
- node.parentNode && node.parentNode.removeChild(node as Node);
60
- this.childNodes.push(node);
61
- node.parentNode = this;
59
+ if (node) {
60
+ node.parentNode && node.parentNode.removeChild(node as Node);
61
+ this.childNodes.push(node);
62
+ node.parentNode = this;
63
+ }
62
64
  return node;
63
65
  }
64
66
 
65
67
  insertBefore<T extends Node>(node: T, child: Node | null): T {
66
- node.parentNode && node.parentNode.removeChild(node as Node);
67
- node.parentNode = this;
68
- if (child) {
69
- let idx = this.childNodes.indexOf(child);
70
- this.childNodes.splice(idx, 0, node);
71
- } else {
72
- this.childNodes.push(node);
68
+ if (node) {
69
+ node.parentNode && node.parentNode.removeChild(node as Node);
70
+ node.parentNode = this;
71
+ if (child) {
72
+ const idx = this.childNodes.indexOf(child);
73
+ this.childNodes.splice(idx, 0, node);
74
+ } else {
75
+ this.childNodes.push(node);
76
+ }
73
77
  }
74
78
  return node;
75
79
  }
76
80
 
77
81
  replaceChild<T extends Node>(node: Node, child: T): T {
78
- if (child && child.parentNode === this) {
82
+ if (node && child && child.parentNode === this) {
79
83
  this.insertBefore(node, child);
80
84
  child.parentNode && child.parentNode.removeChild(child);
81
85
  }
@@ -83,19 +87,24 @@ export class Node implements Node {
83
87
  }
84
88
  removeChild<T extends Node>(child: T): T {
85
89
  if (child && child.parentNode === this) {
86
- let idx = (this.childNodes as unknown as Node[]).indexOf(child);
90
+ const idx = (this.childNodes as unknown as Node[]).indexOf(child);
87
91
  (this.childNodes as unknown as Node[]).splice(idx, 1);
88
92
  child.parentNode = null;
89
93
  }
90
94
  return child;
91
95
  }
96
+
97
+ remove(): Node {
98
+ return this.parentNode ? this.parentNode.removeChild(this) : this;
99
+ }
100
+
92
101
  cloneNode(deep?: boolean | undefined): Node {
93
102
  if (this.nodeType === 3) {
94
103
  return new Text(this.nodeValue);
95
104
  }
96
105
 
97
106
  if (this.nodeType === 1) {
98
- let node = new Element();
107
+ const node = new Element();
99
108
  node.nodeType = this.nodeType;
100
109
  this.nodeName = this.nodeName;
101
110
  if (this.attributes) {
@@ -111,14 +120,14 @@ export class Node implements Node {
111
120
  return node;
112
121
  }
113
122
 
114
- let node = new Node();
123
+ const node = new Node();
115
124
  node.nodeType = this.nodeType;
116
125
  node.nodeName = this.nodeName;
117
126
  return node;
118
127
  }
119
128
 
120
129
  setAttribute(name: string, value: any) {
121
- let attr = {
130
+ const attr = {
122
131
  nodeName: name,
123
132
  nodeValue: value
124
133
  };
@@ -262,8 +271,8 @@ export class Text extends Node {
262
271
 
263
272
  function updateElementStyles(element: Element, state: Record<string, any>) {
264
273
  let str = "";
265
- for (let key in state) {
266
- let value = state[key];
274
+ for (const key in state) {
275
+ const value = state[key];
267
276
  if (typeof value !== "undefined" && value !== null && String(value).length > 0) {
268
277
  str += `${key}: ${state[key]};`;
269
278
  }
@@ -320,11 +329,23 @@ export class Element extends Node {
320
329
  throw new Error("Cannot set style");
321
330
  }
322
331
 
332
+ get className(): string {
333
+ return this.getAttribute("class") || "";
334
+ }
335
+
336
+ set className(value: string | boolean) {
337
+ if (value == null || value === false) {
338
+ this.removeAttribute("class");
339
+ } else {
340
+ this.setAttribute("class", String(value));
341
+ }
342
+ }
343
+
323
344
  classList = {
324
345
  toggle: (item: any, force: any) => {
325
346
  if (item) {
326
- let classes = (this.getAttribute("class") || "").split(" ");
327
- let itemIndex = classes.indexOf(item);
347
+ const classes = (this.className || "").split(" ");
348
+ const itemIndex = classes.indexOf(item);
328
349
  if (force && itemIndex === -1) {
329
350
  classes.push(item);
330
351
  }
@@ -333,16 +354,28 @@ export class Element extends Node {
333
354
  classes.splice(itemIndex, 1);
334
355
  }
335
356
 
336
- let final = classes.join(" ").trim();
357
+ const final = classes.join(" ").trim();
337
358
  if (final.length) {
338
- this.setAttribute("class", classes.join(" ").trim());
359
+ this.className = classes.join(" ").trim();
339
360
  } else {
340
- this.removeAttribute("class");
361
+ this.className = false;
341
362
  }
342
363
  }
343
364
  }
344
365
  };
345
366
 
367
+ get id(): string {
368
+ return this.getAttribute("id") || "";
369
+ }
370
+
371
+ set id(value: string | boolean) {
372
+ if (value == null || value === false) {
373
+ this.removeAttribute("id");
374
+ } else {
375
+ this.setAttribute("id", String(value));
376
+ }
377
+ }
378
+
346
379
  set textContent(text) {
347
380
  this.nodeValue = String(text);
348
381
  this.childNodes = this.nodeValue ? [new Text(this.nodeValue)] : [];
@@ -370,7 +403,7 @@ export class Element extends Node {
370
403
 
371
404
  set innerHTML(html) {
372
405
  this.textContent = "";
373
- let result = htmlToDom(html);
406
+ const result = htmlToDom(html);
374
407
  if (result instanceof DocumentFragment) {
375
408
  for (let i = 0, l = result.childNodes.length; i < l; i++) {
376
409
  this.appendChild(result.childNodes[i]);
@@ -405,13 +438,13 @@ export class Document extends Element {
405
438
  }
406
439
 
407
440
  createElement(type: string) {
408
- let element = new Element();
441
+ const element = new Element();
409
442
  element.nodeName = type.toUpperCase();
410
443
  return element;
411
444
  }
412
445
 
413
446
  createElementNS(ns: string, type: string) {
414
- let element = this.createElement(type);
447
+ const element = this.createElement(type);
415
448
  element.baseURI = ns;
416
449
  return element;
417
450
  }
@@ -421,7 +454,7 @@ export class Document extends Element {
421
454
  }
422
455
  }
423
456
 
424
- let selfClosingTags = [
457
+ const selfClosingTags = [
425
458
  "area",
426
459
  "base",
427
460
  "br",
@@ -445,7 +478,7 @@ export function domToHtml(dom: Element): string {
445
478
  }
446
479
 
447
480
  if (dom.nodeType === 1) {
448
- let name = dom.nodeName.toLowerCase();
481
+ const name = dom.nodeName.toLowerCase();
449
482
  let str = "<" + name;
450
483
  for (let i = 0, l = dom.attributes.length; i < l; i++) {
451
484
  str += " " + dom.attributes[i].nodeName + '="' + dom.attributes[i].nodeValue + '"';
@@ -455,7 +488,7 @@ export function domToHtml(dom: Element): string {
455
488
  str += ">";
456
489
  if (dom.childNodes && dom.childNodes.length > 0) {
457
490
  for (let i = 0, l = dom.childNodes.length; i < l; i++) {
458
- let child = domToHtml(dom.childNodes[i] as Element);
491
+ const child = domToHtml(dom.childNodes[i] as Element);
459
492
  if (child) {
460
493
  str += child;
461
494
  }
@@ -488,9 +521,9 @@ export function domToHyperscript(childNodes: ChildNodes, depth = 1) {
488
521
  let str = `\n${spaces}v("${item.nodeName}", `;
489
522
 
490
523
  if (item.attributes) {
491
- let attrs: Record<string, any> = {};
524
+ const attrs: Record<string, any> = {};
492
525
  for (let i = 0, l = item.attributes.length; i < l; i++) {
493
- let attr = item.attributes[i];
526
+ const attr = item.attributes[i];
494
527
  attrs[attr.nodeName] = attr.nodeValue;
495
528
  }
496
529
  str += JSON.stringify(attrs);
@@ -530,21 +563,21 @@ interface ObjectIndexItemWithContent extends ObjectIndexItem {
530
563
  interface ObjectIndexList extends Array<ObjectIndexItem> {}
531
564
 
532
565
  function findTexts(item: ObjectIndexItemWithContent, html: string) {
533
- let newChildren: ObjectIndexItemWithContent[] = [];
566
+ const newChildren: ObjectIndexItemWithContent[] = [];
534
567
 
535
568
  // If the item has children
536
569
  if (item.children.length) {
537
570
  // Search for texts in the children.
538
571
  for (let i = 0; i < item.children.length; i++) {
539
- let child = item.children[i];
540
- let nextChild = item.children[i + 1];
572
+ const child = item.children[i];
573
+ const nextChild = item.children[i + 1];
541
574
 
542
575
  // If is the first child and the child startsAt is greater than the item contentStartsAt then
543
576
  // the content between the item contentStartsAt and the child startsAt is a text child of the item.
544
577
  if (i === 0 && child.startsAt > item.contentStartsAt) {
545
- let childContent = html.substring(item.contentStartsAt, child.startsAt);
578
+ const childContent = html.substring(item.contentStartsAt, child.startsAt);
546
579
 
547
- let childText: ObjectIndexItemWithContent = {
580
+ const childText: ObjectIndexItemWithContent = {
548
581
  tagName: "#text",
549
582
  startsAt: item.contentStartsAt,
550
583
  endsAt: item.contentStartsAt + childContent.length,
@@ -564,9 +597,9 @@ function findTexts(item: ObjectIndexItemWithContent, html: string) {
564
597
  // If there is a next child and the child endsAt is less than the next child startsAt then
565
598
  // the content between the child endsAt and the next child startsAt is a text child of the item.
566
599
  if (nextChild && child.endsAt < nextChild.startsAt) {
567
- let childContent = html.substring(child.endsAt, nextChild.startsAt);
600
+ const childContent = html.substring(child.endsAt, nextChild.startsAt);
568
601
 
569
- let childText: ObjectIndexItemWithContent = {
602
+ const childText: ObjectIndexItemWithContent = {
570
603
  tagName: "#text",
571
604
  startsAt: child.endsAt,
572
605
  endsAt: child.endsAt + childContent.length,
@@ -583,9 +616,9 @@ function findTexts(item: ObjectIndexItemWithContent, html: string) {
583
616
  // If there are no next child and the child endsAt is less than the item contentEndsAt then
584
617
  // the content between the child endsAt and the item contentEndsAt is a text child of the item.
585
618
  if (!nextChild && child.endsAt < item.contentEndsAt) {
586
- let childContent = html.substring(child.endsAt, item.contentEndsAt);
619
+ const childContent = html.substring(child.endsAt, item.contentEndsAt);
587
620
 
588
- let childText: ObjectIndexItemWithContent = {
621
+ const childText: ObjectIndexItemWithContent = {
589
622
  tagName: "#text",
590
623
  startsAt: child.endsAt,
591
624
  endsAt: child.endsAt + childContent.length,
@@ -607,10 +640,10 @@ function findTexts(item: ObjectIndexItemWithContent, html: string) {
607
640
  // If the item has no children then set the contents between the item contentStartsAt and the item contentEndsAt
608
641
  // as a text child of the item.
609
642
  if (!item.children.length) {
610
- let childContent = html.substring(item.contentStartsAt, item.contentEndsAt);
643
+ const childContent = html.substring(item.contentStartsAt, item.contentEndsAt);
611
644
 
612
645
  if (childContent.length) {
613
- let childText: ObjectIndexItemWithContent = {
646
+ const childText: ObjectIndexItemWithContent = {
614
647
  tagName: "#text",
615
648
  startsAt: item.contentStartsAt,
616
649
  endsAt: item.contentEndsAt,
@@ -638,12 +671,12 @@ function convertToDom<T extends Node>(item: ObjectIndexItemWithContent): T {
638
671
  ? document.createDocumentFragment()
639
672
  : document.createElement(item.tagName)) as unknown as T;
640
673
 
641
- for (let key in item.attributes) {
674
+ for (const key in item.attributes) {
642
675
  node.setAttribute(key, item.attributes[key]);
643
676
  }
644
677
 
645
678
  for (let i = 0; i < item.children.length; i++) {
646
- let child = convertToDom(item.children[i]);
679
+ const child = convertToDom(item.children[i]);
647
680
  node.appendChild(child);
648
681
  }
649
682
  }
@@ -654,23 +687,23 @@ function convertToDom<T extends Node>(item: ObjectIndexItemWithContent): T {
654
687
  // eslint-disable-next-line sonarjs/cognitive-complexity
655
688
  function getObjectIndexTree(html: string): DocumentFragment {
656
689
  let item;
657
- let regex = RegExp("<([^>|^!]+)>", "g");
658
- let items: ObjectIndexList = [];
690
+ const regex = RegExp("<([^>|^!]+)>", "g");
691
+ const items: ObjectIndexList = [];
659
692
 
660
693
  // Make the initial list of items.
661
694
  while ((item = regex.exec(html))) {
662
695
  // If is a closing tag
663
696
  if (item[0].startsWith("</")) {
664
- let lastOpenedItem = [...items].reverse().find((item) => item.endsAt === null);
697
+ const lastOpenedItem = [...items].reverse().find((item) => item.endsAt === null);
665
698
  if (lastOpenedItem) {
666
699
  lastOpenedItem.endsAt = item.index + item[0].length;
667
700
  lastOpenedItem.contentEndsAt = item.index;
668
701
 
669
702
  // Find the last opened item again, this will be the parent of the current item.
670
- let parent = [...items].reverse().find((item) => item.endsAt === null);
703
+ const parent = [...items].reverse().find((item) => item.endsAt === null);
671
704
  if (parent) {
672
705
  // Find the index of the current item in the items array.
673
- let index = items.indexOf(lastOpenedItem);
706
+ const index = items.indexOf(lastOpenedItem);
674
707
  // Remove the last opened item from the items array.
675
708
  items.splice(index, 1);
676
709
 
@@ -683,7 +716,7 @@ function getObjectIndexTree(html: string): DocumentFragment {
683
716
  }
684
717
 
685
718
  // If is an opening tag
686
- let element: ObjectIndexItem = {
719
+ const element: ObjectIndexItem = {
687
720
  tagName: item[1].split(" ")[0],
688
721
  startsAt: item.index,
689
722
  endsAt: null,
@@ -696,10 +729,10 @@ function getObjectIndexTree(html: string): DocumentFragment {
696
729
 
697
730
  // Find the attributes of the tag.
698
731
  let string = (item[1] || "").substring(element.tagName.length + 1).replace(/\/$/g, "");
699
- let attributesWithValues = string.match(/\S+="[^"]+"/g);
732
+ const attributesWithValues = string.match(/\S+="[^"]+"/g);
700
733
 
701
734
  if (attributesWithValues) {
702
- for (let attribute of attributesWithValues) {
735
+ for (const attribute of attributesWithValues) {
703
736
  const [name, ...value] = attribute.trim().split("=");
704
737
  string = string.replace(attribute, "");
705
738
  if (value) {
@@ -708,9 +741,9 @@ function getObjectIndexTree(html: string): DocumentFragment {
708
741
  }
709
742
  }
710
743
 
711
- let attributesWithBooleanValues = string.match(/\s\S+=[^"]+/g);
744
+ const attributesWithBooleanValues = string.match(/\s\S+=[^"]+/g);
712
745
  if (attributesWithBooleanValues) {
713
- for (let attribute of attributesWithBooleanValues) {
746
+ for (const attribute of attributesWithBooleanValues) {
714
747
  const [name, ...value] = attribute.trim().split("=");
715
748
  string = string.replace(attribute, "");
716
749
  if (value) {
@@ -719,9 +752,9 @@ function getObjectIndexTree(html: string): DocumentFragment {
719
752
  }
720
753
  }
721
754
 
722
- let attributesWithEmptyValues = string.match(/\s?\S+/g);
755
+ const attributesWithEmptyValues = string.match(/\s?\S+/g);
723
756
  if (attributesWithEmptyValues) {
724
- for (let attribute of attributesWithEmptyValues) {
757
+ for (const attribute of attributesWithEmptyValues) {
725
758
  const name = attribute.trim();
726
759
  element.attributes[name] = true;
727
760
  }
@@ -733,7 +766,7 @@ function getObjectIndexTree(html: string): DocumentFragment {
733
766
  element.contentStartsAt = element.contentEndsAt = element.endsAt;
734
767
 
735
768
  // Find the last opened item, this will be the parent of the current item.
736
- let parent = [...items].reverse().find((item) => item.endsAt === null);
769
+ const parent = [...items].reverse().find((item) => item.endsAt === null);
737
770
  if (parent) {
738
771
  // Add the last opened item as a child of the parent.
739
772
  parent.children.push(element);
@@ -744,7 +777,7 @@ function getObjectIndexTree(html: string): DocumentFragment {
744
777
  items.push(element);
745
778
  }
746
779
 
747
- let fragmentItem: ObjectIndexItemWithContent = {
780
+ const fragmentItem: ObjectIndexItemWithContent = {
748
781
  tagName: "#document-fragment",
749
782
  startsAt: 0,
750
783
  endsAt: html.length,
@@ -773,16 +806,16 @@ export function htmlToDom(html: string): Element | Text | DocumentFragment {
773
806
  // search for the first opening tag.
774
807
  const openingTag = html.match(/<[^>]+>/g);
775
808
 
776
- let document = new Document();
809
+ const document = new Document();
777
810
 
778
811
  // If the opening tag is not found, return a document fragment node with the html string as text content.
779
812
  if (!openingTag) {
780
- let documentFragment = document.createDocumentFragment();
813
+ const documentFragment = document.createDocumentFragment();
781
814
  documentFragment.appendChild(document.createTextNode(html));
782
815
  return documentFragment;
783
816
  }
784
817
 
785
- let fragment = getObjectIndexTree(html);
818
+ const fragment = getObjectIndexTree(html);
786
819
 
787
820
  if (fragment.childNodes.length > 1) {
788
821
  return fragment;
@@ -792,8 +825,8 @@ export function htmlToDom(html: string): Element | Text | DocumentFragment {
792
825
  }
793
826
 
794
827
  export function htmlToHyperscript(html: string) {
795
- let domTree = htmlToDom(html);
796
- let hyperscript = domToHyperscript(domTree instanceof DocumentFragment ? domTree.childNodes : [domTree]);
828
+ const domTree = htmlToDom(html);
829
+ const hyperscript = domToHyperscript(domTree instanceof DocumentFragment ? domTree.childNodes : [domTree]);
797
830
  return `[${hyperscript}\n]`;
798
831
  }
799
832
 
@@ -65,8 +65,8 @@ function makeUnsubscribe(
65
65
  function createSubscription(signal: ProxySignal, subscriptions: Subscriptions, handler: Subscription) {
66
66
  if (subscriptions.has(handler) === false) {
67
67
  // eslint-disable-next-line no-use-before-define
68
- let computed = ProxySignal(() => handler(signal.value));
69
- let cleanup = computed(); // Execute to register itself
68
+ const computed = ProxySignal(() => handler(signal.value));
69
+ const cleanup = computed(); // Execute to register itself
70
70
  makeUnsubscribe(subscriptions, computed, handler, cleanup);
71
71
  subscriptions.set(handler, computed);
72
72
  }
@@ -82,12 +82,12 @@ function delayedUpdate() {
82
82
 
83
83
  // eslint-disable-next-line sonarjs/cognitive-complexity
84
84
  export function ProxySignal(value: any): ProxySignal {
85
- let subscriptions = new Map();
86
- let getters: Getters = {};
85
+ const subscriptions = new Map();
86
+ const getters: Getters = {};
87
87
 
88
88
  let forceUpdate = false;
89
89
 
90
- let signal: ProxySignal = new Proxy(
90
+ const signal: ProxySignal = new Proxy(
91
91
  // eslint-disable-next-line no-unused-vars
92
92
  function (valOrPath?: any | Subscription, handler?: (valueAtPathPosition: any) => any) {
93
93
  // Works as a getter
@@ -102,7 +102,7 @@ export function ProxySignal(value: any): ProxySignal {
102
102
 
103
103
  // Works as a setter with a path
104
104
  if (typeof valOrPath === "string" && typeof handler !== "undefined") {
105
- let parsed = valOrPath.split(".");
105
+ const parsed = valOrPath.split(".");
106
106
  let result = signal.value;
107
107
  let next;
108
108
  while (parsed.length) {
@@ -128,13 +128,13 @@ export function ProxySignal(value: any): ProxySignal {
128
128
  {
129
129
  set(state, prop, val) {
130
130
  if (prop === "value" || prop === "unsubscribe" || prop === "cleanup") {
131
- let old = state[prop];
131
+ const old = state[prop];
132
132
  state[prop] = val;
133
133
  if (prop === "value" && (forceUpdate || val !== old)) {
134
134
  forceUpdate = false;
135
- for (let [handler, computed] of subscriptions) {
135
+ for (const [handler, computed] of subscriptions) {
136
136
  computed.cleanup();
137
- let cleanup = handler(val);
137
+ const cleanup = handler(val);
138
138
  makeUnsubscribe(subscriptions, computed, handler, cleanup);
139
139
  }
140
140
  delayedUpdate();
@@ -164,7 +164,7 @@ export function ProxySignal(value: any): ProxySignal {
164
164
  cleanup: {
165
165
  value() {
166
166
  // eslint-disable-next-line no-unused-vars
167
- for (let [handler, computed] of subscriptions) {
167
+ for (const [handler, computed] of subscriptions) {
168
168
  computed.unsubscribe();
169
169
  }
170
170
  },