@pi-r/chrome 0.6.2 → 0.6.4
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 +64 -27
- package/package.json +6 -6
- package/types/index.d.ts +1 -0
- package/types/squared.d.ts +16 -2
package/index.js
CHANGED
|
@@ -1302,6 +1302,7 @@ class ChromeDocument extends Document {
|
|
|
1302
1302
|
forDb(item) {
|
|
1303
1303
|
switch (item.source) {
|
|
1304
1304
|
case 'cloud':
|
|
1305
|
+
case 'json':
|
|
1305
1306
|
case 'uri':
|
|
1306
1307
|
case 'local':
|
|
1307
1308
|
case 'export':
|
|
@@ -1718,12 +1719,11 @@ class ChromeDocument extends Document {
|
|
|
1718
1719
|
const cloudUrl = endpoint ? url.replace(endpoint, '') : url;
|
|
1719
1720
|
file.cloudUrl = cloudUrl;
|
|
1720
1721
|
if (inlineUrlCloud) {
|
|
1721
|
-
const htmlFile = this.htmlFile;
|
|
1722
1722
|
const pattern = new RegExp((0, types_1.escapePattern)(inlineUrlCloud), 'g');
|
|
1723
1723
|
for (const item of this.editing) {
|
|
1724
1724
|
if (item.inlineUrlCloudMap?.[inlineUrlCloud]) {
|
|
1725
1725
|
const source = host.getUTF8String(item);
|
|
1726
|
-
const output = source.replace(pattern, endpoint && item
|
|
1726
|
+
const output = source.replace(pattern, endpoint && item.imported && cloudUrl.includes('/') ? url : cloudUrl);
|
|
1727
1727
|
if (source !== output) {
|
|
1728
1728
|
item.sourceUTF8 = output;
|
|
1729
1729
|
item.modified = true;
|
|
@@ -2294,43 +2294,46 @@ class ChromeDocument extends Document {
|
|
|
2294
2294
|
const detectWidth = domElement.getAttribute('width') === 'detect';
|
|
2295
2295
|
const detectHeight = domElement.getAttribute('height') === 'detect';
|
|
2296
2296
|
if (detectWidth || detectHeight) {
|
|
2297
|
-
let width = 0, height = 0, buffer = null;
|
|
2297
|
+
let width = 0, height = 0, buffer = null, packageName;
|
|
2298
|
+
const addLog = (dimension) => this.addLog(types_1.STATUS_TYPE.WARN, 'Could not detect image ' + dimension, packageName || this.moduleName, item.localUri ? path.basename(item.localUri) : item.filename);
|
|
2298
2299
|
if (isImage(item.mimeType) && (buffer = host.getBuffer(item))) {
|
|
2299
|
-
let dimensions;
|
|
2300
2300
|
try {
|
|
2301
|
-
|
|
2301
|
+
({ width, height } = require(packageName = 'image-size').imageSize(buffer));
|
|
2302
2302
|
}
|
|
2303
2303
|
catch {
|
|
2304
|
-
}
|
|
2305
|
-
if (dimensions) {
|
|
2306
|
-
({ width, height } = dimensions);
|
|
2307
|
-
}
|
|
2308
|
-
else {
|
|
2309
2304
|
try {
|
|
2310
|
-
|
|
2305
|
+
const dimension = require(packageName = 'probe-image-size').sync(buffer);
|
|
2306
|
+
if (!dimension) {
|
|
2307
|
+
throw new Error("MIME not found" /* ERR_MESSAGE.NOTFOUND_MIME */);
|
|
2308
|
+
}
|
|
2309
|
+
({ width, height } = dimension);
|
|
2311
2310
|
}
|
|
2312
2311
|
catch {
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2312
|
+
try {
|
|
2313
|
+
({ width, height } = (await require('jimp').read(buffer)).bitmap);
|
|
2314
|
+
}
|
|
2315
|
+
catch {
|
|
2316
2316
|
}
|
|
2317
|
+
packageName = '';
|
|
2317
2318
|
}
|
|
2318
2319
|
}
|
|
2319
2320
|
}
|
|
2320
2321
|
if (detectWidth) {
|
|
2321
|
-
if (width
|
|
2322
|
+
if (width) {
|
|
2322
2323
|
domElement.setAttribute('width', width.toString());
|
|
2323
2324
|
}
|
|
2324
2325
|
else {
|
|
2325
2326
|
domElement.removeAttribute('width');
|
|
2327
|
+
addLog('width');
|
|
2326
2328
|
}
|
|
2327
2329
|
}
|
|
2328
2330
|
if (detectHeight) {
|
|
2329
|
-
if (height
|
|
2331
|
+
if (height) {
|
|
2330
2332
|
domElement.setAttribute('height', height.toString());
|
|
2331
2333
|
}
|
|
2332
2334
|
else {
|
|
2333
2335
|
domElement.removeAttribute('height');
|
|
2336
|
+
addLog('height');
|
|
2334
2337
|
}
|
|
2335
2338
|
}
|
|
2336
2339
|
}
|
|
@@ -2425,6 +2428,7 @@ class ChromeDocument extends Document {
|
|
|
2425
2428
|
}
|
|
2426
2429
|
break;
|
|
2427
2430
|
}
|
|
2431
|
+
case 'json':
|
|
2428
2432
|
case 'uri':
|
|
2429
2433
|
case 'local':
|
|
2430
2434
|
case 'export':
|
|
@@ -2489,11 +2493,20 @@ class ChromeDocument extends Document {
|
|
|
2489
2493
|
return [];
|
|
2490
2494
|
});
|
|
2491
2495
|
break;
|
|
2496
|
+
case 'json':
|
|
2497
|
+
if ((result[0] = checkObject(current, current.items)) === null) {
|
|
2498
|
+
this.abort(type);
|
|
2499
|
+
errorRemove(current, errorDataSource("Invalid parameters" /* ERR_MESSAGE.PARAMETERS */ + ' (items)', type));
|
|
2500
|
+
return;
|
|
2501
|
+
}
|
|
2502
|
+
if (this.settingsOf(type, 'coerce') === true) {
|
|
2503
|
+
(0, types_1.coerceObject)(result[0]);
|
|
2504
|
+
}
|
|
2505
|
+
break;
|
|
2492
2506
|
case 'uri':
|
|
2493
2507
|
case 'local': {
|
|
2494
2508
|
const { ignoreCache, encoding = 'utf-8', options } = current;
|
|
2495
2509
|
let content, target, data, cacheKey;
|
|
2496
|
-
const addDownload = () => typeof content === 'string' && host.addDownload(Buffer.byteLength(content, encoding));
|
|
2497
2510
|
if (type === 'local') {
|
|
2498
2511
|
let location;
|
|
2499
2512
|
({ pathname: target } = current);
|
|
@@ -2509,7 +2522,6 @@ class ChromeDocument extends Document {
|
|
|
2509
2522
|
try {
|
|
2510
2523
|
content = fs.readFileSync(location, encoding);
|
|
2511
2524
|
cacheKey = location;
|
|
2512
|
-
addDownload();
|
|
2513
2525
|
}
|
|
2514
2526
|
catch (err) {
|
|
2515
2527
|
this.abort(type);
|
|
@@ -2532,7 +2544,22 @@ class ChromeDocument extends Document {
|
|
|
2532
2544
|
return;
|
|
2533
2545
|
}
|
|
2534
2546
|
else if (Document.isURL(target, 'file')) {
|
|
2535
|
-
|
|
2547
|
+
let { format, contentType, body } = current;
|
|
2548
|
+
if (body) {
|
|
2549
|
+
if (!format && !contentType && (0, types_1.isPlainObject)(body)) {
|
|
2550
|
+
format = 'json';
|
|
2551
|
+
}
|
|
2552
|
+
try {
|
|
2553
|
+
content = await host.Request.post(target, body, { format, encoding, contentType });
|
|
2554
|
+
}
|
|
2555
|
+
catch (err) {
|
|
2556
|
+
this.abort(type);
|
|
2557
|
+
this.writeFail(["Unable to download file" /* ERR_MESSAGE.DOWNLOAD_FILE */, target], err, { type: 1024 /* LOG_TYPE.HTTP */, startTime });
|
|
2558
|
+
errorRemove(current);
|
|
2559
|
+
return;
|
|
2560
|
+
}
|
|
2561
|
+
}
|
|
2562
|
+
else if (!ignoreCache && CACHE_DBRESULT.has(target)) {
|
|
2536
2563
|
data = getCacheItem(CACHE_DBRESULT, target);
|
|
2537
2564
|
}
|
|
2538
2565
|
else {
|
|
@@ -2541,10 +2568,7 @@ class ChromeDocument extends Document {
|
|
|
2541
2568
|
}
|
|
2542
2569
|
if (!(data = cacheData[target])) {
|
|
2543
2570
|
try {
|
|
2544
|
-
content = await host.
|
|
2545
|
-
if (Buffer.isBuffer(content)) {
|
|
2546
|
-
content = content.toString('utf-8');
|
|
2547
|
-
}
|
|
2571
|
+
content = await host.Request.get(target, { format, encoding });
|
|
2548
2572
|
cacheKey = target;
|
|
2549
2573
|
}
|
|
2550
2574
|
catch (err) {
|
|
@@ -2574,7 +2598,6 @@ class ChromeDocument extends Document {
|
|
|
2574
2598
|
try {
|
|
2575
2599
|
content = fs.readFileSync(pathname, encoding);
|
|
2576
2600
|
cacheKey = pathname;
|
|
2577
|
-
addDownload();
|
|
2578
2601
|
}
|
|
2579
2602
|
catch (err) {
|
|
2580
2603
|
this.abort(type);
|
|
@@ -2585,6 +2608,9 @@ class ChromeDocument extends Document {
|
|
|
2585
2608
|
}
|
|
2586
2609
|
}
|
|
2587
2610
|
}
|
|
2611
|
+
if (Buffer.isBuffer(content)) {
|
|
2612
|
+
content = content.toString('utf-8');
|
|
2613
|
+
}
|
|
2588
2614
|
if ((0, types_1.isString)(content)) {
|
|
2589
2615
|
const { format = path.extname(target).substring(1) } = current;
|
|
2590
2616
|
try {
|
|
@@ -2596,15 +2622,19 @@ class ChromeDocument extends Document {
|
|
|
2596
2622
|
errorRemove(current);
|
|
2597
2623
|
return;
|
|
2598
2624
|
}
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2625
|
+
host.addDownload(Buffer.byteLength(content, encoding));
|
|
2626
|
+
}
|
|
2627
|
+
else if (content) {
|
|
2628
|
+
data = content;
|
|
2602
2629
|
}
|
|
2603
2630
|
if (!data) {
|
|
2604
2631
|
this.abort(type);
|
|
2605
2632
|
errorRemove(current, errorDataSource(content !== null ? 'Invalid response' : 'Empty response', target));
|
|
2606
2633
|
return;
|
|
2607
2634
|
}
|
|
2635
|
+
if (cacheKey) {
|
|
2636
|
+
setCacheData.call(this, current, data, cacheKey, cacheData);
|
|
2637
|
+
}
|
|
2608
2638
|
if ((result[0] = checkObject(current, data)) === null) {
|
|
2609
2639
|
this.abort(type);
|
|
2610
2640
|
errorRemove(current, errorDataSource('Invalid ' + (current.query ? 'query' : 'URI'), target));
|
|
@@ -2975,6 +3005,13 @@ class ChromeDocument extends Document {
|
|
|
2975
3005
|
if (preRender) {
|
|
2976
3006
|
await checkValue(preRender);
|
|
2977
3007
|
}
|
|
3008
|
+
const { leadingText, trailingText } = item;
|
|
3009
|
+
if (leadingText) {
|
|
3010
|
+
value = leadingText + value;
|
|
3011
|
+
}
|
|
3012
|
+
if (trailingText) {
|
|
3013
|
+
value += trailingText;
|
|
3014
|
+
}
|
|
2978
3015
|
domElement.innerXml = domBase.initOpts.normalize ? dom_1.DomWriter.normalize(value, { newline: domBase.newline, escapeEntities: domBase.initOpts.escapeEntities }) : value;
|
|
2979
3016
|
}
|
|
2980
3017
|
else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/chrome",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.4",
|
|
4
4
|
"description": "Chrome document constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/anpham6/pi-r.git",
|
|
11
|
+
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
12
12
|
"directory": "src/module/chrome"
|
|
13
13
|
},
|
|
14
14
|
"keywords": [
|
|
@@ -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.4",
|
|
24
|
+
"@e-mc/core": "^0.8.4",
|
|
25
|
+
"@e-mc/document": "^0.8.4",
|
|
26
|
+
"@e-mc/types": "^0.8.4"
|
|
27
27
|
}
|
|
28
28
|
}
|
package/types/index.d.ts
CHANGED
package/types/squared.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { AttributeAction, ConditionProperty, CssConditionData, ElementActio
|
|
|
3
3
|
import type { UploadAction } from '@e-mc/types/lib/cloud';
|
|
4
4
|
import type { CascadeAction, DbSource } from '@e-mc/types/lib/db';
|
|
5
5
|
import type { RequestData as IRequestData } from '@e-mc/types/lib/node';
|
|
6
|
+
import type { BufferFormat } from '@e-mc/types/lib/request';
|
|
6
7
|
|
|
7
8
|
interface ImportFrom {
|
|
8
9
|
placeholder: string;
|
|
@@ -13,7 +14,7 @@ interface ImportFrom {
|
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
interface DataObject extends CascadeAction {
|
|
16
|
-
format?:
|
|
17
|
+
format?: BufferFormat;
|
|
17
18
|
options?: PlainObject;
|
|
18
19
|
}
|
|
19
20
|
|
|
@@ -86,7 +87,7 @@ export interface UnusedAtRule {
|
|
|
86
87
|
}
|
|
87
88
|
|
|
88
89
|
export interface DataSource<T = string> extends IDataSource<T>, ElementAction {
|
|
89
|
-
source: "cloud" | "uri" | "local" | "export" | DbSource;
|
|
90
|
+
source: "cloud" | "json" | "uri" | "local" | "export" | DbSource;
|
|
90
91
|
element?: XmlTagNode;
|
|
91
92
|
type?: "text" | "attribute" | "display";
|
|
92
93
|
dynamic?: boolean;
|
|
@@ -96,8 +97,16 @@ export interface DataSource<T = string> extends IDataSource<T>, ElementAction {
|
|
|
96
97
|
ignoreEmpty?: boolean;
|
|
97
98
|
}
|
|
98
99
|
|
|
100
|
+
export interface TextDataSource extends DataSource {
|
|
101
|
+
type: "text";
|
|
102
|
+
leadingText?: string;
|
|
103
|
+
trailingText?: string;
|
|
104
|
+
}
|
|
105
|
+
|
|
99
106
|
export interface UriDataSource extends DataSource, DataObject {
|
|
100
107
|
source: "uri";
|
|
108
|
+
body?: unknown;
|
|
109
|
+
contentType?: string;
|
|
101
110
|
}
|
|
102
111
|
|
|
103
112
|
export interface LocalDataSource extends DataSource, DataObject {
|
|
@@ -105,6 +114,11 @@ export interface LocalDataSource extends DataSource, DataObject {
|
|
|
105
114
|
pathname?: string;
|
|
106
115
|
}
|
|
107
116
|
|
|
117
|
+
export interface JSONDataSource extends DataSource, CascadeAction {
|
|
118
|
+
source: "json";
|
|
119
|
+
items?: unknown;
|
|
120
|
+
}
|
|
121
|
+
|
|
108
122
|
export interface ExportDataSource extends DataSource, CascadeAction {
|
|
109
123
|
source: "export";
|
|
110
124
|
execute?: FunctionType;
|