@pi-r/chrome 0.9.4 → 0.9.6

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 +27 -28
  2. package/package.json +5 -5
package/index.js CHANGED
@@ -28,11 +28,11 @@ const [REGEXP_NTHCHILD, REGEXP_NTHCHILD_UNSAFE, REGEXP_REPLACECSS] = (function (
28
28
  return [
29
29
  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'),
30
30
  new RegExp(`\\(\\s*([+-])?(?:(\\d*)[nN]|(0))?\\s*([+-])?\\s*(\\d*)(?:\\s+[oO][fF]\\s+(${parenthesis})\\s*\\)|\\s*\\))`, 'g'),
31
- new RegExp(`^@import\\s+(?:url\\((?:[^)]|(?<=\\\\)\\))+\\)|"(?:[^"]|(?<=\\\\)")+"|'(?:[^']|(?<=\\\\)')+')(\\s*layer(?:\\(([^)]*)\\)|\\b))?(?:\\s*supports\\((${parenthesis})\\))?(.*?);?$`)
31
+ new RegExp(`^@import\\s+(?:url\\((?:[^)]|(?<=\\\\)\\))+\\)|"(?:[^"]|(?<=\\\\)")+"|'(?:[^']|(?<=\\\\)')+')(\\s*layer(\\([^)]*\\))?)?(?:\\s*supports\\((${parenthesis})\\))?(.*)$`, 'si')
32
32
  ];
33
33
  })();
34
34
  const REGEXP_SRCSETSIZE = /~\s*([\d.]+)\s*([wx])/i;
