@nextcloud/files 3.2.1 → 3.3.1

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