@nextcloud/files 3.2.1 → 3.3.1

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/dist/index.cjs CHANGED
@@ -1,6 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const _ = require("@nextcloud/auth"), K = require("@nextcloud/logger"), ge = require("@nextcloud/l10n"), y = require("path"), we = require("@nextcloud/paths"), me = require("@nextcloud/router"), W = require("webdav"), Ne = require("cancelable-promise");
3
+ const auth = require("@nextcloud/auth");
4
+ const logger$1 = require("@nextcloud/logger");
5
+ const l10n = require("@nextcloud/l10n");
6
+ const path = require("path");
7
+ const paths = require("@nextcloud/paths");
8
+ const router = require("@nextcloud/router");
9
+ const webdav = require("webdav");
10
+ const cancelablePromise = require("cancelable-promise");
4
11
  /**
5
12
  * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
6
13
  *
@@ -22,7 +29,13 @@ const _ = require("@nextcloud/auth"), K = require("@nextcloud/logger"), ge = req
22
29
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
23
30
  *
24
31
  */
25
- const Ee = (e) => e === null ? K.getLoggerBuilder().setApp("files").build() : K.getLoggerBuilder().setApp("files").setUid(e.uid).build(), N = Ee(_.getCurrentUser());
32
+ const getLogger = (user) => {
33
+ if (user === null) {
34
+ return logger$1.getLoggerBuilder().setApp("files").build();
35
+ }
36
+ return logger$1.getLoggerBuilder().setApp("files").setUid(user.uid).build();
37
+ };
38
+ const logger = getLogger(auth.getCurrentUser());
26
39
  /**
27
40
  * @copyright Copyright (c) 2021 John Molakvoæ <skjnldsv@protonmail.com>
28
41
  *
@@ -44,49 +57,71 @@ const Ee = (e) => e === null ? K.getLoggerBuilder().setApp("files").build() : K.
44
57
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
45
58
  *
46
59
  */
