valyrian.js 7.2.11 → 8.0.0
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/README.md +6 -6
- package/dist/flux-store/index.d.ts +32 -0
- package/dist/flux-store/index.d.ts.map +1 -0
- package/dist/flux-store/index.js +258 -0
- package/dist/flux-store/index.js.map +7 -0
- package/dist/flux-store/index.min.js +1 -0
- package/dist/flux-store/index.min.js.map +1 -0
- package/dist/flux-store/index.mjs +237 -0
- package/dist/flux-store/index.mjs.map +7 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +42 -75
- package/dist/hooks/index.js.map +2 -2
- package/dist/hooks/index.min.js +1 -0
- package/dist/hooks/index.min.js.map +1 -0
- package/dist/hooks/index.mjs +43 -76
- package/dist/hooks/index.mjs.map +2 -2
- package/dist/index.d.ts +52 -54
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +397 -328
- 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 +397 -328
- package/dist/index.mjs.map +3 -3
- package/dist/native-store/index.d.ts +14 -0
- package/dist/native-store/index.d.ts.map +1 -0
- package/dist/native-store/index.js +103 -0
- package/dist/native-store/index.js.map +7 -0
- package/dist/native-store/index.min.js +1 -0
- package/dist/native-store/index.min.js.map +1 -0
- package/dist/native-store/index.mjs +82 -0
- package/dist/native-store/index.mjs.map +7 -0
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +223 -86
- package/dist/node/index.js.map +4 -4
- package/dist/node/index.mjs +223 -86
- package/dist/node/index.mjs.map +4 -4
- package/dist/node/node.sw.js +152 -0
- package/dist/node/utils/inline.d.ts.map +1 -1
- package/dist/node/utils/node.sw.js +152 -0
- package/dist/node/utils/session-storage.d.ts +22 -0
- package/dist/node/utils/session-storage.d.ts.map +1 -0
- package/dist/node/utils/sw.d.ts.map +1 -1
- package/dist/node/utils/tree-adapter.d.ts +9 -0
- package/dist/node/utils/tree-adapter.d.ts.map +1 -1
- package/dist/pulse-store/index.d.ts +13 -0
- package/dist/pulse-store/index.d.ts.map +1 -0
- package/dist/pulse-store/index.js +143 -0
- package/dist/pulse-store/index.js.map +7 -0
- package/dist/pulse-store/index.min.js +1 -0
- package/dist/pulse-store/index.min.js.map +1 -0
- package/dist/pulse-store/index.mjs +122 -0
- package/dist/pulse-store/index.mjs.map +7 -0
- package/dist/request/index.d.ts.map +1 -1
- package/dist/request/index.js +68 -89
- package/dist/request/index.js.map +2 -2
- package/dist/request/index.min.js +1 -0
- package/dist/request/index.min.js.map +1 -0
- package/dist/request/index.mjs +68 -89
- package/dist/request/index.mjs.map +2 -2
- package/dist/router/index.d.ts +32 -31
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/index.js +256 -104
- package/dist/router/index.js.map +3 -3
- package/dist/router/index.min.js +1 -0
- package/dist/router/index.min.js.map +1 -0
- package/dist/router/index.mjs +256 -104
- package/dist/router/index.mjs.map +3 -3
- package/dist/signals/index.d.ts +6 -0
- package/dist/signals/index.d.ts.map +1 -0
- package/dist/signals/index.js +92 -0
- package/dist/signals/index.js.map +7 -0
- package/dist/signals/index.min.js +1 -0
- package/dist/signals/index.min.js.map +1 -0
- package/dist/signals/index.mjs +71 -0
- package/dist/signals/index.mjs.map +7 -0
- package/dist/suspense/index.d.ts +6 -0
- package/dist/suspense/index.d.ts.map +1 -0
- package/dist/suspense/index.js +67 -0
- package/dist/suspense/index.js.map +7 -0
- package/dist/suspense/index.min.js +1 -0
- package/dist/suspense/index.min.js.map +1 -0
- package/dist/suspense/index.mjs +46 -0
- package/dist/suspense/index.mjs.map +7 -0
- package/dist/sw/index.min.js +1 -0
- package/dist/sw/index.min.js.map +1 -0
- package/dist/translate/index.d.ts +19 -0
- package/dist/translate/index.d.ts.map +1 -0
- package/dist/translate/index.js +150 -0
- package/dist/translate/index.js.map +7 -0
- package/dist/translate/index.min.js +1 -0
- package/dist/translate/index.min.js.map +1 -0
- package/dist/translate/index.mjs +129 -0
- package/dist/translate/index.mjs.map +7 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/deep-freeze.d.ts +3 -0
- package/dist/utils/deep-freeze.d.ts.map +1 -0
- package/dist/utils/getter-setter.d.ts +3 -0
- package/dist/utils/getter-setter.d.ts.map +1 -0
- package/dist/utils/has-changed.d.ts +2 -0
- package/dist/utils/has-changed.d.ts.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +138 -0
- package/dist/utils/index.js.map +7 -0
- package/dist/utils/index.min.js +1 -0
- package/dist/utils/index.min.js.map +1 -0
- package/dist/utils/index.mjs +115 -0
- package/dist/utils/index.mjs.map +7 -0
- package/lib/flux-store/index.ts +301 -0
- package/lib/hooks/index.ts +52 -101
- package/lib/index.ts +479 -719
- package/lib/native-store/index.ts +106 -0
- package/lib/node/index.ts +5 -3
- package/lib/node/utils/icons.ts +5 -5
- package/lib/node/utils/inline.ts +17 -17
- package/lib/node/utils/node.sw.js +152 -0
- package/lib/node/utils/session-storage.ts +117 -0
- package/lib/node/utils/sw.ts +35 -11
- package/lib/node/utils/tree-adapter.ts +99 -52
- package/lib/pulse-store/index.ts +181 -0
- package/lib/request/index.ts +86 -116
- package/lib/router/index.ts +358 -170
- package/lib/signals/index.ts +98 -0
- package/lib/suspense/index.ts +57 -0
- package/lib/translate/index.ts +156 -0
- package/lib/utils/deep-freeze.ts +54 -0
- package/lib/utils/getter-setter.ts +40 -0
- package/lib/utils/has-changed.ts +43 -0
- package/lib/utils/index.ts +3 -0
- package/package.json +38 -50
- package/tsconfig.json +1 -1
- package/dist/dataset/index.d.ts +0 -24
- package/dist/dataset/index.d.ts.map +0 -1
- package/dist/dataset/index.js +0 -178
- package/dist/dataset/index.js.map +0 -7
- package/dist/dataset/index.mjs +0 -157
- package/dist/dataset/index.mjs.map +0 -7
- package/dist/node/node.sw.tpl +0 -133
- package/dist/node/utils/node.sw.tpl +0 -133
- package/dist/proxy-signal/index.d.ts +0 -23
- package/dist/proxy-signal/index.d.ts.map +0 -1
- package/dist/proxy-signal/index.js +0 -138
- package/dist/proxy-signal/index.js.map +0 -7
- package/dist/proxy-signal/index.mjs +0 -117
- package/dist/proxy-signal/index.mjs.map +0 -7
- package/dist/signal/index.d.ts +0 -20
- package/dist/signal/index.d.ts.map +0 -1
- package/dist/signal/index.js +0 -95
- package/dist/signal/index.js.map +0 -7
- package/dist/signal/index.mjs +0 -74
- package/dist/signal/index.mjs.map +0 -7
- package/dist/store/index.d.ts +0 -16
- package/dist/store/index.d.ts.map +0 -1
- package/dist/store/index.js +0 -93
- package/dist/store/index.js.map +0 -7
- package/dist/store/index.mjs +0 -72
- package/dist/store/index.mjs.map +0 -7
- package/lib/dataset/index.ts +0 -193
- package/lib/index.d.ts +0 -0
- package/lib/interfaces.ts.bak +0 -141
- package/lib/node/utils/node.sw.tpl +0 -133
- package/lib/proxy-signal/index.ts +0 -187
- package/lib/signal/index.ts +0 -161
- package/lib/store/index.ts +0 -101
package/dist/node/index.mjs
CHANGED
|
@@ -45,6 +45,13 @@ var Node = class _Node {
|
|
|
45
45
|
set parentNode(node) {
|
|
46
46
|
this.parent_node = node;
|
|
47
47
|
}
|
|
48
|
+
#dataset = {};
|
|
49
|
+
get dataset() {
|
|
50
|
+
return this.#dataset;
|
|
51
|
+
}
|
|
52
|
+
set dataset(value) {
|
|
53
|
+
this.#dataset = value;
|
|
54
|
+
}
|
|
48
55
|
constructor() {
|
|
49
56
|
}
|
|
50
57
|
appendChild(node) {
|
|
@@ -60,7 +67,7 @@ var Node = class _Node {
|
|
|
60
67
|
node.parentNode && node.parentNode.removeChild(node);
|
|
61
68
|
node.parentNode = this;
|
|
62
69
|
if (child) {
|
|
63
|
-
|
|
70
|
+
const idx = this.childNodes.indexOf(child);
|
|
64
71
|
this.childNodes.splice(idx, 0, node);
|
|
65
72
|
} else {
|
|
66
73
|
this.childNodes.push(node);
|
|
@@ -77,18 +84,21 @@ var Node = class _Node {
|
|
|
77
84
|
}
|
|
78
85
|
removeChild(child) {
|
|
79
86
|
if (child && child.parentNode === this) {
|
|
80
|
-
|
|
87
|
+
const idx = this.childNodes.indexOf(child);
|
|
81
88
|
this.childNodes.splice(idx, 1);
|
|
82
89
|
child.parentNode = null;
|
|
83
90
|
}
|
|
84
91
|
return child;
|
|
85
92
|
}
|
|
93
|
+
remove() {
|
|
94
|
+
return this.parentNode ? this.parentNode.removeChild(this) : this;
|
|
95
|
+
}
|
|
86
96
|
cloneNode(deep) {
|
|
87
97
|
if (this.nodeType === 3) {
|
|
88
98
|
return new Text(this.nodeValue);
|
|
89
99
|
}
|
|
90
100
|
if (this.nodeType === 1) {
|
|
91
|
-
|
|
101
|
+
const node2 = new Element();
|
|
92
102
|
node2.nodeType = this.nodeType;
|
|
93
103
|
this.nodeName = this.nodeName;
|
|
94
104
|
if (this.attributes) {
|
|
@@ -96,6 +106,9 @@ var Node = class _Node {
|
|
|
96
106
|
node2.setAttribute(this.attributes[i].nodeName, this.attributes[i].nodeValue);
|
|
97
107
|
}
|
|
98
108
|
}
|
|
109
|
+
for (const key in this.dataset) {
|
|
110
|
+
node2.dataset[key] = this.dataset[key];
|
|
111
|
+
}
|
|
99
112
|
if (deep) {
|
|
100
113
|
for (let i = 0, l = this.childNodes.length; i < l; i++) {
|
|
101
114
|
node2.appendChild(this.childNodes[i].cloneNode(deep));
|
|
@@ -103,13 +116,13 @@ var Node = class _Node {
|
|
|
103
116
|
}
|
|
104
117
|
return node2;
|
|
105
118
|
}
|
|
106
|
-
|
|
119
|
+
const node = new _Node();
|
|
107
120
|
node.nodeType = this.nodeType;
|
|
108
121
|
node.nodeName = this.nodeName;
|
|
109
122
|
return node;
|
|
110
123
|
}
|
|
111
124
|
setAttribute(name, value) {
|
|
112
|
-
|
|
125
|
+
const attr = {
|
|
113
126
|
nodeName: name,
|
|
114
127
|
nodeValue: value
|
|
115
128
|
};
|
|
@@ -231,8 +244,8 @@ var Text = class extends Node {
|
|
|
231
244
|
};
|
|
232
245
|
function updateElementStyles(element, state) {
|
|
233
246
|
let str = "";
|
|
234
|
-
for (
|
|
235
|
-
|
|
247
|
+
for (const key in state) {
|
|
248
|
+
const value = state[key];
|
|
236
249
|
if (typeof value !== "undefined" && value !== null && String(value).length > 0) {
|
|
237
250
|
str += `${key}: ${state[key]};`;
|
|
238
251
|
}
|
|
@@ -280,26 +293,46 @@ var Element = class extends Node {
|
|
|
280
293
|
}
|
|
281
294
|
throw new Error("Cannot set style");
|
|
282
295
|
}
|
|
296
|
+
get className() {
|
|
297
|
+
return this.getAttribute("class") || "";
|
|
298
|
+
}
|
|
299
|
+
set className(value) {
|
|
300
|
+
if (value == null || value === false) {
|
|
301
|
+
this.removeAttribute("class");
|
|
302
|
+
} else {
|
|
303
|
+
this.setAttribute("class", String(value));
|
|
304
|
+
}
|
|
305
|
+
}
|
|
283
306
|
classList = {
|
|
284
307
|
toggle: (item, force) => {
|
|
285
308
|
if (item) {
|
|
286
|
-
|
|
287
|
-
|
|
309
|
+
const classes = (this.className || "").split(" ");
|
|
310
|
+
const itemIndex = classes.indexOf(item);
|
|
288
311
|
if (force && itemIndex === -1) {
|
|
289
312
|
classes.push(item);
|
|
290
313
|
}
|
|
291
314
|
if (!force && itemIndex !== -1) {
|
|
292
315
|
classes.splice(itemIndex, 1);
|
|
293
316
|
}
|
|
294
|
-
|
|
317
|
+
const final = classes.join(" ").trim();
|
|
295
318
|
if (final.length) {
|
|
296
|
-
this.
|
|
319
|
+
this.className = classes.join(" ").trim();
|
|
297
320
|
} else {
|
|
298
|
-
this.
|
|
321
|
+
this.className = false;
|
|
299
322
|
}
|
|
300
323
|
}
|
|
301
324
|
}
|
|
302
325
|
};
|
|
326
|
+
get id() {
|
|
327
|
+
return this.getAttribute("id") || "";
|
|
328
|
+
}
|
|
329
|
+
set id(value) {
|
|
330
|
+
if (value == null || value === false) {
|
|
331
|
+
this.removeAttribute("id");
|
|
332
|
+
} else {
|
|
333
|
+
this.setAttribute("id", String(value));
|
|
334
|
+
}
|
|
335
|
+
}
|
|
303
336
|
set textContent(text) {
|
|
304
337
|
this.nodeValue = String(text);
|
|
305
338
|
this.childNodes = this.nodeValue ? [new Text(this.nodeValue)] : [];
|
|
@@ -322,7 +355,7 @@ var Element = class extends Node {
|
|
|
322
355
|
}
|
|
323
356
|
set innerHTML(html) {
|
|
324
357
|
this.textContent = "";
|
|
325
|
-
|
|
358
|
+
const result = htmlToDom(html);
|
|
326
359
|
if (result instanceof DocumentFragment) {
|
|
327
360
|
for (let i = 0, l = result.childNodes.length; i < l; i++) {
|
|
328
361
|
this.appendChild(result.childNodes[i]);
|
|
@@ -347,17 +380,19 @@ var Document = class extends Element {
|
|
|
347
380
|
super();
|
|
348
381
|
this.nodeType = 9;
|
|
349
382
|
this.nodeName = "#document";
|
|
383
|
+
this.body = this.createElement("body");
|
|
350
384
|
}
|
|
385
|
+
body;
|
|
351
386
|
createDocumentFragment() {
|
|
352
387
|
return new DocumentFragment();
|
|
353
388
|
}
|
|
354
389
|
createElement(type) {
|
|
355
|
-
|
|
390
|
+
const element = new Element();
|
|
356
391
|
element.nodeName = type.toUpperCase();
|
|
357
392
|
return element;
|
|
358
393
|
}
|
|
359
394
|
createElementNS(ns, type) {
|
|
360
|
-
|
|
395
|
+
const element = this.createElement(type);
|
|
361
396
|
element.baseURI = ns;
|
|
362
397
|
return element;
|
|
363
398
|
}
|
|
@@ -387,7 +422,7 @@ function domToHtml(dom) {
|
|
|
387
422
|
return dom.textContent;
|
|
388
423
|
}
|
|
389
424
|
if (dom.nodeType === 1) {
|
|
390
|
-
|
|
425
|
+
const name = dom.nodeName.toLowerCase();
|
|
391
426
|
let str = "<" + name;
|
|
392
427
|
for (let i = 0, l = dom.attributes.length; i < l; i++) {
|
|
393
428
|
str += " " + dom.attributes[i].nodeName + '="' + dom.attributes[i].nodeValue + '"';
|
|
@@ -396,7 +431,7 @@ function domToHtml(dom) {
|
|
|
396
431
|
str += ">";
|
|
397
432
|
if (dom.childNodes && dom.childNodes.length > 0) {
|
|
398
433
|
for (let i = 0, l = dom.childNodes.length; i < l; i++) {
|
|
399
|
-
|
|
434
|
+
const child = domToHtml(dom.childNodes[i]);
|
|
400
435
|
if (child) {
|
|
401
436
|
str += child;
|
|
402
437
|
}
|
|
@@ -426,9 +461,9 @@ ${spaces}"${item.nodeValue}"`;
|
|
|
426
461
|
let str = `
|
|
427
462
|
${spaces}v("${item.nodeName}", `;
|
|
428
463
|
if (item.attributes) {
|
|
429
|
-
|
|
464
|
+
const attrs = {};
|
|
430
465
|
for (let i = 0, l = item.attributes.length; i < l; i++) {
|
|
431
|
-
|
|
466
|
+
const attr = item.attributes[i];
|
|
432
467
|
attrs[attr.nodeName] = attr.nodeValue;
|
|
433
468
|
}
|
|
434
469
|
str += JSON.stringify(attrs);
|
|
@@ -446,14 +481,14 @@ ${spaces}`;
|
|
|
446
481
|
}).join(",");
|
|
447
482
|
}
|
|
448
483
|
function findTexts(item, html) {
|
|
449
|
-
|
|
484
|
+
const newChildren = [];
|
|
450
485
|
if (item.children.length) {
|
|
451
486
|
for (let i = 0; i < item.children.length; i++) {
|
|
452
|
-
|
|
453
|
-
|
|
487
|
+
const child = item.children[i];
|
|
488
|
+
const nextChild = item.children[i + 1];
|
|
454
489
|
if (i === 0 && child.startsAt > item.contentStartsAt) {
|
|
455
|
-
|
|
456
|
-
|
|
490
|
+
const childContent = html.substring(item.contentStartsAt, child.startsAt);
|
|
491
|
+
const childText = {
|
|
457
492
|
tagName: "#text",
|
|
458
493
|
startsAt: item.contentStartsAt,
|
|
459
494
|
endsAt: item.contentStartsAt + childContent.length,
|
|
@@ -467,8 +502,8 @@ function findTexts(item, html) {
|
|
|
467
502
|
}
|
|
468
503
|
newChildren.push(child);
|
|
469
504
|
if (nextChild && child.endsAt < nextChild.startsAt) {
|
|
470
|
-
|
|
471
|
-
|
|
505
|
+
const childContent = html.substring(child.endsAt, nextChild.startsAt);
|
|
506
|
+
const childText = {
|
|
472
507
|
tagName: "#text",
|
|
473
508
|
startsAt: child.endsAt,
|
|
474
509
|
endsAt: child.endsAt + childContent.length,
|
|
@@ -481,8 +516,8 @@ function findTexts(item, html) {
|
|
|
481
516
|
newChildren.push(childText);
|
|
482
517
|
}
|
|
483
518
|
if (!nextChild && child.endsAt < item.contentEndsAt) {
|
|
484
|
-
|
|
485
|
-
|
|
519
|
+
const childContent = html.substring(child.endsAt, item.contentEndsAt);
|
|
520
|
+
const childText = {
|
|
486
521
|
tagName: "#text",
|
|
487
522
|
startsAt: child.endsAt,
|
|
488
523
|
endsAt: child.endsAt + childContent.length,
|
|
@@ -498,9 +533,9 @@ function findTexts(item, html) {
|
|
|
498
533
|
}
|
|
499
534
|
}
|
|
500
535
|
if (!item.children.length) {
|
|
501
|
-
|
|
536
|
+
const childContent = html.substring(item.contentStartsAt, item.contentEndsAt);
|
|
502
537
|
if (childContent.length) {
|
|
503
|
-
|
|
538
|
+
const childText = {
|
|
504
539
|
tagName: "#text",
|
|
505
540
|
startsAt: item.contentStartsAt,
|
|
506
541
|
endsAt: item.contentEndsAt,
|
|
@@ -521,11 +556,11 @@ function convertToDom(item) {
|
|
|
521
556
|
node = document.createTextNode(item.nodeValue);
|
|
522
557
|
} else {
|
|
523
558
|
node = item.tagName === "#document-fragment" ? document.createDocumentFragment() : document.createElement(item.tagName);
|
|
524
|
-
for (
|
|
559
|
+
for (const key in item.attributes) {
|
|
525
560
|
node.setAttribute(key, item.attributes[key]);
|
|
526
561
|
}
|
|
527
562
|
for (let i = 0; i < item.children.length; i++) {
|
|
528
|
-
|
|
563
|
+
const child = convertToDom(item.children[i]);
|
|
529
564
|
node.appendChild(child);
|
|
530
565
|
}
|
|
531
566
|
}
|
|
@@ -533,24 +568,24 @@ function convertToDom(item) {
|
|
|
533
568
|
}
|
|
534
569
|
function getObjectIndexTree(html) {
|
|
535
570
|
let item;
|
|
536
|
-
|
|
537
|
-
|
|
571
|
+
const regex = RegExp("<([^>|^!]+)>", "g");
|
|
572
|
+
const items = [];
|
|
538
573
|
while (item = regex.exec(html)) {
|
|
539
574
|
if (item[0].startsWith("</")) {
|
|
540
|
-
|
|
575
|
+
const lastOpenedItem = [...items].reverse().find((item2) => item2.endsAt === null);
|
|
541
576
|
if (lastOpenedItem) {
|
|
542
577
|
lastOpenedItem.endsAt = item.index + item[0].length;
|
|
543
578
|
lastOpenedItem.contentEndsAt = item.index;
|
|
544
|
-
|
|
579
|
+
const parent = [...items].reverse().find((item2) => item2.endsAt === null);
|
|
545
580
|
if (parent) {
|
|
546
|
-
|
|
581
|
+
const index = items.indexOf(lastOpenedItem);
|
|
547
582
|
items.splice(index, 1);
|
|
548
583
|
parent.children.push(lastOpenedItem);
|
|
549
584
|
}
|
|
550
585
|
}
|
|
551
586
|
continue;
|
|
552
587
|
}
|
|
553
|
-
|
|
588
|
+
const element = {
|
|
554
589
|
tagName: item[1].split(" ")[0],
|
|
555
590
|
startsAt: item.index,
|
|
556
591
|
endsAt: null,
|
|
@@ -561,9 +596,9 @@ function getObjectIndexTree(html) {
|
|
|
561
596
|
nodeValue: null
|
|
562
597
|
};
|
|
563
598
|
let string = (item[1] || "").substring(element.tagName.length + 1).replace(/\/$/g, "");
|
|
564
|
-
|
|
599
|
+
const attributesWithValues = string.match(/\S+="[^"]+"/g);
|
|
565
600
|
if (attributesWithValues) {
|
|
566
|
-
for (
|
|
601
|
+
for (const attribute of attributesWithValues) {
|
|
567
602
|
const [name, ...value] = attribute.trim().split("=");
|
|
568
603
|
string = string.replace(attribute, "");
|
|
569
604
|
if (value) {
|
|
@@ -571,9 +606,9 @@ function getObjectIndexTree(html) {
|
|
|
571
606
|
}
|
|
572
607
|
}
|
|
573
608
|
}
|
|
574
|
-
|
|
609
|
+
const attributesWithBooleanValues = string.match(/\s\S+=[^"]+/g);
|
|
575
610
|
if (attributesWithBooleanValues) {
|
|
576
|
-
for (
|
|
611
|
+
for (const attribute of attributesWithBooleanValues) {
|
|
577
612
|
const [name, ...value] = attribute.trim().split("=");
|
|
578
613
|
string = string.replace(attribute, "");
|
|
579
614
|
if (value) {
|
|
@@ -581,9 +616,9 @@ function getObjectIndexTree(html) {
|
|
|
581
616
|
}
|
|
582
617
|
}
|
|
583
618
|
}
|
|
584
|
-
|
|
619
|
+
const attributesWithEmptyValues = string.match(/\s?\S+/g);
|
|
585
620
|
if (attributesWithEmptyValues) {
|
|
586
|
-
for (
|
|
621
|
+
for (const attribute of attributesWithEmptyValues) {
|
|
587
622
|
const name = attribute.trim();
|
|
588
623
|
element.attributes[name] = true;
|
|
589
624
|
}
|
|
@@ -591,7 +626,7 @@ function getObjectIndexTree(html) {
|
|
|
591
626
|
if (item[0].endsWith("/>")) {
|
|
592
627
|
element.endsAt = element.startsAt + item[0].length;
|
|
593
628
|
element.contentStartsAt = element.contentEndsAt = element.endsAt;
|
|
594
|
-
|
|
629
|
+
const parent = [...items].reverse().find((item2) => item2.endsAt === null);
|
|
595
630
|
if (parent) {
|
|
596
631
|
parent.children.push(element);
|
|
597
632
|
continue;
|
|
@@ -599,7 +634,7 @@ function getObjectIndexTree(html) {
|
|
|
599
634
|
}
|
|
600
635
|
items.push(element);
|
|
601
636
|
}
|
|
602
|
-
|
|
637
|
+
const fragmentItem = {
|
|
603
638
|
tagName: "#document-fragment",
|
|
604
639
|
startsAt: 0,
|
|
605
640
|
endsAt: html.length,
|
|
@@ -614,21 +649,21 @@ function getObjectIndexTree(html) {
|
|
|
614
649
|
}
|
|
615
650
|
function htmlToDom(html) {
|
|
616
651
|
const openingTag = html.match(/<[^>]+>/g);
|
|
617
|
-
|
|
652
|
+
const document2 = new Document();
|
|
618
653
|
if (!openingTag) {
|
|
619
|
-
|
|
654
|
+
const documentFragment = document2.createDocumentFragment();
|
|
620
655
|
documentFragment.appendChild(document2.createTextNode(html));
|
|
621
656
|
return documentFragment;
|
|
622
657
|
}
|
|
623
|
-
|
|
658
|
+
const fragment = getObjectIndexTree(html);
|
|
624
659
|
if (fragment.childNodes.length > 1) {
|
|
625
660
|
return fragment;
|
|
626
661
|
}
|
|
627
662
|
return fragment.childNodes[0];
|
|
628
663
|
}
|
|
629
664
|
function htmlToHyperscript(html) {
|
|
630
|
-
|
|
631
|
-
|
|
665
|
+
const domTree = htmlToDom(html);
|
|
666
|
+
const hyperscript = domToHyperscript(domTree instanceof DocumentFragment ? domTree.childNodes : [domTree]);
|
|
632
667
|
return `[${hyperscript}
|
|
633
668
|
]`;
|
|
634
669
|
}
|
|
@@ -641,7 +676,7 @@ import FormData from "form-data";
|
|
|
641
676
|
// lib/node/utils/icons.ts
|
|
642
677
|
import fs from "fs";
|
|
643
678
|
async function icons(source, configuration) {
|
|
644
|
-
|
|
679
|
+
const options = {
|
|
645
680
|
...icons.options,
|
|
646
681
|
...configuration || {}
|
|
647
682
|
};
|
|
@@ -653,17 +688,17 @@ async function icons(source, configuration) {
|
|
|
653
688
|
}
|
|
654
689
|
const { favicons } = await import("favicons");
|
|
655
690
|
try {
|
|
656
|
-
|
|
691
|
+
const response = await favicons(source, options);
|
|
657
692
|
if (options.iconsPath) {
|
|
658
|
-
for (
|
|
693
|
+
for (const i in response.images) {
|
|
659
694
|
fs.writeFileSync(options.iconsPath + response.images[i].name, response.images[i].contents);
|
|
660
695
|
}
|
|
661
|
-
for (
|
|
696
|
+
for (const i in response.files) {
|
|
662
697
|
fs.writeFileSync(options.iconsPath + response.files[i].name, response.files[i].contents);
|
|
663
698
|
}
|
|
664
699
|
}
|
|
665
700
|
if (options.linksViewPath) {
|
|
666
|
-
|
|
701
|
+
const html = `
|
|
667
702
|
function Links(){
|
|
668
703
|
return ${htmlToHyperscript(response.html.join(""))};
|
|
669
704
|
}
|
|
@@ -718,12 +753,12 @@ import esbuild from "esbuild";
|
|
|
718
753
|
import fs2 from "fs";
|
|
719
754
|
async function inline(file, options = {}) {
|
|
720
755
|
if (typeof file === "string") {
|
|
721
|
-
|
|
756
|
+
const ext = file.split(".").pop();
|
|
722
757
|
if (ext && /(js|cjs|jsx|mjs|ts|tsx)/.test(ext)) {
|
|
723
758
|
if (/(ts|tsx)/.test(ext) && !options.noValidate) {
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
759
|
+
const declarationDir = options.declarationDir;
|
|
760
|
+
const emitDeclaration = !!declarationDir;
|
|
761
|
+
const tscProgOptions = {
|
|
727
762
|
basePath: process.cwd(),
|
|
728
763
|
// always required, used for relative paths
|
|
729
764
|
configFilePath: "tsconfig.json",
|
|
@@ -756,7 +791,7 @@ async function inline(file, options = {}) {
|
|
|
756
791
|
console.log("tsc", tscProgOptions);
|
|
757
792
|
tsc.build(tscProgOptions);
|
|
758
793
|
}
|
|
759
|
-
|
|
794
|
+
const esbuildOptions = {
|
|
760
795
|
entryPoints: [file],
|
|
761
796
|
bundle: "bundle" in options ? options.bundle : true,
|
|
762
797
|
sourcemap: "external",
|
|
@@ -774,13 +809,13 @@ async function inline(file, options = {}) {
|
|
|
774
809
|
},
|
|
775
810
|
...options.esbuild || {}
|
|
776
811
|
};
|
|
777
|
-
|
|
812
|
+
const result = await esbuild.build(esbuildOptions);
|
|
778
813
|
if (result.outputFiles?.length !== 2) {
|
|
779
814
|
throw new Error(result.errors.join("\n"));
|
|
780
815
|
}
|
|
781
816
|
if (options.compact) {
|
|
782
817
|
const terser = await import("terser");
|
|
783
|
-
|
|
818
|
+
const result2 = await terser.minify(result.outputFiles[1].text, {
|
|
784
819
|
sourceMap: {
|
|
785
820
|
content: result.outputFiles[0].text.toString()
|
|
786
821
|
},
|
|
@@ -796,16 +831,16 @@ async function inline(file, options = {}) {
|
|
|
796
831
|
if (!result2.code || !result2.map) {
|
|
797
832
|
throw new Error("Unknown error");
|
|
798
833
|
}
|
|
799
|
-
|
|
800
|
-
|
|
834
|
+
const mapBase64 = Buffer.from(result2.map.toString()).toString("base64");
|
|
835
|
+
const suffix = `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${mapBase64}`;
|
|
801
836
|
return { raw: result2.code, map: suffix, file };
|
|
802
837
|
} else {
|
|
803
|
-
|
|
804
|
-
|
|
838
|
+
const mapBase64 = Buffer.from(result.outputFiles[0].text.toString()).toString("base64");
|
|
839
|
+
const suffix = `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${mapBase64}`;
|
|
805
840
|
return { raw: result.outputFiles[1].text, map: suffix, file };
|
|
806
841
|
}
|
|
807
842
|
} else if (ext && /(css|scss|styl)/.test(ext)) {
|
|
808
|
-
|
|
843
|
+
const result = await new CleanCSS({
|
|
809
844
|
sourceMap: true,
|
|
810
845
|
level: {
|
|
811
846
|
1: {
|
|
@@ -827,15 +862,15 @@ async function inline(file, options = {}) {
|
|
|
827
862
|
}
|
|
828
863
|
}
|
|
829
864
|
inline.uncss = async function(renderedHtml, css, options = {}) {
|
|
830
|
-
|
|
831
|
-
|
|
865
|
+
const html = await Promise.all(renderedHtml);
|
|
866
|
+
const contents = html.map((item) => {
|
|
832
867
|
return {
|
|
833
868
|
raw: item,
|
|
834
869
|
extension: "html"
|
|
835
870
|
};
|
|
836
871
|
});
|
|
837
|
-
|
|
838
|
-
|
|
872
|
+
const purgecss = new PurgeCSS();
|
|
873
|
+
const output = await purgecss.purge({
|
|
839
874
|
fontFace: true,
|
|
840
875
|
keyframes: true,
|
|
841
876
|
variables: true,
|
|
@@ -844,7 +879,7 @@ inline.uncss = async function(renderedHtml, css, options = {}) {
|
|
|
844
879
|
content: contents,
|
|
845
880
|
css: [{ raw: css }]
|
|
846
881
|
});
|
|
847
|
-
|
|
882
|
+
const cleanCss = await new CleanCSS({
|
|
848
883
|
sourceMap: false,
|
|
849
884
|
level: {
|
|
850
885
|
1: {
|
|
@@ -864,17 +899,15 @@ inline.uncss = async function(renderedHtml, css, options = {}) {
|
|
|
864
899
|
import fs3 from "fs";
|
|
865
900
|
import path from "path";
|
|
866
901
|
function sw(file, options = {}) {
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
options
|
|
877
|
-
);
|
|
902
|
+
const swfiletemplate = path.resolve(__dirname, "./node.sw.js");
|
|
903
|
+
const swTpl = fs3.readFileSync(swfiletemplate, "utf8");
|
|
904
|
+
const opt = {
|
|
905
|
+
version: "v1::",
|
|
906
|
+
name: "Valyrian.js",
|
|
907
|
+
urls: ["/"],
|
|
908
|
+
debug: false,
|
|
909
|
+
...options
|
|
910
|
+
};
|
|
878
911
|
let contents = swTpl.replace("v1::", "v" + opt.version + "::").replace("Valyrian.js", opt.name).replace("['/']", '["' + opt.urls.join('","') + '"]');
|
|
879
912
|
if (!opt.debug) {
|
|
880
913
|
contents = contents.replace("console.log", "() => {}");
|
|
@@ -882,12 +915,116 @@ function sw(file, options = {}) {
|
|
|
882
915
|
fs3.writeFileSync(file, contents, "utf8");
|
|
883
916
|
}
|
|
884
917
|
|
|
918
|
+
// lib/node/utils/session-storage.ts
|
|
919
|
+
import fs4 from "fs";
|
|
920
|
+
import path2 from "path";
|
|
921
|
+
var SessionStorage = class {
|
|
922
|
+
storage;
|
|
923
|
+
limit;
|
|
924
|
+
persist;
|
|
925
|
+
filePath;
|
|
926
|
+
directory = ".session-storage";
|
|
927
|
+
constructor({ persist = false, filePath = "./sessionData.json" } = {}) {
|
|
928
|
+
this.storage = {};
|
|
929
|
+
this.limit = 5 * 1024 * 1024;
|
|
930
|
+
this.persist = persist;
|
|
931
|
+
this.filePath = path2.resolve(this.directory, filePath);
|
|
932
|
+
if (!fs4.existsSync(this.directory)) {
|
|
933
|
+
fs4.mkdirSync(this.directory, { recursive: true });
|
|
934
|
+
}
|
|
935
|
+
if (this.persist) {
|
|
936
|
+
this.loadFromFile();
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
// Calculate total size in bytes of stored data
|
|
940
|
+
getStorageSize() {
|
|
941
|
+
return new TextEncoder().encode(JSON.stringify(this.storage)).length;
|
|
942
|
+
}
|
|
943
|
+
// Check if storage limit is exceeded
|
|
944
|
+
checkSizeLimit() {
|
|
945
|
+
const size = this.getStorageSize();
|
|
946
|
+
if (size > this.limit) {
|
|
947
|
+
throw new DOMException("Storage limit exceeded", "QuotaExceededError");
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
// Store value under the specified key
|
|
951
|
+
setItem(key, value) {
|
|
952
|
+
if (key === null || key === void 0) {
|
|
953
|
+
throw new TypeError("Failed to execute 'setItem' on 'Storage': 1 argument required, but only 0 present.");
|
|
954
|
+
}
|
|
955
|
+
if (value === null) {
|
|
956
|
+
value = "null";
|
|
957
|
+
} else if (value === void 0) {
|
|
958
|
+
value = "undefined";
|
|
959
|
+
}
|
|
960
|
+
this.storage[key] = String(value);
|
|
961
|
+
this.checkSizeLimit();
|
|
962
|
+
if (this.persist) {
|
|
963
|
+
this.saveToFile();
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
// Retrieve value stored under the specified key
|
|
967
|
+
getItem(key) {
|
|
968
|
+
if (key === null || key === void 0) {
|
|
969
|
+
throw new TypeError("Failed to execute 'getItem' on 'Storage': 1 argument required, but only 0 present.");
|
|
970
|
+
}
|
|
971
|
+
return this.storage[key] || null;
|
|
972
|
+
}
|
|
973
|
+
// Remove the value under the specified key
|
|
974
|
+
removeItem(key) {
|
|
975
|
+
if (key === null || key === void 0) {
|
|
976
|
+
throw new TypeError("Failed to execute 'removeItem' on 'Storage': 1 argument required, but only 0 present.");
|
|
977
|
+
}
|
|
978
|
+
delete this.storage[key];
|
|
979
|
+
if (this.persist) {
|
|
980
|
+
this.saveToFile();
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
// Clear all stored values
|
|
984
|
+
clear() {
|
|
985
|
+
this.storage = {};
|
|
986
|
+
if (this.persist) {
|
|
987
|
+
this.saveToFile();
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
// Return the number of stored items
|
|
991
|
+
get length() {
|
|
992
|
+
return Object.keys(this.storage).length;
|
|
993
|
+
}
|
|
994
|
+
// Return the key at the specified index
|
|
995
|
+
key(index) {
|
|
996
|
+
const keys = Object.keys(this.storage);
|
|
997
|
+
return keys[index] || null;
|
|
998
|
+
}
|
|
999
|
+
// Save data to a file (only if persistence is enabled)
|
|
1000
|
+
saveToFile() {
|
|
1001
|
+
try {
|
|
1002
|
+
fs4.writeFileSync(this.filePath, JSON.stringify(this.storage), "utf-8");
|
|
1003
|
+
} catch (error) {
|
|
1004
|
+
throw new Error(`Error saving data to file: ${error.message}`);
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
// Load data from a file (only if persistence is enabled)
|
|
1008
|
+
loadFromFile() {
|
|
1009
|
+
try {
|
|
1010
|
+
if (fs4.existsSync(this.filePath)) {
|
|
1011
|
+
const data = fs4.readFileSync(this.filePath, "utf-8");
|
|
1012
|
+
this.storage = JSON.parse(data || "{}");
|
|
1013
|
+
}
|
|
1014
|
+
} catch (error) {
|
|
1015
|
+
throw new Error(`Error loading data from file: ${error.message}`);
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
};
|
|
1019
|
+
|
|
885
1020
|
// lib/node/index.ts
|
|
886
1021
|
global.FormData = FormData;
|
|
887
1022
|
global.document = document;
|
|
1023
|
+
global.sessionStorage = new SessionStorage();
|
|
1024
|
+
global.localStorage = new SessionStorage();
|
|
888
1025
|
function render(...args) {
|
|
889
|
-
|
|
890
|
-
|
|
1026
|
+
const Component = () => args;
|
|
1027
|
+
const result = mount("div", Component);
|
|
891
1028
|
unmount();
|
|
892
1029
|
return result;
|
|
893
1030
|
}
|