@pi-r/chrome 0.10.3 → 0.10.5

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 +28 -29
  2. package/package.json +5 -5
package/index.js CHANGED
@@ -30,12 +30,12 @@ const [REGEXP_NTHCHILD, REGEXP_NTHCHILD_UNSAFE, REGEXP_REPLACECSS] = (function (
30
30
  return [
31
31
  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'),
32
32
  new RegExp(`\\(\\s*([+-])?(?:(\\d*)[nN]|(0))?\\s*([+-])?\\s*(\\d*)(?:\\s+[oO][fF]\\s+(${parenthesis})\\s*\\)|\\s*\\))`, 'g'),
33
- new RegExp(`^@import\\s+(?:url\\((?:[^)]|(?<=\\\\)\\))+\\)|"(?:[^"]|(?<=\\\\)")+"|'(?:[^']|(?<=\\\\)')+')(\\s*layer(?:\\(([^)]*)\\)|\\b))?(?:\\s*supports\\((${parenthesis})\\))?(.*?);?$`)
33
+ new RegExp(`^@import\\s+(?:url\\((?:[^)]|(?<=\\\\)\\))+\\)|"(?:[^"]|(?<=\\\\)")+"|'(?:[^']|(?<=\\\\)')+')(\\s*layer(\\([^)]*\\))?)?(?:\\s*supports\\((${parenthesis})\\))?(.*)$`, 'si')
34
34
  ];
35
35
  })();
36
36
  const REGEXP_SRCSETSIZE = /~\s*([\d.]+)\s*([wx])/i;
