@pi-r/chrome 0.7.4 → 0.7.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.
- package/LICENSE +6 -6
- package/index.d.ts +6 -6
- package/index.js +19 -23
- package/package.json +5 -5
package/LICENSE
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Copyright 2024 An Pham
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
-
|
|
5
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
-
|
|
1
|
+
Copyright 2024 An Pham
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
7
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { IFileManager } from '@e-mc/types/lib';
|
|
2
|
-
|
|
3
|
-
import type { ChromeDocumentConstructor, DocumentAsset } from './types';
|
|
4
|
-
|
|
5
|
-
declare const Chrome: ChromeDocumentConstructor<IFileManager<DocumentAsset>>;
|
|
6
|
-
|
|
1
|
+
import type { IFileManager } from '@e-mc/types/lib';
|
|
2
|
+
|
|
3
|
+
import type { ChromeDocumentConstructor, DocumentAsset } from './types';
|
|
4
|
+
|
|
5
|
+
declare const Chrome: ChromeDocumentConstructor<IFileManager<DocumentAsset>>;
|
|
6
|
+
|
|
7
7
|
export = Chrome;
|
package/index.js
CHANGED
|
@@ -28,7 +28,7 @@ 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(
|
|
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;
|
|
@@ -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 = /(?:\
|
|
57
|
+
const REGEXP_URL = /(?:\burl\(|@import\s+(["'])|\b(href)\s*=)/gi;
|
|
58
58
|
const REGEXP_URL_JS = /\bimport\(/g;
|
|
59
|
-
const REGEXP_URL_SVG = /(?:\
|
|
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*(?:,|$|[^)][^,]*,?)/g;
|
|
62
62
|
function removeNamespace(name, source, newline, comments) {
|
|
@@ -200,7 +200,7 @@ function hasCondition(data, condition) {
|
|
|
200
200
|
if (items.length && !isSpace(match[0][0])) {
|
|
201
201
|
return false;
|
|
202
202
|
}
|
|
203
|
-
items.push([match[1], match[2], match[3]]);
|
|
203
|
+
items.push([match[1], trimQuote(match[2]), match[3] ? trimQuote(match[3]) : '']);
|
|
204
204
|
}
|
|
205
205
|
REGEXP_TEMPLATECOMPARISON.lastIndex = 0;
|
|
206
206
|
const length = items.length;
|
|
@@ -211,18 +211,13 @@ function hasCondition(data, condition) {
|
|
|
211
211
|
if (!isNaN(+value)) {
|
|
212
212
|
return +value;
|
|
213
213
|
}
|
|
214
|
-
if (match = /^(["'])([\S\s]*)\1$/.exec(value)) {
|
|
215
|
-
return match[2];
|
|
216
|
-
}
|
|
217
214
|
return getObjectValue(data, value);
|
|
218
215
|
};
|
|
219
216
|
for (let i = 0; i < length; ++i) {
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
const arg2 = item[2];
|
|
223
|
-
let valid;
|
|
217
|
+
const [cmp, arg1, arg2] = items[i];
|
|
218
|
+
let valid = false;
|
|
224
219
|
if (arg2) {
|
|
225
|
-
switch (
|
|
220
|
+
switch (cmp) {
|
|
226
221
|
case 'eq':
|
|
227
222
|
valid = parseArg(arg1) == parseArg(arg2);
|
|
228
223
|
break;
|
|
@@ -245,7 +240,7 @@ function hasCondition(data, condition) {
|
|
|
245
240
|
return false;
|
|
246
241
|
}
|
|
247
242
|
}
|
|
248
|
-
else if (
|
|
243
|
+
else if (cmp) {
|
|
249
244
|
return false;
|
|
250
245
|
}
|
|
251
246
|
else {
|
|
@@ -582,7 +577,7 @@ function transformURL(host, parent, type, source, importFile) {
|
|
|
582
577
|
if (!isText) {
|
|
583
578
|
let j = startIndex;
|
|
584
579
|
while (isSpace(source[--j])) { }
|
|
585
|
-
valid = source.substring(k = j - 6, j + 1) === '@import';
|
|
580
|
+
valid = source.substring(k = j - 6, j + 1).toLowerCase() === '@import';
|
|
586
581
|
}
|
|
587
582
|
else {
|
|
588
583
|
k = startIndex;
|
|
@@ -1689,7 +1684,7 @@ class ChromeDocument extends Document {
|
|
|
1689
1684
|
if (match) {
|
|
1690
1685
|
const layer = match[1];
|
|
1691
1686
|
const supports = match[3]?.trim();
|
|
1692
|
-
const query = match[4].trim();
|
|
1687
|
+
const query = match[4].trim().replace(/;+$/, '');
|
|
1693
1688
|
if (layer || supports || query) {
|
|
1694
1689
|
const newline = (0, util_1.getNewline)(source);
|
|
1695
1690
|
let result = supports ? `@supports (${supports}) {` + newline : '';
|
|
@@ -1697,8 +1692,8 @@ class ChromeDocument extends Document {
|
|
|
1697
1692
|
result += `@media ${query} {` + newline;
|
|
1698
1693
|
}
|
|
1699
1694
|
if (layer) {
|
|
1700
|
-
|
|
1701
|
-
result += '@layer ' + (name
|
|
1695
|
+
const name = match[2]?.replace(/\s+/g, '');
|
|
1696
|
+
result += '@layer ' + (name ? name.slice(1, -1) + ' ' : '') + `{${newline + source + newline}}` + (query ? newline + '}' : '');
|
|
1702
1697
|
}
|
|
1703
1698
|
else if (query) {
|
|
1704
1699
|
result += source + newline + '}';
|
|
@@ -3007,14 +3002,14 @@ class ChromeDocument extends Document {
|
|
|
3007
3002
|
continue;
|
|
3008
3003
|
}
|
|
3009
3004
|
try {
|
|
3010
|
-
let
|
|
3005
|
+
let unsafe = new Function('return ' + literal + ';').call(row);
|
|
3011
3006
|
if (!segment.startsWith('`')) {
|
|
3012
|
-
|
|
3007
|
+
unsafe = segment.substring(0, segment.indexOf('`')) + unsafe;
|
|
3013
3008
|
}
|
|
3014
3009
|
if (!segment.endsWith('`')) {
|
|
3015
|
-
|
|
3010
|
+
unsafe += segment.substring(segment.lastIndexOf('`') + 1);
|
|
3016
3011
|
}
|
|
3017
|
-
segment =
|
|
3012
|
+
segment = unsafe;
|
|
3018
3013
|
}
|
|
3019
3014
|
catch (err) {
|
|
3020
3015
|
errors = err instanceof Error ? err : true;
|
|
@@ -3149,7 +3144,8 @@ class ChromeDocument extends Document {
|
|
|
3149
3144
|
const row = items[0];
|
|
3150
3145
|
let condition = NaN;
|
|
3151
3146
|
for (let seg of template) {
|
|
3152
|
-
|
|
3147
|
+
seg = seg.trim();
|
|
3148
|
+
switch (seg.toLowerCase()) {
|
|
3153
3149
|
case ':is(and)':
|
|
3154
3150
|
if (condition === 0) {
|
|
3155
3151
|
remove = false;
|
|
@@ -3344,7 +3340,7 @@ class ChromeDocument extends Document {
|
|
|
3344
3340
|
const parseSelector = (value) => {
|
|
3345
3341
|
const items = [];
|
|
3346
3342
|
const revised = value.replace(useUnsafeCssReplace ? REGEXP_NTHCHILD_UNSAFE : REGEXP_NTHCHILD, (...capture) => {
|
|
3347
|
-
return '`%' + (items.push('\\(' + getStringSome() + (capture[1] === '-' ? '\\x2d' : '\\x2b?') + (capture[2] || '[01]?') + (capture[3] === '0' ? !capture[1] && !capture[2] && !capture[4] && !capture[5] ? '[+-]?0[nN]?' : '0' : '[nN]') + getStringSome() + (capture[5] ? (capture[4] === '-' ? '\\x2d' : '\\x2b') + getStringSome() + capture[5] : `(?:[+-]${getStringSome()}0)?`) + (capture[6] ? getStringMany() + '[oO][fF]' + getStringMany() + capture[6].trim() : '') + getStringSome() + '\\)') - 1) + '`';
|
|
3343
|
+
return '`%' + (items.push('\\(' + getStringSome() + (capture[1] === '-' ? '\\x2d' : '\\x2b?') + (capture[2] || '[01]?') + (capture[3] === '0' ? !capture[1] && !capture[2] && !capture[4] && !capture[5] ? '[+-]?0[nN]?' : '0' : '[nN]?') + getStringSome() + (capture[5] ? (capture[4] === '-' ? '\\x2d' : '\\x2b?') + getStringSome() + capture[5] : `(?:[+-]${getStringSome()}0)?`) + (capture[6] ? getStringMany() + '[oO][fF]' + getStringMany() + capture[6].trim() : '') + getStringSome() + '\\)') - 1) + '`';
|
|
3348
3344
|
});
|
|
3349
3345
|
let selector = '';
|
|
3350
3346
|
for (let i = 0, length = revised.length, casing = false, attr = false, quote = false; i < length; i++) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/chrome",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.6",
|
|
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.9.
|
|
24
|
-
"@e-mc/core": "^0.9.
|
|
25
|
-
"@e-mc/document": "^0.9.
|
|
26
|
-
"@e-mc/types": "^0.9.
|
|
23
|
+
"@e-mc/cloud": "^0.9.28",
|
|
24
|
+
"@e-mc/core": "^0.9.28",
|
|
25
|
+
"@e-mc/document": "^0.9.28",
|
|
26
|
+
"@e-mc/types": "^0.9.28"
|
|
27
27
|
}
|
|
28
28
|
}
|