UNPKG

@eva-ics/webengine-react

Version:

React components for EVA ICS HMI Web Engine

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