@pi-r/chrome 0.12.2 → 0.12.3

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.
@@ -34,6 +34,7 @@ const getEndIndex = (match) => match.index + match[0].length;
34
34
  const hasBracket = (value) => value.includes('{') || value.includes('}');
35
35
  const getWhiteSpace = (unsafe) => unsafe ? ['\\s*', '\\s+'] : [PATTERN_STRING_SOME, PATTERN_STRING_MANY];
36
36
  function replaceBracket(pattern, current, replaceMap) {
37
+ pattern.lastIndex = 0;
37
38
  let match;
38
39
  while (match = pattern.exec(current)) {
39
40
  const seg = match[0];
@@ -43,7 +44,6 @@ function replaceBracket(pattern, current, replaceMap) {
43
44
  current = replaceMatch(match, current, placeholder, pattern);
44
45
  }
45
46
  }
46
- pattern.lastIndex = 0;
47
47
  return current;
48
48
  }
49
49
  function parseSelector(value, unsafe) {
@@ -231,14 +231,14 @@ function removeUnused(source, options) {
231
231
  if (options.file?.preserve) {
232
232
  return;
233
233
  }
234
- const { usedVariables, usedFontFace, usedKeyframes, unusedStyles, unusedMedia, unusedSupports, unusedContainer, unusedScope, useUnsafeCssReplace = false, useSessionCache = true } = options.config;
234
+ const { usedVariables, usedFontFace, usedKeyframes, unusedStyles, unusedMedia, unusedSupports, unusedContainer, unusedScope, stripStyleComments, useUnsafeCssReplace = false, useSessionCache = true } = options.config;
235
235
  if (!usedVariables && !usedFontFace && !usedKeyframes && !unusedStyles && !unusedMedia && !unusedSupports && !unusedContainer && !unusedScope) {
236
236
  return;
237
237
  }
238
238
  const stringSome = getWhiteSpace(useUnsafeCssReplace)[0];
239
239
  const replaceMap = [];
240
240
  const checkEmpty = {};
241
- let current = source, modified = false, match;
241
+ let current = stripStyleComments ? source.replace(REGEXP_COMMENT, '') : source, modified = source !== current, match;
242
242
  const setModified = (args) => {
243
243
  if (args[0]) {
244
244
  current = args[1];
@@ -247,7 +247,9 @@ function removeUnused(source, options) {
247
247
  }
248
248
  };
249
249
  if (!useUnsafeCssReplace) {
250
- current = replaceBracket(REGEXP_COMMENT, current, replaceMap);
250
+ if (!stripStyleComments) {
251
+ current = replaceBracket(REGEXP_COMMENT, current, replaceMap);
252
+ }
251
253
  current = replaceBracket(REGEXP_QUOTEDVALUE, current, replaceMap);
252
254
  const values = splitEnclosing(current, /\b(?<!-)url/gi);
253
255
  for (let i = 0, length = values.length; i < length; ++i) {
package/index.js CHANGED
@@ -675,6 +675,7 @@ class ChromeDocument extends Document {
675
675
  useUnsafeCssReplace: undefined,
676
676
  useSessionCache: undefined,
677
677
  stripCommentsAndCDATA: undefined,
678
+ stripStyleComments: undefined,
678
679
  normalizeHtmlOutput: undefined,
679
680
  escapeReservedCharacters: undefined,
680
681
  ignoreServerCodeBlocks: undefined
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/chrome",
3
- "version": "0.12.2",
3
+ "version": "0.12.3",
4
4
  "description": "Chrome document constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -17,10 +17,10 @@
17
17
  "license": "MIT",
18
18
  "homepage": "https://github.com/anpham6/pi-r#readme",
19
19
  "dependencies": {
20
- "@e-mc/cloud": "^0.14.3",
21
- "@e-mc/core": "^0.14.3",
22
- "@e-mc/document": "^0.14.3",
23
- "@e-mc/types": "^0.14.3",
20
+ "@e-mc/cloud": "^0.14.4",
21
+ "@e-mc/core": "^0.14.4",
22
+ "@e-mc/document": "^0.14.4",
23
+ "@e-mc/types": "^0.14.4",
24
24
  "image-size": "^2.0.2"
25
25
  }
26
26
  }
@@ -50,6 +50,7 @@ export interface DocumentOutput {
50
50
  /** @deprecated */
51
51
  useSessionCache?: boolean;
52
52
  stripCommentsAndCDATA?: boolean | string;
53
+ stripStyleComments?: boolean;
53
54
  normalizeHtmlOutput?: boolean | string;
54
55
  escapeReservedCharacters?: boolean;
55
56
  ignoreServerCodeBlocks?: string[];