UNPKG

@eva-ics/webengine-react

Version:

React components for EVA ICS HMI Web Engine

1,515 lines (1,512 loc) 108 kB
import { EvaError as we, EvaErrorKind as ne, StateProp as Te, EventKind as Oe } from "@eva-ics/webengine"; import Ne, { useState as _e, useEffect as se, useRef as xe, useCallback as ge, useId as ar, useMemo as Ze } from "react"; import { cookies as fe } from "bmat/dom"; import nr from "react-qr-code"; import _t from "react-hot-toast"; import { calculateFormula as Ce } from "bmat/numbers"; import { Doughnut as sr, Radar as ir, Bar as or, Line as cr } from "react-chartjs-2"; import { deepMerge as lr } from "bmat/tools"; import { DashTableColType as ur, generateDashTableRichCSV as dr } from "bmat/dashtable"; const hr = new Error("request for lock canceled"); var fr = function(e, t, s, n) { function i(c) { return c instanceof s ? c : new s(function(o) { o(c); }); } return new (s || (s = Promise))(function(c, o) { function d(f) { try { g(n.next(f)); } catch (u) { o(u); } } function l(f) { try { g(n.throw(f)); } catch (u) { o(u); } } function g(f) { f.done ? c(f.value) : i(f.value).then(d, l); } g((n = n.apply(e, t || [])).next()); }); }; class gr { constructor(t, s = hr) { this._value = t, this._cancelError = s, this._weightedQueues = [], this._weightedWaiters = []; } acquire(t = 1) { if (t <= 0) throw new Error(`invalid weight ${t}: must be positive`); return new Promise((s, n) => { this._weightedQueues[t - 1] || (this._weightedQueues[t - 1] = []), this._weightedQueues[t - 1].push({ resolve: s, reject: n }), this._dispatch(); }); } runExclusive(t, s = 1) { return fr(this, void 0, void 0, function* () { const [n, i] = yield this.acquire(s); try { return yield t(n); } finally { i(); } }); } waitForUnlock(t = 1) { if (t <= 0) throw new Error(`invalid weight ${t}: must be positive`); return new Promise((s) => { this._weightedWaiters[t - 1] || (this._weightedWaiters[t - 1] = []), this._weightedWaiters[t - 1].push(s), this._dispatch(); }); } isLocked() { return this._value <= 0; } getValue() { return this._value; } setValue(t) { this._value = t, this._dispatch(); } release(t = 1) { if (t <= 0) throw new Error(`invalid weight ${t}: must be positive`); this._value += t, this._dispatch(); } cancel() { this._weightedQueues.forEach((t) => t.forEach((s) => s.reject(this._cancelError))), this._weightedQueues = []; } _dispatch() { var t; for (let s = this._value; s > 0; s--) { const n = (t = this._weightedQueues[s - 1]) === null || t === void 0 ? void 0 : t.shift(); if (!n) continue; const i = this._value, c = s; this._value -= s, s = this._value + 1, n.resolve([i, this._newReleaser(c)]); } this._drainUnlockWaiters(); } _newReleaser(t) { let s = !1; return () => { s || (s = !0, this.release(t)); }; } _drainUnlockWaiters() { for (let t = this._value; t > 0; t--) this._weightedWaiters[t - 1] && (this._weightedWaiters[t - 1].forEach((s) => s()), this._weightedWaiters[t - 1] = []); } } var vr = function(e, t, s, n) { function i(c) { return c instanceof s ? c : new s(function(o) { o(c); }); } return new (s || (s = Promise))(function(c, o) { function d(f) { try { g(n.next(f)); } catch (u) { o(u); } } function l(f) { try { g(n.throw(f)); } catch (u) { o(u); } } function g(f) { f.done ? c(f.value) : i(f.value).then(d, l); } g((n = n.apply(e, t || [])).next()); }); }; class mr { constructor(t) { this._semaphore = new gr(1, t); } acquire() { return vr(this, void 0, void 0, function* () { const [, t] = yield this._semaphore.acquire(); return t; }); } runExclusive(t) { return this._semaphore.runExclusive(() => t()); } isLocked() { return this._semaphore.isLocked(); } waitForUnlock() { return this._semaphore.waitForUnlock(); } release() { this._semaphore.isLocked() && this._semaphore.release(); } cancel() { return this._semaphore.cancel(); } } var xr = Object.defineProperty, br = (e, t, s) => t in e ? xr(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s, L = (e, t, s) => br(e, typeof t != "symbol" ? t + "" : t, s); const _r = "0.1.0"; let et = null; const yr = (e) => { et = e, et.we_multimedia_version = _r; }; var Rt = /* @__PURE__ */ ((e) => (e.None = "none", e.KeepWidth = "keep-width", e.KeepHeight = "keep-height", e.Resize = "resize", e))(Rt || {}); class jr { constructor(t) { L(this, "name"), L(this, "decoder"), L(this, "engine"), L(this, "autoSize"), L(this, "canvas"), L(this, "onFrame"), L(this, "onError"), L(this, "onEOS"), L(this, "paused"), L(this, "drawNext", "none"), L(this, "drawNextError"), L(this, "frameCounter"), this.name = t.name, this.canvas = t.canvas; const s = t.engine || et; if (!s) throw new Error("EVA ICS WebEngine not set"); this.engine = s, this.autoSize = t.autoSize ?? "none", this.onFrame = t.onFrame, this.onError = t.onError, this.onEOS = t.onEOS, this.paused = !1, this.frameCounter = 0, this.decoder = new wr(), this.decoder.setPreferredHardwareAcceleration( t.decoderHardwareAcceleration ?? !0 ), this.decoder.fallbackToSoftware = t.decoderFallbackToSoftware ?? !0, this.decoder.onError = (i) => { console.error(`Error in decoder: ${i.message} (${i.code})`), t.onError && t.onError(i), this.messageError(i), this.close(); }; const n = this.autoSize; this.decoder.onChange = (i) => { switch (n) { case "keep-width": this.canvas.height = this.canvas.width * i.height / i.width; break; case "keep-height": this.canvas.width = this.canvas.height * i.width / i.height; break; case "resize": this.canvas.width = i.width, this.canvas.height = i.height; break; } this.messageStart(), t.onChange && t.onChange(i); }, this.decoder.onOutput = (i) => { if (this.frameCounter++, this.frameCounter > 10 && (this.drawNext = "none", this.drawNextError = void 0), !this.paused) { const c = t.canvas.getContext("2d"); c == null || c.drawImage( i, 0, 0, t.canvas.width, t.canvas.height ); } this.onFrame && this.onFrame(); }; } message(t, s, n = "white") { const i = this.canvas.getContext("2d"); i.fillStyle = "black", i.fillRect(0, 0, this.canvas.width, this.canvas.height), i.fillStyle = n, i.font = `bold ${s}px sans-serif`, i.textAlign = "center", i.textBaseline = "middle", i.fillText(t, this.canvas.width / 2, this.canvas.height / 2); } pause() { this.paused = !0; } resume() { switch (this.paused = !1, this.drawNext) { case "eos": this.messageEOS(); break; case "start": this.messageStart(); break; case "error": this.drawNextError && this.messageError(this.drawNextError); break; } } togglePause() { this.isPlaying() ? this.pause() : this.resume(); } isPlaying() { return !this.paused; } messageStart() { this.paused ? this.drawNext = "start" : this.message("...", 50); } messageEOS() { this.paused ? this.drawNext = "eos" : this.message("EOS", 50); } messageError(t) { this.paused ? (this.drawNext = "error", this.drawNextError = t) : this.message(`Error: ${t.message} (${t.code})`, 12, "red"); } start(t) { this.engine.start_stream({ oid: t, name: this.name, onError: (s) => { this.messageError(s), this.onError && this.onError(s), this.close(); }, onData: (s) => { this.decoder.decode(s); }, onStart: () => { this.messageStart(), this.frameCounter = 0; }, onEOS: () => { this.messageEOS(), this.frameCounter = 0; } }); } close() { this.engine.stop_stream(this.name), this.decoder.close(); } } class wr { constructor() { L(this, "first_key_received"), L(this, "decoder"), L(this, "codec"), L(this, "width"), L(this, "height"), L(this, "hardwareAcceleration"), L(this, "actualHardwareAcceleration"), L(this, "fallback"), L(this, "fallbackToSoftware"), L(this, "onOutput"), L(this, "onChange"), L(this, "onError"), this.onOutput = () => { }, this.onChange = () => { }, this.onError = (t) => { console.error("VideoDecoder error:", t); }, this.hardwareAcceleration = !0, this.actualHardwareAcceleration = !0, this.fallbackToSoftware = !0, this.first_key_received = !1, this.fallback = !1; } setPreferredHardwareAcceleration(t) { this.hardwareAcceleration = t; } isHardwareAccelerationEnabled() { return this.actualHardwareAcceleration; } close() { var t; try { (t = this.decoder) == null || t.close(); } catch { } this.decoder = void 0, this.codec = void 0, this.width = void 0, this.height = void 0, this.first_key_received = !1, this.fallback = !1; } decode(t) { var s, n; const i = new Nr(t); if (!i.format) throw new we( ne.INVALID_DATA, "Unsupported video format in frame" ); if ((!this.decoder || this.decoder.state === "closed" || this.codec !== i.format || this.width !== i.width || this.height !== i.height) && (this._createDecoder(i), this.first_key_received = !1, this.fallback ? this.fallback = !1 : this.actualHardwareAcceleration = this.hardwareAcceleration, this.onChange({ width: i.width, height: i.height, codec: i.format, hardwareAcceleration: this.actualHardwareAcceleration })), !this.first_key_received) if (i.isKey()) this.first_key_received = !0; else return !1; const c = new EncodedVideoChunk({ type: i.isKey() ? "key" : "delta", timestamp: 0, // Timestamp is not used in this example data: i.data }); try { (s = this.decoder) == null || s.decode(c); } catch (o) { try { (n = this.decoder) == null || n.close(); } catch { } return this.decoder = void 0, this.fallbackToSoftware && this.actualHardwareAcceleration ? (this.actualHardwareAcceleration = !1, this.fallback = !0, !1) : (this.onError(new we(ne.FUNC_FAILED, o)), !1); } return !0; } _createDecoder(t) { var s; if (this.codec = t.format, this.width = t.width, this.height = t.height, !this.codec) throw new we( ne.INVALID_DATA, "Unsupported video format in frame" ); try { (s = this.decoder) == null || s.close(); } catch { } this.decoder = new VideoDecoder({ output: (i) => { this.onOutput(i); try { i.close(); } catch { } }, error: (i) => { this.onError(i); } }); const n = { codec: this.codec }; switch (this.codec) { case "avc1.42E01E": n.optimizeForLatency = !0, n.hardwareAcceleration = this.isHardwareAccelerationEnabled() ? "prefer-hardware" : "prefer-software"; break; case "hvc1.1.6.L93.00": n.optimizeForLatency = !0, n.hardwareAcceleration = this.isHardwareAccelerationEnabled() ? "prefer-hardware" : "prefer-software"; break; case "vp8": n.optimizeForLatency = !0; break; case "vp09.00.10.08": n.optimizeForLatency = !0, n.hardwareAcceleration = this.isHardwareAccelerationEnabled() ? "prefer-hardware" : "prefer-software"; break; case "av01.0.05M.08": n.optimizeForLatency = !0, n.hardwareAcceleration = this.isHardwareAccelerationEnabled() ? "prefer-hardware" : "prefer-software"; break; } this.decoder.configure(n); } } class Nr { constructor(t) { L(this, "version"), L(this, "format"), L(this, "width"), L(this, "height"), L(this, "metadata"), L(this, "data"); const s = new Uint8Array(t, 0, 3); if (s[0] !== 69 || s[1] !== 86 || s[2] !== 83) throw new we( ne.INVALID_DATA, "Invalid magic number in video frame data" ); const n = new Uint8Array(t, 3, 10), i = n[0]; if (i !== 1) throw new we( ne.INVALID_DATA, `Unsupported video frame version: ${i}` ); switch (this.version = i, n[1]) { case 10: this.format = "avc1.42E01E"; break; case 11: this.format = "hvc1.1.6.L93.00"; break; case 12: this.format = "vp8"; break; case 13: this.format = "vp09.00.10.08"; break; case 14: this.format = "av01.0.05M.08"; break; } this.width = n[3] << 8 | n[2], this.height = n[5] << 8 | n[4], this.metadata = n[6], this.data = new Uint8Array(t, 10); } isKey() { return (this.metadata & 1) !== 0; } } const pr = "0.5.18"; let be = null, yt = new mr(); const qe = () => be, aa = (e) => { be = e, be.wer_version = pr, yr(be); }, pe = (e, t) => { const [s, n] = _e({}), i = e.engine || be; return se(() => { const c = (o) => { n(o); }; if (e.oid) if (i) i.watch(e.oid, c, !1, !0); else throw new Error("EVA ICS WebEngine not set"); else n({}); return () => { i && e.oid && i.unwatch(e.oid, c); }; }, t), s; }, na = (e, t) => { const [s, n] = _e({}), i = e.engine || be; return se(() => { const c = (o) => { o.oid && n((d) => ({ ...d, [o.oid]: o })); }; if (e.oid && e.oid.length > 0) if (i) e.oid.forEach((o) => { i.watch(o, c, !1, !0); }); else throw new Error("EVA ICS WebEngine not set"); else n({}); return () => { i && e.oid && e.oid.length > 0 && (n({}), e.oid.forEach((o) => { i.unwatch(o, c); })); }; }, t), s; }, sa = (e, t) => { const s = e.engine || be; if (!s) throw new Error("EVA ICS WebEngine not set"); return se(() => (s.register_state_block(e.name, e.state_updates), () => { s.unregister_state_block(e.name); }), t); }, Er = (e, t) => { const [s, n] = _e({ data: null }), i = xe(!1), c = xe(null), o = xe({ enabled: !0 }), d = e.engine || be; let l = e.update ? e.update * 1e3 : 1e3; isNaN(l) ? l = 1e3 : l < 100 && (l = 100); const g = ge(() => { if (!i.current) { c.current = null, o.current.enabled = !1, o.current = { enabled: !1 }, n({ data: null }); return; } o.current = { enabled: !0 }; const f = o.current; if (d && d.logged_in) { let u = e.timeframe || "1H"; Array.isArray(u) || (u = [u]); let m = 0, j = u.map((x, w) => { let A = x.split(":"), k = A[0]; k.startsWith("t") && (k = k.substr(1), m = w); let b = A[1] || null, _ = e.args, y = e.prop === void 0 ? Te.Value : e.prop == Te.Any ? null : e.prop, E = { s: k, e: b, x: y, w: e.fill + (e.digits === void 0 ? "" : `:${e.digits}`), ..._ }; return d.call( "item.state_history", e.oid, E ); }); Promise.all(j).then((x) => { x.t = x[m].t, f.enabled && (n({ data: x }), c.current = setTimeout(g, l)); }).catch((x) => { f.enabled && (n({ data: null, error: x }), c.current = setTimeout(g, l)); }); } else n({ data: null }), c.current = setTimeout( g, e.update_uninit ? e.update_uninit * 1e3 : l ); }, t); return se(() => { if (i.current = !0, !c.current) if (d) typeof e.oid == "string" || Array.isArray(e.oid) && e.oid.length > 0 ? g() : n({ data: null, error: Array.isArray(e.oid) ? void 0 : new we(ne.INVALID_PARAMS, "OID not specified") }); else throw new Error("EVA ICS WebEngine not set"); return () => { i.current = !1, clearTimeout(c.current), n({ data: null }), c.current = null, o.current.enabled = !1, o.current = { enabled: !1 }; }; }, [g]), s; }, ia = (e, t) => { const [s, n] = _e({ data: null }), i = xe(!1), c = xe(null), o = xe({ enabled: !0 }), d = e.engine || be; let l = e.update ? e.update * 1e3 : 1e3; isNaN(l) ? l = 1e3 : l < 100 && (l = 100); const g = ge(() => { if (!i.current) { c.current = null, o.current.enabled = !1, o.current = { enabled: !1 }, n({ data: null }); return; } o.current = { enabled: !0 }; const f = o.current; d && d.logged_in && e.method ? d.call(e.method, e.params).then((u) => { f.enabled && (n({ data: u }), c.current = setTimeout(g, l)); }).catch((u) => { f.enabled && (n({ data: null, error: u }), c.current = setTimeout(g, l)); }) : (n({ data: null }), c.current = setTimeout( g, e.update_uninit ? e.update_uninit * 1e3 : l )); }, [e.method, e.params, l, e.update_uninit]); return se(() => { if (i.current = !0, !c.current) if (d) e.method ? g() : n({ data: null }); else throw new Error("EVA ICS WebEngine not set"); return () => { i.current = !1, clearTimeout(c.current), n({ data: null }), c.current = null, o.current.enabled = !1, o.current = { enabled: !1 }; }; }, t), s; }; var kr = /* @__PURE__ */ ((e) => (e[e.Working = 0] = "Working", e[e.Active = 1] = "Active", e[e.Failed = 2] = "Failed", e))(kr || {}); const oa = (e, t) => { const [s, n] = _e( 0 /* Working */ ), i = e.engine || be; return se(() => { let c = !1; if (i) n( 0 /* Working */ ), yt.acquire().then((o) => { e.keep && (c = i.state_updates); let d = e.state_updates; e.append && (i.state_updates === !0 ? d = !0 : Array.isArray(i.state_updates) && Array.isArray(d) && (d = [].concat(i.state_updates).concat(d))), i.state_updates === d ? (o(), n( 1 /* Active */ )) : i.set_state_updates(d, e.clear_existing).then(() => n( 1 /* Active */ )).catch((l) => { i.log.error(l), n( 2 /* Failed */ ); }).finally(() => o()); }); else throw new Error("EVA ICS WebEngine not set"); return () => { i && yt.acquire().then((o) => { c === i.state_updates ? o() : i.set_state_updates(c, e.clear_existing).catch((d) => i.log.error(d)).finally(() => o()); }); }; }, t), s; }, jt = "progress-color", wt = "warning-progress-color", Nt = "critical-progress-color", rt = (e, t, s, n, i, c) => t === void 0 || isNaN(t) ? `${e}-${jt}` : c !== void 0 && t <= c ? `${e}-${Nt}` : i !== void 0 && t <= i ? `${e}-${wt}` : n !== void 0 && t >= n ? `${e}-${Nt}` : s !== void 0 && t >= s ? `${e}-${wt}` : `${e}-${jt}`; var tt = { exports: {} }, $e = {}; /** * @license React * react-jsx-runtime.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var pt; function Rr() { if (pt) return $e; pt = 1; var e = Ne, t = Symbol.for("react.element"), s = Symbol.for("react.fragment"), n = Object.prototype.hasOwnProperty, i = e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, c = { key: !0, ref: !0, __self: !0, __source: !0 }; function o(d, l, g) { var f, u = {}, m = null, j = null; g !== void 0 && (m = "" + g), l.key !== void 0 && (m = "" + l.key), l.ref !== void 0 && (j = l.ref); for (f in l) n.call(l, f) && !c.hasOwnProperty(f) && (u[f] = l[f]); if (d && d.defaultProps) for (f in l = d.defaultProps, l) u[f] === void 0 && (u[f] = l[f]); return { $$typeof: t, type: d, key: m, ref: j, props: u, _owner: i.current }; } return $e.Fragment = s, $e.jsx = o, $e.jsxs = o, $e; } var De = {}; /** * @license React * react-jsx-runtime.development.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var Et; function Sr() { return Et || (Et = 1, process.env.NODE_ENV !== "production" && function() { var e = Ne, t = Symbol.for("react.element"), s = Symbol.for("react.portal"), n = Symbol.for("react.fragment"), i = Symbol.for("react.strict_mode"), c = Symbol.for("react.profiler"), o = Symbol.for("react.provider"), d = Symbol.for("react.context"), l = Symbol.for("react.forward_ref"), g = Symbol.for("react.suspense"), f = Symbol.for("react.suspense_list"), u = Symbol.for("react.memo"), m = Symbol.for("react.lazy"), j = Symbol.for("react.offscreen"), x = Symbol.iterator, w = "@@iterator"; function A(a) { if (a === null || typeof a != "object") return null; var h = x && a[x] || a[w]; return typeof h == "function" ? h : null; } var k = e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; function b(a) { { for (var h = arguments.length, v = new Array(h > 1 ? h - 1 : 0), R = 1; R < h; R++) v[R - 1] = arguments[R]; _("error", a, v); } } function _(a, h, v) { { var R = k.ReactDebugCurrentFrame, $ = R.getStackAddendum(); $ !== "" && (h += "%s", v = v.concat([$])); var M = v.map(function(O) { return String(O); }); M.unshift("Warning: " + h), Function.prototype.apply.call(console[a], console, M); } } var y = !1, E = !1, N = !1, T = !1, S = !1, C; C = Symbol.for("react.module.reference"); function D(a) { return !!(typeof a == "string" || typeof a == "function" || a === n || a === c || S || a === i || a === g || a === f || T || a === j || y || E || N || typeof a == "object" && a !== null && (a.$$typeof === m || a.$$typeof === u || a.$$typeof === o || a.$$typeof === d || a.$$typeof === l || // This needs to include all possible module reference object // types supported by any Flight configuration anywhere since // we don't know which Flight build this will end up being used // with. a.$$typeof === C || a.getModuleId !== void 0)); } function I(a, h, v) { var R = a.displayName; if (R) return R; var $ = h.displayName || h.name || ""; return $ !== "" ? v + "(" + $ + ")" : v; } function W(a) { return a.displayName || "Context"; } function F(a) { if (a == null) return null; if (typeof a.tag == "number" && b("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof a == "function") return a.displayName || a.name || null; if (typeof a == "string") return a; switch (a) { case n: return "Fragment"; case s: return "Portal"; case c: return "Profiler"; case i: return "StrictMode"; case g: return "Suspense"; case f: return "SuspenseList"; } if (typeof a == "object") switch (a.$$typeof) { case d: var h = a; return W(h) + ".Consumer"; case o: var v = a; return W(v._context) + ".Provider"; case l: return I(a, a.render, "ForwardRef"); case u: var R = a.displayName || null; return R !== null ? R : F(a.type) || "Memo"; case m: { var $ = a, M = $._payload, O = $._init; try { return F(O(M)); } catch { return null; } } } return null; } var p = Object.assign, z = 0, U, H, J, X, q, Q, te; function re() { } re.__reactDisabledLog = !0; function ie() { { if (z === 0) { U = console.log, H = console.info, J = console.warn, X = console.error, q = console.group, Q = console.groupCollapsed, te = console.groupEnd; var a = { configurable: !0, enumerable: !0, value: re, writable: !0 }; Object.defineProperties(console, { info: a, log: a, warn: a, error: a, group: a, groupCollapsed: a, groupEnd: a }); } z++; } } function B() { { if (z--, z === 0) { var a = { configurable: !0, enumerable: !0, writable: !0 }; Object.defineProperties(console, { log: p({}, a, { value: U }), info: p({}, a, { value: H }), warn: p({}, a, { value: J }), error: p({}, a, { value: X }), group: p({}, a, { value: q }), groupCollapsed: p({}, a, { value: Q }), groupEnd: p({}, a, { value: te }) }); } z < 0 && b("disabledDepth fell below zero. This is a bug in React. Please file an issue."); } } var ce = k.ReactCurrentDispatcher, Y; function Ee(a, h, v) { { if (Y === void 0) try { throw Error(); } catch ($) { var R = $.stack.trim().match(/\n( *(at )?)/); Y = R && R[1] || ""; } return ` ` + Y + a; } } var Be = !1, Me; { var Ft = typeof WeakMap == "function" ? WeakMap : Map; Me = new Ft(); } function st(a, h) { if (!a || Be) return ""; { var v = Me.get(a); if (v !== void 0) return v; } var R; Be = !0; var $ = Error.prepareStackTrace; Error.prepareStackTrace = void 0; var M; M = ce.current, ce.current = null, ie(); try { if (h) { var O = function() { throw Error(); }; if (Object.defineProperty(O.prototype, "props", { set: function() { throw Error(); } }), typeof Reflect == "object" && Reflect.construct) { try { Reflect.construct(O, []); } catch (ae) { R = ae; } Reflect.construct(a, [], O); } else { try { O.call(); } catch (ae) { R = ae; } a.call(O.prototype); } } else { try { throw Error(); } catch (ae) { R = ae; } a(); } } catch (ae) { if (ae && R && typeof ae.stack == "string") { for (var P = ae.stack.split(` `), ee = R.stack.split(` `), G = P.length - 1, V = ee.length - 1; G >= 1 && V >= 0 && P[G] !== ee[V]; ) V--; for (; G >= 1 && V >= 0; G--, V--) if (P[G] !== ee[V]) { if (G !== 1 || V !== 1) do if (G--, V--, V < 0 || P[G] !== ee[V]) { var oe = ` ` + P[G].replace(" at new ", " at "); return a.displayName && oe.includes("<anonymous>") && (oe = oe.replace("<anonymous>", a.displayName)), typeof a == "function" && Me.set(a, oe), oe; } while (G >= 1 && V >= 0); break; } } } finally { Be = !1, ce.current = M, B(), Error.prepareStackTrace = $; } var Re = a ? a.displayName || a.name : "", je = Re ? Ee(Re) : ""; return typeof a == "function" && Me.set(a, je), je; } function Pt(a, h, v) { return st(a, !1); } function Ot(a) { var h = a.prototype; return !!(h && h.isReactComponent); } function Ue(a, h, v) { if (a == null) return ""; if (typeof a == "function") return st(a, Ot(a)); if (typeof a == "string") return Ee(a); switch (a) { case g: return Ee("Suspense"); case f: return Ee("SuspenseList"); } if (typeof a == "object") switch (a.$$typeof) { case l: return Pt(a.render); case u: return Ue(a.type, h, v); case m: { var R = a, $ = R._payload, M = R._init; try { return Ue(M($), h, v); } catch { } } } return ""; } var Fe = Object.prototype.hasOwnProperty, it = {}, ot = k.ReactDebugCurrentFrame; function ze(a) { if (a) { var h = a._owner, v = Ue(a.type, a._source, h ? h.type : null); ot.setExtraStackFrame(v); } else ot.setExtraStackFrame(null); } function $t(a, h, v, R, $) { { var M = Function.call.bind(Fe); for (var O in a) if (M(a, O)) { var P = void 0; try { if (typeof a[O] != "function") { var ee = Error((R || "React class") + ": " + v + " type `" + O + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof a[O] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`."); throw ee.name = "Invariant Violation", ee; } P = a[O](h, O, R, v, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"); } catch (G) { P = G; } P && !(P instanceof Error) && (ze($), b("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", R || "React class", v, O, typeof P), ze(null)), P instanceof Error && !(P.message in it) && (it[P.message] = !0, ze($), b("Failed %s type: %s", v, P.message), ze(null)); } } } var Dt = Array.isArray; function Ge(a) { return Dt(a); } function Lt(a) { { var h = typeof Symbol == "function" && Symbol.toStringTag, v = h && a[Symbol.toStringTag] || a.constructor.name || "Object"; return v; } } function It(a) { try { return ct(a), !1; } catch { return !0; } } function ct(a) { return "" + a; } function lt(a) { if (It(a)) return b("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", Lt(a)), ct(a); } var Pe = k.ReactCurrentOwner, Wt = { key: !0, ref: !0, __self: !0, __source: !0 }, ut, dt, Ve; Ve = {}; function Mt(a) { if (Fe.call(a, "ref")) { var h = Object.getOwnPropertyDescriptor(a, "ref").get; if (h && h.isReactWarning) return !1; } return a.ref !== void 0; } function Ut(a) { if (Fe.call(a, "key")) { var h = Object.getOwnPropertyDescriptor(a, "key").get; if (h && h.isReactWarning) return !1; } return a.key !== void 0; } function zt(a, h) { if (typeof a.ref == "string" && Pe.current && h && Pe.current.stateNode !== h) { var v = F(Pe.current.type); Ve[v] || (b('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref', F(Pe.current.type), a.ref), Ve[v] = !0); } } function Ht(a, h) { { var v = function() { ut || (ut = !0, b("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", h)); }; v.isReactWarning = !0, Object.defineProperty(a, "key", { get: v, configurable: !0 }); } } function Yt(a, h) { { var v = function() { dt || (dt = !0, b("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", h)); }; v.isReactWarning = !0, Object.defineProperty(a, "ref", { get: v, configurable: !0 }); } } var qt = function(a, h, v, R, $, M, O) { var P = { // This tag allows us to uniquely identify this as a React Element $$typeof: t, // Built-in properties that belong on the element type: a, key: h, ref: v, props: O, // Record the component responsible for creating this element. _owner: M }; return P._store = {}, Object.defineProperty(P._store, "validated", { configurable: !1, enumerable: !1, writable: !0, value: !1 }), Object.defineProperty(P, "_self", { configurable: !1, enumerable: !1, writable: !1, value: R }), Object.defineProperty(P, "_source", { configurable: !1, enumerable: !1, writable: !1, value: $ }), Object.freeze && (Object.freeze(P.props), Object.freeze(P)), P; }; function Bt(a, h, v, R, $) { { var M, O = {}, P = null, ee = null; v !== void 0 && (lt(v), P = "" + v), Ut(h) && (lt(h.key), P = "" + h.key), Mt(h) && (ee = h.ref, zt(h, $)); for (M in h) Fe.call(h, M) && !Wt.hasOwnProperty(M) && (O[M] = h[M]); if (a && a.defaultProps) { var G = a.defaultProps; for (M in G) O[M] === void 0 && (O[M] = G[M]); } if (P || ee) { var V = typeof a == "function" ? a.displayName || a.name || "Unknown" : a; P && Ht(O, V), ee && Yt(O, V); } return qt(a, P, ee, $, R, Pe.current, O); } } var Je = k.ReactCurrentOwner, ht = k.ReactDebugCurrentFrame; function ke(a) { if (a) { var h = a._owner, v = Ue(a.type, a._source, h ? h.type : null); ht.setExtraStackFrame(v); } else ht.setExtraStackFrame(null); } var Qe; Qe = !1; function Xe(a) { return typeof a == "object" && a !== null && a.$$typeof === t; } function ft() { { if (Je.current) { var a = F(Je.current.type); if (a) return ` Check the render method of \`` + a + "`."; } return ""; } } function Gt(a) { { if (a !== void 0) { var h = a.fileName.replace(/^.*[\\\/]/, ""), v = a.lineNumber; return ` Check your code at ` + h + ":" + v + "."; } return ""; } } var gt = {}; function Vt(a) { { var h = ft(); if (!h) { var v = typeof a == "string" ? a : a.displayName || a.name; v && (h = ` Check the top-level render call using <` + v + ">."); } return h; } } function vt(a, h) { { if (!a._store || a._store.validated || a.key != null) return; a._store.validated = !0; var v = Vt(h); if (gt[v]) return; gt[v] = !0; var R = ""; a && a._owner && a._owner !== Je.current && (R = " It was passed a child from " + F(a._owner.type) + "."), ke(a), b('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', v, R), ke(null); } } function mt(a, h) { { if (typeof a != "object") return; if (Ge(a)) for (var v = 0; v < a.length; v++) { var R = a[v]; Xe(R) && vt(R, h); } else if (Xe(a)) a._store && (a._store.validated = !0); else if (a) { var $ = A(a); if (typeof $ == "function" && $ !== a.entries) for (var M = $.call(a), O; !(O = M.next()).done; ) Xe(O.value) && vt(O.value, h); } } } function Jt(a) { { var h = a.type; if (h == null || typeof h == "string") return; var v; if (typeof h == "function") v = h.propTypes; else if (typeof h == "object" && (h.$$typeof === l || // Note: Memo only checks outer props here. // Inner props are checked in the reconciler. h.$$typeof === u)) v = h.propTypes; else return; if (v) { var R = F(h); $t(v, a.props, "prop", R, a); } else if (h.PropTypes !== void 0 && !Qe) { Qe = !0; var $ = F(h); b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", $ || "Unknown"); } typeof h.getDefaultProps == "function" && !h.getDefaultProps.isReactClassApproved && b("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead."); } } function Qt(a) { { for (var h = Object.keys(a.props), v = 0; v < h.length; v++) { var R = h[v]; if (R !== "children" && R !== "key") { ke(a), b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", R), ke(null); break; } } a.ref !== null && (ke(a), b("Invalid attribute `ref` supplied to `React.Fragment`."), ke(null)); } } var xt = {}; function bt(a, h, v, R, $, M) { { var O = D(a); if (!O) { var P = ""; (a === void 0 || typeof a == "object" && a !== null && Object.keys(a).length === 0) && (P += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports."); var ee = Gt($); ee ? P += ee : P += ft(); var G; a === null ? G = "null" : Ge(a) ? G = "array" : a !== void 0 && a.$$typeof === t ? (G = "<" + (F(a.type) || "Unknown") + " />", P = " Did you accidentally export a JSX literal instead of a component?") : G = typeof a, b("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", G, P); } var V = Bt(a, h, v, $, M); if (V == null) return V; if (O) { var oe = h.children; if (oe !== void 0) if (R) if (Ge(oe)) { for (var Re = 0; Re < oe.length; Re++) mt(oe[Re], a); Object.freeze && Object.freeze(oe); } else b("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."); else mt(oe, a); } if (Fe.call(h, "key")) { var je = F(a), ae = Object.keys(h).filter(function(rr) { return rr !== "key"; }), Ke = ae.length > 0 ? "{key: someKey, " + ae.join(": ..., ") + ": ...}" : "{key: someKey}"; if (!xt[je + Ke]) { var tr = ae.length > 0 ? "{" + ae.join(": ..., ") + ": ...}" : "{}"; b(`A props object containing a "key" prop is being spread into JSX: let props = %s; <%s {...props} /> React keys must be passed directly to JSX without using spread: let props = %s; <%s key={someKey} {...props} />`, Ke, je, tr, je), xt[je + Ke] = !0; } } return a === n ? Qt(V) : Jt(V), V; } } function Xt(a, h, v) { return bt(a, h, v, !0); } function Kt(a, h, v) { return bt(a, h, v, !1); } var Zt = Kt, er = Xt; De.Fragment = n, De.jsx = Zt, De.jsxs = er; }()), De; } process.env.NODE_ENV === "production" ? tt.exports = Rr() : tt.exports = Sr(); var r = tt.exports, Ar = /* @__PURE__ */ ((e) => (e.LoginSession = "login_session", e.LoginAuto = "login_auto", e.Login = "login", e.OtpSetup = "otp_setup", e.OtpAuth = "otp_auth", e.LoginForm = "login_form", e.Active = "active", e))(Ar || {}), Tr = /* @__PURE__ */ ((e) => (e.Default = "default", e.Retry = "retry", e.Abort = "abort", e))(Tr || {}); const Cr = (e, t, s) => { let n; t === "warning" || t === "error" ? n = _t.error : n = _t.success; let i = s; i === void 0 && (i = 5), n(e, { duration: i * 1e3 }); }, ca = ({ engine: e, Dashboard: t, login_props: s }) => { var f; const [n, i] = _e({ state: "login_session" /* LoginSession */ }), c = ge( (u) => { s != null && s.state_announce && s.state_announce({ ...u }), i(u); }, [s == null ? void 0 : s.state_announce] ), o = e || qe(); if (!o) throw new Error("EVA ICS WebEngine not set"); const [d, l] = _e({ login: "", password: "", remember: !0 }), g = ge(async () => { try { try { fe.erase( "auth_password" /* Password */ ); } catch { } await o.stop(), o.clear_auth(); } catch { } c({ state: "login_form" /* LoginForm */ }); }, [o]); if (se(() => { if (s != null && s.register_globals) { o.register_globals(); const u = window; u.$eva.hmi == null && (u.$eva.hmi = {}); const m = u.$eva.hmi; m.logout = g, m.login = (j, x) => { c({ state: "login" /* Login */ }), o.stop().finally(() => { o.set_login_password(j, x), l({ login: "", password: "", remember: !1 }), o.start(); }); }, m.display_alert = Cr; } }, [s, g, o]), se(() => { o.on(Oe.LoginSuccess, () => { o.login_xopts = null, c({ state: "active" /* Active */ }); }); }, [d.remember, s, n, o]), se(() => { o.on(Oe.LoginOTPSetup, (u) => { c({ state: "otp_setup", svc_msg: u }), o.login_xopts = null; }), o.on(Oe.LoginOTPRequired, () => { c({ state: "otp_auth" /* OtpAuth */ }), o.login_xopts = null; }), o.on(Oe.LoginOTPInvalid, () => { c({ state: "otp_auth", err: { code: ne.ACCESS_DENIED } }), o.login_xopts = null; }); }, [o]), se(() => { switch (o.on(Oe.LoginFailed, (u) => { let m; if (s != null && s.on_login_failed ? m = s.on_login_failed(u) : m = "default", m == "retry") { o.restart(); return; } if (m != "abort") { if (u.code == ne.ACCESS_DENIED && (u.message == "invalid token" || u.message == "No token/API key specified") && o.is_auth_set()) { o.erase_token_cookie(), o.restart(); return; } if (u.code == ne.CORE_ERROR && u.message == "Server error") { c({ state: "login" /* Login */ }), o.restart(); return; } } if (u.code == ne.ACCESS_DENIED && n.state == "login_auto") try { fe.erase( "auth_password" /* Password */ ); } catch { } c({ state: n.state == "login_session" && u.code == ne.ACCESS_DENIED ? "login_auto" : "login_form", err: u }); }), n.state) { case "login_session": s != null && s.cache_auth && !o.is_auth_set() && (o.ignore_password_set_on_next_login = !0, o.set_login_password( fe.read( "auth_login" /* Login */ ) || "", fe.read( "auth_password" /* Password */ ) || "" )), o.start(); break; case "login_auto": s != null && s.cache_auth && o.set_login_password( fe.read( "auth_login" /* Login */ ) || "", fe.read( "auth_password" /* Password */ ) || "" ), o.is_auth_set() ? o.start() : c({ state: "login_form" /* LoginForm */ }); break; } }, [n, s, o]), n.state == "login_session" && o.logged_in) return c({ state: "active" /* Active */ }), /* @__PURE__ */ r.jsx(r.Fragment, {}); switch (n.state) { case "active": return /* @__PURE__ */ r.jsx(r.Fragment, { children: /* @__PURE__ */ r.jsx(t, { engine: o, logout: g }) }); case "login_session": case "login_auto": case "login": return /* @__PURE__ */ r.jsx(r.Fragment, { children: /* @__PURE__ */ r.jsx("div", { className: "eva login progress", children: (s == null ? void 0 : s.label_logging_in) || "Logging in..." }) }); case "otp_auth": case "otp_setup": return /* @__PURE__ */ r.jsx(r.Fragment, { children: /* @__PURE__ */ r.jsx( Fr, { engine: o, app_state: n, setAppState: c, props: s, logout: g } ) }); default: let u = (f = n.err) == null ? void 0 : f.message; return u == "No authentication data provided" && (o.log.debug( "suppressing error message, strict mode & development on?" ), u = void 0), /* @__PURE__ */ r.jsx(r.Fragment, { children: /* @__PURE__ */ r.jsx( Pr, { engine: o, form: d, setForm: l, setAppState: c, props: s, error_msg: u } ) }); } }, Fr = ({ engine: e, app_state: t, setAppState: s, props: n, logout: i }) => { var j, x; const c = xe(null), [o, d] = _e({ otp: "" }), l = (w) => { const A = { ...o, [w.target.name]: w.target.value }; d(A); }, g = (w) => { w.preventDefault(), s({ state: "login" /* Login */ }), e.login_xopts = { otp: o.otp }; const A = { ...o, otp: "" }; d(A), e.start(); }, f = (w) => { w.preventDefault(), i(); }; se(() => { c.current.focus(); }, []); let u; switch (t.state) { case "otp_setup": let w = `otpauth://totp/${e.login}?secret=${(j = t == null ? void 0 : t.svc_msg) == null ? void 0 : j.value}`; n != null && n.otp_issuer_name && (w += `&issuer=${n.otp_issuer_name}`), u = /* @__PURE__ */ r.jsxs(r.Fragment, { children: [ /* @__PURE__ */ r.jsx("div", { className: "eva login widerow", children: (n == null ? void 0 : n.label_otp_setup) || "OTP authentication setup" }), /* @__PURE__ */ r.jsx("div", { className: "eva login widerow", children: (n == null ? void 0 : n.label_otp_setup_scan) || "scan this code with an authenticator app then enter the response" }), /* @__PURE__ */ r.jsx("div", { className: "eva login qr", children: /* @__PURE__ */ r.jsx("div", { style: { background: "white", padding: "10px" }, children: /* @__PURE__ */ r.jsx( nr, { size: ((n == null ? void 0 : n.otp_qr_size) || 170) - 20, value: w } ) }) }) ] }); break; default: u = /* @__PURE__ */ r.jsx(r.Fragment, { children: /* @__PURE__ */ r.jsxs("div", { className: "eva login widerow", children: [ (n == null ? void 0 : n.label_otp_required) || "OTP required", " (", e.login, ")" ] }) }); } let m = /* @__PURE__ */ r.jsx(r.Fragment, { children: /* @__PURE__ */ r.jsxs("form", { className: "eva login", onSubmit: g, children: [ u, /* @__PURE__ */ r.jsx("div", { className: "eva login error", children: ((x = t.err) == null ? void 0 : x.code) == ne.ACCESS_DENIED ? (n == null ? void 0 : n.label_otp_invalid) || "Invalid OTP code" : "" }), /* @__PURE__ */ r.jsxs("div", { className: "eva login row text", children: [ /* @__PURE__ */ r.jsx("label", { htmlFor: "eva_input_otp", children: (n == null ? void 0 : n.label_otp_code) || "Code" }), /* @__PURE__ */ r.jsx( "input", { className: "eva login", ref: c, id: "eva_input_otp", type: "text", name: "otp", onChange: l } ) ] }), /* @__PURE__ */ r.jsx("button", { className: "eva login", children: (n == null ? void 0 : n.label_enter) || "Enter" }), /* @__PURE__ */ r.jsx("button", { className: "eva login", onClick: f, children: (n == null ? void 0 : n.label_cancel) || "Abort" }) ] }) }); return /* @__PURE__ */ r.jsx(r.Fragment, { children: /* @__PURE__ */ r.jsx(St, { content: m }) }); }, Pr = ({ engine: e, form: t, setForm: s, setAppState: n, error_msg: i, props: c }) => { const o = xe(null); se(() => { if (o.current.focus(), c != null && c.cache_login || c != null && c.cache_auth) { let u = fe.read( "auth_login" /* Login */ ) || ""; if (u) { const m = { ...t, login: u }; s(m); } } }, [c, s]); const d = ge( (u) => { const m = { ...t, [u.target.name]: u.target.name == "remember" ? u.target.checked : u.target.value }; s(m); }, [t] ), l = ge( (u) => { u.preventDefault(); const m = () => { if (n({ state: "login" /* Login */ }), e.set_login_password(t.login, t.password), c != null && c.cache_login || c != null && c.cache_auth) fe.create("auth_login", t.log