@eva-ics/webengine-react
Version:
React components for EVA ICS HMI Web Engine
32 lines (29 loc) • 66.9 kB
JavaScript
(function(S,O){typeof exports=="object"&&typeof module<"u"?O(exports,require("@eva-ics/webengine"),require("react"),require("bmat/dom"),require("react-qr-code"),require("react-hot-toast"),require("bmat/numbers"),require("react-chartjs-2"),require("bmat/tools"),require("bmat/dashtable")):typeof define=="function"&&define.amd?define(["exports","@eva-ics/webengine","react","bmat/dom","react-qr-code","react-hot-toast","bmat/numbers","react-chartjs-2","bmat/tools","bmat/dashtable"],O):(S=typeof globalThis<"u"?globalThis:S||self,O(S["webengine-react"]={},S.webengine,S.React,S.dom,S.QRCode,S.toast,S.numbers,S.reactChartjs2,S.tools,S.dashtable))})(this,function(S,O,w,ue,Ft,rt,Ee,De,Ot,at){"use strict";const $t=new Error("request for lock canceled");var Dt=function(e,t,n,s){function i(c){return c instanceof n?c:new n(function(o){o(c)})}return new(n||(n=Promise))(function(c,o){function d(f){try{v(s.next(f))}catch(u){o(u)}}function l(f){try{v(s.throw(f))}catch(u){o(u)}}function v(f){f.done?c(f.value):i(f.value).then(d,l)}v((s=s.apply(e,t||[])).next())})};class Lt{constructor(t,n=$t){this._value=t,this._cancelError=n,this._weightedQueues=[],this._weightedWaiters=[]}acquire(t=1){if(t<=0)throw new Error(`invalid weight ${t}: must be positive`);return new Promise((n,s)=>{this._weightedQueues[t-1]||(this._weightedQueues[t-1]=[]),this._weightedQueues[t-1].push({resolve:n,reject:s}),this._dispatch()})}runExclusive(t,n=1){return Dt(this,void 0,void 0,function*(){const[s,i]=yield this.acquire(n);try{return yield t(s)}finally{i()}})}waitForUnlock(t=1){if(t<=0)throw new Error(`invalid weight ${t}: must be positive`);return new Promise(n=>{this._weightedWaiters[t-1]||(this._weightedWaiters[t-1]=[]),this._weightedWaiters[t-1].push(n),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(n=>n.reject(this._cancelError))),this._weightedQueues=[]}_dispatch(){var t;for(let n=this._value;n>0;n--){const s=(t=this._weightedQueues[n-1])===null||t===void 0?void 0:t.shift();if(!s)continue;const i=this._value,c=n;this._value-=n,n=this._value+1,s.resolve([i,this._newReleaser(c)])}this._drainUnlockWaiters()}_newReleaser(t){let n=!1;return()=>{n||(n=!0,this.release(t))}}_drainUnlockWaiters(){for(let t=this._value;t>0;t--)this._weightedWaiters[t-1]&&(this._weightedWaiters[t-1].forEach(n=>n()),this._weightedWaiters[t-1]=[])}}var It=function(e,t,n,s){function i(c){return c instanceof n?c:new n(function(o){o(c)})}return new(n||(n=Promise))(function(c,o){function d(f){try{v(s.next(f))}catch(u){o(u)}}function l(f){try{v(s.throw(f))}catch(u){o(u)}}function v(f){f.done?c(f.value):i(f.value).then(d,l)}v((s=s.apply(e,t||[])).next())})};class Wt{constructor(t){this._semaphore=new Lt(1,t)}acquire(){return It(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 Mt=Object.defineProperty,Ut=(e,t,n)=>t in e?Mt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,W=(e,t,n)=>Ut(e,typeof t!="symbol"?t+"":t,n);const Ht="0.1.0";let Ue=null;const qt=e=>{Ue=e,Ue.we_multimedia_version=Ht};var st=(e=>(e.None="none",e.KeepWidth="keep-width",e.KeepHeight="keep-height",e.Resize="resize",e))(st||{});class zt{constructor(t){W(this,"name"),W(this,"decoder"),W(this,"engine"),W(this,"autoSize"),W(this,"canvas"),W(this,"onFrame"),W(this,"onError"),W(this,"onEOS"),W(this,"paused"),W(this,"drawNext","none"),W(this,"drawNextError"),W(this,"frameCounter"),this.name=t.name,this.canvas=t.canvas;const n=t.engine||Ue;if(!n)throw new Error("EVA ICS WebEngine not set");this.engine=n,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 Bt,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 s=this.autoSize;this.decoder.onChange=i=>{switch(s){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,n,s="white"){const i=this.canvas.getContext("2d");i.fillStyle="black",i.fillRect(0,0,this.canvas.width,this.canvas.height),i.fillStyle=s,i.font=`bold ${n}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:n=>{this.messageError(n),this.onError&&this.onError(n),this.close()},onData:n=>{this.decoder.decode(n)},onStart:()=>{this.messageStart(),this.frameCounter=0},onEOS:()=>{this.messageEOS(),this.frameCounter=0}})}close(){this.engine.stop_stream(this.name),this.decoder.close()}}class Bt{constructor(){W(this,"first_key_received"),W(this,"decoder"),W(this,"codec"),W(this,"width"),W(this,"height"),W(this,"hardwareAcceleration"),W(this,"actualHardwareAcceleration"),W(this,"fallback"),W(this,"fallbackToSoftware"),W(this,"onOutput"),W(this,"onChange"),W(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 n,s;const i=new Kt(t);if(!i.format)throw new O.EvaError(O.EvaErrorKind.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,data:i.data});try{(n=this.decoder)==null||n.decode(c)}catch(o){try{(s=this.decoder)==null||s.close()}catch{}return this.decoder=void 0,this.fallbackToSoftware&&this.actualHardwareAcceleration?(this.actualHardwareAcceleration=!1,this.fallback=!0,!1):(this.onError(new O.EvaError(O.EvaErrorKind.FUNC_FAILED,o)),!1)}return!0}_createDecoder(t){var n;if(this.codec=t.format,this.width=t.width,this.height=t.height,!this.codec)throw new O.EvaError(O.EvaErrorKind.INVALID_DATA,"Unsupported video format in frame");try{(n=this.decoder)==null||n.close()}catch{}this.decoder=new VideoDecoder({output:i=>{this.onOutput(i);try{i.close()}catch{}},error:i=>{this.onError(i)}});const s={codec:this.codec};switch(this.codec){case"avc1.42E01E":s.optimizeForLatency=!0,s.hardwareAcceleration=this.isHardwareAccelerationEnabled()?"prefer-hardware":"prefer-software";break;case"hvc1.1.6.L93.00":s.optimizeForLatency=!0,s.hardwareAcceleration=this.isHardwareAccelerationEnabled()?"prefer-hardware":"prefer-software";break;case"vp8":s.optimizeForLatency=!0;break;case"vp09.00.10.08":s.optimizeForLatency=!0,s.hardwareAcceleration=this.isHardwareAccelerationEnabled()?"prefer-hardware":"prefer-software";break;case"av01.0.05M.08":s.optimizeForLatency=!0,s.hardwareAcceleration=this.isHardwareAccelerationEnabled()?"prefer-hardware":"prefer-software";break}this.decoder.configure(s)}}class Kt{constructor(t){W(this,"version"),W(this,"format"),W(this,"width"),W(this,"height"),W(this,"metadata"),W(this,"data");const n=new Uint8Array(t,0,3);if(n[0]!==69||n[1]!==86||n[2]!==83)throw new O.EvaError(O.EvaErrorKind.INVALID_DATA,"Invalid magic number in video frame data");const s=new Uint8Array(t,3,10),i=s[0];if(i!==1)throw new O.EvaError(O.EvaErrorKind.INVALID_DATA,`Unsupported video frame version: ${i}`);switch(this.version=i,s[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=s[3]<<8|s[2],this.height=s[5]<<8|s[4],this.metadata=s[6],this.data=new Uint8Array(t,10)}isKey(){return(this.metadata&1)!==0}}const Yt="0.5.18";let me=null,nt=new Wt;const Ae=()=>me,Vt=e=>{me=e,me.wer_version=Yt,qt(me)},xe=(e,t)=>{const[n,s]=w.useState({}),i=e.engine||me;return w.useEffect(()=>{const c=o=>{s(o)};if(e.oid)if(i)i.watch(e.oid,c,!1,!0);else throw new Error("EVA ICS WebEngine not set");else s({});return()=>{i&&e.oid&&i.unwatch(e.oid,c)}},t),n},Gt=(e,t)=>{const[n,s]=w.useState({}),i=e.engine||me;return w.useEffect(()=>{const c=o=>{o.oid&&s(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 s({});return()=>{i&&e.oid&&e.oid.length>0&&(s({}),e.oid.forEach(o=>{i.unwatch(o,c)}))}},t),n},Jt=(e,t)=>{const n=e.engine||me;if(!n)throw new Error("EVA ICS WebEngine not set");return w.useEffect(()=>(n.register_state_block(e.name,e.state_updates),()=>{n.unregister_state_block(e.name)}),t)},it=(e,t)=>{const[n,s]=w.useState({data:null}),i=w.useRef(!1),c=w.useRef(null),o=w.useRef({enabled:!0}),d=e.engine||me;let l=e.update?e.update*1e3:1e3;isNaN(l)?l=1e3:l<100&&(l=100);const v=w.useCallback(()=>{if(!i.current){c.current=null,o.current.enabled=!1,o.current={enabled:!1},s({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,E=u.map((_,j)=>{let R=_.split(":"),A=R[0];A.startsWith("t")&&(A=A.substr(1),m=j);let b=R[1]||null,x=e.args,y=e.prop===void 0?O.StateProp.Value:e.prop==O.StateProp.Any?null:e.prop,p={s:A,e:b,x:y,w:e.fill+(e.digits===void 0?"":`:${e.digits}`),...x};return d.call("item.state_history",e.oid,p)});Promise.all(E).then(_=>{_.t=_[m].t,f.enabled&&(s({data:_}),c.current=setTimeout(v,l))}).catch(_=>{f.enabled&&(s({data:null,error:_}),c.current=setTimeout(v,l))})}else s({data:null}),c.current=setTimeout(v,e.update_uninit?e.update_uninit*1e3:l)},t);return w.useEffect(()=>{if(i.current=!0,!c.current)if(d)typeof e.oid=="string"||Array.isArray(e.oid)&&e.oid.length>0?v():s({data:null,error:Array.isArray(e.oid)?void 0:new O.EvaError(O.EvaErrorKind.INVALID_PARAMS,"OID not specified")});else throw new Error("EVA ICS WebEngine not set");return()=>{i.current=!1,clearTimeout(c.current),s({data:null}),c.current=null,o.current.enabled=!1,o.current={enabled:!1}}},[v]),n},Qt=(e,t)=>{const[n,s]=w.useState({data:null}),i=w.useRef(!1),c=w.useRef(null),o=w.useRef({enabled:!0}),d=e.engine||me;let l=e.update?e.update*1e3:1e3;isNaN(l)?l=1e3:l<100&&(l=100);const v=w.useCallback(()=>{if(!i.current){c.current=null,o.current.enabled=!1,o.current={enabled:!1},s({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&&(s({data:u}),c.current=setTimeout(v,l))}).catch(u=>{f.enabled&&(s({data:null,error:u}),c.current=setTimeout(v,l))}):(s({data:null}),c.current=setTimeout(v,e.update_uninit?e.update_uninit*1e3:l))},[e.method,e.params,l,e.update_uninit]);return w.useEffect(()=>{if(i.current=!0,!c.current)if(d)e.method?v():s({data:null});else throw new Error("EVA ICS WebEngine not set");return()=>{i.current=!1,clearTimeout(c.current),s({data:null}),c.current=null,o.current.enabled=!1,o.current={enabled:!1}}},t),n};var ot=(e=>(e[e.Working=0]="Working",e[e.Active=1]="Active",e[e.Failed=2]="Failed",e))(ot||{});const Xt=(e,t)=>{const[n,s]=w.useState(0),i=e.engine||me;return w.useEffect(()=>{let c=!1;if(i)s(0),nt.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(),s(1)):i.set_state_updates(d,e.clear_existing).then(()=>s(1)).catch(l=>{i.log.error(l),s(2)}).finally(()=>o())});else throw new Error("EVA ICS WebEngine not set");return()=>{i&&nt.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),n},ct="progress-color",lt="warning-progress-color",ut="critical-progress-color",He=(e,t,n,s,i,c)=>t===void 0||isNaN(t)?`${e}-${ct}`:c!==void 0&&t<=c?`${e}-${ut}`:i!==void 0&&t<=i?`${e}-${lt}`:s!==void 0&&t>=s?`${e}-${ut}`:n!==void 0&&t>=n?`${e}-${lt}`:`${e}-${ct}`;var qe={exports:{}},Te={};/**
* @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 dt;function Zt(){if(dt)return Te;dt=1;var e=w,t=Symbol.for("react.element"),n=Symbol.for("react.fragment"),s=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,v){var f,u={},m=null,E=null;v!==void 0&&(m=""+v),l.key!==void 0&&(m=""+l.key),l.ref!==void 0&&(E=l.ref);for(f in l)s.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:E,props:u,_owner:i.current}}return Te.Fragment=n,Te.jsx=o,Te.jsxs=o,Te}var Ce={};/**
* @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 ht;function er(){return ht||(ht=1,process.env.NODE_ENV!=="production"&&function(){var e=w,t=Symbol.for("react.element"),n=Symbol.for("react.portal"),s=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"),v=Symbol.for("react.suspense"),f=Symbol.for("react.suspense_list"),u=Symbol.for("react.memo"),m=Symbol.for("react.lazy"),E=Symbol.for("react.offscreen"),_=Symbol.iterator,j="@@iterator";function R(a){if(a===null||typeof a!="object")return null;var h=_&&a[_]||a[j];return typeof h=="function"?h:null}var A=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function b(a){{for(var h=arguments.length,g=new Array(h>1?h-1:0),T=1;T<h;T++)g[T-1]=arguments[T];x("error",a,g)}}function x(a,h,g){{var T=A.ReactDebugCurrentFrame,I=T.getStackAddendum();I!==""&&(h+="%s",g=g.concat([I]));var q=g.map(function(L){return String(L)});q.unshift("Warning: "+h),Function.prototype.apply.call(console[a],console,q)}}var y=!1,p=!1,k=!1,P=!1,C=!1,F;F=Symbol.for("react.module.reference");function M(a){return!!(typeof a=="string"||typeof a=="function"||a===s||a===c||C||a===i||a===v||a===f||P||a===E||y||p||k||typeof a=="object"&&a!==null&&(a.$$typeof===m||a.$$typeof===u||a.$$typeof===o||a.$$typeof===d||a.$$typeof===l||a.$$typeof===F||a.getModuleId!==void 0))}function U(a,h,g){var T=a.displayName;if(T)return T;var I=h.displayName||h.name||"";return I!==""?g+"("+I+")":g}function H(a){return a.displayName||"Context"}function $(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 s:return"Fragment";case n:return"Portal";case c:return"Profiler";case i:return"StrictMode";case v:return"Suspense";case f:return"SuspenseList"}if(typeof a=="object")switch(a.$$typeof){case d:var h=a;return H(h)+".Consumer";case o:var g=a;return H(g._context)+".Provider";case l:return U(a,a.render,"ForwardRef");case u:var T=a.displayName||null;return T!==null?T:$(a.type)||"Memo";case m:{var I=a,q=I._payload,L=I._init;try{return $(L(q))}catch{return null}}}return null}var N=Object.assign,B=0,z,K,X,te,V,Z,se;function ne(){}ne.__reactDisabledLog=!0;function ce(){{if(B===0){z=console.log,K=console.info,X=console.warn,te=console.error,V=console.group,Z=console.groupCollapsed,se=console.groupEnd;var a={configurable:!0,enumerable:!0,value:ne,writable:!0};Object.defineProperties(console,{info:a,log:a,warn:a,error:a,group:a,groupCollapsed:a,groupEnd:a})}B++}}function G(){{if(B--,B===0){var a={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:N({},a,{value:z}),info:N({},a,{value:K}),warn:N({},a,{value:X}),error:N({},a,{value:te}),group:N({},a,{value:V}),groupCollapsed:N({},a,{value:Z}),groupEnd:N({},a,{value:se})})}B<0&&b("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var ge=A.ReactCurrentDispatcher,Y;function Ne(a,h,g){{if(Y===void 0)try{throw Error()}catch(I){var T=I.stack.trim().match(/\n( *(at )?)/);Y=T&&T[1]||""}return`
`+Y+a}}var Ge=!1,Ie;{var pr=typeof WeakMap=="function"?WeakMap:Map;Ie=new pr}function xt(a,h){if(!a||Ge)return"";{var g=Ie.get(a);if(g!==void 0)return g}var T;Ge=!0;var I=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var q;q=ge.current,ge.current=null,ce();try{if(h){var L=function(){throw Error()};if(Object.defineProperty(L.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(L,[])}catch(ie){T=ie}Reflect.construct(a,[],L)}else{try{L.call()}catch(ie){T=ie}a.call(L.prototype)}}else{try{throw Error()}catch(ie){T=ie}a()}}catch(ie){if(ie&&T&&typeof ie.stack=="string"){for(var D=ie.stack.split(`
`),ae=T.stack.split(`
`),J=D.length-1,Q=ae.length-1;J>=1&&Q>=0&&D[J]!==ae[Q];)Q--;for(;J>=1&&Q>=0;J--,Q--)if(D[J]!==ae[Q]){if(J!==1||Q!==1)do if(J--,Q--,Q<0||D[J]!==ae[Q]){var le=`
`+D[J].replace(" at new "," at ");return a.displayName&&le.includes("<anonymous>")&&(le=le.replace("<anonymous>",a.displayName)),typeof a=="function"&&Ie.set(a,le),le}while(J>=1&&Q>=0);break}}}finally{Ge=!1,ge.current=q,G(),Error.prepareStackTrace=I}var Se=a?a.displayName||a.name:"",ye=Se?Ne(Se):"";return typeof a=="function"&&Ie.set(a,ye),ye}function Sr(a,h,g){return xt(a,!1)}function Ar(a){var h=a.prototype;return!!(h&&h.isReactComponent)}function We(a,h,g){if(a==null)return"";if(typeof a=="function")return xt(a,Ar(a));if(typeof a=="string")return Ne(a);switch(a){case v:return Ne("Suspense");case f:return Ne("SuspenseList")}if(typeof a=="object")switch(a.$$typeof){case l:return Sr(a.render);case u:return We(a.type,h,g);case m:{var T=a,I=T._payload,q=T._init;try{return We(q(I),h,g)}catch{}}}return""}var Oe=Object.prototype.hasOwnProperty,yt={},Et=A.ReactDebugCurrentFrame;function Me(a){if(a){var h=a._owner,g=We(a.type,a._source,h?h.type:null);Et.setExtraStackFrame(g)}else Et.setExtraStackFrame(null)}function Tr(a,h,g,T,I){{var q=Function.call.bind(Oe);for(var L in a)if(q(a,L)){var D=void 0;try{if(typeof a[L]!="function"){var ae=Error((T||"React class")+": "+g+" type `"+L+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof a[L]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw ae.name="Invariant Violation",ae}D=a[L](h,L,T,g,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(J){D=J}D&&!(D instanceof Error)&&(Me(I),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).",T||"React class",g,L,typeof D),Me(null)),D instanceof Error&&!(D.message in yt)&&(yt[D.message]=!0,Me(I),b("Failed %s type: %s",g,D.message),Me(null))}}}var Cr=Array.isArray;function Je(a){return Cr(a)}function Rr(a){{var h=typeof Symbol=="function"&&Symbol.toStringTag,g=h&&a[Symbol.toStringTag]||a.constructor.name||"Object";return g}}function Pr(a){try{return jt(a),!1}catch{return!0}}function jt(a){return""+a}function kt(a){if(Pr(a))return b("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Rr(a)),jt(a)}var $e=A.ReactCurrentOwner,Fr={key:!0,ref:!0,__self:!0,__source:!0},wt,Nt,Qe;Qe={};function Or(a){if(Oe.call(a,"ref")){var h=Object.getOwnPropertyDescriptor(a,"ref").get;if(h&&h.isReactWarning)return!1}return a.ref!==void 0}function $r(a){if(Oe.call(a,"key")){var h=Object.getOwnPropertyDescriptor(a,"key").get;if(h&&h.isReactWarning)return!1}return a.key!==void 0}function Dr(a,h){if(typeof a.ref=="string"&&$e.current&&h&&$e.current.stateNode!==h){var g=$($e.current.type);Qe[g]||(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',$($e.current.type),a.ref),Qe[g]=!0)}}function Lr(a,h){{var g=function(){wt||(wt=!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))};g.isReactWarning=!0,Object.defineProperty(a,"key",{get:g,configurable:!0})}}function Ir(a,h){{var g=function(){Nt||(Nt=!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))};g.isReactWarning=!0,Object.defineProperty(a,"ref",{get:g,configurable:!0})}}var Wr=function(a,h,g,T,I,q,L){var D={$$typeof:t,type:a,key:h,ref:g,props:L,_owner:q};return D._store={},Object.defineProperty(D._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(D,"_self",{configurable:!1,enumerable:!1,writable:!1,value:T}),Object.defineProperty(D,"_source",{configurable:!1,enumerable:!1,writable:!1,value:I}),Object.freeze&&(Object.freeze(D.props),Object.freeze(D)),D};function Mr(a,h,g,T,I){{var q,L={},D=null,ae=null;g!==void 0&&(kt(g),D=""+g),$r(h)&&(kt(h.key),D=""+h.key),Or(h)&&(ae=h.ref,Dr(h,I));for(q in h)Oe.call(h,q)&&!Fr.hasOwnProperty(q)&&(L[q]=h[q]);if(a&&a.defaultProps){var J=a.defaultProps;for(q in J)L[q]===void 0&&(L[q]=J[q])}if(D||ae){var Q=typeof a=="function"?a.displayName||a.name||"Unknown":a;D&&Lr(L,Q),ae&&Ir(L,Q)}return Wr(a,D,ae,I,T,$e.current,L)}}var Xe=A.ReactCurrentOwner,pt=A.ReactDebugCurrentFrame;function pe(a){if(a){var h=a._owner,g=We(a.type,a._source,h?h.type:null);pt.setExtraStackFrame(g)}else pt.setExtraStackFrame(null)}var Ze;Ze=!1;function et(a){return typeof a=="object"&&a!==null&&a.$$typeof===t}function St(){{if(Xe.current){var a=$(Xe.current.type);if(a)return`
Check the render method of \``+a+"`."}return""}}function Ur(a){{if(a!==void 0){var h=a.fileName.replace(/^.*[\\\/]/,""),g=a.lineNumber;return`
Check your code at `+h+":"+g+"."}return""}}var At={};function Hr(a){{var h=St();if(!h){var g=typeof a=="string"?a:a.displayName||a.name;g&&(h=`
Check the top-level render call using <`+g+">.")}return h}}function Tt(a,h){{if(!a._store||a._store.validated||a.key!=null)return;a._store.validated=!0;var g=Hr(h);if(At[g])return;At[g]=!0;var T="";a&&a._owner&&a._owner!==Xe.current&&(T=" It was passed a child from "+$(a._owner.type)+"."),pe(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.',g,T),pe(null)}}function Ct(a,h){{if(typeof a!="object")return;if(Je(a))for(var g=0;g<a.length;g++){var T=a[g];et(T)&&Tt(T,h)}else if(et(a))a._store&&(a._store.validated=!0);else if(a){var I=R(a);if(typeof I=="function"&&I!==a.entries)for(var q=I.call(a),L;!(L=q.next()).done;)et(L.value)&&Tt(L.value,h)}}}function qr(a){{var h=a.type;if(h==null||typeof h=="string")return;var g;if(typeof h=="function")g=h.propTypes;else if(typeof h=="object"&&(h.$$typeof===l||h.$$typeof===u))g=h.propTypes;else return;if(g){var T=$(h);Tr(g,a.props,"prop",T,a)}else if(h.PropTypes!==void 0&&!Ze){Ze=!0;var I=$(h);b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",I||"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 zr(a){{for(var h=Object.keys(a.props),g=0;g<h.length;g++){var T=h[g];if(T!=="children"&&T!=="key"){pe(a),b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",T),pe(null);break}}a.ref!==null&&(pe(a),b("Invalid attribute `ref` supplied to `React.Fragment`."),pe(null))}}var Rt={};function Pt(a,h,g,T,I,q){{var L=M(a);if(!L){var D="";(a===void 0||typeof a=="object"&&a!==null&&Object.keys(a).length===0)&&(D+=" 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 ae=Ur(I);ae?D+=ae:D+=St();var J;a===null?J="null":Je(a)?J="array":a!==void 0&&a.$$typeof===t?(J="<"+($(a.type)||"Unknown")+" />",D=" Did you accidentally export a JSX literal instead of a component?"):J=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",J,D)}var Q=Mr(a,h,g,I,q);if(Q==null)return Q;if(L){var le=h.children;if(le!==void 0)if(T)if(Je(le)){for(var Se=0;Se<le.length;Se++)Ct(le[Se],a);Object.freeze&&Object.freeze(le)}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 Ct(le,a)}if(Oe.call(h,"key")){var ye=$(a),ie=Object.keys(h).filter(function(Jr){return Jr!=="key"}),tt=ie.length>0?"{key: someKey, "+ie.join(": ..., ")+": ...}":"{key: someKey}";if(!Rt[ye+tt]){var Gr=ie.length>0?"{"+ie.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} />`,tt,ye,Gr,ye),Rt[ye+tt]=!0}}return a===s?zr(Q):qr(Q),Q}}function Br(a,h,g){return Pt(a,h,g,!0)}function Kr(a,h,g){return Pt(a,h,g,!1)}var Yr=Kr,Vr=Br;Ce.Fragment=s,Ce.jsx=Yr,Ce.jsxs=Vr}()),Ce}process.env.NODE_ENV==="production"?qe.exports=Zt():qe.exports=er();var r=qe.exports,ft=(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))(ft||{}),vt=(e=>(e.Default="default",e.Retry="retry",e.Abort="abort",e))(vt||{});const tr=(e,t,n)=>{let s;t==="warning"||t==="error"?s=rt.error:s=rt.success;let i=n;i===void 0&&(i=5),s(e,{duration:i*1e3})},rr=({engine:e,Dashboard:t,login_props:n})=>{var f;const[s,i]=w.useState({state:"login_session"}),c=w.useCallback(u=>{n!=null&&n.state_announce&&n.state_announce({...u}),i(u)},[n==null?void 0:n.state_announce]),o=e||Ae();if(!o)throw new Error("EVA ICS WebEngine not set");const[d,l]=w.useState({login:"",password:"",remember:!0}),v=w.useCallback(async()=>{try{try{ue.cookies.erase("auth_password")}catch{}await o.stop(),o.clear_auth()}catch{}c({state:"login_form"})},[o]);if(w.useEffect(()=>{if(n!=null&&n.register_globals){o.register_globals();const u=window;u.$eva.hmi==null&&(u.$eva.hmi={});const m=u.$eva.hmi;m.logout=v,m.login=(E,_)=>{c({state:"login"}),o.stop().finally(()=>{o.set_login_password(E,_),l({login:"",password:"",remember:!1}),o.start()})},m.display_alert=tr}},[n,v,o]),w.useEffect(()=>{o.on(O.EventKind.LoginSuccess,()=>{o.login_xopts=null,c({state:"active"})})},[d.remember,n,s,o]),w.useEffect(()=>{o.on(O.EventKind.LoginOTPSetup,u=>{c({state:"otp_setup",svc_msg:u}),o.login_xopts=null}),o.on(O.EventKind.LoginOTPRequired,()=>{c({state:"otp_auth"}),o.login_xopts=null}),o.on(O.EventKind.LoginOTPInvalid,()=>{c({state:"otp_auth",err:{code:O.EvaErrorKind.ACCESS_DENIED}}),o.login_xopts=null})},[o]),w.useEffect(()=>{switch(o.on(O.EventKind.LoginFailed,u=>{let m;if(n!=null&&n.on_login_failed?m=n.on_login_failed(u):m="default",m=="retry"){o.restart();return}if(m!="abort"){if(u.code==O.EvaErrorKind.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==O.EvaErrorKind.CORE_ERROR&&u.message=="Server error"){c({state:"login"}),o.restart();return}}if(u.code==O.EvaErrorKind.ACCESS_DENIED&&s.state=="login_auto")try{ue.cookies.erase("auth_password")}catch{}c({state:s.state=="login_session"&&u.code==O.EvaErrorKind.ACCESS_DENIED?"login_auto":"login_form",err:u})}),s.state){case"login_session":n!=null&&n.cache_auth&&!o.is_auth_set()&&(o.ignore_password_set_on_next_login=!0,o.set_login_password(ue.cookies.read("auth_login")||"",ue.cookies.read("auth_password")||"")),o.start();break;case"login_auto":n!=null&&n.cache_auth&&o.set_login_password(ue.cookies.read("auth_login")||"",ue.cookies.read("auth_password")||""),o.is_auth_set()?o.start():c({state:"login_form"});break}},[s,n,o]),s.state=="login_session"&&o.logged_in)return c({state:"active"}),r.jsx(r.Fragment,{});switch(s.state){case"active":return r.jsx(r.Fragment,{children:r.jsx(t,{engine:o,logout:v})});case"login_session":case"login_auto":case"login":return r.jsx(r.Fragment,{children:r.jsx("div",{className:"eva login progress",children:(n==null?void 0:n.label_logging_in)||"Logging in..."})});case"otp_auth":case"otp_setup":return r.jsx(r.Fragment,{children:r.jsx(ar,{engine:o,app_state:s,setAppState:c,props:n,logout:v})});default:let u=(f=s.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),r.jsx(r.Fragment,{children:r.jsx(sr,{engine:o,form:d,setForm:l,setAppState:c,props:n,error_msg:u})})}},ar=({engine:e,app_state:t,setAppState:n,props:s,logout:i})=>{var E,_;const c=w.useRef(null),[o,d]=w.useState({otp:""}),l=j=>{const R={...o,[j.target.name]:j.target.value};d(R)},v=j=>{j.preventDefault(),n({state:"login"}),e.login_xopts={otp:o.otp};const R={...o,otp:""};d(R),e.start()},f=j=>{j.preventDefault(),i()};w.useEffect(()=>{c.current.focus()},[]);let u;switch(t.state){case"otp_setup":let j=`otpauth://totp/${e.login}?secret=${(E=t==null?void 0:t.svc_msg)==null?void 0:E.value}`;s!=null&&s.otp_issuer_name&&(j+=`&issuer=${s.otp_issuer_name}`),u=r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"eva login widerow",children:(s==null?void 0:s.label_otp_setup)||"OTP authentication setup"}),r.jsx("div",{className:"eva login widerow",children:(s==null?void 0:s.label_otp_setup_scan)||"scan this code with an authenticator app then enter the response"}),r.jsx("div",{className:"eva login qr",children:r.jsx("div",{style:{background:"white",padding:"10px"},children:r.jsx(Ft,{size:((s==null?void 0:s.otp_qr_size)||170)-20,value:j})})})]});break;default:u=r.jsx(r.Fragment,{children:r.jsxs("div",{className:"eva login widerow",children:[(s==null?void 0:s.label_otp_required)||"OTP required"," (",e.login,")"]})})}let m=r.jsx(r.Fragment,{children:r.jsxs("form",{className:"eva login",onSubmit:v,children:[u,r.jsx("div",{className:"eva login error",children:((_=t.err)==null?void 0:_.code)==O.EvaErrorKind.ACCESS_DENIED?(s==null?void 0:s.label_otp_invalid)||"Invalid OTP code":""}),r.jsxs("div",{className:"eva login row text",children:[r.jsx("label",{htmlFor:"eva_input_otp",children:(s==null?void 0:s.label_otp_code)||"Code"}),r.jsx("input",{className:"eva login",ref:c,id:"eva_input_otp",type:"text",name:"otp",onChange:l})]}),r.jsx("button",{className:"eva login",children:(s==null?void 0:s.label_enter)||"Enter"}),r.jsx("button",{className:"eva login",onClick:f,children:(s==null?void 0:s.label_cancel)||"Abort"})]})});return r.jsx(r.Fragment,{children:r.jsx(gt,{content:m})})},sr=({engine:e,form:t,setForm:n,setAppState:s,error_msg:i,props:c})=>{const o=w.useRef(null);w.useEffect(()=>{if(o.current.focus(),c!=null&&c.cache_login||c!=null&&c.cache_auth){let u=ue.cookies.read("auth_login")||"";if(u){const m={...t,login:u};n(m)}}},[c,n]);const d=w.useCallback(u=>{const m={...t,[u.target.name]:u.target.name=="remember"?u.target.checked:u.target.value};n(m)},[t]),l=w.useCallback(u=>{u.preventDefault();const m=()=>{if(s({state:"login"}),e.set_login_password(t.login,t.password),c!=null&&c.cache_login||c!=null&&c.cache_auth)ue.cookies.create("auth_login",t.login,365);else try{ue.cookies.erase("auth_login")}catch{}if(c!=null&&c.cache_auth)ue.cookies.create("auth_password",t.password,365);else try{ue.cookies.erase("auth_password")}catch{}const E={...t,password:""};n(E),e.start()};c!=null&&c.prelogin_hook?c.prelogin_hook().then(E=>{e.login_xopts={data:E},m()}).catch(E=>{s({state:"login_form",err:{code:O.EvaErrorKind.FUNC_FAILED,message:E.toString()}})}):m()},[e,c,t]);let v;c!=null&&c.cache_auth&&(v=r.jsx(r.Fragment,{children:r.jsxs("div",{className:"eva login row remember",children:[r.jsx("input",{className:"eva login checkbox",type:"checkbox",name:"remember",id:"eva_input_remember",checked:t.remember,onChange:d}),r.jsx("label",{htmlFor:"eva_input_remember",children:c.label_remember||"remember credentials"})]})}));let f=r.jsxs(r.Fragment,{children:[(c==null?void 0:c.form_header)&&c.form_header(),r.jsxs("form",{className:"eva login",onSubmit:l,children:[r.jsx("div",{className:"eva login error",children:i}),r.jsxs("div",{className:"eva login row text",children:[r.jsx("label",{htmlFor:"eva_input_login",children:(c==null?void 0:c.label_login)||"Login"}),r.jsx("input",{className:"eva login",id:"eva_input_login",ref:o,type:"text",name:"login",value:t.login,onChange:d})]}),r.jsxs("div",{className:"eva login row text",children:[r.jsx("label",{htmlFor:"eva_input_password",children:(c==null?void 0:c.label_password)||"Password"}),r.jsx("input",{className:"eva login",id:"eva_input_password",type:"password",name:"password",value:t.password,onChange:d})]}),v,r.jsx("button",{className:"eva login",children:(c==null?void 0:c.label_enter)||"Enter"})]}),(c==null?void 0:c.form_footer)&&c.form_footer()]});return r.jsx(r.Fragment,{children:r.jsx(gt,{content:f})})},gt=({content:e})=>r.jsx(r.Fragment,{children:r.jsxs("div",{className:"eva login container",children:[r.jsx("div",{className:"eva login logo"}),r.jsx("div",{className:"eva login header"}),r.jsx("div",{className:"eva login form-container",children:e})]})}),nr=({items:e,title:t,engine:n})=>{const s=t?r.jsx("tr",{className:"eva state valuetable header",children:r.jsx("th",{className:"eva state valuetable",colSpan:2,children:t})}):"";return r.jsx("table",{className:"eva state valuetable",children:r.jsxs("tbody",{className:"eva state valuetable",children:[s,e.map(i=>r.jsxs("tr",{className:"eva state valuetable",children:[r.jsx("td",{className:"eva state valuetable label",children:i.label||i.oid||""}),r.jsx("td",{className:"eva state valuetable value",children:r.jsx(_e,{oid:i.oid,formula:i.formula,state:i.state,digits:i.digits,units:i.units,className:i.className,threshold:i.threshold,format_with:i.format_with,set_color_with:i.set_color_with,set_class_name_with:i.set_class_name_with,engine:n})})]},i.oid))]})})},_e=({oid:e,formula:t,state:n,digits:s,units:i,className:c,threshold:o,format_with:d,set_color_with:l,set_class_name_with:v,set_style_with:f,engine:u})=>{const m=xe({oid:e,engine:u},[e,u]),E=n||m;let _=E.value;if(t&&typeof _=="number")try{_=Ee.calculateFormula(t,_)}catch{_=NaN}s!==void 0&&(_=parseFloat(_).toFixed(s));let j;switch(v?j=v(_)||"":j=c||"",E.status){case-1:j+=" error";break;default:j+=" ok";break}if(E.connected==!1&&(j+=" disconnected"),o){let b=parseFloat(_);for(const x of o)if(b>=x.value){j+=` ${x.class}`;break}}let R;l&&(R=l(_)),d&&(_=d(_));const A=f?f(_):{};return R&&(A.color=R),r.jsxs("span",{className:`eva state ${j}`,style:A,children:[_,i]})},ze=(e,t,n)=>{e.exitcode===0?t&&t(e):n&&n(new O.EvaError(O.EvaErrorKind.FUNC_FAILED,e.err||void 0))},Be=(e,t)=>{t&&t(e)};var Re=(e=>(e.Toggle="toggle",e.Value="value",e.Run="run",e))(Re||{});const ir=({buttons:e,title:t,engine:n,on_success:s,on_fail:i})=>{let c;return t&&(c=r.jsx("div",{className:"eva button block_title",children:t})),r.jsxs("div",{className:"eva button block",children:[c,r.jsx("div",{className:"eva button block_container",children:e.map(o=>{let d=o.kind;switch(o.oid.startsWith("lmacro:")&&(d="run"),d){case"value":return r.jsx(Ye,{oid:o.oid,label:o.label,css_class:o.css_class,input_size:o.input_size,engine:n,on_success:s,on_fail:i},o.oid);case"run":return r.jsx(Ve,{oid:o.oid,params:o.params,busy:o.busy,label:o.label,css_class:o.css_class,engine:n,on_success:s,on_fail:i},o.oid);default:return r.jsx(Ke,{oid:o.oid,label:o.label,css_class:o.css_class,engine:n,on_success:s,on_fail:i},o.oid)}})})]})},Ke=({oid:e,label:t,css_class:n,engine:s,on_success:i,on_fail:c,disabled_actions:o})=>{const d=xe({oid:e,engine:s},[e,s]),l=v=>{if(v.preventDefault(),o)return;(s||Ae()).action.toggle(e,!0).then(u=>ze(u,i,c)).catch(u=>Be(u,c))};return r.jsx("div",{className:`eva button container toggle ${n||""}`,children:r.jsxs("label",{className:"eva button switch",children:[r.jsx("input",{type:"checkbox",onChange:l,checked:d&&d.value>0,disabled:d&&d.act!==void 0&&d.act>0}),r.jsx("span",{className:`eva button slider ${n||""}`}),r.jsx("div",{className:`eva button label slider ${n||""}`,children:t})]})})},Ye=({oid:e,label:t,css_class:n,input_size:s,engine:i,on_success:c,on_fail:o,disabled_actions:d})=>{const l=xe({oid:e,engine:i},[e,i]),[v,f]=w.useState(l.value),u=w.useId(),m=w.useRef(null),E=j=>{if(j.preventDefault(),d)return;const R=i||Ae();if(v===void 0)return;let A=parseFloat(v);isNaN(A)&&(A=v),R.action.exec(e,{v:A},!0).then(b=>{f(void 0),ze(b,c,o)}).catch(b=>{f(void 0),Be(b,o)})};v===void 0&&m.current&&(m.current.value=l.value===void 0?"":l.value);let _=`eva button value ${n||""}`;return v!==void 0&&(_+=" changed"),r.jsxs("div",{className:`eva button container value ${n||""}`,children:[r.jsx("input",{className:_,size:s||5,onChange:j=>f(j.target.value),onKeyDown:j=>{switch(j.code){case"Escape":f(void 0);break;case"Enter":E(j);break}},type:"text",ref:m,id:u,disabled:d}),r.jsx("label",{htmlFor:u,children:r.jsx("div",{className:`eva button input label ${n||""}`,children:t||e})}),r.jsx("button",{disabled:(v===void 0||l&&l.act!==void 0&&l.act>0)&&!d,onClick:E,className:`eva button input apply ${n||""}`})]})},Ve=({oid:e,params:t,label:n,busy:s,css_class:i,engine:c,on_success:o,on_fail:d,disabled_actions:l})=>{const v=xe({oid:s,engine:c},[s,c]),f=m=>{if(m.preventDefault(),l)return;(c||Ae()).action.run(e,t,!0).then(_=>ze(_,o,d)).catch(_=>Be(_,d))},u=()=>{if(s)return s.startsWith("sensor:")?v.value==1:s.startsWith("lvar:")?v.status==1:v.act!==void 0&&v.act>0};return r.jsx("div",{className:`eva button container run ${i||""}`,children:r.jsx("button",{disabled:u(),onClick:f,className:`eva button run ${i||""}`,children:n||e})})},or=({image:e,css_class:t,items:n,buttons:s,engine:i,on_success:c,on_fail:o})=>{let d;return e&&(d={background:`url(${e})`,backgroundPosition:"center",backgroundRepeat:"no-repeat",backgroundSize:"contain"}),r.jsx("div",{className:`eva canvas container ${t||""}`,children:r.jsxs("div",{style:d,className:`eva canvas area ${t||""}`,children:[n==null?void 0:n.map(l=>{let v;return l.position&&(v={position:"absolute",left:l.position.x,top:l.position.y}),r.jsxs("div",{style:v,className:`eva canvas element ${t||""} ${l.css_class||""}`,children:[l.label?`${l.label}: `:"",r.jsx(_e,{oid:l.oid,digits:l.digits,units:l.units,threshold:l.threshold,format_with:l.format_with,engine:i})]},`item_${l.oid}`)}),s==null?void 0:s.map(l=>{let v=l.kind;l.oid.startsWith("lmacro:")&&(v=Re.Run);let f;switch(l.position&&(f={position:"absolute",left:l.position.x,top:l.position.y}),v){case Re.Value:return r.jsx("div",{style:f,className:`eva canvas element ${t||""} ${l.css_class||""}`,children:r.jsx(Ye,{oid:l.oid,label:l.label,input_size:l.input_size,css_class:l.css_class,engine:i,on_success:c,on_fail:o},l.oid)},`button_${l.oid}`);case Re.Run:return r.jsx("div",{style:f,className:`eva canvas element ${t||""} ${l.css_class||""}`,children:r.jsx(Ve,{oid:l.oid,params:l.params,busy:l.busy,label:l.label,css_class:l.css_class,engine:i,on_success:c,on_fail:o},l.oid)},`button_${l.oid}`);default:return r.jsx("div",{style:f,className:`eva canvas element ${t||""} ${l.css_class||""}`,children:r.jsx(Ke,{oid:l.oid,label:l.label,css_class:l.css_class,engine:i,on_success:c,on_fail:o},l.oid)},l.oid)}})]})})};var mt=(e=>(e.Line="line",e.Bar="bar",e.Radar="radar",e.Doughnut="doughnut",e))(mt||{});const cr=({datasetIdKey:e,data:t,options:n,kind:s})=>{switch(s){case"line":return r.jsx(De.Line,{datasetIdKey:e,data:t,options:n});case"bar":return r.jsx(De.Bar,{datasetIdKey:e,data:t,options:n});case"radar":return r.jsx(De.Radar,{datasetIdKey:e,data:t,options:n});case"doughnut":return r.jsx(De.Doughnut,{datasetIdKey:e,data:t,options:n})}},lr=({oid:e,timeframe:t,formula:n,digits:s,update:i,prop:c,fill:o,args:d,colors:l,labels:v,title:f,options:u,className:m,width:E,height:_,data_callback:j,state:R,engine:A})=>_t({oid:e,timeframe:t,formula:n,digits:s,update:i,prop:c,fill:o,args:d,colors:l,labels:v,title:f,options:u,className:m,width:E,height:_,data_callback:j,state:R,kind:"line",engine:A}),_t=({oid:e,timeframe:t,formula:n,digits:s,update:i,prop:c,fill:o,args:d,colors:l,dataset_options:v,labels:f,title:u,options:m,className:E,width:_,height:j,data_callback:R,state:A,kind:b,engine:x})=>{const y=w.useMemo(()=>A?[]:e,[A,e]),p=it({oid:y,timeframe:t,update:i,prop:c,fill:o,digits:s,args:d,engine:x},[y,t,i,c,o,s,d,x]),k=A||p,P={width:_,height:j};if(w.useMemo(()=>{R&&R(k.data)},[R,k.data]),k.data)try{let C;c?C=c===O.StateProp.Any?O.StateProp.Value:c:C=O.StateProp.Value;let F={labels:k.data.t.map(z=>z*1e3),datasets:[]},M=0;for(let z=0;z<k.data.length;z++)for(let K=0;K<(Array.isArray(e)?e.length:1);K++){let X;l&&(X=l[M]);let te;n&&(typeof n=="string"?te=n:te=n[M]);let V;f&&(V=f[M]),V||(Array.isArray(e)?V=e[K]:V=e);let Z;Array.isArray(e)?Z=`${e[K]}/${C}`:Z=C;let se=[];try{te?se=k.data[z][Z].map(ce=>{try{let G=Ee.calculateFormula(te,ce);return s===void 0||G===void 0?G:parseFloat(G.toFixed(s))}catch{return NaN}}):se=k.data[z][Z]}catch{}let ne;v?ne=v(M):ne={fill:!1},F.datasets.push({data:se,label:V,borderColor:X,backgroundColor:X,...ne}),M+=1}let U,H,$=Array.isArray(t)?t[0]:t;if($.includes(":")){let[z,K]=$.split(":");const X=parseFloat(z),te=parseFloat(K);if(X&&te){const V=te-X;V<3600*2?$="T":V<86400*2?$="H":V<86400*30?$="D":V<86400*365?$="W":$="M"}}else $=$.slice(-1);switch($){case"T":case"S":U="second",H="mm:ss";break;case"W":U="day",H="MM/dd HH:mm";break;case"M":U="month",H="yyyy/MM/dd";break;case"D":U="hour",H="MM/dd HH:mm:ss";break;default:U="minute",H="HH:mm:ss"}const N={responsive:!0,scales:{y:{type:"linear",display:!0,position:"left"},y1:{type:"linear",display:!0,position:"right",grid:{drawOnChartArea:!1}},x:{type:"time",time:{unit:U,unitStepSize:1,round:U,tooltipFormat:H},ticks:{fontSize:12,fontColor:"#ccc",maxTicksLimit:8,maxRotation:0,autoSkip:!0,callback:function(z,K,X){return K===X.length-1?"":this.getLabelForValue(z).split(" ")}}}},plugins:{filler:{propagate:!0},title:{text:u,display:!0},legend:{display:M>1,position:"top"}}};let B=Ot.deepMerge(N,m);return r.jsx("div",{style:P,className:`eva chart container ${E}`,children:r.jsx(cr,{kind:b,datasetIdKey:"id",data:F,options:B})})}catch(C){const F=`Error: ${C})`;return r.jsx("div",{style:P,className:`eva chart error ${E}`,children:F})}else if(k.error){const C=`Error: ${k.error.message} (${k.error.code})`;return r.jsx("div",{style:P,className:`eva chart error ${E}`,children:C})}else return r.jsx("div",{style:P,className:`eva chart loading ${E}`})},ur=({minValue:e,maxValue:t,oid:n,formula:s,state:i,type:c,engine:o,digits:d,units:l,className:v,threshold:f,format_with:u,set_color_with:m,set_class_name_with:E,diameter:_,warnValue:j,critValue:R,lowWarnValue:A,lowCritValue:b,startAngle:x,endAngle:y,numTicks:p,offset:k,arcStrokeWidth:P,strokeLineCap:C,tickLength:F,baseRadius:M,tipRadius:U,needleOffset:H,middleRadius:$,showValue:N,label:B})=>{const z=xe({oid:n,engine:o},[n,o]);if(s&&s!=="x"){i=i?{...i}:{...z};try{typeof(i==null?void 0:i.value)=="number"&&(i.value=Ee.calculateFormula(s,i.value))}catch{i.value=NaN}}else i=i||z;switch(c){case we.Sphere:return r.jsx(fr,{minValue:e,maxValue:t,oid:n,formula:s,state:i,engine:o,digits:d,units:l,className:v,threshold:f,format_with:u,set_color_with:m,set_class_name_with:E,diameter:_,warnValue:j,critValue:R,lowWarnValue:A,lowCritValue:b,startAngle:x,endAngle:y,numTicks:p,offset:k,arcStrokeWidth:P,strokeLineCap:C,tickLength:F,baseRadius:M,tipRadius:U,needleOffset:H,middleRadius:$,showValue:N,label:B});case we.Light:return r.jsx(vr,{minValue:e,maxValue:t,oid:n,formula:s,state:i,engine:o,digits:d,units:l,className:v,threshold:f,format_with:u,set_color_with:m,set_class_name_with:E,diameter:_,warnValue:j,critValue:R,lowWarnValue:A,lowCritValue:b,startAngle:x,endAngle:y,numTicks:p,offset:k,arcStrokeWidth:P,strokeLineCap:C,tickLength:F,baseRadius:M,tipRadius:U,needleOffset:H,middleRadius:$,showValue:N,label:B});case we.Minimal:return r.jsx(gr,{minValue:e,maxValue:t,oid:n,formula:s,state:i,engine:o,digits:d,units:l,className:v,threshold:f,format_with:u,set_color_with:m,set_class_name_with:E,diameter:_,warnValue:j,critValue:R,lowWarnValue:A,lowCritValue:b,startAngle:x,endAngle:y,numTicks:p,offset:k,arcStrokeWidth:P,strokeLineCap:C,tickLength:F,baseRadius:M,tipRadius:U,needleOffset:H,middleRadius:$,showValue:N,label:B});case we.Modern:return r.jsx(mr,{minValue:e,maxValue:t,oid:n,formula:s,state:i,engine:o,digits:d,units:l,className:v,threshold:f,format_with:u,set_color_with:m,set_class_name_with:E,diameter:_,warnValue:j,critValue:R,lowWarnValue:A,lowCritValue:b,startAngle:x,endAngle:y,numTicks:p,offset:k,arcStrokeWidth:P,strokeLineCap:C,showValue:N,label:B});default:return r.jsx(hr,{minValue:e,maxValue:t,oid:n,formula:s,state:i,engine:o,digits:d,units:l,className:v,threshold:f,format_with:u,set_color_with:m,set_class_name_with:E,diameter:_,warnValue:j,critValue:R,lowWarnValue:A,lowCritValue:b,startAngle:x,endAngle:y,numTicks:p,offset:k,arcStrokeWidth:P,strokeLineCap:C,tickLength:F,baseRadius:M,tipRadius:U,needleOffset:H,middleRadius:$,showValue:N,label:B})}},be=e=>e*Math.PI/180,dr=(e,t,n)=>{const s=[],c=(t-e)/(n-1);for(let o=0;o<n;o++)s.push(Math.floor(e+o*c));return s.reverse()},je=(e,t,n,s)=>{const i=be(s);return{x:e+n*Math.cos(i),y:t+n*Math.sin(i)}},Pe=e=>{const{startAngle:t,endAngle:n,numTicks:s,diameter:i,domain:c}=e,o=i/2,[d,l]=c,v=w.useMemo(()=>dr(t,n,s).reverse(),[t,n,s]),f=w.useCallback(b=>{const{angle:x,offset:y}=b,p=je(0,0,o-y,x+90);return{x:p.x,y:p.y,dominantBaseline:"middle",textAnchor:"middle"}},[i,o]),u=w.useCallback(b=>{const{length:x,angle:y}=b,p=je(0,0,o,y+90),k=je(0,0,o+x,y+90);return{x1:p.x,x2:k.x,y1:p.y,y2:k.y}},[v,i,o]),m=b=>{const x=n-t,y=l-d,p=d+(b-t)/x*y;return Math.round(p)},E=b=>{const x=n-t,y=l-d,p=t+(b-d)/y*x;return Math.round(p)},_=w.useCallback(b=>{const{offset:x=0,startAngle:y,endAngle:p,...k}=b;let P=je(0,0,o+x,y+90),C=je(0,0,o+x,p+90),F=p-y<180?"0":"1";return{d:["M",P.x-.001,P.y,"A",o+x,o+x,0,F,1,C.x,C.y].join(" "),...k}},[i,o]),j=w.useCallback(b=>{const{value:x,baseRadius:y,tipRadius:p,offset:k=0}=b,P=E(x),C={x:0,y:0},F=je(0,0,o-k,P+90);return isNaN(F.x)&&(F.x=0),isNaN(F.y)&&(F.y=0),{base:{r:y,cx:C.x,cy:C.y},tip:{r:p,cx:F.x,cy:F.y},points:[[C.x+y*Math.cos(be(P)),C.y+y*Math.sin(be(P))],[F.x+p*Math.cos(be(P)),F.y+p*Math.sin(be(P))],[F.x+p*Math.cos(be(P-180)),F.y+p*Math.sin(be(P-180))],[C.x+y*Math.cos(be(P-180)),C.y+y*Math.sin(be(P-180))]].map(([U,H])=>{if(!isNaN(U)||!isNaN(H))return`${U},${H}`}).join(" ")}},[E,i,o]),R=w.useCallback((b,x)=>{const y=b-x;return Math.cos(be(y))*i/2},[i]);return{ticks:v,getTickProps:u,getLabelProps:f,valueToAngle:E,angleToValue:m,getArcProps:_,getNeedleProps:j,getSVGProps:()=>{const b=M=>{if(t<M&&n>M)return i/2;const U=R(t+90,M+90),H=R(n+90,M+90);return Math.max(0,U,H)},[x,y,p,k]=[b(180),b(270),b(0),b(90)],P=k+y,C=x+p,F=[-k,-x,P,C].join(" ");return{width:P,height:C,viewBox:F}}}},Fe=(e,t,n,s,i)=>He("gauge",e,t,n,s,i),de={diameter:200,minValue:0,maxValue:100,startAngle:90,endAngle:270,numTicks:11,offset:10,arcStrokeWidth:24,strokeLin