@olenbetong/appframe-core 2.11.7 → 2.11.9

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.
@@ -1,26 +1,9 @@
1
- var af = af || {};
2
- af.common = (() => {
1
+ var af;
2
+ (af ||= {}).common = (() => {
3
3
  var __defProp = Object.defineProperty;
4
- var __defProps = Object.defineProperties;
5
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
8
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
- var __spreadValues = (a, b) => {
13
- for (var prop in b || (b = {}))
14
- if (__hasOwnProp.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- if (__getOwnPropSymbols)
17
- for (var prop of __getOwnPropSymbols(b)) {
18
- if (__propIsEnum.call(b, prop))
19
- __defNormalProp(a, prop, b[prop]);
20
- }
21
- return a;
22
- };
23
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
7
  var __export = (target, all) => {
25
8
  for (var name in all)
26
9
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -34,7 +17,6 @@ af.common = (() => {
34
17
  return to;
35
18
  };
36
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
38
20
 
39
21
  // src/index.ts
40
22
  var index_exports = {};
@@ -88,9 +70,7 @@ af.common = (() => {
88
70
 
89
71
  // src/SessionHandler.ts
90
72
  var SessionHandler = class {
91
- constructor() {
92
- __publicField(this, "eventHandler", mitt_default());
93
- }
73
+ eventHandler = mitt_default();
94
74
  authenticated() {
95
75
  this.eventHandler.emit("onAuthenticated");
96
76
  }
@@ -99,7 +79,7 @@ af.common = (() => {
99
79
  let authPromise = new Promise((resolve) => {
100
80
  let eventHandler = () => {
101
81
  this.eventHandler.off("onAuthenticated", eventHandler);
102
- callback == null ? void 0 : callback();
82
+ callback?.();
103
83
  resolve();
104
84
  };
105
85
  this.eventHandler.on("onAuthenticated", eventHandler);
@@ -118,7 +98,7 @@ af.common = (() => {
118
98
  } else {
119
99
  link = "/login?RequireTwoFactor=1&ReturnUrl=%2fapi/sessionexpired/remove";
120
100
  }
121
- dialog.innerHTML = '<iframe sandbox="allow-same-origin allow-scripts allow-modals allow-top-navigation-by-user-activation allow-forms" src="'.concat(link, '" style="border:0;width:min(500px,100vw);height:min(700px, 100vh);"></iframe>');
101
+ dialog.innerHTML = `<iframe sandbox="allow-same-origin allow-scripts allow-modals allow-top-navigation-by-user-activation allow-forms" src="${link}" style="border:0;width:min(500px,100vw);height:min(700px, 100vh);"></iframe>`;
122
102
  document.body.append(dialog);
123
103
  dialog.showModal();
124
104
  await authPromise;
@@ -127,9 +107,9 @@ af.common = (() => {
127
107
  await authPromise;
128
108
  }
129
109
  } catch (_) {
130
- window.location.href = "/login?ReturnUrl=".concat(encodeURIComponent(window.location.pathname)).concat(encodeURIComponent(
110
+ window.location.href = `/login?ReturnUrl=${encodeURIComponent(window.location.pathname)}${encodeURIComponent(
131
111
  window.location.search
132
- ));
112
+ )}`;
133
113
  }
134
114
  }
135
115
  attachEvent(eventName, handler) {
@@ -142,51 +122,49 @@ af.common = (() => {
142
122
 
143
123
  // src/UserSession.ts
144
124
  var UserSession = class extends SessionHandler {
125
+ amDesignator = "a.m.";
126
+ dayNames = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
127
+ dayNamesShort = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"];
128
+ decimalSeparator = ".";
129
+ domain = "OB";
130
+ email;
131
+ formats;
132
+ groupSeparator = null;
133
+ integratedSecurity = false;
134
+ isDeveloper = false;
135
+ login = "";
136
+ loginType;
137
+ monthNames = [
138
+ "january",
139
+ "february",
140
+ "march",
141
+ "april",
142
+ "may",
143
+ "june",
144
+ "july",
145
+ "august",
146
+ "september",
147
+ "october",
148
+ "november",
149
+ "december",
150
+ ""
151
+ ];
152
+ monthNamesShort = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "augt", "sep", "oct", "nov", "dec", ""];
153
+ name;
154
+ pmDesignator = "p.m.";
155
+ shortDateFormat = "dd.MM.yyyy";
156
+ culture = "en-GB";
157
+ uiculture = "en-GB";
145
158
  constructor(userData) {
146
159
  super();
147
- __publicField(this, "amDesignator", "a.m.");
148
- __publicField(this, "dayNames", ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"]);
149
- __publicField(this, "dayNamesShort", ["sun", "mon", "tue", "wed", "thu", "fri", "sat"]);
150
- __publicField(this, "decimalSeparator", ".");
151
- __publicField(this, "domain", "OB");
152
- __publicField(this, "email");
153
- __publicField(this, "formats");
154
- __publicField(this, "groupSeparator", null);
155
- __publicField(this, "integratedSecurity", false);
156
- __publicField(this, "isDeveloper", false);
157
- __publicField(this, "login", "");
158
- __publicField(this, "loginType");
159
- __publicField(this, "monthNames", [
160
- "january",
161
- "february",
162
- "march",
163
- "april",
164
- "may",
165
- "june",
166
- "july",
167
- "august",
168
- "september",
169
- "october",
170
- "november",
171
- "december",
172
- ""
173
- ]);
174
- __publicField(this, "monthNamesShort", ["jan", "feb", "mar", "apr", "may", "jun", "jul", "augt", "sep", "oct", "nov", "dec", ""]);
175
- __publicField(this, "name");
176
- __publicField(this, "pmDesignator", "p.m.");
177
- __publicField(this, "shortDateFormat", "dd.MM.yyyy");
178
- __publicField(this, "culture", "en-GB");
179
- __publicField(this, "uiculture", "en-GB");
180
160
  this.formats = {};
181
161
  Object.assign(this, userData);
182
162
  }
183
163
  };
184
164
 
185
165
  // src/log.ts
186
- var _a, _b, _c, _d;
187
- var article = (_d = (_b = (_a = window.af) == null ? void 0 : _a.article) == null ? void 0 : _b.id) != null ? _d : (_c = window.window) == null ? void 0 : _c.location.pathname.substring(1).split("/")[0];
166
+ var article = window.af?.article?.id ?? window.window?.location.pathname.substring(1).split("/")[0];
188
167
  async function logActivity(activity, parameters = {}, timeElapsed = 0) {
189
- var _a3;
190
168
  try {
191
169
  let response = await fetch("/api/logging/log-activity", {
192
170
  method: "POST",
@@ -194,26 +172,27 @@ af.common = (() => {
194
172
  article,
195
173
  timeElapsed,
196
174
  action: activity,
197
- parameters: __spreadProps(__spreadValues({}, parameters), {
175
+ parameters: {
176
+ ...parameters,
198
177
  _session: getSessionData()
199
- })
178
+ }
200
179
  }),
201
180
  headers: { "Content-Type": "application/json", Accept: "application/json" }
202
181
  });
203
182
  if (!response.ok) {
204
- if ((_a3 = response.headers.get("Content-Type")) == null ? void 0 : _a3.includes("application/json")) {
183
+ if (response.headers.get("Content-Type")?.includes("application/json")) {
205
184
  let data = await response.json();
206
185
  console.error(data.error);
207
186
  } else {
208
- console.error("".concat(response.status, " ").concat(response.statusText));
187
+ console.error(`${response.status} ${response.statusText}`);
209
188
  }
210
189
  }
211
- } catch (error) {
190
+ } catch {
212
191
  }
213
192
  }
214
193
  function startActivity(activity, startParameters = {}) {
215
194
  let start = performance.now();
216
- return (endParameters = {}) => logActivity(activity, __spreadValues(__spreadValues({}, startParameters), endParameters), performance.now() - start);
195
+ return (endParameters = {}) => logActivity(activity, { ...startParameters, ...endParameters }, performance.now() - start);
217
196
  }
218
197
  async function time(callback) {
219
198
  let start = performance.now();
@@ -221,12 +200,11 @@ af.common = (() => {
221
200
  return [returnValue, performance.now() - start];
222
201
  }
223
202
  async function logError(error) {
224
- var _a3;
225
203
  try {
226
204
  if (!error) return;
227
205
  let data = typeof error === "string" ? { error } : typeof error === "object" ? "message" in error ? {
228
206
  error: error.message,
229
- stack: (_a3 = error.stack) != null ? _a3 : null
207
+ stack: error.stack ?? null
230
208
  } : { error: error.toString() } : { error: "Unspecified error" };
231
209
  console.error(error);
232
210
  let result = await fetch("/data/Logger/LogError", {
@@ -240,26 +218,22 @@ af.common = (() => {
240
218
  return await result.json();
241
219
  }
242
220
  console.error(Error("Failed to log error"));
243
- } catch (e) {
221
+ } catch {
244
222
  }
245
223
  }
246
224
  function getSessionId() {
247
- var _a3;
248
- return (_a3 = crypto.randomUUID) == null ? void 0 : _a3.call(crypto);
225
+ return crypto.randomUUID?.();
249
226
  }
250
227
  var sessionStart = Date.now();
251
228
  var sessionId = getSessionId();
252
229
  var deviceId = "";
253
230
  var browserSessionId = "";
254
231
  if ("document" in window) {
255
- let startSession = () => {
256
- var _a3, _b2, _c2, _d2, _e, _f;
257
- return logActivity("AfSessionInit", {
258
- "appframe-core": (_b2 = (_a3 = window.af) == null ? void 0 : _a3.common) == null ? void 0 : _b2.version,
259
- "appframe-data": (_d2 = (_c2 = window.af) == null ? void 0 : _c2.data) == null ? void 0 : _d2.version,
260
- "app-version": (_f = (_e = window.af) == null ? void 0 : _e.article) == null ? void 0 : _f.version
261
- });
262
- };
232
+ let startSession = () => logActivity("AfSessionInit", {
233
+ "appframe-core": window.af?.common?.version,
234
+ "appframe-data": window.af?.data?.version,
235
+ "app-version": window.af?.article?.version
236
+ });
263
237
  document.addEventListener("DOMContentLoaded", () => {
264
238
  deviceId = localStorage.getItem("_afDeviceId");
265
239
  browserSessionId = sessionStorage.getItem("_afSessionId");
@@ -301,9 +275,8 @@ af.common = (() => {
301
275
  }
302
276
 
303
277
  // src/errorHandler.ts
304
- var _a2;
305
278
  if (true) {
306
- (_a2 = window.window) == null ? void 0 : _a2.addEventListener("error", (event) => {
279
+ window.window?.addEventListener("error", (event) => {
307
280
  if (typeof event === "object" && "error" in event) {
308
281
  logError(event.error);
309
282
  } else if (typeof event === "object" && "message" in event) {
@@ -314,13 +287,10 @@ af.common = (() => {
314
287
 
315
288
  // src/localStorage.ts
316
289
  function getLocalKey(key) {
317
- var _a3;
318
- return [((_a3 = af == null ? void 0 : af.article) == null ? void 0 : _a3.id) || "", "common", key].join(".");
290
+ return [af?.article?.id || "", "common", key].join(".");
319
291
  }
320
292
  var LocalStorage = class {
321
- constructor() {
322
- __publicField(this, "isPersisted", () => true);
323
- }
293
+ isPersisted = () => true;
324
294
  getLocalStorageKey(key, global) {
325
295
  return global ? ["common", key].join(".") : getLocalKey(key);
326
296
  }
@@ -360,9 +330,9 @@ af.common = (() => {
360
330
  return String(num).padStart(digits, "0");
361
331
  }
362
332
  function toLocalISODateTime(date) {
363
- return date ? "".concat(date.getFullYear(), "-").concat(pad(date.getMonth() + 1), "-").concat(pad(date.getDate()), "T").concat(pad(date.getHours()), ":").concat(pad(
333
+ return date ? `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(
364
334
  date.getMinutes()
365
- ), ":").concat(pad(date.getSeconds()), ".").concat(pad(date.getMilliseconds(), 3)) : null;
335
+ )}:${pad(date.getSeconds())}.${pad(date.getMilliseconds(), 3)}` : null;
366
336
  }
367
337
  function toLocalDateTime(date) {
368
338
  return date ? date.toISOString().substring(0, 16) : "";
@@ -396,22 +366,21 @@ af.common = (() => {
396
366
  return;
397
367
  }
398
368
  const provided = typeof message === "function" ? message() : message;
399
- throw new Error(provided != null ? provided : "Invariant failed");
369
+ throw new Error(provided ?? "Invariant failed");
400
370
  }
401
371
 
402
372
  // src/downloadRequest.ts
403
373
  async function downloadRequest(request, { fileName, signal, onProgress }) {
404
- var _a3;
405
374
  let bytesReceived = 0;
406
- onProgress == null ? void 0 : onProgress({ status: "requested" });
375
+ onProgress?.({ status: "requested" });
407
376
  try {
408
377
  let response = await fetch(request);
409
378
  if (!response.ok || !response.body) {
410
- if ((_a3 = response.headers.get("content-type")) == null ? void 0 : _a3.includes("application/json")) {
379
+ if (response.headers.get("content-type")?.includes("application/json")) {
411
380
  let data = await response.json();
412
381
  invariant(!data.error, data.error);
413
382
  }
414
- throw new Error("".concat(response.status, " ").concat(response.statusText));
383
+ throw new Error(`${response.status} ${response.statusText}`);
415
384
  }
416
385
  try {
417
386
  const reader = response.body.getReader();
@@ -424,7 +393,7 @@ af.common = (() => {
424
393
  return;
425
394
  }
426
395
  bytesReceived += read.value.length;
427
- onProgress == null ? void 0 : onProgress({ bytesReceived, status: "downloading" });
396
+ onProgress?.({ bytesReceived, status: "downloading" });
428
397
  controller.enqueue(read.value);
429
398
  return pump();
430
399
  });
@@ -433,17 +402,17 @@ af.common = (() => {
433
402
  }
434
403
  });
435
404
  response = new Response(stream);
436
- } catch (error) {
405
+ } catch {
437
406
  }
438
407
  const blob = await response.blob();
439
- onProgress == null ? void 0 : onProgress({ bytesReceived, status: "downloaded" });
408
+ onProgress?.({ bytesReceived, status: "downloaded" });
440
409
  await downloadBlob(blob, fileName);
441
- onProgress == null ? void 0 : onProgress({ bytesReceived, status: "completed" });
410
+ onProgress?.({ bytesReceived, status: "completed" });
442
411
  } catch (err) {
443
- if (signal == null ? void 0 : signal.aborted) {
444
- onProgress == null ? void 0 : onProgress({ status: "cancelled" });
412
+ if (signal?.aborted) {
413
+ onProgress?.({ status: "cancelled" });
445
414
  } else {
446
- onProgress == null ? void 0 : onProgress({ error: err.message, status: "error" });
415
+ onProgress?.({ error: err.message, status: "error" });
447
416
  }
448
417
  }
449
418
  }
@@ -451,10 +420,9 @@ af.common = (() => {
451
420
  // src/parseFunc.ts
452
421
  var funcRegex = /^function(?:\s+([a-zA-Z$_][a-zA-Z0-9$_]*))?\s*\(((?:(?:\s*[a-zA-Z$_][a-zA-Z0-9$_]*)(?:\s*,\s*[a-zA-Z$_][a-zA-Z0-9$_]*)*)?)\s*\)\s*\{((?:.|\n|\r)*)\}$/;
453
422
  function parseFunc(func) {
454
- var _a3;
455
423
  const match = func.toString().match(funcRegex);
456
424
  invariant(match, "Unable to parse function!");
457
- return { name: (_a3 = func.name) != null ? _a3 : match[1], args: match[2].split(",").map((a) => a.trim()), body: match[3] };
425
+ return { name: func.name ?? match[1], args: match[2].split(",").map((a) => a.trim()), body: match[3] };
458
426
  }
459
427
 
460
428
  // src/Namespace.ts
@@ -508,37 +476,18 @@ af.common = (() => {
508
476
  } else {
509
477
  invariant(false, "Invalid typeof parameter 'name', or unable to parse pValue!");
510
478
  }
511
- if (Object.hasOwn(namespace, keyName) && (options == null ? void 0 : options.overwrite) !== true) {
512
- console.warn("".concat([name, keyName].join("."), " is already defined!"));
479
+ if (Object.hasOwn(namespace, keyName) && options?.overwrite !== true) {
480
+ console.warn(`${[name, keyName].join(".")} is already defined!`);
513
481
  } else {
514
482
  namespace[keyName] = value;
515
483
  }
516
484
  }
517
485
  }
518
486
 
519
- // src/getUserImage.ts
520
- var sizeMap = {
521
- xs: 64,
522
- sm: 128,
523
- md: 256,
524
- lg: 512,
525
- xl: void 0
526
- };
527
- function getUserImage(primKeyOrOptions, login, hash, size = "xs") {
528
- if (primKeyOrOptions && typeof primKeyOrOptions === "object") {
529
- return getUserImage(primKeyOrOptions.primKey, primKeyOrOptions.login, primKeyOrOptions.hash, primKeyOrOptions.size);
530
- }
531
- if (!primKeyOrOptions || !hash) {
532
- return "";
533
- }
534
- let sizePx = sizeMap[size];
535
- return "/api/data/blob/EmployeesLookup/".concat(primKeyOrOptions, "/Image/").concat(encodeURIComponent(login != null ? login : "")).concat(login ? "." : "").concat(encodeURIComponent(hash), ".jpg").concat(sizePx ? "?width=".concat(sizePx) : "");
536
- }
537
-
538
487
  // src/getLocalizedString.ts
539
488
  async function fetchLocalizedString(text) {
540
489
  try {
541
- let response = await fetch("/api/user/localize/new/".concat(af.article.id), {
490
+ let response = await fetch(`/api/user/localize/new/${af.article.id}`, {
542
491
  body: JSON.stringify({ text }),
543
492
  headers: {
544
493
  Accept: "application/json; */*",
@@ -550,19 +499,18 @@ af.common = (() => {
550
499
  if (response.ok) {
551
500
  return await response.json();
552
501
  }
553
- } catch (error) {
502
+ } catch {
554
503
  }
555
504
  return text;
556
505
  }
557
506
  function getLocalizedString(string, wait) {
558
- var _a3, _b2;
559
507
  if (typeof string === "string" && string.trim().length === 0) {
560
508
  return string;
561
509
  }
562
510
  if (string === void 0 || string === "" || string === null) {
563
511
  return;
564
512
  }
565
- if (((_b2 = (_a3 = window.af) == null ? void 0 : _a3.article) == null ? void 0 : _b2.i18n) !== void 0) {
513
+ if (window.af?.article?.i18n !== void 0) {
566
514
  if (!Object.hasOwn(af.article.i18n, string)) {
567
515
  af.article.i18n[string] = string;
568
516
  let promise = fetchLocalizedString(string).then((text) => {
@@ -579,51 +527,50 @@ af.common = (() => {
579
527
  }
580
528
  }
581
529
 
530
+ // src/getUserImage.ts
531
+ var sizeMap = {
532
+ xs: 64,
533
+ sm: 128,
534
+ md: 256,
535
+ lg: 512,
536
+ xl: void 0
537
+ };
538
+ function getUserImage(primKeyOrOptions, login, hash, size = "xs") {
539
+ if (primKeyOrOptions && typeof primKeyOrOptions === "object") {
540
+ return getUserImage(primKeyOrOptions.primKey, primKeyOrOptions.login, primKeyOrOptions.hash, primKeyOrOptions.size);
541
+ }
542
+ if (!primKeyOrOptions || !hash) {
543
+ return "";
544
+ }
545
+ let sizePx = sizeMap[size];
546
+ return `/api/data/blob/EmployeesLookup/${primKeyOrOptions}/Image/${encodeURIComponent(login ?? "")}${login ? "." : ""}${encodeURIComponent(hash)}.jpg${sizePx ? `?width=${sizePx}` : ""}`;
547
+ }
548
+
582
549
  // src/localize.ts
583
550
  function localize(stringParts, ...args) {
584
551
  invariant(
585
552
  Array.isArray(stringParts) && stringParts.length === args.length + 1,
586
553
  "Method 'localize' must be used as a tag function"
587
554
  );
588
- let stringToLocalize = stringParts.map((s, i) => i === stringParts.length - 1 ? s : "".concat(s, "$").concat(i)).join("");
555
+ let stringToLocalize = stringParts.map((s, i) => i === stringParts.length - 1 ? s : `${s}$${i}`).join("");
589
556
  let localized = getLocalizedString(stringToLocalize);
590
557
  args.forEach((arg, index) => {
591
- localized = localized.replace("$".concat(index), arg);
558
+ localized = localized.replace(`$${index}`, arg);
592
559
  });
593
560
  return localized;
594
561
  }
595
562
 
596
- // src/settings.ts
597
- function getKey(article2) {
598
- var _a3, _b2, _c2, _d2, _e, _f;
599
- const articleKey = (_d2 = article2 != null ? article2 : (_b2 = (_a3 = window.af) == null ? void 0 : _a3.article) == null ? void 0 : _b2.id) != null ? _d2 : (_c2 = window.window) == null ? void 0 : _c2.location.pathname.substring(1).split("/")[0];
600
- return "".concat(articleKey, ".").concat((_f = (_e = window.af) == null ? void 0 : _e.userSession.login) != null ? _f : "anonymous");
601
- }
602
- function getSettings(setting, article2) {
603
- var _a3;
604
- if (!((_a3 = window.af) == null ? void 0 : _a3.userSession)) return null;
605
- const key = getKey(article2);
606
- const settings = JSON.parse(localStorage.getItem(key) || "{}");
607
- if (setting) {
608
- return settings[setting] || null;
609
- }
610
- return settings;
611
- }
612
- function saveSettings(setting, value, article2) {
613
- var _a3;
614
- if (!((_a3 = window.af) == null ? void 0 : _a3.userSession)) return;
615
- const key = getKey(article2);
616
- let userSettings = JSON.parse(localStorage.getItem(key) || "{}");
617
- if (typeof value !== "undefined") {
618
- userSettings[setting] = value;
619
- } else {
620
- userSettings = setting;
621
- }
622
- localStorage.setItem(key, JSON.stringify(userSettings));
623
- }
624
-
625
563
  // src/alert.ts
626
- var template = '\n <dialog class="alert-dialog">\n <form method="dialog">\n <article></article>\n <footer>\n <menu></menu>\n </footer>\n </form>\n </dialog>\n';
564
+ var template = `
565
+ <dialog class="alert-dialog">
566
+ <form method="dialog">
567
+ <article></article>
568
+ <footer>
569
+ <menu></menu>
570
+ </footer>
571
+ </form>
572
+ </dialog>
573
+ `;
627
574
  if (window.document && !document.querySelector("#AlertDialogTemplate")) {
628
575
  let $template = document.createElement("template");
629
576
  $template.id = "AlertDialogTemplate";
@@ -653,25 +600,24 @@ af.common = (() => {
653
600
  }
654
601
  var alertDialogPromiseMap = /* @__PURE__ */ new Map();
655
602
  async function openAlertDialog({ buttons, content, className, id, title }) {
656
- var _a3, _b2;
657
603
  if (id && alertDialogPromiseMap.has(id)) {
658
604
  return await alertDialogPromiseMap.get(id);
659
605
  }
660
606
  let $template = document.querySelector("#AlertDialogTemplate");
661
607
  if (!$template) throw Error("No alert dialog template found");
662
- let $dialog = (_a3 = $template.content.firstElementChild) == null ? void 0 : _a3.cloneNode(true);
663
- let $content = $dialog == null ? void 0 : $dialog.querySelector("article");
664
- let $menu = $dialog == null ? void 0 : $dialog.querySelector("footer menu");
608
+ let $dialog = $template.content.firstElementChild?.cloneNode(true);
609
+ let $content = $dialog?.querySelector("article");
610
+ let $menu = $dialog?.querySelector("footer menu");
665
611
  if (!$dialog || !$content || !$menu) throw Error("Invalid alert dialog template");
666
612
  if (className) {
667
613
  for (const className_ of className.split(/\s+/)) {
668
- $dialog == null ? void 0 : $dialog.classList.add(className_);
614
+ $dialog?.classList.add(className_);
669
615
  }
670
616
  }
671
617
  if (title) {
672
618
  let $header = document.createElement("header");
673
619
  $header.append(title);
674
- (_b2 = $content.parentNode) == null ? void 0 : _b2.insertBefore($header, $content);
620
+ $content.parentNode?.insertBefore($header, $content);
675
621
  }
676
622
  $content.appendChild(typeof content === "string" ? document.createTextNode(content) : content);
677
623
  for (let { label, value, primary } of buttons) {
@@ -717,14 +663,41 @@ af.common = (() => {
717
663
  return result === "yes";
718
664
  }
719
665
  async function alert(prompt, options = {}) {
720
- await openAlertDialog(__spreadValues({
666
+ await openAlertDialog({
721
667
  content: prompt,
722
668
  className: "alert-dialog-alert",
723
- buttons: [{ label: getLocalizedString("OK"), value: "ok", primary: true }]
724
- }, options));
669
+ buttons: [{ label: getLocalizedString("OK"), value: "ok", primary: true }],
670
+ ...options
671
+ });
672
+ }
673
+
674
+ // src/settings.ts
675
+ function getKey(article2) {
676
+ const articleKey = article2 ?? window.af?.article?.id ?? window.window?.location.pathname.substring(1).split("/")[0];
677
+ return `${articleKey}.${window.af?.userSession.login ?? "anonymous"}`;
678
+ }
679
+ function getSettings(setting, article2) {
680
+ if (!window.af?.userSession) return null;
681
+ const key = getKey(article2);
682
+ const settings = JSON.parse(localStorage.getItem(key) || "{}");
683
+ if (setting) {
684
+ return settings[setting] || null;
685
+ }
686
+ return settings;
687
+ }
688
+ function saveSettings(setting, value, article2) {
689
+ if (!window.af?.userSession) return;
690
+ const key = getKey(article2);
691
+ let userSettings = JSON.parse(localStorage.getItem(key) || "{}");
692
+ if (typeof value !== "undefined") {
693
+ userSettings[setting] = value;
694
+ } else {
695
+ userSettings = setting;
696
+ }
697
+ localStorage.setItem(key, JSON.stringify(userSettings));
725
698
  }
726
699
 
727
700
  // src/index.ts
728
- var version = "2.11.7";
701
+ var version = "2.11.9";
729
702
  return __toCommonJS(index_exports);
730
703
  })();
@@ -1,2 +1,11 @@
1
- var af=af||{};af.common=(()=>{var A=Object.defineProperty,ye=Object.defineProperties,he=Object.getOwnPropertyDescriptor,Se=Object.getOwnPropertyDescriptors,be=Object.getOwnPropertyNames,q=Object.getOwnPropertySymbols;var k=Object.prototype.hasOwnProperty,xe=Object.prototype.propertyIsEnumerable;var O=(e,t,o)=>t in e?A(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,g=(e,t)=>{for(var o in t||(t={}))k.call(t,o)&&O(e,o,t[o]);if(q)for(var o of q(t))xe.call(t,o)&&O(e,o,t[o]);return e},B=(e,t)=>ye(e,Se(t));var we=(e,t)=>{for(var o in t)A(e,o,{get:t[o],enumerable:!0})},ve=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of be(t))!k.call(e,r)&&r!==o&&A(e,r,{get:()=>t[r],enumerable:!(n=he(t,r))||n.enumerable});return e};var De=e=>ve(A({},"__esModule",{value:!0}),e);var l=(e,t,o)=>O(e,typeof t!="symbol"?t+"":t,o);var je={};we(je,{ConfirmButtons:()=>M,SessionHandler:()=>p,UserSession:()=>L,alert:()=>fe,confirm:()=>de,downloadBlob:()=>j,downloadRequest:()=>re,expose:()=>_,getLocalizedString:()=>u,getSessionData:()=>E,getSettings:()=>ce,getUserImage:()=>U,invariant:()=>c,localStorage:()=>te,localize:()=>le,logActivity:()=>T,logError:()=>w,mitt:()=>I,openAlertDialog:()=>z,saveSettings:()=>ue,startActivity:()=>X,time:()=>G,toLocalDateTime:()=>oe,toLocalISODate:()=>ne,toLocalISODateTime:()=>$,version:()=>Ee,waitForDialog:()=>H});function I(e){return{all:e=e||new Map,on:function(t,o){var n=e.get(t);n?n.push(o):e.set(t,[o])},off:function(t,o){var n=e.get(t);n&&(o?n.splice(n.indexOf(o)>>>0,1):e.set(t,[]))},emit:function(t,o){var n=e.get(t);n&&n.slice().map(function(r){r(o)}),(n=e.get("*"))&&n.slice().map(function(r){r(t,o)})}}}var p=class{constructor(){l(this,"eventHandler",I())}authenticated(){this.eventHandler.emit("onAuthenticated")}async expired(t,o){try{let n=new Promise(i=>{let a=()=>{this.eventHandler.off("onAuthenticated",a),t==null||t(),i()};this.eventHandler.on("onAuthenticated",a)}),r=document.querySelector("dialog.session-expired-dialog");if(r)await n;else{r=document.createElement("dialog"),r.className="session-expired-dialog",r.style.display="flex",r.style.padding="0",r.style.left="50%",r.style.transform="translateX(-50%)";let i="/login?ReturnUrl=%2fapi/sessionexpired/remove";o!=="RequireTwoFactor"?await fetch("/logout",{method:"POST"}):i="/login?RequireTwoFactor=1&ReturnUrl=%2fapi/sessionexpired/remove",r.innerHTML='<iframe sandbox="allow-same-origin allow-scripts allow-modals allow-top-navigation-by-user-activation allow-forms" src="'.concat(i,'" style="border:0;width:min(500px,100vw);height:min(700px, 100vh);"></iframe>'),document.body.append(r),r.showModal(),await n,r.remove()}}catch(n){window.location.href="/login?ReturnUrl=".concat(encodeURIComponent(window.location.pathname)).concat(encodeURIComponent(window.location.search))}}attachEvent(t,o){return this.eventHandler.on(t,o)}detachEvent(t,o){return this.eventHandler.off(t,o)}};var L=class extends p{constructor(o){super();l(this,"amDesignator","a.m.");l(this,"dayNames",["sunday","monday","tuesday","wednesday","thursday","friday","saturday"]);l(this,"dayNamesShort",["sun","mon","tue","wed","thu","fri","sat"]);l(this,"decimalSeparator",".");l(this,"domain","OB");l(this,"email");l(this,"formats");l(this,"groupSeparator",null);l(this,"integratedSecurity",!1);l(this,"isDeveloper",!1);l(this,"login","");l(this,"loginType");l(this,"monthNames",["january","february","march","april","may","june","july","august","september","october","november","december",""]);l(this,"monthNamesShort",["jan","feb","mar","apr","may","jun","jul","augt","sep","oct","nov","dec",""]);l(this,"name");l(this,"pmDesignator","p.m.");l(this,"shortDateFormat","dd.MM.yyyy");l(this,"culture","en-GB");l(this,"uiculture","en-GB");this.formats={},Object.assign(this,o)}};var J,K,V,Z,Y=(Z=(K=(J=window.af)==null?void 0:J.article)==null?void 0:K.id)!=null?Z:(V=window.window)==null?void 0:V.location.pathname.substring(1).split("/")[0];async function T(e,t={},o=0){var n;try{let r=await fetch("/api/logging/log-activity",{method:"POST",body:JSON.stringify({article:Y,timeElapsed:o,action:e,parameters:B(g({},t),{_session:E()})}),headers:{"Content-Type":"application/json",Accept:"application/json"}});if(!r.ok)if((n=r.headers.get("Content-Type"))!=null&&n.includes("application/json")){let i=await r.json();console.error(i.error)}else console.error("".concat(r.status," ").concat(r.statusText))}catch(r){}}function X(e,t={}){let o=performance.now();return(n={})=>T(e,g(g({},t),n),performance.now()-o)}async function G(e){let t=performance.now();return[await e(),performance.now()-t]}async function w(e){var t;try{if(!e)return;let o=typeof e=="string"?{error:e}:typeof e=="object"?"message"in e?{error:e.message,stack:(t=e.stack)!=null?t:null}:{error:e.toString()}:{error:"Unspecified error"};console.error(e);let n=await fetch("/data/Logger/LogError",{method:"POST",body:JSON.stringify(o),headers:{"Content-Type":"application/json; charset=utf-8"}});if(n.ok)return await n.json();console.error(Error("Failed to log error"))}catch(o){}}function W(){var e;return(e=crypto.randomUUID)==null?void 0:e.call(crypto)}var F=Date.now(),Q=W(),b="",x="";if("document"in window){let e=()=>{var t,o,n,r,i,a;return T("AfSessionInit",{"appframe-core":(o=(t=window.af)==null?void 0:t.common)==null?void 0:o.version,"appframe-data":(r=(n=window.af)==null?void 0:n.data)==null?void 0:r.version,"app-version":(a=(i=window.af)==null?void 0:i.article)==null?void 0:a.version})};document.addEventListener("DOMContentLoaded",()=>{b=localStorage.getItem("_afDeviceId"),x=sessionStorage.getItem("_afSessionId"),b||(b=W(),localStorage.setItem("_afDeviceId",b)),x||(x=Q,sessionStorage.setItem("_afSessionId",x)),e()}),document.addEventListener("visibilitychange",function(){document.visibilityState==="hidden"?navigator.sendBeacon("/api/logging/log-activity",JSON.stringify({article:Y,action:"AfSessionEnd",parameters:{_session:E()}})):e()})}function E(){return{browserSessionId:x,sessionStart:F,sessionLength:Date.now()-F,sessionId:Q,deviceId:b}}var P;(P=window.window)==null||P.addEventListener("error",e=>{typeof e=="object"&&"error"in e?w(e.error):typeof e=="object"&&"message"in e&&w(e)});function ee(e){var t;return[((t=af==null?void 0:af.article)==null?void 0:t.id)||"","common",e].join(".")}var N=class{constructor(){l(this,"isPersisted",()=>!0)}getLocalStorageKey(t,o){return o?["common",t].join("."):ee(t)}get(t,o,n){let r=this.getLocalStorageKey(t,n),i=localStorage.getItem(r);return i!==null?JSON.parse(i):o}set(t,o,n){localStorage.setItem(this.getLocalStorageKey(t,n),JSON.stringify(o))}remove(t,o){let n=this.getLocalStorageKey(t,o);return localStorage.getItem(n)!==null?(localStorage.removeItem(n),!0):!1}clear(){let t=ee("");for(let o in localStorage)o.slice(0,t.length)===t&&localStorage.removeItem(o)}},te=new N;function ne(e){return e?$(e).substring(0,10):null}function m(e,t=2){return String(e).padStart(t,"0")}function $(e){return e?"".concat(e.getFullYear(),"-").concat(m(e.getMonth()+1),"-").concat(m(e.getDate()),"T").concat(m(e.getHours()),":").concat(m(e.getMinutes()),":").concat(m(e.getSeconds()),".").concat(m(e.getMilliseconds(),3)):null}function oe(e){return e?e.toISOString().substring(0,16):""}function j(e,t){return new Promise((o,n)=>{try{let r=URL.createObjectURL(e),i=document.body,a=document.createElement("a");a.setAttribute("download",t),a.href=r,i.append(a),a.click(),i.removeChild(a),setTimeout(()=>{URL.revokeObjectURL(r),o()},250)}catch(r){n(r)}})}function c(e,t){if(e)return;let o=typeof t=="function"?t():t;throw new Error(o!=null?o:"Invariant failed")}async function re(e,{fileName:t,signal:o,onProgress:n}){var i;let r=0;n==null||n({status:"requested"});try{let a=await fetch(e);if(!a.ok||!a.body){if((i=a.headers.get("content-type"))!=null&&i.includes("application/json")){let f=await a.json();c(!f.error,f.error)}throw new Error("".concat(a.status," ").concat(a.statusText))}try{let f=a.body.getReader(),D=new ReadableStream({start:y=>{function h(){return f.read().then(s=>{if(s.done){y.close();return}return r+=s.value.length,n==null||n({bytesReceived:r,status:"downloading"}),y.enqueue(s.value),h()})}return h()}});a=new Response(D)}catch(f){}let d=await a.blob();n==null||n({bytesReceived:r,status:"downloaded"}),await j(d,t),n==null||n({bytesReceived:r,status:"completed"})}catch(a){o!=null&&o.aborted?n==null||n({status:"cancelled"}):n==null||n({error:a.message,status:"error"})}}var Ae=/^function(?:\s+([a-zA-Z$_][a-zA-Z0-9$_]*))?\s*\(((?:(?:\s*[a-zA-Z$_][a-zA-Z0-9$_]*)(?:\s*,\s*[a-zA-Z$_][a-zA-Z0-9$_]*)*)?)\s*\)\s*\{((?:.|\n|\r)*)\}$/;function R(e){var o;let t=e.toString().match(Ae);return c(t,"Unable to parse function!"),{name:(o=e.name)!=null?o:t[1],args:t[2].split(",").map(n=>n.trim()),body:t[3]}}function ie(){}ie.prototype=Object.create(null);var ae=ie;function C(e,t){if(typeof e=="object"){if(typeof t=="string"){let o=t.split(".");return C(e,o)}else if(Array.isArray(t)){let o=e;for(let n=0;n<t.length;n++)o=o[t[n]]=o[t[n]]||new ae;return o}}}function _(e,t,o={}){if(Array.isArray(t))for(let n of t){let{name:r}=R(n);c(r,"Unable to detect name of function! Name it, or only supply one function and include name in first parameter."),_(e,n)}else{let n,r;if(typeof t=="function"&&(n=R(t).name),typeof e=="string"){let i=e.split(".");n||(n=i[i.length-1],i=i.slice(0,i.length-1)),r=C(window,i)}else n&&(typeof e=="object"||typeof e=="function")?r=e:c(!1,"Invalid typeof parameter 'name', or unable to parse pValue!");Object.hasOwn(r,n)&&(o==null?void 0:o.overwrite)!==!0?console.warn("".concat([e,n].join(".")," is already defined!")):r[n]=t}}var Ie={xs:64,sm:128,md:256,lg:512,xl:void 0};function U(e,t,o,n="xs"){if(e&&typeof e=="object")return U(e.primKey,e.login,e.hash,e.size);if(!e||!o)return"";let r=Ie[n];return"/api/data/blob/EmployeesLookup/".concat(e,"/Image/").concat(encodeURIComponent(t!=null?t:"")).concat(t?".":"").concat(encodeURIComponent(o),".jpg").concat(r?"?width=".concat(r):"")}async function Le(e){try{let t=await fetch("/api/user/localize/new/".concat(af.article.id),{body:JSON.stringify({text:e}),headers:{Accept:"application/json; */*","Content-Type":"application/json","X-Requested-With":"XMLHttpRequest"},method:"POST"});if(t.ok)return await t.json()}catch(t){}return e}function u(e,t){var o,n;if(typeof e=="string"&&e.trim().length===0)return e;if(!(e===void 0||e===""||e===null))if(((n=(o=window.af)==null?void 0:o.article)==null?void 0:n.i18n)!==void 0){if(!Object.hasOwn(af.article.i18n,e)){af.article.i18n[e]=e;let r=Le(e).then(i=>(af.article.i18n[e]=i,i));if(t)return r}return af.article.i18n[e]}else return e}function le(e,...t){c(Array.isArray(e)&&e.length===t.length+1,"Method 'localize' must be used as a tag function");let o=e.map((r,i)=>i===e.length-1?r:"".concat(r,"$").concat(i)).join(""),n=u(o);return t.forEach((r,i)=>{n=n.replace("$".concat(i),r)}),n}function se(e){var o,n,r,i,a,d;let t=(i=e!=null?e:(n=(o=window.af)==null?void 0:o.article)==null?void 0:n.id)!=null?i:(r=window.window)==null?void 0:r.location.pathname.substring(1).split("/")[0];return"".concat(t,".").concat((d=(a=window.af)==null?void 0:a.userSession.login)!=null?d:"anonymous")}function ce(e,t){var r;if(!((r=window.af)!=null&&r.userSession))return null;let o=se(t),n=JSON.parse(localStorage.getItem(o)||"{}");return e?n[e]||null:n}function ue(e,t,o){var i;if(!((i=window.af)!=null&&i.userSession))return;let n=se(o),r=JSON.parse(localStorage.getItem(n)||"{}");typeof t<"u"?r[e]=t:r=e,localStorage.setItem(n,JSON.stringify(r))}var Te='\n <dialog class="alert-dialog">\n <form method="dialog">\n <article></article>\n <footer>\n <menu></menu>\n </footer>\n </form>\n </dialog>\n';if(window.document&&!document.querySelector("#AlertDialogTemplate")){let e=document.createElement("template");e.id="AlertDialogTemplate",e.innerHTML=Te,document.body.append(e)}function H(e,t="No"){return new Promise(o=>{let n=new AbortController;e.addEventListener("close",()=>{o(e.returnValue),n.abort()},{signal:n.signal}),e.addEventListener("cancel",()=>{o(t),n.abort()},{signal:n.signal})})}var v=new Map;async function z({buttons:e,content:t,className:o,id:n,title:r}){var y,h;if(n&&v.has(n))return await v.get(n);let i=document.querySelector("#AlertDialogTemplate");if(!i)throw Error("No alert dialog template found");let a=(y=i.content.firstElementChild)==null?void 0:y.cloneNode(!0),d=a==null?void 0:a.querySelector("article"),f=a==null?void 0:a.querySelector("footer menu");if(!a||!d||!f)throw Error("Invalid alert dialog template");if(o)for(let s of o.split(/\s+/))a==null||a.classList.add(s);if(r){let s=document.createElement("header");s.append(r),(h=d.parentNode)==null||h.insertBefore(s,d)}d.appendChild(typeof t=="string"?document.createTextNode(t):t);for(let{label:s,value:pe,primary:ge}of e){let me=document.createElement("li"),S=document.createElement("button");S.value=pe,ge&&S.classList.add("primary"),S.textContent=s,me.appendChild(S),f.appendChild(S)}document.body.appendChild(a),a.showModal();let D=H(a).then(s=>(n&&v.has(n)&&v.delete(n),a&&document.body.removeChild(a),s));return n&&v.set(n,D),await D}var M=(o=>(o[o.YesNo=0]="YesNo",o[o.OkCancel=1]="OkCancel",o))(M||{});async function de(e,t={}){let{buttons:o=0,title:n}=t,r=o===1?[{label:u("OK"),value:"yes",primary:!0},{label:u("Cancel"),value:"no"}]:[{label:u("Yes"),value:"yes",primary:!0},{label:u("No"),value:"no"}];return await z({content:e,buttons:r,className:"alert-dialog-confirm",title:n})==="yes"}async function fe(e,t={}){await z(g({content:e,className:"alert-dialog-alert",buttons:[{label:u("OK"),value:"ok",primary:!0}]},t))}var Ee="2.11.7";return De(je);})();
1
+ var af;(af||={}).common=(()=>{var T=Object.defineProperty;var ne=Object.getOwnPropertyDescriptor;var re=Object.getOwnPropertyNames;var ie=Object.prototype.hasOwnProperty;var ae=(e,t)=>{for(var n in t)T(e,n,{get:t[n],enumerable:!0})},le=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of re(t))!ie.call(e,r)&&r!==n&&T(e,r,{get:()=>t[r],enumerable:!(o=ne(t,r))||o.enumerable});return e};var se=e=>le(T({},"__esModule",{value:!0}),e);var fe={};ae(fe,{ConfirmButtons:()=>C,SessionHandler:()=>g,UserSession:()=>v,alert:()=>G,confirm:()=>X,downloadBlob:()=>I,downloadRequest:()=>K,expose:()=>O,getLocalizedString:()=>c,getSessionData:()=>A,getSettings:()=>Q,getUserImage:()=>N,invariant:()=>s,localStorage:()=>B,localize:()=>Y,logActivity:()=>D,logError:()=>b,mitt:()=>w,openAlertDialog:()=>L,saveSettings:()=>ee,startActivity:()=>H,time:()=>M,toLocalDateTime:()=>J,toLocalISODate:()=>F,toLocalISODateTime:()=>j,version:()=>pe,waitForDialog:()=>R});function w(e){return{all:e=e||new Map,on:function(t,n){var o=e.get(t);o?o.push(n):e.set(t,[n])},off:function(t,n){var o=e.get(t);o&&(n?o.splice(o.indexOf(n)>>>0,1):e.set(t,[]))},emit:function(t,n){var o=e.get(t);o&&o.slice().map(function(r){r(n)}),(o=e.get("*"))&&o.slice().map(function(r){r(t,n)})}}}var g=class{eventHandler=w();authenticated(){this.eventHandler.emit("onAuthenticated")}async expired(t,n){try{let o=new Promise(i=>{let a=()=>{this.eventHandler.off("onAuthenticated",a),t?.(),i()};this.eventHandler.on("onAuthenticated",a)}),r=document.querySelector("dialog.session-expired-dialog");if(r)await o;else{r=document.createElement("dialog"),r.className="session-expired-dialog",r.style.display="flex",r.style.padding="0",r.style.left="50%",r.style.transform="translateX(-50%)";let i="/login?ReturnUrl=%2fapi/sessionexpired/remove";n!=="RequireTwoFactor"?await fetch("/logout",{method:"POST"}):i="/login?RequireTwoFactor=1&ReturnUrl=%2fapi/sessionexpired/remove",r.innerHTML=`<iframe sandbox="allow-same-origin allow-scripts allow-modals allow-top-navigation-by-user-activation allow-forms" src="${i}" style="border:0;width:min(500px,100vw);height:min(700px, 100vh);"></iframe>`,document.body.append(r),r.showModal(),await o,r.remove()}}catch{window.location.href=`/login?ReturnUrl=${encodeURIComponent(window.location.pathname)}${encodeURIComponent(window.location.search)}`}}attachEvent(t,n){return this.eventHandler.on(t,n)}detachEvent(t,n){return this.eventHandler.off(t,n)}};var v=class extends g{amDesignator="a.m.";dayNames=["sunday","monday","tuesday","wednesday","thursday","friday","saturday"];dayNamesShort=["sun","mon","tue","wed","thu","fri","sat"];decimalSeparator=".";domain="OB";email;formats;groupSeparator=null;integratedSecurity=!1;isDeveloper=!1;login="";loginType;monthNames=["january","february","march","april","may","june","july","august","september","october","november","december",""];monthNamesShort=["jan","feb","mar","apr","may","jun","jul","augt","sep","oct","nov","dec",""];name;pmDesignator="p.m.";shortDateFormat="dd.MM.yyyy";culture="en-GB";uiculture="en-GB";constructor(t){super(),this.formats={},Object.assign(this,t)}};var U=window.af?.article?.id??window.window?.location.pathname.substring(1).split("/")[0];async function D(e,t={},n=0){try{let o=await fetch("/api/logging/log-activity",{method:"POST",body:JSON.stringify({article:U,timeElapsed:n,action:e,parameters:{...t,_session:A()}}),headers:{"Content-Type":"application/json",Accept:"application/json"}});if(!o.ok)if(o.headers.get("Content-Type")?.includes("application/json")){let r=await o.json();console.error(r.error)}else console.error(`${o.status} ${o.statusText}`)}catch{}}function H(e,t={}){let n=performance.now();return(o={})=>D(e,{...t,...o},performance.now()-n)}async function M(e){let t=performance.now();return[await e(),performance.now()-t]}async function b(e){try{if(!e)return;let t=typeof e=="string"?{error:e}:typeof e=="object"?"message"in e?{error:e.message,stack:e.stack??null}:{error:e.toString()}:{error:"Unspecified error"};console.error(e);let n=await fetch("/data/Logger/LogError",{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json; charset=utf-8"}});if(n.ok)return await n.json();console.error(Error("Failed to log error"))}catch{}}function k(){return crypto.randomUUID?.()}var _=Date.now(),P=k(),y="",h="";if("document"in window){let e=()=>D("AfSessionInit",{"appframe-core":window.af?.common?.version,"appframe-data":window.af?.data?.version,"app-version":window.af?.article?.version});document.addEventListener("DOMContentLoaded",()=>{y=localStorage.getItem("_afDeviceId"),h=sessionStorage.getItem("_afSessionId"),y||(y=k(),localStorage.setItem("_afDeviceId",y)),h||(h=P,sessionStorage.setItem("_afSessionId",h)),e()}),document.addEventListener("visibilitychange",function(){document.visibilityState==="hidden"?navigator.sendBeacon("/api/logging/log-activity",JSON.stringify({article:U,action:"AfSessionEnd",parameters:{_session:A()}})):e()})}function A(){return{browserSessionId:h,sessionStart:_,sessionLength:Date.now()-_,sessionId:P,deviceId:y}}window.window?.addEventListener("error",e=>{typeof e=="object"&&"error"in e?b(e.error):typeof e=="object"&&"message"in e&&b(e)});function q(e){return[af?.article?.id||"","common",e].join(".")}var E=class{isPersisted=()=>!0;getLocalStorageKey(t,n){return n?["common",t].join("."):q(t)}get(t,n,o){let r=this.getLocalStorageKey(t,o),i=localStorage.getItem(r);return i!==null?JSON.parse(i):n}set(t,n,o){localStorage.setItem(this.getLocalStorageKey(t,o),JSON.stringify(n))}remove(t,n){let o=this.getLocalStorageKey(t,n);return localStorage.getItem(o)!==null?(localStorage.removeItem(o),!0):!1}clear(){let t=q("");for(let n in localStorage)n.slice(0,t.length)===t&&localStorage.removeItem(n)}},B=new E;function F(e){return e?j(e).substring(0,10):null}function d(e,t=2){return String(e).padStart(t,"0")}function j(e){return e?`${e.getFullYear()}-${d(e.getMonth()+1)}-${d(e.getDate())}T${d(e.getHours())}:${d(e.getMinutes())}:${d(e.getSeconds())}.${d(e.getMilliseconds(),3)}`:null}function J(e){return e?e.toISOString().substring(0,16):""}function I(e,t){return new Promise((n,o)=>{try{let r=URL.createObjectURL(e),i=document.body,a=document.createElement("a");a.setAttribute("download",t),a.href=r,i.append(a),a.click(),i.removeChild(a),setTimeout(()=>{URL.revokeObjectURL(r),n()},250)}catch(r){o(r)}})}function s(e,t){if(e)return;let n=typeof t=="function"?t():t;throw new Error(n??"Invariant failed")}async function K(e,{fileName:t,signal:n,onProgress:o}){let r=0;o?.({status:"requested"});try{let i=await fetch(e);if(!i.ok||!i.body){if(i.headers.get("content-type")?.includes("application/json")){let u=await i.json();s(!u.error,u.error)}throw new Error(`${i.status} ${i.statusText}`)}try{let u=i.body.getReader(),x=new ReadableStream({start:p=>{function l(){return u.read().then(f=>{if(f.done){p.close();return}return r+=f.value.length,o?.({bytesReceived:r,status:"downloading"}),p.enqueue(f.value),l()})}return l()}});i=new Response(x)}catch{}let a=await i.blob();o?.({bytesReceived:r,status:"downloaded"}),await I(a,t),o?.({bytesReceived:r,status:"completed"})}catch(i){n?.aborted?o?.({status:"cancelled"}):o?.({error:i.message,status:"error"})}}var ce=/^function(?:\s+([a-zA-Z$_][a-zA-Z0-9$_]*))?\s*\(((?:(?:\s*[a-zA-Z$_][a-zA-Z0-9$_]*)(?:\s*,\s*[a-zA-Z$_][a-zA-Z0-9$_]*)*)?)\s*\)\s*\{((?:.|\n|\r)*)\}$/;function z(e){let t=e.toString().match(ce);return s(t,"Unable to parse function!"),{name:e.name??t[1],args:t[2].split(",").map(n=>n.trim()),body:t[3]}}function V(){}V.prototype=Object.create(null);var Z=V;function $(e,t){if(typeof e=="object"){if(typeof t=="string"){let n=t.split(".");return $(e,n)}else if(Array.isArray(t)){let n=e;for(let o=0;o<t.length;o++)n=n[t[o]]=n[t[o]]||new Z;return n}}}function O(e,t,n={}){if(Array.isArray(t))for(let o of t){let{name:r}=z(o);s(r,"Unable to detect name of function! Name it, or only supply one function and include name in first parameter."),O(e,o)}else{let o,r;if(typeof t=="function"&&(o=z(t).name),typeof e=="string"){let i=e.split(".");o||(o=i[i.length-1],i=i.slice(0,i.length-1)),r=$(window,i)}else o&&(typeof e=="object"||typeof e=="function")?r=e:s(!1,"Invalid typeof parameter 'name', or unable to parse pValue!");Object.hasOwn(r,o)&&n?.overwrite!==!0?console.warn(`${[e,o].join(".")} is already defined!`):r[o]=t}}async function ue(e){try{let t=await fetch(`/api/user/localize/new/${af.article.id}`,{body:JSON.stringify({text:e}),headers:{Accept:"application/json; */*","Content-Type":"application/json","X-Requested-With":"XMLHttpRequest"},method:"POST"});if(t.ok)return await t.json()}catch{}return e}function c(e,t){if(typeof e=="string"&&e.trim().length===0)return e;if(!(e===void 0||e===""||e===null))if(window.af?.article?.i18n!==void 0){if(!Object.hasOwn(af.article.i18n,e)){af.article.i18n[e]=e;let n=ue(e).then(o=>(af.article.i18n[e]=o,o));if(t)return n}return af.article.i18n[e]}else return e}var ge={xs:64,sm:128,md:256,lg:512,xl:void 0};function N(e,t,n,o="xs"){if(e&&typeof e=="object")return N(e.primKey,e.login,e.hash,e.size);if(!e||!n)return"";let r=ge[o];return`/api/data/blob/EmployeesLookup/${e}/Image/${encodeURIComponent(t??"")}${t?".":""}${encodeURIComponent(n)}.jpg${r?`?width=${r}`:""}`}function Y(e,...t){s(Array.isArray(e)&&e.length===t.length+1,"Method 'localize' must be used as a tag function");let n=e.map((r,i)=>i===e.length-1?r:`${r}$${i}`).join(""),o=c(n);return t.forEach((r,i)=>{o=o.replace(`$${i}`,r)}),o}var de=`
2
+ <dialog class="alert-dialog">
3
+ <form method="dialog">
4
+ <article></article>
5
+ <footer>
6
+ <menu></menu>
7
+ </footer>
8
+ </form>
9
+ </dialog>
10
+ `;if(window.document&&!document.querySelector("#AlertDialogTemplate")){let e=document.createElement("template");e.id="AlertDialogTemplate",e.innerHTML=de,document.body.append(e)}function R(e,t="No"){return new Promise(n=>{let o=new AbortController;e.addEventListener("close",()=>{n(e.returnValue),o.abort()},{signal:o.signal}),e.addEventListener("cancel",()=>{n(t),o.abort()},{signal:o.signal})})}var S=new Map;async function L({buttons:e,content:t,className:n,id:o,title:r}){if(o&&S.has(o))return await S.get(o);let i=document.querySelector("#AlertDialogTemplate");if(!i)throw Error("No alert dialog template found");let a=i.content.firstElementChild?.cloneNode(!0),u=a?.querySelector("article"),x=a?.querySelector("footer menu");if(!a||!u||!x)throw Error("Invalid alert dialog template");if(n)for(let l of n.split(/\s+/))a?.classList.add(l);if(r){let l=document.createElement("header");l.append(r),u.parentNode?.insertBefore(l,u)}u.appendChild(typeof t=="string"?document.createTextNode(t):t);for(let{label:l,value:f,primary:te}of e){let oe=document.createElement("li"),m=document.createElement("button");m.value=f,te&&m.classList.add("primary"),m.textContent=l,oe.appendChild(m),x.appendChild(m)}document.body.appendChild(a),a.showModal();let p=R(a).then(l=>(o&&S.has(o)&&S.delete(o),a&&document.body.removeChild(a),l));return o&&S.set(o,p),await p}var C=(n=>(n[n.YesNo=0]="YesNo",n[n.OkCancel=1]="OkCancel",n))(C||{});async function X(e,t={}){let{buttons:n=0,title:o}=t,r=n===1?[{label:c("OK"),value:"yes",primary:!0},{label:c("Cancel"),value:"no"}]:[{label:c("Yes"),value:"yes",primary:!0},{label:c("No"),value:"no"}];return await L({content:e,buttons:r,className:"alert-dialog-confirm",title:o})==="yes"}async function G(e,t={}){await L({content:e,className:"alert-dialog-alert",buttons:[{label:c("OK"),value:"ok",primary:!0}],...t})}function W(e){return`${e??window.af?.article?.id??window.window?.location.pathname.substring(1).split("/")[0]}.${window.af?.userSession.login??"anonymous"}`}function Q(e,t){if(!window.af?.userSession)return null;let n=W(t),o=JSON.parse(localStorage.getItem(n)||"{}");return e?o[e]||null:o}function ee(e,t,n){if(!window.af?.userSession)return;let o=W(n),r=JSON.parse(localStorage.getItem(o)||"{}");typeof t<"u"?r[e]=t:r=e,localStorage.setItem(o,JSON.stringify(r))}var pe="2.11.9";return se(fe);})();
2
11
  //# sourceMappingURL=af.common.legacy.min.js.map