37
- const REGEXP_TEMPLATECONDITIONAL = /(\n\s+)?\{\{\s*if\s+((?:[^}]|}(?!}))+?)\}\}(\s*)(.*?)((?:\s*\{\{\s*else if\s+(?:(?:[^}]|}(?!}))+?)\}\}.*?)*)(?:\s*\{\{\s*else\s*\}\}(\s*)(.*?))?\s*\{\{\s*end\s*\}\}/gs;
38
- const REGEXP_TEMPLATEELSEIF = /\{\{\s*else if\s+((?:[^}]|}(?!}))+?)\}\}(\s*)((?:.(?!\{\{\s*else if))*)/gs;
37
+ const REGEXP_TEMPLATECONDITIONAL = /(\n\s+)?\{\{\s*if\s+((?:[^}]|}(?!}))+?)\}\}(\s*)([\S\s]*?)((?:\s*\{\{\s*else if\s+(?:(?:[^}]|}(?!}))+?)\}\}[\S\s]*?)*)(?:\s*\{\{\s*else\s*\}\}(\s*)([\S\s]*?))?\s*\{\{\s*end\s*\}\}/g;
38
+ const REGEXP_TEMPLATEELSEIF = /\{\{\s*else if\s+((?:[^}]|}(?!}))+?)\}\}(\s*)((?:[\S\s](?!\{\{\s*else if))*)/g;
39
39
  const REGEXP_TEMPLATECOMPARISON = /\s*\(\s*(?:(eq|ne|lt|le|gt|ge)\s+)?("[^"]+"|'[^']+'|[^\s)]+)(?:\s+("[^"]+"|'[^']+'|[^\s)]+))?\s*\)/g;
40
40
  const REGEXP_TEMPLATEMATCH = new RegExp(`^(?:(and|or|not)\\s+)?((?:${REGEXP_TEMPLATECOMPARISON.source})+)|(!|not\\s+)?([^\\s][\\S\\s]*)$`);
41
41
  const REGEXP_IMPORTMODULE = /(?:(?:^|[\n;]+)\s*import\s+(?:("(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+')|.+?from\s+("(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+')(?:[ \t]+with[ \t]+\{((?:"(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+'|`(?:[^`]|(?<=\\)`)+`|{[^{]*{|{[^}]*}|}[^}]*}|[^"'`]+)+)\})?)|\bimport\(\s*("(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+')\s*(?:,\s*\{((?:"(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+'|`(?:[^`]|(?<=\\)`)+`|{[^{]*{|{[^}]*}|}[^}]*}|[^"'`]+)+)\}\s*)?\))/gd;
@@ -57,9 +57,9 @@ const REGEXP_OBJECT_NAME = /([^[.\s]+)((?:\s*\[[^\]]+\]\s*)+)?\s*\.?\s*/g;
57
57
  const REGEXP_OBJECT_SUBSCRIPT = /\[\s*(["'])?(.+?)\1\s*\]/g;
58
58
  const REGEXP_TEMPLATE_LEADING = /\s*\{\{- \s*((?:[^}]|}(?!}))+?)\}\}/g;
59
59
  const REGEXP_TEMPLATE_TRAILING = /\{\{((?:[^}]|}(?!}))+?)\s*? -\}\}\s*/g;
60
- const REGEXP_URL = /(?:\b[Uu][Rr][Ll]\(|@import\s+(["'])|\b([Hh][Rr][Ee][Ff])\s*=)/g;
60
+ const REGEXP_URL = /(?:\burl\(|@import\s+(["'])|\b(href)\s*=)/gi;
61
61
  const REGEXP_URL_JS = /\bimport\(/g;
62
- const REGEXP_URL_SVG = /(?:\b[Uu][Rr][Ll]\(|@import\s+(["'])|\b([Hh][Rr][Ee][Ff])\s*=)/g;
62
+ const REGEXP_URL_SVG = /(?:\burl\(|@import\s+(["'])|\b(href)\s*=)/gi;
63
63
  const REGEXP_IMAGESET = /\b(?:-webkit-)?image-set\(/gi;
64
64
  const REGEXP_IMAGESET_URL = /(?:^|[^(])\s*("(\s*[^)][^"]*)"|'(\s*[^)][^"]*)')\s*(?:,|$|[^)][^,]*,?)/gd;
65
65
  const REGEXP_SANITIZEALL = new RegExp(`(?:\\s+|\\b)data-(?:pathname|filename|intl-locales|(?:use|exclude)-[^=\\s]+)\\s*${dom_1.DomWriter.PATTERN_ATTRVALUE}(?=(?:[^"<]+"[^"]*"|[^'<]+'[^']*')*[^<>]*>)`, 'g');
@@ -186,10 +186,6 @@ function parseArg(data, value) {
186
186
  if (!isNaN(n)) {
187
187
  return n;
188
188
  }
189
- const match = /^(["'])(.*)\1$/s.exec(value);
190
- if (match) {
191
- return match[2];
192
- }
193
189
  return getObjectValue(data, value);
194
190
  }
195
191
  function hasCondition(data, condition) {
@@ -206,7 +202,7 @@ function hasCondition(data, condition) {
206
202
  if (items.length > 0 && !isSpace(match[0][0])) {
207
203
  return false;
208
204
  }
209
- items.push([match[1], (0, util_1.trimQuote)(match[2]), (0, util_1.trimQuote)(match[3])]);
205
+ items.push([match[1], (0, util_1.trimQuote)(match[2]), match[3] ? (0, util_1.trimQuote)(match[3]) : '']);
210
206
  }
211
207
  REGEXP_TEMPLATECOMPARISON.lastIndex = 0;
212
208
  const length = items.length;
@@ -214,12 +210,10 @@ function hasCondition(data, condition) {
214
210
  return false;
215
211
  }
216
212
  for (let i = 0; i < length; ++i) {
217
- const item = items[i];
218
- const arg1 = item[1];
219
- const arg2 = item[2];
213
+ const [cmp, arg1, arg2] = items[i];
220
214
  let valid = false;
221
215
  if (arg2) {
222
- switch (item[0]) {
216
+ switch (cmp) {
223
217
  case 'eq':
224
218
  valid = parseArg(data, arg1) == parseArg(data, arg2);
225
219
  break;
@@ -242,7 +236,7 @@ function hasCondition(data, condition) {
242
236
  return false;
243
237
  }
244
238
  }
245
- else if (item[0]) {
239
+ else if (cmp) {
246
240
  return false;
247
241
  }
248
242
  else {
@@ -1414,7 +1408,7 @@ class ChromeDocument extends Document {
1414
1408
  if (match) {
1415
1409
  const layer = match[1];
1416
1410
  const supports = match[3]?.trim();
1417
- const query = match[4].trim();
1411
+ const query = match[4].trim().replace(/;+$/, '');
1418
1412
  if (layer || supports || query) {
1419
1413
  const newline = (0, util_1.getNewline)(source);
1420
1414
  let result = supports ? `@supports (${supports}) {` + newline : '';
@@ -1422,8 +1416,8 @@ class ChromeDocument extends Document {
1422
1416
  result += `@media ${query} {` + newline;
1423
1417
  }
1424
1418
  if (layer) {
1425
- let name = match[2];
1426
- result += '@layer ' + (name && (name = name.trim()) ? name + ' ' : '') + `{${newline + source + newline}}` + (query ? newline + '}' : '');
1419
+ const name = match[2]?.replace(/\s+/g, '');
1420
+ result += '@layer ' + (name ? name.slice(1, -1) + ' ' : '') + `{${newline + source + newline}}` + (query ? newline + '}' : '');
1427
1421
  }
1428
1422
  else if (query) {
1429
1423
  result += source + newline + '}';
@@ -2496,13 +2490,15 @@ class ChromeDocument extends Document {
2496
2490
  case 'mongodb':
2497
2491
  for (let j = 0; j < length; ++j) {
2498
2492
  const cmd = batch[j];
2499
- cmd.cacheObjectKey = typeof cmd.cascade === 'string' ? cmd.cascade : '';
2493
+ if (cmd.cascade) {
2494
+ cmd.cacheObjectKey ||= cmd.cascade;
2495
+ }
2500
2496
  }
2501
2497
  break;
2502
2498
  case 'redis':
2503
2499
  for (let j = 0; j < length; ++j) {
2504
2500
  const cmd = batch[j];
2505
- const { search, key, query, cascade } = cmd;
2501
+ const search = cmd.search;
2506
2502
  if ((0, types_1.isObject)(search) && typeof search.schema === 'string') {
2507
2503
  const pathname = this.resolveDir('schema', search.schema);
2508
2504
  if (pathname) {
@@ -2529,8 +2525,11 @@ class ChromeDocument extends Document {
2529
2525
  search.schema = undefined;
2530
2526
  }
2531
2527
  }
2532
- if (key) {
2533
- cmd.cacheObjectKey = ((0, types_1.isString)(cascade) ? cascade : '') + '_' + ((0, types_1.isString)(query) ? query : '');
2528
+ if (cmd.key) {
2529
+ const { cascade, query } = cmd;
2530
+ if (cascade || query) {
2531
+ cmd.cacheObjectKey ||= (cascade ? cascade : '') + '_' + (query ? Document.asString(query, true) : '');
2532
+ }
2534
2533
  }
2535
2534
  }
2536
2535
  break;
@@ -2721,20 +2720,20 @@ class ChromeDocument extends Document {
2721
2720
  segment = replaceMatch(match, segment, target[col] ? (!match[1] || target[col - 1].includes('\n') ? '' : match[1]) + target[col - 1] + target[col] : '', REGEXP_TEMPLATECONDITIONAL);
2722
2721
  }
2723
2722
  const literal = segment.trim();
2724
- if (literal.startsWith('`') && literal.endsWith('`')) {
2723
+ if (literal.at(0) === '`' && literal.at(-1) === '`') {
2725
2724
  if (!this.hasEval('function')) {
2726
2725
  errors = (0, types_1.errorMessage)('eval', "Unsupported access", 'function');
2727
2726
  continue;
2728
2727
  }
2729
2728
  try {
2730
- let content = new Function('return ' + literal + ';')(row);
2729
+ let unsafe = new Function('return ' + literal + ';').call(row);
2731
2730
  if (!segment.startsWith('`')) {
2732
- content = segment.substring(0, segment.indexOf('`')) + content;
2731
+ unsafe = segment.substring(0, segment.indexOf('`')) + unsafe;
2733
2732
  }
2734
2733
  if (!segment.endsWith('`')) {
2735
- content += segment.substring(segment.lastIndexOf('`') + 1);
2734
+ unsafe += segment.substring(segment.lastIndexOf('`') + 1);
2736
2735
  }
2737
- segment = content;
2736
+ segment = unsafe;
2738
2737
  }
2739
2738
  catch (err) {
2740
2739
  errors = err instanceof Error ? err : true;
@@ -2968,7 +2967,7 @@ class ChromeDocument extends Document {
2968
2967
  if (!empty && item.type !== 'display' || item.transactionFail) {
2969
2968
  const emptyResponse = (value, service = item.source) => {
2970
2969
  value ||= "Unknown";
2971
- return errorDataSource(service + ': ' + (errors instanceof Error ? errors.message : 'Empty'), value);
2970
+ return errorDataSource(errors instanceof Error ? errors.message : service + ': Empty', value);
2972
2971
  };
2973
2972
  switch (item.source) {
2974
2973
  case 'cloud': {
@@ -3755,7 +3754,7 @@ class ChromeDocument extends Document {
3755
3754
  if (!isText) {
3756
3755
  let j = startIndex;
3757
3756
  while (isSpace(source[--j])) { }
3758
- valid = source.substring(k = j - 6, j + 1) === '@import';
3757
+ valid = source.substring(k = j - 6, j + 1).toLowerCase() === '@import';
3759
3758
  }
3760
3759
  else {
3761
3760
  k = startIndex;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/chrome",
3
- "version": "0.10.3",
3
+ "version": "0.10.5",
4
4
  "description": "Chrome document constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -20,10 +20,10 @@
20
20
  "license": "MIT",
21
21
  "homepage": "https://github.com/anpham6/pi-r#readme",
22
22
  "dependencies": {
23
- "@e-mc/cloud": "^0.12.7",
24
- "@e-mc/core": "^0.12.7",
25
- "@e-mc/document": "^0.12.7",
26
- "@e-mc/types": "^0.12.7",
23
+ "@e-mc/cloud": "^0.12.17",
24
+ "@e-mc/core": "^0.12.17",
25
+ "@e-mc/document": "^0.12.17",
26
+ "@e-mc/types": "^0.12.17",
27
27
  "image-size": "^2.0.2"
28
28
  }
29
29
  }