UNPKG

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 173 kB
import{formatZonedCrosshairLabel as e,registeredChartTypes as t,getChartType as o,INDICATOR_SOURCES as n,registeredIndicators as i,getIndicator as a,indicatorStyleInputs as r,indicatorDefaults as s,chartSettingsSchema as l,readChartSettings as c,applyChartSettings as d,PRICE_SCALE_MODES as p,tryResolveInterval as h,lightTheme as u,darkTheme as g,DataLoadingController as b,resolveInterval as f,isKnownInterval as m,registeredIntervals as w,createChart as v,ChartObjects as x}from"./openalgo-charts.mjs";import{chromeIconSvg as _,hasDrawingTool as y,DRAWING_TOOL_ICONS as k,iconUse as C,getDrawingTool as $,iconSprite as S,toolCursor as L,drawingShortcuts as A,DEFAULT_FIB as E,drawingSettingsSchema as T,gannLabel as M,formatRatio as O,readDrawingSetting as j,cloneLevels as P,applyDrawingSettings as D,LEVEL_NEUTRAL as I,levelColor as N,readDrawingSettings as R,registeredDrawingTools as z,DrawingController as H,keyToDrawingAction as F}from"./openalgo-charts.draw.mjs";const B=e=>String(e).replace(/[&<>"]/g,e=>"&"===e?"&amp;":"<"===e?"&lt;":">"===e?"&gt;":"&quot;");function U(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 V(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 K(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 q(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 W=e=>Array.from(e.querySelectorAll("*")).filter(q);function G(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 Y(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 Z(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 J(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}}class X{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 Q="oac-widget:";class ee{constructor(e,t){Object.defineProperty(this,"_store",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_ns",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._ns=Q+e+":",this._store=t}key(e){return this._ns+e}get(e){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._store)return!1;try{return this._store.setItem(this.key(e),JSON.stringify(t)),!0}catch{return!1}}remove(e){if(null!==this._store)try{this._store.removeItem(this.key(e))}catch{}}get enabled(){return null!==this._store}}function te(){try{const e=globalThis;return void 0!==e.localStorage&&"function"==typeof e.localStorage.getItem?e.localStorage:null}catch{return null}}const oe=new Map;function ne(e,t){return oe.set(e,t),()=>{oe.get(e)===t&&oe.delete(e)}}function ie(e){const t=Object.entries(e).map(([e,t])=>ne(e,t));return()=>{for(const e of t)e()}}function ae(e){return oe.delete(e)}function re(e){return oe.get(e)??null}function se(){return Array.from(oe.keys())}function le(e,t){const o=U(t,"div","oac-layer");e.appendChild(o);const n=[],i=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&&l()},a=e=>{const o=n[n.length-1];if(void 0===o)return;if("Escape"===e.key){if(!1===o.opts.dismissOnEscape)return;return e.preventDefault(),e.stopImmediatePropagation(),void i(o)}if("Tab"!==e.key)return;const a=W(o.el);if(0===a.length)return void e.preventDefault();const r=a.indexOf(t.activeElement);let s=null;e.shiftKey?r<=0&&(s=a.length-1):(-1===r||r>=a.length-1)&&(s=0),null!==s&&(e.preventDefault(),a[s].focus())},r=e=>{const t=e.target;for(let e=n.length-1;e>=0;e--){const o=n[e];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;i(o)}};let s=!1;const l=()=>{s&&(s=!1,t.removeEventListener("keydown",a,!0),t.removeEventListener("pointerdown",r,!0))};return{open:(l,c={})=>{const d=c.placement??(c.anchor?"below":"center"),p=c.modal??"center"===d,h=t.activeElement,u=null===h||h===t.body||l.contains(h)?null:h;let g=null;const b={el:l,opts:{...c,modal:p},scrim:null,restore:u,closed:!1};if(p&&(g=U(t,"div","oac-scrim"),!0===c.dismissOnOutside&&g.addEventListener("pointerdown",()=>i(b)),o.appendChild(g),b.scrim=g),l.addEventListener("pointerdown",e=>e.stopPropagation()),"center"===d?(l.classList.add("oac-dialog"),l.hasAttribute("role")||l.setAttribute("role","dialog"),l.setAttribute("aria-modal","true")):l.classList.add("oac-pop"),l.hasAttribute("tabindex")||(l.tabIndex=-1),o.appendChild(l),"center"!==d&&c.anchor){const t=e.getBoundingClientRect();let o=J(e,c.anchor);if("beside"===d&&c.edge){const t=J(e,c.edge),n=Math.max(o.right,t.right);o={...o,right:n,width:n-o.left}}const n={width:l.offsetWidth,height:l.offsetHeight},i="beside"===d?G(o,n,t):Y(o,n,t);l.style.left=i.left+"px",l.style.top=i.top+"px",c.anchor.setAttribute("aria-expanded","true")}if(n.push(b),s||(s=!0,t.addEventListener("keydown",a,!0),t.addEventListener("pointerdown",r,!0)),null!==c.initialFocus){(c.initialFocus??function(e){const t=W(e);return t.find(e=>null===e.closest(".oac-dialog__head"))??t[0]??null}(l)??l).focus()}return()=>i(b)},closeTop:()=>{const e=n[n.length-1];return void 0!==e&&(i(e),!0)},closeAll:()=>{for(const e of n.slice().reverse())i(e)},top:()=>n[n.length-1]?.el??null,size:()=>n.length,layer:o,destroy:()=>{for(const e of n.slice().reverse())i(e);l(),o.remove()}}}const ce=600;function de(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.title),null===i&&(i=U(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=U(o,"kbd","oac-tip__chord");e.textContent=d.chord,i.appendChild(e)}if(d.sub){const e=U(o,"span","oac-tip__sub");e.textContent=d.sub,i.appendChild(e)}const p=e.getBoundingClientRect(),h=Z(J(e,a),{width:i.offsetWidth,height:i.offsetHeight},p,d.side??"right");i.style.left=h.left+"px",i.style.top=h.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.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.title)},show:c,hide:l,target:()=>r,destroy:()=>{l(),i?.remove(),i=null}}}const pe={mod:"Mod",ctrl:"Mod",control:"Mod",cmd:"Mod",command:"Mod",meta:"Mod",win:"Mod",alt:"Alt",option:"Alt",opt:"Alt",shift:"Shift"},he={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:","},ue=new Set(["Shift","Control","Alt","Meta","OS","AltGraph","CapsLock","Fn"]),ge=["Mod","Alt","Shift"];function be(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!==pe[o.toLowerCase()])return"";const i=new Set;for(const e of n){const t=pe[e.toLowerCase()];if(void 0===t)return"";i.add(t)}o=function(e){const t=e.toLowerCase();return void 0!==he[t]?he[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[...ge.filter(e=>i.has(e)),o].join("+")}function fe(e){let t=e.key??"";if(""===t||"Unidentified"===t||ue.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 me={Escape:"Esc",Delete:"Del",ArrowLeft:"Left",ArrowRight:"Right",ArrowUp:"Up",ArrowDown:"Down"};function we(){const e=globalThis.navigator;return void 0!==e&&/mac|iphone|ipad/i.test(e.platform??e.userAgent??"")}function ve(e,t=we()){const o=be(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"),me[i]??(1===i.length?i.toUpperCase():i)].join("+")}function xe(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=/^Digit([0-9])$/.exec(o);return i=null!==a?a[1].toLowerCase():null!==r?r[1]:"Equal"===o?n.includes("Shift")?"+":"=":"Minus"===o?n.includes("Shift")?"_":"-":"NumpadAdd"===o?"+":"NumpadSubtract"===o?"-":"Slash"===o?n.includes("Shift")?"?":"/":o,be([...n,i].join("+"))}class _e{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,"_conflicts",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_conflictListeners",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"_detach",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_nextId",{enumerable:!0,configurable:!0,writable:!0,value:1}),this._isMac=e.isMac??we(),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=be(e);if(""===i)throw new Error(`openalgo-charts widget: "${e}" is not a key binding`);const a={id:this._nextId++,combo:i,scope:o,label:n.label??ve(i,this._isMac),group:n.group??"Widget",hidden:!0===n.hidden,inText:!0===n.inText,layered:!0===n.layered,action:t,when:n.when},r=this._byCombo.get(i)??[];if(!0!==n.layered){const e=r.find(e=>e.scope===o);void 0!==e&&this._conflict({combo:i,scope:o,kept:e.label,shadowed:a.label,source:"widget"})}return r.push(a),this._byCombo.set(i,r),this._bindings.push(a),()=>this._unregister(a)}_unregister(e){const t=this._bindings.indexOf(e);t>=0&&this._bindings.splice(t,1);const o=this._byCombo.get(e.combo);if(void 0!==o){const t=o.indexOf(e);t>=0&&o.splice(t,1),0===o.length&&this._byCombo.delete(e.combo)}for(let t=this._conflicts.length-1;t>=0;t--){const o=this._conflicts[t];"widget"!==o.source||o.combo!==e.combo||o.kept!==e.label&&o.shadowed!==e.label||this._conflicts.splice(t,1)}}_conflict(e){this._conflicts.push(e);for(const t of this._conflictListeners)t(e)}onConflict(e){return this._conflictListeners.add(e),()=>this._conflictListeners.delete(e)}handle(e){const t=fe(e);if(""===t)return!1;const o=this._byCombo.get(t);if(void 0===o)return!1;const n=K(e.target);for(const t of this._scopes())for(const i of o)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._detach=()=>{e.removeEventListener("keydown",t,!0),this._detach=null},this._detach}list(){return this._bindings.slice()}conflicts(){const e=this._conflicts.slice();if(null!==this._chart)for(const t of this._chart.list())if(!t.isDisabled)for(const o of t.combos){const n=xe(o),i=(this._byCombo.get(n)??[]).find(e=>"overlay"!==e.scope&&"rail"!==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 ve(e,this._isMac)}describe(){const e=new Map;for(const t of this._bindings){if(t.hidden)continue;const o=e.get(t.group)??[];o.push({label:t.label,combo:t.combo,display:this.format(t.combo)}),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=[];for(const t of this._chart.list()){if(t.isDisabled||0===t.combos.length)continue;const n=xe(t.combos[0]),i={label:t.label,combo:n,display:this.format(n)},a=e.get(t.label+"|"+n);void 0!==a&&(i.shadowedBy=a),o.push(i)}o.length>0&&t.push({group:"Chart",rows:o})}return t}destroy(){this._detach?.(),this._bindings.length=0,this._byCombo.clear(),this._conflicts.length=0,this._conflictListeners.clear()}}function ye(e){const t=e.document,o=U(t,"div","oac-keys-dialog",{"aria-label":"Keyboard shortcuts"}),n=U(t,"div","oac-dialog__head"),i=U(t,"div","oac-dialog__title");i.textContent="Keyboard shortcuts";const a=U(t,"button","oac-btn oac-btn--icon",{type:"button","aria-label":"Close"});a.innerHTML=_("close"),n.appendChild(i),n.appendChild(a);const r=U(t,"div","oac-dialog__body"),s=U(t,"div","oac-keys");let l=0;for(const o of e.keymap.describe()){const e=U(t,"div","oac-keys__group"),n=U(t,"div","oac-head");n.textContent=o.group,e.appendChild(n);for(const n of o.rows){const o=U(t,"div","oac-keys__row"),i=U(t,"span");i.textContent=n.label;const a=U(t,"kbd");a.textContent=n.display,o.appendChild(i),o.appendChild(a),void 0!==n.shadowedBy&&(o.classList.add("is-shadowed"),o.title=`Claimed by ${n.shadowedBy}`,l++),e.appendChild(o)}s.appendChild(e)}if(r.appendChild(s),l>0){const e=U(t,"div","oac-keys__note");e.textContent=`${l} chart shortcut${1===l?"":"s"} struck through: the same chord arms a drawing tool here and takes precedence.`,r.appendChild(e)}o.appendChild(n),o.appendChild(r);const c=e.openOverlay(o,{placement:"center",dismissOnOutside:!0});return a.addEventListener("click",c),c}const ke=["off","weak","strong"],Ce=[{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:"dedekind-tessellation"},{tool:"sonic"},{tool:"supersonic"},{tool:"golden-sonic"},{tool:"golden-supersonic"}]},{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:"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"}]}],$e=e=>null!==e&&y(e)?$(e).name:String(e??"Cursor"),Se="rail",Le="oac-rail-sprite";function Ae(e,t){if(void 0!==k[t])return V(e,C(t),"tool");const o=U(e,"span","oac-glyph oac-glyph--text",{"aria-hidden":"true"});return o.textContent=String(t).charAt(0).toUpperCase(),o}const Ee=(e,t)=>V(e,_(t),"chrome");function Te(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&&y(e)&&o.indexOf(e)===t)),"string"==typeof i.magnet&&ke.includes(i.magnet)&&(n.magnet=i.magnet),n.stay=!0===i.stay,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 Me(e,t,o={}){const n=e.document,i=e.draw,a=e.chart;!function(e){if(null!==e.getElementById(Le))return;const t=e.createElement("div");t.id=Le,t.hidden=!0,t.innerHTML=S(),(e.body??e.documentElement).appendChild(t)}(n);const r=void 0===o.tools?null:new Set(o.tools),s=e=>(e.items??[]).filter(e=>void 0!==e.tool&&y(e.tool)&&(null===r||r.has(e.tool))).map(e=>e.tool),l=e=>Ce.find(t=>t.id===e);let c=Te(e.storage.get(Se),Ce,s);null===e.storage.get(Se)&&o.favorites&&(c.favorites=o.favorites.filter((e,t,o)=>y(e)&&o.indexOf(e)===t));let d=!1;const p=()=>{e.storage.set(Se,c)},h=e=>c.last[e.id??""]??s(e)[0]??null;let u=null;const g=t=>{if(null===t)return;null===u&&(u=A());const o=u[t];return void 0===o?void 0:e.keymap.format(o)},b=()=>{const e=i;if("function"==typeof e.selection)return e.selection().slice();const t=i.selected();return null===t?[]:[t]},f=e=>e.length>0&&e.every(e=>!0===i.get(e)?.locked),m=e=>e.length>0&&e.every(e=>!1===i.get(e)?.visible),w=e=>{const t=o.cursorTarget;t&&(null!==e&&void 0!==k[e]?t.style.setProperty("--oac-tool-cursor",L(e)):t.style.removeProperty("--oac-tool-cursor"))},v=()=>{i.setOptions({magnet:c.magnet})},x=()=>{i.setOptions({stayInDrawingMode:c.stay||d})},C=e=>{if(!ke.includes(e))throw new Error(`openalgo-charts widget: unknown magnet mode "${String(e)}"`);c.magnet=e,p(),v(),K()},$=()=>{const t=ke[(ke.indexOf(c.magnet)+1)%ke.length];return C(t),e.status("off"===t?"Magnet off":"weak"===t?"Magnet weak: snaps when O/H/L/C is within a few pixels":"Magnet strong: every anchor lands on the nearest O/H/L/C"),t},E=t=>{c.stay=!0===t,p(),x(),K(),e.status(c.stay?"Tools stay armed after each drawing":"One drawing per pick")},T=e=>{d=!0===e,x(),Q(i.activeTool())},M=e=>{i.setTool(e),Q(e)},O=t=>{T(!0),M(t),e.status(`${$e(t)} stays armed until Escape`)};t.classList.add("oac-rail"),t.setAttribute("role","toolbar"),t.setAttribute("aria-orientation","vertical"),t.setAttribute("aria-label","Drawing tools");const j=t=>{const o=U(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},P=(e,t)=>{const o=e.querySelector(".oac-glyph");o?o.replaceWith(t):e.insertBefore(t,e.firstChild)},D=()=>U(n,"div","oac-rail__sep",{role:"separator"}),I=e=>{const t=j({cls:"oac-rail__tool oac-rail__fav",glyphEl:Ae(n,e),tip:()=>({title:$e(e),chord:g(e),sub:"Pinned. Right-click to unpin",side:"right"}),onClick:t=>{t.detail>=2&&!c.stay?O(e):(T(!1),M(e))},onContext:()=>F(t,[{label:"Unpin from rail",icon:"star",onSelect:()=>Y(e,!1)}])});return t.dataset.tools=e,t},N=e=>{const t=s(e),o=j({cls:"oac-rail__tool oac-rail__group",glyphEl:Ae(n,h(e)??t[0]),tip:()=>({title:$e(h(e)),chord:g(h(e)),sub:(e.title??"")+": chevron for the rest"+(c.stay?"":". Double-click keeps it armed"),side:"right"}),onClick:t=>{const n=t.target,a=null!==n&&"function"==typeof n.closest&&null!==n.closest(".oac-rail__chev");if(null===R||"true"!==o.getAttribute("aria-expanded"))if(a)H(e,o,!1);else{if(t.detail>=2&&!c.stay){const t=h(e);return void(null!==t&&O(t))}i.activeTool()!==h(e)?(T(!1),M(h(e))):H(e,o,!1)}else z()},onContext:()=>H(e,o,!1)});o.dataset.tools=t.join(","),o.dataset.group=e.id??"",o.dataset.face=h(e)??"",o.setAttribute("aria-haspopup","menu"),o.setAttribute("aria-expanded","false");const a=U(n,"span","oac-rail__chev",{"aria-hidden":"true"});return a.innerHTML=_("chevron-right"),o.appendChild(a),o};let R=null;const z=()=>{R?.close()},H=(o,a,s)=>{z(),e.tips.hide();const l=U(n,"div","oac-fly",{role:"menu","aria-label":o.title??"Tools"}),d=i.activeTool(),h=[];for(const e of o.items??[]){if(void 0!==e.head){const t=U(n,"div","oac-head");t.textContent=e.head,l.appendChild(t);continue}const t=e.tool;if(void 0===t||!y(t)||null!==r&&!r.has(t))continue;const o=U(n,"div","oac-fly__row",{role:"menuitemradio","aria-checked":String(d===t)});o.tabIndex=-1,o.dataset.tool=t,o.appendChild(Ae(n,t));const i=U(n,"span","oac-fly__name");i.textContent=$e(t),o.appendChild(i);const s=W(t),c=U(n,"button","oac-fly__star",{type:"button","aria-pressed":String(s),"aria-label":s?"Unpin from rail":"Pin to rail"});c.tabIndex=-1,c.innerHTML=_(s?"star-filled":"star"),o.appendChild(c);const p=U(n,"kbd","oac-fly__chord");p.textContent=g(t)??"",o.appendChild(p);const b=()=>{const e=!W(t);Y(t,e),c.setAttribute("aria-pressed",String(e)),c.setAttribute("aria-label",e?"Unpin from rail":"Pin to rail"),c.innerHTML=_(e?"star-filled":"star")};c.addEventListener("click",e=>{e.stopPropagation(),b()}),o.addEventListener("click",e=>{e.stopPropagation(),u(t)}),o.addEventListener("keydown",e=>{const o=e;"Enter"!==o.key&&" "!==o.key||(o.preventDefault(),o.stopPropagation(),null!==o.target.closest(".oac-fly__star")?b():(u(t),a.focus()))}),h.push(o),l.appendChild(o)}const u=e=>{void 0!==o.id&&(c.last[o.id]=e,p()),z(),T(!1),M(e)};l.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 b=h.find(e=>"true"===e.getAttribute("aria-checked"))??h[0]??null,f=e.openOverlay(l,{anchor:a,placement:"beside",edge:t,initialFocus:s?b:l,onClose:()=>{null!==R&&R.el===l&&(R=null)}});R={el:l,close:f}},F=(o,i)=>{e.tips.hide();const a=U(n,"div","oac-menu",{role:"menu"});let r=()=>{};for(const e of i){const t=U(n,"button","oac-menu__row"+(e.danger?" is-danger":""),{type:"button",role:"menuitem","aria-disabled":String(!0===e.disabled)});t.appendChild(void 0!==e.tool?Ae(n,e.tool):void 0!==e.icon?Ee(n,e.icon):U(n,"span","oac-glyph"));const o=U(n,"span","oac-menu__label");o.textContent=e.label,t.appendChild(o),t.addEventListener("click",t=>{t.stopPropagation(),e.disabled||(r(),e.onSelect())}),a.appendChild(t)}r=e.openOverlay(a,{anchor:o,placement:"beside",edge:t})},B={},V=(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,P(e,Ee(n,t.glyph))))},K=()=>{if(void 0===B.magnet)return;V(B.magnet,{on:"strong"===c.magnet,pressed:"off"!==c.magnet}),B.magnet.classList.toggle("is-weak","weak"===c.magnet),B.magnet.dataset.mode=c.magnet,V(B.stay,{on:c.stay,pressed:c.stay});const t=b(),o=0===t.length,n=!o&&f(t),a=!o&&m(t);V(B.lock,{off:o,on:n,pressed:n,glyph:n?"unlock":"lock"}),V(B.eye,{off:o,on:a,pressed:a,glyph:a?"eye-off":"eye"}),V(B.trash,{off:o}),V(B.undo,{off:!i.canUndo()}),V(B.redo,{off:!i.canRedo()});for(const t of Object.values(B))e.tips.refreshLabel(t)};let q=null;const W=e=>c.favorites.includes(e),G=()=>{if(null===q)return;q.textContent="";const e=c.favorites.filter(e=>y(e));if(0!==e.length){q.appendChild(D());for(const t of e)q.appendChild(I(t))}},Y=(e,t=!W(e))=>{if(!y(e))return;const o=W(e);t&&!o&&c.favorites.push(e),!t&&o&&c.favorites.splice(c.favorites.indexOf(e),1),p(),G(),Q(i.activeTool())},Z=()=>Array.from(t.querySelectorAll(".oac-rail__btn")),J=e=>{for(const t of Z())t.tabIndex=t===e?0:-1},X=()=>{t.textContent="",t.appendChild((()=>{const e=j({cls:"oac-rail__tool",glyphEl:Ae(n,"cursor"),tip:()=>({title:"Cursor",chord:"Esc",side:"right"}),onClick:()=>{T(!1),M(null)}});return e.dataset.tools="",e})()),q=U(n,"div","oac-rail__favs"),t.appendChild(q),G(),t.appendChild(D());for(const e of Ce)e.sep?t.appendChild(D()):s(e).length>0&&t.appendChild(N(e));t.appendChild((()=>{const t=U(n,"div","oac-rail__ctl");return B.magnet=j({cls:"oac-rail__btn--magnet",glyphEl:Ae(n,"magnet"),tip:()=>({title:"Magnet: "+c.magnet,sub:"off"===c.magnet?"Click for weak: snaps when O/H/L/C is within a few pixels":"weak"===c.magnet?"Click for strong: every anchor lands on the nearest O/H/L/C":"Click to switch the magnet off",side:"right"}),onClick:()=>{$()}}),t.appendChild(B.magnet),B.stay=j({cls:"oac-rail__btn--chrome",glyphEl:Ee(n,"link"),tip:()=>({title:"Keep tool armed",sub:c.stay?"On: the tool stays armed after each drawing":"Off: one drawing per pick",side:"right"}),onClick:()=>E(!c.stay)}),t.appendChild(B.stay),t.appendChild(D()),B.lock=j({cls:"oac-rail__btn--chrome",glyphEl:Ee(n,"lock"),tip:()=>{const e=b();return 0===e.length?{title:"Lock drawing",sub:"Select a drawing first",side:"right"}:{title:f(e)?"Unlock drawing":"Lock drawing",side:"right"}},onClick:()=>{const e=b(),t=!f(e);for(const o of e)i.update(o,{locked:t});K()}}),t.appendChild(B.lock),B.eye=j({cls:"oac-rail__btn--chrome",glyphEl:Ee(n,"eye"),tip:()=>{const e=b();return 0===e.length?{title:"Hide drawing",sub:"Select a drawing first",side:"right"}:m(e)?{title:"Show drawing",side:"right"}:{title:"Hide drawing",sub:"Stays selected, so the eye brings it back",side:"right"}},onClick:()=>{const e=b(),t=m(e);for(const o of e)i.update(o,{visible:t});K()}}),t.appendChild(B.eye),B.trash=j({cls:"oac-rail__btn--chrome oac-rail__btn--danger",glyphEl:Ee(n,"trash"),tip:()=>{const e=b();return e.length>0?{title:e.length>1?`Delete ${e.length} drawings`:"Delete drawing",chord:"Del",sub:"Right-click to remove all",side:"right"}:{title:"Delete drawing",chord:"Del",sub:"Select one first. Right-click to remove all",side:"right"}},onClick:()=>{for(const e of b())i.remove(e);K()},onContext:()=>{const t=i.drawings().length;F(B.trash,[{label:`Select all (${t})`,icon:"cursor",disabled:0===t,onSelect:()=>{i.select(i.drawings().map(e=>e.id)),K()}},{label:`Remove all drawings (${t})`,icon:"trash",danger:!0,disabled:0===t,onSelect:()=>{i.clear(),K(),e.status(t>0?`Removed ${t} drawing${1===t?"":"s"}`:"No drawings to remove")}}])}}),t.appendChild(B.trash),t.appendChild(D()),B.undo=j({cls:"oac-rail__btn--chrome",glyphEl:Ee(n,"undo"),tip:()=>({title:"Undo",chord:e.keymap.format("Mod+Z"),side:"right"}),onClick:()=>{i.undo(),K()}}),t.appendChild(B.undo),B.redo=j({cls:"oac-rail__btn--chrome",glyphEl:Ee(n,"redo"),tip:()=>({title:"Redo",chord:e.keymap.format("Mod+Y"),side:"right"}),onClick:()=>{i.redo(),K()}}),t.appendChild(B.redo),t})()),Q(i.activeTool())},Q=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&&d&&t.length>0),o.setAttribute("aria-pressed",String(r)),r&&null===a&&(a=o),r&&o.dataset.group&&t.length>0&&null!==i&&(c.last[o.dataset.group]!==i&&(c.last[o.dataset.group]=i,p()),o.dataset.face!==i&&(o.dataset.face=i,P(o,Ae(n,i)))),e.tips.refreshLabel(o)}const r=n.activeElement;null===a||null!==r&&t.contains(r)||J(a),w(i),K()},ee=()=>{const e=n.activeElement;return null!==e&&t.contains(e)?e.closest(".oac-rail__btn"):null},te=e=>{const t=Z();if(0===t.length)return;const o=t[(e%t.length+t.length)%t.length];J(o),o.focus()},oe=[],ne=(t,o,n)=>{oe.push(e.keymap.register(t,o,"rail",{label:n,group:"Tool rail"}))};ne("ArrowDown",()=>{te(Z().indexOf(ee())+1)},"Next tool"),ne("ArrowUp",()=>{te(Z().indexOf(ee())-1)},"Previous tool"),ne("Home",()=>{te(0)},"First tool"),ne("End",()=>{te(Z().length-1)},"Last tool"),ne("ArrowRight",()=>{const e=ee(),t=e?.dataset.group?l(e.dataset.group):void 0;return null!==e&&void 0!==t&&(H(t,e,!0),!0)},"Open the group"),ne("Escape",()=>{const t=null!==R;z(),e.tips.hide();const n=o.cursorTarget;return void 0!==n&&"function"==typeof n.focus?n.focus():ee()?.blur(),t},"Back to the chart");const ie=e=>{const t=e.target,o=null!==t&&"function"==typeof t.closest?t.closest(".oac-rail__btn"):null;null!==o&&J(o)};t.addEventListener("focusin",ie);const ae=[];ae.push(a.on("draw:tool",e=>{Q(e.tool)}));for(const e of["draw:select","drawing:select","drawing:change","draw:add","draw:remove","draw:update","draw:paste","draw:cut"])ae.push(a.on(e,K));return v(),x(),X(),{el:t,sync:Q,refresh:K,prefs:()=>({favorites:c.favorites.slice(),magnet:c.magnet,stay:c.stay,last:{...c.last}}),restorePrefs:e=>{c=Te(e,Ce,s),p(),v(),x(),X()},magnetMode:()=>c.magnet,setMagnetMode:C,cycleMagnet:$,stayMode:()=>c.stay,setStayMode:E,favorites:()=>c.favorites.slice(),isFavorite:W,toggleFavorite:Y,setDrawLock:T,drawLocked:()=>d,openGroup:(e,o=!1)=>{const n=l(e),i=t.querySelector(`.oac-rail__group[data-group="${e}"]`);void 0!==n&&null!==i&&H(n,i,o)},closeFlyout:z,flyoutOpen:()=>null!==R,destroy:()=>{z();for(const e of ae)e();for(const e of oe)e();t.removeEventListener("focusin",ie),w(null),t.textContent=""}}}const Oe=2;function je(e){const t=e.panes()[0];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 Pe(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 De(t,o,n={}){const i=t.document,a=t.chart,r=n.locale??t.locale;o.classList.add("oac-statusline"),o.setAttribute("role","status"),o.setAttribute("aria-live","polite");const s=U(i,"span","oac-statusline__title"),l=U(i,"span","oac-statusline__sym"),c=U(i,"span","oac-statusline__iv");s.appendChild(l),s.appendChild(c),o.appendChild(s);const d=(e,t)=>{const n=U(i,"span","oac-statusline__field "+t),a=U(i,"i");a.textContent=e;const r=U(i,"b");return n.appendChild(a),n.appendChild(r),n.hidden=!0,o.appendChild(n),{el:n,val:r}},p=d("O","oac-statusline__o"),h=d("H","oac-statusline__h"),u=d("L","oac-statusline__l"),g=d("C","oac-statusline__c"),b=d("","oac-statusline__chg"),f=d("Vol","oac-statusline__vol"),m=U(i,"span","oac-statusline__time");o.appendChild(m);const w=U(i,"span","oac-statusline__msg");o.appendChild(w);const v=U(i,"span","oac-statusline__tz");o.appendChild(v);const x=new Map,_=new Intl.NumberFormat(r,{minimumFractionDigits:2,maximumFractionDigits:2}),y=new Intl.NumberFormat(r,{notation:"compact",maximumFractionDigits:2});let k=null,C=null;const $=(e,t)=>{e.textContent!==t&&(e.textContent=t)},S=(e,t)=>{e.hidden===t&&(e.hidden=!t)},L=()=>{const t=a.statusLineOptions();S(s,!1!==t.title);const o=!1!==t.chartValues&&null!==k;for(const e of[p,h,u,g])S(e.el,o);const n=je(a);if(o&&null!==k){const e=Pe(r,n,x);$(p.val,e.format(k.open)),$(h.val,e.format(k.high)),$(u.val,e.format(k.low)),$(g.val,e.format(k.close))}const i=!1!==t.barChange&&null!==k;if(S(b.el,i),i&&null!==k){const e=k.close-k.open,t=0!==k.open?e/k.open*100:0,o=e>0?"+":"";$(b.val,`${o}${Pe(r,n,x).format(e)} (${o}${_.format(t)}%)`),b.el.classList.toggle("is-up",e>0),b.el.classList.toggle("is-down",e<0)}const l=!1!==t.volume&&null!==k&&"number"==typeof k.volume;S(f.el,l),l&&null!==k&&$(f.val,y.format(k.volume)),$(m,null!==C&&null!==k?e(C,a.timezone()):""),$(v,a.timezone())},A=()=>{const e=a.primarySeries()?.getData()??[],t=e[e.length-1];return void 0===t?{bar:null,time:null}:{bar:t,time:t.time}},E=(e,t)=>{e===k&&t===C||(k=e,C=t,L())},T=a.on("crosshair:move",e=>{const t=e;if(null!==t.bar&&void 0!==t.bar)return void E(t.bar,t.time);const o=A();E(o.bar,o.time)}),M=a.on("resize",()=>{if(null===k){const e=A();E(e.bar,e.time)}}),O={el:o,setMessage:(e,t="info")=>{$(w,e),w.classList.toggle("is-error","error"===t)},setSymbol:(e,t,o)=>{$(l,t?`${t}:${e}`:e),$(c,o)},setBar:E,refresh:()=>{if(null===k){const e=A();k=e.bar,C=e.time}L()},destroy:()=>{T(),M(),o.textContent=""}};return L(),O}const Ie=150,Ne={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 Re(e){const t=Ne[e];return void 0!==t?t:e.replace(/[-_]+/g," ").replace(/^\w/,e=>e.toUpperCase())}function ze(){return t().filter(e=>{try{return o(e).isPriceSeries}catch{return!1}})}function He(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 Fe(e,t,o,n={}){const i=e.document,a=U(i,"div","oac-menu",{role:"menu"});n.ariaLabel&&a.setAttribute("aria-label",n.ariaLabel);let r=null;if(n.find){const e=U(i,"div","oac-menu__find");r=U(i,"input",void 0,{type:"text",placeholder:n.find,"aria-label":n.find}),e.appendChild(r),a.appendChild(e)}const s=U(i,"div","oac-menu__body");a.appendChild(s);let l=()=>{};const c=e=>{const t=e.trim().toLowerCase();s.textContent="";let n=0,a=null;for(const e of o){if("string"==typeof e){a=e;continue}if(""!==t&&!e.label.toLowerCase().includes(t)&&!(e.sub??"").toLowerCase().includes(t))continue;if(null!==a){const e=U(i,"div","oac-head");e.textContent=a,s.appendChild(e),a=null}const o=U(i,"button","oac-menu__row"+(e.danger?" is-danger":""),{type:"button",role:"menuitemradio","aria-checked":String(!0===e.on),"aria-disabled":String(!0===e.disabled)}),r=U(i,"span","oac-menu__label");if(r.textContent=e.label,o.appendChild(r),e.sub){const t=U(i,"span","oac-menu__sub");t.textContent=e.sub,o.appendChild(t)}if(e.key){const t=U(i,"kbd","oac-menu__key");t.textContent=e.key,o.appendChild(t)}o.addEventListener("click",t=>{t.stopPropagation(),e.disabled||(l(),e.onSelect())}),s.appendChild(o),n++}if(0===n){const e=U(i,"div","oac-menu__empty");e.textContent="No match",s.appendChild(e)}};if(c(""),null!==r){const e=r;e.addEventListener("input",()=>c(e.value)),e.addEventListener("keydown",e=>{if("Enter"!==e.key)return;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:"below",initialFocus:r??s.querySelector('.oac-menu__row[aria-checked="true"]')??void 0}),l}function Be(e){const t=e.brandingOptions?.();if(!t||"string"!=typeof t.href||!/^https?:\/\//i.test(t.href))return null;const o="string"==typeof t.label&&""!==t.label.trim()?t.label.trim():"Chart branding";return{href:t.href,label:o}}function Ue(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=i.URL.createObjectURL(new i.Blob([o],{type:n})),r=e.createElement("a");return r.href=a,r.download=t,(e.body??e.documentElement).appendChild(r),r.click(),r.remove(),setTimeout(()=>i.URL?.revokeObjectURL(a),0),!0}function Ve(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 Ke(e,t,o){const n=e.document;t.classList.add("oac-topbar"),t.setAttribute("role","toolbar"),t.setAttribute("aria-label","Chart toolbar");const i=(e,t="")=>U(n,"button","oac-btn"+(t?" "+t:""),{type:"button","aria-label":e}),a=()=>U(n,"span","oac-sep",{role:"separator"}),r=(e,t)=>{e.classList.toggle("is-off",t),e.setAttribute("aria-disabled",String(t))},s=U(n,"div","oac-sym");s.appendChild(V(n,_("search"),"chrome"));const l=U(n,"input","oac-sym__input",{type:"text","aria-label":"Symbol",placeholder:"Symbol",autocomplete:"off",spellcheck:"false"});s.appendChild(l);const c=U(n,"span","oac-sym__ex");s.appendChild(c),t.appendChild(s),t.appendChild(a());let d=null,p=0,h=0;const u=()=>{d?.close(),d=null},g=(e,t)=>{u();const n=e.trim().toUpperCase();""!==n?(o.onSymbol(n,t),l.blur()):T()},b=()=>null===d?-1:d.rows.findIndex(e=>e.classList.contains("is-active")),f=e=>{if(null===d)return;const t=d.rows.length,o=(e%t+t)%t;d.rows.forEach((e,t)=>e.classList.toggle("is-active",t===o))},m=t=>{if(!o.search)return;const i=++h;Promise.resolve(o.search(t)).then(t=>{i===h&&n.activeElement===l&&(t=>{if(u(),0===t.length)return;const o=U(n,"div","oac-menu oac-sym__results",{role:"listbox","aria-label":"Symbols"}),i=[];t.forEach((e,t)=>{const a=U(n,"button","oac-menu__row"+(0===t?" is-active":""),{type:"button",role:"option"}),r=U(n,"span","oac-menu__label");if(r.textContent=e.exchange?`${e.exchange}:${e.symbol}`:e.symbol,a.appendChild(r),e.name){const t=U(n,"span","oac-menu__sub");t.textContent=e.name,a.appendChild(t)}a.addEventListener("click",t=>{t.stopPropagation(),g(e.symbol,e.exchange)}),i.push(a),o.appendChild(a)});const a=e.openOverlay(o,{anchor:s,placement:"below",initialFocus:null,onClose:()=>{null!==d&&d.rows===i&&(d=null)}});d={close:a,rows:i,matches:t}})(t)}).catch(()=>{u()})};l.addEventListener("input",()=>{if(!o.search)return;0!==p&&clearTimeout(p);const e=l.value.trim();""!==e?p=setTimeout(()=>{p=0,m(e)},150):u()}),l.addEventListener("keydown",e=>{const t=e;if("Enter"===t.key){t.preventDefault();const e=b();if(null!==d&&e>=0){const t=d.matches[e];return void g(t.symbol,t.exchange)}g(l.value)}else"ArrowDown"===t.key&&null!==d?(t.preventDefault(),f(b()+1)):"ArrowUp"===t.key&&null!==d?(t.preventDefault(),f(b()-1)):"Escape"===t.key&&null===d&&(T(),l.blur())}),l.addEventListener("focus",()=>{l.select()}),l.addEventListener("blur",()=>{null===d&&T()});const w=U(n,"div","oac-pills",{role:"radiogroup","aria-label":"Interval"}),v=new Map;for(const e of o.intervals){const t=U(n,"button",void 0,{type:"button",role:"radio","aria-pressed":"false","aria-label":`Interval ${e}`});t.textContent=He(e),t.dataset.interval=e,t.addEventListener("click",()=>o.onInterval(e)),w.appendChild(t),v.set(e,t)}t.appendChild(w),t.appendChild(a());const x=i("Chart type","oac-topbar__type"),y=U(n,"span");x.appendChild(y),x.appendChild((()=>{const e=U(n,"span","oac-chev",{"aria-hidden":"true"});return e.innerHTML=_("chevron-down"),e})()),x.setAttribute("aria-haspopup","menu"),x.addEventListener("click",()=>{const t=o.state().chartType;Fe(e,x,ze().map(e=>({label:Re(e),on:e===t,onSelect:()=>o.onChartType(e)})),{ariaLabel:"Chart type"})}),t.appendChild(x);let k=null;if(!1!==o.indicators){k=i("Indicators"),k.appendChild(V(n,_("plus"),"chrome"));const e=U(n,"span");e.textContent="Indicators",k.appendChild(e),k.addEventListener("click",()=>{null!==k&&k.classList.contains("is-off")||null!==k&&o.onIndicators(k)}),t.appendChild(k)}t.appendChild(U(n,"span","oac-topbar__spacer"));const C=U(n,"span","oac-topbar__branding-slot");let $=null;if(t.appendChild(C),o.onObjects){const e=i("Objects","oac-topbar__objects");e.textContent="Objects",e.setAttribute("aria-haspopup","dialog"),e.addEventListener("click",()=>{o.onObjects?.(e)}),t.appendChild(e)}const S=i("Capture chart","oac-btn--icon");S.appendChild(V(n,_("camera"),"chrome")),S.setAttribute("aria-haspopup","menu"),e.tips.attach(S,{title:"Capture",sub:"PNG, SVG, or the clipboard",side:"bottom"}),S.addEventListener("click",()=>{const t=o.state(),i=globalThis,a=void 0!==i.navigator?.clipboard?.write&&void 0!==i.ClipboardItem;Fe(e,S,[{label:"Download PNG",onSelect:()=>{e.chart.downloadScreenshot(Ve(t.symbol,t.interval)+".png"),e.status("Saved a PNG of the chart")}},{label:"Download SVG",sub:"text stays text",onSelect:()=>{const o=Ue(n,Ve(t.symbol,t.interval)+".svg",e.chart.exportSVG(),"image/svg+xml");e.status(o?"Saved an SVG of the chart":"This runtime cannot save files",o?"info":"error")}},{label:"Copy image",sub:a?"paste it anywhere":"needs https or localhost",disabled:!a,onSelect:()=>{e.chart.takeScreenshot().toBlob(t=>{if(null===t)return void e.status("The canvas produced no image","error");const o=globalThis.ClipboardItem;globalThis.navigator.clipboard.write([new o({"image/png":t})]).then(()=>e.status("Chart copied"),t=>e.status("Copy failed: "+String(t?.message??t),"error"))},"image/png")}}],{ariaLabel:"Capture"})}),t.appendChild(S);const L=i("Chart settings","oac-btn--icon");L.appendChild(V(n,_("settings"),"chrome")),e.tips.attach(L,()=>({title:"Chart settings",sub:o.settingsAvailable()?void 0:"The settings dialog is not in this build",side:"bottom"})),L.addEventListener("click",()=>{L.classList.contains("is-off")||o.onSettings(L)}),t.appendChild(L);const A=i("Theme","oac-topbar__theme"),E=U(n,"span");A.appendChild(E),e.tips.attach(A,()=>({title:"dark"===o.state().theme?"Switch to the light theme":"Switch to the dark theme",side:"bottom"})),A.addEventListener("click",()=>o.onTheme("dark"===o.state().theme?"light":"dark")),t.appendChild(A),null!==k&&e.tips.attach(k,()=>({title:"Indicators",sub:o.indicatorsAvailable()?"Add a study to the chart":"The indicator picker is not in this build",side:"bottom"}));const T=()=>{const t=o.state();n.activeElement!==l&&(l.value=t.symbol),c.textContent=t.exchange,c.hidden=""===t.exchange;for(const[e,o]of v){const n=e===t.interval;o.setAttribute("aria-pressed",String(n)),o.setAttribute("aria-checked",String(n))}y.textContent=Re(t.chartType),r(L,!o.settingsAvailable()),null!==k&&r(k,!o.indicatorsAvailable()),A.dataset.theme=t.theme,E.textContent="dark"===t.theme?"Light":"Dark",e.tips.refreshLabel(A),e.tips.refreshLabel(L),null!==k&&e.tips.refreshLabel(k);const i=Be(e.chart);null===i?($?.remove(),$=null):(null===$&&($=U(n,"a","oac-topbar__branding",{target:"_blank",rel:"noopener noreferrer"}),C.appendChild($)),$.setAttribute("href",i.href),$.textContent=i.label,$.setAttribute("aria-label",i.label))},M=e.chart.on("branding:changed",T);return T(),{el:t,refresh:T,focusSymbol:()=>{l.focus()},destroy:()=>{M(),0!==p&&clearTimeout(p),u(),t.textContent=""}}}const qe={info:4e3,success:3500,error:0},We=5,Ge=160;function Ye(e,t=e.ownerDocument){e.classList.add("oac-toasts"),e.setAttribute("role","status"),e.setAttribute("aria-live","polite");const o=new Set;return{toast:(n,i="info",a={})=>{const r=i in qe?i:"info",s=t.createElement("div");s.className="oac-toast oac-toast--"+r;const l=t.createElement("span");l.className="oac-toast__msg",l.textContent=n;const c=t.createElement("button");c.type="button",c.className="oac-toast__x",c.setAttribute("aria-label","Dismiss"),c.innerHTML=_("close"),s.appendChild(l),s.appendChild(c);const d=void 0!==a.ms?a.ms:qe[r];let p=0,h=!1;const u={node:s,dismiss:()=>{h||(h=!0,0!==p&&clearTimeout(p),o.delete(u),s.classList.add("is-out"),setTimeout(()=>s.remove(),160))}},g=()=>{d>0&&(p=setTimeout(u.dismiss,d))};for(c.addEventListener("click",u.dismiss),s.addEventListener("pointerenter",()=>{0!==p&&clearTimeout(p),p=0}),s.addEventListener("pointerleave",g),e.appendChild(s),o.add(u);o.size>5;){const e=o.values().next().value;o.delete(e),e.node.remove()}return g(),u},clear:()=>{for(const e of Array.from(o))e.dismiss()},count:()=>o.size,destroy:()=>{for(const e of Array.from(o))e.node.remove();o.clear(),e.remove()}}}const Ze="--oac-",Je=e=>e<0?0:e>1?1:e;function Xe(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 Xe("#"+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:Je(e)}}return null}const Qe=e=>Math.round(Math.max(0,Math.min(255,e))).toString(16).padStart(2,"0");function et(e){return e.a>=1?`#${Qe(e.r)}${Qe(e.g)}${Qe(e.b)}`:`rgba(${Math.round(e.r)},${Math.round(e.g)},${Math.round(e.b)},${Math.round(1e3*e.a)/1e3})`}function tt(e){const t=Xe(e);if(null===t)return.5;const o=e=>{const t=e/255;return t<=.03928?t/12.92:Math.pow((t+.055)/1.055,2.4)};return.2126*o(t.r)+.7152*o(t.g)+.0722*o(t.b)}function ot(e){return tt(e.background)<.35?"dark":"light"}function nt(e,t,o){const n=Xe(e),i=Xe(t);if(null===n||null===i)return e;const a=Je(o);return et({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 it(e,t){const o=Xe(e);return null===o?e:et({...o,a:Je(t)})}const at='ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif',rt="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",st=42,lt=40,ct=24;function dt(e,t=ot(e)){const o="dark"===t,n=e.background,i=o?"#ffffff":"#0c1120",a=e=>nt(n,i,e),r=e.lineColor,s=nt(e.axisText,i,o?.55:.6),l={bg:n,panel:a(o?.035:.02),"panel-2":a(o?.02:.045),elev:a(o?.07:.06),"elev-2":a(o?.11:.1),"elev-3":a(o?.18:.16),bd:e.axisLine,"bd-soft":e.paneSeparator,"bd-hover":nt(e.axisLine,i,.25),tx:s,"tx-strong":nt(s,i,.5),mut:e.axisText,faint:nt(e.axisText,n,.4),acc:r,"acc-2":nt(r,i,o?.2:.1),"on-bg":it(r,.16),"on-bd":nt(r,n,.45),ring:r,"ring-soft":it(r,.2),buy:e.upColor,sell:e.downColor,amber:o?"#e6b53c":"#b8860b",danger:nt(e.downColor,i,o?.3:.1),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:at,mono:rt,fs:"12.5px",radius:"7px","rail-w":"42px","topbar-h":"40px","status-h":"24px","ctl-h":"28px"},c={};for(const[e,t]of Object.entries(l))c[Ze+e]=t;return c}function pt(e,t){for(const[o,n]of Object.entries(t))e.style.setProperty(o,n)}const ht=e=>`var(${Ze}${e})`,ut="oac-widget-css",gt=e=>`var(--oac-${e})`,bt=`\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: ${gt("bg")}; color: ${gt("tx")}; font: ${gt("fs")}/1.35 ${gt("font")};\n  -webkit-font-smoothing: antialiased; overflow: hidden; }\n.oac-widget, .oac-widget * { box-sizing: border-box; }\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 ${gt("mono")}; font-variant-numeric: tabular-nums; }\n.oac-widget [hidden] { display: none !important; }\n\n/* Scrollbars: a thumb one step lighter than its panel, and no visible track. */\n.oac-widget * { scrollbar-width: thin; scrollbar-color: ${gt("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: ${gt("sb-thumb")}; border: 2px solid transparent;\n  background-clip: padding-box; border-radius: 999px; }\n.oac-widget ::-webkit-scrollbar-thumb:hover { background: ${gt("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 ${gt("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: ${gt("acc")}; box-shadow: 0 0 0 3px ${gt("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 ${gt("bd")}; border-radius: 4px; background: ${gt("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: ${gt("bd-hover")}; }\n.oac-widget input[type=checkbox]:checked { background: ${gt("acc")}; border-color: ${gt("acc")}; }\n.oac-widget input[type=checkbox]:checked::after { content: ''; width: 4px; height: 8px; margin-top: -2px;\n  border: solid ${gt("bg")}; border-width: 0 2px 2px 0; transform: rotate(45deg); }\n.oac-widget input[type=checkbox]:disabled { opacity: .4; cursor: not-allowed; }\n.oac-widget select { appearance: none; -webkit-appearance: none; height: ${gt("ctl-h")}; padding: 0 24px 0 8px;\n  background: ${gt("elev")}; border: 1px solid ${gt("bd")}; border-radius: 6px; cursor: pointer; }\n.oac-widget .oac-select { position: relative; display: inline-flex; }\n.oac-widget .oac-select > svg { position: absolute; right: 7px; top: 50%; width: 11px; height: 11px;\n  transform: translateY(-50%); pointer-events: none; color: ${gt("mut")}; fill: none; stroke: currentColor; stroke-width: 1.5; }\n.oac-widget select option, .oac-widget select optgroup { background: ${gt("panel")}; color: ${gt("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: ${gt("elev")}; border: 1px solid ${gt("bd")}; border-radius: 6px; }\n.oac-widget input[type=color]:hover { border-color: ${gt("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: ${gt("ctl-h")}; padding: 0 8px; background: ${gt("elev")}; border: 1px solid ${gt("bd")}; border-radius: 6px;\n  transition: border-color .15s, box-shadow .15s; }\n.oac-widget textarea { height: auto; padding: 6px 8px; }\n.oac-widget input::placeholder { color: ${gt("faint")}; }\n.oac-widget input:hover, .oac-widget select:hover { border-color: ${gt("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: ${gt("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: ${gt("acc")}; border: 0; }\n.oac-widget input[type=range]::-moz-range-track { height: 3px; border-radius: 2px; background: ${gt("elev-3")}; }\n.oac-widget input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: ${gt("acc")}; border: 0; }\n\n/* Section heads and rows shared by every panel. */\n.oac-widget .oac-head { padding: 8px 10px 4px; color: ${gt("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: ${gt("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 ${gt("bd")}; border-radius: 50%; color: ${gt("faint")};\n  font-size: 9px; font-weight: 600; line-height: 1; cursor: help; user-select: none; }\n.oac-widget .oac-help:hover, .oac-widget .oac-help:focus-visible {\n  color: ${gt("tx")}; border-color: ${gt("bd-hover")}; outline: none; }\n\n/* Buttons: flat, 28px tall, a tint when pressed or armed. */\n.oac-widget .oac-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px;\n  height: ${gt("ctl-h")}; padding: 0 9px; background: transparent; border: 1px solid transparent;\n  border-radius: 6px; color: ${gt("tx")}; white-space: nowrap; transition: background .1s, border-color .1s, color .1s; }\n.oac-widget .oac-btn:hover { background: ${gt("elev")}; border-color: ${gt("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: ${gt("on-bg")}; border-color: ${gt("on-bd")}; color: ${gt("acc-2")}; }\n.oac-widget .oac-btn.is-off, .oac-widget .oac-btn[aria-disabled="true"], .oac-widget .oac-btn:disabled {\n  color: ${gt("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: ${gt("ctl-h")}; padding: 0; }\n.oac-widget .oac-btn--primary { background: ${gt("acc")}; color: ${gt("bg")}; border-color: transparent; font-weight: 600; }\n.oac-widget .oac-btn--primary:hover { background: ${gt("acc-2")}; border-color: transparent; }\n.oac-widget .oac-btn--danger:not(.is-off):hover { color: ${gt("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: 24px; height: 24px; stroke-width: 2; }\n.oac-widget .oac-glyph--chrome > svg { width: 16px; height: 16px; stroke-width: 1.5; }\n.oac-widget .oac-glyph--text { display: inline-grid; place-items: center; width: 24px; height: 24px;\n  font-size: 12px; font-weight: 600; }\n.oac-widget .oac-chev { display: inline-grid; place-items: center; line-height: 0; color: ${gt("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: ${gt("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: ${gt("topbar-h")};\n  padding: 5px 8px; background: ${gt("panel")}; border-bottom: 1px solid ${gt("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: ${gt("mut")}; font-size: 11px; text-decoration: none; white-space: nowrap; }\n.oac-widget .oac-topbar__branding:hover { color: ${gt("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: ${gt("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: ${gt("mut")}; pointer-events: none; }\n.oac-widget .oac-sym__ex { margin-left: 6px; color: ${gt("faint")}; font-size: 11px; font-weight: 600; letter-spacing: .5px; }\n.oac-widget .oac-pills { display: inline-flex; background: ${gt("elev")}; border: 1px solid ${gt("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: ${gt("mut")}; font-weight: 600; font-size: 11.5px; letter-spacing: .2px; }\n.oac-widget .oac-pills > button:hover { color: ${gt("tx")}; }\n.oac-widget .oac-pills > button[aria-pressed="true"] { background: ${gt("elev-2")}; color: ${gt("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: ${gt("panel")}; border: 1px solid ${gt("bd")}; border-radius: 9px; box-shadow: ${gt("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: ${gt("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: ${gt("elev-2")}; outline: none; }\n.oac-widget .oac-menu__row[aria-checked="true"] { color: ${gt("acc-2")}; }\n.oac-widget .oac-menu__row[aria-checked="true"]::before { content: ''; width: 6px; height: 6px; border-radius: 50%;\n  background: ${gt("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: ${gt("faint")}; cursor: default; background: transparent; }\n.oac-widget .oac-menu__row.is-danger:hover { color: ${gt("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: ${gt("faint")}; font-size: 11px; }\n.oac-widget .oac-menu__key { margin-left: auto; color: ${gt("faint")}; }\n.oac-widget .oac-menu__empty { padding: 8px 10px; color: ${gt("faint")}; }\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: ${gt("panel")}; color: ${gt("tx")};\n  border: 1px solid ${gt("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: ${gt("acc-2")}; }\n\n/* Rail */\n.oac-widget .oac-rail { flex: none; width: ${gt("rail-w")}; display: flex; flex-direction: column; align-items: center;\n  gap: 2px; padding: 6px 0 0; background: ${gt("panel-2")}; border-right: 1px solid ${gt("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: 32px; padding: 0; display: grid; place-items: center;\n  flex: none; background: transparent; border: 1px solid transparent; border-radius: 7px; color: ${gt("mut")};\n  transition: background .1s, color .1s, border-color .1s; }\n.oac-widget .oac-rail__btn:hover { background: ${gt("elev")}; color: ${gt("tx")}; }\n.oac-widget .oac-rail__btn:focus-visible { outline: 2px solid ${gt("acc-2")}; outline-offset: -2px; }\n.oac-widget .oac-rail__btn.is-on { background: ${gt("on-bg")}; border-color: ${gt("on-bd")}; color: ${gt("acc-2")}; }\n.oac-widget .oac-rail__btn.is-weak { color: ${gt("acc-2")}; }\n.oac-widget .oac-rail__btn.is-off { color: ${gt("faint")}; cursor: default; }\n.oac-widget .oac-rail__btn.is-off:hover { background: transparent; color: ${gt("faint")}; }\n.oac-widget .oac-rail__btn--danger:not(.is-off):hover { color: ${gt("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: ${gt("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: ${gt("elev-2")}; color: ${gt("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: ${gt("acc-2")}; }\n.oac-widget .oac-rail__btn[data-mode="weak"]::after { border: 1.5px solid ${gt("acc-2")}; width: 4px; height: 4px; }\n.oac-widget .oac-rail__sep { width: 22px; height: 1px; background: ${gt("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: ${gt("panel-2")};\n  border-top: 1px solid ${gt("bd-soft")}; flex: none; }\n.oac-widget .oac-rail__ctl .oac-rail__sep { margin: 3px 0; }\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: ${gt("panel")}; border: 1px solid ${gt("bd")}; border-radius: 10px; box-shadow: ${gt("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: ${gt("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: ${gt("elev-2")}; }\n.oac-widget .oac-fly__row[aria-checked="true"] { background: ${gt("on-bg")}; color: ${gt("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: ${gt("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: ${gt("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: ${gt("elev")}; color: ${gt("tx")}; }\n.oac-widget .oac-fly__star:focus-visible { outline: 2px solid ${gt("acc-2")}; outline-offset: -1px; opacity: 1; }\n.oac-widget .oac-fly__star[aria-pressed="true"] { color: ${gt("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 { position: absolute; z-index: 200; left: 0; top: 0; max-width: 260px; pointer-events: none;\n  padding: 5px 9px; border-radius: 6px; background: ${gt("elev-2")}; color: ${gt("tx")}; border: 1px solid ${gt("bd")};\n  box-shadow: ${gt("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: ${gt("mut")}; }\n.oac-widget .oac-tip__sub { display: block; margin-top: 2px; color: ${gt("faint")}; font-size: 11px; }\n\n/* Status line */\n.oac-widget .oac-statusline { grid-row: 3; display: flex; align-items: center; gap: 12px; height: ${gt("status-h")}; padding: 0 10px;\n  background: ${gt("panel")}; border-top: 1px solid ${gt("bd-soft")}; color: ${gt("mut")}; font-size: 11.5px;\n  font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; }\n.oac-widget .oac-statusline__sym { color: ${gt("tx-strong")}; font-weight: 600; letter-spacing: .3px; }\n.oac-widget .oac-statusline__iv { color: ${gt("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: ${gt("faint")}; }\n.oac-widget .oac-statusline__field > b { font-weight: 500; color: ${gt("tx")}; }\n.oac-widget .oac-statusline .is-up > b { color: ${gt("buy")}; }\n.oac-widget .oac-statusline .is-down > b { color: ${gt("sell")}; }\n.oac-widget .oac-statusline__msg { margin-left: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; color: ${gt("mut")}; }\n.oac-widget .oac-statusline__msg.is-error { color: ${gt("danger")}; }\n.oac-widget .oac-statusline__tz { color: ${gt("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 > .oac-rail { 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: ${gt("panel")}; border-bottom: 1px solid ${gt("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: ${gt("panel")}; border-top: 1px solid ${gt("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 ${gt("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: ${gt("tx")}; overflow-wrap: anywhere; touch-action: manipulation; }\n.oac-widget .oac-mobile__action:hover, .oac-widget .oac-mobile__action:focus-visible { background: ${gt("elev")}; }\n.oac-widget .oac-mobile__action[aria-pressed="true"] { color: ${gt("acc-2")}; background: ${gt("on-bg")}; }\n.oac-widget .oac-mobile__action[aria-disabled="true"] { color: ${gt("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 ${gt("bd-soft")}; }\n.oac-widget .oac-mobile-sheet__title { flex: 1 1 auto; color: ${gt("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 ${gt("bd-soft")}; margin-bottom: 6px; }\n.oac-widget .oac-mobile-sheet__body small { display: block; color: ${gt("faint")}; }\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: ${gt("panel")}; border: 1px solid ${gt("bd")}; border-radius: 10px; box-shadow: ${gt("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 ${gt("bd-soft")}; }\n.oac-widget .oac-mobile-results__head > strong { flex: 1 1 auto; color: ${gt("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: ${gt("faint")}; }\n.oac-widget .oac-mobile-results__status { min-height: 44px; padding: 13px 12px; color: ${gt("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(${gt("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: ${gt("panel")}; color: ${gt("tx")}; border: 1px solid ${gt("bd")}; border-left: 3px solid ${gt("acc")};\n  box-shadow: ${gt("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: ${gt("buy")}; }\n.oac-widget .oac-toast--error { border-left-color: ${gt("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: ${gt("faint")}; padding: 0; display: grid; place-items: center; }\n.oac-widget .oac-toast__x:hover { background: ${gt("elev-2")}; color: ${gt("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.oac-widget .oac-layer > * { pointer-events: auto; }\n.oac-widget .oac-scrim { position: absolute; inset: 0; background: ${gt("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: ${gt("panel")}; border: 1px solid ${gt("bd")}; border-radius: 12px; box-shadow: ${gt("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: ${gt("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 ${gt("bd-soft")}; }\n.oac-widget .oac-dialog__foot > .oac-spacer { flex: 1 1 auto; }\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: ${gt("elev")};\n  border: 1px solid ${gt("bd-soft")}; color: ${gt("mut")}; }\n.oac-widget .oac-keys__row.is-shadowed > span, .oac-widget .oac-keys__row.is-shadowed > kbd { color: ${gt("faint")}; text-decoration: line-through; }\n.oac-widget .oac-keys__note { color: ${gt("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 ft(e,t="",o){const n=e.getElementById(ut);if(n?.textContent?.trim())return n;const i=n??e.createElement("style");return i.id=ut,i.nonce||void 0===o||(i.nonce=o),i.textContent=bt+t,null===n&&(e.head??e.body??e.documentElement).appendChild(i),i}function mt(e){const t=[];for(const o of e){const e=t.length;switch(o.type){case"colorPair":t.push({key:o.key,kind:"colorPair",label:o.label,group:o.group,pair:{enabled:void 0===o.enabled?void 0:{key:o.enabled.key},up:{key:o.up.key,label:o.up.label},down:{key:o.down.key,label:o.down.label}}});break;case"number":t.push({key:o.key,kind:"number",label:o.label,group:o.group,min:o.min,max:o.max,step:o.step});break;case"select":t.push({key:o.key,kind:"select",label:o.label,group:o.group,options:o.options});break;case"source":t.push({key:o.key,kind:"select",label:o.label,group:o.group,options:n});break;case"boolean":case"color":case"text":t.push({key:o.key,kind:o.type,label:o.label,group:o.group})}void 0!==o.tooltip&&t.length>e&&(t[e].tooltip=o.tooltip)}return t}const wt={line:"Line",fill:"Fill",text:"Text",levels:"Levels",behavior:"Behavior"};function vt(e){const t=[];for(const o of e){const e=void 0===o.group?void 0:wt[o.group]??o.group,n={key:o.path,label:o.label,group:e};switch(o.kind){case"color":t.push({...n,kind:"color"});break;case"number":t.push({...n,kind:"number",min:o.min,max:o.max,step:o.step});break;case"opacity":t.push({...n,kind:"opacity"});break;case"boolean":t.push({...n,kind:"boolean"});break;case"select":case"lineStyle":t.push(void 0===o.options?{...n,kind:"text"}:{...n,kind:"select",options:o.options});break;case"text":t.push({...n,kind:"text.value"===o.path?"multiline":"text"});break;case"levels":t.push({...n,kind:"custom",custom:"levels"})}}return t}function xt(e){if("string"!=typeof e)return null;const t=e.trim(),o=/^#([0-9a-f]{3,8})$/i.exec(t);if(null!==o){const e=o[1];return 3===e.length||4===e.length?"#"+e.slice(0,3).split("").map(e=>e+e).join("").toLowerCase():6===e.length||8===e.length?"#"+e.slice(0,6).toLowerCase():null}const n=/^rgba?\(\s*([\d.]+)(?:\s*,\s*|\s+)([\d.]+)(?:\s*,\s*|\s+)([\d.]+)/i.exec(t);if(null===n)return null;const i=e=>Math.round(Math.max(0,Math.min(255,Number(e)))).toString(16).padStart(2,"0");return`#${i(n[1])}${i(n[2])}${i(n[3])}`}function _t(e,t,o,n){const i=e.createElement(t);return void 0!==o&&""!==o&&(i.className=o),void 0!==n&&(i.textContent=n),i}function yt(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="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="${e}"/></svg>`}function kt(e,t){const o=_t(e,"span","oac-glyph oac-glyph--chrome");return o.innerHTML=_(t),o}function Ct(e,t){const o=_t(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(kt(e,t.icon));else if(void 0!==t.svg){const n=_t(e,"span","oac-glyph oac-glyph--chrome");n.innerHTML=t.svg,o.appendChild(n)}if(!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 $t(e){e.addEventListener("keydown",e=>{const t=e.key;"Escape"!==t&&"Tab"!==t&&e.stopPropagation()}),e.addEventListener("pointerdown",e=>{e.stopPropagation()})}let St=0;function Lt(e,t){const o=_t(e,"div","oac-panel"+(void 0===t.className?"":" "+t.className));o.setAttribute("role","dialog"),o.tabIndex=-1;const n="oac-dlg-title-"+ ++St;o.setAttribute("aria-labelledby",n);const i=_t(e,"div","oac-dialog__head"),a=_t(e,"span","oac-dialog__title",t.title);a.id=n;const r=Ct(e,{label:"Close",icon:"close",iconOnly:!0,onClick:()=>t.onClose()});i.appendChild(a),i.appendChild(r);const s=_t(e,"div","oac-dialog__body"),l=_t(e,"div","oac-dialog__foot"),c=_t(e,"div","oac-dialog__lead"),d=_t(e,"div","oac-spacer"),p=_t(e,"div","oac-dialog__actions");return l.appendChild(c),l.appendChild(d),l.appendChild(p),o.appendChild(i),o.appendChild(s),o.appendChild(l),$t(o),{el:o,head:i,body:s,foot:l,lead:c,actions:p,closeButton:r,setTitle:e=>{a.textContent=e}}}function At(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 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}}function Tt(e,t,o){const n=t.panes()[0]?.element.parentElement??null,i=null===n?{left:0,top:0}:Et(e,n);let a=1/0,r=-1/0;for(const e of o)for(const o of e.points){const n=t.timeToCoordinate(o.time),i=t.priceToCoordinate(o.price,e.paneIndex);Number.isFinite(n)&&null!==i&&Number.isFinite(i)&&(a=Math.min(a,n),r=Math.max(r,i))}return Number.isFinite(a)&&Number.isFinite(r)?{x:i.left+a,y:i.top+r+12}:{x:i.left+60,y:i.top+60}}function Mt(e,t,o,n,i){const a=_t(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=_t(e,"button","oac-tab");if(i.type="button",i.setAttribute("role","tab"),i.dataset.tab=o.id,void 0!==o.icon){const t=_t(e,"span","oac-glyph oac-glyph--chrome");t.innerHTML=o.icon,i.appendChild(t)}i.appendChild(_t(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 Ot(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`}function jt(e,t,o){const n=e.ownerDocument;e.innerHTML="",e.classList.add("oac-form");const i=[],a=o.unavailable??(()=>null),r=e=>`${o.idPrefix}-${e.replace(/[^A-Za-z0-9_-]/g,"-")}`,s=new Map,l=(e,t)=>{s.has(e)&&Object.is(s.get(e),t)||(s.set(e,t),o.onChange(e,t))},c=(e,t)=>{null!==t&&(e.disabled=!0,e.title=t)};function d(e,t,i,r){const d=a(e);let p,h;switch(t){case"boolean":{const t=_t(n,"input");t.type="checkbox",t.checked=!0===r,t.addEventListener("change",()=>l(e,t.checked)),p=t,h={key:e,control:t,read:()=>t.checked,write:e=>{t.checked=!0===e}};break}case"number":{const t=_t(n,"input","oac-input--num");t.type="number",void 0!==i.min&&(t.min=String(i.min)),void 0!==i.max&&(t.max=String(i.max)),void 0!==i.step&&(t.step=String(i.step));const o=e=>{var o;t.value="number"==typeof e&&Number.isFinite(e)?(o=e,Number.isInteger(o)?String(o):String(Math.round(1e3*o)/1e3)):""};o(r),t.addEventListener("change",()=>{const n=t.value.trim(),a=""===n?NaN:Number(n);if(!Number.isFinite(a))return void o(s.has(e)?s.get(e):r);const c=i.min??-1/0,d=i.max??1/0,p=Math.min(d,Math.max(c,a));p!==a&&o(p),l(e,p)}),p=t,h={key:e,control:t,read:()=>{const e=Number(t.value);return""!==t.value.trim()&&Number.isFinite(e)?e:void 0},write:o};break}case"color":{const t=_t(n,"input","oac-swatch-input");t.type="color";const i=e=>{t.value=xt(e)??"#000000"};i(r),t.addEventListener("change",()=>l(e,t.value)),!0===o.live&&t.addEventListener("input",()=>l(e,t.value)),p=t,h={key:e,control:t,read:()=>t.value,write:i};break}case"opacity":{const t=_t(n,"input","oac-range");t.type="range",t.min="0",t.max="100",t.step="1";const i=_t(n,"output","oac-out"),a=e=>Math.round(100*("number"==typeof e?Math.min(1,Math.max(0,e)):0)),s=e=>{t.value=String(a(e)),i.textContent=`${a(e)}%`};s(r),t.addEventListener("input",()=>{i.textContent=`${t.value}%`,!0===o.live&&l(e,Number(t.value)/100)}),t.addEventListener("change",()=>l(e,Number(t.value)/100));const u=_t(n,"span","oac-opacity");return u.appendChild(t),u.appendChild(i),c(t,d),p=u,h={key:e,control:t,read:()=>Number(t.value)/100,write:s},{ctl:p,b:h}}case"select":{const{wrap:t,select:o}=function(e){const t=_t(e,"span","oac-select"),o=_t(e,"select");t.appendChild(o);const n=_t(e,"span","oac-chev");return n.innerHTML=_("chevron-down"),t.appendChild(n),{wrap:t,select:o}}(n),s=i.options??[],u=t=>{o.innerHTML="";const i=s.slice(),r="string"==typeof t?t:void 0===t?void 0:String(t);void 0===r||""===r||i.some(e=>e.value===r)||i.push({value:r,label:"Custom"});for(const t of i){const i=_t(n,"option",void 0,t.label);i.value=t.value;const r=a(e,t.value);null!==r&&(i.disabled=!0,i.title=r),o.appendChild(i)}o.value=void 0===r||""===r?i[0]?.value??"":r};return u(r),o.addEventListener("change",()=>l(e,o.value)),c(o,d),p=t,h={key:e,control:o,read:()=>o.value,write:u},{ctl:p,b:h}}case"multiline":{const t=_t(n,"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",()=>l(e,t.value)),p=t,h={key:e,control:t,read:()=>t.value,write:o};break}default:{const t=_t(n,"input");t.type="text",t.setAttribute("spellcheck","false");const o=e=>{t.value=null==e?"":String(e)};o(r),t.addEventListener("change",()=>l(e,t.value)),p=t,h={key:e,control:t,read:()=>t.value,write:o};break}}return c(p,d),{ctl:p,b:h}}let p;for(const s of t){void 0!==s.group&&s.group!==p&&e.appendChild(_t(n,"div","oac-head",s.group)),p=s.group??p;const t=_t(n,"div","oac-row");t.dataset.key=s.key;const l=_t(n,"label","oac-row__label",s.label);if(void 0!==s.tooltip&&""!==s.tooltip){const e=_t(n,"span","oac-help","?");e.title=s.tooltip,e.tabIndex=0,e.setAttribute("role","note"),e.setAttribute("aria-label",s.tooltip),l.appendChild(e)}if("custom"===s.kind){const i=void 0===o.custom?null:o.custom(s,t);if(null===i)continue;t.appendChild(_t(n,"span","oac-row__sw")),t.appendChild(l);const a=_t(n,"div","oac-row__ctl");a.appendChild(i),t.appendChild(a),e.appendChild(t);continue}if("colorPair"===s.kind&&void 0!==s.pair){const c=s.pair,p=a(c.up.key),h=a(c.down.key);if(null!==p&&null!==h&&(t.classList.add("oac-row--off"),t.title=p),void 0!==c.enabled){const e=d(c.enabled.key,"boolean",s,o.values[c.enabled.key]);e.ctl.classList.add("oac-row__sw"),e.ctl.id=r(c.enabled.key),l.htmlFor=e.ctl.id,i.push(e.b),t.appendChild(e.ctl)}else t.appendChild(_t(n,"span","oac-row__sw"));t.appendChild(l);const u=_t(n,"div","oac-row__ctl");for(const e of[c.up,c.down]){const t=d(e.key,"color",s,o.values[e.key]);t.ctl.id=r(e.key),t.ctl.title=t.ctl.disabled?`${e.label}: ${t.ctl.title}`:e.label,t.ctl.setAttribute("aria-label",`${s.label} ${e.label}`),i.push(t.b),u.appendChild(t.ctl)}void 0===c.enabled&&(l.htmlFor=r(c.up.key)),t.appendChild(u),e.appendChild(t);continue}const c=d(s.key,s.kind,s,o.values[s.key]),h=a(s.key);if(null!==h&&(t.classList.add("oac-row--off"),t.title=h),c.b.control.id=r(s.key),l.htmlFor=c.b.control.id,i.push(c.b),"boolean"===s.kind)c.ctl.classList.add("oac-row__sw"),t.appendChild(c.ctl),t.appendChild(l);else if("multiline"===s.kind)t.classList.add("oac-row--block"),t.appendChild(l),t.appendChild(c.ctl);else{t.appendChild(_t(n,"span","oac-row__sw")),t.appendChild(l);const e=_t(n,"div","oac-row__ctl");e.appendChild(c.ctl),t.appendChild(e)}e.appendChild(t)}return{el:e,sync:e=>{const t=n.activeElement;for(const o of i)o.control!==t&&o.key in e&&o.write(e[o.key])},values:()=>{const e={};for(const t of i)e[t.key]=t.read();return e},focusFirst:()=>{for(const e of i)if(!e.control.disabled)return e.control.focus(),!0;return!1}}}const Pt=[0,.236,.382,.5,.618,.786,1,1.272,1.414,1.618,2,2.618,3.618,4.236],Dt=(e,t)=>e.some(e=>Math.abs(e.ratio-t)<=1e-6);function It(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&&T(t.tool).fields.some(e=>"levels"===e.kind)&&o.push(t)}return{drawings:o,schema:0===o.length?null:T(o[0].tool)}}(e,i);if(null===r)return e.toast("Select a drawing with levels first","info"),{el:n.createElement("div"),close:()=>{},isOpen:()=>!1};const s=a[0],l=function(e){try{return $(e)}catch{return null}}(s.tool),c=r.fields.find(e=>"levels"===e.kind),d=r.fields.find(e=>"style.showLabels"===e.path),p=c?.path??"style.levels",h=l?.defaultStyle?.levels??E,u="gann-fan"===(g=s.tool)?M:"fib-time-zone"===g?e=>String(e):O;var g;const b=()=>{const e=j(s,p);return Array.isArray(e)?P(e):P(h)},f=()=>{const e=j(s,"style.showLabels");return void 0===e?!0===l?.defaultStyle?.showLabels:!0===e};let m=b();function w(t){const o=[];for(const n of a){const i=e.draw.get(n.id);if(void 0===i)continue;const a=D(i,t,r);Object.keys(a).length>0&&o.push({id:n.id,patch:a})}o.length>0&&e.draw.updateMany(o)}const v=()=>w({[p]:P(m)}),x=_t(n,"div","oac-panel oac-levels");x.setAttribute("role","dialog"),x.setAttribute("aria-label","Levels"),x.tabIndex=-1,$t(x);const _=_t(n,"div","oac-levels__head");_.appendChild(_t(n,"b","oac-levels__title","Levels"));let y=null;if(void 0!==d){const e=_t(n,"label","oac-levels__labels");y=_t(n,"input"),y.type="checkbox",y.checked=f(),y.dataset.path=d.path;const t=y;t.addEventListener("change",()=>w({[d.path]:t.checked})),e.appendChild(t),e.appendChild(_t(n,"span",void 0,"Show labels")),_.appendChild(e)}_.appendChild(Ct(n,{label:"Close",icon:"close",iconOnly:!0,onClick:()=>R.close()})),x.appendChild(_);const k=_t(n,"div","oac-levels__rows");function C(){k.innerHTML="",0!==m.length?m.forEach((e,t)=>k.appendChild(function(e,t){const o=_t(n,"div","oac-levels__row"+(!1===e.enabled?" is-off":"")),i=_t(n,"input");i.type="checkbox",i.checked=!1!==e.enabled,i.setAttribute("aria-label","Enabled"),i.addEventListener("change",()=>{i.checked?delete m[t].enabled:m[t].enabled=!1,o.classList.toggle("is-off",!i.checked),v()}),o.appendChild(i);const a=_t(n,"input");a.type="number",a.step="0.001",a.value=String(e.ratio),a.setAttribute("aria-label","Ratio"),a.addEventListener("change",()=>{const e=Number(a.value);""!==a.value.trim()&&Number.isFinite(e)?(m[t].ratio=e,void 0===m[t].label&&(l.placeholder=u(e)),v()):a.value=String(m[t].ratio)}),o.appendChild(a);const r=_t(n,"input");r.type="color",r.value=xt(e.color)??xt(s.style.color)??xt(N(e.ratio))??I,r.setAttribute("aria-label","Color"),r.addEventListener("change",()=>{m[t].color=r.value,v()}),o.appendChild(r);const l=_t(n,"input");l.type="text",l.value=e.label??"",l.placeholder=u(e.ratio),l.setAttribute("aria-label","Label"),l.setAttribute("spellcheck","false"),l.addEventListener("change",()=>{const e=l.value.trim();""===e?delete m[t].label:m[t].label=e,v()}),o.appendChild(l);const c=_t(n,"button","oac-levels__x");return c.type="button",c.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="12" height="12" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" aria-hidden="true"><path d="M3 3l10 10M13 3 3 13"/></svg>',c.setAttribute("aria-label","Remove level"),c.addEventListener("click",e=>{e.stopPropagation(),m.splice(t,1),C(),v()}),o.appendChild(c),o}(e,t))):k.appendChild(_t(n,"div","oac-empty","No levels. Add one, or reset to the defaults."))}x.appendChild(k),C();const S=_t(n,"div","oac-levels__foot");S.appendChild(Ct(n,{label:"Add level",icon:"plus",onClick:()=>{const e=function(e){for(const t of Pt)if(!Dt(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}(m),t={ratio:e},o=N(e);o!==I&&(t.color=o),m.push(t),C(),v()}})),S.appendChild(_t(n,"span","oac-spacer")),S.appendChild(Ct(n,{label:"Reset",onClick:()=>{m=P(h),C(),v()}})),x.appendChild(S);const L=e.chart.on("draw:update",()=>{if(!R.isOpen())return;if(void 0===e.draw.get(s.id))return void R.close();const t=b();JSON.stringify(t)===JSON.stringify(m)||x.contains(n.activeElement)||(m=t,C()),null!==y&&y!==n.activeElement&&(y.checked=f())}),A=e.chart.on("draw:remove",()=>{R.isOpen()&&void 0===e.draw.get(s.id)&&R.close()}),R=At(e,x,void 0===t?{placement:"below",dismissOnOutside:!0}:{anchor:t,placement:"below"},()=>{});void 0===t&&Ot(e.root,x,{point:Tt(e.root,e.chart,a)});const z=R.close;return{el:x,isOpen:R.isOpen,close:()=>{L(),A(),z()}}}function Nt(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 Rt(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 zt(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 Ht(e){return e.panes()[0]?.element.parentElement??null}function Ft(e){return void 0!==e&&!0===T(e.tool).textIsContent}function Bt(e,t,o){return e.toast(t,"info"),o?.(!1),{el:e.document.createElement("div"),close:()=>{},isOpen:()=>!1,commit:()=>{},cancel:()=>{}}}function Ut(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(!Ft(l))return Bt(e,"Select a text drawing first",o.onDone);const c=(()=>{try{return $(l.tool)}catch{return null}})(),d=void 0!==c?.defaultText?.value&&""!==c.defaultText.value?c.defaultText.value:"Text",p=l.text??{value:""},h=p.fontSize??14,u=Nt(p,h),g=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,u,h),b=function(e,t,o,n="Text"){const i=t.points[0];if(void 0===i)return null;const a=e.timeToCoordinate(i.time),r=e.priceToCoordinate(i.price,t.paneIndex);if(!Number.isFinite(a)||null===r||!Number.isFinite(r))return null;const s=t.text??{value:""},l=s.fontSize??14,c=Nt(s,l),d=Rt(o,s,void 0===s.value||""===s.value?n:s.value,s.wrapWidth??220);let p=0;for(const e of d)p=Math.max(p,o(e));const h=1.35*l,u=d.length*h+10,g=s.valign??"top";return{x:a,y:"middle"===g?r-u/2:"bottom"===g?r-u:r,width:p+10,height:u,lineHeight:h,lines:d,font:c,size:l}}(i,l,g,d),f=Ht(i);if(null===b||null===f)return Bt(e,"That text is off the chart",o.onDone);const m=Et(e.root,f),w=_t(n,"div","oac-textedit");w.setAttribute("contenteditable","plaintext-only"),w.setAttribute("spellcheck","false"),w.setAttribute("role","textbox"),w.setAttribute("aria-multiline","true"),w.setAttribute("aria-label","Drawing text"),w.tabIndex=0;const v=w.style;v.left=`${Math.round(b.x+m.left)}px`,v.top=`${Math.round(b.y+m.top)}px`,v.font=u,v.lineHeight=`${b.lineHeight}px`,v.color=p.color??l.style.color??"inherit",v.textAlign=p.align??"left",v.minWidth=`${Math.ceil(b.width)}px`,v.minHeight=`${Math.ceil(b.height)}px`;const x=!0===p.wrap,_=p.wrapWidth??220;v.whiteSpace=x?"pre-wrap":"pre",x&&(v.width=`${Math.ceil(b.width)}px`);const y=p.value??"";w.textContent=y;let k=!1;const C=e=>{k||(k=!0,A.close(),o.onDone?.(e))},S=()=>{if(k)return;const e=zt(w),t=e!==y;t&&void 0!==a.get(l.id)&&a.update(l.id,{text:{...a.get(l.id)?.text??{value:""},value:e}}),C(t)},L=()=>C(!1);for(const e of["pointerdown","pointermove","pointerup","click","dblclick","contextmenu","keyup","keypress"])w.addEventListener(e,e=>{e.stopPropagation()});w.addEventListener("keydown",e=>{const t=e.key;if("Tab"!==t&&e.stopPropagation(),"Escape"===t)return e.preventDefault(),void L();"Enter"===t&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),S())}),w.addEventListener("blur",()=>S()),x&&w.addEventListener("input",()=>{const e=Rt(g,p,zt(w)||d,_);let t=0;for(const o of e)t=Math.max(t,g(o));v.width=`${Math.ceil(t+10)}px`});const A=At(e,w,{placement:"below",modal:!1,dismissOnOutside:!1,initialFocus:w},L);try{const e=n.defaultView;if(null!==e&&"function"==typeof e.getSelection&&"function"==typeof n.createRange){const t=n.createRange();t.selectNodeContents(w),t.collapse(!1);const o=e.getSelection();o?.removeAllRanges(),o?.addRange(t)}}catch{}return{el:w,isOpen:A.isOpen,close:()=>S(),commit:S,cancel:L}}function Vt(e){const t=e.map(e=>T(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 Kt={"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 qt(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=Kt[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 Wt(e){try{return $(e)}catch{return null}}const Gt=(e,t)=>e.length===t.length&&e.every((e,o)=>e===t[o]);function Yt(e,t,o={}){const{draw:n,chart:i}=e,a=e.document;void 0!==o.ids&&o.ids.length>0&&!Gt(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 e.toast("Select a drawing first","info"),{el:a.createElement("div"),close:()=>{},isOpen:()=>!1};let c=Vt(l.map(e=>e.tool)),d=Wt(l[0].tool),p=null;const h=()=>1===l.length?d?.name??l[0].tool:`${l.length} drawings`,u=()=>function(e,t,o,n){const i=qt(o,t,n);for(const[o,n]of Object.entries(R(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}(l[0],c,d,e.chartTheme.lineColor);function g(e){const t=[];for(const o of l){const i=n.get(o.id);if(void 0===i)continue;const a=D(i,e,c);Object.keys(a).length>0&&t.push({id:o.id,patch:a})}t.length>0&&n.updateMany(t)}const b=Lt(a,{title:h(),className:"oac-props",onClose:()=>C.close()}),f=_t(a,"div","oac-props__tools");f.setAttribute("role","toolbar"),f.setAttribute("aria-label","Drawing actions"),b.el.insertBefore(f,b.body);const m=_t(a,"div","oac-props__pane");function w(){f.innerHTML="";const e=l[0],t=!0===e.locked,o=!1===e.visible,i=e.zIndex<0,s=(e,t,o)=>{const n=Ct(a,{...e,iconOnly:!0});n.dataset.act=t,void 0!==o&&n.setAttribute("aria-pressed",o?"true":"false"),f.appendChild(n)},c=()=>{f.appendChild(_t(a,"span","oac-sep"))};s({label:t?"Unlock":"Lock",icon:t?"lock":"unlock",onClick:()=>{n.updateMany(r.map(e=>({id:e,patch:{locked:!t}})))}},"lock",t),s({label:o?"Show":"Hide",icon:o?"eye-off":"eye",onClick:()=>{n.updateMany(r.map(e=>({id:e,patch:{visible:o}})))}},"visible",o),c(),s({label:"Bring to front",icon:"front",onClick:()=>{for(const e of r)n.bringToFront(e)}},"front"),s({label:"Send to back",icon:"back",onClick:()=>{for(const e of r)n.sendToBack(e)}},"back"),s({label:"In front of the series",svg:yt("M3 4h10M8 14V6M5 9l3-3 3 3"),onClick:()=>{for(const e of r)n.bringAboveSeries(e)}},"above",!i),s({label:"Behind the series",svg:yt("M3 12h10M8 2v8M5 7l3 3 3-3"),onClick:()=>{for(const e of r)n.sendBehindSeries(e)}},"behind",i),c(),s({label:"Duplicate",icon:"duplicate",chord:"Ctrl+D",onClick:()=>{n.duplicate(r)}},"duplicate"),s({label:"Delete",icon:"trash",chord:"Del",variant:"danger",onClick:()=>{n.removeMany(r)}},"delete")}function v(){m.innerHTML="";const t=vt(c.fields);if(0===t.length)return m.appendChild(_t(a,"div","oac-empty","These drawings share no settings.")),void(p=null);if(p=jt(m,t,{values:u(),idPrefix:"oac-props",onChange:(e,t)=>{g({[e]:t}),p?.sync(u())},custom:t=>{if("levels"!==t.custom)return null;const o=Ct(a,{label:"Edit levels...",onClick:t=>{It(e,t.currentTarget,{ids:r})}});return o.dataset.act="edit-levels",o}}),!0===c.textIsContent&&1===l.length){const t=m.querySelector('[data-key="text.value"]');if(null!==t){const o=Ct(a,{label:"Edit on chart",icon:"text",onClick:()=>{Ut(e,0,{id:l[0].id})}});o.dataset.act="edit-text",t.appendChild(o)}}}function x(){if(!C.isOpen())return;const e=n.selection().slice();if(0!==e.length){if(Gt(e,r))return l=s(),0===l.length?void C.close():(p?.sync(u()),void w());r=e,l=s(),0!==l.length?(c=Vt(l.map(e=>e.tool)),d=Wt(l[0].tool),b.setTitle(h()),w(),v()):C.close()}else C.close()}b.body.appendChild(m),w(),v(),b.lead.appendChild(Ct(a,{label:"Restore defaults",onClick:()=>{const t={},o=qt(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]}g(t),p?.sync(u())}})),b.actions.appendChild(Ct(a,{label:"Done",variant:"primary",onClick:()=>C.close()}));const _=[i.on("draw:update",x),i.on("draw:select",x),i.on("draw:remove",x)],y=At(e,b.el,void 0===t?{placement:"below",dismissOnOutside:!0}:{anchor:t,placement:"below"},()=>{});void 0===t&&Ot(e.root,b.el,{point:Tt(e.root,i,l)});let k=!1;const C={el:b.el,isOpen:y.isOpen,close:()=>{if(!k){k=!0;for(const e of _)e();y.close(),o.onClose?.()}}};return C}function Zt(e,t,o={}){const{chart:n}=e,a=e.document,r=i(),s=Lt(a,{title:"Indicators",className:"oac-pick",onClose:()=>m.close()}),l=_t(a,"input","oac-pick__find");l.type="search",l.placeholder="Search indicators",l.setAttribute("aria-label","Search indicators"),l.setAttribute("spellcheck","false");const c=_t(a,"div","oac-pick__findwrap");c.appendChild(l);const d=_t(a,"div","oac-pick__list");d.setAttribute("role","listbox"),d.setAttribute("aria-label","Indicators"),s.body.appendChild(c),s.body.appendChild(d),s.actions.appendChild(Ct(a,{label:"Done",variant:"primary",onClick:()=>m.close()}));let p=[],h=-1;const u=e=>n.indicators().filter(t=>t.indicatorId===e).length,g=e=>{0!==p.length?(h=Math.max(0,Math.min(p.length-1,e)),p.forEach((e,t)=>{e.classList.toggle("is-active",t===h),e.setAttribute("aria-selected",t===h?"true":"false")})):h=-1},b=t=>{const i=n.addIndicator(t.id);e.toast(`Added ${i.name}`,"success"),o.onAdd?.(i),!0!==o.closeOnAdd?(f(),l.focus()):m.close()};function f(){const e=l.value;if(d.innerHTML="",p=[],0===r.length)return void d.appendChild(_t(a,"div","oac-empty","No indicators are registered. Import the indicators tier to fill this list."));const t=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))}(r,e);if(0!==t.length){for(const[e,o]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]))}(t)){d.appendChild(_t(a,"div","oac-head",e));for(const e of o){const t=_t(a,"button","oac-pick__row");t.type="button",t.setAttribute("role","option"),t.dataset.id=e.id,t.appendChild(_t(a,"span","oac-pick__name",e.name));const o=u(e.id);if(o>0){const e=_t(a,"span","oac-pick__count",1===o?"on chart":`on chart x${o}`);e.setAttribute("aria-label",1===o?"one instance on the chart":`${o} instances on the chart`),t.appendChild(e)}t.addEventListener("click",t=>{t.stopPropagation(),b(e)}),d.appendChild(t),p.push(t)}}g(h<0?0:h)}else d.appendChild(_t(a,"div","oac-empty","No match"))}l.addEventListener("input",()=>{h=0,f()}),l.addEventListener("keydown",e=>{const t=e.key;if("ArrowDown"===t)e.preventDefault(),g(h+1);else if("ArrowUp"===t)e.preventDefault(),g(h-1);else if("Enter"===t){e.preventDefault();const t=p[h],o=t?.dataset.id,n=r.find(e=>e.id===o);void 0!==n&&b(n)}}),f();const m=At(e,s.el,void 0===t?{placement:"center",modal:!0,initialFocus:l}:{anchor:t,placement:"below",initialFocus:l},()=>{});return m}function Jt(e){const t={};for(const o of e)t[o.key]=o.default;return t}function Xt(e,t){return e.toast(t,"info"),{el:e.document.createElement("div"),close:()=>{},isOpen:()=>!1}}function Qt(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 e=n.find(e=>e.id===i)??null;return null===e?{inst:null,why:"That indicator is no longer on the chart"}:{inst:e,why:null}}return 1===n.length?{inst:n[0],why:null}:{inst:null,why:0===n.length?"No indicator on the chart to configure":"Pick an indicator from the legend first"}}(e,t,o);if(null===i.inst)return Xt(e,i.why??"No indicator to configure");const l=i.inst,c=a(l.indicatorId),d=[];c.inputs.length>0&&d.push({id:"inputs",label:"Inputs",icon:_("settings"),inputs:c.inputs});const p=r(c);if(p.length>0&&d.push({id:"style",label:"Style",icon:yt("M3 13c2.5 0 3.5-1.5 4-3.5M7.5 9.5 13 4a1.4 1.4 0 0 1 2 2l-5.5 5.5"),inputs:p}),0===d.length)return Xt(e,`${l.name} has nothing to configure`);const h=l.settings(),u=new Set;let g=d.some(e=>e.id===o.tab)?o.tab:d[0].id,b=null,f=!1;const m=()=>({...s(c),...Jt(p),...l.settings()}),w=e=>{for(const t of Object.keys(e))u.add(t);l.setSettings(e),o.onChange?.(l)},v=Lt(n,{title:`${l.name} settings`,className:"oac-indset",onClose:()=>C()}),x=_t(n,"div","oac-indset__pane");if(d.length>1){const e=Mt(n,d.map(e=>({id:e.id,label:e.label,icon:e.icon})),g,"row",e=>{g=e,y()});v.body.appendChild(e.el)}function y(){const e=d.find(e=>e.id===g)??d[0];x.innerHTML="",b=jt(x,mt(e.inputs),{values:m(),idPrefix:`oac-ind-${l.id}`,live:!0,onChange:(e,t)=>{w({[e]:t}),b?.sync(m())}})}v.body.appendChild(x),y(),v.lead.appendChild(Ct(n,{label:"Defaults",onClick:()=>{const e=d.find(e=>e.id===g)??d[0];w(Jt(e.inputs)),y()}})),v.actions.appendChild(Ct(n,{label:"Cancel",onClick:()=>C()})),v.actions.appendChild(Ct(n,{label:"OK",variant:"primary",onClick:()=>$()}));const k=At(e,v.el,{placement:"center",modal:!0},()=>C());function C(){k.isOpen()&&(!function(){if(f||0===u.size)return;const e={};for(const t of u)e[t]=h[t];u.clear(),l.setSettings(e),o.onChange?.(l)}(),k.close(),o.onClose?.(!1))}function $(){k.isOpen()&&(f=!0,k.close(),o.onClose?.(!0))}return{el:v.el,isOpen:k.isOpen,close:()=>$()}}const eo={price:"M5 2v12M3 5h4v6H3zM11 2v12M9 4h4v7H9z",readout:"M2 4h8M2 8h12M2 12h9",axes:"M3 2v11h11M3 6h2M3 10h2M7 13v-2M11 13v-2",appearance:"M2 3h12v10H2zM2 8h12M7 3v10",trading:"M2 12l4-4 3 2 5-6M11 4h3v3M2 14h12"};function to(e,t,o={}){const{chart:n}=e,i=e.document,a=l(n).filter(e=>e.inputs.length>0),r=c(n),s=new Set;let p=a.some(e=>e.id===o.tab)?o.tab:a[0]?.id??"price",h=null,u=!1;const g=e=>{for(const t of Object.keys(e))s.add(t);d(n,e),o.onApply?.(e)},b=Lt(i,{title:"Chart settings",className:"oac-settings",onClose:()=>_()}),f=_t(i,"div","oac-settings__main"),m=_t(i,"div","oac-settings__pane");b.body.appendChild(f);const w=Mt(i,a.map(e=>({id:e.id,label:e.label,icon:yt(eo[e.id]??"")})),p,"rail",e=>{p=e,v()});function v(){const e=a.find(e=>e.id===p);m.innerHTML="",h=null,void 0!==e?h=jt(m,mt(e.inputs),{values:c(n),idPrefix:"oac-cset",live:!0,unavailable:o.unavailable,onChange:(e,t)=>{g({[e]:t}),h?.sync(c(n))}}):m.appendChild(_t(i,"div","oac-empty","Nothing to configure on this chart yet."))}f.appendChild(w.el),f.appendChild(m),v(),b.lead.appendChild(Ct(i,{label:"Restore this tab",onClick:()=>{const e=a.find(e=>e.id===p);void 0!==e&&(g(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}(e)),v())}})),b.actions.appendChild(Ct(i,{label:"Cancel",onClick:()=>_()})),b.actions.appendChild(Ct(i,{label:"OK",variant:"primary",onClick:()=>y()}));const x=At(e,b.el,{placement:"center",modal:!0},()=>_());function _(){x.isOpen()&&(!function(){if(u||0===s.size)return;const e={};for(const t of s){const o=r[t];void 0!==o&&(e[t]=o)}s.clear(),d(n,e),o.onApply?.(e)}(),x.close(),o.onClose?.(!1))}function y(){x.isOpen()&&(u=!0,x.close(),o.onClose?.(!0))}return{el:b.el,isOpen:x.isOpen,close:()=>y()}}const oo={kind:"separator"},no=e=>({kind:"header",label:e}),io={linear:"Linear",logarithmic:"Logarithmic",percentage:"Percent","indexed-to-100":"Indexed to 100"};function ao(e,t,o){const n=e.panes()[t];return void 0===n?String(o):n.readoutScale().format(o)}function ro(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(oo)};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:"Auto-fit to the data",mark:"check",on:a.autoFit,keepOpen:!0,run:()=>{const e=i();null!==e&&n.setPriceAxisAutoFit(t,o,!e.autoFit)}}),r.push({id:"axis-invert",label:"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:"Pin price per bar",mark:"check",on:a.lockRatio,keepOpen:!0,disabled:!a.scaled,note:a.scaled?void 0:"nothing measured",run:()=>{const a=i();null!==a&&(n.setPriceAxisLockRatio(t,o,!a.lockRatio)||e.toast("Nothing measured on this scale yet","info"))}}),r.push(oo),r.push(no("Scale"));for(const e of p)r.push({id:`axis-mode-${e}`,label:io[e],mark:"radio",on:a.mode===e,keepOpen:!0,run:()=>{n.setPriceAxisOptions(t,o,{mode:e})}});return r.push(oo),r.push({id:"axis-move",label:"right"===a.side?"Move the scale to the left":"Move the scale to the right",disabled:!a.movable,note:a.movable?void 0:a.active?"other side taken":"nothing on this side",run:()=>{const o=i();null!==o&&(n.movePriceAxis(t,o.side,"right"===o.side?"left":"right")||e.toast("That side is already in use","info"))}}),r.push(oo),r.push({id:"axis-settings",label:"Axis settings...",icon:"settings",run:()=>{to(e,0,{tab:"axes"})}}),r}(e,t.paneIndex,a.scaleId??a.side??"right")),r;const l=o.onOrder;if(void 0!==l&&"time-scale"!==a.kind){const e=t.price,o=(o,i)=>({id:`order-${o.toLowerCase()}-${i.toLowerCase()}`,label:"MARKET"===i?("BUY"===o?"Buy":"Sell")+" market":`${"BUY"===o?"Buy":"Sell"} ${"LIMIT"===i?"limit":"stop"} at ${ao(n,t.paneIndex,e)}`,run:()=>l({side:o,type:i,price:"MARKET"===i?null:e,paneIndex:t.paneIndex})});r.push(no("Trade")),r.push(o("BUY","MARKET"),o("SELL","MARKET")),null!==e&&r.push(o("BUY","LIMIT"),o("SELL","LIMIT"),o("BUY","SL"),o("SELL","SL"))}const c=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),d=null===c?void 0:i.get(c);if(void 0!==d){i.selection().includes(d.id)||i.select(d.id);const t=i.selection().includes(d.id)?i.selection().slice():[d.id];s(),r.push(...function(e,t,o){const{draw:n}=e,i=T(t.tool),a=[],r=!0===t.locked,s=!1===t.visible,l=t.zIndex<0,c=o.length>1,d=c?`${o.length} drawings`:"drawing";return a.push({id:"draw-props",label:c?"Properties of the selection...":"Properties...",icon:"settings",run:()=>{Yt(e,void 0,{ids:o})}}),!c&&Ft(t)&&a.push({id:"draw-text",label:"Edit text",icon:"text",chord:"Enter",run:()=>{Ut(e,0,{id:t.id})}}),i.fields.some(e=>"levels"===e.kind)&&a.push({id:"draw-levels",label:"Edit levels...",run:()=>{It(e,void 0,{ids:o})}}),a.push(oo),a.push({id:"draw-copy",label:`Copy ${d}`,icon:"copy",chord:"Ctrl+C",run:()=>{n.copy(o)}}),a.push({id:"draw-cut",label:`Cut ${d}`,chord:"Ctrl+X",disabled:r,note:r?"locked":void 0,run:()=>{n.cut(o)}}),a.push({id:"draw-duplicate",label:"Duplicate",icon:"duplicate",chord:"Ctrl+D",run:()=>{n.duplicate(o)}}),a.push(oo),a.push({id:"draw-lock",label:r?"Unlock":"Lock",icon:r?"lock":"unlock",mark:"check",on:r,run:()=>{n.updateMany(o.map(e=>({id:e,patch:{locked:!r}})))}}),a.push({id:"draw-hide",label:s?"Show":"Hide",icon:s?"eye-off":"eye",mark:"check",on:s,run:()=>{n.updateMany(o.map(e=>({id:e,patch:{visible:s}})))}}),a.push(oo),a.push(no("Order")),a.push({id:"draw-front",label:"Bring to front",icon:"front",run:()=>{for(const e of o)n.bringToFront(e)}}),a.push({id:"draw-back",label:"Send to back",icon:"back",run:()=>{for(const e of o)n.sendToBack(e)}}),a.push({id:"draw-above",label:"In front of the series",icon:yt("M3 4h10M8 14V6M5 9l3-3 3 3"),mark:"radio",on:!l,run:()=>{for(const e of o)n.bringAboveSeries(e)}}),a.push({id:"draw-behind",label:"Behind the series",icon:yt("M3 12h10M8 2v8M5 7l3 3 3-3"),mark:"radio",on:l,run:()=>{for(const e of o)n.sendBehindSeries(e)}}),a.push(oo),a.push({id:"draw-delete",label:c?`Delete ${d}`:"Delete",icon:"trash",chord:"Del",danger:!0,disabled:r,note:r?"locked":void 0,run:()=>{n.removeMany(o)}}),a}(e,d,t))}if("indicator"===a.kind&&void 0!==a.instanceId){const t=n.indicators().find(e=>e.id===a.instanceId);void 0!==t&&(s(),r.push({id:"ind-settings",label:`${t.name} settings...`,icon:"settings",run:()=>{Qt(e,void 0,{instanceId:t.id})}}),r.push({id:"ind-visible",label:t.visible()?`Hide ${t.name}`:`Show ${t.name}`,icon:t.visible()?"eye":"eye-off",run:()=>{t.setVisible(!t.visible())}}),r.push({id:"ind-remove",label:`Remove ${t.name}`,icon:"trash",danger:!0,run:()=>{n.removeIndicator(t.id)}}))}if("time-scale"!==a.kind){s(),r.push({id:"draw-paste",label:"Paste",icon:"paste",chord:"Ctrl+V",run:()=>{i.paste().then(t=>{0===t.length&&e.toast("Nothing to paste","info")})}});const t=i.drawings().length;t>0&&r.push({id:"draw-clear",label:`Remove all drawings (${t})`,icon:"trash",danger:!0,run:()=>{i.clear()}})}s(),r.push({id:"chart-fit",label:"Fit all bars",icon:yt("M2 8h12M4 5l-2 3 2 3M12 5l2 3-2 3"),run:()=>{n.fitContent()}}),"time-scale"!==a.kind&&r.push({id:"chart-indicators",label:"Indicators...",run:()=>{Zt(e)}}),r.push({id:"chart-settings",label:"Settings...",icon:"settings",run:()=>{to(e)}});const h=o.items?.(t)??[];return h.length>0&&(s(),r.push(...h)),r}const so=new WeakMap;function lo(e,t,o={}){const n=e.document;so.get(e.root)?.close();const i=o.event??{paneIndex:0,point:{x:0,y:0},price:null,time:null,index:null,target:{kind:"empty",id:null},preventDefault:()=>{}},a=o.hooks??{},r=_t(n,"div","oac-panel oac-ctx");r.setAttribute("role","menu"),r.setAttribute("aria-label","Chart menu"),r.tabIndex=-1,$t(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=ro(e,i,a);for(const e of l){if("separator"===e.kind){r.appendChild(_t(n,"div","oac-ctx__hr"));continue}if("header"===e.kind){r.appendChild(_t(n,"div","oac-head",e.label));continue}const o=e,i=_t(n,"button","oac-ctx__row"+(!0===o.danger?" is-danger":""));i.type="button",i.setAttribute("role","check"===o.mark?"menuitemcheckbox":"radio"===o.mark?"menuitemradio":"menuitem"),void 0!==o.mark&&i.setAttribute("aria-checked",!0===o.on?"true":"false"),void 0!==o.id&&(i.dataset.act=o.id),i.tabIndex=-1;const a=_t(n,"span","oac-ctx__mark");if("radio"===o.mark&&!0===o.on)a.appendChild(_t(n,"span","oac-ctx__dot"));else if("check"===o.mark&&!0===o.on)a.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" aria-hidden="true"><path d="M3 8.5l3.5 3.5L13 4"/></svg>';else if(void 0!==o.icon)if(o.icon.startsWith("<svg")){const e=_t(n,"span","oac-glyph oac-glyph--chrome");e.innerHTML=o.icon,a.appendChild(e)}else a.appendChild(kt(n,o.icon));i.appendChild(a),i.appendChild(_t(n,"span","oac-ctx__label",o.label)),void 0!==o.note&&""!==o.note&&i.appendChild(_t(n,"span","oac-ctx__note",o.note)),void 0!==o.chord&&i.appendChild(_t(n,"kbd","oac-ctx__key",o.chord)),!0===o.disabled?i.setAttribute("aria-disabled","true"):i.addEventListener("click",e=>{e.stopPropagation(),o.run?.(),!0===o.keepOpen?t(s.indexOf(i)):d.close()}),r.appendChild(i),s.push(i)}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=At(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=Ht(e.chart),o=null===t?{left:0,top:0}:Et(e.root,t);Ot(e.root,r,{point:{x:i.point.x+o.left,y:i.point.y+o.top}})}return so.set(e.root,d),d}function co(e,t={}){return e.chart.on("contextmenu",o=>{const n=o;n.preventDefault(),lo(e,void 0,{event:n,hooks:t})})}const po={settings:to,indicatorPicker:Zt,indicatorSettings:Qt,drawingProperties:Yt,contextMenu:lo,levelEditor:It,textEditor:Ut};ie(po);const ho=e=>`var(--oac-${e})`,uo=`\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: ${ho("panel")}; border: 1px solid ${ho("bd")}; border-radius: 12px;\n  box-shadow: ${ho("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: ${ho("bd-soft")}; }\n.oac-widget .oac-empty { padding: 10px 6px; color: ${ho("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: ${ho("mut")}; cursor: pointer; }\n.oac-widget .oac-row__ctl { display: flex; align-items: center; justify-content: flex-end; gap: 6px; width: min(164px, 48%); min-width: 0; flex: none; }\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=text] { width: 100%; min-width: 0; }\n.oac-widget .oac-row__ctl .oac-select, .oac-widget .oac-row__ctl select { width: 164px; 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: ${ho("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: ${ho("faint")}; cursor: not-allowed; }\n.oac-widget .oac-row input:disabled, .oac-widget .oac-row select:disabled { opacity: .45; pointer-events: none; }\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 ${ho("bd-soft")}; }\n.oac-widget .oac-tabs--row { overflow-x: auto; flex: none; padding: 0 0 6px; margin-bottom: 6px; border-bottom: 1px solid ${ho("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: ${ho("mut")}; text-align: left; white-space: nowrap; }\n.oac-widget .oac-tab:hover { background: ${ho("elev")}; color: ${ho("tx")}; }\n.oac-widget .oac-tab[aria-selected="true"] { background: ${ho("on-bg")}; border-color: ${ho("on-bd")}; color: ${ho("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: ${ho("tx")}; text-align: left; }\n.oac-widget .oac-pick__row:hover, .oac-widget .oac-pick__row.is-active { background: ${ho("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: ${ho("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: ${ho("tx-strong")}; }\n.oac-widget .oac-levels__labels { display: inline-flex; align-items: center; gap: 6px; color: ${ho("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: ${ho("faint")}; }\n.oac-widget .oac-levels__x:hover { background: ${ho("elev-2")}; color: ${ho("danger")}; }\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 ${ho("acc")}; border-radius: 4px; background: color-mix(in srgb, ${ho("bg")} 58%, transparent);\n  box-shadow: 0 0 0 3px ${ho("ring-soft")}; caret-color: ${ho("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: ${ho("tx")}; text-align: left; white-space: nowrap; }\n.oac-widget .oac-ctx__row:hover, .oac-widget .oac-ctx__row:focus-visible { background: ${ho("elev-2")}; outline: none; }\n.oac-widget .oac-ctx__row[aria-disabled="true"] { color: ${ho("faint")}; cursor: default; background: transparent; }\n.oac-widget .oac-ctx__row.is-danger:not([aria-disabled="true"]):hover { color: ${ho("danger")}; }\n.oac-widget .oac-ctx__row[aria-checked="true"] { color: ${ho("acc-2")}; }\n.oac-widget .oac-ctx__mark { width: 16px; height: 16px; display: inline-grid; place-items: center; flex: none; color: ${ho("mut")}; }\n.oac-widget .oac-ctx__row[aria-checked="true"] .oac-ctx__mark { color: ${ho("acc-2")}; }\n.oac-widget .oac-ctx__mark > svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 1.8;\n  stroke-linecap: round; stroke-linejoin: round; }\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: ${ho("faint")}; font-size: 11px; }\n.oac-widget .oac-ctx__key { margin-left: 8px; color: ${ho("faint")}; }\n.oac-widget .oac-ctx__hr { height: 1px; background: ${ho("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 ${ho("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`,go={source:"Source",indicator:"Indicator",drawing:"Drawing",profile:"Profile"},bo=["visibility","lock","settings","focus","remove"],fo={loading:"Loading",ready:"Ready",empty:"No data",unsupported:"Unsupported",error:"Could not load"},mo={select:"select",visibility:"change visibility for",lock:"change lock for",settings:"open settings for",focus:"focus",remove:"remove"},wo=e=>`Pane ${e.paneIndex+1}`;let vo=0;function xo(e,t,o={}){const n=o.objects??e.objects;if(void 0===n)throw new Error("Objects panel requires an object model");const i=n,a=e.document;let r=!1,s=[];const l=new Map,c=Lt(a,{title:"Objects",className:"oac-objects",onClose:()=>m.close()});c.closeButton.textContent="Close",c.closeButton.classList.remove("oac-btn--icon");const d=_t(a,"input","oac-objects__find");d.type="search",d.placeholder="Search name, type or pane",d.setAttribute("aria-label","Search objects"),d.setAttribute("spellcheck","false");const p=_t(a,"div","oac-objects__list");p.setAttribute("role","list"),p.setAttribute("aria-label","Chart objects");const h=_t(a,"div","oac-empty");h.setAttribute("role","status");const u=_t(a,"span","oac-objects__count");function g(t,o,n){if(r)return;const a=i.get(o);let s=!1;try{if(a?.capabilities[t])switch(t){case"select":s=i.select(o,!0===n?.ctrlKey||!0===n?.metaKey);break;case"visibility":s=i.setVisible(o,!a.visible);break;case"lock":s=i.setLocked(o,!a.locked);break;case"settings":s=i.openSettings(o);break;case"focus":s=i.focus(o);break;case"remove":s=i.remove(o)}}catch{}s||e.toast(`Could not ${mo[t]} ${a?.name??"object"}`,"error")}function b(){if(r)return;const e=d.value.trim().toLowerCase(),t=s.filter(t=>`${t.name} ${go[t.kind]} ${wo(t)}`.toLowerCase().includes(e)),o=new Set(t.map(e=>e.id)),n=a.activeElement,i=null!==n&&p.contains(n);for(const[e,t]of l)o.has(e)||(t.el.remove(),l.delete(e));t.forEach((e,t)=>{let o=l.get(e.id);void 0!==o&&o.selectable===e.capabilities.select||(o?.el.remove(),o=function(e){const t=_t(a,"div","oac-objects__row");t.dataset.objectId=e.id,t.setAttribute("role","listitem");const o=e.capabilities.select?Ct(a,{label:"",onClick:t=>g("select",e.id,t)}):_t(a,"div");o.classList.add("oac-objects__summary"),e.capabilities.select&&(o.dataset.action="select");const n=_t(a,"span","oac-objects__name"),i=_t(a,"span","oac-objects__meta"),r=_t(a,"span","oac-objects__status"),s="oac-object-"+ ++vo;i.id=`${s}-meta`,r.id=`${s}-status`,e.capabilities.select&&o.setAttribute("aria-describedby",`${i.id} ${r.id}`),o.append(n,i,r);const l=_t(a,"div","oac-objects__actions");return t.append(o,l),{el:t,summary:o,name:n,meta:i,status:r,actions:l,selectable:e.capabilities.select,buttons:new Map}}(e),l.set(e.id,o)),function(e,t){e.name.textContent=t.name;const o=[go[t.kind],wo(t),t.visible?"Visible":"Hidden"];void 0!==t.locked&&o.push(t.locked?"Locked":"Unlocked"),t.selected&&o.push("Selected"),e.meta.textContent=o.join(", "),e.el.classList.toggle("is-selected",t.selected),e.selectable&&(e.summary.setAttribute("aria-label",`Select ${t.name}`),e.summary.setAttribute("aria-pressed",String(t.selected))),e.status.textContent=void 0===t.dataStatus?"":fo[t.dataStatus.state],e.status.hidden=void 0===t.dataStatus,e.status.dataset.state=t.dataStatus?.state??"";let n=0;for(const o of bo){let i=e.buttons.get(o);if(!t.capabilities[o]){i?.remove(),e.buttons.delete(o);continue}void 0===i&&(i=Ct(a,{label:"",variant:"remove"===o?"danger":"ghost",onClick:()=>g(o,t.id)}),i.dataset.action=o,e.buttons.set(o,i));const r="visibility"===o?t.visible?"Hide":"Show":"lock"===o?t.locked?"Unlock":"Lock":"settings"===o?"Settings":"focus"===o?"Focus":"Remove";i.textContent=r,i.setAttribute("aria-label",`${r}${"settings"===o?" for":""} ${t.name}`),e.actions.children[n]!==i&&e.actions.insertBefore(i,e.actions.children[n]??null),n++}e.actions.hidden=0===n}(o,e),p.children[t]!==o.el&&p.insertBefore(o.el,p.children[t]??null)}),h.hidden=t.length>0,h.textContent=0===s.length?"No objects on this chart.":"No objects match your search.",u.textContent=""===e?`${s.length} objects`:`${t.length} of ${s.length} objects`,i&&(p.contains(n)?a.activeElement!==n&&n.focus():d.focus())}u.setAttribute("role","status"),c.body.append(d,p,h),c.lead.appendChild(u),c.actions.appendChild(Ct(a,{label:"Done",variant:"primary",onClick:()=>m.close()})),d.addEventListener("input",b);const f=i.subscribe(e=>{r||(s=e,b())}),m=At(e,c.el,{...void 0===t?{placement:"center",modal:!0}:{anchor:t,placement:"below"},initialFocus:d,onClose:()=>{r||(r=!0,f(),d.removeEventListener("input",b),l.clear(),s=[],o.onClose?.())}},()=>{});return m}const _o='\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__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 { 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.is-selected { border-color: var(--oac-acc); background: var(--oac-elev); }\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';let yo=0;function ko(e,t){const o=e.document,n=t.mode??"auto",i=U(o,"div","oac-mobile");e.root.appendChild(i);let a=!1,r=!1,s=!1,l=0,c=0,d=null,p=null,h=null,u=null,g=!1,b=null,f=null;const m=[],w=e=>{e.stopPropagation()};i.addEventListener("pointerdown",w);const v=(e,t,n)=>{const i=U(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},x=()=>{const e=f;f=null,e?.close()},_=()=>{0!==l&&(clearTimeout(l),l=0),c++,d=null},y=()=>{_();const e=u;u=null,p=null,h=null,b?.setAttribute("aria-expanded","false"),b?.removeAttribute("aria-controls"),null!==e&&(g=!0,e(),g=!1)},k=(t,n,i,r=void 0)=>{x();const s=U(o,"section","oac-mobile-sheet",{"aria-label":t}),l=U(o,"div","oac-mobile-sheet__head oac-dialog__head"),c=U(o,"strong","oac-mobile-sheet__title");c.textContent=t;const d=v("close","Close",()=>x());l.append(c,d);const p=U(o,"div","oac-mobile-sheet__body");s.append(l,p);const h=()=>{if(a||f?.repaint!==h)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;return null===t||void 0===o?null:{action:o,...void 0===t.dataset.tool?{}:{tool:t.dataset.tool},...void 0===t.dataset.interval?{}:{interval:t.dataset.interval},...void 0===t.dataset.chartType?{}:{chartType:t.dataset.chartType}}})(e):null,r=p.scrollTop;if(p.textContent="",i(p,x),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&&e.dataset.tool===t.tool&&e.dataset.interval===t.interval&&e.dataset.chartType===t.chartType)??null)(p,n);(e??p.querySelector("[data-mobile-action]"))?.focus()}};let u=()=>{};const g={close:()=>u(),repaint:h};f=g,i(p,x),u=e.openOverlay(s,{anchor:n,placement:"center",dismissOnOutside:!0,initialFocus:r,onClose:()=>{f===g&&(f=null)}})};let C=null;if(t.topbar){const n=U(o,"div","oac-mobile__header",{role:"toolbar","aria-label":"Chart header"});b=U(o,"input","oac-mobile__symbol",{type:"text","aria-label":"Symbol",placeholder:"Symbol",autocomplete:"off",spellcheck:"false"}),void 0!==t.search&&(b.setAttribute("aria-autocomplete","list"),b.setAttribute("aria-haspopup","listbox"),b.setAttribute("aria-expanded","false")),C=v("interval","",e=>{k("Interval",e,(e,o)=>{for(const n of t.intervals){const i=v("pick-interval",He(n),()=>{t.onInterval(n),o()});i.dataset.interval=n;const a=t.state().interval===n;i.setAttribute("aria-pressed",String(a)),e.appendChild(i)}})});const s=(e,o)=>{const n=e.trim().toUpperCase();y(),""!==n&&t.onSymbol(n,o),j(),b?.blur()},f=()=>{if(null!==p)return p;const t=U(o,"section","oac-mobile-results",{role:"region","aria-label":"Symbol search results"}),n=U(o,"div","oac-mobile-results__head"),i=U(o,"strong");i.textContent="Symbols",n.append(i,v("close-search","Close",()=>y()));const a=U(o,"div","oac-mobile-results__list",{role:"listbox"});a.id="oac-mobile-results-"+ ++yo,t.append(n,a),p=t,h=a,b?.setAttribute("aria-controls",a.id);let r=()=>{};return r=e.openOverlay(t,{anchor:b??void 0,placement:"below",initialFocus:null,dismissOnOutside:!0,onClose:()=>{p===t&&(p=null,h=null,u=null),b?.setAttribute("aria-expanded","false"),b?.removeAttribute("aria-controls"),g||_()}}),u=r,t},m=()=>{if(f(),null===h)return;h.textContent="";const e=U(o,"div","oac-mobile-results__status",{role:"status"});e.textContent="Searching",h.appendChild(e)},w=e=>{if(0!==e.length){if(f(),null!==h){h.textContent="";for(const t of e){const e=t.exchange?`${t.exchange}:${t.symbol}`:t.symbol,n=v("pick-symbol",e,()=>s(t.symbol,t.exchange));if(n.setAttribute("role","option"),t.name){const e=U(o,"small");e.textContent=t.name,n.appendChild(e)}h.appendChild(n)}}}else y()};b.addEventListener("keydown",e=>{"Enter"===e.key&&(e.preventDefault(),s(b?.value??""))}),void 0!==t.search&&(b.addEventListener("input",()=>{_();const e=b?.value.trim()??"";if(""===e)return void y();const n=++c;d=e,m(),l=setTimeout(()=>{l=0,Promise.resolve(t.search?.(e)??[]).then(t=>{const i=o.activeElement,s=i===b||null!==i&&!0===p?.contains(i);!a&&r&&n===c&&d===e&&b?.value.trim()===e&&s&&w(t)}).catch(()=>{n===c&&d===e&&y()})},150)}),b.addEventListener("blur",e=>{const t=e.relatedTarget;null!==t&&!0===p?.contains(t)||y()})),n.append(b,C),i.appendChild(n)}const $=U(o,"div","oac-mobile__footer"),S=U(o,"div","oac-mobile__selection",{role:"toolbar","aria-label":"Selected drawing"});let L=null,A=null,E=null;null!==t.rail&&(L=v("properties","Properties",e=>{t.onProperties(e)}),A=v("lock","Lock",()=>{const t=e.draw.selection(),o=!t.every(t=>!0===e.draw.get(t)?.locked);for(const n of t)e.draw.update(n,{locked:o});j()}),E=v("delete","Delete",()=>{e.draw.removeMany(e.draw.selection()),j()}),S.append(L,A,E),$.appendChild(S));const T=U(o,"nav","oac-mobile__bar",{"aria-label":"Chart controls"});let M=null,O=null;function j(){if(a)return;const n=t.state();if(null!==b&&o.activeElement!==b&&(b.value=n.symbol),null!==C&&(C.textContent=He(n.interval)),null!==M&&M.setAttribute("aria-pressed",String(null!==e.draw.activeTool())),null!==O&&O.setAttribute("aria-disabled",String(!t.indicatorsAvailable())),null!==S.parentNode){const t=e.draw.selection();if(S.hidden=0===t.length,t.length>0&&null!==A){const o=t.every(t=>!0===e.draw.get(t)?.locked);A.textContent=o?"Unlock":"Lock",A.setAttribute("aria-pressed",String(o))}null!==L&&L.setAttribute("aria-disabled",String(0===t.length)),null!==E&&E.setAttribute("aria-disabled",String(0===t.length))}f?.repaint()}null!==t.rail&&(M=v("draw","Draw",n=>{k("Drawing",n,n=>{const i=e.draw.activeTool();if(null!==i){const i=U(o,"div","oac-mobile-sheet__controls");i.append(v("finish","Finish",()=>{e.draw.finish(),j()}),v("cancel","Cancel",()=>{e.draw.cancel(),j()}),v("undo","Undo",()=>{e.draw.undo(),j()}),v("magnet",`Magnet: ${t.rail?.magnetMode()??"off"}`,()=>{t.rail?.cycleMagnet(),j()}),v("stay","Stay: "+(t.rail?.stayMode()?"on":"off"),()=>{null!==t.rail&&t.rail.setStayMode(!t.rail.stayMode()),j()})),n.appendChild(i)}const a=void 0===t.tools?null:new Set(t.tools);for(const t of z()){if(null!==a&&!a.has(t.id))continue;const o=v("tool",t.name,()=>{e.draw.setTool(t.id),x()});o.classList.add("oac-mobile__tool"),o.dataset.tool=t.id,o.setAttribute("aria-pressed",String(i===t.id)),n.appendChild(o)}})}),T.appendChild(M)),t.topbar&&t.indicators&&(O=v("studies","Studies",e=>{t.onIndicators(e)}),T.appendChild(O)),t.topbar&&(T.appendChild(v("objects","Objects",e=>{t.onObjects(e)})),T.appendChild(v("more","More",n=>{k("More",n,(i,a)=>{const r=v("theme","dark"===t.state().theme?"Light theme":"Dark theme",()=>{t.onTheme(),a()});i.appendChild(r);const s=v("settings","Chart settings",()=>{a(),t.onSettings(n)});s.setAttribute("aria-disabled",String(!t.settingsAvailable())),i.appendChild(s);const l=Be(e.chart);if(null!==l){const e=U(o,"a","oac-mobile__action oac-mobile__branding",{href:l.href,target:"_blank",rel:"noopener noreferrer","aria-label":l.label});e.dataset.mobileAction="branding",e.textContent=l.label,i.appendChild(e)}const c=U(o,"div","oac-head");c.textContent="Chart type",i.appendChild(c);for(const e of ze()){const o=v("chart-type",Re(e),()=>{t.onChartType(e),a()});o.dataset.chartType=e,o.setAttribute("aria-pressed",String(t.state().chartType===e)),i.appendChild(o)}})}))),T.children.length>0&&$.appendChild(T),$.children.length>0&&i.appendChild($);const P="auto"===n?o.defaultView?.matchMedia?.("(pointer: coarse)")??null:null,D=()=>{const o="always"===n||"auto"===n&&((t.container.getBoundingClientRect().width||t.container.clientWidth)<=640||!0===P?.matches);s&&o===r||(s=!0,r=o,e.root.classList.toggle("is-mobile",r),e.root.dataset.mobile=String(r),i.hidden=!r,r||(x(),y()))},I=o.defaultView?.ResizeObserver;let N=null;if("auto"===n&&void 0!==I)N=new I(D),N.observe(t.container);else if("auto"===n){const e=o.defaultView;null!==e&&"function"==typeof e.addEventListener&&(e.addEventListener("resize",D),m.push(()=>e.removeEventListener("resize",D)))}null!==P&&("function"==typeof P.addEventListener?(P.addEventListener("change",D),m.push(()=>P.removeEventListener("change",D))):(P.addListener(D),m.push(()=>P.removeListener(D))));for(const t of["draw:tool","draw:select","drawing:select","drawing:change","draw:add","draw:remove","draw:update"])m.push(e.chart.on(t,j));return m.push(e.bus.on("symbol",j)),m.push(e.bus.on("interval",j)),m.push(e.bus.on("theme",j)),m.push(e.chart.on("branding:changed",j)),D(),j(),{el:i,active:()=>r,refresh:j,destroy:()=>{if(!a){a=!0,y(),x(),N?.disconnect(),N=null;for(const e of m.splice(0))e();i.removeEventListener("pointerdown",w),i.remove(),e.root.classList.remove("is-mobile"),delete e.root.dataset.mobile}}}}const Co=["1m","5m","15m","1h","1d","1w"],$o=500,So=250,Lo="state",Ao=1,Eo=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),To=["feed","symbol","exchange","interval","intervals","chartType","theme","rail","topbar","statusline","mobile","loading","persist","storage","locale","indicators","symbolSearch","lookbackBars","now","onOrder","styleNonce"];function Mo(e){const t={...e};return delete t.viewport,delete t.barSpacing,Array.isArray(t.panes)&&(t.panes=t.panes.map(e=>{if(!Eo(e)||!Eo(e.priceScale))return e;const t={...e.priceScale,autoScale:!0};return delete t.range,{...e,priceScale:t}})),t}function Oo(e){return"light"===e?{theme:u,name:"light"}:"dark"===e||void 0===e?{theme:g,name:"dark"}:{theme:e,name:ot(e)}}function jo(e,t,o){const n=h(e),i=null!==n&&"interval"===n.bucketing.mode?n.bucketing.seconds:null;return{from:o-(null===i?15768e4:Math.max(1,Math.round(t))*i),to:o}}class Po{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,"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,"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,"_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.root=t.root,this.document=t.document,this.keymap=t.keymap,this.bus=t.bus,this.storage=t.storage,this.locale=t.locale,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}get theme(){return this._source.theme()}get chartTheme(){return this._source.chartThemeInUse()}}class Do{constructor(e,o){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,"objects",{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,"_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 X}),Object.defineProperty(this,"_storage",{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,"_objectsPanel",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_intervals",{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,"_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,"_chartType",{enumerable:!0,configurable:!0,writable:!0,value:void 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,"_destroyed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_cleanups",{enumerable:!0,configurable:!0,writable:!0,value:[]}),this._opts=o,this.dataController=o.feed?new b(o.feed,{now:()=>Math.floor((o.now??Date.now)()/1e3),...o.loading}):null;const n=o.document??e.ownerDocument;this._doc=n,ft(n,uo+_o,o.styleNonce);const i="string"==typeof o.persist?o.persist:"default",a=o.persist?void 0===o.storage?te():o.storage:null;this._storage=new ee(i,a);const r=this._readSaved();this._symbol=(o.symbol??r?.symbol??"").toUpperCase(),this._exchange=o.exchange??r?.exchange??"",void 0!==o.interval&&f(o.interval);for(const e of o.intervals??[])f(e);const s=null!==r&&m(r.interval)?r.interval:"1d";this._interval=o.interval??s;const l=o.chartType??r?.chartType??"candlestick";if(void 0!==o.chartType&&!t().includes(o.chartType))throw new Error(`openalgo-charts widget: "${o.chartType}" is not a registered chart type`);this._chartType=t().includes(l)?l:"candlestick";const c=Oo(o.theme??r?.theme);this._themeName=c.name,this._chartTheme=c.theme;const d=new Set(o.intervals??[...Co,...w().map(e=>e.code)]);d.add(this._interval),this._intervals=Array.from(d);const p=U(n,"div","oac-widget");p.dataset.theme=this._themeName,pt(p,dt(this._chartTheme,this._themeName)),this.root=p;const h=U(n,"div","oac-topbar");!1===o.topbar&&(h.hidden=!0),p.appendChild(h);const u=U(n,"div","oac-stage");p.appendChild(u);const g=U(n,"div","oac-rail");!1===o.rail&&(g.hidden=!0),u.appendChild(g);const _=U(n,"div","oac-chart");this._chartEl=_,u.appendChild(_);const y=U(n,"div","oac-statusline");!1===o.statusline&&(y.hidden=!0),p.appendChild(y);const k=U(n,"div","oac-toasts");p.appendChild(k),e.appendChild(p);const C={...o};for(const e of To)delete C[e];const $=!0===n.defaultView?.matchMedia?.("(prefers-reduced-motion: reduce)").matches;$&&void 0===C.animZoom&&(C.animZoom=!1),$&&void 0===C.animAutoscale&&(C.animAutoscale=!1),this.chart=v(_,{...C,theme:this._chartTheme,document:n}),_.setAttribute("aria-label",o.ariaLabel??"Price chart"),this._series=this.chart.addSeries(this._chartType),this.chart.setDataContext({symbol:this._symbol,exchange:this._exchange,interval:this._interval}),this.draw=new H(this.chart,{}),this.objects=new x(this.chart,{drawings:this.draw,onSettings:e=>{"source"===e.kind?this.openSettings():"indicator"===e.kind?Qt(this.context,void 0,{instanceId:e.sourceId}):"drawing"===e.kind&&Yt(this.context,void 0,{ids:[e.sourceId]})}});const S=le(p,n),L=de(p,S.layer,n);this._toasts=Ye(k,n);const A=this.chart.shortcuts;if(this._keymap=new _e({chart:null===A?null:{list:()=>A.list()},scopes:()=>this._scopes()}),this._keymap.onConflict(e=>this._bus.emit("keymap:conflict",{combo:e.combo,kept:e.kept,shadowed:e.shadowed})),this.context=new Po(this,{chart:this.chart,draw:this.draw,objects:this.objects,root:p,document:n,keymap:this._keymap,bus:this._bus,storage:this._storage,locale:o.locale,toast:(e,t)=>this._toasts.toast(e,t),openOverlay:(e,t)=>S.open(e,t),status:(e,t="info")=>{this._statusline?.setMessage(e,t),this._bus.emit("status",{text:e,kind:t})},tips:L,overlays:S,symbol:()=>({symbol:this._symbol,exchange:this._exchange}),interval:()=>this._interval}),this._cleanups.push(()=>{L.destroy(),S.destroy()}),this._dataStatus=function(e,t,o,n){const i=U(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 e=a.request?.symbol??"",i=a.request?.interval??"";switch(a.status){case"loading":t.push({text:`Loading ${e} ${i}`});break;case"refreshing":t.push({text:`Refreshing ${e} ${i}`});break;case"empty":t.push({text:`No bars for ${e} ${i}`,label:"Retry chart data",retry:n});break;case"stale":t.push({text:`History is stale for ${e} ${i}`,label:"Retry chart data",retry:n});break;case"error":t.push({text:`Could not load ${e} ${i}`,label:"Retry chart data",retry:n})}"limited"===a.historyStatus?t.push({text:"History retention limit reached"}):"loading"===a.historyStatus?t.push({text:"Loading older history"}):"error"===a.historyStatus&&t.push({text:"Could not load older history",label:"Retry older history",retry:()=>{o?.loadMore()}})}for(const o of e.chart.indicators()){const e=o.dataStatus();if(null===e||"ready"===e.state)continue;const n={loading:"Loading",empty:"No data",unsupported:"Unsupported",error:"Could not load"}[e.state];t.push({text:`${o.name}: ${n}`,label:`Retry ${o.name}`,retry:"loading"===e.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=U(e.document,"div","oac-data-status__row"),n=U(e.document,"span","oac-data-status__text");if(n.textContent=o.text,t.appendChild(n),o.retry){const n=U(e.document,"button","oac-btn");n.textContent="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)},p=["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 p)e();for(const e of["pointerdown","wheel","keydown"])i.removeEventListener(e,l);i.remove()}}}(this.context,u,this.dataController,()=>{this.reload()}),this._cleanups.push(co(this.context,{onOrder:o.onOrder})),!1!==o.rail){const e={..."object"==typeof o.rail?o.rail:{},cursorTarget:_};this._rail=Me(this.context,g,e)}if(!1!==o.statusline&&(this._statusline=De(this.context,y,{locale:o.locale}),this._statusline.setSymbol(this._symbol,this._exchange,this._interval)),!1!==o.topbar&&(this._topbar=Ke(this.context,h,{intervals:this._intervals,indicators:o.indicators,search:o.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),settingsAvailable:()=>null!==re("settings"),indicatorsAvailable:()=>null!==re("indicatorPicker")})),this._mobile=ko(this.context,{mode:o.mobile,container:e,intervals:this._intervals,topbar:!1!==o.topbar,rail:this._rail,tools:"object"==typeof o.rail?o.rail.tools:void 0,indicators:!1!==o.indicators,search:o.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),onProperties:e=>this._openDialog("drawingProperties",e),settingsAvailable:()=>null!==re("settings"),indicatorsAvailable:()=>null!==re("indicatorPicker")}),this._installKeys(),this._keymap.attach(n),this._trackPointer(),this._followChart(),void 0!==r?.chart){const e=r.symbol===this._symbol&&r.exchange===this._exchange&&r.interval===this._interval,t=this.chart.restoreState(e?r.chart:Mo(r.chart));t.applied?(this._keepView=e,this._pendingView=e?r.chart.viewport??null:null,this.draw.fromJSON(void 0===r.chart.drawings?[]:r.chart.drawings)):this._toasts.toast(`The saved layout could not be restored: ${t.reason??"unknown reason"}`,"error")}if(r?.rail&&null!==this._rail&&this._rail.restorePrefs(r.rail),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.reload()}}get series(){return this._series}get isDestroyed(){return this._destroyed}symbol(){return this._symbol}exchange(){return this._exchange}interval(){return this._interval}chartType(){return this._chartType}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._keepView=!1,this._pendingView=null,null===this.dataController&&(this._series.setData([]),this.chart.setDataContext({symbol:this._symbol,exchange:this._exchange,interval:this._interval})),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(f(t),t===this._interval)return this._topbar?.refresh(),void this._mobile?.refresh();this._interval=t,this._keepView=!1,this._pendingView=null,null===this.dataController&&(this._series.setData([]),this.chart.setDataContext({symbol:this._symbol,exchange:this._exchange,interval:this._interval})),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})}setChartType(e){if(!t().includes(e))throw new Error(`openalgo-charts widget: "${e}" is not a registered chart type`);if(e===this._chartType)return;const o=this._series.getData();this._series.remove(),this._series=this.chart.addSeries(e),o.length>0&&this._series.setData(o),this._chartType=e,this._topbar?.refresh(),this._mobile?.refresh(),this._statusline?.refresh(),this._scheduleSave(),this._bus.emit("layout",{reason:"chartType",chartType:e})}setTheme(e){const t=Oo(e);this._themeName=t.name,this._chartTheme=t.theme,this.chart.setTheme(t.theme),this.root.dataset.theme=t.name,pt(this.root,dt(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()}_openObjects(e){return!this._destroyed&&(this._objectsPanel?.isOpen()?(this._objectsPanel.el.focus(),!0):(this._objectsPanel=xo(this.context,e,{onClose:()=>{this._objectsPanel=null}}),!0))}_openDialog(e,t){const o=re(e);return null!==o&&(o(this.context,t),!0)}async reload(){const e=this.dataController;if(null===e||this._destroyed)return;const t=e.getState().request;if(t?.symbol===this._symbol&&t.exchange===this._exchange&&t.interval===this._interval)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,...jo(this._interval,this._opts.lookbackBars??500,o)};this._initialView=!0,this._displayedBars=null,this._series.setData([]),this.chart.setDataContext({symbol:this._symbol,exchange:this._exchange,interval:this._interval}),await e.load(n)}_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=t[Math.max(0,Math.min(t.length-1,Math.round(o.from)))],i=void 0===n?-1:t.findIndex(e=>e.time===n.time),a=e.bars[e.bars.length-1];if("live"!==e.reason||void 0===a||t[0]?.time!==e.bars[0]?.time||t.length!==e.bars.length&&t.length+1!==e.bars.length){if(this._series.setData(e.bars),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=void 0===n?-1:e.bars.findIndex(e=>e.time===n.time),a=t<0||i<0?0:t-i;this.chart.setVisibleLogicalRange({from:o.from+a,to:o.to+a})}}else this._series.update(a);this._displayedBars=e.bars,this._statusline?.refresh()}(t?.status!==e.status||t.error!==e.error||["load","refresh","prepend","resume"].includes(e.reason))&&("loading"===e.status?this.context.status(`Loading ${o} ${n}`):"refreshing"===e.status?this.context.status(`History is stale. Refreshing ${o} ${n}`):"error"===e.status||"stale"===e.status?(this.context.status("stale"===e.status?`History is stale for ${o} ${n}. Reload to retry.`:`Could not load ${o} ${n}`,"error"),e.error&&e.error!==t?.error&&(this._toasts.toast(`Could not load ${o} ${n}: ${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?`No bars for ${o} ${n}`:`${e.bars.length} bars`),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,chart:this.chart.getState(),rail:this._rail?.prefs()??null}}restoreState(e){if(!Eo(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`};"dark"!==e.theme&&"light"!==e.theme||this.setTheme(e.theme),"string"==typeof e.chartType&&t().includes(e.chartType)&&this.setChartType(e.chartType),void 0!==e.rail&&null!==this._rail&&this._rail.restorePrefs(e.rail);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&&m(e.interval)?e.interval:this._interval,a=o===this._symbol&&n===this._exchange&&i===this._interval;let r;if(Eo(e.chart)){const t=e.chart;if(r=this.chart.restoreState(a?t:Mo(t)),!r.applied)return{applied:!1,reason:r.reason,chart:r};this.draw.fromJSON(void 0===t.drawings?[]:t.drawings),this._keepView=a,this._pendingView=a?t.viewport??null:null}return a||(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})),this._statusline?.setSymbol(this._symbol,this._exchange,this._interval),this._topbar?.refresh(),this._mobile?.refresh(),this._opts.feed?this.reload():(this._series.setData([]),this.chart.setDataContext({symbol:this._symbol,exchange:this._exchange,interval:this._interval}))),this._rail?.refresh(),this._statusline?.refresh(),this._bus.emit("layout",{reason:"restore",chartType:this._chartType}),this._scheduleSave(),void 0===r?{applied:!0}:{applied:!0,chart:r}}_readSaved(){const e=this._storage.get(Lo);if(!Eo(e)||1!==e.version)return null;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",chart:Eo(e.chart)?e.chart:void 0,rail:Eo(e.rail)?e.rail:null}}_scheduleSave(){this._storage.enabled&&!this._destroyed&&(0!==this._saveTimer&&clearTimeout(this._saveTimer),this._saveTimer=setTimeout(()=>{this._saveTimer=0,this._saveNow()},250))}_saveNow(){this._storage.enabled&&!this._destroyed&&(0!==this._saveTimer&&(clearTimeout(this._saveTimer),this._saveTimer=0),this._storage.set(Lo,this.getState()))}_scopes(){if(this.context.overlays.size()>0)return["overlay"];const e=[],t=this._doc.activeElement;return null!==t&&this._dataStatus.el.contains(t)?[]:(null!==this._rail&&null!==t&&this._rail.el.contains(t)&&e.push("rail"),(this._pointerInChart||null!==t&&this._chartEl.contains(t))&&e.push("chart"),(this._pointerInside||null!==t&&this.root.contains(t))&&e.push("widget"),e.push("global"),e)}_installKeys(){const e=this._keymap,t=this.draw,o=()=>{const e=t.selection();if(e.length>0)return e.slice();const o=t.hovered();return null===o?[]:[o]},n=e=>{const n=F(e,{hasSelection:null!==t.selected(),hasTarget:null!==t.hovered(),editingText:!1,placing:null!==t.activeTool()});if(null===n)return!1;switch(n.type){case"undo":t.undo();break;case"redo":t.redo();break;case"delete":t.removeMany(o());break;case"duplicate":t.duplicate(o());break;case"nudge":t.nudge(o(),n.dx,n.dy);break;case"cancel":t.cancel(),null===t.activeTool()&&this._rail?.setDrawLock(!1);break;case"finish":t.finish();break;case"popAnchor":t.popAnchor();break;case"copy":t.copy(o());break;case"cut":t.cut(o());break;case"paste":t.paste()}return this._rail?.refresh(),!0},i="Drawing",a=(t,o,a=!1,r=!1)=>{e.register(t,n,"widget",{label:o,group:i,hidden:a,layered:r})};a("Mod+Z","Undo"),a("Mod+Shift+Z","Redo"),a("Mod+Y","Redo",!0),a("Mod+C","Copy the selected drawing"),a("Mod+X","Cut the selected drawing"),a("Mod+V","Paste drawings"),a("Mod+D","Duplicate the selected drawing"),a("Delete","Delete the selected drawing"),a("Backspace","Delete, or drop the last anchor while placing"),a("Enter","Finish the drawing being placed"),a("ArrowLeft","Nudge the selection left (Shift: ten pixels)",!1,!0),a("ArrowRight","Nudge the selection right (Shift: ten pixels)",!1,!0),a("ArrowUp","Nudge the selection up (Shift: ten pixels)",!1,!0),a("ArrowDown","Nudge the selection down (Shift: ten pixels)",!1,!0);for(const e of["Shift+ArrowLeft","Shift+ArrowRight","Shift+ArrowUp","Shift+ArrowDown"])a(e,"Nudge ten pixels",!0,!0);e.register("Escape",e=>null!==t.activeTool()?(n(e)||(t.setTool(null),this._rail?.setDrawLock(!1)),!0):t.selection().length>0&&(t.select(null),this._rail?.refresh(),!0),"widget",{label:"Leave the tool, then clear the selection",group:i});for(const[o,n]of Object.entries(A()))e.register(n,()=>{this._rail?.setDrawLock(!1),t.setTool(o)},"widget",{label:$e(o),group:"Drawing tools"});e.register("?",()=>{ye(this.context)},"widget",{label:"Keyboard shortcuts",group:"Widget"})}_trackPointer(){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)})}_followChart(){const e=["paneAdded","paneResized","paneMoved","paneMaximized","paneRemoved","indicatorRemoved","indicatorSettings","priceAxisMoved","objects:change"];for(const t of e)this._cleanups.push(this.chart.on(t,()=>{this._bus.emit("layout",{reason:t}),this._scheduleSave()}));for(const e of["draw:add","draw:remove","draw:update","draw:paste","draw:cut"])this._cleanups.push(this.chart.on(e,()=>this._scheduleSave()));const t=this._doc.defaultView;if(null!=t&&"function"==typeof t.addEventListener){const e=()=>this._saveNow();t.addEventListener("pagehide",e),this._cleanups.push(()=>t.removeEventListener("pagehide",e))}}destroy(){if(!this._destroyed){this._saveNow(),this._destroyed=!0,this.dataController?.destroy(),this._dataStatus.destroy(),this._mobile?.destroy(),this._mobile=null,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.objects.destroy(),this.draw.destroy(),this.chart.destroy(),this.root.remove(),this._bus.clear()}}}function Io(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 Do(o,t)}const No="widget";export{Ne as CHART_TYPE_LABELS,Co as DEFAULT_INTERVALS,$o as DEFAULT_LOOKBACK_BARS,uo as DIALOG_CSS,_e as Keymap,ke as MAGNET_MODES,Oe as MIN_PRICE_DIGITS,_o as OBJECTS_PANEL_CSS,Ce as RAIL_GROUPS,Se as RAIL_PREFS_KEY,st as RAIL_WIDTH,So as SAVE_DEBOUNCE_MS,Ie as SEARCH_DEBOUNCE_MS,Lo as STATE_KEY,ct as STATUSLINE_HEIGHT,Q as STORAGE_PREFIX,ce as TIP_DWELL_MS,Ge as TOAST_LEAVE_MS,We as TOAST_MAX,qe as TOAST_MS,Ze as TOKEN_PREFIX,lt as TOPBAR_HEIGHT,bt as WIDGET_CSS,po as WIDGET_DIALOGS,at as WIDGET_FONT,rt as WIDGET_MONO,Ao as WIDGET_STATE_VERSION,ut as WIDGET_STYLE_ID,No as WIDGET_TIER,X as WidgetBus,ee as WidgetStorage,pt as applyTokens,co as attachContextMenu,J as boxIn,Ve as captureName,ze as chartTypeChoices,Re as chartTypeLabel,ro as contextMenuEntries,vt as controlsFromFields,mt as controlsFromInputs,le as createOverlayStack,de as createTipController,Io as createWidget,te as defaultStorage,Ue as downloadText,B as esc,fe as eventKeyCombo,q as focusable,W as focusables,et as formatColor,ve as formatKeyCombo,xe as fromChartCombo,V as glyph,U as h,K as inTextField,ft as injectWidgetStyles,He as intervalLabel,jo as loadWindow,tt as luminance,nt as mix,lo as mountContextMenu,Yt as mountDrawingProperties,Zt as mountIndicatorPicker,Qt as mountIndicatorSettings,It as mountLevelEditor,ko as mountMobile,xo as mountObjectsPanel,Me as mountRail,to as mountSettingsDialog,De as mountStatusline,Ut as mountTextEditor,Ye as mountToasts,Ke as mountTopbar,Fe as openMenu,ye as openShortcutsPanel,Xe as parseColor,be as parseKeyCombo,Y as placeBelow,G as placeBeside,Z as placeTip,je as priceDigits,ne as registerWidgetDialog,ie as registerWidgetDialogs,se as registeredWidgetDialogs,jt as renderForm,Oo as resolveTheme,Te as sanitizeRailPrefs,Mo as stripView,ot as themeMode,ht as token,Ae as toolGlyph,$e as toolName,ae as unregisterWidgetDialog,re as widgetDialog,dt as widgetTokens,it as withAlpha};
//# sourceMappingURL=openalgo-charts.widget.mjs.map