@pi-r/chrome 0.2.8 → 0.2.10
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 +1 -1
- package/index.js +17 -13
- package/package.json +5 -5
- package/types/index.d.ts +7 -7
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright
|
|
1
|
+
Copyright 2024 An Pham
|
|
2
2
|
|
|
3
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
4
|
|
package/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
2
|
const path = require("path");
|
|
4
3
|
const fs = require("fs");
|
|
5
4
|
const asset_1 = require("@e-mc/document/asset");
|
|
@@ -25,6 +24,14 @@ const [PATTERN_STRING_SOME, PATTERN_STRING_MANY] = (function () {
|
|
|
25
24
|
const pattern = '(?:\\s|' + dom_1.DomWriter.PATTERN_COMMENT + '|`[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}`)';
|
|
26
25
|
return [pattern + '*', pattern + '+'];
|
|
27
26
|
})();
|
|
27
|
+
const [REGEXP_NTHCHILD, REGEXP_NTHCHILD_UNSAFE, REGEXP_REPLACECSS] = (function () {
|
|
28
|
+
const parenthesis = '(?:,[^()]+(?=\\))|[^()]|\\([^()]*\\(+|\\([^()]*\\)|(?:\\)[^()]+)?\\)*?)+';
|
|
29
|
+
return [
|
|
30
|
+
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'),
|
|
31
|
+
new RegExp(`\\(\\s*([+-])?(?:(\\d*)[nN]|(0))?\\s*([+-])?\\s*(\\d*)(?:\\s+[oO][fF]\\s+(${parenthesis})\\s*\\)|\\s*\\))`, 'g'),
|
|
32
|
+
new RegExp(`^@import\\s+(?:url\\((?:[^)]|(?<=\\\\)\\))+\\)|"(?:[^"]|(?<=\\\\)")+"|'(?:[^']|(?<=\\\\)')+')(\\s*layer(?:\\(([^)]*)\\)|\\b))?(?:\\s*supports\\((${parenthesis})\\))?(.*?);?$`)
|
|
33
|
+
];
|
|
34
|
+
})();
|
|
28
35
|
const REGEXP_COMMENT = new RegExp(dom_1.DomWriter.PATTERN_COMMENT, 'g');
|
|
29
36
|
const REGEXP_CONTENT = new RegExp(`\\bcontent${PATTERN_STRING_SOME}:${PATTERN_STRING_SOME}(?:"[^"]*"|'[^']*')`, 'gi');
|
|
30
37
|
const REGEXP_STYLE = new RegExp(`(<style${dom_1.DomWriter.PATTERN_TAGOPEN}*>)([\\S\\s]*?)(<\\/style\\s*>)`, 'gi');
|
|
@@ -32,12 +39,10 @@ const REGEXP_VARIABLES = new RegExp(`(\\s*)(--[^\\s:]*)${PATTERN_STRING_SOME}:[^
|
|
|
32
39
|
const REGEXP_FONTFACE = new RegExp(`(\\s*)@font-face${PATTERN_STRING_SOME}{([^}]+)}` + dom_1.DomWriter.PATTERN_TRAILINGSPACE, 'gi');
|
|
33
40
|
const REGEXP_FONTFAMILY = new RegExp(`font-family${PATTERN_STRING_SOME}:([^;}]+)`, 'i');
|
|
34
41
|
const REGEXP_KEYFRAMES = new RegExp(`(\\s*)@keyframes${PATTERN_STRING_MANY}([^{]+){`, 'gi');
|
|
35
|
-
const REGEXP_NTHCHILD = new RegExp(`\\(${PATTERN_STRING_SOME}([+-])?(?:(\\d*)[nN]|(0))${PATTERN_STRING_SOME}([+-])?${PATTERN_STRING_SOME}(\\d*)${PATTERN_STRING_SOME}\\)`, 'g');
|
|
36
42
|
const REGEXP_VARIABLES_UNSAFE = new RegExp(`(\\s*)(--[^\\s:]*)\\s*:[^;}]*([;}])` + dom_1.DomWriter.PATTERN_TRAILINGSPACE, 'g');
|
|
37
43
|
const REGEXP_FONTFACE_UNSAFE = new RegExp(`(\\s*)@font-face\\s*{([^}]+)}` + dom_1.DomWriter.PATTERN_TRAILINGSPACE, 'gi');
|
|
38
44
|
const REGEXP_FONTFAMILY_UNSAFE = /font-family\s*:([^;}]+)/i;
|
|
39
45
|
const REGEXP_KEYFRAMES_UNSAFE = /(\s*)@keyframes\s+([^{]+){/gi;
|
|
40
|
-
const REGEXP_NTHCHILD_UNSAFE = /\(\s*([+-])?(?:(\d*)[nN]|(0))\s*([+-])?\s*(\d*)\s*\)/g;
|
|
41
46
|
function removeNamespace(name, source, newline, comments) {
|
|
42
47
|
if (source.indexOf('-' + name) !== -1) {
|
|
43
48
|
const dataset = CACHE_DATASET[name] || (CACHE_DATASET[name] = [
|
|
@@ -1143,7 +1148,7 @@ class ChromeDocument extends Document {
|
|
|
1143
1148
|
return 0;
|
|
1144
1149
|
});
|
|
1145
1150
|
if (config) {
|
|
1146
|
-
const { useUnsafeReplace, baseUrl, productionRelease, productionIncremental, templateMap, userAgentData,
|
|
1151
|
+
const { useUnsafeReplace, baseUrl, productionRelease, productionIncremental, templateMap, userAgentData, cache } = config;
|
|
1147
1152
|
const target = this.config;
|
|
1148
1153
|
for (const attr in config) {
|
|
1149
1154
|
if (attr in target) {
|
|
@@ -1188,7 +1193,10 @@ class ChromeDocument extends Document {
|
|
|
1188
1193
|
if ((0, types_1.isObject)(userAgentData)) {
|
|
1189
1194
|
this.userAgentData = userAgentData;
|
|
1190
1195
|
}
|
|
1191
|
-
|
|
1196
|
+
const imports = (0, types_1.isPlainObject)(config.imports) ? { ...this.module.imports, ...config.imports } : this.module.imports;
|
|
1197
|
+
if (imports) {
|
|
1198
|
+
this.imports = imports;
|
|
1199
|
+
}
|
|
1192
1200
|
if ((0, types_1.isObject)(cache) && 'transform' in cache) {
|
|
1193
1201
|
this.customize({ transform: cache.transform });
|
|
1194
1202
|
}
|
|
@@ -1572,14 +1580,14 @@ class ChromeDocument extends Document {
|
|
|
1572
1580
|
replaceContent(source, statement, mimeType) {
|
|
1573
1581
|
switch (mimeType) {
|
|
1574
1582
|
case 'text/css': {
|
|
1575
|
-
const match =
|
|
1583
|
+
const match = REGEXP_REPLACECSS.exec((typeof statement === 'string' ? statement : statement[0]).trim());
|
|
1576
1584
|
if (match) {
|
|
1577
1585
|
const layer = match[1];
|
|
1578
1586
|
const supports = match[3]?.trim();
|
|
1579
1587
|
const query = match[4].trim();
|
|
1580
1588
|
if (layer || supports || query) {
|
|
1581
1589
|
const newline = (0, util_1.getNewline)(source);
|
|
1582
|
-
let result = supports ? `@supports (${
|
|
1590
|
+
let result = supports ? `@supports (${supports}) {` + newline : '';
|
|
1583
1591
|
if (query) {
|
|
1584
1592
|
result += `@media ${query} {` + newline;
|
|
1585
1593
|
}
|
|
@@ -3204,7 +3212,7 @@ class ChromeDocument extends Document {
|
|
|
3204
3212
|
const parseSelector = (value) => {
|
|
3205
3213
|
const items = [];
|
|
3206
3214
|
const revised = value.replace(useUnsafeCssReplace ? REGEXP_NTHCHILD_UNSAFE : REGEXP_NTHCHILD, (...capture) => {
|
|
3207
|
-
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)?`) + getStringSome() + '\\)') - 1) + '`';
|
|
3215
|
+
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) + '`';
|
|
3208
3216
|
});
|
|
3209
3217
|
let selector = '';
|
|
3210
3218
|
for (let i = 0, length = revised.length, casing = false, attr = false, quote = false; i < length; i++) {
|
|
@@ -3537,9 +3545,5 @@ class ChromeDocument extends Document {
|
|
|
3537
3545
|
}
|
|
3538
3546
|
ChromeDocument.INTERNAL_ASSIGNUUID = '__assign__';
|
|
3539
3547
|
ChromeDocument.INTERNAL_SERVERROOT = '__serverroot__';
|
|
3540
|
-
exports.default = ChromeDocument;
|
|
3541
3548
|
|
|
3542
|
-
|
|
3543
|
-
module.exports = exports.default;
|
|
3544
|
-
module.exports.default = exports.default;
|
|
3545
|
-
}
|
|
3549
|
+
module.exports = ChromeDocument;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/chrome",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.10",
|
|
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.5.
|
|
24
|
-
"@e-mc/core": "^0.5.
|
|
25
|
-
"@e-mc/document": "^0.5.
|
|
26
|
-
"@e-mc/types": "^0.5.
|
|
23
|
+
"@e-mc/cloud": "^0.5.6",
|
|
24
|
+
"@e-mc/core": "^0.5.6",
|
|
25
|
+
"@e-mc/document": "^0.5.6",
|
|
26
|
+
"@e-mc/types": "^0.5.6"
|
|
27
27
|
}
|
|
28
28
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -91,12 +91,12 @@ export interface IChromeDocument<T extends IFileManager<U>, U extends DocumentAs
|
|
|
91
91
|
formatMap?: ObjectMap<FormatUri>;
|
|
92
92
|
setElementSrc(asset: U, element: IXmlElement, value: string): void;
|
|
93
93
|
findDataValue(name: string): Undef<string>;
|
|
94
|
-
setInlinedAttributes(processing: FinalizeProcessing<T>): void;
|
|
95
|
-
applyTransforms(processing: FinalizeProcessing<T>): Promise<void>;
|
|
96
|
-
rewriteHtml(processing: FinalizeProcessing<T>): Promise<void>;
|
|
97
|
-
setElementAttributes(processing: FinalizeProcessing<T>, domBase: IDomWriter): Promise<void>;
|
|
98
|
-
applyDataSource(processing: FinalizeProcessing<T>, domBase: IDomWriter): Promise<void>;
|
|
99
|
-
setProductionAttributes(processing: FinalizeProcessing<T>): void;
|
|
94
|
+
setInlinedAttributes(processing: FinalizeProcessing<T, U>): void;
|
|
95
|
+
applyTransforms(processing: FinalizeProcessing<T, U>): Promise<void>;
|
|
96
|
+
rewriteHtml(processing: FinalizeProcessing<T, U>): Promise<void>;
|
|
97
|
+
setElementAttributes(processing: FinalizeProcessing<T, U>, domBase: IDomWriter): Promise<void>;
|
|
98
|
+
applyDataSource(processing: FinalizeProcessing<T, U>, domBase: IDomWriter): Promise<void>;
|
|
99
|
+
setProductionAttributes(processing: FinalizeProcessing<T, U>): void;
|
|
100
100
|
removeUnusedStyles(source: string, options?: UserConfig): Undef<string>;
|
|
101
101
|
removeServerRoot(value: string): string;
|
|
102
102
|
replaceContent(source: string, match: RegExpExecArray | string, mimeType?: string): Undef<string>;
|
|
@@ -115,4 +115,4 @@ export interface ChromeDocumentConstructor<T extends IFileManager<U>, U extends
|
|
|
115
115
|
INTERNAL_SERVERROOT: string;
|
|
116
116
|
readonly prototype: IChromeDocument<T, U>;
|
|
117
117
|
new(module?: DocumentModule, ...args: unknown[]): IChromeDocument<T, U>;
|
|
118
|
-
}
|
|
118
|
+
}
|