@pi-r/chrome 0.3.6 → 0.3.8

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.
Files changed (3) hide show
  1. package/index.js +154 -131
  2. package/package.json +5 -5
  3. package/types/index.d.ts +2 -1
package/index.js CHANGED
@@ -32,7 +32,7 @@ const [REGEXP_NTHCHILD, REGEXP_NTHCHILD_UNSAFE, REGEXP_REPLACECSS] = (function (
32
32
  return [
33
33
  new RegExp(`\\(${PATTERN_STRING_SOME}([+-])?(?:(\\d*)[nN]|(0))?${PATTERN_STRING_SOME}([+-])?${PATTERN_STRING_SOME}(\\d*)(?:${PATTERN_STRING_MANY}[oO][fF]${PATTERN_STRING_MANY}(${parenthesis})${PATTERN_STRING_SOME}\\)|${PATTERN_STRING_SOME}\\))`, 'g'),
34
34
  new RegExp(`\\(\\s*([+-])?(?:(\\d*)[nN]|(0))?\\s*([+-])?\\s*(\\d*)(?:\\s+[oO][fF]\\s+(${parenthesis})\\s*\\)|\\s*\\))`, 'g'),
35
- new RegExp(`^@import\\s+(?:url\\((?:[^)]|(?<=\\\\)\\))+\\)|"(?:[^"]|(?<=\\\\)")+"|'(?:[^']|(?<=\\\\)')+')(\\s*layer(?:\\(([^)]*)\\)|\\b))?(?:\\s*supports\\((${parenthesis})\\))?(.*?);?$`)
35
+ new RegExp(`^@import\\s+(?:url\\((?:[^)]|(?<=\\\\)\\))+\\)|"(?:[^"]|(?<=\\\\)")+"|'(?:[^']|(?<=\\\\)')+')(\\s*layer(\\([^)]*\\))?)?(?:\\s*supports\\((${parenthesis})\\))?(.*)$`, 'si')
36
36
  ];
37
37
  })();
38
38
  const REGEXP_COMMENT = new RegExp(dom_1.DomWriter.PATTERN_COMMENT, 'g');
@@ -46,9 +46,13 @@ const REGEXP_VARIABLES_UNSAFE = new RegExp(`(\\s*)(--[^\\s:]*)\\s*:[^;}]*([;}])`
46
46
  const REGEXP_FONTFACE_UNSAFE = new RegExp(`(\\s*)@font-face\\s*{([^}]+)}` + dom_1.DomWriter.PATTERN_TRAILINGSPACE, 'gi');
47
47
  const REGEXP_FONTFAMILY_UNSAFE = /font-family\s*:([^;}]+)/i;
