@pi-r/chrome 0.9.1 → 0.9.2

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 -14
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -209,7 +209,7 @@ function hasCondition(data, condition) {
209
209
  if (items.length > 0 && !isSpace(match[0][0])) {
210
210
  return false;
211
211
  }
212
- items.push([match[1], match[2], match[3]]);
212
+ items.push([match[1], trimQuote(match[2]), trimQuote(match[3])]);
213
213
  }
214
214
  REGEXP_TEMPLATECOMPARISON.lastIndex = 0;
215
215
  const length = items.length;
@@ -818,7 +818,7 @@ function replaceHtml(instance, source, { productionRelease, contentMap }, cssMap
818
818
  }
819
819
  function finalizeHtml(value, data) {
820
820
  for (const id in data) {
821
- value = value.replace(new RegExp(escapePattern(id), 'g'), data[id]);
821
+ value = value.replace(new RegExp((0, types_1.escapePattern)(id), 'g'), data[id]);
822
822
  }
823
823
  return value;
824
824
  }
@@ -907,9 +907,6 @@ function errorCredential(instance, domBase, item, err) {
907
907
  instance.writeFail(["Invalid credentials", item.source], err);
908
908
  }
909
909
  }
910
- function escapePattern(value) {
911
- return value.replace(/[-|\\{}()[\]^$+*?.]/g, capture => capture === '-' ? '\\x2d' : '\\' + capture);
912
- }
913
910
  const isSpace = dom_1.DomWriter.isSpace.bind(dom_1.DomWriter);
914
911
  const replaceMatch = dom_1.DomWriter.replaceMatch.bind(dom_1.DomWriter);
915
912
  const getNewlineString = dom_1.DomWriter.getNewlineString.bind(dom_1.DomWriter);
@@ -1851,7 +1848,7 @@ class ChromeDocument extends Document {
1851
1848
  }
1852
1849
  }
1853
1850
  removeServerRoot(value) {
1854
- return value.replace(new RegExp('(\\.\\./)*' + escapePattern(ChromeDocument.INTERNAL_SERVERROOT), 'g'), '');
1851
+ return value.replace(new RegExp('(\\.\\./)*' + (0, types_1.escapePattern)(ChromeDocument.INTERNAL_SERVERROOT), 'g'), '');
1855
1852
  }
