mdas-jsview-sdk 1.0.10-uat.0 → 1.0.12-uat.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mdas-sdk.esm.js +328 -82
- package/dist/mdas-sdk.esm.js.map +1 -1
- package/dist/mdas-sdk.js +328 -82
- package/dist/mdas-sdk.js.map +1 -1
- package/dist/mdas-sdk.min.js +9 -9
- package/dist/mdas-sdk.min.js.map +1 -1
- package/package.json +1 -1
package/dist/mdas-sdk.min.js
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).MdasSDK={})}(this,(function(t){"use strict";class e{constructor(){this.state=new Map,this.listeners=new Map}setState(t,e){this.state.set(t,e),this.notifyListeners(t,e)}getState(t){return this.state.get(t)}subscribe(t,e){return this.listeners.has(t)||this.listeners.set(t,new Set),this.listeners.get(t).add(e),()=>{const n=this.listeners.get(t);n&&n.delete(e)}}notifyListeners(t,e){const n=this.listeners.get(t);n&&n.forEach((t=>t(e)))}clear(){this.state.clear(),this.listeners.clear()}}class n{constructor(t,e,n){this.setContainer(t),this.options=e,this.widgetId=n,this.isDestroyed=!1,this.lastData=null,this.lastDataTimestamp=null,this.connectionQuality="disconnected",this.eventListeners=[],this.timeouts=[],this.intervals=[]}setContainer(t){if(!t)throw new Error("DOM element is required for widget");if("string"==typeof t){const e=document.querySelector(t);if(!e)throw new Error(`Element not found: ${t}`);this.container=e}else{if(t.nodeType!==Node.ELEMENT_NODE)throw new Error("Invalid element provided to widget");this.container=t}}showLoading(){const t=this.container.querySelector(".widget-loading-overlay");t&&t.classList.remove("hidden")}hideLoading(){const t=this.container.querySelector(".widget-loading-overlay");t&&t.classList.add("hidden")}showError(t){this.hideLoading(),this.clearError();const e=document.createElement("div");e.className="widget-error",e.textContent=`Error: ${t}`,this.container.appendChild(e)}clearError(){const t=this.container.querySelector(".widget-error");t&&t.remove()}showConnectionQuality(){const t=this.container.querySelector(".connection-quality");if(t&&t.remove(),"live"===this.connectionQuality)return;const e=this.container.querySelector('.last-update, [class*="last-update"], [class*="timestamp"]');if(e){const t=document.createElement("span");switch(t.className="connection-quality",this.connectionQuality){case"offline":t.textContent=" (disconnected)",t.style.color="#dc2626",t.style.fontWeight="500";break;case"reconnecting":t.textContent=" (reconnecting...)",t.style.color="#d97706"}t.style.fontSize="11px",e.appendChild(t)}}handleMessage(t){if(!this.isDestroyed)try{const{event:e,data:n}=t;if(console.log("[BaseWidget] handleMessage called with event:",e,"data:",n),this.debug&&console.log(`[${this.type}] Received:`,e,n),"connection"===e)return void this.handleConnectionStatus(n);if("data"===e)return console.log("[BaseWidget] Caching live data"),this.lastData=n,this.lastDataTimestamp=Date.now(),this.connectionQuality="live",void this.handleData(n);if("session_revoked"===e)return void this.handleSessionRevoked(n);this.handleCustomEvent&&this.handleCustomEvent(e,n)}catch(t){console.error(`[${this.constructor.name}] Error handling message:`,t),this.showError("Error processing data")}}handleSessionRevoked(t){"attempting_relogin"===t.status?(this.connectionQuality="reconnecting",this.lastData?this.showCachedData():this.showLoading()):"relogin_failed"===t.status?(this.connectionQuality="offline",this.showError(t.error||"Session expired. Please refresh the page.")):"relogin_successful"===t.status&&(this.connectionQuality="live",this.hideLoading(),this.clearError())}handleData(t){throw new Error("handleData must be implemented by child widget")}handleConnectionStatus(t){"connected"===t.status?(this.connectionQuality="live",this.clearError(),this.hideLoading()):"reconnecting"===t.status?(this.connectionQuality="reconnecting",this.lastData?this.showCachedData():this.showLoading()):"disconnected"===t.status?(this.connectionQuality="offline",this.lastData?this.showCachedData():this.hideLoading()):"failed"===t.status?(this.connectionQuality="offline",this.handleConnectionFailed(t),this.showConnectionQuality()):"error"===t.status&&(this.connectionQuality="offline",this.lastData?this.showCachedData():this.hideLoading())}showCachedData(){if(this.lastData&&this.lastDataTimestamp){const t=Date.now()-this.lastDataTimestamp,e=t>3e5,n={...this.lastData,_cached:!0,_cacheAge:t,_isStale:e,_quality:this.connectionQuality};this.handleData(n)}}addEventListener(t,e,n){let i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};t&&e&&n?(t.addEventListener(e,n,i),this.eventListeners.push({element:t,event:e,handler:n,options:i})):console.warn("[BaseWidget] Invalid addEventListener parameters")}setTimeout(t,e){const n=setTimeout(t,e);return this.timeouts.push(n),n}setInterval(t,e){const n=setInterval(t,e);return this.intervals.push(n),n}clearTimeout(t){clearTimeout(t);const e=this.timeouts.indexOf(t);e>-1&&this.timeouts.splice(e,1)}clearInterval(t){clearInterval(t);const e=this.intervals.indexOf(t);e>-1&&this.intervals.splice(e,1)}showInputError(t,e){if(!t)return;this.clearInputError(t);const n=document.createElement("div");n.className="input-error-message",n.textContent=e,n.style.cssText="\n color: #dc2626;\n font-size: 12px;\n margin-top: 4px;\n animation: slideDown 0.2s ease-out;\n ",t.classList.add("input-error"),t.style.borderColor="#dc2626",t.parentNode&&t.parentNode.insertBefore(n,t.nextSibling),t.errorElement=n}clearInputError(t){t&&(t.errorElement&&(t.errorElement.remove(),t.errorElement=null),t.classList.remove("input-error"),t.style.borderColor="")}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.eventListeners.forEach((t=>{let{element:e,event:n,handler:i,options:s}=t;try{e.removeEventListener(n,i,s)}catch(t){console.error("[BaseWidget] Error removing event listener:",t)}})),this.eventListeners=[],this.timeouts.forEach((t=>{clearTimeout(t)})),this.timeouts=[],this.intervals.forEach((t=>{clearInterval(t)})),this.intervals=[],this.lastData=null,this.container&&(this.container.innerHTML=""),this.debug&&console.log(`[${this.constructor.name}] Widget destroyed and cleaned up`))}handleConnectionFailed(t){this.connectionQuality="offline",this.lastData?(this.showCachedData(),this.hideLoading()):this.hideLoading(),this.debug&&console.log(`[${this.constructor.name}] Connection failed after ${t.maxAttempts} attempts`)}}class i{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.symbol=t.Symbol||"",this.companyName=t.CompName||"",this.companyDescription=t.CompDesc||"",this.instrumentType=t.InstrType||"",this.lastPrice=t.LastPx||0,this.previousClose=t.YestClosePx||0,this.open=t.OpenPx||0,this.high=t.HighPx||0,this.low=t.LowPx||0,this.close=t.ClosingPx||0,this.change=t.Change||0,this.changePercent=t.ChangePercent||0,this.vwap=t.VWAP||0,this.volume=t.Volume||0,this.averageVolume=t.AvgVol30d||0,this.yesterdayVolume=t.YesterdayTradeVolume||0,this.bidPrice=t.BidPx||0,this.bidSize=t.BidSz||0,this.bidExchange=t.BidExch||"",this.askPrice=t.AskPx||0,this.askSize=t.AskSz||0,this.askExchange=t.AskExch||"",this.issueMarket=t.IssueMarket||"",this.marketName=t.MarketName||"",this.marketDescription=t.MarketDesc||"",this.mic=t.MIC||"",this.countryCode=t.CountryCode||"",this.timeZone=t.TimeZone||"",this.tradePrice=t.TradePx||0,this.tradeSize=t.TradeSz||0,this.tradeCondition=t.Condition||0,this.tradeTime=t.TradeTime||"",this.tradeRegion=t.TradeRegion||"",this.tradeRegionName=t.TradeRegionName||"",this.preMarketPrice=t.PreLastPx||0,this.preMarketTradeTime=t.PreTradeTime||"",this.postMarketPrice=t.PostLastPx||0,this.postMarketTradeTime=t.PostTradeTime||"",this.high52Week=t.High52wPx||0,this.low52Week=t.Low52wPx||0,this.high52WeekDate=t.High52wDate||"",this.low52WeekDate=t.Low52wDate||"",this.calendarYearHigh=t.CalendarYearHigh||0,this.calendarYearLow=t.CalendarYearLow||0,this.calendarYearHighDate=t.CalendarYearHighDate||"",this.calendarYearLowDate=t.CalendarYearLowDate||"",this.marketCap=t.MktCap||0,this.peRatio=t.PeRatio||0,this.beta=t.FundBeta||0,this.sharesOutstanding=t.ComShrsOut||0,this.dividendYield=t.DivYield||0,this.dividendAmount=t.DivAmt||0,this.dividendRate=t.DividendRate||0,this.dividendPaymentDate=t.DividendPaymentDate||t.PayDate||"",this.dividendExDate=t.DividendExDate||t.DivDateEx||"",this.isin=t.ISIN||"",this.cusip=t.CUSIP||"",this.sedol=t.SEDOL||"",this.gics=t.GICS||"",this.status=t.Status||"",this.dataSource=t.DataSource||"",this.quoteTime=t.QuoteTime||"",this.infoTime=t.InfoTime||""}get openPrice(){return this.open}get description(){return this.companyDescription}get lastUpdate(){return this.quoteTime||this.infoTime}getSecurityType(){return{257:"Stock",262:"ETF",261:"Mutual Fund",258:"Bond",260:"Option",263:"Future",259:"Index"}[this.instrumentType]||"Stock"}getPriceChange(){return this.change}getPriceChangePercent(){return 100*this.changePercent}getDataSource(){return"delay"===this.dataSource.toLowerCase()?"20 mins delayed":"real-time"===this.dataSource.toLowerCase()?"Real-time":null!==this.dataSource&&""!==this.dataSource?this.dataSource:"MDAS Server"}getCurrentPrice(){return this.lastPrice}get52WeekRange(){return`${this.low52Week.toFixed(2)} - ${this.high52Week.toFixed(2)}`}getMarketCapFormatted(){return this.formatMarketCap()}formatPrice(){return`$${(arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.lastPrice).toFixed(2)}`}formatPriceChange(){const t=this.getPriceChange();return`${t>=0?"+":""} ${t.toFixed(2)}`}formatPriceChangePercent(){const t=this.getPriceChangePercent();return`${t>=0?"+":""}${t.toFixed(2)}%`}formatBidAsk(){return`$${this.bidPrice.toFixed(2)} x ${this.bidSize} / $${this.askPrice.toFixed(2)} x ${this.askSize}`}formatVolume(){return 0===this.volume?"N/A":this.volume.toLocaleString()}formatAvgVolume(){return 0===this.averageVolume?"N/A":this.averageVolume.toLocaleString()}formatAverageVolume(){return 0===this.averageVolume?"N/A":this.averageVolume.toLocaleString()}formatDayRange(){return 0===this.low&&0===this.high?"N/A":`$${this.low.toFixed(2)} - $${this.high.toFixed(2)}`}format52WeekRange(){return 0===this.low52Week&&0===this.high52Week?"N/A":`${this.low52Week.toFixed(2)} - ${this.high52Week.toFixed(2)}`}formatMarketCap(){if(0===this.marketCap)return"N/A";const t=1e6*this.marketCap;return t>=1e12?`$${(t/1e12).toFixed(2)}T`:t>=1e9?`$${(t/1e9).toFixed(2)}B`:t>=1e6?`$${(t/1e6).toFixed(2)}M`:t>=1e3?`$${(t/1e3).toFixed(2)}K`:`$${t.toFixed(2)}`}formatAvg30DayVolume(){return this.formatAverageVolume()}static fromApiResponse(t){return new i(t)}}class s{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.widget=t,this.options={maxLength:e.maxLength||10,placeholder:e.placeholder||"Enter symbol...",onSymbolChange:e.onSymbolChange||(()=>{}),debug:e.debug||!1,autoUppercase:!1!==e.autoUppercase,...e},this.symbolType=e.symbolType||null,this.apiService=this.widget.wsManager.getApiService(),this.isEditing=!1,this.isValidating=!1,this.originalSymbol="",this.elements={},this.addStyles(),this.initialize()}initialize(){this.setupElements(),this.attachEventListeners()}setupElements(){if(this.elements.symbolDisplay=this.widget.container.querySelector(".editable-symbol"),!this.elements.symbolDisplay)throw new Error('No element with class "editable-symbol" found in widget');this.originalSymbol=this.elements.symbolDisplay.textContent.trim(),this.elements.symbolDisplay.dataset.originalSymbol=this.originalSymbol}attachEventListeners(){this.startEditing=this.startEditing.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.handleInput=this.handleInput.bind(this),this.handleBlur=this.handleBlur.bind(this),this.handleClickOutside=this.handleClickOutside.bind(this),this.elements.symbolDisplay.addEventListener("dblclick",this.startEditing)}startEditing(){this.isEditing||this.isValidating||(this.isEditing=!0,this.originalSymbol=this.elements.symbolDisplay.textContent.trim(),this.options.debug&&(console.log(this.widget.connectionQuality),console.log("[SymbolEditor] Starting edit mode for:",this.originalSymbol)),this.transformToInput())}transformToInput(){const t=this.elements.symbolDisplay,e=window.getComputedStyle(t),n=document.createElement("div");n.className="symbol-edit-container",n.style.display="inline-flex",n.style.alignItems="center",n.style.gap="8px",n.style.verticalAlign="baseline";const i=document.createElement("input");i.type="text",i.value=this.originalSymbol,i.className=t.className+" symbol-input-mode",i.style.fontSize=e.fontSize,i.style.fontWeight=e.fontWeight,i.style.fontFamily=e.fontFamily,i.style.color=e.color,i.style.backgroundColor="transparent",i.style.border="2px solid #3b82f6",i.style.borderRadius="4px",i.style.padding="2px 6px",i.style.margin="0",i.style.outline="none",i.style.width="auto",i.style.minWidth="120px",i.style.maxWidth="200px",i.style.flexShrink="0";const s=document.createElement("button");s.className="symbol-save-btn",s.innerHTML="✓",s.title="Save symbol",s.style.width="28px",s.style.height="28px",s.style.border="none",s.style.borderRadius="4px",s.style.backgroundColor="#059669",s.style.color="white",s.style.cursor="pointer",s.style.fontSize="12px",s.style.display="inline-flex",s.style.alignItems="center",s.style.justifyContent="center",s.style.flexShrink="0",n.appendChild(i),n.appendChild(s),t.style.display="none",t.parentNode.insertBefore(n,t.nextSibling),this.elements.symbolInput=i,this.elements.saveBtn=s,this.elements.editContainer=n,i.focus(),i.select(),i.addEventListener("keydown",this.handleKeydown),i.addEventListener("input",this.handleInput),i.addEventListener("blur",this.handleBlur),document.addEventListener("click",this.handleClickOutside),s.addEventListener("click",(t=>{t.stopPropagation(),this.saveSymbol()}))}async saveSymbol(){if(this.isValidating)return;const t=this.elements.symbolInput.value.trim(),e=await this.validateSymbol(t);if(!e.isValid)return this.showError(e.message),void setTimeout((()=>{this.elements.symbolInput&&(this.elements.symbolInput.value=this.originalSymbol,this.clearError(),this.cancelEditing())}),2e3);this.setLoadingState(!0);try{const n=await this.options.onSymbolChange(t,this.originalSymbol,e.data);if(n&&n.success)this.finishEditing(t),this.showSuccess("Symbol updated successfully");else{const t=n?.message||"Failed to update symbol";this.showError(t)}}catch(t){console.error("[SymbolEditor] Error changing symbol:",t),this.showError("Error updating symbol")}finally{this.setLoadingState(!1)}}cancelEditing(){this.options.debug&&console.log("[SymbolEditor] Cancelling edit mode"),this.finishEditing(this.originalSymbol)}finishEditing(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;this.isEditing=!1;const e=t||this.originalSymbol;this.elements.symbolDisplay.textContent=e,this.elements.symbolDisplay.dataset.originalSymbol=e,this.elements.symbolDisplay.style.display="",this.elements.editContainer&&(this.elements.editContainer.remove(),this.elements.editContainer=null),this.elements.symbolInput=null,this.elements.saveBtn=null,document.removeEventListener("click",this.handleClickOutside)}handleKeydown(t){"Enter"===t.key?(t.preventDefault(),this.saveSymbol()):"Escape"===t.key&&(t.preventDefault(),this.cancelEditing())}handleInput(t){if(this.options.autoUppercase){const e=t.target,n=e.selectionStart,i=e.selectionEnd;e.value=e.value.toUpperCase(),e.setSelectionRange(n,i)}this.clearError()}handleBlur(t){t.relatedTarget&&t.relatedTarget===this.elements.saveBtn||setTimeout((()=>{this.isEditing&&this.cancelEditing()}),150)}handleClickOutside(t){if(!this.isEditing)return;this.elements.symbolInput?.contains(t.target)||this.elements.saveBtn?.contains(t.target)||this.cancelEditing()}async validateSymbol(t){if("live"!==this.widget.connectionQuality)return{isValid:!1,message:"Not connected to data service"};if(!t||0===t.trim().length)return{isValid:!1,message:"Symbol cannot be empty"};const e=t.trim().toUpperCase();try{if("optionsl1"==this.symbolType){const t=await this.apiService.quoteOptionl1(e);return t[0]&&(t[0].error||1==t[0].not_found)?1==t[0].not_found?{isValid:!1,message:"Symbol not found"}:{isValid:!1,message:t[0].error}:{isValid:!0,data:t[0]}}if("quotel1"==this.symbolType||"nightsession"==this.symbolType){const t=await this.apiService.quotel1(e);return t&&t.message?t.message.includes("no data")?{isValid:!1,message:"Symbol not found"}:{isValid:!1,message:t.message}:{isValid:!0,data:t.data[0]}}if("nightsession"==this.symbolType){const t=await this.apiService.quoteBlueOcean(e);return t[0]&&1==t[0].not_found?{isValid:!1,message:"Symbol not found"}:t[0]&&0==t[0].not_found?{isValid:!0,data:t[0]}:{isValid:!1,message:t[0].error}}}catch(t){return console.warn("[SymbolEditor] API validation failed, falling back to basic validation:",t),this.defaultValidator(e)}return this.defaultValidator(e)}defaultValidator(t){return t&&0!==t.length?t.length>this.options.maxLength?{isValid:!1,message:`Symbol too long (max ${this.options.maxLength} chars)`}:{isValid:!0,data:null}:{isValid:!1,message:"Symbol cannot be empty"}}setLoadingState(t){this.isValidating=t,this.elements.saveBtn&&(t?(this.elements.saveBtn.innerHTML='<div class="loading-spinner"></div>',this.elements.saveBtn.disabled=!0):(this.elements.saveBtn.innerHTML="✓",this.elements.saveBtn.disabled=!1)),this.elements.symbolInput&&(this.elements.symbolInput.disabled=t)}showError(t){if(this.elements.symbolInput){this.elements.symbolInput.style.borderColor="#dc2626",this.elements.symbolInput.style.boxShadow="0 0 0 3px rgba(220, 38, 38, 0.1)",this.removeErrorMessage();const e=document.createElement("div");e.className="symbol-error-message",e.textContent=t,e.style.cssText="\n color: #dc2626;\n font-size: 12px;\n margin-bottom: 2px;\n position: absolute;\n background: white;\n z-index: 1000;\n transform: translateY(-100%);\n top: -4px;\n left: 0; // Align with input box\n ";const n=this.elements.editContainer;n&&(n.style.position="relative",n.appendChild(e)),this.elements.errorMessage=e,this.elements.symbolInput.focus()}}removeErrorMessage(){this.elements.errorMessage&&(this.elements.errorMessage.remove(),this.elements.errorMessage=null)}clearError(){this.elements.symbolInput&&(this.elements.symbolInput.style.borderColor="#3b82f6",this.elements.symbolInput.style.boxShadow="0 0 0 3px rgba(59, 130, 246, 0.1)",this.elements.symbolInput.title=""),this.removeErrorMessage()}showSuccess(t){this.options.debug&&console.log("[SymbolEditor] Success:",t)}updateSymbol(t){const e=this.options.autoUppercase?t.toUpperCase():t;this.elements.symbolDisplay.textContent=e,this.elements.symbolDisplay.dataset.originalSymbol=e,this.options.debug&&console.log("[SymbolEditor] Symbol updated externally:",e)}destroy(){this.finishEditing(),this.elements.symbolDisplay?.removeEventListener("dblclick",this.startEditing)}addStyles(){if(document.querySelector("#symbol-editor-styles"))return;const t=document.createElement("style");t.id="symbol-editor-styles",t.textContent='\n .editable-symbol {\n cursor: pointer;\n transition: all 0.2s ease;\n position: relative;\n }\n\n .editable-symbol:hover {\n opacity: 0.8;\n transform: scale(1.02);\n }\n\n .editable-symbol:hover::after {\n content: "✎";\n position: absolute;\n top: -8px;\n right: -8px;\n background: #3b82f6;\n color: white;\n font-size: 10px;\n padding: 2px 4px;\n border-radius: 4px;\n opacity: 0.8;\n pointer-events: none;\n }\n\n .symbol-input-mode {\n text-transform: uppercase;\n }\n\n .symbol-save-btn:hover {\n background-color: #047857 !important;\n transform: scale(1.05);\n }\n\n .symbol-save-btn:disabled {\n background-color: #9ca3af !important;\n cursor: not-allowed !important;\n transform: none !important;\n }\n\n .loading-spinner {\n width: 12px;\n height: 12px;\n border: 2px solid rgba(255, 255, 255, 0.3);\n border-top-color: white;\n border-radius: 50%;\n animation: spin 1s linear infinite;\n }\n\n @keyframes spin {\n to { transform: rotate(360deg); }\n }\n ',document.head.appendChild(t)}}const o='\n /* ========================================\n FONT SIZE SYSTEM - CSS Variables\n Adjust --mdas-base-font-size to scale all fonts\n ======================================== */\n :root {\n /* Base font size - change this to scale everything */\n --mdas-base-font-size: 14px;\n\n /* Relative font sizes (in em, scales with base) */\n --mdas-company-name-size: 1.43em; /* 20px at base 14px */\n --mdas-symbol-size: 1.79em; /* 25px at base 14px */\n --mdas-price-size: 2.29em; /* 32px at base 14px */\n --mdas-price-change-size: 1.14em; /* 16px at base 14px */\n --mdas-section-title-size: 1em; /* 14px at base 14px */\n --mdas-data-label-size: 0.93em; /* 13px at base 14px */\n --mdas-data-value-size: 1em; /* 14px at base 14px */\n --mdas-bid-ask-size: 1.07em; /* 15px at base 14px */\n --mdas-small-text-size: 0.86em; /* 12px at base 14px */\n --mdas-badge-size: 0.86em; /* 12px at base 14px */\n --mdas-loading-text-size: 1.14em; /* 16px at base 14px */\n --mdas-no-data-title-size: 1.14em; /* 16px at base 14px */\n --mdas-edit-icon-size: 0.71em; /* 10px at base 14px */\n }\n\n /* Apply base font size to widgets */\n .widget {\n font-size: var(--mdas-base-font-size);\n }\n\n /* ========================================\n OPTIONAL CARD STYLING\n Add \'widget-styled\' class for card design\n ======================================== */\n .widget-styled {\n background: white;\n border-radius: 12px;\n padding: 24px;\n box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);\n border: 1px solid #e5e7eb;\n }\n\n /* Base widget styles */\n .widget-loading-overlay {\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background: rgba(255, 255, 255, 0.95);\n backdrop-filter: blur(2px);\n display: flex;\n align-items: center;\n justify-content: center;\n z-index: 10;\n border-radius: 12px;\n }\n\n .widget-loading-overlay.hidden {\n display: none;\n }\n\n .widget {\n font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, sans-serif;\n width: 100%;\n max-width: 1400px;\n }\n\n /* HEADER STYLES */\n\n .widget-header {\n display: flex;\n justify-content: space-between;\n align-items: flex-start;\n margin-bottom: 20px;\n gap: 16px;\n }\n\n .symbol-section {\n display: flex;\n flex-direction: column;\n gap: 4px;\n }\n\n .night-company-name {\n font-size: var(--mdas-company-name-size);\n font-weight: 500;\n color: #111827;\n cursor: pointer;\n transition: all 0.2s ease;\n position: relative;\n }\n\n .symbol {\n font-size: var(--mdas-symbol-size);\n font-weight: 700;\n color: #111827;\n cursor: pointer;\n transition: all 0.2s ease;\n position: relative;\n }\n\n .symbol:hover {\n opacity: 0.8;\n transform: scale(1.02);\n }\n\n .symbol:hover::after {\n content: "✎";\n position: absolute;\n top: -8px;\n right: -8px;\n background: #3b82f6;\n color: white;\n font-size: var(--mdas-edit-icon-size);\n padding: 2px 4px;\n border-radius: 4px;\n opacity: 0.8;\n }\n\n .data-type {\n background:rgb(214, 228, 250);\n padding: 2px 8px;\n border-radius: 6px;\n font-size: var(--mdas-badge-size);\n font-weight: 500;\n color: #3b82f6;\n }\n\n .price-section {\n text-align: right;\n }\n\n .current-price {\n font-size: var(--mdas-price-size);\n font-weight: 700;\n color: #111827;\n line-height: 1;\n }\n\n .price-change {\n font-size: var(--mdas-price-change-size);\n font-weight: 600;\n margin-top: 4px;\n display: flex;\n align-items: center;\n justify-content: flex-end;\n gap: 4px;\n }\n\n .price-change.positive { \n color: #10b981; \n }\n\n .price-change.negative { \n color: #ef4444; \n }\n\n .price-change.neutral { \n color: #6b7280; \n }\n\n .market-data-widget .price-change.positive::before,\n .night-session-widget .price-change.positive::before,\n .options-widget .price-change.positive::before{\n content: "↗";\n }\n\n .market-data-widget .price-change.negative::before,\n .night-session-widget .price-change.negative::before,\n .options-widget .price-change.negative::before {\n content: "↘";\n }\n\n /* BODY SECTION STYLES */\n\n .data-grid {\n display: grid;\n grid-template-columns: 1fr 1fr;\n gap: 32px;\n margin-bottom: 24px;\n }\n\n .data-section {\n display: flex;\n flex-direction: column;\n gap: 16px;\n }\n\n .section-title {\n font-size: var(--mdas-section-title-size);\n font-weight: 600;\n color: #6b7280;\n margin: 0;\n text-transform: uppercase;\n letter-spacing: 0.5px;\n border-bottom: 1px solid #e5e7eb;\n padding-bottom: 8px;\n }\n\n .data-row {\n display: grid;\n grid-template-columns: 1fr 1fr;\n gap: 16px;\n }\n\n .data-item {\n display: flex;\n flex-direction: column;\n gap: 4px;\n }\n\n .price-metadata,\n .data-label {\n font-size: var(--mdas-data-label-size);\n color: #6b7280;\n font-weight: 500;\n }\n\n .data-value {\n font-size: var(--mdas-data-value-size);\n font-weight: 600;\n color: #111827;\n text-align: right;\n flex-shrink: 0;\n }\n\n\n /* Footer */\n .widget-footer {\n display: flex;\n justify-content: space-between;\n align-items: center;\n padding-top: 16px;\n border-top: 1px solid #e5e7eb;\n font-size: var(--mdas-small-text-size);\n color: #9ca3af;\n }\n \n\n /* LOADING STYLES */\n\n\n .loading-content {\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: 16px;\n }\n\n .loading-spinner {\n width: 40px;\n height: 40px;\n border: 4px solid #e5e7eb;\n border-top-color: #3b82f6;\n border-radius: 50%;\n animation: spin 1s linear infinite;\n }\n\n .loading-text {\n color: #6b7280;\n font-size: var(--mdas-loading-text-size);\n font-weight: 500;\n }\n\n @keyframes spin {\n to { transform: rotate(360deg); }\n }\n\n .widget-error {\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n background: #fef2f2;\n border: 1px solid #fecaca;\n border-radius: 8px;\n padding: 16px;\n color: #dc2626;\n font-size: var(--mdas-data-value-size);\n font-weight: 600;\n text-align: center;\n z-index: 10;\n max-width: 80%;\n }\n\n /* Price change colors */\n .positive {\n color: #059669;\n }\n\n .negative {\n color: #dc2626;\n }\n\n \n\n /* No data state */\n .no-data-state {\n display: flex;\n align-items: center;\n justify-content: center;\n min-height: 160px;\n margin: 16px 0;\n background: #f9fafb;\n border: 1px solid #e5e7eb;\n border-radius: 12px;\n padding: 24px 16px;\n width: 100%;\n box-sizing: border-box;\n overflow: hidden;\n }\n\n .no-data-content {\n text-align: center;\n max-width: 280px;\n width: 100%;\n word-wrap: break-word;\n overflow-wrap: break-word;\n }\n\n .no-data-icon {\n margin-bottom: 16px;\n display: flex;\n justify-content: center;\n }\n\n .no-data-icon svg {\n opacity: 0.6;\n }\n\n .no-data-title {\n font-size: var(--mdas-no-data-title-size);\n font-weight: 600;\n color: #6b7280;\n margin: 0 0 8px 0;\n }\n\n .no-data-description {\n font-size: var(--mdas-data-value-size);\n color: #9ca3af;\n margin: 0 0 12px 0;\n line-height: 1.4;\n }\n\n .no-data-description strong {\n color: #6b7280;\n font-weight: 600;\n }\n\n .no-data-guidance {\n font-size: var(--mdas-small-text-size);\n color: #9ca3af;\n margin: 0;\n font-style: italic;\n }\n\n /* Error Access State */\n .no-data-state.error-access {\n border: 1px solid #fecaca;\n background:rgb(255, 255, 255);\n \n }\n\n .no-data-title.error {\n color: #ef4444;\n }\n\n .no-data-icon.error svg {\n stroke: #ef4444;\n }\n\n .no-data-icon.error svg circle[fill] {\n fill: #ef4444;\n }\n',a=`\n ${o}\n\n /* Reset and base styles for widget */\n\n .night-session-widget {\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;\n line-height: 1.5;\n max-width: 800px;\n position: relative;\n }\n\n /* STANDARDIZED HEADER LAYOUT */\n\n\n .symbol-section {\n display: flex;\n flex-direction: column;\n gap: 4px;\n }\n\n .night-session-widget .symbol {\n font-size: var(--mdas-symbol-size);\n font-weight: 700;\n color: #111827;\n cursor: pointer;\n transition: all 0.2s ease;\n position: relative;\n }\n\n .night-session-widget .symbol:hover {\n opacity: 0.8;\n transform: scale(1.02);\n }\n\n .night-session-widget .symbol:hover::after {\n content: "✎";\n position: absolute;\n top: -8px;\n right: -8px;\n background: #3b82f6;\n color: white;\n font-size: var(--mdas-edit-icon-size);\n padding: 2px 4px;\n border-radius: 4px;\n opacity: 0.8;\n }\n\n .company-info {\n display: flex;\n align-items: center;\n gap: 8px;\n font-size: var(--mdas-section-title-size);\n color: #6b7280;\n }\n\n .market-name {\n font-weight: 600;\n text-transform: uppercase;\n }\n\n /* Company and market info styling */\n .company-market-info {\n display: flex;\n align-items: center;\n gap: 8px;\n font-size: var(--mdas-small-text-size);\n color: #6b7280;\n margin-bottom: 4px;\n }\n\n .company-market-info .market-name {\n font-weight: 600;\n }\n\n .company-market-info .market-name::before {\n content: '|';\n margin-right: 8px;\n color: #9ca3af;\n }\n\n .company-market-info .market-mic {\n font-weight: 600;\n }\n\n .company-market-info .market-mic::before {\n content: '•';\n margin-right: 8px;\n }\n\n /* Price metadata (source and last update) */\n .price-metadata {\n margin-top: 8px;\n display: flex;\n flex-direction: column;\n gap: 4px;\n }\n\n \n\n /* STANDARDIZED GRID LAYOUT */\n .data-grid {\n display: grid;\n grid-template-columns: repeat(2, 1fr);\n gap: 24px;\n margin-top: 24px;\n }\n\n .data-section {\n display: flex;\n flex-direction: column;\n gap: 12px;\n }\n\n .night-session-widget .section-title {\n font-size: var(--mdas-small-text-size);\n font-weight: 600;\n color: #6b7280;\n text-transform: uppercase;\n letter-spacing: 0.5px;\n border-bottom: 1px solid #e5e7eb;\n padding-bottom: 8px;\n }\n\n .night-session-widget .data-row {\n display: flex;\n justify-content: space-between;\n align-items: center;\n min-height: 20px;\n }\n\n\n\n .night-session-widget .data-value {\n font-size: var(--mdas-data-value-size);\n font-weight: 600;\n color: #111827;\n text-align: right;\n }\n\n /* SPECIAL FORMATTING FOR DIFFERENT DATA TYPES */\n .night-session-widget .bid-ask-value {\n font-size: var(--mdas-bid-ask-size);\n font-weight: 700;\n }\n\n .night-session-widget .size-info {\n font-size: var(--mdas-small-text-size);\n color: #6b7280;\n margin-left: 4px;\n }\n\n /* Footer */\n .night-session-widget .widget-footer {\n display: flex;\n justify-content: space-between;\n align-items: center;\n margin-top: 24px;\n padding-top: 16px;\n border-top: 1px solid #e5e7eb;\n font-size: var(--mdas-small-text-size);\n color: #9ca3af;\n grid-column: 1 / -1;\n }\n\n /* Loading Overlay */\n .widget-loading-overlay {\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background: rgba(255, 255, 255, 0.95);\n backdrop-filter: blur(2px);\n display: flex;\n align-items: center;\n justify-content: center;\n z-index: 10;\n border-radius: 12px;\n }\n\n .widget-loading-overlay.hidden {\n display: none;\n }\n\n .loading-content {\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: 12px;\n }\n\n .loading-spinner {\n width: 32px;\n height: 32px;\n border: 3px solid #f3f4f6;\n border-top-color: #3b82f6;\n border-radius: 50%;\n animation: spin 1s linear infinite;\n }\n\n .night-session-widget .loading-text {\n color: #6b7280;\n font-size: var(--mdas-data-value-size);\n font-weight: 500;\n }\n\n @keyframes spin {\n to { transform: rotate(360deg); }\n }\n\n /* Widget Error Styles */\n .night-session-widget .widget-error {\n background: #fef2f2;\n color: #9ca3af;\n padding: 12px;\n border-radius: 8px;\n border: 1px solid #fecaca;\n margin-top: 16px;\n font-size: var(--mdas-data-value-size);\n font-weight: 500;\n }\n\n /* No Data State */\n .night-session-widget .no-data-state {\n padding: 24px;\n text-align: center;\n color: #6b7280;\n grid-column: 1 / -1;\n }\n\n .night-session-widget .no-data-content {\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: 12px;\n }\n\n .night-session-widget .no-data-icon {\n font-size: 3.43em;\n opacity: 0.5;\n }\n\n .night-session-widget .no-data-title {\n font-size: 1.29em;\n font-weight: 600;\n color: #374151;\n }\n\n .night-session-widget .no-data-message {\n font-size: var(--mdas-data-value-size);\n max-width: 300px;\n line-height: 1.5;\n }\n\n .night-session-widget .no-data-suggestion {\n font-size: var(--mdas-small-text-size);\n color: #9ca3af;\n max-width: 350px;\n line-height: 1.4;\n }\n\n /* Dimmed state for no data */\n .widget-header.dimmed,\n .price-section.dimmed {\n opacity: 0.6;\n }\n\n /* Responsive Design */\n @media (max-width: 768px) {\n :root {\n --mdas-base-font-size: 13px; /* Slightly smaller on tablets */\n }\n\n .widget-styled {\n padding: 16px;\n }\n\n .widget-header {\n grid-template-columns: 1fr;\n gap: 12px;\n text-align: center;\n }\n\n .symbol-section {\n align-items: center;\n }\n\n .price-section {\n text-align: center;\n }\n\n .data-grid {\n grid-template-columns: 1fr;\n gap: 16px;\n }\n\n .widget-footer {\n flex-direction: column;\n gap: 8px;\n text-align: center;\n }\n }\n\n @media (max-width: 480px) {\n :root {\n --mdas-base-font-size: 12px; /* Smaller on mobile */\n }\n }\n\n \n`,r=`\n ${o}\n\n /* Reset and base styles for widget */\n\n .market-data-widget {\n color: #333;\n margin: 0 auto;\n position: relative;\n overflow: hidden;\n }\n\n /* MARKET DATA HEADER STYLES */\n\n\n .market-data-widget .company-info {\n display: flex;\n align-items: center;\n gap: 8px;\n font-size: var(--mdas-section-title-size);\n color: #6b7280;\n }\n\n .company-name {\n position: relative;\n cursor: help;\n transition: all 0.2s ease;\n }\n\n .company-name:hover {\n border-bottom-color: #3b82f6;\n color: #3b82f6;\n }\n\n\n /* STANDARDIZED GRID LAYOUT */\n \n .data-section {\n display: flex;\n flex-direction: column;\n gap: 12px;\n min-width: 0;\n overflow: hidden;\n }\n\n .market-data-widget .section-title {\n font-size: var(--mdas-small-text-size);\n font-weight: 600;\n color: #6b7280;\n text-transform: uppercase;\n letter-spacing: 0.5px;\n padding-bottom: 8px;\n }\n\n\n\n /* SPECIAL FORMATTING FOR DIFFERENT DATA TYPES */\n .market-data-widget .bid-ask-value {\n font-size: var(--mdas-bid-ask-size);\n font-weight: 700;\n }\n\n .market-data-widget .size-info {\n font-size: var(--mdas-small-text-size);\n color: #6b7280;\n margin-left: 4px;\n }\n\n .market-data-widget .range-value {\n font-size: var(--mdas-data-label-size);\n }\n\n \n\n /* Tooltip Styles */\n .company-name::after {\n content: attr(data-tooltip);\n position: absolute;\n bottom: 100%;\n left: 50%;\n transform: translateX(-50%);\n background: #1f2937;\n color: white;\n padding: 8px 12px;\n border-radius: 6px;\n font-size: var(--mdas-small-text-size);\n font-weight: normal;\n white-space: nowrap;\n max-width: 300px;\n white-space: normal;\n line-height: 1.4;\n z-index: 1000;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\n opacity: 0;\n visibility: hidden;\n transition: all 0.2s ease;\n pointer-events: none;\n margin-bottom: 5px;\n }\n\n .company-name:hover::after {\n opacity: 1;\n visibility: visible;\n }\n\n .company-name::before {\n content: '';\n position: absolute;\n bottom: 100%;\n left: 50%;\n transform: translateX(-50%);\n border: 5px solid transparent;\n border-top-color: #1f2937;\n opacity: 0;\n visibility: hidden;\n transition: all 0.2s ease;\n pointer-events: none;\n }\n\n .company-name:hover::before {\n opacity: 1;\n visibility: visible;\n }\n\n /* Loading Overlay */\n .widget-loading-overlay {\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background: rgba(255, 255, 255, 0.95);\n backdrop-filter: blur(2px);\n display: flex;\n align-items: center;\n justify-content: center;\n z-index: 10;\n border-radius: 12px;\n }\n\n .widget-loading-overlay.hidden {\n display: none;\n }\n\n .loading-content {\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: 12px;\n }\n\n .loading-spinner {\n width: 32px;\n height: 32px;\n border: 3px solid #f3f4f6;\n border-top-color: #3b82f6;\n border-radius: 50%;\n animation: spin 1s linear infinite;\n }\n\n .market-data-widget .loading-text {\n color: #6b7280;\n font-size: var(--mdas-data-value-size);\n font-weight: 500;\n }\n\n @keyframes spin {\n to { transform: rotate(360deg); }\n }\n\n /* Widget Error Styles */\n .market-data-widget .widget-error {\n background: #fef2f2;\n color: #dc2626;\n padding: 12px;\n border-radius: 8px;\n border: 1px solid #fecaca;\n margin-top: 16px;\n font-size: var(--mdas-data-value-size);\n font-weight: 500;\n }\n\n /* Responsive Design */\n\n\n @media (max-width: 600px) {\n .widget-header {\n grid-template-columns: 1fr;\n gap: 12px;\n text-align: center;\n }\n\n .symbol-section {\n align-items: center;\n }\n\n .price-section {\n text-align: center;\n }\n\n .data-grid {\n grid-template-columns: 1fr;\n gap: 16px;\n }\n\n .widget-footer {\n flex-direction: column;\n gap: 8px;\n text-align: center;\n }\n }\n\n @media (max-width: 480px) {\n .company-name::after {\n left: 0;\n transform: none;\n max-width: 250px;\n }\n\n .company-name::before {\n left: 20px;\n transform: none;\n }\n }\n`,c=`\n ${o}\n\n .options-widget {\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;\n color: #333;\n max-width: 1400px;\n width: 100%;\n margin: 0 auto;\n position: relative;\n overflow: hidden;\n }\n\n .widget-content {\n position: relative;\n z-index: 1;\n }\n\n \n .options-widget .symbol-info .symbol {\n font-size: var(--mdas-symbol-size);\n font-weight: 700;\n margin: 0 0 8px 0;\n color: #1f2937;\n }\n\n .options-widget .option-info {\n display: flex;\n align-items: center;\n gap: 8px;\n color: #6b7280;\n font-size: var(--mdas-price-change-size);\n }\n\n .options-widget .underlying-symbol {\n font-weight: 600;\n color: #6b7280;\n }\n\n .options-widget .option-details-section {\n display: flex;\n gap: 24px;\n margin-bottom: 24px;\n padding-bottom: 20px;\n border-bottom: 1px solid #e5e7eb;\n }\n\n .options-widget .option-details-section .detail-item {\n display: flex;\n flex-direction: column;\n gap: 4px;\n }\n\n .options-widget .option-details-section .detail-item label {\n font-size: var(--mdas-small-text-size);\n color: #6b7280;\n font-weight: 500;\n text-transform: uppercase;\n letter-spacing: 0.3px;\n }\n\n .options-widget .option-details-section .detail-item span {\n font-size: var(--mdas-price-change-size);\n font-weight: 600;\n color: #1f2937;\n }\n\n\n .options-widget .widget-footer {\n display: flex;\n justify-content: space-between;\n align-items: center;\n padding-top: 16px;\n border-top: 1px solid #e5e7eb;\n font-size: var(--mdas-small-text-size);\n color: #9ca3af;\n }\n\n /* Dimmed state for no-data */\n .widget-header.dimmed {\n opacity: 0.6;\n }\n\n .widget-header.dimmed .symbol {\n color: #9ca3af;\n }\n\n /* Responsive design */\n @media (max-width: 768px) {\n .widget-header {\n flex-direction: column;\n gap: 16px;\n text-align: left;\n }\n\n .price-info {\n text-align: left;\n }\n\n .data-grid {\n grid-template-columns: 1fr;\n gap: 20px;\n }\n\n .option-details-section {\n flex-wrap: wrap;\n gap: 16px;\n }\n\n .current-price {\n font-size: 32px;\n }\n\n .symbol {\n font-size: 20px !important;\n }\n }\n\n @media (max-width: 480px) {\n .widget-styled {\n padding: 12px;\n }\n\n .widget-header {\n margin-bottom: 16px;\n padding-bottom: 16px;\n }\n\n .current-price {\n font-size: 28px;\n }\n\n .data-row {\n grid-template-columns: 1fr;\n gap: 12px;\n }\n\n .option-details-section {\n flex-direction: column;\n gap: 12px;\n }\n\n .no-data-state {\n min-height: 120px;\n padding: 20px 12px;\n }\n\n .no-data-title {\n font-size: 14px;\n }\n\n .no-data-description {\n font-size: 12px;\n }\n\n .no-data-guidance {\n font-size: 11px;\n }\n }\n`;function l(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"";const i=document.createElement(t);return n&&(i.className=n),e&&(i.textContent=e),i}function d(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"--";if(null==t||""===t)return n;const i=parseFloat(t);return isNaN(i)?n:i.toFixed(e)}function h(t){if(!t)return"";return String(t).replace(/[^A-Za-z0-9.\-_+ ]/g,"").substring(0,50)}function u(t){if(t)for(;t.firstChild;)t.removeChild(t.firstChild)}function g(t){if(!t||"string"!=typeof t)return{valid:!1,error:"Symbol is required",sanitized:""};const e=t.trim().toUpperCase();return 0===e.length?{valid:!1,error:"Symbol cannot be empty",sanitized:""}:e.length>10?{valid:!1,error:"Symbol too long (max 10 characters)",sanitized:""}:{valid:!0,sanitized:e}}function p(t){if(!t||"string"!=typeof t)return{valid:!1,error:"Option symbol is required",sanitized:""};const e=t.trim().toUpperCase();if(e.length<15||e.length>21)return{valid:!1,error:"Invalid option symbol length",sanitized:e};const n=e.match(/^([A-Z]{1,6})(\d{2})(0[1-9]|1[0-2])([0-2][0-9]|3[01])([CP])(\d{8})$/);if(!n)return{valid:!1,error:"Invalid option symbol format. Expected: SYMBOL+YYMMDD+C/P+STRIKE",sanitized:e};const[,i,s,o,a,r,c]=n,l=2e3+parseInt(s,10),d=parseInt(o,10),h=parseInt(a,10),u=new Date(l,d-1,h);if(u.getMonth()+1!==d||u.getDate()!==h)return{valid:!1,error:"Invalid expiration date in option symbol",sanitized:e};const g=new Date;g.setHours(0,0,0,0),u<g&&console.warn("Option symbol has expired");return{valid:!0,sanitized:e,parsed:{underlying:i,expiry:u,type:"C"===r?"call":"put",strike:parseInt(c,10)/1e3}}}function m(t){if(!t)return"ET";const[e,n,i]=t.split("-").map(Number),s=new Date(e,n-1,i),o=function(t,e){const n=new Date(t,e,1),i=1+(7-n.getDay())%7;return new Date(t,e,i+7)}(e,2),a=function(t,e){const n=new Date(t,e,1),i=1+(7-n.getDay())%7;return new Date(t,e,i)}(e,10);return s>=o&&s<a?"EDT":"EST"}function f(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{includeSeconds:n=!0,includeTimezone:i=!0,format:s="short"}=e;let o;if(t||(t=Date.now()),o=t instanceof Date?t:new Date(t),isNaN(o.getTime()))return"Invalid Date";const a=o.getUTCFullYear(),r=o.getUTCMonth(),c=o.getUTCDate(),l=o.getUTCHours(),d=o.getUTCMinutes(),h=o.getUTCSeconds(),u=function(t){const e=t.getUTCFullYear(),n=t.getUTCMonth(),i=t.getUTCDate(),s=new Date(Date.UTC(e,n,i)),o=function(t,e){const n=new Date(Date.UTC(t,e,1)),i=1+(7-n.getUTCDay())%7;return new Date(Date.UTC(t,e,i+7))}(e,2),a=function(t,e){const n=new Date(Date.UTC(t,e,1)),i=1+(7-n.getUTCDay())%7;return new Date(Date.UTC(t,e,i))}(e,10);return s>=o&&s<a}(o),g=u?-4:-5,p=new Date(Date.UTC(a,r,c,l+g,d,h)),m=p.getUTCFullYear(),f=p.getUTCMonth()+1,b=p.getUTCDate(),y=p.getUTCHours(),x=p.getUTCMinutes(),v=p.getUTCSeconds(),w=y%12||12,S=y>=12?"PM":"AM",k=x.toString().padStart(2,"0"),M=v.toString().padStart(2,"0"),_=n?`${w}:${k}:${M} ${S}`:`${w}:${k} ${S}`,C=i?u?" EDT":" EST":"";if("long"===s){return`${["January","February","March","April","May","June","July","August","September","Oct","November","December"][f-1]} ${b}, ${m}, ${_}${C}`}return`${f}/${b}/${m}, ${_}${C}`}class b extends n{constructor(t,e,n){if(super(t,e,n),!e.symbol)throw new Error("Symbol is required for MarketDataWidget");if(!e.wsManager)throw new Error("WebSocketManager is required for MarketDataWidget");this.type="marketdata";const i=g(e.symbol);if(!i.valid)throw new Error(`Invalid symbol: ${i.error}`);this.symbol=i.sanitized,this.wsManager=e.wsManager,this.debug=e.debug||!1,this.styled=void 0===e.styled||e.styled,this.data=null,this.isDestroyed=!1,this.unsubscribe=null,this.loadingTimeout=null,this.createWidgetStructure(),this.initializeSymbolEditor(),this.initialize()}createWidgetStructure(){if(this.container.innerHTML='\n <div class="market-data-widget widget">\n <div class="widget-content">\n \x3c!-- Header Section --\x3e\n <div class="widget-header">\n <div class="symbol-section">\n <h1 class="symbol editable-symbol" \n title="Double-click to edit symbol" \n data-original-symbol="">\n </h1>\n <div class="company-info">\n <span class="company-name" \n title="" \n data-tooltip="">\n </span>\n <span class="data-type">STOCK</span>\n </div>\n </div>\n <div class="price-section">\n <div class="current-price"></div>\n <div class="price-change">\n <span class="change-value"></span>\n <span class="change-percent"></span>\n </div>\n </div>\n </div>\n\n \x3c!-- Data Grid Section --\x3e\n <div class="data-grid">\n <div class="data-section">\n <div class="section-title">Quote</div>\n <div class="data-row">\n <span class="data-label">Bid</span>\n <span class="data-value bid-ask-value bid-data"></span>\n </div>\n <div class="data-row">\n <span class="data-label">Ask</span>\n <span class="data-value bid-ask-value ask-data"></span>\n </div>\n </div>\n\n <div class="data-section">\n <div class="section-title">Trading Activity</div>\n <div class="data-row">\n <span class="data-label">Volume</span>\n <span class="data-value volume"></span>\n </div>\n <div class="data-row">\n <span class="data-label">Average Volume</span>\n <span class="data-value avg-volume"></span>\n </div>\n </div>\n\n <div class="data-section">\n <div class="section-title">Performance</div>\n <div class="data-row">\n <span class="data-label">Previous Close</span>\n <span class="data-value prev-close"></span>\n </div>\n <div class="data-row">\n <span class="data-label">Open</span>\n <span class="data-value open-price"></span>\n </div>\n <div class="data-row">\n <span class="data-label">Day Range</span>\n <span class="data-value range-value day-range"></span>\n </div>\n <div class="data-row">\n <span class="data-label">52-Week Range</span>\n <span class="data-value range-value week-range"></span>\n </div>\n </div>\n\n <div class="data-section">\n <div class="section-title">Key Metrics</div>\n <div class="data-row">\n <span class="data-label">Market Cap</span>\n <span class="data-value market-cap"></span>\n </div>\n <div class="data-row">\n <span class="data-label">P/E Ratio</span>\n <span class="data-value pe-ratio"></span>\n </div>\n <div class="data-row">\n <span class="data-label">Dividend Yield</span>\n <span class="data-value dividend-yield"></span>\n </div>\n <div class="data-row">\n <span class="data-label">Beta</span>\n <span class="data-value beta"></span>\n </div>\n </div>\n </div>\n\n \x3c!-- Footer --\x3e\n <div class="widget-footer">\n <span class="last-update"></span>\n <span class="data-source"></span>\n </div>\n </div>\n \n \x3c!-- Loading Overlay --\x3e\n <div class="widget-loading-overlay">\n <div class="loading-content">\n <div class="loading-spinner"></div>\n <span class="loading-text">Loading market data...</span>\n </div>\n </div>\n </div>\n',this.styled){const t=this.container.querySelector(".market-data-widget");t&&t.classList.add("widget-styled")}this.addStyles()}addStyles(){if(!document.querySelector("#market-data-styles")){const t=document.createElement("style");t.id="market-data-styles",t.textContent=r,document.head.appendChild(t)}}initializeSymbolEditor(){this.symbolEditor=new s(this,{maxLength:10,placeholder:"Enter symbol...",onSymbolChange:this.handleSymbolChange.bind(this),debug:this.debug,autoUppercase:!0,symbolType:"quotel1"});const t=this.container.querySelector(".symbol");t&&(t.textContent=this.symbol,t.dataset.originalSymbol=this.symbol)}async handleSymbolChange(t){this.debug&&console.log("[MarketDataWidget] Symbol change requested:",t);const e=g(t);if(!e.valid)return this.debug&&console.log("[MarketDataWidget] Invalid symbol:",e.error),{success:!1,error:e.error};const n=e.sanitized;if(n===this.symbol)return this.debug&&console.log("[MarketDataWidget] Same symbol, no change needed"),{success:!0};try{const t=this.symbol;return this.showLoading(),this.loadingTimeout&&this.clearTimeout(this.loadingTimeout),this.loadingTimeout=this.setTimeout((()=>{this.debug&&console.log("[MarketDataWidget] Loading timeout for symbol:",n),this.hideLoading(),this.showError(`No data received for ${n}. Please try again.`)}),1e4),this.unsubscribe&&(this.debug&&console.log(`[MarketDataWidget] Unsubscribing from ${t}`),this.wsManager.sendUnsubscribe("queryl1",t),this.unsubscribe(),this.unsubscribe=null),this.symbol=n,this.debug&&console.log(`[MarketDataWidget] Subscribing to ${n}`),this.subscribeToData(),this.debug&&console.log(`[MarketDataWidget] Successfully changed symbol from ${t} to ${n}`),{success:!0}}catch(t){return console.error("[MarketDataWidget] Error changing symbol:",t),this.hideLoading(),this.showError(`Failed to load data for ${n}`),{success:!1,error:`Failed to load ${n}`}}}async initialize(){this.showLoading(),await this.validateInitialSymbol(),this.subscribeToData()}async validateInitialSymbol(){try{const t=this.wsManager.getApiService();if(!t)return void(this.debug&&console.log("[MarketDataWidget] API service not available for initial validation"));const e=await t.quotel1(this.symbol);if(e&&e.data&&e.data[0]){const t=e.data[0];this.initialValidationData=t,this.debug&&console.log("[MarketDataWidget] Initial symbol validated:",{symbol:this.symbol,companyName:t.comp_name,exchangeName:t.market_name})}}catch(t){this.debug&&console.warn("[MarketDataWidget] Initial symbol validation failed:",t)}}subscribeToData(){this.unsubscribe=this.wsManager.subscribe(this.widgetId,["queryl1"],this.handleMessage.bind(this),this.symbol)}handleData(t){if(this.loadingTimeout&&(clearTimeout(this.loadingTimeout),this.loadingTimeout=null),"error"===t.type&&t.noData)return this.debug&&console.log("[MarketDataWidget] Received no data message:",t.message),void(this.data?(this.hideLoading(),this.debug&&console.log("[MarketDataWidget] No new data, keeping cached data visible")):this.showNoDataState({Symbol:this.symbol,NotFound:!0,message:t.message}));if("error"!==t.type){if("object"==typeof t&&t.Message){const e=t.Message.toLowerCase();if(e.includes("no data")||e.includes("not found"))return this.debug&&console.log("[MarketDataWidget] Received no data message:",t.Message),void(this.data?(this.hideLoading(),this.debug&&console.log("[MarketDataWidget] No new data, keeping cached data visible")):this.showNoDataState({Symbol:this.symbol,NotFound:!0,message:t.Message}))}if(t.Data&&t.Data.length>0){const e=t.Data.find((t=>t.Symbol===this.symbol));if(e){const t=new i(e);this.data=t,this.updateWidget(t)}else this.debug&&console.log("[MarketDataWidget] No data for symbol in response, keeping cached data"),this.hideLoading()}t._cached&&this.showConnectionQuality()}else{const e=t.message||"Server error";this.data?(this.hideLoading(),this.debug&&console.log("[MarketDataWidget] Error received but keeping cached data:",e)):this.showError(e)}}showNoDataState(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!this.isDestroyed)try{this.hideLoading(),this.clearError();const e=t.Symbol||this.symbol,n=this.container.querySelector(".symbol");n&&(n.textContent=e);const i=this.container.querySelector(".company-name");i&&(i.textContent=`${e} Inc`);const s=this.container.querySelector(".current-price");s&&(s.textContent="$0.00");const o=this.container.querySelector(".price-change");if(o){const t=o.querySelector(".change-value"),e=o.querySelector(".change-percent");t&&(t.textContent="+0.00"),e&&(e.textContent=" (0.00%)"),o.classList.remove("positive","negative"),o.classList.add("neutral")}const a=this.container.querySelector(".widget-header");a&&a.classList.add("dimmed"),this.showNoDataMessage(e,t);const r=this.container.querySelector(".last-update");if(r){const t=f();r.textContent=`Checked: ${t}`}const c=this.container.querySelector(".data-source");c&&(c.textContent="Source: No data available")}catch(t){console.error("Error showing no data state:",t),this.showError("Error displaying no data state")}}showNoDataMessage(t){const e=this.container.querySelector(".data-grid");e&&(e.style.display="none");const n=this.container.querySelector(".no-data-state");n&&n.remove();const i=l("div","","no-data-state"),s=l("div","","no-data-content"),o=document.createElement("div");o.className="no-data-icon",o.innerHTML='<svg width="32" height="32" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <circle cx="12" cy="12" r="10" stroke="#9ca3af" stroke-width="2"/>\n <path d="M12 8v4" stroke="#9ca3af" stroke-width="2" stroke-linecap="round"/>\n <circle cx="12" cy="16" r="1" fill="#9ca3af"/>\n </svg>',s.appendChild(o);const a=l("h3","No Market Data","no-data-title");s.appendChild(a);const r=l("p","","no-data-description");r.appendChild(document.createTextNode("Market data for "));const c=l("strong",h(t));r.appendChild(c),r.appendChild(document.createTextNode(" was not found")),s.appendChild(r);const d=l("p","Please check the symbol spelling or try a different symbol","no-data-guidance");s.appendChild(d),i.appendChild(s);const u=this.container.querySelector(".widget-footer");u&&u.parentNode?u.parentNode.insertBefore(i,u):this.container.appendChild(i)}updateWidget(t){if(!this.isDestroyed)try{this.loadingTimeout&&(clearTimeout(this.loadingTimeout),this.loadingTimeout=null),this.clearError(),this.hideLoading();const e=this.container.querySelector(".widget-header");e&&e.classList.remove("dimmed");const n=this.container.querySelector(".data-grid");n&&(n.style.display="");const i=this.container.querySelector(".no-data-state");i&&i.remove();const s=this.container.querySelector(".symbol");s&&(s.textContent=t.symbol,s.dataset.originalSymbol=t.symbol);const o=this.container.querySelector(".company-name");if(o){const e=t.companyName||`${t.symbol} Inc`,n=t.companyDescription||`${t.symbol} designs, manufactures, and markets consumer electronics and software.`;o.textContent=e,o.setAttribute("title",n),o.setAttribute("data-tooltip",n)}const a=this.container.querySelector(".current-price");a&&(a.textContent=t.formatPrice());const r=t.getPriceChange(),c=this.container.querySelector(".price-change");if(c){const e=c.querySelector(".change-value"),n=c.querySelector(".change-percent");e&&(e.textContent=t.formatPriceChange()),n&&(n.textContent=` (${t.formatPriceChangePercent()})`),c.classList.remove("positive","negative","neutral"),r>0?c.classList.add("positive"):r<0?c.classList.add("negative"):c.classList.add("neutral")}const h=this.container.querySelector(".bid-data");if(h){u(h);const e=d(t.bidPrice,2,"0.00"),n=t.bidSize||0;h.appendChild(document.createTextNode(`$${e}`));const i=l("span",`× ${n}`,"size-info");h.appendChild(i)}const g=this.container.querySelector(".ask-data");if(g){u(g);const e=d(t.askPrice,2,"0.00"),n=t.askSize||0;g.appendChild(document.createTextNode(`$${e}`));const i=l("span",`× ${n}`,"size-info");g.appendChild(i)}const p=this.container.querySelector(".volume");p&&(p.textContent=t.formatVolume());const m=this.container.querySelector(".avg-volume");m&&(m.textContent=t.formatAverageVolume());const b=this.container.querySelector(".prev-close");b&&(b.textContent=`$${t.previousClose?.toFixed(2)||"0.00"}`);const y=this.container.querySelector(".open-price");y&&(y.textContent=`$${t.openPrice?.toFixed(2)||"0.00"}`);const x=this.container.querySelector(".day-range");x&&(x.textContent=t.formatDayRange());const v=this.container.querySelector(".week-range");v&&(v.textContent=t.format52WeekRange());const w=this.container.querySelector(".market-cap");w&&(w.textContent=t.formatMarketCap());const S=this.container.querySelector(".pe-ratio");S&&(S.textContent=t.peRatio?.toFixed(2)||"N/A");const k=this.container.querySelector(".dividend-yield");k&&(k.textContent=t.dividendYield?`${t.dividendYield.toFixed(2)}%`:"N/A");const M=this.container.querySelector(".beta");M&&(M.textContent=t.beta?.toFixed(2)||"N/A");const _=f(t.quoteTime),C=this.container.querySelector(".last-update");C&&(C.textContent=`Last update: ${_}`);const T=this.container.querySelector(".data-source");T&&(T.textContent=`Source: ${t.getDataSource()}`)}catch(t){console.error("Error updating widget:",t),this.showError("Error updating data")}}showLoading(){const t=this.container.querySelector(".widget-loading-overlay");t&&t.classList.remove("hidden")}hideLoading(){const t=this.container.querySelector(".widget-loading-overlay");t&&t.classList.add("hidden")}showError(t){this.hideLoading(),this.clearError();const e=document.createElement("div");e.className="widget-error",e.textContent=`Error: ${t}`,e.style.cssText="\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n padding: 15px 20px;\n background: #fee;\n border: 1px solid #f5c6cb;\n border-radius: 6px;\n color: #721c24;\n text-align: center;\n font-size: 14px;\n z-index: 100;\n ",this.container.appendChild(e)}clearError(){const t=this.container.querySelector(".widget-error"),e=this.container.querySelector(".widget-error-container");t&&t.remove(),e&&e.remove()}destroy(){this.isDestroyed=!0,this.loadingTimeout&&(this.clearTimeout(this.loadingTimeout),this.loadingTimeout=null),this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=null),this.symbolEditor&&(this.symbolEditor.destroy(),this.symbolEditor=null),super.destroy()}}class y{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.symbol=t.Symbol||"",this.marketName=t.MarketName||("bruce"===t.Source?.toLowerCase()?"Bruce":"Blue Ocean"),this.marketDesc=null!==t.MarketDesc?t.MarketDesc||"":null,this.countryCode=null!==t.CountryCode?t.CountryCode||"":null,this.volume=null!==t.Volume?t.Volume||0:null,this.askPrice=null!==t.AskPx?t.AskPx||0:null,this.askSize=null!==t.AskSz?t.AskSz||0:null,this.bidPrice=null!==t.BidPx?t.BidPx||0:null,this.bidSize=null!==t.BidSz?t.BidSz||0:null,this.lastPrice=null!==t.LastPx?t.LastPx||0:null,this.quoteTime=null!==t.QuoteTime?t.QuoteTime:null,this.activityTimestamp=null!==t.ActivityTimestamp?t.ActivityTimestamp||"":null,this.tradeSize=null!==t.TradeSz?t.TradeSz||0:null,this.bidExchange=null!==t.BidExch?t.BidExch||"":null,this.askExchange=null!==t.AskExch?t.AskExch||"":null,this.notFound=t.NotFound||!1,this.source=t.Source||"",this.accuAmount=null!==t.AccuAmmount?t.AccuAmmount||0:null,this.change=null!==t.Change?t.Change||0:null,this.changePercent=null!==t.ChangePercent?t.ChangePercent||0:null,this.closingPrice=null!==t.ClosingPx?t.ClosingPx:null!==t.PreviousClose?t.PreviousClose:null,this.highPrice=null!==t.HighPx?t.HighPx||0:null,this.lowPrice=null!==t.LowPx?t.LowPx||0:null,this.openPrice=null!==t.OpenPx?t.OpenPx||0:null,this.tradePrice=null!==t.TradePx?t.TradePx||0:null,this.tradeRegionName=null!==t.TradeRegionName?t.TradeRegionName||"":null,this.companyName=t.comp_name||t.CompanyName||"",this.exchangeName=t.market_name||t.Exchange||"",this.mic=t.mic||""}formatPrice(){return`$${this.lastPrice.toFixed(2)}`}formatBidAsk(){return`$${this.bidPrice.toFixed(2)} × ${this.bidSize} / $${this.askPrice.toFixed(2)} × ${this.askSize}`}formatVolume(){return this.volume.toLocaleString()}formatPriceChange(){if(null===this.change||void 0===this.change)return"--";return`${this.change>0?"+":""}${this.change.toFixed(2)}`}formatPriceChangePercent(){if(null===this.changePercent||void 0===this.changePercent)return"--";return`${this.changePercent>0?"+":""}${this.getPriceChangePercent().toFixed(2)}%`}getDataSource(){return"blueocean-d"===this.source.toLowerCase()||"bruce-d"===this.source.toLowerCase()?"bruce-d"===this.source.toLowerCase()?"Bruce 20 mins delayed":"BlueOcean 20 mins delayed":this.source.toLowerCase().includes("bruce")||this.source.toLowerCase().includes("blueocean")?"bruce"===this.source.toLowerCase()?"Bruce Real-time":"BlueOcean Real-time":null!==this.source&&""!==this.source?this.source:"MDAS"}getPriceChangePercent(){return null===this.changePercent||void 0===this.changePercent?0:Math.abs(this.changePercent)>1?this.changePercent:100*this.changePercent}}class x extends n{constructor(t,e,n){if(super(t,e,n),!e.symbol)throw new Error("Symbol is required for NightSessionWidget");if(!e.wsManager)throw new Error("WebSocketManager is required for NightSessionWidget");if(!e.source||"blueocean"!==e.source.toLowerCase()&&"bruce"!==e.source.toLowerCase())throw new Error('Source should be either "blueocean" or "bruce"');this.type="nightsession "+e.source;const i=g(e.symbol);if(!i.valid)throw new Error(`Invalid symbol: ${i.error}`);this.symbol=i.sanitized,this.source=e.source||"blueocean",this.wsManager=e.wsManager,this.debug=e.debug||!1,this.styled=void 0===e.styled||e.styled,this.data=null,this.isDestroyed=!1,this.unsubscribe=null,this.symbolEditor=null,this.loadingTimeout=null,this.companyName="",this.exchangeName="",this.mic="",this.createWidgetStructure(),this.initialize()}createWidgetStructure(){if(this.container.innerHTML='\n <div class="night-session-widget widget">\n <div class="widget-content">\n \x3c!-- Header Section --\x3e\n <div class="widget-header">\n <div class="symbol-section">\n <div class="company-market-info">\n <span class="night-company-name"></span>\n <span class="market-name"></span>\n <span class="market-mic"></span>\n </div>\n <h1 class="symbol editable-symbol"\n title="Double-click to edit symbol"\n data-original-symbol="">\n </h1>\n \n </div>\n <div class="price-section">\n <div class="current-price"></div>\n <div class="price-change">\n <span class="change-value"></span>\n <span class="change-percent"></span>\n </div>\n <div class="price-metadata">\n <div class="last-update"></div>\n <div class="data-source"></div>\n </div>\n </div>\n </div>\n\n \x3c!-- Data Grid Section --\x3e\n <div class="data-grid">\n <div class="data-section">\n <div class="section-title">Quote</div>\n <div class="data-row">\n <span class="data-label">Bid</span>\n <span class="data-value bid-ask-value">\n <span class="bid-price"></span>\n <span class="size-info bid-size"></span>\n </span>\n </div>\n <div class="data-row">\n <span class="data-label">Ask</span>\n <span class="data-value bid-ask-value">\n <span class="ask-price"></span>\n <span class="size-info ask-size"></span>\n </span>\n </div>\n </div>\n\n <div class="data-section">\n <div class="section-title">Trading Activity</div>\n <div class="data-row">\n <span class="data-label">Volume</span>\n <span class="data-value volume"></span>\n </div>\n <div class="data-row">\n <span class="data-label">Accumulated Amount</span>\n <span class="data-value accu-amount"></span>\n </div>\n </div>\n\n <div class="data-section">\n <div class="section-title">Performance</div>\n <div class="data-row">\n <span class="data-label">Previous Close</span>\n <span class="data-value previous-close"></span>\n </div>\n <div class="data-row at-close-row">\n <span class="data-label">At close</span>\n <span class="data-value at-close-time"></span>\n </div>\n <div class="data-row">\n <span class="data-label">Open</span>\n <span class="data-value open-price"></span>\n </div>\n <div class="data-row">\n <span class="data-label">Day Range</span>\n <span class="data-value range-value day-range"></span>\n </div>\n </div>\n </div>\n </div>\n\n \x3c!-- Loading Overlay --\x3e\n <div class="widget-loading-overlay">\n <div class="loading-content">\n <div class="loading-spinner"></div>\n <span class="loading-text">Loading night session data...</span>\n </div>\n </div>\n </div>\n',this.styled){const t=this.container.querySelector(".night-session-widget");t&&t.classList.add("widget-styled")}this.addStyles(),this.setupSymbolEditor()}addStyles(){if(!document.querySelector("#night-session-styles")){const t=document.createElement("style");t.id="night-session-styles",t.textContent=a,document.head.appendChild(t)}}setupSymbolEditor(){this.symbolEditor=new s(this,{maxLength:10,placeholder:"Enter symbol...",onSymbolChange:this.handleSymbolChange.bind(this),debug:this.debug,autoUppercase:!0,cancelOnBlur:!1,symbolType:"nightsession"})}async handleSymbolChange(t,e){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;this.debug&&(console.log("[NightSessionWidget] Symbol change requested:",t),console.log("[NightSessionWidget] Validation data:",n));const i=g(t);if(!i.valid)return this.debug&&console.log("[NightSessionWidget] Invalid symbol:",i.error),{success:!1,error:i.error};const s=i.sanitized;if(n&&(this.companyName=n.comp_name||"",this.exchangeName=n.market_name||"",this.mic=n.mic||"",this.debug&&console.log("[NightSessionWidget] Extracted company info:",{companyName:this.companyName,exchangeName:this.exchangeName},n)),s===this.symbol)return this.debug&&console.log("[NightSessionWidget] Same symbol, no change needed"),{success:!0};try{const t=this.symbol;return this.showLoading(),this.loadingTimeout&&this.clearTimeout(this.loadingTimeout),this.loadingTimeout=this.setTimeout((()=>{this.debug&&console.log("[NightSessionWidget] Loading timeout for symbol:",s),this.hideLoading(),this.showError(`No data received for ${s}. Please try again.`)}),1e4),this.unsubscribe&&(this.debug&&console.log(`[NightSessionWidget] Unsubscribing from ${t}`),this.unsubscribe(),this.unsubscribe=null),this.symbol=s,this.debug&&console.log(`[NightSessionWidget] Subscribing to ${s}`),this.subscribeToData(),this.debug&&console.log(`[NightSessionWidget] Successfully changed symbol from ${t} to ${s}`),{success:!0}}catch(t){return console.error("[NightSessionWidget] Error changing symbol:",t),this.showError(`Failed to load data for ${s}`),{success:!1,error:`Failed to load ${s}`}}}async initialize(){this.showLoading(),await this.validateInitialSymbol(),this.loadingTimeout=setTimeout((()=>{this.debug&&console.log("[NightSessionWidget] Loading timeout - no data received for:",this.symbol),this.hideLoading(),this.showNoDataState({Symbol:this.symbol,NotFound:!0,message:"No data available for this symbol"})}),1e4),this.subscribeToData()}async validateInitialSymbol(){try{const t=this.wsManager.getApiService();if(!t)return void(this.debug&&console.log("[NightSessionWidget] API service not available for initial validation"));const e=await t.quotel1(this.symbol);if(e&&e.data&&e.data[0]){const t=e.data[0];this.companyName=t.comp_name||"",this.exchangeName=t.market_name||"",this.mic=t.mic||"",this.debug&&console.log("[NightSessionWidget] Initial symbol validated:",{symbol:this.symbol,companyName:this.companyName,exchangeName:this.exchangeName,mic:this.mic})}}catch(t){this.debug&&console.warn("[NightSessionWidget] Initial symbol validation failed:",t)}}subscribeToData(){const t="bruce"===this.source?"querybrucel1":"queryblueoceanl1";this.unsubscribe=this.wsManager.subscribe(this.widgetId,[t],this.handleMessage.bind(this),this.symbol)}handleData(t){if(this.loadingTimeout&&(clearTimeout(this.loadingTimeout),this.loadingTimeout=null),"error"===t.type&&t.noData)return this.debug&&console.log("[NightSessionWidget] Received no data message:",t.message),void(this.data?(this.hideLoading(),this.debug&&console.log("[NightSessionWidget] No new data, keeping cached data visible")):this.showNoDataState({Symbol:this.symbol,NotFound:!0,message:t.message}));if("error"!==t.type){if(Array.isArray(t)){const e=t.find((t=>t.Symbol===this.symbol));if(e){if(this.debug&&console.log("[NightSessionWidget] Found data for symbol:",e),!0===e.NotFound)this.data?(this.hideLoading(),this.debug&&console.log("[NightSessionWidget] No new data, keeping cached data visible")):this.showNoDataState(e);else{const t=new y(e);this.data=t,this.updateWidget(t)}return}this.data?(this.hideLoading(),this.debug&&console.log("[NightSessionWidget] No matching data in response, keeping cached data")):this.showNoDataState({Symbol:this.symbol,NotFound:!0})}else if("queryblueoceanl1"===t.type||"querybrucel1"===t.type)if(t[0]?.Symbol===this.symbol)if(!0!==t[0].NotFound&&t[0].MarketName&&"BLUE"===t[0].MarketName){const e=new y(t[0]);this.data=e,this.updateWidget(e)}else this.data?(this.hideLoading(),this.debug&&console.log("[NightSessionWidget] No new data, keeping cached data visible")):this.showNoDataState(t[0]);else this.debug&&console.log("[NightSessionWidget] No matching symbol in response, keeping cached data"),this.hideLoading();t._cached}else{const e=t.message||"Server error";e.toLowerCase().includes("access")||e.toLowerCase().includes("permission")||e.toLowerCase().includes("denied")?this.data?(this.hideLoading(),this.debug&&console.log("[NightSessionWidget] Access error but keeping cached data")):this.showNoDataState({Symbol:this.symbol,NotFound:!0,isAccessError:!0,message:e}):this.data?(this.hideLoading(),this.debug&&console.log("[NightSessionWidget] Error received but keeping cached data:",e)):(console.log("errorMsg",e),this.showError(e))}}updateWidget(t){if(!this.isDestroyed)try{this.hideLoading(),this.clearError();const e=this.container.querySelector(".widget-header");e&&e.classList.remove("dimmed");const n=this.container.querySelector(".price-section");n&&n.classList.remove("dimmed");const i=this.container.querySelector(".data-grid");i&&(i.style.display="grid");const s=this.container.querySelector(".no-data-state");s&&s.remove();const o=this.container.querySelector(".symbol");o&&(o.textContent=t.symbol);const a=this.container.querySelector(".night-company-name");a&&(a.textContent=this.companyName||t.companyName||"");const r=this.container.querySelector(".market-name");r&&(r.textContent=this.exchangeName||t.exchangeName||"");const c=this.container.querySelector(".market-mic");if(c){const e=this.mic||t.mic||"";c.textContent=e}const l=this.container.querySelector(".current-price");l&&(l.textContent=null!==t.lastPrice?t.formatPrice():"--");const d=t.change,h=this.container.querySelector(".price-change");if(h){const e=h.querySelector(".change-value"),n=h.querySelector(".change-percent");e&&(e.textContent=null!==d&&0!==d?d:"--"),n&&(0!==t.changePercent?n.textContent=` (${t.getPriceChangePercent().toFixed(2)}%)`:n.textContent=" (0.00%)"),h.classList.remove("positive","negative","neutral"),d>0?h.classList.add("positive"):d<0?h.classList.add("negative"):h.classList.add("neutral")}const u=this.container.querySelector(".bid-price");u&&(u.textContent=null!==t.bidPrice?`$${t.bidPrice.toFixed(2)} `:"-- ×");const g=this.container.querySelector(".bid-size");g&&(g.textContent=null!==t.bidSize?`× ${t.bidSize}`:"--");const p=this.container.querySelector(".ask-price");p&&(p.textContent=null!==t.askPrice?`$${t.askPrice.toFixed(2)} `:"-- ×");const m=this.container.querySelector(".ask-size");m&&(m.textContent=null!==t.askSize?`× ${t.askSize}`:"--");const b=this.container.querySelector(".volume");b&&(b.textContent=null!==t.volume?t.formatVolume():"--");const y=this.container.querySelector(".accu-amount");y&&(y.textContent=null!==t.accuAmount?`$${t.accuAmount.toLocaleString()}`:"--");const x=this.container.querySelector(".open-price");x&&(x.textContent=null!==t.openPrice?`$${t.openPrice.toFixed(2)}`:"--");const v=this.container.querySelector(".previous-close");v&&(v.textContent=null!==t.closingPrice?`$${t.closingPrice.toFixed(2)}`:"--");const w=this.container.querySelector(".at-close-time");if(w){const e=t.quoteTime?f(new Date(t.quoteTime)):"--";w.textContent=e}const S=this.container.querySelector(".day-range");S&&(null!==t.highPrice&&null!==t.lowPrice?S.textContent=`$${t.lowPrice.toFixed(2)} - $${t.highPrice.toFixed(2)}`:S.textContent="--");const k=this.container.querySelector(".data-source");k&&(k.textContent="Source: "+t.getDataSource());const M=(t=>{if(!t)return f();const e=new Date(t);return isNaN(e.getTime())?f():f(e)})(t.quoteTime),_=this.container.querySelector(".last-update");_&&(_.textContent=`Overnight: ${M}`)}catch(t){console.error("Error updating widget:",t),this.showError("Error updating data")}}showLoading(){const t=this.container.querySelector(".widget-loading-overlay");t&&t.classList.remove("hidden")}hideLoading(){const t=this.container.querySelector(".widget-loading-overlay");t&&t.classList.add("hidden")}showError(t){this.hideLoading(),this.clearError();const e=document.createElement("div");e.className="widget-error",e.textContent=`Error: ${t}`,e.style.cssText="\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n padding: 15px 20px;\n background: #fee;\n border: 1px solid #f5c6cb;\n border-radius: 6px;\n color: #721c24;\n text-align: center;\n font-size: 14px;\n z-index: 100;\n ",this.container.appendChild(e)}clearError(){const t=this.container.querySelector(".widget-error"),e=this.container.querySelector(".widget-error-container");t&&t.remove(),e&&e.remove()}showNoDataState(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!this.isDestroyed)try{this.hideLoading(),this.clearError();const e=t.Symbol||this.symbol,n=this.container.querySelector(".symbol");n&&(n.textContent=e);const i=this.container.querySelector(".current-price");i&&(i.textContent="$0.00");const s=this.container.querySelector(".price-change");if(s){const t=s.querySelector(".change-value");t&&(t.textContent="+0.00");const e=s.querySelector(".change-percent");e&&(e.textContent=" (0.00%)"),s.classList.remove("positive","negative")}const o=this.container.querySelector(".widget-header");o&&o.classList.add("dimmed");const a=this.container.querySelector(".price-section");a&&a.classList.add("dimmed"),this.showNoDataMessage(e,t);const r=f(),c=this.container.querySelector(".last-update");c&&(c.textContent=`Overnight: ${r}`)}catch(t){console.error("Error showing no data state:",t),this.showError("Error displaying no data state")}}showNoDataMessage(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const n=this.container.querySelector(".data-grid");n&&(n.style.display="none");const i=this.container.querySelector(".no-data-state");i&&i.remove();const s=e.isAccessError||e.message&&e.message.toLowerCase().includes("access"),o=l("div","","no-data-state"),a=l("div","","no-data-content");if(s){const n=document.createElement("div");n.className="no-data-icon error",n.innerHTML='<svg width="32" height="32" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <circle cx="12" cy="12" r="10" stroke="#ef4444" stroke-width="2"/>\n <path d="M12 8v4" stroke="#ef4444" stroke-width="2" stroke-linecap="round"/>\n <circle cx="12" cy="16" r="1" fill="#ef4444"/>\n </svg>',a.appendChild(n);const i=l("h3",String(e.message||"Access Denied"),"no-data-title error");a.appendChild(i);const s=l("p","","no-data-description");s.appendChild(document.createTextNode("You do not have permission to view night session data for "));const o=l("strong",h(t));s.appendChild(o),a.appendChild(s);const r=l("p","Contact your administrator or try a different symbol","no-data-guidance");a.appendChild(r)}else{const n=document.createElement("div");n.className="no-data-icon",n.innerHTML='<svg width="32" height="32" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <circle cx="12" cy="12" r="10" stroke="#9ca3af" stroke-width="2"/>\n <path d="M12 6v6l4 2" stroke="#9ca3af" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n </svg>',a.appendChild(n);const i=l("h3",String(e.message||"No Data Available"),"no-data-title");a.appendChild(i);const s=l("p","","no-data-description");s.appendChild(document.createTextNode("Night session data for "));const o=l("strong",h(t));s.appendChild(o),s.appendChild(document.createTextNode(" was not found")),a.appendChild(s);const r=l("p","Please check the symbol or try again later","no-data-guidance");a.appendChild(r)}o.appendChild(a);const r=this.container.querySelector(".widget-footer");r&&r.parentNode?r.parentNode.insertBefore(o,r):this.container.appendChild(o)}destroy(){this.isDestroyed=!0,this.loadingTimeout&&(this.clearTimeout(this.loadingTimeout),this.loadingTimeout=null),this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=null),this.symbolEditor&&(this.symbolEditor.destroy(),this.symbolEditor=null),super.destroy()}updateSymbol(t){this.handleSymbolChange(t)}}class v{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.rawData=t,this.symbol=t.Symbol||"",this.rootSymbol=t.RootSymbol||"",this.underlying=t.Underlying||"",this.expire=t.Expire||"",this.strike=t.Strike||0,this.type=this.determineOptionType(),this.lastPrice=t.LastPx||0,this.closePx=t.ClosePx||0,this.yestClosePx=t.YestClosePx||0,this.openPx=t.OpenPx||0,this.highPx=t.HighPx||0,this.lowPx=t.LowPx||0,this.bidPx=t.BidPx||0,this.bidSz=t.BidSz||0,this.bidExch=t.BidExch||"",this.askPx=t.AskPx||0,this.askSz=t.AskSz||0,this.askExch=t.AskExch||"",this.volume=t.Volume||0,this.openInterest=t.OpenInst||0,this.primeShare=t.PrimeShare||0,this.exch=t.Exch||"",this.dataSource=t.DataSource||"",this.quoteTime=t.QuoteTime||"",this.notFound=t.NotFound||!1}determineOptionType(){return this.symbol?this.symbol.includes("C")?"call":this.symbol.includes("P")?"put":"unknown":"unknown"}getChange(){return this.lastPrice-this.yestClosePx}getChangePercent(){return 0===this.yestClosePx?0:(this.lastPrice-this.yestClosePx)/this.yestClosePx*100}getSpread(){return this.askPx-this.bidPx}getSpreadPercent(){const t=(this.askPx+this.bidPx)/2;return 0===t?0:(this.askPx-this.bidPx)/t*100}getMidPrice(){return(this.askPx+this.bidPx)/2}formatPrice(t){return t?t.toFixed(2):"0.00"}formatStrike(){return`$${this.formatPrice(this.strike)}`}formatLastPrice(){return`$${this.formatPrice(this.lastPrice)}`}formatClosePx(){return`$${this.formatPrice(this.closePx)}`}formatYestClosePx(){return`$${this.formatPrice(this.yestClosePx)}`}formatOpenPx(){return`$${this.formatPrice(this.openPx)}`}formatHighPx(){return`$${this.formatPrice(this.highPx)}`}formatLowPx(){return`$${this.formatPrice(this.lowPx)}`}formatBid(){return`$${this.formatPrice(this.bidPx)}`}formatAsk(){return`$${this.formatPrice(this.askPx)}`}formatBidSize(){return this.bidSz.toString()}formatAskSize(){return this.askSz.toString()}formatSpread(){return`$${this.formatPrice(this.getSpread())}`}formatMidPrice(){return`$${this.formatPrice(this.getMidPrice())}`}formatChange(){const t=this.getChange();return`${t>=0?"+":""}${this.formatPrice(t)}`}formatChangePercent(){const t=this.getChangePercent();return`${t>=0?"+":""}${t.toFixed(2)}%`}formatVolume(){return this.volume.toLocaleString()}formatOpenInterest(){return this.openInterest.toLocaleString()}formatPrimeShare(){return this.primeShare.toString()}formatExpirationDate(){if(!this.expire)return"N/A";try{return new Date(this.expire).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})}catch(t){return this.expire}}formatQuoteTime(){if(!this.quoteTime)return"N/A";try{return new Date(this.quoteTime).toLocaleString("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit"})}catch(t){return this.quoteTime}}formatExchange(){return this.exch||"N/A"}formatDataSource(){return this.dataSource||"N/A"}formatDayRange(){return`$${this.formatPrice(this.lowPx)} - $${this.formatPrice(this.highPx)}`}formatOptionType(){return this.type.toUpperCase()}getDaysToExpiration(){if(!this.expire)return 0;try{const t=new Date(this.expire),e=new Date,n=t.getTime()-e.getTime(),i=Math.ceil(n/864e5);return Math.max(0,i)}catch(t){return 0}}formatDaysToExpiration(){const t=this.getDaysToExpiration();return`${t} day${1!==t?"s":""}`}getMoneyness(t){return t&&0!==this.strike?"call"===this.type?t-this.strike:"put"===this.type?this.strike-t:0:0}isInTheMoney(t){return this.getMoneyness(t)>0}parseSymbol(){return{underlying:this.rootSymbol||"",expirationDate:this.expire||"",type:this.type||"",strikePrice:this.strike||0,fullSymbol:this.symbol||""}}getSummary(){return{symbol:this.symbol,underlying:this.underlying,type:this.formatOptionType(),strike:this.formatStrike(),expiration:this.formatExpirationDate(),lastPrice:this.formatLastPrice(),change:this.formatChange(),changePercent:this.formatChangePercent(),volume:this.formatVolume(),openInterest:this.formatOpenInterest(),bid:this.formatBid(),ask:this.formatAsk(),exchange:this.formatExchange()}}getDataSource(){return"opra-d"===this.dataSource.toLowerCase()?"20 mins delayed":"real-time"===this.dataSource.toLowerCase()?"Real-time":"MDAS Server"}static fromApiResponse(t){return new v(t)}isValid(){return!this.notFound&&this.symbol&&this.strike>0}}class w extends n{constructor(t,e,n){if(super(t,e,n),!e.symbol)throw new Error("Symbol is required for OptionsWidget");if(!e.wsManager)throw new Error("WebSocketManager is required for OptionsWidget");this.type="options";const i=p(e.symbol);if(!i.valid)throw new Error(`Invalid option symbol: ${i.error}`);this.symbol=i.sanitized,this.wsManager=e.wsManager,this.debug=e.debug||!1,this.styled=void 0===e.styled||e.styled,this.data=null,this.isDestroyed=!1,this.unsubscribe=null,this.loadingTimeout=null,this.createWidgetStructure(),this.initializeSymbolEditor(),this.initialize()}createWidgetStructure(){if(this.container.innerHTML='\n <div class="options-widget widget">\n <div class="widget-content">\n \x3c!-- Header Section with Purple Background --\x3e\n <div class="widget-header">\n <div class="symbol-section">\n <h1 class="symbol editable-symbol" \n title="Double-click to edit symbol" \n data-original-symbol="">\n </h1>\n <div class="option-info">\n <span class="underlying-symbol"></span>\n <span class="data-type">OPTIONS</span>\n </div>\n </div>\n <div class="price-section">\n <div class="current-price"></div>\n <div class="price-change">\n <span class="change-value"></span>\n <span class="change-percent"></span>\n </div>\n </div>\n </div>\n\n \x3c!-- Data Grid Section --\x3e\n <div class="data-grid">\n <div class="data-section">\n <div class="section-title">Quote</div>\n <div class="data-row">\n <span class="data-label">Bid</span>\n <span class="data-value bid-ask-value bid-data"></span>\n </div>\n <div class="data-row">\n <span class="data-label">Ask</span>\n <span class="data-value bid-ask-value ask-data"></span>\n </div>\n </div>\n\n <div class="data-section">\n <div class="section-title">Trading Activity</div>\n <div class="data-row">\n <span class="data-label">Volume</span>\n <span class="data-value volume"></span>\n </div>\n <div class="data-row">\n <span class="data-label">Open Interest</span>\n <span class="data-value open-interest"></span>\n </div>\n </div>\n\n <div class="data-section">\n <div class="section-title">Performance</div>\n <div class="data-row">\n <span class="data-label">Previous Close</span>\n <span class="data-value yesterday-close"></span>\n </div>\n <div class="data-row">\n <span class="data-label">Open</span>\n <span class="data-value open-price"></span>\n </div>\n <div class="data-row">\n <span class="data-label">Day Range</span>\n <span class="data-value range-value day-range"></span>\n </div>\n </div>\n\n <div class="data-section">\n <div class="section-title">Contract Info</div>\n <div class="data-row">\n <span class="data-label">Strike Price</span>\n <span class="data-value strike-price"></span>\n </div>\n <div class="data-row">\n <span class="data-label">Expiration</span>\n <span class="data-value expiry-date"></span>\n </div>\n <div class="data-row">\n <span class="data-label">Prime Share</span>\n <span class="data-value prime-share"></span>\n </div>\n </div>\n </div>\n\n \x3c!-- Footer --\x3e\n <div class="widget-footer">\n <span class="last-update"></span>\n <span class="data-source"></span>\n </div>\n </div>\n \n \x3c!-- Loading Overlay --\x3e\n <div class="widget-loading-overlay">\n <div class="loading-content">\n <div class="loading-spinner"></div>\n <span class="loading-text">Loading options data...</span>\n </div>\n </div>\n </div>\n',this.styled){const t=this.container.querySelector(".options-widget");t&&t.classList.add("widget-styled")}this.addStyles()}addStyles(){if(!document.querySelector("#options-widget-styles")){const t=document.createElement("style");t.id="options-widget-styles",t.textContent=c,document.head.appendChild(t)}}initializeSymbolEditor(){this.symbolEditor=new s(this,{maxLength:20,placeholder:"Enter option contract...",onSymbolChange:this.handleSymbolChange.bind(this),debug:this.debug,autoUppercase:!0,symbolType:"optionsl1"});const t=this.container.querySelector(".symbol");t&&(t.textContent=this.symbol,t.dataset.originalSymbol=this.symbol)}async handleSymbolChange(t){this.debug&&console.log("[OptionsWidget] Symbol change requested:",t);const e=p(t);if(!e.valid)return this.debug&&console.log("[OptionsWidget] Invalid option symbol:",e.error),{success:!1,error:e.error};const n=e.sanitized;if(n===this.symbol)return this.debug&&console.log("[OptionsWidget] Same symbol, no change needed"),{success:!0};try{const t=this.symbol;return this.showLoading(),this.loadingTimeout&&this.clearTimeout(this.loadingTimeout),this.loadingTimeout=this.setTimeout((()=>{this.debug&&console.log("[OptionsWidget] Loading timeout for symbol:",n),this.hideLoading(),this.showError(`No data received for ${n}. Please try again.`)}),1e4),this.unsubscribe&&(this.debug&&console.log(`[OptionsWidget] Unsubscribing from ${t}`),this.wsManager.sendUnsubscribe("queryoptionl1",t),this.unsubscribe(),this.unsubscribe=null),this.symbol=n,this.debug&&console.log(`[OptionsWidget] Subscribing to ${n}`),this.subscribeToData(),this.debug&&console.log(`[OptionsWidget] Successfully changed symbol from ${t} to ${n}`),{success:!0}}catch(t){return console.error("[OptionsWidget] Error changing symbol:",t),this.showError(`Failed to load data for ${n}`),{success:!1,error:`Failed to load ${n}`}}}async initialize(){this.showLoading(),await this.validateInitialSymbol(),this.subscribeToData()}async validateInitialSymbol(){try{const t=this.wsManager.getApiService();if(!t)return void(this.debug&&console.log("[OptionsWidget] API service not available for initial validation"));const e=await t.quoteOptionl1(this.symbol);if(e&&e[0]&&!e[0].error&&!e[0].not_found){const t=e[0];this.initialValidationData=t,this.debug&&console.log("[OptionsWidget] Initial symbol validated:",{symbol:this.symbol,underlying:t.Underlying||t.RootSymbol})}}catch(t){this.debug&&console.warn("[OptionsWidget] Initial symbol validation failed:",t)}}subscribeToData(){this.unsubscribe=this.wsManager.subscribe(this.widgetId,["queryoptionl1"],this.handleMessage.bind(this),this.symbol)}handleData(t){if(this.loadingTimeout&&(clearTimeout(this.loadingTimeout),this.loadingTimeout=null),"error"!==t.type){if(t.RootSymbol===this.symbol||t.Underlying===this.symbol||t.Symbol?.includes(this.symbol))if(this.debug&&console.log("[OptionsWidget] Found matching options data for",this.symbol,":",t),!0===t.NotFound)this.data?(this.hideLoading(),this.debug&&console.log("[OptionsWidget] No new data, keeping cached data visible")):this.showNoDataState(t);else{const e=new v(t);this.data=e,this.updateWidget(e)}else if(Array.isArray(t)){const e=t.find((t=>t.RootSymbol===this.symbol||t.Underlying===this.symbol||t.Symbol?.includes(this.symbol)));if(e)if(!0===e.NotFound)this.data?(this.hideLoading(),this.debug&&console.log("[OptionsWidget] No new data, keeping cached data visible")):this.showNoDataState(e);else{const t=new v(e);this.data=t,this.updateWidget(t)}else this.debug&&console.log("[OptionsWidget] No matching data in response, keeping cached data"),this.hideLoading()}t._cached&&this.showConnectionQuality()}else{const e=t.message||"Server error";this.data?(this.hideLoading(),this.debug&&console.log("[OptionsWidget] Error received but keeping cached data:",e)):this.showError(e)}}showNoDataState(t){if(!this.isDestroyed)try{this.hideLoading();const e=t.Symbol||this.symbol,n=this.container.querySelector(".symbol");n&&(n.textContent=e);const i=this.container.querySelector(".underlying-symbol");i&&(i.textContent=t.RootSymbol||this.symbol);const s=this.container.querySelector(".current-price");s&&(s.textContent="$0.00");const o=this.container.querySelector(".price-change");if(o){const t=o.querySelector(".change-value");t&&(t.textContent="+0.00");const e=o.querySelector(".change-percent");e&&(e.textContent=" (0.00%)"),o.classList.remove("positive","negative")}const a=this.container.querySelector(".widget-header");a&&a.classList.add("dimmed"),this.showNoDataMessage(e);const r=f(),c=this.container.querySelector(".last-update");c&&(c.textContent=`Checked: ${r}`)}catch(t){console.error("Error showing no data state:",t),this.showError("Error displaying no data state")}}showNoDataMessage(t){const e=this.container.querySelector(".data-grid"),n=this.container.querySelector(".option-details-section");e&&(e.style.display="none"),n&&(n.style.display="none");const i=this.container.querySelector(".no-data-state");i&&i.remove();const s=l("div","","no-data-state"),o=l("div","","no-data-content"),a=document.createElement("div");a.className="no-data-icon",a.innerHTML='<svg width="48" height="48" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <circle cx="12" cy="12" r="10" stroke="#9ca3af" stroke-width="2"/>\n <path d="M12 6v6l4 2" stroke="#9ca3af" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n </svg>',o.appendChild(a);const r=l("h3","No Data Available","no-data-title");o.appendChild(r);const c=l("p","","no-data-description");c.appendChild(document.createTextNode("Data for "));const d=l("strong",String(t));c.appendChild(d),c.appendChild(document.createTextNode(" was not found")),o.appendChild(c);const h=l("p","Please check the symbol or try again later","no-data-guidance");o.appendChild(h),s.appendChild(o);const u=this.container.querySelector(".widget-footer");u&&u.parentNode?u.parentNode.insertBefore(s,u):this.container.appendChild(s)}updateWidget(t){if(!this.isDestroyed)try{this.loadingTimeout&&(clearTimeout(this.loadingTimeout),this.loadingTimeout=null),this.hideLoading(),this.clearError();const e=this.container.querySelector(".widget-header");e&&e.classList.remove("dimmed");const n=this.container.querySelector(".data-grid");n&&(n.style.display="grid");const i=this.container.querySelector(".no-data-state");i&&i.remove();const s=this.container.querySelector(".symbol");s&&(s.textContent=t.symbol,s.dataset.originalSymbol=t.symbol);const o=this.container.querySelector(".underlying-symbol");o&&(o.textContent=t.rootSymbol||t.underlying||"QQQ");const a=this.container.querySelector(".current-price");a&&(a.textContent=t.formatLastPrice());const r=t.getChange(),c=this.container.querySelector(".price-change");if(c){const e=c.querySelector(".change-value"),n=c.querySelector(".change-percent");e&&(e.textContent=t.formatChange()),n&&(n.textContent=` (${t.formatChangePercent()})`),c.classList.remove("positive","negative","neutral"),r>0?c.classList.add("positive"):r<0?c.classList.add("negative"):c.classList.add("neutral")}const d=this.container.querySelector(".bid-data");if(d){u(d),d.appendChild(document.createTextNode(t.formatBid()));const e=l("span",`× ${t.bidSz}`,"size-info");d.appendChild(e)}const h=this.container.querySelector(".ask-data");if(h){u(h),h.appendChild(document.createTextNode(t.formatAsk()));const e=l("span",`× ${t.askSz}`,"size-info");h.appendChild(e)}const g=this.container.querySelector(".volume");g&&(g.textContent=t.formatVolume());const p=this.container.querySelector(".open-interest");p&&(p.textContent=t.formatOpenInterest());const m=this.container.querySelector(".day-range");m&&(m.textContent=t.formatDayRange());const b=this.container.querySelector(".open-price");b&&(b.textContent=t.formatOpenPx());const y=this.container.querySelector(".yesterday-close");y&&(y.textContent=t.formatYestClosePx());const x=this.container.querySelector(".strike-price");x&&(x.textContent=t.formatStrike());const v=this.container.querySelector(".expiry-date");v&&(v.textContent=t.formatExpirationDate());const w=this.container.querySelector(".prime-share");w&&(w.textContent=t.formatPrimeShare());const S=f(t.quoteTime||Date.now()),k=this.container.querySelector(".last-update");k&&(k.textContent=`Last update: ${S}`);const M=this.container.querySelector(".data-source");M&&(M.textContent=`Source: ${t.getDataSource()}`)}catch(t){console.error("Error updating options widget:",t),this.showError("Error updating data")}}formatPrice(t){return t?t.toFixed(2):"0.00"}formatPriceChange(t){return`${t>=0?"+":""}${t.toFixed(2)}`}showLoading(){const t=this.container.querySelector(".widget-loading-overlay");t&&t.classList.remove("hidden")}hideLoading(){const t=this.container.querySelector(".widget-loading-overlay");t&&t.classList.add("hidden")}showError(t){this.hideLoading(),this.clearError();const e=document.createElement("div");e.className="widget-error",e.textContent=`Error: ${t}`,e.style.cssText="\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n padding: 15px 20px;\n background: #fee;\n border: 1px solid #f5c6cb;\n border-radius: 6px;\n color: #721c24;\n text-align: center;\n font-size: 14px;\n z-index: 100;\n ",this.container.appendChild(e)}clearError(){const t=this.container.querySelector(".widget-error"),e=this.container.querySelector(".widget-error-container");t&&t.remove(),e&&e.remove()}destroy(){this.isDestroyed=!0,this.loadingTimeout&&(this.clearTimeout(this.loadingTimeout),this.loadingTimeout=null),this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=null),this.symbolEditor&&(this.symbolEditor.destroy(),this.symbolEditor=null),super.destroy()}}class S{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.openInterest=t.OpenInst||0,this.volume=t.Vol||0,this.askSize=t.AskSz||0,this.bidSize=t.BidSz||0,this.strike=t.Strike||0,this.askPrice=t.AskPx||0,this.bidPrice=t.BidPx||0,this.lastChange=t.LastChg||0,this.lastPrice=t.LastPx||0,this.dataSource=t.DataSource||"",this.expire=t.Expire||"",this.symbol=t.Symbol||""}}const k=`\n${o}\n\n/* Base styles remain the same until responsive section */\n.option-chain-widget {\n border: 1px solid #e5e7eb;\n border-radius: 8px;\n background: white;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;\n font-size: 13px;\n max-width: 100%;\n overflow: hidden;\n position: relative;\n}\n\n.option-chain-widget .widget-header {\n background: #f9fafb;\n padding: 16px;\n border-bottom: 1px solid #e5e7eb;\n}\n\n.option-chain-widget .input-section {\n display: flex;\n gap: 12px;\n align-items: center;\n flex-wrap: wrap;\n}\n\n.option-chain-widget .symbol-input,\n.option-chain-widget .date-select {\n padding: 8px 12px;\n border: 1px solid #d1d5db;\n border-radius: 4px;\n font-size: 14px;\n font-family: inherit;\n min-width: 0;\n flex: 1;\n}\n\n.option-chain-widget .symbol-input {\n text-transform: uppercase;\n min-width: 100px;\n max-width: 120px;\n}\n\n.option-chain-widget .date-select {\n min-width: 140px;\n background: white;\n}\n\n.option-chain-widget .fetch-button {\n padding: 8px 16px;\n background: #3b82f6;\n color: white;\n border: none;\n border-radius: 4px;\n font-size: 14px;\n cursor: pointer;\n font-family: inherit;\n white-space: nowrap;\n}\n\n.option-chain-widget .fetch-button:hover {\n background: #2563eb;\n}\n\n.option-chain-widget .fetch-button:disabled {\n background: #9ca3af;\n cursor: not-allowed;\n}\n\n.option-chain-widget .date-select:disabled {\n background: #f3f4f6;\n color: #9ca3af;\n cursor: not-allowed;\n}\n\n.option-chain-widget .option-chain-table {\n max-height: 800px;\n overflow-x: auto; /* Enable horizontal scrolling */\n overflow-y: auto; /* Enable vertical scrolling if needed */\n -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */\n width: 100%; /* Ensure full width */\n position: relative; /* Establish positioning context */\n box-sizing: border-box; /* Include padding and border in the element's total width and height */\n}\n\n.option-chain-widget .table-header {\n background: #f3f4f6;\n font-weight: 600;\n border-bottom: 2px solid #d1d5db;\n position: sticky;\n top: 0;\n z-index: 10;\n width: fit-content; /* Ensure it spans the full width */\n box-sizing: border-box; /* Include padding and border in the element's total width and height */\n}\n\n.option-chain-widget .price-change.positive::before,\n.option-chain-widget .price-change.negative::before {\n content: none;\n}\n \n\n/* Better approach - make section headers align with actual column structure */\n.option-chain-widget .section-headers,\n.option-chain-widget .column-headers {\n\n display: grid;\n grid-template-columns: minmax(160px, 1fr) repeat(6, minmax(80px, 1fr)) 80px minmax(160px, 1fr) repeat(6, minmax(80px, 1fr));\n border-bottom: 1px solid #d1d5db;\n background: #f3f4f6;\n position: sticky;\n top: 0;\n z-index: 12;\n box-sizing: border-box; /* Include padding and border in the element's total width and height */\n margin: 0;\n padding: 0;\n min-width: fit-content;\n}\n\n.option-chain-widget .calls-header {\n grid-column: 1 / 8; /* Span across first 7 columns */\n padding: 8px;\n text-align: center;\n font-weight: 600;\n font-size: 14px;\n color: #374151;\n display: flex;\n align-items: center;\n justify-content: center;\n background: #f3f4f6;\n}\n\n.option-chain-widget .strike-header {\n grid-column: 8 / 9; /* Strike column */\n background: #e5e7eb;\n display: flex;\n align-items: center;\n justify-content: center;\n}\n\n.option-chain-widget .puts-header {\n grid-column: 9 / -1; /* Span from column 9 to the end */\n padding: 8px;\n text-align: center;\n font-weight: 600;\n font-size: 14px;\n color: #374151;\n display: flex;\n align-items: center;\n justify-content: center;\n background: #f3f4f6;\n}\n\n.option-chain-widget .column-headers {\n display: grid;\n grid-template-columns: minmax(160px, 1fr) repeat(6, minmax(80px, 1fr)) 80px minmax(160px, 1fr) repeat(6, minmax(80px, 1fr));\n position: sticky;\n top: 40px;\n z-index: 11;\n background: #f3f4f6;\n}\n\n.option-chain-widget .calls-columns,\n.option-chain-widget .puts-columns {\n display: contents; /* Remove their own grid, use parent grid */\n}\n\n.option-chain-widget .strike-column {\n display: flex;\n align-items: center;\n justify-content: center;\n background: #e5e7eb !important;\n font-weight: bold;\n color: #374151;\n font-size: 11px;\n text-transform: uppercase;\n}\n\n.option-chain-widget .strike-column span {\n background: transparent !important; /* Ensure span doesn't override parent background */\n}\n\n.option-chain-widget .column-headers span {\n padding: 6px 2px; /* Reduce padding to prevent text overflow */\n text-align: center;\n font-size: 11px; /* Reduce font size */\n text-transform: uppercase;\n color: #6b7280;\n font-weight: 600;\n letter-spacing: 0.3px; /* Reduce letter spacing */\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n background: #f3f4f6;\n}\n\n.option-chain-widget .option-row {\n display: grid;\n grid-template-columns: minmax(160px, 1fr) repeat(6, minmax(80px, 1fr)) 80px minmax(160px, 1fr) repeat(6, minmax(80px, 1fr));\n border-bottom: 1px solid #f3f4f6;\n min-height: 32px;\n}\n\n.option-chain-widget .option-row:hover {\n background: #f9fafb;\n}\n .option-chain-widget .option-row:hover .calls-data span,\n.option-chain-widget .option-row:hover .puts-data span,\n.option-chain-widget .option-row:hover .strike-data {\n background: #f9fafb;\n}\n\n.option-chain-widget .calls-data,\n.option-chain-widget .puts-data {\n display: contents; /* Make children participate in parent grid */\n}\n\n.option-chain-widget .strike-data {\n display: flex;\n align-items: center;\n justify-content: center;\n background: #f9fafb;\n font-weight: 600; /* Changed from bold to 600 for consistency */\n color: #6b7280; /* Changed from #1f2937 to match other widgets */\n}\n\n.option-chain-widget .calls-data span,\n.option-chain-widget .puts-data span {\n padding: 6px 4px;\n text-align: center;\n font-size: 12px; /* Changed from 12px to 14px */\n font-weight: 400; /* Added to match data values in other widgets */\n color: #111827; /* Changed from #374151 to match other widgets */\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n\n.option-chain-widget .contract-cell {\n font-size: 10px;\n color: #6b7280;\n text-align: left;\n padding: 4px 6px;\n font-family: monospace;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n\n.option-chain-widget .positive {\n color: #059669;\n}\n\n.option-chain-widget .negative {\n color: #dc2626;\n}\n\n.option-chain-widget .neutral {\n color: #6b7280;\n}\n\n.option-chain-widget .widget-footer {\n background: #f9fafb;\n padding: 8px 16px;\n border-top: 1px solid #e5e7eb;\n text-align: center;\n font-size: 11px;\n color: #6b7280;\n}\n\n.option-chain-widget .widget-loading-overlay {\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background: rgba(255, 255, 255, 0.9);\n display: flex;\n align-items: center;\n justify-content: center;\n z-index: 20;\n}\n\n.option-chain-widget .widget-loading-overlay.hidden {\n display: none;\n}\n\n.option-chain-widget .loading-content {\n text-align: center;\n}\n\n.option-chain-widget .loading-spinner {\n width: 32px;\n height: 32px;\n border: 3px solid #e5e7eb;\n border-top: 3px solid #3b82f6;\n border-radius: 50%;\n animation: spin 1s linear infinite;\n margin: 0 auto 12px;\n}\n\n@keyframes spin {\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n}\n\n.option-chain-widget .no-data-state {\n padding: 40px;\n text-align: center;\n color: #6b7280;\n}\n\n.option-chain-widget .widget-error {\n padding: 20px;\n background: #fef2f2;\n color: #dc2626;\n border: 1px solid #fecaca;\n margin: 16px;\n border-radius: 4px;\n text-align: center;\n}\n\n/* RESPONSIVE STYLES */\n\n/* Tablet styles (768px and down) */\n@media (max-width: 768px) {\n .option-chain-widget .input-section {\n flex-direction: column;\n align-items: stretch;\n gap: 8px;\n }\n \n .option-chain-widget .symbol-input,\n .option-chain-widget .date-select {\n width: 100%;\n max-width: none;\n }\n \n .option-chain-widget .fetch-button {\n width: 100%;\n }\n \n .option-chain-widget .calls-columns,\n .option-chain-widget .puts-columns {\n grid-template-columns: 120px repeat(6, minmax(50px, 1fr));\n }\n \n .option-chain-widget .calls-data,\n .option-chain-widget .puts-data {\n grid-template-columns: 120px repeat(6, minmax(50px, 1fr));\n }\n \n .option-chain-widget .column-headers span {\n font-size: 10px;\n padding: 6px 2px;\n }\n \n .option-chain-widget .calls-data span,\n .option-chain-widget .puts-data span {\n font-size: 11px;\n padding: 4px 2px;\n }\n \n .option-chain-widget .contract-cell {\n font-size: 9px;\n padding: 4px 4px;\n }\n \n .option-chain-widget .strike-data {\n font-size: 12px;\n }\n\n /* Update responsive breakpoints to match */\n .option-chain-widget .section-headers {\n grid-template-columns: 1fr 80px 1fr;\n background: #f3f4f6;\n width: 100%;\n\n }\n}\n\n/* Mobile styles (480px and down) */\n@media (max-width: 480px) {\n .option-chain-widget {\n font-size: 12px;\n }\n \n .option-chain-widget .widget-header {\n padding: 12px;\n }\n \n .option-chain-widget .section-headers {\n grid-template-columns: 1fr 60px 1fr;\n background: #f3f4f6;\n }\n \n .option-chain-widget .column-headers {\n grid-template-columns: 1fr 60px 1fr;\n }\n \n .option-chain-widget .option-row {\n grid-template-columns: 1fr 60px 1fr;\n min-height: 28px;\n }\n \n .option-chain-widget .calls-columns,\n .option-chain-widget .puts-columns {\n grid-template-columns: 100px repeat(6, minmax(40px, 1fr));\n }\n \n .option-chain-widget .calls-data,\n .option-chain-widget .puts-data {\n grid-template-columns: 100px repeat(6, minmax(40px, 1fr));\n }\n \n .option-chain-widget .column-headers span {\n font-size: 9px;\n padding: 4px 1px;\n }\n \n .option-chain-widget .calls-data span,\n .option-chain-widget .puts-data span {\n font-size: 10px;\n padding: 3px 1px;\n }\n \n .option-chain-widget .contract-cell {\n font-size: 8px;\n padding: 3px 2px;\n }\n \n .option-chain-widget .strike-data {\n font-size: 11px;\n padding: 3px;\n }\n \n \n .option-chain-widget .option-chain-table {\n max-height: 400px;\n }\n \n .option-chain-widget .no-data-state {\n padding: 20px;\n font-size: 12px;\n }\n \n .option-chain-widget .widget-error {\n margin: 8px;\n padding: 12px;\n font-size: 12px;\n }\n}\n\n/* Very small mobile (320px and down) */\n@media (max-width: 320px) {\n .option-chain-widget .section-headers {\n grid-template-columns: 1fr 50px 1fr;\n }\n \n .option-chain-widget .column-headers {\n grid-template-columns: 1fr 50px 1fr;\n }\n \n .option-chain-widget .option-row {\n grid-template-columns: 1fr 50px 1fr;\n }\n \n .option-chain-widget .calls-columns,\n .option-chain-widget .puts-columns {\n grid-template-columns: 80px repeat(6, minmax(35px, 1fr));\n }\n \n .option-chain-widget .calls-data,\n .option-chain-widget .puts-data {\n grid-template-columns: 80px repeat(6, minmax(35px, 1fr));\n }\n \n .option-chain-widget .column-headers span {\n font-size: 8px;\n padding: 3px 1px;\n }\n \n .option-chain-widget .calls-data span,\n .option-chain-widget .puts-data span {\n font-size: 9px;\n padding: 2px 1px;\n }\n \n .option-chain-widget .contract-cell {\n font-size: 7px;\n padding: 2px 1px;\n }\n}\n`;class M extends n{constructor(t,e,n){if(super(t,e,n),!e.wsManager)throw new Error("WebSocketManager is required for OptionChainWidget");if(this.type="optionchain",this.wsManager=e.wsManager,this.debug=e.debug||!1,this.data=null,this.isDestroyed=!1,this.unsubscribe=null,this.loadingTimeout=null,e.symbol){const t=g(e.symbol);t.valid?this.symbol=t.sanitized:(console.warn("[OptionChainWidget] Invalid initial symbol:",t.error),this.symbol="")}else this.symbol="";this.date="",this.availableDates={},this.fetchRateLimiter=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:500,e=0;return()=>{const n=Date.now(),i=n-e;return i<t?{valid:!1,error:`Please wait ${Math.ceil((t-i)/1e3)} seconds`,remainingMs:t-i}:(e=n,{valid:!0})}}(1e3),this.createWidgetStructure(),this.initialize()}createWidgetStructure(){this.container.innerHTML='\n <div class="option-chain-widget widget">\n <div class="widget-content">\n \x3c!-- Header Section --\x3e\n <div class="widget-header">\n <div class="input-section">\n <input type="text" class="symbol-input" placeholder="Enter Symbol" value="" />\n <select class="date-select" disabled>\n <option value="">Select a date...</option>\n </select>\n <button class="fetch-button" disabled>Search</button>\n </div>\n </div>\n\n \x3c!-- Data Grid Section --\x3e\n <div class="option-chain-table">\n <div class="table-header">\n <div class="section-headers">\n <div class="calls-header">Calls</div>\n <div class="strike-header"></div>\n <div class="puts-header">Puts</div>\n </div>\n <div class="column-headers">\n <div class="calls-columns">\n <span>Contract</span>\n <span>Last</span>\n <span>Change</span>\n <span>Bid</span>\n <span>Ask</span>\n <span>Volume</span>\n <span>Open Int.</span>\n </div>\n <div class="strike-column">\n <span>Strike</span>\n </div>\n <div class="puts-columns">\n <span>Contract</span>\n <span>Last</span>\n <span>Change</span>\n <span>Bid</span>\n <span>Ask</span>\n <span>Volume</span>\n <span>Open Int.</span>\n </div>\n </div>\n </div>\n <div class="option-chain-data-grid">\n \x3c!-- Option chain data will be populated here --\x3e\n </div>\n </div>\n\n \x3c!-- Footer --\x3e\n <div class="widget-footer">\n <span class="last-update"></span>\n <span class="data-source"></span>\n </div>\n </div>\n \n \x3c!-- Loading Overlay --\x3e\n <div class="widget-loading-overlay hidden">\n <div class="loading-content">\n <div class="loading-spinner"></div>\n <span class="loading-text">Loading option chain data...</span>\n </div>\n </div>\n </div>\n',this.addStyles(),this.setupEventListeners()}addStyles(){if(!document.querySelector("#option-chain-styles")){const t=document.createElement("style");t.id="option-chain-styles",t.textContent=k,document.head.appendChild(t)}}setupEventListeners(){this.symbolInput=this.container.querySelector(".symbol-input"),this.dateSelect=this.container.querySelector(".date-select"),this.fetchButton=this.container.querySelector(".fetch-button"),this.dataGrid=this.container.querySelector(".option-chain-data-grid"),this.symbol&&(this.symbolInput.value=this.symbol,this.fetchButton.disabled=!1,this.dateSelect.innerHTML='<option value="">Click search to load dates...</option>'),this.addEventListener(this.symbolInput,"input",(t=>{const e=t.target.value,n=g(e);this.clearInputError(this.symbolInput),n.valid?(this.symbol=n.sanitized,this.symbolInput.value=n.sanitized,this.dateSelect.innerHTML='<option value="">Click search to load dates...</option>',this.dateSelect.disabled=!0,this.fetchButton.disabled=!1,this.availableDates={},this.date=""):""!==e.trim()?(this.showInputError(this.symbolInput,n.error),this.fetchButton.disabled=!0):this.clearDateOptions()})),this.addEventListener(this.dateSelect,"change",(t=>{const e=t.target.value;if(!e)return void(this.date="");const n=function(t){if(!t||"string"!=typeof t)return{valid:!1,error:"Date is required",normalized:""};const e=t.trim();let n;if(/^\d{4}-\d{2}-\d{2}$/.test(e))n=new Date(e);else if(/^\d{2}\/\d{2}\/\d{4}$/.test(e)){const[t,i,s]=e.split("/");n=new Date(s,parseInt(t,10)-1,parseInt(i,10))}else{if(!/^\d+$/.test(e))return{valid:!1,error:"Invalid date format. Use YYYY-MM-DD or MM/DD/YYYY",normalized:""};n=new Date(parseInt(e,10))}return isNaN(n.getTime())?{valid:!1,error:"Invalid date",normalized:""}:{valid:!0,normalized:n.toISOString().split("T")[0]}}(e);n.valid?(this.date=n.normalized,this.symbol&&this.fetchOptionChain()):(this.showError(n.error),this.date="")})),this.addEventListener(this.fetchButton,"click",(()=>{const t=g(this.symbol);if(!t.valid)return void this.showError(t.error||"Please enter a valid symbol first");const e=this.fetchRateLimiter();e.valid?this.loadAvailableDates(t.sanitized):this.showError(e.error)}))}async loadAvailableDates(t){if(t)try{this.symbol=t,this.symbolInput.value=t,this.dateSelect.disabled=!0,this.dateSelect.innerHTML='<option value="">Loading dates...</option>',this.fetchButton.disabled=!0;const e=this.wsManager.getApiService(),n=await e.getOptionChainDates(t);console.log("Available dates:",n.dates_dictionary),this.availableDates=n.dates_dictionary||{},this.populateDateOptions()}catch(e){console.error("[OptionChainWidget] Error loading dates:",e),this.dateSelect.innerHTML='<option value="">Error loading dates</option>',this.fetchButton.disabled=!1,this.showError(`Failed to load dates for ${t}: ${e.message}`)}}populateDateOptions(){this.dateSelect.innerHTML='<option value="">Select expiration date...</option>';const t=Object.keys(this.availableDates).sort();if(0===t.length)return this.dateSelect.innerHTML='<option value="">No dates available</option>',void(this.fetchButton.disabled=!1);t.forEach((t=>{const e=document.createElement("option");e.value=t;const n=this.availableDates[t],i=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{timezone:n="ET",format:i="short"}=e;if(!t||"string"!=typeof t)return"";const s=t.split("-");if(3!==s.length)return t;const[o,a,r]=s,c=parseInt(a,10)-1,l=parseInt(r,10),d=("long"===i?["January","February","March","April","May","June","July","August","September","October","November","December"]:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"])[c];return`${d} ${l}, ${o}`}(t,{timezone:m(t),format:"short"});e.textContent=i,e.className=`date-option ${n}`,this.dateSelect.appendChild(e)})),this.dateSelect.disabled=!1,this.fetchButton.disabled=!1,t.length>0&&(this.dateSelect.value=t[0],this.date=t[0],this.fetchOptionChain())}clearDateOptions(){this.dateSelect.innerHTML='<option value="">Click fetch to load dates...</option>',this.dateSelect.disabled=!0,this.fetchButton.disabled=!this.symbol,this.symbol=this.symbolInput.value.trim().toUpperCase()||"",this.date="",this.availableDates={}}initialize(){this.hideLoading(),this.symbol&&this.loadAvailableDates(this.symbol)}fetchOptionChain(){if(this.symbol&&this.date)try{this.showLoading(),this.loadingTimeout&&this.clearTimeout(this.loadingTimeout),this.loadingTimeout=this.setTimeout((()=>{this.debug&&console.log("[OptionChainWidget] Loading timeout for:",this.symbol,this.date),this.hideLoading(),this.showError(`No data received for ${this.symbol} on ${this.date}. Please try again.`)}),1e4),this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=null),this.subscribeToData()}catch(t){console.error("[OptionChainWidget] Error fetching option chain:",t),this.showError(`Failed to load data for ${this.symbol}`)}else console.warn("[OptionChainWidget] Missing symbol or date")}subscribeToData(){this.unsubscribe=this.wsManager.subscribe(this.widgetId,["queryoptionchain"],this.handleMessage.bind(this),this.symbol,{date:this.date})}handleData(t){if(this.loadingTimeout&&(clearTimeout(this.loadingTimeout),this.loadingTimeout=null),"error"!==t.type)Array.isArray(t)?0===t.length?this.data?(this.hideLoading(),this.debug&&console.log("[OptionChainWidget] No new data, keeping cached data visible")):this.showNoDataState():(this.data=t,this.displayOptionChain(t)):"queryoptionchain"===t.type&&Array.isArray(t.data)&&(0===t.data.length?this.data?(this.hideLoading(),this.debug&&console.log("[OptionChainWidget] No new data, keeping cached data visible")):this.showNoDataState():(this.data=t.data,this.displayOptionChain(t.data))),t._cached&&this.showConnectionQuality();else{const e=t.message||"Server error";this.data?(this.hideLoading(),this.debug&&console.log("[OptionChainWidget] Error received but keeping cached data:",e)):this.showError(e)}}displayOptionChain(t){if(!this.isDestroyed)try{this.hideLoading(),this.clearError(),this.dataGrid.innerHTML="";const e={};t.forEach((t=>{const n=new S(t),i=n.strike;e[i]||(e[i]={call:null,put:null});"call"===_(n.symbol)?e[i].call=n:e[i].put=n}));if(Object.keys(e).sort(((t,e)=>parseFloat(t)-parseFloat(e))).forEach((t=>{const{call:n,put:i}=e[t],s=document.createElement("div");s.classList.add("option-row");const o=t=>{const e=document.createElement("span");if(!t||0===t)return e.className="neutral",e.textContent="0.00",e;const n=parseFloat(t).toFixed(2),i=t>0?"positive":t<0?"negative":"neutral",s=t>0?"+":"";return e.className=`option-chain-${i}`,e.textContent=`${s}${n}`,e},a=t=>d(t,2,"0.00"),r=document.createElement("div");r.className="calls-data",r.appendChild(l("span",n?h(n.symbol):"--","contract-cell")),r.appendChild(l("span",a(n?.lastPrice)));const c=document.createElement("span");n?c.appendChild(o(n.lastChange)):(c.textContent="0.00",c.className="neutral"),r.appendChild(c),r.appendChild(l("span",a(n?.bidPrice))),r.appendChild(l("span",a(n?.askPrice))),r.appendChild(l("span",n?String(n.volume):"0")),r.appendChild(l("span",n?String(n.openInterest):"0"));const u=document.createElement("div");u.className="strike-data",u.textContent=t;const g=document.createElement("div");g.className="puts-data",g.appendChild(l("span",i?h(i.symbol):"","contract-cell")),g.appendChild(l("span",a(i?.lastPrice)));const p=document.createElement("span");i?p.appendChild(o(i.lastChange)):(p.textContent="0.00",p.className="neutral"),g.appendChild(p),g.appendChild(l("span",a(i?.bidPrice))),g.appendChild(l("span",a(i?.askPrice))),g.appendChild(l("span",i?String(i.volume):"0")),g.appendChild(l("span",i?String(i.openInterest):"0")),s.appendChild(r),s.appendChild(u),s.appendChild(g),this.dataGrid.appendChild(s)})),t&&t.length>0){const e=f(t[0].quoteTime||Date.now()),n=this.container.querySelector(".last-update");n&&(n.textContent=`Last update: ${e}`);const i="OPRA-D"===t[0].DataSource?"20 mins delayed":"Real-time",s=this.container.querySelector(".data-source");s&&(s.textContent=`Source: ${i}`)}}catch(t){console.error("Error displaying option chain:",t),this.showError("Error displaying data")}}showLoading(){const t=this.container.querySelector(".widget-loading-overlay");t&&t.classList.remove("hidden")}hideLoading(){const t=this.container.querySelector(".widget-loading-overlay");t&&t.classList.add("hidden")}showError(t){this.hideLoading(),this.clearError();const e=document.createElement("div");e.className="widget-error",e.textContent=`Error: ${t}`,e.style.cssText="\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n padding: 15px 20px;\n background: #fee;\n border: 1px solid #f5c6cb;\n border-radius: 6px;\n color: #721c24;\n text-align: center;\n font-size: 14px;\n z-index: 100;\n ",this.container.appendChild(e)}clearError(){const t=this.container.querySelector(".widget-error"),e=this.container.querySelector(".widget-error-container");t&&t.remove(),e&&e.remove()}showNoDataState(){this.hideLoading(),this.clearError();const t=l("div","","no-data-state"),e=l("div","","no-data-content"),n=document.createElement("div");n.className="no-data-icon",n.innerHTML='<svg width="32" height="32" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <circle cx="12" cy="12" r="10" stroke="#9ca3af" stroke-width="2"/>\n <path d="M12 6v6l4 2" stroke="#9ca3af" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n </svg>',e.appendChild(n);const i=l("h3","No Option Chain Data","no-data-title");e.appendChild(i);const s=l("p","","no-data-description");s.appendChild(document.createTextNode("Option chain data for "));const o=l("strong",h(this.symbol));s.appendChild(o),s.appendChild(document.createTextNode(" on "));const a=l("strong",String(this.date));s.appendChild(a),s.appendChild(document.createTextNode(" was not found")),e.appendChild(s);const r=l("p","Please check the symbol and date or try again later","no-data-guidance");e.appendChild(r),t.appendChild(e);const c=this.container.querySelector(".widget-footer");c&&c.parentNode?c.parentNode.insertBefore(t,c):this.container.appendChild(t)}destroy(){this.isDestroyed=!0,this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=null),this.loadingTimeout&&(this.clearTimeout(this.loadingTimeout),this.loadingTimeout=null),super.destroy()}}const _=t=>{const e=t.match(/^(.+?)(\d{6})([CP])(\d{8})$/);if(e){const[,t,n,i,s]=e;return"C"===i?"call":"put"}return null};class C extends n{constructor(t,e,n){if(super(t,e,n),!e.symbol)throw new Error("Symbol is required for DataWidget");if(!e.wsManager)throw new Error("WebSocketManager is required for DataWidget");this.type="data",this.symbol=(e.symbol||"").toString().toUpperCase(),this.wsManager=e.wsManager,this.dataSource=e.dataSource||"queryl1",this.debug=e.debug||!1,this.data=null,this.isDestroyed=!1,this.unsubscribe=null,this.loadingTimeout=null,this.createWidgetStructure(),this.initializeSymbolEditor(),this.initialize()}createWidgetStructure(){this.container.innerHTML='\n <div class="data-widget widget">\n <div class="widget-content">\n \x3c!-- Header Section --\x3e\n <div class="widget-header">\n <div class="symbol-section">\n <h1 class="symbol editable-symbol" \n title="Double-click to edit symbol" \n data-original-symbol="">\n </h1>\n <div class="company-info">\n <span class="data-type">Stock</span>\n <span class="company-name"></span>\n </div>\n </div>\n </div>\n\n \x3c!-- Price Section --\x3e\n <div class="price-section">\n <div class="current-price"></div>\n <div class="price-change">\n <span class="change-value"></span>\n <span class="change-percent"></span>\n </div>\n </div>\n\n \x3c!-- Bid/Ask Section --\x3e\n <div class="bid-ask-section">\n <div class="ask">\n <span class="label">Ask</span>\n <span class="value ask-price"></span>\n <span class="size ask-size"></span>\n </div>\n <div class="bid">\n <span class="label">Bid</span>\n <span class="value bid-price"></span>\n <span class="size bid-size"></span>\n </div>\n </div>\n\n \x3c!-- Footer --\x3e\n <div class="widget-footer">\n <span class="last-size">Last Size: <span class="trade-size"></span></span>\n <span class="source">Market Data Powered by MDAS</span>\n </div>\n </div>\n\n \n </div>\n',this.addStyles()}addStyles(){if(!document.querySelector("#data-styles")){const t=document.createElement("style");t.id="data-styles",t.textContent="\n .data-widget {\n position: relative;\n border: 1px solid #ddd;\n border-radius: 8px;\n overflow: hidden;\n background-color: #fff;\n box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);\n padding: 10px;\n font-family: Arial, sans-serif;\n }\n\n .widget-header {\n display: flex;\n flex-direction: column;\n margin-bottom: 10px;\n }\n\n .symbol {\n font-size: 24px;\n font-weight: bold;\n margin-right: 10px;\n }\n\n .company-info {\n font-size: 12px;\n color: #666;\n }\n\n .trading-info {\n font-size: 12px;\n color: #999;\n }\n\n .price-section {\n display: flex;\n align-items: baseline;\n margin-bottom: 10px;\n }\n\n .current-price {\n font-size: 36px;\n font-weight: bold;\n margin-right: 10px;\n }\n\n .price-change {\n font-size: 18px;\n }\n\n .price-change.positive {\n color: green;\n }\n\n .price-change.negative {\n color: red;\n }\n\n .bid-ask-section {\n display: flex;\n justify-content: space-between;\n margin-bottom: 10px;\n }\n\n .ask, .bid {\n display: flex;\n align-items: center;\n }\n\n .label {\n font-size: 14px;\n margin-right: 5px;\n }\n\n .value {\n font-size: 16px;\n font-weight: bold;\n margin-right: 5px;\n }\n\n .size {\n font-size: 14px;\n color: red;\n }\n\n .widget-footer {\n font-size: 12px;\n color: #333;\n }\n",document.head.appendChild(t)}}initializeSymbolEditor(){this.symbolEditor=new s(this,{maxLength:10,placeholder:"Enter symbol...",onSymbolChange:this.handleSymbolChange.bind(this),debug:this.debug,autoUppercase:!0,symbolType:"quotel1"});const t=this.container.querySelector(".symbol");t&&(t.textContent=this.symbol,t.dataset.originalSymbol=this.symbol)}async handleSymbolChange(t){this.debug&&console.log("[DataWidget] Symbol change requested:",t);const e=t.toUpperCase();if(e===this.symbol)return this.debug&&console.log("[DataWidget] Same symbol, no change needed"),{success:!0};try{const t=this.symbol;return this.showLoading(),this.loadingTimeout&&clearTimeout(this.loadingTimeout),this.loadingTimeout=setTimeout((()=>{this.debug&&console.log("[DataWidget] Loading timeout for symbol:",e),this.hideLoading(),this.showError(`No data received for ${e}. Please try again.`)}),1e4),this.unsubscribe&&(this.debug&&console.log(`[DataWidget] Unsubscribing from ${t}`),this.wsManager.sendUnsubscribe(this.dataSource,t),this.unsubscribe(),this.unsubscribe=null),this.symbol=e,this.debug&&console.log(`[DataWidget] Subscribing to ${e}`),this.subscribeToData(),this.debug&&console.log(`[DataWidget] Successfully changed symbol from ${t} to ${e}`),{success:!0}}catch(t){return console.error("[DataWidget] Error changing symbol:",t),this.hideLoading(),this.showError(`Failed to load data for ${e}`),{success:!1,error:`Failed to load ${e}`}}}initialize(){this.showLoading(),this.subscribeToData()}subscribeToData(){this.unsubscribe=this.wsManager.subscribe(this.widgetId,[this.dataSource],this.handleMessage.bind(this),this.symbol)}showNoDataState(t){let{Symbol:e,NotFound:n,message:i}=t;this.clearError(),this.hideLoading();const s=document.createElement("div");s.className="no-data-state",s.innerHTML=`\n <div class="no-data-content">\n <div class="no-data-icon">\n <svg width="32" height="32" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <circle cx="12" cy="12" r="10" stroke="#9ca3af" stroke-width="2"/>\n <path d="M12 6v6l4 2" stroke="#9ca3af" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n </svg>\n </div>\n <h3 class="no-data-title">No Data Available</h3>\n <p class="no-data-description">Data for <strong>${e}</strong> was not found.</p>\n <p class="no-data-guidance">${i||"Please check the symbol or try again later."}</p>\n </div>\n `,this.container.appendChild(s)}handleData(t){if(this.loadingTimeout&&(clearTimeout(this.loadingTimeout),this.loadingTimeout=null),"error"===t.type&&t.noData)return this.debug&&console.log("[DataWidget] Received no data message:",t.message),void this.showNoDataState({Symbol:this.symbol,NotFound:!0,message:t.message});if("error"!==t.type){if(t.Data&&t.Data.length>0){const e=t.Data.find((t=>t.Symbol===this.symbol));if(e){const t=new i(e);this.updateWidget(t)}else console.log("hereee"),this.showNoDataState({Symbol:this.symbol,NotFound:!0,message:`No data found for ${this.symbol}`})}t._cached&&this.showConnectionQuality()}else{const e=t.message||"Server error";this.showError(e)}}updateWidget(t){if(!this.isDestroyed)try{this.clearError(),this.hideLoading();const e=this.container.querySelector(".symbol");e&&(e.textContent=t.symbol,e.dataset.originalSymbol=t.symbol);const n=this.container.querySelector(".current-price");n&&(n.textContent=t.formatPrice());const i=this.container.querySelector(".price-change"),s=i.querySelector(".change-value"),o=i.querySelector(".change-percent");s.textContent=t.formatPriceChange(),o.textContent=` (${t.formatPriceChangePercent()})`,i.classList.remove("positive","negative","neutral"),t.getPriceChange()>0?i.classList.add("positive"):t.getPriceChange()<0?i.classList.add("negative"):i.classList.add("neutral");const a=this.container.querySelector(".bid-price");a&&(a.textContent=t.bidPrice.toFixed(2));const r=this.container.querySelector(".ask-price");r&&(r.textContent=t.askPrice.toFixed(2));const c=this.container.querySelector(".bid-size");c&&(c.textContent=`× ${t.bidSize}`);const l=this.container.querySelector(".ask-size");l&&(l.textContent=`× ${t.askSize}`);const d=this.container.querySelector(".trade-size");d&&(d.textContent=t.tradeSize);const h=this.container.querySelector(".last-update");if(h){const e=f(t.quoteTime);h.textContent=`Last update: ${e}`}const u=this.container.querySelector(".data-source");u&&(u.textContent=`Source: ${t.getDataSource()}`)}catch(t){console.error("Error updating widget:",t),this.showError("Error updating data")}}}class T extends n{constructor(t,e,n){if(super(t,e,n),!e.symbol)throw new Error("Symbol is required for CombinedMarketWidget");if(!e.wsManager)throw new Error("WebSocketManager is required for CombinedMarketWidget");const i=g(e.symbol);if(!i.valid)throw new Error(`Invalid symbol: ${i.error}`);this.type="combined-market",this.wsManager=e.wsManager,this.symbol=i.sanitized,this.debug=e.debug||!1,this.removeNightSession=!0,this.marketData=null,this.nightSessionData=null,this.unsubscribeMarket=null,this.unsubscribeNight=null,this.createWidgetStructure(),this.initializeSymbolEditor(),this.subscribeToData()}createWidgetStructure(){this.container.innerHTML='\n <div class="combined-market-widget">\n <div class="combined-market-header">\n <div class="combined-symbol-section">\n <h1 class="combined-symbol editable-symbol"\n title="Double-click to edit symbol"\n data-original-symbol="">\n </h1>\n <div class="combined-company-info">\n <span class="company-name">\n </span>\n </div>\n </div>\n </div>\n\n <div class="combined-data-container">\n \x3c!-- Regular Market Data (Left) --\x3e\n <div class="combined-market-section regular-market">\n <div class="combined-price-info">\n <div class="combined-current-price">--</div>\n <div class="combined-price-change neutral">\n <span class="combined-change-value">--</span>\n <span class="combined-change-percent">(--)</span>\n </div>\n </div>\n <div class="combined-market-status"><span class="market-status-label"></span> <span class="combined-timestamp">--</span></div>\n </div>\n\n \x3c!-- Night Session Data (Right) --\x3e\n <div class="combined-market-section night-session">\n\n <div class="combined-price-info">\n <div class="combined-current-price">--</div>\n <div class="combined-price-change neutral">\n <span class="combined-change-value">--</span>\n <span class="combined-change-percent">(--)</span>\n </div>\n </div>\n <div class="combined-market-status">Overnight: <span class="combined-timestamp">--</span></div>\n </div>\n </div>\n\n <div class="combined-loading-overlay hidden">\n <div class="combined-loading-content">\n <div class="combined-loading-spinner"></div>\n <span class="combined-loading-text">Loading market data...</span>\n </div>\n </div>\n </div>\n';const t=this.container.querySelector(".combined-symbol");if(t&&(t.textContent=this.symbol,t.dataset.originalSymbol=this.symbol),this.removeNightSession&&!this.isNightSessionActive()){const t=this.container.querySelector(".night-session");t&&(t.style.display="none")}this.addStyles()}addStyles(){if(!document.querySelector("#combined-market-styles")){const t=document.createElement("style");t.id="combined-market-styles",t.textContent='\n .combined-market-widget {\n background: #ffffff;\n color: #111827;\n padding: 24px;\n border-radius: 12px;\n border: 1px solid #e5e7eb;\n box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);\n font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;\n position: relative;\n }\n\n .combined-market-widget .combined-market-header {\n display: flex;\n justify-content: space-between;\n align-items: center;\n margin-bottom: 24px;\n padding-bottom: 16px;\n border-bottom: 1px solid #e5e7eb;\n }\n\n .combined-market-widget .combined-symbol-section {\n display: flex;\n flex-direction: column;\n gap: 4px;\n }\n\n .combined-market-widget .combined-symbol {\n font-size: 24px;\n font-weight: 700;\n margin: 0;\n color: #111827;\n cursor: pointer;\n transition: all 0.2s ease;\n position: relative;\n }\n\n .combined-market-widget .combined-symbol:hover {\n opacity: 0.8;\n transform: scale(1.02);\n }\n\n .combined-market-widget .combined-symbol:hover::after {\n content: "✎";\n position: absolute;\n top: -8px;\n right: -8px;\n background: #3b82f6;\n color: white;\n font-size: 10px;\n padding: 2px 4px;\n border-radius: 4px;\n opacity: 0.8;\n pointer-events: none;\n }\n\n .combined-market-widget .follow-btn {\n background: #ffffff;\n border: 1px solid #d1d5db;\n color: #374151;\n padding: 8px 16px;\n border-radius: 20px;\n cursor: pointer;\n font-size: 14px;\n font-weight: 500;\n transition: all 0.2s;\n }\n\n .combined-market-widget .follow-btn:hover {\n border-color: #9ca3af;\n background: #f9fafb;\n }\n\n .combined-market-widget .combined-data-container {\n display: grid;\n grid-template-columns: 1fr 1fr;\n gap: 40px;\n }\n\n .combined-market-widget .combined-market-section {\n display: flex;\n flex-direction: column;\n gap: 8px;\n }\n\n .combined-market-widget .combined-price-info {\n display: flex;\n flex-direction: column;\n min-height: 90px;\n }\n\n .combined-market-widget .session-label {\n display: flex;\n align-items: center;\n gap: 6px;\n font-size: 14px;\n color: #6b7280;\n margin-bottom: 4px;\n font-weight: 500;\n }\n\n .combined-market-widget .session-label .icon {\n font-size: 16px;\n }\n\n .combined-market-widget .combined-current-price {\n font-size: 48px;\n font-weight: 700;\n line-height: 1;\n color: #111827;\n }\n\n .combined-market-widget .combined-price-change {\n display: flex;\n gap: 8px;\n font-size: 20px;\n font-weight: 600;\n margin-top: 4px;\n }\n\n .combined-market-widget .combined-price-change.positive {\n color: #059669;\n }\n\n .combined-market-widget .combined-price-change.negative {\n color: #dc2626;\n }\n\n .combined-market-widget .combined-price-change.neutral {\n color: #6b7280;\n }\n\n .combined-market-widget .combined-market-status {\n font-size: 14px;\n color: #6b7280;\n margin-top: 8px;\n }\n\n .combined-market-widget .combined-timestamp {\n color: #9ca3af;\n font-weight: 400;\n }\n\n /* Loading overlay */\n .combined-market-widget .combined-loading-overlay {\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background: rgba(255, 255, 255, 0.95);\n backdrop-filter: blur(2px);\n display: flex;\n align-items: center;\n justify-content: center;\n border-radius: 12px;\n z-index: 10;\n }\n\n .combined-market-widget .combined-loading-overlay.hidden {\n display: none;\n }\n\n .combined-market-widget .combined-loading-content {\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: 12px;\n }\n\n .combined-market-widget .combined-loading-spinner {\n width: 40px;\n height: 40px;\n border: 3px solid #e5e7eb;\n border-top-color: #3b82f6;\n border-radius: 50%;\n animation: combined-market-spin 1s linear infinite;\n }\n\n .combined-market-widget .combined-loading-text {\n color: #6b7280;\n font-size: 14px;\n font-weight: 500;\n }\n\n @keyframes combined-market-spin {\n to { transform: rotate(360deg); }\n }\n\n /* Responsive */\n @media (max-width: 768px) {\n .combined-market-widget .combined-data-container {\n grid-template-columns: 1fr;\n gap: 30px;\n }\n\n .combined-market-widget .combined-current-price {\n font-size: 36px;\n }\n\n .combined-market-widget .combined-price-change {\n font-size: 16px;\n }\n }\n',document.head.appendChild(t)}}initializeSymbolEditor(){this.symbolEditor=new s(this,{maxLength:10,placeholder:"Enter symbol...",onSymbolChange:this.handleSymbolChange.bind(this),debug:this.debug,autoUppercase:!0,symbolType:"quotel1"});const t=this.container.querySelector(".combined-symbol");t&&(t.textContent=this.symbol,t.dataset.originalSymbol=this.symbol)}async handleSymbolChange(t){this.debug&&console.log("[CombinedMarketWidget] Symbol change requested:",t);const e=g(t);if(!e.valid)return this.debug&&console.log("[CombinedMarketWidget] Invalid symbol:",e.error),{success:!1,error:e.error};const n=e.sanitized;if(n===this.symbol)return this.debug&&console.log("[CombinedMarketWidget] Same symbol, no change needed"),{success:!0};try{const t=this.symbol;return this.showLoading(),this.unsubscribeMarket&&(this.debug&&console.log(`[CombinedMarketWidget] Unsubscribing from market data: ${t}`),this.wsManager.sendUnsubscribe("queryl1",t),this.unsubscribeMarket(),this.unsubscribeMarket=null),this.unsubscribeNight&&(this.debug&&console.log(`[CombinedMarketWidget] Unsubscribing from night session: ${t}`),this.wsManager.sendUnsubscribe("queryblueoceanl1",t),this.unsubscribeNight(),this.unsubscribeNight=null),this.symbol=n,this.marketData=null,this.nightSessionData=null,this.debug&&console.log(`[CombinedMarketWidget] Subscribing to new symbol: ${n}`),this.subscribeToData(),this.debug&&console.log(`[CombinedMarketWidget] Successfully changed symbol from ${t} to ${n}`),{success:!0}}catch(t){return console.error("[CombinedMarketWidget] Error changing symbol:",t),this.hideLoading(),{success:!1,error:`Failed to load ${n}`}}}subscribeToData(){this.showLoading(),this.unsubscribeMarket=this.wsManager.subscribe(`${this.widgetId}-market`,["queryl1"],(t=>{const{event:e,data:n}=t;"connection"!==e?"data"===e&&(n._dataType="market",this.handleMessage({event:e,data:n})):this.handleConnectionStatus(n)}),this.symbol),this.unsubscribeNight=this.wsManager.subscribe(`${this.widgetId}-night`,["queryblueoceanl1"],(t=>{const{event:e,data:n}=t;"connection"!==e&&"data"===e&&(n._dataType="night",this.handleMessage({event:e,data:n}))}),this.symbol)}handleData(t){const e=t._dataType;if(this.debug&&console.log(`[CombinedMarketWidget] handleData called with type: ${e}`,t),e){if("error"===t.type&&t.noData)return this.debug&&console.log(`[CombinedMarketWidget] Received no data message for ${e}:`,t.message),"market"!==e||this.marketData?"night"!==e||this.nightSessionData||this.debug&&console.log("[CombinedMarketWidget] No night session data available"):this.debug&&console.log("[CombinedMarketWidget] No market data available"),void this.hideLoading();if("error"===t.type){const n=t.message||"Server error";return this.debug&&console.log(`[CombinedMarketWidget] Error received for ${e}:`,n),void this.hideLoading()}if("object"==typeof t&&t.Message){const n=t.Message.toLowerCase();if(n.includes("no data")||n.includes("not found"))return this.debug&&console.log(`[CombinedMarketWidget] No data message for ${e}:`,t.Message),void this.hideLoading()}if("market"===e){if(t.Data&&Array.isArray(t.Data)){const e=t.Data.find((t=>t.Symbol===this.symbol));e?(this.debug&&console.log("[CombinedMarketWidget] Market data received:",e),this.marketData=new i(e),this.updateMarketSection(),this.hideLoading()):(this.debug&&console.log("[CombinedMarketWidget] No market data for symbol in response, keeping cached data"),this.hideLoading())}delete t._dataType}if("night"===e){if(Array.isArray(t)){const e=t.find((t=>t.Symbol===this.symbol));e?!0!==e.NotFound&&e.MarketName&&"BLUE"===e.MarketName?(this.debug&&console.log("[CombinedMarketWidget] Night session data received:",e),this.nightSessionData=new y(e),this.updateNightSessionSection(),this.hideLoading()):(this.debug&&console.log("[CombinedMarketWidget] Night session data not found or not available"),this.hideLoading()):(this.debug&&console.log("[CombinedMarketWidget] No night session data for symbol in response, keeping cached data"),this.hideLoading())}else"queryblueoceanl1"!==t.type&&"querybrucel1"!==t.type||(t[0]?.Symbol===this.symbol?!0!==t[0].NotFound&&t[0].MarketName&&"BLUE"===t[0].MarketName?(this.debug&&console.log("[CombinedMarketWidget] Night session data received (wrapped format):",t[0]),this.nightSessionData=new y(t[0]),this.updateNightSessionSection(),this.hideLoading()):(this.debug&&console.log("[CombinedMarketWidget] Night session data not found or not available (wrapped format)"),this.hideLoading()):(this.debug&&console.log("[CombinedMarketWidget] No matching symbol in wrapped response, keeping cached data"),this.hideLoading()));delete t._dataType}t._cached&&this.showConnectionQuality()}else this.debug&&console.warn("[CombinedMarketWidget] No data type specified, attempting to infer from structure")}updateMarketSection(){if(!this.marketData)return;const t=this.container.querySelector(".regular-market"),e=this.container.querySelector(".company-name");if(e){const t=this.marketData.companyName||`${this.marketData.symbol} Inc.`,n=this.marketData.companyDescription||`${this.marketData.symbol}`;e.textContent=t,e.setAttribute("title",n),e.setAttribute("data-tooltip",n)}t.querySelector(".combined-current-price").textContent=this.marketData.formatPrice();const n=t.querySelector(".combined-price-change"),i=t.querySelector(".combined-change-value"),s=t.querySelector(".combined-change-percent"),o=this.marketData.change,a=o>0?"positive":o<0?"negative":"neutral";n.className=`combined-price-change ${a}`,i.textContent=this.marketData.formatPriceChange(),s.textContent=`(${this.marketData.formatPriceChangePercent()})`;const r=t.querySelector(".market-status-label");r&&(r.textContent=`${this.getSessionType()}:`);t.querySelector(".combined-timestamp").textContent=f(this.marketData.quoteTime,{format:"long"}),this.debug&&console.log("[CombinedMarketWidget] Updated market section:",this.marketData)}updateNightSessionSection(){if(!this.nightSessionData)return;const t=this.container.querySelector(".night-session");if(this.removeNightSession&&!this.isNightSessionActive())return t.style.display="none",void(this.debug&&console.log("[CombinedMarketWidget] Night session hidden (market closed)"));t.style.display="";const e=t.querySelector(".combined-current-price");e&&(e.textContent=this.nightSessionData.lastPrice?this.nightSessionData.formatPrice():"--");const n=t.querySelector(".combined-price-change"),i=t.querySelector(".combined-change-value"),s=t.querySelector(".combined-change-percent"),o=this.nightSessionData.change,a=o>0?"positive":o<0?"negative":"neutral";n.className=`combined-price-change ${a}`,i.textContent=null!==this.nightSessionData.change?this.nightSessionData.formatPriceChange():"--",s.textContent=`(${this.nightSessionData.formatPriceChangePercent()})`;t.querySelector(".combined-timestamp").textContent=f(this.nightSessionData.quoteTime,{format:"long"}),this.debug&&(console.log("connection quality:",this.connectionQuality),console.log("[CombinedMarketWidget] Updated night session section:",this.nightSessionData))}getSessionType(){const t=(new Date).toLocaleString("en-US",{timeZone:"America/New_York"}),e=new Date(t),n=e.getHours(),i=e.getMinutes(),s=60*n+i;return console.log("Current EST time:",n+":"+(i<10?"0":"")+i),s>=240&&s<570?"Pre-Market":s>=570&&s<960?"Market Hours":s>=960&&s<1200?"Post-Market":"Market Closed"}isNightSessionActive(){return"Market Closed"===this.getSessionType()}destroy(){this.unsubscribeMarket&&(this.unsubscribeMarket(),this.unsubscribeMarket=null),this.unsubscribeNight&&(this.unsubscribeNight(),this.unsubscribeNight=null),this.symbolEditor&&(this.symbolEditor.destroy(),this.symbolEditor=null),super.destroy()}}class D{constructor(t){Array.isArray(t)?(console.log("[IntradayChartModel] Processing",t.length,"raw data points"),t.length>0&&console.log("[IntradayChartModel] Sample raw point:",t[0]),this.dataPoints=t.map(((t,e)=>{const n={symbol:t.symbol||t.Symbol,time:t.time||t.Time||t.timestamp||t.Timestamp,open:parseFloat(t.open||t.Open)||0,high:parseFloat(t.high||t.High)||0,low:parseFloat(t.low||t.Low)||0,close:parseFloat(t.close||t.Close)||0,volume:parseInt(t.volume||t.Volume)||0,source:t.source||t.Source};return e<2&&console.log(`[IntradayChartModel] Processed point ${e}:`,n),n.time||console.warn(`[IntradayChartModel] Point ${e} missing time:`,t),0===n.close&&console.warn(`[IntradayChartModel] Point ${e} has zero close price:`,t),n})).filter((t=>{if(!t.time||t.close<=0)return!1;const e=new Date(t.time).getTime();return!(isNaN(e)||e<9466848e5)||(console.warn("[IntradayChartModel] Invalid timestamp:",t.time),!1)})),this.dataPoints.sort(((t,e)=>new Date(t.time).getTime()-new Date(e.time).getTime())),console.log("[IntradayChartModel] Valid data points after filtering:",this.dataPoints.length),this.dataPoints.length>0&&console.log("[IntradayChartModel] Time range:",this.dataPoints[0].time,"to",this.dataPoints[this.dataPoints.length-1].time)):(console.warn("[IntradayChartModel] Expected array of data points, got:",typeof t),this.dataPoints=[]),this.symbol=this.dataPoints.length>0?this.dataPoints[0].symbol:null,this.source=this.dataPoints.length>0?this.dataPoints[0].source:null}getTimeLabels(){return this.dataPoints.map((t=>{const e=new Date(t.time);let n=e.getHours();const i=n>=12?"PM":"AM";n%=12,n=n||12;return[`${n}:${e.getMinutes().toString().padStart(2,"0")} ${i}`,`${(e.getMonth()+1).toString().padStart(2,"0")}/${e.getDate().toString().padStart(2,"0")}`]}))}getOHLCData(){return this.dataPoints.map((t=>({x:new Date(t.time).getTime(),o:t.open,h:t.high,l:t.low,c:t.close})))}getClosePrices(){return this.dataPoints.map((t=>t.close))}getVolumeData(){return this.dataPoints.map((t=>t.volume))}getHighPrices(){return this.dataPoints.map((t=>t.high))}getLowPrices(){return this.dataPoints.map((t=>t.low))}getOpenPrices(){return this.dataPoints.map((t=>t.open))}getStats(){if(0===this.dataPoints.length)return{high:0,low:0,open:0,close:0,change:0,changePercent:0,volume:0};this.getClosePrices();const t=this.getHighPrices(),e=this.getLowPrices(),n=this.getVolumeData(),i=this.dataPoints[0],s=this.dataPoints[this.dataPoints.length-1],o=s.close-i.open,a=0!==i.open?o/i.open*100:0;return{high:Math.max(...t),low:Math.min(...e),open:i.open,close:s.close,change:o,changePercent:a,volume:n.reduce(((t,e)=>t+e),0),dataPoints:this.dataPoints.length}}formatPrice(t){return t.toFixed(2)}formatVolume(t){return t>=1e6?(t/1e6).toFixed(2)+"M":t>=1e3?(t/1e3).toFixed(2)+"K":t.toString()}}
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).MdasSDK={})}(this,(function(t){"use strict";class e{constructor(){this.state=new Map,this.listeners=new Map}setState(t,e){this.state.set(t,e),this.notifyListeners(t,e)}getState(t){return this.state.get(t)}subscribe(t,e){return this.listeners.has(t)||this.listeners.set(t,new Set),this.listeners.get(t).add(e),()=>{const n=this.listeners.get(t);n&&n.delete(e)}}notifyListeners(t,e){const n=this.listeners.get(t);n&&n.forEach((t=>t(e)))}clear(){this.state.clear(),this.listeners.clear()}}class n{constructor(t,e,n){this.setContainer(t),this.options=e,this.widgetId=n,this.isDestroyed=!1,this.lastData=null,this.lastDataTimestamp=null,this.connectionQuality="disconnected",this.eventListeners=[],this.timeouts=[],this.intervals=[]}setContainer(t){if(!t)throw new Error("DOM element is required for widget");if("string"==typeof t){const e=document.querySelector(t);if(!e)throw new Error(`Element not found: ${t}`);this.container=e}else{if(t.nodeType!==Node.ELEMENT_NODE)throw new Error("Invalid element provided to widget");this.container=t}}showLoading(){const t=this.container.querySelector(".widget-loading-overlay");t&&t.classList.remove("hidden")}hideLoading(){const t=this.container.querySelector(".widget-loading-overlay");t&&t.classList.add("hidden")}showError(t){this.hideLoading(),this.clearError();const e=document.createElement("div");e.className="widget-error",e.textContent=`Error: ${t}`,this.container.appendChild(e)}clearError(){const t=this.container.querySelector(".widget-error");t&&t.remove()}showConnectionQuality(){const t=this.container.querySelector(".connection-quality");if(t&&t.remove(),"live"===this.connectionQuality)return;const e=this.container.querySelector('.last-update, [class*="last-update"], [class*="timestamp"]');if(e){const t=document.createElement("span");switch(t.className="connection-quality",this.connectionQuality){case"offline":t.textContent=" (disconnected)",t.style.color="#dc2626",t.style.fontWeight="500";break;case"reconnecting":t.textContent=" (reconnecting...)",t.style.color="#d97706"}t.style.fontSize="11px",e.appendChild(t)}}handleMessage(t){if(!this.isDestroyed)try{const{event:e,data:n}=t;if(console.log("[BaseWidget] handleMessage called with event:",e,"data:",n),this.debug&&console.log(`[${this.type}] Received:`,e,n),"connection"===e)return void this.handleConnectionStatus(n);if("data"===e)return console.log("[BaseWidget] Caching live data"),this.lastData=n,this.lastDataTimestamp=Date.now(),this.connectionQuality="live",void this.handleData(n);if("session_revoked"===e)return void this.handleSessionRevoked(n);this.handleCustomEvent&&this.handleCustomEvent(e,n)}catch(t){console.error(`[${this.constructor.name}] Error handling message:`,t),this.showError("Error processing data")}}handleSessionRevoked(t){"attempting_relogin"===t.status?(this.connectionQuality="reconnecting",this.lastData?this.showCachedData():this.showLoading()):"relogin_failed"===t.status?(this.connectionQuality="offline",this.showError(t.error||"Session expired. Please refresh the page.")):"relogin_successful"===t.status&&(this.connectionQuality="live",this.hideLoading(),this.clearError())}handleData(t){throw new Error("handleData must be implemented by child widget")}handleConnectionStatus(t){"connected"===t.status?(this.connectionQuality="live",this.clearError(),this.hideLoading()):"reconnecting"===t.status?(this.connectionQuality="reconnecting",this.lastData?this.showCachedData():this.showLoading()):"disconnected"===t.status?(this.connectionQuality="offline",this.lastData?this.showCachedData():this.hideLoading()):"failed"===t.status?(this.connectionQuality="offline",this.handleConnectionFailed(t),this.showConnectionQuality()):"error"===t.status&&(this.connectionQuality="offline",this.lastData?this.showCachedData():this.hideLoading())}showCachedData(){if(this.lastData&&this.lastDataTimestamp){const t=Date.now()-this.lastDataTimestamp,e=t>3e5,n={...this.lastData,_cached:!0,_cacheAge:t,_isStale:e,_quality:this.connectionQuality};this.handleData(n)}}addEventListener(t,e,n){let i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};t&&e&&n?(t.addEventListener(e,n,i),this.eventListeners.push({element:t,event:e,handler:n,options:i})):console.warn("[BaseWidget] Invalid addEventListener parameters")}setTimeout(t,e){const n=setTimeout(t,e);return this.timeouts.push(n),n}setInterval(t,e){const n=setInterval(t,e);return this.intervals.push(n),n}clearTimeout(t){clearTimeout(t);const e=this.timeouts.indexOf(t);e>-1&&this.timeouts.splice(e,1)}clearInterval(t){clearInterval(t);const e=this.intervals.indexOf(t);e>-1&&this.intervals.splice(e,1)}showInputError(t,e){if(!t)return;this.clearInputError(t);const n=document.createElement("div");n.className="input-error-message",n.textContent=e,n.style.cssText="\n color: #dc2626;\n font-size: 12px;\n margin-top: 4px;\n animation: slideDown 0.2s ease-out;\n ",t.classList.add("input-error"),t.style.borderColor="#dc2626",t.parentNode&&t.parentNode.insertBefore(n,t.nextSibling),t.errorElement=n}clearInputError(t){t&&(t.errorElement&&(t.errorElement.remove(),t.errorElement=null),t.classList.remove("input-error"),t.style.borderColor="")}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.eventListeners.forEach((t=>{let{element:e,event:n,handler:i,options:s}=t;try{e.removeEventListener(n,i,s)}catch(t){console.error("[BaseWidget] Error removing event listener:",t)}})),this.eventListeners=[],this.timeouts.forEach((t=>{clearTimeout(t)})),this.timeouts=[],this.intervals.forEach((t=>{clearInterval(t)})),this.intervals=[],this.lastData=null,this.container&&(this.container.innerHTML=""),this.debug&&console.log(`[${this.constructor.name}] Widget destroyed and cleaned up`))}handleConnectionFailed(t){this.connectionQuality="offline",this.lastData?(this.showCachedData(),this.hideLoading()):this.hideLoading(),this.debug&&console.log(`[${this.constructor.name}] Connection failed after ${t.maxAttempts} attempts`)}}class i{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.symbol=t.Symbol||"",this.companyName=t.CompName||"",this.companyDescription=t.CompDesc||"",this.instrumentType=t.InstrType||"",this.lastPrice=t.LastPx||0,this.previousClose=t.YestClosePx||0,this.open=t.OpenPx||0,this.high=t.HighPx||0,this.low=t.LowPx||0,this.close=t.ClosingPx||0,this.change=t.Change||0,this.changePercent=t.ChangePercent||0,this.vwap=t.VWAP||0,this.volume=t.Volume||0,this.averageVolume=t.AvgVol30d||0,this.yesterdayVolume=t.YesterdayTradeVolume||0,this.bidPrice=t.BidPx||0,this.bidSize=t.BidSz||0,this.bidExchange=t.BidExch||"",this.askPrice=t.AskPx||0,this.askSize=t.AskSz||0,this.askExchange=t.AskExch||"",this.issueMarket=t.IssueMarket||"",this.marketName=t.MarketName||"",this.marketDescription=t.MarketDesc||"",this.mic=t.MIC||"",this.countryCode=t.CountryCode||"",this.timeZone=t.TimeZone||"",this.tradePrice=t.TradePx||0,this.tradeSize=t.TradeSz||0,this.tradeCondition=t.Condition||0,this.tradeTime=t.TradeTime||"",this.tradeRegion=t.TradeRegion||"",this.tradeRegionName=t.TradeRegionName||"",this.preMarketPrice=t.PreLastPx||0,this.preMarketTradeTime=t.PreTradeTime||"",this.postMarketPrice=t.PostLastPx||0,this.postMarketTradeTime=t.PostTradeTime||"",this.high52Week=t.High52wPx||0,this.low52Week=t.Low52wPx||0,this.high52WeekDate=t.High52wDate||"",this.low52WeekDate=t.Low52wDate||"",this.calendarYearHigh=t.CalendarYearHigh||0,this.calendarYearLow=t.CalendarYearLow||0,this.calendarYearHighDate=t.CalendarYearHighDate||"",this.calendarYearLowDate=t.CalendarYearLowDate||"",this.marketCap=t.MktCap||0,this.peRatio=t.PeRatio||0,this.beta=t.FundBeta||0,this.sharesOutstanding=t.ComShrsOut||0,this.dividendYield=t.DivYield||0,this.dividendAmount=t.DivAmt||0,this.dividendRate=t.DividendRate||0,this.dividendPaymentDate=t.DividendPaymentDate||t.PayDate||"",this.dividendExDate=t.DividendExDate||t.DivDateEx||"",this.isin=t.ISIN||"",this.cusip=t.CUSIP||"",this.sedol=t.SEDOL||"",this.gics=t.GICS||"",this.status=t.Status||"",this.dataSource=t.DataSource||"",this.quoteTime=t.QuoteTime||"",this.infoTime=t.InfoTime||""}get openPrice(){return this.open}get description(){return this.companyDescription}get lastUpdate(){return this.quoteTime||this.infoTime}getSecurityType(){return{257:"Stock",262:"ETF",261:"Mutual Fund",258:"Bond",260:"Option",263:"Future",259:"Index"}[this.instrumentType]||"Stock"}getPriceChange(){return this.change}getPriceChangePercent(){return 100*this.changePercent}getDataSource(){return"delay"===this.dataSource.toLowerCase()?"20 mins delayed":"real-time"===this.dataSource.toLowerCase()?"Real-time":null!==this.dataSource&&""!==this.dataSource?this.dataSource:"MDAS Server"}getCurrentPrice(){return this.lastPrice}get52WeekRange(){return`${this.low52Week.toFixed(2)} - ${this.high52Week.toFixed(2)}`}getMarketCapFormatted(){return this.formatMarketCap()}formatPrice(){return`$${(arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.lastPrice).toFixed(2)}`}formatPriceChange(){const t=this.getPriceChange();return`${t>=0?"+":""} ${t.toFixed(2)}`}formatPriceChangePercent(){const t=this.getPriceChangePercent();return`${t>=0?"+":""}${t.toFixed(2)}%`}formatBidAsk(){return`$${this.bidPrice.toFixed(2)} x ${this.bidSize} / $${this.askPrice.toFixed(2)} x ${this.askSize}`}formatVolume(){return 0===this.volume?"N/A":this.volume.toLocaleString()}formatAvgVolume(){return 0===this.averageVolume?"N/A":this.averageVolume.toLocaleString()}formatAverageVolume(){return 0===this.averageVolume?"N/A":this.averageVolume.toLocaleString()}formatDayRange(){return 0===this.low&&0===this.high?"N/A":`$${this.low.toFixed(2)} - $${this.high.toFixed(2)}`}format52WeekRange(){return 0===this.low52Week&&0===this.high52Week?"N/A":`${this.low52Week.toFixed(2)} - ${this.high52Week.toFixed(2)}`}formatMarketCap(){if(0===this.marketCap)return"N/A";const t=1e6*this.marketCap;return t>=1e12?`$${(t/1e12).toFixed(2)}T`:t>=1e9?`$${(t/1e9).toFixed(2)}B`:t>=1e6?`$${(t/1e6).toFixed(2)}M`:t>=1e3?`$${(t/1e3).toFixed(2)}K`:`$${t.toFixed(2)}`}formatAvg30DayVolume(){return this.formatAverageVolume()}static fromApiResponse(t){return new i(t)}}class s{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.widget=t,this.options={maxLength:e.maxLength||10,placeholder:e.placeholder||"Enter symbol...",onSymbolChange:e.onSymbolChange||(()=>{}),debug:e.debug||!1,autoUppercase:!1!==e.autoUppercase,...e},this.symbolType=e.symbolType||null,this.apiService=this.widget.wsManager.getApiService(),this.isEditing=!1,this.isValidating=!1,this.originalSymbol="",this.elements={},this.addStyles(),this.initialize()}initialize(){this.setupElements(),this.attachEventListeners()}setupElements(){if(this.elements.symbolDisplay=this.widget.container.querySelector(".editable-symbol"),!this.elements.symbolDisplay)throw new Error('No element with class "editable-symbol" found in widget');this.originalSymbol=this.elements.symbolDisplay.textContent.trim(),this.elements.symbolDisplay.dataset.originalSymbol=this.originalSymbol}attachEventListeners(){this.startEditing=this.startEditing.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.handleInput=this.handleInput.bind(this),this.handleBlur=this.handleBlur.bind(this),this.handleClickOutside=this.handleClickOutside.bind(this),this.elements.symbolDisplay.addEventListener("dblclick",this.startEditing)}startEditing(){this.isEditing||this.isValidating||(this.isEditing=!0,this.originalSymbol=this.elements.symbolDisplay.textContent.trim(),this.options.debug&&(console.log(this.widget.connectionQuality),console.log("[SymbolEditor] Starting edit mode for:",this.originalSymbol)),this.transformToInput())}transformToInput(){const t=this.elements.symbolDisplay,e=window.getComputedStyle(t),n=document.createElement("div");n.className="symbol-edit-container",n.style.display="inline-flex",n.style.alignItems="center",n.style.gap="8px",n.style.verticalAlign="baseline";const i=document.createElement("input");i.type="text",i.value=this.originalSymbol,i.className=t.className+" symbol-input-mode",i.style.fontSize=e.fontSize,i.style.fontWeight=e.fontWeight,i.style.fontFamily=e.fontFamily,i.style.color=e.color,i.style.backgroundColor="transparent",i.style.border="2px solid #3b82f6",i.style.borderRadius="4px",i.style.padding="2px 6px",i.style.margin="0",i.style.outline="none",i.style.width="auto",i.style.minWidth="120px",i.style.maxWidth="200px",i.style.flexShrink="0";const s=document.createElement("button");s.className="symbol-save-btn",s.innerHTML="✓",s.title="Save symbol",s.style.width="28px",s.style.height="28px",s.style.border="none",s.style.borderRadius="4px",s.style.backgroundColor="#059669",s.style.color="white",s.style.cursor="pointer",s.style.fontSize="12px",s.style.display="inline-flex",s.style.alignItems="center",s.style.justifyContent="center",s.style.flexShrink="0",n.appendChild(i),n.appendChild(s),t.style.display="none",t.parentNode.insertBefore(n,t.nextSibling),this.elements.symbolInput=i,this.elements.saveBtn=s,this.elements.editContainer=n,i.focus(),i.select(),i.addEventListener("keydown",this.handleKeydown),i.addEventListener("input",this.handleInput),i.addEventListener("blur",this.handleBlur),document.addEventListener("click",this.handleClickOutside),s.addEventListener("click",(t=>{t.stopPropagation(),this.saveSymbol()}))}async saveSymbol(){if(this.isValidating)return;const t=this.elements.symbolInput.value.trim(),e=await this.validateSymbol(t);if(!e.isValid)return this.showError(e.message),void setTimeout((()=>{this.elements.symbolInput&&(this.elements.symbolInput.value=this.originalSymbol,this.clearError(),this.cancelEditing())}),2e3);this.setLoadingState(!0);try{const n=await this.options.onSymbolChange(t,this.originalSymbol,e.data);if(n&&n.success)this.finishEditing(t),this.showSuccess("Symbol updated successfully");else{const t=n?.message||"Failed to update symbol";this.showError(t)}}catch(t){console.error("[SymbolEditor] Error changing symbol:",t),this.showError("Error updating symbol")}finally{this.setLoadingState(!1)}}cancelEditing(){this.options.debug&&console.log("[SymbolEditor] Cancelling edit mode"),this.finishEditing(this.originalSymbol)}finishEditing(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;this.isEditing=!1;const e=t||this.originalSymbol;this.elements.symbolDisplay.textContent=e,this.elements.symbolDisplay.dataset.originalSymbol=e,this.elements.symbolDisplay.style.display="",this.elements.editContainer&&(this.elements.editContainer.remove(),this.elements.editContainer=null),this.elements.symbolInput=null,this.elements.saveBtn=null,document.removeEventListener("click",this.handleClickOutside)}handleKeydown(t){"Enter"===t.key?(t.preventDefault(),this.saveSymbol()):"Escape"===t.key&&(t.preventDefault(),this.cancelEditing())}handleInput(t){if(this.options.autoUppercase){const e=t.target,n=e.selectionStart,i=e.selectionEnd;e.value=e.value.toUpperCase(),e.setSelectionRange(n,i)}this.clearError()}handleBlur(t){t.relatedTarget&&t.relatedTarget===this.elements.saveBtn||setTimeout((()=>{this.isEditing&&this.cancelEditing()}),150)}handleClickOutside(t){if(!this.isEditing)return;this.elements.symbolInput?.contains(t.target)||this.elements.saveBtn?.contains(t.target)||this.cancelEditing()}async validateSymbol(t){if("live"!==this.widget.connectionQuality)return{isValid:!1,message:"Not connected to data service"};if(!t||0===t.trim().length)return{isValid:!1,message:"Symbol cannot be empty"};const e=t.trim().toUpperCase();try{if("optionsl1"==this.symbolType){const t=await this.apiService.quoteOptionl1(e);return t[0]&&(t[0].error||1==t[0].not_found)?1==t[0].not_found?{isValid:!1,message:"Symbol not found"}:{isValid:!1,message:t[0].error}:{isValid:!0,data:t[0]}}if("quotel1"==this.symbolType||"nightsession"==this.symbolType){const t=await this.apiService.quotel1(e);return t&&t.message?t.message.includes("no data")?{isValid:!1,message:"Symbol not found"}:{isValid:!1,message:t.message}:{isValid:!0,data:t.data[0]}}if("nightsession"==this.symbolType){const t=await this.apiService.quoteBlueOcean(e);return t[0]&&1==t[0].not_found?{isValid:!1,message:"Symbol not found"}:t[0]&&0==t[0].not_found?{isValid:!0,data:t[0]}:{isValid:!1,message:t[0].error}}}catch(t){return console.warn("[SymbolEditor] API validation failed, falling back to basic validation:",t),this.defaultValidator(e)}return this.defaultValidator(e)}defaultValidator(t){return t&&0!==t.length?t.length>this.options.maxLength?{isValid:!1,message:`Symbol too long (max ${this.options.maxLength} chars)`}:{isValid:!0,data:null}:{isValid:!1,message:"Symbol cannot be empty"}}setLoadingState(t){this.isValidating=t,this.elements.saveBtn&&(t?(this.elements.saveBtn.innerHTML='<div class="loading-spinner"></div>',this.elements.saveBtn.disabled=!0):(this.elements.saveBtn.innerHTML="✓",this.elements.saveBtn.disabled=!1)),this.elements.symbolInput&&(this.elements.symbolInput.disabled=t)}showError(t){if(this.elements.symbolInput){this.elements.symbolInput.style.borderColor="#dc2626",this.elements.symbolInput.style.boxShadow="0 0 0 3px rgba(220, 38, 38, 0.1)",this.removeErrorMessage();const e=document.createElement("div");e.className="symbol-error-message",e.textContent=t,e.style.cssText="\n color: #dc2626;\n font-size: 12px;\n margin-bottom: 2px;\n position: absolute;\n background: white;\n z-index: 1000;\n transform: translateY(-100%);\n top: -4px;\n left: 0; // Align with input box\n ";const n=this.elements.editContainer;n&&(n.style.position="relative",n.appendChild(e)),this.elements.errorMessage=e,this.elements.symbolInput.focus()}}removeErrorMessage(){this.elements.errorMessage&&(this.elements.errorMessage.remove(),this.elements.errorMessage=null)}clearError(){this.elements.symbolInput&&(this.elements.symbolInput.style.borderColor="#3b82f6",this.elements.symbolInput.style.boxShadow="0 0 0 3px rgba(59, 130, 246, 0.1)",this.elements.symbolInput.title=""),this.removeErrorMessage()}showSuccess(t){this.options.debug&&console.log("[SymbolEditor] Success:",t)}updateSymbol(t){const e=this.options.autoUppercase?t.toUpperCase():t;this.elements.symbolDisplay.textContent=e,this.elements.symbolDisplay.dataset.originalSymbol=e,this.options.debug&&console.log("[SymbolEditor] Symbol updated externally:",e)}destroy(){this.finishEditing(),this.elements.symbolDisplay?.removeEventListener("dblclick",this.startEditing)}addStyles(){if(document.querySelector("#symbol-editor-styles"))return;const t=document.createElement("style");t.id="symbol-editor-styles",t.textContent='\n .editable-symbol {\n cursor: pointer;\n transition: all 0.2s ease;\n position: relative;\n }\n\n .editable-symbol:hover {\n opacity: 0.8;\n transform: scale(1.02);\n }\n\n .editable-symbol:hover::after {\n content: "✎";\n position: absolute;\n top: -8px;\n right: -8px;\n background: #3b82f6;\n color: white;\n font-size: 10px;\n padding: 2px 4px;\n border-radius: 4px;\n opacity: 0.8;\n pointer-events: none;\n }\n\n .symbol-input-mode {\n text-transform: uppercase;\n }\n\n .symbol-save-btn:hover {\n background-color: #047857 !important;\n transform: scale(1.05);\n }\n\n .symbol-save-btn:disabled {\n background-color: #9ca3af !important;\n cursor: not-allowed !important;\n transform: none !important;\n }\n\n .loading-spinner {\n width: 12px;\n height: 12px;\n border: 2px solid rgba(255, 255, 255, 0.3);\n border-top-color: white;\n border-radius: 50%;\n animation: spin 1s linear infinite;\n }\n\n @keyframes spin {\n to { transform: rotate(360deg); }\n }\n ',document.head.appendChild(t)}}const o='\n /* ========================================\n FONT SIZE SYSTEM - CSS Variables\n Adjust --mdas-base-font-size to scale all fonts\n ======================================== */\n :root {\n /* Base font size - change this to scale everything */\n --mdas-base-font-size: 14px;\n\n /* Relative font sizes (in em, scales with base) */\n --mdas-company-name-size: 1.43em; /* 20px at base 14px */\n --mdas-symbol-size: 1.79em; /* 25px at base 14px */\n --mdas-price-size: 2.29em; /* 32px at base 14px */\n --mdas-price-change-size: 1.14em; /* 16px at base 14px */\n --mdas-section-title-size: 1em; /* 14px at base 14px */\n --mdas-data-label-size: 0.93em; /* 13px at base 14px */\n --mdas-data-value-size: 1em; /* 14px at base 14px */\n --mdas-bid-ask-size: 1.07em; /* 15px at base 14px */\n --mdas-small-text-size: 0.86em; /* 12px at base 14px */\n --mdas-badge-size: 0.86em; /* 12px at base 14px */\n --mdas-loading-text-size: 1.14em; /* 16px at base 14px */\n --mdas-no-data-title-size: 1.14em; /* 16px at base 14px */\n --mdas-edit-icon-size: 0.71em; /* 10px at base 14px */\n }\n\n /* Apply base font size to widgets */\n .widget {\n font-size: var(--mdas-base-font-size);\n }\n\n /* ========================================\n OPTIONAL CARD STYLING\n Add \'widget-styled\' class for card design\n ======================================== */\n .widget-styled {\n background: white;\n border-radius: 12px;\n padding: 24px;\n box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);\n border: 1px solid #e5e7eb;\n }\n\n /* Base widget styles */\n .widget-loading-overlay {\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background: rgba(255, 255, 255, 0.95);\n backdrop-filter: blur(2px);\n display: flex;\n align-items: center;\n justify-content: center;\n z-index: 10;\n border-radius: 12px;\n }\n\n .widget-loading-overlay.hidden {\n display: none;\n }\n\n .widget {\n font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, sans-serif;\n width: 100%;\n max-width: 1400px;\n }\n\n /* HEADER STYLES */\n\n .widget-header {\n display: flex;\n justify-content: space-between;\n align-items: flex-start;\n margin-bottom: 20px;\n gap: 16px;\n }\n\n .symbol-section {\n display: flex;\n flex-direction: column;\n gap: 4px;\n }\n\n .night-company-name {\n font-size: var(--mdas-company-name-size);\n font-weight: 500;\n color: #111827;\n cursor: pointer;\n transition: all 0.2s ease;\n position: relative;\n }\n\n .symbol {\n font-size: var(--mdas-symbol-size);\n font-weight: 700;\n color: #111827;\n cursor: pointer;\n transition: all 0.2s ease;\n position: relative;\n }\n\n .symbol:hover {\n opacity: 0.8;\n transform: scale(1.02);\n }\n\n .symbol:hover::after {\n content: "✎";\n position: absolute;\n top: -8px;\n right: -8px;\n background: #3b82f6;\n color: white;\n font-size: var(--mdas-edit-icon-size);\n padding: 2px 4px;\n border-radius: 4px;\n opacity: 0.8;\n }\n\n .data-type {\n background:rgb(214, 228, 250);\n padding: 2px 8px;\n border-radius: 6px;\n font-size: var(--mdas-badge-size);\n font-weight: 500;\n color: #3b82f6;\n }\n\n .price-section {\n text-align: right;\n }\n\n .current-price {\n font-size: var(--mdas-price-size);\n font-weight: 700;\n color: #111827;\n line-height: 1;\n }\n\n .price-change {\n font-size: var(--mdas-price-change-size);\n font-weight: 600;\n margin-top: 4px;\n display: flex;\n align-items: center;\n justify-content: flex-end;\n gap: 4px;\n }\n\n .price-change.positive { \n color: #10b981; \n }\n\n .price-change.negative { \n color: #ef4444; \n }\n\n .price-change.neutral { \n color: #6b7280; \n }\n\n .market-data-widget .price-change.positive::before,\n .night-session-widget .price-change.positive::before,\n .options-widget .price-change.positive::before{\n content: "↗";\n }\n\n .market-data-widget .price-change.negative::before,\n .night-session-widget .price-change.negative::before,\n .options-widget .price-change.negative::before {\n content: "↘";\n }\n\n /* BODY SECTION STYLES */\n\n .data-grid {\n display: grid;\n grid-template-columns: 1fr 1fr;\n gap: 32px;\n margin-bottom: 24px;\n }\n\n .data-section {\n display: flex;\n flex-direction: column;\n gap: 16px;\n }\n\n .section-title {\n font-size: var(--mdas-section-title-size);\n font-weight: 600;\n color: #6b7280;\n margin: 0;\n text-transform: uppercase;\n letter-spacing: 0.5px;\n border-bottom: 1px solid #e5e7eb;\n padding-bottom: 8px;\n }\n\n .data-row {\n display: grid;\n grid-template-columns: 1fr 1fr;\n gap: 16px;\n }\n\n .data-item {\n display: flex;\n flex-direction: column;\n gap: 4px;\n }\n\n .price-metadata,\n .data-label {\n font-size: var(--mdas-data-label-size);\n color: #6b7280;\n font-weight: 500;\n }\n\n .data-value {\n font-size: var(--mdas-data-value-size);\n font-weight: 600;\n color: #111827;\n text-align: right;\n flex-shrink: 0;\n }\n\n\n /* Footer */\n .widget-footer {\n display: flex;\n justify-content: space-between;\n align-items: center;\n padding-top: 16px;\n border-top: 1px solid #e5e7eb;\n font-size: var(--mdas-small-text-size);\n color: #9ca3af;\n }\n \n\n /* LOADING STYLES */\n\n\n .loading-content {\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: 16px;\n }\n\n .loading-spinner {\n width: 40px;\n height: 40px;\n border: 4px solid #e5e7eb;\n border-top-color: #3b82f6;\n border-radius: 50%;\n animation: spin 1s linear infinite;\n }\n\n .loading-text {\n color: #6b7280;\n font-size: var(--mdas-loading-text-size);\n font-weight: 500;\n }\n\n @keyframes spin {\n to { transform: rotate(360deg); }\n }\n\n .widget-error {\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n background: #fef2f2;\n border: 1px solid #fecaca;\n border-radius: 8px;\n padding: 16px;\n color: #dc2626;\n font-size: var(--mdas-data-value-size);\n font-weight: 600;\n text-align: center;\n z-index: 10;\n max-width: 80%;\n }\n\n /* Price change colors */\n .positive {\n color: #059669;\n }\n\n .negative {\n color: #dc2626;\n }\n\n \n\n /* No data state */\n .no-data-state {\n display: flex;\n align-items: center;\n justify-content: center;\n min-height: 160px;\n margin: 16px 0;\n background: #f9fafb;\n border: 1px solid #e5e7eb;\n border-radius: 12px;\n padding: 24px 16px;\n width: 100%;\n box-sizing: border-box;\n overflow: hidden;\n }\n\n .no-data-content {\n text-align: center;\n max-width: 280px;\n width: 100%;\n word-wrap: break-word;\n overflow-wrap: break-word;\n }\n\n .no-data-icon {\n margin-bottom: 16px;\n display: flex;\n justify-content: center;\n }\n\n .no-data-icon svg {\n opacity: 0.6;\n }\n\n .no-data-title {\n font-size: var(--mdas-no-data-title-size);\n font-weight: 600;\n color: #6b7280;\n margin: 0 0 8px 0;\n }\n\n .no-data-description {\n font-size: var(--mdas-data-value-size);\n color: #9ca3af;\n margin: 0 0 12px 0;\n line-height: 1.4;\n }\n\n .no-data-description strong {\n color: #6b7280;\n font-weight: 600;\n }\n\n .no-data-guidance {\n font-size: var(--mdas-small-text-size);\n color: #9ca3af;\n margin: 0;\n font-style: italic;\n }\n\n /* Error Access State */\n .no-data-state.error-access {\n border: 1px solid #fecaca;\n background:rgb(255, 255, 255);\n \n }\n\n .no-data-title.error {\n color: #ef4444;\n }\n\n .no-data-icon.error svg {\n stroke: #ef4444;\n }\n\n .no-data-icon.error svg circle[fill] {\n fill: #ef4444;\n }\n',a=`\n ${o}\n\n /* Reset and base styles for widget */\n\n .night-session-widget {\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;\n line-height: 1.5;\n max-width: 800px;\n position: relative;\n }\n\n /* STANDARDIZED HEADER LAYOUT */\n\n\n .symbol-section {\n display: flex;\n flex-direction: column;\n gap: 4px;\n }\n\n .night-session-widget .symbol {\n font-size: var(--mdas-symbol-size);\n font-weight: 700;\n color: #111827;\n cursor: pointer;\n transition: all 0.2s ease;\n position: relative;\n }\n\n .night-session-widget .symbol:hover {\n opacity: 0.8;\n transform: scale(1.02);\n }\n\n .night-session-widget .symbol:hover::after {\n content: "✎";\n position: absolute;\n top: -8px;\n right: -8px;\n background: #3b82f6;\n color: white;\n font-size: var(--mdas-edit-icon-size);\n padding: 2px 4px;\n border-radius: 4px;\n opacity: 0.8;\n }\n\n .company-info {\n display: flex;\n align-items: center;\n gap: 8px;\n font-size: var(--mdas-section-title-size);\n color: #6b7280;\n }\n\n .market-name {\n font-weight: 600;\n text-transform: uppercase;\n }\n\n /* Company and market info styling */\n .company-market-info {\n display: flex;\n align-items: center;\n gap: 8px;\n font-size: var(--mdas-small-text-size);\n color: #6b7280;\n margin-bottom: 4px;\n }\n\n .company-market-info .market-name {\n font-weight: 600;\n }\n\n .company-market-info .market-name::before {\n content: '|';\n margin-right: 8px;\n color: #9ca3af;\n }\n\n .company-market-info .market-mic {\n font-weight: 600;\n }\n\n .company-market-info .market-mic::before {\n content: '•';\n margin-right: 8px;\n }\n\n /* Price metadata (source and last update) */\n .price-metadata {\n margin-top: 8px;\n display: flex;\n flex-direction: column;\n gap: 4px;\n }\n\n \n\n /* STANDARDIZED GRID LAYOUT */\n .data-grid {\n display: grid;\n grid-template-columns: repeat(2, 1fr);\n gap: 24px;\n margin-top: 24px;\n }\n\n .data-section {\n display: flex;\n flex-direction: column;\n gap: 12px;\n }\n\n .night-session-widget .section-title {\n font-size: var(--mdas-small-text-size);\n font-weight: 600;\n color: #6b7280;\n text-transform: uppercase;\n letter-spacing: 0.5px;\n border-bottom: 1px solid #e5e7eb;\n padding-bottom: 8px;\n }\n\n .night-session-widget .data-row {\n display: flex;\n justify-content: space-between;\n align-items: center;\n min-height: 20px;\n }\n\n\n\n .night-session-widget .data-value {\n font-size: var(--mdas-data-value-size);\n font-weight: 600;\n color: #111827;\n text-align: right;\n }\n\n /* SPECIAL FORMATTING FOR DIFFERENT DATA TYPES */\n .night-session-widget .bid-ask-value {\n font-size: var(--mdas-bid-ask-size);\n font-weight: 700;\n }\n\n .night-session-widget .size-info {\n font-size: var(--mdas-small-text-size);\n color: #6b7280;\n margin-left: 4px;\n }\n\n /* Footer */\n .night-session-widget .widget-footer {\n display: flex;\n justify-content: space-between;\n align-items: center;\n margin-top: 24px;\n padding-top: 16px;\n border-top: 1px solid #e5e7eb;\n font-size: var(--mdas-small-text-size);\n color: #9ca3af;\n grid-column: 1 / -1;\n }\n\n /* Loading Overlay */\n .widget-loading-overlay {\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background: rgba(255, 255, 255, 0.95);\n backdrop-filter: blur(2px);\n display: flex;\n align-items: center;\n justify-content: center;\n z-index: 10;\n border-radius: 12px;\n }\n\n .widget-loading-overlay.hidden {\n display: none;\n }\n\n .loading-content {\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: 12px;\n }\n\n .loading-spinner {\n width: 32px;\n height: 32px;\n border: 3px solid #f3f4f6;\n border-top-color: #3b82f6;\n border-radius: 50%;\n animation: spin 1s linear infinite;\n }\n\n .night-session-widget .loading-text {\n color: #6b7280;\n font-size: var(--mdas-data-value-size);\n font-weight: 500;\n }\n\n @keyframes spin {\n to { transform: rotate(360deg); }\n }\n\n /* Widget Error Styles */\n .night-session-widget .widget-error {\n background: #fef2f2;\n color: #9ca3af;\n padding: 12px;\n border-radius: 8px;\n border: 1px solid #fecaca;\n margin-top: 16px;\n font-size: var(--mdas-data-value-size);\n font-weight: 500;\n }\n\n /* No Data State */\n .night-session-widget .no-data-state {\n padding: 24px;\n text-align: center;\n color: #6b7280;\n grid-column: 1 / -1;\n }\n\n .night-session-widget .no-data-content {\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: 12px;\n }\n\n .night-session-widget .no-data-icon {\n font-size: 3.43em;\n opacity: 0.5;\n }\n\n .night-session-widget .no-data-title {\n font-size: 1.29em;\n font-weight: 600;\n color: #374151;\n }\n\n .night-session-widget .no-data-message {\n font-size: var(--mdas-data-value-size);\n max-width: 300px;\n line-height: 1.5;\n }\n\n .night-session-widget .no-data-suggestion {\n font-size: var(--mdas-small-text-size);\n color: #9ca3af;\n max-width: 350px;\n line-height: 1.4;\n }\n\n /* Dimmed state for no data */\n .widget-header.dimmed,\n .price-section.dimmed {\n opacity: 0.6;\n }\n\n /* Responsive Design */\n @media (max-width: 768px) {\n :root {\n --mdas-base-font-size: 13px; /* Slightly smaller on tablets */\n }\n\n .widget-styled {\n padding: 16px;\n }\n\n .widget-header {\n grid-template-columns: 1fr;\n gap: 12px;\n text-align: center;\n }\n\n .symbol-section {\n align-items: center;\n }\n\n .price-section {\n text-align: center;\n }\n\n .data-grid {\n grid-template-columns: 1fr;\n gap: 16px;\n }\n\n .widget-footer {\n flex-direction: column;\n gap: 8px;\n text-align: center;\n }\n }\n\n @media (max-width: 480px) {\n :root {\n --mdas-base-font-size: 12px; /* Smaller on mobile */\n }\n }\n\n \n`,r=`\n ${o}\n\n /* Reset and base styles for widget */\n\n .market-data-widget {\n color: #333;\n margin: 0 auto;\n position: relative;\n overflow: hidden;\n }\n\n /* MARKET DATA HEADER STYLES */\n\n\n .market-data-widget .company-info {\n display: flex;\n align-items: center;\n gap: 8px;\n font-size: var(--mdas-section-title-size);\n color: #6b7280;\n }\n\n .company-name {\n position: relative;\n cursor: help;\n transition: all 0.2s ease;\n }\n\n .company-name:hover {\n border-bottom-color: #3b82f6;\n color: #3b82f6;\n }\n\n\n /* STANDARDIZED GRID LAYOUT */\n \n .data-section {\n display: flex;\n flex-direction: column;\n gap: 12px;\n min-width: 0;\n overflow: hidden;\n }\n\n .market-data-widget .section-title {\n font-size: var(--mdas-small-text-size);\n font-weight: 600;\n color: #6b7280;\n text-transform: uppercase;\n letter-spacing: 0.5px;\n padding-bottom: 8px;\n }\n\n\n\n /* SPECIAL FORMATTING FOR DIFFERENT DATA TYPES */\n .market-data-widget .bid-ask-value {\n font-size: var(--mdas-bid-ask-size);\n font-weight: 700;\n }\n\n .market-data-widget .size-info {\n font-size: var(--mdas-small-text-size);\n color: #6b7280;\n margin-left: 4px;\n }\n\n .market-data-widget .range-value {\n font-size: var(--mdas-data-label-size);\n }\n\n \n\n /* Tooltip Styles */\n .company-name::after {\n content: attr(data-tooltip);\n position: absolute;\n bottom: 100%;\n left: 50%;\n transform: translateX(-50%);\n background: #1f2937;\n color: white;\n padding: 8px 12px;\n border-radius: 6px;\n font-size: var(--mdas-small-text-size);\n font-weight: normal;\n white-space: nowrap;\n max-width: 300px;\n white-space: normal;\n line-height: 1.4;\n z-index: 1000;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\n opacity: 0;\n visibility: hidden;\n transition: all 0.2s ease;\n pointer-events: none;\n margin-bottom: 5px;\n }\n\n .company-name:hover::after {\n opacity: 1;\n visibility: visible;\n }\n\n .company-name::before {\n content: '';\n position: absolute;\n bottom: 100%;\n left: 50%;\n transform: translateX(-50%);\n border: 5px solid transparent;\n border-top-color: #1f2937;\n opacity: 0;\n visibility: hidden;\n transition: all 0.2s ease;\n pointer-events: none;\n }\n\n .company-name:hover::before {\n opacity: 1;\n visibility: visible;\n }\n\n /* Loading Overlay */\n .widget-loading-overlay {\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background: rgba(255, 255, 255, 0.95);\n backdrop-filter: blur(2px);\n display: flex;\n align-items: center;\n justify-content: center;\n z-index: 10;\n border-radius: 12px;\n }\n\n .widget-loading-overlay.hidden {\n display: none;\n }\n\n .loading-content {\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: 12px;\n }\n\n .loading-spinner {\n width: 32px;\n height: 32px;\n border: 3px solid #f3f4f6;\n border-top-color: #3b82f6;\n border-radius: 50%;\n animation: spin 1s linear infinite;\n }\n\n .market-data-widget .loading-text {\n color: #6b7280;\n font-size: var(--mdas-data-value-size);\n font-weight: 500;\n }\n\n @keyframes spin {\n to { transform: rotate(360deg); }\n }\n\n /* Widget Error Styles */\n .market-data-widget .widget-error {\n background: #fef2f2;\n color: #dc2626;\n padding: 12px;\n border-radius: 8px;\n border: 1px solid #fecaca;\n margin-top: 16px;\n font-size: var(--mdas-data-value-size);\n font-weight: 500;\n }\n\n /* Responsive Design */\n\n\n @media (max-width: 600px) {\n .widget-header {\n grid-template-columns: 1fr;\n gap: 12px;\n text-align: center;\n }\n\n .symbol-section {\n align-items: center;\n }\n\n .price-section {\n text-align: center;\n }\n\n .data-grid {\n grid-template-columns: 1fr;\n gap: 16px;\n }\n\n .widget-footer {\n flex-direction: column;\n gap: 8px;\n text-align: center;\n }\n }\n\n @media (max-width: 480px) {\n .company-name::after {\n left: 0;\n transform: none;\n max-width: 250px;\n }\n\n .company-name::before {\n left: 20px;\n transform: none;\n }\n }\n`,c=`\n ${o}\n\n .options-widget {\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;\n color: #333;\n max-width: 1400px;\n width: 100%;\n margin: 0 auto;\n position: relative;\n overflow: hidden;\n }\n\n .widget-content {\n position: relative;\n z-index: 1;\n }\n\n \n .options-widget .symbol-info .symbol {\n font-size: var(--mdas-symbol-size);\n font-weight: 700;\n margin: 0 0 8px 0;\n color: #1f2937;\n }\n\n .options-widget .option-info {\n display: flex;\n align-items: center;\n gap: 8px;\n color: #6b7280;\n font-size: var(--mdas-price-change-size);\n }\n\n .options-widget .underlying-symbol {\n font-weight: 600;\n color: #6b7280;\n }\n\n .options-widget .option-details-section {\n display: flex;\n gap: 24px;\n margin-bottom: 24px;\n padding-bottom: 20px;\n border-bottom: 1px solid #e5e7eb;\n }\n\n .options-widget .option-details-section .detail-item {\n display: flex;\n flex-direction: column;\n gap: 4px;\n }\n\n .options-widget .option-details-section .detail-item label {\n font-size: var(--mdas-small-text-size);\n color: #6b7280;\n font-weight: 500;\n text-transform: uppercase;\n letter-spacing: 0.3px;\n }\n\n .options-widget .option-details-section .detail-item span {\n font-size: var(--mdas-price-change-size);\n font-weight: 600;\n color: #1f2937;\n }\n\n\n .options-widget .widget-footer {\n display: flex;\n justify-content: space-between;\n align-items: center;\n padding-top: 16px;\n border-top: 1px solid #e5e7eb;\n font-size: var(--mdas-small-text-size);\n color: #9ca3af;\n }\n\n /* Dimmed state for no-data */\n .widget-header.dimmed {\n opacity: 0.6;\n }\n\n .widget-header.dimmed .symbol {\n color: #9ca3af;\n }\n\n /* Responsive design */\n @media (max-width: 768px) {\n .widget-header {\n flex-direction: column;\n gap: 16px;\n text-align: left;\n }\n\n .price-info {\n text-align: left;\n }\n\n .data-grid {\n grid-template-columns: 1fr;\n gap: 20px;\n }\n\n .option-details-section {\n flex-wrap: wrap;\n gap: 16px;\n }\n\n .current-price {\n font-size: 32px;\n }\n\n .symbol {\n font-size: 20px !important;\n }\n }\n\n @media (max-width: 480px) {\n .widget-styled {\n padding: 12px;\n }\n\n .widget-header {\n margin-bottom: 16px;\n padding-bottom: 16px;\n }\n\n .current-price {\n font-size: 28px;\n }\n\n .data-row {\n grid-template-columns: 1fr;\n gap: 12px;\n }\n\n .option-details-section {\n flex-direction: column;\n gap: 12px;\n }\n\n .no-data-state {\n min-height: 120px;\n padding: 20px 12px;\n }\n\n .no-data-title {\n font-size: 14px;\n }\n\n .no-data-description {\n font-size: 12px;\n }\n\n .no-data-guidance {\n font-size: 11px;\n }\n }\n`;function l(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"";const i=document.createElement(t);return n&&(i.className=n),e&&(i.textContent=e),i}function d(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:2,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"--";if(null==t||""===t)return n;const i=parseFloat(t);return isNaN(i)?n:i.toFixed(e)}function h(t){if(!t)return"";return String(t).replace(/[^A-Za-z0-9.\-_+ ]/g,"").substring(0,50)}function u(t){if(t)for(;t.firstChild;)t.removeChild(t.firstChild)}function g(t){if(!t||"string"!=typeof t)return{valid:!1,error:"Symbol is required",sanitized:""};const e=t.trim().toUpperCase();return 0===e.length?{valid:!1,error:"Symbol cannot be empty",sanitized:""}:e.length>10?{valid:!1,error:"Symbol too long (max 10 characters)",sanitized:""}:{valid:!0,sanitized:e}}function p(t){if(!t||"string"!=typeof t)return{valid:!1,error:"Option symbol is required",sanitized:""};const e=t.trim().toUpperCase();if(e.length<15||e.length>21)return{valid:!1,error:"Invalid option symbol length",sanitized:e};const n=e.match(/^([A-Z]{1,6})(\d{2})(0[1-9]|1[0-2])([0-2][0-9]|3[01])([CP])(\d{8})$/);if(!n)return{valid:!1,error:"Invalid option symbol format. Expected: SYMBOL+YYMMDD+C/P+STRIKE",sanitized:e};const[,i,s,o,a,r,c]=n,l=2e3+parseInt(s,10),d=parseInt(o,10),h=parseInt(a,10),u=new Date(l,d-1,h);if(u.getMonth()+1!==d||u.getDate()!==h)return{valid:!1,error:"Invalid expiration date in option symbol",sanitized:e};const g=new Date;g.setHours(0,0,0,0),u<g&&console.warn("Option symbol has expired");return{valid:!0,sanitized:e,parsed:{underlying:i,expiry:u,type:"C"===r?"call":"put",strike:parseInt(c,10)/1e3}}}function m(t){if(!t)return"ET";const[e,n,i]=t.split("-").map(Number),s=new Date(e,n-1,i),o=function(t,e){const n=new Date(t,e,1),i=1+(7-n.getDay())%7;return new Date(t,e,i+7)}(e,2),a=function(t,e){const n=new Date(t,e,1),i=1+(7-n.getDay())%7;return new Date(t,e,i)}(e,10);return s>=o&&s<a?"EDT":"EST"}function f(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{includeSeconds:n=!0,includeTimezone:i=!0,format:s="short"}=e;let o;if(t||(t=Date.now()),o=t instanceof Date?t:new Date(t),isNaN(o.getTime()))return"Invalid Date";const a=o.getUTCFullYear(),r=o.getUTCMonth(),c=o.getUTCDate(),l=o.getUTCHours(),d=o.getUTCMinutes(),h=o.getUTCSeconds(),u=function(t){const e=t.getUTCFullYear(),n=t.getUTCMonth(),i=t.getUTCDate(),s=new Date(Date.UTC(e,n,i)),o=function(t,e){const n=new Date(Date.UTC(t,e,1)),i=1+(7-n.getUTCDay())%7;return new Date(Date.UTC(t,e,i+7))}(e,2),a=function(t,e){const n=new Date(Date.UTC(t,e,1)),i=1+(7-n.getUTCDay())%7;return new Date(Date.UTC(t,e,i))}(e,10);return s>=o&&s<a}(o),g=u?-4:-5,p=new Date(Date.UTC(a,r,c,l+g,d,h)),m=p.getUTCFullYear(),f=p.getUTCMonth()+1,b=p.getUTCDate(),y=p.getUTCHours(),x=p.getUTCMinutes(),v=p.getUTCSeconds(),w=y%12||12,S=y>=12?"PM":"AM",k=x.toString().padStart(2,"0"),M=v.toString().padStart(2,"0"),C=n?`${w}:${k}:${M} ${S}`:`${w}:${k} ${S}`,_=i?u?" EDT":" EST":"";if("long"===s){return`${["January","February","March","April","May","June","July","August","September","Oct","November","December"][f-1]} ${b}, ${m}, ${C}${_}`}return`${f}/${b}/${m}, ${C}${_}`}class b extends n{constructor(t,e,n){if(super(t,e,n),!e.symbol)throw new Error("Symbol is required for MarketDataWidget");if(!e.wsManager)throw new Error("WebSocketManager is required for MarketDataWidget");this.type="marketdata";const i=g(e.symbol);if(!i.valid)throw new Error(`Invalid symbol: ${i.error}`);this.symbol=i.sanitized,this.wsManager=e.wsManager,this.debug=e.debug||!1,this.styled=void 0===e.styled||e.styled,this.data=null,this.isDestroyed=!1,this.unsubscribe=null,this.loadingTimeout=null,this.createWidgetStructure(),this.initializeSymbolEditor(),this.initialize()}createWidgetStructure(){if(this.container.innerHTML='\n <div class="market-data-widget widget">\n <div class="widget-content">\n \x3c!-- Header Section --\x3e\n <div class="widget-header">\n <div class="symbol-section">\n <h1 class="symbol editable-symbol" \n title="Double-click to edit symbol" \n data-original-symbol="">\n </h1>\n <div class="company-info">\n <span class="company-name" \n title="" \n data-tooltip="">\n </span>\n <span class="data-type">STOCK</span>\n </div>\n </div>\n <div class="price-section">\n <div class="current-price"></div>\n <div class="price-change">\n <span class="change-value"></span>\n <span class="change-percent"></span>\n </div>\n </div>\n </div>\n\n \x3c!-- Data Grid Section --\x3e\n <div class="data-grid">\n <div class="data-section">\n <div class="section-title">Quote</div>\n <div class="data-row">\n <span class="data-label">Bid</span>\n <span class="data-value bid-ask-value bid-data"></span>\n </div>\n <div class="data-row">\n <span class="data-label">Ask</span>\n <span class="data-value bid-ask-value ask-data"></span>\n </div>\n </div>\n\n <div class="data-section">\n <div class="section-title">Trading Activity</div>\n <div class="data-row">\n <span class="data-label">Volume</span>\n <span class="data-value volume"></span>\n </div>\n <div class="data-row">\n <span class="data-label">Average Volume</span>\n <span class="data-value avg-volume"></span>\n </div>\n </div>\n\n <div class="data-section">\n <div class="section-title">Performance</div>\n <div class="data-row">\n <span class="data-label">Previous Close</span>\n <span class="data-value prev-close"></span>\n </div>\n <div class="data-row">\n <span class="data-label">Open</span>\n <span class="data-value open-price"></span>\n </div>\n <div class="data-row">\n <span class="data-label">Day Range</span>\n <span class="data-value range-value day-range"></span>\n </div>\n <div class="data-row">\n <span class="data-label">52-Week Range</span>\n <span class="data-value range-value week-range"></span>\n </div>\n </div>\n\n <div class="data-section">\n <div class="section-title">Key Metrics</div>\n <div class="data-row">\n <span class="data-label">Market Cap</span>\n <span class="data-value market-cap"></span>\n </div>\n <div class="data-row">\n <span class="data-label">P/E Ratio</span>\n <span class="data-value pe-ratio"></span>\n </div>\n <div class="data-row">\n <span class="data-label">Dividend Yield</span>\n <span class="data-value dividend-yield"></span>\n </div>\n <div class="data-row">\n <span class="data-label">Beta</span>\n <span class="data-value beta"></span>\n </div>\n </div>\n </div>\n\n \x3c!-- Footer --\x3e\n <div class="widget-footer">\n <span class="last-update"></span>\n <span class="data-source"></span>\n </div>\n </div>\n \n \x3c!-- Loading Overlay --\x3e\n <div class="widget-loading-overlay">\n <div class="loading-content">\n <div class="loading-spinner"></div>\n <span class="loading-text">Loading market data...</span>\n </div>\n </div>\n </div>\n',this.styled){const t=this.container.querySelector(".market-data-widget");t&&t.classList.add("widget-styled")}this.addStyles()}addStyles(){if(!document.querySelector("#market-data-styles")){const t=document.createElement("style");t.id="market-data-styles",t.textContent=r,document.head.appendChild(t)}}initializeSymbolEditor(){this.symbolEditor=new s(this,{maxLength:10,placeholder:"Enter symbol...",onSymbolChange:this.handleSymbolChange.bind(this),debug:this.debug,autoUppercase:!0,symbolType:"quotel1"});const t=this.container.querySelector(".symbol");t&&(t.textContent=this.symbol,t.dataset.originalSymbol=this.symbol)}async handleSymbolChange(t){this.debug&&console.log("[MarketDataWidget] Symbol change requested:",t);const e=g(t);if(!e.valid)return this.debug&&console.log("[MarketDataWidget] Invalid symbol:",e.error),{success:!1,error:e.error};const n=e.sanitized;if(n===this.symbol)return this.debug&&console.log("[MarketDataWidget] Same symbol, no change needed"),{success:!0};try{const t=this.symbol;return this.showLoading(),this.loadingTimeout&&this.clearTimeout(this.loadingTimeout),this.loadingTimeout=this.setTimeout((()=>{this.debug&&console.log("[MarketDataWidget] Loading timeout for symbol:",n),this.hideLoading(),this.showError(`No data received for ${n}. Please try again.`)}),1e4),this.unsubscribe&&(this.debug&&console.log(`[MarketDataWidget] Unsubscribing from ${t}`),this.wsManager.sendUnsubscribe("queryl1",t),this.unsubscribe(),this.unsubscribe=null),this.symbol=n,this.debug&&console.log(`[MarketDataWidget] Subscribing to ${n}`),this.subscribeToData(),this.debug&&console.log(`[MarketDataWidget] Successfully changed symbol from ${t} to ${n}`),{success:!0}}catch(t){return console.error("[MarketDataWidget] Error changing symbol:",t),this.hideLoading(),this.showError(`Failed to load data for ${n}`),{success:!1,error:`Failed to load ${n}`}}}async initialize(){this.showLoading(),await this.validateInitialSymbol(),this.subscribeToData()}async validateInitialSymbol(){try{const t=this.wsManager.getApiService();if(!t)return void(this.debug&&console.log("[MarketDataWidget] API service not available for initial validation"));const e=await t.quotel1(this.symbol);if(e&&e.data&&e.data[0]){const t=e.data[0];this.initialValidationData=t,this.debug&&console.log("[MarketDataWidget] Initial symbol validated:",{symbol:this.symbol,companyName:t.comp_name,exchangeName:t.market_name})}}catch(t){this.debug&&console.warn("[MarketDataWidget] Initial symbol validation failed:",t)}}subscribeToData(){this.unsubscribe=this.wsManager.subscribe(this.widgetId,["queryl1"],this.handleMessage.bind(this),this.symbol)}handleData(t){if(this.loadingTimeout&&(clearTimeout(this.loadingTimeout),this.loadingTimeout=null),"error"===t.type&&t.noData)return this.debug&&console.log("[MarketDataWidget] Received no data message:",t.message),void(this.data?(this.hideLoading(),this.debug&&console.log("[MarketDataWidget] No new data, keeping cached data visible")):this.showNoDataState({Symbol:this.symbol,NotFound:!0,message:t.message}));if("error"!==t.type){if("object"==typeof t&&t.Message){const e=t.Message.toLowerCase();if(e.includes("no data")||e.includes("not found"))return this.debug&&console.log("[MarketDataWidget] Received no data message:",t.Message),void(this.data?(this.hideLoading(),this.debug&&console.log("[MarketDataWidget] No new data, keeping cached data visible")):this.showNoDataState({Symbol:this.symbol,NotFound:!0,message:t.Message}))}if(t.Data&&t.Data.length>0){const e=t.Data.find((t=>t.Symbol===this.symbol));if(e){const t=new i(e);this.data=t,this.updateWidget(t)}else this.debug&&console.log("[MarketDataWidget] No data for symbol in response, keeping cached data"),this.hideLoading()}t._cached&&this.showConnectionQuality()}else{const e=t.message||"Server error";this.data?(this.hideLoading(),this.debug&&console.log("[MarketDataWidget] Error received but keeping cached data:",e)):this.showError(e)}}showNoDataState(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!this.isDestroyed)try{this.hideLoading(),this.clearError();const e=t.Symbol||this.symbol,n=this.container.querySelector(".symbol");n&&(n.textContent=e);const i=this.container.querySelector(".company-name");i&&(i.textContent=`${e} Inc`);const s=this.container.querySelector(".current-price");s&&(s.textContent="$0.00");const o=this.container.querySelector(".price-change");if(o){const t=o.querySelector(".change-value"),e=o.querySelector(".change-percent");t&&(t.textContent="+0.00"),e&&(e.textContent=" (0.00%)"),o.classList.remove("positive","negative"),o.classList.add("neutral")}const a=this.container.querySelector(".widget-header");a&&a.classList.add("dimmed"),this.showNoDataMessage(e,t);const r=this.container.querySelector(".last-update");if(r){const t=f();r.textContent=`Checked: ${t}`}const c=this.container.querySelector(".data-source");c&&(c.textContent="Source: No data available")}catch(t){console.error("Error showing no data state:",t),this.showError("Error displaying no data state")}}showNoDataMessage(t){const e=this.container.querySelector(".data-grid");e&&(e.style.display="none");const n=this.container.querySelector(".no-data-state");n&&n.remove();const i=l("div","","no-data-state"),s=l("div","","no-data-content"),o=document.createElement("div");o.className="no-data-icon",o.innerHTML='<svg width="32" height="32" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <circle cx="12" cy="12" r="10" stroke="#9ca3af" stroke-width="2"/>\n <path d="M12 8v4" stroke="#9ca3af" stroke-width="2" stroke-linecap="round"/>\n <circle cx="12" cy="16" r="1" fill="#9ca3af"/>\n </svg>',s.appendChild(o);const a=l("h3","No Market Data","no-data-title");s.appendChild(a);const r=l("p","","no-data-description");r.appendChild(document.createTextNode("Market data for "));const c=l("strong",h(t));r.appendChild(c),r.appendChild(document.createTextNode(" was not found")),s.appendChild(r);const d=l("p","Please check the symbol spelling or try a different symbol","no-data-guidance");s.appendChild(d),i.appendChild(s);const u=this.container.querySelector(".widget-footer");u&&u.parentNode?u.parentNode.insertBefore(i,u):this.container.appendChild(i)}updateWidget(t){if(!this.isDestroyed)try{this.loadingTimeout&&(clearTimeout(this.loadingTimeout),this.loadingTimeout=null),this.clearError(),this.hideLoading();const e=this.container.querySelector(".widget-header");e&&e.classList.remove("dimmed");const n=this.container.querySelector(".data-grid");n&&(n.style.display="");const i=this.container.querySelector(".no-data-state");i&&i.remove();const s=this.container.querySelector(".symbol");s&&(s.textContent=t.symbol,s.dataset.originalSymbol=t.symbol);const o=this.container.querySelector(".company-name");if(o){const e=t.companyName||`${t.symbol} Inc`,n=t.companyDescription||`${t.symbol} designs, manufactures, and markets consumer electronics and software.`;o.textContent=e,o.setAttribute("title",n),o.setAttribute("data-tooltip",n)}const a=this.container.querySelector(".current-price");a&&(a.textContent=t.formatPrice());const r=t.getPriceChange(),c=this.container.querySelector(".price-change");if(c){const e=c.querySelector(".change-value"),n=c.querySelector(".change-percent");e&&(e.textContent=t.formatPriceChange()),n&&(n.textContent=` (${t.formatPriceChangePercent()})`),c.classList.remove("positive","negative","neutral"),r>0?c.classList.add("positive"):r<0?c.classList.add("negative"):c.classList.add("neutral")}const h=this.container.querySelector(".bid-data");if(h){u(h);const e=d(t.bidPrice,2,"0.00"),n=t.bidSize||0;h.appendChild(document.createTextNode(`$${e}`));const i=l("span",`× ${n}`,"size-info");h.appendChild(i)}const g=this.container.querySelector(".ask-data");if(g){u(g);const e=d(t.askPrice,2,"0.00"),n=t.askSize||0;g.appendChild(document.createTextNode(`$${e}`));const i=l("span",`× ${n}`,"size-info");g.appendChild(i)}const p=this.container.querySelector(".volume");p&&(p.textContent=t.formatVolume());const m=this.container.querySelector(".avg-volume");m&&(m.textContent=t.formatAverageVolume());const b=this.container.querySelector(".prev-close");b&&(b.textContent=`$${t.previousClose?.toFixed(2)||"0.00"}`);const y=this.container.querySelector(".open-price");y&&(y.textContent=`$${t.openPrice?.toFixed(2)||"0.00"}`);const x=this.container.querySelector(".day-range");x&&(x.textContent=t.formatDayRange());const v=this.container.querySelector(".week-range");v&&(v.textContent=t.format52WeekRange());const w=this.container.querySelector(".market-cap");w&&(w.textContent=t.formatMarketCap());const S=this.container.querySelector(".pe-ratio");S&&(S.textContent=t.peRatio?.toFixed(2)||"N/A");const k=this.container.querySelector(".dividend-yield");k&&(k.textContent=t.dividendYield?`${t.dividendYield.toFixed(2)}%`:"N/A");const M=this.container.querySelector(".beta");M&&(M.textContent=t.beta?.toFixed(2)||"N/A");const C=f(t.quoteTime),_=this.container.querySelector(".last-update");_&&(_.textContent=`Last update: ${C}`);const D=this.container.querySelector(".data-source");D&&(D.textContent=`Source: ${t.getDataSource()}`)}catch(t){console.error("Error updating widget:",t),this.showError("Error updating data")}}showLoading(){const t=this.container.querySelector(".widget-loading-overlay");t&&t.classList.remove("hidden")}hideLoading(){const t=this.container.querySelector(".widget-loading-overlay");t&&t.classList.add("hidden")}showError(t){this.hideLoading(),this.clearError();const e=document.createElement("div");e.className="widget-error",e.textContent=`Error: ${t}`,e.style.cssText="\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n padding: 15px 20px;\n background: #fee;\n border: 1px solid #f5c6cb;\n border-radius: 6px;\n color: #721c24;\n text-align: center;\n font-size: 14px;\n z-index: 100;\n ",this.container.appendChild(e)}clearError(){const t=this.container.querySelector(".widget-error"),e=this.container.querySelector(".widget-error-container");t&&t.remove(),e&&e.remove()}destroy(){this.isDestroyed=!0,this.loadingTimeout&&(this.clearTimeout(this.loadingTimeout),this.loadingTimeout=null),this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=null),this.symbolEditor&&(this.symbolEditor.destroy(),this.symbolEditor=null),super.destroy()}}class y{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.symbol=t.Symbol||"",this.marketName=t.MarketName||("bruce"===t.Source?.toLowerCase()?"Bruce":"Blue Ocean"),this.marketDesc=null!==t.MarketDesc?t.MarketDesc||"":null,this.countryCode=null!==t.CountryCode?t.CountryCode||"":null,this.volume=null!==t.Volume?t.Volume||0:null,this.askPrice=null!==t.AskPx?t.AskPx||0:null,this.askSize=null!==t.AskSz?t.AskSz||0:null,this.bidPrice=null!==t.BidPx?t.BidPx||0:null,this.bidSize=null!==t.BidSz?t.BidSz||0:null,this.lastPrice=null!==t.LastPx?t.LastPx||0:null,this.quoteTime=null!==t.QuoteTime?t.QuoteTime:null,this.activityTimestamp=null!==t.ActivityTimestamp?t.ActivityTimestamp||"":null,this.tradeSize=null!==t.TradeSz?t.TradeSz||0:null,this.bidExchange=null!==t.BidExch?t.BidExch||"":null,this.askExchange=null!==t.AskExch?t.AskExch||"":null,this.notFound=t.NotFound||!1,this.source=t.Source||"",this.accuAmount=null!==t.AccuAmmount?t.AccuAmmount||0:null,this.change=null!==t.Change?t.Change||0:null,this.changePercent=null!==t.ChangePercent?t.ChangePercent||0:null,this.closingPrice=null!==t.ClosingPx?t.ClosingPx:null!==t.PreviousClose?t.PreviousClose:null,this.highPrice=null!==t.HighPx?t.HighPx||0:null,this.lowPrice=null!==t.LowPx?t.LowPx||0:null,this.openPrice=null!==t.OpenPx?t.OpenPx||0:null,this.tradePrice=null!==t.TradePx?t.TradePx||0:null,this.tradeRegionName=null!==t.TradeRegionName?t.TradeRegionName||"":null,this.companyName=t.comp_name||t.CompanyName||"",this.exchangeName=t.market_name||t.Exchange||"",this.mic=t.mic||""}formatPrice(){return`$${this.lastPrice.toFixed(2)}`}formatBidAsk(){return`$${this.bidPrice.toFixed(2)} × ${this.bidSize} / $${this.askPrice.toFixed(2)} × ${this.askSize}`}formatVolume(){return this.volume.toLocaleString()}formatPriceChange(){if(null===this.change||void 0===this.change)return"--";return`${this.change>0?"+":""}${this.change.toFixed(2)}`}formatPriceChangePercent(){if(null===this.changePercent||void 0===this.changePercent)return"--";return`${this.changePercent>0?"+":""}${this.getPriceChangePercent().toFixed(2)}%`}getDataSource(){return"blueocean-d"===this.source.toLowerCase()||"bruce-d"===this.source.toLowerCase()?"bruce-d"===this.source.toLowerCase()?"Bruce 20 mins delayed":"BlueOcean 20 mins delayed":this.source.toLowerCase().includes("bruce")||this.source.toLowerCase().includes("blueocean")?"bruce"===this.source.toLowerCase()?"Bruce Real-time":"BlueOcean Real-time":null!==this.source&&""!==this.source?this.source:"MDAS"}getPriceChangePercent(){return null===this.changePercent||void 0===this.changePercent?0:Math.abs(this.changePercent)>1?this.changePercent:100*this.changePercent}}class x extends n{constructor(t,e,n){if(super(t,e,n),!e.symbol)throw new Error("Symbol is required for NightSessionWidget");if(!e.wsManager)throw new Error("WebSocketManager is required for NightSessionWidget");if(!e.source||"blueocean"!==e.source.toLowerCase()&&"bruce"!==e.source.toLowerCase())throw new Error('Source should be either "blueocean" or "bruce"');this.type="nightsession "+e.source;const i=g(e.symbol);if(!i.valid)throw new Error(`Invalid symbol: ${i.error}`);this.symbol=i.sanitized,this.source=e.source||"blueocean",this.wsManager=e.wsManager,this.debug=e.debug||!1,this.styled=void 0===e.styled||e.styled,this.data=null,this.isDestroyed=!1,this.unsubscribe=null,this.symbolEditor=null,this.loadingTimeout=null,this.companyName="",this.exchangeName="",this.mic="",this.createWidgetStructure(),this.initialize()}createWidgetStructure(){if(this.container.innerHTML='\n <div class="night-session-widget widget">\n <div class="widget-content">\n \x3c!-- Header Section --\x3e\n <div class="widget-header">\n <div class="symbol-section">\n <div class="company-market-info">\n <span class="night-company-name"></span>\n <span class="market-name"></span>\n </div>\n <h1 class="symbol editable-symbol"\n title="Double-click to edit symbol"\n data-original-symbol="">\n </h1>\n\n </div>\n <div class="price-section">\n <div class="current-price"></div>\n <div class="price-change">\n <span class="change-value"></span>\n <span class="change-percent"></span>\n </div>\n <div class="price-metadata">\n <div class="last-update"></div>\n <div class="data-source"></div>\n </div>\n </div>\n </div>\n\n \x3c!-- Data Grid Section --\x3e\n <div class="data-grid">\n <div class="data-section">\n <div class="section-title">Quote</div>\n <div class="data-row">\n <span class="data-label">Bid</span>\n <span class="data-value bid-ask-value">\n <span class="bid-price"></span>\n <span class="size-info bid-size"></span>\n </span>\n </div>\n <div class="data-row">\n <span class="data-label">Ask</span>\n <span class="data-value bid-ask-value">\n <span class="ask-price"></span>\n <span class="size-info ask-size"></span>\n </span>\n </div>\n </div>\n\n <div class="data-section">\n <div class="section-title">Trading Activity</div>\n <div class="data-row">\n <span class="data-label">Volume</span>\n <span class="data-value volume"></span>\n </div>\n <div class="data-row">\n <span class="data-label">Accumulated Amount</span>\n <span class="data-value accu-amount"></span>\n </div>\n </div>\n\n <div class="data-section">\n <div class="section-title">Performance</div>\n <div class="data-row">\n <span class="data-label">Previous Close</span>\n <span class="data-value previous-close"></span>\n </div>\n <div class="data-row at-close-row">\n <span class="data-label">At close</span>\n <span class="data-value at-close-time"></span>\n </div>\n <div class="data-row">\n <span class="data-label">Open</span>\n <span class="data-value open-price"></span>\n </div>\n <div class="data-row">\n <span class="data-label">Day Range</span>\n <span class="data-value range-value day-range"></span>\n </div>\n </div>\n </div>\n </div>\n\n \x3c!-- Loading Overlay --\x3e\n <div class="widget-loading-overlay">\n <div class="loading-content">\n <div class="loading-spinner"></div>\n <span class="loading-text">Loading night session data...</span>\n </div>\n </div>\n </div>\n',this.styled){const t=this.container.querySelector(".night-session-widget");t&&t.classList.add("widget-styled")}this.addStyles(),this.setupSymbolEditor()}addStyles(){if(!document.querySelector("#night-session-styles")){const t=document.createElement("style");t.id="night-session-styles",t.textContent=a,document.head.appendChild(t)}}setupSymbolEditor(){this.symbolEditor=new s(this,{maxLength:10,placeholder:"Enter symbol...",onSymbolChange:this.handleSymbolChange.bind(this),debug:this.debug,autoUppercase:!0,cancelOnBlur:!1,symbolType:"nightsession"})}async handleSymbolChange(t,e){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;this.debug&&(console.log("[NightSessionWidget] Symbol change requested:",t),console.log("[NightSessionWidget] Validation data:",n));const i=g(t);if(!i.valid)return this.debug&&console.log("[NightSessionWidget] Invalid symbol:",i.error),{success:!1,error:i.error};const s=i.sanitized;if(n&&(this.companyName=n.comp_name||"",this.exchangeName=n.market_name||"",this.mic=n.mic||"",this.debug&&console.log("[NightSessionWidget] Extracted company info:",{companyName:this.companyName,exchangeName:this.exchangeName},n)),s===this.symbol)return this.debug&&console.log("[NightSessionWidget] Same symbol, no change needed"),{success:!0};try{const t=this.symbol;return this.showLoading(),this.loadingTimeout&&this.clearTimeout(this.loadingTimeout),this.loadingTimeout=this.setTimeout((()=>{this.debug&&console.log("[NightSessionWidget] Loading timeout for symbol:",s),this.hideLoading(),this.showError(`No data received for ${s}. Please try again.`)}),1e4),this.unsubscribe&&(this.debug&&console.log(`[NightSessionWidget] Unsubscribing from ${t}`),this.unsubscribe(),this.unsubscribe=null),this.symbol=s,this.debug&&console.log(`[NightSessionWidget] Subscribing to ${s}`),this.subscribeToData(),this.debug&&console.log(`[NightSessionWidget] Successfully changed symbol from ${t} to ${s}`),{success:!0}}catch(t){return console.error("[NightSessionWidget] Error changing symbol:",t),this.showError(`Failed to load data for ${s}`),{success:!1,error:`Failed to load ${s}`}}}async initialize(){this.showLoading(),await this.validateInitialSymbol(),this.loadingTimeout=setTimeout((()=>{this.debug&&console.log("[NightSessionWidget] Loading timeout - no data received for:",this.symbol),this.hideLoading(),this.showNoDataState({Symbol:this.symbol,NotFound:!0,message:"No data available for this symbol"})}),1e4),this.subscribeToData()}async validateInitialSymbol(){try{const t=this.wsManager.getApiService();if(!t)return void(this.debug&&console.log("[NightSessionWidget] API service not available for initial validation"));const e=await t.quotel1(this.symbol);if(e&&e.data&&e.data[0]){const t=e.data[0];this.companyName=t.comp_name||"",this.exchangeName=t.market_name||"",this.mic=t.mic||"",this.debug&&console.log("[NightSessionWidget] Initial symbol validated:",{symbol:this.symbol,companyName:this.companyName,exchangeName:this.exchangeName,mic:this.mic})}}catch(t){this.debug&&console.warn("[NightSessionWidget] Initial symbol validation failed:",t)}}subscribeToData(){const t="bruce"===this.source?"querybrucel1":"queryblueoceanl1";this.unsubscribe=this.wsManager.subscribe(this.widgetId,[t],this.handleMessage.bind(this),this.symbol)}handleData(t){if(this.loadingTimeout&&(clearTimeout(this.loadingTimeout),this.loadingTimeout=null),"error"===t.type&&t.noData)return this.debug&&console.log("[NightSessionWidget] Received no data message:",t.message),void(this.data?(this.hideLoading(),this.debug&&console.log("[NightSessionWidget] No new data, keeping cached data visible")):this.showNoDataState({Symbol:this.symbol,NotFound:!0,message:t.message}));if("error"!==t.type){if(Array.isArray(t)){const e=t.find((t=>t.Symbol===this.symbol));if(e){if(this.debug&&console.log("[NightSessionWidget] Found data for symbol:",e),!0===e.NotFound)this.data?(this.hideLoading(),this.debug&&console.log("[NightSessionWidget] No new data, keeping cached data visible")):this.showNoDataState(e);else{const t=new y(e);this.data=t,this.updateWidget(t)}return}this.data?(this.hideLoading(),this.debug&&console.log("[NightSessionWidget] No matching data in response, keeping cached data")):this.showNoDataState({Symbol:this.symbol,NotFound:!0})}else if("queryblueoceanl1"===t.type||"querybrucel1"===t.type)if(t[0]?.Symbol===this.symbol)if(!0!==t[0].NotFound&&t[0].MarketName&&"BLUE"===t[0].MarketName){const e=new y(t[0]);this.data=e,this.updateWidget(e)}else this.data?(this.hideLoading(),this.debug&&console.log("[NightSessionWidget] No new data, keeping cached data visible")):this.showNoDataState(t[0]);else this.debug&&console.log("[NightSessionWidget] No matching symbol in response, keeping cached data"),this.hideLoading();t._cached}else{const e=t.message||"Server error";e.toLowerCase().includes("access")||e.toLowerCase().includes("permission")||e.toLowerCase().includes("denied")?this.data?(this.hideLoading(),this.debug&&console.log("[NightSessionWidget] Access error but keeping cached data")):this.showNoDataState({Symbol:this.symbol,NotFound:!0,isAccessError:!0,message:e}):this.data?(this.hideLoading(),this.debug&&console.log("[NightSessionWidget] Error received but keeping cached data:",e)):(console.log("errorMsg",e),this.showError(e))}}updateWidget(t){if(!this.isDestroyed)try{this.hideLoading(),this.clearError();const e=this.container.querySelector(".widget-header");e&&e.classList.remove("dimmed");const n=this.container.querySelector(".price-section");n&&n.classList.remove("dimmed");const i=this.container.querySelector(".data-grid");i&&(i.style.display="grid");const s=this.container.querySelector(".no-data-state");s&&s.remove();const o=this.container.querySelector(".symbol");o&&(o.textContent=t.symbol);const a=this.container.querySelector(".night-company-name");a&&(a.textContent=this.companyName||t.companyName||"");const r=this.container.querySelector(".market-name");r&&(r.textContent=this.exchangeName||t.exchangeName||"");const c=this.container.querySelector(".current-price");c&&(c.textContent=null!==t.lastPrice?t.formatPrice():"--");const l=t.change,d=this.container.querySelector(".price-change");if(d){const e=d.querySelector(".change-value"),n=d.querySelector(".change-percent");e&&(e.textContent=null!==l&&0!==l?l:"--"),n&&(0!==t.changePercent?n.textContent=` (${t.getPriceChangePercent().toFixed(2)}%)`:n.textContent=" (0.00%)"),d.classList.remove("positive","negative","neutral"),l>0?d.classList.add("positive"):l<0?d.classList.add("negative"):d.classList.add("neutral")}const h=this.container.querySelector(".bid-price");h&&(h.textContent=null!==t.bidPrice?`$${t.bidPrice.toFixed(2)} `:"-- ×");const u=this.container.querySelector(".bid-size");u&&(u.textContent=null!==t.bidSize?`× ${t.bidSize}`:"--");const g=this.container.querySelector(".ask-price");g&&(g.textContent=null!==t.askPrice?`$${t.askPrice.toFixed(2)} `:"-- ×");const p=this.container.querySelector(".ask-size");p&&(p.textContent=null!==t.askSize?`× ${t.askSize}`:"--");const m=this.container.querySelector(".volume");m&&(m.textContent=null!==t.volume?t.formatVolume():"--");const b=this.container.querySelector(".accu-amount");b&&(b.textContent=null!==t.accuAmount?`$${t.accuAmount.toLocaleString()}`:"--");const y=this.container.querySelector(".open-price");y&&(y.textContent=null!==t.openPrice?`$${t.openPrice.toFixed(2)}`:"--");const x=this.container.querySelector(".previous-close");x&&(x.textContent=null!==t.closingPrice?`$${t.closingPrice.toFixed(2)}`:"--");const v=this.container.querySelector(".at-close-time");if(v){const e=t.quoteTime?f(new Date(t.quoteTime)):"--";v.textContent=e}const w=this.container.querySelector(".day-range");w&&(null!==t.highPrice&&null!==t.lowPrice?w.textContent=`$${t.lowPrice.toFixed(2)} - $${t.highPrice.toFixed(2)}`:w.textContent="--");const S=this.container.querySelector(".data-source");S&&(S.textContent="Source: "+t.getDataSource());const k=(t=>{if(!t)return f();const e=new Date(t);return isNaN(e.getTime())?f():f(e)})(t.quoteTime),M=this.container.querySelector(".last-update");M&&(M.textContent=`Overnight: ${k}`)}catch(t){console.error("Error updating widget:",t),this.showError("Error updating data")}}showLoading(){const t=this.container.querySelector(".widget-loading-overlay");t&&t.classList.remove("hidden")}hideLoading(){const t=this.container.querySelector(".widget-loading-overlay");t&&t.classList.add("hidden")}showError(t){this.hideLoading(),this.clearError();const e=document.createElement("div");e.className="widget-error",e.textContent=`Error: ${t}`,e.style.cssText="\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n padding: 15px 20px;\n background: #fee;\n border: 1px solid #f5c6cb;\n border-radius: 6px;\n color: #721c24;\n text-align: center;\n font-size: 14px;\n z-index: 100;\n ",this.container.appendChild(e)}clearError(){const t=this.container.querySelector(".widget-error"),e=this.container.querySelector(".widget-error-container");t&&t.remove(),e&&e.remove()}showNoDataState(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!this.isDestroyed)try{this.hideLoading(),this.clearError();const e=t.Symbol||this.symbol,n=this.container.querySelector(".symbol");n&&(n.textContent=e);const i=this.container.querySelector(".current-price");i&&(i.textContent="$0.00");const s=this.container.querySelector(".price-change");if(s){const t=s.querySelector(".change-value");t&&(t.textContent="+0.00");const e=s.querySelector(".change-percent");e&&(e.textContent=" (0.00%)"),s.classList.remove("positive","negative")}const o=this.container.querySelector(".widget-header");o&&o.classList.add("dimmed");const a=this.container.querySelector(".price-section");a&&a.classList.add("dimmed"),this.showNoDataMessage(e,t);const r=f(),c=this.container.querySelector(".last-update");c&&(c.textContent=`Overnight: ${r}`)}catch(t){console.error("Error showing no data state:",t),this.showError("Error displaying no data state")}}showNoDataMessage(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const n=this.container.querySelector(".data-grid");n&&(n.style.display="none");const i=this.container.querySelector(".no-data-state");i&&i.remove();const s=e.isAccessError||e.message&&e.message.toLowerCase().includes("access"),o=l("div","","no-data-state"),a=l("div","","no-data-content");if(s){const n=document.createElement("div");n.className="no-data-icon error",n.innerHTML='<svg width="32" height="32" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <circle cx="12" cy="12" r="10" stroke="#ef4444" stroke-width="2"/>\n <path d="M12 8v4" stroke="#ef4444" stroke-width="2" stroke-linecap="round"/>\n <circle cx="12" cy="16" r="1" fill="#ef4444"/>\n </svg>',a.appendChild(n);const i=l("h3",String(e.message||"Access Denied"),"no-data-title error");a.appendChild(i);const s=l("p","","no-data-description");s.appendChild(document.createTextNode("You do not have permission to view night session data for "));const o=l("strong",h(t));s.appendChild(o),a.appendChild(s);const r=l("p","Contact your administrator or try a different symbol","no-data-guidance");a.appendChild(r)}else{const n=document.createElement("div");n.className="no-data-icon",n.innerHTML='<svg width="32" height="32" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <circle cx="12" cy="12" r="10" stroke="#9ca3af" stroke-width="2"/>\n <path d="M12 6v6l4 2" stroke="#9ca3af" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n </svg>',a.appendChild(n);const i=l("h3",String(e.message||"No Data Available"),"no-data-title");a.appendChild(i);const s=l("p","","no-data-description");s.appendChild(document.createTextNode("Night session data for "));const o=l("strong",h(t));s.appendChild(o),s.appendChild(document.createTextNode(" was not found")),a.appendChild(s);const r=l("p","Please check the symbol or try again later","no-data-guidance");a.appendChild(r)}o.appendChild(a);const r=this.container.querySelector(".widget-footer");r&&r.parentNode?r.parentNode.insertBefore(o,r):this.container.appendChild(o)}destroy(){this.isDestroyed=!0,this.loadingTimeout&&(this.clearTimeout(this.loadingTimeout),this.loadingTimeout=null),this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=null),this.symbolEditor&&(this.symbolEditor.destroy(),this.symbolEditor=null),super.destroy()}updateSymbol(t){this.handleSymbolChange(t)}}class v{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.rawData=t,this.symbol=t.Symbol||"",this.rootSymbol=t.RootSymbol||"",this.underlying=t.Underlying||"",this.expire=t.Expire||"",this.strike=t.Strike||0,this.type=this.determineOptionType(),this.lastPrice=t.LastPx||0,this.closePx=t.ClosePx||0,this.yestClosePx=t.YestClosePx||0,this.openPx=t.OpenPx||0,this.highPx=t.HighPx||0,this.lowPx=t.LowPx||0,this.bidPx=t.BidPx||0,this.bidSz=t.BidSz||0,this.bidExch=t.BidExch||"",this.askPx=t.AskPx||0,this.askSz=t.AskSz||0,this.askExch=t.AskExch||"",this.volume=t.Volume||0,this.openInterest=t.OpenInst||0,this.primeShare=t.PrimeShare||0,this.exch=t.Exch||"",this.dataSource=t.DataSource||"",this.quoteTime=t.QuoteTime||"",this.notFound=t.NotFound||!1}determineOptionType(){return this.symbol?this.symbol.includes("C")?"call":this.symbol.includes("P")?"put":"unknown":"unknown"}getChange(){return this.lastPrice-this.yestClosePx}getChangePercent(){return 0===this.yestClosePx?0:(this.lastPrice-this.yestClosePx)/this.yestClosePx*100}getSpread(){return this.askPx-this.bidPx}getSpreadPercent(){const t=(this.askPx+this.bidPx)/2;return 0===t?0:(this.askPx-this.bidPx)/t*100}getMidPrice(){return(this.askPx+this.bidPx)/2}formatPrice(t){return t?t.toFixed(2):"0.00"}formatStrike(){return`$${this.formatPrice(this.strike)}`}formatLastPrice(){return`$${this.formatPrice(this.lastPrice)}`}formatClosePx(){return`$${this.formatPrice(this.closePx)}`}formatYestClosePx(){return`$${this.formatPrice(this.yestClosePx)}`}formatOpenPx(){return`$${this.formatPrice(this.openPx)}`}formatHighPx(){return`$${this.formatPrice(this.highPx)}`}formatLowPx(){return`$${this.formatPrice(this.lowPx)}`}formatBid(){return`$${this.formatPrice(this.bidPx)}`}formatAsk(){return`$${this.formatPrice(this.askPx)}`}formatBidSize(){return this.bidSz.toString()}formatAskSize(){return this.askSz.toString()}formatSpread(){return`$${this.formatPrice(this.getSpread())}`}formatMidPrice(){return`$${this.formatPrice(this.getMidPrice())}`}formatChange(){const t=this.getChange();return`${t>=0?"+":""}${this.formatPrice(t)}`}formatChangePercent(){const t=this.getChangePercent();return`${t>=0?"+":""}${t.toFixed(2)}%`}formatVolume(){return this.volume.toLocaleString()}formatOpenInterest(){return this.openInterest.toLocaleString()}formatPrimeShare(){return this.primeShare.toString()}formatExpirationDate(){if(!this.expire)return"N/A";try{return new Date(this.expire).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})}catch(t){return this.expire}}formatQuoteTime(){if(!this.quoteTime)return"N/A";try{return new Date(this.quoteTime).toLocaleString("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit"})}catch(t){return this.quoteTime}}formatExchange(){return this.exch||"N/A"}formatDataSource(){return this.dataSource||"N/A"}formatDayRange(){return`$${this.formatPrice(this.lowPx)} - $${this.formatPrice(this.highPx)}`}formatOptionType(){return this.type.toUpperCase()}getDaysToExpiration(){if(!this.expire)return 0;try{const t=new Date(this.expire),e=new Date,n=t.getTime()-e.getTime(),i=Math.ceil(n/864e5);return Math.max(0,i)}catch(t){return 0}}formatDaysToExpiration(){const t=this.getDaysToExpiration();return`${t} day${1!==t?"s":""}`}getMoneyness(t){return t&&0!==this.strike?"call"===this.type?t-this.strike:"put"===this.type?this.strike-t:0:0}isInTheMoney(t){return this.getMoneyness(t)>0}parseSymbol(){return{underlying:this.rootSymbol||"",expirationDate:this.expire||"",type:this.type||"",strikePrice:this.strike||0,fullSymbol:this.symbol||""}}getSummary(){return{symbol:this.symbol,underlying:this.underlying,type:this.formatOptionType(),strike:this.formatStrike(),expiration:this.formatExpirationDate(),lastPrice:this.formatLastPrice(),change:this.formatChange(),changePercent:this.formatChangePercent(),volume:this.formatVolume(),openInterest:this.formatOpenInterest(),bid:this.formatBid(),ask:this.formatAsk(),exchange:this.formatExchange()}}getDataSource(){return"opra-d"===this.dataSource.toLowerCase()?"20 mins delayed":"real-time"===this.dataSource.toLowerCase()?"Real-time":"MDAS Server"}static fromApiResponse(t){return new v(t)}isValid(){return!this.notFound&&this.symbol&&this.strike>0}}class w extends n{constructor(t,e,n){if(super(t,e,n),!e.symbol)throw new Error("Symbol is required for OptionsWidget");if(!e.wsManager)throw new Error("WebSocketManager is required for OptionsWidget");this.type="options";const i=p(e.symbol);if(!i.valid)throw new Error(`Invalid option symbol: ${i.error}`);this.symbol=i.sanitized,this.wsManager=e.wsManager,this.debug=e.debug||!1,this.styled=void 0===e.styled||e.styled,this.data=null,this.isDestroyed=!1,this.unsubscribe=null,this.loadingTimeout=null,this.createWidgetStructure(),this.initializeSymbolEditor(),this.initialize()}createWidgetStructure(){if(this.container.innerHTML='\n <div class="options-widget widget">\n <div class="widget-content">\n \x3c!-- Header Section with Purple Background --\x3e\n <div class="widget-header">\n <div class="symbol-section">\n <h1 class="symbol editable-symbol" \n title="Double-click to edit symbol" \n data-original-symbol="">\n </h1>\n <div class="option-info">\n <span class="underlying-symbol"></span>\n <span class="data-type">OPTIONS</span>\n </div>\n </div>\n <div class="price-section">\n <div class="current-price"></div>\n <div class="price-change">\n <span class="change-value"></span>\n <span class="change-percent"></span>\n </div>\n </div>\n </div>\n\n \x3c!-- Data Grid Section --\x3e\n <div class="data-grid">\n <div class="data-section">\n <div class="section-title">Quote</div>\n <div class="data-row">\n <span class="data-label">Bid</span>\n <span class="data-value bid-ask-value bid-data"></span>\n </div>\n <div class="data-row">\n <span class="data-label">Ask</span>\n <span class="data-value bid-ask-value ask-data"></span>\n </div>\n </div>\n\n <div class="data-section">\n <div class="section-title">Trading Activity</div>\n <div class="data-row">\n <span class="data-label">Volume</span>\n <span class="data-value volume"></span>\n </div>\n <div class="data-row">\n <span class="data-label">Open Interest</span>\n <span class="data-value open-interest"></span>\n </div>\n </div>\n\n <div class="data-section">\n <div class="section-title">Performance</div>\n <div class="data-row">\n <span class="data-label">Previous Close</span>\n <span class="data-value yesterday-close"></span>\n </div>\n <div class="data-row">\n <span class="data-label">Open</span>\n <span class="data-value open-price"></span>\n </div>\n <div class="data-row">\n <span class="data-label">Day Range</span>\n <span class="data-value range-value day-range"></span>\n </div>\n </div>\n\n <div class="data-section">\n <div class="section-title">Contract Info</div>\n <div class="data-row">\n <span class="data-label">Strike Price</span>\n <span class="data-value strike-price"></span>\n </div>\n <div class="data-row">\n <span class="data-label">Expiration</span>\n <span class="data-value expiry-date"></span>\n </div>\n <div class="data-row">\n <span class="data-label">Prime Share</span>\n <span class="data-value prime-share"></span>\n </div>\n </div>\n </div>\n\n \x3c!-- Footer --\x3e\n <div class="widget-footer">\n <span class="last-update"></span>\n <span class="data-source"></span>\n </div>\n </div>\n \n \x3c!-- Loading Overlay --\x3e\n <div class="widget-loading-overlay">\n <div class="loading-content">\n <div class="loading-spinner"></div>\n <span class="loading-text">Loading options data...</span>\n </div>\n </div>\n </div>\n',this.styled){const t=this.container.querySelector(".options-widget");t&&t.classList.add("widget-styled")}this.addStyles()}addStyles(){if(!document.querySelector("#options-widget-styles")){const t=document.createElement("style");t.id="options-widget-styles",t.textContent=c,document.head.appendChild(t)}}initializeSymbolEditor(){this.symbolEditor=new s(this,{maxLength:20,placeholder:"Enter option contract...",onSymbolChange:this.handleSymbolChange.bind(this),debug:this.debug,autoUppercase:!0,symbolType:"optionsl1"});const t=this.container.querySelector(".symbol");t&&(t.textContent=this.symbol,t.dataset.originalSymbol=this.symbol)}async handleSymbolChange(t){this.debug&&console.log("[OptionsWidget] Symbol change requested:",t);const e=p(t);if(!e.valid)return this.debug&&console.log("[OptionsWidget] Invalid option symbol:",e.error),{success:!1,error:e.error};const n=e.sanitized;if(n===this.symbol)return this.debug&&console.log("[OptionsWidget] Same symbol, no change needed"),{success:!0};try{const t=this.symbol;return this.showLoading(),this.loadingTimeout&&this.clearTimeout(this.loadingTimeout),this.loadingTimeout=this.setTimeout((()=>{this.debug&&console.log("[OptionsWidget] Loading timeout for symbol:",n),this.hideLoading(),this.showError(`No data received for ${n}. Please try again.`)}),1e4),this.unsubscribe&&(this.debug&&console.log(`[OptionsWidget] Unsubscribing from ${t}`),this.wsManager.sendUnsubscribe("queryoptionl1",t),this.unsubscribe(),this.unsubscribe=null),this.symbol=n,this.debug&&console.log(`[OptionsWidget] Subscribing to ${n}`),this.subscribeToData(),this.debug&&console.log(`[OptionsWidget] Successfully changed symbol from ${t} to ${n}`),{success:!0}}catch(t){return console.error("[OptionsWidget] Error changing symbol:",t),this.showError(`Failed to load data for ${n}`),{success:!1,error:`Failed to load ${n}`}}}async initialize(){this.showLoading(),await this.validateInitialSymbol(),this.subscribeToData()}async validateInitialSymbol(){try{const t=this.wsManager.getApiService();if(!t)return void(this.debug&&console.log("[OptionsWidget] API service not available for initial validation"));const e=await t.quoteOptionl1(this.symbol);if(e&&e[0]&&!e[0].error&&!e[0].not_found){const t=e[0];this.initialValidationData=t,this.debug&&console.log("[OptionsWidget] Initial symbol validated:",{symbol:this.symbol,underlying:t.Underlying||t.RootSymbol})}}catch(t){this.debug&&console.warn("[OptionsWidget] Initial symbol validation failed:",t)}}subscribeToData(){this.unsubscribe=this.wsManager.subscribe(this.widgetId,["queryoptionl1"],this.handleMessage.bind(this),this.symbol)}handleData(t){if(this.loadingTimeout&&(clearTimeout(this.loadingTimeout),this.loadingTimeout=null),"error"!==t.type){if(t.RootSymbol===this.symbol||t.Underlying===this.symbol||t.Symbol?.includes(this.symbol))if(this.debug&&console.log("[OptionsWidget] Found matching options data for",this.symbol,":",t),!0===t.NotFound)this.data?(this.hideLoading(),this.debug&&console.log("[OptionsWidget] No new data, keeping cached data visible")):this.showNoDataState(t);else{const e=new v(t);this.data=e,this.updateWidget(e)}else if(Array.isArray(t)){const e=t.find((t=>t.RootSymbol===this.symbol||t.Underlying===this.symbol||t.Symbol?.includes(this.symbol)));if(e)if(!0===e.NotFound)this.data?(this.hideLoading(),this.debug&&console.log("[OptionsWidget] No new data, keeping cached data visible")):this.showNoDataState(e);else{const t=new v(e);this.data=t,this.updateWidget(t)}else this.debug&&console.log("[OptionsWidget] No matching data in response, keeping cached data"),this.hideLoading()}t._cached&&this.showConnectionQuality()}else{const e=t.message||"Server error";this.data?(this.hideLoading(),this.debug&&console.log("[OptionsWidget] Error received but keeping cached data:",e)):this.showError(e)}}showNoDataState(t){if(!this.isDestroyed)try{this.hideLoading();const e=t.Symbol||this.symbol,n=this.container.querySelector(".symbol");n&&(n.textContent=e);const i=this.container.querySelector(".underlying-symbol");i&&(i.textContent=t.RootSymbol||this.symbol);const s=this.container.querySelector(".current-price");s&&(s.textContent="$0.00");const o=this.container.querySelector(".price-change");if(o){const t=o.querySelector(".change-value");t&&(t.textContent="+0.00");const e=o.querySelector(".change-percent");e&&(e.textContent=" (0.00%)"),o.classList.remove("positive","negative")}const a=this.container.querySelector(".widget-header");a&&a.classList.add("dimmed"),this.showNoDataMessage(e);const r=f(),c=this.container.querySelector(".last-update");c&&(c.textContent=`Checked: ${r}`)}catch(t){console.error("Error showing no data state:",t),this.showError("Error displaying no data state")}}showNoDataMessage(t){const e=this.container.querySelector(".data-grid"),n=this.container.querySelector(".option-details-section");e&&(e.style.display="none"),n&&(n.style.display="none");const i=this.container.querySelector(".no-data-state");i&&i.remove();const s=l("div","","no-data-state"),o=l("div","","no-data-content"),a=document.createElement("div");a.className="no-data-icon",a.innerHTML='<svg width="48" height="48" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <circle cx="12" cy="12" r="10" stroke="#9ca3af" stroke-width="2"/>\n <path d="M12 6v6l4 2" stroke="#9ca3af" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n </svg>',o.appendChild(a);const r=l("h3","No Data Available","no-data-title");o.appendChild(r);const c=l("p","","no-data-description");c.appendChild(document.createTextNode("Data for "));const d=l("strong",String(t));c.appendChild(d),c.appendChild(document.createTextNode(" was not found")),o.appendChild(c);const h=l("p","Please check the symbol or try again later","no-data-guidance");o.appendChild(h),s.appendChild(o);const u=this.container.querySelector(".widget-footer");u&&u.parentNode?u.parentNode.insertBefore(s,u):this.container.appendChild(s)}updateWidget(t){if(!this.isDestroyed)try{this.loadingTimeout&&(clearTimeout(this.loadingTimeout),this.loadingTimeout=null),this.hideLoading(),this.clearError();const e=this.container.querySelector(".widget-header");e&&e.classList.remove("dimmed");const n=this.container.querySelector(".data-grid");n&&(n.style.display="grid");const i=this.container.querySelector(".no-data-state");i&&i.remove();const s=this.container.querySelector(".symbol");s&&(s.textContent=t.symbol,s.dataset.originalSymbol=t.symbol);const o=this.container.querySelector(".underlying-symbol");o&&(o.textContent=t.rootSymbol||t.underlying||"QQQ");const a=this.container.querySelector(".current-price");a&&(a.textContent=t.formatLastPrice());const r=t.getChange(),c=this.container.querySelector(".price-change");if(c){const e=c.querySelector(".change-value"),n=c.querySelector(".change-percent");e&&(e.textContent=t.formatChange()),n&&(n.textContent=` (${t.formatChangePercent()})`),c.classList.remove("positive","negative","neutral"),r>0?c.classList.add("positive"):r<0?c.classList.add("negative"):c.classList.add("neutral")}const d=this.container.querySelector(".bid-data");if(d){u(d),d.appendChild(document.createTextNode(t.formatBid()));const e=l("span",`× ${t.bidSz}`,"size-info");d.appendChild(e)}const h=this.container.querySelector(".ask-data");if(h){u(h),h.appendChild(document.createTextNode(t.formatAsk()));const e=l("span",`× ${t.askSz}`,"size-info");h.appendChild(e)}const g=this.container.querySelector(".volume");g&&(g.textContent=t.formatVolume());const p=this.container.querySelector(".open-interest");p&&(p.textContent=t.formatOpenInterest());const m=this.container.querySelector(".day-range");m&&(m.textContent=t.formatDayRange());const b=this.container.querySelector(".open-price");b&&(b.textContent=t.formatOpenPx());const y=this.container.querySelector(".yesterday-close");y&&(y.textContent=t.formatYestClosePx());const x=this.container.querySelector(".strike-price");x&&(x.textContent=t.formatStrike());const v=this.container.querySelector(".expiry-date");v&&(v.textContent=t.formatExpirationDate());const w=this.container.querySelector(".prime-share");w&&(w.textContent=t.formatPrimeShare());const S=f(t.quoteTime||Date.now()),k=this.container.querySelector(".last-update");k&&(k.textContent=`Last update: ${S}`);const M=this.container.querySelector(".data-source");M&&(M.textContent=`Source: ${t.getDataSource()}`)}catch(t){console.error("Error updating options widget:",t),this.showError("Error updating data")}}formatPrice(t){return t?t.toFixed(2):"0.00"}formatPriceChange(t){return`${t>=0?"+":""}${t.toFixed(2)}`}showLoading(){const t=this.container.querySelector(".widget-loading-overlay");t&&t.classList.remove("hidden")}hideLoading(){const t=this.container.querySelector(".widget-loading-overlay");t&&t.classList.add("hidden")}showError(t){this.hideLoading(),this.clearError();const e=document.createElement("div");e.className="widget-error",e.textContent=`Error: ${t}`,e.style.cssText="\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n padding: 15px 20px;\n background: #fee;\n border: 1px solid #f5c6cb;\n border-radius: 6px;\n color: #721c24;\n text-align: center;\n font-size: 14px;\n z-index: 100;\n ",this.container.appendChild(e)}clearError(){const t=this.container.querySelector(".widget-error"),e=this.container.querySelector(".widget-error-container");t&&t.remove(),e&&e.remove()}destroy(){this.isDestroyed=!0,this.loadingTimeout&&(this.clearTimeout(this.loadingTimeout),this.loadingTimeout=null),this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=null),this.symbolEditor&&(this.symbolEditor.destroy(),this.symbolEditor=null),super.destroy()}}class S{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.openInterest=t.OpenInst||0,this.volume=t.Vol||0,this.askSize=t.AskSz||0,this.bidSize=t.BidSz||0,this.strike=t.Strike||0,this.askPrice=t.AskPx||0,this.bidPrice=t.BidPx||0,this.lastChange=t.LastChg||0,this.lastPrice=t.LastPx||0,this.dataSource=t.DataSource||"",this.expire=t.Expire||"",this.symbol=t.Symbol||""}}const k=`\n${o}\n\n/* Base styles remain the same until responsive section */\n.option-chain-widget {\n border: 1px solid #e5e7eb;\n border-radius: 8px;\n background: white;\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;\n font-size: 13px;\n max-width: 100%;\n overflow: hidden;\n position: relative;\n}\n\n.option-chain-widget .widget-header {\n background: #f9fafb;\n padding: 16px;\n border-bottom: 1px solid #e5e7eb;\n}\n\n.option-chain-widget .input-section {\n display: flex;\n gap: 12px;\n align-items: center;\n flex-wrap: wrap;\n}\n\n.option-chain-widget .symbol-input,\n.option-chain-widget .date-select {\n padding: 8px 12px;\n border: 1px solid #d1d5db;\n border-radius: 4px;\n font-size: 14px;\n font-family: inherit;\n min-width: 0;\n flex: 1;\n}\n\n.option-chain-widget .symbol-input {\n text-transform: uppercase;\n min-width: 100px;\n max-width: 120px;\n}\n\n.option-chain-widget .date-select {\n min-width: 140px;\n background: white;\n}\n\n.option-chain-widget .fetch-button {\n padding: 8px 16px;\n background: #3b82f6;\n color: white;\n border: none;\n border-radius: 4px;\n font-size: 14px;\n cursor: pointer;\n font-family: inherit;\n white-space: nowrap;\n}\n\n.option-chain-widget .fetch-button:hover {\n background: #2563eb;\n}\n\n.option-chain-widget .fetch-button:disabled {\n background: #9ca3af;\n cursor: not-allowed;\n}\n\n.option-chain-widget .date-select:disabled {\n background: #f3f4f6;\n color: #9ca3af;\n cursor: not-allowed;\n}\n\n.option-chain-widget .option-chain-table {\n max-height: 800px;\n overflow-x: auto; /* Enable horizontal scrolling */\n overflow-y: auto; /* Enable vertical scrolling if needed */\n -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */\n width: 100%; /* Ensure full width */\n position: relative; /* Establish positioning context */\n box-sizing: border-box; /* Include padding and border in the element's total width and height */\n}\n\n.option-chain-widget .table-header {\n background: #f3f4f6;\n font-weight: 600;\n border-bottom: 2px solid #d1d5db;\n position: sticky;\n top: 0;\n z-index: 10;\n width: fit-content; /* Ensure it spans the full width */\n box-sizing: border-box; /* Include padding and border in the element's total width and height */\n}\n\n.option-chain-widget .price-change.positive::before,\n.option-chain-widget .price-change.negative::before {\n content: none;\n}\n \n\n/* Better approach - make section headers align with actual column structure */\n.option-chain-widget .section-headers,\n.option-chain-widget .column-headers {\n\n display: grid;\n grid-template-columns: minmax(160px, 1fr) repeat(6, minmax(80px, 1fr)) 80px minmax(160px, 1fr) repeat(6, minmax(80px, 1fr));\n border-bottom: 1px solid #d1d5db;\n background: #f3f4f6;\n position: sticky;\n top: 0;\n z-index: 12;\n box-sizing: border-box; /* Include padding and border in the element's total width and height */\n margin: 0;\n padding: 0;\n min-width: fit-content;\n}\n\n.option-chain-widget .calls-header {\n grid-column: 1 / 8; /* Span across first 7 columns */\n padding: 8px;\n text-align: center;\n font-weight: 600;\n font-size: 14px;\n color: #374151;\n display: flex;\n align-items: center;\n justify-content: center;\n background: #f3f4f6;\n}\n\n.option-chain-widget .strike-header {\n grid-column: 8 / 9; /* Strike column */\n background: #e5e7eb;\n display: flex;\n align-items: center;\n justify-content: center;\n}\n\n.option-chain-widget .puts-header {\n grid-column: 9 / -1; /* Span from column 9 to the end */\n padding: 8px;\n text-align: center;\n font-weight: 600;\n font-size: 14px;\n color: #374151;\n display: flex;\n align-items: center;\n justify-content: center;\n background: #f3f4f6;\n}\n\n.option-chain-widget .column-headers {\n display: grid;\n grid-template-columns: minmax(160px, 1fr) repeat(6, minmax(80px, 1fr)) 80px minmax(160px, 1fr) repeat(6, minmax(80px, 1fr));\n position: sticky;\n top: 40px;\n z-index: 11;\n background: #f3f4f6;\n}\n\n.option-chain-widget .calls-columns,\n.option-chain-widget .puts-columns {\n display: contents; /* Remove their own grid, use parent grid */\n}\n\n.option-chain-widget .strike-column {\n display: flex;\n align-items: center;\n justify-content: center;\n background: #e5e7eb !important;\n font-weight: bold;\n color: #374151;\n font-size: 11px;\n text-transform: uppercase;\n}\n\n.option-chain-widget .strike-column span {\n background: transparent !important; /* Ensure span doesn't override parent background */\n}\n\n.option-chain-widget .column-headers span {\n padding: 6px 2px; /* Reduce padding to prevent text overflow */\n text-align: center;\n font-size: 11px; /* Reduce font size */\n text-transform: uppercase;\n color: #6b7280;\n font-weight: 600;\n letter-spacing: 0.3px; /* Reduce letter spacing */\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n background: #f3f4f6;\n}\n\n.option-chain-widget .option-row {\n display: grid;\n grid-template-columns: minmax(160px, 1fr) repeat(6, minmax(80px, 1fr)) 80px minmax(160px, 1fr) repeat(6, minmax(80px, 1fr));\n border-bottom: 1px solid #f3f4f6;\n min-height: 32px;\n}\n\n.option-chain-widget .option-row:hover {\n background: #f9fafb;\n}\n .option-chain-widget .option-row:hover .calls-data span,\n.option-chain-widget .option-row:hover .puts-data span,\n.option-chain-widget .option-row:hover .strike-data {\n background: #f9fafb;\n}\n\n.option-chain-widget .calls-data,\n.option-chain-widget .puts-data {\n display: contents; /* Make children participate in parent grid */\n}\n\n.option-chain-widget .strike-data {\n display: flex;\n align-items: center;\n justify-content: center;\n background: #f9fafb;\n font-weight: 600; /* Changed from bold to 600 for consistency */\n color: #6b7280; /* Changed from #1f2937 to match other widgets */\n}\n\n.option-chain-widget .calls-data span,\n.option-chain-widget .puts-data span {\n padding: 6px 4px;\n text-align: center;\n font-size: 12px; /* Changed from 12px to 14px */\n font-weight: 400; /* Added to match data values in other widgets */\n color: #111827; /* Changed from #374151 to match other widgets */\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n\n.option-chain-widget .contract-cell {\n font-size: 10px;\n color: #6b7280;\n text-align: left;\n padding: 4px 6px;\n font-family: monospace;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n\n.option-chain-widget .positive {\n color: #059669;\n}\n\n.option-chain-widget .negative {\n color: #dc2626;\n}\n\n.option-chain-widget .neutral {\n color: #6b7280;\n}\n\n.option-chain-widget .widget-footer {\n background: #f9fafb;\n padding: 8px 16px;\n border-top: 1px solid #e5e7eb;\n text-align: center;\n font-size: 11px;\n color: #6b7280;\n}\n\n.option-chain-widget .widget-loading-overlay {\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background: rgba(255, 255, 255, 0.9);\n display: flex;\n align-items: center;\n justify-content: center;\n z-index: 20;\n}\n\n.option-chain-widget .widget-loading-overlay.hidden {\n display: none;\n}\n\n.option-chain-widget .loading-content {\n text-align: center;\n}\n\n.option-chain-widget .loading-spinner {\n width: 32px;\n height: 32px;\n border: 3px solid #e5e7eb;\n border-top: 3px solid #3b82f6;\n border-radius: 50%;\n animation: spin 1s linear infinite;\n margin: 0 auto 12px;\n}\n\n@keyframes spin {\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n}\n\n.option-chain-widget .no-data-state {\n padding: 40px;\n text-align: center;\n color: #6b7280;\n}\n\n.option-chain-widget .widget-error {\n padding: 20px;\n background: #fef2f2;\n color: #dc2626;\n border: 1px solid #fecaca;\n margin: 16px;\n border-radius: 4px;\n text-align: center;\n}\n\n/* RESPONSIVE STYLES */\n\n/* Tablet styles (768px and down) */\n@media (max-width: 768px) {\n .option-chain-widget .input-section {\n flex-direction: column;\n align-items: stretch;\n gap: 8px;\n }\n \n .option-chain-widget .symbol-input,\n .option-chain-widget .date-select {\n width: 100%;\n max-width: none;\n }\n \n .option-chain-widget .fetch-button {\n width: 100%;\n }\n \n .option-chain-widget .calls-columns,\n .option-chain-widget .puts-columns {\n grid-template-columns: 120px repeat(6, minmax(50px, 1fr));\n }\n \n .option-chain-widget .calls-data,\n .option-chain-widget .puts-data {\n grid-template-columns: 120px repeat(6, minmax(50px, 1fr));\n }\n \n .option-chain-widget .column-headers span {\n font-size: 10px;\n padding: 6px 2px;\n }\n \n .option-chain-widget .calls-data span,\n .option-chain-widget .puts-data span {\n font-size: 11px;\n padding: 4px 2px;\n }\n \n .option-chain-widget .contract-cell {\n font-size: 9px;\n padding: 4px 4px;\n }\n \n .option-chain-widget .strike-data {\n font-size: 12px;\n }\n\n /* Update responsive breakpoints to match */\n .option-chain-widget .section-headers {\n grid-template-columns: 1fr 80px 1fr;\n background: #f3f4f6;\n width: 100%;\n\n }\n}\n\n/* Mobile styles (480px and down) */\n@media (max-width: 480px) {\n .option-chain-widget {\n font-size: 12px;\n }\n \n .option-chain-widget .widget-header {\n padding: 12px;\n }\n \n .option-chain-widget .section-headers {\n grid-template-columns: 1fr 60px 1fr;\n background: #f3f4f6;\n }\n \n .option-chain-widget .column-headers {\n grid-template-columns: 1fr 60px 1fr;\n }\n \n .option-chain-widget .option-row {\n grid-template-columns: 1fr 60px 1fr;\n min-height: 28px;\n }\n \n .option-chain-widget .calls-columns,\n .option-chain-widget .puts-columns {\n grid-template-columns: 100px repeat(6, minmax(40px, 1fr));\n }\n \n .option-chain-widget .calls-data,\n .option-chain-widget .puts-data {\n grid-template-columns: 100px repeat(6, minmax(40px, 1fr));\n }\n \n .option-chain-widget .column-headers span {\n font-size: 9px;\n padding: 4px 1px;\n }\n \n .option-chain-widget .calls-data span,\n .option-chain-widget .puts-data span {\n font-size: 10px;\n padding: 3px 1px;\n }\n \n .option-chain-widget .contract-cell {\n font-size: 8px;\n padding: 3px 2px;\n }\n \n .option-chain-widget .strike-data {\n font-size: 11px;\n padding: 3px;\n }\n \n \n .option-chain-widget .option-chain-table {\n max-height: 400px;\n }\n \n .option-chain-widget .no-data-state {\n padding: 20px;\n font-size: 12px;\n }\n \n .option-chain-widget .widget-error {\n margin: 8px;\n padding: 12px;\n font-size: 12px;\n }\n}\n\n/* Very small mobile (320px and down) */\n@media (max-width: 320px) {\n .option-chain-widget .section-headers {\n grid-template-columns: 1fr 50px 1fr;\n }\n \n .option-chain-widget .column-headers {\n grid-template-columns: 1fr 50px 1fr;\n }\n \n .option-chain-widget .option-row {\n grid-template-columns: 1fr 50px 1fr;\n }\n \n .option-chain-widget .calls-columns,\n .option-chain-widget .puts-columns {\n grid-template-columns: 80px repeat(6, minmax(35px, 1fr));\n }\n \n .option-chain-widget .calls-data,\n .option-chain-widget .puts-data {\n grid-template-columns: 80px repeat(6, minmax(35px, 1fr));\n }\n \n .option-chain-widget .column-headers span {\n font-size: 8px;\n padding: 3px 1px;\n }\n \n .option-chain-widget .calls-data span,\n .option-chain-widget .puts-data span {\n font-size: 9px;\n padding: 2px 1px;\n }\n \n .option-chain-widget .contract-cell {\n font-size: 7px;\n padding: 2px 1px;\n }\n}\n`;class M extends n{constructor(t,e,n){if(super(t,e,n),!e.wsManager)throw new Error("WebSocketManager is required for OptionChainWidget");if(this.type="optionchain",this.wsManager=e.wsManager,this.debug=e.debug||!1,this.data=null,this.isDestroyed=!1,this.unsubscribe=null,this.loadingTimeout=null,e.symbol){const t=g(e.symbol);t.valid?this.symbol=t.sanitized:(console.warn("[OptionChainWidget] Invalid initial symbol:",t.error),this.symbol="")}else this.symbol="";this.date="",this.availableDates={},this.fetchRateLimiter=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:500,e=0;return()=>{const n=Date.now(),i=n-e;return i<t?{valid:!1,error:`Please wait ${Math.ceil((t-i)/1e3)} seconds`,remainingMs:t-i}:(e=n,{valid:!0})}}(1e3),this.createWidgetStructure(),this.initialize()}createWidgetStructure(){this.container.innerHTML='\n <div class="option-chain-widget widget">\n <div class="widget-content">\n \x3c!-- Header Section --\x3e\n <div class="widget-header">\n <div class="input-section">\n <input type="text" class="symbol-input" placeholder="Enter Symbol" value="" />\n <select class="date-select" disabled>\n <option value="">Select a date...</option>\n </select>\n <button class="fetch-button" disabled>Search</button>\n </div>\n </div>\n\n \x3c!-- Data Grid Section --\x3e\n <div class="option-chain-table">\n <div class="table-header">\n <div class="section-headers">\n <div class="calls-header">Calls</div>\n <div class="strike-header"></div>\n <div class="puts-header">Puts</div>\n </div>\n <div class="column-headers">\n <div class="calls-columns">\n <span>Contract</span>\n <span>Last</span>\n <span>Change</span>\n <span>Bid</span>\n <span>Ask</span>\n <span>Volume</span>\n <span>Open Int.</span>\n </div>\n <div class="strike-column">\n <span>Strike</span>\n </div>\n <div class="puts-columns">\n <span>Contract</span>\n <span>Last</span>\n <span>Change</span>\n <span>Bid</span>\n <span>Ask</span>\n <span>Volume</span>\n <span>Open Int.</span>\n </div>\n </div>\n </div>\n <div class="option-chain-data-grid">\n \x3c!-- Option chain data will be populated here --\x3e\n </div>\n </div>\n\n \x3c!-- Footer --\x3e\n <div class="widget-footer">\n <span class="last-update"></span>\n <span class="data-source"></span>\n </div>\n </div>\n \n \x3c!-- Loading Overlay --\x3e\n <div class="widget-loading-overlay hidden">\n <div class="loading-content">\n <div class="loading-spinner"></div>\n <span class="loading-text">Loading option chain data...</span>\n </div>\n </div>\n </div>\n',this.addStyles(),this.setupEventListeners()}addStyles(){if(!document.querySelector("#option-chain-styles")){const t=document.createElement("style");t.id="option-chain-styles",t.textContent=k,document.head.appendChild(t)}}setupEventListeners(){this.symbolInput=this.container.querySelector(".symbol-input"),this.dateSelect=this.container.querySelector(".date-select"),this.fetchButton=this.container.querySelector(".fetch-button"),this.dataGrid=this.container.querySelector(".option-chain-data-grid"),this.symbol&&(this.symbolInput.value=this.symbol,this.fetchButton.disabled=!1,this.dateSelect.innerHTML='<option value="">Click search to load dates...</option>'),this.addEventListener(this.symbolInput,"input",(t=>{const e=t.target.value,n=g(e);this.clearInputError(this.symbolInput),n.valid?(this.symbol=n.sanitized,this.symbolInput.value=n.sanitized,this.dateSelect.innerHTML='<option value="">Click search to load dates...</option>',this.dateSelect.disabled=!0,this.fetchButton.disabled=!1,this.availableDates={},this.date=""):""!==e.trim()?(this.showInputError(this.symbolInput,n.error),this.fetchButton.disabled=!0):this.clearDateOptions()})),this.addEventListener(this.dateSelect,"change",(t=>{const e=t.target.value;if(!e)return void(this.date="");const n=function(t){if(!t||"string"!=typeof t)return{valid:!1,error:"Date is required",normalized:""};const e=t.trim();let n;if(/^\d{4}-\d{2}-\d{2}$/.test(e))n=new Date(e);else if(/^\d{2}\/\d{2}\/\d{4}$/.test(e)){const[t,i,s]=e.split("/");n=new Date(s,parseInt(t,10)-1,parseInt(i,10))}else{if(!/^\d+$/.test(e))return{valid:!1,error:"Invalid date format. Use YYYY-MM-DD or MM/DD/YYYY",normalized:""};n=new Date(parseInt(e,10))}return isNaN(n.getTime())?{valid:!1,error:"Invalid date",normalized:""}:{valid:!0,normalized:n.toISOString().split("T")[0]}}(e);n.valid?(this.date=n.normalized,this.symbol&&this.fetchOptionChain()):(this.showError(n.error),this.date="")})),this.addEventListener(this.fetchButton,"click",(()=>{const t=g(this.symbol);if(!t.valid)return void this.showError(t.error||"Please enter a valid symbol first");const e=this.fetchRateLimiter();e.valid?this.loadAvailableDates(t.sanitized):this.showError(e.error)}))}async loadAvailableDates(t){if(t)try{this.symbol=t,this.symbolInput.value=t,this.dateSelect.disabled=!0,this.dateSelect.innerHTML='<option value="">Loading dates...</option>',this.fetchButton.disabled=!0;const e=this.wsManager.getApiService(),n=await e.getOptionChainDates(t);console.log("Available dates:",n.dates_dictionary),this.availableDates=n.dates_dictionary||{},this.populateDateOptions()}catch(e){console.error("[OptionChainWidget] Error loading dates:",e),this.dateSelect.innerHTML='<option value="">Error loading dates</option>',this.fetchButton.disabled=!1,this.showError(`Failed to load dates for ${t}: ${e.message}`)}}populateDateOptions(){this.dateSelect.innerHTML='<option value="">Select expiration date...</option>';const t=Object.keys(this.availableDates).sort();if(0===t.length)return this.dateSelect.innerHTML='<option value="">No dates available</option>',void(this.fetchButton.disabled=!1);t.forEach((t=>{const e=document.createElement("option");e.value=t;const n=this.availableDates[t],i=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const{timezone:n="ET",format:i="short"}=e;if(!t||"string"!=typeof t)return"";const s=t.split("-");if(3!==s.length)return t;const[o,a,r]=s,c=parseInt(a,10)-1,l=parseInt(r,10),d=("long"===i?["January","February","March","April","May","June","July","August","September","October","November","December"]:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"])[c];return`${d} ${l}, ${o}`}(t,{timezone:m(t),format:"short"});e.textContent=i,e.className=`date-option ${n}`,this.dateSelect.appendChild(e)})),this.dateSelect.disabled=!1,this.fetchButton.disabled=!1,t.length>0&&(this.dateSelect.value=t[0],this.date=t[0],this.fetchOptionChain())}clearDateOptions(){this.dateSelect.innerHTML='<option value="">Click fetch to load dates...</option>',this.dateSelect.disabled=!0,this.fetchButton.disabled=!this.symbol,this.symbol=this.symbolInput.value.trim().toUpperCase()||"",this.date="",this.availableDates={}}initialize(){this.hideLoading(),this.symbol&&this.loadAvailableDates(this.symbol)}fetchOptionChain(){if(this.symbol&&this.date)try{this.showLoading(),this.loadingTimeout&&this.clearTimeout(this.loadingTimeout),this.loadingTimeout=this.setTimeout((()=>{this.debug&&console.log("[OptionChainWidget] Loading timeout for:",this.symbol,this.date),this.hideLoading(),this.showError(`No data received for ${this.symbol} on ${this.date}. Please try again.`)}),1e4),this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=null),this.subscribeToData()}catch(t){console.error("[OptionChainWidget] Error fetching option chain:",t),this.showError(`Failed to load data for ${this.symbol}`)}else console.warn("[OptionChainWidget] Missing symbol or date")}subscribeToData(){this.unsubscribe=this.wsManager.subscribe(this.widgetId,["queryoptionchain"],this.handleMessage.bind(this),this.symbol,{date:this.date})}handleData(t){if(this.loadingTimeout&&(clearTimeout(this.loadingTimeout),this.loadingTimeout=null),"error"!==t.type)Array.isArray(t)?0===t.length?this.data?(this.hideLoading(),this.debug&&console.log("[OptionChainWidget] No new data, keeping cached data visible")):this.showNoDataState():(this.data=t,this.displayOptionChain(t)):"queryoptionchain"===t.type&&Array.isArray(t.data)&&(0===t.data.length?this.data?(this.hideLoading(),this.debug&&console.log("[OptionChainWidget] No new data, keeping cached data visible")):this.showNoDataState():(this.data=t.data,this.displayOptionChain(t.data))),t._cached&&this.showConnectionQuality();else{const e=t.message||"Server error";this.data?(this.hideLoading(),this.debug&&console.log("[OptionChainWidget] Error received but keeping cached data:",e)):this.showError(e)}}displayOptionChain(t){if(!this.isDestroyed)try{this.hideLoading(),this.clearError(),this.dataGrid.innerHTML="";const e={};t.forEach((t=>{const n=new S(t),i=n.strike;e[i]||(e[i]={call:null,put:null});"call"===C(n.symbol)?e[i].call=n:e[i].put=n}));if(Object.keys(e).sort(((t,e)=>parseFloat(t)-parseFloat(e))).forEach((t=>{const{call:n,put:i}=e[t],s=document.createElement("div");s.classList.add("option-row");const o=t=>{const e=document.createElement("span");if(!t||0===t)return e.className="neutral",e.textContent="0.00",e;const n=parseFloat(t).toFixed(2),i=t>0?"positive":t<0?"negative":"neutral",s=t>0?"+":"";return e.className=`option-chain-${i}`,e.textContent=`${s}${n}`,e},a=t=>d(t,2,"0.00"),r=document.createElement("div");r.className="calls-data",r.appendChild(l("span",n?h(n.symbol):"--","contract-cell")),r.appendChild(l("span",a(n?.lastPrice)));const c=document.createElement("span");n?c.appendChild(o(n.lastChange)):(c.textContent="0.00",c.className="neutral"),r.appendChild(c),r.appendChild(l("span",a(n?.bidPrice))),r.appendChild(l("span",a(n?.askPrice))),r.appendChild(l("span",n?String(n.volume):"0")),r.appendChild(l("span",n?String(n.openInterest):"0"));const u=document.createElement("div");u.className="strike-data",u.textContent=t;const g=document.createElement("div");g.className="puts-data",g.appendChild(l("span",i?h(i.symbol):"","contract-cell")),g.appendChild(l("span",a(i?.lastPrice)));const p=document.createElement("span");i?p.appendChild(o(i.lastChange)):(p.textContent="0.00",p.className="neutral"),g.appendChild(p),g.appendChild(l("span",a(i?.bidPrice))),g.appendChild(l("span",a(i?.askPrice))),g.appendChild(l("span",i?String(i.volume):"0")),g.appendChild(l("span",i?String(i.openInterest):"0")),s.appendChild(r),s.appendChild(u),s.appendChild(g),this.dataGrid.appendChild(s)})),t&&t.length>0){const e=f(t[0].quoteTime||Date.now()),n=this.container.querySelector(".last-update");n&&(n.textContent=`Last update: ${e}`);const i="OPRA-D"===t[0].DataSource?"20 mins delayed":"Real-time",s=this.container.querySelector(".data-source");s&&(s.textContent=`Source: ${i}`)}}catch(t){console.error("Error displaying option chain:",t),this.showError("Error displaying data")}}showLoading(){const t=this.container.querySelector(".widget-loading-overlay");t&&t.classList.remove("hidden")}hideLoading(){const t=this.container.querySelector(".widget-loading-overlay");t&&t.classList.add("hidden")}showError(t){this.hideLoading(),this.clearError();const e=document.createElement("div");e.className="widget-error",e.textContent=`Error: ${t}`,e.style.cssText="\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n padding: 15px 20px;\n background: #fee;\n border: 1px solid #f5c6cb;\n border-radius: 6px;\n color: #721c24;\n text-align: center;\n font-size: 14px;\n z-index: 100;\n ",this.container.appendChild(e)}clearError(){const t=this.container.querySelector(".widget-error"),e=this.container.querySelector(".widget-error-container");t&&t.remove(),e&&e.remove()}showNoDataState(){this.hideLoading(),this.clearError();const t=l("div","","no-data-state"),e=l("div","","no-data-content"),n=document.createElement("div");n.className="no-data-icon",n.innerHTML='<svg width="32" height="32" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <circle cx="12" cy="12" r="10" stroke="#9ca3af" stroke-width="2"/>\n <path d="M12 6v6l4 2" stroke="#9ca3af" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n </svg>',e.appendChild(n);const i=l("h3","No Option Chain Data","no-data-title");e.appendChild(i);const s=l("p","","no-data-description");s.appendChild(document.createTextNode("Option chain data for "));const o=l("strong",h(this.symbol));s.appendChild(o),s.appendChild(document.createTextNode(" on "));const a=l("strong",String(this.date));s.appendChild(a),s.appendChild(document.createTextNode(" was not found")),e.appendChild(s);const r=l("p","Please check the symbol and date or try again later","no-data-guidance");e.appendChild(r),t.appendChild(e);const c=this.container.querySelector(".widget-footer");c&&c.parentNode?c.parentNode.insertBefore(t,c):this.container.appendChild(t)}destroy(){this.isDestroyed=!0,this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=null),this.loadingTimeout&&(this.clearTimeout(this.loadingTimeout),this.loadingTimeout=null),super.destroy()}}const C=t=>{const e=t.match(/^(.+?)(\d{6})([CP])(\d{8})$/);if(e){const[,t,n,i,s]=e;return"C"===i?"call":"put"}return null};class _ extends n{constructor(t,e,n){if(super(t,e,n),!e.symbol)throw new Error("Symbol is required for DataWidget");if(!e.wsManager)throw new Error("WebSocketManager is required for DataWidget");this.type="data",this.symbol=(e.symbol||"").toString().toUpperCase(),this.wsManager=e.wsManager,this.dataSource=e.dataSource||"queryl1",this.debug=e.debug||!1,this.data=null,this.isDestroyed=!1,this.unsubscribe=null,this.loadingTimeout=null,this.createWidgetStructure(),this.initializeSymbolEditor(),this.initialize()}createWidgetStructure(){this.container.innerHTML='\n <div class="data-widget widget">\n <div class="widget-content">\n \x3c!-- Header Section --\x3e\n <div class="widget-header">\n <div class="symbol-section">\n <h1 class="symbol editable-symbol" \n title="Double-click to edit symbol" \n data-original-symbol="">\n </h1>\n <div class="company-info">\n <span class="data-type">Stock</span>\n <span class="company-name"></span>\n </div>\n </div>\n </div>\n\n \x3c!-- Price Section --\x3e\n <div class="price-section">\n <div class="current-price"></div>\n <div class="price-change">\n <span class="change-value"></span>\n <span class="change-percent"></span>\n </div>\n </div>\n\n \x3c!-- Bid/Ask Section --\x3e\n <div class="bid-ask-section">\n <div class="ask">\n <span class="label">Ask</span>\n <span class="value ask-price"></span>\n <span class="size ask-size"></span>\n </div>\n <div class="bid">\n <span class="label">Bid</span>\n <span class="value bid-price"></span>\n <span class="size bid-size"></span>\n </div>\n </div>\n\n \x3c!-- Footer --\x3e\n <div class="widget-footer">\n <span class="last-size">Last Size: <span class="trade-size"></span></span>\n <span class="source">Market Data Powered by MDAS</span>\n </div>\n </div>\n\n \n </div>\n',this.addStyles()}addStyles(){if(!document.querySelector("#data-styles")){const t=document.createElement("style");t.id="data-styles",t.textContent="\n .data-widget {\n position: relative;\n border: 1px solid #ddd;\n border-radius: 8px;\n overflow: hidden;\n background-color: #fff;\n box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);\n padding: 10px;\n font-family: Arial, sans-serif;\n }\n\n .widget-header {\n display: flex;\n flex-direction: column;\n margin-bottom: 10px;\n }\n\n .symbol {\n font-size: 24px;\n font-weight: bold;\n margin-right: 10px;\n }\n\n .company-info {\n font-size: 12px;\n color: #666;\n }\n\n .trading-info {\n font-size: 12px;\n color: #999;\n }\n\n .price-section {\n display: flex;\n align-items: baseline;\n margin-bottom: 10px;\n }\n\n .current-price {\n font-size: 36px;\n font-weight: bold;\n margin-right: 10px;\n }\n\n .price-change {\n font-size: 18px;\n }\n\n .price-change.positive {\n color: green;\n }\n\n .price-change.negative {\n color: red;\n }\n\n .bid-ask-section {\n display: flex;\n justify-content: space-between;\n margin-bottom: 10px;\n }\n\n .ask, .bid {\n display: flex;\n align-items: center;\n }\n\n .label {\n font-size: 14px;\n margin-right: 5px;\n }\n\n .value {\n font-size: 16px;\n font-weight: bold;\n margin-right: 5px;\n }\n\n .size {\n font-size: 14px;\n color: red;\n }\n\n .widget-footer {\n font-size: 12px;\n color: #333;\n }\n",document.head.appendChild(t)}}initializeSymbolEditor(){this.symbolEditor=new s(this,{maxLength:10,placeholder:"Enter symbol...",onSymbolChange:this.handleSymbolChange.bind(this),debug:this.debug,autoUppercase:!0,symbolType:"quotel1"});const t=this.container.querySelector(".symbol");t&&(t.textContent=this.symbol,t.dataset.originalSymbol=this.symbol)}async handleSymbolChange(t){this.debug&&console.log("[DataWidget] Symbol change requested:",t);const e=t.toUpperCase();if(e===this.symbol)return this.debug&&console.log("[DataWidget] Same symbol, no change needed"),{success:!0};try{const t=this.symbol;return this.showLoading(),this.loadingTimeout&&clearTimeout(this.loadingTimeout),this.loadingTimeout=setTimeout((()=>{this.debug&&console.log("[DataWidget] Loading timeout for symbol:",e),this.hideLoading(),this.showError(`No data received for ${e}. Please try again.`)}),1e4),this.unsubscribe&&(this.debug&&console.log(`[DataWidget] Unsubscribing from ${t}`),this.wsManager.sendUnsubscribe(this.dataSource,t),this.unsubscribe(),this.unsubscribe=null),this.symbol=e,this.debug&&console.log(`[DataWidget] Subscribing to ${e}`),this.subscribeToData(),this.debug&&console.log(`[DataWidget] Successfully changed symbol from ${t} to ${e}`),{success:!0}}catch(t){return console.error("[DataWidget] Error changing symbol:",t),this.hideLoading(),this.showError(`Failed to load data for ${e}`),{success:!1,error:`Failed to load ${e}`}}}initialize(){this.showLoading(),this.subscribeToData()}subscribeToData(){this.unsubscribe=this.wsManager.subscribe(this.widgetId,[this.dataSource],this.handleMessage.bind(this),this.symbol)}showNoDataState(t){let{Symbol:e,NotFound:n,message:i}=t;this.clearError(),this.hideLoading();const s=document.createElement("div");s.className="no-data-state",s.innerHTML=`\n <div class="no-data-content">\n <div class="no-data-icon">\n <svg width="32" height="32" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">\n <circle cx="12" cy="12" r="10" stroke="#9ca3af" stroke-width="2"/>\n <path d="M12 6v6l4 2" stroke="#9ca3af" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>\n </svg>\n </div>\n <h3 class="no-data-title">No Data Available</h3>\n <p class="no-data-description">Data for <strong>${e}</strong> was not found.</p>\n <p class="no-data-guidance">${i||"Please check the symbol or try again later."}</p>\n </div>\n `,this.container.appendChild(s)}handleData(t){if(this.loadingTimeout&&(clearTimeout(this.loadingTimeout),this.loadingTimeout=null),"error"===t.type&&t.noData)return this.debug&&console.log("[DataWidget] Received no data message:",t.message),void this.showNoDataState({Symbol:this.symbol,NotFound:!0,message:t.message});if("error"!==t.type){if(t.Data&&t.Data.length>0){const e=t.Data.find((t=>t.Symbol===this.symbol));if(e){const t=new i(e);this.updateWidget(t)}else console.log("hereee"),this.showNoDataState({Symbol:this.symbol,NotFound:!0,message:`No data found for ${this.symbol}`})}t._cached&&this.showConnectionQuality()}else{const e=t.message||"Server error";this.showError(e)}}updateWidget(t){if(!this.isDestroyed)try{this.clearError(),this.hideLoading();const e=this.container.querySelector(".symbol");e&&(e.textContent=t.symbol,e.dataset.originalSymbol=t.symbol);const n=this.container.querySelector(".current-price");n&&(n.textContent=t.formatPrice());const i=this.container.querySelector(".price-change"),s=i.querySelector(".change-value"),o=i.querySelector(".change-percent");s.textContent=t.formatPriceChange(),o.textContent=` (${t.formatPriceChangePercent()})`,i.classList.remove("positive","negative","neutral"),t.getPriceChange()>0?i.classList.add("positive"):t.getPriceChange()<0?i.classList.add("negative"):i.classList.add("neutral");const a=this.container.querySelector(".bid-price");a&&(a.textContent=t.bidPrice.toFixed(2));const r=this.container.querySelector(".ask-price");r&&(r.textContent=t.askPrice.toFixed(2));const c=this.container.querySelector(".bid-size");c&&(c.textContent=`× ${t.bidSize}`);const l=this.container.querySelector(".ask-size");l&&(l.textContent=`× ${t.askSize}`);const d=this.container.querySelector(".trade-size");d&&(d.textContent=t.tradeSize);const h=this.container.querySelector(".last-update");if(h){const e=f(t.quoteTime);h.textContent=`Last update: ${e}`}const u=this.container.querySelector(".data-source");u&&(u.textContent=`Source: ${t.getDataSource()}`)}catch(t){console.error("Error updating widget:",t),this.showError("Error updating data")}}}class D extends n{constructor(t,e,n){if(super(t,e,n),!e.symbol)throw new Error("Symbol is required for CombinedMarketWidget");if(!e.wsManager)throw new Error("WebSocketManager is required for CombinedMarketWidget");const i=g(e.symbol);if(!i.valid)throw new Error(`Invalid symbol: ${i.error}`);this.type="combined-market",this.wsManager=e.wsManager,this.symbol=i.sanitized,this.debug=e.debug||!1,this.removeNightSession=!0,this.marketData=null,this.nightSessionData=null,this.unsubscribeMarket=null,this.unsubscribeNight=null,this.createWidgetStructure(),this.initializeSymbolEditor(),this.subscribeToData()}createWidgetStructure(){this.container.innerHTML='\n <div class="combined-market-widget">\n <div class="combined-market-header">\n <div class="combined-symbol-section">\n <h1 class="combined-symbol editable-symbol"\n title="Double-click to edit symbol"\n data-original-symbol="">\n </h1>\n <div class="combined-company-info">\n <span class="company-name">\n </span>\n </div>\n </div>\n </div>\n\n <div class="combined-data-container">\n \x3c!-- Regular Market Data (Left) --\x3e\n <div class="combined-market-section regular-market">\n <div class="combined-price-info">\n <div class="combined-current-price">--</div>\n <div class="combined-price-change neutral">\n <span class="combined-change-value">--</span>\n <span class="combined-change-percent">(--)</span>\n </div>\n </div>\n <div class="combined-market-status"><span class="market-status-label"></span> <span class="combined-timestamp">--</span></div>\n </div>\n\n \x3c!-- Night Session Data (Right) --\x3e\n <div class="combined-market-section night-session">\n\n <div class="combined-price-info">\n <div class="combined-current-price">--</div>\n <div class="combined-price-change neutral">\n <span class="combined-change-value">--</span>\n <span class="combined-change-percent">(--)</span>\n </div>\n </div>\n <div class="combined-market-status">Overnight: <span class="combined-timestamp">--</span></div>\n </div>\n </div>\n\n <div class="combined-loading-overlay hidden">\n <div class="combined-loading-content">\n <div class="combined-loading-spinner"></div>\n <span class="combined-loading-text">Loading market data...</span>\n </div>\n </div>\n </div>\n';const t=this.container.querySelector(".combined-symbol");if(t&&(t.textContent=this.symbol,t.dataset.originalSymbol=this.symbol),this.removeNightSession&&!this.isNightSessionActive()){const t=this.container.querySelector(".night-session");t&&(t.style.display="none")}this.addStyles()}addStyles(){if(!document.querySelector("#combined-market-styles")){const t=document.createElement("style");t.id="combined-market-styles",t.textContent='\n .combined-market-widget {\n background: #ffffff;\n color: #111827;\n padding: 24px;\n border-radius: 12px;\n border: 1px solid #e5e7eb;\n box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);\n font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;\n position: relative;\n }\n\n .combined-market-widget .combined-market-header {\n display: flex;\n justify-content: space-between;\n align-items: center;\n margin-bottom: 24px;\n padding-bottom: 16px;\n border-bottom: 1px solid #e5e7eb;\n }\n\n .combined-market-widget .combined-symbol-section {\n display: flex;\n flex-direction: column;\n gap: 4px;\n }\n\n .combined-market-widget .combined-symbol {\n font-size: 24px;\n font-weight: 700;\n margin: 0;\n color: #111827;\n cursor: pointer;\n transition: all 0.2s ease;\n position: relative;\n }\n\n .combined-market-widget .combined-symbol:hover {\n opacity: 0.8;\n transform: scale(1.02);\n }\n\n .combined-market-widget .combined-symbol:hover::after {\n content: "✎";\n position: absolute;\n top: -8px;\n right: -8px;\n background: #3b82f6;\n color: white;\n font-size: 10px;\n padding: 2px 4px;\n border-radius: 4px;\n opacity: 0.8;\n pointer-events: none;\n }\n\n .combined-market-widget .follow-btn {\n background: #ffffff;\n border: 1px solid #d1d5db;\n color: #374151;\n padding: 8px 16px;\n border-radius: 20px;\n cursor: pointer;\n font-size: 14px;\n font-weight: 500;\n transition: all 0.2s;\n }\n\n .combined-market-widget .follow-btn:hover {\n border-color: #9ca3af;\n background: #f9fafb;\n }\n\n .combined-market-widget .combined-data-container {\n display: grid;\n grid-template-columns: 1fr 1fr;\n gap: 40px;\n }\n\n .combined-market-widget .combined-market-section {\n display: flex;\n flex-direction: column;\n gap: 8px;\n }\n\n .combined-market-widget .combined-price-info {\n display: flex;\n flex-direction: column;\n min-height: 90px;\n }\n\n .combined-market-widget .session-label {\n display: flex;\n align-items: center;\n gap: 6px;\n font-size: 14px;\n color: #6b7280;\n margin-bottom: 4px;\n font-weight: 500;\n }\n\n .combined-market-widget .session-label .icon {\n font-size: 16px;\n }\n\n .combined-market-widget .combined-current-price {\n font-size: 48px;\n font-weight: 700;\n line-height: 1;\n color: #111827;\n }\n\n .combined-market-widget .combined-price-change {\n display: flex;\n gap: 8px;\n font-size: 20px;\n font-weight: 600;\n margin-top: 4px;\n }\n\n .combined-market-widget .combined-price-change.positive {\n color: #059669;\n }\n\n .combined-market-widget .combined-price-change.negative {\n color: #dc2626;\n }\n\n .combined-market-widget .combined-price-change.neutral {\n color: #6b7280;\n }\n\n .combined-market-widget .combined-market-status {\n font-size: 14px;\n color: #6b7280;\n margin-top: 8px;\n }\n\n .combined-market-widget .combined-timestamp {\n color: #9ca3af;\n font-weight: 400;\n }\n\n /* Loading overlay */\n .combined-market-widget .combined-loading-overlay {\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background: rgba(255, 255, 255, 0.95);\n backdrop-filter: blur(2px);\n display: flex;\n align-items: center;\n justify-content: center;\n border-radius: 12px;\n z-index: 10;\n }\n\n .combined-market-widget .combined-loading-overlay.hidden {\n display: none;\n }\n\n .combined-market-widget .combined-loading-content {\n display: flex;\n flex-direction: column;\n align-items: center;\n gap: 12px;\n }\n\n .combined-market-widget .combined-loading-spinner {\n width: 40px;\n height: 40px;\n border: 3px solid #e5e7eb;\n border-top-color: #3b82f6;\n border-radius: 50%;\n animation: combined-market-spin 1s linear infinite;\n }\n\n .combined-market-widget .combined-loading-text {\n color: #6b7280;\n font-size: 14px;\n font-weight: 500;\n }\n\n @keyframes combined-market-spin {\n to { transform: rotate(360deg); }\n }\n\n /* Responsive */\n @media (max-width: 768px) {\n .combined-market-widget .combined-data-container {\n grid-template-columns: 1fr;\n gap: 30px;\n }\n\n .combined-market-widget .combined-current-price {\n font-size: 36px;\n }\n\n .combined-market-widget .combined-price-change {\n font-size: 16px;\n }\n }\n',document.head.appendChild(t)}}initializeSymbolEditor(){this.symbolEditor=new s(this,{maxLength:10,placeholder:"Enter symbol...",onSymbolChange:this.handleSymbolChange.bind(this),debug:this.debug,autoUppercase:!0,symbolType:"quotel1"});const t=this.container.querySelector(".combined-symbol");t&&(t.textContent=this.symbol,t.dataset.originalSymbol=this.symbol)}async handleSymbolChange(t){this.debug&&console.log("[CombinedMarketWidget] Symbol change requested:",t);const e=g(t);if(!e.valid)return this.debug&&console.log("[CombinedMarketWidget] Invalid symbol:",e.error),{success:!1,error:e.error};const n=e.sanitized;if(n===this.symbol)return this.debug&&console.log("[CombinedMarketWidget] Same symbol, no change needed"),{success:!0};try{const t=this.symbol;return this.showLoading(),this.unsubscribeMarket&&(this.debug&&console.log(`[CombinedMarketWidget] Unsubscribing from market data: ${t}`),this.wsManager.sendUnsubscribe("queryl1",t),this.unsubscribeMarket(),this.unsubscribeMarket=null),this.unsubscribeNight&&(this.debug&&console.log(`[CombinedMarketWidget] Unsubscribing from night session: ${t}`),this.wsManager.sendUnsubscribe("queryblueoceanl1",t),this.unsubscribeNight(),this.unsubscribeNight=null),this.symbol=n,this.marketData=null,this.nightSessionData=null,this.debug&&console.log(`[CombinedMarketWidget] Subscribing to new symbol: ${n}`),this.subscribeToData(),this.debug&&console.log(`[CombinedMarketWidget] Successfully changed symbol from ${t} to ${n}`),{success:!0}}catch(t){return console.error("[CombinedMarketWidget] Error changing symbol:",t),this.hideLoading(),{success:!1,error:`Failed to load ${n}`}}}subscribeToData(){this.showLoading(),this.unsubscribeMarket=this.wsManager.subscribe(`${this.widgetId}-market`,["queryl1"],(t=>{const{event:e,data:n}=t;"connection"!==e?"data"===e&&(n._dataType="market",this.handleMessage({event:e,data:n})):this.handleConnectionStatus(n)}),this.symbol),this.unsubscribeNight=this.wsManager.subscribe(`${this.widgetId}-night`,["queryblueoceanl1"],(t=>{const{event:e,data:n}=t;"connection"!==e&&"data"===e&&(n._dataType="night",this.handleMessage({event:e,data:n}))}),this.symbol)}handleData(t){const e=t._dataType;if(this.debug&&console.log(`[CombinedMarketWidget] handleData called with type: ${e}`,t),e){if("error"===t.type&&t.noData)return this.debug&&console.log(`[CombinedMarketWidget] Received no data message for ${e}:`,t.message),"market"!==e||this.marketData?"night"!==e||this.nightSessionData||this.debug&&console.log("[CombinedMarketWidget] No night session data available"):this.debug&&console.log("[CombinedMarketWidget] No market data available"),void this.hideLoading();if("error"===t.type){const n=t.message||"Server error";return this.debug&&console.log(`[CombinedMarketWidget] Error received for ${e}:`,n),void this.hideLoading()}if("object"==typeof t&&t.Message){const n=t.Message.toLowerCase();if(n.includes("no data")||n.includes("not found"))return this.debug&&console.log(`[CombinedMarketWidget] No data message for ${e}:`,t.Message),void this.hideLoading()}if("market"===e){if(t.Data&&Array.isArray(t.Data)){const e=t.Data.find((t=>t.Symbol===this.symbol));e?(this.debug&&console.log("[CombinedMarketWidget] Market data received:",e),this.marketData=new i(e),this.updateMarketSection(),this.hideLoading()):(this.debug&&console.log("[CombinedMarketWidget] No market data for symbol in response, keeping cached data"),this.hideLoading())}delete t._dataType}if("night"===e){if(Array.isArray(t)){const e=t.find((t=>t.Symbol===this.symbol));e?!0!==e.NotFound&&e.MarketName&&"BLUE"===e.MarketName?(this.debug&&console.log("[CombinedMarketWidget] Night session data received:",e),this.nightSessionData=new y(e),this.updateNightSessionSection(),this.hideLoading()):(this.debug&&console.log("[CombinedMarketWidget] Night session data not found or not available"),this.hideLoading()):(this.debug&&console.log("[CombinedMarketWidget] No night session data for symbol in response, keeping cached data"),this.hideLoading())}else"queryblueoceanl1"!==t.type&&"querybrucel1"!==t.type||(t[0]?.Symbol===this.symbol?!0!==t[0].NotFound&&t[0].MarketName&&"BLUE"===t[0].MarketName?(this.debug&&console.log("[CombinedMarketWidget] Night session data received (wrapped format):",t[0]),this.nightSessionData=new y(t[0]),this.updateNightSessionSection(),this.hideLoading()):(this.debug&&console.log("[CombinedMarketWidget] Night session data not found or not available (wrapped format)"),this.hideLoading()):(this.debug&&console.log("[CombinedMarketWidget] No matching symbol in wrapped response, keeping cached data"),this.hideLoading()));delete t._dataType}t._cached&&this.showConnectionQuality()}else this.debug&&console.warn("[CombinedMarketWidget] No data type specified, attempting to infer from structure")}updateMarketSection(){if(!this.marketData)return;const t=this.container.querySelector(".regular-market"),e=this.container.querySelector(".company-name");if(e){const t=this.marketData.companyName||`${this.marketData.symbol} Inc.`,n=this.marketData.companyDescription||`${this.marketData.symbol}`;e.textContent=t,e.setAttribute("title",n),e.setAttribute("data-tooltip",n)}t.querySelector(".combined-current-price").textContent=this.marketData.formatPrice();const n=t.querySelector(".combined-price-change"),i=t.querySelector(".combined-change-value"),s=t.querySelector(".combined-change-percent"),o=this.marketData.change,a=o>0?"positive":o<0?"negative":"neutral";n.className=`combined-price-change ${a}`,i.textContent=this.marketData.formatPriceChange(),s.textContent=`(${this.marketData.formatPriceChangePercent()})`;const r=t.querySelector(".market-status-label");r&&(r.textContent=`${this.getSessionType()}:`);t.querySelector(".combined-timestamp").textContent=f(this.marketData.quoteTime,{format:"long"}),this.debug&&console.log("[CombinedMarketWidget] Updated market section:",this.marketData)}updateNightSessionSection(){if(!this.nightSessionData)return;const t=this.container.querySelector(".night-session");if(this.removeNightSession&&!this.isNightSessionActive())return t.style.display="none",void(this.debug&&console.log("[CombinedMarketWidget] Night session hidden (market closed)"));t.style.display="";const e=t.querySelector(".combined-current-price");e&&(e.textContent=this.nightSessionData.lastPrice?this.nightSessionData.formatPrice():"--");const n=t.querySelector(".combined-price-change"),i=t.querySelector(".combined-change-value"),s=t.querySelector(".combined-change-percent"),o=this.nightSessionData.change,a=o>0?"positive":o<0?"negative":"neutral";n.className=`combined-price-change ${a}`,i.textContent=null!==this.nightSessionData.change?this.nightSessionData.formatPriceChange():"--",s.textContent=`(${this.nightSessionData.formatPriceChangePercent()})`;t.querySelector(".combined-timestamp").textContent=f(this.nightSessionData.quoteTime,{format:"long"}),this.debug&&(console.log("connection quality:",this.connectionQuality),console.log("[CombinedMarketWidget] Updated night session section:",this.nightSessionData))}getSessionType(){const t=(new Date).toLocaleString("en-US",{timeZone:"America/New_York"}),e=new Date(t),n=e.getHours(),i=e.getMinutes(),s=60*n+i;return console.log("Current EST time:",n+":"+(i<10?"0":"")+i),s>=240&&s<570?"Pre-Market":s>=570&&s<960?"Market Hours":s>=960&&s<1200?"Post-Market":"Market Closed"}isNightSessionActive(){return"Market Closed"===this.getSessionType()}destroy(){this.unsubscribeMarket&&(this.unsubscribeMarket(),this.unsubscribeMarket=null),this.unsubscribeNight&&(this.unsubscribeNight(),this.unsubscribeNight=null),this.symbolEditor&&(this.symbolEditor.destroy(),this.symbolEditor=null),super.destroy()}}class T{constructor(t){Array.isArray(t)?(console.log("[IntradayChartModel] Processing",t.length,"raw data points"),t.length>0&&console.log("[IntradayChartModel] Sample raw point:",t[0]),this.dataPoints=t.map(((t,e)=>{const n={symbol:t.symbol||t.Symbol,time:t.time||t.Time||t.timestamp||t.Timestamp,open:parseFloat(t.open||t.Open)||0,high:parseFloat(t.high||t.High)||0,low:parseFloat(t.low||t.Low)||0,close:parseFloat(t.close||t.Close)||0,volume:parseInt(t.volume||t.Volume)||0,source:t.source||t.Source};return e<2&&console.log(`[IntradayChartModel] Processed point ${e}:`,n),n.time||console.warn(`[IntradayChartModel] Point ${e} missing time:`,t),0===n.close&&console.warn(`[IntradayChartModel] Point ${e} has zero close price:`,t),n})).filter((t=>{if(!t.time||t.close<=0)return!1;const e=new Date(t.time).getTime();return!(isNaN(e)||e<9466848e5)||(console.warn("[IntradayChartModel] Invalid timestamp:",t.time),!1)})),this.dataPoints.sort(((t,e)=>new Date(t.time).getTime()-new Date(e.time).getTime())),console.log("[IntradayChartModel] Valid data points after filtering:",this.dataPoints.length),this.dataPoints.length>0&&console.log("[IntradayChartModel] Time range:",this.dataPoints[0].time,"to",this.dataPoints[this.dataPoints.length-1].time)):(console.warn("[IntradayChartModel] Expected array of data points, got:",typeof t),this.dataPoints=[]),this.symbol=this.dataPoints.length>0?this.dataPoints[0].symbol:null,this.source=this.dataPoints.length>0?this.dataPoints[0].source:null}getTimeLabels(){return this.dataPoints.map((t=>{const e=new Date(t.time);let n=e.getHours();const i=n>=12?"PM":"AM";n%=12,n=n||12;return[`${n}:${e.getMinutes().toString().padStart(2,"0")} ${i}`,`${(e.getMonth()+1).toString().padStart(2,"0")}/${e.getDate().toString().padStart(2,"0")}`]}))}getOHLCData(){return this.dataPoints.map((t=>({x:new Date(t.time).getTime(),o:t.open,h:t.high,l:t.low,c:t.close})))}getClosePrices(){return this.dataPoints.map((t=>t.close))}getVolumeData(){return this.dataPoints.map((t=>t.volume))}getHighPrices(){return this.dataPoints.map((t=>t.high))}getLowPrices(){return this.dataPoints.map((t=>t.low))}getOpenPrices(){return this.dataPoints.map((t=>t.open))}getStats(){if(0===this.dataPoints.length)return{high:0,low:0,open:0,close:0,change:0,changePercent:0,volume:0};this.getClosePrices();const t=this.getHighPrices(),e=this.getLowPrices(),n=this.getVolumeData(),i=this.dataPoints[0],s=this.dataPoints[this.dataPoints.length-1],o=s.close-i.open,a=0!==i.open?o/i.open*100:0;return{high:Math.max(...t),low:Math.min(...e),open:i.open,close:s.close,change:o,changePercent:a,volume:n.reduce(((t,e)=>t+e),0),dataPoints:this.dataPoints.length}}formatPrice(t){return t.toFixed(2)}formatVolume(t){return t>=1e6?(t/1e6).toFixed(2)+"M":t>=1e3?(t/1e3).toFixed(2)+"K":t.toString()}}
|
|
2
2
|
/*!
|
|
3
3
|
* @kurkle/color v0.3.4
|
|
4
4
|
* https://github.com/kurkle/color#readme
|
|
5
5
|
* (c) 2024 Jukka Kurkela
|
|
6
6
|
* Released under the MIT License
|
|
7
7
|
*/
|
|
8
|
-
function P(t){return t+.5|0}const E=(t,e,n)=>Math.max(Math.min(t,n),e);function A(t){return E(P(2.55*t),0,255)}function L(t){return E(P(255*t),0,255)}function I(t){return E(P(t/2.55)/100,0,1)}function O(t){return E(P(100*t),0,100)}const z={0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,A:10,B:11,C:12,D:13,E:14,F:15,a:10,b:11,c:12,d:13,e:14,f:15},W=[..."0123456789ABCDEF"],N=t=>W[15&t],R=t=>W[(240&t)>>4]+W[15&t],$=t=>(240&t)>>4==(15&t);function F(t){var e=(t=>$(t.r)&&$(t.g)&&$(t.b)&&$(t.a))(t)?N:R;return t?"#"+e(t.r)+e(t.g)+e(t.b)+((t,e)=>t<255?e(t):"")(t.a,e):void 0}const q=/^(hsla?|hwb|hsv)\(\s*([-+.e\d]+)(?:deg)?[\s,]+([-+.e\d]+)%[\s,]+([-+.e\d]+)%(?:[\s,]+([-+.e\d]+)(%)?)?\s*\)$/;function B(t,e,n){const i=e*Math.min(n,1-n),s=(e,s=(e+t/30)%12)=>n-i*Math.max(Math.min(s-3,9-s,1),-1);return[s(0),s(8),s(4)]}function H(t,e,n){const i=(i,s=(i+t/60)%6)=>n-n*e*Math.max(Math.min(s,4-s,1),0);return[i(5),i(3),i(1)]}function V(t,e,n){const i=B(t,1,.5);let s;for(e+n>1&&(s=1/(e+n),e*=s,n*=s),s=0;s<3;s++)i[s]*=1-e-n,i[s]+=e;return i}function j(t){const e=t.r/255,n=t.g/255,i=t.b/255,s=Math.max(e,n,i),o=Math.min(e,n,i),a=(s+o)/2;let r,c,l;return s!==o&&(l=s-o,c=a>.5?l/(2-s-o):l/(s+o),r=function(t,e,n,i,s){return t===s?(e-n)/i+(e<n?6:0):e===s?(n-t)/i+2:(t-e)/i+4}(e,n,i,l,s),r=60*r+.5),[0|r,c||0,a]}function Y(t,e,n,i){return(Array.isArray(e)?t(e[0],e[1],e[2]):t(e,n,i)).map(L)}function U(t,e,n){return Y(B,t,e,n)}function X(t){return(t%360+360)%360}function Q(t){const e=q.exec(t);let n,i=255;if(!e)return;e[5]!==n&&(i=e[6]?A(+e[5]):L(+e[5]));const s=X(+e[2]),o=+e[3]/100,a=+e[4]/100;return n="hwb"===e[1]?function(t,e,n){return Y(V,t,e,n)}(s,o,a):"hsv"===e[1]?function(t,e,n){return Y(H,t,e,n)}(s,o,a):U(s,o,a),{r:n[0],g:n[1],b:n[2],a:i}}const K={x:"dark",Z:"light",Y:"re",X:"blu",W:"gr",V:"medium",U:"slate",A:"ee",T:"ol",S:"or",B:"ra",C:"lateg",D:"ights",R:"in",Q:"turquois",E:"hi",P:"ro",O:"al",N:"le",M:"de",L:"yello",F:"en",K:"ch",G:"arks",H:"ea",I:"ightg",J:"wh"},
|
|
8
|
+
function P(t){return t+.5|0}const E=(t,e,n)=>Math.max(Math.min(t,n),e);function A(t){return E(P(2.55*t),0,255)}function L(t){return E(P(255*t),0,255)}function I(t){return E(P(t/2.55)/100,0,1)}function O(t){return E(P(100*t),0,100)}const z={0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,A:10,B:11,C:12,D:13,E:14,F:15,a:10,b:11,c:12,d:13,e:14,f:15},W=[..."0123456789ABCDEF"],N=t=>W[15&t],R=t=>W[(240&t)>>4]+W[15&t],$=t=>(240&t)>>4==(15&t);function F(t){var e=(t=>$(t.r)&&$(t.g)&&$(t.b)&&$(t.a))(t)?N:R;return t?"#"+e(t.r)+e(t.g)+e(t.b)+((t,e)=>t<255?e(t):"")(t.a,e):void 0}const q=/^(hsla?|hwb|hsv)\(\s*([-+.e\d]+)(?:deg)?[\s,]+([-+.e\d]+)%[\s,]+([-+.e\d]+)%(?:[\s,]+([-+.e\d]+)(%)?)?\s*\)$/;function B(t,e,n){const i=e*Math.min(n,1-n),s=(e,s=(e+t/30)%12)=>n-i*Math.max(Math.min(s-3,9-s,1),-1);return[s(0),s(8),s(4)]}function H(t,e,n){const i=(i,s=(i+t/60)%6)=>n-n*e*Math.max(Math.min(s,4-s,1),0);return[i(5),i(3),i(1)]}function V(t,e,n){const i=B(t,1,.5);let s;for(e+n>1&&(s=1/(e+n),e*=s,n*=s),s=0;s<3;s++)i[s]*=1-e-n,i[s]+=e;return i}function j(t){const e=t.r/255,n=t.g/255,i=t.b/255,s=Math.max(e,n,i),o=Math.min(e,n,i),a=(s+o)/2;let r,c,l;return s!==o&&(l=s-o,c=a>.5?l/(2-s-o):l/(s+o),r=function(t,e,n,i,s){return t===s?(e-n)/i+(e<n?6:0):e===s?(n-t)/i+2:(t-e)/i+4}(e,n,i,l,s),r=60*r+.5),[0|r,c||0,a]}function Y(t,e,n,i){return(Array.isArray(e)?t(e[0],e[1],e[2]):t(e,n,i)).map(L)}function U(t,e,n){return Y(B,t,e,n)}function X(t){return(t%360+360)%360}function Q(t){const e=q.exec(t);let n,i=255;if(!e)return;e[5]!==n&&(i=e[6]?A(+e[5]):L(+e[5]));const s=X(+e[2]),o=+e[3]/100,a=+e[4]/100;return n="hwb"===e[1]?function(t,e,n){return Y(V,t,e,n)}(s,o,a):"hsv"===e[1]?function(t,e,n){return Y(H,t,e,n)}(s,o,a):U(s,o,a),{r:n[0],g:n[1],b:n[2],a:i}}const K={x:"dark",Z:"light",Y:"re",X:"blu",W:"gr",V:"medium",U:"slate",A:"ee",T:"ol",S:"or",B:"ra",C:"lateg",D:"ights",R:"in",Q:"turquois",E:"hi",P:"ro",O:"al",N:"le",M:"de",L:"yello",F:"en",K:"ch",G:"arks",H:"ea",I:"ightg",J:"wh"},G={OiceXe:"f0f8ff",antiquewEte:"faebd7",aqua:"ffff",aquamarRe:"7fffd4",azuY:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"0",blanKedOmond:"ffebcd",Xe:"ff",XeviTet:"8a2be2",bPwn:"a52a2a",burlywood:"deb887",caMtXe:"5f9ea0",KartYuse:"7fff00",KocTate:"d2691e",cSO:"ff7f50",cSnflowerXe:"6495ed",cSnsilk:"fff8dc",crimson:"dc143c",cyan:"ffff",xXe:"8b",xcyan:"8b8b",xgTMnPd:"b8860b",xWay:"a9a9a9",xgYF:"6400",xgYy:"a9a9a9",xkhaki:"bdb76b",xmagFta:"8b008b",xTivegYF:"556b2f",xSange:"ff8c00",xScEd:"9932cc",xYd:"8b0000",xsOmon:"e9967a",xsHgYF:"8fbc8f",xUXe:"483d8b",xUWay:"2f4f4f",xUgYy:"2f4f4f",xQe:"ced1",xviTet:"9400d3",dAppRk:"ff1493",dApskyXe:"bfff",dimWay:"696969",dimgYy:"696969",dodgerXe:"1e90ff",fiYbrick:"b22222",flSOwEte:"fffaf0",foYstWAn:"228b22",fuKsia:"ff00ff",gaRsbSo:"dcdcdc",ghostwEte:"f8f8ff",gTd:"ffd700",gTMnPd:"daa520",Way:"808080",gYF:"8000",gYFLw:"adff2f",gYy:"808080",honeyMw:"f0fff0",hotpRk:"ff69b4",RdianYd:"cd5c5c",Rdigo:"4b0082",ivSy:"fffff0",khaki:"f0e68c",lavFMr:"e6e6fa",lavFMrXsh:"fff0f5",lawngYF:"7cfc00",NmoncEffon:"fffacd",ZXe:"add8e6",ZcSO:"f08080",Zcyan:"e0ffff",ZgTMnPdLw:"fafad2",ZWay:"d3d3d3",ZgYF:"90ee90",ZgYy:"d3d3d3",ZpRk:"ffb6c1",ZsOmon:"ffa07a",ZsHgYF:"20b2aa",ZskyXe:"87cefa",ZUWay:"778899",ZUgYy:"778899",ZstAlXe:"b0c4de",ZLw:"ffffe0",lime:"ff00",limegYF:"32cd32",lRF:"faf0e6",magFta:"ff00ff",maPon:"800000",VaquamarRe:"66cdaa",VXe:"cd",VScEd:"ba55d3",VpurpN:"9370db",VsHgYF:"3cb371",VUXe:"7b68ee",VsprRggYF:"fa9a",VQe:"48d1cc",VviTetYd:"c71585",midnightXe:"191970",mRtcYam:"f5fffa",mistyPse:"ffe4e1",moccasR:"ffe4b5",navajowEte:"ffdead",navy:"80",Tdlace:"fdf5e6",Tive:"808000",TivedBb:"6b8e23",Sange:"ffa500",SangeYd:"ff4500",ScEd:"da70d6",pOegTMnPd:"eee8aa",pOegYF:"98fb98",pOeQe:"afeeee",pOeviTetYd:"db7093",papayawEp:"ffefd5",pHKpuff:"ffdab9",peru:"cd853f",pRk:"ffc0cb",plum:"dda0dd",powMrXe:"b0e0e6",purpN:"800080",YbeccapurpN:"663399",Yd:"ff0000",Psybrown:"bc8f8f",PyOXe:"4169e1",saddNbPwn:"8b4513",sOmon:"fa8072",sandybPwn:"f4a460",sHgYF:"2e8b57",sHshell:"fff5ee",siFna:"a0522d",silver:"c0c0c0",skyXe:"87ceeb",UXe:"6a5acd",UWay:"708090",UgYy:"708090",snow:"fffafa",sprRggYF:"ff7f",stAlXe:"4682b4",tan:"d2b48c",teO:"8080",tEstN:"d8bfd8",tomato:"ff6347",Qe:"40e0d0",viTet:"ee82ee",JHt:"f5deb3",wEte:"ffffff",wEtesmoke:"f5f5f5",Lw:"ffff00",LwgYF:"9acd32"};let Z;function J(t){Z||(Z=function(){const t={},e=Object.keys(G),n=Object.keys(K);let i,s,o,a,r;for(i=0;i<e.length;i++){for(a=r=e[i],s=0;s<n.length;s++)o=n[s],r=r.replace(o,K[o]);o=parseInt(G[a],16),t[r]=[o>>16&255,o>>8&255,255&o]}return t}(),Z.transparent=[0,0,0,0]);const e=Z[t.toLowerCase()];return e&&{r:e[0],g:e[1],b:e[2],a:4===e.length?e[3]:255}}const tt=/^rgba?\(\s*([-+.\d]+)(%)?[\s,]+([-+.e\d]+)(%)?[\s,]+([-+.e\d]+)(%)?(?:[\s,/]+([-+.e\d]+)(%)?)?\s*\)$/;const et=t=>t<=.0031308?12.92*t:1.055*Math.pow(t,1/2.4)-.055,nt=t=>t<=.04045?t/12.92:Math.pow((t+.055)/1.055,2.4);function it(t,e,n){if(t){let i=j(t);i[e]=Math.max(0,Math.min(i[e]+i[e]*n,0===e?360:1)),i=U(i),t.r=i[0],t.g=i[1],t.b=i[2]}}function st(t,e){return t?Object.assign(e||{},t):t}function ot(t){var e={r:0,g:0,b:0,a:255};return Array.isArray(t)?t.length>=3&&(e={r:t[0],g:t[1],b:t[2],a:255},t.length>3&&(e.a=L(t[3]))):(e=st(t,{r:0,g:0,b:0,a:1})).a=L(e.a),e}function at(t){return"r"===t.charAt(0)?function(t){const e=tt.exec(t);let n,i,s,o=255;if(e){if(e[7]!==n){const t=+e[7];o=e[8]?A(t):E(255*t,0,255)}return n=+e[1],i=+e[3],s=+e[5],n=255&(e[2]?A(n):E(n,0,255)),i=255&(e[4]?A(i):E(i,0,255)),s=255&(e[6]?A(s):E(s,0,255)),{r:n,g:i,b:s,a:o}}}(t):Q(t)}class rt{constructor(t){if(t instanceof rt)return t;const e=typeof t;let n;var i,s,o;"object"===e?n=ot(t):"string"===e&&(o=(i=t).length,"#"===i[0]&&(4===o||5===o?s={r:255&17*z[i[1]],g:255&17*z[i[2]],b:255&17*z[i[3]],a:5===o?17*z[i[4]]:255}:7!==o&&9!==o||(s={r:z[i[1]]<<4|z[i[2]],g:z[i[3]]<<4|z[i[4]],b:z[i[5]]<<4|z[i[6]],a:9===o?z[i[7]]<<4|z[i[8]]:255})),n=s||J(t)||at(t)),this._rgb=n,this._valid=!!n}get valid(){return this._valid}get rgb(){var t=st(this._rgb);return t&&(t.a=I(t.a)),t}set rgb(t){this._rgb=ot(t)}rgbString(){return this._valid?(t=this._rgb)&&(t.a<255?`rgba(${t.r}, ${t.g}, ${t.b}, ${I(t.a)})`:`rgb(${t.r}, ${t.g}, ${t.b})`):void 0;var t}hexString(){return this._valid?F(this._rgb):void 0}hslString(){return this._valid?function(t){if(!t)return;const e=j(t),n=e[0],i=O(e[1]),s=O(e[2]);return t.a<255?`hsla(${n}, ${i}%, ${s}%, ${I(t.a)})`:`hsl(${n}, ${i}%, ${s}%)`}(this._rgb):void 0}mix(t,e){if(t){const n=this.rgb,i=t.rgb;let s;const o=e===s?.5:e,a=2*o-1,r=n.a-i.a,c=((a*r===-1?a:(a+r)/(1+a*r))+1)/2;s=1-c,n.r=255&c*n.r+s*i.r+.5,n.g=255&c*n.g+s*i.g+.5,n.b=255&c*n.b+s*i.b+.5,n.a=o*n.a+(1-o)*i.a,this.rgb=n}return this}interpolate(t,e){return t&&(this._rgb=function(t,e,n){const i=nt(I(t.r)),s=nt(I(t.g)),o=nt(I(t.b));return{r:L(et(i+n*(nt(I(e.r))-i))),g:L(et(s+n*(nt(I(e.g))-s))),b:L(et(o+n*(nt(I(e.b))-o))),a:t.a+n*(e.a-t.a)}}(this._rgb,t._rgb,e)),this}clone(){return new rt(this.rgb)}alpha(t){return this._rgb.a=L(t),this}clearer(t){return this._rgb.a*=1-t,this}greyscale(){const t=this._rgb,e=P(.3*t.r+.59*t.g+.11*t.b);return t.r=t.g=t.b=e,this}opaquer(t){return this._rgb.a*=1+t,this}negate(){const t=this._rgb;return t.r=255-t.r,t.g=255-t.g,t.b=255-t.b,this}lighten(t){return it(this._rgb,2,t),this}darken(t){return it(this._rgb,2,-t),this}saturate(t){return it(this._rgb,1,t),this}desaturate(t){return it(this._rgb,1,-t),this}rotate(t){return function(t,e){var n=j(t);n[0]=X(n[0]+e),n=U(n),t.r=n[0],t.g=n[1],t.b=n[2]}(this._rgb,t),this}}
|
|
9
9
|
/*!
|
|
10
10
|
* Chart.js v4.5.1
|
|
11
11
|
* https://www.chartjs.org
|
|
12
12
|
* (c) 2025 Chart.js Contributors
|
|
13
13
|
* Released under the MIT License
|
|
14
|
-
*/function ct(){}const lt=(()=>{let t=0;return()=>t++})();function dt(t){return null==t}function ht(t){if(Array.isArray&&Array.isArray(t))return!0;const e=Object.prototype.toString.call(t);return"[object"===e.slice(0,7)&&"Array]"===e.slice(-6)}function ut(t){return null!==t&&"[object Object]"===Object.prototype.toString.call(t)}function gt(t){return("number"==typeof t||t instanceof Number)&&isFinite(+t)}function pt(t,e){return gt(t)?t:e}function mt(t,e){return void 0===t?e:t}const ft=(t,e)=>"string"==typeof t&&t.endsWith("%")?parseFloat(t)/100*e:+t;function bt(t,e,n){if(t&&"function"==typeof t.call)return t.apply(n,e)}function yt(t,e,n,i){let s,o,a;if(ht(t))if(o=t.length,i)for(s=o-1;s>=0;s--)e.call(n,t[s],s);else for(s=0;s<o;s++)e.call(n,t[s],s);else if(ut(t))for(a=Object.keys(t),o=a.length,s=0;s<o;s++)e.call(n,t[a[s]],a[s])}function xt(t,e){let n,i,s,o;if(!t||!e||t.length!==e.length)return!1;for(n=0,i=t.length;n<i;++n)if(s=t[n],o=e[n],s.datasetIndex!==o.datasetIndex||s.index!==o.index)return!1;return!0}function vt(t){if(ht(t))return t.map(vt);if(ut(t)){const e=Object.create(null),n=Object.keys(t),i=n.length;let s=0;for(;s<i;++s)e[n[s]]=vt(t[n[s]]);return e}return t}function wt(t){return-1===["__proto__","prototype","constructor"].indexOf(t)}function St(t,e,n,i){if(!wt(t))return;const s=e[t],o=n[t];ut(s)&&ut(o)?kt(s,o,i):e[t]=vt(o)}function kt(t,e,n){const i=ht(e)?e:[e],s=i.length;if(!ut(t))return t;const o=(n=n||{}).merger||St;let a;for(let e=0;e<s;++e){if(a=i[e],!ut(a))continue;const s=Object.keys(a);for(let e=0,i=s.length;e<i;++e)o(s[e],t,a,n)}return t}function Mt(t,e){return kt(t,e,{merger:_t})}function _t(t,e,n){if(!wt(t))return;const i=e[t],s=n[t];ut(i)&&ut(s)?Mt(i,s):Object.prototype.hasOwnProperty.call(e,t)||(e[t]=vt(s))}const Ct={"":t=>t,x:t=>t.x,y:t=>t.y};function Tt(t,e){const n=Ct[e]||(Ct[e]=function(t){const e=function(t){const e=t.split("."),n=[];let i="";for(const t of e)i+=t,i.endsWith("\\")?i=i.slice(0,-1)+".":(n.push(i),i="");return n}(t);return t=>{for(const n of e){if(""===n)break;t=t&&t[n]}return t}}(e));return n(t)}function Dt(t){return t.charAt(0).toUpperCase()+t.slice(1)}const Pt=t=>void 0!==t,Et=t=>"function"==typeof t,At=(t,e)=>{if(t.size!==e.size)return!1;for(const n of t)if(!e.has(n))return!1;return!0};const Lt=Math.PI,It=2*Lt,Ot=It+Lt,zt=Number.POSITIVE_INFINITY,Wt=Lt/180,Nt=Lt/2,Rt=Lt/4,$t=2*Lt/3,Ft=Math.log10,qt=Math.sign;function Bt(t,e,n){return Math.abs(t-e)<n}function Ht(t){const e=Math.round(t);t=Bt(t,e,t/1e3)?e:t;const n=Math.pow(10,Math.floor(Ft(t))),i=t/n;return(i<=1?1:i<=2?2:i<=5?5:10)*n}function Vt(t){return!function(t){return"symbol"==typeof t||"object"==typeof t&&null!==t&&!(Symbol.toPrimitive in t||"toString"in t||"valueOf"in t)}(t)&&!isNaN(parseFloat(t))&&isFinite(t)}function jt(t,e,n){let i,s,o;for(i=0,s=t.length;i<s;i++)o=t[i][n],isNaN(o)||(e.min=Math.min(e.min,o),e.max=Math.max(e.max,o))}function Yt(t){return t*(Lt/180)}function Ut(t){return t*(180/Lt)}function Xt(t){if(!gt(t))return;let e=1,n=0;for(;Math.round(t*e)/e!==t;)e*=10,n++;return n}function Qt(t,e){const n=e.x-t.x,i=e.y-t.y,s=Math.sqrt(n*n+i*i);let o=Math.atan2(i,n);return o<-.5*Lt&&(o+=It),{angle:o,distance:s}}function Kt(t,e){return Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2))}function Zt(t,e){return(t-e+Ot)%It-Lt}function Gt(t){return(t%It+It)%It}function Jt(t,e,n,i){const s=Gt(t),o=Gt(e),a=Gt(n),r=Gt(o-s),c=Gt(a-s),l=Gt(s-o),d=Gt(s-a);return s===o||s===a||i&&o===a||r>c&&l<d}function te(t,e,n){return Math.max(e,Math.min(n,t))}function ee(t,e,n,i=1e-6){return t>=Math.min(e,n)-i&&t<=Math.max(e,n)+i}function ne(t,e,n){n=n||(n=>t[n]<e);let i,s=t.length-1,o=0;for(;s-o>1;)i=o+s>>1,n(i)?o=i:s=i;return{lo:o,hi:s}}const ie=(t,e,n,i)=>ne(t,n,i?i=>{const s=t[i][e];return s<n||s===n&&t[i+1][e]===n}:i=>t[i][e]<n),se=(t,e,n)=>ne(t,n,(i=>t[i][e]>=n));const oe=["push","pop","shift","splice","unshift"];function ae(t,e){const n=t._chartjs;if(!n)return;const i=n.listeners,s=i.indexOf(e);-1!==s&&i.splice(s,1),i.length>0||(oe.forEach((e=>{delete t[e]})),delete t._chartjs)}function re(t){const e=new Set(t);return e.size===t.length?t:Array.from(e)}const ce="undefined"==typeof window?function(t){return t()}:window.requestAnimationFrame;function le(t,e){let n=[],i=!1;return function(...s){n=s,i||(i=!0,ce.call(window,(()=>{i=!1,t.apply(e,n)})))}}const de=t=>"start"===t?"left":"end"===t?"right":"center",he=(t,e,n)=>"start"===t?e:"end"===t?n:(e+n)/2;function ue(t,e,n){const i=e.length;let s=0,o=i;if(t._sorted){const{iScale:a,vScale:r,_parsed:c}=t,l=t.dataset&&t.dataset.options?t.dataset.options.spanGaps:null,d=a.axis,{min:h,max:u,minDefined:g,maxDefined:p}=a.getUserBounds();if(g){if(s=Math.min(ie(c,d,h).lo,n?i:ie(e,d,a.getPixelForValue(h)).lo),l){const t=c.slice(0,s+1).reverse().findIndex((t=>!dt(t[r.axis])));s-=Math.max(0,t)}s=te(s,0,i-1)}if(p){let t=Math.max(ie(c,a.axis,u,!0).hi+1,n?0:ie(e,d,a.getPixelForValue(u),!0).hi+1);if(l){const e=c.slice(t-1).findIndex((t=>!dt(t[r.axis])));t+=Math.max(0,e)}o=te(t,s,i)-s}else o=i-s}return{start:s,count:o}}function ge(t){const{xScale:e,yScale:n,_scaleRanges:i}=t,s={xmin:e.min,xmax:e.max,ymin:n.min,ymax:n.max};if(!i)return t._scaleRanges=s,!0;const o=i.xmin!==e.min||i.xmax!==e.max||i.ymin!==n.min||i.ymax!==n.max;return Object.assign(i,s),o}const pe=t=>0===t||1===t,me=(t,e,n)=>-Math.pow(2,10*(t-=1))*Math.sin((t-e)*It/n),fe=(t,e,n)=>Math.pow(2,-10*t)*Math.sin((t-e)*It/n)+1,be={linear:t=>t,easeInQuad:t=>t*t,easeOutQuad:t=>-t*(t-2),easeInOutQuad:t=>(t/=.5)<1?.5*t*t:-.5*(--t*(t-2)-1),easeInCubic:t=>t*t*t,easeOutCubic:t=>(t-=1)*t*t+1,easeInOutCubic:t=>(t/=.5)<1?.5*t*t*t:.5*((t-=2)*t*t+2),easeInQuart:t=>t*t*t*t,easeOutQuart:t=>-((t-=1)*t*t*t-1),easeInOutQuart:t=>(t/=.5)<1?.5*t*t*t*t:-.5*((t-=2)*t*t*t-2),easeInQuint:t=>t*t*t*t*t,easeOutQuint:t=>(t-=1)*t*t*t*t+1,easeInOutQuint:t=>(t/=.5)<1?.5*t*t*t*t*t:.5*((t-=2)*t*t*t*t+2),easeInSine:t=>1-Math.cos(t*Nt),easeOutSine:t=>Math.sin(t*Nt),easeInOutSine:t=>-.5*(Math.cos(Lt*t)-1),easeInExpo:t=>0===t?0:Math.pow(2,10*(t-1)),easeOutExpo:t=>1===t?1:1-Math.pow(2,-10*t),easeInOutExpo:t=>pe(t)?t:t<.5?.5*Math.pow(2,10*(2*t-1)):.5*(2-Math.pow(2,-10*(2*t-1))),easeInCirc:t=>t>=1?t:-(Math.sqrt(1-t*t)-1),easeOutCirc:t=>Math.sqrt(1-(t-=1)*t),easeInOutCirc:t=>(t/=.5)<1?-.5*(Math.sqrt(1-t*t)-1):.5*(Math.sqrt(1-(t-=2)*t)+1),easeInElastic:t=>pe(t)?t:me(t,.075,.3),easeOutElastic:t=>pe(t)?t:fe(t,.075,.3),easeInOutElastic(t){const e=.1125;return pe(t)?t:t<.5?.5*me(2*t,e,.45):.5+.5*fe(2*t-1,e,.45)},easeInBack(t){const e=1.70158;return t*t*((e+1)*t-e)},easeOutBack(t){const e=1.70158;return(t-=1)*t*((e+1)*t+e)+1},easeInOutBack(t){let e=1.70158;return(t/=.5)<1?t*t*((1+(e*=1.525))*t-e)*.5:.5*((t-=2)*t*((1+(e*=1.525))*t+e)+2)},easeInBounce:t=>1-be.easeOutBounce(1-t),easeOutBounce(t){const e=7.5625,n=2.75;return t<1/n?e*t*t:t<2/n?e*(t-=1.5/n)*t+.75:t<2.5/n?e*(t-=2.25/n)*t+.9375:e*(t-=2.625/n)*t+.984375},easeInOutBounce:t=>t<.5?.5*be.easeInBounce(2*t):.5*be.easeOutBounce(2*t-1)+.5};function ye(t){if(t&&"object"==typeof t){const e=t.toString();return"[object CanvasPattern]"===e||"[object CanvasGradient]"===e}return!1}function xe(t){return ye(t)?t:new rt(t)}function ve(t){return ye(t)?t:new rt(t).saturate(.5).darken(.1).hexString()}const we=["x","y","borderWidth","radius","tension"],Se=["color","borderColor","backgroundColor"];const ke=new Map;function Me(t,e,n){return function(t,e){e=e||{};const n=t+JSON.stringify(e);let i=ke.get(n);return i||(i=new Intl.NumberFormat(t,e),ke.set(n,i)),i}(e,n).format(t)}const _e={values:t=>ht(t)?t:""+t,numeric(t,e,n){if(0===t)return"0";const i=this.chart.options.locale;let s,o=t;if(n.length>1){const e=Math.max(Math.abs(n[0].value),Math.abs(n[n.length-1].value));(e<1e-4||e>1e15)&&(s="scientific"),o=function(t,e){let n=e.length>3?e[2].value-e[1].value:e[1].value-e[0].value;Math.abs(n)>=1&&t!==Math.floor(t)&&(n=t-Math.floor(t));return n}(t,n)}const a=Ft(Math.abs(o)),r=isNaN(a)?1:Math.max(Math.min(-1*Math.floor(a),20),0),c={notation:s,minimumFractionDigits:r,maximumFractionDigits:r};return Object.assign(c,this.options.ticks.format),Me(t,i,c)},logarithmic(t,e,n){if(0===t)return"0";const i=n[e].significand||t/Math.pow(10,Math.floor(Ft(t)));return[1,2,3,5,10,15].includes(i)||e>.8*n.length?_e.numeric.call(this,t,e,n):""}};var Ce={formatters:_e};const Te=Object.create(null),De=Object.create(null);function Pe(t,e){if(!e)return t;const n=e.split(".");for(let e=0,i=n.length;e<i;++e){const i=n[e];t=t[i]||(t[i]=Object.create(null))}return t}function Ee(t,e,n){return"string"==typeof e?kt(Pe(t,e),n):kt(Pe(t,""),e)}class Ae{constructor(t,e){this.animation=void 0,this.backgroundColor="rgba(0,0,0,0.1)",this.borderColor="rgba(0,0,0,0.1)",this.color="#666",this.datasets={},this.devicePixelRatio=t=>t.chart.platform.getDevicePixelRatio(),this.elements={},this.events=["mousemove","mouseout","click","touchstart","touchmove"],this.font={family:"'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",size:12,style:"normal",lineHeight:1.2,weight:null},this.hover={},this.hoverBackgroundColor=(t,e)=>ve(e.backgroundColor),this.hoverBorderColor=(t,e)=>ve(e.borderColor),this.hoverColor=(t,e)=>ve(e.color),this.indexAxis="x",this.interaction={mode:"nearest",intersect:!0,includeInvisible:!1},this.maintainAspectRatio=!0,this.onHover=null,this.onClick=null,this.parsing=!0,this.plugins={},this.responsive=!0,this.scale=void 0,this.scales={},this.showLine=!0,this.drawActiveElementsOnTop=!0,this.describe(t),this.apply(e)}set(t,e){return Ee(this,t,e)}get(t){return Pe(this,t)}describe(t,e){return Ee(De,t,e)}override(t,e){return Ee(Te,t,e)}route(t,e,n,i){const s=Pe(this,t),o=Pe(this,n),a="_"+e;Object.defineProperties(s,{[a]:{value:s[e],writable:!0},[e]:{enumerable:!0,get(){const t=this[a],e=o[i];return ut(t)?Object.assign({},e,t):mt(t,e)},set(t){this[a]=t}}})}apply(t){t.forEach((t=>t(this)))}}var Le=new Ae({_scriptable:t=>!t.startsWith("on"),_indexable:t=>"events"!==t,hover:{_fallback:"interaction"},interaction:{_scriptable:!1,_indexable:!1}},[function(t){t.set("animation",{delay:void 0,duration:1e3,easing:"easeOutQuart",fn:void 0,from:void 0,loop:void 0,to:void 0,type:void 0}),t.describe("animation",{_fallback:!1,_indexable:!1,_scriptable:t=>"onProgress"!==t&&"onComplete"!==t&&"fn"!==t}),t.set("animations",{colors:{type:"color",properties:Se},numbers:{type:"number",properties:we}}),t.describe("animations",{_fallback:"animation"}),t.set("transitions",{active:{animation:{duration:400}},resize:{animation:{duration:0}},show:{animations:{colors:{from:"transparent"},visible:{type:"boolean",duration:0}}},hide:{animations:{colors:{to:"transparent"},visible:{type:"boolean",easing:"linear",fn:t=>0|t}}}})},function(t){t.set("layout",{autoPadding:!0,padding:{top:0,right:0,bottom:0,left:0}})},function(t){t.set("scale",{display:!0,offset:!1,reverse:!1,beginAtZero:!1,bounds:"ticks",clip:!0,grace:0,grid:{display:!0,lineWidth:1,drawOnChartArea:!0,drawTicks:!0,tickLength:8,tickWidth:(t,e)=>e.lineWidth,tickColor:(t,e)=>e.color,offset:!1},border:{display:!0,dash:[],dashOffset:0,width:1},title:{display:!1,text:"",padding:{top:4,bottom:4}},ticks:{minRotation:0,maxRotation:50,mirror:!1,textStrokeWidth:0,textStrokeColor:"",padding:3,display:!0,autoSkip:!0,autoSkipPadding:3,labelOffset:0,callback:Ce.formatters.values,minor:{},major:{},align:"center",crossAlign:"near",showLabelBackdrop:!1,backdropColor:"rgba(255, 255, 255, 0.75)",backdropPadding:2}}),t.route("scale.ticks","color","","color"),t.route("scale.grid","color","","borderColor"),t.route("scale.border","color","","borderColor"),t.route("scale.title","color","","color"),t.describe("scale",{_fallback:!1,_scriptable:t=>!t.startsWith("before")&&!t.startsWith("after")&&"callback"!==t&&"parser"!==t,_indexable:t=>"borderDash"!==t&&"tickBorderDash"!==t&&"dash"!==t}),t.describe("scales",{_fallback:"scale"}),t.describe("scale.ticks",{_scriptable:t=>"backdropPadding"!==t&&"callback"!==t,_indexable:t=>"backdropPadding"!==t})}]);function Ie(t,e,n,i,s){let o=e[s];return o||(o=e[s]=t.measureText(s).width,n.push(s)),o>i&&(i=o),i}function Oe(t,e,n,i){let s=(i=i||{}).data=i.data||{},o=i.garbageCollect=i.garbageCollect||[];i.font!==e&&(s=i.data={},o=i.garbageCollect=[],i.font=e),t.save(),t.font=e;let a=0;const r=n.length;let c,l,d,h,u;for(c=0;c<r;c++)if(h=n[c],null==h||ht(h)){if(ht(h))for(l=0,d=h.length;l<d;l++)u=h[l],null==u||ht(u)||(a=Ie(t,s,o,a,u))}else a=Ie(t,s,o,a,h);t.restore();const g=o.length/2;if(g>n.length){for(c=0;c<g;c++)delete s[o[c]];o.splice(0,g)}return a}function ze(t,e,n){const i=t.currentDevicePixelRatio,s=0!==n?Math.max(n/2,.5):0;return Math.round((e-s)*i)/i+s}function We(t,e){(e||t)&&((e=e||t.getContext("2d")).save(),e.resetTransform(),e.clearRect(0,0,t.width,t.height),e.restore())}function Ne(t,e,n,i){Re(t,e,n,i,null)}function Re(t,e,n,i,s){let o,a,r,c,l,d,h,u;const g=e.pointStyle,p=e.rotation,m=e.radius;let f=(p||0)*Wt;if(g&&"object"==typeof g&&(o=g.toString(),"[object HTMLImageElement]"===o||"[object HTMLCanvasElement]"===o))return t.save(),t.translate(n,i),t.rotate(f),t.drawImage(g,-g.width/2,-g.height/2,g.width,g.height),void t.restore();if(!(isNaN(m)||m<=0)){switch(t.beginPath(),g){default:s?t.ellipse(n,i,s/2,m,0,0,It):t.arc(n,i,m,0,It),t.closePath();break;case"triangle":d=s?s/2:m,t.moveTo(n+Math.sin(f)*d,i-Math.cos(f)*m),f+=$t,t.lineTo(n+Math.sin(f)*d,i-Math.cos(f)*m),f+=$t,t.lineTo(n+Math.sin(f)*d,i-Math.cos(f)*m),t.closePath();break;case"rectRounded":l=.516*m,c=m-l,a=Math.cos(f+Rt)*c,h=Math.cos(f+Rt)*(s?s/2-l:c),r=Math.sin(f+Rt)*c,u=Math.sin(f+Rt)*(s?s/2-l:c),t.arc(n-h,i-r,l,f-Lt,f-Nt),t.arc(n+u,i-a,l,f-Nt,f),t.arc(n+h,i+r,l,f,f+Nt),t.arc(n-u,i+a,l,f+Nt,f+Lt),t.closePath();break;case"rect":if(!p){c=Math.SQRT1_2*m,d=s?s/2:c,t.rect(n-d,i-c,2*d,2*c);break}f+=Rt;case"rectRot":h=Math.cos(f)*(s?s/2:m),a=Math.cos(f)*m,r=Math.sin(f)*m,u=Math.sin(f)*(s?s/2:m),t.moveTo(n-h,i-r),t.lineTo(n+u,i-a),t.lineTo(n+h,i+r),t.lineTo(n-u,i+a),t.closePath();break;case"crossRot":f+=Rt;case"cross":h=Math.cos(f)*(s?s/2:m),a=Math.cos(f)*m,r=Math.sin(f)*m,u=Math.sin(f)*(s?s/2:m),t.moveTo(n-h,i-r),t.lineTo(n+h,i+r),t.moveTo(n+u,i-a),t.lineTo(n-u,i+a);break;case"star":h=Math.cos(f)*(s?s/2:m),a=Math.cos(f)*m,r=Math.sin(f)*m,u=Math.sin(f)*(s?s/2:m),t.moveTo(n-h,i-r),t.lineTo(n+h,i+r),t.moveTo(n+u,i-a),t.lineTo(n-u,i+a),f+=Rt,h=Math.cos(f)*(s?s/2:m),a=Math.cos(f)*m,r=Math.sin(f)*m,u=Math.sin(f)*(s?s/2:m),t.moveTo(n-h,i-r),t.lineTo(n+h,i+r),t.moveTo(n+u,i-a),t.lineTo(n-u,i+a);break;case"line":a=s?s/2:Math.cos(f)*m,r=Math.sin(f)*m,t.moveTo(n-a,i-r),t.lineTo(n+a,i+r);break;case"dash":t.moveTo(n,i),t.lineTo(n+Math.cos(f)*(s?s/2:m),i+Math.sin(f)*m);break;case!1:t.closePath()}t.fill(),e.borderWidth>0&&t.stroke()}}function $e(t,e,n){return n=n||.5,!e||t&&t.x>e.left-n&&t.x<e.right+n&&t.y>e.top-n&&t.y<e.bottom+n}function Fe(t,e){t.save(),t.beginPath(),t.rect(e.left,e.top,e.right-e.left,e.bottom-e.top),t.clip()}function qe(t){t.restore()}function Be(t,e,n,i,s){if(!e)return t.lineTo(n.x,n.y);if("middle"===s){const i=(e.x+n.x)/2;t.lineTo(i,e.y),t.lineTo(i,n.y)}else"after"===s!=!!i?t.lineTo(e.x,n.y):t.lineTo(n.x,e.y);t.lineTo(n.x,n.y)}function He(t,e,n,i){if(!e)return t.lineTo(n.x,n.y);t.bezierCurveTo(i?e.cp1x:e.cp2x,i?e.cp1y:e.cp2y,i?n.cp2x:n.cp1x,i?n.cp2y:n.cp1y,n.x,n.y)}function Ve(t,e,n,i,s){if(s.strikethrough||s.underline){const o=t.measureText(i),a=e-o.actualBoundingBoxLeft,r=e+o.actualBoundingBoxRight,c=n-o.actualBoundingBoxAscent,l=n+o.actualBoundingBoxDescent,d=s.strikethrough?(c+l)/2:l;t.strokeStyle=t.fillStyle,t.beginPath(),t.lineWidth=s.decorationWidth||2,t.moveTo(a,d),t.lineTo(r,d),t.stroke()}}function je(t,e){const n=t.fillStyle;t.fillStyle=e.color,t.fillRect(e.left,e.top,e.width,e.height),t.fillStyle=n}function Ye(t,e,n,i,s,o={}){const a=ht(e)?e:[e],r=o.strokeWidth>0&&""!==o.strokeColor;let c,l;for(t.save(),t.font=s.string,function(t,e){e.translation&&t.translate(e.translation[0],e.translation[1]),dt(e.rotation)||t.rotate(e.rotation),e.color&&(t.fillStyle=e.color),e.textAlign&&(t.textAlign=e.textAlign),e.textBaseline&&(t.textBaseline=e.textBaseline)}(t,o),c=0;c<a.length;++c)l=a[c],o.backdrop&&je(t,o.backdrop),r&&(o.strokeColor&&(t.strokeStyle=o.strokeColor),dt(o.strokeWidth)||(t.lineWidth=o.strokeWidth),t.strokeText(l,n,i,o.maxWidth)),t.fillText(l,n,i,o.maxWidth),Ve(t,n,i,l,o),i+=Number(s.lineHeight);t.restore()}function Ue(t,e){const{x:n,y:i,w:s,h:o,radius:a}=e;t.arc(n+a.topLeft,i+a.topLeft,a.topLeft,1.5*Lt,Lt,!0),t.lineTo(n,i+o-a.bottomLeft),t.arc(n+a.bottomLeft,i+o-a.bottomLeft,a.bottomLeft,Lt,Nt,!0),t.lineTo(n+s-a.bottomRight,i+o),t.arc(n+s-a.bottomRight,i+o-a.bottomRight,a.bottomRight,Nt,0,!0),t.lineTo(n+s,i+a.topRight),t.arc(n+s-a.topRight,i+a.topRight,a.topRight,0,-Nt,!0),t.lineTo(n+a.topLeft,i)}const Xe=/^(normal|(\d+(?:\.\d+)?)(px|em|%)?)$/,Qe=/^(normal|italic|initial|inherit|unset|(oblique( -?[0-9]?[0-9]deg)?))$/;function Ke(t,e){const n=(""+t).match(Xe);if(!n||"normal"===n[1])return 1.2*e;switch(t=+n[2],n[3]){case"px":return t;case"%":t/=100}return e*t}function Ze(t,e){const n={},i=ut(e),s=i?Object.keys(e):e,o=ut(t)?i?n=>mt(t[n],t[e[n]]):e=>t[e]:()=>t;for(const t of s)n[t]=+o(t)||0;return n}function Ge(t){return Ze(t,{top:"y",right:"x",bottom:"y",left:"x"})}function Je(t){return Ze(t,["topLeft","topRight","bottomLeft","bottomRight"])}function tn(t){const e=Ge(t);return e.width=e.left+e.right,e.height=e.top+e.bottom,e}function en(t,e){t=t||{},e=e||Le.font;let n=mt(t.size,e.size);"string"==typeof n&&(n=parseInt(n,10));let i=mt(t.style,e.style);i&&!(""+i).match(Qe)&&(console.warn('Invalid font style specified: "'+i+'"'),i=void 0);const s={family:mt(t.family,e.family),lineHeight:Ke(mt(t.lineHeight,e.lineHeight),n),size:n,style:i,weight:mt(t.weight,e.weight),string:""};return s.string=function(t){return!t||dt(t.size)||dt(t.family)?null:(t.style?t.style+" ":"")+(t.weight?t.weight+" ":"")+t.size+"px "+t.family}(s),s}function nn(t,e,n,i){let s,o,a,r=!0;for(s=0,o=t.length;s<o;++s)if(a=t[s],void 0!==a&&(void 0!==e&&"function"==typeof a&&(a=a(e),r=!1),void 0!==n&&ht(a)&&(a=a[n%a.length],r=!1),void 0!==a))return i&&!r&&(i.cacheable=!1),a}function sn(t,e){return Object.assign(Object.create(t),e)}function on(t,e=[""],n,i,s=()=>t[0]){const o=n||t;void 0===i&&(i=fn("_fallback",t));const a={[Symbol.toStringTag]:"Object",_cacheable:!0,_scopes:t,_rootScopes:o,_fallback:i,_getTarget:s,override:n=>on([n,...t],e,o,i)};return new Proxy(a,{deleteProperty:(e,n)=>(delete e[n],delete e._keys,delete t[0][n],!0),get:(n,i)=>dn(n,i,(()=>function(t,e,n,i){let s;for(const o of e)if(s=fn(cn(o,t),n),void 0!==s)return ln(t,s)?pn(n,i,t,s):s}(i,e,t,n))),getOwnPropertyDescriptor:(t,e)=>Reflect.getOwnPropertyDescriptor(t._scopes[0],e),getPrototypeOf:()=>Reflect.getPrototypeOf(t[0]),has:(t,e)=>bn(t).includes(e),ownKeys:t=>bn(t),set(t,e,n){const i=t._storage||(t._storage=s());return t[e]=i[e]=n,delete t._keys,!0}})}function an(t,e,n,i){const s={_cacheable:!1,_proxy:t,_context:e,_subProxy:n,_stack:new Set,_descriptors:rn(t,i),setContext:e=>an(t,e,n,i),override:s=>an(t.override(s),e,n,i)};return new Proxy(s,{deleteProperty:(e,n)=>(delete e[n],delete t[n],!0),get:(t,e,n)=>dn(t,e,(()=>function(t,e,n){const{_proxy:i,_context:s,_subProxy:o,_descriptors:a}=t;let r=i[e];Et(r)&&a.isScriptable(e)&&(r=function(t,e,n,i){const{_proxy:s,_context:o,_subProxy:a,_stack:r}=n;if(r.has(t))throw new Error("Recursion detected: "+Array.from(r).join("->")+"->"+t);r.add(t);let c=e(o,a||i);r.delete(t),ln(t,c)&&(c=pn(s._scopes,s,t,c));return c}(e,r,t,n));ht(r)&&r.length&&(r=function(t,e,n,i){const{_proxy:s,_context:o,_subProxy:a,_descriptors:r}=n;if(void 0!==o.index&&i(t))return e[o.index%e.length];if(ut(e[0])){const n=e,i=s._scopes.filter((t=>t!==n));e=[];for(const c of n){const n=pn(i,s,t,c);e.push(an(n,o,a&&a[t],r))}}return e}(e,r,t,a.isIndexable));ln(e,r)&&(r=an(r,s,o&&o[e],a));return r}(t,e,n))),getOwnPropertyDescriptor:(e,n)=>e._descriptors.allKeys?Reflect.has(t,n)?{enumerable:!0,configurable:!0}:void 0:Reflect.getOwnPropertyDescriptor(t,n),getPrototypeOf:()=>Reflect.getPrototypeOf(t),has:(e,n)=>Reflect.has(t,n),ownKeys:()=>Reflect.ownKeys(t),set:(e,n,i)=>(t[n]=i,delete e[n],!0)})}function rn(t,e={scriptable:!0,indexable:!0}){const{_scriptable:n=e.scriptable,_indexable:i=e.indexable,_allKeys:s=e.allKeys}=t;return{allKeys:s,scriptable:n,indexable:i,isScriptable:Et(n)?n:()=>n,isIndexable:Et(i)?i:()=>i}}const cn=(t,e)=>t?t+Dt(e):e,ln=(t,e)=>ut(e)&&"adapters"!==t&&(null===Object.getPrototypeOf(e)||e.constructor===Object);function dn(t,e,n){if(Object.prototype.hasOwnProperty.call(t,e)||"constructor"===e)return t[e];const i=n();return t[e]=i,i}function hn(t,e,n){return Et(t)?t(e,n):t}const un=(t,e)=>!0===t?e:"string"==typeof t?Tt(e,t):void 0;function gn(t,e,n,i,s){for(const o of e){const e=un(n,o);if(e){t.add(e);const o=hn(e._fallback,n,s);if(void 0!==o&&o!==n&&o!==i)return o}else if(!1===e&&void 0!==i&&n!==i)return null}return!1}function pn(t,e,n,i){const s=e._rootScopes,o=hn(e._fallback,n,i),a=[...t,...s],r=new Set;r.add(i);let c=mn(r,a,n,o||n,i);return null!==c&&((void 0===o||o===n||(c=mn(r,a,o,c,i),null!==c))&&on(Array.from(r),[""],s,o,(()=>function(t,e,n){const i=t._getTarget();e in i||(i[e]={});const s=i[e];if(ht(s)&&ut(n))return n;return s||{}}(e,n,i))))}function mn(t,e,n,i,s){for(;n;)n=gn(t,e,n,i,s);return n}function fn(t,e){for(const n of e){if(!n)continue;const e=n[t];if(void 0!==e)return e}}function bn(t){let e=t._keys;return e||(e=t._keys=function(t){const e=new Set;for(const n of t)for(const t of Object.keys(n).filter((t=>!t.startsWith("_"))))e.add(t);return Array.from(e)}(t._scopes)),e}function yn(t,e,n,i){const{iScale:s}=t,{key:o="r"}=this._parsing,a=new Array(i);let r,c,l,d;for(r=0,c=i;r<c;++r)l=r+n,d=e[l],a[r]={r:s.parse(Tt(d,o),l)};return a}const xn=Number.EPSILON||1e-14,vn=(t,e)=>e<t.length&&!t[e].skip&&t[e],wn=t=>"x"===t?"y":"x";function Sn(t,e,n,i){const s=t.skip?e:t,o=e,a=n.skip?e:n,r=Kt(o,s),c=Kt(a,o);let l=r/(r+c),d=c/(r+c);l=isNaN(l)?0:l,d=isNaN(d)?0:d;const h=i*l,u=i*d;return{previous:{x:o.x-h*(a.x-s.x),y:o.y-h*(a.y-s.y)},next:{x:o.x+u*(a.x-s.x),y:o.y+u*(a.y-s.y)}}}function kn(t,e="x"){const n=wn(e),i=t.length,s=Array(i).fill(0),o=Array(i);let a,r,c,l=vn(t,0);for(a=0;a<i;++a)if(r=c,c=l,l=vn(t,a+1),c){if(l){const t=l[e]-c[e];s[a]=0!==t?(l[n]-c[n])/t:0}o[a]=r?l?qt(s[a-1])!==qt(s[a])?0:(s[a-1]+s[a])/2:s[a-1]:s[a]}!function(t,e,n){const i=t.length;let s,o,a,r,c,l=vn(t,0);for(let d=0;d<i-1;++d)c=l,l=vn(t,d+1),c&&l&&(Bt(e[d],0,xn)?n[d]=n[d+1]=0:(s=n[d]/e[d],o=n[d+1]/e[d],r=Math.pow(s,2)+Math.pow(o,2),r<=9||(a=3/Math.sqrt(r),n[d]=s*a*e[d],n[d+1]=o*a*e[d])))}(t,s,o),function(t,e,n="x"){const i=wn(n),s=t.length;let o,a,r,c=vn(t,0);for(let l=0;l<s;++l){if(a=r,r=c,c=vn(t,l+1),!r)continue;const s=r[n],d=r[i];a&&(o=(s-a[n])/3,r[`cp1${n}`]=s-o,r[`cp1${i}`]=d-o*e[l]),c&&(o=(c[n]-s)/3,r[`cp2${n}`]=s+o,r[`cp2${i}`]=d+o*e[l])}}(t,o,e)}function Mn(t,e,n){return Math.max(Math.min(t,n),e)}function _n(t,e,n,i,s){let o,a,r,c;if(e.spanGaps&&(t=t.filter((t=>!t.skip))),"monotone"===e.cubicInterpolationMode)kn(t,s);else{let n=i?t[t.length-1]:t[0];for(o=0,a=t.length;o<a;++o)r=t[o],c=Sn(n,r,t[Math.min(o+1,a-(i?0:1))%a],e.tension),r.cp1x=c.previous.x,r.cp1y=c.previous.y,r.cp2x=c.next.x,r.cp2y=c.next.y,n=r}e.capBezierPoints&&function(t,e){let n,i,s,o,a,r=$e(t[0],e);for(n=0,i=t.length;n<i;++n)a=o,o=r,r=n<i-1&&$e(t[n+1],e),o&&(s=t[n],a&&(s.cp1x=Mn(s.cp1x,e.left,e.right),s.cp1y=Mn(s.cp1y,e.top,e.bottom)),r&&(s.cp2x=Mn(s.cp2x,e.left,e.right),s.cp2y=Mn(s.cp2y,e.top,e.bottom)))}(t,n)}function Cn(){return"undefined"!=typeof window&&"undefined"!=typeof document}function Tn(t){let e=t.parentNode;return e&&"[object ShadowRoot]"===e.toString()&&(e=e.host),e}function Dn(t,e,n){let i;return"string"==typeof t?(i=parseInt(t,10),-1!==t.indexOf("%")&&(i=i/100*e.parentNode[n])):i=t,i}const Pn=t=>t.ownerDocument.defaultView.getComputedStyle(t,null);const En=["top","right","bottom","left"];function An(t,e,n){const i={};n=n?"-"+n:"";for(let s=0;s<4;s++){const o=En[s];i[o]=parseFloat(t[e+"-"+o+n])||0}return i.width=i.left+i.right,i.height=i.top+i.bottom,i}function Ln(t,e){if("native"in t)return t;const{canvas:n,currentDevicePixelRatio:i}=e,s=Pn(n),o="border-box"===s.boxSizing,a=An(s,"padding"),r=An(s,"border","width"),{x:c,y:l,box:d}=function(t,e){const n=t.touches,i=n&&n.length?n[0]:t,{offsetX:s,offsetY:o}=i;let a,r,c=!1;if(((t,e,n)=>(t>0||e>0)&&(!n||!n.shadowRoot))(s,o,t.target))a=s,r=o;else{const t=e.getBoundingClientRect();a=i.clientX-t.left,r=i.clientY-t.top,c=!0}return{x:a,y:r,box:c}}(t,n),h=a.left+(d&&r.left),u=a.top+(d&&r.top);let{width:g,height:p}=e;return o&&(g-=a.width+r.width,p-=a.height+r.height),{x:Math.round((c-h)/g*n.width/i),y:Math.round((l-u)/p*n.height/i)}}const In=t=>Math.round(10*t)/10;function On(t,e,n,i){const s=Pn(t),o=An(s,"margin"),a=Dn(s.maxWidth,t,"clientWidth")||zt,r=Dn(s.maxHeight,t,"clientHeight")||zt,c=function(t,e,n){let i,s;if(void 0===e||void 0===n){const o=t&&Tn(t);if(o){const t=o.getBoundingClientRect(),a=Pn(o),r=An(a,"border","width"),c=An(a,"padding");e=t.width-c.width-r.width,n=t.height-c.height-r.height,i=Dn(a.maxWidth,o,"clientWidth"),s=Dn(a.maxHeight,o,"clientHeight")}else e=t.clientWidth,n=t.clientHeight}return{width:e,height:n,maxWidth:i||zt,maxHeight:s||zt}}(t,e,n);let{width:l,height:d}=c;if("content-box"===s.boxSizing){const t=An(s,"border","width"),e=An(s,"padding");l-=e.width+t.width,d-=e.height+t.height}l=Math.max(0,l-o.width),d=Math.max(0,i?l/i:d-o.height),l=In(Math.min(l,a,c.maxWidth)),d=In(Math.min(d,r,c.maxHeight)),l&&!d&&(d=In(l/2));return(void 0!==e||void 0!==n)&&i&&c.height&&d>c.height&&(d=c.height,l=In(Math.floor(d*i))),{width:l,height:d}}function zn(t,e,n){const i=e||1,s=In(t.height*i),o=In(t.width*i);t.height=In(t.height),t.width=In(t.width);const a=t.canvas;return a.style&&(n||!a.style.height&&!a.style.width)&&(a.style.height=`${t.height}px`,a.style.width=`${t.width}px`),(t.currentDevicePixelRatio!==i||a.height!==s||a.width!==o)&&(t.currentDevicePixelRatio=i,a.height=s,a.width=o,t.ctx.setTransform(i,0,0,i,0,0),!0)}const Wn=function(){let t=!1;try{const e={get passive(){return t=!0,!1}};Cn()&&(window.addEventListener("test",null,e),window.removeEventListener("test",null,e))}catch(t){}return t}();function Nn(t,e){const n=function(t,e){return Pn(t).getPropertyValue(e)}(t,e),i=n&&n.match(/^(\d+)(\.\d+)?px$/);return i?+i[1]:void 0}function Rn(t,e,n,i){return{x:t.x+n*(e.x-t.x),y:t.y+n*(e.y-t.y)}}function $n(t,e,n,i){return{x:t.x+n*(e.x-t.x),y:"middle"===i?n<.5?t.y:e.y:"after"===i?n<1?t.y:e.y:n>0?e.y:t.y}}function Fn(t,e,n,i){const s={x:t.cp2x,y:t.cp2y},o={x:e.cp1x,y:e.cp1y},a=Rn(t,s,n),r=Rn(s,o,n),c=Rn(o,e,n),l=Rn(a,r,n),d=Rn(r,c,n);return Rn(l,d,n)}function qn(t,e,n){return t?function(t,e){return{x:n=>t+t+e-n,setWidth(t){e=t},textAlign:t=>"center"===t?t:"right"===t?"left":"right",xPlus:(t,e)=>t-e,leftForLtr:(t,e)=>t-e}}(e,n):{x:t=>t,setWidth(t){},textAlign:t=>t,xPlus:(t,e)=>t+e,leftForLtr:(t,e)=>t}}function Bn(t,e){let n,i;"ltr"!==e&&"rtl"!==e||(n=t.canvas.style,i=[n.getPropertyValue("direction"),n.getPropertyPriority("direction")],n.setProperty("direction",e,"important"),t.prevTextDirection=i)}function Hn(t,e){void 0!==e&&(delete t.prevTextDirection,t.canvas.style.setProperty("direction",e[0],e[1]))}function Vn(t){return"angle"===t?{between:Jt,compare:Zt,normalize:Gt}:{between:ee,compare:(t,e)=>t-e,normalize:t=>t}}function jn({start:t,end:e,count:n,loop:i,style:s}){return{start:t%n,end:e%n,loop:i&&(e-t+1)%n==0,style:s}}function Yn(t,e,n){if(!n)return[t];const{property:i,start:s,end:o}=n,a=e.length,{compare:r,between:c,normalize:l}=Vn(i),{start:d,end:h,loop:u,style:g}=function(t,e,n){const{property:i,start:s,end:o}=n,{between:a,normalize:r}=Vn(i),c=e.length;let l,d,{start:h,end:u,loop:g}=t;if(g){for(h+=c,u+=c,l=0,d=c;l<d&&a(r(e[h%c][i]),s,o);++l)h--,u--;h%=c,u%=c}return u<h&&(u+=c),{start:h,end:u,loop:g,style:t.style}}(t,e,n),p=[];let m,f,b,y=!1,x=null;const v=()=>y||c(s,b,m)&&0!==r(s,b),w=()=>!y||0===r(o,m)||c(o,b,m);for(let t=d,n=d;t<=h;++t)f=e[t%a],f.skip||(m=l(f[i]),m!==b&&(y=c(m,s,o),null===x&&v()&&(x=0===r(m,s)?t:n),null!==x&&w()&&(p.push(jn({start:x,end:t,loop:u,count:a,style:g})),x=null),n=t,b=m));return null!==x&&p.push(jn({start:x,end:h,loop:u,count:a,style:g})),p}function Un(t,e){const n=[],i=t.segments;for(let s=0;s<i.length;s++){const o=Yn(i[s],t.points,e);o.length&&n.push(...o)}return n}function Xn(t,e,n,i){return i&&i.setContext&&n?function(t,e,n,i){const s=t._chart.getContext(),o=Qn(t.options),{_datasetIndex:a,options:{spanGaps:r}}=t,c=n.length,l=[];let d=o,h=e[0].start,u=h;function g(t,e,i,s){const o=r?-1:1;if(t!==e){for(t+=c;n[t%c].skip;)t-=o;for(;n[e%c].skip;)e+=o;t%c!==e%c&&(l.push({start:t%c,end:e%c,loop:i,style:s}),d=s,h=e%c)}}for(const t of e){h=r?h:t.start;let e,o=n[h%c];for(u=h+1;u<=t.end;u++){const r=n[u%c];e=Qn(i.setContext(sn(s,{type:"segment",p0:o,p1:r,p0DataIndex:(u-1)%c,p1DataIndex:u%c,datasetIndex:a}))),Kn(e,d)&&g(h,u-1,t.loop,d),o=r,d=e}h<u-1&&g(h,u-1,t.loop,d)}return l}(t,e,n,i):e}function Qn(t){return{backgroundColor:t.backgroundColor,borderCapStyle:t.borderCapStyle,borderDash:t.borderDash,borderDashOffset:t.borderDashOffset,borderJoinStyle:t.borderJoinStyle,borderWidth:t.borderWidth,borderColor:t.borderColor}}function Kn(t,e){if(!e)return!1;const n=[],i=function(t,e){return ye(e)?(n.includes(e)||n.push(e),n.indexOf(e)):e};return JSON.stringify(t,i)!==JSON.stringify(e,i)}function Zn(t,e,n){return t.options.clip?t[n]:e[n]}function Gn(t,e){const n=e._clip;if(n.disabled)return!1;const i=function(t,e){const{xScale:n,yScale:i}=t;return n&&i?{left:Zn(n,e,"left"),right:Zn(n,e,"right"),top:Zn(i,e,"top"),bottom:Zn(i,e,"bottom")}:e}(e,t.chartArea);return{left:!1===n.left?0:i.left-(!0===n.left?0:n.left),right:!1===n.right?t.width:i.right+(!0===n.right?0:n.right),top:!1===n.top?0:i.top-(!0===n.top?0:n.top),bottom:!1===n.bottom?t.height:i.bottom+(!0===n.bottom?0:n.bottom)}}
|
|
14
|
+
*/function ct(){}const lt=(()=>{let t=0;return()=>t++})();function dt(t){return null==t}function ht(t){if(Array.isArray&&Array.isArray(t))return!0;const e=Object.prototype.toString.call(t);return"[object"===e.slice(0,7)&&"Array]"===e.slice(-6)}function ut(t){return null!==t&&"[object Object]"===Object.prototype.toString.call(t)}function gt(t){return("number"==typeof t||t instanceof Number)&&isFinite(+t)}function pt(t,e){return gt(t)?t:e}function mt(t,e){return void 0===t?e:t}const ft=(t,e)=>"string"==typeof t&&t.endsWith("%")?parseFloat(t)/100*e:+t;function bt(t,e,n){if(t&&"function"==typeof t.call)return t.apply(n,e)}function yt(t,e,n,i){let s,o,a;if(ht(t))if(o=t.length,i)for(s=o-1;s>=0;s--)e.call(n,t[s],s);else for(s=0;s<o;s++)e.call(n,t[s],s);else if(ut(t))for(a=Object.keys(t),o=a.length,s=0;s<o;s++)e.call(n,t[a[s]],a[s])}function xt(t,e){let n,i,s,o;if(!t||!e||t.length!==e.length)return!1;for(n=0,i=t.length;n<i;++n)if(s=t[n],o=e[n],s.datasetIndex!==o.datasetIndex||s.index!==o.index)return!1;return!0}function vt(t){if(ht(t))return t.map(vt);if(ut(t)){const e=Object.create(null),n=Object.keys(t),i=n.length;let s=0;for(;s<i;++s)e[n[s]]=vt(t[n[s]]);return e}return t}function wt(t){return-1===["__proto__","prototype","constructor"].indexOf(t)}function St(t,e,n,i){if(!wt(t))return;const s=e[t],o=n[t];ut(s)&&ut(o)?kt(s,o,i):e[t]=vt(o)}function kt(t,e,n){const i=ht(e)?e:[e],s=i.length;if(!ut(t))return t;const o=(n=n||{}).merger||St;let a;for(let e=0;e<s;++e){if(a=i[e],!ut(a))continue;const s=Object.keys(a);for(let e=0,i=s.length;e<i;++e)o(s[e],t,a,n)}return t}function Mt(t,e){return kt(t,e,{merger:Ct})}function Ct(t,e,n){if(!wt(t))return;const i=e[t],s=n[t];ut(i)&&ut(s)?Mt(i,s):Object.prototype.hasOwnProperty.call(e,t)||(e[t]=vt(s))}const _t={"":t=>t,x:t=>t.x,y:t=>t.y};function Dt(t,e){const n=_t[e]||(_t[e]=function(t){const e=function(t){const e=t.split("."),n=[];let i="";for(const t of e)i+=t,i.endsWith("\\")?i=i.slice(0,-1)+".":(n.push(i),i="");return n}(t);return t=>{for(const n of e){if(""===n)break;t=t&&t[n]}return t}}(e));return n(t)}function Tt(t){return t.charAt(0).toUpperCase()+t.slice(1)}const Pt=t=>void 0!==t,Et=t=>"function"==typeof t,At=(t,e)=>{if(t.size!==e.size)return!1;for(const n of t)if(!e.has(n))return!1;return!0};const Lt=Math.PI,It=2*Lt,Ot=It+Lt,zt=Number.POSITIVE_INFINITY,Wt=Lt/180,Nt=Lt/2,Rt=Lt/4,$t=2*Lt/3,Ft=Math.log10,qt=Math.sign;function Bt(t,e,n){return Math.abs(t-e)<n}function Ht(t){const e=Math.round(t);t=Bt(t,e,t/1e3)?e:t;const n=Math.pow(10,Math.floor(Ft(t))),i=t/n;return(i<=1?1:i<=2?2:i<=5?5:10)*n}function Vt(t){return!function(t){return"symbol"==typeof t||"object"==typeof t&&null!==t&&!(Symbol.toPrimitive in t||"toString"in t||"valueOf"in t)}(t)&&!isNaN(parseFloat(t))&&isFinite(t)}function jt(t,e,n){let i,s,o;for(i=0,s=t.length;i<s;i++)o=t[i][n],isNaN(o)||(e.min=Math.min(e.min,o),e.max=Math.max(e.max,o))}function Yt(t){return t*(Lt/180)}function Ut(t){return t*(180/Lt)}function Xt(t){if(!gt(t))return;let e=1,n=0;for(;Math.round(t*e)/e!==t;)e*=10,n++;return n}function Qt(t,e){const n=e.x-t.x,i=e.y-t.y,s=Math.sqrt(n*n+i*i);let o=Math.atan2(i,n);return o<-.5*Lt&&(o+=It),{angle:o,distance:s}}function Kt(t,e){return Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2))}function Gt(t,e){return(t-e+Ot)%It-Lt}function Zt(t){return(t%It+It)%It}function Jt(t,e,n,i){const s=Zt(t),o=Zt(e),a=Zt(n),r=Zt(o-s),c=Zt(a-s),l=Zt(s-o),d=Zt(s-a);return s===o||s===a||i&&o===a||r>c&&l<d}function te(t,e,n){return Math.max(e,Math.min(n,t))}function ee(t,e,n,i=1e-6){return t>=Math.min(e,n)-i&&t<=Math.max(e,n)+i}function ne(t,e,n){n=n||(n=>t[n]<e);let i,s=t.length-1,o=0;for(;s-o>1;)i=o+s>>1,n(i)?o=i:s=i;return{lo:o,hi:s}}const ie=(t,e,n,i)=>ne(t,n,i?i=>{const s=t[i][e];return s<n||s===n&&t[i+1][e]===n}:i=>t[i][e]<n),se=(t,e,n)=>ne(t,n,(i=>t[i][e]>=n));const oe=["push","pop","shift","splice","unshift"];function ae(t,e){const n=t._chartjs;if(!n)return;const i=n.listeners,s=i.indexOf(e);-1!==s&&i.splice(s,1),i.length>0||(oe.forEach((e=>{delete t[e]})),delete t._chartjs)}function re(t){const e=new Set(t);return e.size===t.length?t:Array.from(e)}const ce="undefined"==typeof window?function(t){return t()}:window.requestAnimationFrame;function le(t,e){let n=[],i=!1;return function(...s){n=s,i||(i=!0,ce.call(window,(()=>{i=!1,t.apply(e,n)})))}}const de=t=>"start"===t?"left":"end"===t?"right":"center",he=(t,e,n)=>"start"===t?e:"end"===t?n:(e+n)/2;function ue(t,e,n){const i=e.length;let s=0,o=i;if(t._sorted){const{iScale:a,vScale:r,_parsed:c}=t,l=t.dataset&&t.dataset.options?t.dataset.options.spanGaps:null,d=a.axis,{min:h,max:u,minDefined:g,maxDefined:p}=a.getUserBounds();if(g){if(s=Math.min(ie(c,d,h).lo,n?i:ie(e,d,a.getPixelForValue(h)).lo),l){const t=c.slice(0,s+1).reverse().findIndex((t=>!dt(t[r.axis])));s-=Math.max(0,t)}s=te(s,0,i-1)}if(p){let t=Math.max(ie(c,a.axis,u,!0).hi+1,n?0:ie(e,d,a.getPixelForValue(u),!0).hi+1);if(l){const e=c.slice(t-1).findIndex((t=>!dt(t[r.axis])));t+=Math.max(0,e)}o=te(t,s,i)-s}else o=i-s}return{start:s,count:o}}function ge(t){const{xScale:e,yScale:n,_scaleRanges:i}=t,s={xmin:e.min,xmax:e.max,ymin:n.min,ymax:n.max};if(!i)return t._scaleRanges=s,!0;const o=i.xmin!==e.min||i.xmax!==e.max||i.ymin!==n.min||i.ymax!==n.max;return Object.assign(i,s),o}const pe=t=>0===t||1===t,me=(t,e,n)=>-Math.pow(2,10*(t-=1))*Math.sin((t-e)*It/n),fe=(t,e,n)=>Math.pow(2,-10*t)*Math.sin((t-e)*It/n)+1,be={linear:t=>t,easeInQuad:t=>t*t,easeOutQuad:t=>-t*(t-2),easeInOutQuad:t=>(t/=.5)<1?.5*t*t:-.5*(--t*(t-2)-1),easeInCubic:t=>t*t*t,easeOutCubic:t=>(t-=1)*t*t+1,easeInOutCubic:t=>(t/=.5)<1?.5*t*t*t:.5*((t-=2)*t*t+2),easeInQuart:t=>t*t*t*t,easeOutQuart:t=>-((t-=1)*t*t*t-1),easeInOutQuart:t=>(t/=.5)<1?.5*t*t*t*t:-.5*((t-=2)*t*t*t-2),easeInQuint:t=>t*t*t*t*t,easeOutQuint:t=>(t-=1)*t*t*t*t+1,easeInOutQuint:t=>(t/=.5)<1?.5*t*t*t*t*t:.5*((t-=2)*t*t*t*t+2),easeInSine:t=>1-Math.cos(t*Nt),easeOutSine:t=>Math.sin(t*Nt),easeInOutSine:t=>-.5*(Math.cos(Lt*t)-1),easeInExpo:t=>0===t?0:Math.pow(2,10*(t-1)),easeOutExpo:t=>1===t?1:1-Math.pow(2,-10*t),easeInOutExpo:t=>pe(t)?t:t<.5?.5*Math.pow(2,10*(2*t-1)):.5*(2-Math.pow(2,-10*(2*t-1))),easeInCirc:t=>t>=1?t:-(Math.sqrt(1-t*t)-1),easeOutCirc:t=>Math.sqrt(1-(t-=1)*t),easeInOutCirc:t=>(t/=.5)<1?-.5*(Math.sqrt(1-t*t)-1):.5*(Math.sqrt(1-(t-=2)*t)+1),easeInElastic:t=>pe(t)?t:me(t,.075,.3),easeOutElastic:t=>pe(t)?t:fe(t,.075,.3),easeInOutElastic(t){const e=.1125;return pe(t)?t:t<.5?.5*me(2*t,e,.45):.5+.5*fe(2*t-1,e,.45)},easeInBack(t){const e=1.70158;return t*t*((e+1)*t-e)},easeOutBack(t){const e=1.70158;return(t-=1)*t*((e+1)*t+e)+1},easeInOutBack(t){let e=1.70158;return(t/=.5)<1?t*t*((1+(e*=1.525))*t-e)*.5:.5*((t-=2)*t*((1+(e*=1.525))*t+e)+2)},easeInBounce:t=>1-be.easeOutBounce(1-t),easeOutBounce(t){const e=7.5625,n=2.75;return t<1/n?e*t*t:t<2/n?e*(t-=1.5/n)*t+.75:t<2.5/n?e*(t-=2.25/n)*t+.9375:e*(t-=2.625/n)*t+.984375},easeInOutBounce:t=>t<.5?.5*be.easeInBounce(2*t):.5*be.easeOutBounce(2*t-1)+.5};function ye(t){if(t&&"object"==typeof t){const e=t.toString();return"[object CanvasPattern]"===e||"[object CanvasGradient]"===e}return!1}function xe(t){return ye(t)?t:new rt(t)}function ve(t){return ye(t)?t:new rt(t).saturate(.5).darken(.1).hexString()}const we=["x","y","borderWidth","radius","tension"],Se=["color","borderColor","backgroundColor"];const ke=new Map;function Me(t,e,n){return function(t,e){e=e||{};const n=t+JSON.stringify(e);let i=ke.get(n);return i||(i=new Intl.NumberFormat(t,e),ke.set(n,i)),i}(e,n).format(t)}const Ce={values:t=>ht(t)?t:""+t,numeric(t,e,n){if(0===t)return"0";const i=this.chart.options.locale;let s,o=t;if(n.length>1){const e=Math.max(Math.abs(n[0].value),Math.abs(n[n.length-1].value));(e<1e-4||e>1e15)&&(s="scientific"),o=function(t,e){let n=e.length>3?e[2].value-e[1].value:e[1].value-e[0].value;Math.abs(n)>=1&&t!==Math.floor(t)&&(n=t-Math.floor(t));return n}(t,n)}const a=Ft(Math.abs(o)),r=isNaN(a)?1:Math.max(Math.min(-1*Math.floor(a),20),0),c={notation:s,minimumFractionDigits:r,maximumFractionDigits:r};return Object.assign(c,this.options.ticks.format),Me(t,i,c)},logarithmic(t,e,n){if(0===t)return"0";const i=n[e].significand||t/Math.pow(10,Math.floor(Ft(t)));return[1,2,3,5,10,15].includes(i)||e>.8*n.length?Ce.numeric.call(this,t,e,n):""}};var _e={formatters:Ce};const De=Object.create(null),Te=Object.create(null);function Pe(t,e){if(!e)return t;const n=e.split(".");for(let e=0,i=n.length;e<i;++e){const i=n[e];t=t[i]||(t[i]=Object.create(null))}return t}function Ee(t,e,n){return"string"==typeof e?kt(Pe(t,e),n):kt(Pe(t,""),e)}class Ae{constructor(t,e){this.animation=void 0,this.backgroundColor="rgba(0,0,0,0.1)",this.borderColor="rgba(0,0,0,0.1)",this.color="#666",this.datasets={},this.devicePixelRatio=t=>t.chart.platform.getDevicePixelRatio(),this.elements={},this.events=["mousemove","mouseout","click","touchstart","touchmove"],this.font={family:"'Helvetica Neue', 'Helvetica', 'Arial', sans-serif",size:12,style:"normal",lineHeight:1.2,weight:null},this.hover={},this.hoverBackgroundColor=(t,e)=>ve(e.backgroundColor),this.hoverBorderColor=(t,e)=>ve(e.borderColor),this.hoverColor=(t,e)=>ve(e.color),this.indexAxis="x",this.interaction={mode:"nearest",intersect:!0,includeInvisible:!1},this.maintainAspectRatio=!0,this.onHover=null,this.onClick=null,this.parsing=!0,this.plugins={},this.responsive=!0,this.scale=void 0,this.scales={},this.showLine=!0,this.drawActiveElementsOnTop=!0,this.describe(t),this.apply(e)}set(t,e){return Ee(this,t,e)}get(t){return Pe(this,t)}describe(t,e){return Ee(Te,t,e)}override(t,e){return Ee(De,t,e)}route(t,e,n,i){const s=Pe(this,t),o=Pe(this,n),a="_"+e;Object.defineProperties(s,{[a]:{value:s[e],writable:!0},[e]:{enumerable:!0,get(){const t=this[a],e=o[i];return ut(t)?Object.assign({},e,t):mt(t,e)},set(t){this[a]=t}}})}apply(t){t.forEach((t=>t(this)))}}var Le=new Ae({_scriptable:t=>!t.startsWith("on"),_indexable:t=>"events"!==t,hover:{_fallback:"interaction"},interaction:{_scriptable:!1,_indexable:!1}},[function(t){t.set("animation",{delay:void 0,duration:1e3,easing:"easeOutQuart",fn:void 0,from:void 0,loop:void 0,to:void 0,type:void 0}),t.describe("animation",{_fallback:!1,_indexable:!1,_scriptable:t=>"onProgress"!==t&&"onComplete"!==t&&"fn"!==t}),t.set("animations",{colors:{type:"color",properties:Se},numbers:{type:"number",properties:we}}),t.describe("animations",{_fallback:"animation"}),t.set("transitions",{active:{animation:{duration:400}},resize:{animation:{duration:0}},show:{animations:{colors:{from:"transparent"},visible:{type:"boolean",duration:0}}},hide:{animations:{colors:{to:"transparent"},visible:{type:"boolean",easing:"linear",fn:t=>0|t}}}})},function(t){t.set("layout",{autoPadding:!0,padding:{top:0,right:0,bottom:0,left:0}})},function(t){t.set("scale",{display:!0,offset:!1,reverse:!1,beginAtZero:!1,bounds:"ticks",clip:!0,grace:0,grid:{display:!0,lineWidth:1,drawOnChartArea:!0,drawTicks:!0,tickLength:8,tickWidth:(t,e)=>e.lineWidth,tickColor:(t,e)=>e.color,offset:!1},border:{display:!0,dash:[],dashOffset:0,width:1},title:{display:!1,text:"",padding:{top:4,bottom:4}},ticks:{minRotation:0,maxRotation:50,mirror:!1,textStrokeWidth:0,textStrokeColor:"",padding:3,display:!0,autoSkip:!0,autoSkipPadding:3,labelOffset:0,callback:_e.formatters.values,minor:{},major:{},align:"center",crossAlign:"near",showLabelBackdrop:!1,backdropColor:"rgba(255, 255, 255, 0.75)",backdropPadding:2}}),t.route("scale.ticks","color","","color"),t.route("scale.grid","color","","borderColor"),t.route("scale.border","color","","borderColor"),t.route("scale.title","color","","color"),t.describe("scale",{_fallback:!1,_scriptable:t=>!t.startsWith("before")&&!t.startsWith("after")&&"callback"!==t&&"parser"!==t,_indexable:t=>"borderDash"!==t&&"tickBorderDash"!==t&&"dash"!==t}),t.describe("scales",{_fallback:"scale"}),t.describe("scale.ticks",{_scriptable:t=>"backdropPadding"!==t&&"callback"!==t,_indexable:t=>"backdropPadding"!==t})}]);function Ie(t,e,n,i,s){let o=e[s];return o||(o=e[s]=t.measureText(s).width,n.push(s)),o>i&&(i=o),i}function Oe(t,e,n,i){let s=(i=i||{}).data=i.data||{},o=i.garbageCollect=i.garbageCollect||[];i.font!==e&&(s=i.data={},o=i.garbageCollect=[],i.font=e),t.save(),t.font=e;let a=0;const r=n.length;let c,l,d,h,u;for(c=0;c<r;c++)if(h=n[c],null==h||ht(h)){if(ht(h))for(l=0,d=h.length;l<d;l++)u=h[l],null==u||ht(u)||(a=Ie(t,s,o,a,u))}else a=Ie(t,s,o,a,h);t.restore();const g=o.length/2;if(g>n.length){for(c=0;c<g;c++)delete s[o[c]];o.splice(0,g)}return a}function ze(t,e,n){const i=t.currentDevicePixelRatio,s=0!==n?Math.max(n/2,.5):0;return Math.round((e-s)*i)/i+s}function We(t,e){(e||t)&&((e=e||t.getContext("2d")).save(),e.resetTransform(),e.clearRect(0,0,t.width,t.height),e.restore())}function Ne(t,e,n,i){Re(t,e,n,i,null)}function Re(t,e,n,i,s){let o,a,r,c,l,d,h,u;const g=e.pointStyle,p=e.rotation,m=e.radius;let f=(p||0)*Wt;if(g&&"object"==typeof g&&(o=g.toString(),"[object HTMLImageElement]"===o||"[object HTMLCanvasElement]"===o))return t.save(),t.translate(n,i),t.rotate(f),t.drawImage(g,-g.width/2,-g.height/2,g.width,g.height),void t.restore();if(!(isNaN(m)||m<=0)){switch(t.beginPath(),g){default:s?t.ellipse(n,i,s/2,m,0,0,It):t.arc(n,i,m,0,It),t.closePath();break;case"triangle":d=s?s/2:m,t.moveTo(n+Math.sin(f)*d,i-Math.cos(f)*m),f+=$t,t.lineTo(n+Math.sin(f)*d,i-Math.cos(f)*m),f+=$t,t.lineTo(n+Math.sin(f)*d,i-Math.cos(f)*m),t.closePath();break;case"rectRounded":l=.516*m,c=m-l,a=Math.cos(f+Rt)*c,h=Math.cos(f+Rt)*(s?s/2-l:c),r=Math.sin(f+Rt)*c,u=Math.sin(f+Rt)*(s?s/2-l:c),t.arc(n-h,i-r,l,f-Lt,f-Nt),t.arc(n+u,i-a,l,f-Nt,f),t.arc(n+h,i+r,l,f,f+Nt),t.arc(n-u,i+a,l,f+Nt,f+Lt),t.closePath();break;case"rect":if(!p){c=Math.SQRT1_2*m,d=s?s/2:c,t.rect(n-d,i-c,2*d,2*c);break}f+=Rt;case"rectRot":h=Math.cos(f)*(s?s/2:m),a=Math.cos(f)*m,r=Math.sin(f)*m,u=Math.sin(f)*(s?s/2:m),t.moveTo(n-h,i-r),t.lineTo(n+u,i-a),t.lineTo(n+h,i+r),t.lineTo(n-u,i+a),t.closePath();break;case"crossRot":f+=Rt;case"cross":h=Math.cos(f)*(s?s/2:m),a=Math.cos(f)*m,r=Math.sin(f)*m,u=Math.sin(f)*(s?s/2:m),t.moveTo(n-h,i-r),t.lineTo(n+h,i+r),t.moveTo(n+u,i-a),t.lineTo(n-u,i+a);break;case"star":h=Math.cos(f)*(s?s/2:m),a=Math.cos(f)*m,r=Math.sin(f)*m,u=Math.sin(f)*(s?s/2:m),t.moveTo(n-h,i-r),t.lineTo(n+h,i+r),t.moveTo(n+u,i-a),t.lineTo(n-u,i+a),f+=Rt,h=Math.cos(f)*(s?s/2:m),a=Math.cos(f)*m,r=Math.sin(f)*m,u=Math.sin(f)*(s?s/2:m),t.moveTo(n-h,i-r),t.lineTo(n+h,i+r),t.moveTo(n+u,i-a),t.lineTo(n-u,i+a);break;case"line":a=s?s/2:Math.cos(f)*m,r=Math.sin(f)*m,t.moveTo(n-a,i-r),t.lineTo(n+a,i+r);break;case"dash":t.moveTo(n,i),t.lineTo(n+Math.cos(f)*(s?s/2:m),i+Math.sin(f)*m);break;case!1:t.closePath()}t.fill(),e.borderWidth>0&&t.stroke()}}function $e(t,e,n){return n=n||.5,!e||t&&t.x>e.left-n&&t.x<e.right+n&&t.y>e.top-n&&t.y<e.bottom+n}function Fe(t,e){t.save(),t.beginPath(),t.rect(e.left,e.top,e.right-e.left,e.bottom-e.top),t.clip()}function qe(t){t.restore()}function Be(t,e,n,i,s){if(!e)return t.lineTo(n.x,n.y);if("middle"===s){const i=(e.x+n.x)/2;t.lineTo(i,e.y),t.lineTo(i,n.y)}else"after"===s!=!!i?t.lineTo(e.x,n.y):t.lineTo(n.x,e.y);t.lineTo(n.x,n.y)}function He(t,e,n,i){if(!e)return t.lineTo(n.x,n.y);t.bezierCurveTo(i?e.cp1x:e.cp2x,i?e.cp1y:e.cp2y,i?n.cp2x:n.cp1x,i?n.cp2y:n.cp1y,n.x,n.y)}function Ve(t,e,n,i,s){if(s.strikethrough||s.underline){const o=t.measureText(i),a=e-o.actualBoundingBoxLeft,r=e+o.actualBoundingBoxRight,c=n-o.actualBoundingBoxAscent,l=n+o.actualBoundingBoxDescent,d=s.strikethrough?(c+l)/2:l;t.strokeStyle=t.fillStyle,t.beginPath(),t.lineWidth=s.decorationWidth||2,t.moveTo(a,d),t.lineTo(r,d),t.stroke()}}function je(t,e){const n=t.fillStyle;t.fillStyle=e.color,t.fillRect(e.left,e.top,e.width,e.height),t.fillStyle=n}function Ye(t,e,n,i,s,o={}){const a=ht(e)?e:[e],r=o.strokeWidth>0&&""!==o.strokeColor;let c,l;for(t.save(),t.font=s.string,function(t,e){e.translation&&t.translate(e.translation[0],e.translation[1]),dt(e.rotation)||t.rotate(e.rotation),e.color&&(t.fillStyle=e.color),e.textAlign&&(t.textAlign=e.textAlign),e.textBaseline&&(t.textBaseline=e.textBaseline)}(t,o),c=0;c<a.length;++c)l=a[c],o.backdrop&&je(t,o.backdrop),r&&(o.strokeColor&&(t.strokeStyle=o.strokeColor),dt(o.strokeWidth)||(t.lineWidth=o.strokeWidth),t.strokeText(l,n,i,o.maxWidth)),t.fillText(l,n,i,o.maxWidth),Ve(t,n,i,l,o),i+=Number(s.lineHeight);t.restore()}function Ue(t,e){const{x:n,y:i,w:s,h:o,radius:a}=e;t.arc(n+a.topLeft,i+a.topLeft,a.topLeft,1.5*Lt,Lt,!0),t.lineTo(n,i+o-a.bottomLeft),t.arc(n+a.bottomLeft,i+o-a.bottomLeft,a.bottomLeft,Lt,Nt,!0),t.lineTo(n+s-a.bottomRight,i+o),t.arc(n+s-a.bottomRight,i+o-a.bottomRight,a.bottomRight,Nt,0,!0),t.lineTo(n+s,i+a.topRight),t.arc(n+s-a.topRight,i+a.topRight,a.topRight,0,-Nt,!0),t.lineTo(n+a.topLeft,i)}const Xe=/^(normal|(\d+(?:\.\d+)?)(px|em|%)?)$/,Qe=/^(normal|italic|initial|inherit|unset|(oblique( -?[0-9]?[0-9]deg)?))$/;function Ke(t,e){const n=(""+t).match(Xe);if(!n||"normal"===n[1])return 1.2*e;switch(t=+n[2],n[3]){case"px":return t;case"%":t/=100}return e*t}function Ge(t,e){const n={},i=ut(e),s=i?Object.keys(e):e,o=ut(t)?i?n=>mt(t[n],t[e[n]]):e=>t[e]:()=>t;for(const t of s)n[t]=+o(t)||0;return n}function Ze(t){return Ge(t,{top:"y",right:"x",bottom:"y",left:"x"})}function Je(t){return Ge(t,["topLeft","topRight","bottomLeft","bottomRight"])}function tn(t){const e=Ze(t);return e.width=e.left+e.right,e.height=e.top+e.bottom,e}function en(t,e){t=t||{},e=e||Le.font;let n=mt(t.size,e.size);"string"==typeof n&&(n=parseInt(n,10));let i=mt(t.style,e.style);i&&!(""+i).match(Qe)&&(console.warn('Invalid font style specified: "'+i+'"'),i=void 0);const s={family:mt(t.family,e.family),lineHeight:Ke(mt(t.lineHeight,e.lineHeight),n),size:n,style:i,weight:mt(t.weight,e.weight),string:""};return s.string=function(t){return!t||dt(t.size)||dt(t.family)?null:(t.style?t.style+" ":"")+(t.weight?t.weight+" ":"")+t.size+"px "+t.family}(s),s}function nn(t,e,n,i){let s,o,a,r=!0;for(s=0,o=t.length;s<o;++s)if(a=t[s],void 0!==a&&(void 0!==e&&"function"==typeof a&&(a=a(e),r=!1),void 0!==n&&ht(a)&&(a=a[n%a.length],r=!1),void 0!==a))return i&&!r&&(i.cacheable=!1),a}function sn(t,e){return Object.assign(Object.create(t),e)}function on(t,e=[""],n,i,s=()=>t[0]){const o=n||t;void 0===i&&(i=fn("_fallback",t));const a={[Symbol.toStringTag]:"Object",_cacheable:!0,_scopes:t,_rootScopes:o,_fallback:i,_getTarget:s,override:n=>on([n,...t],e,o,i)};return new Proxy(a,{deleteProperty:(e,n)=>(delete e[n],delete e._keys,delete t[0][n],!0),get:(n,i)=>dn(n,i,(()=>function(t,e,n,i){let s;for(const o of e)if(s=fn(cn(o,t),n),void 0!==s)return ln(t,s)?pn(n,i,t,s):s}(i,e,t,n))),getOwnPropertyDescriptor:(t,e)=>Reflect.getOwnPropertyDescriptor(t._scopes[0],e),getPrototypeOf:()=>Reflect.getPrototypeOf(t[0]),has:(t,e)=>bn(t).includes(e),ownKeys:t=>bn(t),set(t,e,n){const i=t._storage||(t._storage=s());return t[e]=i[e]=n,delete t._keys,!0}})}function an(t,e,n,i){const s={_cacheable:!1,_proxy:t,_context:e,_subProxy:n,_stack:new Set,_descriptors:rn(t,i),setContext:e=>an(t,e,n,i),override:s=>an(t.override(s),e,n,i)};return new Proxy(s,{deleteProperty:(e,n)=>(delete e[n],delete t[n],!0),get:(t,e,n)=>dn(t,e,(()=>function(t,e,n){const{_proxy:i,_context:s,_subProxy:o,_descriptors:a}=t;let r=i[e];Et(r)&&a.isScriptable(e)&&(r=function(t,e,n,i){const{_proxy:s,_context:o,_subProxy:a,_stack:r}=n;if(r.has(t))throw new Error("Recursion detected: "+Array.from(r).join("->")+"->"+t);r.add(t);let c=e(o,a||i);r.delete(t),ln(t,c)&&(c=pn(s._scopes,s,t,c));return c}(e,r,t,n));ht(r)&&r.length&&(r=function(t,e,n,i){const{_proxy:s,_context:o,_subProxy:a,_descriptors:r}=n;if(void 0!==o.index&&i(t))return e[o.index%e.length];if(ut(e[0])){const n=e,i=s._scopes.filter((t=>t!==n));e=[];for(const c of n){const n=pn(i,s,t,c);e.push(an(n,o,a&&a[t],r))}}return e}(e,r,t,a.isIndexable));ln(e,r)&&(r=an(r,s,o&&o[e],a));return r}(t,e,n))),getOwnPropertyDescriptor:(e,n)=>e._descriptors.allKeys?Reflect.has(t,n)?{enumerable:!0,configurable:!0}:void 0:Reflect.getOwnPropertyDescriptor(t,n),getPrototypeOf:()=>Reflect.getPrototypeOf(t),has:(e,n)=>Reflect.has(t,n),ownKeys:()=>Reflect.ownKeys(t),set:(e,n,i)=>(t[n]=i,delete e[n],!0)})}function rn(t,e={scriptable:!0,indexable:!0}){const{_scriptable:n=e.scriptable,_indexable:i=e.indexable,_allKeys:s=e.allKeys}=t;return{allKeys:s,scriptable:n,indexable:i,isScriptable:Et(n)?n:()=>n,isIndexable:Et(i)?i:()=>i}}const cn=(t,e)=>t?t+Tt(e):e,ln=(t,e)=>ut(e)&&"adapters"!==t&&(null===Object.getPrototypeOf(e)||e.constructor===Object);function dn(t,e,n){if(Object.prototype.hasOwnProperty.call(t,e)||"constructor"===e)return t[e];const i=n();return t[e]=i,i}function hn(t,e,n){return Et(t)?t(e,n):t}const un=(t,e)=>!0===t?e:"string"==typeof t?Dt(e,t):void 0;function gn(t,e,n,i,s){for(const o of e){const e=un(n,o);if(e){t.add(e);const o=hn(e._fallback,n,s);if(void 0!==o&&o!==n&&o!==i)return o}else if(!1===e&&void 0!==i&&n!==i)return null}return!1}function pn(t,e,n,i){const s=e._rootScopes,o=hn(e._fallback,n,i),a=[...t,...s],r=new Set;r.add(i);let c=mn(r,a,n,o||n,i);return null!==c&&((void 0===o||o===n||(c=mn(r,a,o,c,i),null!==c))&&on(Array.from(r),[""],s,o,(()=>function(t,e,n){const i=t._getTarget();e in i||(i[e]={});const s=i[e];if(ht(s)&&ut(n))return n;return s||{}}(e,n,i))))}function mn(t,e,n,i,s){for(;n;)n=gn(t,e,n,i,s);return n}function fn(t,e){for(const n of e){if(!n)continue;const e=n[t];if(void 0!==e)return e}}function bn(t){let e=t._keys;return e||(e=t._keys=function(t){const e=new Set;for(const n of t)for(const t of Object.keys(n).filter((t=>!t.startsWith("_"))))e.add(t);return Array.from(e)}(t._scopes)),e}function yn(t,e,n,i){const{iScale:s}=t,{key:o="r"}=this._parsing,a=new Array(i);let r,c,l,d;for(r=0,c=i;r<c;++r)l=r+n,d=e[l],a[r]={r:s.parse(Dt(d,o),l)};return a}const xn=Number.EPSILON||1e-14,vn=(t,e)=>e<t.length&&!t[e].skip&&t[e],wn=t=>"x"===t?"y":"x";function Sn(t,e,n,i){const s=t.skip?e:t,o=e,a=n.skip?e:n,r=Kt(o,s),c=Kt(a,o);let l=r/(r+c),d=c/(r+c);l=isNaN(l)?0:l,d=isNaN(d)?0:d;const h=i*l,u=i*d;return{previous:{x:o.x-h*(a.x-s.x),y:o.y-h*(a.y-s.y)},next:{x:o.x+u*(a.x-s.x),y:o.y+u*(a.y-s.y)}}}function kn(t,e="x"){const n=wn(e),i=t.length,s=Array(i).fill(0),o=Array(i);let a,r,c,l=vn(t,0);for(a=0;a<i;++a)if(r=c,c=l,l=vn(t,a+1),c){if(l){const t=l[e]-c[e];s[a]=0!==t?(l[n]-c[n])/t:0}o[a]=r?l?qt(s[a-1])!==qt(s[a])?0:(s[a-1]+s[a])/2:s[a-1]:s[a]}!function(t,e,n){const i=t.length;let s,o,a,r,c,l=vn(t,0);for(let d=0;d<i-1;++d)c=l,l=vn(t,d+1),c&&l&&(Bt(e[d],0,xn)?n[d]=n[d+1]=0:(s=n[d]/e[d],o=n[d+1]/e[d],r=Math.pow(s,2)+Math.pow(o,2),r<=9||(a=3/Math.sqrt(r),n[d]=s*a*e[d],n[d+1]=o*a*e[d])))}(t,s,o),function(t,e,n="x"){const i=wn(n),s=t.length;let o,a,r,c=vn(t,0);for(let l=0;l<s;++l){if(a=r,r=c,c=vn(t,l+1),!r)continue;const s=r[n],d=r[i];a&&(o=(s-a[n])/3,r[`cp1${n}`]=s-o,r[`cp1${i}`]=d-o*e[l]),c&&(o=(c[n]-s)/3,r[`cp2${n}`]=s+o,r[`cp2${i}`]=d+o*e[l])}}(t,o,e)}function Mn(t,e,n){return Math.max(Math.min(t,n),e)}function Cn(t,e,n,i,s){let o,a,r,c;if(e.spanGaps&&(t=t.filter((t=>!t.skip))),"monotone"===e.cubicInterpolationMode)kn(t,s);else{let n=i?t[t.length-1]:t[0];for(o=0,a=t.length;o<a;++o)r=t[o],c=Sn(n,r,t[Math.min(o+1,a-(i?0:1))%a],e.tension),r.cp1x=c.previous.x,r.cp1y=c.previous.y,r.cp2x=c.next.x,r.cp2y=c.next.y,n=r}e.capBezierPoints&&function(t,e){let n,i,s,o,a,r=$e(t[0],e);for(n=0,i=t.length;n<i;++n)a=o,o=r,r=n<i-1&&$e(t[n+1],e),o&&(s=t[n],a&&(s.cp1x=Mn(s.cp1x,e.left,e.right),s.cp1y=Mn(s.cp1y,e.top,e.bottom)),r&&(s.cp2x=Mn(s.cp2x,e.left,e.right),s.cp2y=Mn(s.cp2y,e.top,e.bottom)))}(t,n)}function _n(){return"undefined"!=typeof window&&"undefined"!=typeof document}function Dn(t){let e=t.parentNode;return e&&"[object ShadowRoot]"===e.toString()&&(e=e.host),e}function Tn(t,e,n){let i;return"string"==typeof t?(i=parseInt(t,10),-1!==t.indexOf("%")&&(i=i/100*e.parentNode[n])):i=t,i}const Pn=t=>t.ownerDocument.defaultView.getComputedStyle(t,null);const En=["top","right","bottom","left"];function An(t,e,n){const i={};n=n?"-"+n:"";for(let s=0;s<4;s++){const o=En[s];i[o]=parseFloat(t[e+"-"+o+n])||0}return i.width=i.left+i.right,i.height=i.top+i.bottom,i}function Ln(t,e){if("native"in t)return t;const{canvas:n,currentDevicePixelRatio:i}=e,s=Pn(n),o="border-box"===s.boxSizing,a=An(s,"padding"),r=An(s,"border","width"),{x:c,y:l,box:d}=function(t,e){const n=t.touches,i=n&&n.length?n[0]:t,{offsetX:s,offsetY:o}=i;let a,r,c=!1;if(((t,e,n)=>(t>0||e>0)&&(!n||!n.shadowRoot))(s,o,t.target))a=s,r=o;else{const t=e.getBoundingClientRect();a=i.clientX-t.left,r=i.clientY-t.top,c=!0}return{x:a,y:r,box:c}}(t,n),h=a.left+(d&&r.left),u=a.top+(d&&r.top);let{width:g,height:p}=e;return o&&(g-=a.width+r.width,p-=a.height+r.height),{x:Math.round((c-h)/g*n.width/i),y:Math.round((l-u)/p*n.height/i)}}const In=t=>Math.round(10*t)/10;function On(t,e,n,i){const s=Pn(t),o=An(s,"margin"),a=Tn(s.maxWidth,t,"clientWidth")||zt,r=Tn(s.maxHeight,t,"clientHeight")||zt,c=function(t,e,n){let i,s;if(void 0===e||void 0===n){const o=t&&Dn(t);if(o){const t=o.getBoundingClientRect(),a=Pn(o),r=An(a,"border","width"),c=An(a,"padding");e=t.width-c.width-r.width,n=t.height-c.height-r.height,i=Tn(a.maxWidth,o,"clientWidth"),s=Tn(a.maxHeight,o,"clientHeight")}else e=t.clientWidth,n=t.clientHeight}return{width:e,height:n,maxWidth:i||zt,maxHeight:s||zt}}(t,e,n);let{width:l,height:d}=c;if("content-box"===s.boxSizing){const t=An(s,"border","width"),e=An(s,"padding");l-=e.width+t.width,d-=e.height+t.height}l=Math.max(0,l-o.width),d=Math.max(0,i?l/i:d-o.height),l=In(Math.min(l,a,c.maxWidth)),d=In(Math.min(d,r,c.maxHeight)),l&&!d&&(d=In(l/2));return(void 0!==e||void 0!==n)&&i&&c.height&&d>c.height&&(d=c.height,l=In(Math.floor(d*i))),{width:l,height:d}}function zn(t,e,n){const i=e||1,s=In(t.height*i),o=In(t.width*i);t.height=In(t.height),t.width=In(t.width);const a=t.canvas;return a.style&&(n||!a.style.height&&!a.style.width)&&(a.style.height=`${t.height}px`,a.style.width=`${t.width}px`),(t.currentDevicePixelRatio!==i||a.height!==s||a.width!==o)&&(t.currentDevicePixelRatio=i,a.height=s,a.width=o,t.ctx.setTransform(i,0,0,i,0,0),!0)}const Wn=function(){let t=!1;try{const e={get passive(){return t=!0,!1}};_n()&&(window.addEventListener("test",null,e),window.removeEventListener("test",null,e))}catch(t){}return t}();function Nn(t,e){const n=function(t,e){return Pn(t).getPropertyValue(e)}(t,e),i=n&&n.match(/^(\d+)(\.\d+)?px$/);return i?+i[1]:void 0}function Rn(t,e,n,i){return{x:t.x+n*(e.x-t.x),y:t.y+n*(e.y-t.y)}}function $n(t,e,n,i){return{x:t.x+n*(e.x-t.x),y:"middle"===i?n<.5?t.y:e.y:"after"===i?n<1?t.y:e.y:n>0?e.y:t.y}}function Fn(t,e,n,i){const s={x:t.cp2x,y:t.cp2y},o={x:e.cp1x,y:e.cp1y},a=Rn(t,s,n),r=Rn(s,o,n),c=Rn(o,e,n),l=Rn(a,r,n),d=Rn(r,c,n);return Rn(l,d,n)}function qn(t,e,n){return t?function(t,e){return{x:n=>t+t+e-n,setWidth(t){e=t},textAlign:t=>"center"===t?t:"right"===t?"left":"right",xPlus:(t,e)=>t-e,leftForLtr:(t,e)=>t-e}}(e,n):{x:t=>t,setWidth(t){},textAlign:t=>t,xPlus:(t,e)=>t+e,leftForLtr:(t,e)=>t}}function Bn(t,e){let n,i;"ltr"!==e&&"rtl"!==e||(n=t.canvas.style,i=[n.getPropertyValue("direction"),n.getPropertyPriority("direction")],n.setProperty("direction",e,"important"),t.prevTextDirection=i)}function Hn(t,e){void 0!==e&&(delete t.prevTextDirection,t.canvas.style.setProperty("direction",e[0],e[1]))}function Vn(t){return"angle"===t?{between:Jt,compare:Gt,normalize:Zt}:{between:ee,compare:(t,e)=>t-e,normalize:t=>t}}function jn({start:t,end:e,count:n,loop:i,style:s}){return{start:t%n,end:e%n,loop:i&&(e-t+1)%n==0,style:s}}function Yn(t,e,n){if(!n)return[t];const{property:i,start:s,end:o}=n,a=e.length,{compare:r,between:c,normalize:l}=Vn(i),{start:d,end:h,loop:u,style:g}=function(t,e,n){const{property:i,start:s,end:o}=n,{between:a,normalize:r}=Vn(i),c=e.length;let l,d,{start:h,end:u,loop:g}=t;if(g){for(h+=c,u+=c,l=0,d=c;l<d&&a(r(e[h%c][i]),s,o);++l)h--,u--;h%=c,u%=c}return u<h&&(u+=c),{start:h,end:u,loop:g,style:t.style}}(t,e,n),p=[];let m,f,b,y=!1,x=null;const v=()=>y||c(s,b,m)&&0!==r(s,b),w=()=>!y||0===r(o,m)||c(o,b,m);for(let t=d,n=d;t<=h;++t)f=e[t%a],f.skip||(m=l(f[i]),m!==b&&(y=c(m,s,o),null===x&&v()&&(x=0===r(m,s)?t:n),null!==x&&w()&&(p.push(jn({start:x,end:t,loop:u,count:a,style:g})),x=null),n=t,b=m));return null!==x&&p.push(jn({start:x,end:h,loop:u,count:a,style:g})),p}function Un(t,e){const n=[],i=t.segments;for(let s=0;s<i.length;s++){const o=Yn(i[s],t.points,e);o.length&&n.push(...o)}return n}function Xn(t,e,n,i){return i&&i.setContext&&n?function(t,e,n,i){const s=t._chart.getContext(),o=Qn(t.options),{_datasetIndex:a,options:{spanGaps:r}}=t,c=n.length,l=[];let d=o,h=e[0].start,u=h;function g(t,e,i,s){const o=r?-1:1;if(t!==e){for(t+=c;n[t%c].skip;)t-=o;for(;n[e%c].skip;)e+=o;t%c!==e%c&&(l.push({start:t%c,end:e%c,loop:i,style:s}),d=s,h=e%c)}}for(const t of e){h=r?h:t.start;let e,o=n[h%c];for(u=h+1;u<=t.end;u++){const r=n[u%c];e=Qn(i.setContext(sn(s,{type:"segment",p0:o,p1:r,p0DataIndex:(u-1)%c,p1DataIndex:u%c,datasetIndex:a}))),Kn(e,d)&&g(h,u-1,t.loop,d),o=r,d=e}h<u-1&&g(h,u-1,t.loop,d)}return l}(t,e,n,i):e}function Qn(t){return{backgroundColor:t.backgroundColor,borderCapStyle:t.borderCapStyle,borderDash:t.borderDash,borderDashOffset:t.borderDashOffset,borderJoinStyle:t.borderJoinStyle,borderWidth:t.borderWidth,borderColor:t.borderColor}}function Kn(t,e){if(!e)return!1;const n=[],i=function(t,e){return ye(e)?(n.includes(e)||n.push(e),n.indexOf(e)):e};return JSON.stringify(t,i)!==JSON.stringify(e,i)}function Gn(t,e,n){return t.options.clip?t[n]:e[n]}function Zn(t,e){const n=e._clip;if(n.disabled)return!1;const i=function(t,e){const{xScale:n,yScale:i}=t;return n&&i?{left:Gn(n,e,"left"),right:Gn(n,e,"right"),top:Gn(i,e,"top"),bottom:Gn(i,e,"bottom")}:e}(e,t.chartArea);return{left:!1===n.left?0:i.left-(!0===n.left?0:n.left),right:!1===n.right?t.width:i.right+(!0===n.right?0:n.right),top:!1===n.top?0:i.top-(!0===n.top?0:n.top),bottom:!1===n.bottom?t.height:i.bottom+(!0===n.bottom?0:n.bottom)}}
|
|
15
15
|
/*!
|
|
16
16
|
* Chart.js v4.5.1
|
|
17
17
|
* https://www.chartjs.org
|
|
18
18
|
* (c) 2025 Chart.js Contributors
|
|
19
19
|
* Released under the MIT License
|
|
20
|
-
*/class Jn{constructor(){this._request=null,this._charts=new Map,this._running=!1,this._lastDate=void 0}_notify(t,e,n,i){const s=e.listeners[i],o=e.duration;s.forEach((i=>i({chart:t,initial:e.initial,numSteps:o,currentStep:Math.min(n-e.start,o)})))}_refresh(){this._request||(this._running=!0,this._request=ce.call(window,(()=>{this._update(),this._request=null,this._running&&this._refresh()})))}_update(t=Date.now()){let e=0;this._charts.forEach(((n,i)=>{if(!n.running||!n.items.length)return;const s=n.items;let o,a=s.length-1,r=!1;for(;a>=0;--a)o=s[a],o._active?(o._total>n.duration&&(n.duration=o._total),o.tick(t),r=!0):(s[a]=s[s.length-1],s.pop());r&&(i.draw(),this._notify(i,n,t,"progress")),s.length||(n.running=!1,this._notify(i,n,t,"complete"),n.initial=!1),e+=s.length})),this._lastDate=t,0===e&&(this._running=!1)}_getAnims(t){const e=this._charts;let n=e.get(t);return n||(n={running:!1,initial:!0,items:[],listeners:{complete:[],progress:[]}},e.set(t,n)),n}listen(t,e,n){this._getAnims(t).listeners[e].push(n)}add(t,e){e&&e.length&&this._getAnims(t).items.push(...e)}has(t){return this._getAnims(t).items.length>0}start(t){const e=this._charts.get(t);e&&(e.running=!0,e.start=Date.now(),e.duration=e.items.reduce(((t,e)=>Math.max(t,e._duration)),0),this._refresh())}running(t){if(!this._running)return!1;const e=this._charts.get(t);return!!(e&&e.running&&e.items.length)}stop(t){const e=this._charts.get(t);if(!e||!e.items.length)return;const n=e.items;let i=n.length-1;for(;i>=0;--i)n[i].cancel();e.items=[],this._notify(t,e,Date.now(),"complete")}remove(t){return this._charts.delete(t)}}var ti=new Jn;const ei="transparent",ni={boolean:(t,e,n)=>n>.5?e:t,color(t,e,n){const i=xe(t||ei),s=i.valid&&xe(e||ei);return s&&s.valid?s.mix(i,n).hexString():e},number:(t,e,n)=>t+(e-t)*n};class ii{constructor(t,e,n,i){const s=e[n];i=nn([t.to,i,s,t.from]);const o=nn([t.from,s,i]);this._active=!0,this._fn=t.fn||ni[t.type||typeof o],this._easing=be[t.easing]||be.linear,this._start=Math.floor(Date.now()+(t.delay||0)),this._duration=this._total=Math.floor(t.duration),this._loop=!!t.loop,this._target=e,this._prop=n,this._from=o,this._to=i,this._promises=void 0}active(){return this._active}update(t,e,n){if(this._active){this._notify(!1);const i=this._target[this._prop],s=n-this._start,o=this._duration-s;this._start=n,this._duration=Math.floor(Math.max(o,t.duration)),this._total+=s,this._loop=!!t.loop,this._to=nn([t.to,e,i,t.from]),this._from=nn([t.from,i,e])}}cancel(){this._active&&(this.tick(Date.now()),this._active=!1,this._notify(!1))}tick(t){const e=t-this._start,n=this._duration,i=this._prop,s=this._from,o=this._loop,a=this._to;let r;if(this._active=s!==a&&(o||e<n),!this._active)return this._target[i]=a,void this._notify(!0);e<0?this._target[i]=s:(r=e/n%2,r=o&&r>1?2-r:r,r=this._easing(Math.min(1,Math.max(0,r))),this._target[i]=this._fn(s,a,r))}wait(){const t=this._promises||(this._promises=[]);return new Promise(((e,n)=>{t.push({res:e,rej:n})}))}_notify(t){const e=t?"res":"rej",n=this._promises||[];for(let t=0;t<n.length;t++)n[t][e]()}}class si{constructor(t,e){this._chart=t,this._properties=new Map,this.configure(e)}configure(t){if(!ut(t))return;const e=Object.keys(Le.animation),n=this._properties;Object.getOwnPropertyNames(t).forEach((i=>{const s=t[i];if(!ut(s))return;const o={};for(const t of e)o[t]=s[t];(ht(s.properties)&&s.properties||[i]).forEach((t=>{t!==i&&n.has(t)||n.set(t,o)}))}))}_animateOptions(t,e){const n=e.options,i=function(t,e){if(!e)return;let n=t.options;if(!n)return void(t.options=e);n.$shared&&(t.options=n=Object.assign({},n,{$shared:!1,$animations:{}}));return n}(t,n);if(!i)return[];const s=this._createAnimations(i,n);return n.$shared&&function(t,e){const n=[],i=Object.keys(e);for(let e=0;e<i.length;e++){const s=t[i[e]];s&&s.active()&&n.push(s.wait())}return Promise.all(n)}(t.options.$animations,n).then((()=>{t.options=n}),(()=>{})),s}_createAnimations(t,e){const n=this._properties,i=[],s=t.$animations||(t.$animations={}),o=Object.keys(e),a=Date.now();let r;for(r=o.length-1;r>=0;--r){const c=o[r];if("$"===c.charAt(0))continue;if("options"===c){i.push(...this._animateOptions(t,e));continue}const l=e[c];let d=s[c];const h=n.get(c);if(d){if(h&&d.active()){d.update(h,l,a);continue}d.cancel()}h&&h.duration?(s[c]=d=new ii(h,t,c,l),i.push(d)):t[c]=l}return i}update(t,e){if(0===this._properties.size)return void Object.assign(t,e);const n=this._createAnimations(t,e);return n.length?(ti.add(this._chart,n),!0):void 0}}function oi(t,e){const n=t&&t.options||{},i=n.reverse,s=void 0===n.min?e:0,o=void 0===n.max?e:0;return{start:i?o:s,end:i?s:o}}function ai(t,e){const n=[],i=t._getSortedDatasetMetas(e);let s,o;for(s=0,o=i.length;s<o;++s)n.push(i[s].index);return n}function ri(t,e,n,i={}){const s=t.keys,o="single"===i.mode;let a,r,c,l;if(null===e)return;let d=!1;for(a=0,r=s.length;a<r;++a){if(c=+s[a],c===n){if(d=!0,i.all)continue;break}l=t.values[c],gt(l)&&(o||0===e||qt(e)===qt(l))&&(e+=l)}return d||i.all?e:0}function ci(t,e){const n=t&&t.options.stacked;return n||void 0===n&&void 0!==e.stack}function li(t,e,n){const i=t[e]||(t[e]={});return i[n]||(i[n]={})}function di(t,e,n,i){for(const s of e.getMatchingVisibleMetas(i).reverse()){const e=t[s.index];if(n&&e>0||!n&&e<0)return s.index}return null}function hi(t,e){const{chart:n,_cachedMeta:i}=t,s=n._stacks||(n._stacks={}),{iScale:o,vScale:a,index:r}=i,c=o.axis,l=a.axis,d=function(t,e,n){return`${t.id}.${e.id}.${n.stack||n.type}`}(o,a,i),h=e.length;let u;for(let t=0;t<h;++t){const n=e[t],{[c]:o,[l]:h}=n;u=(n._stacks||(n._stacks={}))[l]=li(s,d,o),u[r]=h,u._top=di(u,a,!0,i.type),u._bottom=di(u,a,!1,i.type);(u._visualValues||(u._visualValues={}))[r]=h}}function ui(t,e){const n=t.scales;return Object.keys(n).filter((t=>n[t].axis===e)).shift()}function gi(t,e){const n=t.controller.index,i=t.vScale&&t.vScale.axis;if(i){e=e||t._parsed;for(const t of e){const e=t._stacks;if(!e||void 0===e[i]||void 0===e[i][n])return;delete e[i][n],void 0!==e[i]._visualValues&&void 0!==e[i]._visualValues[n]&&delete e[i]._visualValues[n]}}}const pi=t=>"reset"===t||"none"===t,mi=(t,e)=>e?t:Object.assign({},t);class fi{static defaults={};static datasetElementType=null;static dataElementType=null;constructor(t,e){this.chart=t,this._ctx=t.ctx,this.index=e,this._cachedDataOpts={},this._cachedMeta=this.getMeta(),this._type=this._cachedMeta.type,this.options=void 0,this._parsing=!1,this._data=void 0,this._objectData=void 0,this._sharedOptions=void 0,this._drawStart=void 0,this._drawCount=void 0,this.enableOptionSharing=!1,this.supportsDecimation=!1,this.$context=void 0,this._syncList=[],this.datasetElementType=new.target.datasetElementType,this.dataElementType=new.target.dataElementType,this.initialize()}initialize(){const t=this._cachedMeta;this.configure(),this.linkScales(),t._stacked=ci(t.vScale,t),this.addElements(),this.options.fill&&!this.chart.isPluginEnabled("filler")&&console.warn("Tried to use the 'fill' option without the 'Filler' plugin enabled. Please import and register the 'Filler' plugin and make sure it is not disabled in the options")}updateIndex(t){this.index!==t&&gi(this._cachedMeta),this.index=t}linkScales(){const t=this.chart,e=this._cachedMeta,n=this.getDataset(),i=(t,e,n,i)=>"x"===t?e:"r"===t?i:n,s=e.xAxisID=mt(n.xAxisID,ui(t,"x")),o=e.yAxisID=mt(n.yAxisID,ui(t,"y")),a=e.rAxisID=mt(n.rAxisID,ui(t,"r")),r=e.indexAxis,c=e.iAxisID=i(r,s,o,a),l=e.vAxisID=i(r,o,s,a);e.xScale=this.getScaleForId(s),e.yScale=this.getScaleForId(o),e.rScale=this.getScaleForId(a),e.iScale=this.getScaleForId(c),e.vScale=this.getScaleForId(l)}getDataset(){return this.chart.data.datasets[this.index]}getMeta(){return this.chart.getDatasetMeta(this.index)}getScaleForId(t){return this.chart.scales[t]}_getOtherScale(t){const e=this._cachedMeta;return t===e.iScale?e.vScale:e.iScale}reset(){this._update("reset")}_destroy(){const t=this._cachedMeta;this._data&&ae(this._data,this),t._stacked&&gi(t)}_dataCheck(){const t=this.getDataset(),e=t.data||(t.data=[]),n=this._data;if(ut(e)){const t=this._cachedMeta;this._data=function(t,e){const{iScale:n,vScale:i}=e,s="x"===n.axis?"x":"y",o="x"===i.axis?"x":"y",a=Object.keys(t),r=new Array(a.length);let c,l,d;for(c=0,l=a.length;c<l;++c)d=a[c],r[c]={[s]:d,[o]:t[d]};return r}(e,t)}else if(n!==e){if(n){ae(n,this);const t=this._cachedMeta;gi(t),t._parsed=[]}e&&Object.isExtensible(e)&&(s=this,(i=e)._chartjs?i._chartjs.listeners.push(s):(Object.defineProperty(i,"_chartjs",{configurable:!0,enumerable:!1,value:{listeners:[s]}}),oe.forEach((t=>{const e="_onData"+Dt(t),n=i[t];Object.defineProperty(i,t,{configurable:!0,enumerable:!1,value(...t){const s=n.apply(this,t);return i._chartjs.listeners.forEach((n=>{"function"==typeof n[e]&&n[e](...t)})),s}})})))),this._syncList=[],this._data=e}var i,s}addElements(){const t=this._cachedMeta;this._dataCheck(),this.datasetElementType&&(t.dataset=new this.datasetElementType)}buildOrUpdateElements(t){const e=this._cachedMeta,n=this.getDataset();let i=!1;this._dataCheck();const s=e._stacked;e._stacked=ci(e.vScale,e),e.stack!==n.stack&&(i=!0,gi(e),e.stack=n.stack),this._resyncElements(t),(i||s!==e._stacked)&&(hi(this,e._parsed),e._stacked=ci(e.vScale,e))}configure(){const t=this.chart.config,e=t.datasetScopeKeys(this._type),n=t.getOptionScopes(this.getDataset(),e,!0);this.options=t.createResolver(n,this.getContext()),this._parsing=this.options.parsing,this._cachedDataOpts={}}parse(t,e){const{_cachedMeta:n,_data:i}=this,{iScale:s,_stacked:o}=n,a=s.axis;let r,c,l,d=0===t&&e===i.length||n._sorted,h=t>0&&n._parsed[t-1];if(!1===this._parsing)n._parsed=i,n._sorted=!0,l=i;else{l=ht(i[t])?this.parseArrayData(n,i,t,e):ut(i[t])?this.parseObjectData(n,i,t,e):this.parsePrimitiveData(n,i,t,e);const s=()=>null===c[a]||h&&c[a]<h[a];for(r=0;r<e;++r)n._parsed[r+t]=c=l[r],d&&(s()&&(d=!1),h=c);n._sorted=d}o&&hi(this,l)}parsePrimitiveData(t,e,n,i){const{iScale:s,vScale:o}=t,a=s.axis,r=o.axis,c=s.getLabels(),l=s===o,d=new Array(i);let h,u,g;for(h=0,u=i;h<u;++h)g=h+n,d[h]={[a]:l||s.parse(c[g],g),[r]:o.parse(e[g],g)};return d}parseArrayData(t,e,n,i){const{xScale:s,yScale:o}=t,a=new Array(i);let r,c,l,d;for(r=0,c=i;r<c;++r)l=r+n,d=e[l],a[r]={x:s.parse(d[0],l),y:o.parse(d[1],l)};return a}parseObjectData(t,e,n,i){const{xScale:s,yScale:o}=t,{xAxisKey:a="x",yAxisKey:r="y"}=this._parsing,c=new Array(i);let l,d,h,u;for(l=0,d=i;l<d;++l)h=l+n,u=e[h],c[l]={x:s.parse(Tt(u,a),h),y:o.parse(Tt(u,r),h)};return c}getParsed(t){return this._cachedMeta._parsed[t]}getDataElement(t){return this._cachedMeta.data[t]}applyStack(t,e,n){const i=this.chart,s=this._cachedMeta,o=e[t.axis];return ri({keys:ai(i,!0),values:e._stacks[t.axis]._visualValues},o,s.index,{mode:n})}updateRangeFromParsed(t,e,n,i){const s=n[e.axis];let o=null===s?NaN:s;const a=i&&n._stacks[e.axis];i&&a&&(i.values=a,o=ri(i,s,this._cachedMeta.index)),t.min=Math.min(t.min,o),t.max=Math.max(t.max,o)}getMinMax(t,e){const n=this._cachedMeta,i=n._parsed,s=n._sorted&&t===n.iScale,o=i.length,a=this._getOtherScale(t),r=((t,e,n)=>t&&!e.hidden&&e._stacked&&{keys:ai(n,!0),values:null})(e,n,this.chart),c={min:Number.POSITIVE_INFINITY,max:Number.NEGATIVE_INFINITY},{min:l,max:d}=function(t){const{min:e,max:n,minDefined:i,maxDefined:s}=t.getUserBounds();return{min:i?e:Number.NEGATIVE_INFINITY,max:s?n:Number.POSITIVE_INFINITY}}(a);let h,u;function g(){u=i[h];const e=u[a.axis];return!gt(u[t.axis])||l>e||d<e}for(h=0;h<o&&(g()||(this.updateRangeFromParsed(c,t,u,r),!s));++h);if(s)for(h=o-1;h>=0;--h)if(!g()){this.updateRangeFromParsed(c,t,u,r);break}return c}getAllParsedValues(t){const e=this._cachedMeta._parsed,n=[];let i,s,o;for(i=0,s=e.length;i<s;++i)o=e[i][t.axis],gt(o)&&n.push(o);return n}getMaxOverflow(){return!1}getLabelAndValue(t){const e=this._cachedMeta,n=e.iScale,i=e.vScale,s=this.getParsed(t);return{label:n?""+n.getLabelForValue(s[n.axis]):"",value:i?""+i.getLabelForValue(s[i.axis]):""}}_update(t){const e=this._cachedMeta;this.update(t||"default"),e._clip=function(t){let e,n,i,s;return ut(t)?(e=t.top,n=t.right,i=t.bottom,s=t.left):e=n=i=s=t,{top:e,right:n,bottom:i,left:s,disabled:!1===t}}(mt(this.options.clip,function(t,e,n){if(!1===n)return!1;const i=oi(t,n),s=oi(e,n);return{top:s.end,right:i.end,bottom:s.start,left:i.start}}(e.xScale,e.yScale,this.getMaxOverflow())))}update(t){}draw(){const t=this._ctx,e=this.chart,n=this._cachedMeta,i=n.data||[],s=e.chartArea,o=[],a=this._drawStart||0,r=this._drawCount||i.length-a,c=this.options.drawActiveElementsOnTop;let l;for(n.dataset&&n.dataset.draw(t,s,a,r),l=a;l<a+r;++l){const e=i[l];e.hidden||(e.active&&c?o.push(e):e.draw(t,s))}for(l=0;l<o.length;++l)o[l].draw(t,s)}getStyle(t,e){const n=e?"active":"default";return void 0===t&&this._cachedMeta.dataset?this.resolveDatasetElementOptions(n):this.resolveDataElementOptions(t||0,n)}getContext(t,e,n){const i=this.getDataset();let s;if(t>=0&&t<this._cachedMeta.data.length){const e=this._cachedMeta.data[t];s=e.$context||(e.$context=function(t,e,n){return sn(t,{active:!1,dataIndex:e,parsed:void 0,raw:void 0,element:n,index:e,mode:"default",type:"data"})}(this.getContext(),t,e)),s.parsed=this.getParsed(t),s.raw=i.data[t],s.index=s.dataIndex=t}else s=this.$context||(this.$context=function(t,e){return sn(t,{active:!1,dataset:void 0,datasetIndex:e,index:e,mode:"default",type:"dataset"})}(this.chart.getContext(),this.index)),s.dataset=i,s.index=s.datasetIndex=this.index;return s.active=!!e,s.mode=n,s}resolveDatasetElementOptions(t){return this._resolveElementOptions(this.datasetElementType.id,t)}resolveDataElementOptions(t,e){return this._resolveElementOptions(this.dataElementType.id,e,t)}_resolveElementOptions(t,e="default",n){const i="active"===e,s=this._cachedDataOpts,o=t+"-"+e,a=s[o],r=this.enableOptionSharing&&Pt(n);if(a)return mi(a,r);const c=this.chart.config,l=c.datasetElementScopeKeys(this._type,t),d=i?[`${t}Hover`,"hover",t,""]:[t,""],h=c.getOptionScopes(this.getDataset(),l),u=Object.keys(Le.elements[t]),g=c.resolveNamedOptions(h,u,(()=>this.getContext(n,i,e)),d);return g.$shared&&(g.$shared=r,s[o]=Object.freeze(mi(g,r))),g}_resolveAnimations(t,e,n){const i=this.chart,s=this._cachedDataOpts,o=`animation-${e}`,a=s[o];if(a)return a;let r;if(!1!==i.options.animation){const i=this.chart.config,s=i.datasetAnimationScopeKeys(this._type,e),o=i.getOptionScopes(this.getDataset(),s);r=i.createResolver(o,this.getContext(t,n,e))}const c=new si(i,r&&r.animations);return r&&r._cacheable&&(s[o]=Object.freeze(c)),c}getSharedOptions(t){if(t.$shared)return this._sharedOptions||(this._sharedOptions=Object.assign({},t))}includeOptions(t,e){return!e||pi(t)||this.chart._animationsDisabled}_getSharedOptions(t,e){const n=this.resolveDataElementOptions(t,e),i=this._sharedOptions,s=this.getSharedOptions(n),o=this.includeOptions(e,s)||s!==i;return this.updateSharedOptions(s,e,n),{sharedOptions:s,includeOptions:o}}updateElement(t,e,n,i){pi(i)?Object.assign(t,n):this._resolveAnimations(e,i).update(t,n)}updateSharedOptions(t,e,n){t&&!pi(e)&&this._resolveAnimations(void 0,e).update(t,n)}_setStyle(t,e,n,i){t.active=i;const s=this.getStyle(e,i);this._resolveAnimations(e,n,i).update(t,{options:!i&&this.getSharedOptions(s)||s})}removeHoverStyle(t,e,n){this._setStyle(t,n,"active",!1)}setHoverStyle(t,e,n){this._setStyle(t,n,"active",!0)}_removeDatasetHoverStyle(){const t=this._cachedMeta.dataset;t&&this._setStyle(t,void 0,"active",!1)}_setDatasetHoverStyle(){const t=this._cachedMeta.dataset;t&&this._setStyle(t,void 0,"active",!0)}_resyncElements(t){const e=this._data,n=this._cachedMeta.data;for(const[t,e,n]of this._syncList)this[t](e,n);this._syncList=[];const i=n.length,s=e.length,o=Math.min(s,i);o&&this.parse(0,o),s>i?this._insertElements(i,s-i,t):s<i&&this._removeElements(s,i-s)}_insertElements(t,e,n=!0){const i=this._cachedMeta,s=i.data,o=t+e;let a;const r=t=>{for(t.length+=e,a=t.length-1;a>=o;a--)t[a]=t[a-e]};for(r(s),a=t;a<o;++a)s[a]=new this.dataElementType;this._parsing&&r(i._parsed),this.parse(t,e),n&&this.updateElements(s,t,e,"reset")}updateElements(t,e,n,i){}_removeElements(t,e){const n=this._cachedMeta;if(this._parsing){const i=n._parsed.splice(t,e);n._stacked&&gi(n,i)}n.data.splice(t,e)}_sync(t){if(this._parsing)this._syncList.push(t);else{const[e,n,i]=t;this[e](n,i)}this.chart._dataChanges.push([this.index,...t])}_onDataPush(){const t=arguments.length;this._sync(["_insertElements",this.getDataset().data.length-t,t])}_onDataPop(){this._sync(["_removeElements",this._cachedMeta.data.length-1,1])}_onDataShift(){this._sync(["_removeElements",0,1])}_onDataSplice(t,e){e&&this._sync(["_removeElements",t,e]);const n=arguments.length-2;n&&this._sync(["_insertElements",t,n])}_onDataUnshift(){this._sync(["_insertElements",0,arguments.length])}}function bi(t){const e=t.iScale,n=function(t,e){if(!t._cache.$bar){const n=t.getMatchingVisibleMetas(e);let i=[];for(let e=0,s=n.length;e<s;e++)i=i.concat(n[e].controller.getAllParsedValues(t));t._cache.$bar=re(i.sort(((t,e)=>t-e)))}return t._cache.$bar}(e,t.type);let i,s,o,a,r=e._length;const c=()=>{32767!==o&&-32768!==o&&(Pt(a)&&(r=Math.min(r,Math.abs(o-a)||r)),a=o)};for(i=0,s=n.length;i<s;++i)o=e.getPixelForValue(n[i]),c();for(a=void 0,i=0,s=e.ticks.length;i<s;++i)o=e.getPixelForTick(i),c();return r}function yi(t,e,n,i){return ht(t)?function(t,e,n,i){const s=n.parse(t[0],i),o=n.parse(t[1],i),a=Math.min(s,o),r=Math.max(s,o);let c=a,l=r;Math.abs(a)>Math.abs(r)&&(c=r,l=a),e[n.axis]=l,e._custom={barStart:c,barEnd:l,start:s,end:o,min:a,max:r}}(t,e,n,i):e[n.axis]=n.parse(t,i),e}function xi(t,e,n,i){const s=t.iScale,o=t.vScale,a=s.getLabels(),r=s===o,c=[];let l,d,h,u;for(l=n,d=n+i;l<d;++l)u=e[l],h={},h[s.axis]=r||s.parse(a[l],l),c.push(yi(u,h,o,l));return c}function vi(t){return t&&void 0!==t.barStart&&void 0!==t.barEnd}function wi(t,e,n,i){let s=e.borderSkipped;const o={};if(!s)return void(t.borderSkipped=o);if(!0===s)return void(t.borderSkipped={top:!0,right:!0,bottom:!0,left:!0});const{start:a,end:r,reverse:c,top:l,bottom:d}=function(t){let e,n,i,s,o;return t.horizontal?(e=t.base>t.x,n="left",i="right"):(e=t.base<t.y,n="bottom",i="top"),e?(s="end",o="start"):(s="start",o="end"),{start:n,end:i,reverse:e,top:s,bottom:o}}(t);"middle"===s&&n&&(t.enableBorderRadius=!0,(n._top||0)===i?s=l:(n._bottom||0)===i?s=d:(o[Si(d,a,r,c)]=!0,s=l)),o[Si(s,a,r,c)]=!0,t.borderSkipped=o}function Si(t,e,n,i){var s,o,a;return i?(a=n,t=ki(t=(s=t)===(o=e)?a:s===a?o:s,n,e)):t=ki(t,e,n),t}function ki(t,e,n){return"start"===t?e:"end"===t?n:t}function Mi(t,{inflateAmount:e},n){t.inflateAmount="auto"===e?1===n?.33:0:e}class _i extends fi{static id="bar";static defaults={datasetElementType:!1,dataElementType:"bar",categoryPercentage:.8,barPercentage:.9,grouped:!0,animations:{numbers:{type:"number",properties:["x","y","base","width","height"]}}};static overrides={scales:{_index_:{type:"category",offset:!0,grid:{offset:!0}},_value_:{type:"linear",beginAtZero:!0}}};parsePrimitiveData(t,e,n,i){return xi(t,e,n,i)}parseArrayData(t,e,n,i){return xi(t,e,n,i)}parseObjectData(t,e,n,i){const{iScale:s,vScale:o}=t,{xAxisKey:a="x",yAxisKey:r="y"}=this._parsing,c="x"===s.axis?a:r,l="x"===o.axis?a:r,d=[];let h,u,g,p;for(h=n,u=n+i;h<u;++h)p=e[h],g={},g[s.axis]=s.parse(Tt(p,c),h),d.push(yi(Tt(p,l),g,o,h));return d}updateRangeFromParsed(t,e,n,i){super.updateRangeFromParsed(t,e,n,i);const s=n._custom;s&&e===this._cachedMeta.vScale&&(t.min=Math.min(t.min,s.min),t.max=Math.max(t.max,s.max))}getMaxOverflow(){return 0}getLabelAndValue(t){const e=this._cachedMeta,{iScale:n,vScale:i}=e,s=this.getParsed(t),o=s._custom,a=vi(o)?"["+o.start+", "+o.end+"]":""+i.getLabelForValue(s[i.axis]);return{label:""+n.getLabelForValue(s[n.axis]),value:a}}initialize(){this.enableOptionSharing=!0,super.initialize();this._cachedMeta.stack=this.getDataset().stack}update(t){const e=this._cachedMeta;this.updateElements(e.data,0,e.data.length,t)}updateElements(t,e,n,i){const s="reset"===i,{index:o,_cachedMeta:{vScale:a}}=this,r=a.getBasePixel(),c=a.isHorizontal(),l=this._getRuler(),{sharedOptions:d,includeOptions:h}=this._getSharedOptions(e,i);for(let u=e;u<e+n;u++){const e=this.getParsed(u),n=s||dt(e[a.axis])?{base:r,head:r}:this._calculateBarValuePixels(u),g=this._calculateBarIndexPixels(u,l),p=(e._stacks||{})[a.axis],m={horizontal:c,base:n.base,enableBorderRadius:!p||vi(e._custom)||o===p._top||o===p._bottom,x:c?n.head:g.center,y:c?g.center:n.head,height:c?g.size:Math.abs(n.size),width:c?Math.abs(n.size):g.size};h&&(m.options=d||this.resolveDataElementOptions(u,t[u].active?"active":i));const f=m.options||t[u].options;wi(m,f,p,o),Mi(m,f,l.ratio),this.updateElement(t[u],u,m,i)}}_getStacks(t,e){const{iScale:n}=this._cachedMeta,i=n.getMatchingVisibleMetas(this._type).filter((t=>t.controller.options.grouped)),s=n.options.stacked,o=[],a=this._cachedMeta.controller.getParsed(e),r=a&&a[n.axis],c=t=>{const e=t._parsed.find((t=>t[n.axis]===r)),i=e&&e[t.vScale.axis];if(dt(i)||isNaN(i))return!0};for(const n of i)if((void 0===e||!c(n))&&((!1===s||-1===o.indexOf(n.stack)||void 0===s&&void 0===n.stack)&&o.push(n.stack),n.index===t))break;return o.length||o.push(void 0),o}_getStackCount(t){return this._getStacks(void 0,t).length}_getAxisCount(){return this._getAxis().length}getFirstScaleIdForIndexAxis(){const t=this.chart.scales,e=this.chart.options.indexAxis;return Object.keys(t).filter((n=>t[n].axis===e)).shift()}_getAxis(){const t={},e=this.getFirstScaleIdForIndexAxis();for(const n of this.chart.data.datasets)t[mt("x"===this.chart.options.indexAxis?n.xAxisID:n.yAxisID,e)]=!0;return Object.keys(t)}_getStackIndex(t,e,n){const i=this._getStacks(t,n),s=void 0!==e?i.indexOf(e):-1;return-1===s?i.length-1:s}_getRuler(){const t=this.options,e=this._cachedMeta,n=e.iScale,i=[];let s,o;for(s=0,o=e.data.length;s<o;++s)i.push(n.getPixelForValue(this.getParsed(s)[n.axis],s));const a=t.barThickness;return{min:a||bi(e),pixels:i,start:n._startPixel,end:n._endPixel,stackCount:this._getStackCount(),scale:n,grouped:t.grouped,ratio:a?1:t.categoryPercentage*t.barPercentage}}_calculateBarValuePixels(t){const{_cachedMeta:{vScale:e,_stacked:n,index:i},options:{base:s,minBarLength:o}}=this,a=s||0,r=this.getParsed(t),c=r._custom,l=vi(c);let d,h,u=r[e.axis],g=0,p=n?this.applyStack(e,r,n):u;p!==u&&(g=p-u,p=u),l&&(u=c.barStart,p=c.barEnd-c.barStart,0!==u&&qt(u)!==qt(c.barEnd)&&(g=0),g+=u);const m=dt(s)||l?g:s;let f=e.getPixelForValue(m);if(d=this.chart.getDataVisibility(t)?e.getPixelForValue(g+p):f,h=d-f,Math.abs(h)<o){h=function(t,e,n){return 0!==t?qt(t):(e.isHorizontal()?1:-1)*(e.min>=n?1:-1)}(h,e,a)*o,u===a&&(f-=h/2);const t=e.getPixelForDecimal(0),s=e.getPixelForDecimal(1),c=Math.min(t,s),g=Math.max(t,s);f=Math.max(Math.min(f,g),c),d=f+h,n&&!l&&(r._stacks[e.axis]._visualValues[i]=e.getValueForPixel(d)-e.getValueForPixel(f))}if(f===e.getPixelForValue(a)){const t=qt(h)*e.getLineWidthForValue(a)/2;f+=t,h-=t}return{size:h,base:f,head:d,center:d+h/2}}_calculateBarIndexPixels(t,e){const n=e.scale,i=this.options,s=i.skipNull,o=mt(i.maxBarThickness,1/0);let a,r;const c=this._getAxisCount();if(e.grouped){const n=s?this._getStackCount(t):e.stackCount,l="flex"===i.barThickness?function(t,e,n,i){const s=e.pixels,o=s[t];let a=t>0?s[t-1]:null,r=t<s.length-1?s[t+1]:null;const c=n.categoryPercentage;null===a&&(a=o-(null===r?e.end-e.start:r-o)),null===r&&(r=o+o-a);const l=o-(o-Math.min(a,r))/2*c;return{chunk:Math.abs(r-a)/2*c/i,ratio:n.barPercentage,start:l}}(t,e,i,n*c):function(t,e,n,i){const s=n.barThickness;let o,a;return dt(s)?(o=e.min*n.categoryPercentage,a=n.barPercentage):(o=s*i,a=1),{chunk:o/i,ratio:a,start:e.pixels[t]-o/2}}(t,e,i,n*c),d="x"===this.chart.options.indexAxis?this.getDataset().xAxisID:this.getDataset().yAxisID,h=this._getAxis().indexOf(mt(d,this.getFirstScaleIdForIndexAxis())),u=this._getStackIndex(this.index,this._cachedMeta.stack,s?t:void 0)+h;a=l.start+l.chunk*u+l.chunk/2,r=Math.min(o,l.chunk*l.ratio)}else a=n.getPixelForValue(this.getParsed(t)[n.axis],t),r=Math.min(o,e.min*e.ratio);return{base:a-r/2,head:a+r/2,center:a,size:r}}draw(){const t=this._cachedMeta,e=t.vScale,n=t.data,i=n.length;let s=0;for(;s<i;++s)null===this.getParsed(s)[e.axis]||n[s].hidden||n[s].draw(this._ctx)}}class Ci extends fi{static id="doughnut";static defaults={datasetElementType:!1,dataElementType:"arc",animation:{animateRotate:!0,animateScale:!1},animations:{numbers:{type:"number",properties:["circumference","endAngle","innerRadius","outerRadius","startAngle","x","y","offset","borderWidth","spacing"]}},cutout:"50%",rotation:0,circumference:360,radius:"100%",spacing:0,indexAxis:"r"};static descriptors={_scriptable:t=>"spacing"!==t,_indexable:t=>"spacing"!==t&&!t.startsWith("borderDash")&&!t.startsWith("hoverBorderDash")};static overrides={aspectRatio:1,plugins:{legend:{labels:{generateLabels(t){const e=t.data,{labels:{pointStyle:n,textAlign:i,color:s,useBorderRadius:o,borderRadius:a}}=t.legend.options;return e.labels.length&&e.datasets.length?e.labels.map(((e,r)=>{const c=t.getDatasetMeta(0).controller.getStyle(r);return{text:e,fillStyle:c.backgroundColor,fontColor:s,hidden:!t.getDataVisibility(r),lineDash:c.borderDash,lineDashOffset:c.borderDashOffset,lineJoin:c.borderJoinStyle,lineWidth:c.borderWidth,strokeStyle:c.borderColor,textAlign:i,pointStyle:n,borderRadius:o&&(a||c.borderRadius),index:r}})):[]}},onClick(t,e,n){n.chart.toggleDataVisibility(e.index),n.chart.update()}}}};constructor(t,e){super(t,e),this.enableOptionSharing=!0,this.innerRadius=void 0,this.outerRadius=void 0,this.offsetX=void 0,this.offsetY=void 0}linkScales(){}parse(t,e){const n=this.getDataset().data,i=this._cachedMeta;if(!1===this._parsing)i._parsed=n;else{let s,o,a=t=>+n[t];if(ut(n[t])){const{key:t="value"}=this._parsing;a=e=>+Tt(n[e],t)}for(s=t,o=t+e;s<o;++s)i._parsed[s]=a(s)}}_getRotation(){return Yt(this.options.rotation-90)}_getCircumference(){return Yt(this.options.circumference)}_getRotationExtents(){let t=It,e=-It;for(let n=0;n<this.chart.data.datasets.length;++n)if(this.chart.isDatasetVisible(n)&&this.chart.getDatasetMeta(n).type===this._type){const i=this.chart.getDatasetMeta(n).controller,s=i._getRotation(),o=i._getCircumference();t=Math.min(t,s),e=Math.max(e,s+o)}return{rotation:t,circumference:e-t}}update(t){const e=this.chart,{chartArea:n}=e,i=this._cachedMeta,s=i.data,o=this.getMaxBorderWidth()+this.getMaxOffset(s)+this.options.spacing,a=Math.max((Math.min(n.width,n.height)-o)/2,0),r=Math.min((c=this.options.cutout,l=a,"string"==typeof c&&c.endsWith("%")?parseFloat(c)/100:+c/l),1);var c,l;const d=this._getRingWeight(this.index),{circumference:h,rotation:u}=this._getRotationExtents(),{ratioX:g,ratioY:p,offsetX:m,offsetY:f}=function(t,e,n){let i=1,s=1,o=0,a=0;if(e<It){const r=t,c=r+e,l=Math.cos(r),d=Math.sin(r),h=Math.cos(c),u=Math.sin(c),g=(t,e,i)=>Jt(t,r,c,!0)?1:Math.max(e,e*n,i,i*n),p=(t,e,i)=>Jt(t,r,c,!0)?-1:Math.min(e,e*n,i,i*n),m=g(0,l,h),f=g(Nt,d,u),b=p(Lt,l,h),y=p(Lt+Nt,d,u);i=(m-b)/2,s=(f-y)/2,o=-(m+b)/2,a=-(f+y)/2}return{ratioX:i,ratioY:s,offsetX:o,offsetY:a}}(u,h,r),b=(n.width-o)/g,y=(n.height-o)/p,x=Math.max(Math.min(b,y)/2,0),v=ft(this.options.radius,x),w=(v-Math.max(v*r,0))/this._getVisibleDatasetWeightTotal();this.offsetX=m*v,this.offsetY=f*v,i.total=this.calculateTotal(),this.outerRadius=v-w*this._getRingWeightOffset(this.index),this.innerRadius=Math.max(this.outerRadius-w*d,0),this.updateElements(s,0,s.length,t)}_circumference(t,e){const n=this.options,i=this._cachedMeta,s=this._getCircumference();return e&&n.animation.animateRotate||!this.chart.getDataVisibility(t)||null===i._parsed[t]||i.data[t].hidden?0:this.calculateCircumference(i._parsed[t]*s/It)}updateElements(t,e,n,i){const s="reset"===i,o=this.chart,a=o.chartArea,r=o.options.animation,c=(a.left+a.right)/2,l=(a.top+a.bottom)/2,d=s&&r.animateScale,h=d?0:this.innerRadius,u=d?0:this.outerRadius,{sharedOptions:g,includeOptions:p}=this._getSharedOptions(e,i);let m,f=this._getRotation();for(m=0;m<e;++m)f+=this._circumference(m,s);for(m=e;m<e+n;++m){const e=this._circumference(m,s),n=t[m],o={x:c+this.offsetX,y:l+this.offsetY,startAngle:f,endAngle:f+e,circumference:e,outerRadius:u,innerRadius:h};p&&(o.options=g||this.resolveDataElementOptions(m,n.active?"active":i)),f+=e,this.updateElement(n,m,o,i)}}calculateTotal(){const t=this._cachedMeta,e=t.data;let n,i=0;for(n=0;n<e.length;n++){const s=t._parsed[n];null===s||isNaN(s)||!this.chart.getDataVisibility(n)||e[n].hidden||(i+=Math.abs(s))}return i}calculateCircumference(t){const e=this._cachedMeta.total;return e>0&&!isNaN(t)?It*(Math.abs(t)/e):0}getLabelAndValue(t){const e=this._cachedMeta,n=this.chart,i=n.data.labels||[],s=Me(e._parsed[t],n.options.locale);return{label:i[t]||"",value:s}}getMaxBorderWidth(t){let e=0;const n=this.chart;let i,s,o,a,r;if(!t)for(i=0,s=n.data.datasets.length;i<s;++i)if(n.isDatasetVisible(i)){o=n.getDatasetMeta(i),t=o.data,a=o.controller;break}if(!t)return 0;for(i=0,s=t.length;i<s;++i)r=a.resolveDataElementOptions(i),"inner"!==r.borderAlign&&(e=Math.max(e,r.borderWidth||0,r.hoverBorderWidth||0));return e}getMaxOffset(t){let e=0;for(let n=0,i=t.length;n<i;++n){const t=this.resolveDataElementOptions(n);e=Math.max(e,t.offset||0,t.hoverOffset||0)}return e}_getRingWeightOffset(t){let e=0;for(let n=0;n<t;++n)this.chart.isDatasetVisible(n)&&(e+=this._getRingWeight(n));return e}_getRingWeight(t){return Math.max(mt(this.chart.data.datasets[t].weight,1),0)}_getVisibleDatasetWeightTotal(){return this._getRingWeightOffset(this.chart.data.datasets.length)||1}}class Ti extends fi{static id="polarArea";static defaults={dataElementType:"arc",animation:{animateRotate:!0,animateScale:!0},animations:{numbers:{type:"number",properties:["x","y","startAngle","endAngle","innerRadius","outerRadius"]}},indexAxis:"r",startAngle:0};static overrides={aspectRatio:1,plugins:{legend:{labels:{generateLabels(t){const e=t.data;if(e.labels.length&&e.datasets.length){const{labels:{pointStyle:n,color:i}}=t.legend.options;return e.labels.map(((e,s)=>{const o=t.getDatasetMeta(0).controller.getStyle(s);return{text:e,fillStyle:o.backgroundColor,strokeStyle:o.borderColor,fontColor:i,lineWidth:o.borderWidth,pointStyle:n,hidden:!t.getDataVisibility(s),index:s}}))}return[]}},onClick(t,e,n){n.chart.toggleDataVisibility(e.index),n.chart.update()}}},scales:{r:{type:"radialLinear",angleLines:{display:!1},beginAtZero:!0,grid:{circular:!0},pointLabels:{display:!1},startAngle:0}}};constructor(t,e){super(t,e),this.innerRadius=void 0,this.outerRadius=void 0}getLabelAndValue(t){const e=this._cachedMeta,n=this.chart,i=n.data.labels||[],s=Me(e._parsed[t].r,n.options.locale);return{label:i[t]||"",value:s}}parseObjectData(t,e,n,i){return yn.bind(this)(t,e,n,i)}update(t){const e=this._cachedMeta.data;this._updateRadius(),this.updateElements(e,0,e.length,t)}getMinMax(){const t=this._cachedMeta,e={min:Number.POSITIVE_INFINITY,max:Number.NEGATIVE_INFINITY};return t.data.forEach(((t,n)=>{const i=this.getParsed(n).r;!isNaN(i)&&this.chart.getDataVisibility(n)&&(i<e.min&&(e.min=i),i>e.max&&(e.max=i))})),e}_updateRadius(){const t=this.chart,e=t.chartArea,n=t.options,i=Math.min(e.right-e.left,e.bottom-e.top),s=Math.max(i/2,0),o=(s-Math.max(n.cutoutPercentage?s/100*n.cutoutPercentage:1,0))/t.getVisibleDatasetCount();this.outerRadius=s-o*this.index,this.innerRadius=this.outerRadius-o}updateElements(t,e,n,i){const s="reset"===i,o=this.chart,a=o.options.animation,r=this._cachedMeta.rScale,c=r.xCenter,l=r.yCenter,d=r.getIndexAngle(0)-.5*Lt;let h,u=d;const g=360/this.countVisibleElements();for(h=0;h<e;++h)u+=this._computeAngle(h,i,g);for(h=e;h<e+n;h++){const e=t[h];let n=u,p=u+this._computeAngle(h,i,g),m=o.getDataVisibility(h)?r.getDistanceFromCenterForValue(this.getParsed(h).r):0;u=p,s&&(a.animateScale&&(m=0),a.animateRotate&&(n=p=d));const f={x:c,y:l,innerRadius:0,outerRadius:m,startAngle:n,endAngle:p,options:this.resolveDataElementOptions(h,e.active?"active":i)};this.updateElement(e,h,f,i)}}countVisibleElements(){const t=this._cachedMeta;let e=0;return t.data.forEach(((t,n)=>{!isNaN(this.getParsed(n).r)&&this.chart.getDataVisibility(n)&&e++})),e}_computeAngle(t,e,n){return this.chart.getDataVisibility(t)?Yt(this.resolveDataElementOptions(t,e).angle||n):0}}var Di=Object.freeze({__proto__:null,BarController:_i,BubbleController:class extends fi{static id="bubble";static defaults={datasetElementType:!1,dataElementType:"point",animations:{numbers:{type:"number",properties:["x","y","borderWidth","radius"]}}};static overrides={scales:{x:{type:"linear"},y:{type:"linear"}}};initialize(){this.enableOptionSharing=!0,super.initialize()}parsePrimitiveData(t,e,n,i){const s=super.parsePrimitiveData(t,e,n,i);for(let t=0;t<s.length;t++)s[t]._custom=this.resolveDataElementOptions(t+n).radius;return s}parseArrayData(t,e,n,i){const s=super.parseArrayData(t,e,n,i);for(let t=0;t<s.length;t++){const i=e[n+t];s[t]._custom=mt(i[2],this.resolveDataElementOptions(t+n).radius)}return s}parseObjectData(t,e,n,i){const s=super.parseObjectData(t,e,n,i);for(let t=0;t<s.length;t++){const i=e[n+t];s[t]._custom=mt(i&&i.r&&+i.r,this.resolveDataElementOptions(t+n).radius)}return s}getMaxOverflow(){const t=this._cachedMeta.data;let e=0;for(let n=t.length-1;n>=0;--n)e=Math.max(e,t[n].size(this.resolveDataElementOptions(n))/2);return e>0&&e}getLabelAndValue(t){const e=this._cachedMeta,n=this.chart.data.labels||[],{xScale:i,yScale:s}=e,o=this.getParsed(t),a=i.getLabelForValue(o.x),r=s.getLabelForValue(o.y),c=o._custom;return{label:n[t]||"",value:"("+a+", "+r+(c?", "+c:"")+")"}}update(t){const e=this._cachedMeta.data;this.updateElements(e,0,e.length,t)}updateElements(t,e,n,i){const s="reset"===i,{iScale:o,vScale:a}=this._cachedMeta,{sharedOptions:r,includeOptions:c}=this._getSharedOptions(e,i),l=o.axis,d=a.axis;for(let h=e;h<e+n;h++){const e=t[h],n=!s&&this.getParsed(h),u={},g=u[l]=s?o.getPixelForDecimal(.5):o.getPixelForValue(n[l]),p=u[d]=s?a.getBasePixel():a.getPixelForValue(n[d]);u.skip=isNaN(g)||isNaN(p),c&&(u.options=r||this.resolveDataElementOptions(h,e.active?"active":i),s&&(u.options.radius=0)),this.updateElement(e,h,u,i)}}resolveDataElementOptions(t,e){const n=this.getParsed(t);let i=super.resolveDataElementOptions(t,e);i.$shared&&(i=Object.assign({},i,{$shared:!1}));const s=i.radius;return"active"!==e&&(i.radius=0),i.radius+=mt(n&&n._custom,s),i}},DoughnutController:Ci,LineController:class extends fi{static id="line";static defaults={datasetElementType:"line",dataElementType:"point",showLine:!0,spanGaps:!1};static overrides={scales:{_index_:{type:"category"},_value_:{type:"linear"}}};initialize(){this.enableOptionSharing=!0,this.supportsDecimation=!0,super.initialize()}update(t){const e=this._cachedMeta,{dataset:n,data:i=[],_dataset:s}=e,o=this.chart._animationsDisabled;let{start:a,count:r}=ue(e,i,o);this._drawStart=a,this._drawCount=r,ge(e)&&(a=0,r=i.length),n._chart=this.chart,n._datasetIndex=this.index,n._decimated=!!s._decimated,n.points=i;const c=this.resolveDatasetElementOptions(t);this.options.showLine||(c.borderWidth=0),c.segment=this.options.segment,this.updateElement(n,void 0,{animated:!o,options:c},t),this.updateElements(i,a,r,t)}updateElements(t,e,n,i){const s="reset"===i,{iScale:o,vScale:a,_stacked:r,_dataset:c}=this._cachedMeta,{sharedOptions:l,includeOptions:d}=this._getSharedOptions(e,i),h=o.axis,u=a.axis,{spanGaps:g,segment:p}=this.options,m=Vt(g)?g:Number.POSITIVE_INFINITY,f=this.chart._animationsDisabled||s||"none"===i,b=e+n,y=t.length;let x=e>0&&this.getParsed(e-1);for(let n=0;n<y;++n){const g=t[n],y=f?g:{};if(n<e||n>=b){y.skip=!0;continue}const v=this.getParsed(n),w=dt(v[u]),S=y[h]=o.getPixelForValue(v[h],n),k=y[u]=s||w?a.getBasePixel():a.getPixelForValue(r?this.applyStack(a,v,r):v[u],n);y.skip=isNaN(S)||isNaN(k)||w,y.stop=n>0&&Math.abs(v[h]-x[h])>m,p&&(y.parsed=v,y.raw=c.data[n]),d&&(y.options=l||this.resolveDataElementOptions(n,g.active?"active":i)),f||this.updateElement(g,n,y,i),x=v}}getMaxOverflow(){const t=this._cachedMeta,e=t.dataset,n=e.options&&e.options.borderWidth||0,i=t.data||[];if(!i.length)return n;const s=i[0].size(this.resolveDataElementOptions(0)),o=i[i.length-1].size(this.resolveDataElementOptions(i.length-1));return Math.max(n,s,o)/2}draw(){const t=this._cachedMeta;t.dataset.updateControlPoints(this.chart.chartArea,t.iScale.axis),super.draw()}},PieController:class extends Ci{static id="pie";static defaults={cutout:0,rotation:0,circumference:360,radius:"100%"}},PolarAreaController:Ti,RadarController:class extends fi{static id="radar";static defaults={datasetElementType:"line",dataElementType:"point",indexAxis:"r",showLine:!0,elements:{line:{fill:"start"}}};static overrides={aspectRatio:1,scales:{r:{type:"radialLinear"}}};getLabelAndValue(t){const e=this._cachedMeta.vScale,n=this.getParsed(t);return{label:e.getLabels()[t],value:""+e.getLabelForValue(n[e.axis])}}parseObjectData(t,e,n,i){return yn.bind(this)(t,e,n,i)}update(t){const e=this._cachedMeta,n=e.dataset,i=e.data||[],s=e.iScale.getLabels();if(n.points=i,"resize"!==t){const e=this.resolveDatasetElementOptions(t);this.options.showLine||(e.borderWidth=0);const o={_loop:!0,_fullLoop:s.length===i.length,options:e};this.updateElement(n,void 0,o,t)}this.updateElements(i,0,i.length,t)}updateElements(t,e,n,i){const s=this._cachedMeta.rScale,o="reset"===i;for(let a=e;a<e+n;a++){const e=t[a],n=this.resolveDataElementOptions(a,e.active?"active":i),r=s.getPointPositionForValue(a,this.getParsed(a).r),c=o?s.xCenter:r.x,l=o?s.yCenter:r.y,d={x:c,y:l,angle:r.angle,skip:isNaN(c)||isNaN(l),options:n};this.updateElement(e,a,d,i)}}},ScatterController:class extends fi{static id="scatter";static defaults={datasetElementType:!1,dataElementType:"point",showLine:!1,fill:!1};static overrides={interaction:{mode:"point"},scales:{x:{type:"linear"},y:{type:"linear"}}};getLabelAndValue(t){const e=this._cachedMeta,n=this.chart.data.labels||[],{xScale:i,yScale:s}=e,o=this.getParsed(t),a=i.getLabelForValue(o.x),r=s.getLabelForValue(o.y);return{label:n[t]||"",value:"("+a+", "+r+")"}}update(t){const e=this._cachedMeta,{data:n=[]}=e,i=this.chart._animationsDisabled;let{start:s,count:o}=ue(e,n,i);if(this._drawStart=s,this._drawCount=o,ge(e)&&(s=0,o=n.length),this.options.showLine){this.datasetElementType||this.addElements();const{dataset:s,_dataset:o}=e;s._chart=this.chart,s._datasetIndex=this.index,s._decimated=!!o._decimated,s.points=n;const a=this.resolveDatasetElementOptions(t);a.segment=this.options.segment,this.updateElement(s,void 0,{animated:!i,options:a},t)}else this.datasetElementType&&(delete e.dataset,this.datasetElementType=!1);this.updateElements(n,s,o,t)}addElements(){const{showLine:t}=this.options;!this.datasetElementType&&t&&(this.datasetElementType=this.chart.registry.getElement("line")),super.addElements()}updateElements(t,e,n,i){const s="reset"===i,{iScale:o,vScale:a,_stacked:r,_dataset:c}=this._cachedMeta,l=this.resolveDataElementOptions(e,i),d=this.getSharedOptions(l),h=this.includeOptions(i,d),u=o.axis,g=a.axis,{spanGaps:p,segment:m}=this.options,f=Vt(p)?p:Number.POSITIVE_INFINITY,b=this.chart._animationsDisabled||s||"none"===i;let y=e>0&&this.getParsed(e-1);for(let l=e;l<e+n;++l){const e=t[l],n=this.getParsed(l),p=b?e:{},x=dt(n[g]),v=p[u]=o.getPixelForValue(n[u],l),w=p[g]=s||x?a.getBasePixel():a.getPixelForValue(r?this.applyStack(a,n,r):n[g],l);p.skip=isNaN(v)||isNaN(w)||x,p.stop=l>0&&Math.abs(n[u]-y[u])>f,m&&(p.parsed=n,p.raw=c.data[l]),h&&(p.options=d||this.resolveDataElementOptions(l,e.active?"active":i)),b||this.updateElement(e,l,p,i),y=n}this.updateSharedOptions(d,i,l)}getMaxOverflow(){const t=this._cachedMeta,e=t.data||[];if(!this.options.showLine){let t=0;for(let n=e.length-1;n>=0;--n)t=Math.max(t,e[n].size(this.resolveDataElementOptions(n))/2);return t>0&&t}const n=t.dataset,i=n.options&&n.options.borderWidth||0;if(!e.length)return i;const s=e[0].size(this.resolveDataElementOptions(0)),o=e[e.length-1].size(this.resolveDataElementOptions(e.length-1));return Math.max(i,s,o)/2}}});function Pi(){throw new Error("This method is not implemented: Check that a complete date adapter is provided.")}class Ei{static override(t){Object.assign(Ei.prototype,t)}options;constructor(t){this.options=t||{}}init(){}formats(){return Pi()}parse(){return Pi()}format(){return Pi()}add(){return Pi()}diff(){return Pi()}startOf(){return Pi()}endOf(){return Pi()}}var Ai={_date:Ei};function Li(t,e,n,i){const{controller:s,data:o,_sorted:a}=t,r=s._cachedMeta.iScale,c=t.dataset&&t.dataset.options?t.dataset.options.spanGaps:null;if(r&&e===r.axis&&"r"!==e&&a&&o.length){const a=r._reversePixels?se:ie;if(!i){const i=a(o,e,n);if(c){const{vScale:e}=s._cachedMeta,{_parsed:n}=t,o=n.slice(0,i.lo+1).reverse().findIndex((t=>!dt(t[e.axis])));i.lo-=Math.max(0,o);const a=n.slice(i.hi).findIndex((t=>!dt(t[e.axis])));i.hi+=Math.max(0,a)}return i}if(s._sharedOptions){const t=o[0],i="function"==typeof t.getRange&&t.getRange(e);if(i){const t=a(o,e,n-i),s=a(o,e,n+i);return{lo:t.lo,hi:s.hi}}}}return{lo:0,hi:o.length-1}}function Ii(t,e,n,i,s){const o=t.getSortedVisibleDatasetMetas(),a=n[e];for(let t=0,n=o.length;t<n;++t){const{index:n,data:r}=o[t],{lo:c,hi:l}=Li(o[t],e,a,s);for(let t=c;t<=l;++t){const e=r[t];e.skip||i(e,n,t)}}}function Oi(t,e,n,i,s){const o=[];if(!s&&!t.isPointInArea(e))return o;return Ii(t,n,e,(function(n,a,r){(s||$e(n,t.chartArea,0))&&n.inRange(e.x,e.y,i)&&o.push({element:n,datasetIndex:a,index:r})}),!0),o}function zi(t,e,n,i,s,o){let a=[];const r=function(t){const e=-1!==t.indexOf("x"),n=-1!==t.indexOf("y");return function(t,i){const s=e?Math.abs(t.x-i.x):0,o=n?Math.abs(t.y-i.y):0;return Math.sqrt(Math.pow(s,2)+Math.pow(o,2))}}(n);let c=Number.POSITIVE_INFINITY;return Ii(t,n,e,(function(n,l,d){const h=n.inRange(e.x,e.y,s);if(i&&!h)return;const u=n.getCenterPoint(s);if(!(!!o||t.isPointInArea(u))&&!h)return;const g=r(e,u);g<c?(a=[{element:n,datasetIndex:l,index:d}],c=g):g===c&&a.push({element:n,datasetIndex:l,index:d})})),a}function Wi(t,e,n,i,s,o){return o||t.isPointInArea(e)?"r"!==n||i?zi(t,e,n,i,s,o):function(t,e,n,i){let s=[];return Ii(t,n,e,(function(t,n,o){const{startAngle:a,endAngle:r}=t.getProps(["startAngle","endAngle"],i),{angle:c}=Qt(t,{x:e.x,y:e.y});Jt(c,a,r)&&s.push({element:t,datasetIndex:n,index:o})})),s}(t,e,n,s):[]}function Ni(t,e,n,i,s){const o=[],a="x"===n?"inXRange":"inYRange";let r=!1;return Ii(t,n,e,((t,i,c)=>{t[a]&&t[a](e[n],s)&&(o.push({element:t,datasetIndex:i,index:c}),r=r||t.inRange(e.x,e.y,s))})),i&&!r?[]:o}var Ri={evaluateInteractionItems:Ii,modes:{index(t,e,n,i){const s=Ln(e,t),o=n.axis||"x",a=n.includeInvisible||!1,r=n.intersect?Oi(t,s,o,i,a):Wi(t,s,o,!1,i,a),c=[];return r.length?(t.getSortedVisibleDatasetMetas().forEach((t=>{const e=r[0].index,n=t.data[e];n&&!n.skip&&c.push({element:n,datasetIndex:t.index,index:e})})),c):[]},dataset(t,e,n,i){const s=Ln(e,t),o=n.axis||"xy",a=n.includeInvisible||!1;let r=n.intersect?Oi(t,s,o,i,a):Wi(t,s,o,!1,i,a);if(r.length>0){const e=r[0].datasetIndex,n=t.getDatasetMeta(e).data;r=[];for(let t=0;t<n.length;++t)r.push({element:n[t],datasetIndex:e,index:t})}return r},point:(t,e,n,i)=>Oi(t,Ln(e,t),n.axis||"xy",i,n.includeInvisible||!1),nearest(t,e,n,i){const s=Ln(e,t),o=n.axis||"xy",a=n.includeInvisible||!1;return Wi(t,s,o,n.intersect,i,a)},x:(t,e,n,i)=>Ni(t,Ln(e,t),"x",n.intersect,i),y:(t,e,n,i)=>Ni(t,Ln(e,t),"y",n.intersect,i)}};const $i=["left","top","right","bottom"];function Fi(t,e){return t.filter((t=>t.pos===e))}function qi(t,e){return t.filter((t=>-1===$i.indexOf(t.pos)&&t.box.axis===e))}function Bi(t,e){return t.sort(((t,n)=>{const i=e?n:t,s=e?t:n;return i.weight===s.weight?i.index-s.index:i.weight-s.weight}))}function Hi(t,e){const n=function(t){const e={};for(const n of t){const{stack:t,pos:i,stackWeight:s}=n;if(!t||!$i.includes(i))continue;const o=e[t]||(e[t]={count:0,placed:0,weight:0,size:0});o.count++,o.weight+=s}return e}(t),{vBoxMaxWidth:i,hBoxMaxHeight:s}=e;let o,a,r;for(o=0,a=t.length;o<a;++o){r=t[o];const{fullSize:a}=r.box,c=n[r.stack],l=c&&r.stackWeight/c.weight;r.horizontal?(r.width=l?l*i:a&&e.availableWidth,r.height=s):(r.width=i,r.height=l?l*s:a&&e.availableHeight)}return n}function Vi(t,e,n,i){return Math.max(t[n],e[n])+Math.max(t[i],e[i])}function ji(t,e){t.top=Math.max(t.top,e.top),t.left=Math.max(t.left,e.left),t.bottom=Math.max(t.bottom,e.bottom),t.right=Math.max(t.right,e.right)}function Yi(t,e,n,i){const{pos:s,box:o}=n,a=t.maxPadding;if(!ut(s)){n.size&&(t[s]-=n.size);const e=i[n.stack]||{size:0,count:1};e.size=Math.max(e.size,n.horizontal?o.height:o.width),n.size=e.size/e.count,t[s]+=n.size}o.getPadding&&ji(a,o.getPadding());const r=Math.max(0,e.outerWidth-Vi(a,t,"left","right")),c=Math.max(0,e.outerHeight-Vi(a,t,"top","bottom")),l=r!==t.w,d=c!==t.h;return t.w=r,t.h=c,n.horizontal?{same:l,other:d}:{same:d,other:l}}function Ui(t,e){const n=e.maxPadding;function i(t){const i={left:0,top:0,right:0,bottom:0};return t.forEach((t=>{i[t]=Math.max(e[t],n[t])})),i}return i(t?["left","right"]:["top","bottom"])}function Xi(t,e,n,i){const s=[];let o,a,r,c,l,d;for(o=0,a=t.length,l=0;o<a;++o){r=t[o],c=r.box,c.update(r.width||e.w,r.height||e.h,Ui(r.horizontal,e));const{same:a,other:h}=Yi(e,n,r,i);l|=a&&s.length,d=d||h,c.fullSize||s.push(r)}return l&&Xi(s,e,n,i)||d}function Qi(t,e,n,i,s){t.top=n,t.left=e,t.right=e+i,t.bottom=n+s,t.width=i,t.height=s}function Ki(t,e,n,i){const s=n.padding;let{x:o,y:a}=e;for(const r of t){const t=r.box,c=i[r.stack]||{count:1,placed:0,weight:1},l=r.stackWeight/c.weight||1;if(r.horizontal){const i=e.w*l,o=c.size||t.height;Pt(c.start)&&(a=c.start),t.fullSize?Qi(t,s.left,a,n.outerWidth-s.right-s.left,o):Qi(t,e.left+c.placed,a,i,o),c.start=a,c.placed+=i,a=t.bottom}else{const i=e.h*l,a=c.size||t.width;Pt(c.start)&&(o=c.start),t.fullSize?Qi(t,o,s.top,a,n.outerHeight-s.bottom-s.top):Qi(t,o,e.top+c.placed,a,i),c.start=o,c.placed+=i,o=t.right}}e.x=o,e.y=a}var Zi={addBox(t,e){t.boxes||(t.boxes=[]),e.fullSize=e.fullSize||!1,e.position=e.position||"top",e.weight=e.weight||0,e._layers=e._layers||function(){return[{z:0,draw(t){e.draw(t)}}]},t.boxes.push(e)},removeBox(t,e){const n=t.boxes?t.boxes.indexOf(e):-1;-1!==n&&t.boxes.splice(n,1)},configure(t,e,n){e.fullSize=n.fullSize,e.position=n.position,e.weight=n.weight},update(t,e,n,i){if(!t)return;const s=tn(t.options.layout.padding),o=Math.max(e-s.width,0),a=Math.max(n-s.height,0),r=function(t){const e=function(t){const e=[];let n,i,s,o,a,r;for(n=0,i=(t||[]).length;n<i;++n)s=t[n],({position:o,options:{stack:a,stackWeight:r=1}}=s),e.push({index:n,box:s,pos:o,horizontal:s.isHorizontal(),weight:s.weight,stack:a&&o+a,stackWeight:r});return e}(t),n=Bi(e.filter((t=>t.box.fullSize)),!0),i=Bi(Fi(e,"left"),!0),s=Bi(Fi(e,"right")),o=Bi(Fi(e,"top"),!0),a=Bi(Fi(e,"bottom")),r=qi(e,"x"),c=qi(e,"y");return{fullSize:n,leftAndTop:i.concat(o),rightAndBottom:s.concat(c).concat(a).concat(r),chartArea:Fi(e,"chartArea"),vertical:i.concat(s).concat(c),horizontal:o.concat(a).concat(r)}}(t.boxes),c=r.vertical,l=r.horizontal;yt(t.boxes,(t=>{"function"==typeof t.beforeLayout&&t.beforeLayout()}));const d=c.reduce(((t,e)=>e.box.options&&!1===e.box.options.display?t:t+1),0)||1,h=Object.freeze({outerWidth:e,outerHeight:n,padding:s,availableWidth:o,availableHeight:a,vBoxMaxWidth:o/2/d,hBoxMaxHeight:a/2}),u=Object.assign({},s);ji(u,tn(i));const g=Object.assign({maxPadding:u,w:o,h:a,x:s.left,y:s.top},s),p=Hi(c.concat(l),h);Xi(r.fullSize,g,h,p),Xi(c,g,h,p),Xi(l,g,h,p)&&Xi(c,g,h,p),function(t){const e=t.maxPadding;function n(n){const i=Math.max(e[n]-t[n],0);return t[n]+=i,i}t.y+=n("top"),t.x+=n("left"),n("right"),n("bottom")}(g),Ki(r.leftAndTop,g,h,p),g.x+=g.w,g.y+=g.h,Ki(r.rightAndBottom,g,h,p),t.chartArea={left:g.left,top:g.top,right:g.left+g.w,bottom:g.top+g.h,height:g.h,width:g.w},yt(r.chartArea,(e=>{const n=e.box;Object.assign(n,t.chartArea),n.update(g.w,g.h,{left:0,top:0,right:0,bottom:0})}))}};class Gi{acquireContext(t,e){}releaseContext(t){return!1}addEventListener(t,e,n){}removeEventListener(t,e,n){}getDevicePixelRatio(){return 1}getMaximumSize(t,e,n,i){return e=Math.max(0,e||t.width),n=n||t.height,{width:e,height:Math.max(0,i?Math.floor(e/i):n)}}isAttached(t){return!0}updateConfig(t){}}class Ji extends Gi{acquireContext(t){return t&&t.getContext&&t.getContext("2d")||null}updateConfig(t){t.options.animation=!1}}const ts="$chartjs",es={touchstart:"mousedown",touchmove:"mousemove",touchend:"mouseup",pointerenter:"mouseenter",pointerdown:"mousedown",pointermove:"mousemove",pointerup:"mouseup",pointerleave:"mouseout",pointerout:"mouseout"},ns=t=>null===t||""===t;const is=!!Wn&&{passive:!0};function ss(t,e,n){t&&t.canvas&&t.canvas.removeEventListener(e,n,is)}function os(t,e){for(const n of t)if(n===e||n.contains(e))return!0}function as(t,e,n){const i=t.canvas,s=new MutationObserver((t=>{let e=!1;for(const n of t)e=e||os(n.addedNodes,i),e=e&&!os(n.removedNodes,i);e&&n()}));return s.observe(document,{childList:!0,subtree:!0}),s}function rs(t,e,n){const i=t.canvas,s=new MutationObserver((t=>{let e=!1;for(const n of t)e=e||os(n.removedNodes,i),e=e&&!os(n.addedNodes,i);e&&n()}));return s.observe(document,{childList:!0,subtree:!0}),s}const cs=new Map;let ls=0;function ds(){const t=window.devicePixelRatio;t!==ls&&(ls=t,cs.forEach(((e,n)=>{n.currentDevicePixelRatio!==t&&e()})))}function hs(t,e,n){const i=t.canvas,s=i&&Tn(i);if(!s)return;const o=le(((t,e)=>{const i=s.clientWidth;n(t,e),i<s.clientWidth&&n()}),window),a=new ResizeObserver((t=>{const e=t[0],n=e.contentRect.width,i=e.contentRect.height;0===n&&0===i||o(n,i)}));return a.observe(s),function(t,e){cs.size||window.addEventListener("resize",ds),cs.set(t,e)}(t,o),a}function us(t,e,n){n&&n.disconnect(),"resize"===e&&function(t){cs.delete(t),cs.size||window.removeEventListener("resize",ds)}(t)}function gs(t,e,n){const i=t.canvas,s=le((e=>{null!==t.ctx&&n(function(t,e){const n=es[t.type]||t.type,{x:i,y:s}=Ln(t,e);return{type:n,chart:e,native:t,x:void 0!==i?i:null,y:void 0!==s?s:null}}(e,t))}),t);return function(t,e,n){t&&t.addEventListener(e,n,is)}(i,e,s),s}class ps extends Gi{acquireContext(t,e){const n=t&&t.getContext&&t.getContext("2d");return n&&n.canvas===t?(function(t,e){const n=t.style,i=t.getAttribute("height"),s=t.getAttribute("width");if(t[ts]={initial:{height:i,width:s,style:{display:n.display,height:n.height,width:n.width}}},n.display=n.display||"block",n.boxSizing=n.boxSizing||"border-box",ns(s)){const e=Nn(t,"width");void 0!==e&&(t.width=e)}if(ns(i))if(""===t.style.height)t.height=t.width/(e||2);else{const e=Nn(t,"height");void 0!==e&&(t.height=e)}}(t,e),n):null}releaseContext(t){const e=t.canvas;if(!e[ts])return!1;const n=e[ts].initial;["height","width"].forEach((t=>{const i=n[t];dt(i)?e.removeAttribute(t):e.setAttribute(t,i)}));const i=n.style||{};return Object.keys(i).forEach((t=>{e.style[t]=i[t]})),e.width=e.width,delete e[ts],!0}addEventListener(t,e,n){this.removeEventListener(t,e);const i=t.$proxies||(t.$proxies={}),s={attach:as,detach:rs,resize:hs}[e]||gs;i[e]=s(t,e,n)}removeEventListener(t,e){const n=t.$proxies||(t.$proxies={}),i=n[e];if(!i)return;({attach:us,detach:us,resize:us}[e]||ss)(t,e,i),n[e]=void 0}getDevicePixelRatio(){return window.devicePixelRatio}getMaximumSize(t,e,n,i){return On(t,e,n,i)}isAttached(t){const e=t&&Tn(t);return!(!e||!e.isConnected)}}class ms{static defaults={};static defaultRoutes=void 0;x;y;active=!1;options;$animations;tooltipPosition(t){const{x:e,y:n}=this.getProps(["x","y"],t);return{x:e,y:n}}hasValue(){return Vt(this.x)&&Vt(this.y)}getProps(t,e){const n=this.$animations;if(!e||!n)return this;const i={};return t.forEach((t=>{i[t]=n[t]&&n[t].active()?n[t]._to:this[t]})),i}}function fs(t,e){const n=t.options.ticks,i=function(t){const e=t.options.offset,n=t._tickSize(),i=t._length/n+(e?0:1),s=t._maxLength/n;return Math.floor(Math.min(i,s))}(t),s=Math.min(n.maxTicksLimit||i,i),o=n.major.enabled?function(t){const e=[];let n,i;for(n=0,i=t.length;n<i;n++)t[n].major&&e.push(n);return e}(e):[],a=o.length,r=o[0],c=o[a-1],l=[];if(a>s)return function(t,e,n,i){let s,o=0,a=n[0];for(i=Math.ceil(i),s=0;s<t.length;s++)s===a&&(e.push(t[s]),o++,a=n[o*i])}(e,l,o,a/s),l;const d=function(t,e,n){const i=function(t){const e=t.length;let n,i;if(e<2)return!1;for(i=t[0],n=1;n<e;++n)if(t[n]-t[n-1]!==i)return!1;return i}(t),s=e.length/n;if(!i)return Math.max(s,1);const o=function(t){const e=[],n=Math.sqrt(t);let i;for(i=1;i<n;i++)t%i===0&&(e.push(i),e.push(t/i));return n===(0|n)&&e.push(n),e.sort(((t,e)=>t-e)).pop(),e}(i);for(let t=0,e=o.length-1;t<e;t++){const e=o[t];if(e>s)return e}return Math.max(s,1)}(o,e,s);if(a>0){let t,n;const i=a>1?Math.round((c-r)/(a-1)):null;for(bs(e,l,d,dt(i)?0:r-i,r),t=0,n=a-1;t<n;t++)bs(e,l,d,o[t],o[t+1]);return bs(e,l,d,c,dt(i)?e.length:c+i),l}return bs(e,l,d),l}function bs(t,e,n,i,s){const o=mt(i,0),a=Math.min(mt(s,t.length),t.length);let r,c,l,d=0;for(n=Math.ceil(n),s&&(r=s-i,n=r/Math.floor(r/n)),l=o;l<0;)d++,l=Math.round(o+d*n);for(c=Math.max(o,0);c<a;c++)c===l&&(e.push(t[c]),d++,l=Math.round(o+d*n))}const ys=(t,e,n)=>"top"===e||"left"===e?t[e]+n:t[e]-n,xs=(t,e)=>Math.min(e||t,t);function vs(t,e){const n=[],i=t.length/e,s=t.length;let o=0;for(;o<s;o+=i)n.push(t[Math.floor(o)]);return n}function ws(t,e,n){const i=t.ticks.length,s=Math.min(e,i-1),o=t._startPixel,a=t._endPixel,r=1e-6;let c,l=t.getPixelForTick(s);if(!(n&&(c=1===i?Math.max(l-o,a-l):0===e?(t.getPixelForTick(1)-l)/2:(l-t.getPixelForTick(s-1))/2,l+=s<e?c:-c,l<o-r||l>a+r)))return l}function Ss(t){return t.drawTicks?t.tickLength:0}function ks(t,e){if(!t.display)return 0;const n=en(t.font,e),i=tn(t.padding);return(ht(t.text)?t.text.length:1)*n.lineHeight+i.height}function Ms(t,e,n){let i=de(t);return(n&&"right"!==e||!n&&"right"===e)&&(i=(t=>"left"===t?"right":"right"===t?"left":t)(i)),i}class _s extends ms{constructor(t){super(),this.id=t.id,this.type=t.type,this.options=void 0,this.ctx=t.ctx,this.chart=t.chart,this.top=void 0,this.bottom=void 0,this.left=void 0,this.right=void 0,this.width=void 0,this.height=void 0,this._margins={left:0,right:0,top:0,bottom:0},this.maxWidth=void 0,this.maxHeight=void 0,this.paddingTop=void 0,this.paddingBottom=void 0,this.paddingLeft=void 0,this.paddingRight=void 0,this.axis=void 0,this.labelRotation=void 0,this.min=void 0,this.max=void 0,this._range=void 0,this.ticks=[],this._gridLineItems=null,this._labelItems=null,this._labelSizes=null,this._length=0,this._maxLength=0,this._longestTextCache={},this._startPixel=void 0,this._endPixel=void 0,this._reversePixels=!1,this._userMax=void 0,this._userMin=void 0,this._suggestedMax=void 0,this._suggestedMin=void 0,this._ticksLength=0,this._borderValue=0,this._cache={},this._dataLimitsCached=!1,this.$context=void 0}init(t){this.options=t.setContext(this.getContext()),this.axis=t.axis,this._userMin=this.parse(t.min),this._userMax=this.parse(t.max),this._suggestedMin=this.parse(t.suggestedMin),this._suggestedMax=this.parse(t.suggestedMax)}parse(t,e){return t}getUserBounds(){let{_userMin:t,_userMax:e,_suggestedMin:n,_suggestedMax:i}=this;return t=pt(t,Number.POSITIVE_INFINITY),e=pt(e,Number.NEGATIVE_INFINITY),n=pt(n,Number.POSITIVE_INFINITY),i=pt(i,Number.NEGATIVE_INFINITY),{min:pt(t,n),max:pt(e,i),minDefined:gt(t),maxDefined:gt(e)}}getMinMax(t){let e,{min:n,max:i,minDefined:s,maxDefined:o}=this.getUserBounds();if(s&&o)return{min:n,max:i};const a=this.getMatchingVisibleMetas();for(let r=0,c=a.length;r<c;++r)e=a[r].controller.getMinMax(this,t),s||(n=Math.min(n,e.min)),o||(i=Math.max(i,e.max));return n=o&&n>i?i:n,i=s&&n>i?n:i,{min:pt(n,pt(i,n)),max:pt(i,pt(n,i))}}getPadding(){return{left:this.paddingLeft||0,top:this.paddingTop||0,right:this.paddingRight||0,bottom:this.paddingBottom||0}}getTicks(){return this.ticks}getLabels(){const t=this.chart.data;return this.options.labels||(this.isHorizontal()?t.xLabels:t.yLabels)||t.labels||[]}getLabelItems(t=this.chart.chartArea){return this._labelItems||(this._labelItems=this._computeLabelItems(t))}beforeLayout(){this._cache={},this._dataLimitsCached=!1}beforeUpdate(){bt(this.options.beforeUpdate,[this])}update(t,e,n){const{beginAtZero:i,grace:s,ticks:o}=this.options,a=o.sampleSize;this.beforeUpdate(),this.maxWidth=t,this.maxHeight=e,this._margins=n=Object.assign({left:0,right:0,top:0,bottom:0},n),this.ticks=null,this._labelSizes=null,this._gridLineItems=null,this._labelItems=null,this.beforeSetDimensions(),this.setDimensions(),this.afterSetDimensions(),this._maxLength=this.isHorizontal()?this.width+n.left+n.right:this.height+n.top+n.bottom,this._dataLimitsCached||(this.beforeDataLimits(),this.determineDataLimits(),this.afterDataLimits(),this._range=function(t,e,n){const{min:i,max:s}=t,o=ft(e,(s-i)/2),a=(t,e)=>n&&0===t?0:t+e;return{min:a(i,-Math.abs(o)),max:a(s,o)}}(this,s,i),this._dataLimitsCached=!0),this.beforeBuildTicks(),this.ticks=this.buildTicks()||[],this.afterBuildTicks();const r=a<this.ticks.length;this._convertTicksToLabels(r?vs(this.ticks,a):this.ticks),this.configure(),this.beforeCalculateLabelRotation(),this.calculateLabelRotation(),this.afterCalculateLabelRotation(),o.display&&(o.autoSkip||"auto"===o.source)&&(this.ticks=fs(this,this.ticks),this._labelSizes=null,this.afterAutoSkip()),r&&this._convertTicksToLabels(this.ticks),this.beforeFit(),this.fit(),this.afterFit(),this.afterUpdate()}configure(){let t,e,n=this.options.reverse;this.isHorizontal()?(t=this.left,e=this.right):(t=this.top,e=this.bottom,n=!n),this._startPixel=t,this._endPixel=e,this._reversePixels=n,this._length=e-t,this._alignToPixels=this.options.alignToPixels}afterUpdate(){bt(this.options.afterUpdate,[this])}beforeSetDimensions(){bt(this.options.beforeSetDimensions,[this])}setDimensions(){this.isHorizontal()?(this.width=this.maxWidth,this.left=0,this.right=this.width):(this.height=this.maxHeight,this.top=0,this.bottom=this.height),this.paddingLeft=0,this.paddingTop=0,this.paddingRight=0,this.paddingBottom=0}afterSetDimensions(){bt(this.options.afterSetDimensions,[this])}_callHooks(t){this.chart.notifyPlugins(t,this.getContext()),bt(this.options[t],[this])}beforeDataLimits(){this._callHooks("beforeDataLimits")}determineDataLimits(){}afterDataLimits(){this._callHooks("afterDataLimits")}beforeBuildTicks(){this._callHooks("beforeBuildTicks")}buildTicks(){return[]}afterBuildTicks(){this._callHooks("afterBuildTicks")}beforeTickToLabelConversion(){bt(this.options.beforeTickToLabelConversion,[this])}generateTickLabels(t){const e=this.options.ticks;let n,i,s;for(n=0,i=t.length;n<i;n++)s=t[n],s.label=bt(e.callback,[s.value,n,t],this)}afterTickToLabelConversion(){bt(this.options.afterTickToLabelConversion,[this])}beforeCalculateLabelRotation(){bt(this.options.beforeCalculateLabelRotation,[this])}calculateLabelRotation(){const t=this.options,e=t.ticks,n=xs(this.ticks.length,t.ticks.maxTicksLimit),i=e.minRotation||0,s=e.maxRotation;let o,a,r,c=i;if(!this._isVisible()||!e.display||i>=s||n<=1||!this.isHorizontal())return void(this.labelRotation=i);const l=this._getLabelSizes(),d=l.widest.width,h=l.highest.height,u=te(this.chart.width-d,0,this.maxWidth);o=t.offset?this.maxWidth/n:u/(n-1),d+6>o&&(o=u/(n-(t.offset?.5:1)),a=this.maxHeight-Ss(t.grid)-e.padding-ks(t.title,this.chart.options.font),r=Math.sqrt(d*d+h*h),c=Ut(Math.min(Math.asin(te((l.highest.height+6)/o,-1,1)),Math.asin(te(a/r,-1,1))-Math.asin(te(h/r,-1,1)))),c=Math.max(i,Math.min(s,c))),this.labelRotation=c}afterCalculateLabelRotation(){bt(this.options.afterCalculateLabelRotation,[this])}afterAutoSkip(){}beforeFit(){bt(this.options.beforeFit,[this])}fit(){const t={width:0,height:0},{chart:e,options:{ticks:n,title:i,grid:s}}=this,o=this._isVisible(),a=this.isHorizontal();if(o){const o=ks(i,e.options.font);if(a?(t.width=this.maxWidth,t.height=Ss(s)+o):(t.height=this.maxHeight,t.width=Ss(s)+o),n.display&&this.ticks.length){const{first:e,last:i,widest:s,highest:o}=this._getLabelSizes(),r=2*n.padding,c=Yt(this.labelRotation),l=Math.cos(c),d=Math.sin(c);if(a){const e=n.mirror?0:d*s.width+l*o.height;t.height=Math.min(this.maxHeight,t.height+e+r)}else{const e=n.mirror?0:l*s.width+d*o.height;t.width=Math.min(this.maxWidth,t.width+e+r)}this._calculatePadding(e,i,d,l)}}this._handleMargins(),a?(this.width=this._length=e.width-this._margins.left-this._margins.right,this.height=t.height):(this.width=t.width,this.height=this._length=e.height-this._margins.top-this._margins.bottom)}_calculatePadding(t,e,n,i){const{ticks:{align:s,padding:o},position:a}=this.options,r=0!==this.labelRotation,c="top"!==a&&"x"===this.axis;if(this.isHorizontal()){const a=this.getPixelForTick(0)-this.left,l=this.right-this.getPixelForTick(this.ticks.length-1);let d=0,h=0;r?c?(d=i*t.width,h=n*e.height):(d=n*t.height,h=i*e.width):"start"===s?h=e.width:"end"===s?d=t.width:"inner"!==s&&(d=t.width/2,h=e.width/2),this.paddingLeft=Math.max((d-a+o)*this.width/(this.width-a),0),this.paddingRight=Math.max((h-l+o)*this.width/(this.width-l),0)}else{let n=e.height/2,i=t.height/2;"start"===s?(n=0,i=t.height):"end"===s&&(n=e.height,i=0),this.paddingTop=n+o,this.paddingBottom=i+o}}_handleMargins(){this._margins&&(this._margins.left=Math.max(this.paddingLeft,this._margins.left),this._margins.top=Math.max(this.paddingTop,this._margins.top),this._margins.right=Math.max(this.paddingRight,this._margins.right),this._margins.bottom=Math.max(this.paddingBottom,this._margins.bottom))}afterFit(){bt(this.options.afterFit,[this])}isHorizontal(){const{axis:t,position:e}=this.options;return"top"===e||"bottom"===e||"x"===t}isFullSize(){return this.options.fullSize}_convertTicksToLabels(t){let e,n;for(this.beforeTickToLabelConversion(),this.generateTickLabels(t),e=0,n=t.length;e<n;e++)dt(t[e].label)&&(t.splice(e,1),n--,e--);this.afterTickToLabelConversion()}_getLabelSizes(){let t=this._labelSizes;if(!t){const e=this.options.ticks.sampleSize;let n=this.ticks;e<n.length&&(n=vs(n,e)),this._labelSizes=t=this._computeLabelSizes(n,n.length,this.options.ticks.maxTicksLimit)}return t}_computeLabelSizes(t,e,n){const{ctx:i,_longestTextCache:s}=this,o=[],a=[],r=Math.floor(e/xs(e,n));let c,l,d,h,u,g,p,m,f,b,y,x=0,v=0;for(c=0;c<e;c+=r){if(h=t[c].label,u=this._resolveTickFontOptions(c),i.font=g=u.string,p=s[g]=s[g]||{data:{},gc:[]},m=u.lineHeight,f=b=0,dt(h)||ht(h)){if(ht(h))for(l=0,d=h.length;l<d;++l)y=h[l],dt(y)||ht(y)||(f=Ie(i,p.data,p.gc,f,y),b+=m)}else f=Ie(i,p.data,p.gc,f,h),b=m;o.push(f),a.push(b),x=Math.max(f,x),v=Math.max(b,v)}!function(t,e){yt(t,(t=>{const n=t.gc,i=n.length/2;let s;if(i>e){for(s=0;s<i;++s)delete t.data[n[s]];n.splice(0,i)}}))}(s,e);const w=o.indexOf(x),S=a.indexOf(v),k=t=>({width:o[t]||0,height:a[t]||0});return{first:k(0),last:k(e-1),widest:k(w),highest:k(S),widths:o,heights:a}}getLabelForValue(t){return t}getPixelForValue(t,e){return NaN}getValueForPixel(t){}getPixelForTick(t){const e=this.ticks;return t<0||t>e.length-1?null:this.getPixelForValue(e[t].value)}getPixelForDecimal(t){this._reversePixels&&(t=1-t);const e=this._startPixel+t*this._length;return te(this._alignToPixels?ze(this.chart,e,0):e,-32768,32767)}getDecimalForPixel(t){const e=(t-this._startPixel)/this._length;return this._reversePixels?1-e:e}getBasePixel(){return this.getPixelForValue(this.getBaseValue())}getBaseValue(){const{min:t,max:e}=this;return t<0&&e<0?e:t>0&&e>0?t:0}getContext(t){const e=this.ticks||[];if(t>=0&&t<e.length){const n=e[t];return n.$context||(n.$context=function(t,e,n){return sn(t,{tick:n,index:e,type:"tick"})}(this.getContext(),t,n))}return this.$context||(this.$context=sn(this.chart.getContext(),{scale:this,type:"scale"}))}_tickSize(){const t=this.options.ticks,e=Yt(this.labelRotation),n=Math.abs(Math.cos(e)),i=Math.abs(Math.sin(e)),s=this._getLabelSizes(),o=t.autoSkipPadding||0,a=s?s.widest.width+o:0,r=s?s.highest.height+o:0;return this.isHorizontal()?r*n>a*i?a/n:r/i:r*i<a*n?r/n:a/i}_isVisible(){const t=this.options.display;return"auto"!==t?!!t:this.getMatchingVisibleMetas().length>0}_computeGridLineItems(t){const e=this.axis,n=this.chart,i=this.options,{grid:s,position:o,border:a}=i,r=s.offset,c=this.isHorizontal(),l=this.ticks.length+(r?1:0),d=Ss(s),h=[],u=a.setContext(this.getContext()),g=u.display?u.width:0,p=g/2,m=function(t){return ze(n,t,g)};let f,b,y,x,v,w,S,k,M,_,C,T;if("top"===o)f=m(this.bottom),w=this.bottom-d,k=f-p,_=m(t.top)+p,T=t.bottom;else if("bottom"===o)f=m(this.top),_=t.top,T=m(t.bottom)-p,w=f+p,k=this.top+d;else if("left"===o)f=m(this.right),v=this.right-d,S=f-p,M=m(t.left)+p,C=t.right;else if("right"===o)f=m(this.left),M=t.left,C=m(t.right)-p,v=f+p,S=this.left+d;else if("x"===e){if("center"===o)f=m((t.top+t.bottom)/2+.5);else if(ut(o)){const t=Object.keys(o)[0],e=o[t];f=m(this.chart.scales[t].getPixelForValue(e))}_=t.top,T=t.bottom,w=f+p,k=w+d}else if("y"===e){if("center"===o)f=m((t.left+t.right)/2);else if(ut(o)){const t=Object.keys(o)[0],e=o[t];f=m(this.chart.scales[t].getPixelForValue(e))}v=f-p,S=v-d,M=t.left,C=t.right}const D=mt(i.ticks.maxTicksLimit,l),P=Math.max(1,Math.ceil(l/D));for(b=0;b<l;b+=P){const t=this.getContext(b),e=s.setContext(t),i=a.setContext(t),o=e.lineWidth,l=e.color,d=i.dash||[],u=i.dashOffset,g=e.tickWidth,p=e.tickColor,m=e.tickBorderDash||[],f=e.tickBorderDashOffset;y=ws(this,b,r),void 0!==y&&(x=ze(n,y,o),c?v=S=M=C=x:w=k=_=T=x,h.push({tx1:v,ty1:w,tx2:S,ty2:k,x1:M,y1:_,x2:C,y2:T,width:o,color:l,borderDash:d,borderDashOffset:u,tickWidth:g,tickColor:p,tickBorderDash:m,tickBorderDashOffset:f}))}return this._ticksLength=l,this._borderValue=f,h}_computeLabelItems(t){const e=this.axis,n=this.options,{position:i,ticks:s}=n,o=this.isHorizontal(),a=this.ticks,{align:r,crossAlign:c,padding:l,mirror:d}=s,h=Ss(n.grid),u=h+l,g=d?-l:u,p=-Yt(this.labelRotation),m=[];let f,b,y,x,v,w,S,k,M,_,C,T,D="middle";if("top"===i)w=this.bottom-g,S=this._getXAxisLabelAlignment();else if("bottom"===i)w=this.top+g,S=this._getXAxisLabelAlignment();else if("left"===i){const t=this._getYAxisLabelAlignment(h);S=t.textAlign,v=t.x}else if("right"===i){const t=this._getYAxisLabelAlignment(h);S=t.textAlign,v=t.x}else if("x"===e){if("center"===i)w=(t.top+t.bottom)/2+u;else if(ut(i)){const t=Object.keys(i)[0],e=i[t];w=this.chart.scales[t].getPixelForValue(e)+u}S=this._getXAxisLabelAlignment()}else if("y"===e){if("center"===i)v=(t.left+t.right)/2-u;else if(ut(i)){const t=Object.keys(i)[0],e=i[t];v=this.chart.scales[t].getPixelForValue(e)}S=this._getYAxisLabelAlignment(h).textAlign}"y"===e&&("start"===r?D="top":"end"===r&&(D="bottom"));const P=this._getLabelSizes();for(f=0,b=a.length;f<b;++f){y=a[f],x=y.label;const t=s.setContext(this.getContext(f));k=this.getPixelForTick(f)+s.labelOffset,M=this._resolveTickFontOptions(f),_=M.lineHeight,C=ht(x)?x.length:1;const e=C/2,n=t.color,r=t.textStrokeColor,l=t.textStrokeWidth;let h,u=S;if(o?(v=k,"inner"===S&&(u=f===b-1?this.options.reverse?"left":"right":0===f?this.options.reverse?"right":"left":"center"),T="top"===i?"near"===c||0!==p?-C*_+_/2:"center"===c?-P.highest.height/2-e*_+_:-P.highest.height+_/2:"near"===c||0!==p?_/2:"center"===c?P.highest.height/2-e*_:P.highest.height-C*_,d&&(T*=-1),0===p||t.showLabelBackdrop||(v+=_/2*Math.sin(p))):(w=k,T=(1-C)*_/2),t.showLabelBackdrop){const e=tn(t.backdropPadding),n=P.heights[f],i=P.widths[f];let s=T-e.top,o=0-e.left;switch(D){case"middle":s-=n/2;break;case"bottom":s-=n}switch(S){case"center":o-=i/2;break;case"right":o-=i;break;case"inner":f===b-1?o-=i:f>0&&(o-=i/2)}h={left:o,top:s,width:i+e.width,height:n+e.height,color:t.backdropColor}}m.push({label:x,font:M,textOffset:T,options:{rotation:p,color:n,strokeColor:r,strokeWidth:l,textAlign:u,textBaseline:D,translation:[v,w],backdrop:h}})}return m}_getXAxisLabelAlignment(){const{position:t,ticks:e}=this.options;if(-Yt(this.labelRotation))return"top"===t?"left":"right";let n="center";return"start"===e.align?n="left":"end"===e.align?n="right":"inner"===e.align&&(n="inner"),n}_getYAxisLabelAlignment(t){const{position:e,ticks:{crossAlign:n,mirror:i,padding:s}}=this.options,o=t+s,a=this._getLabelSizes().widest.width;let r,c;return"left"===e?i?(c=this.right+s,"near"===n?r="left":"center"===n?(r="center",c+=a/2):(r="right",c+=a)):(c=this.right-o,"near"===n?r="right":"center"===n?(r="center",c-=a/2):(r="left",c=this.left)):"right"===e?i?(c=this.left+s,"near"===n?r="right":"center"===n?(r="center",c-=a/2):(r="left",c-=a)):(c=this.left+o,"near"===n?r="left":"center"===n?(r="center",c+=a/2):(r="right",c=this.right)):r="right",{textAlign:r,x:c}}_computeLabelArea(){if(this.options.ticks.mirror)return;const t=this.chart,e=this.options.position;return"left"===e||"right"===e?{top:0,left:this.left,bottom:t.height,right:this.right}:"top"===e||"bottom"===e?{top:this.top,left:0,bottom:this.bottom,right:t.width}:void 0}drawBackground(){const{ctx:t,options:{backgroundColor:e},left:n,top:i,width:s,height:o}=this;e&&(t.save(),t.fillStyle=e,t.fillRect(n,i,s,o),t.restore())}getLineWidthForValue(t){const e=this.options.grid;if(!this._isVisible()||!e.display)return 0;const n=this.ticks.findIndex((e=>e.value===t));if(n>=0){return e.setContext(this.getContext(n)).lineWidth}return 0}drawGrid(t){const e=this.options.grid,n=this.ctx,i=this._gridLineItems||(this._gridLineItems=this._computeGridLineItems(t));let s,o;const a=(t,e,i)=>{i.width&&i.color&&(n.save(),n.lineWidth=i.width,n.strokeStyle=i.color,n.setLineDash(i.borderDash||[]),n.lineDashOffset=i.borderDashOffset,n.beginPath(),n.moveTo(t.x,t.y),n.lineTo(e.x,e.y),n.stroke(),n.restore())};if(e.display)for(s=0,o=i.length;s<o;++s){const t=i[s];e.drawOnChartArea&&a({x:t.x1,y:t.y1},{x:t.x2,y:t.y2},t),e.drawTicks&&a({x:t.tx1,y:t.ty1},{x:t.tx2,y:t.ty2},{color:t.tickColor,width:t.tickWidth,borderDash:t.tickBorderDash,borderDashOffset:t.tickBorderDashOffset})}}drawBorder(){const{chart:t,ctx:e,options:{border:n,grid:i}}=this,s=n.setContext(this.getContext()),o=n.display?s.width:0;if(!o)return;const a=i.setContext(this.getContext(0)).lineWidth,r=this._borderValue;let c,l,d,h;this.isHorizontal()?(c=ze(t,this.left,o)-o/2,l=ze(t,this.right,a)+a/2,d=h=r):(d=ze(t,this.top,o)-o/2,h=ze(t,this.bottom,a)+a/2,c=l=r),e.save(),e.lineWidth=s.width,e.strokeStyle=s.color,e.beginPath(),e.moveTo(c,d),e.lineTo(l,h),e.stroke(),e.restore()}drawLabels(t){if(!this.options.ticks.display)return;const e=this.ctx,n=this._computeLabelArea();n&&Fe(e,n);const i=this.getLabelItems(t);for(const t of i){const n=t.options,i=t.font;Ye(e,t.label,0,t.textOffset,i,n)}n&&qe(e)}drawTitle(){const{ctx:t,options:{position:e,title:n,reverse:i}}=this;if(!n.display)return;const s=en(n.font),o=tn(n.padding),a=n.align;let r=s.lineHeight/2;"bottom"===e||"center"===e||ut(e)?(r+=o.bottom,ht(n.text)&&(r+=s.lineHeight*(n.text.length-1))):r+=o.top;const{titleX:c,titleY:l,maxWidth:d,rotation:h}=function(t,e,n,i){const{top:s,left:o,bottom:a,right:r,chart:c}=t,{chartArea:l,scales:d}=c;let h,u,g,p=0;const m=a-s,f=r-o;if(t.isHorizontal()){if(u=he(i,o,r),ut(n)){const t=Object.keys(n)[0],i=n[t];g=d[t].getPixelForValue(i)+m-e}else g="center"===n?(l.bottom+l.top)/2+m-e:ys(t,n,e);h=r-o}else{if(ut(n)){const t=Object.keys(n)[0],i=n[t];u=d[t].getPixelForValue(i)-f+e}else u="center"===n?(l.left+l.right)/2-f+e:ys(t,n,e);g=he(i,a,s),p="left"===n?-Nt:Nt}return{titleX:u,titleY:g,maxWidth:h,rotation:p}}(this,r,e,a);Ye(t,n.text,0,0,s,{color:n.color,maxWidth:d,rotation:h,textAlign:Ms(a,e,i),textBaseline:"middle",translation:[c,l]})}draw(t){this._isVisible()&&(this.drawBackground(),this.drawGrid(t),this.drawBorder(),this.drawTitle(),this.drawLabels(t))}_layers(){const t=this.options,e=t.ticks&&t.ticks.z||0,n=mt(t.grid&&t.grid.z,-1),i=mt(t.border&&t.border.z,0);return this._isVisible()&&this.draw===_s.prototype.draw?[{z:n,draw:t=>{this.drawBackground(),this.drawGrid(t),this.drawTitle()}},{z:i,draw:()=>{this.drawBorder()}},{z:e,draw:t=>{this.drawLabels(t)}}]:[{z:e,draw:t=>{this.draw(t)}}]}getMatchingVisibleMetas(t){const e=this.chart.getSortedVisibleDatasetMetas(),n=this.axis+"AxisID",i=[];let s,o;for(s=0,o=e.length;s<o;++s){const o=e[s];o[n]!==this.id||t&&o.type!==t||i.push(o)}return i}_resolveTickFontOptions(t){return en(this.options.ticks.setContext(this.getContext(t)).font)}_maxDigits(){const t=this._resolveTickFontOptions(0).lineHeight;return(this.isHorizontal()?this.width:this.height)/t}}class Cs{constructor(t,e,n){this.type=t,this.scope=e,this.override=n,this.items=Object.create(null)}isForType(t){return Object.prototype.isPrototypeOf.call(this.type.prototype,t.prototype)}register(t){const e=Object.getPrototypeOf(t);let n;(function(t){return"id"in t&&"defaults"in t})(e)&&(n=this.register(e));const i=this.items,s=t.id,o=this.scope+"."+s;if(!s)throw new Error("class does not have id: "+t);return s in i||(i[s]=t,function(t,e,n){const i=kt(Object.create(null),[n?Le.get(n):{},Le.get(e),t.defaults]);Le.set(e,i),t.defaultRoutes&&function(t,e){Object.keys(e).forEach((n=>{const i=n.split("."),s=i.pop(),o=[t].concat(i).join("."),a=e[n].split("."),r=a.pop(),c=a.join(".");Le.route(o,s,c,r)}))}(e,t.defaultRoutes);t.descriptors&&Le.describe(e,t.descriptors)}(t,o,n),this.override&&Le.override(t.id,t.overrides)),o}get(t){return this.items[t]}unregister(t){const e=this.items,n=t.id,i=this.scope;n in e&&delete e[n],i&&n in Le[i]&&(delete Le[i][n],this.override&&delete Te[n])}}class Ts{constructor(){this.controllers=new Cs(fi,"datasets",!0),this.elements=new Cs(ms,"elements"),this.plugins=new Cs(Object,"plugins"),this.scales=new Cs(_s,"scales"),this._typedRegistries=[this.controllers,this.scales,this.elements]}add(...t){this._each("register",t)}remove(...t){this._each("unregister",t)}addControllers(...t){this._each("register",t,this.controllers)}addElements(...t){this._each("register",t,this.elements)}addPlugins(...t){this._each("register",t,this.plugins)}addScales(...t){this._each("register",t,this.scales)}getController(t){return this._get(t,this.controllers,"controller")}getElement(t){return this._get(t,this.elements,"element")}getPlugin(t){return this._get(t,this.plugins,"plugin")}getScale(t){return this._get(t,this.scales,"scale")}removeControllers(...t){this._each("unregister",t,this.controllers)}removeElements(...t){this._each("unregister",t,this.elements)}removePlugins(...t){this._each("unregister",t,this.plugins)}removeScales(...t){this._each("unregister",t,this.scales)}_each(t,e,n){[...e].forEach((e=>{const i=n||this._getRegistryForType(e);n||i.isForType(e)||i===this.plugins&&e.id?this._exec(t,i,e):yt(e,(e=>{const i=n||this._getRegistryForType(e);this._exec(t,i,e)}))}))}_exec(t,e,n){const i=Dt(t);bt(n["before"+i],[],n),e[t](n),bt(n["after"+i],[],n)}_getRegistryForType(t){for(let e=0;e<this._typedRegistries.length;e++){const n=this._typedRegistries[e];if(n.isForType(t))return n}return this.plugins}_get(t,e,n){const i=e.get(t);if(void 0===i)throw new Error('"'+t+'" is not a registered '+n+".");return i}}var Ds=new Ts;class Ps{constructor(){this._init=void 0}notify(t,e,n,i){if("beforeInit"===e&&(this._init=this._createDescriptors(t,!0),this._notify(this._init,t,"install")),void 0===this._init)return;const s=i?this._descriptors(t).filter(i):this._descriptors(t),o=this._notify(s,t,e,n);return"afterDestroy"===e&&(this._notify(s,t,"stop"),this._notify(this._init,t,"uninstall"),this._init=void 0),o}_notify(t,e,n,i){i=i||{};for(const s of t){const t=s.plugin;if(!1===bt(t[n],[e,i,s.options],t)&&i.cancelable)return!1}return!0}invalidate(){dt(this._cache)||(this._oldCache=this._cache,this._cache=void 0)}_descriptors(t){if(this._cache)return this._cache;const e=this._cache=this._createDescriptors(t);return this._notifyStateChanges(t),e}_createDescriptors(t,e){const n=t&&t.config,i=mt(n.options&&n.options.plugins,{}),s=function(t){const e={},n=[],i=Object.keys(Ds.plugins.items);for(let t=0;t<i.length;t++)n.push(Ds.getPlugin(i[t]));const s=t.plugins||[];for(let t=0;t<s.length;t++){const i=s[t];-1===n.indexOf(i)&&(n.push(i),e[i.id]=!0)}return{plugins:n,localIds:e}}(n);return!1!==i||e?function(t,{plugins:e,localIds:n},i,s){const o=[],a=t.getContext();for(const r of e){const e=r.id,c=Es(i[e],s);null!==c&&o.push({plugin:r,options:As(t.config,{plugin:r,local:n[e]},c,a)})}return o}(t,s,i,e):[]}_notifyStateChanges(t){const e=this._oldCache||[],n=this._cache,i=(t,e)=>t.filter((t=>!e.some((e=>t.plugin.id===e.plugin.id))));this._notify(i(e,n),t,"stop"),this._notify(i(n,e),t,"start")}}function Es(t,e){return e||!1!==t?!0===t?{}:t:null}function As(t,{plugin:e,local:n},i,s){const o=t.pluginScopeKeys(e),a=t.getOptionScopes(i,o);return n&&e.defaults&&a.push(e.defaults),t.createResolver(a,s,[""],{scriptable:!1,indexable:!1,allKeys:!0})}function Ls(t,e){const n=Le.datasets[t]||{};return((e.datasets||{})[t]||{}).indexAxis||e.indexAxis||n.indexAxis||"x"}function Is(t){if("x"===t||"y"===t||"r"===t)return t}function Os(t,...e){if(Is(t))return t;for(const i of e){const e=i.axis||("top"===(n=i.position)||"bottom"===n?"x":"left"===n||"right"===n?"y":void 0)||t.length>1&&Is(t[0].toLowerCase());if(e)return e}var n;throw new Error(`Cannot determine type of '${t}' axis. Please provide 'axis' or 'position' option.`)}function zs(t,e,n){if(n[e+"AxisID"]===t)return{axis:e}}function Ws(t,e){const n=Te[t.type]||{scales:{}},i=e.scales||{},s=Ls(t.type,e),o=Object.create(null);return Object.keys(i).forEach((e=>{const a=i[e];if(!ut(a))return console.error(`Invalid scale configuration for scale: ${e}`);if(a._proxy)return console.warn(`Ignoring resolver passed as options for scale: ${e}`);const r=Os(e,a,function(t,e){if(e.data&&e.data.datasets){const n=e.data.datasets.filter((e=>e.xAxisID===t||e.yAxisID===t));if(n.length)return zs(t,"x",n[0])||zs(t,"y",n[0])}return{}}(e,t),Le.scales[a.type]),c=function(t,e){return t===e?"_index_":"_value_"}(r,s),l=n.scales||{};o[e]=Mt(Object.create(null),[{axis:r},a,l[r],l[c]])})),t.data.datasets.forEach((n=>{const s=n.type||t.type,a=n.indexAxis||Ls(s,e),r=(Te[s]||{}).scales||{};Object.keys(r).forEach((t=>{const e=function(t,e){let n=t;return"_index_"===t?n=e:"_value_"===t&&(n="x"===e?"y":"x"),n}(t,a),s=n[e+"AxisID"]||e;o[s]=o[s]||Object.create(null),Mt(o[s],[{axis:e},i[s],r[t]])}))})),Object.keys(o).forEach((t=>{const e=o[t];Mt(e,[Le.scales[e.type],Le.scale])})),o}function Ns(t){const e=t.options||(t.options={});e.plugins=mt(e.plugins,{}),e.scales=Ws(t,e)}function Rs(t){return(t=t||{}).datasets=t.datasets||[],t.labels=t.labels||[],t}const $s=new Map,Fs=new Set;function qs(t,e){let n=$s.get(t);return n||(n=e(),$s.set(t,n),Fs.add(n)),n}const Bs=(t,e,n)=>{const i=Tt(e,n);void 0!==i&&t.add(i)};class Hs{constructor(t){this._config=function(t){return(t=t||{}).data=Rs(t.data),Ns(t),t}(t),this._scopeCache=new Map,this._resolverCache=new Map}get platform(){return this._config.platform}get type(){return this._config.type}set type(t){this._config.type=t}get data(){return this._config.data}set data(t){this._config.data=Rs(t)}get options(){return this._config.options}set options(t){this._config.options=t}get plugins(){return this._config.plugins}update(){const t=this._config;this.clearCache(),Ns(t)}clearCache(){this._scopeCache.clear(),this._resolverCache.clear()}datasetScopeKeys(t){return qs(t,(()=>[[`datasets.${t}`,""]]))}datasetAnimationScopeKeys(t,e){return qs(`${t}.transition.${e}`,(()=>[[`datasets.${t}.transitions.${e}`,`transitions.${e}`],[`datasets.${t}`,""]]))}datasetElementScopeKeys(t,e){return qs(`${t}-${e}`,(()=>[[`datasets.${t}.elements.${e}`,`datasets.${t}`,`elements.${e}`,""]]))}pluginScopeKeys(t){const e=t.id;return qs(`${this.type}-plugin-${e}`,(()=>[[`plugins.${e}`,...t.additionalOptionScopes||[]]]))}_cachedScopes(t,e){const n=this._scopeCache;let i=n.get(t);return i&&!e||(i=new Map,n.set(t,i)),i}getOptionScopes(t,e,n){const{options:i,type:s}=this,o=this._cachedScopes(t,n),a=o.get(e);if(a)return a;const r=new Set;e.forEach((e=>{t&&(r.add(t),e.forEach((e=>Bs(r,t,e)))),e.forEach((t=>Bs(r,i,t))),e.forEach((t=>Bs(r,Te[s]||{},t))),e.forEach((t=>Bs(r,Le,t))),e.forEach((t=>Bs(r,De,t)))}));const c=Array.from(r);return 0===c.length&&c.push(Object.create(null)),Fs.has(e)&&o.set(e,c),c}chartOptionScopes(){const{options:t,type:e}=this;return[t,Te[e]||{},Le.datasets[e]||{},{type:e},Le,De]}resolveNamedOptions(t,e,n,i=[""]){const s={$shared:!0},{resolver:o,subPrefixes:a}=Vs(this._resolverCache,t,i);let r=o;if(function(t,e){const{isScriptable:n,isIndexable:i}=rn(t);for(const s of e){const e=n(s),o=i(s),a=(o||e)&&t[s];if(e&&(Et(a)||js(a))||o&&ht(a))return!0}return!1}(o,e)){s.$shared=!1;r=an(o,n=Et(n)?n():n,this.createResolver(t,n,a))}for(const t of e)s[t]=r[t];return s}createResolver(t,e,n=[""],i){const{resolver:s}=Vs(this._resolverCache,t,n);return ut(e)?an(s,e,void 0,i):s}}function Vs(t,e,n){let i=t.get(e);i||(i=new Map,t.set(e,i));const s=n.join();let o=i.get(s);if(!o){o={resolver:on(e,n),subPrefixes:n.filter((t=>!t.toLowerCase().includes("hover")))},i.set(s,o)}return o}const js=t=>ut(t)&&Object.getOwnPropertyNames(t).some((e=>Et(t[e])));const Ys=["top","bottom","left","right","chartArea"];function Us(t,e){return"top"===t||"bottom"===t||-1===Ys.indexOf(t)&&"x"===e}function Xs(t,e){return function(n,i){return n[t]===i[t]?n[e]-i[e]:n[t]-i[t]}}function Qs(t){const e=t.chart,n=e.options.animation;e.notifyPlugins("afterRender"),bt(n&&n.onComplete,[t],e)}function Ks(t){const e=t.chart,n=e.options.animation;bt(n&&n.onProgress,[t],e)}function Zs(t){return Cn()&&"string"==typeof t?t=document.getElementById(t):t&&t.length&&(t=t[0]),t&&t.canvas&&(t=t.canvas),t}const Gs={},Js=t=>{const e=Zs(t);return Object.values(Gs).filter((t=>t.canvas===e)).pop()};function to(t,e,n){const i=Object.keys(t);for(const s of i){const i=+s;if(i>=e){const o=t[s];delete t[s],(n>0||i>e)&&(t[i+n]=o)}}}class eo{static defaults=Le;static instances=Gs;static overrides=Te;static registry=Ds;static version="4.5.1";static getChart=Js;static register(...t){Ds.add(...t),no()}static unregister(...t){Ds.remove(...t),no()}constructor(t,e){const n=this.config=new Hs(e),i=Zs(t),s=Js(i);if(s)throw new Error("Canvas is already in use. Chart with ID '"+s.id+"' must be destroyed before the canvas with ID '"+s.canvas.id+"' can be reused.");const o=n.createResolver(n.chartOptionScopes(),this.getContext());this.platform=new(n.platform||function(t){return!Cn()||"undefined"!=typeof OffscreenCanvas&&t instanceof OffscreenCanvas?Ji:ps}(i)),this.platform.updateConfig(n);const a=this.platform.acquireContext(i,o.aspectRatio),r=a&&a.canvas,c=r&&r.height,l=r&&r.width;this.id=lt(),this.ctx=a,this.canvas=r,this.width=l,this.height=c,this._options=o,this._aspectRatio=this.aspectRatio,this._layers=[],this._metasets=[],this._stacks=void 0,this.boxes=[],this.currentDevicePixelRatio=void 0,this.chartArea=void 0,this._active=[],this._lastEvent=void 0,this._listeners={},this._responsiveListeners=void 0,this._sortedMetasets=[],this.scales={},this._plugins=new Ps,this.$proxies={},this._hiddenIndices={},this.attached=!1,this._animationsDisabled=void 0,this.$context=void 0,this._doResize=function(t,e){let n;return function(...i){return e?(clearTimeout(n),n=setTimeout(t,e,i)):t.apply(this,i),e}}((t=>this.update(t)),o.resizeDelay||0),this._dataChanges=[],Gs[this.id]=this,a&&r?(ti.listen(this,"complete",Qs),ti.listen(this,"progress",Ks),this._initialize(),this.attached&&this.update()):console.error("Failed to create chart: can't acquire context from the given item")}get aspectRatio(){const{options:{aspectRatio:t,maintainAspectRatio:e},width:n,height:i,_aspectRatio:s}=this;return dt(t)?e&&s?s:i?n/i:null:t}get data(){return this.config.data}set data(t){this.config.data=t}get options(){return this._options}set options(t){this.config.options=t}get registry(){return Ds}_initialize(){return this.notifyPlugins("beforeInit"),this.options.responsive?this.resize():zn(this,this.options.devicePixelRatio),this.bindEvents(),this.notifyPlugins("afterInit"),this}clear(){return We(this.canvas,this.ctx),this}stop(){return ti.stop(this),this}resize(t,e){ti.running(this)?this._resizeBeforeDraw={width:t,height:e}:this._resize(t,e)}_resize(t,e){const n=this.options,i=this.canvas,s=n.maintainAspectRatio&&this.aspectRatio,o=this.platform.getMaximumSize(i,t,e,s),a=n.devicePixelRatio||this.platform.getDevicePixelRatio(),r=this.width?"resize":"attach";this.width=o.width,this.height=o.height,this._aspectRatio=this.aspectRatio,zn(this,a,!0)&&(this.notifyPlugins("resize",{size:o}),bt(n.onResize,[this,o],this),this.attached&&this._doResize(r)&&this.render())}ensureScalesHaveIDs(){yt(this.options.scales||{},((t,e)=>{t.id=e}))}buildOrUpdateScales(){const t=this.options,e=t.scales,n=this.scales,i=Object.keys(n).reduce(((t,e)=>(t[e]=!1,t)),{});let s=[];e&&(s=s.concat(Object.keys(e).map((t=>{const n=e[t],i=Os(t,n),s="r"===i,o="x"===i;return{options:n,dposition:s?"chartArea":o?"bottom":"left",dtype:s?"radialLinear":o?"category":"linear"}})))),yt(s,(e=>{const s=e.options,o=s.id,a=Os(o,s),r=mt(s.type,e.dtype);void 0!==s.position&&Us(s.position,a)===Us(e.dposition)||(s.position=e.dposition),i[o]=!0;let c=null;if(o in n&&n[o].type===r)c=n[o];else{c=new(Ds.getScale(r))({id:o,type:r,ctx:this.ctx,chart:this}),n[c.id]=c}c.init(s,t)})),yt(i,((t,e)=>{t||delete n[e]})),yt(n,(t=>{Zi.configure(this,t,t.options),Zi.addBox(this,t)}))}_updateMetasets(){const t=this._metasets,e=this.data.datasets.length,n=t.length;if(t.sort(((t,e)=>t.index-e.index)),n>e){for(let t=e;t<n;++t)this._destroyDatasetMeta(t);t.splice(e,n-e)}this._sortedMetasets=t.slice(0).sort(Xs("order","index"))}_removeUnreferencedMetasets(){const{_metasets:t,data:{datasets:e}}=this;t.length>e.length&&delete this._stacks,t.forEach(((t,n)=>{0===e.filter((e=>e===t._dataset)).length&&this._destroyDatasetMeta(n)}))}buildOrUpdateControllers(){const t=[],e=this.data.datasets;let n,i;for(this._removeUnreferencedMetasets(),n=0,i=e.length;n<i;n++){const i=e[n];let s=this.getDatasetMeta(n);const o=i.type||this.config.type;if(s.type&&s.type!==o&&(this._destroyDatasetMeta(n),s=this.getDatasetMeta(n)),s.type=o,s.indexAxis=i.indexAxis||Ls(o,this.options),s.order=i.order||0,s.index=n,s.label=""+i.label,s.visible=this.isDatasetVisible(n),s.controller)s.controller.updateIndex(n),s.controller.linkScales();else{const e=Ds.getController(o),{datasetElementType:i,dataElementType:a}=Le.datasets[o];Object.assign(e,{dataElementType:Ds.getElement(a),datasetElementType:i&&Ds.getElement(i)}),s.controller=new e(this,n),t.push(s.controller)}}return this._updateMetasets(),t}_resetElements(){yt(this.data.datasets,((t,e)=>{this.getDatasetMeta(e).controller.reset()}),this)}reset(){this._resetElements(),this.notifyPlugins("reset")}update(t){const e=this.config;e.update();const n=this._options=e.createResolver(e.chartOptionScopes(),this.getContext()),i=this._animationsDisabled=!n.animation;if(this._updateScales(),this._checkEventBindings(),this._updateHiddenIndices(),this._plugins.invalidate(),!1===this.notifyPlugins("beforeUpdate",{mode:t,cancelable:!0}))return;const s=this.buildOrUpdateControllers();this.notifyPlugins("beforeElementsUpdate");let o=0;for(let t=0,e=this.data.datasets.length;t<e;t++){const{controller:e}=this.getDatasetMeta(t),n=!i&&-1===s.indexOf(e);e.buildOrUpdateElements(n),o=Math.max(+e.getMaxOverflow(),o)}o=this._minPadding=n.layout.autoPadding?o:0,this._updateLayout(o),i||yt(s,(t=>{t.reset()})),this._updateDatasets(t),this.notifyPlugins("afterUpdate",{mode:t}),this._layers.sort(Xs("z","_idx"));const{_active:a,_lastEvent:r}=this;r?this._eventHandler(r,!0):a.length&&this._updateHoverStyles(a,a,!0),this.render()}_updateScales(){yt(this.scales,(t=>{Zi.removeBox(this,t)})),this.ensureScalesHaveIDs(),this.buildOrUpdateScales()}_checkEventBindings(){const t=this.options,e=new Set(Object.keys(this._listeners)),n=new Set(t.events);At(e,n)&&!!this._responsiveListeners===t.responsive||(this.unbindEvents(),this.bindEvents())}_updateHiddenIndices(){const{_hiddenIndices:t}=this,e=this._getUniformDataChanges()||[];for(const{method:n,start:i,count:s}of e){to(t,i,"_removeElements"===n?-s:s)}}_getUniformDataChanges(){const t=this._dataChanges;if(!t||!t.length)return;this._dataChanges=[];const e=this.data.datasets.length,n=e=>new Set(t.filter((t=>t[0]===e)).map(((t,e)=>e+","+t.splice(1).join(",")))),i=n(0);for(let t=1;t<e;t++)if(!At(i,n(t)))return;return Array.from(i).map((t=>t.split(","))).map((t=>({method:t[1],start:+t[2],count:+t[3]})))}_updateLayout(t){if(!1===this.notifyPlugins("beforeLayout",{cancelable:!0}))return;Zi.update(this,this.width,this.height,t);const e=this.chartArea,n=e.width<=0||e.height<=0;this._layers=[],yt(this.boxes,(t=>{n&&"chartArea"===t.position||(t.configure&&t.configure(),this._layers.push(...t._layers()))}),this),this._layers.forEach(((t,e)=>{t._idx=e})),this.notifyPlugins("afterLayout")}_updateDatasets(t){if(!1!==this.notifyPlugins("beforeDatasetsUpdate",{mode:t,cancelable:!0})){for(let t=0,e=this.data.datasets.length;t<e;++t)this.getDatasetMeta(t).controller.configure();for(let e=0,n=this.data.datasets.length;e<n;++e)this._updateDataset(e,Et(t)?t({datasetIndex:e}):t);this.notifyPlugins("afterDatasetsUpdate",{mode:t})}}_updateDataset(t,e){const n=this.getDatasetMeta(t),i={meta:n,index:t,mode:e,cancelable:!0};!1!==this.notifyPlugins("beforeDatasetUpdate",i)&&(n.controller._update(e),i.cancelable=!1,this.notifyPlugins("afterDatasetUpdate",i))}render(){!1!==this.notifyPlugins("beforeRender",{cancelable:!0})&&(ti.has(this)?this.attached&&!ti.running(this)&&ti.start(this):(this.draw(),Qs({chart:this})))}draw(){let t;if(this._resizeBeforeDraw){const{width:t,height:e}=this._resizeBeforeDraw;this._resizeBeforeDraw=null,this._resize(t,e)}if(this.clear(),this.width<=0||this.height<=0)return;if(!1===this.notifyPlugins("beforeDraw",{cancelable:!0}))return;const e=this._layers;for(t=0;t<e.length&&e[t].z<=0;++t)e[t].draw(this.chartArea);for(this._drawDatasets();t<e.length;++t)e[t].draw(this.chartArea);this.notifyPlugins("afterDraw")}_getSortedDatasetMetas(t){const e=this._sortedMetasets,n=[];let i,s;for(i=0,s=e.length;i<s;++i){const s=e[i];t&&!s.visible||n.push(s)}return n}getSortedVisibleDatasetMetas(){return this._getSortedDatasetMetas(!0)}_drawDatasets(){if(!1===this.notifyPlugins("beforeDatasetsDraw",{cancelable:!0}))return;const t=this.getSortedVisibleDatasetMetas();for(let e=t.length-1;e>=0;--e)this._drawDataset(t[e]);this.notifyPlugins("afterDatasetsDraw")}_drawDataset(t){const e=this.ctx,n={meta:t,index:t.index,cancelable:!0},i=Gn(this,t);!1!==this.notifyPlugins("beforeDatasetDraw",n)&&(i&&Fe(e,i),t.controller.draw(),i&&qe(e),n.cancelable=!1,this.notifyPlugins("afterDatasetDraw",n))}isPointInArea(t){return $e(t,this.chartArea,this._minPadding)}getElementsAtEventForMode(t,e,n,i){const s=Ri.modes[e];return"function"==typeof s?s(this,t,n,i):[]}getDatasetMeta(t){const e=this.data.datasets[t],n=this._metasets;let i=n.filter((t=>t&&t._dataset===e)).pop();return i||(i={type:null,data:[],dataset:null,controller:null,hidden:null,xAxisID:null,yAxisID:null,order:e&&e.order||0,index:t,_dataset:e,_parsed:[],_sorted:!1},n.push(i)),i}getContext(){return this.$context||(this.$context=sn(null,{chart:this,type:"chart"}))}getVisibleDatasetCount(){return this.getSortedVisibleDatasetMetas().length}isDatasetVisible(t){const e=this.data.datasets[t];if(!e)return!1;const n=this.getDatasetMeta(t);return"boolean"==typeof n.hidden?!n.hidden:!e.hidden}setDatasetVisibility(t,e){this.getDatasetMeta(t).hidden=!e}toggleDataVisibility(t){this._hiddenIndices[t]=!this._hiddenIndices[t]}getDataVisibility(t){return!this._hiddenIndices[t]}_updateVisibility(t,e,n){const i=n?"show":"hide",s=this.getDatasetMeta(t),o=s.controller._resolveAnimations(void 0,i);Pt(e)?(s.data[e].hidden=!n,this.update()):(this.setDatasetVisibility(t,n),o.update(s,{visible:n}),this.update((e=>e.datasetIndex===t?i:void 0)))}hide(t,e){this._updateVisibility(t,e,!1)}show(t,e){this._updateVisibility(t,e,!0)}_destroyDatasetMeta(t){const e=this._metasets[t];e&&e.controller&&e.controller._destroy(),delete this._metasets[t]}_stop(){let t,e;for(this.stop(),ti.remove(this),t=0,e=this.data.datasets.length;t<e;++t)this._destroyDatasetMeta(t)}destroy(){this.notifyPlugins("beforeDestroy");const{canvas:t,ctx:e}=this;this._stop(),this.config.clearCache(),t&&(this.unbindEvents(),We(t,e),this.platform.releaseContext(e),this.canvas=null,this.ctx=null),delete Gs[this.id],this.notifyPlugins("afterDestroy")}toBase64Image(...t){return this.canvas.toDataURL(...t)}bindEvents(){this.bindUserEvents(),this.options.responsive?this.bindResponsiveEvents():this.attached=!0}bindUserEvents(){const t=this._listeners,e=this.platform,n=(n,i)=>{e.addEventListener(this,n,i),t[n]=i},i=(t,e,n)=>{t.offsetX=e,t.offsetY=n,this._eventHandler(t)};yt(this.options.events,(t=>n(t,i)))}bindResponsiveEvents(){this._responsiveListeners||(this._responsiveListeners={});const t=this._responsiveListeners,e=this.platform,n=(n,i)=>{e.addEventListener(this,n,i),t[n]=i},i=(n,i)=>{t[n]&&(e.removeEventListener(this,n,i),delete t[n])},s=(t,e)=>{this.canvas&&this.resize(t,e)};let o;const a=()=>{i("attach",a),this.attached=!0,this.resize(),n("resize",s),n("detach",o)};o=()=>{this.attached=!1,i("resize",s),this._stop(),this._resize(0,0),n("attach",a)},e.isAttached(this.canvas)?a():o()}unbindEvents(){yt(this._listeners,((t,e)=>{this.platform.removeEventListener(this,e,t)})),this._listeners={},yt(this._responsiveListeners,((t,e)=>{this.platform.removeEventListener(this,e,t)})),this._responsiveListeners=void 0}updateHoverStyle(t,e,n){const i=n?"set":"remove";let s,o,a,r;for("dataset"===e&&(s=this.getDatasetMeta(t[0].datasetIndex),s.controller["_"+i+"DatasetHoverStyle"]()),a=0,r=t.length;a<r;++a){o=t[a];const e=o&&this.getDatasetMeta(o.datasetIndex).controller;e&&e[i+"HoverStyle"](o.element,o.datasetIndex,o.index)}}getActiveElements(){return this._active||[]}setActiveElements(t){const e=this._active||[],n=t.map((({datasetIndex:t,index:e})=>{const n=this.getDatasetMeta(t);if(!n)throw new Error("No dataset found at index "+t);return{datasetIndex:t,element:n.data[e],index:e}}));!xt(n,e)&&(this._active=n,this._lastEvent=null,this._updateHoverStyles(n,e))}notifyPlugins(t,e,n){return this._plugins.notify(this,t,e,n)}isPluginEnabled(t){return 1===this._plugins._cache.filter((e=>e.plugin.id===t)).length}_updateHoverStyles(t,e,n){const i=this.options.hover,s=(t,e)=>t.filter((t=>!e.some((e=>t.datasetIndex===e.datasetIndex&&t.index===e.index)))),o=s(e,t),a=n?t:s(t,e);o.length&&this.updateHoverStyle(o,i.mode,!1),a.length&&i.mode&&this.updateHoverStyle(a,i.mode,!0)}_eventHandler(t,e){const n={event:t,replay:e,cancelable:!0,inChartArea:this.isPointInArea(t)},i=e=>(e.options.events||this.options.events).includes(t.native.type);if(!1===this.notifyPlugins("beforeEvent",n,i))return;const s=this._handleEvent(t,e,n.inChartArea);return n.cancelable=!1,this.notifyPlugins("afterEvent",n,i),(s||n.changed)&&this.render(),this}_handleEvent(t,e,n){const{_active:i=[],options:s}=this,o=e,a=this._getActiveElements(t,i,n,o),r=function(t){return"mouseup"===t.type||"click"===t.type||"contextmenu"===t.type}(t),c=function(t,e,n,i){return n&&"mouseout"!==t.type?i?e:t:null}(t,this._lastEvent,n,r);n&&(this._lastEvent=null,bt(s.onHover,[t,a,this],this),r&&bt(s.onClick,[t,a,this],this));const l=!xt(a,i);return(l||e)&&(this._active=a,this._updateHoverStyles(a,i,e)),this._lastEvent=c,l}_getActiveElements(t,e,n,i){if("mouseout"===t.type)return[];if(!n)return e;const s=this.options.hover;return this.getElementsAtEventForMode(t,s.mode,s,i)}}function no(){return yt(eo.instances,(t=>t._plugins.invalidate()))}function io(t,e,n,i){const s=Ze(t.options.borderRadius,["outerStart","outerEnd","innerStart","innerEnd"]);const o=(n-e)/2,a=Math.min(o,i*e/2),r=t=>{const e=(n-Math.min(o,t))*i/2;return te(t,0,Math.min(o,e))};return{outerStart:r(s.outerStart),outerEnd:r(s.outerEnd),innerStart:te(s.innerStart,0,a),innerEnd:te(s.innerEnd,0,a)}}function so(t,e,n,i){return{x:n+t*Math.cos(e),y:i+t*Math.sin(e)}}function oo(t,e,n,i,s,o){const{x:a,y:r,startAngle:c,pixelMargin:l,innerRadius:d}=e,h=Math.max(e.outerRadius+i+n-l,0),u=d>0?d+i+n+l:0;let g=0;const p=s-c;if(i){const t=((d>0?d-i:0)+(h>0?h-i:0))/2;g=(p-(0!==t?p*t/(t+i):p))/2}const m=(p-Math.max(.001,p*h-n/Lt)/h)/2,f=c+m+g,b=s-m-g,{outerStart:y,outerEnd:x,innerStart:v,innerEnd:w}=io(e,u,h,b-f),S=h-y,k=h-x,M=f+y/S,_=b-x/k,C=u+v,T=u+w,D=f+v/C,P=b-w/T;if(t.beginPath(),o){const e=(M+_)/2;if(t.arc(a,r,h,M,e),t.arc(a,r,h,e,_),x>0){const e=so(k,_,a,r);t.arc(e.x,e.y,x,_,b+Nt)}const n=so(T,b,a,r);if(t.lineTo(n.x,n.y),w>0){const e=so(T,P,a,r);t.arc(e.x,e.y,w,b+Nt,P+Math.PI)}const i=(b-w/u+(f+v/u))/2;if(t.arc(a,r,u,b-w/u,i,!0),t.arc(a,r,u,i,f+v/u,!0),v>0){const e=so(C,D,a,r);t.arc(e.x,e.y,v,D+Math.PI,f-Nt)}const s=so(S,f,a,r);if(t.lineTo(s.x,s.y),y>0){const e=so(S,M,a,r);t.arc(e.x,e.y,y,f-Nt,M)}}else{t.moveTo(a,r);const e=Math.cos(M)*h+a,n=Math.sin(M)*h+r;t.lineTo(e,n);const i=Math.cos(_)*h+a,s=Math.sin(_)*h+r;t.lineTo(i,s)}t.closePath()}function ao(t,e,n,i,s){const{fullCircles:o,startAngle:a,circumference:r,options:c}=e,{borderWidth:l,borderJoinStyle:d,borderDash:h,borderDashOffset:u,borderRadius:g}=c,p="inner"===c.borderAlign;if(!l)return;t.setLineDash(h||[]),t.lineDashOffset=u,p?(t.lineWidth=2*l,t.lineJoin=d||"round"):(t.lineWidth=l,t.lineJoin=d||"bevel");let m=e.endAngle;if(o){oo(t,e,n,i,m,s);for(let e=0;e<o;++e)t.stroke();isNaN(r)||(m=a+(r%It||It))}p&&function(t,e,n){const{startAngle:i,pixelMargin:s,x:o,y:a,outerRadius:r,innerRadius:c}=e;let l=s/r;t.beginPath(),t.arc(o,a,r,i-l,n+l),c>s?(l=s/c,t.arc(o,a,c,n+l,i-l,!0)):t.arc(o,a,s,n+Nt,i-Nt),t.closePath(),t.clip()}(t,e,m),c.selfJoin&&m-a>=Lt&&0===g&&"miter"!==d&&function(t,e,n){const{startAngle:i,x:s,y:o,outerRadius:a,innerRadius:r,options:c}=e,{borderWidth:l,borderJoinStyle:d}=c,h=Math.min(l/a,Gt(i-n));if(t.beginPath(),t.arc(s,o,a-l/2,i+h/2,n-h/2),r>0){const e=Math.min(l/r,Gt(i-n));t.arc(s,o,r+l/2,n-e/2,i+e/2,!0)}else{const e=Math.min(l/2,a*Gt(i-n));if("round"===d)t.arc(s,o,e,n-Lt/2,i+Lt/2,!0);else if("bevel"===d){const a=2*e*e,r=-a*Math.cos(n+Lt/2)+s,c=-a*Math.sin(n+Lt/2)+o,l=a*Math.cos(i+Lt/2)+s,d=a*Math.sin(i+Lt/2)+o;t.lineTo(r,c),t.lineTo(l,d)}}t.closePath(),t.moveTo(0,0),t.rect(0,0,t.canvas.width,t.canvas.height),t.clip("evenodd")}(t,e,m),o||(oo(t,e,n,i,m,s),t.stroke())}function ro(t,e,n=e){t.lineCap=mt(n.borderCapStyle,e.borderCapStyle),t.setLineDash(mt(n.borderDash,e.borderDash)),t.lineDashOffset=mt(n.borderDashOffset,e.borderDashOffset),t.lineJoin=mt(n.borderJoinStyle,e.borderJoinStyle),t.lineWidth=mt(n.borderWidth,e.borderWidth),t.strokeStyle=mt(n.borderColor,e.borderColor)}function co(t,e,n){t.lineTo(n.x,n.y)}function lo(t,e,n={}){const i=t.length,{start:s=0,end:o=i-1}=n,{start:a,end:r}=e,c=Math.max(s,a),l=Math.min(o,r),d=s<a&&o<a||s>r&&o>r;return{count:i,start:c,loop:e.loop,ilen:l<c&&!d?i+l-c:l-c}}function ho(t,e,n,i){const{points:s,options:o}=e,{count:a,start:r,loop:c,ilen:l}=lo(s,n,i),d=function(t){return t.stepped?Be:t.tension||"monotone"===t.cubicInterpolationMode?He:co}(o);let h,u,g,{move:p=!0,reverse:m}=i||{};for(h=0;h<=l;++h)u=s[(r+(m?l-h:h))%a],u.skip||(p?(t.moveTo(u.x,u.y),p=!1):d(t,g,u,m,o.stepped),g=u);return c&&(u=s[(r+(m?l:0))%a],d(t,g,u,m,o.stepped)),!!c}function uo(t,e,n,i){const s=e.points,{count:o,start:a,ilen:r}=lo(s,n,i),{move:c=!0,reverse:l}=i||{};let d,h,u,g,p,m,f=0,b=0;const y=t=>(a+(l?r-t:t))%o,x=()=>{g!==p&&(t.lineTo(f,p),t.lineTo(f,g),t.lineTo(f,m))};for(c&&(h=s[y(0)],t.moveTo(h.x,h.y)),d=0;d<=r;++d){if(h=s[y(d)],h.skip)continue;const e=h.x,n=h.y,i=0|e;i===u?(n<g?g=n:n>p&&(p=n),f=(b*f+e)/++b):(x(),t.lineTo(e,n),u=i,b=0,g=p=n),m=n}x()}function go(t){const e=t.options,n=e.borderDash&&e.borderDash.length;return!(t._decimated||t._loop||e.tension||"monotone"===e.cubicInterpolationMode||e.stepped||n)?uo:ho}const po="function"==typeof Path2D;function mo(t,e,n,i){po&&!e.options.segment?function(t,e,n,i){let s=e._path;s||(s=e._path=new Path2D,e.path(s,n,i)&&s.closePath()),ro(t,e.options),t.stroke(s)}(t,e,n,i):function(t,e,n,i){const{segments:s,options:o}=e,a=go(e);for(const r of s)ro(t,o,r.style),t.beginPath(),a(t,e,r,{start:n,end:n+i-1})&&t.closePath(),t.stroke()}(t,e,n,i)}class fo extends ms{static id="line";static defaults={borderCapStyle:"butt",borderDash:[],borderDashOffset:0,borderJoinStyle:"miter",borderWidth:3,capBezierPoints:!0,cubicInterpolationMode:"default",fill:!1,spanGaps:!1,stepped:!1,tension:0};static defaultRoutes={backgroundColor:"backgroundColor",borderColor:"borderColor"};static descriptors={_scriptable:!0,_indexable:t=>"borderDash"!==t&&"fill"!==t};constructor(t){super(),this.animated=!0,this.options=void 0,this._chart=void 0,this._loop=void 0,this._fullLoop=void 0,this._path=void 0,this._points=void 0,this._segments=void 0,this._decimated=!1,this._pointsUpdated=!1,this._datasetIndex=void 0,t&&Object.assign(this,t)}updateControlPoints(t,e){const n=this.options;if((n.tension||"monotone"===n.cubicInterpolationMode)&&!n.stepped&&!this._pointsUpdated){const i=n.spanGaps?this._loop:this._fullLoop;_n(this._points,n,t,i,e),this._pointsUpdated=!0}}set points(t){this._points=t,delete this._segments,delete this._path,this._pointsUpdated=!1}get points(){return this._points}get segments(){return this._segments||(this._segments=function(t,e){const n=t.points,i=t.options.spanGaps,s=n.length;if(!s)return[];const o=!!t._loop,{start:a,end:r}=function(t,e,n,i){let s=0,o=e-1;if(n&&!i)for(;s<e&&!t[s].skip;)s++;for(;s<e&&t[s].skip;)s++;for(s%=e,n&&(o+=s);o>s&&t[o%e].skip;)o--;return o%=e,{start:s,end:o}}(n,s,o,i);return Xn(t,!0===i?[{start:a,end:r,loop:o}]:function(t,e,n,i){const s=t.length,o=[];let a,r=e,c=t[e];for(a=e+1;a<=n;++a){const n=t[a%s];n.skip||n.stop?c.skip||(i=!1,o.push({start:e%s,end:(a-1)%s,loop:i}),e=r=n.stop?a:null):(r=a,c.skip&&(e=a)),c=n}return null!==r&&o.push({start:e%s,end:r%s,loop:i}),o}(n,a,r<a?r+s:r,!!t._fullLoop&&0===a&&r===s-1),n,e)}(this,this.options.segment))}first(){const t=this.segments,e=this.points;return t.length&&e[t[0].start]}last(){const t=this.segments,e=this.points,n=t.length;return n&&e[t[n-1].end]}interpolate(t,e){const n=this.options,i=t[e],s=this.points,o=Un(this,{property:e,start:i,end:i});if(!o.length)return;const a=[],r=function(t){return t.stepped?$n:t.tension||"monotone"===t.cubicInterpolationMode?Fn:Rn}(n);let c,l;for(c=0,l=o.length;c<l;++c){const{start:l,end:d}=o[c],h=s[l],u=s[d];if(h===u){a.push(h);continue}const g=r(h,u,Math.abs((i-h[e])/(u[e]-h[e])),n.stepped);g[e]=t[e],a.push(g)}return 1===a.length?a[0]:a}pathSegment(t,e,n){return go(this)(t,this,e,n)}path(t,e,n){const i=this.segments,s=go(this);let o=this._loop;e=e||0,n=n||this.points.length-e;for(const a of i)o&=s(t,this,a,{start:e,end:e+n-1});return!!o}draw(t,e,n,i){const s=this.options||{};(this.points||[]).length&&s.borderWidth&&(t.save(),mo(t,this,n,i),t.restore()),this.animated&&(this._pointsUpdated=!1,this._path=void 0)}}function bo(t,e,n,i){const s=t.options,{[n]:o}=t.getProps([n],i);return Math.abs(e-o)<s.radius+s.hitRadius}function yo(t,e){const{x:n,y:i,base:s,width:o,height:a}=t.getProps(["x","y","base","width","height"],e);let r,c,l,d,h;return t.horizontal?(h=a/2,r=Math.min(n,s),c=Math.max(n,s),l=i-h,d=i+h):(h=o/2,r=n-h,c=n+h,l=Math.min(i,s),d=Math.max(i,s)),{left:r,top:l,right:c,bottom:d}}function xo(t,e,n,i){return t?0:te(e,n,i)}function vo(t){const e=yo(t),n=e.right-e.left,i=e.bottom-e.top,s=function(t,e,n){const i=t.options.borderWidth,s=t.borderSkipped,o=Ge(i);return{t:xo(s.top,o.top,0,n),r:xo(s.right,o.right,0,e),b:xo(s.bottom,o.bottom,0,n),l:xo(s.left,o.left,0,e)}}(t,n/2,i/2),o=function(t,e,n){const{enableBorderRadius:i}=t.getProps(["enableBorderRadius"]),s=t.options.borderRadius,o=Je(s),a=Math.min(e,n),r=t.borderSkipped,c=i||ut(s);return{topLeft:xo(!c||r.top||r.left,o.topLeft,0,a),topRight:xo(!c||r.top||r.right,o.topRight,0,a),bottomLeft:xo(!c||r.bottom||r.left,o.bottomLeft,0,a),bottomRight:xo(!c||r.bottom||r.right,o.bottomRight,0,a)}}(t,n/2,i/2);return{outer:{x:e.left,y:e.top,w:n,h:i,radius:o},inner:{x:e.left+s.l,y:e.top+s.t,w:n-s.l-s.r,h:i-s.t-s.b,radius:{topLeft:Math.max(0,o.topLeft-Math.max(s.t,s.l)),topRight:Math.max(0,o.topRight-Math.max(s.t,s.r)),bottomLeft:Math.max(0,o.bottomLeft-Math.max(s.b,s.l)),bottomRight:Math.max(0,o.bottomRight-Math.max(s.b,s.r))}}}}function wo(t,e,n,i){const s=null===e,o=null===n,a=t&&!(s&&o)&&yo(t,i);return a&&(s||ee(e,a.left,a.right))&&(o||ee(n,a.top,a.bottom))}function So(t,e){t.rect(e.x,e.y,e.w,e.h)}function ko(t,e,n={}){const i=t.x!==n.x?-e:0,s=t.y!==n.y?-e:0,o=(t.x+t.w!==n.x+n.w?e:0)-i,a=(t.y+t.h!==n.y+n.h?e:0)-s;return{x:t.x+i,y:t.y+s,w:t.w+o,h:t.h+a,radius:t.radius}}class Mo extends ms{static id="bar";static defaults={borderSkipped:"start",borderWidth:0,borderRadius:0,inflateAmount:"auto",pointStyle:void 0};static defaultRoutes={backgroundColor:"backgroundColor",borderColor:"borderColor"};constructor(t){super(),this.options=void 0,this.horizontal=void 0,this.base=void 0,this.width=void 0,this.height=void 0,this.inflateAmount=void 0,t&&Object.assign(this,t)}draw(t){const{inflateAmount:e,options:{borderColor:n,backgroundColor:i}}=this,{inner:s,outer:o}=vo(this),a=(r=o.radius).topLeft||r.topRight||r.bottomLeft||r.bottomRight?Ue:So;var r;t.save(),o.w===s.w&&o.h===s.h||(t.beginPath(),a(t,ko(o,e,s)),t.clip(),a(t,ko(s,-e,o)),t.fillStyle=n,t.fill("evenodd")),t.beginPath(),a(t,ko(s,e)),t.fillStyle=i,t.fill(),t.restore()}inRange(t,e,n){return wo(this,t,e,n)}inXRange(t,e){return wo(this,t,null,e)}inYRange(t,e){return wo(this,null,t,e)}getCenterPoint(t){const{x:e,y:n,base:i,horizontal:s}=this.getProps(["x","y","base","horizontal"],t);return{x:s?(e+i)/2:e,y:s?n:(n+i)/2}}getRange(t){return"x"===t?this.width/2:this.height/2}}var _o=Object.freeze({__proto__:null,ArcElement:class extends ms{static id="arc";static defaults={borderAlign:"center",borderColor:"#fff",borderDash:[],borderDashOffset:0,borderJoinStyle:void 0,borderRadius:0,borderWidth:2,offset:0,spacing:0,angle:void 0,circular:!0,selfJoin:!1};static defaultRoutes={backgroundColor:"backgroundColor"};static descriptors={_scriptable:!0,_indexable:t=>"borderDash"!==t};circumference;endAngle;fullCircles;innerRadius;outerRadius;pixelMargin;startAngle;constructor(t){super(),this.options=void 0,this.circumference=void 0,this.startAngle=void 0,this.endAngle=void 0,this.innerRadius=void 0,this.outerRadius=void 0,this.pixelMargin=0,this.fullCircles=0,t&&Object.assign(this,t)}inRange(t,e,n){const i=this.getProps(["x","y"],n),{angle:s,distance:o}=Qt(i,{x:t,y:e}),{startAngle:a,endAngle:r,innerRadius:c,outerRadius:l,circumference:d}=this.getProps(["startAngle","endAngle","innerRadius","outerRadius","circumference"],n),h=(this.options.spacing+this.options.borderWidth)/2,u=mt(d,r-a),g=Jt(s,a,r)&&a!==r,p=u>=It||g,m=ee(o,c+h,l+h);return p&&m}getCenterPoint(t){const{x:e,y:n,startAngle:i,endAngle:s,innerRadius:o,outerRadius:a}=this.getProps(["x","y","startAngle","endAngle","innerRadius","outerRadius"],t),{offset:r,spacing:c}=this.options,l=(i+s)/2,d=(o+a+c+r)/2;return{x:e+Math.cos(l)*d,y:n+Math.sin(l)*d}}tooltipPosition(t){return this.getCenterPoint(t)}draw(t){const{options:e,circumference:n}=this,i=(e.offset||0)/4,s=(e.spacing||0)/2,o=e.circular;if(this.pixelMargin="inner"===e.borderAlign?.33:0,this.fullCircles=n>It?Math.floor(n/It):0,0===n||this.innerRadius<0||this.outerRadius<0)return;t.save();const a=(this.startAngle+this.endAngle)/2;t.translate(Math.cos(a)*i,Math.sin(a)*i);const r=i*(1-Math.sin(Math.min(Lt,n||0)));t.fillStyle=e.backgroundColor,t.strokeStyle=e.borderColor,function(t,e,n,i,s){const{fullCircles:o,startAngle:a,circumference:r}=e;let c=e.endAngle;if(o){oo(t,e,n,i,c,s);for(let e=0;e<o;++e)t.fill();isNaN(r)||(c=a+(r%It||It))}oo(t,e,n,i,c,s),t.fill()}(t,this,r,s,o),ao(t,this,r,s,o),t.restore()}},BarElement:Mo,LineElement:fo,PointElement:class extends ms{static id="point";parsed;skip;stop;static defaults={borderWidth:1,hitRadius:1,hoverBorderWidth:1,hoverRadius:4,pointStyle:"circle",radius:3,rotation:0};static defaultRoutes={backgroundColor:"backgroundColor",borderColor:"borderColor"};constructor(t){super(),this.options=void 0,this.parsed=void 0,this.skip=void 0,this.stop=void 0,t&&Object.assign(this,t)}inRange(t,e,n){const i=this.options,{x:s,y:o}=this.getProps(["x","y"],n);return Math.pow(t-s,2)+Math.pow(e-o,2)<Math.pow(i.hitRadius+i.radius,2)}inXRange(t,e){return bo(this,t,"x",e)}inYRange(t,e){return bo(this,t,"y",e)}getCenterPoint(t){const{x:e,y:n}=this.getProps(["x","y"],t);return{x:e,y:n}}size(t){let e=(t=t||this.options||{}).radius||0;e=Math.max(e,e&&t.hoverRadius||0);return 2*(e+(e&&t.borderWidth||0))}draw(t,e){const n=this.options;this.skip||n.radius<.1||!$e(this,e,this.size(n)/2)||(t.strokeStyle=n.borderColor,t.lineWidth=n.borderWidth,t.fillStyle=n.backgroundColor,Ne(t,n,this.x,this.y))}getRange(){const t=this.options||{};return t.radius+t.hitRadius}}});const Co=["rgb(54, 162, 235)","rgb(255, 99, 132)","rgb(255, 159, 64)","rgb(255, 205, 86)","rgb(75, 192, 192)","rgb(153, 102, 255)","rgb(201, 203, 207)"],To=Co.map((t=>t.replace("rgb(","rgba(").replace(")",", 0.5)")));function Do(t){return Co[t%Co.length]}function Po(t){return To[t%To.length]}function Eo(t){let e=0;return(n,i)=>{const s=t.getDatasetMeta(i).controller;s instanceof Ci?e=function(t,e){return t.backgroundColor=t.data.map((()=>Do(e++))),e}(n,e):s instanceof Ti?e=function(t,e){return t.backgroundColor=t.data.map((()=>Po(e++))),e}(n,e):s&&(e=function(t,e){return t.borderColor=Do(e),t.backgroundColor=Po(e),++e}(n,e))}}function Ao(t){let e;for(e in t)if(t[e].borderColor||t[e].backgroundColor)return!0;return!1}var Lo={id:"colors",defaults:{enabled:!0,forceOverride:!1},beforeLayout(t,e,n){if(!n.enabled)return;const{data:{datasets:i},options:s}=t.config,{elements:o}=s,a=Ao(i)||(r=s)&&(r.borderColor||r.backgroundColor)||o&&Ao(o)||"rgba(0,0,0,0.1)"!==Le.borderColor||"rgba(0,0,0,0.1)"!==Le.backgroundColor;var r;if(!n.forceOverride&&a)return;const c=Eo(t);i.forEach(c)}};function Io(t){if(t._decimated){const e=t._data;delete t._decimated,delete t._data,Object.defineProperty(t,"data",{configurable:!0,enumerable:!0,writable:!0,value:e})}}function Oo(t){t.data.datasets.forEach((t=>{Io(t)}))}var zo={id:"decimation",defaults:{algorithm:"min-max",enabled:!1},beforeElementsUpdate:(t,e,n)=>{if(!n.enabled)return void Oo(t);const i=t.width;t.data.datasets.forEach(((e,s)=>{const{_data:o,indexAxis:a}=e,r=t.getDatasetMeta(s),c=o||e.data;if("y"===nn([a,t.options.indexAxis]))return;if(!r.controller.supportsDecimation)return;const l=t.scales[r.xAxisID];if("linear"!==l.type&&"time"!==l.type)return;if(t.options.parsing)return;let{start:d,count:h}=function(t,e){const n=e.length;let i,s=0;const{iScale:o}=t,{min:a,max:r,minDefined:c,maxDefined:l}=o.getUserBounds();return c&&(s=te(ie(e,o.axis,a).lo,0,n-1)),i=l?te(ie(e,o.axis,r).hi+1,s,n)-s:n-s,{start:s,count:i}}(r,c);if(h<=(n.threshold||4*i))return void Io(e);let u;switch(dt(o)&&(e._data=c,delete e.data,Object.defineProperty(e,"data",{configurable:!0,enumerable:!0,get:function(){return this._decimated},set:function(t){this._data=t}})),n.algorithm){case"lttb":u=function(t,e,n,i,s){const o=s.samples||i;if(o>=n)return t.slice(e,e+n);const a=[],r=(n-2)/(o-2);let c=0;const l=e+n-1;let d,h,u,g,p,m=e;for(a[c++]=t[m],d=0;d<o-2;d++){let i,s=0,o=0;const l=Math.floor((d+1)*r)+1+e,f=Math.min(Math.floor((d+2)*r)+1,n)+e,b=f-l;for(i=l;i<f;i++)s+=t[i].x,o+=t[i].y;s/=b,o/=b;const y=Math.floor(d*r)+1+e,x=Math.min(Math.floor((d+1)*r)+1,n)+e,{x:v,y:w}=t[m];for(u=g=-1,i=y;i<x;i++)g=.5*Math.abs((v-s)*(t[i].y-w)-(v-t[i].x)*(o-w)),g>u&&(u=g,h=t[i],p=i);a[c++]=h,m=p}return a[c++]=t[l],a}(c,d,h,i,n);break;case"min-max":u=function(t,e,n,i){let s,o,a,r,c,l,d,h,u,g,p=0,m=0;const f=[],b=e+n-1,y=t[e].x,x=t[b].x-y;for(s=e;s<e+n;++s){o=t[s],a=(o.x-y)/x*i,r=o.y;const e=0|a;if(e===c)r<u?(u=r,l=s):r>g&&(g=r,d=s),p=(m*p+o.x)/++m;else{const n=s-1;if(!dt(l)&&!dt(d)){const e=Math.min(l,d),i=Math.max(l,d);e!==h&&e!==n&&f.push({...t[e],x:p}),i!==h&&i!==n&&f.push({...t[i],x:p})}s>0&&n!==h&&f.push(t[n]),f.push(o),c=e,m=0,u=g=r,l=d=h=s}}return f}(c,d,h,i);break;default:throw new Error(`Unsupported decimation algorithm '${n.algorithm}'`)}e._decimated=u}))},destroy(t){Oo(t)}};function Wo(t,e,n,i){if(i)return;let s=e[t],o=n[t];return"angle"===t&&(s=Gt(s),o=Gt(o)),{property:t,start:s,end:o}}function No(t,e,n){for(;e>t;e--){const t=n[e];if(!isNaN(t.x)&&!isNaN(t.y))break}return e}function Ro(t,e,n,i){return t&&e?i(t[n],e[n]):t?t[n]:e?e[n]:0}function $o(t,e){let n=[],i=!1;return ht(t)?(i=!0,n=t):n=function(t,e){const{x:n=null,y:i=null}=t||{},s=e.points,o=[];return e.segments.forEach((({start:t,end:e})=>{e=No(t,e,s);const a=s[t],r=s[e];null!==i?(o.push({x:a.x,y:i}),o.push({x:r.x,y:i})):null!==n&&(o.push({x:n,y:a.y}),o.push({x:n,y:r.y}))})),o}(t,e),n.length?new fo({points:n,options:{tension:0},_loop:i,_fullLoop:i}):null}function Fo(t){return t&&!1!==t.fill}function qo(t,e,n){let i=t[e].fill;const s=[e];let o;if(!n)return i;for(;!1!==i&&-1===s.indexOf(i);){if(!gt(i))return i;if(o=t[i],!o)return!1;if(o.visible)return i;s.push(i),i=o.fill}return!1}function Bo(t,e,n){const i=function(t){const e=t.options,n=e.fill;let i=mt(n&&n.target,n);void 0===i&&(i=!!e.backgroundColor);if(!1===i||null===i)return!1;if(!0===i)return"origin";return i}(t);if(ut(i))return!isNaN(i.value)&&i;let s=parseFloat(i);return gt(s)&&Math.floor(s)===s?function(t,e,n,i){"-"!==t&&"+"!==t||(n=e+n);if(n===e||n<0||n>=i)return!1;return n}(i[0],e,s,n):["origin","start","end","stack","shape"].indexOf(i)>=0&&i}function Ho(t,e,n){const i=[];for(let s=0;s<n.length;s++){const o=n[s],{first:a,last:r,point:c}=Vo(o,e,"x");if(!(!c||a&&r))if(a)i.unshift(c);else if(t.push(c),!r)break}t.push(...i)}function Vo(t,e,n){const i=t.interpolate(e,n);if(!i)return{};const s=i[n],o=t.segments,a=t.points;let r=!1,c=!1;for(let t=0;t<o.length;t++){const e=o[t],i=a[e.start][n],l=a[e.end][n];if(ee(s,i,l)){r=s===i,c=s===l;break}}return{first:r,last:c,point:i}}class jo{constructor(t){this.x=t.x,this.y=t.y,this.radius=t.radius}pathSegment(t,e,n){const{x:i,y:s,radius:o}=this;return e=e||{start:0,end:It},t.arc(i,s,o,e.end,e.start,!0),!n.bounds}interpolate(t){const{x:e,y:n,radius:i}=this,s=t.angle;return{x:e+Math.cos(s)*i,y:n+Math.sin(s)*i,angle:s}}}function Yo(t){const{chart:e,fill:n,line:i}=t;if(gt(n))return function(t,e){const n=t.getDatasetMeta(e),i=n&&t.isDatasetVisible(e);return i?n.dataset:null}(e,n);if("stack"===n)return function(t){const{scale:e,index:n,line:i}=t,s=[],o=i.segments,a=i.points,r=function(t,e){const n=[],i=t.getMatchingVisibleMetas("line");for(let t=0;t<i.length;t++){const s=i[t];if(s.index===e)break;s.hidden||n.unshift(s.dataset)}return n}(e,n);r.push($o({x:null,y:e.bottom},i));for(let t=0;t<o.length;t++){const e=o[t];for(let t=e.start;t<=e.end;t++)Ho(s,a[t],r)}return new fo({points:s,options:{}})}(t);if("shape"===n)return!0;const s=function(t){const e=t.scale||{};if(e.getPointPositionForValue)return function(t){const{scale:e,fill:n}=t,i=e.options,s=e.getLabels().length,o=i.reverse?e.max:e.min,a=function(t,e,n){let i;return i="start"===t?n:"end"===t?e.options.reverse?e.min:e.max:ut(t)?t.value:e.getBaseValue(),i}(n,e,o),r=[];if(i.grid.circular){const t=e.getPointPositionForValue(0,o);return new jo({x:t.x,y:t.y,radius:e.getDistanceFromCenterForValue(a)})}for(let t=0;t<s;++t)r.push(e.getPointPositionForValue(t,a));return r}(t);return function(t){const{scale:e={},fill:n}=t,i=function(t,e){let n=null;return"start"===t?n=e.bottom:"end"===t?n=e.top:ut(t)?n=e.getPixelForValue(t.value):e.getBasePixel&&(n=e.getBasePixel()),n}(n,e);if(gt(i)){const t=e.isHorizontal();return{x:t?i:null,y:t?null:i}}return null}(t)}(t);return s instanceof jo?s:$o(s,i)}function Uo(t,e,n){const i=Yo(e),{chart:s,index:o,line:a,scale:r,axis:c}=e,l=a.options,d=l.fill,h=l.backgroundColor,{above:u=h,below:g=h}=d||{},p=s.getDatasetMeta(o),m=Gn(s,p);i&&a.points.length&&(Fe(t,n),function(t,e){const{line:n,target:i,above:s,below:o,area:a,scale:r,clip:c}=e,l=n._loop?"angle":e.axis;t.save();let d=o;o!==s&&("x"===l?(Xo(t,i,a.top),Ko(t,{line:n,target:i,color:s,scale:r,property:l,clip:c}),t.restore(),t.save(),Xo(t,i,a.bottom)):"y"===l&&(Qo(t,i,a.left),Ko(t,{line:n,target:i,color:o,scale:r,property:l,clip:c}),t.restore(),t.save(),Qo(t,i,a.right),d=s));Ko(t,{line:n,target:i,color:d,scale:r,property:l,clip:c}),t.restore()}(t,{line:a,target:i,above:u,below:g,area:n,scale:r,axis:c,clip:m}),qe(t))}function Xo(t,e,n){const{segments:i,points:s}=e;let o=!0,a=!1;t.beginPath();for(const r of i){const{start:i,end:c}=r,l=s[i],d=s[No(i,c,s)];o?(t.moveTo(l.x,l.y),o=!1):(t.lineTo(l.x,n),t.lineTo(l.x,l.y)),a=!!e.pathSegment(t,r,{move:a}),a?t.closePath():t.lineTo(d.x,n)}t.lineTo(e.first().x,n),t.closePath(),t.clip()}function Qo(t,e,n){const{segments:i,points:s}=e;let o=!0,a=!1;t.beginPath();for(const r of i){const{start:i,end:c}=r,l=s[i],d=s[No(i,c,s)];o?(t.moveTo(l.x,l.y),o=!1):(t.lineTo(n,l.y),t.lineTo(l.x,l.y)),a=!!e.pathSegment(t,r,{move:a}),a?t.closePath():t.lineTo(n,d.y)}t.lineTo(n,e.first().y),t.closePath(),t.clip()}function Ko(t,e){const{line:n,target:i,property:s,color:o,scale:a,clip:r}=e,c=function(t,e,n){const i=t.segments,s=t.points,o=e.points,a=[];for(const t of i){let{start:i,end:r}=t;r=No(i,r,s);const c=Wo(n,s[i],s[r],t.loop);if(!e.segments){a.push({source:t,target:c,start:s[i],end:s[r]});continue}const l=Un(e,c);for(const e of l){const i=Wo(n,o[e.start],o[e.end],e.loop),r=Yn(t,s,i);for(const t of r)a.push({source:t,target:e,start:{[n]:Ro(c,i,"start",Math.max)},end:{[n]:Ro(c,i,"end",Math.min)}})}}return a}(n,i,s);for(const{source:e,target:l,start:d,end:h}of c){const{style:{backgroundColor:c=o}={}}=e,u=!0!==i;t.save(),t.fillStyle=c,Zo(t,a,r,u&&Wo(s,d,h)),t.beginPath();const g=!!n.pathSegment(t,e);let p;if(u){g?t.closePath():Go(t,i,h,s);const e=!!i.pathSegment(t,l,{move:g,reverse:!0});p=g&&e,p||Go(t,i,d,s)}t.closePath(),t.fill(p?"evenodd":"nonzero"),t.restore()}}function Zo(t,e,n,i){const s=e.chart.chartArea,{property:o,start:a,end:r}=i||{};if("x"===o||"y"===o){let e,i,c,l;"x"===o?(e=a,i=s.top,c=r,l=s.bottom):(e=s.left,i=a,c=s.right,l=r),t.beginPath(),n&&(e=Math.max(e,n.left),c=Math.min(c,n.right),i=Math.max(i,n.top),l=Math.min(l,n.bottom)),t.rect(e,i,c-e,l-i),t.clip()}}function Go(t,e,n,i){const s=e.interpolate(n,i);s&&t.lineTo(s.x,s.y)}var Jo={id:"filler",afterDatasetsUpdate(t,e,n){const i=(t.data.datasets||[]).length,s=[];let o,a,r,c;for(a=0;a<i;++a)o=t.getDatasetMeta(a),r=o.dataset,c=null,r&&r.options&&r instanceof fo&&(c={visible:t.isDatasetVisible(a),index:a,fill:Bo(r,a,i),chart:t,axis:o.controller.options.indexAxis,scale:o.vScale,line:r}),o.$filler=c,s.push(c);for(a=0;a<i;++a)c=s[a],c&&!1!==c.fill&&(c.fill=qo(s,a,n.propagate))},beforeDraw(t,e,n){const i="beforeDraw"===n.drawTime,s=t.getSortedVisibleDatasetMetas(),o=t.chartArea;for(let e=s.length-1;e>=0;--e){const n=s[e].$filler;n&&(n.line.updateControlPoints(o,n.axis),i&&n.fill&&Uo(t.ctx,n,o))}},beforeDatasetsDraw(t,e,n){if("beforeDatasetsDraw"!==n.drawTime)return;const i=t.getSortedVisibleDatasetMetas();for(let e=i.length-1;e>=0;--e){const n=i[e].$filler;Fo(n)&&Uo(t.ctx,n,t.chartArea)}},beforeDatasetDraw(t,e,n){const i=e.meta.$filler;Fo(i)&&"beforeDatasetDraw"===n.drawTime&&Uo(t.ctx,i,t.chartArea)},defaults:{propagate:!0,drawTime:"beforeDatasetDraw"}};const ta=(t,e)=>{let{boxHeight:n=e,boxWidth:i=e}=t;return t.usePointStyle&&(n=Math.min(n,e),i=t.pointStyleWidth||Math.min(i,e)),{boxWidth:i,boxHeight:n,itemHeight:Math.max(e,n)}};class ea extends ms{constructor(t){super(),this._added=!1,this.legendHitBoxes=[],this._hoveredItem=null,this.doughnutMode=!1,this.chart=t.chart,this.options=t.options,this.ctx=t.ctx,this.legendItems=void 0,this.columnSizes=void 0,this.lineWidths=void 0,this.maxHeight=void 0,this.maxWidth=void 0,this.top=void 0,this.bottom=void 0,this.left=void 0,this.right=void 0,this.height=void 0,this.width=void 0,this._margins=void 0,this.position=void 0,this.weight=void 0,this.fullSize=void 0}update(t,e,n){this.maxWidth=t,this.maxHeight=e,this._margins=n,this.setDimensions(),this.buildLabels(),this.fit()}setDimensions(){this.isHorizontal()?(this.width=this.maxWidth,this.left=this._margins.left,this.right=this.width):(this.height=this.maxHeight,this.top=this._margins.top,this.bottom=this.height)}buildLabels(){const t=this.options.labels||{};let e=bt(t.generateLabels,[this.chart],this)||[];t.filter&&(e=e.filter((e=>t.filter(e,this.chart.data)))),t.sort&&(e=e.sort(((e,n)=>t.sort(e,n,this.chart.data)))),this.options.reverse&&e.reverse(),this.legendItems=e}fit(){const{options:t,ctx:e}=this;if(!t.display)return void(this.width=this.height=0);const n=t.labels,i=en(n.font),s=i.size,o=this._computeTitleHeight(),{boxWidth:a,itemHeight:r}=ta(n,s);let c,l;e.font=i.string,this.isHorizontal()?(c=this.maxWidth,l=this._fitRows(o,s,a,r)+10):(l=this.maxHeight,c=this._fitCols(o,i,a,r)+10),this.width=Math.min(c,t.maxWidth||this.maxWidth),this.height=Math.min(l,t.maxHeight||this.maxHeight)}_fitRows(t,e,n,i){const{ctx:s,maxWidth:o,options:{labels:{padding:a}}}=this,r=this.legendHitBoxes=[],c=this.lineWidths=[0],l=i+a;let d=t;s.textAlign="left",s.textBaseline="middle";let h=-1,u=-l;return this.legendItems.forEach(((t,g)=>{const p=n+e/2+s.measureText(t.text).width;(0===g||c[c.length-1]+p+2*a>o)&&(d+=l,c[c.length-(g>0?0:1)]=0,u+=l,h++),r[g]={left:0,top:u,row:h,width:p,height:i},c[c.length-1]+=p+a})),d}_fitCols(t,e,n,i){const{ctx:s,maxHeight:o,options:{labels:{padding:a}}}=this,r=this.legendHitBoxes=[],c=this.columnSizes=[],l=o-t;let d=a,h=0,u=0,g=0,p=0;return this.legendItems.forEach(((t,o)=>{const{itemWidth:m,itemHeight:f}=function(t,e,n,i,s){const o=function(t,e,n,i){let s=t.text;s&&"string"!=typeof s&&(s=s.reduce(((t,e)=>t.length>e.length?t:e)));return e+n.size/2+i.measureText(s).width}(i,t,e,n),a=function(t,e,n){let i=t;"string"!=typeof e.text&&(i=na(e,n));return i}(s,i,e.lineHeight);return{itemWidth:o,itemHeight:a}}(n,e,s,t,i);o>0&&u+f+2*a>l&&(d+=h+a,c.push({width:h,height:u}),g+=h+a,p++,h=u=0),r[o]={left:g,top:u,col:p,width:m,height:f},h=Math.max(h,m),u+=f+a})),d+=h,c.push({width:h,height:u}),d}adjustHitBoxes(){if(!this.options.display)return;const t=this._computeTitleHeight(),{legendHitBoxes:e,options:{align:n,labels:{padding:i},rtl:s}}=this,o=qn(s,this.left,this.width);if(this.isHorizontal()){let s=0,a=he(n,this.left+i,this.right-this.lineWidths[s]);for(const r of e)s!==r.row&&(s=r.row,a=he(n,this.left+i,this.right-this.lineWidths[s])),r.top+=this.top+t+i,r.left=o.leftForLtr(o.x(a),r.width),a+=r.width+i}else{let s=0,a=he(n,this.top+t+i,this.bottom-this.columnSizes[s].height);for(const r of e)r.col!==s&&(s=r.col,a=he(n,this.top+t+i,this.bottom-this.columnSizes[s].height)),r.top=a,r.left+=this.left+i,r.left=o.leftForLtr(o.x(r.left),r.width),a+=r.height+i}}isHorizontal(){return"top"===this.options.position||"bottom"===this.options.position}draw(){if(this.options.display){const t=this.ctx;Fe(t,this),this._draw(),qe(t)}}_draw(){const{options:t,columnSizes:e,lineWidths:n,ctx:i}=this,{align:s,labels:o}=t,a=Le.color,r=qn(t.rtl,this.left,this.width),c=en(o.font),{padding:l}=o,d=c.size,h=d/2;let u;this.drawTitle(),i.textAlign=r.textAlign("left"),i.textBaseline="middle",i.lineWidth=.5,i.font=c.string;const{boxWidth:g,boxHeight:p,itemHeight:m}=ta(o,d),f=this.isHorizontal(),b=this._computeTitleHeight();u=f?{x:he(s,this.left+l,this.right-n[0]),y:this.top+l+b,line:0}:{x:this.left+l,y:he(s,this.top+b+l,this.bottom-e[0].height),line:0},Bn(this.ctx,t.textDirection);const y=m+l;this.legendItems.forEach(((x,v)=>{i.strokeStyle=x.fontColor,i.fillStyle=x.fontColor;const w=i.measureText(x.text).width,S=r.textAlign(x.textAlign||(x.textAlign=o.textAlign)),k=g+h+w;let M=u.x,_=u.y;r.setWidth(this.width),f?v>0&&M+k+l>this.right&&(_=u.y+=y,u.line++,M=u.x=he(s,this.left+l,this.right-n[u.line])):v>0&&_+y>this.bottom&&(M=u.x=M+e[u.line].width+l,u.line++,_=u.y=he(s,this.top+b+l,this.bottom-e[u.line].height));if(function(t,e,n){if(isNaN(g)||g<=0||isNaN(p)||p<0)return;i.save();const s=mt(n.lineWidth,1);if(i.fillStyle=mt(n.fillStyle,a),i.lineCap=mt(n.lineCap,"butt"),i.lineDashOffset=mt(n.lineDashOffset,0),i.lineJoin=mt(n.lineJoin,"miter"),i.lineWidth=s,i.strokeStyle=mt(n.strokeStyle,a),i.setLineDash(mt(n.lineDash,[])),o.usePointStyle){const a={radius:p*Math.SQRT2/2,pointStyle:n.pointStyle,rotation:n.rotation,borderWidth:s},c=r.xPlus(t,g/2);Re(i,a,c,e+h,o.pointStyleWidth&&g)}else{const o=e+Math.max((d-p)/2,0),a=r.leftForLtr(t,g),c=Je(n.borderRadius);i.beginPath(),Object.values(c).some((t=>0!==t))?Ue(i,{x:a,y:o,w:g,h:p,radius:c}):i.rect(a,o,g,p),i.fill(),0!==s&&i.stroke()}i.restore()}(r.x(M),_,x),M=((t,e,n,i)=>t===(i?"left":"right")?n:"center"===t?(e+n)/2:e)(S,M+g+h,f?M+k:this.right,t.rtl),function(t,e,n){Ye(i,n.text,t,e+m/2,c,{strikethrough:n.hidden,textAlign:r.textAlign(n.textAlign)})}(r.x(M),_,x),f)u.x+=k+l;else if("string"!=typeof x.text){const t=c.lineHeight;u.y+=na(x,t)+l}else u.y+=y})),Hn(this.ctx,t.textDirection)}drawTitle(){const t=this.options,e=t.title,n=en(e.font),i=tn(e.padding);if(!e.display)return;const s=qn(t.rtl,this.left,this.width),o=this.ctx,a=e.position,r=n.size/2,c=i.top+r;let l,d=this.left,h=this.width;if(this.isHorizontal())h=Math.max(...this.lineWidths),l=this.top+c,d=he(t.align,d,this.right-h);else{const e=this.columnSizes.reduce(((t,e)=>Math.max(t,e.height)),0);l=c+he(t.align,this.top,this.bottom-e-t.labels.padding-this._computeTitleHeight())}const u=he(a,d,d+h);o.textAlign=s.textAlign(de(a)),o.textBaseline="middle",o.strokeStyle=e.color,o.fillStyle=e.color,o.font=n.string,Ye(o,e.text,u,l,n)}_computeTitleHeight(){const t=this.options.title,e=en(t.font),n=tn(t.padding);return t.display?e.lineHeight+n.height:0}_getLegendItemAt(t,e){let n,i,s;if(ee(t,this.left,this.right)&&ee(e,this.top,this.bottom))for(s=this.legendHitBoxes,n=0;n<s.length;++n)if(i=s[n],ee(t,i.left,i.left+i.width)&&ee(e,i.top,i.top+i.height))return this.legendItems[n];return null}handleEvent(t){const e=this.options;if(!function(t,e){if(("mousemove"===t||"mouseout"===t)&&(e.onHover||e.onLeave))return!0;if(e.onClick&&("click"===t||"mouseup"===t))return!0;return!1}(t.type,e))return;const n=this._getLegendItemAt(t.x,t.y);if("mousemove"===t.type||"mouseout"===t.type){const o=this._hoveredItem,a=(s=n,null!==(i=o)&&null!==s&&i.datasetIndex===s.datasetIndex&&i.index===s.index);o&&!a&&bt(e.onLeave,[t,o,this],this),this._hoveredItem=n,n&&!a&&bt(e.onHover,[t,n,this],this)}else n&&bt(e.onClick,[t,n,this],this);var i,s}}function na(t,e){return e*(t.text?t.text.length:0)}var ia={id:"legend",_element:ea,start(t,e,n){const i=t.legend=new ea({ctx:t.ctx,options:n,chart:t});Zi.configure(t,i,n),Zi.addBox(t,i)},stop(t){Zi.removeBox(t,t.legend),delete t.legend},beforeUpdate(t,e,n){const i=t.legend;Zi.configure(t,i,n),i.options=n},afterUpdate(t){const e=t.legend;e.buildLabels(),e.adjustHitBoxes()},afterEvent(t,e){e.replay||t.legend.handleEvent(e.event)},defaults:{display:!0,position:"top",align:"center",fullSize:!0,reverse:!1,weight:1e3,onClick(t,e,n){const i=e.datasetIndex,s=n.chart;s.isDatasetVisible(i)?(s.hide(i),e.hidden=!0):(s.show(i),e.hidden=!1)},onHover:null,onLeave:null,labels:{color:t=>t.chart.options.color,boxWidth:40,padding:10,generateLabels(t){const e=t.data.datasets,{labels:{usePointStyle:n,pointStyle:i,textAlign:s,color:o,useBorderRadius:a,borderRadius:r}}=t.legend.options;return t._getSortedDatasetMetas().map((t=>{const c=t.controller.getStyle(n?0:void 0),l=tn(c.borderWidth);return{text:e[t.index].label,fillStyle:c.backgroundColor,fontColor:o,hidden:!t.visible,lineCap:c.borderCapStyle,lineDash:c.borderDash,lineDashOffset:c.borderDashOffset,lineJoin:c.borderJoinStyle,lineWidth:(l.width+l.height)/4,strokeStyle:c.borderColor,pointStyle:i||c.pointStyle,rotation:c.rotation,textAlign:s||c.textAlign,borderRadius:a&&(r||c.borderRadius),datasetIndex:t.index}}),this)}},title:{color:t=>t.chart.options.color,display:!1,position:"center",text:""}},descriptors:{_scriptable:t=>!t.startsWith("on"),labels:{_scriptable:t=>!["generateLabels","filter","sort"].includes(t)}}};class sa extends ms{constructor(t){super(),this.chart=t.chart,this.options=t.options,this.ctx=t.ctx,this._padding=void 0,this.top=void 0,this.bottom=void 0,this.left=void 0,this.right=void 0,this.width=void 0,this.height=void 0,this.position=void 0,this.weight=void 0,this.fullSize=void 0}update(t,e){const n=this.options;if(this.left=0,this.top=0,!n.display)return void(this.width=this.height=this.right=this.bottom=0);this.width=this.right=t,this.height=this.bottom=e;const i=ht(n.text)?n.text.length:1;this._padding=tn(n.padding);const s=i*en(n.font).lineHeight+this._padding.height;this.isHorizontal()?this.height=s:this.width=s}isHorizontal(){const t=this.options.position;return"top"===t||"bottom"===t}_drawArgs(t){const{top:e,left:n,bottom:i,right:s,options:o}=this,a=o.align;let r,c,l,d=0;return this.isHorizontal()?(c=he(a,n,s),l=e+t,r=s-n):("left"===o.position?(c=n+t,l=he(a,i,e),d=-.5*Lt):(c=s-t,l=he(a,e,i),d=.5*Lt),r=i-e),{titleX:c,titleY:l,maxWidth:r,rotation:d}}draw(){const t=this.ctx,e=this.options;if(!e.display)return;const n=en(e.font),i=n.lineHeight/2+this._padding.top,{titleX:s,titleY:o,maxWidth:a,rotation:r}=this._drawArgs(i);Ye(t,e.text,0,0,n,{color:e.color,maxWidth:a,rotation:r,textAlign:de(e.align),textBaseline:"middle",translation:[s,o]})}}var oa={id:"title",_element:sa,start(t,e,n){!function(t,e){const n=new sa({ctx:t.ctx,options:e,chart:t});Zi.configure(t,n,e),Zi.addBox(t,n),t.titleBlock=n}(t,n)},stop(t){const e=t.titleBlock;Zi.removeBox(t,e),delete t.titleBlock},beforeUpdate(t,e,n){const i=t.titleBlock;Zi.configure(t,i,n),i.options=n},defaults:{align:"center",display:!1,font:{weight:"bold"},fullSize:!0,padding:10,position:"top",text:"",weight:2e3},defaultRoutes:{color:"color"},descriptors:{_scriptable:!0,_indexable:!1}};const aa=new WeakMap;var ra={id:"subtitle",start(t,e,n){const i=new sa({ctx:t.ctx,options:n,chart:t});Zi.configure(t,i,n),Zi.addBox(t,i),aa.set(t,i)},stop(t){Zi.removeBox(t,aa.get(t)),aa.delete(t)},beforeUpdate(t,e,n){const i=aa.get(t);Zi.configure(t,i,n),i.options=n},defaults:{align:"center",display:!1,font:{weight:"normal"},fullSize:!0,padding:0,position:"top",text:"",weight:1500},defaultRoutes:{color:"color"},descriptors:{_scriptable:!0,_indexable:!1}};const ca={average(t){if(!t.length)return!1;let e,n,i=new Set,s=0,o=0;for(e=0,n=t.length;e<n;++e){const n=t[e].element;if(n&&n.hasValue()){const t=n.tooltipPosition();i.add(t.x),s+=t.y,++o}}if(0===o||0===i.size)return!1;return{x:[...i].reduce(((t,e)=>t+e))/i.size,y:s/o}},nearest(t,e){if(!t.length)return!1;let n,i,s,o=e.x,a=e.y,r=Number.POSITIVE_INFINITY;for(n=0,i=t.length;n<i;++n){const i=t[n].element;if(i&&i.hasValue()){const t=Kt(e,i.getCenterPoint());t<r&&(r=t,s=i)}}if(s){const t=s.tooltipPosition();o=t.x,a=t.y}return{x:o,y:a}}};function la(t,e){return e&&(ht(e)?Array.prototype.push.apply(t,e):t.push(e)),t}function da(t){return("string"==typeof t||t instanceof String)&&t.indexOf("\n")>-1?t.split("\n"):t}function ha(t,e){const{element:n,datasetIndex:i,index:s}=e,o=t.getDatasetMeta(i).controller,{label:a,value:r}=o.getLabelAndValue(s);return{chart:t,label:a,parsed:o.getParsed(s),raw:t.data.datasets[i].data[s],formattedValue:r,dataset:o.getDataset(),dataIndex:s,datasetIndex:i,element:n}}function ua(t,e){const n=t.chart.ctx,{body:i,footer:s,title:o}=t,{boxWidth:a,boxHeight:r}=e,c=en(e.bodyFont),l=en(e.titleFont),d=en(e.footerFont),h=o.length,u=s.length,g=i.length,p=tn(e.padding);let m=p.height,f=0,b=i.reduce(((t,e)=>t+e.before.length+e.lines.length+e.after.length),0);if(b+=t.beforeBody.length+t.afterBody.length,h&&(m+=h*l.lineHeight+(h-1)*e.titleSpacing+e.titleMarginBottom),b){m+=g*(e.displayColors?Math.max(r,c.lineHeight):c.lineHeight)+(b-g)*c.lineHeight+(b-1)*e.bodySpacing}u&&(m+=e.footerMarginTop+u*d.lineHeight+(u-1)*e.footerSpacing);let y=0;const x=function(t){f=Math.max(f,n.measureText(t).width+y)};return n.save(),n.font=l.string,yt(t.title,x),n.font=c.string,yt(t.beforeBody.concat(t.afterBody),x),y=e.displayColors?a+2+e.boxPadding:0,yt(i,(t=>{yt(t.before,x),yt(t.lines,x),yt(t.after,x)})),y=0,n.font=d.string,yt(t.footer,x),n.restore(),f+=p.width,{width:f,height:m}}function ga(t,e,n,i){const{x:s,width:o}=n,{width:a,chartArea:{left:r,right:c}}=t;let l="center";return"center"===i?l=s<=(r+c)/2?"left":"right":s<=o/2?l="left":s>=a-o/2&&(l="right"),function(t,e,n,i){const{x:s,width:o}=i,a=n.caretSize+n.caretPadding;return"left"===t&&s+o+a>e.width||"right"===t&&s-o-a<0||void 0}(l,t,e,n)&&(l="center"),l}function pa(t,e,n){const i=n.yAlign||e.yAlign||function(t,e){const{y:n,height:i}=e;return n<i/2?"top":n>t.height-i/2?"bottom":"center"}(t,n);return{xAlign:n.xAlign||e.xAlign||ga(t,e,n,i),yAlign:i}}function ma(t,e,n,i){const{caretSize:s,caretPadding:o,cornerRadius:a}=t,{xAlign:r,yAlign:c}=n,l=s+o,{topLeft:d,topRight:h,bottomLeft:u,bottomRight:g}=Je(a);let p=function(t,e){let{x:n,width:i}=t;return"right"===e?n-=i:"center"===e&&(n-=i/2),n}(e,r);const m=function(t,e,n){let{y:i,height:s}=t;return"top"===e?i+=n:i-="bottom"===e?s+n:s/2,i}(e,c,l);return"center"===c?"left"===r?p+=l:"right"===r&&(p-=l):"left"===r?p-=Math.max(d,u)+s:"right"===r&&(p+=Math.max(h,g)+s),{x:te(p,0,i.width-e.width),y:te(m,0,i.height-e.height)}}function fa(t,e,n){const i=tn(n.padding);return"center"===e?t.x+t.width/2:"right"===e?t.x+t.width-i.right:t.x+i.left}function ba(t){return la([],da(t))}function ya(t,e){const n=e&&e.dataset&&e.dataset.tooltip&&e.dataset.tooltip.callbacks;return n?t.override(n):t}const xa={beforeTitle:ct,title(t){if(t.length>0){const e=t[0],n=e.chart.data.labels,i=n?n.length:0;if(this&&this.options&&"dataset"===this.options.mode)return e.dataset.label||"";if(e.label)return e.label;if(i>0&&e.dataIndex<i)return n[e.dataIndex]}return""},afterTitle:ct,beforeBody:ct,beforeLabel:ct,label(t){if(this&&this.options&&"dataset"===this.options.mode)return t.label+": "+t.formattedValue||t.formattedValue;let e=t.dataset.label||"";e&&(e+=": ");const n=t.formattedValue;return dt(n)||(e+=n),e},labelColor(t){const e=t.chart.getDatasetMeta(t.datasetIndex).controller.getStyle(t.dataIndex);return{borderColor:e.borderColor,backgroundColor:e.backgroundColor,borderWidth:e.borderWidth,borderDash:e.borderDash,borderDashOffset:e.borderDashOffset,borderRadius:0}},labelTextColor(){return this.options.bodyColor},labelPointStyle(t){const e=t.chart.getDatasetMeta(t.datasetIndex).controller.getStyle(t.dataIndex);return{pointStyle:e.pointStyle,rotation:e.rotation}},afterLabel:ct,afterBody:ct,beforeFooter:ct,footer:ct,afterFooter:ct};function va(t,e,n,i){const s=t[e].call(n,i);return void 0===s?xa[e].call(n,i):s}class wa extends ms{static positioners=ca;constructor(t){super(),this.opacity=0,this._active=[],this._eventPosition=void 0,this._size=void 0,this._cachedAnimations=void 0,this._tooltipItems=[],this.$animations=void 0,this.$context=void 0,this.chart=t.chart,this.options=t.options,this.dataPoints=void 0,this.title=void 0,this.beforeBody=void 0,this.body=void 0,this.afterBody=void 0,this.footer=void 0,this.xAlign=void 0,this.yAlign=void 0,this.x=void 0,this.y=void 0,this.height=void 0,this.width=void 0,this.caretX=void 0,this.caretY=void 0,this.labelColors=void 0,this.labelPointStyles=void 0,this.labelTextColors=void 0}initialize(t){this.options=t,this._cachedAnimations=void 0,this.$context=void 0}_resolveAnimations(){const t=this._cachedAnimations;if(t)return t;const e=this.chart,n=this.options.setContext(this.getContext()),i=n.enabled&&e.options.animation&&n.animations,s=new si(this.chart,i);return i._cacheable&&(this._cachedAnimations=Object.freeze(s)),s}getContext(){return this.$context||(this.$context=(t=this.chart.getContext(),e=this,n=this._tooltipItems,sn(t,{tooltip:e,tooltipItems:n,type:"tooltip"})));var t,e,n}getTitle(t,e){const{callbacks:n}=e,i=va(n,"beforeTitle",this,t),s=va(n,"title",this,t),o=va(n,"afterTitle",this,t);let a=[];return a=la(a,da(i)),a=la(a,da(s)),a=la(a,da(o)),a}getBeforeBody(t,e){return ba(va(e.callbacks,"beforeBody",this,t))}getBody(t,e){const{callbacks:n}=e,i=[];return yt(t,(t=>{const e={before:[],lines:[],after:[]},s=ya(n,t);la(e.before,da(va(s,"beforeLabel",this,t))),la(e.lines,va(s,"label",this,t)),la(e.after,da(va(s,"afterLabel",this,t))),i.push(e)})),i}getAfterBody(t,e){return ba(va(e.callbacks,"afterBody",this,t))}getFooter(t,e){const{callbacks:n}=e,i=va(n,"beforeFooter",this,t),s=va(n,"footer",this,t),o=va(n,"afterFooter",this,t);let a=[];return a=la(a,da(i)),a=la(a,da(s)),a=la(a,da(o)),a}_createItems(t){const e=this._active,n=this.chart.data,i=[],s=[],o=[];let a,r,c=[];for(a=0,r=e.length;a<r;++a)c.push(ha(this.chart,e[a]));return t.filter&&(c=c.filter(((e,i,s)=>t.filter(e,i,s,n)))),t.itemSort&&(c=c.sort(((e,i)=>t.itemSort(e,i,n)))),yt(c,(e=>{const n=ya(t.callbacks,e);i.push(va(n,"labelColor",this,e)),s.push(va(n,"labelPointStyle",this,e)),o.push(va(n,"labelTextColor",this,e))})),this.labelColors=i,this.labelPointStyles=s,this.labelTextColors=o,this.dataPoints=c,c}update(t,e){const n=this.options.setContext(this.getContext()),i=this._active;let s,o=[];if(i.length){const t=ca[n.position].call(this,i,this._eventPosition);o=this._createItems(n),this.title=this.getTitle(o,n),this.beforeBody=this.getBeforeBody(o,n),this.body=this.getBody(o,n),this.afterBody=this.getAfterBody(o,n),this.footer=this.getFooter(o,n);const e=this._size=ua(this,n),a=Object.assign({},t,e),r=pa(this.chart,n,a),c=ma(n,a,r,this.chart);this.xAlign=r.xAlign,this.yAlign=r.yAlign,s={opacity:1,x:c.x,y:c.y,width:e.width,height:e.height,caretX:t.x,caretY:t.y}}else 0!==this.opacity&&(s={opacity:0});this._tooltipItems=o,this.$context=void 0,s&&this._resolveAnimations().update(this,s),t&&n.external&&n.external.call(this,{chart:this.chart,tooltip:this,replay:e})}drawCaret(t,e,n,i){const s=this.getCaretPosition(t,n,i);e.lineTo(s.x1,s.y1),e.lineTo(s.x2,s.y2),e.lineTo(s.x3,s.y3)}getCaretPosition(t,e,n){const{xAlign:i,yAlign:s}=this,{caretSize:o,cornerRadius:a}=n,{topLeft:r,topRight:c,bottomLeft:l,bottomRight:d}=Je(a),{x:h,y:u}=t,{width:g,height:p}=e;let m,f,b,y,x,v;return"center"===s?(x=u+p/2,"left"===i?(m=h,f=m-o,y=x+o,v=x-o):(m=h+g,f=m+o,y=x-o,v=x+o),b=m):(f="left"===i?h+Math.max(r,l)+o:"right"===i?h+g-Math.max(c,d)-o:this.caretX,"top"===s?(y=u,x=y-o,m=f-o,b=f+o):(y=u+p,x=y+o,m=f+o,b=f-o),v=y),{x1:m,x2:f,x3:b,y1:y,y2:x,y3:v}}drawTitle(t,e,n){const i=this.title,s=i.length;let o,a,r;if(s){const c=qn(n.rtl,this.x,this.width);for(t.x=fa(this,n.titleAlign,n),e.textAlign=c.textAlign(n.titleAlign),e.textBaseline="middle",o=en(n.titleFont),a=n.titleSpacing,e.fillStyle=n.titleColor,e.font=o.string,r=0;r<s;++r)e.fillText(i[r],c.x(t.x),t.y+o.lineHeight/2),t.y+=o.lineHeight+a,r+1===s&&(t.y+=n.titleMarginBottom-a)}}_drawColorBox(t,e,n,i,s){const o=this.labelColors[n],a=this.labelPointStyles[n],{boxHeight:r,boxWidth:c}=s,l=en(s.bodyFont),d=fa(this,"left",s),h=i.x(d),u=r<l.lineHeight?(l.lineHeight-r)/2:0,g=e.y+u;if(s.usePointStyle){const e={radius:Math.min(c,r)/2,pointStyle:a.pointStyle,rotation:a.rotation,borderWidth:1},n=i.leftForLtr(h,c)+c/2,l=g+r/2;t.strokeStyle=s.multiKeyBackground,t.fillStyle=s.multiKeyBackground,Ne(t,e,n,l),t.strokeStyle=o.borderColor,t.fillStyle=o.backgroundColor,Ne(t,e,n,l)}else{t.lineWidth=ut(o.borderWidth)?Math.max(...Object.values(o.borderWidth)):o.borderWidth||1,t.strokeStyle=o.borderColor,t.setLineDash(o.borderDash||[]),t.lineDashOffset=o.borderDashOffset||0;const e=i.leftForLtr(h,c),n=i.leftForLtr(i.xPlus(h,1),c-2),a=Je(o.borderRadius);Object.values(a).some((t=>0!==t))?(t.beginPath(),t.fillStyle=s.multiKeyBackground,Ue(t,{x:e,y:g,w:c,h:r,radius:a}),t.fill(),t.stroke(),t.fillStyle=o.backgroundColor,t.beginPath(),Ue(t,{x:n,y:g+1,w:c-2,h:r-2,radius:a}),t.fill()):(t.fillStyle=s.multiKeyBackground,t.fillRect(e,g,c,r),t.strokeRect(e,g,c,r),t.fillStyle=o.backgroundColor,t.fillRect(n,g+1,c-2,r-2))}t.fillStyle=this.labelTextColors[n]}drawBody(t,e,n){const{body:i}=this,{bodySpacing:s,bodyAlign:o,displayColors:a,boxHeight:r,boxWidth:c,boxPadding:l}=n,d=en(n.bodyFont);let h=d.lineHeight,u=0;const g=qn(n.rtl,this.x,this.width),p=function(n){e.fillText(n,g.x(t.x+u),t.y+h/2),t.y+=h+s},m=g.textAlign(o);let f,b,y,x,v,w,S;for(e.textAlign=o,e.textBaseline="middle",e.font=d.string,t.x=fa(this,m,n),e.fillStyle=n.bodyColor,yt(this.beforeBody,p),u=a&&"right"!==m?"center"===o?c/2+l:c+2+l:0,x=0,w=i.length;x<w;++x){for(f=i[x],b=this.labelTextColors[x],e.fillStyle=b,yt(f.before,p),y=f.lines,a&&y.length&&(this._drawColorBox(e,t,x,g,n),h=Math.max(d.lineHeight,r)),v=0,S=y.length;v<S;++v)p(y[v]),h=d.lineHeight;yt(f.after,p)}u=0,h=d.lineHeight,yt(this.afterBody,p),t.y-=s}drawFooter(t,e,n){const i=this.footer,s=i.length;let o,a;if(s){const r=qn(n.rtl,this.x,this.width);for(t.x=fa(this,n.footerAlign,n),t.y+=n.footerMarginTop,e.textAlign=r.textAlign(n.footerAlign),e.textBaseline="middle",o=en(n.footerFont),e.fillStyle=n.footerColor,e.font=o.string,a=0;a<s;++a)e.fillText(i[a],r.x(t.x),t.y+o.lineHeight/2),t.y+=o.lineHeight+n.footerSpacing}}drawBackground(t,e,n,i){const{xAlign:s,yAlign:o}=this,{x:a,y:r}=t,{width:c,height:l}=n,{topLeft:d,topRight:h,bottomLeft:u,bottomRight:g}=Je(i.cornerRadius);e.fillStyle=i.backgroundColor,e.strokeStyle=i.borderColor,e.lineWidth=i.borderWidth,e.beginPath(),e.moveTo(a+d,r),"top"===o&&this.drawCaret(t,e,n,i),e.lineTo(a+c-h,r),e.quadraticCurveTo(a+c,r,a+c,r+h),"center"===o&&"right"===s&&this.drawCaret(t,e,n,i),e.lineTo(a+c,r+l-g),e.quadraticCurveTo(a+c,r+l,a+c-g,r+l),"bottom"===o&&this.drawCaret(t,e,n,i),e.lineTo(a+u,r+l),e.quadraticCurveTo(a,r+l,a,r+l-u),"center"===o&&"left"===s&&this.drawCaret(t,e,n,i),e.lineTo(a,r+d),e.quadraticCurveTo(a,r,a+d,r),e.closePath(),e.fill(),i.borderWidth>0&&e.stroke()}_updateAnimationTarget(t){const e=this.chart,n=this.$animations,i=n&&n.x,s=n&&n.y;if(i||s){const n=ca[t.position].call(this,this._active,this._eventPosition);if(!n)return;const o=this._size=ua(this,t),a=Object.assign({},n,this._size),r=pa(e,t,a),c=ma(t,a,r,e);i._to===c.x&&s._to===c.y||(this.xAlign=r.xAlign,this.yAlign=r.yAlign,this.width=o.width,this.height=o.height,this.caretX=n.x,this.caretY=n.y,this._resolveAnimations().update(this,c))}}_willRender(){return!!this.opacity}draw(t){const e=this.options.setContext(this.getContext());let n=this.opacity;if(!n)return;this._updateAnimationTarget(e);const i={width:this.width,height:this.height},s={x:this.x,y:this.y};n=Math.abs(n)<.001?0:n;const o=tn(e.padding),a=this.title.length||this.beforeBody.length||this.body.length||this.afterBody.length||this.footer.length;e.enabled&&a&&(t.save(),t.globalAlpha=n,this.drawBackground(s,t,i,e),Bn(t,e.textDirection),s.y+=o.top,this.drawTitle(s,t,e),this.drawBody(s,t,e),this.drawFooter(s,t,e),Hn(t,e.textDirection),t.restore())}getActiveElements(){return this._active||[]}setActiveElements(t,e){const n=this._active,i=t.map((({datasetIndex:t,index:e})=>{const n=this.chart.getDatasetMeta(t);if(!n)throw new Error("Cannot find a dataset at index "+t);return{datasetIndex:t,element:n.data[e],index:e}})),s=!xt(n,i),o=this._positionChanged(i,e);(s||o)&&(this._active=i,this._eventPosition=e,this._ignoreReplayEvents=!0,this.update(!0))}handleEvent(t,e,n=!0){if(e&&this._ignoreReplayEvents)return!1;this._ignoreReplayEvents=!1;const i=this.options,s=this._active||[],o=this._getActiveElements(t,s,e,n),a=this._positionChanged(o,t),r=e||!xt(o,s)||a;return r&&(this._active=o,(i.enabled||i.external)&&(this._eventPosition={x:t.x,y:t.y},this.update(!0,e))),r}_getActiveElements(t,e,n,i){const s=this.options;if("mouseout"===t.type)return[];if(!i)return e.filter((t=>this.chart.data.datasets[t.datasetIndex]&&void 0!==this.chart.getDatasetMeta(t.datasetIndex).controller.getParsed(t.index)));const o=this.chart.getElementsAtEventForMode(t,s.mode,s,n);return s.reverse&&o.reverse(),o}_positionChanged(t,e){const{caretX:n,caretY:i,options:s}=this,o=ca[s.position].call(this,t,e);return!1!==o&&(n!==o.x||i!==o.y)}}var Sa={id:"tooltip",_element:wa,positioners:ca,afterInit(t,e,n){n&&(t.tooltip=new wa({chart:t,options:n}))},beforeUpdate(t,e,n){t.tooltip&&t.tooltip.initialize(n)},reset(t,e,n){t.tooltip&&t.tooltip.initialize(n)},afterDraw(t){const e=t.tooltip;if(e&&e._willRender()){const n={tooltip:e};if(!1===t.notifyPlugins("beforeTooltipDraw",{...n,cancelable:!0}))return;e.draw(t.ctx),t.notifyPlugins("afterTooltipDraw",n)}},afterEvent(t,e){if(t.tooltip){const n=e.replay;t.tooltip.handleEvent(e.event,n,e.inChartArea)&&(e.changed=!0)}},defaults:{enabled:!0,external:null,position:"average",backgroundColor:"rgba(0,0,0,0.8)",titleColor:"#fff",titleFont:{weight:"bold"},titleSpacing:2,titleMarginBottom:6,titleAlign:"left",bodyColor:"#fff",bodySpacing:2,bodyFont:{},bodyAlign:"left",footerColor:"#fff",footerSpacing:2,footerMarginTop:6,footerFont:{weight:"bold"},footerAlign:"left",padding:6,caretPadding:2,caretSize:5,cornerRadius:6,boxHeight:(t,e)=>e.bodyFont.size,boxWidth:(t,e)=>e.bodyFont.size,multiKeyBackground:"#fff",displayColors:!0,boxPadding:0,borderColor:"rgba(0,0,0,0)",borderWidth:0,animation:{duration:400,easing:"easeOutQuart"},animations:{numbers:{type:"number",properties:["x","y","width","height","caretX","caretY"]},opacity:{easing:"linear",duration:200}},callbacks:xa},defaultRoutes:{bodyFont:"font",footerFont:"font",titleFont:"font"},descriptors:{_scriptable:t=>"filter"!==t&&"itemSort"!==t&&"external"!==t,_indexable:!1,callbacks:{_scriptable:!1,_indexable:!1},animation:{_fallback:!1},animations:{_fallback:"animation"}},additionalOptionScopes:["interaction"]},ka=Object.freeze({__proto__:null,Colors:Lo,Decimation:zo,Filler:Jo,Legend:ia,SubTitle:ra,Title:oa,Tooltip:Sa});function Ma(t,e,n,i){const s=t.indexOf(e);if(-1===s)return((t,e,n,i)=>("string"==typeof e?(n=t.push(e)-1,i.unshift({index:n,label:e})):isNaN(e)&&(n=null),n))(t,e,n,i);return s!==t.lastIndexOf(e)?n:s}function _a(t){const e=this.getLabels();return t>=0&&t<e.length?e[t]:t}function Ca(t,e){const n=[],{bounds:i,step:s,min:o,max:a,precision:r,count:c,maxTicks:l,maxDigits:d,includeBounds:h}=t,u=s||1,g=l-1,{min:p,max:m}=e,f=!dt(o),b=!dt(a),y=!dt(c),x=(m-p)/(d+1);let v,w,S,k,M=Ht((m-p)/g/u)*u;if(M<1e-14&&!f&&!b)return[{value:p},{value:m}];k=Math.ceil(m/M)-Math.floor(p/M),k>g&&(M=Ht(k*M/g/u)*u),dt(r)||(v=Math.pow(10,r),M=Math.ceil(M*v)/v),"ticks"===i?(w=Math.floor(p/M)*M,S=Math.ceil(m/M)*M):(w=p,S=m),f&&b&&s&&function(t,e){const n=Math.round(t);return n-e<=t&&n+e>=t}((a-o)/s,M/1e3)?(k=Math.round(Math.min((a-o)/M,l)),M=(a-o)/k,w=o,S=a):y?(w=f?o:w,S=b?a:S,k=c-1,M=(S-w)/k):(k=(S-w)/M,k=Bt(k,Math.round(k),M/1e3)?Math.round(k):Math.ceil(k));const _=Math.max(Xt(M),Xt(w));v=Math.pow(10,dt(r)?_:r),w=Math.round(w*v)/v,S=Math.round(S*v)/v;let C=0;for(f&&(h&&w!==o?(n.push({value:o}),w<o&&C++,Bt(Math.round((w+C*M)*v)/v,o,Ta(o,x,t))&&C++):w<o&&C++);C<k;++C){const t=Math.round((w+C*M)*v)/v;if(b&&t>a)break;n.push({value:t})}return b&&h&&S!==a?n.length&&Bt(n[n.length-1].value,a,Ta(a,x,t))?n[n.length-1].value=a:n.push({value:a}):b&&S!==a||n.push({value:S}),n}function Ta(t,e,{horizontal:n,minRotation:i}){const s=Yt(i),o=(n?Math.sin(s):Math.cos(s))||.001,a=.75*e*(""+t).length;return Math.min(e/o,a)}class Da extends _s{constructor(t){super(t),this.start=void 0,this.end=void 0,this._startValue=void 0,this._endValue=void 0,this._valueRange=0}parse(t,e){return dt(t)||("number"==typeof t||t instanceof Number)&&!isFinite(+t)?null:+t}handleTickRangeOptions(){const{beginAtZero:t}=this.options,{minDefined:e,maxDefined:n}=this.getUserBounds();let{min:i,max:s}=this;const o=t=>i=e?i:t,a=t=>s=n?s:t;if(t){const t=qt(i),e=qt(s);t<0&&e<0?a(0):t>0&&e>0&&o(0)}if(i===s){let e=0===s?1:Math.abs(.05*s);a(s+e),t||o(i-e)}this.min=i,this.max=s}getTickLimit(){const t=this.options.ticks;let e,{maxTicksLimit:n,stepSize:i}=t;return i?(e=Math.ceil(this.max/i)-Math.floor(this.min/i)+1,e>1e3&&(console.warn(`scales.${this.id}.ticks.stepSize: ${i} would result generating up to ${e} ticks. Limiting to 1000.`),e=1e3)):(e=this.computeTickLimit(),n=n||11),n&&(e=Math.min(n,e)),e}computeTickLimit(){return Number.POSITIVE_INFINITY}buildTicks(){const t=this.options,e=t.ticks;let n=this.getTickLimit();n=Math.max(2,n);const i=Ca({maxTicks:n,bounds:t.bounds,min:t.min,max:t.max,precision:e.precision,step:e.stepSize,count:e.count,maxDigits:this._maxDigits(),horizontal:this.isHorizontal(),minRotation:e.minRotation||0,includeBounds:!1!==e.includeBounds},this._range||this);return"ticks"===t.bounds&&jt(i,this,"value"),t.reverse?(i.reverse(),this.start=this.max,this.end=this.min):(this.start=this.min,this.end=this.max),i}configure(){const t=this.ticks;let e=this.min,n=this.max;if(super.configure(),this.options.offset&&t.length){const i=(n-e)/Math.max(t.length-1,1)/2;e-=i,n+=i}this._startValue=e,this._endValue=n,this._valueRange=n-e}getLabelForValue(t){return Me(t,this.chart.options.locale,this.options.ticks.format)}}class Pa extends Da{static id="linear";static defaults={ticks:{callback:Ce.formatters.numeric}};determineDataLimits(){const{min:t,max:e}=this.getMinMax(!0);this.min=gt(t)?t:0,this.max=gt(e)?e:1,this.handleTickRangeOptions()}computeTickLimit(){const t=this.isHorizontal(),e=t?this.width:this.height,n=Yt(this.options.ticks.minRotation),i=(t?Math.sin(n):Math.cos(n))||.001,s=this._resolveTickFontOptions(0);return Math.ceil(e/Math.min(40,s.lineHeight/i))}getPixelForValue(t){return null===t?NaN:this.getPixelForDecimal((t-this._startValue)/this._valueRange)}getValueForPixel(t){return this._startValue+this.getDecimalForPixel(t)*this._valueRange}}const Ea=t=>Math.floor(Ft(t)),Aa=(t,e)=>Math.pow(10,Ea(t)+e);function La(t){return 1===t/Math.pow(10,Ea(t))}function Ia(t,e,n){const i=Math.pow(10,n),s=Math.floor(t/i);return Math.ceil(e/i)-s}function Oa(t,{min:e,max:n}){e=pt(t.min,e);const i=[],s=Ea(e);let o=function(t,e){let n=Ea(e-t);for(;Ia(t,e,n)>10;)n++;for(;Ia(t,e,n)<10;)n--;return Math.min(n,Ea(t))}(e,n),a=o<0?Math.pow(10,Math.abs(o)):1;const r=Math.pow(10,o),c=s>o?Math.pow(10,s):0,l=Math.round((e-c)*a)/a,d=Math.floor((e-c)/r/10)*r*10;let h=Math.floor((l-d)/Math.pow(10,o)),u=pt(t.min,Math.round((c+d+h*Math.pow(10,o))*a)/a);for(;u<n;)i.push({value:u,major:La(u),significand:h}),h>=10?h=h<15?15:20:h++,h>=20&&(o++,h=2,a=o>=0?1:a),u=Math.round((c+d+h*Math.pow(10,o))*a)/a;const g=pt(t.max,u);return i.push({value:g,major:La(g),significand:h}),i}class za extends _s{static id="logarithmic";static defaults={ticks:{callback:Ce.formatters.logarithmic,major:{enabled:!0}}};constructor(t){super(t),this.start=void 0,this.end=void 0,this._startValue=void 0,this._valueRange=0}parse(t,e){const n=Da.prototype.parse.apply(this,[t,e]);if(0!==n)return gt(n)&&n>0?n:null;this._zero=!0}determineDataLimits(){const{min:t,max:e}=this.getMinMax(!0);this.min=gt(t)?Math.max(0,t):null,this.max=gt(e)?Math.max(0,e):null,this.options.beginAtZero&&(this._zero=!0),this._zero&&this.min!==this._suggestedMin&&!gt(this._userMin)&&(this.min=t===Aa(this.min,0)?Aa(this.min,-1):Aa(this.min,0)),this.handleTickRangeOptions()}handleTickRangeOptions(){const{minDefined:t,maxDefined:e}=this.getUserBounds();let n=this.min,i=this.max;const s=e=>n=t?n:e,o=t=>i=e?i:t;n===i&&(n<=0?(s(1),o(10)):(s(Aa(n,-1)),o(Aa(i,1)))),n<=0&&s(Aa(i,-1)),i<=0&&o(Aa(n,1)),this.min=n,this.max=i}buildTicks(){const t=this.options,e=Oa({min:this._userMin,max:this._userMax},this);return"ticks"===t.bounds&&jt(e,this,"value"),t.reverse?(e.reverse(),this.start=this.max,this.end=this.min):(this.start=this.min,this.end=this.max),e}getLabelForValue(t){return void 0===t?"0":Me(t,this.chart.options.locale,this.options.ticks.format)}configure(){const t=this.min;super.configure(),this._startValue=Ft(t),this._valueRange=Ft(this.max)-Ft(t)}getPixelForValue(t){return void 0!==t&&0!==t||(t=this.min),null===t||isNaN(t)?NaN:this.getPixelForDecimal(t===this.min?0:(Ft(t)-this._startValue)/this._valueRange)}getValueForPixel(t){const e=this.getDecimalForPixel(t);return Math.pow(10,this._startValue+e*this._valueRange)}}function Wa(t){const e=t.ticks;if(e.display&&t.display){const t=tn(e.backdropPadding);return mt(e.font&&e.font.size,Le.font.size)+t.height}return 0}function Na(t,e,n,i,s){return t===i||t===s?{start:e-n/2,end:e+n/2}:t<i||t>s?{start:e-n,end:e}:{start:e,end:e+n}}function Ra(t){const e={l:t.left+t._padding.left,r:t.right-t._padding.right,t:t.top+t._padding.top,b:t.bottom-t._padding.bottom},n=Object.assign({},e),i=[],s=[],o=t._pointLabels.length,a=t.options.pointLabels,r=a.centerPointLabels?Lt/o:0;for(let h=0;h<o;h++){const o=a.setContext(t.getPointLabelContext(h));s[h]=o.padding;const u=t.getPointPosition(h,t.drawingArea+s[h],r),g=en(o.font),p=(c=t.ctx,l=g,d=ht(d=t._pointLabels[h])?d:[d],{w:Oe(c,l.string,d),h:d.length*l.lineHeight});i[h]=p;const m=Gt(t.getIndexAngle(h)+r),f=Math.round(Ut(m));$a(n,e,m,Na(f,u.x,p.w,0,180),Na(f,u.y,p.h,90,270))}var c,l,d;t.setCenterPoint(e.l-n.l,n.r-e.r,e.t-n.t,n.b-e.b),t._pointLabelItems=function(t,e,n){const i=[],s=t._pointLabels.length,o=t.options,{centerPointLabels:a,display:r}=o.pointLabels,c={extra:Wa(o)/2,additionalAngle:a?Lt/s:0};let l;for(let o=0;o<s;o++){c.padding=n[o],c.size=e[o];const s=Fa(t,o,c);i.push(s),"auto"===r&&(s.visible=qa(s,l),s.visible&&(l=s))}return i}(t,i,s)}function $a(t,e,n,i,s){const o=Math.abs(Math.sin(n)),a=Math.abs(Math.cos(n));let r=0,c=0;i.start<e.l?(r=(e.l-i.start)/o,t.l=Math.min(t.l,e.l-r)):i.end>e.r&&(r=(i.end-e.r)/o,t.r=Math.max(t.r,e.r+r)),s.start<e.t?(c=(e.t-s.start)/a,t.t=Math.min(t.t,e.t-c)):s.end>e.b&&(c=(s.end-e.b)/a,t.b=Math.max(t.b,e.b+c))}function Fa(t,e,n){const i=t.drawingArea,{extra:s,additionalAngle:o,padding:a,size:r}=n,c=t.getPointPosition(e,i+s+a,o),l=Math.round(Ut(Gt(c.angle+Nt))),d=function(t,e,n){90===n||270===n?t-=e/2:(n>270||n<90)&&(t-=e);return t}(c.y,r.h,l),h=function(t){if(0===t||180===t)return"center";if(t<180)return"left";return"right"}(l),u=function(t,e,n){"right"===n?t-=e:"center"===n&&(t-=e/2);return t}(c.x,r.w,h);return{visible:!0,x:c.x,y:d,textAlign:h,left:u,top:d,right:u+r.w,bottom:d+r.h}}function qa(t,e){if(!e)return!0;const{left:n,top:i,right:s,bottom:o}=t;return!($e({x:n,y:i},e)||$e({x:n,y:o},e)||$e({x:s,y:i},e)||$e({x:s,y:o},e))}function Ba(t,e,n){const{left:i,top:s,right:o,bottom:a}=n,{backdropColor:r}=e;if(!dt(r)){const n=Je(e.borderRadius),c=tn(e.backdropPadding);t.fillStyle=r;const l=i-c.left,d=s-c.top,h=o-i+c.width,u=a-s+c.height;Object.values(n).some((t=>0!==t))?(t.beginPath(),Ue(t,{x:l,y:d,w:h,h:u,radius:n}),t.fill()):t.fillRect(l,d,h,u)}}function Ha(t,e,n,i){const{ctx:s}=t;if(n)s.arc(t.xCenter,t.yCenter,e,0,It);else{let n=t.getPointPosition(0,e);s.moveTo(n.x,n.y);for(let o=1;o<i;o++)n=t.getPointPosition(o,e),s.lineTo(n.x,n.y)}}class Va extends Da{static id="radialLinear";static defaults={display:!0,animate:!0,position:"chartArea",angleLines:{display:!0,lineWidth:1,borderDash:[],borderDashOffset:0},grid:{circular:!1},startAngle:0,ticks:{showLabelBackdrop:!0,callback:Ce.formatters.numeric},pointLabels:{backdropColor:void 0,backdropPadding:2,display:!0,font:{size:10},callback:t=>t,padding:5,centerPointLabels:!1}};static defaultRoutes={"angleLines.color":"borderColor","pointLabels.color":"color","ticks.color":"color"};static descriptors={angleLines:{_fallback:"grid"}};constructor(t){super(t),this.xCenter=void 0,this.yCenter=void 0,this.drawingArea=void 0,this._pointLabels=[],this._pointLabelItems=[]}setDimensions(){const t=this._padding=tn(Wa(this.options)/2),e=this.width=this.maxWidth-t.width,n=this.height=this.maxHeight-t.height;this.xCenter=Math.floor(this.left+e/2+t.left),this.yCenter=Math.floor(this.top+n/2+t.top),this.drawingArea=Math.floor(Math.min(e,n)/2)}determineDataLimits(){const{min:t,max:e}=this.getMinMax(!1);this.min=gt(t)&&!isNaN(t)?t:0,this.max=gt(e)&&!isNaN(e)?e:0,this.handleTickRangeOptions()}computeTickLimit(){return Math.ceil(this.drawingArea/Wa(this.options))}generateTickLabels(t){Da.prototype.generateTickLabels.call(this,t),this._pointLabels=this.getLabels().map(((t,e)=>{const n=bt(this.options.pointLabels.callback,[t,e],this);return n||0===n?n:""})).filter(((t,e)=>this.chart.getDataVisibility(e)))}fit(){const t=this.options;t.display&&t.pointLabels.display?Ra(this):this.setCenterPoint(0,0,0,0)}setCenterPoint(t,e,n,i){this.xCenter+=Math.floor((t-e)/2),this.yCenter+=Math.floor((n-i)/2),this.drawingArea-=Math.min(this.drawingArea/2,Math.max(t,e,n,i))}getIndexAngle(t){return Gt(t*(It/(this._pointLabels.length||1))+Yt(this.options.startAngle||0))}getDistanceFromCenterForValue(t){if(dt(t))return NaN;const e=this.drawingArea/(this.max-this.min);return this.options.reverse?(this.max-t)*e:(t-this.min)*e}getValueForDistanceFromCenter(t){if(dt(t))return NaN;const e=t/(this.drawingArea/(this.max-this.min));return this.options.reverse?this.max-e:this.min+e}getPointLabelContext(t){const e=this._pointLabels||[];if(t>=0&&t<e.length){const n=e[t];return function(t,e,n){return sn(t,{label:n,index:e,type:"pointLabel"})}(this.getContext(),t,n)}}getPointPosition(t,e,n=0){const i=this.getIndexAngle(t)-Nt+n;return{x:Math.cos(i)*e+this.xCenter,y:Math.sin(i)*e+this.yCenter,angle:i}}getPointPositionForValue(t,e){return this.getPointPosition(t,this.getDistanceFromCenterForValue(e))}getBasePosition(t){return this.getPointPositionForValue(t||0,this.getBaseValue())}getPointLabelPosition(t){const{left:e,top:n,right:i,bottom:s}=this._pointLabelItems[t];return{left:e,top:n,right:i,bottom:s}}drawBackground(){const{backgroundColor:t,grid:{circular:e}}=this.options;if(t){const n=this.ctx;n.save(),n.beginPath(),Ha(this,this.getDistanceFromCenterForValue(this._endValue),e,this._pointLabels.length),n.closePath(),n.fillStyle=t,n.fill(),n.restore()}}drawGrid(){const t=this.ctx,e=this.options,{angleLines:n,grid:i,border:s}=e,o=this._pointLabels.length;let a,r,c;if(e.pointLabels.display&&function(t,e){const{ctx:n,options:{pointLabels:i}}=t;for(let s=e-1;s>=0;s--){const e=t._pointLabelItems[s];if(!e.visible)continue;const o=i.setContext(t.getPointLabelContext(s));Ba(n,o,e);const a=en(o.font),{x:r,y:c,textAlign:l}=e;Ye(n,t._pointLabels[s],r,c+a.lineHeight/2,a,{color:o.color,textAlign:l,textBaseline:"middle"})}}(this,o),i.display&&this.ticks.forEach(((t,e)=>{if(0!==e||0===e&&this.min<0){r=this.getDistanceFromCenterForValue(t.value);const n=this.getContext(e),a=i.setContext(n),c=s.setContext(n);!function(t,e,n,i,s){const o=t.ctx,a=e.circular,{color:r,lineWidth:c}=e;!a&&!i||!r||!c||n<0||(o.save(),o.strokeStyle=r,o.lineWidth=c,o.setLineDash(s.dash||[]),o.lineDashOffset=s.dashOffset,o.beginPath(),Ha(t,n,a,i),o.closePath(),o.stroke(),o.restore())}(this,a,r,o,c)}})),n.display){for(t.save(),a=o-1;a>=0;a--){const i=n.setContext(this.getPointLabelContext(a)),{color:s,lineWidth:o}=i;o&&s&&(t.lineWidth=o,t.strokeStyle=s,t.setLineDash(i.borderDash),t.lineDashOffset=i.borderDashOffset,r=this.getDistanceFromCenterForValue(e.reverse?this.min:this.max),c=this.getPointPosition(a,r),t.beginPath(),t.moveTo(this.xCenter,this.yCenter),t.lineTo(c.x,c.y),t.stroke())}t.restore()}}drawBorder(){}drawLabels(){const t=this.ctx,e=this.options,n=e.ticks;if(!n.display)return;const i=this.getIndexAngle(0);let s,o;t.save(),t.translate(this.xCenter,this.yCenter),t.rotate(i),t.textAlign="center",t.textBaseline="middle",this.ticks.forEach(((i,a)=>{if(0===a&&this.min>=0&&!e.reverse)return;const r=n.setContext(this.getContext(a)),c=en(r.font);if(s=this.getDistanceFromCenterForValue(this.ticks[a].value),r.showLabelBackdrop){t.font=c.string,o=t.measureText(i.label).width,t.fillStyle=r.backdropColor;const e=tn(r.backdropPadding);t.fillRect(-o/2-e.left,-s-c.size/2-e.top,o+e.width,c.size+e.height)}Ye(t,i.label,0,-s,c,{color:r.color,strokeColor:r.textStrokeColor,strokeWidth:r.textStrokeWidth})})),t.restore()}drawTitle(){}}const ja={millisecond:{common:!0,size:1,steps:1e3},second:{common:!0,size:1e3,steps:60},minute:{common:!0,size:6e4,steps:60},hour:{common:!0,size:36e5,steps:24},day:{common:!0,size:864e5,steps:30},week:{common:!1,size:6048e5,steps:4},month:{common:!0,size:2628e6,steps:12},quarter:{common:!1,size:7884e6,steps:4},year:{common:!0,size:3154e7}},Ya=Object.keys(ja);function Ua(t,e){return t-e}function Xa(t,e){if(dt(e))return null;const n=t._adapter,{parser:i,round:s,isoWeekday:o}=t._parseOpts;let a=e;return"function"==typeof i&&(a=i(a)),gt(a)||(a="string"==typeof i?n.parse(a,i):n.parse(a)),null===a?null:(s&&(a="week"!==s||!Vt(o)&&!0!==o?n.startOf(a,s):n.startOf(a,"isoWeek",o)),+a)}function Qa(t,e,n,i){const s=Ya.length;for(let o=Ya.indexOf(t);o<s-1;++o){const t=ja[Ya[o]],s=t.steps?t.steps:Number.MAX_SAFE_INTEGER;if(t.common&&Math.ceil((n-e)/(s*t.size))<=i)return Ya[o]}return Ya[s-1]}function Ka(t,e,n){if(n){if(n.length){const{lo:i,hi:s}=ne(n,e);t[n[i]>=e?n[i]:n[s]]=!0}}else t[e]=!0}function Za(t,e,n){const i=[],s={},o=e.length;let a,r;for(a=0;a<o;++a)r=e[a],s[r]=a,i.push({value:r,major:!1});return 0!==o&&n?function(t,e,n,i){const s=t._adapter,o=+s.startOf(e[0].value,i),a=e[e.length-1].value;let r,c;for(r=o;r<=a;r=+s.add(r,1,i))c=n[r],c>=0&&(e[c].major=!0);return e}(t,i,s,n):i}class Ga extends _s{static id="time";static defaults={bounds:"data",adapters:{},time:{parser:!1,unit:!1,round:!1,isoWeekday:!1,minUnit:"millisecond",displayFormats:{}},ticks:{source:"auto",callback:!1,major:{enabled:!1}}};constructor(t){super(t),this._cache={data:[],labels:[],all:[]},this._unit="day",this._majorUnit=void 0,this._offsets={},this._normalized=!1,this._parseOpts=void 0}init(t,e={}){const n=t.time||(t.time={}),i=this._adapter=new Ai._date(t.adapters.date);i.init(e),Mt(n.displayFormats,i.formats()),this._parseOpts={parser:n.parser,round:n.round,isoWeekday:n.isoWeekday},super.init(t),this._normalized=e.normalized}parse(t,e){return void 0===t?null:Xa(this,t)}beforeLayout(){super.beforeLayout(),this._cache={data:[],labels:[],all:[]}}determineDataLimits(){const t=this.options,e=this._adapter,n=t.time.unit||"day";let{min:i,max:s,minDefined:o,maxDefined:a}=this.getUserBounds();function r(t){o||isNaN(t.min)||(i=Math.min(i,t.min)),a||isNaN(t.max)||(s=Math.max(s,t.max))}o&&a||(r(this._getLabelBounds()),"ticks"===t.bounds&&"labels"===t.ticks.source||r(this.getMinMax(!1))),i=gt(i)&&!isNaN(i)?i:+e.startOf(Date.now(),n),s=gt(s)&&!isNaN(s)?s:+e.endOf(Date.now(),n)+1,this.min=Math.min(i,s-1),this.max=Math.max(i+1,s)}_getLabelBounds(){const t=this.getLabelTimestamps();let e=Number.POSITIVE_INFINITY,n=Number.NEGATIVE_INFINITY;return t.length&&(e=t[0],n=t[t.length-1]),{min:e,max:n}}buildTicks(){const t=this.options,e=t.time,n=t.ticks,i="labels"===n.source?this.getLabelTimestamps():this._generate();"ticks"===t.bounds&&i.length&&(this.min=this._userMin||i[0],this.max=this._userMax||i[i.length-1]);const s=this.min,o=function(t,e,n){let i=0,s=t.length;for(;i<s&&t[i]<e;)i++;for(;s>i&&t[s-1]>n;)s--;return i>0||s<t.length?t.slice(i,s):t}(i,s,this.max);return this._unit=e.unit||(n.autoSkip?Qa(e.minUnit,this.min,this.max,this._getLabelCapacity(s)):function(t,e,n,i,s){for(let o=Ya.length-1;o>=Ya.indexOf(n);o--){const n=Ya[o];if(ja[n].common&&t._adapter.diff(s,i,n)>=e-1)return n}return Ya[n?Ya.indexOf(n):0]}(this,o.length,e.minUnit,this.min,this.max)),this._majorUnit=n.major.enabled&&"year"!==this._unit?function(t){for(let e=Ya.indexOf(t)+1,n=Ya.length;e<n;++e)if(ja[Ya[e]].common)return Ya[e]}(this._unit):void 0,this.initOffsets(i),t.reverse&&o.reverse(),Za(this,o,this._majorUnit)}afterAutoSkip(){this.options.offsetAfterAutoskip&&this.initOffsets(this.ticks.map((t=>+t.value)))}initOffsets(t=[]){let e,n,i=0,s=0;this.options.offset&&t.length&&(e=this.getDecimalForValue(t[0]),i=1===t.length?1-e:(this.getDecimalForValue(t[1])-e)/2,n=this.getDecimalForValue(t[t.length-1]),s=1===t.length?n:(n-this.getDecimalForValue(t[t.length-2]))/2);const o=t.length<3?.5:.25;i=te(i,0,o),s=te(s,0,o),this._offsets={start:i,end:s,factor:1/(i+1+s)}}_generate(){const t=this._adapter,e=this.min,n=this.max,i=this.options,s=i.time,o=s.unit||Qa(s.minUnit,e,n,this._getLabelCapacity(e)),a=mt(i.ticks.stepSize,1),r="week"===o&&s.isoWeekday,c=Vt(r)||!0===r,l={};let d,h,u=e;if(c&&(u=+t.startOf(u,"isoWeek",r)),u=+t.startOf(u,c?"day":o),t.diff(n,e,o)>1e5*a)throw new Error(e+" and "+n+" are too far apart with stepSize of "+a+" "+o);const g="data"===i.ticks.source&&this.getDataTimestamps();for(d=u,h=0;d<n;d=+t.add(d,a,o),h++)Ka(l,d,g);return d!==n&&"ticks"!==i.bounds&&1!==h||Ka(l,d,g),Object.keys(l).sort(Ua).map((t=>+t))}getLabelForValue(t){const e=this._adapter,n=this.options.time;return n.tooltipFormat?e.format(t,n.tooltipFormat):e.format(t,n.displayFormats.datetime)}format(t,e){const n=this.options.time.displayFormats,i=this._unit,s=e||n[i];return this._adapter.format(t,s)}_tickFormatFunction(t,e,n,i){const s=this.options,o=s.ticks.callback;if(o)return bt(o,[t,e,n],this);const a=s.time.displayFormats,r=this._unit,c=this._majorUnit,l=r&&a[r],d=c&&a[c],h=n[e],u=c&&d&&h&&h.major;return this._adapter.format(t,i||(u?d:l))}generateTickLabels(t){let e,n,i;for(e=0,n=t.length;e<n;++e)i=t[e],i.label=this._tickFormatFunction(i.value,e,t)}getDecimalForValue(t){return null===t?NaN:(t-this.min)/(this.max-this.min)}getPixelForValue(t){const e=this._offsets,n=this.getDecimalForValue(t);return this.getPixelForDecimal((e.start+n)*e.factor)}getValueForPixel(t){const e=this._offsets,n=this.getDecimalForPixel(t)/e.factor-e.end;return this.min+n*(this.max-this.min)}_getLabelSize(t){const e=this.options.ticks,n=this.ctx.measureText(t).width,i=Yt(this.isHorizontal()?e.maxRotation:e.minRotation),s=Math.cos(i),o=Math.sin(i),a=this._resolveTickFontOptions(0).size;return{w:n*s+a*o,h:n*o+a*s}}_getLabelCapacity(t){const e=this.options.time,n=e.displayFormats,i=n[e.unit]||n.millisecond,s=this._tickFormatFunction(t,0,Za(this,[t],this._majorUnit),i),o=this._getLabelSize(s),a=Math.floor(this.isHorizontal()?this.width/o.w:this.height/o.h)-1;return a>0?a:1}getDataTimestamps(){let t,e,n=this._cache.data||[];if(n.length)return n;const i=this.getMatchingVisibleMetas();if(this._normalized&&i.length)return this._cache.data=i[0].controller.getAllParsedValues(this);for(t=0,e=i.length;t<e;++t)n=n.concat(i[t].controller.getAllParsedValues(this));return this._cache.data=this.normalize(n)}getLabelTimestamps(){const t=this._cache.labels||[];let e,n;if(t.length)return t;const i=this.getLabels();for(e=0,n=i.length;e<n;++e)t.push(Xa(this,i[e]));return this._cache.labels=this._normalized?t:this.normalize(t)}normalize(t){return re(t.sort(Ua))}}function Ja(t,e,n){let i,s,o,a,r=0,c=t.length-1;n?(e>=t[r].pos&&e<=t[c].pos&&({lo:r,hi:c}=ie(t,"pos",e)),({pos:i,time:o}=t[r]),({pos:s,time:a}=t[c])):(e>=t[r].time&&e<=t[c].time&&({lo:r,hi:c}=ie(t,"time",e)),({time:i,pos:o}=t[r]),({time:s,pos:a}=t[c]));const l=s-i;return l?o+(a-o)*(e-i)/l:o}var tr=Object.freeze({__proto__:null,CategoryScale:class extends _s{static id="category";static defaults={ticks:{callback:_a}};constructor(t){super(t),this._startValue=void 0,this._valueRange=0,this._addedLabels=[]}init(t){const e=this._addedLabels;if(e.length){const t=this.getLabels();for(const{index:n,label:i}of e)t[n]===i&&t.splice(n,1);this._addedLabels=[]}super.init(t)}parse(t,e){if(dt(t))return null;const n=this.getLabels();return((t,e)=>null===t?null:te(Math.round(t),0,e))(e=isFinite(e)&&n[e]===t?e:Ma(n,t,mt(e,t),this._addedLabels),n.length-1)}determineDataLimits(){const{minDefined:t,maxDefined:e}=this.getUserBounds();let{min:n,max:i}=this.getMinMax(!0);"ticks"===this.options.bounds&&(t||(n=0),e||(i=this.getLabels().length-1)),this.min=n,this.max=i}buildTicks(){const t=this.min,e=this.max,n=this.options.offset,i=[];let s=this.getLabels();s=0===t&&e===s.length-1?s:s.slice(t,e+1),this._valueRange=Math.max(s.length-(n?0:1),1),this._startValue=this.min-(n?.5:0);for(let n=t;n<=e;n++)i.push({value:n});return i}getLabelForValue(t){return _a.call(this,t)}configure(){super.configure(),this.isHorizontal()||(this._reversePixels=!this._reversePixels)}getPixelForValue(t){return"number"!=typeof t&&(t=this.parse(t)),null===t?NaN:this.getPixelForDecimal((t-this._startValue)/this._valueRange)}getPixelForTick(t){const e=this.ticks;return t<0||t>e.length-1?null:this.getPixelForValue(e[t].value)}getValueForPixel(t){return Math.round(this._startValue+this.getDecimalForPixel(t)*this._valueRange)}getBasePixel(){return this.bottom}},LinearScale:Pa,LogarithmicScale:za,RadialLinearScale:Va,TimeScale:Ga,TimeSeriesScale:class extends Ga{static id="timeseries";static defaults=Ga.defaults;constructor(t){super(t),this._table=[],this._minPos=void 0,this._tableRange=void 0}initOffsets(){const t=this._getTimestampsForTable(),e=this._table=this.buildLookupTable(t);this._minPos=Ja(e,this.min),this._tableRange=Ja(e,this.max)-this._minPos,super.initOffsets(t)}buildLookupTable(t){const{min:e,max:n}=this,i=[],s=[];let o,a,r,c,l;for(o=0,a=t.length;o<a;++o)c=t[o],c>=e&&c<=n&&i.push(c);if(i.length<2)return[{time:e,pos:0},{time:n,pos:1}];for(o=0,a=i.length;o<a;++o)l=i[o+1],r=i[o-1],c=i[o],Math.round((l+r)/2)!==c&&s.push({time:c,pos:o/(a-1)});return s}_generate(){const t=this.min,e=this.max;let n=super.getDataTimestamps();return n.includes(t)&&n.length||n.splice(0,0,t),n.includes(e)&&1!==n.length||n.push(e),n.sort(((t,e)=>t-e))}_getTimestampsForTable(){let t=this._cache.all||[];if(t.length)return t;const e=this.getDataTimestamps(),n=this.getLabelTimestamps();return t=e.length&&n.length?this.normalize(e.concat(n)):e.length?e:n,t=this._cache.all=t,t}getDecimalForValue(t){return(Ja(this._table,t)-this._minPos)/this._tableRange}getValueForPixel(t){const e=this._offsets,n=this.getDecimalForPixel(t)/e.factor-e.end;return Ja(this._table,n*this._tableRange+this._minPos,!0)}}});const er=[Di,_o,ka,tr],nr=6048e5,ir=6e4,sr=36e5,or=Symbol.for("constructDateFrom");function ar(t,e){return"function"==typeof t?t(e):t&&"object"==typeof t&&or in t?t[or](e):t instanceof Date?new t.constructor(e):new Date(e)}function rr(t,e){return ar(e||t,t)}function cr(t,e,n){const i=rr(t,n?.in);return isNaN(e)?ar(n?.in||t,NaN):e?(i.setDate(i.getDate()+e),i):i}function lr(t,e,n){const i=rr(t,n?.in);if(isNaN(e))return ar(n?.in||t,NaN);if(!e)return i;const s=i.getDate(),o=ar(n?.in||t,i.getTime());o.setMonth(i.getMonth()+e+1,0);return s>=o.getDate()?o:(i.setFullYear(o.getFullYear(),o.getMonth(),s),i)}function dr(t,e,n){return ar(n?.in||t,+rr(t)+e)}let hr={};function ur(){return hr}function gr(t,e){const n=ur(),i=e?.weekStartsOn??e?.locale?.options?.weekStartsOn??n.weekStartsOn??n.locale?.options?.weekStartsOn??0,s=rr(t,e?.in),o=s.getDay(),a=(o<i?7:0)+o-i;return s.setDate(s.getDate()-a),s.setHours(0,0,0,0),s}function pr(t,e){return gr(t,{...e,weekStartsOn:1})}function mr(t,e){const n=rr(t,e?.in),i=n.getFullYear(),s=ar(n,0);s.setFullYear(i+1,0,4),s.setHours(0,0,0,0);const o=pr(s),a=ar(n,0);a.setFullYear(i,0,4),a.setHours(0,0,0,0);const r=pr(a);return n.getTime()>=o.getTime()?i+1:n.getTime()>=r.getTime()?i:i-1}function fr(t){const e=rr(t),n=new Date(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds()));return n.setUTCFullYear(e.getFullYear()),+t-+n}function br(t,...e){const n=ar.bind(null,t||e.find((t=>"object"==typeof t)));return e.map(n)}function yr(t,e){const n=rr(t,e?.in);return n.setHours(0,0,0,0),n}function xr(t,e,n){const[i,s]=br(n?.in,t,e),o=yr(i),a=yr(s),r=+o-fr(o),c=+a-fr(a);return Math.round((r-c)/864e5)}function vr(t,e){const n=+rr(t)-+rr(e);return n<0?-1:n>0?1:n}function wr(t){return!(!((e=t)instanceof Date||"object"==typeof e&&"[object Date]"===Object.prototype.toString.call(e))&&"number"!=typeof t||isNaN(+rr(t)));var e}function Sr(t,e,n){const[i,s]=br(n?.in,t,e),o=kr(i,s),a=Math.abs(xr(i,s));i.setDate(i.getDate()-o*a);const r=o*(a-Number(kr(i,s)===-o));return 0===r?0:r}function kr(t,e){const n=t.getFullYear()-e.getFullYear()||t.getMonth()-e.getMonth()||t.getDate()-e.getDate()||t.getHours()-e.getHours()||t.getMinutes()-e.getMinutes()||t.getSeconds()-e.getSeconds()||t.getMilliseconds()-e.getMilliseconds();return n<0?-1:n>0?1:n}function Mr(t){return e=>{const n=(t?Math[t]:Math.trunc)(e);return 0===n?0:n}}function _r(t,e){return+rr(t)-+rr(e)}function Cr(t,e){const n=rr(t,e?.in);return n.setHours(23,59,59,999),n}function Tr(t,e){const n=rr(t,e?.in),i=n.getMonth();return n.setFullYear(n.getFullYear(),i+1,0),n.setHours(23,59,59,999),n}function Dr(t,e,n){const[i,s,o]=br(n?.in,t,t,e),a=vr(s,o),r=Math.abs(function(t,e,n){const[i,s]=br(n?.in,t,e);return 12*(i.getFullYear()-s.getFullYear())+(i.getMonth()-s.getMonth())}(s,o));if(r<1)return 0;1===s.getMonth()&&s.getDate()>27&&s.setDate(30),s.setMonth(s.getMonth()-a*r);let c=vr(s,o)===-a;(function(t,e){const n=rr(t,e?.in);return+Cr(n,e)===+Tr(n,e)})(i)&&1===r&&1===vr(i,o)&&(c=!1);const l=a*(r-+c);return 0===l?0:l}function Pr(t,e,n){const[i,s]=br(n?.in,t,e),o=vr(i,s),a=Math.abs(function(t,e,n){const[i,s]=br(n?.in,t,e);return i.getFullYear()-s.getFullYear()}(i,s));i.setFullYear(1584),s.setFullYear(1584);const r=o*(a-+(vr(i,s)===-o));return 0===r?0:r}function Er(t,e){const n=rr(t,e?.in);return n.setFullYear(n.getFullYear(),0,1),n.setHours(0,0,0,0),n}const Ar={lessThanXSeconds:{one:"less than a second",other:"less than {{count}} seconds"},xSeconds:{one:"1 second",other:"{{count}} seconds"},halfAMinute:"half a minute",lessThanXMinutes:{one:"less than a minute",other:"less than {{count}} minutes"},xMinutes:{one:"1 minute",other:"{{count}} minutes"},aboutXHours:{one:"about 1 hour",other:"about {{count}} hours"},xHours:{one:"1 hour",other:"{{count}} hours"},xDays:{one:"1 day",other:"{{count}} days"},aboutXWeeks:{one:"about 1 week",other:"about {{count}} weeks"},xWeeks:{one:"1 week",other:"{{count}} weeks"},aboutXMonths:{one:"about 1 month",other:"about {{count}} months"},xMonths:{one:"1 month",other:"{{count}} months"},aboutXYears:{one:"about 1 year",other:"about {{count}} years"},xYears:{one:"1 year",other:"{{count}} years"},overXYears:{one:"over 1 year",other:"over {{count}} years"},almostXYears:{one:"almost 1 year",other:"almost {{count}} years"}};function Lr(t){return(e={})=>{const n=e.width?String(e.width):t.defaultWidth;return t.formats[n]||t.formats[t.defaultWidth]}}const Ir={date:Lr({formats:{full:"EEEE, MMMM do, y",long:"MMMM do, y",medium:"MMM d, y",short:"MM/dd/yyyy"},defaultWidth:"full"}),time:Lr({formats:{full:"h:mm:ss a zzzz",long:"h:mm:ss a z",medium:"h:mm:ss a",short:"h:mm a"},defaultWidth:"full"}),dateTime:Lr({formats:{full:"{{date}} 'at' {{time}}",long:"{{date}} 'at' {{time}}",medium:"{{date}}, {{time}}",short:"{{date}}, {{time}}"},defaultWidth:"full"})},Or={lastWeek:"'last' eeee 'at' p",yesterday:"'yesterday at' p",today:"'today at' p",tomorrow:"'tomorrow at' p",nextWeek:"eeee 'at' p",other:"P"};function zr(t){return(e,n)=>{let i;if("formatting"===(n?.context?String(n.context):"standalone")&&t.formattingValues){const e=t.defaultFormattingWidth||t.defaultWidth,s=n?.width?String(n.width):e;i=t.formattingValues[s]||t.formattingValues[e]}else{const e=t.defaultWidth,s=n?.width?String(n.width):t.defaultWidth;i=t.values[s]||t.values[e]}return i[t.argumentCallback?t.argumentCallback(e):e]}}const Wr={ordinalNumber:(t,e)=>{const n=Number(t),i=n%100;if(i>20||i<10)switch(i%10){case 1:return n+"st";case 2:return n+"nd";case 3:return n+"rd"}return n+"th"},era:zr({values:{narrow:["B","A"],abbreviated:["BC","AD"],wide:["Before Christ","Anno Domini"]},defaultWidth:"wide"}),quarter:zr({values:{narrow:["1","2","3","4"],abbreviated:["Q1","Q2","Q3","Q4"],wide:["1st quarter","2nd quarter","3rd quarter","4th quarter"]},defaultWidth:"wide",argumentCallback:t=>t-1}),month:zr({values:{narrow:["J","F","M","A","M","J","J","A","S","O","N","D"],abbreviated:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],wide:["January","February","March","April","May","June","July","August","September","October","November","December"]},defaultWidth:"wide"}),day:zr({values:{narrow:["S","M","T","W","T","F","S"],short:["Su","Mo","Tu","We","Th","Fr","Sa"],abbreviated:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],wide:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]},defaultWidth:"wide"}),dayPeriod:zr({values:{narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"}},defaultWidth:"wide",formattingValues:{narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"}},defaultFormattingWidth:"wide"})};function Nr(t){return(e,n={})=>{const i=n.width,s=i&&t.matchPatterns[i]||t.matchPatterns[t.defaultMatchWidth],o=e.match(s);if(!o)return null;const a=o[0],r=i&&t.parsePatterns[i]||t.parsePatterns[t.defaultParseWidth],c=Array.isArray(r)?function(t,e){for(let n=0;n<t.length;n++)if(e(t[n]))return n;return}(r,(t=>t.test(a))):function(t,e){for(const n in t)if(Object.prototype.hasOwnProperty.call(t,n)&&e(t[n]))return n;return}(r,(t=>t.test(a)));let l;l=t.valueCallback?t.valueCallback(c):c,l=n.valueCallback?n.valueCallback(l):l;return{value:l,rest:e.slice(a.length)}}}const Rr={ordinalNumber:($r={matchPattern:/^(\d+)(th|st|nd|rd)?/i,parsePattern:/\d+/i,valueCallback:t=>parseInt(t,10)},(t,e={})=>{const n=t.match($r.matchPattern);if(!n)return null;const i=n[0],s=t.match($r.parsePattern);if(!s)return null;let o=$r.valueCallback?$r.valueCallback(s[0]):s[0];return o=e.valueCallback?e.valueCallback(o):o,{value:o,rest:t.slice(i.length)}}),era:Nr({matchPatterns:{narrow:/^(b|a)/i,abbreviated:/^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,wide:/^(before christ|before common era|anno domini|common era)/i},defaultMatchWidth:"wide",parsePatterns:{any:[/^b/i,/^(a|c)/i]},defaultParseWidth:"any"}),quarter:Nr({matchPatterns:{narrow:/^[1234]/i,abbreviated:/^q[1234]/i,wide:/^[1234](th|st|nd|rd)? quarter/i},defaultMatchWidth:"wide",parsePatterns:{any:[/1/i,/2/i,/3/i,/4/i]},defaultParseWidth:"any",valueCallback:t=>t+1}),month:Nr({matchPatterns:{narrow:/^[jfmasond]/i,abbreviated:/^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,wide:/^(january|february|march|april|may|june|july|august|september|october|november|december)/i},defaultMatchWidth:"wide",parsePatterns:{narrow:[/^j/i,/^f/i,/^m/i,/^a/i,/^m/i,/^j/i,/^j/i,/^a/i,/^s/i,/^o/i,/^n/i,/^d/i],any:[/^ja/i,/^f/i,/^mar/i,/^ap/i,/^may/i,/^jun/i,/^jul/i,/^au/i,/^s/i,/^o/i,/^n/i,/^d/i]},defaultParseWidth:"any"}),day:Nr({matchPatterns:{narrow:/^[smtwf]/i,short:/^(su|mo|tu|we|th|fr|sa)/i,abbreviated:/^(sun|mon|tue|wed|thu|fri|sat)/i,wide:/^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i},defaultMatchWidth:"wide",parsePatterns:{narrow:[/^s/i,/^m/i,/^t/i,/^w/i,/^t/i,/^f/i,/^s/i],any:[/^su/i,/^m/i,/^tu/i,/^w/i,/^th/i,/^f/i,/^sa/i]},defaultParseWidth:"any"}),dayPeriod:Nr({matchPatterns:{narrow:/^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,any:/^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i},defaultMatchWidth:"any",parsePatterns:{any:{am:/^a/i,pm:/^p/i,midnight:/^mi/i,noon:/^no/i,morning:/morning/i,afternoon:/afternoon/i,evening:/evening/i,night:/night/i}},defaultParseWidth:"any"})};var $r;const Fr={code:"en-US",formatDistance:(t,e,n)=>{let i;const s=Ar[t];return i="string"==typeof s?s:1===e?s.one:s.other.replace("{{count}}",e.toString()),n?.addSuffix?n.comparison&&n.comparison>0?"in "+i:i+" ago":i},formatLong:Ir,formatRelative:(t,e,n,i)=>Or[t],localize:Wr,match:Rr,options:{weekStartsOn:0,firstWeekContainsDate:1}};function qr(t,e){const n=rr(t,e?.in),i=+pr(n)-+function(t,e){const n=mr(t,e),i=ar(e?.in||t,0);return i.setFullYear(n,0,4),i.setHours(0,0,0,0),pr(i)}(n);return Math.round(i/nr)+1}function Br(t,e){const n=rr(t,e?.in),i=n.getFullYear(),s=ur(),o=e?.firstWeekContainsDate??e?.locale?.options?.firstWeekContainsDate??s.firstWeekContainsDate??s.locale?.options?.firstWeekContainsDate??1,a=ar(e?.in||t,0);a.setFullYear(i+1,0,o),a.setHours(0,0,0,0);const r=gr(a,e),c=ar(e?.in||t,0);c.setFullYear(i,0,o),c.setHours(0,0,0,0);const l=gr(c,e);return+n>=+r?i+1:+n>=+l?i:i-1}function Hr(t,e){const n=rr(t,e?.in),i=+gr(n,e)-+function(t,e){const n=ur(),i=e?.firstWeekContainsDate??e?.locale?.options?.firstWeekContainsDate??n.firstWeekContainsDate??n.locale?.options?.firstWeekContainsDate??1,s=Br(t,e),o=ar(e?.in||t,0);return o.setFullYear(s,0,i),o.setHours(0,0,0,0),gr(o,e)}(n,e);return Math.round(i/nr)+1}function Vr(t,e){return(t<0?"-":"")+Math.abs(t).toString().padStart(e,"0")}const jr={y(t,e){const n=t.getFullYear(),i=n>0?n:1-n;return Vr("yy"===e?i%100:i,e.length)},M(t,e){const n=t.getMonth();return"M"===e?String(n+1):Vr(n+1,2)},d:(t,e)=>Vr(t.getDate(),e.length),a(t,e){const n=t.getHours()/12>=1?"pm":"am";switch(e){case"a":case"aa":return n.toUpperCase();case"aaa":return n;case"aaaaa":return n[0];default:return"am"===n?"a.m.":"p.m."}},h:(t,e)=>Vr(t.getHours()%12||12,e.length),H:(t,e)=>Vr(t.getHours(),e.length),m:(t,e)=>Vr(t.getMinutes(),e.length),s:(t,e)=>Vr(t.getSeconds(),e.length),S(t,e){const n=e.length,i=t.getMilliseconds();return Vr(Math.trunc(i*Math.pow(10,n-3)),e.length)}},Yr="midnight",Ur="noon",Xr="morning",Qr="afternoon",Kr="evening",Zr="night",Gr={G:function(t,e,n){const i=t.getFullYear()>0?1:0;switch(e){case"G":case"GG":case"GGG":return n.era(i,{width:"abbreviated"});case"GGGGG":return n.era(i,{width:"narrow"});default:return n.era(i,{width:"wide"})}},y:function(t,e,n){if("yo"===e){const e=t.getFullYear(),i=e>0?e:1-e;return n.ordinalNumber(i,{unit:"year"})}return jr.y(t,e)},Y:function(t,e,n,i){const s=Br(t,i),o=s>0?s:1-s;if("YY"===e){return Vr(o%100,2)}return"Yo"===e?n.ordinalNumber(o,{unit:"year"}):Vr(o,e.length)},R:function(t,e){return Vr(mr(t),e.length)},u:function(t,e){return Vr(t.getFullYear(),e.length)},Q:function(t,e,n){const i=Math.ceil((t.getMonth()+1)/3);switch(e){case"Q":return String(i);case"QQ":return Vr(i,2);case"Qo":return n.ordinalNumber(i,{unit:"quarter"});case"QQQ":return n.quarter(i,{width:"abbreviated",context:"formatting"});case"QQQQQ":return n.quarter(i,{width:"narrow",context:"formatting"});default:return n.quarter(i,{width:"wide",context:"formatting"})}},q:function(t,e,n){const i=Math.ceil((t.getMonth()+1)/3);switch(e){case"q":return String(i);case"qq":return Vr(i,2);case"qo":return n.ordinalNumber(i,{unit:"quarter"});case"qqq":return n.quarter(i,{width:"abbreviated",context:"standalone"});case"qqqqq":return n.quarter(i,{width:"narrow",context:"standalone"});default:return n.quarter(i,{width:"wide",context:"standalone"})}},M:function(t,e,n){const i=t.getMonth();switch(e){case"M":case"MM":return jr.M(t,e);case"Mo":return n.ordinalNumber(i+1,{unit:"month"});case"MMM":return n.month(i,{width:"abbreviated",context:"formatting"});case"MMMMM":return n.month(i,{width:"narrow",context:"formatting"});default:return n.month(i,{width:"wide",context:"formatting"})}},L:function(t,e,n){const i=t.getMonth();switch(e){case"L":return String(i+1);case"LL":return Vr(i+1,2);case"Lo":return n.ordinalNumber(i+1,{unit:"month"});case"LLL":return n.month(i,{width:"abbreviated",context:"standalone"});case"LLLLL":return n.month(i,{width:"narrow",context:"standalone"});default:return n.month(i,{width:"wide",context:"standalone"})}},w:function(t,e,n,i){const s=Hr(t,i);return"wo"===e?n.ordinalNumber(s,{unit:"week"}):Vr(s,e.length)},I:function(t,e,n){const i=qr(t);return"Io"===e?n.ordinalNumber(i,{unit:"week"}):Vr(i,e.length)},d:function(t,e,n){return"do"===e?n.ordinalNumber(t.getDate(),{unit:"date"}):jr.d(t,e)},D:function(t,e,n){const i=function(t,e){const n=rr(t,e?.in);return xr(n,Er(n))+1}(t);return"Do"===e?n.ordinalNumber(i,{unit:"dayOfYear"}):Vr(i,e.length)},E:function(t,e,n){const i=t.getDay();switch(e){case"E":case"EE":case"EEE":return n.day(i,{width:"abbreviated",context:"formatting"});case"EEEEE":return n.day(i,{width:"narrow",context:"formatting"});case"EEEEEE":return n.day(i,{width:"short",context:"formatting"});default:return n.day(i,{width:"wide",context:"formatting"})}},e:function(t,e,n,i){const s=t.getDay(),o=(s-i.weekStartsOn+8)%7||7;switch(e){case"e":return String(o);case"ee":return Vr(o,2);case"eo":return n.ordinalNumber(o,{unit:"day"});case"eee":return n.day(s,{width:"abbreviated",context:"formatting"});case"eeeee":return n.day(s,{width:"narrow",context:"formatting"});case"eeeeee":return n.day(s,{width:"short",context:"formatting"});default:return n.day(s,{width:"wide",context:"formatting"})}},c:function(t,e,n,i){const s=t.getDay(),o=(s-i.weekStartsOn+8)%7||7;switch(e){case"c":return String(o);case"cc":return Vr(o,e.length);case"co":return n.ordinalNumber(o,{unit:"day"});case"ccc":return n.day(s,{width:"abbreviated",context:"standalone"});case"ccccc":return n.day(s,{width:"narrow",context:"standalone"});case"cccccc":return n.day(s,{width:"short",context:"standalone"});default:return n.day(s,{width:"wide",context:"standalone"})}},i:function(t,e,n){const i=t.getDay(),s=0===i?7:i;switch(e){case"i":return String(s);case"ii":return Vr(s,e.length);case"io":return n.ordinalNumber(s,{unit:"day"});case"iii":return n.day(i,{width:"abbreviated",context:"formatting"});case"iiiii":return n.day(i,{width:"narrow",context:"formatting"});case"iiiiii":return n.day(i,{width:"short",context:"formatting"});default:return n.day(i,{width:"wide",context:"formatting"})}},a:function(t,e,n){const i=t.getHours()/12>=1?"pm":"am";switch(e){case"a":case"aa":return n.dayPeriod(i,{width:"abbreviated",context:"formatting"});case"aaa":return n.dayPeriod(i,{width:"abbreviated",context:"formatting"}).toLowerCase();case"aaaaa":return n.dayPeriod(i,{width:"narrow",context:"formatting"});default:return n.dayPeriod(i,{width:"wide",context:"formatting"})}},b:function(t,e,n){const i=t.getHours();let s;switch(s=12===i?Ur:0===i?Yr:i/12>=1?"pm":"am",e){case"b":case"bb":return n.dayPeriod(s,{width:"abbreviated",context:"formatting"});case"bbb":return n.dayPeriod(s,{width:"abbreviated",context:"formatting"}).toLowerCase();case"bbbbb":return n.dayPeriod(s,{width:"narrow",context:"formatting"});default:return n.dayPeriod(s,{width:"wide",context:"formatting"})}},B:function(t,e,n){const i=t.getHours();let s;switch(s=i>=17?Kr:i>=12?Qr:i>=4?Xr:Zr,e){case"B":case"BB":case"BBB":return n.dayPeriod(s,{width:"abbreviated",context:"formatting"});case"BBBBB":return n.dayPeriod(s,{width:"narrow",context:"formatting"});default:return n.dayPeriod(s,{width:"wide",context:"formatting"})}},h:function(t,e,n){if("ho"===e){let e=t.getHours()%12;return 0===e&&(e=12),n.ordinalNumber(e,{unit:"hour"})}return jr.h(t,e)},H:function(t,e,n){return"Ho"===e?n.ordinalNumber(t.getHours(),{unit:"hour"}):jr.H(t,e)},K:function(t,e,n){const i=t.getHours()%12;return"Ko"===e?n.ordinalNumber(i,{unit:"hour"}):Vr(i,e.length)},k:function(t,e,n){let i=t.getHours();return 0===i&&(i=24),"ko"===e?n.ordinalNumber(i,{unit:"hour"}):Vr(i,e.length)},m:function(t,e,n){return"mo"===e?n.ordinalNumber(t.getMinutes(),{unit:"minute"}):jr.m(t,e)},s:function(t,e,n){return"so"===e?n.ordinalNumber(t.getSeconds(),{unit:"second"}):jr.s(t,e)},S:function(t,e){return jr.S(t,e)},X:function(t,e,n){const i=t.getTimezoneOffset();if(0===i)return"Z";switch(e){case"X":return tc(i);case"XXXX":case"XX":return ec(i);default:return ec(i,":")}},x:function(t,e,n){const i=t.getTimezoneOffset();switch(e){case"x":return tc(i);case"xxxx":case"xx":return ec(i);default:return ec(i,":")}},O:function(t,e,n){const i=t.getTimezoneOffset();switch(e){case"O":case"OO":case"OOO":return"GMT"+Jr(i,":");default:return"GMT"+ec(i,":")}},z:function(t,e,n){const i=t.getTimezoneOffset();switch(e){case"z":case"zz":case"zzz":return"GMT"+Jr(i,":");default:return"GMT"+ec(i,":")}},t:function(t,e,n){return Vr(Math.trunc(+t/1e3),e.length)},T:function(t,e,n){return Vr(+t,e.length)}};function Jr(t,e=""){const n=t>0?"-":"+",i=Math.abs(t),s=Math.trunc(i/60),o=i%60;return 0===o?n+String(s):n+String(s)+e+Vr(o,2)}function tc(t,e){if(t%60==0){return(t>0?"-":"+")+Vr(Math.abs(t)/60,2)}return ec(t,e)}function ec(t,e=""){const n=t>0?"-":"+",i=Math.abs(t);return n+Vr(Math.trunc(i/60),2)+e+Vr(i%60,2)}const nc=(t,e)=>{switch(t){case"P":return e.date({width:"short"});case"PP":return e.date({width:"medium"});case"PPP":return e.date({width:"long"});default:return e.date({width:"full"})}},ic=(t,e)=>{switch(t){case"p":return e.time({width:"short"});case"pp":return e.time({width:"medium"});case"ppp":return e.time({width:"long"});default:return e.time({width:"full"})}},sc={p:ic,P:(t,e)=>{const n=t.match(/(P+)(p+)?/)||[],i=n[1],s=n[2];if(!s)return nc(t,e);let o;switch(i){case"P":o=e.dateTime({width:"short"});break;case"PP":o=e.dateTime({width:"medium"});break;case"PPP":o=e.dateTime({width:"long"});break;default:o=e.dateTime({width:"full"})}return o.replace("{{date}}",nc(i,e)).replace("{{time}}",ic(s,e))}},oc=/^D+$/,ac=/^Y+$/,rc=["D","DD","YY","YYYY"];function cc(t){return oc.test(t)}function lc(t){return ac.test(t)}function dc(t,e,n){const i=function(t,e,n){const i="Y"===t[0]?"years":"days of the month";return`Use \`${t.toLowerCase()}\` instead of \`${t}\` (in \`${e}\`) for formatting ${i} to the input \`${n}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`}(t,e,n);if(console.warn(i),rc.includes(t))throw new RangeError(i)}const hc=/[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g,uc=/P+p+|P+|p+|''|'(''|[^'])+('|$)|./g,gc=/^'([^]*?)'?$/,pc=/''/g,mc=/[a-zA-Z]/;function fc(t){const e=t.match(gc);return e?e[1].replace(pc,"'"):t}class bc{subPriority=0;validate(t,e){return!0}}class yc extends bc{constructor(t,e,n,i,s){super(),this.value=t,this.validateValue=e,this.setValue=n,this.priority=i,s&&(this.subPriority=s)}validate(t,e){return this.validateValue(t,this.value,e)}set(t,e,n){return this.setValue(t,e,this.value,n)}}class xc extends bc{priority=10;subPriority=-1;constructor(t,e){super(),this.context=t||(t=>ar(e,t))}set(t,e){return e.timestampIsSet?t:ar(t,function(t,e){const n=function(t){return"function"==typeof t&&t.prototype?.constructor===t}(e)?new e(0):ar(e,0);return n.setFullYear(t.getFullYear(),t.getMonth(),t.getDate()),n.setHours(t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds()),n}(t,this.context))}}class vc{run(t,e,n,i){const s=this.parse(t,e,n,i);return s?{setter:new yc(s.value,this.validate,this.set,this.priority,this.subPriority),rest:s.rest}:null}validate(t,e,n){return!0}}const wc=/^(1[0-2]|0?\d)/,Sc=/^(3[0-1]|[0-2]?\d)/,kc=/^(36[0-6]|3[0-5]\d|[0-2]?\d?\d)/,Mc=/^(5[0-3]|[0-4]?\d)/,_c=/^(2[0-3]|[0-1]?\d)/,Cc=/^(2[0-4]|[0-1]?\d)/,Tc=/^(1[0-1]|0?\d)/,Dc=/^(1[0-2]|0?\d)/,Pc=/^[0-5]?\d/,Ec=/^[0-5]?\d/,Ac=/^\d/,Lc=/^\d{1,2}/,Ic=/^\d{1,3}/,Oc=/^\d{1,4}/,zc=/^-?\d+/,Wc=/^-?\d/,Nc=/^-?\d{1,2}/,Rc=/^-?\d{1,3}/,$c=/^-?\d{1,4}/,Fc=/^([+-])(\d{2})(\d{2})?|Z/,qc=/^([+-])(\d{2})(\d{2})|Z/,Bc=/^([+-])(\d{2})(\d{2})((\d{2}))?|Z/,Hc=/^([+-])(\d{2}):(\d{2})|Z/,Vc=/^([+-])(\d{2}):(\d{2})(:(\d{2}))?|Z/;function jc(t,e){return t?{value:e(t.value),rest:t.rest}:t}function Yc(t,e){const n=e.match(t);return n?{value:parseInt(n[0],10),rest:e.slice(n[0].length)}:null}function Uc(t,e){const n=e.match(t);if(!n)return null;if("Z"===n[0])return{value:0,rest:e.slice(1)};const i="+"===n[1]?1:-1,s=n[2]?parseInt(n[2],10):0,o=n[3]?parseInt(n[3],10):0,a=n[5]?parseInt(n[5],10):0;return{value:i*(s*sr+o*ir+1e3*a),rest:e.slice(n[0].length)}}function Xc(t){return Yc(zc,t)}function Qc(t,e){switch(t){case 1:return Yc(Ac,e);case 2:return Yc(Lc,e);case 3:return Yc(Ic,e);case 4:return Yc(Oc,e);default:return Yc(new RegExp("^\\d{1,"+t+"}"),e)}}function Kc(t,e){switch(t){case 1:return Yc(Wc,e);case 2:return Yc(Nc,e);case 3:return Yc(Rc,e);case 4:return Yc($c,e);default:return Yc(new RegExp("^-?\\d{1,"+t+"}"),e)}}function Zc(t){switch(t){case"morning":return 4;case"evening":return 17;case"pm":case"noon":case"afternoon":return 12;default:return 0}}function Gc(t,e){const n=e>0,i=n?e:1-e;let s;if(i<=50)s=t||100;else{const e=i+50;s=t+100*Math.trunc(e/100)-(t>=e%100?100:0)}return n?s:1-s}function Jc(t){return t%400==0||t%4==0&&t%100!=0}const tl=[31,28,31,30,31,30,31,31,30,31,30,31],el=[31,29,31,30,31,30,31,31,30,31,30,31];function nl(t,e,n){const i=ur(),s=n?.weekStartsOn??n?.locale?.options?.weekStartsOn??i.weekStartsOn??i.locale?.options?.weekStartsOn??0,o=rr(t,n?.in),a=o.getDay(),r=7-s;return cr(o,e<0||e>6?e-(a+r)%7:((e%7+7)%7+r)%7-(a+r)%7,n)}function il(t,e,n){const i=rr(t,n?.in),s=function(t,e){const n=rr(t,e?.in).getDay();return 0===n?7:n}(i,n);return cr(i,e-s,n)}const sl={G:new class extends vc{priority=140;parse(t,e,n){switch(e){case"G":case"GG":case"GGG":return n.era(t,{width:"abbreviated"})||n.era(t,{width:"narrow"});case"GGGGG":return n.era(t,{width:"narrow"});default:return n.era(t,{width:"wide"})||n.era(t,{width:"abbreviated"})||n.era(t,{width:"narrow"})}}set(t,e,n){return e.era=n,t.setFullYear(n,0,1),t.setHours(0,0,0,0),t}incompatibleTokens=["R","u","t","T"]},y:new class extends vc{priority=130;incompatibleTokens=["Y","R","u","w","I","i","e","c","t","T"];parse(t,e,n){const i=t=>({year:t,isTwoDigitYear:"yy"===e});switch(e){case"y":return jc(Qc(4,t),i);case"yo":return jc(n.ordinalNumber(t,{unit:"year"}),i);default:return jc(Qc(e.length,t),i)}}validate(t,e){return e.isTwoDigitYear||e.year>0}set(t,e,n){const i=t.getFullYear();if(n.isTwoDigitYear){const e=Gc(n.year,i);return t.setFullYear(e,0,1),t.setHours(0,0,0,0),t}const s="era"in e&&1!==e.era?1-n.year:n.year;return t.setFullYear(s,0,1),t.setHours(0,0,0,0),t}},Y:new class extends vc{priority=130;parse(t,e,n){const i=t=>({year:t,isTwoDigitYear:"YY"===e});switch(e){case"Y":return jc(Qc(4,t),i);case"Yo":return jc(n.ordinalNumber(t,{unit:"year"}),i);default:return jc(Qc(e.length,t),i)}}validate(t,e){return e.isTwoDigitYear||e.year>0}set(t,e,n,i){const s=Br(t,i);if(n.isTwoDigitYear){const e=Gc(n.year,s);return t.setFullYear(e,0,i.firstWeekContainsDate),t.setHours(0,0,0,0),gr(t,i)}const o="era"in e&&1!==e.era?1-n.year:n.year;return t.setFullYear(o,0,i.firstWeekContainsDate),t.setHours(0,0,0,0),gr(t,i)}incompatibleTokens=["y","R","u","Q","q","M","L","I","d","D","i","t","T"]},R:new class extends vc{priority=130;parse(t,e){return Kc("R"===e?4:e.length,t)}set(t,e,n){const i=ar(t,0);return i.setFullYear(n,0,4),i.setHours(0,0,0,0),pr(i)}incompatibleTokens=["G","y","Y","u","Q","q","M","L","w","d","D","e","c","t","T"]},u:new class extends vc{priority=130;parse(t,e){return Kc("u"===e?4:e.length,t)}set(t,e,n){return t.setFullYear(n,0,1),t.setHours(0,0,0,0),t}incompatibleTokens=["G","y","Y","R","w","I","i","e","c","t","T"]},Q:new class extends vc{priority=120;parse(t,e,n){switch(e){case"Q":case"QQ":return Qc(e.length,t);case"Qo":return n.ordinalNumber(t,{unit:"quarter"});case"QQQ":return n.quarter(t,{width:"abbreviated",context:"formatting"})||n.quarter(t,{width:"narrow",context:"formatting"});case"QQQQQ":return n.quarter(t,{width:"narrow",context:"formatting"});default:return n.quarter(t,{width:"wide",context:"formatting"})||n.quarter(t,{width:"abbreviated",context:"formatting"})||n.quarter(t,{width:"narrow",context:"formatting"})}}validate(t,e){return e>=1&&e<=4}set(t,e,n){return t.setMonth(3*(n-1),1),t.setHours(0,0,0,0),t}incompatibleTokens=["Y","R","q","M","L","w","I","d","D","i","e","c","t","T"]},q:new class extends vc{priority=120;parse(t,e,n){switch(e){case"q":case"qq":return Qc(e.length,t);case"qo":return n.ordinalNumber(t,{unit:"quarter"});case"qqq":return n.quarter(t,{width:"abbreviated",context:"standalone"})||n.quarter(t,{width:"narrow",context:"standalone"});case"qqqqq":return n.quarter(t,{width:"narrow",context:"standalone"});default:return n.quarter(t,{width:"wide",context:"standalone"})||n.quarter(t,{width:"abbreviated",context:"standalone"})||n.quarter(t,{width:"narrow",context:"standalone"})}}validate(t,e){return e>=1&&e<=4}set(t,e,n){return t.setMonth(3*(n-1),1),t.setHours(0,0,0,0),t}incompatibleTokens=["Y","R","Q","M","L","w","I","d","D","i","e","c","t","T"]},M:new class extends vc{incompatibleTokens=["Y","R","q","Q","L","w","I","D","i","e","c","t","T"];priority=110;parse(t,e,n){const i=t=>t-1;switch(e){case"M":return jc(Yc(wc,t),i);case"MM":return jc(Qc(2,t),i);case"Mo":return jc(n.ordinalNumber(t,{unit:"month"}),i);case"MMM":return n.month(t,{width:"abbreviated",context:"formatting"})||n.month(t,{width:"narrow",context:"formatting"});case"MMMMM":return n.month(t,{width:"narrow",context:"formatting"});default:return n.month(t,{width:"wide",context:"formatting"})||n.month(t,{width:"abbreviated",context:"formatting"})||n.month(t,{width:"narrow",context:"formatting"})}}validate(t,e){return e>=0&&e<=11}set(t,e,n){return t.setMonth(n,1),t.setHours(0,0,0,0),t}},L:new class extends vc{priority=110;parse(t,e,n){const i=t=>t-1;switch(e){case"L":return jc(Yc(wc,t),i);case"LL":return jc(Qc(2,t),i);case"Lo":return jc(n.ordinalNumber(t,{unit:"month"}),i);case"LLL":return n.month(t,{width:"abbreviated",context:"standalone"})||n.month(t,{width:"narrow",context:"standalone"});case"LLLLL":return n.month(t,{width:"narrow",context:"standalone"});default:return n.month(t,{width:"wide",context:"standalone"})||n.month(t,{width:"abbreviated",context:"standalone"})||n.month(t,{width:"narrow",context:"standalone"})}}validate(t,e){return e>=0&&e<=11}set(t,e,n){return t.setMonth(n,1),t.setHours(0,0,0,0),t}incompatibleTokens=["Y","R","q","Q","M","w","I","D","i","e","c","t","T"]},w:new class extends vc{priority=100;parse(t,e,n){switch(e){case"w":return Yc(Mc,t);case"wo":return n.ordinalNumber(t,{unit:"week"});default:return Qc(e.length,t)}}validate(t,e){return e>=1&&e<=53}set(t,e,n,i){return gr(function(t,e,n){const i=rr(t,n?.in),s=Hr(i,n)-e;return i.setDate(i.getDate()-7*s),rr(i,n?.in)}(t,n,i),i)}incompatibleTokens=["y","R","u","q","Q","M","L","I","d","D","i","t","T"]},I:new class extends vc{priority=100;parse(t,e,n){switch(e){case"I":return Yc(Mc,t);case"Io":return n.ordinalNumber(t,{unit:"week"});default:return Qc(e.length,t)}}validate(t,e){return e>=1&&e<=53}set(t,e,n){return pr(function(t,e,n){const i=rr(t,n?.in),s=qr(i,n)-e;return i.setDate(i.getDate()-7*s),i}(t,n))}incompatibleTokens=["y","Y","u","q","Q","M","L","w","d","D","e","c","t","T"]},d:new class extends vc{priority=90;subPriority=1;parse(t,e,n){switch(e){case"d":return Yc(Sc,t);case"do":return n.ordinalNumber(t,{unit:"date"});default:return Qc(e.length,t)}}validate(t,e){const n=Jc(t.getFullYear()),i=t.getMonth();return n?e>=1&&e<=el[i]:e>=1&&e<=tl[i]}set(t,e,n){return t.setDate(n),t.setHours(0,0,0,0),t}incompatibleTokens=["Y","R","q","Q","w","I","D","i","e","c","t","T"]},D:new class extends vc{priority=90;subpriority=1;parse(t,e,n){switch(e){case"D":case"DD":return Yc(kc,t);case"Do":return n.ordinalNumber(t,{unit:"date"});default:return Qc(e.length,t)}}validate(t,e){return Jc(t.getFullYear())?e>=1&&e<=366:e>=1&&e<=365}set(t,e,n){return t.setMonth(0,n),t.setHours(0,0,0,0),t}incompatibleTokens=["Y","R","q","Q","M","L","w","I","d","E","i","e","c","t","T"]},E:new class extends vc{priority=90;parse(t,e,n){switch(e){case"E":case"EE":case"EEE":return n.day(t,{width:"abbreviated",context:"formatting"})||n.day(t,{width:"short",context:"formatting"})||n.day(t,{width:"narrow",context:"formatting"});case"EEEEE":return n.day(t,{width:"narrow",context:"formatting"});case"EEEEEE":return n.day(t,{width:"short",context:"formatting"})||n.day(t,{width:"narrow",context:"formatting"});default:return n.day(t,{width:"wide",context:"formatting"})||n.day(t,{width:"abbreviated",context:"formatting"})||n.day(t,{width:"short",context:"formatting"})||n.day(t,{width:"narrow",context:"formatting"})}}validate(t,e){return e>=0&&e<=6}set(t,e,n,i){return(t=nl(t,n,i)).setHours(0,0,0,0),t}incompatibleTokens=["D","i","e","c","t","T"]},e:new class extends vc{priority=90;parse(t,e,n,i){const s=t=>{const e=7*Math.floor((t-1)/7);return(t+i.weekStartsOn+6)%7+e};switch(e){case"e":case"ee":return jc(Qc(e.length,t),s);case"eo":return jc(n.ordinalNumber(t,{unit:"day"}),s);case"eee":return n.day(t,{width:"abbreviated",context:"formatting"})||n.day(t,{width:"short",context:"formatting"})||n.day(t,{width:"narrow",context:"formatting"});case"eeeee":return n.day(t,{width:"narrow",context:"formatting"});case"eeeeee":return n.day(t,{width:"short",context:"formatting"})||n.day(t,{width:"narrow",context:"formatting"});default:return n.day(t,{width:"wide",context:"formatting"})||n.day(t,{width:"abbreviated",context:"formatting"})||n.day(t,{width:"short",context:"formatting"})||n.day(t,{width:"narrow",context:"formatting"})}}validate(t,e){return e>=0&&e<=6}set(t,e,n,i){return(t=nl(t,n,i)).setHours(0,0,0,0),t}incompatibleTokens=["y","R","u","q","Q","M","L","I","d","D","E","i","c","t","T"]},c:new class extends vc{priority=90;parse(t,e,n,i){const s=t=>{const e=7*Math.floor((t-1)/7);return(t+i.weekStartsOn+6)%7+e};switch(e){case"c":case"cc":return jc(Qc(e.length,t),s);case"co":return jc(n.ordinalNumber(t,{unit:"day"}),s);case"ccc":return n.day(t,{width:"abbreviated",context:"standalone"})||n.day(t,{width:"short",context:"standalone"})||n.day(t,{width:"narrow",context:"standalone"});case"ccccc":return n.day(t,{width:"narrow",context:"standalone"});case"cccccc":return n.day(t,{width:"short",context:"standalone"})||n.day(t,{width:"narrow",context:"standalone"});default:return n.day(t,{width:"wide",context:"standalone"})||n.day(t,{width:"abbreviated",context:"standalone"})||n.day(t,{width:"short",context:"standalone"})||n.day(t,{width:"narrow",context:"standalone"})}}validate(t,e){return e>=0&&e<=6}set(t,e,n,i){return(t=nl(t,n,i)).setHours(0,0,0,0),t}incompatibleTokens=["y","R","u","q","Q","M","L","I","d","D","E","i","e","t","T"]},i:new class extends vc{priority=90;parse(t,e,n){const i=t=>0===t?7:t;switch(e){case"i":case"ii":return Qc(e.length,t);case"io":return n.ordinalNumber(t,{unit:"day"});case"iii":return jc(n.day(t,{width:"abbreviated",context:"formatting"})||n.day(t,{width:"short",context:"formatting"})||n.day(t,{width:"narrow",context:"formatting"}),i);case"iiiii":return jc(n.day(t,{width:"narrow",context:"formatting"}),i);case"iiiiii":return jc(n.day(t,{width:"short",context:"formatting"})||n.day(t,{width:"narrow",context:"formatting"}),i);default:return jc(n.day(t,{width:"wide",context:"formatting"})||n.day(t,{width:"abbreviated",context:"formatting"})||n.day(t,{width:"short",context:"formatting"})||n.day(t,{width:"narrow",context:"formatting"}),i)}}validate(t,e){return e>=1&&e<=7}set(t,e,n){return(t=il(t,n)).setHours(0,0,0,0),t}incompatibleTokens=["y","Y","u","q","Q","M","L","w","d","D","E","e","c","t","T"]},a:new class extends vc{priority=80;parse(t,e,n){switch(e){case"a":case"aa":case"aaa":return n.dayPeriod(t,{width:"abbreviated",context:"formatting"})||n.dayPeriod(t,{width:"narrow",context:"formatting"});case"aaaaa":return n.dayPeriod(t,{width:"narrow",context:"formatting"});default:return n.dayPeriod(t,{width:"wide",context:"formatting"})||n.dayPeriod(t,{width:"abbreviated",context:"formatting"})||n.dayPeriod(t,{width:"narrow",context:"formatting"})}}set(t,e,n){return t.setHours(Zc(n),0,0,0),t}incompatibleTokens=["b","B","H","k","t","T"]},b:new class extends vc{priority=80;parse(t,e,n){switch(e){case"b":case"bb":case"bbb":return n.dayPeriod(t,{width:"abbreviated",context:"formatting"})||n.dayPeriod(t,{width:"narrow",context:"formatting"});case"bbbbb":return n.dayPeriod(t,{width:"narrow",context:"formatting"});default:return n.dayPeriod(t,{width:"wide",context:"formatting"})||n.dayPeriod(t,{width:"abbreviated",context:"formatting"})||n.dayPeriod(t,{width:"narrow",context:"formatting"})}}set(t,e,n){return t.setHours(Zc(n),0,0,0),t}incompatibleTokens=["a","B","H","k","t","T"]},B:new class extends vc{priority=80;parse(t,e,n){switch(e){case"B":case"BB":case"BBB":return n.dayPeriod(t,{width:"abbreviated",context:"formatting"})||n.dayPeriod(t,{width:"narrow",context:"formatting"});case"BBBBB":return n.dayPeriod(t,{width:"narrow",context:"formatting"});default:return n.dayPeriod(t,{width:"wide",context:"formatting"})||n.dayPeriod(t,{width:"abbreviated",context:"formatting"})||n.dayPeriod(t,{width:"narrow",context:"formatting"})}}set(t,e,n){return t.setHours(Zc(n),0,0,0),t}incompatibleTokens=["a","b","t","T"]},h:new class extends vc{priority=70;parse(t,e,n){switch(e){case"h":return Yc(Dc,t);case"ho":return n.ordinalNumber(t,{unit:"hour"});default:return Qc(e.length,t)}}validate(t,e){return e>=1&&e<=12}set(t,e,n){const i=t.getHours()>=12;return i&&n<12?t.setHours(n+12,0,0,0):i||12!==n?t.setHours(n,0,0,0):t.setHours(0,0,0,0),t}incompatibleTokens=["H","K","k","t","T"]},H:new class extends vc{priority=70;parse(t,e,n){switch(e){case"H":return Yc(_c,t);case"Ho":return n.ordinalNumber(t,{unit:"hour"});default:return Qc(e.length,t)}}validate(t,e){return e>=0&&e<=23}set(t,e,n){return t.setHours(n,0,0,0),t}incompatibleTokens=["a","b","h","K","k","t","T"]},K:new class extends vc{priority=70;parse(t,e,n){switch(e){case"K":return Yc(Tc,t);case"Ko":return n.ordinalNumber(t,{unit:"hour"});default:return Qc(e.length,t)}}validate(t,e){return e>=0&&e<=11}set(t,e,n){return t.getHours()>=12&&n<12?t.setHours(n+12,0,0,0):t.setHours(n,0,0,0),t}incompatibleTokens=["h","H","k","t","T"]},k:new class extends vc{priority=70;parse(t,e,n){switch(e){case"k":return Yc(Cc,t);case"ko":return n.ordinalNumber(t,{unit:"hour"});default:return Qc(e.length,t)}}validate(t,e){return e>=1&&e<=24}set(t,e,n){const i=n<=24?n%24:n;return t.setHours(i,0,0,0),t}incompatibleTokens=["a","b","h","H","K","t","T"]},m:new class extends vc{priority=60;parse(t,e,n){switch(e){case"m":return Yc(Pc,t);case"mo":return n.ordinalNumber(t,{unit:"minute"});default:return Qc(e.length,t)}}validate(t,e){return e>=0&&e<=59}set(t,e,n){return t.setMinutes(n,0,0),t}incompatibleTokens=["t","T"]},s:new class extends vc{priority=50;parse(t,e,n){switch(e){case"s":return Yc(Ec,t);case"so":return n.ordinalNumber(t,{unit:"second"});default:return Qc(e.length,t)}}validate(t,e){return e>=0&&e<=59}set(t,e,n){return t.setSeconds(n,0),t}incompatibleTokens=["t","T"]},S:new class extends vc{priority=30;parse(t,e){return jc(Qc(e.length,t),(t=>Math.trunc(t*Math.pow(10,3-e.length))))}set(t,e,n){return t.setMilliseconds(n),t}incompatibleTokens=["t","T"]},X:new class extends vc{priority=10;parse(t,e){switch(e){case"X":return Uc(Fc,t);case"XX":return Uc(qc,t);case"XXXX":return Uc(Bc,t);case"XXXXX":return Uc(Vc,t);default:return Uc(Hc,t)}}set(t,e,n){return e.timestampIsSet?t:ar(t,t.getTime()-fr(t)-n)}incompatibleTokens=["t","T","x"]},x:new class extends vc{priority=10;parse(t,e){switch(e){case"x":return Uc(Fc,t);case"xx":return Uc(qc,t);case"xxxx":return Uc(Bc,t);case"xxxxx":return Uc(Vc,t);default:return Uc(Hc,t)}}set(t,e,n){return e.timestampIsSet?t:ar(t,t.getTime()-fr(t)-n)}incompatibleTokens=["t","T","X"]},t:new class extends vc{priority=40;parse(t){return Xc(t)}set(t,e,n){return[ar(t,1e3*n),{timestampIsSet:!0}]}incompatibleTokens="*"},T:new class extends vc{priority=20;parse(t){return Xc(t)}set(t,e,n){return[ar(t,n),{timestampIsSet:!0}]}incompatibleTokens="*"}},ol=/[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g,al=/P+p+|P+|p+|''|'(''|[^'])+('|$)|./g,rl=/^'([^]*?)'?$/,cl=/''/g,ll=/\S/,dl=/[a-zA-Z]/;function hl(t,e,n,i){const s=()=>ar(i?.in||n,NaN),o=Object.assign({},ur()),a=i?.locale??o.locale??Fr,r=i?.firstWeekContainsDate??i?.locale?.options?.firstWeekContainsDate??o.firstWeekContainsDate??o.locale?.options?.firstWeekContainsDate??1,c=i?.weekStartsOn??i?.locale?.options?.weekStartsOn??o.weekStartsOn??o.locale?.options?.weekStartsOn??0;if(!e)return t?s():rr(n,i?.in);const l={firstWeekContainsDate:r,weekStartsOn:c,locale:a},d=[new xc(i?.in,n)],h=e.match(al).map((t=>{const e=t[0];if(e in sc){return(0,sc[e])(t,a.formatLong)}return t})).join("").match(ol),u=[];for(let n of h){!i?.useAdditionalWeekYearTokens&&lc(n)&&dc(n,e,t),!i?.useAdditionalDayOfYearTokens&&cc(n)&&dc(n,e,t);const o=n[0],r=sl[o];if(r){const{incompatibleTokens:e}=r;if(Array.isArray(e)){const t=u.find((t=>e.includes(t.token)||t.token===o));if(t)throw new RangeError(`The format string mustn't contain \`${t.fullToken}\` and \`${n}\` at the same time`)}else if("*"===r.incompatibleTokens&&u.length>0)throw new RangeError(`The format string mustn't contain \`${n}\` and any other token at the same time`);u.push({token:o,fullToken:n});const i=r.run(t,n,a.match,l);if(!i)return s();d.push(i.setter),t=i.rest}else{if(o.match(dl))throw new RangeError("Format string contains an unescaped latin alphabet character `"+o+"`");if("''"===n?n="'":"'"===o&&(n=n.match(rl)[1].replace(cl,"'")),0!==t.indexOf(n))return s();t=t.slice(n.length)}}if(t.length>0&&ll.test(t))return s();const g=d.map((t=>t.priority)).sort(((t,e)=>e-t)).filter(((t,e,n)=>n.indexOf(t)===e)).map((t=>d.filter((e=>e.priority===t)).sort(((t,e)=>e.subPriority-t.subPriority)))).map((t=>t[0]));let p=rr(n,i?.in);if(isNaN(+p))return s();const m={};for(const t of g){if(!t.validate(p,l))return s();const e=t.set(p,m,l);Array.isArray(e)?(p=e[0],Object.assign(m,e[1])):p=e}return p}function ul(t,e){const n=()=>ar(e?.in,NaN),i=e?.additionalDigits??2,s=function(t){const e={},n=t.split(gl.dateTimeDelimiter);let i;if(n.length>2)return e;/:/.test(n[0])?i=n[0]:(e.date=n[0],i=n[1],gl.timeZoneDelimiter.test(e.date)&&(e.date=t.split(gl.timeZoneDelimiter)[0],i=t.substr(e.date.length,t.length)));if(i){const t=gl.timezone.exec(i);t?(e.time=i.replace(t[1],""),e.timezone=t[1]):e.time=i}return e}(t);let o;if(s.date){const t=function(t,e){const n=new RegExp("^(?:(\\d{4}|[+-]\\d{"+(4+e)+"})|(\\d{2}|[+-]\\d{"+(2+e)+"})$)"),i=t.match(n);if(!i)return{year:NaN,restDateString:""};const s=i[1]?parseInt(i[1]):null,o=i[2]?parseInt(i[2]):null;return{year:null===o?s:100*o,restDateString:t.slice((i[1]||i[2]).length)}}(s.date,i);o=function(t,e){if(null===e)return new Date(NaN);const n=t.match(pl);if(!n)return new Date(NaN);const i=!!n[4],s=bl(n[1]),o=bl(n[2])-1,a=bl(n[3]),r=bl(n[4]),c=bl(n[5])-1;if(i)return function(t,e,n){return e>=1&&e<=53&&n>=0&&n<=6}(0,r,c)?function(t,e,n){const i=new Date(0);i.setUTCFullYear(t,0,4);const s=i.getUTCDay()||7,o=7*(e-1)+n+1-s;return i.setUTCDate(i.getUTCDate()+o),i}(e,r,c):new Date(NaN);{const t=new Date(0);return function(t,e,n){return e>=0&&e<=11&&n>=1&&n<=(xl[e]||(vl(t)?29:28))}(e,o,a)&&function(t,e){return e>=1&&e<=(vl(t)?366:365)}(e,s)?(t.setUTCFullYear(e,o,Math.max(s,a)),t):new Date(NaN)}}(t.restDateString,t.year)}if(!o||isNaN(+o))return n();const a=+o;let r,c=0;if(s.time&&(c=function(t){const e=t.match(ml);if(!e)return NaN;const n=yl(e[1]),i=yl(e[2]),s=yl(e[3]);if(!function(t,e,n){if(24===t)return 0===e&&0===n;return n>=0&&n<60&&e>=0&&e<60&&t>=0&&t<25}(n,i,s))return NaN;return n*sr+i*ir+1e3*s}(s.time),isNaN(c)))return n();if(!s.timezone){const t=new Date(a+c),n=rr(0,e?.in);return n.setFullYear(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate()),n.setHours(t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),t.getUTCMilliseconds()),n}return r=function(t){if("Z"===t)return 0;const e=t.match(fl);if(!e)return 0;const n="+"===e[1]?-1:1,i=parseInt(e[2]),s=e[3]&&parseInt(e[3])||0;if(!function(t,e){return e>=0&&e<=59}
|
|
20
|
+
*/class Jn{constructor(){this._request=null,this._charts=new Map,this._running=!1,this._lastDate=void 0}_notify(t,e,n,i){const s=e.listeners[i],o=e.duration;s.forEach((i=>i({chart:t,initial:e.initial,numSteps:o,currentStep:Math.min(n-e.start,o)})))}_refresh(){this._request||(this._running=!0,this._request=ce.call(window,(()=>{this._update(),this._request=null,this._running&&this._refresh()})))}_update(t=Date.now()){let e=0;this._charts.forEach(((n,i)=>{if(!n.running||!n.items.length)return;const s=n.items;let o,a=s.length-1,r=!1;for(;a>=0;--a)o=s[a],o._active?(o._total>n.duration&&(n.duration=o._total),o.tick(t),r=!0):(s[a]=s[s.length-1],s.pop());r&&(i.draw(),this._notify(i,n,t,"progress")),s.length||(n.running=!1,this._notify(i,n,t,"complete"),n.initial=!1),e+=s.length})),this._lastDate=t,0===e&&(this._running=!1)}_getAnims(t){const e=this._charts;let n=e.get(t);return n||(n={running:!1,initial:!0,items:[],listeners:{complete:[],progress:[]}},e.set(t,n)),n}listen(t,e,n){this._getAnims(t).listeners[e].push(n)}add(t,e){e&&e.length&&this._getAnims(t).items.push(...e)}has(t){return this._getAnims(t).items.length>0}start(t){const e=this._charts.get(t);e&&(e.running=!0,e.start=Date.now(),e.duration=e.items.reduce(((t,e)=>Math.max(t,e._duration)),0),this._refresh())}running(t){if(!this._running)return!1;const e=this._charts.get(t);return!!(e&&e.running&&e.items.length)}stop(t){const e=this._charts.get(t);if(!e||!e.items.length)return;const n=e.items;let i=n.length-1;for(;i>=0;--i)n[i].cancel();e.items=[],this._notify(t,e,Date.now(),"complete")}remove(t){return this._charts.delete(t)}}var ti=new Jn;const ei="transparent",ni={boolean:(t,e,n)=>n>.5?e:t,color(t,e,n){const i=xe(t||ei),s=i.valid&&xe(e||ei);return s&&s.valid?s.mix(i,n).hexString():e},number:(t,e,n)=>t+(e-t)*n};class ii{constructor(t,e,n,i){const s=e[n];i=nn([t.to,i,s,t.from]);const o=nn([t.from,s,i]);this._active=!0,this._fn=t.fn||ni[t.type||typeof o],this._easing=be[t.easing]||be.linear,this._start=Math.floor(Date.now()+(t.delay||0)),this._duration=this._total=Math.floor(t.duration),this._loop=!!t.loop,this._target=e,this._prop=n,this._from=o,this._to=i,this._promises=void 0}active(){return this._active}update(t,e,n){if(this._active){this._notify(!1);const i=this._target[this._prop],s=n-this._start,o=this._duration-s;this._start=n,this._duration=Math.floor(Math.max(o,t.duration)),this._total+=s,this._loop=!!t.loop,this._to=nn([t.to,e,i,t.from]),this._from=nn([t.from,i,e])}}cancel(){this._active&&(this.tick(Date.now()),this._active=!1,this._notify(!1))}tick(t){const e=t-this._start,n=this._duration,i=this._prop,s=this._from,o=this._loop,a=this._to;let r;if(this._active=s!==a&&(o||e<n),!this._active)return this._target[i]=a,void this._notify(!0);e<0?this._target[i]=s:(r=e/n%2,r=o&&r>1?2-r:r,r=this._easing(Math.min(1,Math.max(0,r))),this._target[i]=this._fn(s,a,r))}wait(){const t=this._promises||(this._promises=[]);return new Promise(((e,n)=>{t.push({res:e,rej:n})}))}_notify(t){const e=t?"res":"rej",n=this._promises||[];for(let t=0;t<n.length;t++)n[t][e]()}}class si{constructor(t,e){this._chart=t,this._properties=new Map,this.configure(e)}configure(t){if(!ut(t))return;const e=Object.keys(Le.animation),n=this._properties;Object.getOwnPropertyNames(t).forEach((i=>{const s=t[i];if(!ut(s))return;const o={};for(const t of e)o[t]=s[t];(ht(s.properties)&&s.properties||[i]).forEach((t=>{t!==i&&n.has(t)||n.set(t,o)}))}))}_animateOptions(t,e){const n=e.options,i=function(t,e){if(!e)return;let n=t.options;if(!n)return void(t.options=e);n.$shared&&(t.options=n=Object.assign({},n,{$shared:!1,$animations:{}}));return n}(t,n);if(!i)return[];const s=this._createAnimations(i,n);return n.$shared&&function(t,e){const n=[],i=Object.keys(e);for(let e=0;e<i.length;e++){const s=t[i[e]];s&&s.active()&&n.push(s.wait())}return Promise.all(n)}(t.options.$animations,n).then((()=>{t.options=n}),(()=>{})),s}_createAnimations(t,e){const n=this._properties,i=[],s=t.$animations||(t.$animations={}),o=Object.keys(e),a=Date.now();let r;for(r=o.length-1;r>=0;--r){const c=o[r];if("$"===c.charAt(0))continue;if("options"===c){i.push(...this._animateOptions(t,e));continue}const l=e[c];let d=s[c];const h=n.get(c);if(d){if(h&&d.active()){d.update(h,l,a);continue}d.cancel()}h&&h.duration?(s[c]=d=new ii(h,t,c,l),i.push(d)):t[c]=l}return i}update(t,e){if(0===this._properties.size)return void Object.assign(t,e);const n=this._createAnimations(t,e);return n.length?(ti.add(this._chart,n),!0):void 0}}function oi(t,e){const n=t&&t.options||{},i=n.reverse,s=void 0===n.min?e:0,o=void 0===n.max?e:0;return{start:i?o:s,end:i?s:o}}function ai(t,e){const n=[],i=t._getSortedDatasetMetas(e);let s,o;for(s=0,o=i.length;s<o;++s)n.push(i[s].index);return n}function ri(t,e,n,i={}){const s=t.keys,o="single"===i.mode;let a,r,c,l;if(null===e)return;let d=!1;for(a=0,r=s.length;a<r;++a){if(c=+s[a],c===n){if(d=!0,i.all)continue;break}l=t.values[c],gt(l)&&(o||0===e||qt(e)===qt(l))&&(e+=l)}return d||i.all?e:0}function ci(t,e){const n=t&&t.options.stacked;return n||void 0===n&&void 0!==e.stack}function li(t,e,n){const i=t[e]||(t[e]={});return i[n]||(i[n]={})}function di(t,e,n,i){for(const s of e.getMatchingVisibleMetas(i).reverse()){const e=t[s.index];if(n&&e>0||!n&&e<0)return s.index}return null}function hi(t,e){const{chart:n,_cachedMeta:i}=t,s=n._stacks||(n._stacks={}),{iScale:o,vScale:a,index:r}=i,c=o.axis,l=a.axis,d=function(t,e,n){return`${t.id}.${e.id}.${n.stack||n.type}`}(o,a,i),h=e.length;let u;for(let t=0;t<h;++t){const n=e[t],{[c]:o,[l]:h}=n;u=(n._stacks||(n._stacks={}))[l]=li(s,d,o),u[r]=h,u._top=di(u,a,!0,i.type),u._bottom=di(u,a,!1,i.type);(u._visualValues||(u._visualValues={}))[r]=h}}function ui(t,e){const n=t.scales;return Object.keys(n).filter((t=>n[t].axis===e)).shift()}function gi(t,e){const n=t.controller.index,i=t.vScale&&t.vScale.axis;if(i){e=e||t._parsed;for(const t of e){const e=t._stacks;if(!e||void 0===e[i]||void 0===e[i][n])return;delete e[i][n],void 0!==e[i]._visualValues&&void 0!==e[i]._visualValues[n]&&delete e[i]._visualValues[n]}}}const pi=t=>"reset"===t||"none"===t,mi=(t,e)=>e?t:Object.assign({},t);class fi{static defaults={};static datasetElementType=null;static dataElementType=null;constructor(t,e){this.chart=t,this._ctx=t.ctx,this.index=e,this._cachedDataOpts={},this._cachedMeta=this.getMeta(),this._type=this._cachedMeta.type,this.options=void 0,this._parsing=!1,this._data=void 0,this._objectData=void 0,this._sharedOptions=void 0,this._drawStart=void 0,this._drawCount=void 0,this.enableOptionSharing=!1,this.supportsDecimation=!1,this.$context=void 0,this._syncList=[],this.datasetElementType=new.target.datasetElementType,this.dataElementType=new.target.dataElementType,this.initialize()}initialize(){const t=this._cachedMeta;this.configure(),this.linkScales(),t._stacked=ci(t.vScale,t),this.addElements(),this.options.fill&&!this.chart.isPluginEnabled("filler")&&console.warn("Tried to use the 'fill' option without the 'Filler' plugin enabled. Please import and register the 'Filler' plugin and make sure it is not disabled in the options")}updateIndex(t){this.index!==t&&gi(this._cachedMeta),this.index=t}linkScales(){const t=this.chart,e=this._cachedMeta,n=this.getDataset(),i=(t,e,n,i)=>"x"===t?e:"r"===t?i:n,s=e.xAxisID=mt(n.xAxisID,ui(t,"x")),o=e.yAxisID=mt(n.yAxisID,ui(t,"y")),a=e.rAxisID=mt(n.rAxisID,ui(t,"r")),r=e.indexAxis,c=e.iAxisID=i(r,s,o,a),l=e.vAxisID=i(r,o,s,a);e.xScale=this.getScaleForId(s),e.yScale=this.getScaleForId(o),e.rScale=this.getScaleForId(a),e.iScale=this.getScaleForId(c),e.vScale=this.getScaleForId(l)}getDataset(){return this.chart.data.datasets[this.index]}getMeta(){return this.chart.getDatasetMeta(this.index)}getScaleForId(t){return this.chart.scales[t]}_getOtherScale(t){const e=this._cachedMeta;return t===e.iScale?e.vScale:e.iScale}reset(){this._update("reset")}_destroy(){const t=this._cachedMeta;this._data&&ae(this._data,this),t._stacked&&gi(t)}_dataCheck(){const t=this.getDataset(),e=t.data||(t.data=[]),n=this._data;if(ut(e)){const t=this._cachedMeta;this._data=function(t,e){const{iScale:n,vScale:i}=e,s="x"===n.axis?"x":"y",o="x"===i.axis?"x":"y",a=Object.keys(t),r=new Array(a.length);let c,l,d;for(c=0,l=a.length;c<l;++c)d=a[c],r[c]={[s]:d,[o]:t[d]};return r}(e,t)}else if(n!==e){if(n){ae(n,this);const t=this._cachedMeta;gi(t),t._parsed=[]}e&&Object.isExtensible(e)&&(s=this,(i=e)._chartjs?i._chartjs.listeners.push(s):(Object.defineProperty(i,"_chartjs",{configurable:!0,enumerable:!1,value:{listeners:[s]}}),oe.forEach((t=>{const e="_onData"+Tt(t),n=i[t];Object.defineProperty(i,t,{configurable:!0,enumerable:!1,value(...t){const s=n.apply(this,t);return i._chartjs.listeners.forEach((n=>{"function"==typeof n[e]&&n[e](...t)})),s}})})))),this._syncList=[],this._data=e}var i,s}addElements(){const t=this._cachedMeta;this._dataCheck(),this.datasetElementType&&(t.dataset=new this.datasetElementType)}buildOrUpdateElements(t){const e=this._cachedMeta,n=this.getDataset();let i=!1;this._dataCheck();const s=e._stacked;e._stacked=ci(e.vScale,e),e.stack!==n.stack&&(i=!0,gi(e),e.stack=n.stack),this._resyncElements(t),(i||s!==e._stacked)&&(hi(this,e._parsed),e._stacked=ci(e.vScale,e))}configure(){const t=this.chart.config,e=t.datasetScopeKeys(this._type),n=t.getOptionScopes(this.getDataset(),e,!0);this.options=t.createResolver(n,this.getContext()),this._parsing=this.options.parsing,this._cachedDataOpts={}}parse(t,e){const{_cachedMeta:n,_data:i}=this,{iScale:s,_stacked:o}=n,a=s.axis;let r,c,l,d=0===t&&e===i.length||n._sorted,h=t>0&&n._parsed[t-1];if(!1===this._parsing)n._parsed=i,n._sorted=!0,l=i;else{l=ht(i[t])?this.parseArrayData(n,i,t,e):ut(i[t])?this.parseObjectData(n,i,t,e):this.parsePrimitiveData(n,i,t,e);const s=()=>null===c[a]||h&&c[a]<h[a];for(r=0;r<e;++r)n._parsed[r+t]=c=l[r],d&&(s()&&(d=!1),h=c);n._sorted=d}o&&hi(this,l)}parsePrimitiveData(t,e,n,i){const{iScale:s,vScale:o}=t,a=s.axis,r=o.axis,c=s.getLabels(),l=s===o,d=new Array(i);let h,u,g;for(h=0,u=i;h<u;++h)g=h+n,d[h]={[a]:l||s.parse(c[g],g),[r]:o.parse(e[g],g)};return d}parseArrayData(t,e,n,i){const{xScale:s,yScale:o}=t,a=new Array(i);let r,c,l,d;for(r=0,c=i;r<c;++r)l=r+n,d=e[l],a[r]={x:s.parse(d[0],l),y:o.parse(d[1],l)};return a}parseObjectData(t,e,n,i){const{xScale:s,yScale:o}=t,{xAxisKey:a="x",yAxisKey:r="y"}=this._parsing,c=new Array(i);let l,d,h,u;for(l=0,d=i;l<d;++l)h=l+n,u=e[h],c[l]={x:s.parse(Dt(u,a),h),y:o.parse(Dt(u,r),h)};return c}getParsed(t){return this._cachedMeta._parsed[t]}getDataElement(t){return this._cachedMeta.data[t]}applyStack(t,e,n){const i=this.chart,s=this._cachedMeta,o=e[t.axis];return ri({keys:ai(i,!0),values:e._stacks[t.axis]._visualValues},o,s.index,{mode:n})}updateRangeFromParsed(t,e,n,i){const s=n[e.axis];let o=null===s?NaN:s;const a=i&&n._stacks[e.axis];i&&a&&(i.values=a,o=ri(i,s,this._cachedMeta.index)),t.min=Math.min(t.min,o),t.max=Math.max(t.max,o)}getMinMax(t,e){const n=this._cachedMeta,i=n._parsed,s=n._sorted&&t===n.iScale,o=i.length,a=this._getOtherScale(t),r=((t,e,n)=>t&&!e.hidden&&e._stacked&&{keys:ai(n,!0),values:null})(e,n,this.chart),c={min:Number.POSITIVE_INFINITY,max:Number.NEGATIVE_INFINITY},{min:l,max:d}=function(t){const{min:e,max:n,minDefined:i,maxDefined:s}=t.getUserBounds();return{min:i?e:Number.NEGATIVE_INFINITY,max:s?n:Number.POSITIVE_INFINITY}}(a);let h,u;function g(){u=i[h];const e=u[a.axis];return!gt(u[t.axis])||l>e||d<e}for(h=0;h<o&&(g()||(this.updateRangeFromParsed(c,t,u,r),!s));++h);if(s)for(h=o-1;h>=0;--h)if(!g()){this.updateRangeFromParsed(c,t,u,r);break}return c}getAllParsedValues(t){const e=this._cachedMeta._parsed,n=[];let i,s,o;for(i=0,s=e.length;i<s;++i)o=e[i][t.axis],gt(o)&&n.push(o);return n}getMaxOverflow(){return!1}getLabelAndValue(t){const e=this._cachedMeta,n=e.iScale,i=e.vScale,s=this.getParsed(t);return{label:n?""+n.getLabelForValue(s[n.axis]):"",value:i?""+i.getLabelForValue(s[i.axis]):""}}_update(t){const e=this._cachedMeta;this.update(t||"default"),e._clip=function(t){let e,n,i,s;return ut(t)?(e=t.top,n=t.right,i=t.bottom,s=t.left):e=n=i=s=t,{top:e,right:n,bottom:i,left:s,disabled:!1===t}}(mt(this.options.clip,function(t,e,n){if(!1===n)return!1;const i=oi(t,n),s=oi(e,n);return{top:s.end,right:i.end,bottom:s.start,left:i.start}}(e.xScale,e.yScale,this.getMaxOverflow())))}update(t){}draw(){const t=this._ctx,e=this.chart,n=this._cachedMeta,i=n.data||[],s=e.chartArea,o=[],a=this._drawStart||0,r=this._drawCount||i.length-a,c=this.options.drawActiveElementsOnTop;let l;for(n.dataset&&n.dataset.draw(t,s,a,r),l=a;l<a+r;++l){const e=i[l];e.hidden||(e.active&&c?o.push(e):e.draw(t,s))}for(l=0;l<o.length;++l)o[l].draw(t,s)}getStyle(t,e){const n=e?"active":"default";return void 0===t&&this._cachedMeta.dataset?this.resolveDatasetElementOptions(n):this.resolveDataElementOptions(t||0,n)}getContext(t,e,n){const i=this.getDataset();let s;if(t>=0&&t<this._cachedMeta.data.length){const e=this._cachedMeta.data[t];s=e.$context||(e.$context=function(t,e,n){return sn(t,{active:!1,dataIndex:e,parsed:void 0,raw:void 0,element:n,index:e,mode:"default",type:"data"})}(this.getContext(),t,e)),s.parsed=this.getParsed(t),s.raw=i.data[t],s.index=s.dataIndex=t}else s=this.$context||(this.$context=function(t,e){return sn(t,{active:!1,dataset:void 0,datasetIndex:e,index:e,mode:"default",type:"dataset"})}(this.chart.getContext(),this.index)),s.dataset=i,s.index=s.datasetIndex=this.index;return s.active=!!e,s.mode=n,s}resolveDatasetElementOptions(t){return this._resolveElementOptions(this.datasetElementType.id,t)}resolveDataElementOptions(t,e){return this._resolveElementOptions(this.dataElementType.id,e,t)}_resolveElementOptions(t,e="default",n){const i="active"===e,s=this._cachedDataOpts,o=t+"-"+e,a=s[o],r=this.enableOptionSharing&&Pt(n);if(a)return mi(a,r);const c=this.chart.config,l=c.datasetElementScopeKeys(this._type,t),d=i?[`${t}Hover`,"hover",t,""]:[t,""],h=c.getOptionScopes(this.getDataset(),l),u=Object.keys(Le.elements[t]),g=c.resolveNamedOptions(h,u,(()=>this.getContext(n,i,e)),d);return g.$shared&&(g.$shared=r,s[o]=Object.freeze(mi(g,r))),g}_resolveAnimations(t,e,n){const i=this.chart,s=this._cachedDataOpts,o=`animation-${e}`,a=s[o];if(a)return a;let r;if(!1!==i.options.animation){const i=this.chart.config,s=i.datasetAnimationScopeKeys(this._type,e),o=i.getOptionScopes(this.getDataset(),s);r=i.createResolver(o,this.getContext(t,n,e))}const c=new si(i,r&&r.animations);return r&&r._cacheable&&(s[o]=Object.freeze(c)),c}getSharedOptions(t){if(t.$shared)return this._sharedOptions||(this._sharedOptions=Object.assign({},t))}includeOptions(t,e){return!e||pi(t)||this.chart._animationsDisabled}_getSharedOptions(t,e){const n=this.resolveDataElementOptions(t,e),i=this._sharedOptions,s=this.getSharedOptions(n),o=this.includeOptions(e,s)||s!==i;return this.updateSharedOptions(s,e,n),{sharedOptions:s,includeOptions:o}}updateElement(t,e,n,i){pi(i)?Object.assign(t,n):this._resolveAnimations(e,i).update(t,n)}updateSharedOptions(t,e,n){t&&!pi(e)&&this._resolveAnimations(void 0,e).update(t,n)}_setStyle(t,e,n,i){t.active=i;const s=this.getStyle(e,i);this._resolveAnimations(e,n,i).update(t,{options:!i&&this.getSharedOptions(s)||s})}removeHoverStyle(t,e,n){this._setStyle(t,n,"active",!1)}setHoverStyle(t,e,n){this._setStyle(t,n,"active",!0)}_removeDatasetHoverStyle(){const t=this._cachedMeta.dataset;t&&this._setStyle(t,void 0,"active",!1)}_setDatasetHoverStyle(){const t=this._cachedMeta.dataset;t&&this._setStyle(t,void 0,"active",!0)}_resyncElements(t){const e=this._data,n=this._cachedMeta.data;for(const[t,e,n]of this._syncList)this[t](e,n);this._syncList=[];const i=n.length,s=e.length,o=Math.min(s,i);o&&this.parse(0,o),s>i?this._insertElements(i,s-i,t):s<i&&this._removeElements(s,i-s)}_insertElements(t,e,n=!0){const i=this._cachedMeta,s=i.data,o=t+e;let a;const r=t=>{for(t.length+=e,a=t.length-1;a>=o;a--)t[a]=t[a-e]};for(r(s),a=t;a<o;++a)s[a]=new this.dataElementType;this._parsing&&r(i._parsed),this.parse(t,e),n&&this.updateElements(s,t,e,"reset")}updateElements(t,e,n,i){}_removeElements(t,e){const n=this._cachedMeta;if(this._parsing){const i=n._parsed.splice(t,e);n._stacked&&gi(n,i)}n.data.splice(t,e)}_sync(t){if(this._parsing)this._syncList.push(t);else{const[e,n,i]=t;this[e](n,i)}this.chart._dataChanges.push([this.index,...t])}_onDataPush(){const t=arguments.length;this._sync(["_insertElements",this.getDataset().data.length-t,t])}_onDataPop(){this._sync(["_removeElements",this._cachedMeta.data.length-1,1])}_onDataShift(){this._sync(["_removeElements",0,1])}_onDataSplice(t,e){e&&this._sync(["_removeElements",t,e]);const n=arguments.length-2;n&&this._sync(["_insertElements",t,n])}_onDataUnshift(){this._sync(["_insertElements",0,arguments.length])}}function bi(t){const e=t.iScale,n=function(t,e){if(!t._cache.$bar){const n=t.getMatchingVisibleMetas(e);let i=[];for(let e=0,s=n.length;e<s;e++)i=i.concat(n[e].controller.getAllParsedValues(t));t._cache.$bar=re(i.sort(((t,e)=>t-e)))}return t._cache.$bar}(e,t.type);let i,s,o,a,r=e._length;const c=()=>{32767!==o&&-32768!==o&&(Pt(a)&&(r=Math.min(r,Math.abs(o-a)||r)),a=o)};for(i=0,s=n.length;i<s;++i)o=e.getPixelForValue(n[i]),c();for(a=void 0,i=0,s=e.ticks.length;i<s;++i)o=e.getPixelForTick(i),c();return r}function yi(t,e,n,i){return ht(t)?function(t,e,n,i){const s=n.parse(t[0],i),o=n.parse(t[1],i),a=Math.min(s,o),r=Math.max(s,o);let c=a,l=r;Math.abs(a)>Math.abs(r)&&(c=r,l=a),e[n.axis]=l,e._custom={barStart:c,barEnd:l,start:s,end:o,min:a,max:r}}(t,e,n,i):e[n.axis]=n.parse(t,i),e}function xi(t,e,n,i){const s=t.iScale,o=t.vScale,a=s.getLabels(),r=s===o,c=[];let l,d,h,u;for(l=n,d=n+i;l<d;++l)u=e[l],h={},h[s.axis]=r||s.parse(a[l],l),c.push(yi(u,h,o,l));return c}function vi(t){return t&&void 0!==t.barStart&&void 0!==t.barEnd}function wi(t,e,n,i){let s=e.borderSkipped;const o={};if(!s)return void(t.borderSkipped=o);if(!0===s)return void(t.borderSkipped={top:!0,right:!0,bottom:!0,left:!0});const{start:a,end:r,reverse:c,top:l,bottom:d}=function(t){let e,n,i,s,o;return t.horizontal?(e=t.base>t.x,n="left",i="right"):(e=t.base<t.y,n="bottom",i="top"),e?(s="end",o="start"):(s="start",o="end"),{start:n,end:i,reverse:e,top:s,bottom:o}}(t);"middle"===s&&n&&(t.enableBorderRadius=!0,(n._top||0)===i?s=l:(n._bottom||0)===i?s=d:(o[Si(d,a,r,c)]=!0,s=l)),o[Si(s,a,r,c)]=!0,t.borderSkipped=o}function Si(t,e,n,i){var s,o,a;return i?(a=n,t=ki(t=(s=t)===(o=e)?a:s===a?o:s,n,e)):t=ki(t,e,n),t}function ki(t,e,n){return"start"===t?e:"end"===t?n:t}function Mi(t,{inflateAmount:e},n){t.inflateAmount="auto"===e?1===n?.33:0:e}class Ci extends fi{static id="bar";static defaults={datasetElementType:!1,dataElementType:"bar",categoryPercentage:.8,barPercentage:.9,grouped:!0,animations:{numbers:{type:"number",properties:["x","y","base","width","height"]}}};static overrides={scales:{_index_:{type:"category",offset:!0,grid:{offset:!0}},_value_:{type:"linear",beginAtZero:!0}}};parsePrimitiveData(t,e,n,i){return xi(t,e,n,i)}parseArrayData(t,e,n,i){return xi(t,e,n,i)}parseObjectData(t,e,n,i){const{iScale:s,vScale:o}=t,{xAxisKey:a="x",yAxisKey:r="y"}=this._parsing,c="x"===s.axis?a:r,l="x"===o.axis?a:r,d=[];let h,u,g,p;for(h=n,u=n+i;h<u;++h)p=e[h],g={},g[s.axis]=s.parse(Dt(p,c),h),d.push(yi(Dt(p,l),g,o,h));return d}updateRangeFromParsed(t,e,n,i){super.updateRangeFromParsed(t,e,n,i);const s=n._custom;s&&e===this._cachedMeta.vScale&&(t.min=Math.min(t.min,s.min),t.max=Math.max(t.max,s.max))}getMaxOverflow(){return 0}getLabelAndValue(t){const e=this._cachedMeta,{iScale:n,vScale:i}=e,s=this.getParsed(t),o=s._custom,a=vi(o)?"["+o.start+", "+o.end+"]":""+i.getLabelForValue(s[i.axis]);return{label:""+n.getLabelForValue(s[n.axis]),value:a}}initialize(){this.enableOptionSharing=!0,super.initialize();this._cachedMeta.stack=this.getDataset().stack}update(t){const e=this._cachedMeta;this.updateElements(e.data,0,e.data.length,t)}updateElements(t,e,n,i){const s="reset"===i,{index:o,_cachedMeta:{vScale:a}}=this,r=a.getBasePixel(),c=a.isHorizontal(),l=this._getRuler(),{sharedOptions:d,includeOptions:h}=this._getSharedOptions(e,i);for(let u=e;u<e+n;u++){const e=this.getParsed(u),n=s||dt(e[a.axis])?{base:r,head:r}:this._calculateBarValuePixels(u),g=this._calculateBarIndexPixels(u,l),p=(e._stacks||{})[a.axis],m={horizontal:c,base:n.base,enableBorderRadius:!p||vi(e._custom)||o===p._top||o===p._bottom,x:c?n.head:g.center,y:c?g.center:n.head,height:c?g.size:Math.abs(n.size),width:c?Math.abs(n.size):g.size};h&&(m.options=d||this.resolveDataElementOptions(u,t[u].active?"active":i));const f=m.options||t[u].options;wi(m,f,p,o),Mi(m,f,l.ratio),this.updateElement(t[u],u,m,i)}}_getStacks(t,e){const{iScale:n}=this._cachedMeta,i=n.getMatchingVisibleMetas(this._type).filter((t=>t.controller.options.grouped)),s=n.options.stacked,o=[],a=this._cachedMeta.controller.getParsed(e),r=a&&a[n.axis],c=t=>{const e=t._parsed.find((t=>t[n.axis]===r)),i=e&&e[t.vScale.axis];if(dt(i)||isNaN(i))return!0};for(const n of i)if((void 0===e||!c(n))&&((!1===s||-1===o.indexOf(n.stack)||void 0===s&&void 0===n.stack)&&o.push(n.stack),n.index===t))break;return o.length||o.push(void 0),o}_getStackCount(t){return this._getStacks(void 0,t).length}_getAxisCount(){return this._getAxis().length}getFirstScaleIdForIndexAxis(){const t=this.chart.scales,e=this.chart.options.indexAxis;return Object.keys(t).filter((n=>t[n].axis===e)).shift()}_getAxis(){const t={},e=this.getFirstScaleIdForIndexAxis();for(const n of this.chart.data.datasets)t[mt("x"===this.chart.options.indexAxis?n.xAxisID:n.yAxisID,e)]=!0;return Object.keys(t)}_getStackIndex(t,e,n){const i=this._getStacks(t,n),s=void 0!==e?i.indexOf(e):-1;return-1===s?i.length-1:s}_getRuler(){const t=this.options,e=this._cachedMeta,n=e.iScale,i=[];let s,o;for(s=0,o=e.data.length;s<o;++s)i.push(n.getPixelForValue(this.getParsed(s)[n.axis],s));const a=t.barThickness;return{min:a||bi(e),pixels:i,start:n._startPixel,end:n._endPixel,stackCount:this._getStackCount(),scale:n,grouped:t.grouped,ratio:a?1:t.categoryPercentage*t.barPercentage}}_calculateBarValuePixels(t){const{_cachedMeta:{vScale:e,_stacked:n,index:i},options:{base:s,minBarLength:o}}=this,a=s||0,r=this.getParsed(t),c=r._custom,l=vi(c);let d,h,u=r[e.axis],g=0,p=n?this.applyStack(e,r,n):u;p!==u&&(g=p-u,p=u),l&&(u=c.barStart,p=c.barEnd-c.barStart,0!==u&&qt(u)!==qt(c.barEnd)&&(g=0),g+=u);const m=dt(s)||l?g:s;let f=e.getPixelForValue(m);if(d=this.chart.getDataVisibility(t)?e.getPixelForValue(g+p):f,h=d-f,Math.abs(h)<o){h=function(t,e,n){return 0!==t?qt(t):(e.isHorizontal()?1:-1)*(e.min>=n?1:-1)}(h,e,a)*o,u===a&&(f-=h/2);const t=e.getPixelForDecimal(0),s=e.getPixelForDecimal(1),c=Math.min(t,s),g=Math.max(t,s);f=Math.max(Math.min(f,g),c),d=f+h,n&&!l&&(r._stacks[e.axis]._visualValues[i]=e.getValueForPixel(d)-e.getValueForPixel(f))}if(f===e.getPixelForValue(a)){const t=qt(h)*e.getLineWidthForValue(a)/2;f+=t,h-=t}return{size:h,base:f,head:d,center:d+h/2}}_calculateBarIndexPixels(t,e){const n=e.scale,i=this.options,s=i.skipNull,o=mt(i.maxBarThickness,1/0);let a,r;const c=this._getAxisCount();if(e.grouped){const n=s?this._getStackCount(t):e.stackCount,l="flex"===i.barThickness?function(t,e,n,i){const s=e.pixels,o=s[t];let a=t>0?s[t-1]:null,r=t<s.length-1?s[t+1]:null;const c=n.categoryPercentage;null===a&&(a=o-(null===r?e.end-e.start:r-o)),null===r&&(r=o+o-a);const l=o-(o-Math.min(a,r))/2*c;return{chunk:Math.abs(r-a)/2*c/i,ratio:n.barPercentage,start:l}}(t,e,i,n*c):function(t,e,n,i){const s=n.barThickness;let o,a;return dt(s)?(o=e.min*n.categoryPercentage,a=n.barPercentage):(o=s*i,a=1),{chunk:o/i,ratio:a,start:e.pixels[t]-o/2}}(t,e,i,n*c),d="x"===this.chart.options.indexAxis?this.getDataset().xAxisID:this.getDataset().yAxisID,h=this._getAxis().indexOf(mt(d,this.getFirstScaleIdForIndexAxis())),u=this._getStackIndex(this.index,this._cachedMeta.stack,s?t:void 0)+h;a=l.start+l.chunk*u+l.chunk/2,r=Math.min(o,l.chunk*l.ratio)}else a=n.getPixelForValue(this.getParsed(t)[n.axis],t),r=Math.min(o,e.min*e.ratio);return{base:a-r/2,head:a+r/2,center:a,size:r}}draw(){const t=this._cachedMeta,e=t.vScale,n=t.data,i=n.length;let s=0;for(;s<i;++s)null===this.getParsed(s)[e.axis]||n[s].hidden||n[s].draw(this._ctx)}}class _i extends fi{static id="doughnut";static defaults={datasetElementType:!1,dataElementType:"arc",animation:{animateRotate:!0,animateScale:!1},animations:{numbers:{type:"number",properties:["circumference","endAngle","innerRadius","outerRadius","startAngle","x","y","offset","borderWidth","spacing"]}},cutout:"50%",rotation:0,circumference:360,radius:"100%",spacing:0,indexAxis:"r"};static descriptors={_scriptable:t=>"spacing"!==t,_indexable:t=>"spacing"!==t&&!t.startsWith("borderDash")&&!t.startsWith("hoverBorderDash")};static overrides={aspectRatio:1,plugins:{legend:{labels:{generateLabels(t){const e=t.data,{labels:{pointStyle:n,textAlign:i,color:s,useBorderRadius:o,borderRadius:a}}=t.legend.options;return e.labels.length&&e.datasets.length?e.labels.map(((e,r)=>{const c=t.getDatasetMeta(0).controller.getStyle(r);return{text:e,fillStyle:c.backgroundColor,fontColor:s,hidden:!t.getDataVisibility(r),lineDash:c.borderDash,lineDashOffset:c.borderDashOffset,lineJoin:c.borderJoinStyle,lineWidth:c.borderWidth,strokeStyle:c.borderColor,textAlign:i,pointStyle:n,borderRadius:o&&(a||c.borderRadius),index:r}})):[]}},onClick(t,e,n){n.chart.toggleDataVisibility(e.index),n.chart.update()}}}};constructor(t,e){super(t,e),this.enableOptionSharing=!0,this.innerRadius=void 0,this.outerRadius=void 0,this.offsetX=void 0,this.offsetY=void 0}linkScales(){}parse(t,e){const n=this.getDataset().data,i=this._cachedMeta;if(!1===this._parsing)i._parsed=n;else{let s,o,a=t=>+n[t];if(ut(n[t])){const{key:t="value"}=this._parsing;a=e=>+Dt(n[e],t)}for(s=t,o=t+e;s<o;++s)i._parsed[s]=a(s)}}_getRotation(){return Yt(this.options.rotation-90)}_getCircumference(){return Yt(this.options.circumference)}_getRotationExtents(){let t=It,e=-It;for(let n=0;n<this.chart.data.datasets.length;++n)if(this.chart.isDatasetVisible(n)&&this.chart.getDatasetMeta(n).type===this._type){const i=this.chart.getDatasetMeta(n).controller,s=i._getRotation(),o=i._getCircumference();t=Math.min(t,s),e=Math.max(e,s+o)}return{rotation:t,circumference:e-t}}update(t){const e=this.chart,{chartArea:n}=e,i=this._cachedMeta,s=i.data,o=this.getMaxBorderWidth()+this.getMaxOffset(s)+this.options.spacing,a=Math.max((Math.min(n.width,n.height)-o)/2,0),r=Math.min((c=this.options.cutout,l=a,"string"==typeof c&&c.endsWith("%")?parseFloat(c)/100:+c/l),1);var c,l;const d=this._getRingWeight(this.index),{circumference:h,rotation:u}=this._getRotationExtents(),{ratioX:g,ratioY:p,offsetX:m,offsetY:f}=function(t,e,n){let i=1,s=1,o=0,a=0;if(e<It){const r=t,c=r+e,l=Math.cos(r),d=Math.sin(r),h=Math.cos(c),u=Math.sin(c),g=(t,e,i)=>Jt(t,r,c,!0)?1:Math.max(e,e*n,i,i*n),p=(t,e,i)=>Jt(t,r,c,!0)?-1:Math.min(e,e*n,i,i*n),m=g(0,l,h),f=g(Nt,d,u),b=p(Lt,l,h),y=p(Lt+Nt,d,u);i=(m-b)/2,s=(f-y)/2,o=-(m+b)/2,a=-(f+y)/2}return{ratioX:i,ratioY:s,offsetX:o,offsetY:a}}(u,h,r),b=(n.width-o)/g,y=(n.height-o)/p,x=Math.max(Math.min(b,y)/2,0),v=ft(this.options.radius,x),w=(v-Math.max(v*r,0))/this._getVisibleDatasetWeightTotal();this.offsetX=m*v,this.offsetY=f*v,i.total=this.calculateTotal(),this.outerRadius=v-w*this._getRingWeightOffset(this.index),this.innerRadius=Math.max(this.outerRadius-w*d,0),this.updateElements(s,0,s.length,t)}_circumference(t,e){const n=this.options,i=this._cachedMeta,s=this._getCircumference();return e&&n.animation.animateRotate||!this.chart.getDataVisibility(t)||null===i._parsed[t]||i.data[t].hidden?0:this.calculateCircumference(i._parsed[t]*s/It)}updateElements(t,e,n,i){const s="reset"===i,o=this.chart,a=o.chartArea,r=o.options.animation,c=(a.left+a.right)/2,l=(a.top+a.bottom)/2,d=s&&r.animateScale,h=d?0:this.innerRadius,u=d?0:this.outerRadius,{sharedOptions:g,includeOptions:p}=this._getSharedOptions(e,i);let m,f=this._getRotation();for(m=0;m<e;++m)f+=this._circumference(m,s);for(m=e;m<e+n;++m){const e=this._circumference(m,s),n=t[m],o={x:c+this.offsetX,y:l+this.offsetY,startAngle:f,endAngle:f+e,circumference:e,outerRadius:u,innerRadius:h};p&&(o.options=g||this.resolveDataElementOptions(m,n.active?"active":i)),f+=e,this.updateElement(n,m,o,i)}}calculateTotal(){const t=this._cachedMeta,e=t.data;let n,i=0;for(n=0;n<e.length;n++){const s=t._parsed[n];null===s||isNaN(s)||!this.chart.getDataVisibility(n)||e[n].hidden||(i+=Math.abs(s))}return i}calculateCircumference(t){const e=this._cachedMeta.total;return e>0&&!isNaN(t)?It*(Math.abs(t)/e):0}getLabelAndValue(t){const e=this._cachedMeta,n=this.chart,i=n.data.labels||[],s=Me(e._parsed[t],n.options.locale);return{label:i[t]||"",value:s}}getMaxBorderWidth(t){let e=0;const n=this.chart;let i,s,o,a,r;if(!t)for(i=0,s=n.data.datasets.length;i<s;++i)if(n.isDatasetVisible(i)){o=n.getDatasetMeta(i),t=o.data,a=o.controller;break}if(!t)return 0;for(i=0,s=t.length;i<s;++i)r=a.resolveDataElementOptions(i),"inner"!==r.borderAlign&&(e=Math.max(e,r.borderWidth||0,r.hoverBorderWidth||0));return e}getMaxOffset(t){let e=0;for(let n=0,i=t.length;n<i;++n){const t=this.resolveDataElementOptions(n);e=Math.max(e,t.offset||0,t.hoverOffset||0)}return e}_getRingWeightOffset(t){let e=0;for(let n=0;n<t;++n)this.chart.isDatasetVisible(n)&&(e+=this._getRingWeight(n));return e}_getRingWeight(t){return Math.max(mt(this.chart.data.datasets[t].weight,1),0)}_getVisibleDatasetWeightTotal(){return this._getRingWeightOffset(this.chart.data.datasets.length)||1}}class Di extends fi{static id="polarArea";static defaults={dataElementType:"arc",animation:{animateRotate:!0,animateScale:!0},animations:{numbers:{type:"number",properties:["x","y","startAngle","endAngle","innerRadius","outerRadius"]}},indexAxis:"r",startAngle:0};static overrides={aspectRatio:1,plugins:{legend:{labels:{generateLabels(t){const e=t.data;if(e.labels.length&&e.datasets.length){const{labels:{pointStyle:n,color:i}}=t.legend.options;return e.labels.map(((e,s)=>{const o=t.getDatasetMeta(0).controller.getStyle(s);return{text:e,fillStyle:o.backgroundColor,strokeStyle:o.borderColor,fontColor:i,lineWidth:o.borderWidth,pointStyle:n,hidden:!t.getDataVisibility(s),index:s}}))}return[]}},onClick(t,e,n){n.chart.toggleDataVisibility(e.index),n.chart.update()}}},scales:{r:{type:"radialLinear",angleLines:{display:!1},beginAtZero:!0,grid:{circular:!0},pointLabels:{display:!1},startAngle:0}}};constructor(t,e){super(t,e),this.innerRadius=void 0,this.outerRadius=void 0}getLabelAndValue(t){const e=this._cachedMeta,n=this.chart,i=n.data.labels||[],s=Me(e._parsed[t].r,n.options.locale);return{label:i[t]||"",value:s}}parseObjectData(t,e,n,i){return yn.bind(this)(t,e,n,i)}update(t){const e=this._cachedMeta.data;this._updateRadius(),this.updateElements(e,0,e.length,t)}getMinMax(){const t=this._cachedMeta,e={min:Number.POSITIVE_INFINITY,max:Number.NEGATIVE_INFINITY};return t.data.forEach(((t,n)=>{const i=this.getParsed(n).r;!isNaN(i)&&this.chart.getDataVisibility(n)&&(i<e.min&&(e.min=i),i>e.max&&(e.max=i))})),e}_updateRadius(){const t=this.chart,e=t.chartArea,n=t.options,i=Math.min(e.right-e.left,e.bottom-e.top),s=Math.max(i/2,0),o=(s-Math.max(n.cutoutPercentage?s/100*n.cutoutPercentage:1,0))/t.getVisibleDatasetCount();this.outerRadius=s-o*this.index,this.innerRadius=this.outerRadius-o}updateElements(t,e,n,i){const s="reset"===i,o=this.chart,a=o.options.animation,r=this._cachedMeta.rScale,c=r.xCenter,l=r.yCenter,d=r.getIndexAngle(0)-.5*Lt;let h,u=d;const g=360/this.countVisibleElements();for(h=0;h<e;++h)u+=this._computeAngle(h,i,g);for(h=e;h<e+n;h++){const e=t[h];let n=u,p=u+this._computeAngle(h,i,g),m=o.getDataVisibility(h)?r.getDistanceFromCenterForValue(this.getParsed(h).r):0;u=p,s&&(a.animateScale&&(m=0),a.animateRotate&&(n=p=d));const f={x:c,y:l,innerRadius:0,outerRadius:m,startAngle:n,endAngle:p,options:this.resolveDataElementOptions(h,e.active?"active":i)};this.updateElement(e,h,f,i)}}countVisibleElements(){const t=this._cachedMeta;let e=0;return t.data.forEach(((t,n)=>{!isNaN(this.getParsed(n).r)&&this.chart.getDataVisibility(n)&&e++})),e}_computeAngle(t,e,n){return this.chart.getDataVisibility(t)?Yt(this.resolveDataElementOptions(t,e).angle||n):0}}var Ti=Object.freeze({__proto__:null,BarController:Ci,BubbleController:class extends fi{static id="bubble";static defaults={datasetElementType:!1,dataElementType:"point",animations:{numbers:{type:"number",properties:["x","y","borderWidth","radius"]}}};static overrides={scales:{x:{type:"linear"},y:{type:"linear"}}};initialize(){this.enableOptionSharing=!0,super.initialize()}parsePrimitiveData(t,e,n,i){const s=super.parsePrimitiveData(t,e,n,i);for(let t=0;t<s.length;t++)s[t]._custom=this.resolveDataElementOptions(t+n).radius;return s}parseArrayData(t,e,n,i){const s=super.parseArrayData(t,e,n,i);for(let t=0;t<s.length;t++){const i=e[n+t];s[t]._custom=mt(i[2],this.resolveDataElementOptions(t+n).radius)}return s}parseObjectData(t,e,n,i){const s=super.parseObjectData(t,e,n,i);for(let t=0;t<s.length;t++){const i=e[n+t];s[t]._custom=mt(i&&i.r&&+i.r,this.resolveDataElementOptions(t+n).radius)}return s}getMaxOverflow(){const t=this._cachedMeta.data;let e=0;for(let n=t.length-1;n>=0;--n)e=Math.max(e,t[n].size(this.resolveDataElementOptions(n))/2);return e>0&&e}getLabelAndValue(t){const e=this._cachedMeta,n=this.chart.data.labels||[],{xScale:i,yScale:s}=e,o=this.getParsed(t),a=i.getLabelForValue(o.x),r=s.getLabelForValue(o.y),c=o._custom;return{label:n[t]||"",value:"("+a+", "+r+(c?", "+c:"")+")"}}update(t){const e=this._cachedMeta.data;this.updateElements(e,0,e.length,t)}updateElements(t,e,n,i){const s="reset"===i,{iScale:o,vScale:a}=this._cachedMeta,{sharedOptions:r,includeOptions:c}=this._getSharedOptions(e,i),l=o.axis,d=a.axis;for(let h=e;h<e+n;h++){const e=t[h],n=!s&&this.getParsed(h),u={},g=u[l]=s?o.getPixelForDecimal(.5):o.getPixelForValue(n[l]),p=u[d]=s?a.getBasePixel():a.getPixelForValue(n[d]);u.skip=isNaN(g)||isNaN(p),c&&(u.options=r||this.resolveDataElementOptions(h,e.active?"active":i),s&&(u.options.radius=0)),this.updateElement(e,h,u,i)}}resolveDataElementOptions(t,e){const n=this.getParsed(t);let i=super.resolveDataElementOptions(t,e);i.$shared&&(i=Object.assign({},i,{$shared:!1}));const s=i.radius;return"active"!==e&&(i.radius=0),i.radius+=mt(n&&n._custom,s),i}},DoughnutController:_i,LineController:class extends fi{static id="line";static defaults={datasetElementType:"line",dataElementType:"point",showLine:!0,spanGaps:!1};static overrides={scales:{_index_:{type:"category"},_value_:{type:"linear"}}};initialize(){this.enableOptionSharing=!0,this.supportsDecimation=!0,super.initialize()}update(t){const e=this._cachedMeta,{dataset:n,data:i=[],_dataset:s}=e,o=this.chart._animationsDisabled;let{start:a,count:r}=ue(e,i,o);this._drawStart=a,this._drawCount=r,ge(e)&&(a=0,r=i.length),n._chart=this.chart,n._datasetIndex=this.index,n._decimated=!!s._decimated,n.points=i;const c=this.resolveDatasetElementOptions(t);this.options.showLine||(c.borderWidth=0),c.segment=this.options.segment,this.updateElement(n,void 0,{animated:!o,options:c},t),this.updateElements(i,a,r,t)}updateElements(t,e,n,i){const s="reset"===i,{iScale:o,vScale:a,_stacked:r,_dataset:c}=this._cachedMeta,{sharedOptions:l,includeOptions:d}=this._getSharedOptions(e,i),h=o.axis,u=a.axis,{spanGaps:g,segment:p}=this.options,m=Vt(g)?g:Number.POSITIVE_INFINITY,f=this.chart._animationsDisabled||s||"none"===i,b=e+n,y=t.length;let x=e>0&&this.getParsed(e-1);for(let n=0;n<y;++n){const g=t[n],y=f?g:{};if(n<e||n>=b){y.skip=!0;continue}const v=this.getParsed(n),w=dt(v[u]),S=y[h]=o.getPixelForValue(v[h],n),k=y[u]=s||w?a.getBasePixel():a.getPixelForValue(r?this.applyStack(a,v,r):v[u],n);y.skip=isNaN(S)||isNaN(k)||w,y.stop=n>0&&Math.abs(v[h]-x[h])>m,p&&(y.parsed=v,y.raw=c.data[n]),d&&(y.options=l||this.resolveDataElementOptions(n,g.active?"active":i)),f||this.updateElement(g,n,y,i),x=v}}getMaxOverflow(){const t=this._cachedMeta,e=t.dataset,n=e.options&&e.options.borderWidth||0,i=t.data||[];if(!i.length)return n;const s=i[0].size(this.resolveDataElementOptions(0)),o=i[i.length-1].size(this.resolveDataElementOptions(i.length-1));return Math.max(n,s,o)/2}draw(){const t=this._cachedMeta;t.dataset.updateControlPoints(this.chart.chartArea,t.iScale.axis),super.draw()}},PieController:class extends _i{static id="pie";static defaults={cutout:0,rotation:0,circumference:360,radius:"100%"}},PolarAreaController:Di,RadarController:class extends fi{static id="radar";static defaults={datasetElementType:"line",dataElementType:"point",indexAxis:"r",showLine:!0,elements:{line:{fill:"start"}}};static overrides={aspectRatio:1,scales:{r:{type:"radialLinear"}}};getLabelAndValue(t){const e=this._cachedMeta.vScale,n=this.getParsed(t);return{label:e.getLabels()[t],value:""+e.getLabelForValue(n[e.axis])}}parseObjectData(t,e,n,i){return yn.bind(this)(t,e,n,i)}update(t){const e=this._cachedMeta,n=e.dataset,i=e.data||[],s=e.iScale.getLabels();if(n.points=i,"resize"!==t){const e=this.resolveDatasetElementOptions(t);this.options.showLine||(e.borderWidth=0);const o={_loop:!0,_fullLoop:s.length===i.length,options:e};this.updateElement(n,void 0,o,t)}this.updateElements(i,0,i.length,t)}updateElements(t,e,n,i){const s=this._cachedMeta.rScale,o="reset"===i;for(let a=e;a<e+n;a++){const e=t[a],n=this.resolveDataElementOptions(a,e.active?"active":i),r=s.getPointPositionForValue(a,this.getParsed(a).r),c=o?s.xCenter:r.x,l=o?s.yCenter:r.y,d={x:c,y:l,angle:r.angle,skip:isNaN(c)||isNaN(l),options:n};this.updateElement(e,a,d,i)}}},ScatterController:class extends fi{static id="scatter";static defaults={datasetElementType:!1,dataElementType:"point",showLine:!1,fill:!1};static overrides={interaction:{mode:"point"},scales:{x:{type:"linear"},y:{type:"linear"}}};getLabelAndValue(t){const e=this._cachedMeta,n=this.chart.data.labels||[],{xScale:i,yScale:s}=e,o=this.getParsed(t),a=i.getLabelForValue(o.x),r=s.getLabelForValue(o.y);return{label:n[t]||"",value:"("+a+", "+r+")"}}update(t){const e=this._cachedMeta,{data:n=[]}=e,i=this.chart._animationsDisabled;let{start:s,count:o}=ue(e,n,i);if(this._drawStart=s,this._drawCount=o,ge(e)&&(s=0,o=n.length),this.options.showLine){this.datasetElementType||this.addElements();const{dataset:s,_dataset:o}=e;s._chart=this.chart,s._datasetIndex=this.index,s._decimated=!!o._decimated,s.points=n;const a=this.resolveDatasetElementOptions(t);a.segment=this.options.segment,this.updateElement(s,void 0,{animated:!i,options:a},t)}else this.datasetElementType&&(delete e.dataset,this.datasetElementType=!1);this.updateElements(n,s,o,t)}addElements(){const{showLine:t}=this.options;!this.datasetElementType&&t&&(this.datasetElementType=this.chart.registry.getElement("line")),super.addElements()}updateElements(t,e,n,i){const s="reset"===i,{iScale:o,vScale:a,_stacked:r,_dataset:c}=this._cachedMeta,l=this.resolveDataElementOptions(e,i),d=this.getSharedOptions(l),h=this.includeOptions(i,d),u=o.axis,g=a.axis,{spanGaps:p,segment:m}=this.options,f=Vt(p)?p:Number.POSITIVE_INFINITY,b=this.chart._animationsDisabled||s||"none"===i;let y=e>0&&this.getParsed(e-1);for(let l=e;l<e+n;++l){const e=t[l],n=this.getParsed(l),p=b?e:{},x=dt(n[g]),v=p[u]=o.getPixelForValue(n[u],l),w=p[g]=s||x?a.getBasePixel():a.getPixelForValue(r?this.applyStack(a,n,r):n[g],l);p.skip=isNaN(v)||isNaN(w)||x,p.stop=l>0&&Math.abs(n[u]-y[u])>f,m&&(p.parsed=n,p.raw=c.data[l]),h&&(p.options=d||this.resolveDataElementOptions(l,e.active?"active":i)),b||this.updateElement(e,l,p,i),y=n}this.updateSharedOptions(d,i,l)}getMaxOverflow(){const t=this._cachedMeta,e=t.data||[];if(!this.options.showLine){let t=0;for(let n=e.length-1;n>=0;--n)t=Math.max(t,e[n].size(this.resolveDataElementOptions(n))/2);return t>0&&t}const n=t.dataset,i=n.options&&n.options.borderWidth||0;if(!e.length)return i;const s=e[0].size(this.resolveDataElementOptions(0)),o=e[e.length-1].size(this.resolveDataElementOptions(e.length-1));return Math.max(i,s,o)/2}}});function Pi(){throw new Error("This method is not implemented: Check that a complete date adapter is provided.")}class Ei{static override(t){Object.assign(Ei.prototype,t)}options;constructor(t){this.options=t||{}}init(){}formats(){return Pi()}parse(){return Pi()}format(){return Pi()}add(){return Pi()}diff(){return Pi()}startOf(){return Pi()}endOf(){return Pi()}}var Ai={_date:Ei};function Li(t,e,n,i){const{controller:s,data:o,_sorted:a}=t,r=s._cachedMeta.iScale,c=t.dataset&&t.dataset.options?t.dataset.options.spanGaps:null;if(r&&e===r.axis&&"r"!==e&&a&&o.length){const a=r._reversePixels?se:ie;if(!i){const i=a(o,e,n);if(c){const{vScale:e}=s._cachedMeta,{_parsed:n}=t,o=n.slice(0,i.lo+1).reverse().findIndex((t=>!dt(t[e.axis])));i.lo-=Math.max(0,o);const a=n.slice(i.hi).findIndex((t=>!dt(t[e.axis])));i.hi+=Math.max(0,a)}return i}if(s._sharedOptions){const t=o[0],i="function"==typeof t.getRange&&t.getRange(e);if(i){const t=a(o,e,n-i),s=a(o,e,n+i);return{lo:t.lo,hi:s.hi}}}}return{lo:0,hi:o.length-1}}function Ii(t,e,n,i,s){const o=t.getSortedVisibleDatasetMetas(),a=n[e];for(let t=0,n=o.length;t<n;++t){const{index:n,data:r}=o[t],{lo:c,hi:l}=Li(o[t],e,a,s);for(let t=c;t<=l;++t){const e=r[t];e.skip||i(e,n,t)}}}function Oi(t,e,n,i,s){const o=[];if(!s&&!t.isPointInArea(e))return o;return Ii(t,n,e,(function(n,a,r){(s||$e(n,t.chartArea,0))&&n.inRange(e.x,e.y,i)&&o.push({element:n,datasetIndex:a,index:r})}),!0),o}function zi(t,e,n,i,s,o){let a=[];const r=function(t){const e=-1!==t.indexOf("x"),n=-1!==t.indexOf("y");return function(t,i){const s=e?Math.abs(t.x-i.x):0,o=n?Math.abs(t.y-i.y):0;return Math.sqrt(Math.pow(s,2)+Math.pow(o,2))}}(n);let c=Number.POSITIVE_INFINITY;return Ii(t,n,e,(function(n,l,d){const h=n.inRange(e.x,e.y,s);if(i&&!h)return;const u=n.getCenterPoint(s);if(!(!!o||t.isPointInArea(u))&&!h)return;const g=r(e,u);g<c?(a=[{element:n,datasetIndex:l,index:d}],c=g):g===c&&a.push({element:n,datasetIndex:l,index:d})})),a}function Wi(t,e,n,i,s,o){return o||t.isPointInArea(e)?"r"!==n||i?zi(t,e,n,i,s,o):function(t,e,n,i){let s=[];return Ii(t,n,e,(function(t,n,o){const{startAngle:a,endAngle:r}=t.getProps(["startAngle","endAngle"],i),{angle:c}=Qt(t,{x:e.x,y:e.y});Jt(c,a,r)&&s.push({element:t,datasetIndex:n,index:o})})),s}(t,e,n,s):[]}function Ni(t,e,n,i,s){const o=[],a="x"===n?"inXRange":"inYRange";let r=!1;return Ii(t,n,e,((t,i,c)=>{t[a]&&t[a](e[n],s)&&(o.push({element:t,datasetIndex:i,index:c}),r=r||t.inRange(e.x,e.y,s))})),i&&!r?[]:o}var Ri={evaluateInteractionItems:Ii,modes:{index(t,e,n,i){const s=Ln(e,t),o=n.axis||"x",a=n.includeInvisible||!1,r=n.intersect?Oi(t,s,o,i,a):Wi(t,s,o,!1,i,a),c=[];return r.length?(t.getSortedVisibleDatasetMetas().forEach((t=>{const e=r[0].index,n=t.data[e];n&&!n.skip&&c.push({element:n,datasetIndex:t.index,index:e})})),c):[]},dataset(t,e,n,i){const s=Ln(e,t),o=n.axis||"xy",a=n.includeInvisible||!1;let r=n.intersect?Oi(t,s,o,i,a):Wi(t,s,o,!1,i,a);if(r.length>0){const e=r[0].datasetIndex,n=t.getDatasetMeta(e).data;r=[];for(let t=0;t<n.length;++t)r.push({element:n[t],datasetIndex:e,index:t})}return r},point:(t,e,n,i)=>Oi(t,Ln(e,t),n.axis||"xy",i,n.includeInvisible||!1),nearest(t,e,n,i){const s=Ln(e,t),o=n.axis||"xy",a=n.includeInvisible||!1;return Wi(t,s,o,n.intersect,i,a)},x:(t,e,n,i)=>Ni(t,Ln(e,t),"x",n.intersect,i),y:(t,e,n,i)=>Ni(t,Ln(e,t),"y",n.intersect,i)}};const $i=["left","top","right","bottom"];function Fi(t,e){return t.filter((t=>t.pos===e))}function qi(t,e){return t.filter((t=>-1===$i.indexOf(t.pos)&&t.box.axis===e))}function Bi(t,e){return t.sort(((t,n)=>{const i=e?n:t,s=e?t:n;return i.weight===s.weight?i.index-s.index:i.weight-s.weight}))}function Hi(t,e){const n=function(t){const e={};for(const n of t){const{stack:t,pos:i,stackWeight:s}=n;if(!t||!$i.includes(i))continue;const o=e[t]||(e[t]={count:0,placed:0,weight:0,size:0});o.count++,o.weight+=s}return e}(t),{vBoxMaxWidth:i,hBoxMaxHeight:s}=e;let o,a,r;for(o=0,a=t.length;o<a;++o){r=t[o];const{fullSize:a}=r.box,c=n[r.stack],l=c&&r.stackWeight/c.weight;r.horizontal?(r.width=l?l*i:a&&e.availableWidth,r.height=s):(r.width=i,r.height=l?l*s:a&&e.availableHeight)}return n}function Vi(t,e,n,i){return Math.max(t[n],e[n])+Math.max(t[i],e[i])}function ji(t,e){t.top=Math.max(t.top,e.top),t.left=Math.max(t.left,e.left),t.bottom=Math.max(t.bottom,e.bottom),t.right=Math.max(t.right,e.right)}function Yi(t,e,n,i){const{pos:s,box:o}=n,a=t.maxPadding;if(!ut(s)){n.size&&(t[s]-=n.size);const e=i[n.stack]||{size:0,count:1};e.size=Math.max(e.size,n.horizontal?o.height:o.width),n.size=e.size/e.count,t[s]+=n.size}o.getPadding&&ji(a,o.getPadding());const r=Math.max(0,e.outerWidth-Vi(a,t,"left","right")),c=Math.max(0,e.outerHeight-Vi(a,t,"top","bottom")),l=r!==t.w,d=c!==t.h;return t.w=r,t.h=c,n.horizontal?{same:l,other:d}:{same:d,other:l}}function Ui(t,e){const n=e.maxPadding;function i(t){const i={left:0,top:0,right:0,bottom:0};return t.forEach((t=>{i[t]=Math.max(e[t],n[t])})),i}return i(t?["left","right"]:["top","bottom"])}function Xi(t,e,n,i){const s=[];let o,a,r,c,l,d;for(o=0,a=t.length,l=0;o<a;++o){r=t[o],c=r.box,c.update(r.width||e.w,r.height||e.h,Ui(r.horizontal,e));const{same:a,other:h}=Yi(e,n,r,i);l|=a&&s.length,d=d||h,c.fullSize||s.push(r)}return l&&Xi(s,e,n,i)||d}function Qi(t,e,n,i,s){t.top=n,t.left=e,t.right=e+i,t.bottom=n+s,t.width=i,t.height=s}function Ki(t,e,n,i){const s=n.padding;let{x:o,y:a}=e;for(const r of t){const t=r.box,c=i[r.stack]||{count:1,placed:0,weight:1},l=r.stackWeight/c.weight||1;if(r.horizontal){const i=e.w*l,o=c.size||t.height;Pt(c.start)&&(a=c.start),t.fullSize?Qi(t,s.left,a,n.outerWidth-s.right-s.left,o):Qi(t,e.left+c.placed,a,i,o),c.start=a,c.placed+=i,a=t.bottom}else{const i=e.h*l,a=c.size||t.width;Pt(c.start)&&(o=c.start),t.fullSize?Qi(t,o,s.top,a,n.outerHeight-s.bottom-s.top):Qi(t,o,e.top+c.placed,a,i),c.start=o,c.placed+=i,o=t.right}}e.x=o,e.y=a}var Gi={addBox(t,e){t.boxes||(t.boxes=[]),e.fullSize=e.fullSize||!1,e.position=e.position||"top",e.weight=e.weight||0,e._layers=e._layers||function(){return[{z:0,draw(t){e.draw(t)}}]},t.boxes.push(e)},removeBox(t,e){const n=t.boxes?t.boxes.indexOf(e):-1;-1!==n&&t.boxes.splice(n,1)},configure(t,e,n){e.fullSize=n.fullSize,e.position=n.position,e.weight=n.weight},update(t,e,n,i){if(!t)return;const s=tn(t.options.layout.padding),o=Math.max(e-s.width,0),a=Math.max(n-s.height,0),r=function(t){const e=function(t){const e=[];let n,i,s,o,a,r;for(n=0,i=(t||[]).length;n<i;++n)s=t[n],({position:o,options:{stack:a,stackWeight:r=1}}=s),e.push({index:n,box:s,pos:o,horizontal:s.isHorizontal(),weight:s.weight,stack:a&&o+a,stackWeight:r});return e}(t),n=Bi(e.filter((t=>t.box.fullSize)),!0),i=Bi(Fi(e,"left"),!0),s=Bi(Fi(e,"right")),o=Bi(Fi(e,"top"),!0),a=Bi(Fi(e,"bottom")),r=qi(e,"x"),c=qi(e,"y");return{fullSize:n,leftAndTop:i.concat(o),rightAndBottom:s.concat(c).concat(a).concat(r),chartArea:Fi(e,"chartArea"),vertical:i.concat(s).concat(c),horizontal:o.concat(a).concat(r)}}(t.boxes),c=r.vertical,l=r.horizontal;yt(t.boxes,(t=>{"function"==typeof t.beforeLayout&&t.beforeLayout()}));const d=c.reduce(((t,e)=>e.box.options&&!1===e.box.options.display?t:t+1),0)||1,h=Object.freeze({outerWidth:e,outerHeight:n,padding:s,availableWidth:o,availableHeight:a,vBoxMaxWidth:o/2/d,hBoxMaxHeight:a/2}),u=Object.assign({},s);ji(u,tn(i));const g=Object.assign({maxPadding:u,w:o,h:a,x:s.left,y:s.top},s),p=Hi(c.concat(l),h);Xi(r.fullSize,g,h,p),Xi(c,g,h,p),Xi(l,g,h,p)&&Xi(c,g,h,p),function(t){const e=t.maxPadding;function n(n){const i=Math.max(e[n]-t[n],0);return t[n]+=i,i}t.y+=n("top"),t.x+=n("left"),n("right"),n("bottom")}(g),Ki(r.leftAndTop,g,h,p),g.x+=g.w,g.y+=g.h,Ki(r.rightAndBottom,g,h,p),t.chartArea={left:g.left,top:g.top,right:g.left+g.w,bottom:g.top+g.h,height:g.h,width:g.w},yt(r.chartArea,(e=>{const n=e.box;Object.assign(n,t.chartArea),n.update(g.w,g.h,{left:0,top:0,right:0,bottom:0})}))}};class Zi{acquireContext(t,e){}releaseContext(t){return!1}addEventListener(t,e,n){}removeEventListener(t,e,n){}getDevicePixelRatio(){return 1}getMaximumSize(t,e,n,i){return e=Math.max(0,e||t.width),n=n||t.height,{width:e,height:Math.max(0,i?Math.floor(e/i):n)}}isAttached(t){return!0}updateConfig(t){}}class Ji extends Zi{acquireContext(t){return t&&t.getContext&&t.getContext("2d")||null}updateConfig(t){t.options.animation=!1}}const ts="$chartjs",es={touchstart:"mousedown",touchmove:"mousemove",touchend:"mouseup",pointerenter:"mouseenter",pointerdown:"mousedown",pointermove:"mousemove",pointerup:"mouseup",pointerleave:"mouseout",pointerout:"mouseout"},ns=t=>null===t||""===t;const is=!!Wn&&{passive:!0};function ss(t,e,n){t&&t.canvas&&t.canvas.removeEventListener(e,n,is)}function os(t,e){for(const n of t)if(n===e||n.contains(e))return!0}function as(t,e,n){const i=t.canvas,s=new MutationObserver((t=>{let e=!1;for(const n of t)e=e||os(n.addedNodes,i),e=e&&!os(n.removedNodes,i);e&&n()}));return s.observe(document,{childList:!0,subtree:!0}),s}function rs(t,e,n){const i=t.canvas,s=new MutationObserver((t=>{let e=!1;for(const n of t)e=e||os(n.removedNodes,i),e=e&&!os(n.addedNodes,i);e&&n()}));return s.observe(document,{childList:!0,subtree:!0}),s}const cs=new Map;let ls=0;function ds(){const t=window.devicePixelRatio;t!==ls&&(ls=t,cs.forEach(((e,n)=>{n.currentDevicePixelRatio!==t&&e()})))}function hs(t,e,n){const i=t.canvas,s=i&&Dn(i);if(!s)return;const o=le(((t,e)=>{const i=s.clientWidth;n(t,e),i<s.clientWidth&&n()}),window),a=new ResizeObserver((t=>{const e=t[0],n=e.contentRect.width,i=e.contentRect.height;0===n&&0===i||o(n,i)}));return a.observe(s),function(t,e){cs.size||window.addEventListener("resize",ds),cs.set(t,e)}(t,o),a}function us(t,e,n){n&&n.disconnect(),"resize"===e&&function(t){cs.delete(t),cs.size||window.removeEventListener("resize",ds)}(t)}function gs(t,e,n){const i=t.canvas,s=le((e=>{null!==t.ctx&&n(function(t,e){const n=es[t.type]||t.type,{x:i,y:s}=Ln(t,e);return{type:n,chart:e,native:t,x:void 0!==i?i:null,y:void 0!==s?s:null}}(e,t))}),t);return function(t,e,n){t&&t.addEventListener(e,n,is)}(i,e,s),s}class ps extends Zi{acquireContext(t,e){const n=t&&t.getContext&&t.getContext("2d");return n&&n.canvas===t?(function(t,e){const n=t.style,i=t.getAttribute("height"),s=t.getAttribute("width");if(t[ts]={initial:{height:i,width:s,style:{display:n.display,height:n.height,width:n.width}}},n.display=n.display||"block",n.boxSizing=n.boxSizing||"border-box",ns(s)){const e=Nn(t,"width");void 0!==e&&(t.width=e)}if(ns(i))if(""===t.style.height)t.height=t.width/(e||2);else{const e=Nn(t,"height");void 0!==e&&(t.height=e)}}(t,e),n):null}releaseContext(t){const e=t.canvas;if(!e[ts])return!1;const n=e[ts].initial;["height","width"].forEach((t=>{const i=n[t];dt(i)?e.removeAttribute(t):e.setAttribute(t,i)}));const i=n.style||{};return Object.keys(i).forEach((t=>{e.style[t]=i[t]})),e.width=e.width,delete e[ts],!0}addEventListener(t,e,n){this.removeEventListener(t,e);const i=t.$proxies||(t.$proxies={}),s={attach:as,detach:rs,resize:hs}[e]||gs;i[e]=s(t,e,n)}removeEventListener(t,e){const n=t.$proxies||(t.$proxies={}),i=n[e];if(!i)return;({attach:us,detach:us,resize:us}[e]||ss)(t,e,i),n[e]=void 0}getDevicePixelRatio(){return window.devicePixelRatio}getMaximumSize(t,e,n,i){return On(t,e,n,i)}isAttached(t){const e=t&&Dn(t);return!(!e||!e.isConnected)}}class ms{static defaults={};static defaultRoutes=void 0;x;y;active=!1;options;$animations;tooltipPosition(t){const{x:e,y:n}=this.getProps(["x","y"],t);return{x:e,y:n}}hasValue(){return Vt(this.x)&&Vt(this.y)}getProps(t,e){const n=this.$animations;if(!e||!n)return this;const i={};return t.forEach((t=>{i[t]=n[t]&&n[t].active()?n[t]._to:this[t]})),i}}function fs(t,e){const n=t.options.ticks,i=function(t){const e=t.options.offset,n=t._tickSize(),i=t._length/n+(e?0:1),s=t._maxLength/n;return Math.floor(Math.min(i,s))}(t),s=Math.min(n.maxTicksLimit||i,i),o=n.major.enabled?function(t){const e=[];let n,i;for(n=0,i=t.length;n<i;n++)t[n].major&&e.push(n);return e}(e):[],a=o.length,r=o[0],c=o[a-1],l=[];if(a>s)return function(t,e,n,i){let s,o=0,a=n[0];for(i=Math.ceil(i),s=0;s<t.length;s++)s===a&&(e.push(t[s]),o++,a=n[o*i])}(e,l,o,a/s),l;const d=function(t,e,n){const i=function(t){const e=t.length;let n,i;if(e<2)return!1;for(i=t[0],n=1;n<e;++n)if(t[n]-t[n-1]!==i)return!1;return i}(t),s=e.length/n;if(!i)return Math.max(s,1);const o=function(t){const e=[],n=Math.sqrt(t);let i;for(i=1;i<n;i++)t%i===0&&(e.push(i),e.push(t/i));return n===(0|n)&&e.push(n),e.sort(((t,e)=>t-e)).pop(),e}(i);for(let t=0,e=o.length-1;t<e;t++){const e=o[t];if(e>s)return e}return Math.max(s,1)}(o,e,s);if(a>0){let t,n;const i=a>1?Math.round((c-r)/(a-1)):null;for(bs(e,l,d,dt(i)?0:r-i,r),t=0,n=a-1;t<n;t++)bs(e,l,d,o[t],o[t+1]);return bs(e,l,d,c,dt(i)?e.length:c+i),l}return bs(e,l,d),l}function bs(t,e,n,i,s){const o=mt(i,0),a=Math.min(mt(s,t.length),t.length);let r,c,l,d=0;for(n=Math.ceil(n),s&&(r=s-i,n=r/Math.floor(r/n)),l=o;l<0;)d++,l=Math.round(o+d*n);for(c=Math.max(o,0);c<a;c++)c===l&&(e.push(t[c]),d++,l=Math.round(o+d*n))}const ys=(t,e,n)=>"top"===e||"left"===e?t[e]+n:t[e]-n,xs=(t,e)=>Math.min(e||t,t);function vs(t,e){const n=[],i=t.length/e,s=t.length;let o=0;for(;o<s;o+=i)n.push(t[Math.floor(o)]);return n}function ws(t,e,n){const i=t.ticks.length,s=Math.min(e,i-1),o=t._startPixel,a=t._endPixel,r=1e-6;let c,l=t.getPixelForTick(s);if(!(n&&(c=1===i?Math.max(l-o,a-l):0===e?(t.getPixelForTick(1)-l)/2:(l-t.getPixelForTick(s-1))/2,l+=s<e?c:-c,l<o-r||l>a+r)))return l}function Ss(t){return t.drawTicks?t.tickLength:0}function ks(t,e){if(!t.display)return 0;const n=en(t.font,e),i=tn(t.padding);return(ht(t.text)?t.text.length:1)*n.lineHeight+i.height}function Ms(t,e,n){let i=de(t);return(n&&"right"!==e||!n&&"right"===e)&&(i=(t=>"left"===t?"right":"right"===t?"left":t)(i)),i}class Cs extends ms{constructor(t){super(),this.id=t.id,this.type=t.type,this.options=void 0,this.ctx=t.ctx,this.chart=t.chart,this.top=void 0,this.bottom=void 0,this.left=void 0,this.right=void 0,this.width=void 0,this.height=void 0,this._margins={left:0,right:0,top:0,bottom:0},this.maxWidth=void 0,this.maxHeight=void 0,this.paddingTop=void 0,this.paddingBottom=void 0,this.paddingLeft=void 0,this.paddingRight=void 0,this.axis=void 0,this.labelRotation=void 0,this.min=void 0,this.max=void 0,this._range=void 0,this.ticks=[],this._gridLineItems=null,this._labelItems=null,this._labelSizes=null,this._length=0,this._maxLength=0,this._longestTextCache={},this._startPixel=void 0,this._endPixel=void 0,this._reversePixels=!1,this._userMax=void 0,this._userMin=void 0,this._suggestedMax=void 0,this._suggestedMin=void 0,this._ticksLength=0,this._borderValue=0,this._cache={},this._dataLimitsCached=!1,this.$context=void 0}init(t){this.options=t.setContext(this.getContext()),this.axis=t.axis,this._userMin=this.parse(t.min),this._userMax=this.parse(t.max),this._suggestedMin=this.parse(t.suggestedMin),this._suggestedMax=this.parse(t.suggestedMax)}parse(t,e){return t}getUserBounds(){let{_userMin:t,_userMax:e,_suggestedMin:n,_suggestedMax:i}=this;return t=pt(t,Number.POSITIVE_INFINITY),e=pt(e,Number.NEGATIVE_INFINITY),n=pt(n,Number.POSITIVE_INFINITY),i=pt(i,Number.NEGATIVE_INFINITY),{min:pt(t,n),max:pt(e,i),minDefined:gt(t),maxDefined:gt(e)}}getMinMax(t){let e,{min:n,max:i,minDefined:s,maxDefined:o}=this.getUserBounds();if(s&&o)return{min:n,max:i};const a=this.getMatchingVisibleMetas();for(let r=0,c=a.length;r<c;++r)e=a[r].controller.getMinMax(this,t),s||(n=Math.min(n,e.min)),o||(i=Math.max(i,e.max));return n=o&&n>i?i:n,i=s&&n>i?n:i,{min:pt(n,pt(i,n)),max:pt(i,pt(n,i))}}getPadding(){return{left:this.paddingLeft||0,top:this.paddingTop||0,right:this.paddingRight||0,bottom:this.paddingBottom||0}}getTicks(){return this.ticks}getLabels(){const t=this.chart.data;return this.options.labels||(this.isHorizontal()?t.xLabels:t.yLabels)||t.labels||[]}getLabelItems(t=this.chart.chartArea){return this._labelItems||(this._labelItems=this._computeLabelItems(t))}beforeLayout(){this._cache={},this._dataLimitsCached=!1}beforeUpdate(){bt(this.options.beforeUpdate,[this])}update(t,e,n){const{beginAtZero:i,grace:s,ticks:o}=this.options,a=o.sampleSize;this.beforeUpdate(),this.maxWidth=t,this.maxHeight=e,this._margins=n=Object.assign({left:0,right:0,top:0,bottom:0},n),this.ticks=null,this._labelSizes=null,this._gridLineItems=null,this._labelItems=null,this.beforeSetDimensions(),this.setDimensions(),this.afterSetDimensions(),this._maxLength=this.isHorizontal()?this.width+n.left+n.right:this.height+n.top+n.bottom,this._dataLimitsCached||(this.beforeDataLimits(),this.determineDataLimits(),this.afterDataLimits(),this._range=function(t,e,n){const{min:i,max:s}=t,o=ft(e,(s-i)/2),a=(t,e)=>n&&0===t?0:t+e;return{min:a(i,-Math.abs(o)),max:a(s,o)}}(this,s,i),this._dataLimitsCached=!0),this.beforeBuildTicks(),this.ticks=this.buildTicks()||[],this.afterBuildTicks();const r=a<this.ticks.length;this._convertTicksToLabels(r?vs(this.ticks,a):this.ticks),this.configure(),this.beforeCalculateLabelRotation(),this.calculateLabelRotation(),this.afterCalculateLabelRotation(),o.display&&(o.autoSkip||"auto"===o.source)&&(this.ticks=fs(this,this.ticks),this._labelSizes=null,this.afterAutoSkip()),r&&this._convertTicksToLabels(this.ticks),this.beforeFit(),this.fit(),this.afterFit(),this.afterUpdate()}configure(){let t,e,n=this.options.reverse;this.isHorizontal()?(t=this.left,e=this.right):(t=this.top,e=this.bottom,n=!n),this._startPixel=t,this._endPixel=e,this._reversePixels=n,this._length=e-t,this._alignToPixels=this.options.alignToPixels}afterUpdate(){bt(this.options.afterUpdate,[this])}beforeSetDimensions(){bt(this.options.beforeSetDimensions,[this])}setDimensions(){this.isHorizontal()?(this.width=this.maxWidth,this.left=0,this.right=this.width):(this.height=this.maxHeight,this.top=0,this.bottom=this.height),this.paddingLeft=0,this.paddingTop=0,this.paddingRight=0,this.paddingBottom=0}afterSetDimensions(){bt(this.options.afterSetDimensions,[this])}_callHooks(t){this.chart.notifyPlugins(t,this.getContext()),bt(this.options[t],[this])}beforeDataLimits(){this._callHooks("beforeDataLimits")}determineDataLimits(){}afterDataLimits(){this._callHooks("afterDataLimits")}beforeBuildTicks(){this._callHooks("beforeBuildTicks")}buildTicks(){return[]}afterBuildTicks(){this._callHooks("afterBuildTicks")}beforeTickToLabelConversion(){bt(this.options.beforeTickToLabelConversion,[this])}generateTickLabels(t){const e=this.options.ticks;let n,i,s;for(n=0,i=t.length;n<i;n++)s=t[n],s.label=bt(e.callback,[s.value,n,t],this)}afterTickToLabelConversion(){bt(this.options.afterTickToLabelConversion,[this])}beforeCalculateLabelRotation(){bt(this.options.beforeCalculateLabelRotation,[this])}calculateLabelRotation(){const t=this.options,e=t.ticks,n=xs(this.ticks.length,t.ticks.maxTicksLimit),i=e.minRotation||0,s=e.maxRotation;let o,a,r,c=i;if(!this._isVisible()||!e.display||i>=s||n<=1||!this.isHorizontal())return void(this.labelRotation=i);const l=this._getLabelSizes(),d=l.widest.width,h=l.highest.height,u=te(this.chart.width-d,0,this.maxWidth);o=t.offset?this.maxWidth/n:u/(n-1),d+6>o&&(o=u/(n-(t.offset?.5:1)),a=this.maxHeight-Ss(t.grid)-e.padding-ks(t.title,this.chart.options.font),r=Math.sqrt(d*d+h*h),c=Ut(Math.min(Math.asin(te((l.highest.height+6)/o,-1,1)),Math.asin(te(a/r,-1,1))-Math.asin(te(h/r,-1,1)))),c=Math.max(i,Math.min(s,c))),this.labelRotation=c}afterCalculateLabelRotation(){bt(this.options.afterCalculateLabelRotation,[this])}afterAutoSkip(){}beforeFit(){bt(this.options.beforeFit,[this])}fit(){const t={width:0,height:0},{chart:e,options:{ticks:n,title:i,grid:s}}=this,o=this._isVisible(),a=this.isHorizontal();if(o){const o=ks(i,e.options.font);if(a?(t.width=this.maxWidth,t.height=Ss(s)+o):(t.height=this.maxHeight,t.width=Ss(s)+o),n.display&&this.ticks.length){const{first:e,last:i,widest:s,highest:o}=this._getLabelSizes(),r=2*n.padding,c=Yt(this.labelRotation),l=Math.cos(c),d=Math.sin(c);if(a){const e=n.mirror?0:d*s.width+l*o.height;t.height=Math.min(this.maxHeight,t.height+e+r)}else{const e=n.mirror?0:l*s.width+d*o.height;t.width=Math.min(this.maxWidth,t.width+e+r)}this._calculatePadding(e,i,d,l)}}this._handleMargins(),a?(this.width=this._length=e.width-this._margins.left-this._margins.right,this.height=t.height):(this.width=t.width,this.height=this._length=e.height-this._margins.top-this._margins.bottom)}_calculatePadding(t,e,n,i){const{ticks:{align:s,padding:o},position:a}=this.options,r=0!==this.labelRotation,c="top"!==a&&"x"===this.axis;if(this.isHorizontal()){const a=this.getPixelForTick(0)-this.left,l=this.right-this.getPixelForTick(this.ticks.length-1);let d=0,h=0;r?c?(d=i*t.width,h=n*e.height):(d=n*t.height,h=i*e.width):"start"===s?h=e.width:"end"===s?d=t.width:"inner"!==s&&(d=t.width/2,h=e.width/2),this.paddingLeft=Math.max((d-a+o)*this.width/(this.width-a),0),this.paddingRight=Math.max((h-l+o)*this.width/(this.width-l),0)}else{let n=e.height/2,i=t.height/2;"start"===s?(n=0,i=t.height):"end"===s&&(n=e.height,i=0),this.paddingTop=n+o,this.paddingBottom=i+o}}_handleMargins(){this._margins&&(this._margins.left=Math.max(this.paddingLeft,this._margins.left),this._margins.top=Math.max(this.paddingTop,this._margins.top),this._margins.right=Math.max(this.paddingRight,this._margins.right),this._margins.bottom=Math.max(this.paddingBottom,this._margins.bottom))}afterFit(){bt(this.options.afterFit,[this])}isHorizontal(){const{axis:t,position:e}=this.options;return"top"===e||"bottom"===e||"x"===t}isFullSize(){return this.options.fullSize}_convertTicksToLabels(t){let e,n;for(this.beforeTickToLabelConversion(),this.generateTickLabels(t),e=0,n=t.length;e<n;e++)dt(t[e].label)&&(t.splice(e,1),n--,e--);this.afterTickToLabelConversion()}_getLabelSizes(){let t=this._labelSizes;if(!t){const e=this.options.ticks.sampleSize;let n=this.ticks;e<n.length&&(n=vs(n,e)),this._labelSizes=t=this._computeLabelSizes(n,n.length,this.options.ticks.maxTicksLimit)}return t}_computeLabelSizes(t,e,n){const{ctx:i,_longestTextCache:s}=this,o=[],a=[],r=Math.floor(e/xs(e,n));let c,l,d,h,u,g,p,m,f,b,y,x=0,v=0;for(c=0;c<e;c+=r){if(h=t[c].label,u=this._resolveTickFontOptions(c),i.font=g=u.string,p=s[g]=s[g]||{data:{},gc:[]},m=u.lineHeight,f=b=0,dt(h)||ht(h)){if(ht(h))for(l=0,d=h.length;l<d;++l)y=h[l],dt(y)||ht(y)||(f=Ie(i,p.data,p.gc,f,y),b+=m)}else f=Ie(i,p.data,p.gc,f,h),b=m;o.push(f),a.push(b),x=Math.max(f,x),v=Math.max(b,v)}!function(t,e){yt(t,(t=>{const n=t.gc,i=n.length/2;let s;if(i>e){for(s=0;s<i;++s)delete t.data[n[s]];n.splice(0,i)}}))}(s,e);const w=o.indexOf(x),S=a.indexOf(v),k=t=>({width:o[t]||0,height:a[t]||0});return{first:k(0),last:k(e-1),widest:k(w),highest:k(S),widths:o,heights:a}}getLabelForValue(t){return t}getPixelForValue(t,e){return NaN}getValueForPixel(t){}getPixelForTick(t){const e=this.ticks;return t<0||t>e.length-1?null:this.getPixelForValue(e[t].value)}getPixelForDecimal(t){this._reversePixels&&(t=1-t);const e=this._startPixel+t*this._length;return te(this._alignToPixels?ze(this.chart,e,0):e,-32768,32767)}getDecimalForPixel(t){const e=(t-this._startPixel)/this._length;return this._reversePixels?1-e:e}getBasePixel(){return this.getPixelForValue(this.getBaseValue())}getBaseValue(){const{min:t,max:e}=this;return t<0&&e<0?e:t>0&&e>0?t:0}getContext(t){const e=this.ticks||[];if(t>=0&&t<e.length){const n=e[t];return n.$context||(n.$context=function(t,e,n){return sn(t,{tick:n,index:e,type:"tick"})}(this.getContext(),t,n))}return this.$context||(this.$context=sn(this.chart.getContext(),{scale:this,type:"scale"}))}_tickSize(){const t=this.options.ticks,e=Yt(this.labelRotation),n=Math.abs(Math.cos(e)),i=Math.abs(Math.sin(e)),s=this._getLabelSizes(),o=t.autoSkipPadding||0,a=s?s.widest.width+o:0,r=s?s.highest.height+o:0;return this.isHorizontal()?r*n>a*i?a/n:r/i:r*i<a*n?r/n:a/i}_isVisible(){const t=this.options.display;return"auto"!==t?!!t:this.getMatchingVisibleMetas().length>0}_computeGridLineItems(t){const e=this.axis,n=this.chart,i=this.options,{grid:s,position:o,border:a}=i,r=s.offset,c=this.isHorizontal(),l=this.ticks.length+(r?1:0),d=Ss(s),h=[],u=a.setContext(this.getContext()),g=u.display?u.width:0,p=g/2,m=function(t){return ze(n,t,g)};let f,b,y,x,v,w,S,k,M,C,_,D;if("top"===o)f=m(this.bottom),w=this.bottom-d,k=f-p,C=m(t.top)+p,D=t.bottom;else if("bottom"===o)f=m(this.top),C=t.top,D=m(t.bottom)-p,w=f+p,k=this.top+d;else if("left"===o)f=m(this.right),v=this.right-d,S=f-p,M=m(t.left)+p,_=t.right;else if("right"===o)f=m(this.left),M=t.left,_=m(t.right)-p,v=f+p,S=this.left+d;else if("x"===e){if("center"===o)f=m((t.top+t.bottom)/2+.5);else if(ut(o)){const t=Object.keys(o)[0],e=o[t];f=m(this.chart.scales[t].getPixelForValue(e))}C=t.top,D=t.bottom,w=f+p,k=w+d}else if("y"===e){if("center"===o)f=m((t.left+t.right)/2);else if(ut(o)){const t=Object.keys(o)[0],e=o[t];f=m(this.chart.scales[t].getPixelForValue(e))}v=f-p,S=v-d,M=t.left,_=t.right}const T=mt(i.ticks.maxTicksLimit,l),P=Math.max(1,Math.ceil(l/T));for(b=0;b<l;b+=P){const t=this.getContext(b),e=s.setContext(t),i=a.setContext(t),o=e.lineWidth,l=e.color,d=i.dash||[],u=i.dashOffset,g=e.tickWidth,p=e.tickColor,m=e.tickBorderDash||[],f=e.tickBorderDashOffset;y=ws(this,b,r),void 0!==y&&(x=ze(n,y,o),c?v=S=M=_=x:w=k=C=D=x,h.push({tx1:v,ty1:w,tx2:S,ty2:k,x1:M,y1:C,x2:_,y2:D,width:o,color:l,borderDash:d,borderDashOffset:u,tickWidth:g,tickColor:p,tickBorderDash:m,tickBorderDashOffset:f}))}return this._ticksLength=l,this._borderValue=f,h}_computeLabelItems(t){const e=this.axis,n=this.options,{position:i,ticks:s}=n,o=this.isHorizontal(),a=this.ticks,{align:r,crossAlign:c,padding:l,mirror:d}=s,h=Ss(n.grid),u=h+l,g=d?-l:u,p=-Yt(this.labelRotation),m=[];let f,b,y,x,v,w,S,k,M,C,_,D,T="middle";if("top"===i)w=this.bottom-g,S=this._getXAxisLabelAlignment();else if("bottom"===i)w=this.top+g,S=this._getXAxisLabelAlignment();else if("left"===i){const t=this._getYAxisLabelAlignment(h);S=t.textAlign,v=t.x}else if("right"===i){const t=this._getYAxisLabelAlignment(h);S=t.textAlign,v=t.x}else if("x"===e){if("center"===i)w=(t.top+t.bottom)/2+u;else if(ut(i)){const t=Object.keys(i)[0],e=i[t];w=this.chart.scales[t].getPixelForValue(e)+u}S=this._getXAxisLabelAlignment()}else if("y"===e){if("center"===i)v=(t.left+t.right)/2-u;else if(ut(i)){const t=Object.keys(i)[0],e=i[t];v=this.chart.scales[t].getPixelForValue(e)}S=this._getYAxisLabelAlignment(h).textAlign}"y"===e&&("start"===r?T="top":"end"===r&&(T="bottom"));const P=this._getLabelSizes();for(f=0,b=a.length;f<b;++f){y=a[f],x=y.label;const t=s.setContext(this.getContext(f));k=this.getPixelForTick(f)+s.labelOffset,M=this._resolveTickFontOptions(f),C=M.lineHeight,_=ht(x)?x.length:1;const e=_/2,n=t.color,r=t.textStrokeColor,l=t.textStrokeWidth;let h,u=S;if(o?(v=k,"inner"===S&&(u=f===b-1?this.options.reverse?"left":"right":0===f?this.options.reverse?"right":"left":"center"),D="top"===i?"near"===c||0!==p?-_*C+C/2:"center"===c?-P.highest.height/2-e*C+C:-P.highest.height+C/2:"near"===c||0!==p?C/2:"center"===c?P.highest.height/2-e*C:P.highest.height-_*C,d&&(D*=-1),0===p||t.showLabelBackdrop||(v+=C/2*Math.sin(p))):(w=k,D=(1-_)*C/2),t.showLabelBackdrop){const e=tn(t.backdropPadding),n=P.heights[f],i=P.widths[f];let s=D-e.top,o=0-e.left;switch(T){case"middle":s-=n/2;break;case"bottom":s-=n}switch(S){case"center":o-=i/2;break;case"right":o-=i;break;case"inner":f===b-1?o-=i:f>0&&(o-=i/2)}h={left:o,top:s,width:i+e.width,height:n+e.height,color:t.backdropColor}}m.push({label:x,font:M,textOffset:D,options:{rotation:p,color:n,strokeColor:r,strokeWidth:l,textAlign:u,textBaseline:T,translation:[v,w],backdrop:h}})}return m}_getXAxisLabelAlignment(){const{position:t,ticks:e}=this.options;if(-Yt(this.labelRotation))return"top"===t?"left":"right";let n="center";return"start"===e.align?n="left":"end"===e.align?n="right":"inner"===e.align&&(n="inner"),n}_getYAxisLabelAlignment(t){const{position:e,ticks:{crossAlign:n,mirror:i,padding:s}}=this.options,o=t+s,a=this._getLabelSizes().widest.width;let r,c;return"left"===e?i?(c=this.right+s,"near"===n?r="left":"center"===n?(r="center",c+=a/2):(r="right",c+=a)):(c=this.right-o,"near"===n?r="right":"center"===n?(r="center",c-=a/2):(r="left",c=this.left)):"right"===e?i?(c=this.left+s,"near"===n?r="right":"center"===n?(r="center",c-=a/2):(r="left",c-=a)):(c=this.left+o,"near"===n?r="left":"center"===n?(r="center",c+=a/2):(r="right",c=this.right)):r="right",{textAlign:r,x:c}}_computeLabelArea(){if(this.options.ticks.mirror)return;const t=this.chart,e=this.options.position;return"left"===e||"right"===e?{top:0,left:this.left,bottom:t.height,right:this.right}:"top"===e||"bottom"===e?{top:this.top,left:0,bottom:this.bottom,right:t.width}:void 0}drawBackground(){const{ctx:t,options:{backgroundColor:e},left:n,top:i,width:s,height:o}=this;e&&(t.save(),t.fillStyle=e,t.fillRect(n,i,s,o),t.restore())}getLineWidthForValue(t){const e=this.options.grid;if(!this._isVisible()||!e.display)return 0;const n=this.ticks.findIndex((e=>e.value===t));if(n>=0){return e.setContext(this.getContext(n)).lineWidth}return 0}drawGrid(t){const e=this.options.grid,n=this.ctx,i=this._gridLineItems||(this._gridLineItems=this._computeGridLineItems(t));let s,o;const a=(t,e,i)=>{i.width&&i.color&&(n.save(),n.lineWidth=i.width,n.strokeStyle=i.color,n.setLineDash(i.borderDash||[]),n.lineDashOffset=i.borderDashOffset,n.beginPath(),n.moveTo(t.x,t.y),n.lineTo(e.x,e.y),n.stroke(),n.restore())};if(e.display)for(s=0,o=i.length;s<o;++s){const t=i[s];e.drawOnChartArea&&a({x:t.x1,y:t.y1},{x:t.x2,y:t.y2},t),e.drawTicks&&a({x:t.tx1,y:t.ty1},{x:t.tx2,y:t.ty2},{color:t.tickColor,width:t.tickWidth,borderDash:t.tickBorderDash,borderDashOffset:t.tickBorderDashOffset})}}drawBorder(){const{chart:t,ctx:e,options:{border:n,grid:i}}=this,s=n.setContext(this.getContext()),o=n.display?s.width:0;if(!o)return;const a=i.setContext(this.getContext(0)).lineWidth,r=this._borderValue;let c,l,d,h;this.isHorizontal()?(c=ze(t,this.left,o)-o/2,l=ze(t,this.right,a)+a/2,d=h=r):(d=ze(t,this.top,o)-o/2,h=ze(t,this.bottom,a)+a/2,c=l=r),e.save(),e.lineWidth=s.width,e.strokeStyle=s.color,e.beginPath(),e.moveTo(c,d),e.lineTo(l,h),e.stroke(),e.restore()}drawLabels(t){if(!this.options.ticks.display)return;const e=this.ctx,n=this._computeLabelArea();n&&Fe(e,n);const i=this.getLabelItems(t);for(const t of i){const n=t.options,i=t.font;Ye(e,t.label,0,t.textOffset,i,n)}n&&qe(e)}drawTitle(){const{ctx:t,options:{position:e,title:n,reverse:i}}=this;if(!n.display)return;const s=en(n.font),o=tn(n.padding),a=n.align;let r=s.lineHeight/2;"bottom"===e||"center"===e||ut(e)?(r+=o.bottom,ht(n.text)&&(r+=s.lineHeight*(n.text.length-1))):r+=o.top;const{titleX:c,titleY:l,maxWidth:d,rotation:h}=function(t,e,n,i){const{top:s,left:o,bottom:a,right:r,chart:c}=t,{chartArea:l,scales:d}=c;let h,u,g,p=0;const m=a-s,f=r-o;if(t.isHorizontal()){if(u=he(i,o,r),ut(n)){const t=Object.keys(n)[0],i=n[t];g=d[t].getPixelForValue(i)+m-e}else g="center"===n?(l.bottom+l.top)/2+m-e:ys(t,n,e);h=r-o}else{if(ut(n)){const t=Object.keys(n)[0],i=n[t];u=d[t].getPixelForValue(i)-f+e}else u="center"===n?(l.left+l.right)/2-f+e:ys(t,n,e);g=he(i,a,s),p="left"===n?-Nt:Nt}return{titleX:u,titleY:g,maxWidth:h,rotation:p}}(this,r,e,a);Ye(t,n.text,0,0,s,{color:n.color,maxWidth:d,rotation:h,textAlign:Ms(a,e,i),textBaseline:"middle",translation:[c,l]})}draw(t){this._isVisible()&&(this.drawBackground(),this.drawGrid(t),this.drawBorder(),this.drawTitle(),this.drawLabels(t))}_layers(){const t=this.options,e=t.ticks&&t.ticks.z||0,n=mt(t.grid&&t.grid.z,-1),i=mt(t.border&&t.border.z,0);return this._isVisible()&&this.draw===Cs.prototype.draw?[{z:n,draw:t=>{this.drawBackground(),this.drawGrid(t),this.drawTitle()}},{z:i,draw:()=>{this.drawBorder()}},{z:e,draw:t=>{this.drawLabels(t)}}]:[{z:e,draw:t=>{this.draw(t)}}]}getMatchingVisibleMetas(t){const e=this.chart.getSortedVisibleDatasetMetas(),n=this.axis+"AxisID",i=[];let s,o;for(s=0,o=e.length;s<o;++s){const o=e[s];o[n]!==this.id||t&&o.type!==t||i.push(o)}return i}_resolveTickFontOptions(t){return en(this.options.ticks.setContext(this.getContext(t)).font)}_maxDigits(){const t=this._resolveTickFontOptions(0).lineHeight;return(this.isHorizontal()?this.width:this.height)/t}}class _s{constructor(t,e,n){this.type=t,this.scope=e,this.override=n,this.items=Object.create(null)}isForType(t){return Object.prototype.isPrototypeOf.call(this.type.prototype,t.prototype)}register(t){const e=Object.getPrototypeOf(t);let n;(function(t){return"id"in t&&"defaults"in t})(e)&&(n=this.register(e));const i=this.items,s=t.id,o=this.scope+"."+s;if(!s)throw new Error("class does not have id: "+t);return s in i||(i[s]=t,function(t,e,n){const i=kt(Object.create(null),[n?Le.get(n):{},Le.get(e),t.defaults]);Le.set(e,i),t.defaultRoutes&&function(t,e){Object.keys(e).forEach((n=>{const i=n.split("."),s=i.pop(),o=[t].concat(i).join("."),a=e[n].split("."),r=a.pop(),c=a.join(".");Le.route(o,s,c,r)}))}(e,t.defaultRoutes);t.descriptors&&Le.describe(e,t.descriptors)}(t,o,n),this.override&&Le.override(t.id,t.overrides)),o}get(t){return this.items[t]}unregister(t){const e=this.items,n=t.id,i=this.scope;n in e&&delete e[n],i&&n in Le[i]&&(delete Le[i][n],this.override&&delete De[n])}}class Ds{constructor(){this.controllers=new _s(fi,"datasets",!0),this.elements=new _s(ms,"elements"),this.plugins=new _s(Object,"plugins"),this.scales=new _s(Cs,"scales"),this._typedRegistries=[this.controllers,this.scales,this.elements]}add(...t){this._each("register",t)}remove(...t){this._each("unregister",t)}addControllers(...t){this._each("register",t,this.controllers)}addElements(...t){this._each("register",t,this.elements)}addPlugins(...t){this._each("register",t,this.plugins)}addScales(...t){this._each("register",t,this.scales)}getController(t){return this._get(t,this.controllers,"controller")}getElement(t){return this._get(t,this.elements,"element")}getPlugin(t){return this._get(t,this.plugins,"plugin")}getScale(t){return this._get(t,this.scales,"scale")}removeControllers(...t){this._each("unregister",t,this.controllers)}removeElements(...t){this._each("unregister",t,this.elements)}removePlugins(...t){this._each("unregister",t,this.plugins)}removeScales(...t){this._each("unregister",t,this.scales)}_each(t,e,n){[...e].forEach((e=>{const i=n||this._getRegistryForType(e);n||i.isForType(e)||i===this.plugins&&e.id?this._exec(t,i,e):yt(e,(e=>{const i=n||this._getRegistryForType(e);this._exec(t,i,e)}))}))}_exec(t,e,n){const i=Tt(t);bt(n["before"+i],[],n),e[t](n),bt(n["after"+i],[],n)}_getRegistryForType(t){for(let e=0;e<this._typedRegistries.length;e++){const n=this._typedRegistries[e];if(n.isForType(t))return n}return this.plugins}_get(t,e,n){const i=e.get(t);if(void 0===i)throw new Error('"'+t+'" is not a registered '+n+".");return i}}var Ts=new Ds;class Ps{constructor(){this._init=void 0}notify(t,e,n,i){if("beforeInit"===e&&(this._init=this._createDescriptors(t,!0),this._notify(this._init,t,"install")),void 0===this._init)return;const s=i?this._descriptors(t).filter(i):this._descriptors(t),o=this._notify(s,t,e,n);return"afterDestroy"===e&&(this._notify(s,t,"stop"),this._notify(this._init,t,"uninstall"),this._init=void 0),o}_notify(t,e,n,i){i=i||{};for(const s of t){const t=s.plugin;if(!1===bt(t[n],[e,i,s.options],t)&&i.cancelable)return!1}return!0}invalidate(){dt(this._cache)||(this._oldCache=this._cache,this._cache=void 0)}_descriptors(t){if(this._cache)return this._cache;const e=this._cache=this._createDescriptors(t);return this._notifyStateChanges(t),e}_createDescriptors(t,e){const n=t&&t.config,i=mt(n.options&&n.options.plugins,{}),s=function(t){const e={},n=[],i=Object.keys(Ts.plugins.items);for(let t=0;t<i.length;t++)n.push(Ts.getPlugin(i[t]));const s=t.plugins||[];for(let t=0;t<s.length;t++){const i=s[t];-1===n.indexOf(i)&&(n.push(i),e[i.id]=!0)}return{plugins:n,localIds:e}}(n);return!1!==i||e?function(t,{plugins:e,localIds:n},i,s){const o=[],a=t.getContext();for(const r of e){const e=r.id,c=Es(i[e],s);null!==c&&o.push({plugin:r,options:As(t.config,{plugin:r,local:n[e]},c,a)})}return o}(t,s,i,e):[]}_notifyStateChanges(t){const e=this._oldCache||[],n=this._cache,i=(t,e)=>t.filter((t=>!e.some((e=>t.plugin.id===e.plugin.id))));this._notify(i(e,n),t,"stop"),this._notify(i(n,e),t,"start")}}function Es(t,e){return e||!1!==t?!0===t?{}:t:null}function As(t,{plugin:e,local:n},i,s){const o=t.pluginScopeKeys(e),a=t.getOptionScopes(i,o);return n&&e.defaults&&a.push(e.defaults),t.createResolver(a,s,[""],{scriptable:!1,indexable:!1,allKeys:!0})}function Ls(t,e){const n=Le.datasets[t]||{};return((e.datasets||{})[t]||{}).indexAxis||e.indexAxis||n.indexAxis||"x"}function Is(t){if("x"===t||"y"===t||"r"===t)return t}function Os(t,...e){if(Is(t))return t;for(const i of e){const e=i.axis||("top"===(n=i.position)||"bottom"===n?"x":"left"===n||"right"===n?"y":void 0)||t.length>1&&Is(t[0].toLowerCase());if(e)return e}var n;throw new Error(`Cannot determine type of '${t}' axis. Please provide 'axis' or 'position' option.`)}function zs(t,e,n){if(n[e+"AxisID"]===t)return{axis:e}}function Ws(t,e){const n=De[t.type]||{scales:{}},i=e.scales||{},s=Ls(t.type,e),o=Object.create(null);return Object.keys(i).forEach((e=>{const a=i[e];if(!ut(a))return console.error(`Invalid scale configuration for scale: ${e}`);if(a._proxy)return console.warn(`Ignoring resolver passed as options for scale: ${e}`);const r=Os(e,a,function(t,e){if(e.data&&e.data.datasets){const n=e.data.datasets.filter((e=>e.xAxisID===t||e.yAxisID===t));if(n.length)return zs(t,"x",n[0])||zs(t,"y",n[0])}return{}}(e,t),Le.scales[a.type]),c=function(t,e){return t===e?"_index_":"_value_"}(r,s),l=n.scales||{};o[e]=Mt(Object.create(null),[{axis:r},a,l[r],l[c]])})),t.data.datasets.forEach((n=>{const s=n.type||t.type,a=n.indexAxis||Ls(s,e),r=(De[s]||{}).scales||{};Object.keys(r).forEach((t=>{const e=function(t,e){let n=t;return"_index_"===t?n=e:"_value_"===t&&(n="x"===e?"y":"x"),n}(t,a),s=n[e+"AxisID"]||e;o[s]=o[s]||Object.create(null),Mt(o[s],[{axis:e},i[s],r[t]])}))})),Object.keys(o).forEach((t=>{const e=o[t];Mt(e,[Le.scales[e.type],Le.scale])})),o}function Ns(t){const e=t.options||(t.options={});e.plugins=mt(e.plugins,{}),e.scales=Ws(t,e)}function Rs(t){return(t=t||{}).datasets=t.datasets||[],t.labels=t.labels||[],t}const $s=new Map,Fs=new Set;function qs(t,e){let n=$s.get(t);return n||(n=e(),$s.set(t,n),Fs.add(n)),n}const Bs=(t,e,n)=>{const i=Dt(e,n);void 0!==i&&t.add(i)};class Hs{constructor(t){this._config=function(t){return(t=t||{}).data=Rs(t.data),Ns(t),t}(t),this._scopeCache=new Map,this._resolverCache=new Map}get platform(){return this._config.platform}get type(){return this._config.type}set type(t){this._config.type=t}get data(){return this._config.data}set data(t){this._config.data=Rs(t)}get options(){return this._config.options}set options(t){this._config.options=t}get plugins(){return this._config.plugins}update(){const t=this._config;this.clearCache(),Ns(t)}clearCache(){this._scopeCache.clear(),this._resolverCache.clear()}datasetScopeKeys(t){return qs(t,(()=>[[`datasets.${t}`,""]]))}datasetAnimationScopeKeys(t,e){return qs(`${t}.transition.${e}`,(()=>[[`datasets.${t}.transitions.${e}`,`transitions.${e}`],[`datasets.${t}`,""]]))}datasetElementScopeKeys(t,e){return qs(`${t}-${e}`,(()=>[[`datasets.${t}.elements.${e}`,`datasets.${t}`,`elements.${e}`,""]]))}pluginScopeKeys(t){const e=t.id;return qs(`${this.type}-plugin-${e}`,(()=>[[`plugins.${e}`,...t.additionalOptionScopes||[]]]))}_cachedScopes(t,e){const n=this._scopeCache;let i=n.get(t);return i&&!e||(i=new Map,n.set(t,i)),i}getOptionScopes(t,e,n){const{options:i,type:s}=this,o=this._cachedScopes(t,n),a=o.get(e);if(a)return a;const r=new Set;e.forEach((e=>{t&&(r.add(t),e.forEach((e=>Bs(r,t,e)))),e.forEach((t=>Bs(r,i,t))),e.forEach((t=>Bs(r,De[s]||{},t))),e.forEach((t=>Bs(r,Le,t))),e.forEach((t=>Bs(r,Te,t)))}));const c=Array.from(r);return 0===c.length&&c.push(Object.create(null)),Fs.has(e)&&o.set(e,c),c}chartOptionScopes(){const{options:t,type:e}=this;return[t,De[e]||{},Le.datasets[e]||{},{type:e},Le,Te]}resolveNamedOptions(t,e,n,i=[""]){const s={$shared:!0},{resolver:o,subPrefixes:a}=Vs(this._resolverCache,t,i);let r=o;if(function(t,e){const{isScriptable:n,isIndexable:i}=rn(t);for(const s of e){const e=n(s),o=i(s),a=(o||e)&&t[s];if(e&&(Et(a)||js(a))||o&&ht(a))return!0}return!1}(o,e)){s.$shared=!1;r=an(o,n=Et(n)?n():n,this.createResolver(t,n,a))}for(const t of e)s[t]=r[t];return s}createResolver(t,e,n=[""],i){const{resolver:s}=Vs(this._resolverCache,t,n);return ut(e)?an(s,e,void 0,i):s}}function Vs(t,e,n){let i=t.get(e);i||(i=new Map,t.set(e,i));const s=n.join();let o=i.get(s);if(!o){o={resolver:on(e,n),subPrefixes:n.filter((t=>!t.toLowerCase().includes("hover")))},i.set(s,o)}return o}const js=t=>ut(t)&&Object.getOwnPropertyNames(t).some((e=>Et(t[e])));const Ys=["top","bottom","left","right","chartArea"];function Us(t,e){return"top"===t||"bottom"===t||-1===Ys.indexOf(t)&&"x"===e}function Xs(t,e){return function(n,i){return n[t]===i[t]?n[e]-i[e]:n[t]-i[t]}}function Qs(t){const e=t.chart,n=e.options.animation;e.notifyPlugins("afterRender"),bt(n&&n.onComplete,[t],e)}function Ks(t){const e=t.chart,n=e.options.animation;bt(n&&n.onProgress,[t],e)}function Gs(t){return _n()&&"string"==typeof t?t=document.getElementById(t):t&&t.length&&(t=t[0]),t&&t.canvas&&(t=t.canvas),t}const Zs={},Js=t=>{const e=Gs(t);return Object.values(Zs).filter((t=>t.canvas===e)).pop()};function to(t,e,n){const i=Object.keys(t);for(const s of i){const i=+s;if(i>=e){const o=t[s];delete t[s],(n>0||i>e)&&(t[i+n]=o)}}}class eo{static defaults=Le;static instances=Zs;static overrides=De;static registry=Ts;static version="4.5.1";static getChart=Js;static register(...t){Ts.add(...t),no()}static unregister(...t){Ts.remove(...t),no()}constructor(t,e){const n=this.config=new Hs(e),i=Gs(t),s=Js(i);if(s)throw new Error("Canvas is already in use. Chart with ID '"+s.id+"' must be destroyed before the canvas with ID '"+s.canvas.id+"' can be reused.");const o=n.createResolver(n.chartOptionScopes(),this.getContext());this.platform=new(n.platform||function(t){return!_n()||"undefined"!=typeof OffscreenCanvas&&t instanceof OffscreenCanvas?Ji:ps}(i)),this.platform.updateConfig(n);const a=this.platform.acquireContext(i,o.aspectRatio),r=a&&a.canvas,c=r&&r.height,l=r&&r.width;this.id=lt(),this.ctx=a,this.canvas=r,this.width=l,this.height=c,this._options=o,this._aspectRatio=this.aspectRatio,this._layers=[],this._metasets=[],this._stacks=void 0,this.boxes=[],this.currentDevicePixelRatio=void 0,this.chartArea=void 0,this._active=[],this._lastEvent=void 0,this._listeners={},this._responsiveListeners=void 0,this._sortedMetasets=[],this.scales={},this._plugins=new Ps,this.$proxies={},this._hiddenIndices={},this.attached=!1,this._animationsDisabled=void 0,this.$context=void 0,this._doResize=function(t,e){let n;return function(...i){return e?(clearTimeout(n),n=setTimeout(t,e,i)):t.apply(this,i),e}}((t=>this.update(t)),o.resizeDelay||0),this._dataChanges=[],Zs[this.id]=this,a&&r?(ti.listen(this,"complete",Qs),ti.listen(this,"progress",Ks),this._initialize(),this.attached&&this.update()):console.error("Failed to create chart: can't acquire context from the given item")}get aspectRatio(){const{options:{aspectRatio:t,maintainAspectRatio:e},width:n,height:i,_aspectRatio:s}=this;return dt(t)?e&&s?s:i?n/i:null:t}get data(){return this.config.data}set data(t){this.config.data=t}get options(){return this._options}set options(t){this.config.options=t}get registry(){return Ts}_initialize(){return this.notifyPlugins("beforeInit"),this.options.responsive?this.resize():zn(this,this.options.devicePixelRatio),this.bindEvents(),this.notifyPlugins("afterInit"),this}clear(){return We(this.canvas,this.ctx),this}stop(){return ti.stop(this),this}resize(t,e){ti.running(this)?this._resizeBeforeDraw={width:t,height:e}:this._resize(t,e)}_resize(t,e){const n=this.options,i=this.canvas,s=n.maintainAspectRatio&&this.aspectRatio,o=this.platform.getMaximumSize(i,t,e,s),a=n.devicePixelRatio||this.platform.getDevicePixelRatio(),r=this.width?"resize":"attach";this.width=o.width,this.height=o.height,this._aspectRatio=this.aspectRatio,zn(this,a,!0)&&(this.notifyPlugins("resize",{size:o}),bt(n.onResize,[this,o],this),this.attached&&this._doResize(r)&&this.render())}ensureScalesHaveIDs(){yt(this.options.scales||{},((t,e)=>{t.id=e}))}buildOrUpdateScales(){const t=this.options,e=t.scales,n=this.scales,i=Object.keys(n).reduce(((t,e)=>(t[e]=!1,t)),{});let s=[];e&&(s=s.concat(Object.keys(e).map((t=>{const n=e[t],i=Os(t,n),s="r"===i,o="x"===i;return{options:n,dposition:s?"chartArea":o?"bottom":"left",dtype:s?"radialLinear":o?"category":"linear"}})))),yt(s,(e=>{const s=e.options,o=s.id,a=Os(o,s),r=mt(s.type,e.dtype);void 0!==s.position&&Us(s.position,a)===Us(e.dposition)||(s.position=e.dposition),i[o]=!0;let c=null;if(o in n&&n[o].type===r)c=n[o];else{c=new(Ts.getScale(r))({id:o,type:r,ctx:this.ctx,chart:this}),n[c.id]=c}c.init(s,t)})),yt(i,((t,e)=>{t||delete n[e]})),yt(n,(t=>{Gi.configure(this,t,t.options),Gi.addBox(this,t)}))}_updateMetasets(){const t=this._metasets,e=this.data.datasets.length,n=t.length;if(t.sort(((t,e)=>t.index-e.index)),n>e){for(let t=e;t<n;++t)this._destroyDatasetMeta(t);t.splice(e,n-e)}this._sortedMetasets=t.slice(0).sort(Xs("order","index"))}_removeUnreferencedMetasets(){const{_metasets:t,data:{datasets:e}}=this;t.length>e.length&&delete this._stacks,t.forEach(((t,n)=>{0===e.filter((e=>e===t._dataset)).length&&this._destroyDatasetMeta(n)}))}buildOrUpdateControllers(){const t=[],e=this.data.datasets;let n,i;for(this._removeUnreferencedMetasets(),n=0,i=e.length;n<i;n++){const i=e[n];let s=this.getDatasetMeta(n);const o=i.type||this.config.type;if(s.type&&s.type!==o&&(this._destroyDatasetMeta(n),s=this.getDatasetMeta(n)),s.type=o,s.indexAxis=i.indexAxis||Ls(o,this.options),s.order=i.order||0,s.index=n,s.label=""+i.label,s.visible=this.isDatasetVisible(n),s.controller)s.controller.updateIndex(n),s.controller.linkScales();else{const e=Ts.getController(o),{datasetElementType:i,dataElementType:a}=Le.datasets[o];Object.assign(e,{dataElementType:Ts.getElement(a),datasetElementType:i&&Ts.getElement(i)}),s.controller=new e(this,n),t.push(s.controller)}}return this._updateMetasets(),t}_resetElements(){yt(this.data.datasets,((t,e)=>{this.getDatasetMeta(e).controller.reset()}),this)}reset(){this._resetElements(),this.notifyPlugins("reset")}update(t){const e=this.config;e.update();const n=this._options=e.createResolver(e.chartOptionScopes(),this.getContext()),i=this._animationsDisabled=!n.animation;if(this._updateScales(),this._checkEventBindings(),this._updateHiddenIndices(),this._plugins.invalidate(),!1===this.notifyPlugins("beforeUpdate",{mode:t,cancelable:!0}))return;const s=this.buildOrUpdateControllers();this.notifyPlugins("beforeElementsUpdate");let o=0;for(let t=0,e=this.data.datasets.length;t<e;t++){const{controller:e}=this.getDatasetMeta(t),n=!i&&-1===s.indexOf(e);e.buildOrUpdateElements(n),o=Math.max(+e.getMaxOverflow(),o)}o=this._minPadding=n.layout.autoPadding?o:0,this._updateLayout(o),i||yt(s,(t=>{t.reset()})),this._updateDatasets(t),this.notifyPlugins("afterUpdate",{mode:t}),this._layers.sort(Xs("z","_idx"));const{_active:a,_lastEvent:r}=this;r?this._eventHandler(r,!0):a.length&&this._updateHoverStyles(a,a,!0),this.render()}_updateScales(){yt(this.scales,(t=>{Gi.removeBox(this,t)})),this.ensureScalesHaveIDs(),this.buildOrUpdateScales()}_checkEventBindings(){const t=this.options,e=new Set(Object.keys(this._listeners)),n=new Set(t.events);At(e,n)&&!!this._responsiveListeners===t.responsive||(this.unbindEvents(),this.bindEvents())}_updateHiddenIndices(){const{_hiddenIndices:t}=this,e=this._getUniformDataChanges()||[];for(const{method:n,start:i,count:s}of e){to(t,i,"_removeElements"===n?-s:s)}}_getUniformDataChanges(){const t=this._dataChanges;if(!t||!t.length)return;this._dataChanges=[];const e=this.data.datasets.length,n=e=>new Set(t.filter((t=>t[0]===e)).map(((t,e)=>e+","+t.splice(1).join(",")))),i=n(0);for(let t=1;t<e;t++)if(!At(i,n(t)))return;return Array.from(i).map((t=>t.split(","))).map((t=>({method:t[1],start:+t[2],count:+t[3]})))}_updateLayout(t){if(!1===this.notifyPlugins("beforeLayout",{cancelable:!0}))return;Gi.update(this,this.width,this.height,t);const e=this.chartArea,n=e.width<=0||e.height<=0;this._layers=[],yt(this.boxes,(t=>{n&&"chartArea"===t.position||(t.configure&&t.configure(),this._layers.push(...t._layers()))}),this),this._layers.forEach(((t,e)=>{t._idx=e})),this.notifyPlugins("afterLayout")}_updateDatasets(t){if(!1!==this.notifyPlugins("beforeDatasetsUpdate",{mode:t,cancelable:!0})){for(let t=0,e=this.data.datasets.length;t<e;++t)this.getDatasetMeta(t).controller.configure();for(let e=0,n=this.data.datasets.length;e<n;++e)this._updateDataset(e,Et(t)?t({datasetIndex:e}):t);this.notifyPlugins("afterDatasetsUpdate",{mode:t})}}_updateDataset(t,e){const n=this.getDatasetMeta(t),i={meta:n,index:t,mode:e,cancelable:!0};!1!==this.notifyPlugins("beforeDatasetUpdate",i)&&(n.controller._update(e),i.cancelable=!1,this.notifyPlugins("afterDatasetUpdate",i))}render(){!1!==this.notifyPlugins("beforeRender",{cancelable:!0})&&(ti.has(this)?this.attached&&!ti.running(this)&&ti.start(this):(this.draw(),Qs({chart:this})))}draw(){let t;if(this._resizeBeforeDraw){const{width:t,height:e}=this._resizeBeforeDraw;this._resizeBeforeDraw=null,this._resize(t,e)}if(this.clear(),this.width<=0||this.height<=0)return;if(!1===this.notifyPlugins("beforeDraw",{cancelable:!0}))return;const e=this._layers;for(t=0;t<e.length&&e[t].z<=0;++t)e[t].draw(this.chartArea);for(this._drawDatasets();t<e.length;++t)e[t].draw(this.chartArea);this.notifyPlugins("afterDraw")}_getSortedDatasetMetas(t){const e=this._sortedMetasets,n=[];let i,s;for(i=0,s=e.length;i<s;++i){const s=e[i];t&&!s.visible||n.push(s)}return n}getSortedVisibleDatasetMetas(){return this._getSortedDatasetMetas(!0)}_drawDatasets(){if(!1===this.notifyPlugins("beforeDatasetsDraw",{cancelable:!0}))return;const t=this.getSortedVisibleDatasetMetas();for(let e=t.length-1;e>=0;--e)this._drawDataset(t[e]);this.notifyPlugins("afterDatasetsDraw")}_drawDataset(t){const e=this.ctx,n={meta:t,index:t.index,cancelable:!0},i=Zn(this,t);!1!==this.notifyPlugins("beforeDatasetDraw",n)&&(i&&Fe(e,i),t.controller.draw(),i&&qe(e),n.cancelable=!1,this.notifyPlugins("afterDatasetDraw",n))}isPointInArea(t){return $e(t,this.chartArea,this._minPadding)}getElementsAtEventForMode(t,e,n,i){const s=Ri.modes[e];return"function"==typeof s?s(this,t,n,i):[]}getDatasetMeta(t){const e=this.data.datasets[t],n=this._metasets;let i=n.filter((t=>t&&t._dataset===e)).pop();return i||(i={type:null,data:[],dataset:null,controller:null,hidden:null,xAxisID:null,yAxisID:null,order:e&&e.order||0,index:t,_dataset:e,_parsed:[],_sorted:!1},n.push(i)),i}getContext(){return this.$context||(this.$context=sn(null,{chart:this,type:"chart"}))}getVisibleDatasetCount(){return this.getSortedVisibleDatasetMetas().length}isDatasetVisible(t){const e=this.data.datasets[t];if(!e)return!1;const n=this.getDatasetMeta(t);return"boolean"==typeof n.hidden?!n.hidden:!e.hidden}setDatasetVisibility(t,e){this.getDatasetMeta(t).hidden=!e}toggleDataVisibility(t){this._hiddenIndices[t]=!this._hiddenIndices[t]}getDataVisibility(t){return!this._hiddenIndices[t]}_updateVisibility(t,e,n){const i=n?"show":"hide",s=this.getDatasetMeta(t),o=s.controller._resolveAnimations(void 0,i);Pt(e)?(s.data[e].hidden=!n,this.update()):(this.setDatasetVisibility(t,n),o.update(s,{visible:n}),this.update((e=>e.datasetIndex===t?i:void 0)))}hide(t,e){this._updateVisibility(t,e,!1)}show(t,e){this._updateVisibility(t,e,!0)}_destroyDatasetMeta(t){const e=this._metasets[t];e&&e.controller&&e.controller._destroy(),delete this._metasets[t]}_stop(){let t,e;for(this.stop(),ti.remove(this),t=0,e=this.data.datasets.length;t<e;++t)this._destroyDatasetMeta(t)}destroy(){this.notifyPlugins("beforeDestroy");const{canvas:t,ctx:e}=this;this._stop(),this.config.clearCache(),t&&(this.unbindEvents(),We(t,e),this.platform.releaseContext(e),this.canvas=null,this.ctx=null),delete Zs[this.id],this.notifyPlugins("afterDestroy")}toBase64Image(...t){return this.canvas.toDataURL(...t)}bindEvents(){this.bindUserEvents(),this.options.responsive?this.bindResponsiveEvents():this.attached=!0}bindUserEvents(){const t=this._listeners,e=this.platform,n=(n,i)=>{e.addEventListener(this,n,i),t[n]=i},i=(t,e,n)=>{t.offsetX=e,t.offsetY=n,this._eventHandler(t)};yt(this.options.events,(t=>n(t,i)))}bindResponsiveEvents(){this._responsiveListeners||(this._responsiveListeners={});const t=this._responsiveListeners,e=this.platform,n=(n,i)=>{e.addEventListener(this,n,i),t[n]=i},i=(n,i)=>{t[n]&&(e.removeEventListener(this,n,i),delete t[n])},s=(t,e)=>{this.canvas&&this.resize(t,e)};let o;const a=()=>{i("attach",a),this.attached=!0,this.resize(),n("resize",s),n("detach",o)};o=()=>{this.attached=!1,i("resize",s),this._stop(),this._resize(0,0),n("attach",a)},e.isAttached(this.canvas)?a():o()}unbindEvents(){yt(this._listeners,((t,e)=>{this.platform.removeEventListener(this,e,t)})),this._listeners={},yt(this._responsiveListeners,((t,e)=>{this.platform.removeEventListener(this,e,t)})),this._responsiveListeners=void 0}updateHoverStyle(t,e,n){const i=n?"set":"remove";let s,o,a,r;for("dataset"===e&&(s=this.getDatasetMeta(t[0].datasetIndex),s.controller["_"+i+"DatasetHoverStyle"]()),a=0,r=t.length;a<r;++a){o=t[a];const e=o&&this.getDatasetMeta(o.datasetIndex).controller;e&&e[i+"HoverStyle"](o.element,o.datasetIndex,o.index)}}getActiveElements(){return this._active||[]}setActiveElements(t){const e=this._active||[],n=t.map((({datasetIndex:t,index:e})=>{const n=this.getDatasetMeta(t);if(!n)throw new Error("No dataset found at index "+t);return{datasetIndex:t,element:n.data[e],index:e}}));!xt(n,e)&&(this._active=n,this._lastEvent=null,this._updateHoverStyles(n,e))}notifyPlugins(t,e,n){return this._plugins.notify(this,t,e,n)}isPluginEnabled(t){return 1===this._plugins._cache.filter((e=>e.plugin.id===t)).length}_updateHoverStyles(t,e,n){const i=this.options.hover,s=(t,e)=>t.filter((t=>!e.some((e=>t.datasetIndex===e.datasetIndex&&t.index===e.index)))),o=s(e,t),a=n?t:s(t,e);o.length&&this.updateHoverStyle(o,i.mode,!1),a.length&&i.mode&&this.updateHoverStyle(a,i.mode,!0)}_eventHandler(t,e){const n={event:t,replay:e,cancelable:!0,inChartArea:this.isPointInArea(t)},i=e=>(e.options.events||this.options.events).includes(t.native.type);if(!1===this.notifyPlugins("beforeEvent",n,i))return;const s=this._handleEvent(t,e,n.inChartArea);return n.cancelable=!1,this.notifyPlugins("afterEvent",n,i),(s||n.changed)&&this.render(),this}_handleEvent(t,e,n){const{_active:i=[],options:s}=this,o=e,a=this._getActiveElements(t,i,n,o),r=function(t){return"mouseup"===t.type||"click"===t.type||"contextmenu"===t.type}(t),c=function(t,e,n,i){return n&&"mouseout"!==t.type?i?e:t:null}(t,this._lastEvent,n,r);n&&(this._lastEvent=null,bt(s.onHover,[t,a,this],this),r&&bt(s.onClick,[t,a,this],this));const l=!xt(a,i);return(l||e)&&(this._active=a,this._updateHoverStyles(a,i,e)),this._lastEvent=c,l}_getActiveElements(t,e,n,i){if("mouseout"===t.type)return[];if(!n)return e;const s=this.options.hover;return this.getElementsAtEventForMode(t,s.mode,s,i)}}function no(){return yt(eo.instances,(t=>t._plugins.invalidate()))}function io(t,e,n,i){const s=Ge(t.options.borderRadius,["outerStart","outerEnd","innerStart","innerEnd"]);const o=(n-e)/2,a=Math.min(o,i*e/2),r=t=>{const e=(n-Math.min(o,t))*i/2;return te(t,0,Math.min(o,e))};return{outerStart:r(s.outerStart),outerEnd:r(s.outerEnd),innerStart:te(s.innerStart,0,a),innerEnd:te(s.innerEnd,0,a)}}function so(t,e,n,i){return{x:n+t*Math.cos(e),y:i+t*Math.sin(e)}}function oo(t,e,n,i,s,o){const{x:a,y:r,startAngle:c,pixelMargin:l,innerRadius:d}=e,h=Math.max(e.outerRadius+i+n-l,0),u=d>0?d+i+n+l:0;let g=0;const p=s-c;if(i){const t=((d>0?d-i:0)+(h>0?h-i:0))/2;g=(p-(0!==t?p*t/(t+i):p))/2}const m=(p-Math.max(.001,p*h-n/Lt)/h)/2,f=c+m+g,b=s-m-g,{outerStart:y,outerEnd:x,innerStart:v,innerEnd:w}=io(e,u,h,b-f),S=h-y,k=h-x,M=f+y/S,C=b-x/k,_=u+v,D=u+w,T=f+v/_,P=b-w/D;if(t.beginPath(),o){const e=(M+C)/2;if(t.arc(a,r,h,M,e),t.arc(a,r,h,e,C),x>0){const e=so(k,C,a,r);t.arc(e.x,e.y,x,C,b+Nt)}const n=so(D,b,a,r);if(t.lineTo(n.x,n.y),w>0){const e=so(D,P,a,r);t.arc(e.x,e.y,w,b+Nt,P+Math.PI)}const i=(b-w/u+(f+v/u))/2;if(t.arc(a,r,u,b-w/u,i,!0),t.arc(a,r,u,i,f+v/u,!0),v>0){const e=so(_,T,a,r);t.arc(e.x,e.y,v,T+Math.PI,f-Nt)}const s=so(S,f,a,r);if(t.lineTo(s.x,s.y),y>0){const e=so(S,M,a,r);t.arc(e.x,e.y,y,f-Nt,M)}}else{t.moveTo(a,r);const e=Math.cos(M)*h+a,n=Math.sin(M)*h+r;t.lineTo(e,n);const i=Math.cos(C)*h+a,s=Math.sin(C)*h+r;t.lineTo(i,s)}t.closePath()}function ao(t,e,n,i,s){const{fullCircles:o,startAngle:a,circumference:r,options:c}=e,{borderWidth:l,borderJoinStyle:d,borderDash:h,borderDashOffset:u,borderRadius:g}=c,p="inner"===c.borderAlign;if(!l)return;t.setLineDash(h||[]),t.lineDashOffset=u,p?(t.lineWidth=2*l,t.lineJoin=d||"round"):(t.lineWidth=l,t.lineJoin=d||"bevel");let m=e.endAngle;if(o){oo(t,e,n,i,m,s);for(let e=0;e<o;++e)t.stroke();isNaN(r)||(m=a+(r%It||It))}p&&function(t,e,n){const{startAngle:i,pixelMargin:s,x:o,y:a,outerRadius:r,innerRadius:c}=e;let l=s/r;t.beginPath(),t.arc(o,a,r,i-l,n+l),c>s?(l=s/c,t.arc(o,a,c,n+l,i-l,!0)):t.arc(o,a,s,n+Nt,i-Nt),t.closePath(),t.clip()}(t,e,m),c.selfJoin&&m-a>=Lt&&0===g&&"miter"!==d&&function(t,e,n){const{startAngle:i,x:s,y:o,outerRadius:a,innerRadius:r,options:c}=e,{borderWidth:l,borderJoinStyle:d}=c,h=Math.min(l/a,Zt(i-n));if(t.beginPath(),t.arc(s,o,a-l/2,i+h/2,n-h/2),r>0){const e=Math.min(l/r,Zt(i-n));t.arc(s,o,r+l/2,n-e/2,i+e/2,!0)}else{const e=Math.min(l/2,a*Zt(i-n));if("round"===d)t.arc(s,o,e,n-Lt/2,i+Lt/2,!0);else if("bevel"===d){const a=2*e*e,r=-a*Math.cos(n+Lt/2)+s,c=-a*Math.sin(n+Lt/2)+o,l=a*Math.cos(i+Lt/2)+s,d=a*Math.sin(i+Lt/2)+o;t.lineTo(r,c),t.lineTo(l,d)}}t.closePath(),t.moveTo(0,0),t.rect(0,0,t.canvas.width,t.canvas.height),t.clip("evenodd")}(t,e,m),o||(oo(t,e,n,i,m,s),t.stroke())}function ro(t,e,n=e){t.lineCap=mt(n.borderCapStyle,e.borderCapStyle),t.setLineDash(mt(n.borderDash,e.borderDash)),t.lineDashOffset=mt(n.borderDashOffset,e.borderDashOffset),t.lineJoin=mt(n.borderJoinStyle,e.borderJoinStyle),t.lineWidth=mt(n.borderWidth,e.borderWidth),t.strokeStyle=mt(n.borderColor,e.borderColor)}function co(t,e,n){t.lineTo(n.x,n.y)}function lo(t,e,n={}){const i=t.length,{start:s=0,end:o=i-1}=n,{start:a,end:r}=e,c=Math.max(s,a),l=Math.min(o,r),d=s<a&&o<a||s>r&&o>r;return{count:i,start:c,loop:e.loop,ilen:l<c&&!d?i+l-c:l-c}}function ho(t,e,n,i){const{points:s,options:o}=e,{count:a,start:r,loop:c,ilen:l}=lo(s,n,i),d=function(t){return t.stepped?Be:t.tension||"monotone"===t.cubicInterpolationMode?He:co}(o);let h,u,g,{move:p=!0,reverse:m}=i||{};for(h=0;h<=l;++h)u=s[(r+(m?l-h:h))%a],u.skip||(p?(t.moveTo(u.x,u.y),p=!1):d(t,g,u,m,o.stepped),g=u);return c&&(u=s[(r+(m?l:0))%a],d(t,g,u,m,o.stepped)),!!c}function uo(t,e,n,i){const s=e.points,{count:o,start:a,ilen:r}=lo(s,n,i),{move:c=!0,reverse:l}=i||{};let d,h,u,g,p,m,f=0,b=0;const y=t=>(a+(l?r-t:t))%o,x=()=>{g!==p&&(t.lineTo(f,p),t.lineTo(f,g),t.lineTo(f,m))};for(c&&(h=s[y(0)],t.moveTo(h.x,h.y)),d=0;d<=r;++d){if(h=s[y(d)],h.skip)continue;const e=h.x,n=h.y,i=0|e;i===u?(n<g?g=n:n>p&&(p=n),f=(b*f+e)/++b):(x(),t.lineTo(e,n),u=i,b=0,g=p=n),m=n}x()}function go(t){const e=t.options,n=e.borderDash&&e.borderDash.length;return!(t._decimated||t._loop||e.tension||"monotone"===e.cubicInterpolationMode||e.stepped||n)?uo:ho}const po="function"==typeof Path2D;function mo(t,e,n,i){po&&!e.options.segment?function(t,e,n,i){let s=e._path;s||(s=e._path=new Path2D,e.path(s,n,i)&&s.closePath()),ro(t,e.options),t.stroke(s)}(t,e,n,i):function(t,e,n,i){const{segments:s,options:o}=e,a=go(e);for(const r of s)ro(t,o,r.style),t.beginPath(),a(t,e,r,{start:n,end:n+i-1})&&t.closePath(),t.stroke()}(t,e,n,i)}class fo extends ms{static id="line";static defaults={borderCapStyle:"butt",borderDash:[],borderDashOffset:0,borderJoinStyle:"miter",borderWidth:3,capBezierPoints:!0,cubicInterpolationMode:"default",fill:!1,spanGaps:!1,stepped:!1,tension:0};static defaultRoutes={backgroundColor:"backgroundColor",borderColor:"borderColor"};static descriptors={_scriptable:!0,_indexable:t=>"borderDash"!==t&&"fill"!==t};constructor(t){super(),this.animated=!0,this.options=void 0,this._chart=void 0,this._loop=void 0,this._fullLoop=void 0,this._path=void 0,this._points=void 0,this._segments=void 0,this._decimated=!1,this._pointsUpdated=!1,this._datasetIndex=void 0,t&&Object.assign(this,t)}updateControlPoints(t,e){const n=this.options;if((n.tension||"monotone"===n.cubicInterpolationMode)&&!n.stepped&&!this._pointsUpdated){const i=n.spanGaps?this._loop:this._fullLoop;Cn(this._points,n,t,i,e),this._pointsUpdated=!0}}set points(t){this._points=t,delete this._segments,delete this._path,this._pointsUpdated=!1}get points(){return this._points}get segments(){return this._segments||(this._segments=function(t,e){const n=t.points,i=t.options.spanGaps,s=n.length;if(!s)return[];const o=!!t._loop,{start:a,end:r}=function(t,e,n,i){let s=0,o=e-1;if(n&&!i)for(;s<e&&!t[s].skip;)s++;for(;s<e&&t[s].skip;)s++;for(s%=e,n&&(o+=s);o>s&&t[o%e].skip;)o--;return o%=e,{start:s,end:o}}(n,s,o,i);return Xn(t,!0===i?[{start:a,end:r,loop:o}]:function(t,e,n,i){const s=t.length,o=[];let a,r=e,c=t[e];for(a=e+1;a<=n;++a){const n=t[a%s];n.skip||n.stop?c.skip||(i=!1,o.push({start:e%s,end:(a-1)%s,loop:i}),e=r=n.stop?a:null):(r=a,c.skip&&(e=a)),c=n}return null!==r&&o.push({start:e%s,end:r%s,loop:i}),o}(n,a,r<a?r+s:r,!!t._fullLoop&&0===a&&r===s-1),n,e)}(this,this.options.segment))}first(){const t=this.segments,e=this.points;return t.length&&e[t[0].start]}last(){const t=this.segments,e=this.points,n=t.length;return n&&e[t[n-1].end]}interpolate(t,e){const n=this.options,i=t[e],s=this.points,o=Un(this,{property:e,start:i,end:i});if(!o.length)return;const a=[],r=function(t){return t.stepped?$n:t.tension||"monotone"===t.cubicInterpolationMode?Fn:Rn}(n);let c,l;for(c=0,l=o.length;c<l;++c){const{start:l,end:d}=o[c],h=s[l],u=s[d];if(h===u){a.push(h);continue}const g=r(h,u,Math.abs((i-h[e])/(u[e]-h[e])),n.stepped);g[e]=t[e],a.push(g)}return 1===a.length?a[0]:a}pathSegment(t,e,n){return go(this)(t,this,e,n)}path(t,e,n){const i=this.segments,s=go(this);let o=this._loop;e=e||0,n=n||this.points.length-e;for(const a of i)o&=s(t,this,a,{start:e,end:e+n-1});return!!o}draw(t,e,n,i){const s=this.options||{};(this.points||[]).length&&s.borderWidth&&(t.save(),mo(t,this,n,i),t.restore()),this.animated&&(this._pointsUpdated=!1,this._path=void 0)}}function bo(t,e,n,i){const s=t.options,{[n]:o}=t.getProps([n],i);return Math.abs(e-o)<s.radius+s.hitRadius}function yo(t,e){const{x:n,y:i,base:s,width:o,height:a}=t.getProps(["x","y","base","width","height"],e);let r,c,l,d,h;return t.horizontal?(h=a/2,r=Math.min(n,s),c=Math.max(n,s),l=i-h,d=i+h):(h=o/2,r=n-h,c=n+h,l=Math.min(i,s),d=Math.max(i,s)),{left:r,top:l,right:c,bottom:d}}function xo(t,e,n,i){return t?0:te(e,n,i)}function vo(t){const e=yo(t),n=e.right-e.left,i=e.bottom-e.top,s=function(t,e,n){const i=t.options.borderWidth,s=t.borderSkipped,o=Ze(i);return{t:xo(s.top,o.top,0,n),r:xo(s.right,o.right,0,e),b:xo(s.bottom,o.bottom,0,n),l:xo(s.left,o.left,0,e)}}(t,n/2,i/2),o=function(t,e,n){const{enableBorderRadius:i}=t.getProps(["enableBorderRadius"]),s=t.options.borderRadius,o=Je(s),a=Math.min(e,n),r=t.borderSkipped,c=i||ut(s);return{topLeft:xo(!c||r.top||r.left,o.topLeft,0,a),topRight:xo(!c||r.top||r.right,o.topRight,0,a),bottomLeft:xo(!c||r.bottom||r.left,o.bottomLeft,0,a),bottomRight:xo(!c||r.bottom||r.right,o.bottomRight,0,a)}}(t,n/2,i/2);return{outer:{x:e.left,y:e.top,w:n,h:i,radius:o},inner:{x:e.left+s.l,y:e.top+s.t,w:n-s.l-s.r,h:i-s.t-s.b,radius:{topLeft:Math.max(0,o.topLeft-Math.max(s.t,s.l)),topRight:Math.max(0,o.topRight-Math.max(s.t,s.r)),bottomLeft:Math.max(0,o.bottomLeft-Math.max(s.b,s.l)),bottomRight:Math.max(0,o.bottomRight-Math.max(s.b,s.r))}}}}function wo(t,e,n,i){const s=null===e,o=null===n,a=t&&!(s&&o)&&yo(t,i);return a&&(s||ee(e,a.left,a.right))&&(o||ee(n,a.top,a.bottom))}function So(t,e){t.rect(e.x,e.y,e.w,e.h)}function ko(t,e,n={}){const i=t.x!==n.x?-e:0,s=t.y!==n.y?-e:0,o=(t.x+t.w!==n.x+n.w?e:0)-i,a=(t.y+t.h!==n.y+n.h?e:0)-s;return{x:t.x+i,y:t.y+s,w:t.w+o,h:t.h+a,radius:t.radius}}class Mo extends ms{static id="bar";static defaults={borderSkipped:"start",borderWidth:0,borderRadius:0,inflateAmount:"auto",pointStyle:void 0};static defaultRoutes={backgroundColor:"backgroundColor",borderColor:"borderColor"};constructor(t){super(),this.options=void 0,this.horizontal=void 0,this.base=void 0,this.width=void 0,this.height=void 0,this.inflateAmount=void 0,t&&Object.assign(this,t)}draw(t){const{inflateAmount:e,options:{borderColor:n,backgroundColor:i}}=this,{inner:s,outer:o}=vo(this),a=(r=o.radius).topLeft||r.topRight||r.bottomLeft||r.bottomRight?Ue:So;var r;t.save(),o.w===s.w&&o.h===s.h||(t.beginPath(),a(t,ko(o,e,s)),t.clip(),a(t,ko(s,-e,o)),t.fillStyle=n,t.fill("evenodd")),t.beginPath(),a(t,ko(s,e)),t.fillStyle=i,t.fill(),t.restore()}inRange(t,e,n){return wo(this,t,e,n)}inXRange(t,e){return wo(this,t,null,e)}inYRange(t,e){return wo(this,null,t,e)}getCenterPoint(t){const{x:e,y:n,base:i,horizontal:s}=this.getProps(["x","y","base","horizontal"],t);return{x:s?(e+i)/2:e,y:s?n:(n+i)/2}}getRange(t){return"x"===t?this.width/2:this.height/2}}var Co=Object.freeze({__proto__:null,ArcElement:class extends ms{static id="arc";static defaults={borderAlign:"center",borderColor:"#fff",borderDash:[],borderDashOffset:0,borderJoinStyle:void 0,borderRadius:0,borderWidth:2,offset:0,spacing:0,angle:void 0,circular:!0,selfJoin:!1};static defaultRoutes={backgroundColor:"backgroundColor"};static descriptors={_scriptable:!0,_indexable:t=>"borderDash"!==t};circumference;endAngle;fullCircles;innerRadius;outerRadius;pixelMargin;startAngle;constructor(t){super(),this.options=void 0,this.circumference=void 0,this.startAngle=void 0,this.endAngle=void 0,this.innerRadius=void 0,this.outerRadius=void 0,this.pixelMargin=0,this.fullCircles=0,t&&Object.assign(this,t)}inRange(t,e,n){const i=this.getProps(["x","y"],n),{angle:s,distance:o}=Qt(i,{x:t,y:e}),{startAngle:a,endAngle:r,innerRadius:c,outerRadius:l,circumference:d}=this.getProps(["startAngle","endAngle","innerRadius","outerRadius","circumference"],n),h=(this.options.spacing+this.options.borderWidth)/2,u=mt(d,r-a),g=Jt(s,a,r)&&a!==r,p=u>=It||g,m=ee(o,c+h,l+h);return p&&m}getCenterPoint(t){const{x:e,y:n,startAngle:i,endAngle:s,innerRadius:o,outerRadius:a}=this.getProps(["x","y","startAngle","endAngle","innerRadius","outerRadius"],t),{offset:r,spacing:c}=this.options,l=(i+s)/2,d=(o+a+c+r)/2;return{x:e+Math.cos(l)*d,y:n+Math.sin(l)*d}}tooltipPosition(t){return this.getCenterPoint(t)}draw(t){const{options:e,circumference:n}=this,i=(e.offset||0)/4,s=(e.spacing||0)/2,o=e.circular;if(this.pixelMargin="inner"===e.borderAlign?.33:0,this.fullCircles=n>It?Math.floor(n/It):0,0===n||this.innerRadius<0||this.outerRadius<0)return;t.save();const a=(this.startAngle+this.endAngle)/2;t.translate(Math.cos(a)*i,Math.sin(a)*i);const r=i*(1-Math.sin(Math.min(Lt,n||0)));t.fillStyle=e.backgroundColor,t.strokeStyle=e.borderColor,function(t,e,n,i,s){const{fullCircles:o,startAngle:a,circumference:r}=e;let c=e.endAngle;if(o){oo(t,e,n,i,c,s);for(let e=0;e<o;++e)t.fill();isNaN(r)||(c=a+(r%It||It))}oo(t,e,n,i,c,s),t.fill()}(t,this,r,s,o),ao(t,this,r,s,o),t.restore()}},BarElement:Mo,LineElement:fo,PointElement:class extends ms{static id="point";parsed;skip;stop;static defaults={borderWidth:1,hitRadius:1,hoverBorderWidth:1,hoverRadius:4,pointStyle:"circle",radius:3,rotation:0};static defaultRoutes={backgroundColor:"backgroundColor",borderColor:"borderColor"};constructor(t){super(),this.options=void 0,this.parsed=void 0,this.skip=void 0,this.stop=void 0,t&&Object.assign(this,t)}inRange(t,e,n){const i=this.options,{x:s,y:o}=this.getProps(["x","y"],n);return Math.pow(t-s,2)+Math.pow(e-o,2)<Math.pow(i.hitRadius+i.radius,2)}inXRange(t,e){return bo(this,t,"x",e)}inYRange(t,e){return bo(this,t,"y",e)}getCenterPoint(t){const{x:e,y:n}=this.getProps(["x","y"],t);return{x:e,y:n}}size(t){let e=(t=t||this.options||{}).radius||0;e=Math.max(e,e&&t.hoverRadius||0);return 2*(e+(e&&t.borderWidth||0))}draw(t,e){const n=this.options;this.skip||n.radius<.1||!$e(this,e,this.size(n)/2)||(t.strokeStyle=n.borderColor,t.lineWidth=n.borderWidth,t.fillStyle=n.backgroundColor,Ne(t,n,this.x,this.y))}getRange(){const t=this.options||{};return t.radius+t.hitRadius}}});const _o=["rgb(54, 162, 235)","rgb(255, 99, 132)","rgb(255, 159, 64)","rgb(255, 205, 86)","rgb(75, 192, 192)","rgb(153, 102, 255)","rgb(201, 203, 207)"],Do=_o.map((t=>t.replace("rgb(","rgba(").replace(")",", 0.5)")));function To(t){return _o[t%_o.length]}function Po(t){return Do[t%Do.length]}function Eo(t){let e=0;return(n,i)=>{const s=t.getDatasetMeta(i).controller;s instanceof _i?e=function(t,e){return t.backgroundColor=t.data.map((()=>To(e++))),e}(n,e):s instanceof Di?e=function(t,e){return t.backgroundColor=t.data.map((()=>Po(e++))),e}(n,e):s&&(e=function(t,e){return t.borderColor=To(e),t.backgroundColor=Po(e),++e}(n,e))}}function Ao(t){let e;for(e in t)if(t[e].borderColor||t[e].backgroundColor)return!0;return!1}var Lo={id:"colors",defaults:{enabled:!0,forceOverride:!1},beforeLayout(t,e,n){if(!n.enabled)return;const{data:{datasets:i},options:s}=t.config,{elements:o}=s,a=Ao(i)||(r=s)&&(r.borderColor||r.backgroundColor)||o&&Ao(o)||"rgba(0,0,0,0.1)"!==Le.borderColor||"rgba(0,0,0,0.1)"!==Le.backgroundColor;var r;if(!n.forceOverride&&a)return;const c=Eo(t);i.forEach(c)}};function Io(t){if(t._decimated){const e=t._data;delete t._decimated,delete t._data,Object.defineProperty(t,"data",{configurable:!0,enumerable:!0,writable:!0,value:e})}}function Oo(t){t.data.datasets.forEach((t=>{Io(t)}))}var zo={id:"decimation",defaults:{algorithm:"min-max",enabled:!1},beforeElementsUpdate:(t,e,n)=>{if(!n.enabled)return void Oo(t);const i=t.width;t.data.datasets.forEach(((e,s)=>{const{_data:o,indexAxis:a}=e,r=t.getDatasetMeta(s),c=o||e.data;if("y"===nn([a,t.options.indexAxis]))return;if(!r.controller.supportsDecimation)return;const l=t.scales[r.xAxisID];if("linear"!==l.type&&"time"!==l.type)return;if(t.options.parsing)return;let{start:d,count:h}=function(t,e){const n=e.length;let i,s=0;const{iScale:o}=t,{min:a,max:r,minDefined:c,maxDefined:l}=o.getUserBounds();return c&&(s=te(ie(e,o.axis,a).lo,0,n-1)),i=l?te(ie(e,o.axis,r).hi+1,s,n)-s:n-s,{start:s,count:i}}(r,c);if(h<=(n.threshold||4*i))return void Io(e);let u;switch(dt(o)&&(e._data=c,delete e.data,Object.defineProperty(e,"data",{configurable:!0,enumerable:!0,get:function(){return this._decimated},set:function(t){this._data=t}})),n.algorithm){case"lttb":u=function(t,e,n,i,s){const o=s.samples||i;if(o>=n)return t.slice(e,e+n);const a=[],r=(n-2)/(o-2);let c=0;const l=e+n-1;let d,h,u,g,p,m=e;for(a[c++]=t[m],d=0;d<o-2;d++){let i,s=0,o=0;const l=Math.floor((d+1)*r)+1+e,f=Math.min(Math.floor((d+2)*r)+1,n)+e,b=f-l;for(i=l;i<f;i++)s+=t[i].x,o+=t[i].y;s/=b,o/=b;const y=Math.floor(d*r)+1+e,x=Math.min(Math.floor((d+1)*r)+1,n)+e,{x:v,y:w}=t[m];for(u=g=-1,i=y;i<x;i++)g=.5*Math.abs((v-s)*(t[i].y-w)-(v-t[i].x)*(o-w)),g>u&&(u=g,h=t[i],p=i);a[c++]=h,m=p}return a[c++]=t[l],a}(c,d,h,i,n);break;case"min-max":u=function(t,e,n,i){let s,o,a,r,c,l,d,h,u,g,p=0,m=0;const f=[],b=e+n-1,y=t[e].x,x=t[b].x-y;for(s=e;s<e+n;++s){o=t[s],a=(o.x-y)/x*i,r=o.y;const e=0|a;if(e===c)r<u?(u=r,l=s):r>g&&(g=r,d=s),p=(m*p+o.x)/++m;else{const n=s-1;if(!dt(l)&&!dt(d)){const e=Math.min(l,d),i=Math.max(l,d);e!==h&&e!==n&&f.push({...t[e],x:p}),i!==h&&i!==n&&f.push({...t[i],x:p})}s>0&&n!==h&&f.push(t[n]),f.push(o),c=e,m=0,u=g=r,l=d=h=s}}return f}(c,d,h,i);break;default:throw new Error(`Unsupported decimation algorithm '${n.algorithm}'`)}e._decimated=u}))},destroy(t){Oo(t)}};function Wo(t,e,n,i){if(i)return;let s=e[t],o=n[t];return"angle"===t&&(s=Zt(s),o=Zt(o)),{property:t,start:s,end:o}}function No(t,e,n){for(;e>t;e--){const t=n[e];if(!isNaN(t.x)&&!isNaN(t.y))break}return e}function Ro(t,e,n,i){return t&&e?i(t[n],e[n]):t?t[n]:e?e[n]:0}function $o(t,e){let n=[],i=!1;return ht(t)?(i=!0,n=t):n=function(t,e){const{x:n=null,y:i=null}=t||{},s=e.points,o=[];return e.segments.forEach((({start:t,end:e})=>{e=No(t,e,s);const a=s[t],r=s[e];null!==i?(o.push({x:a.x,y:i}),o.push({x:r.x,y:i})):null!==n&&(o.push({x:n,y:a.y}),o.push({x:n,y:r.y}))})),o}(t,e),n.length?new fo({points:n,options:{tension:0},_loop:i,_fullLoop:i}):null}function Fo(t){return t&&!1!==t.fill}function qo(t,e,n){let i=t[e].fill;const s=[e];let o;if(!n)return i;for(;!1!==i&&-1===s.indexOf(i);){if(!gt(i))return i;if(o=t[i],!o)return!1;if(o.visible)return i;s.push(i),i=o.fill}return!1}function Bo(t,e,n){const i=function(t){const e=t.options,n=e.fill;let i=mt(n&&n.target,n);void 0===i&&(i=!!e.backgroundColor);if(!1===i||null===i)return!1;if(!0===i)return"origin";return i}(t);if(ut(i))return!isNaN(i.value)&&i;let s=parseFloat(i);return gt(s)&&Math.floor(s)===s?function(t,e,n,i){"-"!==t&&"+"!==t||(n=e+n);if(n===e||n<0||n>=i)return!1;return n}(i[0],e,s,n):["origin","start","end","stack","shape"].indexOf(i)>=0&&i}function Ho(t,e,n){const i=[];for(let s=0;s<n.length;s++){const o=n[s],{first:a,last:r,point:c}=Vo(o,e,"x");if(!(!c||a&&r))if(a)i.unshift(c);else if(t.push(c),!r)break}t.push(...i)}function Vo(t,e,n){const i=t.interpolate(e,n);if(!i)return{};const s=i[n],o=t.segments,a=t.points;let r=!1,c=!1;for(let t=0;t<o.length;t++){const e=o[t],i=a[e.start][n],l=a[e.end][n];if(ee(s,i,l)){r=s===i,c=s===l;break}}return{first:r,last:c,point:i}}class jo{constructor(t){this.x=t.x,this.y=t.y,this.radius=t.radius}pathSegment(t,e,n){const{x:i,y:s,radius:o}=this;return e=e||{start:0,end:It},t.arc(i,s,o,e.end,e.start,!0),!n.bounds}interpolate(t){const{x:e,y:n,radius:i}=this,s=t.angle;return{x:e+Math.cos(s)*i,y:n+Math.sin(s)*i,angle:s}}}function Yo(t){const{chart:e,fill:n,line:i}=t;if(gt(n))return function(t,e){const n=t.getDatasetMeta(e),i=n&&t.isDatasetVisible(e);return i?n.dataset:null}(e,n);if("stack"===n)return function(t){const{scale:e,index:n,line:i}=t,s=[],o=i.segments,a=i.points,r=function(t,e){const n=[],i=t.getMatchingVisibleMetas("line");for(let t=0;t<i.length;t++){const s=i[t];if(s.index===e)break;s.hidden||n.unshift(s.dataset)}return n}(e,n);r.push($o({x:null,y:e.bottom},i));for(let t=0;t<o.length;t++){const e=o[t];for(let t=e.start;t<=e.end;t++)Ho(s,a[t],r)}return new fo({points:s,options:{}})}(t);if("shape"===n)return!0;const s=function(t){const e=t.scale||{};if(e.getPointPositionForValue)return function(t){const{scale:e,fill:n}=t,i=e.options,s=e.getLabels().length,o=i.reverse?e.max:e.min,a=function(t,e,n){let i;return i="start"===t?n:"end"===t?e.options.reverse?e.min:e.max:ut(t)?t.value:e.getBaseValue(),i}(n,e,o),r=[];if(i.grid.circular){const t=e.getPointPositionForValue(0,o);return new jo({x:t.x,y:t.y,radius:e.getDistanceFromCenterForValue(a)})}for(let t=0;t<s;++t)r.push(e.getPointPositionForValue(t,a));return r}(t);return function(t){const{scale:e={},fill:n}=t,i=function(t,e){let n=null;return"start"===t?n=e.bottom:"end"===t?n=e.top:ut(t)?n=e.getPixelForValue(t.value):e.getBasePixel&&(n=e.getBasePixel()),n}(n,e);if(gt(i)){const t=e.isHorizontal();return{x:t?i:null,y:t?null:i}}return null}(t)}(t);return s instanceof jo?s:$o(s,i)}function Uo(t,e,n){const i=Yo(e),{chart:s,index:o,line:a,scale:r,axis:c}=e,l=a.options,d=l.fill,h=l.backgroundColor,{above:u=h,below:g=h}=d||{},p=s.getDatasetMeta(o),m=Zn(s,p);i&&a.points.length&&(Fe(t,n),function(t,e){const{line:n,target:i,above:s,below:o,area:a,scale:r,clip:c}=e,l=n._loop?"angle":e.axis;t.save();let d=o;o!==s&&("x"===l?(Xo(t,i,a.top),Ko(t,{line:n,target:i,color:s,scale:r,property:l,clip:c}),t.restore(),t.save(),Xo(t,i,a.bottom)):"y"===l&&(Qo(t,i,a.left),Ko(t,{line:n,target:i,color:o,scale:r,property:l,clip:c}),t.restore(),t.save(),Qo(t,i,a.right),d=s));Ko(t,{line:n,target:i,color:d,scale:r,property:l,clip:c}),t.restore()}(t,{line:a,target:i,above:u,below:g,area:n,scale:r,axis:c,clip:m}),qe(t))}function Xo(t,e,n){const{segments:i,points:s}=e;let o=!0,a=!1;t.beginPath();for(const r of i){const{start:i,end:c}=r,l=s[i],d=s[No(i,c,s)];o?(t.moveTo(l.x,l.y),o=!1):(t.lineTo(l.x,n),t.lineTo(l.x,l.y)),a=!!e.pathSegment(t,r,{move:a}),a?t.closePath():t.lineTo(d.x,n)}t.lineTo(e.first().x,n),t.closePath(),t.clip()}function Qo(t,e,n){const{segments:i,points:s}=e;let o=!0,a=!1;t.beginPath();for(const r of i){const{start:i,end:c}=r,l=s[i],d=s[No(i,c,s)];o?(t.moveTo(l.x,l.y),o=!1):(t.lineTo(n,l.y),t.lineTo(l.x,l.y)),a=!!e.pathSegment(t,r,{move:a}),a?t.closePath():t.lineTo(n,d.y)}t.lineTo(n,e.first().y),t.closePath(),t.clip()}function Ko(t,e){const{line:n,target:i,property:s,color:o,scale:a,clip:r}=e,c=function(t,e,n){const i=t.segments,s=t.points,o=e.points,a=[];for(const t of i){let{start:i,end:r}=t;r=No(i,r,s);const c=Wo(n,s[i],s[r],t.loop);if(!e.segments){a.push({source:t,target:c,start:s[i],end:s[r]});continue}const l=Un(e,c);for(const e of l){const i=Wo(n,o[e.start],o[e.end],e.loop),r=Yn(t,s,i);for(const t of r)a.push({source:t,target:e,start:{[n]:Ro(c,i,"start",Math.max)},end:{[n]:Ro(c,i,"end",Math.min)}})}}return a}(n,i,s);for(const{source:e,target:l,start:d,end:h}of c){const{style:{backgroundColor:c=o}={}}=e,u=!0!==i;t.save(),t.fillStyle=c,Go(t,a,r,u&&Wo(s,d,h)),t.beginPath();const g=!!n.pathSegment(t,e);let p;if(u){g?t.closePath():Zo(t,i,h,s);const e=!!i.pathSegment(t,l,{move:g,reverse:!0});p=g&&e,p||Zo(t,i,d,s)}t.closePath(),t.fill(p?"evenodd":"nonzero"),t.restore()}}function Go(t,e,n,i){const s=e.chart.chartArea,{property:o,start:a,end:r}=i||{};if("x"===o||"y"===o){let e,i,c,l;"x"===o?(e=a,i=s.top,c=r,l=s.bottom):(e=s.left,i=a,c=s.right,l=r),t.beginPath(),n&&(e=Math.max(e,n.left),c=Math.min(c,n.right),i=Math.max(i,n.top),l=Math.min(l,n.bottom)),t.rect(e,i,c-e,l-i),t.clip()}}function Zo(t,e,n,i){const s=e.interpolate(n,i);s&&t.lineTo(s.x,s.y)}var Jo={id:"filler",afterDatasetsUpdate(t,e,n){const i=(t.data.datasets||[]).length,s=[];let o,a,r,c;for(a=0;a<i;++a)o=t.getDatasetMeta(a),r=o.dataset,c=null,r&&r.options&&r instanceof fo&&(c={visible:t.isDatasetVisible(a),index:a,fill:Bo(r,a,i),chart:t,axis:o.controller.options.indexAxis,scale:o.vScale,line:r}),o.$filler=c,s.push(c);for(a=0;a<i;++a)c=s[a],c&&!1!==c.fill&&(c.fill=qo(s,a,n.propagate))},beforeDraw(t,e,n){const i="beforeDraw"===n.drawTime,s=t.getSortedVisibleDatasetMetas(),o=t.chartArea;for(let e=s.length-1;e>=0;--e){const n=s[e].$filler;n&&(n.line.updateControlPoints(o,n.axis),i&&n.fill&&Uo(t.ctx,n,o))}},beforeDatasetsDraw(t,e,n){if("beforeDatasetsDraw"!==n.drawTime)return;const i=t.getSortedVisibleDatasetMetas();for(let e=i.length-1;e>=0;--e){const n=i[e].$filler;Fo(n)&&Uo(t.ctx,n,t.chartArea)}},beforeDatasetDraw(t,e,n){const i=e.meta.$filler;Fo(i)&&"beforeDatasetDraw"===n.drawTime&&Uo(t.ctx,i,t.chartArea)},defaults:{propagate:!0,drawTime:"beforeDatasetDraw"}};const ta=(t,e)=>{let{boxHeight:n=e,boxWidth:i=e}=t;return t.usePointStyle&&(n=Math.min(n,e),i=t.pointStyleWidth||Math.min(i,e)),{boxWidth:i,boxHeight:n,itemHeight:Math.max(e,n)}};class ea extends ms{constructor(t){super(),this._added=!1,this.legendHitBoxes=[],this._hoveredItem=null,this.doughnutMode=!1,this.chart=t.chart,this.options=t.options,this.ctx=t.ctx,this.legendItems=void 0,this.columnSizes=void 0,this.lineWidths=void 0,this.maxHeight=void 0,this.maxWidth=void 0,this.top=void 0,this.bottom=void 0,this.left=void 0,this.right=void 0,this.height=void 0,this.width=void 0,this._margins=void 0,this.position=void 0,this.weight=void 0,this.fullSize=void 0}update(t,e,n){this.maxWidth=t,this.maxHeight=e,this._margins=n,this.setDimensions(),this.buildLabels(),this.fit()}setDimensions(){this.isHorizontal()?(this.width=this.maxWidth,this.left=this._margins.left,this.right=this.width):(this.height=this.maxHeight,this.top=this._margins.top,this.bottom=this.height)}buildLabels(){const t=this.options.labels||{};let e=bt(t.generateLabels,[this.chart],this)||[];t.filter&&(e=e.filter((e=>t.filter(e,this.chart.data)))),t.sort&&(e=e.sort(((e,n)=>t.sort(e,n,this.chart.data)))),this.options.reverse&&e.reverse(),this.legendItems=e}fit(){const{options:t,ctx:e}=this;if(!t.display)return void(this.width=this.height=0);const n=t.labels,i=en(n.font),s=i.size,o=this._computeTitleHeight(),{boxWidth:a,itemHeight:r}=ta(n,s);let c,l;e.font=i.string,this.isHorizontal()?(c=this.maxWidth,l=this._fitRows(o,s,a,r)+10):(l=this.maxHeight,c=this._fitCols(o,i,a,r)+10),this.width=Math.min(c,t.maxWidth||this.maxWidth),this.height=Math.min(l,t.maxHeight||this.maxHeight)}_fitRows(t,e,n,i){const{ctx:s,maxWidth:o,options:{labels:{padding:a}}}=this,r=this.legendHitBoxes=[],c=this.lineWidths=[0],l=i+a;let d=t;s.textAlign="left",s.textBaseline="middle";let h=-1,u=-l;return this.legendItems.forEach(((t,g)=>{const p=n+e/2+s.measureText(t.text).width;(0===g||c[c.length-1]+p+2*a>o)&&(d+=l,c[c.length-(g>0?0:1)]=0,u+=l,h++),r[g]={left:0,top:u,row:h,width:p,height:i},c[c.length-1]+=p+a})),d}_fitCols(t,e,n,i){const{ctx:s,maxHeight:o,options:{labels:{padding:a}}}=this,r=this.legendHitBoxes=[],c=this.columnSizes=[],l=o-t;let d=a,h=0,u=0,g=0,p=0;return this.legendItems.forEach(((t,o)=>{const{itemWidth:m,itemHeight:f}=function(t,e,n,i,s){const o=function(t,e,n,i){let s=t.text;s&&"string"!=typeof s&&(s=s.reduce(((t,e)=>t.length>e.length?t:e)));return e+n.size/2+i.measureText(s).width}(i,t,e,n),a=function(t,e,n){let i=t;"string"!=typeof e.text&&(i=na(e,n));return i}(s,i,e.lineHeight);return{itemWidth:o,itemHeight:a}}(n,e,s,t,i);o>0&&u+f+2*a>l&&(d+=h+a,c.push({width:h,height:u}),g+=h+a,p++,h=u=0),r[o]={left:g,top:u,col:p,width:m,height:f},h=Math.max(h,m),u+=f+a})),d+=h,c.push({width:h,height:u}),d}adjustHitBoxes(){if(!this.options.display)return;const t=this._computeTitleHeight(),{legendHitBoxes:e,options:{align:n,labels:{padding:i},rtl:s}}=this,o=qn(s,this.left,this.width);if(this.isHorizontal()){let s=0,a=he(n,this.left+i,this.right-this.lineWidths[s]);for(const r of e)s!==r.row&&(s=r.row,a=he(n,this.left+i,this.right-this.lineWidths[s])),r.top+=this.top+t+i,r.left=o.leftForLtr(o.x(a),r.width),a+=r.width+i}else{let s=0,a=he(n,this.top+t+i,this.bottom-this.columnSizes[s].height);for(const r of e)r.col!==s&&(s=r.col,a=he(n,this.top+t+i,this.bottom-this.columnSizes[s].height)),r.top=a,r.left+=this.left+i,r.left=o.leftForLtr(o.x(r.left),r.width),a+=r.height+i}}isHorizontal(){return"top"===this.options.position||"bottom"===this.options.position}draw(){if(this.options.display){const t=this.ctx;Fe(t,this),this._draw(),qe(t)}}_draw(){const{options:t,columnSizes:e,lineWidths:n,ctx:i}=this,{align:s,labels:o}=t,a=Le.color,r=qn(t.rtl,this.left,this.width),c=en(o.font),{padding:l}=o,d=c.size,h=d/2;let u;this.drawTitle(),i.textAlign=r.textAlign("left"),i.textBaseline="middle",i.lineWidth=.5,i.font=c.string;const{boxWidth:g,boxHeight:p,itemHeight:m}=ta(o,d),f=this.isHorizontal(),b=this._computeTitleHeight();u=f?{x:he(s,this.left+l,this.right-n[0]),y:this.top+l+b,line:0}:{x:this.left+l,y:he(s,this.top+b+l,this.bottom-e[0].height),line:0},Bn(this.ctx,t.textDirection);const y=m+l;this.legendItems.forEach(((x,v)=>{i.strokeStyle=x.fontColor,i.fillStyle=x.fontColor;const w=i.measureText(x.text).width,S=r.textAlign(x.textAlign||(x.textAlign=o.textAlign)),k=g+h+w;let M=u.x,C=u.y;r.setWidth(this.width),f?v>0&&M+k+l>this.right&&(C=u.y+=y,u.line++,M=u.x=he(s,this.left+l,this.right-n[u.line])):v>0&&C+y>this.bottom&&(M=u.x=M+e[u.line].width+l,u.line++,C=u.y=he(s,this.top+b+l,this.bottom-e[u.line].height));if(function(t,e,n){if(isNaN(g)||g<=0||isNaN(p)||p<0)return;i.save();const s=mt(n.lineWidth,1);if(i.fillStyle=mt(n.fillStyle,a),i.lineCap=mt(n.lineCap,"butt"),i.lineDashOffset=mt(n.lineDashOffset,0),i.lineJoin=mt(n.lineJoin,"miter"),i.lineWidth=s,i.strokeStyle=mt(n.strokeStyle,a),i.setLineDash(mt(n.lineDash,[])),o.usePointStyle){const a={radius:p*Math.SQRT2/2,pointStyle:n.pointStyle,rotation:n.rotation,borderWidth:s},c=r.xPlus(t,g/2);Re(i,a,c,e+h,o.pointStyleWidth&&g)}else{const o=e+Math.max((d-p)/2,0),a=r.leftForLtr(t,g),c=Je(n.borderRadius);i.beginPath(),Object.values(c).some((t=>0!==t))?Ue(i,{x:a,y:o,w:g,h:p,radius:c}):i.rect(a,o,g,p),i.fill(),0!==s&&i.stroke()}i.restore()}(r.x(M),C,x),M=((t,e,n,i)=>t===(i?"left":"right")?n:"center"===t?(e+n)/2:e)(S,M+g+h,f?M+k:this.right,t.rtl),function(t,e,n){Ye(i,n.text,t,e+m/2,c,{strikethrough:n.hidden,textAlign:r.textAlign(n.textAlign)})}(r.x(M),C,x),f)u.x+=k+l;else if("string"!=typeof x.text){const t=c.lineHeight;u.y+=na(x,t)+l}else u.y+=y})),Hn(this.ctx,t.textDirection)}drawTitle(){const t=this.options,e=t.title,n=en(e.font),i=tn(e.padding);if(!e.display)return;const s=qn(t.rtl,this.left,this.width),o=this.ctx,a=e.position,r=n.size/2,c=i.top+r;let l,d=this.left,h=this.width;if(this.isHorizontal())h=Math.max(...this.lineWidths),l=this.top+c,d=he(t.align,d,this.right-h);else{const e=this.columnSizes.reduce(((t,e)=>Math.max(t,e.height)),0);l=c+he(t.align,this.top,this.bottom-e-t.labels.padding-this._computeTitleHeight())}const u=he(a,d,d+h);o.textAlign=s.textAlign(de(a)),o.textBaseline="middle",o.strokeStyle=e.color,o.fillStyle=e.color,o.font=n.string,Ye(o,e.text,u,l,n)}_computeTitleHeight(){const t=this.options.title,e=en(t.font),n=tn(t.padding);return t.display?e.lineHeight+n.height:0}_getLegendItemAt(t,e){let n,i,s;if(ee(t,this.left,this.right)&&ee(e,this.top,this.bottom))for(s=this.legendHitBoxes,n=0;n<s.length;++n)if(i=s[n],ee(t,i.left,i.left+i.width)&&ee(e,i.top,i.top+i.height))return this.legendItems[n];return null}handleEvent(t){const e=this.options;if(!function(t,e){if(("mousemove"===t||"mouseout"===t)&&(e.onHover||e.onLeave))return!0;if(e.onClick&&("click"===t||"mouseup"===t))return!0;return!1}(t.type,e))return;const n=this._getLegendItemAt(t.x,t.y);if("mousemove"===t.type||"mouseout"===t.type){const o=this._hoveredItem,a=(s=n,null!==(i=o)&&null!==s&&i.datasetIndex===s.datasetIndex&&i.index===s.index);o&&!a&&bt(e.onLeave,[t,o,this],this),this._hoveredItem=n,n&&!a&&bt(e.onHover,[t,n,this],this)}else n&&bt(e.onClick,[t,n,this],this);var i,s}}function na(t,e){return e*(t.text?t.text.length:0)}var ia={id:"legend",_element:ea,start(t,e,n){const i=t.legend=new ea({ctx:t.ctx,options:n,chart:t});Gi.configure(t,i,n),Gi.addBox(t,i)},stop(t){Gi.removeBox(t,t.legend),delete t.legend},beforeUpdate(t,e,n){const i=t.legend;Gi.configure(t,i,n),i.options=n},afterUpdate(t){const e=t.legend;e.buildLabels(),e.adjustHitBoxes()},afterEvent(t,e){e.replay||t.legend.handleEvent(e.event)},defaults:{display:!0,position:"top",align:"center",fullSize:!0,reverse:!1,weight:1e3,onClick(t,e,n){const i=e.datasetIndex,s=n.chart;s.isDatasetVisible(i)?(s.hide(i),e.hidden=!0):(s.show(i),e.hidden=!1)},onHover:null,onLeave:null,labels:{color:t=>t.chart.options.color,boxWidth:40,padding:10,generateLabels(t){const e=t.data.datasets,{labels:{usePointStyle:n,pointStyle:i,textAlign:s,color:o,useBorderRadius:a,borderRadius:r}}=t.legend.options;return t._getSortedDatasetMetas().map((t=>{const c=t.controller.getStyle(n?0:void 0),l=tn(c.borderWidth);return{text:e[t.index].label,fillStyle:c.backgroundColor,fontColor:o,hidden:!t.visible,lineCap:c.borderCapStyle,lineDash:c.borderDash,lineDashOffset:c.borderDashOffset,lineJoin:c.borderJoinStyle,lineWidth:(l.width+l.height)/4,strokeStyle:c.borderColor,pointStyle:i||c.pointStyle,rotation:c.rotation,textAlign:s||c.textAlign,borderRadius:a&&(r||c.borderRadius),datasetIndex:t.index}}),this)}},title:{color:t=>t.chart.options.color,display:!1,position:"center",text:""}},descriptors:{_scriptable:t=>!t.startsWith("on"),labels:{_scriptable:t=>!["generateLabels","filter","sort"].includes(t)}}};class sa extends ms{constructor(t){super(),this.chart=t.chart,this.options=t.options,this.ctx=t.ctx,this._padding=void 0,this.top=void 0,this.bottom=void 0,this.left=void 0,this.right=void 0,this.width=void 0,this.height=void 0,this.position=void 0,this.weight=void 0,this.fullSize=void 0}update(t,e){const n=this.options;if(this.left=0,this.top=0,!n.display)return void(this.width=this.height=this.right=this.bottom=0);this.width=this.right=t,this.height=this.bottom=e;const i=ht(n.text)?n.text.length:1;this._padding=tn(n.padding);const s=i*en(n.font).lineHeight+this._padding.height;this.isHorizontal()?this.height=s:this.width=s}isHorizontal(){const t=this.options.position;return"top"===t||"bottom"===t}_drawArgs(t){const{top:e,left:n,bottom:i,right:s,options:o}=this,a=o.align;let r,c,l,d=0;return this.isHorizontal()?(c=he(a,n,s),l=e+t,r=s-n):("left"===o.position?(c=n+t,l=he(a,i,e),d=-.5*Lt):(c=s-t,l=he(a,e,i),d=.5*Lt),r=i-e),{titleX:c,titleY:l,maxWidth:r,rotation:d}}draw(){const t=this.ctx,e=this.options;if(!e.display)return;const n=en(e.font),i=n.lineHeight/2+this._padding.top,{titleX:s,titleY:o,maxWidth:a,rotation:r}=this._drawArgs(i);Ye(t,e.text,0,0,n,{color:e.color,maxWidth:a,rotation:r,textAlign:de(e.align),textBaseline:"middle",translation:[s,o]})}}var oa={id:"title",_element:sa,start(t,e,n){!function(t,e){const n=new sa({ctx:t.ctx,options:e,chart:t});Gi.configure(t,n,e),Gi.addBox(t,n),t.titleBlock=n}(t,n)},stop(t){const e=t.titleBlock;Gi.removeBox(t,e),delete t.titleBlock},beforeUpdate(t,e,n){const i=t.titleBlock;Gi.configure(t,i,n),i.options=n},defaults:{align:"center",display:!1,font:{weight:"bold"},fullSize:!0,padding:10,position:"top",text:"",weight:2e3},defaultRoutes:{color:"color"},descriptors:{_scriptable:!0,_indexable:!1}};const aa=new WeakMap;var ra={id:"subtitle",start(t,e,n){const i=new sa({ctx:t.ctx,options:n,chart:t});Gi.configure(t,i,n),Gi.addBox(t,i),aa.set(t,i)},stop(t){Gi.removeBox(t,aa.get(t)),aa.delete(t)},beforeUpdate(t,e,n){const i=aa.get(t);Gi.configure(t,i,n),i.options=n},defaults:{align:"center",display:!1,font:{weight:"normal"},fullSize:!0,padding:0,position:"top",text:"",weight:1500},defaultRoutes:{color:"color"},descriptors:{_scriptable:!0,_indexable:!1}};const ca={average(t){if(!t.length)return!1;let e,n,i=new Set,s=0,o=0;for(e=0,n=t.length;e<n;++e){const n=t[e].element;if(n&&n.hasValue()){const t=n.tooltipPosition();i.add(t.x),s+=t.y,++o}}if(0===o||0===i.size)return!1;return{x:[...i].reduce(((t,e)=>t+e))/i.size,y:s/o}},nearest(t,e){if(!t.length)return!1;let n,i,s,o=e.x,a=e.y,r=Number.POSITIVE_INFINITY;for(n=0,i=t.length;n<i;++n){const i=t[n].element;if(i&&i.hasValue()){const t=Kt(e,i.getCenterPoint());t<r&&(r=t,s=i)}}if(s){const t=s.tooltipPosition();o=t.x,a=t.y}return{x:o,y:a}}};function la(t,e){return e&&(ht(e)?Array.prototype.push.apply(t,e):t.push(e)),t}function da(t){return("string"==typeof t||t instanceof String)&&t.indexOf("\n")>-1?t.split("\n"):t}function ha(t,e){const{element:n,datasetIndex:i,index:s}=e,o=t.getDatasetMeta(i).controller,{label:a,value:r}=o.getLabelAndValue(s);return{chart:t,label:a,parsed:o.getParsed(s),raw:t.data.datasets[i].data[s],formattedValue:r,dataset:o.getDataset(),dataIndex:s,datasetIndex:i,element:n}}function ua(t,e){const n=t.chart.ctx,{body:i,footer:s,title:o}=t,{boxWidth:a,boxHeight:r}=e,c=en(e.bodyFont),l=en(e.titleFont),d=en(e.footerFont),h=o.length,u=s.length,g=i.length,p=tn(e.padding);let m=p.height,f=0,b=i.reduce(((t,e)=>t+e.before.length+e.lines.length+e.after.length),0);if(b+=t.beforeBody.length+t.afterBody.length,h&&(m+=h*l.lineHeight+(h-1)*e.titleSpacing+e.titleMarginBottom),b){m+=g*(e.displayColors?Math.max(r,c.lineHeight):c.lineHeight)+(b-g)*c.lineHeight+(b-1)*e.bodySpacing}u&&(m+=e.footerMarginTop+u*d.lineHeight+(u-1)*e.footerSpacing);let y=0;const x=function(t){f=Math.max(f,n.measureText(t).width+y)};return n.save(),n.font=l.string,yt(t.title,x),n.font=c.string,yt(t.beforeBody.concat(t.afterBody),x),y=e.displayColors?a+2+e.boxPadding:0,yt(i,(t=>{yt(t.before,x),yt(t.lines,x),yt(t.after,x)})),y=0,n.font=d.string,yt(t.footer,x),n.restore(),f+=p.width,{width:f,height:m}}function ga(t,e,n,i){const{x:s,width:o}=n,{width:a,chartArea:{left:r,right:c}}=t;let l="center";return"center"===i?l=s<=(r+c)/2?"left":"right":s<=o/2?l="left":s>=a-o/2&&(l="right"),function(t,e,n,i){const{x:s,width:o}=i,a=n.caretSize+n.caretPadding;return"left"===t&&s+o+a>e.width||"right"===t&&s-o-a<0||void 0}(l,t,e,n)&&(l="center"),l}function pa(t,e,n){const i=n.yAlign||e.yAlign||function(t,e){const{y:n,height:i}=e;return n<i/2?"top":n>t.height-i/2?"bottom":"center"}(t,n);return{xAlign:n.xAlign||e.xAlign||ga(t,e,n,i),yAlign:i}}function ma(t,e,n,i){const{caretSize:s,caretPadding:o,cornerRadius:a}=t,{xAlign:r,yAlign:c}=n,l=s+o,{topLeft:d,topRight:h,bottomLeft:u,bottomRight:g}=Je(a);let p=function(t,e){let{x:n,width:i}=t;return"right"===e?n-=i:"center"===e&&(n-=i/2),n}(e,r);const m=function(t,e,n){let{y:i,height:s}=t;return"top"===e?i+=n:i-="bottom"===e?s+n:s/2,i}(e,c,l);return"center"===c?"left"===r?p+=l:"right"===r&&(p-=l):"left"===r?p-=Math.max(d,u)+s:"right"===r&&(p+=Math.max(h,g)+s),{x:te(p,0,i.width-e.width),y:te(m,0,i.height-e.height)}}function fa(t,e,n){const i=tn(n.padding);return"center"===e?t.x+t.width/2:"right"===e?t.x+t.width-i.right:t.x+i.left}function ba(t){return la([],da(t))}function ya(t,e){const n=e&&e.dataset&&e.dataset.tooltip&&e.dataset.tooltip.callbacks;return n?t.override(n):t}const xa={beforeTitle:ct,title(t){if(t.length>0){const e=t[0],n=e.chart.data.labels,i=n?n.length:0;if(this&&this.options&&"dataset"===this.options.mode)return e.dataset.label||"";if(e.label)return e.label;if(i>0&&e.dataIndex<i)return n[e.dataIndex]}return""},afterTitle:ct,beforeBody:ct,beforeLabel:ct,label(t){if(this&&this.options&&"dataset"===this.options.mode)return t.label+": "+t.formattedValue||t.formattedValue;let e=t.dataset.label||"";e&&(e+=": ");const n=t.formattedValue;return dt(n)||(e+=n),e},labelColor(t){const e=t.chart.getDatasetMeta(t.datasetIndex).controller.getStyle(t.dataIndex);return{borderColor:e.borderColor,backgroundColor:e.backgroundColor,borderWidth:e.borderWidth,borderDash:e.borderDash,borderDashOffset:e.borderDashOffset,borderRadius:0}},labelTextColor(){return this.options.bodyColor},labelPointStyle(t){const e=t.chart.getDatasetMeta(t.datasetIndex).controller.getStyle(t.dataIndex);return{pointStyle:e.pointStyle,rotation:e.rotation}},afterLabel:ct,afterBody:ct,beforeFooter:ct,footer:ct,afterFooter:ct};function va(t,e,n,i){const s=t[e].call(n,i);return void 0===s?xa[e].call(n,i):s}class wa extends ms{static positioners=ca;constructor(t){super(),this.opacity=0,this._active=[],this._eventPosition=void 0,this._size=void 0,this._cachedAnimations=void 0,this._tooltipItems=[],this.$animations=void 0,this.$context=void 0,this.chart=t.chart,this.options=t.options,this.dataPoints=void 0,this.title=void 0,this.beforeBody=void 0,this.body=void 0,this.afterBody=void 0,this.footer=void 0,this.xAlign=void 0,this.yAlign=void 0,this.x=void 0,this.y=void 0,this.height=void 0,this.width=void 0,this.caretX=void 0,this.caretY=void 0,this.labelColors=void 0,this.labelPointStyles=void 0,this.labelTextColors=void 0}initialize(t){this.options=t,this._cachedAnimations=void 0,this.$context=void 0}_resolveAnimations(){const t=this._cachedAnimations;if(t)return t;const e=this.chart,n=this.options.setContext(this.getContext()),i=n.enabled&&e.options.animation&&n.animations,s=new si(this.chart,i);return i._cacheable&&(this._cachedAnimations=Object.freeze(s)),s}getContext(){return this.$context||(this.$context=(t=this.chart.getContext(),e=this,n=this._tooltipItems,sn(t,{tooltip:e,tooltipItems:n,type:"tooltip"})));var t,e,n}getTitle(t,e){const{callbacks:n}=e,i=va(n,"beforeTitle",this,t),s=va(n,"title",this,t),o=va(n,"afterTitle",this,t);let a=[];return a=la(a,da(i)),a=la(a,da(s)),a=la(a,da(o)),a}getBeforeBody(t,e){return ba(va(e.callbacks,"beforeBody",this,t))}getBody(t,e){const{callbacks:n}=e,i=[];return yt(t,(t=>{const e={before:[],lines:[],after:[]},s=ya(n,t);la(e.before,da(va(s,"beforeLabel",this,t))),la(e.lines,va(s,"label",this,t)),la(e.after,da(va(s,"afterLabel",this,t))),i.push(e)})),i}getAfterBody(t,e){return ba(va(e.callbacks,"afterBody",this,t))}getFooter(t,e){const{callbacks:n}=e,i=va(n,"beforeFooter",this,t),s=va(n,"footer",this,t),o=va(n,"afterFooter",this,t);let a=[];return a=la(a,da(i)),a=la(a,da(s)),a=la(a,da(o)),a}_createItems(t){const e=this._active,n=this.chart.data,i=[],s=[],o=[];let a,r,c=[];for(a=0,r=e.length;a<r;++a)c.push(ha(this.chart,e[a]));return t.filter&&(c=c.filter(((e,i,s)=>t.filter(e,i,s,n)))),t.itemSort&&(c=c.sort(((e,i)=>t.itemSort(e,i,n)))),yt(c,(e=>{const n=ya(t.callbacks,e);i.push(va(n,"labelColor",this,e)),s.push(va(n,"labelPointStyle",this,e)),o.push(va(n,"labelTextColor",this,e))})),this.labelColors=i,this.labelPointStyles=s,this.labelTextColors=o,this.dataPoints=c,c}update(t,e){const n=this.options.setContext(this.getContext()),i=this._active;let s,o=[];if(i.length){const t=ca[n.position].call(this,i,this._eventPosition);o=this._createItems(n),this.title=this.getTitle(o,n),this.beforeBody=this.getBeforeBody(o,n),this.body=this.getBody(o,n),this.afterBody=this.getAfterBody(o,n),this.footer=this.getFooter(o,n);const e=this._size=ua(this,n),a=Object.assign({},t,e),r=pa(this.chart,n,a),c=ma(n,a,r,this.chart);this.xAlign=r.xAlign,this.yAlign=r.yAlign,s={opacity:1,x:c.x,y:c.y,width:e.width,height:e.height,caretX:t.x,caretY:t.y}}else 0!==this.opacity&&(s={opacity:0});this._tooltipItems=o,this.$context=void 0,s&&this._resolveAnimations().update(this,s),t&&n.external&&n.external.call(this,{chart:this.chart,tooltip:this,replay:e})}drawCaret(t,e,n,i){const s=this.getCaretPosition(t,n,i);e.lineTo(s.x1,s.y1),e.lineTo(s.x2,s.y2),e.lineTo(s.x3,s.y3)}getCaretPosition(t,e,n){const{xAlign:i,yAlign:s}=this,{caretSize:o,cornerRadius:a}=n,{topLeft:r,topRight:c,bottomLeft:l,bottomRight:d}=Je(a),{x:h,y:u}=t,{width:g,height:p}=e;let m,f,b,y,x,v;return"center"===s?(x=u+p/2,"left"===i?(m=h,f=m-o,y=x+o,v=x-o):(m=h+g,f=m+o,y=x-o,v=x+o),b=m):(f="left"===i?h+Math.max(r,l)+o:"right"===i?h+g-Math.max(c,d)-o:this.caretX,"top"===s?(y=u,x=y-o,m=f-o,b=f+o):(y=u+p,x=y+o,m=f+o,b=f-o),v=y),{x1:m,x2:f,x3:b,y1:y,y2:x,y3:v}}drawTitle(t,e,n){const i=this.title,s=i.length;let o,a,r;if(s){const c=qn(n.rtl,this.x,this.width);for(t.x=fa(this,n.titleAlign,n),e.textAlign=c.textAlign(n.titleAlign),e.textBaseline="middle",o=en(n.titleFont),a=n.titleSpacing,e.fillStyle=n.titleColor,e.font=o.string,r=0;r<s;++r)e.fillText(i[r],c.x(t.x),t.y+o.lineHeight/2),t.y+=o.lineHeight+a,r+1===s&&(t.y+=n.titleMarginBottom-a)}}_drawColorBox(t,e,n,i,s){const o=this.labelColors[n],a=this.labelPointStyles[n],{boxHeight:r,boxWidth:c}=s,l=en(s.bodyFont),d=fa(this,"left",s),h=i.x(d),u=r<l.lineHeight?(l.lineHeight-r)/2:0,g=e.y+u;if(s.usePointStyle){const e={radius:Math.min(c,r)/2,pointStyle:a.pointStyle,rotation:a.rotation,borderWidth:1},n=i.leftForLtr(h,c)+c/2,l=g+r/2;t.strokeStyle=s.multiKeyBackground,t.fillStyle=s.multiKeyBackground,Ne(t,e,n,l),t.strokeStyle=o.borderColor,t.fillStyle=o.backgroundColor,Ne(t,e,n,l)}else{t.lineWidth=ut(o.borderWidth)?Math.max(...Object.values(o.borderWidth)):o.borderWidth||1,t.strokeStyle=o.borderColor,t.setLineDash(o.borderDash||[]),t.lineDashOffset=o.borderDashOffset||0;const e=i.leftForLtr(h,c),n=i.leftForLtr(i.xPlus(h,1),c-2),a=Je(o.borderRadius);Object.values(a).some((t=>0!==t))?(t.beginPath(),t.fillStyle=s.multiKeyBackground,Ue(t,{x:e,y:g,w:c,h:r,radius:a}),t.fill(),t.stroke(),t.fillStyle=o.backgroundColor,t.beginPath(),Ue(t,{x:n,y:g+1,w:c-2,h:r-2,radius:a}),t.fill()):(t.fillStyle=s.multiKeyBackground,t.fillRect(e,g,c,r),t.strokeRect(e,g,c,r),t.fillStyle=o.backgroundColor,t.fillRect(n,g+1,c-2,r-2))}t.fillStyle=this.labelTextColors[n]}drawBody(t,e,n){const{body:i}=this,{bodySpacing:s,bodyAlign:o,displayColors:a,boxHeight:r,boxWidth:c,boxPadding:l}=n,d=en(n.bodyFont);let h=d.lineHeight,u=0;const g=qn(n.rtl,this.x,this.width),p=function(n){e.fillText(n,g.x(t.x+u),t.y+h/2),t.y+=h+s},m=g.textAlign(o);let f,b,y,x,v,w,S;for(e.textAlign=o,e.textBaseline="middle",e.font=d.string,t.x=fa(this,m,n),e.fillStyle=n.bodyColor,yt(this.beforeBody,p),u=a&&"right"!==m?"center"===o?c/2+l:c+2+l:0,x=0,w=i.length;x<w;++x){for(f=i[x],b=this.labelTextColors[x],e.fillStyle=b,yt(f.before,p),y=f.lines,a&&y.length&&(this._drawColorBox(e,t,x,g,n),h=Math.max(d.lineHeight,r)),v=0,S=y.length;v<S;++v)p(y[v]),h=d.lineHeight;yt(f.after,p)}u=0,h=d.lineHeight,yt(this.afterBody,p),t.y-=s}drawFooter(t,e,n){const i=this.footer,s=i.length;let o,a;if(s){const r=qn(n.rtl,this.x,this.width);for(t.x=fa(this,n.footerAlign,n),t.y+=n.footerMarginTop,e.textAlign=r.textAlign(n.footerAlign),e.textBaseline="middle",o=en(n.footerFont),e.fillStyle=n.footerColor,e.font=o.string,a=0;a<s;++a)e.fillText(i[a],r.x(t.x),t.y+o.lineHeight/2),t.y+=o.lineHeight+n.footerSpacing}}drawBackground(t,e,n,i){const{xAlign:s,yAlign:o}=this,{x:a,y:r}=t,{width:c,height:l}=n,{topLeft:d,topRight:h,bottomLeft:u,bottomRight:g}=Je(i.cornerRadius);e.fillStyle=i.backgroundColor,e.strokeStyle=i.borderColor,e.lineWidth=i.borderWidth,e.beginPath(),e.moveTo(a+d,r),"top"===o&&this.drawCaret(t,e,n,i),e.lineTo(a+c-h,r),e.quadraticCurveTo(a+c,r,a+c,r+h),"center"===o&&"right"===s&&this.drawCaret(t,e,n,i),e.lineTo(a+c,r+l-g),e.quadraticCurveTo(a+c,r+l,a+c-g,r+l),"bottom"===o&&this.drawCaret(t,e,n,i),e.lineTo(a+u,r+l),e.quadraticCurveTo(a,r+l,a,r+l-u),"center"===o&&"left"===s&&this.drawCaret(t,e,n,i),e.lineTo(a,r+d),e.quadraticCurveTo(a,r,a+d,r),e.closePath(),e.fill(),i.borderWidth>0&&e.stroke()}_updateAnimationTarget(t){const e=this.chart,n=this.$animations,i=n&&n.x,s=n&&n.y;if(i||s){const n=ca[t.position].call(this,this._active,this._eventPosition);if(!n)return;const o=this._size=ua(this,t),a=Object.assign({},n,this._size),r=pa(e,t,a),c=ma(t,a,r,e);i._to===c.x&&s._to===c.y||(this.xAlign=r.xAlign,this.yAlign=r.yAlign,this.width=o.width,this.height=o.height,this.caretX=n.x,this.caretY=n.y,this._resolveAnimations().update(this,c))}}_willRender(){return!!this.opacity}draw(t){const e=this.options.setContext(this.getContext());let n=this.opacity;if(!n)return;this._updateAnimationTarget(e);const i={width:this.width,height:this.height},s={x:this.x,y:this.y};n=Math.abs(n)<.001?0:n;const o=tn(e.padding),a=this.title.length||this.beforeBody.length||this.body.length||this.afterBody.length||this.footer.length;e.enabled&&a&&(t.save(),t.globalAlpha=n,this.drawBackground(s,t,i,e),Bn(t,e.textDirection),s.y+=o.top,this.drawTitle(s,t,e),this.drawBody(s,t,e),this.drawFooter(s,t,e),Hn(t,e.textDirection),t.restore())}getActiveElements(){return this._active||[]}setActiveElements(t,e){const n=this._active,i=t.map((({datasetIndex:t,index:e})=>{const n=this.chart.getDatasetMeta(t);if(!n)throw new Error("Cannot find a dataset at index "+t);return{datasetIndex:t,element:n.data[e],index:e}})),s=!xt(n,i),o=this._positionChanged(i,e);(s||o)&&(this._active=i,this._eventPosition=e,this._ignoreReplayEvents=!0,this.update(!0))}handleEvent(t,e,n=!0){if(e&&this._ignoreReplayEvents)return!1;this._ignoreReplayEvents=!1;const i=this.options,s=this._active||[],o=this._getActiveElements(t,s,e,n),a=this._positionChanged(o,t),r=e||!xt(o,s)||a;return r&&(this._active=o,(i.enabled||i.external)&&(this._eventPosition={x:t.x,y:t.y},this.update(!0,e))),r}_getActiveElements(t,e,n,i){const s=this.options;if("mouseout"===t.type)return[];if(!i)return e.filter((t=>this.chart.data.datasets[t.datasetIndex]&&void 0!==this.chart.getDatasetMeta(t.datasetIndex).controller.getParsed(t.index)));const o=this.chart.getElementsAtEventForMode(t,s.mode,s,n);return s.reverse&&o.reverse(),o}_positionChanged(t,e){const{caretX:n,caretY:i,options:s}=this,o=ca[s.position].call(this,t,e);return!1!==o&&(n!==o.x||i!==o.y)}}var Sa={id:"tooltip",_element:wa,positioners:ca,afterInit(t,e,n){n&&(t.tooltip=new wa({chart:t,options:n}))},beforeUpdate(t,e,n){t.tooltip&&t.tooltip.initialize(n)},reset(t,e,n){t.tooltip&&t.tooltip.initialize(n)},afterDraw(t){const e=t.tooltip;if(e&&e._willRender()){const n={tooltip:e};if(!1===t.notifyPlugins("beforeTooltipDraw",{...n,cancelable:!0}))return;e.draw(t.ctx),t.notifyPlugins("afterTooltipDraw",n)}},afterEvent(t,e){if(t.tooltip){const n=e.replay;t.tooltip.handleEvent(e.event,n,e.inChartArea)&&(e.changed=!0)}},defaults:{enabled:!0,external:null,position:"average",backgroundColor:"rgba(0,0,0,0.8)",titleColor:"#fff",titleFont:{weight:"bold"},titleSpacing:2,titleMarginBottom:6,titleAlign:"left",bodyColor:"#fff",bodySpacing:2,bodyFont:{},bodyAlign:"left",footerColor:"#fff",footerSpacing:2,footerMarginTop:6,footerFont:{weight:"bold"},footerAlign:"left",padding:6,caretPadding:2,caretSize:5,cornerRadius:6,boxHeight:(t,e)=>e.bodyFont.size,boxWidth:(t,e)=>e.bodyFont.size,multiKeyBackground:"#fff",displayColors:!0,boxPadding:0,borderColor:"rgba(0,0,0,0)",borderWidth:0,animation:{duration:400,easing:"easeOutQuart"},animations:{numbers:{type:"number",properties:["x","y","width","height","caretX","caretY"]},opacity:{easing:"linear",duration:200}},callbacks:xa},defaultRoutes:{bodyFont:"font",footerFont:"font",titleFont:"font"},descriptors:{_scriptable:t=>"filter"!==t&&"itemSort"!==t&&"external"!==t,_indexable:!1,callbacks:{_scriptable:!1,_indexable:!1},animation:{_fallback:!1},animations:{_fallback:"animation"}},additionalOptionScopes:["interaction"]},ka=Object.freeze({__proto__:null,Colors:Lo,Decimation:zo,Filler:Jo,Legend:ia,SubTitle:ra,Title:oa,Tooltip:Sa});function Ma(t,e,n,i){const s=t.indexOf(e);if(-1===s)return((t,e,n,i)=>("string"==typeof e?(n=t.push(e)-1,i.unshift({index:n,label:e})):isNaN(e)&&(n=null),n))(t,e,n,i);return s!==t.lastIndexOf(e)?n:s}function Ca(t){const e=this.getLabels();return t>=0&&t<e.length?e[t]:t}function _a(t,e){const n=[],{bounds:i,step:s,min:o,max:a,precision:r,count:c,maxTicks:l,maxDigits:d,includeBounds:h}=t,u=s||1,g=l-1,{min:p,max:m}=e,f=!dt(o),b=!dt(a),y=!dt(c),x=(m-p)/(d+1);let v,w,S,k,M=Ht((m-p)/g/u)*u;if(M<1e-14&&!f&&!b)return[{value:p},{value:m}];k=Math.ceil(m/M)-Math.floor(p/M),k>g&&(M=Ht(k*M/g/u)*u),dt(r)||(v=Math.pow(10,r),M=Math.ceil(M*v)/v),"ticks"===i?(w=Math.floor(p/M)*M,S=Math.ceil(m/M)*M):(w=p,S=m),f&&b&&s&&function(t,e){const n=Math.round(t);return n-e<=t&&n+e>=t}((a-o)/s,M/1e3)?(k=Math.round(Math.min((a-o)/M,l)),M=(a-o)/k,w=o,S=a):y?(w=f?o:w,S=b?a:S,k=c-1,M=(S-w)/k):(k=(S-w)/M,k=Bt(k,Math.round(k),M/1e3)?Math.round(k):Math.ceil(k));const C=Math.max(Xt(M),Xt(w));v=Math.pow(10,dt(r)?C:r),w=Math.round(w*v)/v,S=Math.round(S*v)/v;let _=0;for(f&&(h&&w!==o?(n.push({value:o}),w<o&&_++,Bt(Math.round((w+_*M)*v)/v,o,Da(o,x,t))&&_++):w<o&&_++);_<k;++_){const t=Math.round((w+_*M)*v)/v;if(b&&t>a)break;n.push({value:t})}return b&&h&&S!==a?n.length&&Bt(n[n.length-1].value,a,Da(a,x,t))?n[n.length-1].value=a:n.push({value:a}):b&&S!==a||n.push({value:S}),n}function Da(t,e,{horizontal:n,minRotation:i}){const s=Yt(i),o=(n?Math.sin(s):Math.cos(s))||.001,a=.75*e*(""+t).length;return Math.min(e/o,a)}class Ta extends Cs{constructor(t){super(t),this.start=void 0,this.end=void 0,this._startValue=void 0,this._endValue=void 0,this._valueRange=0}parse(t,e){return dt(t)||("number"==typeof t||t instanceof Number)&&!isFinite(+t)?null:+t}handleTickRangeOptions(){const{beginAtZero:t}=this.options,{minDefined:e,maxDefined:n}=this.getUserBounds();let{min:i,max:s}=this;const o=t=>i=e?i:t,a=t=>s=n?s:t;if(t){const t=qt(i),e=qt(s);t<0&&e<0?a(0):t>0&&e>0&&o(0)}if(i===s){let e=0===s?1:Math.abs(.05*s);a(s+e),t||o(i-e)}this.min=i,this.max=s}getTickLimit(){const t=this.options.ticks;let e,{maxTicksLimit:n,stepSize:i}=t;return i?(e=Math.ceil(this.max/i)-Math.floor(this.min/i)+1,e>1e3&&(console.warn(`scales.${this.id}.ticks.stepSize: ${i} would result generating up to ${e} ticks. Limiting to 1000.`),e=1e3)):(e=this.computeTickLimit(),n=n||11),n&&(e=Math.min(n,e)),e}computeTickLimit(){return Number.POSITIVE_INFINITY}buildTicks(){const t=this.options,e=t.ticks;let n=this.getTickLimit();n=Math.max(2,n);const i=_a({maxTicks:n,bounds:t.bounds,min:t.min,max:t.max,precision:e.precision,step:e.stepSize,count:e.count,maxDigits:this._maxDigits(),horizontal:this.isHorizontal(),minRotation:e.minRotation||0,includeBounds:!1!==e.includeBounds},this._range||this);return"ticks"===t.bounds&&jt(i,this,"value"),t.reverse?(i.reverse(),this.start=this.max,this.end=this.min):(this.start=this.min,this.end=this.max),i}configure(){const t=this.ticks;let e=this.min,n=this.max;if(super.configure(),this.options.offset&&t.length){const i=(n-e)/Math.max(t.length-1,1)/2;e-=i,n+=i}this._startValue=e,this._endValue=n,this._valueRange=n-e}getLabelForValue(t){return Me(t,this.chart.options.locale,this.options.ticks.format)}}class Pa extends Ta{static id="linear";static defaults={ticks:{callback:_e.formatters.numeric}};determineDataLimits(){const{min:t,max:e}=this.getMinMax(!0);this.min=gt(t)?t:0,this.max=gt(e)?e:1,this.handleTickRangeOptions()}computeTickLimit(){const t=this.isHorizontal(),e=t?this.width:this.height,n=Yt(this.options.ticks.minRotation),i=(t?Math.sin(n):Math.cos(n))||.001,s=this._resolveTickFontOptions(0);return Math.ceil(e/Math.min(40,s.lineHeight/i))}getPixelForValue(t){return null===t?NaN:this.getPixelForDecimal((t-this._startValue)/this._valueRange)}getValueForPixel(t){return this._startValue+this.getDecimalForPixel(t)*this._valueRange}}const Ea=t=>Math.floor(Ft(t)),Aa=(t,e)=>Math.pow(10,Ea(t)+e);function La(t){return 1===t/Math.pow(10,Ea(t))}function Ia(t,e,n){const i=Math.pow(10,n),s=Math.floor(t/i);return Math.ceil(e/i)-s}function Oa(t,{min:e,max:n}){e=pt(t.min,e);const i=[],s=Ea(e);let o=function(t,e){let n=Ea(e-t);for(;Ia(t,e,n)>10;)n++;for(;Ia(t,e,n)<10;)n--;return Math.min(n,Ea(t))}(e,n),a=o<0?Math.pow(10,Math.abs(o)):1;const r=Math.pow(10,o),c=s>o?Math.pow(10,s):0,l=Math.round((e-c)*a)/a,d=Math.floor((e-c)/r/10)*r*10;let h=Math.floor((l-d)/Math.pow(10,o)),u=pt(t.min,Math.round((c+d+h*Math.pow(10,o))*a)/a);for(;u<n;)i.push({value:u,major:La(u),significand:h}),h>=10?h=h<15?15:20:h++,h>=20&&(o++,h=2,a=o>=0?1:a),u=Math.round((c+d+h*Math.pow(10,o))*a)/a;const g=pt(t.max,u);return i.push({value:g,major:La(g),significand:h}),i}class za extends Cs{static id="logarithmic";static defaults={ticks:{callback:_e.formatters.logarithmic,major:{enabled:!0}}};constructor(t){super(t),this.start=void 0,this.end=void 0,this._startValue=void 0,this._valueRange=0}parse(t,e){const n=Ta.prototype.parse.apply(this,[t,e]);if(0!==n)return gt(n)&&n>0?n:null;this._zero=!0}determineDataLimits(){const{min:t,max:e}=this.getMinMax(!0);this.min=gt(t)?Math.max(0,t):null,this.max=gt(e)?Math.max(0,e):null,this.options.beginAtZero&&(this._zero=!0),this._zero&&this.min!==this._suggestedMin&&!gt(this._userMin)&&(this.min=t===Aa(this.min,0)?Aa(this.min,-1):Aa(this.min,0)),this.handleTickRangeOptions()}handleTickRangeOptions(){const{minDefined:t,maxDefined:e}=this.getUserBounds();let n=this.min,i=this.max;const s=e=>n=t?n:e,o=t=>i=e?i:t;n===i&&(n<=0?(s(1),o(10)):(s(Aa(n,-1)),o(Aa(i,1)))),n<=0&&s(Aa(i,-1)),i<=0&&o(Aa(n,1)),this.min=n,this.max=i}buildTicks(){const t=this.options,e=Oa({min:this._userMin,max:this._userMax},this);return"ticks"===t.bounds&&jt(e,this,"value"),t.reverse?(e.reverse(),this.start=this.max,this.end=this.min):(this.start=this.min,this.end=this.max),e}getLabelForValue(t){return void 0===t?"0":Me(t,this.chart.options.locale,this.options.ticks.format)}configure(){const t=this.min;super.configure(),this._startValue=Ft(t),this._valueRange=Ft(this.max)-Ft(t)}getPixelForValue(t){return void 0!==t&&0!==t||(t=this.min),null===t||isNaN(t)?NaN:this.getPixelForDecimal(t===this.min?0:(Ft(t)-this._startValue)/this._valueRange)}getValueForPixel(t){const e=this.getDecimalForPixel(t);return Math.pow(10,this._startValue+e*this._valueRange)}}function Wa(t){const e=t.ticks;if(e.display&&t.display){const t=tn(e.backdropPadding);return mt(e.font&&e.font.size,Le.font.size)+t.height}return 0}function Na(t,e,n,i,s){return t===i||t===s?{start:e-n/2,end:e+n/2}:t<i||t>s?{start:e-n,end:e}:{start:e,end:e+n}}function Ra(t){const e={l:t.left+t._padding.left,r:t.right-t._padding.right,t:t.top+t._padding.top,b:t.bottom-t._padding.bottom},n=Object.assign({},e),i=[],s=[],o=t._pointLabels.length,a=t.options.pointLabels,r=a.centerPointLabels?Lt/o:0;for(let h=0;h<o;h++){const o=a.setContext(t.getPointLabelContext(h));s[h]=o.padding;const u=t.getPointPosition(h,t.drawingArea+s[h],r),g=en(o.font),p=(c=t.ctx,l=g,d=ht(d=t._pointLabels[h])?d:[d],{w:Oe(c,l.string,d),h:d.length*l.lineHeight});i[h]=p;const m=Zt(t.getIndexAngle(h)+r),f=Math.round(Ut(m));$a(n,e,m,Na(f,u.x,p.w,0,180),Na(f,u.y,p.h,90,270))}var c,l,d;t.setCenterPoint(e.l-n.l,n.r-e.r,e.t-n.t,n.b-e.b),t._pointLabelItems=function(t,e,n){const i=[],s=t._pointLabels.length,o=t.options,{centerPointLabels:a,display:r}=o.pointLabels,c={extra:Wa(o)/2,additionalAngle:a?Lt/s:0};let l;for(let o=0;o<s;o++){c.padding=n[o],c.size=e[o];const s=Fa(t,o,c);i.push(s),"auto"===r&&(s.visible=qa(s,l),s.visible&&(l=s))}return i}(t,i,s)}function $a(t,e,n,i,s){const o=Math.abs(Math.sin(n)),a=Math.abs(Math.cos(n));let r=0,c=0;i.start<e.l?(r=(e.l-i.start)/o,t.l=Math.min(t.l,e.l-r)):i.end>e.r&&(r=(i.end-e.r)/o,t.r=Math.max(t.r,e.r+r)),s.start<e.t?(c=(e.t-s.start)/a,t.t=Math.min(t.t,e.t-c)):s.end>e.b&&(c=(s.end-e.b)/a,t.b=Math.max(t.b,e.b+c))}function Fa(t,e,n){const i=t.drawingArea,{extra:s,additionalAngle:o,padding:a,size:r}=n,c=t.getPointPosition(e,i+s+a,o),l=Math.round(Ut(Zt(c.angle+Nt))),d=function(t,e,n){90===n||270===n?t-=e/2:(n>270||n<90)&&(t-=e);return t}(c.y,r.h,l),h=function(t){if(0===t||180===t)return"center";if(t<180)return"left";return"right"}(l),u=function(t,e,n){"right"===n?t-=e:"center"===n&&(t-=e/2);return t}(c.x,r.w,h);return{visible:!0,x:c.x,y:d,textAlign:h,left:u,top:d,right:u+r.w,bottom:d+r.h}}function qa(t,e){if(!e)return!0;const{left:n,top:i,right:s,bottom:o}=t;return!($e({x:n,y:i},e)||$e({x:n,y:o},e)||$e({x:s,y:i},e)||$e({x:s,y:o},e))}function Ba(t,e,n){const{left:i,top:s,right:o,bottom:a}=n,{backdropColor:r}=e;if(!dt(r)){const n=Je(e.borderRadius),c=tn(e.backdropPadding);t.fillStyle=r;const l=i-c.left,d=s-c.top,h=o-i+c.width,u=a-s+c.height;Object.values(n).some((t=>0!==t))?(t.beginPath(),Ue(t,{x:l,y:d,w:h,h:u,radius:n}),t.fill()):t.fillRect(l,d,h,u)}}function Ha(t,e,n,i){const{ctx:s}=t;if(n)s.arc(t.xCenter,t.yCenter,e,0,It);else{let n=t.getPointPosition(0,e);s.moveTo(n.x,n.y);for(let o=1;o<i;o++)n=t.getPointPosition(o,e),s.lineTo(n.x,n.y)}}class Va extends Ta{static id="radialLinear";static defaults={display:!0,animate:!0,position:"chartArea",angleLines:{display:!0,lineWidth:1,borderDash:[],borderDashOffset:0},grid:{circular:!1},startAngle:0,ticks:{showLabelBackdrop:!0,callback:_e.formatters.numeric},pointLabels:{backdropColor:void 0,backdropPadding:2,display:!0,font:{size:10},callback:t=>t,padding:5,centerPointLabels:!1}};static defaultRoutes={"angleLines.color":"borderColor","pointLabels.color":"color","ticks.color":"color"};static descriptors={angleLines:{_fallback:"grid"}};constructor(t){super(t),this.xCenter=void 0,this.yCenter=void 0,this.drawingArea=void 0,this._pointLabels=[],this._pointLabelItems=[]}setDimensions(){const t=this._padding=tn(Wa(this.options)/2),e=this.width=this.maxWidth-t.width,n=this.height=this.maxHeight-t.height;this.xCenter=Math.floor(this.left+e/2+t.left),this.yCenter=Math.floor(this.top+n/2+t.top),this.drawingArea=Math.floor(Math.min(e,n)/2)}determineDataLimits(){const{min:t,max:e}=this.getMinMax(!1);this.min=gt(t)&&!isNaN(t)?t:0,this.max=gt(e)&&!isNaN(e)?e:0,this.handleTickRangeOptions()}computeTickLimit(){return Math.ceil(this.drawingArea/Wa(this.options))}generateTickLabels(t){Ta.prototype.generateTickLabels.call(this,t),this._pointLabels=this.getLabels().map(((t,e)=>{const n=bt(this.options.pointLabels.callback,[t,e],this);return n||0===n?n:""})).filter(((t,e)=>this.chart.getDataVisibility(e)))}fit(){const t=this.options;t.display&&t.pointLabels.display?Ra(this):this.setCenterPoint(0,0,0,0)}setCenterPoint(t,e,n,i){this.xCenter+=Math.floor((t-e)/2),this.yCenter+=Math.floor((n-i)/2),this.drawingArea-=Math.min(this.drawingArea/2,Math.max(t,e,n,i))}getIndexAngle(t){return Zt(t*(It/(this._pointLabels.length||1))+Yt(this.options.startAngle||0))}getDistanceFromCenterForValue(t){if(dt(t))return NaN;const e=this.drawingArea/(this.max-this.min);return this.options.reverse?(this.max-t)*e:(t-this.min)*e}getValueForDistanceFromCenter(t){if(dt(t))return NaN;const e=t/(this.drawingArea/(this.max-this.min));return this.options.reverse?this.max-e:this.min+e}getPointLabelContext(t){const e=this._pointLabels||[];if(t>=0&&t<e.length){const n=e[t];return function(t,e,n){return sn(t,{label:n,index:e,type:"pointLabel"})}(this.getContext(),t,n)}}getPointPosition(t,e,n=0){const i=this.getIndexAngle(t)-Nt+n;return{x:Math.cos(i)*e+this.xCenter,y:Math.sin(i)*e+this.yCenter,angle:i}}getPointPositionForValue(t,e){return this.getPointPosition(t,this.getDistanceFromCenterForValue(e))}getBasePosition(t){return this.getPointPositionForValue(t||0,this.getBaseValue())}getPointLabelPosition(t){const{left:e,top:n,right:i,bottom:s}=this._pointLabelItems[t];return{left:e,top:n,right:i,bottom:s}}drawBackground(){const{backgroundColor:t,grid:{circular:e}}=this.options;if(t){const n=this.ctx;n.save(),n.beginPath(),Ha(this,this.getDistanceFromCenterForValue(this._endValue),e,this._pointLabels.length),n.closePath(),n.fillStyle=t,n.fill(),n.restore()}}drawGrid(){const t=this.ctx,e=this.options,{angleLines:n,grid:i,border:s}=e,o=this._pointLabels.length;let a,r,c;if(e.pointLabels.display&&function(t,e){const{ctx:n,options:{pointLabels:i}}=t;for(let s=e-1;s>=0;s--){const e=t._pointLabelItems[s];if(!e.visible)continue;const o=i.setContext(t.getPointLabelContext(s));Ba(n,o,e);const a=en(o.font),{x:r,y:c,textAlign:l}=e;Ye(n,t._pointLabels[s],r,c+a.lineHeight/2,a,{color:o.color,textAlign:l,textBaseline:"middle"})}}(this,o),i.display&&this.ticks.forEach(((t,e)=>{if(0!==e||0===e&&this.min<0){r=this.getDistanceFromCenterForValue(t.value);const n=this.getContext(e),a=i.setContext(n),c=s.setContext(n);!function(t,e,n,i,s){const o=t.ctx,a=e.circular,{color:r,lineWidth:c}=e;!a&&!i||!r||!c||n<0||(o.save(),o.strokeStyle=r,o.lineWidth=c,o.setLineDash(s.dash||[]),o.lineDashOffset=s.dashOffset,o.beginPath(),Ha(t,n,a,i),o.closePath(),o.stroke(),o.restore())}(this,a,r,o,c)}})),n.display){for(t.save(),a=o-1;a>=0;a--){const i=n.setContext(this.getPointLabelContext(a)),{color:s,lineWidth:o}=i;o&&s&&(t.lineWidth=o,t.strokeStyle=s,t.setLineDash(i.borderDash),t.lineDashOffset=i.borderDashOffset,r=this.getDistanceFromCenterForValue(e.reverse?this.min:this.max),c=this.getPointPosition(a,r),t.beginPath(),t.moveTo(this.xCenter,this.yCenter),t.lineTo(c.x,c.y),t.stroke())}t.restore()}}drawBorder(){}drawLabels(){const t=this.ctx,e=this.options,n=e.ticks;if(!n.display)return;const i=this.getIndexAngle(0);let s,o;t.save(),t.translate(this.xCenter,this.yCenter),t.rotate(i),t.textAlign="center",t.textBaseline="middle",this.ticks.forEach(((i,a)=>{if(0===a&&this.min>=0&&!e.reverse)return;const r=n.setContext(this.getContext(a)),c=en(r.font);if(s=this.getDistanceFromCenterForValue(this.ticks[a].value),r.showLabelBackdrop){t.font=c.string,o=t.measureText(i.label).width,t.fillStyle=r.backdropColor;const e=tn(r.backdropPadding);t.fillRect(-o/2-e.left,-s-c.size/2-e.top,o+e.width,c.size+e.height)}Ye(t,i.label,0,-s,c,{color:r.color,strokeColor:r.textStrokeColor,strokeWidth:r.textStrokeWidth})})),t.restore()}drawTitle(){}}const ja={millisecond:{common:!0,size:1,steps:1e3},second:{common:!0,size:1e3,steps:60},minute:{common:!0,size:6e4,steps:60},hour:{common:!0,size:36e5,steps:24},day:{common:!0,size:864e5,steps:30},week:{common:!1,size:6048e5,steps:4},month:{common:!0,size:2628e6,steps:12},quarter:{common:!1,size:7884e6,steps:4},year:{common:!0,size:3154e7}},Ya=Object.keys(ja);function Ua(t,e){return t-e}function Xa(t,e){if(dt(e))return null;const n=t._adapter,{parser:i,round:s,isoWeekday:o}=t._parseOpts;let a=e;return"function"==typeof i&&(a=i(a)),gt(a)||(a="string"==typeof i?n.parse(a,i):n.parse(a)),null===a?null:(s&&(a="week"!==s||!Vt(o)&&!0!==o?n.startOf(a,s):n.startOf(a,"isoWeek",o)),+a)}function Qa(t,e,n,i){const s=Ya.length;for(let o=Ya.indexOf(t);o<s-1;++o){const t=ja[Ya[o]],s=t.steps?t.steps:Number.MAX_SAFE_INTEGER;if(t.common&&Math.ceil((n-e)/(s*t.size))<=i)return Ya[o]}return Ya[s-1]}function Ka(t,e,n){if(n){if(n.length){const{lo:i,hi:s}=ne(n,e);t[n[i]>=e?n[i]:n[s]]=!0}}else t[e]=!0}function Ga(t,e,n){const i=[],s={},o=e.length;let a,r;for(a=0;a<o;++a)r=e[a],s[r]=a,i.push({value:r,major:!1});return 0!==o&&n?function(t,e,n,i){const s=t._adapter,o=+s.startOf(e[0].value,i),a=e[e.length-1].value;let r,c;for(r=o;r<=a;r=+s.add(r,1,i))c=n[r],c>=0&&(e[c].major=!0);return e}(t,i,s,n):i}class Za extends Cs{static id="time";static defaults={bounds:"data",adapters:{},time:{parser:!1,unit:!1,round:!1,isoWeekday:!1,minUnit:"millisecond",displayFormats:{}},ticks:{source:"auto",callback:!1,major:{enabled:!1}}};constructor(t){super(t),this._cache={data:[],labels:[],all:[]},this._unit="day",this._majorUnit=void 0,this._offsets={},this._normalized=!1,this._parseOpts=void 0}init(t,e={}){const n=t.time||(t.time={}),i=this._adapter=new Ai._date(t.adapters.date);i.init(e),Mt(n.displayFormats,i.formats()),this._parseOpts={parser:n.parser,round:n.round,isoWeekday:n.isoWeekday},super.init(t),this._normalized=e.normalized}parse(t,e){return void 0===t?null:Xa(this,t)}beforeLayout(){super.beforeLayout(),this._cache={data:[],labels:[],all:[]}}determineDataLimits(){const t=this.options,e=this._adapter,n=t.time.unit||"day";let{min:i,max:s,minDefined:o,maxDefined:a}=this.getUserBounds();function r(t){o||isNaN(t.min)||(i=Math.min(i,t.min)),a||isNaN(t.max)||(s=Math.max(s,t.max))}o&&a||(r(this._getLabelBounds()),"ticks"===t.bounds&&"labels"===t.ticks.source||r(this.getMinMax(!1))),i=gt(i)&&!isNaN(i)?i:+e.startOf(Date.now(),n),s=gt(s)&&!isNaN(s)?s:+e.endOf(Date.now(),n)+1,this.min=Math.min(i,s-1),this.max=Math.max(i+1,s)}_getLabelBounds(){const t=this.getLabelTimestamps();let e=Number.POSITIVE_INFINITY,n=Number.NEGATIVE_INFINITY;return t.length&&(e=t[0],n=t[t.length-1]),{min:e,max:n}}buildTicks(){const t=this.options,e=t.time,n=t.ticks,i="labels"===n.source?this.getLabelTimestamps():this._generate();"ticks"===t.bounds&&i.length&&(this.min=this._userMin||i[0],this.max=this._userMax||i[i.length-1]);const s=this.min,o=function(t,e,n){let i=0,s=t.length;for(;i<s&&t[i]<e;)i++;for(;s>i&&t[s-1]>n;)s--;return i>0||s<t.length?t.slice(i,s):t}(i,s,this.max);return this._unit=e.unit||(n.autoSkip?Qa(e.minUnit,this.min,this.max,this._getLabelCapacity(s)):function(t,e,n,i,s){for(let o=Ya.length-1;o>=Ya.indexOf(n);o--){const n=Ya[o];if(ja[n].common&&t._adapter.diff(s,i,n)>=e-1)return n}return Ya[n?Ya.indexOf(n):0]}(this,o.length,e.minUnit,this.min,this.max)),this._majorUnit=n.major.enabled&&"year"!==this._unit?function(t){for(let e=Ya.indexOf(t)+1,n=Ya.length;e<n;++e)if(ja[Ya[e]].common)return Ya[e]}(this._unit):void 0,this.initOffsets(i),t.reverse&&o.reverse(),Ga(this,o,this._majorUnit)}afterAutoSkip(){this.options.offsetAfterAutoskip&&this.initOffsets(this.ticks.map((t=>+t.value)))}initOffsets(t=[]){let e,n,i=0,s=0;this.options.offset&&t.length&&(e=this.getDecimalForValue(t[0]),i=1===t.length?1-e:(this.getDecimalForValue(t[1])-e)/2,n=this.getDecimalForValue(t[t.length-1]),s=1===t.length?n:(n-this.getDecimalForValue(t[t.length-2]))/2);const o=t.length<3?.5:.25;i=te(i,0,o),s=te(s,0,o),this._offsets={start:i,end:s,factor:1/(i+1+s)}}_generate(){const t=this._adapter,e=this.min,n=this.max,i=this.options,s=i.time,o=s.unit||Qa(s.minUnit,e,n,this._getLabelCapacity(e)),a=mt(i.ticks.stepSize,1),r="week"===o&&s.isoWeekday,c=Vt(r)||!0===r,l={};let d,h,u=e;if(c&&(u=+t.startOf(u,"isoWeek",r)),u=+t.startOf(u,c?"day":o),t.diff(n,e,o)>1e5*a)throw new Error(e+" and "+n+" are too far apart with stepSize of "+a+" "+o);const g="data"===i.ticks.source&&this.getDataTimestamps();for(d=u,h=0;d<n;d=+t.add(d,a,o),h++)Ka(l,d,g);return d!==n&&"ticks"!==i.bounds&&1!==h||Ka(l,d,g),Object.keys(l).sort(Ua).map((t=>+t))}getLabelForValue(t){const e=this._adapter,n=this.options.time;return n.tooltipFormat?e.format(t,n.tooltipFormat):e.format(t,n.displayFormats.datetime)}format(t,e){const n=this.options.time.displayFormats,i=this._unit,s=e||n[i];return this._adapter.format(t,s)}_tickFormatFunction(t,e,n,i){const s=this.options,o=s.ticks.callback;if(o)return bt(o,[t,e,n],this);const a=s.time.displayFormats,r=this._unit,c=this._majorUnit,l=r&&a[r],d=c&&a[c],h=n[e],u=c&&d&&h&&h.major;return this._adapter.format(t,i||(u?d:l))}generateTickLabels(t){let e,n,i;for(e=0,n=t.length;e<n;++e)i=t[e],i.label=this._tickFormatFunction(i.value,e,t)}getDecimalForValue(t){return null===t?NaN:(t-this.min)/(this.max-this.min)}getPixelForValue(t){const e=this._offsets,n=this.getDecimalForValue(t);return this.getPixelForDecimal((e.start+n)*e.factor)}getValueForPixel(t){const e=this._offsets,n=this.getDecimalForPixel(t)/e.factor-e.end;return this.min+n*(this.max-this.min)}_getLabelSize(t){const e=this.options.ticks,n=this.ctx.measureText(t).width,i=Yt(this.isHorizontal()?e.maxRotation:e.minRotation),s=Math.cos(i),o=Math.sin(i),a=this._resolveTickFontOptions(0).size;return{w:n*s+a*o,h:n*o+a*s}}_getLabelCapacity(t){const e=this.options.time,n=e.displayFormats,i=n[e.unit]||n.millisecond,s=this._tickFormatFunction(t,0,Ga(this,[t],this._majorUnit),i),o=this._getLabelSize(s),a=Math.floor(this.isHorizontal()?this.width/o.w:this.height/o.h)-1;return a>0?a:1}getDataTimestamps(){let t,e,n=this._cache.data||[];if(n.length)return n;const i=this.getMatchingVisibleMetas();if(this._normalized&&i.length)return this._cache.data=i[0].controller.getAllParsedValues(this);for(t=0,e=i.length;t<e;++t)n=n.concat(i[t].controller.getAllParsedValues(this));return this._cache.data=this.normalize(n)}getLabelTimestamps(){const t=this._cache.labels||[];let e,n;if(t.length)return t;const i=this.getLabels();for(e=0,n=i.length;e<n;++e)t.push(Xa(this,i[e]));return this._cache.labels=this._normalized?t:this.normalize(t)}normalize(t){return re(t.sort(Ua))}}function Ja(t,e,n){let i,s,o,a,r=0,c=t.length-1;n?(e>=t[r].pos&&e<=t[c].pos&&({lo:r,hi:c}=ie(t,"pos",e)),({pos:i,time:o}=t[r]),({pos:s,time:a}=t[c])):(e>=t[r].time&&e<=t[c].time&&({lo:r,hi:c}=ie(t,"time",e)),({time:i,pos:o}=t[r]),({time:s,pos:a}=t[c]));const l=s-i;return l?o+(a-o)*(e-i)/l:o}var tr=Object.freeze({__proto__:null,CategoryScale:class extends Cs{static id="category";static defaults={ticks:{callback:Ca}};constructor(t){super(t),this._startValue=void 0,this._valueRange=0,this._addedLabels=[]}init(t){const e=this._addedLabels;if(e.length){const t=this.getLabels();for(const{index:n,label:i}of e)t[n]===i&&t.splice(n,1);this._addedLabels=[]}super.init(t)}parse(t,e){if(dt(t))return null;const n=this.getLabels();return((t,e)=>null===t?null:te(Math.round(t),0,e))(e=isFinite(e)&&n[e]===t?e:Ma(n,t,mt(e,t),this._addedLabels),n.length-1)}determineDataLimits(){const{minDefined:t,maxDefined:e}=this.getUserBounds();let{min:n,max:i}=this.getMinMax(!0);"ticks"===this.options.bounds&&(t||(n=0),e||(i=this.getLabels().length-1)),this.min=n,this.max=i}buildTicks(){const t=this.min,e=this.max,n=this.options.offset,i=[];let s=this.getLabels();s=0===t&&e===s.length-1?s:s.slice(t,e+1),this._valueRange=Math.max(s.length-(n?0:1),1),this._startValue=this.min-(n?.5:0);for(let n=t;n<=e;n++)i.push({value:n});return i}getLabelForValue(t){return Ca.call(this,t)}configure(){super.configure(),this.isHorizontal()||(this._reversePixels=!this._reversePixels)}getPixelForValue(t){return"number"!=typeof t&&(t=this.parse(t)),null===t?NaN:this.getPixelForDecimal((t-this._startValue)/this._valueRange)}getPixelForTick(t){const e=this.ticks;return t<0||t>e.length-1?null:this.getPixelForValue(e[t].value)}getValueForPixel(t){return Math.round(this._startValue+this.getDecimalForPixel(t)*this._valueRange)}getBasePixel(){return this.bottom}},LinearScale:Pa,LogarithmicScale:za,RadialLinearScale:Va,TimeScale:Za,TimeSeriesScale:class extends Za{static id="timeseries";static defaults=Za.defaults;constructor(t){super(t),this._table=[],this._minPos=void 0,this._tableRange=void 0}initOffsets(){const t=this._getTimestampsForTable(),e=this._table=this.buildLookupTable(t);this._minPos=Ja(e,this.min),this._tableRange=Ja(e,this.max)-this._minPos,super.initOffsets(t)}buildLookupTable(t){const{min:e,max:n}=this,i=[],s=[];let o,a,r,c,l;for(o=0,a=t.length;o<a;++o)c=t[o],c>=e&&c<=n&&i.push(c);if(i.length<2)return[{time:e,pos:0},{time:n,pos:1}];for(o=0,a=i.length;o<a;++o)l=i[o+1],r=i[o-1],c=i[o],Math.round((l+r)/2)!==c&&s.push({time:c,pos:o/(a-1)});return s}_generate(){const t=this.min,e=this.max;let n=super.getDataTimestamps();return n.includes(t)&&n.length||n.splice(0,0,t),n.includes(e)&&1!==n.length||n.push(e),n.sort(((t,e)=>t-e))}_getTimestampsForTable(){let t=this._cache.all||[];if(t.length)return t;const e=this.getDataTimestamps(),n=this.getLabelTimestamps();return t=e.length&&n.length?this.normalize(e.concat(n)):e.length?e:n,t=this._cache.all=t,t}getDecimalForValue(t){return(Ja(this._table,t)-this._minPos)/this._tableRange}getValueForPixel(t){const e=this._offsets,n=this.getDecimalForPixel(t)/e.factor-e.end;return Ja(this._table,n*this._tableRange+this._minPos,!0)}}});const er=[Ti,Co,ka,tr],nr=6048e5,ir=6e4,sr=36e5,or=Symbol.for("constructDateFrom");function ar(t,e){return"function"==typeof t?t(e):t&&"object"==typeof t&&or in t?t[or](e):t instanceof Date?new t.constructor(e):new Date(e)}function rr(t,e){return ar(e||t,t)}function cr(t,e,n){const i=rr(t,n?.in);return isNaN(e)?ar(n?.in||t,NaN):e?(i.setDate(i.getDate()+e),i):i}function lr(t,e,n){const i=rr(t,n?.in);if(isNaN(e))return ar(n?.in||t,NaN);if(!e)return i;const s=i.getDate(),o=ar(n?.in||t,i.getTime());o.setMonth(i.getMonth()+e+1,0);return s>=o.getDate()?o:(i.setFullYear(o.getFullYear(),o.getMonth(),s),i)}function dr(t,e,n){return ar(n?.in||t,+rr(t)+e)}let hr={};function ur(){return hr}function gr(t,e){const n=ur(),i=e?.weekStartsOn??e?.locale?.options?.weekStartsOn??n.weekStartsOn??n.locale?.options?.weekStartsOn??0,s=rr(t,e?.in),o=s.getDay(),a=(o<i?7:0)+o-i;return s.setDate(s.getDate()-a),s.setHours(0,0,0,0),s}function pr(t,e){return gr(t,{...e,weekStartsOn:1})}function mr(t,e){const n=rr(t,e?.in),i=n.getFullYear(),s=ar(n,0);s.setFullYear(i+1,0,4),s.setHours(0,0,0,0);const o=pr(s),a=ar(n,0);a.setFullYear(i,0,4),a.setHours(0,0,0,0);const r=pr(a);return n.getTime()>=o.getTime()?i+1:n.getTime()>=r.getTime()?i:i-1}function fr(t){const e=rr(t),n=new Date(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate(),e.getHours(),e.getMinutes(),e.getSeconds(),e.getMilliseconds()));return n.setUTCFullYear(e.getFullYear()),+t-+n}function br(t,...e){const n=ar.bind(null,t||e.find((t=>"object"==typeof t)));return e.map(n)}function yr(t,e){const n=rr(t,e?.in);return n.setHours(0,0,0,0),n}function xr(t,e,n){const[i,s]=br(n?.in,t,e),o=yr(i),a=yr(s),r=+o-fr(o),c=+a-fr(a);return Math.round((r-c)/864e5)}function vr(t,e){const n=+rr(t)-+rr(e);return n<0?-1:n>0?1:n}function wr(t){return!(!((e=t)instanceof Date||"object"==typeof e&&"[object Date]"===Object.prototype.toString.call(e))&&"number"!=typeof t||isNaN(+rr(t)));var e}function Sr(t,e,n){const[i,s]=br(n?.in,t,e),o=kr(i,s),a=Math.abs(xr(i,s));i.setDate(i.getDate()-o*a);const r=o*(a-Number(kr(i,s)===-o));return 0===r?0:r}function kr(t,e){const n=t.getFullYear()-e.getFullYear()||t.getMonth()-e.getMonth()||t.getDate()-e.getDate()||t.getHours()-e.getHours()||t.getMinutes()-e.getMinutes()||t.getSeconds()-e.getSeconds()||t.getMilliseconds()-e.getMilliseconds();return n<0?-1:n>0?1:n}function Mr(t){return e=>{const n=(t?Math[t]:Math.trunc)(e);return 0===n?0:n}}function Cr(t,e){return+rr(t)-+rr(e)}function _r(t,e){const n=rr(t,e?.in);return n.setHours(23,59,59,999),n}function Dr(t,e){const n=rr(t,e?.in),i=n.getMonth();return n.setFullYear(n.getFullYear(),i+1,0),n.setHours(23,59,59,999),n}function Tr(t,e,n){const[i,s,o]=br(n?.in,t,t,e),a=vr(s,o),r=Math.abs(function(t,e,n){const[i,s]=br(n?.in,t,e);return 12*(i.getFullYear()-s.getFullYear())+(i.getMonth()-s.getMonth())}(s,o));if(r<1)return 0;1===s.getMonth()&&s.getDate()>27&&s.setDate(30),s.setMonth(s.getMonth()-a*r);let c=vr(s,o)===-a;(function(t,e){const n=rr(t,e?.in);return+_r(n,e)===+Dr(n,e)})(i)&&1===r&&1===vr(i,o)&&(c=!1);const l=a*(r-+c);return 0===l?0:l}function Pr(t,e,n){const[i,s]=br(n?.in,t,e),o=vr(i,s),a=Math.abs(function(t,e,n){const[i,s]=br(n?.in,t,e);return i.getFullYear()-s.getFullYear()}(i,s));i.setFullYear(1584),s.setFullYear(1584);const r=o*(a-+(vr(i,s)===-o));return 0===r?0:r}function Er(t,e){const n=rr(t,e?.in);return n.setFullYear(n.getFullYear(),0,1),n.setHours(0,0,0,0),n}const Ar={lessThanXSeconds:{one:"less than a second",other:"less than {{count}} seconds"},xSeconds:{one:"1 second",other:"{{count}} seconds"},halfAMinute:"half a minute",lessThanXMinutes:{one:"less than a minute",other:"less than {{count}} minutes"},xMinutes:{one:"1 minute",other:"{{count}} minutes"},aboutXHours:{one:"about 1 hour",other:"about {{count}} hours"},xHours:{one:"1 hour",other:"{{count}} hours"},xDays:{one:"1 day",other:"{{count}} days"},aboutXWeeks:{one:"about 1 week",other:"about {{count}} weeks"},xWeeks:{one:"1 week",other:"{{count}} weeks"},aboutXMonths:{one:"about 1 month",other:"about {{count}} months"},xMonths:{one:"1 month",other:"{{count}} months"},aboutXYears:{one:"about 1 year",other:"about {{count}} years"},xYears:{one:"1 year",other:"{{count}} years"},overXYears:{one:"over 1 year",other:"over {{count}} years"},almostXYears:{one:"almost 1 year",other:"almost {{count}} years"}};function Lr(t){return(e={})=>{const n=e.width?String(e.width):t.defaultWidth;return t.formats[n]||t.formats[t.defaultWidth]}}const Ir={date:Lr({formats:{full:"EEEE, MMMM do, y",long:"MMMM do, y",medium:"MMM d, y",short:"MM/dd/yyyy"},defaultWidth:"full"}),time:Lr({formats:{full:"h:mm:ss a zzzz",long:"h:mm:ss a z",medium:"h:mm:ss a",short:"h:mm a"},defaultWidth:"full"}),dateTime:Lr({formats:{full:"{{date}} 'at' {{time}}",long:"{{date}} 'at' {{time}}",medium:"{{date}}, {{time}}",short:"{{date}}, {{time}}"},defaultWidth:"full"})},Or={lastWeek:"'last' eeee 'at' p",yesterday:"'yesterday at' p",today:"'today at' p",tomorrow:"'tomorrow at' p",nextWeek:"eeee 'at' p",other:"P"};function zr(t){return(e,n)=>{let i;if("formatting"===(n?.context?String(n.context):"standalone")&&t.formattingValues){const e=t.defaultFormattingWidth||t.defaultWidth,s=n?.width?String(n.width):e;i=t.formattingValues[s]||t.formattingValues[e]}else{const e=t.defaultWidth,s=n?.width?String(n.width):t.defaultWidth;i=t.values[s]||t.values[e]}return i[t.argumentCallback?t.argumentCallback(e):e]}}const Wr={ordinalNumber:(t,e)=>{const n=Number(t),i=n%100;if(i>20||i<10)switch(i%10){case 1:return n+"st";case 2:return n+"nd";case 3:return n+"rd"}return n+"th"},era:zr({values:{narrow:["B","A"],abbreviated:["BC","AD"],wide:["Before Christ","Anno Domini"]},defaultWidth:"wide"}),quarter:zr({values:{narrow:["1","2","3","4"],abbreviated:["Q1","Q2","Q3","Q4"],wide:["1st quarter","2nd quarter","3rd quarter","4th quarter"]},defaultWidth:"wide",argumentCallback:t=>t-1}),month:zr({values:{narrow:["J","F","M","A","M","J","J","A","S","O","N","D"],abbreviated:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],wide:["January","February","March","April","May","June","July","August","September","October","November","December"]},defaultWidth:"wide"}),day:zr({values:{narrow:["S","M","T","W","T","F","S"],short:["Su","Mo","Tu","We","Th","Fr","Sa"],abbreviated:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],wide:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]},defaultWidth:"wide"}),dayPeriod:zr({values:{narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"}},defaultWidth:"wide",formattingValues:{narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"}},defaultFormattingWidth:"wide"})};function Nr(t){return(e,n={})=>{const i=n.width,s=i&&t.matchPatterns[i]||t.matchPatterns[t.defaultMatchWidth],o=e.match(s);if(!o)return null;const a=o[0],r=i&&t.parsePatterns[i]||t.parsePatterns[t.defaultParseWidth],c=Array.isArray(r)?function(t,e){for(let n=0;n<t.length;n++)if(e(t[n]))return n;return}(r,(t=>t.test(a))):function(t,e){for(const n in t)if(Object.prototype.hasOwnProperty.call(t,n)&&e(t[n]))return n;return}(r,(t=>t.test(a)));let l;l=t.valueCallback?t.valueCallback(c):c,l=n.valueCallback?n.valueCallback(l):l;return{value:l,rest:e.slice(a.length)}}}const Rr={ordinalNumber:($r={matchPattern:/^(\d+)(th|st|nd|rd)?/i,parsePattern:/\d+/i,valueCallback:t=>parseInt(t,10)},(t,e={})=>{const n=t.match($r.matchPattern);if(!n)return null;const i=n[0],s=t.match($r.parsePattern);if(!s)return null;let o=$r.valueCallback?$r.valueCallback(s[0]):s[0];return o=e.valueCallback?e.valueCallback(o):o,{value:o,rest:t.slice(i.length)}}),era:Nr({matchPatterns:{narrow:/^(b|a)/i,abbreviated:/^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,wide:/^(before christ|before common era|anno domini|common era)/i},defaultMatchWidth:"wide",parsePatterns:{any:[/^b/i,/^(a|c)/i]},defaultParseWidth:"any"}),quarter:Nr({matchPatterns:{narrow:/^[1234]/i,abbreviated:/^q[1234]/i,wide:/^[1234](th|st|nd|rd)? quarter/i},defaultMatchWidth:"wide",parsePatterns:{any:[/1/i,/2/i,/3/i,/4/i]},defaultParseWidth:"any",valueCallback:t=>t+1}),month:Nr({matchPatterns:{narrow:/^[jfmasond]/i,abbreviated:/^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,wide:/^(january|february|march|april|may|june|july|august|september|october|november|december)/i},defaultMatchWidth:"wide",parsePatterns:{narrow:[/^j/i,/^f/i,/^m/i,/^a/i,/^m/i,/^j/i,/^j/i,/^a/i,/^s/i,/^o/i,/^n/i,/^d/i],any:[/^ja/i,/^f/i,/^mar/i,/^ap/i,/^may/i,/^jun/i,/^jul/i,/^au/i,/^s/i,/^o/i,/^n/i,/^d/i]},defaultParseWidth:"any"}),day:Nr({matchPatterns:{narrow:/^[smtwf]/i,short:/^(su|mo|tu|we|th|fr|sa)/i,abbreviated:/^(sun|mon|tue|wed|thu|fri|sat)/i,wide:/^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i},defaultMatchWidth:"wide",parsePatterns:{narrow:[/^s/i,/^m/i,/^t/i,/^w/i,/^t/i,/^f/i,/^s/i],any:[/^su/i,/^m/i,/^tu/i,/^w/i,/^th/i,/^f/i,/^sa/i]},defaultParseWidth:"any"}),dayPeriod:Nr({matchPatterns:{narrow:/^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,any:/^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i},defaultMatchWidth:"any",parsePatterns:{any:{am:/^a/i,pm:/^p/i,midnight:/^mi/i,noon:/^no/i,morning:/morning/i,afternoon:/afternoon/i,evening:/evening/i,night:/night/i}},defaultParseWidth:"any"})};var $r;const Fr={code:"en-US",formatDistance:(t,e,n)=>{let i;const s=Ar[t];return i="string"==typeof s?s:1===e?s.one:s.other.replace("{{count}}",e.toString()),n?.addSuffix?n.comparison&&n.comparison>0?"in "+i:i+" ago":i},formatLong:Ir,formatRelative:(t,e,n,i)=>Or[t],localize:Wr,match:Rr,options:{weekStartsOn:0,firstWeekContainsDate:1}};function qr(t,e){const n=rr(t,e?.in),i=+pr(n)-+function(t,e){const n=mr(t,e),i=ar(e?.in||t,0);return i.setFullYear(n,0,4),i.setHours(0,0,0,0),pr(i)}(n);return Math.round(i/nr)+1}function Br(t,e){const n=rr(t,e?.in),i=n.getFullYear(),s=ur(),o=e?.firstWeekContainsDate??e?.locale?.options?.firstWeekContainsDate??s.firstWeekContainsDate??s.locale?.options?.firstWeekContainsDate??1,a=ar(e?.in||t,0);a.setFullYear(i+1,0,o),a.setHours(0,0,0,0);const r=gr(a,e),c=ar(e?.in||t,0);c.setFullYear(i,0,o),c.setHours(0,0,0,0);const l=gr(c,e);return+n>=+r?i+1:+n>=+l?i:i-1}function Hr(t,e){const n=rr(t,e?.in),i=+gr(n,e)-+function(t,e){const n=ur(),i=e?.firstWeekContainsDate??e?.locale?.options?.firstWeekContainsDate??n.firstWeekContainsDate??n.locale?.options?.firstWeekContainsDate??1,s=Br(t,e),o=ar(e?.in||t,0);return o.setFullYear(s,0,i),o.setHours(0,0,0,0),gr(o,e)}(n,e);return Math.round(i/nr)+1}function Vr(t,e){return(t<0?"-":"")+Math.abs(t).toString().padStart(e,"0")}const jr={y(t,e){const n=t.getFullYear(),i=n>0?n:1-n;return Vr("yy"===e?i%100:i,e.length)},M(t,e){const n=t.getMonth();return"M"===e?String(n+1):Vr(n+1,2)},d:(t,e)=>Vr(t.getDate(),e.length),a(t,e){const n=t.getHours()/12>=1?"pm":"am";switch(e){case"a":case"aa":return n.toUpperCase();case"aaa":return n;case"aaaaa":return n[0];default:return"am"===n?"a.m.":"p.m."}},h:(t,e)=>Vr(t.getHours()%12||12,e.length),H:(t,e)=>Vr(t.getHours(),e.length),m:(t,e)=>Vr(t.getMinutes(),e.length),s:(t,e)=>Vr(t.getSeconds(),e.length),S(t,e){const n=e.length,i=t.getMilliseconds();return Vr(Math.trunc(i*Math.pow(10,n-3)),e.length)}},Yr="midnight",Ur="noon",Xr="morning",Qr="afternoon",Kr="evening",Gr="night",Zr={G:function(t,e,n){const i=t.getFullYear()>0?1:0;switch(e){case"G":case"GG":case"GGG":return n.era(i,{width:"abbreviated"});case"GGGGG":return n.era(i,{width:"narrow"});default:return n.era(i,{width:"wide"})}},y:function(t,e,n){if("yo"===e){const e=t.getFullYear(),i=e>0?e:1-e;return n.ordinalNumber(i,{unit:"year"})}return jr.y(t,e)},Y:function(t,e,n,i){const s=Br(t,i),o=s>0?s:1-s;if("YY"===e){return Vr(o%100,2)}return"Yo"===e?n.ordinalNumber(o,{unit:"year"}):Vr(o,e.length)},R:function(t,e){return Vr(mr(t),e.length)},u:function(t,e){return Vr(t.getFullYear(),e.length)},Q:function(t,e,n){const i=Math.ceil((t.getMonth()+1)/3);switch(e){case"Q":return String(i);case"QQ":return Vr(i,2);case"Qo":return n.ordinalNumber(i,{unit:"quarter"});case"QQQ":return n.quarter(i,{width:"abbreviated",context:"formatting"});case"QQQQQ":return n.quarter(i,{width:"narrow",context:"formatting"});default:return n.quarter(i,{width:"wide",context:"formatting"})}},q:function(t,e,n){const i=Math.ceil((t.getMonth()+1)/3);switch(e){case"q":return String(i);case"qq":return Vr(i,2);case"qo":return n.ordinalNumber(i,{unit:"quarter"});case"qqq":return n.quarter(i,{width:"abbreviated",context:"standalone"});case"qqqqq":return n.quarter(i,{width:"narrow",context:"standalone"});default:return n.quarter(i,{width:"wide",context:"standalone"})}},M:function(t,e,n){const i=t.getMonth();switch(e){case"M":case"MM":return jr.M(t,e);case"Mo":return n.ordinalNumber(i+1,{unit:"month"});case"MMM":return n.month(i,{width:"abbreviated",context:"formatting"});case"MMMMM":return n.month(i,{width:"narrow",context:"formatting"});default:return n.month(i,{width:"wide",context:"formatting"})}},L:function(t,e,n){const i=t.getMonth();switch(e){case"L":return String(i+1);case"LL":return Vr(i+1,2);case"Lo":return n.ordinalNumber(i+1,{unit:"month"});case"LLL":return n.month(i,{width:"abbreviated",context:"standalone"});case"LLLLL":return n.month(i,{width:"narrow",context:"standalone"});default:return n.month(i,{width:"wide",context:"standalone"})}},w:function(t,e,n,i){const s=Hr(t,i);return"wo"===e?n.ordinalNumber(s,{unit:"week"}):Vr(s,e.length)},I:function(t,e,n){const i=qr(t);return"Io"===e?n.ordinalNumber(i,{unit:"week"}):Vr(i,e.length)},d:function(t,e,n){return"do"===e?n.ordinalNumber(t.getDate(),{unit:"date"}):jr.d(t,e)},D:function(t,e,n){const i=function(t,e){const n=rr(t,e?.in);return xr(n,Er(n))+1}(t);return"Do"===e?n.ordinalNumber(i,{unit:"dayOfYear"}):Vr(i,e.length)},E:function(t,e,n){const i=t.getDay();switch(e){case"E":case"EE":case"EEE":return n.day(i,{width:"abbreviated",context:"formatting"});case"EEEEE":return n.day(i,{width:"narrow",context:"formatting"});case"EEEEEE":return n.day(i,{width:"short",context:"formatting"});default:return n.day(i,{width:"wide",context:"formatting"})}},e:function(t,e,n,i){const s=t.getDay(),o=(s-i.weekStartsOn+8)%7||7;switch(e){case"e":return String(o);case"ee":return Vr(o,2);case"eo":return n.ordinalNumber(o,{unit:"day"});case"eee":return n.day(s,{width:"abbreviated",context:"formatting"});case"eeeee":return n.day(s,{width:"narrow",context:"formatting"});case"eeeeee":return n.day(s,{width:"short",context:"formatting"});default:return n.day(s,{width:"wide",context:"formatting"})}},c:function(t,e,n,i){const s=t.getDay(),o=(s-i.weekStartsOn+8)%7||7;switch(e){case"c":return String(o);case"cc":return Vr(o,e.length);case"co":return n.ordinalNumber(o,{unit:"day"});case"ccc":return n.day(s,{width:"abbreviated",context:"standalone"});case"ccccc":return n.day(s,{width:"narrow",context:"standalone"});case"cccccc":return n.day(s,{width:"short",context:"standalone"});default:return n.day(s,{width:"wide",context:"standalone"})}},i:function(t,e,n){const i=t.getDay(),s=0===i?7:i;switch(e){case"i":return String(s);case"ii":return Vr(s,e.length);case"io":return n.ordinalNumber(s,{unit:"day"});case"iii":return n.day(i,{width:"abbreviated",context:"formatting"});case"iiiii":return n.day(i,{width:"narrow",context:"formatting"});case"iiiiii":return n.day(i,{width:"short",context:"formatting"});default:return n.day(i,{width:"wide",context:"formatting"})}},a:function(t,e,n){const i=t.getHours()/12>=1?"pm":"am";switch(e){case"a":case"aa":return n.dayPeriod(i,{width:"abbreviated",context:"formatting"});case"aaa":return n.dayPeriod(i,{width:"abbreviated",context:"formatting"}).toLowerCase();case"aaaaa":return n.dayPeriod(i,{width:"narrow",context:"formatting"});default:return n.dayPeriod(i,{width:"wide",context:"formatting"})}},b:function(t,e,n){const i=t.getHours();let s;switch(s=12===i?Ur:0===i?Yr:i/12>=1?"pm":"am",e){case"b":case"bb":return n.dayPeriod(s,{width:"abbreviated",context:"formatting"});case"bbb":return n.dayPeriod(s,{width:"abbreviated",context:"formatting"}).toLowerCase();case"bbbbb":return n.dayPeriod(s,{width:"narrow",context:"formatting"});default:return n.dayPeriod(s,{width:"wide",context:"formatting"})}},B:function(t,e,n){const i=t.getHours();let s;switch(s=i>=17?Kr:i>=12?Qr:i>=4?Xr:Gr,e){case"B":case"BB":case"BBB":return n.dayPeriod(s,{width:"abbreviated",context:"formatting"});case"BBBBB":return n.dayPeriod(s,{width:"narrow",context:"formatting"});default:return n.dayPeriod(s,{width:"wide",context:"formatting"})}},h:function(t,e,n){if("ho"===e){let e=t.getHours()%12;return 0===e&&(e=12),n.ordinalNumber(e,{unit:"hour"})}return jr.h(t,e)},H:function(t,e,n){return"Ho"===e?n.ordinalNumber(t.getHours(),{unit:"hour"}):jr.H(t,e)},K:function(t,e,n){const i=t.getHours()%12;return"Ko"===e?n.ordinalNumber(i,{unit:"hour"}):Vr(i,e.length)},k:function(t,e,n){let i=t.getHours();return 0===i&&(i=24),"ko"===e?n.ordinalNumber(i,{unit:"hour"}):Vr(i,e.length)},m:function(t,e,n){return"mo"===e?n.ordinalNumber(t.getMinutes(),{unit:"minute"}):jr.m(t,e)},s:function(t,e,n){return"so"===e?n.ordinalNumber(t.getSeconds(),{unit:"second"}):jr.s(t,e)},S:function(t,e){return jr.S(t,e)},X:function(t,e,n){const i=t.getTimezoneOffset();if(0===i)return"Z";switch(e){case"X":return tc(i);case"XXXX":case"XX":return ec(i);default:return ec(i,":")}},x:function(t,e,n){const i=t.getTimezoneOffset();switch(e){case"x":return tc(i);case"xxxx":case"xx":return ec(i);default:return ec(i,":")}},O:function(t,e,n){const i=t.getTimezoneOffset();switch(e){case"O":case"OO":case"OOO":return"GMT"+Jr(i,":");default:return"GMT"+ec(i,":")}},z:function(t,e,n){const i=t.getTimezoneOffset();switch(e){case"z":case"zz":case"zzz":return"GMT"+Jr(i,":");default:return"GMT"+ec(i,":")}},t:function(t,e,n){return Vr(Math.trunc(+t/1e3),e.length)},T:function(t,e,n){return Vr(+t,e.length)}};function Jr(t,e=""){const n=t>0?"-":"+",i=Math.abs(t),s=Math.trunc(i/60),o=i%60;return 0===o?n+String(s):n+String(s)+e+Vr(o,2)}function tc(t,e){if(t%60==0){return(t>0?"-":"+")+Vr(Math.abs(t)/60,2)}return ec(t,e)}function ec(t,e=""){const n=t>0?"-":"+",i=Math.abs(t);return n+Vr(Math.trunc(i/60),2)+e+Vr(i%60,2)}const nc=(t,e)=>{switch(t){case"P":return e.date({width:"short"});case"PP":return e.date({width:"medium"});case"PPP":return e.date({width:"long"});default:return e.date({width:"full"})}},ic=(t,e)=>{switch(t){case"p":return e.time({width:"short"});case"pp":return e.time({width:"medium"});case"ppp":return e.time({width:"long"});default:return e.time({width:"full"})}},sc={p:ic,P:(t,e)=>{const n=t.match(/(P+)(p+)?/)||[],i=n[1],s=n[2];if(!s)return nc(t,e);let o;switch(i){case"P":o=e.dateTime({width:"short"});break;case"PP":o=e.dateTime({width:"medium"});break;case"PPP":o=e.dateTime({width:"long"});break;default:o=e.dateTime({width:"full"})}return o.replace("{{date}}",nc(i,e)).replace("{{time}}",ic(s,e))}},oc=/^D+$/,ac=/^Y+$/,rc=["D","DD","YY","YYYY"];function cc(t){return oc.test(t)}function lc(t){return ac.test(t)}function dc(t,e,n){const i=function(t,e,n){const i="Y"===t[0]?"years":"days of the month";return`Use \`${t.toLowerCase()}\` instead of \`${t}\` (in \`${e}\`) for formatting ${i} to the input \`${n}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`}(t,e,n);if(console.warn(i),rc.includes(t))throw new RangeError(i)}const hc=/[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g,uc=/P+p+|P+|p+|''|'(''|[^'])+('|$)|./g,gc=/^'([^]*?)'?$/,pc=/''/g,mc=/[a-zA-Z]/;function fc(t){const e=t.match(gc);return e?e[1].replace(pc,"'"):t}class bc{subPriority=0;validate(t,e){return!0}}class yc extends bc{constructor(t,e,n,i,s){super(),this.value=t,this.validateValue=e,this.setValue=n,this.priority=i,s&&(this.subPriority=s)}validate(t,e){return this.validateValue(t,this.value,e)}set(t,e,n){return this.setValue(t,e,this.value,n)}}class xc extends bc{priority=10;subPriority=-1;constructor(t,e){super(),this.context=t||(t=>ar(e,t))}set(t,e){return e.timestampIsSet?t:ar(t,function(t,e){const n=function(t){return"function"==typeof t&&t.prototype?.constructor===t}(e)?new e(0):ar(e,0);return n.setFullYear(t.getFullYear(),t.getMonth(),t.getDate()),n.setHours(t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds()),n}(t,this.context))}}class vc{run(t,e,n,i){const s=this.parse(t,e,n,i);return s?{setter:new yc(s.value,this.validate,this.set,this.priority,this.subPriority),rest:s.rest}:null}validate(t,e,n){return!0}}const wc=/^(1[0-2]|0?\d)/,Sc=/^(3[0-1]|[0-2]?\d)/,kc=/^(36[0-6]|3[0-5]\d|[0-2]?\d?\d)/,Mc=/^(5[0-3]|[0-4]?\d)/,Cc=/^(2[0-3]|[0-1]?\d)/,_c=/^(2[0-4]|[0-1]?\d)/,Dc=/^(1[0-1]|0?\d)/,Tc=/^(1[0-2]|0?\d)/,Pc=/^[0-5]?\d/,Ec=/^[0-5]?\d/,Ac=/^\d/,Lc=/^\d{1,2}/,Ic=/^\d{1,3}/,Oc=/^\d{1,4}/,zc=/^-?\d+/,Wc=/^-?\d/,Nc=/^-?\d{1,2}/,Rc=/^-?\d{1,3}/,$c=/^-?\d{1,4}/,Fc=/^([+-])(\d{2})(\d{2})?|Z/,qc=/^([+-])(\d{2})(\d{2})|Z/,Bc=/^([+-])(\d{2})(\d{2})((\d{2}))?|Z/,Hc=/^([+-])(\d{2}):(\d{2})|Z/,Vc=/^([+-])(\d{2}):(\d{2})(:(\d{2}))?|Z/;function jc(t,e){return t?{value:e(t.value),rest:t.rest}:t}function Yc(t,e){const n=e.match(t);return n?{value:parseInt(n[0],10),rest:e.slice(n[0].length)}:null}function Uc(t,e){const n=e.match(t);if(!n)return null;if("Z"===n[0])return{value:0,rest:e.slice(1)};const i="+"===n[1]?1:-1,s=n[2]?parseInt(n[2],10):0,o=n[3]?parseInt(n[3],10):0,a=n[5]?parseInt(n[5],10):0;return{value:i*(s*sr+o*ir+1e3*a),rest:e.slice(n[0].length)}}function Xc(t){return Yc(zc,t)}function Qc(t,e){switch(t){case 1:return Yc(Ac,e);case 2:return Yc(Lc,e);case 3:return Yc(Ic,e);case 4:return Yc(Oc,e);default:return Yc(new RegExp("^\\d{1,"+t+"}"),e)}}function Kc(t,e){switch(t){case 1:return Yc(Wc,e);case 2:return Yc(Nc,e);case 3:return Yc(Rc,e);case 4:return Yc($c,e);default:return Yc(new RegExp("^-?\\d{1,"+t+"}"),e)}}function Gc(t){switch(t){case"morning":return 4;case"evening":return 17;case"pm":case"noon":case"afternoon":return 12;default:return 0}}function Zc(t,e){const n=e>0,i=n?e:1-e;let s;if(i<=50)s=t||100;else{const e=i+50;s=t+100*Math.trunc(e/100)-(t>=e%100?100:0)}return n?s:1-s}function Jc(t){return t%400==0||t%4==0&&t%100!=0}const tl=[31,28,31,30,31,30,31,31,30,31,30,31],el=[31,29,31,30,31,30,31,31,30,31,30,31];function nl(t,e,n){const i=ur(),s=n?.weekStartsOn??n?.locale?.options?.weekStartsOn??i.weekStartsOn??i.locale?.options?.weekStartsOn??0,o=rr(t,n?.in),a=o.getDay(),r=7-s;return cr(o,e<0||e>6?e-(a+r)%7:((e%7+7)%7+r)%7-(a+r)%7,n)}function il(t,e,n){const i=rr(t,n?.in),s=function(t,e){const n=rr(t,e?.in).getDay();return 0===n?7:n}(i,n);return cr(i,e-s,n)}const sl={G:new class extends vc{priority=140;parse(t,e,n){switch(e){case"G":case"GG":case"GGG":return n.era(t,{width:"abbreviated"})||n.era(t,{width:"narrow"});case"GGGGG":return n.era(t,{width:"narrow"});default:return n.era(t,{width:"wide"})||n.era(t,{width:"abbreviated"})||n.era(t,{width:"narrow"})}}set(t,e,n){return e.era=n,t.setFullYear(n,0,1),t.setHours(0,0,0,0),t}incompatibleTokens=["R","u","t","T"]},y:new class extends vc{priority=130;incompatibleTokens=["Y","R","u","w","I","i","e","c","t","T"];parse(t,e,n){const i=t=>({year:t,isTwoDigitYear:"yy"===e});switch(e){case"y":return jc(Qc(4,t),i);case"yo":return jc(n.ordinalNumber(t,{unit:"year"}),i);default:return jc(Qc(e.length,t),i)}}validate(t,e){return e.isTwoDigitYear||e.year>0}set(t,e,n){const i=t.getFullYear();if(n.isTwoDigitYear){const e=Zc(n.year,i);return t.setFullYear(e,0,1),t.setHours(0,0,0,0),t}const s="era"in e&&1!==e.era?1-n.year:n.year;return t.setFullYear(s,0,1),t.setHours(0,0,0,0),t}},Y:new class extends vc{priority=130;parse(t,e,n){const i=t=>({year:t,isTwoDigitYear:"YY"===e});switch(e){case"Y":return jc(Qc(4,t),i);case"Yo":return jc(n.ordinalNumber(t,{unit:"year"}),i);default:return jc(Qc(e.length,t),i)}}validate(t,e){return e.isTwoDigitYear||e.year>0}set(t,e,n,i){const s=Br(t,i);if(n.isTwoDigitYear){const e=Zc(n.year,s);return t.setFullYear(e,0,i.firstWeekContainsDate),t.setHours(0,0,0,0),gr(t,i)}const o="era"in e&&1!==e.era?1-n.year:n.year;return t.setFullYear(o,0,i.firstWeekContainsDate),t.setHours(0,0,0,0),gr(t,i)}incompatibleTokens=["y","R","u","Q","q","M","L","I","d","D","i","t","T"]},R:new class extends vc{priority=130;parse(t,e){return Kc("R"===e?4:e.length,t)}set(t,e,n){const i=ar(t,0);return i.setFullYear(n,0,4),i.setHours(0,0,0,0),pr(i)}incompatibleTokens=["G","y","Y","u","Q","q","M","L","w","d","D","e","c","t","T"]},u:new class extends vc{priority=130;parse(t,e){return Kc("u"===e?4:e.length,t)}set(t,e,n){return t.setFullYear(n,0,1),t.setHours(0,0,0,0),t}incompatibleTokens=["G","y","Y","R","w","I","i","e","c","t","T"]},Q:new class extends vc{priority=120;parse(t,e,n){switch(e){case"Q":case"QQ":return Qc(e.length,t);case"Qo":return n.ordinalNumber(t,{unit:"quarter"});case"QQQ":return n.quarter(t,{width:"abbreviated",context:"formatting"})||n.quarter(t,{width:"narrow",context:"formatting"});case"QQQQQ":return n.quarter(t,{width:"narrow",context:"formatting"});default:return n.quarter(t,{width:"wide",context:"formatting"})||n.quarter(t,{width:"abbreviated",context:"formatting"})||n.quarter(t,{width:"narrow",context:"formatting"})}}validate(t,e){return e>=1&&e<=4}set(t,e,n){return t.setMonth(3*(n-1),1),t.setHours(0,0,0,0),t}incompatibleTokens=["Y","R","q","M","L","w","I","d","D","i","e","c","t","T"]},q:new class extends vc{priority=120;parse(t,e,n){switch(e){case"q":case"qq":return Qc(e.length,t);case"qo":return n.ordinalNumber(t,{unit:"quarter"});case"qqq":return n.quarter(t,{width:"abbreviated",context:"standalone"})||n.quarter(t,{width:"narrow",context:"standalone"});case"qqqqq":return n.quarter(t,{width:"narrow",context:"standalone"});default:return n.quarter(t,{width:"wide",context:"standalone"})||n.quarter(t,{width:"abbreviated",context:"standalone"})||n.quarter(t,{width:"narrow",context:"standalone"})}}validate(t,e){return e>=1&&e<=4}set(t,e,n){return t.setMonth(3*(n-1),1),t.setHours(0,0,0,0),t}incompatibleTokens=["Y","R","Q","M","L","w","I","d","D","i","e","c","t","T"]},M:new class extends vc{incompatibleTokens=["Y","R","q","Q","L","w","I","D","i","e","c","t","T"];priority=110;parse(t,e,n){const i=t=>t-1;switch(e){case"M":return jc(Yc(wc,t),i);case"MM":return jc(Qc(2,t),i);case"Mo":return jc(n.ordinalNumber(t,{unit:"month"}),i);case"MMM":return n.month(t,{width:"abbreviated",context:"formatting"})||n.month(t,{width:"narrow",context:"formatting"});case"MMMMM":return n.month(t,{width:"narrow",context:"formatting"});default:return n.month(t,{width:"wide",context:"formatting"})||n.month(t,{width:"abbreviated",context:"formatting"})||n.month(t,{width:"narrow",context:"formatting"})}}validate(t,e){return e>=0&&e<=11}set(t,e,n){return t.setMonth(n,1),t.setHours(0,0,0,0),t}},L:new class extends vc{priority=110;parse(t,e,n){const i=t=>t-1;switch(e){case"L":return jc(Yc(wc,t),i);case"LL":return jc(Qc(2,t),i);case"Lo":return jc(n.ordinalNumber(t,{unit:"month"}),i);case"LLL":return n.month(t,{width:"abbreviated",context:"standalone"})||n.month(t,{width:"narrow",context:"standalone"});case"LLLLL":return n.month(t,{width:"narrow",context:"standalone"});default:return n.month(t,{width:"wide",context:"standalone"})||n.month(t,{width:"abbreviated",context:"standalone"})||n.month(t,{width:"narrow",context:"standalone"})}}validate(t,e){return e>=0&&e<=11}set(t,e,n){return t.setMonth(n,1),t.setHours(0,0,0,0),t}incompatibleTokens=["Y","R","q","Q","M","w","I","D","i","e","c","t","T"]},w:new class extends vc{priority=100;parse(t,e,n){switch(e){case"w":return Yc(Mc,t);case"wo":return n.ordinalNumber(t,{unit:"week"});default:return Qc(e.length,t)}}validate(t,e){return e>=1&&e<=53}set(t,e,n,i){return gr(function(t,e,n){const i=rr(t,n?.in),s=Hr(i,n)-e;return i.setDate(i.getDate()-7*s),rr(i,n?.in)}(t,n,i),i)}incompatibleTokens=["y","R","u","q","Q","M","L","I","d","D","i","t","T"]},I:new class extends vc{priority=100;parse(t,e,n){switch(e){case"I":return Yc(Mc,t);case"Io":return n.ordinalNumber(t,{unit:"week"});default:return Qc(e.length,t)}}validate(t,e){return e>=1&&e<=53}set(t,e,n){return pr(function(t,e,n){const i=rr(t,n?.in),s=qr(i,n)-e;return i.setDate(i.getDate()-7*s),i}(t,n))}incompatibleTokens=["y","Y","u","q","Q","M","L","w","d","D","e","c","t","T"]},d:new class extends vc{priority=90;subPriority=1;parse(t,e,n){switch(e){case"d":return Yc(Sc,t);case"do":return n.ordinalNumber(t,{unit:"date"});default:return Qc(e.length,t)}}validate(t,e){const n=Jc(t.getFullYear()),i=t.getMonth();return n?e>=1&&e<=el[i]:e>=1&&e<=tl[i]}set(t,e,n){return t.setDate(n),t.setHours(0,0,0,0),t}incompatibleTokens=["Y","R","q","Q","w","I","D","i","e","c","t","T"]},D:new class extends vc{priority=90;subpriority=1;parse(t,e,n){switch(e){case"D":case"DD":return Yc(kc,t);case"Do":return n.ordinalNumber(t,{unit:"date"});default:return Qc(e.length,t)}}validate(t,e){return Jc(t.getFullYear())?e>=1&&e<=366:e>=1&&e<=365}set(t,e,n){return t.setMonth(0,n),t.setHours(0,0,0,0),t}incompatibleTokens=["Y","R","q","Q","M","L","w","I","d","E","i","e","c","t","T"]},E:new class extends vc{priority=90;parse(t,e,n){switch(e){case"E":case"EE":case"EEE":return n.day(t,{width:"abbreviated",context:"formatting"})||n.day(t,{width:"short",context:"formatting"})||n.day(t,{width:"narrow",context:"formatting"});case"EEEEE":return n.day(t,{width:"narrow",context:"formatting"});case"EEEEEE":return n.day(t,{width:"short",context:"formatting"})||n.day(t,{width:"narrow",context:"formatting"});default:return n.day(t,{width:"wide",context:"formatting"})||n.day(t,{width:"abbreviated",context:"formatting"})||n.day(t,{width:"short",context:"formatting"})||n.day(t,{width:"narrow",context:"formatting"})}}validate(t,e){return e>=0&&e<=6}set(t,e,n,i){return(t=nl(t,n,i)).setHours(0,0,0,0),t}incompatibleTokens=["D","i","e","c","t","T"]},e:new class extends vc{priority=90;parse(t,e,n,i){const s=t=>{const e=7*Math.floor((t-1)/7);return(t+i.weekStartsOn+6)%7+e};switch(e){case"e":case"ee":return jc(Qc(e.length,t),s);case"eo":return jc(n.ordinalNumber(t,{unit:"day"}),s);case"eee":return n.day(t,{width:"abbreviated",context:"formatting"})||n.day(t,{width:"short",context:"formatting"})||n.day(t,{width:"narrow",context:"formatting"});case"eeeee":return n.day(t,{width:"narrow",context:"formatting"});case"eeeeee":return n.day(t,{width:"short",context:"formatting"})||n.day(t,{width:"narrow",context:"formatting"});default:return n.day(t,{width:"wide",context:"formatting"})||n.day(t,{width:"abbreviated",context:"formatting"})||n.day(t,{width:"short",context:"formatting"})||n.day(t,{width:"narrow",context:"formatting"})}}validate(t,e){return e>=0&&e<=6}set(t,e,n,i){return(t=nl(t,n,i)).setHours(0,0,0,0),t}incompatibleTokens=["y","R","u","q","Q","M","L","I","d","D","E","i","c","t","T"]},c:new class extends vc{priority=90;parse(t,e,n,i){const s=t=>{const e=7*Math.floor((t-1)/7);return(t+i.weekStartsOn+6)%7+e};switch(e){case"c":case"cc":return jc(Qc(e.length,t),s);case"co":return jc(n.ordinalNumber(t,{unit:"day"}),s);case"ccc":return n.day(t,{width:"abbreviated",context:"standalone"})||n.day(t,{width:"short",context:"standalone"})||n.day(t,{width:"narrow",context:"standalone"});case"ccccc":return n.day(t,{width:"narrow",context:"standalone"});case"cccccc":return n.day(t,{width:"short",context:"standalone"})||n.day(t,{width:"narrow",context:"standalone"});default:return n.day(t,{width:"wide",context:"standalone"})||n.day(t,{width:"abbreviated",context:"standalone"})||n.day(t,{width:"short",context:"standalone"})||n.day(t,{width:"narrow",context:"standalone"})}}validate(t,e){return e>=0&&e<=6}set(t,e,n,i){return(t=nl(t,n,i)).setHours(0,0,0,0),t}incompatibleTokens=["y","R","u","q","Q","M","L","I","d","D","E","i","e","t","T"]},i:new class extends vc{priority=90;parse(t,e,n){const i=t=>0===t?7:t;switch(e){case"i":case"ii":return Qc(e.length,t);case"io":return n.ordinalNumber(t,{unit:"day"});case"iii":return jc(n.day(t,{width:"abbreviated",context:"formatting"})||n.day(t,{width:"short",context:"formatting"})||n.day(t,{width:"narrow",context:"formatting"}),i);case"iiiii":return jc(n.day(t,{width:"narrow",context:"formatting"}),i);case"iiiiii":return jc(n.day(t,{width:"short",context:"formatting"})||n.day(t,{width:"narrow",context:"formatting"}),i);default:return jc(n.day(t,{width:"wide",context:"formatting"})||n.day(t,{width:"abbreviated",context:"formatting"})||n.day(t,{width:"short",context:"formatting"})||n.day(t,{width:"narrow",context:"formatting"}),i)}}validate(t,e){return e>=1&&e<=7}set(t,e,n){return(t=il(t,n)).setHours(0,0,0,0),t}incompatibleTokens=["y","Y","u","q","Q","M","L","w","d","D","E","e","c","t","T"]},a:new class extends vc{priority=80;parse(t,e,n){switch(e){case"a":case"aa":case"aaa":return n.dayPeriod(t,{width:"abbreviated",context:"formatting"})||n.dayPeriod(t,{width:"narrow",context:"formatting"});case"aaaaa":return n.dayPeriod(t,{width:"narrow",context:"formatting"});default:return n.dayPeriod(t,{width:"wide",context:"formatting"})||n.dayPeriod(t,{width:"abbreviated",context:"formatting"})||n.dayPeriod(t,{width:"narrow",context:"formatting"})}}set(t,e,n){return t.setHours(Gc(n),0,0,0),t}incompatibleTokens=["b","B","H","k","t","T"]},b:new class extends vc{priority=80;parse(t,e,n){switch(e){case"b":case"bb":case"bbb":return n.dayPeriod(t,{width:"abbreviated",context:"formatting"})||n.dayPeriod(t,{width:"narrow",context:"formatting"});case"bbbbb":return n.dayPeriod(t,{width:"narrow",context:"formatting"});default:return n.dayPeriod(t,{width:"wide",context:"formatting"})||n.dayPeriod(t,{width:"abbreviated",context:"formatting"})||n.dayPeriod(t,{width:"narrow",context:"formatting"})}}set(t,e,n){return t.setHours(Gc(n),0,0,0),t}incompatibleTokens=["a","B","H","k","t","T"]},B:new class extends vc{priority=80;parse(t,e,n){switch(e){case"B":case"BB":case"BBB":return n.dayPeriod(t,{width:"abbreviated",context:"formatting"})||n.dayPeriod(t,{width:"narrow",context:"formatting"});case"BBBBB":return n.dayPeriod(t,{width:"narrow",context:"formatting"});default:return n.dayPeriod(t,{width:"wide",context:"formatting"})||n.dayPeriod(t,{width:"abbreviated",context:"formatting"})||n.dayPeriod(t,{width:"narrow",context:"formatting"})}}set(t,e,n){return t.setHours(Gc(n),0,0,0),t}incompatibleTokens=["a","b","t","T"]},h:new class extends vc{priority=70;parse(t,e,n){switch(e){case"h":return Yc(Tc,t);case"ho":return n.ordinalNumber(t,{unit:"hour"});default:return Qc(e.length,t)}}validate(t,e){return e>=1&&e<=12}set(t,e,n){const i=t.getHours()>=12;return i&&n<12?t.setHours(n+12,0,0,0):i||12!==n?t.setHours(n,0,0,0):t.setHours(0,0,0,0),t}incompatibleTokens=["H","K","k","t","T"]},H:new class extends vc{priority=70;parse(t,e,n){switch(e){case"H":return Yc(Cc,t);case"Ho":return n.ordinalNumber(t,{unit:"hour"});default:return Qc(e.length,t)}}validate(t,e){return e>=0&&e<=23}set(t,e,n){return t.setHours(n,0,0,0),t}incompatibleTokens=["a","b","h","K","k","t","T"]},K:new class extends vc{priority=70;parse(t,e,n){switch(e){case"K":return Yc(Dc,t);case"Ko":return n.ordinalNumber(t,{unit:"hour"});default:return Qc(e.length,t)}}validate(t,e){return e>=0&&e<=11}set(t,e,n){return t.getHours()>=12&&n<12?t.setHours(n+12,0,0,0):t.setHours(n,0,0,0),t}incompatibleTokens=["h","H","k","t","T"]},k:new class extends vc{priority=70;parse(t,e,n){switch(e){case"k":return Yc(_c,t);case"ko":return n.ordinalNumber(t,{unit:"hour"});default:return Qc(e.length,t)}}validate(t,e){return e>=1&&e<=24}set(t,e,n){const i=n<=24?n%24:n;return t.setHours(i,0,0,0),t}incompatibleTokens=["a","b","h","H","K","t","T"]},m:new class extends vc{priority=60;parse(t,e,n){switch(e){case"m":return Yc(Pc,t);case"mo":return n.ordinalNumber(t,{unit:"minute"});default:return Qc(e.length,t)}}validate(t,e){return e>=0&&e<=59}set(t,e,n){return t.setMinutes(n,0,0),t}incompatibleTokens=["t","T"]},s:new class extends vc{priority=50;parse(t,e,n){switch(e){case"s":return Yc(Ec,t);case"so":return n.ordinalNumber(t,{unit:"second"});default:return Qc(e.length,t)}}validate(t,e){return e>=0&&e<=59}set(t,e,n){return t.setSeconds(n,0),t}incompatibleTokens=["t","T"]},S:new class extends vc{priority=30;parse(t,e){return jc(Qc(e.length,t),(t=>Math.trunc(t*Math.pow(10,3-e.length))))}set(t,e,n){return t.setMilliseconds(n),t}incompatibleTokens=["t","T"]},X:new class extends vc{priority=10;parse(t,e){switch(e){case"X":return Uc(Fc,t);case"XX":return Uc(qc,t);case"XXXX":return Uc(Bc,t);case"XXXXX":return Uc(Vc,t);default:return Uc(Hc,t)}}set(t,e,n){return e.timestampIsSet?t:ar(t,t.getTime()-fr(t)-n)}incompatibleTokens=["t","T","x"]},x:new class extends vc{priority=10;parse(t,e){switch(e){case"x":return Uc(Fc,t);case"xx":return Uc(qc,t);case"xxxx":return Uc(Bc,t);case"xxxxx":return Uc(Vc,t);default:return Uc(Hc,t)}}set(t,e,n){return e.timestampIsSet?t:ar(t,t.getTime()-fr(t)-n)}incompatibleTokens=["t","T","X"]},t:new class extends vc{priority=40;parse(t){return Xc(t)}set(t,e,n){return[ar(t,1e3*n),{timestampIsSet:!0}]}incompatibleTokens="*"},T:new class extends vc{priority=20;parse(t){return Xc(t)}set(t,e,n){return[ar(t,n),{timestampIsSet:!0}]}incompatibleTokens="*"}},ol=/[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g,al=/P+p+|P+|p+|''|'(''|[^'])+('|$)|./g,rl=/^'([^]*?)'?$/,cl=/''/g,ll=/\S/,dl=/[a-zA-Z]/;function hl(t,e,n,i){const s=()=>ar(i?.in||n,NaN),o=Object.assign({},ur()),a=i?.locale??o.locale??Fr,r=i?.firstWeekContainsDate??i?.locale?.options?.firstWeekContainsDate??o.firstWeekContainsDate??o.locale?.options?.firstWeekContainsDate??1,c=i?.weekStartsOn??i?.locale?.options?.weekStartsOn??o.weekStartsOn??o.locale?.options?.weekStartsOn??0;if(!e)return t?s():rr(n,i?.in);const l={firstWeekContainsDate:r,weekStartsOn:c,locale:a},d=[new xc(i?.in,n)],h=e.match(al).map((t=>{const e=t[0];if(e in sc){return(0,sc[e])(t,a.formatLong)}return t})).join("").match(ol),u=[];for(let n of h){!i?.useAdditionalWeekYearTokens&&lc(n)&&dc(n,e,t),!i?.useAdditionalDayOfYearTokens&&cc(n)&&dc(n,e,t);const o=n[0],r=sl[o];if(r){const{incompatibleTokens:e}=r;if(Array.isArray(e)){const t=u.find((t=>e.includes(t.token)||t.token===o));if(t)throw new RangeError(`The format string mustn't contain \`${t.fullToken}\` and \`${n}\` at the same time`)}else if("*"===r.incompatibleTokens&&u.length>0)throw new RangeError(`The format string mustn't contain \`${n}\` and any other token at the same time`);u.push({token:o,fullToken:n});const i=r.run(t,n,a.match,l);if(!i)return s();d.push(i.setter),t=i.rest}else{if(o.match(dl))throw new RangeError("Format string contains an unescaped latin alphabet character `"+o+"`");if("''"===n?n="'":"'"===o&&(n=n.match(rl)[1].replace(cl,"'")),0!==t.indexOf(n))return s();t=t.slice(n.length)}}if(t.length>0&&ll.test(t))return s();const g=d.map((t=>t.priority)).sort(((t,e)=>e-t)).filter(((t,e,n)=>n.indexOf(t)===e)).map((t=>d.filter((e=>e.priority===t)).sort(((t,e)=>e.subPriority-t.subPriority)))).map((t=>t[0]));let p=rr(n,i?.in);if(isNaN(+p))return s();const m={};for(const t of g){if(!t.validate(p,l))return s();const e=t.set(p,m,l);Array.isArray(e)?(p=e[0],Object.assign(m,e[1])):p=e}return p}function ul(t,e){const n=()=>ar(e?.in,NaN),i=e?.additionalDigits??2,s=function(t){const e={},n=t.split(gl.dateTimeDelimiter);let i;if(n.length>2)return e;/:/.test(n[0])?i=n[0]:(e.date=n[0],i=n[1],gl.timeZoneDelimiter.test(e.date)&&(e.date=t.split(gl.timeZoneDelimiter)[0],i=t.substr(e.date.length,t.length)));if(i){const t=gl.timezone.exec(i);t?(e.time=i.replace(t[1],""),e.timezone=t[1]):e.time=i}return e}(t);let o;if(s.date){const t=function(t,e){const n=new RegExp("^(?:(\\d{4}|[+-]\\d{"+(4+e)+"})|(\\d{2}|[+-]\\d{"+(2+e)+"})$)"),i=t.match(n);if(!i)return{year:NaN,restDateString:""};const s=i[1]?parseInt(i[1]):null,o=i[2]?parseInt(i[2]):null;return{year:null===o?s:100*o,restDateString:t.slice((i[1]||i[2]).length)}}(s.date,i);o=function(t,e){if(null===e)return new Date(NaN);const n=t.match(pl);if(!n)return new Date(NaN);const i=!!n[4],s=bl(n[1]),o=bl(n[2])-1,a=bl(n[3]),r=bl(n[4]),c=bl(n[5])-1;if(i)return function(t,e,n){return e>=1&&e<=53&&n>=0&&n<=6}(0,r,c)?function(t,e,n){const i=new Date(0);i.setUTCFullYear(t,0,4);const s=i.getUTCDay()||7,o=7*(e-1)+n+1-s;return i.setUTCDate(i.getUTCDate()+o),i}(e,r,c):new Date(NaN);{const t=new Date(0);return function(t,e,n){return e>=0&&e<=11&&n>=1&&n<=(xl[e]||(vl(t)?29:28))}(e,o,a)&&function(t,e){return e>=1&&e<=(vl(t)?366:365)}(e,s)?(t.setUTCFullYear(e,o,Math.max(s,a)),t):new Date(NaN)}}(t.restDateString,t.year)}if(!o||isNaN(+o))return n();const a=+o;let r,c=0;if(s.time&&(c=function(t){const e=t.match(ml);if(!e)return NaN;const n=yl(e[1]),i=yl(e[2]),s=yl(e[3]);if(!function(t,e,n){if(24===t)return 0===e&&0===n;return n>=0&&n<60&&e>=0&&e<60&&t>=0&&t<25}(n,i,s))return NaN;return n*sr+i*ir+1e3*s}(s.time),isNaN(c)))return n();if(!s.timezone){const t=new Date(a+c),n=rr(0,e?.in);return n.setFullYear(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate()),n.setHours(t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),t.getUTCMilliseconds()),n}return r=function(t){if("Z"===t)return 0;const e=t.match(fl);if(!e)return 0;const n="+"===e[1]?-1:1,i=parseInt(e[2]),s=e[3]&&parseInt(e[3])||0;if(!function(t,e){return e>=0&&e<=59}
|
|
21
21
|
/*!
|
|
22
22
|
* chartjs-adapter-date-fns v3.0.0
|
|
23
23
|
* https://www.chartjs.org
|
|
24
24
|
* (c) 2022 chartjs-adapter-date-fns Contributors
|
|
25
25
|
* Released under the MIT license
|
|
26
|
-
*/(0,s))return NaN;return n*(i*sr+s*ir)}(s.timezone),isNaN(r)?n():rr(a+c+r,e?.in)}const gl={dateTimeDelimiter:/[T ]/,timeZoneDelimiter:/[Z ]/i,timezone:/([Z+-].*)$/},pl=/^-?(?:(\d{3})|(\d{2})(?:-?(\d{2}))?|W(\d{2})(?:-?(\d{1}))?|)$/,ml=/^(\d{2}(?:[.,]\d*)?)(?::?(\d{2}(?:[.,]\d*)?))?(?::?(\d{2}(?:[.,]\d*)?))?$/,fl=/^([+-])(\d{2})(?::?(\d{2}))?$/;function bl(t){return t?parseInt(t):1}function yl(t){return t&&parseFloat(t.replace(",","."))||0}const xl=[31,null,31,30,31,30,31,31,30,31,30,31];function vl(t){return t%400==0||t%4==0&&t%100!=0}const wl={datetime:"MMM d, yyyy, h:mm:ss aaaa",millisecond:"h:mm:ss.SSS aaaa",second:"h:mm:ss aaaa",minute:"h:mm aaaa",hour:"ha",day:"MMM d",week:"PP",month:"MMM yyyy",quarter:"qqq - yyyy",year:"yyyy"};Ai._date.override({_id:"date-fns",formats:function(){return wl},parse:function(t,e){if(null==t)return null;const n=typeof t;return"number"===n||t instanceof Date?t=rr(t):"string"===n&&(t="string"==typeof e?hl(t,e,new Date,this.options):ul(t,this.options)),wr(t)?t.getTime():null},format:function(t,e){return function(t,e,n){const i=ur(),s=n?.locale??i.locale??Fr,o=n?.firstWeekContainsDate??n?.locale?.options?.firstWeekContainsDate??i.firstWeekContainsDate??i.locale?.options?.firstWeekContainsDate??1,a=n?.weekStartsOn??n?.locale?.options?.weekStartsOn??i.weekStartsOn??i.locale?.options?.weekStartsOn??0,r=rr(t,n?.in);if(!wr(r))throw new RangeError("Invalid time value");let c=e.match(uc).map((t=>{const e=t[0];return"p"===e||"P"===e?(0,sc[e])(t,s.formatLong):t})).join("").match(hc).map((t=>{if("''"===t)return{isToken:!1,value:"'"};const e=t[0];if("'"===e)return{isToken:!1,value:fc(t)};if(
|
|
26
|
+
*/(0,s))return NaN;return n*(i*sr+s*ir)}(s.timezone),isNaN(r)?n():rr(a+c+r,e?.in)}const gl={dateTimeDelimiter:/[T ]/,timeZoneDelimiter:/[Z ]/i,timezone:/([Z+-].*)$/},pl=/^-?(?:(\d{3})|(\d{2})(?:-?(\d{2}))?|W(\d{2})(?:-?(\d{1}))?|)$/,ml=/^(\d{2}(?:[.,]\d*)?)(?::?(\d{2}(?:[.,]\d*)?))?(?::?(\d{2}(?:[.,]\d*)?))?$/,fl=/^([+-])(\d{2})(?::?(\d{2}))?$/;function bl(t){return t?parseInt(t):1}function yl(t){return t&&parseFloat(t.replace(",","."))||0}const xl=[31,null,31,30,31,30,31,31,30,31,30,31];function vl(t){return t%400==0||t%4==0&&t%100!=0}const wl={datetime:"MMM d, yyyy, h:mm:ss aaaa",millisecond:"h:mm:ss.SSS aaaa",second:"h:mm:ss aaaa",minute:"h:mm aaaa",hour:"ha",day:"MMM d",week:"PP",month:"MMM yyyy",quarter:"qqq - yyyy",year:"yyyy"};Ai._date.override({_id:"date-fns",formats:function(){return wl},parse:function(t,e){if(null==t)return null;const n=typeof t;return"number"===n||t instanceof Date?t=rr(t):"string"===n&&(t="string"==typeof e?hl(t,e,new Date,this.options):ul(t,this.options)),wr(t)?t.getTime():null},format:function(t,e){return function(t,e,n){const i=ur(),s=n?.locale??i.locale??Fr,o=n?.firstWeekContainsDate??n?.locale?.options?.firstWeekContainsDate??i.firstWeekContainsDate??i.locale?.options?.firstWeekContainsDate??1,a=n?.weekStartsOn??n?.locale?.options?.weekStartsOn??i.weekStartsOn??i.locale?.options?.weekStartsOn??0,r=rr(t,n?.in);if(!wr(r))throw new RangeError("Invalid time value");let c=e.match(uc).map((t=>{const e=t[0];return"p"===e||"P"===e?(0,sc[e])(t,s.formatLong):t})).join("").match(hc).map((t=>{if("''"===t)return{isToken:!1,value:"'"};const e=t[0];if("'"===e)return{isToken:!1,value:fc(t)};if(Zr[e])return{isToken:!0,value:t};if(e.match(mc))throw new RangeError("Format string contains an unescaped latin alphabet character `"+e+"`");return{isToken:!1,value:t}}));s.localize.preprocessor&&(c=s.localize.preprocessor(r,c));const l={firstWeekContainsDate:o,weekStartsOn:a,locale:s};return c.map((i=>{if(!i.isToken)return i.value;const o=i.value;return(!n?.useAdditionalWeekYearTokens&&lc(o)||!n?.useAdditionalDayOfYearTokens&&cc(o))&&dc(o,e,String(t)),(0,Zr[o[0]])(r,o,s.localize,l)})).join("")}(t,e,this.options)},add:function(t,e,n){switch(n){case"millisecond":return dr(t,e);case"second":return function(t,e,n){return dr(t,1e3*e,n)}(t,e);case"minute":return function(t,e,n){const i=rr(t,n?.in);return i.setTime(i.getTime()+e*ir),i}(t,e);case"hour":return function(t,e,n){return dr(t,e*sr,n)}(t,e);case"day":return cr(t,e);case"week":return function(t,e,n){return cr(t,7*e,n)}(t,e);case"month":return lr(t,e);case"quarter":return function(t,e,n){return lr(t,3*e,n)}(t,e);case"year":return function(t,e,n){return lr(t,12*e,n)}(t,e);default:return t}},diff:function(t,e,n){switch(n){case"millisecond":return Cr(t,e);case"second":return function(t,e,n){const i=Cr(t,e)/1e3;return Mr(n?.roundingMethod)(i)}(t,e);case"minute":return function(t,e,n){const i=Cr(t,e)/ir;return Mr(n?.roundingMethod)(i)}(t,e);case"hour":return function(t,e,n){const[i,s]=br(n?.in,t,e),o=(+i-+s)/sr;return Mr(n?.roundingMethod)(o)}(t,e);case"day":return Sr(t,e);case"week":return function(t,e,n){const i=Sr(t,e,n)/7;return Mr(n?.roundingMethod)(i)}(t,e);case"month":return Tr(t,e);case"quarter":return function(t,e,n){const i=Tr(t,e,n)/3;return Mr(n?.roundingMethod)(i)}(t,e);case"year":return Pr(t,e);default:return 0}},startOf:function(t,e,n){switch(e){case"second":return function(t,e){const n=rr(t,e?.in);return n.setMilliseconds(0),n}(t);case"minute":return function(t,e){const n=rr(t,e?.in);return n.setSeconds(0,0),n}(t);case"hour":return function(t,e){const n=rr(t,e?.in);return n.setMinutes(0,0,0),n}(t);case"day":return yr(t);case"week":return gr(t);case"isoWeek":return gr(t,{weekStartsOn:+n});case"month":return function(t,e){const n=rr(t,e?.in);return n.setDate(1),n.setHours(0,0,0,0),n}(t);case"quarter":return function(t,e){const n=rr(t,e?.in),i=n.getMonth(),s=i-i%3;return n.setMonth(s,1),n.setHours(0,0,0,0),n}(t);case"year":return Er(t);default:return t}},endOf:function(t,e){switch(e){case"second":return function(t,e){const n=rr(t,e?.in);return n.setMilliseconds(999),n}(t);case"minute":return function(t,e){const n=rr(t,e?.in);return n.setSeconds(59,999),n}(t);case"hour":return function(t,e){const n=rr(t,e?.in);return n.setMinutes(59,59,999),n}(t);case"day":return _r(t);case"week":return function(t,e){const n=ur(),i=e?.weekStartsOn??e?.locale?.options?.weekStartsOn??n.weekStartsOn??n.locale?.options?.weekStartsOn??0,s=rr(t,e?.in),o=s.getDay(),a=6+(o<i?-7:0)-(o-i);return s.setDate(s.getDate()+a),s.setHours(23,59,59,999),s}(t);case"month":return Dr(t);case"quarter":return function(t,e){const n=rr(t,e?.in),i=n.getMonth(),s=i-i%3+3;return n.setMonth(s,0),n.setHours(23,59,59,999),n}(t);case"year":return function(t,e){const n=rr(t,e?.in),i=n.getFullYear();return n.setFullYear(i+1,0,0),n.setHours(23,59,59,999),n}(t);default:return t}}});
|
|
27
27
|
/*!
|
|
28
28
|
* chartjs-plugin-annotation v3.1.0
|
|
29
29
|
* https://www.chartjs.org/chartjs-plugin-annotation/index
|
|
30
30
|
* (c) 2024 chartjs-plugin-annotation Contributors
|
|
31
31
|
* Released under the MIT License
|
|
32
32
|
*/
|
|
33
|
-
const Sl={modes:{point:(t,e)=>Ml(t,e,{intersect:!0}),nearest:(t,e,n)=>function(t,e,n){let i=Number.POSITIVE_INFINITY;return Ml(t,e,n).reduce(((t,s)=>{const o=s.getCenterPoint(),a=function(t,e,n){if("x"===n)return{x:t.x,y:e.y};if("y"===n)return{x:e.x,y:t.y};return e}(e,o,n.axis),r=Kt(e,a);return r<i?(t=[s],i=r):r===i&&t.push(s),t}),[]).sort(((t,e)=>t._index-e._index)).slice(0,1)}(t,e,n),x:(t,e,n)=>Ml(t,e,{intersect:n.intersect,axis:"x"}),y:(t,e,n)=>Ml(t,e,{intersect:n.intersect,axis:"y"})}};function kl(t,e,n){return(Sl.modes[n.mode]||Sl.modes.nearest)(t,e,n)}function Ml(t,e,n){return t.filter((t=>n.intersect?t.inRange(e.x,e.y):function(t,e,n){return"x"!==n&&"y"!==n?t.inRange(e.x,e.y,"x",!0)||t.inRange(e.x,e.y,"y",!0):t.inRange(e.x,e.y,n,!0)}(t,e,n.axis)))}function _l(t,e,n){const i=Math.cos(n),s=Math.sin(n),o=e.x,a=e.y;return{x:o+i*(t.x-o)-s*(t.y-a),y:a+s*(t.x-o)+i*(t.y-a)}}const Cl=(t,e)=>e>t||t.length>e.length&&t.slice(0,e.length)===e,Tl=.001,Dl=(t,e,n)=>Math.min(n,Math.max(e,t)),Pl=(t,e)=>t.value>=t.start-e&&t.value<=t.end+e;function El(t,e,n){for(const i of Object.keys(t))t[i]=Dl(t[i],e,n);return t}function Al(t,{x:e,y:n,x2:i,y2:s},o,{borderWidth:a,hitTolerance:r}){const c=(a+r)/2,l=t.x>=e-c-Tl&&t.x<=i+c+Tl,d=t.y>=n-c-Tl&&t.y<=s+c+Tl;return"x"===o?l:("y"===o||l)&&d}function Ll(t,{rect:e,center:n},i,{rotation:s,borderWidth:o,hitTolerance:a}){return Al(_l(t,n,Yt(-s)),e,i,{borderWidth:o,hitTolerance:a})}function Il(t,e){const{centerX:n,centerY:i}=t.getProps(["centerX","centerY"],e);return{x:n,y:i}}const Ol=t=>"string"==typeof t&&t.endsWith("%"),zl=t=>parseFloat(t)/100,Wl=t=>Dl(zl(t),0,1),Nl=(t,e)=>({x:t,y:e,x2:t,y2:e,width:0,height:0}),Rl={box:t=>Nl(t.centerX,t.centerY),doughnutLabel:t=>Nl(t.centerX,t.centerY),ellipse:t=>({centerX:t.centerX,centerY:t.centerX,radius:0,width:0,height:0}),label:t=>Nl(t.centerX,t.centerY),line:t=>Nl(t.x,t.y),point:t=>({centerX:t.centerX,centerY:t.centerY,radius:0,width:0,height:0}),polygon:t=>Nl(t.centerX,t.centerY)};function $l(t,e){return"start"===e?0:"end"===e?t:Ol(e)?Wl(e)*t:t/2}function Fl(t,e,n=!0){return"number"==typeof e?e:Ol(e)?(n?Wl(e):zl(e))*t:t}function ql(t,e,{borderWidth:n,position:i,xAdjust:s,yAdjust:o},a){const r=ut(a),c=e.width+(r?a.width:0)+n,l=e.height+(r?a.height:0)+n,d=Bl(i),h=Yl(t.x,c,s,d.x),u=Yl(t.y,l,o,d.y);return{x:h,y:u,x2:h+c,y2:u+l,width:c,height:l,centerX:h+c/2,centerY:u+l/2}}function Bl(t,e="center"){return ut(t)?{x:mt(t.x,e),y:mt(t.y,e)}:{x:t=mt(t,e),y:t}}const Hl=(t,e)=>t&&t.autoFit&&e<1;function Vl(t,e){const n=t.font,i=ht(n)?n:[n];return Hl(t,e)?i.map((function(t){const n=en(t);return n.size=Math.floor(t.size*e),n.lineHeight=t.lineHeight,en(n)})):i.map((t=>en(t)))}function jl(t){return t&&(Pt(t.xValue)||Pt(t.yValue))}function Yl(t,e,n=0,i){return t-$l(e,i)+n}function Ul(t,e,n){const i=n.init;if(i)return!0===i?Ql(e,n):function(t,e,n){const i=bt(n.init,[{chart:t,properties:e,options:n}]);if(!0===i)return Ql(e,n);if(ut(i))return i}(t,e,n)}function Xl(t,e,n){let i=!1;return e.forEach((e=>{Et(t[e])?(i=!0,n[e]=t[e]):Pt(n[e])&&delete n[e]})),i}function Ql(t,e){const n=e.type||"line";return Rl[n](t)}const Kl=new Map;function Zl(t){if(t&&"object"==typeof t){const e=t.toString();return"[object HTMLImageElement]"===e||"[object HTMLCanvasElement]"===e}}function Gl(t,{x:e,y:n},i){i&&(t.translate(e,n),t.rotate(Yt(i)),t.translate(-e,-n))}function Jl(t,e){if(e&&e.borderWidth)return t.lineCap=e.borderCapStyle||"butt",t.setLineDash(e.borderDash),t.lineDashOffset=e.borderDashOffset,t.lineJoin=e.borderJoinStyle||"miter",t.lineWidth=e.borderWidth,t.strokeStyle=e.borderColor,!0}function td(t,e){t.shadowColor=e.backgroundShadowColor,t.shadowBlur=e.shadowBlur,t.shadowOffsetX=e.shadowOffsetX,t.shadowOffsetY=e.shadowOffsetY}function ed(t,e){const n=e.content;if(Zl(n)){return{width:Fl(n.width,e.width),height:Fl(n.height,e.height)}}const i=Vl(e),s=e.textStrokeWidth,o=ht(n)?n:[n],a=o.join()+(t=>t.reduce((function(t,e){return t+e.string}),""))(i)+s+(t._measureText?"-spriting":"");return Kl.has(a)||Kl.set(a,function(t,e,n,i){t.save();const s=e.length;let o=0,a=i;for(let r=0;r<s;r++){const s=n[Math.min(r,n.length-1)];t.font=s.string;const c=e[r];o=Math.max(o,t.measureText(c).width+i),a+=s.lineHeight}return t.restore(),{width:o,height:a}}(t,o,i,s)),Kl.get(a)}function nd(t,e,n){const{x:i,y:s,width:o,height:a}=e;t.save(),td(t,n);const r=Jl(t,n);t.fillStyle=n.backgroundColor,t.beginPath(),Ue(t,{x:i,y:s,w:o,h:a,radius:El(Je(n.borderRadius),0,Math.min(o,a)/2)}),t.closePath(),t.fill(),r&&(t.shadowColor=n.borderShadowColor,t.stroke()),t.restore()}function id(t,e,n,i){const s=n.content;if(Zl(s))return t.save(),t.globalAlpha=function(t,e){const n=Vt(t)?t:e;return Vt(n)?Dl(n,0,1):1}(n.opacity,s.style.opacity),t.drawImage(s,e.x,e.y,e.width,e.height),void t.restore();const o=ht(s)?s:[s],a=Vl(n,i),r=n.color,c=ht(r)?r:[r],l=function(t,e){const{x:n,width:i}=t,s=e.textAlign;return"center"===s?n+i/2:"end"===s||"right"===s?n+i:n}(e,n),d=e.y+n.textStrokeWidth/2;t.save(),t.textBaseline="middle",t.textAlign=n.textAlign,function(t,e){if(e.textStrokeWidth>0)return t.lineJoin="round",t.miterLimit=2,t.lineWidth=e.textStrokeWidth,t.strokeStyle=e.textStrokeColor,!0}(t,n)&&function(t,{x:e,y:n},i,s){t.beginPath();let o=0;i.forEach((function(i,a){const r=s[Math.min(a,s.length-1)],c=r.lineHeight;t.font=r.string,t.strokeText(i,e,n+c/2+o),o+=c})),t.stroke()}(t,{x:l,y:d},o,a),function(t,{x:e,y:n},i,{fonts:s,colors:o}){let a=0;i.forEach((function(i,r){const c=o[Math.min(r,o.length-1)],l=s[Math.min(r,s.length-1)],d=l.lineHeight;t.beginPath(),t.font=l.string,t.fillStyle=c,t.fillText(i,e,n+d/2+a),a+=d,t.fill()}))}(t,{x:l,y:d},o,{fonts:a,colors:c}),t.restore()}function sd(t,e,n,i){const{radius:s,options:o}=e,a=o.pointStyle,r=o.rotation;let c=(r||0)*Wt;if(Zl(a))return t.save(),t.translate(n,i),t.rotate(c),t.drawImage(a,-a.width/2,-a.height/2,a.width,a.height),void t.restore();(t=>isNaN(t)||t<=0)(s)||function(t,{x:e,y:n,radius:i,rotation:s,style:o,rad:a}){let r,c,l,d;switch(t.beginPath(),o){default:t.arc(e,n,i,0,It),t.closePath();break;case"triangle":t.moveTo(e+Math.sin(a)*i,n-Math.cos(a)*i),a+=$t,t.lineTo(e+Math.sin(a)*i,n-Math.cos(a)*i),a+=$t,t.lineTo(e+Math.sin(a)*i,n-Math.cos(a)*i),t.closePath();break;case"rectRounded":d=.516*i,l=i-d,r=Math.cos(a+Rt)*l,c=Math.sin(a+Rt)*l,t.arc(e-r,n-c,d,a-Lt,a-Nt),t.arc(e+c,n-r,d,a-Nt,a),t.arc(e+r,n+c,d,a,a+Nt),t.arc(e-c,n+r,d,a+Nt,a+Lt),t.closePath();break;case"rect":if(!s){l=Math.SQRT1_2*i,t.rect(e-l,n-l,2*l,2*l);break}a+=Rt;case"rectRot":r=Math.cos(a)*i,c=Math.sin(a)*i,t.moveTo(e-r,n-c),t.lineTo(e+c,n-r),t.lineTo(e+r,n+c),t.lineTo(e-c,n+r),t.closePath();break;case"crossRot":a+=Rt;case"cross":r=Math.cos(a)*i,c=Math.sin(a)*i,t.moveTo(e-r,n-c),t.lineTo(e+r,n+c),t.moveTo(e+c,n-r),t.lineTo(e-c,n+r);break;case"star":r=Math.cos(a)*i,c=Math.sin(a)*i,t.moveTo(e-r,n-c),t.lineTo(e+r,n+c),t.moveTo(e+c,n-r),t.lineTo(e-c,n+r),a+=Rt,r=Math.cos(a)*i,c=Math.sin(a)*i,t.moveTo(e-r,n-c),t.lineTo(e+r,n+c),t.moveTo(e+c,n-r),t.lineTo(e-c,n+r);break;case"line":r=Math.cos(a)*i,c=Math.sin(a)*i,t.moveTo(e-r,n-c),t.lineTo(e+r,n+c);break;case"dash":t.moveTo(e,n),t.lineTo(e+Math.cos(a)*i,n+Math.sin(a)*i)}t.fill()}(t,{x:n,y:i,radius:s,rotation:r,style:a,rad:c})}const od=["left","bottom","top","right"];function ad(t,e){const{pointX:n,pointY:i,options:s}=e,o=s.callout,a=o&&o.display&&function(t,e){const n=e.position;if(od.includes(n))return n;return function(t,e){const{x:n,y:i,x2:s,y2:o,width:a,height:r,pointX:c,pointY:l,centerX:d,centerY:h,rotation:u}=t,g={x:d,y:h},p=e.start,m=Fl(a,p),f=Fl(r,p),b=[n,n+m,n+m,s],y=[i+f,o,i,o],x=[];for(let t=0;t<4;t++){const e=_l({x:b[t],y:y[t]},g,Yt(u));x.push({position:od[t],distance:Kt(e,{x:c,y:l})})}return x.sort(((t,e)=>t.distance-e.distance))[0].position}(t,e)}(e,o);if(!a||function(t,e,n){const{pointX:i,pointY:s}=t,o=e.margin;let a=i,r=s;"left"===n?a+=o:"right"===n?a-=o:"top"===n?r+=o:"bottom"===n&&(r-=o);return t.inRange(a,r)}(e,o,a))return;t.save(),t.beginPath();if(!Jl(t,o))return t.restore();const{separatorStart:r,separatorEnd:c}=function(t,e){const{x:n,y:i,x2:s,y2:o}=t,a=function(t,e){const{width:n,height:i,options:s}=t,o=s.callout.margin+s.borderWidth/2;if("right"===e)return n+o;if("bottom"===e)return i+o;return-o}(t,e);let r,c;"left"===e||"right"===e?(r={x:n+a,y:i},c={x:r.x,y:o}):(r={x:n,y:i+a},c={x:s,y:r.y});return{separatorStart:r,separatorEnd:c}}(e,a),{sideStart:l,sideEnd:d}=function(t,e,n){const{y:i,width:s,height:o,options:a}=t,r=a.callout.start,c=function(t,e){const n=e.side;if("left"===t||"top"===t)return-n;return n}(e,a.callout);let l,d;"left"===e||"right"===e?(l={x:n.x,y:i+Fl(o,r)},d={x:l.x+c,y:l.y}):(l={x:n.x+Fl(s,r),y:n.y},d={x:l.x,y:l.y+c});return{sideStart:l,sideEnd:d}}(e,a,r);(o.margin>0||0===s.borderWidth)&&(t.moveTo(r.x,r.y),t.lineTo(c.x,c.y)),t.moveTo(l.x,l.y),t.lineTo(d.x,d.y);const h=_l({x:n,y:i},e.getCenterPoint(),Yt(-e.rotation));t.lineTo(h.x,h.y),t.stroke(),t.restore()}const rd={xScaleID:{min:"xMin",max:"xMax",start:"left",end:"right",startProp:"x",endProp:"x2"},yScaleID:{min:"yMin",max:"yMax",start:"bottom",end:"top",startProp:"y",endProp:"y2"}};function cd(t,e,n){return gt(e="number"==typeof e?e:t.parse(e))?t.getPixelForValue(e):n}function ld(t,e,n){const i=e[n];if(i||"scaleID"===n)return i;const s=n.charAt(0),o=Object.values(t).filter((t=>t.axis&&t.axis===s));return o.length?o[0].id:s}function dd(t,e){if(t){const n=t.options.reverse;return{start:cd(t,e.min,n?e.end:e.start),end:cd(t,e.max,n?e.start:e.end)}}}function hd(t,e){const{chartArea:n,scales:i}=t,s=i[ld(i,e,"xScaleID")],o=i[ld(i,e,"yScaleID")];let a=n.width/2,r=n.height/2;return s&&(a=cd(s,e.xValue,s.left+s.width/2)),o&&(r=cd(o,e.yValue,o.top+o.height/2)),{x:a,y:r}}function ud(t,e){const n=t.scales,i=n[ld(n,e,"xScaleID")],s=n[ld(n,e,"yScaleID")];if(!i&&!s)return{};let{left:o,right:a}=i||t.chartArea,{top:r,bottom:c}=s||t.chartArea;const l=fd(i,{min:e.xMin,max:e.xMax,start:o,end:a});o=l.start,a=l.end;const d=fd(s,{min:e.yMin,max:e.yMax,start:c,end:r});return r=d.start,c=d.end,{x:o,y:r,x2:a,y2:c,width:a-o,height:c-r,centerX:o+(a-o)/2,centerY:r+(c-r)/2}}function gd(t,e){if(!jl(e)){const n=ud(t,e);let i=e.radius;i&&!isNaN(i)||(i=Math.min(n.width,n.height)/2,e.radius=i);const s=2*i,o=n.centerX+e.xAdjust,a=n.centerY+e.yAdjust;return{x:o-i,y:a-i,x2:o+i,y2:a+i,centerX:o,centerY:a,width:s,height:s,radius:i}}return function(t,e){const n=hd(t,e),i=2*e.radius;return{x:n.x-e.radius+e.xAdjust,y:n.y-e.radius+e.yAdjust,x2:n.x+e.radius+e.xAdjust,y2:n.y+e.radius+e.yAdjust,centerX:n.x+e.xAdjust,centerY:n.y+e.yAdjust,radius:e.radius,width:i,height:i}}(t,e)}function pd(t,e){const{scales:n,chartArea:i}=t,s=n[e.scaleID],o={x:i.left,y:i.top,x2:i.right,y2:i.bottom};return s?function(t,e,n){const i=cd(t,n.value,NaN),s=cd(t,n.endValue,i);t.isHorizontal()?(e.x=i,e.x2=s):(e.y=i,e.y2=s)}(s,o,e):function(t,e,n){for(const i of Object.keys(rd)){const s=t[ld(t,n,i)];if(s){const{min:t,max:o,start:a,end:r,startProp:c,endProp:l}=rd[i],d=dd(s,{min:n[t],max:n[o],start:s[a],end:s[r]});e[c]=d.start,e[l]=d.end}}}(n,o,e),o}function md(t,e){const n=ud(t,e);return n.initProperties=Ul(t,n,e),n.elements=[{type:"label",optionScope:"label",properties:yd(t,n,e),initProperties:n.initProperties}],n}function fd(t,e){const n=dd(t,e)||e;return{start:Math.min(n.start,n.end),end:Math.max(n.start,n.end)}}function bd(t,e){const{start:n,end:i,borderWidth:s}=t,{position:o,padding:{start:a,end:r},adjust:c}=e;return n+s/2+c+$l(i-s-n-a-r-e.size,o)}function yd(t,e,n){const i=n.label;i.backgroundColor="transparent",i.callout.display=!1;const s=Bl(i.position),o=tn(i.padding),a=ed(t.ctx,i),r=function({properties:t,options:e},n,i,s){const{x:o,x2:a,width:r}=t;return bd({start:o,end:a,size:r,borderWidth:e.borderWidth},{position:i.x,padding:{start:s.left,end:s.right},adjust:e.label.xAdjust,size:n.width})}({properties:e,options:n},a,s,o),c=function({properties:t,options:e},n,i,s){const{y:o,y2:a,height:r}=t;return bd({start:o,end:a,size:r,borderWidth:e.borderWidth},{position:i.y,padding:{start:s.top,end:s.bottom},adjust:e.label.yAdjust,size:n.height})}({properties:e,options:n},a,s,o),l=a.width+o.width,d=a.height+o.height;return{x:r,y:c,x2:r+l,y2:c+d,width:l,height:d,centerX:r+l/2,centerY:c+d/2,rotation:i.rotation}}const xd=["enter","leave"],vd=xd.concat("click");function wd(t,e,n){if(t.listened)switch(e.type){case"mousemove":case"mouseout":return function(t,e,n){if(!t.moveListened)return;let i;i="mousemove"===e.type?kl(t.visibleElements,e,n.interaction):[];const s=t.hovered;t.hovered=i;const o={state:t,event:e};let a=Sd(o,"leave",s,i);return Sd(o,"enter",i,s)||a}(t,e,n);case"click":return function(t,e,n){const i=t.listeners,s=kl(t.visibleElements,e,n.interaction);let o;for(const t of s)o=kd(t.options.click||i.click,t,e)||o;return o}(t,e,n)}}function Sd({state:t,event:e},n,i,s){let o;for(const a of i)s.indexOf(a)<0&&(o=kd(a.options[n]||t.listeners[n],a,e)||o);return o}function kd(t,e,n){return!0===bt(t,[e.$context,n])}const Md=["afterDraw","beforeDraw"];function _d(t,e,n){if(t.hooked){return bt(e.options[n]||t.hooks[n],[e.$context])}}function Cd(t,e,n){const i=function(t,e,n){const i=e.axis,s=e.id,o=i+"ScaleID",a={min:mt(e.min,Number.NEGATIVE_INFINITY),max:mt(e.max,Number.POSITIVE_INFINITY)};for(const r of n)r.scaleID===s?Ed(r,e,["value","endValue"],a):ld(t,r,o)===s&&Ed(r,e,[i+"Min",i+"Max",i+"Value"],a);return a}(t.scales,e,n);let s=Td(e,i,"min","suggestedMin");s=Td(e,i,"max","suggestedMax")||s,s&&Et(e.handleTickRangeOptions)&&e.handleTickRangeOptions()}function Td(t,e,n,i){if(gt(e[n])&&!function(t,e,n){return Pt(t[e])||Pt(t[n])}(t.options,n,i)){const i=t[n]!==e[n];return t[n]=e[n],i}}function Dd(t,e){for(const n of["scaleID","xScaleID","yScaleID"]){const i=ld(e,t,n);i&&!e[i]&&Pd(t,n)&&console.warn(`No scale found with id '${i}' for annotation '${t.id}'`)}}function Pd(t,e){if("scaleID"===e)return!0;const n=e.charAt(0);for(const e of["Min","Max","Value"])if(Pt(t[n+e]))return!0;return!1}function Ed(t,e,n,i){for(const s of n){const n=t[s];if(Pt(n)){const t=e.parse(n);i.min=Math.min(i.min,t),i.max=Math.max(i.max,t)}}}class Ad extends ms{inRange(t,e,n,i){const{x:s,y:o}=_l({x:t,y:e},this.getCenterPoint(i),Yt(-this.options.rotation));return Al({x:s,y:o},this.getProps(["x","y","x2","y2"],i),n,this.options)}getCenterPoint(t){return Il(this,t)}draw(t){t.save(),Gl(t,this.getCenterPoint(),this.options.rotation),nd(t,this,this.options),t.restore()}get label(){return this.elements&&this.elements[0]}resolveElementProperties(t,e){return md(t,e)}}Ad.id="boxAnnotation",Ad.defaults={adjustScaleRange:!0,backgroundShadowColor:"transparent",borderCapStyle:"butt",borderDash:[],borderDashOffset:0,borderJoinStyle:"miter",borderRadius:0,borderShadowColor:"transparent",borderWidth:1,display:!0,init:void 0,hitTolerance:0,label:{backgroundColor:"transparent",borderWidth:0,callout:{display:!1},color:"black",content:null,display:!1,drawTime:void 0,font:{family:void 0,lineHeight:void 0,size:void 0,style:void 0,weight:"bold"},height:void 0,hitTolerance:void 0,opacity:void 0,padding:6,position:"center",rotation:void 0,textAlign:"start",textStrokeColor:void 0,textStrokeWidth:0,width:void 0,xAdjust:0,yAdjust:0,z:void 0},rotation:0,shadowBlur:0,shadowOffsetX:0,shadowOffsetY:0,xMax:void 0,xMin:void 0,xScaleID:void 0,yMax:void 0,yMin:void 0,yScaleID:void 0,z:0},Ad.defaultRoutes={borderColor:"color",backgroundColor:"color"},Ad.descriptors={label:{_fallback:!0}};class Ld extends ms{inRange(t,e,n,i){return Ll({x:t,y:e},{rect:this.getProps(["x","y","x2","y2"],i),center:this.getCenterPoint(i)},n,{rotation:this.rotation,borderWidth:0,hitTolerance:this.options.hitTolerance})}getCenterPoint(t){return Il(this,t)}draw(t){const e=this.options;e.display&&e.content&&(!function(t,e){const{_centerX:n,_centerY:i,_radius:s,_startAngle:o,_endAngle:a,_counterclockwise:r,options:c}=e;t.save();const l=Jl(t,c);t.fillStyle=c.backgroundColor,t.beginPath(),t.arc(n,i,s,o,a,r),t.closePath(),t.fill(),l&&t.stroke();t.restore()}(t,this),t.save(),Gl(t,this.getCenterPoint(),this.rotation),id(t,this,e,this._fitRatio),t.restore())}resolveElementProperties(t,e){const n=function(t,e){return t.getSortedVisibleDatasetMetas().reduce((function(n,i){const s=i.controller;return s instanceof Ci&&function(t,e,n){if(!e.autoHide)return!0;for(let e=0;e<n.length;e++)if(!n[e].hidden&&t.getDataVisibility(e))return!0}(t,e,i.data)&&(!n||s.innerRadius<n.controller.innerRadius)&&s.options.circumference>=90?i:n}),void 0)}(t,e);if(!n)return{};const{controllerMeta:i,point:s,radius:o}=function({chartArea:t},e,n){const{left:i,top:s,right:o,bottom:a}=t,{innerRadius:r,offsetX:c,offsetY:l}=n.controller,d=(i+o)/2+c,h=(s+a)/2+l,u={left:Math.max(d-r,i),right:Math.min(d+r,o),top:Math.max(h-r,s),bottom:Math.min(h+r,a)},g={x:(u.left+u.right)/2,y:(u.top+u.bottom)/2},p=e.spacing+e.borderWidth/2,m=r-p,f=g.y>h,b=function(t,e,n,i){const s=Math.pow(n-t,2),o=Math.pow(i,2),a=-2*e,r=Math.pow(e,2)+s-o,c=Math.pow(a,2)-4*r;if(c<=0)return{_startAngle:0,_endAngle:It};const l=(-a-Math.sqrt(c))/2,d=(-a+Math.sqrt(c))/2;return{_startAngle:Qt({x:e,y:n},{x:l,y:t}).angle,_endAngle:Qt({x:e,y:n},{x:d,y:t}).angle}}(f?s+p:a-p,d,h,m),y={_centerX:d,_centerY:h,_radius:m,_counterclockwise:f,...b};return{controllerMeta:y,point:g,radius:Math.min(r,Math.min(u.right-u.left,u.bottom-u.top)/2)}}(t,e,n);let a=ed(t.ctx,e);const r=function({width:t,height:e},n){const i=Math.sqrt(Math.pow(t,2)+Math.pow(e,2));return 2*n/i}(a,o);Hl(e,r)&&(a={width:a.width*r,height:a.height*r});const{position:c,xAdjust:l,yAdjust:d}=e,h=ql(s,a,{borderWidth:0,position:c,xAdjust:l,yAdjust:d});return{initProperties:Ul(t,h,e),...h,...i,rotation:e.rotation,_fitRatio:r}}}Ld.id="doughnutLabelAnnotation",Ld.defaults={autoFit:!0,autoHide:!0,backgroundColor:"transparent",backgroundShadowColor:"transparent",borderColor:"transparent",borderDash:[],borderDashOffset:0,borderJoinStyle:"miter",borderShadowColor:"transparent",borderWidth:0,color:"black",content:null,display:!0,font:{family:void 0,lineHeight:void 0,size:void 0,style:void 0,weight:void 0},height:void 0,hitTolerance:0,init:void 0,opacity:void 0,position:"center",rotation:0,shadowBlur:0,shadowOffsetX:0,shadowOffsetY:0,spacing:1,textAlign:"center",textStrokeColor:void 0,textStrokeWidth:0,width:void 0,xAdjust:0,yAdjust:0},Ld.defaultRoutes={};class Id extends ms{inRange(t,e,n,i){return Ll({x:t,y:e},{rect:this.getProps(["x","y","x2","y2"],i),center:this.getCenterPoint(i)},n,{rotation:this.rotation,borderWidth:this.options.borderWidth,hitTolerance:this.options.hitTolerance})}getCenterPoint(t){return Il(this,t)}draw(t){const e=this.options,n=!Pt(this._visible)||this._visible;e.display&&e.content&&n&&(t.save(),Gl(t,this.getCenterPoint(),this.rotation),ad(t,this),nd(t,this,e),id(t,function({x:t,y:e,width:n,height:i,options:s}){const o=s.borderWidth/2,a=tn(s.padding);return{x:t+a.left+o,y:e+a.top+o,width:n-a.left-a.right-s.borderWidth,height:i-a.top-a.bottom-s.borderWidth}}(this),e),t.restore())}resolveElementProperties(t,e){let n;if(jl(e))n=hd(t,e);else{const{centerX:i,centerY:s}=ud(t,e);n={x:i,y:s}}const i=tn(e.padding),s=ql(n,ed(t.ctx,e),e,i);return{initProperties:Ul(t,s,e),pointX:n.x,pointY:n.y,...s,rotation:e.rotation}}}Id.id="labelAnnotation",Id.defaults={adjustScaleRange:!0,backgroundColor:"transparent",backgroundShadowColor:"transparent",borderCapStyle:"butt",borderDash:[],borderDashOffset:0,borderJoinStyle:"miter",borderRadius:0,borderShadowColor:"transparent",borderWidth:0,callout:{borderCapStyle:"butt",borderColor:void 0,borderDash:[],borderDashOffset:0,borderJoinStyle:"miter",borderWidth:1,display:!1,margin:5,position:"auto",side:5,start:"50%"},color:"black",content:null,display:!0,font:{family:void 0,lineHeight:void 0,size:void 0,style:void 0,weight:void 0},height:void 0,hitTolerance:0,init:void 0,opacity:void 0,padding:6,position:"center",rotation:0,shadowBlur:0,shadowOffsetX:0,shadowOffsetY:0,textAlign:"center",textStrokeColor:void 0,textStrokeWidth:0,width:void 0,xAdjust:0,xMax:void 0,xMin:void 0,xScaleID:void 0,xValue:void 0,yAdjust:0,yMax:void 0,yMin:void 0,yScaleID:void 0,yValue:void 0,z:0},Id.defaultRoutes={borderColor:"color"};const Od=(t,e,n)=>({x:t.x+n*(e.x-t.x),y:t.y+n*(e.y-t.y)}),zd=(t,e,n)=>Od(e,n,Math.abs((t-e.y)/(n.y-e.y))).x,Wd=(t,e,n)=>Od(e,n,Math.abs((t-e.x)/(n.x-e.x))).y,Nd=t=>t*t,Rd=(t,e,n,i)=>(1-i)*(1-i)*t+2*(1-i)*i*e+i*i*n,$d=(t,e,n,i)=>({x:Rd(t.x,e.x,n.x,i),y:Rd(t.y,e.y,n.y,i)}),Fd=(t,e,n,i)=>2*(1-i)*(e-t)+2*i*(n-e),qd=(t,e,n,i)=>-Math.atan2(Fd(t.x,e.x,n.x,i),Fd(t.y,e.y,n.y,i))+.5*Lt;class Bd extends ms{inRange(t,e,n,i){const s=(this.options.borderWidth+this.options.hitTolerance)/2;if("x"!==n&&"y"!==n){const n={mouseX:t,mouseY:e},{path:o,ctx:a}=this;if(o){Jl(a,this.options),a.lineWidth+=this.options.hitTolerance;const{chart:s}=this.$context,r=t*s.currentDevicePixelRatio,c=e*s.currentDevicePixelRatio,l=a.isPointInStroke(o,r,c)||jd(this,n,i);return a.restore(),l}return function(t,{mouseX:e,mouseY:n},i=.001,s){const{x:o,y:a,x2:r,y2:c}=t.getProps(["x","y","x2","y2"],s),l=r-o,d=c-a,h=Nd(l)+Nd(d),u=0===h?-1:((e-o)*l+(n-a)*d)/h;let g,p;u<0?(g=o,p=a):u>1?(g=r,p=c):(g=o+u*l,p=a+u*d);return Nd(e-g)+Nd(n-p)<=i}(this,n,Nd(s),i)||jd(this,n,i)}return function(t,{mouseX:e,mouseY:n},i,{hitSize:s,useFinalPosition:o}){const a=((t,e,{x:n,y:i,x2:s,y2:o},a)=>"y"===a?{start:Math.min(i,o),end:Math.max(i,o),value:e}:{start:Math.min(n,s),end:Math.max(n,s),value:t})(e,n,t.getProps(["x","y","x2","y2"],o),i);return Pl(a,s)||jd(t,{mouseX:e,mouseY:n},o,i)}(this,{mouseX:t,mouseY:e},n,{hitSize:s,useFinalPosition:i})}getCenterPoint(t){return Il(this,t)}draw(t){const{x:e,y:n,x2:i,y2:s,cp:o,options:a}=this;if(t.save(),!Jl(t,a))return t.restore();td(t,a);const r=Math.sqrt(Math.pow(i-e,2)+Math.pow(s-n,2));if(a.curve&&o)return function(t,e,n,i){const{x:s,y:o,x2:a,y2:r,options:c}=e,{startOpts:l,endOpts:d,startAdjust:h,endAdjust:u}=Xd(e),g={x:s,y:o},p={x:a,y:r},m=qd(g,n,p,0),f=qd(g,n,p,1)-Lt,b=$d(g,n,p,h/i),y=$d(g,n,p,1-u/i),x=new Path2D;t.beginPath(),x.moveTo(b.x,b.y),x.quadraticCurveTo(n.x,n.y,y.x,y.y),t.shadowColor=c.borderShadowColor,t.stroke(x),e.path=x,e.ctx=t,Zd(t,b,{angle:m,adjust:h},l),Zd(t,y,{angle:f,adjust:u},d)}(t,this,o,r),t.restore();const{startOpts:c,endOpts:l,startAdjust:d,endAdjust:h}=Xd(this),u=Math.atan2(s-n,i-e);t.translate(e,n),t.rotate(u),t.beginPath(),t.moveTo(0+d,0),t.lineTo(r-h,0),t.shadowColor=a.borderShadowColor,t.stroke(),Kd(t,0,d,c),Kd(t,r,-h,l),t.restore()}get label(){return this.elements&&this.elements[0]}resolveElementProperties(t,e){const n=pd(t,e),{x:i,y:s,x2:o,y2:a}=n,r=function({x:t,y:e,x2:n,y2:i},{top:s,right:o,bottom:a,left:r}){return!(t<r&&n<r||t>o&&n>o||e<s&&i<s||e>a&&i>a)}(n,t.chartArea),c=r?function(t,e,n){const{x:i,y:s}=Vd(t,e,n),{x:o,y:a}=Vd(e,t,n);return{x:i,y:s,x2:o,y2:a,width:Math.abs(o-i),height:Math.abs(a-s)}}({x:i,y:s},{x:o,y:a},t.chartArea):{x:i,y:s,x2:o,y2:a,width:Math.abs(o-i),height:Math.abs(a-s)};if(c.centerX=(o+i)/2,c.centerY=(a+s)/2,c.initProperties=Ul(t,c,e),e.curve){const t={x:c.x,y:c.y},n={x:c.x2,y:c.y2};c.cp=function(t,e,n){const{x:i,y:s,x2:o,y2:a,centerX:r,centerY:c}=t,l=Math.atan2(a-s,o-i),d=Bl(e.controlPoint,0);return _l({x:r+Fl(n,d.x,!1),y:c+Fl(n,d.y,!1)},{x:r,y:c},l)}(c,e,Kt(t,n))}const l=function(t,e,n){const i=n.borderWidth,s=tn(n.padding),o=ed(t.ctx,n),a=o.width+s.width+i,r=o.height+s.height+i;return function(t,e,n,i){const{width:s,height:o,padding:a}=n,{xAdjust:r,yAdjust:c}=e,l={x:t.x,y:t.y},d={x:t.x2,y:t.y2},h="auto"===e.rotation?function(t){const{x:e,y:n,x2:i,y2:s}=t,o=Math.atan2(s-n,i-e);return o>Lt/2?o-Lt:o<Lt/-2?o+Lt:o}(t):Yt(e.rotation),u=function(t,e,n){const i=Math.cos(n),s=Math.sin(n);return{w:Math.abs(t*i)+Math.abs(e*s),h:Math.abs(t*s)+Math.abs(e*i)}}(s,o,h),g=function(t,e,n,i){let s;const o=function(t,e){const{x:n,x2:i,y:s,y2:o}=t,a=Math.min(s,o)-e.top,r=Math.min(n,i)-e.left,c=e.bottom-Math.max(s,o),l=e.right-Math.max(n,i);return{x:Math.min(r,l),y:Math.min(a,c),dx:r<=l?1:-1,dy:a<=c?1:-1}}(t,i);s="start"===e.position?Yd({w:t.x2-t.x,h:t.y2-t.y},n,e,o):"end"===e.position?1-Yd({w:t.x-t.x2,h:t.y-t.y2},n,e,o):$l(1,e.position);return s}(t,e,{labelSize:u,padding:a},i),p=t.cp?$d(l,t.cp,d,g):Od(l,d,g),m={size:u.w,min:i.left,max:i.right,padding:a.left},f={size:u.h,min:i.top,max:i.bottom,padding:a.top},b=Ud(p.x,m)+r,y=Ud(p.y,f)+c;return{x:b-s/2,y:y-o/2,x2:b+s/2,y2:y+o/2,centerX:b,centerY:y,pointX:p.x,pointY:p.y,width:s,height:o,rotation:Ut(h)}}(e,n,{width:a,height:r,padding:s},t.chartArea)}(t,c,e.label);return l._visible=r,c.elements=[{type:"label",optionScope:"label",properties:l,initProperties:c.initProperties}],c}}Bd.id="lineAnnotation";const Hd={backgroundColor:void 0,backgroundShadowColor:void 0,borderColor:void 0,borderDash:void 0,borderDashOffset:void 0,borderShadowColor:void 0,borderWidth:void 0,display:void 0,fill:void 0,length:void 0,shadowBlur:void 0,shadowOffsetX:void 0,shadowOffsetY:void 0,width:void 0};function Vd({x:t,y:e},n,{top:i,right:s,bottom:o,left:a}){return t<a&&(e=Wd(a,{x:t,y:e},n),t=a),t>s&&(e=Wd(s,{x:t,y:e},n),t=s),e<i&&(t=zd(i,{x:t,y:e},n),e=i),e>o&&(t=zd(o,{x:t,y:e},n),e=o),{x:t,y:e}}function jd(t,{mouseX:e,mouseY:n},i,s){const o=t.label;return o.options.display&&o.inRange(e,n,s,i)}function Yd(t,e,n,i){const{labelSize:s,padding:o}=e,a=t.w*i.dx,r=t.h*i.dy,c=a>0&&(s.w/2+o.left-i.x)/a,l=r>0&&(s.h/2+o.top-i.y)/r;return Dl(Math.max(c,l),0,.25)}function Ud(t,e){const{size:n,min:i,max:s,padding:o}=e,a=n/2;return n>s-i?(s+i)/2:(i>=t-o-a&&(t=i+o+a),s<=t+o+a&&(t=s-o-a),t)}function Xd(t){const e=t.options,n=e.arrowHeads&&e.arrowHeads.start,i=e.arrowHeads&&e.arrowHeads.end;return{startOpts:n,endOpts:i,startAdjust:Qd(t,n),endAdjust:Qd(t,i)}}function Qd(t,e){if(!e||!e.display)return 0;const{length:n,width:i}=e,s=t.options.borderWidth/2,o={x:n,y:i+s},a={x:0,y:s};return Math.abs(zd(0,o,a))}function Kd(t,e,n,i){if(!i||!i.display)return;const{length:s,width:o,fill:a,backgroundColor:r,borderColor:c}=i,l=Math.abs(e-s)+n;t.beginPath(),td(t,i),Jl(t,i),t.moveTo(l,-o),t.lineTo(e+n,0),t.lineTo(l,o),!0===a?(t.fillStyle=r||c,t.closePath(),t.fill(),t.shadowColor="transparent"):t.shadowColor=i.borderShadowColor,t.stroke()}function Zd(t,{x:e,y:n},{angle:i,adjust:s},o){o&&o.display&&(t.save(),t.translate(e,n),t.rotate(i),Kd(t,0,-s,o),t.restore())}Bd.defaults={adjustScaleRange:!0,arrowHeads:{display:!1,end:Object.assign({},Hd),fill:!1,length:12,start:Object.assign({},Hd),width:6},borderDash:[],borderDashOffset:0,borderShadowColor:"transparent",borderWidth:2,curve:!1,controlPoint:{y:"-50%"},display:!0,endValue:void 0,init:void 0,hitTolerance:0,label:{backgroundColor:"rgba(0,0,0,0.8)",backgroundShadowColor:"transparent",borderCapStyle:"butt",borderColor:"black",borderDash:[],borderDashOffset:0,borderJoinStyle:"miter",borderRadius:6,borderShadowColor:"transparent",borderWidth:0,callout:Object.assign({},Id.defaults.callout),color:"#fff",content:null,display:!1,drawTime:void 0,font:{family:void 0,lineHeight:void 0,size:void 0,style:void 0,weight:"bold"},height:void 0,hitTolerance:void 0,opacity:void 0,padding:6,position:"center",rotation:0,shadowBlur:0,shadowOffsetX:0,shadowOffsetY:0,textAlign:"center",textStrokeColor:void 0,textStrokeWidth:0,width:void 0,xAdjust:0,yAdjust:0,z:void 0},scaleID:void 0,shadowBlur:0,shadowOffsetX:0,shadowOffsetY:0,value:void 0,xMax:void 0,xMin:void 0,xScaleID:void 0,yMax:void 0,yMin:void 0,yScaleID:void 0,z:0},Bd.descriptors={arrowHeads:{start:{_fallback:!0},end:{_fallback:!0},_fallback:!0}},Bd.defaultRoutes={borderColor:"color"};class Gd extends ms{inRange(t,e,n,i){const s=this.options.rotation,o=(this.options.borderWidth+this.options.hitTolerance)/2;if("x"!==n&&"y"!==n)return function(t,e,n,i){const{width:s,height:o,centerX:a,centerY:r}=e,c=s/2,l=o/2;if(c<=0||l<=0)return!1;const d=Yt(n||0),h=Math.cos(d),u=Math.sin(d),g=Math.pow(h*(t.x-a)+u*(t.y-r),2),p=Math.pow(u*(t.x-a)-h*(t.y-r),2);return g/Math.pow(c+i,2)+p/Math.pow(l+i,2)<=1.0001}({x:t,y:e},this.getProps(["width","height","centerX","centerY"],i),s,o);const{x:a,y:r,x2:c,y2:l}=this.getProps(["x","y","x2","y2"],i),d="y"===n?{start:r,end:l}:{start:a,end:c},h=_l({x:t,y:e},this.getCenterPoint(i),Yt(-s));return h[n]>=d.start-o-Tl&&h[n]<=d.end+o+Tl}getCenterPoint(t){return Il(this,t)}draw(t){const{width:e,height:n,centerX:i,centerY:s,options:o}=this;t.save(),Gl(t,this.getCenterPoint(),o.rotation),td(t,this.options),t.beginPath(),t.fillStyle=o.backgroundColor;const a=Jl(t,o);t.ellipse(i,s,n/2,e/2,Lt/2,0,2*Lt),t.fill(),a&&(t.shadowColor=o.borderShadowColor,t.stroke()),t.restore()}get label(){return this.elements&&this.elements[0]}resolveElementProperties(t,e){return md(t,e)}}Gd.id="ellipseAnnotation",Gd.defaults={adjustScaleRange:!0,backgroundShadowColor:"transparent",borderDash:[],borderDashOffset:0,borderShadowColor:"transparent",borderWidth:1,display:!0,hitTolerance:0,init:void 0,label:Object.assign({},Ad.defaults.label),rotation:0,shadowBlur:0,shadowOffsetX:0,shadowOffsetY:0,xMax:void 0,xMin:void 0,xScaleID:void 0,yMax:void 0,yMin:void 0,yScaleID:void 0,z:0},Gd.defaultRoutes={borderColor:"color",backgroundColor:"color"},Gd.descriptors={label:{_fallback:!0}};class Jd extends ms{inRange(t,e,n,i){const{x:s,y:o,x2:a,y2:r,width:c}=this.getProps(["x","y","x2","y2","width"],i),l=(this.options.borderWidth+this.options.hitTolerance)/2;if("x"!==n&&"y"!==n)return function(t,e,n,i){return!(!t||!e||n<=0)&&Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2)<=Math.pow(n+i,2)}({x:t,y:e},this.getCenterPoint(i),c/2,l);return Pl("y"===n?{start:o,end:r,value:e}:{start:s,end:a,value:t},l)}getCenterPoint(t){return Il(this,t)}draw(t){const e=this.options,n=e.borderWidth;if(e.radius<.1)return;t.save(),t.fillStyle=e.backgroundColor,td(t,e);const i=Jl(t,e);sd(t,this,this.centerX,this.centerY),i&&!Zl(e.pointStyle)&&(t.shadowColor=e.borderShadowColor,t.stroke()),t.restore(),e.borderWidth=n}resolveElementProperties(t,e){const n=gd(t,e);return n.initProperties=Ul(t,n,e),n}}Jd.id="pointAnnotation",Jd.defaults={adjustScaleRange:!0,backgroundShadowColor:"transparent",borderDash:[],borderDashOffset:0,borderShadowColor:"transparent",borderWidth:1,display:!0,hitTolerance:0,init:void 0,pointStyle:"circle",radius:10,rotation:0,shadowBlur:0,shadowOffsetX:0,shadowOffsetY:0,xAdjust:0,xMax:void 0,xMin:void 0,xScaleID:void 0,xValue:void 0,yAdjust:0,yMax:void 0,yMin:void 0,yScaleID:void 0,yValue:void 0,z:0},Jd.defaultRoutes={borderColor:"color",backgroundColor:"color"};class th extends ms{inRange(t,e,n,i){if("x"!==n&&"y"!==n)return this.options.radius>=.1&&this.elements.length>1&&function(t,e,n,i){let s=!1,o=t[t.length-1].getProps(["bX","bY"],i);for(const a of t){const t=a.getProps(["bX","bY"],i);t.bY>n!=o.bY>n&&e<(o.bX-t.bX)*(n-t.bY)/(o.bY-t.bY)+t.bX&&(s=!s),o=t}return s}(this.elements,t,e,i);const s=_l({x:t,y:e},this.getCenterPoint(i),Yt(-this.options.rotation)),o=this.elements.map((t=>"y"===n?t.bY:t.bX)),a=Math.min(...o),r=Math.max(...o);return s[n]>=a&&s[n]<=r}getCenterPoint(t){return Il(this,t)}draw(t){const{elements:e,options:n}=this;t.save(),t.beginPath(),t.fillStyle=n.backgroundColor,td(t,n);const i=Jl(t,n);let s=!0;for(const n of e)s?(t.moveTo(n.x,n.y),s=!1):t.lineTo(n.x,n.y);t.closePath(),t.fill(),i&&(t.shadowColor=n.borderShadowColor,t.stroke()),t.restore()}resolveElementProperties(t,e){const n=gd(t,e),{sides:i,rotation:s}=e,o=[],a=2*Lt/i;let r=s*Wt;for(let s=0;s<i;s++,r+=a){const i=eh(n,e,r);i.initProperties=Ul(t,n,e),o.push(i)}return n.elements=o,n}}function eh({centerX:t,centerY:e},{radius:n,borderWidth:i,hitTolerance:s},o){const a=(i+s)/2,r=Math.sin(o),c=Math.cos(o),l={x:t+r*n,y:e-c*n};return{type:"point",optionScope:"point",properties:{x:l.x,y:l.y,centerX:l.x,centerY:l.y,bX:t+r*(n+a),bY:e-c*(n+a)}}}th.id="polygonAnnotation",th.defaults={adjustScaleRange:!0,backgroundShadowColor:"transparent",borderCapStyle:"butt",borderDash:[],borderDashOffset:0,borderJoinStyle:"miter",borderShadowColor:"transparent",borderWidth:1,display:!0,hitTolerance:0,init:void 0,point:{radius:0},radius:10,rotation:0,shadowBlur:0,shadowOffsetX:0,shadowOffsetY:0,sides:3,xAdjust:0,xMax:void 0,xMin:void 0,xScaleID:void 0,xValue:void 0,yAdjust:0,yMax:void 0,yMin:void 0,yScaleID:void 0,yValue:void 0,z:0},th.defaultRoutes={borderColor:"color",backgroundColor:"color"};const nh={box:Ad,doughnutLabel:Ld,ellipse:Gd,label:Id,line:Bd,point:Jd,polygon:th};Object.keys(nh).forEach((t=>{Le.describe(`elements.${nh[t].id}`,{_fallback:"plugins.annotation.common"})}));const ih={update:Object.assign},sh=vd.concat(Md),oh=(t,e)=>ut(e)?gh(t,e):t,ah=t=>"color"===t||"font"===t;function rh(t="line"){return nh[t]?t:(console.warn(`Unknown annotation type: '${t}', defaulting to 'line'`),"line")}function ch(t,e,n,i){const s=function(t,e,n){if("reset"===n||"none"===n||"resize"===n)return ih;return new si(t,e)}(t,n.animations,i),o=e.annotations,a=function(t,e){const n=e.length,i=t.length;if(i<n){const e=n-i;t.splice(i,0,...new Array(e))}else i>n&&t.splice(n,i-n);return t}(e.elements,o);for(let e=0;e<o.length;e++){const n=o[e],i=hh(a,e,n.type),r=n.setContext(ph(t,i,a,n)),c=i.resolveElementProperties(t,r);c.skip=lh(c),"elements"in c&&(dh(i,c.elements,r,s),delete c.elements),Pt(i.x)||Object.assign(i,c),Object.assign(i,c.initProperties),c.options=uh(r),s.update(i,c)}}function lh(t){return isNaN(t.x)||isNaN(t.y)}function dh(t,e,n,i){const s=t.elements||(t.elements=[]);s.length=e.length;for(let t=0;t<e.length;t++){const o=e[t],a=o.properties,r=hh(s,t,o.type,o.initProperties),c=n[o.optionScope].override(o);a.options=uh(c),i.update(r,a)}}function hh(t,e,n,i){const s=nh[rh(n)];let o=t[e];return o&&o instanceof s||(o=t[e]=new s,Object.assign(o,i)),o}function uh(t){const e=nh[rh(t.type)],n={};n.id=t.id,n.type=t.type,n.drawTime=t.drawTime,Object.assign(n,gh(t,e.defaults),gh(t,e.defaultRoutes));for(const e of sh)n[e]=t[e];return n}function gh(t,e){const n={};for(const i of Object.keys(e)){const s=e[i],o=t[i];ah(i)&&ht(o)?n[i]=o.map((t=>oh(t,s))):n[i]=oh(o,s)}return n}function ph(t,e,n,i){return e.$context||(e.$context=Object.assign(Object.create(t.getContext()),{element:e,get elements(){return n.filter((t=>t&&t.options))},id:i.id,type:"annotation"}))}const mh=new Map,fh=t=>"doughnutLabel"!==t.type,bh=vd.concat(Md);var yh={id:"annotation",version:"3.1.0",beforeRegister(){!function(t,e,n,i=!0){const s=n.split(".");let o=0;for(const a of e.split(".")){const r=s[o++];if(parseInt(a,10)<parseInt(r,10))break;if(Cl(r,a)){if(i)throw new Error(`${t} v${n} is not supported. v${e} or newer is required.`);return!1}}}("chart.js","4.0",eo.version)},afterRegister(){eo.register(nh)},afterUnregister(){eo.unregister(nh)},beforeInit(t){mh.set(t,{annotations:[],elements:[],visibleElements:[],listeners:{},listened:!1,moveListened:!1,hooks:{},hooked:!1,hovered:[]})},beforeUpdate(t,e,n){const i=mh.get(t).annotations=[];let s=n.annotations;ut(s)?Object.keys(s).forEach((t=>{const e=s[t];ut(e)&&(e.id=t,i.push(e))})):ht(s)&&i.push(...s),function(t,e){for(const n of t)Dd(n,e)}(i.filter(fh),t.scales)},afterDataLimits(t,e){const n=mh.get(t);Cd(t,e.scale,n.annotations.filter(fh).filter((t=>t.display&&t.adjustScaleRange)))},afterUpdate(t,e,n){const i=mh.get(t);!function(t,e,n){e.listened=Xl(n,vd,e.listeners),e.moveListened=!1,xd.forEach((t=>{Et(n[t])&&(e.moveListened=!0)})),e.listened&&e.moveListened||e.annotations.forEach((t=>{!e.listened&&Et(t.click)&&(e.listened=!0),e.moveListened||xd.forEach((n=>{Et(t[n])&&(e.listened=!0,e.moveListened=!0)}))}))}(0,i,n),ch(t,i,n,e.mode),i.visibleElements=i.elements.filter((t=>!t.skip&&t.options.display)),function(t,e,n){const i=e.visibleElements;e.hooked=Xl(n,Md,e.hooks),e.hooked||i.forEach((t=>{e.hooked||Md.forEach((n=>{Et(t.options[n])&&(e.hooked=!0)}))}))}(0,i,n)},beforeDatasetsDraw(t,e,n){xh(t,"beforeDatasetsDraw",n.clip)},afterDatasetsDraw(t,e,n){xh(t,"afterDatasetsDraw",n.clip)},beforeDatasetDraw(t,e,n){xh(t,e.index,n.clip)},beforeDraw(t,e,n){xh(t,"beforeDraw",n.clip)},afterDraw(t,e,n){xh(t,"afterDraw",n.clip)},beforeEvent(t,e,n){wd(mh.get(t),e.event,n)&&(e.changed=!0)},afterDestroy(t){mh.delete(t)},getAnnotations(t){const e=mh.get(t);return e?e.elements:[]},_getAnnotationElementsAtEventForMode:(t,e,n)=>kl(t,e,n),defaults:{animations:{numbers:{properties:["x","y","x2","y2","width","height","centerX","centerY","pointX","pointY","radius"],type:"number"},colors:{properties:["backgroundColor","borderColor"],type:"color"}},clip:!0,interaction:{mode:void 0,axis:void 0,intersect:void 0},common:{drawTime:"afterDatasetsDraw",init:!1,label:{}}},descriptors:{_indexable:!1,_scriptable:t=>!bh.includes(t)&&"init"!==t,annotations:{_allKeys:!1,_fallback:(t,e)=>`elements.${nh[rh(e.type)].id}`},interaction:{_fallback:!0},common:{label:{_indexable:ah,_fallback:!0},_indexable:ah}},additionalOptionScopes:[""]};function xh(t,e,n){const{ctx:i,chartArea:s}=t,o=mh.get(t);n&&Fe(i,s);const a=function(t,e){const n=[];for(const i of t)if(i.options.drawTime===e&&n.push({element:i,main:!0}),i.elements&&i.elements.length)for(const t of i.elements)t.options.display&&t.options.drawTime===e&&n.push({element:t});return n}(o.visibleElements,e).sort(((t,e)=>t.element.options.z-e.element.options.z));for(const t of a)vh(i,s,o,t);n&&qe(i)}function vh(t,e,n,i){const s=i.element;i.main?(_d(n,s,"beforeDraw"),s.draw(t,e),_d(n,s,"afterDraw")):s.draw(t,e)}function wh(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Sh={exports:{}};
|
|
33
|
+
const Sl={modes:{point:(t,e)=>Ml(t,e,{intersect:!0}),nearest:(t,e,n)=>function(t,e,n){let i=Number.POSITIVE_INFINITY;return Ml(t,e,n).reduce(((t,s)=>{const o=s.getCenterPoint(),a=function(t,e,n){if("x"===n)return{x:t.x,y:e.y};if("y"===n)return{x:e.x,y:t.y};return e}(e,o,n.axis),r=Kt(e,a);return r<i?(t=[s],i=r):r===i&&t.push(s),t}),[]).sort(((t,e)=>t._index-e._index)).slice(0,1)}(t,e,n),x:(t,e,n)=>Ml(t,e,{intersect:n.intersect,axis:"x"}),y:(t,e,n)=>Ml(t,e,{intersect:n.intersect,axis:"y"})}};function kl(t,e,n){return(Sl.modes[n.mode]||Sl.modes.nearest)(t,e,n)}function Ml(t,e,n){return t.filter((t=>n.intersect?t.inRange(e.x,e.y):function(t,e,n){return"x"!==n&&"y"!==n?t.inRange(e.x,e.y,"x",!0)||t.inRange(e.x,e.y,"y",!0):t.inRange(e.x,e.y,n,!0)}(t,e,n.axis)))}function Cl(t,e,n){const i=Math.cos(n),s=Math.sin(n),o=e.x,a=e.y;return{x:o+i*(t.x-o)-s*(t.y-a),y:a+s*(t.x-o)+i*(t.y-a)}}const _l=(t,e)=>e>t||t.length>e.length&&t.slice(0,e.length)===e,Dl=.001,Tl=(t,e,n)=>Math.min(n,Math.max(e,t)),Pl=(t,e)=>t.value>=t.start-e&&t.value<=t.end+e;function El(t,e,n){for(const i of Object.keys(t))t[i]=Tl(t[i],e,n);return t}function Al(t,{x:e,y:n,x2:i,y2:s},o,{borderWidth:a,hitTolerance:r}){const c=(a+r)/2,l=t.x>=e-c-Dl&&t.x<=i+c+Dl,d=t.y>=n-c-Dl&&t.y<=s+c+Dl;return"x"===o?l:("y"===o||l)&&d}function Ll(t,{rect:e,center:n},i,{rotation:s,borderWidth:o,hitTolerance:a}){return Al(Cl(t,n,Yt(-s)),e,i,{borderWidth:o,hitTolerance:a})}function Il(t,e){const{centerX:n,centerY:i}=t.getProps(["centerX","centerY"],e);return{x:n,y:i}}const Ol=t=>"string"==typeof t&&t.endsWith("%"),zl=t=>parseFloat(t)/100,Wl=t=>Tl(zl(t),0,1),Nl=(t,e)=>({x:t,y:e,x2:t,y2:e,width:0,height:0}),Rl={box:t=>Nl(t.centerX,t.centerY),doughnutLabel:t=>Nl(t.centerX,t.centerY),ellipse:t=>({centerX:t.centerX,centerY:t.centerX,radius:0,width:0,height:0}),label:t=>Nl(t.centerX,t.centerY),line:t=>Nl(t.x,t.y),point:t=>({centerX:t.centerX,centerY:t.centerY,radius:0,width:0,height:0}),polygon:t=>Nl(t.centerX,t.centerY)};function $l(t,e){return"start"===e?0:"end"===e?t:Ol(e)?Wl(e)*t:t/2}function Fl(t,e,n=!0){return"number"==typeof e?e:Ol(e)?(n?Wl(e):zl(e))*t:t}function ql(t,e,{borderWidth:n,position:i,xAdjust:s,yAdjust:o},a){const r=ut(a),c=e.width+(r?a.width:0)+n,l=e.height+(r?a.height:0)+n,d=Bl(i),h=Yl(t.x,c,s,d.x),u=Yl(t.y,l,o,d.y);return{x:h,y:u,x2:h+c,y2:u+l,width:c,height:l,centerX:h+c/2,centerY:u+l/2}}function Bl(t,e="center"){return ut(t)?{x:mt(t.x,e),y:mt(t.y,e)}:{x:t=mt(t,e),y:t}}const Hl=(t,e)=>t&&t.autoFit&&e<1;function Vl(t,e){const n=t.font,i=ht(n)?n:[n];return Hl(t,e)?i.map((function(t){const n=en(t);return n.size=Math.floor(t.size*e),n.lineHeight=t.lineHeight,en(n)})):i.map((t=>en(t)))}function jl(t){return t&&(Pt(t.xValue)||Pt(t.yValue))}function Yl(t,e,n=0,i){return t-$l(e,i)+n}function Ul(t,e,n){const i=n.init;if(i)return!0===i?Ql(e,n):function(t,e,n){const i=bt(n.init,[{chart:t,properties:e,options:n}]);if(!0===i)return Ql(e,n);if(ut(i))return i}(t,e,n)}function Xl(t,e,n){let i=!1;return e.forEach((e=>{Et(t[e])?(i=!0,n[e]=t[e]):Pt(n[e])&&delete n[e]})),i}function Ql(t,e){const n=e.type||"line";return Rl[n](t)}const Kl=new Map;function Gl(t){if(t&&"object"==typeof t){const e=t.toString();return"[object HTMLImageElement]"===e||"[object HTMLCanvasElement]"===e}}function Zl(t,{x:e,y:n},i){i&&(t.translate(e,n),t.rotate(Yt(i)),t.translate(-e,-n))}function Jl(t,e){if(e&&e.borderWidth)return t.lineCap=e.borderCapStyle||"butt",t.setLineDash(e.borderDash),t.lineDashOffset=e.borderDashOffset,t.lineJoin=e.borderJoinStyle||"miter",t.lineWidth=e.borderWidth,t.strokeStyle=e.borderColor,!0}function td(t,e){t.shadowColor=e.backgroundShadowColor,t.shadowBlur=e.shadowBlur,t.shadowOffsetX=e.shadowOffsetX,t.shadowOffsetY=e.shadowOffsetY}function ed(t,e){const n=e.content;if(Gl(n)){return{width:Fl(n.width,e.width),height:Fl(n.height,e.height)}}const i=Vl(e),s=e.textStrokeWidth,o=ht(n)?n:[n],a=o.join()+(t=>t.reduce((function(t,e){return t+e.string}),""))(i)+s+(t._measureText?"-spriting":"");return Kl.has(a)||Kl.set(a,function(t,e,n,i){t.save();const s=e.length;let o=0,a=i;for(let r=0;r<s;r++){const s=n[Math.min(r,n.length-1)];t.font=s.string;const c=e[r];o=Math.max(o,t.measureText(c).width+i),a+=s.lineHeight}return t.restore(),{width:o,height:a}}(t,o,i,s)),Kl.get(a)}function nd(t,e,n){const{x:i,y:s,width:o,height:a}=e;t.save(),td(t,n);const r=Jl(t,n);t.fillStyle=n.backgroundColor,t.beginPath(),Ue(t,{x:i,y:s,w:o,h:a,radius:El(Je(n.borderRadius),0,Math.min(o,a)/2)}),t.closePath(),t.fill(),r&&(t.shadowColor=n.borderShadowColor,t.stroke()),t.restore()}function id(t,e,n,i){const s=n.content;if(Gl(s))return t.save(),t.globalAlpha=function(t,e){const n=Vt(t)?t:e;return Vt(n)?Tl(n,0,1):1}(n.opacity,s.style.opacity),t.drawImage(s,e.x,e.y,e.width,e.height),void t.restore();const o=ht(s)?s:[s],a=Vl(n,i),r=n.color,c=ht(r)?r:[r],l=function(t,e){const{x:n,width:i}=t,s=e.textAlign;return"center"===s?n+i/2:"end"===s||"right"===s?n+i:n}(e,n),d=e.y+n.textStrokeWidth/2;t.save(),t.textBaseline="middle",t.textAlign=n.textAlign,function(t,e){if(e.textStrokeWidth>0)return t.lineJoin="round",t.miterLimit=2,t.lineWidth=e.textStrokeWidth,t.strokeStyle=e.textStrokeColor,!0}(t,n)&&function(t,{x:e,y:n},i,s){t.beginPath();let o=0;i.forEach((function(i,a){const r=s[Math.min(a,s.length-1)],c=r.lineHeight;t.font=r.string,t.strokeText(i,e,n+c/2+o),o+=c})),t.stroke()}(t,{x:l,y:d},o,a),function(t,{x:e,y:n},i,{fonts:s,colors:o}){let a=0;i.forEach((function(i,r){const c=o[Math.min(r,o.length-1)],l=s[Math.min(r,s.length-1)],d=l.lineHeight;t.beginPath(),t.font=l.string,t.fillStyle=c,t.fillText(i,e,n+d/2+a),a+=d,t.fill()}))}(t,{x:l,y:d},o,{fonts:a,colors:c}),t.restore()}function sd(t,e,n,i){const{radius:s,options:o}=e,a=o.pointStyle,r=o.rotation;let c=(r||0)*Wt;if(Gl(a))return t.save(),t.translate(n,i),t.rotate(c),t.drawImage(a,-a.width/2,-a.height/2,a.width,a.height),void t.restore();(t=>isNaN(t)||t<=0)(s)||function(t,{x:e,y:n,radius:i,rotation:s,style:o,rad:a}){let r,c,l,d;switch(t.beginPath(),o){default:t.arc(e,n,i,0,It),t.closePath();break;case"triangle":t.moveTo(e+Math.sin(a)*i,n-Math.cos(a)*i),a+=$t,t.lineTo(e+Math.sin(a)*i,n-Math.cos(a)*i),a+=$t,t.lineTo(e+Math.sin(a)*i,n-Math.cos(a)*i),t.closePath();break;case"rectRounded":d=.516*i,l=i-d,r=Math.cos(a+Rt)*l,c=Math.sin(a+Rt)*l,t.arc(e-r,n-c,d,a-Lt,a-Nt),t.arc(e+c,n-r,d,a-Nt,a),t.arc(e+r,n+c,d,a,a+Nt),t.arc(e-c,n+r,d,a+Nt,a+Lt),t.closePath();break;case"rect":if(!s){l=Math.SQRT1_2*i,t.rect(e-l,n-l,2*l,2*l);break}a+=Rt;case"rectRot":r=Math.cos(a)*i,c=Math.sin(a)*i,t.moveTo(e-r,n-c),t.lineTo(e+c,n-r),t.lineTo(e+r,n+c),t.lineTo(e-c,n+r),t.closePath();break;case"crossRot":a+=Rt;case"cross":r=Math.cos(a)*i,c=Math.sin(a)*i,t.moveTo(e-r,n-c),t.lineTo(e+r,n+c),t.moveTo(e+c,n-r),t.lineTo(e-c,n+r);break;case"star":r=Math.cos(a)*i,c=Math.sin(a)*i,t.moveTo(e-r,n-c),t.lineTo(e+r,n+c),t.moveTo(e+c,n-r),t.lineTo(e-c,n+r),a+=Rt,r=Math.cos(a)*i,c=Math.sin(a)*i,t.moveTo(e-r,n-c),t.lineTo(e+r,n+c),t.moveTo(e+c,n-r),t.lineTo(e-c,n+r);break;case"line":r=Math.cos(a)*i,c=Math.sin(a)*i,t.moveTo(e-r,n-c),t.lineTo(e+r,n+c);break;case"dash":t.moveTo(e,n),t.lineTo(e+Math.cos(a)*i,n+Math.sin(a)*i)}t.fill()}(t,{x:n,y:i,radius:s,rotation:r,style:a,rad:c})}const od=["left","bottom","top","right"];function ad(t,e){const{pointX:n,pointY:i,options:s}=e,o=s.callout,a=o&&o.display&&function(t,e){const n=e.position;if(od.includes(n))return n;return function(t,e){const{x:n,y:i,x2:s,y2:o,width:a,height:r,pointX:c,pointY:l,centerX:d,centerY:h,rotation:u}=t,g={x:d,y:h},p=e.start,m=Fl(a,p),f=Fl(r,p),b=[n,n+m,n+m,s],y=[i+f,o,i,o],x=[];for(let t=0;t<4;t++){const e=Cl({x:b[t],y:y[t]},g,Yt(u));x.push({position:od[t],distance:Kt(e,{x:c,y:l})})}return x.sort(((t,e)=>t.distance-e.distance))[0].position}(t,e)}(e,o);if(!a||function(t,e,n){const{pointX:i,pointY:s}=t,o=e.margin;let a=i,r=s;"left"===n?a+=o:"right"===n?a-=o:"top"===n?r+=o:"bottom"===n&&(r-=o);return t.inRange(a,r)}(e,o,a))return;t.save(),t.beginPath();if(!Jl(t,o))return t.restore();const{separatorStart:r,separatorEnd:c}=function(t,e){const{x:n,y:i,x2:s,y2:o}=t,a=function(t,e){const{width:n,height:i,options:s}=t,o=s.callout.margin+s.borderWidth/2;if("right"===e)return n+o;if("bottom"===e)return i+o;return-o}(t,e);let r,c;"left"===e||"right"===e?(r={x:n+a,y:i},c={x:r.x,y:o}):(r={x:n,y:i+a},c={x:s,y:r.y});return{separatorStart:r,separatorEnd:c}}(e,a),{sideStart:l,sideEnd:d}=function(t,e,n){const{y:i,width:s,height:o,options:a}=t,r=a.callout.start,c=function(t,e){const n=e.side;if("left"===t||"top"===t)return-n;return n}(e,a.callout);let l,d;"left"===e||"right"===e?(l={x:n.x,y:i+Fl(o,r)},d={x:l.x+c,y:l.y}):(l={x:n.x+Fl(s,r),y:n.y},d={x:l.x,y:l.y+c});return{sideStart:l,sideEnd:d}}(e,a,r);(o.margin>0||0===s.borderWidth)&&(t.moveTo(r.x,r.y),t.lineTo(c.x,c.y)),t.moveTo(l.x,l.y),t.lineTo(d.x,d.y);const h=Cl({x:n,y:i},e.getCenterPoint(),Yt(-e.rotation));t.lineTo(h.x,h.y),t.stroke(),t.restore()}const rd={xScaleID:{min:"xMin",max:"xMax",start:"left",end:"right",startProp:"x",endProp:"x2"},yScaleID:{min:"yMin",max:"yMax",start:"bottom",end:"top",startProp:"y",endProp:"y2"}};function cd(t,e,n){return gt(e="number"==typeof e?e:t.parse(e))?t.getPixelForValue(e):n}function ld(t,e,n){const i=e[n];if(i||"scaleID"===n)return i;const s=n.charAt(0),o=Object.values(t).filter((t=>t.axis&&t.axis===s));return o.length?o[0].id:s}function dd(t,e){if(t){const n=t.options.reverse;return{start:cd(t,e.min,n?e.end:e.start),end:cd(t,e.max,n?e.start:e.end)}}}function hd(t,e){const{chartArea:n,scales:i}=t,s=i[ld(i,e,"xScaleID")],o=i[ld(i,e,"yScaleID")];let a=n.width/2,r=n.height/2;return s&&(a=cd(s,e.xValue,s.left+s.width/2)),o&&(r=cd(o,e.yValue,o.top+o.height/2)),{x:a,y:r}}function ud(t,e){const n=t.scales,i=n[ld(n,e,"xScaleID")],s=n[ld(n,e,"yScaleID")];if(!i&&!s)return{};let{left:o,right:a}=i||t.chartArea,{top:r,bottom:c}=s||t.chartArea;const l=fd(i,{min:e.xMin,max:e.xMax,start:o,end:a});o=l.start,a=l.end;const d=fd(s,{min:e.yMin,max:e.yMax,start:c,end:r});return r=d.start,c=d.end,{x:o,y:r,x2:a,y2:c,width:a-o,height:c-r,centerX:o+(a-o)/2,centerY:r+(c-r)/2}}function gd(t,e){if(!jl(e)){const n=ud(t,e);let i=e.radius;i&&!isNaN(i)||(i=Math.min(n.width,n.height)/2,e.radius=i);const s=2*i,o=n.centerX+e.xAdjust,a=n.centerY+e.yAdjust;return{x:o-i,y:a-i,x2:o+i,y2:a+i,centerX:o,centerY:a,width:s,height:s,radius:i}}return function(t,e){const n=hd(t,e),i=2*e.radius;return{x:n.x-e.radius+e.xAdjust,y:n.y-e.radius+e.yAdjust,x2:n.x+e.radius+e.xAdjust,y2:n.y+e.radius+e.yAdjust,centerX:n.x+e.xAdjust,centerY:n.y+e.yAdjust,radius:e.radius,width:i,height:i}}(t,e)}function pd(t,e){const{scales:n,chartArea:i}=t,s=n[e.scaleID],o={x:i.left,y:i.top,x2:i.right,y2:i.bottom};return s?function(t,e,n){const i=cd(t,n.value,NaN),s=cd(t,n.endValue,i);t.isHorizontal()?(e.x=i,e.x2=s):(e.y=i,e.y2=s)}(s,o,e):function(t,e,n){for(const i of Object.keys(rd)){const s=t[ld(t,n,i)];if(s){const{min:t,max:o,start:a,end:r,startProp:c,endProp:l}=rd[i],d=dd(s,{min:n[t],max:n[o],start:s[a],end:s[r]});e[c]=d.start,e[l]=d.end}}}(n,o,e),o}function md(t,e){const n=ud(t,e);return n.initProperties=Ul(t,n,e),n.elements=[{type:"label",optionScope:"label",properties:yd(t,n,e),initProperties:n.initProperties}],n}function fd(t,e){const n=dd(t,e)||e;return{start:Math.min(n.start,n.end),end:Math.max(n.start,n.end)}}function bd(t,e){const{start:n,end:i,borderWidth:s}=t,{position:o,padding:{start:a,end:r},adjust:c}=e;return n+s/2+c+$l(i-s-n-a-r-e.size,o)}function yd(t,e,n){const i=n.label;i.backgroundColor="transparent",i.callout.display=!1;const s=Bl(i.position),o=tn(i.padding),a=ed(t.ctx,i),r=function({properties:t,options:e},n,i,s){const{x:o,x2:a,width:r}=t;return bd({start:o,end:a,size:r,borderWidth:e.borderWidth},{position:i.x,padding:{start:s.left,end:s.right},adjust:e.label.xAdjust,size:n.width})}({properties:e,options:n},a,s,o),c=function({properties:t,options:e},n,i,s){const{y:o,y2:a,height:r}=t;return bd({start:o,end:a,size:r,borderWidth:e.borderWidth},{position:i.y,padding:{start:s.top,end:s.bottom},adjust:e.label.yAdjust,size:n.height})}({properties:e,options:n},a,s,o),l=a.width+o.width,d=a.height+o.height;return{x:r,y:c,x2:r+l,y2:c+d,width:l,height:d,centerX:r+l/2,centerY:c+d/2,rotation:i.rotation}}const xd=["enter","leave"],vd=xd.concat("click");function wd(t,e,n){if(t.listened)switch(e.type){case"mousemove":case"mouseout":return function(t,e,n){if(!t.moveListened)return;let i;i="mousemove"===e.type?kl(t.visibleElements,e,n.interaction):[];const s=t.hovered;t.hovered=i;const o={state:t,event:e};let a=Sd(o,"leave",s,i);return Sd(o,"enter",i,s)||a}(t,e,n);case"click":return function(t,e,n){const i=t.listeners,s=kl(t.visibleElements,e,n.interaction);let o;for(const t of s)o=kd(t.options.click||i.click,t,e)||o;return o}(t,e,n)}}function Sd({state:t,event:e},n,i,s){let o;for(const a of i)s.indexOf(a)<0&&(o=kd(a.options[n]||t.listeners[n],a,e)||o);return o}function kd(t,e,n){return!0===bt(t,[e.$context,n])}const Md=["afterDraw","beforeDraw"];function Cd(t,e,n){if(t.hooked){return bt(e.options[n]||t.hooks[n],[e.$context])}}function _d(t,e,n){const i=function(t,e,n){const i=e.axis,s=e.id,o=i+"ScaleID",a={min:mt(e.min,Number.NEGATIVE_INFINITY),max:mt(e.max,Number.POSITIVE_INFINITY)};for(const r of n)r.scaleID===s?Ed(r,e,["value","endValue"],a):ld(t,r,o)===s&&Ed(r,e,[i+"Min",i+"Max",i+"Value"],a);return a}(t.scales,e,n);let s=Dd(e,i,"min","suggestedMin");s=Dd(e,i,"max","suggestedMax")||s,s&&Et(e.handleTickRangeOptions)&&e.handleTickRangeOptions()}function Dd(t,e,n,i){if(gt(e[n])&&!function(t,e,n){return Pt(t[e])||Pt(t[n])}(t.options,n,i)){const i=t[n]!==e[n];return t[n]=e[n],i}}function Td(t,e){for(const n of["scaleID","xScaleID","yScaleID"]){const i=ld(e,t,n);i&&!e[i]&&Pd(t,n)&&console.warn(`No scale found with id '${i}' for annotation '${t.id}'`)}}function Pd(t,e){if("scaleID"===e)return!0;const n=e.charAt(0);for(const e of["Min","Max","Value"])if(Pt(t[n+e]))return!0;return!1}function Ed(t,e,n,i){for(const s of n){const n=t[s];if(Pt(n)){const t=e.parse(n);i.min=Math.min(i.min,t),i.max=Math.max(i.max,t)}}}class Ad extends ms{inRange(t,e,n,i){const{x:s,y:o}=Cl({x:t,y:e},this.getCenterPoint(i),Yt(-this.options.rotation));return Al({x:s,y:o},this.getProps(["x","y","x2","y2"],i),n,this.options)}getCenterPoint(t){return Il(this,t)}draw(t){t.save(),Zl(t,this.getCenterPoint(),this.options.rotation),nd(t,this,this.options),t.restore()}get label(){return this.elements&&this.elements[0]}resolveElementProperties(t,e){return md(t,e)}}Ad.id="boxAnnotation",Ad.defaults={adjustScaleRange:!0,backgroundShadowColor:"transparent",borderCapStyle:"butt",borderDash:[],borderDashOffset:0,borderJoinStyle:"miter",borderRadius:0,borderShadowColor:"transparent",borderWidth:1,display:!0,init:void 0,hitTolerance:0,label:{backgroundColor:"transparent",borderWidth:0,callout:{display:!1},color:"black",content:null,display:!1,drawTime:void 0,font:{family:void 0,lineHeight:void 0,size:void 0,style:void 0,weight:"bold"},height:void 0,hitTolerance:void 0,opacity:void 0,padding:6,position:"center",rotation:void 0,textAlign:"start",textStrokeColor:void 0,textStrokeWidth:0,width:void 0,xAdjust:0,yAdjust:0,z:void 0},rotation:0,shadowBlur:0,shadowOffsetX:0,shadowOffsetY:0,xMax:void 0,xMin:void 0,xScaleID:void 0,yMax:void 0,yMin:void 0,yScaleID:void 0,z:0},Ad.defaultRoutes={borderColor:"color",backgroundColor:"color"},Ad.descriptors={label:{_fallback:!0}};class Ld extends ms{inRange(t,e,n,i){return Ll({x:t,y:e},{rect:this.getProps(["x","y","x2","y2"],i),center:this.getCenterPoint(i)},n,{rotation:this.rotation,borderWidth:0,hitTolerance:this.options.hitTolerance})}getCenterPoint(t){return Il(this,t)}draw(t){const e=this.options;e.display&&e.content&&(!function(t,e){const{_centerX:n,_centerY:i,_radius:s,_startAngle:o,_endAngle:a,_counterclockwise:r,options:c}=e;t.save();const l=Jl(t,c);t.fillStyle=c.backgroundColor,t.beginPath(),t.arc(n,i,s,o,a,r),t.closePath(),t.fill(),l&&t.stroke();t.restore()}(t,this),t.save(),Zl(t,this.getCenterPoint(),this.rotation),id(t,this,e,this._fitRatio),t.restore())}resolveElementProperties(t,e){const n=function(t,e){return t.getSortedVisibleDatasetMetas().reduce((function(n,i){const s=i.controller;return s instanceof _i&&function(t,e,n){if(!e.autoHide)return!0;for(let e=0;e<n.length;e++)if(!n[e].hidden&&t.getDataVisibility(e))return!0}(t,e,i.data)&&(!n||s.innerRadius<n.controller.innerRadius)&&s.options.circumference>=90?i:n}),void 0)}(t,e);if(!n)return{};const{controllerMeta:i,point:s,radius:o}=function({chartArea:t},e,n){const{left:i,top:s,right:o,bottom:a}=t,{innerRadius:r,offsetX:c,offsetY:l}=n.controller,d=(i+o)/2+c,h=(s+a)/2+l,u={left:Math.max(d-r,i),right:Math.min(d+r,o),top:Math.max(h-r,s),bottom:Math.min(h+r,a)},g={x:(u.left+u.right)/2,y:(u.top+u.bottom)/2},p=e.spacing+e.borderWidth/2,m=r-p,f=g.y>h,b=function(t,e,n,i){const s=Math.pow(n-t,2),o=Math.pow(i,2),a=-2*e,r=Math.pow(e,2)+s-o,c=Math.pow(a,2)-4*r;if(c<=0)return{_startAngle:0,_endAngle:It};const l=(-a-Math.sqrt(c))/2,d=(-a+Math.sqrt(c))/2;return{_startAngle:Qt({x:e,y:n},{x:l,y:t}).angle,_endAngle:Qt({x:e,y:n},{x:d,y:t}).angle}}(f?s+p:a-p,d,h,m),y={_centerX:d,_centerY:h,_radius:m,_counterclockwise:f,...b};return{controllerMeta:y,point:g,radius:Math.min(r,Math.min(u.right-u.left,u.bottom-u.top)/2)}}(t,e,n);let a=ed(t.ctx,e);const r=function({width:t,height:e},n){const i=Math.sqrt(Math.pow(t,2)+Math.pow(e,2));return 2*n/i}(a,o);Hl(e,r)&&(a={width:a.width*r,height:a.height*r});const{position:c,xAdjust:l,yAdjust:d}=e,h=ql(s,a,{borderWidth:0,position:c,xAdjust:l,yAdjust:d});return{initProperties:Ul(t,h,e),...h,...i,rotation:e.rotation,_fitRatio:r}}}Ld.id="doughnutLabelAnnotation",Ld.defaults={autoFit:!0,autoHide:!0,backgroundColor:"transparent",backgroundShadowColor:"transparent",borderColor:"transparent",borderDash:[],borderDashOffset:0,borderJoinStyle:"miter",borderShadowColor:"transparent",borderWidth:0,color:"black",content:null,display:!0,font:{family:void 0,lineHeight:void 0,size:void 0,style:void 0,weight:void 0},height:void 0,hitTolerance:0,init:void 0,opacity:void 0,position:"center",rotation:0,shadowBlur:0,shadowOffsetX:0,shadowOffsetY:0,spacing:1,textAlign:"center",textStrokeColor:void 0,textStrokeWidth:0,width:void 0,xAdjust:0,yAdjust:0},Ld.defaultRoutes={};class Id extends ms{inRange(t,e,n,i){return Ll({x:t,y:e},{rect:this.getProps(["x","y","x2","y2"],i),center:this.getCenterPoint(i)},n,{rotation:this.rotation,borderWidth:this.options.borderWidth,hitTolerance:this.options.hitTolerance})}getCenterPoint(t){return Il(this,t)}draw(t){const e=this.options,n=!Pt(this._visible)||this._visible;e.display&&e.content&&n&&(t.save(),Zl(t,this.getCenterPoint(),this.rotation),ad(t,this),nd(t,this,e),id(t,function({x:t,y:e,width:n,height:i,options:s}){const o=s.borderWidth/2,a=tn(s.padding);return{x:t+a.left+o,y:e+a.top+o,width:n-a.left-a.right-s.borderWidth,height:i-a.top-a.bottom-s.borderWidth}}(this),e),t.restore())}resolveElementProperties(t,e){let n;if(jl(e))n=hd(t,e);else{const{centerX:i,centerY:s}=ud(t,e);n={x:i,y:s}}const i=tn(e.padding),s=ql(n,ed(t.ctx,e),e,i);return{initProperties:Ul(t,s,e),pointX:n.x,pointY:n.y,...s,rotation:e.rotation}}}Id.id="labelAnnotation",Id.defaults={adjustScaleRange:!0,backgroundColor:"transparent",backgroundShadowColor:"transparent",borderCapStyle:"butt",borderDash:[],borderDashOffset:0,borderJoinStyle:"miter",borderRadius:0,borderShadowColor:"transparent",borderWidth:0,callout:{borderCapStyle:"butt",borderColor:void 0,borderDash:[],borderDashOffset:0,borderJoinStyle:"miter",borderWidth:1,display:!1,margin:5,position:"auto",side:5,start:"50%"},color:"black",content:null,display:!0,font:{family:void 0,lineHeight:void 0,size:void 0,style:void 0,weight:void 0},height:void 0,hitTolerance:0,init:void 0,opacity:void 0,padding:6,position:"center",rotation:0,shadowBlur:0,shadowOffsetX:0,shadowOffsetY:0,textAlign:"center",textStrokeColor:void 0,textStrokeWidth:0,width:void 0,xAdjust:0,xMax:void 0,xMin:void 0,xScaleID:void 0,xValue:void 0,yAdjust:0,yMax:void 0,yMin:void 0,yScaleID:void 0,yValue:void 0,z:0},Id.defaultRoutes={borderColor:"color"};const Od=(t,e,n)=>({x:t.x+n*(e.x-t.x),y:t.y+n*(e.y-t.y)}),zd=(t,e,n)=>Od(e,n,Math.abs((t-e.y)/(n.y-e.y))).x,Wd=(t,e,n)=>Od(e,n,Math.abs((t-e.x)/(n.x-e.x))).y,Nd=t=>t*t,Rd=(t,e,n,i)=>(1-i)*(1-i)*t+2*(1-i)*i*e+i*i*n,$d=(t,e,n,i)=>({x:Rd(t.x,e.x,n.x,i),y:Rd(t.y,e.y,n.y,i)}),Fd=(t,e,n,i)=>2*(1-i)*(e-t)+2*i*(n-e),qd=(t,e,n,i)=>-Math.atan2(Fd(t.x,e.x,n.x,i),Fd(t.y,e.y,n.y,i))+.5*Lt;class Bd extends ms{inRange(t,e,n,i){const s=(this.options.borderWidth+this.options.hitTolerance)/2;if("x"!==n&&"y"!==n){const n={mouseX:t,mouseY:e},{path:o,ctx:a}=this;if(o){Jl(a,this.options),a.lineWidth+=this.options.hitTolerance;const{chart:s}=this.$context,r=t*s.currentDevicePixelRatio,c=e*s.currentDevicePixelRatio,l=a.isPointInStroke(o,r,c)||jd(this,n,i);return a.restore(),l}return function(t,{mouseX:e,mouseY:n},i=.001,s){const{x:o,y:a,x2:r,y2:c}=t.getProps(["x","y","x2","y2"],s),l=r-o,d=c-a,h=Nd(l)+Nd(d),u=0===h?-1:((e-o)*l+(n-a)*d)/h;let g,p;u<0?(g=o,p=a):u>1?(g=r,p=c):(g=o+u*l,p=a+u*d);return Nd(e-g)+Nd(n-p)<=i}(this,n,Nd(s),i)||jd(this,n,i)}return function(t,{mouseX:e,mouseY:n},i,{hitSize:s,useFinalPosition:o}){const a=((t,e,{x:n,y:i,x2:s,y2:o},a)=>"y"===a?{start:Math.min(i,o),end:Math.max(i,o),value:e}:{start:Math.min(n,s),end:Math.max(n,s),value:t})(e,n,t.getProps(["x","y","x2","y2"],o),i);return Pl(a,s)||jd(t,{mouseX:e,mouseY:n},o,i)}(this,{mouseX:t,mouseY:e},n,{hitSize:s,useFinalPosition:i})}getCenterPoint(t){return Il(this,t)}draw(t){const{x:e,y:n,x2:i,y2:s,cp:o,options:a}=this;if(t.save(),!Jl(t,a))return t.restore();td(t,a);const r=Math.sqrt(Math.pow(i-e,2)+Math.pow(s-n,2));if(a.curve&&o)return function(t,e,n,i){const{x:s,y:o,x2:a,y2:r,options:c}=e,{startOpts:l,endOpts:d,startAdjust:h,endAdjust:u}=Xd(e),g={x:s,y:o},p={x:a,y:r},m=qd(g,n,p,0),f=qd(g,n,p,1)-Lt,b=$d(g,n,p,h/i),y=$d(g,n,p,1-u/i),x=new Path2D;t.beginPath(),x.moveTo(b.x,b.y),x.quadraticCurveTo(n.x,n.y,y.x,y.y),t.shadowColor=c.borderShadowColor,t.stroke(x),e.path=x,e.ctx=t,Gd(t,b,{angle:m,adjust:h},l),Gd(t,y,{angle:f,adjust:u},d)}(t,this,o,r),t.restore();const{startOpts:c,endOpts:l,startAdjust:d,endAdjust:h}=Xd(this),u=Math.atan2(s-n,i-e);t.translate(e,n),t.rotate(u),t.beginPath(),t.moveTo(0+d,0),t.lineTo(r-h,0),t.shadowColor=a.borderShadowColor,t.stroke(),Kd(t,0,d,c),Kd(t,r,-h,l),t.restore()}get label(){return this.elements&&this.elements[0]}resolveElementProperties(t,e){const n=pd(t,e),{x:i,y:s,x2:o,y2:a}=n,r=function({x:t,y:e,x2:n,y2:i},{top:s,right:o,bottom:a,left:r}){return!(t<r&&n<r||t>o&&n>o||e<s&&i<s||e>a&&i>a)}(n,t.chartArea),c=r?function(t,e,n){const{x:i,y:s}=Vd(t,e,n),{x:o,y:a}=Vd(e,t,n);return{x:i,y:s,x2:o,y2:a,width:Math.abs(o-i),height:Math.abs(a-s)}}({x:i,y:s},{x:o,y:a},t.chartArea):{x:i,y:s,x2:o,y2:a,width:Math.abs(o-i),height:Math.abs(a-s)};if(c.centerX=(o+i)/2,c.centerY=(a+s)/2,c.initProperties=Ul(t,c,e),e.curve){const t={x:c.x,y:c.y},n={x:c.x2,y:c.y2};c.cp=function(t,e,n){const{x:i,y:s,x2:o,y2:a,centerX:r,centerY:c}=t,l=Math.atan2(a-s,o-i),d=Bl(e.controlPoint,0);return Cl({x:r+Fl(n,d.x,!1),y:c+Fl(n,d.y,!1)},{x:r,y:c},l)}(c,e,Kt(t,n))}const l=function(t,e,n){const i=n.borderWidth,s=tn(n.padding),o=ed(t.ctx,n),a=o.width+s.width+i,r=o.height+s.height+i;return function(t,e,n,i){const{width:s,height:o,padding:a}=n,{xAdjust:r,yAdjust:c}=e,l={x:t.x,y:t.y},d={x:t.x2,y:t.y2},h="auto"===e.rotation?function(t){const{x:e,y:n,x2:i,y2:s}=t,o=Math.atan2(s-n,i-e);return o>Lt/2?o-Lt:o<Lt/-2?o+Lt:o}(t):Yt(e.rotation),u=function(t,e,n){const i=Math.cos(n),s=Math.sin(n);return{w:Math.abs(t*i)+Math.abs(e*s),h:Math.abs(t*s)+Math.abs(e*i)}}(s,o,h),g=function(t,e,n,i){let s;const o=function(t,e){const{x:n,x2:i,y:s,y2:o}=t,a=Math.min(s,o)-e.top,r=Math.min(n,i)-e.left,c=e.bottom-Math.max(s,o),l=e.right-Math.max(n,i);return{x:Math.min(r,l),y:Math.min(a,c),dx:r<=l?1:-1,dy:a<=c?1:-1}}(t,i);s="start"===e.position?Yd({w:t.x2-t.x,h:t.y2-t.y},n,e,o):"end"===e.position?1-Yd({w:t.x-t.x2,h:t.y-t.y2},n,e,o):$l(1,e.position);return s}(t,e,{labelSize:u,padding:a},i),p=t.cp?$d(l,t.cp,d,g):Od(l,d,g),m={size:u.w,min:i.left,max:i.right,padding:a.left},f={size:u.h,min:i.top,max:i.bottom,padding:a.top},b=Ud(p.x,m)+r,y=Ud(p.y,f)+c;return{x:b-s/2,y:y-o/2,x2:b+s/2,y2:y+o/2,centerX:b,centerY:y,pointX:p.x,pointY:p.y,width:s,height:o,rotation:Ut(h)}}(e,n,{width:a,height:r,padding:s},t.chartArea)}(t,c,e.label);return l._visible=r,c.elements=[{type:"label",optionScope:"label",properties:l,initProperties:c.initProperties}],c}}Bd.id="lineAnnotation";const Hd={backgroundColor:void 0,backgroundShadowColor:void 0,borderColor:void 0,borderDash:void 0,borderDashOffset:void 0,borderShadowColor:void 0,borderWidth:void 0,display:void 0,fill:void 0,length:void 0,shadowBlur:void 0,shadowOffsetX:void 0,shadowOffsetY:void 0,width:void 0};function Vd({x:t,y:e},n,{top:i,right:s,bottom:o,left:a}){return t<a&&(e=Wd(a,{x:t,y:e},n),t=a),t>s&&(e=Wd(s,{x:t,y:e},n),t=s),e<i&&(t=zd(i,{x:t,y:e},n),e=i),e>o&&(t=zd(o,{x:t,y:e},n),e=o),{x:t,y:e}}function jd(t,{mouseX:e,mouseY:n},i,s){const o=t.label;return o.options.display&&o.inRange(e,n,s,i)}function Yd(t,e,n,i){const{labelSize:s,padding:o}=e,a=t.w*i.dx,r=t.h*i.dy,c=a>0&&(s.w/2+o.left-i.x)/a,l=r>0&&(s.h/2+o.top-i.y)/r;return Tl(Math.max(c,l),0,.25)}function Ud(t,e){const{size:n,min:i,max:s,padding:o}=e,a=n/2;return n>s-i?(s+i)/2:(i>=t-o-a&&(t=i+o+a),s<=t+o+a&&(t=s-o-a),t)}function Xd(t){const e=t.options,n=e.arrowHeads&&e.arrowHeads.start,i=e.arrowHeads&&e.arrowHeads.end;return{startOpts:n,endOpts:i,startAdjust:Qd(t,n),endAdjust:Qd(t,i)}}function Qd(t,e){if(!e||!e.display)return 0;const{length:n,width:i}=e,s=t.options.borderWidth/2,o={x:n,y:i+s},a={x:0,y:s};return Math.abs(zd(0,o,a))}function Kd(t,e,n,i){if(!i||!i.display)return;const{length:s,width:o,fill:a,backgroundColor:r,borderColor:c}=i,l=Math.abs(e-s)+n;t.beginPath(),td(t,i),Jl(t,i),t.moveTo(l,-o),t.lineTo(e+n,0),t.lineTo(l,o),!0===a?(t.fillStyle=r||c,t.closePath(),t.fill(),t.shadowColor="transparent"):t.shadowColor=i.borderShadowColor,t.stroke()}function Gd(t,{x:e,y:n},{angle:i,adjust:s},o){o&&o.display&&(t.save(),t.translate(e,n),t.rotate(i),Kd(t,0,-s,o),t.restore())}Bd.defaults={adjustScaleRange:!0,arrowHeads:{display:!1,end:Object.assign({},Hd),fill:!1,length:12,start:Object.assign({},Hd),width:6},borderDash:[],borderDashOffset:0,borderShadowColor:"transparent",borderWidth:2,curve:!1,controlPoint:{y:"-50%"},display:!0,endValue:void 0,init:void 0,hitTolerance:0,label:{backgroundColor:"rgba(0,0,0,0.8)",backgroundShadowColor:"transparent",borderCapStyle:"butt",borderColor:"black",borderDash:[],borderDashOffset:0,borderJoinStyle:"miter",borderRadius:6,borderShadowColor:"transparent",borderWidth:0,callout:Object.assign({},Id.defaults.callout),color:"#fff",content:null,display:!1,drawTime:void 0,font:{family:void 0,lineHeight:void 0,size:void 0,style:void 0,weight:"bold"},height:void 0,hitTolerance:void 0,opacity:void 0,padding:6,position:"center",rotation:0,shadowBlur:0,shadowOffsetX:0,shadowOffsetY:0,textAlign:"center",textStrokeColor:void 0,textStrokeWidth:0,width:void 0,xAdjust:0,yAdjust:0,z:void 0},scaleID:void 0,shadowBlur:0,shadowOffsetX:0,shadowOffsetY:0,value:void 0,xMax:void 0,xMin:void 0,xScaleID:void 0,yMax:void 0,yMin:void 0,yScaleID:void 0,z:0},Bd.descriptors={arrowHeads:{start:{_fallback:!0},end:{_fallback:!0},_fallback:!0}},Bd.defaultRoutes={borderColor:"color"};class Zd extends ms{inRange(t,e,n,i){const s=this.options.rotation,o=(this.options.borderWidth+this.options.hitTolerance)/2;if("x"!==n&&"y"!==n)return function(t,e,n,i){const{width:s,height:o,centerX:a,centerY:r}=e,c=s/2,l=o/2;if(c<=0||l<=0)return!1;const d=Yt(n||0),h=Math.cos(d),u=Math.sin(d),g=Math.pow(h*(t.x-a)+u*(t.y-r),2),p=Math.pow(u*(t.x-a)-h*(t.y-r),2);return g/Math.pow(c+i,2)+p/Math.pow(l+i,2)<=1.0001}({x:t,y:e},this.getProps(["width","height","centerX","centerY"],i),s,o);const{x:a,y:r,x2:c,y2:l}=this.getProps(["x","y","x2","y2"],i),d="y"===n?{start:r,end:l}:{start:a,end:c},h=Cl({x:t,y:e},this.getCenterPoint(i),Yt(-s));return h[n]>=d.start-o-Dl&&h[n]<=d.end+o+Dl}getCenterPoint(t){return Il(this,t)}draw(t){const{width:e,height:n,centerX:i,centerY:s,options:o}=this;t.save(),Zl(t,this.getCenterPoint(),o.rotation),td(t,this.options),t.beginPath(),t.fillStyle=o.backgroundColor;const a=Jl(t,o);t.ellipse(i,s,n/2,e/2,Lt/2,0,2*Lt),t.fill(),a&&(t.shadowColor=o.borderShadowColor,t.stroke()),t.restore()}get label(){return this.elements&&this.elements[0]}resolveElementProperties(t,e){return md(t,e)}}Zd.id="ellipseAnnotation",Zd.defaults={adjustScaleRange:!0,backgroundShadowColor:"transparent",borderDash:[],borderDashOffset:0,borderShadowColor:"transparent",borderWidth:1,display:!0,hitTolerance:0,init:void 0,label:Object.assign({},Ad.defaults.label),rotation:0,shadowBlur:0,shadowOffsetX:0,shadowOffsetY:0,xMax:void 0,xMin:void 0,xScaleID:void 0,yMax:void 0,yMin:void 0,yScaleID:void 0,z:0},Zd.defaultRoutes={borderColor:"color",backgroundColor:"color"},Zd.descriptors={label:{_fallback:!0}};class Jd extends ms{inRange(t,e,n,i){const{x:s,y:o,x2:a,y2:r,width:c}=this.getProps(["x","y","x2","y2","width"],i),l=(this.options.borderWidth+this.options.hitTolerance)/2;if("x"!==n&&"y"!==n)return function(t,e,n,i){return!(!t||!e||n<=0)&&Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2)<=Math.pow(n+i,2)}({x:t,y:e},this.getCenterPoint(i),c/2,l);return Pl("y"===n?{start:o,end:r,value:e}:{start:s,end:a,value:t},l)}getCenterPoint(t){return Il(this,t)}draw(t){const e=this.options,n=e.borderWidth;if(e.radius<.1)return;t.save(),t.fillStyle=e.backgroundColor,td(t,e);const i=Jl(t,e);sd(t,this,this.centerX,this.centerY),i&&!Gl(e.pointStyle)&&(t.shadowColor=e.borderShadowColor,t.stroke()),t.restore(),e.borderWidth=n}resolveElementProperties(t,e){const n=gd(t,e);return n.initProperties=Ul(t,n,e),n}}Jd.id="pointAnnotation",Jd.defaults={adjustScaleRange:!0,backgroundShadowColor:"transparent",borderDash:[],borderDashOffset:0,borderShadowColor:"transparent",borderWidth:1,display:!0,hitTolerance:0,init:void 0,pointStyle:"circle",radius:10,rotation:0,shadowBlur:0,shadowOffsetX:0,shadowOffsetY:0,xAdjust:0,xMax:void 0,xMin:void 0,xScaleID:void 0,xValue:void 0,yAdjust:0,yMax:void 0,yMin:void 0,yScaleID:void 0,yValue:void 0,z:0},Jd.defaultRoutes={borderColor:"color",backgroundColor:"color"};class th extends ms{inRange(t,e,n,i){if("x"!==n&&"y"!==n)return this.options.radius>=.1&&this.elements.length>1&&function(t,e,n,i){let s=!1,o=t[t.length-1].getProps(["bX","bY"],i);for(const a of t){const t=a.getProps(["bX","bY"],i);t.bY>n!=o.bY>n&&e<(o.bX-t.bX)*(n-t.bY)/(o.bY-t.bY)+t.bX&&(s=!s),o=t}return s}(this.elements,t,e,i);const s=Cl({x:t,y:e},this.getCenterPoint(i),Yt(-this.options.rotation)),o=this.elements.map((t=>"y"===n?t.bY:t.bX)),a=Math.min(...o),r=Math.max(...o);return s[n]>=a&&s[n]<=r}getCenterPoint(t){return Il(this,t)}draw(t){const{elements:e,options:n}=this;t.save(),t.beginPath(),t.fillStyle=n.backgroundColor,td(t,n);const i=Jl(t,n);let s=!0;for(const n of e)s?(t.moveTo(n.x,n.y),s=!1):t.lineTo(n.x,n.y);t.closePath(),t.fill(),i&&(t.shadowColor=n.borderShadowColor,t.stroke()),t.restore()}resolveElementProperties(t,e){const n=gd(t,e),{sides:i,rotation:s}=e,o=[],a=2*Lt/i;let r=s*Wt;for(let s=0;s<i;s++,r+=a){const i=eh(n,e,r);i.initProperties=Ul(t,n,e),o.push(i)}return n.elements=o,n}}function eh({centerX:t,centerY:e},{radius:n,borderWidth:i,hitTolerance:s},o){const a=(i+s)/2,r=Math.sin(o),c=Math.cos(o),l={x:t+r*n,y:e-c*n};return{type:"point",optionScope:"point",properties:{x:l.x,y:l.y,centerX:l.x,centerY:l.y,bX:t+r*(n+a),bY:e-c*(n+a)}}}th.id="polygonAnnotation",th.defaults={adjustScaleRange:!0,backgroundShadowColor:"transparent",borderCapStyle:"butt",borderDash:[],borderDashOffset:0,borderJoinStyle:"miter",borderShadowColor:"transparent",borderWidth:1,display:!0,hitTolerance:0,init:void 0,point:{radius:0},radius:10,rotation:0,shadowBlur:0,shadowOffsetX:0,shadowOffsetY:0,sides:3,xAdjust:0,xMax:void 0,xMin:void 0,xScaleID:void 0,xValue:void 0,yAdjust:0,yMax:void 0,yMin:void 0,yScaleID:void 0,yValue:void 0,z:0},th.defaultRoutes={borderColor:"color",backgroundColor:"color"};const nh={box:Ad,doughnutLabel:Ld,ellipse:Zd,label:Id,line:Bd,point:Jd,polygon:th};Object.keys(nh).forEach((t=>{Le.describe(`elements.${nh[t].id}`,{_fallback:"plugins.annotation.common"})}));const ih={update:Object.assign},sh=vd.concat(Md),oh=(t,e)=>ut(e)?gh(t,e):t,ah=t=>"color"===t||"font"===t;function rh(t="line"){return nh[t]?t:(console.warn(`Unknown annotation type: '${t}', defaulting to 'line'`),"line")}function ch(t,e,n,i){const s=function(t,e,n){if("reset"===n||"none"===n||"resize"===n)return ih;return new si(t,e)}(t,n.animations,i),o=e.annotations,a=function(t,e){const n=e.length,i=t.length;if(i<n){const e=n-i;t.splice(i,0,...new Array(e))}else i>n&&t.splice(n,i-n);return t}(e.elements,o);for(let e=0;e<o.length;e++){const n=o[e],i=hh(a,e,n.type),r=n.setContext(ph(t,i,a,n)),c=i.resolveElementProperties(t,r);c.skip=lh(c),"elements"in c&&(dh(i,c.elements,r,s),delete c.elements),Pt(i.x)||Object.assign(i,c),Object.assign(i,c.initProperties),c.options=uh(r),s.update(i,c)}}function lh(t){return isNaN(t.x)||isNaN(t.y)}function dh(t,e,n,i){const s=t.elements||(t.elements=[]);s.length=e.length;for(let t=0;t<e.length;t++){const o=e[t],a=o.properties,r=hh(s,t,o.type,o.initProperties),c=n[o.optionScope].override(o);a.options=uh(c),i.update(r,a)}}function hh(t,e,n,i){const s=nh[rh(n)];let o=t[e];return o&&o instanceof s||(o=t[e]=new s,Object.assign(o,i)),o}function uh(t){const e=nh[rh(t.type)],n={};n.id=t.id,n.type=t.type,n.drawTime=t.drawTime,Object.assign(n,gh(t,e.defaults),gh(t,e.defaultRoutes));for(const e of sh)n[e]=t[e];return n}function gh(t,e){const n={};for(const i of Object.keys(e)){const s=e[i],o=t[i];ah(i)&&ht(o)?n[i]=o.map((t=>oh(t,s))):n[i]=oh(o,s)}return n}function ph(t,e,n,i){return e.$context||(e.$context=Object.assign(Object.create(t.getContext()),{element:e,get elements(){return n.filter((t=>t&&t.options))},id:i.id,type:"annotation"}))}const mh=new Map,fh=t=>"doughnutLabel"!==t.type,bh=vd.concat(Md);var yh={id:"annotation",version:"3.1.0",beforeRegister(){!function(t,e,n,i=!0){const s=n.split(".");let o=0;for(const a of e.split(".")){const r=s[o++];if(parseInt(a,10)<parseInt(r,10))break;if(_l(r,a)){if(i)throw new Error(`${t} v${n} is not supported. v${e} or newer is required.`);return!1}}}("chart.js","4.0",eo.version)},afterRegister(){eo.register(nh)},afterUnregister(){eo.unregister(nh)},beforeInit(t){mh.set(t,{annotations:[],elements:[],visibleElements:[],listeners:{},listened:!1,moveListened:!1,hooks:{},hooked:!1,hovered:[]})},beforeUpdate(t,e,n){const i=mh.get(t).annotations=[];let s=n.annotations;ut(s)?Object.keys(s).forEach((t=>{const e=s[t];ut(e)&&(e.id=t,i.push(e))})):ht(s)&&i.push(...s),function(t,e){for(const n of t)Td(n,e)}(i.filter(fh),t.scales)},afterDataLimits(t,e){const n=mh.get(t);_d(t,e.scale,n.annotations.filter(fh).filter((t=>t.display&&t.adjustScaleRange)))},afterUpdate(t,e,n){const i=mh.get(t);!function(t,e,n){e.listened=Xl(n,vd,e.listeners),e.moveListened=!1,xd.forEach((t=>{Et(n[t])&&(e.moveListened=!0)})),e.listened&&e.moveListened||e.annotations.forEach((t=>{!e.listened&&Et(t.click)&&(e.listened=!0),e.moveListened||xd.forEach((n=>{Et(t[n])&&(e.listened=!0,e.moveListened=!0)}))}))}(0,i,n),ch(t,i,n,e.mode),i.visibleElements=i.elements.filter((t=>!t.skip&&t.options.display)),function(t,e,n){const i=e.visibleElements;e.hooked=Xl(n,Md,e.hooks),e.hooked||i.forEach((t=>{e.hooked||Md.forEach((n=>{Et(t.options[n])&&(e.hooked=!0)}))}))}(0,i,n)},beforeDatasetsDraw(t,e,n){xh(t,"beforeDatasetsDraw",n.clip)},afterDatasetsDraw(t,e,n){xh(t,"afterDatasetsDraw",n.clip)},beforeDatasetDraw(t,e,n){xh(t,e.index,n.clip)},beforeDraw(t,e,n){xh(t,"beforeDraw",n.clip)},afterDraw(t,e,n){xh(t,"afterDraw",n.clip)},beforeEvent(t,e,n){wd(mh.get(t),e.event,n)&&(e.changed=!0)},afterDestroy(t){mh.delete(t)},getAnnotations(t){const e=mh.get(t);return e?e.elements:[]},_getAnnotationElementsAtEventForMode:(t,e,n)=>kl(t,e,n),defaults:{animations:{numbers:{properties:["x","y","x2","y2","width","height","centerX","centerY","pointX","pointY","radius"],type:"number"},colors:{properties:["backgroundColor","borderColor"],type:"color"}},clip:!0,interaction:{mode:void 0,axis:void 0,intersect:void 0},common:{drawTime:"afterDatasetsDraw",init:!1,label:{}}},descriptors:{_indexable:!1,_scriptable:t=>!bh.includes(t)&&"init"!==t,annotations:{_allKeys:!1,_fallback:(t,e)=>`elements.${nh[rh(e.type)].id}`},interaction:{_fallback:!0},common:{label:{_indexable:ah,_fallback:!0},_indexable:ah}},additionalOptionScopes:[""]};function xh(t,e,n){const{ctx:i,chartArea:s}=t,o=mh.get(t);n&&Fe(i,s);const a=function(t,e){const n=[];for(const i of t)if(i.options.drawTime===e&&n.push({element:i,main:!0}),i.elements&&i.elements.length)for(const t of i.elements)t.options.display&&t.options.drawTime===e&&n.push({element:t});return n}(o.visibleElements,e).sort(((t,e)=>t.element.options.z-e.element.options.z));for(const t of a)vh(i,s,o,t);n&&qe(i)}function vh(t,e,n,i){const s=i.element;i.main?(Cd(n,s,"beforeDraw"),s.draw(t,e),Cd(n,s,"afterDraw")):s.draw(t,e)}function wh(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Sh={exports:{}};
|
|
34
34
|
/*! Hammer.JS - v2.0.7 - 2016-04-22
|
|
35
35
|
* http://hammerjs.github.io/
|
|
36
36
|
*
|
|
37
37
|
* Copyright (c) 2016 Jorik Tangelder;
|
|
38
|
-
* Licensed under the MIT license */!function(t){!function(e,n,i,s){var o,a=["","webkit","Moz","MS","ms","o"],r=n.createElement("div"),c=Math.round,l=Math.abs,d=Date.now;function h(t,e,n){return setTimeout(y(t,n),e)}function u(t,e,n){return!!Array.isArray(t)&&(g(t,n[e],n),!0)}function g(t,e,n){var i;if(t)if(t.forEach)t.forEach(e,n);else if(t.length!==s)for(i=0;i<t.length;)e.call(n,t[i],i,t),i++;else for(i in t)t.hasOwnProperty(i)&&e.call(n,t[i],i,t)}function p(t,n,i){var s="DEPRECATED METHOD: "+n+"\n"+i+" AT \n";return function(){var n=new Error("get-stack-trace"),i=n&&n.stack?n.stack.replace(/^[^\(]+?[\n$]/gm,"").replace(/^\s+at\s+/gm,"").replace(/^Object.<anonymous>\s*\(/gm,"{anonymous}()@"):"Unknown Stack Trace",o=e.console&&(e.console.warn||e.console.log);return o&&o.call(e.console,s,i),t.apply(this,arguments)}}o="function"!=typeof Object.assign?function(t){if(t===s||null===t)throw new TypeError("Cannot convert undefined or null to object");for(var e=Object(t),n=1;n<arguments.length;n++){var i=arguments[n];if(i!==s&&null!==i)for(var o in i)i.hasOwnProperty(o)&&(e[o]=i[o])}return e}:Object.assign;var m=p((function(t,e,n){for(var i=Object.keys(e),o=0;o<i.length;)(!n||n&&t[i[o]]===s)&&(t[i[o]]=e[i[o]]),o++;return t}),"extend","Use `assign`."),f=p((function(t,e){return m(t,e,!0)}),"merge","Use `assign`.");function b(t,e,n){var i,s=e.prototype;(i=t.prototype=Object.create(s)).constructor=t,i._super=s,n&&o(i,n)}function y(t,e){return function(){return t.apply(e,arguments)}}function x(t,e){return"function"==typeof t?t.apply(e&&e[0]||s,e):t}function v(t,e){return t===s?e:t}function w(t,e,n){g(_(e),(function(e){t.addEventListener(e,n,!1)}))}function S(t,e,n){g(_(e),(function(e){t.removeEventListener(e,n,!1)}))}function k(t,e){for(;t;){if(t==e)return!0;t=t.parentNode}return!1}function M(t,e){return t.indexOf(e)>-1}function _(t){return t.trim().split(/\s+/g)}function C(t,e,n){if(t.indexOf&&!n)return t.indexOf(e);for(var i=0;i<t.length;){if(n&&t[i][n]==e||!n&&t[i]===e)return i;i++}return-1}function T(t){return Array.prototype.slice.call(t,0)}function D(t,e,n){for(var i=[],s=[],o=0;o<t.length;){var a=e?t[o][e]:t[o];C(s,a)<0&&i.push(t[o]),s[o]=a,o++}return n&&(i=e?i.sort((function(t,n){return t[e]>n[e]})):i.sort()),i}function P(t,e){for(var n,i,o=e[0].toUpperCase()+e.slice(1),r=0;r<a.length;){if((i=(n=a[r])?n+o:e)in t)return i;r++}return s}var E=1;function A(t){var n=t.ownerDocument||t;return n.defaultView||n.parentWindow||e}var L="ontouchstart"in e,I=P(e,"PointerEvent")!==s,O=L&&/mobile|tablet|ip(ad|hone|od)|android/i.test(navigator.userAgent),z="touch",W="mouse",N=24,R=["x","y"],$=["clientX","clientY"];function F(t,e){var n=this;this.manager=t,this.callback=e,this.element=t.element,this.target=t.options.inputTarget,this.domHandler=function(e){x(t.options.enable,[t])&&n.handler(e)},this.init()}function q(t,e,n){var i=n.pointers.length,o=n.changedPointers.length,a=1&e&&i-o===0,r=12&e&&i-o===0;n.isFirst=!!a,n.isFinal=!!r,a&&(t.session={}),n.eventType=e,function(t,e){var n=t.session,i=e.pointers,o=i.length;n.firstInput||(n.firstInput=B(e));o>1&&!n.firstMultiple?n.firstMultiple=B(e):1===o&&(n.firstMultiple=!1);var a=n.firstInput,r=n.firstMultiple,c=r?r.center:a.center,h=e.center=H(i);e.timeStamp=d(),e.deltaTime=e.timeStamp-a.timeStamp,e.angle=U(c,h),e.distance=Y(c,h),function(t,e){var n=e.center,i=t.offsetDelta||{},s=t.prevDelta||{},o=t.prevInput||{};1!==e.eventType&&4!==o.eventType||(s=t.prevDelta={x:o.deltaX||0,y:o.deltaY||0},i=t.offsetDelta={x:n.x,y:n.y});e.deltaX=s.x+(n.x-i.x),e.deltaY=s.y+(n.y-i.y)}(n,e),e.offsetDirection=j(e.deltaX,e.deltaY);var u=V(e.deltaTime,e.deltaX,e.deltaY);e.overallVelocityX=u.x,e.overallVelocityY=u.y,e.overallVelocity=l(u.x)>l(u.y)?u.x:u.y,e.scale=r?(g=r.pointers,p=i,Y(p[0],p[1],$)/Y(g[0],g[1],$)):1,e.rotation=r?function(t,e){return U(e[1],e[0],$)+U(t[1],t[0],$)}(r.pointers,i):0,e.maxPointers=n.prevInput?e.pointers.length>n.prevInput.maxPointers?e.pointers.length:n.prevInput.maxPointers:e.pointers.length,function(t,e){var n,i,o,a,r=t.lastInterval||e,c=e.timeStamp-r.timeStamp;if(8!=e.eventType&&(c>25||r.velocity===s)){var d=e.deltaX-r.deltaX,h=e.deltaY-r.deltaY,u=V(c,d,h);i=u.x,o=u.y,n=l(u.x)>l(u.y)?u.x:u.y,a=j(d,h),t.lastInterval=e}else n=r.velocity,i=r.velocityX,o=r.velocityY,a=r.direction;e.velocity=n,e.velocityX=i,e.velocityY=o,e.direction=a}(n,e);var g,p;var m=t.element;k(e.srcEvent.target,m)&&(m=e.srcEvent.target);e.target=m}(t,n),t.emit("hammer.input",n),t.recognize(n),t.session.prevInput=n}function B(t){for(var e=[],n=0;n<t.pointers.length;)e[n]={clientX:c(t.pointers[n].clientX),clientY:c(t.pointers[n].clientY)},n++;return{timeStamp:d(),pointers:e,center:H(e),deltaX:t.deltaX,deltaY:t.deltaY}}function H(t){var e=t.length;if(1===e)return{x:c(t[0].clientX),y:c(t[0].clientY)};for(var n=0,i=0,s=0;s<e;)n+=t[s].clientX,i+=t[s].clientY,s++;return{x:c(n/e),y:c(i/e)}}function V(t,e,n){return{x:e/t||0,y:n/t||0}}function j(t,e){return t===e?1:l(t)>=l(e)?t<0?2:4:e<0?8:16}function Y(t,e,n){n||(n=R);var i=e[n[0]]-t[n[0]],s=e[n[1]]-t[n[1]];return Math.sqrt(i*i+s*s)}function U(t,e,n){n||(n=R);var i=e[n[0]]-t[n[0]],s=e[n[1]]-t[n[1]];return 180*Math.atan2(s,i)/Math.PI}F.prototype={handler:function(){},init:function(){this.evEl&&w(this.element,this.evEl,this.domHandler),this.evTarget&&w(this.target,this.evTarget,this.domHandler),this.evWin&&w(A(this.element),this.evWin,this.domHandler)},destroy:function(){this.evEl&&S(this.element,this.evEl,this.domHandler),this.evTarget&&S(this.target,this.evTarget,this.domHandler),this.evWin&&S(A(this.element),this.evWin,this.domHandler)}};var X={mousedown:1,mousemove:2,mouseup:4},Q="mousedown",K="mousemove mouseup";function Z(){this.evEl=Q,this.evWin=K,this.pressed=!1,F.apply(this,arguments)}b(Z,F,{handler:function(t){var e=X[t.type];1&e&&0===t.button&&(this.pressed=!0),2&e&&1!==t.which&&(e=4),this.pressed&&(4&e&&(this.pressed=!1),this.callback(this.manager,e,{pointers:[t],changedPointers:[t],pointerType:W,srcEvent:t}))}});var G={pointerdown:1,pointermove:2,pointerup:4,pointercancel:8,pointerout:8},J={2:z,3:"pen",4:W,5:"kinect"},tt="pointerdown",et="pointermove pointerup pointercancel";function nt(){this.evEl=tt,this.evWin=et,F.apply(this,arguments),this.store=this.manager.session.pointerEvents=[]}e.MSPointerEvent&&!e.PointerEvent&&(tt="MSPointerDown",et="MSPointerMove MSPointerUp MSPointerCancel"),b(nt,F,{handler:function(t){var e=this.store,n=!1,i=t.type.toLowerCase().replace("ms",""),s=G[i],o=J[t.pointerType]||t.pointerType,a=o==z,r=C(e,t.pointerId,"pointerId");1&s&&(0===t.button||a)?r<0&&(e.push(t),r=e.length-1):12&s&&(n=!0),r<0||(e[r]=t,this.callback(this.manager,s,{pointers:e,changedPointers:[t],pointerType:o,srcEvent:t}),n&&e.splice(r,1))}});var it={touchstart:1,touchmove:2,touchend:4,touchcancel:8};function st(){this.evTarget="touchstart",this.evWin="touchstart touchmove touchend touchcancel",this.started=!1,F.apply(this,arguments)}function ot(t,e){var n=T(t.touches),i=T(t.changedTouches);return 12&e&&(n=D(n.concat(i),"identifier",!0)),[n,i]}b(st,F,{handler:function(t){var e=it[t.type];if(1===e&&(this.started=!0),this.started){var n=ot.call(this,t,e);12&e&&n[0].length-n[1].length===0&&(this.started=!1),this.callback(this.manager,e,{pointers:n[0],changedPointers:n[1],pointerType:z,srcEvent:t})}}});var at={touchstart:1,touchmove:2,touchend:4,touchcancel:8},rt="touchstart touchmove touchend touchcancel";function ct(){this.evTarget=rt,this.targetIds={},F.apply(this,arguments)}function lt(t,e){var n=T(t.touches),i=this.targetIds;if(3&e&&1===n.length)return i[n[0].identifier]=!0,[n,n];var s,o,a=T(t.changedTouches),r=[],c=this.target;if(o=n.filter((function(t){return k(t.target,c)})),1===e)for(s=0;s<o.length;)i[o[s].identifier]=!0,s++;for(s=0;s<a.length;)i[a[s].identifier]&&r.push(a[s]),12&e&&delete i[a[s].identifier],s++;return r.length?[D(o.concat(r),"identifier",!0),r]:void 0}b(ct,F,{handler:function(t){var e=at[t.type],n=lt.call(this,t,e);n&&this.callback(this.manager,e,{pointers:n[0],changedPointers:n[1],pointerType:z,srcEvent:t})}});function dt(){F.apply(this,arguments);var t=y(this.handler,this);this.touch=new ct(this.manager,t),this.mouse=new Z(this.manager,t),this.primaryTouch=null,this.lastTouches=[]}function ht(t,e){1&t?(this.primaryTouch=e.changedPointers[0].identifier,ut.call(this,e)):12&t&&ut.call(this,e)}function ut(t){var e=t.changedPointers[0];if(e.identifier===this.primaryTouch){var n={x:e.clientX,y:e.clientY};this.lastTouches.push(n);var i=this.lastTouches;setTimeout((function(){var t=i.indexOf(n);t>-1&&i.splice(t,1)}),2500)}}function gt(t){for(var e=t.srcEvent.clientX,n=t.srcEvent.clientY,i=0;i<this.lastTouches.length;i++){var s=this.lastTouches[i],o=Math.abs(e-s.x),a=Math.abs(n-s.y);if(o<=25&&a<=25)return!0}return!1}b(dt,F,{handler:function(t,e,n){var i=n.pointerType==z,s=n.pointerType==W;if(!(s&&n.sourceCapabilities&&n.sourceCapabilities.firesTouchEvents)){if(i)ht.call(this,e,n);else if(s&>.call(this,n))return;this.callback(t,e,n)}},destroy:function(){this.touch.destroy(),this.mouse.destroy()}});var pt=P(r.style,"touchAction"),mt=pt!==s,ft="compute",bt="auto",yt="manipulation",xt="none",vt="pan-x",wt="pan-y",St=function(){if(!mt)return!1;var t={},n=e.CSS&&e.CSS.supports;return["auto","manipulation","pan-y","pan-x","pan-x pan-y","none"].forEach((function(i){t[i]=!n||e.CSS.supports("touch-action",i)})),t}();function kt(t,e){this.manager=t,this.set(e)}kt.prototype={set:function(t){t==ft&&(t=this.compute()),mt&&this.manager.element.style&&St[t]&&(this.manager.element.style[pt]=t),this.actions=t.toLowerCase().trim()},update:function(){this.set(this.manager.options.touchAction)},compute:function(){var t=[];return g(this.manager.recognizers,(function(e){x(e.options.enable,[e])&&(t=t.concat(e.getTouchAction()))})),function(t){if(M(t,xt))return xt;var e=M(t,vt),n=M(t,wt);if(e&&n)return xt;if(e||n)return e?vt:wt;if(M(t,yt))return yt;return bt}(t.join(" "))},preventDefaults:function(t){var e=t.srcEvent,n=t.offsetDirection;if(this.manager.session.prevented)e.preventDefault();else{var i=this.actions,s=M(i,xt)&&!St[xt],o=M(i,wt)&&!St[wt],a=M(i,vt)&&!St[vt];if(s){var r=1===t.pointers.length,c=t.distance<2,l=t.deltaTime<250;if(r&&c&&l)return}if(!a||!o)return s||o&&6&n||a&&n&N?this.preventSrc(e):void 0}},preventSrc:function(t){this.manager.session.prevented=!0,t.preventDefault()}};var Mt=32;function _t(t){this.options=o({},this.defaults,t||{}),this.id=E++,this.manager=null,this.options.enable=v(this.options.enable,!0),this.state=1,this.simultaneous={},this.requireFail=[]}function Ct(t){return 16&t?"cancel":8&t?"end":4&t?"move":2&t?"start":""}function Tt(t){return 16==t?"down":8==t?"up":2==t?"left":4==t?"right":""}function Dt(t,e){var n=e.manager;return n?n.get(t):t}function Pt(){_t.apply(this,arguments)}function Et(){Pt.apply(this,arguments),this.pX=null,this.pY=null}function At(){Pt.apply(this,arguments)}function Lt(){_t.apply(this,arguments),this._timer=null,this._input=null}function It(){Pt.apply(this,arguments)}function Ot(){Pt.apply(this,arguments)}function zt(){_t.apply(this,arguments),this.pTime=!1,this.pCenter=!1,this._timer=null,this._input=null,this.count=0}function Wt(t,e){return(e=e||{}).recognizers=v(e.recognizers,Wt.defaults.preset),new Nt(t,e)}_t.prototype={defaults:{},set:function(t){return o(this.options,t),this.manager&&this.manager.touchAction.update(),this},recognizeWith:function(t){if(u(t,"recognizeWith",this))return this;var e=this.simultaneous;return e[(t=Dt(t,this)).id]||(e[t.id]=t,t.recognizeWith(this)),this},dropRecognizeWith:function(t){return u(t,"dropRecognizeWith",this)||(t=Dt(t,this),delete this.simultaneous[t.id]),this},requireFailure:function(t){if(u(t,"requireFailure",this))return this;var e=this.requireFail;return-1===C(e,t=Dt(t,this))&&(e.push(t),t.requireFailure(this)),this},dropRequireFailure:function(t){if(u(t,"dropRequireFailure",this))return this;t=Dt(t,this);var e=C(this.requireFail,t);return e>-1&&this.requireFail.splice(e,1),this},hasRequireFailures:function(){return this.requireFail.length>0},canRecognizeWith:function(t){return!!this.simultaneous[t.id]},emit:function(t){var e=this,n=this.state;function i(n){e.manager.emit(n,t)}n<8&&i(e.options.event+Ct(n)),i(e.options.event),t.additionalEvent&&i(t.additionalEvent),n>=8&&i(e.options.event+Ct(n))},tryEmit:function(t){if(this.canEmit())return this.emit(t);this.state=Mt},canEmit:function(){for(var t=0;t<this.requireFail.length;){if(!(33&this.requireFail[t].state))return!1;t++}return!0},recognize:function(t){var e=o({},t);if(!x(this.options.enable,[this,e]))return this.reset(),void(this.state=Mt);56&this.state&&(this.state=1),this.state=this.process(e),30&this.state&&this.tryEmit(e)},process:function(t){},getTouchAction:function(){},reset:function(){}},b(Pt,_t,{defaults:{pointers:1},attrTest:function(t){var e=this.options.pointers;return 0===e||t.pointers.length===e},process:function(t){var e=this.state,n=t.eventType,i=6&e,s=this.attrTest(t);return i&&(8&n||!s)?16|e:i||s?4&n?8|e:2&e?4|e:2:Mt}}),b(Et,Pt,{defaults:{event:"pan",threshold:10,pointers:1,direction:30},getTouchAction:function(){var t=this.options.direction,e=[];return 6&t&&e.push(wt),t&N&&e.push(vt),e},directionTest:function(t){var e=this.options,n=!0,i=t.distance,s=t.direction,o=t.deltaX,a=t.deltaY;return s&e.direction||(6&e.direction?(s=0===o?1:o<0?2:4,n=o!=this.pX,i=Math.abs(t.deltaX)):(s=0===a?1:a<0?8:16,n=a!=this.pY,i=Math.abs(t.deltaY))),t.direction=s,n&&i>e.threshold&&s&e.direction},attrTest:function(t){return Pt.prototype.attrTest.call(this,t)&&(2&this.state||!(2&this.state)&&this.directionTest(t))},emit:function(t){this.pX=t.deltaX,this.pY=t.deltaY;var e=Tt(t.direction);e&&(t.additionalEvent=this.options.event+e),this._super.emit.call(this,t)}}),b(At,Pt,{defaults:{event:"pinch",threshold:0,pointers:2},getTouchAction:function(){return[xt]},attrTest:function(t){return this._super.attrTest.call(this,t)&&(Math.abs(t.scale-1)>this.options.threshold||2&this.state)},emit:function(t){if(1!==t.scale){var e=t.scale<1?"in":"out";t.additionalEvent=this.options.event+e}this._super.emit.call(this,t)}}),b(Lt,_t,{defaults:{event:"press",pointers:1,time:251,threshold:9},getTouchAction:function(){return[bt]},process:function(t){var e=this.options,n=t.pointers.length===e.pointers,i=t.distance<e.threshold,s=t.deltaTime>e.time;if(this._input=t,!i||!n||12&t.eventType&&!s)this.reset();else if(1&t.eventType)this.reset(),this._timer=h((function(){this.state=8,this.tryEmit()}),e.time,this);else if(4&t.eventType)return 8;return Mt},reset:function(){clearTimeout(this._timer)},emit:function(t){8===this.state&&(t&&4&t.eventType?this.manager.emit(this.options.event+"up",t):(this._input.timeStamp=d(),this.manager.emit(this.options.event,this._input)))}}),b(It,Pt,{defaults:{event:"rotate",threshold:0,pointers:2},getTouchAction:function(){return[xt]},attrTest:function(t){return this._super.attrTest.call(this,t)&&(Math.abs(t.rotation)>this.options.threshold||2&this.state)}}),b(Ot,Pt,{defaults:{event:"swipe",threshold:10,velocity:.3,direction:30,pointers:1},getTouchAction:function(){return Et.prototype.getTouchAction.call(this)},attrTest:function(t){var e,n=this.options.direction;return 30&n?e=t.overallVelocity:6&n?e=t.overallVelocityX:n&N&&(e=t.overallVelocityY),this._super.attrTest.call(this,t)&&n&t.offsetDirection&&t.distance>this.options.threshold&&t.maxPointers==this.options.pointers&&l(e)>this.options.velocity&&4&t.eventType},emit:function(t){var e=Tt(t.offsetDirection);e&&this.manager.emit(this.options.event+e,t),this.manager.emit(this.options.event,t)}}),b(zt,_t,{defaults:{event:"tap",pointers:1,taps:1,interval:300,time:250,threshold:9,posThreshold:10},getTouchAction:function(){return[yt]},process:function(t){var e=this.options,n=t.pointers.length===e.pointers,i=t.distance<e.threshold,s=t.deltaTime<e.time;if(this.reset(),1&t.eventType&&0===this.count)return this.failTimeout();if(i&&s&&n){if(4!=t.eventType)return this.failTimeout();var o=!this.pTime||t.timeStamp-this.pTime<e.interval,a=!this.pCenter||Y(this.pCenter,t.center)<e.posThreshold;if(this.pTime=t.timeStamp,this.pCenter=t.center,a&&o?this.count+=1:this.count=1,this._input=t,0===this.count%e.taps)return this.hasRequireFailures()?(this._timer=h((function(){this.state=8,this.tryEmit()}),e.interval,this),2):8}return Mt},failTimeout:function(){return this._timer=h((function(){this.state=Mt}),this.options.interval,this),Mt},reset:function(){clearTimeout(this._timer)},emit:function(){8==this.state&&(this._input.tapCount=this.count,this.manager.emit(this.options.event,this._input))}}),Wt.VERSION="2.0.7",Wt.defaults={domEvents:!1,touchAction:ft,enable:!0,inputTarget:null,inputClass:null,preset:[[It,{enable:!1}],[At,{enable:!1},["rotate"]],[Ot,{direction:6}],[Et,{direction:6},["swipe"]],[zt],[zt,{event:"doubletap",taps:2},["tap"]],[Lt]],cssProps:{userSelect:"none",touchSelect:"none",touchCallout:"none",contentZooming:"none",userDrag:"none",tapHighlightColor:"rgba(0,0,0,0)"}};function Nt(t,e){var n;this.options=o({},Wt.defaults,e||{}),this.options.inputTarget=this.options.inputTarget||t,this.handlers={},this.session={},this.recognizers=[],this.oldCssProps={},this.element=t,this.input=new((n=this).options.inputClass||(I?nt:O?ct:L?dt:Z))(n,q),this.touchAction=new kt(this,this.options.touchAction),Rt(this,!0),g(this.options.recognizers,(function(t){var e=this.add(new t[0](t[1]));t[2]&&e.recognizeWith(t[2]),t[3]&&e.requireFailure(t[3])}),this)}function Rt(t,e){var n,i=t.element;i.style&&(g(t.options.cssProps,(function(s,o){n=P(i.style,o),e?(t.oldCssProps[n]=i.style[n],i.style[n]=s):i.style[n]=t.oldCssProps[n]||""})),e||(t.oldCssProps={}))}Nt.prototype={set:function(t){return o(this.options,t),t.touchAction&&this.touchAction.update(),t.inputTarget&&(this.input.destroy(),this.input.target=t.inputTarget,this.input.init()),this},stop:function(t){this.session.stopped=t?2:1},recognize:function(t){var e=this.session;if(!e.stopped){var n;this.touchAction.preventDefaults(t);var i=this.recognizers,s=e.curRecognizer;(!s||s&&8&s.state)&&(s=e.curRecognizer=null);for(var o=0;o<i.length;)n=i[o],2===e.stopped||s&&n!=s&&!n.canRecognizeWith(s)?n.reset():n.recognize(t),!s&&14&n.state&&(s=e.curRecognizer=n),o++}},get:function(t){if(t instanceof _t)return t;for(var e=this.recognizers,n=0;n<e.length;n++)if(e[n].options.event==t)return e[n];return null},add:function(t){if(u(t,"add",this))return this;var e=this.get(t.options.event);return e&&this.remove(e),this.recognizers.push(t),t.manager=this,this.touchAction.update(),t},remove:function(t){if(u(t,"remove",this))return this;if(t=this.get(t)){var e=this.recognizers,n=C(e,t);-1!==n&&(e.splice(n,1),this.touchAction.update())}return this},on:function(t,e){if(t!==s&&e!==s){var n=this.handlers;return g(_(t),(function(t){n[t]=n[t]||[],n[t].push(e)})),this}},off:function(t,e){if(t!==s){var n=this.handlers;return g(_(t),(function(t){e?n[t]&&n[t].splice(C(n[t],e),1):delete n[t]})),this}},emit:function(t,e){this.options.domEvents&&function(t,e){var i=n.createEvent("Event");i.initEvent(t,!0,!0),i.gesture=e,e.target.dispatchEvent(i)}(t,e);var i=this.handlers[t]&&this.handlers[t].slice();if(i&&i.length){e.type=t,e.preventDefault=function(){e.srcEvent.preventDefault()};for(var s=0;s<i.length;)i[s](e),s++}},destroy:function(){this.element&&Rt(this,!1),this.handlers={},this.session={},this.input.destroy(),this.element=null}},o(Wt,{INPUT_START:1,INPUT_MOVE:2,INPUT_END:4,INPUT_CANCEL:8,STATE_POSSIBLE:1,STATE_BEGAN:2,STATE_CHANGED:4,STATE_ENDED:8,STATE_RECOGNIZED:8,STATE_CANCELLED:16,STATE_FAILED:Mt,DIRECTION_NONE:1,DIRECTION_LEFT:2,DIRECTION_RIGHT:4,DIRECTION_UP:8,DIRECTION_DOWN:16,DIRECTION_HORIZONTAL:6,DIRECTION_VERTICAL:N,DIRECTION_ALL:30,Manager:Nt,Input:F,TouchAction:kt,TouchInput:ct,MouseInput:Z,PointerEventInput:nt,TouchMouseInput:dt,SingleTouchInput:st,Recognizer:_t,AttrRecognizer:Pt,Tap:zt,Pan:Et,Swipe:Ot,Pinch:At,Rotate:It,Press:Lt,on:w,off:S,each:g,merge:f,extend:m,assign:o,inherit:b,bindFn:y,prefixed:P}),(void 0!==e?e:"undefined"!=typeof self?self:{}).Hammer=Wt,t.exports?t.exports=Wt:e.Hammer=Wt}(window,document)}(Sh);var kh=wh(Sh.exports);
|
|
38
|
+
* Licensed under the MIT license */!function(t){!function(e,n,i,s){var o,a=["","webkit","Moz","MS","ms","o"],r=n.createElement("div"),c=Math.round,l=Math.abs,d=Date.now;function h(t,e,n){return setTimeout(y(t,n),e)}function u(t,e,n){return!!Array.isArray(t)&&(g(t,n[e],n),!0)}function g(t,e,n){var i;if(t)if(t.forEach)t.forEach(e,n);else if(t.length!==s)for(i=0;i<t.length;)e.call(n,t[i],i,t),i++;else for(i in t)t.hasOwnProperty(i)&&e.call(n,t[i],i,t)}function p(t,n,i){var s="DEPRECATED METHOD: "+n+"\n"+i+" AT \n";return function(){var n=new Error("get-stack-trace"),i=n&&n.stack?n.stack.replace(/^[^\(]+?[\n$]/gm,"").replace(/^\s+at\s+/gm,"").replace(/^Object.<anonymous>\s*\(/gm,"{anonymous}()@"):"Unknown Stack Trace",o=e.console&&(e.console.warn||e.console.log);return o&&o.call(e.console,s,i),t.apply(this,arguments)}}o="function"!=typeof Object.assign?function(t){if(t===s||null===t)throw new TypeError("Cannot convert undefined or null to object");for(var e=Object(t),n=1;n<arguments.length;n++){var i=arguments[n];if(i!==s&&null!==i)for(var o in i)i.hasOwnProperty(o)&&(e[o]=i[o])}return e}:Object.assign;var m=p((function(t,e,n){for(var i=Object.keys(e),o=0;o<i.length;)(!n||n&&t[i[o]]===s)&&(t[i[o]]=e[i[o]]),o++;return t}),"extend","Use `assign`."),f=p((function(t,e){return m(t,e,!0)}),"merge","Use `assign`.");function b(t,e,n){var i,s=e.prototype;(i=t.prototype=Object.create(s)).constructor=t,i._super=s,n&&o(i,n)}function y(t,e){return function(){return t.apply(e,arguments)}}function x(t,e){return"function"==typeof t?t.apply(e&&e[0]||s,e):t}function v(t,e){return t===s?e:t}function w(t,e,n){g(C(e),(function(e){t.addEventListener(e,n,!1)}))}function S(t,e,n){g(C(e),(function(e){t.removeEventListener(e,n,!1)}))}function k(t,e){for(;t;){if(t==e)return!0;t=t.parentNode}return!1}function M(t,e){return t.indexOf(e)>-1}function C(t){return t.trim().split(/\s+/g)}function _(t,e,n){if(t.indexOf&&!n)return t.indexOf(e);for(var i=0;i<t.length;){if(n&&t[i][n]==e||!n&&t[i]===e)return i;i++}return-1}function D(t){return Array.prototype.slice.call(t,0)}function T(t,e,n){for(var i=[],s=[],o=0;o<t.length;){var a=e?t[o][e]:t[o];_(s,a)<0&&i.push(t[o]),s[o]=a,o++}return n&&(i=e?i.sort((function(t,n){return t[e]>n[e]})):i.sort()),i}function P(t,e){for(var n,i,o=e[0].toUpperCase()+e.slice(1),r=0;r<a.length;){if((i=(n=a[r])?n+o:e)in t)return i;r++}return s}var E=1;function A(t){var n=t.ownerDocument||t;return n.defaultView||n.parentWindow||e}var L="ontouchstart"in e,I=P(e,"PointerEvent")!==s,O=L&&/mobile|tablet|ip(ad|hone|od)|android/i.test(navigator.userAgent),z="touch",W="mouse",N=24,R=["x","y"],$=["clientX","clientY"];function F(t,e){var n=this;this.manager=t,this.callback=e,this.element=t.element,this.target=t.options.inputTarget,this.domHandler=function(e){x(t.options.enable,[t])&&n.handler(e)},this.init()}function q(t,e,n){var i=n.pointers.length,o=n.changedPointers.length,a=1&e&&i-o===0,r=12&e&&i-o===0;n.isFirst=!!a,n.isFinal=!!r,a&&(t.session={}),n.eventType=e,function(t,e){var n=t.session,i=e.pointers,o=i.length;n.firstInput||(n.firstInput=B(e));o>1&&!n.firstMultiple?n.firstMultiple=B(e):1===o&&(n.firstMultiple=!1);var a=n.firstInput,r=n.firstMultiple,c=r?r.center:a.center,h=e.center=H(i);e.timeStamp=d(),e.deltaTime=e.timeStamp-a.timeStamp,e.angle=U(c,h),e.distance=Y(c,h),function(t,e){var n=e.center,i=t.offsetDelta||{},s=t.prevDelta||{},o=t.prevInput||{};1!==e.eventType&&4!==o.eventType||(s=t.prevDelta={x:o.deltaX||0,y:o.deltaY||0},i=t.offsetDelta={x:n.x,y:n.y});e.deltaX=s.x+(n.x-i.x),e.deltaY=s.y+(n.y-i.y)}(n,e),e.offsetDirection=j(e.deltaX,e.deltaY);var u=V(e.deltaTime,e.deltaX,e.deltaY);e.overallVelocityX=u.x,e.overallVelocityY=u.y,e.overallVelocity=l(u.x)>l(u.y)?u.x:u.y,e.scale=r?(g=r.pointers,p=i,Y(p[0],p[1],$)/Y(g[0],g[1],$)):1,e.rotation=r?function(t,e){return U(e[1],e[0],$)+U(t[1],t[0],$)}(r.pointers,i):0,e.maxPointers=n.prevInput?e.pointers.length>n.prevInput.maxPointers?e.pointers.length:n.prevInput.maxPointers:e.pointers.length,function(t,e){var n,i,o,a,r=t.lastInterval||e,c=e.timeStamp-r.timeStamp;if(8!=e.eventType&&(c>25||r.velocity===s)){var d=e.deltaX-r.deltaX,h=e.deltaY-r.deltaY,u=V(c,d,h);i=u.x,o=u.y,n=l(u.x)>l(u.y)?u.x:u.y,a=j(d,h),t.lastInterval=e}else n=r.velocity,i=r.velocityX,o=r.velocityY,a=r.direction;e.velocity=n,e.velocityX=i,e.velocityY=o,e.direction=a}(n,e);var g,p;var m=t.element;k(e.srcEvent.target,m)&&(m=e.srcEvent.target);e.target=m}(t,n),t.emit("hammer.input",n),t.recognize(n),t.session.prevInput=n}function B(t){for(var e=[],n=0;n<t.pointers.length;)e[n]={clientX:c(t.pointers[n].clientX),clientY:c(t.pointers[n].clientY)},n++;return{timeStamp:d(),pointers:e,center:H(e),deltaX:t.deltaX,deltaY:t.deltaY}}function H(t){var e=t.length;if(1===e)return{x:c(t[0].clientX),y:c(t[0].clientY)};for(var n=0,i=0,s=0;s<e;)n+=t[s].clientX,i+=t[s].clientY,s++;return{x:c(n/e),y:c(i/e)}}function V(t,e,n){return{x:e/t||0,y:n/t||0}}function j(t,e){return t===e?1:l(t)>=l(e)?t<0?2:4:e<0?8:16}function Y(t,e,n){n||(n=R);var i=e[n[0]]-t[n[0]],s=e[n[1]]-t[n[1]];return Math.sqrt(i*i+s*s)}function U(t,e,n){n||(n=R);var i=e[n[0]]-t[n[0]],s=e[n[1]]-t[n[1]];return 180*Math.atan2(s,i)/Math.PI}F.prototype={handler:function(){},init:function(){this.evEl&&w(this.element,this.evEl,this.domHandler),this.evTarget&&w(this.target,this.evTarget,this.domHandler),this.evWin&&w(A(this.element),this.evWin,this.domHandler)},destroy:function(){this.evEl&&S(this.element,this.evEl,this.domHandler),this.evTarget&&S(this.target,this.evTarget,this.domHandler),this.evWin&&S(A(this.element),this.evWin,this.domHandler)}};var X={mousedown:1,mousemove:2,mouseup:4},Q="mousedown",K="mousemove mouseup";function G(){this.evEl=Q,this.evWin=K,this.pressed=!1,F.apply(this,arguments)}b(G,F,{handler:function(t){var e=X[t.type];1&e&&0===t.button&&(this.pressed=!0),2&e&&1!==t.which&&(e=4),this.pressed&&(4&e&&(this.pressed=!1),this.callback(this.manager,e,{pointers:[t],changedPointers:[t],pointerType:W,srcEvent:t}))}});var Z={pointerdown:1,pointermove:2,pointerup:4,pointercancel:8,pointerout:8},J={2:z,3:"pen",4:W,5:"kinect"},tt="pointerdown",et="pointermove pointerup pointercancel";function nt(){this.evEl=tt,this.evWin=et,F.apply(this,arguments),this.store=this.manager.session.pointerEvents=[]}e.MSPointerEvent&&!e.PointerEvent&&(tt="MSPointerDown",et="MSPointerMove MSPointerUp MSPointerCancel"),b(nt,F,{handler:function(t){var e=this.store,n=!1,i=t.type.toLowerCase().replace("ms",""),s=Z[i],o=J[t.pointerType]||t.pointerType,a=o==z,r=_(e,t.pointerId,"pointerId");1&s&&(0===t.button||a)?r<0&&(e.push(t),r=e.length-1):12&s&&(n=!0),r<0||(e[r]=t,this.callback(this.manager,s,{pointers:e,changedPointers:[t],pointerType:o,srcEvent:t}),n&&e.splice(r,1))}});var it={touchstart:1,touchmove:2,touchend:4,touchcancel:8};function st(){this.evTarget="touchstart",this.evWin="touchstart touchmove touchend touchcancel",this.started=!1,F.apply(this,arguments)}function ot(t,e){var n=D(t.touches),i=D(t.changedTouches);return 12&e&&(n=T(n.concat(i),"identifier",!0)),[n,i]}b(st,F,{handler:function(t){var e=it[t.type];if(1===e&&(this.started=!0),this.started){var n=ot.call(this,t,e);12&e&&n[0].length-n[1].length===0&&(this.started=!1),this.callback(this.manager,e,{pointers:n[0],changedPointers:n[1],pointerType:z,srcEvent:t})}}});var at={touchstart:1,touchmove:2,touchend:4,touchcancel:8},rt="touchstart touchmove touchend touchcancel";function ct(){this.evTarget=rt,this.targetIds={},F.apply(this,arguments)}function lt(t,e){var n=D(t.touches),i=this.targetIds;if(3&e&&1===n.length)return i[n[0].identifier]=!0,[n,n];var s,o,a=D(t.changedTouches),r=[],c=this.target;if(o=n.filter((function(t){return k(t.target,c)})),1===e)for(s=0;s<o.length;)i[o[s].identifier]=!0,s++;for(s=0;s<a.length;)i[a[s].identifier]&&r.push(a[s]),12&e&&delete i[a[s].identifier],s++;return r.length?[T(o.concat(r),"identifier",!0),r]:void 0}b(ct,F,{handler:function(t){var e=at[t.type],n=lt.call(this,t,e);n&&this.callback(this.manager,e,{pointers:n[0],changedPointers:n[1],pointerType:z,srcEvent:t})}});function dt(){F.apply(this,arguments);var t=y(this.handler,this);this.touch=new ct(this.manager,t),this.mouse=new G(this.manager,t),this.primaryTouch=null,this.lastTouches=[]}function ht(t,e){1&t?(this.primaryTouch=e.changedPointers[0].identifier,ut.call(this,e)):12&t&&ut.call(this,e)}function ut(t){var e=t.changedPointers[0];if(e.identifier===this.primaryTouch){var n={x:e.clientX,y:e.clientY};this.lastTouches.push(n);var i=this.lastTouches;setTimeout((function(){var t=i.indexOf(n);t>-1&&i.splice(t,1)}),2500)}}function gt(t){for(var e=t.srcEvent.clientX,n=t.srcEvent.clientY,i=0;i<this.lastTouches.length;i++){var s=this.lastTouches[i],o=Math.abs(e-s.x),a=Math.abs(n-s.y);if(o<=25&&a<=25)return!0}return!1}b(dt,F,{handler:function(t,e,n){var i=n.pointerType==z,s=n.pointerType==W;if(!(s&&n.sourceCapabilities&&n.sourceCapabilities.firesTouchEvents)){if(i)ht.call(this,e,n);else if(s&>.call(this,n))return;this.callback(t,e,n)}},destroy:function(){this.touch.destroy(),this.mouse.destroy()}});var pt=P(r.style,"touchAction"),mt=pt!==s,ft="compute",bt="auto",yt="manipulation",xt="none",vt="pan-x",wt="pan-y",St=function(){if(!mt)return!1;var t={},n=e.CSS&&e.CSS.supports;return["auto","manipulation","pan-y","pan-x","pan-x pan-y","none"].forEach((function(i){t[i]=!n||e.CSS.supports("touch-action",i)})),t}();function kt(t,e){this.manager=t,this.set(e)}kt.prototype={set:function(t){t==ft&&(t=this.compute()),mt&&this.manager.element.style&&St[t]&&(this.manager.element.style[pt]=t),this.actions=t.toLowerCase().trim()},update:function(){this.set(this.manager.options.touchAction)},compute:function(){var t=[];return g(this.manager.recognizers,(function(e){x(e.options.enable,[e])&&(t=t.concat(e.getTouchAction()))})),function(t){if(M(t,xt))return xt;var e=M(t,vt),n=M(t,wt);if(e&&n)return xt;if(e||n)return e?vt:wt;if(M(t,yt))return yt;return bt}(t.join(" "))},preventDefaults:function(t){var e=t.srcEvent,n=t.offsetDirection;if(this.manager.session.prevented)e.preventDefault();else{var i=this.actions,s=M(i,xt)&&!St[xt],o=M(i,wt)&&!St[wt],a=M(i,vt)&&!St[vt];if(s){var r=1===t.pointers.length,c=t.distance<2,l=t.deltaTime<250;if(r&&c&&l)return}if(!a||!o)return s||o&&6&n||a&&n&N?this.preventSrc(e):void 0}},preventSrc:function(t){this.manager.session.prevented=!0,t.preventDefault()}};var Mt=32;function Ct(t){this.options=o({},this.defaults,t||{}),this.id=E++,this.manager=null,this.options.enable=v(this.options.enable,!0),this.state=1,this.simultaneous={},this.requireFail=[]}function _t(t){return 16&t?"cancel":8&t?"end":4&t?"move":2&t?"start":""}function Dt(t){return 16==t?"down":8==t?"up":2==t?"left":4==t?"right":""}function Tt(t,e){var n=e.manager;return n?n.get(t):t}function Pt(){Ct.apply(this,arguments)}function Et(){Pt.apply(this,arguments),this.pX=null,this.pY=null}function At(){Pt.apply(this,arguments)}function Lt(){Ct.apply(this,arguments),this._timer=null,this._input=null}function It(){Pt.apply(this,arguments)}function Ot(){Pt.apply(this,arguments)}function zt(){Ct.apply(this,arguments),this.pTime=!1,this.pCenter=!1,this._timer=null,this._input=null,this.count=0}function Wt(t,e){return(e=e||{}).recognizers=v(e.recognizers,Wt.defaults.preset),new Nt(t,e)}Ct.prototype={defaults:{},set:function(t){return o(this.options,t),this.manager&&this.manager.touchAction.update(),this},recognizeWith:function(t){if(u(t,"recognizeWith",this))return this;var e=this.simultaneous;return e[(t=Tt(t,this)).id]||(e[t.id]=t,t.recognizeWith(this)),this},dropRecognizeWith:function(t){return u(t,"dropRecognizeWith",this)||(t=Tt(t,this),delete this.simultaneous[t.id]),this},requireFailure:function(t){if(u(t,"requireFailure",this))return this;var e=this.requireFail;return-1===_(e,t=Tt(t,this))&&(e.push(t),t.requireFailure(this)),this},dropRequireFailure:function(t){if(u(t,"dropRequireFailure",this))return this;t=Tt(t,this);var e=_(this.requireFail,t);return e>-1&&this.requireFail.splice(e,1),this},hasRequireFailures:function(){return this.requireFail.length>0},canRecognizeWith:function(t){return!!this.simultaneous[t.id]},emit:function(t){var e=this,n=this.state;function i(n){e.manager.emit(n,t)}n<8&&i(e.options.event+_t(n)),i(e.options.event),t.additionalEvent&&i(t.additionalEvent),n>=8&&i(e.options.event+_t(n))},tryEmit:function(t){if(this.canEmit())return this.emit(t);this.state=Mt},canEmit:function(){for(var t=0;t<this.requireFail.length;){if(!(33&this.requireFail[t].state))return!1;t++}return!0},recognize:function(t){var e=o({},t);if(!x(this.options.enable,[this,e]))return this.reset(),void(this.state=Mt);56&this.state&&(this.state=1),this.state=this.process(e),30&this.state&&this.tryEmit(e)},process:function(t){},getTouchAction:function(){},reset:function(){}},b(Pt,Ct,{defaults:{pointers:1},attrTest:function(t){var e=this.options.pointers;return 0===e||t.pointers.length===e},process:function(t){var e=this.state,n=t.eventType,i=6&e,s=this.attrTest(t);return i&&(8&n||!s)?16|e:i||s?4&n?8|e:2&e?4|e:2:Mt}}),b(Et,Pt,{defaults:{event:"pan",threshold:10,pointers:1,direction:30},getTouchAction:function(){var t=this.options.direction,e=[];return 6&t&&e.push(wt),t&N&&e.push(vt),e},directionTest:function(t){var e=this.options,n=!0,i=t.distance,s=t.direction,o=t.deltaX,a=t.deltaY;return s&e.direction||(6&e.direction?(s=0===o?1:o<0?2:4,n=o!=this.pX,i=Math.abs(t.deltaX)):(s=0===a?1:a<0?8:16,n=a!=this.pY,i=Math.abs(t.deltaY))),t.direction=s,n&&i>e.threshold&&s&e.direction},attrTest:function(t){return Pt.prototype.attrTest.call(this,t)&&(2&this.state||!(2&this.state)&&this.directionTest(t))},emit:function(t){this.pX=t.deltaX,this.pY=t.deltaY;var e=Dt(t.direction);e&&(t.additionalEvent=this.options.event+e),this._super.emit.call(this,t)}}),b(At,Pt,{defaults:{event:"pinch",threshold:0,pointers:2},getTouchAction:function(){return[xt]},attrTest:function(t){return this._super.attrTest.call(this,t)&&(Math.abs(t.scale-1)>this.options.threshold||2&this.state)},emit:function(t){if(1!==t.scale){var e=t.scale<1?"in":"out";t.additionalEvent=this.options.event+e}this._super.emit.call(this,t)}}),b(Lt,Ct,{defaults:{event:"press",pointers:1,time:251,threshold:9},getTouchAction:function(){return[bt]},process:function(t){var e=this.options,n=t.pointers.length===e.pointers,i=t.distance<e.threshold,s=t.deltaTime>e.time;if(this._input=t,!i||!n||12&t.eventType&&!s)this.reset();else if(1&t.eventType)this.reset(),this._timer=h((function(){this.state=8,this.tryEmit()}),e.time,this);else if(4&t.eventType)return 8;return Mt},reset:function(){clearTimeout(this._timer)},emit:function(t){8===this.state&&(t&&4&t.eventType?this.manager.emit(this.options.event+"up",t):(this._input.timeStamp=d(),this.manager.emit(this.options.event,this._input)))}}),b(It,Pt,{defaults:{event:"rotate",threshold:0,pointers:2},getTouchAction:function(){return[xt]},attrTest:function(t){return this._super.attrTest.call(this,t)&&(Math.abs(t.rotation)>this.options.threshold||2&this.state)}}),b(Ot,Pt,{defaults:{event:"swipe",threshold:10,velocity:.3,direction:30,pointers:1},getTouchAction:function(){return Et.prototype.getTouchAction.call(this)},attrTest:function(t){var e,n=this.options.direction;return 30&n?e=t.overallVelocity:6&n?e=t.overallVelocityX:n&N&&(e=t.overallVelocityY),this._super.attrTest.call(this,t)&&n&t.offsetDirection&&t.distance>this.options.threshold&&t.maxPointers==this.options.pointers&&l(e)>this.options.velocity&&4&t.eventType},emit:function(t){var e=Dt(t.offsetDirection);e&&this.manager.emit(this.options.event+e,t),this.manager.emit(this.options.event,t)}}),b(zt,Ct,{defaults:{event:"tap",pointers:1,taps:1,interval:300,time:250,threshold:9,posThreshold:10},getTouchAction:function(){return[yt]},process:function(t){var e=this.options,n=t.pointers.length===e.pointers,i=t.distance<e.threshold,s=t.deltaTime<e.time;if(this.reset(),1&t.eventType&&0===this.count)return this.failTimeout();if(i&&s&&n){if(4!=t.eventType)return this.failTimeout();var o=!this.pTime||t.timeStamp-this.pTime<e.interval,a=!this.pCenter||Y(this.pCenter,t.center)<e.posThreshold;if(this.pTime=t.timeStamp,this.pCenter=t.center,a&&o?this.count+=1:this.count=1,this._input=t,0===this.count%e.taps)return this.hasRequireFailures()?(this._timer=h((function(){this.state=8,this.tryEmit()}),e.interval,this),2):8}return Mt},failTimeout:function(){return this._timer=h((function(){this.state=Mt}),this.options.interval,this),Mt},reset:function(){clearTimeout(this._timer)},emit:function(){8==this.state&&(this._input.tapCount=this.count,this.manager.emit(this.options.event,this._input))}}),Wt.VERSION="2.0.7",Wt.defaults={domEvents:!1,touchAction:ft,enable:!0,inputTarget:null,inputClass:null,preset:[[It,{enable:!1}],[At,{enable:!1},["rotate"]],[Ot,{direction:6}],[Et,{direction:6},["swipe"]],[zt],[zt,{event:"doubletap",taps:2},["tap"]],[Lt]],cssProps:{userSelect:"none",touchSelect:"none",touchCallout:"none",contentZooming:"none",userDrag:"none",tapHighlightColor:"rgba(0,0,0,0)"}};function Nt(t,e){var n;this.options=o({},Wt.defaults,e||{}),this.options.inputTarget=this.options.inputTarget||t,this.handlers={},this.session={},this.recognizers=[],this.oldCssProps={},this.element=t,this.input=new((n=this).options.inputClass||(I?nt:O?ct:L?dt:G))(n,q),this.touchAction=new kt(this,this.options.touchAction),Rt(this,!0),g(this.options.recognizers,(function(t){var e=this.add(new t[0](t[1]));t[2]&&e.recognizeWith(t[2]),t[3]&&e.requireFailure(t[3])}),this)}function Rt(t,e){var n,i=t.element;i.style&&(g(t.options.cssProps,(function(s,o){n=P(i.style,o),e?(t.oldCssProps[n]=i.style[n],i.style[n]=s):i.style[n]=t.oldCssProps[n]||""})),e||(t.oldCssProps={}))}Nt.prototype={set:function(t){return o(this.options,t),t.touchAction&&this.touchAction.update(),t.inputTarget&&(this.input.destroy(),this.input.target=t.inputTarget,this.input.init()),this},stop:function(t){this.session.stopped=t?2:1},recognize:function(t){var e=this.session;if(!e.stopped){var n;this.touchAction.preventDefaults(t);var i=this.recognizers,s=e.curRecognizer;(!s||s&&8&s.state)&&(s=e.curRecognizer=null);for(var o=0;o<i.length;)n=i[o],2===e.stopped||s&&n!=s&&!n.canRecognizeWith(s)?n.reset():n.recognize(t),!s&&14&n.state&&(s=e.curRecognizer=n),o++}},get:function(t){if(t instanceof Ct)return t;for(var e=this.recognizers,n=0;n<e.length;n++)if(e[n].options.event==t)return e[n];return null},add:function(t){if(u(t,"add",this))return this;var e=this.get(t.options.event);return e&&this.remove(e),this.recognizers.push(t),t.manager=this,this.touchAction.update(),t},remove:function(t){if(u(t,"remove",this))return this;if(t=this.get(t)){var e=this.recognizers,n=_(e,t);-1!==n&&(e.splice(n,1),this.touchAction.update())}return this},on:function(t,e){if(t!==s&&e!==s){var n=this.handlers;return g(C(t),(function(t){n[t]=n[t]||[],n[t].push(e)})),this}},off:function(t,e){if(t!==s){var n=this.handlers;return g(C(t),(function(t){e?n[t]&&n[t].splice(_(n[t],e),1):delete n[t]})),this}},emit:function(t,e){this.options.domEvents&&function(t,e){var i=n.createEvent("Event");i.initEvent(t,!0,!0),i.gesture=e,e.target.dispatchEvent(i)}(t,e);var i=this.handlers[t]&&this.handlers[t].slice();if(i&&i.length){e.type=t,e.preventDefault=function(){e.srcEvent.preventDefault()};for(var s=0;s<i.length;)i[s](e),s++}},destroy:function(){this.element&&Rt(this,!1),this.handlers={},this.session={},this.input.destroy(),this.element=null}},o(Wt,{INPUT_START:1,INPUT_MOVE:2,INPUT_END:4,INPUT_CANCEL:8,STATE_POSSIBLE:1,STATE_BEGAN:2,STATE_CHANGED:4,STATE_ENDED:8,STATE_RECOGNIZED:8,STATE_CANCELLED:16,STATE_FAILED:Mt,DIRECTION_NONE:1,DIRECTION_LEFT:2,DIRECTION_RIGHT:4,DIRECTION_UP:8,DIRECTION_DOWN:16,DIRECTION_HORIZONTAL:6,DIRECTION_VERTICAL:N,DIRECTION_ALL:30,Manager:Nt,Input:F,TouchAction:kt,TouchInput:ct,MouseInput:G,PointerEventInput:nt,TouchMouseInput:dt,SingleTouchInput:st,Recognizer:Ct,AttrRecognizer:Pt,Tap:zt,Pan:Et,Swipe:Ot,Pinch:At,Rotate:It,Press:Lt,on:w,off:S,each:g,merge:f,extend:m,assign:o,inherit:b,bindFn:y,prefixed:P}),(void 0!==e?e:"undefined"!=typeof self?self:{}).Hammer=Wt,t.exports?t.exports=Wt:e.Hammer=Wt}(window,document)}(Sh);var kh=wh(Sh.exports);
|
|
39
39
|
/*!
|
|
40
40
|
* chartjs-plugin-zoom v2.2.0
|
|
41
41
|
* https://www.chartjs.org/chartjs-plugin-zoom/2.2.0/
|
|
42
42
|
* (c) 2016-2024 chartjs-plugin-zoom Contributors
|
|
43
43
|
* Released under the MIT License
|
|
44
44
|
*/
|
|
45
|
-
const Mh=t=>t&&t.enabled&&t.modifierKey,_h=(t,e)=>t&&e[t+"Key"],Ch=(t,e)=>t&&!e[t+"Key"];function Th(t,e,n){return void 0===t||("string"==typeof t?-1!==t.indexOf(e):"function"==typeof t&&-1!==t({chart:n}).indexOf(e))}function Dh(t,e){return"function"==typeof t&&(t=t({chart:e})),"string"==typeof t?{x:-1!==t.indexOf("x"),y:-1!==t.indexOf("y")}:{x:!1,y:!1}}function Ph(t,e,n){const{mode:i="xy",scaleMode:s,overScaleMode:o}=t||{},a=function({x:t,y:e},n){const i=n.scales,s=Object.keys(i);for(let n=0;n<s.length;n++){const o=i[s[n]];if(e>=o.top&&e<=o.bottom&&t>=o.left&&t<=o.right)return o}return null}(e,n),r=Dh(i,n),c=Dh(s,n);if(o){const t=Dh(o,n);for(const e of["x","y"])t[e]&&(c[e]=r[e],r[e]=!1)}if(a&&c[a.axis])return[a];const l=[];return yt(n.scales,(function(t){r[t.axis]&&l.push(t)})),l}const Eh=new WeakMap;function Ah(t){let e=Eh.get(t);return e||(e={originalScaleLimits:{},updatedScaleLimits:{},handlers:{},panDelta:{},dragging:!1,panning:!1},Eh.set(t,e)),e}function Lh(t,e,n,i){const s=Math.max(0,Math.min(1,(t-e)/n||0));return{min:i*s,max:i*(1-s)}}function Ih(t,e){const n=t.isHorizontal()?e.x:e.y;return t.getValueForPixel(n)}function Oh(t,e,n){const i=t.max-t.min,s=i*(e-1);return Lh(Ih(t,n),t.min,i,s)}function zh(t,e,n,i,s){let o=n[i];if("original"===o){const n=t.originalScaleLimits[e.id][i];o=mt(n.options,n.scale)}return mt(o,s)}function Wh(t,{min:e,max:n},i,s=!1){const o=Ah(t.chart),{options:a}=t,r=function(t,e){return e&&(e[t.id]||e[t.axis])||{}}(t,i),{minRange:c=0}=r,l=zh(o,t,r,"min",-1/0),d=zh(o,t,r,"max",1/0);if("pan"===s&&(e<l||n>d))return!0;const h=t.max-t.min,u=s?Math.max(n-e,c):h;if(s&&u===c&&h<=c)return!0;const g=function(t,{min:e,max:n,minLimit:i,maxLimit:s},o){const a=(t-n+e)/2;e-=a,n+=a;const r=o.min.options??o.min.scale,c=o.max.options??o.max.scale,l=t/1e6;return Bt(e,r,l)&&(e=r),Bt(n,c,l)&&(n=c),e<i?(e=i,n=Math.min(i+t,s)):n>s&&(n=s,e=Math.max(s-t,i)),{min:e,max:n}}(u,{min:e,max:n,minLimit:l,maxLimit:d},o.originalScaleLimits[t.id]);return a.min=g.min,a.max=g.max,o.updatedScaleLimits[t.id]=g,t.parse(g.min)!==t.min||t.parse(g.max)!==t.max}const Nh=t=>0===t||isNaN(t)?0:t<0?Math.min(Math.round(t),-1):Math.max(Math.round(t),1);const Rh={second:500,minute:3e4,hour:18e5,day:432e5,week:3024e5,month:1296e6,quarter:5184e6,year:157248e5};function $h(t,e,n,i=!1){const{min:s,max:o,options:a}=t,r=a.time&&a.time.round,c=Rh[r]||0,l=t.getValueForPixel(t.getPixelForValue(s+c)-e),d=t.getValueForPixel(t.getPixelForValue(o+c)-e);return!(!isNaN(l)&&!isNaN(d))||Wh(t,{min:l,max:d},n,!!i&&"pan")}function Fh(t,e,n){return $h(t,e,n,!0)}const qh={category:function(t,e,n,i){const s=Oh(t,e,n);return t.min===t.max&&e<1&&function(t){const e=t.getLabels().length-1;t.min>0&&(t.min-=1),t.max<e&&(t.max+=1)}(t),Wh(t,{min:t.min+Nh(s.min),max:t.max-Nh(s.max)},i,!0)},default:function(t,e,n,i){const s=Oh(t,e,n);return Wh(t,{min:t.min+s.min,max:t.max-s.max},i,!0)},logarithmic:function(t,e,n,i){const s=function(t,e,n){const i=Ih(t,n);if(void 0===i)return{min:t.min,max:t.max};const s=Math.log10(t.min),o=Math.log10(t.max),a=o-s,r=Lh(Math.log10(i),s,a,a*(e-1));return{min:Math.pow(10,s+r.min),max:Math.pow(10,o-r.max)}}(t,e,n);return Wh(t,s,i,!0)}},Bh={default:function(t,e,n,i){Wh(t,function(t,e,n){const i=t.getValueForPixel(e),s=t.getValueForPixel(n);return{min:Math.min(i,s),max:Math.max(i,s)}}(t,e,n),i,!0)}},Hh={category:function(t,e,n){const i=t.getLabels().length-1;let{min:s,max:o}=t;const a=Math.max(o-s,1),r=Math.round(function(t){return t.isHorizontal()?t.width:t.height}(t)/Math.max(a,10)),c=Math.round(Math.abs(e/r));let l;return e<-r?(o=Math.min(o+c,i),s=1===a?o:o-a,l=o===i):e>r&&(s=Math.max(0,s-c),o=1===a?s:s+a,l=0===s),Wh(t,{min:s,max:o},n)||l},default:$h,logarithmic:Fh,timeseries:Fh};function Vh(t,e){yt(t,((n,i)=>{e[i]||delete t[i]}))}function jh(t,e){const{scales:n}=t,{originalScaleLimits:i,updatedScaleLimits:s}=e;return yt(n,(function(t){(function(t,e,n){const{id:i,options:{min:s,max:o}}=t;if(!e[i]||!n[i])return!0;const a=n[i];return a.min!==s||a.max!==o})(t,i,s)&&(i[t.id]={min:{scale:t.min,options:t.options.min},max:{scale:t.max,options:t.options.max}})})),Vh(i,n),Vh(s,n),i}function Yh(t,e,n,i){bt(qh[t.type]||qh.default,[t,e,n,i])}function Uh(t,e,n,i){bt(Bh[t.type]||Bh.default,[t,e,n,i])}function Xh(t){const e=t.chartArea;return{x:(e.left+e.right)/2,y:(e.top+e.bottom)/2}}function Qh(t,e,n="none",i="api"){const{x:s=1,y:o=1,focalPoint:a=Xh(t)}="number"==typeof e?{x:e,y:e}:e,r=Ah(t),{options:{limits:c,zoom:l}}=r;jh(t,r);const d=1!==s,h=1!==o;yt(Ph(l,a,t)||t.scales,(function(t){t.isHorizontal()&&d?Yh(t,s,a,c):!t.isHorizontal()&&h&&Yh(t,o,a,c)})),t.update(n),bt(l.onZoom,[{chart:t,trigger:i}])}function Kh(t,e,n,i="none",s="api"){const o=Ah(t),{options:{limits:a,zoom:r}}=o,{mode:c="xy"}=r;jh(t,o);const l=Th(c,"x",t),d=Th(c,"y",t);yt(t.scales,(function(t){t.isHorizontal()&&l?Uh(t,e.x,n.x,a):!t.isHorizontal()&&d&&Uh(t,e.y,n.y,a)})),t.update(i),bt(r.onZoom,[{chart:t,trigger:s}])}function Zh(t){const e=Ah(t);let n=1,i=1;return yt(t.scales,(function(t){const s=function(t,e){const n=t.originalScaleLimits[e];if(!n)return;const{min:i,max:s}=n;return mt(s.options,s.scale)-mt(i.options,i.scale)}(e,t.id);if(s){const e=Math.round(s/(t.max-t.min)*100)/100;n=Math.min(n,e),i=Math.max(i,e)}})),n<1?n:i}function Gh(t,e,n,i){const{panDelta:s}=i,o=s[t.id]||0;qt(o)===qt(e)&&(e+=o);bt(Hh[t.type]||Hh.default,[t,e,n])?s[t.id]=0:s[t.id]=e}function Jh(t,e,n,i="none"){const{x:s=0,y:o=0}="number"==typeof e?{x:e,y:e}:e,a=Ah(t),{options:{pan:r,limits:c}}=a,{onPan:l}=r||{};jh(t,a);const d=0!==s,h=0!==o;yt(n||t.scales,(function(t){t.isHorizontal()&&d?Gh(t,s,c,a):!t.isHorizontal()&&h&&Gh(t,o,c,a)})),t.update(i),bt(l,[{chart:t}])}function tu(t){const e=Ah(t);jh(t,e);const n={};for(const i of Object.keys(t.scales)){const{min:t,max:s}=e.originalScaleLimits[i]||{min:{},max:{}};n[i]={min:t.scale,max:s.scale}}return n}function eu(t){const e=Ah(t);return e.panning||e.dragging}const nu=(t,e,n)=>Math.min(n,Math.max(e,t));function iu(t,e){const{handlers:n}=Ah(t),i=n[e];i&&i.target&&(i.target.removeEventListener(e,i),delete n[e])}function su(t,e,n,i){const{handlers:s,options:o}=Ah(t),a=s[n];if(a&&a.target===e)return;iu(t,n),s[n]=e=>i(t,e,o),s[n].target=e;const r="wheel"!==n&&void 0;e.addEventListener(n,s[n],{passive:r})}function ou(t,e){const n=Ah(t);n.dragStart&&(n.dragging=!0,n.dragEnd=e,t.update("none"))}function au(t,e){const n=Ah(t);n.dragStart&&"Escape"===e.key&&(iu(t,"keydown"),n.dragging=!1,n.dragStart=n.dragEnd=null,t.update("none"))}function ru(t,e){if(t.target!==e.canvas){const n=e.canvas.getBoundingClientRect();return{x:t.clientX-n.left,y:t.clientY-n.top}}return Ln(t,e)}function cu(t,e,n){const{onZoomStart:i,onZoomRejected:s}=n;if(i){if(!1===bt(i,[{chart:t,event:e,point:ru(e,t)}]))return bt(s,[{chart:t,event:e}]),!1}}function lu(t,e){if(t.legend){if($e(Ln(e,t),t.legend))return}const n=Ah(t),{pan:i,zoom:s={}}=n.options;if(0!==e.button||_h(Mh(i),e)||Ch(Mh(s.drag),e))return bt(s.onZoomRejected,[{chart:t,event:e}]);!1!==cu(t,e,s)&&(n.dragStart=e,su(t,t.canvas.ownerDocument,"mousemove",ou),su(t,window.document,"keydown",au))}function du(t,e,n,{min:i,max:s,prop:o}){t[i]=nu(Math.min(n.begin[o],n.end[o]),e[i],e[s]),t[s]=nu(Math.max(n.begin[o],n.end[o]),e[i],e[s])}function hu(t,e,n){const i={begin:ru(e.dragStart,t),end:ru(e.dragEnd,t)};if(n){!function({begin:t,end:e},n){let i=e.x-t.x,s=e.y-t.y;const o=Math.abs(i/s);o>n?i=Math.sign(i)*Math.abs(s*n):o<n&&(s=Math.sign(s)*Math.abs(i/n)),e.x=t.x+i,e.y=t.y+s}(i,t.chartArea.width/t.chartArea.height)}return i}function uu(t,e,n,i){const s=Th(e,"x",t),o=Th(e,"y",t),{top:a,left:r,right:c,bottom:l,width:d,height:h}=t.chartArea,u={top:a,left:r,right:c,bottom:l},g=hu(t,n,i&&s&&o);s&&du(u,t.chartArea,g,{min:"left",max:"right",prop:"x"}),o&&du(u,t.chartArea,g,{min:"top",max:"bottom",prop:"y"});const p=u.right-u.left,m=u.bottom-u.top;return{...u,width:p,height:m,zoomX:s&&p?1+(d-p)/d:1,zoomY:o&&m?1+(h-m)/h:1}}function gu(t,e){const n=Ah(t);if(!n.dragStart)return;iu(t,"mousemove");const{mode:i,onZoomComplete:s,drag:{threshold:o=0,maintainAspectRatio:a}}=n.options.zoom,r=uu(t,i,{dragStart:n.dragStart,dragEnd:e},a),c=Th(i,"x",t)?r.width:0,l=Th(i,"y",t)?r.height:0,d=Math.sqrt(c*c+l*l);if(n.dragStart=n.dragEnd=null,d<=o)return n.dragging=!1,void t.update("none");Kh(t,{x:r.left,y:r.top},{x:r.right,y:r.bottom},"zoom","drag"),n.dragging=!1,n.filterNextClick=!0,bt(s,[{chart:t}])}function pu(t,e){const{handlers:{onZoomComplete:n},options:{zoom:i}}=Ah(t);if(!function(t,e,n){if(Ch(Mh(n.wheel),e))bt(n.onZoomRejected,[{chart:t,event:e}]);else if(!1!==cu(t,e,n)&&(e.cancelable&&e.preventDefault(),void 0!==e.deltaY))return!0}(t,e,i))return;const s=e.target.getBoundingClientRect(),o=i.wheel.speed,a=e.deltaY>=0?2-1/(1-o):1+o;Qh(t,{x:a,y:a,focalPoint:{x:e.clientX-s.left,y:e.clientY-s.top}},"zoom","wheel"),bt(n,[{chart:t}])}function mu(t,e,n,i){n&&(Ah(t).handlers[e]=function(t,e){let n;return function(){return clearTimeout(n),n=setTimeout(t,e),e}}((()=>bt(n,[{chart:t}])),i))}function fu(t,e){return function(n,i){const{pan:s,zoom:o={}}=e.options;if(!s||!s.enabled)return!1;const a=i&&i.srcEvent;return!a||(!(!e.panning&&"mouse"===i.pointerType&&(Ch(Mh(s),a)||_h(Mh(o.drag),a)))||(bt(s.onPanRejected,[{chart:t,event:i}]),!1))}}function bu(t,e,n){if(e.scale){const{center:i,pointers:s}=n,o=1/e.scale*n.scale,a=n.target.getBoundingClientRect(),r=function(t,e){const n=Math.abs(t.clientX-e.clientX),i=Math.abs(t.clientY-e.clientY),s=n/i;let o,a;return s>.3&&s<1.7?o=a=!0:n>i?o=!0:a=!0,{x:o,y:a}}(s[0],s[1]),c=e.options.zoom.mode;Qh(t,{x:r.x&&Th(c,"x",t)?o:1,y:r.y&&Th(c,"y",t)?o:1,focalPoint:{x:i.x-a.left,y:i.y-a.top}},"zoom","pinch"),e.scale=n.scale}}function yu(t,e,n){const i=e.delta;i&&(e.panning=!0,Jh(t,{x:n.deltaX-i.x,y:n.deltaY-i.y},e.panScales),e.delta={x:n.deltaX,y:n.deltaY})}const xu=new WeakMap;function vu(t,e){const n=Ah(t),i=t.canvas,{pan:s,zoom:o}=e,a=new kh.Manager(i);o&&o.pinch.enabled&&(a.add(new kh.Pinch),a.on("pinchstart",(e=>function(t,e,n){if(e.options.zoom.pinch.enabled){const i=Ln(n,t);!1===bt(e.options.zoom.onZoomStart,[{chart:t,event:n,point:i}])?(e.scale=null,bt(e.options.zoom.onZoomRejected,[{chart:t,event:n}])):e.scale=1}}(t,n,e))),a.on("pinch",(e=>bu(t,n,e))),a.on("pinchend",(e=>function(t,e,n){e.scale&&(bu(t,e,n),e.scale=null,bt(e.options.zoom.onZoomComplete,[{chart:t}]))}(t,n,e)))),s&&s.enabled&&(a.add(new kh.Pan({threshold:s.threshold,enable:fu(t,n)})),a.on("panstart",(e=>function(t,e,n){const{enabled:i,onPanStart:s,onPanRejected:o}=e.options.pan;if(!i)return;const a=n.target.getBoundingClientRect(),r={x:n.center.x-a.left,y:n.center.y-a.top};if(!1===bt(s,[{chart:t,event:n,point:r}]))return bt(o,[{chart:t,event:n}]);e.panScales=Ph(e.options.pan,r,t),e.delta={x:0,y:0},yu(t,e,n)}(t,n,e))),a.on("panmove",(e=>yu(t,n,e))),a.on("panend",(()=>function(t,e){e.delta=null,e.panning&&(e.panning=!1,e.filterNextClick=!0,bt(e.options.pan.onPanComplete,[{chart:t}]))}(t,n)))),xu.set(t,a)}function wu(t){const e=xu.get(t);e&&(e.remove("pinchstart"),e.remove("pinch"),e.remove("pinchend"),e.remove("panstart"),e.remove("pan"),e.remove("panend"),e.destroy(),xu.delete(t))}function Su(t,e,n){const i=n.zoom.drag,{dragStart:s,dragEnd:o}=Ah(t);if(i.drawTime!==e||!o)return;const{left:a,top:r,width:c,height:l}=uu(t,n.zoom.mode,{dragStart:s,dragEnd:o},i.maintainAspectRatio),d=t.ctx;d.save(),d.beginPath(),d.fillStyle=i.backgroundColor||"rgba(225,225,225,0.3)",d.fillRect(a,r,c,l),i.borderWidth>0&&(d.lineWidth=i.borderWidth,d.strokeStyle=i.borderColor||"rgba(225,225,225)",d.strokeRect(a,r,c,l)),d.restore()}var ku={id:"zoom",version:"2.2.0",defaults:{pan:{enabled:!1,mode:"xy",threshold:10,modifierKey:null},zoom:{wheel:{enabled:!1,speed:.1,modifierKey:null},drag:{enabled:!1,drawTime:"beforeDatasetsDraw",modifierKey:null},pinch:{enabled:!1},mode:"xy"}},start:function(t,e,n){Ah(t).options=n,Object.prototype.hasOwnProperty.call(n.zoom,"enabled")&&console.warn("The option `zoom.enabled` is no longer supported. Please use `zoom.wheel.enabled`, `zoom.drag.enabled`, or `zoom.pinch.enabled`."),(Object.prototype.hasOwnProperty.call(n.zoom,"overScaleMode")||Object.prototype.hasOwnProperty.call(n.pan,"overScaleMode"))&&console.warn("The option `overScaleMode` is deprecated. Please use `scaleMode` instead (and update `mode` as desired)."),kh&&vu(t,n),t.pan=(e,n,i)=>Jh(t,e,n,i),t.zoom=(e,n)=>Qh(t,e,n),t.zoomRect=(e,n,i)=>Kh(t,e,n,i),t.zoomScale=(e,n,i)=>function(t,e,n,i="none",s="api"){const o=Ah(t);jh(t,o),Wh(t.scales[e],n,void 0,!0),t.update(i),bt(o.options.zoom?.onZoom,[{chart:t,trigger:s}])}(t,e,n,i),t.resetZoom=e=>function(t,e="default"){const n=Ah(t),i=jh(t,n);yt(t.scales,(function(t){const e=t.options;i[t.id]?(e.min=i[t.id].min.options,e.max=i[t.id].max.options):(delete e.min,delete e.max),delete n.updatedScaleLimits[t.id]})),t.update(e),bt(n.options.zoom.onZoomComplete,[{chart:t}])}(t,e),t.getZoomLevel=()=>Zh(t),t.getInitialScaleBounds=()=>tu(t),t.getZoomedScaleBounds=()=>function(t){const e=Ah(t),n={};for(const i of Object.keys(t.scales))n[i]=e.updatedScaleLimits[i];return n}(t),t.isZoomedOrPanned=()=>function(t){const e=tu(t);for(const n of Object.keys(t.scales)){const{min:i,max:s}=e[n];if(void 0!==i&&t.scales[n].min!==i)return!0;if(void 0!==s&&t.scales[n].max!==s)return!0}return!1}(t),t.isZoomingOrPanning=()=>eu(t)},beforeEvent(t,{event:e}){if(eu(t))return!1;if("click"===e.type||"mouseup"===e.type){const e=Ah(t);if(e.filterNextClick)return e.filterNextClick=!1,!1}},beforeUpdate:function(t,e,n){const i=Ah(t),s=i.options;i.options=n,function(t,e){const{pan:n,zoom:i}=t,{pan:s,zoom:o}=e;return i?.zoom?.pinch?.enabled!==o?.zoom?.pinch?.enabled||n?.enabled!==s?.enabled||n?.threshold!==s?.threshold}(s,n)&&(wu(t),vu(t,n)),function(t,e){const n=t.canvas,{wheel:i,drag:s,onZoomComplete:o}=e.zoom;i.enabled?(su(t,n,"wheel",pu),mu(t,"onZoomComplete",o,250)):iu(t,"wheel"),s.enabled?(su(t,n,"mousedown",lu),su(t,n.ownerDocument,"mouseup",gu)):(iu(t,"mousedown"),iu(t,"mousemove"),iu(t,"mouseup"),iu(t,"keydown"))}(t,n)},beforeDatasetsDraw(t,e,n){Su(t,"beforeDatasetsDraw",n)},afterDatasetsDraw(t,e,n){Su(t,"afterDatasetsDraw",n)},beforeDraw(t,e,n){Su(t,"beforeDraw",n)},afterDraw(t,e,n){Su(t,"afterDraw",n)},stop:function(t){!function(t){iu(t,"mousedown"),iu(t,"mousemove"),iu(t,"mouseup"),iu(t,"wheel"),iu(t,"click"),iu(t,"keydown")}(t),kh&&wu(t),function(t){Eh.delete(t)}(t)},panFunctions:Hh,zoomFunctions:qh,zoomRectFunctions:Bh};
|
|
45
|
+
const Mh=t=>t&&t.enabled&&t.modifierKey,Ch=(t,e)=>t&&e[t+"Key"],_h=(t,e)=>t&&!e[t+"Key"];function Dh(t,e,n){return void 0===t||("string"==typeof t?-1!==t.indexOf(e):"function"==typeof t&&-1!==t({chart:n}).indexOf(e))}function Th(t,e){return"function"==typeof t&&(t=t({chart:e})),"string"==typeof t?{x:-1!==t.indexOf("x"),y:-1!==t.indexOf("y")}:{x:!1,y:!1}}function Ph(t,e,n){const{mode:i="xy",scaleMode:s,overScaleMode:o}=t||{},a=function({x:t,y:e},n){const i=n.scales,s=Object.keys(i);for(let n=0;n<s.length;n++){const o=i[s[n]];if(e>=o.top&&e<=o.bottom&&t>=o.left&&t<=o.right)return o}return null}(e,n),r=Th(i,n),c=Th(s,n);if(o){const t=Th(o,n);for(const e of["x","y"])t[e]&&(c[e]=r[e],r[e]=!1)}if(a&&c[a.axis])return[a];const l=[];return yt(n.scales,(function(t){r[t.axis]&&l.push(t)})),l}const Eh=new WeakMap;function Ah(t){let e=Eh.get(t);return e||(e={originalScaleLimits:{},updatedScaleLimits:{},handlers:{},panDelta:{},dragging:!1,panning:!1},Eh.set(t,e)),e}function Lh(t,e,n,i){const s=Math.max(0,Math.min(1,(t-e)/n||0));return{min:i*s,max:i*(1-s)}}function Ih(t,e){const n=t.isHorizontal()?e.x:e.y;return t.getValueForPixel(n)}function Oh(t,e,n){const i=t.max-t.min,s=i*(e-1);return Lh(Ih(t,n),t.min,i,s)}function zh(t,e,n,i,s){let o=n[i];if("original"===o){const n=t.originalScaleLimits[e.id][i];o=mt(n.options,n.scale)}return mt(o,s)}function Wh(t,{min:e,max:n},i,s=!1){const o=Ah(t.chart),{options:a}=t,r=function(t,e){return e&&(e[t.id]||e[t.axis])||{}}(t,i),{minRange:c=0}=r,l=zh(o,t,r,"min",-1/0),d=zh(o,t,r,"max",1/0);if("pan"===s&&(e<l||n>d))return!0;const h=t.max-t.min,u=s?Math.max(n-e,c):h;if(s&&u===c&&h<=c)return!0;const g=function(t,{min:e,max:n,minLimit:i,maxLimit:s},o){const a=(t-n+e)/2;e-=a,n+=a;const r=o.min.options??o.min.scale,c=o.max.options??o.max.scale,l=t/1e6;return Bt(e,r,l)&&(e=r),Bt(n,c,l)&&(n=c),e<i?(e=i,n=Math.min(i+t,s)):n>s&&(n=s,e=Math.max(s-t,i)),{min:e,max:n}}(u,{min:e,max:n,minLimit:l,maxLimit:d},o.originalScaleLimits[t.id]);return a.min=g.min,a.max=g.max,o.updatedScaleLimits[t.id]=g,t.parse(g.min)!==t.min||t.parse(g.max)!==t.max}const Nh=t=>0===t||isNaN(t)?0:t<0?Math.min(Math.round(t),-1):Math.max(Math.round(t),1);const Rh={second:500,minute:3e4,hour:18e5,day:432e5,week:3024e5,month:1296e6,quarter:5184e6,year:157248e5};function $h(t,e,n,i=!1){const{min:s,max:o,options:a}=t,r=a.time&&a.time.round,c=Rh[r]||0,l=t.getValueForPixel(t.getPixelForValue(s+c)-e),d=t.getValueForPixel(t.getPixelForValue(o+c)-e);return!(!isNaN(l)&&!isNaN(d))||Wh(t,{min:l,max:d},n,!!i&&"pan")}function Fh(t,e,n){return $h(t,e,n,!0)}const qh={category:function(t,e,n,i){const s=Oh(t,e,n);return t.min===t.max&&e<1&&function(t){const e=t.getLabels().length-1;t.min>0&&(t.min-=1),t.max<e&&(t.max+=1)}(t),Wh(t,{min:t.min+Nh(s.min),max:t.max-Nh(s.max)},i,!0)},default:function(t,e,n,i){const s=Oh(t,e,n);return Wh(t,{min:t.min+s.min,max:t.max-s.max},i,!0)},logarithmic:function(t,e,n,i){const s=function(t,e,n){const i=Ih(t,n);if(void 0===i)return{min:t.min,max:t.max};const s=Math.log10(t.min),o=Math.log10(t.max),a=o-s,r=Lh(Math.log10(i),s,a,a*(e-1));return{min:Math.pow(10,s+r.min),max:Math.pow(10,o-r.max)}}(t,e,n);return Wh(t,s,i,!0)}},Bh={default:function(t,e,n,i){Wh(t,function(t,e,n){const i=t.getValueForPixel(e),s=t.getValueForPixel(n);return{min:Math.min(i,s),max:Math.max(i,s)}}(t,e,n),i,!0)}},Hh={category:function(t,e,n){const i=t.getLabels().length-1;let{min:s,max:o}=t;const a=Math.max(o-s,1),r=Math.round(function(t){return t.isHorizontal()?t.width:t.height}(t)/Math.max(a,10)),c=Math.round(Math.abs(e/r));let l;return e<-r?(o=Math.min(o+c,i),s=1===a?o:o-a,l=o===i):e>r&&(s=Math.max(0,s-c),o=1===a?s:s+a,l=0===s),Wh(t,{min:s,max:o},n)||l},default:$h,logarithmic:Fh,timeseries:Fh};function Vh(t,e){yt(t,((n,i)=>{e[i]||delete t[i]}))}function jh(t,e){const{scales:n}=t,{originalScaleLimits:i,updatedScaleLimits:s}=e;return yt(n,(function(t){(function(t,e,n){const{id:i,options:{min:s,max:o}}=t;if(!e[i]||!n[i])return!0;const a=n[i];return a.min!==s||a.max!==o})(t,i,s)&&(i[t.id]={min:{scale:t.min,options:t.options.min},max:{scale:t.max,options:t.options.max}})})),Vh(i,n),Vh(s,n),i}function Yh(t,e,n,i){bt(qh[t.type]||qh.default,[t,e,n,i])}function Uh(t,e,n,i){bt(Bh[t.type]||Bh.default,[t,e,n,i])}function Xh(t){const e=t.chartArea;return{x:(e.left+e.right)/2,y:(e.top+e.bottom)/2}}function Qh(t,e,n="none",i="api"){const{x:s=1,y:o=1,focalPoint:a=Xh(t)}="number"==typeof e?{x:e,y:e}:e,r=Ah(t),{options:{limits:c,zoom:l}}=r;jh(t,r);const d=1!==s,h=1!==o;yt(Ph(l,a,t)||t.scales,(function(t){t.isHorizontal()&&d?Yh(t,s,a,c):!t.isHorizontal()&&h&&Yh(t,o,a,c)})),t.update(n),bt(l.onZoom,[{chart:t,trigger:i}])}function Kh(t,e,n,i="none",s="api"){const o=Ah(t),{options:{limits:a,zoom:r}}=o,{mode:c="xy"}=r;jh(t,o);const l=Dh(c,"x",t),d=Dh(c,"y",t);yt(t.scales,(function(t){t.isHorizontal()&&l?Uh(t,e.x,n.x,a):!t.isHorizontal()&&d&&Uh(t,e.y,n.y,a)})),t.update(i),bt(r.onZoom,[{chart:t,trigger:s}])}function Gh(t){const e=Ah(t);let n=1,i=1;return yt(t.scales,(function(t){const s=function(t,e){const n=t.originalScaleLimits[e];if(!n)return;const{min:i,max:s}=n;return mt(s.options,s.scale)-mt(i.options,i.scale)}(e,t.id);if(s){const e=Math.round(s/(t.max-t.min)*100)/100;n=Math.min(n,e),i=Math.max(i,e)}})),n<1?n:i}function Zh(t,e,n,i){const{panDelta:s}=i,o=s[t.id]||0;qt(o)===qt(e)&&(e+=o);bt(Hh[t.type]||Hh.default,[t,e,n])?s[t.id]=0:s[t.id]=e}function Jh(t,e,n,i="none"){const{x:s=0,y:o=0}="number"==typeof e?{x:e,y:e}:e,a=Ah(t),{options:{pan:r,limits:c}}=a,{onPan:l}=r||{};jh(t,a);const d=0!==s,h=0!==o;yt(n||t.scales,(function(t){t.isHorizontal()&&d?Zh(t,s,c,a):!t.isHorizontal()&&h&&Zh(t,o,c,a)})),t.update(i),bt(l,[{chart:t}])}function tu(t){const e=Ah(t);jh(t,e);const n={};for(const i of Object.keys(t.scales)){const{min:t,max:s}=e.originalScaleLimits[i]||{min:{},max:{}};n[i]={min:t.scale,max:s.scale}}return n}function eu(t){const e=Ah(t);return e.panning||e.dragging}const nu=(t,e,n)=>Math.min(n,Math.max(e,t));function iu(t,e){const{handlers:n}=Ah(t),i=n[e];i&&i.target&&(i.target.removeEventListener(e,i),delete n[e])}function su(t,e,n,i){const{handlers:s,options:o}=Ah(t),a=s[n];if(a&&a.target===e)return;iu(t,n),s[n]=e=>i(t,e,o),s[n].target=e;const r="wheel"!==n&&void 0;e.addEventListener(n,s[n],{passive:r})}function ou(t,e){const n=Ah(t);n.dragStart&&(n.dragging=!0,n.dragEnd=e,t.update("none"))}function au(t,e){const n=Ah(t);n.dragStart&&"Escape"===e.key&&(iu(t,"keydown"),n.dragging=!1,n.dragStart=n.dragEnd=null,t.update("none"))}function ru(t,e){if(t.target!==e.canvas){const n=e.canvas.getBoundingClientRect();return{x:t.clientX-n.left,y:t.clientY-n.top}}return Ln(t,e)}function cu(t,e,n){const{onZoomStart:i,onZoomRejected:s}=n;if(i){if(!1===bt(i,[{chart:t,event:e,point:ru(e,t)}]))return bt(s,[{chart:t,event:e}]),!1}}function lu(t,e){if(t.legend){if($e(Ln(e,t),t.legend))return}const n=Ah(t),{pan:i,zoom:s={}}=n.options;if(0!==e.button||Ch(Mh(i),e)||_h(Mh(s.drag),e))return bt(s.onZoomRejected,[{chart:t,event:e}]);!1!==cu(t,e,s)&&(n.dragStart=e,su(t,t.canvas.ownerDocument,"mousemove",ou),su(t,window.document,"keydown",au))}function du(t,e,n,{min:i,max:s,prop:o}){t[i]=nu(Math.min(n.begin[o],n.end[o]),e[i],e[s]),t[s]=nu(Math.max(n.begin[o],n.end[o]),e[i],e[s])}function hu(t,e,n){const i={begin:ru(e.dragStart,t),end:ru(e.dragEnd,t)};if(n){!function({begin:t,end:e},n){let i=e.x-t.x,s=e.y-t.y;const o=Math.abs(i/s);o>n?i=Math.sign(i)*Math.abs(s*n):o<n&&(s=Math.sign(s)*Math.abs(i/n)),e.x=t.x+i,e.y=t.y+s}(i,t.chartArea.width/t.chartArea.height)}return i}function uu(t,e,n,i){const s=Dh(e,"x",t),o=Dh(e,"y",t),{top:a,left:r,right:c,bottom:l,width:d,height:h}=t.chartArea,u={top:a,left:r,right:c,bottom:l},g=hu(t,n,i&&s&&o);s&&du(u,t.chartArea,g,{min:"left",max:"right",prop:"x"}),o&&du(u,t.chartArea,g,{min:"top",max:"bottom",prop:"y"});const p=u.right-u.left,m=u.bottom-u.top;return{...u,width:p,height:m,zoomX:s&&p?1+(d-p)/d:1,zoomY:o&&m?1+(h-m)/h:1}}function gu(t,e){const n=Ah(t);if(!n.dragStart)return;iu(t,"mousemove");const{mode:i,onZoomComplete:s,drag:{threshold:o=0,maintainAspectRatio:a}}=n.options.zoom,r=uu(t,i,{dragStart:n.dragStart,dragEnd:e},a),c=Dh(i,"x",t)?r.width:0,l=Dh(i,"y",t)?r.height:0,d=Math.sqrt(c*c+l*l);if(n.dragStart=n.dragEnd=null,d<=o)return n.dragging=!1,void t.update("none");Kh(t,{x:r.left,y:r.top},{x:r.right,y:r.bottom},"zoom","drag"),n.dragging=!1,n.filterNextClick=!0,bt(s,[{chart:t}])}function pu(t,e){const{handlers:{onZoomComplete:n},options:{zoom:i}}=Ah(t);if(!function(t,e,n){if(_h(Mh(n.wheel),e))bt(n.onZoomRejected,[{chart:t,event:e}]);else if(!1!==cu(t,e,n)&&(e.cancelable&&e.preventDefault(),void 0!==e.deltaY))return!0}(t,e,i))return;const s=e.target.getBoundingClientRect(),o=i.wheel.speed,a=e.deltaY>=0?2-1/(1-o):1+o;Qh(t,{x:a,y:a,focalPoint:{x:e.clientX-s.left,y:e.clientY-s.top}},"zoom","wheel"),bt(n,[{chart:t}])}function mu(t,e,n,i){n&&(Ah(t).handlers[e]=function(t,e){let n;return function(){return clearTimeout(n),n=setTimeout(t,e),e}}((()=>bt(n,[{chart:t}])),i))}function fu(t,e){return function(n,i){const{pan:s,zoom:o={}}=e.options;if(!s||!s.enabled)return!1;const a=i&&i.srcEvent;return!a||(!(!e.panning&&"mouse"===i.pointerType&&(_h(Mh(s),a)||Ch(Mh(o.drag),a)))||(bt(s.onPanRejected,[{chart:t,event:i}]),!1))}}function bu(t,e,n){if(e.scale){const{center:i,pointers:s}=n,o=1/e.scale*n.scale,a=n.target.getBoundingClientRect(),r=function(t,e){const n=Math.abs(t.clientX-e.clientX),i=Math.abs(t.clientY-e.clientY),s=n/i;let o,a;return s>.3&&s<1.7?o=a=!0:n>i?o=!0:a=!0,{x:o,y:a}}(s[0],s[1]),c=e.options.zoom.mode;Qh(t,{x:r.x&&Dh(c,"x",t)?o:1,y:r.y&&Dh(c,"y",t)?o:1,focalPoint:{x:i.x-a.left,y:i.y-a.top}},"zoom","pinch"),e.scale=n.scale}}function yu(t,e,n){const i=e.delta;i&&(e.panning=!0,Jh(t,{x:n.deltaX-i.x,y:n.deltaY-i.y},e.panScales),e.delta={x:n.deltaX,y:n.deltaY})}const xu=new WeakMap;function vu(t,e){const n=Ah(t),i=t.canvas,{pan:s,zoom:o}=e,a=new kh.Manager(i);o&&o.pinch.enabled&&(a.add(new kh.Pinch),a.on("pinchstart",(e=>function(t,e,n){if(e.options.zoom.pinch.enabled){const i=Ln(n,t);!1===bt(e.options.zoom.onZoomStart,[{chart:t,event:n,point:i}])?(e.scale=null,bt(e.options.zoom.onZoomRejected,[{chart:t,event:n}])):e.scale=1}}(t,n,e))),a.on("pinch",(e=>bu(t,n,e))),a.on("pinchend",(e=>function(t,e,n){e.scale&&(bu(t,e,n),e.scale=null,bt(e.options.zoom.onZoomComplete,[{chart:t}]))}(t,n,e)))),s&&s.enabled&&(a.add(new kh.Pan({threshold:s.threshold,enable:fu(t,n)})),a.on("panstart",(e=>function(t,e,n){const{enabled:i,onPanStart:s,onPanRejected:o}=e.options.pan;if(!i)return;const a=n.target.getBoundingClientRect(),r={x:n.center.x-a.left,y:n.center.y-a.top};if(!1===bt(s,[{chart:t,event:n,point:r}]))return bt(o,[{chart:t,event:n}]);e.panScales=Ph(e.options.pan,r,t),e.delta={x:0,y:0},yu(t,e,n)}(t,n,e))),a.on("panmove",(e=>yu(t,n,e))),a.on("panend",(()=>function(t,e){e.delta=null,e.panning&&(e.panning=!1,e.filterNextClick=!0,bt(e.options.pan.onPanComplete,[{chart:t}]))}(t,n)))),xu.set(t,a)}function wu(t){const e=xu.get(t);e&&(e.remove("pinchstart"),e.remove("pinch"),e.remove("pinchend"),e.remove("panstart"),e.remove("pan"),e.remove("panend"),e.destroy(),xu.delete(t))}function Su(t,e,n){const i=n.zoom.drag,{dragStart:s,dragEnd:o}=Ah(t);if(i.drawTime!==e||!o)return;const{left:a,top:r,width:c,height:l}=uu(t,n.zoom.mode,{dragStart:s,dragEnd:o},i.maintainAspectRatio),d=t.ctx;d.save(),d.beginPath(),d.fillStyle=i.backgroundColor||"rgba(225,225,225,0.3)",d.fillRect(a,r,c,l),i.borderWidth>0&&(d.lineWidth=i.borderWidth,d.strokeStyle=i.borderColor||"rgba(225,225,225)",d.strokeRect(a,r,c,l)),d.restore()}var ku={id:"zoom",version:"2.2.0",defaults:{pan:{enabled:!1,mode:"xy",threshold:10,modifierKey:null},zoom:{wheel:{enabled:!1,speed:.1,modifierKey:null},drag:{enabled:!1,drawTime:"beforeDatasetsDraw",modifierKey:null},pinch:{enabled:!1},mode:"xy"}},start:function(t,e,n){Ah(t).options=n,Object.prototype.hasOwnProperty.call(n.zoom,"enabled")&&console.warn("The option `zoom.enabled` is no longer supported. Please use `zoom.wheel.enabled`, `zoom.drag.enabled`, or `zoom.pinch.enabled`."),(Object.prototype.hasOwnProperty.call(n.zoom,"overScaleMode")||Object.prototype.hasOwnProperty.call(n.pan,"overScaleMode"))&&console.warn("The option `overScaleMode` is deprecated. Please use `scaleMode` instead (and update `mode` as desired)."),kh&&vu(t,n),t.pan=(e,n,i)=>Jh(t,e,n,i),t.zoom=(e,n)=>Qh(t,e,n),t.zoomRect=(e,n,i)=>Kh(t,e,n,i),t.zoomScale=(e,n,i)=>function(t,e,n,i="none",s="api"){const o=Ah(t);jh(t,o),Wh(t.scales[e],n,void 0,!0),t.update(i),bt(o.options.zoom?.onZoom,[{chart:t,trigger:s}])}(t,e,n,i),t.resetZoom=e=>function(t,e="default"){const n=Ah(t),i=jh(t,n);yt(t.scales,(function(t){const e=t.options;i[t.id]?(e.min=i[t.id].min.options,e.max=i[t.id].max.options):(delete e.min,delete e.max),delete n.updatedScaleLimits[t.id]})),t.update(e),bt(n.options.zoom.onZoomComplete,[{chart:t}])}(t,e),t.getZoomLevel=()=>Gh(t),t.getInitialScaleBounds=()=>tu(t),t.getZoomedScaleBounds=()=>function(t){const e=Ah(t),n={};for(const i of Object.keys(t.scales))n[i]=e.updatedScaleLimits[i];return n}(t),t.isZoomedOrPanned=()=>function(t){const e=tu(t);for(const n of Object.keys(t.scales)){const{min:i,max:s}=e[n];if(void 0!==i&&t.scales[n].min!==i)return!0;if(void 0!==s&&t.scales[n].max!==s)return!0}return!1}(t),t.isZoomingOrPanning=()=>eu(t)},beforeEvent(t,{event:e}){if(eu(t))return!1;if("click"===e.type||"mouseup"===e.type){const e=Ah(t);if(e.filterNextClick)return e.filterNextClick=!1,!1}},beforeUpdate:function(t,e,n){const i=Ah(t),s=i.options;i.options=n,function(t,e){const{pan:n,zoom:i}=t,{pan:s,zoom:o}=e;return i?.zoom?.pinch?.enabled!==o?.zoom?.pinch?.enabled||n?.enabled!==s?.enabled||n?.threshold!==s?.threshold}(s,n)&&(wu(t),vu(t,n)),function(t,e){const n=t.canvas,{wheel:i,drag:s,onZoomComplete:o}=e.zoom;i.enabled?(su(t,n,"wheel",pu),mu(t,"onZoomComplete",o,250)):iu(t,"wheel"),s.enabled?(su(t,n,"mousedown",lu),su(t,n.ownerDocument,"mouseup",gu)):(iu(t,"mousedown"),iu(t,"mousemove"),iu(t,"mouseup"),iu(t,"keydown"))}(t,n)},beforeDatasetsDraw(t,e,n){Su(t,"beforeDatasetsDraw",n)},afterDatasetsDraw(t,e,n){Su(t,"afterDatasetsDraw",n)},beforeDraw(t,e,n){Su(t,"beforeDraw",n)},afterDraw(t,e,n){Su(t,"afterDraw",n)},stop:function(t){!function(t){iu(t,"mousedown"),iu(t,"mousemove"),iu(t,"mouseup"),iu(t,"wheel"),iu(t,"click"),iu(t,"keydown")}(t),kh&&wu(t),function(t){Eh.delete(t)}(t)},panFunctions:Hh,zoomFunctions:qh,zoomRectFunctions:Bh};
|
|
46
46
|
/*!
|
|
47
47
|
* @license
|
|
48
48
|
* chartjs-chart-financial
|
|
@@ -52,4 +52,4 @@ const Mh=t=>t&&t.enabled&&t.modifierKey,_h=(t,e)=>t&&e[t+"Key"],Ch=(t,e)=>t&&!e[
|
|
|
52
52
|
* Copyright 2024 Chart.js Contributors
|
|
53
53
|
* Released under the MIT license
|
|
54
54
|
* https://github.com/chartjs/chartjs-chart-financial/blob/master/LICENSE.md
|
|
55
|
-
*/function Mu(t,e,n,i){const s=null===e,o=null===n,a=!(!t||s&&o)&&function(t,e){const{x:n,y:i,base:s,width:o,height:a}=t.getProps(["x","low","high","width","height"],e);let r,c,l,d,h;return t.horizontal?(h=a/2,r=Math.min(n,s),c=Math.max(n,s),l=i-h,d=i+h):(h=o/2,r=n-h,c=n+h,l=Math.min(i,s),d=Math.max(i,s)),{left:r,top:l,right:c,bottom:d}}(t,i);return a&&(s||e>=a.left&&e<=a.right)&&(o||n>=a.top&&n<=a.bottom)}class _u extends Mo{static defaults={backgroundColors:{up:"rgba(75, 192, 192, 0.5)",down:"rgba(255, 99, 132, 0.5)",unchanged:"rgba(201, 203, 207, 0.5)"},borderColors:{up:"rgb(75, 192, 192)",down:"rgb(255, 99, 132)",unchanged:"rgb(201, 203, 207)"}};height(){return this.base-this.y}inRange(t,e,n){return Mu(this,t,e,n)}inXRange(t,e){return Mu(this,t,null,e)}inYRange(t,e){return Mu(this,null,t,e)}getRange(t){return"x"===t?this.width/2:this.height/2}getCenterPoint(t){const{x:e,low:n,high:i}=this.getProps(["x","low","high"],t);return{x:e,y:(i+n)/2}}tooltipPosition(t){const{x:e,open:n,close:i}=this.getProps(["x","open","close"],t);return{x:e,y:(n+i)/2}}}const Cu=eo.defaults;class Tu extends _u{static id="ohlc";static defaults={..._u.defaults,lineWidth:2,armLength:null,armLengthRatio:.8};draw(t){const e=this,{x:n,open:i,high:s,low:o,close:a}=e,r=mt(e.armLengthRatio,Cu.elements.ohlc.armLengthRatio);let c=mt(e.armLength,Cu.elements.ohlc.armLength);null===c&&(c=e.width*r*.5),t.strokeStyle=a<i?mt(e.options.borderColors?e.options.borderColors.up:void 0,Cu.elements.ohlc.borderColors.up):a>i?mt(e.options.borderColors?e.options.borderColors.down:void 0,Cu.elements.ohlc.borderColors.down):mt(e.options.borderColors?e.options.borderColors.unchanged:void 0,Cu.elements.ohlc.borderColors.unchanged),t.lineWidth=mt(e.lineWidth,Cu.elements.ohlc.lineWidth),t.beginPath(),t.moveTo(n,s),t.lineTo(n,o),t.moveTo(n-c,i),t.lineTo(n,i),t.moveTo(n+c,a),t.lineTo(n,a),t.stroke()}}class Du extends _i{static overrides={label:"",parsing:!1,hover:{mode:"label"},animations:{numbers:{type:"number",properties:["x","y","base","width","open","high","low","close"]}},scales:{x:{type:"timeseries",offset:!0,ticks:{major:{enabled:!0},source:"data",maxRotation:0,autoSkip:!0,autoSkipPadding:75,sampleSize:100}},y:{type:"linear"}},plugins:{tooltip:{intersect:!1,mode:"index",callbacks:{label(t){const e=t.parsed;if(!dt(e.y))return Le.plugins.tooltip.callbacks.label(t);const{o:n,h:i,l:s,c:o}=e;return`O: ${n} H: ${i} L: ${s} C: ${o}`}}}}};getLabelAndValue(t){const e=this,n=e.getParsed(t),i=e._cachedMeta.iScale.axis,{o:s,h:o,l:a,c:r}=n,c=`O: ${s} H: ${o} L: ${a} C: ${r}`;return{label:`${e._cachedMeta.iScale.getLabelForValue(n[i])}`,value:c}}getUserBounds(t){const{min:e,max:n,minDefined:i,maxDefined:s}=t.getUserBounds();return{min:i?e:Number.NEGATIVE_INFINITY,max:s?n:Number.POSITIVE_INFINITY}}getMinMax(t){const e=this._cachedMeta,n=e._parsed,i=e.iScale.axis,s=this._getOtherScale(t),{min:o,max:a}=this.getUserBounds(s);if(n.length<2)return{min:0,max:1};if(t===e.iScale)return{min:n[0][i],max:n[n.length-1][i]};const r=n.filter((({x:t})=>t>=o&&t<a));let c=Number.POSITIVE_INFINITY,l=Number.NEGATIVE_INFINITY;for(let t=0;t<r.length;t++){const e=r[t];c=Math.min(c,e.l),l=Math.max(l,e.h)}return{min:c,max:l}}calculateElementProperties(t,e,n,i){const s=this,o=s._cachedMeta.vScale,a=o.getBasePixel(),r=s._calculateBarIndexPixels(t,e,i),c=s.chart.data.datasets[s.index].data[t],l=o.getPixelForValue(c.o),d=o.getPixelForValue(c.h),h=o.getPixelForValue(c.l),u=o.getPixelForValue(c.c);return{base:n?a:h,x:r.center,y:(h+d)/2,width:r.size,open:l,high:d,low:h,close:u}}draw(){const t=this,e=t.chart,n=t._cachedMeta.data;Fe(e.ctx,e.chartArea);for(let e=0;e<n.length;++e)n[e].draw(t._ctx);qe(e.ctx)}}class Pu extends _u{static id="candlestick";static defaults={..._u.defaults,borderWidth:1};draw(t){const e=this,{x:n,open:i,high:s,low:o,close:a}=e;let r,c=e.options.borderColors;"string"==typeof c&&(c={up:c,down:c,unchanged:c}),a<i?(r=mt(c?c.up:void 0,Le.elements.candlestick.borderColors.up),t.fillStyle=mt(e.options.backgroundColors?e.options.backgroundColors.up:void 0,Le.elements.candlestick.backgroundColors.up)):a>i?(r=mt(c?c.down:void 0,Le.elements.candlestick.borderColors.down),t.fillStyle=mt(e.options.backgroundColors?e.options.backgroundColors.down:void 0,Le.elements.candlestick.backgroundColors.down)):(r=mt(c?c.unchanged:void 0,Le.elements.candlestick.borderColors.unchanged),t.fillStyle=mt(e.backgroundColors?e.backgroundColors.unchanged:void 0,Le.elements.candlestick.backgroundColors.unchanged)),t.lineWidth=mt(e.options.borderWidth,Le.elements.candlestick.borderWidth),t.strokeStyle=r,t.beginPath(),t.moveTo(n,s),t.lineTo(n,Math.min(i,a)),t.moveTo(n,o),t.lineTo(n,Math.max(i,a)),t.stroke(),t.fillRect(n-e.width/2,a,e.width,i-a),t.strokeRect(n-e.width/2,a,e.width,i-a),t.closePath()}}class Eu extends Du{static id="candlestick";static defaults={...Du.defaults,dataElementType:Pu.id};static defaultRoutes=_i.defaultRoutes;updateElements(t,e,n,i){const s="reset"===i,o=this._getRuler(),{sharedOptions:a,includeOptions:r}=this._getSharedOptions(e,i);for(let c=e;c<e+n;c++){const e=a||this.resolveDataElementOptions(c,i),n=this.calculateElementProperties(c,o,s,e);r&&(n.options=e),this.updateElement(t[c],c,n,i)}}}eo.register(...er,yh,ku,Eu,Pu);class Au extends n{constructor(t,e,n){if(super(t,e,n),!e.symbol)throw new Error("Symbol is required for IntradayChartWidget");if(!e.wsManager)throw new Error("WebSocketManager is required for IntradayChartWidget");const i=g(e.symbol);if(!i.valid)throw new Error(`Invalid symbol: ${i.error}`);this.type="intraday-chart",this.wsManager=e.wsManager,this.symbol=i.sanitized,this.debug=e.debug||!1,this.source=e.source||"blueocean",this.rangeBack=e.rangeBack||0,this.chartType=e.chartType||"line",this.autoRefresh=void 0===e.autoRefresh||e.autoRefresh,this.refreshInterval=e.refreshInterval||6e4,this.refreshTimer=null,this.isUserInteracting=!1,this.marketIsOpen=null,this.marketStatusChecked=!1,this.chartData=null,this.chartInstance=null,this.unsubscribe=null,this.livePrice=null,this.companyName="",this.exchangeName="",this.mic="",this.symbolEditor=null,this.createWidgetStructure(),this.setupSymbolEditor(),this.initialize()}createWidgetStructure(){this.container.innerHTML='\n <div class="intraday-chart-widget">\n <div class="chart-header">\n <div class="chart-title-section">\n <div class="company-market-info">\n <span class="intraday-company-name"></span>\n </div>\n <h3 class="intraday-chart-symbol editable-symbol"\n title="Double-click to edit symbol"\n data-original-symbol="">AAPL</h3>\n </div>\n <div class="chart-change positive">+0.00 (+0.00%)</div>\n </div>\n\n <div class="chart-controls">\n <div class="chart-range-selector">\n <button class="range-btn active" data-range="0">1D</button>\n <button class="range-btn" data-range="5">5D</button>\n </div>\n <div class="chart-type-selector">\n <button class="type-btn active" data-type="line" title="Line Chart">Line</button>\n <button class="type-btn" data-type="area" title="Area Chart">Mountain</button>\n <button class="type-btn" data-type="candlestick" title="Candlestick Chart">Candles</button>\n </div>\n <button class="zoom-reset-btn" title="Reset Zoom">\n <svg width="16" height="16" viewBox="0 0 16 16" fill="none">\n <path d="M2 8a6 6 0 1 1 12 0A6 6 0 0 1 2 8zm6-7a7 7 0 1 0 0 14A7 7 0 0 0 8 1z" fill="currentColor"/>\n <path d="M5 8h6M8 5v6" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>\n </svg>\n Reset Zoom\n </button>\n </div>\n\n <div class="chart-container">\n <canvas id="intradayChart"></canvas>\n </div>\n\n <div class="chart-stats">\n <div class="stat-item stat-open">\n <span class="stat-label">Open</span>\n <span class="stat-value">$0.00</span>\n </div>\n <div class="stat-item stat-high">\n <span class="stat-label">High</span>\n <span class="stat-value">$0.00</span>\n </div>\n <div class="stat-item stat-low">\n <span class="stat-label">Low</span>\n <span class="stat-value">$0.00</span>\n </div>\n <div class="stat-item stat-close">\n <span class="stat-label">Close</span>\n <span class="stat-value">$0.00</span>\n </div>\n <div class="stat-item stat-volume">\n <span class="stat-label">Volume</span>\n <span class="stat-value">0</span>\n </div>\n </div>\n\n <div class="widget-loading-overlay hidden">\n <div class="loading-spinner"></div>\n <div class="loading-text">Loading chart data...</div>\n </div>\n </div>\n';const t=this.container.querySelector(".intraday-chart-symbol");t&&(t.textContent=this.symbol),this.setupRangeButtons(),this.setupChartTypeButtons(),this.addStyles()}setupSymbolEditor(){this.symbolEditor=new s(this,{maxLength:10,placeholder:"Enter symbol...",onSymbolChange:this.handleSymbolChange.bind(this),debug:this.debug,autoUppercase:!0,symbolType:"nightsession"});const t=this.container.querySelector(".intraday-chart-symbol");t&&(t.textContent=this.symbol,t.dataset.originalSymbol=this.symbol)}async handleSymbolChange(t,e){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;this.debug&&(console.log("[IntradayChartWidget] Symbol change requested:",t),console.log("[IntradayChartWidget] Validation data:",n));const i=g(t);if(!i.valid)return this.debug&&console.log("[IntradayChartWidget] Invalid symbol:",i.error),{success:!1,error:i.error};const s=i.sanitized;if(n&&(this.companyName=n.comp_name||"",this.exchangeName=n.market_name||"",this.mic=n.mic||"",this.debug&&console.log("[IntradayChartWidget] Extracted company info:",{companyName:this.companyName,exchangeName:this.exchangeName})),s===this.symbol)return this.debug&&console.log("[IntradayChartWidget] Same symbol, no change needed"),{success:!0};try{return this.showLoading(),this.stopAutoRefresh(),this.unsubscribe&&(this.debug&&console.log(`[IntradayChartWidget] Unsubscribing from ${e}`),this.unsubscribe(),this.unsubscribe=null),this.chartInstance&&(this.debug&&console.log("[IntradayChartWidget] Clearing chart for symbol change"),this.chartInstance.destroy(),this.chartInstance=null),this.chartData=null,this.livePrice=null,this.symbol=s,this.updateCompanyName(),await this.loadChartData(),this.debug&&console.log(`[IntradayChartWidget] Successfully changed symbol from ${e} to ${s}`),{success:!0}}catch(t){return console.error("[IntradayChartWidget] Error changing symbol:",t),this.showError(`Failed to load data for ${s}`),{success:!1,error:`Failed to load ${s}`}}}async initialize(){await this.validateInitialSymbol(),this.updateCompanyName(),await this.loadChartData()}async validateInitialSymbol(){try{const t=this.wsManager.getApiService();if(!t)return void(this.debug&&console.log("[IntradayChartWidget] API service not available for initial validation"));const e=await t.quotel1(this.symbol);if(e&&e.data&&e.data[0]){const t=e.data[0];this.companyName=t.comp_name||"",this.exchangeName=t.market_name||"",this.mic=t.mic||"",this.debug&&console.log("[IntradayChartWidget] Initial symbol validated:",{symbol:this.symbol,companyName:this.companyName,exchangeName:this.exchangeName,mic:this.mic})}}catch(t){this.debug&&console.warn("[IntradayChartWidget] Initial symbol validation failed:",t)}}updateCompanyName(){const t=this.container.querySelector(".intraday-company-name");t&&(t.textContent=this.companyName||"")}setupRangeButtons(){const t=this.container.querySelectorAll(".range-btn");t.forEach((e=>{e.addEventListener("click",(async e=>{const n=parseInt(e.target.getAttribute("data-range"));t.forEach((t=>t.classList.remove("active"))),e.target.classList.add("active"),this.rangeBack=n,await this.loadChartData(),0===n?(await this.startAutoRefresh(),await this.subscribeToLivePrice()):(this.stopAutoRefresh(),this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=null,this.livePrice=null))}))}))}setupChartTypeButtons(){const t=this.container.querySelectorAll(".type-btn");t.forEach((e=>{e.addEventListener("click",(e=>{const n=e.target.getAttribute("data-type");t.forEach((t=>t.classList.remove("active"))),e.target.classList.add("active"),this.chartType=n,this.renderChart(),this.updateStats()}))}))}addStyles(){if(this.options.skipStyleInjection||document.querySelector('link[href*="mdas-styles.css"]'))this.debug&&console.log("[IntradayChartWidget] Skipping style injection - external styles detected");else if(!document.querySelector("#intraday-chart-styles"))try{const t=document.createElement("style");t.id="intraday-chart-styles",t.textContent="\n .intraday-chart-widget {\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;\n background: white;\n border-radius: 12px;\n padding: 20px;\n box-shadow: 0 2px 8px rgba(0,0,0,0.1);\n position: relative;\n width: 100%;\n min-width: 600px;\n max-width: 1400px;\n margin: 0 auto;\n }\n\n .chart-header {\n display: flex;\n justify-content: space-between;\n align-items: center;\n margin-bottom: 20px;\n padding-bottom: 15px;\n border-bottom: 1px solid #e5e7eb;\n }\n\n .chart-title-section {\n display: flex;\n flex-direction: column;\n gap: 4px;\n }\n\n .company-market-info {\n display: flex;\n gap: 8px;\n align-items: center;\n font-size: 0.75em;\n color: #6b7280;\n }\n\n .intraday-company-name {\n font-weight: 500;\n }\n\n .intraday-chart-symbol {\n font-size: 1.5em;\n font-weight: 700;\n color: #1f2937;\n margin: 0;\n }\n\n .intraday-chart-source {\n font-size: 0.75em;\n padding: 4px 8px;\n border-radius: 4px;\n background: #e0e7ff;\n color: #4338ca;\n font-weight: 600;\n }\n\n .chart-change {\n font-size: 1.1em;\n font-weight: 600;\n padding: 6px 12px;\n border-radius: 6px;\n }\n\n .chart-change.positive {\n color: #059669;\n background: #d1fae5;\n }\n\n .chart-change.negative {\n color: #dc2626;\n background: #fee2e2;\n }\n\n .chart-controls {\n display: flex;\n justify-content: space-between;\n align-items: center;\n margin-bottom: 15px;\n }\n\n .chart-range-selector {\n display: flex;\n gap: 8px;\n }\n\n .range-btn {\n padding: 8px 16px;\n border: 1px solid #e5e7eb;\n background: white;\n border-radius: 6px;\n font-size: 0.875em;\n font-weight: 600;\n color: #6b7280;\n cursor: pointer;\n transition: all 0.2s ease;\n }\n\n .range-btn:hover {\n background: #f9fafb;\n border-color: #d1d5db;\n }\n\n .range-btn.active {\n background: #667eea;\n color: white;\n border-color: #667eea;\n }\n\n .range-btn:focus {\n outline: none;\n box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);\n }\n\n .chart-type-selector {\n display: flex;\n gap: 8px;\n }\n\n .type-btn {\n padding: 8px 16px;\n border: 1px solid #e5e7eb;\n background: white;\n border-radius: 6px;\n font-size: 0.875em;\n font-weight: 600;\n color: #6b7280;\n cursor: pointer;\n transition: all 0.2s ease;\n }\n\n .type-btn:hover {\n background: #f9fafb;\n border-color: #d1d5db;\n }\n\n .type-btn.active {\n background: #10b981;\n color: white;\n border-color: #10b981;\n }\n\n .type-btn:focus {\n outline: none;\n box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);\n }\n\n .zoom-reset-btn {\n display: flex;\n align-items: center;\n gap: 6px;\n padding: 8px 12px;\n border: 1px solid #e5e7eb;\n background: white;\n border-radius: 6px;\n font-size: 0.875em;\n font-weight: 500;\n color: #6b7280;\n cursor: pointer;\n transition: all 0.2s ease;\n }\n\n .zoom-reset-btn:hover {\n background: #f9fafb;\n border-color: #667eea;\n color: #667eea;\n }\n\n .zoom-reset-btn:focus {\n outline: none;\n box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);\n }\n\n .zoom-reset-btn svg {\n flex-shrink: 0;\n }\n\n .chart-container {\n height: 500px;\n margin-bottom: 20px;\n position: relative;\n }\n\n .chart-stats {\n display: grid;\n grid-template-columns: repeat(5, 1fr);\n gap: 15px;\n padding: 15px;\n background: #f9fafb;\n border-radius: 8px;\n }\n\n .stat-item {\n display: flex;\n flex-direction: column;\n gap: 4px;\n }\n\n .stat-label {\n font-size: 0.75em;\n color: #6b7280;\n font-weight: 600;\n text-transform: uppercase;\n letter-spacing: 0.5px;\n }\n\n .stat-value {\n font-size: 1.1em;\n font-weight: 700;\n color: #1f2937;\n }\n\n .widget-loading-overlay {\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background: rgba(255, 255, 255, 0.4);\n display: flex;\n flex-direction: row;\n align-items: center;\n justify-content: center;\n gap: 10px;\n padding: 10px 16px;\n border-radius: 12px;\n z-index: 10;\n pointer-events: none;\n backdrop-filter: blur(1px);\n }\n\n .widget-loading-overlay.hidden {\n display: none;\n }\n\n .loading-spinner {\n width: 20px;\n height: 20px;\n border: 3px solid #e5e7eb;\n border-top-color: #667eea;\n border-radius: 50%;\n animation: spin 0.8s linear infinite;\n }\n\n .loading-text {\n color: #6b7280;\n font-size: 0.875em;\n font-weight: 500;\n }\n\n @keyframes spin {\n to { transform: rotate(360deg); }\n }\n\n @media (max-width: 768px) {\n .intraday-chart-widget {\n min-width: unset;\n padding: 15px;\n }\n\n .chart-stats {\n grid-template-columns: repeat(3, 1fr);\n gap: 10px;\n }\n\n .chart-container {\n height: 350px;\n }\n\n .intraday-chart-symbol {\n font-size: 1.2em;\n }\n }\n\n .widget-error {\n padding: 15px;\n background: #fee2e2;\n border: 1px solid #fecaca;\n border-radius: 8px;\n color: #dc2626;\n font-size: 0.9em;\n margin-top: 10px;\n }\n",document.head.appendChild(t),this.debug&&console.log("[IntradayChartWidget] Styles injected successfully")}catch(t){console.warn("[IntradayChartWidget] Failed to inject styles:",t),console.warn('[IntradayChartWidget] Please add <link rel="stylesheet" href="mdas-styles.css"> to your HTML')}}async loadChartData(){try{this.showLoading(),this.clearError();const t=this.wsManager.getApiService();if(!t)throw new Error("API service not available");const e=7;let n=this.rangeBack,i=!1,s=null,o=null,a=!1;for(let r=0;r<e;r++){if(this.debug&&console.log(`[IntradayChartWidget] Loading data for ${this.symbol} from ${this.source}, range_back: ${n} (attempt ${r+1}/${e})`),s=await t.getIntradayChart(this.source,this.symbol,n),console.log("[IntradayChartWidget] API response type:",typeof s),console.log("[IntradayChartWidget] API response:",s),s&&(console.log("[IntradayChartWidget] Response keys:",Object.keys(s)),Array.isArray(s)&&(console.log("[IntradayChartWidget] Response is array, length:",s.length),s.length>0&&(console.log("[IntradayChartWidget] First item:",s[0]),console.log("[IntradayChartWidget] First item keys:",Object.keys(s[0]))))),s&&s.error)throw new Error(s.error||"Server error");if(o=s,s&&s.data&&Array.isArray(s.data)&&(console.log("[IntradayChartWidget] Found data array in response.data"),o=s.data),o&&Array.isArray(o)&&o.length>0){i=!0,n!==this.rangeBack&&(a=!0,this.debug&&console.log(`[IntradayChartWidget] Using fallback data: requested rangeBack ${this.rangeBack}, got data from rangeBack ${n}`));break}console.log(`[IntradayChartWidget] No data for rangeBack ${n}, trying ${n+1}...`),n++}if(!i||!o||0===o.length)throw new Error(`No intraday data available for ${this.symbol} in the past ${e} days`);if(console.log("[IntradayChartWidget] Processing",o.length,"data points"),this.chartData=new D(o),console.log("[IntradayChartWidget] Model created with",this.chartData.dataPoints.length,"points"),0===this.chartData.dataPoints.length)throw console.error("[IntradayChartWidget] Model has no data points after processing"),new Error(`No valid data points for ${this.symbol}`);this.renderChart(),this.updateStats(),this.hideLoading(),this.debug&&console.log(`[IntradayChartWidget] Loaded ${o.length} data points`),0!==this.rangeBack||a?(this.stopAutoRefresh(),this.debug&&console.log("[IntradayChartWidget] Not starting auto-refresh for historical/fallback data")):(await this.startAutoRefresh(),this.subscribeToLivePrice())}catch(t){console.error("[IntradayChartWidget] Error loading chart data:",t),this.hideLoading();let e="Failed to load chart data";t.message.includes("No intraday data")?e=t.message:t.message.includes("API service not available")?e="Unable to connect to data service":t.message.includes("HTTP error")||t.message.includes("status: 4")?e=`Unable to load data for ${this.symbol}`:t.message.includes("status: 5")?e="Server error. Please try again later":t.message.includes("Failed to fetch")&&(e="Network error. Please check your connection"),this.showError(e)}}subscribeToLivePrice(){this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=null);const t="bruce"===this.source?"querybrucel1":"queryblueoceanl1";this.debug&&console.log(`[IntradayChartWidget] Subscribing to live price with ${t} for ${this.symbol}`),this.unsubscribe=this.wsManager.subscribe(this.widgetId,[t],this.handleMessage.bind(this),this.symbol)}handleError(t){this.debug&&console.error("[IntradayChartWidget] WebSocket error:",t.message||t)}handleData(t){console.log("[IntradayChartWidget] handleData called with:",t),console.log("[IntradayChartWidget] Looking for symbol:",this.symbol),console.log("[IntradayChartWidget] Message is array?",Array.isArray(t));let e=null;if(Array.isArray(t)){console.log("[IntradayChartWidget] Processing array format, length:",t.length);const n=t.find((t=>t.Symbol===this.symbol));console.log("[IntradayChartWidget] Found symbol data:",n),n&&!n.NotFound&&(e=n)}else"queryblueoceanl1"===t.type||"querybrucel1"===t.type?(console.log("[IntradayChartWidget] Processing wrapped format"),t[0]?.Symbol!==this.symbol||t[0].NotFound||(e=t[0])):t.Symbol!==this.symbol||t.NotFound||(console.log("[IntradayChartWidget] Processing direct format"),e=t);if(!e)return void console.log("[IntradayChartWidget] No matching price data found for symbol:",this.symbol);console.log("[IntradayChartWidget] Price data found:",e);let n=null;void 0!==e.LastPx&&null!==e.LastPx?(n=parseFloat(e.LastPx),console.log("[IntradayChartWidget] Price from LastPx:",n)):void 0!==e.Last&&null!==e.Last?(n=parseFloat(e.Last),console.log("[IntradayChartWidget] Price from Last:",n)):void 0!==e.last_price&&null!==e.last_price?(n=parseFloat(e.last_price),console.log("[IntradayChartWidget] Price from last_price:",n)):void 0!==e.TradePx&&null!==e.TradePx?(n=parseFloat(e.TradePx),console.log("[IntradayChartWidget] Price from TradePx:",n)):void 0!==e.Close&&null!==e.Close?(n=parseFloat(e.Close),console.log("[IntradayChartWidget] Price from Close:",n)):void 0!==e.close&&null!==e.close&&(n=parseFloat(e.close),console.log("[IntradayChartWidget] Price from close:",n)),console.log("[IntradayChartWidget] Extracted price:",n),n&&!isNaN(n)&&n>0?(this.livePrice=n,console.log("[IntradayChartWidget] Updating live price line to:",n),this.updateLivePriceLine(),console.log(`[IntradayChartWidget] Live price update: $${n.toFixed(2)}`)):console.log("[IntradayChartWidget] Invalid price, not updating:",n)}updateLivePriceLine(){this.chartInstance&&this.livePrice?this.chartInstance.options.plugins.annotation&&(this.chartInstance.options.plugins.annotation.annotations.livePriceLine.value=this.livePrice,this.chartInstance.options.plugins.annotation.annotations.livePriceLine.label.content=`$${this.livePrice.toFixed(2)}`,this.chartInstance.options.plugins.annotation.annotations.livePriceLine.label.display=!0,this.debug&&console.log("[IntradayChartWidget] Live price line updated:",{price:this.livePrice,label:this.chartInstance.options.plugins.annotation.annotations.livePriceLine.label.content}),this.chartInstance.update("none")):this.debug&&console.log("[IntradayChartWidget] Cannot update live price line:",{hasChart:!!this.chartInstance,livePrice:this.livePrice})}async isMarketOpen(){const t=new Date,e=t.toLocaleString("en-US",{timeZone:"America/New_York",weekday:"short"}),n=parseInt(t.toLocaleString("en-US",{timeZone:"America/New_York",hour12:!1,hour:"numeric"}),10),i=parseInt(t.toLocaleString("en-US",{timeZone:"America/New_York",minute:"numeric"}),10);if("Sat"===e||"Sun"===e)return!1;const s=n>=20||n<4;if(this.debug&&console.log(`[IntradayChartWidget] Market check: ET hour=${n}, minute=${i}, day=${e}, open=${s}`),!s)return this.debug&&console.log("[IntradayChartWidget] Market is currently closed (outside 8pm-4am ET on weekdays)."),!1;if(!this.marketStatusChecked)try{const t=this.wsManager.getApiService(),e=await t.getMarketStatus(this.source);if(e&&Array.isArray(e)&&e.length>0){const t=e[0].status;return this.marketIsOpen=t&&"open"===t.toLowerCase(),this.marketStatusChecked=!0,this.debug&&console.log(`[IntradayChartWidget] Market status from API: ${t} (${this.marketIsOpen?"Open":"Closed"})`),this.marketIsOpen}}catch(t){return this.debug&&console.warn("[IntradayChartWidget] Failed to get market status from API, assuming open based on time:",t),this.marketIsOpen=!0,this.marketStatusChecked=!0,!0}return!1!==this.marketIsOpen&&(!0!==this.marketIsOpen||(!(3===n&&i>=45)||(this.debug&&console.log("[IntradayChartWidget] Approaching market close, re-checking status..."),this.marketStatusChecked=!1,await this.isMarketOpen())))}async startAutoRefresh(){if(this.stopAutoRefresh(),!this.autoRefresh)return;await this.isMarketOpen()?(this.debug&&console.log(`[IntradayChartWidget] Starting auto-refresh every ${this.refreshInterval/1e3} seconds`),this.refreshTimer=setInterval((async()=>{if(!await this.isMarketOpen())return this.debug&&console.log("[IntradayChartWidget] Market closed. Stopping auto-refresh."),void this.stopAutoRefresh();if(this.isUserInteracting)this.debug&&console.log("[IntradayChartWidget] Skipping refresh - user is interacting");else{this.debug&&console.log("[IntradayChartWidget] Auto-refreshing chart data");try{const t=this.wsManager.getApiService(),e=await t.getIntradayChart(this.source,this.symbol,this.rangeBack);e&&Array.isArray(e)&&(this.chartData=new D(e),this.renderChart(),this.updateStats(),this.debug&&console.log(`[IntradayChartWidget] Auto-refresh complete - ${e.length} data points`))}catch(t){console.error("[IntradayChartWidget] Auto-refresh failed:",t)}}}),this.refreshInterval)):this.debug&&console.log("[IntradayChartWidget] Market is closed. Auto-refresh will not start.")}stopAutoRefresh(){this.refreshTimer&&(this.debug&&console.log("[IntradayChartWidget] Stopping auto-refresh"),clearInterval(this.refreshTimer),this.refreshTimer=null)}parseTimestamp(t){return new Date(t)}renderChart(){if(console.log("[IntradayChartWidget] renderChart called"),!this.chartData||0===this.chartData.dataPoints.length)return void console.error("[IntradayChartWidget] No data to render");console.log("[IntradayChartWidget] Chart data points:",this.chartData.dataPoints.length);const t=this.container.querySelector("#intradayChart");if(console.log("[IntradayChartWidget] Canvas element:",t),!t)return void console.error("[IntradayChartWidget] Canvas element not found");if(this.chartInstance){console.log("[IntradayChartWidget] Destroying existing chart instance");try{this.chartInstance.destroy(),this.chartInstance=null}catch(t){console.error("[IntradayChartWidget] Error destroying chart:",t),this.chartInstance=null}}const e=t.getContext("2d");console.log("[IntradayChartWidget] Canvas context:",e),console.log("[IntradayChartWidget] Preparing chart data...");const n=this.chartData.getStats();console.log("[IntradayChartWidget] Stats:",n);const i=n.change>=0,s=i?"#10b981":"#ef4444";let o,a;const r=this.chartData.dataPoints;if(0===r.length)return console.error("[IntradayChartWidget] No valid data points from model"),void this.showError("No valid chart data available");if(console.log("[IntradayChartWidget] Rendering",r.length,"data points"),"candlestick"===this.chartType){if(o=r.map((t=>({x:this.parseTimestamp(t.time).getTime(),o:t.open,h:t.high,l:t.low,c:t.close}))).filter((t=>!isNaN(t.x)&&t.x>0)),0===o.length)return console.error("[IntradayChartWidget] No valid candlestick data points after date parsing"),void this.showError("Unable to parse chart data timestamps");a={label:"Price",data:o,color:{up:"#10b981",down:"#ef4444",unchanged:"#6b7280"},borderColor:{up:"#10b981",down:"#ef4444",unchanged:"#6b7280"}}}else{if(o=r.map((t=>({x:this.parseTimestamp(t.time),y:t.close}))).filter((t=>{const e=t.x.getTime();return!isNaN(e)&&e>0})),0===o.length)return console.error("[IntradayChartWidget] No valid chart data points after date parsing"),void this.showError("Unable to parse chart data timestamps");const t=e.createLinearGradient(0,0,0,300);i?(t.addColorStop(0,"rgba(16, 185, 129, 0.3)"),t.addColorStop(1,"rgba(16, 185, 129, 0.01)")):(t.addColorStop(0,"rgba(239, 68, 68, 0.3)"),t.addColorStop(1,"rgba(239, 68, 68, 0.01)")),a={label:"Price",data:o,borderColor:s,backgroundColor:"area"===this.chartType?t:"transparent",borderWidth:2,fill:"area"===this.chartType,tension:.4,pointRadius:0,pointHoverRadius:4,pointBackgroundColor:s,pointBorderColor:"#fff",pointBorderWidth:2}}console.log("[IntradayChartWidget] Chart data points prepared:",o.length),console.log("[IntradayChartWidget] First data point - Source time:",r[0].time),console.log("[IntradayChartWidget] First chart point:",o[0]),console.log("[IntradayChartWidget] Last data point - Source time:",r[r.length-1].time),console.log("[IntradayChartWidget] Last chart point:",o[o.length-1]);const c=o.map((t=>"candlestick"===this.chartType?t.x:t.x.getTime())),l=Math.min(...c),d=Math.max(...c);console.log("[IntradayChartWidget] X-axis bounds:",{min:l,max:d,minDate:new Date(l),maxDate:new Date(d)});const h={type:"candlestick"===this.chartType?"candlestick":"line",data:{datasets:[a]},options:{responsive:!0,maintainAspectRatio:!1,interaction:{intersect:!1,mode:"index"},plugins:{legend:{display:!1},decimation:{enabled:o.length>1e3,algorithm:"lttb",samples:500,threshold:1e3},tooltip:{enabled:!0,backgroundColor:"rgba(0, 0, 0, 0.8)",titleColor:"#fff",bodyColor:"#fff",borderColor:s,borderWidth:1,padding:10,displayColors:!1,callbacks:{title:t=>{const e=t[0].dataIndex,n=r[e];if(n){return new Date(n.time).toLocaleString("en-US",{timeZone:"America/New_York",month:"2-digit",day:"2-digit",year:"numeric",hour:"numeric",minute:"2-digit",second:"2-digit",hour12:!0})}return""},label:t=>{const e=t.dataIndex,n=r[e];return n?"candlestick"===this.chartType?[`Open: $${n.open.toFixed(2)}`,`High: $${n.high.toFixed(2)}`,`Low: $${n.low.toFixed(2)}`,`Close: $${n.close.toFixed(2)}`,`Volume: ${this.chartData.formatVolume(n.volume)}`]:[`Price: $${n.close.toFixed(2)}`,`Open: $${n.open.toFixed(2)}`,`High: $${n.high.toFixed(2)}`,`Low: $${n.low.toFixed(2)}`,`Volume: ${this.chartData.formatVolume(n.volume)}`]:[]}}},zoom:{pan:{enabled:!0,mode:"x",modifierKey:"ctrl"},zoom:{wheel:{enabled:!0,speed:.1},pinch:{enabled:!0},mode:"x"},limits:{x:{min:"original",max:"original"}}},annotation:{annotations:{livePriceLine:{type:"line",scaleID:"y",value:this.livePrice||n.close,borderColor:"#667eea",borderWidth:2,borderDash:[5,5],label:{display:!0,content:this.livePrice?`$${this.livePrice.toFixed(2)}`:`$${n.close.toFixed(2)}`,enabled:!0,position:"end",backgroundColor:"rgb(102, 126, 234)",color:"#ffffff",font:{size:12,weight:"bold",family:"system-ui, -apple-system, sans-serif"},padding:{top:4,bottom:4,left:8,right:8},borderRadius:4,xAdjust:-10,yAdjust:0}}}}},scales:{x:{type:"time",min:l,max:d,time:{unit:0===this.rangeBack?"minute":"hour",displayFormats:{minute:"h:mm a",hour:"MMM d, ha"},tooltipFormat:"MMM d, h:mm a"},grid:{display:!1},ticks:{maxTicksLimit:10,color:"#6b7280",autoSkip:!0,maxRotation:0,minRotation:0}},y:{position:"right",grid:{color:"rgba(0, 0, 0, 0.05)"},ticks:{color:"#6b7280",callback:function(t){return"$"+t.toFixed(2)}},afterDataLimits:t=>{const e=.1*(t.max-t.min);t.max+=e,t.min-=e}}}}};console.log("[IntradayChartWidget] Creating Chart.js instance with config:",h),console.log("[IntradayChartWidget] Chart available?",void 0!==eo);try{this.chartInstance=new eo(e,h),console.log("[IntradayChartWidget] Chart instance created successfully:",this.chartInstance)}catch(t){throw console.error("[IntradayChartWidget] Error creating chart:",t),t}t.addEventListener("mouseenter",(()=>{this.isUserInteracting=!0})),t.addEventListener("mouseleave",(()=>{this.isUserInteracting=!1})),this.setupZoomReset()}setupZoomReset(){const t=this.container.querySelector(".zoom-reset-btn");t&&t.addEventListener("click",(()=>{this.chartInstance&&(this.chartInstance.resetZoom(),this.debug&&console.log("[IntradayChartWidget] Zoom reset"))}))}updateStats(){if(!this.chartData)return;const t=this.chartData.getStats(),e=this.container.querySelector(".stat-high .stat-value"),n=this.container.querySelector(".stat-low .stat-value"),i=this.container.querySelector(".stat-open .stat-value"),s=this.container.querySelector(".stat-close .stat-value"),o=this.container.querySelector(".stat-volume .stat-value"),a=this.container.querySelector(".chart-change");if(e&&(e.textContent=`$${t.high.toFixed(2)}`),n&&(n.textContent=`$${t.low.toFixed(2)}`),i&&(i.textContent=`$${t.open.toFixed(2)}`),s&&(s.textContent=`$${t.close.toFixed(2)}`),o&&(o.textContent=this.chartData.formatVolume(t.volume)),a){const e=t.change>=0?"positive":"negative";a.className=`chart-change ${e}`;const n=t.change>=0?"+":"";a.textContent=`${n}${t.change.toFixed(2)} (${n}${t.changePercent.toFixed(2)}%)`}}async refreshData(){await this.loadChartData()}destroy(){this.stopAutoRefresh(),this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=null),this.chartInstance&&(this.chartInstance.destroy(),this.chartInstance=null),this.symbolEditor&&(this.symbolEditor.destroy(),this.symbolEditor=null),super.destroy()}}class Lu{constructor(t){this.stateManager=t,this.widgets=new Map}createWidget(t,e){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const i=this.generateWidgetId();let s;switch(t){case"quote-level1":s=new b(e,n,i);break;case"night-session":s=new x(e,n,i);break;case"options":s=new w(e,n,i);break;case"option-chain":s=new M(e,n,i);break;case"data":s=new C(e,n,i);break;case"combined-market":s=new T(e,n,i);break;case"intraday-chart":s=new Au(e,n,i);break;default:throw new Error(`Unknown widget type: ${t}`)}return this.widgets.set(i,s),s}generateWidgetId(){return`widget_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}destroyWidget(t){const e=this.widgets.get(t);e&&(e.destroy(),this.widgets.delete(t))}getWidgetCount(){return this.widgets.size}destroy(){this.widgets.forEach((t=>t.destroy())),this.widgets.clear()}}class Iu{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"https://mdas-api-dev.viewtrade.dev";this.token=t,this.baseUrl=e}async request(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const n=`${this.baseUrl}${t}`,i={method:"GET",headers:{Authorization:`Bearer ${this.token}`,"Content-Type":"application/json",...e.headers},...e};try{const t=await fetch(n,i);if(!t.ok)throw new Error(`HTTP error! status: ${t.status}`);return await t.json()}catch(t){throw console.error(`[ApiService] Request failed for ${n}:`,t),t}}async getOptionChainDates(t){return this.request(`/api/quote/option-chain-dates?symbol=${t}&response_camel_case=false`)}async quoteOptionl1(t){return this.request(`/api/quote/option-level1?option_names=${t}&response_camel_case=false`)}async quotel1(t){return this.request(`/api/quote/level1?symbols=${t}&response_camel_case=false`)}async quoteBlueOcean(t){return this.request(`/api/quote/night-session/level1/blueocean?symbols=${t}&response_camel_case=false`)}async getIntradayChart(t,e){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;return this.request(`/api/quote/night-session/intraday/${t}?symbol=${e}&range_back=${n}`)}async getMarketStatus(t){return this.request(`/api/quote/night-session/market-status/${t}`)}}class Ou{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.config={debug:t.debug||!1,token:t.token,baseUrl:t.baseUrl||"ws://localhost:3000/wssub",apiBaseUrl:t.apiBaseUrl,maxConnections:t.maxConnections||1,reconnectOptions:{maxAttempts:t.reconnectOptions?.maxAttempts||10,initialDelay:t.reconnectOptions?.initialDelay||1e3,maxDelay:t.reconnectOptions?.maxDelay||3e4,backoff:t.reconnectOptions?.backoff||1.5,jitter:t.reconnectOptions?.jitter||.3},timeouts:{connection:t.timeouts?.connection||1e4,inactivity:t.timeouts?.inactivity||9e4},enableActivityMonitoring:!1},this.apiService=new Iu(this.config.token,this.config.apiBaseUrl),this.connection=null,this.connectionState="disconnected",this.reconnectAttempts=0,this.reconnectTimer=null,this.connectionStartTime=null,this.subscriptions=new Map,this.activeSubscriptions=new Set,this.messageQueue=[],this.symbolSubscriptions=new Map,this.typeSubscriptions=new Map,this.lastMessageCache=new Map,this.connectionPromise=null,this.reloginCallback=t.reloginCallback||null,this.isReloginInProgress=!1,this.lastMessageReceived=null,this.activityCheckInterval=null,this.isOnline="undefined"==typeof navigator||navigator.onLine,this.onlineHandler=null,this.offlineHandler=null,this.circuitBreaker={state:"closed",failureCount:0,failureThreshold:5,timeout:6e4,lastFailureTime:null,resetTimer:null},this.metrics={successfulConnections:0,failedConnections:0,totalReconnects:0,avgConnectionTime:0,lastSuccessfulConnection:null,messagesReceived:0,messagesSent:0},this.handleOpen=this.handleOpen.bind(this),this.handleMessage=this.handleMessage.bind(this),this.handleClose=this.handleClose.bind(this),this.handleError=this.handleError.bind(this),this.isManualDisconnect=!1,this._initNetworkMonitoring(),this.config.debug&&console.log("[WebSocketManager] Initialized with config:",this.config)}async connect(){return"connected"===this.connectionState||"connecting"===this.connectionState?Promise.resolve():new Promise(((t,e)=>{this.connectionPromise={resolve:t,reject:e},this._connect()}))}subscribe(t,e,n){let i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,s=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};Array.isArray(e)||(e=[e]);const o=this.subscriptions.get(t);if(o){if(this.config.debug&&console.log(`[WebSocketManager] Cleaning up existing subscription for widget ${t} before re-subscribing`),o.symbol){const e=this.symbolSubscriptions.get(o.symbol);e&&(e.delete(t),0===e.size&&this.symbolSubscriptions.delete(o.symbol))}o.types&&o.types.forEach((e=>{const n=this.typeSubscriptions.get(e);n&&(n.delete(t),0===n.size&&this.typeSubscriptions.delete(e))}))}const a={types:new Set(e),callback:n,symbol:i?.toUpperCase(),additionalParams:s};if(this.subscriptions.set(t,a),i){const e=i.toUpperCase();this.symbolSubscriptions.has(e)||this.symbolSubscriptions.set(e,new Set),this.symbolSubscriptions.get(e).add(t)}return e.forEach((e=>{this.typeSubscriptions.has(e)||this.typeSubscriptions.set(e,new Set),this.typeSubscriptions.get(e).add(t)})),this.config.debug&&console.log(`[WebSocketManager] Widget ${t} subscribed to:`,e,`for symbol: ${i}`,s),"connected"===this.connectionState&&(this._sendSubscriptions(e),e.forEach((e=>{const s=i?`${e}:${i}`:e,o=this.lastMessageCache.get(s);if(o&&this.activeSubscriptions.has(s)){this.config.debug&&console.log(`[WebSocketManager] Sending cached data to new widget ${t} for ${s}`);try{n({event:"data",data:o,widgetId:t})}catch(e){console.error(`[WebSocketManager] Error sending cached data to widget ${t}:`,e)}}}))),()=>this.unsubscribe(t)}unsubscribe(t){const e=this.subscriptions.get(t);if(e){if(e.symbol&&e.types&&e.types.forEach((t=>{this.sendUnsubscribe(t,e.symbol,e.additionalParams||{})})),e.symbol){const n=this.symbolSubscriptions.get(e.symbol);n&&(n.delete(t),0===n.size&&this.symbolSubscriptions.delete(e.symbol))}e.types.forEach((e=>{const n=this.typeSubscriptions.get(e);n&&(n.delete(t),0===n.size&&this.typeSubscriptions.delete(e))})),this.subscriptions.delete(t),this.config.debug&&console.log(`[WebSocketManager] Widget ${t} unsubscribed`),this._cleanupUnusedSubscriptions()}}sendUnsubscribe(t,e){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};try{let i,s;"queryoptionchain"===t?(s=`${t}:${e}:${n.date||""}`,i={type:t,underlying:e,date:n.date,unsubscribe:!0}):"queryoptionl1"===t?(s=`${t}:${e}`,i={type:t,optionName:e,unsubscribe:!0}):(s=`${t}:${e}`,i={type:t,symbol:e,unsubscribe:!0}),this.config.debug&&console.log(`[WebSocketManager] Sending unsubscribe for ${s}:`,i),this.send(i),this.activeSubscriptions.delete(s),this.config.debug&&console.log(`[WebSocketManager] Removed ${s} from active subscriptions`)}catch(t){console.error("[WebSocketManager] Error sending unsubscribe:",t)}}sendUnsubscribeAll(){try{const t={unsubscribe_all:!0};this.config.debug&&console.log("[WebSocketManager] Sending unsubscribe all"),this.send(t),this.activeSubscriptions.clear()}catch(t){console.error("[WebSocketManager] Error sending unsubscribe all:",t)}}send(t){if("connected"!==this.connectionState||!this.connection||1!==this.connection.readyState)return this.messageQueue&&Array.isArray(this.messageQueue)||(this.messageQueue=[]),this.messageQueue.push(t),this.config.debug&&console.log("[WebSocketManager] Message queued (not connected):",t),!1;try{return this.connection.send(JSON.stringify(t)),this.config.debug&&console.log("[WebSocketManager] Sent message:",t),this.metrics.messagesSent++,!0}catch(t){return console.error("[WebSocketManager] Error sending message:",t),!1}}getConnectionState(){return this.connectionState}getSubscriptionCount(){return this.subscriptions.size}_connect(){if("connecting"!==this.connectionState){this.isManualDisconnect=!1,this.connectionState="connecting",this.connectionStartTime=Date.now();try{this.connection&&(this.connection.removeEventListener("open",this.handleOpen),this.connection.removeEventListener("message",this.handleMessage),this.connection.removeEventListener("close",this.handleClose),this.connection.removeEventListener("error",this.handleError),this.connection=null);const t=`${this.config.baseUrl}?token=${this.config.token}`;this.config.debug&&console.log("[WebSocketManager] Connecting to:",t),this.connection=new WebSocket(t);const e=setTimeout((()=>{this.connection&&0===this.connection.readyState&&(console.error("[WebSocketManager] Connection timeout"),this.connection.close(),this.connectionState="disconnected",this._updateCircuitBreaker(!1),this.connectionPromise&&(this.connectionPromise.reject(new Error("Connection timeout")),this.connectionPromise=null),this._scheduleReconnect())}),this.config.timeouts.connection);this.connection.addEventListener("open",(t=>{clearTimeout(e),this.handleOpen(t)})),this.connection.addEventListener("message",this.handleMessage),this.connection.addEventListener("close",(t=>{clearTimeout(e),this.handleClose(t)})),this.connection.addEventListener("error",(t=>{clearTimeout(e),this.handleError(t)}))}catch(t){console.error("[WebSocketManager] Connection error:",t),this.connectionState="disconnected",this.connectionPromise&&(this.connectionPromise.reject(t),this.connectionPromise=null),this._scheduleReconnect()}}}handleOpen(t){const e=Date.now()-this.connectionStartTime;this.connectionState="connected",this.reconnectAttempts=0,this.lastMessageReceived=Date.now(),this.metrics.successfulConnections++,this.metrics.lastSuccessfulConnection=Date.now();const n=this.metrics.avgConnectionTime,i=this.metrics.successfulConnections;this.metrics.avgConnectionTime=(n*(i-1)+e)/i,this._updateCircuitBreaker(!0),this.config.debug&&console.log("[WebSocketManager] Connected successfully",{connectionTime:`${e}ms`,avgConnectionTime:`${Math.round(this.metrics.avgConnectionTime)}ms`,attempt:this.metrics.totalReconnects+1}),this.connectionPromise&&(this.connectionPromise.resolve(),this.connectionPromise=null);try{this._startActivityMonitoring(),this._sendAllSubscriptions(),this._processMessageQueue(),this._notifyWidgets("connection",{status:"connected"})}catch(t){console.error("[WebSocketManager] Error in handleOpen:",t)}}handleMessage(t){try{let e;this.lastMessageReceived=Date.now(),this.metrics.messagesReceived++;try{e=JSON.parse(t.data)}catch(n){const i=t.data.toString();if(this.config.debug&&console.log("[WebSocketManager] Received plain text message:",i),i.toLowerCase().includes("session revoked")||i.toLowerCase().includes("please relogin")||i.toLowerCase().includes("session expired")||i.toLowerCase().includes("unauthorized")||i.toLowerCase().includes("authentication failed"))return this.config.debug&&console.log("[WebSocketManager] Session revoked detected, attempting relogin..."),void this._handleSessionRevoked(i);const s=this._getTargetTypeFromErrorMessage(i);e=i.toLowerCase().includes("no night session")||i.toLowerCase().includes("no data")?{type:"error",message:i,error:i,noData:!0,targetType:s}:{type:"error",message:i,error:i,targetType:s}}this.config.debug&&console.log("[WebSocketManager] Processed message:",e),this._routeMessage(e)}catch(t){console.error("[WebSocketManager] Error handling message:",t),this._notifyWidgets("error",{error:"Failed to process message",details:t.message})}}handleClose(t){const e="connected"===this.connectionState;this.connectionState="disconnected",this.activeSubscriptions.clear(),this._stopActivityMonitoring(),this.config.debug&&console.log(`[WebSocketManager] Connection closed: ${t.code} ${t.reason}`),e&&this._notifyWidgets("connection",{status:"disconnected",code:t.code,reason:t.reason}),!this.isManualDisconnect&&this.subscriptions.size>0?(this.metrics.totalReconnects++,this._scheduleReconnect()):this.isManualDisconnect&&(this.config.debug&&console.log("[WebSocketManager] Manual disconnect - skipping reconnection"),this.isManualDisconnect=!1)}handleError(t){const e=this.connection?this.connection.readyState:"no connection";console.error("[WebSocketManager] WebSocket error:",{readyState:e,stateName:{0:"CONNECTING",1:"OPEN",2:"CLOSING",3:"CLOSED"}[e]||"UNKNOWN",url:this.connection?.url,error:t}),this.connection&&(3===this.connection.readyState?(console.log("[WebSocketManager] Connection closed due to error"),this.connectionState="disconnected",!this.isManualDisconnect&&this.subscriptions.size>0?(console.log("[WebSocketManager] Attempting reconnection after error..."),this._scheduleReconnect()):this.isManualDisconnect&&console.log("[WebSocketManager] Manual disconnect - skipping reconnection after error")):2===this.connection.readyState&&console.log("[WebSocketManager] Connection closing...")),this._notifyWidgets("connection",{status:"error",error:"WebSocket connection error",readyState:e,details:"Connection failed or was closed unexpectedly"}),this.connectionPromise&&(this.connectionPromise.reject(new Error("WebSocket connection failed")),this.connectionPromise=null)}_sendAllSubscriptions(){try{const t=new Set;this.subscriptions.forEach((e=>{e&&e.types&&e.types.forEach((e=>t.add(e)))})),this._sendSubscriptions([...t])}catch(t){console.error("[WebSocketManager] Error sending subscriptions:",t)}}_sendSubscriptions(t){t.forEach((t=>{if("queryoptionchain"===t)this._sendOptionChainSubscriptions();else{this._getSymbolsForType(t).forEach((e=>{const n=`${t}:${e}`;if(this.activeSubscriptions.has(n))this.config.debug&&console.log(`[WebSocketManager] Subscription ${n} already active, skipping`);else{let i;i="queryoptionl1"===t?{type:t,optionName:e}:{type:t,symbol:e},this.config.debug&&console.log(`[WebSocketManager] Sending subscription for ${n}`),this.send(i)&&this.activeSubscriptions.add(n)}}))}}))}_sendOptionChainSubscriptions(){this.subscriptions.forEach(((t,e)=>{if(t.types.has("queryoptionchain")&&t.symbol&&t.additionalParams?.date){const e=`queryoptionchain:${t.symbol}:${t.additionalParams.date}`;if(this.activeSubscriptions.has(e))this.config.debug&&console.log(`[WebSocketManager] Option chain subscription ${e} already active, skipping`);else{const n={type:"queryoptionchain",underlying:t.symbol,date:t.additionalParams.date};this.config.debug&&console.log(`[WebSocketManager] Sending option chain subscription for ${e}`),this.send(n)&&this.activeSubscriptions.add(e)}}}))}_getSymbolsForType(t){const e=new Set;return this.subscriptions.forEach(((n,i)=>{n.types.has(t)&&n.symbol&&e.add(n.symbol)})),[...e]}_routeMessage(t){if(Array.isArray(t)&&0===t.length)return void(this.config.debug&&console.log("[WebSocketManager] Received empty array, ignoring"));if(this._cacheMessage(t),t.targetType){const e=this.typeSubscriptions.get(t.targetType);if(e&&e.size>0)return this.config.debug&&console.log(`[WebSocketManager] Routing ${t.targetType} error to specific widgets:`,[...e]),void e.forEach((e=>{const n=this.subscriptions.get(e);if(n)try{n.callback({event:"data",data:t,widgetId:e})}catch(t){console.error(`[WebSocketManager] Error in widget ${e} callback:`,t)}}))}const e=this._getRelevantWidgets(t);if(this.config.debug&&e.size>0&&console.log(`[WebSocketManager] Routing message to ${e.size} relevant widgets`),0===e.size&&this.subscriptions.size>0)return this.config.debug&&console.log("[WebSocketManager] No specific routing found, broadcasting to all widgets"),void this.subscriptions.forEach(((e,n)=>{try{e.callback({event:"data",data:t,widgetId:n})}catch(t){console.error(`[WebSocketManager] Error in widget ${n} callback:`,t)}}));e.forEach((e=>{const n=this.subscriptions.get(e);if(n)try{n.callback({event:"data",data:t,widgetId:e})}catch(t){console.error(`[WebSocketManager] Error in widget ${e} callback:`,t)}}))}_cacheMessage(t){try{const e=this._extractSymbol(t),n=this._extractMessageType(t);if(n&&e){const i=`${n}:${e}`;this.lastMessageCache.set(i,t),this.config.debug&&console.log(`[WebSocketManager] Cached message for ${i}`)}if(Array.isArray(t)&&t.length>0&&t[0].Symbol){const e=t[0].Symbol,n=this._extractMessageType(t);if(n&&e){const i=`${n}:${e}`;this.lastMessageCache.set(i,t),this.config.debug&&console.log(`[WebSocketManager] Cached array message for ${i}`)}}t.Data&&Array.isArray(t.Data)&&t.Data.forEach((e=>{if(e.Symbol){const n=`queryl1:${e.Symbol}`;this.lastMessageCache.set(n,t),this.config.debug&&console.log(`[WebSocketManager] Cached data item for ${n}`)}}))}catch(t){console.error("[WebSocketManager] Error caching message:",t)}}_getRelevantWidgets(t){const e=new Set;return this._addRelevantWidgetsForItem(t,e),e}_addRelevantWidgetsForItem(t,e){t.Data&&Array.isArray(t.Data)?t.Data.forEach((t=>{this._processDataItem(t,e)})):t&&t[0]&&void 0!==t[0].Strike&&t[0].Expire&&!t[0].underlyingSymbol?this._processOptionChainData(t,e):this._processDataItem(t,e)}_processOptionChainData(t,e){if(!t||0===t.length)return;const n=t[0],i=this._extractUnderlyingFromOption(n.Symbol),s=n.Expire;if(this.config.debug&&console.log("[WebSocketManager] Processing option chain data:",{underlyingSymbol:i,expireDate:s,contractCount:t.length}),i){const t=this.symbolSubscriptions.get(i);t&&t.forEach((t=>{const n=this.subscriptions.get(t);if(n&&n.types.has("queryoptionchain")){let o=!0;if(n.additionalParams?.date&&s){o=this._normalizeDate(n.additionalParams.date)===this._normalizeDate(s)}o&&(e.add(t),this.config.debug&&console.log(`[WebSocketManager] Routing option chain data for ${i} (${s}) to widget ${t}`))}}))}}_processDataItem(t,e){const n=this._extractSymbol(t),i=this._extractMessageType(t);if(this.config.debug&&console.log("[WebSocketManager] Processing data item:",{symbol:n,messageType:i,dataItem:t}),n){const t=this.symbolSubscriptions.get(n);t&&t.forEach((t=>{const s=this.subscriptions.get(t);if(s){this._isDataTypeCompatible(i,s.types)&&(e.add(t),this.config.debug&&console.log(`[WebSocketManager] Routing ${i} data for ${n} to widget ${t}`))}}))}if(i){const t=this.typeSubscriptions.get(i);t&&t.forEach((t=>{const s=this.subscriptions.get(t);!s||s.symbol&&s.symbol!==n||(e.add(t),this.config.debug&&console.log(`[WebSocketManager] Routing ${i} data to type-subscribed widget ${t}`))}))}}_isDataTypeCompatible(t,e){if(e.has(t))return!0;const n={queryoptionchain:["queryoptionchain","optionchain","option-chain"],queryl1:["queryl1","stock","equity"],queryoptionl1:["queryoptionl1","option","options"],queryblueoceanl1:["queryblueoceanl1","blueoceanl1","blueocean"],querybrucel1:["querybrucel1","brucel1","bruce"]};for(const i of e){if((n[i]||[i]).includes(t))return!0}return!1}_normalizeDate(t){if(!t)return null;if(t.includes("/")){const[e,n,i]=t.split("/");return`${i}-${e.padStart(2,"0")}-${n.padStart(2,"0")}`}return t}_extractSymbol(t){return Array.isArray(t)&&t[0]&&t[0].Source&&null!==t[0].Symbol&&(t[0].Source.toLowerCase().includes("blueocean")||t[0].Source.toLowerCase().includes("bruce"))&&(t=t[0]),t.Symbol&&!t.Underlying&&t.Strike?this._extractUnderlyingFromOption(t.Symbol):t.Symbol||t.RootSymbol||t.Underlying||t.symbol||t.rootSymbol||t.underlying}_isOptionSymbol(t){return/^[A-Z]+\d{6}[CP]\d+$/.test(t)}_extractUnderlyingFromOption(t){const e=t.match(/^([A-Z]+)\d{6}[CP]\d+$/),n=e?e[1]:t;return{SPXW:"SPX$",SPX:"SPX$",NDXP:"NDX$",RUT:"RUT$",VIX:"VIX$",DJX:"DJX$"}[n]||n}_extractMessageType(t){return t.type?t.type:t[0]&&t[0].Source&&(t[0].Source.toLowerCase().includes("blueocean")||t[0].Source.toLowerCase().includes("blueocean-d")||t[0].Source.toLowerCase().includes("bruce"))?t[0].Source.toLowerCase().includes("bruce")?"querybrucel1":"queryblueoceanl1":void 0!==t.Strike||void 0!==t.Expire||t.Symbol&&this._isOptionSymbol(t.Symbol)?"queryoptionl1":void 0!==t.BidPx||void 0!==t.AskPx?"queryl1":null}_notifyWidgets(t,e){try{this.subscriptions.forEach(((n,i)=>{try{n&&n.callback&&n.callback({event:t,data:e,widgetId:i})}catch(t){console.error(`[WebSocketManager] Error notifying widget ${i}:`,t)}}))}catch(t){console.error("[WebSocketManager] Error in _notifyWidgets:",t)}}_processMessageQueue(){if(!this.messageQueue||!Array.isArray(this.messageQueue))return this.config.debug&&console.warn("[WebSocketManager] messageQueue not properly initialized, creating new array"),void(this.messageQueue=[]);for(this.config.debug&&this.messageQueue.length>0&&console.log(`[WebSocketManager] Processing ${this.messageQueue.length} queued messages`);this.messageQueue.length>0;){const t=this.messageQueue.shift();t&&this.send(t)}}_cleanupUnusedSubscriptions(){const t=new Set;this.subscriptions.forEach((e=>{e.types.forEach((e=>t.add(e)))})),this.activeSubscriptions.forEach((e=>{const[n]=e.split(":");t.has(n)||this.activeSubscriptions.delete(e)}))}_scheduleReconnect(){if(!this.isOnline)return this.config.debug&&console.log("[WebSocketManager] Network offline, waiting for network to return..."),void this._notifyWidgets("connection",{status:"offline",reason:"Network offline - will reconnect when network returns"});if("open"===this.circuitBreaker.state){const t=Date.now()-this.circuitBreaker.lastFailureTime,e=this.circuitBreaker.timeout-t;return console.warn(`[WebSocketManager] Circuit breaker OPEN, will retry in ${Math.round(e/1e3)}s`),void this._notifyWidgets("connection",{status:"circuit_open",reason:"Too many connection failures - circuit breaker active",retryIn:Math.round(e/1e3)})}if(this.reconnectAttempts>=this.config.reconnectOptions.maxAttempts)return console.error("[WebSocketManager] Max reconnection attempts reached"),this.metrics.failedConnections++,void this._notifyWidgets("connection",{status:"failed",error:"Max reconnection attempts reached",maxAttempts:this.config.reconnectOptions.maxAttempts,canRetry:!0});this.connectionState="reconnecting",this.reconnectAttempts++;const t=this.config.reconnectOptions.initialDelay*Math.pow(this.config.reconnectOptions.backoff,this.reconnectAttempts-1),e=Math.min(t,this.config.reconnectOptions.maxDelay),n=e*this.config.reconnectOptions.jitter,i=(2*Math.random()-1)*n,s=Math.max(0,e+i);console.log(`[WebSocketManager] Scheduling reconnect attempt ${this.reconnectAttempts}/${this.config.reconnectOptions.maxAttempts} in ${Math.round(s)}ms`),this._notifyWidgets("connection",{status:"reconnecting",attempt:this.reconnectAttempts,maxAttempts:this.config.reconnectOptions.maxAttempts,delay:Math.round(s),estimatedTime:new Date(Date.now()+s).toISOString()}),this.reconnectTimer=setTimeout((()=>{this._connect()}),s)}_resetState(){this.connectionState="disconnected",this.reconnectAttempts=0,this.connectionPromise=null,this.subscriptions&&this.subscriptions instanceof Map||(this.subscriptions=new Map),this.activeSubscriptions&&this.activeSubscriptions instanceof Set||(this.activeSubscriptions=new Set),this.messageQueue&&Array.isArray(this.messageQueue)||(this.messageQueue=[]),this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null)}_getTargetTypeFromErrorMessage(t){const e=t.toLowerCase();return e.includes("night session")||e.includes("blue ocean")||e.includes("bruce")||e.includes("blueocean")?e[0].toLowerCase().includes("bruce")?"querybrucel1":"queryblueoceanl1":e.includes("option chain")||e.includes("expiration date")?"queryoptionchain":e.includes("option")||e.includes("strike")||e.includes("expiration")?"queryoptionl1":e.includes("stock")||e.includes("equity")||e.includes("bid")||e.includes("ask")?"queryl1":null}async _handleSessionRevoked(t){if(this.isReloginInProgress)this.config.debug&&console.log("[WebSocketManager] Relogin already in progress, skipping...");else{this.isReloginInProgress=!0;try{if(this._notifyWidgets("session_revoked",{message:t,status:"attempting_relogin"}),this.config.debug&&console.log("[WebSocketManager] Session revoked, attempting relogin..."),this._closeConnection(),!this.reloginCallback||"function"!=typeof this.reloginCallback)throw new Error("No relogin callback provided");{const t=await this.reloginCallback();if(!(t&&"string"==typeof t&&t.length>0))throw new Error("Relogin failed: Invalid token received");this.updateToken(t),this.config.debug&&console.log("[WebSocketManager] Relogin successful, reconnecting..."),await this._reconnectAndResubscribe()}}catch(e){console.error("[WebSocketManager] Relogin failed:",e),this._notifyWidgets("session_revoked",{message:t,status:"relogin_failed",error:e.message}),this.connectionState="failed"}finally{this.isReloginInProgress=!1}}}async _reconnectAndResubscribe(){try{this.connectionState="disconnected",this.reconnectAttempts=0,this.activeSubscriptions.clear(),await this.connect(),this.config.debug&&console.log("[WebSocketManager] Reconnected successfully after relogin"),this._notifyWidgets("session_revoked",{status:"relogin_successful"})}catch(t){throw console.error("[WebSocketManager] Failed to reconnect after relogin:",t),t}}_closeConnection(){this.connection&&(this.connection.removeEventListener("open",this.handleOpen),this.connection.removeEventListener("message",this.handleMessage),this.connection.removeEventListener("close",this.handleClose),this.connection.removeEventListener("error",this.handleError),this.connection.readyState===WebSocket.OPEN&&this.connection.close(),this.connection=null),this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.connectionState="disconnected"}setReloginCallback(t){this.reloginCallback=t,this.config.debug&&console.log("[WebSocketManager] Relogin callback set")}updateToken(t){this.config.token=t,this.apiService=new Iu(this.config.token,this.config.apiBaseUrl),this.config.debug&&console.log("[WebSocketManager] Token updated")}getApiService(){return this.apiService}async manualReconnect(){this.config.debug&&console.log("[WebSocketManager] Manual reconnect initiated"),this.reconnectAttempts=0,this.connectionState="disconnected",this.isManualDisconnect=!1,this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this._notifyWidgets("connection",{status:"reconnecting",attempt:1,maxAttempts:this.config.reconnectOptions.maxAttempts,manual:!0});try{return await this.connect(),!0}catch(t){return console.error("[WebSocketManager] Manual reconnect failed:",t),!1}}_initNetworkMonitoring(){"undefined"!=typeof window&&(this.onlineHandler=()=>{this.isOnline=!0,this.config.debug&&console.log("[WebSocketManager] Network online detected"),"disconnected"===this.connectionState&&this.subscriptions.size>0&&(console.log("[WebSocketManager] Network restored, attempting reconnection..."),this.reconnectAttempts=0,this._scheduleReconnect())},this.offlineHandler=()=>{this.isOnline=!1,this.config.debug&&console.log("[WebSocketManager] Network offline detected"),this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this._notifyWidgets("connection",{status:"offline",reason:"Network offline"})},window.addEventListener("online",this.onlineHandler),window.addEventListener("offline",this.offlineHandler))}_cleanupNetworkMonitoring(){"undefined"!=typeof window&&(this.onlineHandler&&(window.removeEventListener("online",this.onlineHandler),this.onlineHandler=null),this.offlineHandler&&(window.removeEventListener("offline",this.offlineHandler),this.offlineHandler=null))}_startActivityMonitoring(){this.config.enableActivityMonitoring?(this._stopActivityMonitoring(),this.activityCheckInterval=setInterval((()=>{if("connected"!==this.connectionState)return;const t=Date.now()-this.lastMessageReceived;t>this.config.timeouts.inactivity?(console.warn(`[WebSocketManager] No messages received in ${this.config.timeouts.inactivity}ms, connection may be dead`),this.connection&&this.connection.close()):this.config.debug&&t>3e4&&console.log(`[WebSocketManager] Last message: ${Math.round(t/1e3)}s ago`)}),15e3)):this.config.debug&&console.log("[WebSocketManager] Activity monitoring disabled")}_stopActivityMonitoring(){this.activityCheckInterval&&(clearInterval(this.activityCheckInterval),this.activityCheckInterval=null)}_updateCircuitBreaker(t){t?(this.circuitBreaker.failureCount=0,this.circuitBreaker.state="closed",this.circuitBreaker.resetTimer&&(clearTimeout(this.circuitBreaker.resetTimer),this.circuitBreaker.resetTimer=null),this.config.debug&&console.log("[WebSocketManager] Circuit breaker CLOSED - connection healthy")):(this.circuitBreaker.failureCount++,this.circuitBreaker.lastFailureTime=Date.now(),this.config.debug&&console.log(`[WebSocketManager] Circuit breaker failure ${this.circuitBreaker.failureCount}/${this.circuitBreaker.failureThreshold}`),this.circuitBreaker.failureCount>=this.circuitBreaker.failureThreshold&&(this.circuitBreaker.state="open",console.warn("[WebSocketManager] Circuit breaker OPEN - too many failures"),this.circuitBreaker.resetTimer=setTimeout((()=>{this.circuitBreaker.state="half-open",this.circuitBreaker.failureCount=0,console.log("[WebSocketManager] Circuit breaker HALF-OPEN - will attempt one reconnection"),this.subscriptions.size>0&&"connected"!==this.connectionState&&(this.reconnectAttempts=0,this._scheduleReconnect())}),this.circuitBreaker.timeout)))}getConnectionMetrics(){const t=this._calculateConnectionQuality();return{state:this.connectionState,quality:t,isOnline:this.isOnline,circuitBreakerState:this.circuitBreaker.state,reconnectAttempts:this.reconnectAttempts,maxReconnectAttempts:this.config.reconnectOptions.maxAttempts,successfulConnections:this.metrics.successfulConnections,failedConnections:this.metrics.failedConnections,totalReconnects:this.metrics.totalReconnects,avgConnectionTime:Math.round(this.metrics.avgConnectionTime),lastSuccessfulConnection:this.metrics.lastSuccessfulConnection?new Date(this.metrics.lastSuccessfulConnection).toISOString():null,messagesReceived:this.metrics.messagesReceived,messagesSent:this.metrics.messagesSent,activeSubscriptions:this.subscriptions.size,lastMessageReceived:this.lastMessageReceived?`${Math.round((Date.now()-this.lastMessageReceived)/1e3)}s ago`:"never"}}_calculateConnectionQuality(){if("connected"!==this.connectionState)return"poor";const t=this.lastMessageReceived?Date.now()-this.lastMessageReceived:1/0;return t<3e4&&this.metrics.avgConnectionTime<2e3?"excellent":t<6e4&&this.metrics.avgConnectionTime<5e3?"good":t<this.config.timeouts.inactivity?"fair":"poor"}enableMetricsLogging(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:3e4;this.metricsInterval&&clearInterval(this.metricsInterval),this.metricsInterval=setInterval((()=>{console.log("[WebSocketManager] Metrics:",this.getConnectionMetrics())}),t),console.log("[WebSocketManager] Metrics logging enabled (every "+t/1e3+"s)")}disableMetricsLogging(){this.metricsInterval&&(clearInterval(this.metricsInterval),this.metricsInterval=null,console.log("[WebSocketManager] Metrics logging disabled"))}disconnect(){this.isManualDisconnect=!0,this._stopActivityMonitoring(),this._cleanupNetworkMonitoring(),this.circuitBreaker.resetTimer&&(clearTimeout(this.circuitBreaker.resetTimer),this.circuitBreaker.resetTimer=null),this.disableMetricsLogging(),this._closeConnection(),this._notifyWidgets("connection",{status:"disconnected",manual:!0}),this.config.debug&&console.log("[WebSocketManager] Disconnected and cleaned up")}}class zu{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.config={apiBaseUrl:t.apiBaseUrl||"https://mdas-api-dev.viewtrade.dev",loginEndpoint:t.loginEndpoint||"/api/user/login",refreshEndpoint:t.refreshEndpoint||"/api/user/refresh",refreshBuffer:t.refreshBuffer||300,maxRetries:t.maxRetries||3,debug:t.debug||!1},this.credentials=null,this.currentToken=null,this.tokenExpiry=null,this.refreshTimer=null,this.isAuthenticating=!1,this.retryCount=0,this.authenticationPromise=null,this.listeners=new Map,this.config.debug&&console.log("[AuthManager] Initialized with config:",{...this.config,loginEndpoint:this.config.loginEndpoint})}setCredentials(t,e){this.credentials={user_name:t,password:e},this.config.debug&&console.log("[AuthManager] Credentials set for user:",t)}async authenticate(){if(this.isAuthenticating&&this.authenticationPromise)return this.config.debug&&console.log("[AuthManager] Authentication already in progress, waiting..."),await this.authenticationPromise;if(!this.credentials)throw new Error("No credentials provided. Call setCredentials() first.");this.isAuthenticating=!0,this.authenticationPromise=this._performAuthentication();try{return await this.authenticationPromise}finally{this.isAuthenticating=!1,this.authenticationPromise=null}}async getValidToken(){return this.currentToken?this._isTokenNearExpiry()?(this.config.debug&&console.log("[AuthManager] Token near expiry, refreshing..."),await this.refreshToken()):this.currentToken:await this.authenticate()}async refreshToken(){if(this.isAuthenticating)return this.currentToken;this.isAuthenticating=!0;try{const t=await this._performRefresh();return this._handleAuthSuccess(t),this.currentToken}catch(t){return this.config.debug&&console.log("[AuthManager] Token refresh failed, attempting re-login"),await this.authenticate()}finally{this.isAuthenticating=!1}}async handleAuthError(t){if(this.config.debug&&console.log("[AuthManager] Handling auth error:",t),this.retryCount>=this.config.maxRetries){const t=new Error(`Authentication failed after ${this.config.maxRetries} attempts`);throw this._notifyListeners("auth_failed",{error:t}),this.retryCount=0,t}this.retryCount++,this._clearToken();try{const t=await this.authenticate();return this.retryCount=0,this._notifyListeners("auth_recovered",{token:t}),t}catch(t){throw this._notifyListeners("auth_retry_failed",{error:t,attempt:this.retryCount}),t}}addEventListener(t,e){this.listeners.has(t)||this.listeners.set(t,new Set),this.listeners.get(t).add(e)}removeEventListener(t,e){this.listeners.has(t)&&this.listeners.get(t).delete(e)}destroy(){this._clearToken(),this.credentials=null,this.listeners.clear(),this.config.debug&&console.log("[AuthManager] Destroyed")}async _performLogin(){const t=`${this.config.apiBaseUrl}${this.config.loginEndpoint}`;this.config.debug&&console.log("[AuthManager] Attempting login to:",t);const e=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({user_name:this.credentials.user_name,password:this.credentials.password})});if(!e.ok){const t=await e.json().catch((()=>({})));throw new Error(t.message||`Login failed: ${e.status} ${e.statusText}`)}const n=await e.json(),i=n.access_token,s=n.refresh_token,o=n.access_expiration,a=n.user_id;if(!i)throw console.error("[AuthManager] Login response missing token:",n),new Error("No token received from login response");let r=null;if(o)try{if(r=new Date(o),isNaN(r.getTime()))throw new Error("Invalid expiration date format")}catch(t){console.warn("[AuthManager] Could not parse expiration date:",n.expiration),r=new Date(Date.now()+36e5)}else r=new Date(Date.now()+18e6);return this.config.debug&&console.log("[AuthManager] Login successful:",{tokenLength:i.length,expiresAt:r.toISOString(),timeUntilExpiry:Math.round((r.getTime()-Date.now())/1e3/60)+" minutes"}),{token:i,refreshToken:s,expirationDate:r,user_id:a}}async _performRefresh(){return this.config.debug&&console.log("[AuthManager] No refresh endpoint available, performing full re-authentication"),await this._performLogin()}async _performAuthentication(){try{const t=await this._performLogin();return this._handleAuthSuccess(t),this.currentToken}catch(t){throw this._handleAuthError(t),t}}_handleAuthSuccess(t){this.currentToken=t.token,t.expirationDate&&(this.tokenExpiry=t.expirationDate),this.retryCount=0,this._scheduleTokenRefresh(),this.config.debug&&console.log("[AuthManager] Authentication successful, token expires:",this.tokenExpiry),this._notifyListeners("auth_success",{token:this.currentToken,expiresAt:this.tokenExpiry})}_handleAuthError(t){this.config.debug&&console.error("[AuthManager] Authentication failed:",t.message),this._notifyListeners("auth_error",{error:t})}_isTokenNearExpiry(){if(!this.tokenExpiry)return!0;const t=new Date,e=1e3*this.config.refreshBuffer;return t>=new Date(this.tokenExpiry.getTime()-e)}_scheduleTokenRefresh(){if(this.refreshTimer&&clearTimeout(this.refreshTimer),!this.tokenExpiry)return;const t=new Date,e=1e3*this.config.refreshBuffer,n=new Date(this.tokenExpiry.getTime()-e),i=Math.max(0,n.getTime()-t.getTime());this.config.debug&&console.log(`[AuthManager] Scheduling token refresh in ${i/1e3} seconds`),this.refreshTimer=setTimeout((async()=>{try{await this.refreshToken()}catch(t){console.error("[AuthManager] Scheduled refresh failed:",t)}}),i)}_clearToken(){this.currentToken=null,this.tokenExpiry=null,this.refreshTimer&&(clearTimeout(this.refreshTimer),this.refreshTimer=null)}_notifyListeners(t,e){this.listeners.has(t)&&this.listeners.get(t).forEach((n=>{try{n(e)}catch(e){console.error(`[AuthManager] Error in ${t} listener:`,e)}}))}}class Wu{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.config={username:t.username,password:t.password,token:t.token,authCallback:t.authCallback,wsUrl:t.wsUrl||"https://mdas-api-dev.viewtrade.dev/wss/sub",apiBaseUrl:t.apiBaseUrl||"https://mdas-api-dev.viewtrade.dev",debug:t.debug||!1,maxConnections:t.maxConnections||1,autoAuth:!1!==t.autoAuth,...t},this.stateManager=new e,this.widgetManager=new Lu(this.stateManager),this.wsManager=null,this.authManager=null,this.isInitialized=!1,this._validateAuthConfig()}async initialize(){try{return this.isInitialized?(console.warn("SDK already initialized"),this):(this.config.debug&&console.log("Initializing MDAS SDK with config:",{hasCredentials:!(!this.config.username||!this.config.password),hasToken:!!this.config.token,hasAuthCallback:!!this.config.authCallback,wsUrl:this.config.wsUrl,autoAuth:this.config.autoAuth}),this.config.username&&this.config.password&&await this._initializeBuiltInAuth(),this.isInitialized=!0,this)}catch(t){throw console.error("Failed to initialize SDK:",t),t}}async createWidget(t,e){let n,i,s,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!this.isInitialized)throw new Error("SDK not initialized. Call initialize() first.");if(this.wsManager||await this._initializeWebSocketManager(),"object"!=typeof t||null===t||Array.isArray(t))n=t,i=e,s=o||{};else if(n=t.type,s=t.options||{},t.containerEl&&1===t.containerEl.nodeType)i=t.containerEl;else if(t.containerId){const e=String(t.containerId).replace(/^#/,"");let n="undefined"!=typeof document?document.getElementById(e):null;n||"undefined"==typeof document||(n=document.createElement("div"),n.id=e,document.body.appendChild(n)),i=n}else{const t="mdas-widget";let e="undefined"!=typeof document?document.getElementById(t):null;e||"undefined"==typeof document||(e=document.createElement("div"),e.id=t,document.body.appendChild(e)),i=e}const a={...s,wsManager:this.wsManager,debug:this.config.debug};return a.reconnect=async()=>await this.manualReconnect(),this.widgetManager.createWidget(n,i,a)}async login(t,e){this.authManager||(this.authManager=new zu({apiBaseUrl:this.config.apiBaseUrl,debug:this.config.debug})),this.authManager.setCredentials(t,e);const n=await this.authManager.authenticate();return this.wsManager&&await this._reconnectWithNewToken(n),n}async destroy(){this.authManager&&(this.authManager.destroy(),this.authManager=null),this.wsManager&&(this.wsManager.disconnect(),this.wsManager=null),this.widgetManager&&this.widgetManager.destroy(),this.isInitialized=!1}getConnectionState(){return this.wsManager?this.wsManager.getConnectionState():"disconnected"}getActiveWidgetCount(){return this.widgetManager?this.widgetManager.getWidgetCount():0}getSubscriptionCount(){return this.wsManager?this.wsManager.getSubscriptionCount():0}isAuthenticated(){return this.authManager?!!this.authManager.currentToken:!!this.config.token}disconnect(){this.wsManager&&(this.wsManager.disconnect(),this.config.debug&&console.log("[MdasSDK] WebSocket disconnected"))}async connect(){if(this.wsManager)try{await this.wsManager.connect(),this.config.debug&&console.log("[MdasSDK] WebSocket reconnected")}catch(t){throw console.error("[MdasSDK] Failed to reconnect:",t),t}else this.config.debug&&console.log("[MdasSDK] No WebSocketManager exists, initializing..."),await this._initializeWebSocketManager()}isConnected(){return!!this.wsManager&&"connected"===this.wsManager.getConnectionState()}async manualReconnect(){return!!this.wsManager&&(this.config.debug&&console.log("[MdasSDK] Manual reconnect requested"),await this.wsManager.manualReconnect())}_validateAuthConfig(){const t=this.config.username&&this.config.password,e=this.config.token,n=this.config.authCallback;if(!t&&!e&&!n)throw new Error("Authentication required: Provide username/password, token, or authCallback");[t,e,n].filter(Boolean).length>1&&console.warn("Multiple auth methods provided. Priority: credentials > token > authCallback")}async _initializeBuiltInAuth(){this.authManager=new zu({apiBaseUrl:this.config.apiBaseUrl,debug:this.config.debug}),this.authManager.setCredentials(this.config.username,this.config.password),this.authManager.addEventListener("auth_error",(t=>{console.error("Authentication error:",t.error)})),this.authManager.addEventListener("auth_success",(t=>{this.config.debug&&console.log("Authentication successful")})),this.authManager.addEventListener("auth_failed",(t=>{console.error("Authentication failed after retries:",t.error)})),this.config.autoAuth&&await this.authManager.authenticate()}async _initializeWebSocketManager(){const t=await this._getToken();this.wsManager=new Ou({debug:this.config.debug,token:t,baseUrl:this.config.wsUrl,apiBaseUrl:this.config.apiBaseUrl,maxConnections:this.config.maxConnections,reconnectOptions:{maxAttempts:5,delay:1e3,backoff:2},reloginCallback:async()=>{try{if(this.authManager){this.config.debug&&console.log("[MdasSDK] Attempting relogin after session revoked...");const t=await this.authManager.authenticate();return this.config.debug&&console.log("[MdasSDK] Relogin successful, new token obtained"),t}return this.config.authCallback?await this.config.authCallback():(console.error("[MdasSDK] No authentication method available for relogin"),null)}catch(t){return console.error("[MdasSDK] Relogin failed:",t),null}}}),this.wsManager.addEventListener=this.wsManager.addEventListener||(()=>{});try{await this.wsManager.connect(),this.config.debug&&console.log("WebSocketManager connected successfully")}catch(t){t.message.includes("401")||t.message.includes("403")?await this._handleWebSocketAuthError(t):console.error("Failed to connect WebSocketManager:",t)}}async _getToken(){if(this.authManager)return await this.authManager.getValidToken();if(this.config.authCallback){const t=await this.config.authCallback();return t.token||t}return this.config.token}async _handleWebSocketAuthError(t){if(!this.authManager)throw t;try{const e=await this.authManager.handleAuthError(t);await this._reconnectWithNewToken(e)}catch(t){throw console.error("Failed to recover from auth error:",t),t}}async _reconnectWithNewToken(t){this.wsManager&&(this.wsManager.updateToken(t),this.wsManager.disconnect(),await this.wsManager.connect())}}"undefined"!=typeof window&&(window.MdasSDK=Wu,window.MdasSDK.MdasSDK=Wu,window.MdasSDK.MarketDataModel=i,window.MdasSDK.NightSessionModel=y,window.MdasSDK.OptionsModel=v,window.MdasSDK.IntradayChartModel=D,window.MdasSDK.CombinedMarketWidget=T,window.MdasSDK.IntradayChartWidget=Au),t.CombinedMarketWidget=T,t.IntradayChartModel=D,t.IntradayChartWidget=Au,t.MarketDataModel=i,t.MdasSDK=Wu,t.NightSessionModel=y,t.OptionChainWidget=M,t.OptionsModel=v,t.default=Wu,Object.defineProperty(t,"__esModule",{value:!0})}));//# sourceMappingURL=mdas-sdk.min.js.map
|
|
55
|
+
*/function Mu(t,e,n,i){const s=null===e,o=null===n,a=!(!t||s&&o)&&function(t,e){const{x:n,y:i,base:s,width:o,height:a}=t.getProps(["x","low","high","width","height"],e);let r,c,l,d,h;return t.horizontal?(h=a/2,r=Math.min(n,s),c=Math.max(n,s),l=i-h,d=i+h):(h=o/2,r=n-h,c=n+h,l=Math.min(i,s),d=Math.max(i,s)),{left:r,top:l,right:c,bottom:d}}(t,i);return a&&(s||e>=a.left&&e<=a.right)&&(o||n>=a.top&&n<=a.bottom)}class Cu extends Mo{static defaults={backgroundColors:{up:"rgba(75, 192, 192, 0.5)",down:"rgba(255, 99, 132, 0.5)",unchanged:"rgba(201, 203, 207, 0.5)"},borderColors:{up:"rgb(75, 192, 192)",down:"rgb(255, 99, 132)",unchanged:"rgb(201, 203, 207)"}};height(){return this.base-this.y}inRange(t,e,n){return Mu(this,t,e,n)}inXRange(t,e){return Mu(this,t,null,e)}inYRange(t,e){return Mu(this,null,t,e)}getRange(t){return"x"===t?this.width/2:this.height/2}getCenterPoint(t){const{x:e,low:n,high:i}=this.getProps(["x","low","high"],t);return{x:e,y:(i+n)/2}}tooltipPosition(t){const{x:e,open:n,close:i}=this.getProps(["x","open","close"],t);return{x:e,y:(n+i)/2}}}const _u=eo.defaults;class Du extends Cu{static id="ohlc";static defaults={...Cu.defaults,lineWidth:2,armLength:null,armLengthRatio:.8};draw(t){const e=this,{x:n,open:i,high:s,low:o,close:a}=e,r=mt(e.armLengthRatio,_u.elements.ohlc.armLengthRatio);let c=mt(e.armLength,_u.elements.ohlc.armLength);null===c&&(c=e.width*r*.5),t.strokeStyle=a<i?mt(e.options.borderColors?e.options.borderColors.up:void 0,_u.elements.ohlc.borderColors.up):a>i?mt(e.options.borderColors?e.options.borderColors.down:void 0,_u.elements.ohlc.borderColors.down):mt(e.options.borderColors?e.options.borderColors.unchanged:void 0,_u.elements.ohlc.borderColors.unchanged),t.lineWidth=mt(e.lineWidth,_u.elements.ohlc.lineWidth),t.beginPath(),t.moveTo(n,s),t.lineTo(n,o),t.moveTo(n-c,i),t.lineTo(n,i),t.moveTo(n+c,a),t.lineTo(n,a),t.stroke()}}class Tu extends Ci{static overrides={label:"",parsing:!1,hover:{mode:"label"},animations:{numbers:{type:"number",properties:["x","y","base","width","open","high","low","close"]}},scales:{x:{type:"timeseries",offset:!0,ticks:{major:{enabled:!0},source:"data",maxRotation:0,autoSkip:!0,autoSkipPadding:75,sampleSize:100}},y:{type:"linear"}},plugins:{tooltip:{intersect:!1,mode:"index",callbacks:{label(t){const e=t.parsed;if(!dt(e.y))return Le.plugins.tooltip.callbacks.label(t);const{o:n,h:i,l:s,c:o}=e;return`O: ${n} H: ${i} L: ${s} C: ${o}`}}}}};getLabelAndValue(t){const e=this,n=e.getParsed(t),i=e._cachedMeta.iScale.axis,{o:s,h:o,l:a,c:r}=n,c=`O: ${s} H: ${o} L: ${a} C: ${r}`;return{label:`${e._cachedMeta.iScale.getLabelForValue(n[i])}`,value:c}}getUserBounds(t){const{min:e,max:n,minDefined:i,maxDefined:s}=t.getUserBounds();return{min:i?e:Number.NEGATIVE_INFINITY,max:s?n:Number.POSITIVE_INFINITY}}getMinMax(t){const e=this._cachedMeta,n=e._parsed,i=e.iScale.axis,s=this._getOtherScale(t),{min:o,max:a}=this.getUserBounds(s);if(n.length<2)return{min:0,max:1};if(t===e.iScale)return{min:n[0][i],max:n[n.length-1][i]};const r=n.filter((({x:t})=>t>=o&&t<a));let c=Number.POSITIVE_INFINITY,l=Number.NEGATIVE_INFINITY;for(let t=0;t<r.length;t++){const e=r[t];c=Math.min(c,e.l),l=Math.max(l,e.h)}return{min:c,max:l}}calculateElementProperties(t,e,n,i){const s=this,o=s._cachedMeta.vScale,a=o.getBasePixel(),r=s._calculateBarIndexPixels(t,e,i),c=s.chart.data.datasets[s.index].data[t],l=o.getPixelForValue(c.o),d=o.getPixelForValue(c.h),h=o.getPixelForValue(c.l),u=o.getPixelForValue(c.c);return{base:n?a:h,x:r.center,y:(h+d)/2,width:r.size,open:l,high:d,low:h,close:u}}draw(){const t=this,e=t.chart,n=t._cachedMeta.data;Fe(e.ctx,e.chartArea);for(let e=0;e<n.length;++e)n[e].draw(t._ctx);qe(e.ctx)}}class Pu extends Cu{static id="candlestick";static defaults={...Cu.defaults,borderWidth:1};draw(t){const e=this,{x:n,open:i,high:s,low:o,close:a}=e;let r,c=e.options.borderColors;"string"==typeof c&&(c={up:c,down:c,unchanged:c}),a<i?(r=mt(c?c.up:void 0,Le.elements.candlestick.borderColors.up),t.fillStyle=mt(e.options.backgroundColors?e.options.backgroundColors.up:void 0,Le.elements.candlestick.backgroundColors.up)):a>i?(r=mt(c?c.down:void 0,Le.elements.candlestick.borderColors.down),t.fillStyle=mt(e.options.backgroundColors?e.options.backgroundColors.down:void 0,Le.elements.candlestick.backgroundColors.down)):(r=mt(c?c.unchanged:void 0,Le.elements.candlestick.borderColors.unchanged),t.fillStyle=mt(e.backgroundColors?e.backgroundColors.unchanged:void 0,Le.elements.candlestick.backgroundColors.unchanged)),t.lineWidth=mt(e.options.borderWidth,Le.elements.candlestick.borderWidth),t.strokeStyle=r,t.beginPath(),t.moveTo(n,s),t.lineTo(n,Math.min(i,a)),t.moveTo(n,o),t.lineTo(n,Math.max(i,a)),t.stroke(),t.fillRect(n-e.width/2,a,e.width,i-a),t.strokeRect(n-e.width/2,a,e.width,i-a),t.closePath()}}class Eu extends Tu{static id="candlestick";static defaults={...Tu.defaults,dataElementType:Pu.id};static defaultRoutes=Ci.defaultRoutes;updateElements(t,e,n,i){const s="reset"===i,o=this._getRuler(),{sharedOptions:a,includeOptions:r}=this._getSharedOptions(e,i);for(let c=e;c<e+n;c++){const e=a||this.resolveDataElementOptions(c,i),n=this.calculateElementProperties(c,o,s,e);r&&(n.options=e),this.updateElement(t[c],c,n,i)}}}eo.register(...er,yh,ku,Eu,Pu);class Au extends n{constructor(t,e,n){if(super(t,e,n),!e.symbol)throw new Error("Symbol is required for IntradayChartWidget");if(!e.wsManager)throw new Error("WebSocketManager is required for IntradayChartWidget");const i=g(e.symbol);if(!i.valid)throw new Error(`Invalid symbol: ${i.error}`);this.type="intraday-chart",this.wsManager=e.wsManager,this.symbol=i.sanitized,this.debug=e.debug||!1,this.source=e.source||"blueocean",this.rangeBack=e.rangeBack||0,this.chartType=e.chartType||"line",this.autoRefresh=void 0===e.autoRefresh||e.autoRefresh,this.refreshInterval=e.refreshInterval||6e4,this.refreshTimer=null,this.isUserInteracting=!1,this.marketIsOpen=null,this.marketStatusChecked=!1,this.chartData=null,this.chartInstance=null,this.unsubscribe=null,this.livePrice=null,this.companyName="",this.exchangeName="",this.mic="",this.symbolEditor=null,this.cached5DData=null,this.is5DDataLoading=!1,this.createWidgetStructure(),this.setupSymbolEditor(),this.initialize()}createWidgetStructure(){this.container.innerHTML='\n <div class="intraday-chart-widget">\n <div class="chart-header">\n <div class="chart-title-section">\n <div class="company-market-info">\n <span class="intraday-company-name"></span>\n </div>\n <h3 class="intraday-chart-symbol editable-symbol"\n title="Double-click to edit symbol"\n data-original-symbol="">AAPL</h3>\n </div>\n <div class="chart-change positive">+0.00 (+0.00%)</div>\n </div>\n\n <div class="chart-controls">\n <div class="chart-range-selector">\n <button class="range-btn active" data-range="0">1D</button>\n <button class="range-btn" data-range="5">5D</button>\n </div>\n <div class="chart-type-selector">\n <button class="type-btn active" data-type="line" title="Line Chart">Line</button>\n <button class="type-btn" data-type="area" title="Area Chart">Mountain</button>\n <button class="type-btn" data-type="candlestick" title="Candlestick Chart">Candles</button>\n </div>\n <button class="zoom-reset-btn" title="Reset Zoom">\n <svg width="16" height="16" viewBox="0 0 16 16" fill="none">\n <path d="M2 8a6 6 0 1 1 12 0A6 6 0 0 1 2 8zm6-7a7 7 0 1 0 0 14A7 7 0 0 0 8 1z" fill="currentColor"/>\n <path d="M5 8h6M8 5v6" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>\n </svg>\n Reset Zoom\n </button>\n </div>\n\n <div class="chart-container">\n <canvas id="intradayChart"></canvas>\n </div>\n\n <div class="chart-stats">\n <div class="stat-item stat-open">\n <span class="stat-label">Open</span>\n <span class="stat-value">$0.00</span>\n </div>\n <div class="stat-item stat-high">\n <span class="stat-label">High</span>\n <span class="stat-value">$0.00</span>\n </div>\n <div class="stat-item stat-low">\n <span class="stat-label">Low</span>\n <span class="stat-value">$0.00</span>\n </div>\n <div class="stat-item stat-close">\n <span class="stat-label">Close</span>\n <span class="stat-value">$0.00</span>\n </div>\n <div class="stat-item stat-volume">\n <span class="stat-label">Volume</span>\n <span class="stat-value">0</span>\n </div>\n </div>\n\n <div class="widget-loading-overlay hidden">\n <div class="loading-spinner"></div>\n <div class="loading-text">Loading chart data...</div>\n </div>\n </div>\n';const t=this.container.querySelector(".intraday-chart-symbol");t&&(t.textContent=this.symbol),this.setupRangeButtons(),this.setupChartTypeButtons(),this.addStyles()}setupSymbolEditor(){this.symbolEditor=new s(this,{maxLength:10,placeholder:"Enter symbol...",onSymbolChange:this.handleSymbolChange.bind(this),debug:this.debug,autoUppercase:!0,symbolType:"nightsession"});const t=this.container.querySelector(".intraday-chart-symbol");t&&(t.textContent=this.symbol,t.dataset.originalSymbol=this.symbol)}async handleSymbolChange(t,e){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;this.debug&&(console.log("[IntradayChartWidget] Symbol change requested:",t),console.log("[IntradayChartWidget] Validation data:",n));const i=g(t);if(!i.valid)return this.debug&&console.log("[IntradayChartWidget] Invalid symbol:",i.error),{success:!1,error:i.error};const s=i.sanitized;if(n&&(this.companyName=n.comp_name||"",this.exchangeName=n.market_name||"",this.mic=n.mic||"",this.debug&&console.log("[IntradayChartWidget] Extracted company info:",{companyName:this.companyName,exchangeName:this.exchangeName})),s===this.symbol)return this.debug&&console.log("[IntradayChartWidget] Same symbol, no change needed"),{success:!0};try{return this.showLoading(),this.stopAutoRefresh(),this.unsubscribe&&(this.debug&&console.log(`[IntradayChartWidget] Unsubscribing from ${e}`),this.unsubscribe(),this.unsubscribe=null),this.chartInstance&&(this.debug&&console.log("[IntradayChartWidget] Clearing chart for symbol change"),this.chartInstance.destroy(),this.chartInstance=null),this.chartData=null,this.livePrice=null,this.cached5DData=null,this.is5DDataLoading=!1,this.symbol=s,this.updateCompanyName(),await this.loadChartData(),this.debug&&console.log(`[IntradayChartWidget] Successfully changed symbol from ${e} to ${s}`),{success:!0}}catch(t){return console.error("[IntradayChartWidget] Error changing symbol:",t),this.showError(`Failed to load data for ${s}`),{success:!1,error:`Failed to load ${s}`}}}async initialize(){await this.validateInitialSymbol(),this.updateCompanyName(),await this.loadChartData()}async validateInitialSymbol(){try{const t=this.wsManager.getApiService();if(!t)return void(this.debug&&console.log("[IntradayChartWidget] API service not available for initial validation"));const e=await t.quotel1(this.symbol);if(e&&e.data&&e.data[0]){const t=e.data[0];this.companyName=t.comp_name||"",this.exchangeName=t.market_name||"",this.mic=t.mic||"",this.debug&&console.log("[IntradayChartWidget] Initial symbol validated:",{symbol:this.symbol,companyName:this.companyName,exchangeName:this.exchangeName,mic:this.mic})}}catch(t){this.debug&&console.warn("[IntradayChartWidget] Initial symbol validation failed:",t)}}updateCompanyName(){const t=this.container.querySelector(".intraday-company-name");t&&(t.textContent=this.companyName||"")}setupRangeButtons(){const t=this.container.querySelectorAll(".range-btn");t.forEach((e=>{e.addEventListener("click",(async e=>{const n=parseInt(e.target.getAttribute("data-range"));t.forEach((t=>t.classList.remove("active"))),e.target.classList.add("active"),this.rangeBack=n,await this.loadChartData(),0===n?(await this.startAutoRefresh(),await this.subscribeToLivePrice()):(this.stopAutoRefresh(),this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=null,this.livePrice=null))}))}))}setupChartTypeButtons(){const t=this.container.querySelectorAll(".type-btn");t.forEach((e=>{e.addEventListener("click",(e=>{const n=e.target.getAttribute("data-type");t.forEach((t=>t.classList.remove("active"))),e.target.classList.add("active"),this.chartType=n,this.renderChart(),this.updateStats()}))}))}addStyles(){if(this.options.skipStyleInjection||document.querySelector('link[href*="mdas-styles.css"]'))this.debug&&console.log("[IntradayChartWidget] Skipping style injection - external styles detected");else if(!document.querySelector("#intraday-chart-styles"))try{const t=document.createElement("style");t.id="intraday-chart-styles",t.textContent="\n .intraday-chart-widget {\n font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;\n background: white;\n border-radius: 12px;\n padding: 20px;\n box-shadow: 0 2px 8px rgba(0,0,0,0.1);\n position: relative;\n width: 100%;\n min-width: 600px;\n max-width: 1400px;\n margin: 0 auto;\n }\n\n .chart-header {\n display: flex;\n justify-content: space-between;\n align-items: center;\n margin-bottom: 20px;\n padding-bottom: 15px;\n border-bottom: 1px solid #e5e7eb;\n }\n\n .chart-title-section {\n display: flex;\n flex-direction: column;\n gap: 4px;\n }\n\n .company-market-info {\n display: flex;\n gap: 8px;\n align-items: center;\n font-size: 0.75em;\n color: #6b7280;\n }\n\n .intraday-company-name {\n font-weight: 500;\n }\n\n .intraday-chart-symbol {\n font-size: 1.5em;\n font-weight: 700;\n color: #1f2937;\n margin: 0;\n }\n\n .intraday-chart-source {\n font-size: 0.75em;\n padding: 4px 8px;\n border-radius: 4px;\n background: #e0e7ff;\n color: #4338ca;\n font-weight: 600;\n }\n\n .chart-change {\n font-size: 1.1em;\n font-weight: 600;\n padding: 6px 12px;\n border-radius: 6px;\n }\n\n .chart-change.positive {\n color: #059669;\n background: #d1fae5;\n }\n\n .chart-change.negative {\n color: #dc2626;\n background: #fee2e2;\n }\n\n .chart-controls {\n display: flex;\n justify-content: space-between;\n align-items: center;\n margin-bottom: 15px;\n }\n\n .chart-range-selector {\n display: flex;\n gap: 8px;\n }\n\n .range-btn {\n padding: 8px 16px;\n border: 1px solid #e5e7eb;\n background: white;\n border-radius: 6px;\n font-size: 0.875em;\n font-weight: 600;\n color: #6b7280;\n cursor: pointer;\n transition: all 0.2s ease;\n }\n\n .range-btn:hover {\n background: #f9fafb;\n border-color: #d1d5db;\n }\n\n .range-btn.active {\n background: #667eea;\n color: white;\n border-color: #667eea;\n }\n\n .range-btn:focus {\n outline: none;\n box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);\n }\n\n .chart-type-selector {\n display: flex;\n gap: 8px;\n }\n\n .type-btn {\n padding: 8px 16px;\n border: 1px solid #e5e7eb;\n background: white;\n border-radius: 6px;\n font-size: 0.875em;\n font-weight: 600;\n color: #6b7280;\n cursor: pointer;\n transition: all 0.2s ease;\n }\n\n .type-btn:hover {\n background: #f9fafb;\n border-color: #d1d5db;\n }\n\n .type-btn.active {\n background: #10b981;\n color: white;\n border-color: #10b981;\n }\n\n .type-btn:focus {\n outline: none;\n box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);\n }\n\n .zoom-reset-btn {\n display: flex;\n align-items: center;\n gap: 6px;\n padding: 8px 12px;\n border: 1px solid #e5e7eb;\n background: white;\n border-radius: 6px;\n font-size: 0.875em;\n font-weight: 500;\n color: #6b7280;\n cursor: pointer;\n transition: all 0.2s ease;\n }\n\n .zoom-reset-btn:hover {\n background: #f9fafb;\n border-color: #667eea;\n color: #667eea;\n }\n\n .zoom-reset-btn:focus {\n outline: none;\n box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);\n }\n\n .zoom-reset-btn svg {\n flex-shrink: 0;\n }\n\n .chart-container {\n height: 500px;\n margin-bottom: 20px;\n position: relative;\n }\n\n .chart-stats {\n display: grid;\n grid-template-columns: repeat(5, 1fr);\n gap: 15px;\n padding: 15px;\n background: #f9fafb;\n border-radius: 8px;\n }\n\n .stat-item {\n display: flex;\n flex-direction: column;\n gap: 4px;\n }\n\n .stat-label {\n font-size: 0.75em;\n color: #6b7280;\n font-weight: 600;\n text-transform: uppercase;\n letter-spacing: 0.5px;\n }\n\n .stat-value {\n font-size: 1.1em;\n font-weight: 700;\n color: #1f2937;\n }\n\n .widget-loading-overlay {\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background: rgba(255, 255, 255, 0.4);\n display: flex;\n flex-direction: row;\n align-items: center;\n justify-content: center;\n gap: 10px;\n padding: 10px 16px;\n border-radius: 12px;\n z-index: 10;\n pointer-events: none;\n backdrop-filter: blur(1px);\n }\n\n .widget-loading-overlay.hidden {\n display: none;\n }\n\n .loading-spinner {\n width: 20px;\n height: 20px;\n border: 3px solid #e5e7eb;\n border-top-color: #667eea;\n border-radius: 50%;\n animation: spin 0.8s linear infinite;\n }\n\n .loading-text {\n color: #6b7280;\n font-size: 0.875em;\n font-weight: 500;\n }\n\n @keyframes spin {\n to { transform: rotate(360deg); }\n }\n\n @media (max-width: 768px) {\n .intraday-chart-widget {\n min-width: unset;\n padding: 15px;\n }\n\n .chart-stats {\n grid-template-columns: repeat(3, 1fr);\n gap: 10px;\n }\n\n .chart-container {\n height: 350px;\n }\n\n .intraday-chart-symbol {\n font-size: 1.2em;\n }\n }\n\n .widget-error {\n padding: 15px;\n background: #fee2e2;\n border: 1px solid #fecaca;\n border-radius: 8px;\n color: #dc2626;\n font-size: 0.9em;\n margin-top: 10px;\n }\n",document.head.appendChild(t),this.debug&&console.log("[IntradayChartWidget] Styles injected successfully")}catch(t){console.warn("[IntradayChartWidget] Failed to inject styles:",t),console.warn('[IntradayChartWidget] Please add <link rel="stylesheet" href="mdas-styles.css"> to your HTML')}}async loadChartData(){try{this.showLoading(),this.clearError();const t=this.wsManager.getApiService();if(!t)throw new Error("API service not available");if(5===this.rangeBack)return void await this.load5DayChartData(t);const e=7;let n=this.rangeBack,i=!1,s=null,o=null,a=!1;for(let r=0;r<e;r++){if(this.debug&&console.log(`[IntradayChartWidget] Loading data for ${this.symbol} from ${this.source}, range_back: ${n} (attempt ${r+1}/${e})`),s=await t.getIntradayChart(this.source,this.symbol,n),console.log("[IntradayChartWidget] API response type:",typeof s),console.log("[IntradayChartWidget] API response:",s),s&&(console.log("[IntradayChartWidget] Response keys:",Object.keys(s)),Array.isArray(s)&&(console.log("[IntradayChartWidget] Response is array, length:",s.length),s.length>0&&(console.log("[IntradayChartWidget] First item:",s[0]),console.log("[IntradayChartWidget] First item keys:",Object.keys(s[0]))))),s&&s.error)throw new Error(s.error||"Server error");if(o=s,s&&s.data&&Array.isArray(s.data)&&(console.log("[IntradayChartWidget] Found data array in response.data"),o=s.data),o&&Array.isArray(o)&&o.length>0){i=!0,n!==this.rangeBack&&(a=!0,this.debug&&console.log(`[IntradayChartWidget] Using fallback data: requested rangeBack ${this.rangeBack}, got data from rangeBack ${n}`));break}console.log(`[IntradayChartWidget] No data for rangeBack ${n}, trying ${n+1}...`),n++}if(!i||!o||0===o.length)throw new Error(`No intraday data available for ${this.symbol} in the past ${e} days`);if(console.log("[IntradayChartWidget] Processing",o.length,"data points"),this.chartData=new T(o),console.log("[IntradayChartWidget] Model created with",this.chartData.dataPoints.length,"points"),0===this.chartData.dataPoints.length)throw console.error("[IntradayChartWidget] Model has no data points after processing"),new Error(`No valid data points for ${this.symbol}`);this.renderChart(),this.updateStats(),this.hideLoading(),this.debug&&console.log(`[IntradayChartWidget] Loaded ${o.length} data points`),0!==this.rangeBack||a?(this.stopAutoRefresh(),this.debug&&console.log("[IntradayChartWidget] Not starting auto-refresh for historical/fallback data")):(await this.startAutoRefresh(),this.subscribeToLivePrice(),this.preload5DDataInBackground())}catch(t){console.error("[IntradayChartWidget] Error loading chart data:",t),this.hideLoading();let e="Failed to load chart data";t.message.includes("No intraday data")?e=t.message:t.message.includes("API service not available")?e="Unable to connect to data service":t.message.includes("HTTP error")||t.message.includes("status: 4")?e=`Unable to load data for ${this.symbol}`:t.message.includes("status: 5")?e="Server error. Please try again later":t.message.includes("Failed to fetch")&&(e="Network error. Please check your connection"),this.showError(e)}}async load5DayChartData(t){try{if(this.cached5DData)return this.debug&&console.log("[IntradayChartWidget] Using cached 5D data"),this.chartData=this.cached5DData,this.renderChart(),this.updateStats(),this.hideLoading(),void this.stopAutoRefresh();const e=await this.fetch5DayData(t);if(this.chartData=new T(e),0===this.chartData.dataPoints.length)throw new Error(`No valid data points for ${this.symbol}`);this.cached5DData=this.chartData,this.renderChart(),this.updateStats(),this.hideLoading(),this.debug&&console.log(`[IntradayChartWidget] 5D chart loaded with ${this.chartData.dataPoints.length} data points`),this.stopAutoRefresh()}catch(t){throw console.error("[IntradayChartWidget] Error loading 5D chart data:",t),t}}async fetch5DayData(t){this.debug&&console.log("[IntradayChartWidget] Fetching 5D chart data with parallel requests (API limit: rangeback 0-6)");const e=[];for(let n=0;n<7;n++)e.push(t.getIntradayChart(this.source,this.symbol,n).then((t=>{let e=t;return t&&t.data&&Array.isArray(t.data)&&(e=t.data),{rangeBack:n,data:e}})).catch((t=>(this.debug&&console.warn(`[IntradayChartWidget] Request failed for rangeback ${n}:`,t),{rangeBack:n,data:null}))));const n=await Promise.all(e);this.debug&&console.log("[IntradayChartWidget] All parallel requests completed");const i=n.filter((t=>{const e=t.data&&Array.isArray(t.data)&&t.data.length>0;return this.debug&&(e?console.log(`[IntradayChartWidget] Rangeback ${t.rangeBack}: ${t.data.length} data points`):console.log(`[IntradayChartWidget] Rangeback ${t.rangeBack}: No data (skipped)`)),e})).slice(0,5);if(0===i.length)throw new Error(`No intraday data available for ${this.symbol} in the past 7 days`);this.debug&&(console.log(`[IntradayChartWidget] Collected ${i.length}/5 days of data`),i.length<5&&console.log(`[IntradayChartWidget] Note: Only ${i.length} days available within API limit (rangeback 0-6)`));const s=[];for(let t=i.length-1;t>=0;t--)s.push(...i[t].data);return this.debug&&console.log(`[IntradayChartWidget] Combined ${s.length} total data points from ${i.length} days`),s}preload5DDataInBackground(){this.is5DDataLoading||this.cached5DData||(this.is5DDataLoading=!0,this.debug&&console.log("[IntradayChartWidget] Starting background preload of 5D data..."),setTimeout((async()=>{try{const t=this.wsManager.getApiService();if(!t)return void(this.debug&&console.log("[IntradayChartWidget] API service not available for preload"));const e=await this.fetch5DayData(t),n=new T(e);this.cached5DData=n,this.debug&&console.log(`[IntradayChartWidget] ✓ Background preload complete: ${n.dataPoints.length} data points cached`)}catch(t){this.debug&&console.warn("[IntradayChartWidget] Background preload failed:",t)}finally{this.is5DDataLoading=!1}}),1e3))}subscribeToLivePrice(){this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=null);const t="bruce"===this.source?"querybrucel1":"queryblueoceanl1";this.debug&&console.log(`[IntradayChartWidget] Subscribing to live price with ${t} for ${this.symbol}`),this.unsubscribe=this.wsManager.subscribe(this.widgetId,[t],this.handleMessage.bind(this),this.symbol)}handleError(t){this.debug&&console.error("[IntradayChartWidget] WebSocket error:",t.message||t)}handleData(t){console.log("[IntradayChartWidget] handleData called with:",t),console.log("[IntradayChartWidget] Looking for symbol:",this.symbol),console.log("[IntradayChartWidget] Message is array?",Array.isArray(t));let e=null;if(Array.isArray(t)){console.log("[IntradayChartWidget] Processing array format, length:",t.length);const n=t.find((t=>t.Symbol===this.symbol));console.log("[IntradayChartWidget] Found symbol data:",n),n&&!n.NotFound&&(e=n)}else"queryblueoceanl1"===t.type||"querybrucel1"===t.type?(console.log("[IntradayChartWidget] Processing wrapped format"),t[0]?.Symbol!==this.symbol||t[0].NotFound||(e=t[0])):t.Symbol!==this.symbol||t.NotFound||(console.log("[IntradayChartWidget] Processing direct format"),e=t);if(!e)return void console.log("[IntradayChartWidget] No matching price data found for symbol:",this.symbol);console.log("[IntradayChartWidget] Price data found:",e);let n=null;void 0!==e.LastPx&&null!==e.LastPx?(n=parseFloat(e.LastPx),console.log("[IntradayChartWidget] Price from LastPx:",n)):void 0!==e.Last&&null!==e.Last?(n=parseFloat(e.Last),console.log("[IntradayChartWidget] Price from Last:",n)):void 0!==e.last_price&&null!==e.last_price?(n=parseFloat(e.last_price),console.log("[IntradayChartWidget] Price from last_price:",n)):void 0!==e.TradePx&&null!==e.TradePx?(n=parseFloat(e.TradePx),console.log("[IntradayChartWidget] Price from TradePx:",n)):void 0!==e.Close&&null!==e.Close?(n=parseFloat(e.Close),console.log("[IntradayChartWidget] Price from Close:",n)):void 0!==e.close&&null!==e.close&&(n=parseFloat(e.close),console.log("[IntradayChartWidget] Price from close:",n)),console.log("[IntradayChartWidget] Extracted price:",n),n&&!isNaN(n)&&n>0?(this.livePrice=n,console.log("[IntradayChartWidget] Updating live price line to:",n),this.updateLivePriceLine(),console.log(`[IntradayChartWidget] Live price update: $${n.toFixed(2)}`)):console.log("[IntradayChartWidget] Invalid price, not updating:",n)}updateLivePriceLine(){this.chartInstance&&this.livePrice?this.chartInstance.options.plugins.annotation&&(this.chartInstance.options.plugins.annotation.annotations.livePriceLine.value=this.livePrice,this.chartInstance.options.plugins.annotation.annotations.livePriceLine.label.content=`$${this.livePrice.toFixed(2)}`,this.chartInstance.options.plugins.annotation.annotations.livePriceLine.label.display=!0,this.debug&&console.log("[IntradayChartWidget] Live price line updated:",{price:this.livePrice,label:this.chartInstance.options.plugins.annotation.annotations.livePriceLine.label.content}),this.chartInstance.update("none")):this.debug&&console.log("[IntradayChartWidget] Cannot update live price line:",{hasChart:!!this.chartInstance,livePrice:this.livePrice})}async isMarketOpen(){const t=new Date,e=t.toLocaleString("en-US",{timeZone:"America/New_York",weekday:"short"}),n=parseInt(t.toLocaleString("en-US",{timeZone:"America/New_York",hour12:!1,hour:"numeric"}),10),i=parseInt(t.toLocaleString("en-US",{timeZone:"America/New_York",minute:"numeric"}),10);if("Sat"===e||"Sun"===e)return!1;const s=n>=20||n<4;if(this.debug&&console.log(`[IntradayChartWidget] Market check: ET hour=${n}, minute=${i}, day=${e}, open=${s}`),!s)return this.debug&&console.log("[IntradayChartWidget] Market is currently closed (outside 8pm-4am ET on weekdays)."),!1;if(!this.marketStatusChecked)try{const t=this.wsManager.getApiService(),e=await t.getMarketStatus(this.source);if(e&&Array.isArray(e)&&e.length>0){const t=e[0].status;return this.marketIsOpen=t&&"open"===t.toLowerCase(),this.marketStatusChecked=!0,this.debug&&console.log(`[IntradayChartWidget] Market status from API: ${t} (${this.marketIsOpen?"Open":"Closed"})`),this.marketIsOpen}}catch(t){return this.debug&&console.warn("[IntradayChartWidget] Failed to get market status from API, assuming open based on time:",t),this.marketIsOpen=!0,this.marketStatusChecked=!0,!0}return!1!==this.marketIsOpen&&(!0!==this.marketIsOpen||(!(3===n&&i>=45)||(this.debug&&console.log("[IntradayChartWidget] Approaching market close, re-checking status..."),this.marketStatusChecked=!1,await this.isMarketOpen())))}async startAutoRefresh(){if(this.stopAutoRefresh(),!this.autoRefresh)return;await this.isMarketOpen()?(this.debug&&console.log(`[IntradayChartWidget] Starting auto-refresh every ${this.refreshInterval/1e3} seconds`),this.refreshTimer=setInterval((async()=>{if(!await this.isMarketOpen())return this.debug&&console.log("[IntradayChartWidget] Market closed. Stopping auto-refresh."),void this.stopAutoRefresh();if(this.isUserInteracting)this.debug&&console.log("[IntradayChartWidget] Skipping refresh - user is interacting");else{this.debug&&console.log("[IntradayChartWidget] Auto-refreshing chart data");try{const t=this.wsManager.getApiService(),e=await t.getIntradayChart(this.source,this.symbol,this.rangeBack);e&&Array.isArray(e)&&(this.chartData=new T(e),this.renderChart(),this.updateStats(),this.debug&&console.log(`[IntradayChartWidget] Auto-refresh complete - ${e.length} data points`))}catch(t){console.error("[IntradayChartWidget] Auto-refresh failed:",t)}}}),this.refreshInterval)):this.debug&&console.log("[IntradayChartWidget] Market is closed. Auto-refresh will not start.")}stopAutoRefresh(){this.refreshTimer&&(this.debug&&console.log("[IntradayChartWidget] Stopping auto-refresh"),clearInterval(this.refreshTimer),this.refreshTimer=null)}parseTimestamp(t){return new Date(t)}renderChart(){if(console.log("[IntradayChartWidget] renderChart called"),!this.chartData||0===this.chartData.dataPoints.length)return void console.error("[IntradayChartWidget] No data to render");console.log("[IntradayChartWidget] Chart data points:",this.chartData.dataPoints.length);const t=this.container.querySelector("#intradayChart");if(console.log("[IntradayChartWidget] Canvas element:",t),!t)return void console.error("[IntradayChartWidget] Canvas element not found");if(this.chartInstance){console.log("[IntradayChartWidget] Destroying existing chart instance");try{this.chartInstance.destroy(),this.chartInstance=null}catch(t){console.error("[IntradayChartWidget] Error destroying chart:",t),this.chartInstance=null}}const e=t.getContext("2d");console.log("[IntradayChartWidget] Canvas context:",e),console.log("[IntradayChartWidget] Preparing chart data...");const n=this.chartData.getStats();console.log("[IntradayChartWidget] Stats:",n);const i=n.change>=0,s=i?"#10b981":"#ef4444";let o,a;const r=this.chartData.dataPoints;if(0===r.length)return console.error("[IntradayChartWidget] No valid data points from model"),void this.showError("No valid chart data available");if(console.log("[IntradayChartWidget] Rendering",r.length,"data points"),"candlestick"===this.chartType){if(o=this.rangeBack>0?r.map(((t,e)=>({x:e,o:t.open,h:t.high,l:t.low,c:t.close}))):r.map((t=>({x:this.parseTimestamp(t.time).getTime(),o:t.open,h:t.high,l:t.low,c:t.close}))).filter((t=>!isNaN(t.x)&&t.x>0)),0===o.length)return console.error("[IntradayChartWidget] No valid candlestick data points after date parsing"),void this.showError("Unable to parse chart data timestamps");a={label:"Price",data:o,color:{up:"#10b981",down:"#ef4444",unchanged:"#6b7280"},borderColor:{up:"#10b981",down:"#ef4444",unchanged:"#6b7280"}}}else{if(o=this.rangeBack>0?r.map(((t,e)=>({x:e,y:t.close}))):r.map((t=>({x:this.parseTimestamp(t.time),y:t.close}))).filter((t=>{const e=t.x.getTime();return!isNaN(e)&&e>0})),0===o.length)return console.error("[IntradayChartWidget] No valid chart data points after date parsing"),void this.showError("Unable to parse chart data timestamps");const t=e.createLinearGradient(0,0,0,300);i?(t.addColorStop(0,"rgba(16, 185, 129, 0.3)"),t.addColorStop(1,"rgba(16, 185, 129, 0.01)")):(t.addColorStop(0,"rgba(239, 68, 68, 0.3)"),t.addColorStop(1,"rgba(239, 68, 68, 0.01)")),a={label:"Price",data:o,borderColor:s,backgroundColor:"area"===this.chartType?t:"transparent",borderWidth:2,fill:"area"===this.chartType,tension:.4,pointRadius:0,pointHoverRadius:4,pointBackgroundColor:s,pointBorderColor:"#fff",pointBorderWidth:2}}let c,l;if(console.log("[IntradayChartWidget] Chart data points prepared:",o.length),console.log("[IntradayChartWidget] First data point - Source time:",r[0].time),console.log("[IntradayChartWidget] First chart point:",o[0]),console.log("[IntradayChartWidget] Last data point - Source time:",r[r.length-1].time),console.log("[IntradayChartWidget] Last chart point:",o[o.length-1]),0===this.rangeBack){const t=o.map((t=>"candlestick"===this.chartType?t.x:t.x.getTime()));c=Math.min(...t),l=Math.max(...t),console.log("[IntradayChartWidget] X-axis bounds:",{min:c,max:l,minDate:new Date(c),maxDate:new Date(l)})}else console.log("[IntradayChartWidget] Using linear scale with",o.length,"data points");const d={type:"candlestick"===this.chartType?"candlestick":"line",data:{datasets:[a]},options:{responsive:!0,maintainAspectRatio:!1,interaction:{intersect:!1,mode:"index"},plugins:{legend:{display:!1},decimation:{enabled:o.length>1e3,algorithm:"lttb",samples:500,threshold:1e3},tooltip:{enabled:!0,backgroundColor:"rgba(0, 0, 0, 0.8)",titleColor:"#fff",bodyColor:"#fff",borderColor:s,borderWidth:1,padding:10,displayColors:!1,callbacks:{title:t=>{const e=t[0].dataIndex,n=r[e];if(n){return new Date(n.time).toLocaleString("en-US",{month:"2-digit",day:"2-digit",year:"numeric",hour:"numeric",minute:"2-digit",second:"2-digit",hour12:!0})}return""},label:t=>{const e=t.dataIndex,n=r[e];return n?"candlestick"===this.chartType?[`Open: $${n.open.toFixed(2)}`,`High: $${n.high.toFixed(2)}`,`Low: $${n.low.toFixed(2)}`,`Close: $${n.close.toFixed(2)}`,`Volume: ${this.chartData.formatVolume(n.volume)}`]:[`Price: $${n.close.toFixed(2)}`,`Open: $${n.open.toFixed(2)}`,`High: $${n.high.toFixed(2)}`,`Low: $${n.low.toFixed(2)}`,`Volume: ${this.chartData.formatVolume(n.volume)}`]:[]}}},zoom:{pan:{enabled:!0,mode:"x",modifierKey:"ctrl"},zoom:{wheel:{enabled:!0,speed:.1},pinch:{enabled:!0},mode:"x"},limits:{x:{min:"original",max:"original"}}},annotation:{annotations:this.createAnnotations(r,n)}},scales:{x:{type:0===this.rangeBack?"time":"linear",min:0===this.rangeBack?c:void 0,max:0===this.rangeBack?l:void 0,time:0===this.rangeBack?{unit:"hour",stepSize:1,displayFormats:{hour:"h:mm a"},tooltipFormat:"MMM d, h:mm a"}:void 0,grid:{display:!1},ticks:{maxTicksLimit:0===this.rangeBack?10:8,color:"#6b7280",autoSkip:!0,maxRotation:0,minRotation:0,callback:(t,e,n)=>{if(this.rangeBack>0){const e=Math.round(t),n=r[e];if(n){return new Date(n.time).toLocaleString("en-US",{month:"short",day:"numeric",hour:"numeric",minute:"2-digit",hour12:!0})}return""}if("number"==typeof t){return new Date(t).toLocaleString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0})}return t}}},y:{position:"right",grid:{color:"rgba(0, 0, 0, 0.05)"},ticks:{color:"#6b7280",callback:function(t){return"$"+t.toFixed(2)}},afterDataLimits:t=>{const e=.1*(t.max-t.min);t.max+=e,t.min-=e}}}}};console.log("[IntradayChartWidget] Creating Chart.js instance with config:",d),console.log("[IntradayChartWidget] Chart available?",void 0!==eo);try{this.chartInstance=new eo(e,d),console.log("[IntradayChartWidget] Chart instance created successfully:",this.chartInstance)}catch(t){throw console.error("[IntradayChartWidget] Error creating chart:",t),t}t.addEventListener("mouseenter",(()=>{this.isUserInteracting=!0})),t.addEventListener("mouseleave",(()=>{this.isUserInteracting=!1})),this.setupZoomReset()}createAnnotations(t,e){const n={livePriceLine:{type:"line",scaleID:"y",value:this.livePrice||e.close,borderColor:"#667eea",borderWidth:2,borderDash:[5,5],label:{display:!0,content:this.livePrice?`$${this.livePrice.toFixed(2)}`:`$${e.close.toFixed(2)}`,enabled:!0,position:"end",backgroundColor:"rgb(102, 126, 234)",color:"#ffffff",font:{size:12,weight:"bold",family:"system-ui, -apple-system, sans-serif"},padding:{top:4,bottom:4,left:8,right:8},borderRadius:4,xAdjust:-10,yAdjust:0}}};if(this.rangeBack>0&&t.length>0){let e=null;t.forEach(((t,i)=>{const s=new Date(t.time).toDateString();e!==s&&null!==e&&(n[`daySeparator${i}`]={type:"line",scaleID:"x",value:i,borderColor:"rgba(0, 0, 0, 0.1)",borderWidth:1,borderDash:[3,3]}),e=s}))}return n}setupZoomReset(){const t=this.container.querySelector(".zoom-reset-btn");t&&t.addEventListener("click",(()=>{this.chartInstance&&(this.chartInstance.resetZoom(),this.debug&&console.log("[IntradayChartWidget] Zoom reset"))}))}updateStats(){if(!this.chartData)return;const t=this.chartData.getStats(),e=this.container.querySelector(".stat-high .stat-value"),n=this.container.querySelector(".stat-low .stat-value"),i=this.container.querySelector(".stat-open .stat-value"),s=this.container.querySelector(".stat-close .stat-value"),o=this.container.querySelector(".stat-volume .stat-value"),a=this.container.querySelector(".chart-change");if(e&&(e.textContent=`$${t.high.toFixed(2)}`),n&&(n.textContent=`$${t.low.toFixed(2)}`),i&&(i.textContent=`$${t.open.toFixed(2)}`),s&&(s.textContent=`$${t.close.toFixed(2)}`),o&&(o.textContent=this.chartData.formatVolume(t.volume)),a){const e=t.change>=0?"positive":"negative";a.className=`chart-change ${e}`;const n=t.change>=0?"+":"";a.textContent=`${n}${t.change.toFixed(2)} (${n}${t.changePercent.toFixed(2)}%)`}}async refreshData(){await this.loadChartData()}destroy(){this.stopAutoRefresh(),this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=null),this.chartInstance&&(this.chartInstance.destroy(),this.chartInstance=null),this.symbolEditor&&(this.symbolEditor.destroy(),this.symbolEditor=null),super.destroy()}}class Lu{constructor(t){this.stateManager=t,this.widgets=new Map}createWidget(t,e){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};const i=this.generateWidgetId();let s;switch(t){case"quote-level1":s=new b(e,n,i);break;case"night-session":s=new x(e,n,i);break;case"options":s=new w(e,n,i);break;case"option-chain":s=new M(e,n,i);break;case"data":s=new _(e,n,i);break;case"combined-market":s=new D(e,n,i);break;case"intraday-chart":s=new Au(e,n,i);break;default:throw new Error(`Unknown widget type: ${t}`)}return this.widgets.set(i,s),s}generateWidgetId(){return`widget_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}destroyWidget(t){const e=this.widgets.get(t);e&&(e.destroy(),this.widgets.delete(t))}getWidgetCount(){return this.widgets.size}destroy(){this.widgets.forEach((t=>t.destroy())),this.widgets.clear()}}class Iu{constructor(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"https://mdas-api-dev.viewtrade.dev";this.token=t,this.baseUrl=e}async request(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};const n=`${this.baseUrl}${t}`,i={method:"GET",headers:{Authorization:`Bearer ${this.token}`,"Content-Type":"application/json",...e.headers},...e};try{const t=await fetch(n,i);if(!t.ok)throw new Error(`HTTP error! status: ${t.status}`);return await t.json()}catch(t){throw console.error(`[ApiService] Request failed for ${n}:`,t),t}}async getOptionChainDates(t){return this.request(`/api/quote/option-chain-dates?symbol=${t}&response_camel_case=false`)}async quoteOptionl1(t){return this.request(`/api/quote/option-level1?option_names=${t}&response_camel_case=false`)}async quotel1(t){return this.request(`/api/quote/level1?symbols=${t}&response_camel_case=false`)}async quoteBlueOcean(t){return this.request(`/api/quote/night-session/level1/blueocean?symbols=${t}&response_camel_case=false`)}async getIntradayChart(t,e){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;return this.request(`/api/quote/night-session/intraday/${t}?symbol=${e}&range_back=${n}`)}async getMarketStatus(t){return this.request(`/api/quote/night-session/market-status/${t}`)}}class Ou{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.config={debug:t.debug||!1,token:t.token,baseUrl:t.baseUrl||"ws://localhost:3000/wssub",apiBaseUrl:t.apiBaseUrl,maxConnections:t.maxConnections||1,reconnectOptions:{maxAttempts:t.reconnectOptions?.maxAttempts||10,initialDelay:t.reconnectOptions?.initialDelay||1e3,maxDelay:t.reconnectOptions?.maxDelay||3e4,backoff:t.reconnectOptions?.backoff||1.5,jitter:t.reconnectOptions?.jitter||.3},timeouts:{connection:t.timeouts?.connection||1e4,inactivity:t.timeouts?.inactivity||9e4},enableActivityMonitoring:!1},this.apiService=new Iu(this.config.token,this.config.apiBaseUrl),this.connection=null,this.connectionState="disconnected",this.reconnectAttempts=0,this.reconnectTimer=null,this.connectionStartTime=null,this.subscriptions=new Map,this.activeSubscriptions=new Set,this.messageQueue=[],this.symbolSubscriptions=new Map,this.typeSubscriptions=new Map,this.lastMessageCache=new Map,this.connectionPromise=null,this.reloginCallback=t.reloginCallback||null,this.isReloginInProgress=!1,this.lastMessageReceived=null,this.activityCheckInterval=null,this.isOnline="undefined"==typeof navigator||navigator.onLine,this.onlineHandler=null,this.offlineHandler=null,this.circuitBreaker={state:"closed",failureCount:0,failureThreshold:5,timeout:6e4,lastFailureTime:null,resetTimer:null},this.metrics={successfulConnections:0,failedConnections:0,totalReconnects:0,avgConnectionTime:0,lastSuccessfulConnection:null,messagesReceived:0,messagesSent:0},this.handleOpen=this.handleOpen.bind(this),this.handleMessage=this.handleMessage.bind(this),this.handleClose=this.handleClose.bind(this),this.handleError=this.handleError.bind(this),this.isManualDisconnect=!1,this._initNetworkMonitoring(),this.config.debug&&console.log("[WebSocketManager] Initialized with config:",this.config)}async connect(){return"connected"===this.connectionState||"connecting"===this.connectionState?Promise.resolve():new Promise(((t,e)=>{this.connectionPromise={resolve:t,reject:e},this._connect()}))}subscribe(t,e,n){let i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:null,s=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};Array.isArray(e)||(e=[e]);const o=this.subscriptions.get(t);if(o){if(this.config.debug&&console.log(`[WebSocketManager] Cleaning up existing subscription for widget ${t} before re-subscribing`),o.symbol){const e=this.symbolSubscriptions.get(o.symbol);e&&(e.delete(t),0===e.size&&this.symbolSubscriptions.delete(o.symbol))}o.types&&o.types.forEach((e=>{const n=this.typeSubscriptions.get(e);n&&(n.delete(t),0===n.size&&this.typeSubscriptions.delete(e))}))}const a={types:new Set(e),callback:n,symbol:i?.toUpperCase(),additionalParams:s};if(this.subscriptions.set(t,a),i){const e=i.toUpperCase();this.symbolSubscriptions.has(e)||this.symbolSubscriptions.set(e,new Set),this.symbolSubscriptions.get(e).add(t)}return e.forEach((e=>{this.typeSubscriptions.has(e)||this.typeSubscriptions.set(e,new Set),this.typeSubscriptions.get(e).add(t)})),this.config.debug&&console.log(`[WebSocketManager] Widget ${t} subscribed to:`,e,`for symbol: ${i}`,s),"connected"===this.connectionState&&(this._sendSubscriptions(e),e.forEach((e=>{const s=i?`${e}:${i}`:e,o=this.lastMessageCache.get(s);if(o&&this.activeSubscriptions.has(s)){this.config.debug&&console.log(`[WebSocketManager] Sending cached data to new widget ${t} for ${s}`);try{n({event:"data",data:o,widgetId:t})}catch(e){console.error(`[WebSocketManager] Error sending cached data to widget ${t}:`,e)}}}))),()=>this.unsubscribe(t)}unsubscribe(t){const e=this.subscriptions.get(t);if(e){if(e.symbol&&e.types&&e.types.forEach((t=>{this.sendUnsubscribe(t,e.symbol,e.additionalParams||{})})),e.symbol){const n=this.symbolSubscriptions.get(e.symbol);n&&(n.delete(t),0===n.size&&this.symbolSubscriptions.delete(e.symbol))}e.types.forEach((e=>{const n=this.typeSubscriptions.get(e);n&&(n.delete(t),0===n.size&&this.typeSubscriptions.delete(e))})),this.subscriptions.delete(t),this.config.debug&&console.log(`[WebSocketManager] Widget ${t} unsubscribed`),this._cleanupUnusedSubscriptions()}}sendUnsubscribe(t,e){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};try{let i,s;"queryoptionchain"===t?(s=`${t}:${e}:${n.date||""}`,i={type:t,underlying:e,date:n.date,unsubscribe:!0}):"queryoptionl1"===t?(s=`${t}:${e}`,i={type:t,optionName:e,unsubscribe:!0}):(s=`${t}:${e}`,i={type:t,symbol:e,unsubscribe:!0}),this.config.debug&&console.log(`[WebSocketManager] Sending unsubscribe for ${s}:`,i),this.send(i),this.activeSubscriptions.delete(s),this.config.debug&&console.log(`[WebSocketManager] Removed ${s} from active subscriptions`)}catch(t){console.error("[WebSocketManager] Error sending unsubscribe:",t)}}sendUnsubscribeAll(){try{const t={unsubscribe_all:!0};this.config.debug&&console.log("[WebSocketManager] Sending unsubscribe all"),this.send(t),this.activeSubscriptions.clear()}catch(t){console.error("[WebSocketManager] Error sending unsubscribe all:",t)}}send(t){if("connected"!==this.connectionState||!this.connection||1!==this.connection.readyState)return this.messageQueue&&Array.isArray(this.messageQueue)||(this.messageQueue=[]),this.messageQueue.push(t),this.config.debug&&console.log("[WebSocketManager] Message queued (not connected):",t),!1;try{return this.connection.send(JSON.stringify(t)),this.config.debug&&console.log("[WebSocketManager] Sent message:",t),this.metrics.messagesSent++,!0}catch(t){return console.error("[WebSocketManager] Error sending message:",t),!1}}getConnectionState(){return this.connectionState}getSubscriptionCount(){return this.subscriptions.size}_connect(){if("connecting"!==this.connectionState){this.isManualDisconnect=!1,this.connectionState="connecting",this.connectionStartTime=Date.now();try{this.connection&&(this.connection.removeEventListener("open",this.handleOpen),this.connection.removeEventListener("message",this.handleMessage),this.connection.removeEventListener("close",this.handleClose),this.connection.removeEventListener("error",this.handleError),this.connection=null);const t=`${this.config.baseUrl}?token=${this.config.token}`;this.config.debug&&console.log("[WebSocketManager] Connecting to:",t),this.connection=new WebSocket(t);const e=setTimeout((()=>{this.connection&&0===this.connection.readyState&&(console.error("[WebSocketManager] Connection timeout"),this.connection.close(),this.connectionState="disconnected",this._updateCircuitBreaker(!1),this.connectionPromise&&(this.connectionPromise.reject(new Error("Connection timeout")),this.connectionPromise=null),this._scheduleReconnect())}),this.config.timeouts.connection);this.connection.addEventListener("open",(t=>{clearTimeout(e),this.handleOpen(t)})),this.connection.addEventListener("message",this.handleMessage),this.connection.addEventListener("close",(t=>{clearTimeout(e),this.handleClose(t)})),this.connection.addEventListener("error",(t=>{clearTimeout(e),this.handleError(t)}))}catch(t){console.error("[WebSocketManager] Connection error:",t),this.connectionState="disconnected",this.connectionPromise&&(this.connectionPromise.reject(t),this.connectionPromise=null),this._scheduleReconnect()}}}handleOpen(t){const e=Date.now()-this.connectionStartTime;this.connectionState="connected",this.reconnectAttempts=0,this.lastMessageReceived=Date.now(),this.metrics.successfulConnections++,this.metrics.lastSuccessfulConnection=Date.now();const n=this.metrics.avgConnectionTime,i=this.metrics.successfulConnections;this.metrics.avgConnectionTime=(n*(i-1)+e)/i,this._updateCircuitBreaker(!0),this.config.debug&&console.log("[WebSocketManager] Connected successfully",{connectionTime:`${e}ms`,avgConnectionTime:`${Math.round(this.metrics.avgConnectionTime)}ms`,attempt:this.metrics.totalReconnects+1}),this.connectionPromise&&(this.connectionPromise.resolve(),this.connectionPromise=null);try{this._startActivityMonitoring(),this._sendAllSubscriptions(),this._processMessageQueue(),this._notifyWidgets("connection",{status:"connected"})}catch(t){console.error("[WebSocketManager] Error in handleOpen:",t)}}handleMessage(t){try{let e;this.lastMessageReceived=Date.now(),this.metrics.messagesReceived++;try{e=JSON.parse(t.data)}catch(n){const i=t.data.toString();if(this.config.debug&&console.log("[WebSocketManager] Received plain text message:",i),i.toLowerCase().includes("session revoked")||i.toLowerCase().includes("please relogin")||i.toLowerCase().includes("session expired")||i.toLowerCase().includes("unauthorized")||i.toLowerCase().includes("authentication failed"))return this.config.debug&&console.log("[WebSocketManager] Session revoked detected, attempting relogin..."),void this._handleSessionRevoked(i);const s=this._getTargetTypeFromErrorMessage(i);e=i.toLowerCase().includes("no night session")||i.toLowerCase().includes("no data")?{type:"error",message:i,error:i,noData:!0,targetType:s}:{type:"error",message:i,error:i,targetType:s}}this.config.debug&&console.log("[WebSocketManager] Processed message:",e),this._routeMessage(e)}catch(t){console.error("[WebSocketManager] Error handling message:",t),this._notifyWidgets("error",{error:"Failed to process message",details:t.message})}}handleClose(t){const e="connected"===this.connectionState;this.connectionState="disconnected",this.activeSubscriptions.clear(),this._stopActivityMonitoring(),this.config.debug&&console.log(`[WebSocketManager] Connection closed: ${t.code} ${t.reason}`),e&&this._notifyWidgets("connection",{status:"disconnected",code:t.code,reason:t.reason}),!this.isManualDisconnect&&this.subscriptions.size>0?(this.metrics.totalReconnects++,this._scheduleReconnect()):this.isManualDisconnect&&(this.config.debug&&console.log("[WebSocketManager] Manual disconnect - skipping reconnection"),this.isManualDisconnect=!1)}handleError(t){const e=this.connection?this.connection.readyState:"no connection";console.error("[WebSocketManager] WebSocket error:",{readyState:e,stateName:{0:"CONNECTING",1:"OPEN",2:"CLOSING",3:"CLOSED"}[e]||"UNKNOWN",url:this.connection?.url,error:t}),this.connection&&(3===this.connection.readyState?(console.log("[WebSocketManager] Connection closed due to error"),this.connectionState="disconnected",!this.isManualDisconnect&&this.subscriptions.size>0?(console.log("[WebSocketManager] Attempting reconnection after error..."),this._scheduleReconnect()):this.isManualDisconnect&&console.log("[WebSocketManager] Manual disconnect - skipping reconnection after error")):2===this.connection.readyState&&console.log("[WebSocketManager] Connection closing...")),this._notifyWidgets("connection",{status:"error",error:"WebSocket connection error",readyState:e,details:"Connection failed or was closed unexpectedly"}),this.connectionPromise&&(this.connectionPromise.reject(new Error("WebSocket connection failed")),this.connectionPromise=null)}_sendAllSubscriptions(){try{const t=new Set;this.subscriptions.forEach((e=>{e&&e.types&&e.types.forEach((e=>t.add(e)))})),this._sendSubscriptions([...t])}catch(t){console.error("[WebSocketManager] Error sending subscriptions:",t)}}_sendSubscriptions(t){t.forEach((t=>{if("queryoptionchain"===t)this._sendOptionChainSubscriptions();else{this._getSymbolsForType(t).forEach((e=>{const n=`${t}:${e}`;if(this.activeSubscriptions.has(n))this.config.debug&&console.log(`[WebSocketManager] Subscription ${n} already active, skipping`);else{let i;i="queryoptionl1"===t?{type:t,optionName:e}:{type:t,symbol:e},this.config.debug&&console.log(`[WebSocketManager] Sending subscription for ${n}`),this.send(i)&&this.activeSubscriptions.add(n)}}))}}))}_sendOptionChainSubscriptions(){this.subscriptions.forEach(((t,e)=>{if(t.types.has("queryoptionchain")&&t.symbol&&t.additionalParams?.date){const e=`queryoptionchain:${t.symbol}:${t.additionalParams.date}`;if(this.activeSubscriptions.has(e))this.config.debug&&console.log(`[WebSocketManager] Option chain subscription ${e} already active, skipping`);else{const n={type:"queryoptionchain",underlying:t.symbol,date:t.additionalParams.date};this.config.debug&&console.log(`[WebSocketManager] Sending option chain subscription for ${e}`),this.send(n)&&this.activeSubscriptions.add(e)}}}))}_getSymbolsForType(t){const e=new Set;return this.subscriptions.forEach(((n,i)=>{n.types.has(t)&&n.symbol&&e.add(n.symbol)})),[...e]}_routeMessage(t){if(Array.isArray(t)&&0===t.length)return void(this.config.debug&&console.log("[WebSocketManager] Received empty array, ignoring"));if(this._cacheMessage(t),t.targetType){const e=this.typeSubscriptions.get(t.targetType);if(e&&e.size>0)return this.config.debug&&console.log(`[WebSocketManager] Routing ${t.targetType} error to specific widgets:`,[...e]),void e.forEach((e=>{const n=this.subscriptions.get(e);if(n)try{n.callback({event:"data",data:t,widgetId:e})}catch(t){console.error(`[WebSocketManager] Error in widget ${e} callback:`,t)}}))}const e=this._getRelevantWidgets(t);if(this.config.debug&&e.size>0&&console.log(`[WebSocketManager] Routing message to ${e.size} relevant widgets`),0===e.size&&this.subscriptions.size>0)return this.config.debug&&console.log("[WebSocketManager] No specific routing found, broadcasting to all widgets"),void this.subscriptions.forEach(((e,n)=>{try{e.callback({event:"data",data:t,widgetId:n})}catch(t){console.error(`[WebSocketManager] Error in widget ${n} callback:`,t)}}));e.forEach((e=>{const n=this.subscriptions.get(e);if(n)try{n.callback({event:"data",data:t,widgetId:e})}catch(t){console.error(`[WebSocketManager] Error in widget ${e} callback:`,t)}}))}_cacheMessage(t){try{const e=this._extractSymbol(t),n=this._extractMessageType(t);if(n&&e){const i=`${n}:${e}`;this.lastMessageCache.set(i,t),this.config.debug&&console.log(`[WebSocketManager] Cached message for ${i}`)}if(Array.isArray(t)&&t.length>0&&t[0].Symbol){const e=t[0].Symbol,n=this._extractMessageType(t);if(n&&e){const i=`${n}:${e}`;this.lastMessageCache.set(i,t),this.config.debug&&console.log(`[WebSocketManager] Cached array message for ${i}`)}}t.Data&&Array.isArray(t.Data)&&t.Data.forEach((e=>{if(e.Symbol){const n=`queryl1:${e.Symbol}`;this.lastMessageCache.set(n,t),this.config.debug&&console.log(`[WebSocketManager] Cached data item for ${n}`)}}))}catch(t){console.error("[WebSocketManager] Error caching message:",t)}}_getRelevantWidgets(t){const e=new Set;return this._addRelevantWidgetsForItem(t,e),e}_addRelevantWidgetsForItem(t,e){t.Data&&Array.isArray(t.Data)?t.Data.forEach((t=>{this._processDataItem(t,e)})):t&&t[0]&&void 0!==t[0].Strike&&t[0].Expire&&!t[0].underlyingSymbol?this._processOptionChainData(t,e):this._processDataItem(t,e)}_processOptionChainData(t,e){if(!t||0===t.length)return;const n=t[0],i=this._extractUnderlyingFromOption(n.Symbol),s=n.Expire;if(this.config.debug&&console.log("[WebSocketManager] Processing option chain data:",{underlyingSymbol:i,expireDate:s,contractCount:t.length}),i){const t=this.symbolSubscriptions.get(i);t&&t.forEach((t=>{const n=this.subscriptions.get(t);if(n&&n.types.has("queryoptionchain")){let o=!0;if(n.additionalParams?.date&&s){o=this._normalizeDate(n.additionalParams.date)===this._normalizeDate(s)}o&&(e.add(t),this.config.debug&&console.log(`[WebSocketManager] Routing option chain data for ${i} (${s}) to widget ${t}`))}}))}}_processDataItem(t,e){const n=this._extractSymbol(t),i=this._extractMessageType(t);if(this.config.debug&&console.log("[WebSocketManager] Processing data item:",{symbol:n,messageType:i,dataItem:t}),n){const t=this.symbolSubscriptions.get(n);t&&t.forEach((t=>{const s=this.subscriptions.get(t);if(s){this._isDataTypeCompatible(i,s.types)&&(e.add(t),this.config.debug&&console.log(`[WebSocketManager] Routing ${i} data for ${n} to widget ${t}`))}}))}if(i){const t=this.typeSubscriptions.get(i);t&&t.forEach((t=>{const s=this.subscriptions.get(t);!s||s.symbol&&s.symbol!==n||(e.add(t),this.config.debug&&console.log(`[WebSocketManager] Routing ${i} data to type-subscribed widget ${t}`))}))}}_isDataTypeCompatible(t,e){if(e.has(t))return!0;const n={queryoptionchain:["queryoptionchain","optionchain","option-chain"],queryl1:["queryl1","stock","equity"],queryoptionl1:["queryoptionl1","option","options"],queryblueoceanl1:["queryblueoceanl1","blueoceanl1","blueocean"],querybrucel1:["querybrucel1","brucel1","bruce"]};for(const i of e){if((n[i]||[i]).includes(t))return!0}return!1}_normalizeDate(t){if(!t)return null;if(t.includes("/")){const[e,n,i]=t.split("/");return`${i}-${e.padStart(2,"0")}-${n.padStart(2,"0")}`}return t}_extractSymbol(t){return Array.isArray(t)&&t[0]&&t[0].Source&&null!==t[0].Symbol&&(t[0].Source.toLowerCase().includes("blueocean")||t[0].Source.toLowerCase().includes("bruce"))&&(t=t[0]),t.Symbol&&!t.Underlying&&t.Strike?this._extractUnderlyingFromOption(t.Symbol):t.Symbol||t.RootSymbol||t.Underlying||t.symbol||t.rootSymbol||t.underlying}_isOptionSymbol(t){return/^[A-Z]+\d{6}[CP]\d+$/.test(t)}_extractUnderlyingFromOption(t){const e=t.match(/^([A-Z]+)\d{6}[CP]\d+$/),n=e?e[1]:t;return{SPXW:"SPX$",SPX:"SPX$",NDXP:"NDX$",RUT:"RUT$",VIX:"VIX$",DJX:"DJX$"}[n]||n}_extractMessageType(t){return t.type?t.type:t[0]&&t[0].Source&&(t[0].Source.toLowerCase().includes("blueocean")||t[0].Source.toLowerCase().includes("blueocean-d")||t[0].Source.toLowerCase().includes("bruce"))?t[0].Source.toLowerCase().includes("bruce")?"querybrucel1":"queryblueoceanl1":void 0!==t.Strike||void 0!==t.Expire||t.Symbol&&this._isOptionSymbol(t.Symbol)?"queryoptionl1":void 0!==t.BidPx||void 0!==t.AskPx?"queryl1":null}_notifyWidgets(t,e){try{this.subscriptions.forEach(((n,i)=>{try{n&&n.callback&&n.callback({event:t,data:e,widgetId:i})}catch(t){console.error(`[WebSocketManager] Error notifying widget ${i}:`,t)}}))}catch(t){console.error("[WebSocketManager] Error in _notifyWidgets:",t)}}_processMessageQueue(){if(!this.messageQueue||!Array.isArray(this.messageQueue))return this.config.debug&&console.warn("[WebSocketManager] messageQueue not properly initialized, creating new array"),void(this.messageQueue=[]);for(this.config.debug&&this.messageQueue.length>0&&console.log(`[WebSocketManager] Processing ${this.messageQueue.length} queued messages`);this.messageQueue.length>0;){const t=this.messageQueue.shift();t&&this.send(t)}}_cleanupUnusedSubscriptions(){const t=new Set;this.subscriptions.forEach((e=>{e.types.forEach((e=>t.add(e)))})),this.activeSubscriptions.forEach((e=>{const[n]=e.split(":");t.has(n)||this.activeSubscriptions.delete(e)}))}_scheduleReconnect(){if(!this.isOnline)return this.config.debug&&console.log("[WebSocketManager] Network offline, waiting for network to return..."),void this._notifyWidgets("connection",{status:"offline",reason:"Network offline - will reconnect when network returns"});if("open"===this.circuitBreaker.state){const t=Date.now()-this.circuitBreaker.lastFailureTime,e=this.circuitBreaker.timeout-t;return console.warn(`[WebSocketManager] Circuit breaker OPEN, will retry in ${Math.round(e/1e3)}s`),void this._notifyWidgets("connection",{status:"circuit_open",reason:"Too many connection failures - circuit breaker active",retryIn:Math.round(e/1e3)})}if(this.reconnectAttempts>=this.config.reconnectOptions.maxAttempts)return console.error("[WebSocketManager] Max reconnection attempts reached"),this.metrics.failedConnections++,void this._notifyWidgets("connection",{status:"failed",error:"Max reconnection attempts reached",maxAttempts:this.config.reconnectOptions.maxAttempts,canRetry:!0});this.connectionState="reconnecting",this.reconnectAttempts++;const t=this.config.reconnectOptions.initialDelay*Math.pow(this.config.reconnectOptions.backoff,this.reconnectAttempts-1),e=Math.min(t,this.config.reconnectOptions.maxDelay),n=e*this.config.reconnectOptions.jitter,i=(2*Math.random()-1)*n,s=Math.max(0,e+i);console.log(`[WebSocketManager] Scheduling reconnect attempt ${this.reconnectAttempts}/${this.config.reconnectOptions.maxAttempts} in ${Math.round(s)}ms`),this._notifyWidgets("connection",{status:"reconnecting",attempt:this.reconnectAttempts,maxAttempts:this.config.reconnectOptions.maxAttempts,delay:Math.round(s),estimatedTime:new Date(Date.now()+s).toISOString()}),this.reconnectTimer=setTimeout((()=>{this._connect()}),s)}_resetState(){this.connectionState="disconnected",this.reconnectAttempts=0,this.connectionPromise=null,this.subscriptions&&this.subscriptions instanceof Map||(this.subscriptions=new Map),this.activeSubscriptions&&this.activeSubscriptions instanceof Set||(this.activeSubscriptions=new Set),this.messageQueue&&Array.isArray(this.messageQueue)||(this.messageQueue=[]),this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null)}_getTargetTypeFromErrorMessage(t){const e=t.toLowerCase();return e.includes("night session")||e.includes("blue ocean")||e.includes("bruce")||e.includes("blueocean")?e[0].toLowerCase().includes("bruce")?"querybrucel1":"queryblueoceanl1":e.includes("option chain")||e.includes("expiration date")?"queryoptionchain":e.includes("option")||e.includes("strike")||e.includes("expiration")?"queryoptionl1":e.includes("stock")||e.includes("equity")||e.includes("bid")||e.includes("ask")?"queryl1":null}async _handleSessionRevoked(t){if(this.isReloginInProgress)this.config.debug&&console.log("[WebSocketManager] Relogin already in progress, skipping...");else{this.isReloginInProgress=!0;try{if(this._notifyWidgets("session_revoked",{message:t,status:"attempting_relogin"}),this.config.debug&&console.log("[WebSocketManager] Session revoked, attempting relogin..."),this._closeConnection(),!this.reloginCallback||"function"!=typeof this.reloginCallback)throw new Error("No relogin callback provided");{const t=await this.reloginCallback();if(!(t&&"string"==typeof t&&t.length>0))throw new Error("Relogin failed: Invalid token received");this.updateToken(t),this.config.debug&&console.log("[WebSocketManager] Relogin successful, reconnecting..."),await this._reconnectAndResubscribe()}}catch(e){console.error("[WebSocketManager] Relogin failed:",e),this._notifyWidgets("session_revoked",{message:t,status:"relogin_failed",error:e.message}),this.connectionState="failed"}finally{this.isReloginInProgress=!1}}}async _reconnectAndResubscribe(){try{this.connectionState="disconnected",this.reconnectAttempts=0,this.activeSubscriptions.clear(),await this.connect(),this.config.debug&&console.log("[WebSocketManager] Reconnected successfully after relogin"),this._notifyWidgets("session_revoked",{status:"relogin_successful"})}catch(t){throw console.error("[WebSocketManager] Failed to reconnect after relogin:",t),t}}_closeConnection(){this.connection&&(this.connection.removeEventListener("open",this.handleOpen),this.connection.removeEventListener("message",this.handleMessage),this.connection.removeEventListener("close",this.handleClose),this.connection.removeEventListener("error",this.handleError),this.connection.readyState===WebSocket.OPEN&&this.connection.close(),this.connection=null),this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.connectionState="disconnected"}setReloginCallback(t){this.reloginCallback=t,this.config.debug&&console.log("[WebSocketManager] Relogin callback set")}updateToken(t){this.config.token=t,this.apiService=new Iu(this.config.token,this.config.apiBaseUrl),this.config.debug&&console.log("[WebSocketManager] Token updated")}getApiService(){return this.apiService}async manualReconnect(){this.config.debug&&console.log("[WebSocketManager] Manual reconnect initiated"),this.reconnectAttempts=0,this.connectionState="disconnected",this.isManualDisconnect=!1,this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this._notifyWidgets("connection",{status:"reconnecting",attempt:1,maxAttempts:this.config.reconnectOptions.maxAttempts,manual:!0});try{return await this.connect(),!0}catch(t){return console.error("[WebSocketManager] Manual reconnect failed:",t),!1}}_initNetworkMonitoring(){"undefined"!=typeof window&&(this.onlineHandler=()=>{this.isOnline=!0,this.config.debug&&console.log("[WebSocketManager] Network online detected"),"disconnected"===this.connectionState&&this.subscriptions.size>0&&(console.log("[WebSocketManager] Network restored, attempting reconnection..."),this.reconnectAttempts=0,this._scheduleReconnect())},this.offlineHandler=()=>{this.isOnline=!1,this.config.debug&&console.log("[WebSocketManager] Network offline detected"),this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this._notifyWidgets("connection",{status:"offline",reason:"Network offline"})},window.addEventListener("online",this.onlineHandler),window.addEventListener("offline",this.offlineHandler))}_cleanupNetworkMonitoring(){"undefined"!=typeof window&&(this.onlineHandler&&(window.removeEventListener("online",this.onlineHandler),this.onlineHandler=null),this.offlineHandler&&(window.removeEventListener("offline",this.offlineHandler),this.offlineHandler=null))}_startActivityMonitoring(){this.config.enableActivityMonitoring?(this._stopActivityMonitoring(),this.activityCheckInterval=setInterval((()=>{if("connected"!==this.connectionState)return;const t=Date.now()-this.lastMessageReceived;t>this.config.timeouts.inactivity?(console.warn(`[WebSocketManager] No messages received in ${this.config.timeouts.inactivity}ms, connection may be dead`),this.connection&&this.connection.close()):this.config.debug&&t>3e4&&console.log(`[WebSocketManager] Last message: ${Math.round(t/1e3)}s ago`)}),15e3)):this.config.debug&&console.log("[WebSocketManager] Activity monitoring disabled")}_stopActivityMonitoring(){this.activityCheckInterval&&(clearInterval(this.activityCheckInterval),this.activityCheckInterval=null)}_updateCircuitBreaker(t){t?(this.circuitBreaker.failureCount=0,this.circuitBreaker.state="closed",this.circuitBreaker.resetTimer&&(clearTimeout(this.circuitBreaker.resetTimer),this.circuitBreaker.resetTimer=null),this.config.debug&&console.log("[WebSocketManager] Circuit breaker CLOSED - connection healthy")):(this.circuitBreaker.failureCount++,this.circuitBreaker.lastFailureTime=Date.now(),this.config.debug&&console.log(`[WebSocketManager] Circuit breaker failure ${this.circuitBreaker.failureCount}/${this.circuitBreaker.failureThreshold}`),this.circuitBreaker.failureCount>=this.circuitBreaker.failureThreshold&&(this.circuitBreaker.state="open",console.warn("[WebSocketManager] Circuit breaker OPEN - too many failures"),this.circuitBreaker.resetTimer=setTimeout((()=>{this.circuitBreaker.state="half-open",this.circuitBreaker.failureCount=0,console.log("[WebSocketManager] Circuit breaker HALF-OPEN - will attempt one reconnection"),this.subscriptions.size>0&&"connected"!==this.connectionState&&(this.reconnectAttempts=0,this._scheduleReconnect())}),this.circuitBreaker.timeout)))}getConnectionMetrics(){const t=this._calculateConnectionQuality();return{state:this.connectionState,quality:t,isOnline:this.isOnline,circuitBreakerState:this.circuitBreaker.state,reconnectAttempts:this.reconnectAttempts,maxReconnectAttempts:this.config.reconnectOptions.maxAttempts,successfulConnections:this.metrics.successfulConnections,failedConnections:this.metrics.failedConnections,totalReconnects:this.metrics.totalReconnects,avgConnectionTime:Math.round(this.metrics.avgConnectionTime),lastSuccessfulConnection:this.metrics.lastSuccessfulConnection?new Date(this.metrics.lastSuccessfulConnection).toISOString():null,messagesReceived:this.metrics.messagesReceived,messagesSent:this.metrics.messagesSent,activeSubscriptions:this.subscriptions.size,lastMessageReceived:this.lastMessageReceived?`${Math.round((Date.now()-this.lastMessageReceived)/1e3)}s ago`:"never"}}_calculateConnectionQuality(){if("connected"!==this.connectionState)return"poor";const t=this.lastMessageReceived?Date.now()-this.lastMessageReceived:1/0;return t<3e4&&this.metrics.avgConnectionTime<2e3?"excellent":t<6e4&&this.metrics.avgConnectionTime<5e3?"good":t<this.config.timeouts.inactivity?"fair":"poor"}enableMetricsLogging(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:3e4;this.metricsInterval&&clearInterval(this.metricsInterval),this.metricsInterval=setInterval((()=>{console.log("[WebSocketManager] Metrics:",this.getConnectionMetrics())}),t),console.log("[WebSocketManager] Metrics logging enabled (every "+t/1e3+"s)")}disableMetricsLogging(){this.metricsInterval&&(clearInterval(this.metricsInterval),this.metricsInterval=null,console.log("[WebSocketManager] Metrics logging disabled"))}disconnect(){this.isManualDisconnect=!0,this._stopActivityMonitoring(),this._cleanupNetworkMonitoring(),this.circuitBreaker.resetTimer&&(clearTimeout(this.circuitBreaker.resetTimer),this.circuitBreaker.resetTimer=null),this.disableMetricsLogging(),this._closeConnection(),this._notifyWidgets("connection",{status:"disconnected",manual:!0}),this.config.debug&&console.log("[WebSocketManager] Disconnected and cleaned up")}}class zu{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.config={apiBaseUrl:t.apiBaseUrl||"https://mdas-api-dev.viewtrade.dev",loginEndpoint:t.loginEndpoint||"/api/user/login",refreshEndpoint:t.refreshEndpoint||"/api/user/refresh",refreshBuffer:t.refreshBuffer||300,maxRetries:t.maxRetries||3,debug:t.debug||!1},this.credentials=null,this.currentToken=null,this.tokenExpiry=null,this.refreshTimer=null,this.isAuthenticating=!1,this.retryCount=0,this.authenticationPromise=null,this.listeners=new Map,this.config.debug&&console.log("[AuthManager] Initialized with config:",{...this.config,loginEndpoint:this.config.loginEndpoint})}setCredentials(t,e){this.credentials={user_name:t,password:e},this.config.debug&&console.log("[AuthManager] Credentials set for user:",t)}async authenticate(){if(this.isAuthenticating&&this.authenticationPromise)return this.config.debug&&console.log("[AuthManager] Authentication already in progress, waiting..."),await this.authenticationPromise;if(!this.credentials)throw new Error("No credentials provided. Call setCredentials() first.");this.isAuthenticating=!0,this.authenticationPromise=this._performAuthentication();try{return await this.authenticationPromise}finally{this.isAuthenticating=!1,this.authenticationPromise=null}}async getValidToken(){return this.currentToken?this._isTokenNearExpiry()?(this.config.debug&&console.log("[AuthManager] Token near expiry, refreshing..."),await this.refreshToken()):this.currentToken:await this.authenticate()}async refreshToken(){if(this.isAuthenticating)return this.currentToken;this.isAuthenticating=!0;try{const t=await this._performRefresh();return this._handleAuthSuccess(t),this.currentToken}catch(t){return this.config.debug&&console.log("[AuthManager] Token refresh failed, attempting re-login"),await this.authenticate()}finally{this.isAuthenticating=!1}}async handleAuthError(t){if(this.config.debug&&console.log("[AuthManager] Handling auth error:",t),this.retryCount>=this.config.maxRetries){const t=new Error(`Authentication failed after ${this.config.maxRetries} attempts`);throw this._notifyListeners("auth_failed",{error:t}),this.retryCount=0,t}this.retryCount++,this._clearToken();try{const t=await this.authenticate();return this.retryCount=0,this._notifyListeners("auth_recovered",{token:t}),t}catch(t){throw this._notifyListeners("auth_retry_failed",{error:t,attempt:this.retryCount}),t}}addEventListener(t,e){this.listeners.has(t)||this.listeners.set(t,new Set),this.listeners.get(t).add(e)}removeEventListener(t,e){this.listeners.has(t)&&this.listeners.get(t).delete(e)}destroy(){this._clearToken(),this.credentials=null,this.listeners.clear(),this.config.debug&&console.log("[AuthManager] Destroyed")}async _performLogin(){const t=`${this.config.apiBaseUrl}${this.config.loginEndpoint}`;this.config.debug&&console.log("[AuthManager] Attempting login to:",t);const e=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({user_name:this.credentials.user_name,password:this.credentials.password})});if(!e.ok){const t=await e.json().catch((()=>({})));throw new Error(t.message||`Login failed: ${e.status} ${e.statusText}`)}const n=await e.json(),i=n.access_token,s=n.refresh_token,o=n.access_expiration,a=n.user_id;if(!i)throw console.error("[AuthManager] Login response missing token:",n),new Error("No token received from login response");let r=null;if(o)try{if(r=new Date(o),isNaN(r.getTime()))throw new Error("Invalid expiration date format")}catch(t){console.warn("[AuthManager] Could not parse expiration date:",n.expiration),r=new Date(Date.now()+36e5)}else r=new Date(Date.now()+18e6);return this.config.debug&&console.log("[AuthManager] Login successful:",{tokenLength:i.length,expiresAt:r.toISOString(),timeUntilExpiry:Math.round((r.getTime()-Date.now())/1e3/60)+" minutes"}),{token:i,refreshToken:s,expirationDate:r,user_id:a}}async _performRefresh(){return this.config.debug&&console.log("[AuthManager] No refresh endpoint available, performing full re-authentication"),await this._performLogin()}async _performAuthentication(){try{const t=await this._performLogin();return this._handleAuthSuccess(t),this.currentToken}catch(t){throw this._handleAuthError(t),t}}_handleAuthSuccess(t){this.currentToken=t.token,t.expirationDate&&(this.tokenExpiry=t.expirationDate),this.retryCount=0,this._scheduleTokenRefresh(),this.config.debug&&console.log("[AuthManager] Authentication successful, token expires:",this.tokenExpiry),this._notifyListeners("auth_success",{token:this.currentToken,expiresAt:this.tokenExpiry})}_handleAuthError(t){this.config.debug&&console.error("[AuthManager] Authentication failed:",t.message),this._notifyListeners("auth_error",{error:t})}_isTokenNearExpiry(){if(!this.tokenExpiry)return!0;const t=new Date,e=1e3*this.config.refreshBuffer;return t>=new Date(this.tokenExpiry.getTime()-e)}_scheduleTokenRefresh(){if(this.refreshTimer&&clearTimeout(this.refreshTimer),!this.tokenExpiry)return;const t=new Date,e=1e3*this.config.refreshBuffer,n=new Date(this.tokenExpiry.getTime()-e),i=Math.max(0,n.getTime()-t.getTime());this.config.debug&&console.log(`[AuthManager] Scheduling token refresh in ${i/1e3} seconds`),this.refreshTimer=setTimeout((async()=>{try{await this.refreshToken()}catch(t){console.error("[AuthManager] Scheduled refresh failed:",t)}}),i)}_clearToken(){this.currentToken=null,this.tokenExpiry=null,this.refreshTimer&&(clearTimeout(this.refreshTimer),this.refreshTimer=null)}_notifyListeners(t,e){this.listeners.has(t)&&this.listeners.get(t).forEach((n=>{try{n(e)}catch(e){console.error(`[AuthManager] Error in ${t} listener:`,e)}}))}}class Wu{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.config={username:t.username,password:t.password,token:t.token,authCallback:t.authCallback,wsUrl:t.wsUrl||"https://mdas-api-dev.viewtrade.dev/wss/sub",apiBaseUrl:t.apiBaseUrl||"https://mdas-api-dev.viewtrade.dev",debug:t.debug||!1,maxConnections:t.maxConnections||1,autoAuth:!1!==t.autoAuth,...t},this.stateManager=new e,this.widgetManager=new Lu(this.stateManager),this.wsManager=null,this.authManager=null,this.isInitialized=!1,this._validateAuthConfig()}async initialize(){try{return this.isInitialized?(console.warn("SDK already initialized"),this):(this.config.debug&&console.log("Initializing MDAS SDK with config:",{hasCredentials:!(!this.config.username||!this.config.password),hasToken:!!this.config.token,hasAuthCallback:!!this.config.authCallback,wsUrl:this.config.wsUrl,autoAuth:this.config.autoAuth}),this.config.username&&this.config.password&&await this._initializeBuiltInAuth(),this.isInitialized=!0,this)}catch(t){throw console.error("Failed to initialize SDK:",t),t}}async createWidget(t,e){let n,i,s,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!this.isInitialized)throw new Error("SDK not initialized. Call initialize() first.");if(this.wsManager||await this._initializeWebSocketManager(),"object"!=typeof t||null===t||Array.isArray(t))n=t,i=e,s=o||{};else if(n=t.type,s=t.options||{},t.containerEl&&1===t.containerEl.nodeType)i=t.containerEl;else if(t.containerId){const e=String(t.containerId).replace(/^#/,"");let n="undefined"!=typeof document?document.getElementById(e):null;n||"undefined"==typeof document||(n=document.createElement("div"),n.id=e,document.body.appendChild(n)),i=n}else{const t="mdas-widget";let e="undefined"!=typeof document?document.getElementById(t):null;e||"undefined"==typeof document||(e=document.createElement("div"),e.id=t,document.body.appendChild(e)),i=e}const a={...s,wsManager:this.wsManager,debug:this.config.debug};return a.reconnect=async()=>await this.manualReconnect(),this.widgetManager.createWidget(n,i,a)}async login(t,e){this.authManager||(this.authManager=new zu({apiBaseUrl:this.config.apiBaseUrl,debug:this.config.debug})),this.authManager.setCredentials(t,e);const n=await this.authManager.authenticate();return this.wsManager&&await this._reconnectWithNewToken(n),n}async destroy(){this.authManager&&(this.authManager.destroy(),this.authManager=null),this.wsManager&&(this.wsManager.disconnect(),this.wsManager=null),this.widgetManager&&this.widgetManager.destroy(),this.isInitialized=!1}getConnectionState(){return this.wsManager?this.wsManager.getConnectionState():"disconnected"}getActiveWidgetCount(){return this.widgetManager?this.widgetManager.getWidgetCount():0}getSubscriptionCount(){return this.wsManager?this.wsManager.getSubscriptionCount():0}isAuthenticated(){return this.authManager?!!this.authManager.currentToken:!!this.config.token}disconnect(){this.wsManager&&(this.wsManager.disconnect(),this.config.debug&&console.log("[MdasSDK] WebSocket disconnected"))}async connect(){if(this.wsManager)try{await this.wsManager.connect(),this.config.debug&&console.log("[MdasSDK] WebSocket reconnected")}catch(t){throw console.error("[MdasSDK] Failed to reconnect:",t),t}else this.config.debug&&console.log("[MdasSDK] No WebSocketManager exists, initializing..."),await this._initializeWebSocketManager()}isConnected(){return!!this.wsManager&&"connected"===this.wsManager.getConnectionState()}async manualReconnect(){return!!this.wsManager&&(this.config.debug&&console.log("[MdasSDK] Manual reconnect requested"),await this.wsManager.manualReconnect())}_validateAuthConfig(){const t=this.config.username&&this.config.password,e=this.config.token,n=this.config.authCallback;if(!t&&!e&&!n)throw new Error("Authentication required: Provide username/password, token, or authCallback");[t,e,n].filter(Boolean).length>1&&console.warn("Multiple auth methods provided. Priority: credentials > token > authCallback")}async _initializeBuiltInAuth(){this.authManager=new zu({apiBaseUrl:this.config.apiBaseUrl,debug:this.config.debug}),this.authManager.setCredentials(this.config.username,this.config.password),this.authManager.addEventListener("auth_error",(t=>{console.error("Authentication error:",t.error)})),this.authManager.addEventListener("auth_success",(t=>{this.config.debug&&console.log("Authentication successful")})),this.authManager.addEventListener("auth_failed",(t=>{console.error("Authentication failed after retries:",t.error)})),this.config.autoAuth&&await this.authManager.authenticate()}async _initializeWebSocketManager(){const t=await this._getToken();this.wsManager=new Ou({debug:this.config.debug,token:t,baseUrl:this.config.wsUrl,apiBaseUrl:this.config.apiBaseUrl,maxConnections:this.config.maxConnections,reconnectOptions:{maxAttempts:5,delay:1e3,backoff:2},reloginCallback:async()=>{try{if(this.authManager){this.config.debug&&console.log("[MdasSDK] Attempting relogin after session revoked...");const t=await this.authManager.authenticate();return this.config.debug&&console.log("[MdasSDK] Relogin successful, new token obtained"),t}return this.config.authCallback?await this.config.authCallback():(console.error("[MdasSDK] No authentication method available for relogin"),null)}catch(t){return console.error("[MdasSDK] Relogin failed:",t),null}}}),this.wsManager.addEventListener=this.wsManager.addEventListener||(()=>{});try{await this.wsManager.connect(),this.config.debug&&console.log("WebSocketManager connected successfully")}catch(t){t.message.includes("401")||t.message.includes("403")?await this._handleWebSocketAuthError(t):console.error("Failed to connect WebSocketManager:",t)}}async _getToken(){if(this.authManager)return await this.authManager.getValidToken();if(this.config.authCallback){const t=await this.config.authCallback();return t.token||t}return this.config.token}async _handleWebSocketAuthError(t){if(!this.authManager)throw t;try{const e=await this.authManager.handleAuthError(t);await this._reconnectWithNewToken(e)}catch(t){throw console.error("Failed to recover from auth error:",t),t}}async _reconnectWithNewToken(t){this.wsManager&&(this.wsManager.updateToken(t),this.wsManager.disconnect(),await this.wsManager.connect())}}"undefined"!=typeof window&&(window.MdasSDK=Wu,window.MdasSDK.MdasSDK=Wu,window.MdasSDK.MarketDataModel=i,window.MdasSDK.NightSessionModel=y,window.MdasSDK.OptionsModel=v,window.MdasSDK.IntradayChartModel=T,window.MdasSDK.CombinedMarketWidget=D,window.MdasSDK.IntradayChartWidget=Au),t.CombinedMarketWidget=D,t.IntradayChartModel=T,t.IntradayChartWidget=Au,t.MarketDataModel=i,t.MdasSDK=Wu,t.NightSessionModel=y,t.OptionChainWidget=M,t.OptionsModel=v,t.default=Wu,Object.defineProperty(t,"__esModule",{value:!0})}));//# sourceMappingURL=mdas-sdk.min.js.map
|