@pi-r/chrome 0.3.7 → 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 (2) hide show
  1. package/index.js +12 -17
  2. package/package.json +5 -5
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');
@@ -190,7 +190,7 @@ function hasCondition(data, condition) {
190
190
  if (items.length && !isSpace(match[0][0])) {
191
191
  return false;
192
192
  }
193
- items.push([match[1], trimQuote(match[2]), trimQuote(match[3])]);
193
+ items.push([match[1], trimQuote(match[2]), match[3] ? trimQuote(match[3]) : '']);
194
194
  }
195
195
  REGEXP_TEMPLATECOMPARISON.lastIndex = 0;
196
196
  const length = items.length;
@@ -201,18 +201,13 @@ function hasCondition(data, condition) {
201
201
  if (!isNaN(+value)) {
202
202
  return +value;
203
203
  }
204
- if (match = /^(["'])([\S\s]*)\1$/.exec(value)) {
205
- return match[2];
206
- }
207
204
  return getObjectValue(data, value);
208
205
  };
209
206
  for (let i = 0; i < length; ++i) {
210
- const item = items[i];
211
- const arg1 = item[1];
212
- const arg2 = item[2];
213
- let valid;
207
+ const [cmp, arg1, arg2] = items[i];
208
+ let valid = false;
214
209
  if (arg2) {
215
- switch (item[0]) {
210
+ switch (cmp) {
216
211
  case 'eq':
217
212
  valid = parseArg(arg1) == parseArg(arg2);
218
213
  break;
@@ -235,7 +230,7 @@ function hasCondition(data, condition) {
235
230
  return false;
236
231
  }
237
232
  }
238
- else if (item[0]) {
233
+ else if (cmp) {
239
234
  return false;
240
235
  }
241
236
  else {
@@ -386,7 +381,7 @@ function transformURL(host, parent, type, source, importFile) {
386
381
  const baseHref = getBaseURLs(importFile || parent, this.baseUrl);
387
382
  const isHtml = type === 'html';
388
383
  const isJs = type === 'js';
389
- 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;
390
385
  let length = source.length, modified, match;
391
386
  while (match = pattern.exec(source)) {
392
387
  const isText = !!match[1];
@@ -558,7 +553,7 @@ function transformURL(host, parent, type, source, importFile) {
558
553
  if (!isText) {
559
554
  let j = startIndex;
560
555
  while (isSpace(source[--j])) { }
561
- valid = source.substring(k = j - 6, j + 1) === '@import';
556
+ valid = source.substring(k = j - 6, j + 1).toLowerCase() === '@import';
562
557
  }
563
558
  else {
564
559
  k = startIndex;
@@ -1655,14 +1650,14 @@ class ChromeDocument extends Document {
1655
1650
  }
1656
1651
  }
1657
1652
  replaceContent(source, statement, mimeType) {
1658
- var _a;
1653
+ var _a, _b;
1659
1654
  switch (mimeType) {
1660
1655
  case 'text/css': {
1661
1656
  const match = REGEXP_REPLACECSS.exec((typeof statement === 'string' ? statement : statement[0]).trim());
1662
1657
  if (match) {
1663
1658
  const layer = match[1];
1664
1659
  const supports = (_a = match[3]) === null || _a === void 0 ? void 0 : _a.trim();
1665
- const query = match[4].trim();
1660
+ const query = match[4].trim().replace(/;+$/, '');
1666
1661
  if (layer || supports || query) {
1667
1662
  const newline = (0, util_1.getNewline)(source);
1668
1663
  let result = supports ? `@supports (${supports}) {` + newline : '';
@@ -1670,8 +1665,8 @@ class ChromeDocument extends Document {
1670
1665
  result += `@media ${query} {` + newline;
1671
1666
  }
1672
1667
  if (layer) {
1673
- let name = match[2];
1674
- 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 + '}' : '');
1675
1670
  }
1676
1671
  else if (query) {
1677
1672
  result += source + newline + '}';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/chrome",
3
- "version": "0.3.7",
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
  }