48
48
  const REGEXP_KEYFRAMES_UNSAFE = /(\s*)@keyframes\s+([^{]+){/gi;
49
+ const REGEXP_OBJECT_NAME = /([^[.\s]+)((?:\s*\[[^\]]+\]\s*)+)?\s*\.?\s*/g;
50
+ const REGEXP_OBJECT_SUBSCRIPT = /\[\s*(["'])?(.+?)\1\s*\]/g;
51
+ const REGEXP_TEMPLATE_LEADING = /\s*\{\{- \s*((?:[^}]|}(?!}))+?)\}\}/g;
52
+ const REGEXP_TEMPLATE_TRAILING = /\{\{((?:[^}]|}(?!}))+?)\s*? -\}\}\s*/g;
49
53
  function removeNamespace(name, source, newline, comments) {
50
54
  if (source.indexOf('-' + name) !== -1) {
51
- const dataset = CACHE_DATASET[name] || (CACHE_DATASET[name] = [
55
+ const [a, b, c, d, e] = CACHE_DATASET[name] || (CACHE_DATASET[name] = [
52
56
  new RegExp(`(\\s*)<(script|style)(${dom_1.DomWriter.PATTERN_TAGOPEN}+)>[\\S\\s]*?<\\/\\2\\s*>` + dom_1.DomWriter.PATTERN_TRAILINGSPACE, 'gi'),
53
57
  new RegExp(`(\\s*)<link(${dom_1.DomWriter.PATTERN_TAGOPEN}+)>` + dom_1.DomWriter.PATTERN_TRAILINGSPACE, 'gi'),
54
58
  new RegExp(`\\s+data-${name}-[a-z-]+\\s*` + dom_1.DomWriter.PATTERN_ATTRVALUE, 'g'),
@@ -56,24 +60,26 @@ function removeNamespace(name, source, newline, comments) {
56
60
  new RegExp(`data-${name}-template\\s*` + dom_1.DomWriter.PATTERN_ATTRVALUE)
57
61
  ]);
58
62
  source = source
59
- .replace(dataset[0], (...capture) => dataset[3].test(capture[3]) || dataset[4].test(capture[3]) ? getNewlineString(capture[1], capture[7], newline) : capture[0])
60
- .replace(dataset[1], (...capture) => dataset[3].test(capture[2]) ? getNewlineString(capture[1], capture[6], newline) : capture[0])
61
- .replace(dataset[2], '');
63
+ .replace(a, (...capture) => d.test(capture[3]) || e.test(capture[3]) ? getNewlineString(capture[1], capture[7], newline) : capture[0])
64
+ .replace(b, (...capture) => d.test(capture[2]) ? getNewlineString(capture[1], capture[6], newline) : capture[0])
65
+ .replace(c, '');
62
66
  }
63
67
  return (0, types_1.isArray)(comments) ? source.replace(REGEXP_BLOCKEXCLUDE, (...capture) => getNewlineString(capture[1], capture[2], newline)) : source;
64
68
  }
65
69
  function getObjectValue(value, key) {
66
- const pattern = /([^[.\s]+)((?:\s*\[[^\]]+\]\s*)+)?\s*\.?\s*/g;
70
+ REGEXP_OBJECT_NAME.lastIndex = 0;
67
71
  let found, match;
68
- while (match = pattern.exec(key)) {
72
+ while (match = REGEXP_OBJECT_NAME.exec(key)) {
69
73
  if ((0, types_1.isObject)(value)) {
70
74
  value = value[match[1]];
71
- if (match[2]) {
72
- const subscript = /\[\s*(["'])?(.+?)\1\s*\]/g;
75
+ const name = match[2];
76
+ if (name) {
77
+ REGEXP_OBJECT_SUBSCRIPT.lastIndex = 0;
73
78
  let index;
74
- while (index = subscript.exec(match[2])) {
75
- const attr = index[1] ? index[2] : index[2].trim();
76
- if (index[1] && (0, types_1.isObject)(value) || /^\d+$/.test(attr) && (typeof value === 'string' || (0, types_1.isObject)(value))) {
79
+ while (index = REGEXP_OBJECT_SUBSCRIPT.exec(name)) {
80
+ const quote = index[1];
81
+ const attr = quote ? index[2] : index[2].trim();
82
+ if (quote && (0, types_1.isObject)(value) || /^\d+$/.test(attr) && (typeof value === 'string' || (0, types_1.isObject)(value))) {
77
83
  value = value[attr];
78
84
  }
79
85
  else {
@@ -91,14 +97,14 @@ function getObjectValue(value, key) {
91
97
  return found ? value : null;
92
98
  }
93
99
  function trimTemplate(value) {
94
- const leading = /\s*\{\{- \s*((?:[^}]|}(?!}))+?)\}\}/g;
100
+ REGEXP_TEMPLATE_LEADING.lastIndex = 0;
95
101
  let match;
96
- while (match = leading.exec(value)) {
97
- value = replaceMatch(match, value, 1, leading);
102
+ while (match = REGEXP_TEMPLATE_LEADING.exec(value)) {
103
+ value = replaceMatch(match, value, 1, REGEXP_TEMPLATE_LEADING);
98
104
  }
99
- const trailing = /\{\{((?:[^}]|}(?!}))+?)\s*? -\}\}\s*/g;
100
- while (match = trailing.exec(value)) {
101
- value = replaceMatch(match, value, 1, trailing);
105
+ REGEXP_TEMPLATE_TRAILING.lastIndex = 0;
106
+ while (match = REGEXP_TEMPLATE_TRAILING.exec(value)) {
107
+ value = replaceMatch(match, value, 1, REGEXP_TEMPLATE_TRAILING);
102
108
  }
103
109
  return value;
104
110
  }
@@ -176,15 +182,15 @@ function hasCondition(data, condition) {
176
182
  }
177
183
  let match = REGEXP_TEMPLATEMATCH.exec(condition.trim());
178
184
  if (match) {
179
- if (match[2]) {
185
+ const comparison = match[2];
186
+ if (comparison) {
180
187
  const join = match[1];
181
- const comparison = match[2];
182
188
  const items = [];
183
189
  while (match = REGEXP_TEMPLATECOMPARISON.exec(comparison)) {
184
190
  if (items.length && !isSpace(match[0][0])) {
185
191
  return false;
186
192
  }
187
- items.push([match[1], trimQuote(match[2]), trimQuote(match[3])]);
193
+ items.push([match[1], trimQuote(match[2]), match[3] ? trimQuote(match[3]) : '']);
188
194
  }
189
195
  REGEXP_TEMPLATECOMPARISON.lastIndex = 0;
190
196
  const length = items.length;
@@ -195,18 +201,13 @@ function hasCondition(data, condition) {
195
201
  if (!isNaN(+value)) {
196
202
  return +value;
197
203
  }
198
- if (match = /^(["'])([\S\s]*)\1$/.exec(value)) {
199
- return match[2];
200
- }
201
204
  return getObjectValue(data, value);
202
205
  };
203
206
  for (let i = 0; i < length; ++i) {
204
- const item = items[i];
205
- const arg1 = item[1];
206
- const arg2 = item[2];
207
- let valid;
207
+ const [cmp, arg1, arg2] = items[i];
208
+ let valid = false;
208
209
  if (arg2) {
209
- switch (item[0]) {
210
+ switch (cmp) {
210
211
  case 'eq':
211
212
  valid = parseArg(arg1) == parseArg(arg2);
212
213
  break;
@@ -229,7 +230,7 @@ function hasCondition(data, condition) {
229
230
  return false;
230
231
  }
231
232
  }
232
- else if (item[0]) {
233
+ else if (cmp) {
233
234
  return false;
234
235
  }
235
236
  else {
@@ -283,17 +284,14 @@ function hasSameOrigin(value, ...other) {
283
284
  return false;
284
285
  }
285
286
  function restoreSearchParams(value, prefix = '__sqd') {
286
- if (value) {
287
- if (value.indexOf(prefix) !== -1) {
288
- const params = new URLSearchParams(value);
289
- params.forEach((_, key) => key.startsWith(prefix) && params.delete(key));
290
- if (value = params.toString()) {
291
- return '?' + value;
292
- }
287
+ if ((value === null || value === void 0 ? void 0 : value.indexOf(prefix)) !== -1) {
288
+ const params = new URLSearchParams(value);
289
+ params.forEach((_, key) => key.startsWith(prefix) && params.delete(key));
290
+ if (value = params.toString()) {
291
+ return '?' + value;
293
292
  }
294
- return value;
295
293
  }
296
- return '';
294
+ return value || '';
297
295
  }
298
296
  function getBaseURLs(asset, baseUrl) {
299
297
  const result = [];
@@ -323,26 +321,27 @@ function getBaseURLs(asset, baseUrl) {
323
321
  }
324
322
  function createHash(host, file, bufferMap) {
325
323
  const hash = file.hash;
326
- if (hash) {
327
- try {
328
- const localUri = file.localUri;
329
- const buffer = localUri && bufferMap[localUri] || getBuffer(file);
330
- if (buffer) {
331
- const [algorithm, length] = (0, util_1.getHashData)(hash);
332
- let value;
333
- if (algorithm && (value = Document.asHash(buffer, { algorithm, encoding: file.encoding }))) {
334
- if (localUri) {
335
- bufferMap[localUri] = buffer;
336
- }
337
- host.rename(file, (0, util_1.appendSuffix)(file.filename, length ? value.substring(0, length) : value));
338
- return file.filename;
324
+ if (!hash) {
325
+ return;
326
+ }
327
+ const { filename, localUri } = file;
328
+ try {
329
+ const buffer = localUri && bufferMap[localUri] || getBuffer(file);
330
+ if (buffer) {
331
+ const [algorithm, length] = (0, util_1.getHashData)(hash);
332
+ let value;
333
+ if (algorithm && (value = Document.asHash(buffer, { algorithm, encoding: file.encoding }))) {
334
+ if (localUri) {
335
+ bufferMap[localUri] = buffer;
339
336
  }
337
+ host.rename(file, (0, util_1.appendSuffix)(filename, length ? value.substring(0, length) : value));
338
+ return file.filename;
340
339
  }
341
- throw (0, types_1.errorMessage)('hash', 'Source not found', file.filename);
342
- }
343
- catch (err) {
344
- host.writeFail(["Unable to read file", file.filename], err, 32);
345
340
  }
341
+ throw (0, types_1.errorMessage)('hash', 'Source not found', filename);
342
+ }
343
+ catch (err) {
344
+ host.writeFail(["Unable to read file", filename], err, 32);
346
345
  }
347
346
  }
348
347
  function getSrcURL(parent, file) {
@@ -382,7 +381,7 @@ function transformURL(host, parent, type, source, importFile) {
382
381
  const baseHref = getBaseURLs(importFile || parent, this.baseUrl);
383
382
  const isHtml = type === 'html';
384
383
  const isJs = type === 'js';
385
- const pattern = isJs ? /\bimport\(/g : type === 'svg' ? /(?:\b[Uu][Rr][Ll]\(|@import\s+(["'])|\b([Hh][Rr][Ee][Ff])\s*=)/g : /\b[Uu][Rr][Ll]\(|@import\s+(["'])/g;
384
+ const pattern = isJs ? /\bimport\(/g : type === 'svg' ? /(?:\burl\(|@import\s+(["'])|\b(href)\s*=)/gi : /\burl\(|@import\s+(["'])/gi;
386
385
  let length = source.length, modified, match;
387
386
  while (match = pattern.exec(source)) {
388
387
  const isText = !!match[1];
@@ -554,7 +553,7 @@ function transformURL(host, parent, type, source, importFile) {
554
553
  if (!isText) {
555
554
  let j = startIndex;
556
555
  while (isSpace(source[--j])) { }
557
- valid = source.substring(k = j - 6, j + 1) === '@import';
556
+ valid = source.substring(k = j - 6, j + 1).toLowerCase() === '@import';
558
557
  }
559
558
  else {
560
559
  k = startIndex;
@@ -664,7 +663,7 @@ function transformOptions(file, mimeType, code, bundleContent) {
664
663
  const metadata = { userAgentData: this.userAgentData };
665
664
  switch (mimeType) {
666
665
  case 'text/html':
667
- metadata['__fromhtml__'] = true;
666
+ metadata.__fromhtml__ = true;
668
667
  case 'text/css':
669
668
  Object.assign(metadata, this.config);
670
669
  default:
@@ -763,11 +762,12 @@ function replaceCss(file) {
763
762
  map[id] = this.removeServerRoot(map[id]);
764
763
  }
765
764
  };
766
- if (file.inlineUrlMap) {
767
- sanitize(file.inlineUrlMap);
765
+ const { inlineUrlMap, inlineUrlCloudMap } = file;
766
+ if (inlineUrlMap) {
767
+ sanitize(inlineUrlMap);
768
768
  }
769
- if (file.inlineUrlCloudMap) {
770
- sanitize(file.inlineUrlCloudMap);
769
+ if (inlineUrlCloudMap) {
770
+ sanitize(inlineUrlCloudMap);
771
771
  }
772
772
  }
773
773
  function replaceHtml(source, { productionRelease, contentMap }, cssMap) {
@@ -843,6 +843,10 @@ async function checkData(item, name, result, validate) {
843
843
  }
844
844
  }
845
845
  }
846
+ function getBuffer(item) {
847
+ let localUri;
848
+ return item.sourceUTF8 || item.buffer || ((localUri = item.localUri) && isPath(localUri) ? fs.readFileSync(localUri, item.encoding) : null);
849
+ }
846
850
  const getNewlineString = dom_1.DomWriter.getNewlineString.bind(dom_1.DomWriter);
847
851
  const isSpace = dom_1.DomWriter.isSpace.bind(dom_1.DomWriter);
848
852
  const replaceMatch = dom_1.DomWriter.replaceMatch.bind(dom_1.DomWriter);
@@ -853,11 +857,10 @@ const asString = Document.asString.bind(Document);
853
857
  const resolvePath = Document.resolvePath.bind(Document);
854
858
  const toPosix = Document.toPosix.bind(Document);
855
859
  const isDir = Document.isDir.bind(Document);
856
- const hasSourceMap = (metadata, value) => (0, types_1.isObject)(metadata) && metadata['__sourcemap__'] === value;
860
+ const hasSourceMap = (metadata, value) => (0, types_1.isObject)(metadata) && metadata.__sourcemap__ === value;
857
861
  const isBundled = (value, main) => typeof value === 'number' && (value > 0 || main && value === 0);
858
862
  const isFont = (value) => value === 'truetype' || value === 'opentype' || value === 'woff' || value === 'woff2';
859
863
  const isImage = (value) => typeof value === 'string' && value.startsWith('image/') && value !== 'image/svg+xml';
860
- const getBuffer = (item) => item.sourceUTF8 || item.buffer || (item.localUri && isPath(item.localUri) ? fs.readFileSync(item.localUri, item.encoding) : null);
861
864
  const isRemoved = (item) => item.exclude === true || isBundled(item.bundleIndex);
862
865
  const isUnedited = (item) => !item.attributes && !item.inlineContent && !item.srcSet && !item.element.dynamic && item.element.textContent === undefined && (!item.uri && !isBundled(item.bundleIndex, true) || (0, util_1.hasValue)(item.format, 'crossorigin'));
863
866
  const isIgnored = (item, exists) => item.invalid || (0, types_1.ignoreFlag)(item.flags) || !exists && (0, types_1.existsFlag)(item.flags);
@@ -1073,15 +1076,16 @@ class ChromeDocument extends Document {
1073
1076
  const items = new Set((asset.watch.assets || []));
1074
1077
  (function recurse(children) {
1075
1078
  for (const item of children) {
1076
- if (!items.has(item)) {
1077
- if (isWatched.call(instance, item)) {
1078
- item.flags |= 8;
1079
- }
1080
- items.add(item);
1081
- const next = related.get(item);
1082
- if (next) {
1083
- recurse(next);
1084
- }
1079
+ if (items.has(item)) {
1080
+ continue;
1081
+ }
1082
+ if (isWatched.call(instance, item)) {
1083
+ item.flags |= 8;
1084
+ }
1085
+ items.add(item);
1086
+ const next = related.get(item);
1087
+ if (next) {
1088
+ recurse(next);
1085
1089
  }
1086
1090
  }
1087
1091
  })(includes);
@@ -1090,34 +1094,37 @@ class ChromeDocument extends Document {
1090
1094
  }
1091
1095
  }
1092
1096
  let productionRelease = instance.productionRelease;
1093
- if ((0, types_1.isString)(productionRelease)) {
1094
- if (path.isAbsolute(productionRelease = path.normalize(productionRelease)) && isDir(productionRelease)) {
1095
- if (this.canWrite(productionRelease)) {
1096
- const serverRoot = ChromeDocument.INTERNAL_SERVERROOT;
1097
- const srcDir = path.join(this.baseDirectory, serverRoot);
1098
- if (isDir(srcDir)) {
1099
- const result = await Document.copyDir(srcDir, productionRelease, this.incremental !== 'staging');
1100
- const failed = result.failed.map(value => this.removeCwd(value));
1101
- for (const value of this.files) {
1102
- if (value.startsWith(serverRoot)) {
1103
- if (!failed.includes(value)) {
1104
- this.delete(value);
1105
- }
1106
- else {
1107
- instance.writeFail(["Unable to move file", instance.moduleName], (0, types_1.errorMessage)('production', path.join(this.baseDirectory, value)), { fatal: true });
1108
- }
1109
- }
1110
- }
1111
- }
1097
+ if (!(0, types_1.isString)(productionRelease)) {
1098
+ return;
1099
+ }
1100
+ if (path.isAbsolute(productionRelease = path.normalize(productionRelease)) && isDir(productionRelease)) {
1101
+ if (this.canWrite(productionRelease)) {
1102
+ const serverRoot = ChromeDocument.INTERNAL_SERVERROOT;
1103
+ const srcDir = path.join(this.baseDirectory, serverRoot);
1104
+ if (!isDir(srcDir)) {
1105
+ return;
1112
1106
  }
1113
- else {
1114
- instance.writeFail(["Unable to write directory", instance.moduleName], (0, types_1.errorMessage)('production', 'Access denied', productionRelease));
1107
+ const result = await Document.copyDir(srcDir, productionRelease, this.incremental !== 'staging');
1108
+ const failed = result.failed.map(value => this.removeCwd(value));
1109
+ for (const value of this.files) {
1110
+ if (!value.startsWith(serverRoot)) {
1111
+ continue;
1112
+ }
1113
+ if (!failed.includes(value)) {
1114
+ this.delete(value);
1115
+ }
1116
+ else {
1117
+ instance.writeFail(["Unable to move file", instance.moduleName], (0, types_1.errorMessage)('production', path.join(this.baseDirectory, value)), { fatal: true });
1118
+ }
1115
1119
  }
1116
1120
  }
1117
1121
  else {
1118
- instance.writeFail(["Unable to read directory", instance.moduleName], (0, types_1.errorMessage)('production', 'Invalid directory', productionRelease), 32);
1122
+ instance.writeFail(["Unable to write directory", instance.moduleName], (0, types_1.errorMessage)('production', 'Access denied', productionRelease));
1119
1123
  }
1120
1124
  }
1125
+ else {
1126
+ instance.writeFail(["Unable to read directory", instance.moduleName], (0, types_1.errorMessage)('production', 'Invalid directory', productionRelease), 32);
1127
+ }
1121
1128
  }
1122
1129
  static sanitizeAssets(assets, exclusions = []) {
1123
1130
  assets.forEach(item => {
@@ -1198,6 +1205,7 @@ class ChromeDocument extends Document {
1198
1205
  }
1199
1206
  return 0;
1200
1207
  });
1208
+ let imports;
1201
1209
  if (config) {
1202
1210
  const { useUnsafeReplace, baseUrl, productionRelease, productionIncremental, templateMap, userAgentData, cache } = config;
1203
1211
  const target = this.config;
@@ -1244,25 +1252,37 @@ class ChromeDocument extends Document {
1244
1252
  if ((0, types_1.isObject)(userAgentData)) {
1245
1253
  this.userAgentData = userAgentData;
1246
1254
  }
1247
- const imports = (0, types_1.isPlainObject)(config.imports) ? { ...this.module.imports, ...config.imports } : this.module.imports;
1248
- if (imports) {
1249
- this.imports = imports;
1250
- }
1251
1255
  if ((0, types_1.isObject)(cache) && 'transform' in cache) {
1252
1256
  this.customize({ transform: cache.transform });
1253
1257
  }
1258
+ if (!(0, types_1.isPlainObject)(imports = config.imports)) {
1259
+ imports = undefined;
1260
+ }
1254
1261
  }
1255
1262
  super.init(assets, config);
1256
1263
  const mimeMap = this._mimeMap;
1257
- if (mimeMap && 'format' in mimeMap) {
1258
- const format = mimeMap.format;
1259
- if ((0, types_1.isObject)(format)) {
1260
- this.formatMap = 'pathname' in format || 'filename' in format || 'dictionary' in format ? { uuid: format } : format;
1264
+ if (mimeMap) {
1265
+ if ('imports' in mimeMap) {
1266
+ const imported = mimeMap.imports;
1267
+ if ((0, types_1.isPlainObject)(imported)) {
1268
+ imports = imports ? Object.assign(imported, imports) : imported;
1269
+ }
1270
+ delete mimeMap.imports;
1261
1271
  }
1262
- else {
1263
- this.formatMap = undefined;
1272
+ if ('format' in mimeMap) {
1273
+ const format = mimeMap.format;
1274
+ if ((0, types_1.isObject)(format)) {
1275
+ this.formatMap = 'pathname' in format || 'filename' in format || 'dictionary' in format ? { uuid: format } : format;
1276
+ }
1277
+ else {
1278
+ this.formatMap = undefined;
1279
+ }
1280
+ delete mimeMap.format;
1264
1281
  }
1265
1282
  }
1283
+ if (imports) {
1284
+ this.imports = imports;
1285
+ }
1266
1286
  for (const storage of cloud) {
1267
1287
  for (const { service, upload, download } of storage) {
1268
1288
  if (upload) {
@@ -1630,14 +1650,14 @@ class ChromeDocument extends Document {
1630
1650
  }
1631
1651
  }
1632
1652
  replaceContent(source, statement, mimeType) {
1633
- var _a;
1653
+ var _a, _b;
1634
1654
  switch (mimeType) {
1635
1655
  case 'text/css': {
1636
1656
  const match = REGEXP_REPLACECSS.exec((typeof statement === 'string' ? statement : statement[0]).trim());
1637
1657
  if (match) {
1638
1658
  const layer = match[1];
1639
1659
  const supports = (_a = match[3]) === null || _a === void 0 ? void 0 : _a.trim();
1640
- const query = match[4].trim();
1660
+ const query = match[4].trim().replace(/;+$/, '');
1641
1661
  if (layer || supports || query) {
1642
1662
  const newline = (0, util_1.getNewline)(source);
1643
1663
  let result = supports ? `@supports (${supports}) {` + newline : '';
@@ -1645,8 +1665,8 @@ class ChromeDocument extends Document {
1645
1665
  result += `@media ${query} {` + newline;
1646
1666
  }
1647
1667
  if (layer) {
1648
- let name = match[2];
1649
- result += '@layer ' + (name && (name = name.trim()) ? name + ' ' : '') + `{${newline + source + newline}}` + (query ? newline + '}' : '');
1668
+ const name = (_b = match[2]) === null || _b === void 0 ? void 0 : _b.replace(/\s+/g, '');
1669
+ result += '@layer ' + (name ? name.slice(1, -1) + ' ' : '') + `{${newline + source + newline}}` + (query ? newline + '}' : '');
1650
1670
  }
1651
1671
  else if (query) {
1652
1672
  result += source + newline + '}';
@@ -1690,8 +1710,9 @@ class ChromeDocument extends Document {
1690
1710
  this._cloudUrlMap = Object.create(null);
1691
1711
  this._cloudUploaded = new Set();
1692
1712
  this._cloudEndpoint = null;
1693
- if (this.htmlFile) {
1694
- const endpoint = (_b = (_a = instance.getStorage('upload', this.htmlFile.cloudStorage)) === null || _a === void 0 ? void 0 : _a.upload) === null || _b === void 0 ? void 0 : _b.endpoint;
1713
+ const htmlFile = this.htmlFile;
1714
+ if (htmlFile) {
1715
+ 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;
1695
1716
  if (endpoint) {
1696
1717
  this._cloudEndpoint = new RegExp((0, types_1.escapePattern)(toPosix(endpoint)) + '/', 'g');
1697
1718
  }
@@ -1872,9 +1893,7 @@ class ChromeDocument extends Document {
1872
1893
  }
1873
1894
  }
1874
1895
  search !== null && search !== void 0 ? search : (search = restoreSearchParams((_a = asset.url) === null || _a === void 0 ? void 0 : _a.search));
1875
- if (status) {
1876
- status = status.filter(item => item.type >= types_1.STATUS_TYPE.FATAL && item.type <= types_1.STATUS_TYPE.WARN);
1877
- }
1896
+ status && (status = status.filter(item => item.type >= types_1.STATUS_TYPE.FATAL && item.type <= types_1.STATUS_TYPE.WARN));
1878
1897
  watch.send(types_1.WATCH_EVENT.MODIFIED, {
1879
1898
  action: pathname && watch.hot && !watch.main ? 'hot' : '',
1880
1899
  type: asset.mimeType,
@@ -2051,8 +2070,9 @@ class ChromeDocument extends Document {
2051
2070
  item.modified = true;
2052
2071
  }
2053
2072
  source = sanitizeSource(item, source);
2054
- if (item.format) {
2055
- const result = await this.transform('html', source, item.format, transformOptions.call(this, item, 'image/svg+xml'));
2073
+ const format = item.format;
2074
+ if (format) {
2075
+ const result = await this.transform('html', source, format, transformOptions.call(this, item, 'image/svg+xml'));
2056
2076
  if (result) {
2057
2077
  item.modified = true;
2058
2078
  source = result.code;
@@ -2162,11 +2182,12 @@ class ChromeDocument extends Document {
2162
2182
  await this.setElementAttributes(processing, domBase);
2163
2183
  await this.applyDataSource(processing, domBase);
2164
2184
  for (const item of this.assets) {
2165
- if (item.element && isRemoved(item) && !(0, types_1.ignoreFlag)(item.flags)) {
2166
- const domElement = new dom_1.HtmlElement(moduleName, item.element, item.attributes);
2185
+ const element = item.element;
2186
+ if (element && isRemoved(item) && !(0, types_1.ignoreFlag)(item.flags)) {
2187
+ const domElement = new dom_1.HtmlElement(moduleName, element, item.attributes);
2167
2188
  domElement.remove = true;
2168
2189
  if (!domBase.write(domElement)) {
2169
- this.writeFail('Unable to exclude HTML element', errorHtml(item.element), 4);
2190
+ this.writeFail('Unable to exclude HTML element', errorHtml(element), 4);
2170
2191
  }
2171
2192
  }
2172
2193
  }
@@ -2187,13 +2208,15 @@ class ChromeDocument extends Document {
2187
2208
  if ((0, types_1.isString)(config.stripCommentsAndCDATA)) {
2188
2209
  source = dom_1.DomWriter.getCommentsAndCDATA(source, config.stripCommentsAndCDATA, true, true);
2189
2210
  }
2190
- if (htmlFile.format) {
2191
- const result = await this.transform('html', source, htmlFile.format, {
2211
+ const format = htmlFile.format;
2212
+ if (format) {
2213
+ const { filename, uri, encoding, metadata } = htmlFile;
2214
+ const result = await this.transform('html', source, format, {
2192
2215
  pathname: path.dirname(localUri),
2193
- filename: htmlFile.filename,
2216
+ filename,
2194
2217
  mimeType: 'text/html',
2195
- metadata: Object.assign({ '__fromhtml__': true, ...this.config }, htmlFile.metadata),
2196
- cacheData: !productionRelease || this.productionIncremental ? { uri: htmlFile.uri, encoding: htmlFile.encoding } : undefined
2218
+ metadata: Object.assign({ '__fromhtml__': true, ...this.config }, metadata),
2219
+ cacheData: !productionRelease || this.productionIncremental ? { uri, encoding } : undefined
2197
2220
  });
2198
2221
  if (result) {
2199
2222
  source = result.code;
@@ -2227,12 +2250,12 @@ class ChromeDocument extends Document {
2227
2250
  const cloud = host.Cloud;
2228
2251
  const removeWatchReload = (item) => (0, types_1.isObject)(item.watch) && delete item.watch.reload;
2229
2252
  for (const item of this.assets) {
2230
- const element = item.element;
2253
+ const { element, inlineContent } = item;
2231
2254
  if (!element || element.removed || isRemoved(item) || isUnedited(item) || (0, types_1.ignoreFlag)(item.flags) && !(0, types_1.processFlag)(item.flags)) {
2232
2255
  continue;
2233
2256
  }
2234
2257
  const domElement = new dom_1.HtmlElement(moduleName, element, item.attributes);
2235
- if (item.inlineContent) {
2258
+ if (inlineContent) {
2236
2259
  let [innerXml, sourceMappingURL, inlineMap] = transform_1.SourceMap.removeSourceMappingURL(host.getUTF8String(item).trim());
2237
2260
  if (sourceMappingURL && !inlineMap && item.localUri) {
2238
2261
  let mapUri = path.resolve(sourceMappingURL = decodeURIComponent(sourceMappingURL));
@@ -2241,7 +2264,7 @@ class ChromeDocument extends Document {
2241
2264
  }
2242
2265
  host.deleteFile(mapUri);
2243
2266
  }
2244
- domElement.tagName = item.inlineContent;
2267
+ domElement.tagName = inlineContent;
2245
2268
  domElement.innerXml = innerXml;
2246
2269
  domElement.removeAttribute('src', 'href');
2247
2270
  }
@@ -2331,10 +2354,10 @@ class ChromeDocument extends Document {
2331
2354
  }
2332
2355
  }
2333
2356
  if (!domBase.write(domElement)) {
2334
- this.writeFail(item.inlineContent ? 'Inline tag replacement' : 'Element attribute replacement', errorHtml(element), { type: 4, startTime });
2357
+ this.writeFail(inlineContent ? 'Inline tag replacement' : 'Element attribute replacement', errorHtml(element), { type: 4, startTime });
2335
2358
  delete item.inlineUrlCloud;
2336
2359
  }
2337
- else if (item.inlineContent) {
2360
+ else if (inlineContent) {
2338
2361
  host.removeAsset(item);
2339
2362
  removeWatchReload(item);
2340
2363
  }
@@ -2931,7 +2954,7 @@ class ChromeDocument extends Document {
2931
2954
  for (let j = 0, match; j < items.length; ++j) {
2932
2955
  const row = items[j];
2933
2956
  if ((0, types_1.isPlainObject)(row)) {
2934
- (_c = row['__index__']) !== null && _c !== void 0 ? _c : (row['__index__'] = j + 1);
2957
+ (_c = row.__index__) !== null && _c !== void 0 ? _c : (row.__index__ = j + 1);
2935
2958
  }
2936
2959
  let segment = template;
2937
2960
  while (match = REGEXP_TEMPLATECONDITIONAL.exec(segment)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/chrome",
3
- "version": "0.3.6",
3
+ "version": "0.3.8",
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.6.16",
24
- "@e-mc/core": "^0.6.16",
25
- "@e-mc/document": "^0.6.16",
26
- "@e-mc/types": "^0.6.16"
23
+ "@e-mc/cloud": "^0.6.19",
24
+ "@e-mc/core": "^0.6.19",
25
+ "@e-mc/document": "^0.6.19",
26
+ "@e-mc/types": "^0.6.19"
27
27
  }
28
28
  }
package/types/index.d.ts CHANGED
@@ -104,10 +104,11 @@ export interface IChromeDocument<T extends IFileManager<U>, U extends DocumentAs
104
104
  cloudObject(state: CloudScopeOrigin<T, U, V>, file: U): boolean;
105
105
  cloudUpload(state: CloudScopeOrigin<T, U, V>, file: U, url: string, active: boolean): Promise<boolean>;
106
106
  cloudFinalize(state: CloudScopeOrigin<T, U, V>): Promise<unknown[]>;
107
- get settings(): ChromeDocumentSettings;
108
107
  get editing(): U[];
108
+ set dataSource(value);
109
109
  get dataSource(): DataSource[];
110
110
  get elements(): XmlTagNode[];
111
+ get settings(): ChromeDocumentSettings;
111
112
  }
112
113
 
113
114
  export interface ChromeDocumentConstructor<T extends IFileManager<U>, U extends DocumentAsset = DocumentAsset> extends DocumentConstructor<T, U> {