@pi-r/chrome 0.12.2 → 0.12.4
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/extensions/css/remove-unused/index.js +6 -4
- package/index.js +209 -197
- package/package.json +5 -5
- package/types/squared.d.ts +1 -0
|
@@ -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 =
|
|
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
|
-
|
|
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
|
@@ -29,10 +29,10 @@ const REGEXP_TEMPLATECOMPARISON = /\s*\(\s*(?:(eq|ne|lt|le|gt|ge)\s+)?("[^"]+"|'
|
|
|
29
29
|
const REGEXP_TEMPLATEMATCH = new RegExp(`^(?:(and|or|not)\\s+)?((?:${REGEXP_TEMPLATECOMPARISON.source})+)|(!|not\\s+)?([^\\s].*)$`, 's');
|
|
30
30
|
const REGEXP_IMPORTMODULE = /(?:(?:^|[\n;]+)\s*import\s+(?:("[^"]+"|'[^']+')|.+from\s+("[^"]+"|'[^']+')(?:[ \t]+with[ \t]+\{((?:"[^"]+"|'[^']+'|`[^`]+`|{[^{]*{|{[^}]*}|}[^}]*}|[^"'`]+)+)\})?)|\bimport\(\s*("[^"]+"|'[^']+')\s*(?:,\s*\{((?:"[^"]+"|'[^']+'|`[^`]+`|{[^{]*{|{[^}]*}|}[^}]*}|[^"'`]+)+)\}\s*)?\))/gd;
|
|
31
31
|
const REGEXP_BLOCKEXCLUDE = new RegExp(`(\\s*)<!--\\s*exclude\\s*:\\s*(?:start|end)\\s*-->` + DomWriter.PATTERN_TRAILINGSPACE, 'gi');
|
|
32
|
-
const REGEXP_STYLE = new RegExp(`(<style${DomWriter.PATTERN_TAGOPEN}*>)(.*?)(<\\/style\\s*>)`, '
|
|
32
|
+
const REGEXP_STYLE = new RegExp(`(<style${DomWriter.PATTERN_TAGOPEN}*>)(.*?)(<\\/style\\s*>)`, 'gis');
|
|
33
33
|
const REGEXP_SANITIZEALL = new RegExp(`(?:\\s+|\\b)data-(?:pathname|filename|intl-locales|(?:use|exclude)-[^=\\s]+)\\s*${DomWriter.PATTERN_ATTRVALUE}(?=(?:[^"<]+"[^"]*"|[^'<]+'[^']*')*[^<>]*>)`, 'g');
|
|
34
34
|
const REGEXP_IMAGESET_URL = /(?:^|[^(])\s*("(\s*[^)][^"]*)"|'(\s*[^)][^"]*)')\s*(?:,|$|[^)][^,]*,?)/gd;
|
|
35
|
-
const REGEXP_REPLACECSS = new RegExp(`^@import\\s+(?:url\\((?:[^)]|(?<=\\\\)\\))+\\)|"(?:[^"]|(?<=\\\\)")+"|'(?:[^']|(?<=\\\\)')+')(
|
|
35
|
+
const REGEXP_REPLACECSS = new RegExp(`^@import\\s+(?:url\\((?:[^)]|(?<=\\\\)\\))+\\)|"(?:[^"]|(?<=\\\\)")+"|'(?:[^']|(?<=\\\\)')+')((?:(?:\\s+|(?<=["'\\\\]))(?:(?:layer|supports)\\(${PATTERN_PARENTHESIS}\\)|layer\\b)){1,2})?(.*)$`, 'is');
|
|
36
36
|
function removeNamespace(name, source, newline, comments) {
|
|
37
37
|
if (source.includes('-' + name)) {
|
|
38
38
|
const [a, b, c, d, e] = CACHE_DATASET[name] ||= [
|
|
@@ -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
|
|
@@ -1235,18 +1236,27 @@ class ChromeDocument extends Document {
|
|
|
1235
1236
|
case "text/css": {
|
|
1236
1237
|
const match = REGEXP_REPLACECSS.exec((typeof statement === 'string' ? statement : statement[0]).trim());
|
|
1237
1238
|
if (match) {
|
|
1238
|
-
const
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1239
|
+
const trailing = match[1];
|
|
1240
|
+
let layer, supports;
|
|
1241
|
+
if (trailing) {
|
|
1242
|
+
const name = /\blayer(?:\(([^)]+)\)|\s|$)/i.exec(trailing);
|
|
1243
|
+
if (name) {
|
|
1244
|
+
layer = name[1]?.trim() || '';
|
|
1245
|
+
supports = spliceString(trailing, name.index, name.index + name[0].length, '').trim();
|
|
1246
|
+
}
|
|
1247
|
+
else {
|
|
1248
|
+
supports = trailing.trimStart();
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
const query = match[2].trim().replace(/\s*;+$/, '');
|
|
1252
|
+
if (typeof layer === 'string' || supports || query) {
|
|
1242
1253
|
const newline = getNewline(source);
|
|
1243
1254
|
let result = supports ? `@supports (${normalizeSpace(supports)}) {` + newline : '';
|
|
1244
1255
|
if (query) {
|
|
1245
1256
|
result += `@media ${normalizeSpace(query)} {` + newline;
|
|
1246
1257
|
}
|
|
1247
|
-
if (layer) {
|
|
1248
|
-
|
|
1249
|
-
result += '@layer ' + (name ? name.slice(1, -1) + ' ' : '') + `{${newline + source + newline}}` + (query ? newline + '}' : '');
|
|
1258
|
+
if (typeof layer === 'string') {
|
|
1259
|
+
result += '@layer ' + (layer ? layer + ' ' : '') + `{${newline + source + newline}}` + (query ? newline + '}' : '');
|
|
1250
1260
|
}
|
|
1251
1261
|
else if (query) {
|
|
1252
1262
|
result += source + newline + '}';
|
|
@@ -3125,10 +3135,10 @@ class ChromeDocument extends Document {
|
|
|
3125
3135
|
processUrl(host, file, source, type, importFile) {
|
|
3126
3136
|
const related = [];
|
|
3127
3137
|
const baseHref = collectBaseUrl(importFile || file, this.baseUrl);
|
|
3128
|
-
const isHtml = type === 'html';
|
|
3138
|
+
const isHtml = type === 'html' || type === 'svg';
|
|
3129
3139
|
const isJs = type === 'js';
|
|
3130
3140
|
const imageSet = /(?:\b(?<!-)|(?<!-)-webkit-)image-set\(/gi;
|
|
3131
|
-
const pattern = isJs ? /\b(?<!-)import\(/g :
|
|
3141
|
+
const pattern = isJs ? /\b(?<!-)import\(/g : !isHtml ? /(?:\b(?<!-)url\(|@import\s+(["']))/gi : /(?:\b(?<!-)url\(|@import\s+(["'])|\b(?<!-)(href)\s*=)/gi;
|
|
3132
3142
|
let length = source.length, modified = false, match;
|
|
3133
3143
|
while (match = imageSet.exec(source)) {
|
|
3134
3144
|
const startIndex = match.index + match[0].length;
|
|
@@ -3154,231 +3164,233 @@ class ChromeDocument extends Document {
|
|
|
3154
3164
|
const isUrl = !isText && !isHref;
|
|
3155
3165
|
const startIndex = match.index;
|
|
3156
3166
|
let quote = match[1], content = '', trailing = '', closed = -1, i = startIndex + match[0].length;
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
if (
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
}
|
|
3166
|
-
if (source[i - 1] !== '\\') {
|
|
3167
|
-
if (isText) {
|
|
3167
|
+
pass: {
|
|
3168
|
+
for (let j = -1; i < length; ++i) {
|
|
3169
|
+
const ch = source[i];
|
|
3170
|
+
if (quote && ch === quote) {
|
|
3171
|
+
if (!isText) {
|
|
3172
|
+
content += ch;
|
|
3173
|
+
}
|
|
3174
|
+
if (isHref) {
|
|
3168
3175
|
break;
|
|
3169
3176
|
}
|
|
3170
|
-
if (
|
|
3171
|
-
|
|
3177
|
+
if (source[i - 1] !== '\\') {
|
|
3178
|
+
if (isText) {
|
|
3179
|
+
break;
|
|
3180
|
+
}
|
|
3181
|
+
if (closed === -1) {
|
|
3182
|
+
closed = i + 1;
|
|
3183
|
+
}
|
|
3172
3184
|
}
|
|
3185
|
+
j = i + 1;
|
|
3186
|
+
continue;
|
|
3173
3187
|
}
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
break;
|
|
3188
|
+
if (!quote && (ch === '"' || ch === "'" || ch === '`' && isJs) && (isHref || !content.trim())) {
|
|
3189
|
+
quote = ch;
|
|
3190
|
+
}
|
|
3191
|
+
else if (isHref && (ch === '#' || !quote && isSpace(ch)) && content.trim()) {
|
|
3192
|
+
break pass;
|
|
3193
|
+
}
|
|
3194
|
+
else if (ch === ')') {
|
|
3195
|
+
if (isUrl) {
|
|
3196
|
+
if (quote && closed !== -1 || !quote && (isJs || source[i - 1] !== '\\')) {
|
|
3197
|
+
break;
|
|
3198
|
+
}
|
|
3199
|
+
j = i;
|
|
3187
3200
|
}
|
|
3188
|
-
j = i;
|
|
3189
3201
|
}
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3202
|
+
else if (j !== -1 && (ch === '\n' ||
|
|
3203
|
+
isText && (ch === ';' || ch === '{') ||
|
|
3204
|
+
isHref && (ch === '=' || ch === '>') ||
|
|
3205
|
+
isUrl && (ch === ';' ||
|
|
3206
|
+
!isJs && (!isHtml && (ch === ':' && !isJs || ch === '}') ||
|
|
3207
|
+
isHtml && (ch === '"' || ch === "'" || ch === ':' || ch === '>'))))) {
|
|
3208
|
+
if (closed !== -1) {
|
|
3209
|
+
i = closed;
|
|
3210
|
+
}
|
|
3211
|
+
else {
|
|
3212
|
+
i = j;
|
|
3213
|
+
content = content.slice(0, i);
|
|
3214
|
+
}
|
|
3215
|
+
break;
|
|
3199
3216
|
}
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
content = content.slice(0, i);
|
|
3217
|
+
if (closed === -1) {
|
|
3218
|
+
content += ch;
|
|
3203
3219
|
}
|
|
3204
|
-
break;
|
|
3205
3220
|
}
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
i = k;
|
|
3238
|
-
break found;
|
|
3221
|
+
const setOutputURL = (value, asset) => {
|
|
3222
|
+
if (!value) {
|
|
3223
|
+
return;
|
|
3224
|
+
}
|
|
3225
|
+
if (asset) {
|
|
3226
|
+
if (!asset.inlineBase64) {
|
|
3227
|
+
if (host.Cloud?.getStorage('upload', asset.cloudStorage)) {
|
|
3228
|
+
const inlineUrlCloud = asset.inlineUrlCloud ||= randomUUID();
|
|
3229
|
+
(file.inlineUrlCloudMap ||= {})[inlineUrlCloud] = value;
|
|
3230
|
+
value = inlineUrlCloud;
|
|
3231
|
+
}
|
|
3232
|
+
else if (asset.hash && this.productionRelease) {
|
|
3233
|
+
const inlineUrl = asset.inlineUrl ||= randomUUID();
|
|
3234
|
+
(file.inlineUrlMap ||= {})[inlineUrl] = value;
|
|
3235
|
+
value = inlineUrl;
|
|
3236
|
+
}
|
|
3237
|
+
}
|
|
3238
|
+
const font = findFont(asset.format);
|
|
3239
|
+
if (font) {
|
|
3240
|
+
found: {
|
|
3241
|
+
for (let k = i + 1; k < length; ++k) {
|
|
3242
|
+
switch (source[k]) {
|
|
3243
|
+
case ')': {
|
|
3244
|
+
const component = source.slice(i + 1, k + 1);
|
|
3245
|
+
const format = /\s+format\([^)]+\)$/i.exec(component);
|
|
3246
|
+
if (format) {
|
|
3247
|
+
trailing = component.replace(format[0], ` format("${font}")`);
|
|
3248
|
+
i = k;
|
|
3249
|
+
break found;
|
|
3250
|
+
}
|
|
3251
|
+
break;
|
|
3239
3252
|
}
|
|
3240
|
-
|
|
3253
|
+
case ',':
|
|
3254
|
+
case ';':
|
|
3255
|
+
case ':':
|
|
3256
|
+
case '}':
|
|
3257
|
+
break found;
|
|
3241
3258
|
}
|
|
3242
|
-
case ',':
|
|
3243
|
-
case ';':
|
|
3244
|
-
case ':':
|
|
3245
|
-
case '}':
|
|
3246
|
-
break found;
|
|
3247
3259
|
}
|
|
3248
3260
|
}
|
|
3249
3261
|
}
|
|
3262
|
+
if (asset.initialValue && !asset.initialValue.cacheable) {
|
|
3263
|
+
file.flags |= 16;
|
|
3264
|
+
}
|
|
3265
|
+
related.push(asset);
|
|
3266
|
+
}
|
|
3267
|
+
if (!quote && !isHtml && !isJs) {
|
|
3268
|
+
if (!value.includes('"')) {
|
|
3269
|
+
quote = '"';
|
|
3270
|
+
}
|
|
3271
|
+
else if (!value.includes("'")) {
|
|
3272
|
+
quote = "'";
|
|
3273
|
+
}
|
|
3250
3274
|
}
|
|
3251
|
-
if (
|
|
3252
|
-
|
|
3275
|
+
if (isUrl) {
|
|
3276
|
+
const index = value.indexOf('#');
|
|
3277
|
+
if (index !== -1) {
|
|
3278
|
+
value = value.slice(0, index);
|
|
3279
|
+
}
|
|
3253
3280
|
}
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
if (!quote && !isHtml && !isJs) {
|
|
3257
|
-
if (!value.includes('"')) {
|
|
3258
|
-
quote = '"';
|
|
3281
|
+
if (quote) {
|
|
3282
|
+
value = quote + value + quote;
|
|
3259
3283
|
}
|
|
3260
|
-
|
|
3261
|
-
|
|
3284
|
+
const revised = isJs ? `import(${value + trailing})` : isHref ? 'href=' + value : (isText ? '@import ' + value : `url(${value})`) + trailing;
|
|
3285
|
+
source = spliceString(source, startIndex, i + 1, revised, pattern);
|
|
3286
|
+
length = source.length;
|
|
3287
|
+
modified = true;
|
|
3288
|
+
};
|
|
3289
|
+
let url;
|
|
3290
|
+
if (isJs) {
|
|
3291
|
+
if (!quote) {
|
|
3292
|
+
continue;
|
|
3262
3293
|
}
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3294
|
+
const target = new RegExp(`^\\s*(${quote}((?:[^${quote}]|(?<=\\\\)${quote})+)${quote})\\s*(,.+)$`).exec(content);
|
|
3295
|
+
if (target) {
|
|
3296
|
+
url = target[1].trim();
|
|
3297
|
+
trailing = target[2].trim();
|
|
3298
|
+
}
|
|
3299
|
+
else {
|
|
3300
|
+
url = trimQuote(content);
|
|
3268
3301
|
}
|
|
3269
|
-
}
|
|
3270
|
-
if (quote) {
|
|
3271
|
-
value = quote + value + quote;
|
|
3272
|
-
}
|
|
3273
|
-
const revised = isJs ? `import(${value + trailing})` : isHref ? 'href=' + value : (isText ? '@import ' + value : `url(${value})`) + trailing;
|
|
3274
|
-
source = spliceString(source, startIndex, i + 1, revised, pattern);
|
|
3275
|
-
length = source.length;
|
|
3276
|
-
modified = true;
|
|
3277
|
-
};
|
|
3278
|
-
let url;
|
|
3279
|
-
if (isJs) {
|
|
3280
|
-
if (!quote) {
|
|
3281
|
-
continue;
|
|
3282
|
-
}
|
|
3283
|
-
const target = new RegExp(`^\\s*(${quote}((?:[^${quote}]|(?<=\\\\)${quote})+)${quote})\\s*(,.+)$`).exec(content);
|
|
3284
|
-
if (target) {
|
|
3285
|
-
url = target[1].trim();
|
|
3286
|
-
trailing = target[2].trim();
|
|
3287
3302
|
}
|
|
3288
3303
|
else {
|
|
3289
3304
|
url = trimQuote(content);
|
|
3290
3305
|
}
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
if (item.base64 === base64) {
|
|
3300
|
-
setOutputURL(this.getSrcUrl(file, item)[0], item);
|
|
3301
|
-
break;
|
|
3306
|
+
if (url.startsWith('data:')) {
|
|
3307
|
+
const base64 = url.split(',')[1]?.trim();
|
|
3308
|
+
if (base64) {
|
|
3309
|
+
for (const item of this.assets) {
|
|
3310
|
+
if (item.base64 === base64) {
|
|
3311
|
+
setOutputURL(this.getSrcUrl(file, item)[0], item);
|
|
3312
|
+
break;
|
|
3313
|
+
}
|
|
3302
3314
|
}
|
|
3303
3315
|
}
|
|
3304
3316
|
}
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3317
|
+
else if (baseHref.length > 0) {
|
|
3318
|
+
let fullUrl, asset;
|
|
3319
|
+
for (const parentUrl of baseHref) {
|
|
3320
|
+
asset = host.findAsset(fullUrl = Document.resolvePath(url, parentUrl), { replaced: true });
|
|
3321
|
+
if (!asset) {
|
|
3322
|
+
const assets = this.related.get(file);
|
|
3323
|
+
asset = assets && host.findAsset(fullUrl, { assets: Array.from(assets), replaced: true });
|
|
3324
|
+
}
|
|
3325
|
+
if (asset) {
|
|
3326
|
+
break;
|
|
3327
|
+
}
|
|
3316
3328
|
}
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
valid = source.slice(k, j + 1).toLowerCase() === '@import';
|
|
3327
|
-
}
|
|
3328
|
-
else {
|
|
3329
|
-
k = startIndex;
|
|
3330
|
-
}
|
|
3331
|
-
if (valid) {
|
|
3332
|
-
let l = i, revised = SourceMap.removeSourceMappingURL(host.getUTF8String(asset))[0];
|
|
3333
|
-
for (let ch; l < length; ++l) {
|
|
3334
|
-
if ((ch = source[l]) === ';' || ch === '\n') {
|
|
3335
|
-
break;
|
|
3336
|
-
}
|
|
3329
|
+
if (asset && asset !== importFile) {
|
|
3330
|
+
if (!hasValue(asset.format, 'base64')) {
|
|
3331
|
+
if (asset.bundleReplace) {
|
|
3332
|
+
let k = 0, valid = true;
|
|
3333
|
+
if (!isText) {
|
|
3334
|
+
let j = startIndex;
|
|
3335
|
+
while (isSpace(source[--j])) { }
|
|
3336
|
+
k = j - 6;
|
|
3337
|
+
valid = source.slice(k, j + 1).toLowerCase() === '@import';
|
|
3337
3338
|
}
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
revised = layer;
|
|
3339
|
+
else {
|
|
3340
|
+
k = startIndex;
|
|
3341
3341
|
}
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
asset.flags |= 8;
|
|
3342
|
+
if (valid) {
|
|
3343
|
+
let l = i, revised = SourceMap.removeSourceMappingURL(host.getUTF8String(asset))[0];
|
|
3344
|
+
for (let ch; l < length; ++l) {
|
|
3345
|
+
if ((ch = source[l]) === ';' || ch === '\n') {
|
|
3346
|
+
break;
|
|
3347
|
+
}
|
|
3349
3348
|
}
|
|
3349
|
+
const layer = this.replaceContent(revised, source.slice(k, l + 1), "text/css");
|
|
3350
|
+
if (layer) {
|
|
3351
|
+
revised = layer;
|
|
3352
|
+
}
|
|
3353
|
+
revised = this.processUrl(host, file, this.removeServerRoot(revised), type, asset) || revised;
|
|
3354
|
+
source = spliceString(source, k, l + 1, revised, pattern);
|
|
3355
|
+
length = source.length;
|
|
3356
|
+
if (file.watch) {
|
|
3357
|
+
related.push(asset);
|
|
3358
|
+
if (!existsFlag(asset.flags)) {
|
|
3359
|
+
asset.flags |= 8;
|
|
3360
|
+
}
|
|
3361
|
+
}
|
|
3362
|
+
else if (asset.localUri) {
|
|
3363
|
+
host.deleteFile(asset.localUri, { ignorePermission: true, emptyDir: true, all: true, id: asset.id });
|
|
3364
|
+
asset.invalid = true;
|
|
3365
|
+
}
|
|
3366
|
+
modified = true;
|
|
3367
|
+
continue;
|
|
3350
3368
|
}
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3369
|
+
}
|
|
3370
|
+
if (hasSameOrigin(asset.url || fullUrl, ...baseHref)) {
|
|
3371
|
+
let sameDir = false;
|
|
3372
|
+
[fullUrl, sameDir] = this.getSrcUrl(file, asset);
|
|
3373
|
+
if (sameDir && isJs) {
|
|
3374
|
+
fullUrl = './' + fullUrl;
|
|
3354
3375
|
}
|
|
3355
|
-
modified = true;
|
|
3356
|
-
continue;
|
|
3357
3376
|
}
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
if (sameDir && isJs) {
|
|
3363
|
-
fullUrl = './' + fullUrl;
|
|
3377
|
+
else {
|
|
3378
|
+
const pathname = file.pathname;
|
|
3379
|
+
const count = pathname && pathname !== '/' ? pathname.split('/').length : 0;
|
|
3380
|
+
fullUrl = (count ? '../'.repeat(count) : '') + asset.relativeUrl;
|
|
3364
3381
|
}
|
|
3365
3382
|
}
|
|
3366
|
-
else {
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3383
|
+
else if (!asset.invalid) {
|
|
3384
|
+
fullUrl = asset.inlineBase64 ||= randomUUID();
|
|
3385
|
+
}
|
|
3386
|
+
if (url !== fullUrl) {
|
|
3387
|
+
setOutputURL(fullUrl, asset);
|
|
3370
3388
|
}
|
|
3371
3389
|
}
|
|
3372
|
-
else if (
|
|
3373
|
-
fullUrl
|
|
3374
|
-
}
|
|
3375
|
-
if (url !== fullUrl) {
|
|
3376
|
-
setOutputURL(fullUrl, asset);
|
|
3390
|
+
else if (importFile && url !== fullUrl) {
|
|
3391
|
+
setOutputURL(fullUrl);
|
|
3377
3392
|
}
|
|
3378
3393
|
}
|
|
3379
|
-
else if (importFile && url !== fullUrl) {
|
|
3380
|
-
setOutputURL(fullUrl);
|
|
3381
|
-
}
|
|
3382
3394
|
}
|
|
3383
3395
|
}
|
|
3384
3396
|
if (modified) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/chrome",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.4",
|
|
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.
|
|
21
|
-
"@e-mc/core": "^0.14.
|
|
22
|
-
"@e-mc/document": "^0.14.
|
|
23
|
-
"@e-mc/types": "^0.14.
|
|
20
|
+
"@e-mc/cloud": "^0.14.5",
|
|
21
|
+
"@e-mc/core": "^0.14.5",
|
|
22
|
+
"@e-mc/document": "^0.14.5",
|
|
23
|
+
"@e-mc/types": "^0.14.5",
|
|
24
24
|
"image-size": "^2.0.2"
|
|
25
25
|
}
|
|
26
26
|
}
|
package/types/squared.d.ts
CHANGED
|
@@ -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[];
|