@nextcloud/files 3.2.1 → 3.3.0

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