openalgo-charts
Version:
From-scratch, dependency-free canvas charting engine for OpenAlgo: professional-grade interactive rendering, advanced on-chart trading, and a one-call widget tier that adds the toolbar, drawing rail, dialogs and shortcuts.
3 lines • 536 kB
JavaScript
import{tryResolveInterval as e,registerInterval as t,resolveInterval as o,intervalParts as n,readChartSettings as i,filterLinkAppearance as a,applyChartSettings as r,DEFAULT_PRICE_SCALE_OPTIONS as s,normalizeCombo as l,isReservedCombo as c,INDICATOR_SOURCES as d,registeredIntervals as u,parseSessionSpec as p,IndicatorInputError as h,formatZonedTimeSeconds as m,formatZonedTime as g,zoneOffsetSeconds as f,marketStatusAt as b,utcSecondsToZonedParts as v,formatZonedCrosshairLabel as w,registeredChartTypes as _,registeredSeriesTransforms as y,isReplaying as x,isTimeBucketed as k,startOfZonedDay as C,nextBucketStart as S,bucketStartOf as A,dataVariantKey as L,normalizeDataVariant as O,isKnownInterval as $,registeredIndicators as E,getChartType as T,getSeriesTransform as P,exportChartDataCsv as j,zonedWallClockToUtcSeconds as M,getIndicator as I,indicatorStyleInputs as D,indicatorDefaults as z,chartSettingsSchema as N,registeredBarConditions as R,alertSettingsSchema as F,getBarCondition as W,PRICE_SCALE_MODES as B,checkTradingCapability as q,DEFAULT_TIMEZONE as U,attachSessionShading as H,lightTheme as K,darkTheme as G,DataLoadingController as V,createChart as J,AlertController as Y,ChartObjects as Z,publishDataContext as Q,VERSION as X,ShortcutManager as ee,createLinkGroup as te}from"./openalgo-charts.mjs";import{hasDrawingTool as oe,getDrawingTool as ne,chromeIconSvg as ie,DRAWING_STATE_VERSION as ae,CHROME_ICON_STROKE as re,chromeIcon as se,DRAWING_TOOL_ICONS as le,iconUse as ce,iconSprite as de,toolCursor as ue,drawingShortcuts as pe,keyToDrawingAction as he,memoryDrawingStore as me,migrateUnscopedDrawings as ge,InstrumentDrawings as fe,instrumentDrawingsKey as be,chartTypeIcon as ve,ICON_SIZE as we,ICON_STROKE as _e,CHROME_ICON_SIZE as ye,readDrawingSettings as xe,drawingSettingsSchema as ke,applyDrawingSettings as Ce,DEFAULT_FIB as Se,gannLabel as Ae,formatRatio as Le,readDrawingSetting as Oe,cloneLevels as $e,LEVEL_NEUTRAL as Ee,levelColor as Te,studyInputTarget as Pe,registeredDrawingTools as je,LINE_STYLE_OPTIONS as Me,DrawingController as Ie,DrawingLinkGroup as De}from"./openalgo-charts.draw.mjs";const ze={seconds:"s",minutes:"m",hours:"h",days:"D",weeks:"W",months:"M",quarters:"Q",years:"Y"};function Ne(e,t){if(!Number.isInteger(e)||e<1||e>1e5||!Object.prototype.hasOwnProperty.call(ze,t))throw new Error("Enter a whole number between 1 and 100000");const o=ze[t];return Re(`${1===e&&/^[DWMQY]$/.test(o)?"":e}${o}`,!0)}function Re(n,i=!1){const a=n.trim(),r=/^(\d*)([smhDWMQY])$/.exec(a);if(i&&(!r||""===r[1]&&/[smh]/.test(r[2])))throw new Error("Use a positive clock or calendar interval");if(r){const o=""===r[1]?1:Number(r[1]);if(!Number.isInteger(o)||o<1||o>1e5)throw new Error("Interval is out of range");if(!e(a)&&/^[MQY]$/.test(r[2])){const e="M"===r[2]?"month":"Q"===r[2]?"quarter":"year";t({code:a,bucketing:{mode:"calendar",unit:e,count:o}})}}const s=o(a);if("interval"===s.bucketing.mode&&(!Number.isSafeInteger(s.bucketing.seconds)||s.bucketing.seconds<=0))throw new Error("Unknown interval");return a}function Fe(e){if("string"==typeof e&&/^(\d*)([MQY])$/.test(e))try{Re(e,!0)}catch{}}function We(e){const t=n(e);return t&&"other"!==t.unit?`${t.unit}:${t.multiplier}`:e}function Be(e,t){if(!Array.isArray(e)||e.length>128)throw new Error("Invalid timeframe preferences");const o=new Set,n=[];for(const i of e){if("string"!=typeof i||i.length>40)throw new Error("Invalid timeframe code");const e=Re(i,t),a=We(e);o.has(a)||(o.add(a),n.push(e))}return n}function qe(e){let t=Be([...e.defaults],!1),o=[],n=!1,i=!1;const a=new Set,r=()=>{try{const n=JSON.parse(e.storage?.getItem(e.key)??"null");if(n&&"object"==typeof n&&"version"in n&&1===n.version&&"custom"in n&&"favorites"in n){const e=Be(n.custom,!0),i=Be(n.favorites,!1);o=e,t=i}}catch{}};r();const s=()=>{if(!n){i=!0;try{e.storage?.setItem(e.key,JSON.stringify({version:1,favorites:t,custom:o}))}catch{}for(const e of a)e()}};return{favorites:()=>[...t],custom:()=>[...o],toggle(e){if(n)return;const o=Re(e),i=We(o),a=t.some(e=>We(e)===i);if(!a&&t.length>=128)throw new Error("Too many favorite intervals");t=a?t.filter(e=>We(e)!==i):[...t,o],s()},addCustom(e){if(n)return;const t=Re(e,!0),i=We(t);if(!o.some(e=>We(e)===i)){if(o.length>=128)throw new Error("Too many custom intervals");o.push(t),s()}},removeCustom(e){if(n)return;const i=We(e);o.some(e=>We(e)===i)&&(o=o.filter(e=>We(e)!==i),t=t.filter(e=>We(e)!==i),s())},subscribe:e=>(n||a.add(e),()=>{a.delete(e)}),reload(){if(!n&&!i){r();for(const e of a)e()}},destroy(){n=!0,a.clear()}}}function Ue(e,t){return qe({defaults:t,key:"timeframes",storage:{getItem:t=>{const o=e.get(t);return null===o?null:JSON.stringify(o)},setItem:(t,o)=>{e.set(t,JSON.parse(o))},removeItem:t=>e.remove(t)}})}const He=e=>String(e).replace(/[&<>"]/g,e=>"&"===e?"&":"<"===e?"<":">"===e?">":""");function Ke(e,t,o,n){const i=e.createElement(t);if(o&&(i.className=o),n)for(const[e,t]of Object.entries(n))i.setAttribute(e,t);return i}function Ge(e,t,o){const n=e.createElement("span");return n.className="oac-glyph oac-glyph--"+o,n.setAttribute("aria-hidden","true"),n.innerHTML=t,n}function Ve(e){const t=e;if(null==t)return!1;if(!0===t.isContentEditable)return!0;const o=(t.tagName??"").toUpperCase();if("TEXTAREA"===o||"SELECT"===o)return!0;if("INPUT"!==o)return!1;const n=(t.type??"text").toLowerCase();return!["checkbox","radio","button","submit","reset","range","color"].includes(n)}function Je(e){if(null===e)return!1;const t=e;if(!0===t.disabled)return!1;const o=t.getAttribute("tabindex");if(null!==o&&Number(o)<0)return!1;const n=t.tagName;if(!("BUTTON"===n||"INPUT"===n||"SELECT"===n||"TEXTAREA"===n||"A"===n&&t.hasAttribute("href"))&&null===o)return!1;for(let e=t;null!==e;e=e.parentElement)if(e.hidden)return!1;return!0}const Ye=e=>Array.from(e.querySelectorAll("*")).filter(Je);function Ze(e,t,o,n=6,i=8){let a=e.right+n,r="right";a+t.width>o.width-i&&e.left-n-t.width>=i&&(a=e.left-n-t.width,r="left"),a=Math.max(i,Math.min(a,o.width-t.width-i));return{left:a,top:Math.max(i,Math.min(e.top,o.height-t.height-i)),side:r}}function Qe(e,t,o,n=4,i=8){let a=e.bottom+n;return a+t.height>o.height-i&&e.top-n-t.height>=i&&(a=e.top-n-t.height),{left:Math.max(i,Math.min(e.left,o.width-t.width-i)),top:Math.max(i,Math.min(a,o.height-t.height-i))}}function Xe(e,t,o,n="right",i=8,a=6){let r,s;if("right"===n||"left"===n){const l="right"===n;r=l?e.right+i:e.left-i-t.width,(l?r+t.width>o.width-a:r<a)&&(r=l?e.left-i-t.width:e.right+i),s=e.top+e.height/2-t.height/2}else{const l="top"!==n;s=l?e.bottom+i:e.top-i-t.height,(l?s+t.height>o.height-a:s<a)&&(s=l?e.top-i-t.height:e.bottom+i),r=e.left+e.width/2-t.width/2}return{left:Math.max(a,Math.min(r,o.width-t.width-a)),top:Math.max(a,Math.min(s,o.height-t.height-a))}}function et(e,t){const o=e.getBoundingClientRect(),n=t.getBoundingClientRect();return{left:n.left-o.left,top:n.top-o.top,right:n.right-o.left,bottom:n.bottom-o.top,width:n.width,height:n.height}}function tt(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}const ot="oac-widget:";class nt{constructor(e,t,o={}){Object.defineProperty(this,"_store",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_async",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_ns",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_journalKey",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_onError",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_mirror",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_pending",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_sending",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_refused",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_loading",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_loaded",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_memoryOnly",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_drain",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_queued",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_journaled",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_heard",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_unsubscribe",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_closed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),this._ns=ot+e+":",this._journalKey="oac-widget-journal:"+e;const n=null!==t&&"function"==typeof t.entries;this._store=n?null:t,this._async=n?t:null,this._loaded=!n,this._onError=o.onError}key(e){return this._ns+e}get(e){if(null!==this._async){const t=this._mirror.get(this.key(e));try{return void 0===t?null:JSON.parse(t)}catch{return null}}if(null===this._store)return null;try{const t=this._store.getItem(this.key(e));return null===t?null:JSON.parse(t)}catch{return null}}set(e,t){if(null!==this._async){let o;try{o=JSON.stringify(t)}catch{return!1}return this._queue(this.key(e),o??null),!0}if(null===this._store)return!1;try{return this._store.setItem(this.key(e),JSON.stringify(t)),!0}catch{return!1}}remove(e){if(null===this._async){if(null!==this._store)try{this._store.removeItem(this.key(e))}catch{}}else this._queue(this.key(e),null)}get enabled(){return null!==this._store||null!==this._async}get loaded(){return this._loaded}load(){return null===this._loading&&(this._loading=null===this._async?Promise.resolve():this._read(this._async)),this._loading}close(){this._closed=!0;const e=this._unsubscribe;this._unsubscribe=null;try{e?.()}catch{}}async flush(){if(null!==this._async){this._writeJournal(this._async.journal),this._requeue();do{await this._send()}while(this._pending.size>0&&!this._memoryOnly)}}_queue(e,t){null===t?this._mirror.delete(e):this._mirror.set(e,t),this._refused.delete(e),this._pending.set(e,t),this._queued||(this._queued=!0,queueMicrotask(()=>{this._queued=!1,this._send()}))}_requeue(){for(const[e,t]of this._refused)this._pending.has(e)||this._pending.set(e,t);this._refused.clear()}async _read(e){if(!this._closed&&"function"==typeof e.subscribe)try{this._unsubscribe=e.subscribe((e,t)=>this._hear(e,t))}catch{}let t=[];try{t=await(o=Promise.resolve().then(()=>e.entries(this._ns)),n=4e3,new Promise((e,t)=>{const i=setTimeout(()=>t(new Error(`no answer within ${n} ms`)),n);o.then(t=>{clearTimeout(i),e(t)},e=>{clearTimeout(i),t(e)})}))}catch(e){this._memoryOnly=!0,this._report("load",this._ns,e)}var o,n;if(!this._memoryOnly){const o=it(e.journal,this._journalKey,this._ns);if(null!==o){this._journaled=!0;for(const[e,t]of o)this._pending.has(e)||(null===t?this._mirror.delete(e):this._mirror.set(e,t),this._pending.set(e,t))}for(const e of Array.isArray(t)?t:[]){const[t,o]=e;"string"==typeof t&&t.startsWith(this._ns)&&"string"==typeof o&&!this._pending.has(t)&&this._mirror.set(t,o)}for(const[e,t]of this._heard)this._pending.has(e)||(null===t?this._mirror.delete(e):this._mirror.set(e,t))}this._heard.clear(),this._loaded=!0,!this._memoryOnly&&(this._pending.size>0||this._journaled)&&this._send()}_send(){const e=this._async;if(null!==this._drain||null===e)return this._drain??Promise.resolve();const t=(async()=>{for(await this.load();this._pending.size>0&&!this._memoryOnly;){const t=[...this._pending];this._pending.clear();for(const[e,o]of t)this._sending.set(e,o);(await Promise.allSettled(t.map(([t,o])=>Promise.resolve().then(()=>null===o?e.removeItem(t):e.setItem(t,o))))).forEach((e,o)=>{const[n,i]=t[o];this._sending.delete(n),"fulfilled"!==e.status&&(this._pending.has(n)||this._refused.set(n,i),this._report(null===i?"remove":"write",n,e.reason))})}if(this._journaled&&!this._memoryOnly&&0===this._pending.size&&0===this._sending.size&&0===this._refused.size){this._journaled=!1;try{e.journal?.removeItem(this._journalKey)}catch{}}})();return this._drain=t,t.finally(()=>{this._drain=null,this._pending.size>0&&!this._memoryOnly&&this._send()}),t}_hear(e,t){this._closed||this._memoryOnly||"string"!=typeof e||!e.startsWith(this._ns)||null!==t&&"string"!=typeof t||this._pending.has(e)||this._sending.has(e)||this._refused.has(e)||(this._loaded?null===t?this._mirror.delete(e):this._mirror.set(e,t):this._heard.set(e,t))}_writeJournal(e){if(null==e||this._memoryOnly)return;const t={};let o=!1;const n=this._loaded?[]:it(e,this._journalKey,this._ns)??[];for(const e of[n,this._refused,this._sending,this._pending])for(const[n,i]of e)t[n]=i,o=!0;if(o)try{e.setItem(this._journalKey,JSON.stringify({version:1,entries:t})),this._journaled=!0}catch{}}_report(e,t,o){try{this._onError?.({operation:e,key:t,error:o})}catch{}}}function it(e,t,o){if(null==e)return null;let n;try{n=e.getItem(t)}catch{return null}if(null===n)return null;try{const e=JSON.parse(n);return tt(e)&&1===e.version&&tt(e.entries)?Object.entries(e.entries).filter(e=>e[0].startsWith(o)&&("string"==typeof e[1]||null===e[1])):[]}catch{return[]}}function at(){try{const e=globalThis;return void 0!==e.localStorage&&"function"==typeof e.localStorage.getItem?e.localStorage:null}catch{return null}}function rt(e,t){const o=Ke(t,"div","oac-layer");e.appendChild(o);const n=[],i=()=>[...n].reverse().find(e=>0===e.suspended),a=e=>{if(e.closed)return;e.closed=!0;const o=n.indexOf(e);o>=0&&n.splice(o,1);const i=t.activeElement,a=null!==i&&e.el.contains(i);e.el.remove(),e.scrim?.remove(),e.opts.anchor?.setAttribute("aria-expanded","false");const r=null===i||i===t.body||a;!1!==e.opts.restoreFocus&&r&&null!==e.restore&&e.restore.isConnected&&e.restore.focus(),e.opts.onClose?.(),0===n.length&&c()},r=e=>{const o=i();if(void 0===o)return;if("Escape"===e.key){if(!1===o.opts.dismissOnEscape)return;return e.preventDefault(),e.stopImmediatePropagation(),void a(o)}if("Tab"!==e.key)return;const n=Ye(o.el);if(0===n.length)return void e.preventDefault();const r=n.indexOf(t.activeElement);let s=null;e.shiftKey?r<=0&&(s=n.length-1):(-1===r||r>=n.length-1)&&(s=0),null!==s&&(e.preventDefault(),n[s].focus())},s=e=>{const t=e.target;for(let e=n.length-1;e>=0;e--){const o=n[e];if(!(void 0===o||o.suspended>0)){if(null!==t&&(o.el.contains(t)||!0===o.opts.anchor?.contains(t)))break;if(!1===o.opts.dismissOnOutside||!0===o.opts.modal&&!0!==o.opts.dismissOnOutside)break;a(o)}}};let l=!1;const c=()=>{l&&(l=!1,t.removeEventListener("keydown",r,!0),t.removeEventListener("pointerdown",s,!0))};return{open:(i,c={})=>{const d=c.placement??(c.anchor?"below":"center"),u=c.modal??"center"===d,p=t.activeElement,h=null===p||p===t.body||i.contains(p)?c.anchor??null:p;let m=null;const g={el:i,opts:{...c,modal:u},scrim:null,restore:h,closed:!1,suspended:0};if(u&&(m=Ke(t,"div","oac-scrim"),!0===c.dismissOnOutside&&m.addEventListener("pointerdown",()=>a(g)),o.appendChild(m),g.scrim=m),i.addEventListener("pointerdown",e=>e.stopPropagation()),"center"===d?(i.classList.add("oac-dialog"),i.hasAttribute("role")||i.setAttribute("role","dialog"),i.setAttribute("aria-modal","true")):i.classList.add("oac-pop"),i.hasAttribute("tabindex")||(i.tabIndex=-1),o.appendChild(i),"center"!==d&&c.anchor){const t=e.getBoundingClientRect();let o=et(e,c.anchor);if("beside"===d&&c.edge){const t=et(e,c.edge),n=Math.max(o.right,t.right);o={...o,right:n,width:n-o.left}}const n={width:i.offsetWidth,height:i.offsetHeight},a="beside"===d?Ze(o,n,t):Qe(o,n,t);i.style.left=a.left+"px",i.style.top=a.top+"px",c.anchor.setAttribute("aria-expanded","true")}if(n.push(g),l||(l=!0,t.addEventListener("keydown",r,!0),t.addEventListener("pointerdown",s,!0)),null!==c.initialFocus){(c.initialFocus??function(e){const t=Ye(e);return t.find(e=>null===e.closest(".oac-dialog__head"))??t[0]??null}(i)??i).focus()}return()=>a(g)},suspend:e=>{const o=n.find(t=>t.el===e);if(!o||o.closed)return()=>{};0===o.suspended&&(o.suspension={hidden:o.el.hidden,scrimHidden:o.scrim?.hidden??!1,focus:t.activeElement}),o.suspended++,o.el.hidden=!0,o.scrim&&(o.scrim.hidden=!0);let i=!1;return()=>{if(i)return;if(i=!0,o.suspended--,o.closed||o.suspended>0)return;const e=o.suspension;o.suspension=void 0,o.el.hidden=e.hidden,o.scrim&&(o.scrim.hidden=e.scrimHidden),!e.hidden&&e.focus?.isConnected&&o.el.contains(e.focus)&&e.focus.focus()}},closeTop:()=>{const e=i();return void 0!==e&&(a(e),!0)},closeAll:()=>{for(const e of n.slice().reverse())a(e)},top:()=>i()?.el??null,size:()=>n.length,layer:o,destroy:()=>{for(const e of n.slice().reverse())a(e);c(),o.remove()}}}const st=600;function lt(e,t,o){const n=new WeakMap;let i=null,a=0,r=null;const s=e=>"function"==typeof e?e():e,l=()=>{0!==a&&clearTimeout(a),a=0,r=null,i?.classList.remove("is-on")},c=a=>{const c=n.get(a);if(void 0===c||!a.isConnected)return;const d=s(c);if(null===d||!d.title)return void l();if("function"==typeof c&&a.setAttribute("aria-label",d.label??d.title),null===i&&(i=Ke(o,"div","oac-tip",{role:"presentation"})),i.parentNode!==t&&t.appendChild(i),r=a,i.textContent="",i.appendChild(o.createTextNode(d.title)),d.chord){const e=Ke(o,"kbd","oac-tip__chord");e.textContent=d.chord,i.appendChild(e)}if(d.sub){const e=Ke(o,"span","oac-tip__sub");e.textContent=d.sub,i.appendChild(e)}const u=e.getBoundingClientRect(),p=Xe(et(e,a),{width:i.offsetWidth,height:i.offsetHeight},u,d.side??"right");i.style.left=p.left+"px",i.style.top=p.top+"px",i.classList.add("is-on")};return{attach:(e,t,o=0)=>{n.set(e,t);const i=s(t);null!==i&&i.title&&!e.getAttribute("aria-label")&&e.setAttribute("aria-label",i.label??i.title),e.removeAttribute("title");const r=()=>{0!==a&&clearTimeout(a),o>0?a=setTimeout(()=>c(e),o):c(e)};e.addEventListener("pointerenter",r),e.addEventListener("focus",r),e.addEventListener("pointerleave",l),e.addEventListener("blur",l),e.addEventListener("pointerdown",l),e.addEventListener("keydown",l)},refreshLabel:e=>{const t=n.get(e);if("function"!=typeof t)return;const o=t();null!==o&&o.title&&e.setAttribute("aria-label",o.label??o.title)},show:c,hide:l,target:()=>r,destroy:()=>{l(),i?.remove(),i=null}}}function ct(e,t){return t.filter(t=>!1!==e.get(t)?.policy?.editable)}function dt(e){return oe(e)?ne(e):null}function ut(e,t){const o=e.history;return void 0===o||o.isDestroyed?"undo"===t?e.draw.undo():e.draw.redo():"undo"===t?o.undo():o.redo()}function pt(e,t,o){void 0!==e.history?e.history.transact(o,t):o()}function ht(e,t){const o=e.history;return void 0===o||o.isDestroyed?"undo"===t?e.draw.canUndo():e.draw.canRedo():"undo"===t?o.canUndo():o.canRedo()}class mt{constructor(){Object.defineProperty(this,"_handlers",{enumerable:!0,configurable:!0,writable:!0,value:new Map})}on(e,t){let o=this._handlers.get(e);return void 0===o&&(o=new Set,this._handlers.set(e,o)),o.add(t),()=>this.off(e,t)}off(e,t){void 0!==t?this._handlers.get(e)?.delete(t):this._handlers.delete(e)}emit(e,t){const o=this._handlers.get(e);if(void 0===o)return;const n=[];for(const e of Array.from(o))try{e(t)}catch(e){n.push(e)}if(n.length>0)throw n[0]}clear(){this._handlers.clear()}}const gt=new Map;function ft(e,t){return gt.set(e,t),()=>{gt.get(e)===t&>.delete(e)}}function bt(e){const t=Object.entries(e).map(([e,t])=>ft(e,t));return()=>{for(const e of t)e()}}function vt(e){return gt.delete(e)}function wt(e){return gt.get(e)??null}function _t(){return Array.from(gt.keys())}const yt=Object.freeze({}),xt=/\{([A-Za-z][A-Za-z0-9_]*)\}/g;function kt(e,t,o=yt,n=t){let i=n;if(void 0!==e.translate)try{const a=e.translate(t,n,Object.freeze({...o}));if("string"==typeof a&&""!==a.trim()){const e=new Set(Array.from(n.matchAll(xt),e=>e[1])),t=new Set(Array.from(a.matchAll(xt),e=>e[1]));e.size===t.size&&[...e].every(e=>t.has(e))&&(i=a)}}catch{}return i.replace(xt,(e,t)=>Object.prototype.hasOwnProperty.call(o,t)?String(o[t]):e)}function Ct(e,t){const o="string"==typeof t?t:t?.message;return"string"==typeof o&&""!==o.trim()?o:kt(e,"unknown error")}const St={tick:"Ticks",s:"Seconds",m:"Minutes",h:"Hours",D:"Days",W:"Weeks",M:"Months",other:"Other intervals"},At=["tick","s","m","h","D","W","M","other"];function Lt(e,t){const o=n(t);if(!o||"other"===o.unit)return t;const i=St[o.unit].toLowerCase();return kt(e,`schema.timeframe.${o.unit}.${1===o.multiplier?"one":"many"}`,{count:o.multiplier},`${o.multiplier} ${1===o.multiplier?i.slice(0,-1):i}`)}function Ot(e,t,o){const n=Ke(e.document,"button","oac-btn",{type:"button","aria-label":t,title:t});return o?n.appendChild(Ge(e.document,ie(o),"chrome")):n.textContent=t,n}function $t(e,t,o){const n=Ke(e.document,"div","oac-dialog oac-timeframe-dialog",{role:"dialog","aria-label":kt(e,"Add custom interval")}),i=Ke(e.document,"div","oac-timeframe-dialog__header"),a=Ke(e.document,"h3");a.textContent=kt(e,"Add custom interval");const r=Ot(e,kt(e,"Close"),"close");i.append(a,r),n.appendChild(i);const s=Ke(e.document,"div","oac-timeframe-dialog__fields"),l=Ke(e.document,"label"),c=Ke(e.document,"label");l.textContent=kt(e,"Type"),c.textContent=kt(e,"Interval");const d=Ke(e.document,"select","oac-input",{name:"unit","aria-label":kt(e,"Type")});for(const t of["seconds","minutes","hours","days","weeks","months","quarters","years"]){const o=Ke(e.document,"option",void 0,{value:t});o.textContent=kt(e,`schema.timeframe.unit.${t}`,{},t),d.appendChild(o)}d.value="minutes";const u=Ke(e.document,"input","oac-input",{name:"quantity",type:"number",min:"1",max:"100000",step:"1",inputmode:"numeric","aria-label":kt(e,"Interval")}),p=Ke(e.document,"span","oac-timeframe-dialog__unit");p.append(d,Ge(e.document,ie("chevron-down"),"chrome")),l.appendChild(p),c.appendChild(u),s.append(l,c),n.appendChild(s);const h=Ke(e.document,"div","oac-timeframe-dialog__error",{role:"status"});n.appendChild(h);const m=Ke(e.document,"div","oac-timeframe-dialog__footer"),g=Ot(e,kt(e,"Cancel")),f=Ot(e,kt(e,"Add"));f.dataset.confirmInterval="",f.classList.add("oac-btn--primary"),m.append(g,f),n.appendChild(m);let b="",v=()=>{};const w=()=>{try{if(b=Ne(Number(u.value),d.value),o.canSelect&&!o.canSelect(b))throw new Error(kt(e,"The current source cannot build this interval"));f.disabled=!1,h.textContent=""}catch(e){b="",f.disabled=!0,h.textContent=u.value?String(e.message):""}},_=()=>{if(w(),b)try{o.preferences.addCustom(b),v(),o.onSelect(b)}catch(e){h.textContent=String(e.message)}};return u.addEventListener("input",w),d.addEventListener("change",w),f.addEventListener("click",_),u.addEventListener("keydown",e=>{"Enter"===e.key&&(e.preventDefault(),_())}),r.addEventListener("click",()=>v()),g.addEventListener("click",()=>v()),w(),v=e.openOverlay(n,{anchor:t,placement:"center",initialFocus:u}),v}function Et(e,t,o){const i=Ke(e.document,"div","oac-menu oac-timeframe-menu",{role:"dialog","aria-label":kt(e,"Timeframes")}),a=Ot(e,kt(e,"Add custom interval"));a.dataset.addInterval="",a.prepend(Ge(e.document,ie("plus"),"chrome")),i.appendChild(a);const r=Ke(e.document,"div","oac-timeframe-menu__body");i.appendChild(r);const s=new Set;let l=()=>{},c=()=>{};a.addEventListener("click",()=>{l(),$t(e,t,o)});const d=()=>{const t=e.document.activeElement,i=t?.dataset.favorite??t?.dataset.removeInterval,a=void 0!==t?.dataset.removeInterval,c=t?.dataset.intervalGroup;r.textContent="";const u=new Map;for(const e of[o.current(),...o.preferences.custom(),...o.preferences.favorites(),...o.intervals]){const t=We(e);u.has(t)||u.set(t,e)}const p=[...u.values()],h=new Set(o.preferences.favorites().map(We)),m=new Set(o.preferences.custom().map(We));for(const t of At){const i=p.filter(e=>(n(e)?.unit??"other")===t);if(!i.length)continue;const a=Ke(e.document,"div","oac-timeframe-menu__group"),c=Ot(e,kt(e,St[t]));if(c.dataset.intervalGroup=t,c.classList.add("oac-timeframe-menu__heading"),c.setAttribute("aria-expanded",String(!s.has(t))),c.appendChild(Ge(e.document,ie(s.has(t)?"chevron-down":"chevron-up"),"chrome")),c.addEventListener("click",()=>{s.delete(t)||s.add(t),d()}),a.appendChild(c),r.appendChild(a),!s.has(t))for(const t of i.sort((e,t)=>(n(e)?.multiplier??0)-(n(t)?.multiplier??0))){const n=We(t),i=Ke(e.document,"div","oac-timeframe-menu__row");i.dataset.selected=String(o.current()===t);const r=Ot(e,Lt(e,t));r.dataset.pickInterval=t,r.dataset.interval=t,r.classList.add("oac-timeframe-menu__pick"),r.setAttribute("aria-pressed",String(o.current()===t)),r.disabled=!1===o.canSelect?.(t),r.disabled&&(r.title=kt(e,"The current source cannot build this interval")),r.addEventListener("click",()=>{r.disabled||(l(),o.onSelect(t))});const s=Ot(e,kt(e,"Remove {code}",{code:t}),"trash");s.dataset.removeInterval=t,s.hidden=!m.has(n),s.addEventListener("click",()=>o.preferences.removeCustom(t));const c=Ot(e,kt(e,h.has(n)?"Remove {code} from favorites":"Add {code} to favorites",{code:t}),h.has(n)?"star-filled":"star");c.dataset.favorite=t,c.setAttribute("aria-pressed",String(h.has(n))),c.addEventListener("click",()=>o.preferences.toggle(t));const d=Ke(e.document,"div","oac-timeframe-menu__actions");d.append(s,c),i.append(r,d),a.appendChild(i)}}c&&Array.from(r.querySelectorAll("[data-interval-group]")).find(e=>e.dataset.intervalGroup===c)?.focus(),i&&Array.from(r.querySelectorAll("button")).find(e=>(a?e.dataset.removeInterval:e.dataset.favorite)===i)?.focus()};d(),c=o.preferences.subscribe(d),i.addEventListener("keydown",t=>{const o=t.key;if("ArrowDown"!==o&&"ArrowUp"!==o)return;const n=Array.from(i.querySelectorAll("button")).filter(e=>!e.hidden&&!e.disabled),a=n.indexOf(e.document.activeElement),r="ArrowDown"===o?1:-1;n[(a+r+n.length)%n.length]?.focus(),t.preventDefault(),t.stopPropagation()});const u=Array.from(r.querySelectorAll("[data-pick-interval]")).find(e=>e.dataset.pickInterval===o.current()),p=e.openOverlay(i,{anchor:t,placement:"below",initialFocus:u??a,onClose:()=>c()});return l=()=>{c(),p()},l}function Tt(e){let t=null;const o={now:null,load:()=>t??(t=e().then(e=>o.now=e,e=>{throw t=null,e}))};return o}function Pt(e,t,o,n,i){if(null!==e.now)return void t(e.now);let a=()=>!!n()||null;if(void 0!==i){const{slot:e,doc:t,from:o}=i,r=e.waiting={},s=t.activeElement;let l=!1;const c=e=>{!0!==o?.contains(e.target)&&(l=!0)},d=e=>{"Escape"===e.key&&(l=!0)};t.addEventListener("pointerdown",c,!0),t.addEventListener("keydown",d,!0),a=()=>{if(t.removeEventListener("pointerdown",c,!0),t.removeEventListener("keydown",d,!0),e.waiting!==r)return null;if(e.waiting=null,!n())return null;const o=t.activeElement;return!(l||o!==s&&Ve(o))}}e.load().then(e=>{!0===a()&&t(e)},e=>{null!==a()&&o(e)})}function jt(e,t,o){return kt(e,"{name} could not load: {error}",{name:t,error:Ct(e,o)})}const Mt="openalgo-charts-widget",It=Tt(()=>import("./openalgo-charts.widget.storage-idb-WH_o01Wj.mjs"));function Dt(e,t){let o=null,n=!1;const i=new Map,a=t=>{if(null!==o)return o;const a=o=e(t);for(const e of i.keys())i.set(e,a.subscribe?.(e));return n&&a.close?.(),a},r=()=>o??(null===It.now?null:a(It.now)),s=e=>{const t=r();return null!==t?e(t):It.load().then(t=>e(a(t)))};return null===r()&&It.load().then(a,()=>{}),{journal:t,entries:e=>s(t=>t.entries(e)),setItem:(e,t)=>s(o=>o.setItem(e,t)),removeItem:e=>s(t=>t.removeItem(e)),subscribe:e=>(i.set(e,r()?.subscribe?.(e)),()=>{i.get(e)?.(),i.delete(e)}),close(){n=!0,o?.close?.()}}}function zt(e,t=Mt,o={}){const n=void 0===o.journal?at():o.journal;return Dt(i=>i.openIndexedDbStore(e,t,{...o,journal:n}),n)}let Nt=null;function Rt(){let e;try{e=globalThis.indexedDB??void 0}catch{e=void 0}if(void 0===e||"function"!=typeof e.open)return at();const t=e;return null!==Nt&&Nt.factory===t||(Nt={factory:t,store:Dt(e=>e.openPageDefault(t),at())}),Nt.store}function Ft(e,t){if(Object.is(e,t))return!0;if("number"==typeof e&&"number"==typeof t)return Math.abs(e-t)<1e-9;if(Array.isArray(e)||Array.isArray(t))return Array.isArray(e)&&Array.isArray(t)&&e.length===t.length&&e.every((e,o)=>Ft(e,t[o]));if(!tt(e)||!tt(t))return!1;const o=new Set([...Object.keys(e),...Object.keys(t)]);for(const n of o)if(!Ft(e[n],t[n]))return!1;return!0}const Wt=e=>tt(e)&&"indicator"===e.kind&&"string"==typeof e.instanceId;function Bt(e,t){const o={};for(const[n,i]of Object.entries(e))o[n]=Wt(i)?{...i,instanceId:t(i.instanceId)}:Array.isArray(i)?i.map(e=>tt(e)?{...e}:e):tt(i)?{...i}:i;return o}function qt(e,t){const o=e.seriesType(t),n=e.seriesTransform(t);return null===o||null===n?o:`${o}+${n.type}`}const Ut=["mode","inverted","marginTop","marginBottom"],Ht=new Set(["scales.mode","scales.inverted","scales.autoScale"]),Kt=["objects:change","indicatorRemoved","paneAdded","paneRemoved","paneMoved","paneCollapsed","paneResized","priceAxisMoved","priceAxisPlacementChanged","layout:change"];function Gt(e,t,o){const n={type:!1,scale:!1,settings:[],defaults:[],studies:new Map,kinds:new Set,order:!1,paneOrder:!1,panes:new Map,born:[],gone:[]};if(e.type!==t.type&&(n.type=!0,n.kinds.add("chart-type")),e.scale!==t.scale&&(n.scale=!0,n.kinds.add("series-scale")),e.settings&&t.settings)for(const o of new Set([...Object.keys(e.settings),...Object.keys(t.settings)]))!Ht.has(o)&&o in e.settings&&o in t.settings&&!Ft(e.settings[o],t.settings[o])&&n.settings.push(o);n.defaults=Ut.filter(o=>!Ft(e.defaults[o],t.defaults[o])),(n.settings.length||n.defaults.length)&&n.kinds.add("settings");const i=new Map(e.studies.map(e=>[e.id,e])),a=new Map(t.studies.map(e=>[e.id,e])),r={presence:!0,keys:[],visible:!0,scale:!0,pane:!0};for(const[e,t]of i){if(void 0!==o&&!o.present(e))continue;const i=a.get(e),s=o?.policy(e)??{};if(void 0===i){!1!==s.removable&&(n.studies.set(e,r),n.kinds.add("study-remove"));continue}const l=!1===s.configurable?[]:[...new Set([...Object.keys(t.settings),...Object.keys(i.settings)])].filter(e=>!Ft(t.settings[e],i.settings[e])),c={presence:!1,keys:l,visible:t.visible!==i.visible,scale:!1!==s.configurable&&(t.scale!==i.scale||!Ft(t.plots,i.plots)),pane:!1!==s.movable&&t.pane!==i.pane};l.length&&n.kinds.add("study-settings"),c.visible&&n.kinds.add("study-visibility"),c.scale&&n.kinds.add("study-scale"),c.pane&&n.kinds.add("study-pane"),(l.length||c.visible||c.scale||c.pane)&&n.studies.set(e,c)}for(const e of a.keys())i.has(e)||(void 0===o||!o.present(e)&&o.returns(e))&&(n.studies.set(e,r),n.kinds.add("study-add"));const s=(e,t)=>e.studies.filter(e=>e.pane===t&&i.has(e.id)&&a.has(e.id)).map(e=>e.id);for(const i of new Set(t.studies.map(e=>e.pane)))Ft(s(e,i),s(t,i))||void 0!==o&&!o.order(t,i)||(n.order=!0);n.order&&n.kinds.add("study-order");const l=new Map(e.panes.map(e=>[e.key,e])),c=new Set(t.panes.map(e=>e.key)),d=(e,t)=>t.studies.some(t=>t.pane===e.key&&n.studies.has(t.id)),u=(e,t)=>d(e,t)||0===e.series&&!0!==e.host;n.gone=e.panes.filter(t=>!c.has(t.key)&&u(t,e)).map(e=>e.key),n.born=t.panes.filter(e=>!l.has(e.key)&&u(e,t)).map(e=>e.key),e.panes.some(t=>n.gone.includes(t.key)&&!d(t,e))&&n.kinds.add("pane-remove"),t.panes.some(e=>n.born.includes(e.key)&&!d(e,t))&&n.kinds.add("pane-add");const p=t.panes.filter(e=>l.has(e.key));Ft(e.panes.filter(e=>p.some(t=>t.key===e.key)).map(e=>e.key),p.map(e=>e.key))||(n.paneOrder=!0,n.kinds.add("pane-order"));for(const e of p){const t=l.get(e.key),o={weight:!Ft(e.weight,t.weight),collapsed:e.collapsed!==t.collapsed,axes:new Map};o.weight&&n.kinds.add("pane-weight"),o.collapsed&&n.kinds.add("pane-collapse");for(const[i,a]of Object.entries(e.axes)){const e=t.axes[i];if(void 0===e)continue;const r=Object.keys(a).filter(t=>t in e&&!Ft(a[t],e[t]));r.length&&(o.axes.set(i,r),n.kinds.add("axis"))}(o.weight||o.collapsed||o.axes.size)&&n.panes.set(e.key,o)}return n}const Vt=e=>0===e.kinds.size,Jt={"study-add":"study-remove","study-remove":"study-add","pane-add":"pane-remove","pane-remove":"pane-add"};function Yt(e){const t=e.id,o={...e.policy()};return{id:t,policy:()=>o}}class Zt extends Error{}const Qt=e=>{throw new Zt(e)};class Xt{constructor(e,t={}){Object.defineProperty(this,"_chart",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_draw",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_opts",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_limit",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_undo",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_redo",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_base",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_epoch",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_pending",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_applying",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_ignoring",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_restoring",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_tx",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_styled",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_drawings",{enumerable:!0,configurable:!0,writable:!0,value:{version:ae,drawings:[]}}),Object.defineProperty(this,"_group",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_dragging",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_deferred",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_dropped",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_orphans",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_keys",{enumerable:!0,configurable:!0,writable:!0,value:new WeakMap}),Object.defineProperty(this,"_nextKey",{enumerable:!0,configurable:!0,writable:!0,value:1}),Object.defineProperty(this,"_seen",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"_hostPanes",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"_names",{enumerable:!0,configurable:!0,writable:!0,value:new WeakMap}),Object.defineProperty(this,"_known",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_lastNames",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_hostRemoved",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"_listeners",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"_off",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_release",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_nextHolder",{enumerable:!0,configurable:!0,writable:!0,value:1}),Object.defineProperty(this,"_heard",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"_destroyed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),this._chart=e,this._draw=t.draw??null,this._opts=t,this._limit=Math.max(1,Math.floor(t.limit??100)),this._base=this._shot(!1),this._drawings=this._document(),this._listen(),this._claim()}get isDestroyed(){return this._destroyed}attach(e,t=this._draw){if(this._destroyed)return;for(const e of this._off.splice(0))e();const o=this._base.panes.map(e=>e.key),n=new Map(this._base.studies.map(e=>[this._liveId(e.id),e.id]));t!==this._draw&&this._detachSteps();const i=this._chart;if(this._chart=e,this._draw=t,this._claim(),this._drawings=this._document(),e.panes().forEach((e,t)=>{void 0!==o[t]&&this._keys.set(e,o[t])}),!e.isDestroyed)for(const t of e.indicators()){const e=n.get(t.id);void 0!==e&&this._bind(e,t)}if(e!==i){const t=new Set(e.isDestroyed?[]:e.indicators());for(const[e,o]of this._known)t.has(o)||this._known.set(e,Yt(o))}this._pending=!1,this._dragging=!1,this._deferred=!1;const a=this._base;this._rebase(),this._took(a,this._base),this._prune(),this._listen(),this._notify()}canUndo(){return this._undo.some(e=>this._reachable(e,"undo"))}canRedo(){return this._redo.some(e=>this._reachable(e,"redo"))}peekUndo(){return this._peek(this._undo,"undo")}peekRedo(){return this._peek(this._redo,"redo")}undo(){return this._move("undo")}redo(){return this._move("redo")}transact(e,t){if(this._destroyed||this._chart.isDestroyed||this._applying>0||this._ignoring>0||null!==this._tx)return e();const o=this.group(t);this._flush();const n=this._tx={label:t,before:this._shot(!0),steps:[],commands:[]};try{return e()}finally{this._cut(n),this._tx=null,o()}}_cut(e){this._pending=!1;const t=this._shot(!0);this._base=t;const o=this._styled;this._styled=!1,this._record({label:e.label,before:e.before,after:t,steps:e.steps.splice(0),commands:e.commands.splice(0),orphans:this._takeOrphans(),linked:o})}_rebase(){this._epoch++,this._base=this._shot(!1)}group(e){if(this._destroyed)return()=>{};if(null!==this._group)return this._group.depth++,this._closer(this._group);this._flush();const t=this._group={entry:null,label:e,depth:1};return this._closer(t)}ignore(e){if(this._destroyed||this._applying>0)return e();const t=0===this._ignoring?this._tx:null;null!==t?this._cut(t):this._flush(),this._ignoring++;try{return this._untracked(e)}finally{if(0===--this._ignoring){this._pending=!1,this._orphans=[],this._styled=!1;const e=this._base;this._rebase(),this._took(e,this._base),null!==t&&this._tx===t&&(this._base=t.before=this._shot(!0)),this._prune()}}}_untracked(e){const t=this._draw;return null===t||t.isDestroyed?e():t.untracked(e)}push(e){this._destroyed||this._applying>0||this._ignoring>0||(null===this._tx?(this._flush(),this._record({label:e.label,commands:[e]})):this._tx.commands.push(e))}clear(){this._undo.length=0,this._redo.length=0,null!==this._group&&(this._group.entry=null),this._pending=!1,this._orphans=[],this._dropped=[],this._hostRemoved.clear(),this._lastNames.clear();const e=new Set(this._chart.isDestroyed?[]:this._chart.indicators());for(const[t,o]of this._known)e.has(o)||this._known.delete(t);this._destroyed||(this._drawings=this._document(),this._rebase()),this._notify()}subscribe(e){return this._listeners.add(e),()=>{this._listeners.delete(e)}}destroy(){if(!this._destroyed){this.clear(),this._destroyed=!0;for(const e of this._off.splice(0))e();this._release?.(),this._release=null,this._listeners.clear()}}_claim(){this._release?.(),this._release=null;const e=this._draw;null===e||e.isDestroyed||(this._release=e.delegateInputAnchorSteps(()=>this._anchorMoved()))}_anchorMoved(){this._destroyed||this._applying>0||this._ignoring>0||this._restoring>0||null!==this._tx||this._flush()}_listen(){const e=this._chart;if(e.isDestroyed)return;const t=(t,o)=>{this._off.push(e.on(t,o))};for(const e of Kt)t(e,()=>this._observe(e));t("drag:start",()=>this._flush()),t("draw:preview",()=>{this._dragging=!0}),t("draw:preview-clear",()=>{this._dragging=!1,this._deferred&&(this._deferred=!1,this._observe("objects:change"))}),t("style:change",()=>{null!==this._tx&&0===this._applying&&0===this._ignoring&&0===this._restoring&&(this._styled=!0)}),t("draw:remove",e=>{const t=e?.drawing;void 0!==t&&0===this._applying&&this._dropped.push(t)}),t("drawing:change",e=>this._drawingChange(e)),t("draw:restore",()=>this._forgetDrawings()),t("draw:destroy",e=>{e?.controller===this._draw&&(this._detachSteps(),this._draw=null,this._release=null)}),t("state:restore:start",()=>{this._restoring++,this._pending=!1}),t("state:restore:end",()=>{0===--this._restoring&&this.clear()}),t("destroy",()=>{if(this._chart===e)for(const e of this._off.splice(0))e()})}_observe(e){this._destroyed||this._applying>0||this._ignoring>0||this._restoring>0||null!==this._tx||("objects:change"===e&&this._dragging?this._deferred=!0:this._pending||(this._pending=!0,queueMicrotask(()=>{this._pending&&this._flush()})))}_flush(){if(!this._pending||this._destroyed)return;this._pending=!1;const e=this._group?.entry?.changes,t=void 0===e?void 0:e[e.length-1],o=this._shot(!0===t?.before.full&&t.epoch===this._epoch),n=this._base;this._base=o,this._record({before:n,after:o,orphans:this._takeOrphans()})}_drawingChange(e){const t=this._dropped;if(this._dropped=[],this._destroyed||this._applying>0)return;const o=this._drawings;if(this._drawings=this._document(),void 0!==e.step){if(this._ignoring>0)return;const t={id:e.step,before:o,after:this._drawings,detached:!1};return null!==this._tx?void this._tx.steps.push(t):(this._flush(),void this._record({steps:[t]}))}if("update"===e.kind&&!0!==e.linked&&t.length>0&&(this._pending||null!==this._tx||this._paneGone())){const e=this._base.panes.map(e=>e.key);for(const o of t){const t=e[o.paneIndex];void 0!==t&&this._orphans.push({pane:t,drawing:o})}return}"undo"!==e.kind&&"redo"!==e.kind||this._follow(e.kind)}_document(){return this._draw?.toJSON()??{version:ae,drawings:[]}}_forgetDrawings(){if(this._destroyed||this._applying>0)return;const e=this._group,t=e=>e.changes.length>0||e.commands.length>0;for(const t of[...this._undo,...this._redo,...e?.redo??[],e?.entry,e?.shifted])t&&(t.steps=[],t.orphans=[]);null!==this._tx&&(this._tx.steps=[]),this._undo=this._undo.filter(t),this._redo=this._redo.filter(t),e?.entry&&!t(e.entry)&&(e.entry=null),this._orphans=[],this._dropped=[],this._prune(),this._notify()}_paneGone(){const e=new Set(this._chart.panes().map(e=>this._keys.get(e)));return this._base.panes.some(t=>!e.has(t.key))}_detachSteps(){for(const e of[...this._undo,...this._redo])for(const t of e.steps)t.detached=!0;if(null!==this._tx)for(const e of this._tx.steps)e.detached=!0}_takeOrphans(){const e=this._orphans;return this._orphans=[],e}_record(e){const t=void 0!==e.before&&void 0!==e.after&&!Vt(Gt(e.before,e.after)),o=t&&!Vt(Gt(e.after,e.before,this._rules));if(t&&!o&&(this._epoch++,this._took(e.before,e.after)),!o&&!e.steps?.length&&!e.commands?.length)return t&&this._prune(),void this._notifyIfMoved();let n;const i=this._group;if(null!==i&&null!==i.entry)n=i.entry;else{n={label:i?.label,changes:[],steps:[],commands:[],orphans:[]},this._undo.push(n);const e=this._undo.length>this._limit?this._undo.shift():void 0;null!==i&&Object.assign(i,{entry:n,redo:this._redo,shifted:e})}this._merge(n,e,o),this._redo=[],this._prune(),this._notify()}_merge(e,t,o){if(e.label??(e.label=t.label),!0===t.linked&&(e.linked=!0),o){const o=t.before,a=t.after,r=e.changes[e.changes.length-1];void 0===r||r.epoch!==this._epoch?e.changes.push({before:o,after:a,epoch:this._epoch}):(!r.before.full&&o.full&&(r.before={...r.before,full:!0,settings:o.settings,panes:(n=r.before.panes,i=o.panes,n.map(e=>{const t=i.find(t=>t.key===e.key);if(void 0===t)return e;const o={};for(const[n,i]of Object.entries(e.axes)){const e=t.axes[n];o[n]=void 0===e?i:{...i,auto:e.auto,lock:e.lock}}return{...e,axes:o}}))}),r.after=a),e.orphans.push(...t.orphans??[])}var n,i;e.steps.push(...t.steps??[]),e.commands.push(...t.commands??[])}_closer(e){let t=!1;return()=>{if(t)return;if(t=!0,--e.depth>0||this._group!==e)return;this._flush(),this._group=null;const o=e.entry,n=o?.changes??[];if(null!==o&&!o.steps.length&&!o.commands.length&&(!n.length||Vt(Gt(n[0].before,n[n.length-1].after)))){const t=this._undo.lastIndexOf(o);t>=0&&(this._undo.splice(t,1),void 0!==e.shifted&&this._undo.unshift(e.shifted),this._redo.length||void 0===e.redo||(this._redo=e.redo))}this._prune(),this._notify()}}_keyOf(e){let t=this._keys.get(e);return void 0===t&&(t=this._nextKey++,this._keys.set(e,t)),t}_nameOf(e){let t=this._names.get(e);if(void 0!==t)return t;t=e.id;const o=this._known.get(t);if(void 0!==o&&o!==e)do{t=`${e.id}~${this._nextHolder++}`}while(this._known.has(t));return this._bind(t,e),t}_bind(e,t){this._names.set(t,e),this._known.set(e,t)}_liveId(e){return this._known.get(e)?.id??e}_policyOf(e){return this._known.get(e)?.policy()??{}}_took(e,t){const o=new Set(t.studies.map(e=>e.id));for(const t of e.studies)o.has(t.id)||this._hostRemoved.add(t.id)}_prune(){const e=this._chart,t=new Set(e.isDestroyed?[]:e.indicators()),o=new Set;if(!e.isDestroyed)for(const t of e.panes()){const e=this._keys.get(t);void 0!==e&&o.add(e)}if(0===this._hostRemoved.size&&this._lastNames.size<=t.size&&this._seen.size<=o.size&&[...this._known.values()].every(e=>t.has(e)))return;const n=new Set,i=e=>{for(const t of e.panes)o.add(t.key);for(const t of e.studies){n.add(t.id);for(const e of Object.values(t.settings))Wt(e)&&n.add(e.instanceId)}},a=e=>{if(null!=e){for(const t of e.changes)i(t.before),i(t.after);for(const t of e.orphans)o.add(t.pane)}};for(const e of this._undo)a(e);for(const e of this._redo)a(e);const r=this._group;null!==r&&(a(r.entry),r.redo?.forEach(a),a(r.shifted)),null!==this._tx&&i(this._tx.before),i(this._base);for(const e of this._orphans)o.add(e.pane);for(const[e,o]of this._known)n.has(e)||t.has(o)||this._known.delete(e);for(const e of this._hostRemoved)this._known.has(e)||this._hostRemoved.delete(e);for(const[e,t]of this._lastNames)this._known.has(t)||this._lastNames.delete(e);for(const e of this._seen)o.has(e)||this._seen.delete(e);for(const e of this._hostPanes)o.has(e)||this._hostPanes.delete(e)}_view(){const e={order:[],pane:new Map};if(this._chart.isDestroyed)return e;const t=this._chart.panes();for(const o of this._chart.indicators()){const n=this._nameOf(o);e.order.push(n),e.pane.set(n,this._keys.get(t[o.paneIndex])??-1)}return e}_series(){return(this._opts.series?this._opts.series():this._chart.primarySeries())??null}_shot(e){const t=this._chart,o={full:e,type:null,scale:null,studies:[],panes:[],defaults:{}};if(t.isDestroyed)return o;const n=0===this._seen.size,a=t.panes(),r=a.map(e=>this._keyOf(e)),s=this._series(),l=s?.priceScale();s&&(o.type=qt(t,s)),a.forEach((n,i)=>{const a={};for(const[r,s]of Object.entries(n.scaleStates())){if(void 0===s)continue;const c=r;void 0!==l&&n.scaleFor(c)===l&&(o.scale=c);const d=t.priceAxisPlacement(i,c),u={side:d?.side??("left"===c||"right"===c?c:"hidden"),order:d?.order??0,mode:s.mode,inverted:s.inverted,marginTop:s.marginTop,marginBottom:s.marginBottom};e&&(u.auto=s.autoScale,u.lock=n.ratioLocked(c)),a[r]=u}const s={key:r[i],weight:t.paneWeight(i),collapsed:t.paneCollapsed(i),series:n.series().length,axes:a};if(0===s.series){s.ranges={};for(const e of Object.keys(a)){const t=n.scaleFor(e);t.scaled&&(s.ranges[e]=t.priceRange())}}o.panes.push(s)});const c=t.indicators(),d=c.map(e=>this._nameOf(e));c.forEach((e,t)=>this._lastNames.set(e.id,d[t]));const u=e=>this._lastNames.get(e)??e;o.studies=c.map((e,t)=>({id:d[t],indicatorId:e.indicatorId,settings:Bt(e.settings(),u),pane:r[e.paneIndex]??-1,visible:e.visible(),scale:e.priceScaleId(),plots:{...e.plotPriceScaleIds()}}));for(const e of o.panes)this._seen.has(e.key)||(this._seen.add(e.key),n||o.studies.some(t=>t.pane===e.key)||this._hostPanes.add(e.key)),this._hostPanes.has(e.key)&&(e.host=!0);const p=t.priceScaleDefaults();for(const e of Ut)void 0!==p[e]&&(o.defaults[e]=p[e]);return e&&(o.settings=i(t)),o}_peek(e,t){for(let o=e.length-1;o>=0;o--)if(this._reachable(e[o],t))return this._describe(e[o],t);return null}_describe(e,t){const o=new Set,n=e=>"redo"===t?e:Jt[e]??e;for(const i of this._moves(e,t))for(const e of i.delta.kinds)o.add(n(e));return e.steps.length&&o.add("drawing"),e.commands.length&&o.add("command"),{...void 0===e.label?{}:{label:e.label},changes:[...o]}}_moves(e,t){const o="undo"===t,n=this._view(),i=[];for(const t of o?e.changes.slice().reverse():e.changes){const e=o?t.after:t.before,a=o?t.before:t.after,r=Gt(e,a,this._rulesFor(n));Vt(r)||(i.push({from:e,to:a,delta:r}),this._project(n,a,r))}return i}_project(e,t,o){const n=new Map(t.studies.map(e=>[e.id,e]));let i=!1;for(const[t,a]of o.studies){const o=n.get(t);void 0!==o?(a.presence&&!e.pane.has(t)&&(e.order.push(t),i=!0),(a.presence||a.pane)&&e.pane.set(t,o.pane)):(e.order=e.order.filter(e=>e!==t),e.pane.delete(t))}if(o.order||i)for(const o of t.panes){const n=this._plan(e,t,o.key);if(null===n||n.blocked)continue;let i=0;e.order=e.order.map(t=>e.pane.get(t)===o.key?n.desired[i++]:t)}}_plan(e,t,o){const n=e.order.filter(t=>e.pane.get(t)===o),i=t.studies.filter(e=>e.pane===o).map(e=>e.id).filter(e=>n.includes(e)),a=n.slice();let r=0;if(n.forEach((e,t)=>{i.includes(e)&&(a[t]=i[r++])}),Ft(a,n))return null;const s=e=>!1===this._policyOf(e).movable;return{now:n,desired:a,blocked:!Ft(n.filter(s),a.filter(s))}}_reachable(e,t){if(e.commands.length||this._moves(e,t).length)return!0;const o=this._draw?.historySteps()[t]??[];return e.steps.some(e=>e.detached||o.includes(e.id))}_move(e){if(this._destroyed||this._applying>0||this._chart.isDestroyed)return!1;this._flush(),null!==this._group&&(this._group.entry=null);const t="undo"===e?this._undo:this._redo,o="undo"===e?this._redo:this._undo;for(let n=t.pop();void 0!==n;n=t.pop()){const i=this._run(n,e);if("skip"!==i)return"done"===i?o.push(n):t.length=0,this._prune(),this._notify(),"done"===i}return this._prune(),this._notify(),!1}_run(e,t){const o="undo"===t,n=this._draw?.historySteps();e.steps=e.steps.filter(e=>e.detached||void 0!==n&&(n.undo.includes(e.id)||n.redo.includes(e.id)));const i=this._moves(e,t);if(!e.commands.length&&!i.length&&!e.steps.length)return"skip";const a={steps:[],moves:0,commands:0},r=!0===e.linked?this._look():null;this._applying++;try{if(this._untracked(()=>{if(!o)for(const t of e.commands)!1===t.redo()&&Qt("command"),a.commands++;o&&this._drawSteps(e.steps.slice().reverse(),"undo",a.steps);for(const e of i)a.moves++,this._apply(e.to,e.delta);if(o&&this._restoreOrphans(e.orphans),o||this._drawSteps(e.steps,"redo",a.steps),o)for(const t of e.commands.slice().reverse())!1===t.undo()&&Qt("command"),a.commands++}),null!==r&&!this._chart.isDestroyed){const e=this._look(),t=Object.fromEntries(Object.entries(e).filter(([e,t])=>!Ft(r[e],t)));Object.keys(t).length&&this._chart.emit("style:change",t)}return"done"}catch(o){this._rollback(e,t,a,i);try{this._opts.onError?.({direction:t,step:this._describe(e,t),error:o})}catch{}return"fail"}finally{this._applying--,this._pending=!1,this._dropped=[],this._orphans=[],this._drawings=this._document(),this._rebase()}}_rollback(e,t,o,n){const i="undo"===t,a=e=>{try{this._untracked(e)}catch{}},r=i?e.commands.slice().reverse():e.commands;for(const e of r.slice(0,o.commands).reverse())a(()=>{i?e.redo():e.undo()});for(const e of n.slice(0,o.moves).reverse())a(()=>this._apply(e.from,Gt(e.to,e.from,this._rules)));a(()=>this._drawSteps(o.steps.slice().reverse(),i?"redo":"undo",[]))}_look(){return this._chart.isDestroyed?{}:a(i(this._chart))}_drawSteps(e,t,o){const n=this._draw;if(null!==n)for(const i of e){const e=n.historySteps()[t];if(!i.detached&&e.includes(i.id)&&e[e.length-1]!==i.id&&(i.detached=!0),i.detached){const[e,a]="undo"===t?[i.after,i.before]:[i.before,i.after],r=new Map(e.drawings.map(e=>[e.id,e])),s=new Map(a.drawings.map(e=>[e.id,e]));for(const e of new Set([...r.keys(),...s.keys()]))Ft(r.get(e),s.get(e))||n.applyLinkedDrawing(e,s.get(e)??null);o.push(i);continue}for(let e=0;n.historySteps()[t].includes(i.id)&&e<1e3&&("undo"===t?n.undo():n.redo());e++);n.historySteps()[t].includes(i.id)&&Qt("drawing"),o.push(i)}else e.length&&Qt("drawing")}_follow(e){const t=this._draw?.historySteps();if(void 0===t)return;const o="undo"===e?this._undo:this._redo,n="undo"===e?this._redo:this._undo,i="undo"===e?t.redo:t.undo;for(let e=o[o.length-1];void 0!==e&&(!e.commands.length&&!e.changes.length&&e.steps.length&&e.steps.every(e=>!e.detached&&i.includes(e.id)));e=o[o.length-1])n.push(o.pop());this._notify()}_restoreOrphans(e){const t=this._draw;if(null!==t)for(const{pane:o,drawing:n}of e){const e=this._slot(o);e>=0&&void 0===t.get(n.id)&&t.applyLinkedDrawing(n.id,{...n,paneIndex:e})}}_slot(e){return this._chart.panes().findIndex(t=>this._keys.get(t)===e)}_find(e){const t=this._known.get(e);return void 0===t||this._chart.isDestroyed?void 0:this._chart.indicators().find(e=>e===t)}_rulesFor(e){return{policy:e=>this._policyOf(e),present:t=>e.pane.has(t),returns:e=>!this._hostRemoved.has(e)&&!1!==this._policyOf(e).removable,order:(t,o)=>{const n=this._plan(e,t,o);return null!==n&&!n.blocked}}}get _rules(){return this._rulesFor(this._view())}_apply(e,t){const o=this._chart,n=new Map(e.studies.map(e=>[e.id,e]));for(const e of t.studies.keys()){if(n.has(e))continue;const t=this._find(e);void 0===t||o.removeIndicator(t.id)||Qt("remove")}const a=e.studies.filter(e=>{const o=t.studies.get(e.id);return void 0!==o&&(o.presence||o.pane)&&this._find(e.id)?.paneIndex!==this._slot(e.pane)}),l=[];for(;a.length;){const e=e=>Object.values(e.settings).some(t=>Wt(t)&&a.some(o=>o!==e&&o.id===t.instanceId)),t=Math.max(0,a.findIndex(t=>!e(t)));l.push(...a.splice(t,1))}const c=new Set;for(const e of t.born){if(this._slot(e)>=0)continue;const t=o.panes().length,n={zOrder:()=>"bottom",draw:()=>{}};o.addPrimitive(n,t),o.removePrimitive(n);const i=o.panes()[t];void 0===i&&Qt("pane"),this._keys.set(i,e),c.add(e)}let d=!1;for(const t of l){let n=this._slot(t.pane);const i=n<0;i&&(n=o.panes().length);const a=this._find(t.id);void 0===a?(this._add(t,n,e),d=!0):a.paneIndex===n||o.moveIndicator(a.id,n)||Qt("move");const r=o.panes()[n];i&&void 0!==r&&(this._keys.set(r,t.pane),c.add(t.pane))}for(const e of t.gone){const t=this._slot(e);t>=0&&0===o.panes()[t].series().length&&!o.removePane(t)&&Qt("pane")}(t.paneOrder||c.size)&&this._arrange(e);for(const n of e.panes){const e=t.panes.get(n.key),i=c.has(n.key),a=void 0!==e||i?this._slot(n.key):-1;a<0||(!i&&!e.weight||Ft(o.paneWeight(a),n.weight)||o.setPaneWeight(a,n.weight),!i&&!e.collapsed||o.paneCollapsed(a)===n.collapsed||o.setPaneCollapsed(a,n.collapsed)||Qt("collapse"))}for(const o of e.studies){const e=t.studies.get(o.id);void 0===e||e.presence||this._fit(o,e)}(t.order||d)&&this._stack(e);const u=this._series();if(t.type&&null!==e.type&&null!==u&&qt(o,u)!==e.type&&(!function(e,t,o,n){const[i,a]=o.split("+");void 0===n?(e.setSeriesTransform(t,void 0===a?null:{type:a}),e.setSeriesType(t,i)):n(a??i)}(o,u,e.type,this._opts.setChartType),qt(o,u)!==e.type&&Qt("chart type")),t.scale&&null!==e.scale&&null!==u&&o.setSeriesPriceScale(u,e.scale),t.settings.length&&e.settings){const n=i(o),a={};for(const o of t.settings)o in e.settings&&!Ft(n[o],e.settings[o])&&(a[o]=e.settings[o]);Object.keys(a).length&&r(o,a)}if(t.defaults.length){const n=o.priceScaleDefaults(),i={};for(const o of t.defaults){const t=e.defaults[o]??s[o];Ft(n[o]??s[o],t)||(i[o]=t)}Object.keys(i).length&&o.setPriceScaleOptions(i)}for(const n of e.panes){const e=c.has(n.key)?null:t.panes.get(n.key)?.axes;if(null!==e&&!e?.size)continue;const i=this._slot(n.key);i>=0&&this._axes(i,n,e??null);const a=o.panes()[i];if(null===e&&void 0!==a&&0===a.series().length)for(const[e,t]of Object.entries(n.ranges??{}))a.scaleFor(e).setComputedRange(t)}this._check(e,t)}_add(e,t,o){const n=this._chart,i=this._liveId(e.id),a={paneIndex:t,instanceId:i};null!==e.scale&&(a.priceScaleId=e.scale),Object.keys(e.plots).length&&(a.plotPriceScaleIds=e.plots);const r=this._policyOf(e.id);Object.keys(r).length&&(a.policy={...r});const s=this._liveSettings(e.settings);let l;try{l=n.addIndicator(e.indicatorId,s,a)}catch(t){if(!n.indicators().some(e=>e.id===i))throw t;const o={...a};delete o.instanceId,l=n.addIndicator(e.indicatorId,s,o)}if(this._bind(e.id,l),this._lastNames.set(l.id,e.id),l.id!==i)for(const t of o.studies){const o=Object.keys(t.settings).filter(o=>Wt(t.settings[o])&&t.settings[o].instanceId===e.id),n=o.length?this._find(t.id):void 0;if(void 0===n)continue;const i=n.settings(),a={};for(const e of o){const t=i[e];Wt(t)&&t.instanceId!==l.id&&(a[e]={...t,instanceId:l.id})}Object.keys(a).length&&n.setSettings(a)}e.visible||l.setVisible(!1)}_liveSettings(e){return Bt(e,e=>this._liveId(e))}_fit(e,t){const o=this._find(e.id);if(void 0===o)return;const n=this._liveSettings(e.settings),i=o.settings(),a={};for(const e of t.keys)e in n&&!Ft(i[e],n[e])&&(a[e]=n[e]);if(Object.keys(a).length&&o.setSettings(a),t.visible&&o.visible()!==e.visible&&o.setVisible(e.visible),!t.scale)return;o.priceScaleId()===e.scale||o.setPriceScale(e.scale)||Qt("scale");const r=o.plotPriceScaleIds(),s={};for(const[t,o]of Object.entries(e.plots))r[t]!==o&&(s[t]=o);for(const t of Object.keys(r))t in e.plots||(s[t]=null);Object.keys(s).length&&!o.setPlotPriceScales(s)&&Qt("scale")}_arrange(e){const t=this._chart,o=()=>t.panes().map(e=>this._keyOf(e)),n=e.panes.map(e=>e.key).filter(e=>o().includes(e)),i=o(),a=i.slice();let r=0;i.forEach((e,t)=>{n.includes(e)&&(a[t]=n[r++])});for(let e=0;e<a.length;e++)for(let n=o().indexOf(a[e]);n>e;n--)t.movePane(n,-1)||Qt("pane order")}_stack(e){const t=this._chart;for(const o of e.panes){const n=this._plan(this._view(),e,o.key);if(null===n||n.blocked)continue;const i=this._slot(o.key),{desired:a}=n,r=()=>t.indicators().filter(e=>e.paneIndex===i).map(e=>this._nameOf(e));for(let e=0;e<a.length;e++)for(let o=r().indexOf(a[e]);o>e;o--){(!1!==this._policyOf(a[e]).movable?t.reorderIndicator(this._liveId(a[e]),-1):t.reorderIndicator(this._liveId(r()[o-1]),1))||Qt("study order")}}}_axes(e,t,o){const n=this._chart,i=n.panes()[e],a=i.scaleStates();for(const[r,s]of Object.entries(t.axes)){const t=a[r],l=o?.get(r);if(void 0===t||null!==o&&void 0===l)continue;const c=e=>void 0===l||l.includes(e),d=r,u=n.priceAxisPlacement(e,d);!c("side")&&!c("order")||null===u||u.side===s.side&&u.order===s.order||n.setPriceAxisPlacement(e,d,s.side,s.order);const p={};c("mode")&&t.mode!==s.mode&&(p.mode=s.mode),c("inverted")&&t.inverted!==s.inverted&&(p.inverted=s.inverted),c("marginTop")&&!Ft(t.marginTop,s.marginTop)&&(p.marginTop=s.marginTop),c("marginBottom")&&!Ft(t.marginBottom,s.marginBottom)&&(p.marginBottom=s.marginBottom),Object.keys(p).length&&n.setPriceAxisOptions(e,d,p),c("auto")&&void 0!==s.auto&&t.autoScale!==s.auto&&n.setPriceAxisAutoFit(e,d,s.auto),c("lock")&&void 0!==s.lock&&i.ratioLocked(d)!==s.lock&&n.setPriceAxisLockRatio(e,d,s.lock)}}_check(e,t){const o=new Map(e.studies.map(e=>[e.id,e]));for(const[e,n]of t.studies){const t=o.get(e),i=this._find(e);void 0===t!=(void 0===i)&&Qt("study"),(n.presence||n.pane)&&void 0!==t&&void 0!==i&&this._slot(t.pane)!==i.paneIndex&&Qt("study pane")}if(t.paneOrder){const t=this._chart.panes().map(e=>this._keys.get(e)),o=e.panes.map(e=>e.key).filter(e=>t.includes(e));Ft(t.filter(e=>void 0!==e&&o.includes(e)),o)||Qt("pane order")}}_notify(){this._heard=this._ready();for(const e of[...this._listeners])try{e()}catch{}}_ready(){return this._destroyed?"":JSON.stringify([this.peekUndo(),this.peekRedo()])}_notifyIfMoved(){this._listeners.size>0&&this._ready()!==this._heard&&this._notify()}}function eo(){return"undefined"!=typeof navigator&&/mac|iphone|ipad/i.test(navigator.platform||navigator.userAgent||"")}new Set(["Mod","Ctrl","Meta","Alt","Shift"]);new Set([{command:"panLeft",label:"Pan left",combos:["ArrowLeft"]},{command:"panRight",label:"Pan right",combos:["ArrowRight"]},{command:"panLeftFast",label:"Pan left (fast)",combos:["Mod+ArrowLeft"]},{command:"panRightFast",label:"Pan right (fast)",combos:["Mod+ArrowRight"]},{command:"panUp",label:"Pan up",combos:["ArrowUp"]},{command:"panDown",label:"Pan down",combos:["ArrowDown"]},{command:"zoomIn",label:"Zoom in",combos:["Equal","Shift+Equal","NumpadAdd"]},{command:"zoomOut",label:"Zoom out",combos:["Minus","NumpadSubtract"]},{command:"resetScale",label:"Reset view",combos:["Home","Digit0"]},{command:"fitContent",label:"Fit all bars",combos:["Alt+KeyF"]},{command:"screenshot",label:"Screenshot (PNG)",combos:["Alt+Shift+KeyS"]},{command:"toggleGridVert",label:"Toggle vertical grid",combos:["Alt+KeyV"]},{command:"toggleGridHorz",label:"Toggle horizontal grid",combos:["Alt+KeyH"]},{command:"toggleCrosshairMagnet",label:"Toggle crosshair magnet",combos:["Alt+KeyM"]}].map(e=>e.command));const to="keymap",oo="chart:",no={mod:"Mod",ctrl:"Mod",control:"Mod",cmd:"Mod",command:"Mod",meta:"Mod",win:"Mod",alt:"Alt",option:"Alt",opt:"Alt",shift:"Shift"},io={esc:"Escape",escape:"Escape",del:"Delete",delete:"Delete",backspace:"Backspace",enter:"Enter",return:"Enter",tab:"Tab",space:"Space",spacebar:"Space",left:"ArrowLeft",right:"ArrowRight",up:"ArrowUp",down:"ArrowDown",arrowleft:"ArrowLeft",arrowright:"ArrowRight",arrowup:"ArrowUp",arrowdown:"ArrowDown",home:"Home",end:"End",pageup:"PageUp",pagedown:"PageDown",insert:"Insert",plus:"+",minus:"-",question:"?",slash:"/",period:".",comma:","},ao=new Set(["Shift","Control","Alt","Meta","OS","AltGraph","CapsLock","Fn"]),ro=["Mod","Alt","Shift"];function so(e){const t=e.trim();if(""===t)return"";let o,n;if("+"===t)o="+",n=[];else if(t.endsWith("++"))o="+",n=t.slice(0,-2).split("+").map(e=>e.trim());else{const e=t.split("+").map(e=>e.trim());o=e[e.length-1],n=e.slice(0,-1)}if(""===o||void 0!==no[o.toLowerCase()])return"";const i=new Set;for(const e of n){const t=no[e.toLowerCase()];if(void 0===t)return"";i.add(t)}o=function(e){const t=e.toLowerCase();return void 0!==io[t]?io[t]:/^f([1-9]|1[0-2])$/.test(t)?t.toUpperCase():1===e.length&&/[a-z]/i.test(e)?t:e}(o),1!==o.length||/[a-z]/.test(o)||i.delete("Shift");return[...ro.filter(e=>i.has(e)),o].join("+")}function lo(e){let t=e.key??"";if(""===t||"Unidentified"===t||ao.has(t))return"";" "!==t&&"Spacebar"!==t||(t="Space"),"Esc"===t&&(t="Escape"),"Del"===t&&(t="Delete");const o=e.code??"";!0===e.altKey&&/^Key[A-Z]$/.test(o)&&(t=o.slice(3).toLowerCase());const n=[];return!0!==e.ctrlKey&&!0!==e.metaKey||n.push("Mod"),!0===e.altKey&&n.push("Alt"),1===t.length?/[a-z]/i.test(t)&&(t=t.toLowerCase(),!0===e.shiftKey&&n.push("Shift")):!0===e.shiftKey&&n.push("Shift"),[...n,t].join("+")}const co={Escape:"Esc",Delete:"Del",ArrowLeft:"Left",ArrowRight:"Right",ArrowUp:"Up",ArrowDown:"Down"};function uo(e,t=eo()){const o=so(e);if(""===o)return"";const n=o.split("+"),i=n[n.length-1];return[...n.slice(0,-1).map(e=>"Mod"===e?t?"Cmd":"Ctrl":"Alt"===e?t?"Opt":"Alt":"Shift"),co[i]??(1===i.length?i.toUpperCase():i)].join("+")}const po={Equal:"=+",Minus:"-_",Slash:"/?",Comma:",<",Period:".>",Semicolon:";:",Quote:"'\"",BracketLeft:"[{",BracketRight:"]}",Backslash:"\\|",Backquote:"`~",Digit1:"1!",Digit2:"2@",Digit3:"3#",Digit4:"4$",Digit5:"5%",Digit6:"6^",Digit7:"7&",Digit8:"8*",Digit9:"9(",Digit0:"0)",NumpadAdd:"++",NumpadSubtract:"--",NumpadMultiply:"**",NumpadDivide:"//",NumpadDecimal:".."};function ho(e){const t=e.split("+").map(e=>e.trim()).filter(e=>""!==e);if(0===t.length)return"";const o=t[t.length-1],n=t.slice(0,-1).map(e=>"Alt"===e?"Alt":"Shift"===e?"Shift":"Mod");let i;const a=/^Key([A-Z])$/.exec(o),r=/^Numpad([0-9])$/.exec(o);return i=null!==a?a[1].toLowerCase():null!==r?r[1]:void 0!==po[o]?po[o][n.includes("Shift")?1:0]:"NumpadEnter"===o?"Enter":o,so([...n,i].join("+"))}function mo(e){const t=e.split("+"),o=t.pop()??"";return/^[a-z]$/.test(o)&&c([...t,"Key"+o.toUpperCase()].join("+"))}const go=new Set(["global","widget","chart"]),fo=(e,t)=>e===t||go.has(e)&&go.has(t),bo=e=>"rail"!==e&&"overlay"!==e,vo=new Set,wo=(e,t=[])=>({ok:!1,reason:e,conflicts:t}),_o=(e,t)=>e===t||null!==e&&null!==t&&e.length===t.length&&e.every((e,o)=>e===t[o]);class yo{constructor(e={}){Object.defineProperty(this,"_isMac",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_chart",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_scopes",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_bindings",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_byCombo",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_conflictListeners",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"_changeListeners",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"_overrides",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_chartOverrides",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_chartBaseline",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_capture",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_detach",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_target",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_nextId",{enumerable:!0,configurable:!0,writable:!0,value:1}),this._isMac=e.isMac??eo(),this._chart=e.chart??null,this._scopes=e.scopes??(()=>["global"])}get isMac(){return this._isMac}setScopes(e){this._scopes=e}activeScopes(){return this._scopes()}register(e,t,o="global",n={}){const i=so(e);if(""===i)throw new Error(`openalgo-charts widget: "${e}" is not a key binding`);const a=n.command??null;if(null!==a&&(""===a||a.startsWith(oo)||this._bindings.some(e=>e.command===a)))throw new Error(`openalgo-charts widget: "${a}" is not a free command name`);const r=null!==a&&!1!==n.rebindable,s=null!==a&&r?this._overrides.get(a):void 0,l={id:this._nextId++,combo:void 0===s?i:s??"",defaultCombo:i,command:a,rebindable:r,scope:o,label:n.label??uo(i,this._isMac),group:n.group??"Widget",hidden:!0===n.hidden,inText:!0===n.inText,layered:!0===n.layered,action:t,when:n.when},c=this._conflictKeys();return this._bindings.push(l),this._index(l),null!==c&&this._announce(c),()=>this._unregister(l)}_index(e){if(""===e.combo)return;const t=this._byCombo.get(e.combo)??[];let o=t.length;for(;o>0&&t[o-1].id>e.id;)o--;t.splice(o,0,e),this._byCombo.set(e.combo,t)}_unindex(e){const t=this._byCombo.get(e.combo);if(void 0===t)return;const o=t.indexOf(e);o>=0&&t.splice(o,1),0===t.length&&this._byCombo.delete(e.combo)}_unregister(e){const t=this._bindings.indexOf(e);t>=0&&this._bindings.splice(t,1),this._unindex(e)}_widgetConflicts(){const e=[];for(const t of this._bindings){if(t.layered||""===t.combo)continue;const o=this._byCombo.get(t.combo)??[],n=o.slice(0,o.indexOf(t)).find(e=>e.scope===t.scope);void 0!==n&&e.push({combo:t.combo,scope:t.scope,kept:n.label,shadowed:t.label,source:"widget"})}return e}_conflictKeys(){return 0===this._conflictListeners.size?null:new Set(this._widgetConflicts().map(e=>`${e.combo}|${e.scope}|${e.kept}|${e.shadowed}`))}_announce(e){for(const t of this._widgetConflicts())if(!e.has(`${t.combo}|${t.scope}|${t.kept}|${t.shadowed}`))for(const e of this._conflictListeners)e(t)}onConflict(e){return this._conflictListeners.add(e),()=>this._conflictListeners.delete(e)}onChange(e){return this._changeListeners.add(e),()=>this._changeListeners.delete(e)}_emit(e){const t=Array.from(new Set(Array.from(e).filter(e=>null!==e)));if(0!==t.length)for(const e of this._changeListeners)e({commands:t})}capture(e){return this._capture=e,vo.add(this),()=>{this._capture===e&&(this._capture=null,vo.delete(this))}}get capturing(){return null!==this._capture}handle(e){if(null!==this._capture)return!1!==this._capture(e)&&(e.preventDefault?.(),void 0!==e.stopImmediatePropagation?e.stopImmediatePropagation():e.stopPropagation?.(),!0);if(null!==this._target)for(const e of vo)if(e!==this&&e._target===this._target)return!1;const t=lo(e);if(""===t)return!1;const o=this._byCombo.get(t);if(void 0===o)return!1;const n=Ve(e.target);for(const t of this._scopes())for(const i of o.slice())if(i.scope===t&&(!n||i.inText)&&(void 0===i.when||i.when())&&!1!==i.action(e))return e.preventDefault?.(),e.stopPropagation?.(),!0;return!1}attach(e){this._detach?.();const t=e=>{this.handle(e)};return e.addEventListener("keydown",t,!0),this._target=e,this._detach=()=>{e.removeEventListener("keydown",t,!0),this._detach=null,this._target=null},this._detach}list(){return this._bindings.slice()}conflicts(){const e=this._widgetConflicts();if(null!==this._chart)for(const t of this._chart.list())if(!t.isDisabled)for(const o of t.combos){const n=ho(o),i=(this._byCombo.get(n)??[]).find(e=>bo(e.scope)&&!e.layered);void 0!==i&&e.push({combo:n,scope:i.scope,kept:i.label,shadowed:t.label,source:"chart"})}return e}format(e){return uo(e,this._isMac)}_use(e){return{command:e.command,label:e.label,group:e.group,source:"widget",rebindable:e.rebindable}}_chartEditable(){const e=this._chart;return null!==e&&"function"==typeof e.setBinding&&"function"==typeof e.disable&&"function"==typeof e.resetBinding}_chartUse(e){return{command:oo+e.command,label:e.label,group:"Chart",source:"chart",rebindable:this._chartEditable()}}_holders(e,t,o){const n=[];for(const i of this._byCombo.get(e)??[])null!==o&&i.command===o||!fo(i.scope,t)||n.push(this._use(i));if(null!==this._chart&&bo(t))for(const t of this._chart.list())t.isDisabled||oo+t.command===o||t.combos.some(t=>ho(t)===e)&&n.push(this._chartUse(t));return n}_chartHolders(e,t){const o=[],n=this._chart;if(null===n)return o;for(const i of n.list())i.isDisabled||i.command===t||i.combos.some(t=>e.includes(t))&&o.push(this._chartUse(i));const i=new Set;for(const t of e)for(const e of this._byCombo.get(ho(t))??[])e.layered||!bo(e.scope)||i.has(e)||(i.add(e),o.push(this._use(e)));return o}conflictsFor(e,t="widget"){const o=so(e);return""===o?[]:this._holders(o,t,null)}chord(e){if(e.startsWith(oo)){const t=this._chart?.list().find(t=>oo+t.command===e);return void 0===t?null:t.isDisabled||0===t.combos.length?"":ho(t.combos[0])}const t=this._bindings.find(t=>t.command===e);return void 0===t?null:t.combo}_setWidget(e,t){e.combo!==t&&(this._unindex(e),e.combo=t,this._index(e));const o=e.command;t===e.defaultCombo?this._overrides.delete(o):this._overrides.set(o,""===t?null:t)}_chartNow(e){const t=this._chart?.list().find(t=>t.command===e);return void 0===t?void 0:t.isDisabled?null:t.combos.slice()}_base(e){const t=this._chartBaseline??(this._chartBaseline=new Map);return t.has(e)||t.set(e,this._chartNow(e)??null),t.get(e)}_setChart(e,t){const o=this._chart,n=this._base(e),i=()=>{null===t?o.disable(e):o.setBinding(e,t)};if(_o(n,t))return o.resetBinding(e),_o(this._chartNow(e)??null,t)||i(),void this._chartOverrides.delete(e);i(),this._chartOverrides.set(e,t)}_dropChart(e,t){const o=e.command.slice(6),n=(this._chartNow(o)??[]).filter(e=>!t(e));this._setChart(o,n.length>0?n:null)}_dropWidget(e){const t=this._bindings.find(t=>t.command===e.command);void 0!==t&&this._setWidget(t,"")}rebind(e,t,o={}){return this._rebind(e,t,!0===o.replace,!1)}reset(e,t={}){return this._rebind(e,void 0,!0===t.replace,!0)}resetAll(){const e=this._clearAll();this._emit(e)}_clearAll(){const e=[];for(const t of Array.from(this._overrides.keys())){const o=this._bindings.find(e=>e.command===t);void 0!==o&&this._setWidget(o,o.defaultCombo),this._overrides.delete(t),e.push(t)}for(const t of Array.from(this._chartOverrides.keys()))this._setChart(t,this._base(t)),e.push(oo+t);return e}_rebind(e,t,o,n){if(e.startsWith(oo))return this._rebindChart(e.slice(6),t,o,n);const i=this._bindings.find(t=>t.command===e);if(void 0===i)return n&&this._overrides.delete(e)&&this._emit([e]),n?{ok:!0,conflicts:[]}:wo("unknown");if(!i.rebindable)return wo("fixed");let a=i.defaultCombo;if(!n&&(a="",null!=t)){const e="string"==typeof t?[t]:t;if(a=1===e.length?so(e[0]):"",""===a)return wo("invalid");if(mo(a))return wo("reserved")}if(a===i.combo)return{ok:!0,conflicts:[]};const r=""===a?[]:this._holders(a,i.scope,e).filter(e=>!n||"widget"===e.source);if(r.length>0){if(!o||r.some(e=>!e.rebindable))return wo("taken",r);for(const e of r)"chart"===e.source?this._dropChart(e,e=>ho(e)===a):this._dropWidget(e)}return this._setWidget(i,a),this._emit([e,...r.map(e=>e.command)]),{ok:!0,conflicts:r}}_rebindChart(e,t,o,n){const i=null===this._chart?void 0:this._chartNow(e);if(void 0===i)return wo("unknown");if(!this._chartEditable())return wo("fixed");let a=null;if(n)a=this._base(e);else if(null!=t){const e=("string"==typeof t?[t]:Array.from(t)).map(l);if(0===e.length||e.includes(""))return wo("invalid");if(e.some(e=>c(e)))return wo("reserved");a=Array.from(new Set(e))}if(_o(a,i))return n&&this._chartOverrides.delete(e)&&this._emit([oo+e]),{ok:!0,conflicts:[]};const r=null===a?[]:this._chartHolders(a,e).filter(e=>!n||"chart"===e.source);if(r.length>0){if(!o||r.some(e=>!e.rebindable))return wo("taken",r);const e=a;for(const t of r)"chart"===t.source?this._dropChart(t,t=>e.includes(t)):this._dropWidget(t)}return this._setChart(e,a),this._emit([oo+e,...r.map(e=>e.command)]),{ok:!0,conflicts:r}}overrides(){const e={};for(const[t,o]of this._overrides)e[t]=o;for(const[t,o]of this._chartOverrides)e[oo+t]=null===o?null:o.slice();return e}applyOverrides(e){const t=new Map,o=new Map;if(null!==e&&"object"==typeof e&&!Array.isArray(e))for(const[n,i]of Object.entries(e))if(n.startsWith(oo)){const e=n.slice(6),t=null===i?null:(Array.isArray(i)?i:[i]).map(e=>"string"==typeof e?l(e):"");if(""===e||null!==t&&(0===t.length||t.some(e=>""===e||c(e))))continue;o.set(e,t)}else if(""!==n&&(null===i||"string"==typeof i)){const e=null===i?null:so(i);if(""===e||null!==e&&mo(e))continue;const o=this._bindings.find(e=>e.command===n);if(void 0!==o&&!o.rebindable)continue;t.set(n,e)}const n=this._conflictKeys(),i=new Map(this._bindings.map(e=>[e,e.combo])),a=this.overrides();this._clearAll();for(const[e,o]of t){const t=this._bindings.find(t=>t.command===e);void 0===t?this._overrides.set(e,o):this._setWidget(t,o??"")}if(this._chartEditable())for(const[e,t]of o)void 0!==this._chartNow(e)&&this._setChart(e,t);null!==n&&this._announce(n);const r=this.overrides(),s=this._bindings.filter(e=>null!==e.command&&i.get(e)!==e.combo).map(e=>e.command);for(const e of new Set([...Object.keys(a),...Object.keys(r)]))JSON.stringify(a[e])!==JSON.stringify(r[e])&&s.push(e);this._emit(s)}_chartDefault(e,t){const o=this._chartBaseline?.get(e),n=void 0===o?t:o??[];return 0===n.length?"":ho(n[0])}describe(){const e=new Map;for(const t of this._bindings){if(t.hidden)continue;const o=e.get(t.group)??[],n={label:t.label,combo:t.combo,display:this.format(t.combo)};null!==t.command&&(n.command=t.command,n.rebindable=t.rebindable,n.defaultCombo=t.defaultCombo,n.changed=t.combo!==t.defaultCombo),o.push(n),e.set(t.group,o)}const t=Array.from(e,([e,t])=>({group:e,rows:t}));if(null!==this._chart){const e=new Map;for(const t of this.conflicts())"chart"===t.source&&e.set(t.shadowed+"|"+t.combo,t.kept);const o=this._chartEditable(),n=[];for(const t of this._chart.list()){const i=this._chartOverrides.has(t.command);if((t.isDisabled||0===t.combos.length)&&!i)continue;const a=t.isDisabled||0===t.combos.length?"":ho(t.combos[0]),r={label:t.label,combo:a,display:this.format(a),command:oo+t.command,rebindable:o,defaultCombo:this._chartDefault(t.command,t.combos),changed:i},s=e.get(t.label+"|"+a);void 0!==s&&(r.shadowedBy=s),n.push(r)}n.length>0&&t.push({group:"Chart",rows:n})}return t}destroy(){this._detach?.(),this._capture=null,vo.delete(this),this._bindings.length=0,this._byCombo.clear(),this._overrides.clear(),this._chartOverrides.clear(),this._conflictListeners.clear(),this._changeListeners.clear()}}function xo(e){const t={Ctrl:"Control",Cmd:"Meta",Opt:"Alt",Del:"Delete",Esc:"Escape",Left:"ArrowLeft",Right:"ArrowRight",Up:"ArrowUp",Down:"ArrowDown"};return e.split("+").map(e=>t[e]??e).join("+")}function ko(e,t,o){const n=e,i=("function"==typeof n?.chord?n.chord(t):null)??o;if(void 0!==i&&""!==i)return"function"==typeof n?.format?n.format(i):uo(i)}const Co=new WeakSet;const So=Tt(()=>import("./openalgo-charts.widget.keymap-editor-Uozy6qFE.mjs")),Ao=new WeakMap;function Lo(e,t={}){let o=null,n=!0,i=Ao.get(e);return void 0===i&&Ao.set(e,i={waiting:null}),Pt(So,n=>{o=n.mountShortcutsPanel(e,t.edit??!Co.has(e.keymap))},t=>e.toast(jt(e,kt(e,"Keyboard shortcuts"),t),"error"),()=>n&&!e.chart.isDestroyed,{slot:i,doc:e.document}),()=>{n=!1,o?.()}}const Oo=["#4f8cff","#26a69a","#ef5350","#f4b740","#ab79df","#22a8bd","#e88555","#9aa6b2","#ffffff","#000000"],$o=[];function Eo(e){if("string"!=typeof e||e.length>256)return null;const t=e.trim(),o=/^#([\da-f]{3}|[\da-f]{4}|[\da-f]{6}|[\da-f]{8})$/i.exec(t);if(null!==o){let e=o[1].toLowerCase();e.length<=4&&(e=e.split("").map(e=>e+e).join(""));const t=8===e.length?parseInt(e.slice(6),16)/255:1;return{hex:`#${e.slice(0,6)}`,alpha:t,format:8===e.length?"hexAlpha":"hex"}}const n=t.toLowerCase(),i=n.startsWith("rgba(")?5:n.startsWith("rgb(")?4:0;if(0===i||!t.endsWith(")"))return null;const a=t.slice(i,-1);let r,s;if(a.includes(",")){const e=a.split(",").map(e=>e.trim());if(3!==e.length&&4!==e.length)return null;r=e.slice(0,3),s=e[3]}else{const e=a.split("/");if(e.length>2)return null;r=e[0].trim().split(/\s+/),s=e[1]?.trim()}if(3!==r.length||r.some(e=>!/^\d{1,3}$/.test(e)))return null;const l=r.map(Number);if(l.some(e=>e>255))return null;if(void 0!==s){const e=s.split(".");if(e.length>2||e.every(e=>""===e)||e.some(e=>/\D/.test(e)))return null}const c=void 0===s?1:Number(s);return!Number.isFinite(c)||c<0||c>1?null:{hex:`#${l.map(e=>e.toString(16).padStart(2,"0")).join("")}`,alpha:c,format:void 0===s?"hex":"rgba"}}function To(e,t,o){if("hex"===o)return e;if("hexAlpha"===o)return`${e}${Math.round(255*t).toString(16).padStart(2,"0")}`;return`rgba(${[1,3,5].map(t=>parseInt(e.slice(t,t+2),16)).join(",")},${Number(t.toFixed(3))})`}function Po(e,t){const o=(t,o)=>{const n=e.createElement(t);return n.className=o,n},n=e=>kt(t,`schema.ui.colorPicker.${e}`,{},e),i=o("span","oac-color"),a=o("input","oac-swatch-input");a.type="color",a.id=t.id,a.tabIndex=-1,a.setAttribute("aria-hidden","true"),a.setAttribute("aria-label",t.label);const r=o("button","oac-color__trigger");r.type="button",r.id=`${t.id}-trigger`,r.setAttribute("aria-label",t.label),r.setAttribute("aria-haspopup","dialog"),r.setAttribute("aria-expanded","false"),null!==t.disabledReason&&void 0!==t.disabledReason?(r.disabled=!0,a.disabled=!0,r.title=t.disabledReason,a.title=t.disabledReason):(r.title=t.label,a.title=t.label),i.appendChild(a),i.appendChild(r);const s=o("div","oac-color__popover");s.hidden=!0,s.setAttribute("role","dialog"),s.setAttribute("aria-label",n("Color"));const l=o("div","oac-color__palette");l.setAttribute("aria-label",n("Palette"));const c=o("div","oac-color__recent");c.setAttribute("aria-label",n("Recent"));const d=o("button","oac-color__custom");d.type="button",d.textContent=n("Custom"),d.addEventListener("click",()=>{v||a.click()}),s.appendChild(l),s.appendChild(c),s.appendChild(d),i.appendChild(s);let u,p,h,m=t.value,g=Eo(m),f=g?.alpha??1,b=!1,v=!1;const w=()=>{a.value=g?.hex??"#000000",r.style.backgroundColor=null===g?"#000000":To(g.hex,f,g.format),void 0!==p&&(p.value=String(Math.round(100*f)),void 0!==h&&(h.textContent=`${p.value}%`))},_=(e,o=f)=>{if(v||r.disabled||!/^#[\da-f]{6}$/i.test(e))return;const n=g?.format??"hex";m=To(e.toLowerCase(),o,n),g={hex:e.toLowerCase(),alpha:o,format:n},f=o,w(),function(e){const t=$o.indexOf(e);t>=0&&$o.splice(t,1),$o.unshift(e),$o.length=Math.min($o.length,6)}(g.hex),t.onChange(m)},y=(e,t)=>{e.innerHTML="";for(const n of t){const t=o("button","oac-color__choice");t.type="button",t.setAttribute("aria-label",n),t.title=n,t.style.backgroundColor=n,t.addEventListener("click",()=>{_(n),C(),r.focus()}),e.appendChild(t)}},x=e=>{i.contains(e.target)||s.contains(e.target)||C()},k=()=>{b&&(u=void 0,b=!1,s.hidden=!0,r.setAttribute("aria-expanded","false"),e.removeEventListener("pointerdown",x,!0),g=Eo(m),f=g?.alpha??1,w(),v||s.parentNode===i||i.appendChild(s))},C=()=>{const e=u;u=void 0,e?.(),k()},S=()=>{if(!(v||b||r.disabled))if(b=!0,function(){if(void 0!==p||null===g||"hex"===g.format)return;const i=o("label","oac-color__opacity");i.appendChild(e.createTextNode(n("Opacity"))),p=o("input","oac-color__range"),p.type="range",p.min="0",p.max="100",p.step="1",h=o("output","oac-color__percent");const r=p,l=h;r.addEventListener("input",()=>{f=Number(r.value)/100,l.textContent=`${r.value}%`,t.live&&_(a.value,f)}),r.addEventListener("change",()=>_(a.value,Number(r.value)/100)),i.appendChild(r),i.appendChild(l),s.appendChild(i)}(),w(),y(l,Oo),y(c,$o),c.hidden=0===$o.length,s.hidden=!1,r.setAttribute("aria-expanded","true"),t.openOverlay){s.classList.remove("oac-color__popover--above"),r.focus();const e=t.openOverlay(s,{anchor:r,placement:"below",modal:!1,initialFocus:l.querySelector("button"),onClose:k});b?u=e:e()}else{const t=i.closest(".oac-widget");if(null!==t){const e=t.getBoundingClientRect().bottom;s.classList.toggle("oac-color__popover--above",r.getBoundingClientRect().bottom+s.offsetHeight>e)}e.addEventListener("pointerdown",x,!0),l.querySelector("button")?.focus()}};r.addEventListener("click",()=>b?C():S());const A=e=>{"Escape"===e.key&&b&&(e.preventDefault(),e.stopPropagation(),C(),r.focus())};return i.addEventListener("keydown",A),s.addEventListener("keydown",A),s.addEventListener("pointerdown",e=>e.stopPropagation()),a.addEventListener("input",()=>{t.live&&_(a.value)}),a.addEventListener("change",()=>_(a.value)),w(),{el:i,input:a,trigger:r,read:()=>m,write:e=>{m=e,g=Eo(e),f=g?.alpha??1,w()},destroy:()=>{v||(v=!0,C(),s.remove(),i.removeEventListener("keydown",A),s.removeEventListener("keydown",A))}}}const jo="\n.oac-widget .oac-color { position: relative; display: inline-flex; width: 27px; height: 27px; flex: 0 0 27px; }\n.oac-widget .oac-color > .oac-swatch-input { position: absolute; inset: 0; width: 27px; height: 27px; padding: 0; opacity: 0; pointer-events: none; }\n.oac-widget .oac-color__trigger { position: absolute; inset: 0; width: 27px; height: 27px; border: 1px solid var(--oac-bd); border-radius: 5px; background: transparent; cursor: pointer; }\n.oac-widget .oac-color__trigger:focus-visible { outline: 2px solid var(--oac-ring); outline-offset: 2px; }\n.oac-widget .oac-color__trigger:disabled { cursor: not-allowed; opacity: .5; }\n.oac-widget .oac-color__popover { position: absolute; z-index: 80; top: 30px; right: 0; width: 188px; padding: 9px; border: 1px solid var(--oac-bd); border-radius: 7px; background: var(--oac-elev); color: var(--oac-tx); box-shadow: var(--oac-shadow); }\n.oac-widget .oac-color__popover--above { top: auto; bottom: 30px; }\n.oac-widget .oac-color__popover.oac-pop { right: auto; bottom: auto; min-width: 0; max-width: calc(100% - 16px); max-height: calc(100% - 16px); overflow: auto; }\n.oac-widget .oac-color__popover[hidden], .oac-widget .oac-color__recent[hidden] { display: none; }\n.oac-widget .oac-color__palette, .oac-widget .oac-color__recent { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; margin-bottom: 7px; }\n.oac-widget .oac-color__choice { width: 28px; height: 28px; padding: 0; border: 1px solid var(--oac-bd); border-radius: 5px; background: transparent; overflow: hidden; cursor: pointer; }\n.oac-widget .oac-color__custom { width: 100%; padding: 5px; border: 1px solid var(--oac-bd); border-radius: 4px; background: transparent; color: inherit; cursor: pointer; }\n.oac-widget .oac-color__opacity { display: flex; align-items: center; gap: 5px; margin-top: 7px; font-size: 11px; }\n.oac-widget .oac-color__range { min-width: 0; flex: 1; }\n.oac-widget .oac-color__percent { min-width: 30px; text-align: right; }\n";function Mo(e,t){if(null===e||"object"!=typeof e)return!0;const o=e;if(Array.isArray(o.all))return o.all.every(e=>Mo(e,t));if(Array.isArray(o.any))return o.any.some(e=>Mo(e,t));if("string"!=typeof o.key)return!0;const n=((e,t)=>Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0)(t,o.key),i=e=>(Array.isArray(e)?e:[e]).includes(n);return"is"in o?i(o.is):!("isNot"in o)||!i(o.isNot)}function Io(e,t=[]){if(null===e||"object"!=typeof e)return t;const o=e,n=Array.isArray(o.all)?o.all:Array.isArray(o.any)?o.any:null;if(null!==n)for(const e of n)Io(e,t);else"string"!=typeof o.key||t.includes(o.key)||t.push(o.key);return t}function Do(e,t){const o=new Map;for(const t of e){const e=t.pair??t;for(const n of[e.enabled,e.up,e.down])"string"==typeof n?.key&&o.set(n.key,t)}for(const t of e)o.set(t.key,t);const n=new Map,i=new Set,a=e=>{const r=o.get(e);if(void 0===r||i.has(r))return;let s=n.get(r.key);if(void 0!==s)return s;i.add(r);const l=Io(r.activeWhen),c=Mo(r.visibleWhen,t)&&Io(r.visibleWhen).every(e=>!1!==a(e)?.visible),d=Mo(r.activeWhen,t)&&l.every(e=>{const t=a(e);return void 0===t||t.visible&&t.active});return i.delete(r),s={visible:c,active:d,dependsOn:l},n.set(r.key,s),s};for(const t of e)a(t.key);return n}const zo=["1m","3m","5m","15m","30m","1h","2h","4h","1d","1w"];function No(e){const t=new Set,o=[{label:"Chart",value:""}];for(const n of e??[...zo,...u().map(e=>e.code)]){const e=n.toLowerCase();t.has(e)||(t.add(e),o.push({label:n,value:n}))}return o}function Ro(e,t,o){const n=[];for(const t of e){const e=n.length;switch(t.type){case"colorPair":n.push({key:t.key,kind:"colorPair",label:t.label,group:t.group,pair:{enabled:void 0===t.enabled?void 0:{key:t.enabled.key},up:{key:t.up.key,label:t.up.label},down:{key:t.down.key,label:t.down.label}}});break;case"number":n.push({key:t.key,kind:"number",label:t.label,group:t.group,min:t.min,max:t.max,step:t.step});break;case"price":case"timestamp":n.push({key:t.key,kind:t.type,label:t.label,group:t.group,min:t.min,max:t.max,step:t.step});break;case"select":n.push({key:t.key,kind:"select",label:t.label,group:t.group,options:t.options});break;case"source":n.push({key:t.key,kind:"select",label:t.label,group:t.group,options:d});break;case"interval":n.push({key:t.key,kind:"select",label:t.label,group:t.group,options:No(o)});break;case"time":n.push({key:t.key,kind:"text",label:t.label,group:t.group});break;case"boolean":case"color":case"text":case"symbol":case"session":case"multiline":n.push({key:t.key,kind:t.type,label:t.label,group:t.group})}if(n.length>e){const o=n[e];void 0!==t.tooltip&&(o.tooltip=t.tooltip),void 0!==t.activeWhen&&(o.activeWhen=t.activeWhen),void 0!==t.visibleWhen&&(o.visibleWhen=t.visibleWhen),"colorPair"!==t.type&&void 0!==t.inline&&(o.inline=t.inline)}}return Fo(n,t)}function Fo(e,t){if(void 0===t?.translate)return e;const o=(e,o)=>kt(t,`schema.${t.scope}.${e}`,{},o);return e.map(e=>({...e,label:o(`${e.key}.label`,e.label),group:void 0===e.group?void 0:o(`group.${e.group}`,e.group),tooltip:void 0===e.tooltip?void 0:o(`${e.key}.tooltip`,e.tooltip),options:e.options?.map(t=>({...t,label:t.label===t.value?t.label:o(`${e.key}.option.${t.value}`,t.label)})),pair:void 0===e.pair?void 0:{...e.pair,up:{...e.pair.up,label:o(`${e.pair.up.key}.label`,e.pair.up.label)},down:{...e.pair.down,label:o(`${e.pair.down.key}.label`,e.pair.down.label)}}}))}const Wo={line:"Line",fill:"Fill",text:"Text",levels:"Levels",behavior:"Behavior"};function Bo(e,t){const o=[];for(const t of e){const e=void 0===t.group?void 0:Wo[t.group]??t.group,n={key:t.path,label:t.label,group:e};switch(t.kind){case"color":o.push({...n,kind:"color"});break;case"number":o.push({...n,kind:"number",min:t.min,max:t.max,step:t.step});break;case"opacity":o.push({...n,kind:"opacity"});break;case"boolean":o.push({...n,kind:"boolean"});break;case"select":case"lineStyle":o.push(void 0===t.options?{...n,kind:"text"}:{...n,kind:"select",options:t.options});break;case"text":o.push({...n,kind:"text.value"===t.path?"multiline":"text"});break;case"levels":o.push({...n,kind:"custom",custom:"levels"})}}return Fo(o,t)}function qo(e,t,o,n){const i=Ke(e,t,o);return void 0!==n&&(i.textContent=n),i}function Uo(e){return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16" fill="none" stroke="currentColor" stroke-width="${re}" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="${e}"/></svg>`}function Ho(e,t){return Ge(e,ie(t),"chrome")}function Ko(e,t){const o=qo(e,"button");o.type="button";const n=["oac-btn"];if(!0===t.iconOnly&&n.push("oac-btn--icon"),"primary"===t.variant&&n.push("oac-btn--primary"),"danger"===t.variant&&n.push("oac-btn--danger"),o.className=n.join(" "),void 0!==t.icon&&o.appendChild(Ho(e,t.icon)),!0===t.iconOnly?(o.setAttribute("aria-label",t.label),o.title=void 0===t.chord?t.label:`${t.label} (${t.chord})`):(o.appendChild(e.createTextNode(t.label)),void 0!==t.chord&&(o.title=t.chord)),void 0!==t.onClick){const e=t.onClick;o.addEventListener("click",t=>{t.stopPropagation(),e(t)})}return o}function Go(e){const t=qo(e,"span","oac-select"),o=qo(e,"select");t.appendChild(o);const n=qo(e,"span","oac-chev");return n.innerHTML=ie("chevron-down"),t.appendChild(n),{wrap:t,select:o}}function Vo(e){e.addEventListener("keydown",e=>{const t=e.key;"Escape"!==t&&"Tab"!==t&&e.stopPropagation()}),e.addEventListener("pointerdown",e=>{e.stopPropagation()})}let Jo=0;function Yo(e,t){const o=qo(e,"div","oac-panel"+(void 0===t.className?"":" "+t.className));o.setAttribute("role","dialog"),o.tabIndex=-1;const n="oac-dlg-title-"+ ++Jo;o.setAttribute("aria-labelledby",n);const i=qo(e,"div","oac-dialog__head"),a=qo(e,"span","oac-dialog__title",t.title);a.id=n;const r=Ko(e,{label:kt(t,"Close"),...!0===t.closeText?{}:{icon:"close",iconOnly:!0},onClick:()=>t.onClose()});i.appendChild(a),i.appendChild(r);const s=qo(e,"div","oac-dialog__body"),l=qo(e,"div","oac-dialog__foot"),c=qo(e,"div","oac-dialog__lead"),d=qo(e,"div","oac-spacer"),u=qo(e,"div","oac-dialog__actions");return l.appendChild(c),l.appendChild(d),l.appendChild(u),o.appendChild(i),o.appendChild(s),o.appendChild(l),Vo(o),{el:o,head:i,body:s,foot:l,lead:c,actions:u,closeButton:r,setTitle:e=>{a.textContent=e}}}function Zo(e,t){return e.toast(t,"info"),{el:e.document.createElement("div"),close:()=>{},isOpen:()=>!1}}function Qo(e,t,o,n){let i,a=!1,r=!1;const s=e.openOverlay(t,{...o,onClose:()=>{o.onClose?.(),a||(r=!0,n(),d())}}),l=t.closest(".oac-widget"),c=t.querySelectorAll(".oac-tabs--rail");if(null!==l&&c.length>0){const e=()=>{const e=l.getBoundingClientRect().width<=720?"horizontal":"vertical";c.forEach(t=>t.setAttribute("aria-orientation",e))};e();const o=t.ownerDocument.defaultView?.ResizeObserver;void 0!==o&&(i=new o(e),i.observe(l))}function d(){a||(a=!0,i?.disconnect(),r||s(),t.remove())}return{el:t,close:d,isOpen:()=>!a}}function Xo(e,t,o,n){const i=t.panes()[0]?.element.parentElement??null,a=null===i?{left:0,top:0}:et(e,i);let r=1/0,s=-1/0;for(const e of o){const o=(void 0!==n&&void 0!==e.id?n(e.id):null)??e.points.map(o=>({x:t.timeToCoordinate(o.time),y:t.priceToCoordinate(o.price,e.paneIndex)}));for(const{x:e,y:t}of o)Number.isFinite(e)&&null!==t&&Number.isFinite(t)&&(r=Math.min(r,e),s=Math.max(s,t))}return Number.isFinite(r)&&Number.isFinite(s)?{x:a.left+r,y:a.top+s+12}:{x:a.left+60,y:a.top+60}}function en(e,t,o,n,i){const a=qo(e,"div",`oac-tabs oac-tabs--${n}`);a.setAttribute("role","tablist"),a.setAttribute("aria-orientation","rail"===n?"vertical":"horizontal");const r=[],s=e=>{t.forEach((t,o)=>{const n=t.id===e;r[o].setAttribute("aria-selected",n?"true":"false"),r[o].tabIndex=n?0:-1})},l=e=>{s(e),i(e)};return t.forEach((o,n)=>{const i=qo(e,"button","oac-tab");i.type="button",i.setAttribute("role","tab"),i.dataset.tab=o.id,void 0!==o.icon&&i.appendChild(Ho(e,o.icon)),i.appendChild(qo(e,"span","oac-tab__label",o.label)),i.addEventListener("click",e=>{e.stopPropagation(),l(o.id)}),i.addEventListener("keydown",e=>{const o=e.key,i="vertical"===a.getAttribute("aria-orientation"),s=i?"ArrowUp":"ArrowLeft";let c=-1;o===(i?"ArrowDown":"ArrowRight")?c=(n+1)%t.length:o===s?c=(n-1+t.length)%t.length:"Home"===o?c=0:"End"===o&&(c=t.length-1),c<0||(e.preventDefault(),r[c].focus(),r[c].scrollIntoView?.({block:"nearest",inline:"nearest"}),l(t[c].id))}),r.push(i),a.appendChild(i)}),s(o),{el:a,setActive:s}}function tn(e,t,o){const n=e.getBoundingClientRect(),i=t.offsetWidth||200,a=t.offsetHeight||100;let r=4,s=4;if(void 0!==o.anchor){const e=o.anchor.getBoundingClientRect();r=e.left-n.left,s=e.bottom-n.top+6,s+a>n.height-4&&(s=Math.max(4,e.top-n.top-a-6))}else void 0!==o.point&&(r=o.point.x,s=o.point.y,s+a>n.height-4&&(s=Math.max(4,n.height-a-4)));r=Math.max(4,Math.min(r,n.width-i-4)),s=Math.max(4,Math.min(s,n.height-a-4)),t.style.left=`${Math.round(r)}px`,t.style.top=`${Math.round(s)}px`}const on=new WeakMap;function nn(e,t,o){on.get(e)?.();let n=!1;const i=[],a=e.ownerDocument;e.innerHTML="",e.classList.add("oac-form");const r=[],s=[],l=o.unavailable??(()=>null),c=e=>`${o.idPrefix}-${e.replace(/[^A-Za-z0-9_-]/g,"-")}`,d=new Map,u=new Map,h=new Map,m={...o.values},g=(e,t)=>{Object.defineProperty(m,e,{value:t,writable:!0,enumerable:!0,configurable:!0})},f=t.some(e=>void 0!==e.activeWhen||void 0!==e.visibleWhen);let b,v=null;const w=e=>u.has(e)&&!1!==h.get(e)?.member?.shown,_=(e,t)=>{const o=h.get(e);null===t?u.delete(e):(u.set(e,t),d.delete(e)),o&&(o.control.setAttribute("aria-invalid",String(null!==t)),o.error.textContent=t??"",o.error.hidden=!w(e))},y=(e,n)=>{const i=t.find(t=>t.key===e);if("price"===i?.kind||"timestamp"===i?.kind){if("number"!=typeof n||!Number.isFinite(n))return kt(o,"Enter a finite number");if(void 0!==i.min&&n<i.min)return kt(o,"Minimum: {value}",{value:i.min});if(void 0!==i.max&&n>i.max)return kt(o,"Maximum: {value}",{value:i.max})}return"session"!==i?.kind||"string"==typeof n&&null!==p(n)?null:kt(o,"Use HHMM-HHMM with optional :days (1 to 7)")},x=(e,t)=>{if(n)return;const i=y(e,t);if(_(e,i),!(null!==i||d.has(e)&&Object.is(d.get(e),t))){d.set(e,t),g(e,t),b=e;try{o.onChange(e,t)}finally{b=void 0}n||D(e)}};function k(e,t,n,r){const s=e=>e??"";let u,p;switch(t){case"price":case"timestamp":{const t=qo(a,"input","oac-input--num");t.type="text",t.inputMode="decimal",void 0!==n.min&&(t.min=String(n.min)),void 0!==n.max&&(t.max=String(n.max)),void 0!==n.step&&(t.step=String(n.step));const o=e=>{t.value="number"==typeof e?String(e):""},i=()=>""===t.value.trim()?void 0:Number(t.value);o(r),t.addEventListener("change",()=>x(e,i())),u=t,p={key:e,control:t,read:i,write:o,title:s};break}case"boolean":{const t=qo(a,"input");t.type="checkbox",t.checked=!0===r,t.addEventListener("change",()=>x(e,t.checked)),u=t,p={key:e,control:t,read:()=>t.checked,write:e=>{t.checked=!0===e},title:s};break}case"number":{const t=qo(a,"input","oac-input--num");t.type="number",void 0!==n.min&&(t.min=String(n.min)),void 0!==n.max&&(t.max=String(n.max)),void 0!==n.step&&(t.step=String(n.step));const i=e=>{var o;t.value="number"==typeof e&&Number.isFinite(e)?(o=e,Number.isInteger(o)?String(o):String(Math.round(1e3*o)/1e3)):""};i(r),t.addEventListener("change",()=>{const a=t.value.trim(),s=""===a?NaN:Number(a);if(!Number.isFinite(s))return void(o.preserveInvalidNumbers?x(e,void 0):i(d.has(e)?d.get(e):r));const l=n.min??-1/0,c=n.max??1/0,u=Math.min(c,Math.max(l,s));u!==s&&i(u),x(e,u)}),u=t,p={key:e,control:t,read:()=>{const e=Number(t.value);return""!==t.value.trim()&&Number.isFinite(e)?e:void 0},write:i,title:s};break}case"color":{const t=Po(a,{id:c(e),label:n.label,value:r,live:o.live,translate:o.translate,openOverlay:o.openOverlay,onChange:t=>x(e,t)});return i.push(t.destroy),u=t.el,p={key:e,control:t.input,focus:t.trigger,read:t.read,write:t.write,title:e=>e??n.label},{ctl:u,b:p}}case"opacity":{const t=qo(a,"input","oac-range");t.type="range",t.min="0",t.max="100",t.step="1";const n=qo(a,"output","oac-out"),i=e=>Math.round(100*("number"==typeof e?Math.min(1,Math.max(0,e)):0)),l=e=>{t.value=String(i(e)),n.textContent=`${i(e)}%`};l(r),t.addEventListener("input",()=>{n.textContent=`${t.value}%`,!0===o.live&&x(e,Number(t.value)/100)}),t.addEventListener("change",()=>x(e,Number(t.value)/100));const c=qo(a,"span","oac-opacity");return c.appendChild(t),c.appendChild(n),u=c,p={key:e,control:t,read:()=>Number(t.value)/100,write:l,title:s},{ctl:u,b:p}}case"select":{const{wrap:t,select:i}=Go(a),c=n.options??[],d=t=>{i.innerHTML="";const n=c.slice(),r="string"==typeof t?t:void 0===t?void 0:String(t);void 0===r||""===r||n.some(e=>e.value===r)||n.push({value:r,label:kt(o,"Custom")});for(const t of n){const o=qo(a,"option",void 0,t.label);o.value=t.value;const n=l(e,t.value);null!==n&&(o.disabled=!0,o.title=n),i.appendChild(o)}i.value=void 0===r||""===r?n[0]?.value??"":r};return d(r),i.addEventListener("change",()=>x(e,i.value)),u=t,p={key:e,control:i,read:()=>i.value,write:d,title:s},{ctl:u,b:p}}case"multiline":{const t=qo(a,"textarea","oac-input--multi");t.rows=3,t.setAttribute("spellcheck","false");const o=e=>{t.value=null==e?"":String(e)};o(r),t.addEventListener("change",()=>x(e,t.value)),u=t,p={key:e,control:t,read:()=>t.value,write:o,title:s};break}default:{const t=qo(a,"input");t.type="text",t.setAttribute("spellcheck","false");const o=e=>{t.value=null==e?"":String(e)};o(r),t.addEventListener("change",()=>x(e,t.value)),u=t,p={key:e,control:t,read:()=>t.value,write:o,title:s};break}}return{ctl:u,b:p}}const C=(e,t)=>{const n=qo(a,"label",t,"timestamp"===e.kind?kt(o,"{label} (UTC seconds)",{label:e.label}):e.label);if(void 0!==e.tooltip&&""!==e.tooltip){const t=qo(a,"span","oac-help","?");t.title=e.tooltip,t.setAttribute("aria-hidden","true"),n.appendChild(t)}return n},S=(e,t,o)=>{e.htmlFor=t.id,void 0!==o.tooltip&&""!==o.tooltip&&t.setAttribute("aria-description",o.tooltip)},A=(e,t,o,n,i)=>{const a={control:e,fields:n,parts:i,offKeys:n.map(e=>e.key),offEl:t,offClass:"oac-row--off",titles:[t],row:t,head:o,shown:!0,enabled:!0};for(const e of n)e.member=a;return s.push(a),a},L=(e,t,o)=>{const n=qo(a,"div","oac-input-error");return n.id=`${c(e)}-error`,n.hidden=!0,n.setAttribute("role","status"),t.control.setAttribute("aria-describedby",n.id),o.appendChild(n),h.set(e,{control:t.control,error:n}),n},O=e=>void 0!==e.inline&&"custom"!==e.kind&&"colorPair"!==e.kind&&"multiline"!==e.kind;let $,E,T=e,P=null;for(const n of t){if(void 0!==n.group&&n.group!==$&&(E=qo(a,"div","oac-head",n.group),e.appendChild(E),E.id=c(`group-${s.length}`),T=qo(a,"div","oac-form__group"),T.setAttribute("role","group"),T.setAttribute("aria-labelledby",E.id),e.appendChild(T),P=null),$=n.group??$,null===P||O(n)&&n.inline===P.id||(P=null),null!==P){const e=k(n.key,n.kind,n,o.values[n.key]);e.b.control.id=c(n.key);const t=C(n,"oac-inline__label");S(t,e.b.focus??e.b.control,n),r.push(e.b);const i=qo(a,"span","oac-inline__item");i.dataset.key=n.key,"boolean"===n.kind?(i.appendChild(e.ctl),i.appendChild(t)):(i.appendChild(t),i.appendChild(e.ctl)),P.ctl.appendChild(i),L(n.key,e.b,P.row);const s=A(n,P.row,E,[e.b],[i]);s.offEl=i,s.offClass="oac-inline__item--off",s.titles=[i],h.get(n.key).member=s;continue}const t=qo(a,"div","oac-row");t.dataset.key=n.key;const i=C(n,"oac-row__label");if("custom"===n.kind){const e=void 0===o.custom?null:o.custom(n,t);if(null===e)continue;t.appendChild(qo(a,"span","oac-row__sw")),t.appendChild(i);const r=qo(a,"div","oac-row__ctl");r.appendChild(e),t.appendChild(r),T.appendChild(t),A(n,t,E,[],[t]).offEl=null;continue}if("colorPair"===n.kind&&void 0!==n.pair){const e=n.pair,s=[];if(void 0!==e.enabled){const a=k(e.enabled.key,"boolean",n,o.values[e.enabled.key]);a.ctl.classList.add("oac-row__sw"),a.ctl.id=c(e.enabled.key),S(i,a.ctl,n),r.push(a.b),s.push(a.b),t.appendChild(a.ctl)}else t.appendChild(qo(a,"span","oac-row__sw"));t.appendChild(i);const l=qo(a,"div","oac-row__ctl");let d;for(const t of[e.up,e.down]){const e=k(t.key,"color",n,o.values[t.key]);d??(d=e.b.focus??e.b.control),e.b.control.id=c(t.key),e.b.title=e=>null===e?t.label:`${t.label}: ${e}`,e.b.control.setAttribute("aria-label",`${n.label} ${t.label}`),e.b.focus?.setAttribute("aria-label",`${n.label} ${t.label}`),r.push(e.b),s.push(e.b),l.appendChild(e.ctl)}void 0===e.enabled&&void 0!==d&&S(i,d,n),t.appendChild(l),T.appendChild(t),A(n,t,E,s,[t]).offKeys=[e.up.key,e.down.key];continue}const l=k(n.key,n.kind,n,o.values[n.key]);l.b.control.id=c(n.key),S(i,l.b.focus??l.b.control,n),r.push(l.b);let d=[t],u=[t];if("boolean"===n.kind)l.ctl.classList.add("oac-row__sw"),t.appendChild(l.ctl),t.appendChild(i),O(n)&&(t.appendChild(qo(a,"div","oac-row__ctl")),d=[l.ctl,i],u=[i]);else if("multiline"===n.kind)t.classList.add("oac-row--block"),t.appendChild(i),t.appendChild(l.ctl);else{t.appendChild(qo(a,"span","oac-row__sw")),t.appendChild(i);const e=qo(a,"div","oac-row__ctl");if(O(n)){const t=qo(a,"span","oac-inline__item");t.dataset.key=n.key,t.appendChild(l.ctl),e.appendChild(t),d=[i,t],u=[i,t]}else e.appendChild(l.ctl);t.appendChild(e)}O(n)&&(t.classList.add("oac-row--inline"),t.dataset.inline=n.inline,P={id:n.inline,row:t,ctl:t.lastChild}),L(n.key,l.b,t),T.appendChild(t);const p=A(n,t,E,[l.b],d);p.titles=u,h.get(n.key).member=p}f&&(v=qo(a,"div","oac-sr"),v.setAttribute("role","status"),v.setAttribute("aria-live","polite"),e.appendChild(v));const j=e=>t.find(t=>t.key===e||[t.pair?.enabled,t.pair?.up,t.pair?.down].some(t=>t?.key===e))?.label,M=e=>!1!==e.member?.shown&&!e.control.disabled,I=()=>{if(n)return!1;for(const e of r)if(M(e))return(e.focus??e.control).focus(),!0;return!1};function D(n=b,i=!0){const c=a.activeElement,d=f?Do(t,m):null,u={shown:[],hidden:[],on:[],off:[]};for(const e of s){const t=d?.get(e.control.key),n=t?.visible??!0;let i=null;if(void 0!==t&&!t.active){const e=t.dependsOn.map(j).filter(e=>void 0!==e);i=e.length>0?kt(o,"Depends on {inputs}",{inputs:e.join(", ")}):kt(o,"Not used with the current settings")}for(const t of e.parts)t.hidden=!n;const a=new Map;for(const t of e.fields){const e=l(t.key)??i;a.set(t.key,e);for(const o of[t.control,t.focus])void 0!==o&&(o.disabled=null!==e,o.title=t.title(e))}const r=e.fields.length>0&&e.offKeys.every(e=>null!==a.get(e));if(null!==e.offEl){e.offEl.classList.toggle(e.offClass,r);const t=a.get(e.offKeys[0])??null;for(const o of e.titles)o.title=r?t??"":""}const s=e.control.label;e.shown!==n?u[n?"shown":"hidden"].push(s):n&&e.enabled===r&&u[r?"off":"on"].push(s),e.shown=n,e.enabled=!r}for(const e of[e=>e.row,e=>e.head]){const t=new Map;for(const o of s){const n=e(o);void 0!==n&&t.set(n,(t.get(n)??!1)||o.shown)}for(const[e,o]of t)e.hidden=!o}for(const[e,t]of h)t.error.hidden=!w(e);if(null!==c&&e.contains(c)&&(s.some(e=>!e.shown&&e.parts.some(e=>e.contains(c)))||c.disabled)){const e=void 0===n?void 0:r.find(e=>e.key===n);void 0!==e&&M(e)?(e.focus??e.control).focus():I()}if(!i||null===v)return;const p=[];if(u.shown.length>0&&p.push(kt(o,"Shown: {inputs}",{inputs:u.shown.join(", ")})),u.hidden.length>0&&p.push(kt(o,"Hidden: {inputs}",{inputs:u.hidden.join(", ")})),u.on.length>0&&p.push(kt(o,"Available: {inputs}",{inputs:u.on.join(", ")})),u.off.length>0&&p.push(kt(o,"Unavailable: {inputs}",{inputs:u.off.join(", ")})),0===p.length)return;const g=p.join(". ");v.textContent=v.textContent===g?`${g} `:g}D(void 0,!1);const z=()=>{if(!n){n=!0;for(const e of i.splice(0))e();on.get(e)===z&&on.delete(e)}};return on.set(e,z),{el:e,destroy:z,setError:_,validate:()=>{const e=new Set(r.filter(e=>!M(e)).map(e=>e.key));for(const t of r){if(e.has(t.key))continue;const o=y(t.key,t.read());null===o&&u.has(t.key)||_(t.key,o)}return[...u.keys()].every(t=>e.has(t))},sync:e=>{if(n)return;for(const t of Object.keys(e))g(t,e[t]);const t=a.activeElement;for(const o of r)o.control!==t&&(u.has(o.key)||o.key in e&&(o.write(e[o.key]),d.has(o.key)&&d.set(o.key,o.read())));D()},values:()=>{const e={};for(const t of r)e[t.key]=t.read();return e},focusFirst:I}}const an=e=>void 0!==e&&void 0!==se(e)?ie(e):'<svg aria-hidden="true"></svg>';function rn(e,t,o,n={}){const i=e.document,a=Ke(i,"div","oac-menu",{role:"menu"});n.ariaLabel&&a.setAttribute("aria-label",n.ariaLabel);let r=null;if(n.find){const e=Ke(i,"div","oac-menu__find");r=Ke(i,"input",void 0,{type:"text",placeholder:n.find,"aria-label":n.find}),e.appendChild(r),a.appendChild(e)}const s=Ke(i,"div","oac-menu__body");a.appendChild(s);let l=()=>{};const c=o.some(e=>"string"!=typeof e&&void 0!==e.icon),d=t=>{const n=t.trim().toLowerCase();s.textContent="";let a=0,r=null;for(const e of o){if("string"==typeof e){r=e;continue}if(""!==n&&!e.label.toLowerCase().includes(n)&&!(e.sub??"").toLowerCase().includes(n))continue;if(null!==r){const e=Ke(i,"div","oac-head");e.textContent=r,s.appendChild(e),r=null}const t=Ke(i,"button","oac-menu__row"+(e.danger?" is-danger":""),{type:"button",role:void 0===e.on?"menuitem":"menuitemradio","aria-disabled":String(!0===e.disabled)});void 0!==e.on&&t.setAttribute("aria-checked",String(e.on)),c&&t.appendChild(Ge(i,an(e.icon),"chrome"));const o=Ke(i,"span","oac-menu__label");if(o.textContent=e.label,t.appendChild(o),e.sub){const o=Ke(i,"span","oac-menu__sub");o.textContent=e.sub,t.appendChild(o)}if(e.key){const o=Ke(i,"kbd","oac-menu__key",{"aria-hidden":"true"});o.textContent=e.key,t.appendChild(o),t.setAttribute("aria-keyshortcuts",xo(e.key))}t.addEventListener("click",t=>{t.stopPropagation(),e.disabled||(l(),e.onSelect())}),s.appendChild(t),a++}if(0===a){const t=Ke(i,"div","oac-menu__empty");t.textContent=kt(e,"No match"),s.appendChild(t)}};if(d(""),null!==r){const e=r;e.addEventListener("input",()=>d(e.value)),e.addEventListener("keydown",e=>{if("Enter"!==e.key)return;e.preventDefault();const t=s.querySelectorAll(".oac-menu__row");1===t.length&&t[0].click()})}return a.addEventListener("keydown",e=>{const t=e,o=Array.from(s.querySelectorAll(".oac-menu__row")),n=o.indexOf(i.activeElement);"ArrowDown"===t.key?(o[(n+1)%o.length]?.focus(),t.preventDefault(),t.stopPropagation()):"ArrowUp"===t.key&&(o[(n-1+o.length)%o.length]?.focus(),t.preventDefault(),t.stopPropagation())}),l=e.openOverlay(a,{anchor:t,placement:n.placement??"below",edge:n.edge,initialFocus:r??s.querySelector('.oac-menu__row[aria-checked="true"]')??void 0}),l}function sn(e,t,o,n){const i=globalThis;if(void 0===i.Blob||void 0===i.URL||"function"!=typeof i.URL.createObjectURL)return!1;const a=e.createElement("a"),r=i.URL.createObjectURL(new i.Blob([o],{type:n}));try{a.href=r,a.download=t,(e.body??e.documentElement).appendChild(a),a.click()}finally{a.remove(),setTimeout(()=>i.URL?.revokeObjectURL(r),0)}return!0}function ln(e,t,o=new Date){const n=o.toISOString().slice(0,16).replace(/[:T]/g,"-");return`${(e||"chart").replace(/[^A-Za-z0-9._-]/g,"")}-${t||"chart"}-${n}`}function cn(e,t){const{draw:o}=e,n=ct(o,t),i=n.map(e=>o.get(e)).filter(e=>void 0!==e),a=i.filter(e=>!0===e.locked).length,r=new Set(t.map(e=>o.get(e)).filter(e=>void 0!==e).map(t=>void 0!==t.stackAbove&&e.chart.seriesStack(t.paneIndex).includes(t.stackAbove)?null:t.zIndex<0?"behind":"above")),[s]=r;return{editable:n,locked:i.length>0&&a===i.length,partlyLocked:a>0&&a<i.length,hidden:i.length>0&&i.every(e=>!1===e.visible),side:1===r.size&&void 0!==s?s:null}}function dn(e,t){const o=cn(e,t),n=t.length>0&&0===o.editable.length?kt(e,"read-only"):null;return{...o,readOnly:n,noDelete:n??(o.locked?kt(e,"locked"):null)}}function un(e,t,o){const{draw:n}=e,i=cn(e,o);("delete"!==t||0!==i.editable.length&&!i.locked)&&pt(e,t,()=>{switch(t){case"lock":n.updateMany(i.editable.map(e=>({id:e,patch:{locked:!i.locked}})));break;case"visible":n.updateMany(i.editable.map(e=>({id:e,patch:{visible:i.hidden}})));break;case"front":for(const e of o)n.bringToFront(e);break;case"back":for(const e of o)n.sendToBack(e);break;case"above":for(const e of o)n.bringAboveSeries(e);break;case"behind":for(const e of o)n.sendBehindSeries(e);break;case"duplicate":n.duplicate(o);break;case"delete":n.removeMany(i.editable)}})}const pn=["off","weak","strong"],hn=[{id:"lines",title:"Lines",items:[{head:"Lines"},{tool:"trend-line"},{tool:"ray"},{tool:"extended-line"},{tool:"arrow"},{tool:"info-line"},{tool:"trend-angle"},{head:"Horizontal and vertical"},{tool:"horizontal-line"},{tool:"horizontal-ray"},{tool:"vertical-line"},{tool:"cross-line"}]},{id:"channels",title:"Channels",items:[{head:"Channels"},{tool:"parallel-channel"},{tool:"fib-channel"},{tool:"disjoint-channel"},{tool:"flat-top-bottom"},{tool:"regression-channel"},{head:"Pitchforks"},{tool:"pitchfork"},{tool:"schiff-pitchfork"},{tool:"modified-schiff-pitchfork"},{tool:"inside-pitchfork"}]},{id:"fib",title:"Fibonacci and Gann",items:[{head:"Fibonacci"},{tool:"fib-retracement"},{tool:"fib-extension"},{tool:"fib-time-zone"},{tool:"fib-fan"},{tool:"fib-extension-two-point"},{tool:"fib-speed-resistance-fan"},{tool:"trend-fib-time"},{tool:"fib-circles"},{tool:"fib-speed-resistance-arcs"},{tool:"fib-wedge"},{tool:"fib-spiral"},{head:"Gann"},{tool:"gann-fan"},{tool:"gann-box"},{tool:"gann-square"}]},{sep:!0},{id:"shapes",title:"Shapes",items:[{head:"Shapes"},{tool:"rectangle"},{tool:"rotated-rectangle"},{tool:"ellipse"},{tool:"circle"},{tool:"triangle"},{head:"Paths"},{tool:"path"},{tool:"polyline"},{tool:"arc"},{tool:"curve"},{tool:"double-curve"}]},{id:"cycles",title:"Cycles",items:[{head:"Cycles"},{tool:"cyclic-lines"},{tool:"time-cycles"},{tool:"sine-line"}]},{id:"patterns",title:"Patterns",items:[{head:"Patterns and waves"},{tool:"xabcd-pattern"},{tool:"abcd-pattern"},{tool:"head-shoulders"},{tool:"elliott-impulse"},{tool:"elliott-correction"},{head:"Harmonic patterns"},{tool:"gartley"},{tool:"bat"},{tool:"butterfly"},{tool:"crab"},{tool:"shark"},{tool:"cypher"}]},{id:"geometry",title:"Geometric studies",items:[{head:"Geometric studies"},{tool:"sonic"},{tool:"supersonic"},{tool:"golden-sonic"},{tool:"golden-supersonic"},{tool:"dedekind-tessellation"}]},{id:"marks",title:"Arrows and marks",items:[{head:"Arrows"},{tool:"arrow-up"},{tool:"arrow-down"},{tool:"arrow-left"},{tool:"arrow-right"},{head:"Marks"},{tool:"flag-mark"},{tool:"icon-stamp"},{tool:"price-label"},{tool:"signpost"}]},{sep:!0},{id:"forecast",title:"Forecasting",items:[{head:"Forecasting"},{tool:"long-position"},{tool:"short-position"},{tool:"forecast"}]},{id:"analysis",title:"Volume studies",items:[{head:"Volume studies"},{tool:"anchored-vwap"},{tool:"fixed-range-volume-profile"}]},{id:"measure",title:"Measurers",items:[{head:"Measurers"},{tool:"price-range"},{tool:"date-range"},{tool:"measure"}]},{sep:!0},{id:"text",title:"Text and notes",items:[{head:"Text and notes"},{tool:"text"},{tool:"note"},{tool:"callout"},{tool:"balloon"},{tool:"comment"},{tool:"price-note"},{tool:"table"},{head:"Brushes"},{tool:"brush"},{tool:"highlighter"}]}],mn=e=>(null===e?null:dt(e))?.name??String(e??"Cursor"),gn="rail",fn="oac-rail-sprite";function bn(e,t){if(void 0!==le[t])return Ge(e,ce(t),"tool");const o=Ke(e,"span","oac-glyph oac-glyph--text",{"aria-hidden":"true"});return o.textContent=String(t).charAt(0).toUpperCase(),o}function vn(e,t,o){const n={favorites:[],magnet:"off",stay:!1,last:{}};if(null===e||"object"!=typeof e)return n;const i=e;if(Array.isArray(i.favorites)&&(n.favorites=i.favorites.filter((e,t,o)=>"string"==typeof e&&oe(e)&&o.indexOf(e)===t)),"string"==typeof i.magnet&&pn.includes(i.magnet)&&(n.magnet=i.magnet),n.stay=!0===i.stay,!0===i.collapsed&&(n.collapsed=!0),null!==i.last&&"object"==typeof i.last){const e=i.last;for(const i of t)void 0!==i.id&&"string"==typeof e[i.id]&&o(i).includes(e[i.id])&&(n.last[i.id]=e[i.id])}return n}function wn(e,t,o={}){const n=e.document,i=t=>kt(e,`schema.drawing.${t??"cursor"}.name`,{},mn(t)),a=e.draw,r=e.chart;!function(e){if(null!==e.getElementById(fn))return;const t=e.createElement("div");t.id=fn,t.hidden=!0,t.innerHTML=de(),(e.body??e.documentElement).appendChild(t)}(n);const s=void 0===o.tools?null:new Set(o.tools),l=e=>(e.items??[]).filter(e=>void 0!==e.tool&&oe(e.tool)&&(null===s||s.has(e.tool))).map(e=>e.tool),c=e=>hn.find(t=>t.id===e);let d=vn(e.storage.get(gn),hn,l);null===e.storage.get(gn)&&o.favorites&&(d.favorites=o.favorites.filter((e,t,o)=>oe(e)&&o.indexOf(e)===t));let u=!1;const p=()=>{e.storage.set(gn,d)},h=e=>d.last[e.id??""]??l(e)[0]??null;let m=null;const g=(t,o)=>ko(e.keymap,t,o),f=e=>{if(null!==e)return null===m&&(m=pe()),g(`tool:${e}`,m[e])},b=()=>a.selection().slice(),v=t=>dn(e,t),w=e=>{const t=o.cursorTarget;t&&(null!==e&&void 0!==le[e]?t.style.setProperty("--oac-tool-cursor",ue(e)):t.style.removeProperty("--oac-tool-cursor"))},_=()=>{a.setOptions({magnet:d.magnet})},y=()=>{a.setOptions({stayInDrawingMode:d.stay||u})},x=e=>{if(!pn.includes(e))throw new Error(`openalgo-charts widget: unknown magnet mode "${String(e)}"`);d.magnet=e,p(),_(),W()},k=()=>{const t=pn[(pn.indexOf(d.magnet)+1)%pn.length];return x(t),e.status(kt(e,"off"===t?"Magnet off":"weak"===t?"Magnet weak: snaps when a bar or study value is within a few pixels":"Magnet strong: every anchor lands on the nearest bar or study value")),t},C=t=>{d.stay=!0===t,p(),y(),W(),e.status(d.stay?kt(e,"Tools stay active after each drawing"):kt(e,"One drawing per pick"))},S=e=>{u=!0===e,y(),J(a.activeTool())},A=e=>{a.setTool(e),J(e)},L=t=>{S(!0),A(t),e.status(kt(e,"{name} stays active until Escape",{name:i(t)}))};t.classList.add("oac-rail"),t.setAttribute("role","toolbar"),t.setAttribute("aria-orientation","vertical"),t.setAttribute("aria-label",kt(e,"Drawing tools"));const O=t=>{const o=Ke(n,"button","oac-rail__btn"+(t.cls?" "+t.cls:""),{type:"button"});return o.tabIndex=-1,o.appendChild(t.glyphEl),e.tips.attach(o,t.tip,600),o.addEventListener("click",e=>{o.classList.contains("is-off")||t.onClick(e)}),t.onContext&&o.addEventListener("contextmenu",e=>{e.preventDefault(),e.stopPropagation(),t.onContext?.(e)}),o},$=(e,t)=>{const o=e.querySelector(".oac-glyph");o?o.replaceWith(t):e.insertBefore(t,e.firstChild)},E=()=>Ke(n,"div","oac-rail__sep",{role:"separator"}),T=t=>{const o=O({cls:"oac-rail__tool oac-rail__fav",glyphEl:bn(n,t),tip:()=>({title:kt(e,"{name} (pinned)",{name:i(t)}),chord:f(t),sub:kt(e,"Pinned. Right-click to unpin"),side:"right"}),onClick:e=>{e.detail>=2&&!d.stay?L(t):(S(!1),A(t))},onContext:()=>D(o,[{label:kt(e,"Unpin from rail"),icon:"star",onSelect:()=>H(t,!1)}])});return o.dataset.tools=t,o},P=t=>{const o=l(t);let r=!1;const s=O({cls:"oac-rail__tool oac-rail__group",glyphEl:bn(n,h(t)??o[0]),tip:()=>({title:i(h(t)),chord:f(h(t)),sub:kt(e,d.stay?"{group}: chevron for the rest":"{group}: chevron for the rest. Double-click keeps it active",{group:void 0===t.title?"":kt(e,`schema.rail.${t.id}.title`,{},t.title)}),side:"right"}),onClick:e=>{const o=r&&0!==e.detail;if(r=!1,null===j||"true"!==s.getAttribute("aria-expanded"))if(o)I(t,s,!1);else{if(e.detail>=2&&!d.stay){const e=h(t);return void(null!==e&&L(e))}a.activeTool()!==h(t)?(S(!1),A(h(t))):I(t,s,!1)}else M()},onContext:()=>I(t,s,!1)});s.addEventListener("pointerdown",e=>{const t=e.target;r="touch"!==e.pointerType&&"function"==typeof t?.closest&&null!==t.closest(".oac-rail__chev")}),s.dataset.tools=o.join(","),s.dataset.group=t.id??"",s.dataset.face=h(t)??"",s.setAttribute("aria-haspopup","menu"),s.setAttribute("aria-expanded","false");const c=Ke(n,"span","oac-rail__chev",{"aria-hidden":"true"});return c.innerHTML=ie("chevron-right"),s.appendChild(c),s};let j=null;const M=()=>{j?.close()},I=(o,r,l)=>{M(),e.tips.hide();const c=Ke(n,"div","oac-fly",{role:"menu","aria-label":void 0===o.title?kt(e,"Tools"):kt(e,`schema.rail.${o.id}.title`,{},o.title)}),u=a.activeTool(),h=[];for(const t of o.items??[]){if(void 0!==t.head){const i=Ke(n,"div","oac-head");i.textContent=kt(e,`schema.rail.${o.id}.group.${t.head}`,{},t.head),c.appendChild(i);continue}const a=t.tool;if(void 0===a||!oe(a)||null!==s&&!s.has(a))continue;const l=Ke(n,"div","oac-fly__row",{role:"menuitemradio","aria-checked":String(u===a)});l.tabIndex=-1,l.dataset.tool=a,l.appendChild(bn(n,a));const d=Ke(n,"span","oac-fly__name");d.textContent=i(a),l.appendChild(d);const p=q(a),g=Ke(n,"button","oac-fly__star",{type:"button","aria-pressed":String(p),"aria-label":kt(e,"Pin to rail")});g.tabIndex=-1,g.innerHTML=ie(p?"star-filled":"star"),l.appendChild(g);const b=Ke(n,"kbd","oac-fly__chord");b.textContent=f(a)??"",l.appendChild(b);const v=()=>{const e=!q(a);H(a,e),g.setAttribute("aria-pressed",String(e)),g.innerHTML=ie(e?"star-filled":"star")};g.addEventListener("click",e=>{e.stopPropagation(),v()}),l.addEventListener("click",e=>{e.stopPropagation(),m(a)}),l.addEventListener("keydown",e=>{const t=e;"Enter"!==t.key&&" "!==t.key||(t.preventDefault(),t.stopPropagation(),null!==t.target.closest(".oac-fly__star")?v():(m(a),r.focus()))}),h.push(l),c.appendChild(l)}const m=e=>{void 0!==o.id&&(d.last[o.id]=e,p()),M(),S(!1),A(e)};c.addEventListener("keydown",e=>{const t=e,o=t.target.closest(".oac-fly__row"),n=null===o?-1:h.indexOf(o),i=e=>{h[(e+h.length)%h.length]?.focus()};switch(t.key){case"ArrowDown":i(n+1);break;case"ArrowUp":i(n-1);break;case"Home":i(0);break;case"End":i(h.length-1);break;case"ArrowRight":o?.querySelector(".oac-fly__star")?.focus();break;case"ArrowLeft":o?.focus();break;default:return}t.preventDefault(),t.stopPropagation()});const g=h.find(e=>"true"===e.getAttribute("aria-checked"))??h[0]??null,b=e.openOverlay(c,{anchor:r,placement:"beside",edge:t,initialFocus:l?g:c,onClose:()=>{null!==j&&j.el===c&&(j=null)}});j={el:c,close:b}},D=(o,n)=>{e.tips.hide(),rn(e,o,n,{placement:"beside",edge:t})},z={},N=function(e,t,o){const n=e.document,i=Ke(n,"button","oac-rail-tab",{type:"button"});i.innerHTML=ie("chevrons-right"),i.hidden=!0,e.tips.attach(i,()=>({title:kt(e,"Show drawing tools"),side:"right"}),600),i.addEventListener("pointerdown",e=>{e.stopPropagation()}),t.parentNode?.insertBefore(i,t.nextSibling);const a=()=>{const n=o.folded();t.classList.toggle("is-collapsed",n),i.hidden=!n,e.tips.refreshLabel(i)},r=r=>{const s=!0===r;if(o.folded()===s)return;const l=s?t.contains(n.activeElement):n.activeElement===i;s&&e.tips.hide(),o.store(s),a(),l&&(s?i:o.unfoldTarget())?.focus()};return i.addEventListener("click",()=>{r(!1)}),{apply:a,set:r,destroy:()=>{t.classList.remove("is-collapsed"),i.remove()}}}(e,t,{folded:()=>!0===d.collapsed,store:e=>{e?(M(),d.collapsed=!0):delete d.collapsed,p()},unfoldTarget:()=>z.collapse}),R=N.set,F=(e,t)=>{void 0!==e&&(e.classList.toggle("is-on",!0===t.on),e.classList.toggle("is-off",!0===t.off),e.setAttribute("aria-disabled",!0===t.off?"true":"false"),void 0!==t.pressed&&e.setAttribute("aria-pressed",String(t.pressed)),void 0!==t.glyph&&e.dataset.glyph!==t.glyph&&(e.dataset.glyph=t.glyph,$(e,Ho(n,t.glyph))))},W=()=>{if(void 0===z.magnet)return;F(z.magnet,{on:"strong"===d.magnet,pressed:"off"!==d.magnet}),z.magnet.classList.toggle("is-weak","weak"===d.magnet),z.magnet.dataset.mode=d.magnet,F(z.stay,{on:d.stay,pressed:d.stay});const t=v(b()),o=0===t.editable.length;F(z.lock,{off:o,on:t.locked,pressed:t.locked,glyph:t.locked?"lock":"unlock"}),F(z.eye,{off:o,on:t.hidden,pressed:t.hidden,glyph:t.hidden?"eye-off":"eye"}),F(z.trash,{off:null!==t.noDelete||o}),F(z.undo,{off:!ht(e,"undo")}),F(z.redo,{off:!ht(e,"redo")});for(const t of Object.values(z))e.tips.refreshLabel(t)};let B=null;const q=e=>d.favorites.includes(e),U=()=>{if(null===B)return;B.textContent="";const e=d.favorites.filter(e=>oe(e));if(0!==e.length){B.appendChild(E());for(const t of e)B.appendChild(T(t))}},H=(e,t=!q(e))=>{if(!oe(e))return;const o=q(e);t&&!o&&d.favorites.push(e),!t&&o&&d.favorites.splice(d.favorites.indexOf(e),1),p(),U(),J(a.activeTool())},K=()=>Array.from(t.querySelectorAll(".oac-rail__btn")),G=e=>{for(const t of K())t.tabIndex=t===e?0:-1},V=()=>{t.textContent="",t.appendChild((()=>{const t=O({cls:"oac-rail__tool",glyphEl:bn(n,"cursor"),tip:()=>({title:kt(e,"Cursor"),chord:"Esc",side:"right"}),onClick:()=>{S(!1),A(null)}});return t.dataset.tools="",t})()),B=Ke(n,"div","oac-rail__favs"),t.appendChild(B),U(),t.appendChild(E());for(const e of hn)e.sep?t.appendChild(E()):l(e).length>0&&t.appendChild(P(e));t.appendChild((()=>{const t=Ke(n,"div","oac-rail__ctl");return z.magnet=O({cls:"oac-rail__btn--chrome oac-rail__btn--magnet",glyphEl:Ho(n,"magnet"),tip:()=>({title:kt(e,"Magnet: {mode}",{mode:kt(e,`schema.magnet.${d.magnet}`,{},d.magnet)}),sub:"off"===d.magnet?kt(e,"Click for weak: snaps when a bar or study value is within a few pixels"):"weak"===d.magnet?kt(e,"Click for strong: every anchor lands on the nearest bar or study value"):kt(e,"Click to switch the magnet off"),side:"right"}),onClick:()=>{k()}}),t.appendChild(z.magnet),z.stay=O({cls:"oac-rail__btn--chrome",glyphEl:Ho(n,"link"),tip:()=>({title:kt(e,"Keep tool active"),sub:d.stay?kt(e,"On: the tool stays active after each drawing"):kt(e,"Off: one drawing per pick"),side:"right"}),onClick:()=>C(!d.stay)}),t.appendChild(z.stay),t.appendChild(E()),z.lock=O({cls:"oac-rail__btn--chrome",glyphEl:Ho(n,"unlock"),tip:()=>{const t=b();return{title:kt(e,"Lock drawing"),sub:0===t.length?kt(e,"Select a drawing first"):v(t).readOnly??void 0,side:"right"}},onClick:()=>{un(e,"lock",b()),W()}}),t.appendChild(z.lock),z.eye=O({cls:"oac-rail__btn--chrome",glyphEl:Ho(n,"eye"),tip:()=>{const t=b(),o=v(t);return{title:kt(e,"Hide drawing"),side:"right",sub:0===t.length?kt(e,"Select a drawing first"):o.readOnly??(o.hidden?void 0:kt(e,"Stays selected, so the eye brings it back"))}},onClick:()=>{un(e,"visible",b()),W()}}),t.appendChild(z.eye),z.trash=O({cls:"oac-rail__btn--chrome oac-rail__btn--danger",glyphEl:Ho(n,"trash"),tip:()=>{const t=b(),o=v(t),n=o.editable.length,i=o.noDelete??void 0;return t.length>0?{title:n>1?kt(e,"Delete {count} drawings",{count:n}):kt(e,"Delete drawing"),chord:g("delete","Delete"),sub:i??kt(e,"Right-click to remove all"),side:"right"}:{title:kt(e,"Delete drawing"),chord:g("delete","Delete"),sub:kt(e,"Select one first. Right-click to remove all"),side:"right"}},onClick:()=>{un(e,"delete",b()),W()},onContext:()=>{const t=a.drawings(),o=t.filter(e=>!1!==e.policy?.selectable).length,n=ct(a,t.map(e=>e.id)).length;D(z.trash,[{label:kt(e,"Select all ({count})",{count:o}),icon:"cursor",disabled:0===o,onSelect:()=>{a.select(t.map(e=>e.id)),W()}},{label:kt(e,"Remove all drawings ({count})",{count:n}),icon:"trash",danger:!0,disabled:0===n,onSelect:()=>{a.clear(),W(),e.status(n>0?kt(e,1===n?"Removed {count} drawing":"Removed {count} drawings",{count:n}):kt(e,"No drawings to remove"))}}])}}),t.appendChild(z.trash),t.appendChild(E()),z.undo=O({cls:"oac-rail__btn--chrome",glyphEl:Ho(n,"undo"),tip:()=>({title:kt(e,"Undo"),chord:g("undo","Mod+Z"),side:"right"}),onClick:()=>{ut(e,"undo"),W()}}),t.appendChild(z.undo),z.redo=O({cls:"oac-rail__btn--chrome",glyphEl:Ho(n,"redo"),tip:()=>({title:kt(e,"Redo"),chord:g("redo-alt","Mod+Y")??g("redo",void 0),side:"right"}),onClick:()=>{ut(e,"redo"),W()}}),t.appendChild(z.redo),t.appendChild(E()),z.collapse=O({cls:"oac-rail__btn--chrome oac-rail__collapse",glyphEl:Ho(n,"chevrons-left"),tip:()=>({title:kt(e,"Hide drawing tools"),sub:kt(e,"The chart takes the space. The tab at its bottom left brings them back"),side:"right"}),onClick:()=>{R(!0)}}),t.appendChild(z.collapse),t})()),J(a.activeTool())},J=o=>{const i=o??null;let a=null;for(const o of Array.from(t.querySelectorAll(".oac-rail__tool"))){const t=(o.dataset.tools??"").split(",").filter(Boolean),r=null===i?0===t.length:t.includes(i);o.classList.toggle("is-on",r),o.classList.toggle("is-held",r&&u&&t.length>0),o.setAttribute("aria-pressed",String(r)),r&&null===a&&(a=o),r&&o.dataset.group&&t.length>0&&null!==i&&(d.last[o.dataset.group]!==i&&(d.last[o.dataset.group]=i,p()),o.dataset.face!==i&&(o.dataset.face=i,$(o,bn(n,i)))),e.tips.refreshLabel(o)}const r=n.activeElement;null===a||null!==r&&t.contains(r)||G(a),w(i),W()},Y=function(e,t,o){const n=e.document,i=()=>{const e=n.activeElement;return null!==e&&t.contains(e)?e.closest(".oac-rail__btn"):null},a=e=>{const t=o.buttons();if(0===t.length)return;const n=t[(e%t.length+t.length)%t.length];o.setRoving(n),n.focus()},r=[],s=(t,o,n)=>{r.push(e.keymap.register(t,o,"rail",{label:n,group:"Tool rail"}))};s("ArrowDown",()=>{a(o.buttons().indexOf(i())+1)},"Next tool"),s("ArrowUp",()=>{a(o.buttons().indexOf(i())-1)},"Previous tool"),s("Home",()=>{a(0)},"First tool"),s("End",()=>{a(o.buttons().length-1)},"Last tool"),s("ArrowRight",()=>{const e=i();return null!==e&&void 0!==e.dataset.group&&""!==e.dataset.group&&o.openGroup(e.dataset.group,e)},"Open the group"),s("Escape",()=>{const t=o.flyoutOpen();o.closeFlyout(),e.tips.hide();const n=o.chart;return void 0!==n&&"function"==typeof n.focus?n.focus():i()?.blur(),t},"Back to the chart");const l=e=>{const t=e.target,n=null!==t&&"function"==typeof t.closest?t.closest(".oac-rail__btn"):null;null!==n&&o.setRoving(n)};return t.addEventListener("focusin",l),{destroy:()=>{for(const e of r)e();t.removeEventListener("focusin",l)}}}(e,t,{buttons:K,setRoving:G,openGroup:(e,t)=>{const o=c(e);return void 0!==o&&(I(o,t,!0),!0)},flyoutOpen:()=>null!==j,closeFlyout:M,chart:o.cursorTarget}),Z=[];Z.push(r.on("draw:tool",e=>{J(e.tool)}));for(const e of["draw:select","drawing:select","drawing:change","draw:add","draw:remove","draw:update","draw:paste","draw:cut"])Z.push(r.on(e,W));return void 0!==e.history&&Z.push(e.history.subscribe(W)),_(),y(),V(),N.apply(),{el:t,sync:J,refresh:W,prefs:()=>({favorites:d.favorites.slice(),magnet:d.magnet,stay:d.stay,last:{...d.last},...!0===d.collapsed?{collapsed:!0}:{}}),restorePrefs:e=>{d=vn(e,hn,l),p(),_(),y(),V(),N.apply()},magnetMode:()=>d.magnet,setMagnetMode:x,cycleMagnet:k,stayMode:()=>d.stay,setStayMode:C,favorites:()=>d.favorites.slice(),isFavorite:q,toggleFavorite:H,setDrawLock:S,drawLocked:()=>u,collapsed:()=>!0===d.collapsed,setCollapsed:R,openGroup:(e,o=!1)=>{const n=c(e),i=t.querySelector(`.oac-rail__group[data-group="${e}"]`);void 0!==n&&null!==i&&I(n,i,o)},closeFlyout:M,flyoutOpen:()=>null!==j,destroy:()=>{M();for(const e of Z)e();Y.destroy(),w(null),N.destroy(),t.textContent=""}}}function _n(e,t,o){if(void 0===t)return"";const n={regular:kt(e,"Regular hours"),extended:kt(e,"Extended hours"),adjusted:kt(e,"Adjusted prices"),raw:kt(e,"Raw prices")},i=[];for(const e of["session","adjustment","currency","unit"]){const a=t[e];void 0===a||void 0!==o&&o!==e||i.push("session"===e||"adjustment"===e?n[a]:a)}return i.join(" ")}const yn={regular:"Market open",pre:"Pre-open",post:"Post-close",extended:"Extended hours",closed:"Market closed",holiday:"Holiday"},xn={regular:"market-open",pre:"market-pre",post:"market-post",extended:"market-post",closed:"market-closed",holiday:"market-holiday"};function kn(e,t){const o=Math.round(f(e,t)/60);if(0===o)return"UTC";const n=Math.abs(o),i=n%60;return`UTC${o<0?"-":"+"}${Math.floor(n/60)}${0===i?"":":"+String(i).padStart(2,"0")}`}function Cn(e,t,o=!0){return o?m(Math.floor(e),t):g(Math.floor(e),t)}const Sn=new Map;function An(e,t,o,n){const i=t.phase,a=kt(e,`schema.ui.market.${i}`,{},yn[i]),r=t=>null===t?"":function(e,t,o,n){const i=g(e,o),a=v(e,o),r=v(t,o);if(a.year===r.year&&a.month===r.month&&a.day===r.day)return i;const s=`${n??""}\0${o}`;let l=Sn.get(s);if(void 0===l){try{l=new Intl.DateTimeFormat(n,{timeZone:o,weekday:"short"})}catch{l=new Intl.DateTimeFormat(void 0,{timeZone:o,weekday:"short"})}Sn.set(s,l)}return`${l.format(new Date(1e3*e))} ${i}`}(t,o,n,e.locale);let s="";return"regular"===i&&null!==t.closesAt?s=kt(e,"schema.ui.market.closes",{time:r(t.closesAt)},"closes {time}"):"post"!==i&&"extended"!==i||null===t.changesAt?"regular"!==i&&null!==t.opensAt&&(s=kt(e,"schema.ui.market.opens",{time:r(t.opensAt)},"opens {time}")):s=kt(e,"schema.ui.market.until",{time:r(t.changesAt)},"until {time}"),{phase:i,label:a,detail:s}}class Ln{constructor(){Object.defineProperty(this,"_calendar",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_status",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_from",{enumerable:!0,configurable:!0,writable:!0,value:1/0}),Object.defineProperty(this,"_until",{enumerable:!0,configurable:!0,writable:!0,value:-1/0})}read(e,t){if(e!==this._calendar||t<this._from||t>=this._until){this._calendar=e,this._from=t;try{this._status=b(e,t)}catch{this._status=null}this._until=this._status?.changesAt??t+86400}return this._status}until(){return this._until}}function On(e){return!1!==e.statusLineOptions().marketStatus}const $n=2;function En(e){const t=e.panes()[e.primaryPaneIndex()];if(void 0===t)return 2;const o=t.priceScale.precision();return Number.isFinite(o)?Math.max(2,Math.min(8,Math.round(o))):2}function Tn(e,t,o){let n=o.get(t);return void 0===n&&(n=new Intl.NumberFormat(e,{minimumFractionDigits:t,maximumFractionDigits:t}),o.set(t,n)),n}function Pn(e,t,o={}){const n=e.document,i=e.chart,a=o.locale??e.locale;t.classList.add("oac-statusline"),t.setAttribute("role","status"),t.setAttribute("aria-live","polite");const r=Ke(n,"span","oac-statusline__title"),s=Ke(n,"span","oac-statusline__sym"),l=Ke(n,"span","oac-statusline__iv"),c=Ke(n,"span","oac-statusline__iv oac-statusline__variant");r.appendChild(s),r.appendChild(l),r.appendChild(c),t.appendChild(r);const d=(e,o)=>{const i=Ke(n,"span","oac-statusline__field "+o),a=Ke(n,"i");a.textContent=e;const r=Ke(n,"b");return i.appendChild(a),i.appendChild(r),i.hidden=!0,t.appendChild(i),{el:i,val:r}},u=d(kt(e,"O"),"oac-statusline__o"),p=d(kt(e,"H"),"oac-statusline__h"),h=d(kt(e,"L"),"oac-statusline__l"),m=d(kt(e,"C"),"oac-statusline__c"),g=d("","oac-statusline__chg"),f=d(kt(e,"Vol"),"oac-statusline__vol"),b=d(kt(e,"OI"),"oac-statusline__oi"),v=Ke(n,"span","oac-statusline__time");t.appendChild(v);const _=Ke(n,"span","oac-statusline__market");_.hidden=!0,t.appendChild(_);const y=Ke(n,"span","oac-statusline__msg");t.appendChild(y);const x=Ke(n,"span","oac-statusline__tz");t.appendChild(x);const k=new Map,C=new Intl.NumberFormat(a,{minimumFractionDigits:2,maximumFractionDigits:2}),S=new Intl.NumberFormat(a,{notation:"compact",maximumFractionDigits:2});let A=null,L=null,O=!0,$=!1,E=!1;const T=(e,t)=>{e.textContent!==t&&(e.textContent=t)},P=(e,t)=>{e.hidden===t&&(e.hidden=!t)},j=()=>{const t=i.statusLineOptions();P(r,!1!==t.title);const o=_n(e,i.getDataContext()?.variant);T(c,o),P(c,""!==o);const n=!1!==t.chartValues&&null!==A;for(const e of[u,p,h,m])P(e.el,n);const s=En(i);if(n&&null!==A){const e=Tn(a,s,k);T(u.val,e.format(A.open)),T(p.val,e.format(A.high)),T(h.val,e.format(A.low)),T(m.val,e.format(A.close))}const l=!1!==t.barChange&&null!==A;if(P(g.el,l),l&&null!==A){const e=A.close-A.open,t=0!==A.open?e/A.open*100:0,o=e>0?"+":"";T(g.val,`${o}${Tn(a,s,k).format(e)} (${o}${C.format(t)}%)`),g.el.classList.toggle("is-up",e>0),g.el.classList.toggle("is-down",e<0)}const d=!1!==t.volume&&null!==A&&"number"==typeof A.volume;P(f.el,d),d&&null!==A&&T(f.val,S.format(A.volume));const _=!0===t.openInterest&&!1!==i.hasOpenInterest&&void 0!==A?.oi&&Number.isFinite(A.oi);P(b.el,_),_&&void 0!==A?.oi&&T(b.val,S.format(A.oi)),T(v,null!==L&&null!==A?w(L,i.timezone()):""),T(x,i.timezone()),N()},M=new Ln;let I=0,D=0,z=!1;function N(){if(!0!==o.marketStatus||z)return;const t=(o.now??Date.now)()/1e3,n=On(i)?M.read(i.dataLayer.sessionCalendar,t):null,r=null===n?null:An({translate:e.translate,locale:a},n,t,i.timezone());P(_,null!==r),null!==r&&(T(_,""===r.detail?r.label:`${r.label} · ${r.detail}`),_.dataset.phase!==r.phase&&(_.dataset.phase=r.phase));const s=Math.floor(null===n?t+60:Math.min(M.until(),t+3600));s!==D&&(0!==I&&clearTimeout(I),I=0,D=s,0!==s&&(I=setTimeout(()=>{I=0,D=0,N()},1e3*Math.max(1,s-t)+50)))}const R=()=>{if($)return{bar:null,time:null};const e=i.primaryBars(),t=e[e.length-1];return void 0===t?{bar:null,time:null}:{bar:t,time:t.time}},F=(e,t)=>{e===A&&t===L||(A=e,L=t,j())},W=()=>{const e=R();F(e.bar,e.time)},B=i.on("crosshair:move",e=>{const t=e;if(null!==t.bar&&void 0!==t.bar)return O=!1,void F(t.bar,t.time);O=!0,W()}),q=i.on("data:context",j),U=i.on("data:update",e=>{const t=e?.kind;if("reset"===t&&($=!1),O)return void W();const o=R();null!==o.bar&&o.time===L&&F(o.bar,o.time)}),H=i.on("resize",()=>{O&&W()}),K=i.on("timezone:changed",j),G={el:t,setMessage:(e,t="info")=>{T(y,e),y.classList.toggle("is-error","error"===t)},setSymbol:(e,t,o)=>{const n=t?`${t}:${e}`:e;E&&n===s.textContent&&o===l.textContent||(T(s,n),T(l,o),$=E,E=!0,O=!0,$?F(null,null):W())},setBar:(e,t)=>{O=null===e,F(e,t)},refresh:()=>{if(O){const e=R();A=e.bar,L=e.time}j()},destroy:()=>{z=!0,0!==I&&clearTimeout(I),B(),q(),U(),H(),K(),t.textContent=""}};return j(),G}function jn(e){return"string"==typeof e&&(_().includes(e)||y().includes(e))}function Mn(e){const t=e.primarySeries(),o=null===t?void 0:e.seriesTransform(t)?.type;return"point-figure"===o||"renko"===o?o:null}const In=150;function Dn(e){if("string"!=typeof e)return null;const t=e.trim();if(/^https:\/\/[^\s]+$/i.test(t))try{const e=new URL(t);return e.username||e.password?null:e.href}catch{return null}return/^\/(?!\/)[\w./%-]+(?:\?[\w=&.%-]+)?$/.test(t)?t:null}let zn=0;function Nn(e,t,o){const n=e.document,i="mobile"===o.variant;let a,r=!1,s=0,l=null,c=null,d=null,u=null,p=null,h=[],m="",g=null,f=[],b=0,v="",w=!1;const _=()=>{s++,null!==l&&(clearTimeout(l),l=null),c?.abort(),c=null},y=()=>{_();const e=p;p=null,d=null,u=null,h=[],f=[],g=null,m="",w=!1,t.setAttribute("aria-expanded","false"),t.removeAttribute("aria-controls"),e?.()},x=e=>{if(r||w||!f.includes(e)||t.value.trim()!==v||(void 0===o.context?void 0:JSON.stringify(o.context()))!==a)return;const n=e.symbol.trim();""!==n&&(t.blur(),y(),o.onSelect(n,e.exchange))},k=()=>{if(null===d||null===u)return;const t=d.querySelector(".oac-symbol-picker__categories");t.textContent="";const o=Array.from(new Set(h.map(e=>e.assetClass?.trim()).filter(e=>Boolean(e))));if(o.length>1)for(const i of["",...o]){const o=Ke(n,"button","oac-symbol-picker__category",{type:"button","aria-pressed":String(m===i)});o.textContent=i||kt(e,"schema.ui.allAssets",{},"All"),o.addEventListener("click",()=>{_(),m=i,g=null,b=0,k()}),t.appendChild(o)}u.textContent="";const a=h.filter(e=>""===m||e.assetClass===m),r=g?.contractGroup;if(f=void 0===r?a.slice():r.contracts.filter(e=>"string"==typeof e.symbol),void 0!==r){const t=Ke(n,"button","oac-symbol-picker__back",{type:"button"});if(t.textContent=kt(e,"schema.ui.backToSymbols",{},"Back to symbols"),t.addEventListener("click",()=>{g=null,b=0,k()}),u.appendChild(t),r.label){const e=Ke(n,"div","oac-head");e.textContent=r.label,u.appendChild(e)}}if(f.forEach((t,o)=>{if("string"!=typeof t.symbol)return;const a=Ke(n,"button","oac-symbol-picker__row oac-menu__row"+(o===b?" is-active":""),{type:"button",role:"option"});i&&(a.dataset.mobileAction="pick-symbol");const r=Dn(t.iconUrl);if(null!==r){const e=Ke(n,"img","oac-symbol-picker__icon",{src:r,alt:""});a.appendChild(e)}const s=Ke(n,"span","oac-menu__label");if(s.textContent=t.exchange?`${t.exchange}:${t.symbol}`:t.symbol,a.appendChild(s),t.name){const e=Ke(n,"span","oac-menu__sub");e.textContent=t.name,a.appendChild(e)}if(t.contractGroup){const t=Ke(n,"span","oac-symbol-picker__group");t.textContent=kt(e,"schema.ui.showContracts",{},"Contracts"),a.appendChild(t)}a.addEventListener("click",e=>{e.stopPropagation(),t.contractGroup?(g=t,b=0,k()):x(t)}),u?.appendChild(a)}),0===f.length){const t=Ke(n,"div","oac-symbol-picker__empty",{role:"status"});t.textContent=kt(e,"schema.ui.noSymbols",{},"No symbols found"),u.appendChild(t)}},C=x=>{if(_(),v=x.trim(),""===v)return void y();m="",g=null,h=[],f=[],b=0,a=void 0===o.context?void 0:JSON.stringify(o.context());const C=s;w=!0,(()=>{if(null!==d)return;if(d=Ke(n,"div","oac-symbol-picker "+(i?"oac-mobile-results":"oac-menu oac-sym__results"),{role:i?"region":"listbox","aria-label":kt(e,"schema.ui.symbolResults",{},"Symbols")}),d.addEventListener("mousedown",e=>e.preventDefault()),i){const t=Ke(n,"div","oac-mobile-results__head"),o=Ke(n,"strong");o.textContent=kt(e,"schema.ui.symbolResults",{},"Symbols");const i=Ke(n,"button","oac-mobile__action",{type:"button"});i.dataset.mobileAction="close-search",i.textContent=kt(e,"schema.ui.closeSearch",{},"Close"),i.addEventListener("click",y),t.append(o,i),d.appendChild(t)}const o=Ke(n,"div","oac-symbol-picker__categories");d.appendChild(o),u=Ke(n,"div",i?"oac-mobile-results__list":"oac-menu__body"),u.setAttribute("role","listbox"),u.id="oac-symbol-picker-"+ ++zn,d.appendChild(u),t.setAttribute("aria-controls",u.id),t.setAttribute("aria-expanded","true");const a=d;p=e.openOverlay(d,{anchor:t,placement:"below",initialFocus:null,dismissOnOutside:!0,onClose:()=>{d===a&&y()}})})(),null!==d&&(d.querySelector(".oac-symbol-picker__categories").textContent="");const S=(t,o)=>{if(null===u)return;const i=Ke(n,"div","oac-symbol-picker__status",{role:"status"});i.textContent=kt(e,t,{},o),u.textContent="",u.appendChild(i)};S("schema.ui.searchingSymbols","Searching");const A=()=>{C===s&&(w=!1,S("schema.ui.symbolSearchFailed","Search unavailable"))};l=setTimeout(()=>{let e;l=null,c=new AbortController;try{e=Promise.resolve(o.search(v,{signal:c.signal}))}catch{return void A()}e.then(e=>{r||C!==s||null===d||t.value.trim()!==v||(void 0===o.context?void 0:JSON.stringify(o.context()))!==a||(w=!1,h=e.filter(e=>"string"==typeof e.symbol&&""!==e.symbol.trim()),0!==h.length?(b=0,k()):y())},A)},150)},S=()=>C(t.value),A=e=>{if(!e.isComposing&&229!==e.keyCode)if("Escape"!==e.key){if(!w&&t.value.trim()===v&&(void 0===o.context?void 0:JSON.stringify(o.context()))===a)if("ArrowDown"===e.key||"ArrowUp"===e.key){if(0===f.length)return;e.preventDefault(),e.stopImmediatePropagation(),b=(b+("ArrowDown"===e.key?1:-1)+f.length)%f.length,k()}else if("Enter"===e.key&&void 0!==f[b]){e.preventDefault(),e.stopImmediatePropagation();const t=f[b];t.contractGroup?(g=t,b=0,k()):x(t)}}else null!==d&&(e.preventDefault(),y())},L=e=>{const t=e.relatedTarget;t&&!0===d?.contains(t)||y()};t.addEventListener("input",S),t.addEventListener("keydown",A),t.addEventListener("blur",L),t.setAttribute("aria-autocomplete","list"),t.setAttribute("aria-haspopup","listbox"),t.setAttribute("aria-expanded","false");const O=e.bus.on("symbol",y),$=e.bus.on("interval",y);return{open:e=>{r||(t.focus(),void 0!==e&&(t.value=e),""!==t.value.trim()&&C(t.value))},canCommitRaw:()=>!w&&0===f.length,close:y,destroy:()=>{r||(r=!0,y(),O(),$(),t.removeEventListener("input",S),t.removeEventListener("keydown",A),t.removeEventListener("blur",L))}}}const Rn="\n.oac-widget .oac-symbol-picker{min-width:250px;max-width:min(420px,calc(100vw - 24px))}\n.oac-widget .oac-symbol-picker__categories{display:flex;gap:4px;overflow-x:auto;padding:5px 7px;scrollbar-color:var(--oac-sb-thumb) var(--oac-panel);scrollbar-width:thin}\n.oac-widget .oac-symbol-picker__categories::-webkit-scrollbar{height:6px}\n.oac-widget .oac-symbol-picker__categories::-webkit-scrollbar-track{background:var(--oac-panel)}\n.oac-widget .oac-symbol-picker__categories::-webkit-scrollbar-thumb{background:var(--oac-sb-thumb);border-radius:3px}\n.oac-widget .oac-symbol-picker__categories::-webkit-scrollbar-thumb:hover{background:var(--oac-sb-thumb-hover)}\n.oac-widget .oac-symbol-picker__categories:empty{display:none}\n.oac-widget .oac-symbol-picker__category,.oac-widget .oac-symbol-picker__back{background:transparent;border:0;color:inherit;cursor:pointer;padding:4px 7px;font:inherit}\n.oac-widget .oac-symbol-picker__category[aria-pressed=true]{background:var(--oac-elev);border-radius:4px}\n.oac-widget .oac-symbol-picker__row{display:flex;align-items:center;gap:7px;width:100%;text-align:left}\n.oac-widget .oac-symbol-picker__icon{width:18px;height:18px;object-fit:contain}\n.oac-widget .oac-symbol-picker__group{margin-left:auto;opacity:.7}\n.oac-widget .oac-symbol-picker__empty,.oac-widget .oac-symbol-picker__status{padding:9px;color:var(--oac-mut)}\n";function Fn(t){const o=void 0===t?null:e(t);return null!==o&&k(o.bucketing)?o.bucketing:null}const Wn=()=>({status:"cancelled"});function Bn(e){const t=e.getDataContext();return`${t?.symbol}\0${t?.exchange}\0${t?.interval}`}function qn(e,t){return new Promise((o,n)=>{const i=()=>n(t.reason);t.aborted?i():(t.addEventListener("abort",i,{once:!0}),e.then(o,n).finally(()=>t.removeEventListener("abort",i)))})}function Un(e,t){let o=0,n=e;for(;o<n;){const e=o+n>>1;t(e)?n=e:o=e+1}return o}function Hn(e,t,o){const n=e.dataLayer.sessionCalendar;if(null===n)return!0;try{const e=n.sessionFrom(t);return null===e||e.open<o}catch{return!0}}class Kn{constructor(e){Object.defineProperty(this,"_options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_abort",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_destroyed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),this._options=e}goTo(e){if(this.cancel(),this._destroyed)return Promise.resolve({status:"cancelled"});const t=new AbortController;return this._abort=t,this._run(e,t.signal).catch(e=>t.signal.aborted?{status:"cancelled"}:{status:"error",error:e instanceof Error?e:new Error(String(e))}).finally(()=>{this._abort===t&&(this._abort=null)})}cancel(){const e=this._abort;this._abort=null,e?.abort()}destroy(){this._destroyed=!0,this.cancel()}_chart(){const e=this._options.chart,t="function"==typeof e?e():e;return null===t||t.isDestroyed?null:t}async _run(e,t){const{from:o,to:n}=e;if(!Number.isFinite(o)||void 0!==n&&!(Number.isFinite(n)&&n>=o))return{status:"invalid"};let i=this._chart();if(null===i)return{status:"cancelled"};const a=Bn(i),r=Fn(this._options.interval?.()??i.getDataContext()?.interval);if(null===r)return{status:"unsupported"};const s=function(e,t){if("interval"===e.mode){if(e.seconds<86400)return{open:e=>e,close:t=>t+e.seconds};const o=e=>C(e,t);return{open:o,close:n=>C(o(n)+e.seconds+43200,t)}}return{open:o=>A(e,o,t),close:o=>S(e,o,t)??o}}(r,i.timezone()),l=i.primaryBars();if(0===l.length||s.close(l[l.length-1].time)<=o)return{status:"no-data"};const c=i.getVisibleLogicalRange(),d=o-(void 0===n?Math.ceil(Math.max(0,c.to-c.from)/2):0)*(s.close(o)-s.open(o));let u,p=l[0].time;for(;s.open(p)>d&&Hn(i,d,s.open(p));){const e=this._options.loadHistory;if(void 0===e||x(i)){u="unavailable";break}if(u=await qn(e(d,t),t),i=this._chart(),t.aborted||null===i||Bn(i)!==a)return Wn();const o=i.primaryBars()[0]?.time;if("loaded"!==u)break;if(void 0===o||o>=p){u="empty";break}p=o}return function(e,t,o,n,i){const a=e.primaryBars(),r=a.length,s=r>0?t.open(a[0].time):o,l=void 0!==i&&"loaded"!==i&&s>o&&Hn(e,o,s)?i:void 0,c=Un(r,e=>t.close(a[e].time)>o),d=void 0===n?c:Un(r,e=>t.open(a[e].time)>n)-1;if(c>=r||d<c)return void 0===l?{status:"no-data"}:{status:"no-data",history:l};const u=t=>e.dataLayer.timeToIndex(a[t].time)??t;let p,h,m=d,g=!1;if(void 0===n){const t=e.getVisibleLogicalRange(),o=(t.to-t.from)/2,n=u(c),i=Math.max(0,n+o-u(r-1)-4);p=n-o-i,h=n+o-i}else{p=u(c)-.5,h=u(d)+.5;const t=e.timeScale.width;if(t>0){const o=t/e.timeScale.constrainBarSpacing(t/(h-p));if(o<h-p-1e-9)for(h=p+o,g=!0;m>c&&u(m)>h-.5;)m--;else p-=(o-(h-p))/2,h=p+o}}e.setVisibleLogicalRange({from:p,to:h});const f={status:void 0!==l||g?"partial":"placed",from:a[c].time,to:a[m].time};return void 0!==l&&(f.history=l),g&&(f.clipped=!0),f}(i,s,o,n,u)}}const Gn=()=>{},Vn=e=>e instanceof Error&&"WorkspaceConflictError"===e.name,Jn=(e,t)=>e?.workspaces.find(e=>e.id===t),Yn=e=>void 0===e?"":JSON.stringify([e.layout,e.panes,e.activePaneId,e.sync]);function Zn(e,t,o={}){const n=Number.isFinite(o.autosaveDelay)?Math.min(Math.max(0,o.autosaveDelay),2147483647):1e3;let i,a=null,r=null,s=null,l=null,c="",d=!1,u=!1,p=!1,h=null,m=!1,g=!1,f=!1,b=0,v=0,w=Promise.resolve(),_=!1,y="";const x=new Set,k=()=>{try{return!0===t.suspended?.()}catch{return!1}},C=()=>({catalog:a,layoutId:s,revision:r,dirty:d,busy:b>0,suspended:k(),conflict:u,autosave:a?.autosave&&null!==s?m?"saving":p||u?"failed":void 0!==i||_||d?"pending":"saved":"off",error:h}),S=()=>{if(f)return;const e=C(),t=JSON.stringify([a?.revision,r,s,d,e.busy,e.suspended,u,e.autosave,null===h]);if(t!==y){y=t;for(const t of Array.from(x))try{t(e)}catch(e){queueMicrotask(()=>{throw e})}}},A=()=>null!==s&&Yn(Jn(a,s))!==c,L=e=>{h=e,y=""},O=()=>!(null===a||null===r||a.revision<=r||A())&&(r=a.revision,!0),$=()=>{s=null,l=null,c="",d=!1,u=!1},E=()=>{u=!0,l=null,d=!0};async function T(){const t=await e.load();(null===a||t.revision>a.revision)&&(a=t),A()&&E(),O(),S()}async function P(e,t){const o=t?.();for(let n=0;;n++){const i=void 0===t?r:a.revision;try{const o=await e(i);return void 0===t&&(r=Math.max(r,i+1)),p=!1,O(),o}catch(e){if(!Vn(e)||3===n)throw e;if(await T(),void 0===t?r===i:t()!==o)throw e}}}const j=e=>()=>JSON.stringify(Jn(a,e)??null),M=e=>()=>Yn(Jn(a,e)),I=()=>"";async function D(){const t=await e.load();return(null===a||t.revision>=a.revision)&&(a=t),p=!1,null!==s&&void 0===Jn(a,s)&&$(),A()?E():(u=!1,r=a.revision),t}const z=async()=>{null===r&&await D()},N=e=>{g=!0;try{return t.apply(e)}catch(e){return{applied:!1,reason:e instanceof Error?e.message:String(e)}}finally{g=!1}},R=(e,t,o)=>{c=Yn(e),l=t,d=v!==o,d||void 0===i||(clearTimeout(i),i=void 0),u=!1,h=null,O()};async function F(o){const n=t.capture(),i=JSON.stringify(n),a=v;m=!0,S();try{const t=await P(t=>e.saveWorkspace(o,n,{expectedRevision:t}));return R(t,i,a),t}catch(e){throw p=!0,e}finally{m=!1}}function W(e){if(f)return Promise.reject(new Error("The layouts controller is destroyed"));b++,S();const t=w.then(()=>{if(f)throw new Error("The layouts controller is destroyed");return e()});return w=t.then(Gn,Gn),t.then(e=>(b--,h=null,U(),S(),e),e=>{throw b--,L(e),U(),S(),e})}async function B(){if(_=!1,f||null===s)return S();const o=s;try{const n=t.capture(),i=JSON.stringify(n),r=v;if(d=i!==l,!d||!a?.autosave||u||p||k())return S();m=!0,S();const c=await P(t=>e.saveWorkspace(o,n,{expectedRevision:t}));m=!1,s===o&&R(c,i,r)}catch(e){m=!1,p=!0,L(e)}S()}const q=()=>{_||f||(_=!0,w=w.then(B).then(Gn,Gn))};function U(){!a?.autosave||null===s||!d||u||p||m||void 0!==i||q()}const H=()=>{f||g||(v++,void 0!==i&&clearTimeout(i),i=setTimeout(()=>{i=void 0,q()},n),S())},K=t.subscribe?.(H),G=e.subscribe(e=>{f||null!==a&&e.revision<=a.revision||(a=e,O(),U(),S())});return{store:e,state:C,subscribe:e=>(x.add(e),()=>{x.delete(e)}),reload:()=>W(async()=>JSON.parse(JSON.stringify(await D()))),open:o=>W(async()=>{if(k())throw new Error("A layout cannot open while the chart is suspended, as during a replay");const n=p;if(await(async()=>{(void 0!==i||_)&&(void 0!==i&&(clearTimeout(i),i=void 0),await B())})(),p&&!n)throw h;await D();const r=Jn(a,o);if(void 0===r)throw new Error("The saved layout no longer exists");const l=t.capture(),c=v,d=N((e=>JSON.parse(JSON.stringify({layout:e.layout,panes:e.panes,activePaneId:e.activePaneId,sync:e.sync})))(r));if(!d.applied)return d;const u=JSON.stringify(t.capture()),m=a;let g=r;if(m.activeWorkspaceId!==o||m.recentWorkspaceIds[0]!==o)try{g=await P(t=>e.openWorkspace(o,{expectedRevision:t}),M(o))}catch(e){throw N(l).applied||$(),e}return s=g.id,R(g,u,c),d}),save:()=>W(async()=>{if(await z(),null===s)throw new Error("No saved layout is held: save it under a name first");return F(s)}),saveAs:o=>W(async()=>{await D();const n=t.capture(),i=JSON.stringify(n),a=v,r=await P(t=>e.createWorkspace(o,n,{expectedRevision:t}),I);return s=r.id,R(r,i,a),await P(t=>e.openWorkspace(r.id,{expectedRevision:t}),M(r.id)),r}),overwrite:()=>W(async()=>{if(await D(),null===s)throw new Error("The saved layout no longer exists: save it under a name");return c=Yn(Jn(a,s)),r=a.revision,F(s)}),rename:(t,o)=>W(async()=>{await z(),await P(n=>e.rename("workspace",t,o,{expectedRevision:n}),j(t))}),duplicate:(t,o)=>W(async()=>(await z(),await P(n=>e.duplicate("workspace",t,o,{expectedRevision:n}),j(t)))),remove:t=>W(async()=>{await z(),await P(o=>e.remove("workspace",t,{expectedRevision:o}),j(t)),t===s&&($(),O())}),setAutosave:t=>W(async()=>{await z(),await P(o=>e.setAutosave(t,{expectedRevision:o}),I),t&&q()}),changed:H,async flush(){f||(void 0!==i&&(clearTimeout(i),i=void 0),q(),await w)},destroy(){f||(f=!0,void 0!==i&&clearTimeout(i),G(),K?.(),x.clear())}}}const Qn=240,Xn=["data","objects","watchlist","news"],ei={data:"Data",objects:"Objects",watchlist:"Watchlist",news:"News"};function ti(e){const t="object"==typeof e&&null!==e?e:{};return{panel:Xn.includes(t.panel)?t.panel:null,width:"number"==typeof t.width&&Number.isFinite(t.width)?Math.round(Math.max(Qn,Math.min(480,t.width))):300}}function oi(e,t,o){const n=e.document,i=(t,o)=>kt(e,`schema.ui.dock.${t}`,{},o),a=qo(n,"aside","oac-panel-dock");a.hidden=!0,a.setAttribute("aria-label",i("title","Chart information"));const r=qo(n,"div","oac-panel-dock__resize");r.setAttribute("role","separator"),r.setAttribute("aria-orientation","vertical"),r.setAttribute("aria-label",i("resize","Resize information panel")),r.tabIndex=0;const s=qo(n,"div","oac-panel-dock__header"),l=qo(n,"div","oac-panel-dock__tabs");l.setAttribute("role","group"),l.setAttribute("aria-label",i("panels","Information panels"));const c=Xn.filter(e=>"function"==typeof o[e]),d=new Map(c.map(e=>[e,Ko(n,{label:i(e,ei[e]),onClick:()=>$(e)})])),u=e=>{for(const[t,o]of d)o.setAttribute("aria-pressed",String(t===e))},p=Ko(n,{label:i("close","Close"),onClick:()=>O()});p.classList.add("oac-panel-dock__close"),l.append(...d.values()),s.append(l,p);const h=qo(n,"div","oac-panel-dock__body");a.append(r,s,h),t.appendChild(a);const m=ti(o.state);let g=null,f=null,b=!1,v=!1,w=null,_=null;const y=()=>e.root.getBoundingClientRect().width||e.root.clientWidth||1e3,x=()=>y()<=640,k=()=>Math.max(Qn,Math.min(480,y()-320)),C=()=>{o.onChange?.({...m})},S=e=>{m.width=Math.round(Math.max(Qn,Math.min(k(),e))),a.style.width=`${m.width}px`,r.setAttribute("aria-valuemin",String(Qn)),r.setAttribute("aria-valuemax",String(k())),r.setAttribute("aria-valuenow",String(m.width))},A=()=>{if(!f)return;v=!0;const e=f;f=null,e(),v=!1},L=(o=!1)=>{if(b||null===m.panel)return;const i=null!==n.activeElement&&a.contains(n.activeElement)?n.activeElement:null,s=x();s!==("true"===a.dataset.sheet)&&A(),a.dataset.sheet=String(s),r.hidden=s,s&&!f?f=e.openOverlay(a,{placement:"center",modal:!0,initialFocus:i??g?.initialFocus??p,restoreFocus:!1,onClose:()=>{f=null,v||O()}}):s||(a.parentElement!==t&&t.appendChild(a),a.classList.remove("oac-dialog"),a.removeAttribute("aria-modal"),a.removeAttribute("role"),a.style.position="",a.style.left="",a.style.top="",a.style.transform="",S(m.width),o?(g?.initialFocus??p).focus():i?.focus())};function O(){if(null===m.panel)return;m.panel=null,_=null,A(),g?.destroy(),g=null,h.textContent="",a.hidden=!0,t.appendChild(a),u(null);const e=n.activeElement;w?.isConnected&&(null===e||e===n.body||a.contains(e))&&w.focus(),w=null,C()}function $(e,t=!0){if(b)return;const i=o[e];c.includes(e)&&void 0!==i&&(m.panel!==e||null===g?(null!==m.panel&&null!==g||(w=n.activeElement),g?.destroy(),h.textContent="",m.panel=e,a.hidden=!1,u(e),g=i(h),L(t),C()):t&&(g.initialFocus??p).focus())}const E=t=>{"Escape"===t.key&&0===e.overlays.size()&&(t.preventDefault(),t.stopPropagation(),O()),t.target===r&&["ArrowLeft","ArrowRight","Home","End"].includes(t.key)&&(t.preventDefault(),t.stopPropagation(),S("Home"===t.key?Qn:"End"===t.key?k():m.width+("ArrowLeft"===t.key?10:-10)*(t.shiftKey?5:1)),C())},T=e=>{0!==e.button||x()||(e.preventDefault(),e.stopPropagation(),_={x:e.clientX,width:m.width,pointer:e.pointerId},r.setPointerCapture?.(e.pointerId),r.focus())},P=e=>{_&&_.pointer===e.pointerId&&(e.preventDefault(),S(_.width+_.x-e.clientX))},j=e=>{if(_&&_.pointer===e.pointerId){_=null,C();try{r.releasePointerCapture?.(e.pointerId)}catch{}}};a.addEventListener("keydown",E),r.addEventListener("pointerdown",T),r.addEventListener("pointermove",P),r.addEventListener("pointerup",j),r.addEventListener("pointercancel",j);const M=n.defaultView,I=()=>{x()||S(m.width),L()};M?.addEventListener?.("resize",I);const D=M?.ResizeObserver,z=D?new D(I):null;z?.observe(e.root),S(m.width);const N=m.panel;return m.panel=null,null!==N&&$(N,!1),{el:a,open:$,close:O,toggle:e=>{m.panel===e?O():$(e)},state:()=>({...m}),restore:e=>{const t=ti(e);S(t.width),null!==t.panel&&c.includes(t.panel)?$(t.panel,!1):O()},destroy:()=>{b||(O(),b=!0,z?.disconnect(),M?.removeEventListener?.("resize",I),a.removeEventListener("keydown",E),r.removeEventListener("pointerdown",T),r.removeEventListener("pointermove",P),r.removeEventListener("pointerup",j),r.removeEventListener("pointercancel",j),a.remove())}}}const ni='\n.oac-widget .oac-panel-dock { position: relative; flex: none; min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--oac-panel); border-left: 1px solid var(--oac-bd); }\n.oac-widget .oac-panel-dock__header { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 10px; border-bottom: 1px solid var(--oac-bd-soft); flex: none; }\n.oac-widget .oac-panel-dock__tabs { display: flex; flex-wrap: wrap; gap: 3px; min-width: 0; }\n.oac-widget .oac-panel-dock__tabs .oac-btn, .oac-widget .oac-panel-dock__close { padding: 0 6px; }\n.oac-widget .oac-panel-dock__tabs .oac-btn { border-color: transparent; background: transparent; }\n.oac-widget .oac-panel-dock__tabs .oac-btn[aria-pressed="true"] { background: var(--oac-elev); color: var(--oac-tx); border-color: var(--oac-bd); }\n.oac-widget .oac-panel-dock__close { color: var(--oac-mut); }\n.oac-widget .oac-panel-dock__body { overflow: auto; min-height: 0; flex: 1 1 auto; overscroll-behavior: contain; }\n.oac-widget .oac-panel-dock__resize { position: absolute; z-index: 2; top: 0; bottom: 0; left: -4px; width: 8px; cursor: col-resize; touch-action: none; }\n.oac-widget .oac-panel-dock__resize:hover, .oac-widget .oac-panel-dock__resize:focus-visible { background: var(--oac-ring-soft); }\n.oac-widget .oac-panel-dock[data-sheet="true"] { position: absolute !important; inset: 0 !important; width: 100% !important; max-width: none !important; height: 100%; max-height: none; transform: none !important; border: 0; border-radius: 0; }\n.oac-widget .oac-panel-dock[data-sheet="true"] .oac-panel-dock__header { padding: 12px; }\n.oac-widget .oac-panel-dock[data-sheet="true"] .oac-btn { min-height: 40px; }\n.oac-widget .oac-panel-dock__body > .oac-objects { width: auto; max-width: none; border: 0; box-shadow: none; }\n';function ii(){if(this.context.overlays.size()>0)return["overlay"];const e=[],t=this._doc.activeElement,o=this._opts.keyboardRoute?.();if(!1===o||null!==t&&this._dataStatus.el.contains(t))return[];const n=null!==t&&this.root.contains(t)?t.closest("[data-key-scope]")?.getAttribute("data-key-scope"):null;return n&&e.push(n),null!==this._rail&&null!==t&&this._rail.el.contains(t)&&e.push("rail"),(o||this._inChart())&&e.push("chart"),(o||this._pointerInside||null!==t&&this.root.contains(t))&&e.push("widget"),e.push("global"),e}function ai(){const e=this._keymap,t=this.draw,o=()=>({hasSelection:null!==t.selected(),hasTarget:null!==t.hovered(),editingText:!1,placing:null!==t.activeTool()}),n=()=>{const e=t.selection();if(e.length>0)return e.slice();const o=t.hovered();return null===o?[]:[o]},i=()=>(this._rail?.refresh(),!0),a=()=>{const e=this.alerts.hovered();return void 0!==e&&null===t.activeTool()&&(this.alerts.remove(e),i())},r=e=>{const r=he(e,o());if(null===r)return("Delete"===e.key||"Backspace"===e.key)&&a();switch(r.type){case"delete":un(this.context,"delete",n());break;case"nudge":t.nudge(n(),r.dx,r.dy);break;case"cancel":t.cancel(),null===t.activeTool()&&this._rail?.setDrawLock(!1);break;case"finish":t.finish();break;case"popAnchor":t.popAnchor();break;default:return!1}return i()},s=()=>{const e=o();return e.hasSelection||e.hasTarget},l=e=>()=>!!s()&&(e(n()),i()),c=(t,o,n,i,a={})=>{e.register(t,o,"widget",{label:n,group:a.group??"Drawing",hidden:a.hidden,layered:a.layered,command:i,rebindable:!0!==a.fixed})},d=e=>()=>(ut(this.context,e),i());c("Mod+Z",d("undo"),"Undo","undo",{group:"Widget"}),c("Mod+Shift+Z",d("redo"),"Redo","redo",{group:"Widget"}),c("Mod+Y",d("redo"),"Redo","redo-alt",{group:"Widget",hidden:!0}),c("Mod+C",l(e=>t.copy(e)),"Copy the selected drawing","copy"),c("Mod+X",l(e=>null===dn(this.context,e).noDelete&&t.cut(e)),"Cut the selected drawing","cut"),c("Mod+V",()=>(t.paste(),i()),"Paste drawings","paste"),c("Mod+D",l(e=>t.duplicate(e)),"Duplicate the selected drawing","duplicate"),c("Delete",()=>s()?(un(this.context,"delete",n()),i()):a(),"Delete the selected drawing","delete"),c("Backspace",r,"Delete, or drop the last anchor while placing","delete-back",{fixed:!0}),c("Enter",r,"Finish the drawing being placed","finish",{fixed:!0});for(const[e,t]of[["left","ArrowLeft"],["right","ArrowRight"],["up","ArrowUp"],["down","ArrowDown"]])c(t,r,`Nudge the selection ${e} (Shift: ten pixels)`,`nudge-${e}`,{layered:!0,fixed:!0});for(const e of["left","right","up","down"])c(`Shift+Arrow${e[0].toUpperCase()}${e.slice(1)}`,r,"Nudge ten pixels",`nudge-${e}-far`,{hidden:!0,layered:!0,fixed:!0});c("Escape",e=>null!==t.activeTool()?(r(e)||(t.setTool(null),this._rail?.setDrawLock(!1)),!0):t.selection().length>0&&(t.select(null),this._rail?.refresh(),!0),"Leave the tool, then clear the selection","leave",{fixed:!0});for(const[e,o]of Object.entries(pe()))c(o,()=>(this._rail?.setDrawLock(!1),t.setTool(e),!0),mn(e),`tool:${e}`,{group:"Drawing tools"});const u=!1!==this._opts.shortcutsEditor;if(c("?",()=>(Lo(this.context,{edit:u}),!0),"Keyboard shortcuts","shortcuts",{group:"Widget",fixed:!0}),!u)return p=e,void Co.add(p);var p;const h=this.context.storage;ri.call(this),this._cleanups.push(e.onChange(()=>{const t=e.overrides();0===Object.keys(t).length?h.remove(to):h.set(to,t)}))}function ri(){!1!==this._opts.shortcutsEditor&&this._keymap.applyOverrides(this.context.storage.get(to))}function si(){const e=this.root,t=this._chartEl,o=()=>{this._pointerInside=!0},n=()=>{this._pointerInside=!1,this._pointerInChart=!1},i=()=>{this._pointerInChart=!0},a=()=>{this._pointerInChart=!1};e.addEventListener("pointerenter",o),e.addEventListener("pointerleave",n),t.addEventListener("pointerenter",i),t.addEventListener("pointerleave",a),this._cleanups.push(()=>{e.removeEventListener("pointerenter",o),e.removeEventListener("pointerleave",n),t.removeEventListener("pointerenter",i),t.removeEventListener("pointerleave",a)})}const li="state",ci="drawings:";function di(e){const t={...e};delete t.viewport,delete t.barSpacing;const o=e=>{if(!tt(e))return e;const t={...e,autoScale:!0};return delete t.range,delete t.ratioLock,t};return Array.isArray(t.panes)&&(t.panes=t.panes.map(e=>{if(!tt(e))return e;const t={...e};return tt(e.priceScale)&&(t.priceScale=o(e.priceScale)),tt(e.scales)&&(t.scales=Object.fromEntries(Object.entries(e.scales).map(([e,t])=>[e,o(t)]))),t})),t}function ui(e,t){if(void 0!==e||"both"!==t.navigation?.mousePan)return t;const{mousePan:o,...n}=t.navigation;return{...t,navigation:n}}function pi(e){if(void 0!==e?.chart){const t=e.symbol===this._symbol&&e.exchange===this._exchange&&e.interval===this._interval&&L(e.variant)===L(this._variant),o=ui(e.savedBy,e.chart);let n=t?o:di(o);null!==this.instrumentDrawings&&null!==bi(e)&&(n={...n,drawings:this.draw.toJSON()});const i=this.chart.restoreState(n);i.applied?(vi.call(this,e.chart),this._keepView=t,this._pendingView=t?e.chart.viewport??null:null):this._toasts.toast(kt(this.context,"The saved layout could not be restored: {error}",{error:i.reason??"unknown reason"}),"error")}e?.rail&&null!==this._rail&&this._rail.restorePrefs(e.rail),e?.panels&&this._dock?.restore(e.panels)}function hi(e){const t=this._storage,o=this._opts.drawingStore??(t.enabled?mi(t):me());return void 0!==e?.chart?.drawings&&ge(o,bi(e),e.chart.drawings),new fe(this.chart,this.draw,{store:o,...this._holdDrawings?{key:e=>this._holdDrawings?null:be(e)}:{},onError:({operation:e,key:t})=>{if("read"===e||this._destroyed)return;const o=kt(this._opts,"The drawings for {instrument} could not be saved",{instrument:decodeURIComponent(t)});this._statusline?.setMessage(o,"error"),this._bus.emit("status",{text:o,kind:"error"})}})}function mi(e){return{get:t=>e.get(ci+t),set:(t,o)=>e.set(ci+t,o),remove:t=>e.remove(ci+t)}}function gi(){this._holdDrawings&&(this._holdDrawings=!1,this.instrumentDrawings?.setInstrument({symbol:this._symbol,exchange:this._exchange}))}function fi(){this._restoring&&(this._stateGiven=!0,gi.call(this))}function bi(e){return be({symbol:e.symbol.toUpperCase(),exchange:e.exchange})}function vi(e){const t=this.chart.seriesTransform(this._series)?.type??this.chart.seriesType(this._series),o=(e.series??[]).find(e=>null!==e&&(e.transform?.type??e.type)===t);void 0!==o?.style&&Object.keys(o.style).length>0&&this._series.applyOptions(o.style)}function wi(e){if(!tt(e))return{applied:!1,reason:"not a widget state object"};if(void 0!==e.version&&1!==e.version)return{applied:!1,reason:`widget state version ${String(e.version)} is not 1`};let t;try{t=O(e.variant)}catch(e){return{applied:!1,reason:e instanceof Error?e.message:"invalid data variant"}}_i(e),"dark"!==e.theme&&"light"!==e.theme||this.setTheme(e.theme),jn(e.chartType)&&this._selectChartType(e.chartType,tt(e.chart)?e.chart:void 0),void 0!==e.rail&&null!==this._rail&&this._rail.restorePrefs(e.rail),void 0!==e.panels&&this._dock?.restore(e.panels);const o="string"==typeof e.symbol?e.symbol.toUpperCase():this._symbol,n="string"==typeof e.exchange?e.exchange:this._exchange,i="string"==typeof e.interval&&$(e.interval)?e.interval:this._interval,a=L(t)===L(this._variant),r=o===this._symbol&&n===this._exchange&&i===this._interval&&a;let s;if(tt(e.chart)){let t=ui(e.savedBy,e.chart);const i=this.instrumentDrawings,a=null!==i&&(o!==this._symbol||n!==this._exchange)&&null!==be({symbol:o,exchange:n}),l=t.drawings;if(a&&(t={...t,drawings:this.draw.toJSON()}),s=this.chart.restoreState(r?t:di(t)),!s.applied)return{applied:!1,reason:s.reason,chart:s};vi.call(this,t),fi.call(this),a&&null!==i&&i.setDocument({symbol:o,exchange:n},l??[]),this._keepView=r,this._pendingView=r?t.viewport??null:null}return fi.call(this),r||(this._cancelNavigation(),i!==this._interval&&(this._interval=i,this._bus.emit("interval",{interval:i})),o===this._symbol&&n===this._exchange||(this._symbol=o,this._exchange=n,this._bus.emit("symbol",{symbol:o,exchange:n})),a||(this._variant=t,this._bus.emit("variant",{variant:t})),this._statusline?.setSymbol(this._symbol,this._exchange,this._interval),this._topbar?.refresh(),this._mobile?.refresh(),this._opts.feed?this.reload():(this._series.setData([]),this._publishDataContext())),this._rail?.refresh(),this._statusline?.refresh(),this._bus.emit("layout",{reason:"restore",chartType:this.chartType()}),this._scheduleSave(),void 0===s?{applied:!0}:{applied:!0,chart:s}}function _i(e){if(Fe(e.interval),tt(e.chart)&&Array.isArray(e.chart.indicators))for(const t of e.chart.indicators)tt(t)&&tt(t.settings)&&Fe(t.settings.timeframe)}function yi(){const e=this._storage.get(li);if(!tt(e)||1!==e.version)return null;_i(e);const t=function(e){try{return O(e)}catch{return null}}(e.variant),o=tt(e.chart)?e.chart:void 0;return{version:1,symbol:"string"==typeof e.symbol?e.symbol:"",exchange:"string"==typeof e.exchange?e.exchange:"",interval:"string"==typeof e.interval&&""!==e.interval?e.interval:"1d",chartType:"string"==typeof e.chartType?e.chartType:"candlestick",theme:"light"===e.theme?"light":"dark",...t?{variant:t}:{},chart:o&&null===t?di(o):o,rail:tt(e.rail)?e.rail:null,panels:ti(e.panels),..."string"==typeof e.savedBy?{savedBy:e.savedBy}:{}}}function xi(){this._storage.enabled&&!this._destroyed&&(this._restoring?this._saveWanted=!0:(0!==this._saveTimer&&clearTimeout(this._saveTimer),this._saveTimer=setTimeout(()=>{this._saveTimer=0,this._saveNow()},250)))}function ki(){if(this._storage.enabled&&!this._destroyed)if(this._restoring)this._saveWanted=!0;else{0!==this._saveTimer&&(clearTimeout(this._saveTimer),this._saveTimer=0);try{this._storage.set(li,this.getState())||this.context.status(kt(this.context,"The chart layout could not be saved"),"error")}catch(e){this.context.status(kt(this.context,"The chart layout could not be saved: {error}",{error:e instanceof Error?e.message:"invalid state"}),"error")}}}function Ci(){const e=this._doc.defaultView,t=!this._storage.loaded;if(null!=e&&"function"==typeof e.addEventListener){const o=t?()=>{this._saveNow(),this._storage.flush()}:()=>this._saveNow();e.addEventListener("pagehide",o),this._cleanups.push(()=>e.removeEventListener("pagehide",o))}if(t){const e=this._doc,t=()=>{"hidden"===e.visibilityState&&(0!==this._saveTimer&&this._saveNow(),this._storage.flush())};e.addEventListener("visibilitychange",t),this._cleanups.push(()=>e.removeEventListener("visibilitychange",t))}}function Si(){const e={symbol:this._symbol,exchange:this._exchange,interval:this._interval,variant:this._variant,chartType:this.chartType(),theme:this._themeName};return this.root.style.visibility="hidden",this._storage.load().then(()=>{if(!this._destroyed){this._timeframePreferences.reload();try{this._bus.shelter(()=>Oi.call(this,e))}catch(e){this._restoring=!1,this._toasts.toast(kt(this.context,"The saved layout could not be restored: {error}",{error:Ct(this.context,e)}),"error");try{gi.call(this),Li.call(this)}catch{}}finally{this._restoring=!1,this._holdDrawings=!1,this.root.style.visibility=""}}})}class Ai extends mt{constructor(){super(...arguments),Object.defineProperty(this,"_sheltered",{enumerable:!0,configurable:!0,writable:!0,value:!1})}emit(e,t){if(this._sheltered)try{super.emit(e,t)}catch{}else super.emit(e,t)}shelter(e){const t=this._sheltered;this._sheltered=!0;try{e()}finally{this._sheltered=t}}}function Li(){const e=this.dataController,t=e?.getState().request??null,o=null!==t&&t.symbol===this._symbol&&t.exchange===this._exchange&&t.interval===this._interval&&L(t.variant)===L(this._variant);null===e||""===this._symbol||o||this.reload()}function Oi(e){const t=this._saveWanted,o=this._stateGiven?null:yi.call(this),n=this._opts,i={symbol:this._symbol,exchange:this._exchange,interval:this._interval,variant:this._variant};if(null!==o){const t=this._symbol===e.symbol&&this._exchange===e.exchange;t&&void 0===n.symbol&&(this._symbol=o.symbol.toUpperCase()),t&&void 0===n.exchange&&(this._exchange=o.exchange),void 0===n.interval&&this._interval===e.interval&&$(o.interval)&&(this._interval=o.interval),void 0===n.variant&&L(this._variant)===L(e.variant)&&(this._variant=o.variant)}const a=this._symbol!==i.symbol||this._exchange!==i.exchange;(a||this._interval!==i.interval||L(this._variant)!==L(i.variant))&&(null===this.dataController&&this._series.setData([]),this._publishDataContext(),this._statusline?.setSymbol(this._symbol,this._exchange,this._interval),this._topbar?.refresh(),this._mobile?.refresh()),this.history.ignore(()=>{null!==o&&null!==this.instrumentDrawings&&void 0!==o.chart?.drawings&&ge(n.drawingStore??mi(this._storage),bi(o),o.chart.drawings),gi.call(this);const t=this._storage.get(gn);if(null!==t&&null!==this._rail&&this._rail.restorePrefs(t),ri.call(this),null===o)return;const i=o.chartType;void 0===n.chartType&&this.chartType()===e.chartType&&i!==e.chartType&&jn(i)&&this._selectChartType(i,o.chart),void 0===n.theme&&this._themeName===e.theme&&o.theme!==e.theme&&this.setTheme(o.theme),pi.call(this,o)}),null!==o&&(this._rail?.refresh(),this._statusline?.refresh()),this._restoring=!1,this._saveWanted=!1,t&&this._scheduleSave(),Li.call(this),this._interval!==i.interval&&this._bus.emit("interval",{interval:this._interval}),a&&(this._bus.emit("symbol",{symbol:this._symbol,exchange:this._exchange}),this.chart.emit("symbol",{symbol:this._symbol,exchange:this._exchange})),L(this._variant)!==L(i.variant)&&this._bus.emit("variant",{variant:this._variant}),null!==o&&this._bus.emit("layout",{reason:"restore",chartType:this.chartType()})}function $i(e){if(this._destroyed)return;const t=Ct(this.context,e.error);if("load"!==e.operation)return void this.context.status(kt(this.context,"Saved chart settings could not be written: {error}",{error:t}),"error");const o=kt(this.context,"Saved chart settings could not be read, so changes are kept for this session only: {error}",{error:t});this.context.status(o,"error"),this._toasts.toast(o,"error")}const Ei="widget.theme",Ti="p0",Pi=["symbol","interval","variant","theme","layout"],ji=["alert:created","alert:updated","alert:removed","alert:triggered","alert:expired","replay:start","replay:stop","replay:end"],Mi=["lastClosedTime","lastTouchedTime","lastTriggeredAt","lastTriggeredTime"];function Ii(e){const t=di(e),o=t.alerts;return void 0!==o&&Array.isArray(o.alerts)?{...t,alerts:{...o,alerts:o.alerts.map(e=>{const t={...e};for(const e of Mi)delete t[e];return t})}}:t}function Di(e,t,o){return{id:e,symbol:t.symbol,exchange:t.exchange,interval:t.interval,...t.variant?{variant:t.variant}:{},chartType:t.chartType,chart:o,settings:{[Ei]:t.theme},volume:!1,magnet:t.rail?.magnet??"off",stay:t.rail?.stay??!1,comparisons:[],comparisonMode:"percent"}}function zi(e,t,o){const n=o?t.settings[Ei]:void 0,i=e.getState().rail;return e.restoreState({version:1,symbol:t.symbol,exchange:t.exchange,interval:t.interval,chartType:t.chartType,chart:t.chart,..."dark"===n||"light"===n?{theme:n}:{},...t.variant?{variant:t.variant}:{},...null===i?{}:{rail:{...i,magnet:t.magnet,stay:t.stay}}})}function Ni(e){return{capture(){const t=JSON.parse(JSON.stringify(e.getState())),o=Di(Ti,t,Ii(t.chart));return{layout:{rows:1,columns:1,slots:[{paneId:Ti,row:0,column:0,rowSpan:1,columnSpan:1}]},panes:[o],activePaneId:Ti,sync:{crosshair:!0,viewport:!0,symbol:!1,interval:!1}}},apply(t){const o=function(e){if(1!==e.panes.length)return`a layout of ${e.panes.length} charts needs a chart grid`;const[t]=e.panes;if(!$(t.interval))return`unknown interval ${t.interval}`;if(!jn(t.chartType))return`unknown chart type ${t.chartType}`;if(t.comparisons.length>0)return"comparison symbols are not supported in a widget chart";const o=new Set(E().map(e=>e.id)),n=(t.chart.indicators??[]).find(e=>!o.has(e.indicatorId));return void 0===n?"":`unavailable study ${n.indicatorId}`}(t);if(""!==o)return{applied:!1,reason:o};const[n]=t.panes,i=zi(e,n,!0);return i.applied?{applied:!0}:{applied:!1,reason:i.reason??"the chart state could not be restored"}},subscribe(t){const o=[...Pi.map(o=>e.on(o,t)),...ji.map(o=>e.chart.on(o,t)),e.history.subscribe(t)];return()=>{for(const e of o)e()}},suspended:()=>x(e.chart)}}function Ri(e){return!1===e?.removable||!1===e?.listed}const Fi=new WeakMap;function Wi(e,t){void 0===t?Fi.delete(e):Fi.set(e,t)}const Bi=(e,t,o,n)=>({version:void 0!==o&&o>0?2:1,indicators:e??[],panes:t,...void 0===o?{}:{primaryPane:o},...n});function qi(e,t){const o=t.panes??[];return{preserveScaleFormats:(e.restoreOptions?.preserveScaleFormats??[]).filter(({paneIndex:e,scaleId:t})=>void 0!==o[e]&&("right"===t||Object.prototype.hasOwnProperty.call(o[e].scales??{},t)))}}function Ui(e,t,o,n,i){const{chart:a}=e;if(void 0===t.planIndicatorTemplateState)throw new Error("This template store cannot apply templates");if(x(a))throw new Error("Stop the replay before applying a template");const r=a.getState(),s=t.planIndicatorTemplateState(a,o,n);if("append"===n&&s.indicators.length===(r.indicators??[]).length)return!1;const l={drawings:r.drawings,alerts:r.alerts},c=void 0!==r.sourceAbove&&s.indicators.some(e=>e.instanceId===r.sourceAbove)?{sourceAbove:r.sourceAbove}:{};let d=!1;const u=a.on("state:restore:start",()=>{d=!0});try{const e=a.restoreState(Bi(s.indicators,s.panes??("append"===n?r.panes:r.panes?.slice(0,1)),s.primaryPane,{...l,...c}),s.restoreOptions??{});if(!e.applied)throw new Error(e.reason??"The template could not be applied");if(e.indicators!==s.indicators.length)throw new Error("The chart did not restore every study")}catch(e){throw d&&a.restoreState(Bi(r.indicators,r.panes,r.primaryPane,{...l,...void 0===r.sourceAbove?{}:{sourceAbove:r.sourceAbove},viewport:r.viewport,barSpacing:r.barSpacing}),qi(s,a.getState())),e}finally{u()}const p=a.getState(),h=e=>{const t=a.getState();return a.restoreState(Bi(e.indicators,e.panes,e.primaryPane,{...void 0===e.sourceAbove?{}:{sourceAbove:e.sourceAbove},drawings:t.drawings,alerts:t.alerts}),qi(s,t)).applied};return e.history?.push({label:i,undo:()=>h(r),redo:()=>h(p)}),!0}function Hi(e,t,o){let n;try{n=t.captureIndicatorTemplate?.(e.chart)??(e.chart.getState().indicators??[]).filter(e=>!Ri(e.policy))}catch(e){return Promise.reject(e)}return 0===(Array.isArray(n)?n:n.indicators).length?Promise.reject(new Error("The chart has no studies of yours to save")):t.createTemplate(o,n)}const Ki=e=>(t,o,n={})=>kt(e,`schema.ui.layouts.${t}`,n,o);function Gi(e,t){const o=Ki(e);return null===t.layoutId?o("unsaved","This chart is not saved as a layout"):t.conflict?o("conflict","Changed in another window"):t.catalog?.autosave?"saving"===t.autosave?o("saving","Saving"):"failed"===t.autosave?o("failed","Could not save"):"pending"===t.autosave?t.suspended?o("suspended","Autosave waits for the replay to end"):o("pending","Waiting to save"):o("saved","Saved"):t.dirty?o("dirty","Unsaved changes"):o("saved","Saved")}function Vi(e,t,o){let n=!1;return e.subscribe(e=>{const i="failed"===e.autosave&&!e.conflict;n||!i&&!e.conflict||o(i?t("autosaveStopped","Autosave stopped: the layout could not be saved"):t("conflictStatus","The layout was changed in another window")),n=i||e.conflict})}function Ji(e){return null!==e.layoutId&&(e.conflict||"failed"===e.autosave||e.dirty&&!e.catalog?.autosave)}const Yi=Tt(()=>import("./openalgo-charts.widget.layouts-menu-B7XYKPAW.mjs"));function Zi(e,t,o){return Yi.load().then(n=>{if(e.chart.isDestroyed)throw new Error("The widget was destroyed before its Layouts menu opened");return n.mountLayoutsMenu(e,t,o)})}function Qi(e,t,o,n,i){n.handle?.isOpen()?n.handle.el.focus():Pt(Yi,i=>{n.handle=i.mountLayoutsMenu(e,t,o)},t=>e.toast(jt(e,Ki(e)("title","Layouts"),t),"error"),i,{slot:n,doc:e.document,from:o})}function Xi(e,t,o){try{const n=t();if(null===n)return!1;const i=n.toDataURL("image/png"),a=e.createElement("a");return a.href=i,a.download=o,(e.body??e.documentElement).appendChild(a),a.click(),a.remove(),!0}catch{return!1}}function ea(){const e=globalThis;return void 0!==e.navigator?.clipboard?.write&&void 0!==e.ClipboardItem}function ta(e,t,o,n){const i=t=>n(kt(e,"Copy failed: {error}",{error:Ct(e,t)}),"error");try{t.toBlob(t=>{if(null===t)return void n(kt(e,"The canvas produced no image"),"error");const a=globalThis.ClipboardItem;globalThis.navigator.clipboard.write([new a({"image/png":t})]).then(()=>n(o,"info"),i)},"image/png")}catch(e){i(e)}}const oa=Tt(()=>import("./openalgo-charts.widget.chart-data-export-dialog-CX6h5-cp.mjs")),na=Tt(()=>import("./openalgo-charts.widget.chart-type-settings-Bu7g-LFB.mjs")),ia={candlestick:"Candles","hollow-candle":"Hollow candles",bar:"Bars","high-low":"High-low","volume-candle":"Volume candles",line:"Line","line-markers":"Line with markers",step:"Step line",area:"Area","hlc-area":"HLC area",baseline:"Baseline","point-figure":"Point and figure",kagi:"Kagi"};function aa(e){const t=ia[e]??(y().includes(e)?P(e).name:void 0);return void 0!==t?t:e.replace(/[-_]+/g," ").replace(/^\w/,e=>e.toUpperCase())}function ra(){const e=y();return[..._().filter(t=>{try{return!e.includes(t)&&T(t).isPriceSeries}catch{return!1}}),...e]}function sa(e){const t=/^(\d*)\s*([smhdwSMHDW])$/.exec(e.trim());if(null===t)return e.toUpperCase();const o=""===t[1]||"1"===t[1]?"":t[1],n=t[2];return"m"===n?`${""===t[1]?"1":t[1]}m`:"s"===n?`${""===t[1]?"1":t[1]}s`:"h"===n||"H"===n?`${""===t[1]?"1":t[1]}h`:o+n.toUpperCase()}function la(e,t={}){const o=e.brandingOptions();if(!o||"string"!=typeof o.href||!/^https?:\/\//i.test(o.href))return null;const n="string"==typeof o.label&&""!==o.label.trim()?o.label.trim():kt(t,"Chart branding");return{href:o.href,label:n}}function ca(e){return e.timeframePreferences?[...new Map([...e.timeframePreferences.favorites(),e.state().interval].map(e=>[We(e),e])).values()]:e.intervals}function da(e,t,o){const n=e.document;t.classList.add("oac-topbar"),t.setAttribute("role","toolbar"),t.setAttribute("aria-label",kt(e,"Chart toolbar"));const i=(e,t="")=>Ke(n,"button","oac-btn"+(t?" "+t:""),{type:"button","aria-label":e}),a=()=>Ke(n,"span","oac-sep",{role:"separator"}),r=(e,t)=>{e.classList.toggle("is-off",t),e.setAttribute("aria-disabled",String(t))},s=Ke(n,"div","oac-sym");s.appendChild(Ge(n,ie("search"),"chrome"));const l=Ke(n,"input","oac-sym__input",{type:"text","aria-label":kt(e,"Symbol"),placeholder:kt(e,"Symbol"),autocomplete:"off",spellcheck:"false"});s.appendChild(l);const c=Ke(n,"span","oac-sym__ex");s.appendChild(c),t.appendChild(s),t.appendChild(a());let d=null;const u=(e,t)=>{d?.close();const n=e.trim().toUpperCase();""!==n?(o.onSymbol(n,t),l.blur()):T()};o.search&&(d=Nn(e,l,{search:o.search,onSelect:u,context:()=>`${o.state().exchange}:${o.state().symbol}:${o.state().interval}`})),l.addEventListener("keydown",e=>{const t=e;"Enter"===t.key?(t.preventDefault(),(null===d||d.canCommitRaw())&&u(l.value)):"Escape"===t.key&&(T(),l.blur())}),l.addEventListener("focus",()=>{l.select()}),l.addEventListener("blur",()=>{T()});const p=function(e,t,o){const n=e.document,i=Ke(n,"div","oac-pills",{role:"radiogroup","aria-label":kt(e,"Interval")}),a=new Map,r=()=>{i.textContent="",a.clear();const t=ca(o);for(const r of t){const t=Ke(n,"button",void 0,{type:"button",role:"radio","aria-pressed":"false","aria-label":kt(e,"Interval {code}",{code:sa(r)})});t.textContent=sa(r),t.dataset.interval=r,t.disabled=!1===o.canSelectInterval?.(r),t.addEventListener("click",()=>o.onInterval(r)),i.appendChild(t),a.set(r,t)}};let s;if(r(),t.appendChild(i),o.timeframePreferences){const i=Ke(n,"button","oac-btn oac-topbar__interval-menu",{type:"button","aria-label":kt(e,"Timeframes")});i.appendChild(Ge(n,ie("chevron-down"),"chrome")),i.setAttribute("aria-haspopup","dialog"),i.addEventListener("click",()=>{s?.(),s=Et(e,i,{intervals:o.intervals,current:()=>o.state().interval,preferences:o.timeframePreferences,...o.canSelectInterval?{canSelect:o.canSelectInterval}:{},onSelect:o.onInterval})}),t.appendChild(i)}const l=()=>{const e=o.state();ca(o).join("|")!==[...a.keys()].join("|")&&r();for(const[t,n]of a)n.setAttribute("aria-pressed",String(t===e.interval)),n.setAttribute("aria-checked",String(t===e.interval)),n.disabled=!1===o.canSelectInterval?.(t)},c=o.timeframePreferences?.subscribe(l);return{refresh:l,destroy:()=>{c?.(),s?.()}}}(e,t,o);t.appendChild(a());const h=i(kt(e,"Chart type"),"oac-topbar__type"),m=Ge(n,"","chrome"),g=Ke(n,"span");h.append(m,g),h.appendChild(Object.assign(Ke(n,"span","oac-chev",{"aria-hidden":"true"}),{innerHTML:ie("chevron-down")})),h.setAttribute("aria-haspopup","menu"),h.addEventListener("click",()=>{const t=o.state().chartType,n=y()[0];rn(e,h,ra().flatMap(i=>[...i===n?[kt(e,"schema.chartType.group.transforms",{},"Transforms")]:[],{label:kt(e,`schema.chartType.${i}`,{},aa(i)),icon:`chart-${i}`,on:i===t,onSelect:()=>o.onChartType(i)}]),{ariaLabel:kt(e,"Chart type")})});const f=function(e,t){const o=e.document,n=Ke(o,"button","oac-btn oac-btn--icon oac-topbar__type-settings",{type:"button","aria-haspopup":"dialog"});n.appendChild(Ge(o,ie("settings"),"chrome"));const i=()=>{const t=Mn(e.chart)??"";return kt(e,"schema.ui.chartTypeSettings.title",{name:kt(e,`schema.chartType.${t}`,{},aa(t))},"{name} settings")};e.tips.attach(n,()=>({title:i(),side:"bottom"}));let a=null;const r={waiting:null};return n.addEventListener("click",()=>{Pt(na,t=>{a?.close(),null!==Mn(e.chart)&&(a=t.openChartTypeSettings(e,n))},t=>e.status(jt(e,i(),t),"error"),()=>t.isConnected,{slot:r,doc:o,from:n})}),{el:n,refresh:()=>{const t=Mn(e.chart)??"";n.dataset.type!==t&&(n.dataset.type=t,n.hidden=""===t,e.tips.target()===n&&e.tips.hide(),e.tips.refreshLabel(n))},close:()=>a?.close()}}(e,t);t.append(h,f.el);let b=null;if(!1!==o.indicators){b=i(kt(e,"Indicators")),b.appendChild(Ge(n,ie("plus"),"chrome"));const a=Ke(n,"span");a.textContent=kt(e,"Indicators"),b.appendChild(a),b.addEventListener("click",()=>{null!==b&&b.classList.contains("is-off")||null!==b&&o.onIndicators(b)}),t.appendChild(b)}t.appendChild(Ke(n,"span","oac-topbar__spacer"));const v=Ke(n,"span","oac-topbar__branding-slot");let w=null;t.appendChild(v);let _=null;const x=o.layouts;if(void 0!==x&&o.onLayouts){const a=kt(e,"schema.ui.layouts.title",{},"Layouts"),r=()=>{const e=x.state();return null===e.layoutId?null:e.catalog?.workspaces.find(t=>t.id===e.layoutId)?.name??null},s=i(a,"oac-topbar__layouts");s.setAttribute("aria-haspopup","dialog"),s.appendChild(Ge(n,ie("layout"),"chrome"));const l=Ke(n,"span","oac-topbar__layouts-name");s.appendChild(l),e.tips.attach(s,()=>{const t=r(),o=x.state(),n=null===t?a:`${a}: ${t}`,i=Gi(e,o);return{title:n,label:Ji(o)?`${n}, ${i}`:void 0,sub:i,side:"bottom"}});const c=()=>{l.textContent=r()??a,s.dataset.attention=String(Ji(x.state())),e.tips.refreshLabel(s)};_=x.subscribe(c),c(),s.addEventListener("click",()=>{o.onLayouts?.(s)}),t.appendChild(s),t.classList.add("has-layouts")}const k=o.onGoTo?i(kt(e,"Go to"),"oac-topbar__goto"):null;if(null!==k&&(k.textContent=kt(e,"Go to"),k.setAttribute("aria-haspopup","dialog"),e.tips.attach(k,()=>({title:kt(e,"Go to"),sub:null===Fn(o.state().interval)?kt(e,"Go to needs a time-based interval"):void 0,side:"bottom"})),k.addEventListener("click",()=>{k.classList.contains("is-off")||o.onGoTo?.(k)}),t.appendChild(k)),o.onObjects){const n=i(kt(e,"Objects"),"oac-topbar__objects");n.textContent=kt(e,"Objects"),n.setAttribute("aria-haspopup","dialog"),n.addEventListener("click",()=>{o.onObjects?.(n)}),t.appendChild(n)}if(o.onDataWindow){const n=i(kt(e,"schema.ui.dataWindow",{},"Data"),"oac-topbar__data");n.textContent=kt(e,"schema.ui.dataWindow",{},"Data"),n.addEventListener("click",()=>{o.onDataWindow?.(n)}),t.appendChild(n)}for(const[n,a,r]of[["watchlist","Watchlist",o.onWatchlist],["news","News",o.onNews]]){if(!r)continue;const o=i(kt(e,`schema.ui.dock.${n}`,{},a),`oac-topbar__${n}`);o.textContent=kt(e,`schema.ui.dock.${n}`,{},a),o.addEventListener("click",()=>{r(o)}),t.appendChild(o)}if(o.onAlerts){const n=i(kt(e,"Alerts"),"oac-topbar__alerts");n.textContent=kt(e,"Alerts"),n.setAttribute("aria-haspopup","dialog"),n.addEventListener("click",()=>{o.onAlerts?.(n)}),t.appendChild(n)}const C=i(kt(e,"Capture chart"),"oac-btn--icon");C.appendChild(Ge(n,ie("camera"),"chrome")),C.setAttribute("aria-haspopup","menu"),e.tips.attach(C,{title:kt(e,"Capture"),sub:kt(e,"PNG, SVG, CSV or the clipboard"),side:"bottom"});let S=null;const A={waiting:null},L=i=>{const a={...o.state()},r=e.chart,s=r.primarySeries(),l=r.getDataContext(),c=()=>!r.isDestroyed&&!1!==o.dataAvailable?.()&&r.primaryBars().length>0,d=()=>{const t=o.state(),n=e.chart.getDataContext();if(e.chart!==r||r.primarySeries()!==s||t.symbol!==a.symbol||t.exchange!==a.exchange||t.interval!==a.interval||t.chartType!==a.chartType||n!==l)throw new Error(kt(e,"The chart changed; reopen Capture for its current source"));if(!c())throw new Error(kt(e,"Wait for this chart to finish loading its data"))},u=ea();rn(e,i,[{label:kt(e,"Download PNG"),onSelect:()=>{const t=Xi(n,()=>e.chart.takeScreenshot(),ln(a.symbol,a.interval)+".png");e.status(kt(e,t?"Saved a PNG of the chart":"This runtime cannot save files"),t?"info":"error")}},{label:kt(e,"Download SVG"),sub:kt(e,"text stays text"),onSelect:()=>{const t=sn(n,ln(a.symbol,a.interval)+".svg",e.chart.exportSVG(),"image/svg+xml");e.status(kt(e,t?"Saved an SVG of the chart":"This runtime cannot save files"),t?"info":"error")}},{label:kt(e,"Copy image"),sub:kt(e,u?"paste it anywhere":"needs https or localhost"),disabled:!u,onSelect:()=>{ta(e,e.chart.takeScreenshot(),kt(e,"Chart copied"),(t,o)=>e.status(t,o))}},{label:kt(e,"Download chart data (CSV)"),disabled:!c(),onSelect:()=>{Pt(oa,t=>{try{d(),S?.close(),S=t.openChartDataExportDialog(e,i,t=>{d();const o=j(r,t);if(d(),!sn(n,ln(a.symbol,a.interval)+".csv",o,"text/csv;charset=utf-8"))throw new Error(kt(e,"This runtime cannot save files"));e.status(kt(e,"Chart data download started"))})}catch(t){(t=>{e.status(kt(e,"Data export failed: {error}",{error:Ct(e,t)}),"error")})(t)}},t=>e.status(jt(e,kt(e,"Download chart data (CSV)"),t),"error"),()=>t.isConnected,{slot:A,doc:n,from:i})}},...o.captureRows?.()??[]],{ariaLabel:kt(e,"Capture")})};C.addEventListener("click",()=>L(C)),t.appendChild(C);const O=i(kt(e,"Chart settings"),"oac-btn--icon");O.appendChild(Ge(n,ie("settings"),"chrome")),e.tips.attach(O,()=>({title:kt(e,"Chart settings"),sub:o.settingsAvailable()?void 0:kt(e,"The settings dialog is not in this build"),side:"bottom"})),O.addEventListener("click",()=>{O.classList.contains("is-off")||o.onSettings(O)}),t.appendChild(O);const $=i(kt(e,"Theme"),"oac-btn--icon oac-topbar__theme"),E=Ge(n,"","chrome");$.appendChild(E),e.tips.attach($,()=>({title:"dark"===o.state().theme?kt(e,"Switch to the light theme"):kt(e,"Switch to the dark theme"),side:"bottom"})),$.addEventListener("click",()=>o.onTheme("dark"===o.state().theme?"light":"dark")),t.appendChild($),null!==b&&e.tips.attach(b,()=>({title:kt(e,"Indicators"),sub:o.indicatorsAvailable()?kt(e,"Add a study to the chart"):kt(e,"The indicator picker is not in this build"),side:"bottom"}));const T=()=>{const t=o.state();p.refresh(),n.activeElement!==l&&(l.value=t.symbol),c.textContent=t.exchange,c.hidden=""===t.exchange,m.dataset.type!==t.chartType&&(m.dataset.type=t.chartType,m.hidden=void 0===ve(t.chartType),m.innerHTML=m.hidden?"":ie(`chart-${t.chartType}`)),g.textContent=kt(e,`schema.chartType.${t.chartType}`,{},aa(t.chartType)),f.refresh(),r(O,!o.settingsAvailable()),null!==b&&r(b,!o.indicatorsAvailable()),null!==k&&r(k,null===Fn(t.interval)),$.dataset.theme!==t.theme&&($.dataset.theme=t.theme,E.innerHTML=ie("dark"===t.theme?"sun":"moon")),e.tips.refreshLabel($),e.tips.refreshLabel(O),null!==b&&e.tips.refreshLabel(b);const i=la(e.chart,e);null===i?(w?.remove(),w=null):(null===w&&(w=Ke(n,"a","oac-topbar__branding",{target:"_blank",rel:"noopener noreferrer"}),v.appendChild(w)),w.setAttribute("href",i.href),w.textContent=i.label,w.setAttribute("aria-label",i.label))},P=e.chart.on("branding:changed",T);return T(),{el:t,openCapture:L,refresh:T,focusSymbol:()=>{l.focus()},destroy:()=>{p.destroy(),S?.close(),f.close(),_?.(),P(),d?.destroy(),t.textContent=""}}}const ua={info:4e3,success:3500,error:0},pa=5,ha=160;function ma(e,t=e.ownerDocument,o={}){e.classList.add("oac-toasts"),e.setAttribute("role","status"),e.setAttribute("aria-live","polite");const n=new Set;return{toast:(i,a="info",r={})=>{const s=a in ua?a:"info",l=t.createElement("div");l.className="oac-toast oac-toast--"+s;const c=t.createElement("span");c.className="oac-toast__msg",c.textContent=i;const d=t.createElement("button");d.type="button",d.className="oac-toast__x",d.setAttribute("aria-label",kt(o,"Dismiss")),d.innerHTML=ie("close"),l.appendChild(c),l.appendChild(d);const u=void 0!==r.ms?r.ms:ua[s];let p=0,h=!1;const m={node:l,dismiss:()=>{h||(h=!0,0!==p&&clearTimeout(p),n.delete(m),l.classList.add("is-out"),setTimeout(()=>l.remove(),160))}},g=()=>{u>0&&(p=setTimeout(m.dismiss,u))};for(d.addEventListener("click",m.dismiss),l.addEventListener("pointerenter",()=>{0!==p&&clearTimeout(p),p=0}),l.addEventListener("pointerleave",g),e.appendChild(l),n.add(m);n.size>5;){const e=n.values().next().value;n.delete(e),e.node.remove()}return g(),m},clear:()=>{for(const e of Array.from(n))e.dismiss()},count:()=>n.size,destroy:()=>{for(const e of Array.from(n))e.node.remove();n.clear(),e.remove()}}}const ga=e=>{const t=e/255;return t<=.03928?t/12.92:Math.pow((t+.055)/1.055,2.4)};const fa="--oac-",ba=e=>e<0?0:e>1?1:e;function va(e){const t=e.trim(),o=/^#([0-9a-f]{3,8})$/i.exec(t);if(null!==o){const e=o[1];if(3===e.length||4===e.length){return va("#"+e.split("").map(e=>e+e).join(""))}if(6!==e.length&&8!==e.length)return null;return{r:parseInt(e.slice(0,2),16),g:parseInt(e.slice(2,4),16),b:parseInt(e.slice(4,6),16),a:8===e.length?parseInt(e.slice(6,8),16)/255:1}}const n=/^rgba?\(\s*([\d.]+)(?:\s*,\s*|\s+)([\d.]+)(?:\s*,\s*|\s+)([\d.]+)(?:\s*[,/]\s*([\d.]+%?))?\s*\)$/i.exec(t);if(null!==n){let e=1;return void 0!==n[4]&&(e=n[4].endsWith("%")?Number(n[4].slice(0,-1))/100:Number(n[4])),{r:Number(n[1]),g:Number(n[2]),b:Number(n[3]),a:ba(e)}}return null}const wa=e=>Math.round(Math.max(0,Math.min(255,e))).toString(16).padStart(2,"0");function _a(e){return e.a>=1?`#${wa(e.r)}${wa(e.g)}${wa(e.b)}`:`rgba(${Math.round(e.r)},${Math.round(e.g)},${Math.round(e.b)},${Math.round(1e3*e.a)/1e3})`}function ya(e){const t=va(e);return null===t?.5:function(e){return.2126*ga(e.r)+.7152*ga(e.g)+.0722*ga(e.b)}(t)}function xa(e,t){const o=ya(e),n=ya(t);return(Math.max(o,n)+.05)/(Math.min(o,n)+.05)}const ka=4.5;function Ca(e,t,o,n=4.5){const i=e=>t.every(t=>xa(e,t)>=n);if(i(e))return e;if(!i(o))return o;let a=0,r=1;for(let t=0;t<20;t++){const t=(a+r)/2;i(Aa(e,o,t))?r=t:a=t}for(let t=r;t<=1;t+=1/256){const n=Aa(e,o,t);if(i(n))return n}return o}function Sa(e){return ya(e.background)<.35?"dark":"light"}function Aa(e,t,o){const n=va(e),i=va(t);if(null===n||null===i)return e;const a=ba(o);return _a({r:n.r+(i.r-n.r)*a,g:n.g+(i.g-n.g)*a,b:n.b+(i.b-n.b)*a,a:n.a+(i.a-n.a)*a})}function La(e,t){const o=va(e);return null===o?e:_a({...o,a:ba(t)})}const Oa='ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif',$a="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",Ea=42,Ta=40,Pa=24;function ja(e,t=Sa(e)){const o="dark"===t,n=e.background,i=o?"#ffffff":"#0c1120",a=e=>Aa(n,i,e),r=e.lineColor,s=Aa(e.axisText,i,o?.55:.6),l=a(o?.035:.02),c=a(o?.02:.045),d=a(o?.07:.06),u=a(o?.11:.1),p=[n,l,c,d],h=(e,t=p)=>Ca(e,t,i),m={bg:n,panel:l,"panel-2":c,elev:d,"elev-2":u,"elev-3":a(o?.18:.16),bd:e.axisLine,"bd-soft":e.paneSeparator,"bd-hover":Aa(e.axisLine,i,.25),tx:s,"tx-strong":Aa(s,i,.5),mut:h(e.axisText,[...p,u]),faint:h(Aa(e.axisText,n,.4)),acc:r,"acc-2":Aa(r,i,o?.2:.1),"on-bg":La(r,.16),"on-bd":Aa(r,n,.45),ring:r,"ring-soft":La(r,.2),buy:e.upColor,sell:e.downColor,up:h(e.upColor),down:h(e.downColor),amber:h(o?"#e6b53c":"#b8860b"),danger:h(Aa(e.downColor,i,o?.3:.1),[...p,u]),scrim:o?"rgba(6,8,12,0.55)":"rgba(24,30,40,0.38)",shadow:o?"0 14px 40px rgba(0,0,0,0.55)":"0 14px 40px rgba(24,32,48,0.16)","sb-thumb":a(o?.16:.2),"sb-thumb-hover":a(o?.24:.3),font:Oa,mono:$a,fs:"12.5px",radius:"7px","rail-w":"42px","topbar-h":"40px","status-h":"24px","ctl-h":"28px"},g={};for(const[e,t]of Object.entries(m))g[fa+e]=t;return g}function Ma(e,t){for(const[o,n]of Object.entries(t))e.style.setProperty(o,n)}const Ia=e=>`var(${fa}${e})`,Da="oac-widget-css",za=`\n.oac-widget { position: relative; display: grid; grid-template-rows: auto 1fr auto; width: 100%; height: 100%;\n min-height: 0; min-width: 0; background: ${Ia("bg")}; color: ${Ia("tx")}; font: ${Ia("fs")}/1.35 ${Ia("font")};\n -webkit-font-smoothing: antialiased; overflow: hidden; }\n.oac-widget, .oac-widget * { box-sizing: border-box; }\n.oac-widget.oac-alert-host { position: absolute; inset: 0; display: block; background: transparent; pointer-events: none; z-index: 40; }\n.oac-widget[data-theme="dark"] { color-scheme: dark; }\n.oac-widget[data-theme="light"] { color-scheme: light; }\n.oac-widget button, .oac-widget input, .oac-widget select, .oac-widget textarea { font: inherit; color: inherit; }\n.oac-widget button { cursor: pointer; }\n.oac-widget kbd { font: 11px/1 ${Ia("mono")}; font-variant-numeric: tabular-nums; }\n.oac-widget [hidden] { display: none !important; }\n.oac-widget .oac-row:has(> .oac-input-error:not([hidden])) { flex-wrap: wrap; }\n.oac-widget .oac-input-error { flex-basis: 100%; min-width: 0; color: ${Ia("danger")}; font-size: 11px; overflow-wrap: anywhere; }\n.oac-widget .oac-row__ctl:has([data-input-action]) { flex-wrap: wrap; }\n.oac-widget .oac-row__ctl [data-input-action] { font-size: 11px; padding: 3px 7px; }\n.oac-widget [aria-invalid="true"] { border-color: ${Ia("danger")}; }\n.oac-widget .oac-input-pick { position: absolute; top: 8px; left: 50%; transform: translateX(-50%);\n display: flex; align-items: center; gap: 8px; max-width: calc(100% - 16px); padding: 8px;\n color: ${Ia("tx")}; background: ${Ia("panel")}; border: 1px solid ${Ia("bd")}; border-radius: 6px; pointer-events: auto; }\n\n/* Scrollbars: a thumb one step lighter than its panel, and no visible track. */\n.oac-widget * { scrollbar-width: thin; scrollbar-color: ${Ia("sb-thumb")} transparent; }\n.oac-widget ::-webkit-scrollbar { width: 10px; height: 10px; }\n.oac-widget ::-webkit-scrollbar-track { background: transparent; }\n.oac-widget ::-webkit-scrollbar-thumb { background: ${Ia("sb-thumb")}; border: 2px solid transparent;\n background-clip: padding-box; border-radius: 999px; }\n.oac-widget ::-webkit-scrollbar-thumb:hover { background: ${Ia("sb-thumb-hover")}; background-clip: padding-box; }\n.oac-widget ::-webkit-scrollbar-corner { background: transparent; }\n\n/* Focus: one ring, keyboard only. Text fields glow on the border instead. */\n.oac-widget :focus-visible { outline: 2px solid ${Ia("ring")}; outline-offset: 2px; }\n.oac-widget :focus:not(:focus-visible) { outline: none; }\n.oac-widget input:not([type=checkbox]):not([type=color]):not([type=range]):focus-visible,\n.oac-widget select:focus-visible, .oac-widget textarea:focus-visible {\n outline: none; border-color: ${Ia("acc")}; box-shadow: 0 0 0 3px ${Ia("ring-soft")}; }\n.oac-widget .oac-sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;\n overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }\n\n/* Form controls: nothing left to the browser on a themed panel. */\n.oac-widget input[type=checkbox] { appearance: none; -webkit-appearance: none; flex: none; margin: 0;\n width: 15px; height: 15px; border: 1px solid ${Ia("bd")}; border-radius: 4px; background: ${Ia("elev")};\n cursor: pointer; display: inline-grid; place-content: center; transition: background .12s, border-color .12s; }\n.oac-widget input[type=checkbox]:hover { border-color: ${Ia("bd-hover")}; }\n.oac-widget input[type=checkbox]:checked { background: ${Ia("acc")}; border-color: ${Ia("acc")}; }\n.oac-widget input[type=checkbox]:checked::after { content: ''; width: 4px; height: 8px; margin-top: -2px;\n border: solid ${Ia("bg")}; border-width: 0 2px 2px 0; transform: rotate(45deg); }\n.oac-widget input[type=checkbox]:disabled { opacity: .4; cursor: not-allowed; }\n/* A radio is the checkbox's round sibling; the dot is an inset ring, which needs no pseudo-element. */\n.oac-widget input[type=radio] { appearance: none; -webkit-appearance: none; flex: none; margin: 0; width: 15px; height: 15px;\n border: 1px solid ${Ia("bd")}; border-radius: 50%; background: ${Ia("elev")}; cursor: pointer; transition: background .12s, border-color .12s; }\n.oac-widget input[type=radio]:hover { border-color: ${Ia("bd-hover")}; }\n.oac-widget input[type=radio]:checked { border-color: ${Ia("acc")}; background: ${Ia("acc")}; box-shadow: inset 0 0 0 3px ${Ia("elev")}; }\n.oac-widget select { appearance: none; -webkit-appearance: none; height: ${Ia("ctl-h")}; padding: 0 24px 0 8px;\n background: ${Ia("elev")}; border: 1px solid ${Ia("bd")}; border-radius: ${Ia("radius")}; cursor: pointer; }\n.oac-widget .oac-select { position: relative; display: inline-flex; }\n/* The chevron overlays the select rather than sitting beside it. selectBox\n wraps the glyph in an oac-chev span, and this rule used to name\n .oac-select > svg, which that markup has never had: the span stayed an\n ordinary flex item, so it took eleven pixels of the row and left the select\n eleven pixels short of every input beside it, with its arrow outside its own\n box. Sized here rather than left to .oac-chev, whose inline-grid is right\n where a chevron follows a word, as it does in the top bar. */\n.oac-widget .oac-select > .oac-chev { position: absolute; right: 7px; top: 50%; width: 11px; height: 11px;\n transform: translateY(-50%); pointer-events: none; display: block; color: ${Ia("mut")}; }\n.oac-widget select option, .oac-widget select optgroup { background: ${Ia("panel")}; color: ${Ia("tx")}; }\n.oac-widget input[type=color] { width: 26px; height: 26px; padding: 0; flex: none; cursor: pointer; appearance: none;\n -webkit-appearance: none; background-color: ${Ia("elev")}; border: 1px solid ${Ia("bd")}; border-radius: ${Ia("radius")}; }\n.oac-widget input[type=color]:hover { border-color: ${Ia("bd-hover")}; }\n.oac-widget input[type=color]::-webkit-color-swatch-wrapper { padding: 3px; }\n.oac-widget input[type=color]::-webkit-color-swatch { border: 1px solid rgba(0,0,0,.35); border-radius: 4px; }\n.oac-widget input[type=color]::-moz-color-swatch { border: 1px solid rgba(0,0,0,.35); border-radius: 4px; }\n.oac-widget .oac-swatch { width: 20px; height: 20px; border-radius: 5px; border: 1px solid rgba(0,0,0,.35); }\n.oac-widget input[type=number] { -moz-appearance: textfield; appearance: textfield; }\n.oac-widget input[type=number]::-webkit-inner-spin-button, .oac-widget input[type=number]::-webkit-outer-spin-button {\n -webkit-appearance: none; margin: 0; }\n.oac-widget input[type=text], .oac-widget input[type=number], .oac-widget input[type=search], .oac-widget textarea {\n height: ${Ia("ctl-h")}; padding: 0 8px; background: ${Ia("elev")}; border: 1px solid ${Ia("bd")}; border-radius: ${Ia("radius")};\n transition: border-color .15s, box-shadow .15s; }\n.oac-widget textarea { height: auto; padding: 6px 8px; }\n.oac-widget input::placeholder { color: ${Ia("faint")}; }\n.oac-widget input:hover, .oac-widget select:hover { border-color: ${Ia("bd-hover")}; }\n.oac-widget input[type=range] { appearance: none; -webkit-appearance: none; height: 22px; margin: 0;\n background: transparent; cursor: pointer; }\n.oac-widget input[type=range]::-webkit-slider-runnable-track { height: 3px; border-radius: 2px; background: ${Ia("elev-3")}; }\n.oac-widget input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 12px;\n margin-top: -4.5px; border-radius: 50%; background: ${Ia("acc")}; border: 0; }\n.oac-widget input[type=range]::-moz-range-track { height: 3px; border-radius: 2px; background: ${Ia("elev-3")}; }\n.oac-widget input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: ${Ia("acc")}; border: 0; }\n\n/* Section heads and rows shared by every panel. */\n.oac-widget .oac-head { padding: 8px 10px 4px; color: ${Ia("faint")}; font-size: 10px; font-weight: 600;\n text-transform: uppercase; letter-spacing: .7px; }\n.oac-widget .oac-row { display: flex; align-items: center; gap: 8px; min-height: 26px; padding: 2px 0; }\n.oac-widget .oac-row > label { flex: 1 1 auto; min-width: 0; color: ${Ia("tx")}; }\n\n/* Help mark: a 13px ring after a label, muted until pointed at. It must not\n grow the row, so it sits on the label's own line box and never wraps away\n from the words it belongs to. */\n.oac-widget .oac-help { display: inline-flex; align-items: center; justify-content: center;\n width: 13px; height: 13px; margin-left: 5px; vertical-align: -2px; flex: none;\n border: 1px solid ${Ia("bd")}; border-radius: 50%; color: ${Ia("faint")};\n font-size: 9px; font-weight: 600; line-height: 1; cursor: help; user-select: none; }\n.oac-widget .oac-help:hover { color: ${Ia("tx")}; border-color: ${Ia("bd-hover")}; }\n/* A heading's rows as one named group, laid out as if the box were not there. */\n.oac-widget .oac-form__group { display: contents; }\n\n/* Buttons: flat, 28px tall, a tint when pressed or active. */\n.oac-widget .oac-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px;\n height: ${Ia("ctl-h")}; padding: 0 9px; background: transparent; border: 1px solid transparent;\n border-radius: ${Ia("radius")}; color: ${Ia("tx")}; white-space: nowrap; transition: background .1s, border-color .1s, color .1s; }\n.oac-widget .oac-btn:hover { background: ${Ia("elev")}; border-color: ${Ia("bd-soft")}; }\n.oac-widget .oac-btn.is-on, .oac-widget .oac-btn[aria-pressed="true"], .oac-widget .oac-btn[aria-expanded="true"] {\n background: ${Ia("on-bg")}; border-color: ${Ia("on-bd")}; color: ${Ia("acc-2")}; }\n.oac-widget .oac-btn.is-off, .oac-widget .oac-btn[aria-disabled="true"], .oac-widget .oac-btn:disabled {\n color: ${Ia("faint")}; cursor: default; }\n.oac-widget .oac-btn.is-off:hover, .oac-widget .oac-btn[aria-disabled="true"]:hover, .oac-widget .oac-btn:disabled:hover {\n background: transparent; border-color: transparent; }\n.oac-widget .oac-btn--icon { width: ${Ia("ctl-h")}; padding: 0; }\n.oac-widget .oac-btn--primary { background: ${Ia("acc")}; color: ${Ia("bg")}; border-color: transparent; font-weight: 600; }\n.oac-widget .oac-btn--primary:hover { background: ${Ia("acc-2")}; border-color: transparent; }\n.oac-widget .oac-btn--danger:not(.is-off):hover { color: ${Ia("danger")}; }\n.oac-widget .oac-btn > b { font-weight: 700; letter-spacing: .3px; }\n.oac-widget .oac-glyph { display: inline-grid; place-items: center; line-height: 0; flex: none; }\n.oac-widget .oac-glyph > svg { fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; }\n.oac-widget .oac-glyph--tool > svg { width: ${we}px; height: ${we}px; stroke-width: ${_e}; }\n.oac-widget .oac-glyph--chrome > svg { width: ${ye}px; height: ${ye}px; stroke-width: ${re}; }\n.oac-widget .oac-glyph--text { display: inline-grid; place-items: center; width: ${we}px; height: ${we}px;\n font-size: 12px; font-weight: 600; }\n.oac-widget .oac-chev { display: inline-grid; place-items: center; line-height: 0; color: ${Ia("mut")}; }\n.oac-widget .oac-chev > svg { width: 11px; height: 11px; fill: none; stroke: currentColor; stroke-width: 1.5;\n stroke-linecap: round; stroke-linejoin: round; }\n.oac-widget .oac-sep { width: 1px; height: 20px; background: ${Ia("bd-soft")}; margin: 0 2px; flex: none; }\n\n/* Top bar */\n.oac-widget .oac-topbar { grid-row: 1; display: flex; align-items: center; gap: 4px; min-height: ${Ia("topbar-h")};\n padding: 5px 8px; background: ${Ia("panel")}; border-bottom: 1px solid ${Ia("bd-soft")}; flex-wrap: wrap; }\n.oac-widget .oac-topbar__spacer { flex: 1 1 auto; }\n.oac-widget .oac-topbar__branding-slot { display: inline-flex; align-items: center; }\n.oac-widget .oac-topbar__branding { color: ${Ia("mut")}; font-size: 11px; text-decoration: none; white-space: nowrap; }\n.oac-widget .oac-topbar__branding:hover { color: ${Ia("tx")}; text-decoration: underline; }\n.oac-widget .oac-sym { position: relative; display: inline-flex; align-items: center; }\n.oac-widget .oac-sym > input { width: 132px; height: ${Ia("ctl-h")}; padding: 0 8px 0 28px; font-weight: 600;\n letter-spacing: .3px; text-transform: uppercase; }\n.oac-widget .oac-sym > .oac-glyph { position: absolute; left: 8px; color: ${Ia("mut")}; pointer-events: none; }\n.oac-widget .oac-sym__ex { margin-left: 6px; color: ${Ia("faint")}; font-size: 11px; font-weight: 600; letter-spacing: .5px; }\n.oac-widget .oac-pills { display: inline-flex; background: ${Ia("elev")}; border: 1px solid ${Ia("bd-soft")};\n border-radius: 7px; padding: 2px; }\n.oac-widget .oac-pills > button { height: 22px; padding: 0 8px; background: transparent; border: 0; border-radius: 5px;\n color: ${Ia("mut")}; font-weight: 600; font-size: 11.5px; letter-spacing: .2px; }\n.oac-widget .oac-pills > button:hover { color: ${Ia("tx")}; }\n.oac-widget .oac-pills > button[aria-pressed="true"] { background: ${Ia("elev-2")}; color: ${Ia("acc-2")}; }\n.oac-widget .oac-pills > button:focus-visible { outline-offset: -1px; }\n\n/* Popup menu (chart types, screenshot, symbol results) */\n.oac-widget .oac-menu { min-width: 190px; max-width: 320px; max-height: 60vh; overflow-y: auto; padding: 5px;\n background: ${Ia("panel")}; border: 1px solid ${Ia("bd")}; border-radius: 9px; box-shadow: ${Ia("shadow")}; outline: none; }\n.oac-widget .oac-menu__find { padding: 3px 3px 6px; }\n.oac-widget .oac-menu__find > input { width: 100%; }\n.oac-widget .oac-menu__row { display: flex; align-items: center; gap: 9px; width: 100%; padding: 6px 8px;\n background: transparent; border: 0; border-radius: 6px; color: ${Ia("tx")}; text-align: left; white-space: nowrap; }\n.oac-widget .oac-menu__row:hover, .oac-widget .oac-menu__row:focus-visible, .oac-widget .oac-menu__row.is-active {\n background: ${Ia("elev-2")}; outline: none; }\n.oac-widget .oac-menu__row[aria-checked="true"] { color: ${Ia("acc-2")}; }\n.oac-widget .oac-menu__row[aria-checked="true"]::before { content: ''; width: 6px; height: 6px; border-radius: 50%;\n background: ${Ia("acc-2")}; margin: 0 2px 0 -2px; flex: none; }\n.oac-widget .oac-menu__row[aria-checked="false"]::before { content: ''; width: 6px; height: 6px; margin: 0 2px 0 -2px; flex: none; }\n.oac-widget .oac-menu__row[aria-disabled="true"] { color: ${Ia("faint")}; cursor: default; background: transparent; }\n.oac-widget .oac-menu__row.is-danger:hover { color: ${Ia("danger")}; }\n.oac-widget .oac-menu__label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }\n.oac-widget .oac-menu__sub { color: ${Ia("faint")}; font-size: 11px; }\n.oac-widget .oac-menu__key { margin-left: auto; color: ${Ia("faint")}; }\n.oac-widget .oac-menu__empty { padding: 8px 10px; color: ${Ia("faint")}; }\n/* A hovered row is elev-2, where faint text no longer reads: its hints brighten with it. */\n.oac-widget .oac-menu__row:is(:hover, :focus-visible, .is-active) :is(.oac-menu__sub, .oac-menu__key),\n.oac-widget .oac-fly__row:is(:hover, :focus-visible) .oac-fly__chord { color: ${Ia("mut")}; }\n\n/* Stage: the rail on the left, the chart filling the rest. */\n.oac-widget .oac-stage { grid-row: 2; position: relative; min-height: 0; min-width: 0; display: flex; }\n.oac-widget .oac-chart { position: relative; flex: 1 1 auto; min-width: 0; min-height: 0;\n cursor: var(--oac-tool-cursor, crosshair); }\n.oac-widget .oac-chart:focus-visible { outline-offset: -2px; }\n\n/* Data state stays compact inside a chart, including narrow embedded widgets. */\n.oac-widget .oac-data-status { position: absolute; top: 8px; right: 8px; z-index: 30;\n max-width: calc(100% - 16px); width: max-content; max-height: 45%; overflow-y: auto;\n display: flex; flex-direction: column; gap: 4px; pointer-events: none; font-size: 12px; }\n.oac-widget .oac-data-status__row { display: flex; align-items: center; gap: 8px;\n max-width: 320px; padding: 4px 6px 4px 10px; background: ${Ia("panel")}; color: ${Ia("tx")};\n border: 1px solid ${Ia("bd")}; border-radius: 6px; pointer-events: auto; }\n.oac-widget .oac-data-status__text { min-width: 0; overflow-wrap: anywhere; }\n.oac-widget .oac-data-status__row > button { flex: none; color: ${Ia("acc-2")}; }\n\n/* Rail */\n.oac-widget .oac-rail { flex: none; width: ${Ia("rail-w")}; display: flex; flex-direction: column; align-items: center;\n gap: 2px; padding: 6px 0 0; background: ${Ia("panel-2")}; border-right: 1px solid ${Ia("bd-soft")};\n overflow-y: auto; overflow-x: hidden; scrollbar-width: none; }\n.oac-widget .oac-rail::-webkit-scrollbar { width: 0; height: 0; }\n.oac-widget .oac-rail__btn { position: relative; width: 32px; height: 30px; padding: 0; display: grid; place-items: center;\n flex: none; background: transparent; border: 1px solid transparent; border-radius: 6px; color: ${Ia("mut")};\n transition: background .09s, color .09s, border-color .09s; }\n.oac-widget .oac-rail__btn:hover { background: ${Ia("elev")}; color: ${Ia("tx")}; }\n.oac-widget .oac-rail__btn:focus-visible { outline: 2px solid ${Ia("acc-2")}; outline-offset: -2px; }\n.oac-widget .oac-rail__btn.is-on { background: ${Ia("on-bg")}; border-color: ${Ia("on-bd")}; color: ${Ia("acc-2")}; }\n.oac-widget .oac-rail__btn.is-weak { color: ${Ia("acc-2")}; }\n.oac-widget .oac-rail__btn.is-off { color: ${Ia("faint")}; cursor: default; }\n.oac-widget .oac-rail__btn.is-off:hover { background: transparent; color: ${Ia("faint")}; }\n.oac-widget .oac-rail__btn--danger:not(.is-off):hover { color: ${Ia("danger")}; }\n.oac-widget .oac-rail__chev { position: absolute; right: 0; bottom: 0; width: 13px; height: 13px; display: grid;\n place-items: center; border-radius: 5px 0 6px 0; color: ${Ia("mut")}; opacity: 0; transition: opacity .1s, background .1s; }\n.oac-widget .oac-rail__chev > svg { width: 9px; height: 9px; fill: none; stroke: currentColor; stroke-width: 2.2;\n stroke-linecap: round; stroke-linejoin: round; }\n.oac-widget .oac-rail__btn:hover .oac-rail__chev, .oac-widget .oac-rail__btn:focus-visible .oac-rail__chev,\n.oac-widget .oac-rail__btn[aria-expanded="true"] .oac-rail__chev { opacity: 1; }\n.oac-widget .oac-rail__chev:hover { background: ${Ia("elev-2")}; color: ${Ia("tx")}; }\n.oac-widget .oac-rail__btn.is-held::after, .oac-widget .oac-rail__btn[data-mode="weak"]::after,\n.oac-widget .oac-rail__btn[data-mode="strong"]::after { content: ''; position: absolute; top: 3px; right: 3px;\n width: 5px; height: 5px; border-radius: 50%; }\n.oac-widget .oac-rail__btn.is-held::after, .oac-widget .oac-rail__btn[data-mode="strong"]::after { background: ${Ia("acc-2")}; }\n.oac-widget .oac-rail__btn[data-mode="weak"]::after { border: 1.5px solid ${Ia("acc-2")}; width: 4px; height: 4px; }\n.oac-widget .oac-rail__sep { width: 22px; height: 1px; background: ${Ia("bd-soft")}; margin: 4px 0; flex: none; }\n.oac-widget .oac-rail__favs { display: contents; }\n.oac-widget .oac-rail__ctl { margin-top: auto; position: sticky; bottom: 0; display: flex; flex-direction: column;\n align-items: center; gap: 2px; width: 100%; padding: 4px 0 6px; background: ${Ia("panel-2")};\n border-top: 1px solid ${Ia("bd-soft")}; flex: none; }\n/* Tools that scroll under the controls fade out instead of being cut through. */\n.oac-widget .oac-rail__ctl::before { content: ''; position: absolute; left: 0; right: 0; bottom: 100%; height: 14px;\n background: linear-gradient(to bottom, transparent, ${Ia("panel-2")}); pointer-events: none; }\n.oac-widget .oac-rail__ctl .oac-rail__sep { margin: 3px 0; }\n.oac-widget .oac-rail.is-collapsed { display: none; }\n.oac-widget .oac-rail-tab { position: absolute; left: 0; bottom: 6px; z-index: 6; width: 16px; height: 26px; padding: 0;\n display: grid; place-items: center; background: ${Ia("panel-2")}; color: ${Ia("mut")};\n border: 1px solid ${Ia("bd-soft")}; border-left: 0; border-radius: 0 6px 6px 0;\n transition: background .09s, color .09s, width .09s; }\n.oac-widget .oac-rail-tab:hover { width: 20px; background: ${Ia("elev")}; color: ${Ia("tx")}; }\n.oac-widget .oac-rail-tab:focus-visible { outline: 2px solid ${Ia("acc-2")}; outline-offset: -2px; }\n.oac-widget .oac-rail-tab > svg { width: 12px; height: 12px; }\n.oac-widget .oac-rail-tab[hidden] { display: none; }\n\n/* Rail flyout: a group's tools, with a pin star and the chord on each row. */\n.oac-widget .oac-fly { min-width: 244px; max-width: 320px; max-height: calc(100% - 16px); overflow-y: auto; padding: 6px;\n background: ${Ia("panel")}; border: 1px solid ${Ia("bd")}; border-radius: 10px; box-shadow: ${Ia("shadow")}; outline: none; }\n.oac-widget .oac-fly__row { display: flex; align-items: center; gap: 8px; padding: 4px 6px 4px 8px; border-radius: 7px;\n color: ${Ia("tx")}; font-size: 13px; cursor: pointer; outline: none; user-select: none; }\n.oac-widget .oac-fly__row:hover, .oac-widget .oac-fly__row:focus-visible { background: ${Ia("elev-2")}; }\n.oac-widget .oac-fly__row[aria-checked="true"] { background: ${Ia("on-bg")}; color: ${Ia("acc-2")}; }\n.oac-widget .oac-fly__name { flex: 1 1 auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }\n.oac-widget .oac-fly__chord { min-width: 40px; text-align: right; color: ${Ia("faint")}; }\n.oac-widget .oac-fly__star { width: 22px; height: 22px; display: grid; place-items: center; padding: 0; border: 0;\n border-radius: 5px; background: transparent; color: ${Ia("faint")}; opacity: 0; transition: opacity .1s, color .1s; }\n.oac-widget .oac-fly__row:hover .oac-fly__star, .oac-widget .oac-fly__row:focus-within .oac-fly__star,\n.oac-widget .oac-fly__star[aria-pressed="true"] { opacity: 1; }\n.oac-widget .oac-fly__star:hover { background: ${Ia("elev")}; color: ${Ia("tx")}; }\n.oac-widget .oac-fly__star:focus-visible { outline: 2px solid ${Ia("acc-2")}; outline-offset: -1px; opacity: 1; }\n.oac-widget .oac-fly__star[aria-pressed="true"] { color: ${Ia("amber")}; }\n.oac-widget .oac-fly__star > svg { width: 14px; height: 14px; stroke: currentColor; stroke-width: 1.5;\n stroke-linecap: round; stroke-linejoin: round; }\n.oac-widget .oac-fly__star[aria-pressed="false"] > svg { fill: none; }\n\n/* Tooltip */\n.oac-widget .oac-tip-spot { position: absolute; width: 1px; height: 1px; pointer-events: none; }\n.oac-widget .oac-tip { position: absolute; z-index: 200; left: 0; top: 0; max-width: 260px; pointer-events: none;\n padding: 5px 9px; border-radius: 6px; background: ${Ia("elev-2")}; color: ${Ia("tx")}; border: 1px solid ${Ia("bd")};\n box-shadow: ${Ia("shadow")}; font-size: 12px; line-height: 1.4; opacity: 0; transition: opacity .09s ease; }\n.oac-widget .oac-tip.is-on { opacity: 1; }\n.oac-widget .oac-tip__chord { margin-left: 10px; color: ${Ia("mut")}; }\n/* The tip sits on elev-2, a step above the surfaces faint text is measured on. */\n.oac-widget .oac-tip__sub { display: block; margin-top: 2px; color: ${Ia("mut")}; font-size: 11px; }\n\n/* Status line */\n.oac-widget .oac-statusline { grid-row: 3; display: flex; align-items: center; gap: 12px; height: ${Ia("status-h")}; padding: 0 10px;\n background: ${Ia("panel")}; border-top: 1px solid ${Ia("bd-soft")}; color: ${Ia("mut")}; font-size: 11.5px;\n font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; }\n.oac-widget .oac-statusline__sym { color: ${Ia("tx-strong")}; font-weight: 600; letter-spacing: .3px; }\n.oac-widget .oac-statusline__iv { color: ${Ia("faint")}; margin-left: 4px; font-weight: 600; }\n.oac-widget .oac-statusline__field { display: inline-flex; align-items: center; gap: 4px; }\n.oac-widget .oac-statusline__field > i { font-style: normal; color: ${Ia("faint")}; }\n.oac-widget .oac-statusline__field > b { font-weight: 500; color: ${Ia("tx")}; }\n.oac-widget .oac-statusline .is-up > b { color: ${Ia("up")}; }\n.oac-widget .oac-statusline .is-down > b { color: ${Ia("down")}; }\n.oac-widget .oac-statusline__msg { margin-left: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; color: ${Ia("mut")}; }\n.oac-widget .oac-statusline__msg.is-error { color: ${Ia("danger")}; }\n.oac-widget .oac-statusline__tz { color: ${Ia("faint")}; }\n\n/* Narrow widget chrome */\n.oac-widget .oac-mobile { display: none; }\n.oac-widget.is-mobile { grid-template-rows: auto minmax(0, 1fr) auto; }\n.oac-widget.is-mobile > .oac-topbar, .oac-widget.is-mobile > .oac-statusline,\n.oac-widget.is-mobile > .oac-stage > :is(.oac-rail, .oac-rail-tab) { display: none; }\n.oac-widget.is-mobile > .oac-stage { grid-row: 2; }\n.oac-widget.is-mobile > .oac-mobile { display: contents; }\n.oac-widget .oac-mobile__header { grid-row: 1; z-index: 40; display: grid; grid-template-columns: minmax(0, 1fr) auto;\n gap: 8px; min-height: 52px; padding: calc(4px + env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) 4px\n max(8px, env(safe-area-inset-left)); background: ${Ia("panel")}; border-bottom: 1px solid ${Ia("bd-soft")}; }\n.oac-widget .oac-mobile__symbol { width: 100%; min-width: 0; height: 44px; text-transform: uppercase; font-weight: 600; }\n.oac-widget .oac-mobile__footer { grid-row: 3; z-index: 40; min-width: 0; padding-bottom: env(safe-area-inset-bottom);\n background: ${Ia("panel")}; border-top: 1px solid ${Ia("bd-soft")}; }\n.oac-widget .oac-mobile__bar, .oac-widget .oac-mobile__selection { display: grid; grid-auto-flow: column;\n grid-auto-columns: minmax(0, 1fr); min-width: 0; }\n.oac-widget .oac-mobile__selection { border-bottom: 1px solid ${Ia("bd-soft")}; }\n.oac-widget .oac-mobile__action { min-width: 0; min-height: 44px; padding: 6px 10px; border: 0; border-radius: 0;\n background: transparent; color: ${Ia("tx")}; overflow-wrap: anywhere; touch-action: manipulation; }\n.oac-widget .oac-mobile__action:hover, .oac-widget .oac-mobile__action:focus-visible { background: ${Ia("elev")}; }\n.oac-widget .oac-mobile__action[aria-pressed="true"] { color: ${Ia("acc-2")}; background: ${Ia("on-bg")}; }\n.oac-widget .oac-mobile__action[aria-disabled="true"] { color: ${Ia("faint")}; cursor: default; background: transparent; }\n.oac-widget .oac-mobile__branding { display: flex; align-items: center; width: 100%; min-height: 44px; text-decoration: none; }\n.oac-widget .oac-mobile-sheet.oac-dialog { left: 0; right: 0; top: auto; bottom: 0; transform: none; width: 100%;\n max-width: 100%; max-height: calc(100% - env(safe-area-inset-top) - 12px); border-radius: 14px 14px 0 0;\n padding-bottom: env(safe-area-inset-bottom); }\n.oac-widget .oac-mobile-sheet__head { flex: none; display: flex; align-items: center; gap: 8px;\n min-height: 52px; padding: 4px 8px 4px 14px; border-bottom: 1px solid ${Ia("bd-soft")}; }\n.oac-widget .oac-mobile-sheet__title { flex: 1 1 auto; color: ${Ia("tx-strong")}; font-size: 14px; }\n.oac-widget .oac-mobile-sheet__body { flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain;\n display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-content: start; padding: 8px; }\n.oac-widget .oac-mobile-sheet__body > .oac-head { grid-column: 1 / -1; }\n.oac-widget .oac-mobile-sheet__controls { grid-column: 1 / -1; display: grid;\n grid-template-columns: repeat(3, minmax(0, 1fr)); border-bottom: 1px solid ${Ia("bd-soft")}; margin-bottom: 6px; }\n.oac-widget .oac-mobile-sheet__body small { display: block; color: ${Ia("faint")}; }\n/* A sheet row with a glyph (a chart type): the glyph sits on the middle of its label, not the baseline. */\n.oac-widget .oac-mobile-sheet .oac-mobile__action > .oac-glyph { vertical-align: middle; margin: -2px 8px 0 0; }\n.oac-widget .oac-mobile-results { width: min(360px, calc(100% - 16px)); max-height: min(50%, 360px); overflow: hidden;\n display: flex; flex-direction: column; background: ${Ia("panel")}; border: 1px solid ${Ia("bd")}; border-radius: 10px; box-shadow: ${Ia("shadow")}; }\n.oac-widget .oac-mobile-results__head { flex: none; display: flex; align-items: center; gap: 8px; min-height: 44px;\n padding-left: 12px; border-bottom: 1px solid ${Ia("bd-soft")}; }\n.oac-widget .oac-mobile-results__head > strong { flex: 1 1 auto; color: ${Ia("tx-strong")}; }\n.oac-widget .oac-mobile-results__list { flex: 1 1 auto; min-height: 0; max-height: min(42vh, 300px);\n overflow-y: auto; overscroll-behavior: contain; }\n.oac-widget .oac-mobile-results__list > .oac-mobile__action { display: block; width: 100%; text-align: left; }\n.oac-widget .oac-mobile-results__list small { display: block; color: ${Ia("faint")}; }\n.oac-widget .oac-mobile-results__status { min-height: 44px; padding: 13px 12px; color: ${Ia("mut")}; }\n.oac-widget.is-mobile .oac-toasts { bottom: calc(54px + env(safe-area-inset-bottom)); }\n\n/* Toasts */\n.oac-widget .oac-toasts { position: absolute; right: 12px; bottom: calc(${Ia("status-h")} + 10px); z-index: 90; display: flex;\n flex-direction: column; gap: 8px; width: min(340px, calc(100% - 24px)); pointer-events: none; }\n.oac-widget .oac-toast { display: flex; align-items: flex-start; gap: 8px; padding: 8px 6px 8px 12px; border-radius: 8px;\n background: ${Ia("panel")}; color: ${Ia("tx")}; border: 1px solid ${Ia("bd")}; border-left: 3px solid ${Ia("acc")};\n box-shadow: ${Ia("shadow")}; font-size: 12.5px; line-height: 1.45; pointer-events: auto; animation: oac-toast-in .16s ease-out; }\n.oac-widget .oac-toast--success { border-left-color: ${Ia("buy")}; }\n.oac-widget .oac-toast--error { border-left-color: ${Ia("sell")}; }\n.oac-widget .oac-toast__msg { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; padding-top: 2px; }\n.oac-widget .oac-toast__x { flex: none; width: 26px; height: 26px; border: 0; border-radius: 6px; background: transparent;\n color: ${Ia("faint")}; padding: 0; display: grid; place-items: center; }\n.oac-widget .oac-toast__x:hover { background: ${Ia("elev-2")}; color: ${Ia("tx")}; }\n.oac-widget .oac-toast__x > svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 1.5; }\n.oac-widget .oac-toast.is-out { opacity: 0; transform: translateY(6px); transition: opacity .16s, transform .16s; }\n@keyframes oac-toast-in { from { opacity: 0; transform: translateY(6px); } }\n\n/* Overlay layer: popovers anchored to a control, dialogs centred over a scrim. */\n.oac-widget .oac-layer { container: oac-widget / inline-size; position: absolute; inset: 0; z-index: 60; pointer-events: none; }\n/* Not the tooltip: it shows over controls (the rail's tab, the bar's buttons) and\n must never take the press meant for them. */\n.oac-widget .oac-layer > :not(.oac-tip, .oac-tip-spot) { pointer-events: auto; }\n.oac-widget .oac-scrim { position: absolute; inset: 0; background: ${Ia("scrim")}; }\n.oac-widget .oac-pop { position: absolute; left: 0; top: 0; }\n.oac-widget .oac-dialog { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);\n min-width: 0; max-width: calc(100% - 24px); max-height: calc(100% - 24px); display: flex; flex-direction: column;\n background: ${Ia("panel")}; border: 1px solid ${Ia("bd")}; border-radius: 12px; box-shadow: ${Ia("shadow")}; outline: none; }\n.oac-widget .oac-dialog__head { flex: none; min-width: 0; display: flex; align-items: center; gap: 8px; padding: 12px 14px 8px; }\n.oac-widget .oac-dialog__title { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; font-size: 14px; font-weight: 700; color: ${Ia("tx-strong")}; }\n.oac-widget .oac-dialog__body { flex: 1 1 auto; min-height: 0; min-width: 0; overflow: auto; overscroll-behavior: contain; padding: 4px 14px 10px; }\n.oac-widget .oac-dialog__foot { flex: none; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 14px 12px;\n border-top: 1px solid ${Ia("bd-soft")}; }\n.oac-widget .oac-dialog__foot > .oac-spacer { flex: 1 1 auto; }\n.oac-widget .oac-csv { width: 490px; }\n.oac-widget .oac-csv__ranges, .oac-widget .oac-csv .oac-dialog__actions { display: flex; flex-wrap: wrap; gap: 8px; }\n.oac-widget .oac-csv__hint { color: ${Ia("mut")}; line-height: 1.5; }\n.oac-widget .oac-csv__error { color: ${Ia("danger")}; overflow-wrap: anywhere; }\n.oac-widget .oac-csv__error:empty { display: none; }\n\n/* Point and figure and Renko settings: a size, its unit and its method share one control column. */\n.oac-widget .oac-ctset { width: 380px; }\n.oac-widget .oac-ctset .oac-row__ctl { width: min(244px, 66%); }\n.oac-widget .oac-ctset__presets { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; width: 100%; padding: 2px 0; }\n.oac-widget .oac-ctset__preset { height: 24px; padding: 0 4px; font-size: 11px; font-variant-numeric: tabular-nums;\n background: ${Ia("elev")}; border-color: ${Ia("bd-soft")}; }\n.oac-widget .oac-ctset__size { display: flex; align-items: center; gap: 6px; width: 100%; min-width: 0; }\n.oac-widget .oac-ctset .oac-row__ctl .oac-ctset__size > input { flex: 1 1 0; width: auto; min-width: 0; }\n.oac-widget .oac-ctset .oac-input--num { text-align: right; font-variant-numeric: tabular-nums; }\n.oac-widget .oac-ctset .oac-row__ctl .oac-ctset__size > .oac-select { flex: 0 0 100px; width: 100px; }\n.oac-widget .oac-ctset__unit { flex: none; color: ${Ia("mut")}; font-size: 11px; white-space: nowrap; }\n.oac-widget .oac-ctset__radios { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px 14px; }\n.oac-widget .oac-ctset__radio { display: inline-flex; align-items: center; gap: 6px; color: ${Ia("tx")}; white-space: nowrap; cursor: pointer; }\n\n/* Shortcuts panel */\n.oac-widget .oac-keys { columns: 2; column-gap: 24px; min-width: 520px; }\n.oac-widget .oac-keys__group { break-inside: avoid; margin-bottom: 8px; }\n.oac-widget .oac-keys__row { display: flex; align-items: center; gap: 10px; padding: 3px 0; }\n.oac-widget .oac-keys__row > span { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }\n.oac-widget .oac-keys__row > kbd { flex: none; padding: 2px 6px; border-radius: 4px; background: ${Ia("elev")};\n border: 1px solid ${Ia("bd-soft")}; color: ${Ia("mut")}; }\n.oac-widget .oac-keys__row.is-shadowed > span, .oac-widget .oac-keys__row.is-shadowed > kbd { color: ${Ia("faint")}; text-decoration: line-through; }\n.oac-widget .oac-keys__note { color: ${Ia("faint")}; font-size: 11px; padding: 4px 0 0; }\n\n@container oac-widget (max-width: 720px) {\n .oac-widget .oac-keys { columns: 1; min-width: 0; }\n}\n@media (max-width: 720px) {\n .oac-widget .oac-sym > input { width: 104px; }\n}\n@media (prefers-reduced-motion: reduce) {\n .oac-widget .oac-rail__btn, .oac-widget .oac-rail__chev, .oac-widget .oac-tip, .oac-widget .oac-fly__star,\n .oac-widget .oac-btn, .oac-widget .oac-toast.is-out { transition: none; }\n .oac-widget .oac-toast { animation: none; }\n .oac-widget .oac-mobile__action { transition: none; }\n}\n`;function Na(e,t="",o){const n=e.getElementById(Da);if(n?.textContent?.trim())return n;const i=n??e.createElement("style");return i.id=Da,i.nonce||void 0===o||(i.nonce=o),i.textContent=za+t,null===n&&(e.head??e.body??e.documentElement).appendChild(i),i}function Ra(e,t){const o=e.getElementById(Da);null===o||(o.textContent??"").includes(t)||o.appendChild(e.createTextNode(t))}const Fa=/^(style|text|props)\./;function Wa(e){return"string"==typeof e||"boolean"==typeof e||"number"==typeof e&&Number.isFinite(e)||Array.isArray(e)}function Ba(e,t){const{draw:o,chart:n}=e;let i=null,a=!1;const r=new Set,s=e=>{a||null!==i&&e.revision<i.revision||(i=e,(()=>{for(const e of Array.from(r))e()})())},l=t.subscribe(s);t.load().then(s,()=>{a||e.status(kt(e,"Drawing templates could not be loaded"),"error")});const c=e=>i?.defaults.find(t=>t.tool===e)?.values;function d(e){const t={};for(const[o,n]of Object.entries(xe(e,ke(e.tool))))Fa.test(o)&&"text.value"!==o&&Wa(n)&&(t[o]=n);return t}function u(e,t){const n=[];for(const i of ct(o,e)){const e=o.get(i);if(void 0===e)continue;const a=Ce(e,t,ke(e.tool));Object.keys(a).length>0&&n.push({id:i,patch:a})}return n}let p=null;const h=[n.on("drawing:change",e=>{p=null;const t=e;if(a||"add"!==t.kind||void 0===t.step||!0===t.linked||1!==t.ids.length)return;const n=o.get(t.ids[0]);if(void 0===n||o.activeTool()!==n.tool||void 0===c(n.tool))return;const i=n.id;p=i,queueMicrotask(()=>{p===i&&(p=null)})}),n.on("draw:tool",()=>{const t=p;p=null;const n=null===t||a?void 0:o.get(t),i=void 0===n?void 0:c(n.tool);if(void 0===n||void 0===i)return;const r=u([n.id],i);if(0===r.length)return;const s=()=>{o.updateMany(r)};void 0===e.history||e.history.isDestroyed?o.untracked(s):e.history.ignore(s)})],m=async(t,o)=>{try{const n=await t();return a||e.toast(o,"success"),n}catch(t){throw a||e.toast(kt(e,"The drawing template could not be saved: {error}",{error:Ct(e,t)}),"error"),t}},g=t=>{const n=o.get(t);if(void 0===n)throw new Error(kt(e,"Select a drawing first"));return n},f=t=>kt(e,`schema.drawing.${t}.name`,{},dt(t)?.name??t);return{store:t,catalog:()=>i,templatesFor:e=>i?.templates.filter(t=>t.tool===e)??[],defaultFor:c,capture:d,apply:function(e,t){const n=u(e,t);return n.length>0&&o.updateMany(n),n.length},saveDefault:async o=>{const n=g(o);await m(()=>t.setDefault(n.tool,d(n)),kt(e,"New {tool} drawings start with this look",{tool:f(n.tool)}))},clearDefault:async o=>{await m(()=>t.setDefault(o,null),kt(e,"New {tool} drawings start with the standard look",{tool:f(o)}))},saveTemplate:async(o,n)=>{const i=g(o);return m(()=>t.saveTemplate(n,i.tool,d(i)),kt(e,"Saved the template {name}",{name:n.trim()}))},removeTemplate:async o=>{await m(()=>t.removeTemplate(o),kt(e,"Removed the template"))},subscribe:e=>(r.add(e),()=>{r.delete(e)}),destroy:()=>{if(!a){a=!0;for(const e of h)e();l(),r.clear()}}}}function qa(e,t,o,n){const i=o.map(t=>e.draw.get(t)).filter(e=>void 0!==e),a=1===new Set(i.map(e=>e.tool)).size?i[0].tool:null,r=i[0],s=ct(e.draw,o).length>0,l=[kt(e,"Templates")],c=e=>{e().catch(()=>{})};l.push({label:kt(e,"Save as default for this tool"),sub:null===a?kt(e,"one tool at a time"):void 0,disabled:null===a,onSelect:()=>{void 0!==r&&c(()=>t.saveDefault(r.id))}}),null!==a&&void 0!==t.defaultFor(a)&&l.push({label:kt(e,"Forget the default for this tool"),onSelect:()=>c(()=>t.clearDefault(a))}),l.push({label:kt(e,"Save as template..."),disabled:null===a,onSelect:()=>{void 0!==r&&Ha(e,n,e=>t.saveTemplate(r.id,e))}});const d=null===a?[]:t.templatesFor(a);for(const n of d)l.push({label:kt(e,"Apply {name}",{name:n.name}),disabled:!s,sub:s?void 0:kt(e,"read-only"),onSelect:()=>{pt(e,"template",()=>t.apply(o,n.values))}});return l}let Ua=0;function Ha(e,t,o){const n=e.document,i=Yo(n,{translate:e.translate,title:kt(e,"Save as template"),className:"oac-template-name",onClose:()=>d.close()}),a=qo(n,"label","oac-template-name__label",kt(e,"Template name")),r=qo(n,"input","oac-template-name__input");r.type="text",r.maxLength=120,r.id="oac-template-name-"+ ++Ua,a.htmlFor=r.id;const s=qo(n,"p","oac-input-error");s.setAttribute("role","alert"),s.hidden=!0,i.body.append(a,r,s);let l=!1;const c=async()=>{const t=r.value.trim();if(!l){if(""===t)return s.textContent=kt(e,"Enter a name"),s.hidden=!1,r.setAttribute("aria-invalid","true"),void r.focus();l=!0;try{await o(t),d.close()}catch(t){s.textContent=Ct(e,t),s.hidden=!1,r.setAttribute("aria-invalid","true")}finally{l=!1}}};r.addEventListener("keydown",e=>{"Enter"===e.key&&(e.preventDefault(),c())}),r.addEventListener("input",()=>{s.hidden=!0,r.removeAttribute("aria-invalid")}),i.actions.appendChild(Ko(n,{label:kt(e,"Cancel"),onClick:()=>d.close()}));i.actions.appendChild(Ko(n,{label:kt(e,"Save"),variant:"primary",onClick:()=>{c()}})).dataset.action="save-template";const d=Qo(e,i.el,void 0===t?{placement:"center",modal:!0,initialFocus:r}:{anchor:t,placement:"below",initialFocus:r},()=>{});return d}const Ka="\n.oac-widget .oac-template-name { width: 300px; }\n.oac-widget .oac-template-name .oac-dialog__body { display: flex; flex-direction: column; gap: 6px; padding-top: 8px; }\n.oac-widget .oac-template-name__label { color: var(--oac-mut); font-size: 11px; }\n.oac-widget .oac-template-name__input { width: 100%; }\n",Ga=/^(\d{4})-(\d{2})-(\d{2})$/,Va=/^(\d{2}):(\d{2})(?::(\d{2}))?$/,Ja=e=>String(e).padStart(2,"0");function Ya(e,t,o){const n=v(e,t),i=o??0!==n.second;return{date:`${n.year}-${Ja(n.month)}-${Ja(n.day)}`,time:`${Ja(n.hour)}:${Ja(n.minute)}${i?`:${Ja(n.second)}`:""}`,seconds:i}}function Za(e,t,o,n={}){const i=Ga.exec(e.trim()),a=t.trim(),r=Va.exec(a);if(null===i||null===r&&(""!==a||void 0===n.blank))return null;const[s,l,c]=[Number(i[1]),Number(i[2]),Number(i[3])],d=new Date(Date.UTC(s,l-1,c));if(d.getUTCMonth()!==l-1||d.getUTCDate()!==c)return null;if(null===r){const e="end"===n.blank?M(s,l,c+1,0,0,0,o)-1:M(s,l,c,0,0,0,o);return Number.isFinite(e)?e:null}const[u,p]=[Number(r[1]),Number(r[2])],h=void 0!==r[3]?Number(r[3]):!0===n.end?59:0;if(u>23||p>59||h>59)return null;const m=M(s,l,c,u,p,h,o);if(!Number.isFinite(m))return null;if(!0===n.rejectSkipped){const e=Ya(m,o,!0);if(e.date!==`${i[1]}-${i[2]}-${i[3]}`||e.time!==`${Ja(u)}:${Ja(p)}:${Ja(h)}`)return null}return m}let Qa=0;function Xa(e,t,o,n){const{chart:i,draw:a}=e,r=e.document,s=qo(r,"div","oac-coords");t.appendChild(s);const l=new Map;let c=i.timezone(),d=!1;function u(e,t,o){const n=Ya(o.time,c),a=function(e,t){const o=e.toFixed(Math.max(0,Math.min(10,t)));return Number(o)===e?o:String(Number(e.toFixed(10)))}(o.price,(e=>{const t=i.panes()[e.paneIndex]?.priceScale.precision();return Math.max(2,void 0!==t&&Number.isFinite(t)?Math.round(t):0)})(t));e.date.value=n.date,e.time.step=n.seconds?"1":"60",e.time.value=n.time,e.price.value=a,e.shown={date:n.date,time:n.time,price:a},e.error.hidden=!0,e.error.textContent="";for(const t of[e.date,e.time,e.price])t.removeAttribute("aria-invalid")}function p(e,t,o){e.error.textContent=o,e.error.hidden=!1,t.setAttribute("aria-invalid","true")}function h(t,o,r){const s=a.get(t),l=s?.points[o];if(d||void 0===s||void 0===l||null!==n())return;for(const e of[r.date,r.time,r.price])e.removeAttribute("aria-invalid");r.error.hidden=!0;let h=l.time;if(r.date.value!==r.shown.date||r.time.value!==r.shown.time){const t=Za(r.date.value,r.time.value,c);if(null===t){return void p(r,null!==Za(r.date.value,"00:00",c)?r.time:r.date,kt(e,"Enter a date and a time on the chart clock"))}h=t}let m=l.price;if(r.price.value!==r.shown.price){const t=function(e){const t=e.trim().replace(/[\s,]/g,"");if(!/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[-+]?\d+)?$/i.test(t))return null;const o=Number(t);return Number.isFinite(o)?o:null}(r.price.value);if(null===t)return void p(r,r.price,kt(e,"Enter a price as a number"));if(t<=0&&(e=>"logarithmic"===i.panes()[e.paneIndex]?.priceScale.options.mode)(s))return void p(r,r.price,kt(e,"A logarithmic scale needs a price above zero"));m=t}if(h===l.time&&m===l.price)return;const g=s.points.map((e,t)=>t===o?{...e,time:h,price:m}:{...e});a.update(t,{points:g});const f=a.get(t),b=f?.points[o];void 0!==f&&void 0!==b&&u(r,f,b)}function m(t,o){const n=qo(r,"div","oac-coords__row");n.dataset.anchor=`${t}:${o}`;const i="oac-coords-"+ ++Qa,a=qo(r,"label","oac-coords__label",kt(e,"Point {number}",{number:o+1}));a.htmlFor=`${i}-date`;const s=qo(r,"input","oac-coords__date");s.type="date",s.id=`${i}-date`;const l=qo(r,"input","oac-coords__time");l.type="time";const c=qo(r,"input","oac-coords__price");c.type="text",c.setAttribute("inputmode","decimal"),c.setAttribute("spellcheck","false"),c.autocomplete="off";const d=qo(r,"p","oac-input-error");d.setAttribute("role","alert"),d.hidden=!0;const u={el:n,date:s,time:l,price:c,error:d,shown:{date:"",time:"",price:""}},p=t=>kt(e,"{field} of point {number}",{field:t,number:o+1});s.setAttribute("aria-label",p(kt(e,"Date"))),l.setAttribute("aria-label",p(kt(e,"Time"))),c.setAttribute("aria-label",p(kt(e,"Price")));for(const e of[s,l,c])e.addEventListener("keydown",e=>{"Enter"===e.key&&(e.preventDefault(),h(t,o,u))});n.addEventListener("focusout",e=>{const i=e.relatedTarget;null!==i&&n.contains(i)||h(t,o,u)});const m=qo(r,"div","oac-coords__fields");return m.append(s,l,c),n.append(a,m,d),u}function g(e){s.appendChild(qo(r,"p","oac-coords__note",e))}let f="";function b(){if(d)return;const t=r.activeElement,p=null!==t&&s.contains(t),h=p?t.closest("[data-anchor]")?.dataset.anchor:void 0;c=i.timezone();const b=n(),v=o().map(e=>a.get(e)).filter(e=>void 0!==e),w=JSON.stringify([c,v.map(e=>[e.id,e.tool,e.space??"data",e.points.length])]),_=w!==f;f=w;const y=new Set;if(_){s.replaceChildren();const t=qo(r,"div","oac-coords__head");t.append(qo(r,"span","",kt(e,"Date")),qo(r,"span","",kt(e,"Time")),qo(r,"span","",kt(e,"Price"))),s.append(t,qo(r,"p","oac-coords__zone",kt(e,"Times are on the chart clock, {zone}.",{zone:c})))}for(const t of v){const o=dt(t.tool);if(_&&v.length>1&&s.appendChild(qo(r,"div","oac-head",kt(e,`schema.drawing.${t.tool}.name`,{},o?.name??t.tool))),"viewport"===t.space){_&&g(kt(e,"Pinned to the screen: its anchors are not a time and a price."));continue}if(!0===o?.freehand){_&&g(kt(e,"A freehand stroke has {count} points. Move it on the chart.",{count:t.points.length}));continue}const n=null!==b||0===ct(a,[t.id]).length;t.points.forEach((o,i)=>{const a=`${t.id}:${i}`;y.add(a);let r=l.get(a);void 0===r&&(r=m(t.id,i),l.set(a,r)),a!==h&&u(r,t,o);for(const t of[r.date,r.time,r.price])t.disabled=n,t.title=n?b??kt(e,"read-only"):"";_&&s.appendChild(r.el)})}for(const e of[...l.keys()])y.has(e)||l.delete(e);if(p&&!s.contains(t)&&void 0!==h){const e=l.get(h),o=void 0===e?void 0:[e.date,e.time,e.price].find(e=>e.className===t.className);o?.focus()}}const v=[i.on("timezone:changed",b)];return b(),{el:s,refresh:b,destroy:()=>{if(!d){d=!0;for(const e of v)e();l.clear(),s.remove()}}}}const er="\n.oac-widget .oac-coords { display: flex; flex-direction: column; gap: 4px; min-width: 0; }\n.oac-widget .oac-coords__head, .oac-widget .oac-coords__fields { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 1fr); align-items: center; gap: 6px; }\n.oac-widget .oac-coords__head { order: -1; color: var(--oac-faint); font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; padding: 2px 0 0; }\n.oac-widget .oac-coords__zone { margin: 0 0 4px; color: var(--oac-faint); font-size: 11px; }\n.oac-widget .oac-coords__row { display: flex; flex-direction: column; gap: 3px; }\n.oac-widget .oac-coords__label { color: var(--oac-mut); font-size: 11px; }\n.oac-widget .oac-coords input { min-width: 0; width: 100%; height: var(--oac-ctl-h); padding: 0 6px; border: 1px solid var(--oac-bd);\n border-radius: var(--oac-radius); background: var(--oac-elev); color: var(--oac-tx); color-scheme: inherit; font-variant-numeric: tabular-nums; }\n.oac-widget .oac-coords input:disabled { opacity: .6; cursor: not-allowed; }\n.oac-widget .oac-coords .oac-input-error { margin: 0; }\n.oac-widget .oac-coords__note { margin: 4px 0; color: var(--oac-mut); font-size: 12px; overflow-wrap: anywhere; }\n",tr=[0,.236,.382,.5,.618,.786,1,1.272,1.414,1.618,2,2.618,3.618,4.236],or=(e,t)=>e.some(e=>Math.abs(e.ratio-t)<=1e-6);function nr(e,t,o={}){const n=e.document,i=o.ids??e.draw.selection(),{drawings:a,schema:r}=function(e,t){const o=[];for(const n of t){const t=e.draw.get(n);void 0!==t&&!1!==t.policy?.editable&&ke(t.tool).fields.some(e=>"levels"===e.kind)&&o.push(t)}return{drawings:o,schema:0===o.length?null:ke(o[0].tool)}}(e,i);if(null===r)return Zo(e,kt(e,"Select a drawing with levels first"));const s=a[0],l=dt(s.tool),c=r.fields.find(e=>"levels"===e.kind),d=r.fields.find(e=>"style.showLabels"===e.path),u=c?.path??"style.levels",p=l?.defaultStyle?.levels??Se,h="gann-fan"===(m=s.tool)?Ae:"fib-time-zone"===m?e=>String(e):Le;var m;const g=()=>{const e=Oe(s,u);return Array.isArray(e)?$e(e):$e(p)},f=()=>{const e=Oe(s,"style.showLabels");return void 0===e?!0===l?.defaultStyle?.showLabels:!0===e};let b=g();function v(t){const o=[];for(const n of a){const i=e.draw.get(n.id);if(void 0===i)continue;const a=Ce(i,t,r);Object.keys(a).length>0&&o.push({id:n.id,patch:a})}o.length>0&&e.draw.updateMany(o)}const w=()=>v({[u]:$e(b)}),_=qo(n,"div","oac-panel oac-levels");_.setAttribute("role","dialog"),_.setAttribute("aria-label",kt(e,"Levels")),_.tabIndex=-1,Vo(_);const y=qo(n,"div","oac-levels__head");y.appendChild(qo(n,"b","oac-levels__title",kt(e,"Levels")));let x=null;if(void 0!==d){const t=qo(n,"label","oac-levels__labels");x=qo(n,"input"),x.type="checkbox",x.checked=f(),x.dataset.path=d.path;const o=x;o.addEventListener("change",()=>v({[d.path]:o.checked})),t.appendChild(o),t.appendChild(qo(n,"span",void 0,kt(e,"Show labels"))),y.appendChild(t)}y.appendChild(Ko(n,{label:kt(e,"Close"),icon:"close",iconOnly:!0,onClick:()=>E.close()})),_.appendChild(y);const k=qo(n,"div","oac-levels__rows");_.appendChild(k);let C=[];function S(){C.forEach(e=>e.destroy()),C=[],k.innerHTML="",0!==b.length?b.forEach((t,o)=>k.appendChild(function(t,o){const i=qo(n,"div","oac-levels__row"+(!1===t.enabled?" is-off":"")),a=qo(n,"input");a.type="checkbox",a.checked=!1!==t.enabled,a.addEventListener("change",()=>{a.checked?delete b[o].enabled:b[o].enabled=!1,i.classList.toggle("is-off",!a.checked),w()}),i.appendChild(a);const r=qo(n,"input");r.type="number",r.step="0.001",r.value=String(t.ratio),r.addEventListener("change",()=>{const e=Number(r.value);""!==r.value.trim()&&Number.isFinite(e)?(b[o].ratio=e,void 0===b[o].label&&(c.placeholder=h(e)),u(),w()):r.value=String(b[o].ratio)}),i.appendChild(r);const l=Po(n,{id:`oac-level-${s.id}-${o}`,label:kt(e,"Level {level} color",{level:h(t.ratio)}),value:t.color??s.style.color??Te(t.ratio)??Ee,translate:e.translate,openOverlay:e.openOverlay,onChange:e=>{b[o].color=e,w()}});C.push(l),i.appendChild(l.el);const c=qo(n,"input");c.type="text",c.value=t.label??"",c.placeholder=h(t.ratio),c.setAttribute("spellcheck","false"),c.addEventListener("change",()=>{const e=c.value.trim();""===e?delete b[o].label:b[o].label=e,w()}),i.appendChild(c);const d=qo(n,"button","oac-levels__x");function u(){const t=h(b[o].ratio);a.setAttribute("aria-label",kt(e,"Level {level} enabled",{level:t})),r.setAttribute("aria-label",kt(e,"Level {level} ratio",{level:t})),l.trigger.setAttribute("aria-label",kt(e,"Level {level} color",{level:t})),c.setAttribute("aria-label",kt(e,"Level {level} label",{level:t})),d.setAttribute("aria-label",kt(e,"Remove level {level}",{level:t}))}return d.type="button",d.appendChild(Ho(n,"close")),d.addEventListener("click",e=>{e.stopPropagation(),b.splice(o,1),S(),w()}),i.appendChild(d),u(),i}(t,o))):k.appendChild(qo(n,"div","oac-empty",kt(e,"No levels. Add one, or reset to the defaults.")))}S();const A=qo(n,"div","oac-levels__foot");A.appendChild(Ko(n,{label:kt(e,"Add level"),icon:"plus",onClick:()=>{const e=function(e){for(const t of tr)if(!or(e,t))return t;let t=0;for(const o of e)Number.isFinite(o.ratio)&&(t=Math.max(t,o.ratio));return t+1}(b),t={ratio:e},o=Te(e);o!==Ee&&(t.color=o),b.push(t),S(),w()}})),A.appendChild(qo(n,"span","oac-spacer")),A.appendChild(Ko(n,{label:kt(e,"Reset"),onClick:()=>{b=$e(p),S(),w()}})),_.appendChild(A);const L=e.chart.on("draw:update",()=>{if(!E.isOpen())return;if(void 0===e.draw.get(s.id))return void E.close();const t=g();JSON.stringify(t)===JSON.stringify(b)||_.contains(n.activeElement)||(b=t,S()),null!==x&&x!==n.activeElement&&(x.checked=f())}),O=e.chart.on("draw:remove",()=>{E.isOpen()&&void 0===e.draw.get(s.id)&&E.close()}),$=()=>{C.forEach(e=>e.destroy()),L(),O()},E=Qo(e,_,void 0===t?{placement:"below",dismissOnOutside:!0}:{anchor:t,placement:"below"},$);void 0===t&&tn(e.root,_,{point:Xo(e.root,e.chart,a)});const T=E.close;return{el:_,isOpen:E.isOpen,close:()=>{$(),T()}}}function ir(e,t){const o=!0===e.bold?"700 ":"";return`${!0===e.italic?"italic ":""}${o}${t}px ${void 0===e.fontFamily||""===e.fontFamily?"ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif":e.fontFamily}`}function ar(e,t,o,n){const i=o.split("\n");if(!0!==t.wrap)return i;const a=[];for(const t of i){const o=t.split(/\s+/).filter(e=>""!==e);if(0===o.length){a.push("");continue}let i=o[0];for(let t=1;t<o.length;t++){const r=`${i} ${o[t]}`;e(r)>n?(a.push(i),i=o[t]):i=r}a.push(i)}return a}function rr(e){let t="",o=!1;const n=e=>{for(const i of Array.from(e.childNodes??[])){if(3===i.nodeType){t+=i.nodeValue??"",o=!1;continue}if(1!==i.nodeType)continue;const e=String(i.nodeName).toUpperCase();"BR"!==e?("DIV"!==e&&"P"!==e||""===t||t.endsWith("\n")||(t+="\n"),o=!1,n(i)):(t+="\n",o=!0)}};return n(e),o?t.slice(0,-1):t}function sr(e){return e.panes()[0]?.element.parentElement??null}function lr(e){return void 0!==e&&!0===ke(e.tool).textIsContent}function cr(e,t,o){const n=Zo(e,t);return o?.(!1),{...n,commit:()=>{},cancel:()=>{}}}function dr(e,t,o={}){const n=e.document,{chart:i,draw:a}=e,r=a.selection(),s=o.id??(1===r.length?r[0]:void 0),l=void 0===s?void 0:a.get(s);if(!lr(l))return cr(e,kt(e,"Select a text drawing first"),o.onDone);if(!1===l.policy?.editable)return cr(e,kt(e,"read-only"),o.onDone);const c=dt(l.tool),d=void 0!==c?.defaultText?.value&&""!==c.defaultText.value?c.defaultText.value:kt(e,"Text"),u=l.text??{value:""},p=u.fontSize??14,h=ir(u,p),m=function(e,t,o){let n=null;try{const t=e.createElement("canvas");n="function"==typeof t.getContext?t.getContext("2d"):null}catch{n=null}if(null!==n&&"function"==typeof n.measureText){n.font=t;const e=n;return t=>e.measureText(t).width}return e=>e.length*o*.6}(n,h,p),g=function(e,t,o,n="Text",i){const a=t.points[0],r=i??(void 0===a?null:{x:e.timeToCoordinate(a.time),y:e.priceToCoordinate(a.price,t.paneIndex)});if(null===r)return null;const{x:s,y:l}=r;if(!Number.isFinite(s)||null===l||!Number.isFinite(l))return null;const c=t.text??{value:""},d=c.fontSize??14,u=ir(c,d),p=ar(o,c,void 0===c.value||""===c.value?n:c.value,c.wrapWidth??220);let h=0;for(const e of p)h=Math.max(h,o(e));const m=1.35*d,g=p.length*m+10,f=c.valign??"top";return{x:s,y:"middle"===f?l-g/2:"bottom"===f?l-g:l,width:h+10,height:g,lineHeight:m,lines:p,font:u,size:d}}(i,l,m,d,"viewport"===l.space?a.screenPoints(l.id)?.[0]??null:void 0),f=sr(i);if(null===g||null===f)return cr(e,kt(e,"That text is off the chart"),o.onDone);const b=et(e.root,f),v=qo(n,"div","oac-textedit");v.setAttribute("contenteditable","plaintext-only"),v.setAttribute("spellcheck","false"),v.setAttribute("role","textbox"),v.setAttribute("aria-multiline","true"),v.setAttribute("aria-label",kt(e,"Drawing text")),v.tabIndex=0;const w=v.style;w.left=`${Math.round(g.x+b.left)}px`,w.top=`${Math.round(g.y+b.top)}px`,w.font=h,w.lineHeight=`${g.lineHeight}px`,w.color=u.color??l.style.color??"inherit",w.textAlign=u.align??"left",w.minWidth=`${Math.ceil(g.width)}px`,w.minHeight=`${Math.ceil(g.height)}px`;const _=!0===u.wrap,y=u.wrapWidth??220;w.whiteSpace=_?"pre-wrap":"pre",_&&(w.width=`${Math.ceil(g.width)}px`);const x=u.value??"";v.textContent=x;let k=!1;const C=e=>{k||(k=!0,L.close(),o.onDone?.(e))},S=()=>{if(k)return;const e=rr(v),t=e!==x;t&&void 0!==a.get(l.id)&&a.update(l.id,{text:{...a.get(l.id)?.text??{value:""},value:e}}),C(t)},A=()=>C(!1);for(const e of["pointerdown","pointermove","pointerup","click","dblclick","contextmenu","keyup","keypress"])v.addEventListener(e,e=>{e.stopPropagation()});v.addEventListener("keydown",e=>{const t=e.key;if("Tab"!==t&&e.stopPropagation(),"Escape"===t)return e.preventDefault(),void A();"Enter"===t&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),S())}),v.addEventListener("blur",()=>S()),_&&v.addEventListener("input",()=>{const e=ar(m,u,rr(v)||d,y);let t=0;for(const o of e)t=Math.max(t,m(o));w.width=`${Math.ceil(t+10)}px`});const L=Qo(e,v,{placement:"below",modal:!1,dismissOnOutside:!1,initialFocus:v},A);try{const e=n.defaultView;if(null!==e&&"function"==typeof e.getSelection&&"function"==typeof n.createRange){const t=n.createRange();t.selectNodeContents(v),t.collapse(!1);const o=e.getSelection();o?.removeAllRanges(),o?.addRange(t)}}catch{}return{el:v,isOpen:L.isOpen,close:()=>S(),commit:S,cancel:A}}function ur(e){const t=e.map(e=>ke(e));if(0===t.length)return{fields:[]};const[o,...n]=t,i=o.fields.filter(e=>n.every(t=>t.fields.some(t=>t.path===e.path&&t.kind===e.kind)));return t.every(e=>!0===e.textIsContent)?{fields:i,textIsContent:!0}:{fields:i}}const pr={"style.lineWidth":1.5,"style.lineStyle":"solid","style.fillOpacity":.12,"text.fontSize":14,"text.wrapWidth":220,"text.backgroundOpacity":1,"text.align":"left","text.valign":"top","text.position":"inside"};function hr(e,t,o){const n={};for(const i of t.fields){const[t,a]=i.path.split("."),r="style"===t?e?.defaultStyle:"text"===t?e?.defaultText:void 0;let s=void 0===r||void 0===a?void 0:r[a];void 0===s&&(s=pr[i.path]),void 0===s&&"boolean"===i.kind&&(s=!1),void 0===s&&"style.color"===i.path&&(s=o),void 0!==s&&(n[i.path]=s)}return n}function mr(e,t,o,n){const i=hr(o,t,n);for(const[o,n]of Object.entries(xe(e,t)))void 0!==n&&(i[o]=n);for(const e of["text.color","style.fillColor","text.borderColor"])void 0===i[e]&&t.fields.some(t=>t.path===e)&&(i[e]=i["style.color"]);return i}const gr=(e,t)=>e.length===t.length&&e.every((e,o)=>e===t[o]);function fr(e,t,o={}){const{draw:n,chart:i}=e,a=e.document;void 0!==o.ids&&o.ids.length>0&&!gr(o.ids,n.selection())&&n.select(o.ids.slice());let r=n.selection().slice();const s=()=>r.map(e=>n.get(e)).filter(e=>void 0!==e);let l=s();if(0===l.length)return Zo(e,kt(e,"Select a drawing first"));let c=ur(l.map(e=>e.tool)),d=dt(l[0].tool),u=null,p=null;const h=()=>1===l.length?kt(e,`schema.drawing.${l[0].tool}.name`,{},d?.name??l[0].tool):kt(e,"{count} drawings",{count:l.length}),m=()=>0===ct(n,r).length?kt(e,"read-only"):null,g=()=>mr(l[0],c,d,e.chartTheme.lineColor);function f(t){const o=[];for(const e of l){const i=n.get(e.id);if(void 0===i)continue;const a=Ce(i,t,c);Object.keys(a).length>0&&o.push({id:e.id,patch:a})}o.length>0&&n.updateMany(o),"string"==typeof t.space&&l.some(e=>(n.get(e.id)?.space??"data")!==t.space)&&e.toast(kt(e,"The anchor changes only while the drawing's pane is on screen"),"info")}const b=Yo(a,{translate:e.translate,title:h(),className:"oac-props",onClose:()=>M.close()}),v=qo(a,"div","oac-props__tools");v.setAttribute("role","toolbar"),v.setAttribute("aria-label",kt(e,"Drawing actions")),b.el.insertBefore(v,b.body);const w=qo(a,"div","oac-props__pane"),_=qo(a,"div","oac-props__pane oac-props__anchors");let y=o.tab??"style";const x=en(a,[{id:"style",label:kt(e,"Style"),icon:"brush"},{id:"coordinates",label:kt(e,"Coordinates"),icon:"coordinates"}],y,"row",e=>{y=e,C()});b.body.append(x.el,w,_);let k=null;function C(){w.hidden="style"!==y,_.hidden="coordinates"!==y,"coordinates"===y&&null===k&&(k=Xa(e,_,()=>r,m))}function S(){v.innerHTML="";const t=dn(e,r),o=(t,o,n,i=null)=>{const s=Ko(a,{...t,iconOnly:!0,onClick:()=>{un(e,o,r)}});s.dataset.act=o,void 0!==n&&s.setAttribute("aria-pressed",n?"true":"false"),null!==i&&(s.disabled=!0,s.title+=` (${i})`),v.appendChild(s)},n=()=>{v.appendChild(qo(a,"span","oac-sep"))};o({label:kt(e,"Lock"),icon:t.locked?"lock":"unlock"},"lock",t.locked,t.readOnly),o({label:kt(e,"Hide"),icon:t.hidden?"eye-off":"eye"},"visible",t.hidden,t.readOnly),n(),o({label:kt(e,"Bring to front"),icon:"front"},"front"),o({label:kt(e,"Send to back"),icon:"back"},"back"),o({label:kt(e,"In front of the series"),icon:"above-series"},"above","above"===t.side),o({label:kt(e,"Behind the series"),icon:"behind-series"},"behind","behind"===t.side),n(),o({label:kt(e,"Duplicate"),icon:"duplicate",chord:ko(e.keymap,"duplicate","Mod+D")},"duplicate"),o({label:kt(e,"Delete"),icon:"trash",chord:ko(e.keymap,"delete","Delete"),variant:"danger"},"delete",void 0,t.noDelete),L.disabled=null!==t.readOnly}function A(){u?.destroy(),w.innerHTML="";const t=Bo(c.fields,{translate:e.translate,scope:`drawing.${l[0].tool}`});if(0===t.length)return w.appendChild(qo(a,"div","oac-empty",kt(e,"These drawings share no settings."))),void(u=null);const o=p=m();if(u=nn(w,t,{values:g(),translate:e.translate,openOverlay:e.openOverlay,idPrefix:"oac-props",unavailable:()=>o,onChange:(e,t)=>{f({[e]:t}),u?.sync(g())},custom:t=>{if("levels"!==t.custom)return null;const n=Ko(a,{label:kt(e,"Edit levels..."),onClick:t=>{nr(e,t.currentTarget,{ids:r})}});return n.dataset.act="edit-levels",n.disabled=null!==o,n}}),!0===c.textIsContent&&1===l.length){const t=w.querySelector('[data-key="text.value"]');if(null!==t){const n=Ko(a,{label:kt(e,"Edit text"),icon:"text",onClick:()=>{dr(e,0,{id:l[0].id})}});n.dataset.act="edit-text",n.disabled=null!==o,t.appendChild(n)}}}const L=b.lead.appendChild(Ko(a,{label:kt(e,"Restore defaults"),onClick:()=>{const t={},o=hr(d,{fields:c.fields},e.chartTheme.lineColor);for(const e of c.fields){if("levels"===e.kind)continue;const[n,i]=e.path.split("."),a="style"===n?d?.defaultStyle:"text"===n?d?.defaultText:void 0,r=void 0===a||void 0===i?void 0:a[i];t[e.path]=void 0===r?void 0:o[e.path]}f(t),u?.sync(g())}})),O=e.drawingTemplates;if(void 0!==O){const t=b.lead.appendChild(Ko(a,{label:kt(e,"Templates"),onClick:()=>{rn(e,t,qa(e,O,r,t),{ariaLabel:kt(e,"Templates")})}}));t.dataset.act="templates",t.setAttribute("aria-haspopup","menu")}function $(){if(!M.isOpen())return;const e=n.selection().slice();if(0!==e.length){if(gr(e,r))return l=s(),0===l.length?void M.close():(m()!==p?A():u?.sync(g()),S(),void k?.refresh());r=e,l=s(),0!==l.length?(c=ur(l.map(e=>e.tool)),d=dt(l[0].tool),b.setTitle(h()),S(),A(),k?.refresh()):M.close()}else M.close()}b.actions.appendChild(Ko(a,{label:kt(e,"Done"),variant:"primary",onClick:()=>M.close()})),S(),A(),C();const E=[i.on("draw:update",$),i.on("draw:select",$),i.on("draw:remove",$)];let T=!1;const P=()=>{if(!T){T=!0,u?.destroy(),k?.destroy();for(const e of E)e();o.onClose?.()}},j=Qo(e,b.el,{...void 0===t?{placement:"below",dismissOnOutside:!0}:{anchor:t,placement:"below"},onClose:P},P);void 0===t&&tn(e.root,b.el,{point:Xo(e.root,i,l,e=>n.screenPoints(e))});const M={el:b.el,isOpen:j.isOpen,close:()=>{u?.destroy(),j.close(),P()}};return M}const br=Tt(()=>import("./openalgo-charts.widget.layouts-templates-menu-CFf0bR9J.mjs"));function vr(e,t,o={}){const{chart:n}=e,i=e.document,a=E(),r=Yo(i,{translate:e.translate,title:kt(e,"Indicators"),className:"oac-pick",onClose:()=>S.close()}),s=qo(i,"input","oac-pick__find");s.type="search",s.placeholder=kt(e,"Search indicators"),s.setAttribute("aria-label",kt(e,"Search indicators")),s.setAttribute("spellcheck","false");const l=qo(i,"div","oac-pick__findwrap");l.appendChild(s);const c=qo(i,"div","oac-pick__list");c.setAttribute("role","listbox"),c.setAttribute("aria-label",kt(e,"Indicators")),r.body.appendChild(l);const d=qo(i,"div","oac-head oac-pick__running-head",kt(e,"schema.ui.indicatorPicker.running",{},"Running studies")),u=qo(i,"div","oac-pick__running");u.setAttribute("aria-label",kt(e,"schema.ui.indicatorPicker.running",{},"Running studies")),r.body.appendChild(d),r.body.appendChild(u),r.body.appendChild(c),r.actions.appendChild(Ko(i,{label:kt(e,"Done"),variant:"primary",onClick:()=>S.close()}));const p=void 0===o.templates?function(e){return Fi.get(e)}(e):o.templates??void 0;let h=null;if(void 0!==p?.planIndicatorTemplateState){const t={waiting:null},o=Ko(i,{label:kt(e,"Templates"),icon:"template",onClick:()=>{Pt(br,t=>{h?.close(),h=t.openTemplatesMenu(e,o,p)},t=>e.toast(jt(e,kt(e,"Templates"),t),"error"),()=>S.isOpen(),{slot:t,doc:i,from:o})}});o.dataset.action="templates",o.setAttribute("aria-haspopup","dialog"),r.lead.appendChild(o)}let m=[],g=-1;const f=e=>n.indicators().filter(t=>t.indicatorId===e).length,b=e=>{0!==m.length?(g=Math.max(0,Math.min(m.length-1,e)),m.forEach((e,t)=>{e.classList.toggle("is-active",t===g),e.setAttribute("aria-selected",t===g?"true":"false")})):g=-1},v=t=>{const i=n.addIndicator(t.id);e.toast(kt(e,"Added {name}",{name:i.name}),"success"),o.onAdd?.(i),!0!==o.closeOnAdd?(w(),s.focus()):S.close()};function w(){!function(){u.innerHTML="";const t=n.indicators().filter(e=>!1!==e.policy().listed);if(0===t.length)return void u.appendChild(qo(i,"div","oac-empty oac-pick__running-empty",kt(e,"schema.ui.indicatorPicker.empty",{},"No running studies")));const o=new Map;for(const a of t){const t=(o.get(a.indicatorId)??0)+1;o.set(a.indicatorId,t);const r=qo(i,"div","oac-pick__running-row");r.dataset.instanceId=a.id,r.appendChild(qo(i,"span","oac-pick__running-name",a.name)),r.appendChild(qo(i,"span","oac-pick__running-number",String(t)));const l=kt(e,"schema.ui.indicatorPicker.remove",{},"Remove"),c=Ko(i,{label:l,onClick:()=>{n.removeIndicator(a.id),w(),s.focus()}});c.classList.add("oac-pick__remove"),c.setAttribute("aria-label",`${l} ${a.name} ${t}`),!1===a.policy().removable&&(c.disabled=!0,c.title=kt(e,"protected"),c.setAttribute("aria-label",`${l} ${a.name} ${t}, ${kt(e,"protected")}`)),r.appendChild(c),u.appendChild(r)}}();const t=s.value;if(c.innerHTML="",m=[],0===a.length)return void c.appendChild(qo(i,"div","oac-empty",kt(e,"No indicators are registered. Import the indicators tier to fill this list.")));const o=function(e,t){const o=t.trim().toLowerCase();return e.filter(e=>""===o||e.name.toLowerCase().includes(o)||e.id.toLowerCase().includes(o)||(e.category??"").toLowerCase().includes(o)).sort((e,t)=>e.name.localeCompare(t.name))}(a.map(t=>({...t,name:kt(e,`schema.indicator.${t.id}.name`,{},t.name),category:void 0===t.category?void 0:kt(e,`schema.indicator.category.${t.category}`,{},t.category)})),t);if(0!==o.length){for(const[t,n]of function(e){const t=new Map;for(const o of e){const e=o.category??"Other",n=t.get(e);void 0===n?t.set(e,[o]):n.push(o)}return Array.from(t.entries()).sort((e,t)=>e[0].localeCompare(t[0]))}(o)){c.appendChild(qo(i,"div","oac-head","Other"===t?kt(e,"Other"):t));for(const t of n){const o=qo(i,"button","oac-pick__row");o.type="button",o.setAttribute("role","option"),o.dataset.id=t.id,o.appendChild(qo(i,"span","oac-pick__name",t.name));const n=f(t.id);if(n>0){const t=qo(i,"span","oac-pick__count",1===n?kt(e,"on chart"):kt(e,"on chart x{count}",{count:n}));t.setAttribute("aria-label",1===n?kt(e,"one instance on the chart"):kt(e,"{count} instances on the chart",{count:n})),o.appendChild(t)}o.addEventListener("click",e=>{e.stopPropagation(),v(t)}),c.appendChild(o),m.push(o)}}b(g<0?0:g)}else c.appendChild(qo(i,"div","oac-empty",kt(e,"No match")))}s.addEventListener("input",()=>{g=0,w()}),s.addEventListener("keydown",e=>{const t=e.key;if("ArrowDown"===t)e.preventDefault(),b(g+1);else if("ArrowUp"===t)e.preventDefault(),b(g-1);else if("Enter"===t){e.preventDefault();const t=m[g],o=t?.dataset.id,n=a.find(e=>e.id===o);void 0!==n&&v(n)}}),w();const _=n.on("objects:change",w),y=n.on("indicatorRemoved",w),x=n.on("state:restore:end",w),k=()=>{_(),y(),x(),h?.close()},C=Qo(e,r.el,void 0===t?{placement:"center",modal:!0,initialFocus:s}:{anchor:t,placement:"below",initialFocus:s},k),S={el:C.el,isOpen:C.isOpen,close:()=>{C.isOpen()&&(k(),C.close())}};return S}const wr=e=>e.disabled?e.title:null;function _r(e,t){let o=!1;const n=[],i=[],a=[],r=[],s=t.instance,l=()=>!o&&!e.chart.isDestroyed&&e.chart.indicators().includes(s)&&(t.current?.()??!0);let c=()=>{};const d=()=>{c();const t=e=>{e.detail>0&&(e.preventDefault(),e.stopImmediatePropagation(),c())},o=()=>{e.document.removeEventListener("click",t,!0),e.document.removeEventListener("pointerdown",o,!0),e.document.removeEventListener("keydown",o,!0),c===o&&(c=()=>{})};c=o,e.document.addEventListener("click",t,!0),e.document.addEventListener("pointerdown",o,!0),e.document.addEventListener("keydown",o,!0)};let u=null;const p=()=>{const e=u;e&&(e.finish(),e.cancel?.())},h=e=>{if(!l()||!t.onPatch(e)||!l())return!1;for(const[o,n]of Object.entries(e)){const e=t.field(o);e&&(e.value=String(n??""))}return!0},m=t=>kt(e,`schema.indicator.${s.indicatorId}.${t.key}.label`,{},t.label);for(const o of t.inputs){const c=t.field(o.key);if(!c)continue;if("symbol"===o.type){const t=Ko(e.document,{label:kt(e,"Search"),onClick:()=>{l()&&d?.open(c.value)}});t.setAttribute("aria-label",kt(e,"Search {label}",{label:m(o)})),t.dataset.inputAction=o.key,c.parentElement?.appendChild(t),n.push(t),a.push(()=>{const o=wr(c)??(void 0===e.symbolSearch?kt(e,"Symbol search is not configured; enter an instrument manually"):null);t.disabled=null!==o,t.title=o??""});const d=void 0===e.symbolSearch?null:Nn(e,c,{search:e.symbolSearch,context:()=>l()?[s.id,e.symbol(),e.interval(),e.chart.getDataContext()]:null,onSelect:(e,t)=>{const n=void 0===o.exchangeKey?{[o.key]:e}:{[o.key]:e,[o.exchangeKey]:t??""};h(n)}});if(d){i.push(d);const e=e=>{d.canCommitRaw()||e.stopImmediatePropagation()};c.addEventListener("change",e,!0),r.push(()=>c.removeEventListener("change",e,!0))}}if("price"!==o.type&&"timestamp"!==o.type||!o.pick)continue;const g=()=>{const n=wr(c);return null!==n?n:null!==e.draw.activeTool()?kt(e,"Finish or cancel the active drawing before picking"):t.suspend||e.overlays.suspend?"price"===o.type&&null===Pe(e.chart,s,o.key)?kt(e,"Choose an explicit pane and scale for this price input"):null:kt(e,"This host cannot suspend the settings dialog")},f="price"===o.type&&void 0!==o.timeKey?t.inputs.find(e=>e.key===o.timeKey&&"timestamp"===e.type):void 0,b=f?kt(e,"Pick {time} and {price} on the chart",{time:m(f),price:m(o)}):kt(e,"Pick {label} on the chart",{label:m(o)}),v=Ko(e.document,{label:kt(e,f?"Pick point on chart":"Pick on chart"),onClick:()=>{if(!l())return;const n=g();if(null!==n)return void e.toast(n,"info");p();for(const e of i)e.close();const a="price"===o.type?Pe(e.chart,s,o.key):void 0,r=t.suspend?.()??e.overlays.suspend(t.panel),c=qo(e.document,"div","oac-input-pick");c.appendChild(qo(e.document,"span",void 0,b));const m=Ko(e.document,{label:kt(e,"Cancel pick"),onClick:p});c.appendChild(m),c.addEventListener("pointerdown",e=>e.stopPropagation()),e.overlays.layer.appendChild(c);let w=()=>{};const _=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopImmediatePropagation(),p())},y={cancel:null,finish:()=>{u===y&&(u=null,w(),c.remove(),e.document.removeEventListener("keydown",_,!0),r(),l()&&v.isConnected&&v.focus())}};u=y;let x=!0;e.document.addEventListener("keydown",_,!0),w=e.chart.on("pick:end",e=>{x||(null===e.value?y.finish():queueMicrotask(()=>{u===y&&y.cancel&&!y.cancel.active()&&(d(),y.finish())}))}),m.focus();try{const t=e=>{u===y&&(d(),y.finish(),h(e))},n=f?e.chart.beginPick("point",e=>t({[o.key]:e.price,[f.key]:e.time}),a):e.chart.beginPick("price"===o.type?"price":"time",e=>t({[o.key]:e}),a);y.cancel=n,x=!1,u!==y?n():n.active()||y.finish()}catch(t){y.finish(),e.toast(t instanceof Error?t.message:kt(e,"The value could not be picked"),"error")}}});v.setAttribute("aria-label",b),v.dataset.inputAction=o.key,c.parentElement?.appendChild(v),n.push(v),a.push(()=>{const e=g();v.disabled=null!==e,v.title=e??""})}const g=()=>{if(!o)for(const e of a)e()},f=e.chart.on("objects:change",()=>{p(),g()}),b=e.chart.on("draw:tool",()=>{p(),g()}),v=e.chart.on("data:context",()=>{p();for(const e of i)e.close()}),w=e.chart.on("indicatorRemoved",()=>{l()||p()}),_=e.chart.on("state:restore:start",p),y=e.chart.on("destroy",p);return g(),{cancelPick:p,refresh:g,destroy:()=>{if(!o){o=!0,p(),c(),f(),b(),v(),w(),_(),y();for(const e of r)e();for(const e of i)e.destroy();for(const e of n)e.remove()}}}}const yr={source:"Source",indicator:"Indicator",drawing:"Drawing",profile:"Profile",group:"Group"},xr=["visibility","lock","settings","focus","remove"],kr={loading:"Loading",ready:"Ready",empty:"No data",unsupported:"Unsupported",error:"Could not load"},Cr={select:"Could not select {name}",visibility:"Could not change visibility for {name}",lock:"Could not change lock for {name}",settings:"Could not open settings for {name}",focus:"Could not focus {name}",remove:"Could not remove {name}"};let Sr=0;function Ar(e,t,o=()=>!0){const n=e=>{const o=new Map;for(const n of e)o.set(t(n),(o.get(t(n))??0)+1);return o},i=e.filter(o),a=e.filter(e=>!o(e)),r=n(i),s=n(e),l=new Map;return new Map([...i,...a].map(e=>{const n=t(e),i=(l.get(n)??0)+1;return l.set(n,i),[e.id,((o(e)?r:s).get(n)??0)>1?`${n} (${i})`:n]}))}const Lr=e=>Ar(e.indicators(),e=>e.name,e=>!1!==e.policy().listed);function Or(e,t={}){const o=t.objects??e.objects;if(void 0===o)throw new Error(kt(e,"Objects panel requires an object model"));const n=o,i=t=>t===n.primaryPaneIndex()?kt(e,"Price pane"):kt(e,"Pane {number}",{number:t+1}),a=e=>i(e.paneIndex),r=t=>kt(e,`schema.object.kind.${t.kind}`,{},yr[t.kind]),s=e.document;let l=!1,c=[];const d=new Map,u=qo(s,"div","oac-objects-content"),p=e=>e.stopPropagation();u.addEventListener("pointerdown",p);const h=new Map;let m=null;const g=(t,o,n={})=>kt(e,`schema.ui.objects.${t}`,n,o),f=qo(s,"input","oac-objects__find");f.type="search",f.placeholder=kt(e,"Search name, type or pane"),f.setAttribute("aria-label",kt(e,"Search objects")),f.setAttribute("spellcheck","false");const b=qo(s,"div","oac-objects__list");b.setAttribute("role","list"),b.setAttribute("aria-label",kt(e,"Chart objects"));const v=qo(s,"div","oac-empty");v.setAttribute("role","status");const w=qo(s,"span","oac-objects__count");w.setAttribute("role","status");const _=qo(s,"p","oac-objects__hint",g("orderHint","Each pane lists back to front. Drag a row, or press Alt with an arrow key, to move it."));u.append(f,_,b,v,w);const y=qo(s,"input","oac-objects__group-name");y.type="text",y.dataset.action="group-name",y.placeholder=g("groupName","Group name"),y.setAttribute("aria-label",g("groupName","Group name"));const x=Ko(s,{label:g("group","Group selected"),onClick:()=>{if(l)return;const e=c.filter(e=>"drawing"===e.kind&&e.selected).map(e=>e.id);n.createGroup(y.value,e)&&(y.value=""),E()}});if(x.dataset.action="group",n.canGroup()){const e=qo(s,"div","oac-objects__grouping");e.append(y,x),u.insertBefore(e,b)}const k=()=>{x.disabled=!y.value.trim()||!c.some(e=>"drawing"===e.kind&&e.selected&&e.capabilities.lock)};function C(t,o){l||(n.move(t,o)||e.toast(g("moveFailed","Could not move object"),"error"),E())}function S(e,t,o){const i=e.getBoundingClientRect();if(i.height>0)return t.clientY<i.top+i.height/2?"below":"above";const a=n.stack(n.get(o)?.paneIndex??-1);return a.findIndex(e=>e.id===m)>a.findIndex(e=>e.id===o)?"below":"above"}function A(){for(const e of d.values())e.el.classList.remove("is-drop-before","is-drop-after")}function L(e,t){const o=n.stack(e.paneIndex),i=o.findIndex(t=>t.id===e.id);if(i<0)return null;if("drawing"===e.kind){const e=o[i+t];return e?{target:e.id,where:1===t?"above":"below"}:null}const a=e=>void 0!==e&&"drawing"!==e.kind;if(-1===t){let e=i-1;for(;e>=0&&!a(o[e])&&"series"===o[e].band;)e--;return a(o[e])?{target:o[e].id,where:"below"}:null}let r=i+1;for(;r<o.length&&"series"===o[r].band&&!a(o[r]);)r++;if(!a(o[r]))return null;let s=r;for(;"series"===o[s+1]?.band&&!a(o[s+1]);)s++;return{target:o[s].id,where:"above"}}function O(t,o,i){if(l)return;const a=n.get(o);let r=!1;try{if(a?.capabilities[t])switch(t){case"select":r=n.select(o,!0===i?.ctrlKey||!0===i?.metaKey);break;case"visibility":r=n.setVisible(o,!a.visible);break;case"lock":r=n.setLocked(o,!a.locked);break;case"settings":r=n.openSettings(o);break;case"focus":r=n.focus(o);break;case"remove":r=n.remove(o)}}catch{}r||e.toast(kt(e,Cr[t],{name:a?.name??kt(e,"object")}),"error")}function $(t){const o=qo(s,"div","oac-objects__row");o.dataset.objectId=t.id,o.setAttribute("role","listitem"),o.addEventListener("dragstart",e=>{const o=n.get(t.id);l||!o?.capabilities.place&&!o?.capabilities.reorder?e.preventDefault():(e.stopPropagation(),m=t.id,e.dataTransfer?.setData("text/plain",t.id),e.dataTransfer&&(e.dataTransfer.effectAllowed="move"))}),o.addEventListener("dragend",()=>{m=null,A()}),o.addEventListener("dragleave",()=>{o.classList.remove("is-drop-before","is-drop-after")}),o.addEventListener("dragover",e=>{if(e.stopPropagation(),null===m||m===t.id)return;const i=n.get(m),a=S(o,e,t.id),r=void 0!==i&&(i.paneIndex!==t.paneIndex?!0===i.capabilities.move:n.canPlace(i.id,t.id,a)||void 0===i.band&&i.kind===t.kind&&!0===i.capabilities.reorder);A(),r&&(e.preventDefault(),o.classList.add("below"===a?"is-drop-before":"is-drop-after"))}),o.addEventListener("drop",i=>{i.preventDefault(),i.stopPropagation(),function(t,o){if(A(),l||null===m||m===t)return;const i=n.get(m),a=n.get(t);if(i&&a&&(i.paneIndex===a.paneIndex||i.capabilities.move&&n.move(i.id,a.paneIndex)))if(n.canPlace(i.id,a.id,o))n.place(i.id,a.id,o)||e.toast(g("reorderFailed","Could not reorder object"),"error");else if(i.kind===a.kind&&void 0===i.band)for(let e=0;e<c.length;e++){const e=n.list().filter(e=>e.kind===i.kind&&e.paneIndex===n.get(i.id)?.paneIndex),t=e.findIndex(e=>e.id===i.id),o=e.findIndex(e=>e.id===a.id);if(t<0||o<0||t===o||!n.reorder(i.id,t<o?1:-1))break;if(1===Math.abs(t-o))break}}(t.id,S(o,i,t.id)),m=null}),o.addEventListener("keydown",e=>{const o=e.key;if(!e.altKey||"ArrowUp"!==o&&"ArrowDown"!==o)return;const n=d.get(t.id)?.buttons.get("ArrowUp"===o?"earlier":"later");void 0!==n&&(e.preventDefault(),e.stopPropagation(),n.disabled||n.click())});const i=qo(s,"span","oac-objects__grip");i.setAttribute("aria-hidden","true"),i.innerHTML=ie("grip"),o.appendChild(i);const a=t.capabilities.select?Ko(s,{label:"",onClick:e=>O("select",t.id,e)}):qo(s,"div");a.classList.add("oac-objects__summary"),t.capabilities.select&&(a.dataset.action="select");const r=qo(s,"span","oac-objects__name"),u=qo(s,"span","oac-objects__meta"),p=qo(s,"span","oac-objects__status"),h="oac-object-"+ ++Sr;u.id=`${h}-meta`,p.id=`${h}-status`,t.capabilities.select&&a.setAttribute("aria-describedby",`${u.id} ${p.id}`),a.append(r,u,p);const f=qo(s,"div","oac-objects__actions");o.append(a,f);const b="group"===t.kind?qo(s,"div","oac-objects__members"):void 0;return b&&(b.setAttribute("role","list"),o.appendChild(b)),{el:o,summary:a,name:r,meta:u,status:p,actions:f,selectable:t.capabilities.select,buttons:new Map,members:b}}function E(){if(l)return;const t=f.value.trim().toLowerCase(),o=new Set(c.filter(e=>`${e.name} ${r(e)} ${a(e)}`.toLowerCase().includes(t)).map(e=>e.id));for(const e of c)e.groupId&&o.has(e.groupId)&&o.add(e.id);const u=c.filter(e=>o.has(e.id)||c.some(t=>t.groupId===e.id&&o.has(t.id))),p=new Set(u.map(e=>e.id)),_=s.activeElement,y=null!==_&&b.contains(_);for(const[e,t]of d)p.has(e)||(t.el.remove(),d.delete(e));const x=[...new Set(u.map(e=>e.paneIndex))].sort((e,t)=>e-t);for(const[e,t]of h)x.includes(e)||(t.element.remove(),h.delete(e));x.forEach((e,t)=>{let o=h.get(e);if(!o){const t=qo(s,"section","oac-objects__pane");t.dataset.paneIndex=String(e);const i=qo(s,"h3","oac-objects__pane-title"),a=qo(s,"div");t.append(i,a),t.addEventListener("dragover",e=>{null!==m&&n.get(m)?.capabilities.move&&e.preventDefault()}),t.addEventListener("drop",t=>{t.preventDefault(),null!==m&&n.get(m)?.capabilities.move&&C(m,e),m=null}),o={element:t,rows:a,heading:i},h.set(e,o)}const a=i(e);o.heading.textContent!==a&&(o.heading.textContent=a,o.element.setAttribute("aria-label",a)),b.children[t]!==o.element&&b.insertBefore(o.element,b.children[t]??null)});const S=new Map;for(const e of x)n.stack(e).forEach((e,t)=>S.set(e.id,t));const A=e=>{if(S.has(e.id))return S.get(e.id);const t=c.filter(t=>t.groupId===e.id&&S.has(t.id)).map(e=>S.get(e.id));return t.length?Math.min(...t)-.5:Number.MAX_SAFE_INTEGER},E=u.map((e,t)=>({item:e,index:t})).sort((e,t)=>A(e.item)-A(t.item)||e.index-t.index).map(e=>e.item),T=new Map;E.forEach(t=>{let o=d.get(t.id);void 0!==o&&o.selectable===t.capabilities.select||(o?.el.remove(),o=$(t),d.set(t.id,o)),function(t,o){t.name.textContent=o.name,t.el.draggable=!0===o.capabilities.reorder||!0===o.capabilities.place,t.el.dataset.groupId=o.groupId??"",t.el.classList.toggle("is-group-member",void 0!==o.groupId);const d=[r(o),a(o),o.visible?kt(e,"Visible"):kt(e,"Hidden")];if("drawing"===o.kind&&"below"===o.band&&d.push(g("behind","Behind the series")),"drawing"===o.kind&&"series"===o.band){const e=c.find(e=>e.id===o.stackAbove);d.push(g("above","Above {name}",{name:e?.name??g("hidden","a hidden study")}))}if(void 0!==o.locked&&d.push(o.locked?kt(e,"Locked"):kt(e,"Unlocked")),o.selected&&d.push(kt(e,"Selected")),o.groupId){const e=c.find(e=>e.id===o.groupId);e&&d.push(e.name)}t.meta.textContent=d.join(", "),t.el.classList.toggle("is-selected",o.selected),t.selectable&&(t.summary.setAttribute("aria-label",kt(e,"Select {name}",{name:o.name})),t.summary.setAttribute("aria-pressed",String(o.selected))),t.status.textContent=void 0===o.dataStatus?"":kt(e,`schema.dataStatus.${o.dataStatus.state}`,{},kr[o.dataStatus.state]),t.status.hidden=void 0===o.dataStatus,t.status.dataset.state=o.dataStatus?.state??"";let u=0;for(const n of xr){let i=t.buttons.get(n);if(!o.capabilities[n]){i?.remove(),t.buttons.delete(n);continue}void 0===i&&(i=Ko(s,{label:"",variant:"remove"===n?"danger":"ghost",onClick:()=>O(n,o.id)}),i.dataset.action=n,t.buttons.set(n,i));const a="visibility"===n?o.visible?kt(e,"Hide"):kt(e,"Show"):"lock"===n?o.locked?kt(e,"Unlock"):kt(e,"Lock"):"settings"===n?kt(e,"Settings"):"focus"===n?kt(e,"Focus"):"drawing"===o.kind?kt(e,"Delete"):kt(e,"Remove");i.textContent=a,i.setAttribute("aria-label",kt(e,"visibility"===n?o.visible?"Hide {name}":"Show {name}":"lock"===n?o.locked?"Unlock {name}":"Lock {name}":"settings"===n?"Settings for {name}":"focus"===n?"Focus {name}":"drawing"===o.kind?"Delete {name}":"Remove {name}",{name:o.name})),t.actions.children[u]!==i&&t.actions.insertBefore(i,t.actions.children[u]??null),u++}if("drawing"===o.kind&&o.id==="drawing:"+o.sourceId&&n.canGroup()){let e=t.buttons.get("add-selection");e||(e=Ko(s,{label:"",variant:"ghost",onClick:()=>{l||n.select(o.id,!0)}}),e.dataset.action="add-selection",t.buttons.set("add-selection",e)),e.textContent=g(o.selected?"deselect":"selectMore",o.selected?"Deselect":"Select"),e.setAttribute("aria-label",g(o.selected?"deselectLabel":"selectMoreLabel",o.selected?"Remove {name} from selection":"Add {name} to selection",{name:o.name})),t.actions.children[u]!==e&&t.actions.insertBefore(e,t.actions.children[u]??null),u++}for(const[i,a]of[["earlier",-1],["later",1]]){let r=t.buttons.get(i);if(!o.capabilities.reorder&&!o.capabilities.place){r?.remove(),t.buttons.delete(i);continue}r||(r=Ko(s,{label:"",variant:"ghost",onClick:()=>{if(l)return;const t=n.get(o.id),i=void 0!==t?.band?L(t,a):null;(void 0!==t?.band?null!==i&&n.place(o.id,i.target,i.where):n.reorder(o.id,a))||e.toast(g("reorderFailed","Could not reorder object"),"error")}}),r.dataset.action=i,t.buttons.set(i,r)),r.textContent=g(i,-1===a?"Earlier":"Later"),r.setAttribute("aria-label",g(i+"Label",-1===a?"Move {name} earlier":"Move {name} later",{name:o.name}));const c=void 0!==o.band?L(o,a):null;r.disabled=void 0!==o.band?null===c||!n.canPlace(o.id,c.target,c.where):!n.canReorder(o.id,a),t.actions.children[u]!==r&&t.actions.insertBefore(r,t.actions.children[u]??null),u++}if(o.capabilities.move){t.move||(t.move=qo(s,"select","oac-objects__move"),t.move.dataset.action="move",t.move.addEventListener("change",()=>C(o.id,Number(t.move.value)))),t.move.setAttribute("aria-label",g("movePane","Move {name} to pane",{name:o.name}));const e=n.paneCount(),a=Array.from({length:e+1},(t,o)=>o===e?g("newPane","New pane"):i(o));(t.move.children.length!==a.length||a.some((e,o)=>t.move.children[o]?.textContent!==e))&&(t.move.replaceChildren(),a.forEach((e,o)=>{const n=qo(s,"option");n.value=String(o),n.textContent=e,t.move.appendChild(n)})),t.move.value=String(o.paneIndex),t.actions.children[u]!==t.move&&t.actions.insertBefore(t.move,t.actions.children[u]??null),u++}else t.move?.remove(),t.move=void 0;t.actions.hidden=0===u}(o,t);const u=t.groupId?c.find(e=>e.id===t.groupId&&e.paneIndex===t.paneIndex):void 0,p=(u?d.get(u.id)?.members:void 0)??h.get(t.paneIndex).rows,m=T.get(p)??0;p.children[m]!==o.el&&p.insertBefore(o.el,p.children[m]??null),T.set(p,m+1)}),k(),v.hidden=u.length>0,v.textContent=0===c.length?kt(e,"No objects on this chart."):kt(e,"No objects match your search.");const P=1===c.length;w.textContent=""===t?kt(e,P?"{count} object":"{count} objects",{count:c.length}):kt(e,P?"{shown} of {count} object":"{shown} of {count} objects",{shown:u.length,count:c.length}),y&&(b.contains(_)?s.activeElement!==_&&_.focus():f.focus())}y.addEventListener("input",k),f.addEventListener("input",E);const T=n.subscribe(t=>{if(l)return;const o=new Map((e.draw?.drawings()??[]).map((e,t)=>[e.id,t])),n=e=>"drawing"===e.kind?o.get(e.sourceId)??o.size:-1,i=Ar([...t].sort((e,t)=>n(e)-n(t)),e=>e.name);c=t.map(e=>i.get(e.id)===e.name?e:{...e,name:i.get(e.id)}),E()});return{element:u,initialFocus:f,destroy:()=>{l||(l=!0,T(),u.removeEventListener("pointerdown",p),f.removeEventListener("input",E),y.removeEventListener("input",k),d.clear(),h.clear(),m=null,c=[],t.onClose?.())}}}function $r(e,t,o={}){const n=Or(e,o),i=Yo(e.document,{translate:e.translate,title:kt(e,"Objects"),className:"oac-objects",onClose:()=>a.close(),closeText:!0});i.body.appendChild(n.element),i.actions.appendChild(Ko(e.document,{label:kt(e,"Done"),variant:"primary",onClick:()=>a.close()}));const a=Qo(e,i.el,{...void 0===t?{placement:"center",modal:!0}:{anchor:t,placement:"below"},initialFocus:n.initialFocus,onClose:()=>n.destroy()},()=>{});return a}const Er='\n.oac-widget .oac-objects { width: 440px; min-width: 0; }\n.oac-widget .oac-objects .oac-dialog__body { display: flex; flex-direction: column; gap: 8px; overflow: hidden; }\n.oac-widget .oac-objects-content { display: flex; flex-direction: column; min-height: 0; gap: 8px; }\n.oac-widget .oac-objects__pane-title { margin: 6px 2px; color: var(--oac-mut); font-size: 11px; text-transform: uppercase; }\n.oac-widget .oac-objects__grouping { display: flex; gap: 4px; }\n.oac-widget .oac-objects__group-name { min-width: 0; width: 100%; }\n.oac-widget .oac-objects__move { min-width: 90px; max-width: 130px; height: 26px; font-size: 11px; }\n.oac-widget .oac-objects__row.is-group-member { margin-left: 10px; border: 0; border-left: 1px solid var(--oac-bd-soft); border-radius: 0; }\n.oac-widget .oac-objects__members { min-width: 0; }\n.oac-widget .oac-objects__list { scrollbar-width: thin; scrollbar-color: var(--oac-bd-soft) var(--oac-bg); }\n.oac-widget .oac-objects__list::-webkit-scrollbar { width: 6px; }\n.oac-widget .oac-objects__list::-webkit-scrollbar-track { background: var(--oac-bg); }\n.oac-widget .oac-objects__list::-webkit-scrollbar-thumb { background: var(--oac-bd-soft); border-radius: 3px; }\n.oac-widget .oac-objects__list::-webkit-scrollbar-thumb:hover { background: var(--oac-mut); }\n.oac-widget .oac-objects__find { width: 100%; min-width: 0; flex: none; }\n.oac-widget .oac-objects__list { min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 2px; }\n.oac-widget .oac-objects__row { position: relative; display: flex; flex-direction: column; gap: 4px; padding: 6px; margin-bottom: 4px;\n border: 1px solid var(--oac-bd-soft); border-radius: 6px; min-width: 0; }\n.oac-widget .oac-objects__row[draggable="true"] { cursor: grab; }\n.oac-widget .oac-objects__grip { display: none; position: absolute; top: 7px; right: 6px; color: var(--oac-faint); line-height: 0; pointer-events: none; }\n.oac-widget .oac-objects__row[draggable="true"] > .oac-objects__grip { display: block; }\n.oac-widget .oac-objects__grip > svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }\n.oac-widget .oac-objects__row[draggable="true"] > .oac-objects__summary { padding-right: 18px; }\n.oac-widget .oac-objects__hint { margin: 0 2px; color: var(--oac-faint); font-size: 11px; line-height: 1.4; }\n.oac-widget .oac-objects__row.is-selected { border-color: var(--oac-acc); background: var(--oac-elev); }\n.oac-widget .oac-objects__row.is-drop-before { box-shadow: inset 0 2px 0 var(--oac-acc); }\n.oac-widget .oac-objects__row.is-drop-after { box-shadow: inset 0 -2px 0 var(--oac-acc); }\n.oac-widget .oac-objects__summary { display: flex; flex-direction: column; align-items: flex-start; justify-content: center;\n gap: 2px; width: 100%; min-width: 0; height: auto; padding: 3px 4px; text-align: left; white-space: normal; }\n.oac-widget .oac-objects__name { font-weight: 600; overflow-wrap: anywhere; }\n.oac-widget .oac-objects__meta, .oac-widget .oac-objects__status { font-size: 11px; color: var(--oac-mut); overflow-wrap: anywhere; }\n.oac-widget .oac-objects__status[data-state="error"] { color: var(--oac-danger); }\n.oac-widget .oac-objects__actions { display: flex; flex-wrap: wrap; gap: 3px; }\n.oac-widget .oac-objects__actions .oac-btn { height: 26px; padding: 0 6px; font-size: 11px; }\n.oac-widget .oac-objects__count { color: var(--oac-mut); font-size: 11px; }\n',Tr="@bars";function Pr(e){if(null===e||"object"!=typeof e)return!1;const t=e;return"indicator"===t.kind&&"string"==typeof t.instanceId&&"string"==typeof t.plotKey}const jr=e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[e,Pr(t)?{...t}:t]));function Mr(e){const t=Object.fromEntries(e.map(e=>[e.key,e.default]));for(const o of e)"symbol"!==o.type||void 0===o.exchangeKey||Object.prototype.hasOwnProperty.call(t,o.exchangeKey)||Object.defineProperty(t,o.exchangeKey,{value:"",writable:!0,configurable:!0,enumerable:!0});return t}function Ir(e,t,o={}){const n=e.document,i=function(e,t,o){const n=e.chart.indicators(),i=o.instanceId??t?.dataset.instanceId;if(void 0!==i){const t=n.find(e=>e.id===i)??null;return null===t?{inst:null,why:kt(e,"That indicator is no longer on the chart")}:{inst:t,why:null}}return 1===n.length?{inst:n[0],why:null}:{inst:null,why:0===n.length?kt(e,"No indicator on the chart to configure"):kt(e,"Pick an indicator from the legend first")}}(e,t,o);if(null===i.inst)return Zo(e,i.why??kt(e,"No indicator to configure"));const a=i.inst;if(!1===a.policy().configurable)return Zo(e,kt(e,"{name} settings are protected",{name:a.name}));const r=I(a.indicatorId),s=[],l=e.chart,c=l.primarySeries?.()??null,d=null===c||null===(l.seriesTransform?.(c)??null)?[]:[{key:Tr,type:"select",label:"Compute on",default:"chart",options:[{label:"Chart bars",value:"chart"},{label:"Underlying bars",value:"underlying"}]}],u=[...d,...r.inputs];u.length>0&&s.push({id:"inputs",label:kt(e,"Inputs"),icon:"settings",inputs:u});const p=D(r);if(p.length>0&&s.push({id:"style",label:kt(e,"Style"),icon:"brush",inputs:p}),0===s.length)return Zo(e,kt(e,"{name} has nothing to configure",{name:a.name}));const h=jr(a.settings()),m=d.length>0?a.barSource():"chart",g=new Set,f=e.history?.group("Study settings")??(()=>{});let b=s.some(e=>e.id===o.tab)?o.tab:s[0].id,v=null,w=null,_=null,y=!1,x=()=>{},k=()=>{};const C=()=>!e.chart.isDestroyed&&e.chart.indicators().includes(a),S=t=>{e.toast(t instanceof Error?t.message:kt(e,"The study settings could not be applied"),"error")},A=()=>kt(e,"{name} settings are protected",{name:a.name}),L=t=>{if(_=null,!C())return P(),!1;try{const{[Tr]:o,...n}=t;if(void 0!==o&&o!==a.barSource()&&!a.setBarSource(o)||Object.keys(n).length>0&&!1===a.setSettings(jr(n)))return _=A(),e.toast(_,"error"),!1}catch(t){return _=t instanceof Error?t.message:kt(e,"The study settings could not be applied"),S(t),!1}for(const e of Object.keys(t))g.add(e);return o.onChange?.(a),!0},O=Yo(n,{translate:e.translate,title:kt(e,"{name} settings",{name:a.name}),className:"oac-indset",onClose:()=>P()}),$=qo(n,"div","oac-indset__pane");if(s.length>1){const e=en(n,s.map(e=>({id:e.id,label:e.label,icon:e.icon})),b,"row",t=>{!v||v.validate()?(b=t,E()):e.setActive(b)});O.body.appendChild(e.el)}function E(){w?.destroy(),w=null,v?.destroy();const t=s.find(e=>e.id===b)??s[0];$.innerHTML="";const o=Ro(t.inputs,{translate:e.translate,scope:`indicator.${r.id}`},e.intervals),i=new Map;for(const n of t.inputs){if("source"!==n.type)continue;const t=o.find(e=>e.key===n.key),r=[...t.options??[]],s=new Map,l=Lr(e.chart);if(n.allowStudyOutputs)for(const t of e.chart.indicators())if(t.id!==a.id)for(const o of I(t.indicatorId).plots){if(o.ohlc)continue;const n=`study-output:${s.size}`;s.set(n,{kind:"indicator",instanceId:t.id,plotKey:o.key});const i=kt(e,`schema.indicator.${t.indicatorId}.plot.${o.key}`,{},o.title??o.key);r.push({value:n,label:`${l.get(t.id)} / ${i}`})}t.options=r,i.set(n.key,s)}const l=()=>{const t={...z(r),...Mr(p),...a.settings(),...d.length>0?{[Tr]:a.barSource()}:{}};for(const[n,a]of i){const i=t[n];if(!Pr(i))continue;let r=[...a].find(([,e])=>e.instanceId===i.instanceId&&e.plotKey===i.plotKey)?.[0];if(void 0===r){r=`study-output:${a.size}`,a.set(r,{...i});o.find(e=>e.key===n).options.push({value:r,label:kt(e,"Unavailable study output: {instanceId} / {plotKey}",{instanceId:i.instanceId,plotKey:i.plotKey})})}t[n]=r}return t};v=nn($,o,{values:l(),translate:e.translate,openOverlay:e.openOverlay,idPrefix:`oac-ind-${a.id}`,live:!0,onChange:(e,o)=>{const a="string"==typeof o?i.get(e)?.get(o):void 0;if(!L({[e]:a?{...a}:o})){if(!C())return;if(t.inputs.some(t=>t.key===e&&["symbol","session","multiline","price","timestamp"].includes(t.type)))return void v?.setError(e,_);const o=n.activeElement?.id;return E(),void(o&&n.getElementById(o)?.focus())}v?.sync(l()),w?.refresh()}}),w=_r(e,{instance:a,inputs:t.inputs,panel:O.el,field:e=>Array.from($.querySelectorAll("input")).find(t=>t.id===`oac-ind-${a.id}-${e.replace(/[^A-Za-z0-9_-]/g,"-")}`)??null,onPatch:e=>{if(!L(e)){for(const t of Object.keys(e))v?.setError(t,_);return!1}for(const t of Object.keys(e))v?.setError(t,null);return v?.sync(l()),w?.refresh(),!0}})}O.body.appendChild($),E(),O.lead.appendChild(Ko(n,{label:kt(e,"Defaults"),onClick:()=>{const e=s.find(e=>e.id===b)??s[0];L(Mr(e.inputs))&&E()}})),O.actions.appendChild(Ko(n,{label:kt(e,"Cancel"),onClick:()=>P()})),O.actions.appendChild(Ko(n,{label:kt(e,"OK"),variant:"primary",onClick:()=>j()})),O.el.addEventListener("keydown",e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),P())});const T=Qo(e,O.el,{placement:"center",modal:!0,dismissOnEscape:!1,onClose:()=>{x(),k(),w?.destroy(),v?.destroy(),f()}},()=>{P(),T.isOpen()&&(v?.destroy(),T.close(),o.onClose?.(!1))});function P(){T.isOpen()&&function(){if(!C())return e.toast(kt(e,"That indicator is no longer on the chart"),"info"),!0;if(y||0===g.size)return!0;const t=Object.fromEntries([...g].filter(e=>e!==Tr).map(e=>[e,h[e]]));try{(g.has(Tr)&&a.barSource()!==m&&!a.setBarSource(m)||Object.keys(t).length>0&&!1===a.setSettings(jr(t)))&&e.toast(A(),"error")}catch(e){return S(e),E(),!1}return g.clear(),o.onChange?.(a),!0}()&&(w?.destroy(),v?.destroy(),T.close(),o.onClose?.(!1))}function j(){T.isOpen()&&(v&&!v.validate()||(y=!0,w?.destroy(),v?.destroy(),T.close(),o.onClose?.(!0)))}return x=e.chart.on("indicatorRemoved",()=>{C()?v?.validate()&&E():P()}),k=e.chart.on("destroy",P),{el:O.el,isOpen:T.isOpen,close:()=>j()}}const Dr={price:"chart-candlestick",readout:"legend",axes:"axes",appearance:"panels",trading:"trading"};function zr(e,t,o={}){const{chart:n}=e,a=e.document,s=N(n).filter(e=>e.inputs.length>0),l=i(n),c=new Set;let d=s.some(e=>e.id===o.tab)?o.tab:s[0]?.id??"price",u=null,p=!1;const h=e.history?.group("Chart settings")??(()=>{}),m=t=>{pt(e,void 0,()=>r(n,t))},g=e=>{for(const t of Object.keys(e))c.add(t);m(e),o.onApply?.(e)},f=Yo(a,{translate:e.translate,title:kt(e,"Chart settings"),className:"oac-settings",onClose:()=>k()}),b=qo(a,"div","oac-settings__main"),v=qo(a,"div","oac-settings__pane");f.body.appendChild(b);const w=en(a,s.map(t=>({id:t.id,label:kt(e,`schema.settings.tab.${t.id}`,{},t.label),icon:Dr[t.id]})),d,"rail",e=>{d=e,_()});function _(){u?.destroy();const t=s.find(e=>e.id===d);v.innerHTML="",u=null,void 0!==t?u=nn(v,Ro(t.inputs,{translate:e.translate,scope:"settings"}),{values:i(n),translate:e.translate,openOverlay:e.openOverlay,idPrefix:"oac-cset",live:!0,unavailable:(t,i)=>"statusLine.openInterest"===t&&!1===n.hasOpenInterest?kt(e,"Open interest is unavailable for this instrument."):o.unavailable?.(t,i)??null,onChange:(e,t)=>{g({[e]:t}),u?.sync(i(n))}}):v.appendChild(qo(a,"div","oac-empty",kt(e,"Nothing to configure on this chart yet.")))}b.appendChild(w.el),b.appendChild(v),_(),f.lead.appendChild(Ko(a,{label:kt(e,"Restore this tab"),onClick:()=>{const t=s.find(e=>e.id===d);if(void 0===t)return;const o=function(e){const t={};for(const o of e.inputs)"colorPair"===o.type?(t[o.up.key]=o.up.default,t[o.down.key]=o.down.default,void 0!==o.enabled&&(t[o.enabled.key]=o.enabled.default)):t[o.key]=o.default;return t}(t);for(const t of Object.keys(o)){const n=e.settingsDefaults?.[t];void 0!==n&&(o[t]=n)}g(o),_()}})),f.actions.appendChild(Ko(a,{label:kt(e,"Cancel"),onClick:()=>k()})),f.actions.appendChild(Ko(a,{label:kt(e,"OK"),variant:"primary",onClick:()=>C()}));const y=n.on("data:context",_),x=Qo(e,f.el,{placement:"center",modal:!0,onClose:()=>{y(),u?.destroy(),h()}},()=>k());function k(){x.isOpen()&&(!function(){if(p||0===c.size)return;const e={};for(const t of c){const o=l[t];void 0!==o&&(e[t]=o)}c.clear(),m(e),o.onApply?.(e)}(),u?.destroy(),x.close(),o.onClose?.(!1))}function C(){x.isOpen()&&(p=!0,u?.destroy(),x.close(),o.onClose?.(!0))}return{el:f.el,isOpen:x.isOpen,close:()=>C()}}const Nr=[{value:"price",label:"Price"},{value:"indicator",label:"Study plot"},{value:"drawing",label:"Drawing level"},{value:"barCondition",label:"Candle condition"}],Rr=(e,t,o)=>({key:e,label:t,kind:"select",options:o}),Fr=e=>e.chart.primaryPaneIndex(),Wr=(e,t,o)=>t?I(t.indicatorId).plots.filter(n=>void 0===o||(n.overlay?Fr(e):t.paneIndex)===o).map(o=>({value:o.key,label:kt(e,`schema.indicator.${t.indicatorId}.plot.${o.key}`,{},o.title)})):[];function Br(e,t){const o=[Rr("kind",kt(e,"Source"),Nr.map(t=>({...t,label:kt(e,`schema.alert.kind.${t.value}`,{},t.label)})))],n=e.chart.indicators().filter(e=>!1!==e.policy().listed||e.id===t.instanceId||e.id===t.inputInstanceId),i=e.chart.primaryBars(),a=i.length-1,r=(e,o)=>(void 0===t[e]&&(t[e]=o[0]?.value??""),String(t[e])),s=Lr(e.chart),l=e=>e.map(e=>({value:e.id,label:s.get(e.id)??e.name})),c=t.kind;if("barCondition"===c){const t=R().map(t=>({value:t.id,label:kt(e,`schema.barCondition.${t.id}.title`,{},t.title)})),n=r("barConditionId",t);return o.push(Rr("barConditionId",kt(e,"Candle condition"),t)),{source:{kind:c,id:n},controls:o,reason:t.some(e=>e.value===n)?void 0:kt(e,"Candle condition is unavailable")}}if("indicator"===c){const i=r("instanceId",l(n)),s=n.find(e=>e.id===i),d=Wr(e,s),u=r("plotKey",d);o.push(Rr("instanceId",kt(e,"Study"),l(n)),Rr("plotKey",kt(e,"Plot"),d));const p=s?.values()[u]?.[a];return"value"in t||(t.value=p??void 0),{source:{kind:c,instanceId:i,plotKey:u,value:t.value,upperValue:t.upperValue},controls:o,reason:s?s.series(u)?void 0:kt(e,"Study plot is unavailable"):kt(e,"Study instance is unavailable"),hint:Number.isFinite(p)?void 0:kt(e,"The current plot value is unavailable. The alert waits for observed values.")}}if("drawing"===c){const i=e.draw.drawings(),a=e=>!1!==e.policy?.listed,s=Ar(i,t=>kt(e,`schema.drawing.${t.tool}.name`,{},mn(t.tool)),a),d=i.filter(e=>a(e)||e.id===t.drawingId).map(e=>({value:e.id,label:s.get(e.id)})),u=r("drawingId",d),p=e.draw.alertInfo(u),h=p.levels.map(e=>({value:e.id,label:e.title})),m=r("level",h);o.push(Rr("drawingId",kt(e,"Drawing"),d),Rr("level",kt(e,"Level"),h));const g=n.filter(t=>Wr(e,t,p.paneIndex).length>0),f=l(g);p.paneIndex===Fr(e)&&f.unshift({value:"",label:kt(e,"Price")});const b=r("inputInstanceId",f);o.push(Rr("inputInstanceId",kt(e,"Compare with"),f));const v=g.find(e=>e.id===b);let w;if(b){const t=Wr(e,v,p.paneIndex),n=r("inputPlotKey",t);w={instanceId:b,plotKey:n},o.push(Rr("inputPlotKey",kt(e,"Input plot"),t))}const _=p.available?h.some(e=>e.value===m)?w?Wr(e,v,p.paneIndex).some(e=>e.value===w.plotKey)?void 0:kt(e,"Select an input plot on the drawing pane"):p.paneIndex!==Fr(e)?kt(e,"Select an input plot on the drawing pane"):void 0:kt(e,"Drawing level is unavailable"):p.reason;return{source:{kind:c,drawingId:u,level:m,...w?{input:w}:{}},controls:o,reason:_}}return"price"in t||(t.price=i[a]?.close),{source:{kind:"price",price:t.price,upperPrice:t.upperPrice},controls:o}}let qr=0;const Ur=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}$/;function Hr(e,t){if(void 0===e)return"";const o=Ya(e,t,!1);return`${o.date}T${o.time}`}function Kr(e,t){if(e)return Hr(e.expiresAt,t);const o=v(Math.floor(Date.now()/1e3),t),n=o.month-1+2,i=Math.min(o.day,new Date(Date.UTC(o.year,n+1,0)).getUTCDate()),a=Date.UTC(o.year,n,i,o.hour,o.minute)/1e3,r=a-f(a,t),s=a-f(r,t);return Hr(s+f(s,t)===a?s:Math.max(r,s),t)}const Gr=e=>{try{return L(e)}catch{return"invalid"}};function Vr(e,t,o={}){const n=e.alerts,i=n?.list().find(e=>e.id===o.alertId),a=e.chart.timezone(),r=e.chart.getDataContext(),s=e=>JSON.stringify([e?.symbol,e?.exchange,e?.interval,Gr(e?.variant)]),l=s(r),c=e.chart.primaryBars(),d=i?.source??o.source??{kind:"price",price:c[c.length-1]?.close};let u,p=!1,h=!1;const m="oac-alert-"+ ++qr,g=[];let f={...i,...d,..."drawing"===d.kind?{inputInstanceId:d.input?.instanceId,inputPlotKey:d.input?.plotKey}:{},..."barCondition"===d.kind?{barConditionId:d.id}:{},enabled:!i||"armed"===i.state,expiresAt:Kr(i,a)};function b(){if(!p){p=!0;for(const e of g.splice(0))e();u?.destroy(),O?.close(),o.onClose?.()}}const v=Yo(e.document,{translate:e.translate,title:kt(e,i?"Edit alert":"Create alert"),className:"oac-alert-editor",onClose:b}),w=qo(e.document,"p","oac-alert-context",[r?.symbol,r?.exchange,r?.interval].filter(Boolean).join(" / ")),_=qo(e.document,"div"),y=qo(e.document,"p","oac-alert-help"),x=qo(e.document,"p","oac-alert-help",kt(e,"Bar close evaluates confirmed values. Intrabar touch can fire on a wick that is absent from final history.")),k=qo(e.document,"p","oac-alert-error");k.setAttribute("role","status"),v.body.append(w,_,y,x,k);const C=Ko(e.document,{label:kt(e,"Save"),variant:"primary",onClick:function(){if(p)return;try{const t=A();if(t)throw new Error(t);f={...f,...u.values()};const o=String(f.title??"").trim();if(""===o)throw new Error(kt(e,"Enter a name"));const r=f.condition,s="enteringRange"===r||"leavingRange"===r,l=Br(e,f).source,c={source:"price"===l.kind?{kind:"price",price:f.price,...s?{upperPrice:f.upperPrice}:{}}:"indicator"===l.kind?{...l,value:f.value,upperValue:s?f.upperValue:void 0}:l,condition:r,title:o,message:String(f.message??"")||void 0,policy:f.policy,repeat:f.repeat,cooldownSeconds:f.cooldownSeconds};i&&f.expiresAt===Hr(i.expiresAt,a)||(c.expiresAt=function(e,t,o){if(""===t)return;const n=kt(e,"Enter an expiry date and time");if("string"!=typeof t||!Ur.test(t))throw new Error(n);const[i,a]=t.split("T"),r=Za(i,a,o,{rejectSkipped:!0});if(null===r)throw new Error(n);return r}(e,f.expiresAt,a)),i&&!h||(c.state=f.enabled?"armed":"disabled"),i?n.update(i.id,c):n.add(c),b()}catch(t){k.textContent=t instanceof Error?t.message:kt(e,"Could not save this alert")}}});C.dataset.action="save-alert";const S=Ko(e.document,{label:kt(e,"Cancel"),onClick:b});function A(){return n?o.alertId&&!n.list().some(e=>e.id===o.alertId)?kt(e,"This alert was removed"):s(e.chart.getDataContext())!==l||i&&s(i.scope)!==l?kt(e,"The instrument context changed. Reopen the editor for the intended instrument."):Br(e,f).reason:kt(e,"Alerts are unavailable in this host")}function L(){const t=A();k.textContent=t??"",C.disabled=void 0!==t,y.textContent=Br(e,f).hint??""}S.dataset.action="cancel-alert",v.actions.append(S,C),function t(){u?.destroy();const o=Br(e,f),n=F(o.source,f.condition);for(const e of n)e.key in f||(f[e.key]=e.default);f.condition=n.find(e=>"condition"===e.key).default;const i=Ro(n,{translate:e.translate,scope:"alert"}),r=i.find(e=>"expiresAt"===e.key);r&&(r.label+=` (${a})`),u=nn(_,[...o.controls,...i],{idPrefix:m,values:f,translate:e.translate,openOverlay:e.openOverlay,preserveInvalidNumbers:!0,onChange:(o,n)=>{f={...f,...u.values(),[o]:n},"enabled"===o&&(h=!0);const i=["kind","instanceId","plotKey","drawingId","level","inputInstanceId"].includes(o);if("kind"===o)for(const e of["price","value","upperPrice","upperValue","condition"])delete f[e];if("instanceId"===o&&(delete f.plotKey,delete f.value,delete f.upperValue),"plotKey"===o&&(delete f.value,delete f.upperValue),"drawingId"===o&&(delete f.level,delete f.inputInstanceId,delete f.inputPlotKey),"inputInstanceId"===o&&delete f.inputPlotKey,"condition"===o||i){const n=null!==e.document.activeElement&&_.contains(e.document.activeElement);t(),n&&_.querySelector(`[data-key="${o}"] select`)?.focus()}L()}});const s=_.querySelector('[data-key="expiresAt"] input');s&&(s.type="datetime-local",s.step="60")}(),L();for(const t of["data:context","data:update","objects:change","alert:removed","alerts:restored"])g.push(e.chart.on(t,L));g.push(e.chart.on("destroy",b));const O=Qo(e,v.el,{anchor:t,modal:!0,placement:"center"},b);return{el:v.el,close:b,isOpen:()=>!p&&O.isOpen()}}function Jr(e,t,o={}){const n=e.alerts;let i=!1,a=!1;const r=[],s=new Map;function l(){if(!i){i=!0;for(const e of r.splice(0))e();v?.close(),o.onClose?.()}}const c=Yo(e.document,{translate:e.translate,title:kt(e,"Alerts"),className:"oac-alerts",onClose:l,closeText:!0}),d=qo(e.document,"div","oac-alerts__list");d.setAttribute("role","list"),d.setAttribute("aria-label",kt(e,"Chart alerts"));const u=qo(e.document,"p","oac-empty",kt(e,n?"No alerts. Create an alert for this chart.":"Alerts are unavailable in this host")),p=qo(e.document,"span","oac-alert-context");p.setAttribute("role","status");const h=Ko(e.document,{label:kt(e,"Create alert"),variant:"primary",onClick:()=>{Vr(e)}});h.dataset.action="create-alert",h.disabled=!n,c.body.append(d,u),c.lead.appendChild(p),c.actions.appendChild(h);const m={armed:kt(e,"Active"),triggered:kt(e,"Triggered"),expired:kt(e,"Expired"),disabled:kt(e,"Disabled")},g=(e,t,o)=>e.find(e=>e.key===t)?.options?.find(e=>e.value===o)?.label;function f(t){const o=t.source;if("price"===o.kind){const t=t=>e.chart.panes()[e.chart.primaryPaneIndex()]?.readoutScale().format(t)??String(t);return void 0===o.upperPrice?kt(e,"Price {price}",{price:t(o.price)}):kt(e,"Price {price} to {upper}",{price:t(o.price),upper:t(o.upperPrice)})}if("barCondition"===o.kind)return W(o.id)?.title??kt(e,"Unavailable candle condition");if("drawing"===o.kind){const{controls:t}=Br(e,{...o,inputInstanceId:o.input?.instanceId,inputPlotKey:o.input?.plotKey});return`${g(t,"drawingId",o.drawingId)??kt(e,"Unavailable drawing")} / ${g(t,"level",o.level)??o.level??kt(e,"Default level")}`}const n=e.chart.indicators().find(e=>e.id===o.instanceId),{controls:i}=Br(e,{kind:"indicator",instanceId:o.instanceId,plotKey:o.plotKey,value:o.value}),a=g(i,"plotKey",o.plotKey)??o.plotKey,r=n?.series(o.plotKey)?.priceScale(),s=e=>r?.format(e)??String(e);return kt(e,void 0===o.upperValue?"{name} / {plot}: {value}":"{name} / {plot}: {value} to {upper}",{name:g(i,"instanceId",o.instanceId)??kt(e,"Unavailable study"),plot:a,value:s(o.value),upper:void 0===o.upperValue?"":s(o.upperValue)})}function b(){if(!i&&!a){a=!0;try{const t=n?.list()??[],o=new Set(t.map(e=>e.id));for(const[e,t]of s)o.has(e)||(t.el.remove(),s.delete(e));for(const o of t){let t=s.get(o.id);if(!t){const i=qo(e.document,"div","oac-alerts__row");i.dataset.alertId=o.id,i.setAttribute("role","listitem");const a=qo(e.document,"div","oac-alerts__summary"),r=qo(e.document,"div","oac-alerts__status"),l=qo(e.document,"div","oac-alerts__actions"),c=Ko(e.document,{label:kt(e,"Edit"),onClick:()=>{Vr(e,void 0,{alertId:o.id})}});c.dataset.action="edit-alert";const u=Ko(e.document,{label:kt(e,"Disable"),onClick:()=>{const e=n?.list().find(e=>e.id===o.id);"armed"===e?.state?n?.disable(o.id):n?.enable(o.id)}});u.dataset.action="toggle-alert";const p=Ko(e.document,{label:kt(e,"Delete"),onClick:()=>{n?.remove(o.id)}});p.dataset.action="delete-alert",l.append(c,u,p),i.append(a,r,l),d.appendChild(i),t={el:i,summary:a,status:r,toggle:u},s.set(o.id,t)}const i=[o.scope.symbol,o.scope.exchange,o.scope.interval,_n(e,o.scope.variant)].filter(Boolean).join(" / ");t.summary.textContent=`${o.title}\n${i}\n${f(o)}`,t.el.dataset.state=o.state;const a=n.availability(o.id);t.status.textContent=[m[o.state],"onBarClose"===o.policy?kt(e,"Bar close"):kt(e,"Intrabar touch"),"once"===o.repeat?kt(e,"Once"):kt(e,"Every match"),o.cooldownSeconds?kt(e,"{seconds}s cooldown",{seconds:o.cooldownSeconds}):"",void 0===o.expiresAt?"":kt(e,"Expires {time}",{time:Hr(o.expiresAt,e.chart.timezone()).replace("T"," ")}),void 0===o.lastTriggeredAt?"":kt(e,"Last fired {time}",{time:Hr(o.lastTriggeredAt,e.chart.timezone()).replace("T"," ")}),a.available?"":a.reason].filter(Boolean).join(" / "),t.toggle.textContent="armed"===o.state?kt(e,"Disable"):kt(e,"Enable"),t.toggle.setAttribute("aria-label",kt(e,"armed"===o.state?"Disable {name}":"Enable {name}",{name:o.title})),t.toggle.disabled="armed"!==o.state&&void 0!==o.expiresAt&&o.expiresAt<=Date.now()/1e3,t.toggle.title=t.toggle.disabled?kt(e,"Edit the expiry before enabling this alert"):""}u.hidden=t.length>0,p.textContent=kt(e,1===t.length?"{count} alert":"{count} alerts",{count:t.length})}finally{a=!1}}}for(const t of["alert:created","alert:updated","alert:removed","alert:triggered","alert:expired","alerts:restored","data:context","data:update","data:range","objects:change","replay:start","replay:stop"])r.push(e.chart.on(t,b));r.push(e.chart.on("destroy",l)),b();const v=Qo(e,c.el,{anchor:t,modal:!0,placement:"center"},l);return{el:c.el,close:l,isOpen:()=>!i&&v.isOpen()}}const Yr={kind:"separator"},Zr=e=>({kind:"header",label:e}),Qr={linear:"Linear",logarithmic:"Logarithmic",percentage:"Percent","indexed-to-100":"Indexed to 100"};function Xr(e,t,o){const n=e.panes()[t];return void 0===n?String(o):n.readoutScale().format(o)}function es(e,t,o={}){const{chart:n,draw:i}=e,a=t.target,r=[],s=()=>{r.length>0&&"separator"!==r[r.length-1].kind&&r.push(Yr)};if("price-scale"===a.kind)return r.push(...function(e,t,o){const{chart:n}=e,i=()=>n.priceAxisState(t,o),a=i();if(null===a)return[];const r=[];r.push({id:"axis-autofit",label:kt(e,"Auto-fit to the data"),mark:"check",on:a.autoFit,keepOpen:!0,run:()=>{const e=i();null!==e&&n.setPriceAxisAutoFit(t,o,!e.autoFit)}});const s=()=>{const e=n.primarySeries?.();return null!=e&&e.priceScale()===n.panes()[t]?.scaleFor(o)};s()&&r.push({id:"axis-price-only",label:kt(e,"Fit primary prices only"),mark:"check",on:n.priceOnlyAutoScale(),keepOpen:!0,run:()=>{s()&&n.setPriceOnlyAutoScale(!n.priceOnlyAutoScale())}}),r.push({id:"axis-invert",label:kt(e,"Invert"),mark:"check",on:a.inverted,keepOpen:!0,run:()=>{const e=i();null!==e&&n.setPriceAxisOptions(t,o,{inverted:!e.inverted})}}),r.push({id:"axis-lock",label:kt(e,"Pin price per bar"),mark:"check",on:a.lockRatio,keepOpen:!0,disabled:!a.scaled,note:a.scaled?void 0:kt(e,"nothing measured"),run:()=>{const a=i();null!==a&&(n.setPriceAxisLockRatio(t,o,!a.lockRatio)||e.toast(kt(e,"Nothing measured on this scale yet"),"info"))}}),r.push(Yr),r.push(Zr(kt(e,"Scale")));for(const i of B)r.push({id:`axis-mode-${i}`,label:kt(e,`schema.scaleMode.${i}`,{},Qr[i]),mark:"radio",on:a.mode===i,keepOpen:!0,run:()=>{n.setPriceAxisOptions(t,o,{mode:i})}});const l=n.priceAxisPlacement(t,o),c=e=>n.priceAxisLayout(t).filter(t=>t.side===e).sort((e,t)=>e.order-t.order);if(null!==l&&"hidden"!==l.side){r.push(Yr),r.push({id:"axis-move",label:"right"===l.side?kt(e,"Move the scale to the left"):kt(e,"Move the scale to the right"),disabled:!a.active,note:a.active?void 0:kt(e,"nothing on this side"),run:()=>{const a=n.priceAxisPlacement(t,o);i()?.active&&null!==a&&"hidden"!==a.side&&(n.setPriceAxisPlacement(t,o,"right"===a.side?"left":"right")||e.toast(kt(e,"The scale could not be moved"),"info"))}});const s=c(l.side),d=s.findIndex(e=>e.scaleId===o);if(d>=0&&s.length>1)for(const a of[-1,1])r.push({id:a<0?"axis-closer":"axis-further",label:kt(e,a<0?"Move the scale closer to the plot":"Move the scale further from the plot"),disabled:void 0===s[d+a],keepOpen:!0,run:()=>{const r=n.priceAxisPlacement(t,o);if(!i()?.active||null===r||"hidden"===r.side)return;const s=c(r.side),l=s.findIndex(e=>e.scaleId===o),d=l<0?void 0:s[l+a];d&&!n.setPriceAxisPlacement(t,o,r.side,d.order)&&e.toast(kt(e,"The scale could not be moved"),"info")}})}return r.push(Yr),r.push({id:"axis-settings",label:kt(e,"Axis settings..."),icon:"settings",run:()=>{zr(e,0,{tab:"axes"})}}),r}(e,t.paneIndex,a.scaleId??a.side??"right")),r;const l=n.primaryPaneIndex(),c=o.onOrder;if(void 0!==c&&"time-scale"!==a.kind){const i=t.paneIndex===l?t.price:null,a={...e.symbol(),interval:e.interval()},s=t=>q(o.tradingCapabilities,{operation:"place",type:t,mode:o.tradingMode,...e.symbol()}),d=()=>{if(x(n))return kt(e,"Order entry is locked during replay");try{if(o.tradingLocked?.())return kt(e,"Order entry is locked by the host")}catch{return kt(e,"Order entry is unavailable")}},u=d(),p=(o,r)=>({id:`order-${o.toLowerCase()}-${r.toLowerCase()}`,icon:"BUY"===o?"buy":"sell",label:"MARKET"===r?kt(e,"BUY"===o?"Buy market":"Sell market"):kt(e,"BUY"===o?"LIMIT"===r?"Buy limit at {price}":"Buy stop at {price}":"LIMIT"===r?"Sell limit at {price}":"Sell stop at {price}",{price:Xr(n,t.paneIndex,i)}),disabled:void 0!==u,note:u,run:()=>{if(n.isDestroyed)return;const l=e.symbol();if(l.symbol!==a.symbol||l.exchange!==a.exchange||e.interval()!==a.interval)return void e.status(kt(e,"The chart changed; reopen the menu before placing an order"),"error");const u=d();if(void 0!==u)return void e.status(u,"error");const p=s(r);p.supported?c({side:o,type:r,price:"MARKET"===r?null:i,paneIndex:t.paneIndex}):e.status(kt(e,"Order entry is unavailable: {reason}",{reason:p.reason}),"error")}}),h=(null===i?["MARKET"]:["MARKET","LIMIT","SL"]).map(e=>({type:e,result:s(e)})),m=h.filter(e=>e.result.supported);if(m.length>0){r.push(Zr(kt(e,"Trade")));for(const{type:e}of m)r.push(p("BUY",e),p("SELL",e))}else{const t=h[0].result;r.push({id:"trading-unavailable",label:kt(e,"Order entry is unavailable"),disabled:!0,note:t.supported?void 0:t.reason})}}const d=function(e){if("drawing"!==e.kind||null===e.id||!e.id.startsWith("draw:"))return null;const t=e.id.slice(5),o=t.indexOf("#");return o<0?t:t.slice(0,o)}(a),u=null===d?void 0:i.get(d);if(e.alerts&&"time-scale"!==a.kind){if(s(),u){const t=i.alertInfo(u.id);r.push({id:"alert-drawing",label:kt(e,"Create drawing alert..."),icon:"bell",disabled:!t.available,note:t.reason,run:()=>{Vr(e,void 0,{source:{kind:"drawing",drawingId:u.id}})}})}else if("indicator"===a.kind&&a.instanceId){const o=n.indicators().find(e=>e.id===a.instanceId),i=o&&I(o.indicatorId).plots.find(e=>(e.overlay?l:o.paneIndex)===t.paneIndex&&(void 0===a.plotKey||e.key===a.plotKey));o&&i&&r.push({id:"alert-indicator",label:kt(e,"Create study alert..."),icon:"bell",run:()=>{const a=o.values()[i.key],r=a?.[t.index??n.primaryBars().length-1];Vr(e,void 0,{source:{kind:"indicator",instanceId:o.id,plotKey:i.key,value:r??NaN}})}})}else t.paneIndex===l&&null!==t.price&&Number.isFinite(t.price)&&r.push({id:"alert-create",label:kt(e,"Create alert at {price}...",{price:Xr(n,l,t.price)}),icon:"bell",run:()=>{Vr(e,void 0,{source:{kind:"price",price:t.price}})}});r.push({id:"chart-alerts",label:kt(e,"Alerts..."),run:()=>{Jr(e)}})}if(void 0!==u){i.selection().includes(u.id)||i.select(u.id);const t=i.selection().includes(u.id)?i.selection().slice():[u.id];s(),r.push(...function(e,t,o){const{draw:n}=e,i=ke(t.tool),a=[],r=dn(e,o),s=t=>()=>{un(e,t,o)},l=o.length>1,c=r.editable.length,d=0===c,u=r.readOnly??void 0,p=r.noDelete??void 0;return a.push({id:"draw-props",label:kt(e,l?"Properties of the selection...":"Properties..."),icon:"settings",run:()=>{fr(e,void 0,{ids:o})}}),!l&&lr(t)&&a.push({id:"draw-text",label:kt(e,"Edit text"),icon:"text",disabled:d,note:u,run:()=>{dr(e,0,{id:t.id})}}),i.fields.some(e=>"levels"===e.kind)&&a.push({id:"draw-levels",label:kt(e,"Edit levels..."),disabled:d,note:u,run:()=>{nr(e,void 0,{ids:o})}}),a.push(Yr),a.push({id:"draw-copy",label:l?kt(e,"Copy {count} drawings",{count:o.length}):kt(e,"Copy drawing"),icon:"copy",chord:ko(e.keymap,"copy","Mod+C"),run:()=>{n.copy(o)}}),a.push({id:"draw-cut",label:c>1?kt(e,"Cut {count} drawings",{count:c}):kt(e,"Cut drawing"),chord:ko(e.keymap,"cut","Mod+X"),disabled:void 0!==p,note:p,run:()=>{n.cut(o)}}),a.push({id:"draw-duplicate",label:kt(e,"Duplicate"),icon:"duplicate",chord:ko(e.keymap,"duplicate","Mod+D"),run:s("duplicate")}),a.push(Yr),a.push({id:"draw-lock",label:kt(e,"Lock"),icon:r.locked?"lock":"unlock",mark:"check",on:r.locked,disabled:d,note:u,run:s("lock")}),a.push({id:"draw-hide",label:kt(e,"Hide"),icon:r.hidden?"eye-off":"eye",mark:"check",on:r.hidden,disabled:d,note:u,run:s("visible")}),a.push(Yr),a.push(Zr(kt(e,"Order"))),a.push({id:"draw-front",label:kt(e,"Bring to front"),icon:"front",run:s("front")}),a.push({id:"draw-back",label:kt(e,"Send to back"),icon:"back",run:s("back")}),a.push({id:"draw-above",label:kt(e,"In front of the series"),icon:"above-series",mark:"radio",on:"above"===r.side,run:s("above")}),a.push({id:"draw-behind",label:kt(e,"Behind the series"),icon:"behind-series",mark:"radio",on:"behind"===r.side,run:s("behind")}),a.push(Yr),a.push({id:"draw-delete",label:c>1?kt(e,"Delete {count} drawings",{count:c}):kt(e,"Delete"),icon:"trash",chord:ko(e.keymap,"delete","Delete"),danger:!0,disabled:void 0!==p,note:p,run:s("delete")}),a}(e,u,t))}if("indicator"===a.kind&&void 0!==a.instanceId){const t=n.indicators().find(e=>e.id===a.instanceId);if(void 0!==t){s();const o=t.policy(),i=t=>!1===o[t]?kt(e,"protected"):void 0;r.push({id:"ind-settings",label:kt(e,"{name} settings...",{name:t.name}),icon:"settings",disabled:void 0!==i("configurable"),note:i("configurable"),run:()=>{Ir(e,void 0,{instanceId:t.id})}}),r.push({id:"ind-visible",label:t.visible()?kt(e,"Hide {name}",{name:t.name}):kt(e,"Show {name}",{name:t.name}),icon:t.visible()?"eye":"eye-off",run:()=>{t.setVisible(!t.visible())}}),r.push({id:"ind-remove",label:kt(e,"Remove {name}",{name:t.name}),icon:"trash",danger:!0,disabled:void 0!==i("removable"),note:i("removable"),run:()=>{n.removeIndicator(t.id)}})}}if("time-scale"!==a.kind&&!ts.has(t)){const o=n.panes().length,i=t.paneIndex;if(o>1&&i>=0&&i<o){s();const t=e=>!n.movablePrimaryPane()&&(i===l||e===l),a=(o,a,r,s,l)=>{const c=s?kt(e,l):t(i+r)?kt(e,"price pane stays on top"):void 0;return{id:o,label:kt(e,a),disabled:void 0!==c,note:c,run:()=>{n.movePane(i,r)}}};r.push(a("pane-up","Move pane up",-1,0===i,"at the top")),r.push(a("pane-down","Move pane down",1,i===o-1,"at the bottom"))}if(i!==l&&i>=0&&i<o){const t=n.paneCollapsed(i);s(),r.push({id:"pane-collapse",label:kt(e,t?"Expand pane":"Collapse pane"),run:()=>{n.setPaneCollapsed(i,!t)}})}}if("time-scale"!==a.kind){s(),r.push({id:"draw-paste",label:kt(e,"Paste"),icon:"paste",chord:ko(e.keymap,"paste","Mod+V"),run:()=>{i.paste().then(t=>{0===t.length&&e.toast(kt(e,"Nothing to paste"),"info")})}});const t=i.drawings().filter(e=>!1!==e.policy?.editable).length;t>0&&r.push({id:"draw-clear",label:kt(e,"Remove all drawings ({count})",{count:t}),icon:"trash",danger:!0,run:()=>{i.clear()}})}s(),r.push({id:"chart-fit",label:kt(e,"Fit all bars"),icon:"fit",chord:ko(e.keymap,"chart:fitContent"),disabled:!1===n.navigationOptions().zoomEnabled,run:()=>{!1!==n.navigationOptions().zoomEnabled&&n.fitContent()}}),"time-scale"!==a.kind&&r.push({id:"chart-indicators",label:kt(e,"Indicators..."),icon:"indicators",run:()=>{vr(e)}}),r.push({id:"chart-settings",label:kt(e,"Settings..."),icon:"settings",run:()=>{zr(e)}});const p=o.items?.(t)??[];return p.length>0&&(s(),r.push(...p)),r}const ts=new WeakSet;const os=new WeakMap;function ns(e,t,o={}){const n=e.document;os.get(e.root)?.close();const i=o.event??function(e){const t={paneIndex:e.primaryPaneIndex(),point:{x:0,y:0},price:null,time:null,index:null,target:{kind:"empty",id:null},preventDefault:()=>{}};return ts.add(t),t}(e.chart),a=o.hooks??{},r=qo(n,"div","oac-panel oac-ctx");r.setAttribute("role","menu"),r.setAttribute("aria-label",kt(e,"Chart menu")),r.tabIndex=-1,Vo(r);let s=[];const l=e=>{const t=s.filter(e=>"true"!==e.getAttribute("aria-disabled"));0!==t.length&&t[(e%t.length+t.length)%t.length].focus()};!function t(o=-1){r.innerHTML="",s=[];const l=es(e,i,a);for(const o of l){if("separator"===o.kind){r.appendChild(qo(n,"div","oac-ctx__hr"));continue}if("header"===o.kind){r.appendChild(qo(n,"div","oac-head",o.label));continue}const i=o,a=qo(n,"button","oac-ctx__row"+(!0===i.danger?" is-danger":""));a.type="button",a.setAttribute("role","check"===i.mark?"menuitemcheckbox":"radio"===i.mark?"menuitemradio":"menuitem"),void 0!==i.mark&&a.setAttribute("aria-checked",!0===i.on?"true":"false"),void 0!==i.id&&(a.dataset.act=i.id),a.tabIndex=-1;const l=qo(n,"span","oac-ctx__mark");if("radio"===i.mark&&!0===i.on)l.appendChild(qo(n,"span","oac-ctx__dot"));else if("check"===i.mark&&!0===i.on)l.appendChild(Ho(n,"check"));else if(void 0!==i.icon)if(i.icon.startsWith("<svg")){const e=qo(n,"span","oac-glyph oac-glyph--chrome");e.innerHTML=i.icon,l.appendChild(e)}else l.appendChild(Ho(n,i.icon));if(a.appendChild(l),a.appendChild(qo(n,"span","oac-ctx__label",i.label)),void 0!==i.note&&""!==i.note&&a.appendChild(qo(n,"span","oac-ctx__note",i.note)),void 0!==i.chord){a.appendChild(qo(n,"kbd","oac-ctx__key",i.chord)).setAttribute("aria-hidden","true"),a.setAttribute("aria-keyshortcuts",xo(i.chord))}!0===i.disabled?a.setAttribute("aria-disabled","true"):a.addEventListener("click",o=>{o.stopPropagation(),void 0!==i.run&&pt(e,i.id,i.run),!0===i.keepOpen?t(s.indexOf(a)):d.close()}),r.appendChild(a),s.push(a)}o>=0&&void 0!==s[o]&&s[o].focus()}(),r.addEventListener("keydown",e=>{const t=e.key,o=s.filter(e=>"true"!==e.getAttribute("aria-disabled")),i=o.indexOf(n.activeElement);"ArrowDown"===t?(e.preventDefault(),l(i+1)):"ArrowUp"===t?(e.preventDefault(),l(i<=0?o.length-1:i-1)):"Home"===t?(e.preventDefault(),l(0)):"End"===t&&(e.preventDefault(),l(o.length-1))});const c=s.find(e=>"true"!==e.getAttribute("aria-disabled"))??r,d=Qo(e,r,void 0!==t&&void 0===o.event?{anchor:t,placement:"below",initialFocus:c}:{placement:"below",modal:!1,dismissOnOutside:!0,initialFocus:c},()=>{});if(void 0===t||void 0!==o.event){const t=sr(e.chart),o=null===t?{left:0,top:0}:et(e.root,t);tn(e.root,r,{point:{x:i.point.x+o.left,y:i.point.y+o.top}})}return os.set(e.root,d),d}function is(e,t={}){return e.chart.on("contextmenu",o=>{const n=o;n.preventDefault(),ns(e,void 0,{event:n,hooks:t})})}const as={settings:zr,indicatorPicker:vr,indicatorSettings:Ir,drawingProperties:fr,contextMenu:ns,levelEditor:nr,textEditor:dr,alertEditor:Vr,alerts:Jr};bt(as);const rs=`\n.oac-widget .oac-alert-editor { width: 480px; }\n.oac-widget .oac-alerts { width: 560px; }\n.oac-widget .oac-alerts__row { padding: 10px 0; border-bottom: 1px solid ${Ia("bd-soft")}; }\n.oac-widget .oac-alerts__summary { white-space: pre-line; overflow-wrap: anywhere; line-height: 1.5; }\n.oac-widget .oac-alerts__status { color: ${Ia("mut")}; font-size: 11px; line-height: 1.5; margin: 4px 0 8px; overflow-wrap: anywhere; }\n.oac-widget .oac-alerts__actions { display: flex; flex-wrap: wrap; gap: 6px; }\n.oac-widget .oac-alert-context { margin: 0 0 8px; color: ${Ia("mut")}; overflow-wrap: anywhere; }\n.oac-widget .oac-alert-help { color: ${Ia("mut")}; font-size: 11px; line-height: 1.5; margin: 10px 0 0; }\n.oac-widget .oac-alert-error { color: ${Ia("danger")}; font-size: 12px; margin: 6px 0 0; overflow-wrap: anywhere; }\n.oac-widget .oac-alert-editor input[type=datetime-local] { width: 100%; min-width: 0; color-scheme: inherit;\n height: ${Ia("ctl-h")}; padding: 0 8px; border: 1px solid ${Ia("bd")}; border-radius: ${Ia("radius")};\n background: ${Ia("elev")}; color: ${Ia("tx")}; font: inherit; }\n/* Panels: the card a dialog or a popover is built on. */\n.oac-widget .oac-panel { display: flex; flex-direction: column; min-width: 0; max-width: calc(100% - 24px);\n max-height: calc(100% - 24px); background: ${Ia("panel")}; border: 1px solid ${Ia("bd")}; border-radius: 12px;\n box-shadow: ${Ia("shadow")}; outline: none; }\n.oac-widget .oac-dialog__lead, .oac-widget .oac-dialog__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; max-width: 100%; }\n.oac-widget .oac-dialog__actions .oac-btn:not(.oac-btn--primary) { border-color: ${Ia("bd-soft")}; }\n.oac-widget .oac-empty { padding: 10px 6px; color: ${Ia("faint")}; }\n\n/* Generated forms: switch column, label, control column. */\n.oac-widget .oac-form { min-width: 0; display: grid; gap: 1px; align-content: start; }\n.oac-widget .oac-form > .oac-head { padding: 10px 0 3px; }\n.oac-widget .oac-form > .oac-head:first-child { padding-top: 2px; }\n.oac-widget .oac-form .oac-row { gap: 8px; min-height: 30px; padding: 1px 0; }\n.oac-widget .oac-row__sw { width: 15px; flex: none; }\n.oac-widget .oac-row__label { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; color: ${Ia("mut")}; cursor: pointer; }\n/* Every row's control occupies the same column, and the column is one width.\n It was not: a select filled it, a lone number sat at 72px against its right\n edge, and one row widened the column for itself. Reading down the form, the\n left edge of the controls stepped in and out by ninety pixels, which is the\n kind of wrongness a reader feels before they can name it. The column is wide\n enough for a date and time, which is the widest control any of these forms\n puts in it. */\n.oac-widget .oac-row__ctl { display: flex; align-items: center; justify-content: flex-end; gap: 6px; width: min(232px, 58%); min-width: 0; flex: none; }\n/* A number that is the only thing in its column fills it like every other\n control, keeping its digits right aligned. One paired with a slider keeps\n its own width, because there the narrow box is the point. */\n.oac-widget .oac-row__ctl input[type=number] { width: 72px; max-width: 100%; min-width: 0; text-align: right; font-variant-numeric: tabular-nums; }\n.oac-widget .oac-row__ctl > input[type=number]:only-child { width: 100%; }\n.oac-widget .oac-row__ctl input[type=text] { width: 100%; min-width: 0; }\n.oac-widget .oac-row__ctl .oac-select, .oac-widget .oac-row__ctl select { width: 100%; min-width: 0; max-width: 100%; }\n.oac-widget .oac-opacity { min-width: 0; max-width: 100%; display: inline-flex; align-items: center; gap: 6px; }\n.oac-widget .oac-opacity input[type=range] { width: 110px; min-width: 0; }\n.oac-widget .oac-out { min-width: 36px; text-align: right; color: ${Ia("mut")}; font-variant-numeric: tabular-nums; }\n.oac-widget .oac-row--block { flex-direction: column; align-items: stretch; gap: 4px; }\n.oac-widget .oac-row--block > .oac-row__ctl { width: 100%; }\n.oac-widget .oac-row--block > .oac-row__label { padding-top: 4px; }\n.oac-widget .oac-row--block textarea { width: 100%; min-height: 56px; resize: vertical; }\n.oac-widget .oac-row--off > .oac-row__label { color: ${Ia("faint")}; cursor: not-allowed; }\n.oac-widget .oac-row input:disabled, .oac-widget .oac-row select:disabled { opacity: .45; pointer-events: none; }\n/* Inline rows: the lead label, then each member's own label and control. The\n control column takes what the label leaves and wraps inside itself, so a\n narrow panel stacks the members rather than scrolling sideways. */\n.oac-widget .oac-row--inline { flex-wrap: wrap; row-gap: 4px; }\n.oac-widget .oac-row--inline > .oac-row__label { flex: 0 1 auto; }\n.oac-widget .oac-row--inline > .oac-row__ctl { width: auto; flex: 1 1 0; min-width: min(100%, 150px); flex-wrap: wrap; row-gap: 4px; }\n.oac-widget .oac-inline__item { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }\n.oac-widget .oac-inline__label { color: ${Ia("mut")}; white-space: nowrap; cursor: pointer; }\n.oac-widget .oac-inline__item--off > .oac-inline__label { color: ${Ia("faint")}; cursor: not-allowed; }\n.oac-widget .oac-row--inline .oac-select, .oac-widget .oac-row--inline select { width: auto; }\n.oac-widget .oac-row--inline input[type=text] { width: 96px; }\n\n/* Tab lists: a rail down the left of a settings dialog, or a row above a form. */\n.oac-widget .oac-tabs { min-width: 0; display: flex; gap: 2px; }\n.oac-widget .oac-tabs--rail { flex-direction: column; min-width: 138px; padding: 2px 10px 2px 0; border-right: 1px solid ${Ia("bd-soft")}; }\n.oac-widget .oac-tabs--row { overflow-x: auto; flex: none; padding: 0 0 6px; margin-bottom: 6px; border-bottom: 1px solid ${Ia("bd-soft")}; }\n.oac-widget .oac-tab { flex: none; display: flex; align-items: center; gap: 9px; height: 30px; padding: 0 10px; background: transparent;\n border: 1px solid transparent; border-radius: 7px; color: ${Ia("mut")}; text-align: left; white-space: nowrap; }\n.oac-widget .oac-tab:hover { background: ${Ia("elev")}; color: ${Ia("tx")}; }\n.oac-widget .oac-tab[aria-selected="true"] { background: ${Ia("on-bg")}; border-color: ${Ia("on-bd")}; color: ${Ia("acc-2")}; }\n.oac-widget .oac-tabs--row .oac-tab { height: 28px; border-radius: 6px; }\n\n/* Chart settings and indicator settings */\n.oac-widget .oac-settings { width: 600px; }\n.oac-widget .oac-settings__main { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0 12px; min-height: 0; }\n.oac-widget .oac-settings__pane { min-width: 0; min-height: 0; padding: 2px 4px 4px 0; }\n.oac-widget .oac-indset { width: 440px; }\n.oac-widget .oac-indset__pane { min-width: 0; padding-right: 4px; }\n\n/* Indicator picker */\n.oac-widget .oac-pick { width: 380px; }\n.oac-widget .oac-pick__findwrap { padding: 2px 0 8px; }\n.oac-widget .oac-pick__find { width: 100%; }\n.oac-widget .oac-pick__list { min-height: 0; display: grid; gap: 1px; align-content: start; }\n.oac-widget .oac-pick__list > .oac-head { padding: 8px 8px 3px; }\n.oac-widget .oac-pick__row { display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px 8px; background: transparent;\n border: 0; border-radius: 6px; color: ${Ia("tx")}; text-align: left; }\n.oac-widget .oac-pick__row:hover, .oac-widget .oac-pick__row.is-active { background: ${Ia("elev-2")}; }\n.oac-widget .oac-pick__name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.oac-widget .oac-pick__count { color: ${Ia("acc-2")}; font-size: 11px; }\n\n/* Level editor */\n.oac-widget .oac-levels { width: 340px; min-width: 0; padding: 10px 12px 12px; gap: 6px; }\n.oac-widget .oac-levels__head { flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }\n.oac-widget .oac-levels__title { flex: 1 1 auto; font-weight: 650; color: ${Ia("tx-strong")}; }\n.oac-widget .oac-levels__labels { display: inline-flex; align-items: center; gap: 6px; color: ${Ia("mut")}; cursor: pointer; }\n.oac-widget .oac-levels__rows { min-height: 0; overflow-y: auto; display: grid; gap: 3px; }\n.oac-widget .oac-levels__row { display: grid; grid-template-columns: 15px minmax(48px, 74px) 26px minmax(0, 1fr) 24px; align-items: center; gap: 6px; min-height: 28px; }\n.oac-widget .oac-levels__row input[type=number], .oac-widget .oac-levels__row input[type=text] { width: 100%; height: 26px; }\n.oac-widget .oac-levels__row.is-off input:not([type=checkbox]) { opacity: .45; }\n.oac-widget .oac-levels__x { width: 24px; height: 24px; display: grid; place-items: center; padding: 0; background: transparent;\n border: 0; border-radius: 5px; color: ${Ia("faint")}; }\n.oac-widget .oac-levels__x:hover { background: ${Ia("elev-2")}; color: ${Ia("danger")}; }\n/* A row's remove cross stays a size under the panel's close, so the two do not read as one control. */\n.oac-widget .oac-levels__x > .oac-glyph > svg { width: 12px; height: 12px; }\n.oac-widget .oac-levels__foot { flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 4px; }\n.oac-widget .oac-levels__foot .oac-spacer { flex: 1 1 auto; }\n\n/* Inline text editor, laid over the painted text. */\n.oac-widget .oac-textedit { position: absolute; z-index: 70; box-sizing: border-box; margin: 0; outline: none; padding: 4px;\n border: 1px solid ${Ia("acc")}; border-radius: 4px; background: color-mix(in srgb, ${Ia("bg")} 58%, transparent);\n box-shadow: 0 0 0 3px ${Ia("ring-soft")}; caret-color: ${Ia("acc-2")}; cursor: text; overflow: hidden; }\n\n/* Drawing properties */\n.oac-widget .oac-props { width: 340px; }\n.oac-widget .oac-props__tools { flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: 2px; padding: 0 10px 6px; }\n.oac-widget .oac-props__tools .oac-sep { margin: 0 4px; }\n.oac-widget .oac-props__pane { min-width: 0; padding-right: 4px; }\n.oac-widget .oac-props__inline { display: inline-flex; align-items: center; gap: 6px; }\n\n/* Context menu */\n.oac-widget .oac-ctx { min-width: 220px; max-width: 320px; padding: 5px; }\n.oac-widget .oac-ctx > .oac-head { padding: 6px 10px 2px; }\n.oac-widget .oac-ctx__row { display: flex; align-items: center; gap: 8px; width: 100%; padding: 5px 8px; background: transparent;\n border: 0; border-radius: 6px; color: ${Ia("tx")}; text-align: left; white-space: nowrap; }\n.oac-widget .oac-ctx__row:hover, .oac-widget .oac-ctx__row:focus-visible { background: ${Ia("elev-2")}; outline: none; }\n.oac-widget .oac-ctx__row:is(:hover, :focus-visible) :is(.oac-ctx__note, .oac-ctx__key) { color: ${Ia("mut")}; }\n.oac-widget .oac-ctx__row[aria-disabled="true"] { color: ${Ia("faint")}; cursor: default; background: transparent; }\n.oac-widget .oac-ctx__row.is-danger:not([aria-disabled="true"]):hover { color: ${Ia("danger")}; }\n.oac-widget .oac-ctx__row[aria-checked="true"] { color: ${Ia("acc-2")}; }\n.oac-widget .oac-ctx__mark { width: 16px; height: 16px; display: inline-grid; place-items: center; flex: none; color: ${Ia("mut")}; }\n.oac-widget .oac-ctx__row[aria-checked="true"] .oac-ctx__mark { color: ${Ia("acc-2")}; }\n.oac-widget .oac-ctx__dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }\n.oac-widget .oac-ctx__label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }\n.oac-widget .oac-ctx__note { color: ${Ia("faint")}; font-size: 11px; }\n.oac-widget .oac-ctx__key { margin-left: 8px; color: ${Ia("faint")}; }\n.oac-widget .oac-ctx__hr { height: 1px; background: ${Ia("bd-soft")}; margin: 4px 6px; }\n\n@container oac-widget (max-width: 720px) {\n .oac-widget .oac-settings__main { grid-template-columns: 1fr; }\n .oac-widget .oac-tabs--rail { flex-direction: row; overflow-x: auto; min-width: 0; padding: 0 0 6px; border-right: 0;\n border-bottom: 1px solid ${Ia("bd-soft")}; }\n .oac-widget .oac-dialog__foot { gap: 6px; }\n .oac-widget .oac-dialog__foot > .oac-spacer { display: none; }\n .oac-widget .oac-dialog__actions { margin-left: auto; }\n}\n`;let ss=0;function ls(e,t,o){switch(t.status){case"partial":return t.clipped?kt(e,"The range is wider than the chart. Showing {from} to {to}",o):"exhausted"===t.history?kt(e,"History starts at {date}",{date:o.from}):"limited"===t.history?kt(e,"The history limit stops at {date}",{date:o.from}):"empty"===t.history?kt(e,"No older bars were found before {date}",{date:o.from}):kt(e,"Older history cannot load now. Showing from {date}",{date:o.from});case"unsupported":return kt(e,"Go to needs a time-based interval");case"error":return kt(e,"Could not load history: {error}",{error:t.error?.message??""});default:return null}}function cs(e,t,o){const n=e.document,i=e.chart,a=i.timezone(),r=e.interval(),s=Fn(r),l="interval"===s?.mode&&s.seconds<86400,c=new Intl.DateTimeFormat(e.locale,{timeZone:a,dateStyle:"medium",...l?{timeStyle:"short"}:{}}),d=e=>c.format(new Date(1e3*e));let u=!1,p=!1,h=!1,m=0,g=null;const f="oac-goto-"+ ++ss,b=Yo(n,{translate:e.translate,title:kt(e,"Go to"),className:"oac-goto",onClose:D}),v=qo(n,"div","oac-goto__modes");v.setAttribute("role","group"),v.setAttribute("aria-label",kt(e,"Go to"));const w=(e,t)=>{const o=Ko(n,{label:t,onClick:()=>P("range"===e)});return o.dataset.mode=e,v.appendChild(o),o},_=w("date",kt(e,"Date")),y=w("range",kt(e,"Range")),x=e=>{const t=qo(n,"div","oac-goto__row"),o=qo(n,"label","oac-goto__label");o.htmlFor=`${f}-${e}`;const i=qo(n,"input");i.type="date",i.id=`${f}-${e}`;const a=qo(n,"input");return a.type="time",a.hidden=!l,t.append(o,i,a),{row:t,label:o,date:i,time:a}},k=x("from"),C=x("to");l||b.el.classList.add("oac-goto--days");const S=qo(n,"p","oac-goto__hint",kt(e,l?"Times are in {zone}. A blank time is the start of the day, or its end for To.":"Dates are in {zone}.",{zone:a})),A=qo(n,"p","oac-goto__message");A.setAttribute("role","status"),A.setAttribute("aria-live","polite"),b.body.append(v,k.row,C.row,S,A);const L=Ko(n,{label:kt(e,"Go"),variant:"primary",onClick:()=>{M()}});L.dataset.action="go-to",b.actions.appendChild(L);for(const e of[k.date,k.time,C.date,C.time])e.addEventListener("keydown",e=>{"Enter"===e.key&&(e.preventDefault(),M())}),e.addEventListener("input",()=>{A.textContent=""});const O=i.getVisibleLogicalRange(),$=[i.dataLayer.indexToTime(Math.max(0,Math.ceil(O.from))),i.dataLayer.indexToTime(Math.min(i.dataLayer.length-1,Math.floor(O.to)))],E=(e,t)=>{if(void 0===t)return;const o=Ya(t,a,!1);e.date.value=o.date,e.time.value=l?o.time:""},T=o.pending;function P(t){u=t,C.row.hidden=!t,k.label.textContent=kt(e,t?"From":"Date"),C.label.textContent=kt(e,"To"),k.time.setAttribute("aria-label",kt(e,t?"From time":"Time")),C.time.setAttribute("aria-label",kt(e,"To time")),_.setAttribute("aria-pressed",String(!t)),y.setAttribute("aria-pressed",String(t)),A.textContent=""}function j(e,t){return Za(e.date.value,e.time.value,a,t?{blank:"end",end:!0}:{blank:"start"})}async function M(){if(p)return;const t=j(k,!1),n=u?j(C,!0):void 0;if(null===t||null===n)return void(A.textContent=kt(e,"Enter a valid date"));if(void 0!==n&&n<t)return void(A.textContent=kt(e,"The end must not be before the start"));const i=void 0===n?{from:t}:{from:t,to:n};await I(i,o.navigate(i))}async function I(t,o){const n=++m;let i;A.textContent=kt(e,"Loading history"),L.disabled=h=!0;try{i=await o}finally{n===m&&(L.disabled=h=!1)}if(p||n!==m)return;if("cancelled"===i.status)return void(A.textContent="");const a=function(t,o){const n={from:d(t.from??o.from),to:d(t.to??o.to??o.from)};switch(t.status){case"placed":return u?kt(e,"Showing {from} to {to}",n):kt(e,"Showing {date}",{date:n.from});case"no-data":return void 0===o.to?kt(e,"No bars at or after {date}",{date:d(o.from)}):kt(e,"No bars between {from} and {to}",{from:d(o.from),to:d(o.to)});case"invalid":return kt(e,"Enter a valid date");default:return ls(e,t,n)??""}}(i,t),r="error"===i.status||"unsupported"===i.status;e.status(a,r?"error":"info"),"placed"===i.status?D():A.textContent=a}function D(){if(!p){p=!0;for(const e of z)e();g?.close(),o.onClose?.(),h&&Promise.resolve().then(()=>{i.isDestroyed||o.cancel?.()})}}E(k,T?.target.from??$[0]),E(C,void 0===T?$[1]:T.target.to??T.target.from),P(void 0!==T?.target.to);const z=[i.on("destroy",D),i.on("timezone:changed",D),i.on("data:context",()=>{e.interval()!==r&&D()})];return g=Qo(e,b.el,{anchor:t,placement:"below",initialFocus:k.date},D),p?g.close():void 0!==T&&I(T.target,T.result),{el:b.el,close:D,isOpen:()=>!p&&g.isOpen()}}const ds=`\n.oac-widget .oac-goto { width: 340px; }\n.oac-widget .oac-goto__modes { display: flex; gap: 4px; margin-bottom: 10px; }\n.oac-widget .oac-goto__row { display: grid; grid-template-columns: 44px minmax(0, 1fr) 96px; align-items: center; gap: 6px; margin: 0 0 6px; }\n.oac-widget .oac-goto--days .oac-goto__row { grid-template-columns: 44px minmax(0, 1fr); }\n.oac-widget .oac-goto__label { color: ${Ia("mut")}; font-size: 12px; }\n.oac-widget .oac-goto input[type=date], .oac-widget .oac-goto input[type=time] { min-width: 0; height: ${Ia("ctl-h")}; padding: 0 6px;\n border: 1px solid ${Ia("bd")}; border-radius: ${Ia("radius")}; background: ${Ia("elev")}; color: ${Ia("tx")}; color-scheme: inherit; }\n.oac-widget .oac-goto__hint { margin: 4px 0 0; color: ${Ia("faint")}; font-size: 11px; line-height: 1.4; }\n.oac-widget .oac-goto__message { min-height: 16px; margin: 6px 0 0; color: ${Ia("mut")}; font-size: 12px; overflow-wrap: anywhere; }\n`,us=86400,ps=e=>Object.freeze({...e}),hs=Object.freeze([ps({id:"1D",label:"1D",interval:"1m",unit:"session",count:1}),ps({id:"5D",label:"5D",interval:"5m",unit:"session",count:5}),ps({id:"1M",label:"1M",interval:"30m",unit:"month",count:1}),ps({id:"3M",label:"3M",interval:"1h",unit:"month",count:3}),ps({id:"6M",label:"6M",interval:"1d",unit:"month",count:6}),ps({id:"YTD",label:"YTD",interval:"1d",unit:"ytd"}),ps({id:"1Y",label:"1Y",interval:"1d",unit:"year",count:1}),ps({id:"5Y",label:"5Y",interval:"1w",unit:"year",count:5}),ps({id:"ALL",label:"All",interval:"1w",unit:"all"})]);function ms(t){const o=e(t);if(null===o)return null;const n=o.bucketing;if("interval"===n.mode)return n.seconds;if("calendar"!==n.mode)return null;return 30.44*(("year"===n.unit?12:"quarter"===n.unit?3:1)*Math.max(1,Math.floor(n.count??1)))*us}function gs(e,t){if(t.includes(e.interval))return e.interval;const o=ms(e.interval);if(null===o)return e.interval;let n=null,i=1/0,a=0;for(const e of t){const t=ms(e);if(null===t)continue;const r=Math.abs(Math.log(t/o));(r<i-1e-9||Math.abs(r-i)<=1e-9&&t>a)&&(n=e,i=r,a=t)}return n??e.interval}function fs(e,t){for(let o=1;o<=21;o++){let n=e.sessionFrom(t-o*us);if(null===n)return null;if(!(n.open>=t)){for(let o=e.sessionFrom(n.close);null!==o&&o.open<t&&o.open>n.open;o=e.sessionFrom(o.close))n=o;return n}}return null}function bs(e,t,o){const n=v(e,t);return M(n.year,n.month,n.day-o,0,0,0,t)}function vs(e,t,o){const n=v(e,t),i=new Date(Date.UTC(n.year,n.month-1-o,1)),a=i.getUTCFullYear(),r=i.getUTCMonth()+1,s=new Date(Date.UTC(a,r,0)).getUTCDate();return M(a,r,Math.min(n.day,s),0,0,0,t)}function ws(e,t){const o=t.end,n=t.zone??U,i=void 0!==t.bars&&t.bars.length>0?t.bars:null,a=Math.max(1,Math.min(400,Math.floor(e.count??1)));let r;switch(e.unit){case"session":{let e=null;if(t.calendar)try{e=function(e,t,o){let n=e.sessionFrom(t);if((null===n||n.open>t)&&(n=fs(e,t)),null===n)return null;let i=n.date,a=n.open,r=1;for(let t=0;t<12*o+12;t++){const t=fs(e,a);if(null===t)break;if(t.date!==i){if(r>=o)break;r++,i=t.date,a=t.open}else a=t.open}if(e.phaseSpans)try{const t=e.phaseSpans(a-us,a),o=t[t.length-1];void 0!==o&&"pre"===o.phase&&o.end===a&&(a=o.start)}catch{}return a}(t.calendar,o,a)}catch{e=null}r=e??(null!==i?function(e,t,o){let n=0,i=NaN,a=e[e.length-1].time;for(let r=e.length-1;r>=0;r--){const s=bs(e[r].time,t,0);if(s!==i){if(n===o)break;n++,i=s}a=e[r].time}return a}(i,n,a):function(e,t,o){let n=0;for(let i=o,a=v(e,t).weekday;i>0;)n++,a=(a+6)%7,0!==a&&6!==a&&i--;return bs(e,t,n)}(o,n,a));break}case"month":r=vs(o,n,a);break;case"year":r=vs(o,n,12*a);break;case"ytd":{const e=v(o,n);r=M(e.year,1,1,0,0,0,n);break}default:r=null!==i?i[0].time:vs(o,n,360)}return{from:Math.min(r,o),to:o}}const _s=28,ys=[{id:"auto",icon:"scale-auto",key:"schema.ui.bottombar.auto",label:"Auto-fit to the data"},{id:"log",icon:"scale-log",key:"schema.ui.bottombar.log",label:"Logarithmic scale"},{id:"percent",icon:"scale-percent",key:"schema.ui.bottombar.percent",label:"Percent scale"}];function xs(e){const t=function(e){if(e.isDestroyed)return null;const t=e.primaryPaneIndex(),o=e.panes()[t];if(void 0===o)return null;const n=e.primarySeries();for(const e of["right","left"])if(null!==n&&n.priceScale()===o.scaleFor(e))return{pane:t,id:e};return{pane:t,id:"right"}}(e),o=null===t?null:e.priceAxisState(t.pane,t.id);return null!==t&&null!==o&&o.active?{state:o,...t}:null}function ks(e,t){const o=Math.max(1,Math.floor(t.count??1));switch(t.unit){case"session":return 1===o?kt(e,"schema.ui.rangeSpan.session",{},"One trading session"):kt(e,"schema.ui.rangeSpan.sessions",{count:o},"{count} trading sessions");case"month":return 1===o?kt(e,"schema.ui.rangeSpan.month",{},"One month"):kt(e,"schema.ui.rangeSpan.months",{count:o},"{count} months");case"year":return 1===o?kt(e,"schema.ui.rangeSpan.year",{},"One year"):kt(e,"schema.ui.rangeSpan.years",{count:o},"{count} years");case"ytd":return kt(e,"schema.ui.rangeSpan.ytd",{},"Year to date");default:return kt(e,"schema.ui.rangeSpan.all",{},"All history")}}function Cs(e,t,o={}){const n=e.document,i=()=>(o.now??Date.now)()/1e3,a=o.ranges??hs,r=()=>o.target?o.target():e.chart?{chart:e.chart}:null,s=()=>{if(p)return null;const e=r()?.chart??null;return null===e||e.isDestroyed?null:e},l=new Set,c=()=>{for(const e of Array.from(l))try{e()}catch{}},d=()=>{z(),c()},u=new Ln;let p=!1,h=0;const m={ranges:()=>r()?.setRange?a:[],range:()=>r()?.range?.()??null,setRange:t=>{const o=p?null:r(),n=a.find(e=>e.id===t);if(void 0===o?.setRange||void 0===n||o.chart.isDestroyed)return;const i=++h;let s;try{s=o.setRange(t)}catch(t){return void e.status(kt(e,"Could not load history: {error}",{error:Ct(e,t)}),"error")}d(),Promise.resolve(s).then(t=>{if(p||i!==h||!t||"cancelled"===t.status)return;const a=function(e,t,o,n){const i=t.timezone(),a=t.primaryBars().length>1&&t.primaryBars()[1].time-t.primaryBars()[0].time<86400;let r;try{r=new Intl.DateTimeFormat(e.locale,{timeZone:i,dateStyle:"medium",...a?{timeStyle:"short"}:{}})}catch{r=new Intl.DateTimeFormat(void 0,{timeZone:i,dateStyle:"medium"})}const s=e=>void 0===e?"":r.format(new Date(1e3*e)),l={range:o,from:s(n.from),to:s(n.to)};switch(n.status){case"placed":return kt(e,"schema.ui.rangeResult.placed",l,"{range}: {from} to {to}");case"no-data":return kt(e,"schema.ui.rangeResult.empty",{range:o},"No bars for {range}");default:return ls(e,n,l)??""}}(e,o.chart,n.label,t);""!==a&&e.status(a,"error"===t.status||"unsupported"===t.status?"error":"info"),d()},t=>{p||i!==h||e.status(kt(e,"Could not load history: {error}",{error:Ct(e,t)}),"error")})},marketStatus:()=>{const t=s();if(null===t||!On(t))return null;const o=i(),n=u.read(t.dataLayer.sessionCalendar,o);return null===n?null:An(e,n,o,t.timezone())},clock:()=>{const e=s();if(null===e)return"";const t=i();return`${Cn(t,e.timezone(),!1)} ${kn(t,e.timezone())}`},timezone:()=>s()?.timezone()??"",timezones:()=>{const e=s();if(null===e)return[];const t=o.timezones?[...o.timezones]:function(e){try{for(const t of N(e)){const e=t.inputs.find(e=>"time.timezone"===e.key),o=e?.options;if(o)return o.map(e=>String(e.value))}}catch{}return[e.timezone()]}(e);return t.includes(e.timezone())||t.push(e.timezone()),t},setTimezone:t=>{const n=s();if(null!==n&&t!==n.timezone()){try{n.setTimezone(t)}catch{return void e.status(kt(e,"schema.ui.bottombar.badZone",{zone:t},"Unknown timezone: {zone}"),"error")}o.onTimezone?.(t),d()}},scale:()=>{const e=s(),t=null===e?null:xs(e);return null===t?null:{auto:t.state.autoFit,log:"logarithmic"===t.state.mode,percent:"percentage"===t.state.mode}},toggleScale:e=>{const t=s(),o=null===t?null:xs(t);if(null!==t&&null!==o){if("auto"===e)t.setPriceAxisAutoFit(o.pane,o.id,!o.state.autoFit);else{const n="log"===e?"logarithmic":"percentage";t.setPriceAxisOptions(o.pane,o.id,{mode:o.state.mode===n?"linear":n})}d()}},subscribe:e=>(l.add(e),()=>{l.delete(e)})};t.classList.add("oac-bottombar"),t.setAttribute("role","toolbar"),t.setAttribute("aria-label",kt(e,"schema.ui.bottombar.label",{},"Range, time and scale"));const g=e=>{e.stopPropagation()};t.addEventListener("pointerdown",g);const f=(e,t)=>Ke(n,"button",e,{type:"button","aria-label":t}),b=(e,t)=>{e.getAttribute("aria-disabled")!==String(t)&&e.setAttribute("aria-disabled",String(t))},v=(e,t)=>{e.textContent!==t&&(e.textContent=t)},w=new Map;if(a.length>0){const o=Ke(n,"div","oac-bottombar__group oac-bottombar__ranges",{role:"group","aria-label":kt(e,"schema.ui.bottombar.ranges",{},"Range")});for(const t of a){const n=kt(e,`schema.ui.range.${t.id}`,{},t.label),i=kt(e,"schema.ui.rangeName",{range:n},"Range {range}"),a=f("oac-bottombar__range",i);a.textContent=n,a.dataset.range=t.id,a.setAttribute("aria-pressed","false"),e.tips.attach(a,()=>({title:i,sub:r()?.setRange?ks(e,t):kt(e,"schema.ui.bottombar.noRanges",{},"This chart takes no preset ranges"),side:"top"})),a.addEventListener("click",()=>{"true"!==a.getAttribute("aria-disabled")&&m.setRange(t.id)}),o.appendChild(a),w.set(t.id,a)}o.addEventListener("focusin",e=>{e.target.scrollIntoView?.({block:"nearest",inline:"nearest"})}),t.appendChild(o)}let _=null;if(o.onGoTo){a.length>0&&t.appendChild(Ke(n,"span","oac-sep",{role:"separator"}));const i=f("oac-bottombar__goto",kt(e,"Go to"));i.appendChild(Ge(n,ie("calendar"),"chrome"));const r=Ke(n,"span");r.textContent=kt(e,"Go to"),i.appendChild(r),i.setAttribute("aria-haspopup","dialog"),e.tips.attach(i,()=>({title:kt(e,"Go to"),sub:null===Fn(T())?kt(e,"Go to needs a time-based interval"):void 0,side:"top"})),i.addEventListener("click",()=>{"true"!==i.getAttribute("aria-disabled")&&o.onGoTo?.(i)}),t.appendChild(i),_=i}t.appendChild(Ke(n,"span","oac-bottombar__spacer"));const y=Ke(n,"span","oac-bottombar__status",{role:"status"}),x=Ke(n,"span","oac-bottombar__phase"),k=Ke(n,"b"),C=Ke(n,"span","oac-bottombar__detail");y.append(x,k,C),y.hidden=!0,t.appendChild(y);const S=Ke(n,"span","oac-sep",{role:"separator"});S.hidden=!0,t.appendChild(S);const A=f("oac-bottombar__clock",kt(e,"schema.ui.bottombar.timezone",{zone:""},"Timezone: {zone}")),L=Ke(n,"span","oac-bottombar__time"),O=Ke(n,"small");A.append(L,O),A.setAttribute("aria-haspopup","menu"),e.tips.attach(A,()=>({title:kt(e,"schema.ui.bottombar.timezone",{zone:m.timezone()},"Timezone: {zone}"),sub:kt(e,"schema.ui.bottombar.timezoneHint",{},"The zone the time axis and the sessions are read in"),side:"top"})),A.addEventListener("click",()=>function(t){const o=s();if(null===o)return;const n=o.timezone(),a=i(),r=m.timezones(),l=e=>{let t="";try{t=kn(a,e)}catch{}return{label:e,sub:t,on:e===n,onSelect:()=>m.setTimezone(e)}},c=function(){const e=Intl;try{return e.supportedValuesOf?.("timeZone")??[]}catch{return[]}}().filter(e=>!r.includes(e)),d=[...r.map(l)];c.length>0&&d.push(kt(e,"schema.ui.bottombar.allZones",{},"All zones"),...c.map(l));P=rn(e,t,d,{find:kt(e,"schema.ui.bottombar.findZone",{},"Find a zone"),ariaLabel:kt(e,"schema.ui.bottombar.timezones",{},"Timezone")})}(A)),t.appendChild(A),t.appendChild(Ke(n,"span","oac-sep",{role:"separator"}));const $=Ke(n,"div","oac-bottombar__group oac-bottombar__scale",{role:"group","aria-label":kt(e,"schema.ui.bottombar.scale",{},"Price scale")}),E=new Map;for(const t of ys){const o=kt(e,t.key,{},t.label),i=f("oac-bottombar__icon",o);i.dataset.scale=t.id,i.setAttribute("aria-pressed","false"),i.appendChild(Ge(n,ie(t.icon),"chrome")),e.tips.attach(i,()=>({title:o,sub:null===m.scale()?kt(e,"schema.ui.bottombar.noScale",{},"Nothing is plotted on the price scale yet"):void 0,side:"top"})),i.addEventListener("click",()=>{"true"!==i.getAttribute("aria-disabled")&&m.toggleScale(t.id)}),$.appendChild(i),E.set(t.id,i)}function T(){const e=r();return e?.interval?.()??e?.chart.getDataContext()?.interval}t.appendChild($);let P=null;let j="";let M=null;const I=()=>{const e=m.marketStatus();if(y.hidden=null===e,S.hidden=null===e,null===e)return void(M=null);e.phase!==M&&(null!==M&&queueMicrotask(c),M=e.phase,y.dataset.phase=e.phase,x.textContent="",x.appendChild(Ge(n,ie(xn[e.phase]),"chrome"))),v(k,e.label),v(C,e.detail);const t=""===e.detail?e.label:`${e.label}, ${e.detail}`;y.getAttribute("aria-label")!==t&&y.setAttribute("aria-label",t)},D=()=>{const e=m.scale();for(const[t,o]of E){const n=null!==e&&e[t];o.getAttribute("aria-pressed")!==String(n)&&o.setAttribute("aria-pressed",String(n)),b(o,null===e)}},z=()=>{p||(!function(){const e=s();if(e===R)return;for(const e of F.splice(0))e();if(R=e,null===e)return;const t=()=>{p||D()},o=()=>{p||(z(),c())};F=[e.on("data:context",o),e.on("timezone:changed",o),e.on("state:restore:end",o),e.on("layout:change",()=>{p||(D(),I())}),e.on("zoom",t),e.on("pan",t),e.on("dblclick",t),e.on("destroy",()=>{p||queueMicrotask(z)})]}(),(()=>{const e=r(),t=e?.range?.()??null;for(const[o,n]of w){const i=o===t;n.getAttribute("aria-pressed")!==String(i)&&n.setAttribute("aria-pressed",String(i)),b(n,void 0===e?.setRange)}null!==_&&b(_,null===e||null===Fn(T()))})(),I(),(()=>{const t=s(),o=i(),n=t?.timezone()??"";v(L,null===t?"":Cn(o,n)),v(O,null===t?"":kn(o,n)),n!==j&&(j=n,e.tips.refreshLabel(A),A.setAttribute("aria-label",kt(e,"schema.ui.bottombar.timezone",{zone:n},"Timezone: {zone}"))),b(A,null===t)})(),D())};let R=null,F=[];const W=()=>{p||D()};n.addEventListener("pointerup",W,!0);let B=0;const q=()=>{if(0!==B&&clearTimeout(B),B=0,p||!0===n.hidden)return;const e=(o.now??Date.now)();B=setTimeout(U,1e3-(e%1e3+1e3)%1e3+5)};function U(){B=0,p||(z(),q())}const H=()=>{!0!==n.hidden&&z(),q()};return n.addEventListener("visibilitychange",H),z(),q(),{el:t,controls:m,refresh:z,destroy:()=>{if(!p){p=!0,h++,P?.(),null!==e.tips.target()&&t.contains(e.tips.target())&&e.tips.hide(),0!==B&&clearTimeout(B),B=0;for(const e of F.splice(0))e();n.removeEventListener("pointerup",W,!0),n.removeEventListener("visibilitychange",H),t.removeEventListener("pointerdown",g),l.clear(),t.textContent=""}}}}const Ss=`\n.oac-widget.has-bottombar { grid-template-rows: auto minmax(0, 1fr) auto auto; }\n.oac-widget.has-bottombar > .oac-bottombar { grid-row: 3; }\n.oac-widget.has-bottombar > .oac-statusline { grid-row: 4; }\n.oac-widget.has-bottombar:not(.is-mobile) > .oac-toasts { bottom: calc(${Ia("status-h")} + 38px); }\n.oac-widget.is-mobile > .oac-bottombar:not(.is-kept) { display: none; }\n.oac-widget.is-mobile:has(> .oac-bottombar.is-kept) .oac-mobile__footer { grid-row: 4; }\n.oac-widget.is-mobile:has(> .oac-bottombar.is-kept) > .oac-toasts { bottom: calc(82px + env(safe-area-inset-bottom)); }\n.oac-widget .oac-bottombar { container: oac-bottombar / inline-size; display: flex; align-items: center; gap: 2px;\n height: 28px; min-width: 0; padding: 0 6px; background: ${Ia("panel")}; border-top: 1px solid ${Ia("bd-soft")};\n color: ${Ia("mut")}; font-size: 11.5px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; }\n.oac-widget .oac-bottombar .oac-sep { height: 16px; }\n.oac-widget .oac-bottombar__group { display: inline-flex; align-items: center; gap: 1px; min-width: 0; }\n.oac-widget .oac-bottombar__ranges { flex: 0 1 auto; min-width: 56px; overflow-x: auto; scrollbar-width: none; }\n.oac-widget .oac-bottombar__scale { flex: none; }\n.oac-widget .oac-bottombar__ranges::-webkit-scrollbar { width: 0; height: 0; }\n.oac-widget .oac-bottombar button { display: inline-flex; align-items: center; gap: 5px; flex: none; height: 22px;\n padding: 0 7px; background: transparent; border: 1px solid transparent; border-radius: 5px; color: ${Ia("mut")};\n font-size: 11.5px; font-weight: 600; letter-spacing: .2px; transition: background .1s, color .1s, border-color .1s; }\n.oac-widget .oac-bottombar button:hover { background: ${Ia("elev")}; color: ${Ia("tx")}; }\n.oac-widget .oac-bottombar button[aria-pressed="true"] { background: ${Ia("on-bg")}; border-color: ${Ia("on-bd")}; color: ${Ia("acc-2")}; }\n.oac-widget .oac-bottombar button[aria-disabled="true"] { background: transparent; border-color: transparent; color: ${Ia("faint")}; cursor: default; }\n.oac-widget .oac-bottombar button:focus-visible { outline-offset: -1px; }\n.oac-widget .oac-bottombar .oac-glyph > svg { width: 14px; height: 14px; }\n.oac-widget .oac-bottombar__icon { width: 24px; padding: 0; justify-content: center; }\n.oac-widget .oac-bottombar__spacer { flex: 1 1 auto; min-width: 6px; }\n.oac-widget .oac-bottombar__status { display: inline-flex; flex: none; align-items: center; gap: 5px; padding: 0 5px; }\n.oac-widget .oac-bottombar__status > b { flex: none; color: ${Ia("tx")}; font-weight: 600; }\n.oac-widget .oac-bottombar__phase { display: inline-grid; flex: none; color: ${Ia("faint")}; }\n.oac-widget .oac-bottombar__status[data-phase="regular"] .oac-bottombar__phase { color: ${Ia("up")}; }\n.oac-widget .oac-bottombar__status:is([data-phase="pre"], [data-phase="post"], [data-phase="extended"]) .oac-bottombar__phase { color: ${Ia("amber")}; }\n.oac-widget .oac-bottombar__detail { color: ${Ia("faint")}; }\n.oac-widget .oac-bottombar__clock { color: ${Ia("tx")}; }\n.oac-widget .oac-bottombar__time { font-weight: 500; }\n.oac-widget .oac-bottombar__clock > small { color: ${Ia("faint")}; font-size: 10.5px; font-weight: 600; }\n.oac-widget .oac-mobile-sheet__note { grid-column: 1 / -1; margin: 0; padding: 8px 10px 10px; color: ${Ia("mut")};\n border-bottom: 1px solid ${Ia("bd-soft")}; margin-bottom: 6px; font-variant-numeric: tabular-nums; }\n.oac-widget .oac-mobile-sheet__note > b { color: ${Ia("tx")}; font-weight: 600; }\n.oac-widget .oac-mobile-sheet__body > [data-mobile-action="timezone"] { grid-column: 1 / -1; }\n.oac-widget .oac-mobile-sheet__ranges, .oac-widget .oac-mobile-sheet__scales { grid-column: 1 / -1; display: grid; }\n.oac-widget .oac-mobile-sheet__ranges { grid-template-columns: repeat(5, minmax(0, 1fr)); }\n.oac-widget .oac-mobile-sheet__scales { grid-template-columns: repeat(3, minmax(0, 1fr)); }\n.oac-widget .oac-statusline__market[data-phase="regular"] { color: ${Ia("up")}; }\n@container oac-bottombar (max-width: 760px) {\n .oac-widget .oac-bottombar__detail, .oac-widget .oac-bottombar__goto > span:not(.oac-glyph) { display: none; }\n}\n@container oac-bottombar (max-width: 600px) {\n .oac-widget .oac-bottombar__clock > small { display: none; }\n}\n@container oac-bottombar (max-width: 360px) {\n .oac-widget .oac-bottombar__status > b { display: none; }\n}\n@media (prefers-reduced-motion: reduce) {\n .oac-widget .oac-bottombar button { transition: none; }\n}\n`,As=e=>e.trim().toLocaleLowerCase().replace(/\s+/g," ");function Ls(e,t,o,n){const i=e.document,a=Ke(i,"div","oac-mobile-drawings__row"),r=n.makeAction("tool","",()=>{e.draw.setTool(t.id),n.close()});r.classList.add("oac-mobile__tool"),r.dataset.tool=t.id,r.setAttribute("aria-pressed",String(e.draw.activeTool()===t.id));const s=Ke(i,"span");s.textContent=o,r.append(bn(i,t.id),s);const l=n.rail.isFavorite(t.id),c=n.makeAction("favorite","",()=>{n.rail.toggleFavorite(t.id),n.refresh()});return c.classList.add("oac-mobile-drawings__pin"),c.dataset.tool=t.id,c.setAttribute("aria-pressed",String(l)),c.setAttribute("aria-label",kt(e,"schema.ui.mobile.drawings.pin",{name:o},"Pin {name} to rail")),c.appendChild(Ge(i,ie(l?"star-filled":"star"),"chrome")),a.append(r,c),a}function Os(e,t,o){const n=e.document,i=void 0===o.tools?null:new Set(o.tools),a=()=>je().filter(e=>null===i||i.has(e.id)),r=Ke(n,"div","oac-mobile-drawings__filters"),s=kt(e,"schema.ui.mobile.drawings.search",{},"Search drawings"),l=Ke(n,"input","oac-mobile-drawings__search",{type:"search","aria-label":s,placeholder:s,autocomplete:"off",spellcheck:"false"});l.dataset.mobileAction="drawing-search";const{wrap:c,select:d}=Go(n);d.classList.add("oac-mobile-drawings__groups"),d.dataset.mobileAction="drawing-group",d.setAttribute("aria-label",kt(e,"schema.ui.mobile.drawings.group",{},"Drawing group"));const u=new Set(a().map(e=>e.id)),p=hn.filter(e=>void 0!==e.id&&(e.items??[]).some(e=>void 0!==e.tool&&u.has(e.tool))),h=[["all",kt(e,"schema.ui.mobile.drawings.all",{},"All tools")],["favorites",kt(e,"schema.ui.mobile.drawings.favorites",{},"Favorites")],...p.map(t=>[t.id,kt(e,`schema.rail.${t.id}.title`,{},t.title??t.id)])];for(const[e,t]of h){const o=Ke(n,"option","",{value:e});o.textContent=t,d.appendChild(o)}d.value="all",r.append(l,c);const m=Ke(n,"div","oac-mobile-sheet__controls"),g=o.makeAction("cursor",kt(e,"Cursor"),()=>{e.draw.setTool(null),o.close()});g.classList.add("oac-mobile-drawings__cursor"),g.prepend(bn(n,"cursor"));const f=Ke(n,"div","oac-mobile-drawings__list",{role:"group","aria-label":kt(e,"Drawing tools")}),b=Ke(n,"div","oac-mobile-drawings__empty",{role:"status","aria-live":"polite"});b.textContent=kt(e,"schema.ui.mobile.drawings.empty",{},"No drawing tools found"),t.append(r,m,g,f,b);const v=()=>{m.textContent="",m.append(...function(e,t){if(null===e.draw.activeTool())return[];const o=t.rail;return[t.makeAction("finish",kt(e,"Finish"),()=>{e.draw.finish(),t.refresh()}),t.makeAction("cancel",kt(e,"Cancel"),()=>{e.draw.cancel(),t.refresh()}),...t.historyActions(),t.makeAction("magnet",kt(e,"Magnet: {mode}",{mode:kt(e,`schema.magnet.${o.magnetMode()}`,{},o.magnetMode())}),()=>{o.cycleMagnet(),t.refresh()}),t.makeAction("stay",kt(e,"Keep tool active: {mode}",{mode:o.stayMode()?kt(e,"on"):kt(e,"off")}),()=>{o.setStayMode(!o.stayMode()),t.refresh()})]}(e,o)),m.hidden=0===m.children.length,g.setAttribute("aria-pressed",String(null===e.draw.activeTool()));const t=As(l.value),n=p.find(e=>e.id===d.value),i=void 0===n?null:new Set(n.items?.map(e=>e.tool));f.textContent="";for(const n of a()){if("favorites"===d.value&&!o.rail.isFavorite(n.id))continue;if(null!==i&&!i.has(n.id))continue;const a=kt(e,`schema.drawing.${n.id}.name`,{},n.name);(""===t||[n.id,n.name,a].some(e=>As(e).includes(t)))&&f.appendChild(Ls(e,n,a,o))}b.hidden=f.children.length>0};for(const[e,n]of[[l,"input"],[d,"change"]])e.addEventListener(n,()=>{t.scrollTop=0,o.refresh()});return v(),v}const $s=`\n.oac-widget .oac-mobile-drawings__filters { grid-column: 1 / -1; display: grid; gap: 8px; margin-bottom: 8px; }\n.oac-widget .oac-mobile-drawings__filters > input, .oac-widget .oac-mobile-drawings__groups { width: 100%; min-width: 0; height: 44px; }\n.oac-widget .oac-mobile-drawings__filters > .oac-select { min-width: 0; }\n.oac-widget .oac-mobile-drawings__cursor, .oac-widget .oac-mobile-drawings__list,\n.oac-widget .oac-mobile-drawings__empty { grid-column: 1 / -1; }\n.oac-widget .oac-mobile-drawings__cursor { text-align: left; }\n.oac-widget .oac-mobile-drawings__row { display: grid; grid-template-columns: minmax(0, 1fr) 44px; border-top: 1px solid ${Ia("bd-soft")}; }\n.oac-widget .oac-mobile-drawings__row > .oac-mobile__tool { display: flex; align-items: center; gap: 10px; text-align: left; }\n.oac-widget .oac-mobile-drawings__row > .oac-mobile__tool > .oac-glyph { margin: 0; }\n.oac-widget .oac-mobile-drawings__pin { min-width: 44px; }\n.oac-widget .oac-mobile-sheet .oac-mobile-drawings__pin > .oac-glyph { margin: 0; }\n.oac-widget .oac-mobile-drawings__empty { min-height: 44px; padding: 13px 10px; color: ${Ia("mut")}; }\n`;const Es=["tool","interval","chartType","range","scale","zone"];function Ts(e,t){const o=e.document,n=t.mode??"auto",i=Ke(o,"div","oac-mobile");e.root.appendChild(i);let a=!1,r=!1,s=!1,l=null,c=null,d=null;const u=[],p=e=>{e.stopPropagation()};i.addEventListener("pointerdown",p);const h=(e,t,n)=>{const i=Ke(o,"button","oac-mobile__action",{type:"button"});return i.dataset.mobileAction=e,i.textContent=t,i.addEventListener("click",()=>{"true"!==i.getAttribute("aria-disabled")&&n(i)}),i},m=()=>["undo","redo"].map(t=>{const o=h(t,kt(e,"undo"===t?"Undo":"Redo"),()=>{ut(e,t),L()});return o.setAttribute("aria-disabled",String(!ht(e,t))),o}),g=()=>{const e=d;d=null,e?.close()},f=()=>l?.close(),b=(t,n,i,r=void 0)=>{g();const s=Ke(o,"section","oac-mobile-sheet",{"aria-label":t}),l=Ke(o,"div","oac-mobile-sheet__head oac-dialog__head"),c=Ke(o,"strong","oac-mobile-sheet__title");c.textContent=t;const u=h("close",kt(e,"Close"),()=>g());l.append(c,u);const p=Ke(o,"div","oac-mobile-sheet__body");s.append(l,p);const m=()=>{if(a||d?.repaint!==m)return;const e=o.activeElement,t=null!==e&&p.contains(e),n=t?(e=>{const t=e.closest("[data-mobile-action]"),o=t?.dataset.mobileAction;if(null===t||void 0===o)return null;const n={action:o};for(const e of Es)void 0!==t.dataset[e]&&(n[e]=t.dataset[e]);return n})(e):null,r=p.scrollTop;if(void 0!==v?v():(p.textContent="",i(p,g)),p.scrollTop=r,t){const e=null===n?null:((e,t)=>Array.from(e.querySelectorAll("[data-mobile-action]")).find(e=>e.dataset.mobileAction===t.action&&Es.every(o=>e.dataset[o]===t[o]))??null)(p,n);(e??p.querySelector(".oac-mobile__tool")??p.querySelector("[data-mobile-action]"))?.focus()}};let f=()=>{};const b={close:()=>f(),repaint:m};d=b;const v=i(p,g);f=e.openOverlay(s,{anchor:n,placement:"center",dismissOnOutside:!0,initialFocus:"function"==typeof r?r(p):r,onClose:()=>{d===b&&(d=null)}})};let v=null;if(t.topbar){const n=Ke(o,"div","oac-mobile__header",{role:"toolbar","aria-label":kt(e,"Chart header")});c=Ke(o,"input","oac-mobile__symbol",{type:"text","aria-label":kt(e,"Symbol"),placeholder:kt(e,"Symbol"),autocomplete:"off",spellcheck:"false"}),v=h("interval","",o=>{t.timeframePreferences?Et(e,o,{intervals:t.intervals,current:()=>t.state().interval,preferences:t.timeframePreferences,...t.canSelectInterval?{canSelect:t.canSelectInterval}:{},onSelect:t.onInterval}):b(kt(e,"Interval"),o,(e,o)=>{!function(e,t,o,n){for(const i of e.intervals){const a=n("pick-interval",sa(i),()=>{e.onInterval(i),o()});a.dataset.interval=i;const r=e.state().interval===i;a.setAttribute("aria-pressed",String(r)),t.appendChild(a)}}(t,e,o,h)})});const a=(e,o)=>{const n=e.trim().toUpperCase();f(),""!==n&&t.onSymbol(n,o),L(),c?.blur()};void 0!==t.search&&(l=Nn(e,c,{search:t.search,onSelect:a,context:()=>`${t.state().exchange}:${t.state().symbol}:${t.state().interval}`,variant:"mobile"})),c.addEventListener("keydown",e=>{"Enter"===e.key&&(e.preventDefault(),(null===l||l.canCommitRaw())&&a(c?.value??""))}),n.append(c,v),i.appendChild(n)}const w=Ke(o,"div","oac-mobile__footer"),_=Ke(o,"div","oac-mobile__selection",{role:"toolbar","aria-label":kt(e,"Selected drawing")});let y=null,x=null,k=null;null!==t.rail&&(y=h("properties",kt(e,"Properties"),e=>{t.onProperties(e)}),x=h("lock",kt(e,"Lock"),()=>{un(e,"lock",e.draw.selection()),L()}),k=h("delete",kt(e,"Delete"),()=>{un(e,"delete",e.draw.selection()),L()}),_.append(y,x,k),w.appendChild(_));const C=Ke(o,"nav","oac-mobile__bar",{"aria-label":kt(e,"Chart controls")});let S=null,A=null;function L(){if(a)return;const n=t.state();if(null!==c&&o.activeElement!==c&&(c.value=n.symbol),null!==v&&(v.textContent=sa(n.interval)),null!==S&&S.setAttribute("aria-pressed",String(null!==e.draw.activeTool())),null!==A&&A.setAttribute("aria-disabled",String(!t.indicatorsAvailable())),null!==_.parentNode){const t=e.draw.selection();_.hidden=0===t.length;const o=dn(e,t);t.length>0&&null!==x&&(x.setAttribute("aria-pressed",String(o.locked)),x.setAttribute("aria-disabled",String(0===o.editable.length))),null!==y&&y.setAttribute("aria-disabled",String(0===t.length)),null!==k&&k.setAttribute("aria-disabled",String(null!==o.noDelete||0===o.editable.length))}d?.repaint()}null!==t.rail&&(S=h("draw",kt(e,"Draw"),o=>{b(kt(e,"Drawing"),o,(o,n)=>Os(e,o,{rail:t.rail,tools:t.tools,makeAction:h,historyActions:m,refresh:L,close:n}),e=>e.querySelector(".oac-mobile-sheet__controls button, .oac-mobile__tool")??e.querySelector('[data-mobile-action="cursor"]'))}),C.appendChild(S)),t.topbar&&t.indicators&&(A=h("studies",kt(e,"Indicators"),e=>{t.onIndicators(e)}),C.appendChild(A)),t.topbar&&(C.appendChild(h("objects",kt(e,"Objects"),e=>{t.onObjects(e)})),t.onDataWindow&&C.appendChild(h("data-window",kt(e,"schema.ui.dataWindow",{},"Data"),e=>{t.onDataWindow?.(e)})),C.appendChild(h("more",kt(e,"More"),n=>{b(kt(e,"More"),n,(i,a)=>{const r=t.bottombar;void 0!==r&&i.appendChild(function(e){const t=Ke(o,"p","oac-mobile-sheet__note"),n=e.marketStatus();if(null!==n){const e=Ke(o,"b");e.textContent=n.label,t.append(e,o.createTextNode(""===n.detail?" · ":` ${n.detail} · `))}return t.appendChild(o.createTextNode(e.clock())),t}(r)),i.append(...m()),t.onCapture&&i.appendChild(h("capture",kt(e,"Capture"),()=>{a(),t.onCapture?.(n)})),t.onLayouts&&i.appendChild(h("layouts",kt(e,"schema.ui.layouts.title",{},"Layouts"),()=>{a(),t.onLayouts?.(n)}));for(const[o,r,s]of[["watchlist","Watchlist",t.onWatchlist],["news","News",t.onNews]])s&&i.appendChild(h(o,kt(e,`schema.ui.dock.${o}`,{},r),()=>{a(),s(n)}));if(t.onAlerts&&i.appendChild(h("alerts",kt(e,"Alerts"),()=>{a(),t.onAlerts?.(n)})),t.onGoTo){const o=h("go-to",kt(e,"Go to"),()=>{a(),t.onGoTo?.(n)});o.setAttribute("aria-disabled",String(null===Fn(t.state().interval))),i.appendChild(o)}const s=h("theme","dark"===t.state().theme?kt(e,"Switch to the light theme"):kt(e,"Switch to the dark theme"),()=>{t.onTheme(),a()});i.appendChild(s);const l=h("settings",kt(e,"Chart settings"),()=>{a(),t.onSettings(n)});l.setAttribute("aria-disabled",String(!t.settingsAvailable())),i.appendChild(l);const c=la(e.chart,e);if(null!==c){const e=Ke(o,"a","oac-mobile__action oac-mobile__branding",{href:c.href,target:"_blank",rel:"noopener noreferrer","aria-label":c.label});e.dataset.mobileAction="branding",e.textContent=c.label,i.appendChild(e)}void 0!==r&&function(t,n,i,a){const r=e=>{const n=Ke(o,"div","oac-head");n.textContent=e,t.appendChild(n)},s=(e,n)=>{r(n);const i=Ke(o,"div",e,{role:"group","aria-label":n});return t.appendChild(i),i},l=n.ranges();if(l.length>0){const t=s("oac-mobile-sheet__ranges",kt(e,"schema.ui.bottombar.ranges",{},"Range")),o=n.range();for(const i of l){const r=h("range",kt(e,`schema.ui.range.${i.id}`,{},i.label),()=>{n.setRange(i.id),a()});r.dataset.range=i.id,r.setAttribute("aria-pressed",String(o===i.id)),t.appendChild(r)}}const c=s("oac-mobile-sheet__scales",kt(e,"schema.ui.bottombar.scale",{},"Price scale")),d=n.scale();for(const t of ys){const o=h("scale",kt(e,t.key,{},t.label),()=>{n.toggleScale(t.id),L()});o.dataset.scale=t.id,o.setAttribute("aria-pressed",String(null!==d&&d[t.id])),o.setAttribute("aria-disabled",String(null===d)),c.appendChild(o)}r(kt(e,"schema.ui.bottombar.timezones",{},"Timezone"));const u=h("timezone",n.timezone(),()=>{b(kt(e,"schema.ui.bottombar.timezones",{},"Timezone"),i,(e,t)=>{const o=n.timezone();for(const i of n.timezones()){const a=h("pick-zone",i,()=>{n.setTimezone(i),t()});a.dataset.zone=i,a.setAttribute("aria-pressed",String(i===o)),e.appendChild(a)}})});u.setAttribute("aria-label",kt(e,"schema.ui.bottombar.timezone",{zone:n.timezone()},"Timezone: {zone}")),u.setAttribute("aria-haspopup","dialog"),t.appendChild(u)}(i,r,n,a);const d=Ke(o,"div","oac-head");d.textContent=kt(e,"Chart type"),i.appendChild(d);for(const n of ra()){const r=h("chart-type",kt(e,`schema.chartType.${n}`,{},aa(n)),()=>{t.onChartType(n),a()});void 0!==ve(n)&&r.prepend(Ge(o,ie(`chart-${n}`),"chrome")),r.dataset.chartType=n,r.setAttribute("aria-pressed",String(t.state().chartType===n)),i.appendChild(r)}})}))),C.children.length>0&&w.appendChild(C),w.children.length>0&&i.appendChild(w);const O="auto"===n?o.defaultView?.matchMedia?.("(pointer: coarse)")??null:null,$=t=>null!==t&&e.root.contains(t)&&(/^(INPUT|TEXTAREA)$/.test(t.tagName)||!0===t.isContentEditable);let E=!1;const T=a=>{const l=t.container.getBoundingClientRect(),c=l.width||t.container.clientWidth,d=l.height||t.container.clientHeight;if(s&&!(c*d>0))return;const u=function(e,t,o,n){return"auto"!==e?"always"===e:t>0&&(t<=640||n&&t<=960&&o>0&&o<600)}(n,c,d,!0===O?.matches);s&&u===r?E=!1:s&&!a&&$(o.activeElement)?E=!0:(E=!1,s=!0,r=u,e.root.classList.toggle("is-mobile",r),e.root.dataset.mobile=String(r),i.hidden=!r,r||(g(),f()))},P=()=>T(!1),j=o.defaultView?.ResizeObserver;let M=null;if("auto"===n){const t=e=>{E&&!$(e.relatedTarget)&&T(!0)};e.root.addEventListener("focusout",t),u.push(()=>e.root.removeEventListener("focusout",t))}if("auto"===n&&void 0!==j)M=new j(P),M.observe(t.container);else if("auto"===n){const e=o.defaultView;null!==e&&"function"==typeof e.addEventListener&&(e.addEventListener("resize",P),u.push(()=>e.removeEventListener("resize",P)))}null!==O&&("function"==typeof O.addEventListener?(O.addEventListener("change",P),u.push(()=>O.removeEventListener("change",P))):(O.addListener(P),u.push(()=>O.removeListener(P))));for(const t of["draw:tool","draw:select","drawing:select","drawing:change","draw:add","draw:remove","draw:update"])u.push(e.chart.on(t,L));return void 0!==e.history&&u.push(e.history.subscribe(L)),u.push(e.bus.on("symbol",L)),u.push(e.bus.on("interval",L)),u.push(e.bus.on("theme",L)),u.push(e.chart.on("branding:changed",L)),void 0!==t.bottombar&&u.push(t.bottombar.subscribe(L)),P(),L(),{el:i,active:()=>r,refresh:L,destroy:()=>{if(!a){a=!0,l?.destroy(),g(),M?.disconnect(),M=null;for(const e of u.splice(0))e();i.removeEventListener("pointerdown",p),i.remove(),e.root.classList.remove("is-mobile"),delete e.root.dataset.mobile}}}}const Ps=[1,1.5,2,3,4],js={solid:"minus",dashed:"line-dashed",dotted:"line-dotted",mixed:"line-mixed"},Ms=Symbol("mixed");function Is(e,t,o){let n,i=!1;for(const a of e){const e=mr(a,{fields:[t]},dt(a.tool),o)[t.path];if(i){if(JSON.stringify(e)!==JSON.stringify(n))return Ms}else n=e,i=!0}return i?n:void 0}let Ds=0;function zs(e,t,o={}){const{draw:n,chart:i}=e,a=e.document,r="oac-drawbar-"+ ++Ds,s=qo(a,"div","oac-drawbar");s.setAttribute("role","toolbar"),s.setAttribute("aria-label",kt(e,"Drawing toolbar")),s.dataset.keyScope="drawing-toolbar",s.hidden=!0;const l=()=>o.chart??sr(i),c=l(),d=Array.from(t.children),u=null===c?-1:d.indexOf(c);t.insertBefore(s,u<0?null:d[u+1]??null);const p=e=>{e.stopPropagation()};s.addEventListener("pointerdown",p),s.addEventListener("dblclick",p);let h=[],m=[],g=new Map,f=!1,b=!1;const v=(t,o=h)=>{un(e,t,o),W()},w=(t,o)=>{if(void 0===g.get(t))return;const i=ct(n,h).flatMap(e=>{const i=n.get(e),a=void 0===i?{}:Ce(i,{[t]:o},ke(i.tool));return Object.keys(a).length>0?[{id:e,patch:a}]:[]});pt(e,t,()=>{i.length>0&&n.updateMany(i)}),W()},_=Po(a,{id:`${r}-color`,label:kt(e,"Color"),value:"#000000",translate:e.translate,openOverlay:e.openOverlay,onChange:e=>{w("style.color",e)}});_.el.classList.add("oac-drawbar__color");const y=_.trigger,x=Ko(a,{label:"",onClick:()=>function(){const t=g.get("style.lineWidth");if(void 0===t)return;const o=Is(m,t,e.chartTheme.lineColor);z(x,Ps.map(t=>({label:kt(e,"{value} px",{value:t}),on:o===t,onSelect:()=>w("style.lineWidth",t)})),kt(e,"Line width"))}()});x.classList.add("oac-drawbar__width"),x.setAttribute("aria-haspopup","menu");const k=Ko(a,{label:"",iconOnly:!0,onClick:()=>function(){const t=g.get("style.lineStyle");if(void 0===t)return;const o=Is(m,t,e.chartTheme.lineColor);z(k,Me.map(e=>({label:N(e.value),icon:js[e.value],on:o===e.value,onSelect:()=>w("style.lineStyle",e.value)})),kt(e,"Line style"))}()});k.setAttribute("aria-haspopup","menu");const C=qo(a,"span","oac-glyph oac-glyph--chrome");k.appendChild(C);const S=Ko(a,{label:kt(e,"Lock"),icon:"lock",iconOnly:!0,onClick:()=>{v("lock")}}),A=Ko(a,{label:kt(e,"Delete"),icon:"trash",iconOnly:!0,variant:"danger",onClick:()=>{v("delete")}}),L=Ko(a,{label:kt(e,"More drawing actions"),icon:"more",iconOnly:!0,onClick:()=>function(){const t=h.slice(),{hidden:n,readOnly:i}=dn(e,t),a=[{label:kt(e,"Properties..."),icon:"settings",onSelect:()=>{fr(e,void 0,{ids:t})}},{label:kt(e,"Duplicate"),icon:"duplicate",key:ko(e.keymap,"duplicate","Mod+D"),onSelect:()=>{v("duplicate",t)}},{label:kt(e,n?"Show":"Hide"),icon:n?"eye-off":"eye",disabled:null!==i,sub:i??void 0,onSelect:()=>{v("visible",t)}},kt(e,"Order"),{label:kt(e,"Bring to front"),icon:"front",onSelect:()=>{v("front",t)}},{label:kt(e,"Send to back"),icon:"back",onSelect:()=>{v("back",t)}},{label:kt(e,"In front of the series"),icon:"above-series",onSelect:()=>{v("above",t)}},{label:kt(e,"Behind the series"),icon:"behind-series",onSelect:()=>{v("behind",t)}}];o.templates&&a.push(...qa(e,o.templates,t,L));z(L,a,kt(e,"More drawing actions"))}()});L.setAttribute("aria-haspopup","menu");const O=()=>qo(a,"span","oac-sep"),$=O();s.append(_.el,x,k,$,S,A,O(),L);for(const[e,t]of[["color",y],["width",x],["style",k],["lock",S],["delete",A],["more",L]])t.dataset.drawbar=e;const E=()=>[y,x,k,S,A,L].filter(e=>!(e.disabled||e.hidden||e===y&&_.el.hidden));let T=L;const P=e=>{T=e;for(const t of[y,x,k,S,A,L])t.tabIndex=t===e?0:-1};s.addEventListener("focusin",e=>{const t=e.target?.closest?.("[data-drawbar]");null!==t&&s.contains(t)&&P(t)});const j=e=>{const t=E();if(0===t.length)return;const o=t[(e%t.length+t.length)%t.length];P(o),o.focus()},M=()=>E().indexOf(a.activeElement),I=(t,o,n,i=!1)=>e.keymap.register(t,o,"drawing-toolbar",{label:n,group:"Drawing toolbar",layered:!0,hidden:i}),D=[I("ArrowRight",()=>{j(M()+1)},"Next control"),I("ArrowLeft",()=>{j(M()-1)},"Previous control"),I("Home",()=>{j(0)},"First control"),I("End",()=>{j(E().length-1)},"Last control"),I("ArrowDown",()=>{j(M()+1)},"Next control",!0),I("ArrowUp",()=>{j(M()-1)},"Previous control",!0),I("Shift+ArrowRight",()=>{j(M()+1)},"Next control",!0),I("Shift+ArrowDown",()=>{j(M()+1)},"Next control",!0),I("Shift+ArrowLeft",()=>{j(M()-1)},"Previous control",!0),I("Shift+ArrowUp",()=>{j(M()-1)},"Previous control",!0),I("Escape",()=>{l()?.focus()},"Back to the chart")],z=(t,o,n)=>{rn(e,t,o,{ariaLabel:n})};const N=t=>kt(e,"dashed"===t?"Dashed":"dotted"===t?"Dotted":"Solid");const R=()=>{if(s.hidden)return;const e=s.contains(a.activeElement);s.hidden=!0,e&&l()?.focus()};function F(){const e=l();if(null===e||s.hidden)return;const o=et(t,e);let i=1/0,a=-1/0,r=1/0,c=-1/0;for(const e of h)for(const t of n.screenPoints(e)??[])Number.isFinite(t.x)&&Number.isFinite(t.y)&&(i=Math.min(i,t.x),a=Math.max(a,t.x),r=Math.min(r,t.y),c=Math.max(c,t.y));const d=s.offsetWidth,u=s.offsetHeight,p=o.left+6,m=Math.max(p,o.right-6-d),g=o.top+6,f=Math.max(g,o.bottom-6-u);let b,v;if(Number.isFinite(i)){const e=o.right-o.left,t=Math.max(0,Math.min(e,i)),n=Math.max(0,Math.min(e,a));b=o.left+(t+n)/2-d/2;const s=o.top+r-10-u,l=o.top+c+10;v=s>=g?s:l<=f?l:s}else b=o.left+(o.right-o.left-d)/2,v=g;s.style.left=`${Math.round(Math.min(m,Math.max(p,b)))}px`,s.style.top=`${Math.round(Math.min(f,Math.max(g,v)))}px`}function W(){b||(h=n.selection().slice(),m=h.map(e=>n.get(e)).filter(e=>void 0!==e),0===m.length||null!==n.activeTool()||f?R():(g=new Map(ur(m.map(e=>e.tool)).fields.map(e=>[e.path,e])),function(){const t=dn(e,h),o=t.readOnly,n=e.chartTheme.lineColor,i=g.get("style.color");if(_.el.hidden=void 0===i,void 0!==i){const t=Is(m,i,n);_.el.classList.toggle("is-mixed",t===Ms),t!==Ms&&_.write(t);const[a,r]=[...new Set(m.map(e=>String(mr(e,{fields:[i]},dt(e.tool),n)["style.color"])))];y.style.backgroundImage=t===Ms?`linear-gradient(135deg, ${a} 0 50%, ${r??a} 50% 100%)`:"",y.setAttribute("aria-label",kt(e,"Color: {value}",t===Ms?{value:kt(e,"mixed")}:{value:String(t??"")})),y.disabled=null!==o,y.title=null===o?kt(e,"Color"):`${kt(e,"Color")} (${o})`}const r=g.get("style.lineWidth");if(x.hidden=void 0===r,void 0!==r){const t=Is(m,r,n),i=t===Ms?kt(e,"Mixed"):kt(e,"{value} px",{value:Number(t??1)});x.textContent=i,x.setAttribute("aria-label",kt(e,"Line width: {value}",{value:t===Ms?kt(e,"mixed"):i})),x.classList.toggle("is-mixed",t===Ms),x.disabled=null!==o,x.title=null===o?kt(e,"Line width"):`${kt(e,"Line width")} (${o})`}const s=g.get("style.lineStyle");if(k.hidden=void 0===s,void 0!==s){const t=Is(m,s,n),i=t===Ms?"mixed":"string"==typeof t?t:"solid";C.innerHTML=ie(js[i]??"minus"),k.classList.toggle("is-mixed",t===Ms);const a=t===Ms?kt(e,"mixed"):N(i);k.setAttribute("aria-label",kt(e,"Line style: {style}",{style:a})),k.disabled=null!==o,k.title=null===o?kt(e,"Line style: {style}",{style:a}):`${kt(e,"Line style")} (${o})`}$.hidden=_.el.hidden&&x.hidden&&k.hidden,S.replaceChildren(Ho(a,t.locked?"lock":"unlock")),S.setAttribute("aria-label",kt(e,"Lock")),S.setAttribute("aria-pressed",t.locked?"true":t.partlyLocked?"mixed":"false"),S.disabled=null!==o,S.title=null===o?kt(e,"Lock"):`${kt(e,"Lock")} (${o})`;const l=t.noDelete;A.disabled=null!==l;const c=l??ko(e.keymap,"delete","Delete");A.title=void 0===c?kt(e,"Delete"):`${kt(e,"Delete")} (${c})`,E().includes(T)?P(T):P(E()[0]??L)}(),s.hidden=!1,F()))}const B=()=>{b||s.hidden||F()},q=[];for(const e of["draw:select","drawing:select","draw:update","draw:remove","draw:add","draw:restore","drawing:change","draw:tool"])q.push(i.on(e,W));for(const e of["pan","zoom","resize","paneResized","paneMoved","paneCollapsed","paneMaximized","paneAdded","paneRemoved","data:update","layout:change"])q.push(i.on(e,B));if(null!==c){const e=e=>{0!==e.buttons&&B()},t={passive:!0};c.addEventListener("pointermove",e,t);for(const e of["pointerup","wheel","dblclick"])c.addEventListener(e,B,t);q.push(()=>{c.removeEventListener("pointermove",e,t);for(const e of["pointerup","wheel","dblclick"])c.removeEventListener(e,B,t)})}q.push(i.on("draw:preview",()=>{f||(f=!0,R())}));for(const e of["draw:preview-clear","drag:end","drag:cancel"])q.push(i.on(e,()=>{f&&(f=!1,W())}));q.push(e.bus.on("theme",W)),void 0!==e.history&&q.push(e.history.subscribe(W));const U=a.defaultView?.ResizeObserver;let H=null;return void 0!==U&&null!==c&&(H=new U(B),H.observe(c)),W(),{el:s,refresh:W,destroy:()=>{if(!b){b=!0;for(const e of q.splice(0))e();for(const e of D.splice(0))e();H?.disconnect(),_.destroy(),s.removeEventListener("pointerdown",p),s.removeEventListener("dblclick",p),s.remove()}}}}const Ns='\n.oac-widget .oac-drawbar { position: absolute; z-index: 25; display: flex; align-items: center; gap: 2px; padding: 3px;\n background: var(--oac-panel); border: 1px solid var(--oac-bd); border-radius: 9px; box-shadow: var(--oac-shadow); }\n.oac-widget .oac-drawbar .oac-btn { height: 28px; }\n.oac-widget .oac-drawbar .oac-sep { height: 18px; margin: 0 3px; }\n.oac-widget .oac-drawbar__color { margin: 0 2px; }\n.oac-widget .oac-drawbar__width { min-width: 44px; padding: 0 7px; font-size: 11.5px; font-variant-numeric: tabular-nums; color: var(--oac-tx); }\n.oac-widget .oac-drawbar .is-mixed { color: var(--oac-mut); font-style: italic; }\n.oac-widget .oac-drawbar .oac-btn[aria-pressed="mixed"] { border-color: var(--oac-on-bd); border-style: dashed; }\n.oac-widget.is-mobile .oac-drawbar { display: none; }\n/* The properties dialog edits the same selection in full; two surfaces for it would sit on each other. */\n.oac-widget:has(.oac-layer > .oac-props) .oac-drawbar { visibility: hidden; }\n',Rs=(e,t)=>Array.from(e,e=>{const o=e.charCodeAt(0);return o>=32&&127!==o||t&&"\n"===e?e:" "}).join(""),Fs=(e,t)=>Rs(e,!1).replace(/\s+/g," ").trim().slice(0,t);function Ws(e){if(null===e||"object"!=typeof e)return null;const{id:t,time:o}=e,n="string"==typeof e.headline?Fs(e.headline,500):"";if("string"!=typeof t||""===t||t.length>256||""===n||"number"!=typeof o||!Number.isFinite(o)||o<=0)return null;const i={id:t,headline:n,time:o},a="string"==typeof e.source?Fs(e.source,120):"";""!==a&&(i.source=a);const r="string"==typeof e.summary?(s=e.summary,l=4e3,Rs(s.replace(/\r\n?/g,"\n"),!0).trim().slice(0,l)):"";var s,l;return""!==r&&(i.summary=r),"string"==typeof e.url&&e.url.length<=2048&&(i.url=e.url.trim()),i}class Bs{constructor(e){Object.defineProperty(this,"_feed",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_pageSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_staleAfter",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_maxItems",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_now",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_onChange",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_instrument",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_status",{enumerable:!0,configurable:!0,writable:!0,value:"idle"}),Object.defineProperty(this,"_items",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_cursor",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_loadingMore",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_refreshFailed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_error",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_loadedAt",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_generation",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_controllers",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"_staleTimer",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_destroyed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),this._feed=e.feed,this._pageSize=Math.max(1,Math.min(100,Math.round(e.pageSize??20))),this._staleAfter=Math.max(0,e.staleAfterMs??3e5),this._maxItems=Math.max(1,Math.round(e.maxItems??500)),this._now=e.now??Date.now,this._onChange=t=>{this._destroyed||e.onChange?.(t)}}setInstrument(e){if(this._destroyed)return;const t=null===e?null:{symbol:e.symbol,exchange:e.exchange},o=this._instrument;t?.symbol===o?.symbol&&t?.exchange===o?.exchange||(this._cancel(),this._instrument=t,this._items=[],this._cursor=null,this._error=null,this._refreshFailed=!1,this._loadedAt=null,this._status="idle",null!==t?this.refresh():this._emit())}async refresh(){if(this._destroyed||null===this._instrument)return;this._cancel(),this._status="loading",this._emit();const e=await this._request();void 0!==e&&(e instanceof Error?(this._error=e.message,this._items.length>0?(this._status="ready",this._refreshFailed=!0):this._status="error"):(this._items=[],this._cursor=this._take(e.items)>0?this._nextCursor(e,void 0):null,this._status=this._items.length>0?"ready":"empty",this._error=null,this._refreshFailed=!1,this._loadedAt=this._now(),this._scheduleStale()),this._emit())}async loadMore(){if(this._destroyed||"ready"!==this._status||null===this._cursor||this._loadingMore)return;const e=this._cursor;this._loadingMore=!0,this._emit();const t=await this._request(e);void 0!==t&&(this._loadingMore=!1,t instanceof Error?this._error=t.message:(this._cursor=this._take(t.items)>0?this._nextCursor(t,e):null,this._error=null),this._emit())}snapshot(){const e=null===this._loadedAt?0:this._now()-this._loadedAt;return{instrument:null===this._instrument?null:{...this._instrument},status:this._status,items:this._items.slice(),hasMore:null!==this._cursor,loadingMore:this._loadingMore,stale:this._refreshFailed||null!==this._loadedAt&&e>this._staleAfter,refreshFailed:this._refreshFailed,error:this._error,loadedAt:this._loadedAt}}destroy(){this._destroyed||(this._cancel(),this._destroyed=!0)}async _request(e){const t=this._instrument,o=this._generation,n=new AbortController;this._controllers.add(n);try{const i=await this._feed.getNews({symbol:t.symbol,exchange:t.exchange,limit:this._pageSize,...void 0===e?{}:{cursor:e},signal:n.signal});if(o!==this._generation||this._destroyed)return;return null!==i&&"object"==typeof i&&Array.isArray(i.items)?i:new Error("The news source returned no page")}catch(e){return o!==this._generation||this._destroyed?void 0:new Error((e=>Ct({},e))(e))}finally{this._controllers.delete(n)}}_take(e){const t=new Set(this._items.map(e=>e.id));let o=0;for(const n of e){const e=Ws(n);null===e||t.has(e.id)||(t.add(e.id),this._items.push(e),o++)}return this._items.sort((e,t)=>t.time-e.time),this._items.length>=this._maxItems?(this._items.length=this._maxItems,0):o}_nextCursor(e,t){const o=e.nextCursor;return"string"==typeof o&&""!==o&&o!==t?o:null}_cancel(){this._generation++;for(const e of this._controllers)e.abort();this._controllers.clear(),this._loadingMore=!1,null!==this._staleTimer&&(clearTimeout(this._staleTimer),this._staleTimer=null)}_scheduleStale(){null!==this._staleTimer&&clearTimeout(this._staleTimer),this._staleTimer=setTimeout(()=>{this._staleTimer=null,this._emit()},this._staleAfter+1)}_emit(){this._onChange(this.snapshot())}}function qs(e){if("string"!=typeof e)return null;const t=e.trim();if(!/^https?:\/\//i.test(t))return null;try{const e=new URL(t);return"http:"!==e.protocol&&"https:"!==e.protocol||""!==e.username||""!==e.password?null:e.href}catch{return null}}function Us(e,t,o){const n=e.document,i=(t,o,n={})=>kt(e,`schema.ui.news.${t}`,n,o),a=qo(n,"div","oac-news");a.setAttribute("aria-label",i("title","News"));const r=qo(n,"div","oac-news__bar"),s=qo(n,"div","oac-news__heading"),l=qo(n,"span","oac-news__instrument"),c=qo(n,"span","oac-news__exchange");s.append(l,c);const d=Ko(n,{label:i("refresh","Refresh"),onClick:()=>{E.refresh()}});d.setAttribute("aria-label",i("refreshNews","Refresh news")),r.append(s,d);const u=qo(n,"div","oac-news__status");u.setAttribute("role","status"),u.setAttribute("aria-live","polite");const p=qo(n,"ul","oac-news__list");p.setAttribute("aria-label",i("headlines","Headlines"));const h=qo(n,"div","oac-news__more"),m=qo(n,"p","oac-news__more-error"),g=Ko(n,{label:"",onClick:()=>{E.loadMore()}}),f=qo(n,"span","oac-news__end");h.append(m,g,f);const b=qo(n,"article","oac-news__detail");b.hidden=!0;const v=Ko(n,{label:i("back","Back to news"),onClick:()=>j()}),w=qo(n,"h3","oac-news__detail-headline"),_=qo(n,"p","oac-news__detail-meta"),y=qo(n,"p","oac-news__detail-summary"),x=qo(n,"div","oac-news__detail-link");b.append(v,w,_,y,x),a.append(r,u,p,h,b),t.appendChild(a);let k=!1,C=null,S=null;const A=new Map,L=()=>{try{return e.chart.timezone()}catch{return U}},O=t=>{try{return new Intl.DateTimeFormat(e.locale,{timeZone:L(),...t})}catch{return new Intl.DateTimeFormat("en-US",{timeZone:"UTC",...t})}};let $=null;const E=new Bs({feed:o.feed,pageSize:o.pageSize,staleAfterMs:o.staleAfterMs,maxItems:o.maxItems,onChange:e=>{C=e,P()}}),T=(e,t)=>{t.textContent="",void 0!==e.source&&t.appendChild(qo(n,"span","oac-news__source",e.source));const o=qo(n,"time","oac-news__time",(i=e.time,$?.zone!==L()&&($={zone:L(),format:O({dateStyle:"medium",timeStyle:"short"})}),$.format.format(new Date(1e3*i))));var i;o.setAttribute("datetime",(e=>{try{return new Date(1e3*e).toISOString()}catch{return""}})(e.time)),t.appendChild(o)};function P(){if(k||null===C)return;const e=C;l.textContent=e.instrument?.symbol??"",c.textContent=e.instrument?.exchange??"",d.disabled=null===e.instrument||"loading"===e.status;const t=function(e){const t=e.instrument?.symbol??"";if(null===e.instrument)return{text:i("status.none","Choose a symbol to see its news"),kind:"idle"};if("loading"===e.status)return e.items.length>0?{text:i("status.refreshing","Refreshing news for {symbol}",{symbol:t}),kind:"loading"}:{text:i("status.loading","Loading news for {symbol}",{symbol:t}),kind:"loading"};if("empty"===e.status)return{text:i("status.empty","No news for {symbol}",{symbol:t}),kind:"empty"};if("error"===e.status)return{text:i("status.error","News could not load: {error}",{error:e.error??""}),kind:"error"};if(e.refreshFailed)return{text:i("status.staleFailed","Showing earlier news. Refresh failed: {error}",{error:e.error??""}),kind:"stale"};const o=null===e.loadedAt?"":O({timeStyle:"short"}).format(new Date(e.loadedAt));return e.stale?{text:i("status.stale","Updated {time}. Refresh for newer news.",{time:o}),kind:"stale"}:{text:i("status.ready","Updated {time}",{time:o}),kind:"ready"}}(e);u.textContent=t.text,u.dataset.state=t.kind;const o=new Set(e.items.map(e=>e.id));for(const[e,t]of A)o.has(e)||(t.li.remove(),A.delete(e));e.items.forEach((e,t)=>{let o=A.get(e.id);if(!o){const t=qo(n,"li","oac-news__item"),a=qo(n,"button","oac-news__open");a.type="button",a.dataset.id=e.id,a.addEventListener("click",()=>function(e){const t=A.get(e);if(!t)return;S=e;const o=t.item;w.textContent=o.headline,T(o,_),y.textContent=o.summary??"",y.hidden=void 0===o.summary,x.textContent="";const a=qs(o.url);if(null!==a){const e=qo(n,"a","oac-btn oac-btn--primary oac-news__article",i("openArticle","Open article"));e.setAttribute("href",a),e.setAttribute("target","_blank"),e.setAttribute("rel","noopener noreferrer"),e.setAttribute("referrerpolicy","no-referrer"),x.appendChild(e)}else x.appendChild(qo(n,"p","oac-news__no-link",i("noLink","No article link")));b.hidden=!1,p.hidden=h.hidden=!0,v.focus()}(e.id)),t.appendChild(a),o={li:t,open:a,item:e},A.set(e.id,o)}o.item=e,o.open.textContent="";const a=qo(n,"span","oac-news__meta");T(e,a),o.open.append(qo(n,"span","oac-news__headline",e.headline),a),p.children[t]!==o.li&&p.insertBefore(o.li,p.children[t]??null)});const a=e.hasMore&&null!==e.error&&!e.loadingMore&&"ready"===e.status&&!e.refreshFailed;m.hidden=!a,m.textContent=a?i("moreFailed","Older news could not load: {error}",{error:e.error??""}):"",g.hidden=!e.hasMore,g.textContent=e.loadingMore?i("loadingMore","Loading older news"):i("loadMore","Load older news"),g.disabled=e.loadingMore||"ready"!==e.status;const r=!e.hasMore&&e.items.length>0&&"ready"===e.status;f.hidden=!r,f.textContent=r?i("end","No older news"):"",null===S||A.has(S)||j(!1),p.hidden=h.hidden=null!==S}function j(e=!0){const t=S;S=null,b.hidden=!0,p.hidden=h.hidden=!1,e&&null!==t&&A.get(t)?.open.focus()}const M=()=>{const t=(()=>{const t=e.symbol();return""===t.symbol?null:{symbol:t.symbol,exchange:t.exchange}})(),o=C?.instrument??null;t?.symbol===o?.symbol&&t?.exchange===o?.exchange&&null!==C||(null!==S&&j(!1),E.setInstrument(t))},I=e=>{e.stopPropagation()};a.addEventListener("pointerdown",I);const D=[e.chart.on("data:context",M),e.chart.on("timezone:changed",()=>{P();const e=null===S?void 0:A.get(S);e&&T(e.item,_)})];return C=E.snapshot(),M(),P(),{el:a,initialFocus:d,refresh:()=>E.refresh(),destroy:()=>{if(!k){k=!0,E.destroy();for(const e of D)e();a.removeEventListener("pointerdown",I),A.clear(),a.remove()}}}}const Hs='\n.oac-widget .oac-news { display: flex; flex-direction: column; gap: 6px; padding: 8px 10px 10px; font-size: 12px; min-height: 0; }\n.oac-widget .oac-news__bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }\n.oac-widget .oac-news__heading { display: flex; align-items: baseline; gap: 5px; min-width: 0; }\n.oac-widget .oac-news__instrument { font-weight: 600; color: var(--oac-tx); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.oac-widget .oac-news__exchange { font-size: 10px; color: var(--oac-mut); }\n.oac-widget .oac-news .oac-btn { height: 26px; padding: 0 8px; font-size: 11px; }\n.oac-widget .oac-news__status { font-size: 11px; color: var(--oac-mut); overflow-wrap: anywhere; }\n.oac-widget .oac-news__status[data-state="error"], .oac-widget .oac-news__more-error { color: var(--oac-danger); }\n.oac-widget .oac-news__status[data-state="stale"] { color: var(--oac-warn, var(--oac-mut)); }\n.oac-widget .oac-news__list { list-style: none; margin: 0; padding: 0; }\n.oac-widget .oac-news__list[hidden], .oac-widget .oac-news__more[hidden], .oac-widget .oac-news__detail[hidden], .oac-widget .oac-news__more > [hidden] { display: none; }\n.oac-widget .oac-news__item { border-bottom: 1px solid var(--oac-bd-soft); }\n.oac-widget .oac-news__open { display: flex; flex-direction: column; gap: 3px; width: 100%; padding: 7px 2px; border: 0; background: none; color: var(--oac-tx); font: inherit; text-align: left; cursor: pointer; }\n.oac-widget .oac-news__open:hover, .oac-widget .oac-news__open:focus-visible { background: var(--oac-elev); }\n.oac-widget .oac-news__headline { font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }\n.oac-widget .oac-news__meta, .oac-widget .oac-news__detail-meta { display: flex; flex-wrap: wrap; gap: 8px; font-size: 11px; color: var(--oac-mut); }\n.oac-widget .oac-news__source { overflow-wrap: anywhere; }\n.oac-widget .oac-news__more { display: flex; flex-direction: column; align-items: stretch; gap: 4px; padding-top: 4px; font-size: 11px; color: var(--oac-mut); text-align: center; }\n.oac-widget .oac-news__more-error { margin: 0; text-align: left; overflow-wrap: anywhere; }\n.oac-widget .oac-news__detail { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }\n.oac-widget .oac-news__detail-headline { margin: 0; font: 600 14px/1.35 var(--oac-font); color: var(--oac-tx); overflow-wrap: anywhere; }\n.oac-widget .oac-news__detail-meta { margin: 0; }\n.oac-widget .oac-news__detail-summary { margin: 0; white-space: pre-line; line-height: 1.5; color: var(--oac-tx); overflow-wrap: anywhere; }\n.oac-widget .oac-news__article { display: inline-flex; align-items: center; text-decoration: none; }\n.oac-widget .oac-news__no-link { margin: 0; font-size: 11px; color: var(--oac-mut); }\n.oac-widget .oac-panel-dock[data-sheet="true"] .oac-news__open { padding: 10px 2px; }\n';function Ks(e){return Array.isArray(e)?e.map(Ks):function(e){if(null===e||"object"!=typeof e)return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}(e)?Object.fromEntries(Object.entries(e).map(([e,t])=>[e,Ks(t)])):e}function Gs(e){return{...e,..."object"==typeof e.details?{details:Ks(e.details)}:{}}}const Vs='\n.oac-event-layer{position:absolute;inset:0;pointer-events:none;z-index:50}\n.oac-event-details{position:absolute;pointer-events:auto;box-sizing:border-box;width:340px;max-width:calc(100% - 16px);max-height:calc(100% - 16px);overflow:auto;background:var(--oac-panel,#171b23);color:var(--oac-tx,#d9dfe8);border:1px solid var(--oac-bd,#343b48);border-radius:8px;box-shadow:var(--oac-shadow,0 12px 32px #0005);font:12px/1.5 var(--oac-font,system-ui,sans-serif);scrollbar-width:thin;scrollbar-color:var(--oac-sb-thumb,#414958) var(--oac-panel,#171b23)}\n.oac-event-details::-webkit-scrollbar{width:6px;height:6px}\n.oac-event-details::-webkit-scrollbar-track{background:var(--oac-panel,#171b23)}\n.oac-event-details::-webkit-scrollbar-thumb{background:var(--oac-sb-thumb,#414958);border-radius:3px}\n.oac-event-details::-webkit-scrollbar-thumb:hover{background:var(--oac-sb-thumb-hover,#586276)}\n.oac-event-details__header{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:10px 12px;border-bottom:1px solid var(--oac-bd,#343b48)}\n.oac-event-details__heading{margin:0;font:600 12px/1.5 var(--oac-font,system-ui,sans-serif)}\n.oac-event-details button{font:inherit;cursor:pointer;border:1px solid var(--oac-bd,#343b48);border-radius:4px;padding:4px 8px;background:var(--oac-elev,#252c37);color:inherit;text-align:left}\n.oac-event-details button:hover{background:var(--oac-elev-2,#333d4b)}\n.oac-event-details button:focus-visible{outline:2px solid var(--oac-ring,#74a7fa);outline-offset:2px}\n.oac-event-details__members{display:flex;flex-wrap:wrap;gap:6px;padding:10px 12px 0}\n.oac-event-details__members button{max-width:100%;overflow-wrap:anywhere}\n.oac-event-details__members button[aria-pressed="true"]{border-color:var(--oac-acc,#74a7fa);background:var(--oac-on-bg,#274263)}\n.oac-event-details__content{padding:12px;overflow-wrap:anywhere}\n.oac-event-details__title{margin:0 0 4px;font-size:14px;font-weight:600}\n.oac-event-details__time,.oac-event-details__status{color:var(--oac-mut,#a0aabc)}\n.oac-event-details__summary{white-space:pre-wrap;margin:10px 0 0}\n.oac-event-details__fields{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:5px 12px;margin:10px 0 0}\n.oac-event-details__fields dt{color:var(--oac-mut,#a0aabc)}\n.oac-event-details__fields dd{margin:0;text-align:right;white-space:pre-wrap}\n.oac-event-details__status{padding:0 12px 10px}\n.oac-event-details__status:empty{display:none}\n.oac-event-details__subhead{margin:10px 0 0;font-size:12px;font-weight:600}\n.oac-event-details__text,.oac-event-details__list{margin:6px 0 0}\n.oac-event-details__list{padding-left:18px}\n.oac-event-details a{color:var(--oac-acc,#74a7fa)}\n.oac-event-details__actions{display:flex;flex-wrap:wrap;justify-content:flex-end;gap:6px;padding:0 12px 12px}\n.oac-event-details__actions:empty{display:none}\n';function Js(e){return{title:kt(e,"Event details"),close:kt(e,"Close"),events:kt(e,"Events"),loading:kt(e,"Loading details..."),empty:kt(e,"No additional details."),error:kt(e,"Unable to load additional details.")}}class Ys{constructor(e,t={}){Object.defineProperty(this,"_container",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"_options",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"element",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_doc",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_overlays",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_ownOverlays",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_labels",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_formatTime",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_close",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_abort",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_revision",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_disposed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_events",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_members",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_content",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_status",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_actions",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_anchor",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._doc=e.ownerDocument,this._labels={...Js({}),...t.labels};const o=new Intl.DateTimeFormat(void 0,{timeZone:U,dateStyle:"medium",timeStyle:"short"});if(this._formatTime=t.formatTime??(e=>{const t=new Date(1e3*e);return Number.isFinite(t.getTime())?o.format(t):String(e)}),this._ownOverlays=void 0===t.overlays,this._overlays=t.overlays??rt(e,this._doc),this._ownOverlays&&this._overlays.layer.classList.add("oac-event-layer"),!1!==t.injectStyles&&null===this._doc.getElementById("oac-event-details-style")){const e=Ke(this._doc,"style",void 0,{id:"oac-event-details-style"});void 0!==t.styleNonce&&e.setAttribute("nonce",t.styleNonce),e.textContent=Vs,this._doc.head.appendChild(e)}this.element=Ke(this._doc,"section","oac-event-details",{role:"dialog","aria-label":this._labels.title});for(const e of["pointerdown","pointerup","click","dblclick","wheel","keydown"])this.element.addEventListener(e,e=>e.stopPropagation());this._content=Ke(this._doc,"div","oac-event-details__content"),this._status=Ke(this._doc,"div","oac-event-details__status",{role:"status","aria-live":"polite"}),this._actions=Ke(this._doc,"div","oac-event-details__actions")}open(e,t){if(this._disposed)return;if(this.close(),0===e.events.length)return;this._events=e.events.map(Gs),this._anchor=void 0===t?void 0:{...t};const o=Ke(this._doc,"header","oac-event-details__header"),n=Ke(this._doc,"h2","oac-event-details__heading");n.textContent=this._labels.title;const i=Ke(this._doc,"button",void 0,{type:"button","data-action":"close-event-details"});if(i.textContent=this._labels.close,i.addEventListener("click",()=>this.close()),o.append(n,i),this.element.replaceChildren(o),this._members=[],this._events.length>1){const e=Ke(this._doc,"div","oac-event-details__members",{role:"group","aria-label":this._labels.events});this._members=this._events.map((t,o)=>{const n=Ke(this._doc,"button",void 0,{type:"button","data-event-index":String(o)});return n.textContent=t.title??t.label,n.addEventListener("click",()=>this._select(o)),e.appendChild(n),n}),this.element.appendChild(e)}this.element.append(this._content,this._status,this._actions),this._close=this._overlays.open(this.element,{placement:"below",modal:!1,initialFocus:i,onClose:()=>{this._close=null,this._cancel()}}),this._select(0),this._position()}close(){this._cancel(),this._close?.(),this._close=null}destroy(){this._disposed||(this._disposed=!0,this.close(),this._events=[],this._members=[],this._ownOverlays&&this._overlays.destroy())}_cancel(){this._revision++,this._abort?.abort(),this._abort=null}_select(e){this._cancel();const t=this._events[e];this._members.forEach((t,o)=>t.setAttribute("aria-pressed",String(o===e))),this._render(t,t.details),this._actions.replaceChildren(...(this._options.actions?.(Gs(t))??[]).map(e=>{const o=Ke(this._doc,"button",void 0,{type:"button"});return o.textContent=e.label,o.addEventListener("click",()=>{const o=Gs(t);this.close(),e.run(o)}),o})),this._status.textContent="",this.element.removeAttribute("aria-busy");const o=this._options.loadDetails;if(void 0===o)return;const n=this._revision,i=new AbortController;this._abort=i,this._status.textContent=this._labels.loading,this.element.setAttribute("aria-busy","true");const a=()=>!this._disposed&&null!==this._close&&n===this._revision&&!i.signal.aborted,r=()=>{a()&&(this.element.removeAttribute("aria-busy"),this._status.textContent=this._labels.error,this._position())};try{Promise.resolve(o(Gs(t),{signal:i.signal})).then(e=>{a()&&(this._status.textContent="",this.element.removeAttribute("aria-busy"),this._render(t,e??t.details))},r)}catch{r()}}_render(e,t){const o=Ke(this._doc,"h3","oac-event-details__title");o.textContent=e.title??e.label;const n=Ke(this._doc,"div","oac-event-details__time");n.textContent=this._formatTime(e.time),this._content.replaceChildren(o,n);const i="string"==typeof t?t:t?.summary;if(i){const e=Ke(this._doc,"p","oac-event-details__summary");e.textContent=i,this._content.appendChild(e)}const a="object"==typeof t?t.fields:void 0;if(a?.length){const e=Ke(this._doc,"dl","oac-event-details__fields");for(const t of a){const o=Ke(this._doc,"dt"),n=Ke(this._doc,"dd");o.textContent=t.label,n.textContent=t.value,e.append(o,n)}this._content.appendChild(e)}let r=!1;const s="object"==typeof t&&Array.isArray(t.blocks)?t.blocks:[];for(const e of s){const{type:t,text:o,items:n}=e??{},i="heading"===t?Ke(this._doc,"h4","oac-event-details__subhead"):"paragraph"===t?Ke(this._doc,"p","oac-event-details__text"):"list"===t?Ke(this._doc,"ul","oac-event-details__list"):null;if(null!==i){if("list"!==t)this._inline(i,o);else if(Array.isArray(n))for(const e of n)this._inline(i.appendChild(Ke(this._doc,"li")),e);i.textContent&&(this._content.appendChild(i),r=!0)}}if(!i&&!a?.length&&!r){const e=Ke(this._doc,"p","oac-event-details__summary");e.textContent=this._labels.empty,this._content.appendChild(e)}this._position()}_inline(e,t){if("string"!=typeof t){if(Array.isArray(t))for(const o of t){if("string"!=typeof o?.text)continue;const t=qs(o.href);let n=null===t?Ke(this._doc,"span"):Ke(this._doc,"a",void 0,{href:t,target:"_blank",rel:"noopener noreferrer",referrerpolicy:"no-referrer"});n.textContent=o.text;for(const e of["em","strong"]){if(!0!==o[e])continue;const t=Ke(this._doc,e);t.appendChild(n),n=t}e.appendChild(n)}}else e.append(t)}_position(){const e=this._container.getBoundingClientRect(),t=this._overlays.layer.getBoundingClientRect(),o=this._ownOverlays?0:e.left-t.left,n=this._ownOverlays?0:e.top-t.top;this.element.style.maxWidth=`${Math.max(0,e.width-16)}px`,this.element.style.maxHeight=`${Math.max(0,e.height-16)}px`;const i=this.element.offsetWidth,a=this.element.offsetHeight,r=this._anchor?.x,s=this._anchor?.y;this.element.style.left=`${o+Math.max(0,Math.min(Number.isFinite(r)?r:e.width-i-8,e.width-i-8))}px`,this.element.style.top=`${n+Math.max(0,Math.min(Number.isFinite(s)?s-a-12:8,e.height-a-8))}px`}}function Zs(e,t,o={}){const n=e.primaryBars();return Qs(e,n,t,o,n.some(e=>Number.isFinite(e.oi)))}function Qs(e,t,o,n,i){const a=(e,t)=>kt(n,`schema.ui.data.${e}`,{},t),r=a("unavailable","Unavailable");let s=t.length-1;if(void 0!==o){let e=0,n=t.length;for(;e<n;){const i=e+n>>>1;t[i].time<o?e=i+1:n=i}s=t[e]?.time===o?e:-1}const l=t[s],c=void 0===o?l?.time??null:Number.isFinite(o)?o:null;let d;try{d=new Intl.NumberFormat(n.locale,{maximumFractionDigits:8})}catch{d=new Intl.NumberFormat("en-US",{maximumFractionDigits:8})}const u=(t,o,n=!1)=>{try{if("custom"===o?.type)return String(o.formatter(t));if("percent"===o?.type)return`${t.toFixed(o.precision??2)}%`;if("price"===o?.type)return t.toFixed(o.precision??2);if(n)return e.primarySeries()?.priceScale().format(t)??t.toFixed(2)}catch{}return d.format(t)},p=(e,t,o,n=!1,i)=>{const a="number"==typeof o&&Number.isFinite(o)?o:null;return{key:e,label:t,raw:a,value:null===a?r:u(a,i,n)}},h=["open","high","low","close"].map(e=>p(e,a(e,e[0].toUpperCase()+e.slice(1)),l?.[e],!0));h.push(p("volume",a("volume","Volume"),l?.volume));!1!==e.hasOpenInterest&&(!0===e.hasOpenInterest||i)&&h.push(p("oi",a("oi","Open interest"),l?.oi));const m=[{id:"price",title:a("price","Price"),rows:h}];for(const t of e.indicators()){const e=I(t.indicatorId),o=t.values(),n=(e?.plots??[]).map(e=>p(`${t.id}:${e.key}`,e.title,s<0?null:o[e.ohlc?.close??e.key]?.[s-(e.offset??0)],!1,e.priceFormat));n.length>0&&m.push({id:t.id,title:t.name,rows:n})}const g=e.getDataContext();let f=r;if(null!==c)try{f=`${w(c,e.timezone())} (${e.timezone()})`}catch{}return{symbol:g?.symbol??"",exchange:g?.exchange??"",time:c,timestamp:f,sections:m}}function Xs(e,t){const o=e.document;t.classList.add("oac-data-window"),t.setAttribute("aria-label",kt(e,"schema.ui.data.title",{},"Data window"));const n=qo(o,"div","oac-data-window__instrument"),i=qo(o,"div","oac-data-window__time"),a=qo(o,"div","oac-data-window__sections");let r;t.append(n,i,a);let s=!1,l=!1,c=!1,d=!0,u=!1,p=[];const h=new Map,m=(e,t)=>{e.textContent!==t&&(e.textContent=t)},g=()=>{if(l)return;d&&(p=e.chart.primaryBars(),u=p.some(e=>Number.isFinite(e.oi)),d=!1);const t=Qs(e.chart,p,c?NaN:r,e,u);m(n,[t.exchange,t.symbol].filter(Boolean).join(":")),m(i,t.timestamp);const s=new Set(t.sections.map(e=>e.id));for(const[e,t]of h)s.has(e)||(t.el.remove(),h.delete(e));for(const[e,n]of t.sections.entries()){let t=h.get(n.id);if(!t){const e=qo(o,"section","oac-data-window__section"),i=qo(o,"h3","oac-data-window__title");e.appendChild(i),a.appendChild(e),t={el:e,title:i,rows:new Map},h.set(n.id,t)}a.children[e]!==t.el&&a.insertBefore(t.el,a.children[e]??null),m(t.title,n.title);const i=new Set(n.rows.map(e=>e.key));for(const[e,o]of t.rows)i.has(e)||(o.el.remove(),t.rows.delete(e));for(const e of n.rows){let n=t.rows.get(e.key);if(!n){const i=qo(o,"div","oac-data-window__row");i.dataset.key=e.key;const a=qo(o,"span","oac-data-window__label"),r=qo(o,"span","oac-data-window__value");i.append(a,r),t.el.appendChild(i),n={el:i,label:a,value:r},t.rows.set(e.key,n)}m(n.label,e.label),m(n.value,e.value),n.value.classList.toggle("is-unavailable",null===e.raw)}}},f=()=>{s||l||(s=!0,Promise.resolve().then(()=>{s=!1,g()}))},b=[e.chart.on("crosshair:readout",e=>{const t=e;r=null===t.index&&null===t.point?void 0:t.time??NaN,f()}),e.chart.on("data:context",()=>{r=void 0,c=!0,d=!0,f()}),e.chart.on("data:range",()=>{c=!1,d=!0,f()}),...["objects:change","indicatorSettings","indicatorRemoved","indicator:data-status","paneMoved","resize","timezone:changed"].map(t=>e.chart.on(t,f))],v=()=>{if(!l){l=!0;for(const e of b)e();h.clear(),t.textContent="",t.classList.remove("oac-data-window"),t.removeAttribute("aria-label")}};return b.push(e.chart.on("destroy",v)),g(),{el:t,refresh:f,destroy:v}}const el="\n.oac-widget .oac-data-window { padding: 12px; font-size: 12px; user-select: text; -webkit-user-select: text; }\n.oac-widget .oac-data-window__instrument { font-weight: 600; color: var(--oac-tx); overflow-wrap: anywhere; }\n.oac-widget .oac-data-window__time { font-size: 11px; color: var(--oac-mut); margin: 4px 0 14px; line-height: 1.5; }\n.oac-widget .oac-data-window__section + .oac-data-window__section { margin-top: 16px; }\n.oac-widget .oac-data-window__title { margin: 0 0 6px; padding: 0; font: 600 11px/1.4 var(--oac-font); color: var(--oac-mut); text-transform: uppercase; letter-spacing: .04em; }\n.oac-widget .oac-data-window__row { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; min-height: 26px; padding: 4px 0; }\n.oac-widget .oac-data-window__label { min-width: 0; overflow-wrap: anywhere; }\n.oac-widget .oac-data-window__value { font-variant-numeric: tabular-nums; text-align: right; overflow-wrap: anywhere; }\n.oac-widget .oac-data-window__value.is-unavailable { font-size: 11px; color: var(--oac-mut); }\n";function tl(t,o){const n=t.document;let i=!1,a=null,r=null,s=null,l=null;const c=()=>{const e=a;a=null,l?.destroy(),l=null,r=null,s=null,e?.()},d=d=>{if(i||d.defaultPrevented||d.isComposing||d.ctrlKey||d.metaKey||d.altKey||d.repeat)return;if(!/^[a-zA-Z0-9]$/.test(d.key))return;const u=d.target,p=n.activeElement;if(null===u||!t.root.contains(u)||null===p||!t.root.contains(p)||function(e){for(let t=e;null!==t;t=t.parentElement)if(t.isContentEditable||["INPUT","TEXTAREA","SELECT"].includes(t.tagName))return!0;return!1}(u))return;if(t.overlays.size()>0||null!==t.draw.activeTool()||!o.enabled())return;const h=lo(d);t.keymap.list().some(e=>e.combo===h&&t.keymap.activeScopes().includes(e.scope))||t.chart.shortcuts?.list().some(e=>!e.isDisabled&&e.combos.some(e=>ho(e)===h))||(d.preventDefault(),d.stopPropagation(),((i,d)=>{c(),r=Ke(n,"section","oac-quick-entry",{role:"dialog","aria-label":kt(t,"symbol"===i?"schema.ui.enterSymbol":"schema.ui.enterInterval",{},"symbol"===i?"Enter symbol":"Enter interval")}),s=Ke(n,"input","oac-quick-entry__input",{type:"text",autocomplete:"off",spellcheck:"false","aria-label":kt(t,"symbol"===i?"schema.ui.symbol":"schema.ui.interval",{},"symbol"===i?"Symbol":"Interval")}),s.value=d;const u=Ke(n,"div","oac-quick-entry__message",{role:"alert"});r.append(s,u);const p=s;p.addEventListener("input",()=>{u.textContent=""});const h=r;a=t.openOverlay(r,{placement:"center",initialFocus:p,onClose:()=>{r===h&&c()}}),"symbol"===i&&o.search&&(l=Nn(t,p,{search:o.search,onSelect:(e,t)=>{c(),o.onSymbol(e,t)},context:()=>`${t.symbol().exchange}:${t.symbol().symbol}:${t.interval()}`}),l.open(d)),p.addEventListener("keydown",n=>{if("Enter"!==n.key||n.isComposing)return;n.preventDefault(),n.stopPropagation();const a=p.value.trim();if("symbol"===i){if(null!==l&&!l.canCommitRaw())return;if(""===a)return void(u.textContent=kt(t,"schema.ui.symbolRequired",{},"Enter a symbol"));c(),o.onSymbol(a.toUpperCase())}else{const n=e(a)??(/^[0-9]+$/.test(a)?e(`${a}m`):null);if(null===n)return void(u.textContent=kt(t,"schema.ui.invalidInterval",{},"Enter a recognized interval"));c(),o.onInterval(n.code)}})})(/[0-9]/.test(d.key)?"interval":"symbol",d.key))};n.addEventListener("keydown",d,!0);const u=t.bus.on("symbol",c),p=t.bus.on("interval",c);return{close:c,destroy:()=>{i||(i=!0,c(),u(),p(),n.removeEventListener("keydown",d,!0))}}}const ol="\n.oac-widget .oac-quick-entry{width:min(330px,calc(100vw - 32px));padding:12px}\n.oac-widget .oac-quick-entry__input{width:100%;box-sizing:border-box;background:var(--oac-panel);color:var(--oac-tx);border:1px solid var(--oac-bd);border-radius:4px;padding:9px;font:inherit}\n.oac-widget .oac-quick-entry__message{min-height:20px;padding-top:5px;color:var(--oac-danger)}\n",nl=(e,t)=>[..."ABCDEFGHIJKLMNOP"].map((o,n)=>`.oac-grid[data-theme="${e}"] [data-group="${o}"] { --oac-group: ${t[n%t.length]}; }`).join("\n"),il=`\n.oac-grid { position: relative; display: flex; flex-direction: column; width: 100%; height: 100%; min-width: 0; min-height: 0;\n background: var(--oac-bg); color: var(--oac-tx); font: var(--oac-fs)/1.35 var(--oac-font); }\n.oac-grid [hidden] { display: none !important; }\n.oac-grid__tabs { display: flex; gap: 2px; padding: 4px; overflow-x: auto; flex: none; background: var(--oac-panel);\n border-bottom: 1px solid var(--oac-bd-soft); scrollbar-width: thin; scrollbar-color: var(--oac-sb-thumb) transparent; }\n.oac-grid__tabs::-webkit-scrollbar { height: 6px; }\n.oac-grid__tabs::-webkit-scrollbar-thumb { background: var(--oac-sb-thumb); border-radius: 999px; }\n.oac-grid__tab { flex: none; height: 26px; padding: 0 10px; border: 1px solid transparent; border-radius: var(--oac-radius);\n background: transparent; color: var(--oac-mut); font: inherit; cursor: pointer; white-space: nowrap; }\n.oac-grid__tab:hover { color: var(--oac-tx); background: var(--oac-elev); }\n.oac-grid__tab[aria-selected="true"] { color: var(--oac-tx-strong); background: var(--oac-on-bg); border-color: var(--oac-on-bd); }\n.oac-grid__tab:focus-visible, .oac-grid__split:focus-visible { outline: 2px solid var(--oac-ring); outline-offset: -2px; }\n.oac-grid__cells { position: relative; flex: 1; display: grid; min-height: 0; background: var(--oac-bd-soft); }\n.oac-grid__cell { position: relative; min-width: 0; min-height: 0; overflow: hidden; }\n.oac-grid__cell::after { content: ''; position: absolute; inset: 0; border: 1px solid transparent; pointer-events: none; z-index: 30; }\n.oac-grid[data-single="false"][data-compact="false"]:not([data-maximized="true"]) .oac-grid__cell[data-active="true"]::after { border-color: var(--oac-acc); }\n.oac-grid__split { position: relative; z-index: 31; touch-action: none; transition: background .12s; }\n.oac-grid__split::before { content: ''; position: absolute; inset: 0 -3px; }\n.oac-grid__split[data-axis="row"]::before { inset: -3px 0; }\n.oac-grid__split[data-axis="column"] { cursor: col-resize; }\n.oac-grid__split[data-axis="row"] { cursor: row-resize; }\n.oac-grid__split:hover, .oac-grid__split.is-drag { background: var(--oac-acc); }\n.oac-grid:is([data-compact="true"], [data-maximized="true"]) .oac-grid__cells { grid-template: minmax(0,1fr) / minmax(0,1fr) !important; }\n.oac-grid:is([data-compact="true"], [data-maximized="true"]) .oac-grid__cell { grid-area: 1 / 1 / 2 / 2 !important; }\n\n/* Dragging a chart by its bar onto another's place. */\n.oac-grid[data-single="false"][data-compact="false"]:not([data-maximized="true"]) .oac-grid__cell .oac-topbar { cursor: grab; }\n.oac-grid[data-single="false"][data-compact="false"]:not([data-maximized="true"]) .oac-grid__cell .oac-topbar input { cursor: text; }\n.oac-grid[data-dragging="true"], .oac-grid[data-dragging="true"] * { cursor: grabbing !important; user-select: none; }\n.oac-grid__cell[data-dragging="true"] { opacity: .55; }\n.oac-grid__cell[data-drop="true"]::after { border: 2px dashed var(--oac-acc); background: var(--oac-on-bg); }\n\n/* Dense cells: a chart a few hundred pixels across keeps its plot and the\n controls a chart needs every minute; the rest waits for maximize. */\n/* One row that scrolls sideways rather than a bar wrapped over a third of the plot. */\n.oac-grid__cell[data-dense="true"] :is(.oac-rail, .oac-rail-tab) { display: none; }\n.oac-grid__cell[data-dense="true"] .oac-topbar { gap: 2px; padding: 3px 5px; flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden;\n scrollbar-width: none; -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 18px), transparent);\n mask-image: linear-gradient(to right, #000 calc(100% - 18px), transparent); }\n.oac-grid__cell[data-dense="true"] .oac-topbar::-webkit-scrollbar { display: none; }\n.oac-grid__cell[data-dense="true"] .oac-topbar > * { flex-shrink: 0; }\n.oac-grid__cell[data-dense="true"] .oac-sym > input { width: 96px; }\n.oac-grid__cell[data-dense="true"] .oac-sym__ex { display: none; }\n.oac-grid__cell[data-dense="true"] :is(.oac-topbar__goto, .oac-topbar__objects, .oac-topbar__data, .oac-topbar__watchlist,\n .oac-topbar__news, .oac-topbar__alerts, .oac-topbar__theme, .oac-topbar__branding-slot, .oac-topbar__spacer + .oac-sep) { display: none; }\n/* A label goes where its glyph shows: a host's chart type with none keeps its name. */\n.oac-grid__cell[data-dense="true"] .oac-topbar > .oac-btn > span:not(.oac-glyph):not(.oac-chev):not([hidden] + span) { display: none; }\n\n/* The grid's own chrome takes the widget's controls; these rules only place it. The bar's strip\n holds its height (a control and its padding) before the bar loads into it (grid-bar.ts). */\n.oac-widget.oac-grid__bar { position: relative; display: flex; align-items: center; gap: 4px; flex: none; height: auto;\n min-height: calc(var(--oac-ctl-h) + 9px); padding: 4px 6px; background: var(--oac-panel); border-bottom: 1px solid var(--oac-bd-soft);\n overflow: visible; container: oac-grid-bar / inline-size; }\n/* One bar under the charts: the widget's own strip, acting on the active chart. */\n.oac-widget.oac-grid__foot { display: block; flex: none; height: auto; min-height: 0; }\n.oac-widget.oac-grid__overlay { position: absolute; inset: 0; display: block; background: transparent; pointer-events: none;\n z-index: 80; overflow: visible; }\n/* A link group mark: the letter on a panel, the group's hue as a stripe. */\n.oac-grid__chip { display: inline-flex; align-items: center; justify-content: center; min-width: 17px; height: 17px;\n padding: 0 4px 0 6px; border-radius: 4px; background: var(--oac-elev-2); color: var(--oac-tx-strong);\n box-shadow: inset 3px 0 0 var(--oac-group, var(--oac-faint)); font: 700 10.5px/1 var(--oac-font); flex: none; }\n.oac-grid__chip[data-group="none"] { padding: 0 3px; box-shadow: none; background: transparent; color: var(--oac-faint); }\n.oac-grid__chip[data-group="none"] > svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 2;\n stroke-linecap: round; stroke-linejoin: round; }\n.oac-grid__mark { display: inline-flex; align-items: center; justify-content: center; height: 24px; min-width: 24px; padding: 0 3px;\n margin-right: 2px; border: 1px solid transparent; border-radius: 6px; background: transparent; cursor: pointer; flex: none; }\n.oac-grid__mark:hover { background: var(--oac-elev); border-color: var(--oac-bd-soft); }\n.oac-grid__mark:focus-visible { outline: 2px solid var(--oac-ring); outline-offset: -1px; }\n.oac-grid__mark--float { position: absolute; top: 6px; left: 6px; z-index: 32; background: var(--oac-panel); border-color: var(--oac-bd-soft); }\n${nl("dark",["#5b9cf6","#f0a445","#4cc38a","#d673d1","#3fc1c9","#d9c34a","#ef6a6a","#9d85f2"])}\n${nl("light",["#1f63c9","#b8660b","#17864f","#a23c9e","#0e7f86","#8a7300","#c0392b","#6247c4"])}\n@media (prefers-reduced-motion: reduce) {\n .oac-grid__split { transition: none; }\n}\n`,al=2147483647,rl=e=>JSON.stringify([e.symbol,e.exchange]),sl=e=>Ct({},e),ll=e=>"number"==typeof e&&Number.isFinite(e);function cl(e){const t=e.previousClose;if(!ll(t)||t<=0||!ll(e.last))return null;const o=e.last-t;return{change:o,percent:o/t*100}}function dl(e,t){if(null===e||"object"!=typeof e||e.symbol!==t.symbol||(e.exchange??"")!==t.exchange||!ll(e.last))return null;const o={symbol:t.symbol,exchange:t.exchange,last:e.last};for(const t of["previousClose","bid","ask","volume","time"])ll(e[t])&&(o[t]=e[t]);return!0===e.delayed&&(o.delayed=!0),o}class ul{constructor(e){Object.defineProperty(this,"_feed",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_staleAfter",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_pollMs",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_now",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_onChange",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_entries",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_visible",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"_requests",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"_seq",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_error",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_poll",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_stale",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_resync",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_destroyed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),this._feed=e.feed??null,this._staleAfter=Math.max(0,e.staleAfterMs??6e4),this._pollMs=Math.max(0,e.pollMs??15e3),this._now=e.now??Date.now,this._onChange=()=>{this._destroyed||e.onChange?.()}}setVisible(e){if(this._destroyed)return;const t=new Map;for(const o of e)t.set(rl(o),{symbol:o.symbol,exchange:o.exchange});for(const e of this._visible)t.has(e)||this._hide(e);const o=[],n=this._visible;this._visible=new Set(t.keys());for(const[e,i]of t)n.has(e)||(this._show(e,i),o.push(i));for(const e of this._requests)[...e.ids].some(e=>this._visible.has(e))||(e.controller.abort(),this._requests.delete(e));this._trim(),o.length>0&&this._snapshot(o),this._schedulePoll(),this._scheduleStale(),this._onChange()}row(e){const t={symbol:e.symbol,exchange:e.exchange},o=this._entries.get(rl(t)),n=e=>({instrument:t,quote:o?.quote?{...o.quote}:null,status:e,receivedAt:o?.receivedAt??null});if(null===this._feed)return n("unavailable");if(!o?.quote)return n(o?.error?"error":o?.missing?"unavailable":"loading");const i=!0===o.quote.delayed;if(!o.fresh||!this._visible.has(rl(t)))return n("stale");const a=o.stream?.status;return"live"===a?n(i?"delayed":"live"):"reconnecting"===a||"disconnected"===a||this._now()-(o.receivedAt??0)>this._staleAfter?n("stale"):n(i?"delayed":"snapshot")}status(){if(null===this._feed)return"unavailable";const e=[...this._visible].map(e=>this._entries.get(e)?.stream).filter(e=>!!e&&!e.closed);if(0===e.length)return null!==this._error?"error":this._visible.size>0&&!this._feed.subscribeQuotes?"snapshot":"idle";for(const t of["disconnected","reconnecting","connecting"])if(e.some(e=>e.status===t))return t;return"live"}error(){return this._error}subscribed(){return[...this._visible].map(e=>this._entries.get(e)).filter(e=>!!e?.stream&&!e.stream.closed).map(e=>({...e.key}))}destroy(){if(!this._destroyed){this._destroyed=!0;for(const e of this._entries.values())e.stream?.stop();for(const e of this._requests)e.controller.abort();this._requests.clear(),null!==this._poll&&clearTimeout(this._poll),null!==this._stale&&clearTimeout(this._stale),this._entries.clear(),this._visible.clear()}}_show(e,t){let o=this._entries.get(e);o?(this._entries.delete(e),this._entries.set(e,o)):(o={key:t,quote:null,receivedAt:null,pushed:0,fresh:!1,missing:!1,error:null,stream:null},this._entries.set(e,o)),o.fresh=!1,o.missing=!1,o.error=null;const n=this._feed;if(!n?.subscribeQuotes)return;const i={status:"connecting",closed:!1,stop:()=>{}};o.stream=i;const a=o;try{const e=n.subscribeQuotes([{...t}],{onQuote:e=>{if(i.closed||this._destroyed)return;const o=dl(e,t);null!==o&&("connecting"===i.status&&(i.status="live"),a.pushed=++this._seq,this._accept(a,o),this._scheduleStale(),this._onChange())},onStatus:e=>{if(i.closed||this._destroyed)return;const o=i.status;i.status=e,"live"!==e||"reconnecting"!==o&&"disconnected"!==o||(a.fresh=!1,this._queueResync(t)),this._scheduleStale(),this._onChange()}});i.stop=()=>{i.closed=!0;try{e()}catch{}}}catch(e){i.closed=!0,o.stream=null,o.error=sl(e)}}_hide(e){const t=this._entries.get(e);t&&(t.stream?.stop(),t.stream=null,t.fresh=!1)}_trim(){for(const[e]of this._entries){if(this._entries.size<=1e3)break;this._visible.has(e)||this._entries.delete(e)}}_accept(e,t){e.quote=t,e.receivedAt=this._now(),e.fresh=!0,e.missing=!1,e.error=null}_queueResync(e){null===this._resync?(this._resync=[e],queueMicrotask(()=>{const e=(this._resync??[]).filter(e=>this._visible.has(rl(e)));this._resync=null,e.length>0&&!this._destroyed&&this._snapshot(e)})):this._resync.push(e)}_snapshot(e){const t=this._feed;if(null===t||this._destroyed)return;const o={controller:new AbortController,ids:new Set(e.map(rl)),seq:++this._seq};let n;this._requests.add(o);try{n=Promise.resolve(t.getQuotes({instruments:e.map(e=>({...e})),signal:o.controller.signal}))}catch(e){n=Promise.reject(e)}n.then(e=>{if(!this._requests.delete(o)||this._destroyed)return;const t=new Set;for(const n of Array.isArray(e)?e:[]){const e=n&&"object"==typeof n?rl({symbol:n.symbol,exchange:n.exchange??""}):"",i=this._entries.get(e);if(!i||!o.ids.has(e)||!this._visible.has(e))continue;const a=dl(n,i.key);null!==a&&(t.add(e),i.pushed>o.seq||this._accept(i,a))}for(const e of o.ids){const o=this._entries.get(e);o&&!t.has(e)&&this._visible.has(e)&&!o.quote&&(o.missing=!0)}this._error=null,this._scheduleStale(),this._onChange()},e=>{if(this._requests.delete(o)&&!this._destroyed){this._error=sl(e);for(const e of o.ids){const t=this._entries.get(e);t&&!t.quote&&this._visible.has(e)&&(t.error=this._error)}this._onChange()}})}_schedulePoll(){null!==this._poll&&(clearTimeout(this._poll),this._poll=null),this._destroyed||null===this._feed||this._feed.subscribeQuotes||0===this._pollMs||0===this._visible.size||(this._poll=setTimeout(()=>{this._poll=null,this._snapshot([...this._visible].map(e=>this._entries.get(e).key)),this._schedulePoll()},Math.min(this._pollMs,al)))}_expires(e){const t=this._entries.get(e);if(!t?.fresh||null===t.quote||null===t.receivedAt)return null;const o=t.stream?.status;return"live"===o||"reconnecting"===o||"disconnected"===o?null:t.receivedAt+this._staleAfter}_scheduleStale(){if(null!==this._stale&&(clearTimeout(this._stale),this._stale=null),this._destroyed)return;const e=this._now();let t=1/0;for(const o of this._visible){const n=this._expires(o);null!==n&&n>=e&&(t=Math.min(t,n))}t!==1/0&&(this._stale=setTimeout(()=>{this._stale=null,this._now()>t&&this._onChange(),this._scheduleStale()},Math.min(t-e+1,al)))}}const pl=[["symbol","Symbol"],["last","Last"],["change","Chg"],["percent","Chg%"]],hl="watchlist-sort",ml=e=>JSON.stringify([e.symbol,e.exchange]),gl=(e,t)=>e.symbol===t.symbol&&e.exchange===t.exchange,fl=new WeakMap;function bl(e,t,o){const n=e.document,i=o.store,a=(t,o,n={})=>kt(e,`schema.ui.watchlist.${t}`,n,o),r=e=>""===e.exchange?e.symbol:a("entry","{symbol} on {exchange}",{symbol:e.symbol,exchange:e.exchange}),s=qo(n,"div","oac-watchlist");s.setAttribute("aria-label",a("title","Watchlist"));const l=qo(n,"div","oac-watchlist__bar"),{wrap:c,select:d}=Go(n);d.setAttribute("aria-label",a("list","Watchlist"));const u=(e,t,o)=>{const i=Ko(n,{label:e,onClick:o});return i.setAttribute("aria-label",t),i},p=u(a("new","New"),a("newList","New list"),()=>Ce("create")),h=u(a("rename","Rename"),a("renameList","Rename list"),()=>Ce("rename")),m=u(a("delete","Delete"),a("deleteList","Delete list"),()=>function(){const e=te();if(null===e)return;ke(),_.textContent=a("confirmDelete","Delete {name} and its {count} symbols?",{name:e.name,count:e.entries.length}),x.textContent=a("deleteNamed","Delete {name}",{name:e.name}),w.hidden=!1,y.focus()}());l.append(c,p,h,m);const g=qo(n,"form","oac-watchlist__name");g.hidden=!0;const f=qo(n,"input");f.type="text",f.maxLength=120,f.setAttribute("aria-label",a("name","List name")),f.autocomplete="off";const b=Ko(n,{label:a("save","Save"),variant:"primary",onClick:()=>{Se()}}),v=Ko(n,{label:a("cancel","Cancel"),onClick:()=>ke()});g.append(f,v,b);const w=qo(n,"div","oac-watchlist__confirm");w.hidden=!0;const _=qo(n,"span","oac-watchlist__confirm-text"),y=Ko(n,{label:a("keep","Keep list"),onClick:()=>ke()}),x=Ko(n,{label:"",variant:"danger",onClick:()=>{!async function(){const e=te();if(ke(),null===e)return;de("");try{await i.removeList(e.id)}catch(e){ue(e)}}()}});w.append(_,y,x);const k=qo(n,"div","oac-watchlist__add"),C=qo(n,"input");C.type="search",C.placeholder=a("addPlaceholder","Add symbol"),C.setAttribute("aria-label",a("addSymbol","Add symbol")),C.autocomplete="off";const S=Ko(n,{label:"",onClick:()=>{const t=e.symbol();""!==t.symbol&&xe({...t})}});S.classList.add("oac-watchlist__add-current"),k.append(C,S);const A=qo(n,"div","oac-watchlist__status");A.setAttribute("role","status"),A.setAttribute("aria-live","polite");const L=qo(n,"div","oac-watchlist__message");L.setAttribute("role","alert"),L.hidden=!0;const O=qo(n,"p","oac-watchlist__empty");O.hidden=!0;const $=qo(n,"div","oac-watchlist__scroll"),E=qo(n,"table","oac-watchlist__table"),T=qo(n,"caption","oac-sr"),P=qo(n,"thead"),j=qo(n,"tr"),M=new Map;for(const[e,t]of pl){const o=qo(n,"th",`oac-watchlist__col oac-watchlist__col--${e}`);o.setAttribute("scope","col"),o.dataset.sort=e;const i=qo(n,"button","oac-watchlist__sort",a(`column.${e}`,t));i.type="button",i.addEventListener("click",()=>be(e)),o.appendChild(i),j.appendChild(o),M.set(e,o)}const I=qo(n,"th","oac-watchlist__col oac-watchlist__col--actions");I.appendChild(qo(n,"span","oac-sr",a("actions","Actions"))),j.appendChild(I),P.appendChild(j);const D=qo(n,"tbody");E.append(T,P,D),$.appendChild(E),s.append(l,g,w,k,A,L,O,$),t.appendChild(s);let z=null,N=null,R=function(e){const t=e,o=t?.key;return"symbol"===o||"last"===o||"change"===o||"percent"===o?{key:o,direction:"ascending"===t?.direction?"ascending":"descending"}:{key:"list",direction:"ascending"}}(e.storage?.get(hl)??fl.get(i)??null),F=null,W=!1,B=!1,q=[],U=!1,H=!1,K=!1;const G=new Map,V=new Set;let J,Y;try{J=new Intl.NumberFormat(e.locale,{minimumFractionDigits:2,maximumFractionDigits:6}),Y=new Intl.NumberFormat(e.locale,{minimumFractionDigits:2,maximumFractionDigits:2})}catch{J=new Intl.NumberFormat("en-US",{minimumFractionDigits:2,maximumFractionDigits:6}),Y=new Intl.NumberFormat("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}const Z=new ul({feed:o.quotes,staleAfterMs:o.staleAfterMs,pollMs:o.pollMs,onChange:()=>le()}),Q=n.defaultView,X=Q?.IntersectionObserver,ee=X?new X(e=>{for(const t of e)t.isIntersecting?V.add(t.target):V.delete(t.target);ce()},{root:$}):null,te=()=>z?.lists.find(e=>e.id===N)??null,oe=e=>{if(o.normalize)try{const t=o.normalize({symbol:e.symbol,exchange:e.exchange});if("string"==typeof t?.symbol&&"string"==typeof t.exchange)return{symbol:t.symbol,exchange:t.exchange}}catch{}return{symbol:e.symbol,exchange:e.exchange}},ne=(e,t)=>{if(o.formatPrice)try{return String(o.formatPrice(e,{...t}))}catch{}return J.format(e)},ie=(e,t)=>(e>0?"+":e<0?"-":"")+t(Math.abs(e));let ae=null;const re=t=>{const o=e.chart.timezone();if(ae?.zone!==o){let t=null;try{t=new Intl.DateTimeFormat(e.locale,{timeZone:o,timeStyle:"medium"})}catch{}ae={zone:o,format:t}}try{if(null!==ae.format)return ae.format.format(new Date(t))}catch{}return new Date(t).toISOString()},se=(e,t)=>{e.textContent!==t&&(e.textContent=t)};function le(){U||H||(U=!0,queueMicrotask(()=>{U=!1,_e()}))}function ce(){if(H)return;const e=!0===n.hidden;Z.setVisible(e?[]:q.map(e=>G.get(e)).filter(e=>null===ee||V.has(e.el)).map(e=>e.entry))}function de(e){L.textContent=e,L.hidden=""===e}function ue(t){de(t instanceof Error&&"WatchlistConflictError"===t.name?a("conflict","The watchlists changed in another session. The saved lists are shown."):Ct(e,t)),ye()}function pe(e,t=!1){if(H||!t&&null!==z&&e.revision<z.revision)return;z=e,K=!1;const o=new Set(e.lists.map(e=>e.id));N=null!==e.activeListId&&o.has(e.activeListId)?e.activeListId:null!==N&&o.has(N)?N:e.lists[0]?.id??null,he()}function he(){const e=te()?.entries??[],t=new Set(e.map(ml));for(const[e,o]of G)t.has(e)||(ee?.unobserve(o.el),V.delete(o.el),o.el.remove(),G.delete(e));for(const t of e){const e=ml(t);G.has(e)?G.get(e).entry=t:G.set(e,me(t))}q=q.filter(e=>t.has(e));for(const t of e)q.includes(ml(t))||q.push(ml(t));_e(),ce()}function me(e){const t=qo(n,"tr","oac-watchlist__row");t.dataset.symbol=e.symbol,t.dataset.exchange=e.exchange;const s=qo(n,"th","oac-watchlist__instrument");s.setAttribute("scope","row");const l=qo(n,"button","oac-watchlist__open");l.type="button",l.setAttribute("aria-label",r(e)),l.appendChild(qo(n,"span","oac-watchlist__symbol",e.symbol)),""!==e.exchange&&l.appendChild(qo(n,"span","oac-watchlist__exchange",e.exchange));const c={entry:e,el:t,open:l,last:qo(n,"td","oac-watchlist__last"),change:qo(n,"td","oac-watchlist__change"),percent:qo(n,"td","oac-watchlist__percent")};l.addEventListener("click",()=>o.onSelect?.({...c.entry})),l.addEventListener("keydown",e=>function(e,t){if("ArrowDown"!==e.key&&"ArrowUp"!==e.key)return;e.preventDefault(),e.stopPropagation();const o="ArrowDown"===e.key?1:-1;if(e.altKey)return void("list"===R.key&&function(e,t){ge=ge.then(async()=>{const o=te();if(H||null===o||null===z||"list"!==R.key)return;const n=o.entries.findIndex(t=>gl(t,e)),a=n+t;if(!(n<0||a<0||a>=o.entries.length)){de("");try{await i.moveEntry(o.id,e,a,{expectedRevision:z.revision})}catch(e){ue(e)}}}).catch(()=>{})}(t.entry,o));const n=q.indexOf(ml(t.entry));G.get(q[n+o])?.open.focus()}(e,c)),s.appendChild(l);const d=qo(n,"td","oac-watchlist__actions");return d.appendChild(Ko(n,{label:a("remove","Remove {name}",{name:r(e)}),icon:"close",iconOnly:!0,onClick:()=>{!async function(e){const t=te();if(null===t)return;de("");try{await i.removeEntry(t.id,e)}catch(e){ue(e)}}(c.entry)}})),t.append(s,c.last,c.change,c.percent,d),D.appendChild(t),ee?.observe(t),c}let ge=Promise.resolve();function fe(){const e=te()?.entries??[];if("list"===R.key)return e.map(ml);const t="ascending"===R.direction?1:-1,o=e=>{if("symbol"===R.key)return e.symbol;const t=Z.row(e).quote;return null===t?null:"last"===R.key?t.last:cl(t)?.["change"===R.key?"change":"percent"]??null};return e.map((e,t)=>({key:ml(e),index:t,value:o(e)})).sort((e,o)=>{if(null===e.value||null===o.value)return e.value===o.value?e.index-o.index:null===e.value?1:-1;const n="string"==typeof e.value?e.value.localeCompare(o.value):e.value-o.value;return 0!==n?n*t:e.index-o.index}).map(e=>e.key)}function be(t){const o="symbol"===t?"ascending":"descending";R=R.key!==t?{key:t,direction:o}:R.direction===o?{key:t,direction:"ascending"===o?"descending":"ascending"}:{key:"list",direction:"ascending"},e.storage?.set(hl,R),fl.set(i,R),_e(),ce()}function ve(e){return{loading:a("state.loading","Loading"),live:a("state.live","Live"),delayed:a("state.delayed","Delayed"),snapshot:a("state.snapshot","Snapshot"),stale:a("state.stale","Stale"),unavailable:a("state.unavailable","No quote"),error:a("state.error","Could not load")}[e]}const we=()=>[...G.values()].some(e=>null!==Z.row(e.entry).quote);function _e(){if(H)return;const t=te(),o=z?.lists??[],i=JSON.stringify(o.map(e=>[e.id,e.name]));if(d.dataset.signature!==i){d.dataset.signature=i,d.textContent="";for(const e of o){const t=qo(n,"option",void 0,e.name);t.value=e.id,d.appendChild(t)}if(0===o.length){const e=qo(n,"option",void 0,a("noLists","No lists"));e.value="",d.appendChild(e)}}d.value=t?.id??"",d.disabled=0===o.length||K,h.disabled=m.disabled=null===t||K,p.disabled=K||o.length>=100,T.textContent=t?.name??a("title","Watchlist");const r=e.symbol(),l=!0===t?.entries.some(e=>gl(oe(e),r));S.textContent=""===r.symbol?a("addChart","Add chart symbol"):a("addCurrent","Add {symbol}",{symbol:r.symbol}),S.disabled=""===r.symbol||l||K,S.title=l?a("inList","Already in this list"):"",C.disabled=K;for(const e of G.values()){const t=Z.row(e.entry),o=t.quote;e.el.dataset.state=t.status,gl(oe(e.entry),r)?e.el.setAttribute("aria-current","true"):e.el.removeAttribute("aria-current");const n=null===o?null:cl(o);se(e.last,null!==o?ne(o.last,e.entry):"loading"===t.status?a("quoteLoading","..."):a("noQuote","n/a")),se(e.change,null===n?"":ie(n.change,t=>ne(t,e.entry))),se(e.percent,null===n?"":`${ie(n.percent,e=>Y.format(e))}%`);for(const t of[e.change,e.percent])t.classList.toggle("is-up",null!==n&&n.change>0),t.classList.toggle("is-down",null!==n&&n.change<0);const i=void 0!==o?.time?1e3*o.time:t.receivedAt,s=null===i?ve(t.status):`${ve(t.status)} ${re(i)}`;e.last.title!==s&&(e.last.title=s)}const c="list"!==R.key&&(W||B)?q.concat(fe().filter(e=>!q.includes(e))).filter(e=>G.has(e)):fe(),u=n.activeElement;c.forEach((e,t)=>{const o=G.get(e).el;D.children[t]!==o&&D.insertBefore(o,D.children[t]??null)}),null!==u&&s.contains(u)&&n.activeElement!==u&&u.focus();const g=c.join("\n")!==q.join("\n");q=c,g&&queueMicrotask(ce);for(const[e,t]of M)t.setAttribute("aria-sort",R.key===e?R.direction:"none");const f=Z.status(),b=function(e){switch(e){case"unavailable":return a("status.unavailable","No quote source. Rows show symbols only.");case"snapshot":return a("status.snapshot","Snapshot quotes");case"connecting":return a("status.connecting","Connecting to quotes");case"live":return a("status.live","Live quotes");case"reconnecting":return we()?a("status.reconnecting","Reconnecting. Quotes shown may be stale."):a("status.reconnectingEmpty","Reconnecting to quotes.");case"disconnected":return we()?a("status.disconnected","Quotes disconnected. Values shown are stale."):a("status.disconnectedEmpty","Quotes disconnected.");case"error":return a("status.error","Quotes could not refresh: {error}",{error:Z.error()??""});default:return""}}(f);se(A,b),A.hidden=""===b,A.dataset.state=f,O.hidden=K||o.length>0&&(t?.entries.length??0)>0,se(O,0===o.length?a("empty.none","No watchlists yet. Add a symbol to start one."):a("empty.list","This list is empty. Add the chart symbol or type one above.")),$.hidden=0===(t?.entries.length??0)}async function ye(){try{pe(await i.load(),!0)}catch(t){if(H)return;K=!0,de(a("loadFailed","Watchlists could not load: {error}",{error:Ct(e,t)})),_e()}}async function xe(e){de("");const t=oe(e),o=te();if(o?.entries.some(e=>gl(oe(e),t)))de(a("duplicate","{name} is already in this list",{name:r(t)}));else try{if(null===o){const e=await i.createList(a("defaultName","Watchlist"),[t]);await i.setActiveList(e.id)}else await i.addEntry(o.id,t)}catch(e){ue(e)}}function ke(){F=null,g.hidden=!0,w.hidden=!0}function Ce(e){ke(),F=e,f.value="rename"===e?te()?.name??"":a("newName","List {number}",{number:(z?.lists.length??0)+1}),g.hidden=!1,f.focus(),f.select?.()}async function Se(){const e=f.value.trim(),t=F;if(""===e||null===t)return;const o=te();ke(),de("");try{if("create"===t){const t=await i.createList(e);await i.setActiveList(t.id)}else null!==o&&await i.renameList(o.id,e)}catch(e){ue(e)}}const Ae=()=>{const e=d.value;""!==e&&e!==N&&null!==z&&(N=e,ke(),he(),i.setActiveList(e).catch(ue))};d.addEventListener("change",Ae);const Le=e=>{e.preventDefault(),Se()};g.addEventListener("submit",Le);const Oe=e=>{"Escape"!==e.key||g.hidden||(e.stopPropagation(),ke())};g.addEventListener("keydown",Oe);let $e=null;e.symbolSearch&&($e=Nn(e,C,{search:e.symbolSearch,onSelect:(t,o)=>{C.value="",xe({symbol:t,exchange:o??e.symbol().exchange})}}));const Ee=t=>{if("Enter"!==t.key||t.defaultPrevented)return;t.preventDefault();const o=C.value.trim().toUpperCase();""===o||null!==$e&&!$e.canCommitRaw()||($e?.close(),C.value="",xe({symbol:o,exchange:e.symbol().exchange}))};C.addEventListener("keydown",Ee);const Te=()=>{W=!0},Pe=()=>{W=!1,le()};D.addEventListener("pointerenter",Te),D.addEventListener("pointerleave",Pe);const je=()=>{B=!0},Me=e=>{const t=e.relatedTarget;null!==t&&D.contains(t)||(B=!1,le())};D.addEventListener("focusin",je),D.addEventListener("focusout",Me);const Ie=e=>{"Escape"!==e.key&&"Tab"!==e.key&&e.stopPropagation()},De=e=>{e.stopPropagation()};s.addEventListener("keydown",Ie),s.addEventListener("pointerdown",De);const ze=()=>ce();n.addEventListener("visibilitychange",ze);const Ne=e.chart.on("data:context",()=>le()),Re=e.chart.on("timezone:changed",()=>le()),Fe=i.subscribe(e=>pe(e));return _e(),ye(),{el:s,initialFocus:d,reload:ye,destroy:()=>{H||(H=!0,Z.destroy(),ee?.disconnect(),$e?.destroy(),Fe(),Ne(),Re(),n.removeEventListener("visibilitychange",ze),d.removeEventListener("change",Ae),g.removeEventListener("submit",Le),g.removeEventListener("keydown",Oe),C.removeEventListener("keydown",Ee),D.removeEventListener("pointerenter",Te),D.removeEventListener("pointerleave",Pe),D.removeEventListener("focusin",je),D.removeEventListener("focusout",Me),s.removeEventListener("keydown",Ie),s.removeEventListener("pointerdown",De),G.clear(),V.clear(),s.remove())}}}const vl='\n.oac-widget .oac-watchlist { display: flex; flex-direction: column; gap: 6px; height: 100%; min-height: 0; padding: 8px 10px 0; box-sizing: border-box; font-size: 12px; }\n.oac-widget .oac-watchlist__bar, .oac-widget .oac-watchlist__add, .oac-widget .oac-watchlist__name, .oac-widget .oac-watchlist__confirm { display: flex; align-items: center; gap: 4px; flex: none; min-width: 0; }\n.oac-widget .oac-watchlist__bar .oac-select { flex: 1 1 auto; min-width: 0; }\n.oac-widget .oac-watchlist__bar .oac-select select { width: 100%; min-width: 0; }\n.oac-widget .oac-watchlist .oac-btn { height: 26px; padding: 0 7px; font-size: 11px; flex: none; }\n.oac-widget .oac-watchlist__name[hidden], .oac-widget .oac-watchlist__confirm[hidden], .oac-widget .oac-watchlist__scroll[hidden] { display: none; }\n.oac-widget .oac-watchlist__name input, .oac-widget .oac-watchlist__add input { flex: 1 1 auto; min-width: 0; height: 26px; }\n.oac-widget .oac-watchlist__confirm { flex-wrap: wrap; }\n.oac-widget .oac-watchlist__confirm-text { flex: 1 1 100%; color: var(--oac-tx); overflow-wrap: anywhere; }\n.oac-widget .oac-watchlist__add-current { max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.oac-widget .oac-watchlist__status { flex: none; font-size: 11px; color: var(--oac-mut); }\n.oac-widget .oac-watchlist__status[data-state="live"] { color: var(--oac-tx); }\n.oac-widget .oac-watchlist__status[data-state="reconnecting"], .oac-widget .oac-watchlist__status[data-state="disconnected"], .oac-widget .oac-watchlist__status[data-state="error"] { color: var(--oac-danger); }\n.oac-widget .oac-watchlist__message { flex: none; font-size: 11px; color: var(--oac-danger); overflow-wrap: anywhere; }\n.oac-widget .oac-watchlist__empty { margin: 6px 0; font-size: 11px; color: var(--oac-mut); }\n.oac-widget .oac-watchlist__scroll { flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; margin: 0 -10px; }\n/* Numbers take the width they need and the symbol the rest, so a price is never the part cut short. */\n.oac-widget .oac-watchlist__table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }\n.oac-widget .oac-watchlist__table thead th { position: sticky; top: 0; z-index: 1; background: var(--oac-panel); border-bottom: 1px solid var(--oac-bd-soft); padding: 0; }\n.oac-widget .oac-watchlist__sort { width: 100%; height: 24px; padding: 0 6px; border: 0; background: none; color: var(--oac-mut); font: 600 10px/1 var(--oac-font); text-transform: uppercase; letter-spacing: .04em; text-align: right; white-space: nowrap; cursor: pointer; }\n.oac-widget .oac-watchlist__col--symbol .oac-watchlist__sort { text-align: left; padding-left: 10px; }\n.oac-widget .oac-watchlist__sort:hover, .oac-widget th[aria-sort="ascending"] .oac-watchlist__sort, .oac-widget th[aria-sort="descending"] .oac-watchlist__sort { color: var(--oac-tx); }\n.oac-widget th[aria-sort="ascending"] .oac-watchlist__sort::after { content: " \\2191"; }\n.oac-widget th[aria-sort="descending"] .oac-watchlist__sort::after { content: " \\2193"; }\n.oac-widget .oac-watchlist__col--symbol { width: 100%; }\n.oac-widget .oac-watchlist__col--actions { width: 26px; min-width: 26px; }\n.oac-widget .oac-watchlist__row { height: 28px; border-bottom: 1px solid var(--oac-bd-soft); }\n.oac-widget .oac-watchlist__row:hover, .oac-widget .oac-watchlist__row:focus-within { background: var(--oac-elev); }\n/* On the cell: some engines paint no shadow on a table row. */\n.oac-widget .oac-watchlist__row[aria-current="true"] > th { box-shadow: inset 2px 0 0 var(--oac-acc); }\n.oac-widget .oac-watchlist__row td, .oac-widget .oac-watchlist__row th { padding: 0 6px; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 400; }\n.oac-widget .oac-watchlist__row .oac-watchlist__instrument { padding: 0; max-width: 0; text-align: left; }\n.oac-widget .oac-watchlist__open { display: block; width: 100%; height: 28px; line-height: 28px; padding: 0 6px 0 10px; border: 0; background: none; color: var(--oac-tx); font: inherit; text-align: left; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }\n.oac-widget .oac-watchlist__symbol { font-weight: 600; }\n.oac-widget .oac-watchlist__exchange { margin-left: 5px; font-size: 10px; color: var(--oac-mut); }\n.oac-widget .oac-watchlist__last { color: var(--oac-tx); }\n/* The theme\'s own pair, lifted to read as text. A fallback colour here would pin one palette. */\n.oac-widget .oac-watchlist .is-up { color: var(--oac-up); }\n.oac-widget .oac-watchlist .is-down { color: var(--oac-down); }\n.oac-widget .oac-watchlist__row[data-state="stale"] td, .oac-widget .oac-watchlist__row[data-state="unavailable"] td, .oac-widget .oac-watchlist__row[data-state="error"] td, .oac-widget .oac-watchlist__row[data-state="loading"] td { color: var(--oac-mut); }\n.oac-widget .oac-watchlist__row[data-state="stale"] .oac-watchlist__last { text-decoration: underline dotted; text-underline-offset: 3px; }\n.oac-widget .oac-watchlist__actions { padding: 0 4px 0 0 !important; }\n.oac-widget .oac-watchlist__actions .oac-btn { width: 22px; height: 22px; padding: 0; border-color: transparent; background: transparent; color: var(--oac-mut); opacity: 0; }\n.oac-widget .oac-watchlist__row:hover .oac-watchlist__actions .oac-btn, .oac-widget .oac-watchlist__row:focus-within .oac-watchlist__actions .oac-btn { opacity: 1; }\n.oac-widget .oac-panel-dock[data-sheet="true"] .oac-watchlist__actions .oac-btn { opacity: 1; width: 32px; height: 32px; }\n.oac-widget .oac-panel-dock[data-sheet="true"] .oac-watchlist__row, .oac-widget .oac-panel-dock[data-sheet="true"] .oac-watchlist__open { height: 40px; line-height: 40px; }\n@media (hover: none) { .oac-widget .oac-watchlist__actions .oac-btn { opacity: 1; } }\n';function wl(e,t,o){const n=e.document,i=o.source,a=o.locale??e.locale,r=Ke(n,"span","oac-account",{role:"group","aria-label":kt(e,"Account")}),s=Ke(n,"button","oac-account__pick",{type:"button","aria-haspopup":"menu"}),l=Ke(n,"span","oac-account__name"),c=Ke(n,"span","oac-chev");c.innerHTML=ie("chevron-down"),s.appendChild(l),s.appendChild(c),r.appendChild(s);const d=(e,t)=>{const o=Ke(n,"span",`oac-account__field ${e}`),i=Ke(n,"i");i.textContent=t;const a=Ke(n,"b");return o.appendChild(i),o.appendChild(a),r.appendChild(o),{el:o,val:a}},u=d("oac-account__equity",kt(e,"Equity")),p=d("oac-account__used",kt(e,"Margin used")),h=d("oac-account__available",kt(e,"Available")),m=Ke(n,"span","oac-account__state");r.appendChild(m);const g=t.querySelector(".oac-statusline__tz");null!==g&&g.parentNode===t?t.insertBefore(r,g):t.appendChild(r),t.classList.add("oac-has-account");const f=new Map,b=(e,t)=>{e.textContent!==t&&(e.textContent=t)},v=(e,t)=>{e.hidden===t&&(e.hidden=!t)},w=(e,t,o)=>{v(e.el,null!==o&&void 0!==t),null!==o&&void 0!==t&&b(e.val,((e,t)=>{const o=t??"";let n=f.get(o);if(void 0===n){const e={minimumFractionDigits:2,maximumFractionDigits:2};try{n=new Intl.NumberFormat(a,void 0===t?e:{...e,style:"currency",currency:t})}catch{n=new Intl.NumberFormat(a,e)}f.set(o,n)}return n.format(e)})(t,o.currency))};let _=null;const y=()=>{const t=i.getState();r.dataset.status=t.status;const o="unsupported"===t.status;r.classList.toggle("is-disabled",o),o?r.setAttribute("aria-disabled","true"):r.removeAttribute("aria-disabled");const a=t.accounts.find(e=>e.id===t.selectedId),c=void 0===a?kt(e,"Account"):a.name??a.id;b(l,c),s.setAttribute("aria-label",void 0===a?c:kt(e,"Account: {name}",{name:c})),s.disabled=o||0===t.accounts.length;const d=!o&&"analyzer"===t.mode;d&&null===_?(_=Ke(n,"span","oac-account__tag"),_.textContent=kt(e,"Analyzer"),r.insertBefore(_,u.el)):d||null===_||(_.remove(),_=null);const g=o?null:t.snapshot;w(u,g?.equity,g),w(p,g?.marginUsed,g),w(h,g?.marginAvailable,g),s.title=[u,p,h].filter(e=>!e.el.hidden).map(e=>`${e.el.firstChild?.textContent??""} ${e.val.textContent??""}`).join(", ");const f=o||"error"===t.status?t.reason??"":"stale"===t.status?kt(e,"Stale"):"loading"===t.status?kt(e,"Loading account"):"";b(m,f),m.title=t.reason??"",m.classList.toggle("is-error","error"===t.status),m.classList.toggle("is-stale","stale"===t.status),v(m,""!==f)},x=()=>{const t=i.getState();"unsupported"!==t.status&&0!==t.accounts.length&&rn(e,s,t.accounts.map(o=>({label:o.name??o.id,sub:o.id,on:o.id===t.selectedId,onSelect:()=>{const t=t=>{e.toast(kt(e,"Could not switch account: {error}",{error:t}),"error")};i.select(o.id).then(e=>{e.ok||!0===e.cancelled||t(e.reason)},o=>t(Ct(e,o)))}})),{ariaLabel:kt(e,"Accounts")})};s.addEventListener("click",x);const k=i.subscribe(y);return y(),{el:r,refresh:y,destroy:()=>{k(),s.removeEventListener("click",x),t.classList.remove("oac-has-account"),r.remove()}}}const _l='\n.oac-widget .oac-statusline.oac-has-account{container:oac-status/inline-size}\n.oac-widget .oac-statusline.oac-has-account .oac-statusline__time{flex:0 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis}\n.oac-widget .oac-statusline .oac-account{flex:none}\n.oac-widget .oac-account>.oac-account__pick,.oac-widget .oac-account>.oac-account__tag,.oac-widget .oac-account>.oac-account__field{flex:none}\n.oac-widget .oac-account{display:inline-flex;align-items:center;gap:10px;min-width:0;white-space:nowrap;font-variant-numeric:tabular-nums}\n.oac-widget .oac-account__pick{display:inline-flex;align-items:center;gap:4px;max-width:180px;height:20px;padding:0 6px;border:1px solid var(--oac-bd);border-radius:5px;background:var(--oac-elev);color:var(--oac-tx-strong);font-size:11.5px;font-weight:600}\n.oac-widget .oac-account__pick:hover:not(:disabled){border-color:var(--oac-bd-hover)}\n.oac-widget .oac-account__pick:disabled{cursor:not-allowed;color:var(--oac-faint)}\n.oac-widget .oac-account__name{min-width:0;overflow:hidden;text-overflow:ellipsis}\n.oac-widget .oac-account__pick .oac-chev{display:inline-grid;width:10px;height:10px;color:var(--oac-mut)}\n.oac-widget .oac-account__tag{padding:0 5px;border:1px solid var(--oac-bd-soft);border-radius:4px;color:var(--oac-amber);font-size:10px;font-weight:600;letter-spacing:.5px;text-transform:uppercase}\n.oac-widget .oac-account__field{display:inline-flex;align-items:center;gap:4px}\n.oac-widget .oac-account__field>i{font-style:normal;color:var(--oac-faint)}\n.oac-widget .oac-account__field>b{font-weight:500;color:var(--oac-tx)}\n.oac-widget .oac-account__state{min-width:0;max-width:320px;overflow:hidden;text-overflow:ellipsis;color:var(--oac-mut)}\n.oac-widget .oac-account__state.is-stale{color:var(--oac-amber)}\n.oac-widget .oac-account__state.is-error{color:var(--oac-danger)}\n.oac-widget .oac-account.is-disabled .oac-account__state{color:var(--oac-faint)}\n.oac-widget .oac-account[data-status="stale"] .oac-account__field>b{color:var(--oac-mut)}\n@container oac-status (max-width:1180px){.oac-widget .oac-account__used{display:none}}\n@container oac-status (max-width:1000px){.oac-widget .oac-account__equity{display:none}}\n@container oac-status (max-width:860px){.oac-widget .oac-account__available{display:none}\n.oac-widget .oac-statusline .oac-statusline__title{order:-2}.oac-widget .oac-statusline .oac-account{order:-1}}\n',yl=rs+Er+Vs+el+ni+Rn+ol+jo+"\n.oac-widget .oac-pick .oac-dialog__body { display: flex; flex-direction: column; overflow: hidden; }\n.oac-widget .oac-pick__findwrap { flex: none; }\n.oac-widget .oac-pick__running-head { flex: none; padding: 1px 6px 3px; }\n.oac-widget .oac-pick__running { display: grid; align-content: start; gap: 1px; flex: 0 1 auto; min-height: 31px; max-height: 132px; }\n.oac-widget .oac-pick__list { flex: 1 1 auto; max-height: 300px; margin-top: 8px; padding-top: 4px; border-top: 1px solid var(--oac-bd); }\n.oac-widget .oac-pick__list, .oac-widget .oac-pick__running { overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--oac-sb-thumb) var(--oac-panel); }\n.oac-widget .oac-pick :is(.oac-pick__list, .oac-pick__running)::-webkit-scrollbar { width: 6px; }\n.oac-widget .oac-pick :is(.oac-pick__list, .oac-pick__running)::-webkit-scrollbar-track { background: var(--oac-panel); }\n.oac-widget .oac-pick :is(.oac-pick__list, .oac-pick__running)::-webkit-scrollbar-thumb { background: var(--oac-sb-thumb); border-radius: 3px; }\n.oac-widget .oac-pick :is(.oac-pick__list, .oac-pick__running)::-webkit-scrollbar-thumb:hover { background: var(--oac-sb-thumb-hover); }\n.oac-widget .oac-pick__running-row { display: flex; align-items: center; gap: 7px; min-height: 29px; padding: 2px 6px; }\n.oac-widget .oac-pick__running-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.oac-widget .oac-pick__running-number { min-width: 16px; color: var(--oac-mut); font-size: 11px; text-align: right; }\n.oac-widget .oac-pick__running-row .oac-pick__remove { height: 23px; min-height: 23px; padding: 2px 6px; }\n"+ds+il+vl+Hs+_l+Ns+Ka+er+Ss+"\n.oac-widget .oac-topbar__layouts { max-width: 190px; }\n.oac-widget .oac-topbar__layouts-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n/* The name gives way before the bar wraps to a second row: the glyph, the unsaved mark, the tip and the\n accessible name still carry it. Measured on the default bar, which needs about 1000 px on one row. */\n.oac-widget .oac-topbar.has-layouts { container: oac-topbar / inline-size; }\n@container oac-topbar (max-width: 1199px) { .oac-widget .oac-topbar__layouts-name { max-width: 96px; } }\n@container oac-topbar (max-width: 1139px) { .oac-widget .oac-topbar__layouts-name { display: none; } }\n.oac-widget .oac-topbar__layouts[data-attention=\"true\"]::after { content: ''; width: 6px; height: 6px; flex: none; border-radius: 50%; background: var(--oac-amber); }\n"+$s+'\n.oac-widget .oac-timeframe-menu{display:flex;flex-direction:column;width:260px;max-width:calc(100% - 16px);padding:6px;max-height:calc(100% - 16px);overflow:hidden}\n.oac-widget .oac-timeframe-menu>[data-add-interval]{display:flex;flex-shrink:0;gap:8px;width:100%;justify-content:flex-start;min-height:34px}\n.oac-widget .oac-timeframe-menu__body{min-height:0;max-height:min(65vh,560px);overflow:auto;scrollbar-width:thin;scrollbar-color:var(--oac-sb-thumb) transparent}\n.oac-widget .oac-timeframe-menu__body::-webkit-scrollbar{width:6px}.oac-widget .oac-timeframe-menu__body::-webkit-scrollbar-thumb{background:var(--oac-sb-thumb);border-radius:3px}\n.oac-widget .oac-timeframe-menu__body::-webkit-scrollbar-thumb:hover{background:var(--oac-sb-thumb-hover)}\n.oac-widget .oac-timeframe-menu__group{border-top:1px solid var(--oac-bd);padding:5px 0}\n.oac-widget .oac-timeframe-menu .oac-timeframe-menu__heading{width:100%;display:flex;justify-content:space-between;text-transform:uppercase;font-size:10px;letter-spacing:.06em;color:var(--oac-mut);min-height:28px;background:transparent;border-color:transparent}\n.oac-widget .oac-timeframe-menu__row{display:flex;align-items:center;border-radius:4px;min-height:34px}\n.oac-widget .oac-timeframe-menu__row:hover,.oac-widget .oac-timeframe-menu__row:focus-within{background:var(--oac-elev-2)}\n.oac-widget .oac-timeframe-menu__row[data-selected="true"]{background:var(--oac-on-bg)}\n.oac-widget .oac-timeframe-menu__pick[aria-pressed]{background:transparent;border-color:transparent;flex:1;text-align:left;min-height:34px;justify-content:flex-start}\n.oac-widget .oac-timeframe-menu__actions{display:grid;grid-template-columns:28px 28px;flex:none;gap:2px}\n.oac-widget .oac-timeframe-menu__actions .oac-btn{background:transparent;border-color:transparent;width:28px;height:28px;padding:5px}.oac-widget .oac-timeframe-menu__actions [hidden]{display:block;visibility:hidden;pointer-events:none}\n.oac-widget .oac-timeframe-dialog{width:340px;max-width:calc(100% - 24px);max-height:calc(100% - 24px);overflow:auto;padding:14px}\n.oac-widget .oac-timeframe-dialog__header,.oac-widget .oac-timeframe-dialog__footer{display:flex;align-items:center;justify-content:space-between;gap:10px}\n.oac-widget .oac-timeframe-dialog__header h3{font-size:15px;margin:0}.oac-widget .oac-timeframe-dialog__fields{display:grid;gap:12px;margin-top:20px}\n.oac-widget .oac-timeframe-dialog__fields label{display:grid;grid-template-columns:80px 1fr;align-items:center;gap:12px}\n.oac-widget .oac-timeframe-dialog__unit{position:relative;display:block}.oac-widget .oac-timeframe-dialog__unit .oac-glyph{position:absolute;right:8px;top:8px;pointer-events:none}\n.oac-widget .oac-timeframe-dialog__unit select{padding-right:30px}\n.oac-widget .oac-timeframe-dialog__fields input,.oac-widget .oac-timeframe-dialog__fields select{width:100%;min-width:0;background:var(--oac-bg);color:var(--oac-tx);border:1px solid var(--oac-bd);border-radius:4px;padding:7px;appearance:none}\n.oac-widget .oac-timeframe-dialog__error{min-height:30px;padding:8px 0;font-size:11px;color:var(--oac-mut)}\n.oac-widget .oac-timeframe-dialog__footer{justify-content:flex-end}.oac-widget .oac-timeframe-dialog__footer button{min-width:58px;min-height:30px}\n',xl=e=>e instanceof Error?e:new Error(String(e));function kl(e){return function(e,t){const o=e._opts,n=e.chart,i=o.ranges??hs,a=o.sessionCalendar;let r=null,s=null;const l=(e,t)=>{if("function"!=typeof a)return a??null;const o=`${t}\0${e}`;if(o!==r){r=o;try{s=""===e?null:a({symbol:e,exchange:t})??null}catch{s=null}}return s},c=()=>void 0===a?n.dataLayer.sessionCalendar:l(e._symbol,e._exchange);if(void 0!==a){const t=()=>{n.isDestroyed||(n.setSessionCalendar(l(e._symbol,e._exchange)),e._statusline?.refresh())};t(),e._cleanups.push(e._bus.on("symbol",t))}if(!1!==o.sessionShading){const t=H(n);e._cleanups.push(()=>t.destroy())}e._cleanups.push(n.on("timezone:changed",()=>{e._destroyed||(e._scheduleSave(),e._bus.emit("layout",{reason:"timezone"}))}));let d=null,u=!1,p=0;const h=()=>{const t=d;return null===t||t.interval!==e._interval?null:i.find(e=>e.id===t.id)??null},m=e=>{const t=n.primaryBars(),o=t[t.length-1];if(void 0===o)return e;const i=n.dataLayer.timeToIndex(o.time)??t.length-1,a=n.getVisibleLogicalRange(),r=i+.5-(a.to-a.from);return n.setVisibleLogicalRange({from:r,to:i+.5}),{...e,from:n.dataLayer.indexToTime(Math.ceil(r+.5))??e.from,to:o.time}},g=async(t,o)=>{for(let t=0;t<4&&null!==e._loading;t++){try{await e._loading}catch{}if(o!==p||e._destroyed)return{status:"cancelled"}}if(o!==p||e._destroyed)return{status:"cancelled"};const i=n.primaryBars();if(0===i.length)return{status:"no-data"};const a="all"===t.unit,r=ws(t,{end:i[i.length-1].time,zone:n.timezone(),calendar:c(),bars:a?void 0:i});let s=await e.goTo(r);return o!==p||e._destroyed?s:(!a||"partial"!==s.status||"exhausted"!==s.history&&"empty"!==s.history||(s={status:!0===s.clipped?"partial":"placed",from:s.from,to:s.to,...!0===s.clipped?{clipped:!0}:{}}),"partial"===s.status&&!0===s.clipped?m(s):s)},f=async t=>{const o=i.find(e=>e.id===t);if(void 0===o||e._destroyed)return{status:"invalid"};const n=++p,a=gs(o,e._intervals);d={id:t,interval:a},u=!0;try{e.setInterval(a)}catch(e){return d=null,{status:"error",error:xl(e)}}finally{u=!1}return g(o,n)};e._cleanups.push(e._bus.on("interval",()=>{u||(d=null,p++)}));const b=()=>{const e=h();null!==e&&g(e,++p)};e._cleanups.push(e._bus.on("symbol",b)),e._cleanups.push(e._bus.on("variant",b));const v=(e,t)=>{const o=h();if(null===o)return e;const i=ws(o,{end:t,zone:n.timezone(),calendar:c()});return{from:Math.min(i.from,e.from),to:e.to}};let w;if(!1!==o.bottombar){const a=Ke(e.context.document,"div","oac-bottombar");!1===o.topbar&&a.classList.add("is-kept"),e.root.insertBefore(a,t),e.root.classList.add("has-bottombar");const r=Cs(e.context,a,{target:()=>({chart:n,interval:()=>e._interval,range:()=>h()?.id??null,setRange:f}),ranges:i,onGoTo:t=>e._openGoTo(t),now:()=>(o.now??Date.now)()});w=r.controls,e._cleanups.push(()=>{r.destroy(),a.remove(),e.root.classList.remove("has-bottombar")})}return{setRange:f,range:()=>h()?.id??null,fetchWindow:v,controls:w}}(this,e)}const Cl=["1m","5m","15m","1h","1d","1w"],Sl=500,Al=250,Ll="state",Ol="drawings:",$l=1,El=new WeakMap,Tl=["feed","symbol","exchange","interval","variant","intervals","chartType","theme","rail","topbar","statusline","mobile","loading","persist","storage","timeframePreferences","canSelectInterval","drawingScope","drawingStore","locale","translate","indicators","symbolSearch","lookbackBars","now","onOrder","styleNonce","tradingCapabilities","tradingMode","tradingLocked","account","eventDetails","captureRows","panels","typingNavigation","keyboardRoute","watchlist","news","drawingTemplates","drawingToolbar","shortcutsEditor","workspaces","layouts","bottombar","ranges","sessionCalendar","sessionShading"];function Pl(e){return di(e)}function jl(e){return"light"===e?{theme:K,name:"light"}:"dark"===e||void 0===e?{theme:G,name:"dark"}:{theme:e,name:Sa(e)}}function Ml(t,o,n){const i=e(t),a=null!==i&&"interval"===i.bucketing.mode?i.bucketing.seconds:null;return{from:n-(null===a?15768e4:Math.max(1,Math.round(o))*a),to:n}}class Il{constructor(e,t){Object.defineProperty(this,"chart",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"draw",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"objects",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"alerts",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"history",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"drawingTemplates",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"root",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"document",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"keymap",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"bus",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"storage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"locale",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"translate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"symbolSearch",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"toast",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"openOverlay",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"status",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"tips",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"overlays",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"symbol",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"interval",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"intervals",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"settingsDefaults",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_source",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._source=e,this.chart=t.chart,this.draw=t.draw,this.objects=t.objects,this.alerts=t.alerts,this.history=t.history,this.root=t.root,this.document=t.document,this.keymap=t.keymap,this.bus=t.bus,this.storage=t.storage,this.locale=t.locale,this.translate=t.translate,this.symbolSearch=t.symbolSearch,this.toast=t.toast,this.openOverlay=t.openOverlay,this.status=t.status,this.tips=t.tips,this.overlays=t.overlays,this.symbol=t.symbol,this.interval=t.interval,this.intervals=t.intervals,this.settingsDefaults=t.settingsDefaults}get theme(){return this._source.theme()}get chartTheme(){return this._source.chartThemeInUse()}}function Dl(e,t,o){const n={...e};for(const e of Tl)delete n[e];const i={mousePan:"horizontal",...e.navigation};void 0===n.zoomAnchor&&(n.zoomAnchor="right"),n.navigation=void 0===i.defaultVisibleBars&&void 0===i.defaultBarSpacing?{...i,defaultBarSpacing:e.timeScale?.barSpacing??8}:i;const a=!0===t.defaultView?.matchMedia?.("(prefers-reduced-motion: reduce)").matches;a&&void 0===n.animZoom&&(n.animZoom=!1),a&&void 0===n.animAutoscale&&(n.animAutoscale=!1);const r=e.keyboardRoute,s=e.shortcuts;if(void 0!==r&&!1!==s){const e=s instanceof ee?s:new ee(s);n.shortcuts=new Proxy(e,{get:(e,t)=>{if("scope"===t)return"global";if("resolve"===t)return t=>r()??("global"===e.scope||o())?e.resolve(t):null;const n=Reflect.get(e,t);return"function"==typeof n?n.bind(e):n}})}return n}function zl(e,t){const o=Ke(e.document,"span","oac-tip-spot",{"aria-hidden":"true"});e.root.appendChild(o);let n=null;e.tips.attach(o,()=>null===n?null:{title:n,side:"bottom"});const i=t=>{const n=e.root.getBoundingClientRect();o.style.left=t.clientX-n.left+"px",o.style.top=t.clientY-n.top+"px"};t.addEventListener("pointermove",i);const a=e.chart.on("hover",t=>{const i=t.id;n=null===i?null:(t=>{const o=t.lastIndexOf("::");if(o<0)return null;const n=t.slice(0,o),i=t.slice(o+2);if(/^(?:ord|order):/.test(n))return"close"===i?kt(e,"Cancel order"):null;if(/^(?:pos|position):/.test(n))return"close"===i?kt(e,"Close position"):null;const a=n.startsWith("indicator:")?e.chart.indicators().find(e=>e.id===n.slice(10)):void 0;if(void 0===a)return null;const r=a.name;return"hide"===i?kt(e,a.visible()?"Hide {name}":"Show {name}",{name:r}):"settings"===i?kt(e,"Settings for {name}",{name:r}):"close"===i?kt(e,"Remove {name}",{name:r}):null})(i),null!==n?e.tips.show(o):e.tips.target()===o&&e.tips.hide()});return()=>{a(),t.removeEventListener("pointermove",i),o.remove()}}class Nl{_initTimeframes(e){const t=new Set(this._timeframePreferences.custom()),o=new Set(e.intervals??[...Cl,...u().map(e=>e.code).filter(e=>!t.has(e))]);o.add(this._interval),this._intervals.push(...o);const n=this._intervals.filter(o=>!t.has(o)||e.intervals?.includes(o)),i=()=>{this._intervals.splice(0,this._intervals.length,...new Set([...n,...this._timeframePreferences.custom()]))};return i(),this._cleanups.push(this._timeframePreferences.subscribe(i)),e.canSelectInterval??(t=>{const o=e.feed;if(o&&"resolve"in o&&"function"==typeof o.resolve)try{return o.resolve({symbol:this._symbol,exchange:this._exchange,interval:t}),!0}catch{return!1}return n.includes(t)})}constructor(e,t){Object.defineProperty(this,"dataController",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"chart",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"draw",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"instrumentDrawings",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"drawingTemplates",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"objects",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"alerts",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"history",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"root",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"context",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"ready",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_series",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_doc",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_opts",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_bus",{enumerable:!0,configurable:!0,writable:!0,value:new Ai}),Object.defineProperty(this,"_storage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_timeframePreferences",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_keymap",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_toasts",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_chartEl",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_rail",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_topbar",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_statusline",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_mobile",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_drawbar",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_objectsPanel",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_dock",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_quickEntry",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_alertsPanel",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_goToPanel",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_layouts",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_navigator",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_bottombar",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_navigation",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_loading",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_anchoring",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_intervals",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_symbol",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_exchange",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_interval",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_variant",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_chartType",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_chartTypeRequest",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_themeName",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_chartTheme",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_pointerInside",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_pointerInChart",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_dataStatus",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_displayedBars",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_dataState",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_initialView",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"_pendingView",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_keepView",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_saveTimer",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_restoring",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_holdDrawings",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_saveWanted",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_stateGiven",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_destroyed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_cleanups",{enumerable:!0,configurable:!0,writable:!0,value:[]}),this._opts=t,this.dataController=t.feed?new V(t.feed,{now:()=>Math.floor((t.now??Date.now)()/1e3),...t.loading}):null,this._navigator=new Kn({chart:()=>this.chart,loadHistory:e=>this._loadHistory(e)});const n=t.document??e.ownerDocument;this._doc=n,Na(n,yl,t.styleNonce);const i="string"==typeof t.persist?t.persist:"default",a=t.persist?void 0===t.storage?Rt():t.storage:null;this._storage=new nt(i,a,{onError:e=>$i.call(this,e)}),this._timeframePreferences=t.timeframePreferences??Ue(this._storage,t.intervals??Cl),t.timeframePreferences||this._cleanups.push(()=>this._timeframePreferences.destroy()),this._restoring=!this._storage.loaded,this._holdDrawings=this._restoring;const r=yi.call(this);this._symbol=(t.symbol??r?.symbol??"").toUpperCase(),this._exchange=t.exchange??r?.exchange??"",this._interval=function(e,t){void 0!==e.interval&&o(e.interval);for(const t of e.intervals??[])o(t);const n=null!==t&&$(t.interval)?t.interval:"1d";return e.interval??n}(t,r),this._variant=void 0!==t.variant?O(t.variant):r?.variant;const s=t.chartType??r?.chartType??"candlestick";if(void 0!==t.chartType&&!jn(t.chartType))throw new Error(`openalgo-charts widget: "${t.chartType}" is not a registered chart type`);this._chartType=jn(s)?s:"candlestick";const l=jl(t.theme??r?.theme);this._themeName=l.name,this._chartTheme=l.theme;const c=this._initTimeframes(t),d=Ke(n,"div","oac-widget");d.dataset.theme=this._themeName,Ma(d,ja(this._chartTheme,this._themeName)),this.root=d;const u=Ke(n,"div","oac-topbar");!1===t.topbar&&(u.hidden=!0),d.appendChild(u);const p=Ke(n,"div","oac-stage");d.appendChild(p);const m=Ke(n,"div","oac-rail");!1===t.rail&&(m.hidden=!0),p.appendChild(m);const g=Ke(n,"div","oac-chart");this._chartEl=g,p.appendChild(g);const f=Ke(n,"div","oac-statusline");!1===t.statusline&&(f.hidden=!0),d.appendChild(f);const b=Ke(n,"div","oac-toasts");d.appendChild(b),e.appendChild(d),this.chart=J(g,{...Dl(t,n,()=>this._inChart()),theme:this._chartTheme,document:n}),g.setAttribute("aria-label",t.ariaLabel??kt(t,"Price chart"));const v=this._transformFor(this._chartType,void 0===t.chartType?r?.chart:void 0);this._series=this.chart.addSeries(null===v?this._chartType:P(v.type).renderer,null===v?{}:{transform:v}),this._publishDataContext(),this.draw=new Ie(this.chart,{}),this.instrumentDrawings="chart"===t.drawingScope?null:hi.call(this,r),this.alerts=new Y(this.chart,{drawings:this.draw}),this.objects=new Z(this.chart,{drawings:this.draw,drawingName:e=>kt(t,`schema.drawing.${e}.name`,{},mn(e)),onSettings:e=>{"source"===e.kind?this.openSettings():"indicator"===e.kind?Ir(this.context,void 0,{instanceId:e.sourceId}):"drawing"===e.kind&&fr(this.context,void 0,{ids:[e.sourceId]})}}),this.history=new Xt(this.chart,{draw:this.draw,series:()=>this._series,setChartType:e=>this.setChartType(e),onError:({direction:e,error:t})=>{const o=Ct(this.context,t);this._toasts.toast(kt(this.context,"undo"===e?"That step could not be undone: {error}":"That step could not be redone: {error}",{error:o}),"error")}});const w=rt(d,n),_=lt(d,w.layer,n);this._toasts=ma(b,n,t);const y=this.chart.shortcuts;if(this._keymap=new yo({chart:y,scopes:()=>ii.call(this)}),this._keymap.onConflict(e=>this._bus.emit("keymap:conflict",{combo:e.combo,kept:e.kept,shadowed:e.shadowed})),this.context=this._createContext(d,n,t,w,_),this._cleanups.push(()=>{_.destroy(),w.destroy()}),this._cleanups.push(zl(this.context,g)),!1!==t.eventDetails&&this._cleanups.push(function(e,t,o){const n=e.chart,i=!1===o.eventDetails?void 0:o.eventDetails,a=new Ys(t,{styleNonce:o.styleNonce,overlays:e.overlays,formatTime:e=>{const t=new Date(1e3*e);return Number.isFinite(t.getTime())?new Intl.DateTimeFormat(o.locale,{timeZone:n.timezone(),dateStyle:"medium",timeStyle:"short"}).format(t):String(e)},...i,labels:{...Js(e),...i?.labels},injectStyles:!1}),r=[n.on("event:click",e=>{const t=e;a.open(t,t.point)}),n.on("data:context",()=>a.close()),n.on("events:change",()=>a.close())];return()=>{for(const e of r)e();a.destroy()}}(this.context,g,t)),this._dataStatus=function(e,t,o,n){const i=Ke(e.document,"div","oac-data-status");i.setAttribute("role","status"),i.setAttribute("aria-live","polite"),i.setAttribute("aria-atomic","true"),i.hidden=!0,t.appendChild(i);let a=o?.getState()??null,r="",s=!1;const l=e=>e.stopPropagation();for(const e of["pointerdown","wheel","keydown"])i.addEventListener(e,l);const c=()=>{if(s)return;const t=[];if(null!==a){const i=a.request?.symbol??"",r=a.request?.interval??"";switch(a.status){case"loading":t.push({text:kt(e,"Loading {symbol} {interval}",{symbol:i,interval:r})});break;case"refreshing":t.push({text:kt(e,"Refreshing {symbol} {interval}",{symbol:i,interval:r})});break;case"empty":t.push({text:kt(e,"No bars for {symbol} {interval}",{symbol:i,interval:r}),label:kt(e,"Retry chart data"),retry:n});break;case"stale":t.push({text:kt(e,"History is stale for {symbol} {interval}",{symbol:i,interval:r}),label:kt(e,"Retry chart data"),retry:n});break;case"error":t.push({text:kt(e,"Could not load {symbol} {interval}",{symbol:i,interval:r}),label:kt(e,"Retry chart data"),retry:n});break;case"unsupported":t.push({text:kt(e,"Not available from this source: {variant}",{variant:_n(e,a.request?.variant,a.unsupported)})})}"limited"===a.historyStatus?t.push({text:kt(e,"History retention limit reached")}):"loading"===a.historyStatus?t.push({text:kt(e,"Loading older history")}):"error"===a.historyStatus&&t.push({text:kt(e,"Could not load older history"),label:kt(e,"Retry older history"),retry:()=>{o?.loadMore()}})}for(const o of e.chart.indicators()){const n=o.dataStatus();if(null===n||"ready"===n.state)continue;if("error"===n.state&&n.error instanceof h){const i=Ct(e,n.error);t.push({text:i.startsWith(`${o.name}: `)?i:kt(e,"{name}: {error}",{name:o.name,error:i})});continue}const i={loading:kt(e,"Loading"),empty:kt(e,"No data"),unsupported:kt(e,"Unsupported"),error:kt(e,"Could not load")}[n.state];t.push({text:`${o.name}: ${i}`,label:kt(e,"Retry {name}",{name:o.name}),retry:"loading"===n.state?void 0:()=>o.retryData()})}const l=JSON.stringify(t.map(e=>[e.text,e.label,!!e.retry]));if(r!==l){r=l,i.textContent="",i.hidden=0===t.length;for(const o of t){const t=Ke(e.document,"div","oac-data-status__row"),n=Ke(e.document,"span","oac-data-status__text");if(n.textContent=o.text,t.appendChild(n),o.retry){const n=Ke(e.document,"button","oac-btn");n.textContent=kt(e,"Retry"),n.type="button",n.setAttribute("aria-label",o.label),n.addEventListener("click",o.retry),t.appendChild(n)}i.appendChild(t)}}},d=()=>{c(),queueMicrotask(c)},u=["indicator:data-status","indicatorRemoved"].map(t=>e.chart.on(t,d));return c(),{el:i,update:e=>{a=e,c()},destroy:()=>{s=!0;for(const e of u)e();for(const e of["pointerdown","wheel","keydown"])i.removeEventListener(e,l);i.remove()}}}(this.context,p,this.dataController,()=>{this.reload()}),!1!==t.panels&&(this._dock=oi(this.context,p,{data:e=>Xs(this.context,e),objects:e=>{const t=Or(this.context);return e.appendChild(t.element),t},...t.watchlist?{watchlist:e=>bl(this.context,e,{...t.watchlist,onSelect:e=>this.setSymbol(e.symbol,e.exchange),normalize:e=>({symbol:e.symbol.trim().toUpperCase(),exchange:e.exchange})})}:{},...t.news?{news:e=>Us(this.context,e,t.news)}:{},onChange:()=>{this._bus.emit("layout",{reason:"panels"}),this._scheduleSave()}})),this._cleanups.push(is(this.context,{...t.onOrder?{onOrder:t.onOrder}:{},tradingCapabilities:t.tradingCapabilities,tradingMode:t.tradingMode,...t.tradingLocked?{tradingLocked:t.tradingLocked}:{}})),!1!==t.rail){const e={..."object"==typeof t.rail?t.rail:{},cursorTarget:g};this._rail=wn(this.context,m,e)}this.drawingTemplates=t.drawingTemplates?Ba(this.context,t.drawingTemplates):null,this.context.drawingTemplates=this.drawingTemplates??void 0,(t.drawingToolbar??!1!==t.rail)&&(this._drawbar=zs(this.context,p,{chart:g,templates:this.drawingTemplates}));const x=El.has(t),k=!1===t.bottombar&&!x;if(!1!==t.statusline&&(this._statusline=Pn(this.context,f,{locale:t.locale,marketStatus:k,now:t.now}),this._statusline.setSymbol(this._symbol,this._exchange,this._interval),void 0!==t.account)){const e=wl(this.context,f,{source:t.account,locale:t.locale});this._cleanups.push(()=>e.destroy())}if(this._bottombar=kl.call(this,f),this._layouts=function(e,t){const o=t.workspaces,n=!1===t.layouts?null:t.layouts??null;if(void 0===o&&null===n)return null;const i=e.context,a=Ki(i);Wi(i,o);const r=null===n&&!1!==t.layouts&&void 0!==o?Zn(o,Ni(e)):null,s=n??r,l={handle:null,waiting:null};let c=!1;const d=null===r?void 0:Vi(r,a,e=>i.status(e,"error")),u=i.document,p=u.defaultView,h=()=>{"hidden"===u.visibilityState&&r?.flush()},m=()=>{r?.flush()};return null!==r&&(u.addEventListener("visibilitychange",h),p?.addEventListener("pagehide",m),r.reload().then(async e=>{if(c||null===e.activeWorkspaceId)return;const t=await r.open(e.activeWorkspaceId);t.applied||c||i.status(a("notReopened","The last layout could not open here: {error}",{error:t.reason??""}),"error")}).catch(e=>{c||i.status(a("notLoaded","Saved layouts could not be read: {error}",{error:Ct(i,e)}),"error")})),{controller:s,open:e=>!c&&null!==s&&(Qi(i,s,e,l,()=>!c),!0),destroy(){c||(c=!0,l.handle?.close(),d?.(),u.removeEventListener("visibilitychange",h),p?.removeEventListener("pagehide",m),r?.destroy(),Wi(i,void 0))}}}(this,t),!1!==t.topbar&&(this._topbar=da(this.context,u,{intervals:this._intervals,timeframePreferences:this._timeframePreferences,canSelectInterval:c,indicators:t.indicators,search:this.context.symbolSearch,state:()=>({symbol:this._symbol,exchange:this._exchange,interval:this._interval,chartType:this.chartType(),theme:this._themeName}),onSymbol:(e,t)=>this.setSymbol(e,t),onInterval:e=>this.setInterval(e),onChartType:e=>this.setChartType(e),onTheme:e=>this.setTheme(e),onSettings:e=>this._openDialog("settings",e),onIndicators:e=>this._openDialog("indicatorPicker",e),onObjects:e=>this._openObjects(e),...!1===t.panels?{}:{onDataWindow:()=>this._dock?.toggle("data")},onAlerts:e=>this._openAlerts(e),...this._docked("watchlist")?{onWatchlist:()=>this._dock?.toggle("watchlist")}:{},...this._docked("news")?{onNews:()=>this._dock?.toggle("news")}:{},...k?{onGoTo:e=>this._openGoTo(e)}:{},layouts:this._layouts?.controller??void 0,onLayouts:e=>this._layouts?.open(e),settingsAvailable:()=>null!==wt("settings"),indicatorsAvailable:()=>null!==wt("indicatorPicker"),dataAvailable:()=>null===this.dataController||"ready"===this._dataState?.status||"stale"===this._dataState?.status,captureRows:t.captureRows})),this._mobile=Ts(this.context,{mode:t.mobile,container:e,intervals:this._intervals,timeframePreferences:this._timeframePreferences,canSelectInterval:c,topbar:!1!==t.topbar,rail:this._rail,tools:"object"==typeof t.rail?t.rail.tools:void 0,indicators:!1!==t.indicators,search:this.context.symbolSearch,state:()=>({symbol:this._symbol,exchange:this._exchange,interval:this._interval,chartType:this.chartType(),theme:this._themeName}),onSymbol:(e,t)=>this.setSymbol(e,t),onInterval:e=>this.setInterval(e),onChartType:e=>this.setChartType(e),onTheme:()=>this.setTheme("dark"===this._themeName?"light":"dark"),onSettings:e=>this._openDialog("settings",e),onIndicators:e=>this._openDialog("indicatorPicker",e),onObjects:e=>this._openObjects(e),...!1===t.panels?{}:{onDataWindow:()=>this._dock?.toggle("data")},onAlerts:e=>this._openAlerts(e),...this._docked("watchlist")?{onWatchlist:()=>this._dock?.open("watchlist")}:{},...this._docked("news")?{onNews:()=>this._dock?.open("news")}:{},...x?{}:{onGoTo:e=>this._openGoTo(e)},onProperties:e=>this._openDialog("drawingProperties",e),onCapture:e=>this._topbar?.openCapture(e),bottombar:this._bottombar.controls,...this._layouts?.controller?{onLayouts:()=>this._layouts?.open()}:{},settingsAvailable:()=>null!==wt("settings"),indicatorsAvailable:()=>null!==wt("indicatorPicker")}),ai.call(this),this._keymap.attach(n),!1!==t.typingNavigation&&(this._quickEntry=tl(this.context,{enabled:()=>!this._destroyed&&null!==this._doc.activeElement&&this._chartEl.contains(this._doc.activeElement)&&0===this.draw.selection().length,onSymbol:(e,t)=>this.setSymbol(e,t),onInterval:e=>this.setInterval(e),search:this.context.symbolSearch})),si.call(this),this._followChart(),pi.call(this,r),null!==this.dataController){this._cleanups.push(this.dataController.subscribe(e=>this._applyData(e))),this.chart.setHistoryLoader(()=>{this.dataController.loadMore().finally(()=>{this._destroyed||this.chart.historyLoadComplete()})});const e=()=>this.dataController.setVisible(!n.hidden);n.addEventListener("visibilitychange",e),this._cleanups.push(()=>n.removeEventListener("visibilitychange",e)),n.hidden&&e(),""===this._symbol||this._restoring||this.reload()}this.ready=this._restoring?Si.call(this):Promise.resolve()}_createContext(e,t,o,n,i){const a=o.symbolSearch??function(e,t){if("function"==typeof e?.searchSymbols)return async(o,n)=>{const i=await e.searchSymbols({query:o,signal:n?.signal}),a=o.trim().toUpperCase(),r=i.findIndex(e=>!e.contractGroup&&e.exchange===t()&&e.symbol.toUpperCase()===a);return r>0?[i[r],...i.slice(0,r),...i.slice(r+1)]:i}}(o.feed,()=>this._exchange);return new Il(this,{chart:this.chart,draw:this.draw,objects:this.objects,alerts:this.alerts,history:this.history,root:e,document:t,keymap:this._keymap,bus:this._bus,storage:this._storage,locale:o.locale,translate:o.translate,symbolSearch:a,toast:(e,t)=>this._toasts.toast(e,t),openOverlay:(e,t)=>n.open(e,t),status:(e,t="info")=>{this._statusline?.setMessage(e,t),this._bus.emit("status",{text:e,kind:t})},tips:i,overlays:n,symbol:()=>({symbol:this._symbol,exchange:this._exchange}),interval:()=>this._interval,intervals:void 0===o.intervals?void 0:this._intervals,settingsDefaults:{"navigation.mousePan":o.navigation?.mousePan??"horizontal"}})}get series(){return this._series}get layouts(){return this._layouts?.controller??null}get isDestroyed(){return this._destroyed}symbol(){return this._symbol}exchange(){return this._exchange}interval(){return this._interval}variant(){return this._variant}chartType(){return this.chart.seriesTransform(this._series)?.type??this.chart.seriesType(this._series)??this._chartType}_transformFor(e,t){if(!y().includes(e)||void 0===this._opts.feed&&_().includes(e))return null;const o=Array.isArray(t?.series)?t.series:[],n=o.find(t=>t?.transform?.type===e)?.transform?.options;if(void 0===n)return{type:e};try{return P(e).create(n),{type:e,options:n}}catch{return{type:e}}}theme(){return this._themeName}chartThemeInUse(){return this._chartTheme}on(e,t){return this._bus.on(e,t)}off(e,t){this._bus.off(e,t)}setSymbol(e,t){const o=e.trim().toUpperCase(),n=t??this._exchange;if(o===this._symbol&&n===this._exchange)return this._topbar?.refresh(),void this._mobile?.refresh();this._symbol=o,this._exchange=n,this._cancelNavigation(),this._keepView=!1,this._pendingView=null,null===this.dataController&&(this._series.setData([]),this._publishDataContext()),this._statusline?.setSymbol(o,n,this._interval),this._topbar?.refresh(),this._mobile?.refresh(),this._scheduleSave(),this._opts.feed&&this.reload(),this._bus.emit("symbol",{symbol:o,exchange:n}),this.chart.emit("symbol",{symbol:o,exchange:n})}setInterval(e){const t=e.trim();if(""===t)throw new Error("openalgo-charts widget: interval code must not be empty");if(o(t),t===this._interval)return this._topbar?.refresh(),void this._mobile?.refresh();this._interval=t,this._cancelNavigation(),this._keepView=!1,this._pendingView=null,null===this.dataController&&(this._series.setData([]),this._publishDataContext()),this._statusline?.setSymbol(this._symbol,this._exchange,t),this._topbar?.refresh(),this._mobile?.refresh(),this._scheduleSave(),this._opts.feed&&this.reload(),this._bus.emit("interval",{interval:t})}setDataVariant(e){const t=O(e);L(t)!==L(this._variant)&&(this._variant=t,this._cancelNavigation(),this._keepView=!1,this._pendingView=null,null===this.dataController&&(this._series.setData([]),this._publishDataContext()),this._scheduleSave(),this._opts.feed&&this.reload(),this._bus.emit("variant",{variant:t}))}setChartType(e){this._selectChartType(e)}_selectChartType(e,t){if(!jn(e))throw new Error(`openalgo-charts widget: "${e}" is not a registered chart type`);if(e===this.chartType()&&void 0===t)return;const o=this._transformFor(e,t),n=++this._chartTypeRequest;let i=this.chart.setSeriesTransform(this._series,o);n===this._chartTypeRequest&&(null===o&&(i=this.chart.setSeriesType(this._series,e)||i),i&&n===this._chartTypeRequest&&this.chartType()===e&&(this._scheduleSave(),this._bus.emit("layout",{reason:"chartType",chartType:e})))}setTheme(e){const t=jl(e);this._themeName=t.name,this._chartTheme=t.theme,this.chart.setTheme(t.theme),this.root.dataset.theme=t.name,Ma(this.root,ja(t.theme,t.name)),this._topbar?.refresh(),this._mobile?.refresh(),this._scheduleSave(),this._bus.emit("theme",{theme:t.name,chartTheme:t.theme})}openSettings(){return this._openDialog("settings")}openIndicatorPicker(){return this._openDialog("indicatorPicker")}openObjects(){return this._openObjects()}openDataWindow(){return!(this._destroyed||!this._dock)&&(this._dock.open("data"),!0)}openAlerts(){return this._openAlerts()}openWatchlist(){return this._openDocked("watchlist")}openNews(){return this._openDocked("news")}openLayouts(){return!this._destroyed&&(this._layouts?.open()??!1)}_docked(e){return!1!==this._opts.panels&&void 0!==this._opts[e]}_openDocked(e){return!(this._destroyed||!this._dock||!this._docked(e))&&(this._dock.open(e),!0)}openDateNavigation(){return this._openGoTo()}setRange(e){return this._bottombar.setRange(e)}range(){return this._bottombar.range()}_openGoTo(e){if(this._destroyed||null===Fn(this._interval))return!1;if(this._goToPanel?.isOpen())return this._goToPanel.el.focus(),!0;let t=0;return this._goToPanel=cs(El.get(this._opts)?.(this.context)??this.context,e,{navigate:e=>{const o=this.goTo(e);return t=this._navigation,o},cancel:()=>{t===this._navigation&&this._cancelNavigation()},onClose:()=>{this._goToPanel=null}}),!0}_openAlerts(e){return!this._destroyed&&(this._alertsPanel?.isOpen()?(this._alertsPanel.el.focus(),!0):(this._alertsPanel=Jr(this.context,e,{onClose:()=>{this._alertsPanel=null}}),!0))}_openObjects(e){return!this._destroyed&&(this._dock?(this._dock.open("objects"),!0):this._objectsPanel?.isOpen()?(this._objectsPanel.el.focus(),!0):(this._objectsPanel=$r(this.context,e,{onClose:()=>{this._objectsPanel=null}}),!0))}_openDialog(e,t){const o=wt(e);return null!==o&&(o(this.context,t),!0)}_publishDataContext(){const e=this.chart.getDataContext(),t=e?.symbol===this._symbol&&e.exchange===this._exchange;Q(this.chart,{symbol:this._symbol,exchange:this._exchange,interval:this._interval,...t&&void 0!==e.hasOpenInterest?{hasOpenInterest:e.hasOpenInterest}:{},...this._variant?{variant:this._variant}:{}})}async reload(){const e=this.dataController;if(null===e||this._destroyed)return;if(this._restoring)return await this.ready,void await this._loading;const t=e.getState().request;if(t?.symbol===this._symbol&&t.exchange===this._exchange&&t.interval===this._interval&&L(t.variant)===L(this._variant))return void await e.refresh();const o=this._opts.loading?.now?.()??Math.floor((this._opts.now??Date.now)()/1e3),n={symbol:this._symbol,exchange:this._exchange,interval:this._interval,...this._bottombar.fetchWindow(Ml(this._interval,this._opts.lookbackBars??500,o),o),...this._variant?{variant:this._variant}:{}};this._initialView=!0,this._displayedBars=null,this._series.setData([]),this._publishDataContext();const i=e.load(n);this._loading=i,await i,this._loading===i&&(this._loading=null)}async goTo(e){const t=++this._navigation;return this._navigator.cancel(),this._restoring&&await this.ready,null!==this._loading&&await this._loading,t!==this._navigation||this._destroyed?{status:"cancelled"}:this._navigator.goTo(e)}_cancelNavigation(){this._navigation++,this._navigator.cancel()}async _loadHistory(e){const t=this.dataController,o=t?.getState();if(null==t||void 0===o||o.paused||null===o.request)return"unavailable";if(!1===o.hasMore)return"exhausted";const n=t.bars()[0]?.time,i=()=>{this._anchoring||this._cancelNavigation()},a=[this.chart.on("pan",i),this.chart.on("zoom",i)];try{await t.loadMore(e)}finally{for(const e of a)e()}const r=t.getState();if("error"===r.historyStatus)throw r.historyError??new Error("Older history failed to load");if("limited"===r.historyStatus)return"limited";const s=t.bars()[0]?.time;return void 0!==s&&(void 0===n||s<n)?"loaded":!1===r.hasMore?"exhausted":"empty"}_applyData(e){if(this._destroyed||null===e.request)return;const t=this._dataState;this._dataState=e,this._dataStatus.update(e);const{symbol:o,interval:n}=e.request;if(!e.paused&&e.bars!==this._displayedBars){const t=this._series.getData(),o=this.chart.getVisibleLogicalRange(),n=null!==this.chart.seriesTransform(this._series),i=n?this.chart.primaryBars():t,a=i[Math.max(0,Math.min(i.length-1,Math.round(o.from)))],r=void 0===a?-1:i.findIndex(e=>e.time===a.time),s=e.bars[e.bars.length-1];if("live"!==e.reason||void 0===s||t[0]?.time!==e.bars[0]?.time||t.length!==e.bars.length&&t.length+1!==e.bars.length){const i=t[0],s=n&&"prepend"===e.reason&&void 0!==i?e.bars.filter(e=>e.time<i.time):[];if(s.length>0&&s.length+t.length===e.bars.length?this._series.prependData(s):this._series.setData(e.bars),this._anchoring=!0,e.bars.length>0)if(this._initialView)this._pendingView?this.chart.setVisibleLogicalRange(this._pendingView):this._keepView||this.chart.resetScale(),this._pendingView=null,this._initialView=!1,this._keepView=!1;else{const t=n?this.chart.primaryBars():e.bars,i=void 0===a?-1:n?t.filter(e=>e.time<=a.time).length-1:t.findIndex(e=>e.time===a.time),s=i<0||r<0?0:i-r;this.chart.setVisibleLogicalRange({from:o.from+s,to:o.to+s})}this._anchoring=!1}else this._series.update(s);this._displayedBars=e.bars,this._statusline?.refresh()}if(t?.status!==e.status||t.error!==e.error||["load","refresh","prepend","resume"].includes(e.reason))if("unsupported"===e.status){const t=_n(this.context,e.request.variant,e.unsupported);this.context.status(kt(this.context,"Not available from this source: {variant}",{variant:t}),"error"),this._bus.emit("data",{symbol:o,interval:n,bars:0,error:e.error?.message})}else"loading"===e.status?this.context.status(kt(this.context,"Loading {symbol} {interval}",{symbol:o,interval:n})):"refreshing"===e.status?this.context.status(kt(this.context,"History is stale. Refreshing {symbol} {interval}",{symbol:o,interval:n})):"error"===e.status||"stale"===e.status?(this.context.status("stale"===e.status?kt(this.context,"History is stale for {symbol} {interval}",{symbol:o,interval:n}):kt(this.context,"Could not load {symbol} {interval}",{symbol:o,interval:n}),"error"),e.error&&e.error!==t?.error&&(this._toasts.toast(kt(this.context,"Could not load {symbol} {interval}: {error}",{symbol:o,interval:n,error:e.error.message}),"error"),this._bus.emit("data",{symbol:o,interval:n,bars:0,error:e.error.message}))):"ready"!==e.status&&"empty"!==e.status||(this.context.status(0===e.bars.length?kt(this.context,"No bars for {symbol} {interval}",{symbol:o,interval:n}):kt(this.context,1===e.bars.length?"{count} bar":"{count} bars",{count:e.bars.length})),this._bus.emit("data",{symbol:o,interval:n,bars:e.bars.length}))}getState(){return{version:1,symbol:this._symbol,exchange:this._exchange,interval:this._interval,chartType:this.chartType(),theme:this._themeName,...this._variant?{variant:this._variant}:{},chart:this.chart.getState(),rail:this._rail?.prefs()??null,panels:this._dock?.state(),savedBy:X}}restoreState(e){const t=this.history.ignore(()=>wi.call(this,e));return t.applied&&this.history.clear(),t}_scheduleSave(){xi.call(this)}_saveNow(){ki.call(this)}_inChart(){const e=this._doc.activeElement;return this._pointerInChart||null!==e&&this._chartEl.contains(e)}_followChart(){this._cleanups.push(this.chart.on("indicatorSettings",({instanceId:e})=>{this._chartEl.dataset.instanceId=e,this._openDialog("indicatorSettings",this._chartEl)}));const e=["paneAdded","paneResized","paneMoved","paneMaximized","paneCollapsed","paneRemoved","indicatorRemoved","indicatorSettings","priceAxisMoved","objects:change"];for(const t of e)this._cleanups.push(this.chart.on(t,()=>{"objects:change"===t&&this.chartType()!==this._chartType&&(this._chartType=this.chartType(),this._topbar?.refresh(),this._mobile?.refresh(),this._statusline?.refresh()),this._bus.emit("layout",{reason:t}),this._scheduleSave()}));for(const e of["draw:add","draw:remove","draw:update","draw:paste","draw:cut","alert:created","alert:updated","alert:removed","alert:triggered","alert:expired","alerts:restored","alerts:checkpoint"])this._cleanups.push(this.chart.on(e,()=>this._scheduleSave()));this._cleanups.push(this.history.subscribe(()=>this._scheduleSave())),this._cleanups.push(this.chart.on("alert:triggered",e=>{const t=e;this.context.toast(t.message??t.title,"success")})),Ci.call(this)}destroy(){if(!this._destroyed){this._saveNow(),this._storage.flush(),this._storage.close(),this._destroyed=!0,this._cancelNavigation(),this._navigator.destroy(),this._goToPanel?.close(),this._quickEntry?.destroy(),this._dock?.destroy(),this.dataController?.destroy(),this._dataStatus.destroy(),this._layouts?.destroy(),this._mobile?.destroy(),this._mobile=null,this._drawbar?.destroy(),this.drawingTemplates?.destroy(),0!==this._saveTimer&&(clearTimeout(this._saveTimer),this._saveTimer=0);for(const e of this._cleanups.splice(0))e();this._topbar?.destroy(),this._rail?.destroy(),this._statusline?.destroy(),this._toasts.destroy(),this._keymap.destroy(),this.history.destroy(),this.objects.destroy(),this.alerts.destroy(),this.instrumentDrawings?.destroy(),this.draw.destroy(),this.chart.destroy(),this.root.remove(),this._bus.clear()}}}function Rl(e,t={}){let o;if("string"==typeof e){const n=t.document??globalThis.document;if(void 0===n)throw new Error("openalgo-charts widget: a selector needs a document");if(o=n.querySelector(e)??n.getElementById(e),null===o)throw new Error(`openalgo-charts widget: no element matches "${e}"`)}else o=e;return new Nl(o,t)}const Fl="ABCDEFGHIJKLMNOP",Wl={crosshair:!1,viewport:!1,symbol:!1,interval:!1,chartType:!1,appearance:!1,drawings:!1,whenMissing:"nearest"},Bl=(e,t)=>JSON.stringify([e,t]);function ql(e){return{crosshair:e.crosshair,viewport:e.viewport,symbol:e.symbol,interval:e.interval,appearance:e.appearance,...e.chartType?{chartType:!0}:{},...e.drawings?{drawings:!0}:{},..."hide"===e.whenMissing?{whenMissing:"hide"}:{}}}function Ul(e){return{crosshair:!0===e.crosshair,viewport:!0===e.viewport,symbol:!0===e.symbol,interval:!0===e.interval,chartType:!0===e.chartType,appearance:!0===e.appearance,drawings:!0===e.drawings,whenMissing:"hide"===e.whenMissing?"hide":"nearest"}}class Hl{constructor(e={}){Object.defineProperty(this,"defaults",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"groups",{enumerable:!0,configurable:!0,writable:!0,value:[]})}create(e={}){const t=e=>!this.groups.some(t=>t.letter===e),o=void 0!==e.id&&/^[a-p]$/.test(e.id)?e.id.toUpperCase():"",n=""!==o&&t(o)?o:[...Fl].find(t);if(void 0===n)return null;let i=e.id??n.toLowerCase();for(let e=2;this.groups.some(e=>e.id===i);e++)i=`${n.toLowerCase()}${e}`;const a={id:i,letter:n,name:e.name??null,links:te({...this.defaults,...e.links}),drawings:new De({enabled:!0}),view:null,keeper:null};return this.groups.push(a),a}find(e){return this.groups.find(t=>t.id===e)}join(e,t){e.group!==t&&(this.leave(e),e.group=t,t.links.add(e.member,function(e,t){const{widget:o}=e,n=o.chart;return{symbol:Bl(o.symbol(),o.exchange()),interval:o.interval(),chartType:o.chartType(),onSymbol:e=>{const[t,n]=JSON.parse(e);o.setSymbol(t,n)},onInterval:e=>!!$(e)&&(o.setInterval(e),!0),onChartType:e=>!!jn(e)&&(o.history.ignore(()=>o.setChartType(e)),o.chartType()===e),appearance:{read:()=>i(n),apply:e=>o.history.ignore(()=>r(n,e))},drawings:{join:()=>t.drawings.add(n,o.draw,()=>({symbol:o.symbol(),exchange:o.exchange()||"-"})),leave:()=>t.drawings.remove(n)}}}(e,t)))}leave(e){const t=e.group;null!==t&&(e.group=null,t.links.remove(e.member),t.keeper===e&&(t.view=null,t.keeper=null))}prune(e){for(const t of this.groups.slice())e.some(e=>e.group===t)||(this.groups.splice(this.groups.indexOf(t),1),t.links.destroy(),t.drawings.destroy())}destroy(){for(const e of this.groups.splice(0))e.links.destroy(),e.drawings.destroy()}trivial(e){return 1===this.groups.length&&null===this.groups[0].name&&e.every(e=>e.group===this.groups[0])}optionsOf(e){return e?.group?.links.options()??{...Wl}}sync(e,t){if(this.trivial(e))return ql(this.groups[0].links.options());const o=this.groups.find(t=>e.every(e=>e.group===t));return{...ql(o?.links.options()??Wl),groups:this.groups.filter(t=>e.some(e=>e.group===t)).map(e=>({id:e.id,name:t(e),...ql(e.links.options())}))}}}function Kl(e,t){return{get:o=>t.get(e)?.get(o)??null,set:(o,n)=>{let i=t.get(e);void 0===i&&t.set(e,i=new Map),i.set(o,JSON.parse(JSON.stringify(n)))},remove:o=>{t.get(e)?.delete(o)}}}const Gl=(e,t,o)=>Number.isInteger(e)&&e>=t&&e<=o;function Vl(e){if(!(tt(e)&&tt(e.layout)&&Array.isArray(e.layout.slots)&&Array.isArray(e.panes)&&tt(e.sync)))return"not a workspace payload";const{rows:t,columns:o,slots:n}=e.layout;if(!Gl(t,1,8)||!Gl(o,1,8)||!Gl(e.panes.length,1,16))return"unsupported grid size";for(const[n,i]of[[e.layout.rowWeights,t],[e.layout.columnWeights,o]])if(!(void 0===n||Array.isArray(n)&&n.length===i&&n.every(e=>"number"==typeof e&&e>0&&e<=1e3)))return"invalid track weights";const i=new Set(E().map(e=>e.id)),a=new Set;for(const t of e.panes){if(!tt(t)||"string"!=typeof t.id||""===t.id||a.has(t.id))return"invalid or duplicate chart id";if(a.add(t.id),"string"!=typeof t.symbol||"string"!=typeof t.exchange||!tt(t.chart)||!["string","undefined"].includes(typeof t.historyPeriod))return`${t.id}: invalid chart`;if(!$(t.interval))return`${t.id}: unknown interval ${String(t.interval)}`;if(!jn(t.chartType))return`${t.id}: unknown chart type ${String(t.chartType)}`;if(Array.isArray(t.comparisons)&&t.comparisons.length>0)return`${t.id}: comparison symbols are not supported in a grid chart`;for(const e of Array.isArray(t.chart.indicators)?t.chart.indicators:[])if(!i.has(e?.indicatorId))return`${t.id}: unavailable study ${String(e?.indicatorId)}`}const r=new Set,s=new Set;for(const e of n){const n=e?.rowSpan??1,i=e?.columnSpan??1;if(!tt(e)||!a.has(e.paneId)||r.has(e.paneId)||!Gl(e.row,0,t-1)||!Gl(e.column,0,o-1)||!Gl(n,1,t-e.row)||!Gl(i,1,o-e.column))return"invalid layout slot";r.add(e.paneId);for(let t=e.row;t<e.row+n;t++)for(let n=e.column;n<e.column+i;n++){if(s.has(t*o+n))return"layout slots overlap";s.add(t*o+n)}}return r.size!==a.size?"every chart needs one layout slot":a.has(e.activePaneId)?function(e){const t=e.sync,o=e.panes,n=[];if(void 0===t.groups)n.push({channels:t,panes:o});else{if(!Array.isArray(t.groups)||t.groups.length>16)return"invalid link groups";const e=new Set;for(const i of t.groups){if("object"!=typeof i||null===i||"string"!=typeof i.id||""===i.id||e.has(i.id))return"invalid or duplicate link group id";e.add(i.id),n.push({channels:i,panes:o.filter(e=>e.linkGroup===i.id)})}for(const t of o)if(void 0!==t.linkGroup&&!e.has(t.linkGroup))return`${t.id}: undeclared link group ${String(t.linkGroup)}`}for(const{channels:e,panes:t}of n){const o=e=>new Set(t.map(e)).size>1;if(!0===e.symbol&&o(e=>Bl(e.symbol,e.exchange)))return"linked symbols differ between charts";if(!0===e.interval&&o(e=>e.interval))return"linked intervals differ between charts";if(!0===e.chartType&&o(e=>e.chartType))return"linked chart types differ between charts"}return""}(e):"the active chart is missing"}const Jl={"1x1":[1,1],"1x2":[1,2],"1x3":[1,3],"2x1":[2,1],"3x1":[3,1],"2x2":[2,2],"1x4":[1,4],"4x1":[4,1],"2x3":[2,3],"3x2":[3,2],"2x4":[2,4],"4x2":[4,2],"3x3":[3,3],"3x4":[3,4],"4x3":[4,3],"4x4":[4,4]},Yl=(e,t,o=1,n=1)=>({row:e,column:t,rowSpan:o,columnSpan:n}),Zl=e=>Array.from({length:e},()=>1);function Ql(e,t){const o=[];for(let n=0;n<e;n++)for(let e=0;e<t;e++)o.push(Yl(n,e));return{rows:e,columns:t,slots:o,rowWeights:Zl(e),columnWeights:Zl(t)}}function Xl(e,t,o,n=Zl(e),i=Zl(t)){return{rows:e,columns:t,slots:o,rowWeights:n,columnWeights:i}}const ec=(e,t)=>Xl(2,e,[Yl(0,0,1,e),...Array.from({length:e},(e,t)=>Yl(1,t))],t,Zl(e));function tc(e){const t=[Yl(0,0,e-1,e-1)];for(let o=0;o<e-1;o++)t.push(Yl(o,e-1));for(let o=0;o<e;o++)t.push(Yl(e-1,o));return Xl(e,e,t)}const oc={"1x1":Ql(1,1),"1x2":Ql(1,2),"2x1":Ql(2,1),"1x3":Ql(1,3),"3x1":Ql(3,1),"left-2":Xl(2,2,[Yl(0,0,2),Yl(0,1),Yl(1,1)]),"right-2":Xl(2,2,[Yl(0,0),Yl(0,1,2),Yl(1,0)]),"top-2":Xl(2,2,[Yl(0,0,1,2),Yl(1,0),Yl(1,1)]),"bottom-2":Xl(2,2,[Yl(0,0),Yl(0,1),Yl(1,0,1,2)]),"2x2":Ql(2,2),"1x4":Ql(1,4),"4x1":Ql(4,1),"left-3":(nc=3,ic=[2,1],Xl(nc,2,[Yl(0,0,nc),...Array.from({length:nc},(e,t)=>Yl(t,1))],Zl(nc),ic)),"top-3":ec(3,[2,1]),"left-4":Xl(2,3,[Yl(0,0,2),Yl(0,1),Yl(0,2),Yl(1,1),Yl(1,2)],Zl(2),[2,1,1]),"top-4":ec(4,[2,1]),"2x3":Ql(2,3),"3x2":Ql(3,2),"corner-5":tc(3),"2x4":Ql(2,4),"4x2":Ql(4,2),"corner-7":tc(4),"3x3":Ql(3,3),"3x4":Ql(3,4),"4x3":Ql(4,3),"4x4":Ql(4,4)};var nc,ic;function ac(e){return"string"==typeof e&&Object.prototype.hasOwnProperty.call(oc,e)}const rc=(e,t,o)=>{let n=0;for(let i=t;i<t+o;i++)n+=e[i];return n},sc="grid",lc="grid-drawings";function cc(e){e.held=!1,e.storage.enabled&&!e.destroyed&&(0!==e.saveTimer&&clearTimeout(e.saveTimer),e.saveTimer=setTimeout(()=>uc(e),250))}function dc(e){e.held=!1,!e.storage.enabled||e.destroyed||e.saveQueued||(e.saveQueued=!0,queueMicrotask(()=>{e.saveQueued=!1,uc(e)}))}function uc(e){if(0!==e.saveTimer&&(clearTimeout(e.saveTimer),e.saveTimer=0),!e.storage.enabled||e.destroyed||e.held||e.restoring||null===e.active)return;const t=e.storage.set(sc,e.grid.getWorkspace()),o={};for(const t of e.cells){const n=e.drawings.get(t.id);void 0!==n&&n.size>0&&(o[t.id]=Object.fromEntries(n))}const n=e.storage.set(lc,{version:1,charts:o}),i=!t||!n;i&&!e.saveRefused&&e.active.widget.context.status(kt(e.text,"The chart layout could not be saved"),"error"),e.saveRefused=i}function pc(e){if(!1!==e.options.shortcutsEditor){e.sharing=!0;try{for(const t of e.cells)t.widget.context.keymap.applyOverrides(e.chords)}finally{e.sharing=!1}}}function hc(e,t){t&&0===e.saveTimer||uc(e),e.storage.flush(),e.saved?.flush()}function mc(e,t,o){const{storage:n,options:i}=e;if(e.chords=n.get(to),e.given)return pc(e),void dc(e);const a=n.get(sc);if(e.restored=null===a?null:o(a,function(e){const t=new Map;if(!tt(e)||1!==e.version||!tt(e.charts))return t;for(const[o,n]of Object.entries(e.charts)){if(!tt(n))continue;const e=new Map;for(const[t,o]of Object.entries(n))tt(o)&&e.set(t,o);t.set(o,e)}return t}(n.get(lc))),!0!==e.restored?.applied){if(t){if(pc(e),void 0!==i.symbol)for(const t of e.cells)t.widget.setSymbol(i.symbol,i.exchange)}else e.grid.setPreset(i.preset??"1x1");null!==e.restored&&(e.held=!0,e.grid.active().widget.context.toast(kt(e.text,"The saved layout could not be restored: {error}",{error:e.restored.reason??""}),"error"))}}const gc=e=>Math.round(1e4*e)/1e4,fc=e=>e.map(e=>`minmax(0,${e}fr)`).join(" 4px "),bc=e=>e.compact||e.maxed;function vc(e){for(const t of e.cells){const e=t.element.getBoundingClientRect();e.width>0&&e.height>0&&(t.element.dataset.dense=String(e.width<560||e.height<340))}}function wc(e,t){const o="column"===t.dataset.axis?e.colW:e.rowW,n=Number(t.dataset.index);t.setAttribute("aria-valuenow",String(Math.round(o[n]/(o[n]+o[n+1])*100)))}function _c(e,t,o,n,i=!1){const a=("column"===t?e.colW:e.rowW).slice(),r=a[o]+a[o+1],s=gc(Math.min(.85*r,Math.max(.15*r,n)));s!==a[o]&&(a[o]=s,a[o+1]=gc(r-s),"column"===t?(e.colW=a,e.body.style.gridTemplateColumns=fc(a)):(e.rowW=a,e.body.style.gridTemplateRows=fc(a)),e.splits.forEach(t=>wc(e,t)),vc(e),i?cc(e):dc(e),e.bus.emit("layout",{reason:"weights"}))}function yc(e,t,o,n){const{doc:i,body:a}=e,r="column"===t,s=Ke(i,"div","oac-grid__split",{role:"separator",tabindex:"0","aria-orientation":r?"vertical":"horizontal","aria-label":kt(e.text,r?"Resize columns {first} and {second}":"Resize rows {first} and {second}",{first:o+1,second:o+2}),"aria-valuemin":"15","aria-valuemax":"85"});s.dataset.axis=t,s.dataset.index=String(o),s.style.gridArea=n;const l=()=>r?e.colW:e.rowW;s.addEventListener("pointerdown",n=>{if(0!==n.button)return;n.preventDefault();const i=a.getBoundingClientRect(),c=l(),d=(r?i.width:i.height)-4*(c.length-1),u=c.reduce((e,t)=>e+t,0),p=r?n.clientX:n.clientY,h=c[o];s.setPointerCapture?.(n.pointerId),s.classList.add("is-drag");const m=n=>{d>0&&_c(e,t,o,h+((r?n.clientX:n.clientY)-p)/d*u,!0)},g=()=>{0!==e.saveTimer&&uc(e),s.classList.remove("is-drag"),s.removeEventListener("pointermove",m),s.removeEventListener("pointerup",g),s.removeEventListener("pointercancel",g)};s.addEventListener("pointermove",m),s.addEventListener("pointerup",g),s.addEventListener("pointercancel",g)}),s.addEventListener("keydown",n=>{const i=(r?["ArrowLeft","ArrowRight"]:["ArrowUp","ArrowDown"]).indexOf(n.key);if(i<0)return;n.preventDefault(),n.stopPropagation();const a=l();_c(e,t,o,a[o]+(2*i-1)*(a[o]+a[o+1])*(n.shiftKey?.2:.05))}),s.addEventListener("dblclick",()=>{const n=l();_c(e,t,o,(n[o]+n[o+1])/2)}),s.hidden=bc(e),a.appendChild(s),e.splits.push(s),wc(e,s)}function xc(e,t){const o="column"===t,n=o?e.rows:e.cols;for(let i=0;i<(o?e.cols:e.rows)-1;i++){let a=-1;for(let r=0;r<=n;r++){const s=r<n&&!e.cells.some(e=>{const[t,n,a,s]=o?[e.column,e.columnSpan,e.row,e.rowSpan]:[e.row,e.rowSpan,e.column,e.columnSpan];return t<=i&&t+n>i+1&&a<=r&&a+s>r});if(s&&a<0&&(a=r),!s&&a>=0){const[n,s,l]=[2*a+1,2*r,2*i+2];yc(e,t,i,(o?[n,l,s,l+1]:[l,n,l+1,s]).join(" / ")),a=-1}}}}const kc=e=>e.cells.length<2||!bc(e)?null:kt(e.text,e.compact?"The grid shows one chart at a time at this width":"Show every chart to capture them together"),Cc=(e,t,o="info")=>{e.active?.widget.context.toast(t,o)},Sc=e=>{const{text:t}=e;e.grid.downloadScreenshot()?Cc(e,kt(t,"Saved a PNG of every chart")):Cc(e,kt(t,"The image could not be saved: {error}",{error:kc(e)??kt(t,"This runtime cannot save files")}),"error")},Ac=e=>{const t=e.grid.takeScreenshot();null!==t&&ta(e.text,t,kt(e.text,"Every chart copied"),(t,o)=>Cc(e,t,o))};function Lc(e){if(e.destroyed||null!==kc(e))return null;const{doc:t}=e,o=e.body.getBoundingClientRect(),n=e=>{const t=e?.getBoundingClientRect();return void 0===t?{left:0,top:0,width:0,height:0}:{left:t.left-o.left,top:t.top-o.top,width:t.width,height:t.height}},i=e.cells.map(e=>({cell:n(e.element),chart:n(e.widget.root.querySelector(".oac-chart")),image:e.widget.chart.takeScreenshot(),label:`${e.widget.symbol()} ${e.widget.interval()}`.trim()})),a=e.options.pixelRatio?.()??t.defaultView?.devicePixelRatio??1,r=ja(jl(e.theme).theme,jl(e.theme).name),s=e=>r[fa+e];return function(e,t,o,n,i){const a=e.createElement("canvas"),r=e=>Math.round(e*o);a.width=Math.max(1,r(t.width)),a.height=Math.max(1,r(t.height));const s=a.getContext("2d");if(null===s)return a;s.fillStyle=i.gutter,s.fillRect(0,0,a.width,a.height);for(const e of n){const{cell:t,chart:o}=e;s.fillStyle=i.panel,s.fillRect(r(t.left),r(t.top),r(t.left+t.width)-r(t.left),r(t.top+t.height)-r(t.top));const n=o.top-t.top;n>=14&&""!==e.label&&(s.fillStyle=i.text,s.font=`600 ${r(12)}px ${i.font}`,s.textBaseline="middle",s.fillText(e.label,r(t.left+8),r(t.top+n/2),r(Math.max(0,t.width-16)))),null===e.image||e.image.width<=1||o.width<=0||o.height<=0||s.drawImage(e.image,r(o.left),r(o.top),r(o.left+o.width)-r(o.left),r(o.top+o.height)-r(o.top))}return a}(t,{width:o.width,height:o.height},function(e,t){for(const o of e)if(!(null===o.image||o.image.width<=1||o.chart.width<=0))return t>0&&Math.abs(o.image.width-o.chart.width*t)<=1?t:o.image.width/o.chart.width;return t>0?t:1}(i,a),i,{gutter:s("bd-soft"),panel:s("panel"),text:s("tx"),font:Oa})}const Oc=(e,t)=>Xi(e.doc,()=>e.grid.takeScreenshot(),t??(e=>ln("charts",e.preset??`${e.rows}x${e.cols}`)+".png")(e));function $c(e,t){const o=Ke(e,"span","oac-grid__chip",{"aria-hidden":"true"});return null===t?(o.dataset.group="none",o.innerHTML=ie("unlink")):(o.dataset.group=t.letter,o.textContent=t.letter),o}function Ec(e,t,o){const n="left"===o||"right"===o,[i,a]=n?[t.row,t.rowSpan]:[t.column,t.columnSpan],r=e=>Math.abs((n?e.row:e.column)-i);return e.filter(e=>e!==t&&(e=>"right"===o?e.column===t.column+t.columnSpan:"left"===o?e.column+e.columnSpan===t.column:"down"===o?e.row===t.row+t.rowSpan:e.row+e.rowSpan===t.row)(e)&&(e=>{const[t,o]=n?[e.row,e.rowSpan]:[e.column,e.columnSpan];return t<i+a&&t+o>i})(e)).sort((e,t)=>r(e)-r(t))[0]}const Tc={left:"ArrowLeft",right:"ArrowRight",up:"ArrowUp",down:"ArrowDown"},Pc={left:"Make the chart to the left active",right:"Make the chart to the right active",up:"Make the chart above active",down:"Make the chart below active"},jc={left:"Swap with the chart to the left",right:"Swap with the chart to the right",up:"Swap with the chart above",down:"Swap with the chart below"};function Mc(e){const{doc:t,body:o,root:n}=e;let i=null;const a=t=>{const o=t;if(null===o||"function"!=typeof o.closest||null!==o.closest('button, input, select, textarea, a, label, [role="button"], [role="radio"], [role="tab"], [contenteditable="true"]'))return;const n=o.closest(".oac-topbar");if(null===n)return;const i=e.cells().find(e=>e.element.contains(n));return void 0===i?void 0:{cell:i,head:n}},r=o=>{const a=i;if(null!==a&&(i=null,t.removeEventListener("pointermove",s,!0),t.removeEventListener("pointerup",l,!0),t.removeEventListener("pointercancel",c,!0),t.removeEventListener("keydown",d,!0),a.moving)){a.over?.element.removeAttribute("data-drop"),a.cell.element.removeAttribute("data-dragging"),n.removeAttribute("data-dragging");try{a.head.releasePointerCapture?.(a.pointer)}catch{}o&&null!==a.over&&e.swap(a.cell,a.over)}},s=t=>{const o=i;if(null!==o&&t.pointerId===o.pointer){if(!o.moving){if(Math.hypot(t.clientX-o.x,t.clientY-o.y)<6)return;if(!e.enabled())return void r(!1);o.moving=!0,n.setAttribute("data-dragging","true"),o.cell.element.setAttribute("data-dragging","true");try{o.head.setPointerCapture?.(o.pointer)}catch{}}var a;t.preventDefault(),a=e.cells().find(e=>e!==o.cell&&((e,t,o)=>{const n=e.element.getBoundingClientRect();return n.width>0&&t>=n.left&&t<n.left+n.width&&o>=n.top&&o<n.top+n.height})(e,t.clientX,t.clientY))??null,null!==i&&(i.over?.element.removeAttribute("data-drop"),i.over=a,a?.element.setAttribute("data-drop","true"))}},l=e=>{null!==i&&e.pointerId===i.pointer&&r(!0)},c=()=>r(!1),d=e=>{"Escape"===e.key&&null!==i&&(i.moving&&(e.preventDefault(),e.stopPropagation()),r(!1))},u=o=>{if(0!==o.button||null!==i||!e.enabled())return;const n=a(o.target);void 0!==n&&(i={...n,x:o.clientX,y:o.clientY,pointer:o.pointerId,moving:!1,over:null},t.addEventListener("pointermove",s,!0),t.addEventListener("pointerup",l,!0),t.addEventListener("pointercancel",c,!0),t.addEventListener("keydown",d,!0))},p=t=>{const o=a(t.target);void 0!==o&&e.toggleMaximize(o.cell)};return o.addEventListener("pointerdown",u),o.addEventListener("dblclick",p),()=>{r(!1),o.removeEventListener("pointerdown",u),o.removeEventListener("dblclick",p)}}function Ic(e,t,o,n,i=!1){return 0===o||t<0&&!i?-1:e===n[1]?(t+1)%o:e===n[0]?t<0?o-1:(t-1+o)%o:"Home"===e?0:"End"===e?o-1:-1}const Dc=Tt(()=>import("./openalgo-charts.widget.grid-bar-Cm_CyA2j.mjs")),zc=Tt(()=>import("./openalgo-charts.widget.grid-menus-CPZWEiD3.mjs")),Nc=["preset","links","compactWidth","persist","storage","drawingStore","toolbar","presets"],Rc=e=>Array.from({length:e},()=>1);function Fc(e,t={}){if("string"==typeof e){const o=(t.document??globalThis.document)?.querySelector(e);if(!o)throw new Error(`openalgo-charts grid: no element matches "${e}"`);e=o}const o=t.document??e.ownerDocument,n=t,i={...t};for(const e of Nc)delete i[e];Object.assign(i,{document:o,mobile:t.mobile??"never",captureRows:()=>function(e){if(e.cells.length<2)return[];const{text:t}=e,o=kc(e);return[kt(t,"Every chart"),{label:kt(t,"Download PNG of every chart"),sub:o??void 0,disabled:null!==o,onSelect:()=>Sc(e)},{label:kt(t,"Copy image of every chart"),sub:o??void 0,disabled:null!==o||!ea(),onSelect:()=>Ac(e)}]}(d)}),i.bottombar=!1,i.layouts=!0!==t.toolbar&&(t.layouts??!1);const a=Ke(o,"div","oac-grid"),r=Ke(o,"div","oac-grid__tabs",{role:"tablist","aria-label":kt(n,"Charts")}),s=Ke(o,"div","oac-grid__cells");r.hidden=!0;const l=!0===t.toolbar?Ke(o,"div","oac-widget oac-grid__bar",{role:"toolbar","aria-label":kt(n,"Chart grid")}):null,c=!0===t.bottombar?Ke(o,"div","oac-widget oac-grid__foot"):null;a.append(...null===l?[]:[l],r,s,...null===c?[]:[c]);const d={doc:o,options:t,text:n,cellOptions:i,bus:new mt,links:new Hl(t.links),offs:[],root:a,tabs:r,body:s,barEl:l,footEl:c,splits:[],given:!1,cells:[],chords:null,sharing:!1,active:null,rows:1,cols:1,rowW:[1],colW:[1],preset:null,theme:t.theme??"dark",themeSync:!1,compact:!1,maxed:!1,pointerIn:!1,destroyed:!1,syncing:!1,nextId:0,saveTimer:0,saveQueued:!1,saveRefused:!1,held:!1,restored:null,drawings:new Map,chromeLayer:null,bar:null,foot:null,saved:null,ready:Promise.resolve()};d.storage=function(e){const{options:t,text:o}=e,n=t.persist?void 0===t.storage?Rt():t.storage:null;return new nt("string"==typeof t.persist?t.persist:"default",n,{onError:t=>{if(e.destroyed||null===e.active)return;const n=Ct(o,t.error),i=e.active.widget.context;if("load"!==t.operation)return void i.status(kt(o,"Saved chart settings could not be written: {error}",{error:n}),"error");const a=kt(o,"Saved chart settings could not be read, so changes are kept for this session only: {error}",{error:n});i.status(a,"error"),i.toast(a,"error")}})}(d),d.timeframePreferences=t.timeframePreferences??Ue(d.storage,t.intervals??Cl),d.cellOptions.timeframePreferences=d.timeframePreferences,t.timeframePreferences||d.offs.push(()=>d.timeframePreferences.destroy()),d.restoring=!d.storage.loaded;const u=d.grid=function(e){const{links:t}=e,o={root:e.root,get ready(){return e.ready},get isDestroyed(){return e.destroyed},restored:()=>e.restored,cells:()=>e.cells.slice(),active:()=>e.active,theme:()=>jl(e.theme).name,compact:()=>e.compact,maximized:()=>e.maxed&&null!==e.active?e.active.id:null,linkOptions:()=>t.optionsOf(e.active),linkGroups:()=>Qc(e),layout:()=>({rows:e.rows,columns:e.cols,preset:e.preset,rowWeights:e.rowW.slice(),columnWeights:e.colW.slice()}),on:(t,o)=>e.bus.on(t,o),setActive:(t,o)=>function(e,t,o={}){const n=e.cells.find(e=>e.id===t);if(void 0===n||e.destroyed)return!1;const i=n!==e.active,a=e.active?.group??null;e.active=n,Kc(e),o.focus&&n.widget.root.querySelector(".oac-chart")?.focus({preventScroll:!0});i&&(e.held||dc(e),Wc(e,"active",{id:t}),a!==n.group&&Wc(e,"links",e.grid.linkOptions()));return!0}(e,t,o),setPreset:t=>function(e,t){if(!ac(t))throw new Error(`openalgo-charts grid: "${String(t)}" is not a preset or layout`);if(e.destroyed)return;const{links:o}=e,n=oc[t],i=n.slots.length,a=e.cells.slice(0,i),r=function(e){const t=e.slots.map(t=>rc(e.rowWeights,t.row,t.rowSpan)*rc(e.columnWeights,t.column,t.columnSpan)),o=Math.max(...t);return t.every(e=>e===o)?-1:t.indexOf(o)}(n);r>=0&&null!==e.active&&!a.includes(e.active)&&a.splice(i-1,1,e.active);const s=e.active,l=null===s?o.groups[0]??o.create():s.group,c=e.active?.widget,d=void 0===c?e.options:{symbol:c.symbol(),exchange:c.exchange(),interval:c.interval(),variant:c.variant(),chartType:c.chartType(),historyPeriod:e.active?.historyPeriod},u=[];try{for(;a.length+u.length<i;){let t;do{t="p"+e.nextId++}while(e.cells.some(e=>e.id===t));u.push(nd(e,t,d,e.body,e.theme,e.drawings))}}catch(t){throw u.forEach(t=>ld(e,t)),t}e.maxed=!1,e.root.dataset.maximized="false";for(const t of e.cells.filter(e=>!a.includes(e)))ld(e,t),e.drawings.delete(t.id);null!==e.active&&a.includes(e.active)||(e.active=a[0]??u[0]);const p=[...a,...u];r>=0&&(p.splice(p.indexOf(e.active),1),p.splice(r,0,e.active));if(p.forEach((e,t)=>Object.assign(e,n.slots[t])),e.cells=p,u.forEach(t=>sd(e,t)),null!==l)for(const e of u)o.join(e,l);o.prune(e.cells),e.rows=n.rows,e.cols=n.columns,e.rowW=n.rowWeights.slice(),e.colW=n.columnWeights.slice(),e.preset=t,od(e),dc(e),Wc(e,"layout",{reason:"preset"}),e.active!==s&&Wc(e,"active",{id:e.active.id})}(e,t),maximize(t){const n=void 0===t?e.active:e.cells.find(e=>e.id===t);return!(e.destroyed||null==n||e.cells.length<2)&&(o.setActive(n.id),Vc(e,!0),!0)},restore(){e.destroyed||Vc(e,!1)},swap:(t,o)=>function(e,t,o){const n=e.cells.find(e=>e.id===t),i=e.cells.find(e=>e.id===o);if(e.destroyed||void 0===n||void 0===i||n===i)return!1;const a=e=>({row:e.row,column:e.column,rowSpan:e.rowSpan,columnSpan:e.columnSpan}),[r,s]=[a(n),a(i)];return Object.assign(n,s),Object.assign(i,r),e.cells.sort((e,t)=>e.row-t.row||e.column-t.column),od(e),dc(e),Wc(e,"layout",{reason:"swap"}),!0}(e,t,o),setLinks(n){const i=null!=e.active?.group?[e.active.group]:t.groups;for(const t of i)pd(e,t,n);dc(e),ed(e),Wc(e,"links",o.linkOptions())},setLinkGroup(o,n){const i=e.cells.find(e=>e.id===o),a=null===n?null:t.find(n);return!e.destroyed&&void 0!==i&&void 0!==a&&(null===a?t.leave(i):t.join(i,a),td(e),!0)},addLinkGroup(o,n={}){const i=e.cells.find(e=>e.id===o);if(e.destroyed||void 0===i)return null;const a=n.name?.trim(),r=t.create({name:void 0===a||""===a?null:a.slice(0,120),links:n.links});return null===r?null:(t.join(i,r),td(e),r.id)},setGroupLinks(n,i){const a=t.find(n);return!e.destroyed&&void 0!==a&&(pd(e,a,i),dc(e),ed(e),Wc(e,"links",o.linkOptions()),!0)},renameLinkGroup(o,n){const i=t.find(o),a=n.trim();return!(e.destroyed||void 0===i||""===a||a.length>120)&&(i.name=a,td(e),!0)},shareDrawings(t){const o=e.cells.find(e=>e.id===t),n=o?.group;return e.destroyed||void 0===o||null==n||!n.links.options().drawings?0:n.drawings.share(o.widget.chart)},setTheme(t){e.theme=t,qc(e),e.themeSync=!0;try{for(const o of e.cells)o.widget.setTheme(t)}finally{e.themeSync=!1}dc(e),Wc(e,"theme",{theme:jl(t).name})},takeScreenshot:()=>Lc(e),downloadScreenshot:t=>Oc(e,t),getWorkspace:()=>function(e){const t=e.links.trivial(e.cells),o={layout:{rows:e.rows,columns:e.cols,slots:e.cells.map(e=>({paneId:e.id,row:e.row,column:e.column,rowSpan:e.rowSpan,columnSpan:e.columnSpan})),...null===e.preset?{}:{preset:e.preset},rowWeights:e.rowW.slice(),columnWeights:e.colW.slice()},panes:e.cells.map(e=>{const o=e.widget.getState();return{...Di(e.id,o,o.chart),historyPeriod:e.historyPeriod,...t||null===e.group?{}:{linkGroup:e.group.id}}}),activePaneId:e.active.id,sync:e.links.sync(e.cells,t=>Zc(e,t))};return JSON.parse(JSON.stringify(o))}(e),applyWorkspace(t){const o=hd(e,t,new Map);return o.applied&&(e.given=!0),o},destroy:()=>function(e){if(e.destroyed)return;uc(e),e.storage.flush(),e.storage.close(),e.destroyed=!0;for(const t of e.offs.splice(0))t();e.saved?.destroy(),e.foot?.destroy(),e.chromeLayer?.overlays.destroy(),e.chromeLayer?.tips.destroy(),e.bar?.destroy(),e.cells.splice(0).forEach(t=>ld(e,t)),e.links.destroy(),e.root.remove(),e.bus.clear()}(e)};return o}(d);if(d.barHost=function(e){const{doc:t,text:o,options:n}=e,i={waiting:null},a={doc:t,text:o,get overlays(){return Bc(e).overlays},get tips(){return Bc(e).tips},layouts:(n.presets??Object.keys(oc)).filter(ac),layout:()=>e.preset,setLayout:t=>e.grid.setPreset(t),maximized:()=>e.maxed,maximizeBlocked:()=>Jc(e),toggleMaximize:()=>Yc(e),links:{groups:()=>Qc(e),current:()=>Xc(e,e.active?.group??null),setGroup:t=>{null!==e.active&&e.grid.setLinkGroup(e.active.id,t)},newGroup:()=>{null!==e.active&&e.grid.addLinkGroup(e.active.id)},rename:(t,o)=>e.grid.renameLinkGroup(t,o),setChannel:(t,o)=>{const n=e.active?.group;null!=n&&e.grid.setGroupLinks(n.id,"nearest"===t?{whenMissing:o?"nearest":"hide"}:{[t]:o})},share:()=>{const t=null===e.active?0:e.grid.shareDrawings(e.active.id);return Cc(e,t>0?kt(o,1===t?"Shared {count} drawing":"Shared {count} drawings",{count:t}):kt(o,"No drawing here can be shared")),t}},capture:{blocked:()=>kc(e),download:()=>Sc(e),copy:()=>Ac(e),canCopy:ea},get saved(){return e.saved??void 0},openMenu:(n,r)=>Pt(zc,e=>{"layouts"===n?e.openLayoutPicker(a,r):"link"===n?e.openLinkMenu(a,r):e.openCaptureMenu(a,r)},t=>Cc(e,jt(o,kt(o,"layouts"===n?"Arrange charts":"link"===n?"Linking":"Capture every chart"),t),"error"),()=>!e.destroyed&&r.isConnected,{slot:i,doc:t,from:r})};return a}(d),qc(d),e.appendChild(a),function(e){const{doc:t,root:o,tabs:n,offs:i}=e,a=(e,t,o,n=!1)=>{e.addEventListener(t,o,n),i.push(()=>e.removeEventListener(t,o,n))};a(n,"keydown",o=>{const i=Array.from(n.children),a=Ic(o.key,i.indexOf(t.activeElement),i.length,["ArrowLeft","ArrowRight"]),r=e.cells[a];a<0||void 0===r||(o.preventDefault(),o.stopPropagation(),e.grid.setActive(r.id),n.children[a]?.focus())}),a(o,"pointerdown",t=>cd(e,t.target),!0),a(o,"focusin",t=>cd(e,t.target)),a(o,"pointerenter",()=>{e.pointerIn=!0}),a(o,"pointerleave",()=>{e.pointerIn=!1}),i.push(Mc({doc:t,body:e.body,root:o,cells:()=>e.cells,enabled:()=>!bc(e)&&e.cells.length>1,swap:(t,o)=>e.grid.swap(t.id,o.id),toggleMaximize:t=>{e.cells.length>1&&!e.compact&&(e.grid.setActive(t.id),Yc(e,t))}}));const r=t.defaultView,s=r?.ResizeObserver;if(void 0!==s){const t=new s(()=>Gc(e));t.observe(o),i.push(()=>t.disconnect())}null!=r&&"function"==typeof r.addEventListener&&(void 0===s&&a(r,"resize",()=>Gc(e)),a(r,"pagehide",()=>hc(e,!1)));a(t,"visibilitychange",()=>{"hidden"===t.visibilityState&&hc(e,!0)})}(d),function(e,t){e.restoring?(e.grid.setPreset(e.options.preset??"1x1"),e.root.style.visibility="hidden",e.ready=e.storage.load().then(()=>{if(!e.destroyed){e.timeframePreferences.reload(),e.restoring=!1;try{mc(e,!0,t)}catch(t){e.grid.active().widget.context.toast(kt(e.text,"The saved layout could not be restored: {error}",{error:Ct(e.text,t)}),"error")}finally{e.root.style.visibility=""}}})):mc(e,!1,t)}(d,(e,t)=>hd(d,e,t)),null!==c){const{tips:e,overlays:n}=Bc(d),i=c.appendChild(Ke(o,"div"));d.foot=Cs({document:o,locale:t.locale,translate:t.translate,tips:e,openOverlay:n.open,status:(e,t)=>d.active?.widget.context.status(e,t)},i,{target:()=>d.active?.widget??null,ranges:t.ranges,now:t.now,onGoTo:()=>d.active?.widget.openDateNavigation()}),d.offs.push(d.bus.on("active",()=>d.foot?.refresh()))}return null!==l&&Pt(Dc,e=>{d.saved=e.attachGridSaved({grid:u,ready:d.ready,workspaces:t.workspaces,layouts:t.layouts,context:()=>Uc(d,d.active.widget.context),opened:()=>d.given}),d.bar=e.mountGridBar(d.barHost,l)},e=>Cc(d,jt(n,kt(n,"Chart grid"),e),"error"),()=>!d.destroyed),Gc(d),u}const Wc=(e,t,o)=>e.bus.emit(t,o);function Bc(e){if(null===e.chromeLayer){const t=Ke(e.doc,"div","oac-widget oac-grid__overlay");t.dataset.theme=jl(e.theme).name,e.root.appendChild(t);const o=rt(t,e.doc);e.chromeLayer={el:t,overlays:o,tips:lt(t,o.layer,e.doc)}}return e.chromeLayer}function qc(e){const t=jl(e.theme);e.root.dataset.theme=t.name;for(const o of[e.chromeLayer?.el,e.barEl,e.footEl])null!=o&&(o.dataset.theme=t.name);Ma(e.root,ja(t.theme,t.name))}const Uc=(e,t,o)=>Object.create(t,{root:{value:Bc(e).el},openOverlay:{value:(t,n={})=>Bc(e).overlays.open(t,{...n,anchor:n.anchor??o?.()??void 0})}});function Hc(e){const{doc:t,tabs:o}=e;for(const t of e.cells)t.element.hidden=bc(e)&&t!==e.active;for(const t of e.splits)t.hidden=bc(e);o.hidden=!bc(e)||e.cells.length<2;const n=e=>`${e.widget.symbol()} ${e.widget.interval()}`.trim();o.replaceChildren(...o.hidden?[]:e.cells.map((o,i)=>{const a=Ke(t,"button","oac-grid__tab",{type:"button",role:"tab","aria-selected":String(o===e.active),tabindex:o===e.active?"0":"-1"});return a.textContent=n(o),e.cells.some(e=>e!==o&&n(e)===n(o))&&a.setAttribute("aria-label",`${n(o)} (${i+1})`),a.addEventListener("click",()=>e.grid.setActive(o.id,{focus:!0})),a})),e.bar?.refresh()}function Kc(e){for(const t of e.cells)t.element.dataset.active=String(t===e.active),t===e.active?t.element.setAttribute("aria-current","true"):t.element.removeAttribute("aria-current");Hc(e)}function Gc(e){if(e.destroyed)return;vc(e);const t=e.root.getBoundingClientRect().width,o=e.options.compactWidth??640,n=o>0&&t>0&&t<=o;e.root.dataset.compact=String(n),n!==e.compact&&(e.compact=n,Hc(e),vc(e),Wc(e,"layout",{reason:"compact"}))}function Vc(e,t){return t!==e.maxed&&(e.maxed=t,null!==e.active&&(e.active.hold=!0),e.root.dataset.maximized=String(t),Hc(e),vc(e),Wc(e,"layout",{reason:"maximize"}),!0)}function Jc(e){return e.cells.length<2?kt(e.text,"There is only one chart"):e.compact?kt(e.text,"The grid shows one chart at a time at this width"):null}function Yc(e,t=e.active){null!==t&&(e.maxed&&t===e.active?e.grid.restore():e.grid.maximize(t.id))}const Zc=(e,t)=>t.name??kt(e.text,"Group {letter}",{letter:t.letter}),Qc=e=>{return t=e.links,o=e.cells,n=t=>Zc(e,t),t.groups.map(e=>({id:e.id,name:n(e),letter:e.letter,links:e.links.options(),cells:o.filter(t=>t.group===e).map(e=>e.id)}));var t,o,n},Xc=(e,t)=>Qc(e).find(e=>e.id===t?.id)??null;function ed(e){const{doc:t,text:o}=e,n=e.links.trivial(e.cells);e.cells.forEach((i,a)=>{const r=a+1;if(i.element.setAttribute("aria-label",n?kt(o,"Chart {index}",{index:r}):null===i.group?kt(o,"Chart {index}, not linked",{index:r}):kt(o,"Chart {index}, linked in {name}",{index:r,name:Zc(e,i.group)})),n)return i.mark?.remove(),void(i.mark=null);if(null===i.mark){const o=i.mark=Ke(t,"button","oac-grid__mark",{type:"button","aria-haspopup":"menu"});o.addEventListener("click",()=>{e.grid.setActive(i.id),e.barHost.openMenu("link",o)});const n=i.widget.root.querySelector(".oac-topbar");null!==n?n.prepend(o):(o.classList.add("oac-grid__mark--float"),i.element.appendChild(o))}i.mark.replaceChildren($c(t,Xc(e,i.group)));const s=null===i.group?kt(o,"Not linked"):kt(o,"Linked in {name}",{name:Zc(e,i.group)});i.mark.setAttribute("aria-label",s),i.mark.title=s,null===i.group?delete i.mark.dataset.group:i.mark.dataset.group=i.group.letter}),e.bar?.refresh()}function td(e){e.links.prune(e.cells),ed(e),dc(e),Wc(e,"links",e.grid.linkOptions())}function od(e){const{doc:t,body:o}=e;o.style.gridTemplateColumns=fc(e.colW),o.style.gridTemplateRows=fc(e.rowW);for(const t of e.splits.splice(0))t.remove();const n=t.activeElement;e.cells.forEach((e,t)=>{e.element.style.gridArea=`${2*e.row+1} / ${2*e.column+1} / ${2*(e.row+e.rowSpan)} / ${2*(e.column+e.columnSpan)}`;const n=o.children[t]??null;n!==e.element&&o.insertBefore(e.element,n)}),null!==n&&n!==t.activeElement&&e.cells.some(e=>e.element.contains(n))&&n.focus({preventScroll:!0}),xc(e,"column"),xc(e,"row"),e.root.dataset.single=String(1===e.cells.length),ed(e),Kc(e),vc(e)}function nd(e,t,o,n,i,a){const{footEl:r}=e,s=Ke(e.doc,"div","oac-grid__cell",{role:"group"});s.dataset.paneId=t,n.appendChild(s);const{historyPeriod:l}=o,c=e.options.feed,d={id:t,element:s,row:0,column:0,rowSpan:1,columnSpan:1,offs:[],span:0,hold:!1,historyPeriod:l,group:null,mark:null,type:""},u={...e.cellOptions,theme:i,symbol:e.restoring?void 0:o.symbol,exchange:o.exchange,interval:o.interval,variant:o.variant,chartType:o.chartType,keyboardRoute:()=>function(e,t){if(t!==e.active)return!1;const o=e.doc.activeElement;return null===o||o===e.doc.body||o===e.doc.documentElement?!!e.pointerIn||void 0:!(e.root.contains(o)&&!e.cells.some(e=>e.element.contains(o)))&&void 0}(e,d),feed:"function"==typeof c?c({id:t,historyPeriod:l}):c,drawingStore:Kl(t,a)};null!==r&&El.set(u,t=>Uc(e,t,()=>r.querySelector(".oac-bottombar__goto")));try{d.widget=Rl(s,u)}catch(e){throw s.remove(),e}return d.type=d.widget.chartType(),Object.defineProperty(d,"linkGroup",{enumerable:!0,get:()=>d.group?.id??null}),d}const id=e=>{const t=e.widget.chart.getVisibleLogicalRange();return t.to-t.from},ad=e=>{const t=e.group;if(null===t)return;const o=e.widget.chart,n=o.getVisibleLogicalRange(),i=o.dataLayer,a=i.indexToTimeFloat(n.from),r=i.indexToTimeFloat(n.to);r>a&&(t.view={from:a,to:r},t.keeper=e)},rd=e=>{null!==e&&(e.view=null,e.keeper=null)};function sd(e,t){const{widget:o}=t,n=o.chart;!function(e,t){if(!1===e.options.shortcutsEditor)return;const o=t.widget.context.keymap;o.applyOverrides(e.chords),t.offs.push(o.onChange(()=>{if(!e.sharing){e.sharing=!0;try{const n=o.overrides();e.chords=n;for(const o of e.cells)o!==t&&o.widget.context.keymap.applyOverrides(n);0===Object.keys(n).length?e.storage.remove(to):e.storage.set(to,n)}finally{e.sharing=!1}}}))}(e,t);let i=!1,a=!1;const r=()=>i||e.syncing||a;t.offs.push(n.on("data:update",()=>{i=!0,queueMicrotask(()=>{i=!1}),t.span=id(t),t===t.group?.keeper&&ad(t)})),t.member=function(e,t,o){return{on:(o,n)=>e.on(o,"pan"===o||"zoom"===o?e=>{t()||n(e)}:"symbol"===o?e=>{const t=e;n({symbol:Bl(t.symbol,t.exchange)})}:n),getVisibleLogicalRange:()=>e.getVisibleLogicalRange(),setVisibleLogicalRange:t=>o(()=>e.setVisibleLogicalRange(t)),get dataLayer(){return e.dataLayer},get isDestroyed(){return e.isDestroyed},panes:()=>e.panes(),addPrimitive:(t,o)=>e.addPrimitive(t,o),removePrimitive:t=>e.removePrimitive(t),setLinkedCrosshairIndex:t=>e.setLinkedCrosshairIndex(t)}}(n,r,e=>{a=!0;try{e()}finally{a=!1}});const s=()=>{t===t.group?.keeper&&rd(t.group),Hc(e),dc(e)},l=()=>{const o=!r();t.span=id(t),(o||t===t.group?.keeper)&&ad(t),!o&&e.held||cc(e)},c=()=>dc(e),d=()=>cc(e);t.offs.push(o.on("interval",({interval:e})=>t.group?.links.setInterval(t.member,e)),o.on("theme",({chartTheme:t})=>{e.themeSync||e.grid.setTheme(t)}),o.on("symbol",s),o.on("interval",s),o.on("variant",s),o.on("layout",()=>{const e=o.chartType();e!==t.type&&(t.type=e,t.group?.links.setChartType(t.member,e))}),o.on("layout",d),n.on("pan",l),n.on("zoom",l),n.on("resize",()=>function(e,t){const o=t.widget.chart,n=o.getVisibleLogicalRange(),i=o.dataLayer,a=t.span,r=t.group,s=null!==r&&r.links.options().viewport?r.view:null,l=t.hold&&a>0;if(t.hold=!1,l||null!==s&&(a>0||t!==r?.keeper)){e.syncing=!0;try{o.setVisibleLogicalRange(a>0||null===s?{from:n.to-a,to:n.to}:{from:i.timeToIndexFloat(s.from),to:i.timeToIndexFloat(s.to)})}finally{e.syncing=!1}}t.span=id(t),(t===r?.keeper||null!==s&&0===a)&&ad(t)}(e,t)),...function(e){const t=e.keymap,o=e.text,n="Chart grid",i=[t.register("Alt+Enter",()=>e.toggleMaximize(),"widget",{label:kt(o,"Maximize or restore the chart"),group:n}),t.register("Escape",()=>!!e.maximized()&&(e.restore(),!0),"widget",{label:kt(o,"Restore the grid"),group:n,layered:!0})];for(const a of["left","right","up","down"])i.push(t.register(`Alt+Shift+${Tc[a]}`,()=>e.focus(a),"widget",{label:kt(o,Pc[a]),group:n}),t.register(`Mod+Shift+${Tc[a]}`,()=>e.swap(a),"widget",{label:kt(o,jc[a]),group:n}));return i}({keymap:o.context.keymap,text:e.text,maximized:()=>e.maxed,toggleMaximize:()=>!(!e.maxed&&null!==Jc(e))&&(Yc(e,t),!0),restore:()=>Vc(e,!1),focus:o=>{const n=Ec(e.cells,t,o);return void 0!==n&&(queueMicrotask(()=>{e.destroyed||e.grid.setActive(n.id,{focus:!0})}),!0)},swap:o=>{const n=Ec(e.cells,t,o);return void 0!==n&&!bc(e)&&(e.grid.swap(t.id,n.id),!0)}}));for(const e of["draw:add","draw:remove","alert:created","alert:removed"])t.offs.push(n.on(e,c));for(const e of["draw:update","alert:updated","objects:change"])t.offs.push(n.on(e,d))}function ld(e,t){t===t.group?.keeper&&rd(t.group);for(const e of t.offs.splice(0))e();void 0!==t.member&&e.links.leave(t),t.widget.destroy(),t.element.remove()}function cd(e,t){const o=e.cells.find(e=>e.element.contains(t));void 0!==o&&e.grid.setActive(o.id)}const dd=(e,t)=>e.active?.group===t?e.active:e.cells.find(e=>e.group===t);function ud(e,t,o){const n=dd(e,t);void 0!==n&&(o.symbol&&t.links.setSymbol(n.member,Bl(n.widget.symbol(),n.widget.exchange())),o.interval&&t.links.setInterval(n.member,n.widget.interval()),o.chartType&&t.links.setChartType(n.member,n.widget.chartType()))}function pd(e,t,o){o.viewport&&!t.links.options().viewport&&rd(t),ud(e,t,o),t.links.setOptions(o)}function hd(e,t,o){if(e.destroyed)return{applied:!1,reason:"the grid is destroyed"};const n=Vl(t);if(""!==n)return{applied:!1,reason:n};const{links:i}=e,a=t.panes.find(e=>e.id===t.activePaneId)?.settings?.[Ei],r="dark"===a||"light"===a?a:e.theme,s=e.doc.createElement("div"),l=[];try{for(const n of t.layout.slots.slice().sort((e,t)=>e.row-t.row||e.column-t.column)){const i=t.panes.find(e=>e.id===n.paneId),a=nd(e,i.id,i,s,r,o);l.push(a),Object.assign(a,{row:n.row,column:n.column,rowSpan:n.rowSpan??1,columnSpan:n.columnSpan??1});const c=zi(a.widget,i,!1);if(!c.applied)throw new Error(`${i.id}: ${c.reason??"the chart state could not be restored"}`);a.type=a.widget.chartType()}}catch(t){return l.reverse().forEach(t=>ld(e,t)),{applied:!1,reason:t instanceof Error?t.message:String(t)}}e.maxed=!1,e.root.dataset.maximized="false",e.cells.forEach(t=>ld(e,t)),i.destroy(),e.cells=l,e.drawings=o;const{layout:c,sync:d}=t;e.rows=c.rows,e.cols=c.columns,e.rowW=c.rowWeights?.slice()??Rc(e.rows),e.colW=c.columnWeights?.slice()??Rc(e.cols),e.preset=c.preset??null,e.theme=r,qc(e),e.active=l.find(e=>e.id===t.activePaneId),l.forEach(t=>sd(e,t));const u=void 0===d.groups?[{id:void 0,name:null,channels:Ul(d),panes:t.panes}]:d.groups.map(e=>({id:e.id,name:e.name,channels:Ul(e),panes:t.panes.filter(t=>t.linkGroup===e.id)}));for(const t of u){const o=i.create({id:t.id,name:t.name,links:Wl});o.name===kt(e.text,"Group {letter}",{letter:o.letter})&&(o.name=null);for(const e of t.panes)i.join(l.find(t=>t.id===e.id),o);ud(e,o,{symbol:!0,interval:!0,chartType:!0}),o.links.setOptions(t.channels)}return i.prune(e.cells),od(e),dc(e),Wc(e,"layout",{reason:"workspace"}),Wc(e,"active",{id:e.active.id}),Wc(e,"links",e.grid.linkOptions()),{applied:!0}}const md={"1x1":"One chart","1x2":"Two columns","2x1":"Two rows","1x3":"Three columns","3x1":"Three rows","left-2":"Large left, two on the right","right-2":"Large right, two on the left","top-2":"Large top, two below","bottom-2":"Large bottom, two above","2x2":"Two by two","1x4":"Four columns","4x1":"Four rows","left-3":"Large left, three on the right","top-3":"Large top, three below","left-4":"Large left, four on the right","top-4":"Large top, four below","2x3":"Two rows of three","3x2":"Three rows of two","corner-5":"Large corner, five around","2x4":"Two rows of four","4x2":"Four rows of two","corner-7":"Large corner, seven around","3x3":"Three by three","3x4":"Three rows of four","4x3":"Four rows of three","4x4":"Four by four"};function gd(e,t){return kt(e,md[t])}function fd(e,t){return 1===t?kt(e,"1 chart"):kt(e,"{count} charts",{count:t})}function bd(e,t){const o=e.ownerDocument;Na(o,yl,t.styleNonce);const n=Ke(o,"div","oac-widget oac-alert-host");e.appendChild(n);const i=rt(n,o),a=lt(n,i.layer,o),r=Ke(o,"div","oac-toasts");n.appendChild(r);const s=ma(r,o,t);let l=t.theme??"dark",c=t.chartTheme??("light"===l?K:G),d=!1,u=!1,p=null;function h(){const e=i.size()>0;e!==u&&(u=e,t.onOpenChange?.(u))}const m={chart:t.chart,draw:t.draw,alerts:t.alerts,root:n,document:o,get theme(){return l},get chartTheme(){return c},keymap:new yo,bus:new mt,storage:new nt("alert-ui",null),locale:t.locale,translate:t.translate,tips:a,overlays:i,toast:(e,t)=>s.toast(e,t),status:(e,t)=>{s.toast(e,t)},symbol:()=>({symbol:t.chart.getDataContext()?.symbol??"",exchange:t.chart.getDataContext()?.exchange??""}),interval:()=>t.chart.getDataContext()?.interval??"",openOverlay:(e,t)=>{const o=i.open(e,{...t,onClose:()=>{t?.onClose?.(),h()}});return h(),o}},g=e=>{e.stopPropagation()};n.addEventListener("keydown",g);const f=t.chart.on("destroy",()=>b.destroy()),b={root:n,context:m,openList:e=>!d&&(p?.isOpen()?(p.el.focus(),!0):(p=Jr(m,e,{onClose:()=>{p=null}}),!0)),openEditor:e=>!d&&(Vr(m,void 0,e),!0),isOpen:()=>!d&&i.size()>0,close:()=>i.closeAll(),setTheme:(e,t)=>{d||(l=e,c=t??("light"===e?K:G),n.dataset.theme=e,Ma(n,ja(c,e)))},destroy:()=>{d||(d=!0,f(),i.destroy(),a.destroy(),s.destroy(),m.keymap.destroy(),m.bus.clear(),n.removeEventListener("keydown",g),n.remove())}};return b.setTheme(l,c),b}const vd="widget";export{Vo as A,_l as ACCOUNT_SUMMARY_CSS,Ha as B,Ss as BOTTOMBAR_CSS,_s as BOTTOMBAR_HEIGHT,Ri as C,il as CHART_GRID_CSS,oc as CHART_GRID_LAYOUTS,md as CHART_GRID_LAYOUT_NAMES,Jl as CHART_GRID_PRESETS,ia as CHART_TYPE_LABELS,jo as COLOR_PICKER_CSS,Xt as ChartHistory,Mt as D,el as DATA_WINDOW_CSS,ds as DATE_NAVIGATION_CSS,Cl as DEFAULT_INTERVALS,Sl as DEFAULT_LOOKBACK_BARS,hs as DEFAULT_RANGES,rs as DIALOG_CSS,Ol as DRAWINGS_KEY_PREFIX,er as DRAWING_COORDINATES_CSS,Ka as DRAWING_TEMPLATES_CSS,Ns as DRAWING_TOOLBAR_CSS,Kn as DateNavigator,Vs as EVENT_DETAILS_CSS,Ys as EventDetailsPopup,to as KEYMAP_KEY,yo as Keymap,pn as MAGNET_MODES,$n as MIN_PRICE_DIGITS,Hs as NEWS_PANEL_CSS,Bs as NewsReader,Er as OBJECTS_PANEL_CSS,ni as PANEL_DOCK_CSS,ol as QUICK_ENTRY_CSS,ul as QuoteBoard,hn as RAIL_GROUPS,gn as RAIL_PREFS_KEY,Ea as RAIL_WIDTH,Al as SAVE_DEBOUNCE_MS,In as SEARCH_DEBOUNCE_MS,Ll as STATE_KEY,Pa as STATUSLINE_HEIGHT,ot as STORAGE_PREFIX,Rn as SYMBOL_PICKER_CSS,ka as TEXT_CONTRAST,st as TIP_DWELL_MS,ha as TOAST_LEAVE_MS,pa as TOAST_MAX,ua as TOAST_MS,fa as TOKEN_PREFIX,Ps as TOOLBAR_LINE_WIDTHS,Ta as TOPBAR_HEIGHT,vl as WATCHLIST_PANEL_CSS,yl as WIDGET_COMPONENT_CSS,za as WIDGET_CSS,as as WIDGET_DIALOGS,Oa as WIDGET_FONT,$a as WIDGET_MONO,$l as WIDGET_STATE_VERSION,Da as WIDGET_STYLE_ID,vd as WIDGET_TIER,mt as WidgetBus,nt as WidgetStorage,Ra as a,Ui as applyIndicatorTemplate,Ma as applyTokens,is as attachContextMenu,Gi as b,et as boxIn,fd as c,ln as captureName,ra as chartTypeChoices,aa as chartTypeLabel,es as contextMenuEntries,xa as contrastRatio,Bo as controlsFromFields,Ro as controlsFromInputs,bd as createAlertUi,Fc as createChartGrid,Po as createColorPicker,Ba as createDrawingTemplates,zt as createIndexedDbWidgetStorage,Zn as createLayoutsController,Or as createObjectsPanelContent,rt as createOverlayStack,qe as createTimeframePreferences,lt as createTipController,Rl as createWidget,Ne as customTimeframeCode,Qi as d,at as defaultStorage,sn as downloadText,Ct as e,He as esc,lo as eventKeyCombo,Ii as f,Je as focusable,Ye as focusables,_a as formatColor,uo as formatKeyCombo,ho as fromChartCombo,$c as g,Ge as glyph,Ke as h,ut as historyPress,ht as historyReady,ac as i,Ve as inTextField,Na as injectWidgetStyles,Mo as inputConditionMet,Do as inputStates,sa as intervalLabel,Uo as j,Ji as k,gd as l,Ml as loadWindow,ya as luminance,Yo as m,Aa as mix,wl as mountAccountSummary,Vr as mountAlertEditor,Jr as mountAlertsPanel,Cs as mountBottombar,ns as mountContextMenu,Xs as mountDataWindow,Xa as mountDrawingCoordinates,fr as mountDrawingProperties,zs as mountDrawingToolbar,_r as mountIndicatorInputControls,vr as mountIndicatorPicker,Ir as mountIndicatorSettings,nr as mountLevelEditor,Ts as mountMobile,Us as mountNewsPanel,$r as mountObjectsPanel,oi as mountPanelDock,tl as mountQuickEntry,wn as mountRail,zr as mountSettingsDialog,Pn as mountStatusline,Nn as mountSymbolPicker,dr as mountTextEditor,ma as mountToasts,da as mountTopbar,bl as mountWatchlistPanel,qo as n,Ko as o,$t as openCustomTimeframeDialog,cs as openDateNavigation,Zi as openLayoutsMenu,rn as openMenu,Lo as openShortcutsPanel,Et as openTimeframeMenu,Qo as p,va as parseColor,so as parseKeyCombo,Qe as placeBelow,Ze as placeBeside,Xe as placeTip,En as priceDigits,Ki as q,cl as quoteChange,Ic as r,gs as rangeInterval,ws as rangeWindow,Zs as readDataWindow,Ca as readableOn,ft as registerWidgetDialog,bt as registerWidgetDialogs,_t as registeredWidgetDialogs,nn as renderForm,jl as resolveTheme,Vi as s,qs as safeNewsUrl,Dn as safeSymbolIconUrl,ti as sanitizePanelDockState,vn as sanitizeRailPrefs,Hi as saveIndicatorTemplate,Pl as stripView,Lr as t,Sa as themeMode,Ia as token,bn as toolGlyph,mn as toolName,Za as u,vt as unregisterWidgetDialog,Ya as v,Mn as w,wt as widgetDialog,Ni as widgetLayoutTarget,kt as widgetText,ja as widgetTokens,La as withAlpha,Zo as x,Go as y,pt as z};
//# sourceMappingURL=openalgo-charts.widget.mjs.map