@e-mc/document 0.8.4 → 0.8.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 CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2023 An Pham
1
+ Copyright 2024 An Pham
2
2
 
3
3
  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
4
 
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/index.d.ts
12
+ - https://www.unpkg.com/@e-mc/types@0.8.6/lib/index.d.ts
13
13
 
14
14
  ```typescript
15
15
  import type { DataSource, ViewEngine } from "./squared";
@@ -85,14 +85,14 @@ interface DocumentConstructor extends ModuleConstructor {
85
85
 
86
86
  ## References
87
87
 
88
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/squared.d.ts
89
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/asset.d.ts
90
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/core.d.ts
91
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/document.d.ts
92
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/filemanager.d.ts
93
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/logger.d.ts
94
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/settings.d.ts
95
- - https://www.unpkg.com/@e-mc/types@0.8.4/lib/watch.d.ts
88
+ - https://www.unpkg.com/@e-mc/types@0.8.6/lib/squared.d.ts
89
+ - https://www.unpkg.com/@e-mc/types@0.8.6/lib/asset.d.ts
90
+ - https://www.unpkg.com/@e-mc/types@0.8.6/lib/core.d.ts
91
+ - https://www.unpkg.com/@e-mc/types@0.8.6/lib/document.d.ts
92
+ - https://www.unpkg.com/@e-mc/types@0.8.6/lib/filemanager.d.ts
93
+ - https://www.unpkg.com/@e-mc/types@0.8.6/lib/logger.d.ts
94
+ - https://www.unpkg.com/@e-mc/types@0.8.6/lib/settings.d.ts
95
+ - https://www.unpkg.com/@e-mc/types@0.8.6/lib/watch.d.ts
96
96
 
97
97
  ## LICENSE
98
98
 
package/index.js CHANGED
@@ -5,12 +5,12 @@ const fs = require("fs");
5
5
  const pm = require("picomatch");
6
6
  const yaml = require("js-yaml");
7
7
  const chalk = require("chalk");
8
- const types_1 = require("../types");
9
- const core_1 = require("../core");
10
- const db_1 = require("../db");
11
- const util_1 = require("./util");
12
- const transform_1 = require("./transform");
13
- const parse_1 = require("./parse");
8
+ const types_1 = require("@e-mc/types");
9
+ const core_1 = require("@e-mc/core");
10
+ const db_1 = require("@e-mc/db");
11
+ const util_1 = require("@e-mc/document/util");
12
+ const transform_1 = require("@e-mc/document/transform");
13
+ const parse_1 = require("@e-mc/document/parse");
14
14
  const PLATFORM_WIN32 = process.platform === 'win32';
15
15
  const CACHE_PACKAGE = {};
16
16
  const CACHE_REQUIRE = {};
@@ -95,17 +95,16 @@ class Document extends core_1.Client {
95
95
  }
96
96
  try {
97
97
  const args = [instance];
98
- // @ts-ignore
99
- if (ext["__cjs__" /* INTERNAL.CJS */]) {
98
+ if (ext["__cjs__"]) {
100
99
  args.push(__dirname);
101
100
  }
102
- else if (core_1.Client.enabled("node.require.inline" /* KEY_NAME.NODE_REQUIRE_INLINE */)) {
101
+ else if (core_1.Client.enabled("node.require.inline")) {
103
102
  args.push(require);
104
103
  }
105
104
  await ext.apply(this, args);
106
105
  }
107
106
  catch (err) {
108
- instance.writeFail(["Unknown" /* ERR_MESSAGE.UNKNOWN */, this.moduleName], err);
107
+ instance.writeFail(["Unknown", this.moduleName], err);
109
108
  }
110
109
  }
111
110
  }
@@ -127,7 +126,7 @@ class Document extends core_1.Client {
127
126
  map.sources = [""];
128
127
  }
129
128
  try {
130
- let css = mimeType === 'text/css', flags = 0 /* SOURCEMAP.NONE */;
129
+ let css = mimeType === 'text/css', flags = 0;
131
130
  const output = JSON.stringify(map);
132
131
  const toBase64 = () => 'data:application/json;base64,' + Buffer.from(output).toString('base64');
133
132
  if (!inlineMap) {
@@ -148,24 +147,24 @@ class Document extends core_1.Client {
148
147
  }
149
148
  }
150
149
  let code = data.code.replace(transform_1.SourceMap.RE_SOURCE_MAPPING_URL, (...capture) => {
151
- flags |= 1 /* SOURCEMAP.FOUND */;
150
+ flags |= 1;
152
151
  if (capture[2] && capture[5]) {
153
152
  css = true;
154
153
  }
155
154
  if (inlineMap || capture[3]) {
156
- flags |= 2 /* SOURCEMAP.INLINE */;
155
+ flags |= 2;
157
156
  return getSourceMappingURL(toBase64(), css);
158
157
  }
159
158
  return capture[1] || css ? getSourceMappingURL(sourceMappingURL, css) : capture[0];
160
159
  });
161
- if (inlineMap || flags & 2 /* SOURCEMAP.INLINE */) {
162
- if (flags === 0 /* SOURCEMAP.NONE */) {
160
+ if (inlineMap || flags & 2) {
161
+ if (flags === 0) {
163
162
  code += getSourceMappingURL(toBase64(), css);
164
163
  }
165
164
  data.code = code;
166
165
  }
167
166
  else {
168
- if (flags === 0 /* SOURCEMAP.NONE */) {
167
+ if (flags === 0) {
169
168
  code += getSourceMappingURL(sourceMappingURL, css);
170
169
  }
171
170
  const result = path.join(path.dirname(uri), sourceMappingURL);
@@ -276,7 +275,7 @@ class Document extends core_1.Client {
276
275
  for (const { severity, line, column, ruleId, message, fatal } of messages) {
277
276
  let error;
278
277
  if (severity) {
279
- if (error = severity === 2 /* LINT_SEVERITY.ERROR */ || severity === "error" /* LINT_SEVERITY.ERROR_TEXT */) {
278
+ if (error = severity === 2 || severity === "error") {
280
279
  ++errorCount;
281
280
  }
282
281
  else {
@@ -349,20 +348,18 @@ class Document extends core_1.Client {
349
348
  for (const pattern in pages) {
350
349
  const item = pages[pattern];
351
350
  if ((0, types_1.isPlainObject)(item)) {
352
- let isMatch;
353
- if (!(isMatch = CACHE_PICOMATCH.get(pattern)) && (0, types_1.hasGlob)(pattern)) {
354
- isMatch = pm(pattern, { matchBase: true });
355
- CACHE_PICOMATCH.set(pattern, isMatch);
356
- }
357
- else {
358
- continue;
359
- }
360
- if (isMatch(baseUrl)) {
351
+ if (pattern === baseUrl) {
361
352
  items.push(item);
362
353
  }
363
- }
364
- else {
365
- delete pages[pattern];
354
+ else if ((0, types_1.hasGlob)(pattern)) {
355
+ let isMatch = CACHE_PICOMATCH.get(pattern);
356
+ if (!isMatch) {
357
+ CACHE_PICOMATCH.set(pattern, isMatch = pm(pattern, { matchBase: true }));
358
+ }
359
+ if (isMatch(baseUrl)) {
360
+ items.push(item);
361
+ }
362
+ }
366
363
  }
367
364
  }
368
365
  if (items.length > 1) {
@@ -391,19 +388,18 @@ class Document extends core_1.Client {
391
388
  const handler = db.handler;
392
389
  const database = this.dataSource.filter(this.forDb.bind(this));
393
390
  let instance;
394
- if ((0, types_1.isString)(handler) && handler !== "@e-mc/db" /* PACKAGE_NAME.DB */) {
391
+ if ((0, types_1.isString)(handler) && handler !== "@e-mc/db") {
395
392
  try {
396
393
  const Handler = require(handler);
397
394
  if (isFunction(Handler) && Handler.prototype instanceof core_1.ClientDb) {
398
- // @ts-ignore
399
395
  instance = new Handler(db, database);
400
396
  }
401
397
  else {
402
- throw (0, types_1.errorMessage)(this.moduleName, "Not a Db constructor" /* ERR_DB.CONSTRUCTOR */, handler);
398
+ throw (0, types_1.errorMessage)(this.moduleName, "Not a Db constructor", handler);
403
399
  }
404
400
  }
405
401
  catch (err) {
406
- this.checkPackage(err, handler, ["Unable to load handler" /* ERR_MESSAGE.LOAD_HANDLER */, this.moduleName], 65536 /* LOG_TYPE.DB */);
402
+ this.checkPackage(err, handler, ["Unable to load handler", this.moduleName], 65536);
407
403
  }
408
404
  }
409
405
  else {
@@ -580,7 +576,7 @@ class Document extends core_1.Client {
580
576
  return getObject(result, false);
581
577
  }
582
578
  else {
583
- warning(path.isAbsolute(value) ? "Unsupported access" /* ERR_MESSAGE.UNSUPPORTED_ACCESS */ + ` (${value})` : "Unknown" /* ERR_MESSAGE.UNKNOWN */);
579
+ warning(path.isAbsolute(value) ? "Unsupported access" + ` (${value})` : "Unknown");
584
580
  }
585
581
  break;
586
582
  }
@@ -623,7 +619,7 @@ class Document extends core_1.Client {
623
619
  result = CACHE_REQUIRE[pkgName];
624
620
  }
625
621
  if (!result) {
626
- if (!core_1.Client.enabled("node.require.npm" /* KEY_NAME.NODE_REQUIRE_NPM */)) {
622
+ if (!core_1.Client.enabled("node.require.npm")) {
627
623
  return null;
628
624
  }
629
625
  try {
@@ -632,11 +628,11 @@ class Document extends core_1.Client {
632
628
  CACHE_REQUIRE[pkgName] = result;
633
629
  }
634
630
  if (typeof result === 'function') {
635
- return Object.defineProperty(result, "__cjs__" /* INTERNAL.CJS */, { value: true });
631
+ return Object.defineProperty(result, "__cjs__", { value: true });
636
632
  }
637
633
  }
638
634
  catch (err) {
639
- this.checkPackage(err, pkgName, "Unknown" /* ERR_MESSAGE.UNKNOWN */);
635
+ this.checkPackage(err, pkgName, "Unknown");
640
636
  }
641
637
  if (!result) {
642
638
  return null;
@@ -655,13 +651,12 @@ class Document extends core_1.Client {
655
651
  catch {
656
652
  }
657
653
  }
658
- // @ts-ignore
659
- if ((0, types_1.isObject)(result) || typeof result === 'function' && (result["__cjs__" /* INTERNAL.CJS */] || this.hasEval('function'))) {
654
+ if ((0, types_1.isObject)(result) || typeof result === 'function' && (result["__cjs__"] || this.hasEval('function'))) {
660
655
  return result;
661
656
  }
662
657
  }
663
658
  catch (err) {
664
- this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, path.basename(value)], err, 8192 /* LOG_TYPE.PERMISSION */);
659
+ this.writeFail(["Unable to read file", path.basename(value)], err, 8192);
665
660
  }
666
661
  return null;
667
662
  }
@@ -811,7 +806,7 @@ class Document extends core_1.Client {
811
806
  }
812
807
  }
813
808
  catch (err) {
814
- this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, localUri && path.basename(localUri)], 32 /* LOG_TYPE.FILE */);
809
+ this.writeFail(["Unable to read file", localUri && path.basename(localUri)], 32);
815
810
  }
816
811
  }
817
812
  else if (bundleContent) {
@@ -867,7 +862,7 @@ class Document extends core_1.Client {
867
862
  catch (err) {
868
863
  const name = (0, util_1.getModuleName)(err);
869
864
  if (name) {
870
- this.checkPackage(err, (0, util_1.getModuleName)(err), "Unknown" /* ERR_MESSAGE.UNKNOWN */);
865
+ this.checkPackage(err, (0, util_1.getModuleName)(err), "Unknown");
871
866
  }
872
867
  throw err;
873
868
  }
@@ -888,8 +883,7 @@ class Document extends core_1.Client {
888
883
  let target, stored;
889
884
  if (typeof viewEngine === 'string') {
890
885
  target = this.settings.view_engine?.[viewEngine];
891
- const username = this.host?.username;
892
- const userConfig = username && this.settings.users?.[username]?.view_engine?.[viewEngine];
886
+ const userConfig = this.getUserSettings()?.view_engine?.[viewEngine];
893
887
  if ((0, types_1.isPlainObject)(userConfig)) {
894
888
  if ((0, types_1.isPlainObject)(target)) {
895
889
  (0, types_1.cloneObject)(userConfig, { target, deep: true, preserve: true });
@@ -906,7 +900,7 @@ class Document extends core_1.Client {
906
900
  if (!((0, types_1.isPlainObject)(target) && target.name)) {
907
901
  this.abort('view_engine');
908
902
  const from = typeof viewEngine === 'string' ? viewEngine : this.moduleName;
909
- this.writeFail(["Unable to load configuration" /* ERR_MESSAGE.LOAD_CONFIG */, from], (0, types_1.errorMessage)('view-engine', from, "Unknown" /* ERR_MESSAGE.UNKNOWN */));
903
+ this.writeFail(["Unable to load configuration", from], (0, types_1.errorMessage)('view-engine', from, "Unknown"));
910
904
  return null;
911
905
  }
912
906
  const length = data.length;
@@ -934,10 +928,10 @@ class Document extends core_1.Client {
934
928
  const cacheKey = username + core_1.Client.asHash(template + (compile ? core_1.Client.asString(compile) : ''));
935
929
  let result = '', render, valid;
936
930
  if (!(render = cache[cacheKey])) {
937
- render = await context.compile(template, compile); // eslint-disable-line @typescript-eslint/await-thenable
931
+ render = await context.compile(template, compile);
938
932
  cache[cacheKey] = render;
939
- if (!core_1.Client.enabled("memory.settings.users" /* KEY_NAME.MEMORY_SETTINGS_USERS */, username)) {
940
- setTimeout(() => delete cache[cacheKey], 60000 /* VALUES.TEMPLATE_EXPIRES */);
933
+ if (!core_1.Client.enabled("memory.settings.users", username)) {
934
+ setTimeout(() => delete cache[cacheKey], 60000);
941
935
  }
942
936
  }
943
937
  for (let i = 0, j = 0, row; i < length; ++i) {
@@ -948,11 +942,11 @@ class Document extends core_1.Client {
948
942
  }
949
943
  }
950
944
  else if (!(0, types_1.isObject)(row)) {
951
- this.addLog(types_1.STATUS_TYPE.WARN, joinString(`view engine[${name}]`, `row #${i + 1}`, core_1.Client.asString(row) || "Unknown" /* ERR_MESSAGE.UNKNOWN */));
945
+ this.addLog(types_1.STATUS_TYPE.WARN, joinString(`view engine[${name}]`, `row #${i + 1}`, core_1.Client.asString(row) || "Unknown"));
952
946
  continue;
