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