@pi-r/chrome 0.10.2 → 0.11.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/index.js +42 -44
- package/package.json +5 -5
- package/types/index.d.ts +1 -0
package/index.js
CHANGED
|
@@ -148,7 +148,7 @@ function findClosingIndex(source, lastIndex, char) {
|
|
|
148
148
|
return [endIndex, trailing];
|
|
149
149
|
}
|
|
150
150
|
function getPackageName(err) {
|
|
151
|
-
if (
|
|
151
|
+
if ((0, types_1.isErrorCode)(err, types_1.ERR_CODE.MODULE_NOT_FOUND)) {
|
|
152
152
|
return (0, util_1.getModuleName)(err);
|
|
153
153
|
}
|
|
154
154
|
}
|
|
@@ -393,40 +393,6 @@ function createHash(host, file, hash, bufferMap) {
|
|
|
393
393
|
host.writeFail(["Unable to read file", filename], err, 32);
|
|
394
394
|
}
|
|
395
395
|
}
|
|
396
|
-
function getSrcUrl(instance, parent, file) {
|
|
397
|
-
const relativeUrl = file.relativeUrl || instance.host.removeCwd(file.localUri) && getRelativeUrl(file);
|
|
398
|
-
if (!relativeUrl) {
|
|
399
|
-
return ['', false];
|
|
400
|
-
}
|
|
401
|
-
if (parent.inlineContent) {
|
|
402
|
-
return [relativeUrl, false];
|
|
403
|
-
}
|
|
404
|
-
let parentDir = parent.pathname, assetDir = file.pathname;
|
|
405
|
-
if (!instance.productionRelease) {
|
|
406
|
-
if (parent.moveTo) {
|
|
407
|
-
parentDir = Document.joinPath(parent.moveTo, parentDir);
|
|
408
|
-
}
|
|
409
|
-
if (file.moveTo) {
|
|
410
|
-
assetDir = Document.joinPath(file.moveTo, assetDir);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
if (parentDir === assetDir) {
|
|
414
|
-
return [file.filename, true];
|
|
415
|
-
}
|
|
416
|
-
if (!parentDir) {
|
|
417
|
-
return [relativeUrl, false];
|
|
418
|
-
}
|
|
419
|
-
const splitPath = (value) => value.split(/\//).filter(seg => seg.trim());
|
|
420
|
-
const prefix = splitPath(parentDir);
|
|
421
|
-
const suffix = splitPath(assetDir);
|
|
422
|
-
let found = false;
|
|
423
|
-
while (prefix.length > 0 && suffix.length > 0 && prefix[0] === suffix[0]) {
|
|
424
|
-
prefix.shift();
|
|
425
|
-
suffix.shift();
|
|
426
|
-
found = true;
|
|
427
|
-
}
|
|
428
|
-
return [found ? Document.joinPath('../'.repeat(prefix.length), suffix.join('/'), file.filename) : '../'.repeat(prefix.length) + relativeUrl, false];
|
|
429
|
-
}
|
|
430
396
|
function replaceCss(instance, file) {
|
|
431
397
|
if (file.inlineUrlMap) {
|
|
432
398
|
sanitizeCss(instance, file.inlineUrlMap);
|
|
@@ -747,7 +713,7 @@ class ChromeDocument extends Document {
|
|
|
747
713
|
if (i !== start && !Document.createDir(destDir = path.join(destDir, ...subDir.slice(i, start)))) {
|
|
748
714
|
throw (0, types_1.errorMessage)('production', destDir, 'create');
|
|
749
715
|
}
|
|
750
|
-
const dest = path.join(destDir, subDir
|
|
716
|
+
const dest = path.join(destDir, subDir.at(-1));
|
|
751
717
|
Document.renameFile(src, dest);
|
|
752
718
|
instance.addLog(4, `production: ${dest} (mapped)`, { source: subDir.join(path.sep) });
|
|
753
719
|
emptyDir.add(path.dirname(src));
|
|
@@ -1283,7 +1249,7 @@ class ChromeDocument extends Document {
|
|
|
1283
1249
|
try {
|
|
1284
1250
|
const asset = host.findAsset(relative ? new URL(from, uri) : from);
|
|
1285
1251
|
if (asset) {
|
|
1286
|
-
const [relativeUrl, sameDir] = getSrcUrl(
|
|
1252
|
+
const [relativeUrl, sameDir] = this.getSrcUrl(bundleMain || file, asset);
|
|
1287
1253
|
if (relativeUrl) {
|
|
1288
1254
|
output = (0, util_1.spliceString)(output, a, b, quote + (sameDir ? './' : '') + relativeUrl + quote, REGEXP_IMPORTMODULE);
|
|
1289
1255
|
}
|
|
@@ -1381,7 +1347,7 @@ class ChromeDocument extends Document {
|
|
|
1381
1347
|
if (hosted) {
|
|
1382
1348
|
const asset = this.host?.findAsset(uri);
|
|
1383
1349
|
if (asset) {
|
|
1384
|
-
const [relativeUrl, sameDir] = getSrcUrl(
|
|
1350
|
+
const [relativeUrl, sameDir] = this.getSrcUrl(bundleMain || file, asset);
|
|
1385
1351
|
if (relativeUrl) {
|
|
1386
1352
|
value = (sameDir ? './' : '') + relativeUrl;
|
|
1387
1353
|
}
|
|
@@ -2067,9 +2033,7 @@ class ChromeDocument extends Document {
|
|
|
2067
2033
|
const detectHeight = domElement.getAttribute('height') === 'detect';
|
|
2068
2034
|
if (detectWidth || detectHeight) {
|
|
2069
2035
|
let width = 0, height = 0, buffer = null;
|
|
2070
|
-
const addLog = (suffix, err) => {
|
|
2071
|
-
this.addLog(3, err instanceof Error ? err : 'Could not detect image ' + suffix, { source: item.localUri ? path.basename(item.localUri) : item.filename });
|
|
2072
|
-
};
|
|
2036
|
+
const addLog = (suffix, err) => this.addLog(3, err || ('Not detectable image ' + suffix), { source: item.localUri ? path.basename(item.localUri) : item.filename });
|
|
2073
2037
|
if (isImage(item.mimeType) && (buffer = host.getBuffer(item))) {
|
|
2074
2038
|
try {
|
|
2075
2039
|
({ width, height } = (0, image_size_1.imageSize)(buffer));
|
|
@@ -2974,7 +2938,7 @@ class ChromeDocument extends Document {
|
|
|
2974
2938
|
case 'cloud': {
|
|
2975
2939
|
const { service, table, id, query } = item;
|
|
2976
2940
|
const queryString = (table ? 'table=' + table : '') + (id || query ? (table ? ';' : '') + (id ? 'id=' + id : 'query=' + Document.asString(query)) : '');
|
|
2977
|
-
(cloud || this).formatFail(64, service, ["Unable to execute query", queryString], emptyResponse(queryString, service),
|
|
2941
|
+
(cloud || this).formatFail(64, service, ["Unable to execute query", queryString], emptyResponse(queryString, service), Cloud.optionsLogMessage('FAIL', { startTime }));
|
|
2978
2942
|
break;
|
|
2979
2943
|
}
|
|
2980
2944
|
case 'uri': {
|
|
@@ -3446,6 +3410,40 @@ class ChromeDocument extends Document {
|
|
|
3446
3410
|
return current;
|
|
3447
3411
|
}
|
|
3448
3412
|
}
|
|
3413
|
+
getSrcUrl(parent, file) {
|
|
3414
|
+
const relativeUrl = file.relativeUrl || this.host.removeCwd(file.localUri) && getRelativeUrl(file);
|
|
3415
|
+
if (!relativeUrl) {
|
|
3416
|
+
return ['', false];
|
|
3417
|
+
}
|
|
3418
|
+
if (parent.inlineContent) {
|
|
3419
|
+
return [relativeUrl, false];
|
|
3420
|
+
}
|
|
3421
|
+
let parentDir = parent.pathname, assetDir = file.pathname;
|
|
3422
|
+
if (!this.productionRelease) {
|
|
3423
|
+
if (parent.moveTo) {
|
|
3424
|
+
parentDir = Document.joinPath(parent.moveTo, parentDir);
|
|
3425
|
+
}
|
|
3426
|
+
if (file.moveTo) {
|
|
3427
|
+
assetDir = Document.joinPath(file.moveTo, assetDir);
|
|
3428
|
+
}
|
|
3429
|
+
}
|
|
3430
|
+
if (parentDir === assetDir) {
|
|
3431
|
+
return [file.filename, true];
|
|
3432
|
+
}
|
|
3433
|
+
if (!parentDir) {
|
|
3434
|
+
return [relativeUrl, false];
|
|
3435
|
+
}
|
|
3436
|
+
const splitPath = (value) => value.split('/').filter(seg => seg.trim());
|
|
3437
|
+
const prefix = splitPath(parentDir);
|
|
3438
|
+
const suffix = splitPath(assetDir);
|
|
3439
|
+
let found = false;
|
|
3440
|
+
while (prefix.length > 0 && suffix.length > 0 && prefix[0] === suffix[0]) {
|
|
3441
|
+
prefix.shift();
|
|
3442
|
+
suffix.shift();
|
|
3443
|
+
found = true;
|
|
3444
|
+
}
|
|
3445
|
+
return [found ? Document.joinPath('../'.repeat(prefix.length), suffix.join('/'), file.filename) : '../'.repeat(prefix.length) + relativeUrl, false];
|
|
3446
|
+
}
|
|
3449
3447
|
isWatched(file) {
|
|
3450
3448
|
const { initialValue, format } = file;
|
|
3451
3449
|
return (file.imported ||
|
|
@@ -3734,7 +3732,7 @@ class ChromeDocument extends Document {
|
|
|
3734
3732
|
if (base64) {
|
|
3735
3733
|
for (const item of this.assets) {
|
|
3736
3734
|
if (item.base64 === base64) {
|
|
3737
|
-
setOutputURL(getSrcUrl(
|
|
3735
|
+
setOutputURL(this.getSrcUrl(file, item)[0], item);
|
|
3738
3736
|
break;
|
|
3739
3737
|
}
|
|
3740
3738
|
}
|
|
@@ -3790,7 +3788,7 @@ class ChromeDocument extends Document {
|
|
|
3790
3788
|
}
|
|
3791
3789
|
if (hasSameOrigin(asset.url || fullUrl, ...baseHref)) {
|
|
3792
3790
|
let sameDir = false;
|
|
3793
|
-
[fullUrl, sameDir] = getSrcUrl(
|
|
3791
|
+
[fullUrl, sameDir] = this.getSrcUrl(file, asset);
|
|
3794
3792
|
if (sameDir && isJs) {
|
|
3795
3793
|
fullUrl = './' + fullUrl;
|
|
3796
3794
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/chrome",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Chrome document constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/cloud": "^0.
|
|
24
|
-
"@e-mc/core": "^0.
|
|
25
|
-
"@e-mc/document": "^0.
|
|
26
|
-
"@e-mc/types": "^0.
|
|
23
|
+
"@e-mc/cloud": "^0.13.0",
|
|
24
|
+
"@e-mc/core": "^0.13.0",
|
|
25
|
+
"@e-mc/document": "^0.13.0",
|
|
26
|
+
"@e-mc/types": "^0.13.0",
|
|
27
27
|
"image-size": "^2.0.2"
|
|
28
28
|
}
|
|
29
29
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -117,6 +117,7 @@ export interface IChromeDocument<T extends IFileManager<U>, U extends DocumentAs
|
|
|
117
117
|
cloudObject(state: CloudScopeOrigin<T, U, V>, file: U): boolean;
|
|
118
118
|
cloudUpload(state: CloudScopeOrigin<T, U, V>, file: U, url: string, active: boolean): Promise<boolean>;
|
|
119
119
|
cloudFinalize(state: CloudScopeOrigin<T, U, V>): Promise<unknown[]>;
|
|
120
|
+
getSrcUrl(parent: U, file: U): [string, boolean];
|
|
120
121
|
isWatched(file: U): boolean;
|
|
121
122
|
get elements(): XmlTagNode[];
|
|
122
123
|
get editing(): U[];
|