@e-mc/document 0.13.5 → 0.13.7
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/README.md +9 -9
- package/index.js +80 -69
- package/package.json +4 -4
- package/parse/dom.js +3 -4
- package/parse/index.js +4 -4
- package/util.js +1 -1
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
## Interface
|
|
11
11
|
|
|
12
|
-
* [View Source](https://www.unpkg.com/@e-mc/types@0.13.
|
|
12
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.13.7/lib/index.d.ts)
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { DataSource, ViewEngine } from "./squared";
|
|
@@ -185,14 +185,14 @@ NOTE: **@e-mc/document** is an abstract base class and cannot be instantiated. *
|
|
|
185
185
|
|
|
186
186
|
## References
|
|
187
187
|
|
|
188
|
-
- https://www.unpkg.com/@e-mc/types@0.13.
|
|
189
|
-
- https://www.unpkg.com/@e-mc/types@0.13.
|
|
190
|
-
- https://www.unpkg.com/@e-mc/types@0.13.
|
|
191
|
-
- https://www.unpkg.com/@e-mc/types@0.13.
|
|
192
|
-
- https://www.unpkg.com/@e-mc/types@0.13.
|
|
193
|
-
- https://www.unpkg.com/@e-mc/types@0.13.
|
|
194
|
-
- https://www.unpkg.com/@e-mc/types@0.13.
|
|
195
|
-
- https://www.unpkg.com/@e-mc/types@0.13.
|
|
188
|
+
- https://www.unpkg.com/@e-mc/types@0.13.7/lib/squared.d.ts
|
|
189
|
+
- https://www.unpkg.com/@e-mc/types@0.13.7/lib/asset.d.ts
|
|
190
|
+
- https://www.unpkg.com/@e-mc/types@0.13.7/lib/core.d.ts
|
|
191
|
+
- https://www.unpkg.com/@e-mc/types@0.13.7/lib/document.d.ts
|
|
192
|
+
- https://www.unpkg.com/@e-mc/types@0.13.7/lib/filemanager.d.ts
|
|
193
|
+
- https://www.unpkg.com/@e-mc/types@0.13.7/lib/logger.d.ts
|
|
194
|
+
- https://www.unpkg.com/@e-mc/types@0.13.7/lib/settings.d.ts
|
|
195
|
+
- https://www.unpkg.com/@e-mc/types@0.13.7/lib/watch.d.ts
|
|
196
196
|
|
|
197
197
|
## LICENSE
|
|
198
198
|
|
package/index.js
CHANGED
|
@@ -12,21 +12,28 @@ const transform_1 = require("@e-mc/document/transform");
|
|
|
12
12
|
const parse_1 = require("@e-mc/document/parse");
|
|
13
13
|
const util_1 = require("@e-mc/document/util");
|
|
14
14
|
const kDocument = Symbol.for('document:constructor');
|
|
15
|
-
const CACHE_PACKAGE =
|
|
15
|
+
const CACHE_PACKAGE = new Map();
|
|
16
16
|
const CACHE_CONFIG = new Map();
|
|
17
|
-
const CACHE_TEMPLATE =
|
|
17
|
+
const CACHE_TEMPLATE = new Map();
|
|
18
18
|
const CACHE_VIEWENGINE = new Map();
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
let CACHE_ETAG;
|
|
20
|
+
let CACHE_CODE;
|
|
21
|
+
let CACHE_HASH;
|
|
22
|
+
let CACHE_EXTERNAL;
|
|
23
|
+
let CACHE_PICOMATCH;
|
|
24
24
|
let CACHE_TOTAL = 0;
|
|
25
|
+
function initCache() {
|
|
26
|
+
CACHE_ETAG = Object.create(null);
|
|
27
|
+
CACHE_CODE = Object.create(null);
|
|
28
|
+
CACHE_HASH = Object.create(null);
|
|
29
|
+
CACHE_PICOMATCH = Object.create(null);
|
|
30
|
+
CACHE_EXTERNAL = Object.create(null);
|
|
31
|
+
}
|
|
25
32
|
function deleteTransform(map, key, timeout) {
|
|
26
33
|
if (timeout) {
|
|
27
34
|
clearTimeout(timeout);
|
|
28
35
|
}
|
|
29
|
-
delete
|
|
36
|
+
map.delete(key);
|
|
30
37
|
--CACHE_TOTAL;
|
|
31
38
|
}
|
|
32
39
|
function getSourceMappingURL(value, css) {
|
|
@@ -83,13 +90,13 @@ class TransformCache {
|
|
|
83
90
|
return data;
|
|
84
91
|
}
|
|
85
92
|
get(stored) {
|
|
86
|
-
const location = stored.format
|
|
93
|
+
const location = stored.format.get(this.formatKey);
|
|
87
94
|
if (typeof location === 'string') {
|
|
88
95
|
try {
|
|
89
96
|
return JSON.parse(fs.readFileSync(location, this.encoding));
|
|
90
97
|
}
|
|
91
98
|
catch {
|
|
92
|
-
|
|
99
|
+
stored.format.delete(this.formatKey);
|
|
93
100
|
fs.unlink(location, () => { });
|
|
94
101
|
return;
|
|
95
102
|
}
|
|
@@ -99,46 +106,48 @@ class TransformCache {
|
|
|
99
106
|
save(type, code, formatData) {
|
|
100
107
|
const lastAccessed = Date.now();
|
|
101
108
|
const config = this.config;
|
|
109
|
+
const create = () => new Map([[this.formatKey, this.set(type, formatData)]]);
|
|
110
|
+
const update = (stored) => {
|
|
111
|
+
stored.format.set(this.formatKey, this.set(type, formatData));
|
|
112
|
+
stored.lastAccessed = lastAccessed;
|
|
113
|
+
};
|
|
102
114
|
if (this.formatType === 1) {
|
|
103
115
|
const { uri, etag } = this.cacheData;
|
|
104
116
|
const etagMap = CACHE_ETAG[config.moduleName];
|
|
105
|
-
const stored = etagMap
|
|
117
|
+
const stored = etagMap.get(uri);
|
|
106
118
|
if (stored) {
|
|
107
|
-
if (stored.
|
|
108
|
-
stored
|
|
109
|
-
stored.lastAccessed = lastAccessed;
|
|
119
|
+
if (stored.hashKey === etag) {
|
|
120
|
+
update(stored);
|
|
110
121
|
return;
|
|
111
122
|
}
|
|
112
123
|
deleteTransform(etagMap, uri, stored.timeout);
|
|
113
124
|
}
|
|
114
|
-
etagMap
|
|
125
|
+
etagMap.set(uri, { lastAccessed, timeout: config.renewSession(etagMap, uri), format: create(), hashKey: etag });
|
|
115
126
|
++CACHE_TOTAL;
|
|
116
127
|
}
|
|
117
128
|
else if (this.formatType === 2) {
|
|
118
129
|
const hashMap = CACHE_HASH[config.moduleName];
|
|
119
130
|
const key = this.hashKey;
|
|
120
|
-
const stored = hashMap
|
|
131
|
+
const stored = hashMap.get(key);
|
|
121
132
|
if (stored) {
|
|
122
|
-
stored
|
|
123
|
-
stored.lastAccessed = lastAccessed;
|
|
133
|
+
update(stored);
|
|
124
134
|
return;
|
|
125
135
|
}
|
|
126
|
-
hashMap
|
|
136
|
+
hashMap.set(key, { lastAccessed, timeout: config.renewSession(hashMap, key), format: create() });
|
|
127
137
|
++CACHE_TOTAL;
|
|
128
138
|
}
|
|
129
139
|
else {
|
|
130
140
|
const uri = this.cacheData.uri;
|
|
131
141
|
const codeMap = CACHE_CODE[config.moduleName];
|
|
132
|
-
const stored = codeMap
|
|
142
|
+
const stored = codeMap.get(uri);
|
|
133
143
|
if (stored) {
|
|
134
|
-
if (stored.
|
|
135
|
-
stored
|
|
136
|
-
stored.lastAccessed = lastAccessed;
|
|
144
|
+
if (stored.hashKey === code) {
|
|
145
|
+
update(stored);
|
|
137
146
|
return;
|
|
138
147
|
}
|
|
139
148
|
deleteTransform(codeMap, uri, stored.timeout);
|
|
140
149
|
}
|
|
141
|
-
codeMap
|
|
150
|
+
codeMap.set(uri, { lastAccessed, timeout: config.renewSession(codeMap, uri), format: create(), hashKey: code });
|
|
142
151
|
++CACHE_TOTAL;
|
|
143
152
|
}
|
|
144
153
|
}
|
|
@@ -174,7 +183,7 @@ class TransformConfig {
|
|
|
174
183
|
algorithm = options;
|
|
175
184
|
enabled = true;
|
|
176
185
|
}
|
|
177
|
-
else if ((0, types_1.
|
|
186
|
+
else if ((0, types_1.isObject)(options)) {
|
|
178
187
|
({ enabled = true, algorithm, etag, expires, renew, limit, include, exclude } = options);
|
|
179
188
|
}
|
|
180
189
|
if (!enabled) {
|
|
@@ -268,19 +277,17 @@ class TransformConfig {
|
|
|
268
277
|
}
|
|
269
278
|
renewSession(map, key) {
|
|
270
279
|
if (this.expires > 0) {
|
|
271
|
-
return setTimeout(() =>
|
|
272
|
-
deleteTransform(map, key);
|
|
273
|
-
}, this.expires);
|
|
280
|
+
return setTimeout(() => deleteTransform(map, key), this.expires);
|
|
274
281
|
}
|
|
275
282
|
return null;
|
|
276
283
|
}
|
|
277
284
|
useETag(cache, etag, uri) {
|
|
278
|
-
const etagMap = CACHE_ETAG[this.moduleName] ||=
|
|
279
|
-
const stored = etagMap
|
|
285
|
+
const etagMap = CACHE_ETAG[this.moduleName] ||= new Map();
|
|
286
|
+
const stored = etagMap.get(uri);
|
|
280
287
|
cache.formatType = 1;
|
|
281
288
|
if (stored) {
|
|
282
289
|
let result;
|
|
283
|
-
if (stored.
|
|
290
|
+
if (stored.hashKey !== etag) {
|
|
284
291
|
deleteTransform(etagMap, uri, stored.timeout);
|
|
285
292
|
}
|
|
286
293
|
else if (result = cache.get(stored)) {
|
|
@@ -293,8 +300,8 @@ class TransformConfig {
|
|
|
293
300
|
useHash(cache, code) {
|
|
294
301
|
let key;
|
|
295
302
|
if (this.withinLimit(code, cache.encoding) && (key = core_1.Client.asHash(code, this.algorithm, { encoding: cache.encoding }))) {
|
|
296
|
-
const hashMap = CACHE_HASH[this.moduleName] ||=
|
|
297
|
-
const stored = hashMap
|
|
303
|
+
const hashMap = CACHE_HASH[this.moduleName] ||= new Map();
|
|
304
|
+
const stored = hashMap.get(key);
|
|
298
305
|
let result;
|
|
299
306
|
cache.formatType ||= 2;
|
|
300
307
|
cache.hashKey = key;
|
|
@@ -307,12 +314,12 @@ class TransformConfig {
|
|
|
307
314
|
}
|
|
308
315
|
useUri(cache, code, uri) {
|
|
309
316
|
if (this.withinLimit(code, cache.encoding)) {
|
|
310
|
-
const codeMap = CACHE_CODE[this.moduleName] ||=
|
|
311
|
-
const stored = codeMap
|
|
317
|
+
const codeMap = CACHE_CODE[this.moduleName] ||= new Map();
|
|
318
|
+
const stored = codeMap.get(uri);
|
|
312
319
|
cache.formatType ||= 3;
|
|
313
320
|
if (stored) {
|
|
314
321
|
let result;
|
|
315
|
-
if (stored.
|
|
322
|
+
if (stored.hashKey !== code) {
|
|
316
323
|
deleteTransform(codeMap, uri, stored.timeout);
|
|
317
324
|
}
|
|
318
325
|
else if (result = cache.get(stored)) {
|
|
@@ -339,20 +346,19 @@ class Document extends core_1.Client {
|
|
|
339
346
|
for (const cache of [CACHE_ETAG, CACHE_CODE, CACHE_HASH]) {
|
|
340
347
|
for (const name in cache) {
|
|
341
348
|
const map = cache[name];
|
|
342
|
-
for (const key
|
|
343
|
-
deleteTransform(map, key,
|
|
349
|
+
for (const [key, data] of map) {
|
|
350
|
+
deleteTransform(map, key, data.timeout);
|
|
344
351
|
++result;
|
|
345
352
|
}
|
|
346
|
-
delete cache[name];
|
|
347
353
|
}
|
|
348
354
|
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
}
|
|
355
|
+
initCache();
|
|
356
|
+
for (const item of CACHE_TEMPLATE.values()) {
|
|
357
|
+
item.clear();
|
|
353
358
|
}
|
|
359
|
+
CACHE_PACKAGE.clear();
|
|
360
|
+
CACHE_TEMPLATE.clear();
|
|
354
361
|
CACHE_VIEWENGINE.clear();
|
|
355
|
-
CACHE_PICOMATCH.clear();
|
|
356
362
|
CACHE_TOTAL = 0;
|
|
357
363
|
}
|
|
358
364
|
else if (percent > 0) {
|
|
@@ -360,16 +366,16 @@ class Document extends core_1.Client {
|
|
|
360
366
|
for (const cache of [CACHE_ETAG, CACHE_CODE, CACHE_HASH]) {
|
|
361
367
|
for (const name in cache) {
|
|
362
368
|
const map = cache[name];
|
|
363
|
-
for (const key
|
|
364
|
-
stored.push([map, key]);
|
|
369
|
+
for (const [key, data] of map) {
|
|
370
|
+
stored.push([map, key, data]);
|
|
365
371
|
}
|
|
366
372
|
}
|
|
367
373
|
}
|
|
368
|
-
stored.sort((
|
|
374
|
+
stored.sort((a, b) => a[2].lastAccessed - b[2].lastAccessed);
|
|
369
375
|
result = Math.floor(stored.length * percent);
|
|
370
376
|
for (let i = 0; i < result; ++i) {
|
|
371
|
-
const [map, key] = stored[i];
|
|
372
|
-
deleteTransform(map, key,
|
|
377
|
+
const [map, key, data] = stored[i];
|
|
378
|
+
deleteTransform(map, key, data.timeout);
|
|
373
379
|
}
|
|
374
380
|
CACHE_TOTAL = stored.length - result;
|
|
375
381
|
}
|
|
@@ -645,10 +651,7 @@ class Document extends core_1.Client {
|
|
|
645
651
|
items.push(item);
|
|
646
652
|
}
|
|
647
653
|
else if ((0, types_1.hasGlob)(pattern)) {
|
|
648
|
-
|
|
649
|
-
if (!isMatch) {
|
|
650
|
-
CACHE_PICOMATCH.set(pattern, isMatch = pm(pattern, { matchBase: true }));
|
|
651
|
-
}
|
|
654
|
+
const isMatch = CACHE_PICOMATCH[pattern] ||= pm(pattern, { matchBase: true });
|
|
652
655
|
if (isMatch(baseUrl)) {
|
|
653
656
|
items.push(item);
|
|
654
657
|
}
|
|
@@ -1065,7 +1068,12 @@ class Document extends core_1.Client {
|
|
|
1065
1068
|
case 'xml':
|
|
1066
1069
|
return new (require('fast-xml-parser').XMLParser)(options).parse(source);
|
|
1067
1070
|
case 'toml':
|
|
1068
|
-
|
|
1071
|
+
try {
|
|
1072
|
+
return require('smol-toml').parse(source, options);
|
|
1073
|
+
}
|
|
1074
|
+
catch {
|
|
1075
|
+
return require('toml').parse(source);
|
|
1076
|
+
}
|
|
1069
1077
|
default:
|
|
1070
1078
|
return JSON.parse(source);
|
|
1071
1079
|
}
|
|
@@ -1138,15 +1146,19 @@ class Document extends core_1.Client {
|
|
|
1138
1146
|
(0, types_1.coerceObject)(output, stored);
|
|
1139
1147
|
}
|
|
1140
1148
|
}
|
|
1149
|
+
let cache = CACHE_TEMPLATE.get(target.name);
|
|
1150
|
+
if (!cache) {
|
|
1151
|
+
cache = new Map();
|
|
1152
|
+
CACHE_TEMPLATE.set(target.name, cache);
|
|
1153
|
+
}
|
|
1141
1154
|
const username = this.host?.username || '';
|
|
1142
|
-
const cache = CACHE_TEMPLATE[target.name] ||= {};
|
|
1143
1155
|
const cacheKey = (username ? username + ':' : '') + (0, types_1.hashKey)(template + (compile ? core_1.Client.asString(compile) : ''));
|
|
1144
1156
|
let result = '', valid = false, expires = typeof target.expires === 'string' ? (0, types_1.parseExpires)(target.expires) : target.expires, render;
|
|
1145
1157
|
if (expires !== 0) {
|
|
1146
|
-
render = cache
|
|
1158
|
+
render = cache.get(cacheKey);
|
|
1147
1159
|
}
|
|
1148
|
-
else if (username && cacheKey
|
|
1149
|
-
delete
|
|
1160
|
+
else if (username && cache.has(cacheKey)) {
|
|
1161
|
+
cache.delete(cacheKey);
|
|
1150
1162
|
}
|
|
1151
1163
|
if (!render) {
|
|
1152
1164
|
if ((0, types_1.isArray)(compile)) {
|
|
@@ -1156,7 +1168,7 @@ class Document extends core_1.Client {
|
|
|
1156
1168
|
render = typeof context.compileSync === 'function' ? context.compileSync(template, compile) : await context.compile(template, compile);
|
|
1157
1169
|
}
|
|
1158
1170
|
if (expires !== 0) {
|
|
1159
|
-
cache
|
|
1171
|
+
cache.set(cacheKey, render);
|
|
1160
1172
|
if (this.hasPermission('memory')) {
|
|
1161
1173
|
expires = typeof expires === 'number' && expires !== Infinity ? Math.min(expires, core_1.Client.MAX_TIMEOUT) : 0;
|
|
1162
1174
|
}
|
|
@@ -1164,7 +1176,7 @@ class Document extends core_1.Client {
|
|
|
1164
1176
|
expires = 60000;
|
|
1165
1177
|
}
|
|
1166
1178
|
if (expires > 0) {
|
|
1167
|
-
setTimeout(() => delete
|
|
1179
|
+
setTimeout(() => cache.delete(cacheKey), expires);
|
|
1168
1180
|
}
|
|
1169
1181
|
}
|
|
1170
1182
|
}
|
|
@@ -1218,13 +1230,13 @@ class Document extends core_1.Client {
|
|
|
1218
1230
|
if (cacheData) {
|
|
1219
1231
|
const cacheDir = this.hasPermission('memory.user') || this.cacheDir || this.hasPermission('memory');
|
|
1220
1232
|
if (cacheDir && !CACHE_EXTERNAL[excludeKey = this.moduleName + '_' + type + '_' + format] && config.valid(type, format)) {
|
|
1221
|
-
const
|
|
1233
|
+
const uri = cacheData.uri;
|
|
1222
1234
|
const encoding = (0, types_1.getEncoding)(cacheData.encoding);
|
|
1223
1235
|
const hashOpts = core_1.Client.asString(options.external) + core_1.Client.asString(options.metadata);
|
|
1224
1236
|
cache = new TransformCache(config, cacheData, cacheDir, encoding, (username ? username + ':' : '') + type + '_' + format + '_' + encoding + (hashOpts ? '_' + (0, types_1.hashKey)(hashOpts) : ''));
|
|
1225
1237
|
let result, cacheName;
|
|
1226
|
-
if (config.etag && etag && uri) {
|
|
1227
|
-
[result, cacheName] = config.useETag(cache, etag, uri);
|
|
1238
|
+
if (config.etag && cacheData.etag && uri) {
|
|
1239
|
+
[result, cacheName] = config.useETag(cache, cacheData.etag, uri);
|
|
1228
1240
|
}
|
|
1229
1241
|
if (!result) {
|
|
1230
1242
|
if (config.algorithm) {
|
|
@@ -1235,14 +1247,12 @@ class Document extends core_1.Client {
|
|
|
1235
1247
|
}
|
|
1236
1248
|
}
|
|
1237
1249
|
if (result) {
|
|
1238
|
-
result.log?.forEach(log =>
|
|
1239
|
-
this.addLog(log);
|
|
1240
|
-
});
|
|
1250
|
+
result.log?.forEach(log => this.addLog(log));
|
|
1241
1251
|
this.formatMessage(4, type, [joinString(cacheName, format.filter(value => value).join(' | '), options.filename), 'cache'], uri, { ...core_1.Client.LOG_STYLE_NOTICE, hintBold: true });
|
|
1242
1252
|
return result;
|
|
1243
1253
|
}
|
|
1244
1254
|
}
|
|
1245
|
-
|
|
1255
|
+
options.cacheData = undefined;
|
|
1246
1256
|
}
|
|
1247
1257
|
const imports = transform.imports ||= {};
|
|
1248
1258
|
const series = new transform_1.TransformSeries(type, code, options);
|
|
@@ -1371,7 +1381,7 @@ class Document extends core_1.Client {
|
|
|
1371
1381
|
}
|
|
1372
1382
|
}
|
|
1373
1383
|
else {
|
|
1374
|
-
let transformer = CACHE_PACKAGE
|
|
1384
|
+
let transformer = CACHE_PACKAGE.get(target + username);
|
|
1375
1385
|
if (!transformer) {
|
|
1376
1386
|
try {
|
|
1377
1387
|
let pkg = this.resolveDir('package', plugin + '.js') || this.resolveDir('package', plugin + '.cjs') || this.resolveDir('package', plugin + '.mjs') || userImports?.[plugin] || imports[plugin] || types_1.IMPORT_MAP[plugin];
|
|
@@ -1408,7 +1418,7 @@ class Document extends core_1.Client {
|
|
|
1408
1418
|
throw (0, types_1.errorMessage)(plugin, "Invalid function", pkg || name);
|
|
1409
1419
|
}
|
|
1410
1420
|
if (pkg) {
|
|
1411
|
-
CACHE_PACKAGE
|
|
1421
|
+
CACHE_PACKAGE.set(target + username, transformer);
|
|
1412
1422
|
}
|
|
1413
1423
|
}
|
|
1414
1424
|
catch (err) {
|
|
@@ -1525,4 +1535,5 @@ class Document extends core_1.Client {
|
|
|
1525
1535
|
return this.assets.some(item => item.watch);
|
|
1526
1536
|
}
|
|
1527
1537
|
}
|
|
1538
|
+
initCache();
|
|
1528
1539
|
module.exports = Document;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/document",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.7",
|
|
4
4
|
"description": "Document constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
"license": "BSD-3-Clause",
|
|
20
20
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@e-mc/core": "0.13.
|
|
23
|
-
"@e-mc/db": "0.13.
|
|
24
|
-
"@e-mc/types": "0.13.
|
|
22
|
+
"@e-mc/core": "0.13.7",
|
|
23
|
+
"@e-mc/db": "0.13.7",
|
|
24
|
+
"@e-mc/types": "0.13.7",
|
|
25
25
|
"chalk": "4.1.2",
|
|
26
26
|
"domhandler": "^5.0.3",
|
|
27
27
|
"domutils": "^3.2.2",
|
package/parse/dom.js
CHANGED
|
@@ -35,8 +35,7 @@ class DomWriter extends index_1.XmlWriter {
|
|
|
35
35
|
if (start.startsWith('<')) {
|
|
36
36
|
tagGroup.push(new RegExp('^' + (0, types_1.escapePattern)(start)));
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
if (end?.[end.length - 1] === '>') {
|
|
38
|
+
if (ignoreTagGroup[i + 1]?.at(-1) === '>') {
|
|
40
39
|
tagGroup.push(new RegExp((0, types_1.escapePattern)(start) + '$'));
|
|
41
40
|
}
|
|
42
41
|
}
|
|
@@ -170,9 +169,9 @@ class DomWriter extends index_1.XmlWriter {
|
|
|
170
169
|
const textContent = trailing.reduce((a, b) => a + b.textContent, '');
|
|
171
170
|
offsetMap = index_1.XmlWriter.getTagOffset(textContent, { ignoreCase: this.ignoreCaseTagName, ignoreTagName: this.ignoreTagName, parser: this.parser });
|
|
172
171
|
source = source.substring(0, match.index) + textContent + source.substring(match.index);
|
|
173
|
-
|
|
172
|
+
for (const item of trailing) {
|
|
174
173
|
delete item.textContent;
|
|
175
|
-
}
|
|
174
|
+
}
|
|
176
175
|
}
|
|
177
176
|
}
|
|
178
177
|
}
|
package/parse/index.js
CHANGED
|
@@ -499,9 +499,9 @@ class XmlWriter {
|
|
|
499
499
|
}
|
|
500
500
|
}
|
|
501
501
|
ignoreFlag(...values) {
|
|
502
|
-
|
|
502
|
+
for (const value of values) {
|
|
503
503
|
this._ignoreFlag |= value;
|
|
504
|
-
}
|
|
504
|
+
}
|
|
505
505
|
}
|
|
506
506
|
getInvalidArea() {
|
|
507
507
|
if ((this._ignoreFlag & IGNORE_FLAG.INTERIOR) === 0 && this._hasInvalidContent) {
|
|
@@ -820,9 +820,9 @@ class XmlWriter {
|
|
|
820
820
|
const revised = this.decrement(node);
|
|
821
821
|
if (revised.includes(node)) {
|
|
822
822
|
if (tagName in this._tagCount) {
|
|
823
|
-
|
|
823
|
+
for (const item of revised) {
|
|
824
824
|
updateTagName(item, tagName);
|
|
825
|
-
}
|
|
825
|
+
}
|
|
826
826
|
this.indexTag(tagName);
|
|
827
827
|
this.increment(revised);
|
|
828
828
|
}
|
package/util.js
CHANGED
|
@@ -186,7 +186,7 @@ function splitEnclosing(value, pattern, options, opening = '(', closing = ')') {
|
|
|
186
186
|
function trimQuote(value) {
|
|
187
187
|
value = value.trim();
|
|
188
188
|
const first = value[0];
|
|
189
|
-
const last = value
|
|
189
|
+
const last = value.at(-1);
|
|
190
190
|
return first === last && (first === '"' || first === "'") ? value.substring(1, value.length - 1).trim() : value;
|
|
191
191
|
}
|
|
192
192
|
function wrapQuote(value, quote = '"') {
|