@e-mc/document 0.7.2 → 0.7.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/LICENSE +4 -8
- package/README.md +1 -1
- package/index.js +49 -35
- package/package.json +4 -4
- package/parse/dom.js +3 -2
- package/parse/index.js +24 -16
- package/transform/index.js +2 -1
package/LICENSE
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
Copyright 2023
|
|
1
|
+
Copyright 2023 Sukina
|
|
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
|
|
|
5
|
-
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
10
|
-
|
|
11
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
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/README.md
CHANGED
package/index.js
CHANGED
|
@@ -217,7 +217,7 @@ class Document extends core_1.Client {
|
|
|
217
217
|
let match;
|
|
218
218
|
while (match = pattern.exec(source)) {
|
|
219
219
|
const preceding = source.substring(lastIndex, match.index);
|
|
220
|
-
let opening = 0, closing =
|
|
220
|
+
let opening = 0, closing = 0;
|
|
221
221
|
for (let j = 0, q = preceding.length; j < q; ++j) {
|
|
222
222
|
switch (preceding[j]) {
|
|
223
223
|
case '{':
|
|
@@ -228,8 +228,11 @@ class Document extends core_1.Client {
|
|
|
228
228
|
break;
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
|
-
if (opening === closing
|
|
232
|
-
|
|
231
|
+
if (opening === closing) {
|
|
232
|
+
if (!multiple || match[1] && sanitizeValue(match[1]) === sanitizeValue(local[3])) {
|
|
233
|
+
return upgrade ? parse_1.XmlWriter.replaceMatch(match, source, value, pattern) : source;
|
|
234
|
+
}
|
|
235
|
+
lastIndex = match.index + match[0].length;
|
|
233
236
|
}
|
|
234
237
|
}
|
|
235
238
|
return spliceSource(source, lastIndex, lastIndex, ident.repeat(length) + value + newline);
|
|
@@ -250,6 +253,7 @@ class Document extends core_1.Client {
|
|
|
250
253
|
return lastIndex > 0 ? spliceSource(source, lastIndex, lastIndex, content) : source + newline + content;
|
|
251
254
|
}
|
|
252
255
|
static generateLintTable(messages, options) {
|
|
256
|
+
var _a, _b, _c;
|
|
253
257
|
const { leadingText, trailingText, pathname, filename, ruleWidth = 30, messageWidth = 60 } = options;
|
|
254
258
|
const result = [];
|
|
255
259
|
const truncate = (value, width) => value.length > width ? value.substring(0, width - 3) + '...' : value.padStart(width);
|
|
@@ -295,9 +299,9 @@ class Document extends core_1.Client {
|
|
|
295
299
|
maxWidth += maxLine + maxColumn;
|
|
296
300
|
const title = (leadingText || '') + (pathname || filename ? (leadingText ? ': ' : '') + (pathname && filename ? path.join(pathname, filename) : pathname || filename) : '');
|
|
297
301
|
const divider = { type: types_1.STATUS_TYPE.INFO, value: '-'.repeat(maxWidth), timeStamp };
|
|
298
|
-
errorCount = (options.errorCount
|
|
299
|
-
warningCount = (options.warningCount
|
|
300
|
-
fatalErrorCount = (options.fatalErrorCount
|
|
302
|
+
errorCount = ((_a = options.errorCount) !== null && _a !== void 0 ? _a : errorCount).toString();
|
|
303
|
+
warningCount = ((_b = options.warningCount) !== null && _b !== void 0 ? _b : warningCount).toString();
|
|
304
|
+
fatalErrorCount = ((_c = options.fatalErrorCount) !== null && _c !== void 0 ? _c : fatalErrorCount).toString();
|
|
301
305
|
const hasFatal = fatalErrorCount !== '0';
|
|
302
306
|
result.unshift(divider, { type: types_1.STATUS_TYPE.INFO, value: title + ' '.repeat(maxWidth - title.length - (hasFatal ? fatalErrorCount.length + 9 : 0)) + (hasFatal ? `fatal(${chalk.bold.bgRed.white(` ${fatalErrorCount} `)})` : ''), timeStamp, duration: currentTime - timeStamp }, divider);
|
|
303
307
|
result.push(divider);
|
|
@@ -323,14 +327,15 @@ class Document extends core_1.Client {
|
|
|
323
327
|
}
|
|
324
328
|
restart() { }
|
|
325
329
|
init(assets, config) {
|
|
326
|
-
var _a;
|
|
330
|
+
var _a, _b;
|
|
331
|
+
var _c;
|
|
327
332
|
let ignoreModules, ignoreExtensions;
|
|
328
333
|
if (config) {
|
|
329
334
|
let baseUrl;
|
|
330
335
|
({ baseUrl, ignoreModules, ignoreExtensions } = config);
|
|
331
336
|
let username, users;
|
|
332
|
-
if (username = this.host
|
|
333
|
-
if (!(0, types_1.isPlainObject)(users = this.settings.users
|
|
337
|
+
if (username = (_a = this.host) === null || _a === void 0 ? void 0 : _a.username) {
|
|
338
|
+
if (!(0, types_1.isPlainObject)(users = (_b = this.settings.users) === null || _b === void 0 ? void 0 : _b[username])) {
|
|
334
339
|
users = undefined;
|
|
335
340
|
}
|
|
336
341
|
else if (Array.isArray(users.extensions)) {
|
|
@@ -387,8 +392,8 @@ class Document extends core_1.Client {
|
|
|
387
392
|
}
|
|
388
393
|
}
|
|
389
394
|
}
|
|
390
|
-
if (this.dataSource.length && !ignoreModules
|
|
391
|
-
const db = (
|
|
395
|
+
if (this.dataSource.length && !(ignoreModules === null || ignoreModules === void 0 ? void 0 : ignoreModules.includes('db'))) {
|
|
396
|
+
const db = (_c = this.module).db || (_c.db = {});
|
|
392
397
|
const handler = db.handler;
|
|
393
398
|
const database = this.dataSource.filter(this.forDb.bind(this));
|
|
394
399
|
let instance;
|
|
@@ -467,7 +472,7 @@ class Document extends core_1.Client {
|
|
|
467
472
|
this._transformConfig = null;
|
|
468
473
|
return;
|
|
469
474
|
}
|
|
470
|
-
switch (algorithm = algorithm
|
|
475
|
+
switch (algorithm = algorithm === null || algorithm === void 0 ? void 0 : algorithm.toLowerCase()) {
|
|
471
476
|
case 'md5':
|
|
472
477
|
case 'sha1':
|
|
473
478
|
case 'sha224':
|
|
@@ -585,11 +590,12 @@ class Document extends core_1.Client {
|
|
|
585
590
|
delete data[name];
|
|
586
591
|
}
|
|
587
592
|
resolveDir(name, ...paths) {
|
|
588
|
-
|
|
593
|
+
var _a, _b;
|
|
594
|
+
let baseDir = (_a = this.settings.directory) === null || _a === void 0 ? void 0 : _a[name];
|
|
589
595
|
if (baseDir) {
|
|
590
596
|
try {
|
|
591
597
|
baseDir = path.resolve(baseDir);
|
|
592
|
-
const username = this.host
|
|
598
|
+
const username = (_b = this.host) === null || _b === void 0 ? void 0 : _b.username;
|
|
593
599
|
let result;
|
|
594
600
|
if (username) {
|
|
595
601
|
const leading = path.join(baseDir, 'users', username);
|
|
@@ -665,6 +671,7 @@ class Document extends core_1.Client {
|
|
|
665
671
|
return null;
|
|
666
672
|
}
|
|
667
673
|
findVersion(name, fallback = '') {
|
|
674
|
+
var _a;
|
|
668
675
|
let result;
|
|
669
676
|
const versions = this.module.versions;
|
|
670
677
|
if (versions) {
|
|
@@ -676,7 +683,7 @@ class Document extends core_1.Client {
|
|
|
676
683
|
}
|
|
677
684
|
}
|
|
678
685
|
else {
|
|
679
|
-
result = this.module.versions
|
|
686
|
+
result = (_a = this.module.versions) === null || _a === void 0 ? void 0 : _a[name];
|
|
680
687
|
}
|
|
681
688
|
}
|
|
682
689
|
return result || fallback;
|
|
@@ -706,6 +713,7 @@ class Document extends core_1.Client {
|
|
|
706
713
|
}
|
|
707
714
|
locateSourceFiles(file, code, bundleContent) {
|
|
708
715
|
return (imports = this.imports) => {
|
|
716
|
+
var _a;
|
|
709
717
|
const href = file.uri;
|
|
710
718
|
const sourceFile = [];
|
|
711
719
|
let mainFile, invalid;
|
|
@@ -748,7 +756,7 @@ class Document extends core_1.Client {
|
|
|
748
756
|
invalid = true;
|
|
749
757
|
break;
|
|
750
758
|
}
|
|
751
|
-
sourceFile.push(['', this.resolveImports
|
|
759
|
+
sourceFile.push(['', ((_a = this.resolveImports) === null || _a === void 0 ? void 0 : _a.call(this, item, source, localFile)) || source, localFile]);
|
|
752
760
|
}
|
|
753
761
|
}
|
|
754
762
|
}
|
|
@@ -759,10 +767,11 @@ class Document extends core_1.Client {
|
|
|
759
767
|
}
|
|
760
768
|
resolveSourceFile(file) {
|
|
761
769
|
return (code, imports = this.imports) => {
|
|
770
|
+
var _a;
|
|
762
771
|
const uri = file.uri;
|
|
763
772
|
let source, sourceFile;
|
|
764
773
|
if (code && imports && Object.keys(imports).length) {
|
|
765
|
-
const output = this.resolveImports
|
|
774
|
+
const output = (_a = this.resolveImports) === null || _a === void 0 ? void 0 : _a.call(this, file, code, uri && this.findSourceRoot(uri, imports));
|
|
766
775
|
if (output) {
|
|
767
776
|
source = output;
|
|
768
777
|
}
|
|
@@ -803,20 +812,23 @@ class Document extends core_1.Client {
|
|
|
803
812
|
return item.source !== 'cloud';
|
|
804
813
|
}
|
|
805
814
|
hasEval(name) {
|
|
806
|
-
|
|
815
|
+
var _a;
|
|
816
|
+
return !!((_a = this.module.eval) === null || _a === void 0 ? void 0 : _a[name]);
|
|
807
817
|
}
|
|
808
818
|
settingsOf(name, option) {
|
|
809
|
-
|
|
819
|
+
var _a;
|
|
820
|
+
const options = (_a = this.settings.options) === null || _a === void 0 ? void 0 : _a[name];
|
|
810
821
|
if ((0, types_1.isObject)(options)) {
|
|
811
822
|
return options[option];
|
|
812
823
|
}
|
|
813
824
|
}
|
|
814
825
|
async parseTemplate(viewEngine, template, data) {
|
|
826
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
815
827
|
let target, stored;
|
|
816
828
|
if (typeof viewEngine === 'string') {
|
|
817
|
-
target = this.settings.view_engine
|
|
818
|
-
const username = this.host
|
|
819
|
-
const userConfig = username && this.settings.users
|
|
829
|
+
target = (_a = this.settings.view_engine) === null || _a === void 0 ? void 0 : _a[viewEngine];
|
|
830
|
+
const username = (_b = this.host) === null || _b === void 0 ? void 0 : _b.username;
|
|
831
|
+
const userConfig = username && ((_e = (_d = (_c = this.settings.users) === null || _c === void 0 ? void 0 : _c[username]) === null || _d === void 0 ? void 0 : _d.view_engine) === null || _e === void 0 ? void 0 : _e[viewEngine]);
|
|
820
832
|
if ((0, types_1.isPlainObject)(userConfig)) {
|
|
821
833
|
if ((0, types_1.isPlainObject)(target)) {
|
|
822
834
|
(0, types_1.cloneObject)(userConfig, { target, deep: true, preserve: true });
|
|
@@ -856,7 +868,7 @@ class Document extends core_1.Client {
|
|
|
856
868
|
(0, types_1.coerceObject)(output, stored);
|
|
857
869
|
}
|
|
858
870
|
}
|
|
859
|
-
const username = this.host
|
|
871
|
+
const username = ((_f = this.host) === null || _f === void 0 ? void 0 : _f.username) || '';
|
|
860
872
|
const cache = CACHE_TEMPLATE[name] || (CACHE_TEMPLATE[name] = {});
|
|
861
873
|
const cacheKey = username + core_1.Client.asHash(template + (compile ? core_1.Client.asString(compile) : ''));
|
|
862
874
|
let result = '', render, valid;
|
|
@@ -869,7 +881,7 @@ class Document extends core_1.Client {
|
|
|
869
881
|
}
|
|
870
882
|
for (let i = 0, j = 0, row; i < length; ++i) {
|
|
871
883
|
if ((0, types_1.isPlainObject)(row = data[i])) {
|
|
872
|
-
row.__index__
|
|
884
|
+
(_g = row.__index__) !== null && _g !== void 0 ? _g : (row.__index__ = ++j);
|
|
873
885
|
if (output) {
|
|
874
886
|
row = { ...output, ...row };
|
|
875
887
|
}
|
|
@@ -886,7 +898,7 @@ class Document extends core_1.Client {
|
|
|
886
898
|
}
|
|
887
899
|
}
|
|
888
900
|
}
|
|
889
|
-
return singleRow ? render.call(context, data)
|
|
901
|
+
return singleRow ? (_h = render.call(context, data)) !== null && _h !== void 0 ? _h : null : valid ? result : null;
|
|
890
902
|
}
|
|
891
903
|
catch (err) {
|
|
892
904
|
this.abort('view_engine');
|
|
@@ -895,13 +907,14 @@ class Document extends core_1.Client {
|
|
|
895
907
|
return null;
|
|
896
908
|
}
|
|
897
909
|
async transform(type, code, format, options = {}) {
|
|
910
|
+
var _a, _b, _c, _d;
|
|
898
911
|
let transform = this.settings.transform, data;
|
|
899
912
|
if (!transform || !(0, types_1.isObject)(data = transform[type])) {
|
|
900
913
|
return;
|
|
901
914
|
}
|
|
902
915
|
format = typeof format === 'string' ? format.trim().split(/\s*\+\s*/) : format.map(item => typeof item === 'string' ? item.trim() : '');
|
|
903
916
|
const moduleName = this.moduleName;
|
|
904
|
-
const username = this.host
|
|
917
|
+
const username = ((_a = this.host) === null || _a === void 0 ? void 0 : _a.username) || '';
|
|
905
918
|
const config = this._transformConfig;
|
|
906
919
|
const cacheData = config && options.cacheData;
|
|
907
920
|
const cacheType = username && core_1.Client.enabled("memory.settings.users", username) ? true : this.cacheDir || core_1.Client.enabled("memory.settings.users");
|
|
@@ -979,7 +992,7 @@ class Document extends core_1.Client {
|
|
|
979
992
|
}
|
|
980
993
|
}
|
|
981
994
|
if (result) {
|
|
982
|
-
result.storedLog
|
|
995
|
+
(_b = result.storedLog) === null || _b === void 0 ? void 0 : _b.forEach(log => this.addLog(log));
|
|
983
996
|
this.formatMessage(4, type, [joinString(cacheName, format.filter(value => value).join(' | '), options.filename), 'cache'], uri, { ...core_1.Client.LOG_STYLE_NOTICE, hintBold: true });
|
|
984
997
|
return result;
|
|
985
998
|
}
|
|
@@ -991,7 +1004,7 @@ class Document extends core_1.Client {
|
|
|
991
1004
|
const series = new transform_1.TransformSeries(type, code, options);
|
|
992
1005
|
series.init(this, __dirname);
|
|
993
1006
|
let valid, excluded, userData, userImports, ignoreCache, storedLog, sourceFiles;
|
|
994
|
-
if (username && (transform = this.settings.users
|
|
1007
|
+
if (username && (transform = (_d = (_c = this.settings.users) === null || _c === void 0 ? void 0 : _c[username]) === null || _d === void 0 ? void 0 : _d.transform)) {
|
|
995
1008
|
userData = transform[type];
|
|
996
1009
|
userImports = transform.imports;
|
|
997
1010
|
}
|
|
@@ -1000,12 +1013,12 @@ class Document extends core_1.Client {
|
|
|
1000
1013
|
this.abort('transform');
|
|
1001
1014
|
};
|
|
1002
1015
|
const includes = (name) => {
|
|
1003
|
-
const include = config
|
|
1004
|
-
if (include === true || include
|
|
1016
|
+
const include = config === null || config === void 0 ? void 0 : config.include[type];
|
|
1017
|
+
if (include === true || (include === null || include === void 0 ? void 0 : include.includes(name))) {
|
|
1005
1018
|
const exclude = config.exclude[type];
|
|
1006
1019
|
return !exclude || exclude === true && include !== true || Array.isArray(exclude) && !exclude.includes(name);
|
|
1007
1020
|
}
|
|
1008
|
-
return cacheData
|
|
1021
|
+
return (cacheData === null || cacheData === void 0 ? void 0 : cacheData.override) === true;
|
|
1009
1022
|
};
|
|
1010
1023
|
for (let i = 0, length = format.length, name; i < length; ++i) {
|
|
1011
1024
|
if (this.aborted) {
|
|
@@ -1124,7 +1137,7 @@ class Document extends core_1.Client {
|
|
|
1124
1137
|
let transformer = CACHE_PACKAGE[plugin + username];
|
|
1125
1138
|
if (!transformer) {
|
|
1126
1139
|
try {
|
|
1127
|
-
let pkg = this.resolveDir('package', plugin + '.js') || userImports
|
|
1140
|
+
let pkg = this.resolveDir('package', plugin + '.js') || (userImports === null || userImports === void 0 ? void 0 : userImports[plugin]) || imports[plugin] || util_1.IMPORTS[plugin];
|
|
1128
1141
|
if ((0, types_1.isString)(pkg)) {
|
|
1129
1142
|
const match = /^(@?\S+)@(\d+(?:\.\d+(?:\.\S+)?)?|[a-z]+)$/.exec(pkg);
|
|
1130
1143
|
if (match) {
|
|
@@ -1193,7 +1206,7 @@ class Document extends core_1.Client {
|
|
|
1193
1206
|
output.map = sourceMap.map;
|
|
1194
1207
|
}
|
|
1195
1208
|
if ((0, types_1.isArray)(series.supplementChunks)) {
|
|
1196
|
-
output.chunks = series.supplementChunks.map(item => ({ code: item.code, map: output.map && item.sourceMap
|
|
1209
|
+
output.chunks = series.supplementChunks.map(item => { var _a; return ({ code: item.code, map: output.map && ((_a = item.sourceMap) === null || _a === void 0 ? void 0 : _a.map), entryPoint: item.entryPoint, filename: item.filename }); });
|
|
1197
1210
|
}
|
|
1198
1211
|
if (sourceFiles) {
|
|
1199
1212
|
output.sourceFiles = sourceFiles;
|
|
@@ -1283,6 +1296,7 @@ class Document extends core_1.Client {
|
|
|
1283
1296
|
return this._dataSource || [];
|
|
1284
1297
|
}
|
|
1285
1298
|
set imports(value) {
|
|
1299
|
+
var _a, _b, _c;
|
|
1286
1300
|
if (!(0, types_1.isPlainObject)(value)) {
|
|
1287
1301
|
this._imports = null;
|
|
1288
1302
|
return;
|
|
@@ -1292,8 +1306,8 @@ class Document extends core_1.Client {
|
|
|
1292
1306
|
this._imports = Object.assign(imports, value);
|
|
1293
1307
|
}
|
|
1294
1308
|
else {
|
|
1295
|
-
const username = this.host
|
|
1296
|
-
imports = username && this.settings.users
|
|
1309
|
+
const username = (_a = this.host) === null || _a === void 0 ? void 0 : _a.username;
|
|
1310
|
+
imports = username && ((_c = (_b = this.settings.users) === null || _b === void 0 ? void 0 : _b[username]) === null || _c === void 0 ? void 0 : _c.imports) || this.module.imports;
|
|
1297
1311
|
this._imports = Object.assign(this._imports || {}, (0, types_1.isPlainObject)(imports) ? imports : undefined, value);
|
|
1298
1312
|
}
|
|
1299
1313
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/document",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.4",
|
|
4
4
|
"description": "Document constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/core": "0.7.
|
|
24
|
-
"@e-mc/db": "0.7.
|
|
25
|
-
"@e-mc/types": "0.7.
|
|
23
|
+
"@e-mc/core": "0.7.4",
|
|
24
|
+
"@e-mc/db": "0.7.4",
|
|
25
|
+
"@e-mc/types": "0.7.4",
|
|
26
26
|
"chalk": "4.1.2",
|
|
27
27
|
"htmlparser2": "^9.0.0",
|
|
28
28
|
"js-yaml": "^4.1.0",
|
package/parse/dom.js
CHANGED
|
@@ -34,7 +34,7 @@ class DomWriter extends index_1.XmlWriter {
|
|
|
34
34
|
tagGroup.push(new RegExp('^' + (0, types_1.escapePattern)(start)));
|
|
35
35
|
}
|
|
36
36
|
const end = ignoreTagGroup[i + 1];
|
|
37
|
-
if (end
|
|
37
|
+
if ((end === null || end === void 0 ? void 0 : end[end.length - 1]) === '>') {
|
|
38
38
|
tagGroup.push(new RegExp((0, types_1.escapePattern)(start) + '$'));
|
|
39
39
|
}
|
|
40
40
|
}
|
|
@@ -226,7 +226,8 @@ class HtmlElement extends index_1.XmlElement {
|
|
|
226
226
|
this._documentType = "HTML";
|
|
227
227
|
}
|
|
228
228
|
getTagOffset(source) {
|
|
229
|
-
|
|
229
|
+
var _a;
|
|
230
|
+
switch (((_a = this.node.append) === null || _a === void 0 ? void 0 : _a.tagName) || this.tagName) {
|
|
230
231
|
case 'html':
|
|
231
232
|
case 'title':
|
|
232
233
|
case 'style':
|
package/parse/index.js
CHANGED
|
@@ -235,7 +235,7 @@ class XmlWriter {
|
|
|
235
235
|
return result;
|
|
236
236
|
}
|
|
237
237
|
const nodes = domutils.getElementsByTagName(node.tagName, outDom, true);
|
|
238
|
-
if (!parser
|
|
238
|
+
if (!(parser === null || parser === void 0 ? void 0 : parser.xmlMode)) {
|
|
239
239
|
nodes.filter(item => item.next && item.next.startIndex <= item.endIndex).forEach(item => {
|
|
240
240
|
for (let i = 0, length = nodes.length; i < length; ++i) {
|
|
241
241
|
const element = nodes[i];
|
|
@@ -262,7 +262,7 @@ class XmlWriter {
|
|
|
262
262
|
const locator = node.locator;
|
|
263
263
|
if (locator && locatorAttr) {
|
|
264
264
|
const { element } = this.locateElement(source, locator, locatorAttr, { parser, outDom });
|
|
265
|
-
if (element
|
|
265
|
+
if ((element === null || element === void 0 ? void 0 : element.tagName) === node.tagName) {
|
|
266
266
|
result.element = element;
|
|
267
267
|
index = nodes.findIndex(item => item === element);
|
|
268
268
|
}
|
|
@@ -346,10 +346,12 @@ class XmlWriter {
|
|
|
346
346
|
CACHE_TAGVOID[type] = values;
|
|
347
347
|
}
|
|
348
348
|
static isTagVoid(type, tagName) {
|
|
349
|
-
|
|
349
|
+
var _a;
|
|
350
|
+
return !!((_a = CACHE_TAGVOID[type]) === null || _a === void 0 ? void 0 : _a.includes(tagName));
|
|
350
351
|
}
|
|
351
352
|
static getNodeId(node, document) {
|
|
352
|
-
|
|
353
|
+
var _a;
|
|
354
|
+
return ((_a = node.id) === null || _a === void 0 ? void 0 : _a[document]) || '';
|
|
353
355
|
}
|
|
354
356
|
static getNameOfId(document) {
|
|
355
357
|
return `data-${document}-id`;
|
|
@@ -424,7 +426,7 @@ class XmlWriter {
|
|
|
424
426
|
if ((ignoreCase ? tagName.toLowerCase() === other.tagName.toLowerCase() : tagName === other.tagName) && (index === other.index && isIndex(index) || tagIndex === other.tagIndex && tagCount === other.tagCount && isIndex(tagIndex) && isCount(tagCount))) {
|
|
425
427
|
return true;
|
|
426
428
|
}
|
|
427
|
-
return document && other.id && id
|
|
429
|
+
return document && other.id && (id === null || id === void 0 ? void 0 : id[document]) ? id[document] === other.id[document] : false;
|
|
428
430
|
}
|
|
429
431
|
static isIndex(value) {
|
|
430
432
|
return isIndex(value);
|
|
@@ -450,7 +452,7 @@ class XmlWriter {
|
|
|
450
452
|
this._patternIgnore = null;
|
|
451
453
|
this._writeStartIndex = -1;
|
|
452
454
|
this._source = source;
|
|
453
|
-
this.parser = options
|
|
455
|
+
this.parser = options === null || options === void 0 ? void 0 : options.parser;
|
|
454
456
|
}
|
|
455
457
|
init(offsetMap) {
|
|
456
458
|
const appending = [];
|
|
@@ -461,7 +463,7 @@ class XmlWriter {
|
|
|
461
463
|
}
|
|
462
464
|
if (isCount(item.tagCount)) {
|
|
463
465
|
const tagName = item.tagName;
|
|
464
|
-
item.tagCount += offsetMap
|
|
466
|
+
item.tagCount += (offsetMap === null || offsetMap === void 0 ? void 0 : offsetMap[tagName]) || 0;
|
|
465
467
|
this._tagCount[tagName] = item.tagCount;
|
|
466
468
|
}
|
|
467
469
|
deletePosition(item, rootName);
|
|
@@ -550,6 +552,7 @@ class XmlWriter {
|
|
|
550
552
|
return null;
|
|
551
553
|
}
|
|
552
554
|
write(element) {
|
|
555
|
+
var _a;
|
|
553
556
|
if (!element.modified) {
|
|
554
557
|
return true;
|
|
555
558
|
}
|
|
@@ -580,7 +583,7 @@ class XmlWriter {
|
|
|
580
583
|
if (append) {
|
|
581
584
|
const { tagName, id, textContent = '', prepend, nextSibling } = append;
|
|
582
585
|
if (!prepend) {
|
|
583
|
-
node.index = nextSibling
|
|
586
|
+
node.index = nextSibling !== null && nextSibling !== void 0 ? nextSibling : -1;
|
|
584
587
|
}
|
|
585
588
|
(node.id || (node.id = {}))[this.documentName] = id;
|
|
586
589
|
element.id = id;
|
|
@@ -603,7 +606,7 @@ class XmlWriter {
|
|
|
603
606
|
this.renameTag(node, element.tagName);
|
|
604
607
|
}
|
|
605
608
|
this.update(node, outerXml, append, element.tagOffset);
|
|
606
|
-
if (element.innerXml && !element.remove && (element.hasModifiedContent() || this.patternIgnore
|
|
609
|
+
if (element.innerXml && !element.remove && (element.hasModifiedContent() || ((_a = this.patternIgnore) === null || _a === void 0 ? void 0 : _a.test(element.tagName)))) {
|
|
607
610
|
this._hasInvalidContent = true;
|
|
608
611
|
this._writeStartIndex = -1;
|
|
609
612
|
}
|
|
@@ -802,6 +805,7 @@ class XmlWriter {
|
|
|
802
805
|
}
|
|
803
806
|
}
|
|
804
807
|
indexTag(tagName, append, offset = 0) {
|
|
808
|
+
var _a;
|
|
805
809
|
if (tagName in this._tagCount) {
|
|
806
810
|
const elements = [];
|
|
807
811
|
const revised = [];
|
|
@@ -871,7 +875,7 @@ class XmlWriter {
|
|
|
871
875
|
return;
|
|
872
876
|
}
|
|
873
877
|
}
|
|
874
|
-
const id = append ? append.id : revised[0].id
|
|
878
|
+
const id = append ? append.id : (_a = revised[0].id) === null || _a === void 0 ? void 0 : _a[this.documentName];
|
|
875
879
|
if (id) {
|
|
876
880
|
const element = XmlWriter.findElement(this.source, (append || revised[0]), { document: this.documentName, id, tagCount: nextCount, parser: this.parser });
|
|
877
881
|
if (element) {
|
|
@@ -893,7 +897,7 @@ class XmlWriter {
|
|
|
893
897
|
item.index = -1;
|
|
894
898
|
}
|
|
895
899
|
const append = item.append;
|
|
896
|
-
if (append
|
|
900
|
+
if ((append === null || append === void 0 ? void 0 : append.tagName) === tagName) {
|
|
897
901
|
delete append.tagCount;
|
|
898
902
|
const nextSibling = append.nextSibling;
|
|
899
903
|
if (isIndex(nextSibling)) {
|
|
@@ -954,6 +958,7 @@ class XmlWriter {
|
|
|
954
958
|
}
|
|
955
959
|
getElementsByTagName(tagName, ignoreCase = false, options) {
|
|
956
960
|
var _a;
|
|
961
|
+
var _b;
|
|
957
962
|
let tagVoid;
|
|
958
963
|
if (options) {
|
|
959
964
|
({ tagVoid } = options);
|
|
@@ -963,14 +968,14 @@ class XmlWriter {
|
|
|
963
968
|
const result = [];
|
|
964
969
|
const patternId = XmlWriter.getPatternId(this.nameOfId);
|
|
965
970
|
const flags = ignoreCase ? 'gi' : 'g';
|
|
966
|
-
const pattern = CACHE_TAGNAME[
|
|
971
|
+
const pattern = CACHE_TAGNAME[_b = tagName + flags + '3'] || (CACHE_TAGNAME[_b] = new RegExp(`<${escapeTagName(tagName) + PATTERN_TAGOPEN}*>`, flags));
|
|
967
972
|
pattern.lastIndex = 0;
|
|
968
973
|
let match;
|
|
969
974
|
while (match = pattern.exec(source)) {
|
|
970
975
|
const startIndex = match.index;
|
|
971
976
|
let outerXml = match[0], endIndex = startIndex + outerXml.length - 1;
|
|
972
977
|
if (!invalid || isValidIndex(invalid, startIndex, endIndex)) {
|
|
973
|
-
const id = patternId.exec(outerXml)
|
|
978
|
+
const id = (_a = patternId.exec(outerXml)) === null || _a === void 0 ? void 0 : _a[1];
|
|
974
979
|
if (!tagVoid) {
|
|
975
980
|
const [index, closeTag] = findCloseIndex(source, tagName, endIndex + 1, ignoreCase);
|
|
976
981
|
if (index !== -1) {
|
|
@@ -1152,6 +1157,7 @@ class XmlElement {
|
|
|
1152
1157
|
}
|
|
1153
1158
|
}
|
|
1154
1159
|
getAttribute(name) {
|
|
1160
|
+
var _a;
|
|
1155
1161
|
let result = this._attributes.get(this._ignoreCase ? name = name.toLowerCase() : name);
|
|
1156
1162
|
if (result) {
|
|
1157
1163
|
return result;
|
|
@@ -1164,7 +1170,7 @@ class XmlElement {
|
|
|
1164
1170
|
if (outerXml) {
|
|
1165
1171
|
const index = XmlWriter.findCloseTag(outerXml);
|
|
1166
1172
|
if (index !== -1) {
|
|
1167
|
-
return XmlWriter.getPatternId(this.nameOfId).exec(outerXml.substring(0, index))
|
|
1173
|
+
return ((_a = XmlWriter.getPatternId(this.nameOfId).exec(outerXml.substring(0, index))) === null || _a === void 0 ? void 0 : _a[1]) || '';
|
|
1168
1174
|
}
|
|
1169
1175
|
}
|
|
1170
1176
|
}
|
|
@@ -1376,7 +1382,8 @@ class XmlElement {
|
|
|
1376
1382
|
return [this.tagName, attributes, this.innerXml];
|
|
1377
1383
|
}
|
|
1378
1384
|
getInnerOffset(tagName) {
|
|
1379
|
-
|
|
1385
|
+
var _a;
|
|
1386
|
+
return ((_a = this._tagOffset) === null || _a === void 0 ? void 0 : _a[tagName]) || 0;
|
|
1380
1387
|
}
|
|
1381
1388
|
hasPosition() {
|
|
1382
1389
|
return isIndex(this.node.startIndex) && isIndex(this.node.endIndex);
|
|
@@ -1412,7 +1419,8 @@ class XmlElement {
|
|
|
1412
1419
|
return this._documentType || this.documentName;
|
|
1413
1420
|
}
|
|
1414
1421
|
get tagVoid() {
|
|
1415
|
-
|
|
1422
|
+
var _a;
|
|
1423
|
+
return (_a = this._tagVoid) !== null && _a !== void 0 ? _a : XmlWriter.isTagVoid(this.documentType, this.tagName);
|
|
1416
1424
|
}
|
|
1417
1425
|
set innerXml(value) {
|
|
1418
1426
|
if (!this.tagVoid && value !== this._innerXml) {
|
package/transform/index.js
CHANGED
|
@@ -136,8 +136,9 @@ class TransformSeries extends core_1.Module {
|
|
|
136
136
|
return context;
|
|
137
137
|
}
|
|
138
138
|
close(instance) {
|
|
139
|
+
var _e;
|
|
139
140
|
core_1.AbortComponent.detach(instance, this.signal);
|
|
140
|
-
this.host
|
|
141
|
+
(_e = this.host) === null || _e === void 0 ? void 0 : _e.release(this);
|
|
141
142
|
}
|
|
142
143
|
set code(value) {
|
|
143
144
|
this[kCode] = value;
|