@pi-r/chrome 0.0.1 → 0.1.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 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
- let metadata;
669
- if (mimeType === 'text/css') {
670
- metadata = { ...this.config, ...file.metadata };
671
- }
672
- else if (mimeType === 'text/html') {
673
- metadata = { '__fromhtml__': true, ...this.config, ...file.metadata };
674
- }
675
- else {
676
- metadata = file.metadata;
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';
@@ -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, opening) => {
3383
+ const replaceBracket = (pattern) => {
3378
3384
  let bracket;
3379
3385
  while (bracket = pattern.exec(current)) {
3380
3386
  const segment = bracket[0];
3381
- if (segment.indexOf('}') !== -1 || opening && segment.indexOf('{') !== -1) {
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, true);
3390
- replaceBracket(REGEXP_CONTENT, false);
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 (seg[seg.length - 1] === ')' && seg.indexOf('}') !== -1 && /^url\(/i.test(seg)) {
3400
+ if (/^url\([^{}]*[{}]/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)}\\{[^}]*\\}` + dom_1.DomWriter.PATTERN_TRAILINGSPACE, 'g');
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[3], match[1] || '');
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 middle = match[2][0] === ',';
3429
- const leading = middle ? match[1].trimEnd() : match[1];
3430
- const trailing = match[3];
3431
- const segment = trailing ? (!middle ? (!isSpace(leading[leading.length - 1]) ? ' ' : '') + trailing.substring(1).trimStart() : trailing).trimEnd() : '';
3432
- current = replaceMatch(match, current, leading + segment + ' {');
3433
- group.lastIndex = match.index;
3434
- modified = true;
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.1",
3
+ "version": "0.1.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.4.0",
24
- "@e-mc/core": "^0.4.0",
25
- "@e-mc/document": "^0.4.0",
26
- "@e-mc/types": "^0.4.0"
23
+ "@e-mc/cloud": "^0.4.2",
24
+ "@e-mc/core": "^0.4.2",
25
+ "@e-mc/document": "^0.4.2",
26
+ "@e-mc/types": "^0.4.2"
27
27
  }
28
28
  }
package/types/index.d.ts CHANGED
@@ -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> extends IDocument<T, U, DocumentModule, DocumentComponent>, Pick<DocumentOutput, OutputType> {
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[];
@@ -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> {}