953
947
  }
954
948
  if (!singleRow) {
955
- const content = await render.call(context, row); // eslint-disable-line @typescript-eslint/await-thenable
949
+ const content = await render.call(context, row);
956
950
  if (content !== undefined && content !== null) {
957
951
  result += content;
958
952
  valid = true;
@@ -963,7 +957,7 @@ class Document extends core_1.Client {
963
957
  }
964
958
  catch (err) {
965
959
  this.abort('view_engine');
966
- this.checkPackage(err, name, "Unknown" /* ERR_MESSAGE.UNKNOWN */, 4 /* LOG_TYPE.PROCESS */);
960
+ this.checkPackage(err, name, "Unknown", 4);
967
961
  }
968
962
  return null;
969
963
  }
@@ -977,7 +971,7 @@ class Document extends core_1.Client {
977
971
  const username = this.host?.username || '';
978
972
  const config = this._transformConfig;
979
973
  const cacheData = config && options.cacheData;
980
- const cacheType = username && core_1.Client.enabled("memory.settings.users" /* KEY_NAME.MEMORY_SETTINGS_USERS */, username) ? true : this.cacheDir || core_1.Client.enabled("memory.settings.users" /* KEY_NAME.MEMORY_SETTINGS_USERS */);
974
+ const cacheType = username && core_1.Client.enabled("memory.settings.users", username) ? true : this.cacheDir || core_1.Client.enabled("memory.settings.users");
981
975
  let formatKey, hashKey, excludeKey;
982
976
  if (cacheData && cacheType && !CACHE_EXTERNAL[excludeKey = moduleName + '_' + type + '_' + format] && (!config.exclude[type] || Array.isArray(config.exclude[type]) && !format.some(value => config.exclude[type].includes(value)) || Array.isArray(config.include[type]) && format.every(value => config.include[type].includes(value)))) {
983
977
  const { uri, etag } = cacheData;
@@ -1053,7 +1047,7 @@ class Document extends core_1.Client {
1053
1047
  }
1054
1048
  if (result) {
1055
1049
  result.storedLog?.forEach(log => this.addLog(log));
1056
- this.formatMessage(4 /* LOG_TYPE.PROCESS */, type, [joinString(cacheName, format.filter(value => value).join(' | '), options.filename), 'cache'], uri, { ...core_1.Client.LOG_STYLE_NOTICE, hintBold: true });
1050
+ this.formatMessage(4, type, [joinString(cacheName, format.filter(value => value).join(' | '), options.filename), 'cache'], uri, { ...core_1.Client.LOG_STYLE_NOTICE, hintBold: true });
1057
1051
  return result;
1058
1052
  }
1059
1053
  }
@@ -1131,7 +1125,7 @@ class Document extends core_1.Client {
1131
1125
  if (typeof value !== 'string' || (0, types_1.isArray)(out.sourceFiles) && this.hasOwnPermission() && out.sourceFiles.some(item => !this.canRead(item, { ownPermissionOnly: true }))) {
1132
1126
  failed = true;
1133
1127
  ignoreCache = true;
1134
- this.writeFail(["Unable to transform document" /* ERR_MESSAGE.TRANSFORM_DOCUMENT */, plugin], (0, types_1.errorMessage)(plugin, name, typeof value === 'string' ? "Unsupported access" /* ERR_MESSAGE.UNSUPPORTED_ACCESS */ : 'Empty'), { type: 4 /* LOG_TYPE.PROCESS */, startTime });
1128
+ this.writeFail(["Unable to transform document", plugin], (0, types_1.errorMessage)(plugin, name, typeof value === 'string' ? "Unsupported access" : 'Empty'), { type: 4, startTime });
1135
1129
  }
1136
1130
  else if (source !== value) {
1137
1131
  series.code = value;
@@ -1163,19 +1157,18 @@ class Document extends core_1.Client {
1163
1157
  }
1164
1158
  this.writeTimeProcess(failed ? 'CHECK' : type, joinString(hint, options.filename) + (series.out.messageAppend || ''), startTime, { failed, bypassLog });
1165
1159
  };
1166
- this.formatMessage(4 /* LOG_TYPE.PROCESS */, type, ['Transforming source...', hint], options.filename, { hintColor: 'cyan' });
1160
+ this.formatMessage(4, type, ['Transforming source...', hint], options.filename, { hintColor: 'cyan' });
1167
1161
  try {
1168
1162
  let context = require(plugin);
1169
1163
  series.packageName = plugin;
1170
1164
  if (typeof baseConfig === 'function') {
1171
1165
  series.baseConfig = outputConfig;
1172
- // @ts-ignore
1173
- if (baseConfig["__cjs__" /* INTERNAL.CJS */]) {
1166
+ if (baseConfig["__cjs__"]) {
1174
1167
  next(await baseConfig(context, source, series));
1175
1168
  }
1176
1169
  else {
1177
- const thisArg = core_1.Client.enabled("node.process.inline" /* KEY_NAME.NODE_PROCESS_INLINE */) ? process : null;
1178
- const inline = core_1.Client.enabled("node.require.inline" /* KEY_NAME.NODE_REQUIRE_INLINE */);
1170
+ const thisArg = core_1.Client.enabled("node.process.inline") ? process : null;
1171
+ const inline = core_1.Client.enabled("node.require.inline");
1179
1172
  const args = [context, source, series];
1180
1173
  if (baseConfig.toString().startsWith('async')) {
1181
1174
  if (inline) {
@@ -1209,7 +1202,7 @@ class Document extends core_1.Client {
1209
1202
  }
1210
1203
  else {
1211
1204
  transformer = context;
1212
- context = this; // eslint-disable-line @typescript-eslint/no-this-alias
1205
+ context = this;
1213
1206
  pkg = undefined;
1214
1207
  }
1215
1208
  if (transformer && typeof transformer !== 'function') {
@@ -1224,7 +1217,7 @@ class Document extends core_1.Client {
1224
1217
  }
1225
1218
  catch (err) {
1226
1219
  abort();
1227
- this.writeFail(["Unknown" /* ERR_MESSAGE.UNKNOWN */, username ? plugin + ':' + username : hint], err, { type: 4 /* LOG_TYPE.PROCESS */, startTime });
1220
+ this.writeFail(["Unknown", username ? plugin + ':' + username : hint], err, { type: 4, startTime });
1228
1221
  continue;
1229
1222
  }
1230
1223
  }
@@ -1234,7 +1227,7 @@ class Document extends core_1.Client {
1234
1227
  }
1235
1228
  catch (err) {
1236
1229
  abort();
1237
- this.checkPackage(err, (0, util_1.getModuleName)(err), ["Unable to transform document" /* ERR_MESSAGE.TRANSFORM_DOCUMENT */, hint], { type: 4 /* LOG_TYPE.PROCESS */, startTime });
1230
+ this.checkPackage(err, (0, util_1.getModuleName)(err), ["Unable to transform document", hint], { type: 4, startTime });
1238
1231
  if (i < length - 1) {
1239
1232
  series.reset();
1240
1233
  }
@@ -1243,10 +1236,10 @@ class Document extends core_1.Client {
1243
1236
  else {
1244
1237
  abort();
1245
1238
  if (plugin) {
1246
- this.writeFail("Unable to load configuration" /* ERR_MESSAGE.LOAD_CONFIG */, (0, types_1.errorMessage)(plugin, name, 'Invalid config'), 4 /* LOG_TYPE.PROCESS */);
1239
+ this.writeFail("Unable to load configuration", (0, types_1.errorMessage)(plugin, name, 'Invalid config'), 4);
1247
1240
  }
1248
1241
  else {
1249
- this.writeFail('Format method was not found', (0, types_1.errorValue)(name, "Unknown" /* ERR_MESSAGE.UNKNOWN */), 4 /* LOG_TYPE.PROCESS */);
1242
+ this.writeFail('Format method was not found', (0, types_1.errorValue)(name, "Unknown"), 4);
1250
1243
  }
1251
1244
  }
1252
1245
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/document",
3
- "version": "0.8.4",
3
+ "version": "0.8.6",
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": "BSD 3-Clause",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/core": "0.8.4",
24
- "@e-mc/db": "0.8.4",
25
- "@e-mc/types": "0.8.4",
23
+ "@e-mc/core": "0.8.6",
24
+ "@e-mc/db": "0.8.6",
25
+ "@e-mc/types": "0.8.6",
26
26
  "chalk": "4.1.2",
27
27
  "htmlparser2": "^9.1.0",
28
28
  "js-yaml": "^4.1.0",
package/parse/dom.js CHANGED
@@ -4,9 +4,9 @@ exports.IGNORE_FLAG = exports.HtmlElement = exports.DomWriter = void 0;
4
4
  const htmlparser2 = require("htmlparser2");
5
5
  const domhandler = require("domhandler");
6
6
  const domutils = require("domutils");
7
- const types_1 = require("../../types");
8
- const util_1 = require("../util");
9
- const index_1 = require("./index");
7
+ const types_1 = require("@e-mc/types");
8
+ const util_1 = require("@e-mc/document/util");
9
+ const index_1 = require("@e-mc/document/parse");
10
10
  Object.defineProperty(exports, "IGNORE_FLAG", { enumerable: true, get: function () { return index_1.IGNORE_FLAG; } });
11
11
  const Parser = htmlparser2.Parser;
12
12
  const DomHandler = domhandler.DomHandler;
@@ -89,7 +89,7 @@ class DomWriter extends index_1.XmlWriter {
89
89
  const result = { element: null, error: null };
90
90
  new Parser(new DomHandler((err, dom) => {
91
91
  if (!err) {
92
- result.element = domutils.findOne(elem => elem.tagName === "html" /* VALUES.ROOT */, dom);
92
+ result.element = domutils.findOne(elem => elem.tagName === "html", dom);
93
93
  }
94
94
  else {
95
95
  result.error = err;
@@ -111,8 +111,8 @@ class DomWriter extends index_1.XmlWriter {
111
111
  parser || (parser = { ...PARSER_OPTIONS });
112
112
  super(documentName, source, elements, { parser });
113
113
  this.documentElement = null;
114
- this.ignoreTagName = "title|style|script" /* VALUES.IGNORE_TAGNAME */;
115
- this.rootName = "html" /* VALUES.ROOT */;
114
+ this.ignoreTagName = "title|style|script";
115
+ this.rootName = "html";
116
116
  this.ignoreCaseTagName = true;
117
117
  const items = [];
118
118
  let outerXml = '', documentElement, offsetMap, startIndex = -1;
@@ -121,7 +121,7 @@ class DomWriter extends index_1.XmlWriter {
121
121
  item.tagName = item.tagName.toLowerCase();
122
122
  item.ignoreCase = true;
123
123
  }
124
- if (item.tagName === "html" /* VALUES.ROOT */) {
124
+ if (item.tagName === "html") {
125
125
  items.push(item);
126
126
  if (!documentElement && item.innerXml) {
127
127
  documentElement = item;
@@ -198,7 +198,7 @@ class DomWriter extends index_1.XmlWriter {
198
198
  if (this.modified && this.documentElement) {
199
199
  let innerXml;
200
200
  for (const item of this.elements) {
201
- if (item.tagName === "html" /* VALUES.ROOT */) {
201
+ if (item.tagName === "html") {
202
202
  if (!innerXml && index_1.XmlWriter.isIndex(item.endIndex)) {
203
203
  innerXml = this.source.substring(item.endIndex + 1, this.source.length - 7).trim();
204
204
  }
@@ -223,7 +223,7 @@ class HtmlElement extends index_1.XmlElement {
223
223
  constructor(documentName, node, attributes, options = {}) {
224
224
  options.parser || (options.parser = { ...PARSER_OPTIONS });
225
225
  super(documentName, node, attributes, { ...options, tagVoid: TAG_VOID.includes(node.tagName) });
226
- this._documentType = "HTML" /* VALUES.DOCUMENT_TYPE */;
226
+ this._documentType = "HTML";
227
227
  }
228
228
  getTagOffset(source) {
229
229
  switch (this.node.append?.tagName || this.tagName) {
@@ -233,7 +233,7 @@ class HtmlElement extends index_1.XmlElement {
233
233
  case 'script':
234
234
  return;
235
235
  default:
236
- return super.getTagOffset(source, { ignoreCase: this.ignoreCase, ignoreTagName: "title|style|script" /* VALUES.IGNORE_TAGNAME */, parser: this.parser });
236
+ return super.getTagOffset(source, { ignoreCase: this.ignoreCase, ignoreTagName: "title|style|script", parser: this.parser });
237
237
  }
238
238
  }
239
239
  findIndexOf(source) {
@@ -244,8 +244,8 @@ class HtmlElement extends index_1.XmlElement {
244
244
  }
245
245
  get outerXml() {
246
246
  const [tagName, items, innerXml] = this.getOuterContent();
247
- return '<' + tagName + HtmlElement.writeAttributes(items) + '>' + (DomWriter.hasInnerXml(tagName) && tagName !== "html" /* VALUES.ROOT */ ? (tagName === 'title' ? index_1.XmlWriter.escapeXmlString(innerXml) : innerXml) + `</${tagName}>` : '');
247
+ return '<' + tagName + HtmlElement.writeAttributes(items) + '>' + (DomWriter.hasInnerXml(tagName) && tagName !== "html" ? (tagName === 'title' ? index_1.XmlWriter.escapeXmlString(innerXml) : innerXml) + `</${tagName}>` : '');
248
248
  }
249
249
  }
250
250
  exports.HtmlElement = HtmlElement;
251
- index_1.XmlWriter.namesOfTagVoid("HTML" /* VALUES.DOCUMENT_TYPE */, TAG_VOID);
251
+ index_1.XmlWriter.namesOfTagVoid("HTML", TAG_VOID);
package/parse/index.js CHANGED
@@ -1,12 +1,11 @@
1
1
  "use strict";
2
- /* eslint @typescript-eslint/prefer-includes: off */
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
3
  exports.XmlElement = exports.XmlWriter = exports.IGNORE_FLAG = void 0;
5
4
  const htmlparser2 = require("htmlparser2");
6
5
  const domhandler = require("domhandler");
7
6
  const domutils = require("domutils");
8
- const types_1 = require("../../types");
9
- const module_1 = require("../../module");
7
+ const types_1 = require("@e-mc/types");
8
+ const module_1 = require("@e-mc/module");
10
9
  var IGNORE_FLAG;
11
10
  (function (IGNORE_FLAG) {
12
11
  IGNORE_FLAG[IGNORE_FLAG["NONE"] = 0] = "NONE";
@@ -3,8 +3,8 @@ var _a, _b, _c, _d;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.SourceMap = exports.TransformSeries = void 0;
5
5
  const path = require("path");
6
- const types_1 = require("../../types");
7
- const core_1 = require("../../core");
6
+ const types_1 = require("@e-mc/types");
7
+ const core_1 = require("@e-mc/core");
8
8
  const kCode = Symbol('code');
9
9
  const kMap = Symbol('map');
10
10
  const kOut = Symbol('out');
@@ -185,20 +185,16 @@ class TransformSeries extends core_1.Module {
185
185
  return this.options.external;
186
186
  }
187
187
  set version(value) {
188
- // @ts-ignore
189
188
  this.metadata.__version__ = value;
190
189
  }
191
190
  get version() {
192
- // @ts-ignore
193
191
  return this.metadata.__version__ || '';
194
192
  }
195
193
  set packageName(value) {
196
- // @ts-ignore
197
194
  this.metadata.__packagename__ = value;
198
195
  this.version = 'latest';
199
196
  }
200
197
  get packageName() {
201
- // @ts-ignore
202
198
  return this.metadata.__packagename__ || '';
203
199
  }
204
200
  get packageVersion() {
package/util.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isObject = exports.removeInternalProperties = exports.getModuleName = exports.hasValue = exports.getHashData = exports.getNewline = exports.getIndent = exports.appendSuffix = exports.splitEnclosing = exports.concatString = exports.replaceAll = exports.loadPlugins = exports.IMPORTS = void 0;
4
4
  const path = require("path");
5
- const types_1 = require("../types");
5
+ const types_1 = require("@e-mc/types");
6
6
  Object.defineProperty(exports, "isObject", { enumerable: true, get: function () { return types_1.isObject; } });
7
7
  exports.IMPORTS = {
8
8
  "@babel/core": "@pi-r/babel",
@@ -50,7 +50,7 @@ function replaceAll(source, valueOf, opening = '{{', closing = '}}') {
50
50
  exports.replaceAll = replaceAll;
51
51
  function concatString(values, newline) {
52
52
  if ((0, types_1.isArray)(values)) {
53
- newline || (newline = values.find(item => item.indexOf('\r') !== -1) ? '\r\n' : '\n'); // eslint-disable-line @typescript-eslint/prefer-includes
53
+ newline || (newline = values.find(item => item.indexOf('\r') !== -1) ? '\r\n' : '\n');
54
54
  return values.reduce((a, b) => a + newline + b, '');
55
55
  }
56
56
  return typeof values === 'string' ? values : '';