35
- const REGEXP_TEMPLATECONDITIONAL = /(\n\s+)?\{\{if\s+((?:[^}]|}(?!}))+?)\}\}(\s*)(.*?)(?:\s*\{\{else(?:\s+if\s+((?:[^}]|}(?!}))+?))?\}\}(\s*)(.*?)\s*)?\s*\{\{end\}\}/gs;
35
+ const REGEXP_TEMPLATECONDITIONAL = /(\n\s+)?\{\{if\s+((?:[^}]|}(?!}))+?)\}\}(\s*)([\S\s]*?)(?:\s*\{\{else(?:\s+if\s+((?:[^}]|}(?!}))+?))?\}\}(\s*)([\S\s]*?)\s*)?\s*\{\{end\}\}/g;
36
36
  const REGEXP_TEMPLATECOMPARISON = /\s*\(\s*(?:\b(eq|ne|lt|le|gt|ge)\s+)?("[^"]+"|'[^']+'|[^\s)]+)(?:\s+("[^"]+"|'[^']+'|[^\s)]+))?\s*\)/g;
37
37
  const REGEXP_TEMPLATEMATCH = new RegExp(`^(?:\\b(and|or|not)\\s+)?((?:${REGEXP_TEMPLATECOMPARISON.source})+)|(!|not\\s+)?([^\\s][\\S\\s]*)$`);
38
38
  const REGEXP_IMPORTMODULE = /(?:(?:^|[\n;]+)\s*import\s+(?:("(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+')|.+?from\s+("(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+')(?:[ \t]+(?:assert|with)[ \t]+\{((?:"(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+'|`(?:[^`]|(?<=\\)`)+`|{[^{]*{|{[^}]*}|}[^}]*}|[^"'`]+)+)\})?)|\bimport\(\s*("(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+')\s*(?:,\s*\{((?:"(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+'|`(?:[^`]|(?<=\\)`)+`|{[^{]*{|{[^}]*}|}[^}]*}|[^"'`]+)+)\}\s*)?\))/gd;
@@ -54,9 +54,9 @@ const REGEXP_OBJECT_NAME = /([^[.\s]+)((?:\s*\[[^\]]+\]\s*)+)?\s*\.?\s*/g;
54
54
  const REGEXP_OBJECT_SUBSCRIPT = /\[\s*(["'])?(.+?)\1\s*\]/g;
55
55
  const REGEXP_TEMPLATE_LEADING = /\s*\{\{- \s*((?:[^}]|}(?!}))+?)\}\}/g;
56
56
  const REGEXP_TEMPLATE_TRAILING = /\{\{((?:[^}]|}(?!}))+?)\s*? -\}\}\s*/g;
57
- const REGEXP_URL = /(?:\b[Uu][Rr][Ll]\(|@import\s+(["'])|\b([Hh][Rr][Ee][Ff])\s*=)/g;
57
+ const REGEXP_URL = /(?:\burl\(|@import\s+(["'])|\b(href)\s*=)/gi;
58
58
  const REGEXP_URL_JS = /\bimport\(/g;
59
- const REGEXP_URL_SVG = /(?:\b[Uu][Rr][Ll]\(|@import\s+(["'])|\b([Hh][Rr][Ee][Ff])\s*=)/g;
59
+ const REGEXP_URL_SVG = /(?:\burl\(|@import\s+(["'])|\b(href)\s*=)/gi;
60
60
  const REGEXP_IMAGESET = /\b(?:-webkit-)?image-set\(/gi;
61
61
  const REGEXP_IMAGESET_URL = /(?:^|[^(])\s*("(\s*[^)][^"]*)"|'(\s*[^)][^"]*)')\s*(?:,|$|[^)][^,]*,?)/gd;
62
62
  const REGEXP_SANITIZEALL = new RegExp(`(?:\\s+|\\b)data-(?:pathname|filename|intl-locales|(?:use|exclude)-[^=\\s]+)\\s*${dom_1.DomWriter.PATTERN_ATTRVALUE}(?=(?:[^"<]+"[^"]*"|[^'<]+'[^']*')*[^<>]*>)`, 'g');
@@ -189,10 +189,6 @@ function parseArg(data, value) {
189
189
  if (!isNaN(n)) {
190
190
  return n;
191
191
  }
192
- const match = /^(["'])(.*)\1$/s.exec(value);
193
- if (match) {
194
- return match[2];
195
- }
196
192
  return getObjectValue(data, value);
197
193
  }
198
194
  function hasCondition(data, condition) {
@@ -209,7 +205,7 @@ function hasCondition(data, condition) {
209
205
  if (items.length > 0 && !isSpace(match[0][0])) {
210
206
  return false;
211
207
  }
212
- items.push([match[1], trimQuote(match[2]), trimQuote(match[3])]);
208
+ items.push([match[1], trimQuote(match[2]), match[3] ? trimQuote(match[3]) : '']);
213
209
  }
214
210
  REGEXP_TEMPLATECOMPARISON.lastIndex = 0;
215
211
  const length = items.length;
@@ -217,12 +213,10 @@ function hasCondition(data, condition) {
217
213
  return false;
218
214
  }
219
215
  for (let i = 0; i < length; ++i) {
220
- const item = items[i];
221
- const arg1 = item[1];
222
- const arg2 = item[2];
223
- let valid;
216
+ const [cmp, arg1, arg2] = items[i];
217
+ let valid = false;
224
218
  if (arg2) {
225
- switch (item[0]) {
219
+ switch (cmp) {
226
220
  case 'eq':
227
221
  valid = parseArg(data, arg1) == parseArg(data, arg2);
228
222
  break;
@@ -245,7 +239,7 @@ function hasCondition(data, condition) {
245
239
  return false;
246
240
  }
247
241
  }
248
- else if (item[0]) {
242
+ else if (cmp) {
249
243
  return false;
250
244
  }
251
245
  else {
@@ -596,7 +590,7 @@ function transformURL(instance, host, parent, type, source, importFile) {
596
590
  if (!isText) {
597
591
  let j = startIndex;
598
592
  while (isSpace(source[--j])) { }
599
- valid = source.substring(k = j - 6, j + 1) === '@import';
593
+ valid = source.substring(k = j - 6, j + 1).toLowerCase() === '@import';
600
594
  }
601
595
  else {
602
596
  k = startIndex;
@@ -1827,7 +1821,7 @@ class ChromeDocument extends Document {
1827
1821
  if (match) {
1828
1822
  const layer = match[1];
1829
1823
  const supports = match[3]?.trim();
1830
- const query = match[4].trim();
1824
+ const query = match[4].trim().replace(/;+$/, '');
1831
1825
  if (layer || supports || query) {
1832
1826
  const newline = (0, util_1.getNewline)(source);
1833
1827
  let result = supports ? `@supports (${supports}) {` + newline : '';
@@ -1835,8 +1829,8 @@ class ChromeDocument extends Document {
1835
1829
  result += `@media ${query} {` + newline;
1836
1830
  }
1837
1831
  if (layer) {
1838
- let name = match[2];
1839
- result += '@layer ' + (name && (name = name.trim()) ? name + ' ' : '') + `{${newline + source + newline}}` + (query ? newline + '}' : '');
1832
+ const name = match[2]?.replace(/\s+/g, '');
1833
+ result += '@layer ' + (name ? name.slice(1, -1) + ' ' : '') + `{${newline + source + newline}}` + (query ? newline + '}' : '');
1840
1834
  }
1841
1835
  else if (query) {
1842
1836
  result += source + newline + '}';
@@ -2920,13 +2914,15 @@ class ChromeDocument extends Document {
2920
2914
  case 'mongodb':
2921
2915
  for (let j = 0; j < length; ++j) {
2922
2916
  const cmd = batch[j];
2923
- cmd.cacheObjectKey = typeof cmd.cascade === 'string' ? cmd.cascade : '';
2917
+ if (cmd.cascade) {
2918
+ cmd.cacheObjectKey ||= cmd.cascade;
2919
+ }
2924
2920
  }
2925
2921
  break;
2926
2922
  case 'redis':
2927
2923
  for (let j = 0; j < length; ++j) {
2928
2924
  const cmd = batch[j];
2929
- const { search, key, query, cascade } = cmd;
2925
+ const search = cmd.search;
2930
2926
  if ((0, types_1.isObject)(search) && typeof search.schema === 'string') {
2931
2927
  const pathname = this.resolveDir('schema', search.schema);
2932
2928
  if (pathname) {
@@ -2952,8 +2948,11 @@ class ChromeDocument extends Document {
2952
2948
  search.schema = undefined;
2953
2949
  }
2954
2950
  }
2955
- if (key) {
2956
- cmd.cacheObjectKey = ((0, types_1.isString)(cascade) ? cascade : '') + '_' + ((0, types_1.isString)(query) ? query : '');
2951
+ if (cmd.key) {
2952
+ const { cascade, query } = cmd;
2953
+ if (cascade || query) {
2954
+ cmd.cacheObjectKey ||= (cascade ? cascade : '') + '_' + (query ? Document.asString(query, true) : '');
2955
+ }
2957
2956
  }
2958
2957
  }
2959
2958
  break;
@@ -3136,20 +3135,20 @@ class ChromeDocument extends Document {
3136
3135
  }
3137
3136
  REGEXP_TEMPLATECONDITIONAL.lastIndex = 0;
3138
3137
  const literal = segment.trim();
3139
- if (literal.startsWith('`') && literal.endsWith('`')) {
3138
+ if (literal.at(0) === '`' && literal.at(-1) === '`') {
3140
3139
  if (!this.hasEval('function')) {
3141
3140
  errors = (0, types_1.errorMessage)('eval', "Unsupported access", 'function');
3142
3141
  continue;
3143
3142
  }
3144
3143
  try {
3145
- let content = new Function('return ' + literal + ';')(row);
3144
+ let unsafe = new Function('return ' + literal + ';').call(row);
3146
3145
  if (!segment.startsWith('`')) {
3147
- content = segment.substring(0, segment.indexOf('`')) + content;
3146
+ unsafe = segment.substring(0, segment.indexOf('`')) + unsafe;
3148
3147
  }
3149
3148
  if (!segment.endsWith('`')) {
3150
- content += segment.substring(segment.lastIndexOf('`') + 1);
3149
+ unsafe += segment.substring(segment.lastIndexOf('`') + 1);
3151
3150
  }
3152
- segment = content;
3151
+ segment = unsafe;
3153
3152
  }
3154
3153
  catch (err) {
3155
3154
  errors = err instanceof Error ? err : true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/chrome",
3
- "version": "0.9.4",
3
+ "version": "0.9.6",
4
4
  "description": "Chrome document constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -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.11.5",
24
- "@e-mc/core": "^0.11.5",
25
- "@e-mc/document": "^0.11.5",
26
- "@e-mc/types": "^0.11.5"
23
+ "@e-mc/cloud": "^0.11.18",
24
+ "@e-mc/core": "^0.11.18",
25
+ "@e-mc/document": "^0.11.18",
26
+ "@e-mc/types": "^0.11.18"
27
27
  }
28
28
  }