@nextcloud/files 3.2.1 → 3.3.0

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