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.
- package/dist/dataset/index.d.ts +2 -2
- package/dist/dataset/index.d.ts.map +1 -1
- package/dist/dataset/index.js +21 -21
- package/dist/dataset/index.js.map +2 -2
- package/dist/dataset/index.mjs +22 -22
- package/dist/dataset/index.mjs.map +2 -2
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +17 -32
- package/dist/hooks/index.js.map +3 -3
- package/dist/hooks/index.mjs +17 -32
- package/dist/hooks/index.mjs.map +3 -3
- package/dist/index.d.ts +49 -53
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +378 -326
- package/dist/index.js.map +3 -3
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/index.mjs +378 -326
- package/dist/index.mjs.map +3 -3
- package/dist/node/index.js +115 -88
- package/dist/node/index.js.map +2 -2
- package/dist/node/index.mjs +115 -88
- package/dist/node/index.mjs.map +2 -2
- package/dist/node/utils/tree-adapter.d.ts +5 -0
- package/dist/node/utils/tree-adapter.d.ts.map +1 -1
- package/dist/proxy-signal/index.js +10 -10
- package/dist/proxy-signal/index.js.map +2 -2
- package/dist/proxy-signal/index.mjs +10 -10
- package/dist/proxy-signal/index.mjs.map +2 -2
- package/dist/request/index.js +16 -16
- package/dist/request/index.js.map +2 -2
- package/dist/request/index.mjs +16 -16
- package/dist/request/index.mjs.map +2 -2
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/index.js +21 -20
- package/dist/router/index.js.map +2 -2
- package/dist/router/index.mjs +21 -20
- package/dist/router/index.mjs.map +2 -2
- package/dist/signal/index.d.ts +7 -18
- package/dist/signal/index.d.ts.map +1 -1
- package/dist/signal/index.js +29 -48
- package/dist/signal/index.js.map +3 -3
- package/dist/signal/index.mjs +31 -50
- package/dist/signal/index.mjs.map +3 -3
- package/dist/store/index.js +2 -2
- package/dist/store/index.js.map +2 -2
- package/dist/store/index.mjs +2 -2
- package/dist/store/index.mjs.map +2 -2
- package/lib/dataset/index.ts +25 -25
- package/lib/hooks/index.ts +25 -54
- package/lib/index.ts +465 -715
- package/lib/node/index.ts +2 -2
- package/lib/node/utils/icons.ts +5 -5
- package/lib/node/utils/inline.ts +17 -17
- package/lib/node/utils/sw.ts +3 -3
- package/lib/node/utils/tree-adapter.ts +95 -62
- package/lib/proxy-signal/index.ts +10 -10
- package/lib/request/index.ts +16 -16
- package/lib/router/index.ts +21 -20
- package/lib/signal/index.ts +56 -131
- package/lib/store/index.ts +2 -2
- package/package.json +10 -3
- package/lib/index.d.ts +0 -0
- 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
|
-
|
|
15
|
-
|
|
14
|
+
const Component = () => args;
|
|
15
|
+
const result = mount("div", Component);
|
|
16
16
|
unmount();
|
|
17
17
|
return result;
|
|
18
18
|
}
|
package/lib/node/utils/icons.ts
CHANGED
|
@@ -33,7 +33,7 @@ interface IconsOptions {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
export async function icons(source: string, configuration?: IconsOptions) {
|
|
36
|
-
|
|
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
|
-
|
|
52
|
+
const response = await favicons(source, options);
|
|
53
53
|
|
|
54
54
|
if (options.iconsPath) {
|
|
55
|
-
for (
|
|
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 (
|
|
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
|
-
|
|
65
|
+
const html = `
|
|
66
66
|
function Links(){
|
|
67
67
|
return ${htmlToHyperscript(response.html.join(""))};
|
|
68
68
|
}
|
package/lib/node/utils/inline.ts
CHANGED
|
@@ -12,13 +12,13 @@ export async function inline(
|
|
|
12
12
|
options: Record<string, any> = {}
|
|
13
13
|
) {
|
|
14
14
|
if (typeof file === "string") {
|
|
15
|
-
|
|
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
|
-
|
|
19
|
-
|
|
18
|
+
const declarationDir = options.declarationDir;
|
|
19
|
+
const emitDeclaration = !!declarationDir;
|
|
20
20
|
|
|
21
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
101
|
-
|
|
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
|
-
|
|
105
|
-
|
|
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
|
-
|
|
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
|
-
|
|
136
|
+
const html = await Promise.all(renderedHtml);
|
|
137
137
|
|
|
138
|
-
|
|
138
|
+
const contents = html.map((item) => {
|
|
139
139
|
return {
|
|
140
140
|
raw: item,
|
|
141
141
|
extension: "html"
|
|
142
142
|
};
|
|
143
143
|
});
|
|
144
144
|
|
|
145
|
-
|
|
145
|
+
const purgecss = new PurgeCSS();
|
|
146
146
|
|
|
147
|
-
|
|
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
|
-
|
|
157
|
+
const cleanCss = await new CleanCSS({
|
|
158
158
|
sourceMap: false,
|
|
159
159
|
level: {
|
|
160
160
|
1: {
|
package/lib/node/utils/sw.ts
CHANGED
|
@@ -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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 (
|
|
266
|
-
|
|
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
|
-
|
|
327
|
-
|
|
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
|
-
|
|
357
|
+
const final = classes.join(" ").trim();
|
|
337
358
|
if (final.length) {
|
|
338
|
-
this.
|
|
359
|
+
this.className = classes.join(" ").trim();
|
|
339
360
|
} else {
|
|
340
|
-
this.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
524
|
+
const attrs: Record<string, any> = {};
|
|
492
525
|
for (let i = 0, l = item.attributes.length; i < l; i++) {
|
|
493
|
-
|
|
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
|
-
|
|
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
|
-
|
|
540
|
-
|
|
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
|
-
|
|
578
|
+
const childContent = html.substring(item.contentStartsAt, child.startsAt);
|
|
546
579
|
|
|
547
|
-
|
|
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
|
-
|
|
600
|
+
const childContent = html.substring(child.endsAt, nextChild.startsAt);
|
|
568
601
|
|
|
569
|
-
|
|
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
|
-
|
|
619
|
+
const childContent = html.substring(child.endsAt, item.contentEndsAt);
|
|
587
620
|
|
|
588
|
-
|
|
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
|
-
|
|
643
|
+
const childContent = html.substring(item.contentStartsAt, item.contentEndsAt);
|
|
611
644
|
|
|
612
645
|
if (childContent.length) {
|
|
613
|
-
|
|
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 (
|
|
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
|
-
|
|
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
|
-
|
|
658
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
732
|
+
const attributesWithValues = string.match(/\S+="[^"]+"/g);
|
|
700
733
|
|
|
701
734
|
if (attributesWithValues) {
|
|
702
|
-
for (
|
|
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
|
-
|
|
744
|
+
const attributesWithBooleanValues = string.match(/\s\S+=[^"]+/g);
|
|
712
745
|
if (attributesWithBooleanValues) {
|
|
713
|
-
for (
|
|
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
|
-
|
|
755
|
+
const attributesWithEmptyValues = string.match(/\s?\S+/g);
|
|
723
756
|
if (attributesWithEmptyValues) {
|
|
724
|
-
for (
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
813
|
+
const documentFragment = document.createDocumentFragment();
|
|
781
814
|
documentFragment.appendChild(document.createTextNode(html));
|
|
782
815
|
return documentFragment;
|
|
783
816
|
}
|
|
784
817
|
|
|
785
|
-
|
|
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
|
-
|
|
796
|
-
|
|
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
|
-
|
|
69
|
-
|
|
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
|
-
|
|
86
|
-
|
|
85
|
+
const subscriptions = new Map();
|
|
86
|
+
const getters: Getters = {};
|
|
87
87
|
|
|
88
88
|
let forceUpdate = false;
|
|
89
89
|
|
|
90
|
-
|
|
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
|
-
|
|
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
|
-
|
|
131
|
+
const old = state[prop];
|
|
132
132
|
state[prop] = val;
|
|
133
133
|
if (prop === "value" && (forceUpdate || val !== old)) {
|
|
134
134
|
forceUpdate = false;
|
|
135
|
-
for (
|
|
135
|
+
for (const [handler, computed] of subscriptions) {
|
|
136
136
|
computed.cleanup();
|
|
137
|
-
|
|
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 (
|
|
167
|
+
for (const [handler, computed] of subscriptions) {
|
|
168
168
|
computed.unsubscribe();
|
|
169
169
|
}
|
|
170
170
|
},
|