@pi-r/chrome 0.0.1 → 0.2.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 +36 -26
- package/package.json +5 -5
- package/types/index.d.ts +8 -8
- package/types/squared.d.ts +8 -0
package/index.js
CHANGED
|
@@ -665,15 +665,17 @@ function setLocationUUID(data, file, ext) {
|
|
|
665
665
|
}
|
|
666
666
|
function transformOptions(file, mimeType, code, bundleContent) {
|
|
667
667
|
const { uri, localUri, exported } = file;
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
668
|
+
const metadata = { userAgentData: this.userAgentData };
|
|
669
|
+
switch (mimeType) {
|
|
670
|
+
case 'text/html':
|
|
671
|
+
metadata['__fromhtml__'] = true;
|
|
672
|
+
case 'text/css':
|
|
673
|
+
Object.assign(metadata, this.config);
|
|
674
|
+
default:
|
|
675
|
+
if ((0, types_1.isObject)(file.metadata)) {
|
|
676
|
+
Object.assign(metadata, file.metadata);
|
|
677
|
+
}
|
|
678
|
+
break;
|
|
677
679
|
}
|
|
678
680
|
const [pathname, filename] = localUri ? [path.dirname(localUri), path.basename(localUri)] : ['', file.filename];
|
|
679
681
|
const options = { pathname, filename, mimeType, metadata, imported: !!file.imports && file.imported !== false };
|
|
@@ -900,6 +902,7 @@ class ChromeDocument extends Document {
|
|
|
900
902
|
this.productionRelease = false;
|
|
901
903
|
this.productionIncremental = false;
|
|
902
904
|
this.templateMap = {};
|
|
905
|
+
this.userAgentData = {};
|
|
903
906
|
this.related = new Map();
|
|
904
907
|
this.replaced = [];
|
|
905
908
|
this._moduleName = 'chrome';
|
|
@@ -1053,7 +1056,7 @@ class ChromeDocument extends Document {
|
|
|
1053
1056
|
const serverRoot = ChromeDocument.INTERNAL_SERVERROOT;
|
|
1054
1057
|
const srcDir = path.join(this.baseDirectory, serverRoot);
|
|
1055
1058
|
if (isDir(srcDir)) {
|
|
1056
|
-
const result = await Document.copyDir(srcDir, productionRelease,
|
|
1059
|
+
const result = await Document.copyDir(srcDir, productionRelease, this.incremental !== 'staging');
|
|
1057
1060
|
const failed = result.failed.map(value => this.removeCwd(value));
|
|
1058
1061
|
for (const value of this.files) {
|
|
1059
1062
|
if (value.startsWith(serverRoot)) {
|
|
@@ -1156,7 +1159,7 @@ class ChromeDocument extends Document {
|
|
|
1156
1159
|
return 0;
|
|
1157
1160
|
});
|
|
1158
1161
|
if (config) {
|
|
1159
|
-
const { useUnsafeReplace, baseUrl, productionRelease, productionIncremental, templateMap, imports, cache } = config;
|
|
1162
|
+
const { useUnsafeReplace, baseUrl, productionRelease, productionIncremental, templateMap, userAgentData, imports, cache } = config;
|
|
1160
1163
|
const target = this.config;
|
|
1161
1164
|
for (const attr in config) {
|
|
1162
1165
|
if (attr in target) {
|
|
@@ -1198,6 +1201,9 @@ class ChromeDocument extends Document {
|
|
|
1198
1201
|
if ((0, types_1.isObject)(templateMap)) {
|
|
1199
1202
|
this.templateMap = templateMap;
|
|
1200
1203
|
}
|
|
1204
|
+
if ((0, types_1.isObject)(userAgentData)) {
|
|
1205
|
+
this.userAgentData = userAgentData;
|
|
1206
|
+
}
|
|
1201
1207
|
this.imports = (0, types_1.isPlainObject)(imports) ? { ...this.module.imports, ...imports } : this.module.imports;
|
|
1202
1208
|
if ((0, types_1.isObject)(cache) && 'transform' in cache) {
|
|
1203
1209
|
this.customize({ transform: cache.transform });
|
|
@@ -3374,11 +3380,11 @@ class ChromeDocument extends Document {
|
|
|
3374
3380
|
}
|
|
3375
3381
|
};
|
|
3376
3382
|
if (!useUnsafeCssReplace) {
|
|
3377
|
-
const replaceBracket = (pattern
|
|
3383
|
+
const replaceBracket = (pattern) => {
|
|
3378
3384
|
let bracket;
|
|
3379
3385
|
while (bracket = pattern.exec(current)) {
|
|
3380
3386
|
const segment = bracket[0];
|
|
3381
|
-
if (
|
|
3387
|
+
if (/[{}]/.test(segment)) {
|
|
3382
3388
|
const placeholder = '`' + (0, types_1.generateUUID)() + '`';
|
|
3383
3389
|
replaceMap.push([placeholder, segment]);
|
|
3384
3390
|
current = replaceMatch(bracket, current, placeholder, pattern);
|
|
@@ -3386,12 +3392,12 @@ class ChromeDocument extends Document {
|
|
|
3386
3392
|
}
|
|
3387
3393
|
pattern.lastIndex = 0;
|
|
3388
3394
|
};
|
|
3389
|
-
replaceBracket(REGEXP_COMMENT
|
|
3390
|
-
replaceBracket(REGEXP_CONTENT
|
|
3395
|
+
replaceBracket(REGEXP_COMMENT);
|
|
3396
|
+
replaceBracket(REGEXP_CONTENT);
|
|
3391
3397
|
const values = (0, util_1.splitEnclosing)(current, /\burl/gi);
|
|
3392
3398
|
for (let i = 0, length = values.length; i < length; ++i) {
|
|
3393
3399
|
const seg = values[i];
|
|
3394
|
-
if (
|
|
3400
|
+
if (/^url\([^{}]*[{}][\S\s]*\)$/i.test(seg)) {
|
|
3395
3401
|
replaceMap.push([values[i] = (0, types_1.generateUUID)(), seg]);
|
|
3396
3402
|
}
|
|
3397
3403
|
}
|
|
@@ -3413,25 +3419,29 @@ class ChromeDocument extends Document {
|
|
|
3413
3419
|
const key = value + (useUnsafeCssReplace ? '_1' : '');
|
|
3414
3420
|
let [single, group] = selectorMap[key] || [], selector;
|
|
3415
3421
|
if (!single || !group) {
|
|
3416
|
-
single = new RegExp(`(}|^)(${getStringSome()})(?<!@[^}]*)${selector = parseSelector(value)}\\{[^}]
|
|
3422
|
+
single = new RegExp(`(}|^)(${getStringSome()})(?<!@[^}]*)${selector = parseSelector(value)}\\{([^}]*)\\}` + dom_1.DomWriter.PATTERN_TRAILINGSPACE, 'g');
|
|
3417
3423
|
group = new RegExp(`((?:}|^)[^{]*?)((?:,${getStringSome()}|(?<!@[^}]*))${selector})(,[^{]*)?\\{`, 'g');
|
|
3418
3424
|
}
|
|
3419
3425
|
else {
|
|
3420
3426
|
single.lastIndex = 0;
|
|
3421
3427
|
group.lastIndex = 0;
|
|
3422
3428
|
}
|
|
3423
|
-
while (match = single.exec(current)) {
|
|
3424
|
-
current = spliceSource(current, match.index, getEndIndex(match), single, match[2], match[
|
|
3429
|
+
while ((match = single.exec(current)) && match[3].indexOf('{') === -1) {
|
|
3430
|
+
current = spliceSource(current, match.index, getEndIndex(match), single, match[2], match[4], match[1] || '');
|
|
3425
3431
|
modified = true;
|
|
3426
3432
|
}
|
|
3427
3433
|
while (match = group.exec(current)) {
|
|
3428
|
-
const
|
|
3429
|
-
const
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3434
|
+
const opening = match.index + match[0].length;
|
|
3435
|
+
const closing = current.indexOf('}', opening);
|
|
3436
|
+
if (closing !== -1 && current.substring(opening, closing).indexOf('{') === -1) {
|
|
3437
|
+
const middle = match[2][0] === ',';
|
|
3438
|
+
const leading = middle ? match[1].trimEnd() : match[1];
|
|
3439
|
+
const trailing = match[3];
|
|
3440
|
+
const segment = trailing ? (!middle ? (!isSpace(leading[leading.length - 1]) ? ' ' : '') + trailing.substring(1).trimStart() : trailing).trimEnd() : '';
|
|
3441
|
+
current = replaceMatch(match, current, leading + segment + ' {');
|
|
3442
|
+
group.lastIndex = match.index;
|
|
3443
|
+
modified = true;
|
|
3444
|
+
}
|
|
3435
3445
|
}
|
|
3436
3446
|
if (selector) {
|
|
3437
3447
|
selectorMap[key] = [single, group];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/chrome",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
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.
|
|
24
|
-
"@e-mc/core": "^0.
|
|
25
|
-
"@e-mc/document": "^0.
|
|
26
|
-
"@e-mc/types": "^0.
|
|
23
|
+
"@e-mc/cloud": "^0.5.0",
|
|
24
|
+
"@e-mc/core": "^0.5.0",
|
|
25
|
+
"@e-mc/document": "^0.5.0",
|
|
26
|
+
"@e-mc/types": "^0.5.0"
|
|
27
27
|
}
|
|
28
28
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { LocationUri, XmlTagNode } from '@e-mc/types/lib/squared';
|
|
2
2
|
|
|
3
|
-
import type { DocumentConstructor, IDocument, IFileManager } from '@e-mc/types/lib';
|
|
3
|
+
import type { DocumentConstructor, ICloud, IDocument, IFileManager } from '@e-mc/types/lib';
|
|
4
4
|
import type { DocumentAsset as IDocumentAsset } from '@e-mc/types/lib/document';
|
|
5
5
|
import type { LogTime } from '@e-mc/types/lib/logger';
|
|
6
6
|
import type { DbSourceDataType, DocumentComponentOption, DocumentComponent as IDocumentComponent, DocumentComponentOptions as IDocumentComponentOptions, DocumentDirectory as IDocumentDirectory, DocumentEval as IDocumentEval, DocumentModule as IDocumentModule, DocumentSettings as IDocumentSettings } from '@e-mc/types/lib/settings';
|
|
@@ -37,7 +37,7 @@ interface ChromeDocumentSettings extends IDocumentSettings {
|
|
|
37
37
|
export?: ObjectMap<string | FunctionType>;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
type OutputType = "useUnsafeReplace" | "productionRelease" | "productionIncremental" | "templateMap";
|
|
40
|
+
type OutputType = "useUnsafeReplace" | "productionRelease" | "productionIncremental" | "templateMap" | "userAgentData";
|
|
41
41
|
|
|
42
42
|
export interface FormatUri extends Partial<LocationUri> {
|
|
43
43
|
dictionary?: string;
|
|
@@ -78,7 +78,7 @@ export interface UserConfig extends CssRuleData, Omit<DocumentOutput, OutputType
|
|
|
78
78
|
useUnsafeCssReplace?: boolean;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
export interface IChromeDocument<T extends IFileManager<U>, U extends DocumentAsset = DocumentAsset
|
|
81
|
+
export interface IChromeDocument<T extends IFileManager<U>, U extends DocumentAsset = DocumentAsset, V extends ICloud = ICloud<T>> extends IDocument<T, U, DocumentModule, DocumentComponent, DocumentComponentOption, V>, Pick<DocumentOutput, OutputType> {
|
|
82
82
|
htmlFile: Null<U>;
|
|
83
83
|
cssFiles: U[];
|
|
84
84
|
jsFiles: U[];
|
|
@@ -100,10 +100,10 @@ export interface IChromeDocument<T extends IFileManager<U>, U extends DocumentAs
|
|
|
100
100
|
removeUnusedStyles(source: string, options?: UserConfig): Undef<string>;
|
|
101
101
|
removeServerRoot(value: string): string;
|
|
102
102
|
replaceContent(source: string, match: RegExpExecArray | string, mimeType?: string): Undef<string>;
|
|
103
|
-
cloudInit(state: CloudScopeOrigin<T, U>): void;
|
|
104
|
-
cloudObject(state: CloudScopeOrigin<T, U>, file: U): boolean;
|
|
105
|
-
cloudUpload(state: CloudScopeOrigin<T, U>, file: U, url: string, active: boolean): Promise<boolean>;
|
|
106
|
-
cloudFinalize(state: CloudScopeOrigin<T, U>): Promise<unknown[]>;
|
|
103
|
+
cloudInit(state: CloudScopeOrigin<T, U, V>): void;
|
|
104
|
+
cloudObject(state: CloudScopeOrigin<T, U, V>, file: U): boolean;
|
|
105
|
+
cloudUpload(state: CloudScopeOrigin<T, U, V>, file: U, url: string, active: boolean): Promise<boolean>;
|
|
106
|
+
cloudFinalize(state: CloudScopeOrigin<T, U, V>): Promise<unknown[]>;
|
|
107
107
|
get settings(): ChromeDocumentSettings;
|
|
108
108
|
get editing(): U[];
|
|
109
109
|
get dataSource(): DataSource[];
|
|
@@ -115,4 +115,4 @@ export interface ChromeDocumentConstructor<T extends IFileManager<U>, U extends
|
|
|
115
115
|
INTERNAL_SERVERROOT: string;
|
|
116
116
|
readonly prototype: IChromeDocument<T, U>;
|
|
117
117
|
new(module?: DocumentModule, ...args: unknown[]): IChromeDocument<T, U>;
|
|
118
|
-
}
|
|
118
|
+
}
|
package/types/squared.d.ts
CHANGED
|
@@ -17,6 +17,13 @@ interface DataObject extends CascadeAction {
|
|
|
17
17
|
options?: PlainObject;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
export interface UserAgentData {
|
|
21
|
+
platform: string;
|
|
22
|
+
brand: string;
|
|
23
|
+
browser: number;
|
|
24
|
+
version: Null<number[]>;
|
|
25
|
+
}
|
|
26
|
+
|
|
20
27
|
export interface DocumentOutput {
|
|
21
28
|
productionRelease?: boolean | string;
|
|
22
29
|
productionIncremental?: boolean;
|
|
@@ -38,6 +45,7 @@ export interface DocumentOutput {
|
|
|
38
45
|
excludeScopes?: string[];
|
|
39
46
|
};
|
|
40
47
|
templateMap?: TemplateMap;
|
|
48
|
+
userAgentData?: Partial<UserAgentData>;
|
|
41
49
|
}
|
|
42
50
|
|
|
43
51
|
export interface RequestData extends IRequestData<ChromeAsset>, Readonly<DocumentOutput>, Readonly<CssRuleData> {}
|