@pi-r/chrome 0.6.6 → 0.6.7
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/index.js +40 -26
- package/package.json +5 -5
package/index.js
CHANGED
|
@@ -297,7 +297,7 @@ function hasSameOrigin(value, ...other) {
|
|
|
297
297
|
return false;
|
|
298
298
|
}
|
|
299
299
|
function restoreSearchParams(value, prefix = '__sqd') {
|
|
300
|
-
if (value
|
|
300
|
+
if (value === null || value === void 0 ? void 0 : value.includes(prefix)) {
|
|
301
301
|
const params = new URLSearchParams(value);
|
|
302
302
|
params.forEach((_, key) => key.startsWith(prefix) && params.delete(key));
|
|
303
303
|
if (value = params.toString()) {
|
|
@@ -385,6 +385,7 @@ function getSrcURL(parent, file) {
|
|
|
385
385
|
return [found ? joinPath('../'.repeat(prefix.length), suffix.join('/'), file.filename) : '../'.repeat(prefix.length) + relativeUrl];
|
|
386
386
|
}
|
|
387
387
|
function transformURL(host, parent, type, source, importFile) {
|
|
388
|
+
var _a;
|
|
388
389
|
const related = [];
|
|
389
390
|
const baseHref = getBaseURLs(importFile || parent, this.baseUrl);
|
|
390
391
|
const isHtml = type === 'html';
|
|
@@ -471,12 +472,13 @@ function transformURL(host, parent, type, source, importFile) {
|
|
|
471
472
|
}
|
|
472
473
|
}
|
|
473
474
|
const setOutputURL = (value, asset) => {
|
|
475
|
+
var _a;
|
|
474
476
|
if (!value) {
|
|
475
477
|
return;
|
|
476
478
|
}
|
|
477
479
|
if (asset) {
|
|
478
480
|
if (!asset.inlineBase64) {
|
|
479
|
-
if (host.Cloud
|
|
481
|
+
if ((_a = host.Cloud) === null || _a === void 0 ? void 0 : _a.getStorage('upload', asset.cloudStorage)) {
|
|
480
482
|
const inlineUrlCloud = asset.inlineUrlCloud || (asset.inlineUrlCloud = (0, types_1.generateUUID)());
|
|
481
483
|
(parent.inlineUrlCloudMap || (parent.inlineUrlCloudMap = {}))[inlineUrlCloud] = value;
|
|
482
484
|
value = inlineUrlCloud;
|
|
@@ -557,7 +559,7 @@ function transformURL(host, parent, type, source, importFile) {
|
|
|
557
559
|
url = trimQuote(content);
|
|
558
560
|
}
|
|
559
561
|
if (url.startsWith('data:')) {
|
|
560
|
-
const base64 = url.split(',')[1]
|
|
562
|
+
const base64 = (_a = url.split(',')[1]) === null || _a === void 0 ? void 0 : _a.trim();
|
|
561
563
|
if (base64) {
|
|
562
564
|
for (const item of this.assets) {
|
|
563
565
|
if (item.base64 === base64) {
|
|
@@ -776,7 +778,7 @@ function transformJs(host, file, output) {
|
|
|
776
778
|
this.writeFail(["Unable to write file", path.basename(chunkUri)], err, 32);
|
|
777
779
|
}
|
|
778
780
|
}
|
|
779
|
-
appending
|
|
781
|
+
appending === null || appending === void 0 ? void 0 : appending.forEach(item => item.order += order);
|
|
780
782
|
}
|
|
781
783
|
if ((0, types_1.isArray)(sourceFiles)) {
|
|
782
784
|
file.sourceFiles = sourceFiles;
|
|
@@ -897,7 +899,7 @@ const isIgnored = (item, exists) => item.invalid || (0, types_1.ignoreFlag)(item
|
|
|
897
899
|
const findFont = (value) => value && (Array.isArray(value) ? value : [value]).find(format => isFont(format));
|
|
898
900
|
const spliceString = (source, startIndex, endIndex, content) => source.substring(0, startIndex) + content + source.substring(endIndex);
|
|
899
901
|
const getEndIndex = (match) => match.index + match[0].length;
|
|
900
|
-
const getRelativeURL = (file) => joinPath(file.moveTo, file.pathname, file.inlineFilename || file.filename) + (!file.static ? restoreSearchParams(file.url
|
|
902
|
+
const getRelativeURL = (file) => { var _a; return joinPath(file.moveTo, file.pathname, file.inlineFilename || file.filename) + (!file.static ? restoreSearchParams((_a = file.url) === null || _a === void 0 ? void 0 : _a.search) : ''); };
|
|
901
903
|
const errorHtml = ({ tagName, tagIndex = -1 }) => (0, types_1.errorMessage)('html', 'Location did not resolve', tagName.toLowerCase() + (tagIndex >= 0 ? ': ' + tagIndex : ''));
|
|
902
904
|
const errorDataSource = (value, hint) => (0, types_1.errorMessage)('data-source', value, hint);
|
|
903
905
|
class ChromeDocument extends Document {
|
|
@@ -975,6 +977,7 @@ class ChromeDocument extends Document {
|
|
|
975
977
|
return result + (parent && result > 0 ? await super.purgeMemory(typeof parent === 'number' && parent > 0 ? parent : percent, limit, true) : 0);
|
|
976
978
|
}
|
|
977
979
|
static async finalize(instance) {
|
|
980
|
+
var _a;
|
|
978
981
|
if (instance.aborted) {
|
|
979
982
|
return Promise.reject((0, types_1.createAbortError)());
|
|
980
983
|
}
|
|
@@ -986,7 +989,7 @@ class ChromeDocument extends Document {
|
|
|
986
989
|
db.writeTimeElapsed('DB', ["Transactions were committed", db.moduleName], processing.startTime, { ...Document.LOG_STYLE_SUCCESS, type: 65536 });
|
|
987
990
|
}
|
|
988
991
|
if (instance.dataSource.length === 0 && outHtml) {
|
|
989
|
-
const incremental = htmlFile.incremental
|
|
992
|
+
const incremental = (_a = htmlFile.incremental) !== null && _a !== void 0 ? _a : this.incremental;
|
|
990
993
|
if (incremental === 'etag' || incremental === 'exists') {
|
|
991
994
|
const fetched = this.fetchedAssets;
|
|
992
995
|
const isHtmlOnly = () => !fetched.find(item => item !== htmlFile && assets.includes(item));
|
|
@@ -1582,6 +1585,7 @@ class ChromeDocument extends Document {
|
|
|
1582
1585
|
}
|
|
1583
1586
|
resolveImports(file, code, baseFile) {
|
|
1584
1587
|
var _a;
|
|
1588
|
+
var _b;
|
|
1585
1589
|
if (!Array.isArray(file.imports)) {
|
|
1586
1590
|
return;
|
|
1587
1591
|
}
|
|
@@ -1597,7 +1601,7 @@ class ChromeDocument extends Document {
|
|
|
1597
1601
|
}
|
|
1598
1602
|
const importMap = {};
|
|
1599
1603
|
for (const item of file.imports) {
|
|
1600
|
-
(importMap[
|
|
1604
|
+
(importMap[_b = item.placeholder] || (importMap[_b] = [])).push(item);
|
|
1601
1605
|
}
|
|
1602
1606
|
for (const placeholder in importMap) {
|
|
1603
1607
|
const items = importMap[placeholder];
|
|
@@ -1609,7 +1613,7 @@ class ChromeDocument extends Document {
|
|
|
1609
1613
|
const hosted = type === 'css';
|
|
1610
1614
|
let value;
|
|
1611
1615
|
if (hosted) {
|
|
1612
|
-
const asset = this.host
|
|
1616
|
+
const asset = (_a = this.host) === null || _a === void 0 ? void 0 : _a.findAsset(uri);
|
|
1613
1617
|
if (asset) {
|
|
1614
1618
|
const [relativeUrl, sameDir] = getSrcURL.call(this, bundleMain || file, asset);
|
|
1615
1619
|
if (relativeUrl) {
|
|
@@ -1638,12 +1642,13 @@ class ChromeDocument extends Document {
|
|
|
1638
1642
|
}
|
|
1639
1643
|
}
|
|
1640
1644
|
replaceContent(source, statement, mimeType) {
|
|
1645
|
+
var _a;
|
|
1641
1646
|
switch (mimeType) {
|
|
1642
1647
|
case 'text/css': {
|
|
1643
1648
|
const match = REGEXP_REPLACECSS.exec((typeof statement === 'string' ? statement : statement[0]).trim());
|
|
1644
1649
|
if (match) {
|
|
1645
1650
|
const layer = match[1];
|
|
1646
|
-
const supports = match[3]
|
|
1651
|
+
const supports = (_a = match[3]) === null || _a === void 0 ? void 0 : _a.trim();
|
|
1647
1652
|
const query = match[4].trim();
|
|
1648
1653
|
if (layer || supports || query) {
|
|
1649
1654
|
const newline = (0, util_1.getNewline)(source);
|
|
@@ -1680,8 +1685,9 @@ class ChromeDocument extends Document {
|
|
|
1680
1685
|
}
|
|
1681
1686
|
}
|
|
1682
1687
|
writeImage(data) {
|
|
1688
|
+
var _a;
|
|
1683
1689
|
const { file, output, command } = data;
|
|
1684
|
-
if (output && command && file.element
|
|
1690
|
+
if (output && command && ((_a = file.element) === null || _a === void 0 ? void 0 : _a.outerXml)) {
|
|
1685
1691
|
const match = REGEXP_SRCSETSIZE.exec(command);
|
|
1686
1692
|
if (match) {
|
|
1687
1693
|
(file.srcSet || (file.srcSet = [])).push(toPosix(data.baseDirectory ? output.substring(data.baseDirectory.length + 1) : output), match[1] + match[2].toLowerCase());
|
|
@@ -1692,12 +1698,13 @@ class ChromeDocument extends Document {
|
|
|
1692
1698
|
return false;
|
|
1693
1699
|
}
|
|
1694
1700
|
cloudInit({ instance }) {
|
|
1701
|
+
var _a, _b;
|
|
1695
1702
|
this._cloudUrlMap = Object.create(null);
|
|
1696
1703
|
this._cloudUploaded = new Set();
|
|
1697
1704
|
this._cloudEndpoint = null;
|
|
1698
1705
|
const htmlFile = this.htmlFile;
|
|
1699
1706
|
if (htmlFile) {
|
|
1700
|
-
const endpoint = instance.getStorage('upload', htmlFile.cloudStorage)
|
|
1707
|
+
const endpoint = (_b = (_a = instance.getStorage('upload', htmlFile.cloudStorage)) === null || _a === void 0 ? void 0 : _a.upload) === null || _b === void 0 ? void 0 : _b.endpoint;
|
|
1701
1708
|
if (endpoint) {
|
|
1702
1709
|
this._cloudEndpoint = new RegExp((0, types_1.escapePattern)(toPosix(endpoint)) + '/', 'g');
|
|
1703
1710
|
}
|
|
@@ -1710,6 +1717,7 @@ class ChromeDocument extends Document {
|
|
|
1710
1717
|
return this.editing.includes(file);
|
|
1711
1718
|
}
|
|
1712
1719
|
async cloudUpload({ host }, file, url, active) {
|
|
1720
|
+
var _a;
|
|
1713
1721
|
if (active) {
|
|
1714
1722
|
const endpoint = this._cloudEndpoint;
|
|
1715
1723
|
const inlineUrlCloud = file.inlineUrlCloud;
|
|
@@ -1718,7 +1726,7 @@ class ChromeDocument extends Document {
|
|
|
1718
1726
|
if (inlineUrlCloud) {
|
|
1719
1727
|
const pattern = new RegExp((0, types_1.escapePattern)(inlineUrlCloud), 'g');
|
|
1720
1728
|
for (const item of this.editing) {
|
|
1721
|
-
if (item.inlineUrlCloudMap
|
|
1729
|
+
if ((_a = item.inlineUrlCloudMap) === null || _a === void 0 ? void 0 : _a[inlineUrlCloud]) {
|
|
1722
1730
|
const source = host.getUTF8String(item);
|
|
1723
1731
|
const output = source.replace(pattern, endpoint && item.imported && cloudUrl.includes('/') ? url : cloudUrl);
|
|
1724
1732
|
if (source !== output) {
|
|
@@ -1733,6 +1741,7 @@ class ChromeDocument extends Document {
|
|
|
1733
1741
|
return false;
|
|
1734
1742
|
}
|
|
1735
1743
|
async cloudFinalize(state) {
|
|
1744
|
+
var _a;
|
|
1736
1745
|
if (this.aborted) {
|
|
1737
1746
|
return Promise.reject((0, types_1.createAbortError)());
|
|
1738
1747
|
}
|
|
@@ -1781,7 +1790,7 @@ class ChromeDocument extends Document {
|
|
|
1781
1790
|
for (const storage of cloudStorage) {
|
|
1782
1791
|
if (instance.hasCredential('storage', storage)) {
|
|
1783
1792
|
const { service, admin, bucket, upload } = storage;
|
|
1784
|
-
const website = admin
|
|
1793
|
+
const website = (_a = admin === null || admin === void 0 ? void 0 : admin.configBucket) === null || _a === void 0 ? void 0 : _a.website;
|
|
1785
1794
|
if ((0, types_1.isPlainObject)(website) && bucket && upload) {
|
|
1786
1795
|
let filename = joinPath(upload.pathname, upload.filename || path.basename(htmlFile.localUri));
|
|
1787
1796
|
if (website.indexPage === true) {
|
|
@@ -1817,7 +1826,7 @@ class ChromeDocument extends Document {
|
|
|
1817
1826
|
}
|
|
1818
1827
|
const main = watch.main;
|
|
1819
1828
|
let result;
|
|
1820
|
-
if (main
|
|
1829
|
+
if ((main === null || main === void 0 ? void 0 : main.editing) && main.mimeType === 'text/html') {
|
|
1821
1830
|
const inlineUrlCloudMap = main.inlineUrlCloudMap || {};
|
|
1822
1831
|
const using = [];
|
|
1823
1832
|
let found;
|
|
@@ -1854,6 +1863,7 @@ class ChromeDocument extends Document {
|
|
|
1854
1863
|
}
|
|
1855
1864
|
watchModified(watch, assets) {
|
|
1856
1865
|
return (files, errors, status) => {
|
|
1866
|
+
var _a;
|
|
1857
1867
|
if (!watch.server || watch.captured || watch.aborted) {
|
|
1858
1868
|
return;
|
|
1859
1869
|
}
|
|
@@ -1873,7 +1883,7 @@ class ChromeDocument extends Document {
|
|
|
1873
1883
|
search = next.url.search;
|
|
1874
1884
|
}
|
|
1875
1885
|
}
|
|
1876
|
-
search
|
|
1886
|
+
search !== null && search !== void 0 ? search : (search = restoreSearchParams((_a = asset.url) === null || _a === void 0 ? void 0 : _a.search));
|
|
1877
1887
|
status && (status = status.filter(item => item.type >= types_1.STATUS_TYPE.FATAL && item.type <= types_1.STATUS_TYPE.WARN));
|
|
1878
1888
|
watch.send(types_1.WATCH_EVENT.MODIFIED, {
|
|
1879
1889
|
action: pathname && watch.hot && !watch.main ? 'hot' : '',
|
|
@@ -1945,11 +1955,13 @@ class ChromeDocument extends Document {
|
|
|
1945
1955
|
}
|
|
1946
1956
|
}
|
|
1947
1957
|
findDataValue(name) {
|
|
1958
|
+
var _a;
|
|
1948
1959
|
if (this.hasEval('template')) {
|
|
1949
|
-
return this.templateMap.data
|
|
1960
|
+
return (_a = this.templateMap.data) === null || _a === void 0 ? void 0 : _a[name];
|
|
1950
1961
|
}
|
|
1951
1962
|
}
|
|
1952
1963
|
setInlinedAttributes({ host, startTime, hashed, contentMap, bufferMap, productionRelease }) {
|
|
1964
|
+
var _a, _b;
|
|
1953
1965
|
const readBase64 = (item, uuid) => {
|
|
1954
1966
|
if (!contentMap[uuid]) {
|
|
1955
1967
|
try {
|
|
@@ -1979,7 +1991,7 @@ class ChromeDocument extends Document {
|
|
|
1979
1991
|
const filename = hash && createHash(host, item, hash, bufferMap);
|
|
1980
1992
|
if (filename) {
|
|
1981
1993
|
for (const asset of this.assets) {
|
|
1982
|
-
const url = inlineUrl ? asset.inlineUrlMap
|
|
1994
|
+
const url = inlineUrl ? (_a = asset.inlineUrlMap) === null || _a === void 0 ? void 0 : _a[inlineUrl] : (_b = asset.inlineUrlCloudMap) === null || _b === void 0 ? void 0 : _b[inlineUrlCloud];
|
|
1983
1995
|
if (url) {
|
|
1984
1996
|
const search = url.indexOf('?');
|
|
1985
1997
|
const index = (search !== -1 ? url.substring(0, search) : url).lastIndexOf('/');
|
|
@@ -2027,10 +2039,10 @@ class ChromeDocument extends Document {
|
|
|
2027
2039
|
const sortNested = (a, b) => {
|
|
2028
2040
|
const { inlineUrlCloud: urlA, inlineUrlCloudMap: mapA } = a;
|
|
2029
2041
|
const { inlineUrlCloud: urlB, inlineUrlCloudMap: mapB } = b;
|
|
2030
|
-
if (urlA && mapB
|
|
2042
|
+
if (urlA && (mapB === null || mapB === void 0 ? void 0 : mapB[urlA])) {
|
|
2031
2043
|
return -1;
|
|
2032
2044
|
}
|
|
2033
|
-
if (urlB && mapA
|
|
2045
|
+
if (urlB && (mapA === null || mapA === void 0 ? void 0 : mapA[urlB])) {
|
|
2034
2046
|
return 1;
|
|
2035
2047
|
}
|
|
2036
2048
|
return 0;
|
|
@@ -2260,7 +2272,7 @@ class ChromeDocument extends Document {
|
|
|
2260
2272
|
}
|
|
2261
2273
|
}
|
|
2262
2274
|
if (uri && !(0, util_1.hasValue)(item.format, 'crossorigin') && item !== htmlFile) {
|
|
2263
|
-
if (cloud
|
|
2275
|
+
if (cloud === null || cloud === void 0 ? void 0 : cloud.getStorage('upload', item.cloudStorage)) {
|
|
2264
2276
|
const inlineUrlCloud = item.inlineUrlCloud || (item.inlineUrlCloud = (0, types_1.generateUUID)());
|
|
2265
2277
|
((_a = htmlFile).inlineUrlCloudMap || (_a.inlineUrlCloudMap = {}))[inlineUrlCloud] = productionRelease ? this.removeServerRoot(uri) : uri;
|
|
2266
2278
|
uri = inlineUrlCloud;
|
|
@@ -2432,7 +2444,7 @@ class ChromeDocument extends Document {
|
|
|
2432
2444
|
batchGroup.push([item]);
|
|
2433
2445
|
break;
|
|
2434
2446
|
default:
|
|
2435
|
-
if (db
|
|
2447
|
+
if (db === null || db === void 0 ? void 0 : db.hasSource(type)) {
|
|
2436
2448
|
try {
|
|
2437
2449
|
await db.setCredential(item);
|
|
2438
2450
|
const credential = item.credential;
|
|
@@ -2465,6 +2477,7 @@ class ChromeDocument extends Document {
|
|
|
2465
2477
|
}
|
|
2466
2478
|
return this.allSettled(batchGroup.map(async (batch) => {
|
|
2467
2479
|
return new Promise(async (resolve, reject) => {
|
|
2480
|
+
var _a, _b, _c;
|
|
2468
2481
|
const errorRemove = (item, reason) => {
|
|
2469
2482
|
removeElement(item);
|
|
2470
2483
|
reject(reason);
|
|
@@ -2531,7 +2544,7 @@ class ChromeDocument extends Document {
|
|
|
2531
2544
|
}
|
|
2532
2545
|
else {
|
|
2533
2546
|
this.abort(type);
|
|
2534
|
-
errorRemove(current, target ? errorDataSource('Not found', target) : errorDataSource('Not defined - ' + (this.settings.directory
|
|
2547
|
+
errorRemove(current, target ? errorDataSource('Not found', target) : errorDataSource('Not defined - ' + (((_a = this.settings.directory) === null || _a === void 0 ? void 0 : _a.data) ? 'file' : 'directory'), type));
|
|
2535
2548
|
return;
|
|
2536
2549
|
}
|
|
2537
2550
|
}
|
|
@@ -2677,7 +2690,7 @@ class ChromeDocument extends Document {
|
|
|
2677
2690
|
}
|
|
2678
2691
|
if (!getData) {
|
|
2679
2692
|
const { settings, encoding, persist = true } = current;
|
|
2680
|
-
target || (target = settings && this.settings.export
|
|
2693
|
+
target || (target = settings && ((_b = this.settings.export) === null || _b === void 0 ? void 0 : _b[settings]) || pathname);
|
|
2681
2694
|
if (typeof target === 'function') {
|
|
2682
2695
|
getData = target;
|
|
2683
2696
|
hint = target.name;
|
|
@@ -2736,7 +2749,7 @@ class ChromeDocument extends Document {
|
|
|
2736
2749
|
break;
|
|
2737
2750
|
}
|
|
2738
2751
|
default:
|
|
2739
|
-
if (db
|
|
2752
|
+
if (db === null || db === void 0 ? void 0 : db.hasSource(type)) {
|
|
2740
2753
|
switch (type) {
|
|
2741
2754
|
case 'mongodb':
|
|
2742
2755
|
for (let j = 0; j < length; ++j) {
|
|
@@ -2960,7 +2973,7 @@ class ChromeDocument extends Document {
|
|
|
2960
2973
|
for (let j = 0, match; j < items.length; ++j) {
|
|
2961
2974
|
const row = items[j];
|
|
2962
2975
|
if ((0, types_1.isPlainObject)(row)) {
|
|
2963
|
-
row.__index__
|
|
2976
|
+
(_c = row.__index__) !== null && _c !== void 0 ? _c : (row.__index__ = j + 1);
|
|
2964
2977
|
}
|
|
2965
2978
|
let segment = template;
|
|
2966
2979
|
while (match = REGEXP_TEMPLATECONDITIONAL.exec(segment)) {
|
|
@@ -3253,6 +3266,7 @@ class ChromeDocument extends Document {
|
|
|
3253
3266
|
}
|
|
3254
3267
|
}
|
|
3255
3268
|
setProductionAttributes({ host, hashed, bufferMap, startTime }) {
|
|
3269
|
+
var _a;
|
|
3256
3270
|
for (const item of this.assets) {
|
|
3257
3271
|
if (isIgnored(item, true)) {
|
|
3258
3272
|
continue;
|
|
@@ -3260,7 +3274,7 @@ class ChromeDocument extends Document {
|
|
|
3260
3274
|
if (item.hash && !hashed.has(item)) {
|
|
3261
3275
|
createHash(host, item, item.hash, bufferMap);
|
|
3262
3276
|
}
|
|
3263
|
-
switch (item.element
|
|
3277
|
+
switch ((_a = item.element) === null || _a === void 0 ? void 0 : _a.tagName.toLowerCase()) {
|
|
3264
3278
|
case 'style':
|
|
3265
3279
|
if (!item.content) {
|
|
3266
3280
|
break;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/chrome",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.7",
|
|
4
4
|
"description": "Chrome document constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/cloud": "^0.8.
|
|
24
|
-
"@e-mc/core": "^0.8.
|
|
25
|
-
"@e-mc/document": "^0.8.
|
|
26
|
-
"@e-mc/types": "^0.8.
|
|
23
|
+
"@e-mc/cloud": "^0.8.8",
|
|
24
|
+
"@e-mc/core": "^0.8.8",
|
|
25
|
+
"@e-mc/document": "^0.8.8",
|
|
26
|
+
"@e-mc/types": "^0.8.8"
|
|
27
27
|
}
|
|
28
28
|
}
|