1856
1853
  addCopy(data, saveAs) {
1857
1854
  if (data.command && this.host) {
@@ -1880,7 +1877,7 @@ class ChromeDocument extends Document {
1880
1877
  if (this.htmlFile) {
1881
1878
  const endpoint = instance.getStorage('upload', this.htmlFile.cloudStorage)?.upload?.endpoint;
1882
1879
  if (endpoint) {
1883
- this._cloudEndpoint = new RegExp(escapePattern(Document.toPosix(endpoint)) + '/', 'g');
1880
+ this._cloudEndpoint = new RegExp((0, types_1.escapePattern)(Document.toPosix(endpoint)) + '/', 'g');
1884
1881
  }
1885
1882
  }
1886
1883
  }
@@ -1897,7 +1894,7 @@ class ChromeDocument extends Document {
1897
1894
  const cloudUrl = endpoint ? url.replace(endpoint, '') : url;
1898
1895
  file.cloudUrl = cloudUrl;
1899
1896
  if (inlineUrlCloud) {
1900
- const pattern = new RegExp(escapePattern(inlineUrlCloud), 'g');
1897
+ const pattern = new RegExp((0, types_1.escapePattern)(inlineUrlCloud), 'g');
1901
1898
  for (const item of this.editing) {
1902
1899
  if (item.inlineUrlCloudMap?.[inlineUrlCloud]) {
1903
1900
  const source = host.getUTF8String(item);
@@ -1927,7 +1924,7 @@ class ChromeDocument extends Document {
1927
1924
  for (const id in this._cloudUrlMap) {
1928
1925
  const inlineUrlCloud = item.inlineUrlCloudMap[id];
1929
1926
  if (inlineUrlCloud && !this._cloudUploaded.has(id)) {
1930
- output = (output || source).replace(new RegExp(escapePattern(id), 'g'), inlineUrlCloud);
1927
+ output = (output || source).replace(new RegExp((0, types_1.escapePattern)(id), 'g'), inlineUrlCloud);
1931
1928
  state.localStorage.delete(this._cloudUrlMap[id]);
1932
1929
  }
1933
1930
  }
@@ -2108,7 +2105,7 @@ class ChromeDocument extends Document {
2108
2105
  let current = srcset, match;
2109
2106
  for (const url of items) {
2110
2107
  const resolve = sameOrigin && !Document.isURL(url);
2111
- const pathname = url.split('/').map(seg => escapePattern(seg)).join('/');
2108
+ const pathname = url.split('/').map(seg => (0, types_1.escapePattern)(seg)).join('/');
2112
2109
  const pattern = new RegExp(`(,?\\s*)(${(resolve && !url.startsWith('.') ? `(?:\\.\\./)*\\.\\.${pathname}|` : '') + pathname})(` + (!url.includes('?') ? '(?:(?!,)(?:[^?]|$)[^,]*)|(?!\\?)[^,]*)' : '[^,]*)'), 'g');
2113
2110
  while (match = pattern.exec(current)) {
2114
2111
  const partial = match[2];
@@ -2356,7 +2353,7 @@ class ChromeDocument extends Document {
2356
2353
  source = removeNamespace(moduleName, domBase.modified ? domBase.close() : source, domBase.newline, domBase.getComments());
2357
2354
  if (this.sanitizeFramework) {
2358
2355
  for (const name of this.sanitizeFramework) {
2359
- source = source.replace(name === '*' ? REGEXP_SANITIZEALL : new RegExp(`(?:\\s+|\\b)data-(?:${escapePattern(name)}-[^=\\s]+|.+?-${escapePattern(name)})\\s*${dom_1.DomWriter.PATTERN_ATTRVALUE}(?=(?:[^"<]+"[^"]*"|[^'<]+'[^']*')*[^<>]*>)`, 'g'), '');
2356
+ source = source.replace(name === '*' ? REGEXP_SANITIZEALL : new RegExp(`(?:\\s+|\\b)data-(?:${(0, types_1.escapePattern)(name)}-[^=\\s]+|.+?-${(0, types_1.escapePattern)(name)})\\s*${dom_1.DomWriter.PATTERN_ATTRVALUE}(?=(?:[^"<]+"[^"]*"|[^'<]+'[^']*')*[^<>]*>)`, 'g'), '');
2360
2357
  }
2361
2358
  }
2362
2359
  if (!htmlFile.preserve) {
@@ -3283,7 +3280,8 @@ class ChromeDocument extends Document {
3283
3280
  const row = items[0];
3284
3281
  let condition = NaN;
3285
3282
  for (let seg of template) {
3286
- switch ((seg = seg.trim()).toLowerCase()) {
3283
+ seg = seg.trim();
3284
+ switch (seg.toLowerCase()) {
3287
3285
  case ':is(and)':
3288
3286
  if (condition === 0) {
3289
3287
  remove = false;
@@ -3552,7 +3550,7 @@ class ChromeDocument extends Document {
3552
3550
  }
3553
3551
  selector += (space & 1 ? '`%%`' : '') + (!casing && ch >= 'a' && ch <= 'z' ? '`' + ch + ch.toUpperCase() + '`' : ch) + (space & 2 ? '`%%`' : '');
3554
3552
  }
3555
- selector = escapePattern(selector)
3553
+ selector = (0, types_1.escapePattern)(selector)
3556
3554
  .replace(/\s*(>|~(?!=)|\\\+|\\\*(?!=)])\s*/g, (...capture) => stringSome + capture[1] + stringSome)
3557
3555
  .replace(/`([a-z][A-Z]|%{2,4})`/g, (...capture) => {
3558
3556
  switch (capture[1]) {
@@ -3618,7 +3616,7 @@ class ChromeDocument extends Document {
3618
3616
  }
3619
3617
  }
3620
3618
  if (!revised) {
3621
- selector = escapePattern(selector || value)
3619
+ selector = (0, types_1.escapePattern)(selector || value)
3622
3620
  .replace(/\s*(\\[()])\s*/g, (...capture) => stringSome + capture[1] + stringSome)
3623
3621
  .replace(/:\s+/g, stringSome + ':' + stringSome)
3624
3622
  .replace(/\s+([<>/]|<=|>=|\\\*)\s+/g, (...capture) => stringSome + capture[1] + stringSome)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/chrome",
3
- "version": "0.9.1",
3
+ "version": "0.9.2",
4
4
  "description": "Chrome document constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",