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/dist/node/index.mjs
CHANGED
|
@@ -48,24 +48,28 @@ var Node = class _Node {
|
|
|
48
48
|
constructor() {
|
|
49
49
|
}
|
|
50
50
|
appendChild(node) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
if (node) {
|
|
52
|
+
node.parentNode && node.parentNode.removeChild(node);
|
|
53
|
+
this.childNodes.push(node);
|
|
54
|
+
node.parentNode = this;
|
|
55
|
+
}
|
|
54
56
|
return node;
|
|
55
57
|
}
|
|
56
58
|
insertBefore(node, child) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
if (node) {
|
|
60
|
+
node.parentNode && node.parentNode.removeChild(node);
|
|
61
|
+
node.parentNode = this;
|
|
62
|
+
if (child) {
|
|
63
|
+
const idx = this.childNodes.indexOf(child);
|
|
64
|
+
this.childNodes.splice(idx, 0, node);
|
|
65
|
+
} else {
|
|
66
|
+
this.childNodes.push(node);
|
|
67
|
+
}
|
|
64
68
|
}
|
|
65
69
|
return node;
|
|
66
70
|
}
|
|
67
71
|
replaceChild(node, child) {
|
|
68
|
-
if (child && child.parentNode === this) {
|
|
72
|
+
if (node && child && child.parentNode === this) {
|
|
69
73
|
this.insertBefore(node, child);
|
|
70
74
|
child.parentNode && child.parentNode.removeChild(child);
|
|
71
75
|
}
|
|
@@ -73,18 +77,21 @@ var Node = class _Node {
|
|
|
73
77
|
}
|
|
74
78
|
removeChild(child) {
|
|
75
79
|
if (child && child.parentNode === this) {
|
|
76
|
-
|
|
80
|
+
const idx = this.childNodes.indexOf(child);
|
|
77
81
|
this.childNodes.splice(idx, 1);
|
|
78
82
|
child.parentNode = null;
|
|
79
83
|
}
|
|
80
84
|
return child;
|
|
81
85
|
}
|
|
86
|
+
remove() {
|
|
87
|
+
return this.parentNode ? this.parentNode.removeChild(this) : this;
|
|
88
|
+
}
|
|
82
89
|
cloneNode(deep) {
|
|
83
90
|
if (this.nodeType === 3) {
|
|
84
91
|
return new Text(this.nodeValue);
|
|
85
92
|
}
|
|
86
93
|
if (this.nodeType === 1) {
|
|
87
|
-
|
|
94
|
+
const node2 = new Element();
|
|
88
95
|
node2.nodeType = this.nodeType;
|
|
89
96
|
this.nodeName = this.nodeName;
|
|
90
97
|
if (this.attributes) {
|
|
@@ -99,13 +106,13 @@ var Node = class _Node {
|
|
|
99
106
|
}
|
|
100
107
|
return node2;
|
|
101
108
|
}
|
|
102
|
-
|
|
109
|
+
const node = new _Node();
|
|
103
110
|
node.nodeType = this.nodeType;
|
|
104
111
|
node.nodeName = this.nodeName;
|
|
105
112
|
return node;
|
|
106
113
|
}
|
|
107
114
|
setAttribute(name, value) {
|
|
108
|
-
|
|
115
|
+
const attr = {
|
|
109
116
|
nodeName: name,
|
|
110
117
|
nodeValue: value
|
|
111
118
|
};
|
|
@@ -227,8 +234,8 @@ var Text = class extends Node {
|
|
|
227
234
|
};
|
|
228
235
|
function updateElementStyles(element, state) {
|
|
229
236
|
let str = "";
|
|
230
|
-
for (
|
|
231
|
-
|
|
237
|
+
for (const key in state) {
|
|
238
|
+
const value = state[key];
|
|
232
239
|
if (typeof value !== "undefined" && value !== null && String(value).length > 0) {
|
|
233
240
|
str += `${key}: ${state[key]};`;
|
|
234
241
|
}
|
|
@@ -276,26 +283,46 @@ var Element = class extends Node {
|
|
|
276
283
|
}
|
|
277
284
|
throw new Error("Cannot set style");
|
|
278
285
|
}
|
|
286
|
+
get className() {
|
|
287
|
+
return this.getAttribute("class") || "";
|
|
288
|
+
}
|
|
289
|
+
set className(value) {
|
|
290
|
+
if (value == null || value === false) {
|
|
291
|
+
this.removeAttribute("class");
|
|
292
|
+
} else {
|
|
293
|
+
this.setAttribute("class", String(value));
|
|
294
|
+
}
|
|
295
|
+
}
|
|
279
296
|
classList = {
|
|
280
297
|
toggle: (item, force) => {
|
|
281
298
|
if (item) {
|
|
282
|
-
|
|
283
|
-
|
|
299
|
+
const classes = (this.className || "").split(" ");
|
|
300
|
+
const itemIndex = classes.indexOf(item);
|
|
284
301
|
if (force && itemIndex === -1) {
|
|
285
302
|
classes.push(item);
|
|
286
303
|
}
|
|
287
304
|
if (!force && itemIndex !== -1) {
|
|
288
305
|
classes.splice(itemIndex, 1);
|
|
289
306
|
}
|
|
290
|
-
|
|
307
|
+
const final = classes.join(" ").trim();
|
|
291
308
|
if (final.length) {
|
|
292
|
-
this.
|
|
309
|
+
this.className = classes.join(" ").trim();
|
|
293
310
|
} else {
|
|
294
|
-
this.
|
|
311
|
+
this.className = false;
|
|
295
312
|
}
|
|
296
313
|
}
|
|
297
314
|
}
|
|
298
315
|
};
|
|
316
|
+
get id() {
|
|
317
|
+
return this.getAttribute("id") || "";
|
|
318
|
+
}
|
|
319
|
+
set id(value) {
|
|
320
|
+
if (value == null || value === false) {
|
|
321
|
+
this.removeAttribute("id");
|
|
322
|
+
} else {
|
|
323
|
+
this.setAttribute("id", String(value));
|
|
324
|
+
}
|
|
325
|
+
}
|
|
299
326
|
set textContent(text) {
|
|
300
327
|
this.nodeValue = String(text);
|
|
301
328
|
this.childNodes = this.nodeValue ? [new Text(this.nodeValue)] : [];
|
|
@@ -318,7 +345,7 @@ var Element = class extends Node {
|
|
|
318
345
|
}
|
|
319
346
|
set innerHTML(html) {
|
|
320
347
|
this.textContent = "";
|
|
321
|
-
|
|
348
|
+
const result = htmlToDom(html);
|
|
322
349
|
if (result instanceof DocumentFragment) {
|
|
323
350
|
for (let i = 0, l = result.childNodes.length; i < l; i++) {
|
|
324
351
|
this.appendChild(result.childNodes[i]);
|
|
@@ -348,12 +375,12 @@ var Document = class extends Element {
|
|
|
348
375
|
return new DocumentFragment();
|
|
349
376
|
}
|
|
350
377
|
createElement(type) {
|
|
351
|
-
|
|
378
|
+
const element = new Element();
|
|
352
379
|
element.nodeName = type.toUpperCase();
|
|
353
380
|
return element;
|
|
354
381
|
}
|
|
355
382
|
createElementNS(ns, type) {
|
|
356
|
-
|
|
383
|
+
const element = this.createElement(type);
|
|
357
384
|
element.baseURI = ns;
|
|
358
385
|
return element;
|
|
359
386
|
}
|
|
@@ -383,7 +410,7 @@ function domToHtml(dom) {
|
|
|
383
410
|
return dom.textContent;
|
|
384
411
|
}
|
|
385
412
|
if (dom.nodeType === 1) {
|
|
386
|
-
|
|
413
|
+
const name = dom.nodeName.toLowerCase();
|
|
387
414
|
let str = "<" + name;
|
|
388
415
|
for (let i = 0, l = dom.attributes.length; i < l; i++) {
|
|
389
416
|
str += " " + dom.attributes[i].nodeName + '="' + dom.attributes[i].nodeValue + '"';
|
|
@@ -392,7 +419,7 @@ function domToHtml(dom) {
|
|
|
392
419
|
str += ">";
|
|
393
420
|
if (dom.childNodes && dom.childNodes.length > 0) {
|
|
394
421
|
for (let i = 0, l = dom.childNodes.length; i < l; i++) {
|
|
395
|
-
|
|
422
|
+
const child = domToHtml(dom.childNodes[i]);
|
|
396
423
|
if (child) {
|
|
397
424
|
str += child;
|
|
398
425
|
}
|
|
@@ -422,9 +449,9 @@ ${spaces}"${item.nodeValue}"`;
|
|
|
422
449
|
let str = `
|
|
423
450
|
${spaces}v("${item.nodeName}", `;
|
|
424
451
|
if (item.attributes) {
|
|
425
|
-
|
|
452
|
+
const attrs = {};
|
|
426
453
|
for (let i = 0, l = item.attributes.length; i < l; i++) {
|
|
427
|
-
|
|
454
|
+
const attr = item.attributes[i];
|
|
428
455
|
attrs[attr.nodeName] = attr.nodeValue;
|
|
429
456
|
}
|
|
430
457
|
str += JSON.stringify(attrs);
|
|
@@ -442,14 +469,14 @@ ${spaces}`;
|
|
|
442
469
|
}).join(",");
|
|
443
470
|
}
|
|
444
471
|
function findTexts(item, html) {
|
|
445
|
-
|
|
472
|
+
const newChildren = [];
|
|
446
473
|
if (item.children.length) {
|
|
447
474
|
for (let i = 0; i < item.children.length; i++) {
|
|
448
|
-
|
|
449
|
-
|
|
475
|
+
const child = item.children[i];
|
|
476
|
+
const nextChild = item.children[i + 1];
|
|
450
477
|
if (i === 0 && child.startsAt > item.contentStartsAt) {
|
|
451
|
-
|
|
452
|
-
|
|
478
|
+
const childContent = html.substring(item.contentStartsAt, child.startsAt);
|
|
479
|
+
const childText = {
|
|
453
480
|
tagName: "#text",
|
|
454
481
|
startsAt: item.contentStartsAt,
|
|
455
482
|
endsAt: item.contentStartsAt + childContent.length,
|
|
@@ -463,8 +490,8 @@ function findTexts(item, html) {
|
|
|
463
490
|
}
|
|
464
491
|
newChildren.push(child);
|
|
465
492
|
if (nextChild && child.endsAt < nextChild.startsAt) {
|
|
466
|
-
|
|
467
|
-
|
|
493
|
+
const childContent = html.substring(child.endsAt, nextChild.startsAt);
|
|
494
|
+
const childText = {
|
|
468
495
|
tagName: "#text",
|
|
469
496
|
startsAt: child.endsAt,
|
|
470
497
|
endsAt: child.endsAt + childContent.length,
|
|
@@ -477,8 +504,8 @@ function findTexts(item, html) {
|
|
|
477
504
|
newChildren.push(childText);
|
|
478
505
|
}
|
|
479
506
|
if (!nextChild && child.endsAt < item.contentEndsAt) {
|
|
480
|
-
|
|
481
|
-
|
|
507
|
+
const childContent = html.substring(child.endsAt, item.contentEndsAt);
|
|
508
|
+
const childText = {
|
|
482
509
|
tagName: "#text",
|
|
483
510
|
startsAt: child.endsAt,
|
|
484
511
|
endsAt: child.endsAt + childContent.length,
|
|
@@ -494,9 +521,9 @@ function findTexts(item, html) {
|
|
|
494
521
|
}
|
|
495
522
|
}
|
|
496
523
|
if (!item.children.length) {
|
|
497
|
-
|
|
524
|
+
const childContent = html.substring(item.contentStartsAt, item.contentEndsAt);
|
|
498
525
|
if (childContent.length) {
|
|
499
|
-
|
|
526
|
+
const childText = {
|
|
500
527
|
tagName: "#text",
|
|
501
528
|
startsAt: item.contentStartsAt,
|
|
502
529
|
endsAt: item.contentEndsAt,
|
|
@@ -517,11 +544,11 @@ function convertToDom(item) {
|
|
|
517
544
|
node = document.createTextNode(item.nodeValue);
|
|
518
545
|
} else {
|
|
519
546
|
node = item.tagName === "#document-fragment" ? document.createDocumentFragment() : document.createElement(item.tagName);
|
|
520
|
-
for (
|
|
547
|
+
for (const key in item.attributes) {
|
|
521
548
|
node.setAttribute(key, item.attributes[key]);
|
|
522
549
|
}
|
|
523
550
|
for (let i = 0; i < item.children.length; i++) {
|
|
524
|
-
|
|
551
|
+
const child = convertToDom(item.children[i]);
|
|
525
552
|
node.appendChild(child);
|
|
526
553
|
}
|
|
527
554
|
}
|
|
@@ -529,24 +556,24 @@ function convertToDom(item) {
|
|
|
529
556
|
}
|
|
530
557
|
function getObjectIndexTree(html) {
|
|
531
558
|
let item;
|
|
532
|
-
|
|
533
|
-
|
|
559
|
+
const regex = RegExp("<([^>|^!]+)>", "g");
|
|
560
|
+
const items = [];
|
|
534
561
|
while (item = regex.exec(html)) {
|
|
535
562
|
if (item[0].startsWith("</")) {
|
|
536
|
-
|
|
563
|
+
const lastOpenedItem = [...items].reverse().find((item2) => item2.endsAt === null);
|
|
537
564
|
if (lastOpenedItem) {
|
|
538
565
|
lastOpenedItem.endsAt = item.index + item[0].length;
|
|
539
566
|
lastOpenedItem.contentEndsAt = item.index;
|
|
540
|
-
|
|
567
|
+
const parent = [...items].reverse().find((item2) => item2.endsAt === null);
|
|
541
568
|
if (parent) {
|
|
542
|
-
|
|
569
|
+
const index = items.indexOf(lastOpenedItem);
|
|
543
570
|
items.splice(index, 1);
|
|
544
571
|
parent.children.push(lastOpenedItem);
|
|
545
572
|
}
|
|
546
573
|
}
|
|
547
574
|
continue;
|
|
548
575
|
}
|
|
549
|
-
|
|
576
|
+
const element = {
|
|
550
577
|
tagName: item[1].split(" ")[0],
|
|
551
578
|
startsAt: item.index,
|
|
552
579
|
endsAt: null,
|
|
@@ -557,9 +584,9 @@ function getObjectIndexTree(html) {
|
|
|
557
584
|
nodeValue: null
|
|
558
585
|
};
|
|
559
586
|
let string = (item[1] || "").substring(element.tagName.length + 1).replace(/\/$/g, "");
|
|
560
|
-
|
|
587
|
+
const attributesWithValues = string.match(/\S+="[^"]+"/g);
|
|
561
588
|
if (attributesWithValues) {
|
|
562
|
-
for (
|
|
589
|
+
for (const attribute of attributesWithValues) {
|
|
563
590
|
const [name, ...value] = attribute.trim().split("=");
|
|
564
591
|
string = string.replace(attribute, "");
|
|
565
592
|
if (value) {
|
|
@@ -567,9 +594,9 @@ function getObjectIndexTree(html) {
|
|
|
567
594
|
}
|
|
568
595
|
}
|
|
569
596
|
}
|
|
570
|
-
|
|
597
|
+
const attributesWithBooleanValues = string.match(/\s\S+=[^"]+/g);
|
|
571
598
|
if (attributesWithBooleanValues) {
|
|
572
|
-
for (
|
|
599
|
+
for (const attribute of attributesWithBooleanValues) {
|
|
573
600
|
const [name, ...value] = attribute.trim().split("=");
|
|
574
601
|
string = string.replace(attribute, "");
|
|
575
602
|
if (value) {
|
|
@@ -577,9 +604,9 @@ function getObjectIndexTree(html) {
|
|
|
577
604
|
}
|
|
578
605
|
}
|
|
579
606
|
}
|
|
580
|
-
|
|
607
|
+
const attributesWithEmptyValues = string.match(/\s?\S+/g);
|
|
581
608
|
if (attributesWithEmptyValues) {
|
|
582
|
-
for (
|
|
609
|
+
for (const attribute of attributesWithEmptyValues) {
|
|
583
610
|
const name = attribute.trim();
|
|
584
611
|
element.attributes[name] = true;
|
|
585
612
|
}
|
|
@@ -587,7 +614,7 @@ function getObjectIndexTree(html) {
|
|
|
587
614
|
if (item[0].endsWith("/>")) {
|
|
588
615
|
element.endsAt = element.startsAt + item[0].length;
|
|
589
616
|
element.contentStartsAt = element.contentEndsAt = element.endsAt;
|
|
590
|
-
|
|
617
|
+
const parent = [...items].reverse().find((item2) => item2.endsAt === null);
|
|
591
618
|
if (parent) {
|
|
592
619
|
parent.children.push(element);
|
|
593
620
|
continue;
|
|
@@ -595,7 +622,7 @@ function getObjectIndexTree(html) {
|
|
|
595
622
|
}
|
|
596
623
|
items.push(element);
|
|
597
624
|
}
|
|
598
|
-
|
|
625
|
+
const fragmentItem = {
|
|
599
626
|
tagName: "#document-fragment",
|
|
600
627
|
startsAt: 0,
|
|
601
628
|
endsAt: html.length,
|
|
@@ -610,21 +637,21 @@ function getObjectIndexTree(html) {
|
|
|
610
637
|
}
|
|
611
638
|
function htmlToDom(html) {
|
|
612
639
|
const openingTag = html.match(/<[^>]+>/g);
|
|
613
|
-
|
|
640
|
+
const document2 = new Document();
|
|
614
641
|
if (!openingTag) {
|
|
615
|
-
|
|
642
|
+
const documentFragment = document2.createDocumentFragment();
|
|
616
643
|
documentFragment.appendChild(document2.createTextNode(html));
|
|
617
644
|
return documentFragment;
|
|
618
645
|
}
|
|
619
|
-
|
|
646
|
+
const fragment = getObjectIndexTree(html);
|
|
620
647
|
if (fragment.childNodes.length > 1) {
|
|
621
648
|
return fragment;
|
|
622
649
|
}
|
|
623
650
|
return fragment.childNodes[0];
|
|
624
651
|
}
|
|
625
652
|
function htmlToHyperscript(html) {
|
|
626
|
-
|
|
627
|
-
|
|
653
|
+
const domTree = htmlToDom(html);
|
|
654
|
+
const hyperscript = domToHyperscript(domTree instanceof DocumentFragment ? domTree.childNodes : [domTree]);
|
|
628
655
|
return `[${hyperscript}
|
|
629
656
|
]`;
|
|
630
657
|
}
|
|
@@ -637,7 +664,7 @@ import FormData from "form-data";
|
|
|
637
664
|
// lib/node/utils/icons.ts
|
|
638
665
|
import fs from "fs";
|
|
639
666
|
async function icons(source, configuration) {
|
|
640
|
-
|
|
667
|
+
const options = {
|
|
641
668
|
...icons.options,
|
|
642
669
|
...configuration || {}
|
|
643
670
|
};
|
|
@@ -649,17 +676,17 @@ async function icons(source, configuration) {
|
|
|
649
676
|
}
|
|
650
677
|
const { favicons } = await import("favicons");
|
|
651
678
|
try {
|
|
652
|
-
|
|
679
|
+
const response = await favicons(source, options);
|
|
653
680
|
if (options.iconsPath) {
|
|
654
|
-
for (
|
|
681
|
+
for (const i in response.images) {
|
|
655
682
|
fs.writeFileSync(options.iconsPath + response.images[i].name, response.images[i].contents);
|
|
656
683
|
}
|
|
657
|
-
for (
|
|
684
|
+
for (const i in response.files) {
|
|
658
685
|
fs.writeFileSync(options.iconsPath + response.files[i].name, response.files[i].contents);
|
|
659
686
|
}
|
|
660
687
|
}
|
|
661
688
|
if (options.linksViewPath) {
|
|
662
|
-
|
|
689
|
+
const html = `
|
|
663
690
|
function Links(){
|
|
664
691
|
return ${htmlToHyperscript(response.html.join(""))};
|
|
665
692
|
}
|
|
@@ -714,12 +741,12 @@ import esbuild from "esbuild";
|
|
|
714
741
|
import fs2 from "fs";
|
|
715
742
|
async function inline(file, options = {}) {
|
|
716
743
|
if (typeof file === "string") {
|
|
717
|
-
|
|
744
|
+
const ext = file.split(".").pop();
|
|
718
745
|
if (ext && /(js|cjs|jsx|mjs|ts|tsx)/.test(ext)) {
|
|
719
746
|
if (/(ts|tsx)/.test(ext) && !options.noValidate) {
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
747
|
+
const declarationDir = options.declarationDir;
|
|
748
|
+
const emitDeclaration = !!declarationDir;
|
|
749
|
+
const tscProgOptions = {
|
|
723
750
|
basePath: process.cwd(),
|
|
724
751
|
// always required, used for relative paths
|
|
725
752
|
configFilePath: "tsconfig.json",
|
|
@@ -752,7 +779,7 @@ async function inline(file, options = {}) {
|
|
|
752
779
|
console.log("tsc", tscProgOptions);
|
|
753
780
|
tsc.build(tscProgOptions);
|
|
754
781
|
}
|
|
755
|
-
|
|
782
|
+
const esbuildOptions = {
|
|
756
783
|
entryPoints: [file],
|
|
757
784
|
bundle: "bundle" in options ? options.bundle : true,
|
|
758
785
|
sourcemap: "external",
|
|
@@ -770,13 +797,13 @@ async function inline(file, options = {}) {
|
|
|
770
797
|
},
|
|
771
798
|
...options.esbuild || {}
|
|
772
799
|
};
|
|
773
|
-
|
|
800
|
+
const result = await esbuild.build(esbuildOptions);
|
|
774
801
|
if (result.outputFiles?.length !== 2) {
|
|
775
802
|
throw new Error(result.errors.join("\n"));
|
|
776
803
|
}
|
|
777
804
|
if (options.compact) {
|
|
778
805
|
const terser = await import("terser");
|
|
779
|
-
|
|
806
|
+
const result2 = await terser.minify(result.outputFiles[1].text, {
|
|
780
807
|
sourceMap: {
|
|
781
808
|
content: result.outputFiles[0].text.toString()
|
|
782
809
|
},
|
|
@@ -792,16 +819,16 @@ async function inline(file, options = {}) {
|
|
|
792
819
|
if (!result2.code || !result2.map) {
|
|
793
820
|
throw new Error("Unknown error");
|
|
794
821
|
}
|
|
795
|
-
|
|
796
|
-
|
|
822
|
+
const mapBase64 = Buffer.from(result2.map.toString()).toString("base64");
|
|
823
|
+
const suffix = `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${mapBase64}`;
|
|
797
824
|
return { raw: result2.code, map: suffix, file };
|
|
798
825
|
} else {
|
|
799
|
-
|
|
800
|
-
|
|
826
|
+
const mapBase64 = Buffer.from(result.outputFiles[0].text.toString()).toString("base64");
|
|
827
|
+
const suffix = `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${mapBase64}`;
|
|
801
828
|
return { raw: result.outputFiles[1].text, map: suffix, file };
|
|
802
829
|
}
|
|
803
830
|
} else if (ext && /(css|scss|styl)/.test(ext)) {
|
|
804
|
-
|
|
831
|
+
const result = await new CleanCSS({
|
|
805
832
|
sourceMap: true,
|
|
806
833
|
level: {
|
|
807
834
|
1: {
|
|
@@ -823,15 +850,15 @@ async function inline(file, options = {}) {
|
|
|
823
850
|
}
|
|
824
851
|
}
|
|
825
852
|
inline.uncss = async function(renderedHtml, css, options = {}) {
|
|
826
|
-
|
|
827
|
-
|
|
853
|
+
const html = await Promise.all(renderedHtml);
|
|
854
|
+
const contents = html.map((item) => {
|
|
828
855
|
return {
|
|
829
856
|
raw: item,
|
|
830
857
|
extension: "html"
|
|
831
858
|
};
|
|
832
859
|
});
|
|
833
|
-
|
|
834
|
-
|
|
860
|
+
const purgecss = new PurgeCSS();
|
|
861
|
+
const output = await purgecss.purge({
|
|
835
862
|
fontFace: true,
|
|
836
863
|
keyframes: true,
|
|
837
864
|
variables: true,
|
|
@@ -840,7 +867,7 @@ inline.uncss = async function(renderedHtml, css, options = {}) {
|
|
|
840
867
|
content: contents,
|
|
841
868
|
css: [{ raw: css }]
|
|
842
869
|
});
|
|
843
|
-
|
|
870
|
+
const cleanCss = await new CleanCSS({
|
|
844
871
|
sourceMap: false,
|
|
845
872
|
level: {
|
|
846
873
|
1: {
|
|
@@ -860,9 +887,9 @@ inline.uncss = async function(renderedHtml, css, options = {}) {
|
|
|
860
887
|
import fs3 from "fs";
|
|
861
888
|
import path from "path";
|
|
862
889
|
function sw(file, options = {}) {
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
890
|
+
const swfiletemplate = path.resolve(__dirname, "./node.sw.tpl");
|
|
891
|
+
const swTpl = fs3.readFileSync(swfiletemplate, "utf8");
|
|
892
|
+
const opt = Object.assign(
|
|
866
893
|
{
|
|
867
894
|
version: "v1::",
|
|
868
895
|
name: "Valyrian.js",
|
|
@@ -882,8 +909,8 @@ function sw(file, options = {}) {
|
|
|
882
909
|
global.FormData = FormData;
|
|
883
910
|
global.document = document;
|
|
884
911
|
function render(...args) {
|
|
885
|
-
|
|
886
|
-
|
|
912
|
+
const Component = () => args;
|
|
913
|
+
const result = mount("div", Component);
|
|
887
914
|
unmount();
|
|
888
915
|
return result;
|
|
889
916
|
}
|