47
- class be {
60
+ var NewMenuEntryCategory = /* @__PURE__ */ ((NewMenuEntryCategory2) => {
61
+ NewMenuEntryCategory2[NewMenuEntryCategory2["UploadFromDevice"] = 0] = "UploadFromDevice";
62
+ NewMenuEntryCategory2[NewMenuEntryCategory2["CreateNew"] = 1] = "CreateNew";
63
+ NewMenuEntryCategory2[NewMenuEntryCategory2["Other"] = 2] = "Other";
64
+ return NewMenuEntryCategory2;
65
+ })(NewMenuEntryCategory || {});
66
+ class NewFileMenu {
48
67
  _entries = [];
49
- registerEntry(t) {
50
- this.validateEntry(t), this._entries.push(t);
51
- }
52
- unregisterEntry(t) {
53
- const r = typeof t == "string" ? this.getEntryIndex(t) : this.getEntryIndex(t.id);
54
- if (r === -1) {
55
- N.warn("Entry not found, nothing removed", { entry: t, entries: this.getEntries() });
68
+ registerEntry(entry) {
69
+ this.validateEntry(entry);
70
+ entry.category = entry.category ?? 1;
71
+ this._entries.push(entry);
72
+ }
73
+ unregisterEntry(entry) {
74
+ const entryIndex = typeof entry === "string" ? this.getEntryIndex(entry) : this.getEntryIndex(entry.id);
75
+ if (entryIndex === -1) {
76
+ logger.warn("Entry not found, nothing removed", { entry, entries: this.getEntries() });
56
77
  return;
57
78
  }
58
- this._entries.splice(r, 1);
79
+ this._entries.splice(entryIndex, 1);
59
80
  }
60
81
  /**
61
82
  * Get the list of registered entries
62
83
  *
63
84
  * @param {Folder} context the creation context. Usually the current folder
64
85
  */
65
- getEntries(t) {
66
- return t ? this._entries.filter((r) => typeof r.enabled == "function" ? r.enabled(t) : !0) : this._entries;
86
+ getEntries(context) {
87
+ if (context) {
88
+ return this._entries.filter((entry) => typeof entry.enabled === "function" ? entry.enabled(context) : true);
89
+ }
90
+ return this._entries;
67
91
  }
68
- getEntryIndex(t) {
69
- return this._entries.findIndex((r) => r.id === t);
92
+ getEntryIndex(id) {
93
+ return this._entries.findIndex((entry) => entry.id === id);
70
94
  }
71
- validateEntry(t) {
72
- if (!t.id || !t.displayName || !(t.iconSvgInline || t.iconClass) || !t.handler)
95
+ validateEntry(entry) {
96
+ if (!entry.id || !entry.displayName || !(entry.iconSvgInline || entry.iconClass) || !entry.handler) {
73
97
  throw new Error("Invalid entry");
74
- if (typeof t.id != "string" || typeof t.displayName != "string")
98
+ }
99
+ if (typeof entry.id !== "string" || typeof entry.displayName !== "string") {
75
100
  throw new Error("Invalid id or displayName property");
76
- if (t.iconClass && typeof t.iconClass != "string" || t.iconSvgInline && typeof t.iconSvgInline != "string")
101
+ }
102
+ if (entry.iconClass && typeof entry.iconClass !== "string" || entry.iconSvgInline && typeof entry.iconSvgInline !== "string") {
77
103
  throw new Error("Invalid icon provided");
78
- if (t.enabled !== void 0 && typeof t.enabled != "function")
104
+ }
105
+ if (entry.enabled !== void 0 && typeof entry.enabled !== "function") {
79
106
  throw new Error("Invalid enabled property");
80
- if (typeof t.handler != "function")
107
+ }
108
+ if (typeof entry.handler !== "function") {
81
109
  throw new Error("Invalid handler property");
82
- if ("order" in t && typeof t.order != "number")
110
+ }
111
+ if ("order" in entry && typeof entry.order !== "number") {
83
112
  throw new Error("Invalid order property");
84
- if (this.getEntryIndex(t.id) !== -1)
113
+ }
114
+ if (this.getEntryIndex(entry.id) !== -1) {
85
115
  throw new Error("Duplicate entry");
116
+ }
86
117
  }
87
118
  }
88
- const L = function() {
89
- return typeof window._nc_newfilemenu > "u" && (window._nc_newfilemenu = new be(), N.debug("NewFileMenu initialized")), window._nc_newfilemenu;
119
+ const getNewFileMenu = function() {
120
+ if (typeof window._nc_newfilemenu === "undefined") {
121
+ window._nc_newfilemenu = new NewFileMenu();
122
+ logger.debug("NewFileMenu initialized");
123
+ }
124
+ return window._nc_newfilemenu;
90
125
  };
91
126
  /**
92
127
  * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
@@ -110,25 +145,38 @@ const L = function() {
110
145
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
111
146
  *
112
147
  */
113
- const x = ["B", "KB", "MB", "GB", "TB", "PB"], $ = ["B", "KiB", "MiB", "GiB", "TiB", "PiB"];
114
- function ye(e, t = !1, r = !1, s = !1) {
115
- r = r && !s, typeof e == "string" && (e = Number(e));
116
- let n = e > 0 ? Math.floor(Math.log(e) / Math.log(s ? 1e3 : 1024)) : 0;
117
- n = Math.min((r ? $.length : x.length) - 1, n);
118
- const i = r ? $[n] : x[n];
119
- let a = (e / Math.pow(s ? 1e3 : 1024, n)).toFixed(1);
120
- return t === !0 && n === 0 ? (a !== "0.0" ? "< 1 " : "0 ") + (r ? $[1] : x[1]) : (n < 2 ? a = parseFloat(a).toFixed(0) : a = parseFloat(a).toLocaleString(ge.getCanonicalLocale()), a + " " + i);
121
- }
122
- function ve(e, t = !1) {
148
+ const humanList = ["B", "KB", "MB", "GB", "TB", "PB"];
149
+ const humanListBinary = ["B", "KiB", "MiB", "GiB", "TiB", "PiB"];
150
+ function formatFileSize(size, skipSmallSizes = false, binaryPrefixes = false, base1000 = false) {
151
+ binaryPrefixes = binaryPrefixes && !base1000;
152
+ if (typeof size === "string") {
153
+ size = Number(size);
154
+ }
155
+ let order = size > 0 ? Math.floor(Math.log(size) / Math.log(base1000 ? 1e3 : 1024)) : 0;
156
+ order = Math.min((binaryPrefixes ? humanListBinary.length : humanList.length) - 1, order);
157
+ const readableFormat = binaryPrefixes ? humanListBinary[order] : humanList[order];
158
+ let relativeSize = (size / Math.pow(base1000 ? 1e3 : 1024, order)).toFixed(1);
159
+ if (skipSmallSizes === true && order === 0) {
160
+ return (relativeSize !== "0.0" ? "< 1 " : "0 ") + (binaryPrefixes ? humanListBinary[1] : humanList[1]);
161
+ }
162
+ if (order < 2) {
163
+ relativeSize = parseFloat(relativeSize).toFixed(0);
164
+ } else {
165
+ relativeSize = parseFloat(relativeSize).toLocaleString(l10n.getCanonicalLocale());
166
+ }
167
+ return relativeSize + " " + readableFormat;
168
+ }
169
+ function parseFileSize(value, forceBinary = false) {
123
170
  try {
124
- e = `${e}`.toLocaleLowerCase().replaceAll(/\s+/g, "").replaceAll(",", ".");
125
- } catch {
171
+ value = `${value}`.toLocaleLowerCase().replaceAll(/\s+/g, "").replaceAll(",", ".");
172
+ } catch (e) {
126
173
  return null;
127
174
  }
128
- const r = e.match(/^([0-9]*(\.[0-9]*)?)([kmgtp]?)(i?)b?$/);
129
- if (r === null || r[1] === "." || r[1] === "")
175
+ const match = value.match(/^([0-9]*(\.[0-9]*)?)([kmgtp]?)(i?)b?$/);
176
+ if (match === null || match[1] === "." || match[1] === "") {
130
177
  return null;
131
- const s = {
178
+ }
179
+ const bytesArray = {
132
180
  "": 0,
133
181
  k: 1,
134
182
  m: 2,
@@ -136,8 +184,10 @@ function ve(e, t = !1) {
136
184
  t: 4,
137
185
  p: 5,
138
186
  e: 6
139
- }, n = `${r[1]}`, i = r[4] === "i" || t ? 1024 : 1e3;
140
- return Math.round(Number.parseFloat(n) * i ** s[r[3]]);
187
+ };
188
+ const decimalString = `${match[1]}`;
189
+ const base = match[4] === "i" || forceBinary ? 1024 : 1e3;
190
+ return Math.round(Number.parseFloat(decimalString) * base ** bytesArray[match[3]]);
141
191
  }
142
192
  /**
143
193
  * @copyright Copyright (c) 2023 John Molakvoæ <skjnldsv@protonmail.com>
@@ -160,11 +210,16 @@ function ve(e, t = !1) {
160
210
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
161
211
  *
162
212
  */
163
- var R = /* @__PURE__ */ ((e) => (e.DEFAULT = "default", e.HIDDEN = "hidden", e))(R || {});
164
- class _e {
213
+ var DefaultType = /* @__PURE__ */ ((DefaultType2) => {
214
+ DefaultType2["DEFAULT"] = "default";
215
+ DefaultType2["HIDDEN"] = "hidden";
216
+ return DefaultType2;
217
+ })(DefaultType || {});
218
+ class FileAction {
165
219
  _action;
166
- constructor(t) {
167
- this.validateAction(t), this._action = t;
220
+ constructor(action) {
221
+ this.validateAction(action);
222
+ this._action = action;
168
223
  }
169
224
  get id() {
170
225
  return this._action.id;
@@ -202,41 +257,62 @@ class _e {
202
257
  get renderInline() {
203
258
  return this._action.renderInline;
204
259
  }
205
- validateAction(t) {
206
- if (!t.id || typeof t.id != "string")
260
+ validateAction(action) {
261
+ if (!action.id || typeof action.id !== "string") {
207
262
  throw new Error("Invalid id");
208
- if (!t.displayName || typeof t.displayName != "function")
263
+ }
264
+ if (!action.displayName || typeof action.displayName !== "function") {
209
265
  throw new Error("Invalid displayName function");
210
- if ("title" in t && typeof t.title != "function")
266
+ }
267
+ if ("title" in action && typeof action.title !== "function") {
211
268
  throw new Error("Invalid title function");
212
- if (!t.iconSvgInline || typeof t.iconSvgInline != "function")
269
+ }
270
+ if (!action.iconSvgInline || typeof action.iconSvgInline !== "function") {
213
271
  throw new Error("Invalid iconSvgInline function");
214
- if (!t.exec || typeof t.exec != "function")
272
+ }
273
+ if (!action.exec || typeof action.exec !== "function") {
215
274
  throw new Error("Invalid exec function");
216
- if ("enabled" in t && typeof t.enabled != "function")
275
+ }
276
+ if ("enabled" in action && typeof action.enabled !== "function") {
217
277
  throw new Error("Invalid enabled function");
218
- if ("execBatch" in t && typeof t.execBatch != "function")
278
+ }
279
+ if ("execBatch" in action && typeof action.execBatch !== "function") {
219
280
  throw new Error("Invalid execBatch function");
220
- if ("order" in t && typeof t.order != "number")
281
+ }
282
+ if ("order" in action && typeof action.order !== "number") {
221
283
  throw new Error("Invalid order");
222
- if ("parent" in t && typeof t.parent != "string")
284
+ }
285
+ if ("parent" in action && typeof action.parent !== "string") {
223
286
  throw new Error("Invalid parent");
224
- if (t.default && !Object.values(R).includes(t.default))
287
+ }
288
+ if (action.default && !Object.values(DefaultType).includes(action.default)) {
225
289
  throw new Error("Invalid default");
226
- if ("inline" in t && typeof t.inline != "function")
290
+ }
291
+ if ("inline" in action && typeof action.inline !== "function") {
227
292
  throw new Error("Invalid inline function");
228
- if ("renderInline" in t && typeof t.renderInline != "function")
293
+ }
294
+ if ("renderInline" in action && typeof action.renderInline !== "function") {
229
295
  throw new Error("Invalid renderInline function");
296
+ }
230
297
  }
231
298
  }
232
- const Te = function(e) {
233
- if (typeof window._nc_fileactions > "u" && (window._nc_fileactions = [], N.debug("FileActions initialized")), window._nc_fileactions.find((t) => t.id === e.id)) {
234
- N.error(`FileAction ${e.id} already registered`, { action: e });
299
+ const registerFileAction = function(action) {
300
+ if (typeof window._nc_fileactions === "undefined") {
301
+ window._nc_fileactions = [];
302
+ logger.debug("FileActions initialized");
303
+ }
304
+ if (window._nc_fileactions.find((search) => search.id === action.id)) {
305
+ logger.error(`FileAction ${action.id} already registered`, { action });
235
306
  return;
236
307
  }
237
- window._nc_fileactions.push(e);
238
- }, Ie = function() {
239
- return typeof window._nc_fileactions > "u" && (window._nc_fileactions = [], N.debug("FileActions initialized")), window._nc_fileactions;
308
+ window._nc_fileactions.push(action);
309
+ };
310
+ const getFileActions = function() {
311
+ if (typeof window._nc_fileactions === "undefined") {
312
+ window._nc_fileactions = [];
313
+ logger.debug("FileActions initialized");
314
+ }
315
+ return window._nc_fileactions;
240
316
  };
241
317
  /**
242
318
  * @copyright Copyright (c) 2023 John Molakvoæ <skjnldsv@protonmail.com>
@@ -259,10 +335,11 @@ const Te = function(e) {
259
335
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
260
336
  *
261
337
  */
262
- class Ae {
338
+ class Header {
263
339
  _header;
264
- constructor(t) {
265
- this.validateHeader(t), this._header = t;
340
+ constructor(header) {
341
+ this.validateHeader(header);
342
+ this._header = header;
266
343
  }
267
344
  get id() {
268
345
  return this._header.id;
@@ -279,27 +356,41 @@ class Ae {
279
356
  get updated() {
280
357
  return this._header.updated;
281
358
  }
282
- validateHeader(t) {
283
- if (!t.id || !t.render || !t.updated)
359
+ validateHeader(header) {
360
+ if (!header.id || !header.render || !header.updated) {
284
361
  throw new Error("Invalid header: id, render and updated are required");
285
- if (typeof t.id != "string")
362
+ }
363
+ if (typeof header.id !== "string") {
286
364
  throw new Error("Invalid id property");
287
- if (t.enabled !== void 0 && typeof t.enabled != "function")
365
+ }
366
+ if (header.enabled !== void 0 && typeof header.enabled !== "function") {
288
367
  throw new Error("Invalid enabled property");
289
- if (t.render && typeof t.render != "function")
368
+ }
369
+ if (header.render && typeof header.render !== "function") {
290
370
  throw new Error("Invalid render property");
291
- if (t.updated && typeof t.updated != "function")
371
+ }
372
+ if (header.updated && typeof header.updated !== "function") {
292
373
  throw new Error("Invalid updated property");
374
+ }
293
375
  }
294
376
  }
295
- const Ce = function(e) {
296
- if (typeof window._nc_filelistheader > "u" && (window._nc_filelistheader = [], N.debug("FileListHeaders initialized")), window._nc_filelistheader.find((t) => t.id === e.id)) {
297
- N.error(`Header ${e.id} already registered`, { header: e });
377
+ const registerFileListHeaders = function(header) {
378
+ if (typeof window._nc_filelistheader === "undefined") {
379
+ window._nc_filelistheader = [];
380
+ logger.debug("FileListHeaders initialized");
381
+ }
382
+ if (window._nc_filelistheader.find((search) => search.id === header.id)) {
383
+ logger.error(`Header ${header.id} already registered`, { header });
298
384
  return;
299
385
  }
300
- window._nc_filelistheader.push(e);
301
- }, Pe = function() {
302
- return typeof window._nc_filelistheader > "u" && (window._nc_filelistheader = [], N.debug("FileListHeaders initialized")), window._nc_filelistheader;
386
+ window._nc_filelistheader.push(header);
387
+ };
388
+ const getFileListHeaders = function() {
389
+ if (typeof window._nc_filelistheader === "undefined") {
390
+ window._nc_filelistheader = [];
391
+ logger.debug("FileListHeaders initialized");
392
+ }
393
+ return window._nc_filelistheader;
303
394
  };
304
395
  /**
305
396
  * @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
@@ -322,7 +413,16 @@ const Ce = function(e) {
322
413
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
323
414
  *
324
415
  */
325
- var m = /* @__PURE__ */ ((e) => (e[e.NONE = 0] = "NONE", e[e.CREATE = 4] = "CREATE", e[e.READ = 1] = "READ", e[e.UPDATE = 2] = "UPDATE", e[e.DELETE = 8] = "DELETE", e[e.SHARE = 16] = "SHARE", e[e.ALL = 31] = "ALL", e))(m || {});
416
+ var Permission = /* @__PURE__ */ ((Permission2) => {
417
+ Permission2[Permission2["NONE"] = 0] = "NONE";
418
+ Permission2[Permission2["CREATE"] = 4] = "CREATE";
419
+ Permission2[Permission2["READ"] = 1] = "READ";
420
+ Permission2[Permission2["UPDATE"] = 2] = "UPDATE";
421
+ Permission2[Permission2["DELETE"] = 8] = "DELETE";
422
+ Permission2[Permission2["SHARE"] = 16] = "SHARE";
423
+ Permission2[Permission2["ALL"] = 31] = "ALL";
424
+ return Permission2;
425
+ })(Permission || {});
326
426
  /**
327
427
  * @copyright Copyright (c) 2023 John Molakvoæ <skjnldsv@protonmail.com>
328
428
  *
@@ -345,7 +445,7 @@ var m = /* @__PURE__ */ ((e) => (e[e.NONE = 0] = "NONE", e[e.CREATE = 4] = "CREA
345
445
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
346
446
  *
347
447
  */
348
- const M = [
448
+ const defaultDavProperties = [
349
449
  "d:getcontentlength",
350
450
  "d:getcontenttype",
351
451
  "d:getetag",
@@ -362,54 +462,80 @@ const M = [
362
462
  "oc:owner-id",
363
463
  "oc:permissions",
364
464
  "oc:size"
365
- ], B = {
465
+ ];
466
+ const defaultDavNamespaces = {
366
467
  d: "DAV:",
367
468
  nc: "http://nextcloud.org/ns",
368
469
  oc: "http://owncloud.org/ns",
369
470
  ocs: "http://open-collaboration-services.org/ns"
370
- }, Oe = function(e, t = { nc: "http://nextcloud.org/ns" }) {
371
- typeof window._nc_dav_properties > "u" && (window._nc_dav_properties = [...M], window._nc_dav_namespaces = { ...B });
372
- const r = { ...window._nc_dav_namespaces, ...t };
373
- if (window._nc_dav_properties.find((n) => n === e))
374
- return N.warn(`${e} already registered`, { prop: e }), !1;
375
- if (e.startsWith("<") || e.split(":").length !== 2)
376
- return N.error(`${e} is not valid. See example: 'oc:fileid'`, { prop: e }), !1;
377
- const s = e.split(":")[0];
378
- return r[s] ? (window._nc_dav_properties.push(e), window._nc_dav_namespaces = r, !0) : (N.error(`${e} namespace unknown`, { prop: e, namespaces: r }), !1);
379
- }, C = function() {
380
- return typeof window._nc_dav_properties > "u" && (window._nc_dav_properties = [...M]), window._nc_dav_properties.map((e) => `<${e} />`).join(" ");
381
- }, P = function() {
382
- return typeof window._nc_dav_namespaces > "u" && (window._nc_dav_namespaces = { ...B }), Object.keys(window._nc_dav_namespaces).map((e) => `xmlns:${e}="${window._nc_dav_namespaces?.[e]}"`).join(" ");
383
- }, Fe = function() {
471
+ };
472
+ const registerDavProperty = function(prop, namespace = { nc: "http://nextcloud.org/ns" }) {
473
+ if (typeof window._nc_dav_properties === "undefined") {
474
+ window._nc_dav_properties = [...defaultDavProperties];
475
+ window._nc_dav_namespaces = { ...defaultDavNamespaces };
476
+ }
477
+ const namespaces = { ...window._nc_dav_namespaces, ...namespace };
478
+ if (window._nc_dav_properties.find((search) => search === prop)) {
479
+ logger.warn(`${prop} already registered`, { prop });
480
+ return false;
481
+ }
482
+ if (prop.startsWith("<") || prop.split(":").length !== 2) {
483
+ logger.error(`${prop} is not valid. See example: 'oc:fileid'`, { prop });
484
+ return false;
485
+ }
486
+ const ns = prop.split(":")[0];
487
+ if (!namespaces[ns]) {
488
+ logger.error(`${prop} namespace unknown`, { prop, namespaces });
489
+ return false;
490
+ }
491
+ window._nc_dav_properties.push(prop);
492
+ window._nc_dav_namespaces = namespaces;
493
+ return true;
494
+ };
495
+ const getDavProperties = function() {
496
+ if (typeof window._nc_dav_properties === "undefined") {
497
+ window._nc_dav_properties = [...defaultDavProperties];
498
+ }
499
+ return window._nc_dav_properties.map((prop) => `<${prop} />`).join(" ");
500
+ };
501
+ const getDavNameSpaces = function() {
502
+ if (typeof window._nc_dav_namespaces === "undefined") {
503
+ window._nc_dav_namespaces = { ...defaultDavNamespaces };
504
+ }
505
+ return Object.keys(window._nc_dav_namespaces).map((ns) => `xmlns:${ns}="${window._nc_dav_namespaces?.[ns]}"`).join(" ");
506
+ };
507
+ const davGetDefaultPropfind = function() {
384
508
  return `<?xml version="1.0"?>
385
- <d:propfind ${P()}>
509
+ <d:propfind ${getDavNameSpaces()}>
386
510
  <d:prop>
387
- ${C()}
511
+ ${getDavProperties()}
388
512
  </d:prop>
389
513
  </d:propfind>`;
390
- }, te = function() {
514
+ };
515
+ const davGetFavoritesReport = function() {
391
516
  return `<?xml version="1.0"?>
392
- <oc:filter-files ${P()}>
517
+ <oc:filter-files ${getDavNameSpaces()}>
393
518
  <d:prop>
394
- ${C()}
519
+ ${getDavProperties()}
395
520
  </d:prop>
396
521
  <oc:filter-rules>
397
522
  <oc:favorite>1</oc:favorite>
398
523
  </oc:filter-rules>
399
524
  </oc:filter-files>`;
400
- }, xe = function(e) {
525
+ };
526
+ const davGetRecentSearch = function(lastModified) {
401
527
  return `<?xml version="1.0" encoding="UTF-8"?>
402
- <d:searchrequest ${P()}
528
+ <d:searchrequest ${getDavNameSpaces()}
403
529
  xmlns:ns="https://github.com/icewind1991/SearchDAV/ns">
404
530
  <d:basicsearch>
405
531
  <d:select>
406
532
  <d:prop>
407
- ${C()}
533
+ ${getDavProperties()}
408
534
  </d:prop>
409
535
  </d:select>
410
536
  <d:from>
411
537
  <d:scope>
412
- <d:href>/files/${_.getCurrentUser()?.uid}/</d:href>
538
+ <d:href>/files/${auth.getCurrentUser()?.uid}/</d:href>
413
539
  <d:depth>infinity</d:depth>
414
540
  </d:scope>
415
541
  </d:from>
@@ -435,7 +561,7 @@ const M = [
435
561
  <d:prop>
436
562
  <d:getlastmodified/>
437
563
  </d:prop>
438
- <d:literal>${e}</d:literal>
564
+ <d:literal>${lastModified}</d:literal>
439
565
  </d:gt>
440
566
  </d:and>
441
567
  </d:where>
@@ -476,9 +602,27 @@ const M = [
476
602
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
477
603
  *
478
604
  */
479
- const re = function(e = "") {
480
- let t = m.NONE;
481
- return e && ((e.includes("C") || e.includes("K")) && (t |= m.CREATE), e.includes("G") && (t |= m.READ), (e.includes("W") || e.includes("N") || e.includes("V")) && (t |= m.UPDATE), e.includes("D") && (t |= m.DELETE), e.includes("R") && (t |= m.SHARE)), t;
605
+ const davParsePermissions = function(permString = "") {
606
+ let permissions = Permission.NONE;
607
+ if (!permString) {
608
+ return permissions;
609
+ }
610
+ if (permString.includes("C") || permString.includes("K")) {
611
+ permissions |= Permission.CREATE;
612
+ }
613
+ if (permString.includes("G")) {
614
+ permissions |= Permission.READ;
615
+ }
616
+ if (permString.includes("W") || permString.includes("N") || permString.includes("V")) {
617
+ permissions |= Permission.UPDATE;
618
+ }
619
+ if (permString.includes("D")) {
620
+ permissions |= Permission.DELETE;
621
+ }
622
+ if (permString.includes("R")) {
623
+ permissions |= Permission.SHARE;
624
+ }
625
+ return permissions;
482
626
  };
483
627
  /**
484
628
  * @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
@@ -501,7 +645,11 @@ const re = function(e = "") {
501
645
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
502
646
  *
503
647
  */
504
- var O = /* @__PURE__ */ ((e) => (e.Folder = "folder", e.File = "file", e))(O || {});
648
+ var FileType = /* @__PURE__ */ ((FileType2) => {
649
+ FileType2["Folder"] = "folder";
650
+ FileType2["File"] = "file";
651
+ return FileType2;
652
+ })(FileType || {});
505
653
  /**
506
654
  * @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
507
655
  *
@@ -523,47 +671,63 @@ var O = /* @__PURE__ */ ((e) => (e.Folder = "folder", e.File = "file", e))(O ||
523
671
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
524
672
  *
525
673
  */
526
- const ne = function(e, t) {
527
- return e.match(t) !== null;
528
- }, Z = (e, t) => {
529
- if (e.id && typeof e.id != "number")
674
+ const isDavRessource = function(source, davService) {
675
+ return source.match(davService) !== null;
676
+ };
677
+ const validateData = (data, davService) => {
678
+ if (data.id && typeof data.id !== "number") {
530
679
  throw new Error("Invalid id type of value");
531
- if (!e.source)
680
+ }
681
+ if (!data.source) {
532
682
  throw new Error("Missing mandatory source");
683
+ }
533
684
  try {
534
- new URL(e.source);
535
- } catch {
685
+ new URL(data.source);
686
+ } catch (e) {
536
687
  throw new Error("Invalid source format, source must be a valid URL");
537
688
  }
538
- if (!e.source.startsWith("http"))
689
+ if (!data.source.startsWith("http")) {
539
690
  throw new Error("Invalid source format, only http(s) is supported");
540
- if (e.mtime && !(e.mtime instanceof Date))
691
+ }
692
+ if (data.mtime && !(data.mtime instanceof Date)) {
541
693
  throw new Error("Invalid mtime type");
542
- if (e.crtime && !(e.crtime instanceof Date))
694
+ }
695
+ if (data.crtime && !(data.crtime instanceof Date)) {
543
696
  throw new Error("Invalid crtime type");
544
- if (!e.mime || typeof e.mime != "string" || !e.mime.match(/^[-\w.]+\/[-+\w.]+$/gi))
697
+ }
698
+ if (!data.mime || typeof data.mime !== "string" || !data.mime.match(/^[-\w.]+\/[-+\w.]+$/gi)) {
545
699
  throw new Error("Missing or invalid mandatory mime");
546
- if ("size" in e && typeof e.size != "number" && e.size !== void 0)
700
+ }
701
+ if ("size" in data && typeof data.size !== "number" && data.size !== void 0) {
547
702
  throw new Error("Invalid size type");
548
- if ("permissions" in e && e.permissions !== void 0 && !(typeof e.permissions == "number" && e.permissions >= m.NONE && e.permissions <= m.ALL))
703
+ }
704
+ if ("permissions" in data && data.permissions !== void 0 && !(typeof data.permissions === "number" && data.permissions >= Permission.NONE && data.permissions <= Permission.ALL)) {
549
705
  throw new Error("Invalid permissions");
550
- if (e.owner && e.owner !== null && typeof e.owner != "string")
706
+ }
707
+ if (data.owner && data.owner !== null && typeof data.owner !== "string") {
551
708
  throw new Error("Invalid owner type");
552
- if (e.attributes && typeof e.attributes != "object")
709
+ }
710
+ if (data.attributes && typeof data.attributes !== "object") {
553
711
  throw new Error("Invalid attributes type");
554
- if (e.root && typeof e.root != "string")
712
+ }
713
+ if (data.root && typeof data.root !== "string") {
555
714
  throw new Error("Invalid root type");
556
- if (e.root && !e.root.startsWith("/"))
715
+ }
716
+ if (data.root && !data.root.startsWith("/")) {
557
717
  throw new Error("Root must start with a leading slash");
558
- if (e.root && !e.source.includes(e.root))
718
+ }
719
+ if (data.root && !data.source.includes(data.root)) {
559
720
  throw new Error("Root must be part of the source");
560
- if (e.root && ne(e.source, t)) {
561
- const r = e.source.match(t)[0];
562
- if (!e.source.includes(y.join(r, e.root)))
721
+ }
722
+ if (data.root && isDavRessource(data.source, davService)) {
723
+ const service = data.source.match(davService)[0];
724
+ if (!data.source.includes(path.join(service, data.root))) {
563
725
  throw new Error("The root must be relative to the service. e.g /files/emma");
726
+ }
564
727
  }
565
- if (e.status && !Object.values(k).includes(e.status))
728
+ if (data.status && !Object.values(NodeStatus).includes(data.status)) {
566
729
  throw new Error("Status must be a valid NodeStatus");
730
+ }
567
731
  };
568
732
  /**
569
733
  * @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
@@ -586,23 +750,42 @@ const ne = function(e, t) {
586
750
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
587
751
  *
588
752
  */
589
- var k = /* @__PURE__ */ ((e) => (e.NEW = "new", e.FAILED = "failed", e.LOADING = "loading", e.LOCKED = "locked", e))(k || {});
590
- class q {
753
+ var NodeStatus = /* @__PURE__ */ ((NodeStatus2) => {
754
+ NodeStatus2["NEW"] = "new";
755
+ NodeStatus2["FAILED"] = "failed";
756
+ NodeStatus2["LOADING"] = "loading";
757
+ NodeStatus2["LOCKED"] = "locked";
758
+ return NodeStatus2;
759
+ })(NodeStatus || {});
760
+ class Node {
591
761
  _data;
592
762
  _attributes;
593
763
  _knownDavService = /(remote|public)\.php\/(web)?dav/i;
594
- constructor(t, r) {
595
- Z(t, r || this._knownDavService), this._data = t;
596
- const s = {
597
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
598
- set: (n, i, a) => (this.updateMtime(), Reflect.set(n, i, a)),
599
- deleteProperty: (n, i) => (this.updateMtime(), Reflect.deleteProperty(n, i))
600
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
601
- };
602
- this._attributes = new Proxy(t.attributes || {}, s), delete this._data.attributes, r && (this._knownDavService = r);
764
+ handler = {
765
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
766
+ set: (target, prop, value) => {
767
+ this.updateMtime();
768
+ return Reflect.set(target, prop, value);
769
+ },
770
+ deleteProperty: (target, prop) => {
771
+ this.updateMtime();
772
+ return Reflect.deleteProperty(target, prop);
773
+ }
774
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
775
+ };
776
+ constructor(data, davService) {
777
+ validateData(data, davService || this._knownDavService);
778
+ this._data = data;
779
+ this._attributes = new Proxy(this.cleanAttributes(data.attributes || {}), this.handler);
780
+ delete this._data.attributes;
781
+ if (davService) {
782
+ this._knownDavService = davService;
783
+ }
603
784
  }
604
785
  /**
605
786
  * Get the source url to this object
787
+ * There is no setter as the source is not meant to be changed manually.
788
+ * You can use the rename or move method to change the source.
606
789
  */
607
790
  get source() {
608
791
  return this._data.source.replace(/\/$/i, "");
@@ -611,49 +794,63 @@ class q {
611
794
  * Get the encoded source url to this object for requests purposes
612
795
  */
613
796
  get encodedSource() {
614
- const { origin: t } = new URL(this.source);
615
- return t + we.encodePath(this.source.slice(t.length));
797
+ const { origin } = new URL(this.source);
798
+ return origin + paths.encodePath(this.source.slice(origin.length));
616
799
  }
617
800
  /**
618
801
  * Get this object name
802
+ * There is no setter as the source is not meant to be changed manually.
803
+ * You can use the rename or move method to change the source.
619
804
  */
620
805
  get basename() {
621
- return y.basename(this.source);
806
+ return path.basename(this.source);
622
807
  }
623
808
  /**
624
809
  * Get this object's extension
810
+ * There is no setter as the source is not meant to be changed manually.
811
+ * You can use the rename or move method to change the source.
625
812
  */
626
813
  get extension() {
627
- return y.extname(this.source);
814
+ return path.extname(this.source);
628
815
  }
629
816
  /**
630
817
  * Get the directory path leading to this object
631
818
  * Will use the relative path to root if available
819
+ *
820
+ * There is no setter as the source is not meant to be changed manually.
821
+ * You can use the rename or move method to change the source.
632
822
  */
633
823
  get dirname() {
634
824
  if (this.root) {
635
- let r = this.source;
636
- this.isDavRessource && (r = r.split(this._knownDavService).pop());
637
- const s = r.indexOf(this.root), n = this.root.replace(/\/$/, "");
638
- return y.dirname(r.slice(s + n.length) || "/");
825
+ let source = this.source;
826
+ if (this.isDavRessource) {
827
+ source = source.split(this._knownDavService).pop();
828
+ }
829
+ const firstMatch = source.indexOf(this.root);
830
+ const root = this.root.replace(/\/$/, "");
831
+ return path.dirname(source.slice(firstMatch + root.length) || "/");
639
832
  }
640
- const t = new URL(this.source);
641
- return y.dirname(t.pathname);
833
+ const url = new URL(this.source);
834
+ return path.dirname(url.pathname);
642
835
  }
643
836
  /**
644
837
  * Get the file mime
838
+ * There is no setter as the mime is not meant to be changed
645
839
  */
646
840
  get mime() {
647
841
  return this._data.mime;
648
842
  }
649
843
  /**
650
844
  * Get the file modification time
845
+ * There is no setter as the modification time is not meant to be changed manually.
846
+ * It will be automatically updated when the attributes are changed.
651
847
  */
652
848
  get mtime() {
653
849
  return this._data.mtime;
654
850
  }
655
851
  /**
656
852
  * Get the file creation time
853
+ * There is no setter as the creation time is not meant to be changed
657
854
  */
658
855
  get crtime() {
659
856
  return this._data.crtime;
@@ -664,6 +861,13 @@ class q {
664
861
  get size() {
665
862
  return this._data.size;
666
863
  }
864
+ /**
865
+ * Set the file size
866
+ */
867
+ set size(size) {
868
+ this.updateMtime();
869
+ this._data.size = size;
870
+ }
667
871
  /**
668
872
  * Get the file attribute
669
873
  */
@@ -674,44 +878,69 @@ class q {
674
878
  * Get the file permissions
675
879
  */
676
880
  get permissions() {
677
- return this.owner === null && !this.isDavRessource ? m.READ : this._data.permissions !== void 0 ? this._data.permissions : m.NONE;
881
+ if (this.owner === null && !this.isDavRessource) {
882
+ return Permission.READ;
883
+ }
884
+ return this._data.permissions !== void 0 ? this._data.permissions : Permission.NONE;
885
+ }
886
+ /**
887
+ * Set the file permissions
888
+ */
889
+ set permissions(permissions) {
890
+ this.updateMtime();
891
+ this._data.permissions = permissions;
678
892
  }
679
893
  /**
680
894
  * Get the file owner
895
+ * There is no setter as the owner is not meant to be changed
681
896
  */
682
897
  get owner() {
683
- return this.isDavRessource ? this._data.owner : null;
898
+ if (!this.isDavRessource) {
899
+ return null;
900
+ }
901
+ return this._data.owner;
684
902
  }
685
903
  /**
686
904
  * Is this a dav-related ressource ?
687
905
  */
688
906
  get isDavRessource() {
689
- return ne(this.source, this._knownDavService);
907
+ return isDavRessource(this.source, this._knownDavService);
690
908
  }
691
909
  /**
692
910
  * Get the dav root of this object
911
+ * There is no setter as the root is not meant to be changed
693
912
  */
694
913
  get root() {
695
- return this._data.root ? this._data.root.replace(/^(.+)\/$/, "$1") : this.isDavRessource && y.dirname(this.source).split(this._knownDavService).pop() || null;
914
+ if (this._data.root) {
915
+ return this._data.root.replace(/^(.+)\/$/, "$1");
916
+ }
917
+ if (this.isDavRessource) {
918
+ const root = path.dirname(this.source);
919
+ return root.split(this._knownDavService).pop() || null;
920
+ }
921
+ return null;
696
922
  }
697
923
  /**
698
924
  * Get the absolute path of this object relative to the root
699
925
  */
700
926
  get path() {
701
927
  if (this.root) {
702
- let t = this.source;
703
- this.isDavRessource && (t = t.split(this._knownDavService).pop());
704
- const r = t.indexOf(this.root), s = this.root.replace(/\/$/, "");
705
- return t.slice(r + s.length) || "/";
928
+ let source = this.source;
929
+ if (this.isDavRessource) {
930
+ source = source.split(this._knownDavService).pop();
931
+ }
932
+ const firstMatch = source.indexOf(this.root);
933
+ const root = this.root.replace(/\/$/, "");
934
+ return source.slice(firstMatch + root.length) || "/";
706
935
  }
707
936
  return (this.dirname + "/" + this.basename).replace(/\/\//g, "/");
708
937
  }
709
938
  /**
710
939
  * Get the node id if defined.
711
- * Will look for the fileid in attributes if undefined.
940
+ * There is no setter as the fileid is not meant to be changed
712
941
  */
713
942
  get fileid() {
714
- return this._data?.id || this.attributes?.fileid;
943
+ return this._data?.id;
715
944
  }
716
945
  /**
717
946
  * Get the node status.
@@ -722,8 +951,8 @@ class q {
722
951
  /**
723
952
  * Set the node status.
724
953
  */
725
- set status(t) {
726
- this._data.status = t;
954
+ set status(status) {
955
+ this._data.status = status;
727
956
  }
728
957
  /**
729
958
  * Move the node to a new destination
@@ -731,8 +960,10 @@ class q {
731
960
  * @param {string} destination the new source.
732
961
  * e.g. https://cloud.domain.com/remote.php/dav/files/emma/Photos/picture.jpg
733
962
  */
734
- move(t) {
735
- Z({ ...this._data, source: t }, this._knownDavService), this._data.source = t, this.updateMtime();
963
+ move(destination) {
964
+ validateData({ ...this._data, source: destination }, this._knownDavService);
965
+ this._data.source = destination;
966
+ this.updateMtime();
736
967
  }
737
968
  /**
738
969
  * Rename the node
@@ -740,16 +971,39 @@ class q {
740
971
  *
741
972
  * @param basename The new name of the node
742
973
  */
743
- rename(t) {
744
- if (t.includes("/"))
974
+ rename(basename2) {
975
+ if (basename2.includes("/")) {
745
976
  throw new Error("Invalid basename");
746
- this.move(y.dirname(this.source) + "/" + t);
977
+ }
978
+ this.move(path.dirname(this.source) + "/" + basename2);
747
979
  }
748
980
  /**
749
981
  * Update the mtime if exists.
750
982
  */
751
983
  updateMtime() {
752
- this._data.mtime && (this._data.mtime = /* @__PURE__ */ new Date());
984
+ if (this._data.mtime) {
985
+ this._data.mtime = /* @__PURE__ */ new Date();
986
+ }
987
+ }
988
+ /**
989
+ * Update the attributes of the node
990
+ *
991
+ * @param attributes The new attributes to update
992
+ */
993
+ update(attributes) {
994
+ this._attributes = new Proxy(this.cleanAttributes(attributes), this.handler);
995
+ }
996
+ cleanAttributes(attributes) {
997
+ const getters = Object.entries(Object.getOwnPropertyDescriptors(Node.prototype)).filter((e) => typeof e[1].get === "function" && e[0] !== "__proto__").map((e) => e[0]);
998
+ const clean = {};
999
+ for (const key in attributes) {
1000
+ if (getters.includes(key)) {
1001
+ logger.debug(`Discarding protected attribute ${key}`, { node: this, attributes });
1002
+ continue;
1003
+ }
1004
+ clean[key] = attributes[key];
1005
+ }
1006
+ return clean;
753
1007
  }
754
1008
  }
755
1009
  /**
@@ -773,9 +1027,9 @@ class q {
773
1027
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
774
1028
  *
775
1029
  */
776
- class ie extends q {
1030
+ class File extends Node {
777
1031
  get type() {
778
- return O.File;
1032
+ return FileType.File;
779
1033
  }
780
1034
  }
781
1035
  /**
@@ -799,15 +1053,15 @@ class ie extends q {
799
1053
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
800
1054
  *
801
1055
  */
802
- class se extends q {
803
- constructor(t) {
1056
+ class Folder extends Node {
1057
+ constructor(data) {
804
1058
  super({
805
- ...t,
1059
+ ...data,
806
1060
  mime: "httpd/unix-directory"
807
1061
  });
808
1062
  }
809
1063
  get type() {
810
- return O.Folder;
1064
+ return FileType.Folder;
811
1065
  }
812
1066
  get extension() {
813
1067
  return null;
@@ -838,62 +1092,95 @@ class se extends q {
838
1092
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
839
1093
  *
840
1094
  */
841
- const U = `/files/${_.getCurrentUser()?.uid}`, X = me.generateRemoteUrl("dav"), $e = function(e = X, t = {}) {
842
- const r = W.createClient(e, { headers: t });
843
- function s(i) {
844
- r.setHeaders({
845
- ...t,
1095
+ const davRootPath = `/files/${auth.getCurrentUser()?.uid}`;
1096
+ const davRemoteURL = router.generateRemoteUrl("dav");
1097
+ const davGetClient = function(remoteURL = davRemoteURL, headers = {}) {
1098
+ const client = webdav.createClient(remoteURL, { headers });
1099
+ function setHeaders(token) {
1100
+ client.setHeaders({
1101
+ ...headers,
846
1102
  // Add this so the server knows it is an request from the browser
847
1103
  "X-Requested-With": "XMLHttpRequest",
848
1104
  // Inject user auth
849
- requesttoken: i ?? ""
1105
+ requesttoken: token ?? ""
850
1106
  });
851
1107
  }
852
- return _.onRequestTokenUpdate(s), s(_.getRequestToken()), W.getPatcher().patch("fetch", (i, a) => {
853
- const u = a.headers;
854
- return u?.method && (a.method = u.method, delete u.method), fetch(i, a);
855
- }), r;
856
- }, Se = (e, t = "/", r = U) => {
857
- const s = new AbortController();
858
- return new Ne.CancelablePromise(async (n, i, a) => {
859
- a(() => s.abort());
1108
+ auth.onRequestTokenUpdate(setHeaders);
1109
+ setHeaders(auth.getRequestToken());
1110
+ const patcher = webdav.getPatcher();
1111
+ patcher.patch("fetch", (url, options) => {
1112
+ const headers2 = options.headers;
1113
+ if (headers2?.method) {
1114
+ options.method = headers2.method;
1115
+ delete headers2.method;
1116
+ }
1117
+ return fetch(url, options);
1118
+ });
1119
+ return client;
1120
+ };
1121
+ const getFavoriteNodes = (davClient, path2 = "/", davRoot = davRootPath) => {
1122
+ const controller = new AbortController();
1123
+ return new cancelablePromise.CancelablePromise(async (resolve, reject, onCancel) => {
1124
+ onCancel(() => controller.abort());
860
1125
  try {
861
- const o = (await e.getDirectoryContents(`${r}${t}`, {
862
- signal: s.signal,
863
- details: !0,
864
- data: te(),
1126
+ const contentsResponse = await davClient.getDirectoryContents(`${davRoot}${path2}`, {
1127
+ signal: controller.signal,
1128
+ details: true,
1129
+ data: davGetFavoritesReport(),
865
1130
  headers: {
866
1131
  // see davGetClient for patched webdav client
867
1132
  method: "REPORT"
868
1133
  },
869
- includeSelf: !0
870
- })).data.filter((d) => d.filename !== t).map((d) => oe(d, r));
871
- n(o);
872
- } catch (u) {
873
- i(u);
1134
+ includeSelf: true
1135
+ });
1136
+ const nodes = contentsResponse.data.filter((node) => node.filename !== path2).map((result) => davResultToNode(result, davRoot));
1137
+ resolve(nodes);
1138
+ } catch (error) {
1139
+ reject(error);
874
1140
  }
875
1141
  });
876
- }, oe = function(e, t = U, r = X) {
877
- const s = _.getCurrentUser()?.uid;
878
- if (!s)
1142
+ };
1143
+ const davResultToNode = function(node, filesRoot = davRootPath, remoteURL = davRemoteURL) {
1144
+ let userId = auth.getCurrentUser()?.uid;
1145
+ const isPublic = document.querySelector("input#isPublic")?.value;
1146
+ if (isPublic) {
1147
+ userId = userId ?? document.querySelector("input#sharingUserId")?.value;
1148
+ userId = userId ?? "anonymous";
1149
+ } else if (!userId) {
879
1150
  throw new Error("No user id found");
880
- const n = e.props, i = re(n?.permissions), a = (n?.["owner-id"] || s).toString(), u = {
881
- id: n?.fileid || 0,
882
- source: `${r}${e.filename}`,
883
- mtime: new Date(Date.parse(e.lastmod)),
884
- mime: e.mime || "application/octet-stream",
885
- size: n?.size || Number.parseInt(n.getcontentlength || "0"),
886
- permissions: i,
887
- owner: a,
888
- root: t,
1151
+ }
1152
+ const props = node.props;
1153
+ const permissions = davParsePermissions(props?.permissions);
1154
+ const owner = String(props?.["owner-id"] || userId);
1155
+ const nodeData = {
1156
+ id: props?.fileid || 0,
1157
+ source: `${remoteURL}${node.filename}`,
1158
+ mtime: new Date(Date.parse(node.lastmod)),
1159
+ mime: node.mime || "application/octet-stream",
1160
+ size: props?.size || Number.parseInt(props.getcontentlength || "0"),
1161
+ permissions,
1162
+ owner,
1163
+ root: filesRoot,
889
1164
  attributes: {
890
- ...e,
891
- ...n,
892
- hasPreview: n?.["has-preview"]
1165
+ ...node,
1166
+ ...props,
1167
+ hasPreview: props?.["has-preview"]
893
1168
  }
894
1169
  };
895
- return delete u.attributes?.props, e.type === "file" ? new ie(u) : new se(u);
1170
+ delete nodeData.attributes?.props;
1171
+ return node.type === "file" ? new File(nodeData) : new Folder(nodeData);
896
1172
  };
1173
+ const forbiddenCharacters = window._oc_config?.forbidden_filenames_characters ?? ["/", "\\"];
1174
+ const forbiddenFilenameRegex = window._oc_config?.blacklist_files_regex ? new RegExp(window._oc_config.blacklist_files_regex) : null;
1175
+ function isFilenameValid(filename) {
1176
+ if (forbiddenCharacters.some((character) => filename.includes(character))) {
1177
+ return false;
1178
+ }
1179
+ if (forbiddenFilenameRegex !== null && filename.match(forbiddenFilenameRegex)) {
1180
+ return false;
1181
+ }
1182
+ return true;
1183
+ }
897
1184
  /**
898
1185
  * @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
899
1186
  *
@@ -915,30 +1202,37 @@ const U = `/files/${_.getCurrentUser()?.uid}`, X = me.generateRemoteUrl("dav"),
915
1202
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
916
1203
  *
917
1204
  */
918
- class ue {
1205
+ class Navigation {
919
1206
  _views = [];
920
1207
  _currentView = null;
921
- register(t) {
922
- if (this._views.find((r) => r.id === t.id))
923
- throw new Error(`View id ${t.id} is already registered`);
924
- this._views.push(t);
1208
+ register(view) {
1209
+ if (this._views.find((search) => search.id === view.id)) {
1210
+ throw new Error(`View id ${view.id} is already registered`);
1211
+ }
1212
+ this._views.push(view);
925
1213
  }
926
- remove(t) {
927
- const r = this._views.findIndex((s) => s.id === t);
928
- r !== -1 && this._views.splice(r, 1);
1214
+ remove(id) {
1215
+ const index = this._views.findIndex((view) => view.id === id);
1216
+ if (index !== -1) {
1217
+ this._views.splice(index, 1);
1218
+ }
929
1219
  }
930
1220
  get views() {
931
1221
  return this._views;
932
1222
  }
933
- setActive(t) {
934
- this._currentView = t;
1223
+ setActive(view) {
1224
+ this._currentView = view;
935
1225
  }
936
1226
  get active() {
937
1227
  return this._currentView;
938
1228
  }
939
1229
  }
940
- const Ve = function() {
941
- return typeof window._nc_navigation > "u" && (window._nc_navigation = new ue(), N.debug("Navigation service initialized")), window._nc_navigation;
1230
+ const getNavigation = function() {
1231
+ if (typeof window._nc_navigation === "undefined") {
1232
+ window._nc_navigation = new Navigation();
1233
+ logger.debug("Navigation service initialized");
1234
+ }
1235
+ return window._nc_navigation;
942
1236
  };
943
1237
  /**
944
1238
  * @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
@@ -961,10 +1255,11 @@ const Ve = function() {
961
1255
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
962
1256
  *
963
1257
  */
964
- class ae {
1258
+ class Column {
965
1259
  _column;
966
- constructor(t) {
967
- Le(t), this._column = t;
1260
+ constructor(column) {
1261
+ isValidColumn(column);
1262
+ this._column = column;
968
1263
  }
969
1264
  get id() {
970
1265
  return this._column.id;
@@ -982,918 +1277,1437 @@ class ae {
982
1277
  return this._column.summary;
983
1278
  }
984
1279
  }
985
- const Le = function(e) {
986
- if (!e.id || typeof e.id != "string")
1280
+ const isValidColumn = function(column) {
1281
+ if (!column.id || typeof column.id !== "string") {
987
1282
  throw new Error("A column id is required");
988
- if (!e.title || typeof e.title != "string")
1283
+ }
1284
+ if (!column.title || typeof column.title !== "string") {
989
1285
  throw new Error("A column title is required");
990
- if (!e.render || typeof e.render != "function")
1286
+ }
1287
+ if (!column.render || typeof column.render !== "function") {
991
1288
  throw new Error("A render function is required");
992
- if (e.sort && typeof e.sort != "function")
1289
+ }
1290
+ if (column.sort && typeof column.sort !== "function") {
993
1291
  throw new Error("Column sortFunction must be a function");
994
- if (e.summary && typeof e.summary != "function")
1292
+ }
1293
+ if (column.summary && typeof column.summary !== "function") {
995
1294
  throw new Error("Column summary must be a function");
996
- return !0;
1295
+ }
1296
+ return true;
997
1297
  };
998
- var G = {}, F = {};
999
- (function(e) {
1000
- const t = ":A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD", r = t + "\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040", s = "[" + t + "][" + r + "]*", n = new RegExp("^" + s + "$"), i = function(u, o) {
1001
- const d = [];
1002
- let l = o.exec(u);
1003
- for (; l; ) {
1004
- const f = [];
1005
- f.startIndex = o.lastIndex - l[0].length;
1006
- const c = l.length;
1007
- for (let g = 0; g < c; g++)
1008
- f.push(l[g]);
1009
- d.push(f), l = o.exec(u);
1010
- }
1011
- return d;
1012
- }, a = function(u) {
1013
- const o = n.exec(u);
1014
- return !(o === null || typeof o > "u");
1298
+ var validator$2 = {};
1299
+ var util$3 = {};
1300
+ (function(exports2) {
1301
+ const nameStartChar = ":A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD";
1302
+ const nameChar = nameStartChar + "\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040";
1303
+ const nameRegexp = "[" + nameStartChar + "][" + nameChar + "]*";
1304
+ const regexName = new RegExp("^" + nameRegexp + "$");
1305
+ const getAllMatches = function(string, regex) {
1306
+ const matches = [];
1307
+ let match = regex.exec(string);
1308
+ while (match) {
1309
+ const allmatches = [];
1310
+ allmatches.startIndex = regex.lastIndex - match[0].length;
1311
+ const len = match.length;
1312
+ for (let index = 0; index < len; index++) {
1313
+ allmatches.push(match[index]);
1314
+ }
1315
+ matches.push(allmatches);
1316
+ match = regex.exec(string);
1317
+ }
1318
+ return matches;
1015
1319
  };
1016
- e.isExist = function(u) {
1017
- return typeof u < "u";
1018
- }, e.isEmptyObject = function(u) {
1019
- return Object.keys(u).length === 0;
1020
- }, e.merge = function(u, o, d) {
1021
- if (o) {
1022
- const l = Object.keys(o), f = l.length;
1023
- for (let c = 0; c < f; c++)
1024
- d === "strict" ? u[l[c]] = [o[l[c]]] : u[l[c]] = o[l[c]];
1025
- }
1026
- }, e.getValue = function(u) {
1027
- return e.isExist(u) ? u : "";
1028
- }, e.isName = a, e.getAllMatches = i, e.nameRegexp = s;
1029
- })(F);
1030
- const H = F, Re = {
1031
- allowBooleanAttributes: !1,
1320
+ const isName = function(string) {
1321
+ const match = regexName.exec(string);
1322
+ return !(match === null || typeof match === "undefined");
1323
+ };
1324
+ exports2.isExist = function(v) {
1325
+ return typeof v !== "undefined";
1326
+ };
1327
+ exports2.isEmptyObject = function(obj) {
1328
+ return Object.keys(obj).length === 0;
1329
+ };
1330
+ exports2.merge = function(target, a, arrayMode) {
1331
+ if (a) {
1332
+ const keys = Object.keys(a);
1333
+ const len = keys.length;
1334
+ for (let i = 0; i < len; i++) {
1335
+ if (arrayMode === "strict") {
1336
+ target[keys[i]] = [a[keys[i]]];
1337
+ } else {
1338
+ target[keys[i]] = a[keys[i]];
1339
+ }
1340
+ }
1341
+ }
1342
+ };
1343
+ exports2.getValue = function(v) {
1344
+ if (exports2.isExist(v)) {
1345
+ return v;
1346
+ } else {
1347
+ return "";
1348
+ }
1349
+ };
1350
+ exports2.isName = isName;
1351
+ exports2.getAllMatches = getAllMatches;
1352
+ exports2.nameRegexp = nameRegexp;
1353
+ })(util$3);
1354
+ const util$2 = util$3;
1355
+ const defaultOptions$2 = {
1356
+ allowBooleanAttributes: false,
1032
1357
  //A tag can have attributes without any value
1033
1358
  unpairedTags: []
1034
1359
  };
1035
- G.validate = function(e, t) {
1036
- t = Object.assign({}, Re, t);
1037
- const r = [];
1038
- let s = !1, n = !1;
1039
- e[0] === "\uFEFF" && (e = e.substr(1));
1040
- for (let i = 0; i < e.length; i++)
1041
- if (e[i] === "<" && e[i + 1] === "?") {
1042
- if (i += 2, i = Y(e, i), i.err)
1360
+ validator$2.validate = function(xmlData, options) {
1361
+ options = Object.assign({}, defaultOptions$2, options);
1362
+ const tags = [];
1363
+ let tagFound = false;
1364
+ let reachedRoot = false;
1365
+ if (xmlData[0] === "\uFEFF") {
1366
+ xmlData = xmlData.substr(1);
1367
+ }
1368
+ for (let i = 0; i < xmlData.length; i++) {
1369
+ if (xmlData[i] === "<" && xmlData[i + 1] === "?") {
1370
+ i += 2;
1371
+ i = readPI(xmlData, i);
1372
+ if (i.err)
1043
1373
  return i;
1044
- } else if (e[i] === "<") {
1045
- let a = i;
1046
- if (i++, e[i] === "!") {
1047
- i = J(e, i);
1374
+ } else if (xmlData[i] === "<") {
1375
+ let tagStartPos = i;
1376
+ i++;
1377
+ if (xmlData[i] === "!") {
1378
+ i = readCommentAndCDATA(xmlData, i);
1048
1379
  continue;
1049
1380
  } else {
1050
- let u = !1;
1051
- e[i] === "/" && (u = !0, i++);
1052
- let o = "";
1053
- for (; i < e.length && e[i] !== ">" && e[i] !== " " && e[i] !== " " && e[i] !== `
1054
- ` && e[i] !== "\r"; i++)
1055
- o += e[i];
1056
- if (o = o.trim(), o[o.length - 1] === "/" && (o = o.substring(0, o.length - 1), i--), !He(o)) {
1057
- let f;
1058
- return o.trim().length === 0 ? f = "Invalid space after '<'." : f = "Tag '" + o + "' is an invalid name.", p("InvalidTag", f, w(e, i));
1381
+ let closingTag = false;
1382
+ if (xmlData[i] === "/") {
1383
+ closingTag = true;
1384
+ i++;
1059
1385
  }
1060
- const d = ke(e, i);
1061
- if (d === !1)
1062
- return p("InvalidAttr", "Attributes for '" + o + "' have open quote.", w(e, i));
1063
- let l = d.value;
1064
- if (i = d.index, l[l.length - 1] === "/") {
1065
- const f = i - l.length;
1066
- l = l.substring(0, l.length - 1);
1067
- const c = Q(l, t);
1068
- if (c === !0)
1069
- s = !0;
1070
- else
1071
- return p(c.err.code, c.err.msg, w(e, f + c.err.line));
1072
- } else if (u)
1073
- if (d.tagClosed) {
1074
- if (l.trim().length > 0)
1075
- return p("InvalidTag", "Closing tag '" + o + "' can't have attributes or invalid starting.", w(e, a));
1076
- {
1077
- const f = r.pop();
1078
- if (o !== f.tagName) {
1079
- let c = w(e, f.tagStartPos);
1080
- return p(
1081
- "InvalidTag",
1082
- "Expected closing tag '" + f.tagName + "' (opened in line " + c.line + ", col " + c.col + ") instead of closing tag '" + o + "'.",
1083
- w(e, a)
1084
- );
1085
- }
1086
- r.length == 0 && (n = !0);
1386
+ let tagName = "";
1387
+ for (; i < xmlData.length && xmlData[i] !== ">" && xmlData[i] !== " " && xmlData[i] !== " " && xmlData[i] !== "\n" && xmlData[i] !== "\r"; i++) {
1388
+ tagName += xmlData[i];
1389
+ }
1390
+ tagName = tagName.trim();
1391
+ if (tagName[tagName.length - 1] === "/") {
1392
+ tagName = tagName.substring(0, tagName.length - 1);
1393
+ i--;
1394
+ }
1395
+ if (!validateTagName(tagName)) {
1396
+ let msg;
1397
+ if (tagName.trim().length === 0) {
1398
+ msg = "Invalid space after '<'.";
1399
+ } else {
1400
+ msg = "Tag '" + tagName + "' is an invalid name.";
1401
+ }
1402
+ return getErrorObject("InvalidTag", msg, getLineNumberForPosition(xmlData, i));
1403
+ }
1404
+ const result = readAttributeStr(xmlData, i);
1405
+ if (result === false) {
1406
+ return getErrorObject("InvalidAttr", "Attributes for '" + tagName + "' have open quote.", getLineNumberForPosition(xmlData, i));
1407
+ }
1408
+ let attrStr = result.value;
1409
+ i = result.index;
1410
+ if (attrStr[attrStr.length - 1] === "/") {
1411
+ const attrStrStart = i - attrStr.length;
1412
+ attrStr = attrStr.substring(0, attrStr.length - 1);
1413
+ const isValid = validateAttributeString(attrStr, options);
1414
+ if (isValid === true) {
1415
+ tagFound = true;
1416
+ } else {
1417
+ return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, attrStrStart + isValid.err.line));
1418
+ }
1419
+ } else if (closingTag) {
1420
+ if (!result.tagClosed) {
1421
+ return getErrorObject("InvalidTag", "Closing tag '" + tagName + "' doesn't have proper closing.", getLineNumberForPosition(xmlData, i));
1422
+ } else if (attrStr.trim().length > 0) {
1423
+ return getErrorObject("InvalidTag", "Closing tag '" + tagName + "' can't have attributes or invalid starting.", getLineNumberForPosition(xmlData, tagStartPos));
1424
+ } else {
1425
+ const otg = tags.pop();
1426
+ if (tagName !== otg.tagName) {
1427
+ let openPos = getLineNumberForPosition(xmlData, otg.tagStartPos);
1428
+ return getErrorObject(
1429
+ "InvalidTag",
1430
+ "Expected closing tag '" + otg.tagName + "' (opened in line " + openPos.line + ", col " + openPos.col + ") instead of closing tag '" + tagName + "'.",
1431
+ getLineNumberForPosition(xmlData, tagStartPos)
1432
+ );
1087
1433
  }
1088
- } else
1089
- return p("InvalidTag", "Closing tag '" + o + "' doesn't have proper closing.", w(e, i));
1090
- else {
1091
- const f = Q(l, t);
1092
- if (f !== !0)
1093
- return p(f.err.code, f.err.msg, w(e, i - l.length + f.err.line));
1094
- if (n === !0)
1095
- return p("InvalidXml", "Multiple possible root nodes found.", w(e, i));
1096
- t.unpairedTags.indexOf(o) !== -1 || r.push({ tagName: o, tagStartPos: a }), s = !0;
1434
+ if (tags.length == 0) {
1435
+ reachedRoot = true;
1436
+ }
1437
+ }
1438
+ } else {
1439
+ const isValid = validateAttributeString(attrStr, options);
1440
+ if (isValid !== true) {
1441
+ return getErrorObject(isValid.err.code, isValid.err.msg, getLineNumberForPosition(xmlData, i - attrStr.length + isValid.err.line));
1442
+ }
1443
+ if (reachedRoot === true) {
1444
+ return getErrorObject("InvalidXml", "Multiple possible root nodes found.", getLineNumberForPosition(xmlData, i));
1445
+ } else if (options.unpairedTags.indexOf(tagName) !== -1)
1446
+ ;
1447
+ else {
1448
+ tags.push({ tagName, tagStartPos });
1449
+ }
1450
+ tagFound = true;
1097
1451
  }
1098
- for (i++; i < e.length; i++)
1099
- if (e[i] === "<")
1100
- if (e[i + 1] === "!") {
1101
- i++, i = J(e, i);
1452
+ for (i++; i < xmlData.length; i++) {
1453
+ if (xmlData[i] === "<") {
1454
+ if (xmlData[i + 1] === "!") {
1455
+ i++;
1456
+ i = readCommentAndCDATA(xmlData, i);
1102
1457
  continue;
1103
- } else if (e[i + 1] === "?") {
1104
- if (i = Y(e, ++i), i.err)
1458
+ } else if (xmlData[i + 1] === "?") {
1459
+ i = readPI(xmlData, ++i);
1460
+ if (i.err)
1105
1461
  return i;
1106
- } else
1462
+ } else {
1107
1463
  break;
1108
- else if (e[i] === "&") {
1109
- const f = Xe(e, i);
1110
- if (f == -1)
1111
- return p("InvalidChar", "char '&' is not expected.", w(e, i));
1112
- i = f;
1113
- } else if (n === !0 && !j(e[i]))
1114
- return p("InvalidXml", "Extra text at the end", w(e, i));
1115
- e[i] === "<" && i--;
1464
+ }
1465
+ } else if (xmlData[i] === "&") {
1466
+ const afterAmp = validateAmpersand(xmlData, i);
1467
+ if (afterAmp == -1)
1468
+ return getErrorObject("InvalidChar", "char '&' is not expected.", getLineNumberForPosition(xmlData, i));
1469
+ i = afterAmp;
1470
+ } else {
1471
+ if (reachedRoot === true && !isWhiteSpace(xmlData[i])) {
1472
+ return getErrorObject("InvalidXml", "Extra text at the end", getLineNumberForPosition(xmlData, i));
1473
+ }
1474
+ }
1475
+ }
1476
+ if (xmlData[i] === "<") {
1477
+ i--;
1478
+ }
1116
1479
  }
1117
1480
  } else {
1118
- if (j(e[i]))
1481
+ if (isWhiteSpace(xmlData[i])) {
1119
1482
  continue;
1120
- return p("InvalidChar", "char '" + e[i] + "' is not expected.", w(e, i));
1483
+ }
1484
+ return getErrorObject("InvalidChar", "char '" + xmlData[i] + "' is not expected.", getLineNumberForPosition(xmlData, i));
1121
1485
  }
1122
- if (s) {
1123
- if (r.length == 1)
1124
- return p("InvalidTag", "Unclosed tag '" + r[0].tagName + "'.", w(e, r[0].tagStartPos));
1125
- if (r.length > 0)
1126
- return p("InvalidXml", "Invalid '" + JSON.stringify(r.map((i) => i.tagName), null, 4).replace(/\r?\n/g, "") + "' found.", { line: 1, col: 1 });
1127
- } else
1128
- return p("InvalidXml", "Start tag expected.", 1);
1129
- return !0;
1486
+ }
1487
+ if (!tagFound) {
1488
+ return getErrorObject("InvalidXml", "Start tag expected.", 1);
1489
+ } else if (tags.length == 1) {
1490
+ return getErrorObject("InvalidTag", "Unclosed tag '" + tags[0].tagName + "'.", getLineNumberForPosition(xmlData, tags[0].tagStartPos));
1491
+ } else if (tags.length > 0) {
1492
+ return getErrorObject("InvalidXml", "Invalid '" + JSON.stringify(tags.map((t) => t.tagName), null, 4).replace(/\r?\n/g, "") + "' found.", { line: 1, col: 1 });
1493
+ }
1494
+ return true;
1130
1495
  };
1131
- function j(e) {
1132
- return e === " " || e === " " || e === `
1133
- ` || e === "\r";
1134
- }
1135
- function Y(e, t) {
1136
- const r = t;
1137
- for (; t < e.length; t++)
1138
- if (e[t] == "?" || e[t] == " ") {
1139
- const s = e.substr(r, t - r);
1140
- if (t > 5 && s === "xml")
1141
- return p("InvalidXml", "XML declaration allowed only at the start of the document.", w(e, t));
1142
- if (e[t] == "?" && e[t + 1] == ">") {
1143
- t++;
1496
+ function isWhiteSpace(char) {
1497
+ return char === " " || char === " " || char === "\n" || char === "\r";
1498
+ }
1499
+ function readPI(xmlData, i) {
1500
+ const start = i;
1501
+ for (; i < xmlData.length; i++) {
1502
+ if (xmlData[i] == "?" || xmlData[i] == " ") {
1503
+ const tagname = xmlData.substr(start, i - start);
1504
+ if (i > 5 && tagname === "xml") {
1505
+ return getErrorObject("InvalidXml", "XML declaration allowed only at the start of the document.", getLineNumberForPosition(xmlData, i));
1506
+ } else if (xmlData[i] == "?" && xmlData[i + 1] == ">") {
1507
+ i++;
1144
1508
  break;
1145
- } else
1509
+ } else {
1146
1510
  continue;
1511
+ }
1147
1512
  }
1148
- return t;
1513
+ }
1514
+ return i;
1149
1515
  }
1150
- function J(e, t) {
1151
- if (e.length > t + 5 && e[t + 1] === "-" && e[t + 2] === "-") {
1152
- for (t += 3; t < e.length; t++)
1153
- if (e[t] === "-" && e[t + 1] === "-" && e[t + 2] === ">") {
1154
- t += 2;
1516
+ function readCommentAndCDATA(xmlData, i) {
1517
+ if (xmlData.length > i + 5 && xmlData[i + 1] === "-" && xmlData[i + 2] === "-") {
1518
+ for (i += 3; i < xmlData.length; i++) {
1519
+ if (xmlData[i] === "-" && xmlData[i + 1] === "-" && xmlData[i + 2] === ">") {
1520
+ i += 2;
1155
1521
  break;
1156
1522
  }
1157
- } else if (e.length > t + 8 && e[t + 1] === "D" && e[t + 2] === "O" && e[t + 3] === "C" && e[t + 4] === "T" && e[t + 5] === "Y" && e[t + 6] === "P" && e[t + 7] === "E") {
1158
- let r = 1;
1159
- for (t += 8; t < e.length; t++)
1160
- if (e[t] === "<")
1161
- r++;
1162
- else if (e[t] === ">" && (r--, r === 0))
1163
- break;
1164
- } else if (e.length > t + 9 && e[t + 1] === "[" && e[t + 2] === "C" && e[t + 3] === "D" && e[t + 4] === "A" && e[t + 5] === "T" && e[t + 6] === "A" && e[t + 7] === "[") {
1165
- for (t += 8; t < e.length; t++)
1166
- if (e[t] === "]" && e[t + 1] === "]" && e[t + 2] === ">") {
1167
- t += 2;
1523
+ }
1524
+ } else if (xmlData.length > i + 8 && xmlData[i + 1] === "D" && xmlData[i + 2] === "O" && xmlData[i + 3] === "C" && xmlData[i + 4] === "T" && xmlData[i + 5] === "Y" && xmlData[i + 6] === "P" && xmlData[i + 7] === "E") {
1525
+ let angleBracketsCount = 1;
1526
+ for (i += 8; i < xmlData.length; i++) {
1527
+ if (xmlData[i] === "<") {
1528
+ angleBracketsCount++;
1529
+ } else if (xmlData[i] === ">") {
1530
+ angleBracketsCount--;
1531
+ if (angleBracketsCount === 0) {
1532
+ break;
1533
+ }
1534
+ }
1535
+ }
1536
+ } else if (xmlData.length > i + 9 && xmlData[i + 1] === "[" && xmlData[i + 2] === "C" && xmlData[i + 3] === "D" && xmlData[i + 4] === "A" && xmlData[i + 5] === "T" && xmlData[i + 6] === "A" && xmlData[i + 7] === "[") {
1537
+ for (i += 8; i < xmlData.length; i++) {
1538
+ if (xmlData[i] === "]" && xmlData[i + 1] === "]" && xmlData[i + 2] === ">") {
1539
+ i += 2;
1168
1540
  break;
1169
1541
  }
1542
+ }
1170
1543
  }
1171
- return t;
1544
+ return i;
1172
1545
  }
1173
- const Me = '"', Be = "'";
1174
- function ke(e, t) {
1175
- let r = "", s = "", n = !1;
1176
- for (; t < e.length; t++) {
1177
- if (e[t] === Me || e[t] === Be)
1178
- s === "" ? s = e[t] : s !== e[t] || (s = "");
1179
- else if (e[t] === ">" && s === "") {
1180
- n = !0;
1181
- break;
1546
+ const doubleQuote = '"';
1547
+ const singleQuote = "'";
1548
+ function readAttributeStr(xmlData, i) {
1549
+ let attrStr = "";
1550
+ let startChar = "";
1551
+ let tagClosed = false;
1552
+ for (; i < xmlData.length; i++) {
1553
+ if (xmlData[i] === doubleQuote || xmlData[i] === singleQuote) {
1554
+ if (startChar === "") {
1555
+ startChar = xmlData[i];
1556
+ } else if (startChar !== xmlData[i])
1557
+ ;
1558
+ else {
1559
+ startChar = "";
1560
+ }
1561
+ } else if (xmlData[i] === ">") {
1562
+ if (startChar === "") {
1563
+ tagClosed = true;
1564
+ break;
1565
+ }
1182
1566
  }
1183
- r += e[t];
1567
+ attrStr += xmlData[i];
1568
+ }
1569
+ if (startChar !== "") {
1570
+ return false;
1184
1571
  }
1185
- return s !== "" ? !1 : {
1186
- value: r,
1187
- index: t,
1188
- tagClosed: n
1572
+ return {
1573
+ value: attrStr,
1574
+ index: i,
1575
+ tagClosed
1189
1576
  };
1190
1577
  }
1191
- const qe = new RegExp(`(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['"])(([\\s\\S])*?)\\5)?`, "g");
1192
- function Q(e, t) {
1193
- const r = H.getAllMatches(e, qe), s = {};
1194
- for (let n = 0; n < r.length; n++) {
1195
- if (r[n][1].length === 0)
1196
- return p("InvalidAttr", "Attribute '" + r[n][2] + "' has no space in starting.", I(r[n]));
1197
- if (r[n][3] !== void 0 && r[n][4] === void 0)
1198
- return p("InvalidAttr", "Attribute '" + r[n][2] + "' is without value.", I(r[n]));
1199
- if (r[n][3] === void 0 && !t.allowBooleanAttributes)
1200
- return p("InvalidAttr", "boolean attribute '" + r[n][2] + "' is not allowed.", I(r[n]));
1201
- const i = r[n][2];
1202
- if (!Ge(i))
1203
- return p("InvalidAttr", "Attribute '" + i + "' is an invalid name.", I(r[n]));
1204
- if (!s.hasOwnProperty(i))
1205
- s[i] = 1;
1206
- else
1207
- return p("InvalidAttr", "Attribute '" + i + "' is repeated.", I(r[n]));
1578
+ const validAttrStrRegxp = new RegExp(`(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['"])(([\\s\\S])*?)\\5)?`, "g");
1579
+ function validateAttributeString(attrStr, options) {
1580
+ const matches = util$2.getAllMatches(attrStr, validAttrStrRegxp);
1581
+ const attrNames = {};
1582
+ for (let i = 0; i < matches.length; i++) {
1583
+ if (matches[i][1].length === 0) {
1584
+ return getErrorObject("InvalidAttr", "Attribute '" + matches[i][2] + "' has no space in starting.", getPositionFromMatch(matches[i]));
1585
+ } else if (matches[i][3] !== void 0 && matches[i][4] === void 0) {
1586
+ return getErrorObject("InvalidAttr", "Attribute '" + matches[i][2] + "' is without value.", getPositionFromMatch(matches[i]));
1587
+ } else if (matches[i][3] === void 0 && !options.allowBooleanAttributes) {
1588
+ return getErrorObject("InvalidAttr", "boolean attribute '" + matches[i][2] + "' is not allowed.", getPositionFromMatch(matches[i]));
1589
+ }
1590
+ const attrName = matches[i][2];
1591
+ if (!validateAttrName(attrName)) {
1592
+ return getErrorObject("InvalidAttr", "Attribute '" + attrName + "' is an invalid name.", getPositionFromMatch(matches[i]));
1593
+ }
1594
+ if (!attrNames.hasOwnProperty(attrName)) {
1595
+ attrNames[attrName] = 1;
1596
+ } else {
1597
+ return getErrorObject("InvalidAttr", "Attribute '" + attrName + "' is repeated.", getPositionFromMatch(matches[i]));
1598
+ }
1208
1599
  }
1209
- return !0;
1600
+ return true;
1210
1601
  }
1211
- function Ue(e, t) {
1212
- let r = /\d/;
1213
- for (e[t] === "x" && (t++, r = /[\da-fA-F]/); t < e.length; t++) {
1214
- if (e[t] === ";")
1215
- return t;
1216
- if (!e[t].match(r))
1602
+ function validateNumberAmpersand(xmlData, i) {
1603
+ let re = /\d/;
1604
+ if (xmlData[i] === "x") {
1605
+ i++;
1606
+ re = /[\da-fA-F]/;
1607
+ }
1608
+ for (; i < xmlData.length; i++) {
1609
+ if (xmlData[i] === ";")
1610
+ return i;
1611
+ if (!xmlData[i].match(re))
1217
1612
  break;
1218
1613
  }
1219
1614
  return -1;
1220
1615
  }
1221
- function Xe(e, t) {
1222
- if (t++, e[t] === ";")
1616
+ function validateAmpersand(xmlData, i) {
1617
+ i++;
1618
+ if (xmlData[i] === ";")
1223
1619
  return -1;
1224
- if (e[t] === "#")
1225
- return t++, Ue(e, t);
1226
- let r = 0;
1227
- for (; t < e.length; t++, r++)
1228
- if (!(e[t].match(/\w/) && r < 20)) {
1229
- if (e[t] === ";")
1230
- break;
1231
- return -1;
1232
- }
1233
- return t;
1620
+ if (xmlData[i] === "#") {
1621
+ i++;
1622
+ return validateNumberAmpersand(xmlData, i);
1623
+ }
1624
+ let count = 0;
1625
+ for (; i < xmlData.length; i++, count++) {
1626
+ if (xmlData[i].match(/\w/) && count < 20)
1627
+ continue;
1628
+ if (xmlData[i] === ";")
1629
+ break;
1630
+ return -1;
1631
+ }
1632
+ return i;
1234
1633
  }
1235
- function p(e, t, r) {
1634
+ function getErrorObject(code, message, lineNumber) {
1236
1635
  return {
1237
1636
  err: {
1238
- code: e,
1239
- msg: t,
1240
- line: r.line || r,
1241
- col: r.col
1637
+ code,
1638
+ msg: message,
1639
+ line: lineNumber.line || lineNumber,
1640
+ col: lineNumber.col
1242
1641
  }
1243
1642
  };
1244
1643
  }
1245
- function Ge(e) {
1246
- return H.isName(e);
1644
+ function validateAttrName(attrName) {
1645
+ return util$2.isName(attrName);
1247
1646
  }
1248
- function He(e) {
1249
- return H.isName(e);
1647
+ function validateTagName(tagname) {
1648
+ return util$2.isName(tagname);
1250
1649
  }
1251
- function w(e, t) {
1252
- const r = e.substring(0, t).split(/\r?\n/);
1650
+ function getLineNumberForPosition(xmlData, index) {
1651
+ const lines = xmlData.substring(0, index).split(/\r?\n/);
1253
1652
  return {
1254
- line: r.length,
1653
+ line: lines.length,
1255
1654
  // column number is last line's length + 1, because column numbering starts at 1:
1256
- col: r[r.length - 1].length + 1
1655
+ col: lines[lines.length - 1].length + 1
1257
1656
  };
1258
1657
  }
1259
- function I(e) {
1260
- return e.startIndex + e[1].length;
1658
+ function getPositionFromMatch(match) {
1659
+ return match.startIndex + match[1].length;
1261
1660
  }
1262
- var z = {};
1263
- const de = {
1264
- preserveOrder: !1,
1661
+ var OptionsBuilder = {};
1662
+ const defaultOptions$1 = {
1663
+ preserveOrder: false,
1265
1664
  attributeNamePrefix: "@_",
1266
- attributesGroupName: !1,
1665
+ attributesGroupName: false,
1267
1666
  textNodeName: "#text",
1268
- ignoreAttributes: !0,
1269
- removeNSPrefix: !1,
1667
+ ignoreAttributes: true,
1668
+ removeNSPrefix: false,
1270
1669
  // remove NS from tag name or attribute name if true
1271
- allowBooleanAttributes: !1,
1670
+ allowBooleanAttributes: false,
1272
1671
  //a tag can have attributes without any value
1273
1672
  //ignoreRootElement : false,
1274
- parseTagValue: !0,
1275
- parseAttributeValue: !1,
1276
- trimValues: !0,
1673
+ parseTagValue: true,
1674
+ parseAttributeValue: false,
1675
+ trimValues: true,
1277
1676
  //Trim string values of tag and attributes
1278
- cdataPropName: !1,
1677
+ cdataPropName: false,
1279
1678
  numberParseOptions: {
1280
- hex: !0,
1281
- leadingZeros: !0,
1282
- eNotation: !0
1679
+ hex: true,
1680
+ leadingZeros: true,
1681
+ eNotation: true
1283
1682
  },
1284
- tagValueProcessor: function(e, t) {
1285
- return t;
1683
+ tagValueProcessor: function(tagName, val2) {
1684
+ return val2;
1286
1685
  },
1287
- attributeValueProcessor: function(e, t) {
1288
- return t;
1686
+ attributeValueProcessor: function(attrName, val2) {
1687
+ return val2;
1289
1688
  },
1290
1689
  stopNodes: [],
1291
1690
  //nested tags will not be parsed even for errors
1292
- alwaysCreateTextNode: !1,
1293
- isArray: () => !1,
1294
- commentPropName: !1,
1691
+ alwaysCreateTextNode: false,
1692
+ isArray: () => false,
1693
+ commentPropName: false,
1295
1694
  unpairedTags: [],
1296
- processEntities: !0,
1297
- htmlEntities: !1,
1298
- ignoreDeclaration: !1,
1299
- ignorePiTags: !1,
1300
- transformTagName: !1,
1301
- transformAttributeName: !1,
1302
- updateTag: function(e, t, r) {
1303
- return e;
1695
+ processEntities: true,
1696
+ htmlEntities: false,
1697
+ ignoreDeclaration: false,
1698
+ ignorePiTags: false,
1699
+ transformTagName: false,
1700
+ transformAttributeName: false,
1701
+ updateTag: function(tagName, jPath, attrs) {
1702
+ return tagName;
1304
1703
  }
1305
1704
  // skipEmptyListItem: false
1306
- }, ze = function(e) {
1307
- return Object.assign({}, de, e);
1308
1705
  };
1309
- z.buildOptions = ze;
1310
- z.defaultOptions = de;
1311
- class Ke {
1312
- constructor(t) {
1313
- this.tagname = t, this.child = [], this[":@"] = {};
1314
- }
1315
- add(t, r) {
1316
- t === "__proto__" && (t = "#__proto__"), this.child.push({ [t]: r });
1317
- }
1318
- addChild(t) {
1319
- t.tagname === "__proto__" && (t.tagname = "#__proto__"), t[":@"] && Object.keys(t[":@"]).length > 0 ? this.child.push({ [t.tagname]: t.child, ":@": t[":@"] }) : this.child.push({ [t.tagname]: t.child });
1320
- }
1321
- }
1322
- var We = Ke;
1323
- const Ze = F;
1324
- function je(e, t) {
1325
- const r = {};
1326
- if (e[t + 3] === "O" && e[t + 4] === "C" && e[t + 5] === "T" && e[t + 6] === "Y" && e[t + 7] === "P" && e[t + 8] === "E") {
1327
- t = t + 9;
1328
- let s = 1, n = !1, i = !1, a = "";
1329
- for (; t < e.length; t++)
1330
- if (e[t] === "<" && !i) {
1331
- if (n && Qe(e, t))
1332
- t += 7, [entityName, val, t] = Ye(e, t + 1), val.indexOf("&") === -1 && (r[rt(entityName)] = {
1333
- regx: RegExp(`&${entityName};`, "g"),
1334
- val
1335
- });
1336
- else if (n && De(e, t))
1337
- t += 8;
1338
- else if (n && et(e, t))
1339
- t += 8;
1340
- else if (n && tt(e, t))
1341
- t += 9;
1342
- else if (Je)
1343
- i = !0;
1706
+ const buildOptions$1 = function(options) {
1707
+ return Object.assign({}, defaultOptions$1, options);
1708
+ };
1709
+ OptionsBuilder.buildOptions = buildOptions$1;
1710
+ OptionsBuilder.defaultOptions = defaultOptions$1;
1711
+ class XmlNode {
1712
+ constructor(tagname) {
1713
+ this.tagname = tagname;
1714
+ this.child = [];
1715
+ this[":@"] = {};
1716
+ }
1717
+ add(key, val2) {
1718
+ if (key === "__proto__")
1719
+ key = "#__proto__";
1720
+ this.child.push({ [key]: val2 });
1721
+ }
1722
+ addChild(node) {
1723
+ if (node.tagname === "__proto__")
1724
+ node.tagname = "#__proto__";
1725
+ if (node[":@"] && Object.keys(node[":@"]).length > 0) {
1726
+ this.child.push({ [node.tagname]: node.child, [":@"]: node[":@"] });
1727
+ } else {
1728
+ this.child.push({ [node.tagname]: node.child });
1729
+ }
1730
+ }
1731
+ }
1732
+ var xmlNode$1 = XmlNode;
1733
+ const util$1 = util$3;
1734
+ function readDocType$1(xmlData, i) {
1735
+ const entities = {};
1736
+ if (xmlData[i + 3] === "O" && xmlData[i + 4] === "C" && xmlData[i + 5] === "T" && xmlData[i + 6] === "Y" && xmlData[i + 7] === "P" && xmlData[i + 8] === "E") {
1737
+ i = i + 9;
1738
+ let angleBracketsCount = 1;
1739
+ let hasBody = false, comment = false;
1740
+ let exp = "";
1741
+ for (; i < xmlData.length; i++) {
1742
+ if (xmlData[i] === "<" && !comment) {
1743
+ if (hasBody && isEntity(xmlData, i)) {
1744
+ i += 7;
1745
+ [entityName, val, i] = readEntityExp(xmlData, i + 1);
1746
+ if (val.indexOf("&") === -1)
1747
+ entities[validateEntityName(entityName)] = {
1748
+ regx: RegExp(`&${entityName};`, "g"),
1749
+ val
1750
+ };
1751
+ } else if (hasBody && isElement(xmlData, i))
1752
+ i += 8;
1753
+ else if (hasBody && isAttlist(xmlData, i))
1754
+ i += 8;
1755
+ else if (hasBody && isNotation(xmlData, i))
1756
+ i += 9;
1757
+ else if (isComment)
1758
+ comment = true;
1344
1759
  else
1345
1760
  throw new Error("Invalid DOCTYPE");
1346
- s++, a = "";
1347
- } else if (e[t] === ">") {
1348
- if (i ? e[t - 1] === "-" && e[t - 2] === "-" && (i = !1, s--) : s--, s === 0)
1761
+ angleBracketsCount++;
1762
+ exp = "";
1763
+ } else if (xmlData[i] === ">") {
1764
+ if (comment) {
1765
+ if (xmlData[i - 1] === "-" && xmlData[i - 2] === "-") {
1766
+ comment = false;
1767
+ angleBracketsCount--;
1768
+ }
1769
+ } else {
1770
+ angleBracketsCount--;
1771
+ }
1772
+ if (angleBracketsCount === 0) {
1349
1773
  break;
1350
- } else
1351
- e[t] === "[" ? n = !0 : a += e[t];
1352
- if (s !== 0)
1353
- throw new Error("Unclosed DOCTYPE");
1354
- } else
1355
- throw new Error("Invalid Tag instead of DOCTYPE");
1356
- return { entities: r, i: t };
1357
- }
1358
- function Ye(e, t) {
1359
- let r = "";
1360
- for (; t < e.length && e[t] !== "'" && e[t] !== '"'; t++)
1361
- r += e[t];
1362
- if (r = r.trim(), r.indexOf(" ") !== -1)
1774
+ }
1775
+ } else if (xmlData[i] === "[") {
1776
+ hasBody = true;
1777
+ } else {
1778
+ exp += xmlData[i];
1779
+ }
1780
+ }
1781
+ if (angleBracketsCount !== 0) {
1782
+ throw new Error(`Unclosed DOCTYPE`);
1783
+ }
1784
+ } else {
1785
+ throw new Error(`Invalid Tag instead of DOCTYPE`);
1786
+ }
1787
+ return { entities, i };
1788
+ }
1789
+ function readEntityExp(xmlData, i) {
1790
+ let entityName2 = "";
1791
+ for (; i < xmlData.length && (xmlData[i] !== "'" && xmlData[i] !== '"'); i++) {
1792
+ entityName2 += xmlData[i];
1793
+ }
1794
+ entityName2 = entityName2.trim();
1795
+ if (entityName2.indexOf(" ") !== -1)
1363
1796
  throw new Error("External entites are not supported");
1364
- const s = e[t++];
1365
- let n = "";
1366
- for (; t < e.length && e[t] !== s; t++)
1367
- n += e[t];
1368
- return [r, n, t];
1369
- }
1370
- function Je(e, t) {
1371
- return e[t + 1] === "!" && e[t + 2] === "-" && e[t + 3] === "-";
1372
- }
1373
- function Qe(e, t) {
1374
- return e[t + 1] === "!" && e[t + 2] === "E" && e[t + 3] === "N" && e[t + 4] === "T" && e[t + 5] === "I" && e[t + 6] === "T" && e[t + 7] === "Y";
1375
- }
1376
- function De(e, t) {
1377
- return e[t + 1] === "!" && e[t + 2] === "E" && e[t + 3] === "L" && e[t + 4] === "E" && e[t + 5] === "M" && e[t + 6] === "E" && e[t + 7] === "N" && e[t + 8] === "T";
1378
- }
1379
- function et(e, t) {
1380
- return e[t + 1] === "!" && e[t + 2] === "A" && e[t + 3] === "T" && e[t + 4] === "T" && e[t + 5] === "L" && e[t + 6] === "I" && e[t + 7] === "S" && e[t + 8] === "T";
1381
- }
1382
- function tt(e, t) {
1383
- return e[t + 1] === "!" && e[t + 2] === "N" && e[t + 3] === "O" && e[t + 4] === "T" && e[t + 5] === "A" && e[t + 6] === "T" && e[t + 7] === "I" && e[t + 8] === "O" && e[t + 9] === "N";
1384
- }
1385
- function rt(e) {
1386
- if (Ze.isName(e))
1387
- return e;
1388
- throw new Error(`Invalid entity name ${e}`);
1389
- }
1390
- var nt = je;
1391
- const it = /^[-+]?0x[a-fA-F0-9]+$/, st = /^([\-\+])?(0*)(\.[0-9]+([eE]\-?[0-9]+)?|[0-9]+(\.[0-9]+([eE]\-?[0-9]+)?)?)$/;
1392
- !Number.parseInt && window.parseInt && (Number.parseInt = window.parseInt);
1393
- !Number.parseFloat && window.parseFloat && (Number.parseFloat = window.parseFloat);
1394
- const ot = {
1395
- hex: !0,
1396
- leadingZeros: !0,
1797
+ const startChar = xmlData[i++];
1798
+ let val2 = "";
1799
+ for (; i < xmlData.length && xmlData[i] !== startChar; i++) {
1800
+ val2 += xmlData[i];
1801
+ }
1802
+ return [entityName2, val2, i];
1803
+ }
1804
+ function isComment(xmlData, i) {
1805
+ if (xmlData[i + 1] === "!" && xmlData[i + 2] === "-" && xmlData[i + 3] === "-")
1806
+ return true;
1807
+ return false;
1808
+ }
1809
+ function isEntity(xmlData, i) {
1810
+ if (xmlData[i + 1] === "!" && xmlData[i + 2] === "E" && xmlData[i + 3] === "N" && xmlData[i + 4] === "T" && xmlData[i + 5] === "I" && xmlData[i + 6] === "T" && xmlData[i + 7] === "Y")
1811
+ return true;
1812
+ return false;
1813
+ }
1814
+ function isElement(xmlData, i) {
1815
+ if (xmlData[i + 1] === "!" && xmlData[i + 2] === "E" && xmlData[i + 3] === "L" && xmlData[i + 4] === "E" && xmlData[i + 5] === "M" && xmlData[i + 6] === "E" && xmlData[i + 7] === "N" && xmlData[i + 8] === "T")
1816
+ return true;
1817
+ return false;
1818
+ }
1819
+ function isAttlist(xmlData, i) {
1820
+ if (xmlData[i + 1] === "!" && xmlData[i + 2] === "A" && xmlData[i + 3] === "T" && xmlData[i + 4] === "T" && xmlData[i + 5] === "L" && xmlData[i + 6] === "I" && xmlData[i + 7] === "S" && xmlData[i + 8] === "T")
1821
+ return true;
1822
+ return false;
1823
+ }
1824
+ function isNotation(xmlData, i) {
1825
+ if (xmlData[i + 1] === "!" && xmlData[i + 2] === "N" && xmlData[i + 3] === "O" && xmlData[i + 4] === "T" && xmlData[i + 5] === "A" && xmlData[i + 6] === "T" && xmlData[i + 7] === "I" && xmlData[i + 8] === "O" && xmlData[i + 9] === "N")
1826
+ return true;
1827
+ return false;
1828
+ }
1829
+ function validateEntityName(name) {
1830
+ if (util$1.isName(name))
1831
+ return name;
1832
+ else
1833
+ throw new Error(`Invalid entity name ${name}`);
1834
+ }
1835
+ var DocTypeReader = readDocType$1;
1836
+ const hexRegex = /^[-+]?0x[a-fA-F0-9]+$/;
1837
+ const numRegex = /^([\-\+])?(0*)(\.[0-9]+([eE]\-?[0-9]+)?|[0-9]+(\.[0-9]+([eE]\-?[0-9]+)?)?)$/;
1838
+ if (!Number.parseInt && window.parseInt) {
1839
+ Number.parseInt = window.parseInt;
1840
+ }
1841
+ if (!Number.parseFloat && window.parseFloat) {
1842
+ Number.parseFloat = window.parseFloat;
1843
+ }
1844
+ const consider = {
1845
+ hex: true,
1846
+ leadingZeros: true,
1397
1847
  decimalPoint: ".",
1398
- eNotation: !0
1848
+ eNotation: true
1399
1849
  //skipLike: /regex/
1400
1850
  };
1401
- function ut(e, t = {}) {
1402
- if (t = Object.assign({}, ot, t), !e || typeof e != "string")
1403
- return e;
1404
- let r = e.trim();
1405
- if (t.skipLike !== void 0 && t.skipLike.test(r))
1406
- return e;
1407
- if (t.hex && it.test(r))
1408
- return Number.parseInt(r, 16);
1409
- {
1410
- const s = st.exec(r);
1411
- if (s) {
1412
- const n = s[1], i = s[2];
1413
- let a = at(s[3]);
1414
- const u = s[4] || s[6];
1415
- if (!t.leadingZeros && i.length > 0 && n && r[2] !== ".")
1416
- return e;
1417
- if (!t.leadingZeros && i.length > 0 && !n && r[1] !== ".")
1418
- return e;
1419
- {
1420
- const o = Number(r), d = "" + o;
1421
- return d.search(/[eE]/) !== -1 || u ? t.eNotation ? o : e : r.indexOf(".") !== -1 ? d === "0" && a === "" || d === a || n && d === "-" + a ? o : e : i ? a === d || n + a === d ? o : e : r === d || r === n + d ? o : e;
1851
+ function toNumber$1(str, options = {}) {
1852
+ options = Object.assign({}, consider, options);
1853
+ if (!str || typeof str !== "string")
1854
+ return str;
1855
+ let trimmedStr = str.trim();
1856
+ if (options.skipLike !== void 0 && options.skipLike.test(trimmedStr))
1857
+ return str;
1858
+ else if (options.hex && hexRegex.test(trimmedStr)) {
1859
+ return Number.parseInt(trimmedStr, 16);
1860
+ } else {
1861
+ const match = numRegex.exec(trimmedStr);
1862
+ if (match) {
1863
+ const sign = match[1];
1864
+ const leadingZeros = match[2];
1865
+ let numTrimmedByZeros = trimZeros(match[3]);
1866
+ const eNotation = match[4] || match[6];
1867
+ if (!options.leadingZeros && leadingZeros.length > 0 && sign && trimmedStr[2] !== ".")
1868
+ return str;
1869
+ else if (!options.leadingZeros && leadingZeros.length > 0 && !sign && trimmedStr[1] !== ".")
1870
+ return str;
1871
+ else {
1872
+ const num = Number(trimmedStr);
1873
+ const numStr = "" + num;
1874
+ if (numStr.search(/[eE]/) !== -1) {
1875
+ if (options.eNotation)
1876
+ return num;
1877
+ else
1878
+ return str;
1879
+ } else if (eNotation) {
1880
+ if (options.eNotation)
1881
+ return num;
1882
+ else
1883
+ return str;
1884
+ } else if (trimmedStr.indexOf(".") !== -1) {
1885
+ if (numStr === "0" && numTrimmedByZeros === "")
1886
+ return num;
1887
+ else if (numStr === numTrimmedByZeros)
1888
+ return num;
1889
+ else if (sign && numStr === "-" + numTrimmedByZeros)
1890
+ return num;
1891
+ else
1892
+ return str;
1893
+ }
1894
+ if (leadingZeros) {
1895
+ if (numTrimmedByZeros === numStr)
1896
+ return num;
1897
+ else if (sign + numTrimmedByZeros === numStr)
1898
+ return num;
1899
+ else
1900
+ return str;
1901
+ }
1902
+ if (trimmedStr === numStr)
1903
+ return num;
1904
+ else if (trimmedStr === sign + numStr)
1905
+ return num;
1906
+ return str;
1422
1907
  }
1423
- } else
1424
- return e;
1425
- }
1426
- }
1427
- function at(e) {
1428
- return e && e.indexOf(".") !== -1 && (e = e.replace(/0+$/, ""), e === "." ? e = "0" : e[0] === "." ? e = "0" + e : e[e.length - 1] === "." && (e = e.substr(0, e.length - 1))), e;
1429
- }
1430
- var dt = ut;
1431
- const le = F, A = We, lt = nt, ft = dt;
1432
- let ct = class {
1433
- constructor(t) {
1434
- this.options = t, this.currentNode = null, this.tagsNodeStack = [], this.docTypeEntities = {}, this.lastEntities = {
1435
- apos: { regex: /&(apos|#39|#x27);/g, val: "'" },
1436
- gt: { regex: /&(gt|#62|#x3E);/g, val: ">" },
1437
- lt: { regex: /&(lt|#60|#x3C);/g, val: "<" },
1438
- quot: { regex: /&(quot|#34|#x22);/g, val: '"' }
1439
- }, this.ampEntity = { regex: /&(amp|#38|#x26);/g, val: "&" }, this.htmlEntities = {
1440
- space: { regex: /&(nbsp|#160);/g, val: " " },
1908
+ } else {
1909
+ return str;
1910
+ }
1911
+ }
1912
+ }
1913
+ function trimZeros(numStr) {
1914
+ if (numStr && numStr.indexOf(".") !== -1) {
1915
+ numStr = numStr.replace(/0+$/, "");
1916
+ if (numStr === ".")
1917
+ numStr = "0";
1918
+ else if (numStr[0] === ".")
1919
+ numStr = "0" + numStr;
1920
+ else if (numStr[numStr.length - 1] === ".")
1921
+ numStr = numStr.substr(0, numStr.length - 1);
1922
+ return numStr;
1923
+ }
1924
+ return numStr;
1925
+ }
1926
+ var strnum = toNumber$1;
1927
+ const util = util$3;
1928
+ const xmlNode = xmlNode$1;
1929
+ const readDocType = DocTypeReader;
1930
+ const toNumber = strnum;
1931
+ let OrderedObjParser$1 = class OrderedObjParser {
1932
+ constructor(options) {
1933
+ this.options = options;
1934
+ this.currentNode = null;
1935
+ this.tagsNodeStack = [];
1936
+ this.docTypeEntities = {};
1937
+ this.lastEntities = {
1938
+ "apos": { regex: /&(apos|#39|#x27);/g, val: "'" },
1939
+ "gt": { regex: /&(gt|#62|#x3E);/g, val: ">" },
1940
+ "lt": { regex: /&(lt|#60|#x3C);/g, val: "<" },
1941
+ "quot": { regex: /&(quot|#34|#x22);/g, val: '"' }
1942
+ };
1943
+ this.ampEntity = { regex: /&(amp|#38|#x26);/g, val: "&" };
1944
+ this.htmlEntities = {
1945
+ "space": { regex: /&(nbsp|#160);/g, val: " " },
1441
1946
  // "lt" : { regex: /&(lt|#60);/g, val: "<" },
1442
1947
  // "gt" : { regex: /&(gt|#62);/g, val: ">" },
1443
1948
  // "amp" : { regex: /&(amp|#38);/g, val: "&" },
1444
1949
  // "quot" : { regex: /&(quot|#34);/g, val: "\"" },
1445
1950
  // "apos" : { regex: /&(apos|#39);/g, val: "'" },
1446
- cent: { regex: /&(cent|#162);/g, val: "¢" },
1447
- pound: { regex: /&(pound|#163);/g, val: "£" },
1448
- yen: { regex: /&(yen|#165);/g, val: "¥" },
1449
- euro: { regex: /&(euro|#8364);/g, val: "€" },
1450
- copyright: { regex: /&(copy|#169);/g, val: "©" },
1451
- reg: { regex: /&(reg|#174);/g, val: "®" },
1452
- inr: { regex: /&(inr|#8377);/g, val: "₹" },
1453
- num_dec: { regex: /&#([0-9]{1,7});/g, val: (r, s) => String.fromCharCode(Number.parseInt(s, 10)) },
1454
- num_hex: { regex: /&#x([0-9a-fA-F]{1,6});/g, val: (r, s) => String.fromCharCode(Number.parseInt(s, 16)) }
1455
- }, this.addExternalEntities = ht, this.parseXml = Nt, this.parseTextData = pt, this.resolveNameSpace = gt, this.buildAttributesMap = mt, this.isItStopNode = vt, this.replaceEntitiesValue = bt, this.readStopNodeData = Tt, this.saveTextToParentTag = yt, this.addChild = Et;
1951
+ "cent": { regex: /&(cent|#162);/g, val: "¢" },
1952
+ "pound": { regex: /&(pound|#163);/g, val: "£" },
1953
+ "yen": { regex: /&(yen|#165);/g, val: "¥" },
1954
+ "euro": { regex: /&(euro|#8364);/g, val: "€" },
1955
+ "copyright": { regex: /&(copy|#169);/g, val: "©" },
1956
+ "reg": { regex: /&(reg|#174);/g, val: "®" },
1957
+ "inr": { regex: /&(inr|#8377);/g, val: "₹" },
1958
+ "num_dec": { regex: /&#([0-9]{1,7});/g, val: (_, str) => String.fromCharCode(Number.parseInt(str, 10)) },
1959
+ "num_hex": { regex: /&#x([0-9a-fA-F]{1,6});/g, val: (_, str) => String.fromCharCode(Number.parseInt(str, 16)) }
1960
+ };
1961
+ this.addExternalEntities = addExternalEntities;
1962
+ this.parseXml = parseXml;
1963
+ this.parseTextData = parseTextData;
1964
+ this.resolveNameSpace = resolveNameSpace;
1965
+ this.buildAttributesMap = buildAttributesMap;
1966
+ this.isItStopNode = isItStopNode;
1967
+ this.replaceEntitiesValue = replaceEntitiesValue$1;
1968
+ this.readStopNodeData = readStopNodeData;
1969
+ this.saveTextToParentTag = saveTextToParentTag;
1970
+ this.addChild = addChild;
1456
1971
  }
1457
1972
  };
1458
- function ht(e) {
1459
- const t = Object.keys(e);
1460
- for (let r = 0; r < t.length; r++) {
1461
- const s = t[r];
1462
- this.lastEntities[s] = {
1463
- regex: new RegExp("&" + s + ";", "g"),
1464
- val: e[s]
1973
+ function addExternalEntities(externalEntities) {
1974
+ const entKeys = Object.keys(externalEntities);
1975
+ for (let i = 0; i < entKeys.length; i++) {
1976
+ const ent = entKeys[i];
1977
+ this.lastEntities[ent] = {
1978
+ regex: new RegExp("&" + ent + ";", "g"),
1979
+ val: externalEntities[ent]
1465
1980
  };
1466
1981
  }
1467
1982
  }
1468
- function pt(e, t, r, s, n, i, a) {
1469
- if (e !== void 0 && (this.options.trimValues && !s && (e = e.trim()), e.length > 0)) {
1470
- a || (e = this.replaceEntitiesValue(e));
1471
- const u = this.options.tagValueProcessor(t, e, r, n, i);
1472
- return u == null ? e : typeof u != typeof e || u !== e ? u : this.options.trimValues ? V(e, this.options.parseTagValue, this.options.numberParseOptions) : e.trim() === e ? V(e, this.options.parseTagValue, this.options.numberParseOptions) : e;
1983
+ function parseTextData(val2, tagName, jPath, dontTrim, hasAttributes, isLeafNode, escapeEntities) {
1984
+ if (val2 !== void 0) {
1985
+ if (this.options.trimValues && !dontTrim) {
1986
+ val2 = val2.trim();
1987
+ }
1988
+ if (val2.length > 0) {
1989
+ if (!escapeEntities)
1990
+ val2 = this.replaceEntitiesValue(val2);
1991
+ const newval = this.options.tagValueProcessor(tagName, val2, jPath, hasAttributes, isLeafNode);
1992
+ if (newval === null || newval === void 0) {
1993
+ return val2;
1994
+ } else if (typeof newval !== typeof val2 || newval !== val2) {
1995
+ return newval;
1996
+ } else if (this.options.trimValues) {
1997
+ return parseValue(val2, this.options.parseTagValue, this.options.numberParseOptions);
1998
+ } else {
1999
+ const trimmedVal = val2.trim();
2000
+ if (trimmedVal === val2) {
2001
+ return parseValue(val2, this.options.parseTagValue, this.options.numberParseOptions);
2002
+ } else {
2003
+ return val2;
2004
+ }
2005
+ }
2006
+ }
1473
2007
  }
1474
2008
  }
1475
- function gt(e) {
2009
+ function resolveNameSpace(tagname) {
1476
2010
  if (this.options.removeNSPrefix) {
1477
- const t = e.split(":"), r = e.charAt(0) === "/" ? "/" : "";
1478
- if (t[0] === "xmlns")
2011
+ const tags = tagname.split(":");
2012
+ const prefix = tagname.charAt(0) === "/" ? "/" : "";
2013
+ if (tags[0] === "xmlns") {
1479
2014
  return "";
1480
- t.length === 2 && (e = r + t[1]);
1481
- }
1482
- return e;
1483
- }
1484
- const wt = new RegExp(`([^\\s=]+)\\s*(=\\s*(['"])([\\s\\S]*?)\\3)?`, "gm");
1485
- function mt(e, t, r) {
1486
- if (!this.options.ignoreAttributes && typeof e == "string") {
1487
- const s = le.getAllMatches(e, wt), n = s.length, i = {};
1488
- for (let a = 0; a < n; a++) {
1489
- const u = this.resolveNameSpace(s[a][1]);
1490
- let o = s[a][4], d = this.options.attributeNamePrefix + u;
1491
- if (u.length)
1492
- if (this.options.transformAttributeName && (d = this.options.transformAttributeName(d)), d === "__proto__" && (d = "#__proto__"), o !== void 0) {
1493
- this.options.trimValues && (o = o.trim()), o = this.replaceEntitiesValue(o);
1494
- const l = this.options.attributeValueProcessor(u, o, t);
1495
- l == null ? i[d] = o : typeof l != typeof o || l !== o ? i[d] = l : i[d] = V(
1496
- o,
1497
- this.options.parseAttributeValue,
1498
- this.options.numberParseOptions
1499
- );
1500
- } else
1501
- this.options.allowBooleanAttributes && (i[d] = !0);
1502
- }
1503
- if (!Object.keys(i).length)
2015
+ }
2016
+ if (tags.length === 2) {
2017
+ tagname = prefix + tags[1];
2018
+ }
2019
+ }
2020
+ return tagname;
2021
+ }
2022
+ const attrsRegx = new RegExp(`([^\\s=]+)\\s*(=\\s*(['"])([\\s\\S]*?)\\3)?`, "gm");
2023
+ function buildAttributesMap(attrStr, jPath, tagName) {
2024
+ if (!this.options.ignoreAttributes && typeof attrStr === "string") {
2025
+ const matches = util.getAllMatches(attrStr, attrsRegx);
2026
+ const len = matches.length;
2027
+ const attrs = {};
2028
+ for (let i = 0; i < len; i++) {
2029
+ const attrName = this.resolveNameSpace(matches[i][1]);
2030
+ let oldVal = matches[i][4];
2031
+ let aName = this.options.attributeNamePrefix + attrName;
2032
+ if (attrName.length) {
2033
+ if (this.options.transformAttributeName) {
2034
+ aName = this.options.transformAttributeName(aName);
2035
+ }
2036
+ if (aName === "__proto__")
2037
+ aName = "#__proto__";
2038
+ if (oldVal !== void 0) {
2039
+ if (this.options.trimValues) {
2040
+ oldVal = oldVal.trim();
2041
+ }
2042
+ oldVal = this.replaceEntitiesValue(oldVal);
2043
+ const newVal = this.options.attributeValueProcessor(attrName, oldVal, jPath);
2044
+ if (newVal === null || newVal === void 0) {
2045
+ attrs[aName] = oldVal;
2046
+ } else if (typeof newVal !== typeof oldVal || newVal !== oldVal) {
2047
+ attrs[aName] = newVal;
2048
+ } else {
2049
+ attrs[aName] = parseValue(
2050
+ oldVal,
2051
+ this.options.parseAttributeValue,
2052
+ this.options.numberParseOptions
2053
+ );
2054
+ }
2055
+ } else if (this.options.allowBooleanAttributes) {
2056
+ attrs[aName] = true;
2057
+ }
2058
+ }
2059
+ }
2060
+ if (!Object.keys(attrs).length) {
1504
2061
  return;
2062
+ }
1505
2063
  if (this.options.attributesGroupName) {
1506
- const a = {};
1507
- return a[this.options.attributesGroupName] = i, a;
1508
- }
1509
- return i;
1510
- }
1511
- }
1512
- const Nt = function(e) {
1513
- e = e.replace(/\r\n?/g, `
1514
- `);
1515
- const t = new A("!xml");
1516
- let r = t, s = "", n = "";
1517
- for (let i = 0; i < e.length; i++)
1518
- if (e[i] === "<")
1519
- if (e[i + 1] === "/") {
1520
- const u = v(e, ">", i, "Closing Tag is not closed.");
1521
- let o = e.substring(i + 2, u).trim();
2064
+ const attrCollection = {};
2065
+ attrCollection[this.options.attributesGroupName] = attrs;
2066
+ return attrCollection;
2067
+ }
2068
+ return attrs;
2069
+ }
2070
+ }
2071
+ const parseXml = function(xmlData) {
2072
+ xmlData = xmlData.replace(/\r\n?/g, "\n");
2073
+ const xmlObj = new xmlNode("!xml");
2074
+ let currentNode = xmlObj;
2075
+ let textData = "";
2076
+ let jPath = "";
2077
+ for (let i = 0; i < xmlData.length; i++) {
2078
+ const ch = xmlData[i];
2079
+ if (ch === "<") {
2080
+ if (xmlData[i + 1] === "/") {
2081
+ const closeIndex = findClosingIndex(xmlData, ">", i, "Closing Tag is not closed.");
2082
+ let tagName = xmlData.substring(i + 2, closeIndex).trim();
1522
2083
  if (this.options.removeNSPrefix) {
1523
- const f = o.indexOf(":");
1524
- f !== -1 && (o = o.substr(f + 1));
2084
+ const colonIndex = tagName.indexOf(":");
2085
+ if (colonIndex !== -1) {
2086
+ tagName = tagName.substr(colonIndex + 1);
2087
+ }
2088
+ }
2089
+ if (this.options.transformTagName) {
2090
+ tagName = this.options.transformTagName(tagName);
1525
2091
  }
1526
- this.options.transformTagName && (o = this.options.transformTagName(o)), r && (s = this.saveTextToParentTag(s, r, n));
1527
- const d = n.substring(n.lastIndexOf(".") + 1);
1528
- if (o && this.options.unpairedTags.indexOf(o) !== -1)
1529
- throw new Error(`Unpaired tag can not be used as closing tag: </${o}>`);
1530
- let l = 0;
1531
- d && this.options.unpairedTags.indexOf(d) !== -1 ? (l = n.lastIndexOf(".", n.lastIndexOf(".") - 1), this.tagsNodeStack.pop()) : l = n.lastIndexOf("."), n = n.substring(0, l), r = this.tagsNodeStack.pop(), s = "", i = u;
1532
- } else if (e[i + 1] === "?") {
1533
- let u = S(e, i, !1, "?>");
1534
- if (!u)
2092
+ if (currentNode) {
2093
+ textData = this.saveTextToParentTag(textData, currentNode, jPath);
2094
+ }
2095
+ const lastTagName = jPath.substring(jPath.lastIndexOf(".") + 1);
2096
+ if (tagName && this.options.unpairedTags.indexOf(tagName) !== -1) {
2097
+ throw new Error(`Unpaired tag can not be used as closing tag: </${tagName}>`);
2098
+ }
2099
+ let propIndex = 0;
2100
+ if (lastTagName && this.options.unpairedTags.indexOf(lastTagName) !== -1) {
2101
+ propIndex = jPath.lastIndexOf(".", jPath.lastIndexOf(".") - 1);
2102
+ this.tagsNodeStack.pop();
2103
+ } else {
2104
+ propIndex = jPath.lastIndexOf(".");
2105
+ }
2106
+ jPath = jPath.substring(0, propIndex);
2107
+ currentNode = this.tagsNodeStack.pop();
2108
+ textData = "";
2109
+ i = closeIndex;
2110
+ } else if (xmlData[i + 1] === "?") {
2111
+ let tagData = readTagExp(xmlData, i, false, "?>");
2112
+ if (!tagData)
1535
2113
  throw new Error("Pi Tag is not closed.");
1536
- if (s = this.saveTextToParentTag(s, r, n), !(this.options.ignoreDeclaration && u.tagName === "?xml" || this.options.ignorePiTags)) {
1537
- const o = new A(u.tagName);
1538
- o.add(this.options.textNodeName, ""), u.tagName !== u.tagExp && u.attrExpPresent && (o[":@"] = this.buildAttributesMap(u.tagExp, n, u.tagName)), this.addChild(r, o, n);
2114
+ textData = this.saveTextToParentTag(textData, currentNode, jPath);
2115
+ if (this.options.ignoreDeclaration && tagData.tagName === "?xml" || this.options.ignorePiTags)
2116
+ ;
2117
+ else {
2118
+ const childNode = new xmlNode(tagData.tagName);
2119
+ childNode.add(this.options.textNodeName, "");
2120
+ if (tagData.tagName !== tagData.tagExp && tagData.attrExpPresent) {
2121
+ childNode[":@"] = this.buildAttributesMap(tagData.tagExp, jPath, tagData.tagName);
2122
+ }
2123
+ this.addChild(currentNode, childNode, jPath);
1539
2124
  }
1540
- i = u.closeIndex + 1;
1541
- } else if (e.substr(i + 1, 3) === "!--") {
1542
- const u = v(e, "-->", i + 4, "Comment is not closed.");
2125
+ i = tagData.closeIndex + 1;
2126
+ } else if (xmlData.substr(i + 1, 3) === "!--") {
2127
+ const endIndex = findClosingIndex(xmlData, "-->", i + 4, "Comment is not closed.");
1543
2128
  if (this.options.commentPropName) {
1544
- const o = e.substring(i + 4, u - 2);
1545
- s = this.saveTextToParentTag(s, r, n), r.add(this.options.commentPropName, [{ [this.options.textNodeName]: o }]);
2129
+ const comment = xmlData.substring(i + 4, endIndex - 2);
2130
+ textData = this.saveTextToParentTag(textData, currentNode, jPath);
2131
+ currentNode.add(this.options.commentPropName, [{ [this.options.textNodeName]: comment }]);
1546
2132
  }
1547
- i = u;
1548
- } else if (e.substr(i + 1, 2) === "!D") {
1549
- const u = lt(e, i);
1550
- this.docTypeEntities = u.entities, i = u.i;
1551
- } else if (e.substr(i + 1, 2) === "![") {
1552
- const u = v(e, "]]>", i, "CDATA is not closed.") - 2, o = e.substring(i + 9, u);
1553
- s = this.saveTextToParentTag(s, r, n);
1554
- let d = this.parseTextData(o, r.tagname, n, !0, !1, !0, !0);
1555
- d == null && (d = ""), this.options.cdataPropName ? r.add(this.options.cdataPropName, [{ [this.options.textNodeName]: o }]) : r.add(this.options.textNodeName, d), i = u + 2;
2133
+ i = endIndex;
2134
+ } else if (xmlData.substr(i + 1, 2) === "!D") {
2135
+ const result = readDocType(xmlData, i);
2136
+ this.docTypeEntities = result.entities;
2137
+ i = result.i;
2138
+ } else if (xmlData.substr(i + 1, 2) === "![") {
2139
+ const closeIndex = findClosingIndex(xmlData, "]]>", i, "CDATA is not closed.") - 2;
2140
+ const tagExp = xmlData.substring(i + 9, closeIndex);
2141
+ textData = this.saveTextToParentTag(textData, currentNode, jPath);
2142
+ let val2 = this.parseTextData(tagExp, currentNode.tagname, jPath, true, false, true, true);
2143
+ if (val2 == void 0)
2144
+ val2 = "";
2145
+ if (this.options.cdataPropName) {
2146
+ currentNode.add(this.options.cdataPropName, [{ [this.options.textNodeName]: tagExp }]);
2147
+ } else {
2148
+ currentNode.add(this.options.textNodeName, val2);
2149
+ }
2150
+ i = closeIndex + 2;
1556
2151
  } else {
1557
- let u = S(e, i, this.options.removeNSPrefix), o = u.tagName;
1558
- const d = u.rawTagName;
1559
- let l = u.tagExp, f = u.attrExpPresent, c = u.closeIndex;
1560
- this.options.transformTagName && (o = this.options.transformTagName(o)), r && s && r.tagname !== "!xml" && (s = this.saveTextToParentTag(s, r, n, !1));
1561
- const g = r;
1562
- if (g && this.options.unpairedTags.indexOf(g.tagname) !== -1 && (r = this.tagsNodeStack.pop(), n = n.substring(0, n.lastIndexOf("."))), o !== t.tagname && (n += n ? "." + o : o), this.isItStopNode(this.options.stopNodes, n, o)) {
1563
- let h = "";
1564
- if (l.length > 0 && l.lastIndexOf("/") === l.length - 1)
1565
- i = u.closeIndex;
1566
- else if (this.options.unpairedTags.indexOf(o) !== -1)
1567
- i = u.closeIndex;
1568
- else {
1569
- const E = this.readStopNodeData(e, d, c + 1);
1570
- if (!E)
1571
- throw new Error(`Unexpected end of ${d}`);
1572
- i = E.i, h = E.tagContent;
2152
+ let result = readTagExp(xmlData, i, this.options.removeNSPrefix);
2153
+ let tagName = result.tagName;
2154
+ const rawTagName = result.rawTagName;
2155
+ let tagExp = result.tagExp;
2156
+ let attrExpPresent = result.attrExpPresent;
2157
+ let closeIndex = result.closeIndex;
2158
+ if (this.options.transformTagName) {
2159
+ tagName = this.options.transformTagName(tagName);
2160
+ }
2161
+ if (currentNode && textData) {
2162
+ if (currentNode.tagname !== "!xml") {
2163
+ textData = this.saveTextToParentTag(textData, currentNode, jPath, false);
1573
2164
  }
1574
- const T = new A(o);
1575
- o !== l && f && (T[":@"] = this.buildAttributesMap(l, n, o)), h && (h = this.parseTextData(h, o, n, !0, f, !0, !0)), n = n.substr(0, n.lastIndexOf(".")), T.add(this.options.textNodeName, h), this.addChild(r, T, n);
2165
+ }
2166
+ const lastTag = currentNode;
2167
+ if (lastTag && this.options.unpairedTags.indexOf(lastTag.tagname) !== -1) {
2168
+ currentNode = this.tagsNodeStack.pop();
2169
+ jPath = jPath.substring(0, jPath.lastIndexOf("."));
2170
+ }
2171
+ if (tagName !== xmlObj.tagname) {
2172
+ jPath += jPath ? "." + tagName : tagName;
2173
+ }
2174
+ if (this.isItStopNode(this.options.stopNodes, jPath, tagName)) {
2175
+ let tagContent = "";
2176
+ if (tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1) {
2177
+ i = result.closeIndex;
2178
+ } else if (this.options.unpairedTags.indexOf(tagName) !== -1) {
2179
+ i = result.closeIndex;
2180
+ } else {
2181
+ const result2 = this.readStopNodeData(xmlData, rawTagName, closeIndex + 1);
2182
+ if (!result2)
2183
+ throw new Error(`Unexpected end of ${rawTagName}`);
2184
+ i = result2.i;
2185
+ tagContent = result2.tagContent;
2186
+ }
2187
+ const childNode = new xmlNode(tagName);
2188
+ if (tagName !== tagExp && attrExpPresent) {
2189
+ childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
2190
+ }
2191
+ if (tagContent) {
2192
+ tagContent = this.parseTextData(tagContent, tagName, jPath, true, attrExpPresent, true, true);
2193
+ }
2194
+ jPath = jPath.substr(0, jPath.lastIndexOf("."));
2195
+ childNode.add(this.options.textNodeName, tagContent);
2196
+ this.addChild(currentNode, childNode, jPath);
1576
2197
  } else {
1577
- if (l.length > 0 && l.lastIndexOf("/") === l.length - 1) {
1578
- o[o.length - 1] === "/" ? (o = o.substr(0, o.length - 1), n = n.substr(0, n.length - 1), l = o) : l = l.substr(0, l.length - 1), this.options.transformTagName && (o = this.options.transformTagName(o));
1579
- const h = new A(o);
1580
- o !== l && f && (h[":@"] = this.buildAttributesMap(l, n, o)), this.addChild(r, h, n), n = n.substr(0, n.lastIndexOf("."));
2198
+ if (tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1) {
2199
+ if (tagName[tagName.length - 1] === "/") {
2200
+ tagName = tagName.substr(0, tagName.length - 1);
2201
+ jPath = jPath.substr(0, jPath.length - 1);
2202
+ tagExp = tagName;
2203
+ } else {
2204
+ tagExp = tagExp.substr(0, tagExp.length - 1);
2205
+ }
2206
+ if (this.options.transformTagName) {
2207
+ tagName = this.options.transformTagName(tagName);
2208
+ }
2209
+ const childNode = new xmlNode(tagName);
2210
+ if (tagName !== tagExp && attrExpPresent) {
2211
+ childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
2212
+ }
2213
+ this.addChild(currentNode, childNode, jPath);
2214
+ jPath = jPath.substr(0, jPath.lastIndexOf("."));
1581
2215
  } else {
1582
- const h = new A(o);
1583
- this.tagsNodeStack.push(r), o !== l && f && (h[":@"] = this.buildAttributesMap(l, n, o)), this.addChild(r, h, n), r = h;
2216
+ const childNode = new xmlNode(tagName);
2217
+ this.tagsNodeStack.push(currentNode);
2218
+ if (tagName !== tagExp && attrExpPresent) {
2219
+ childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
2220
+ }
2221
+ this.addChild(currentNode, childNode, jPath);
2222
+ currentNode = childNode;
1584
2223
  }
1585
- s = "", i = c;
2224
+ textData = "";
2225
+ i = closeIndex;
1586
2226
  }
1587
2227
  }
1588
- else
1589
- s += e[i];
1590
- return t.child;
2228
+ } else {
2229
+ textData += xmlData[i];
2230
+ }
2231
+ }
2232
+ return xmlObj.child;
1591
2233
  };
1592
- function Et(e, t, r) {
1593
- const s = this.options.updateTag(t.tagname, r, t[":@"]);
1594
- s === !1 || (typeof s == "string" && (t.tagname = s), e.addChild(t));
2234
+ function addChild(currentNode, childNode, jPath) {
2235
+ const result = this.options.updateTag(childNode.tagname, jPath, childNode[":@"]);
2236
+ if (result === false)
2237
+ ;
2238
+ else if (typeof result === "string") {
2239
+ childNode.tagname = result;
2240
+ currentNode.addChild(childNode);
2241
+ } else {
2242
+ currentNode.addChild(childNode);
2243
+ }
1595
2244
  }
1596
- const bt = function(e) {
2245
+ const replaceEntitiesValue$1 = function(val2) {
1597
2246
  if (this.options.processEntities) {
1598
- for (let t in this.docTypeEntities) {
1599
- const r = this.docTypeEntities[t];
1600
- e = e.replace(r.regx, r.val);
1601
- }
1602
- for (let t in this.lastEntities) {
1603
- const r = this.lastEntities[t];
1604
- e = e.replace(r.regex, r.val);
1605
- }
1606
- if (this.options.htmlEntities)
1607
- for (let t in this.htmlEntities) {
1608
- const r = this.htmlEntities[t];
1609
- e = e.replace(r.regex, r.val);
2247
+ for (let entityName2 in this.docTypeEntities) {
2248
+ const entity = this.docTypeEntities[entityName2];
2249
+ val2 = val2.replace(entity.regx, entity.val);
2250
+ }
2251
+ for (let entityName2 in this.lastEntities) {
2252
+ const entity = this.lastEntities[entityName2];
2253
+ val2 = val2.replace(entity.regex, entity.val);
2254
+ }
2255
+ if (this.options.htmlEntities) {
2256
+ for (let entityName2 in this.htmlEntities) {
2257
+ const entity = this.htmlEntities[entityName2];
2258
+ val2 = val2.replace(entity.regex, entity.val);
1610
2259
  }
1611
- e = e.replace(this.ampEntity.regex, this.ampEntity.val);
2260
+ }
2261
+ val2 = val2.replace(this.ampEntity.regex, this.ampEntity.val);
1612
2262
  }
1613
- return e;
2263
+ return val2;
1614
2264
  };
1615
- function yt(e, t, r, s) {
1616
- return e && (s === void 0 && (s = Object.keys(t.child).length === 0), e = this.parseTextData(
1617
- e,
1618
- t.tagname,
1619
- r,
1620
- !1,
1621
- t[":@"] ? Object.keys(t[":@"]).length !== 0 : !1,
1622
- s
1623
- ), e !== void 0 && e !== "" && t.add(this.options.textNodeName, e), e = ""), e;
1624
- }
1625
- function vt(e, t, r) {
1626
- const s = "*." + r;
1627
- for (const n in e) {
1628
- const i = e[n];
1629
- if (s === i || t === i)
1630
- return !0;
1631
- }
1632
- return !1;
1633
- }
1634
- function _t(e, t, r = ">") {
1635
- let s, n = "";
1636
- for (let i = t; i < e.length; i++) {
1637
- let a = e[i];
1638
- if (s)
1639
- a === s && (s = "");
1640
- else if (a === '"' || a === "'")
1641
- s = a;
1642
- else if (a === r[0])
1643
- if (r[1]) {
1644
- if (e[i + 1] === r[1])
2265
+ function saveTextToParentTag(textData, currentNode, jPath, isLeafNode) {
2266
+ if (textData) {
2267
+ if (isLeafNode === void 0)
2268
+ isLeafNode = Object.keys(currentNode.child).length === 0;
2269
+ textData = this.parseTextData(
2270
+ textData,
2271
+ currentNode.tagname,
2272
+ jPath,
2273
+ false,
2274
+ currentNode[":@"] ? Object.keys(currentNode[":@"]).length !== 0 : false,
2275
+ isLeafNode
2276
+ );
2277
+ if (textData !== void 0 && textData !== "")
2278
+ currentNode.add(this.options.textNodeName, textData);
2279
+ textData = "";
2280
+ }
2281
+ return textData;
2282
+ }
2283
+ function isItStopNode(stopNodes, jPath, currentTagName) {
2284
+ const allNodesExp = "*." + currentTagName;
2285
+ for (const stopNodePath in stopNodes) {
2286
+ const stopNodeExp = stopNodes[stopNodePath];
2287
+ if (allNodesExp === stopNodeExp || jPath === stopNodeExp)
2288
+ return true;
2289
+ }
2290
+ return false;
2291
+ }
2292
+ function tagExpWithClosingIndex(xmlData, i, closingChar = ">") {
2293
+ let attrBoundary;
2294
+ let tagExp = "";
2295
+ for (let index = i; index < xmlData.length; index++) {
2296
+ let ch = xmlData[index];
2297
+ if (attrBoundary) {
2298
+ if (ch === attrBoundary)
2299
+ attrBoundary = "";
2300
+ } else if (ch === '"' || ch === "'") {
2301
+ attrBoundary = ch;
2302
+ } else if (ch === closingChar[0]) {
2303
+ if (closingChar[1]) {
2304
+ if (xmlData[index + 1] === closingChar[1]) {
1645
2305
  return {
1646
- data: n,
1647
- index: i
2306
+ data: tagExp,
2307
+ index
1648
2308
  };
1649
- } else
2309
+ }
2310
+ } else {
1650
2311
  return {
1651
- data: n,
1652
- index: i
2312
+ data: tagExp,
2313
+ index
1653
2314
  };
1654
- else
1655
- a === " " && (a = " ");
1656
- n += a;
2315
+ }
2316
+ } else if (ch === " ") {
2317
+ ch = " ";
2318
+ }
2319
+ tagExp += ch;
1657
2320
  }
1658
2321
  }
1659
- function v(e, t, r, s) {
1660
- const n = e.indexOf(t, r);
1661
- if (n === -1)
1662
- throw new Error(s);
1663
- return n + t.length - 1;
2322
+ function findClosingIndex(xmlData, str, i, errMsg) {
2323
+ const closingIndex = xmlData.indexOf(str, i);
2324
+ if (closingIndex === -1) {
2325
+ throw new Error(errMsg);
2326
+ } else {
2327
+ return closingIndex + str.length - 1;
2328
+ }
1664
2329
  }
1665
- function S(e, t, r, s = ">") {
1666
- const n = _t(e, t + 1, s);
1667
- if (!n)
2330
+ function readTagExp(xmlData, i, removeNSPrefix, closingChar = ">") {
2331
+ const result = tagExpWithClosingIndex(xmlData, i + 1, closingChar);
2332
+ if (!result)
1668
2333
  return;
1669
- let i = n.data;
1670
- const a = n.index, u = i.search(/\s/);
1671
- let o = i, d = !0;
1672
- u !== -1 && (o = i.substring(0, u), i = i.substring(u + 1).trimStart());
1673
- const l = o;
1674
- if (r) {
1675
- const f = o.indexOf(":");
1676
- f !== -1 && (o = o.substr(f + 1), d = o !== n.data.substr(f + 1));
2334
+ let tagExp = result.data;
2335
+ const closeIndex = result.index;
2336
+ const separatorIndex = tagExp.search(/\s/);
2337
+ let tagName = tagExp;
2338
+ let attrExpPresent = true;
2339
+ if (separatorIndex !== -1) {
2340
+ tagName = tagExp.substring(0, separatorIndex);
2341
+ tagExp = tagExp.substring(separatorIndex + 1).trimStart();
2342
+ }
2343
+ const rawTagName = tagName;
2344
+ if (removeNSPrefix) {
2345
+ const colonIndex = tagName.indexOf(":");
2346
+ if (colonIndex !== -1) {
2347
+ tagName = tagName.substr(colonIndex + 1);
2348
+ attrExpPresent = tagName !== result.data.substr(colonIndex + 1);
2349
+ }
1677
2350
  }
1678
2351
  return {
1679
- tagName: o,
1680
- tagExp: i,
1681
- closeIndex: a,
1682
- attrExpPresent: d,
1683
- rawTagName: l
2352
+ tagName,
2353
+ tagExp,
2354
+ closeIndex,
2355
+ attrExpPresent,
2356
+ rawTagName
1684
2357
  };
1685
2358
  }
1686
- function Tt(e, t, r) {
1687
- const s = r;
1688
- let n = 1;
1689
- for (; r < e.length; r++)
1690
- if (e[r] === "<")
1691
- if (e[r + 1] === "/") {
1692
- const i = v(e, ">", r, `${t} is not closed`);
1693
- if (e.substring(r + 2, i).trim() === t && (n--, n === 0))
1694
- return {
1695
- tagContent: e.substring(s, r),
1696
- i
1697
- };
1698
- r = i;
1699
- } else if (e[r + 1] === "?")
1700
- r = v(e, "?>", r + 1, "StopNode is not closed.");
1701
- else if (e.substr(r + 1, 3) === "!--")
1702
- r = v(e, "-->", r + 3, "StopNode is not closed.");
1703
- else if (e.substr(r + 1, 2) === "![")
1704
- r = v(e, "]]>", r, "StopNode is not closed.") - 2;
1705
- else {
1706
- const i = S(e, r, ">");
1707
- i && ((i && i.tagName) === t && i.tagExp[i.tagExp.length - 1] !== "/" && n++, r = i.closeIndex);
2359
+ function readStopNodeData(xmlData, tagName, i) {
2360
+ const startIndex = i;
2361
+ let openTagCount = 1;
2362
+ for (; i < xmlData.length; i++) {
2363
+ if (xmlData[i] === "<") {
2364
+ if (xmlData[i + 1] === "/") {
2365
+ const closeIndex = findClosingIndex(xmlData, ">", i, `${tagName} is not closed`);
2366
+ let closeTagName = xmlData.substring(i + 2, closeIndex).trim();
2367
+ if (closeTagName === tagName) {
2368
+ openTagCount--;
2369
+ if (openTagCount === 0) {
2370
+ return {
2371
+ tagContent: xmlData.substring(startIndex, i),
2372
+ i: closeIndex
2373
+ };
2374
+ }
2375
+ }
2376
+ i = closeIndex;
2377
+ } else if (xmlData[i + 1] === "?") {
2378
+ const closeIndex = findClosingIndex(xmlData, "?>", i + 1, "StopNode is not closed.");
2379
+ i = closeIndex;
2380
+ } else if (xmlData.substr(i + 1, 3) === "!--") {
2381
+ const closeIndex = findClosingIndex(xmlData, "-->", i + 3, "StopNode is not closed.");
2382
+ i = closeIndex;
2383
+ } else if (xmlData.substr(i + 1, 2) === "![") {
2384
+ const closeIndex = findClosingIndex(xmlData, "]]>", i, "StopNode is not closed.") - 2;
2385
+ i = closeIndex;
2386
+ } else {
2387
+ const tagData = readTagExp(xmlData, i, ">");
2388
+ if (tagData) {
2389
+ const openTagName = tagData && tagData.tagName;
2390
+ if (openTagName === tagName && tagData.tagExp[tagData.tagExp.length - 1] !== "/") {
2391
+ openTagCount++;
2392
+ }
2393
+ i = tagData.closeIndex;
2394
+ }
1708
2395
  }
2396
+ }
2397
+ }
1709
2398
  }
1710
- function V(e, t, r) {
1711
- if (t && typeof e == "string") {
1712
- const s = e.trim();
1713
- return s === "true" ? !0 : s === "false" ? !1 : ft(e, r);
1714
- } else
1715
- return le.isExist(e) ? e : "";
1716
- }
1717
- var It = ct, fe = {};
1718
- function At(e, t) {
1719
- return ce(e, t);
1720
- }
1721
- function ce(e, t, r) {
1722
- let s;
1723
- const n = {};
1724
- for (let i = 0; i < e.length; i++) {
1725
- const a = e[i], u = Ct(a);
1726
- let o = "";
1727
- if (r === void 0 ? o = u : o = r + "." + u, u === t.textNodeName)
1728
- s === void 0 ? s = a[u] : s += "" + a[u];
1729
- else {
1730
- if (u === void 0)
1731
- continue;
1732
- if (a[u]) {
1733
- let d = ce(a[u], t, o);
1734
- const l = Ot(d, t);
1735
- a[":@"] ? Pt(d, a[":@"], o, t) : Object.keys(d).length === 1 && d[t.textNodeName] !== void 0 && !t.alwaysCreateTextNode ? d = d[t.textNodeName] : Object.keys(d).length === 0 && (t.alwaysCreateTextNode ? d[t.textNodeName] = "" : d = ""), n[u] !== void 0 && n.hasOwnProperty(u) ? (Array.isArray(n[u]) || (n[u] = [n[u]]), n[u].push(d)) : t.isArray(u, o, l) ? n[u] = [d] : n[u] = d;
2399
+ function parseValue(val2, shouldParse, options) {
2400
+ if (shouldParse && typeof val2 === "string") {
2401
+ const newval = val2.trim();
2402
+ if (newval === "true")
2403
+ return true;
2404
+ else if (newval === "false")
2405
+ return false;
2406
+ else
2407
+ return toNumber(val2, options);
2408
+ } else {
2409
+ if (util.isExist(val2)) {
2410
+ return val2;
2411
+ } else {
2412
+ return "";
2413
+ }
2414
+ }
2415
+ }
2416
+ var OrderedObjParser_1 = OrderedObjParser$1;
2417
+ var node2json = {};
2418
+ function prettify$1(node, options) {
2419
+ return compress(node, options);
2420
+ }
2421
+ function compress(arr, options, jPath) {
2422
+ let text;
2423
+ const compressedObj = {};
2424
+ for (let i = 0; i < arr.length; i++) {
2425
+ const tagObj = arr[i];
2426
+ const property = propName$1(tagObj);
2427
+ let newJpath = "";
2428
+ if (jPath === void 0)
2429
+ newJpath = property;
2430
+ else
2431
+ newJpath = jPath + "." + property;
2432
+ if (property === options.textNodeName) {
2433
+ if (text === void 0)
2434
+ text = tagObj[property];
2435
+ else
2436
+ text += "" + tagObj[property];
2437
+ } else if (property === void 0) {
2438
+ continue;
2439
+ } else if (tagObj[property]) {
2440
+ let val2 = compress(tagObj[property], options, newJpath);
2441
+ const isLeaf = isLeafTag(val2, options);
2442
+ if (tagObj[":@"]) {
2443
+ assignAttributes(val2, tagObj[":@"], newJpath, options);
2444
+ } else if (Object.keys(val2).length === 1 && val2[options.textNodeName] !== void 0 && !options.alwaysCreateTextNode) {
2445
+ val2 = val2[options.textNodeName];
2446
+ } else if (Object.keys(val2).length === 0) {
2447
+ if (options.alwaysCreateTextNode)
2448
+ val2[options.textNodeName] = "";
2449
+ else
2450
+ val2 = "";
2451
+ }
2452
+ if (compressedObj[property] !== void 0 && compressedObj.hasOwnProperty(property)) {
2453
+ if (!Array.isArray(compressedObj[property])) {
2454
+ compressedObj[property] = [compressedObj[property]];
2455
+ }
2456
+ compressedObj[property].push(val2);
2457
+ } else {
2458
+ if (options.isArray(property, newJpath, isLeaf)) {
2459
+ compressedObj[property] = [val2];
2460
+ } else {
2461
+ compressedObj[property] = val2;
2462
+ }
1736
2463
  }
1737
2464
  }
1738
2465
  }
1739
- return typeof s == "string" ? s.length > 0 && (n[t.textNodeName] = s) : s !== void 0 && (n[t.textNodeName] = s), n;
2466
+ if (typeof text === "string") {
2467
+ if (text.length > 0)
2468
+ compressedObj[options.textNodeName] = text;
2469
+ } else if (text !== void 0)
2470
+ compressedObj[options.textNodeName] = text;
2471
+ return compressedObj;
1740
2472
  }
1741
- function Ct(e) {
1742
- const t = Object.keys(e);
1743
- for (let r = 0; r < t.length; r++) {
1744
- const s = t[r];
1745
- if (s !== ":@")
1746
- return s;
2473
+ function propName$1(obj) {
2474
+ const keys = Object.keys(obj);
2475
+ for (let i = 0; i < keys.length; i++) {
2476
+ const key = keys[i];
2477
+ if (key !== ":@")
2478
+ return key;
1747
2479
  }
1748
2480
  }
1749
- function Pt(e, t, r, s) {
1750
- if (t) {
1751
- const n = Object.keys(t), i = n.length;
1752
- for (let a = 0; a < i; a++) {
1753
- const u = n[a];
1754
- s.isArray(u, r + "." + u, !0, !0) ? e[u] = [t[u]] : e[u] = t[u];
2481
+ function assignAttributes(obj, attrMap, jpath, options) {
2482
+ if (attrMap) {
2483
+ const keys = Object.keys(attrMap);
2484
+ const len = keys.length;
2485
+ for (let i = 0; i < len; i++) {
2486
+ const atrrName = keys[i];
2487
+ if (options.isArray(atrrName, jpath + "." + atrrName, true, true)) {
2488
+ obj[atrrName] = [attrMap[atrrName]];
2489
+ } else {
2490
+ obj[atrrName] = attrMap[atrrName];
2491
+ }
1755
2492
  }
1756
2493
  }
1757
2494
  }
1758
- function Ot(e, t) {
1759
- const { textNodeName: r } = t, s = Object.keys(e).length;
1760
- return !!(s === 0 || s === 1 && (e[r] || typeof e[r] == "boolean" || e[r] === 0));
2495
+ function isLeafTag(obj, options) {
2496
+ const { textNodeName } = options;
2497
+ const propCount = Object.keys(obj).length;
2498
+ if (propCount === 0) {
2499
+ return true;
2500
+ }
2501
+ if (propCount === 1 && (obj[textNodeName] || typeof obj[textNodeName] === "boolean" || obj[textNodeName] === 0)) {
2502
+ return true;
2503
+ }
2504
+ return false;
1761
2505
  }
1762
- fe.prettify = At;
1763
- const { buildOptions: Ft } = z, xt = It, { prettify: $t } = fe, St = G;
1764
- let Vt = class {
1765
- constructor(t) {
1766
- this.externalEntities = {}, this.options = Ft(t);
2506
+ node2json.prettify = prettify$1;
2507
+ const { buildOptions } = OptionsBuilder;
2508
+ const OrderedObjParser2 = OrderedObjParser_1;
2509
+ const { prettify } = node2json;
2510
+ const validator$1 = validator$2;
2511
+ let XMLParser$1 = class XMLParser {
2512
+ constructor(options) {
2513
+ this.externalEntities = {};
2514
+ this.options = buildOptions(options);
1767
2515
  }
1768
2516
  /**
1769
2517
  * Parse XML dats to JS object
1770
2518
  * @param {string|Buffer} xmlData
1771
2519
  * @param {boolean|Object} validationOption
1772
2520
  */
1773
- parse(t, r) {
1774
- if (typeof t != "string")
1775
- if (t.toString)
1776
- t = t.toString();
1777
- else
1778
- throw new Error("XML data is accepted in String or Bytes[] form.");
1779
- if (r) {
1780
- r === !0 && (r = {});
1781
- const i = St.validate(t, r);
1782
- if (i !== !0)
1783
- throw Error(`${i.err.msg}:${i.err.line}:${i.err.col}`);
1784
- }
1785
- const s = new xt(this.options);
1786
- s.addExternalEntities(this.externalEntities);
1787
- const n = s.parseXml(t);
1788
- return this.options.preserveOrder || n === void 0 ? n : $t(n, this.options);
2521
+ parse(xmlData, validationOption) {
2522
+ if (typeof xmlData === "string")
2523
+ ;
2524
+ else if (xmlData.toString) {
2525
+ xmlData = xmlData.toString();
2526
+ } else {
2527
+ throw new Error("XML data is accepted in String or Bytes[] form.");
2528
+ }
2529
+ if (validationOption) {
2530
+ if (validationOption === true)
2531
+ validationOption = {};
2532
+ const result = validator$1.validate(xmlData, validationOption);
2533
+ if (result !== true) {
2534
+ throw Error(`${result.err.msg}:${result.err.line}:${result.err.col}`);
2535
+ }
2536
+ }
2537
+ const orderedObjParser = new OrderedObjParser2(this.options);
2538
+ orderedObjParser.addExternalEntities(this.externalEntities);
2539
+ const orderedResult = orderedObjParser.parseXml(xmlData);
2540
+ if (this.options.preserveOrder || orderedResult === void 0)
2541
+ return orderedResult;
2542
+ else
2543
+ return prettify(orderedResult, this.options);
1789
2544
  }
1790
2545
  /**
1791
2546
  * Add Entity which is not by default supported by this library
1792
2547
  * @param {string} key
1793
2548
  * @param {string} value
1794
2549
  */
1795
- addEntity(t, r) {
1796
- if (r.indexOf("&") !== -1)
2550
+ addEntity(key, value) {
2551
+ if (value.indexOf("&") !== -1) {
1797
2552
  throw new Error("Entity value can't have '&'");
1798
- if (t.indexOf("&") !== -1 || t.indexOf(";") !== -1)
2553
+ } else if (key.indexOf("&") !== -1 || key.indexOf(";") !== -1) {
1799
2554
  throw new Error("An entity must be set without '&' and ';'. Eg. use '#xD' for '&#xD;'");
1800
- if (r === "&")
2555
+ } else if (value === "&") {
1801
2556
  throw new Error("An entity with value '&' is not permitted");
1802
- this.externalEntities[t] = r;
2557
+ } else {
2558
+ this.externalEntities[key] = value;
2559
+ }
1803
2560
  }
1804
2561
  };
1805
- var Lt = Vt;
1806
- const Rt = `
1807
- `;
1808
- function Mt(e, t) {
1809
- let r = "";
1810
- return t.format && t.indentBy.length > 0 && (r = Rt), he(e, t, "", r);
1811
- }
1812
- function he(e, t, r, s) {
1813
- let n = "", i = !1;
1814
- for (let a = 0; a < e.length; a++) {
1815
- const u = e[a], o = Bt(u);
1816
- if (o === void 0)
2562
+ var XMLParser_1 = XMLParser$1;
2563
+ const EOL = "\n";
2564
+ function toXml(jArray, options) {
2565
+ let indentation = "";
2566
+ if (options.format && options.indentBy.length > 0) {
2567
+ indentation = EOL;
2568
+ }
2569
+ return arrToStr(jArray, options, "", indentation);
2570
+ }
2571
+ function arrToStr(arr, options, jPath, indentation) {
2572
+ let xmlStr = "";
2573
+ let isPreviousElementTag = false;
2574
+ for (let i = 0; i < arr.length; i++) {
2575
+ const tagObj = arr[i];
2576
+ const tagName = propName(tagObj);
2577
+ if (tagName === void 0)
1817
2578
  continue;
1818
- let d = "";
1819
- if (r.length === 0 ? d = o : d = `${r}.${o}`, o === t.textNodeName) {
1820
- let h = u[o];
1821
- kt(d, t) || (h = t.tagValueProcessor(o, h), h = pe(h, t)), i && (n += s), n += h, i = !1;
2579
+ let newJPath = "";
2580
+ if (jPath.length === 0)
2581
+ newJPath = tagName;
2582
+ else
2583
+ newJPath = `${jPath}.${tagName}`;
2584
+ if (tagName === options.textNodeName) {
2585
+ let tagText = tagObj[tagName];
2586
+ if (!isStopNode(newJPath, options)) {
2587
+ tagText = options.tagValueProcessor(tagName, tagText);
2588
+ tagText = replaceEntitiesValue(tagText, options);
2589
+ }
2590
+ if (isPreviousElementTag) {
2591
+ xmlStr += indentation;
2592
+ }
2593
+ xmlStr += tagText;
2594
+ isPreviousElementTag = false;
1822
2595
  continue;
1823
- } else if (o === t.cdataPropName) {
1824
- i && (n += s), n += `<![CDATA[${u[o][0][t.textNodeName]}]]>`, i = !1;
2596
+ } else if (tagName === options.cdataPropName) {
2597
+ if (isPreviousElementTag) {
2598
+ xmlStr += indentation;
2599
+ }
2600
+ xmlStr += `<![CDATA[${tagObj[tagName][0][options.textNodeName]}]]>`;
2601
+ isPreviousElementTag = false;
1825
2602
  continue;
1826
- } else if (o === t.commentPropName) {
1827
- n += s + `<!--${u[o][0][t.textNodeName]}-->`, i = !0;
2603
+ } else if (tagName === options.commentPropName) {
2604
+ xmlStr += indentation + `<!--${tagObj[tagName][0][options.textNodeName]}-->`;
2605
+ isPreviousElementTag = true;
1828
2606
  continue;
1829
- } else if (o[0] === "?") {
1830
- const h = D(u[":@"], t), T = o === "?xml" ? "" : s;
1831
- let E = u[o][0][t.textNodeName];
1832
- E = E.length !== 0 ? " " + E : "", n += T + `<${o}${E}${h}?>`, i = !0;
2607
+ } else if (tagName[0] === "?") {
2608
+ const attStr2 = attr_to_str(tagObj[":@"], options);
2609
+ const tempInd = tagName === "?xml" ? "" : indentation;
2610
+ let piTextNodeName = tagObj[tagName][0][options.textNodeName];
2611
+ piTextNodeName = piTextNodeName.length !== 0 ? " " + piTextNodeName : "";
2612
+ xmlStr += tempInd + `<${tagName}${piTextNodeName}${attStr2}?>`;
2613
+ isPreviousElementTag = true;
1833
2614
  continue;
1834
2615
  }
1835
- let l = s;
1836
- l !== "" && (l += t.indentBy);
1837
- const f = D(u[":@"], t), c = s + `<${o}${f}`, g = he(u[o], t, d, l);
1838
- t.unpairedTags.indexOf(o) !== -1 ? t.suppressUnpairedNode ? n += c + ">" : n += c + "/>" : (!g || g.length === 0) && t.suppressEmptyNode ? n += c + "/>" : g && g.endsWith(">") ? n += c + `>${g}${s}</${o}>` : (n += c + ">", g && s !== "" && (g.includes("/>") || g.includes("</")) ? n += s + t.indentBy + g + s : n += g, n += `</${o}>`), i = !0;
2616
+ let newIdentation = indentation;
2617
+ if (newIdentation !== "") {
2618
+ newIdentation += options.indentBy;
2619
+ }
2620
+ const attStr = attr_to_str(tagObj[":@"], options);
2621
+ const tagStart = indentation + `<${tagName}${attStr}`;
2622
+ const tagValue = arrToStr(tagObj[tagName], options, newJPath, newIdentation);
2623
+ if (options.unpairedTags.indexOf(tagName) !== -1) {
2624
+ if (options.suppressUnpairedNode)
2625
+ xmlStr += tagStart + ">";
2626
+ else
2627
+ xmlStr += tagStart + "/>";
2628
+ } else if ((!tagValue || tagValue.length === 0) && options.suppressEmptyNode) {
2629
+ xmlStr += tagStart + "/>";
2630
+ } else if (tagValue && tagValue.endsWith(">")) {
2631
+ xmlStr += tagStart + `>${tagValue}${indentation}</${tagName}>`;
2632
+ } else {
2633
+ xmlStr += tagStart + ">";
2634
+ if (tagValue && indentation !== "" && (tagValue.includes("/>") || tagValue.includes("</"))) {
2635
+ xmlStr += indentation + options.indentBy + tagValue + indentation;
2636
+ } else {
2637
+ xmlStr += tagValue;
2638
+ }
2639
+ xmlStr += `</${tagName}>`;
2640
+ }
2641
+ isPreviousElementTag = true;
1839
2642
  }
1840
- return n;
2643
+ return xmlStr;
1841
2644
  }
1842
- function Bt(e) {
1843
- const t = Object.keys(e);
1844
- for (let r = 0; r < t.length; r++) {
1845
- const s = t[r];
1846
- if (e.hasOwnProperty(s) && s !== ":@")
1847
- return s;
2645
+ function propName(obj) {
2646
+ const keys = Object.keys(obj);
2647
+ for (let i = 0; i < keys.length; i++) {
2648
+ const key = keys[i];
2649
+ if (!obj.hasOwnProperty(key))
2650
+ continue;
2651
+ if (key !== ":@")
2652
+ return key;
1848
2653
  }
1849
2654
  }
1850
- function D(e, t) {
1851
- let r = "";
1852
- if (e && !t.ignoreAttributes)
1853
- for (let s in e) {
1854
- if (!e.hasOwnProperty(s))
2655
+ function attr_to_str(attrMap, options) {
2656
+ let attrStr = "";
2657
+ if (attrMap && !options.ignoreAttributes) {
2658
+ for (let attr in attrMap) {
2659
+ if (!attrMap.hasOwnProperty(attr))
1855
2660
  continue;
1856
- let n = t.attributeValueProcessor(s, e[s]);
1857
- n = pe(n, t), n === !0 && t.suppressBooleanAttributes ? r += ` ${s.substr(t.attributeNamePrefix.length)}` : r += ` ${s.substr(t.attributeNamePrefix.length)}="${n}"`;
2661
+ let attrVal = options.attributeValueProcessor(attr, attrMap[attr]);
2662
+ attrVal = replaceEntitiesValue(attrVal, options);
2663
+ if (attrVal === true && options.suppressBooleanAttributes) {
2664
+ attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}`;
2665
+ } else {
2666
+ attrStr += ` ${attr.substr(options.attributeNamePrefix.length)}="${attrVal}"`;
2667
+ }
1858
2668
  }
1859
- return r;
2669
+ }
2670
+ return attrStr;
1860
2671
  }
1861
- function kt(e, t) {
1862
- e = e.substr(0, e.length - t.textNodeName.length - 1);
1863
- let r = e.substr(e.lastIndexOf(".") + 1);
1864
- for (let s in t.stopNodes)
1865
- if (t.stopNodes[s] === e || t.stopNodes[s] === "*." + r)
1866
- return !0;
1867
- return !1;
2672
+ function isStopNode(jPath, options) {
2673
+ jPath = jPath.substr(0, jPath.length - options.textNodeName.length - 1);
2674
+ let tagName = jPath.substr(jPath.lastIndexOf(".") + 1);
2675
+ for (let index in options.stopNodes) {
2676
+ if (options.stopNodes[index] === jPath || options.stopNodes[index] === "*." + tagName)
2677
+ return true;
2678
+ }
2679
+ return false;
1868
2680
  }
1869
- function pe(e, t) {
1870
- if (e && e.length > 0 && t.processEntities)
1871
- for (let r = 0; r < t.entities.length; r++) {
1872
- const s = t.entities[r];
1873
- e = e.replace(s.regex, s.val);
2681
+ function replaceEntitiesValue(textValue, options) {
2682
+ if (textValue && textValue.length > 0 && options.processEntities) {
2683
+ for (let i = 0; i < options.entities.length; i++) {
2684
+ const entity = options.entities[i];
2685
+ textValue = textValue.replace(entity.regex, entity.val);
1874
2686
  }
1875
- return e;
2687
+ }
2688
+ return textValue;
1876
2689
  }
1877
- var qt = Mt;
1878
- const Ut = qt, Xt = {
2690
+ var orderedJs2Xml = toXml;
2691
+ const buildFromOrderedJs = orderedJs2Xml;
2692
+ const defaultOptions = {
1879
2693
  attributeNamePrefix: "@_",
1880
- attributesGroupName: !1,
2694
+ attributesGroupName: false,
1881
2695
  textNodeName: "#text",
1882
- ignoreAttributes: !0,
1883
- cdataPropName: !1,
1884
- format: !1,
2696
+ ignoreAttributes: true,
2697
+ cdataPropName: false,
2698
+ format: false,
1885
2699
  indentBy: " ",
1886
- suppressEmptyNode: !1,
1887
- suppressUnpairedNode: !0,
1888
- suppressBooleanAttributes: !0,
1889
- tagValueProcessor: function(e, t) {
1890
- return t;
2700
+ suppressEmptyNode: false,
2701
+ suppressUnpairedNode: true,
2702
+ suppressBooleanAttributes: true,
2703
+ tagValueProcessor: function(key, a) {
2704
+ return a;
1891
2705
  },
1892
- attributeValueProcessor: function(e, t) {
1893
- return t;
2706
+ attributeValueProcessor: function(attrName, a) {
2707
+ return a;
1894
2708
  },
1895
- preserveOrder: !1,
1896
- commentPropName: !1,
2709
+ preserveOrder: false,
2710
+ commentPropName: false,
1897
2711
  unpairedTags: [],
1898
2712
  entities: [
1899
2713
  { regex: new RegExp("&", "g"), val: "&amp;" },
@@ -1903,126 +2717,240 @@ const Ut = qt, Xt = {
1903
2717
  { regex: new RegExp("'", "g"), val: "&apos;" },
1904
2718
  { regex: new RegExp('"', "g"), val: "&quot;" }
1905
2719
  ],
1906
- processEntities: !0,
2720
+ processEntities: true,
1907
2721
  stopNodes: [],
1908
2722
  // transformTagName: false,
1909
2723
  // transformAttributeName: false,
1910
- oneListGroup: !1
2724
+ oneListGroup: false
1911
2725
  };
1912
- function b(e) {
1913
- this.options = Object.assign({}, Xt, e), this.options.ignoreAttributes || this.options.attributesGroupName ? this.isAttribute = function() {
1914
- return !1;
1915
- } : (this.attrPrefixLen = this.options.attributeNamePrefix.length, this.isAttribute = zt), this.processTextOrObjNode = Gt, this.options.format ? (this.indentate = Ht, this.tagEndChar = `>
1916
- `, this.newLine = `
1917
- `) : (this.indentate = function() {
1918
- return "";
1919
- }, this.tagEndChar = ">", this.newLine = "");
1920
- }
1921
- b.prototype.build = function(e) {
1922
- return this.options.preserveOrder ? Ut(e, this.options) : (Array.isArray(e) && this.options.arrayNodeName && this.options.arrayNodeName.length > 1 && (e = {
1923
- [this.options.arrayNodeName]: e
1924
- }), this.j2x(e, 0).val);
2726
+ function Builder(options) {
2727
+ this.options = Object.assign({}, defaultOptions, options);
2728
+ if (this.options.ignoreAttributes || this.options.attributesGroupName) {
2729
+ this.isAttribute = function() {
2730
+ return false;
2731
+ };
2732
+ } else {
2733
+ this.attrPrefixLen = this.options.attributeNamePrefix.length;
2734
+ this.isAttribute = isAttribute;
2735
+ }
2736
+ this.processTextOrObjNode = processTextOrObjNode;
2737
+ if (this.options.format) {
2738
+ this.indentate = indentate;
2739
+ this.tagEndChar = ">\n";
2740
+ this.newLine = "\n";
2741
+ } else {
2742
+ this.indentate = function() {
2743
+ return "";
2744
+ };
2745
+ this.tagEndChar = ">";
2746
+ this.newLine = "";
2747
+ }
2748
+ }
2749
+ Builder.prototype.build = function(jObj) {
2750
+ if (this.options.preserveOrder) {
2751
+ return buildFromOrderedJs(jObj, this.options);
2752
+ } else {
2753
+ if (Array.isArray(jObj) && this.options.arrayNodeName && this.options.arrayNodeName.length > 1) {
2754
+ jObj = {
2755
+ [this.options.arrayNodeName]: jObj
2756
+ };
2757
+ }
2758
+ return this.j2x(jObj, 0).val;
2759
+ }
1925
2760
  };
1926
- b.prototype.j2x = function(e, t) {
1927
- let r = "", s = "";
1928
- for (let n in e)
1929
- if (Object.prototype.hasOwnProperty.call(e, n))
1930
- if (typeof e[n] > "u")
1931
- this.isAttribute(n) && (s += "");
1932
- else if (e[n] === null)
1933
- this.isAttribute(n) ? s += "" : n[0] === "?" ? s += this.indentate(t) + "<" + n + "?" + this.tagEndChar : s += this.indentate(t) + "<" + n + "/" + this.tagEndChar;
1934
- else if (e[n] instanceof Date)
1935
- s += this.buildTextValNode(e[n], n, "", t);
1936
- else if (typeof e[n] != "object") {
1937
- const i = this.isAttribute(n);
1938
- if (i)
1939
- r += this.buildAttrPairStr(i, "" + e[n]);
1940
- else if (n === this.options.textNodeName) {
1941
- let a = this.options.tagValueProcessor(n, "" + e[n]);
1942
- s += this.replaceEntitiesValue(a);
1943
- } else
1944
- s += this.buildTextValNode(e[n], n, "", t);
1945
- } else if (Array.isArray(e[n])) {
1946
- const i = e[n].length;
1947
- let a = "";
1948
- for (let u = 0; u < i; u++) {
1949
- const o = e[n][u];
1950
- typeof o > "u" || (o === null ? n[0] === "?" ? s += this.indentate(t) + "<" + n + "?" + this.tagEndChar : s += this.indentate(t) + "<" + n + "/" + this.tagEndChar : typeof o == "object" ? this.options.oneListGroup ? a += this.j2x(o, t + 1).val : a += this.processTextOrObjNode(o, n, t) : a += this.buildTextValNode(o, n, "", t));
2761
+ Builder.prototype.j2x = function(jObj, level) {
2762
+ let attrStr = "";
2763
+ let val2 = "";
2764
+ for (let key in jObj) {
2765
+ if (!Object.prototype.hasOwnProperty.call(jObj, key))
2766
+ continue;
2767
+ if (typeof jObj[key] === "undefined") {
2768
+ if (this.isAttribute(key)) {
2769
+ val2 += "";
2770
+ }
2771
+ } else if (jObj[key] === null) {
2772
+ if (this.isAttribute(key)) {
2773
+ val2 += "";
2774
+ } else if (key[0] === "?") {
2775
+ val2 += this.indentate(level) + "<" + key + "?" + this.tagEndChar;
2776
+ } else {
2777
+ val2 += this.indentate(level) + "<" + key + "/" + this.tagEndChar;
2778
+ }
2779
+ } else if (jObj[key] instanceof Date) {
2780
+ val2 += this.buildTextValNode(jObj[key], key, "", level);
2781
+ } else if (typeof jObj[key] !== "object") {
2782
+ const attr = this.isAttribute(key);
2783
+ if (attr) {
2784
+ attrStr += this.buildAttrPairStr(attr, "" + jObj[key]);
2785
+ } else {
2786
+ if (key === this.options.textNodeName) {
2787
+ let newval = this.options.tagValueProcessor(key, "" + jObj[key]);
2788
+ val2 += this.replaceEntitiesValue(newval);
2789
+ } else {
2790
+ val2 += this.buildTextValNode(jObj[key], key, "", level);
1951
2791
  }
1952
- this.options.oneListGroup && (a = this.buildObjectNode(a, n, "", t)), s += a;
1953
- } else if (this.options.attributesGroupName && n === this.options.attributesGroupName) {
1954
- const i = Object.keys(e[n]), a = i.length;
1955
- for (let u = 0; u < a; u++)
1956
- r += this.buildAttrPairStr(i[u], "" + e[n][i[u]]);
1957
- } else
1958
- s += this.processTextOrObjNode(e[n], n, t);
1959
- return { attrStr: r, val: s };
2792
+ }
2793
+ } else if (Array.isArray(jObj[key])) {
2794
+ const arrLen = jObj[key].length;
2795
+ let listTagVal = "";
2796
+ for (let j = 0; j < arrLen; j++) {
2797
+ const item = jObj[key][j];
2798
+ if (typeof item === "undefined")
2799
+ ;
2800
+ else if (item === null) {
2801
+ if (key[0] === "?")
2802
+ val2 += this.indentate(level) + "<" + key + "?" + this.tagEndChar;
2803
+ else
2804
+ val2 += this.indentate(level) + "<" + key + "/" + this.tagEndChar;
2805
+ } else if (typeof item === "object") {
2806
+ if (this.options.oneListGroup) {
2807
+ listTagVal += this.j2x(item, level + 1).val;
2808
+ } else {
2809
+ listTagVal += this.processTextOrObjNode(item, key, level);
2810
+ }
2811
+ } else {
2812
+ listTagVal += this.buildTextValNode(item, key, "", level);
2813
+ }
2814
+ }
2815
+ if (this.options.oneListGroup) {
2816
+ listTagVal = this.buildObjectNode(listTagVal, key, "", level);
2817
+ }
2818
+ val2 += listTagVal;
2819
+ } else {
2820
+ if (this.options.attributesGroupName && key === this.options.attributesGroupName) {
2821
+ const Ks = Object.keys(jObj[key]);
2822
+ const L = Ks.length;
2823
+ for (let j = 0; j < L; j++) {
2824
+ attrStr += this.buildAttrPairStr(Ks[j], "" + jObj[key][Ks[j]]);
2825
+ }
2826
+ } else {
2827
+ val2 += this.processTextOrObjNode(jObj[key], key, level);
2828
+ }
2829
+ }
2830
+ }
2831
+ return { attrStr, val: val2 };
1960
2832
  };
1961
- b.prototype.buildAttrPairStr = function(e, t) {
1962
- return t = this.options.attributeValueProcessor(e, "" + t), t = this.replaceEntitiesValue(t), this.options.suppressBooleanAttributes && t === "true" ? " " + e : " " + e + '="' + t + '"';
2833
+ Builder.prototype.buildAttrPairStr = function(attrName, val2) {
2834
+ val2 = this.options.attributeValueProcessor(attrName, "" + val2);
2835
+ val2 = this.replaceEntitiesValue(val2);
2836
+ if (this.options.suppressBooleanAttributes && val2 === "true") {
2837
+ return " " + attrName;
2838
+ } else
2839
+ return " " + attrName + '="' + val2 + '"';
1963
2840
  };
1964
- function Gt(e, t, r) {
1965
- const s = this.j2x(e, r + 1);
1966
- return e[this.options.textNodeName] !== void 0 && Object.keys(e).length === 1 ? this.buildTextValNode(e[this.options.textNodeName], t, s.attrStr, r) : this.buildObjectNode(s.val, t, s.attrStr, r);
2841
+ function processTextOrObjNode(object, key, level) {
2842
+ const result = this.j2x(object, level + 1);
2843
+ if (object[this.options.textNodeName] !== void 0 && Object.keys(object).length === 1) {
2844
+ return this.buildTextValNode(object[this.options.textNodeName], key, result.attrStr, level);
2845
+ } else {
2846
+ return this.buildObjectNode(result.val, key, result.attrStr, level);
2847
+ }
1967
2848
  }
1968
- b.prototype.buildObjectNode = function(e, t, r, s) {
1969
- if (e === "")
1970
- return t[0] === "?" ? this.indentate(s) + "<" + t + r + "?" + this.tagEndChar : this.indentate(s) + "<" + t + r + this.closeTag(t) + this.tagEndChar;
1971
- {
1972
- let n = "</" + t + this.tagEndChar, i = "";
1973
- return t[0] === "?" && (i = "?", n = ""), (r || r === "") && e.indexOf("<") === -1 ? this.indentate(s) + "<" + t + r + i + ">" + e + n : this.options.commentPropName !== !1 && t === this.options.commentPropName && i.length === 0 ? this.indentate(s) + `<!--${e}-->` + this.newLine : this.indentate(s) + "<" + t + r + i + this.tagEndChar + e + this.indentate(s) + n;
2849
+ Builder.prototype.buildObjectNode = function(val2, key, attrStr, level) {
2850
+ if (val2 === "") {
2851
+ if (key[0] === "?")
2852
+ return this.indentate(level) + "<" + key + attrStr + "?" + this.tagEndChar;
2853
+ else {
2854
+ return this.indentate(level) + "<" + key + attrStr + this.closeTag(key) + this.tagEndChar;
2855
+ }
2856
+ } else {
2857
+ let tagEndExp = "</" + key + this.tagEndChar;
2858
+ let piClosingChar = "";
2859
+ if (key[0] === "?") {
2860
+ piClosingChar = "?";
2861
+ tagEndExp = "";
2862
+ }
2863
+ if ((attrStr || attrStr === "") && val2.indexOf("<") === -1) {
2864
+ return this.indentate(level) + "<" + key + attrStr + piClosingChar + ">" + val2 + tagEndExp;
2865
+ } else if (this.options.commentPropName !== false && key === this.options.commentPropName && piClosingChar.length === 0) {
2866
+ return this.indentate(level) + `<!--${val2}-->` + this.newLine;
2867
+ } else {
2868
+ return this.indentate(level) + "<" + key + attrStr + piClosingChar + this.tagEndChar + val2 + this.indentate(level) + tagEndExp;
2869
+ }
1974
2870
  }
1975
2871
  };
1976
- b.prototype.closeTag = function(e) {
1977
- let t = "";
1978
- return this.options.unpairedTags.indexOf(e) !== -1 ? this.options.suppressUnpairedNode || (t = "/") : this.options.suppressEmptyNode ? t = "/" : t = `></${e}`, t;
2872
+ Builder.prototype.closeTag = function(key) {
2873
+ let closeTag = "";
2874
+ if (this.options.unpairedTags.indexOf(key) !== -1) {
2875
+ if (!this.options.suppressUnpairedNode)
2876
+ closeTag = "/";
2877
+ } else if (this.options.suppressEmptyNode) {
2878
+ closeTag = "/";
2879
+ } else {
2880
+ closeTag = `></${key}`;
2881
+ }
2882
+ return closeTag;
1979
2883
  };
1980
- b.prototype.buildTextValNode = function(e, t, r, s) {
1981
- if (this.options.cdataPropName !== !1 && t === this.options.cdataPropName)
1982
- return this.indentate(s) + `<![CDATA[${e}]]>` + this.newLine;
1983
- if (this.options.commentPropName !== !1 && t === this.options.commentPropName)
1984
- return this.indentate(s) + `<!--${e}-->` + this.newLine;
1985
- if (t[0] === "?")
1986
- return this.indentate(s) + "<" + t + r + "?" + this.tagEndChar;
1987
- {
1988
- let n = this.options.tagValueProcessor(t, e);
1989
- return n = this.replaceEntitiesValue(n), n === "" ? this.indentate(s) + "<" + t + r + this.closeTag(t) + this.tagEndChar : this.indentate(s) + "<" + t + r + ">" + n + "</" + t + this.tagEndChar;
2884
+ Builder.prototype.buildTextValNode = function(val2, key, attrStr, level) {
2885
+ if (this.options.cdataPropName !== false && key === this.options.cdataPropName) {
2886
+ return this.indentate(level) + `<![CDATA[${val2}]]>` + this.newLine;
2887
+ } else if (this.options.commentPropName !== false && key === this.options.commentPropName) {
2888
+ return this.indentate(level) + `<!--${val2}-->` + this.newLine;
2889
+ } else if (key[0] === "?") {
2890
+ return this.indentate(level) + "<" + key + attrStr + "?" + this.tagEndChar;
2891
+ } else {
2892
+ let textValue = this.options.tagValueProcessor(key, val2);
2893
+ textValue = this.replaceEntitiesValue(textValue);
2894
+ if (textValue === "") {
2895
+ return this.indentate(level) + "<" + key + attrStr + this.closeTag(key) + this.tagEndChar;
2896
+ } else {
2897
+ return this.indentate(level) + "<" + key + attrStr + ">" + textValue + "</" + key + this.tagEndChar;
2898
+ }
1990
2899
  }
1991
2900
  };
1992
- b.prototype.replaceEntitiesValue = function(e) {
1993
- if (e && e.length > 0 && this.options.processEntities)
1994
- for (let t = 0; t < this.options.entities.length; t++) {
1995
- const r = this.options.entities[t];
1996
- e = e.replace(r.regex, r.val);
2901
+ Builder.prototype.replaceEntitiesValue = function(textValue) {
2902
+ if (textValue && textValue.length > 0 && this.options.processEntities) {
2903
+ for (let i = 0; i < this.options.entities.length; i++) {
2904
+ const entity = this.options.entities[i];
2905
+ textValue = textValue.replace(entity.regex, entity.val);
1997
2906
  }
1998
- return e;
2907
+ }
2908
+ return textValue;
1999
2909
  };
2000
- function Ht(e) {
2001
- return this.options.indentBy.repeat(e);
2002
- }
2003
- function zt(e) {
2004
- return e.startsWith(this.options.attributeNamePrefix) && e !== this.options.textNodeName ? e.substr(this.attrPrefixLen) : !1;
2005
- }
2006
- var Kt = b;
2007
- const Wt = G, Zt = Lt, jt = Kt;
2008
- var ee = {
2009
- XMLParser: Zt,
2010
- XMLValidator: Wt,
2011
- XMLBuilder: jt
2910
+ function indentate(level) {
2911
+ return this.options.indentBy.repeat(level);
2912
+ }
2913
+ function isAttribute(name) {
2914
+ if (name.startsWith(this.options.attributeNamePrefix) && name !== this.options.textNodeName) {
2915
+ return name.substr(this.attrPrefixLen);
2916
+ } else {
2917
+ return false;
2918
+ }
2919
+ }
2920
+ var json2xml = Builder;
2921
+ const validator = validator$2;
2922
+ const XMLParser2 = XMLParser_1;
2923
+ const XMLBuilder = json2xml;
2924
+ var fxp = {
2925
+ XMLParser: XMLParser2,
2926
+ XMLValidator: validator,
2927
+ XMLBuilder
2012
2928
  };
2013
- function Yt(e) {
2014
- if (typeof e != "string")
2015
- throw new TypeError(`Expected a \`string\`, got \`${typeof e}\``);
2016
- if (e = e.trim(), e.length === 0 || ee.XMLValidator.validate(e) !== !0)
2017
- return !1;
2018
- let t;
2019
- const r = new ee.XMLParser();
2929
+ function isSvg(string) {
2930
+ if (typeof string !== "string") {
2931
+ throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
2932
+ }
2933
+ string = string.trim();
2934
+ if (string.length === 0) {
2935
+ return false;
2936
+ }
2937
+ if (fxp.XMLValidator.validate(string) !== true) {
2938
+ return false;
2939
+ }
2940
+ let jsonObject;
2941
+ const parser = new fxp.XMLParser();
2020
2942
  try {
2021
- t = r.parse(e);
2943
+ jsonObject = parser.parse(string);
2022
2944
  } catch {
2023
- return !1;
2945
+ return false;
2946
+ }
2947
+ if (!jsonObject) {
2948
+ return false;
2949
+ }
2950
+ if (!Object.keys(jsonObject).some((x) => x.toLowerCase() === "svg")) {
2951
+ return false;
2024
2952
  }
2025
- return !(!t || !("svg" in t));
2953
+ return true;
2026
2954
  }
2027
2955
  /**
2028
2956
  * @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
@@ -2045,10 +2973,11 @@ function Yt(e) {
2045
2973
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
2046
2974
  *
2047
2975
  */
2048
- class Jt {
2976
+ class View {
2049
2977
  _view;
2050
- constructor(t) {
2051
- Qt(t), this._view = t;
2978
+ constructor(view) {
2979
+ isValidView(view);
2980
+ this._view = view;
2052
2981
  }
2053
2982
  get id() {
2054
2983
  return this._view.id;
@@ -2071,20 +3000,20 @@ class Jt {
2071
3000
  get icon() {
2072
3001
  return this._view.icon;
2073
3002
  }
2074
- set icon(t) {
2075
- this._view.icon = t;
3003
+ set icon(icon) {
3004
+ this._view.icon = icon;
2076
3005
  }
2077
3006
  get order() {
2078
3007
  return this._view.order;
2079
3008
  }
2080
- set order(t) {
2081
- this._view.order = t;
3009
+ set order(order) {
3010
+ this._view.order = order;
2082
3011
  }
2083
3012
  get params() {
2084
3013
  return this._view.params;
2085
3014
  }
2086
- set params(t) {
2087
- this._view.params = t;
3015
+ set params(params) {
3016
+ this._view.params = params;
2088
3017
  }
2089
3018
  get columns() {
2090
3019
  return this._view.columns;
@@ -2101,40 +3030,55 @@ class Jt {
2101
3030
  get expanded() {
2102
3031
  return this._view.expanded;
2103
3032
  }
2104
- set expanded(t) {
2105
- this._view.expanded = t;
3033
+ set expanded(expanded) {
3034
+ this._view.expanded = expanded;
2106
3035
  }
2107
3036
  get defaultSortKey() {
2108
3037
  return this._view.defaultSortKey;
2109
3038
  }
2110
3039
  }
2111
- const Qt = function(e) {
2112
- if (!e.id || typeof e.id != "string")
3040
+ const isValidView = function(view) {
3041
+ if (!view.id || typeof view.id !== "string") {
2113
3042
  throw new Error("View id is required and must be a string");
2114
- if (!e.name || typeof e.name != "string")
3043
+ }
3044
+ if (!view.name || typeof view.name !== "string") {
2115
3045
  throw new Error("View name is required and must be a string");
2116
- if (e.columns && e.columns.length > 0 && (!e.caption || typeof e.caption != "string"))
3046
+ }
3047
+ if (view.columns && view.columns.length > 0 && (!view.caption || typeof view.caption !== "string")) {
2117
3048
  throw new Error("View caption is required for top-level views and must be a string");
2118
- if (!e.getContents || typeof e.getContents != "function")
3049
+ }
3050
+ if (!view.getContents || typeof view.getContents !== "function") {
2119
3051
  throw new Error("View getContents is required and must be a function");
2120
- if (!e.icon || typeof e.icon != "string" || !Yt(e.icon))
3052
+ }
3053
+ if (!view.icon || typeof view.icon !== "string" || !isSvg(view.icon)) {
2121
3054
  throw new Error("View icon is required and must be a valid svg string");
2122
- if (!("order" in e) || typeof e.order != "number")
3055
+ }
3056
+ if (!("order" in view) || typeof view.order !== "number") {
2123
3057
  throw new Error("View order is required and must be a number");
2124
- if (e.columns && e.columns.forEach((t) => {
2125
- if (!(t instanceof ae))
2126
- throw new Error("View columns must be an array of Column. Invalid column found");
2127
- }), e.emptyView && typeof e.emptyView != "function")
3058
+ }
3059
+ if (view.columns) {
3060
+ view.columns.forEach((column) => {
3061
+ if (!(column instanceof Column)) {
3062
+ throw new Error("View columns must be an array of Column. Invalid column found");
3063
+ }
3064
+ });
3065
+ }
3066
+ if (view.emptyView && typeof view.emptyView !== "function") {
2128
3067
  throw new Error("View emptyView must be a function");
2129
- if (e.parent && typeof e.parent != "string")
3068
+ }
3069
+ if (view.parent && typeof view.parent !== "string") {
2130
3070
  throw new Error("View parent must be a string");
2131
- if ("sticky" in e && typeof e.sticky != "boolean")
3071
+ }
3072
+ if ("sticky" in view && typeof view.sticky !== "boolean") {
2132
3073
  throw new Error("View sticky must be a boolean");
2133
- if ("expanded" in e && typeof e.expanded != "boolean")
3074
+ }
3075
+ if ("expanded" in view && typeof view.expanded !== "boolean") {
2134
3076
  throw new Error("View expanded must be a boolean");
2135
- if (e.defaultSortKey && typeof e.defaultSortKey != "string")
3077
+ }
3078
+ if (view.defaultSortKey && typeof view.defaultSortKey !== "string") {
2136
3079
  throw new Error("View defaultSortKey must be a string");
2137
- return !0;
3080
+ }
3081
+ return true;
2138
3082
  };
2139
3083
  /**
2140
3084
  * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
@@ -2158,46 +3102,58 @@ const Qt = function(e) {
2158
3102
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
2159
3103
  *
2160
3104
  */
2161
- const Dt = function(e) {
2162
- return L().registerEntry(e);
2163
- }, er = function(e) {
2164
- return L().unregisterEntry(e);
2165
- }, tr = function(e) {
2166
- return L().getEntries(e).sort((r, s) => r.order !== void 0 && s.order !== void 0 && r.order !== s.order ? r.order - s.order : r.displayName.localeCompare(s.displayName, void 0, { numeric: !0, sensitivity: "base" }));
3105
+ const addNewFileMenuEntry = function(entry) {
3106
+ const newFileMenu = getNewFileMenu();
3107
+ return newFileMenu.registerEntry(entry);
3108
+ };
3109
+ const removeNewFileMenuEntry = function(entry) {
3110
+ const newFileMenu = getNewFileMenu();
3111
+ return newFileMenu.unregisterEntry(entry);
3112
+ };
3113
+ const getNewFileMenuEntries = function(context) {
3114
+ const newFileMenu = getNewFileMenu();
3115
+ return newFileMenu.getEntries(context).sort((a, b) => {
3116
+ if (a.order !== void 0 && b.order !== void 0 && a.order !== b.order) {
3117
+ return a.order - b.order;
3118
+ }
3119
+ return a.displayName.localeCompare(b.displayName, void 0, { numeric: true, sensitivity: "base" });
3120
+ });
2167
3121
  };
2168
- exports.Column = ae;
2169
- exports.DefaultType = R;
2170
- exports.File = ie;
2171
- exports.FileAction = _e;
2172
- exports.FileType = O;
2173
- exports.Folder = se;
2174
- exports.Header = Ae;
2175
- exports.Navigation = ue;
2176
- exports.Node = q;
2177
- exports.NodeStatus = k;
2178
- exports.Permission = m;
2179
- exports.View = Jt;
2180
- exports.addNewFileMenuEntry = Dt;
2181
- exports.davGetClient = $e;
2182
- exports.davGetDefaultPropfind = Fe;
2183
- exports.davGetFavoritesReport = te;
2184
- exports.davGetRecentSearch = xe;
2185
- exports.davParsePermissions = re;
2186
- exports.davRemoteURL = X;
2187
- exports.davResultToNode = oe;
2188
- exports.davRootPath = U;
2189
- exports.defaultDavNamespaces = B;
2190
- exports.defaultDavProperties = M;
2191
- exports.formatFileSize = ye;
2192
- exports.getDavNameSpaces = P;
2193
- exports.getDavProperties = C;
2194
- exports.getFavoriteNodes = Se;
2195
- exports.getFileActions = Ie;
2196
- exports.getFileListHeaders = Pe;
2197
- exports.getNavigation = Ve;
2198
- exports.getNewFileMenuEntries = tr;
2199
- exports.parseFileSize = ve;
2200
- exports.registerDavProperty = Oe;
2201
- exports.registerFileAction = Te;
2202
- exports.registerFileListHeaders = Ce;
2203
- exports.removeNewFileMenuEntry = er;
3122
+ exports.Column = Column;
3123
+ exports.DefaultType = DefaultType;
3124
+ exports.File = File;
3125
+ exports.FileAction = FileAction;
3126
+ exports.FileType = FileType;
3127
+ exports.Folder = Folder;
3128
+ exports.Header = Header;
3129
+ exports.Navigation = Navigation;
3130
+ exports.NewMenuEntryCategory = NewMenuEntryCategory;
3131
+ exports.Node = Node;
3132
+ exports.NodeStatus = NodeStatus;
3133
+ exports.Permission = Permission;
3134
+ exports.View = View;
3135
+ exports.addNewFileMenuEntry = addNewFileMenuEntry;
3136
+ exports.davGetClient = davGetClient;
3137
+ exports.davGetDefaultPropfind = davGetDefaultPropfind;
3138
+ exports.davGetFavoritesReport = davGetFavoritesReport;
3139
+ exports.davGetRecentSearch = davGetRecentSearch;
3140
+ exports.davParsePermissions = davParsePermissions;
3141
+ exports.davRemoteURL = davRemoteURL;
3142
+ exports.davResultToNode = davResultToNode;
3143
+ exports.davRootPath = davRootPath;
3144
+ exports.defaultDavNamespaces = defaultDavNamespaces;
3145
+ exports.defaultDavProperties = defaultDavProperties;
3146
+ exports.formatFileSize = formatFileSize;
3147
+ exports.getDavNameSpaces = getDavNameSpaces;
3148
+ exports.getDavProperties = getDavProperties;
3149
+ exports.getFavoriteNodes = getFavoriteNodes;
3150
+ exports.getFileActions = getFileActions;
3151
+ exports.getFileListHeaders = getFileListHeaders;
3152
+ exports.getNavigation = getNavigation;
3153
+ exports.getNewFileMenuEntries = getNewFileMenuEntries;
3154
+ exports.isFilenameValid = isFilenameValid;
3155
+ exports.parseFileSize = parseFileSize;
3156
+ exports.registerDavProperty = registerDavProperty;
3157
+ exports.registerFileAction = registerFileAction;
3158
+ exports.registerFileListHeaders = registerFileListHeaders;
3159
+ exports.removeNewFileMenuEntry = removeNewFileMenuEntry;