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.

2 lines • 598 kB
if("undefined"==typeof OpenAlgoCharts||!OpenAlgoCharts.draw)throw new Error("openalgo-charts.widget.standalone.js needs openalgo-charts.standalone.js and openalgo-charts.draw.standalone.js loaded before it");this.OpenAlgoCharts=this.OpenAlgoCharts||{},this.OpenAlgoCharts.widget=function(e,t,o){"use strict";const n={seconds:"s",minutes:"m",hours:"h",days:"D",weeks:"W",months:"M",quarters:"Q",years:"Y"};function a(e,t){if(!Number.isInteger(e)||e<1||e>1e5||!Object.prototype.hasOwnProperty.call(n,t))throw new Error("Enter a whole number between 1 and 100000");const o=n[t];return i(`${1===e&&/^[DWMQY]$/.test(o)?"":e}${o}`,!0)}function i(e,o=!1){const n=e.trim(),a=/^(\d*)([smhDWMQY])$/.exec(n);if(o&&(!a||""===a[1]&&/[smh]/.test(a[2])))throw new Error("Use a positive clock or calendar interval");if(a){const e=""===a[1]?1:Number(a[1]);if(!Number.isInteger(e)||e<1||e>1e5)throw new Error("Interval is out of range");if(!t.tryResolveInterval(n)&&/^[MQY]$/.test(a[2])){const o="M"===a[2]?"month":"Q"===a[2]?"quarter":"year";t.registerInterval({code:n,bucketing:{mode:"calendar",unit:o,count:e}})}}const i=t.resolveInterval(n);if("interval"===i.bucketing.mode&&(!Number.isSafeInteger(i.bucketing.seconds)||i.bucketing.seconds<=0))throw new Error("Unknown interval");return n}function r(e){if("string"==typeof e&&/^(\d*)([MQY])$/.test(e))try{i(e,!0)}catch{}}function s(e){const o=t.intervalParts(e);return o&&"other"!==o.unit?`${o.unit}:${o.multiplier}`:e}function l(e,t){if(!Array.isArray(e)||e.length>128)throw new Error("Invalid timeframe preferences");const o=new Set,n=[];for(const a of e){if("string"!=typeof a||a.length>40)throw new Error("Invalid timeframe code");const e=i(a,t),r=s(e);o.has(r)||(o.add(r),n.push(e))}return n}function c(e){let t=l([...e.defaults],!1),o=[],n=!1,a=!1;const r=new Set,c=()=>{try{const n=JSON.parse(e.storage?.getItem(e.key)??"null");if(n&&"object"==typeof n&&"version"in n&&1===n.version&&"custom"in n&&"favorites"in n){const e=l(n.custom,!0),a=l(n.favorites,!1);o=e,t=a}}catch{}};c();const d=()=>{if(!n){a=!0;try{e.storage?.setItem(e.key,JSON.stringify({version:1,favorites:t,custom:o}))}catch{}for(const e of r)e()}};return{favorites:()=>[...t],custom:()=>[...o],toggle(e){if(n)return;const o=i(e),a=s(o),r=t.some(e=>s(e)===a);if(!r&&t.length>=128)throw new Error("Too many favorite intervals");t=r?t.filter(e=>s(e)!==a):[...t,o],d()},addCustom(e){if(n)return;const t=i(e,!0),a=s(t);if(!o.some(e=>s(e)===a)){if(o.length>=128)throw new Error("Too many custom intervals");o.push(t),d()}},removeCustom(e){if(n)return;const a=s(e);o.some(e=>s(e)===a)&&(o=o.filter(e=>s(e)!==a),t=t.filter(e=>s(e)!==a),d())},subscribe:e=>(n||r.add(e),()=>{r.delete(e)}),reload(){if(!n&&!a){c();for(const e of r)e()}},destroy(){n=!0,r.clear()}}}function d(e,t){return c({defaults:t,key:"timeframes",storage:{getItem:t=>{const o=e.get(t);return null===o?null:JSON.stringify(o)},setItem:(t,o)=>{e.set(t,JSON.parse(o))},removeItem:t=>e.remove(t)}})}function u(e,t,o,n){const a=e.createElement(t);if(o&&(a.className=o),n)for(const[e,t]of Object.entries(n))a.setAttribute(e,t);return a}function p(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 h(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 m(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 g=e=>Array.from(e.querySelectorAll("*")).filter(m);function f(e,t,o,n=6,a=8){let i=e.right+n,r="right";i+t.width>o.width-a&&e.left-n-t.width>=a&&(i=e.left-n-t.width,r="left"),i=Math.max(a,Math.min(i,o.width-t.width-a));return{left:i,top:Math.max(a,Math.min(e.top,o.height-t.height-a)),side:r}}function b(e,t,o,n=4,a=8){let i=e.bottom+n;return i+t.height>o.height-a&&e.top-n-t.height>=a&&(i=e.top-n-t.height),{left:Math.max(a,Math.min(e.left,o.width-t.width-a)),top:Math.max(a,Math.min(i,o.height-t.height-a))}}function v(e,t,o,n="right",a=8,i=6){let r,s;if("right"===n||"left"===n){const l="right"===n;r=l?e.right+a:e.left-a-t.width,(l?r+t.width>o.width-i:r<i)&&(r=l?e.left-a-t.width:e.right+a),s=e.top+e.height/2-t.height/2}else{const l="top"!==n;s=l?e.bottom+a:e.top-a-t.height,(l?s+t.height>o.height-i:s<i)&&(s=l?e.top-a-t.height:e.bottom+a),r=e.left+e.width/2-t.width/2}return{left:Math.max(i,Math.min(r,o.width-t.width-i)),top:Math.max(i,Math.min(s,o.height-t.height-i))}}function w(e,t){const o=e.getBoundingClientRect(),n=t.getBoundingClientRect();return{left:n.left-o.left,top:n.top-o.top,right:n.right-o.left,bottom:n.bottom-o.top,width:n.width,height:n.height}}function y(e){return"object"==typeof e&&null!==e&&!Array.isArray(e)}const _="oac-widget:";class x{constructor(e,t,o={}){Object.defineProperty(this,"_store",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_async",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_ns",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_journalKey",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_onError",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_mirror",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_pending",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_sending",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_refused",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_loading",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_loaded",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_memoryOnly",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_drain",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_queued",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_journaled",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_heard",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_unsubscribe",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_closed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),this._ns=_+e+":",this._journalKey="oac-widget-journal:"+e;const n=null!==t&&"function"==typeof t.entries;this._store=n?null:t,this._async=n?t:null,this._loaded=!n,this._onError=o.onError}key(e){return this._ns+e}get(e){if(null!==this._async){const t=this._mirror.get(this.key(e));try{return void 0===t?null:JSON.parse(t)}catch{return null}}if(null===this._store)return null;try{const t=this._store.getItem(this.key(e));return null===t?null:JSON.parse(t)}catch{return null}}set(e,t){if(null!==this._async){let o;try{o=JSON.stringify(t)}catch{return!1}return this._queue(this.key(e),o??null),!0}if(null===this._store)return!1;try{return this._store.setItem(this.key(e),JSON.stringify(t)),!0}catch{return!1}}remove(e){if(null===this._async){if(null!==this._store)try{this._store.removeItem(this.key(e))}catch{}}else this._queue(this.key(e),null)}get enabled(){return null!==this._store||null!==this._async}get loaded(){return this._loaded}load(){return null===this._loading&&(this._loading=null===this._async?Promise.resolve():this._read(this._async)),this._loading}close(){this._closed=!0;const e=this._unsubscribe;this._unsubscribe=null;try{e?.()}catch{}}async flush(){if(null!==this._async){this._writeJournal(this._async.journal),this._requeue();do{await this._send()}while(this._pending.size>0&&!this._memoryOnly)}}_queue(e,t){null===t?this._mirror.delete(e):this._mirror.set(e,t),this._refused.delete(e),this._pending.set(e,t),this._queued||(this._queued=!0,queueMicrotask(()=>{this._queued=!1,this._send()}))}_requeue(){for(const[e,t]of this._refused)this._pending.has(e)||this._pending.set(e,t);this._refused.clear()}async _read(e){if(!this._closed&&"function"==typeof e.subscribe)try{this._unsubscribe=e.subscribe((e,t)=>this._hear(e,t))}catch{}let t=[];try{t=await(o=Promise.resolve().then(()=>e.entries(this._ns)),n=4e3,new Promise((e,t)=>{const a=setTimeout(()=>t(new Error(`no answer within ${n} ms`)),n);o.then(t=>{clearTimeout(a),e(t)},e=>{clearTimeout(a),t(e)})}))}catch(e){this._memoryOnly=!0,this._report("load",this._ns,e)}var o,n;if(!this._memoryOnly){const o=k(e.journal,this._journalKey,this._ns);if(null!==o){this._journaled=!0;for(const[e,t]of o)this._pending.has(e)||(null===t?this._mirror.delete(e):this._mirror.set(e,t),this._pending.set(e,t))}for(const e of Array.isArray(t)?t:[]){const[t,o]=e;"string"==typeof t&&t.startsWith(this._ns)&&"string"==typeof o&&!this._pending.has(t)&&this._mirror.set(t,o)}for(const[e,t]of this._heard)this._pending.has(e)||(null===t?this._mirror.delete(e):this._mirror.set(e,t))}this._heard.clear(),this._loaded=!0,!this._memoryOnly&&(this._pending.size>0||this._journaled)&&this._send()}_send(){const e=this._async;if(null!==this._drain||null===e)return this._drain??Promise.resolve();const t=(async()=>{for(await this.load();this._pending.size>0&&!this._memoryOnly;){const t=[...this._pending];this._pending.clear();for(const[e,o]of t)this._sending.set(e,o);(await Promise.allSettled(t.map(([t,o])=>Promise.resolve().then(()=>null===o?e.removeItem(t):e.setItem(t,o))))).forEach((e,o)=>{const[n,a]=t[o];this._sending.delete(n),"fulfilled"!==e.status&&(this._pending.has(n)||this._refused.set(n,a),this._report(null===a?"remove":"write",n,e.reason))})}if(this._journaled&&!this._memoryOnly&&0===this._pending.size&&0===this._sending.size&&0===this._refused.size){this._journaled=!1;try{e.journal?.removeItem(this._journalKey)}catch{}}})();return this._drain=t,t.finally(()=>{this._drain=null,this._pending.size>0&&!this._memoryOnly&&this._send()}),t}_hear(e,t){this._closed||this._memoryOnly||"string"!=typeof e||!e.startsWith(this._ns)||null!==t&&"string"!=typeof t||this._pending.has(e)||this._sending.has(e)||this._refused.has(e)||(this._loaded?null===t?this._mirror.delete(e):this._mirror.set(e,t):this._heard.set(e,t))}_writeJournal(e){if(null==e||this._memoryOnly)return;const t={};let o=!1;const n=this._loaded?[]:k(e,this._journalKey,this._ns)??[];for(const e of[n,this._refused,this._sending,this._pending])for(const[n,a]of e)t[n]=a,o=!0;if(o)try{e.setItem(this._journalKey,JSON.stringify({version:1,entries:t})),this._journaled=!0}catch{}}_report(e,t,o){try{this._onError?.({operation:e,key:t,error:o})}catch{}}}function k(e,t,o){if(null==e)return null;let n;try{n=e.getItem(t)}catch{return null}if(null===n)return null;try{const e=JSON.parse(n);return y(e)&&1===e.version&&y(e.entries)?Object.entries(e.entries).filter(e=>e[0].startsWith(o)&&("string"==typeof e[1]||null===e[1])):[]}catch{return[]}}function C(){try{const e=globalThis;return void 0!==e.localStorage&&"function"==typeof e.localStorage.getItem?e.localStorage:null}catch{return null}}function S(e,t){const o=u(t,"div","oac-layer");e.appendChild(o);const n=[],a=()=>[...n].reverse().find(e=>0===e.suspended),i=e=>{if(e.closed)return;e.closed=!0;const o=n.indexOf(e);o>=0&&n.splice(o,1);const a=t.activeElement,i=null!==a&&e.el.contains(a);e.el.remove(),e.scrim?.remove(),e.opts.anchor?.setAttribute("aria-expanded","false");const r=null===a||a===t.body||i;!1!==e.opts.restoreFocus&&r&&null!==e.restore&&e.restore.isConnected&&e.restore.focus(),e.opts.onClose?.(),0===n.length&&c()},r=e=>{const o=a();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 n=g(o.el);if(0===n.length)return void e.preventDefault();const r=n.indexOf(t.activeElement);let s=null;e.shiftKey?r<=0&&(s=n.length-1):(-1===r||r>=n.length-1)&&(s=0),null!==s&&(e.preventDefault(),n[s].focus())},s=e=>{const t=e.target;for(let e=n.length-1;e>=0;e--){const o=n[e];if(!(void 0===o||o.suspended>0)){if(null!==t&&(o.el.contains(t)||!0===o.opts.anchor?.contains(t)))break;if(!1===o.opts.dismissOnOutside||!0===o.opts.modal&&!0!==o.opts.dismissOnOutside)break;i(o)}}};let l=!1;const c=()=>{l&&(l=!1,t.removeEventListener("keydown",r,!0),t.removeEventListener("pointerdown",s,!0))};return{open:(a,c={})=>{const d=c.placement??(c.anchor?"below":"center"),p=c.modal??"center"===d,h=t.activeElement,m=null===h||h===t.body||a.contains(h)?c.anchor??null:h;let v=null;const y={el:a,opts:{...c,modal:p},scrim:null,restore:m,closed:!1,suspended:0};if(p&&(v=u(t,"div","oac-scrim"),!0===c.dismissOnOutside&&v.addEventListener("pointerdown",()=>i(y)),o.appendChild(v),y.scrim=v),a.addEventListener("pointerdown",e=>e.stopPropagation()),"center"===d?(a.classList.add("oac-dialog"),a.hasAttribute("role")||a.setAttribute("role","dialog"),a.setAttribute("aria-modal","true")):a.classList.add("oac-pop"),a.hasAttribute("tabindex")||(a.tabIndex=-1),o.appendChild(a),"center"!==d&&c.anchor){const t=e.getBoundingClientRect();let o=w(e,c.anchor);if("beside"===d&&c.edge){const t=w(e,c.edge),n=Math.max(o.right,t.right);o={...o,right:n,width:n-o.left}}const n={width:a.offsetWidth,height:a.offsetHeight},i="beside"===d?f(o,n,t):b(o,n,t);a.style.left=i.left+"px",a.style.top=i.top+"px",c.anchor.setAttribute("aria-expanded","true")}if(n.push(y),l||(l=!0,t.addEventListener("keydown",r,!0),t.addEventListener("pointerdown",s,!0)),null!==c.initialFocus){(c.initialFocus??function(e){const t=g(e);return t.find(e=>null===e.closest(".oac-dialog__head"))??t[0]??null}(a)??a).focus()}return()=>i(y)},suspend:e=>{const o=n.find(t=>t.el===e);if(!o||o.closed)return()=>{};0===o.suspended&&(o.suspension={hidden:o.el.hidden,scrimHidden:o.scrim?.hidden??!1,focus:t.activeElement}),o.suspended++,o.el.hidden=!0,o.scrim&&(o.scrim.hidden=!0);let a=!1;return()=>{if(a)return;if(a=!0,o.suspended--,o.closed||o.suspended>0)return;const e=o.suspension;o.suspension=void 0,o.el.hidden=e.hidden,o.scrim&&(o.scrim.hidden=e.scrimHidden),!e.hidden&&e.focus?.isConnected&&o.el.contains(e.focus)&&e.focus.focus()}},closeTop:()=>{const e=a();return void 0!==e&&(i(e),!0)},closeAll:()=>{for(const e of n.slice().reverse())i(e)},top:()=>a()?.el??null,size:()=>n.length,layer:o,destroy:()=>{for(const e of n.slice().reverse())i(e);c(),o.remove()}}}function A(e,t,o){const n=new WeakMap;let a=null,i=0,r=null;const s=e=>"function"==typeof e?e():e,l=()=>{0!==i&&clearTimeout(i),i=0,r=null,a?.classList.remove("is-on")},c=i=>{const c=n.get(i);if(void 0===c||!i.isConnected)return;const d=s(c);if(null===d||!d.title)return void l();if("function"==typeof c&&i.setAttribute("aria-label",d.label??d.title),null===a&&(a=u(o,"div","oac-tip",{role:"presentation"})),a.parentNode!==t&&t.appendChild(a),r=i,a.textContent="",a.appendChild(o.createTextNode(d.title)),d.chord){const e=u(o,"kbd","oac-tip__chord");e.textContent=d.chord,a.appendChild(e)}if(d.sub){const e=u(o,"span","oac-tip__sub");e.textContent=d.sub,a.appendChild(e)}const p=e.getBoundingClientRect(),h=v(w(e,i),{width:a.offsetWidth,height:a.offsetHeight},p,d.side??"right");a.style.left=h.left+"px",a.style.top=h.top+"px",a.classList.add("is-on")};return{attach:(e,t,o=0)=>{n.set(e,t);const a=s(t);null!==a&&a.title&&!e.getAttribute("aria-label")&&e.setAttribute("aria-label",a.label??a.title),e.removeAttribute("title");const r=()=>{0!==i&&clearTimeout(i),o>0?i=setTimeout(()=>c(e),o):c(e)};e.addEventListener("pointerenter",r),e.addEventListener("focus",r),e.addEventListener("pointerleave",l),e.addEventListener("blur",l),e.addEventListener("pointerdown",l),e.addEventListener("keydown",l)},refreshLabel:e=>{const t=n.get(e);if("function"!=typeof t)return;const o=t();null!==o&&o.title&&e.setAttribute("aria-label",o.label??o.title)},show:c,hide:l,target:()=>r,destroy:()=>{l(),a?.remove(),a=null}}}function T(e,t){return t.filter(t=>!1!==e.get(t)?.policy?.editable)}function E(e){return o.hasDrawingTool(e)?o.getDrawingTool(e):null}function L(e,t){const o=e.history;return void 0===o||o.isDestroyed?"undo"===t?e.draw.undo():e.draw.redo():"undo"===t?o.undo():o.redo()}function O(e,t,o){void 0!==e.history?e.history.transact(o,t):o()}function I(e,t){const o=e.history;return void 0===o||o.isDestroyed?"undo"===t?e.draw.canUndo():e.draw.canRedo():"undo"===t?o.canUndo():o.canRedo()}class P{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 $=new Map;function j(e,t){return $.set(e,t),()=>{$.get(e)===t&&$.delete(e)}}function D(e){const t=Object.entries(e).map(([e,t])=>j(e,t));return()=>{for(const e of t)e()}}function M(e){return $.get(e)??null}const z=Object.freeze({}),N=/\{([A-Za-z][A-Za-z0-9_]*)\}/g;function R(e,t,o=z,n=t){let a=n;if(void 0!==e.translate)try{const i=e.translate(t,n,Object.freeze({...o}));if("string"==typeof i&&""!==i.trim()){const e=new Set(Array.from(n.matchAll(N),e=>e[1])),t=new Set(Array.from(i.matchAll(N),e=>e[1]));e.size===t.size&&[...e].every(e=>t.has(e))&&(a=i)}}catch{}return a.replace(N,(e,t)=>Object.prototype.hasOwnProperty.call(o,t)?String(o[t]):e)}function F(e,t){const o="string"==typeof t?t:t?.message;return"string"==typeof o&&""!==o.trim()?o:R(e,"unknown error")}const W={tick:"Ticks",s:"Seconds",m:"Minutes",h:"Hours",D:"Days",W:"Weeks",M:"Months",other:"Other intervals"},B=["tick","s","m","h","D","W","M","other"];function U(e,o){const n=t.intervalParts(o);if(!n||"other"===n.unit)return o;const a=W[n.unit].toLowerCase();return R(e,`schema.timeframe.${n.unit}.${1===n.multiplier?"one":"many"}`,{count:n.multiplier},`${n.multiplier} ${1===n.multiplier?a.slice(0,-1):a}`)}function q(e,t,n){const a=u(e.document,"button","oac-btn",{type:"button","aria-label":t,title:t});return n?a.appendChild(p(e.document,o.chromeIconSvg(n),"chrome")):a.textContent=t,a}function K(e,t,n){const i=u(e.document,"div","oac-dialog oac-timeframe-dialog",{role:"dialog","aria-label":R(e,"Add custom interval")}),r=u(e.document,"div","oac-timeframe-dialog__header"),s=u(e.document,"h3");s.textContent=R(e,"Add custom interval");const l=q(e,R(e,"Close"),"close");r.append(s,l),i.appendChild(r);const c=u(e.document,"div","oac-timeframe-dialog__fields"),d=u(e.document,"label"),h=u(e.document,"label");d.textContent=R(e,"Type"),h.textContent=R(e,"Interval");const m=u(e.document,"select","oac-input",{name:"unit","aria-label":R(e,"Type")});for(const t of["seconds","minutes","hours","days","weeks","months","quarters","years"]){const o=u(e.document,"option",void 0,{value:t});o.textContent=R(e,`schema.timeframe.unit.${t}`,{},t),m.appendChild(o)}m.value="minutes";const g=u(e.document,"input","oac-input",{name:"quantity",type:"number",min:"1",max:"100000",step:"1",inputmode:"numeric","aria-label":R(e,"Interval")}),f=u(e.document,"span","oac-timeframe-dialog__unit");f.append(m,p(e.document,o.chromeIconSvg("chevron-down"),"chrome")),d.appendChild(f),h.appendChild(g),c.append(d,h),i.appendChild(c);const b=u(e.document,"div","oac-timeframe-dialog__error",{role:"status"});i.appendChild(b);const v=u(e.document,"div","oac-timeframe-dialog__footer"),w=q(e,R(e,"Cancel")),y=q(e,R(e,"Add"));y.dataset.confirmInterval="",y.classList.add("oac-btn--primary"),v.append(w,y),i.appendChild(v);let _="",x=()=>{};const k=()=>{try{if(_=a(Number(g.value),m.value),n.canSelect&&!n.canSelect(_))throw new Error(R(e,"The current source cannot build this interval"));y.disabled=!1,b.textContent=""}catch(e){_="",y.disabled=!0,b.textContent=g.value?String(e.message):""}},C=()=>{if(k(),_)try{n.preferences.addCustom(_),x(),n.onSelect(_)}catch(e){b.textContent=String(e.message)}};return g.addEventListener("input",k),m.addEventListener("change",k),y.addEventListener("click",C),g.addEventListener("keydown",e=>{"Enter"===e.key&&(e.preventDefault(),C())}),l.addEventListener("click",()=>x()),w.addEventListener("click",()=>x()),k(),x=e.openOverlay(i,{anchor:t,placement:"center",initialFocus:g}),x}function G(e,n,a){const i=u(e.document,"div","oac-menu oac-timeframe-menu",{role:"dialog","aria-label":R(e,"Timeframes")}),r=q(e,R(e,"Add custom interval"));r.dataset.addInterval="",r.prepend(p(e.document,o.chromeIconSvg("plus"),"chrome")),i.appendChild(r);const l=u(e.document,"div","oac-timeframe-menu__body");i.appendChild(l);const c=new Set;let d=()=>{},h=()=>{};r.addEventListener("click",()=>{d(),K(e,n,a)});const m=()=>{const n=e.document.activeElement,i=n?.dataset.favorite??n?.dataset.removeInterval,r=void 0!==n?.dataset.removeInterval,h=n?.dataset.intervalGroup;l.textContent="";const g=new Map;for(const e of[a.current(),...a.preferences.custom(),...a.preferences.favorites(),...a.intervals]){const t=s(e);g.has(t)||g.set(t,e)}const f=[...g.values()],b=new Set(a.preferences.favorites().map(s)),v=new Set(a.preferences.custom().map(s));for(const n of B){const i=f.filter(e=>(t.intervalParts(e)?.unit??"other")===n);if(!i.length)continue;const r=u(e.document,"div","oac-timeframe-menu__group"),h=q(e,R(e,W[n]));if(h.dataset.intervalGroup=n,h.classList.add("oac-timeframe-menu__heading"),h.setAttribute("aria-expanded",String(!c.has(n))),h.appendChild(p(e.document,o.chromeIconSvg(c.has(n)?"chevron-down":"chevron-up"),"chrome")),h.addEventListener("click",()=>{c.delete(n)||c.add(n),m()}),r.appendChild(h),l.appendChild(r),!c.has(n))for(const o of i.sort((e,o)=>(t.intervalParts(e)?.multiplier??0)-(t.intervalParts(o)?.multiplier??0))){const t=s(o),n=u(e.document,"div","oac-timeframe-menu__row");n.dataset.selected=String(a.current()===o);const i=q(e,U(e,o));i.dataset.pickInterval=o,i.dataset.interval=o,i.classList.add("oac-timeframe-menu__pick"),i.setAttribute("aria-pressed",String(a.current()===o)),i.disabled=!1===a.canSelect?.(o),i.disabled&&(i.title=R(e,"The current source cannot build this interval")),i.addEventListener("click",()=>{i.disabled||(d(),a.onSelect(o))});const l=q(e,R(e,"Remove {code}",{code:o}),"trash");l.dataset.removeInterval=o,l.hidden=!v.has(t),l.addEventListener("click",()=>a.preferences.removeCustom(o));const c=q(e,R(e,b.has(t)?"Remove {code} from favorites":"Add {code} to favorites",{code:o}),b.has(t)?"star-filled":"star");c.dataset.favorite=o,c.setAttribute("aria-pressed",String(b.has(t))),c.addEventListener("click",()=>a.preferences.toggle(o));const p=u(e.document,"div","oac-timeframe-menu__actions");p.append(l,c),n.append(i,p),r.appendChild(n)}}h&&Array.from(l.querySelectorAll("[data-interval-group]")).find(e=>e.dataset.intervalGroup===h)?.focus(),i&&Array.from(l.querySelectorAll("button")).find(e=>(r?e.dataset.removeInterval:e.dataset.favorite)===i)?.focus()};m(),h=a.preferences.subscribe(m),i.addEventListener("keydown",t=>{const o=t.key;if("ArrowDown"!==o&&"ArrowUp"!==o)return;const n=Array.from(i.querySelectorAll("button")).filter(e=>!e.hidden&&!e.disabled),a=n.indexOf(e.document.activeElement),r="ArrowDown"===o?1:-1;n[(a+r+n.length)%n.length]?.focus(),t.preventDefault(),t.stopPropagation()});const g=Array.from(l.querySelectorAll("[data-pick-interval]")).find(e=>e.dataset.pickInterval===a.current()),f=e.openOverlay(i,{anchor:n,placement:"below",initialFocus:g??r,onClose:()=>h()});return d=()=>{h(),f()},d}function V(e){let t=null;const o={now:null,load:()=>t??(t=e().then(e=>o.now=e,e=>{throw t=null,e}))};return o}function H(e,t,o,n,a){if(null!==e.now)return void t(e.now);let i=()=>!!n()||null;if(void 0!==a){const{slot:e,doc:t,from:o}=a,r=e.waiting={},s=t.activeElement;let l=!1;const c=e=>{!0!==o?.contains(e.target)&&(l=!0)},d=e=>{"Escape"===e.key&&(l=!0)};t.addEventListener("pointerdown",c,!0),t.addEventListener("keydown",d,!0),i=()=>{if(t.removeEventListener("pointerdown",c,!0),t.removeEventListener("keydown",d,!0),e.waiting!==r)return null;if(e.waiting=null,!n())return null;const o=t.activeElement;return!(l||o!==s&&h(o))}}e.load().then(e=>{!0===i()&&t(e)},e=>{null!==i()&&o(e)})}function J(e,t,o){return R(e,"{name} could not load: {error}",{name:t,error:F(e,o)})}const Z="openalgo-charts-widget",Y=V(()=>Promise.resolve().then(function(){return yl}));function Q(e,t){let o=null,n=!1;const a=new Map,i=t=>{if(null!==o)return o;const i=o=e(t);for(const e of a.keys())a.set(e,i.subscribe?.(e));return n&&i.close?.(),i},r=()=>o??(null===Y.now?null:i(Y.now)),s=e=>{const t=r();return null!==t?e(t):Y.load().then(t=>e(i(t)))};return null===r()&&Y.load().then(i,()=>{}),{journal:t,entries:e=>s(t=>t.entries(e)),setItem:(e,t)=>s(o=>o.setItem(e,t)),removeItem:e=>s(t=>t.removeItem(e)),subscribe:e=>(a.set(e,r()?.subscribe?.(e)),()=>{a.get(e)?.(),a.delete(e)}),close(){n=!0,o?.close?.()}}}let X=null;function ee(){let e;try{e=globalThis.indexedDB??void 0}catch{e=void 0}if(void 0===e||"function"!=typeof e.open)return C();const t=e;return null!==X&&X.factory===t||(X={factory:t,store:Q(e=>e.openPageDefault(t),C())}),X.store}function te(e,t){if(Object.is(e,t))return!0;if("number"==typeof e&&"number"==typeof t)return Math.abs(e-t)<1e-9;if(Array.isArray(e)||Array.isArray(t))return Array.isArray(e)&&Array.isArray(t)&&e.length===t.length&&e.every((e,o)=>te(e,t[o]));if(!y(e)||!y(t))return!1;const o=new Set([...Object.keys(e),...Object.keys(t)]);for(const n of o)if(!te(e[n],t[n]))return!1;return!0}const oe=e=>y(e)&&"indicator"===e.kind&&"string"==typeof e.instanceId;function ne(e,t){const o={};for(const[n,a]of Object.entries(e))o[n]=oe(a)?{...a,instanceId:t(a.instanceId)}:Array.isArray(a)?a.map(e=>y(e)?{...e}:e):y(a)?{...a}:a;return o}function ae(e,t){const o=e.seriesType(t),n=e.seriesTransform(t);return null===o||null===n?o:`${o}+${n.type}`}const ie=["mode","inverted","marginTop","marginBottom"],re=new Set(["scales.mode","scales.inverted","scales.autoScale"]),se=["objects:change","indicatorRemoved","paneAdded","paneRemoved","paneMoved","paneCollapsed","paneResized","priceAxisMoved","priceAxisPlacementChanged","layout:change"];function le(e,t,o){const n={type:!1,scale:!1,settings:[],defaults:[],studies:new Map,kinds:new Set,order:!1,paneOrder:!1,panes:new Map,born:[],gone:[]};if(e.type!==t.type&&(n.type=!0,n.kinds.add("chart-type")),e.scale!==t.scale&&(n.scale=!0,n.kinds.add("series-scale")),e.settings&&t.settings)for(const o of new Set([...Object.keys(e.settings),...Object.keys(t.settings)]))!re.has(o)&&o in e.settings&&o in t.settings&&!te(e.settings[o],t.settings[o])&&n.settings.push(o);n.defaults=ie.filter(o=>!te(e.defaults[o],t.defaults[o])),(n.settings.length||n.defaults.length)&&n.kinds.add("settings");const a=new Map(e.studies.map(e=>[e.id,e])),i=new Map(t.studies.map(e=>[e.id,e])),r={presence:!0,keys:[],visible:!0,scale:!0,pane:!0};for(const[e,t]of a){if(void 0!==o&&!o.present(e))continue;const a=i.get(e),s=o?.policy(e)??{};if(void 0===a){!1!==s.removable&&(n.studies.set(e,r),n.kinds.add("study-remove"));continue}const l=!1===s.configurable?[]:[...new Set([...Object.keys(t.settings),...Object.keys(a.settings)])].filter(e=>!te(t.settings[e],a.settings[e])),c={presence:!1,keys:l,visible:t.visible!==a.visible,scale:!1!==s.configurable&&(t.scale!==a.scale||!te(t.plots,a.plots)),pane:!1!==s.movable&&t.pane!==a.pane};l.length&&n.kinds.add("study-settings"),c.visible&&n.kinds.add("study-visibility"),c.scale&&n.kinds.add("study-scale"),c.pane&&n.kinds.add("study-pane"),(l.length||c.visible||c.scale||c.pane)&&n.studies.set(e,c)}for(const e of i.keys())a.has(e)||(void 0===o||!o.present(e)&&o.returns(e))&&(n.studies.set(e,r),n.kinds.add("study-add"));const s=(e,t)=>e.studies.filter(e=>e.pane===t&&a.has(e.id)&&i.has(e.id)).map(e=>e.id);for(const a of new Set(t.studies.map(e=>e.pane)))te(s(e,a),s(t,a))||void 0!==o&&!o.order(t,a)||(n.order=!0);n.order&&n.kinds.add("study-order");const l=new Map(e.panes.map(e=>[e.key,e])),c=new Set(t.panes.map(e=>e.key)),d=(e,t)=>t.studies.some(t=>t.pane===e.key&&n.studies.has(t.id)),u=(e,t)=>d(e,t)||0===e.series&&!0!==e.host;n.gone=e.panes.filter(t=>!c.has(t.key)&&u(t,e)).map(e=>e.key),n.born=t.panes.filter(e=>!l.has(e.key)&&u(e,t)).map(e=>e.key),e.panes.some(t=>n.gone.includes(t.key)&&!d(t,e))&&n.kinds.add("pane-remove"),t.panes.some(e=>n.born.includes(e.key)&&!d(e,t))&&n.kinds.add("pane-add");const p=t.panes.filter(e=>l.has(e.key));te(e.panes.filter(e=>p.some(t=>t.key===e.key)).map(e=>e.key),p.map(e=>e.key))||(n.paneOrder=!0,n.kinds.add("pane-order"));for(const e of p){const t=l.get(e.key),o={weight:!te(e.weight,t.weight),collapsed:e.collapsed!==t.collapsed,axes:new Map};o.weight&&n.kinds.add("pane-weight"),o.collapsed&&n.kinds.add("pane-collapse");for(const[a,i]of Object.entries(e.axes)){const e=t.axes[a];if(void 0===e)continue;const r=Object.keys(i).filter(t=>t in e&&!te(i[t],e[t]));r.length&&(o.axes.set(a,r),n.kinds.add("axis"))}(o.weight||o.collapsed||o.axes.size)&&n.panes.set(e.key,o)}return n}const ce=e=>0===e.kinds.size,de={"study-add":"study-remove","study-remove":"study-add","pane-add":"pane-remove","pane-remove":"pane-add"};function ue(e){const t=e.id,o={...e.policy()};return{id:t,policy:()=>o}}class pe extends Error{}const he=e=>{throw new pe(e)};class me{constructor(e,t={}){Object.defineProperty(this,"_chart",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_draw",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_opts",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_limit",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_undo",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_redo",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_base",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_epoch",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_pending",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_applying",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_ignoring",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_restoring",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_tx",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_styled",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_drawings",{enumerable:!0,configurable:!0,writable:!0,value:{version:o.DRAWING_STATE_VERSION,drawings:[]}}),Object.defineProperty(this,"_group",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_dragging",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_deferred",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_dropped",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_orphans",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_keys",{enumerable:!0,configurable:!0,writable:!0,value:new WeakMap}),Object.defineProperty(this,"_nextKey",{enumerable:!0,configurable:!0,writable:!0,value:1}),Object.defineProperty(this,"_seen",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"_hostPanes",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"_names",{enumerable:!0,configurable:!0,writable:!0,value:new WeakMap}),Object.defineProperty(this,"_known",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_lastNames",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_hostRemoved",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"_listeners",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"_off",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_release",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_nextHolder",{enumerable:!0,configurable:!0,writable:!0,value:1}),Object.defineProperty(this,"_heard",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"_destroyed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),this._chart=e,this._draw=t.draw??null,this._opts=t,this._limit=Math.max(1,Math.floor(t.limit??100)),this._base=this._shot(!1),this._drawings=this._document(),this._listen(),this._claim()}get isDestroyed(){return this._destroyed}attach(e,t=this._draw){if(this._destroyed)return;for(const e of this._off.splice(0))e();const o=this._base.panes.map(e=>e.key),n=new Map(this._base.studies.map(e=>[this._liveId(e.id),e.id]));t!==this._draw&&this._detachSteps();const a=this._chart;if(this._chart=e,this._draw=t,this._claim(),this._drawings=this._document(),e.panes().forEach((e,t)=>{void 0!==o[t]&&this._keys.set(e,o[t])}),!e.isDestroyed)for(const t of e.indicators()){const e=n.get(t.id);void 0!==e&&this._bind(e,t)}if(e!==a){const t=new Set(e.isDestroyed?[]:e.indicators());for(const[e,o]of this._known)t.has(o)||this._known.set(e,ue(o))}this._pending=!1,this._dragging=!1,this._deferred=!1;const i=this._base;this._rebase(),this._took(i,this._base),this._prune(),this._listen(),this._notify()}canUndo(){return this._undo.some(e=>this._reachable(e,"undo"))}canRedo(){return this._redo.some(e=>this._reachable(e,"redo"))}peekUndo(){return this._peek(this._undo,"undo")}peekRedo(){return this._peek(this._redo,"redo")}undo(){return this._move("undo")}redo(){return this._move("redo")}transact(e,t){if(this._destroyed||this._chart.isDestroyed||this._applying>0||this._ignoring>0||null!==this._tx)return e();const o=this.group(t);this._flush();const n=this._tx={label:t,before:this._shot(!0),steps:[],commands:[]};try{return e()}finally{this._cut(n),this._tx=null,o()}}_cut(e){this._pending=!1;const t=this._shot(!0);this._base=t;const o=this._styled;this._styled=!1,this._record({label:e.label,before:e.before,after:t,steps:e.steps.splice(0),commands:e.commands.splice(0),orphans:this._takeOrphans(),linked:o})}_rebase(){this._epoch++,this._base=this._shot(!1)}group(e){if(this._destroyed)return()=>{};if(null!==this._group)return this._group.depth++,this._closer(this._group);this._flush();const t=this._group={entry:null,label:e,depth:1};return this._closer(t)}ignore(e){if(this._destroyed||this._applying>0)return e();const t=0===this._ignoring?this._tx:null;null!==t?this._cut(t):this._flush(),this._ignoring++;try{return this._untracked(e)}finally{if(0===--this._ignoring){this._pending=!1,this._orphans=[],this._styled=!1;const e=this._base;this._rebase(),this._took(e,this._base),null!==t&&this._tx===t&&(this._base=t.before=this._shot(!0)),this._prune()}}}_untracked(e){const t=this._draw;return null===t||t.isDestroyed?e():t.untracked(e)}push(e){this._destroyed||this._applying>0||this._ignoring>0||(null===this._tx?(this._flush(),this._record({label:e.label,commands:[e]})):this._tx.commands.push(e))}clear(){this._undo.length=0,this._redo.length=0,null!==this._group&&(this._group.entry=null),this._pending=!1,this._orphans=[],this._dropped=[],this._hostRemoved.clear(),this._lastNames.clear();const e=new Set(this._chart.isDestroyed?[]:this._chart.indicators());for(const[t,o]of this._known)e.has(o)||this._known.delete(t);this._destroyed||(this._drawings=this._document(),this._rebase()),this._notify()}subscribe(e){return this._listeners.add(e),()=>{this._listeners.delete(e)}}destroy(){if(!this._destroyed){this.clear(),this._destroyed=!0;for(const e of this._off.splice(0))e();this._release?.(),this._release=null,this._listeners.clear()}}_claim(){this._release?.(),this._release=null;const e=this._draw;null===e||e.isDestroyed||(this._release=e.delegateInputAnchorSteps(()=>this._anchorMoved()))}_anchorMoved(){this._destroyed||this._applying>0||this._ignoring>0||this._restoring>0||null!==this._tx||this._flush()}_listen(){const e=this._chart;if(e.isDestroyed)return;const t=(t,o)=>{this._off.push(e.on(t,o))};for(const e of se)t(e,()=>this._observe(e));t("drag:start",()=>this._flush()),t("draw:preview",()=>{this._dragging=!0}),t("draw:preview-clear",()=>{this._dragging=!1,this._deferred&&(this._deferred=!1,this._observe("objects:change"))}),t("style:change",()=>{null!==this._tx&&0===this._applying&&0===this._ignoring&&0===this._restoring&&(this._styled=!0)}),t("draw:remove",e=>{const t=e?.drawing;void 0!==t&&0===this._applying&&this._dropped.push(t)}),t("drawing:change",e=>this._drawingChange(e)),t("draw:restore",()=>this._forgetDrawings()),t("draw:destroy",e=>{e?.controller===this._draw&&(this._detachSteps(),this._draw=null,this._release=null)}),t("state:restore:start",()=>{this._restoring++,this._pending=!1}),t("state:restore:end",()=>{0===--this._restoring&&this.clear()}),t("destroy",()=>{if(this._chart===e)for(const e of this._off.splice(0))e()})}_observe(e){this._destroyed||this._applying>0||this._ignoring>0||this._restoring>0||null!==this._tx||("objects:change"===e&&this._dragging?this._deferred=!0:this._pending||(this._pending=!0,queueMicrotask(()=>{this._pending&&this._flush()})))}_flush(){if(!this._pending||this._destroyed)return;this._pending=!1;const e=this._group?.entry?.changes,t=void 0===e?void 0:e[e.length-1],o=this._shot(!0===t?.before.full&&t.epoch===this._epoch),n=this._base;this._base=o,this._record({before:n,after:o,orphans:this._takeOrphans()})}_drawingChange(e){const t=this._dropped;if(this._dropped=[],this._destroyed||this._applying>0)return;const o=this._drawings;if(this._drawings=this._document(),void 0!==e.step){if(this._ignoring>0)return;const t={id:e.step,before:o,after:this._drawings,detached:!1};return null!==this._tx?void this._tx.steps.push(t):(this._flush(),void this._record({steps:[t]}))}if("update"===e.kind&&!0!==e.linked&&t.length>0&&(this._pending||null!==this._tx||this._paneGone())){const e=this._base.panes.map(e=>e.key);for(const o of t){const t=e[o.paneIndex];void 0!==t&&this._orphans.push({pane:t,drawing:o})}return}"undo"!==e.kind&&"redo"!==e.kind||this._follow(e.kind)}_document(){return this._draw?.toJSON()??{version:o.DRAWING_STATE_VERSION,drawings:[]}}_forgetDrawings(){if(this._destroyed||this._applying>0)return;const e=this._group,t=e=>e.changes.length>0||e.commands.length>0;for(const t of[...this._undo,...this._redo,...e?.redo??[],e?.entry,e?.shifted])t&&(t.steps=[],t.orphans=[]);null!==this._tx&&(this._tx.steps=[]),this._undo=this._undo.filter(t),this._redo=this._redo.filter(t),e?.entry&&!t(e.entry)&&(e.entry=null),this._orphans=[],this._dropped=[],this._prune(),this._notify()}_paneGone(){const e=new Set(this._chart.panes().map(e=>this._keys.get(e)));return this._base.panes.some(t=>!e.has(t.key))}_detachSteps(){for(const e of[...this._undo,...this._redo])for(const t of e.steps)t.detached=!0;if(null!==this._tx)for(const e of this._tx.steps)e.detached=!0}_takeOrphans(){const e=this._orphans;return this._orphans=[],e}_record(e){const t=void 0!==e.before&&void 0!==e.after&&!ce(le(e.before,e.after)),o=t&&!ce(le(e.after,e.before,this._rules));if(t&&!o&&(this._epoch++,this._took(e.before,e.after)),!o&&!e.steps?.length&&!e.commands?.length)return t&&this._prune(),void this._notifyIfMoved();let n;const a=this._group;if(null!==a&&null!==a.entry)n=a.entry;else{n={label:a?.label,changes:[],steps:[],commands:[],orphans:[]},this._undo.push(n);const e=this._undo.length>this._limit?this._undo.shift():void 0;null!==a&&Object.assign(a,{entry:n,redo:this._redo,shifted:e})}this._merge(n,e,o),this._redo=[],this._prune(),this._notify()}_merge(e,t,o){if(e.label??(e.label=t.label),!0===t.linked&&(e.linked=!0),o){const o=t.before,i=t.after,r=e.changes[e.changes.length-1];void 0===r||r.epoch!==this._epoch?e.changes.push({before:o,after:i,epoch:this._epoch}):(!r.before.full&&o.full&&(r.before={...r.before,full:!0,settings:o.settings,panes:(n=r.before.panes,a=o.panes,n.map(e=>{const t=a.find(t=>t.key===e.key);if(void 0===t)return e;const o={};for(const[n,a]of Object.entries(e.axes)){const e=t.axes[n];o[n]=void 0===e?a:{...a,auto:e.auto,lock:e.lock}}return{...e,axes:o}}))}),r.after=i),e.orphans.push(...t.orphans??[])}var n,a;e.steps.push(...t.steps??[]),e.commands.push(...t.commands??[])}_closer(e){let t=!1;return()=>{if(t)return;if(t=!0,--e.depth>0||this._group!==e)return;this._flush(),this._group=null;const o=e.entry,n=o?.changes??[];if(null!==o&&!o.steps.length&&!o.commands.length&&(!n.length||ce(le(n[0].before,n[n.length-1].after)))){const t=this._undo.lastIndexOf(o);t>=0&&(this._undo.splice(t,1),void 0!==e.shifted&&this._undo.unshift(e.shifted),this._redo.length||void 0===e.redo||(this._redo=e.redo))}this._prune(),this._notify()}}_keyOf(e){let t=this._keys.get(e);return void 0===t&&(t=this._nextKey++,this._keys.set(e,t)),t}_nameOf(e){let t=this._names.get(e);if(void 0!==t)return t;t=e.id;const o=this._known.get(t);if(void 0!==o&&o!==e)do{t=`${e.id}~${this._nextHolder++}`}while(this._known.has(t));return this._bind(t,e),t}_bind(e,t){this._names.set(t,e),this._known.set(e,t)}_liveId(e){return this._known.get(e)?.id??e}_policyOf(e){return this._known.get(e)?.policy()??{}}_took(e,t){const o=new Set(t.studies.map(e=>e.id));for(const t of e.studies)o.has(t.id)||this._hostRemoved.add(t.id)}_prune(){const e=this._chart,t=new Set(e.isDestroyed?[]:e.indicators()),o=new Set;if(!e.isDestroyed)for(const t of e.panes()){const e=this._keys.get(t);void 0!==e&&o.add(e)}if(0===this._hostRemoved.size&&this._lastNames.size<=t.size&&this._seen.size<=o.size&&[...this._known.values()].every(e=>t.has(e)))return;const n=new Set,a=e=>{for(const t of e.panes)o.add(t.key);for(const t of e.studies){n.add(t.id);for(const e of Object.values(t.settings))oe(e)&&n.add(e.instanceId)}},i=e=>{if(null!=e){for(const t of e.changes)a(t.before),a(t.after);for(const t of e.orphans)o.add(t.pane)}};for(const e of this._undo)i(e);for(const e of this._redo)i(e);const r=this._group;null!==r&&(i(r.entry),r.redo?.forEach(i),i(r.shifted)),null!==this._tx&&a(this._tx.before),a(this._base);for(const e of this._orphans)o.add(e.pane);for(const[e,o]of this._known)n.has(e)||t.has(o)||this._known.delete(e);for(const e of this._hostRemoved)this._known.has(e)||this._hostRemoved.delete(e);for(const[e,t]of this._lastNames)this._known.has(t)||this._lastNames.delete(e);for(const e of this._seen)o.has(e)||this._seen.delete(e);for(const e of this._hostPanes)o.has(e)||this._hostPanes.delete(e)}_view(){const e={order:[],pane:new Map};if(this._chart.isDestroyed)return e;const t=this._chart.panes();for(const o of this._chart.indicators()){const n=this._nameOf(o);e.order.push(n),e.pane.set(n,this._keys.get(t[o.paneIndex])??-1)}return e}_series(){return(this._opts.series?this._opts.series():this._chart.primarySeries())??null}_shot(e){const o=this._chart,n={full:e,type:null,scale:null,studies:[],panes:[],defaults:{}};if(o.isDestroyed)return n;const a=0===this._seen.size,i=o.panes(),r=i.map(e=>this._keyOf(e)),s=this._series(),l=s?.priceScale();s&&(n.type=ae(o,s)),i.forEach((t,a)=>{const i={};for(const[r,s]of Object.entries(t.scaleStates())){if(void 0===s)continue;const c=r;void 0!==l&&t.scaleFor(c)===l&&(n.scale=c);const d=o.priceAxisPlacement(a,c),u={side:d?.side??("left"===c||"right"===c?c:"hidden"),order:d?.order??0,mode:s.mode,inverted:s.inverted,marginTop:s.marginTop,marginBottom:s.marginBottom};e&&(u.auto=s.autoScale,u.lock=t.ratioLocked(c)),i[r]=u}const s={key:r[a],weight:o.paneWeight(a),collapsed:o.paneCollapsed(a),series:t.series().length,axes:i};if(0===s.series){s.ranges={};for(const e of Object.keys(i)){const o=t.scaleFor(e);o.scaled&&(s.ranges[e]=o.priceRange())}}n.panes.push(s)});const c=o.indicators(),d=c.map(e=>this._nameOf(e));c.forEach((e,t)=>this._lastNames.set(e.id,d[t]));const u=e=>this._lastNames.get(e)??e;n.studies=c.map((e,t)=>({id:d[t],indicatorId:e.indicatorId,settings:ne(e.settings(),u),pane:r[e.paneIndex]??-1,visible:e.visible(),scale:e.priceScaleId(),plots:{...e.plotPriceScaleIds()}}));for(const e of n.panes)this._seen.has(e.key)||(this._seen.add(e.key),a||n.studies.some(t=>t.pane===e.key)||this._hostPanes.add(e.key)),this._hostPanes.has(e.key)&&(e.host=!0);const p=o.priceScaleDefaults();for(const e of ie)void 0!==p[e]&&(n.defaults[e]=p[e]);return e&&(n.settings=t.readChartSettings(o)),n}_peek(e,t){for(let o=e.length-1;o>=0;o--)if(this._reachable(e[o],t))return this._describe(e[o],t);return null}_describe(e,t){const o=new Set,n=e=>"redo"===t?e:de[e]??e;for(const a of this._moves(e,t))for(const e of a.delta.kinds)o.add(n(e));return e.steps.length&&o.add("drawing"),e.commands.length&&o.add("command"),{...void 0===e.label?{}:{label:e.label},changes:[...o]}}_moves(e,t){const o="undo"===t,n=this._view(),a=[];for(const t of o?e.changes.slice().reverse():e.changes){const e=o?t.after:t.before,i=o?t.before:t.after,r=le(e,i,this._rulesFor(n));ce(r)||(a.push({from:e,to:i,delta:r}),this._project(n,i,r))}return a}_project(e,t,o){const n=new Map(t.studies.map(e=>[e.id,e]));let a=!1;for(const[t,i]of o.studies){const o=n.get(t);void 0!==o?(i.presence&&!e.pane.has(t)&&(e.order.push(t),a=!0),(i.presence||i.pane)&&e.pane.set(t,o.pane)):(e.order=e.order.filter(e=>e!==t),e.pane.delete(t))}if(o.order||a)for(const o of t.panes){const n=this._plan(e,t,o.key);if(null===n||n.blocked)continue;let a=0;e.order=e.order.map(t=>e.pane.get(t)===o.key?n.desired[a++]:t)}}_plan(e,t,o){const n=e.order.filter(t=>e.pane.get(t)===o),a=t.studies.filter(e=>e.pane===o).map(e=>e.id).filter(e=>n.includes(e)),i=n.slice();let r=0;if(n.forEach((e,t)=>{a.includes(e)&&(i[t]=a[r++])}),te(i,n))return null;const s=e=>!1===this._policyOf(e).movable;return{now:n,desired:i,blocked:!te(n.filter(s),i.filter(s))}}_reachable(e,t){if(e.commands.length||this._moves(e,t).length)return!0;const o=this._draw?.historySteps()[t]??[];return e.steps.some(e=>e.detached||o.includes(e.id))}_move(e){if(this._destroyed||this._applying>0||this._chart.isDestroyed)return!1;this._flush(),null!==this._group&&(this._group.entry=null);const t="undo"===e?this._undo:this._redo,o="undo"===e?this._redo:this._undo;for(let n=t.pop();void 0!==n;n=t.pop()){const a=this._run(n,e);if("skip"!==a)return"done"===a?o.push(n):t.length=0,this._prune(),this._notify(),"done"===a}return this._prune(),this._notify(),!1}_run(e,t){const o="undo"===t,n=this._draw?.historySteps();e.steps=e.steps.filter(e=>e.detached||void 0!==n&&(n.undo.includes(e.id)||n.redo.includes(e.id)));const a=this._moves(e,t);if(!e.commands.length&&!a.length&&!e.steps.length)return"skip";const i={steps:[],moves:0,commands:0},r=!0===e.linked?this._look():null;this._applying++;try{if(this._untracked(()=>{if(!o)for(const t of e.commands)!1===t.redo()&&he("command"),i.commands++;o&&this._drawSteps(e.steps.slice().reverse(),"undo",i.steps);for(const e of a)i.moves++,this._apply(e.to,e.delta);if(o&&this._restoreOrphans(e.orphans),o||this._drawSteps(e.steps,"redo",i.steps),o)for(const t of e.commands.slice().reverse())!1===t.undo()&&he("command"),i.commands++}),null!==r&&!this._chart.isDestroyed){const e=this._look(),t=Object.fromEntries(Object.entries(e).filter(([e,t])=>!te(r[e],t)));Object.keys(t).length&&this._chart.emit("style:change",t)}return"done"}catch(o){this._rollback(e,t,i,a);try{this._opts.onError?.({direction:t,step:this._describe(e,t),error:o})}catch{}return"fail"}finally{this._applying--,this._pending=!1,this._dropped=[],this._orphans=[],this._drawings=this._document(),this._rebase()}}_rollback(e,t,o,n){const a="undo"===t,i=e=>{try{this._untracked(e)}catch{}},r=a?e.commands.slice().reverse():e.commands;for(const e of r.slice(0,o.commands).reverse())i(()=>{a?e.redo():e.undo()});for(const e of n.slice(0,o.moves).reverse())i(()=>this._apply(e.from,le(e.to,e.from,this._rules)));i(()=>this._drawSteps(o.steps.slice().reverse(),a?"redo":"undo",[]))}_look(){return this._chart.isDestroyed?{}:t.filterLinkAppearance(t.readChartSettings(this._chart))}_drawSteps(e,t,o){const n=this._draw;if(null!==n)for(const a of e){const e=n.historySteps()[t];if(!a.detached&&e.includes(a.id)&&e[e.length-1]!==a.id&&(a.detached=!0),a.detached){const[e,i]="undo"===t?[a.after,a.before]:[a.before,a.after],r=new Map(e.drawings.map(e=>[e.id,e])),s=new Map(i.drawings.map(e=>[e.id,e]));for(const e of new Set([...r.keys(),...s.keys()]))te(r.get(e),s.get(e))||n.applyLinkedDrawing(e,s.get(e)??null);o.push(a);continue}for(let e=0;n.historySteps()[t].includes(a.id)&&e<1e3&&("undo"===t?n.undo():n.redo());e++);n.historySteps()[t].includes(a.id)&&he("drawing"),o.push(a)}else e.length&&he("drawing")}_follow(e){const t=this._draw?.historySteps();if(void 0===t)return;const o="undo"===e?this._undo:this._redo,n="undo"===e?this._redo:this._undo,a="undo"===e?t.redo:t.undo;for(let e=o[o.length-1];void 0!==e&&(!e.commands.length&&!e.changes.length&&e.steps.length&&e.steps.every(e=>!e.detached&&a.includes(e.id)));e=o[o.length-1])n.push(o.pop());this._notify()}_restoreOrphans(e){const t=this._draw;if(null!==t)for(const{pane:o,drawing:n}of e){const e=this._slot(o);e>=0&&void 0===t.get(n.id)&&t.applyLinkedDrawing(n.id,{...n,paneIndex:e})}}_slot(e){return this._chart.panes().findIndex(t=>this._keys.get(t)===e)}_find(e){const t=this._known.get(e);return void 0===t||this._chart.isDestroyed?void 0:this._chart.indicators().find(e=>e===t)}_rulesFor(e){return{policy:e=>this._policyOf(e),present:t=>e.pane.has(t),returns:e=>!this._hostRemoved.has(e)&&!1!==this._policyOf(e).removable,order:(t,o)=>{const n=this._plan(e,t,o);return null!==n&&!n.blocked}}}get _rules(){return this._rulesFor(this._view())}_apply(e,o){const n=this._chart,a=new Map(e.studies.map(e=>[e.id,e]));for(const e of o.studies.keys()){if(a.has(e))continue;const t=this._find(e);void 0===t||n.removeIndicator(t.id)||he("remove")}const i=e.studies.filter(e=>{const t=o.studies.get(e.id);return void 0!==t&&(t.presence||t.pane)&&this._find(e.id)?.paneIndex!==this._slot(e.pane)}),r=[];for(;i.length;){const e=e=>Object.values(e.settings).some(t=>oe(t)&&i.some(o=>o!==e&&o.id===t.instanceId)),t=Math.max(0,i.findIndex(t=>!e(t)));r.push(...i.splice(t,1))}const s=new Set;for(const e of o.born){if(this._slot(e)>=0)continue;const t=n.panes().length,o={zOrder:()=>"bottom",draw:()=>{}};n.addPrimitive(o,t),n.removePrimitive(o);const a=n.panes()[t];void 0===a&&he("pane"),this._keys.set(a,e),s.add(e)}let l=!1;for(const t of r){let o=this._slot(t.pane);const a=o<0;a&&(o=n.panes().length);const i=this._find(t.id);void 0===i?(this._add(t,o,e),l=!0):i.paneIndex===o||n.moveIndicator(i.id,o)||he("move");const r=n.panes()[o];a&&void 0!==r&&(this._keys.set(r,t.pane),s.add(t.pane))}for(const e of o.gone){const t=this._slot(e);t>=0&&0===n.panes()[t].series().length&&!n.removePane(t)&&he("pane")}(o.paneOrder||s.size)&&this._arrange(e);for(const t of e.panes){const e=o.panes.get(t.key),a=s.has(t.key),i=void 0!==e||a?this._slot(t.key):-1;i<0||(!a&&!e.weight||te(n.paneWeight(i),t.weight)||n.setPaneWeight(i,t.weight),!a&&!e.collapsed||n.paneCollapsed(i)===t.collapsed||n.setPaneCollapsed(i,t.collapsed)||he("collapse"))}for(const t of e.studies){const e=o.studies.get(t.id);void 0===e||e.presence||this._fit(t,e)}(o.order||l)&&this._stack(e);const c=this._series();if(o.type&&null!==e.type&&null!==c&&ae(n,c)!==e.type&&(!function(e,t,o,n){const[a,i]=o.split("+");void 0===n?(e.setSeriesTransform(t,void 0===i?null:{type:i}),e.setSeriesType(t,a)):n(i??a)}(n,c,e.type,this._opts.setChartType),ae(n,c)!==e.type&&he("chart type")),o.scale&&null!==e.scale&&null!==c&&n.setSeriesPriceScale(c,e.scale),o.settings.length&&e.settings){const a=t.readChartSettings(n),i={};for(const t of o.settings)t in e.settings&&!te(a[t],e.settings[t])&&(i[t]=e.settings[t]);Object.keys(i).length&&t.applyChartSettings(n,i)}if(o.defaults.length){const a=n.priceScaleDefaults(),i={};for(const n of o.defaults){const o=e.defaults[n]??t.DEFAULT_PRICE_SCALE_OPTIONS[n];te(a[n]??t.DEFAULT_PRICE_SCALE_OPTIONS[n],o)||(i[n]=o)}Object.keys(i).length&&n.setPriceScaleOptions(i)}for(const t of e.panes){const e=s.has(t.key)?null:o.panes.get(t.key)?.axes;if(null!==e&&!e?.size)continue;const a=this._slot(t.key);a>=0&&this._axes(a,t,e??null);const i=n.panes()[a];if(null===e&&void 0!==i&&0===i.series().length)for(const[e,o]of Object.entries(t.ranges??{}))i.scaleFor(e).setComputedRange(o)}this._check(e,o)}_add(e,t,o){const n=this._chart,a=this._liveId(e.id),i={paneIndex:t,instanceId:a};null!==e.scale&&(i.priceScaleId=e.scale),Object.keys(e.plots).length&&(i.plotPriceScaleIds=e.plots);const r=this._policyOf(e.id);Object.keys(r).length&&(i.policy={...r});const s=this._liveSettings(e.settings);let l;try{l=n.addIndicator(e.indicatorId,s,i)}catch(t){if(!n.indicators().some(e=>e.id===a))throw t;const o={...i};delete o.instanceId,l=n.addIndicator(e.indicatorId,s,o)}if(this._bind(e.id,l),this._lastNames.set(l.id,e.id),l.id!==a)for(const t of o.studies){const o=Object.keys(t.settings).filter(o=>oe(t.settings[o])&&t.settings[o].instanceId===e.id),n=o.length?this._find(t.id):void 0;if(void 0===n)continue;const a=n.settings(),i={};for(const e of o){const t=a[e];oe(t)&&t.instanceId!==l.id&&(i[e]={...t,instanceId:l.id})}Object.keys(i).length&&n.setSettings(i)}e.visible||l.setVisible(!1)}_liveSettings(e){return ne(e,e=>this._liveId(e))}_fit(e,t){const o=this._find(e.id);if(void 0===o)return;const n=this._liveSettings(e.settings),a=o.settings(),i={};for(const e of t.keys)e in n&&!te(a[e],n[e])&&(i[e]=n[e]);if(Object.keys(i).length&&o.setSettings(i),t.visible&&o.visible()!==e.visible&&o.setVisible(e.visible),!t.scale)return;o.priceScaleId()===e.scale||o.setPriceScale(e.scale)||he("scale");const r=o.plotPriceScaleIds(),s={};for(const[t,o]of Object.entries(e.plots))r[t]!==o&&(s[t]=o);for(const t of Object.keys(r))t in e.plots||(s[t]=null);Object.keys(s).length&&!o.setPlotPriceScales(s)&&he("scale")}_arrange(e){const t=this._chart,o=()=>t.panes().map(e=>this._keyOf(e)),n=e.panes.map(e=>e.key).filter(e=>o().includes(e)),a=o(),i=a.slice();let r=0;a.forEach((e,t)=>{n.includes(e)&&(i[t]=n[r++])});for(let e=0;e<i.length;e++)for(let n=o().indexOf(i[e]);n>e;n--)t.movePane(n,-1)||he("pane order")}_stack(e){const t=this._chart;for(const o of e.panes){const n=this._plan(this._view(),e,o.key);if(null===n||n.blocked)continue;const a=this._slot(o.key),{desired:i}=n,r=()=>t.indicators().filter(e=>e.paneIndex===a).map(e=>this._nameOf(e));for(let e=0;e<i.length;e++)for(let o=r().indexOf(i[e]);o>e;o--){(!1!==this._policyOf(i[e]).movable?t.reorderIndicator(this._liveId(i[e]),-1):t.reorderIndicator(this._liveId(r()[o-1]),1))||he("study order")}}}_axes(e,t,o){const n=this._chart,a=n.panes()[e],i=a.scaleStates();for(const[r,s]of Object.entries(t.axes)){const t=i[r],l=o?.get(r);if(void 0===t||null!==o&&void 0===l)continue;const c=e=>void 0===l||l.includes(e),d=r,u=n.priceAxisPlacement(e,d);!c("side")&&!c("order")||null===u||u.side===s.side&&u.order===s.order||n.setPriceAxisPlacement(e,d,s.side,s.order);const p={};c("mode")&&t.mode!==s.mode&&(p.mode=s.mode),c("inverted")&&t.inverted!==s.inverted&&(p.inverted=s.inverted),c("marginTop")&&!te(t.marginTop,s.marginTop)&&(p.marginTop=s.marginTop),c("marginBottom")&&!te(t.marginBottom,s.marginBottom)&&(p.marginBottom=s.marginBottom),Object.keys(p).length&&n.setPriceAxisOptions(e,d,p),c("auto")&&void 0!==s.auto&&t.autoScale!==s.auto&&n.setPriceAxisAutoFit(e,d,s.auto),c("lock")&&void 0!==s.lock&&a.ratioLocked(d)!==s.lock&&n.setPriceAxisLockRatio(e,d,s.lock)}}_check(e,t){const o=new Map(e.studies.map(e=>[e.id,e]));for(const[e,n]of t.studies){const t=o.get(e),a=this._find(e);void 0===t!=(void 0===a)&&he("study"),(n.presence||n.pane)&&void 0!==t&&void 0!==a&&this._slot(t.pane)!==a.paneIndex&&he("study pane")}if(t.paneOrder){const t=this._chart.panes().map(e=>this._keys.get(e)),o=e.panes.map(e=>e.key).filter(e=>t.includes(e));te(t.filter(e=>void 0!==e&&o.includes(e)),o)||he("pane order")}}_notify(){this._heard=this._ready();for(const e of[...this._listeners])try{e()}catch{}}_ready(){return this._destroyed?"":JSON.stringify([this.peekUndo(),this.peekRedo()])}_notifyIfMoved(){this._listeners.size>0&&this._ready()!==this._heard&&this._notify()}}function ge(){return"undefined"!=typeof navigator&&/mac|iphone|ipad/i.test(navigator.platform||navigator.userAgent||"")}new Set(["Mod","Ctrl","Meta","Alt","Shift"]);new Set([{command:"panLeft",label:"Pan left",combos:["ArrowLeft"]},{command:"panRight",label:"Pan right",combos:["ArrowRight"]},{command:"panLeftFast",label:"Pan left (fast)",combos:["Mod+ArrowLeft"]},{command:"panRightFast",label:"Pan right (fast)",combos:["Mod+ArrowRight"]},{command:"panUp",label:"Pan up",combos:["ArrowUp"]},{command:"panDown",label:"Pan down",combos:["ArrowDown"]},{command:"zoomIn",label:"Zoom in",combos:["Equal","Shift+Equal","NumpadAdd"]},{command:"zoomOut",label:"Zoom out",combos:["Minus","NumpadSubtract"]},{command:"resetScale",label:"Reset view",combos:["Home","Digit0"]},{command:"fitContent",label:"Fit all bars",combos:["Alt+KeyF"]},{command:"screenshot",label:"Screenshot (PNG)",combos:["Alt+Shift+KeyS"]},{command:"toggleGridVert",label:"Toggle vertical grid",combos:["Alt+KeyV"]},{command:"toggleGridHorz",label:"Toggle horizontal grid",combos:["Alt+KeyH"]},{command:"toggleCrosshairMagnet",label:"Toggle crosshair magnet",combos:["Alt+KeyM"]}].map(e=>e.command));const fe="keymap",be="chart:",ve={mod:"Mod",ctrl:"Mod",control:"Mod",cmd:"Mod",command:"Mod",meta:"Mod",win:"Mod",alt:"Alt",option:"Alt",opt:"Alt",shift:"Shift"},we={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:","},ye=new Set(["Shift","Control","Alt","Meta","OS","AltGraph","CapsLock","Fn"]),_e=["Mod","Alt","Shift"];function xe(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!==ve[o.toLowerCase()])return"";const a=new Set;for(const e of n){const t=ve[e.toLowerCase()];if(void 0===t)return"";a.add(t)}o=function(e){const t=e.toLowerCase();return void 0!==we[t]?we[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)||a.delete("Shift");return[..._e.filter(e=>a.has(e)),o].join("+")}function ke(e){let t=e.key??"";if(""===t||"Unidentified"===t||ye.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 Ce={Escape:"Esc",Delete:"Del",ArrowLeft:"Left",ArrowRight:"Right",ArrowUp:"Up",ArrowDown:"Down"};function Se(e,t=ge()){const o=xe(e);if(""===o)return"";const n=o.split("+"),a=n[n.length-1];return[...n.slice(0,-1).map(e=>"Mod"===e?t?"Cmd":"Ctrl":"Alt"===e?t?"Opt":"Alt":"Shift"),Ce[a]??(1===a.length?a.toUpperCase():a)].join("+")}const Ae={Equal:"=+",Minus:"-_",Slash:"/?",Comma:",<",Period:".>",Semicolon:";:",Quote:"'\"",BracketLeft:"[{",BracketRight:"]}",Backslash:"\\|",Backquote:"`~",Digit1:"1!",Digit2:"2@",Digit3:"3#",Digit4:"4$",Digit5:"5%",Digit6:"6^",Digit7:"7&",Digit8:"8*",Digit9:"9(",Digit0:"0)",NumpadAdd:"++",NumpadSubtract:"--",NumpadMultiply:"**",NumpadDivide:"//",NumpadDecimal:".."};function Te(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 a;const i=/^Key([A-Z])$/.exec(o),r=/^Numpad([0-9])$/.exec(o);return a=null!==i?i[1].toLowerCase():null!==r?r[1]:void 0!==Ae[o]?Ae[o][n.includes("Shift")?1:0]:"NumpadEnter"===o?"Enter":o,xe([...n,a].join("+"))}function Ee(e){const o=e.split("+"),n=o.pop()??"";return/^[a-z]$/.test(n)&&t.isReservedCombo([...o,"Key"+n.toUpperCase()].join("+"))}const Le=new Set(["global","widget","chart"]),Oe=(e,t)=>e===t||Le.has(e)&&Le.has(t),Ie=e=>"rail"!==e&&"overlay"!==e,Pe=new Set,$e=(e,t=[])=>({ok:!1,reason:e,conflicts:t}),je=(e,t)=>e===t||null!==e&&null!==t&&e.length===t.length&&e.every((e,o)=>e===t[o]);class De{constructor(e={}){Object.defineProperty(this,"_isMac",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_chart",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_scopes",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_bindings",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_byCombo",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_conflictListeners",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"_changeListeners",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"_overrides",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_chartOverrides",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_chartBaseline",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_capture",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_detach",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_target",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_nextId",{enumerable:!0,configurable:!0,writable:!0,value:1}),this._isMac=e.isMac??ge(),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 a=xe(e);if(""===a)throw new Error(`openalgo-charts widget: "${e}" is not a key binding`);const i=n.command??null;if(null!==i&&(""===i||i.startsWith(be)||this._bindings.some(e=>e.command===i)))throw new Error(`openalgo-charts widget: "${i}" is not a free command name`);const r=null!==i&&!1!==n.rebindable,s=null!==i&&r?this._overrides.get(i):void 0,l={id:this._nextId++,combo:void 0===s?a:s??"",defaultCombo:a,command:i,rebindable:r,scope:o,label:n.label??Se(a,this._isMac),group:n.group??"Widget",hidden:!0===n.hidden,inText:!0===n.inText,layered:!0===n.layered,action:t,when:n.when},c=this._conflictKeys();return this._bindings.push(l),this._index(l),null!==c&&this._announce(c),()=>this._unregister(l)}_index(e){if(""===e.combo)return;const t=this._byCombo.get(e.combo)??[];let o=t.length;for(;o>0&&t[o-1].id>e.id;)o--;t.splice(o,0,e),this._byCombo.set(e.combo,t)}_unindex(e){const t=this._byCombo.get(e.combo);if(void 0===t)return;const o=t.indexOf(e);o>=0&&t.splice(o,1),0===t.length&&this._byCombo.delete(e.combo)}_unregister(e){const t=this._bindings.indexOf(e);t>=0&&this._bindings.splice(t,1),this._unindex(e)}_widgetConflicts(){const e=[];for(const t of this._bindings){if(t.layered||""===t.combo)continue;const o=this._byCombo.get(t.combo)??[],n=o.slice(0,o.indexOf(t)).find(e=>e.scope===t.scope);void 0!==n&&e.push({combo:t.combo,scope:t.scope,kept:n.label,shadowed:t.label,source:"widget"})}return e}_conflictKeys(){return 0===this._conflictListeners.size?null:new Set(this._widgetConflicts().map(e=>`${e.combo}|${e.scope}|${e.kept}|${e.shadowed}`))}_announce(e){for(const t of this._widgetConflicts())if(!e.has(`${t.combo}|${t.scope}|${t.kept}|${t.shadowed}`))for(const e of this._conflictListeners)e(t)}onConflict(e){return this._conflictListeners.add(e),()=>this._conflictListeners.delete(e)}onChange(e){return this._changeListeners.add(e),()=>this._changeListeners.delete(e)}_emit(e){const t=Array.from(new Set(Array.from(e).filter(e=>null!==e)));if(0!==t.length)for(const e of this._changeListeners)e({commands:t})}capture(e){return this._capture=e,Pe.add(this),()=>{this._capture===e&&(this._capture=null,Pe.delete(this))}}get capturing(){return null!==this._capture}handle(e){if(null!==this._capture)return!1!==this._capture(e)&&(e.preventDefault?.(),void 0!==e.stopImmediatePropagation?e.stopImmediatePropagation():e.stopPropagation?.(),!0);if(null!==this._target)for(const e of Pe)if(e!==this&&e._target===this._target)return!1;const t=ke(e);if(""===t)return!1;const o=this._byCombo.get(t);if(void 0===o)return!1;const n=h(e.target);for(const t of this._scopes())for(const a of o.slice())if(a.scope===t&&(!n||a.inText)&&(void 0===a.when||a.when())&&!1!==a.action(e))return e.preventDefault?.(),e.stopPropagation?.(),!0;return!1}attach(e){this._detach?.();const t=e=>{this.handle(e)};return e.addEventListener("keydown",t,!0),this._target=e,this._detach=()=>{e.removeEventListener("keydown",t,!0),this._detach=null,this._target=null},this._detach}list(){return this._bindings.slice()}conflicts(){const e=this._widgetConflicts();if(null!==this._chart)for(const t of this._chart.list())if(!t.isDisabled)for(const o of t.combos){const n=Te(o),a=(this._byCombo.get(n)??[]).find(e=>Ie(e.scope)&&!e.layered);void 0!==a&&e.push({combo:n,scope:a.scope,kept:a.label,shadowed:t.label,source:"chart"})}return e}format(e){return Se(e,this._isMac)}_use(e){return{command:e.command,label:e.label,group:e.group,source:"widget",rebindable:e.rebindable}}_chartEditable(){const e=this._chart;return null!==e&&"function"==typeof e.setBinding&&"function"==typeof e.disable&&"function"==typeof e.resetBinding}_chartUse(e){return{command:be+e.command,label:e.label,group:"Chart",source:"chart",rebindable:this._chartEditable()}}_holders(e,t,o){const n=[];for(const a of this._byCombo.get(e)??[])null!==o&&a.command===o||!Oe(a.scope,t)||n.push(this._use(a));if(null!==this._chart&&Ie(t))for(const t of this._chart.list())t.isDisabled||be+t.command===o||t.combos.some(t=>Te(t)===e)&&n.push(this._chartUse(t));return n}_chartHolders(e,t){const o=[],n=this._chart;if(null===n)return o;for(const a of n.list())a.isDisabled||a.command===t||a.combos.some(t=>e.includes(t))&&o.push(this._chartUse(a));const a=new Set;for(const t of e)for(const e of this._byCombo.get(Te(t))??[])e.layered||!Ie(e.scope)||a.has(e)||(a.add(e),o.push(this._use(e)));return o}conflictsFor(e,t="widget"){const o=xe(e);return""===o?[]:this._holders(o,t,null)}chord(e){if(e.startsWith(be)){const t=this._chart?.list().find(t=>be+t.command===e);return void 0===t?null:t.isDisabled||0===t.combos.length?"":Te(t.combos[0])}const t=this._bindings.find(t=>t.command===e);return void 0===t?null:t.combo}_setWidget(e,t){e.combo!==t&&(this._unindex(e),e.combo=t,this._index(e));const o=e.command;t===e.defaultCombo?this._overrides.delete(o):this._overrides.set(o,""===t?null:t)}_chartNow(e){const t=this._chart?.list().find(t=>t.command===e);return void 0===t?void 0:t.isDisabled?null:t.combos.slice()}_base(e){const t=this._chartBaseline??(this._chartBaseline=new Map);return t.has(e)||t.set(e,this._chartNow(e)??null),t.get(e)}_setChart(e,t){const o=this._chart,n=this._base(e),a=()=>{null===t?o.disable(e):o.setBinding(e,t)};if(je(n,t))return o.resetBinding(e),je(this._chartNow(e)??null,t)||a(),void this._chartOverrides.delete(e);a(),this._chartOverrides.set(e,t)}_dropChart(e,t){const o=e.command.slice(6),n=(this._chartNow(o)??[]).filter(e=>!t(e));this._setChart(o,n.length>0?n:null)}_dropWidget(e){const t=this._bindings.find(t=>t.command===e.command);void 0!==t&&this._setWidget(t,"")}rebind(e,t,o={}){return this._rebind(e,t,!0===o.replace,!1)}reset(e,t={}){return this._rebind(e,void 0,!0===t.replace,!0)}resetAll(){const e=this._clearAll();this._emit(e)}_clearAll(){const e=[];for(const t of Array.from(this._overrides.keys())){const o=this._bindings.find(e=>e.command===t);void 0!==o&&this._setWidget(o,o.defaultCombo),this._overrides.delete(t),e.push(t)}for(const t of Array.from(this._chartOverrides.keys()))this._setChart(t,this._base(t)),e.push(be+t);return e}_rebind(e,t,o,n){if(e.startsWith(be))return this._rebindChart(e.slice(6),t,o,n);const a=this._bindings.find(t=>t.command===e);if(void 0===a)return n&&this._overrides.delete(e)&&this._emit([e]),n?{ok:!0,conflicts:[]}:$e("unknown");if(!a.rebindable)return $e("fixed");let i=a.defaultCombo;if(!n&&(i="",null!=t)){const e="string"==typeof t?[t]:t;if(i=1===e.length?xe(e[0]):"",""===i)return $e("invalid");if(Ee(i))return $e("reserved")}if(i===a.combo)return{ok:!0,conflicts:[]};const r=""===i?[]:this._holders(i,a.scope,e).filter(e=>!n||"widget"===e.source);if(r.length>0){if(!o||r.some(e=>!e.rebindable))return $e("taken",r);for(const e of r)"chart"===e.source?this._dropChart(e,e=>Te(e)===i):this._dropWidget(e)}return this._setWidget(a,i),this._emit([e,...r.map(e=>e.command)]),{ok:!0,conflicts:r}}_rebindChart(e,o,n,a){const i=null===this._chart?void 0:this._chartNow(e);if(void 0===i)return $e("unknown");if(!this._chartEditable())return $e("fixed");let r=null;if(a)r=this._base(e);else if(null!=o){const e=("string"==typeof o?[o]:Array.from(o)).map(t.normalizeCombo);if(0===e.length||e.includes(""))return $e("invalid");if(e.some(e=>t.isReservedCombo(e)))return $e("reserved");r=Array.from(new Set(e))}if(je(r,i))return a&&this._chartOverrides.delete(e)&&this._emit([be+e]),{ok:!0,conflicts:[]};const s=null===r?[]:this._chartHolders(r,e).filter(e=>!a||"chart"===e.source);if(s.length>0){if(!n||s.some(e=>!e.rebindable))return $e("taken",s);const e=r;for(const t of s)"chart"===t.source?this._dropChart(t,t=>e.includes(t)):this._dropWidget(t)}return this._setChart(e,r),this._emit([be+e,...s.map(e=>e.command)]),{ok:!0,conflicts:s}}overrides(){const e={};for(const[t,o]of this._overrides)e[t]=o;for(const[t,o]of this._chartOverrides)e[be+t]=null===o?null:o.slice();return e}applyOverrides(e){const o=new Map,n=new Map;if(null!==e&&"object"==typeof e&&!Array.isArray(e))for(const[a,i]of Object.entries(e))if(a.startsWith(be)){const e=a.slice(6),o=null===i?null:(Array.isArray(i)?i:[i]).map(e=>"string"==typeof e?t.normalizeCombo(e):"");if(""===e||null!==o&&(0===o.length||o.some(e=>""===e||t.isReservedCombo(e))))continue;n.set(e,o)}else if(""!==a&&(null===i||"string"==typeof i)){const e=null===i?null:xe(i);if(""===e||null!==e&&Ee(e))continue;const t=this._bindings.find(e=>e.command===a);if(void 0!==t&&!t.rebindable)continue;o.set(a,e)}const a=this._conflictKeys(),i=new Map(this._bindings.map(e=>[e,e.combo])),r=this.overrides();this._clearAll();for(const[e,t]of o){const o=this._bindings.find(t=>t.command===e);void 0===o?this._overrides.set(e,t):this._setWidget(o,t??"")}if(this._chartEditable())for(const[e,t]of n)void 0!==this._chartNow(e)&&this._setChart(e,t);null!==a&&this._announce(a);const s=this.overrides(),l=this._bindings.filter(e=>null!==e.command&&i.get(e)!==e.combo).map(e=>e.command);for(const e of new Set([...Object.keys(r),...Object.keys(s)]))JSON.stringify(r[e])!==JSON.stringify(s[e])&&l.push(e);this._emit(l)}_chartDefault(e,t){const o=this._chartBaseline?.get(e),n=void 0===o?t:o??[];return 0===n.length?"":Te(n[0])}describe(){const e=new Map;for(const t of this._bindings){if(t.hidden)continue;const o=e.get(t.group)??[],n={label:t.label,combo:t.combo,display:this.format(t.combo)};null!==t.command&&(n.command=t.command,n.rebindable=t.rebindable,n.defaultCombo=t.defaultCombo,n.changed=t.combo!==t.defaultCombo),o.push(n),e.set(t.group,o)}const t=Array.from(e,([e,t])=>({group:e,rows:t}));if(null!==this._chart){const e=new Map;for(const t of this.conflicts())"chart"===t.source&&e.set(t.shadowed+"|"+t.combo,t.kept);const o=this._chartEditable(),n=[];for(const t of this._chart.list()){const a=this._chartOverrides.has(t.command);if((t.isDisabled||0===t.combos.length)&&!a)continue;const i=t.isDisabled||0===t.combos.length?"":Te(t.combos[0]),r={label:t.label,combo:i,display:this.format(i),command:be+t.command,rebindable:o,defaultCombo:this._chartDefault(t.command,t.combos),changed:a},s=e.get(t.label+"|"+i);void 0!==s&&(r.shadowedBy=s),n.push(r)}n.length>0&&t.push({group:"Chart",rows:n})}return t}destroy(){this._detach?.(),this._capture=null,Pe.delete(this),this._bindings.length=0,this._byCombo.clear(),this._overrides.clear(),this._chartOverrides.clear(),this._conflictListeners.clear(),this._changeListeners.clear()}}function Me(e){const t={Ctrl:"Control",Cmd:"Meta",Opt:"Alt",Del:"Delete",Esc:"Escape",Left:"ArrowLeft",Right:"ArrowRight",Up:"ArrowUp",Down:"ArrowDown"};return e.split("+").map(e=>t[e]??e).join("+")}function ze(e,t,o){const n=e,a=("function"==typeof n?.chord?n.chord(t):null)??o;if(void 0!==a&&""!==a)return"function"==typeof n?.format?n.format(a):Se(a)}const Ne=new WeakSet;const Re=V(()=>Promise.resolve().then(function(){return Cl})),Fe=new WeakMap;function We(e,t={}){let o=null,n=!0,a=Fe.get(e);return void 0===a&&Fe.set(e,a={waiting:null}),H(Re,n=>{o=n.mountShortcutsPanel(e,t.edit??!Ne.has(e.keymap))},t=>e.toast(J(e,R(e,"Keyboard shortcuts"),t),"error"),()=>n&&!e.chart.isDestroyed,{slot:a,doc:e.document}),()=>{n=!1,o?.()}}const Be=["#4f8cff","#26a69a","#ef5350","#f4b740","#ab79df","#22a8bd","#e88555","#9aa6b2","#ffffff","#000000"],Ue=[];function qe(e){if("string"!=typeof e||e.length>256)return null;const t=e.trim(),o=/^#([\da-f]{3}|[\da-f]{4}|[\da-f]{6}|[\da-f]{8})$/i.exec(t);if(null!==o){let e=o[1].toLowerCase();e.length<=4&&(e=e.split("").map(e=>e+e).join(""));const t=8===e.length?parseInt(e.slice(6),16)/255:1;return{hex:`#${e.slice(0,6)}`,alpha:t,format:8===e.length?"hexAlpha":"hex"}}const n=t.toLowerCase(),a=n.startsWith("rgba(")?5:n.startsWith("rgb(")?4:0;if(0===a||!t.endsWith(")"))return null;const i=t.slice(a,-1);let r,s;if(i.includes(",")){const e=i.split(",").map(e=>e.trim());if(3!==e.length&&4!==e.length)return null;r=e.slice(0,3),s=e[3]}else{const e=i.split("/");if(e.length>2)return null;r=e[0].trim().split(/\s+/),s=e[1]?.trim()}if(3!==r.length||r.some(e=>!/^\d{1,3}$/.test(e)))return null;const l=r.map(Number);if(l.some(e=>e>255))return null;if(void 0!==s){const e=s.split(".");if(e.length>2||e.every(e=>""===e)||e.some(e=>/\D/.test(e)))return null}const c=void 0===s?1:Number(s);return!Number.isFinite(c)||c<0||c>1?null:{hex:`#${l.map(e=>e.toString(16).padStart(2,"0")).join("")}`,alpha:c,format:void 0===s?"hex":"rgba"}}function Ke(e,t,o){if("hex"===o)return e;if("hexAlpha"===o)return`${e}${Math.round(255*t).toString(16).padStart(2,"0")}`;return`rgba(${[1,3,5].map(t=>parseInt(e.slice(t,t+2),16)).join(",")},${Number(t.toFixed(3))})`}function Ge(e,t){const o=(t,o)=>{const n=e.createElement(t);return n.className=o,n},n=e=>R(t,`schema.ui.colorPicker.${e}`,{},e),a=o("span","oac-color"),i=o("input","oac-swatch-input");i.type="color",i.id=t.id,i.tabIndex=-1,i.setAttribute("aria-hidden","true"),i.setAttribute("aria-label",t.label);const r=o("button","oac-color__trigger");r.type="button",r.id=`${t.id}-trigger`,r.setAttribute("aria-label",t.label),r.setAttribute("aria-haspopup","dialog"),r.setAttribute("aria-expanded","false"),null!==t.disabledReason&&void 0!==t.disabledReason?(r.disabled=!0,i.disabled=!0,r.title=t.disabledReason,i.title=t.disabledReason):(r.title=t.label,i.title=t.label),a.appendChild(i),a.appendChild(r);const s=o("div","oac-color__popover");s.hidden=!0,s.setAttribute("role","dialog"),s.setAttribute("aria-label",n("Color"));const l=o("div","oac-color__palette");l.setAttribute("aria-label",n("Palette"));const c=o("div","oac-color__recent");c.setAttribute("aria-label",n("Recent"));const d=o("button","oac-color__custom");d.type="button",d.textContent=n("Custom"),d.addEventListener("click",()=>{v||i.click()}),s.appendChild(l),s.appendChild(c),s.appendChild(d),a.appendChild(s);let u,p,h,m=t.value,g=qe(m),f=g?.alpha??1,b=!1,v=!1;const w=()=>{i.value=g?.hex??"#000000",r.style.backgroundColor=null===g?"#000000":Ke(g.hex,f,g.format),void 0!==p&&(p.value=String(Math.round(100*f)),void 0!==h&&(h.textContent=`${p.value}%`))},y=(e,o=f)=>{if(v||r.disabled||!/^#[\da-f]{6}$/i.test(e))return;const n=g?.format??"hex";m=Ke(e.toLowerCase(),o,n),g={hex:e.toLowerCase(),alpha:o,format:n},f=o,w(),function(e){const t=Ue.indexOf(e);t>=0&&Ue.splice(t,1),Ue.unshift(e),Ue.length=Math.min(Ue.length,6)}(g.hex),t.onChange(m)},_=(e,t)=>{e.innerHTML="";for(const n of t){const t=o("button","oac-color__choice");t.type="button",t.setAttribute("aria-label",n),t.title=n,t.style.backgroundColor=n,t.addEventListener("click",()=>{y(n),C(),r.focus()}),e.appendChild(t)}},x=e=>{a.contains(e.target)||s.contains(e.target)||C()},k=()=>{b&&(u=void 0,b=!1,s.hidden=!0,r.setAttribute("aria-expanded","false"),e.removeEventListener("pointerdown",x,!0),g=qe(m),f=g?.alpha??1,w(),v||s.parentNode===a||a.appendChild(s))},C=()=>{const e=u;u=void 0,e?.(),k()},S=()=>{if(!(v||b||r.disabled))if(b=!0,function(){if(void 0!==p||null===g||"hex"===g.format)return;const a=o("label","oac-color__opacity");a.appendChild(e.createTextNode(n("Opacity"))),p=o("input","oac-color__range"),p.type="range",p.min="0",p.max="100",p.step="1",h=o("output","oac-color__percent");const r=p,l=h;r.addEventListener("input",()=>{f=Number(r.value)/100,l.textContent=`${r.value}%`,t.live&&y(i.value,f)}),r.addEventListener("change",()=>y(i.value,Number(r.value)/100)),a.appendChild(r),a.appendChild(l),s.appendChild(a)}(),w(),_(l,Be),_(c,Ue),c.hidden=0===Ue.length,s.hidden=!1,r.setAttribute("aria-expanded","true"),t.openOverlay){s.classList.remove("oac-color__popover--above"),r.focus();const e=t.openOverlay(s,{anchor:r,placement:"below",modal:!1,initialFocus:l.querySelector("button"),onClose:k});b?u=e:e()}else{const t=a.closest(".oac-widget");if(null!==t){const e=t.getBoundingClientRect().bottom;s.classList.toggle("oac-color__popover--above",r.getBoundingClientRect().bottom+s.offsetHeight>e)}e.addEventListener("pointerdown",x,!0),l.querySelector("button")?.focus()}};r.addEventListener("click",()=>b?C():S());const A=e=>{"Escape"===e.key&&b&&(e.preventDefault(),e.stopPropagation(),C(),r.focus())};return a.addEventListener("keydown",A),s.addEventListener("keydown",A),s.addEventListener("pointerdown",e=>e.stopPropagation()),i.addEventListener("input",()=>{t.live&&y(i.value)}),i.addEventListener("change",()=>y(i.value)),w(),{el:a,input:i,trigger:r,read:()=>m,write:e=>{m=e,g=qe(e),f=g?.alpha??1,w()},destroy:()=>{v||(v=!0,C(),s.remove(),a.removeEventListener("keydown",A),s.removeEventListener("keydown",A))}}}const Ve="\n.oac-widget .oac-color { position: relative; display: inline-flex; width: 27px; height: 27px; flex: 0 0 27px; }\n.oac-widget .oac-color > .oac-swatch-input { position: absolute; inset: 0; width: 27px; height: 27px; padding: 0; opacity: 0; pointer-events: none; }\n.oac-widget .oac-color__trigger { position: absolute; inset: 0; width: 27px; height: 27px; border: 1px solid var(--oac-bd); border-radius: 5px; background: transparent; cursor: pointer; }\n.oac-widget .oac-color__trigger:focus-visible { outline: 2px solid var(--oac-ring); outline-offset: 2px; }\n.oac-widget .oac-color__trigger:disabled { cursor: not-allowed; opacity: .5; }\n.oac-widget .oac-color__popover { position: absolute; z-index: 80; top: 30px; right: 0; width: 188px; padding: 9px; border: 1px solid var(--oac-bd); border-radius: 7px; background: var(--oac-elev); color: var(--oac-tx); box-shadow: var(--oac-shadow); }\n.oac-widget .oac-color__popover--above { top: auto; bottom: 30px; }\n.oac-widget .oac-color__popover.oac-pop { right: auto; bottom: auto; min-width: 0; max-width: calc(100% - 16px); max-height: calc(100% - 16px); overflow: auto; }\n.oac-widget .oac-color__popover[hidden], .oac-widget .oac-color__recent[hidden] { display: none; }\n.oac-widget .oac-color__palette, .oac-widget .oac-color__recent { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; margin-bottom: 7px; }\n.oac-widget .oac-color__choice { width: 28px; height: 28px; padding: 0; border: 1px solid var(--oac-bd); border-radius: 5px; background: transparent; overflow: hidden; cursor: pointer; }\n.oac-widget .oac-color__custom { width: 100%; padding: 5px; border: 1px solid var(--oac-bd); border-radius: 4px; background: transparent; color: inherit; cursor: pointer; }\n.oac-widget .oac-color__opacity { display: flex; align-items: center; gap: 5px; margin-top: 7px; font-size: 11px; }\n.oac-widget .oac-color__range { min-width: 0; flex: 1; }\n.oac-widget .oac-color__percent { min-width: 30px; text-align: right; }\n";function He(e,t){if(null===e||"object"!=typeof e)return!0;const o=e;if(Array.isArray(o.all))return o.all.every(e=>He(e,t));if(Array.isArray(o.any))return o.any.some(e=>He(e,t));if("string"!=typeof o.key)return!0;const n=((e,t)=>Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0)(t,o.key),a=e=>(Array.isArray(e)?e:[e]).includes(n);return"is"in o?a(o.is):!("isNot"in o)||!a(o.isNot)}function Je(e,t=[]){if(null===e||"object"!=typeof e)return t;const o=e,n=Array.isArray(o.all)?o.all:Array.isArray(o.any)?o.any:null;if(null!==n)for(const e of n)Je(e,t);else"string"!=typeof o.key||t.includes(o.key)||t.push(o.key);return t}function Ze(e,t){const o=new Map;for(const t of e){const e=t.pair??t;for(const n of[e.enabled,e.up,e.down])"string"==typeof n?.key&&o.set(n.key,t)}for(const t of e)o.set(t.key,t);const n=new Map,a=new Set,i=e=>{const r=o.get(e);if(void 0===r||a.has(r))return;let s=n.get(r.key);if(void 0!==s)return s;a.add(r);const l=Je(r.activeWhen),c=He(r.visibleWhen,t)&&Je(r.visibleWhen).every(e=>!1!==i(e)?.visible),d=He(r.activeWhen,t)&&l.every(e=>{const t=i(e);return void 0===t||t.visible&&t.active});return a.delete(r),s={visible:c,active:d,dependsOn:l},n.set(r.key,s),s};for(const t of e)i(t.key);return n}const Ye=["1m","3m","5m","15m","30m","1h","2h","4h","1d","1w"];function Qe(e){const o=new Set,n=[{label:"Chart",value:""}];for(const a of e??[...Ye,...t.registeredIntervals().map(e=>e.code)]){const e=a.toLowerCase();o.has(e)||(o.add(e),n.push({label:a,value:a}))}return n}function Xe(e,o,n){const a=[];for(const o of e){const e=a.length;switch(o.type){case"colorPair":a.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":a.push({key:o.key,kind:"number",label:o.label,group:o.group,min:o.min,max:o.max,step:o.step});break;case"price":case"timestamp":a.push({key:o.key,kind:o.type,label:o.label,group:o.group,min:o.min,max:o.max,step:o.step});break;case"select":a.push({key:o.key,kind:"select",label:o.label,group:o.group,options:o.options});break;case"source":a.push({key:o.key,kind:"select",label:o.label,group:o.group,options:t.INDICATOR_SOURCES});break;case"interval":a.push({key:o.key,kind:"select",label:o.label,group:o.group,options:Qe(n)});break;case"time":a.push({key:o.key,kind:"text",label:o.label,group:o.group});break;case"boolean":case"color":case"text":case"symbol":case"session":case"multiline":a.push({key:o.key,kind:o.type,label:o.label,group:o.group})}if(a.length>e){const t=a[e];void 0!==o.tooltip&&(t.tooltip=o.tooltip),void 0!==o.activeWhen&&(t.activeWhen=o.activeWhen),void 0!==o.visibleWhen&&(t.visibleWhen=o.visibleWhen),"colorPair"!==o.type&&void 0!==o.inline&&(t.inline=o.inline)}}return et(a,o)}function et(e,t){if(void 0===t?.translate)return e;const o=(e,o)=>R(t,`schema.${t.scope}.${e}`,{},o);return e.map(e=>({...e,label:o(`${e.key}.label`,e.label),group:void 0===e.group?void 0:o(`group.${e.group}`,e.group),tooltip:void 0===e.tooltip?void 0:o(`${e.key}.tooltip`,e.tooltip),options:e.options?.map(t=>({...t,label:t.label===t.value?t.label:o(`${e.key}.option.${t.value}`,t.label)})),pair:void 0===e.pair?void 0:{...e.pair,up:{...e.pair.up,label:o(`${e.pair.up.key}.label`,e.pair.up.label)},down:{...e.pair.down,label:o(`${e.pair.down.key}.label`,e.pair.down.label)}}}))}const tt={line:"Line",fill:"Fill",text:"Text",levels:"Levels",behavior:"Behavior"};function ot(e,t){const o=[];for(const t of e){const e=void 0===t.group?void 0:tt[t.group]??t.group,n={key:t.path,label:t.label,group:e};switch(t.kind){case"color":o.push({...n,kind:"color"});break;case"number":o.push({...n,kind:"number",min:t.min,max:t.max,step:t.step});break;case"opacity":o.push({...n,kind:"opacity"});break;case"boolean":o.push({...n,kind:"boolean"});break;case"select":case"lineStyle":o.push(void 0===t.options?{...n,kind:"text"}:{...n,kind:"select",options:t.options});break;case"text":o.push({...n,kind:"text.value"===t.path?"multiline":"text"});break;case"levels":o.push({...n,kind:"custom",custom:"levels"})}}return et(o,t)}function nt(e,t,o,n){const a=u(e,t,o);return void 0!==n&&(a.textContent=n),a}function at(e,t){return p(e,o.chromeIconSvg(t),"chrome")}function it(e,t){const o=nt(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(at(e,t.icon)),!0===t.iconOnly?(o.setAttribute("aria-label",t.label),o.title=void 0===t.chord?t.label:`${t.label} (${t.chord})`):(o.appendChild(e.createTextNode(t.label)),void 0!==t.chord&&(o.title=t.chord)),void 0!==t.onClick){const e=t.onClick;o.addEventListener("click",t=>{t.stopPropagation(),e(t)})}return o}function rt(e){const t=nt(e,"span","oac-select"),n=nt(e,"select");t.appendChild(n);const a=nt(e,"span","oac-chev");return a.innerHTML=o.chromeIconSvg("chevron-down"),t.appendChild(a),{wrap:t,select:n}}function st(e){e.addEventListener("keydown",e=>{const t=e.key;"Escape"!==t&&"Tab"!==t&&e.stopPropagation()}),e.addEventListener("pointerdown",e=>{e.stopPropagation()})}let lt=0;function ct(e,t){const o=nt(e,"div","oac-panel"+(void 0===t.className?"":" "+t.className));o.setAttribute("role","dialog"),o.tabIndex=-1;const n="oac-dlg-title-"+ ++lt;o.setAttribute("aria-labelledby",n);const a=nt(e,"div","oac-dialog__head"),i=nt(e,"span","oac-dialog__title",t.title);i.id=n;const r=it(e,{label:R(t,"Close"),...!0===t.closeText?{}:{icon:"close",iconOnly:!0},onClick:()=>t.onClose()});a.appendChild(i),a.appendChild(r);const s=nt(e,"div","oac-dialog__body"),l=nt(e,"div","oac-dialog__foot"),c=nt(e,"div","oac-dialog__lead"),d=nt(e,"div","oac-spacer"),u=nt(e,"div","oac-dialog__actions");return l.appendChild(c),l.appendChild(d),l.appendChild(u),o.appendChild(a),o.appendChild(s),o.appendChild(l),st(o),{el:o,head:a,body:s,foot:l,lead:c,actions:u,closeButton:r,setTitle:e=>{i.textContent=e}}}function dt(e,t){return e.toast(t,"info"),{el:e.document.createElement("div"),close:()=>{},isOpen:()=>!1}}function ut(e,t,o,n){let a,i=!1,r=!1;const s=e.openOverlay(t,{...o,onClose:()=>{o.onClose?.(),i||(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&&(a=new o(e),a.observe(l))}function d(){i||(i=!0,a?.disconnect(),r||s(),t.remove())}return{el:t,close:d,isOpen:()=>!i}}function pt(e,t,o,n){const a=t.panes()[0]?.element.parentElement??null,i=null===a?{left:0,top:0}:w(e,a);let r=1/0,s=-1/0;for(const e of o){const o=(void 0!==n&&void 0!==e.id?n(e.id):null)??e.points.map(o=>({x:t.timeToCoordinate(o.time),y:t.priceToCoordinate(o.price,e.paneIndex)}));for(const{x:e,y:t}of o)Number.isFinite(e)&&null!==t&&Number.isFinite(t)&&(r=Math.min(r,e),s=Math.max(s,t))}return Number.isFinite(r)&&Number.isFinite(s)?{x:i.left+r,y:i.top+s+12}:{x:i.left+60,y:i.top+60}}function ht(e,t,o,n,a){const i=nt(e,"div",`oac-tabs oac-tabs--${n}`);i.setAttribute("role","tablist"),i.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),a(e)};return t.forEach((o,n)=>{const a=nt(e,"button","oac-tab");a.type="button",a.setAttribute("role","tab"),a.dataset.tab=o.id,void 0!==o.icon&&a.appendChild(at(e,o.icon)),a.appendChild(nt(e,"span","oac-tab__label",o.label)),a.addEventListener("click",e=>{e.stopPropagation(),l(o.id)}),a.addEventListener("keydown",e=>{const o=e.key,a="vertical"===i.getAttribute("aria-orientation"),s=a?"ArrowUp":"ArrowLeft";let c=-1;o===(a?"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(a),i.appendChild(a)}),s(o),{el:i,setActive:s}}function mt(e,t,o){const n=e.getBoundingClientRect(),a=t.offsetWidth||200,i=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+i>n.height-4&&(s=Math.max(4,e.top-n.top-i-6))}else void 0!==o.point&&(r=o.point.x,s=o.point.y,s+i>n.height-4&&(s=Math.max(4,n.height-i-4)));r=Math.max(4,Math.min(r,n.width-a-4)),s=Math.max(4,Math.min(s,n.height-i-4)),t.style.left=`${Math.round(r)}px`,t.style.top=`${Math.round(s)}px`}const gt=new WeakMap;function ft(e,o,n){gt.get(e)?.();let a=!1;const i=[],r=e.ownerDocument;e.innerHTML="",e.classList.add("oac-form");const s=[],l=[],c=n.unavailable??(()=>null),d=e=>`${n.idPrefix}-${e.replace(/[^A-Za-z0-9_-]/g,"-")}`,u=new Map,p=new Map,h=new Map,m={...n.values},g=(e,t)=>{Object.defineProperty(m,e,{value:t,writable:!0,enumerable:!0,configurable:!0})},f=o.some(e=>void 0!==e.activeWhen||void 0!==e.visibleWhen);let b,v=null;const w=e=>p.has(e)&&!1!==h.get(e)?.member?.shown,y=(e,t)=>{const o=h.get(e);null===t?p.delete(e):(p.set(e,t),u.delete(e)),o&&(o.control.setAttribute("aria-invalid",String(null!==t)),o.error.textContent=t??"",o.error.hidden=!w(e))},_=(e,a)=>{const i=o.find(t=>t.key===e);if("price"===i?.kind||"timestamp"===i?.kind){if("number"!=typeof a||!Number.isFinite(a))return R(n,"Enter a finite number");if(void 0!==i.min&&a<i.min)return R(n,"Minimum: {value}",{value:i.min});if(void 0!==i.max&&a>i.max)return R(n,"Maximum: {value}",{value:i.max})}return"session"!==i?.kind||"string"==typeof a&&null!==t.parseSessionSpec(a)?null:R(n,"Use HHMM-HHMM with optional :days (1 to 7)")},x=(e,t)=>{if(a)return;const o=_(e,t);if(y(e,o),!(null!==o||u.has(e)&&Object.is(u.get(e),t))){u.set(e,t),g(e,t),b=e;try{n.onChange(e,t)}finally{b=void 0}a||M(e)}};function k(e,t,o,a){const s=e=>e??"";let l,p;switch(t){case"price":case"timestamp":{const t=nt(r,"input","oac-input--num");t.type="text",t.inputMode="decimal",void 0!==o.min&&(t.min=String(o.min)),void 0!==o.max&&(t.max=String(o.max)),void 0!==o.step&&(t.step=String(o.step));const n=e=>{t.value="number"==typeof e?String(e):""},i=()=>""===t.value.trim()?void 0:Number(t.value);n(a),t.addEventListener("change",()=>x(e,i())),l=t,p={key:e,control:t,read:i,write:n,title:s};break}case"boolean":{const t=nt(r,"input");t.type="checkbox",t.checked=!0===a,t.addEventListener("change",()=>x(e,t.checked)),l=t,p={key:e,control:t,read:()=>t.checked,write:e=>{t.checked=!0===e},title:s};break}case"number":{const t=nt(r,"input","oac-input--num");t.type="number",void 0!==o.min&&(t.min=String(o.min)),void 0!==o.max&&(t.max=String(o.max)),void 0!==o.step&&(t.step=String(o.step));const i=e=>{var o;t.value="number"==typeof e&&Number.isFinite(e)?(o=e,Number.isInteger(o)?String(o):String(Math.round(1e3*o)/1e3)):""};i(a),t.addEventListener("change",()=>{const r=t.value.trim(),s=""===r?NaN:Number(r);if(!Number.isFinite(s))return void(n.preserveInvalidNumbers?x(e,void 0):i(u.has(e)?u.get(e):a));const l=o.min??-1/0,c=o.max??1/0,d=Math.min(c,Math.max(l,s));d!==s&&i(d),x(e,d)}),l=t,p={key:e,control:t,read:()=>{const e=Number(t.value);return""!==t.value.trim()&&Number.isFinite(e)?e:void 0},write:i,title:s};break}case"color":{const t=Ge(r,{id:d(e),label:o.label,value:a,live:n.live,translate:n.translate,openOverlay:n.openOverlay,onChange:t=>x(e,t)});return i.push(t.destroy),l=t.el,p={key:e,control:t.input,focus:t.trigger,read:t.read,write:t.write,title:e=>e??o.label},{ctl:l,b:p}}case"opacity":{const t=nt(r,"input","oac-range");t.type="range",t.min="0",t.max="100",t.step="1";const o=nt(r,"output","oac-out"),i=e=>Math.round(100*("number"==typeof e?Math.min(1,Math.max(0,e)):0)),c=e=>{t.value=String(i(e)),o.textContent=`${i(e)}%`};c(a),t.addEventListener("input",()=>{o.textContent=`${t.value}%`,!0===n.live&&x(e,Number(t.value)/100)}),t.addEventListener("change",()=>x(e,Number(t.value)/100));const d=nt(r,"span","oac-opacity");return d.appendChild(t),d.appendChild(o),l=d,p={key:e,control:t,read:()=>Number(t.value)/100,write:c,title:s},{ctl:l,b:p}}case"select":{const{wrap:t,select:i}=rt(r),d=o.options??[],u=t=>{i.innerHTML="";const o=d.slice(),a="string"==typeof t?t:void 0===t?void 0:String(t);void 0===a||""===a||o.some(e=>e.value===a)||o.push({value:a,label:R(n,"Custom")});for(const t of o){const o=nt(r,"option",void 0,t.label);o.value=t.value;const n=c(e,t.value);null!==n&&(o.disabled=!0,o.title=n),i.appendChild(o)}i.value=void 0===a||""===a?o[0]?.value??"":a};return u(a),i.addEventListener("change",()=>x(e,i.value)),l=t,p={key:e,control:i,read:()=>i.value,write:u,title:s},{ctl:l,b:p}}case"multiline":{const t=nt(r,"textarea","oac-input--multi");t.rows=3,t.setAttribute("spellcheck","false");const o=e=>{t.value=null==e?"":String(e)};o(a),t.addEventListener("change",()=>x(e,t.value)),l=t,p={key:e,control:t,read:()=>t.value,write:o,title:s};break}default:{const t=nt(r,"input");t.type="text",t.setAttribute("spellcheck","false");const o=e=>{t.value=null==e?"":String(e)};o(a),t.addEventListener("change",()=>x(e,t.value)),l=t,p={key:e,control:t,read:()=>t.value,write:o,title:s};break}}return{ctl:l,b:p}}const C=(e,t)=>{const o=nt(r,"label",t,"timestamp"===e.kind?R(n,"{label} (UTC seconds)",{label:e.label}):e.label);if(void 0!==e.tooltip&&""!==e.tooltip){const t=nt(r,"span","oac-help","?");t.title=e.tooltip,t.setAttribute("aria-hidden","true"),o.appendChild(t)}return o},S=(e,t,o)=>{e.htmlFor=t.id,void 0!==o.tooltip&&""!==o.tooltip&&t.setAttribute("aria-description",o.tooltip)},A=(e,t,o,n,a)=>{const i={control:e,fields:n,parts:a,offKeys:n.map(e=>e.key),offEl:t,offClass:"oac-row--off",titles:[t],row:t,head:o,shown:!0,enabled:!0};for(const e of n)e.member=i;return l.push(i),i},T=(e,t,o)=>{const n=nt(r,"div","oac-input-error");return n.id=`${d(e)}-error`,n.hidden=!0,n.setAttribute("role","status"),t.control.setAttribute("aria-describedby",n.id),o.appendChild(n),h.set(e,{control:t.control,error:n}),n},E=e=>void 0!==e.inline&&"custom"!==e.kind&&"colorPair"!==e.kind&&"multiline"!==e.kind;let L,O,I=e,P=null;for(const t of o){if(void 0!==t.group&&t.group!==L&&(O=nt(r,"div","oac-head",t.group),e.appendChild(O),O.id=d(`group-${l.length}`),I=nt(r,"div","oac-form__group"),I.setAttribute("role","group"),I.setAttribute("aria-labelledby",O.id),e.appendChild(I),P=null),L=t.group??L,null===P||E(t)&&t.inline===P.id||(P=null),null!==P){const e=k(t.key,t.kind,t,n.values[t.key]);e.b.control.id=d(t.key);const o=C(t,"oac-inline__label");S(o,e.b.focus??e.b.control,t),s.push(e.b);const a=nt(r,"span","oac-inline__item");a.dataset.key=t.key,"boolean"===t.kind?(a.appendChild(e.ctl),a.appendChild(o)):(a.appendChild(o),a.appendChild(e.ctl)),P.ctl.appendChild(a),T(t.key,e.b,P.row);const i=A(t,P.row,O,[e.b],[a]);i.offEl=a,i.offClass="oac-inline__item--off",i.titles=[a],h.get(t.key).member=i;continue}const o=nt(r,"div","oac-row");o.dataset.key=t.key;const a=C(t,"oac-row__label");if("custom"===t.kind){const e=void 0===n.custom?null:n.custom(t,o);if(null===e)continue;o.appendChild(nt(r,"span","oac-row__sw")),o.appendChild(a);const i=nt(r,"div","oac-row__ctl");i.appendChild(e),o.appendChild(i),I.appendChild(o),A(t,o,O,[],[o]).offEl=null;continue}if("colorPair"===t.kind&&void 0!==t.pair){const e=t.pair,i=[];if(void 0!==e.enabled){const r=k(e.enabled.key,"boolean",t,n.values[e.enabled.key]);r.ctl.classList.add("oac-row__sw"),r.ctl.id=d(e.enabled.key),S(a,r.ctl,t),s.push(r.b),i.push(r.b),o.appendChild(r.ctl)}else o.appendChild(nt(r,"span","oac-row__sw"));o.appendChild(a);const l=nt(r,"div","oac-row__ctl");let c;for(const o of[e.up,e.down]){const e=k(o.key,"color",t,n.values[o.key]);c??(c=e.b.focus??e.b.control),e.b.control.id=d(o.key),e.b.title=e=>null===e?o.label:`${o.label}: ${e}`,e.b.control.setAttribute("aria-label",`${t.label} ${o.label}`),e.b.focus?.setAttribute("aria-label",`${t.label} ${o.label}`),s.push(e.b),i.push(e.b),l.appendChild(e.ctl)}void 0===e.enabled&&void 0!==c&&S(a,c,t),o.appendChild(l),I.appendChild(o),A(t,o,O,i,[o]).offKeys=[e.up.key,e.down.key];continue}const i=k(t.key,t.kind,t,n.values[t.key]);i.b.control.id=d(t.key),S(a,i.b.focus??i.b.control,t),s.push(i.b);let c=[o],u=[o];if("boolean"===t.kind)i.ctl.classList.add("oac-row__sw"),o.appendChild(i.ctl),o.appendChild(a),E(t)&&(o.appendChild(nt(r,"div","oac-row__ctl")),c=[i.ctl,a],u=[a]);else if("multiline"===t.kind)o.classList.add("oac-row--block"),o.appendChild(a),o.appendChild(i.ctl);else{o.appendChild(nt(r,"span","oac-row__sw")),o.appendChild(a);const e=nt(r,"div","oac-row__ctl");if(E(t)){const o=nt(r,"span","oac-inline__item");o.dataset.key=t.key,o.appendChild(i.ctl),e.appendChild(o),c=[a,o],u=[a,o]}else e.appendChild(i.ctl);o.appendChild(e)}E(t)&&(o.classList.add("oac-row--inline"),o.dataset.inline=t.inline,P={id:t.inline,row:o,ctl:o.lastChild}),T(t.key,i.b,o),I.appendChild(o);const p=A(t,o,O,[i.b],c);p.titles=u,h.get(t.key).member=p}f&&(v=nt(r,"div","oac-sr"),v.setAttribute("role","status"),v.setAttribute("aria-live","polite"),e.appendChild(v));const $=e=>o.find(t=>t.key===e||[t.pair?.enabled,t.pair?.up,t.pair?.down].some(t=>t?.key===e))?.label,j=e=>!1!==e.member?.shown&&!e.control.disabled,D=()=>{if(a)return!1;for(const e of s)if(j(e))return(e.focus??e.control).focus(),!0;return!1};function M(t=b,a=!0){const i=r.activeElement,d=f?Ze(o,m):null,u={shown:[],hidden:[],on:[],off:[]};for(const e of l){const t=d?.get(e.control.key),o=t?.visible??!0;let a=null;if(void 0!==t&&!t.active){const e=t.dependsOn.map($).filter(e=>void 0!==e);a=e.length>0?R(n,"Depends on {inputs}",{inputs:e.join(", ")}):R(n,"Not used with the current settings")}for(const t of e.parts)t.hidden=!o;const i=new Map;for(const t of e.fields){const e=c(t.key)??a;i.set(t.key,e);for(const o of[t.control,t.focus])void 0!==o&&(o.disabled=null!==e,o.title=t.title(e))}const r=e.fields.length>0&&e.offKeys.every(e=>null!==i.get(e));if(null!==e.offEl){e.offEl.classList.toggle(e.offClass,r);const t=i.get(e.offKeys[0])??null;for(const o of e.titles)o.title=r?t??"":""}const s=e.control.label;e.shown!==o?u[o?"shown":"hidden"].push(s):o&&e.enabled===r&&u[r?"off":"on"].push(s),e.shown=o,e.enabled=!r}for(const e of[e=>e.row,e=>e.head]){const t=new Map;for(const o of l){const n=e(o);void 0!==n&&t.set(n,(t.get(n)??!1)||o.shown)}for(const[e,o]of t)e.hidden=!o}for(const[e,t]of h)t.error.hidden=!w(e);if(null!==i&&e.contains(i)&&(l.some(e=>!e.shown&&e.parts.some(e=>e.contains(i)))||i.disabled)){const e=void 0===t?void 0:s.find(e=>e.key===t);void 0!==e&&j(e)?(e.focus??e.control).focus():D()}if(!a||null===v)return;const p=[];if(u.shown.length>0&&p.push(R(n,"Shown: {inputs}",{inputs:u.shown.join(", ")})),u.hidden.length>0&&p.push(R(n,"Hidden: {inputs}",{inputs:u.hidden.join(", ")})),u.on.length>0&&p.push(R(n,"Available: {inputs}",{inputs:u.on.join(", ")})),u.off.length>0&&p.push(R(n,"Unavailable: {inputs}",{inputs:u.off.join(", ")})),0===p.length)return;const g=p.join(". ");v.textContent=v.textContent===g?`${g} `:g}M(void 0,!1);const z=()=>{if(!a){a=!0;for(const e of i.splice(0))e();gt.get(e)===z&&gt.delete(e)}};return gt.set(e,z),{el:e,destroy:z,setError:y,validate:()=>{const e=new Set(s.filter(e=>!j(e)).map(e=>e.key));for(const t of s){if(e.has(t.key))continue;const o=_(t.key,t.read());null===o&&p.has(t.key)||y(t.key,o)}return[...p.keys()].every(t=>e.has(t))},sync:e=>{if(a)return;for(const t of Object.keys(e))g(t,e[t]);const t=r.activeElement;for(const o of s)o.control!==t&&(p.has(o.key)||o.key in e&&(o.write(e[o.key]),u.has(o.key)&&u.set(o.key,o.read())));M()},values:()=>{const e={};for(const t of s)e[t.key]=t.read();return e},focusFirst:D}}const bt=e=>void 0!==e&&void 0!==o.chromeIcon(e)?o.chromeIconSvg(e):'<svg aria-hidden="true"></svg>';function vt(e,t,o,n={}){const a=e.document,i=u(a,"div","oac-menu",{role:"menu"});n.ariaLabel&&i.setAttribute("aria-label",n.ariaLabel);let r=null;if(n.find){const e=u(a,"div","oac-menu__find");r=u(a,"input",void 0,{type:"text",placeholder:n.find,"aria-label":n.find}),e.appendChild(r),i.appendChild(e)}const s=u(a,"div","oac-menu__body");i.appendChild(s);let l=()=>{};const c=o.some(e=>"string"!=typeof e&&void 0!==e.icon),d=t=>{const n=t.trim().toLowerCase();s.textContent="";let i=0,r=null;for(const e of o){if("string"==typeof e){r=e;continue}if(""!==n&&!e.label.toLowerCase().includes(n)&&!(e.sub??"").toLowerCase().includes(n))continue;if(null!==r){const e=u(a,"div","oac-head");e.textContent=r,s.appendChild(e),r=null}const t=u(a,"button","oac-menu__row"+(e.danger?" is-danger":""),{type:"button",role:void 0===e.on?"menuitem":"menuitemradio","aria-disabled":String(!0===e.disabled)});void 0!==e.on&&t.setAttribute("aria-checked",String(e.on)),c&&t.appendChild(p(a,bt(e.icon),"chrome"));const o=u(a,"span","oac-menu__label");if(o.textContent=e.label,t.appendChild(o),e.sub){const o=u(a,"span","oac-menu__sub");o.textContent=e.sub,t.appendChild(o)}if(e.key){const o=u(a,"kbd","oac-menu__key",{"aria-hidden":"true"});o.textContent=e.key,t.appendChild(o),t.setAttribute("aria-keyshortcuts",Me(e.key))}t.addEventListener("click",t=>{t.stopPropagation(),e.disabled||(l(),e.onSelect())}),s.appendChild(t),i++}if(0===i){const t=u(a,"div","oac-menu__empty");t.textContent=R(e,"No match"),s.appendChild(t)}};if(d(""),null!==r){const e=r;e.addEventListener("input",()=>d(e.value)),e.addEventListener("keydown",e=>{if("Enter"!==e.key)return;e.preventDefault();const t=s.querySelectorAll(".oac-menu__row");1===t.length&&t[0].click()})}return i.addEventListener("keydown",e=>{const t=e,o=Array.from(s.querySelectorAll(".oac-menu__row")),n=o.indexOf(a.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(i,{anchor:t,placement:n.placement??"below",edge:n.edge,initialFocus:r??s.querySelector('.oac-menu__row[aria-checked="true"]')??void 0}),l}function wt(e,t,o,n){const a=globalThis;if(void 0===a.Blob||void 0===a.URL||"function"!=typeof a.URL.createObjectURL)return!1;const i=e.createElement("a"),r=a.URL.createObjectURL(new a.Blob([o],{type:n}));try{i.href=r,i.download=t,(e.body??e.documentElement).appendChild(i),i.click()}finally{i.remove(),setTimeout(()=>a.URL?.revokeObjectURL(r),0)}return!0}function yt(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 _t(e,t){const{draw:o}=e,n=T(o,t),a=n.map(e=>o.get(e)).filter(e=>void 0!==e),i=a.filter(e=>!0===e.locked).length,r=new Set(t.map(e=>o.get(e)).filter(e=>void 0!==e).map(t=>void 0!==t.stackAbove&&e.chart.seriesStack(t.paneIndex).includes(t.stackAbove)?null:t.zIndex<0?"behind":"above")),[s]=r;return{editable:n,locked:a.length>0&&i===a.length,partlyLocked:i>0&&i<a.length,hidden:a.length>0&&a.every(e=>!1===e.visible),side:1===r.size&&void 0!==s?s:null}}function xt(e,t){const o=_t(e,t),n=t.length>0&&0===o.editable.length?R(e,"read-only"):null;return{...o,readOnly:n,noDelete:n??(o.locked?R(e,"locked"):null)}}function kt(e,t,o){const{draw:n}=e,a=_t(e,o);("delete"!==t||0!==a.editable.length&&!a.locked)&&O(e,t,()=>{switch(t){case"lock":n.updateMany(a.editable.map(e=>({id:e,patch:{locked:!a.locked}})));break;case"visible":n.updateMany(a.editable.map(e=>({id:e,patch:{visible:a.hidden}})));break;case"front":for(const e of o)n.bringToFront(e);break;case"back":for(const e of o)n.sendToBack(e);break;case"above":for(const e of o)n.bringAboveSeries(e);break;case"behind":for(const e of o)n.sendBehindSeries(e);break;case"duplicate":n.duplicate(o);break;case"delete":n.removeMany(a.editable)}})}const Ct=["off","weak","strong"],St=[{id:"lines",title:"Lines",items:[{head:"Lines"},{tool:"trend-line"},{tool:"ray"},{tool:"extended-line"},{tool:"arrow"},{tool:"info-line"},{tool:"trend-angle"},{head:"Horizontal and vertical"},{tool:"horizontal-line"},{tool:"horizontal-ray"},{tool:"vertical-line"},{tool:"cross-line"}]},{id:"channels",title:"Channels",items:[{head:"Channels"},{tool:"parallel-channel"},{tool:"fib-channel"},{tool:"disjoint-channel"},{tool:"flat-top-bottom"},{tool:"regression-channel"},{head:"Pitchforks"},{tool:"pitchfork"},{tool:"schiff-pitchfork"},{tool:"modified-schiff-pitchfork"},{tool:"inside-pitchfork"}]},{id:"fib",title:"Fibonacci and Gann",items:[{head:"Fibonacci"},{tool:"fib-retracement"},{tool:"fib-extension"},{tool:"fib-time-zone"},{tool:"fib-fan"},{tool:"fib-extension-two-point"},{tool:"fib-speed-resistance-fan"},{tool:"trend-fib-time"},{tool:"fib-circles"},{tool:"fib-speed-resistance-arcs"},{tool:"fib-wedge"},{tool:"fib-spiral"},{head:"Gann"},{tool:"gann-fan"},{tool:"gann-box"},{tool:"gann-square"}]},{sep:!0},{id:"shapes",title:"Shapes",items:[{head:"Shapes"},{tool:"rectangle"},{tool:"rotated-rectangle"},{tool:"ellipse"},{tool:"circle"},{tool:"triangle"},{head:"Paths"},{tool:"path"},{tool:"polyline"},{tool:"arc"},{tool:"curve"},{tool:"double-curve"}]},{id:"cycles",title:"Cycles",items:[{head:"Cycles"},{tool:"cyclic-lines"},{tool:"time-cycles"},{tool:"sine-line"}]},{id:"patterns",title:"Patterns",items:[{head:"Patterns and waves"},{tool:"xabcd-pattern"},{tool:"abcd-pattern"},{tool:"head-shoulders"},{tool:"elliott-impulse"},{tool:"elliott-correction"},{head:"Harmonic patterns"},{tool:"gartley"},{tool:"bat"},{tool:"butterfly"},{tool:"crab"},{tool:"shark"},{tool:"cypher"}]},{id:"geometry",title:"Geometric studies",items:[{head:"Geometric studies"},{tool:"sonic"},{tool:"supersonic"},{tool:"golden-sonic"},{tool:"golden-supersonic"},{tool:"dedekind-tessellation"}]},{id:"marks",title:"Arrows and marks",items:[{head:"Arrows"},{tool:"arrow-up"},{tool:"arrow-down"},{tool:"arrow-left"},{tool:"arrow-right"},{head:"Marks"},{tool:"flag-mark"},{tool:"icon-stamp"},{tool:"price-label"},{tool:"signpost"}]},{sep:!0},{id:"forecast",title:"Forecasting",items:[{head:"Forecasting"},{tool:"long-position"},{tool:"short-position"},{tool:"forecast"}]},{id:"analysis",title:"Volume studies",items:[{head:"Volume studies"},{tool:"anchored-vwap"},{tool:"fixed-range-volume-profile"}]},{id:"measure",title:"Measurers",items:[{head:"Measurers"},{tool:"price-range"},{tool:"date-range"},{tool:"measure"}]},{sep:!0},{id:"text",title:"Text and notes",items:[{head:"Text and notes"},{tool:"text"},{tool:"note"},{tool:"callout"},{tool:"balloon"},{tool:"comment"},{tool:"price-note"},{tool:"table"},{head:"Brushes"},{tool:"brush"},{tool:"highlighter"}]}],At=e=>(null===e?null:E(e))?.name??String(e??"Cursor"),Tt="rail",Et="oac-rail-sprite";function Lt(e,t){if(void 0!==o.DRAWING_TOOL_ICONS[t])return p(e,o.iconUse(t),"tool");const n=u(e,"span","oac-glyph oac-glyph--text",{"aria-hidden":"true"});return n.textContent=String(t).charAt(0).toUpperCase(),n}function Ot(e,t,n){const a={favorites:[],magnet:"off",stay:!1,last:{}};if(null===e||"object"!=typeof e)return a;const i=e;if(Array.isArray(i.favorites)&&(a.favorites=i.favorites.filter((e,t,n)=>"string"==typeof e&&o.hasDrawingTool(e)&&n.indexOf(e)===t)),"string"==typeof i.magnet&&Ct.includes(i.magnet)&&(a.magnet=i.magnet),a.stay=!0===i.stay,!0===i.collapsed&&(a.collapsed=!0),null!==i.last&&"object"==typeof i.last){const e=i.last;for(const o of t)void 0!==o.id&&"string"==typeof e[o.id]&&n(o).includes(e[o.id])&&(a.last[o.id]=e[o.id])}return a}function It(e,t,n={}){const a=e.document,i=t=>R(e,`schema.drawing.${t??"cursor"}.name`,{},At(t)),r=e.draw,s=e.chart;!function(e){if(null!==e.getElementById(Et))return;const t=e.createElement("div");t.id=Et,t.hidden=!0,t.innerHTML=o.iconSprite(),(e.body??e.documentElement).appendChild(t)}(a);const l=void 0===n.tools?null:new Set(n.tools),c=e=>(e.items??[]).filter(e=>void 0!==e.tool&&o.hasDrawingTool(e.tool)&&(null===l||l.has(e.tool))).map(e=>e.tool),d=e=>St.find(t=>t.id===e);let p=Ot(e.storage.get(Tt),St,c);null===e.storage.get(Tt)&&n.favorites&&(p.favorites=n.favorites.filter((e,t,n)=>o.hasDrawingTool(e)&&n.indexOf(e)===t));let h=!1;const m=()=>{e.storage.set(Tt,p)},g=e=>p.last[e.id??""]??c(e)[0]??null;let f=null;const b=(t,o)=>ze(e.keymap,t,o),v=e=>{if(null!==e)return null===f&&(f=o.drawingShortcuts()),b(`tool:${e}`,f[e])},w=()=>r.selection().slice(),y=t=>xt(e,t),_=e=>{const t=n.cursorTarget;t&&(null!==e&&void 0!==o.DRAWING_TOOL_ICONS[e]?t.style.setProperty("--oac-tool-cursor",o.toolCursor(e)):t.style.removeProperty("--oac-tool-cursor"))},x=()=>{r.setOptions({magnet:p.magnet})},k=()=>{r.setOptions({stayInDrawingMode:p.stay||h})},C=e=>{if(!Ct.includes(e))throw new Error(`openalgo-charts widget: unknown magnet mode "${String(e)}"`);p.magnet=e,m(),x(),V()},S=()=>{const t=Ct[(Ct.indexOf(p.magnet)+1)%Ct.length];return C(t),e.status(R(e,"off"===t?"Magnet off":"weak"===t?"Magnet weak: snaps when a bar or study value is within a few pixels":"Magnet strong: every anchor lands on the nearest bar or study value")),t},A=t=>{p.stay=!0===t,m(),k(),V(),e.status(p.stay?R(e,"Tools stay active after each drawing"):R(e,"One drawing per pick"))},E=e=>{h=!0===e,k(),te(r.activeTool())},O=e=>{r.setTool(e),te(e)},P=t=>{E(!0),O(t),e.status(R(e,"{name} stays active until Escape",{name:i(t)}))};t.classList.add("oac-rail"),t.setAttribute("role","toolbar"),t.setAttribute("aria-orientation","vertical"),t.setAttribute("aria-label",R(e,"Drawing tools"));const $=t=>{const o=u(a,"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},j=(e,t)=>{const o=e.querySelector(".oac-glyph");o?o.replaceWith(t):e.insertBefore(t,e.firstChild)},D=()=>u(a,"div","oac-rail__sep",{role:"separator"}),M=t=>{const o=$({cls:"oac-rail__tool oac-rail__fav",glyphEl:Lt(a,t),tip:()=>({title:R(e,"{name} (pinned)",{name:i(t)}),chord:v(t),sub:R(e,"Pinned. Right-click to unpin"),side:"right"}),onClick:e=>{e.detail>=2&&!p.stay?P(t):(E(!1),O(t))},onContext:()=>B(o,[{label:R(e,"Unpin from rail"),icon:"star",onSelect:()=>Y(t,!1)}])});return o.dataset.tools=t,o},z=t=>{const n=c(t);let s=!1;const l=$({cls:"oac-rail__tool oac-rail__group",glyphEl:Lt(a,g(t)??n[0]),tip:()=>({title:i(g(t)),chord:v(g(t)),sub:R(e,p.stay?"{group}: chevron for the rest":"{group}: chevron for the rest. Double-click keeps it active",{group:void 0===t.title?"":R(e,`schema.rail.${t.id}.title`,{},t.title)}),side:"right"}),onClick:e=>{const o=s&&0!==e.detail;if(s=!1,null===N||"true"!==l.getAttribute("aria-expanded"))if(o)W(t,l,!1);else{if(e.detail>=2&&!p.stay){const e=g(t);return void(null!==e&&P(e))}r.activeTool()!==g(t)?(E(!1),O(g(t))):W(t,l,!1)}else F()},onContext:()=>W(t,l,!1)});l.addEventListener("pointerdown",e=>{const t=e.target;s="touch"!==e.pointerType&&"function"==typeof t?.closest&&null!==t.closest(".oac-rail__chev")}),l.dataset.tools=n.join(","),l.dataset.group=t.id??"",l.dataset.face=g(t)??"",l.setAttribute("aria-haspopup","menu"),l.setAttribute("aria-expanded","false");const d=u(a,"span","oac-rail__chev",{"aria-hidden":"true"});return d.innerHTML=o.chromeIconSvg("chevron-right"),l.appendChild(d),l};let N=null;const F=()=>{N?.close()},W=(n,s,c)=>{F(),e.tips.hide();const d=u(a,"div","oac-fly",{role:"menu","aria-label":void 0===n.title?R(e,"Tools"):R(e,`schema.rail.${n.id}.title`,{},n.title)}),h=r.activeTool(),g=[];for(const t of n.items??[]){if(void 0!==t.head){const o=u(a,"div","oac-head");o.textContent=R(e,`schema.rail.${n.id}.group.${t.head}`,{},t.head),d.appendChild(o);continue}const r=t.tool;if(void 0===r||!o.hasDrawingTool(r)||null!==l&&!l.has(r))continue;const c=u(a,"div","oac-fly__row",{role:"menuitemradio","aria-checked":String(h===r)});c.tabIndex=-1,c.dataset.tool=r,c.appendChild(Lt(a,r));const p=u(a,"span","oac-fly__name");p.textContent=i(r),c.appendChild(p);const m=J(r),b=u(a,"button","oac-fly__star",{type:"button","aria-pressed":String(m),"aria-label":R(e,"Pin to rail")});b.tabIndex=-1,b.innerHTML=o.chromeIconSvg(m?"star-filled":"star"),c.appendChild(b);const w=u(a,"kbd","oac-fly__chord");w.textContent=v(r)??"",c.appendChild(w);const y=()=>{const e=!J(r);Y(r,e),b.setAttribute("aria-pressed",String(e)),b.innerHTML=o.chromeIconSvg(e?"star-filled":"star")};b.addEventListener("click",e=>{e.stopPropagation(),y()}),c.addEventListener("click",e=>{e.stopPropagation(),f(r)}),c.addEventListener("keydown",e=>{const t=e;"Enter"!==t.key&&" "!==t.key||(t.preventDefault(),t.stopPropagation(),null!==t.target.closest(".oac-fly__star")?y():(f(r),s.focus()))}),g.push(c),d.appendChild(c)}const f=e=>{void 0!==n.id&&(p.last[n.id]=e,m()),F(),E(!1),O(e)};d.addEventListener("keydown",e=>{const t=e,o=t.target.closest(".oac-fly__row"),n=null===o?-1:g.indexOf(o),a=e=>{g[(e+g.length)%g.length]?.focus()};switch(t.key){case"ArrowDown":a(n+1);break;case"ArrowUp":a(n-1);break;case"Home":a(0);break;case"End":a(g.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=g.find(e=>"true"===e.getAttribute("aria-checked"))??g[0]??null,w=e.openOverlay(d,{anchor:s,placement:"beside",edge:t,initialFocus:c?b:d,onClose:()=>{null!==N&&N.el===d&&(N=null)}});N={el:d,close:w}},B=(o,n)=>{e.tips.hide(),vt(e,o,n,{placement:"beside",edge:t})},U={},q=function(e,t,n){const a=e.document,i=u(a,"button","oac-rail-tab",{type:"button"});i.innerHTML=o.chromeIconSvg("chevrons-right"),i.hidden=!0,e.tips.attach(i,()=>({title:R(e,"Show drawing tools"),side:"right"}),600),i.addEventListener("pointerdown",e=>{e.stopPropagation()}),t.parentNode?.insertBefore(i,t.nextSibling);const r=()=>{const o=n.folded();t.classList.toggle("is-collapsed",o),i.hidden=!o,e.tips.refreshLabel(i)},s=o=>{const s=!0===o;if(n.folded()===s)return;const l=s?t.contains(a.activeElement):a.activeElement===i;s&&e.tips.hide(),n.store(s),r(),l&&(s?i:n.unfoldTarget())?.focus()};return i.addEventListener("click",()=>{s(!1)}),{apply:r,set:s,destroy:()=>{t.classList.remove("is-collapsed"),i.remove()}}}(e,t,{folded:()=>!0===p.collapsed,store:e=>{e?(F(),p.collapsed=!0):delete p.collapsed,m()},unfoldTarget:()=>U.collapse}),K=q.set,G=(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,j(e,at(a,t.glyph))))},V=()=>{if(void 0===U.magnet)return;G(U.magnet,{on:"strong"===p.magnet,pressed:"off"!==p.magnet}),U.magnet.classList.toggle("is-weak","weak"===p.magnet),U.magnet.dataset.mode=p.magnet,G(U.stay,{on:p.stay,pressed:p.stay});const t=y(w()),o=0===t.editable.length;G(U.lock,{off:o,on:t.locked,pressed:t.locked,glyph:t.locked?"lock":"unlock"}),G(U.eye,{off:o,on:t.hidden,pressed:t.hidden,glyph:t.hidden?"eye-off":"eye"}),G(U.trash,{off:null!==t.noDelete||o}),G(U.undo,{off:!I(e,"undo")}),G(U.redo,{off:!I(e,"redo")});for(const t of Object.values(U))e.tips.refreshLabel(t)};let H=null;const J=e=>p.favorites.includes(e),Z=()=>{if(null===H)return;H.textContent="";const e=p.favorites.filter(e=>o.hasDrawingTool(e));if(0!==e.length){H.appendChild(D());for(const t of e)H.appendChild(M(t))}},Y=(e,t=!J(e))=>{if(!o.hasDrawingTool(e))return;const n=J(e);t&&!n&&p.favorites.push(e),!t&&n&&p.favorites.splice(p.favorites.indexOf(e),1),m(),Z(),te(r.activeTool())},Q=()=>Array.from(t.querySelectorAll(".oac-rail__btn")),X=e=>{for(const t of Q())t.tabIndex=t===e?0:-1},ee=()=>{t.textContent="",t.appendChild((()=>{const t=$({cls:"oac-rail__tool",glyphEl:Lt(a,"cursor"),tip:()=>({title:R(e,"Cursor"),chord:"Esc",side:"right"}),onClick:()=>{E(!1),O(null)}});return t.dataset.tools="",t})()),H=u(a,"div","oac-rail__favs"),t.appendChild(H),Z(),t.appendChild(D());for(const e of St)e.sep?t.appendChild(D()):c(e).length>0&&t.appendChild(z(e));t.appendChild((()=>{const t=u(a,"div","oac-rail__ctl");return U.magnet=$({cls:"oac-rail__btn--chrome oac-rail__btn--magnet",glyphEl:at(a,"magnet"),tip:()=>({title:R(e,"Magnet: {mode}",{mode:R(e,`schema.magnet.${p.magnet}`,{},p.magnet)}),sub:"off"===p.magnet?R(e,"Click for weak: snaps when a bar or study value is within a few pixels"):"weak"===p.magnet?R(e,"Click for strong: every anchor lands on the nearest bar or study value"):R(e,"Click to switch the magnet off"),side:"right"}),onClick:()=>{S()}}),t.appendChild(U.magnet),U.stay=$({cls:"oac-rail__btn--chrome",glyphEl:at(a,"link"),tip:()=>({title:R(e,"Keep tool active"),sub:p.stay?R(e,"On: the tool stays active after each drawing"):R(e,"Off: one drawing per pick"),side:"right"}),onClick:()=>A(!p.stay)}),t.appendChild(U.stay),t.appendChild(D()),U.lock=$({cls:"oac-rail__btn--chrome",glyphEl:at(a,"unlock"),tip:()=>{const t=w();return{title:R(e,"Lock drawing"),sub:0===t.length?R(e,"Select a drawing first"):y(t).readOnly??void 0,side:"right"}},onClick:()=>{kt(e,"lock",w()),V()}}),t.appendChild(U.lock),U.eye=$({cls:"oac-rail__btn--chrome",glyphEl:at(a,"eye"),tip:()=>{const t=w(),o=y(t);return{title:R(e,"Hide drawing"),side:"right",sub:0===t.length?R(e,"Select a drawing first"):o.readOnly??(o.hidden?void 0:R(e,"Stays selected, so the eye brings it back"))}},onClick:()=>{kt(e,"visible",w()),V()}}),t.appendChild(U.eye),U.trash=$({cls:"oac-rail__btn--chrome oac-rail__btn--danger",glyphEl:at(a,"trash"),tip:()=>{const t=w(),o=y(t),n=o.editable.length,a=o.noDelete??void 0;return t.length>0?{title:n>1?R(e,"Delete {count} drawings",{count:n}):R(e,"Delete drawing"),chord:b("delete","Delete"),sub:a??R(e,"Right-click to remove all"),side:"right"}:{title:R(e,"Delete drawing"),chord:b("delete","Delete"),sub:R(e,"Select one first. Right-click to remove all"),side:"right"}},onClick:()=>{kt(e,"delete",w()),V()},onContext:()=>{const t=r.drawings(),o=t.filter(e=>!1!==e.policy?.selectable).length,n=T(r,t.map(e=>e.id)).length;B(U.trash,[{label:R(e,"Select all ({count})",{count:o}),icon:"cursor",disabled:0===o,onSelect:()=>{r.select(t.map(e=>e.id)),V()}},{label:R(e,"Remove all drawings ({count})",{count:n}),icon:"trash",danger:!0,disabled:0===n,onSelect:()=>{r.clear(),V(),e.status(n>0?R(e,1===n?"Removed {count} drawing":"Removed {count} drawings",{count:n}):R(e,"No drawings to remove"))}}])}}),t.appendChild(U.trash),t.appendChild(D()),U.undo=$({cls:"oac-rail__btn--chrome",glyphEl:at(a,"undo"),tip:()=>({title:R(e,"Undo"),chord:b("undo","Mod+Z"),side:"right"}),onClick:()=>{L(e,"undo"),V()}}),t.appendChild(U.undo),U.redo=$({cls:"oac-rail__btn--chrome",glyphEl:at(a,"redo"),tip:()=>({title:R(e,"Redo"),chord:b("redo-alt","Mod+Y")??b("redo",void 0),side:"right"}),onClick:()=>{L(e,"redo"),V()}}),t.appendChild(U.redo),t.appendChild(D()),U.collapse=$({cls:"oac-rail__btn--chrome oac-rail__collapse",glyphEl:at(a,"chevrons-left"),tip:()=>({title:R(e,"Hide drawing tools"),sub:R(e,"The chart takes the space. The tab at its bottom left brings them back"),side:"right"}),onClick:()=>{K(!0)}}),t.appendChild(U.collapse),t})()),te(r.activeTool())},te=o=>{const n=o??null;let i=null;for(const o of Array.from(t.querySelectorAll(".oac-rail__tool"))){const t=(o.dataset.tools??"").split(",").filter(Boolean),r=null===n?0===t.length:t.includes(n);o.classList.toggle("is-on",r),o.classList.toggle("is-held",r&&h&&t.length>0),o.setAttribute("aria-pressed",String(r)),r&&null===i&&(i=o),r&&o.dataset.group&&t.length>0&&null!==n&&(p.last[o.dataset.group]!==n&&(p.last[o.dataset.group]=n,m()),o.dataset.face!==n&&(o.dataset.face=n,j(o,Lt(a,n)))),e.tips.refreshLabel(o)}const r=a.activeElement;null===i||null!==r&&t.contains(r)||X(i),_(n),V()},oe=function(e,t,o){const n=e.document,a=()=>{const e=n.activeElement;return null!==e&&t.contains(e)?e.closest(".oac-rail__btn"):null},i=e=>{const t=o.buttons();if(0===t.length)return;const n=t[(e%t.length+t.length)%t.length];o.setRoving(n),n.focus()},r=[],s=(t,o,n)=>{r.push(e.keymap.register(t,o,"rail",{label:n,group:"Tool rail"}))};s("ArrowDown",()=>{i(o.buttons().indexOf(a())+1)},"Next tool"),s("ArrowUp",()=>{i(o.buttons().indexOf(a())-1)},"Previous tool"),s("Home",()=>{i(0)},"First tool"),s("End",()=>{i(o.buttons().length-1)},"Last tool"),s("ArrowRight",()=>{const e=a();return null!==e&&void 0!==e.dataset.group&&""!==e.dataset.group&&o.openGroup(e.dataset.group,e)},"Open the group"),s("Escape",()=>{const t=o.flyoutOpen();o.closeFlyout(),e.tips.hide();const n=o.chart;return void 0!==n&&"function"==typeof n.focus?n.focus():a()?.blur(),t},"Back to the chart");const l=e=>{const t=e.target,n=null!==t&&"function"==typeof t.closest?t.closest(".oac-rail__btn"):null;null!==n&&o.setRoving(n)};return t.addEventListener("focusin",l),{destroy:()=>{for(const e of r)e();t.removeEventListener("focusin",l)}}}(e,t,{buttons:Q,setRoving:X,openGroup:(e,t)=>{const o=d(e);return void 0!==o&&(W(o,t,!0),!0)},flyoutOpen:()=>null!==N,closeFlyout:F,chart:n.cursorTarget}),ne=[];ne.push(s.on("draw:tool",e=>{te(e.tool)}));for(const e of["draw:select","drawing:select","drawing:change","draw:add","draw:remove","draw:update","draw:paste","draw:cut"])ne.push(s.on(e,V));return void 0!==e.history&&ne.push(e.history.subscribe(V)),x(),k(),ee(),q.apply(),{el:t,sync:te,refresh:V,prefs:()=>({favorites:p.favorites.slice(),magnet:p.magnet,stay:p.stay,last:{...p.last},...!0===p.collapsed?{collapsed:!0}:{}}),restorePrefs:e=>{p=Ot(e,St,c),m(),x(),k(),ee(),q.apply()},magnetMode:()=>p.magnet,setMagnetMode:C,cycleMagnet:S,stayMode:()=>p.stay,setStayMode:A,favorites:()=>p.favorites.slice(),isFavorite:J,toggleFavorite:Y,setDrawLock:E,drawLocked:()=>h,collapsed:()=>!0===p.collapsed,setCollapsed:K,openGroup:(e,o=!1)=>{const n=d(e),a=t.querySelector(`.oac-rail__group[data-group="${e}"]`);void 0!==n&&null!==a&&W(n,a,o)},closeFlyout:F,flyoutOpen:()=>null!==N,destroy:()=>{F();for(const e of ne)e();oe.destroy(),_(null),q.destroy(),t.textContent=""}}}function Pt(e,t,o){if(void 0===t)return"";const n={regular:R(e,"Regular hours"),extended:R(e,"Extended hours"),adjusted:R(e,"Adjusted prices"),raw:R(e,"Raw prices")},a=[];for(const e of["session","adjustment","currency","unit"]){const i=t[e];void 0===i||void 0!==o&&o!==e||a.push("session"===e||"adjustment"===e?n[i]:i)}return a.join(" ")}const $t={regular:"Market open",pre:"Pre-open",post:"Post-close",extended:"Extended hours",closed:"Market closed",holiday:"Holiday"},jt={regular:"market-open",pre:"market-pre",post:"market-post",extended:"market-post",closed:"market-closed",holiday:"market-holiday"};function Dt(e,o){const n=Math.round(t.zoneOffsetSeconds(e,o)/60);if(0===n)return"UTC";const a=Math.abs(n),i=a%60;return`UTC${n<0?"-":"+"}${Math.floor(a/60)}${0===i?"":":"+String(i).padStart(2,"0")}`}function Mt(e,o,n=!0){return n?t.formatZonedTimeSeconds(Math.floor(e),o):t.formatZonedTime(Math.floor(e),o)}const zt=new Map;function Nt(e,o,n,a){const i=o.phase,r=R(e,`schema.ui.market.${i}`,{},$t[i]),s=o=>null===o?"":function(e,o,n,a){const i=t.formatZonedTime(e,n),r=t.utcSecondsToZonedParts(e,n),s=t.utcSecondsToZonedParts(o,n);if(r.year===s.year&&r.month===s.month&&r.day===s.day)return i;const l=`${a??""}\0${n}`;let c=zt.get(l);if(void 0===c){try{c=new Intl.DateTimeFormat(a,{timeZone:n,weekday:"short"})}catch{c=new Intl.DateTimeFormat(void 0,{timeZone:n,weekday:"short"})}zt.set(l,c)}return`${c.format(new Date(1e3*e))} ${i}`}(o,n,a,e.locale);let l="";return"regular"===i&&null!==o.closesAt?l=R(e,"schema.ui.market.closes",{time:s(o.closesAt)},"closes {time}"):"post"!==i&&"extended"!==i||null===o.changesAt?"regular"!==i&&null!==o.opensAt&&(l=R(e,"schema.ui.market.opens",{time:s(o.opensAt)},"opens {time}")):l=R(e,"schema.ui.market.until",{time:s(o.changesAt)},"until {time}"),{phase:i,label:r,detail:l}}class Rt{constructor(){Object.defineProperty(this,"_calendar",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_status",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_from",{enumerable:!0,configurable:!0,writable:!0,value:1/0}),Object.defineProperty(this,"_until",{enumerable:!0,configurable:!0,writable:!0,value:-1/0})}read(e,o){if(e!==this._calendar||o<this._from||o>=this._until){this._calendar=e,this._from=o;try{this._status=t.marketStatusAt(e,o)}catch{this._status=null}this._until=this._status?.changesAt??o+86400}return this._status}until(){return this._until}}function Ft(e){return!1!==e.statusLineOptions().marketStatus}function Wt(e){const t=e.panes()[e.primaryPaneIndex()];if(void 0===t)return 2;const o=t.priceScale.precision();return Number.isFinite(o)?Math.max(2,Math.min(8,Math.round(o))):2}function Bt(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 Ut(e,o,n={}){const a=e.document,i=e.chart,r=n.locale??e.locale;o.classList.add("oac-statusline"),o.setAttribute("role","status"),o.setAttribute("aria-live","polite");const s=u(a,"span","oac-statusline__title"),l=u(a,"span","oac-statusline__sym"),c=u(a,"span","oac-statusline__iv"),d=u(a,"span","oac-statusline__iv oac-statusline__variant");s.appendChild(l),s.appendChild(c),s.appendChild(d),o.appendChild(s);const p=(e,t)=>{const n=u(a,"span","oac-statusline__field "+t),i=u(a,"i");i.textContent=e;const r=u(a,"b");return n.appendChild(i),n.appendChild(r),n.hidden=!0,o.appendChild(n),{el:n,val:r}},h=p(R(e,"O"),"oac-statusline__o"),m=p(R(e,"H"),"oac-statusline__h"),g=p(R(e,"L"),"oac-statusline__l"),f=p(R(e,"C"),"oac-statusline__c"),b=p("","oac-statusline__chg"),v=p(R(e,"Vol"),"oac-statusline__vol"),w=p(R(e,"OI"),"oac-statusline__oi"),y=u(a,"span","oac-statusline__time");o.appendChild(y);const _=u(a,"span","oac-statusline__market");_.hidden=!0,o.appendChild(_);const x=u(a,"span","oac-statusline__msg");o.appendChild(x);const k=u(a,"span","oac-statusline__tz");o.appendChild(k);const C=new Map,S=new Intl.NumberFormat(r,{minimumFractionDigits:2,maximumFractionDigits:2}),A=new Intl.NumberFormat(r,{notation:"compact",maximumFractionDigits:2});let T=null,E=null,L=!0,O=!1,I=!1;const P=(e,t)=>{e.textContent!==t&&(e.textContent=t)},$=(e,t)=>{e.hidden===t&&(e.hidden=!t)},j=()=>{const o=i.statusLineOptions();$(s,!1!==o.title);const n=Pt(e,i.getDataContext()?.variant);P(d,n),$(d,""!==n);const a=!1!==o.chartValues&&null!==T;for(const e of[h,m,g,f])$(e.el,a);const l=Wt(i);if(a&&null!==T){const e=Bt(r,l,C);P(h.val,e.format(T.open)),P(m.val,e.format(T.high)),P(g.val,e.format(T.low)),P(f.val,e.format(T.close))}const c=!1!==o.barChange&&null!==T;if($(b.el,c),c&&null!==T){const e=T.close-T.open,t=0!==T.open?e/T.open*100:0,o=e>0?"+":"";P(b.val,`${o}${Bt(r,l,C).format(e)} (${o}${S.format(t)}%)`),b.el.classList.toggle("is-up",e>0),b.el.classList.toggle("is-down",e<0)}const u=!1!==o.volume&&null!==T&&"number"==typeof T.volume;$(v.el,u),u&&null!==T&&P(v.val,A.format(T.volume));const p=!0===o.openInterest&&!1!==i.hasOpenInterest&&void 0!==T?.oi&&Number.isFinite(T.oi);$(w.el,p),p&&void 0!==T?.oi&&P(w.val,A.format(T.oi)),P(y,null!==E&&null!==T?t.formatZonedCrosshairLabel(E,i.timezone()):""),P(k,i.timezone()),F()},D=new Rt;let M=0,z=0,N=!1;function F(){if(!0!==n.marketStatus||N)return;const t=(n.now??Date.now)()/1e3,o=Ft(i)?D.read(i.dataLayer.sessionCalendar,t):null,a=null===o?null:Nt({translate:e.translate,locale:r},o,t,i.timezone());$(_,null!==a),null!==a&&(P(_,""===a.detail?a.label:`${a.label} · ${a.detail}`),_.dataset.phase!==a.phase&&(_.dataset.phase=a.phase));const s=Math.floor(null===o?t+60:Math.min(D.until(),t+3600));s!==z&&(0!==M&&clearTimeout(M),M=0,z=s,0!==s&&(M=setTimeout(()=>{M=0,z=0,F()},1e3*Math.max(1,s-t)+50)))}const W=()=>{if(O)return{bar:null,time:null};const e=i.primaryBars(),t=e[e.length-1];return void 0===t?{bar:null,time:null}:{bar:t,time:t.time}},B=(e,t)=>{e===T&&t===E||(T=e,E=t,j())},U=()=>{const e=W();B(e.bar,e.time)},q=i.on("crosshair:move",e=>{const t=e;if(null!==t.bar&&void 0!==t.bar)return L=!1,void B(t.bar,t.time);L=!0,U()}),K=i.on("data:context",j),G=i.on("data:update",e=>{const t=e?.kind;if("reset"===t&&(O=!1),L)return void U();const o=W();null!==o.bar&&o.time===E&&B(o.bar,o.time)}),V=i.on("resize",()=>{L&&U()}),H=i.on("timezone:changed",j),J={el:o,setMessage:(e,t="info")=>{P(x,e),x.classList.toggle("is-error","error"===t)},setSymbol:(e,t,o)=>{const n=t?`${t}:${e}`:e;I&&n===l.textContent&&o===c.textContent||(P(l,n),P(c,o),O=I,I=!0,L=!0,O?B(null,null):U())},setBar:(e,t)=>{L=null===e,B(e,t)},refresh:()=>{if(L){const e=W();T=e.bar,E=e.time}j()},destroy:()=>{N=!0,0!==M&&clearTimeout(M),q(),K(),G(),V(),H(),o.textContent=""}};return j(),J}function qt(e){return"string"==typeof e&&(t.registeredChartTypes().includes(e)||t.registeredSeriesTransforms().includes(e))}function Kt(e){const t=e.primarySeries(),o=null===t?void 0:e.seriesTransform(t)?.type;return"point-figure"===o||"renko"===o?o:null}function Gt(e){if("string"!=typeof e)return null;const t=e.trim();if(/^https:\/\/[^\s]+$/i.test(t))try{const e=new URL(t);return e.username||e.password?null:e.href}catch{return null}return/^\/(?!\/)[\w./%-]+(?:\?[\w=&.%-]+)?$/.test(t)?t:null}let Vt=0;function Ht(e,t,o){const n=e.document,a="mobile"===o.variant;let i,r=!1,s=0,l=null,c=null,d=null,p=null,h=null,m=[],g="",f=null,b=[],v=0,w="",y=!1;const _=()=>{s++,null!==l&&(clearTimeout(l),l=null),c?.abort(),c=null},x=()=>{_();const e=h;h=null,d=null,p=null,m=[],b=[],f=null,g="",y=!1,t.setAttribute("aria-expanded","false"),t.removeAttribute("aria-controls"),e?.()},k=e=>{if(r||y||!b.includes(e)||t.value.trim()!==w||(void 0===o.context?void 0:JSON.stringify(o.context()))!==i)return;const n=e.symbol.trim();""!==n&&(t.blur(),x(),o.onSelect(n,e.exchange))},C=()=>{if(null===d||null===p)return;const t=d.querySelector(".oac-symbol-picker__categories");t.textContent="";const o=Array.from(new Set(m.map(e=>e.assetClass?.trim()).filter(e=>Boolean(e))));if(o.length>1)for(const a of["",...o]){const o=u(n,"button","oac-symbol-picker__category",{type:"button","aria-pressed":String(g===a)});o.textContent=a||R(e,"schema.ui.allAssets",{},"All"),o.addEventListener("click",()=>{_(),g=a,f=null,v=0,C()}),t.appendChild(o)}p.textContent="";const i=m.filter(e=>""===g||e.assetClass===g),r=f?.contractGroup;if(b=void 0===r?i.slice():r.contracts.filter(e=>"string"==typeof e.symbol),void 0!==r){const t=u(n,"button","oac-symbol-picker__back",{type:"button"});if(t.textContent=R(e,"schema.ui.backToSymbols",{},"Back to symbols"),t.addEventListener("click",()=>{f=null,v=0,C()}),p.appendChild(t),r.label){const e=u(n,"div","oac-head");e.textContent=r.label,p.appendChild(e)}}if(b.forEach((t,o)=>{if("string"!=typeof t.symbol)return;const i=u(n,"button","oac-symbol-picker__row oac-menu__row"+(o===v?" is-active":""),{type:"button",role:"option"});a&&(i.dataset.mobileAction="pick-symbol");const r=Gt(t.iconUrl);if(null!==r){const e=u(n,"img","oac-symbol-picker__icon",{src:r,alt:""});i.appendChild(e)}const s=u(n,"span","oac-menu__label");if(s.textContent=t.exchange?`${t.exchange}:${t.symbol}`:t.symbol,i.appendChild(s),t.name){const e=u(n,"span","oac-menu__sub");e.textContent=t.name,i.appendChild(e)}if(t.contractGroup){const t=u(n,"span","oac-symbol-picker__group");t.textContent=R(e,"schema.ui.showContracts",{},"Contracts"),i.appendChild(t)}i.addEventListener("click",e=>{e.stopPropagation(),t.contractGroup?(f=t,v=0,C()):k(t)}),p?.appendChild(i)}),0===b.length){const t=u(n,"div","oac-symbol-picker__empty",{role:"status"});t.textContent=R(e,"schema.ui.noSymbols",{},"No symbols found"),p.appendChild(t)}},S=k=>{if(_(),w=k.trim(),""===w)return void x();g="",f=null,m=[],b=[],v=0,i=void 0===o.context?void 0:JSON.stringify(o.context());const S=s;y=!0,(()=>{if(null!==d)return;if(d=u(n,"div","oac-symbol-picker "+(a?"oac-mobile-results":"oac-menu oac-sym__results"),{role:a?"region":"listbox","aria-label":R(e,"schema.ui.symbolResults",{},"Symbols")}),d.addEventListener("mousedown",e=>e.preventDefault()),a){const t=u(n,"div","oac-mobile-results__head"),o=u(n,"strong");o.textContent=R(e,"schema.ui.symbolResults",{},"Symbols");const a=u(n,"button","oac-mobile__action",{type:"button"});a.dataset.mobileAction="close-search",a.textContent=R(e,"schema.ui.closeSearch",{},"Close"),a.addEventListener("click",x),t.append(o,a),d.appendChild(t)}const o=u(n,"div","oac-symbol-picker__categories");d.appendChild(o),p=u(n,"div",a?"oac-mobile-results__list":"oac-menu__body"),p.setAttribute("role","listbox"),p.id="oac-symbol-picker-"+ ++Vt,d.appendChild(p),t.setAttribute("aria-controls",p.id),t.setAttribute("aria-expanded","true");const i=d;h=e.openOverlay(d,{anchor:t,placement:"below",initialFocus:null,dismissOnOutside:!0,onClose:()=>{d===i&&x()}})})(),null!==d&&(d.querySelector(".oac-symbol-picker__categories").textContent="");const A=(t,o)=>{if(null===p)return;const a=u(n,"div","oac-symbol-picker__status",{role:"status"});a.textContent=R(e,t,{},o),p.textContent="",p.appendChild(a)};A("schema.ui.searchingSymbols","Searching");const T=()=>{S===s&&(y=!1,A("schema.ui.symbolSearchFailed","Search unavailable"))};l=setTimeout(()=>{let e;l=null,c=new AbortController;try{e=Promise.resolve(o.search(w,{signal:c.signal}))}catch{return void T()}e.then(e=>{r||S!==s||null===d||t.value.trim()!==w||(void 0===o.context?void 0:JSON.stringify(o.context()))!==i||(y=!1,m=e.filter(e=>"string"==typeof e.symbol&&""!==e.symbol.trim()),0!==m.length?(v=0,C()):x())},T)},150)},A=()=>S(t.value),T=e=>{if(!e.isComposing&&229!==e.keyCode)if("Escape"!==e.key){if(!y&&t.value.trim()===w&&(void 0===o.context?void 0:JSON.stringify(o.context()))===i)if("ArrowDown"===e.key||"ArrowUp"===e.key){if(0===b.length)return;e.preventDefault(),e.stopImmediatePropagation(),v=(v+("ArrowDown"===e.key?1:-1)+b.length)%b.length,C()}else if("Enter"===e.key&&void 0!==b[v]){e.preventDefault(),e.stopImmediatePropagation();const t=b[v];t.contractGroup?(f=t,v=0,C()):k(t)}}else null!==d&&(e.preventDefault(),x())},E=e=>{const t=e.relatedTarget;t&&!0===d?.contains(t)||x()};t.addEventListener("input",A),t.addEventListener("keydown",T),t.addEventListener("blur",E),t.setAttribute("aria-autocomplete","list"),t.setAttribute("aria-haspopup","listbox"),t.setAttribute("aria-expanded","false");const L=e.bus.on("symbol",x),O=e.bus.on("interval",x);return{open:e=>{r||(t.focus(),void 0!==e&&(t.value=e),""!==t.value.trim()&&S(t.value))},canCommitRaw:()=>!y&&0===b.length,close:x,destroy:()=>{r||(r=!0,x(),L(),O(),t.removeEventListener("input",A),t.removeEventListener("keydown",T),t.removeEventListener("blur",E))}}}const Jt="\n.oac-widget .oac-symbol-picker{min-width:250px;max-width:min(420px,calc(100vw - 24px))}\n.oac-widget .oac-symbol-picker__categories{display:flex;gap:4px;overflow-x:auto;padding:5px 7px;scrollbar-color:var(--oac-sb-thumb) var(--oac-panel);scrollbar-width:thin}\n.oac-widget .oac-symbol-picker__categories::-webkit-scrollbar{height:6px}\n.oac-widget .oac-symbol-picker__categories::-webkit-scrollbar-track{background:var(--oac-panel)}\n.oac-widget .oac-symbol-picker__categories::-webkit-scrollbar-thumb{background:var(--oac-sb-thumb);border-radius:3px}\n.oac-widget .oac-symbol-picker__categories::-webkit-scrollbar-thumb:hover{background:var(--oac-sb-thumb-hover)}\n.oac-widget .oac-symbol-picker__categories:empty{display:none}\n.oac-widget .oac-symbol-picker__category,.oac-widget .oac-symbol-picker__back{background:transparent;border:0;color:inherit;cursor:pointer;padding:4px 7px;font:inherit}\n.oac-widget .oac-symbol-picker__category[aria-pressed=true]{background:var(--oac-elev);border-radius:4px}\n.oac-widget .oac-symbol-picker__row{display:flex;align-items:center;gap:7px;width:100%;text-align:left}\n.oac-widget .oac-symbol-picker__icon{width:18px;height:18px;object-fit:contain}\n.oac-widget .oac-symbol-picker__group{margin-left:auto;opacity:.7}\n.oac-widget .oac-symbol-picker__empty,.oac-widget .oac-symbol-picker__status{padding:9px;color:var(--oac-mut)}\n";function Zt(e){const o=void 0===e?null:t.tryResolveInterval(e);return null!==o&&t.isTimeBucketed(o.bucketing)?o.bucketing:null}const Yt=()=>({status:"cancelled"});function Qt(e){const t=e.getDataContext();return`${t?.symbol}\0${t?.exchange}\0${t?.interval}`}function Xt(e,t){return new Promise((o,n)=>{const a=()=>n(t.reason);t.aborted?a():(t.addEventListener("abort",a,{once:!0}),e.then(o,n).finally(()=>t.removeEventListener("abort",a)))})}function eo(e,t){let o=0,n=e;for(;o<n;){const e=o+n>>1;t(e)?n=e:o=e+1}return o}function to(e,t,o){const n=e.dataLayer.sessionCalendar;if(null===n)return!0;try{const e=n.sessionFrom(t);return null===e||e.open<o}catch{return!0}}class oo{constructor(e){Object.defineProperty(this,"_options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_abort",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_destroyed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),this._options=e}goTo(e){if(this.cancel(),this._destroyed)return Promise.resolve({status:"cancelled"});const t=new AbortController;return this._abort=t,this._run(e,t.signal).catch(e=>t.signal.aborted?{status:"cancelled"}:{status:"error",error:e instanceof Error?e:new Error(String(e))}).finally(()=>{this._abort===t&&(this._abort=null)})}cancel(){const e=this._abort;this._abort=null,e?.abort()}destroy(){this._destroyed=!0,this.cancel()}_chart(){const e=this._options.chart,t="function"==typeof e?e():e;return null===t||t.isDestroyed?null:t}async _run(e,o){const{from:n,to:a}=e;if(!Number.isFinite(n)||void 0!==a&&!(Number.isFinite(a)&&a>=n))return{status:"invalid"};let i=this._chart();if(null===i)return{status:"cancelled"};const r=Qt(i),s=Zt(this._options.interval?.()??i.getDataContext()?.interval);if(null===s)return{status:"unsupported"};const l=function(e,o){if("interval"===e.mode){if(e.seconds<86400)return{open:e=>e,close:t=>t+e.seconds};const n=e=>t.startOfZonedDay(e,o);return{open:n,close:a=>t.startOfZonedDay(n(a)+e.seconds+43200,o)}}return{open:n=>t.bucketStartOf(e,n,o),close:n=>t.nextBucketStart(e,n,o)??n}}(s,i.timezone()),c=i.primaryBars();if(0===c.length||l.close(c[c.length-1].time)<=n)return{status:"no-data"};const d=i.getVisibleLogicalRange(),u=n-(void 0===a?Math.ceil(Math.max(0,d.to-d.from)/2):0)*(l.close(n)-l.open(n));let p,h=c[0].time;for(;l.open(h)>u&&to(i,u,l.open(h));){const e=this._options.loadHistory;if(void 0===e||t.isReplaying(i)){p="unavailable";break}if(p=await Xt(e(u,o),o),i=this._chart(),o.aborted||null===i||Qt(i)!==r)return Yt();const n=i.primaryBars()[0]?.time;if("loaded"!==p)break;if(void 0===n||n>=h){p="empty";break}h=n}return function(e,t,o,n,a){const i=e.primaryBars(),r=i.length,s=r>0?t.open(i[0].time):o,l=void 0!==a&&"loaded"!==a&&s>o&&to(e,o,s)?a:void 0,c=eo(r,e=>t.close(i[e].time)>o),d=void 0===n?c:eo(r,e=>t.open(i[e].time)>n)-1;if(c>=r||d<c)return void 0===l?{status:"no-data"}:{status:"no-data",history:l};const u=t=>e.dataLayer.timeToIndex(i[t].time)??t;let p,h,m=d,g=!1;if(void 0===n){const t=e.getVisibleLogicalRange(),o=(t.to-t.from)/2,n=u(c),a=Math.max(0,n+o-u(r-1)-4);p=n-o-a,h=n+o-a}else{p=u(c)-.5,h=u(d)+.5;const t=e.timeScale.width;if(t>0){const o=t/e.timeScale.constrainBarSpacing(t/(h-p));if(o<h-p-1e-9)for(h=p+o,g=!0;m>c&&u(m)>h-.5;)m--;else p-=(o-(h-p))/2,h=p+o}}e.setVisibleLogicalRange({from:p,to:h});const f={status:void 0!==l||g?"partial":"placed",from:i[c].time,to:i[m].time};return void 0!==l&&(f.history=l),g&&(f.clipped=!0),f}(i,l,n,a,p)}}const no=()=>{},ao=e=>e instanceof Error&&"WorkspaceConflictError"===e.name,io=(e,t)=>e?.workspaces.find(e=>e.id===t),ro=e=>void 0===e?"":JSON.stringify([e.layout,e.panes,e.activePaneId,e.sync]);function so(e,t,o={}){const n=Number.isFinite(o.autosaveDelay)?Math.min(Math.max(0,o.autosaveDelay),2147483647):1e3;let a,i=null,r=null,s=null,l=null,c="",d=!1,u=!1,p=!1,h=null,m=!1,g=!1,f=!1,b=0,v=0,w=Promise.resolve(),y=!1,_="";const x=new Set,k=()=>{try{return!0===t.suspended?.()}catch{return!1}},C=()=>({catalog:i,layoutId:s,revision:r,dirty:d,busy:b>0,suspended:k(),conflict:u,autosave:i?.autosave&&null!==s?m?"saving":p||u?"failed":void 0!==a||y||d?"pending":"saved":"off",error:h}),S=()=>{if(f)return;const e=C(),t=JSON.stringify([i?.revision,r,s,d,e.busy,e.suspended,u,e.autosave,null===h]);if(t!==_){_=t;for(const t of Array.from(x))try{t(e)}catch(e){queueMicrotask(()=>{throw e})}}},A=()=>null!==s&&ro(io(i,s))!==c,T=e=>{h=e,_=""},E=()=>!(null===i||null===r||i.revision<=r||A())&&(r=i.revision,!0),L=()=>{s=null,l=null,c="",d=!1,u=!1},O=()=>{u=!0,l=null,d=!0};async function I(){const t=await e.load();(null===i||t.revision>i.revision)&&(i=t),A()&&O(),E(),S()}async function P(e,t){const o=t?.();for(let n=0;;n++){const a=void 0===t?r:i.revision;try{const o=await e(a);return void 0===t&&(r=Math.max(r,a+1)),p=!1,E(),o}catch(e){if(!ao(e)||3===n)throw e;if(await I(),void 0===t?r===a:t()!==o)throw e}}}const $=e=>()=>JSON.stringify(io(i,e)??null),j=e=>()=>ro(io(i,e)),D=()=>"";async function M(){const t=await e.load();return(null===i||t.revision>=i.revision)&&(i=t),p=!1,null!==s&&void 0===io(i,s)&&L(),A()?O():(u=!1,r=i.revision),t}const z=async()=>{null===r&&await M()},N=e=>{g=!0;try{return t.apply(e)}catch(e){return{applied:!1,reason:e instanceof Error?e.message:String(e)}}finally{g=!1}},R=(e,t,o)=>{c=ro(e),l=t,d=v!==o,d||void 0===a||(clearTimeout(a),a=void 0),u=!1,h=null,E()};async function F(o){const n=t.capture(),a=JSON.stringify(n),i=v;m=!0,S();try{const t=await P(t=>e.saveWorkspace(o,n,{expectedRevision:t}));return R(t,a,i),t}catch(e){throw p=!0,e}finally{m=!1}}function W(e){if(f)return Promise.reject(new Error("The layouts controller is destroyed"));b++,S();const t=w.then(()=>{if(f)throw new Error("The layouts controller is destroyed");return e()});return w=t.then(no,no),t.then(e=>(b--,h=null,q(),S(),e),e=>{throw b--,T(e),q(),S(),e})}async function B(){if(y=!1,f||null===s)return S();const o=s;try{const n=t.capture(),a=JSON.stringify(n),r=v;if(d=a!==l,!d||!i?.autosave||u||p||k())return S();m=!0,S();const c=await P(t=>e.saveWorkspace(o,n,{expectedRevision:t}));m=!1,s===o&&R(c,a,r)}catch(e){m=!1,p=!0,T(e)}S()}const U=()=>{y||f||(y=!0,w=w.then(B).then(no,no))};function q(){!i?.autosave||null===s||!d||u||p||m||void 0!==a||U()}const K=()=>{f||g||(v++,void 0!==a&&clearTimeout(a),a=setTimeout(()=>{a=void 0,U()},n),S())},G=t.subscribe?.(K),V=e.subscribe(e=>{f||null!==i&&e.revision<=i.revision||(i=e,E(),q(),S())});return{store:e,state:C,subscribe:e=>(x.add(e),()=>{x.delete(e)}),reload:()=>W(async()=>JSON.parse(JSON.stringify(await M()))),open:o=>W(async()=>{if(k())throw new Error("A layout cannot open while the chart is suspended, as during a replay");const n=p;if(await(async()=>{(void 0!==a||y)&&(void 0!==a&&(clearTimeout(a),a=void 0),await B())})(),p&&!n)throw h;await M();const r=io(i,o);if(void 0===r)throw new Error("The saved layout no longer exists");const l=t.capture(),c=v,d=N((e=>JSON.parse(JSON.stringify({layout:e.layout,panes:e.panes,activePaneId:e.activePaneId,sync:e.sync})))(r));if(!d.applied)return d;const u=JSON.stringify(t.capture()),m=i;let g=r;if(m.activeWorkspaceId!==o||m.recentWorkspaceIds[0]!==o)try{g=await P(t=>e.openWorkspace(o,{expectedRevision:t}),j(o))}catch(e){throw N(l).applied||L(),e}return s=g.id,R(g,u,c),d}),save:()=>W(async()=>{if(await z(),null===s)throw new Error("No saved layout is held: save it under a name first");return F(s)}),saveAs:o=>W(async()=>{await M();const n=t.capture(),a=JSON.stringify(n),i=v,r=await P(t=>e.createWorkspace(o,n,{expectedRevision:t}),D);return s=r.id,R(r,a,i),await P(t=>e.openWorkspace(r.id,{expectedRevision:t}),j(r.id)),r}),overwrite:()=>W(async()=>{if(await M(),null===s)throw new Error("The saved layout no longer exists: save it under a name");return c=ro(io(i,s)),r=i.revision,F(s)}),rename:(t,o)=>W(async()=>{await z(),await P(n=>e.rename("workspace",t,o,{expectedRevision:n}),$(t))}),duplicate:(t,o)=>W(async()=>(await z(),await P(n=>e.duplicate("workspace",t,o,{expectedRevision:n}),$(t)))),remove:t=>W(async()=>{await z(),await P(o=>e.remove("workspace",t,{expectedRevision:o}),$(t)),t===s&&(L(),E())}),setAutosave:t=>W(async()=>{await z(),await P(o=>e.setAutosave(t,{expectedRevision:o}),D),t&&U()}),changed:K,async flush(){f||(void 0!==a&&(clearTimeout(a),a=void 0),U(),await w)},destroy(){f||(f=!0,void 0!==a&&clearTimeout(a),V(),G?.(),x.clear())}}}const lo=240,co=["data","objects","watchlist","news"],uo={data:"Data",objects:"Objects",watchlist:"Watchlist",news:"News"};function po(e){const t="object"==typeof e&&null!==e?e:{};return{panel:co.includes(t.panel)?t.panel:null,width:"number"==typeof t.width&&Number.isFinite(t.width)?Math.round(Math.max(lo,Math.min(480,t.width))):300}}function ho(e,t,o){const n=e.document,a=(t,o)=>R(e,`schema.ui.dock.${t}`,{},o),i=nt(n,"aside","oac-panel-dock");i.hidden=!0,i.setAttribute("aria-label",a("title","Chart information"));const r=nt(n,"div","oac-panel-dock__resize");r.setAttribute("role","separator"),r.setAttribute("aria-orientation","vertical"),r.setAttribute("aria-label",a("resize","Resize information panel")),r.tabIndex=0;const s=nt(n,"div","oac-panel-dock__header"),l=nt(n,"div","oac-panel-dock__tabs");l.setAttribute("role","group"),l.setAttribute("aria-label",a("panels","Information panels"));const c=co.filter(e=>"function"==typeof o[e]),d=new Map(c.map(e=>[e,it(n,{label:a(e,uo[e]),onClick:()=>L(e)})])),u=e=>{for(const[t,o]of d)o.setAttribute("aria-pressed",String(t===e))},p=it(n,{label:a("close","Close"),onClick:()=>E()});p.classList.add("oac-panel-dock__close"),l.append(...d.values()),s.append(l,p);const h=nt(n,"div","oac-panel-dock__body");i.append(r,s,h),t.appendChild(i);const m=po(o.state);let g=null,f=null,b=!1,v=!1,w=null,y=null;const _=()=>e.root.getBoundingClientRect().width||e.root.clientWidth||1e3,x=()=>_()<=640,k=()=>Math.max(lo,Math.min(480,_()-320)),C=()=>{o.onChange?.({...m})},S=e=>{m.width=Math.round(Math.max(lo,Math.min(k(),e))),i.style.width=`${m.width}px`,r.setAttribute("aria-valuemin",String(lo)),r.setAttribute("aria-valuemax",String(k())),r.setAttribute("aria-valuenow",String(m.width))},A=()=>{if(!f)return;v=!0;const e=f;f=null,e(),v=!1},T=(o=!1)=>{if(b||null===m.panel)return;const a=null!==n.activeElement&&i.contains(n.activeElement)?n.activeElement:null,s=x();s!==("true"===i.dataset.sheet)&&A(),i.dataset.sheet=String(s),r.hidden=s,s&&!f?f=e.openOverlay(i,{placement:"center",modal:!0,initialFocus:a??g?.initialFocus??p,restoreFocus:!1,onClose:()=>{f=null,v||E()}}):s||(i.parentElement!==t&&t.appendChild(i),i.classList.remove("oac-dialog"),i.removeAttribute("aria-modal"),i.removeAttribute("role"),i.style.position="",i.style.left="",i.style.top="",i.style.transform="",S(m.width),o?(g?.initialFocus??p).focus():a?.focus())};function E(){if(null===m.panel)return;m.panel=null,y=null,A(),g?.destroy(),g=null,h.textContent="",i.hidden=!0,t.appendChild(i),u(null);const e=n.activeElement;w?.isConnected&&(null===e||e===n.body||i.contains(e))&&w.focus(),w=null,C()}function L(e,t=!0){if(b)return;const a=o[e];c.includes(e)&&void 0!==a&&(m.panel!==e||null===g?(null!==m.panel&&null!==g||(w=n.activeElement),g?.destroy(),h.textContent="",m.panel=e,i.hidden=!1,u(e),g=a(h),T(t),C()):t&&(g.initialFocus??p).focus())}const O=t=>{"Escape"===t.key&&0===e.overlays.size()&&(t.preventDefault(),t.stopPropagation(),E()),t.target===r&&["ArrowLeft","ArrowRight","Home","End"].includes(t.key)&&(t.preventDefault(),t.stopPropagation(),S("Home"===t.key?lo:"End"===t.key?k():m.width+("ArrowLeft"===t.key?10:-10)*(t.shiftKey?5:1)),C())},I=e=>{0!==e.button||x()||(e.preventDefault(),e.stopPropagation(),y={x:e.clientX,width:m.width,pointer:e.pointerId},r.setPointerCapture?.(e.pointerId),r.focus())},P=e=>{y&&y.pointer===e.pointerId&&(e.preventDefault(),S(y.width+y.x-e.clientX))},$=e=>{if(y&&y.pointer===e.pointerId){y=null,C();try{r.releasePointerCapture?.(e.pointerId)}catch{}}};i.addEventListener("keydown",O),r.addEventListener("pointerdown",I),r.addEventListener("pointermove",P),r.addEventListener("pointerup",$),r.addEventListener("pointercancel",$);const j=n.defaultView,D=()=>{x()||S(m.width),T()};j?.addEventListener?.("resize",D);const M=j?.ResizeObserver,z=M?new M(D):null;z?.observe(e.root),S(m.width);const N=m.panel;return m.panel=null,null!==N&&L(N,!1),{el:i,open:L,close:E,toggle:e=>{m.panel===e?E():L(e)},state:()=>({...m}),restore:e=>{const t=po(e);S(t.width),null!==t.panel&&c.includes(t.panel)?L(t.panel,!1):E()},destroy:()=>{b||(E(),b=!0,z?.disconnect(),j?.removeEventListener?.("resize",D),i.removeEventListener("keydown",O),r.removeEventListener("pointerdown",I),r.removeEventListener("pointermove",P),r.removeEventListener("pointerup",$),r.removeEventListener("pointercancel",$),i.remove())}}}const mo='\n.oac-widget .oac-panel-dock { position: relative; flex: none; min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--oac-panel); border-left: 1px solid var(--oac-bd); }\n.oac-widget .oac-panel-dock__header { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 10px; border-bottom: 1px solid var(--oac-bd-soft); flex: none; }\n.oac-widget .oac-panel-dock__tabs { display: flex; flex-wrap: wrap; gap: 3px; min-width: 0; }\n.oac-widget .oac-panel-dock__tabs .oac-btn, .oac-widget .oac-panel-dock__close { padding: 0 6px; }\n.oac-widget .oac-panel-dock__tabs .oac-btn { border-color: transparent; background: transparent; }\n.oac-widget .oac-panel-dock__tabs .oac-btn[aria-pressed="true"] { background: var(--oac-elev); color: var(--oac-tx); border-color: var(--oac-bd); }\n.oac-widget .oac-panel-dock__close { color: var(--oac-mut); }\n.oac-widget .oac-panel-dock__body { overflow: auto; min-height: 0; flex: 1 1 auto; overscroll-behavior: contain; }\n.oac-widget .oac-panel-dock__resize { position: absolute; z-index: 2; top: 0; bottom: 0; left: -4px; width: 8px; cursor: col-resize; touch-action: none; }\n.oac-widget .oac-panel-dock__resize:hover, .oac-widget .oac-panel-dock__resize:focus-visible { background: var(--oac-ring-soft); }\n.oac-widget .oac-panel-dock[data-sheet="true"] { position: absolute !important; inset: 0 !important; width: 100% !important; max-width: none !important; height: 100%; max-height: none; transform: none !important; border: 0; border-radius: 0; }\n.oac-widget .oac-panel-dock[data-sheet="true"] .oac-panel-dock__header { padding: 12px; }\n.oac-widget .oac-panel-dock[data-sheet="true"] .oac-btn { min-height: 40px; }\n.oac-widget .oac-panel-dock__body > .oac-objects { width: auto; max-width: none; border: 0; box-shadow: none; }\n';function go(){if(this.context.overlays.size()>0)return["overlay"];const e=[],t=this._doc.activeElement,o=this._opts.keyboardRoute?.();if(!1===o||null!==t&&this._dataStatus.el.contains(t))return[];const n=null!==t&&this.root.contains(t)?t.closest("[data-key-scope]")?.getAttribute("data-key-scope"):null;return n&&e.push(n),null!==this._rail&&null!==t&&this._rail.el.contains(t)&&e.push("rail"),(o||this._inChart())&&e.push("chart"),(o||this._pointerInside||null!==t&&this.root.contains(t))&&e.push("widget"),e.push("global"),e}function fo(){const e=this._keymap,t=this.draw,n=()=>({hasSelection:null!==t.selected(),hasTarget:null!==t.hovered(),editingText:!1,placing:null!==t.activeTool()}),a=()=>{const e=t.selection();if(e.length>0)return e.slice();const o=t.hovered();return null===o?[]:[o]},i=()=>(this._rail?.refresh(),!0),r=()=>{const e=this.alerts.hovered();return void 0!==e&&null===t.activeTool()&&(this.alerts.remove(e),i())},s=e=>{const s=o.keyToDrawingAction(e,n());if(null===s)return("Delete"===e.key||"Backspace"===e.key)&&r();switch(s.type){case"delete":kt(this.context,"delete",a());break;case"nudge":t.nudge(a(),s.dx,s.dy);break;case"cancel":t.cancel(),null===t.activeTool()&&this._rail?.setDrawLock(!1);break;case"finish":t.finish();break;case"popAnchor":t.popAnchor();break;default:return!1}return i()},l=()=>{const e=n();return e.hasSelection||e.hasTarget},c=e=>()=>!!l()&&(e(a()),i()),d=(t,o,n,a,i={})=>{e.register(t,o,"widget",{label:n,group:i.group??"Drawing",hidden:i.hidden,layered:i.layered,command:a,rebindable:!0!==i.fixed})},u=e=>()=>(L(this.context,e),i());d("Mod+Z",u("undo"),"Undo","undo",{group:"Widget"}),d("Mod+Shift+Z",u("redo"),"Redo","redo",{group:"Widget"}),d("Mod+Y",u("redo"),"Redo","redo-alt",{group:"Widget",hidden:!0}),d("Mod+C",c(e=>t.copy(e)),"Copy the selected drawing","copy"),d("Mod+X",c(e=>null===xt(this.context,e).noDelete&&t.cut(e)),"Cut the selected drawing","cut"),d("Mod+V",()=>(t.paste(),i()),"Paste drawings","paste"),d("Mod+D",c(e=>t.duplicate(e)),"Duplicate the selected drawing","duplicate"),d("Delete",()=>l()?(kt(this.context,"delete",a()),i()):r(),"Delete the selected drawing","delete"),d("Backspace",s,"Delete, or drop the last anchor while placing","delete-back",{fixed:!0}),d("Enter",s,"Finish the drawing being placed","finish",{fixed:!0});for(const[e,t]of[["left","ArrowLeft"],["right","ArrowRight"],["up","ArrowUp"],["down","ArrowDown"]])d(t,s,`Nudge the selection ${e} (Shift: ten pixels)`,`nudge-${e}`,{layered:!0,fixed:!0});for(const e of["left","right","up","down"])d(`Shift+Arrow${e[0].toUpperCase()}${e.slice(1)}`,s,"Nudge ten pixels",`nudge-${e}-far`,{hidden:!0,layered:!0,fixed:!0});d("Escape",e=>null!==t.activeTool()?(s(e)||(t.setTool(null),this._rail?.setDrawLock(!1)),!0):t.selection().length>0&&(t.select(null),this._rail?.refresh(),!0),"Leave the tool, then clear the selection","leave",{fixed:!0});for(const[e,n]of Object.entries(o.drawingShortcuts()))d(n,()=>(this._rail?.setDrawLock(!1),t.setTool(e),!0),At(e),`tool:${e}`,{group:"Drawing tools"});const p=!1!==this._opts.shortcutsEditor;if(d("?",()=>(We(this.context,{edit:p}),!0),"Keyboard shortcuts","shortcuts",{group:"Widget",fixed:!0}),!p)return h=e,void Ne.add(h);var h;const m=this.context.storage;bo.call(this),this._cleanups.push(e.onChange(()=>{const t=e.overrides();0===Object.keys(t).length?m.remove(fe):m.set(fe,t)}))}function bo(){!1!==this._opts.shortcutsEditor&&this._keymap.applyOverrides(this.context.storage.get(fe))}function vo(){const e=this.root,t=this._chartEl,o=()=>{this._pointerInside=!0},n=()=>{this._pointerInside=!1,this._pointerInChart=!1},a=()=>{this._pointerInChart=!0},i=()=>{this._pointerInChart=!1};e.addEventListener("pointerenter",o),e.addEventListener("pointerleave",n),t.addEventListener("pointerenter",a),t.addEventListener("pointerleave",i),this._cleanups.push(()=>{e.removeEventListener("pointerenter",o),e.removeEventListener("pointerleave",n),t.removeEventListener("pointerenter",a),t.removeEventListener("pointerleave",i)})}const wo="state",yo="drawings:";function _o(e){const t={...e};delete t.viewport,delete t.barSpacing;const o=e=>{if(!y(e))return e;const t={...e,autoScale:!0};return delete t.range,delete t.ratioLock,t};return Array.isArray(t.panes)&&(t.panes=t.panes.map(e=>{if(!y(e))return e;const t={...e};return y(e.priceScale)&&(t.priceScale=o(e.priceScale)),y(e.scales)&&(t.scales=Object.fromEntries(Object.entries(e.scales).map(([e,t])=>[e,o(t)]))),t})),t}function xo(e,t){if(void 0!==e||"both"!==t.navigation?.mousePan)return t;const{mousePan:o,...n}=t.navigation;return{...t,navigation:n}}function ko(e){if(void 0!==e?.chart){const o=e.symbol===this._symbol&&e.exchange===this._exchange&&e.interval===this._interval&&t.dataVariantKey(e.variant)===t.dataVariantKey(this._variant),n=xo(e.savedBy,e.chart);let a=o?n:_o(n);null!==this.instrumentDrawings&&null!==Eo(e)&&(a={...a,drawings:this.draw.toJSON()});const i=this.chart.restoreState(a);i.applied?(Lo.call(this,e.chart),this._keepView=o,this._pendingView=o?e.chart.viewport??null:null):this._toasts.toast(R(this.context,"The saved layout could not be restored: {error}",{error:i.reason??"unknown reason"}),"error")}e?.rail&&null!==this._rail&&this._rail.restorePrefs(e.rail),e?.panels&&this._dock?.restore(e.panels)}function Co(e){const t=this._storage,n=this._opts.drawingStore??(t.enabled?So(t):o.memoryDrawingStore());return void 0!==e?.chart?.drawings&&o.migrateUnscopedDrawings(n,Eo(e),e.chart.drawings),new o.InstrumentDrawings(this.chart,this.draw,{store:n,...this._holdDrawings?{key:e=>this._holdDrawings?null:o.instrumentDrawingsKey(e)}:{},onError:({operation:e,key:t})=>{if("read"===e||this._destroyed)return;const o=R(this._opts,"The drawings for {instrument} could not be saved",{instrument:decodeURIComponent(t)});this._statusline?.setMessage(o,"error"),this._bus.emit("status",{text:o,kind:"error"})}})}function So(e){return{get:t=>e.get(yo+t),set:(t,o)=>e.set(yo+t,o),remove:t=>e.remove(yo+t)}}function Ao(){this._holdDrawings&&(this._holdDrawings=!1,this.instrumentDrawings?.setInstrument({symbol:this._symbol,exchange:this._exchange}))}function To(){this._restoring&&(this._stateGiven=!0,Ao.call(this))}function Eo(e){return o.instrumentDrawingsKey({symbol:e.symbol.toUpperCase(),exchange:e.exchange})}function Lo(e){const t=this.chart.seriesTransform(this._series)?.type??this.chart.seriesType(this._series),o=(e.series??[]).find(e=>null!==e&&(e.transform?.type??e.type)===t);void 0!==o?.style&&Object.keys(o.style).length>0&&this._series.applyOptions(o.style)}function Oo(e){if(!y(e))return{applied:!1,reason:"not a widget state object"};if(void 0!==e.version&&1!==e.version)return{applied:!1,reason:`widget state version ${String(e.version)} is not 1`};let n;try{n=t.normalizeDataVariant(e.variant)}catch(e){return{applied:!1,reason:e instanceof Error?e.message:"invalid data variant"}}Io(e),"dark"!==e.theme&&"light"!==e.theme||this.setTheme(e.theme),qt(e.chartType)&&this._selectChartType(e.chartType,y(e.chart)?e.chart:void 0),void 0!==e.rail&&null!==this._rail&&this._rail.restorePrefs(e.rail),void 0!==e.panels&&this._dock?.restore(e.panels);const a="string"==typeof e.symbol?e.symbol.toUpperCase():this._symbol,i="string"==typeof e.exchange?e.exchange:this._exchange,r="string"==typeof e.interval&&t.isKnownInterval(e.interval)?e.interval:this._interval,s=t.dataVariantKey(n)===t.dataVariantKey(this._variant),l=a===this._symbol&&i===this._exchange&&r===this._interval&&s;let c;if(y(e.chart)){let t=xo(e.savedBy,e.chart);const n=this.instrumentDrawings,r=null!==n&&(a!==this._symbol||i!==this._exchange)&&null!==o.instrumentDrawingsKey({symbol:a,exchange:i}),s=t.drawings;if(r&&(t={...t,drawings:this.draw.toJSON()}),c=this.chart.restoreState(l?t:_o(t)),!c.applied)return{applied:!1,reason:c.reason,chart:c};Lo.call(this,t),To.call(this),r&&null!==n&&n.setDocument({symbol:a,exchange:i},s??[]),this._keepView=l,this._pendingView=l?t.viewport??null:null}return To.call(this),l||(this._cancelNavigation(),r!==this._interval&&(this._interval=r,this._bus.emit("interval",{interval:r})),a===this._symbol&&i===this._exchange||(this._symbol=a,this._exchange=i,this._bus.emit("symbol",{symbol:a,exchange:i})),s||(this._variant=n,this._bus.emit("variant",{variant: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._publishDataContext())),this._rail?.refresh(),this._statusline?.refresh(),this._bus.emit("layout",{reason:"restore",chartType:this.chartType()}),this._scheduleSave(),void 0===c?{applied:!0}:{applied:!0,chart:c}}function Io(e){if(r(e.interval),y(e.chart)&&Array.isArray(e.chart.indicators))for(const t of e.chart.indicators)y(t)&&y(t.settings)&&r(t.settings.timeframe)}function Po(){const e=this._storage.get(wo);if(!y(e)||1!==e.version)return null;Io(e);const o=function(e){try{return t.normalizeDataVariant(e)}catch{return null}}(e.variant),n=y(e.chart)?e.chart:void 0;return{version:1,symbol:"string"==typeof e.symbol?e.symbol:"",exchange:"string"==typeof e.exchange?e.exchange:"",interval:"string"==typeof e.interval&&""!==e.interval?e.interval:"1d",chartType:"string"==typeof e.chartType?e.chartType:"candlestick",theme:"light"===e.theme?"light":"dark",...o?{variant:o}:{},chart:n&&null===o?_o(n):n,rail:y(e.rail)?e.rail:null,panels:po(e.panels),..."string"==typeof e.savedBy?{savedBy:e.savedBy}:{}}}function $o(){this._storage.enabled&&!this._destroyed&&(this._restoring?this._saveWanted=!0:(0!==this._saveTimer&&clearTimeout(this._saveTimer),this._saveTimer=setTimeout(()=>{this._saveTimer=0,this._saveNow()},250)))}function jo(){if(this._storage.enabled&&!this._destroyed)if(this._restoring)this._saveWanted=!0;else{0!==this._saveTimer&&(clearTimeout(this._saveTimer),this._saveTimer=0);try{this._storage.set(wo,this.getState())||this.context.status(R(this.context,"The chart layout could not be saved"),"error")}catch(e){this.context.status(R(this.context,"The chart layout could not be saved: {error}",{error:e instanceof Error?e.message:"invalid state"}),"error")}}}function Do(){const e=this._doc.defaultView,t=!this._storage.loaded;if(null!=e&&"function"==typeof e.addEventListener){const o=t?()=>{this._saveNow(),this._storage.flush()}:()=>this._saveNow();e.addEventListener("pagehide",o),this._cleanups.push(()=>e.removeEventListener("pagehide",o))}if(t){const e=this._doc,t=()=>{"hidden"===e.visibilityState&&(0!==this._saveTimer&&this._saveNow(),this._storage.flush())};e.addEventListener("visibilitychange",t),this._cleanups.push(()=>e.removeEventListener("visibilitychange",t))}}function Mo(){const e={symbol:this._symbol,exchange:this._exchange,interval:this._interval,variant:this._variant,chartType:this.chartType(),theme:this._themeName};return this.root.style.visibility="hidden",this._storage.load().then(()=>{if(!this._destroyed){this._timeframePreferences.reload();try{this._bus.shelter(()=>Ro.call(this,e))}catch(e){this._restoring=!1,this._toasts.toast(R(this.context,"The saved layout could not be restored: {error}",{error:F(this.context,e)}),"error");try{Ao.call(this),No.call(this)}catch{}}finally{this._restoring=!1,this._holdDrawings=!1,this.root.style.visibility=""}}})}class zo extends P{constructor(){super(...arguments),Object.defineProperty(this,"_sheltered",{enumerable:!0,configurable:!0,writable:!0,value:!1})}emit(e,t){if(this._sheltered)try{super.emit(e,t)}catch{}else super.emit(e,t)}shelter(e){const t=this._sheltered;this._sheltered=!0;try{e()}finally{this._sheltered=t}}}function No(){const e=this.dataController,o=e?.getState().request??null,n=null!==o&&o.symbol===this._symbol&&o.exchange===this._exchange&&o.interval===this._interval&&t.dataVariantKey(o.variant)===t.dataVariantKey(this._variant);null===e||""===this._symbol||n||this.reload()}function Ro(e){const n=this._saveWanted,a=this._stateGiven?null:Po.call(this),i=this._opts,r={symbol:this._symbol,exchange:this._exchange,interval:this._interval,variant:this._variant};if(null!==a){const o=this._symbol===e.symbol&&this._exchange===e.exchange;o&&void 0===i.symbol&&(this._symbol=a.symbol.toUpperCase()),o&&void 0===i.exchange&&(this._exchange=a.exchange),void 0===i.interval&&this._interval===e.interval&&t.isKnownInterval(a.interval)&&(this._interval=a.interval),void 0===i.variant&&t.dataVariantKey(this._variant)===t.dataVariantKey(e.variant)&&(this._variant=a.variant)}const s=this._symbol!==r.symbol||this._exchange!==r.exchange;(s||this._interval!==r.interval||t.dataVariantKey(this._variant)!==t.dataVariantKey(r.variant))&&(null===this.dataController&&this._series.setData([]),this._publishDataContext(),this._statusline?.setSymbol(this._symbol,this._exchange,this._interval),this._topbar?.refresh(),this._mobile?.refresh()),this.history.ignore(()=>{null!==a&&null!==this.instrumentDrawings&&void 0!==a.chart?.drawings&&o.migrateUnscopedDrawings(i.drawingStore??So(this._storage),Eo(a),a.chart.drawings),Ao.call(this);const t=this._storage.get(Tt);if(null!==t&&null!==this._rail&&this._rail.restorePrefs(t),bo.call(this),null===a)return;const n=a.chartType;void 0===i.chartType&&this.chartType()===e.chartType&&n!==e.chartType&&qt(n)&&this._selectChartType(n,a.chart),void 0===i.theme&&this._themeName===e.theme&&a.theme!==e.theme&&this.setTheme(a.theme),ko.call(this,a)}),null!==a&&(this._rail?.refresh(),this._statusline?.refresh()),this._restoring=!1,this._saveWanted=!1,n&&this._scheduleSave(),No.call(this),this._interval!==r.interval&&this._bus.emit("interval",{interval:this._interval}),s&&(this._bus.emit("symbol",{symbol:this._symbol,exchange:this._exchange}),this.chart.emit("symbol",{symbol:this._symbol,exchange:this._exchange})),t.dataVariantKey(this._variant)!==t.dataVariantKey(r.variant)&&this._bus.emit("variant",{variant:this._variant}),null!==a&&this._bus.emit("layout",{reason:"restore",chartType:this.chartType()})}function Fo(e){if(this._destroyed)return;const t=F(this.context,e.error);if("load"!==e.operation)return void this.context.status(R(this.context,"Saved chart settings could not be written: {error}",{error:t}),"error");const o=R(this.context,"Saved chart settings could not be read, so changes are kept for this session only: {error}",{error:t});this.context.status(o,"error"),this._toasts.toast(o,"error")}const Wo="widget.theme",Bo="p0",Uo=["symbol","interval","variant","theme","layout"],qo=["alert:created","alert:updated","alert:removed","alert:triggered","alert:expired","replay:start","replay:stop","replay:end"],Ko=["lastClosedTime","lastTouchedTime","lastTriggeredAt","lastTriggeredTime"];function Go(e){const t=_o(e),o=t.alerts;return void 0!==o&&Array.isArray(o.alerts)?{...t,alerts:{...o,alerts:o.alerts.map(e=>{const t={...e};for(const e of Ko)delete t[e];return t})}}:t}function Vo(e,t,o){return{id:e,symbol:t.symbol,exchange:t.exchange,interval:t.interval,...t.variant?{variant:t.variant}:{},chartType:t.chartType,chart:o,settings:{[Wo]:t.theme},volume:!1,magnet:t.rail?.magnet??"off",stay:t.rail?.stay??!1,comparisons:[],comparisonMode:"percent"}}function Ho(e,t,o){const n=o?t.settings[Wo]:void 0,a=e.getState().rail;return e.restoreState({version:1,symbol:t.symbol,exchange:t.exchange,interval:t.interval,chartType:t.chartType,chart:t.chart,..."dark"===n||"light"===n?{theme:n}:{},...t.variant?{variant:t.variant}:{},...null===a?{}:{rail:{...a,magnet:t.magnet,stay:t.stay}}})}function Jo(e){return{capture(){const t=JSON.parse(JSON.stringify(e.getState())),o=Vo(Bo,t,Go(t.chart));return{layout:{rows:1,columns:1,slots:[{paneId:Bo,row:0,column:0,rowSpan:1,columnSpan:1}]},panes:[o],activePaneId:Bo,sync:{crosshair:!0,viewport:!0,symbol:!1,interval:!1}}},apply(o){const n=function(e){if(1!==e.panes.length)return`a layout of ${e.panes.length} charts needs a chart grid`;const[o]=e.panes;if(!t.isKnownInterval(o.interval))return`unknown interval ${o.interval}`;if(!qt(o.chartType))return`unknown chart type ${o.chartType}`;if(o.comparisons.length>0)return"comparison symbols are not supported in a widget chart";const n=new Set(t.registeredIndicators().map(e=>e.id)),a=(o.chart.indicators??[]).find(e=>!n.has(e.indicatorId));return void 0===a?"":`unavailable study ${a.indicatorId}`}(o);if(""!==n)return{applied:!1,reason:n};const[a]=o.panes,i=Ho(e,a,!0);return i.applied?{applied:!0}:{applied:!1,reason:i.reason??"the chart state could not be restored"}},subscribe(t){const o=[...Uo.map(o=>e.on(o,t)),...qo.map(o=>e.chart.on(o,t)),e.history.subscribe(t)];return()=>{for(const e of o)e()}},suspended:()=>t.isReplaying(e.chart)}}function Zo(e){return!1===e?.removable||!1===e?.listed}const Yo=new WeakMap;function Qo(e,t){void 0===t?Yo.delete(e):Yo.set(e,t)}const Xo=(e,t,o,n)=>({version:void 0!==o&&o>0?2:1,indicators:e??[],panes:t,...void 0===o?{}:{primaryPane:o},...n});function en(e,t){const o=t.panes??[];return{preserveScaleFormats:(e.restoreOptions?.preserveScaleFormats??[]).filter(({paneIndex:e,scaleId:t})=>void 0!==o[e]&&("right"===t||Object.prototype.hasOwnProperty.call(o[e].scales??{},t)))}}function tn(e,o,n,a,i){const{chart:r}=e;if(void 0===o.planIndicatorTemplateState)throw new Error("This template store cannot apply templates");if(t.isReplaying(r))throw new Error("Stop the replay before applying a template");const s=r.getState(),l=o.planIndicatorTemplateState(r,n,a);if("append"===a&&l.indicators.length===(s.indicators??[]).length)return!1;const c={drawings:s.drawings,alerts:s.alerts},d=void 0!==s.sourceAbove&&l.indicators.some(e=>e.instanceId===s.sourceAbove)?{sourceAbove:s.sourceAbove}:{};let u=!1;const p=r.on("state:restore:start",()=>{u=!0});try{const e=r.restoreState(Xo(l.indicators,l.panes??("append"===a?s.panes:s.panes?.slice(0,1)),l.primaryPane,{...c,...d}),l.restoreOptions??{});if(!e.applied)throw new Error(e.reason??"The template could not be applied");if(e.indicators!==l.indicators.length)throw new Error("The chart did not restore every study")}catch(e){throw u&&r.restoreState(Xo(s.indicators,s.panes,s.primaryPane,{...c,...void 0===s.sourceAbove?{}:{sourceAbove:s.sourceAbove},viewport:s.viewport,barSpacing:s.barSpacing}),en(l,r.getState())),e}finally{p()}const h=r.getState(),m=e=>{const t=r.getState();return r.restoreState(Xo(e.indicators,e.panes,e.primaryPane,{...void 0===e.sourceAbove?{}:{sourceAbove:e.sourceAbove},drawings:t.drawings,alerts:t.alerts}),en(l,t)).applied};return e.history?.push({label:i,undo:()=>m(s),redo:()=>m(h)}),!0}function on(e,t,o){let n;try{n=t.captureIndicatorTemplate?.(e.chart)??(e.chart.getState().indicators??[]).filter(e=>!Zo(e.policy))}catch(e){return Promise.reject(e)}return 0===(Array.isArray(n)?n:n.indicators).length?Promise.reject(new Error("The chart has no studies of yours to save")):t.createTemplate(o,n)}const nn=e=>(t,o,n={})=>R(e,`schema.ui.layouts.${t}`,n,o);function an(e,t){const o=nn(e);return null===t.layoutId?o("unsaved","This chart is not saved as a layout"):t.conflict?o("conflict","Changed in another window"):t.catalog?.autosave?"saving"===t.autosave?o("saving","Saving"):"failed"===t.autosave?o("failed","Could not save"):"pending"===t.autosave?t.suspended?o("suspended","Autosave waits for the replay to end"):o("pending","Waiting to save"):o("saved","Saved"):t.dirty?o("dirty","Unsaved changes"):o("saved","Saved")}function rn(e,t,o){let n=!1;return e.subscribe(e=>{const a="failed"===e.autosave&&!e.conflict;n||!a&&!e.conflict||o(a?t("autosaveStopped","Autosave stopped: the layout could not be saved"):t("conflictStatus","The layout was changed in another window")),n=a||e.conflict})}function sn(e){return null!==e.layoutId&&(e.conflict||"failed"===e.autosave||e.dirty&&!e.catalog?.autosave)}const ln=V(()=>Promise.resolve().then(function(){return Ol}));function cn(e,t,o,n,a){n.handle?.isOpen()?n.handle.el.focus():H(ln,a=>{n.handle=a.mountLayoutsMenu(e,t,o)},t=>e.toast(J(e,nn(e)("title","Layouts"),t),"error"),a,{slot:n,doc:e.document,from:o})}function dn(e,t,o){try{const n=t();if(null===n)return!1;const a=n.toDataURL("image/png"),i=e.createElement("a");return i.href=a,i.download=o,(e.body??e.documentElement).appendChild(i),i.click(),i.remove(),!0}catch{return!1}}function un(){const e=globalThis;return void 0!==e.navigator?.clipboard?.write&&void 0!==e.ClipboardItem}function pn(e,t,o,n){const a=t=>n(R(e,"Copy failed: {error}",{error:F(e,t)}),"error");try{t.toBlob(t=>{if(null===t)return void n(R(e,"The canvas produced no image"),"error");const i=globalThis.ClipboardItem;globalThis.navigator.clipboard.write([new i({"image/png":t})]).then(()=>n(o,"info"),a)},"image/png")}catch(e){a(e)}}const hn=V(()=>Promise.resolve().then(function(){return Pl})),mn=V(()=>Promise.resolve().then(function(){return Fl})),gn={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 fn(e){const o=gn[e]??(t.registeredSeriesTransforms().includes(e)?t.getSeriesTransform(e).name:void 0);return void 0!==o?o:e.replace(/[-_]+/g," ").replace(/^\w/,e=>e.toUpperCase())}function bn(){const e=t.registeredSeriesTransforms();return[...t.registeredChartTypes().filter(o=>{try{return!e.includes(o)&&t.getChartType(o).isPriceSeries}catch{return!1}}),...e]}function vn(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 wn(e,t={}){const o=e.brandingOptions();if(!o||"string"!=typeof o.href||!/^https?:\/\//i.test(o.href))return null;const n="string"==typeof o.label&&""!==o.label.trim()?o.label.trim():R(t,"Chart branding");return{href:o.href,label:n}}function yn(e){return e.timeframePreferences?[...new Map([...e.timeframePreferences.favorites(),e.state().interval].map(e=>[s(e),e])).values()]:e.intervals}function _n(e,n,a){const i=e.document;n.classList.add("oac-topbar"),n.setAttribute("role","toolbar"),n.setAttribute("aria-label",R(e,"Chart toolbar"));const r=(e,t="")=>u(i,"button","oac-btn"+(t?" "+t:""),{type:"button","aria-label":e}),s=()=>u(i,"span","oac-sep",{role:"separator"}),l=(e,t)=>{e.classList.toggle("is-off",t),e.setAttribute("aria-disabled",String(t))},c=u(i,"div","oac-sym");c.appendChild(p(i,o.chromeIconSvg("search"),"chrome"));const d=u(i,"input","oac-sym__input",{type:"text","aria-label":R(e,"Symbol"),placeholder:R(e,"Symbol"),autocomplete:"off",spellcheck:"false"});c.appendChild(d);const h=u(i,"span","oac-sym__ex");c.appendChild(h),n.appendChild(c),n.appendChild(s());let m=null;const g=(e,t)=>{m?.close();const o=e.trim().toUpperCase();""!==o?(a.onSymbol(o,t),d.blur()):j()};a.search&&(m=Ht(e,d,{search:a.search,onSelect:g,context:()=>`${a.state().exchange}:${a.state().symbol}:${a.state().interval}`})),d.addEventListener("keydown",e=>{const t=e;"Enter"===t.key?(t.preventDefault(),(null===m||m.canCommitRaw())&&g(d.value)):"Escape"===t.key&&(j(),d.blur())}),d.addEventListener("focus",()=>{d.select()}),d.addEventListener("blur",()=>{j()});const f=function(e,t,n){const a=e.document,i=u(a,"div","oac-pills",{role:"radiogroup","aria-label":R(e,"Interval")}),r=new Map,s=()=>{i.textContent="",r.clear();const t=yn(n);for(const o of t){const t=u(a,"button",void 0,{type:"button",role:"radio","aria-pressed":"false","aria-label":R(e,"Interval {code}",{code:vn(o)})});t.textContent=vn(o),t.dataset.interval=o,t.disabled=!1===n.canSelectInterval?.(o),t.addEventListener("click",()=>n.onInterval(o)),i.appendChild(t),r.set(o,t)}};let l;if(s(),t.appendChild(i),n.timeframePreferences){const i=u(a,"button","oac-btn oac-topbar__interval-menu",{type:"button","aria-label":R(e,"Timeframes")});i.appendChild(p(a,o.chromeIconSvg("chevron-down"),"chrome")),i.setAttribute("aria-haspopup","dialog"),i.addEventListener("click",()=>{l?.(),l=G(e,i,{intervals:n.intervals,current:()=>n.state().interval,preferences:n.timeframePreferences,...n.canSelectInterval?{canSelect:n.canSelectInterval}:{},onSelect:n.onInterval})}),t.appendChild(i)}const c=()=>{const e=n.state();yn(n).join("|")!==[...r.keys()].join("|")&&s();for(const[t,o]of r)o.setAttribute("aria-pressed",String(t===e.interval)),o.setAttribute("aria-checked",String(t===e.interval)),o.disabled=!1===n.canSelectInterval?.(t)},d=n.timeframePreferences?.subscribe(c);return{refresh:c,destroy:()=>{d?.(),l?.()}}}(e,n,a);n.appendChild(s());const b=r(R(e,"Chart type"),"oac-topbar__type"),v=p(i,"","chrome"),w=u(i,"span");b.append(v,w),b.appendChild(Object.assign(u(i,"span","oac-chev",{"aria-hidden":"true"}),{innerHTML:o.chromeIconSvg("chevron-down")})),b.setAttribute("aria-haspopup","menu"),b.addEventListener("click",()=>{const o=a.state().chartType,n=t.registeredSeriesTransforms()[0];vt(e,b,bn().flatMap(t=>[...t===n?[R(e,"schema.chartType.group.transforms",{},"Transforms")]:[],{label:R(e,`schema.chartType.${t}`,{},fn(t)),icon:`chart-${t}`,on:t===o,onSelect:()=>a.onChartType(t)}]),{ariaLabel:R(e,"Chart type")})});const y=function(e,t){const n=e.document,a=u(n,"button","oac-btn oac-btn--icon oac-topbar__type-settings",{type:"button","aria-haspopup":"dialog"});a.appendChild(p(n,o.chromeIconSvg("settings"),"chrome"));const i=()=>{const t=Kt(e.chart)??"";return R(e,"schema.ui.chartTypeSettings.title",{name:R(e,`schema.chartType.${t}`,{},fn(t))},"{name} settings")};e.tips.attach(a,()=>({title:i(),side:"bottom"}));let r=null;const s={waiting:null};return a.addEventListener("click",()=>{H(mn,t=>{r?.close(),null!==Kt(e.chart)&&(r=t.openChartTypeSettings(e,a))},t=>e.status(J(e,i(),t),"error"),()=>t.isConnected,{slot:s,doc:n,from:a})}),{el:a,refresh:()=>{const t=Kt(e.chart)??"";a.dataset.type!==t&&(a.dataset.type=t,a.hidden=""===t,e.tips.target()===a&&e.tips.hide(),e.tips.refreshLabel(a))},close:()=>r?.close()}}(e,n);n.append(b,y.el);let _=null;if(!1!==a.indicators){_=r(R(e,"Indicators")),_.appendChild(p(i,o.chromeIconSvg("plus"),"chrome"));const t=u(i,"span");t.textContent=R(e,"Indicators"),_.appendChild(t),_.addEventListener("click",()=>{null!==_&&_.classList.contains("is-off")||null!==_&&a.onIndicators(_)}),n.appendChild(_)}n.appendChild(u(i,"span","oac-topbar__spacer"));const x=u(i,"span","oac-topbar__branding-slot");let k=null;n.appendChild(x);let C=null;const S=a.layouts;if(void 0!==S&&a.onLayouts){const t=R(e,"schema.ui.layouts.title",{},"Layouts"),s=()=>{const e=S.state();return null===e.layoutId?null:e.catalog?.workspaces.find(t=>t.id===e.layoutId)?.name??null},l=r(t,"oac-topbar__layouts");l.setAttribute("aria-haspopup","dialog"),l.appendChild(p(i,o.chromeIconSvg("layout"),"chrome"));const c=u(i,"span","oac-topbar__layouts-name");l.appendChild(c),e.tips.attach(l,()=>{const o=s(),n=S.state(),a=null===o?t:`${t}: ${o}`,i=an(e,n);return{title:a,label:sn(n)?`${a}, ${i}`:void 0,sub:i,side:"bottom"}});const d=()=>{c.textContent=s()??t,l.dataset.attention=String(sn(S.state())),e.tips.refreshLabel(l)};C=S.subscribe(d),d(),l.addEventListener("click",()=>{a.onLayouts?.(l)}),n.appendChild(l),n.classList.add("has-layouts")}const A=a.onGoTo?r(R(e,"Go to"),"oac-topbar__goto"):null;if(null!==A&&(A.textContent=R(e,"Go to"),A.setAttribute("aria-haspopup","dialog"),e.tips.attach(A,()=>({title:R(e,"Go to"),sub:null===Zt(a.state().interval)?R(e,"Go to needs a time-based interval"):void 0,side:"bottom"})),A.addEventListener("click",()=>{A.classList.contains("is-off")||a.onGoTo?.(A)}),n.appendChild(A)),a.onObjects){const t=r(R(e,"Objects"),"oac-topbar__objects");t.textContent=R(e,"Objects"),t.setAttribute("aria-haspopup","dialog"),t.addEventListener("click",()=>{a.onObjects?.(t)}),n.appendChild(t)}if(a.onDataWindow){const t=r(R(e,"schema.ui.dataWindow",{},"Data"),"oac-topbar__data");t.textContent=R(e,"schema.ui.dataWindow",{},"Data"),t.addEventListener("click",()=>{a.onDataWindow?.(t)}),n.appendChild(t)}for(const[t,o,i]of[["watchlist","Watchlist",a.onWatchlist],["news","News",a.onNews]]){if(!i)continue;const a=r(R(e,`schema.ui.dock.${t}`,{},o),`oac-topbar__${t}`);a.textContent=R(e,`schema.ui.dock.${t}`,{},o),a.addEventListener("click",()=>{i(a)}),n.appendChild(a)}if(a.onAlerts){const t=r(R(e,"Alerts"),"oac-topbar__alerts");t.textContent=R(e,"Alerts"),t.setAttribute("aria-haspopup","dialog"),t.addEventListener("click",()=>{a.onAlerts?.(t)}),n.appendChild(t)}const T=r(R(e,"Capture chart"),"oac-btn--icon");T.appendChild(p(i,o.chromeIconSvg("camera"),"chrome")),T.setAttribute("aria-haspopup","menu"),e.tips.attach(T,{title:R(e,"Capture"),sub:R(e,"PNG, SVG, CSV or the clipboard"),side:"bottom"});let E=null;const L={waiting:null},O=o=>{const r={...a.state()},s=e.chart,l=s.primarySeries(),c=s.getDataContext(),d=()=>!s.isDestroyed&&!1!==a.dataAvailable?.()&&s.primaryBars().length>0,u=()=>{const t=a.state(),o=e.chart.getDataContext();if(e.chart!==s||s.primarySeries()!==l||t.symbol!==r.symbol||t.exchange!==r.exchange||t.interval!==r.interval||t.chartType!==r.chartType||o!==c)throw new Error(R(e,"The chart changed; reopen Capture for its current source"));if(!d())throw new Error(R(e,"Wait for this chart to finish loading its data"))},p=un();vt(e,o,[{label:R(e,"Download PNG"),onSelect:()=>{const t=dn(i,()=>e.chart.takeScreenshot(),yt(r.symbol,r.interval)+".png");e.status(R(e,t?"Saved a PNG of the chart":"This runtime cannot save files"),t?"info":"error")}},{label:R(e,"Download SVG"),sub:R(e,"text stays text"),onSelect:()=>{const t=wt(i,yt(r.symbol,r.interval)+".svg",e.chart.exportSVG(),"image/svg+xml");e.status(R(e,t?"Saved an SVG of the chart":"This runtime cannot save files"),t?"info":"error")}},{label:R(e,"Copy image"),sub:R(e,p?"paste it anywhere":"needs https or localhost"),disabled:!p,onSelect:()=>{pn(e,e.chart.takeScreenshot(),R(e,"Chart copied"),(t,o)=>e.status(t,o))}},{label:R(e,"Download chart data (CSV)"),disabled:!d(),onSelect:()=>{H(hn,n=>{try{u(),E?.close(),E=n.openChartDataExportDialog(e,o,o=>{u();const n=t.exportChartDataCsv(s,o);if(u(),!wt(i,yt(r.symbol,r.interval)+".csv",n,"text/csv;charset=utf-8"))throw new Error(R(e,"This runtime cannot save files"));e.status(R(e,"Chart data download started"))})}catch(t){(t=>{e.status(R(e,"Data export failed: {error}",{error:F(e,t)}),"error")})(t)}},t=>e.status(J(e,R(e,"Download chart data (CSV)"),t),"error"),()=>n.isConnected,{slot:L,doc:i,from:o})}},...a.captureRows?.()??[]],{ariaLabel:R(e,"Capture")})};T.addEventListener("click",()=>O(T)),n.appendChild(T);const I=r(R(e,"Chart settings"),"oac-btn--icon");I.appendChild(p(i,o.chromeIconSvg("settings"),"chrome")),e.tips.attach(I,()=>({title:R(e,"Chart settings"),sub:a.settingsAvailable()?void 0:R(e,"The settings dialog is not in this build"),side:"bottom"})),I.addEventListener("click",()=>{I.classList.contains("is-off")||a.onSettings(I)}),n.appendChild(I);const P=r(R(e,"Theme"),"oac-btn--icon oac-topbar__theme"),$=p(i,"","chrome");P.appendChild($),e.tips.attach(P,()=>({title:"dark"===a.state().theme?R(e,"Switch to the light theme"):R(e,"Switch to the dark theme"),side:"bottom"})),P.addEventListener("click",()=>a.onTheme("dark"===a.state().theme?"light":"dark")),n.appendChild(P),null!==_&&e.tips.attach(_,()=>({title:R(e,"Indicators"),sub:a.indicatorsAvailable()?R(e,"Add a study to the chart"):R(e,"The indicator picker is not in this build"),side:"bottom"}));const j=()=>{const t=a.state();f.refresh(),i.activeElement!==d&&(d.value=t.symbol),h.textContent=t.exchange,h.hidden=""===t.exchange,v.dataset.type!==t.chartType&&(v.dataset.type=t.chartType,v.hidden=void 0===o.chartTypeIcon(t.chartType),v.innerHTML=v.hidden?"":o.chromeIconSvg(`chart-${t.chartType}`)),w.textContent=R(e,`schema.chartType.${t.chartType}`,{},fn(t.chartType)),y.refresh(),l(I,!a.settingsAvailable()),null!==_&&l(_,!a.indicatorsAvailable()),null!==A&&l(A,null===Zt(t.interval)),P.dataset.theme!==t.theme&&(P.dataset.theme=t.theme,$.innerHTML=o.chromeIconSvg("dark"===t.theme?"sun":"moon")),e.tips.refreshLabel(P),e.tips.refreshLabel(I),null!==_&&e.tips.refreshLabel(_);const n=wn(e.chart,e);null===n?(k?.remove(),k=null):(null===k&&(k=u(i,"a","oac-topbar__branding",{target:"_blank",rel:"noopener noreferrer"}),x.appendChild(k)),k.setAttribute("href",n.href),k.textContent=n.label,k.setAttribute("aria-label",n.label))},D=e.chart.on("branding:changed",j);return j(),{el:n,openCapture:O,refresh:j,focusSymbol:()=>{d.focus()},destroy:()=>{f.destroy(),E?.close(),y.close(),C?.(),D(),m?.destroy(),n.textContent=""}}}const xn={info:4e3,success:3500,error:0};function kn(e,t=e.ownerDocument,n={}){e.classList.add("oac-toasts"),e.setAttribute("role","status"),e.setAttribute("aria-live","polite");const a=new Set;return{toast:(i,r="info",s={})=>{const l=r in xn?r:"info",c=t.createElement("div");c.className="oac-toast oac-toast--"+l;const d=t.createElement("span");d.className="oac-toast__msg",d.textContent=i;const u=t.createElement("button");u.type="button",u.className="oac-toast__x",u.setAttribute("aria-label",R(n,"Dismiss")),u.innerHTML=o.chromeIconSvg("close"),c.appendChild(d),c.appendChild(u);const p=void 0!==s.ms?s.ms:xn[l];let h=0,m=!1;const g={node:c,dismiss:()=>{m||(m=!0,0!==h&&clearTimeout(h),a.delete(g),c.classList.add("is-out"),setTimeout(()=>c.remove(),160))}},f=()=>{p>0&&(h=setTimeout(g.dismiss,p))};for(u.addEventListener("click",g.dismiss),c.addEventListener("pointerenter",()=>{0!==h&&clearTimeout(h),h=0}),c.addEventListener("pointerleave",f),e.appendChild(c),a.add(g);a.size>5;){const e=a.values().next().value;a.delete(e),e.node.remove()}return f(),g},clear:()=>{for(const e of Array.from(a))e.dismiss()},count:()=>a.size,destroy:()=>{for(const e of Array.from(a))e.node.remove();a.clear(),e.remove()}}}const Cn=e=>{const t=e/255;return t<=.03928?t/12.92:Math.pow((t+.055)/1.055,2.4)};const Sn="--oac-",An=e=>e<0?0:e>1?1:e;function Tn(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 Tn("#"+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:An(e)}}return null}const En=e=>Math.round(Math.max(0,Math.min(255,e))).toString(16).padStart(2,"0");function Ln(e){return e.a>=1?`#${En(e.r)}${En(e.g)}${En(e.b)}`:`rgba(${Math.round(e.r)},${Math.round(e.g)},${Math.round(e.b)},${Math.round(1e3*e.a)/1e3})`}function On(e){const t=Tn(e);return null===t?.5:function(e){return.2126*Cn(e.r)+.7152*Cn(e.g)+.0722*Cn(e.b)}(t)}function In(e,t){const o=On(e),n=On(t);return(Math.max(o,n)+.05)/(Math.min(o,n)+.05)}function Pn(e,t,o,n=4.5){const a=e=>t.every(t=>In(e,t)>=n);if(a(e))return e;if(!a(o))return o;let i=0,r=1;for(let t=0;t<20;t++){const t=(i+r)/2;a(jn(e,o,t))?r=t:i=t}for(let t=r;t<=1;t+=1/256){const n=jn(e,o,t);if(a(n))return n}return o}function $n(e){return On(e.background)<.35?"dark":"light"}function jn(e,t,o){const n=Tn(e),a=Tn(t);if(null===n||null===a)return e;const i=An(o);return Ln({r:n.r+(a.r-n.r)*i,g:n.g+(a.g-n.g)*i,b:n.b+(a.b-n.b)*i,a:n.a+(a.a-n.a)*i})}function Dn(e,t){const o=Tn(e);return null===o?e:Ln({...o,a:An(t)})}const Mn='ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif',zn="ui-monospace, SFMono-Regular, Menlo, Consolas, monospace";function Nn(e,t=$n(e)){const o="dark"===t,n=e.background,a=o?"#ffffff":"#0c1120",i=e=>jn(n,a,e),r=e.lineColor,s=jn(e.axisText,a,o?.55:.6),l=i(o?.035:.02),c=i(o?.02:.045),d=i(o?.07:.06),u=i(o?.11:.1),p=[n,l,c,d],h=(e,t=p)=>Pn(e,t,a),m={bg:n,panel:l,"panel-2":c,elev:d,"elev-2":u,"elev-3":i(o?.18:.16),bd:e.axisLine,"bd-soft":e.paneSeparator,"bd-hover":jn(e.axisLine,a,.25),tx:s,"tx-strong":jn(s,a,.5),mut:h(e.axisText,[...p,u]),faint:h(jn(e.axisText,n,.4)),acc:r,"acc-2":jn(r,a,o?.2:.1),"on-bg":Dn(r,.16),"on-bd":jn(r,n,.45),ring:r,"ring-soft":Dn(r,.2),buy:e.upColor,sell:e.downColor,up:h(e.upColor),down:h(e.downColor),amber:h(o?"#e6b53c":"#b8860b"),danger:h(jn(e.downColor,a,o?.3:.1),[...p,u]),scrim:o?"rgba(6,8,12,0.55)":"rgba(24,30,40,0.38)",shadow:o?"0 14px 40px rgba(0,0,0,0.55)":"0 14px 40px rgba(24,32,48,0.16)","sb-thumb":i(o?.16:.2),"sb-thumb-hover":i(o?.24:.3),font:Mn,mono:zn,fs:"12.5px",radius:"7px","rail-w":"42px","topbar-h":"40px","status-h":"24px","ctl-h":"28px"},g={};for(const[e,t]of Object.entries(m))g[Sn+e]=t;return g}function Rn(e,t){for(const[o,n]of Object.entries(t))e.style.setProperty(o,n)}const Fn=e=>`var(${Sn}${e})`,Wn="oac-widget-css",Bn=`\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: ${Fn("bg")}; color: ${Fn("tx")}; font: ${Fn("fs")}/1.35 ${Fn("font")};\n  -webkit-font-smoothing: antialiased; overflow: hidden; }\n.oac-widget, .oac-widget * { box-sizing: border-box; }\n.oac-widget.oac-alert-host { position: absolute; inset: 0; display: block; background: transparent; pointer-events: none; z-index: 40; }\n.oac-widget[data-theme="dark"] { color-scheme: dark; }\n.oac-widget[data-theme="light"] { color-scheme: light; }\n.oac-widget button, .oac-widget input, .oac-widget select, .oac-widget textarea { font: inherit; color: inherit; }\n.oac-widget button { cursor: pointer; }\n.oac-widget kbd { font: 11px/1 ${Fn("mono")}; font-variant-numeric: tabular-nums; }\n.oac-widget [hidden] { display: none !important; }\n.oac-widget .oac-row:has(> .oac-input-error:not([hidden])) { flex-wrap: wrap; }\n.oac-widget .oac-input-error { flex-basis: 100%; min-width: 0; color: ${Fn("danger")}; font-size: 11px; overflow-wrap: anywhere; }\n.oac-widget .oac-row__ctl:has([data-input-action]) { flex-wrap: wrap; }\n.oac-widget .oac-row__ctl [data-input-action] { font-size: 11px; padding: 3px 7px; }\n.oac-widget [aria-invalid="true"] { border-color: ${Fn("danger")}; }\n.oac-widget .oac-input-pick { position: absolute; top: 8px; left: 50%; transform: translateX(-50%);\n  display: flex; align-items: center; gap: 8px; max-width: calc(100% - 16px); padding: 8px;\n  color: ${Fn("tx")}; background: ${Fn("panel")}; border: 1px solid ${Fn("bd")}; border-radius: 6px; pointer-events: auto; }\n\n/* Scrollbars: a thumb one step lighter than its panel, and no visible track. */\n.oac-widget * { scrollbar-width: thin; scrollbar-color: ${Fn("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: ${Fn("sb-thumb")}; border: 2px solid transparent;\n  background-clip: padding-box; border-radius: 999px; }\n.oac-widget ::-webkit-scrollbar-thumb:hover { background: ${Fn("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 ${Fn("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: ${Fn("acc")}; box-shadow: 0 0 0 3px ${Fn("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 ${Fn("bd")}; border-radius: 4px; background: ${Fn("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: ${Fn("bd-hover")}; }\n.oac-widget input[type=checkbox]:checked { background: ${Fn("acc")}; border-color: ${Fn("acc")}; }\n.oac-widget input[type=checkbox]:checked::after { content: ''; width: 4px; height: 8px; margin-top: -2px;\n  border: solid ${Fn("bg")}; border-width: 0 2px 2px 0; transform: rotate(45deg); }\n.oac-widget input[type=checkbox]:disabled { opacity: .4; cursor: not-allowed; }\n/* A radio is the checkbox's round sibling; the dot is an inset ring, which needs no pseudo-element. */\n.oac-widget input[type=radio] { appearance: none; -webkit-appearance: none; flex: none; margin: 0; width: 15px; height: 15px;\n  border: 1px solid ${Fn("bd")}; border-radius: 50%; background: ${Fn("elev")}; cursor: pointer; transition: background .12s, border-color .12s; }\n.oac-widget input[type=radio]:hover { border-color: ${Fn("bd-hover")}; }\n.oac-widget input[type=radio]:checked { border-color: ${Fn("acc")}; background: ${Fn("acc")}; box-shadow: inset 0 0 0 3px ${Fn("elev")}; }\n.oac-widget select { appearance: none; -webkit-appearance: none; height: ${Fn("ctl-h")}; padding: 0 24px 0 8px;\n  background: ${Fn("elev")}; border: 1px solid ${Fn("bd")}; border-radius: ${Fn("radius")}; cursor: pointer; }\n.oac-widget .oac-select { position: relative; display: inline-flex; }\n/* The chevron overlays the select rather than sitting beside it. selectBox\n   wraps the glyph in an oac-chev span, and this rule used to name\n   .oac-select > svg, which that markup has never had: the span stayed an\n   ordinary flex item, so it took eleven pixels of the row and left the select\n   eleven pixels short of every input beside it, with its arrow outside its own\n   box. Sized here rather than left to .oac-chev, whose inline-grid is right\n   where a chevron follows a word, as it does in the top bar. */\n.oac-widget .oac-select > .oac-chev { position: absolute; right: 7px; top: 50%; width: 11px; height: 11px;\n  transform: translateY(-50%); pointer-events: none; display: block; color: ${Fn("mut")}; }\n.oac-widget select option, .oac-widget select optgroup { background: ${Fn("panel")}; color: ${Fn("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: ${Fn("elev")}; border: 1px solid ${Fn("bd")}; border-radius: ${Fn("radius")}; }\n.oac-widget input[type=color]:hover { border-color: ${Fn("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: ${Fn("ctl-h")}; padding: 0 8px; background: ${Fn("elev")}; border: 1px solid ${Fn("bd")}; border-radius: ${Fn("radius")};\n  transition: border-color .15s, box-shadow .15s; }\n.oac-widget textarea { height: auto; padding: 6px 8px; }\n.oac-widget input::placeholder { color: ${Fn("faint")}; }\n.oac-widget input:hover, .oac-widget select:hover { border-color: ${Fn("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: ${Fn("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: ${Fn("acc")}; border: 0; }\n.oac-widget input[type=range]::-moz-range-track { height: 3px; border-radius: 2px; background: ${Fn("elev-3")}; }\n.oac-widget input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: ${Fn("acc")}; border: 0; }\n\n/* Section heads and rows shared by every panel. */\n.oac-widget .oac-head { padding: 8px 10px 4px; color: ${Fn("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: ${Fn("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 ${Fn("bd")}; border-radius: 50%; color: ${Fn("faint")};\n  font-size: 9px; font-weight: 600; line-height: 1; cursor: help; user-select: none; }\n.oac-widget .oac-help:hover { color: ${Fn("tx")}; border-color: ${Fn("bd-hover")}; }\n/* A heading's rows as one named group, laid out as if the box were not there. */\n.oac-widget .oac-form__group { display: contents; }\n\n/* Buttons: flat, 28px tall, a tint when pressed or active. */\n.oac-widget .oac-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px;\n  height: ${Fn("ctl-h")}; padding: 0 9px; background: transparent; border: 1px solid transparent;\n  border-radius: ${Fn("radius")}; color: ${Fn("tx")}; white-space: nowrap; transition: background .1s, border-color .1s, color .1s; }\n.oac-widget .oac-btn:hover { background: ${Fn("elev")}; border-color: ${Fn("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: ${Fn("on-bg")}; border-color: ${Fn("on-bd")}; color: ${Fn("acc-2")}; }\n.oac-widget .oac-btn.is-off, .oac-widget .oac-btn[aria-disabled="true"], .oac-widget .oac-btn:disabled {\n  color: ${Fn("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: ${Fn("ctl-h")}; padding: 0; }\n.oac-widget .oac-btn--primary { background: ${Fn("acc")}; color: ${Fn("bg")}; border-color: transparent; font-weight: 600; }\n.oac-widget .oac-btn--primary:hover { background: ${Fn("acc-2")}; border-color: transparent; }\n.oac-widget .oac-btn--danger:not(.is-off):hover { color: ${Fn("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: ${o.ICON_SIZE}px; height: ${o.ICON_SIZE}px; stroke-width: ${o.ICON_STROKE}; }\n.oac-widget .oac-glyph--chrome > svg { width: ${o.CHROME_ICON_SIZE}px; height: ${o.CHROME_ICON_SIZE}px; stroke-width: ${o.CHROME_ICON_STROKE}; }\n.oac-widget .oac-glyph--text { display: inline-grid; place-items: center; width: ${o.ICON_SIZE}px; height: ${o.ICON_SIZE}px;\n  font-size: 12px; font-weight: 600; }\n.oac-widget .oac-chev { display: inline-grid; place-items: center; line-height: 0; color: ${Fn("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: ${Fn("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: ${Fn("topbar-h")};\n  padding: 5px 8px; background: ${Fn("panel")}; border-bottom: 1px solid ${Fn("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: ${Fn("mut")}; font-size: 11px; text-decoration: none; white-space: nowrap; }\n.oac-widget .oac-topbar__branding:hover { color: ${Fn("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: ${Fn("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: ${Fn("mut")}; pointer-events: none; }\n.oac-widget .oac-sym__ex { margin-left: 6px; color: ${Fn("faint")}; font-size: 11px; font-weight: 600; letter-spacing: .5px; }\n.oac-widget .oac-pills { display: inline-flex; background: ${Fn("elev")}; border: 1px solid ${Fn("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: ${Fn("mut")}; font-weight: 600; font-size: 11.5px; letter-spacing: .2px; }\n.oac-widget .oac-pills > button:hover { color: ${Fn("tx")}; }\n.oac-widget .oac-pills > button[aria-pressed="true"] { background: ${Fn("elev-2")}; color: ${Fn("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: ${Fn("panel")}; border: 1px solid ${Fn("bd")}; border-radius: 9px; box-shadow: ${Fn("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: ${Fn("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: ${Fn("elev-2")}; outline: none; }\n.oac-widget .oac-menu__row[aria-checked="true"] { color: ${Fn("acc-2")}; }\n.oac-widget .oac-menu__row[aria-checked="true"]::before { content: ''; width: 6px; height: 6px; border-radius: 50%;\n  background: ${Fn("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: ${Fn("faint")}; cursor: default; background: transparent; }\n.oac-widget .oac-menu__row.is-danger:hover { color: ${Fn("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: ${Fn("faint")}; font-size: 11px; }\n.oac-widget .oac-menu__key { margin-left: auto; color: ${Fn("faint")}; }\n.oac-widget .oac-menu__empty { padding: 8px 10px; color: ${Fn("faint")}; }\n/* A hovered row is elev-2, where faint text no longer reads: its hints brighten with it. */\n.oac-widget .oac-menu__row:is(:hover, :focus-visible, .is-active) :is(.oac-menu__sub, .oac-menu__key),\n.oac-widget .oac-fly__row:is(:hover, :focus-visible) .oac-fly__chord { color: ${Fn("mut")}; }\n\n/* Stage: the rail on the left, the chart filling the rest. */\n.oac-widget .oac-stage { grid-row: 2; position: relative; min-height: 0; min-width: 0; display: flex; }\n.oac-widget .oac-chart { position: relative; flex: 1 1 auto; min-width: 0; min-height: 0;\n  cursor: var(--oac-tool-cursor, crosshair); }\n.oac-widget .oac-chart:focus-visible { outline-offset: -2px; }\n\n/* Data state stays compact inside a chart, including narrow embedded widgets. */\n.oac-widget .oac-data-status { position: absolute; top: 8px; right: 8px; z-index: 30;\n  max-width: calc(100% - 16px); width: max-content; max-height: 45%; overflow-y: auto;\n  display: flex; flex-direction: column; gap: 4px; pointer-events: none; font-size: 12px; }\n.oac-widget .oac-data-status__row { display: flex; align-items: center; gap: 8px;\n  max-width: 320px; padding: 4px 6px 4px 10px; background: ${Fn("panel")}; color: ${Fn("tx")};\n  border: 1px solid ${Fn("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: ${Fn("acc-2")}; }\n\n/* Rail */\n.oac-widget .oac-rail { flex: none; width: ${Fn("rail-w")}; display: flex; flex-direction: column; align-items: center;\n  gap: 2px; padding: 6px 0 0; background: ${Fn("panel-2")}; border-right: 1px solid ${Fn("bd-soft")};\n  overflow-y: auto; overflow-x: hidden; scrollbar-width: none; }\n.oac-widget .oac-rail::-webkit-scrollbar { width: 0; height: 0; }\n.oac-widget .oac-rail__btn { position: relative; width: 32px; height: 30px; padding: 0; display: grid; place-items: center;\n  flex: none; background: transparent; border: 1px solid transparent; border-radius: 6px; color: ${Fn("mut")};\n  transition: background .09s, color .09s, border-color .09s; }\n.oac-widget .oac-rail__btn:hover { background: ${Fn("elev")}; color: ${Fn("tx")}; }\n.oac-widget .oac-rail__btn:focus-visible { outline: 2px solid ${Fn("acc-2")}; outline-offset: -2px; }\n.oac-widget .oac-rail__btn.is-on { background: ${Fn("on-bg")}; border-color: ${Fn("on-bd")}; color: ${Fn("acc-2")}; }\n.oac-widget .oac-rail__btn.is-weak { color: ${Fn("acc-2")}; }\n.oac-widget .oac-rail__btn.is-off { color: ${Fn("faint")}; cursor: default; }\n.oac-widget .oac-rail__btn.is-off:hover { background: transparent; color: ${Fn("faint")}; }\n.oac-widget .oac-rail__btn--danger:not(.is-off):hover { color: ${Fn("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: ${Fn("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: ${Fn("elev-2")}; color: ${Fn("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: ${Fn("acc-2")}; }\n.oac-widget .oac-rail__btn[data-mode="weak"]::after { border: 1.5px solid ${Fn("acc-2")}; width: 4px; height: 4px; }\n.oac-widget .oac-rail__sep { width: 22px; height: 1px; background: ${Fn("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: ${Fn("panel-2")};\n  border-top: 1px solid ${Fn("bd-soft")}; flex: none; }\n/* Tools that scroll under the controls fade out instead of being cut through. */\n.oac-widget .oac-rail__ctl::before { content: ''; position: absolute; left: 0; right: 0; bottom: 100%; height: 14px;\n  background: linear-gradient(to bottom, transparent, ${Fn("panel-2")}); pointer-events: none; }\n.oac-widget .oac-rail__ctl .oac-rail__sep { margin: 3px 0; }\n.oac-widget .oac-rail.is-collapsed { display: none; }\n.oac-widget .oac-rail-tab { position: absolute; left: 0; bottom: 6px; z-index: 6; width: 16px; height: 26px; padding: 0;\n  display: grid; place-items: center; background: ${Fn("panel-2")}; color: ${Fn("mut")};\n  border: 1px solid ${Fn("bd-soft")}; border-left: 0; border-radius: 0 6px 6px 0;\n  transition: background .09s, color .09s, width .09s; }\n.oac-widget .oac-rail-tab:hover { width: 20px; background: ${Fn("elev")}; color: ${Fn("tx")}; }\n.oac-widget .oac-rail-tab:focus-visible { outline: 2px solid ${Fn("acc-2")}; outline-offset: -2px; }\n.oac-widget .oac-rail-tab > svg { width: 12px; height: 12px; }\n.oac-widget .oac-rail-tab[hidden] { display: none; }\n\n/* Rail flyout: a group's tools, with a pin star and the chord on each row. */\n.oac-widget .oac-fly { min-width: 244px; max-width: 320px; max-height: calc(100% - 16px); overflow-y: auto; padding: 6px;\n  background: ${Fn("panel")}; border: 1px solid ${Fn("bd")}; border-radius: 10px; box-shadow: ${Fn("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: ${Fn("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: ${Fn("elev-2")}; }\n.oac-widget .oac-fly__row[aria-checked="true"] { background: ${Fn("on-bg")}; color: ${Fn("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: ${Fn("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: ${Fn("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: ${Fn("elev")}; color: ${Fn("tx")}; }\n.oac-widget .oac-fly__star:focus-visible { outline: 2px solid ${Fn("acc-2")}; outline-offset: -1px; opacity: 1; }\n.oac-widget .oac-fly__star[aria-pressed="true"] { color: ${Fn("amber")}; }\n.oac-widget .oac-fly__star > svg { width: 14px; height: 14px; stroke: currentColor; stroke-width: 1.5;\n  stroke-linecap: round; stroke-linejoin: round; }\n.oac-widget .oac-fly__star[aria-pressed="false"] > svg { fill: none; }\n\n/* Tooltip */\n.oac-widget .oac-tip-spot { position: absolute; width: 1px; height: 1px; pointer-events: none; }\n.oac-widget .oac-tip { position: absolute; z-index: 200; left: 0; top: 0; max-width: 260px; pointer-events: none;\n  padding: 5px 9px; border-radius: 6px; background: ${Fn("elev-2")}; color: ${Fn("tx")}; border: 1px solid ${Fn("bd")};\n  box-shadow: ${Fn("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: ${Fn("mut")}; }\n/* The tip sits on elev-2, a step above the surfaces faint text is measured on. */\n.oac-widget .oac-tip__sub { display: block; margin-top: 2px; color: ${Fn("mut")}; font-size: 11px; }\n\n/* Status line */\n.oac-widget .oac-statusline { grid-row: 3; display: flex; align-items: center; gap: 12px; height: ${Fn("status-h")}; padding: 0 10px;\n  background: ${Fn("panel")}; border-top: 1px solid ${Fn("bd-soft")}; color: ${Fn("mut")}; font-size: 11.5px;\n  font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; }\n.oac-widget .oac-statusline__sym { color: ${Fn("tx-strong")}; font-weight: 600; letter-spacing: .3px; }\n.oac-widget .oac-statusline__iv { color: ${Fn("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: ${Fn("faint")}; }\n.oac-widget .oac-statusline__field > b { font-weight: 500; color: ${Fn("tx")}; }\n.oac-widget .oac-statusline .is-up > b { color: ${Fn("up")}; }\n.oac-widget .oac-statusline .is-down > b { color: ${Fn("down")}; }\n.oac-widget .oac-statusline__msg { margin-left: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; color: ${Fn("mut")}; }\n.oac-widget .oac-statusline__msg.is-error { color: ${Fn("danger")}; }\n.oac-widget .oac-statusline__tz { color: ${Fn("faint")}; }\n\n/* Narrow widget chrome */\n.oac-widget .oac-mobile { display: none; }\n.oac-widget.is-mobile { grid-template-rows: auto minmax(0, 1fr) auto; }\n.oac-widget.is-mobile > .oac-topbar, .oac-widget.is-mobile > .oac-statusline,\n.oac-widget.is-mobile > .oac-stage > :is(.oac-rail, .oac-rail-tab) { display: none; }\n.oac-widget.is-mobile > .oac-stage { grid-row: 2; }\n.oac-widget.is-mobile > .oac-mobile { display: contents; }\n.oac-widget .oac-mobile__header { grid-row: 1; z-index: 40; display: grid; grid-template-columns: minmax(0, 1fr) auto;\n  gap: 8px; min-height: 52px; padding: calc(4px + env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) 4px\n  max(8px, env(safe-area-inset-left)); background: ${Fn("panel")}; border-bottom: 1px solid ${Fn("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: ${Fn("panel")}; border-top: 1px solid ${Fn("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 ${Fn("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: ${Fn("tx")}; overflow-wrap: anywhere; touch-action: manipulation; }\n.oac-widget .oac-mobile__action:hover, .oac-widget .oac-mobile__action:focus-visible { background: ${Fn("elev")}; }\n.oac-widget .oac-mobile__action[aria-pressed="true"] { color: ${Fn("acc-2")}; background: ${Fn("on-bg")}; }\n.oac-widget .oac-mobile__action[aria-disabled="true"] { color: ${Fn("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 ${Fn("bd-soft")}; }\n.oac-widget .oac-mobile-sheet__title { flex: 1 1 auto; color: ${Fn("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 ${Fn("bd-soft")}; margin-bottom: 6px; }\n.oac-widget .oac-mobile-sheet__body small { display: block; color: ${Fn("faint")}; }\n/* A sheet row with a glyph (a chart type): the glyph sits on the middle of its label, not the baseline. */\n.oac-widget .oac-mobile-sheet .oac-mobile__action > .oac-glyph { vertical-align: middle; margin: -2px 8px 0 0; }\n.oac-widget .oac-mobile-results { width: min(360px, calc(100% - 16px)); max-height: min(50%, 360px); overflow: hidden;\n  display: flex; flex-direction: column; background: ${Fn("panel")}; border: 1px solid ${Fn("bd")}; border-radius: 10px; box-shadow: ${Fn("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 ${Fn("bd-soft")}; }\n.oac-widget .oac-mobile-results__head > strong { flex: 1 1 auto; color: ${Fn("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: ${Fn("faint")}; }\n.oac-widget .oac-mobile-results__status { min-height: 44px; padding: 13px 12px; color: ${Fn("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(${Fn("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: ${Fn("panel")}; color: ${Fn("tx")}; border: 1px solid ${Fn("bd")}; border-left: 3px solid ${Fn("acc")};\n  box-shadow: ${Fn("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: ${Fn("buy")}; }\n.oac-widget .oac-toast--error { border-left-color: ${Fn("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: ${Fn("faint")}; padding: 0; display: grid; place-items: center; }\n.oac-widget .oac-toast__x:hover { background: ${Fn("elev-2")}; color: ${Fn("tx")}; }\n.oac-widget .oac-toast__x > svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 1.5; }\n.oac-widget .oac-toast.is-out { opacity: 0; transform: translateY(6px); transition: opacity .16s, transform .16s; }\n@keyframes oac-toast-in { from { opacity: 0; transform: translateY(6px); } }\n\n/* Overlay layer: popovers anchored to a control, dialogs centred over a scrim. */\n.oac-widget .oac-layer { container: oac-widget / inline-size; position: absolute; inset: 0; z-index: 60; pointer-events: none; }\n/* Not the tooltip: it shows over controls (the rail's tab, the bar's buttons) and\n   must never take the press meant for them. */\n.oac-widget .oac-layer > :not(.oac-tip, .oac-tip-spot) { pointer-events: auto; }\n.oac-widget .oac-scrim { position: absolute; inset: 0; background: ${Fn("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: ${Fn("panel")}; border: 1px solid ${Fn("bd")}; border-radius: 12px; box-shadow: ${Fn("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: ${Fn("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 ${Fn("bd-soft")}; }\n.oac-widget .oac-dialog__foot > .oac-spacer { flex: 1 1 auto; }\n.oac-widget .oac-csv { width: 490px; }\n.oac-widget .oac-csv__ranges, .oac-widget .oac-csv .oac-dialog__actions { display: flex; flex-wrap: wrap; gap: 8px; }\n.oac-widget .oac-csv__hint { color: ${Fn("mut")}; line-height: 1.5; }\n.oac-widget .oac-csv__error { color: ${Fn("danger")}; overflow-wrap: anywhere; }\n.oac-widget .oac-csv__error:empty { display: none; }\n\n/* Point and figure and Renko settings: a size, its unit and its method share one control column. */\n.oac-widget .oac-ctset { width: 380px; }\n.oac-widget .oac-ctset .oac-row__ctl { width: min(244px, 66%); }\n.oac-widget .oac-ctset__presets { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; width: 100%; padding: 2px 0; }\n.oac-widget .oac-ctset__preset { height: 24px; padding: 0 4px; font-size: 11px; font-variant-numeric: tabular-nums;\n  background: ${Fn("elev")}; border-color: ${Fn("bd-soft")}; }\n.oac-widget .oac-ctset__size { display: flex; align-items: center; gap: 6px; width: 100%; min-width: 0; }\n.oac-widget .oac-ctset .oac-row__ctl .oac-ctset__size > input { flex: 1 1 0; width: auto; min-width: 0; }\n.oac-widget .oac-ctset .oac-input--num { text-align: right; font-variant-numeric: tabular-nums; }\n.oac-widget .oac-ctset .oac-row__ctl .oac-ctset__size > .oac-select { flex: 0 0 100px; width: 100px; }\n.oac-widget .oac-ctset__unit { flex: none; color: ${Fn("mut")}; font-size: 11px; white-space: nowrap; }\n.oac-widget .oac-ctset__radios { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px 14px; }\n.oac-widget .oac-ctset__radio { display: inline-flex; align-items: center; gap: 6px; color: ${Fn("tx")}; white-space: nowrap; cursor: pointer; }\n\n/* Shortcuts panel */\n.oac-widget .oac-keys { columns: 2; column-gap: 24px; min-width: 520px; }\n.oac-widget .oac-keys__group { break-inside: avoid; margin-bottom: 8px; }\n.oac-widget .oac-keys__row { display: flex; align-items: center; gap: 10px; padding: 3px 0; }\n.oac-widget .oac-keys__row > span { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }\n.oac-widget .oac-keys__row > kbd { flex: none; padding: 2px 6px; border-radius: 4px; background: ${Fn("elev")};\n  border: 1px solid ${Fn("bd-soft")}; color: ${Fn("mut")}; }\n.oac-widget .oac-keys__row.is-shadowed > span, .oac-widget .oac-keys__row.is-shadowed > kbd { color: ${Fn("faint")}; text-decoration: line-through; }\n.oac-widget .oac-keys__note { color: ${Fn("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 Un(e,t="",o){const n=e.getElementById(Wn);if(n?.textContent?.trim())return n;const a=n??e.createElement("style");return a.id=Wn,a.nonce||void 0===o||(a.nonce=o),a.textContent=Bn+t,null===n&&(e.head??e.body??e.documentElement).appendChild(a),a}function qn(e,t){const o=e.getElementById(Wn);null===o||(o.textContent??"").includes(t)||o.appendChild(e.createTextNode(t))}const Kn=/^(style|text|props)\./;function Gn(e){return"string"==typeof e||"boolean"==typeof e||"number"==typeof e&&Number.isFinite(e)||Array.isArray(e)}function Vn(e,t){const{draw:n,chart:a}=e;let i=null,r=!1;const s=new Set,l=e=>{r||null!==i&&e.revision<i.revision||(i=e,(()=>{for(const e of Array.from(s))e()})())},c=t.subscribe(l);t.load().then(l,()=>{r||e.status(R(e,"Drawing templates could not be loaded"),"error")});const d=e=>i?.defaults.find(t=>t.tool===e)?.values;function u(e){const t={};for(const[n,a]of Object.entries(o.readDrawingSettings(e,o.drawingSettingsSchema(e.tool))))Kn.test(n)&&"text.value"!==n&&Gn(a)&&(t[n]=a);return t}function p(e,t){const a=[];for(const i of T(n,e)){const e=n.get(i);if(void 0===e)continue;const r=o.applyDrawingSettings(e,t,o.drawingSettingsSchema(e.tool));Object.keys(r).length>0&&a.push({id:i,patch:r})}return a}let h=null;const m=[a.on("drawing:change",e=>{h=null;const t=e;if(r||"add"!==t.kind||void 0===t.step||!0===t.linked||1!==t.ids.length)return;const o=n.get(t.ids[0]);if(void 0===o||n.activeTool()!==o.tool||void 0===d(o.tool))return;const a=o.id;h=a,queueMicrotask(()=>{h===a&&(h=null)})}),a.on("draw:tool",()=>{const t=h;h=null;const o=null===t||r?void 0:n.get(t),a=void 0===o?void 0:d(o.tool);if(void 0===o||void 0===a)return;const i=p([o.id],a);if(0===i.length)return;const s=()=>{n.updateMany(i)};void 0===e.history||e.history.isDestroyed?n.untracked(s):e.history.ignore(s)})],g=async(t,o)=>{try{const n=await t();return r||e.toast(o,"success"),n}catch(t){throw r||e.toast(R(e,"The drawing template could not be saved: {error}",{error:F(e,t)}),"error"),t}},f=t=>{const o=n.get(t);if(void 0===o)throw new Error(R(e,"Select a drawing first"));return o},b=t=>R(e,`schema.drawing.${t}.name`,{},E(t)?.name??t);return{store:t,catalog:()=>i,templatesFor:e=>i?.templates.filter(t=>t.tool===e)??[],defaultFor:d,capture:u,apply:function(e,t){const o=p(e,t);return o.length>0&&n.updateMany(o),o.length},saveDefault:async o=>{const n=f(o);await g(()=>t.setDefault(n.tool,u(n)),R(e,"New {tool} drawings start with this look",{tool:b(n.tool)}))},clearDefault:async o=>{await g(()=>t.setDefault(o,null),R(e,"New {tool} drawings start with the standard look",{tool:b(o)}))},saveTemplate:async(o,n)=>{const a=f(o);return g(()=>t.saveTemplate(n,a.tool,u(a)),R(e,"Saved the template {name}",{name:n.trim()}))},removeTemplate:async o=>{await g(()=>t.removeTemplate(o),R(e,"Removed the template"))},subscribe:e=>(s.add(e),()=>{s.delete(e)}),destroy:()=>{if(!r){r=!0;for(const e of m)e();c(),s.clear()}}}}function Hn(e,t,o,n){const a=o.map(t=>e.draw.get(t)).filter(e=>void 0!==e),i=1===new Set(a.map(e=>e.tool)).size?a[0].tool:null,r=a[0],s=T(e.draw,o).length>0,l=[R(e,"Templates")],c=e=>{e().catch(()=>{})};l.push({label:R(e,"Save as default for this tool"),sub:null===i?R(e,"one tool at a time"):void 0,disabled:null===i,onSelect:()=>{void 0!==r&&c(()=>t.saveDefault(r.id))}}),null!==i&&void 0!==t.defaultFor(i)&&l.push({label:R(e,"Forget the default for this tool"),onSelect:()=>c(()=>t.clearDefault(i))}),l.push({label:R(e,"Save as template..."),disabled:null===i,onSelect:()=>{void 0!==r&&Zn(e,n,e=>t.saveTemplate(r.id,e))}});const d=null===i?[]:t.templatesFor(i);for(const n of d)l.push({label:R(e,"Apply {name}",{name:n.name}),disabled:!s,sub:s?void 0:R(e,"read-only"),onSelect:()=>{O(e,"template",()=>t.apply(o,n.values))}});return l}let Jn=0;function Zn(e,t,o){const n=e.document,a=ct(n,{translate:e.translate,title:R(e,"Save as template"),className:"oac-template-name",onClose:()=>d.close()}),i=nt(n,"label","oac-template-name__label",R(e,"Template name")),r=nt(n,"input","oac-template-name__input");r.type="text",r.maxLength=120,r.id="oac-template-name-"+ ++Jn,i.htmlFor=r.id;const s=nt(n,"p","oac-input-error");s.setAttribute("role","alert"),s.hidden=!0,a.body.append(i,r,s);let l=!1;const c=async()=>{const t=r.value.trim();if(!l){if(""===t)return s.textContent=R(e,"Enter a name"),s.hidden=!1,r.setAttribute("aria-invalid","true"),void r.focus();l=!0;try{await o(t),d.close()}catch(t){s.textContent=F(e,t),s.hidden=!1,r.setAttribute("aria-invalid","true")}finally{l=!1}}};r.addEventListener("keydown",e=>{"Enter"===e.key&&(e.preventDefault(),c())}),r.addEventListener("input",()=>{s.hidden=!0,r.removeAttribute("aria-invalid")}),a.actions.appendChild(it(n,{label:R(e,"Cancel"),onClick:()=>d.close()}));a.actions.appendChild(it(n,{label:R(e,"Save"),variant:"primary",onClick:()=>{c()}})).dataset.action="save-template";const d=ut(e,a.el,void 0===t?{placement:"center",modal:!0,initialFocus:r}:{anchor:t,placement:"below",initialFocus:r},()=>{});return d}const Yn="\n.oac-widget .oac-template-name { width: 300px; }\n.oac-widget .oac-template-name .oac-dialog__body { display: flex; flex-direction: column; gap: 6px; padding-top: 8px; }\n.oac-widget .oac-template-name__label { color: var(--oac-mut); font-size: 11px; }\n.oac-widget .oac-template-name__input { width: 100%; }\n",Qn=/^(\d{4})-(\d{2})-(\d{2})$/,Xn=/^(\d{2}):(\d{2})(?::(\d{2}))?$/,ea=e=>String(e).padStart(2,"0");function ta(e,o,n){const a=t.utcSecondsToZonedParts(e,o),i=n??0!==a.second;return{date:`${a.year}-${ea(a.month)}-${ea(a.day)}`,time:`${ea(a.hour)}:${ea(a.minute)}${i?`:${ea(a.second)}`:""}`,seconds:i}}function oa(e,o,n,a={}){const i=Qn.exec(e.trim()),r=o.trim(),s=Xn.exec(r);if(null===i||null===s&&(""!==r||void 0===a.blank))return null;const[l,c,d]=[Number(i[1]),Number(i[2]),Number(i[3])],u=new Date(Date.UTC(l,c-1,d));if(u.getUTCMonth()!==c-1||u.getUTCDate()!==d)return null;if(null===s){const e="end"===a.blank?t.zonedWallClockToUtcSeconds(l,c,d+1,0,0,0,n)-1:t.zonedWallClockToUtcSeconds(l,c,d,0,0,0,n);return Number.isFinite(e)?e:null}const[p,h]=[Number(s[1]),Number(s[2])],m=void 0!==s[3]?Number(s[3]):!0===a.end?59:0;if(p>23||h>59||m>59)return null;const g=t.zonedWallClockToUtcSeconds(l,c,d,p,h,m,n);if(!Number.isFinite(g))return null;if(!0===a.rejectSkipped){const e=ta(g,n,!0);if(e.date!==`${i[1]}-${i[2]}-${i[3]}`||e.time!==`${ea(p)}:${ea(h)}:${ea(m)}`)return null}return g}let na=0;function aa(e,t,o,n){const{chart:a,draw:i}=e,r=e.document,s=nt(r,"div","oac-coords");t.appendChild(s);const l=new Map;let c=a.timezone(),d=!1;function u(e,t,o){const n=ta(o.time,c),i=function(e,t){const o=e.toFixed(Math.max(0,Math.min(10,t)));return Number(o)===e?o:String(Number(e.toFixed(10)))}(o.price,(e=>{const t=a.panes()[e.paneIndex]?.priceScale.precision();return Math.max(2,void 0!==t&&Number.isFinite(t)?Math.round(t):0)})(t));e.date.value=n.date,e.time.step=n.seconds?"1":"60",e.time.value=n.time,e.price.value=i,e.shown={date:n.date,time:n.time,price:i},e.error.hidden=!0,e.error.textContent="";for(const t of[e.date,e.time,e.price])t.removeAttribute("aria-invalid")}function p(e,t,o){e.error.textContent=o,e.error.hidden=!1,t.setAttribute("aria-invalid","true")}function h(t,o,r){const s=i.get(t),l=s?.points[o];if(d||void 0===s||void 0===l||null!==n())return;for(const e of[r.date,r.time,r.price])e.removeAttribute("aria-invalid");r.error.hidden=!0;let h=l.time;if(r.date.value!==r.shown.date||r.time.value!==r.shown.time){const t=oa(r.date.value,r.time.value,c);if(null===t){return void p(r,null!==oa(r.date.value,"00:00",c)?r.time:r.date,R(e,"Enter a date and a time on the chart clock"))}h=t}let m=l.price;if(r.price.value!==r.shown.price){const t=function(e){const t=e.trim().replace(/[\s,]/g,"");if(!/^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[-+]?\d+)?$/i.test(t))return null;const o=Number(t);return Number.isFinite(o)?o:null}(r.price.value);if(null===t)return void p(r,r.price,R(e,"Enter a price as a number"));if(t<=0&&(e=>"logarithmic"===a.panes()[e.paneIndex]?.priceScale.options.mode)(s))return void p(r,r.price,R(e,"A logarithmic scale needs a price above zero"));m=t}if(h===l.time&&m===l.price)return;const g=s.points.map((e,t)=>t===o?{...e,time:h,price:m}:{...e});i.update(t,{points:g});const f=i.get(t),b=f?.points[o];void 0!==f&&void 0!==b&&u(r,f,b)}function m(t,o){const n=nt(r,"div","oac-coords__row");n.dataset.anchor=`${t}:${o}`;const a="oac-coords-"+ ++na,i=nt(r,"label","oac-coords__label",R(e,"Point {number}",{number:o+1}));i.htmlFor=`${a}-date`;const s=nt(r,"input","oac-coords__date");s.type="date",s.id=`${a}-date`;const l=nt(r,"input","oac-coords__time");l.type="time";const c=nt(r,"input","oac-coords__price");c.type="text",c.setAttribute("inputmode","decimal"),c.setAttribute("spellcheck","false"),c.autocomplete="off";const d=nt(r,"p","oac-input-error");d.setAttribute("role","alert"),d.hidden=!0;const u={el:n,date:s,time:l,price:c,error:d,shown:{date:"",time:"",price:""}},p=t=>R(e,"{field} of point {number}",{field:t,number:o+1});s.setAttribute("aria-label",p(R(e,"Date"))),l.setAttribute("aria-label",p(R(e,"Time"))),c.setAttribute("aria-label",p(R(e,"Price")));for(const e of[s,l,c])e.addEventListener("keydown",e=>{"Enter"===e.key&&(e.preventDefault(),h(t,o,u))});n.addEventListener("focusout",e=>{const a=e.relatedTarget;null!==a&&n.contains(a)||h(t,o,u)});const m=nt(r,"div","oac-coords__fields");return m.append(s,l,c),n.append(i,m,d),u}function g(e){s.appendChild(nt(r,"p","oac-coords__note",e))}let f="";function b(){if(d)return;const t=r.activeElement,p=null!==t&&s.contains(t),h=p?t.closest("[data-anchor]")?.dataset.anchor:void 0;c=a.timezone();const b=n(),v=o().map(e=>i.get(e)).filter(e=>void 0!==e),w=JSON.stringify([c,v.map(e=>[e.id,e.tool,e.space??"data",e.points.length])]),y=w!==f;f=w;const _=new Set;if(y){s.replaceChildren();const t=nt(r,"div","oac-coords__head");t.append(nt(r,"span","",R(e,"Date")),nt(r,"span","",R(e,"Time")),nt(r,"span","",R(e,"Price"))),s.append(t,nt(r,"p","oac-coords__zone",R(e,"Times are on the chart clock, {zone}.",{zone:c})))}for(const t of v){const o=E(t.tool);if(y&&v.length>1&&s.appendChild(nt(r,"div","oac-head",R(e,`schema.drawing.${t.tool}.name`,{},o?.name??t.tool))),"viewport"===t.space){y&&g(R(e,"Pinned to the screen: its anchors are not a time and a price."));continue}if(!0===o?.freehand){y&&g(R(e,"A freehand stroke has {count} points. Move it on the chart.",{count:t.points.length}));continue}const n=null!==b||0===T(i,[t.id]).length;t.points.forEach((o,a)=>{const i=`${t.id}:${a}`;_.add(i);let r=l.get(i);void 0===r&&(r=m(t.id,a),l.set(i,r)),i!==h&&u(r,t,o);for(const t of[r.date,r.time,r.price])t.disabled=n,t.title=n?b??R(e,"read-only"):"";y&&s.appendChild(r.el)})}for(const e of[...l.keys()])_.has(e)||l.delete(e);if(p&&!s.contains(t)&&void 0!==h){const e=l.get(h),o=void 0===e?void 0:[e.date,e.time,e.price].find(e=>e.className===t.className);o?.focus()}}const v=[a.on("timezone:changed",b)];return b(),{el:s,refresh:b,destroy:()=>{if(!d){d=!0;for(const e of v)e();l.clear(),s.remove()}}}}const ia="\n.oac-widget .oac-coords { display: flex; flex-direction: column; gap: 4px; min-width: 0; }\n.oac-widget .oac-coords__head, .oac-widget .oac-coords__fields { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 1fr); align-items: center; gap: 6px; }\n.oac-widget .oac-coords__head { order: -1; color: var(--oac-faint); font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; padding: 2px 0 0; }\n.oac-widget .oac-coords__zone { margin: 0 0 4px; color: var(--oac-faint); font-size: 11px; }\n.oac-widget .oac-coords__row { display: flex; flex-direction: column; gap: 3px; }\n.oac-widget .oac-coords__label { color: var(--oac-mut); font-size: 11px; }\n.oac-widget .oac-coords input { min-width: 0; width: 100%; height: var(--oac-ctl-h); padding: 0 6px; border: 1px solid var(--oac-bd);\n  border-radius: var(--oac-radius); background: var(--oac-elev); color: var(--oac-tx); color-scheme: inherit; font-variant-numeric: tabular-nums; }\n.oac-widget .oac-coords input:disabled { opacity: .6; cursor: not-allowed; }\n.oac-widget .oac-coords .oac-input-error { margin: 0; }\n.oac-widget .oac-coords__note { margin: 4px 0; color: var(--oac-mut); font-size: 12px; overflow-wrap: anywhere; }\n",ra=[0,.236,.382,.5,.618,.786,1,1.272,1.414,1.618,2,2.618,3.618,4.236],sa=(e,t)=>e.some(e=>Math.abs(e.ratio-t)<=1e-6);function la(e,t,n={}){const a=e.document,i=n.ids??e.draw.selection(),{drawings:r,schema:s}=function(e,t){const n=[];for(const a of t){const t=e.draw.get(a);void 0!==t&&!1!==t.policy?.editable&&o.drawingSettingsSchema(t.tool).fields.some(e=>"levels"===e.kind)&&n.push(t)}return{drawings:n,schema:0===n.length?null:o.drawingSettingsSchema(n[0].tool)}}(e,i);if(null===s)return dt(e,R(e,"Select a drawing with levels first"));const l=r[0],c=E(l.tool),d=s.fields.find(e=>"levels"===e.kind),u=s.fields.find(e=>"style.showLabels"===e.path),p=d?.path??"style.levels",h=c?.defaultStyle?.levels??o.DEFAULT_FIB,m="gann-fan"===(g=l.tool)?o.gannLabel:"fib-time-zone"===g?e=>String(e):o.formatRatio;var g;const f=()=>{const e=o.readDrawingSetting(l,p);return Array.isArray(e)?o.cloneLevels(e):o.cloneLevels(h)},b=()=>{const e=o.readDrawingSetting(l,"style.showLabels");return void 0===e?!0===c?.defaultStyle?.showLabels:!0===e};let v=f();function w(t){const n=[];for(const a of r){const i=e.draw.get(a.id);if(void 0===i)continue;const r=o.applyDrawingSettings(i,t,s);Object.keys(r).length>0&&n.push({id:a.id,patch:r})}n.length>0&&e.draw.updateMany(n)}const y=()=>w({[p]:o.cloneLevels(v)}),_=nt(a,"div","oac-panel oac-levels");_.setAttribute("role","dialog"),_.setAttribute("aria-label",R(e,"Levels")),_.tabIndex=-1,st(_);const x=nt(a,"div","oac-levels__head");x.appendChild(nt(a,"b","oac-levels__title",R(e,"Levels")));let k=null;if(void 0!==u){const t=nt(a,"label","oac-levels__labels");k=nt(a,"input"),k.type="checkbox",k.checked=b(),k.dataset.path=u.path;const o=k;o.addEventListener("change",()=>w({[u.path]:o.checked})),t.appendChild(o),t.appendChild(nt(a,"span",void 0,R(e,"Show labels"))),x.appendChild(t)}x.appendChild(it(a,{label:R(e,"Close"),icon:"close",iconOnly:!0,onClick:()=>P.close()})),_.appendChild(x);const C=nt(a,"div","oac-levels__rows");_.appendChild(C);let S=[];function A(){S.forEach(e=>e.destroy()),S=[],C.innerHTML="",0!==v.length?v.forEach((t,n)=>C.appendChild(function(t,n){const i=nt(a,"div","oac-levels__row"+(!1===t.enabled?" is-off":"")),r=nt(a,"input");r.type="checkbox",r.checked=!1!==t.enabled,r.addEventListener("change",()=>{r.checked?delete v[n].enabled:v[n].enabled=!1,i.classList.toggle("is-off",!r.checked),y()}),i.appendChild(r);const s=nt(a,"input");s.type="number",s.step="0.001",s.value=String(t.ratio),s.addEventListener("change",()=>{const e=Number(s.value);""!==s.value.trim()&&Number.isFinite(e)?(v[n].ratio=e,void 0===v[n].label&&(d.placeholder=m(e)),p(),y()):s.value=String(v[n].ratio)}),i.appendChild(s);const c=Ge(a,{id:`oac-level-${l.id}-${n}`,label:R(e,"Level {level} color",{level:m(t.ratio)}),value:t.color??l.style.color??o.levelColor(t.ratio)??o.LEVEL_NEUTRAL,translate:e.translate,openOverlay:e.openOverlay,onChange:e=>{v[n].color=e,y()}});S.push(c),i.appendChild(c.el);const d=nt(a,"input");d.type="text",d.value=t.label??"",d.placeholder=m(t.ratio),d.setAttribute("spellcheck","false"),d.addEventListener("change",()=>{const e=d.value.trim();""===e?delete v[n].label:v[n].label=e,y()}),i.appendChild(d);const u=nt(a,"button","oac-levels__x");function p(){const t=m(v[n].ratio);r.setAttribute("aria-label",R(e,"Level {level} enabled",{level:t})),s.setAttribute("aria-label",R(e,"Level {level} ratio",{level:t})),c.trigger.setAttribute("aria-label",R(e,"Level {level} color",{level:t})),d.setAttribute("aria-label",R(e,"Level {level} label",{level:t})),u.setAttribute("aria-label",R(e,"Remove level {level}",{level:t}))}return u.type="button",u.appendChild(at(a,"close")),u.addEventListener("click",e=>{e.stopPropagation(),v.splice(n,1),A(),y()}),i.appendChild(u),p(),i}(t,n))):C.appendChild(nt(a,"div","oac-empty",R(e,"No levels. Add one, or reset to the defaults.")))}A();const T=nt(a,"div","oac-levels__foot");T.appendChild(it(a,{label:R(e,"Add level"),icon:"plus",onClick:()=>{const e=function(e){for(const t of ra)if(!sa(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}(v),t={ratio:e},n=o.levelColor(e);n!==o.LEVEL_NEUTRAL&&(t.color=n),v.push(t),A(),y()}})),T.appendChild(nt(a,"span","oac-spacer")),T.appendChild(it(a,{label:R(e,"Reset"),onClick:()=>{v=o.cloneLevels(h),A(),y()}})),_.appendChild(T);const L=e.chart.on("draw:update",()=>{if(!P.isOpen())return;if(void 0===e.draw.get(l.id))return void P.close();const t=f();JSON.stringify(t)===JSON.stringify(v)||_.contains(a.activeElement)||(v=t,A()),null!==k&&k!==a.activeElement&&(k.checked=b())}),O=e.chart.on("draw:remove",()=>{P.isOpen()&&void 0===e.draw.get(l.id)&&P.close()}),I=()=>{S.forEach(e=>e.destroy()),L(),O()},P=ut(e,_,void 0===t?{placement:"below",dismissOnOutside:!0}:{anchor:t,placement:"below"},I);void 0===t&&mt(e.root,_,{point:pt(e.root,e.chart,r)});const $=P.close;return{el:_,isOpen:P.isOpen,close:()=>{I(),$()}}}function ca(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 da(e,t,o,n){const a=o.split("\n");if(!0!==t.wrap)return a;const i=[];for(const t of a){const o=t.split(/\s+/).filter(e=>""!==e);if(0===o.length){i.push("");continue}let a=o[0];for(let t=1;t<o.length;t++){const r=`${a} ${o[t]}`;e(r)>n?(i.push(a),a=o[t]):a=r}i.push(a)}return i}function ua(e){let t="",o=!1;const n=e=>{for(const a of Array.from(e.childNodes??[])){if(3===a.nodeType){t+=a.nodeValue??"",o=!1;continue}if(1!==a.nodeType)continue;const e=String(a.nodeName).toUpperCase();"BR"!==e?("DIV"!==e&&"P"!==e||""===t||t.endsWith("\n")||(t+="\n"),o=!1,n(a)):(t+="\n",o=!0)}};return n(e),o?t.slice(0,-1):t}function pa(e){return e.panes()[0]?.element.parentElement??null}function ha(e){return void 0!==e&&!0===o.drawingSettingsSchema(e.tool).textIsContent}function ma(e,t,o){const n=dt(e,t);return o?.(!1),{...n,commit:()=>{},cancel:()=>{}}}function ga(e,t,o={}){const n=e.document,{chart:a,draw:i}=e,r=i.selection(),s=o.id??(1===r.length?r[0]:void 0),l=void 0===s?void 0:i.get(s);if(!ha(l))return ma(e,R(e,"Select a text drawing first"),o.onDone);if(!1===l.policy?.editable)return ma(e,R(e,"read-only"),o.onDone);const c=E(l.tool),d=void 0!==c?.defaultText?.value&&""!==c.defaultText.value?c.defaultText.value:R(e,"Text"),u=l.text??{value:""},p=u.fontSize??14,h=ca(u,p),m=function(e,t,o){let n=null;try{const t=e.createElement("canvas");n="function"==typeof t.getContext?t.getContext("2d"):null}catch{n=null}if(null!==n&&"function"==typeof n.measureText){n.font=t;const e=n;return t=>e.measureText(t).width}return e=>e.length*o*.6}(n,h,p),g=function(e,t,o,n="Text",a){const i=t.points[0],r=a??(void 0===i?null:{x:e.timeToCoordinate(i.time),y:e.priceToCoordinate(i.price,t.paneIndex)});if(null===r)return null;const{x:s,y:l}=r;if(!Number.isFinite(s)||null===l||!Number.isFinite(l))return null;const c=t.text??{value:""},d=c.fontSize??14,u=ca(c,d),p=da(o,c,void 0===c.value||""===c.value?n:c.value,c.wrapWidth??220);let h=0;for(const e of p)h=Math.max(h,o(e));const m=1.35*d,g=p.length*m+10,f=c.valign??"top";return{x:s,y:"middle"===f?l-g/2:"bottom"===f?l-g:l,width:h+10,height:g,lineHeight:m,lines:p,font:u,size:d}}(a,l,m,d,"viewport"===l.space?i.screenPoints(l.id)?.[0]??null:void 0),f=pa(a);if(null===g||null===f)return ma(e,R(e,"That text is off the chart"),o.onDone);const b=w(e.root,f),v=nt(n,"div","oac-textedit");v.setAttribute("contenteditable","plaintext-only"),v.setAttribute("spellcheck","false"),v.setAttribute("role","textbox"),v.setAttribute("aria-multiline","true"),v.setAttribute("aria-label",R(e,"Drawing text")),v.tabIndex=0;const y=v.style;y.left=`${Math.round(g.x+b.left)}px`,y.top=`${Math.round(g.y+b.top)}px`,y.font=h,y.lineHeight=`${g.lineHeight}px`,y.color=u.color??l.style.color??"inherit",y.textAlign=u.align??"left",y.minWidth=`${Math.ceil(g.width)}px`,y.minHeight=`${Math.ceil(g.height)}px`;const _=!0===u.wrap,x=u.wrapWidth??220;y.whiteSpace=_?"pre-wrap":"pre",_&&(y.width=`${Math.ceil(g.width)}px`);const k=u.value??"";v.textContent=k;let C=!1;const S=e=>{C||(C=!0,L.close(),o.onDone?.(e))},A=()=>{if(C)return;const e=ua(v),t=e!==k;t&&void 0!==i.get(l.id)&&i.update(l.id,{text:{...i.get(l.id)?.text??{value:""},value:e}}),S(t)},T=()=>S(!1);for(const e of["pointerdown","pointermove","pointerup","click","dblclick","contextmenu","keyup","keypress"])v.addEventListener(e,e=>{e.stopPropagation()});v.addEventListener("keydown",e=>{const t=e.key;if("Tab"!==t&&e.stopPropagation(),"Escape"===t)return e.preventDefault(),void T();"Enter"===t&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),A())}),v.addEventListener("blur",()=>A()),_&&v.addEventListener("input",()=>{const e=da(m,u,ua(v)||d,x);let t=0;for(const o of e)t=Math.max(t,m(o));y.width=`${Math.ceil(t+10)}px`});const L=ut(e,v,{placement:"below",modal:!1,dismissOnOutside:!1,initialFocus:v},T);try{const e=n.defaultView;if(null!==e&&"function"==typeof e.getSelection&&"function"==typeof n.createRange){const t=n.createRange();t.selectNodeContents(v),t.collapse(!1);const o=e.getSelection();o?.removeAllRanges(),o?.addRange(t)}}catch{}return{el:v,isOpen:L.isOpen,close:()=>A(),commit:A,cancel:T}}function fa(e){const t=e.map(e=>o.drawingSettingsSchema(e));if(0===t.length)return{fields:[]};const[n,...a]=t,i=n.fields.filter(e=>a.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 ba={"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 va(e,t,o){const n={};for(const a of t.fields){const[t,i]=a.path.split("."),r="style"===t?e?.defaultStyle:"text"===t?e?.defaultText:void 0;let s=void 0===r||void 0===i?void 0:r[i];void 0===s&&(s=ba[a.path]),void 0===s&&"boolean"===a.kind&&(s=!1),void 0===s&&"style.color"===a.path&&(s=o),void 0!==s&&(n[a.path]=s)}return n}function wa(e,t,n,a){const i=va(n,t,a);for(const[n,a]of Object.entries(o.readDrawingSettings(e,t)))void 0!==a&&(i[n]=a);for(const e of["text.color","style.fillColor","text.borderColor"])void 0===i[e]&&t.fields.some(t=>t.path===e)&&(i[e]=i["style.color"]);return i}const ya=(e,t)=>e.length===t.length&&e.every((e,o)=>e===t[o]);function _a(e,t,n={}){const{draw:a,chart:i}=e,r=e.document;void 0!==n.ids&&n.ids.length>0&&!ya(n.ids,a.selection())&&a.select(n.ids.slice());let s=a.selection().slice();const l=()=>s.map(e=>a.get(e)).filter(e=>void 0!==e);let c=l();if(0===c.length)return dt(e,R(e,"Select a drawing first"));let d=fa(c.map(e=>e.tool)),u=E(c[0].tool),p=null,h=null;const m=()=>1===c.length?R(e,`schema.drawing.${c[0].tool}.name`,{},u?.name??c[0].tool):R(e,"{count} drawings",{count:c.length}),g=()=>0===T(a,s).length?R(e,"read-only"):null,f=()=>wa(c[0],d,u,e.chartTheme.lineColor);function b(t){const n=[];for(const e of c){const i=a.get(e.id);if(void 0===i)continue;const r=o.applyDrawingSettings(i,t,d);Object.keys(r).length>0&&n.push({id:e.id,patch:r})}n.length>0&&a.updateMany(n),"string"==typeof t.space&&c.some(e=>(a.get(e.id)?.space??"data")!==t.space)&&e.toast(R(e,"The anchor changes only while the drawing's pane is on screen"),"info")}const v=ct(r,{translate:e.translate,title:m(),className:"oac-props",onClose:()=>z.close()}),w=nt(r,"div","oac-props__tools");w.setAttribute("role","toolbar"),w.setAttribute("aria-label",R(e,"Drawing actions")),v.el.insertBefore(w,v.body);const y=nt(r,"div","oac-props__pane"),_=nt(r,"div","oac-props__pane oac-props__anchors");let x=n.tab??"style";const k=ht(r,[{id:"style",label:R(e,"Style"),icon:"brush"},{id:"coordinates",label:R(e,"Coordinates"),icon:"coordinates"}],x,"row",e=>{x=e,S()});v.body.append(k.el,y,_);let C=null;function S(){y.hidden="style"!==x,_.hidden="coordinates"!==x,"coordinates"===x&&null===C&&(C=aa(e,_,()=>s,g))}function A(){w.innerHTML="";const t=xt(e,s),o=(t,o,n,a=null)=>{const i=it(r,{...t,iconOnly:!0,onClick:()=>{kt(e,o,s)}});i.dataset.act=o,void 0!==n&&i.setAttribute("aria-pressed",n?"true":"false"),null!==a&&(i.disabled=!0,i.title+=` (${a})`),w.appendChild(i)},n=()=>{w.appendChild(nt(r,"span","oac-sep"))};o({label:R(e,"Lock"),icon:t.locked?"lock":"unlock"},"lock",t.locked,t.readOnly),o({label:R(e,"Hide"),icon:t.hidden?"eye-off":"eye"},"visible",t.hidden,t.readOnly),n(),o({label:R(e,"Bring to front"),icon:"front"},"front"),o({label:R(e,"Send to back"),icon:"back"},"back"),o({label:R(e,"In front of the series"),icon:"above-series"},"above","above"===t.side),o({label:R(e,"Behind the series"),icon:"behind-series"},"behind","behind"===t.side),n(),o({label:R(e,"Duplicate"),icon:"duplicate",chord:ze(e.keymap,"duplicate","Mod+D")},"duplicate"),o({label:R(e,"Delete"),icon:"trash",chord:ze(e.keymap,"delete","Delete"),variant:"danger"},"delete",void 0,t.noDelete),O.disabled=null!==t.readOnly}function L(){p?.destroy(),y.innerHTML="";const t=ot(d.fields,{translate:e.translate,scope:`drawing.${c[0].tool}`});if(0===t.length)return y.appendChild(nt(r,"div","oac-empty",R(e,"These drawings share no settings."))),void(p=null);const o=h=g();if(p=ft(y,t,{values:f(),translate:e.translate,openOverlay:e.openOverlay,idPrefix:"oac-props",unavailable:()=>o,onChange:(e,t)=>{b({[e]:t}),p?.sync(f())},custom:t=>{if("levels"!==t.custom)return null;const n=it(r,{label:R(e,"Edit levels..."),onClick:t=>{la(e,t.currentTarget,{ids:s})}});return n.dataset.act="edit-levels",n.disabled=null!==o,n}}),!0===d.textIsContent&&1===c.length){const t=y.querySelector('[data-key="text.value"]');if(null!==t){const n=it(r,{label:R(e,"Edit text"),icon:"text",onClick:()=>{ga(e,0,{id:c[0].id})}});n.dataset.act="edit-text",n.disabled=null!==o,t.appendChild(n)}}}const O=v.lead.appendChild(it(r,{label:R(e,"Restore defaults"),onClick:()=>{const t={},o=va(u,{fields:d.fields},e.chartTheme.lineColor);for(const e of d.fields){if("levels"===e.kind)continue;const[n,a]=e.path.split("."),i="style"===n?u?.defaultStyle:"text"===n?u?.defaultText:void 0,r=void 0===i||void 0===a?void 0:i[a];t[e.path]=void 0===r?void 0:o[e.path]}b(t),p?.sync(f())}})),I=e.drawingTemplates;if(void 0!==I){const t=v.lead.appendChild(it(r,{label:R(e,"Templates"),onClick:()=>{vt(e,t,Hn(e,I,s,t),{ariaLabel:R(e,"Templates")})}}));t.dataset.act="templates",t.setAttribute("aria-haspopup","menu")}function P(){if(!z.isOpen())return;const e=a.selection().slice();if(0!==e.length){if(ya(e,s))return c=l(),0===c.length?void z.close():(g()!==h?L():p?.sync(f()),A(),void C?.refresh());s=e,c=l(),0!==c.length?(d=fa(c.map(e=>e.tool)),u=E(c[0].tool),v.setTitle(m()),A(),L(),C?.refresh()):z.close()}else z.close()}v.actions.appendChild(it(r,{label:R(e,"Done"),variant:"primary",onClick:()=>z.close()})),A(),L(),S();const $=[i.on("draw:update",P),i.on("draw:select",P),i.on("draw:remove",P)];let j=!1;const D=()=>{if(!j){j=!0,p?.destroy(),C?.destroy();for(const e of $)e();n.onClose?.()}},M=ut(e,v.el,{...void 0===t?{placement:"below",dismissOnOutside:!0}:{anchor:t,placement:"below"},onClose:D},D);void 0===t&&mt(e.root,v.el,{point:pt(e.root,i,c,e=>a.screenPoints(e))});const z={el:v.el,isOpen:M.isOpen,close:()=>{p?.destroy(),M.close(),D()}};return z}const xa=V(()=>Promise.resolve().then(function(){return Bl}));function ka(e,o,n={}){const{chart:a}=e,i=e.document,r=t.registeredIndicators(),s=ct(i,{translate:e.translate,title:R(e,"Indicators"),className:"oac-pick",onClose:()=>A.close()}),l=nt(i,"input","oac-pick__find");l.type="search",l.placeholder=R(e,"Search indicators"),l.setAttribute("aria-label",R(e,"Search indicators")),l.setAttribute("spellcheck","false");const c=nt(i,"div","oac-pick__findwrap");c.appendChild(l);const d=nt(i,"div","oac-pick__list");d.setAttribute("role","listbox"),d.setAttribute("aria-label",R(e,"Indicators")),s.body.appendChild(c);const u=nt(i,"div","oac-head oac-pick__running-head",R(e,"schema.ui.indicatorPicker.running",{},"Running studies")),p=nt(i,"div","oac-pick__running");p.setAttribute("aria-label",R(e,"schema.ui.indicatorPicker.running",{},"Running studies")),s.body.appendChild(u),s.body.appendChild(p),s.body.appendChild(d),s.actions.appendChild(it(i,{label:R(e,"Done"),variant:"primary",onClick:()=>A.close()}));const h=void 0===n.templates?function(e){return Yo.get(e)}(e):n.templates??void 0;let m=null;if(void 0!==h?.planIndicatorTemplateState){const t={waiting:null},o=it(i,{label:R(e,"Templates"),icon:"template",onClick:()=>{H(xa,t=>{m?.close(),m=t.openTemplatesMenu(e,o,h)},t=>e.toast(J(e,R(e,"Templates"),t),"error"),()=>A.isOpen(),{slot:t,doc:i,from:o})}});o.dataset.action="templates",o.setAttribute("aria-haspopup","dialog"),s.lead.appendChild(o)}let g=[],f=-1;const b=e=>a.indicators().filter(t=>t.indicatorId===e).length,v=e=>{0!==g.length?(f=Math.max(0,Math.min(g.length-1,e)),g.forEach((e,t)=>{e.classList.toggle("is-active",t===f),e.setAttribute("aria-selected",t===f?"true":"false")})):f=-1},w=t=>{const o=a.addIndicator(t.id);e.toast(R(e,"Added {name}",{name:o.name}),"success"),n.onAdd?.(o),!0!==n.closeOnAdd?(y(),l.focus()):A.close()};function y(){!function(){p.innerHTML="";const t=a.indicators().filter(e=>!1!==e.policy().listed);if(0===t.length)return void p.appendChild(nt(i,"div","oac-empty oac-pick__running-empty",R(e,"schema.ui.indicatorPicker.empty",{},"No running studies")));const o=new Map;for(const n of t){const t=(o.get(n.indicatorId)??0)+1;o.set(n.indicatorId,t);const r=nt(i,"div","oac-pick__running-row");r.dataset.instanceId=n.id,r.appendChild(nt(i,"span","oac-pick__running-name",n.name)),r.appendChild(nt(i,"span","oac-pick__running-number",String(t)));const s=R(e,"schema.ui.indicatorPicker.remove",{},"Remove"),c=it(i,{label:s,onClick:()=>{a.removeIndicator(n.id),y(),l.focus()}});c.classList.add("oac-pick__remove"),c.setAttribute("aria-label",`${s} ${n.name} ${t}`),!1===n.policy().removable&&(c.disabled=!0,c.title=R(e,"protected"),c.setAttribute("aria-label",`${s} ${n.name} ${t}, ${R(e,"protected")}`)),r.appendChild(c),p.appendChild(r)}}();const t=l.value;if(d.innerHTML="",g=[],0===r.length)return void d.appendChild(nt(i,"div","oac-empty",R(e,"No indicators are registered. Import the indicators tier to fill this list.")));const o=function(e,t){const o=t.trim().toLowerCase();return e.filter(e=>""===o||e.name.toLowerCase().includes(o)||e.id.toLowerCase().includes(o)||(e.category??"").toLowerCase().includes(o)).sort((e,t)=>e.name.localeCompare(t.name))}(r.map(t=>({...t,name:R(e,`schema.indicator.${t.id}.name`,{},t.name),category:void 0===t.category?void 0:R(e,`schema.indicator.category.${t.category}`,{},t.category)})),t);if(0!==o.length){for(const[t,n]of function(e){const t=new Map;for(const o of e){const e=o.category??"Other",n=t.get(e);void 0===n?t.set(e,[o]):n.push(o)}return Array.from(t.entries()).sort((e,t)=>e[0].localeCompare(t[0]))}(o)){d.appendChild(nt(i,"div","oac-head","Other"===t?R(e,"Other"):t));for(const t of n){const o=nt(i,"button","oac-pick__row");o.type="button",o.setAttribute("role","option"),o.dataset.id=t.id,o.appendChild(nt(i,"span","oac-pick__name",t.name));const n=b(t.id);if(n>0){const t=nt(i,"span","oac-pick__count",1===n?R(e,"on chart"):R(e,"on chart x{count}",{count:n}));t.setAttribute("aria-label",1===n?R(e,"one instance on the chart"):R(e,"{count} instances on the chart",{count:n})),o.appendChild(t)}o.addEventListener("click",e=>{e.stopPropagation(),w(t)}),d.appendChild(o),g.push(o)}}v(f<0?0:f)}else d.appendChild(nt(i,"div","oac-empty",R(e,"No match")))}l.addEventListener("input",()=>{f=0,y()}),l.addEventListener("keydown",e=>{const t=e.key;if("ArrowDown"===t)e.preventDefault(),v(f+1);else if("ArrowUp"===t)e.preventDefault(),v(f-1);else if("Enter"===t){e.preventDefault();const t=g[f],o=t?.dataset.id,n=r.find(e=>e.id===o);void 0!==n&&w(n)}}),y();const _=a.on("objects:change",y),x=a.on("indicatorRemoved",y),k=a.on("state:restore:end",y),C=()=>{_(),x(),k(),m?.close()},S=ut(e,s.el,void 0===o?{placement:"center",modal:!0,initialFocus:l}:{anchor:o,placement:"below",initialFocus:l},C),A={el:S.el,isOpen:S.isOpen,close:()=>{S.isOpen()&&(C(),S.close())}};return A}const Ca=e=>e.disabled?e.title:null;function Sa(e,t){let n=!1;const a=[],i=[],r=[],s=[],l=t.instance,c=()=>!n&&!e.chart.isDestroyed&&e.chart.indicators().includes(l)&&(t.current?.()??!0);let d=()=>{};const u=()=>{d();const t=e=>{e.detail>0&&(e.preventDefault(),e.stopImmediatePropagation(),d())},o=()=>{e.document.removeEventListener("click",t,!0),e.document.removeEventListener("pointerdown",o,!0),e.document.removeEventListener("keydown",o,!0),d===o&&(d=()=>{})};d=o,e.document.addEventListener("click",t,!0),e.document.addEventListener("pointerdown",o,!0),e.document.addEventListener("keydown",o,!0)};let p=null;const h=()=>{const e=p;e&&(e.finish(),e.cancel?.())},m=e=>{if(!c()||!t.onPatch(e)||!c())return!1;for(const[o,n]of Object.entries(e)){const e=t.field(o);e&&(e.value=String(n??""))}return!0},g=t=>R(e,`schema.indicator.${l.indicatorId}.${t.key}.label`,{},t.label);for(const n of t.inputs){const d=t.field(n.key);if(!d)continue;if("symbol"===n.type){const t=it(e.document,{label:R(e,"Search"),onClick:()=>{c()&&o?.open(d.value)}});t.setAttribute("aria-label",R(e,"Search {label}",{label:g(n)})),t.dataset.inputAction=n.key,d.parentElement?.appendChild(t),a.push(t),r.push(()=>{const o=Ca(d)??(void 0===e.symbolSearch?R(e,"Symbol search is not configured; enter an instrument manually"):null);t.disabled=null!==o,t.title=o??""});const o=void 0===e.symbolSearch?null:Ht(e,d,{search:e.symbolSearch,context:()=>c()?[l.id,e.symbol(),e.interval(),e.chart.getDataContext()]:null,onSelect:(e,t)=>{const o=void 0===n.exchangeKey?{[n.key]:e}:{[n.key]:e,[n.exchangeKey]:t??""};m(o)}});if(o){i.push(o);const e=e=>{o.canCommitRaw()||e.stopImmediatePropagation()};d.addEventListener("change",e,!0),s.push(()=>d.removeEventListener("change",e,!0))}}if("price"!==n.type&&"timestamp"!==n.type||!n.pick)continue;const f=()=>{const a=Ca(d);return null!==a?a:null!==e.draw.activeTool()?R(e,"Finish or cancel the active drawing before picking"):t.suspend||e.overlays.suspend?"price"===n.type&&null===o.studyInputTarget(e.chart,l,n.key)?R(e,"Choose an explicit pane and scale for this price input"):null:R(e,"This host cannot suspend the settings dialog")},b="price"===n.type&&void 0!==n.timeKey?t.inputs.find(e=>e.key===n.timeKey&&"timestamp"===e.type):void 0,v=b?R(e,"Pick {time} and {price} on the chart",{time:g(b),price:g(n)}):R(e,"Pick {label} on the chart",{label:g(n)}),w=it(e.document,{label:R(e,b?"Pick point on chart":"Pick on chart"),onClick:()=>{if(!c())return;const a=f();if(null!==a)return void e.toast(a,"info");h();for(const e of i)e.close();const r="price"===n.type?o.studyInputTarget(e.chart,l,n.key):void 0,s=t.suspend?.()??e.overlays.suspend(t.panel),d=nt(e.document,"div","oac-input-pick");d.appendChild(nt(e.document,"span",void 0,v));const g=it(e.document,{label:R(e,"Cancel pick"),onClick:h});d.appendChild(g),d.addEventListener("pointerdown",e=>e.stopPropagation()),e.overlays.layer.appendChild(d);let y=()=>{};const _=e=>{"Escape"===e.key&&(e.preventDefault(),e.stopImmediatePropagation(),h())},x={cancel:null,finish:()=>{p===x&&(p=null,y(),d.remove(),e.document.removeEventListener("keydown",_,!0),s(),c()&&w.isConnected&&w.focus())}};p=x;let k=!0;e.document.addEventListener("keydown",_,!0),y=e.chart.on("pick:end",e=>{k||(null===e.value?x.finish():queueMicrotask(()=>{p===x&&x.cancel&&!x.cancel.active()&&(u(),x.finish())}))}),g.focus();try{const t=e=>{p===x&&(u(),x.finish(),m(e))},o=b?e.chart.beginPick("point",e=>t({[n.key]:e.price,[b.key]:e.time}),r):e.chart.beginPick("price"===n.type?"price":"time",e=>t({[n.key]:e}),r);x.cancel=o,k=!1,p!==x?o():o.active()||x.finish()}catch(t){x.finish(),e.toast(t instanceof Error?t.message:R(e,"The value could not be picked"),"error")}}});w.setAttribute("aria-label",v),w.dataset.inputAction=n.key,d.parentElement?.appendChild(w),a.push(w),r.push(()=>{const e=f();w.disabled=null!==e,w.title=e??""})}const f=()=>{if(!n)for(const e of r)e()},b=e.chart.on("objects:change",()=>{h(),f()}),v=e.chart.on("draw:tool",()=>{h(),f()}),w=e.chart.on("data:context",()=>{h();for(const e of i)e.close()}),y=e.chart.on("indicatorRemoved",()=>{c()||h()}),_=e.chart.on("state:restore:start",h),x=e.chart.on("destroy",h);return f(),{cancelPick:h,refresh:f,destroy:()=>{if(!n){n=!0,h(),d(),b(),v(),w(),y(),_(),x();for(const e of s)e();for(const e of i)e.destroy();for(const e of a)e.remove()}}}}const Aa={source:"Source",indicator:"Indicator",drawing:"Drawing",profile:"Profile",group:"Group"},Ta=["visibility","lock","settings","focus","remove"],Ea={loading:"Loading",ready:"Ready",empty:"No data",unsupported:"Unsupported",error:"Could not load"},La={select:"Could not select {name}",visibility:"Could not change visibility for {name}",lock:"Could not change lock for {name}",settings:"Could not open settings for {name}",focus:"Could not focus {name}",remove:"Could not remove {name}"};let Oa=0;function Ia(e,t,o=()=>!0){const n=e=>{const o=new Map;for(const n of e)o.set(t(n),(o.get(t(n))??0)+1);return o},a=e.filter(o),i=e.filter(e=>!o(e)),r=n(a),s=n(e),l=new Map;return new Map([...a,...i].map(e=>{const n=t(e),a=(l.get(n)??0)+1;return l.set(n,a),[e.id,((o(e)?r:s).get(n)??0)>1?`${n} (${a})`:n]}))}const Pa=e=>Ia(e.indicators(),e=>e.name,e=>!1!==e.policy().listed);function $a(e,t={}){const n=t.objects??e.objects;if(void 0===n)throw new Error(R(e,"Objects panel requires an object model"));const a=n,i=t=>t===a.primaryPaneIndex()?R(e,"Price pane"):R(e,"Pane {number}",{number:t+1}),r=e=>i(e.paneIndex),s=t=>R(e,`schema.object.kind.${t.kind}`,{},Aa[t.kind]),l=e.document;let c=!1,d=[];const u=new Map,p=nt(l,"div","oac-objects-content"),h=e=>e.stopPropagation();p.addEventListener("pointerdown",h);const m=new Map;let g=null;const f=(t,o,n={})=>R(e,`schema.ui.objects.${t}`,n,o),b=nt(l,"input","oac-objects__find");b.type="search",b.placeholder=R(e,"Search name, type or pane"),b.setAttribute("aria-label",R(e,"Search objects")),b.setAttribute("spellcheck","false");const v=nt(l,"div","oac-objects__list");v.setAttribute("role","list"),v.setAttribute("aria-label",R(e,"Chart objects"));const w=nt(l,"div","oac-empty");w.setAttribute("role","status");const y=nt(l,"span","oac-objects__count");y.setAttribute("role","status");const _=nt(l,"p","oac-objects__hint",f("orderHint","Each pane lists back to front. Drag a row, or press Alt with an arrow key, to move it."));p.append(b,_,v,w,y);const x=nt(l,"input","oac-objects__group-name");x.type="text",x.dataset.action="group-name",x.placeholder=f("groupName","Group name"),x.setAttribute("aria-label",f("groupName","Group name"));const k=it(l,{label:f("group","Group selected"),onClick:()=>{if(c)return;const e=d.filter(e=>"drawing"===e.kind&&e.selected).map(e=>e.id);a.createGroup(x.value,e)&&(x.value=""),I()}});if(k.dataset.action="group",a.canGroup()){const e=nt(l,"div","oac-objects__grouping");e.append(x,k),p.insertBefore(e,v)}const C=()=>{k.disabled=!x.value.trim()||!d.some(e=>"drawing"===e.kind&&e.selected&&e.capabilities.lock)};function S(t,o){c||(a.move(t,o)||e.toast(f("moveFailed","Could not move object"),"error"),I())}function A(e,t,o){const n=e.getBoundingClientRect();if(n.height>0)return t.clientY<n.top+n.height/2?"below":"above";const i=a.stack(a.get(o)?.paneIndex??-1);return i.findIndex(e=>e.id===g)>i.findIndex(e=>e.id===o)?"below":"above"}function T(){for(const e of u.values())e.el.classList.remove("is-drop-before","is-drop-after")}function E(e,t){const o=a.stack(e.paneIndex),n=o.findIndex(t=>t.id===e.id);if(n<0)return null;if("drawing"===e.kind){const e=o[n+t];return e?{target:e.id,where:1===t?"above":"below"}:null}const i=e=>void 0!==e&&"drawing"!==e.kind;if(-1===t){let e=n-1;for(;e>=0&&!i(o[e])&&"series"===o[e].band;)e--;return i(o[e])?{target:o[e].id,where:"below"}:null}let r=n+1;for(;r<o.length&&"series"===o[r].band&&!i(o[r]);)r++;if(!i(o[r]))return null;let s=r;for(;"series"===o[s+1]?.band&&!i(o[s+1]);)s++;return{target:o[s].id,where:"above"}}function L(t,o,n){if(c)return;const i=a.get(o);let r=!1;try{if(i?.capabilities[t])switch(t){case"select":r=a.select(o,!0===n?.ctrlKey||!0===n?.metaKey);break;case"visibility":r=a.setVisible(o,!i.visible);break;case"lock":r=a.setLocked(o,!i.locked);break;case"settings":r=a.openSettings(o);break;case"focus":r=a.focus(o);break;case"remove":r=a.remove(o)}}catch{}r||e.toast(R(e,La[t],{name:i?.name??R(e,"object")}),"error")}function O(t){const n=nt(l,"div","oac-objects__row");n.dataset.objectId=t.id,n.setAttribute("role","listitem"),n.addEventListener("dragstart",e=>{const o=a.get(t.id);c||!o?.capabilities.place&&!o?.capabilities.reorder?e.preventDefault():(e.stopPropagation(),g=t.id,e.dataTransfer?.setData("text/plain",t.id),e.dataTransfer&&(e.dataTransfer.effectAllowed="move"))}),n.addEventListener("dragend",()=>{g=null,T()}),n.addEventListener("dragleave",()=>{n.classList.remove("is-drop-before","is-drop-after")}),n.addEventListener("dragover",e=>{if(e.stopPropagation(),null===g||g===t.id)return;const o=a.get(g),i=A(n,e,t.id),r=void 0!==o&&(o.paneIndex!==t.paneIndex?!0===o.capabilities.move:a.canPlace(o.id,t.id,i)||void 0===o.band&&o.kind===t.kind&&!0===o.capabilities.reorder);T(),r&&(e.preventDefault(),n.classList.add("below"===i?"is-drop-before":"is-drop-after"))}),n.addEventListener("drop",o=>{o.preventDefault(),o.stopPropagation(),function(t,o){if(T(),c||null===g||g===t)return;const n=a.get(g),i=a.get(t);if(n&&i&&(n.paneIndex===i.paneIndex||n.capabilities.move&&a.move(n.id,i.paneIndex)))if(a.canPlace(n.id,i.id,o))a.place(n.id,i.id,o)||e.toast(f("reorderFailed","Could not reorder object"),"error");else if(n.kind===i.kind&&void 0===n.band)for(let e=0;e<d.length;e++){const e=a.list().filter(e=>e.kind===n.kind&&e.paneIndex===a.get(n.id)?.paneIndex),t=e.findIndex(e=>e.id===n.id),o=e.findIndex(e=>e.id===i.id);if(t<0||o<0||t===o||!a.reorder(n.id,t<o?1:-1))break;if(1===Math.abs(t-o))break}}(t.id,A(n,o,t.id)),g=null}),n.addEventListener("keydown",e=>{const o=e.key;if(!e.altKey||"ArrowUp"!==o&&"ArrowDown"!==o)return;const n=u.get(t.id)?.buttons.get("ArrowUp"===o?"earlier":"later");void 0!==n&&(e.preventDefault(),e.stopPropagation(),n.disabled||n.click())});const i=nt(l,"span","oac-objects__grip");i.setAttribute("aria-hidden","true"),i.innerHTML=o.chromeIconSvg("grip"),n.appendChild(i);const r=t.capabilities.select?it(l,{label:"",onClick:e=>L("select",t.id,e)}):nt(l,"div");r.classList.add("oac-objects__summary"),t.capabilities.select&&(r.dataset.action="select");const s=nt(l,"span","oac-objects__name"),p=nt(l,"span","oac-objects__meta"),h=nt(l,"span","oac-objects__status"),m="oac-object-"+ ++Oa;p.id=`${m}-meta`,h.id=`${m}-status`,t.capabilities.select&&r.setAttribute("aria-describedby",`${p.id} ${h.id}`),r.append(s,p,h);const b=nt(l,"div","oac-objects__actions");n.append(r,b);const v="group"===t.kind?nt(l,"div","oac-objects__members"):void 0;return v&&(v.setAttribute("role","list"),n.appendChild(v)),{el:n,summary:r,name:s,meta:p,status:h,actions:b,selectable:t.capabilities.select,buttons:new Map,members:v}}function I(){if(c)return;const t=b.value.trim().toLowerCase(),o=new Set(d.filter(e=>`${e.name} ${s(e)} ${r(e)}`.toLowerCase().includes(t)).map(e=>e.id));for(const e of d)e.groupId&&o.has(e.groupId)&&o.add(e.id);const n=d.filter(e=>o.has(e.id)||d.some(t=>t.groupId===e.id&&o.has(t.id))),p=new Set(n.map(e=>e.id)),h=l.activeElement,_=null!==h&&v.contains(h);for(const[e,t]of u)p.has(e)||(t.el.remove(),u.delete(e));const x=[...new Set(n.map(e=>e.paneIndex))].sort((e,t)=>e-t);for(const[e,t]of m)x.includes(e)||(t.element.remove(),m.delete(e));x.forEach((e,t)=>{let o=m.get(e);if(!o){const t=nt(l,"section","oac-objects__pane");t.dataset.paneIndex=String(e);const n=nt(l,"h3","oac-objects__pane-title"),i=nt(l,"div");t.append(n,i),t.addEventListener("dragover",e=>{null!==g&&a.get(g)?.capabilities.move&&e.preventDefault()}),t.addEventListener("drop",t=>{t.preventDefault(),null!==g&&a.get(g)?.capabilities.move&&S(g,e),g=null}),o={element:t,rows:i,heading:n},m.set(e,o)}const n=i(e);o.heading.textContent!==n&&(o.heading.textContent=n,o.element.setAttribute("aria-label",n)),v.children[t]!==o.element&&v.insertBefore(o.element,v.children[t]??null)});const k=new Map;for(const e of x)a.stack(e).forEach((e,t)=>k.set(e.id,t));const A=e=>{if(k.has(e.id))return k.get(e.id);const t=d.filter(t=>t.groupId===e.id&&k.has(t.id)).map(e=>k.get(e.id));return t.length?Math.min(...t)-.5:Number.MAX_SAFE_INTEGER},T=n.map((e,t)=>({item:e,index:t})).sort((e,t)=>A(e.item)-A(t.item)||e.index-t.index).map(e=>e.item),I=new Map;T.forEach(t=>{let o=u.get(t.id);void 0!==o&&o.selectable===t.capabilities.select||(o?.el.remove(),o=O(t),u.set(t.id,o)),function(t,o){t.name.textContent=o.name,t.el.draggable=!0===o.capabilities.reorder||!0===o.capabilities.place,t.el.dataset.groupId=o.groupId??"",t.el.classList.toggle("is-group-member",void 0!==o.groupId);const n=[s(o),r(o),o.visible?R(e,"Visible"):R(e,"Hidden")];if("drawing"===o.kind&&"below"===o.band&&n.push(f("behind","Behind the series")),"drawing"===o.kind&&"series"===o.band){const e=d.find(e=>e.id===o.stackAbove);n.push(f("above","Above {name}",{name:e?.name??f("hidden","a hidden study")}))}if(void 0!==o.locked&&n.push(o.locked?R(e,"Locked"):R(e,"Unlocked")),o.selected&&n.push(R(e,"Selected")),o.groupId){const e=d.find(e=>e.id===o.groupId);e&&n.push(e.name)}t.meta.textContent=n.join(", "),t.el.classList.toggle("is-selected",o.selected),t.selectable&&(t.summary.setAttribute("aria-label",R(e,"Select {name}",{name:o.name})),t.summary.setAttribute("aria-pressed",String(o.selected))),t.status.textContent=void 0===o.dataStatus?"":R(e,`schema.dataStatus.${o.dataStatus.state}`,{},Ea[o.dataStatus.state]),t.status.hidden=void 0===o.dataStatus,t.status.dataset.state=o.dataStatus?.state??"";let u=0;for(const n of Ta){let a=t.buttons.get(n);if(!o.capabilities[n]){a?.remove(),t.buttons.delete(n);continue}void 0===a&&(a=it(l,{label:"",variant:"remove"===n?"danger":"ghost",onClick:()=>L(n,o.id)}),a.dataset.action=n,t.buttons.set(n,a));const i="visibility"===n?o.visible?R(e,"Hide"):R(e,"Show"):"lock"===n?o.locked?R(e,"Unlock"):R(e,"Lock"):"settings"===n?R(e,"Settings"):"focus"===n?R(e,"Focus"):"drawing"===o.kind?R(e,"Delete"):R(e,"Remove");a.textContent=i,a.setAttribute("aria-label",R(e,"visibility"===n?o.visible?"Hide {name}":"Show {name}":"lock"===n?o.locked?"Unlock {name}":"Lock {name}":"settings"===n?"Settings for {name}":"focus"===n?"Focus {name}":"drawing"===o.kind?"Delete {name}":"Remove {name}",{name:o.name})),t.actions.children[u]!==a&&t.actions.insertBefore(a,t.actions.children[u]??null),u++}if("drawing"===o.kind&&o.id==="drawing:"+o.sourceId&&a.canGroup()){let e=t.buttons.get("add-selection");e||(e=it(l,{label:"",variant:"ghost",onClick:()=>{c||a.select(o.id,!0)}}),e.dataset.action="add-selection",t.buttons.set("add-selection",e)),e.textContent=f(o.selected?"deselect":"selectMore",o.selected?"Deselect":"Select"),e.setAttribute("aria-label",f(o.selected?"deselectLabel":"selectMoreLabel",o.selected?"Remove {name} from selection":"Add {name} to selection",{name:o.name})),t.actions.children[u]!==e&&t.actions.insertBefore(e,t.actions.children[u]??null),u++}for(const[n,i]of[["earlier",-1],["later",1]]){let r=t.buttons.get(n);if(!o.capabilities.reorder&&!o.capabilities.place){r?.remove(),t.buttons.delete(n);continue}r||(r=it(l,{label:"",variant:"ghost",onClick:()=>{if(c)return;const t=a.get(o.id),n=void 0!==t?.band?E(t,i):null;(void 0!==t?.band?null!==n&&a.place(o.id,n.target,n.where):a.reorder(o.id,i))||e.toast(f("reorderFailed","Could not reorder object"),"error")}}),r.dataset.action=n,t.buttons.set(n,r)),r.textContent=f(n,-1===i?"Earlier":"Later"),r.setAttribute("aria-label",f(n+"Label",-1===i?"Move {name} earlier":"Move {name} later",{name:o.name}));const s=void 0!==o.band?E(o,i):null;r.disabled=void 0!==o.band?null===s||!a.canPlace(o.id,s.target,s.where):!a.canReorder(o.id,i),t.actions.children[u]!==r&&t.actions.insertBefore(r,t.actions.children[u]??null),u++}if(o.capabilities.move){t.move||(t.move=nt(l,"select","oac-objects__move"),t.move.dataset.action="move",t.move.addEventListener("change",()=>S(o.id,Number(t.move.value)))),t.move.setAttribute("aria-label",f("movePane","Move {name} to pane",{name:o.name}));const e=a.paneCount(),n=Array.from({length:e+1},(t,o)=>o===e?f("newPane","New pane"):i(o));(t.move.children.length!==n.length||n.some((e,o)=>t.move.children[o]?.textContent!==e))&&(t.move.replaceChildren(),n.forEach((e,o)=>{const n=nt(l,"option");n.value=String(o),n.textContent=e,t.move.appendChild(n)})),t.move.value=String(o.paneIndex),t.actions.children[u]!==t.move&&t.actions.insertBefore(t.move,t.actions.children[u]??null),u++}else t.move?.remove(),t.move=void 0;t.actions.hidden=0===u}(o,t);const n=t.groupId?d.find(e=>e.id===t.groupId&&e.paneIndex===t.paneIndex):void 0,p=(n?u.get(n.id)?.members:void 0)??m.get(t.paneIndex).rows,h=I.get(p)??0;p.children[h]!==o.el&&p.insertBefore(o.el,p.children[h]??null),I.set(p,h+1)}),C(),w.hidden=n.length>0,w.textContent=0===d.length?R(e,"No objects on this chart."):R(e,"No objects match your search.");const P=1===d.length;y.textContent=""===t?R(e,P?"{count} object":"{count} objects",{count:d.length}):R(e,P?"{shown} of {count} object":"{shown} of {count} objects",{shown:n.length,count:d.length}),_&&(v.contains(h)?l.activeElement!==h&&h.focus():b.focus())}x.addEventListener("input",C),b.addEventListener("input",I);const P=a.subscribe(t=>{if(c)return;const o=new Map((e.draw?.drawings()??[]).map((e,t)=>[e.id,t])),n=e=>"drawing"===e.kind?o.get(e.sourceId)??o.size:-1,a=Ia([...t].sort((e,t)=>n(e)-n(t)),e=>e.name);d=t.map(e=>a.get(e.id)===e.name?e:{...e,name:a.get(e.id)}),I()});return{element:p,initialFocus:b,destroy:()=>{c||(c=!0,P(),p.removeEventListener("pointerdown",h),b.removeEventListener("input",I),x.removeEventListener("input",C),u.clear(),m.clear(),g=null,d=[],t.onClose?.())}}}function ja(e,t,o={}){const n=$a(e,o),a=ct(e.document,{translate:e.translate,title:R(e,"Objects"),className:"oac-objects",onClose:()=>i.close(),closeText:!0});a.body.appendChild(n.element),a.actions.appendChild(it(e.document,{label:R(e,"Done"),variant:"primary",onClick:()=>i.close()}));const i=ut(e,a.el,{...void 0===t?{placement:"center",modal:!0}:{anchor:t,placement:"below"},initialFocus:n.initialFocus,onClose:()=>n.destroy()},()=>{});return i}const Da='\n.oac-widget .oac-objects { width: 440px; min-width: 0; }\n.oac-widget .oac-objects .oac-dialog__body { display: flex; flex-direction: column; gap: 8px; overflow: hidden; }\n.oac-widget .oac-objects-content { display: flex; flex-direction: column; min-height: 0; gap: 8px; }\n.oac-widget .oac-objects__pane-title { margin: 6px 2px; color: var(--oac-mut); font-size: 11px; text-transform: uppercase; }\n.oac-widget .oac-objects__grouping { display: flex; gap: 4px; }\n.oac-widget .oac-objects__group-name { min-width: 0; width: 100%; }\n.oac-widget .oac-objects__move { min-width: 90px; max-width: 130px; height: 26px; font-size: 11px; }\n.oac-widget .oac-objects__row.is-group-member { margin-left: 10px; border: 0; border-left: 1px solid var(--oac-bd-soft); border-radius: 0; }\n.oac-widget .oac-objects__members { min-width: 0; }\n.oac-widget .oac-objects__list { scrollbar-width: thin; scrollbar-color: var(--oac-bd-soft) var(--oac-bg); }\n.oac-widget .oac-objects__list::-webkit-scrollbar { width: 6px; }\n.oac-widget .oac-objects__list::-webkit-scrollbar-track { background: var(--oac-bg); }\n.oac-widget .oac-objects__list::-webkit-scrollbar-thumb { background: var(--oac-bd-soft); border-radius: 3px; }\n.oac-widget .oac-objects__list::-webkit-scrollbar-thumb:hover { background: var(--oac-mut); }\n.oac-widget .oac-objects__find { width: 100%; min-width: 0; flex: none; }\n.oac-widget .oac-objects__list { min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 2px; }\n.oac-widget .oac-objects__row { position: relative; display: flex; flex-direction: column; gap: 4px; padding: 6px; margin-bottom: 4px;\n  border: 1px solid var(--oac-bd-soft); border-radius: 6px; min-width: 0; }\n.oac-widget .oac-objects__row[draggable="true"] { cursor: grab; }\n.oac-widget .oac-objects__grip { display: none; position: absolute; top: 7px; right: 6px; color: var(--oac-faint); line-height: 0; pointer-events: none; }\n.oac-widget .oac-objects__row[draggable="true"] > .oac-objects__grip { display: block; }\n.oac-widget .oac-objects__grip > svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }\n.oac-widget .oac-objects__row[draggable="true"] > .oac-objects__summary { padding-right: 18px; }\n.oac-widget .oac-objects__hint { margin: 0 2px; color: var(--oac-faint); font-size: 11px; line-height: 1.4; }\n.oac-widget .oac-objects__row.is-selected { border-color: var(--oac-acc); background: var(--oac-elev); }\n.oac-widget .oac-objects__row.is-drop-before { box-shadow: inset 0 2px 0 var(--oac-acc); }\n.oac-widget .oac-objects__row.is-drop-after { box-shadow: inset 0 -2px 0 var(--oac-acc); }\n.oac-widget .oac-objects__summary { display: flex; flex-direction: column; align-items: flex-start; justify-content: center;\n  gap: 2px; width: 100%; min-width: 0; height: auto; padding: 3px 4px; text-align: left; white-space: normal; }\n.oac-widget .oac-objects__name { font-weight: 600; overflow-wrap: anywhere; }\n.oac-widget .oac-objects__meta, .oac-widget .oac-objects__status { font-size: 11px; color: var(--oac-mut); overflow-wrap: anywhere; }\n.oac-widget .oac-objects__status[data-state="error"] { color: var(--oac-danger); }\n.oac-widget .oac-objects__actions { display: flex; flex-wrap: wrap; gap: 3px; }\n.oac-widget .oac-objects__actions .oac-btn { height: 26px; padding: 0 6px; font-size: 11px; }\n.oac-widget .oac-objects__count { color: var(--oac-mut); font-size: 11px; }\n',Ma="@bars";function za(e){if(null===e||"object"!=typeof e)return!1;const t=e;return"indicator"===t.kind&&"string"==typeof t.instanceId&&"string"==typeof t.plotKey}const Na=e=>Object.fromEntries(Object.entries(e).map(([e,t])=>[e,za(t)?{...t}:t]));function Ra(e){const t=Object.fromEntries(e.map(e=>[e.key,e.default]));for(const o of e)"symbol"!==o.type||void 0===o.exchangeKey||Object.prototype.hasOwnProperty.call(t,o.exchangeKey)||Object.defineProperty(t,o.exchangeKey,{value:"",writable:!0,configurable:!0,enumerable:!0});return t}function Fa(e,o,n={}){const a=e.document,i=function(e,t,o){const n=e.chart.indicators(),a=o.instanceId??t?.dataset.instanceId;if(void 0!==a){const t=n.find(e=>e.id===a)??null;return null===t?{inst:null,why:R(e,"That indicator is no longer on the chart")}:{inst:t,why:null}}return 1===n.length?{inst:n[0],why:null}:{inst:null,why:0===n.length?R(e,"No indicator on the chart to configure"):R(e,"Pick an indicator from the legend first")}}(e,o,n);if(null===i.inst)return dt(e,i.why??R(e,"No indicator to configure"));const r=i.inst;if(!1===r.policy().configurable)return dt(e,R(e,"{name} settings are protected",{name:r.name}));const s=t.getIndicator(r.indicatorId),l=[],c=e.chart,d=c.primarySeries?.()??null,u=null===d||null===(c.seriesTransform?.(d)??null)?[]:[{key:Ma,type:"select",label:"Compute on",default:"chart",options:[{label:"Chart bars",value:"chart"},{label:"Underlying bars",value:"underlying"}]}],p=[...u,...s.inputs];p.length>0&&l.push({id:"inputs",label:R(e,"Inputs"),icon:"settings",inputs:p});const h=t.indicatorStyleInputs(s);if(h.length>0&&l.push({id:"style",label:R(e,"Style"),icon:"brush",inputs:h}),0===l.length)return dt(e,R(e,"{name} has nothing to configure",{name:r.name}));const m=Na(r.settings()),g=u.length>0?r.barSource():"chart",f=new Set,b=e.history?.group("Study settings")??(()=>{});let v=l.some(e=>e.id===n.tab)?n.tab:l[0].id,w=null,y=null,_=null,x=!1,k=()=>{},C=()=>{};const S=()=>!e.chart.isDestroyed&&e.chart.indicators().includes(r),A=t=>{e.toast(t instanceof Error?t.message:R(e,"The study settings could not be applied"),"error")},T=()=>R(e,"{name} settings are protected",{name:r.name}),E=t=>{if(_=null,!S())return $(),!1;try{const{[Ma]:o,...n}=t;if(void 0!==o&&o!==r.barSource()&&!r.setBarSource(o)||Object.keys(n).length>0&&!1===r.setSettings(Na(n)))return _=T(),e.toast(_,"error"),!1}catch(t){return _=t instanceof Error?t.message:R(e,"The study settings could not be applied"),A(t),!1}for(const e of Object.keys(t))f.add(e);return n.onChange?.(r),!0},L=ct(a,{translate:e.translate,title:R(e,"{name} settings",{name:r.name}),className:"oac-indset",onClose:()=>$()}),O=nt(a,"div","oac-indset__pane");if(l.length>1){const e=ht(a,l.map(e=>({id:e.id,label:e.label,icon:e.icon})),v,"row",t=>{!w||w.validate()?(v=t,I()):e.setActive(v)});L.body.appendChild(e.el)}function I(){y?.destroy(),y=null,w?.destroy();const o=l.find(e=>e.id===v)??l[0];O.innerHTML="";const n=Xe(o.inputs,{translate:e.translate,scope:`indicator.${s.id}`},e.intervals),i=new Map;for(const a of o.inputs){if("source"!==a.type)continue;const o=n.find(e=>e.key===a.key),s=[...o.options??[]],l=new Map,c=Pa(e.chart);if(a.allowStudyOutputs)for(const o of e.chart.indicators())if(o.id!==r.id)for(const n of t.getIndicator(o.indicatorId).plots){if(n.ohlc)continue;const t=`study-output:${l.size}`;l.set(t,{kind:"indicator",instanceId:o.id,plotKey:n.key});const a=R(e,`schema.indicator.${o.indicatorId}.plot.${n.key}`,{},n.title??n.key);s.push({value:t,label:`${c.get(o.id)} / ${a}`})}o.options=s,i.set(a.key,l)}const c=()=>{const o={...t.indicatorDefaults(s),...Ra(h),...r.settings(),...u.length>0?{[Ma]:r.barSource()}:{}};for(const[t,a]of i){const i=o[t];if(!za(i))continue;let r=[...a].find(([,e])=>e.instanceId===i.instanceId&&e.plotKey===i.plotKey)?.[0];if(void 0===r){r=`study-output:${a.size}`,a.set(r,{...i});n.find(e=>e.key===t).options.push({value:r,label:R(e,"Unavailable study output: {instanceId} / {plotKey}",{instanceId:i.instanceId,plotKey:i.plotKey})})}o[t]=r}return o};w=ft(O,n,{values:c(),translate:e.translate,openOverlay:e.openOverlay,idPrefix:`oac-ind-${r.id}`,live:!0,onChange:(e,t)=>{const n="string"==typeof t?i.get(e)?.get(t):void 0;if(!E({[e]:n?{...n}:t})){if(!S())return;if(o.inputs.some(t=>t.key===e&&["symbol","session","multiline","price","timestamp"].includes(t.type)))return void w?.setError(e,_);const t=a.activeElement?.id;return I(),void(t&&a.getElementById(t)?.focus())}w?.sync(c()),y?.refresh()}}),y=Sa(e,{instance:r,inputs:o.inputs,panel:L.el,field:e=>Array.from(O.querySelectorAll("input")).find(t=>t.id===`oac-ind-${r.id}-${e.replace(/[^A-Za-z0-9_-]/g,"-")}`)??null,onPatch:e=>{if(!E(e)){for(const t of Object.keys(e))w?.setError(t,_);return!1}for(const t of Object.keys(e))w?.setError(t,null);return w?.sync(c()),y?.refresh(),!0}})}L.body.appendChild(O),I(),L.lead.appendChild(it(a,{label:R(e,"Defaults"),onClick:()=>{const e=l.find(e=>e.id===v)??l[0];E(Ra(e.inputs))&&I()}})),L.actions.appendChild(it(a,{label:R(e,"Cancel"),onClick:()=>$()})),L.actions.appendChild(it(a,{label:R(e,"OK"),variant:"primary",onClick:()=>j()})),L.el.addEventListener("keydown",e=>{"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),$())});const P=ut(e,L.el,{placement:"center",modal:!0,dismissOnEscape:!1,onClose:()=>{k(),C(),y?.destroy(),w?.destroy(),b()}},()=>{$(),P.isOpen()&&(w?.destroy(),P.close(),n.onClose?.(!1))});function $(){P.isOpen()&&function(){if(!S())return e.toast(R(e,"That indicator is no longer on the chart"),"info"),!0;if(x||0===f.size)return!0;const t=Object.fromEntries([...f].filter(e=>e!==Ma).map(e=>[e,m[e]]));try{(f.has(Ma)&&r.barSource()!==g&&!r.setBarSource(g)||Object.keys(t).length>0&&!1===r.setSettings(Na(t)))&&e.toast(T(),"error")}catch(e){return A(e),I(),!1}return f.clear(),n.onChange?.(r),!0}()&&(y?.destroy(),w?.destroy(),P.close(),n.onClose?.(!1))}function j(){P.isOpen()&&(w&&!w.validate()||(x=!0,y?.destroy(),w?.destroy(),P.close(),n.onClose?.(!0)))}return k=e.chart.on("indicatorRemoved",()=>{S()?w?.validate()&&I():$()}),C=e.chart.on("destroy",$),{el:L.el,isOpen:P.isOpen,close:()=>j()}}const Wa={price:"chart-candlestick",readout:"legend",axes:"axes",appearance:"panels",trading:"trading"};function Ba(e,o,n={}){const{chart:a}=e,i=e.document,r=t.chartSettingsSchema(a).filter(e=>e.inputs.length>0),s=t.readChartSettings(a),l=new Set;let c=r.some(e=>e.id===n.tab)?n.tab:r[0]?.id??"price",d=null,u=!1;const p=e.history?.group("Chart settings")??(()=>{}),h=o=>{O(e,void 0,()=>t.applyChartSettings(a,o))},m=e=>{for(const t of Object.keys(e))l.add(t);h(e),n.onApply?.(e)},g=ct(i,{translate:e.translate,title:R(e,"Chart settings"),className:"oac-settings",onClose:()=>x()}),f=nt(i,"div","oac-settings__main"),b=nt(i,"div","oac-settings__pane");g.body.appendChild(f);const v=ht(i,r.map(t=>({id:t.id,label:R(e,`schema.settings.tab.${t.id}`,{},t.label),icon:Wa[t.id]})),c,"rail",e=>{c=e,w()});function w(){d?.destroy();const o=r.find(e=>e.id===c);b.innerHTML="",d=null,void 0!==o?d=ft(b,Xe(o.inputs,{translate:e.translate,scope:"settings"}),{values:t.readChartSettings(a),translate:e.translate,openOverlay:e.openOverlay,idPrefix:"oac-cset",live:!0,unavailable:(t,o)=>"statusLine.openInterest"===t&&!1===a.hasOpenInterest?R(e,"Open interest is unavailable for this instrument."):n.unavailable?.(t,o)??null,onChange:(e,o)=>{m({[e]:o}),d?.sync(t.readChartSettings(a))}}):b.appendChild(nt(i,"div","oac-empty",R(e,"Nothing to configure on this chart yet.")))}f.appendChild(v.el),f.appendChild(b),w(),g.lead.appendChild(it(i,{label:R(e,"Restore this tab"),onClick:()=>{const t=r.find(e=>e.id===c);if(void 0===t)return;const o=function(e){const t={};for(const o of e.inputs)"colorPair"===o.type?(t[o.up.key]=o.up.default,t[o.down.key]=o.down.default,void 0!==o.enabled&&(t[o.enabled.key]=o.enabled.default)):t[o.key]=o.default;return t}(t);for(const t of Object.keys(o)){const n=e.settingsDefaults?.[t];void 0!==n&&(o[t]=n)}m(o),w()}})),g.actions.appendChild(it(i,{label:R(e,"Cancel"),onClick:()=>x()})),g.actions.appendChild(it(i,{label:R(e,"OK"),variant:"primary",onClick:()=>k()}));const y=a.on("data:context",w),_=ut(e,g.el,{placement:"center",modal:!0,onClose:()=>{y(),d?.destroy(),p()}},()=>x());function x(){_.isOpen()&&(!function(){if(u||0===l.size)return;const e={};for(const t of l){const o=s[t];void 0!==o&&(e[t]=o)}l.clear(),h(e),n.onApply?.(e)}(),d?.destroy(),_.close(),n.onClose?.(!1))}function k(){_.isOpen()&&(u=!0,d?.destroy(),_.close(),n.onClose?.(!0))}return{el:g.el,isOpen:_.isOpen,close:()=>k()}}const Ua=[{value:"price",label:"Price"},{value:"indicator",label:"Study plot"},{value:"drawing",label:"Drawing level"},{value:"barCondition",label:"Candle condition"}],qa=(e,t,o)=>({key:e,label:t,kind:"select",options:o}),Ka=e=>e.chart.primaryPaneIndex(),Ga=(e,o,n)=>o?t.getIndicator(o.indicatorId).plots.filter(t=>void 0===n||(t.overlay?Ka(e):o.paneIndex)===n).map(t=>({value:t.key,label:R(e,`schema.indicator.${o.indicatorId}.plot.${t.key}`,{},t.title)})):[];function Va(e,o){const n=[qa("kind",R(e,"Source"),Ua.map(t=>({...t,label:R(e,`schema.alert.kind.${t.value}`,{},t.label)})))],a=e.chart.indicators().filter(e=>!1!==e.policy().listed||e.id===o.instanceId||e.id===o.inputInstanceId),i=e.chart.primaryBars(),r=i.length-1,s=(e,t)=>(void 0===o[e]&&(o[e]=t[0]?.value??""),String(o[e])),l=Pa(e.chart),c=e=>e.map(e=>({value:e.id,label:l.get(e.id)??e.name})),d=o.kind;if("barCondition"===d){const o=t.registeredBarConditions().map(t=>({value:t.id,label:R(e,`schema.barCondition.${t.id}.title`,{},t.title)})),a=s("barConditionId",o);return n.push(qa("barConditionId",R(e,"Candle condition"),o)),{source:{kind:d,id:a},controls:n,reason:o.some(e=>e.value===a)?void 0:R(e,"Candle condition is unavailable")}}if("indicator"===d){const t=s("instanceId",c(a)),i=a.find(e=>e.id===t),l=Ga(e,i),u=s("plotKey",l);n.push(qa("instanceId",R(e,"Study"),c(a)),qa("plotKey",R(e,"Plot"),l));const p=i?.values()[u]?.[r];return"value"in o||(o.value=p??void 0),{source:{kind:d,instanceId:t,plotKey:u,value:o.value,upperValue:o.upperValue},controls:n,reason:i?i.series(u)?void 0:R(e,"Study plot is unavailable"):R(e,"Study instance is unavailable"),hint:Number.isFinite(p)?void 0:R(e,"The current plot value is unavailable. The alert waits for observed values.")}}if("drawing"===d){const t=e.draw.drawings(),i=e=>!1!==e.policy?.listed,r=Ia(t,t=>R(e,`schema.drawing.${t.tool}.name`,{},At(t.tool)),i),l=t.filter(e=>i(e)||e.id===o.drawingId).map(e=>({value:e.id,label:r.get(e.id)})),u=s("drawingId",l),p=e.draw.alertInfo(u),h=p.levels.map(e=>({value:e.id,label:e.title})),m=s("level",h);n.push(qa("drawingId",R(e,"Drawing"),l),qa("level",R(e,"Level"),h));const g=a.filter(t=>Ga(e,t,p.paneIndex).length>0),f=c(g);p.paneIndex===Ka(e)&&f.unshift({value:"",label:R(e,"Price")});const b=s("inputInstanceId",f);n.push(qa("inputInstanceId",R(e,"Compare with"),f));const v=g.find(e=>e.id===b);let w;if(b){const t=Ga(e,v,p.paneIndex),o=s("inputPlotKey",t);w={instanceId:b,plotKey:o},n.push(qa("inputPlotKey",R(e,"Input plot"),t))}const y=p.available?h.some(e=>e.value===m)?w?Ga(e,v,p.paneIndex).some(e=>e.value===w.plotKey)?void 0:R(e,"Select an input plot on the drawing pane"):p.paneIndex!==Ka(e)?R(e,"Select an input plot on the drawing pane"):void 0:R(e,"Drawing level is unavailable"):p.reason;return{source:{kind:d,drawingId:u,level:m,...w?{input:w}:{}},controls:n,reason:y}}return"price"in o||(o.price=i[r]?.close),{source:{kind:"price",price:o.price,upperPrice:o.upperPrice},controls:n}}let Ha=0;const Ja=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}$/;function Za(e,t){if(void 0===e)return"";const o=ta(e,t,!1);return`${o.date}T${o.time}`}function Ya(e,o){if(e)return Za(e.expiresAt,o);const n=t.utcSecondsToZonedParts(Math.floor(Date.now()/1e3),o),a=n.month-1+2,i=Math.min(n.day,new Date(Date.UTC(n.year,a+1,0)).getUTCDate()),r=Date.UTC(n.year,a,i,n.hour,n.minute)/1e3,s=r-t.zoneOffsetSeconds(r,o),l=r-t.zoneOffsetSeconds(s,o);return Za(l+t.zoneOffsetSeconds(l,o)===r?l:Math.max(s,l),o)}const Qa=e=>{try{return t.dataVariantKey(e)}catch{return"invalid"}};function Xa(e,o,n={}){const a=e.alerts,i=a?.list().find(e=>e.id===n.alertId),r=e.chart.timezone(),s=e.chart.getDataContext(),l=e=>JSON.stringify([e?.symbol,e?.exchange,e?.interval,Qa(e?.variant)]),c=l(s),d=e.chart.primaryBars(),u=i?.source??n.source??{kind:"price",price:d[d.length-1]?.close};let p,h=!1,m=!1;const g="oac-alert-"+ ++Ha,f=[];let b={...i,...u,..."drawing"===u.kind?{inputInstanceId:u.input?.instanceId,inputPlotKey:u.input?.plotKey}:{},..."barCondition"===u.kind?{barConditionId:u.id}:{},enabled:!i||"armed"===i.state,expiresAt:Ya(i,r)};function v(){if(!h){h=!0;for(const e of f.splice(0))e();p?.destroy(),L?.close(),n.onClose?.()}}const w=ct(e.document,{translate:e.translate,title:R(e,i?"Edit alert":"Create alert"),className:"oac-alert-editor",onClose:v}),y=nt(e.document,"p","oac-alert-context",[s?.symbol,s?.exchange,s?.interval].filter(Boolean).join(" / ")),_=nt(e.document,"div"),x=nt(e.document,"p","oac-alert-help"),k=nt(e.document,"p","oac-alert-help",R(e,"Bar close evaluates confirmed values. Intrabar touch can fire on a wick that is absent from final history.")),C=nt(e.document,"p","oac-alert-error");C.setAttribute("role","status"),w.body.append(y,_,x,k,C);const S=it(e.document,{label:R(e,"Save"),variant:"primary",onClick:function(){if(h)return;try{const t=T();if(t)throw new Error(t);b={...b,...p.values()};const o=String(b.title??"").trim();if(""===o)throw new Error(R(e,"Enter a name"));const n=b.condition,s="enteringRange"===n||"leavingRange"===n,l=Va(e,b).source,c={source:"price"===l.kind?{kind:"price",price:b.price,...s?{upperPrice:b.upperPrice}:{}}:"indicator"===l.kind?{...l,value:b.value,upperValue:s?b.upperValue:void 0}:l,condition:n,title:o,message:String(b.message??"")||void 0,policy:b.policy,repeat:b.repeat,cooldownSeconds:b.cooldownSeconds};i&&b.expiresAt===Za(i.expiresAt,r)||(c.expiresAt=function(e,t,o){if(""===t)return;const n=R(e,"Enter an expiry date and time");if("string"!=typeof t||!Ja.test(t))throw new Error(n);const[a,i]=t.split("T"),r=oa(a,i,o,{rejectSkipped:!0});if(null===r)throw new Error(n);return r}(e,b.expiresAt,r)),i&&!m||(c.state=b.enabled?"armed":"disabled"),i?a.update(i.id,c):a.add(c),v()}catch(t){C.textContent=t instanceof Error?t.message:R(e,"Could not save this alert")}}});S.dataset.action="save-alert";const A=it(e.document,{label:R(e,"Cancel"),onClick:v});function T(){return a?n.alertId&&!a.list().some(e=>e.id===n.alertId)?R(e,"This alert was removed"):l(e.chart.getDataContext())!==c||i&&l(i.scope)!==c?R(e,"The instrument context changed. Reopen the editor for the intended instrument."):Va(e,b).reason:R(e,"Alerts are unavailable in this host")}function E(){const t=T();C.textContent=t??"",S.disabled=void 0!==t,x.textContent=Va(e,b).hint??""}A.dataset.action="cancel-alert",w.actions.append(A,S),function o(){p?.destroy();const n=Va(e,b),a=t.alertSettingsSchema(n.source,b.condition);for(const e of a)e.key in b||(b[e.key]=e.default);b.condition=a.find(e=>"condition"===e.key).default;const i=Xe(a,{translate:e.translate,scope:"alert"}),s=i.find(e=>"expiresAt"===e.key);s&&(s.label+=` (${r})`),p=ft(_,[...n.controls,...i],{idPrefix:g,values:b,translate:e.translate,openOverlay:e.openOverlay,preserveInvalidNumbers:!0,onChange:(t,n)=>{b={...b,...p.values(),[t]:n},"enabled"===t&&(m=!0);const a=["kind","instanceId","plotKey","drawingId","level","inputInstanceId"].includes(t);if("kind"===t)for(const e of["price","value","upperPrice","upperValue","condition"])delete b[e];if("instanceId"===t&&(delete b.plotKey,delete b.value,delete b.upperValue),"plotKey"===t&&(delete b.value,delete b.upperValue),"drawingId"===t&&(delete b.level,delete b.inputInstanceId,delete b.inputPlotKey),"inputInstanceId"===t&&delete b.inputPlotKey,"condition"===t||a){const n=null!==e.document.activeElement&&_.contains(e.document.activeElement);o(),n&&_.querySelector(`[data-key="${t}"] select`)?.focus()}E()}});const l=_.querySelector('[data-key="expiresAt"] input');l&&(l.type="datetime-local",l.step="60")}(),E();for(const t of["data:context","data:update","objects:change","alert:removed","alerts:restored"])f.push(e.chart.on(t,E));f.push(e.chart.on("destroy",v));const L=ut(e,w.el,{anchor:o,modal:!0,placement:"center"},v);return{el:w.el,close:v,isOpen:()=>!h&&L.isOpen()}}function ei(e,o,n={}){const a=e.alerts;let i=!1,r=!1;const s=[],l=new Map;function c(){if(!i){i=!0;for(const e of s.splice(0))e();w?.close(),n.onClose?.()}}const d=ct(e.document,{translate:e.translate,title:R(e,"Alerts"),className:"oac-alerts",onClose:c,closeText:!0}),u=nt(e.document,"div","oac-alerts__list");u.setAttribute("role","list"),u.setAttribute("aria-label",R(e,"Chart alerts"));const p=nt(e.document,"p","oac-empty",R(e,a?"No alerts. Create an alert for this chart.":"Alerts are unavailable in this host")),h=nt(e.document,"span","oac-alert-context");h.setAttribute("role","status");const m=it(e.document,{label:R(e,"Create alert"),variant:"primary",onClick:()=>{Xa(e)}});m.dataset.action="create-alert",m.disabled=!a,d.body.append(u,p),d.lead.appendChild(h),d.actions.appendChild(m);const g={armed:R(e,"Active"),triggered:R(e,"Triggered"),expired:R(e,"Expired"),disabled:R(e,"Disabled")},f=(e,t,o)=>e.find(e=>e.key===t)?.options?.find(e=>e.value===o)?.label;function b(o){const n=o.source;if("price"===n.kind){const t=t=>e.chart.panes()[e.chart.primaryPaneIndex()]?.readoutScale().format(t)??String(t);return void 0===n.upperPrice?R(e,"Price {price}",{price:t(n.price)}):R(e,"Price {price} to {upper}",{price:t(n.price),upper:t(n.upperPrice)})}if("barCondition"===n.kind)return t.getBarCondition(n.id)?.title??R(e,"Unavailable candle condition");if("drawing"===n.kind){const{controls:t}=Va(e,{...n,inputInstanceId:n.input?.instanceId,inputPlotKey:n.input?.plotKey});return`${f(t,"drawingId",n.drawingId)??R(e,"Unavailable drawing")} / ${f(t,"level",n.level)??n.level??R(e,"Default level")}`}const a=e.chart.indicators().find(e=>e.id===n.instanceId),{controls:i}=Va(e,{kind:"indicator",instanceId:n.instanceId,plotKey:n.plotKey,value:n.value}),r=f(i,"plotKey",n.plotKey)??n.plotKey,s=a?.series(n.plotKey)?.priceScale(),l=e=>s?.format(e)??String(e);return R(e,void 0===n.upperValue?"{name} / {plot}: {value}":"{name} / {plot}: {value} to {upper}",{name:f(i,"instanceId",n.instanceId)??R(e,"Unavailable study"),plot:r,value:l(n.value),upper:void 0===n.upperValue?"":l(n.upperValue)})}function v(){if(!i&&!r){r=!0;try{const t=a?.list()??[],o=new Set(t.map(e=>e.id));for(const[e,t]of l)o.has(e)||(t.el.remove(),l.delete(e));for(const o of t){let t=l.get(o.id);if(!t){const n=nt(e.document,"div","oac-alerts__row");n.dataset.alertId=o.id,n.setAttribute("role","listitem");const i=nt(e.document,"div","oac-alerts__summary"),r=nt(e.document,"div","oac-alerts__status"),s=nt(e.document,"div","oac-alerts__actions"),c=it(e.document,{label:R(e,"Edit"),onClick:()=>{Xa(e,void 0,{alertId:o.id})}});c.dataset.action="edit-alert";const d=it(e.document,{label:R(e,"Disable"),onClick:()=>{const e=a?.list().find(e=>e.id===o.id);"armed"===e?.state?a?.disable(o.id):a?.enable(o.id)}});d.dataset.action="toggle-alert";const p=it(e.document,{label:R(e,"Delete"),onClick:()=>{a?.remove(o.id)}});p.dataset.action="delete-alert",s.append(c,d,p),n.append(i,r,s),u.appendChild(n),t={el:n,summary:i,status:r,toggle:d},l.set(o.id,t)}const n=[o.scope.symbol,o.scope.exchange,o.scope.interval,Pt(e,o.scope.variant)].filter(Boolean).join(" / ");t.summary.textContent=`${o.title}\n${n}\n${b(o)}`,t.el.dataset.state=o.state;const i=a.availability(o.id);t.status.textContent=[g[o.state],"onBarClose"===o.policy?R(e,"Bar close"):R(e,"Intrabar touch"),"once"===o.repeat?R(e,"Once"):R(e,"Every match"),o.cooldownSeconds?R(e,"{seconds}s cooldown",{seconds:o.cooldownSeconds}):"",void 0===o.expiresAt?"":R(e,"Expires {time}",{time:Za(o.expiresAt,e.chart.timezone()).replace("T"," ")}),void 0===o.lastTriggeredAt?"":R(e,"Last fired {time}",{time:Za(o.lastTriggeredAt,e.chart.timezone()).replace("T"," ")}),i.available?"":i.reason].filter(Boolean).join(" / "),t.toggle.textContent="armed"===o.state?R(e,"Disable"):R(e,"Enable"),t.toggle.setAttribute("aria-label",R(e,"armed"===o.state?"Disable {name}":"Enable {name}",{name:o.title})),t.toggle.disabled="armed"!==o.state&&void 0!==o.expiresAt&&o.expiresAt<=Date.now()/1e3,t.toggle.title=t.toggle.disabled?R(e,"Edit the expiry before enabling this alert"):""}p.hidden=t.length>0,h.textContent=R(e,1===t.length?"{count} alert":"{count} alerts",{count:t.length})}finally{r=!1}}}for(const t of["alert:created","alert:updated","alert:removed","alert:triggered","alert:expired","alerts:restored","data:context","data:update","data:range","objects:change","replay:start","replay:stop"])s.push(e.chart.on(t,v));s.push(e.chart.on("destroy",c)),v();const w=ut(e,d.el,{anchor:o,modal:!0,placement:"center"},c);return{el:d.el,close:c,isOpen:()=>!i&&w.isOpen()}}const ti={kind:"separator"},oi=e=>({kind:"header",label:e}),ni={linear:"Linear",logarithmic:"Logarithmic",percentage:"Percent","indexed-to-100":"Indexed to 100"};function ai(e,t,o){const n=e.panes()[t];return void 0===n?String(o):n.readoutScale().format(o)}function ii(e,t,n){const{draw:a}=e,i=o.drawingSettingsSchema(t.tool),r=[],s=xt(e,n),l=t=>()=>{kt(e,t,n)},c=n.length>1,d=s.editable.length,u=0===d,p=s.readOnly??void 0,h=s.noDelete??void 0;return r.push({id:"draw-props",label:R(e,c?"Properties of the selection...":"Properties..."),icon:"settings",run:()=>{_a(e,void 0,{ids:n})}}),!c&&ha(t)&&r.push({id:"draw-text",label:R(e,"Edit text"),icon:"text",disabled:u,note:p,run:()=>{ga(e,0,{id:t.id})}}),i.fields.some(e=>"levels"===e.kind)&&r.push({id:"draw-levels",label:R(e,"Edit levels..."),disabled:u,note:p,run:()=>{la(e,void 0,{ids:n})}}),r.push(ti),r.push({id:"draw-copy",label:c?R(e,"Copy {count} drawings",{count:n.length}):R(e,"Copy drawing"),icon:"copy",chord:ze(e.keymap,"copy","Mod+C"),run:()=>{a.copy(n)}}),r.push({id:"draw-cut",label:d>1?R(e,"Cut {count} drawings",{count:d}):R(e,"Cut drawing"),chord:ze(e.keymap,"cut","Mod+X"),disabled:void 0!==h,note:h,run:()=>{a.cut(n)}}),r.push({id:"draw-duplicate",label:R(e,"Duplicate"),icon:"duplicate",chord:ze(e.keymap,"duplicate","Mod+D"),run:l("duplicate")}),r.push(ti),r.push({id:"draw-lock",label:R(e,"Lock"),icon:s.locked?"lock":"unlock",mark:"check",on:s.locked,disabled:u,note:p,run:l("lock")}),r.push({id:"draw-hide",label:R(e,"Hide"),icon:s.hidden?"eye-off":"eye",mark:"check",on:s.hidden,disabled:u,note:p,run:l("visible")}),r.push(ti),r.push(oi(R(e,"Order"))),r.push({id:"draw-front",label:R(e,"Bring to front"),icon:"front",run:l("front")}),r.push({id:"draw-back",label:R(e,"Send to back"),icon:"back",run:l("back")}),r.push({id:"draw-above",label:R(e,"In front of the series"),icon:"above-series",mark:"radio",on:"above"===s.side,run:l("above")}),r.push({id:"draw-behind",label:R(e,"Behind the series"),icon:"behind-series",mark:"radio",on:"behind"===s.side,run:l("behind")}),r.push(ti),r.push({id:"draw-delete",label:d>1?R(e,"Delete {count} drawings",{count:d}):R(e,"Delete"),icon:"trash",chord:ze(e.keymap,"delete","Delete"),danger:!0,disabled:void 0!==h,note:h,run:l("delete")}),r}function ri(e,o,n={}){const{chart:a,draw:i}=e,r=o.target,s=[],l=()=>{s.length>0&&"separator"!==s[s.length-1].kind&&s.push(ti)};if("price-scale"===r.kind)return s.push(...function(e,o,n){const{chart:a}=e,i=()=>a.priceAxisState(o,n),r=i();if(null===r)return[];const s=[];s.push({id:"axis-autofit",label:R(e,"Auto-fit to the data"),mark:"check",on:r.autoFit,keepOpen:!0,run:()=>{const e=i();null!==e&&a.setPriceAxisAutoFit(o,n,!e.autoFit)}});const l=()=>{const e=a.primarySeries?.();return null!=e&&e.priceScale()===a.panes()[o]?.scaleFor(n)};l()&&s.push({id:"axis-price-only",label:R(e,"Fit primary prices only"),mark:"check",on:a.priceOnlyAutoScale(),keepOpen:!0,run:()=>{l()&&a.setPriceOnlyAutoScale(!a.priceOnlyAutoScale())}}),s.push({id:"axis-invert",label:R(e,"Invert"),mark:"check",on:r.inverted,keepOpen:!0,run:()=>{const e=i();null!==e&&a.setPriceAxisOptions(o,n,{inverted:!e.inverted})}}),s.push({id:"axis-lock",label:R(e,"Pin price per bar"),mark:"check",on:r.lockRatio,keepOpen:!0,disabled:!r.scaled,note:r.scaled?void 0:R(e,"nothing measured"),run:()=>{const t=i();null!==t&&(a.setPriceAxisLockRatio(o,n,!t.lockRatio)||e.toast(R(e,"Nothing measured on this scale yet"),"info"))}}),s.push(ti),s.push(oi(R(e,"Scale")));for(const i of t.PRICE_SCALE_MODES)s.push({id:`axis-mode-${i}`,label:R(e,`schema.scaleMode.${i}`,{},ni[i]),mark:"radio",on:r.mode===i,keepOpen:!0,run:()=>{a.setPriceAxisOptions(o,n,{mode:i})}});const c=a.priceAxisPlacement(o,n),d=e=>a.priceAxisLayout(o).filter(t=>t.side===e).sort((e,t)=>e.order-t.order);if(null!==c&&"hidden"!==c.side){s.push(ti),s.push({id:"axis-move",label:"right"===c.side?R(e,"Move the scale to the left"):R(e,"Move the scale to the right"),disabled:!r.active,note:r.active?void 0:R(e,"nothing on this side"),run:()=>{const t=a.priceAxisPlacement(o,n);i()?.active&&null!==t&&"hidden"!==t.side&&(a.setPriceAxisPlacement(o,n,"right"===t.side?"left":"right")||e.toast(R(e,"The scale could not be moved"),"info"))}});const t=d(c.side),l=t.findIndex(e=>e.scaleId===n);if(l>=0&&t.length>1)for(const r of[-1,1])s.push({id:r<0?"axis-closer":"axis-further",label:R(e,r<0?"Move the scale closer to the plot":"Move the scale further from the plot"),disabled:void 0===t[l+r],keepOpen:!0,run:()=>{const t=a.priceAxisPlacement(o,n);if(!i()?.active||null===t||"hidden"===t.side)return;const s=d(t.side),l=s.findIndex(e=>e.scaleId===n),c=l<0?void 0:s[l+r];c&&!a.setPriceAxisPlacement(o,n,t.side,c.order)&&e.toast(R(e,"The scale could not be moved"),"info")}})}return s.push(ti),s.push({id:"axis-settings",label:R(e,"Axis settings..."),icon:"settings",run:()=>{Ba(e,0,{tab:"axes"})}}),s}(e,o.paneIndex,r.scaleId??r.side??"right")),s;const c=a.primaryPaneIndex(),d=n.onOrder;if(void 0!==d&&"time-scale"!==r.kind){const i=o.paneIndex===c?o.price:null,r={...e.symbol(),interval:e.interval()},l=o=>t.checkTradingCapability(n.tradingCapabilities,{operation:"place",type:o,mode:n.tradingMode,...e.symbol()}),u=()=>{if(t.isReplaying(a))return R(e,"Order entry is locked during replay");try{if(n.tradingLocked?.())return R(e,"Order entry is locked by the host")}catch{return R(e,"Order entry is unavailable")}},p=u(),h=(t,n)=>({id:`order-${t.toLowerCase()}-${n.toLowerCase()}`,icon:"BUY"===t?"buy":"sell",label:"MARKET"===n?R(e,"BUY"===t?"Buy market":"Sell market"):R(e,"BUY"===t?"LIMIT"===n?"Buy limit at {price}":"Buy stop at {price}":"LIMIT"===n?"Sell limit at {price}":"Sell stop at {price}",{price:ai(a,o.paneIndex,i)}),disabled:void 0!==p,note:p,run:()=>{if(a.isDestroyed)return;const s=e.symbol();if(s.symbol!==r.symbol||s.exchange!==r.exchange||e.interval()!==r.interval)return void e.status(R(e,"The chart changed; reopen the menu before placing an order"),"error");const c=u();if(void 0!==c)return void e.status(c,"error");const p=l(n);p.supported?d({side:t,type:n,price:"MARKET"===n?null:i,paneIndex:o.paneIndex}):e.status(R(e,"Order entry is unavailable: {reason}",{reason:p.reason}),"error")}}),m=(null===i?["MARKET"]:["MARKET","LIMIT","SL"]).map(e=>({type:e,result:l(e)})),g=m.filter(e=>e.result.supported);if(g.length>0){s.push(oi(R(e,"Trade")));for(const{type:e}of g)s.push(h("BUY",e),h("SELL",e))}else{const t=m[0].result;s.push({id:"trading-unavailable",label:R(e,"Order entry is unavailable"),disabled:!0,note:t.supported?void 0:t.reason})}}const u=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)}(r),p=null===u?void 0:i.get(u);if(e.alerts&&"time-scale"!==r.kind){if(l(),p){const t=i.alertInfo(p.id);s.push({id:"alert-drawing",label:R(e,"Create drawing alert..."),icon:"bell",disabled:!t.available,note:t.reason,run:()=>{Xa(e,void 0,{source:{kind:"drawing",drawingId:p.id}})}})}else if("indicator"===r.kind&&r.instanceId){const n=a.indicators().find(e=>e.id===r.instanceId),i=n&&t.getIndicator(n.indicatorId).plots.find(e=>(e.overlay?c:n.paneIndex)===o.paneIndex&&(void 0===r.plotKey||e.key===r.plotKey));n&&i&&s.push({id:"alert-indicator",label:R(e,"Create study alert..."),icon:"bell",run:()=>{const t=n.values()[i.key],r=t?.[o.index??a.primaryBars().length-1];Xa(e,void 0,{source:{kind:"indicator",instanceId:n.id,plotKey:i.key,value:r??NaN}})}})}else o.paneIndex===c&&null!==o.price&&Number.isFinite(o.price)&&s.push({id:"alert-create",label:R(e,"Create alert at {price}...",{price:ai(a,c,o.price)}),icon:"bell",run:()=>{Xa(e,void 0,{source:{kind:"price",price:o.price}})}});s.push({id:"chart-alerts",label:R(e,"Alerts..."),run:()=>{ei(e)}})}if(void 0!==p){i.selection().includes(p.id)||i.select(p.id);const t=i.selection().includes(p.id)?i.selection().slice():[p.id];l(),s.push(...ii(e,p,t))}if("indicator"===r.kind&&void 0!==r.instanceId){const t=a.indicators().find(e=>e.id===r.instanceId);if(void 0!==t){l();const o=t.policy(),n=t=>!1===o[t]?R(e,"protected"):void 0;s.push({id:"ind-settings",label:R(e,"{name} settings...",{name:t.name}),icon:"settings",disabled:void 0!==n("configurable"),note:n("configurable"),run:()=>{Fa(e,void 0,{instanceId:t.id})}}),s.push({id:"ind-visible",label:t.visible()?R(e,"Hide {name}",{name:t.name}):R(e,"Show {name}",{name:t.name}),icon:t.visible()?"eye":"eye-off",run:()=>{t.setVisible(!t.visible())}}),s.push({id:"ind-remove",label:R(e,"Remove {name}",{name:t.name}),icon:"trash",danger:!0,disabled:void 0!==n("removable"),note:n("removable"),run:()=>{a.removeIndicator(t.id)}})}}if("time-scale"!==r.kind&&!si.has(o)){const t=a.panes().length,n=o.paneIndex;if(t>1&&n>=0&&n<t){l();const o=e=>!a.movablePrimaryPane()&&(n===c||e===c),i=(t,i,r,s,l)=>{const c=s?R(e,l):o(n+r)?R(e,"price pane stays on top"):void 0;return{id:t,label:R(e,i),disabled:void 0!==c,note:c,run:()=>{a.movePane(n,r)}}};s.push(i("pane-up","Move pane up",-1,0===n,"at the top")),s.push(i("pane-down","Move pane down",1,n===t-1,"at the bottom"))}if(n!==c&&n>=0&&n<t){const t=a.paneCollapsed(n);l(),s.push({id:"pane-collapse",label:R(e,t?"Expand pane":"Collapse pane"),run:()=>{a.setPaneCollapsed(n,!t)}})}}if("time-scale"!==r.kind){l(),s.push({id:"draw-paste",label:R(e,"Paste"),icon:"paste",chord:ze(e.keymap,"paste","Mod+V"),run:()=>{i.paste().then(t=>{0===t.length&&e.toast(R(e,"Nothing to paste"),"info")})}});const t=i.drawings().filter(e=>!1!==e.policy?.editable).length;t>0&&s.push({id:"draw-clear",label:R(e,"Remove all drawings ({count})",{count:t}),icon:"trash",danger:!0,run:()=>{i.clear()}})}l(),s.push({id:"chart-fit",label:R(e,"Fit all bars"),icon:"fit",chord:ze(e.keymap,"chart:fitContent"),disabled:!1===a.navigationOptions().zoomEnabled,run:()=>{!1!==a.navigationOptions().zoomEnabled&&a.fitContent()}}),"time-scale"!==r.kind&&s.push({id:"chart-indicators",label:R(e,"Indicators..."),icon:"indicators",run:()=>{ka(e)}}),s.push({id:"chart-settings",label:R(e,"Settings..."),icon:"settings",run:()=>{Ba(e)}});const h=n.items?.(o)??[];return h.length>0&&(l(),s.push(...h)),s}const si=new WeakSet;const li=new WeakMap;function ci(e,t,o={}){const n=e.document;li.get(e.root)?.close();const a=o.event??function(e){const t={paneIndex:e.primaryPaneIndex(),point:{x:0,y:0},price:null,time:null,index:null,target:{kind:"empty",id:null},preventDefault:()=>{}};return si.add(t),t}(e.chart),i=o.hooks??{},r=nt(n,"div","oac-panel oac-ctx");r.setAttribute("role","menu"),r.setAttribute("aria-label",R(e,"Chart menu")),r.tabIndex=-1,st(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=ri(e,a,i);for(const o of l){if("separator"===o.kind){r.appendChild(nt(n,"div","oac-ctx__hr"));continue}if("header"===o.kind){r.appendChild(nt(n,"div","oac-head",o.label));continue}const a=o,i=nt(n,"button","oac-ctx__row"+(!0===a.danger?" is-danger":""));i.type="button",i.setAttribute("role","check"===a.mark?"menuitemcheckbox":"radio"===a.mark?"menuitemradio":"menuitem"),void 0!==a.mark&&i.setAttribute("aria-checked",!0===a.on?"true":"false"),void 0!==a.id&&(i.dataset.act=a.id),i.tabIndex=-1;const l=nt(n,"span","oac-ctx__mark");if("radio"===a.mark&&!0===a.on)l.appendChild(nt(n,"span","oac-ctx__dot"));else if("check"===a.mark&&!0===a.on)l.appendChild(at(n,"check"));else if(void 0!==a.icon)if(a.icon.startsWith("<svg")){const e=nt(n,"span","oac-glyph oac-glyph--chrome");e.innerHTML=a.icon,l.appendChild(e)}else l.appendChild(at(n,a.icon));if(i.appendChild(l),i.appendChild(nt(n,"span","oac-ctx__label",a.label)),void 0!==a.note&&""!==a.note&&i.appendChild(nt(n,"span","oac-ctx__note",a.note)),void 0!==a.chord){i.appendChild(nt(n,"kbd","oac-ctx__key",a.chord)).setAttribute("aria-hidden","true"),i.setAttribute("aria-keyshortcuts",Me(a.chord))}!0===a.disabled?i.setAttribute("aria-disabled","true"):i.addEventListener("click",o=>{o.stopPropagation(),void 0!==a.run&&O(e,a.id,a.run),!0===a.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")),a=o.indexOf(n.activeElement);"ArrowDown"===t?(e.preventDefault(),l(a+1)):"ArrowUp"===t?(e.preventDefault(),l(a<=0?o.length-1:a-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=ut(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=pa(e.chart),o=null===t?{left:0,top:0}:w(e.root,t);mt(e.root,r,{point:{x:a.point.x+o.left,y:a.point.y+o.top}})}return li.set(e.root,d),d}function di(e,t={}){return e.chart.on("contextmenu",o=>{const n=o;n.preventDefault(),ci(e,void 0,{event:n,hooks:t})})}const ui={settings:Ba,indicatorPicker:ka,indicatorSettings:Fa,drawingProperties:_a,contextMenu:ci,levelEditor:la,textEditor:ga,alertEditor:Xa,alerts:ei};D(ui);const pi=`\n.oac-widget .oac-alert-editor { width: 480px; }\n.oac-widget .oac-alerts { width: 560px; }\n.oac-widget .oac-alerts__row { padding: 10px 0; border-bottom: 1px solid ${Fn("bd-soft")}; }\n.oac-widget .oac-alerts__summary { white-space: pre-line; overflow-wrap: anywhere; line-height: 1.5; }\n.oac-widget .oac-alerts__status { color: ${Fn("mut")}; font-size: 11px; line-height: 1.5; margin: 4px 0 8px; overflow-wrap: anywhere; }\n.oac-widget .oac-alerts__actions { display: flex; flex-wrap: wrap; gap: 6px; }\n.oac-widget .oac-alert-context { margin: 0 0 8px; color: ${Fn("mut")}; overflow-wrap: anywhere; }\n.oac-widget .oac-alert-help { color: ${Fn("mut")}; font-size: 11px; line-height: 1.5; margin: 10px 0 0; }\n.oac-widget .oac-alert-error { color: ${Fn("danger")}; font-size: 12px; margin: 6px 0 0; overflow-wrap: anywhere; }\n.oac-widget .oac-alert-editor input[type=datetime-local] { width: 100%; min-width: 0; color-scheme: inherit;\n  height: ${Fn("ctl-h")}; padding: 0 8px; border: 1px solid ${Fn("bd")}; border-radius: ${Fn("radius")};\n  background: ${Fn("elev")}; color: ${Fn("tx")}; font: inherit; }\n/* Panels: the card a dialog or a popover is built on. */\n.oac-widget .oac-panel { display: flex; flex-direction: column; min-width: 0; max-width: calc(100% - 24px);\n  max-height: calc(100% - 24px); background: ${Fn("panel")}; border: 1px solid ${Fn("bd")}; border-radius: 12px;\n  box-shadow: ${Fn("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: ${Fn("bd-soft")}; }\n.oac-widget .oac-empty { padding: 10px 6px; color: ${Fn("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: ${Fn("mut")}; cursor: pointer; }\n/* Every row's control occupies the same column, and the column is one width.\n   It was not: a select filled it, a lone number sat at 72px against its right\n   edge, and one row widened the column for itself. Reading down the form, the\n   left edge of the controls stepped in and out by ninety pixels, which is the\n   kind of wrongness a reader feels before they can name it. The column is wide\n   enough for a date and time, which is the widest control any of these forms\n   puts in it. */\n.oac-widget .oac-row__ctl { display: flex; align-items: center; justify-content: flex-end; gap: 6px; width: min(232px, 58%); min-width: 0; flex: none; }\n/* A number that is the only thing in its column fills it like every other\n   control, keeping its digits right aligned. One paired with a slider keeps\n   its own width, because there the narrow box is the point. */\n.oac-widget .oac-row__ctl input[type=number] { width: 72px; max-width: 100%; min-width: 0; text-align: right; font-variant-numeric: tabular-nums; }\n.oac-widget .oac-row__ctl > input[type=number]:only-child { width: 100%; }\n.oac-widget .oac-row__ctl input[type=text] { width: 100%; min-width: 0; }\n.oac-widget .oac-row__ctl .oac-select, .oac-widget .oac-row__ctl select { width: 100%; min-width: 0; max-width: 100%; }\n.oac-widget .oac-opacity { min-width: 0; max-width: 100%; display: inline-flex; align-items: center; gap: 6px; }\n.oac-widget .oac-opacity input[type=range] { width: 110px; min-width: 0; }\n.oac-widget .oac-out { min-width: 36px; text-align: right; color: ${Fn("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: ${Fn("faint")}; cursor: not-allowed; }\n.oac-widget .oac-row input:disabled, .oac-widget .oac-row select:disabled { opacity: .45; pointer-events: none; }\n/* Inline rows: the lead label, then each member's own label and control. The\n   control column takes what the label leaves and wraps inside itself, so a\n   narrow panel stacks the members rather than scrolling sideways. */\n.oac-widget .oac-row--inline { flex-wrap: wrap; row-gap: 4px; }\n.oac-widget .oac-row--inline > .oac-row__label { flex: 0 1 auto; }\n.oac-widget .oac-row--inline > .oac-row__ctl { width: auto; flex: 1 1 0; min-width: min(100%, 150px); flex-wrap: wrap; row-gap: 4px; }\n.oac-widget .oac-inline__item { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }\n.oac-widget .oac-inline__label { color: ${Fn("mut")}; white-space: nowrap; cursor: pointer; }\n.oac-widget .oac-inline__item--off > .oac-inline__label { color: ${Fn("faint")}; cursor: not-allowed; }\n.oac-widget .oac-row--inline .oac-select, .oac-widget .oac-row--inline select { width: auto; }\n.oac-widget .oac-row--inline input[type=text] { width: 96px; }\n\n/* Tab lists: a rail down the left of a settings dialog, or a row above a form. */\n.oac-widget .oac-tabs { min-width: 0; display: flex; gap: 2px; }\n.oac-widget .oac-tabs--rail { flex-direction: column; min-width: 138px; padding: 2px 10px 2px 0; border-right: 1px solid ${Fn("bd-soft")}; }\n.oac-widget .oac-tabs--row { overflow-x: auto; flex: none; padding: 0 0 6px; margin-bottom: 6px; border-bottom: 1px solid ${Fn("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: ${Fn("mut")}; text-align: left; white-space: nowrap; }\n.oac-widget .oac-tab:hover { background: ${Fn("elev")}; color: ${Fn("tx")}; }\n.oac-widget .oac-tab[aria-selected="true"] { background: ${Fn("on-bg")}; border-color: ${Fn("on-bd")}; color: ${Fn("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: ${Fn("tx")}; text-align: left; }\n.oac-widget .oac-pick__row:hover, .oac-widget .oac-pick__row.is-active { background: ${Fn("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: ${Fn("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: ${Fn("tx-strong")}; }\n.oac-widget .oac-levels__labels { display: inline-flex; align-items: center; gap: 6px; color: ${Fn("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: ${Fn("faint")}; }\n.oac-widget .oac-levels__x:hover { background: ${Fn("elev-2")}; color: ${Fn("danger")}; }\n/* A row's remove cross stays a size under the panel's close, so the two do not read as one control. */\n.oac-widget .oac-levels__x > .oac-glyph > svg { width: 12px; height: 12px; }\n.oac-widget .oac-levels__foot { flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 4px; }\n.oac-widget .oac-levels__foot .oac-spacer { flex: 1 1 auto; }\n\n/* Inline text editor, laid over the painted text. */\n.oac-widget .oac-textedit { position: absolute; z-index: 70; box-sizing: border-box; margin: 0; outline: none; padding: 4px;\n  border: 1px solid ${Fn("acc")}; border-radius: 4px; background: color-mix(in srgb, ${Fn("bg")} 58%, transparent);\n  box-shadow: 0 0 0 3px ${Fn("ring-soft")}; caret-color: ${Fn("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: ${Fn("tx")}; text-align: left; white-space: nowrap; }\n.oac-widget .oac-ctx__row:hover, .oac-widget .oac-ctx__row:focus-visible { background: ${Fn("elev-2")}; outline: none; }\n.oac-widget .oac-ctx__row:is(:hover, :focus-visible) :is(.oac-ctx__note, .oac-ctx__key) { color: ${Fn("mut")}; }\n.oac-widget .oac-ctx__row[aria-disabled="true"] { color: ${Fn("faint")}; cursor: default; background: transparent; }\n.oac-widget .oac-ctx__row.is-danger:not([aria-disabled="true"]):hover { color: ${Fn("danger")}; }\n.oac-widget .oac-ctx__row[aria-checked="true"] { color: ${Fn("acc-2")}; }\n.oac-widget .oac-ctx__mark { width: 16px; height: 16px; display: inline-grid; place-items: center; flex: none; color: ${Fn("mut")}; }\n.oac-widget .oac-ctx__row[aria-checked="true"] .oac-ctx__mark { color: ${Fn("acc-2")}; }\n.oac-widget .oac-ctx__dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }\n.oac-widget .oac-ctx__label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }\n.oac-widget .oac-ctx__note { color: ${Fn("faint")}; font-size: 11px; }\n.oac-widget .oac-ctx__key { margin-left: 8px; color: ${Fn("faint")}; }\n.oac-widget .oac-ctx__hr { height: 1px; background: ${Fn("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 ${Fn("bd-soft")}; }\n  .oac-widget .oac-dialog__foot { gap: 6px; }\n  .oac-widget .oac-dialog__foot > .oac-spacer { display: none; }\n  .oac-widget .oac-dialog__actions { margin-left: auto; }\n}\n`;let hi=0;function mi(e,t,o){switch(t.status){case"partial":return t.clipped?R(e,"The range is wider than the chart. Showing {from} to {to}",o):"exhausted"===t.history?R(e,"History starts at {date}",{date:o.from}):"limited"===t.history?R(e,"The history limit stops at {date}",{date:o.from}):"empty"===t.history?R(e,"No older bars were found before {date}",{date:o.from}):R(e,"Older history cannot load now. Showing from {date}",{date:o.from});case"unsupported":return R(e,"Go to needs a time-based interval");case"error":return R(e,"Could not load history: {error}",{error:t.error?.message??""});default:return null}}function gi(e,t,o){const n=e.document,a=e.chart,i=a.timezone(),r=e.interval(),s=Zt(r),l="interval"===s?.mode&&s.seconds<86400,c=new Intl.DateTimeFormat(e.locale,{timeZone:i,dateStyle:"medium",...l?{timeStyle:"short"}:{}}),d=e=>c.format(new Date(1e3*e));let u=!1,p=!1,h=!1,m=0,g=null;const f="oac-goto-"+ ++hi,b=ct(n,{translate:e.translate,title:R(e,"Go to"),className:"oac-goto",onClose:M}),v=nt(n,"div","oac-goto__modes");v.setAttribute("role","group"),v.setAttribute("aria-label",R(e,"Go to"));const w=(e,t)=>{const o=it(n,{label:t,onClick:()=>P("range"===e)});return o.dataset.mode=e,v.appendChild(o),o},y=w("date",R(e,"Date")),_=w("range",R(e,"Range")),x=e=>{const t=nt(n,"div","oac-goto__row"),o=nt(n,"label","oac-goto__label");o.htmlFor=`${f}-${e}`;const a=nt(n,"input");a.type="date",a.id=`${f}-${e}`;const i=nt(n,"input");return i.type="time",i.hidden=!l,t.append(o,a,i),{row:t,label:o,date:a,time:i}},k=x("from"),C=x("to");l||b.el.classList.add("oac-goto--days");const S=nt(n,"p","oac-goto__hint",R(e,l?"Times are in {zone}. A blank time is the start of the day, or its end for To.":"Dates are in {zone}.",{zone:i})),A=nt(n,"p","oac-goto__message");A.setAttribute("role","status"),A.setAttribute("aria-live","polite"),b.body.append(v,k.row,C.row,S,A);const T=it(n,{label:R(e,"Go"),variant:"primary",onClick:()=>{j()}});T.dataset.action="go-to",b.actions.appendChild(T);for(const e of[k.date,k.time,C.date,C.time])e.addEventListener("keydown",e=>{"Enter"===e.key&&(e.preventDefault(),j())}),e.addEventListener("input",()=>{A.textContent=""});const E=a.getVisibleLogicalRange(),L=[a.dataLayer.indexToTime(Math.max(0,Math.ceil(E.from))),a.dataLayer.indexToTime(Math.min(a.dataLayer.length-1,Math.floor(E.to)))],O=(e,t)=>{if(void 0===t)return;const o=ta(t,i,!1);e.date.value=o.date,e.time.value=l?o.time:""},I=o.pending;function P(t){u=t,C.row.hidden=!t,k.label.textContent=R(e,t?"From":"Date"),C.label.textContent=R(e,"To"),k.time.setAttribute("aria-label",R(e,t?"From time":"Time")),C.time.setAttribute("aria-label",R(e,"To time")),y.setAttribute("aria-pressed",String(!t)),_.setAttribute("aria-pressed",String(t)),A.textContent=""}function $(e,t){return oa(e.date.value,e.time.value,i,t?{blank:"end",end:!0}:{blank:"start"})}async function j(){if(p)return;const t=$(k,!1),n=u?$(C,!0):void 0;if(null===t||null===n)return void(A.textContent=R(e,"Enter a valid date"));if(void 0!==n&&n<t)return void(A.textContent=R(e,"The end must not be before the start"));const a=void 0===n?{from:t}:{from:t,to:n};await D(a,o.navigate(a))}async function D(t,o){const n=++m;let a;A.textContent=R(e,"Loading history"),T.disabled=h=!0;try{a=await o}finally{n===m&&(T.disabled=h=!1)}if(p||n!==m)return;if("cancelled"===a.status)return void(A.textContent="");const i=function(t,o){const n={from:d(t.from??o.from),to:d(t.to??o.to??o.from)};switch(t.status){case"placed":return u?R(e,"Showing {from} to {to}",n):R(e,"Showing {date}",{date:n.from});case"no-data":return void 0===o.to?R(e,"No bars at or after {date}",{date:d(o.from)}):R(e,"No bars between {from} and {to}",{from:d(o.from),to:d(o.to)});case"invalid":return R(e,"Enter a valid date");default:return mi(e,t,n)??""}}(a,t),r="error"===a.status||"unsupported"===a.status;e.status(i,r?"error":"info"),"placed"===a.status?M():A.textContent=i}function M(){if(!p){p=!0;for(const e of z)e();g?.close(),o.onClose?.(),h&&Promise.resolve().then(()=>{a.isDestroyed||o.cancel?.()})}}O(k,I?.target.from??L[0]),O(C,void 0===I?L[1]:I.target.to??I.target.from),P(void 0!==I?.target.to);const z=[a.on("destroy",M),a.on("timezone:changed",M),a.on("data:context",()=>{e.interval()!==r&&M()})];return g=ut(e,b.el,{anchor:t,placement:"below",initialFocus:k.date},M),p?g.close():void 0!==I&&D(I.target,I.result),{el:b.el,close:M,isOpen:()=>!p&&g.isOpen()}}const fi=`\n.oac-widget .oac-goto { width: 340px; }\n.oac-widget .oac-goto__modes { display: flex; gap: 4px; margin-bottom: 10px; }\n.oac-widget .oac-goto__row { display: grid; grid-template-columns: 44px minmax(0, 1fr) 96px; align-items: center; gap: 6px; margin: 0 0 6px; }\n.oac-widget .oac-goto--days .oac-goto__row { grid-template-columns: 44px minmax(0, 1fr); }\n.oac-widget .oac-goto__label { color: ${Fn("mut")}; font-size: 12px; }\n.oac-widget .oac-goto input[type=date], .oac-widget .oac-goto input[type=time] { min-width: 0; height: ${Fn("ctl-h")}; padding: 0 6px;\n  border: 1px solid ${Fn("bd")}; border-radius: ${Fn("radius")}; background: ${Fn("elev")}; color: ${Fn("tx")}; color-scheme: inherit; }\n.oac-widget .oac-goto__hint { margin: 4px 0 0; color: ${Fn("faint")}; font-size: 11px; line-height: 1.4; }\n.oac-widget .oac-goto__message { min-height: 16px; margin: 6px 0 0; color: ${Fn("mut")}; font-size: 12px; overflow-wrap: anywhere; }\n`,bi=86400,vi=e=>Object.freeze({...e}),wi=Object.freeze([vi({id:"1D",label:"1D",interval:"1m",unit:"session",count:1}),vi({id:"5D",label:"5D",interval:"5m",unit:"session",count:5}),vi({id:"1M",label:"1M",interval:"30m",unit:"month",count:1}),vi({id:"3M",label:"3M",interval:"1h",unit:"month",count:3}),vi({id:"6M",label:"6M",interval:"1d",unit:"month",count:6}),vi({id:"YTD",label:"YTD",interval:"1d",unit:"ytd"}),vi({id:"1Y",label:"1Y",interval:"1d",unit:"year",count:1}),vi({id:"5Y",label:"5Y",interval:"1w",unit:"year",count:5}),vi({id:"ALL",label:"All",interval:"1w",unit:"all"})]);function yi(e){const o=t.tryResolveInterval(e);if(null===o)return null;const n=o.bucketing;if("interval"===n.mode)return n.seconds;if("calendar"!==n.mode)return null;return 30.44*(("year"===n.unit?12:"quarter"===n.unit?3:1)*Math.max(1,Math.floor(n.count??1)))*bi}function _i(e,t){if(t.includes(e.interval))return e.interval;const o=yi(e.interval);if(null===o)return e.interval;let n=null,a=1/0,i=0;for(const e of t){const t=yi(e);if(null===t)continue;const r=Math.abs(Math.log(t/o));(r<a-1e-9||Math.abs(r-a)<=1e-9&&t>i)&&(n=e,a=r,i=t)}return n??e.interval}function xi(e,t){for(let o=1;o<=21;o++){let n=e.sessionFrom(t-o*bi);if(null===n)return null;if(!(n.open>=t)){for(let o=e.sessionFrom(n.close);null!==o&&o.open<t&&o.open>n.open;o=e.sessionFrom(o.close))n=o;return n}}return null}function ki(e,o,n){const a=t.utcSecondsToZonedParts(e,o);return t.zonedWallClockToUtcSeconds(a.year,a.month,a.day-n,0,0,0,o)}function Ci(e,o,n){const a=t.utcSecondsToZonedParts(e,o),i=new Date(Date.UTC(a.year,a.month-1-n,1)),r=i.getUTCFullYear(),s=i.getUTCMonth()+1,l=new Date(Date.UTC(r,s,0)).getUTCDate();return t.zonedWallClockToUtcSeconds(r,s,Math.min(a.day,l),0,0,0,o)}function Si(e,o){const n=o.end,a=o.zone??t.DEFAULT_TIMEZONE,i=void 0!==o.bars&&o.bars.length>0?o.bars:null,r=Math.max(1,Math.min(400,Math.floor(e.count??1)));let s;switch(e.unit){case"session":{let e=null;if(o.calendar)try{e=function(e,t,o){let n=e.sessionFrom(t);if((null===n||n.open>t)&&(n=xi(e,t)),null===n)return null;let a=n.date,i=n.open,r=1;for(let t=0;t<12*o+12;t++){const t=xi(e,i);if(null===t)break;if(t.date!==a){if(r>=o)break;r++,a=t.date,i=t.open}else i=t.open}if(e.phaseSpans)try{const t=e.phaseSpans(i-bi,i),o=t[t.length-1];void 0!==o&&"pre"===o.phase&&o.end===i&&(i=o.start)}catch{}return i}(o.calendar,n,r)}catch{e=null}s=e??(null!==i?function(e,t,o){let n=0,a=NaN,i=e[e.length-1].time;for(let r=e.length-1;r>=0;r--){const s=ki(e[r].time,t,0);if(s!==a){if(n===o)break;n++,a=s}i=e[r].time}return i}(i,a,r):function(e,o,n){let a=0;for(let i=n,r=t.utcSecondsToZonedParts(e,o).weekday;i>0;)a++,r=(r+6)%7,0!==r&&6!==r&&i--;return ki(e,o,a)}(n,a,r));break}case"month":s=Ci(n,a,r);break;case"year":s=Ci(n,a,12*r);break;case"ytd":{const e=t.utcSecondsToZonedParts(n,a);s=t.zonedWallClockToUtcSeconds(e.year,1,1,0,0,0,a);break}default:s=null!==i?i[0].time:Ci(n,a,360)}return{from:Math.min(s,n),to:n}}const Ai=[{id:"auto",icon:"scale-auto",key:"schema.ui.bottombar.auto",label:"Auto-fit to the data"},{id:"log",icon:"scale-log",key:"schema.ui.bottombar.log",label:"Logarithmic scale"},{id:"percent",icon:"scale-percent",key:"schema.ui.bottombar.percent",label:"Percent scale"}];function Ti(e){const t=function(e){if(e.isDestroyed)return null;const t=e.primaryPaneIndex(),o=e.panes()[t];if(void 0===o)return null;const n=e.primarySeries();for(const e of["right","left"])if(null!==n&&n.priceScale()===o.scaleFor(e))return{pane:t,id:e};return{pane:t,id:"right"}}(e),o=null===t?null:e.priceAxisState(t.pane,t.id);return null!==t&&null!==o&&o.active?{state:o,...t}:null}function Ei(e,t){const o=Math.max(1,Math.floor(t.count??1));switch(t.unit){case"session":return 1===o?R(e,"schema.ui.rangeSpan.session",{},"One trading session"):R(e,"schema.ui.rangeSpan.sessions",{count:o},"{count} trading sessions");case"month":return 1===o?R(e,"schema.ui.rangeSpan.month",{},"One month"):R(e,"schema.ui.rangeSpan.months",{count:o},"{count} months");case"year":return 1===o?R(e,"schema.ui.rangeSpan.year",{},"One year"):R(e,"schema.ui.rangeSpan.years",{count:o},"{count} years");case"ytd":return R(e,"schema.ui.rangeSpan.ytd",{},"Year to date");default:return R(e,"schema.ui.rangeSpan.all",{},"All history")}}function Li(e,n,a={}){const i=e.document,r=()=>(a.now??Date.now)()/1e3,s=a.ranges??wi,l=()=>a.target?a.target():e.chart?{chart:e.chart}:null,c=()=>{if(f)return null;const e=l()?.chart??null;return null===e||e.isDestroyed?null:e},d=new Set,h=()=>{for(const e of Array.from(d))try{e()}catch{}},m=()=>{U(),h()},g=new Rt;let f=!1,b=0;const v={ranges:()=>l()?.setRange?s:[],range:()=>l()?.range?.()??null,setRange:t=>{const o=f?null:l(),n=s.find(e=>e.id===t);if(void 0===o?.setRange||void 0===n||o.chart.isDestroyed)return;const a=++b;let i;try{i=o.setRange(t)}catch(t){return void e.status(R(e,"Could not load history: {error}",{error:F(e,t)}),"error")}m(),Promise.resolve(i).then(t=>{if(f||a!==b||!t||"cancelled"===t.status)return;const i=function(e,t,o,n){const a=t.timezone(),i=t.primaryBars().length>1&&t.primaryBars()[1].time-t.primaryBars()[0].time<86400;let r;try{r=new Intl.DateTimeFormat(e.locale,{timeZone:a,dateStyle:"medium",...i?{timeStyle:"short"}:{}})}catch{r=new Intl.DateTimeFormat(void 0,{timeZone:a,dateStyle:"medium"})}const s=e=>void 0===e?"":r.format(new Date(1e3*e)),l={range:o,from:s(n.from),to:s(n.to)};switch(n.status){case"placed":return R(e,"schema.ui.rangeResult.placed",l,"{range}: {from} to {to}");case"no-data":return R(e,"schema.ui.rangeResult.empty",{range:o},"No bars for {range}");default:return mi(e,n,l)??""}}(e,o.chart,n.label,t);""!==i&&e.status(i,"error"===t.status||"unsupported"===t.status?"error":"info"),m()},t=>{f||a!==b||e.status(R(e,"Could not load history: {error}",{error:F(e,t)}),"error")})},marketStatus:()=>{const t=c();if(null===t||!Ft(t))return null;const o=r(),n=g.read(t.dataLayer.sessionCalendar,o);return null===n?null:Nt(e,n,o,t.timezone())},clock:()=>{const e=c();if(null===e)return"";const t=r();return`${Mt(t,e.timezone(),!1)} ${Dt(t,e.timezone())}`},timezone:()=>c()?.timezone()??"",timezones:()=>{const e=c();if(null===e)return[];const o=a.timezones?[...a.timezones]:function(e){try{for(const o of t.chartSettingsSchema(e)){const e=o.inputs.find(e=>"time.timezone"===e.key),t=e?.options;if(t)return t.map(e=>String(e.value))}}catch{}return[e.timezone()]}(e);return o.includes(e.timezone())||o.push(e.timezone()),o},setTimezone:t=>{const o=c();if(null!==o&&t!==o.timezone()){try{o.setTimezone(t)}catch{return void e.status(R(e,"schema.ui.bottombar.badZone",{zone:t},"Unknown timezone: {zone}"),"error")}a.onTimezone?.(t),m()}},scale:()=>{const e=c(),t=null===e?null:Ti(e);return null===t?null:{auto:t.state.autoFit,log:"logarithmic"===t.state.mode,percent:"percentage"===t.state.mode}},toggleScale:e=>{const t=c(),o=null===t?null:Ti(t);if(null!==t&&null!==o){if("auto"===e)t.setPriceAxisAutoFit(o.pane,o.id,!o.state.autoFit);else{const n="log"===e?"logarithmic":"percentage";t.setPriceAxisOptions(o.pane,o.id,{mode:o.state.mode===n?"linear":n})}m()}},subscribe:e=>(d.add(e),()=>{d.delete(e)})};n.classList.add("oac-bottombar"),n.setAttribute("role","toolbar"),n.setAttribute("aria-label",R(e,"schema.ui.bottombar.label",{},"Range, time and scale"));const w=e=>{e.stopPropagation()};n.addEventListener("pointerdown",w);const y=(e,t)=>u(i,"button",e,{type:"button","aria-label":t}),_=(e,t)=>{e.getAttribute("aria-disabled")!==String(t)&&e.setAttribute("aria-disabled",String(t))},x=(e,t)=>{e.textContent!==t&&(e.textContent=t)},k=new Map;if(s.length>0){const t=u(i,"div","oac-bottombar__group oac-bottombar__ranges",{role:"group","aria-label":R(e,"schema.ui.bottombar.ranges",{},"Range")});for(const o of s){const n=R(e,`schema.ui.range.${o.id}`,{},o.label),a=R(e,"schema.ui.rangeName",{range:n},"Range {range}"),i=y("oac-bottombar__range",a);i.textContent=n,i.dataset.range=o.id,i.setAttribute("aria-pressed","false"),e.tips.attach(i,()=>({title:a,sub:l()?.setRange?Ei(e,o):R(e,"schema.ui.bottombar.noRanges",{},"This chart takes no preset ranges"),side:"top"})),i.addEventListener("click",()=>{"true"!==i.getAttribute("aria-disabled")&&v.setRange(o.id)}),t.appendChild(i),k.set(o.id,i)}t.addEventListener("focusin",e=>{e.target.scrollIntoView?.({block:"nearest",inline:"nearest"})}),n.appendChild(t)}let C=null;if(a.onGoTo){s.length>0&&n.appendChild(u(i,"span","oac-sep",{role:"separator"}));const t=y("oac-bottombar__goto",R(e,"Go to"));t.appendChild(p(i,o.chromeIconSvg("calendar"),"chrome"));const r=u(i,"span");r.textContent=R(e,"Go to"),t.appendChild(r),t.setAttribute("aria-haspopup","dialog"),e.tips.attach(t,()=>({title:R(e,"Go to"),sub:null===Zt(D())?R(e,"Go to needs a time-based interval"):void 0,side:"top"})),t.addEventListener("click",()=>{"true"!==t.getAttribute("aria-disabled")&&a.onGoTo?.(t)}),n.appendChild(t),C=t}n.appendChild(u(i,"span","oac-bottombar__spacer"));const S=u(i,"span","oac-bottombar__status",{role:"status"}),A=u(i,"span","oac-bottombar__phase"),T=u(i,"b"),E=u(i,"span","oac-bottombar__detail");S.append(A,T,E),S.hidden=!0,n.appendChild(S);const L=u(i,"span","oac-sep",{role:"separator"});L.hidden=!0,n.appendChild(L);const O=y("oac-bottombar__clock",R(e,"schema.ui.bottombar.timezone",{zone:""},"Timezone: {zone}")),I=u(i,"span","oac-bottombar__time"),P=u(i,"small");O.append(I,P),O.setAttribute("aria-haspopup","menu"),e.tips.attach(O,()=>({title:R(e,"schema.ui.bottombar.timezone",{zone:v.timezone()},"Timezone: {zone}"),sub:R(e,"schema.ui.bottombar.timezoneHint",{},"The zone the time axis and the sessions are read in"),side:"top"})),O.addEventListener("click",()=>function(t){const o=c();if(null===o)return;const n=o.timezone(),a=r(),i=v.timezones(),s=e=>{let t="";try{t=Dt(a,e)}catch{}return{label:e,sub:t,on:e===n,onSelect:()=>v.setTimezone(e)}},l=function(){const e=Intl;try{return e.supportedValuesOf?.("timeZone")??[]}catch{return[]}}().filter(e=>!i.includes(e)),d=[...i.map(s)];l.length>0&&d.push(R(e,"schema.ui.bottombar.allZones",{},"All zones"),...l.map(s));M=vt(e,t,d,{find:R(e,"schema.ui.bottombar.findZone",{},"Find a zone"),ariaLabel:R(e,"schema.ui.bottombar.timezones",{},"Timezone")})}(O)),n.appendChild(O),n.appendChild(u(i,"span","oac-sep",{role:"separator"}));const $=u(i,"div","oac-bottombar__group oac-bottombar__scale",{role:"group","aria-label":R(e,"schema.ui.bottombar.scale",{},"Price scale")}),j=new Map;for(const t of Ai){const n=R(e,t.key,{},t.label),a=y("oac-bottombar__icon",n);a.dataset.scale=t.id,a.setAttribute("aria-pressed","false"),a.appendChild(p(i,o.chromeIconSvg(t.icon),"chrome")),e.tips.attach(a,()=>({title:n,sub:null===v.scale()?R(e,"schema.ui.bottombar.noScale",{},"Nothing is plotted on the price scale yet"):void 0,side:"top"})),a.addEventListener("click",()=>{"true"!==a.getAttribute("aria-disabled")&&v.toggleScale(t.id)}),$.appendChild(a),j.set(t.id,a)}function D(){const e=l();return e?.interval?.()??e?.chart.getDataContext()?.interval}n.appendChild($);let M=null;let z="";let N=null;const W=()=>{const e=v.marketStatus();if(S.hidden=null===e,L.hidden=null===e,null===e)return void(N=null);e.phase!==N&&(null!==N&&queueMicrotask(h),N=e.phase,S.dataset.phase=e.phase,A.textContent="",A.appendChild(p(i,o.chromeIconSvg(jt[e.phase]),"chrome"))),x(T,e.label),x(E,e.detail);const t=""===e.detail?e.label:`${e.label}, ${e.detail}`;S.getAttribute("aria-label")!==t&&S.setAttribute("aria-label",t)},B=()=>{const e=v.scale();for(const[t,o]of j){const n=null!==e&&e[t];o.getAttribute("aria-pressed")!==String(n)&&o.setAttribute("aria-pressed",String(n)),_(o,null===e)}},U=()=>{f||(!function(){const e=c();if(e===q)return;for(const e of K.splice(0))e();if(q=e,null===e)return;const t=()=>{f||B()},o=()=>{f||(U(),h())};K=[e.on("data:context",o),e.on("timezone:changed",o),e.on("state:restore:end",o),e.on("layout:change",()=>{f||(B(),W())}),e.on("zoom",t),e.on("pan",t),e.on("dblclick",t),e.on("destroy",()=>{f||queueMicrotask(U)})]}(),(()=>{const e=l(),t=e?.range?.()??null;for(const[o,n]of k){const a=o===t;n.getAttribute("aria-pressed")!==String(a)&&n.setAttribute("aria-pressed",String(a)),_(n,void 0===e?.setRange)}null!==C&&_(C,null===e||null===Zt(D()))})(),W(),(()=>{const t=c(),o=r(),n=t?.timezone()??"";x(I,null===t?"":Mt(o,n)),x(P,null===t?"":Dt(o,n)),n!==z&&(z=n,e.tips.refreshLabel(O),O.setAttribute("aria-label",R(e,"schema.ui.bottombar.timezone",{zone:n},"Timezone: {zone}"))),_(O,null===t)})(),B())};let q=null,K=[];const G=()=>{f||B()};i.addEventListener("pointerup",G,!0);let V=0;const H=()=>{if(0!==V&&clearTimeout(V),V=0,f||!0===i.hidden)return;const e=(a.now??Date.now)();V=setTimeout(J,1e3-(e%1e3+1e3)%1e3+5)};function J(){V=0,f||(U(),H())}const Z=()=>{!0!==i.hidden&&U(),H()};return i.addEventListener("visibilitychange",Z),U(),H(),{el:n,controls:v,refresh:U,destroy:()=>{if(!f){f=!0,b++,M?.(),null!==e.tips.target()&&n.contains(e.tips.target())&&e.tips.hide(),0!==V&&clearTimeout(V),V=0;for(const e of K.splice(0))e();i.removeEventListener("pointerup",G,!0),i.removeEventListener("visibilitychange",Z),n.removeEventListener("pointerdown",w),d.clear(),n.textContent=""}}}}const Oi=`\n.oac-widget.has-bottombar { grid-template-rows: auto minmax(0, 1fr) auto auto; }\n.oac-widget.has-bottombar > .oac-bottombar { grid-row: 3; }\n.oac-widget.has-bottombar > .oac-statusline { grid-row: 4; }\n.oac-widget.has-bottombar:not(.is-mobile) > .oac-toasts { bottom: calc(${Fn("status-h")} + 38px); }\n.oac-widget.is-mobile > .oac-bottombar:not(.is-kept) { display: none; }\n.oac-widget.is-mobile:has(> .oac-bottombar.is-kept) .oac-mobile__footer { grid-row: 4; }\n.oac-widget.is-mobile:has(> .oac-bottombar.is-kept) > .oac-toasts { bottom: calc(82px + env(safe-area-inset-bottom)); }\n.oac-widget .oac-bottombar { container: oac-bottombar / inline-size; display: flex; align-items: center; gap: 2px;\n  height: 28px; min-width: 0; padding: 0 6px; background: ${Fn("panel")}; border-top: 1px solid ${Fn("bd-soft")};\n  color: ${Fn("mut")}; font-size: 11.5px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; }\n.oac-widget .oac-bottombar .oac-sep { height: 16px; }\n.oac-widget .oac-bottombar__group { display: inline-flex; align-items: center; gap: 1px; min-width: 0; }\n.oac-widget .oac-bottombar__ranges { flex: 0 1 auto; min-width: 56px; overflow-x: auto; scrollbar-width: none; }\n.oac-widget .oac-bottombar__scale { flex: none; }\n.oac-widget .oac-bottombar__ranges::-webkit-scrollbar { width: 0; height: 0; }\n.oac-widget .oac-bottombar button { display: inline-flex; align-items: center; gap: 5px; flex: none; height: 22px;\n  padding: 0 7px; background: transparent; border: 1px solid transparent; border-radius: 5px; color: ${Fn("mut")};\n  font-size: 11.5px; font-weight: 600; letter-spacing: .2px; transition: background .1s, color .1s, border-color .1s; }\n.oac-widget .oac-bottombar button:hover { background: ${Fn("elev")}; color: ${Fn("tx")}; }\n.oac-widget .oac-bottombar button[aria-pressed="true"] { background: ${Fn("on-bg")}; border-color: ${Fn("on-bd")}; color: ${Fn("acc-2")}; }\n.oac-widget .oac-bottombar button[aria-disabled="true"] { background: transparent; border-color: transparent; color: ${Fn("faint")}; cursor: default; }\n.oac-widget .oac-bottombar button:focus-visible { outline-offset: -1px; }\n.oac-widget .oac-bottombar .oac-glyph > svg { width: 14px; height: 14px; }\n.oac-widget .oac-bottombar__icon { width: 24px; padding: 0; justify-content: center; }\n.oac-widget .oac-bottombar__spacer { flex: 1 1 auto; min-width: 6px; }\n.oac-widget .oac-bottombar__status { display: inline-flex; flex: none; align-items: center; gap: 5px; padding: 0 5px; }\n.oac-widget .oac-bottombar__status > b { flex: none; color: ${Fn("tx")}; font-weight: 600; }\n.oac-widget .oac-bottombar__phase { display: inline-grid; flex: none; color: ${Fn("faint")}; }\n.oac-widget .oac-bottombar__status[data-phase="regular"] .oac-bottombar__phase { color: ${Fn("up")}; }\n.oac-widget .oac-bottombar__status:is([data-phase="pre"], [data-phase="post"], [data-phase="extended"]) .oac-bottombar__phase { color: ${Fn("amber")}; }\n.oac-widget .oac-bottombar__detail { color: ${Fn("faint")}; }\n.oac-widget .oac-bottombar__clock { color: ${Fn("tx")}; }\n.oac-widget .oac-bottombar__time { font-weight: 500; }\n.oac-widget .oac-bottombar__clock > small { color: ${Fn("faint")}; font-size: 10.5px; font-weight: 600; }\n.oac-widget .oac-mobile-sheet__note { grid-column: 1 / -1; margin: 0; padding: 8px 10px 10px; color: ${Fn("mut")};\n  border-bottom: 1px solid ${Fn("bd-soft")}; margin-bottom: 6px; font-variant-numeric: tabular-nums; }\n.oac-widget .oac-mobile-sheet__note > b { color: ${Fn("tx")}; font-weight: 600; }\n.oac-widget .oac-mobile-sheet__body > [data-mobile-action="timezone"] { grid-column: 1 / -1; }\n.oac-widget .oac-mobile-sheet__ranges, .oac-widget .oac-mobile-sheet__scales { grid-column: 1 / -1; display: grid; }\n.oac-widget .oac-mobile-sheet__ranges { grid-template-columns: repeat(5, minmax(0, 1fr)); }\n.oac-widget .oac-mobile-sheet__scales { grid-template-columns: repeat(3, minmax(0, 1fr)); }\n.oac-widget .oac-statusline__market[data-phase="regular"] { color: ${Fn("up")}; }\n@container oac-bottombar (max-width: 760px) {\n  .oac-widget .oac-bottombar__detail, .oac-widget .oac-bottombar__goto > span:not(.oac-glyph) { display: none; }\n}\n@container oac-bottombar (max-width: 600px) {\n  .oac-widget .oac-bottombar__clock > small { display: none; }\n}\n@container oac-bottombar (max-width: 360px) {\n  .oac-widget .oac-bottombar__status > b { display: none; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .oac-widget .oac-bottombar button { transition: none; }\n}\n`,Ii=e=>e.trim().toLocaleLowerCase().replace(/\s+/g," ");function Pi(e,t,n,a){const i=e.document,r=u(i,"div","oac-mobile-drawings__row"),s=a.makeAction("tool","",()=>{e.draw.setTool(t.id),a.close()});s.classList.add("oac-mobile__tool"),s.dataset.tool=t.id,s.setAttribute("aria-pressed",String(e.draw.activeTool()===t.id));const l=u(i,"span");l.textContent=n,s.append(Lt(i,t.id),l);const c=a.rail.isFavorite(t.id),d=a.makeAction("favorite","",()=>{a.rail.toggleFavorite(t.id),a.refresh()});return d.classList.add("oac-mobile-drawings__pin"),d.dataset.tool=t.id,d.setAttribute("aria-pressed",String(c)),d.setAttribute("aria-label",R(e,"schema.ui.mobile.drawings.pin",{name:n},"Pin {name} to rail")),d.appendChild(p(i,o.chromeIconSvg(c?"star-filled":"star"),"chrome")),r.append(s,d),r}function $i(e,t,n){const a=e.document,i=void 0===n.tools?null:new Set(n.tools),r=()=>o.registeredDrawingTools().filter(e=>null===i||i.has(e.id)),s=u(a,"div","oac-mobile-drawings__filters"),l=R(e,"schema.ui.mobile.drawings.search",{},"Search drawings"),c=u(a,"input","oac-mobile-drawings__search",{type:"search","aria-label":l,placeholder:l,autocomplete:"off",spellcheck:"false"});c.dataset.mobileAction="drawing-search";const{wrap:d,select:p}=rt(a);p.classList.add("oac-mobile-drawings__groups"),p.dataset.mobileAction="drawing-group",p.setAttribute("aria-label",R(e,"schema.ui.mobile.drawings.group",{},"Drawing group"));const h=new Set(r().map(e=>e.id)),m=St.filter(e=>void 0!==e.id&&(e.items??[]).some(e=>void 0!==e.tool&&h.has(e.tool))),g=[["all",R(e,"schema.ui.mobile.drawings.all",{},"All tools")],["favorites",R(e,"schema.ui.mobile.drawings.favorites",{},"Favorites")],...m.map(t=>[t.id,R(e,`schema.rail.${t.id}.title`,{},t.title??t.id)])];for(const[e,t]of g){const o=u(a,"option","",{value:e});o.textContent=t,p.appendChild(o)}p.value="all",s.append(c,d);const f=u(a,"div","oac-mobile-sheet__controls"),b=n.makeAction("cursor",R(e,"Cursor"),()=>{e.draw.setTool(null),n.close()});b.classList.add("oac-mobile-drawings__cursor"),b.prepend(Lt(a,"cursor"));const v=u(a,"div","oac-mobile-drawings__list",{role:"group","aria-label":R(e,"Drawing tools")}),w=u(a,"div","oac-mobile-drawings__empty",{role:"status","aria-live":"polite"});w.textContent=R(e,"schema.ui.mobile.drawings.empty",{},"No drawing tools found"),t.append(s,f,b,v,w);const y=()=>{f.textContent="",f.append(...function(e,t){if(null===e.draw.activeTool())return[];const o=t.rail;return[t.makeAction("finish",R(e,"Finish"),()=>{e.draw.finish(),t.refresh()}),t.makeAction("cancel",R(e,"Cancel"),()=>{e.draw.cancel(),t.refresh()}),...t.historyActions(),t.makeAction("magnet",R(e,"Magnet: {mode}",{mode:R(e,`schema.magnet.${o.magnetMode()}`,{},o.magnetMode())}),()=>{o.cycleMagnet(),t.refresh()}),t.makeAction("stay",R(e,"Keep tool active: {mode}",{mode:o.stayMode()?R(e,"on"):R(e,"off")}),()=>{o.setStayMode(!o.stayMode()),t.refresh()})]}(e,n)),f.hidden=0===f.children.length,b.setAttribute("aria-pressed",String(null===e.draw.activeTool()));const t=Ii(c.value),o=m.find(e=>e.id===p.value),a=void 0===o?null:new Set(o.items?.map(e=>e.tool));v.textContent="";for(const o of r()){if("favorites"===p.value&&!n.rail.isFavorite(o.id))continue;if(null!==a&&!a.has(o.id))continue;const i=R(e,`schema.drawing.${o.id}.name`,{},o.name);(""===t||[o.id,o.name,i].some(e=>Ii(e).includes(t)))&&v.appendChild(Pi(e,o,i,n))}w.hidden=v.children.length>0};for(const[e,o]of[[c,"input"],[p,"change"]])e.addEventListener(o,()=>{t.scrollTop=0,n.refresh()});return y(),y}const ji=`\n.oac-widget .oac-mobile-drawings__filters { grid-column: 1 / -1; display: grid; gap: 8px; margin-bottom: 8px; }\n.oac-widget .oac-mobile-drawings__filters > input, .oac-widget .oac-mobile-drawings__groups { width: 100%; min-width: 0; height: 44px; }\n.oac-widget .oac-mobile-drawings__filters > .oac-select { min-width: 0; }\n.oac-widget .oac-mobile-drawings__cursor, .oac-widget .oac-mobile-drawings__list,\n.oac-widget .oac-mobile-drawings__empty { grid-column: 1 / -1; }\n.oac-widget .oac-mobile-drawings__cursor { text-align: left; }\n.oac-widget .oac-mobile-drawings__row { display: grid; grid-template-columns: minmax(0, 1fr) 44px; border-top: 1px solid ${Fn("bd-soft")}; }\n.oac-widget .oac-mobile-drawings__row > .oac-mobile__tool { display: flex; align-items: center; gap: 10px; text-align: left; }\n.oac-widget .oac-mobile-drawings__row > .oac-mobile__tool > .oac-glyph { margin: 0; }\n.oac-widget .oac-mobile-drawings__pin { min-width: 44px; }\n.oac-widget .oac-mobile-sheet .oac-mobile-drawings__pin > .oac-glyph { margin: 0; }\n.oac-widget .oac-mobile-drawings__empty { min-height: 44px; padding: 13px 10px; color: ${Fn("mut")}; }\n`;const Di=["tool","interval","chartType","range","scale","zone"];function Mi(e,t){const n=e.document,a=t.mode??"auto",i=u(n,"div","oac-mobile");e.root.appendChild(i);let r=!1,s=!1,l=!1,c=null,d=null,h=null;const m=[],g=e=>{e.stopPropagation()};i.addEventListener("pointerdown",g);const f=(e,t,o)=>{const a=u(n,"button","oac-mobile__action",{type:"button"});return a.dataset.mobileAction=e,a.textContent=t,a.addEventListener("click",()=>{"true"!==a.getAttribute("aria-disabled")&&o(a)}),a},b=()=>["undo","redo"].map(t=>{const o=f(t,R(e,"undo"===t?"Undo":"Redo"),()=>{L(e,t),P()});return o.setAttribute("aria-disabled",String(!I(e,t))),o}),v=()=>{const e=h;h=null,e?.close()},w=()=>c?.close(),y=(t,o,a,i=void 0)=>{v();const s=u(n,"section","oac-mobile-sheet",{"aria-label":t}),l=u(n,"div","oac-mobile-sheet__head oac-dialog__head"),c=u(n,"strong","oac-mobile-sheet__title");c.textContent=t;const d=f("close",R(e,"Close"),()=>v());l.append(c,d);const p=u(n,"div","oac-mobile-sheet__body");s.append(l,p);const m=()=>{if(r||h?.repaint!==m)return;const e=n.activeElement,t=null!==e&&p.contains(e),o=t?(e=>{const t=e.closest("[data-mobile-action]"),o=t?.dataset.mobileAction;if(null===t||void 0===o)return null;const n={action:o};for(const e of Di)void 0!==t.dataset[e]&&(n[e]=t.dataset[e]);return n})(e):null,i=p.scrollTop;if(void 0!==w?w():(p.textContent="",a(p,v)),p.scrollTop=i,t){const e=null===o?null:((e,t)=>Array.from(e.querySelectorAll("[data-mobile-action]")).find(e=>e.dataset.mobileAction===t.action&&Di.every(o=>e.dataset[o]===t[o]))??null)(p,o);(e??p.querySelector(".oac-mobile__tool")??p.querySelector("[data-mobile-action]"))?.focus()}};let g=()=>{};const b={close:()=>g(),repaint:m};h=b;const w=a(p,v);g=e.openOverlay(s,{anchor:o,placement:"center",dismissOnOutside:!0,initialFocus:"function"==typeof i?i(p):i,onClose:()=>{h===b&&(h=null)}})};let _=null;if(t.topbar){const o=u(n,"div","oac-mobile__header",{role:"toolbar","aria-label":R(e,"Chart header")});d=u(n,"input","oac-mobile__symbol",{type:"text","aria-label":R(e,"Symbol"),placeholder:R(e,"Symbol"),autocomplete:"off",spellcheck:"false"}),_=f("interval","",o=>{t.timeframePreferences?G(e,o,{intervals:t.intervals,current:()=>t.state().interval,preferences:t.timeframePreferences,...t.canSelectInterval?{canSelect:t.canSelectInterval}:{},onSelect:t.onInterval}):y(R(e,"Interval"),o,(e,o)=>{!function(e,t,o,n){for(const a of e.intervals){const i=n("pick-interval",vn(a),()=>{e.onInterval(a),o()});i.dataset.interval=a;const r=e.state().interval===a;i.setAttribute("aria-pressed",String(r)),t.appendChild(i)}}(t,e,o,f)})});const a=(e,o)=>{const n=e.trim().toUpperCase();w(),""!==n&&t.onSymbol(n,o),P(),d?.blur()};void 0!==t.search&&(c=Ht(e,d,{search:t.search,onSelect:a,context:()=>`${t.state().exchange}:${t.state().symbol}:${t.state().interval}`,variant:"mobile"})),d.addEventListener("keydown",e=>{"Enter"===e.key&&(e.preventDefault(),(null===c||c.canCommitRaw())&&a(d?.value??""))}),o.append(d,_),i.appendChild(o)}const x=u(n,"div","oac-mobile__footer"),k=u(n,"div","oac-mobile__selection",{role:"toolbar","aria-label":R(e,"Selected drawing")});let C=null,S=null,A=null;null!==t.rail&&(C=f("properties",R(e,"Properties"),e=>{t.onProperties(e)}),S=f("lock",R(e,"Lock"),()=>{kt(e,"lock",e.draw.selection()),P()}),A=f("delete",R(e,"Delete"),()=>{kt(e,"delete",e.draw.selection()),P()}),k.append(C,S,A),x.appendChild(k));const T=u(n,"nav","oac-mobile__bar",{"aria-label":R(e,"Chart controls")});let E=null,O=null;function P(){if(r)return;const o=t.state();if(null!==d&&n.activeElement!==d&&(d.value=o.symbol),null!==_&&(_.textContent=vn(o.interval)),null!==E&&E.setAttribute("aria-pressed",String(null!==e.draw.activeTool())),null!==O&&O.setAttribute("aria-disabled",String(!t.indicatorsAvailable())),null!==k.parentNode){const t=e.draw.selection();k.hidden=0===t.length;const o=xt(e,t);t.length>0&&null!==S&&(S.setAttribute("aria-pressed",String(o.locked)),S.setAttribute("aria-disabled",String(0===o.editable.length))),null!==C&&C.setAttribute("aria-disabled",String(0===t.length)),null!==A&&A.setAttribute("aria-disabled",String(null!==o.noDelete||0===o.editable.length))}h?.repaint()}null!==t.rail&&(E=f("draw",R(e,"Draw"),o=>{y(R(e,"Drawing"),o,(o,n)=>$i(e,o,{rail:t.rail,tools:t.tools,makeAction:f,historyActions:b,refresh:P,close:n}),e=>e.querySelector(".oac-mobile-sheet__controls button, .oac-mobile__tool")??e.querySelector('[data-mobile-action="cursor"]'))}),T.appendChild(E)),t.topbar&&t.indicators&&(O=f("studies",R(e,"Indicators"),e=>{t.onIndicators(e)}),T.appendChild(O)),t.topbar&&(T.appendChild(f("objects",R(e,"Objects"),e=>{t.onObjects(e)})),t.onDataWindow&&T.appendChild(f("data-window",R(e,"schema.ui.dataWindow",{},"Data"),e=>{t.onDataWindow?.(e)})),T.appendChild(f("more",R(e,"More"),a=>{y(R(e,"More"),a,(i,r)=>{const s=t.bottombar;void 0!==s&&i.appendChild(function(e){const t=u(n,"p","oac-mobile-sheet__note"),o=e.marketStatus();if(null!==o){const e=u(n,"b");e.textContent=o.label,t.append(e,n.createTextNode(""===o.detail?" · ":` ${o.detail} · `))}return t.appendChild(n.createTextNode(e.clock())),t}(s)),i.append(...b()),t.onCapture&&i.appendChild(f("capture",R(e,"Capture"),()=>{r(),t.onCapture?.(a)})),t.onLayouts&&i.appendChild(f("layouts",R(e,"schema.ui.layouts.title",{},"Layouts"),()=>{r(),t.onLayouts?.(a)}));for(const[o,n,s]of[["watchlist","Watchlist",t.onWatchlist],["news","News",t.onNews]])s&&i.appendChild(f(o,R(e,`schema.ui.dock.${o}`,{},n),()=>{r(),s(a)}));if(t.onAlerts&&i.appendChild(f("alerts",R(e,"Alerts"),()=>{r(),t.onAlerts?.(a)})),t.onGoTo){const o=f("go-to",R(e,"Go to"),()=>{r(),t.onGoTo?.(a)});o.setAttribute("aria-disabled",String(null===Zt(t.state().interval))),i.appendChild(o)}const l=f("theme","dark"===t.state().theme?R(e,"Switch to the light theme"):R(e,"Switch to the dark theme"),()=>{t.onTheme(),r()});i.appendChild(l);const c=f("settings",R(e,"Chart settings"),()=>{r(),t.onSettings(a)});c.setAttribute("aria-disabled",String(!t.settingsAvailable())),i.appendChild(c);const d=wn(e.chart,e);if(null!==d){const e=u(n,"a","oac-mobile__action oac-mobile__branding",{href:d.href,target:"_blank",rel:"noopener noreferrer","aria-label":d.label});e.dataset.mobileAction="branding",e.textContent=d.label,i.appendChild(e)}void 0!==s&&function(t,o,a,i){const r=e=>{const o=u(n,"div","oac-head");o.textContent=e,t.appendChild(o)},s=(e,o)=>{r(o);const a=u(n,"div",e,{role:"group","aria-label":o});return t.appendChild(a),a},l=o.ranges();if(l.length>0){const t=s("oac-mobile-sheet__ranges",R(e,"schema.ui.bottombar.ranges",{},"Range")),n=o.range();for(const a of l){const r=f("range",R(e,`schema.ui.range.${a.id}`,{},a.label),()=>{o.setRange(a.id),i()});r.dataset.range=a.id,r.setAttribute("aria-pressed",String(n===a.id)),t.appendChild(r)}}const c=s("oac-mobile-sheet__scales",R(e,"schema.ui.bottombar.scale",{},"Price scale")),d=o.scale();for(const t of Ai){const n=f("scale",R(e,t.key,{},t.label),()=>{o.toggleScale(t.id),P()});n.dataset.scale=t.id,n.setAttribute("aria-pressed",String(null!==d&&d[t.id])),n.setAttribute("aria-disabled",String(null===d)),c.appendChild(n)}r(R(e,"schema.ui.bottombar.timezones",{},"Timezone"));const p=f("timezone",o.timezone(),()=>{y(R(e,"schema.ui.bottombar.timezones",{},"Timezone"),a,(e,t)=>{const n=o.timezone();for(const a of o.timezones()){const i=f("pick-zone",a,()=>{o.setTimezone(a),t()});i.dataset.zone=a,i.setAttribute("aria-pressed",String(a===n)),e.appendChild(i)}})});p.setAttribute("aria-label",R(e,"schema.ui.bottombar.timezone",{zone:o.timezone()},"Timezone: {zone}")),p.setAttribute("aria-haspopup","dialog"),t.appendChild(p)}(i,s,a,r);const h=u(n,"div","oac-head");h.textContent=R(e,"Chart type"),i.appendChild(h);for(const a of bn()){const s=f("chart-type",R(e,`schema.chartType.${a}`,{},fn(a)),()=>{t.onChartType(a),r()});void 0!==o.chartTypeIcon(a)&&s.prepend(p(n,o.chromeIconSvg(`chart-${a}`),"chrome")),s.dataset.chartType=a,s.setAttribute("aria-pressed",String(t.state().chartType===a)),i.appendChild(s)}})}))),T.children.length>0&&x.appendChild(T),x.children.length>0&&i.appendChild(x);const $="auto"===a?n.defaultView?.matchMedia?.("(pointer: coarse)")??null:null,j=t=>null!==t&&e.root.contains(t)&&(/^(INPUT|TEXTAREA)$/.test(t.tagName)||!0===t.isContentEditable);let D=!1;const M=o=>{const r=t.container.getBoundingClientRect(),c=r.width||t.container.clientWidth,d=r.height||t.container.clientHeight;if(l&&!(c*d>0))return;const u=function(e,t,o,n){return"auto"!==e?"always"===e:t>0&&(t<=640||n&&t<=960&&o>0&&o<600)}(a,c,d,!0===$?.matches);l&&u===s?D=!1:l&&!o&&j(n.activeElement)?D=!0:(D=!1,l=!0,s=u,e.root.classList.toggle("is-mobile",s),e.root.dataset.mobile=String(s),i.hidden=!s,s||(v(),w()))},z=()=>M(!1),N=n.defaultView?.ResizeObserver;let F=null;if("auto"===a){const t=e=>{D&&!j(e.relatedTarget)&&M(!0)};e.root.addEventListener("focusout",t),m.push(()=>e.root.removeEventListener("focusout",t))}if("auto"===a&&void 0!==N)F=new N(z),F.observe(t.container);else if("auto"===a){const e=n.defaultView;null!==e&&"function"==typeof e.addEventListener&&(e.addEventListener("resize",z),m.push(()=>e.removeEventListener("resize",z)))}null!==$&&("function"==typeof $.addEventListener?($.addEventListener("change",z),m.push(()=>$.removeEventListener("change",z))):($.addListener(z),m.push(()=>$.removeListener(z))));for(const t of["draw:tool","draw:select","drawing:select","drawing:change","draw:add","draw:remove","draw:update"])m.push(e.chart.on(t,P));return void 0!==e.history&&m.push(e.history.subscribe(P)),m.push(e.bus.on("symbol",P)),m.push(e.bus.on("interval",P)),m.push(e.bus.on("theme",P)),m.push(e.chart.on("branding:changed",P)),void 0!==t.bottombar&&m.push(t.bottombar.subscribe(P)),z(),P(),{el:i,active:()=>s,refresh:P,destroy:()=>{if(!r){r=!0,c?.destroy(),v(),F?.disconnect(),F=null;for(const e of m.splice(0))e();i.removeEventListener("pointerdown",g),i.remove(),e.root.classList.remove("is-mobile"),delete e.root.dataset.mobile}}}}const zi=[1,1.5,2,3,4],Ni={solid:"minus",dashed:"line-dashed",dotted:"line-dotted",mixed:"line-mixed"},Ri=Symbol("mixed");function Fi(e,t,o){let n,a=!1;for(const i of e){const e=wa(i,{fields:[t]},E(i.tool),o)[t.path];if(a){if(JSON.stringify(e)!==JSON.stringify(n))return Ri}else n=e,a=!0}return a?n:void 0}let Wi=0;function Bi(e,t,n={}){const{draw:a,chart:i}=e,r=e.document,s="oac-drawbar-"+ ++Wi,l=nt(r,"div","oac-drawbar");l.setAttribute("role","toolbar"),l.setAttribute("aria-label",R(e,"Drawing toolbar")),l.dataset.keyScope="drawing-toolbar",l.hidden=!0;const c=()=>n.chart??pa(i),d=c(),u=Array.from(t.children),p=null===d?-1:u.indexOf(d);t.insertBefore(l,p<0?null:u[p+1]??null);const h=e=>{e.stopPropagation()};l.addEventListener("pointerdown",h),l.addEventListener("dblclick",h);let m=[],g=[],f=new Map,b=!1,v=!1;const y=(t,o=m)=>{kt(e,t,o),V()},_=(t,n)=>{if(void 0===f.get(t))return;const i=T(a,m).flatMap(e=>{const i=a.get(e),r=void 0===i?{}:o.applyDrawingSettings(i,{[t]:n},o.drawingSettingsSchema(i.tool));return Object.keys(r).length>0?[{id:e,patch:r}]:[]});O(e,t,()=>{i.length>0&&a.updateMany(i)}),V()},x=Ge(r,{id:`${s}-color`,label:R(e,"Color"),value:"#000000",translate:e.translate,openOverlay:e.openOverlay,onChange:e=>{_("style.color",e)}});x.el.classList.add("oac-drawbar__color");const k=x.trigger,C=it(r,{label:"",onClick:()=>function(){const t=f.get("style.lineWidth");if(void 0===t)return;const o=Fi(g,t,e.chartTheme.lineColor);U(C,zi.map(t=>({label:R(e,"{value} px",{value:t}),on:o===t,onSelect:()=>_("style.lineWidth",t)})),R(e,"Line width"))}()});C.classList.add("oac-drawbar__width"),C.setAttribute("aria-haspopup","menu");const S=it(r,{label:"",iconOnly:!0,onClick:()=>function(){const t=f.get("style.lineStyle");if(void 0===t)return;const n=Fi(g,t,e.chartTheme.lineColor);U(S,o.LINE_STYLE_OPTIONS.map(e=>({label:q(e.value),icon:Ni[e.value],on:n===e.value,onSelect:()=>_("style.lineStyle",e.value)})),R(e,"Line style"))}()});S.setAttribute("aria-haspopup","menu");const A=nt(r,"span","oac-glyph oac-glyph--chrome");S.appendChild(A);const L=it(r,{label:R(e,"Lock"),icon:"lock",iconOnly:!0,onClick:()=>{y("lock")}}),I=it(r,{label:R(e,"Delete"),icon:"trash",iconOnly:!0,variant:"danger",onClick:()=>{y("delete")}}),P=it(r,{label:R(e,"More drawing actions"),icon:"more",iconOnly:!0,onClick:()=>function(){const t=m.slice(),{hidden:o,readOnly:a}=xt(e,t),i=[{label:R(e,"Properties..."),icon:"settings",onSelect:()=>{_a(e,void 0,{ids:t})}},{label:R(e,"Duplicate"),icon:"duplicate",key:ze(e.keymap,"duplicate","Mod+D"),onSelect:()=>{y("duplicate",t)}},{label:R(e,o?"Show":"Hide"),icon:o?"eye-off":"eye",disabled:null!==a,sub:a??void 0,onSelect:()=>{y("visible",t)}},R(e,"Order"),{label:R(e,"Bring to front"),icon:"front",onSelect:()=>{y("front",t)}},{label:R(e,"Send to back"),icon:"back",onSelect:()=>{y("back",t)}},{label:R(e,"In front of the series"),icon:"above-series",onSelect:()=>{y("above",t)}},{label:R(e,"Behind the series"),icon:"behind-series",onSelect:()=>{y("behind",t)}}];n.templates&&i.push(...Hn(e,n.templates,t,P));U(P,i,R(e,"More drawing actions"))}()});P.setAttribute("aria-haspopup","menu");const $=()=>nt(r,"span","oac-sep"),j=$();l.append(x.el,C,S,j,L,I,$(),P);for(const[e,t]of[["color",k],["width",C],["style",S],["lock",L],["delete",I],["more",P]])t.dataset.drawbar=e;const D=()=>[k,C,S,L,I,P].filter(e=>!(e.disabled||e.hidden||e===k&&x.el.hidden));let M=P;const z=e=>{M=e;for(const t of[k,C,S,L,I,P])t.tabIndex=t===e?0:-1};l.addEventListener("focusin",e=>{const t=e.target?.closest?.("[data-drawbar]");null!==t&&l.contains(t)&&z(t)});const N=e=>{const t=D();if(0===t.length)return;const o=t[(e%t.length+t.length)%t.length];z(o),o.focus()},F=()=>D().indexOf(r.activeElement),W=(t,o,n,a=!1)=>e.keymap.register(t,o,"drawing-toolbar",{label:n,group:"Drawing toolbar",layered:!0,hidden:a}),B=[W("ArrowRight",()=>{N(F()+1)},"Next control"),W("ArrowLeft",()=>{N(F()-1)},"Previous control"),W("Home",()=>{N(0)},"First control"),W("End",()=>{N(D().length-1)},"Last control"),W("ArrowDown",()=>{N(F()+1)},"Next control",!0),W("ArrowUp",()=>{N(F()-1)},"Previous control",!0),W("Shift+ArrowRight",()=>{N(F()+1)},"Next control",!0),W("Shift+ArrowDown",()=>{N(F()+1)},"Next control",!0),W("Shift+ArrowLeft",()=>{N(F()-1)},"Previous control",!0),W("Shift+ArrowUp",()=>{N(F()-1)},"Previous control",!0),W("Escape",()=>{c()?.focus()},"Back to the chart")],U=(t,o,n)=>{vt(e,t,o,{ariaLabel:n})};const q=t=>R(e,"dashed"===t?"Dashed":"dotted"===t?"Dotted":"Solid");const K=()=>{if(l.hidden)return;const e=l.contains(r.activeElement);l.hidden=!0,e&&c()?.focus()};function G(){const e=c();if(null===e||l.hidden)return;const o=w(t,e);let n=1/0,i=-1/0,r=1/0,s=-1/0;for(const e of m)for(const t of a.screenPoints(e)??[])Number.isFinite(t.x)&&Number.isFinite(t.y)&&(n=Math.min(n,t.x),i=Math.max(i,t.x),r=Math.min(r,t.y),s=Math.max(s,t.y));const d=l.offsetWidth,u=l.offsetHeight,p=o.left+6,h=Math.max(p,o.right-6-d),g=o.top+6,f=Math.max(g,o.bottom-6-u);let b,v;if(Number.isFinite(n)){const e=o.right-o.left,t=Math.max(0,Math.min(e,n)),a=Math.max(0,Math.min(e,i));b=o.left+(t+a)/2-d/2;const l=o.top+r-10-u,c=o.top+s+10;v=l>=g?l:c<=f?c:l}else b=o.left+(o.right-o.left-d)/2,v=g;l.style.left=`${Math.round(Math.min(h,Math.max(p,b)))}px`,l.style.top=`${Math.round(Math.min(f,Math.max(g,v)))}px`}function V(){v||(m=a.selection().slice(),g=m.map(e=>a.get(e)).filter(e=>void 0!==e),0===g.length||null!==a.activeTool()||b?K():(f=new Map(fa(g.map(e=>e.tool)).fields.map(e=>[e.path,e])),function(){const t=xt(e,m),n=t.readOnly,a=e.chartTheme.lineColor,i=f.get("style.color");if(x.el.hidden=void 0===i,void 0!==i){const t=Fi(g,i,a);x.el.classList.toggle("is-mixed",t===Ri),t!==Ri&&x.write(t);const[o,r]=[...new Set(g.map(e=>String(wa(e,{fields:[i]},E(e.tool),a)["style.color"])))];k.style.backgroundImage=t===Ri?`linear-gradient(135deg, ${o} 0 50%, ${r??o} 50% 100%)`:"",k.setAttribute("aria-label",R(e,"Color: {value}",t===Ri?{value:R(e,"mixed")}:{value:String(t??"")})),k.disabled=null!==n,k.title=null===n?R(e,"Color"):`${R(e,"Color")} (${n})`}const s=f.get("style.lineWidth");if(C.hidden=void 0===s,void 0!==s){const t=Fi(g,s,a),o=t===Ri?R(e,"Mixed"):R(e,"{value} px",{value:Number(t??1)});C.textContent=o,C.setAttribute("aria-label",R(e,"Line width: {value}",{value:t===Ri?R(e,"mixed"):o})),C.classList.toggle("is-mixed",t===Ri),C.disabled=null!==n,C.title=null===n?R(e,"Line width"):`${R(e,"Line width")} (${n})`}const l=f.get("style.lineStyle");if(S.hidden=void 0===l,void 0!==l){const t=Fi(g,l,a),i=t===Ri?"mixed":"string"==typeof t?t:"solid";A.innerHTML=o.chromeIconSvg(Ni[i]??"minus"),S.classList.toggle("is-mixed",t===Ri);const r=t===Ri?R(e,"mixed"):q(i);S.setAttribute("aria-label",R(e,"Line style: {style}",{style:r})),S.disabled=null!==n,S.title=null===n?R(e,"Line style: {style}",{style:r}):`${R(e,"Line style")} (${n})`}j.hidden=x.el.hidden&&C.hidden&&S.hidden,L.replaceChildren(at(r,t.locked?"lock":"unlock")),L.setAttribute("aria-label",R(e,"Lock")),L.setAttribute("aria-pressed",t.locked?"true":t.partlyLocked?"mixed":"false"),L.disabled=null!==n,L.title=null===n?R(e,"Lock"):`${R(e,"Lock")} (${n})`;const c=t.noDelete;I.disabled=null!==c;const d=c??ze(e.keymap,"delete","Delete");I.title=void 0===d?R(e,"Delete"):`${R(e,"Delete")} (${d})`,D().includes(M)?z(M):z(D()[0]??P)}(),l.hidden=!1,G()))}const H=()=>{v||l.hidden||G()},J=[];for(const e of["draw:select","drawing:select","draw:update","draw:remove","draw:add","draw:restore","drawing:change","draw:tool"])J.push(i.on(e,V));for(const e of["pan","zoom","resize","paneResized","paneMoved","paneCollapsed","paneMaximized","paneAdded","paneRemoved","data:update","layout:change"])J.push(i.on(e,H));if(null!==d){const e=e=>{0!==e.buttons&&H()},t={passive:!0};d.addEventListener("pointermove",e,t);for(const e of["pointerup","wheel","dblclick"])d.addEventListener(e,H,t);J.push(()=>{d.removeEventListener("pointermove",e,t);for(const e of["pointerup","wheel","dblclick"])d.removeEventListener(e,H,t)})}J.push(i.on("draw:preview",()=>{b||(b=!0,K())}));for(const e of["draw:preview-clear","drag:end","drag:cancel"])J.push(i.on(e,()=>{b&&(b=!1,V())}));J.push(e.bus.on("theme",V)),void 0!==e.history&&J.push(e.history.subscribe(V));const Z=r.defaultView?.ResizeObserver;let Y=null;return void 0!==Z&&null!==d&&(Y=new Z(H),Y.observe(d)),V(),{el:l,refresh:V,destroy:()=>{if(!v){v=!0;for(const e of J.splice(0))e();for(const e of B.splice(0))e();Y?.disconnect(),x.destroy(),l.removeEventListener("pointerdown",h),l.removeEventListener("dblclick",h),l.remove()}}}}const Ui='\n.oac-widget .oac-drawbar { position: absolute; z-index: 25; display: flex; align-items: center; gap: 2px; padding: 3px;\n  background: var(--oac-panel); border: 1px solid var(--oac-bd); border-radius: 9px; box-shadow: var(--oac-shadow); }\n.oac-widget .oac-drawbar .oac-btn { height: 28px; }\n.oac-widget .oac-drawbar .oac-sep { height: 18px; margin: 0 3px; }\n.oac-widget .oac-drawbar__color { margin: 0 2px; }\n.oac-widget .oac-drawbar__width { min-width: 44px; padding: 0 7px; font-size: 11.5px; font-variant-numeric: tabular-nums; color: var(--oac-tx); }\n.oac-widget .oac-drawbar .is-mixed { color: var(--oac-mut); font-style: italic; }\n.oac-widget .oac-drawbar .oac-btn[aria-pressed="mixed"] { border-color: var(--oac-on-bd); border-style: dashed; }\n.oac-widget.is-mobile .oac-drawbar { display: none; }\n/* The properties dialog edits the same selection in full; two surfaces for it would sit on each other. */\n.oac-widget:has(.oac-layer > .oac-props) .oac-drawbar { visibility: hidden; }\n',qi=(e,t)=>Array.from(e,e=>{const o=e.charCodeAt(0);return o>=32&&127!==o||t&&"\n"===e?e:" "}).join(""),Ki=(e,t)=>qi(e,!1).replace(/\s+/g," ").trim().slice(0,t);function Gi(e){if(null===e||"object"!=typeof e)return null;const{id:t,time:o}=e,n="string"==typeof e.headline?Ki(e.headline,500):"";if("string"!=typeof t||""===t||t.length>256||""===n||"number"!=typeof o||!Number.isFinite(o)||o<=0)return null;const a={id:t,headline:n,time:o},i="string"==typeof e.source?Ki(e.source,120):"";""!==i&&(a.source=i);const r="string"==typeof e.summary?(s=e.summary,l=4e3,qi(s.replace(/\r\n?/g,"\n"),!0).trim().slice(0,l)):"";var s,l;return""!==r&&(a.summary=r),"string"==typeof e.url&&e.url.length<=2048&&(a.url=e.url.trim()),a}class Vi{constructor(e){Object.defineProperty(this,"_feed",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_pageSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_staleAfter",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_maxItems",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_now",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_onChange",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_instrument",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_status",{enumerable:!0,configurable:!0,writable:!0,value:"idle"}),Object.defineProperty(this,"_items",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_cursor",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_loadingMore",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_refreshFailed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_error",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_loadedAt",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_generation",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_controllers",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"_staleTimer",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_destroyed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),this._feed=e.feed,this._pageSize=Math.max(1,Math.min(100,Math.round(e.pageSize??20))),this._staleAfter=Math.max(0,e.staleAfterMs??3e5),this._maxItems=Math.max(1,Math.round(e.maxItems??500)),this._now=e.now??Date.now,this._onChange=t=>{this._destroyed||e.onChange?.(t)}}setInstrument(e){if(this._destroyed)return;const t=null===e?null:{symbol:e.symbol,exchange:e.exchange},o=this._instrument;t?.symbol===o?.symbol&&t?.exchange===o?.exchange||(this._cancel(),this._instrument=t,this._items=[],this._cursor=null,this._error=null,this._refreshFailed=!1,this._loadedAt=null,this._status="idle",null!==t?this.refresh():this._emit())}async refresh(){if(this._destroyed||null===this._instrument)return;this._cancel(),this._status="loading",this._emit();const e=await this._request();void 0!==e&&(e instanceof Error?(this._error=e.message,this._items.length>0?(this._status="ready",this._refreshFailed=!0):this._status="error"):(this._items=[],this._cursor=this._take(e.items)>0?this._nextCursor(e,void 0):null,this._status=this._items.length>0?"ready":"empty",this._error=null,this._refreshFailed=!1,this._loadedAt=this._now(),this._scheduleStale()),this._emit())}async loadMore(){if(this._destroyed||"ready"!==this._status||null===this._cursor||this._loadingMore)return;const e=this._cursor;this._loadingMore=!0,this._emit();const t=await this._request(e);void 0!==t&&(this._loadingMore=!1,t instanceof Error?this._error=t.message:(this._cursor=this._take(t.items)>0?this._nextCursor(t,e):null,this._error=null),this._emit())}snapshot(){const e=null===this._loadedAt?0:this._now()-this._loadedAt;return{instrument:null===this._instrument?null:{...this._instrument},status:this._status,items:this._items.slice(),hasMore:null!==this._cursor,loadingMore:this._loadingMore,stale:this._refreshFailed||null!==this._loadedAt&&e>this._staleAfter,refreshFailed:this._refreshFailed,error:this._error,loadedAt:this._loadedAt}}destroy(){this._destroyed||(this._cancel(),this._destroyed=!0)}async _request(e){const t=this._instrument,o=this._generation,n=new AbortController;this._controllers.add(n);try{const a=await this._feed.getNews({symbol:t.symbol,exchange:t.exchange,limit:this._pageSize,...void 0===e?{}:{cursor:e},signal:n.signal});if(o!==this._generation||this._destroyed)return;return null!==a&&"object"==typeof a&&Array.isArray(a.items)?a:new Error("The news source returned no page")}catch(e){return o!==this._generation||this._destroyed?void 0:new Error((e=>F({},e))(e))}finally{this._controllers.delete(n)}}_take(e){const t=new Set(this._items.map(e=>e.id));let o=0;for(const n of e){const e=Gi(n);null===e||t.has(e.id)||(t.add(e.id),this._items.push(e),o++)}return this._items.sort((e,t)=>t.time-e.time),this._items.length>=this._maxItems?(this._items.length=this._maxItems,0):o}_nextCursor(e,t){const o=e.nextCursor;return"string"==typeof o&&""!==o&&o!==t?o:null}_cancel(){this._generation++;for(const e of this._controllers)e.abort();this._controllers.clear(),this._loadingMore=!1,null!==this._staleTimer&&(clearTimeout(this._staleTimer),this._staleTimer=null)}_scheduleStale(){null!==this._staleTimer&&clearTimeout(this._staleTimer),this._staleTimer=setTimeout(()=>{this._staleTimer=null,this._emit()},this._staleAfter+1)}_emit(){this._onChange(this.snapshot())}}function Hi(e){if("string"!=typeof e)return null;const t=e.trim();if(!/^https?:\/\//i.test(t))return null;try{const e=new URL(t);return"http:"!==e.protocol&&"https:"!==e.protocol||""!==e.username||""!==e.password?null:e.href}catch{return null}}function Ji(e,o,n){const a=e.document,i=(t,o,n={})=>R(e,`schema.ui.news.${t}`,n,o),r=nt(a,"div","oac-news");r.setAttribute("aria-label",i("title","News"));const s=nt(a,"div","oac-news__bar"),l=nt(a,"div","oac-news__heading"),c=nt(a,"span","oac-news__instrument"),d=nt(a,"span","oac-news__exchange");l.append(c,d);const u=it(a,{label:i("refresh","Refresh"),onClick:()=>{I.refresh()}});u.setAttribute("aria-label",i("refreshNews","Refresh news")),s.append(l,u);const p=nt(a,"div","oac-news__status");p.setAttribute("role","status"),p.setAttribute("aria-live","polite");const h=nt(a,"ul","oac-news__list");h.setAttribute("aria-label",i("headlines","Headlines"));const m=nt(a,"div","oac-news__more"),g=nt(a,"p","oac-news__more-error"),f=it(a,{label:"",onClick:()=>{I.loadMore()}}),b=nt(a,"span","oac-news__end");m.append(g,f,b);const v=nt(a,"article","oac-news__detail");v.hidden=!0;const w=it(a,{label:i("back","Back to news"),onClick:()=>j()}),y=nt(a,"h3","oac-news__detail-headline"),_=nt(a,"p","oac-news__detail-meta"),x=nt(a,"p","oac-news__detail-summary"),k=nt(a,"div","oac-news__detail-link");v.append(w,y,_,x,k),r.append(s,p,h,m,v),o.appendChild(r);let C=!1,S=null,A=null;const T=new Map,E=()=>{try{return e.chart.timezone()}catch{return t.DEFAULT_TIMEZONE}},L=t=>{try{return new Intl.DateTimeFormat(e.locale,{timeZone:E(),...t})}catch{return new Intl.DateTimeFormat("en-US",{timeZone:"UTC",...t})}};let O=null;const I=new Vi({feed:n.feed,pageSize:n.pageSize,staleAfterMs:n.staleAfterMs,maxItems:n.maxItems,onChange:e=>{S=e,$()}}),P=(e,t)=>{t.textContent="",void 0!==e.source&&t.appendChild(nt(a,"span","oac-news__source",e.source));const o=nt(a,"time","oac-news__time",(n=e.time,O?.zone!==E()&&(O={zone:E(),format:L({dateStyle:"medium",timeStyle:"short"})}),O.format.format(new Date(1e3*n))));var n;o.setAttribute("datetime",(e=>{try{return new Date(1e3*e).toISOString()}catch{return""}})(e.time)),t.appendChild(o)};function $(){if(C||null===S)return;const e=S;c.textContent=e.instrument?.symbol??"",d.textContent=e.instrument?.exchange??"",u.disabled=null===e.instrument||"loading"===e.status;const t=function(e){const t=e.instrument?.symbol??"";if(null===e.instrument)return{text:i("status.none","Choose a symbol to see its news"),kind:"idle"};if("loading"===e.status)return e.items.length>0?{text:i("status.refreshing","Refreshing news for {symbol}",{symbol:t}),kind:"loading"}:{text:i("status.loading","Loading news for {symbol}",{symbol:t}),kind:"loading"};if("empty"===e.status)return{text:i("status.empty","No news for {symbol}",{symbol:t}),kind:"empty"};if("error"===e.status)return{text:i("status.error","News could not load: {error}",{error:e.error??""}),kind:"error"};if(e.refreshFailed)return{text:i("status.staleFailed","Showing earlier news. Refresh failed: {error}",{error:e.error??""}),kind:"stale"};const o=null===e.loadedAt?"":L({timeStyle:"short"}).format(new Date(e.loadedAt));return e.stale?{text:i("status.stale","Updated {time}. Refresh for newer news.",{time:o}),kind:"stale"}:{text:i("status.ready","Updated {time}",{time:o}),kind:"ready"}}(e);p.textContent=t.text,p.dataset.state=t.kind;const o=new Set(e.items.map(e=>e.id));for(const[e,t]of T)o.has(e)||(t.li.remove(),T.delete(e));e.items.forEach((e,t)=>{let o=T.get(e.id);if(!o){const t=nt(a,"li","oac-news__item"),n=nt(a,"button","oac-news__open");n.type="button",n.dataset.id=e.id,n.addEventListener("click",()=>function(e){const t=T.get(e);if(!t)return;A=e;const o=t.item;y.textContent=o.headline,P(o,_),x.textContent=o.summary??"",x.hidden=void 0===o.summary,k.textContent="";const n=Hi(o.url);if(null!==n){const e=nt(a,"a","oac-btn oac-btn--primary oac-news__article",i("openArticle","Open article"));e.setAttribute("href",n),e.setAttribute("target","_blank"),e.setAttribute("rel","noopener noreferrer"),e.setAttribute("referrerpolicy","no-referrer"),k.appendChild(e)}else k.appendChild(nt(a,"p","oac-news__no-link",i("noLink","No article link")));v.hidden=!1,h.hidden=m.hidden=!0,w.focus()}(e.id)),t.appendChild(n),o={li:t,open:n,item:e},T.set(e.id,o)}o.item=e,o.open.textContent="";const n=nt(a,"span","oac-news__meta");P(e,n),o.open.append(nt(a,"span","oac-news__headline",e.headline),n),h.children[t]!==o.li&&h.insertBefore(o.li,h.children[t]??null)});const n=e.hasMore&&null!==e.error&&!e.loadingMore&&"ready"===e.status&&!e.refreshFailed;g.hidden=!n,g.textContent=n?i("moreFailed","Older news could not load: {error}",{error:e.error??""}):"",f.hidden=!e.hasMore,f.textContent=e.loadingMore?i("loadingMore","Loading older news"):i("loadMore","Load older news"),f.disabled=e.loadingMore||"ready"!==e.status;const r=!e.hasMore&&e.items.length>0&&"ready"===e.status;b.hidden=!r,b.textContent=r?i("end","No older news"):"",null===A||T.has(A)||j(!1),h.hidden=m.hidden=null!==A}function j(e=!0){const t=A;A=null,v.hidden=!0,h.hidden=m.hidden=!1,e&&null!==t&&T.get(t)?.open.focus()}const D=()=>{const t=(()=>{const t=e.symbol();return""===t.symbol?null:{symbol:t.symbol,exchange:t.exchange}})(),o=S?.instrument??null;t?.symbol===o?.symbol&&t?.exchange===o?.exchange&&null!==S||(null!==A&&j(!1),I.setInstrument(t))},M=e=>{e.stopPropagation()};r.addEventListener("pointerdown",M);const z=[e.chart.on("data:context",D),e.chart.on("timezone:changed",()=>{$();const e=null===A?void 0:T.get(A);e&&P(e.item,_)})];return S=I.snapshot(),D(),$(),{el:r,initialFocus:u,refresh:()=>I.refresh(),destroy:()=>{if(!C){C=!0,I.destroy();for(const e of z)e();r.removeEventListener("pointerdown",M),T.clear(),r.remove()}}}}const Zi='\n.oac-widget .oac-news { display: flex; flex-direction: column; gap: 6px; padding: 8px 10px 10px; font-size: 12px; min-height: 0; }\n.oac-widget .oac-news__bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }\n.oac-widget .oac-news__heading { display: flex; align-items: baseline; gap: 5px; min-width: 0; }\n.oac-widget .oac-news__instrument { font-weight: 600; color: var(--oac-tx); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.oac-widget .oac-news__exchange { font-size: 10px; color: var(--oac-mut); }\n.oac-widget .oac-news .oac-btn { height: 26px; padding: 0 8px; font-size: 11px; }\n.oac-widget .oac-news__status { font-size: 11px; color: var(--oac-mut); overflow-wrap: anywhere; }\n.oac-widget .oac-news__status[data-state="error"], .oac-widget .oac-news__more-error { color: var(--oac-danger); }\n.oac-widget .oac-news__status[data-state="stale"] { color: var(--oac-warn, var(--oac-mut)); }\n.oac-widget .oac-news__list { list-style: none; margin: 0; padding: 0; }\n.oac-widget .oac-news__list[hidden], .oac-widget .oac-news__more[hidden], .oac-widget .oac-news__detail[hidden], .oac-widget .oac-news__more > [hidden] { display: none; }\n.oac-widget .oac-news__item { border-bottom: 1px solid var(--oac-bd-soft); }\n.oac-widget .oac-news__open { display: flex; flex-direction: column; gap: 3px; width: 100%; padding: 7px 2px; border: 0; background: none; color: var(--oac-tx); font: inherit; text-align: left; cursor: pointer; }\n.oac-widget .oac-news__open:hover, .oac-widget .oac-news__open:focus-visible { background: var(--oac-elev); }\n.oac-widget .oac-news__headline { font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }\n.oac-widget .oac-news__meta, .oac-widget .oac-news__detail-meta { display: flex; flex-wrap: wrap; gap: 8px; font-size: 11px; color: var(--oac-mut); }\n.oac-widget .oac-news__source { overflow-wrap: anywhere; }\n.oac-widget .oac-news__more { display: flex; flex-direction: column; align-items: stretch; gap: 4px; padding-top: 4px; font-size: 11px; color: var(--oac-mut); text-align: center; }\n.oac-widget .oac-news__more-error { margin: 0; text-align: left; overflow-wrap: anywhere; }\n.oac-widget .oac-news__detail { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }\n.oac-widget .oac-news__detail-headline { margin: 0; font: 600 14px/1.35 var(--oac-font); color: var(--oac-tx); overflow-wrap: anywhere; }\n.oac-widget .oac-news__detail-meta { margin: 0; }\n.oac-widget .oac-news__detail-summary { margin: 0; white-space: pre-line; line-height: 1.5; color: var(--oac-tx); overflow-wrap: anywhere; }\n.oac-widget .oac-news__article { display: inline-flex; align-items: center; text-decoration: none; }\n.oac-widget .oac-news__no-link { margin: 0; font-size: 11px; color: var(--oac-mut); }\n.oac-widget .oac-panel-dock[data-sheet="true"] .oac-news__open { padding: 10px 2px; }\n';function Yi(e){return Array.isArray(e)?e.map(Yi):function(e){if(null===e||"object"!=typeof e)return!1;const t=Object.getPrototypeOf(e);return t===Object.prototype||null===t}(e)?Object.fromEntries(Object.entries(e).map(([e,t])=>[e,Yi(t)])):e}function Qi(e){return{...e,..."object"==typeof e.details?{details:Yi(e.details)}:{}}}const Xi='\n.oac-event-layer{position:absolute;inset:0;pointer-events:none;z-index:50}\n.oac-event-details{position:absolute;pointer-events:auto;box-sizing:border-box;width:340px;max-width:calc(100% - 16px);max-height:calc(100% - 16px);overflow:auto;background:var(--oac-panel,#171b23);color:var(--oac-tx,#d9dfe8);border:1px solid var(--oac-bd,#343b48);border-radius:8px;box-shadow:var(--oac-shadow,0 12px 32px #0005);font:12px/1.5 var(--oac-font,system-ui,sans-serif);scrollbar-width:thin;scrollbar-color:var(--oac-sb-thumb,#414958) var(--oac-panel,#171b23)}\n.oac-event-details::-webkit-scrollbar{width:6px;height:6px}\n.oac-event-details::-webkit-scrollbar-track{background:var(--oac-panel,#171b23)}\n.oac-event-details::-webkit-scrollbar-thumb{background:var(--oac-sb-thumb,#414958);border-radius:3px}\n.oac-event-details::-webkit-scrollbar-thumb:hover{background:var(--oac-sb-thumb-hover,#586276)}\n.oac-event-details__header{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:10px 12px;border-bottom:1px solid var(--oac-bd,#343b48)}\n.oac-event-details__heading{margin:0;font:600 12px/1.5 var(--oac-font,system-ui,sans-serif)}\n.oac-event-details button{font:inherit;cursor:pointer;border:1px solid var(--oac-bd,#343b48);border-radius:4px;padding:4px 8px;background:var(--oac-elev,#252c37);color:inherit;text-align:left}\n.oac-event-details button:hover{background:var(--oac-elev-2,#333d4b)}\n.oac-event-details button:focus-visible{outline:2px solid var(--oac-ring,#74a7fa);outline-offset:2px}\n.oac-event-details__members{display:flex;flex-wrap:wrap;gap:6px;padding:10px 12px 0}\n.oac-event-details__members button{max-width:100%;overflow-wrap:anywhere}\n.oac-event-details__members button[aria-pressed="true"]{border-color:var(--oac-acc,#74a7fa);background:var(--oac-on-bg,#274263)}\n.oac-event-details__content{padding:12px;overflow-wrap:anywhere}\n.oac-event-details__title{margin:0 0 4px;font-size:14px;font-weight:600}\n.oac-event-details__time,.oac-event-details__status{color:var(--oac-mut,#a0aabc)}\n.oac-event-details__summary{white-space:pre-wrap;margin:10px 0 0}\n.oac-event-details__fields{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:5px 12px;margin:10px 0 0}\n.oac-event-details__fields dt{color:var(--oac-mut,#a0aabc)}\n.oac-event-details__fields dd{margin:0;text-align:right;white-space:pre-wrap}\n.oac-event-details__status{padding:0 12px 10px}\n.oac-event-details__status:empty{display:none}\n.oac-event-details__subhead{margin:10px 0 0;font-size:12px;font-weight:600}\n.oac-event-details__text,.oac-event-details__list{margin:6px 0 0}\n.oac-event-details__list{padding-left:18px}\n.oac-event-details a{color:var(--oac-acc,#74a7fa)}\n.oac-event-details__actions{display:flex;flex-wrap:wrap;justify-content:flex-end;gap:6px;padding:0 12px 12px}\n.oac-event-details__actions:empty{display:none}\n';function er(e){return{title:R(e,"Event details"),close:R(e,"Close"),events:R(e,"Events"),loading:R(e,"Loading details..."),empty:R(e,"No additional details."),error:R(e,"Unable to load additional details.")}}class tr{constructor(e,o={}){Object.defineProperty(this,"_container",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"_options",{enumerable:!0,configurable:!0,writable:!0,value:o}),Object.defineProperty(this,"element",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_doc",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_overlays",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_ownOverlays",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_labels",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_formatTime",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_close",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_abort",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_revision",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_disposed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_events",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_members",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_content",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_status",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_actions",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_anchor",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._doc=e.ownerDocument,this._labels={...er({}),...o.labels};const n=new Intl.DateTimeFormat(void 0,{timeZone:t.DEFAULT_TIMEZONE,dateStyle:"medium",timeStyle:"short"});if(this._formatTime=o.formatTime??(e=>{const t=new Date(1e3*e);return Number.isFinite(t.getTime())?n.format(t):String(e)}),this._ownOverlays=void 0===o.overlays,this._overlays=o.overlays??S(e,this._doc),this._ownOverlays&&this._overlays.layer.classList.add("oac-event-layer"),!1!==o.injectStyles&&null===this._doc.getElementById("oac-event-details-style")){const e=u(this._doc,"style",void 0,{id:"oac-event-details-style"});void 0!==o.styleNonce&&e.setAttribute("nonce",o.styleNonce),e.textContent=Xi,this._doc.head.appendChild(e)}this.element=u(this._doc,"section","oac-event-details",{role:"dialog","aria-label":this._labels.title});for(const e of["pointerdown","pointerup","click","dblclick","wheel","keydown"])this.element.addEventListener(e,e=>e.stopPropagation());this._content=u(this._doc,"div","oac-event-details__content"),this._status=u(this._doc,"div","oac-event-details__status",{role:"status","aria-live":"polite"}),this._actions=u(this._doc,"div","oac-event-details__actions")}open(e,t){if(this._disposed)return;if(this.close(),0===e.events.length)return;this._events=e.events.map(Qi),this._anchor=void 0===t?void 0:{...t};const o=u(this._doc,"header","oac-event-details__header"),n=u(this._doc,"h2","oac-event-details__heading");n.textContent=this._labels.title;const a=u(this._doc,"button",void 0,{type:"button","data-action":"close-event-details"});if(a.textContent=this._labels.close,a.addEventListener("click",()=>this.close()),o.append(n,a),this.element.replaceChildren(o),this._members=[],this._events.length>1){const e=u(this._doc,"div","oac-event-details__members",{role:"group","aria-label":this._labels.events});this._members=this._events.map((t,o)=>{const n=u(this._doc,"button",void 0,{type:"button","data-event-index":String(o)});return n.textContent=t.title??t.label,n.addEventListener("click",()=>this._select(o)),e.appendChild(n),n}),this.element.appendChild(e)}this.element.append(this._content,this._status,this._actions),this._close=this._overlays.open(this.element,{placement:"below",modal:!1,initialFocus:a,onClose:()=>{this._close=null,this._cancel()}}),this._select(0),this._position()}close(){this._cancel(),this._close?.(),this._close=null}destroy(){this._disposed||(this._disposed=!0,this.close(),this._events=[],this._members=[],this._ownOverlays&&this._overlays.destroy())}_cancel(){this._revision++,this._abort?.abort(),this._abort=null}_select(e){this._cancel();const t=this._events[e];this._members.forEach((t,o)=>t.setAttribute("aria-pressed",String(o===e))),this._render(t,t.details),this._actions.replaceChildren(...(this._options.actions?.(Qi(t))??[]).map(e=>{const o=u(this._doc,"button",void 0,{type:"button"});return o.textContent=e.label,o.addEventListener("click",()=>{const o=Qi(t);this.close(),e.run(o)}),o})),this._status.textContent="",this.element.removeAttribute("aria-busy");const o=this._options.loadDetails;if(void 0===o)return;const n=this._revision,a=new AbortController;this._abort=a,this._status.textContent=this._labels.loading,this.element.setAttribute("aria-busy","true");const i=()=>!this._disposed&&null!==this._close&&n===this._revision&&!a.signal.aborted,r=()=>{i()&&(this.element.removeAttribute("aria-busy"),this._status.textContent=this._labels.error,this._position())};try{Promise.resolve(o(Qi(t),{signal:a.signal})).then(e=>{i()&&(this._status.textContent="",this.element.removeAttribute("aria-busy"),this._render(t,e??t.details))},r)}catch{r()}}_render(e,t){const o=u(this._doc,"h3","oac-event-details__title");o.textContent=e.title??e.label;const n=u(this._doc,"div","oac-event-details__time");n.textContent=this._formatTime(e.time),this._content.replaceChildren(o,n);const a="string"==typeof t?t:t?.summary;if(a){const e=u(this._doc,"p","oac-event-details__summary");e.textContent=a,this._content.appendChild(e)}const i="object"==typeof t?t.fields:void 0;if(i?.length){const e=u(this._doc,"dl","oac-event-details__fields");for(const t of i){const o=u(this._doc,"dt"),n=u(this._doc,"dd");o.textContent=t.label,n.textContent=t.value,e.append(o,n)}this._content.appendChild(e)}let r=!1;const s="object"==typeof t&&Array.isArray(t.blocks)?t.blocks:[];for(const e of s){const{type:t,text:o,items:n}=e??{},a="heading"===t?u(this._doc,"h4","oac-event-details__subhead"):"paragraph"===t?u(this._doc,"p","oac-event-details__text"):"list"===t?u(this._doc,"ul","oac-event-details__list"):null;if(null!==a){if("list"!==t)this._inline(a,o);else if(Array.isArray(n))for(const e of n)this._inline(a.appendChild(u(this._doc,"li")),e);a.textContent&&(this._content.appendChild(a),r=!0)}}if(!a&&!i?.length&&!r){const e=u(this._doc,"p","oac-event-details__summary");e.textContent=this._labels.empty,this._content.appendChild(e)}this._position()}_inline(e,t){if("string"!=typeof t){if(Array.isArray(t))for(const o of t){if("string"!=typeof o?.text)continue;const t=Hi(o.href);let n=null===t?u(this._doc,"span"):u(this._doc,"a",void 0,{href:t,target:"_blank",rel:"noopener noreferrer",referrerpolicy:"no-referrer"});n.textContent=o.text;for(const e of["em","strong"]){if(!0!==o[e])continue;const t=u(this._doc,e);t.appendChild(n),n=t}e.appendChild(n)}}else e.append(t)}_position(){const e=this._container.getBoundingClientRect(),t=this._overlays.layer.getBoundingClientRect(),o=this._ownOverlays?0:e.left-t.left,n=this._ownOverlays?0:e.top-t.top;this.element.style.maxWidth=`${Math.max(0,e.width-16)}px`,this.element.style.maxHeight=`${Math.max(0,e.height-16)}px`;const a=this.element.offsetWidth,i=this.element.offsetHeight,r=this._anchor?.x,s=this._anchor?.y;this.element.style.left=`${o+Math.max(0,Math.min(Number.isFinite(r)?r:e.width-a-8,e.width-a-8))}px`,this.element.style.top=`${n+Math.max(0,Math.min(Number.isFinite(s)?s-i-12:8,e.height-i-8))}px`}}function or(e,o,n,a,i){const r=(e,t)=>R(a,`schema.ui.data.${e}`,{},t),s=r("unavailable","Unavailable");let l=o.length-1;if(void 0!==n){let e=0,t=o.length;for(;e<t;){const a=e+t>>>1;o[a].time<n?e=a+1:t=a}l=o[e]?.time===n?e:-1}const c=o[l],d=void 0===n?c?.time??null:Number.isFinite(n)?n:null;let u;try{u=new Intl.NumberFormat(a.locale,{maximumFractionDigits:8})}catch{u=new Intl.NumberFormat("en-US",{maximumFractionDigits:8})}const p=(t,o,n=!1)=>{try{if("custom"===o?.type)return String(o.formatter(t));if("percent"===o?.type)return`${t.toFixed(o.precision??2)}%`;if("price"===o?.type)return t.toFixed(o.precision??2);if(n)return e.primarySeries()?.priceScale().format(t)??t.toFixed(2)}catch{}return u.format(t)},h=(e,t,o,n=!1,a)=>{const i="number"==typeof o&&Number.isFinite(o)?o:null;return{key:e,label:t,raw:i,value:null===i?s:p(i,a,n)}},m=["open","high","low","close"].map(e=>h(e,r(e,e[0].toUpperCase()+e.slice(1)),c?.[e],!0));m.push(h("volume",r("volume","Volume"),c?.volume));!1!==e.hasOpenInterest&&(!0===e.hasOpenInterest||i)&&m.push(h("oi",r("oi","Open interest"),c?.oi));const g=[{id:"price",title:r("price","Price"),rows:m}];for(const o of e.indicators()){const e=t.getIndicator(o.indicatorId),n=o.values(),a=(e?.plots??[]).map(e=>h(`${o.id}:${e.key}`,e.title,l<0?null:n[e.ohlc?.close??e.key]?.[l-(e.offset??0)],!1,e.priceFormat));a.length>0&&g.push({id:o.id,title:o.name,rows:a})}const f=e.getDataContext();let b=s;if(null!==d)try{b=`${t.formatZonedCrosshairLabel(d,e.timezone())} (${e.timezone()})`}catch{}return{symbol:f?.symbol??"",exchange:f?.exchange??"",time:d,timestamp:b,sections:g}}function nr(e,t){const o=e.document;t.classList.add("oac-data-window"),t.setAttribute("aria-label",R(e,"schema.ui.data.title",{},"Data window"));const n=nt(o,"div","oac-data-window__instrument"),a=nt(o,"div","oac-data-window__time"),i=nt(o,"div","oac-data-window__sections");let r;t.append(n,a,i);let s=!1,l=!1,c=!1,d=!0,u=!1,p=[];const h=new Map,m=(e,t)=>{e.textContent!==t&&(e.textContent=t)},g=()=>{if(l)return;d&&(p=e.chart.primaryBars(),u=p.some(e=>Number.isFinite(e.oi)),d=!1);const t=or(e.chart,p,c?NaN:r,e,u);m(n,[t.exchange,t.symbol].filter(Boolean).join(":")),m(a,t.timestamp);const s=new Set(t.sections.map(e=>e.id));for(const[e,t]of h)s.has(e)||(t.el.remove(),h.delete(e));for(const[e,n]of t.sections.entries()){let t=h.get(n.id);if(!t){const e=nt(o,"section","oac-data-window__section"),a=nt(o,"h3","oac-data-window__title");e.appendChild(a),i.appendChild(e),t={el:e,title:a,rows:new Map},h.set(n.id,t)}i.children[e]!==t.el&&i.insertBefore(t.el,i.children[e]??null),m(t.title,n.title);const a=new Set(n.rows.map(e=>e.key));for(const[e,o]of t.rows)a.has(e)||(o.el.remove(),t.rows.delete(e));for(const e of n.rows){let n=t.rows.get(e.key);if(!n){const a=nt(o,"div","oac-data-window__row");a.dataset.key=e.key;const i=nt(o,"span","oac-data-window__label"),r=nt(o,"span","oac-data-window__value");a.append(i,r),t.el.appendChild(a),n={el:a,label:i,value:r},t.rows.set(e.key,n)}m(n.label,e.label),m(n.value,e.value),n.value.classList.toggle("is-unavailable",null===e.raw)}}},f=()=>{s||l||(s=!0,Promise.resolve().then(()=>{s=!1,g()}))},b=[e.chart.on("crosshair:readout",e=>{const t=e;r=null===t.index&&null===t.point?void 0:t.time??NaN,f()}),e.chart.on("data:context",()=>{r=void 0,c=!0,d=!0,f()}),e.chart.on("data:range",()=>{c=!1,d=!0,f()}),...["objects:change","indicatorSettings","indicatorRemoved","indicator:data-status","paneMoved","resize","timezone:changed"].map(t=>e.chart.on(t,f))],v=()=>{if(!l){l=!0;for(const e of b)e();h.clear(),t.textContent="",t.classList.remove("oac-data-window"),t.removeAttribute("aria-label")}};return b.push(e.chart.on("destroy",v)),g(),{el:t,refresh:f,destroy:v}}const ar="\n.oac-widget .oac-data-window { padding: 12px; font-size: 12px; user-select: text; -webkit-user-select: text; }\n.oac-widget .oac-data-window__instrument { font-weight: 600; color: var(--oac-tx); overflow-wrap: anywhere; }\n.oac-widget .oac-data-window__time { font-size: 11px; color: var(--oac-mut); margin: 4px 0 14px; line-height: 1.5; }\n.oac-widget .oac-data-window__section + .oac-data-window__section { margin-top: 16px; }\n.oac-widget .oac-data-window__title { margin: 0 0 6px; padding: 0; font: 600 11px/1.4 var(--oac-font); color: var(--oac-mut); text-transform: uppercase; letter-spacing: .04em; }\n.oac-widget .oac-data-window__row { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; min-height: 26px; padding: 4px 0; }\n.oac-widget .oac-data-window__label { min-width: 0; overflow-wrap: anywhere; }\n.oac-widget .oac-data-window__value { font-variant-numeric: tabular-nums; text-align: right; overflow-wrap: anywhere; }\n.oac-widget .oac-data-window__value.is-unavailable { font-size: 11px; color: var(--oac-mut); }\n";function ir(e,o){const n=e.document;let a=!1,i=null,r=null,s=null,l=null;const c=()=>{const e=i;i=null,l?.destroy(),l=null,r=null,s=null,e?.()},d=d=>{if(a||d.defaultPrevented||d.isComposing||d.ctrlKey||d.metaKey||d.altKey||d.repeat)return;if(!/^[a-zA-Z0-9]$/.test(d.key))return;const p=d.target,h=n.activeElement;if(null===p||!e.root.contains(p)||null===h||!e.root.contains(h)||function(e){for(let t=e;null!==t;t=t.parentElement)if(t.isContentEditable||["INPUT","TEXTAREA","SELECT"].includes(t.tagName))return!0;return!1}(p))return;if(e.overlays.size()>0||null!==e.draw.activeTool()||!o.enabled())return;const m=ke(d);e.keymap.list().some(t=>t.combo===m&&e.keymap.activeScopes().includes(t.scope))||e.chart.shortcuts?.list().some(e=>!e.isDisabled&&e.combos.some(e=>Te(e)===m))||(d.preventDefault(),d.stopPropagation(),((a,d)=>{c(),r=u(n,"section","oac-quick-entry",{role:"dialog","aria-label":R(e,"symbol"===a?"schema.ui.enterSymbol":"schema.ui.enterInterval",{},"symbol"===a?"Enter symbol":"Enter interval")}),s=u(n,"input","oac-quick-entry__input",{type:"text",autocomplete:"off",spellcheck:"false","aria-label":R(e,"symbol"===a?"schema.ui.symbol":"schema.ui.interval",{},"symbol"===a?"Symbol":"Interval")}),s.value=d;const p=u(n,"div","oac-quick-entry__message",{role:"alert"});r.append(s,p);const h=s;h.addEventListener("input",()=>{p.textContent=""});const m=r;i=e.openOverlay(r,{placement:"center",initialFocus:h,onClose:()=>{r===m&&c()}}),"symbol"===a&&o.search&&(l=Ht(e,h,{search:o.search,onSelect:(e,t)=>{c(),o.onSymbol(e,t)},context:()=>`${e.symbol().exchange}:${e.symbol().symbol}:${e.interval()}`}),l.open(d)),h.addEventListener("keydown",n=>{if("Enter"!==n.key||n.isComposing)return;n.preventDefault(),n.stopPropagation();const i=h.value.trim();if("symbol"===a){if(null!==l&&!l.canCommitRaw())return;if(""===i)return void(p.textContent=R(e,"schema.ui.symbolRequired",{},"Enter a symbol"));c(),o.onSymbol(i.toUpperCase())}else{const n=t.tryResolveInterval(i)??(/^[0-9]+$/.test(i)?t.tryResolveInterval(`${i}m`):null);if(null===n)return void(p.textContent=R(e,"schema.ui.invalidInterval",{},"Enter a recognized interval"));c(),o.onInterval(n.code)}})})(/[0-9]/.test(d.key)?"interval":"symbol",d.key))};n.addEventListener("keydown",d,!0);const p=e.bus.on("symbol",c),h=e.bus.on("interval",c);return{close:c,destroy:()=>{a||(a=!0,c(),p(),h(),n.removeEventListener("keydown",d,!0))}}}const rr="\n.oac-widget .oac-quick-entry{width:min(330px,calc(100vw - 32px));padding:12px}\n.oac-widget .oac-quick-entry__input{width:100%;box-sizing:border-box;background:var(--oac-panel);color:var(--oac-tx);border:1px solid var(--oac-bd);border-radius:4px;padding:9px;font:inherit}\n.oac-widget .oac-quick-entry__message{min-height:20px;padding-top:5px;color:var(--oac-danger)}\n",sr=(e,t)=>[..."ABCDEFGHIJKLMNOP"].map((o,n)=>`.oac-grid[data-theme="${e}"] [data-group="${o}"] { --oac-group: ${t[n%t.length]}; }`).join("\n"),lr=`\n.oac-grid { position: relative; display: flex; flex-direction: column; width: 100%; height: 100%; min-width: 0; min-height: 0;\n  background: var(--oac-bg); color: var(--oac-tx); font: var(--oac-fs)/1.35 var(--oac-font); }\n.oac-grid [hidden] { display: none !important; }\n.oac-grid__tabs { display: flex; gap: 2px; padding: 4px; overflow-x: auto; flex: none; background: var(--oac-panel);\n  border-bottom: 1px solid var(--oac-bd-soft); scrollbar-width: thin; scrollbar-color: var(--oac-sb-thumb) transparent; }\n.oac-grid__tabs::-webkit-scrollbar { height: 6px; }\n.oac-grid__tabs::-webkit-scrollbar-thumb { background: var(--oac-sb-thumb); border-radius: 999px; }\n.oac-grid__tab { flex: none; height: 26px; padding: 0 10px; border: 1px solid transparent; border-radius: var(--oac-radius);\n  background: transparent; color: var(--oac-mut); font: inherit; cursor: pointer; white-space: nowrap; }\n.oac-grid__tab:hover { color: var(--oac-tx); background: var(--oac-elev); }\n.oac-grid__tab[aria-selected="true"] { color: var(--oac-tx-strong); background: var(--oac-on-bg); border-color: var(--oac-on-bd); }\n.oac-grid__tab:focus-visible, .oac-grid__split:focus-visible { outline: 2px solid var(--oac-ring); outline-offset: -2px; }\n.oac-grid__cells { position: relative; flex: 1; display: grid; min-height: 0; background: var(--oac-bd-soft); }\n.oac-grid__cell { position: relative; min-width: 0; min-height: 0; overflow: hidden; }\n.oac-grid__cell::after { content: ''; position: absolute; inset: 0; border: 1px solid transparent; pointer-events: none; z-index: 30; }\n.oac-grid[data-single="false"][data-compact="false"]:not([data-maximized="true"]) .oac-grid__cell[data-active="true"]::after { border-color: var(--oac-acc); }\n.oac-grid__split { position: relative; z-index: 31; touch-action: none; transition: background .12s; }\n.oac-grid__split::before { content: ''; position: absolute; inset: 0 -3px; }\n.oac-grid__split[data-axis="row"]::before { inset: -3px 0; }\n.oac-grid__split[data-axis="column"] { cursor: col-resize; }\n.oac-grid__split[data-axis="row"] { cursor: row-resize; }\n.oac-grid__split:hover, .oac-grid__split.is-drag { background: var(--oac-acc); }\n.oac-grid:is([data-compact="true"], [data-maximized="true"]) .oac-grid__cells { grid-template: minmax(0,1fr) / minmax(0,1fr) !important; }\n.oac-grid:is([data-compact="true"], [data-maximized="true"]) .oac-grid__cell { grid-area: 1 / 1 / 2 / 2 !important; }\n\n/* Dragging a chart by its bar onto another's place. */\n.oac-grid[data-single="false"][data-compact="false"]:not([data-maximized="true"]) .oac-grid__cell .oac-topbar { cursor: grab; }\n.oac-grid[data-single="false"][data-compact="false"]:not([data-maximized="true"]) .oac-grid__cell .oac-topbar input { cursor: text; }\n.oac-grid[data-dragging="true"], .oac-grid[data-dragging="true"] * { cursor: grabbing !important; user-select: none; }\n.oac-grid__cell[data-dragging="true"] { opacity: .55; }\n.oac-grid__cell[data-drop="true"]::after { border: 2px dashed var(--oac-acc); background: var(--oac-on-bg); }\n\n/* Dense cells: a chart a few hundred pixels across keeps its plot and the\n   controls a chart needs every minute; the rest waits for maximize. */\n/* One row that scrolls sideways rather than a bar wrapped over a third of the plot. */\n.oac-grid__cell[data-dense="true"] :is(.oac-rail, .oac-rail-tab) { display: none; }\n.oac-grid__cell[data-dense="true"] .oac-topbar { gap: 2px; padding: 3px 5px; flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden;\n  scrollbar-width: none; -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 18px), transparent);\n  mask-image: linear-gradient(to right, #000 calc(100% - 18px), transparent); }\n.oac-grid__cell[data-dense="true"] .oac-topbar::-webkit-scrollbar { display: none; }\n.oac-grid__cell[data-dense="true"] .oac-topbar > * { flex-shrink: 0; }\n.oac-grid__cell[data-dense="true"] .oac-sym > input { width: 96px; }\n.oac-grid__cell[data-dense="true"] .oac-sym__ex { display: none; }\n.oac-grid__cell[data-dense="true"] :is(.oac-topbar__goto, .oac-topbar__objects, .oac-topbar__data, .oac-topbar__watchlist,\n  .oac-topbar__news, .oac-topbar__alerts, .oac-topbar__theme, .oac-topbar__branding-slot, .oac-topbar__spacer + .oac-sep) { display: none; }\n/* A label goes where its glyph shows: a host's chart type with none keeps its name. */\n.oac-grid__cell[data-dense="true"] .oac-topbar > .oac-btn > span:not(.oac-glyph):not(.oac-chev):not([hidden] + span) { display: none; }\n\n/* The grid's own chrome takes the widget's controls; these rules only place it. The bar's strip\n   holds its height (a control and its padding) before the bar loads into it (grid-bar.ts). */\n.oac-widget.oac-grid__bar { position: relative; display: flex; align-items: center; gap: 4px; flex: none; height: auto;\n  min-height: calc(var(--oac-ctl-h) + 9px); padding: 4px 6px; background: var(--oac-panel); border-bottom: 1px solid var(--oac-bd-soft);\n  overflow: visible; container: oac-grid-bar / inline-size; }\n/* One bar under the charts: the widget's own strip, acting on the active chart. */\n.oac-widget.oac-grid__foot { display: block; flex: none; height: auto; min-height: 0; }\n.oac-widget.oac-grid__overlay { position: absolute; inset: 0; display: block; background: transparent; pointer-events: none;\n  z-index: 80; overflow: visible; }\n/* A link group mark: the letter on a panel, the group's hue as a stripe. */\n.oac-grid__chip { display: inline-flex; align-items: center; justify-content: center; min-width: 17px; height: 17px;\n  padding: 0 4px 0 6px; border-radius: 4px; background: var(--oac-elev-2); color: var(--oac-tx-strong);\n  box-shadow: inset 3px 0 0 var(--oac-group, var(--oac-faint)); font: 700 10.5px/1 var(--oac-font); flex: none; }\n.oac-grid__chip[data-group="none"] { padding: 0 3px; box-shadow: none; background: transparent; color: var(--oac-faint); }\n.oac-grid__chip[data-group="none"] > svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 2;\n  stroke-linecap: round; stroke-linejoin: round; }\n.oac-grid__mark { display: inline-flex; align-items: center; justify-content: center; height: 24px; min-width: 24px; padding: 0 3px;\n  margin-right: 2px; border: 1px solid transparent; border-radius: 6px; background: transparent; cursor: pointer; flex: none; }\n.oac-grid__mark:hover { background: var(--oac-elev); border-color: var(--oac-bd-soft); }\n.oac-grid__mark:focus-visible { outline: 2px solid var(--oac-ring); outline-offset: -1px; }\n.oac-grid__mark--float { position: absolute; top: 6px; left: 6px; z-index: 32; background: var(--oac-panel); border-color: var(--oac-bd-soft); }\n${sr("dark",["#5b9cf6","#f0a445","#4cc38a","#d673d1","#3fc1c9","#d9c34a","#ef6a6a","#9d85f2"])}\n${sr("light",["#1f63c9","#b8660b","#17864f","#a23c9e","#0e7f86","#8a7300","#c0392b","#6247c4"])}\n@media (prefers-reduced-motion: reduce) {\n  .oac-grid__split { transition: none; }\n}\n`,cr=2147483647,dr=e=>JSON.stringify([e.symbol,e.exchange]),ur=e=>F({},e),pr=e=>"number"==typeof e&&Number.isFinite(e);function hr(e){const t=e.previousClose;if(!pr(t)||t<=0||!pr(e.last))return null;const o=e.last-t;return{change:o,percent:o/t*100}}function mr(e,t){if(null===e||"object"!=typeof e||e.symbol!==t.symbol||(e.exchange??"")!==t.exchange||!pr(e.last))return null;const o={symbol:t.symbol,exchange:t.exchange,last:e.last};for(const t of["previousClose","bid","ask","volume","time"])pr(e[t])&&(o[t]=e[t]);return!0===e.delayed&&(o.delayed=!0),o}class gr{constructor(e){Object.defineProperty(this,"_feed",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_staleAfter",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_pollMs",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_now",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_onChange",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_entries",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"_visible",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"_requests",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"_seq",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_error",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_poll",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_stale",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_resync",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_destroyed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),this._feed=e.feed??null,this._staleAfter=Math.max(0,e.staleAfterMs??6e4),this._pollMs=Math.max(0,e.pollMs??15e3),this._now=e.now??Date.now,this._onChange=()=>{this._destroyed||e.onChange?.()}}setVisible(e){if(this._destroyed)return;const t=new Map;for(const o of e)t.set(dr(o),{symbol:o.symbol,exchange:o.exchange});for(const e of this._visible)t.has(e)||this._hide(e);const o=[],n=this._visible;this._visible=new Set(t.keys());for(const[e,a]of t)n.has(e)||(this._show(e,a),o.push(a));for(const e of this._requests)[...e.ids].some(e=>this._visible.has(e))||(e.controller.abort(),this._requests.delete(e));this._trim(),o.length>0&&this._snapshot(o),this._schedulePoll(),this._scheduleStale(),this._onChange()}row(e){const t={symbol:e.symbol,exchange:e.exchange},o=this._entries.get(dr(t)),n=e=>({instrument:t,quote:o?.quote?{...o.quote}:null,status:e,receivedAt:o?.receivedAt??null});if(null===this._feed)return n("unavailable");if(!o?.quote)return n(o?.error?"error":o?.missing?"unavailable":"loading");const a=!0===o.quote.delayed;if(!o.fresh||!this._visible.has(dr(t)))return n("stale");const i=o.stream?.status;return"live"===i?n(a?"delayed":"live"):"reconnecting"===i||"disconnected"===i||this._now()-(o.receivedAt??0)>this._staleAfter?n("stale"):n(a?"delayed":"snapshot")}status(){if(null===this._feed)return"unavailable";const e=[...this._visible].map(e=>this._entries.get(e)?.stream).filter(e=>!!e&&!e.closed);if(0===e.length)return null!==this._error?"error":this._visible.size>0&&!this._feed.subscribeQuotes?"snapshot":"idle";for(const t of["disconnected","reconnecting","connecting"])if(e.some(e=>e.status===t))return t;return"live"}error(){return this._error}subscribed(){return[...this._visible].map(e=>this._entries.get(e)).filter(e=>!!e?.stream&&!e.stream.closed).map(e=>({...e.key}))}destroy(){if(!this._destroyed){this._destroyed=!0;for(const e of this._entries.values())e.stream?.stop();for(const e of this._requests)e.controller.abort();this._requests.clear(),null!==this._poll&&clearTimeout(this._poll),null!==this._stale&&clearTimeout(this._stale),this._entries.clear(),this._visible.clear()}}_show(e,t){let o=this._entries.get(e);o?(this._entries.delete(e),this._entries.set(e,o)):(o={key:t,quote:null,receivedAt:null,pushed:0,fresh:!1,missing:!1,error:null,stream:null},this._entries.set(e,o)),o.fresh=!1,o.missing=!1,o.error=null;const n=this._feed;if(!n?.subscribeQuotes)return;const a={status:"connecting",closed:!1,stop:()=>{}};o.stream=a;const i=o;try{const e=n.subscribeQuotes([{...t}],{onQuote:e=>{if(a.closed||this._destroyed)return;const o=mr(e,t);null!==o&&("connecting"===a.status&&(a.status="live"),i.pushed=++this._seq,this._accept(i,o),this._scheduleStale(),this._onChange())},onStatus:e=>{if(a.closed||this._destroyed)return;const o=a.status;a.status=e,"live"!==e||"reconnecting"!==o&&"disconnected"!==o||(i.fresh=!1,this._queueResync(t)),this._scheduleStale(),this._onChange()}});a.stop=()=>{a.closed=!0;try{e()}catch{}}}catch(e){a.closed=!0,o.stream=null,o.error=ur(e)}}_hide(e){const t=this._entries.get(e);t&&(t.stream?.stop(),t.stream=null,t.fresh=!1)}_trim(){for(const[e]of this._entries){if(this._entries.size<=1e3)break;this._visible.has(e)||this._entries.delete(e)}}_accept(e,t){e.quote=t,e.receivedAt=this._now(),e.fresh=!0,e.missing=!1,e.error=null}_queueResync(e){null===this._resync?(this._resync=[e],queueMicrotask(()=>{const e=(this._resync??[]).filter(e=>this._visible.has(dr(e)));this._resync=null,e.length>0&&!this._destroyed&&this._snapshot(e)})):this._resync.push(e)}_snapshot(e){const t=this._feed;if(null===t||this._destroyed)return;const o={controller:new AbortController,ids:new Set(e.map(dr)),seq:++this._seq};let n;this._requests.add(o);try{n=Promise.resolve(t.getQuotes({instruments:e.map(e=>({...e})),signal:o.controller.signal}))}catch(e){n=Promise.reject(e)}n.then(e=>{if(!this._requests.delete(o)||this._destroyed)return;const t=new Set;for(const n of Array.isArray(e)?e:[]){const e=n&&"object"==typeof n?dr({symbol:n.symbol,exchange:n.exchange??""}):"",a=this._entries.get(e);if(!a||!o.ids.has(e)||!this._visible.has(e))continue;const i=mr(n,a.key);null!==i&&(t.add(e),a.pushed>o.seq||this._accept(a,i))}for(const e of o.ids){const o=this._entries.get(e);o&&!t.has(e)&&this._visible.has(e)&&!o.quote&&(o.missing=!0)}this._error=null,this._scheduleStale(),this._onChange()},e=>{if(this._requests.delete(o)&&!this._destroyed){this._error=ur(e);for(const e of o.ids){const t=this._entries.get(e);t&&!t.quote&&this._visible.has(e)&&(t.error=this._error)}this._onChange()}})}_schedulePoll(){null!==this._poll&&(clearTimeout(this._poll),this._poll=null),this._destroyed||null===this._feed||this._feed.subscribeQuotes||0===this._pollMs||0===this._visible.size||(this._poll=setTimeout(()=>{this._poll=null,this._snapshot([...this._visible].map(e=>this._entries.get(e).key)),this._schedulePoll()},Math.min(this._pollMs,cr)))}_expires(e){const t=this._entries.get(e);if(!t?.fresh||null===t.quote||null===t.receivedAt)return null;const o=t.stream?.status;return"live"===o||"reconnecting"===o||"disconnected"===o?null:t.receivedAt+this._staleAfter}_scheduleStale(){if(null!==this._stale&&(clearTimeout(this._stale),this._stale=null),this._destroyed)return;const e=this._now();let t=1/0;for(const o of this._visible){const n=this._expires(o);null!==n&&n>=e&&(t=Math.min(t,n))}t!==1/0&&(this._stale=setTimeout(()=>{this._stale=null,this._now()>t&&this._onChange(),this._scheduleStale()},Math.min(t-e+1,cr)))}}const fr=[["symbol","Symbol"],["last","Last"],["change","Chg"],["percent","Chg%"]],br="watchlist-sort",vr=e=>JSON.stringify([e.symbol,e.exchange]),wr=(e,t)=>e.symbol===t.symbol&&e.exchange===t.exchange,yr=new WeakMap;function _r(e,t,o){const n=e.document,a=o.store,i=(t,o,n={})=>R(e,`schema.ui.watchlist.${t}`,n,o),r=e=>""===e.exchange?e.symbol:i("entry","{symbol} on {exchange}",{symbol:e.symbol,exchange:e.exchange}),s=nt(n,"div","oac-watchlist");s.setAttribute("aria-label",i("title","Watchlist"));const l=nt(n,"div","oac-watchlist__bar"),{wrap:c,select:d}=rt(n);d.setAttribute("aria-label",i("list","Watchlist"));const u=(e,t,o)=>{const a=it(n,{label:e,onClick:o});return a.setAttribute("aria-label",t),a},p=u(i("new","New"),i("newList","New list"),()=>Ae("create")),h=u(i("rename","Rename"),i("renameList","Rename list"),()=>Ae("rename")),m=u(i("delete","Delete"),i("deleteList","Delete list"),()=>function(){const e=ne();if(null===e)return;Se(),y.textContent=i("confirmDelete","Delete {name} and its {count} symbols?",{name:e.name,count:e.entries.length}),x.textContent=i("deleteNamed","Delete {name}",{name:e.name}),w.hidden=!1,_.focus()}());l.append(c,p,h,m);const g=nt(n,"form","oac-watchlist__name");g.hidden=!0;const f=nt(n,"input");f.type="text",f.maxLength=120,f.setAttribute("aria-label",i("name","List name")),f.autocomplete="off";const b=it(n,{label:i("save","Save"),variant:"primary",onClick:()=>{Te()}}),v=it(n,{label:i("cancel","Cancel"),onClick:()=>Se()});g.append(f,v,b);const w=nt(n,"div","oac-watchlist__confirm");w.hidden=!0;const y=nt(n,"span","oac-watchlist__confirm-text"),_=it(n,{label:i("keep","Keep list"),onClick:()=>Se()}),x=it(n,{label:"",variant:"danger",onClick:()=>{!async function(){const e=ne();if(Se(),null===e)return;pe("");try{await a.removeList(e.id)}catch(e){he(e)}}()}});w.append(y,_,x);const k=nt(n,"div","oac-watchlist__add"),C=nt(n,"input");C.type="search",C.placeholder=i("addPlaceholder","Add symbol"),C.setAttribute("aria-label",i("addSymbol","Add symbol")),C.autocomplete="off";const S=it(n,{label:"",onClick:()=>{const t=e.symbol();""!==t.symbol&&Ce({...t})}});S.classList.add("oac-watchlist__add-current"),k.append(C,S);const A=nt(n,"div","oac-watchlist__status");A.setAttribute("role","status"),A.setAttribute("aria-live","polite");const T=nt(n,"div","oac-watchlist__message");T.setAttribute("role","alert"),T.hidden=!0;const E=nt(n,"p","oac-watchlist__empty");E.hidden=!0;const L=nt(n,"div","oac-watchlist__scroll"),O=nt(n,"table","oac-watchlist__table"),I=nt(n,"caption","oac-sr"),P=nt(n,"thead"),$=nt(n,"tr"),j=new Map;for(const[e,t]of fr){const o=nt(n,"th",`oac-watchlist__col oac-watchlist__col--${e}`);o.setAttribute("scope","col"),o.dataset.sort=e;const a=nt(n,"button","oac-watchlist__sort",i(`column.${e}`,t));a.type="button",a.addEventListener("click",()=>we(e)),o.appendChild(a),$.appendChild(o),j.set(e,o)}const D=nt(n,"th","oac-watchlist__col oac-watchlist__col--actions");D.appendChild(nt(n,"span","oac-sr",i("actions","Actions"))),$.appendChild(D),P.appendChild($);const M=nt(n,"tbody");O.append(I,P,M),L.appendChild(O),s.append(l,g,w,k,A,T,E,L),t.appendChild(s);let z=null,N=null,W=function(e){const t=e,o=t?.key;return"symbol"===o||"last"===o||"change"===o||"percent"===o?{key:o,direction:"ascending"===t?.direction?"ascending":"descending"}:{key:"list",direction:"ascending"}}(e.storage?.get(br)??yr.get(a)??null),B=null,U=!1,q=!1,K=[],G=!1,V=!1,H=!1;const J=new Map,Z=new Set;let Y,Q;try{Y=new Intl.NumberFormat(e.locale,{minimumFractionDigits:2,maximumFractionDigits:6}),Q=new Intl.NumberFormat(e.locale,{minimumFractionDigits:2,maximumFractionDigits:2})}catch{Y=new Intl.NumberFormat("en-US",{minimumFractionDigits:2,maximumFractionDigits:6}),Q=new Intl.NumberFormat("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}const X=new gr({feed:o.quotes,staleAfterMs:o.staleAfterMs,pollMs:o.pollMs,onChange:()=>de()}),ee=n.defaultView,te=ee?.IntersectionObserver,oe=te?new te(e=>{for(const t of e)t.isIntersecting?Z.add(t.target):Z.delete(t.target);ue()},{root:L}):null,ne=()=>z?.lists.find(e=>e.id===N)??null,ae=e=>{if(o.normalize)try{const t=o.normalize({symbol:e.symbol,exchange:e.exchange});if("string"==typeof t?.symbol&&"string"==typeof t.exchange)return{symbol:t.symbol,exchange:t.exchange}}catch{}return{symbol:e.symbol,exchange:e.exchange}},ie=(e,t)=>{if(o.formatPrice)try{return String(o.formatPrice(e,{...t}))}catch{}return Y.format(e)},re=(e,t)=>(e>0?"+":e<0?"-":"")+t(Math.abs(e));let se=null;const le=t=>{const o=e.chart.timezone();if(se?.zone!==o){let t=null;try{t=new Intl.DateTimeFormat(e.locale,{timeZone:o,timeStyle:"medium"})}catch{}se={zone:o,format:t}}try{if(null!==se.format)return se.format.format(new Date(t))}catch{}return new Date(t).toISOString()},ce=(e,t)=>{e.textContent!==t&&(e.textContent=t)};function de(){G||V||(G=!0,queueMicrotask(()=>{G=!1,xe()}))}function ue(){if(V)return;const e=!0===n.hidden;X.setVisible(e?[]:K.map(e=>J.get(e)).filter(e=>null===oe||Z.has(e.el)).map(e=>e.entry))}function pe(e){T.textContent=e,T.hidden=""===e}function he(t){pe(t instanceof Error&&"WatchlistConflictError"===t.name?i("conflict","The watchlists changed in another session. The saved lists are shown."):F(e,t)),ke()}function me(e,t=!1){if(V||!t&&null!==z&&e.revision<z.revision)return;z=e,H=!1;const o=new Set(e.lists.map(e=>e.id));N=null!==e.activeListId&&o.has(e.activeListId)?e.activeListId:null!==N&&o.has(N)?N:e.lists[0]?.id??null,ge()}function ge(){const e=ne()?.entries??[],t=new Set(e.map(vr));for(const[e,o]of J)t.has(e)||(oe?.unobserve(o.el),Z.delete(o.el),o.el.remove(),J.delete(e));for(const t of e){const e=vr(t);J.has(e)?J.get(e).entry=t:J.set(e,fe(t))}K=K.filter(e=>t.has(e));for(const t of e)K.includes(vr(t))||K.push(vr(t));xe(),ue()}function fe(e){const t=nt(n,"tr","oac-watchlist__row");t.dataset.symbol=e.symbol,t.dataset.exchange=e.exchange;const s=nt(n,"th","oac-watchlist__instrument");s.setAttribute("scope","row");const l=nt(n,"button","oac-watchlist__open");l.type="button",l.setAttribute("aria-label",r(e)),l.appendChild(nt(n,"span","oac-watchlist__symbol",e.symbol)),""!==e.exchange&&l.appendChild(nt(n,"span","oac-watchlist__exchange",e.exchange));const c={entry:e,el:t,open:l,last:nt(n,"td","oac-watchlist__last"),change:nt(n,"td","oac-watchlist__change"),percent:nt(n,"td","oac-watchlist__percent")};l.addEventListener("click",()=>o.onSelect?.({...c.entry})),l.addEventListener("keydown",e=>function(e,t){if("ArrowDown"!==e.key&&"ArrowUp"!==e.key)return;e.preventDefault(),e.stopPropagation();const o="ArrowDown"===e.key?1:-1;if(e.altKey)return void("list"===W.key&&function(e,t){be=be.then(async()=>{const o=ne();if(V||null===o||null===z||"list"!==W.key)return;const n=o.entries.findIndex(t=>wr(t,e)),i=n+t;if(!(n<0||i<0||i>=o.entries.length)){pe("");try{await a.moveEntry(o.id,e,i,{expectedRevision:z.revision})}catch(e){he(e)}}}).catch(()=>{})}(t.entry,o));const n=K.indexOf(vr(t.entry));J.get(K[n+o])?.open.focus()}(e,c)),s.appendChild(l);const d=nt(n,"td","oac-watchlist__actions");return d.appendChild(it(n,{label:i("remove","Remove {name}",{name:r(e)}),icon:"close",iconOnly:!0,onClick:()=>{!async function(e){const t=ne();if(null===t)return;pe("");try{await a.removeEntry(t.id,e)}catch(e){he(e)}}(c.entry)}})),t.append(s,c.last,c.change,c.percent,d),M.appendChild(t),oe?.observe(t),c}let be=Promise.resolve();function ve(){const e=ne()?.entries??[];if("list"===W.key)return e.map(vr);const t="ascending"===W.direction?1:-1,o=e=>{if("symbol"===W.key)return e.symbol;const t=X.row(e).quote;return null===t?null:"last"===W.key?t.last:hr(t)?.["change"===W.key?"change":"percent"]??null};return e.map((e,t)=>({key:vr(e),index:t,value:o(e)})).sort((e,o)=>{if(null===e.value||null===o.value)return e.value===o.value?e.index-o.index:null===e.value?1:-1;const n="string"==typeof e.value?e.value.localeCompare(o.value):e.value-o.value;return 0!==n?n*t:e.index-o.index}).map(e=>e.key)}function we(t){const o="symbol"===t?"ascending":"descending";W=W.key!==t?{key:t,direction:o}:W.direction===o?{key:t,direction:"ascending"===o?"descending":"ascending"}:{key:"list",direction:"ascending"},e.storage?.set(br,W),yr.set(a,W),xe(),ue()}function ye(e){return{loading:i("state.loading","Loading"),live:i("state.live","Live"),delayed:i("state.delayed","Delayed"),snapshot:i("state.snapshot","Snapshot"),stale:i("state.stale","Stale"),unavailable:i("state.unavailable","No quote"),error:i("state.error","Could not load")}[e]}const _e=()=>[...J.values()].some(e=>null!==X.row(e.entry).quote);function xe(){if(V)return;const t=ne(),o=z?.lists??[],a=JSON.stringify(o.map(e=>[e.id,e.name]));if(d.dataset.signature!==a){d.dataset.signature=a,d.textContent="";for(const e of o){const t=nt(n,"option",void 0,e.name);t.value=e.id,d.appendChild(t)}if(0===o.length){const e=nt(n,"option",void 0,i("noLists","No lists"));e.value="",d.appendChild(e)}}d.value=t?.id??"",d.disabled=0===o.length||H,h.disabled=m.disabled=null===t||H,p.disabled=H||o.length>=100,I.textContent=t?.name??i("title","Watchlist");const r=e.symbol(),l=!0===t?.entries.some(e=>wr(ae(e),r));S.textContent=""===r.symbol?i("addChart","Add chart symbol"):i("addCurrent","Add {symbol}",{symbol:r.symbol}),S.disabled=""===r.symbol||l||H,S.title=l?i("inList","Already in this list"):"",C.disabled=H;for(const e of J.values()){const t=X.row(e.entry),o=t.quote;e.el.dataset.state=t.status,wr(ae(e.entry),r)?e.el.setAttribute("aria-current","true"):e.el.removeAttribute("aria-current");const n=null===o?null:hr(o);ce(e.last,null!==o?ie(o.last,e.entry):"loading"===t.status?i("quoteLoading","..."):i("noQuote","n/a")),ce(e.change,null===n?"":re(n.change,t=>ie(t,e.entry))),ce(e.percent,null===n?"":`${re(n.percent,e=>Q.format(e))}%`);for(const t of[e.change,e.percent])t.classList.toggle("is-up",null!==n&&n.change>0),t.classList.toggle("is-down",null!==n&&n.change<0);const a=void 0!==o?.time?1e3*o.time:t.receivedAt,s=null===a?ye(t.status):`${ye(t.status)} ${le(a)}`;e.last.title!==s&&(e.last.title=s)}const c="list"!==W.key&&(U||q)?K.concat(ve().filter(e=>!K.includes(e))).filter(e=>J.has(e)):ve(),u=n.activeElement;c.forEach((e,t)=>{const o=J.get(e).el;M.children[t]!==o&&M.insertBefore(o,M.children[t]??null)}),null!==u&&s.contains(u)&&n.activeElement!==u&&u.focus();const g=c.join("\n")!==K.join("\n");K=c,g&&queueMicrotask(ue);for(const[e,t]of j)t.setAttribute("aria-sort",W.key===e?W.direction:"none");const f=X.status(),b=function(e){switch(e){case"unavailable":return i("status.unavailable","No quote source. Rows show symbols only.");case"snapshot":return i("status.snapshot","Snapshot quotes");case"connecting":return i("status.connecting","Connecting to quotes");case"live":return i("status.live","Live quotes");case"reconnecting":return _e()?i("status.reconnecting","Reconnecting. Quotes shown may be stale."):i("status.reconnectingEmpty","Reconnecting to quotes.");case"disconnected":return _e()?i("status.disconnected","Quotes disconnected. Values shown are stale."):i("status.disconnectedEmpty","Quotes disconnected.");case"error":return i("status.error","Quotes could not refresh: {error}",{error:X.error()??""});default:return""}}(f);ce(A,b),A.hidden=""===b,A.dataset.state=f,E.hidden=H||o.length>0&&(t?.entries.length??0)>0,ce(E,0===o.length?i("empty.none","No watchlists yet. Add a symbol to start one."):i("empty.list","This list is empty. Add the chart symbol or type one above.")),L.hidden=0===(t?.entries.length??0)}async function ke(){try{me(await a.load(),!0)}catch(t){if(V)return;H=!0,pe(i("loadFailed","Watchlists could not load: {error}",{error:F(e,t)})),xe()}}async function Ce(e){pe("");const t=ae(e),o=ne();if(o?.entries.some(e=>wr(ae(e),t)))pe(i("duplicate","{name} is already in this list",{name:r(t)}));else try{if(null===o){const e=await a.createList(i("defaultName","Watchlist"),[t]);await a.setActiveList(e.id)}else await a.addEntry(o.id,t)}catch(e){he(e)}}function Se(){B=null,g.hidden=!0,w.hidden=!0}function Ae(e){Se(),B=e,f.value="rename"===e?ne()?.name??"":i("newName","List {number}",{number:(z?.lists.length??0)+1}),g.hidden=!1,f.focus(),f.select?.()}async function Te(){const e=f.value.trim(),t=B;if(""===e||null===t)return;const o=ne();Se(),pe("");try{if("create"===t){const t=await a.createList(e);await a.setActiveList(t.id)}else null!==o&&await a.renameList(o.id,e)}catch(e){he(e)}}const Ee=()=>{const e=d.value;""!==e&&e!==N&&null!==z&&(N=e,Se(),ge(),a.setActiveList(e).catch(he))};d.addEventListener("change",Ee);const Le=e=>{e.preventDefault(),Te()};g.addEventListener("submit",Le);const Oe=e=>{"Escape"!==e.key||g.hidden||(e.stopPropagation(),Se())};g.addEventListener("keydown",Oe);let Ie=null;e.symbolSearch&&(Ie=Ht(e,C,{search:e.symbolSearch,onSelect:(t,o)=>{C.value="",Ce({symbol:t,exchange:o??e.symbol().exchange})}}));const Pe=t=>{if("Enter"!==t.key||t.defaultPrevented)return;t.preventDefault();const o=C.value.trim().toUpperCase();""===o||null!==Ie&&!Ie.canCommitRaw()||(Ie?.close(),C.value="",Ce({symbol:o,exchange:e.symbol().exchange}))};C.addEventListener("keydown",Pe);const $e=()=>{U=!0},je=()=>{U=!1,de()};M.addEventListener("pointerenter",$e),M.addEventListener("pointerleave",je);const De=()=>{q=!0},Me=e=>{const t=e.relatedTarget;null!==t&&M.contains(t)||(q=!1,de())};M.addEventListener("focusin",De),M.addEventListener("focusout",Me);const ze=e=>{"Escape"!==e.key&&"Tab"!==e.key&&e.stopPropagation()},Ne=e=>{e.stopPropagation()};s.addEventListener("keydown",ze),s.addEventListener("pointerdown",Ne);const Re=()=>ue();n.addEventListener("visibilitychange",Re);const Fe=e.chart.on("data:context",()=>de()),We=e.chart.on("timezone:changed",()=>de()),Be=a.subscribe(e=>me(e));return xe(),ke(),{el:s,initialFocus:d,reload:ke,destroy:()=>{V||(V=!0,X.destroy(),oe?.disconnect(),Ie?.destroy(),Be(),Fe(),We(),n.removeEventListener("visibilitychange",Re),d.removeEventListener("change",Ee),g.removeEventListener("submit",Le),g.removeEventListener("keydown",Oe),C.removeEventListener("keydown",Pe),M.removeEventListener("pointerenter",$e),M.removeEventListener("pointerleave",je),M.removeEventListener("focusin",De),M.removeEventListener("focusout",Me),s.removeEventListener("keydown",ze),s.removeEventListener("pointerdown",Ne),J.clear(),Z.clear(),s.remove())}}}const xr='\n.oac-widget .oac-watchlist { display: flex; flex-direction: column; gap: 6px; height: 100%; min-height: 0; padding: 8px 10px 0; box-sizing: border-box; font-size: 12px; }\n.oac-widget .oac-watchlist__bar, .oac-widget .oac-watchlist__add, .oac-widget .oac-watchlist__name, .oac-widget .oac-watchlist__confirm { display: flex; align-items: center; gap: 4px; flex: none; min-width: 0; }\n.oac-widget .oac-watchlist__bar .oac-select { flex: 1 1 auto; min-width: 0; }\n.oac-widget .oac-watchlist__bar .oac-select select { width: 100%; min-width: 0; }\n.oac-widget .oac-watchlist .oac-btn { height: 26px; padding: 0 7px; font-size: 11px; flex: none; }\n.oac-widget .oac-watchlist__name[hidden], .oac-widget .oac-watchlist__confirm[hidden], .oac-widget .oac-watchlist__scroll[hidden] { display: none; }\n.oac-widget .oac-watchlist__name input, .oac-widget .oac-watchlist__add input { flex: 1 1 auto; min-width: 0; height: 26px; }\n.oac-widget .oac-watchlist__confirm { flex-wrap: wrap; }\n.oac-widget .oac-watchlist__confirm-text { flex: 1 1 100%; color: var(--oac-tx); overflow-wrap: anywhere; }\n.oac-widget .oac-watchlist__add-current { max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.oac-widget .oac-watchlist__status { flex: none; font-size: 11px; color: var(--oac-mut); }\n.oac-widget .oac-watchlist__status[data-state="live"] { color: var(--oac-tx); }\n.oac-widget .oac-watchlist__status[data-state="reconnecting"], .oac-widget .oac-watchlist__status[data-state="disconnected"], .oac-widget .oac-watchlist__status[data-state="error"] { color: var(--oac-danger); }\n.oac-widget .oac-watchlist__message { flex: none; font-size: 11px; color: var(--oac-danger); overflow-wrap: anywhere; }\n.oac-widget .oac-watchlist__empty { margin: 6px 0; font-size: 11px; color: var(--oac-mut); }\n.oac-widget .oac-watchlist__scroll { flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; margin: 0 -10px; }\n/* Numbers take the width they need and the symbol the rest, so a price is never the part cut short. */\n.oac-widget .oac-watchlist__table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }\n.oac-widget .oac-watchlist__table thead th { position: sticky; top: 0; z-index: 1; background: var(--oac-panel); border-bottom: 1px solid var(--oac-bd-soft); padding: 0; }\n.oac-widget .oac-watchlist__sort { width: 100%; height: 24px; padding: 0 6px; border: 0; background: none; color: var(--oac-mut); font: 600 10px/1 var(--oac-font); text-transform: uppercase; letter-spacing: .04em; text-align: right; white-space: nowrap; cursor: pointer; }\n.oac-widget .oac-watchlist__col--symbol .oac-watchlist__sort { text-align: left; padding-left: 10px; }\n.oac-widget .oac-watchlist__sort:hover, .oac-widget th[aria-sort="ascending"] .oac-watchlist__sort, .oac-widget th[aria-sort="descending"] .oac-watchlist__sort { color: var(--oac-tx); }\n.oac-widget th[aria-sort="ascending"] .oac-watchlist__sort::after { content: " \\2191"; }\n.oac-widget th[aria-sort="descending"] .oac-watchlist__sort::after { content: " \\2193"; }\n.oac-widget .oac-watchlist__col--symbol { width: 100%; }\n.oac-widget .oac-watchlist__col--actions { width: 26px; min-width: 26px; }\n.oac-widget .oac-watchlist__row { height: 28px; border-bottom: 1px solid var(--oac-bd-soft); }\n.oac-widget .oac-watchlist__row:hover, .oac-widget .oac-watchlist__row:focus-within { background: var(--oac-elev); }\n/* On the cell: some engines paint no shadow on a table row. */\n.oac-widget .oac-watchlist__row[aria-current="true"] > th { box-shadow: inset 2px 0 0 var(--oac-acc); }\n.oac-widget .oac-watchlist__row td, .oac-widget .oac-watchlist__row th { padding: 0 6px; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 400; }\n.oac-widget .oac-watchlist__row .oac-watchlist__instrument { padding: 0; max-width: 0; text-align: left; }\n.oac-widget .oac-watchlist__open { display: block; width: 100%; height: 28px; line-height: 28px; padding: 0 6px 0 10px; border: 0; background: none; color: var(--oac-tx); font: inherit; text-align: left; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }\n.oac-widget .oac-watchlist__symbol { font-weight: 600; }\n.oac-widget .oac-watchlist__exchange { margin-left: 5px; font-size: 10px; color: var(--oac-mut); }\n.oac-widget .oac-watchlist__last { color: var(--oac-tx); }\n/* The theme\'s own pair, lifted to read as text. A fallback colour here would pin one palette. */\n.oac-widget .oac-watchlist .is-up { color: var(--oac-up); }\n.oac-widget .oac-watchlist .is-down { color: var(--oac-down); }\n.oac-widget .oac-watchlist__row[data-state="stale"] td, .oac-widget .oac-watchlist__row[data-state="unavailable"] td, .oac-widget .oac-watchlist__row[data-state="error"] td, .oac-widget .oac-watchlist__row[data-state="loading"] td { color: var(--oac-mut); }\n.oac-widget .oac-watchlist__row[data-state="stale"] .oac-watchlist__last { text-decoration: underline dotted; text-underline-offset: 3px; }\n.oac-widget .oac-watchlist__actions { padding: 0 4px 0 0 !important; }\n.oac-widget .oac-watchlist__actions .oac-btn { width: 22px; height: 22px; padding: 0; border-color: transparent; background: transparent; color: var(--oac-mut); opacity: 0; }\n.oac-widget .oac-watchlist__row:hover .oac-watchlist__actions .oac-btn, .oac-widget .oac-watchlist__row:focus-within .oac-watchlist__actions .oac-btn { opacity: 1; }\n.oac-widget .oac-panel-dock[data-sheet="true"] .oac-watchlist__actions .oac-btn { opacity: 1; width: 32px; height: 32px; }\n.oac-widget .oac-panel-dock[data-sheet="true"] .oac-watchlist__row, .oac-widget .oac-panel-dock[data-sheet="true"] .oac-watchlist__open { height: 40px; line-height: 40px; }\n@media (hover: none) { .oac-widget .oac-watchlist__actions .oac-btn { opacity: 1; } }\n';function kr(e,t,n){const a=e.document,i=n.source,r=n.locale??e.locale,s=u(a,"span","oac-account",{role:"group","aria-label":R(e,"Account")}),l=u(a,"button","oac-account__pick",{type:"button","aria-haspopup":"menu"}),c=u(a,"span","oac-account__name"),d=u(a,"span","oac-chev");d.innerHTML=o.chromeIconSvg("chevron-down"),l.appendChild(c),l.appendChild(d),s.appendChild(l);const p=(e,t)=>{const o=u(a,"span",`oac-account__field ${e}`),n=u(a,"i");n.textContent=t;const i=u(a,"b");return o.appendChild(n),o.appendChild(i),s.appendChild(o),{el:o,val:i}},h=p("oac-account__equity",R(e,"Equity")),m=p("oac-account__used",R(e,"Margin used")),g=p("oac-account__available",R(e,"Available")),f=u(a,"span","oac-account__state");s.appendChild(f);const b=t.querySelector(".oac-statusline__tz");null!==b&&b.parentNode===t?t.insertBefore(s,b):t.appendChild(s),t.classList.add("oac-has-account");const v=new Map,w=(e,t)=>{e.textContent!==t&&(e.textContent=t)},y=(e,t)=>{e.hidden===t&&(e.hidden=!t)},_=(e,t,o)=>{y(e.el,null!==o&&void 0!==t),null!==o&&void 0!==t&&w(e.val,((e,t)=>{const o=t??"";let n=v.get(o);if(void 0===n){const e={minimumFractionDigits:2,maximumFractionDigits:2};try{n=new Intl.NumberFormat(r,void 0===t?e:{...e,style:"currency",currency:t})}catch{n=new Intl.NumberFormat(r,e)}v.set(o,n)}return n.format(e)})(t,o.currency))};let x=null;const k=()=>{const t=i.getState();s.dataset.status=t.status;const o="unsupported"===t.status;s.classList.toggle("is-disabled",o),o?s.setAttribute("aria-disabled","true"):s.removeAttribute("aria-disabled");const n=t.accounts.find(e=>e.id===t.selectedId),r=void 0===n?R(e,"Account"):n.name??n.id;w(c,r),l.setAttribute("aria-label",void 0===n?r:R(e,"Account: {name}",{name:r})),l.disabled=o||0===t.accounts.length;const d=!o&&"analyzer"===t.mode;d&&null===x?(x=u(a,"span","oac-account__tag"),x.textContent=R(e,"Analyzer"),s.insertBefore(x,h.el)):d||null===x||(x.remove(),x=null);const p=o?null:t.snapshot;_(h,p?.equity,p),_(m,p?.marginUsed,p),_(g,p?.marginAvailable,p),l.title=[h,m,g].filter(e=>!e.el.hidden).map(e=>`${e.el.firstChild?.textContent??""} ${e.val.textContent??""}`).join(", ");const b=o||"error"===t.status?t.reason??"":"stale"===t.status?R(e,"Stale"):"loading"===t.status?R(e,"Loading account"):"";w(f,b),f.title=t.reason??"",f.classList.toggle("is-error","error"===t.status),f.classList.toggle("is-stale","stale"===t.status),y(f,""!==b)},C=()=>{const t=i.getState();"unsupported"!==t.status&&0!==t.accounts.length&&vt(e,l,t.accounts.map(o=>({label:o.name??o.id,sub:o.id,on:o.id===t.selectedId,onSelect:()=>{const t=t=>{e.toast(R(e,"Could not switch account: {error}",{error:t}),"error")};i.select(o.id).then(e=>{e.ok||!0===e.cancelled||t(e.reason)},o=>t(F(e,o)))}})),{ariaLabel:R(e,"Accounts")})};l.addEventListener("click",C);const S=i.subscribe(k);return k(),{el:s,refresh:k,destroy:()=>{S(),l.removeEventListener("click",C),t.classList.remove("oac-has-account"),s.remove()}}}const Cr='\n.oac-widget .oac-statusline.oac-has-account{container:oac-status/inline-size}\n.oac-widget .oac-statusline.oac-has-account .oac-statusline__time{flex:0 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis}\n.oac-widget .oac-statusline .oac-account{flex:none}\n.oac-widget .oac-account>.oac-account__pick,.oac-widget .oac-account>.oac-account__tag,.oac-widget .oac-account>.oac-account__field{flex:none}\n.oac-widget .oac-account{display:inline-flex;align-items:center;gap:10px;min-width:0;white-space:nowrap;font-variant-numeric:tabular-nums}\n.oac-widget .oac-account__pick{display:inline-flex;align-items:center;gap:4px;max-width:180px;height:20px;padding:0 6px;border:1px solid var(--oac-bd);border-radius:5px;background:var(--oac-elev);color:var(--oac-tx-strong);font-size:11.5px;font-weight:600}\n.oac-widget .oac-account__pick:hover:not(:disabled){border-color:var(--oac-bd-hover)}\n.oac-widget .oac-account__pick:disabled{cursor:not-allowed;color:var(--oac-faint)}\n.oac-widget .oac-account__name{min-width:0;overflow:hidden;text-overflow:ellipsis}\n.oac-widget .oac-account__pick .oac-chev{display:inline-grid;width:10px;height:10px;color:var(--oac-mut)}\n.oac-widget .oac-account__tag{padding:0 5px;border:1px solid var(--oac-bd-soft);border-radius:4px;color:var(--oac-amber);font-size:10px;font-weight:600;letter-spacing:.5px;text-transform:uppercase}\n.oac-widget .oac-account__field{display:inline-flex;align-items:center;gap:4px}\n.oac-widget .oac-account__field>i{font-style:normal;color:var(--oac-faint)}\n.oac-widget .oac-account__field>b{font-weight:500;color:var(--oac-tx)}\n.oac-widget .oac-account__state{min-width:0;max-width:320px;overflow:hidden;text-overflow:ellipsis;color:var(--oac-mut)}\n.oac-widget .oac-account__state.is-stale{color:var(--oac-amber)}\n.oac-widget .oac-account__state.is-error{color:var(--oac-danger)}\n.oac-widget .oac-account.is-disabled .oac-account__state{color:var(--oac-faint)}\n.oac-widget .oac-account[data-status="stale"] .oac-account__field>b{color:var(--oac-mut)}\n@container oac-status (max-width:1180px){.oac-widget .oac-account__used{display:none}}\n@container oac-status (max-width:1000px){.oac-widget .oac-account__equity{display:none}}\n@container oac-status (max-width:860px){.oac-widget .oac-account__available{display:none}\n.oac-widget .oac-statusline .oac-statusline__title{order:-2}.oac-widget .oac-statusline .oac-account{order:-1}}\n',Sr=pi+Da+Xi+ar+mo+Jt+rr+Ve+"\n.oac-widget .oac-pick .oac-dialog__body { display: flex; flex-direction: column; overflow: hidden; }\n.oac-widget .oac-pick__findwrap { flex: none; }\n.oac-widget .oac-pick__running-head { flex: none; padding: 1px 6px 3px; }\n.oac-widget .oac-pick__running { display: grid; align-content: start; gap: 1px; flex: 0 1 auto; min-height: 31px; max-height: 132px; }\n.oac-widget .oac-pick__list { flex: 1 1 auto; max-height: 300px; margin-top: 8px; padding-top: 4px; border-top: 1px solid var(--oac-bd); }\n.oac-widget .oac-pick__list, .oac-widget .oac-pick__running { overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--oac-sb-thumb) var(--oac-panel); }\n.oac-widget .oac-pick :is(.oac-pick__list, .oac-pick__running)::-webkit-scrollbar { width: 6px; }\n.oac-widget .oac-pick :is(.oac-pick__list, .oac-pick__running)::-webkit-scrollbar-track { background: var(--oac-panel); }\n.oac-widget .oac-pick :is(.oac-pick__list, .oac-pick__running)::-webkit-scrollbar-thumb { background: var(--oac-sb-thumb); border-radius: 3px; }\n.oac-widget .oac-pick :is(.oac-pick__list, .oac-pick__running)::-webkit-scrollbar-thumb:hover { background: var(--oac-sb-thumb-hover); }\n.oac-widget .oac-pick__running-row { display: flex; align-items: center; gap: 7px; min-height: 29px; padding: 2px 6px; }\n.oac-widget .oac-pick__running-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.oac-widget .oac-pick__running-number { min-width: 16px; color: var(--oac-mut); font-size: 11px; text-align: right; }\n.oac-widget .oac-pick__running-row .oac-pick__remove { height: 23px; min-height: 23px; padding: 2px 6px; }\n"+fi+lr+xr+Zi+Cr+Ui+Yn+ia+Oi+"\n.oac-widget .oac-topbar__layouts { max-width: 190px; }\n.oac-widget .oac-topbar__layouts-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n/* The name gives way before the bar wraps to a second row: the glyph, the unsaved mark, the tip and the\n   accessible name still carry it. Measured on the default bar, which needs about 1000 px on one row. */\n.oac-widget .oac-topbar.has-layouts { container: oac-topbar / inline-size; }\n@container oac-topbar (max-width: 1199px) { .oac-widget .oac-topbar__layouts-name { max-width: 96px; } }\n@container oac-topbar (max-width: 1139px) { .oac-widget .oac-topbar__layouts-name { display: none; } }\n.oac-widget .oac-topbar__layouts[data-attention=\"true\"]::after { content: ''; width: 6px; height: 6px; flex: none; border-radius: 50%; background: var(--oac-amber); }\n"+ji+'\n.oac-widget .oac-timeframe-menu{display:flex;flex-direction:column;width:260px;max-width:calc(100% - 16px);padding:6px;max-height:calc(100% - 16px);overflow:hidden}\n.oac-widget .oac-timeframe-menu>[data-add-interval]{display:flex;flex-shrink:0;gap:8px;width:100%;justify-content:flex-start;min-height:34px}\n.oac-widget .oac-timeframe-menu__body{min-height:0;max-height:min(65vh,560px);overflow:auto;scrollbar-width:thin;scrollbar-color:var(--oac-sb-thumb) transparent}\n.oac-widget .oac-timeframe-menu__body::-webkit-scrollbar{width:6px}.oac-widget .oac-timeframe-menu__body::-webkit-scrollbar-thumb{background:var(--oac-sb-thumb);border-radius:3px}\n.oac-widget .oac-timeframe-menu__body::-webkit-scrollbar-thumb:hover{background:var(--oac-sb-thumb-hover)}\n.oac-widget .oac-timeframe-menu__group{border-top:1px solid var(--oac-bd);padding:5px 0}\n.oac-widget .oac-timeframe-menu .oac-timeframe-menu__heading{width:100%;display:flex;justify-content:space-between;text-transform:uppercase;font-size:10px;letter-spacing:.06em;color:var(--oac-mut);min-height:28px;background:transparent;border-color:transparent}\n.oac-widget .oac-timeframe-menu__row{display:flex;align-items:center;border-radius:4px;min-height:34px}\n.oac-widget .oac-timeframe-menu__row:hover,.oac-widget .oac-timeframe-menu__row:focus-within{background:var(--oac-elev-2)}\n.oac-widget .oac-timeframe-menu__row[data-selected="true"]{background:var(--oac-on-bg)}\n.oac-widget .oac-timeframe-menu__pick[aria-pressed]{background:transparent;border-color:transparent;flex:1;text-align:left;min-height:34px;justify-content:flex-start}\n.oac-widget .oac-timeframe-menu__actions{display:grid;grid-template-columns:28px 28px;flex:none;gap:2px}\n.oac-widget .oac-timeframe-menu__actions .oac-btn{background:transparent;border-color:transparent;width:28px;height:28px;padding:5px}.oac-widget .oac-timeframe-menu__actions [hidden]{display:block;visibility:hidden;pointer-events:none}\n.oac-widget .oac-timeframe-dialog{width:340px;max-width:calc(100% - 24px);max-height:calc(100% - 24px);overflow:auto;padding:14px}\n.oac-widget .oac-timeframe-dialog__header,.oac-widget .oac-timeframe-dialog__footer{display:flex;align-items:center;justify-content:space-between;gap:10px}\n.oac-widget .oac-timeframe-dialog__header h3{font-size:15px;margin:0}.oac-widget .oac-timeframe-dialog__fields{display:grid;gap:12px;margin-top:20px}\n.oac-widget .oac-timeframe-dialog__fields label{display:grid;grid-template-columns:80px 1fr;align-items:center;gap:12px}\n.oac-widget .oac-timeframe-dialog__unit{position:relative;display:block}.oac-widget .oac-timeframe-dialog__unit .oac-glyph{position:absolute;right:8px;top:8px;pointer-events:none}\n.oac-widget .oac-timeframe-dialog__unit select{padding-right:30px}\n.oac-widget .oac-timeframe-dialog__fields input,.oac-widget .oac-timeframe-dialog__fields select{width:100%;min-width:0;background:var(--oac-bg);color:var(--oac-tx);border:1px solid var(--oac-bd);border-radius:4px;padding:7px;appearance:none}\n.oac-widget .oac-timeframe-dialog__error{min-height:30px;padding:8px 0;font-size:11px;color:var(--oac-mut)}\n.oac-widget .oac-timeframe-dialog__footer{justify-content:flex-end}.oac-widget .oac-timeframe-dialog__footer button{min-width:58px;min-height:30px}\n',Ar=e=>e instanceof Error?e:new Error(String(e));function Tr(e){return function(e,o){const n=e._opts,a=e.chart,i=n.ranges??wi,r=n.sessionCalendar;let s=null,l=null;const c=(e,t)=>{if("function"!=typeof r)return r??null;const o=`${t}\0${e}`;if(o!==s){s=o;try{l=""===e?null:r({symbol:e,exchange:t})??null}catch{l=null}}return l},d=()=>void 0===r?a.dataLayer.sessionCalendar:c(e._symbol,e._exchange);if(void 0!==r){const t=()=>{a.isDestroyed||(a.setSessionCalendar(c(e._symbol,e._exchange)),e._statusline?.refresh())};t(),e._cleanups.push(e._bus.on("symbol",t))}if(!1!==n.sessionShading){const o=t.attachSessionShading(a);e._cleanups.push(()=>o.destroy())}e._cleanups.push(a.on("timezone:changed",()=>{e._destroyed||(e._scheduleSave(),e._bus.emit("layout",{reason:"timezone"}))}));let p=null,h=!1,m=0;const g=()=>{const t=p;return null===t||t.interval!==e._interval?null:i.find(e=>e.id===t.id)??null},f=e=>{const t=a.primaryBars(),o=t[t.length-1];if(void 0===o)return e;const n=a.dataLayer.timeToIndex(o.time)??t.length-1,i=a.getVisibleLogicalRange(),r=n+.5-(i.to-i.from);return a.setVisibleLogicalRange({from:r,to:n+.5}),{...e,from:a.dataLayer.indexToTime(Math.ceil(r+.5))??e.from,to:o.time}},b=async(t,o)=>{for(let t=0;t<4&&null!==e._loading;t++){try{await e._loading}catch{}if(o!==m||e._destroyed)return{status:"cancelled"}}if(o!==m||e._destroyed)return{status:"cancelled"};const n=a.primaryBars();if(0===n.length)return{status:"no-data"};const i="all"===t.unit,r=Si(t,{end:n[n.length-1].time,zone:a.timezone(),calendar:d(),bars:i?void 0:n});let s=await e.goTo(r);return o!==m||e._destroyed?s:(!i||"partial"!==s.status||"exhausted"!==s.history&&"empty"!==s.history||(s={status:!0===s.clipped?"partial":"placed",from:s.from,to:s.to,...!0===s.clipped?{clipped:!0}:{}}),"partial"===s.status&&!0===s.clipped?f(s):s)},v=async t=>{const o=i.find(e=>e.id===t);if(void 0===o||e._destroyed)return{status:"invalid"};const n=++m,a=_i(o,e._intervals);p={id:t,interval:a},h=!0;try{e.setInterval(a)}catch(e){return p=null,{status:"error",error:Ar(e)}}finally{h=!1}return b(o,n)};e._cleanups.push(e._bus.on("interval",()=>{h||(p=null,m++)}));const w=()=>{const e=g();null!==e&&b(e,++m)};e._cleanups.push(e._bus.on("symbol",w)),e._cleanups.push(e._bus.on("variant",w));const y=(e,t)=>{const o=g();if(null===o)return e;const n=Si(o,{end:t,zone:a.timezone(),calendar:d()});return{from:Math.min(n.from,e.from),to:e.to}};let _;if(!1!==n.bottombar){const t=u(e.context.document,"div","oac-bottombar");!1===n.topbar&&t.classList.add("is-kept"),e.root.insertBefore(t,o),e.root.classList.add("has-bottombar");const r=Li(e.context,t,{target:()=>({chart:a,interval:()=>e._interval,range:()=>g()?.id??null,setRange:v}),ranges:i,onGoTo:t=>e._openGoTo(t),now:()=>(n.now??Date.now)()});_=r.controls,e._cleanups.push(()=>{r.destroy(),t.remove(),e.root.classList.remove("has-bottombar")})}return{setRange:v,range:()=>g()?.id??null,fetchWindow:y,controls:_}}(this,e)}const Er=["1m","5m","15m","1h","1d","1w"],Lr=new WeakMap,Or=["feed","symbol","exchange","interval","variant","intervals","chartType","theme","rail","topbar","statusline","mobile","loading","persist","storage","timeframePreferences","canSelectInterval","drawingScope","drawingStore","locale","translate","indicators","symbolSearch","lookbackBars","now","onOrder","styleNonce","tradingCapabilities","tradingMode","tradingLocked","account","eventDetails","captureRows","panels","typingNavigation","keyboardRoute","watchlist","news","drawingTemplates","drawingToolbar","shortcutsEditor","workspaces","layouts","bottombar","ranges","sessionCalendar","sessionShading"];function Ir(e){return"light"===e?{theme:t.lightTheme,name:"light"}:"dark"===e||void 0===e?{theme:t.darkTheme,name:"dark"}:{theme:e,name:$n(e)}}function Pr(e,o,n){const a=t.tryResolveInterval(e),i=null!==a&&"interval"===a.bucketing.mode?a.bucketing.seconds:null;return{from:n-(null===i?15768e4:Math.max(1,Math.round(o))*i),to:n}}class $r{constructor(e,t){Object.defineProperty(this,"chart",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"draw",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"objects",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"alerts",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"history",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"drawingTemplates",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"root",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"document",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"keymap",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"bus",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"storage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"locale",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"translate",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"symbolSearch",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"toast",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"openOverlay",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"status",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"tips",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"overlays",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"symbol",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"interval",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"intervals",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"settingsDefaults",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_source",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._source=e,this.chart=t.chart,this.draw=t.draw,this.objects=t.objects,this.alerts=t.alerts,this.history=t.history,this.root=t.root,this.document=t.document,this.keymap=t.keymap,this.bus=t.bus,this.storage=t.storage,this.locale=t.locale,this.translate=t.translate,this.symbolSearch=t.symbolSearch,this.toast=t.toast,this.openOverlay=t.openOverlay,this.status=t.status,this.tips=t.tips,this.overlays=t.overlays,this.symbol=t.symbol,this.interval=t.interval,this.intervals=t.intervals,this.settingsDefaults=t.settingsDefaults}get theme(){return this._source.theme()}get chartTheme(){return this._source.chartThemeInUse()}}function jr(e,o,n){const a={...e};for(const e of Or)delete a[e];const i={mousePan:"horizontal",...e.navigation};void 0===a.zoomAnchor&&(a.zoomAnchor="right"),a.navigation=void 0===i.defaultVisibleBars&&void 0===i.defaultBarSpacing?{...i,defaultBarSpacing:e.timeScale?.barSpacing??8}:i;const r=!0===o.defaultView?.matchMedia?.("(prefers-reduced-motion: reduce)").matches;r&&void 0===a.animZoom&&(a.animZoom=!1),r&&void 0===a.animAutoscale&&(a.animAutoscale=!1);const s=e.keyboardRoute,l=e.shortcuts;if(void 0!==s&&!1!==l){const e=l instanceof t.ShortcutManager?l:new t.ShortcutManager(l);a.shortcuts=new Proxy(e,{get:(e,t)=>{if("scope"===t)return"global";if("resolve"===t)return t=>s()??("global"===e.scope||n())?e.resolve(t):null;const o=Reflect.get(e,t);return"function"==typeof o?o.bind(e):o}})}return a}function Dr(e,t){const o=u(e.document,"span","oac-tip-spot",{"aria-hidden":"true"});e.root.appendChild(o);let n=null;e.tips.attach(o,()=>null===n?null:{title:n,side:"bottom"});const a=t=>{const n=e.root.getBoundingClientRect();o.style.left=t.clientX-n.left+"px",o.style.top=t.clientY-n.top+"px"};t.addEventListener("pointermove",a);const i=e.chart.on("hover",t=>{const a=t.id;n=null===a?null:(t=>{const o=t.lastIndexOf("::");if(o<0)return null;const n=t.slice(0,o),a=t.slice(o+2);if(/^(?:ord|order):/.test(n))return"close"===a?R(e,"Cancel order"):null;if(/^(?:pos|position):/.test(n))return"close"===a?R(e,"Close position"):null;const i=n.startsWith("indicator:")?e.chart.indicators().find(e=>e.id===n.slice(10)):void 0;if(void 0===i)return null;const r=i.name;return"hide"===a?R(e,i.visible()?"Hide {name}":"Show {name}",{name:r}):"settings"===a?R(e,"Settings for {name}",{name:r}):"close"===a?R(e,"Remove {name}",{name:r}):null})(a),null!==n?e.tips.show(o):e.tips.target()===o&&e.tips.hide()});return()=>{i(),t.removeEventListener("pointermove",a),o.remove()}}class Mr{_initTimeframes(e){const o=new Set(this._timeframePreferences.custom()),n=new Set(e.intervals??[...Er,...t.registeredIntervals().map(e=>e.code).filter(e=>!o.has(e))]);n.add(this._interval),this._intervals.push(...n);const a=this._intervals.filter(t=>!o.has(t)||e.intervals?.includes(t)),i=()=>{this._intervals.splice(0,this._intervals.length,...new Set([...a,...this._timeframePreferences.custom()]))};return i(),this._cleanups.push(this._timeframePreferences.subscribe(i)),e.canSelectInterval??(t=>{const o=e.feed;if(o&&"resolve"in o&&"function"==typeof o.resolve)try{return o.resolve({symbol:this._symbol,exchange:this._exchange,interval:t}),!0}catch{return!1}return a.includes(t)})}constructor(e,n){Object.defineProperty(this,"dataController",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"chart",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"draw",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"instrumentDrawings",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"drawingTemplates",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"objects",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"alerts",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"history",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"root",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"context",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"ready",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_series",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_doc",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_opts",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_bus",{enumerable:!0,configurable:!0,writable:!0,value:new zo}),Object.defineProperty(this,"_storage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_timeframePreferences",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_keymap",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_toasts",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_chartEl",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_rail",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_topbar",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_statusline",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_mobile",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_drawbar",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_objectsPanel",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_dock",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_quickEntry",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_alertsPanel",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_goToPanel",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_layouts",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_navigator",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_bottombar",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_navigation",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_loading",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_anchoring",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_intervals",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"_symbol",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_exchange",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_interval",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_variant",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_chartType",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_chartTypeRequest",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_themeName",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_chartTheme",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_pointerInside",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_pointerInChart",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_dataStatus",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_displayedBars",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_dataState",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_initialView",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"_pendingView",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"_keepView",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_saveTimer",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"_restoring",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_holdDrawings",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_saveWanted",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_stateGiven",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_destroyed",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_cleanups",{enumerable:!0,configurable:!0,writable:!0,value:[]}),this._opts=n,this.dataController=n.feed?new t.DataLoadingController(n.feed,{now:()=>Math.floor((n.now??Date.now)()/1e3),...n.loading}):null,this._navigator=new oo({chart:()=>this.chart,loadHistory:e=>this._loadHistory(e)});const a=n.document??e.ownerDocument;this._doc=a,Un(a,Sr,n.styleNonce);const i="string"==typeof n.persist?n.persist:"default",r=n.persist?void 0===n.storage?ee():n.storage:null;this._storage=new x(i,r,{onError:e=>Fo.call(this,e)}),this._timeframePreferences=n.timeframePreferences??d(this._storage,n.intervals??Er),n.timeframePreferences||this._cleanups.push(()=>this._timeframePreferences.destroy()),this._restoring=!this._storage.loaded,this._holdDrawings=this._restoring;const s=Po.call(this);this._symbol=(n.symbol??s?.symbol??"").toUpperCase(),this._exchange=n.exchange??s?.exchange??"",this._interval=function(e,o){void 0!==e.interval&&t.resolveInterval(e.interval);for(const o of e.intervals??[])t.resolveInterval(o);const n=null!==o&&t.isKnownInterval(o.interval)?o.interval:"1d";return e.interval??n}(n,s),this._variant=void 0!==n.variant?t.normalizeDataVariant(n.variant):s?.variant;const l=n.chartType??s?.chartType??"candlestick";if(void 0!==n.chartType&&!qt(n.chartType))throw new Error(`openalgo-charts widget: "${n.chartType}" is not a registered chart type`);this._chartType=qt(l)?l:"candlestick";const c=Ir(n.theme??s?.theme);this._themeName=c.name,this._chartTheme=c.theme;const p=this._initTimeframes(n),h=u(a,"div","oac-widget");h.dataset.theme=this._themeName,Rn(h,Nn(this._chartTheme,this._themeName)),this.root=h;const m=u(a,"div","oac-topbar");!1===n.topbar&&(m.hidden=!0),h.appendChild(m);const g=u(a,"div","oac-stage");h.appendChild(g);const f=u(a,"div","oac-rail");!1===n.rail&&(f.hidden=!0),g.appendChild(f);const b=u(a,"div","oac-chart");this._chartEl=b,g.appendChild(b);const v=u(a,"div","oac-statusline");!1===n.statusline&&(v.hidden=!0),h.appendChild(v);const w=u(a,"div","oac-toasts");h.appendChild(w),e.appendChild(h),this.chart=t.createChart(b,{...jr(n,a,()=>this._inChart()),theme:this._chartTheme,document:a}),b.setAttribute("aria-label",n.ariaLabel??R(n,"Price chart"));const y=this._transformFor(this._chartType,void 0===n.chartType?s?.chart:void 0);this._series=this.chart.addSeries(null===y?this._chartType:t.getSeriesTransform(y.type).renderer,null===y?{}:{transform:y}),this._publishDataContext(),this.draw=new o.DrawingController(this.chart,{}),this.instrumentDrawings="chart"===n.drawingScope?null:Co.call(this,s),this.alerts=new t.AlertController(this.chart,{drawings:this.draw}),this.objects=new t.ChartObjects(this.chart,{drawings:this.draw,drawingName:e=>R(n,`schema.drawing.${e}.name`,{},At(e)),onSettings:e=>{"source"===e.kind?this.openSettings():"indicator"===e.kind?Fa(this.context,void 0,{instanceId:e.sourceId}):"drawing"===e.kind&&_a(this.context,void 0,{ids:[e.sourceId]})}}),this.history=new me(this.chart,{draw:this.draw,series:()=>this._series,setChartType:e=>this.setChartType(e),onError:({direction:e,error:t})=>{const o=F(this.context,t);this._toasts.toast(R(this.context,"undo"===e?"That step could not be undone: {error}":"That step could not be redone: {error}",{error:o}),"error")}});const _=S(h,a),k=A(h,_.layer,a);this._toasts=kn(w,a,n);const C=this.chart.shortcuts;if(this._keymap=new De({chart:C,scopes:()=>go.call(this)}),this._keymap.onConflict(e=>this._bus.emit("keymap:conflict",{combo:e.combo,kept:e.kept,shadowed:e.shadowed})),this.context=this._createContext(h,a,n,_,k),this._cleanups.push(()=>{k.destroy(),_.destroy()}),this._cleanups.push(Dr(this.context,b)),!1!==n.eventDetails&&this._cleanups.push(function(e,t,o){const n=e.chart,a=!1===o.eventDetails?void 0:o.eventDetails,i=new tr(t,{styleNonce:o.styleNonce,overlays:e.overlays,formatTime:e=>{const t=new Date(1e3*e);return Number.isFinite(t.getTime())?new Intl.DateTimeFormat(o.locale,{timeZone:n.timezone(),dateStyle:"medium",timeStyle:"short"}).format(t):String(e)},...a,labels:{...er(e),...a?.labels},injectStyles:!1}),r=[n.on("event:click",e=>{const t=e;i.open(t,t.point)}),n.on("data:context",()=>i.close()),n.on("events:change",()=>i.close())];return()=>{for(const e of r)e();i.destroy()}}(this.context,b,n)),this._dataStatus=function(e,o,n,a){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,o.appendChild(i);let r=n?.getState()??null,s="",l=!1;const c=e=>e.stopPropagation();for(const e of["pointerdown","wheel","keydown"])i.addEventListener(e,c);const d=()=>{if(l)return;const o=[];if(null!==r){const t=r.request?.symbol??"",i=r.request?.interval??"";switch(r.status){case"loading":o.push({text:R(e,"Loading {symbol} {interval}",{symbol:t,interval:i})});break;case"refreshing":o.push({text:R(e,"Refreshing {symbol} {interval}",{symbol:t,interval:i})});break;case"empty":o.push({text:R(e,"No bars for {symbol} {interval}",{symbol:t,interval:i}),label:R(e,"Retry chart data"),retry:a});break;case"stale":o.push({text:R(e,"History is stale for {symbol} {interval}",{symbol:t,interval:i}),label:R(e,"Retry chart data"),retry:a});break;case"error":o.push({text:R(e,"Could not load {symbol} {interval}",{symbol:t,interval:i}),label:R(e,"Retry chart data"),retry:a});break;case"unsupported":o.push({text:R(e,"Not available from this source: {variant}",{variant:Pt(e,r.request?.variant,r.unsupported)})})}"limited"===r.historyStatus?o.push({text:R(e,"History retention limit reached")}):"loading"===r.historyStatus?o.push({text:R(e,"Loading older history")}):"error"===r.historyStatus&&o.push({text:R(e,"Could not load older history"),label:R(e,"Retry older history"),retry:()=>{n?.loadMore()}})}for(const n of e.chart.indicators()){const a=n.dataStatus();if(null===a||"ready"===a.state)continue;if("error"===a.state&&a.error instanceof t.IndicatorInputError){const t=F(e,a.error);o.push({text:t.startsWith(`${n.name}: `)?t:R(e,"{name}: {error}",{name:n.name,error:t})});continue}const i={loading:R(e,"Loading"),empty:R(e,"No data"),unsupported:R(e,"Unsupported"),error:R(e,"Could not load")}[a.state];o.push({text:`${n.name}: ${i}`,label:R(e,"Retry {name}",{name:n.name}),retry:"loading"===a.state?void 0:()=>n.retryData()})}const c=JSON.stringify(o.map(e=>[e.text,e.label,!!e.retry]));if(s!==c){s=c,i.textContent="",i.hidden=0===o.length;for(const t of o){const o=u(e.document,"div","oac-data-status__row"),n=u(e.document,"span","oac-data-status__text");if(n.textContent=t.text,o.appendChild(n),t.retry){const n=u(e.document,"button","oac-btn");n.textContent=R(e,"Retry"),n.type="button",n.setAttribute("aria-label",t.label),n.addEventListener("click",t.retry),o.appendChild(n)}i.appendChild(o)}}},p=()=>{d(),queueMicrotask(d)},h=["indicator:data-status","indicatorRemoved"].map(t=>e.chart.on(t,p));return d(),{el:i,update:e=>{r=e,d()},destroy:()=>{l=!0;for(const e of h)e();for(const e of["pointerdown","wheel","keydown"])i.removeEventListener(e,c);i.remove()}}}(this.context,g,this.dataController,()=>{this.reload()}),!1!==n.panels&&(this._dock=ho(this.context,g,{data:e=>nr(this.context,e),objects:e=>{const t=$a(this.context);return e.appendChild(t.element),t},...n.watchlist?{watchlist:e=>_r(this.context,e,{...n.watchlist,onSelect:e=>this.setSymbol(e.symbol,e.exchange),normalize:e=>({symbol:e.symbol.trim().toUpperCase(),exchange:e.exchange})})}:{},...n.news?{news:e=>Ji(this.context,e,n.news)}:{},onChange:()=>{this._bus.emit("layout",{reason:"panels"}),this._scheduleSave()}})),this._cleanups.push(di(this.context,{...n.onOrder?{onOrder:n.onOrder}:{},tradingCapabilities:n.tradingCapabilities,tradingMode:n.tradingMode,...n.tradingLocked?{tradingLocked:n.tradingLocked}:{}})),!1!==n.rail){const e={..."object"==typeof n.rail?n.rail:{},cursorTarget:b};this._rail=It(this.context,f,e)}this.drawingTemplates=n.drawingTemplates?Vn(this.context,n.drawingTemplates):null,this.context.drawingTemplates=this.drawingTemplates??void 0,(n.drawingToolbar??!1!==n.rail)&&(this._drawbar=Bi(this.context,g,{chart:b,templates:this.drawingTemplates}));const T=Lr.has(n),E=!1===n.bottombar&&!T;if(!1!==n.statusline&&(this._statusline=Ut(this.context,v,{locale:n.locale,marketStatus:E,now:n.now}),this._statusline.setSymbol(this._symbol,this._exchange,this._interval),void 0!==n.account)){const e=kr(this.context,v,{source:n.account,locale:n.locale});this._cleanups.push(()=>e.destroy())}if(this._bottombar=Tr.call(this,v),this._layouts=function(e,t){const o=t.workspaces,n=!1===t.layouts?null:t.layouts??null;if(void 0===o&&null===n)return null;const a=e.context,i=nn(a);Qo(a,o);const r=null===n&&!1!==t.layouts&&void 0!==o?so(o,Jo(e)):null,s=n??r,l={handle:null,waiting:null};let c=!1;const d=null===r?void 0:rn(r,i,e=>a.status(e,"error")),u=a.document,p=u.defaultView,h=()=>{"hidden"===u.visibilityState&&r?.flush()},m=()=>{r?.flush()};return null!==r&&(u.addEventListener("visibilitychange",h),p?.addEventListener("pagehide",m),r.reload().then(async e=>{if(c||null===e.activeWorkspaceId)return;const t=await r.open(e.activeWorkspaceId);t.applied||c||a.status(i("notReopened","The last layout could not open here: {error}",{error:t.reason??""}),"error")}).catch(e=>{c||a.status(i("notLoaded","Saved layouts could not be read: {error}",{error:F(a,e)}),"error")})),{controller:s,open:e=>!c&&null!==s&&(cn(a,s,e,l,()=>!c),!0),destroy(){c||(c=!0,l.handle?.close(),d?.(),u.removeEventListener("visibilitychange",h),p?.removeEventListener("pagehide",m),r?.destroy(),Qo(a,void 0))}}}(this,n),!1!==n.topbar&&(this._topbar=_n(this.context,m,{intervals:this._intervals,timeframePreferences:this._timeframePreferences,canSelectInterval:p,indicators:n.indicators,search:this.context.symbolSearch,state:()=>({symbol:this._symbol,exchange:this._exchange,interval:this._interval,chartType:this.chartType(),theme:this._themeName}),onSymbol:(e,t)=>this.setSymbol(e,t),onInterval:e=>this.setInterval(e),onChartType:e=>this.setChartType(e),onTheme:e=>this.setTheme(e),onSettings:e=>this._openDialog("settings",e),onIndicators:e=>this._openDialog("indicatorPicker",e),onObjects:e=>this._openObjects(e),...!1===n.panels?{}:{onDataWindow:()=>this._dock?.toggle("data")},onAlerts:e=>this._openAlerts(e),...this._docked("watchlist")?{onWatchlist:()=>this._dock?.toggle("watchlist")}:{},...this._docked("news")?{onNews:()=>this._dock?.toggle("news")}:{},...E?{onGoTo:e=>this._openGoTo(e)}:{},layouts:this._layouts?.controller??void 0,onLayouts:e=>this._layouts?.open(e),settingsAvailable:()=>null!==M("settings"),indicatorsAvailable:()=>null!==M("indicatorPicker"),dataAvailable:()=>null===this.dataController||"ready"===this._dataState?.status||"stale"===this._dataState?.status,captureRows:n.captureRows})),this._mobile=Mi(this.context,{mode:n.mobile,container:e,intervals:this._intervals,timeframePreferences:this._timeframePreferences,canSelectInterval:p,topbar:!1!==n.topbar,rail:this._rail,tools:"object"==typeof n.rail?n.rail.tools:void 0,indicators:!1!==n.indicators,search:this.context.symbolSearch,state:()=>({symbol:this._symbol,exchange:this._exchange,interval:this._interval,chartType:this.chartType(),theme:this._themeName}),onSymbol:(e,t)=>this.setSymbol(e,t),onInterval:e=>this.setInterval(e),onChartType:e=>this.setChartType(e),onTheme:()=>this.setTheme("dark"===this._themeName?"light":"dark"),onSettings:e=>this._openDialog("settings",e),onIndicators:e=>this._openDialog("indicatorPicker",e),onObjects:e=>this._openObjects(e),...!1===n.panels?{}:{onDataWindow:()=>this._dock?.toggle("data")},onAlerts:e=>this._openAlerts(e),...this._docked("watchlist")?{onWatchlist:()=>this._dock?.open("watchlist")}:{},...this._docked("news")?{onNews:()=>this._dock?.open("news")}:{},...T?{}:{onGoTo:e=>this._openGoTo(e)},onProperties:e=>this._openDialog("drawingProperties",e),onCapture:e=>this._topbar?.openCapture(e),bottombar:this._bottombar.controls,...this._layouts?.controller?{onLayouts:()=>this._layouts?.open()}:{},settingsAvailable:()=>null!==M("settings"),indicatorsAvailable:()=>null!==M("indicatorPicker")}),fo.call(this),this._keymap.attach(a),!1!==n.typingNavigation&&(this._quickEntry=ir(this.context,{enabled:()=>!this._destroyed&&null!==this._doc.activeElement&&this._chartEl.contains(this._doc.activeElement)&&0===this.draw.selection().length,onSymbol:(e,t)=>this.setSymbol(e,t),onInterval:e=>this.setInterval(e),search:this.context.symbolSearch})),vo.call(this),this._followChart(),ko.call(this,s),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(!a.hidden);a.addEventListener("visibilitychange",e),this._cleanups.push(()=>a.removeEventListener("visibilitychange",e)),a.hidden&&e(),""===this._symbol||this._restoring||this.reload()}this.ready=this._restoring?Mo.call(this):Promise.resolve()}_createContext(e,t,o,n,a){const i=o.symbolSearch??function(e,t){if("function"==typeof e?.searchSymbols)return async(o,n)=>{const a=await e.searchSymbols({query:o,signal:n?.signal}),i=o.trim().toUpperCase(),r=a.findIndex(e=>!e.contractGroup&&e.exchange===t()&&e.symbol.toUpperCase()===i);return r>0?[a[r],...a.slice(0,r),...a.slice(r+1)]:a}}(o.feed,()=>this._exchange);return new $r(this,{chart:this.chart,draw:this.draw,objects:this.objects,alerts:this.alerts,history:this.history,root:e,document:t,keymap:this._keymap,bus:this._bus,storage:this._storage,locale:o.locale,translate:o.translate,symbolSearch:i,toast:(e,t)=>this._toasts.toast(e,t),openOverlay:(e,t)=>n.open(e,t),status:(e,t="info")=>{this._statusline?.setMessage(e,t),this._bus.emit("status",{text:e,kind:t})},tips:a,overlays:n,symbol:()=>({symbol:this._symbol,exchange:this._exchange}),interval:()=>this._interval,intervals:void 0===o.intervals?void 0:this._intervals,settingsDefaults:{"navigation.mousePan":o.navigation?.mousePan??"horizontal"}})}get series(){return this._series}get layouts(){return this._layouts?.controller??null}get isDestroyed(){return this._destroyed}symbol(){return this._symbol}exchange(){return this._exchange}interval(){return this._interval}variant(){return this._variant}chartType(){return this.chart.seriesTransform(this._series)?.type??this.chart.seriesType(this._series)??this._chartType}_transformFor(e,o){if(!t.registeredSeriesTransforms().includes(e)||void 0===this._opts.feed&&t.registeredChartTypes().includes(e))return null;const n=Array.isArray(o?.series)?o.series:[],a=n.find(t=>t?.transform?.type===e)?.transform?.options;if(void 0===a)return{type:e};try{return t.getSeriesTransform(e).create(a),{type:e,options:a}}catch{return{type:e}}}theme(){return this._themeName}chartThemeInUse(){return this._chartTheme}on(e,t){return this._bus.on(e,t)}off(e,t){this._bus.off(e,t)}setSymbol(e,t){const o=e.trim().toUpperCase(),n=t??this._exchange;if(o===this._symbol&&n===this._exchange)return this._topbar?.refresh(),void this._mobile?.refresh();this._symbol=o,this._exchange=n,this._cancelNavigation(),this._keepView=!1,this._pendingView=null,null===this.dataController&&(this._series.setData([]),this._publishDataContext()),this._statusline?.setSymbol(o,n,this._interval),this._topbar?.refresh(),this._mobile?.refresh(),this._scheduleSave(),this._opts.feed&&this.reload(),this._bus.emit("symbol",{symbol:o,exchange:n}),this.chart.emit("symbol",{symbol:o,exchange:n})}setInterval(e){const o=e.trim();if(""===o)throw new Error("openalgo-charts widget: interval code must not be empty");if(t.resolveInterval(o),o===this._interval)return this._topbar?.refresh(),void this._mobile?.refresh();this._interval=o,this._cancelNavigation(),this._keepView=!1,this._pendingView=null,null===this.dataController&&(this._series.setData([]),this._publishDataContext()),this._statusline?.setSymbol(this._symbol,this._exchange,o),this._topbar?.refresh(),this._mobile?.refresh(),this._scheduleSave(),this._opts.feed&&this.reload(),this._bus.emit("interval",{interval:o})}setDataVariant(e){const o=t.normalizeDataVariant(e);t.dataVariantKey(o)!==t.dataVariantKey(this._variant)&&(this._variant=o,this._cancelNavigation(),this._keepView=!1,this._pendingView=null,null===this.dataController&&(this._series.setData([]),this._publishDataContext()),this._scheduleSave(),this._opts.feed&&this.reload(),this._bus.emit("variant",{variant:o}))}setChartType(e){this._selectChartType(e)}_selectChartType(e,t){if(!qt(e))throw new Error(`openalgo-charts widget: "${e}" is not a registered chart type`);if(e===this.chartType()&&void 0===t)return;const o=this._transformFor(e,t),n=++this._chartTypeRequest;let a=this.chart.setSeriesTransform(this._series,o);n===this._chartTypeRequest&&(null===o&&(a=this.chart.setSeriesType(this._series,e)||a),a&&n===this._chartTypeRequest&&this.chartType()===e&&(this._scheduleSave(),this._bus.emit("layout",{reason:"chartType",chartType:e})))}setTheme(e){const t=Ir(e);this._themeName=t.name,this._chartTheme=t.theme,this.chart.setTheme(t.theme),this.root.dataset.theme=t.name,Rn(this.root,Nn(t.theme,t.name)),this._topbar?.refresh(),this._mobile?.refresh(),this._scheduleSave(),this._bus.emit("theme",{theme:t.name,chartTheme:t.theme})}openSettings(){return this._openDialog("settings")}openIndicatorPicker(){return this._openDialog("indicatorPicker")}openObjects(){return this._openObjects()}openDataWindow(){return!(this._destroyed||!this._dock)&&(this._dock.open("data"),!0)}openAlerts(){return this._openAlerts()}openWatchlist(){return this._openDocked("watchlist")}openNews(){return this._openDocked("news")}openLayouts(){return!this._destroyed&&(this._layouts?.open()??!1)}_docked(e){return!1!==this._opts.panels&&void 0!==this._opts[e]}_openDocked(e){return!(this._destroyed||!this._dock||!this._docked(e))&&(this._dock.open(e),!0)}openDateNavigation(){return this._openGoTo()}setRange(e){return this._bottombar.setRange(e)}range(){return this._bottombar.range()}_openGoTo(e){if(this._destroyed||null===Zt(this._interval))return!1;if(this._goToPanel?.isOpen())return this._goToPanel.el.focus(),!0;let t=0;return this._goToPanel=gi(Lr.get(this._opts)?.(this.context)??this.context,e,{navigate:e=>{const o=this.goTo(e);return t=this._navigation,o},cancel:()=>{t===this._navigation&&this._cancelNavigation()},onClose:()=>{this._goToPanel=null}}),!0}_openAlerts(e){return!this._destroyed&&(this._alertsPanel?.isOpen()?(this._alertsPanel.el.focus(),!0):(this._alertsPanel=ei(this.context,e,{onClose:()=>{this._alertsPanel=null}}),!0))}_openObjects(e){return!this._destroyed&&(this._dock?(this._dock.open("objects"),!0):this._objectsPanel?.isOpen()?(this._objectsPanel.el.focus(),!0):(this._objectsPanel=ja(this.context,e,{onClose:()=>{this._objectsPanel=null}}),!0))}_openDialog(e,t){const o=M(e);return null!==o&&(o(this.context,t),!0)}_publishDataContext(){const e=this.chart.getDataContext(),o=e?.symbol===this._symbol&&e.exchange===this._exchange;t.publishDataContext(this.chart,{symbol:this._symbol,exchange:this._exchange,interval:this._interval,...o&&void 0!==e.hasOpenInterest?{hasOpenInterest:e.hasOpenInterest}:{},...this._variant?{variant:this._variant}:{}})}async reload(){const e=this.dataController;if(null===e||this._destroyed)return;if(this._restoring)return await this.ready,void await this._loading;const o=e.getState().request;if(o?.symbol===this._symbol&&o.exchange===this._exchange&&o.interval===this._interval&&t.dataVariantKey(o.variant)===t.dataVariantKey(this._variant))return void await e.refresh();const n=this._opts.loading?.now?.()??Math.floor((this._opts.now??Date.now)()/1e3),a={symbol:this._symbol,exchange:this._exchange,interval:this._interval,...this._bottombar.fetchWindow(Pr(this._interval,this._opts.lookbackBars??500,n),n),...this._variant?{variant:this._variant}:{}};this._initialView=!0,this._displayedBars=null,this._series.setData([]),this._publishDataContext();const i=e.load(a);this._loading=i,await i,this._loading===i&&(this._loading=null)}async goTo(e){const t=++this._navigation;return this._navigator.cancel(),this._restoring&&await this.ready,null!==this._loading&&await this._loading,t!==this._navigation||this._destroyed?{status:"cancelled"}:this._navigator.goTo(e)}_cancelNavigation(){this._navigation++,this._navigator.cancel()}async _loadHistory(e){const t=this.dataController,o=t?.getState();if(null==t||void 0===o||o.paused||null===o.request)return"unavailable";if(!1===o.hasMore)return"exhausted";const n=t.bars()[0]?.time,a=()=>{this._anchoring||this._cancelNavigation()},i=[this.chart.on("pan",a),this.chart.on("zoom",a)];try{await t.loadMore(e)}finally{for(const e of i)e()}const r=t.getState();if("error"===r.historyStatus)throw r.historyError??new Error("Older history failed to load");if("limited"===r.historyStatus)return"limited";const s=t.bars()[0]?.time;return void 0!==s&&(void 0===n||s<n)?"loaded":!1===r.hasMore?"exhausted":"empty"}_applyData(e){if(this._destroyed||null===e.request)return;const t=this._dataState;this._dataState=e,this._dataStatus.update(e);const{symbol:o,interval:n}=e.request;if(!e.paused&&e.bars!==this._displayedBars){const t=this._series.getData(),o=this.chart.getVisibleLogicalRange(),n=null!==this.chart.seriesTransform(this._series),a=n?this.chart.primaryBars():t,i=a[Math.max(0,Math.min(a.length-1,Math.round(o.from)))],r=void 0===i?-1:a.findIndex(e=>e.time===i.time),s=e.bars[e.bars.length-1];if("live"!==e.reason||void 0===s||t[0]?.time!==e.bars[0]?.time||t.length!==e.bars.length&&t.length+1!==e.bars.length){const a=t[0],s=n&&"prepend"===e.reason&&void 0!==a?e.bars.filter(e=>e.time<a.time):[];if(s.length>0&&s.length+t.length===e.bars.length?this._series.prependData(s):this._series.setData(e.bars),this._anchoring=!0,e.bars.length>0)if(this._initialView)this._pendingView?this.chart.setVisibleLogicalRange(this._pendingView):this._keepView||this.chart.resetScale(),this._pendingView=null,this._initialView=!1,this._keepView=!1;else{const t=n?this.chart.primaryBars():e.bars,a=void 0===i?-1:n?t.filter(e=>e.time<=i.time).length-1:t.findIndex(e=>e.time===i.time),s=a<0||r<0?0:a-r;this.chart.setVisibleLogicalRange({from:o.from+s,to:o.to+s})}this._anchoring=!1}else this._series.update(s);this._displayedBars=e.bars,this._statusline?.refresh()}if(t?.status!==e.status||t.error!==e.error||["load","refresh","prepend","resume"].includes(e.reason))if("unsupported"===e.status){const t=Pt(this.context,e.request.variant,e.unsupported);this.context.status(R(this.context,"Not available from this source: {variant}",{variant:t}),"error"),this._bus.emit("data",{symbol:o,interval:n,bars:0,error:e.error?.message})}else"loading"===e.status?this.context.status(R(this.context,"Loading {symbol} {interval}",{symbol:o,interval:n})):"refreshing"===e.status?this.context.status(R(this.context,"History is stale. Refreshing {symbol} {interval}",{symbol:o,interval:n})):"error"===e.status||"stale"===e.status?(this.context.status("stale"===e.status?R(this.context,"History is stale for {symbol} {interval}",{symbol:o,interval:n}):R(this.context,"Could not load {symbol} {interval}",{symbol:o,interval:n}),"error"),e.error&&e.error!==t?.error&&(this._toasts.toast(R(this.context,"Could not load {symbol} {interval}: {error}",{symbol:o,interval:n,error:e.error.message}),"error"),this._bus.emit("data",{symbol:o,interval:n,bars:0,error:e.error.message}))):"ready"!==e.status&&"empty"!==e.status||(this.context.status(0===e.bars.length?R(this.context,"No bars for {symbol} {interval}",{symbol:o,interval:n}):R(this.context,1===e.bars.length?"{count} bar":"{count} bars",{count:e.bars.length})),this._bus.emit("data",{symbol:o,interval:n,bars:e.bars.length}))}getState(){return{version:1,symbol:this._symbol,exchange:this._exchange,interval:this._interval,chartType:this.chartType(),theme:this._themeName,...this._variant?{variant:this._variant}:{},chart:this.chart.getState(),rail:this._rail?.prefs()??null,panels:this._dock?.state(),savedBy:t.VERSION}}restoreState(e){const t=this.history.ignore(()=>Oo.call(this,e));return t.applied&&this.history.clear(),t}_scheduleSave(){$o.call(this)}_saveNow(){jo.call(this)}_inChart(){const e=this._doc.activeElement;return this._pointerInChart||null!==e&&this._chartEl.contains(e)}_followChart(){this._cleanups.push(this.chart.on("indicatorSettings",({instanceId:e})=>{this._chartEl.dataset.instanceId=e,this._openDialog("indicatorSettings",this._chartEl)}));const e=["paneAdded","paneResized","paneMoved","paneMaximized","paneCollapsed","paneRemoved","indicatorRemoved","indicatorSettings","priceAxisMoved","objects:change"];for(const t of e)this._cleanups.push(this.chart.on(t,()=>{"objects:change"===t&&this.chartType()!==this._chartType&&(this._chartType=this.chartType(),this._topbar?.refresh(),this._mobile?.refresh(),this._statusline?.refresh()),this._bus.emit("layout",{reason:t}),this._scheduleSave()}));for(const e of["draw:add","draw:remove","draw:update","draw:paste","draw:cut","alert:created","alert:updated","alert:removed","alert:triggered","alert:expired","alerts:restored","alerts:checkpoint"])this._cleanups.push(this.chart.on(e,()=>this._scheduleSave()));this._cleanups.push(this.history.subscribe(()=>this._scheduleSave())),this._cleanups.push(this.chart.on("alert:triggered",e=>{const t=e;this.context.toast(t.message??t.title,"success")})),Do.call(this)}destroy(){if(!this._destroyed){this._saveNow(),this._storage.flush(),this._storage.close(),this._destroyed=!0,this._cancelNavigation(),this._navigator.destroy(),this._goToPanel?.close(),this._quickEntry?.destroy(),this._dock?.destroy(),this.dataController?.destroy(),this._dataStatus.destroy(),this._layouts?.destroy(),this._mobile?.destroy(),this._mobile=null,this._drawbar?.destroy(),this.drawingTemplates?.destroy(),0!==this._saveTimer&&(clearTimeout(this._saveTimer),this._saveTimer=0);for(const e of this._cleanups.splice(0))e();this._topbar?.destroy(),this._rail?.destroy(),this._statusline?.destroy(),this._toasts.destroy(),this._keymap.destroy(),this.history.destroy(),this.objects.destroy(),this.alerts.destroy(),this.instrumentDrawings?.destroy(),this.draw.destroy(),this.chart.destroy(),this.root.remove(),this._bus.clear()}}}function zr(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 Mr(o,t)}const Nr="ABCDEFGHIJKLMNOP",Rr={crosshair:!1,viewport:!1,symbol:!1,interval:!1,chartType:!1,appearance:!1,drawings:!1,whenMissing:"nearest"},Fr=(e,t)=>JSON.stringify([e,t]);function Wr(e){return{crosshair:e.crosshair,viewport:e.viewport,symbol:e.symbol,interval:e.interval,appearance:e.appearance,...e.chartType?{chartType:!0}:{},...e.drawings?{drawings:!0}:{},..."hide"===e.whenMissing?{whenMissing:"hide"}:{}}}function Br(e){return{crosshair:!0===e.crosshair,viewport:!0===e.viewport,symbol:!0===e.symbol,interval:!0===e.interval,chartType:!0===e.chartType,appearance:!0===e.appearance,drawings:!0===e.drawings,whenMissing:"hide"===e.whenMissing?"hide":"nearest"}}class Ur{constructor(e={}){Object.defineProperty(this,"defaults",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"groups",{enumerable:!0,configurable:!0,writable:!0,value:[]})}create(e={}){const n=e=>!this.groups.some(t=>t.letter===e),a=void 0!==e.id&&/^[a-p]$/.test(e.id)?e.id.toUpperCase():"",i=""!==a&&n(a)?a:[...Nr].find(n);if(void 0===i)return null;let r=e.id??i.toLowerCase();for(let e=2;this.groups.some(e=>e.id===r);e++)r=`${i.toLowerCase()}${e}`;const s={id:r,letter:i,name:e.name??null,links:t.createLinkGroup({...this.defaults,...e.links}),drawings:new o.DrawingLinkGroup({enabled:!0}),view:null,keeper:null};return this.groups.push(s),s}find(e){return this.groups.find(t=>t.id===e)}join(e,o){e.group!==o&&(this.leave(e),e.group=o,o.links.add(e.member,function(e,o){const{widget:n}=e,a=n.chart;return{symbol:Fr(n.symbol(),n.exchange()),interval:n.interval(),chartType:n.chartType(),onSymbol:e=>{const[t,o]=JSON.parse(e);n.setSymbol(t,o)},onInterval:e=>!!t.isKnownInterval(e)&&(n.setInterval(e),!0),onChartType:e=>!!qt(e)&&(n.history.ignore(()=>n.setChartType(e)),n.chartType()===e),appearance:{read:()=>t.readChartSettings(a),apply:e=>n.history.ignore(()=>t.applyChartSettings(a,e))},drawings:{join:()=>o.drawings.add(a,n.draw,()=>({symbol:n.symbol(),exchange:n.exchange()||"-"})),leave:()=>o.drawings.remove(a)}}}(e,o)))}leave(e){const t=e.group;null!==t&&(e.group=null,t.links.remove(e.member),t.keeper===e&&(t.view=null,t.keeper=null))}prune(e){for(const t of this.groups.slice())e.some(e=>e.group===t)||(this.groups.splice(this.groups.indexOf(t),1),t.links.destroy(),t.drawings.destroy())}destroy(){for(const e of this.groups.splice(0))e.links.destroy(),e.drawings.destroy()}trivial(e){return 1===this.groups.length&&null===this.groups[0].name&&e.every(e=>e.group===this.groups[0])}optionsOf(e){return e?.group?.links.options()??{...Rr}}sync(e,t){if(this.trivial(e))return Wr(this.groups[0].links.options());const o=this.groups.find(t=>e.every(e=>e.group===t));return{...Wr(o?.links.options()??Rr),groups:this.groups.filter(t=>e.some(e=>e.group===t)).map(e=>({id:e.id,name:t(e),...Wr(e.links.options())}))}}}function qr(e,t){return{get:o=>t.get(e)?.get(o)??null,set:(o,n)=>{let a=t.get(e);void 0===a&&t.set(e,a=new Map),a.set(o,JSON.parse(JSON.stringify(n)))},remove:o=>{t.get(e)?.delete(o)}}}const Kr=(e,t,o)=>Number.isInteger(e)&&e>=t&&e<=o;function Gr(e){if(!(y(e)&&y(e.layout)&&Array.isArray(e.layout.slots)&&Array.isArray(e.panes)&&y(e.sync)))return"not a workspace payload";const{rows:o,columns:n,slots:a}=e.layout;if(!Kr(o,1,8)||!Kr(n,1,8)||!Kr(e.panes.length,1,16))return"unsupported grid size";for(const[t,a]of[[e.layout.rowWeights,o],[e.layout.columnWeights,n]])if(!(void 0===t||Array.isArray(t)&&t.length===a&&t.every(e=>"number"==typeof e&&e>0&&e<=1e3)))return"invalid track weights";const i=new Set(t.registeredIndicators().map(e=>e.id)),r=new Set;for(const o of e.panes){if(!y(o)||"string"!=typeof o.id||""===o.id||r.has(o.id))return"invalid or duplicate chart id";if(r.add(o.id),"string"!=typeof o.symbol||"string"!=typeof o.exchange||!y(o.chart)||!["string","undefined"].includes(typeof o.historyPeriod))return`${o.id}: invalid chart`;if(!t.isKnownInterval(o.interval))return`${o.id}: unknown interval ${String(o.interval)}`;if(!qt(o.chartType))return`${o.id}: unknown chart type ${String(o.chartType)}`;if(Array.isArray(o.comparisons)&&o.comparisons.length>0)return`${o.id}: comparison symbols are not supported in a grid chart`;for(const e of Array.isArray(o.chart.indicators)?o.chart.indicators:[])if(!i.has(e?.indicatorId))return`${o.id}: unavailable study ${String(e?.indicatorId)}`}const s=new Set,l=new Set;for(const e of a){const t=e?.rowSpan??1,a=e?.columnSpan??1;if(!y(e)||!r.has(e.paneId)||s.has(e.paneId)||!Kr(e.row,0,o-1)||!Kr(e.column,0,n-1)||!Kr(t,1,o-e.row)||!Kr(a,1,n-e.column))return"invalid layout slot";s.add(e.paneId);for(let o=e.row;o<e.row+t;o++)for(let t=e.column;t<e.column+a;t++){if(l.has(o*n+t))return"layout slots overlap";l.add(o*n+t)}}return s.size!==r.size?"every chart needs one layout slot":r.has(e.activePaneId)?function(e){const t=e.sync,o=e.panes,n=[];if(void 0===t.groups)n.push({channels:t,panes:o});else{if(!Array.isArray(t.groups)||t.groups.length>16)return"invalid link groups";const e=new Set;for(const a of t.groups){if("object"!=typeof a||null===a||"string"!=typeof a.id||""===a.id||e.has(a.id))return"invalid or duplicate link group id";e.add(a.id),n.push({channels:a,panes:o.filter(e=>e.linkGroup===a.id)})}for(const t of o)if(void 0!==t.linkGroup&&!e.has(t.linkGroup))return`${t.id}: undeclared link group ${String(t.linkGroup)}`}for(const{channels:e,panes:t}of n){const o=e=>new Set(t.map(e)).size>1;if(!0===e.symbol&&o(e=>Fr(e.symbol,e.exchange)))return"linked symbols differ between charts";if(!0===e.interval&&o(e=>e.interval))return"linked intervals differ between charts";if(!0===e.chartType&&o(e=>e.chartType))return"linked chart types differ between charts"}return""}(e):"the active chart is missing"}const Vr=(e,t,o=1,n=1)=>({row:e,column:t,rowSpan:o,columnSpan:n}),Hr=e=>Array.from({length:e},()=>1);function Jr(e,t){const o=[];for(let n=0;n<e;n++)for(let e=0;e<t;e++)o.push(Vr(n,e));return{rows:e,columns:t,slots:o,rowWeights:Hr(e),columnWeights:Hr(t)}}function Zr(e,t,o,n=Hr(e),a=Hr(t)){return{rows:e,columns:t,slots:o,rowWeights:n,columnWeights:a}}const Yr=(e,t)=>Zr(2,e,[Vr(0,0,1,e),...Array.from({length:e},(e,t)=>Vr(1,t))],t,Hr(e));function Qr(e){const t=[Vr(0,0,e-1,e-1)];for(let o=0;o<e-1;o++)t.push(Vr(o,e-1));for(let o=0;o<e;o++)t.push(Vr(e-1,o));return Zr(e,e,t)}const Xr={"1x1":Jr(1,1),"1x2":Jr(1,2),"2x1":Jr(2,1),"1x3":Jr(1,3),"3x1":Jr(3,1),"left-2":Zr(2,2,[Vr(0,0,2),Vr(0,1),Vr(1,1)]),"right-2":Zr(2,2,[Vr(0,0),Vr(0,1,2),Vr(1,0)]),"top-2":Zr(2,2,[Vr(0,0,1,2),Vr(1,0),Vr(1,1)]),"bottom-2":Zr(2,2,[Vr(0,0),Vr(0,1),Vr(1,0,1,2)]),"2x2":Jr(2,2),"1x4":Jr(1,4),"4x1":Jr(4,1),"left-3":(es=3,ts=[2,1],Zr(es,2,[Vr(0,0,es),...Array.from({length:es},(e,t)=>Vr(t,1))],Hr(es),ts)),"top-3":Yr(3,[2,1]),"left-4":Zr(2,3,[Vr(0,0,2),Vr(0,1),Vr(0,2),Vr(1,1),Vr(1,2)],Hr(2),[2,1,1]),"top-4":Yr(4,[2,1]),"2x3":Jr(2,3),"3x2":Jr(3,2),"corner-5":Qr(3),"2x4":Jr(2,4),"4x2":Jr(4,2),"corner-7":Qr(4),"3x3":Jr(3,3),"3x4":Jr(3,4),"4x3":Jr(4,3),"4x4":Jr(4,4)};var es,ts;function os(e){return"string"==typeof e&&Object.prototype.hasOwnProperty.call(Xr,e)}const ns=(e,t,o)=>{let n=0;for(let a=t;a<t+o;a++)n+=e[a];return n},as="grid",is="grid-drawings";function rs(e){e.held=!1,e.storage.enabled&&!e.destroyed&&(0!==e.saveTimer&&clearTimeout(e.saveTimer),e.saveTimer=setTimeout(()=>ls(e),250))}function ss(e){e.held=!1,!e.storage.enabled||e.destroyed||e.saveQueued||(e.saveQueued=!0,queueMicrotask(()=>{e.saveQueued=!1,ls(e)}))}function ls(e){if(0!==e.saveTimer&&(clearTimeout(e.saveTimer),e.saveTimer=0),!e.storage.enabled||e.destroyed||e.held||e.restoring||null===e.active)return;const t=e.storage.set(as,e.grid.getWorkspace()),o={};for(const t of e.cells){const n=e.drawings.get(t.id);void 0!==n&&n.size>0&&(o[t.id]=Object.fromEntries(n))}const n=e.storage.set(is,{version:1,charts:o}),a=!t||!n;a&&!e.saveRefused&&e.active.widget.context.status(R(e.text,"The chart layout could not be saved"),"error"),e.saveRefused=a}function cs(e){if(!1!==e.options.shortcutsEditor){e.sharing=!0;try{for(const t of e.cells)t.widget.context.keymap.applyOverrides(e.chords)}finally{e.sharing=!1}}}function ds(e,t){t&&0===e.saveTimer||ls(e),e.storage.flush(),e.saved?.flush()}function us(e,t,o){const{storage:n,options:a}=e;if(e.chords=n.get(fe),e.given)return cs(e),void ss(e);const i=n.get(as);if(e.restored=null===i?null:o(i,function(e){const t=new Map;if(!y(e)||1!==e.version||!y(e.charts))return t;for(const[o,n]of Object.entries(e.charts)){if(!y(n))continue;const e=new Map;for(const[t,o]of Object.entries(n))y(o)&&e.set(t,o);t.set(o,e)}return t}(n.get(is))),!0!==e.restored?.applied){if(t){if(cs(e),void 0!==a.symbol)for(const t of e.cells)t.widget.setSymbol(a.symbol,a.exchange)}else e.grid.setPreset(a.preset??"1x1");null!==e.restored&&(e.held=!0,e.grid.active().widget.context.toast(R(e.text,"The saved layout could not be restored: {error}",{error:e.restored.reason??""}),"error"))}}const ps=e=>Math.round(1e4*e)/1e4,hs=e=>e.map(e=>`minmax(0,${e}fr)`).join(" 4px "),ms=e=>e.compact||e.maxed;function gs(e){for(const t of e.cells){const e=t.element.getBoundingClientRect();e.width>0&&e.height>0&&(t.element.dataset.dense=String(e.width<560||e.height<340))}}function fs(e,t){const o="column"===t.dataset.axis?e.colW:e.rowW,n=Number(t.dataset.index);t.setAttribute("aria-valuenow",String(Math.round(o[n]/(o[n]+o[n+1])*100)))}function bs(e,t,o,n,a=!1){const i=("column"===t?e.colW:e.rowW).slice(),r=i[o]+i[o+1],s=ps(Math.min(.85*r,Math.max(.15*r,n)));s!==i[o]&&(i[o]=s,i[o+1]=ps(r-s),"column"===t?(e.colW=i,e.body.style.gridTemplateColumns=hs(i)):(e.rowW=i,e.body.style.gridTemplateRows=hs(i)),e.splits.forEach(t=>fs(e,t)),gs(e),a?rs(e):ss(e),e.bus.emit("layout",{reason:"weights"}))}function vs(e,t,o,n){const{doc:a,body:i}=e,r="column"===t,s=u(a,"div","oac-grid__split",{role:"separator",tabindex:"0","aria-orientation":r?"vertical":"horizontal","aria-label":R(e.text,r?"Resize columns {first} and {second}":"Resize rows {first} and {second}",{first:o+1,second:o+2}),"aria-valuemin":"15","aria-valuemax":"85"});s.dataset.axis=t,s.dataset.index=String(o),s.style.gridArea=n;const l=()=>r?e.colW:e.rowW;s.addEventListener("pointerdown",n=>{if(0!==n.button)return;n.preventDefault();const a=i.getBoundingClientRect(),c=l(),d=(r?a.width:a.height)-4*(c.length-1),u=c.reduce((e,t)=>e+t,0),p=r?n.clientX:n.clientY,h=c[o];s.setPointerCapture?.(n.pointerId),s.classList.add("is-drag");const m=n=>{d>0&&bs(e,t,o,h+((r?n.clientX:n.clientY)-p)/d*u,!0)},g=()=>{0!==e.saveTimer&&ls(e),s.classList.remove("is-drag"),s.removeEventListener("pointermove",m),s.removeEventListener("pointerup",g),s.removeEventListener("pointercancel",g)};s.addEventListener("pointermove",m),s.addEventListener("pointerup",g),s.addEventListener("pointercancel",g)}),s.addEventListener("keydown",n=>{const a=(r?["ArrowLeft","ArrowRight"]:["ArrowUp","ArrowDown"]).indexOf(n.key);if(a<0)return;n.preventDefault(),n.stopPropagation();const i=l();bs(e,t,o,i[o]+(2*a-1)*(i[o]+i[o+1])*(n.shiftKey?.2:.05))}),s.addEventListener("dblclick",()=>{const n=l();bs(e,t,o,(n[o]+n[o+1])/2)}),s.hidden=ms(e),i.appendChild(s),e.splits.push(s),fs(e,s)}function ws(e,t){const o="column"===t,n=o?e.rows:e.cols;for(let a=0;a<(o?e.cols:e.rows)-1;a++){let i=-1;for(let r=0;r<=n;r++){const s=r<n&&!e.cells.some(e=>{const[t,n,i,s]=o?[e.column,e.columnSpan,e.row,e.rowSpan]:[e.row,e.rowSpan,e.column,e.columnSpan];return t<=a&&t+n>a+1&&i<=r&&i+s>r});if(s&&i<0&&(i=r),!s&&i>=0){const[n,s,l]=[2*i+1,2*r,2*a+2];vs(e,t,a,(o?[n,l,s,l+1]:[l,n,l+1,s]).join(" / ")),i=-1}}}}const ys=e=>e.cells.length<2||!ms(e)?null:R(e.text,e.compact?"The grid shows one chart at a time at this width":"Show every chart to capture them together"),_s=(e,t,o="info")=>{e.active?.widget.context.toast(t,o)},xs=e=>{const{text:t}=e;e.grid.downloadScreenshot()?_s(e,R(t,"Saved a PNG of every chart")):_s(e,R(t,"The image could not be saved: {error}",{error:ys(e)??R(t,"This runtime cannot save files")}),"error")},ks=e=>{const t=e.grid.takeScreenshot();null!==t&&pn(e.text,t,R(e.text,"Every chart copied"),(t,o)=>_s(e,t,o))};function Cs(e){if(e.destroyed||null!==ys(e))return null;const{doc:t}=e,o=e.body.getBoundingClientRect(),n=e=>{const t=e?.getBoundingClientRect();return void 0===t?{left:0,top:0,width:0,height:0}:{left:t.left-o.left,top:t.top-o.top,width:t.width,height:t.height}},a=e.cells.map(e=>({cell:n(e.element),chart:n(e.widget.root.querySelector(".oac-chart")),image:e.widget.chart.takeScreenshot(),label:`${e.widget.symbol()} ${e.widget.interval()}`.trim()})),i=e.options.pixelRatio?.()??t.defaultView?.devicePixelRatio??1,r=Nn(Ir(e.theme).theme,Ir(e.theme).name),s=e=>r[Sn+e];return function(e,t,o,n,a){const i=e.createElement("canvas"),r=e=>Math.round(e*o);i.width=Math.max(1,r(t.width)),i.height=Math.max(1,r(t.height));const s=i.getContext("2d");if(null===s)return i;s.fillStyle=a.gutter,s.fillRect(0,0,i.width,i.height);for(const e of n){const{cell:t,chart:o}=e;s.fillStyle=a.panel,s.fillRect(r(t.left),r(t.top),r(t.left+t.width)-r(t.left),r(t.top+t.height)-r(t.top));const n=o.top-t.top;n>=14&&""!==e.label&&(s.fillStyle=a.text,s.font=`600 ${r(12)}px ${a.font}`,s.textBaseline="middle",s.fillText(e.label,r(t.left+8),r(t.top+n/2),r(Math.max(0,t.width-16)))),null===e.image||e.image.width<=1||o.width<=0||o.height<=0||s.drawImage(e.image,r(o.left),r(o.top),r(o.left+o.width)-r(o.left),r(o.top+o.height)-r(o.top))}return i}(t,{width:o.width,height:o.height},function(e,t){for(const o of e)if(!(null===o.image||o.image.width<=1||o.chart.width<=0))return t>0&&Math.abs(o.image.width-o.chart.width*t)<=1?t:o.image.width/o.chart.width;return t>0?t:1}(a,i),a,{gutter:s("bd-soft"),panel:s("panel"),text:s("tx"),font:Mn})}const Ss=(e,t)=>dn(e.doc,()=>e.grid.takeScreenshot(),t??(e=>yt("charts",e.preset??`${e.rows}x${e.cols}`)+".png")(e));function As(e,t){const n=u(e,"span","oac-grid__chip",{"aria-hidden":"true"});return null===t?(n.dataset.group="none",n.innerHTML=o.chromeIconSvg("unlink")):(n.dataset.group=t.letter,n.textContent=t.letter),n}function Ts(e,t,o){const n="left"===o||"right"===o,[a,i]=n?[t.row,t.rowSpan]:[t.column,t.columnSpan],r=e=>Math.abs((n?e.row:e.column)-a);return e.filter(e=>e!==t&&(e=>"right"===o?e.column===t.column+t.columnSpan:"left"===o?e.column+e.columnSpan===t.column:"down"===o?e.row===t.row+t.rowSpan:e.row+e.rowSpan===t.row)(e)&&(e=>{const[t,o]=n?[e.row,e.rowSpan]:[e.column,e.columnSpan];return t<a+i&&t+o>a})(e)).sort((e,t)=>r(e)-r(t))[0]}const Es={left:"ArrowLeft",right:"ArrowRight",up:"ArrowUp",down:"ArrowDown"},Ls={left:"Make the chart to the left active",right:"Make the chart to the right active",up:"Make the chart above active",down:"Make the chart below active"},Os={left:"Swap with the chart to the left",right:"Swap with the chart to the right",up:"Swap with the chart above",down:"Swap with the chart below"};function Is(e){const{doc:t,body:o,root:n}=e;let a=null;const i=t=>{const o=t;if(null===o||"function"!=typeof o.closest||null!==o.closest('button, input, select, textarea, a, label, [role="button"], [role="radio"], [role="tab"], [contenteditable="true"]'))return;const n=o.closest(".oac-topbar");if(null===n)return;const a=e.cells().find(e=>e.element.contains(n));return void 0===a?void 0:{cell:a,head:n}},r=o=>{const i=a;if(null!==i&&(a=null,t.removeEventListener("pointermove",s,!0),t.removeEventListener("pointerup",l,!0),t.removeEventListener("pointercancel",c,!0),t.removeEventListener("keydown",d,!0),i.moving)){i.over?.element.removeAttribute("data-drop"),i.cell.element.removeAttribute("data-dragging"),n.removeAttribute("data-dragging");try{i.head.releasePointerCapture?.(i.pointer)}catch{}o&&null!==i.over&&e.swap(i.cell,i.over)}},s=t=>{const o=a;if(null!==o&&t.pointerId===o.pointer){if(!o.moving){if(Math.hypot(t.clientX-o.x,t.clientY-o.y)<6)return;if(!e.enabled())return void r(!1);o.moving=!0,n.setAttribute("data-dragging","true"),o.cell.element.setAttribute("data-dragging","true");try{o.head.setPointerCapture?.(o.pointer)}catch{}}var i;t.preventDefault(),i=e.cells().find(e=>e!==o.cell&&((e,t,o)=>{const n=e.element.getBoundingClientRect();return n.width>0&&t>=n.left&&t<n.left+n.width&&o>=n.top&&o<n.top+n.height})(e,t.clientX,t.clientY))??null,null!==a&&(a.over?.element.removeAttribute("data-drop"),a.over=i,i?.element.setAttribute("data-drop","true"))}},l=e=>{null!==a&&e.pointerId===a.pointer&&r(!0)},c=()=>r(!1),d=e=>{"Escape"===e.key&&null!==a&&(a.moving&&(e.preventDefault(),e.stopPropagation()),r(!1))},u=o=>{if(0!==o.button||null!==a||!e.enabled())return;const n=i(o.target);void 0!==n&&(a={...n,x:o.clientX,y:o.clientY,pointer:o.pointerId,moving:!1,over:null},t.addEventListener("pointermove",s,!0),t.addEventListener("pointerup",l,!0),t.addEventListener("pointercancel",c,!0),t.addEventListener("keydown",d,!0))},p=t=>{const o=i(t.target);void 0!==o&&e.toggleMaximize(o.cell)};return o.addEventListener("pointerdown",u),o.addEventListener("dblclick",p),()=>{r(!1),o.removeEventListener("pointerdown",u),o.removeEventListener("dblclick",p)}}function Ps(e,t,o,n,a=!1){return 0===o||t<0&&!a?-1:e===n[1]?(t+1)%o:e===n[0]?t<0?o-1:(t-1+o)%o:"Home"===e?0:"End"===e?o-1:-1}const $s=V(()=>Promise.resolve().then(function(){return Gl})),js=V(()=>Promise.resolve().then(function(){return Xl})),Ds=["preset","links","compactWidth","persist","storage","drawingStore","toolbar","presets"],Ms=e=>Array.from({length:e},()=>1);const zs=(e,t,o)=>e.bus.emit(t,o);function Ns(e){if(null===e.chromeLayer){const t=u(e.doc,"div","oac-widget oac-grid__overlay");t.dataset.theme=Ir(e.theme).name,e.root.appendChild(t);const o=S(t,e.doc);e.chromeLayer={el:t,overlays:o,tips:A(t,o.layer,e.doc)}}return e.chromeLayer}function Rs(e){const t=Ir(e.theme);e.root.dataset.theme=t.name;for(const o of[e.chromeLayer?.el,e.barEl,e.footEl])null!=o&&(o.dataset.theme=t.name);Rn(e.root,Nn(t.theme,t.name))}const Fs=(e,t,o)=>Object.create(t,{root:{value:Ns(e).el},openOverlay:{value:(t,n={})=>Ns(e).overlays.open(t,{...n,anchor:n.anchor??o?.()??void 0})}});function Ws(e){const{doc:t,tabs:o}=e;for(const t of e.cells)t.element.hidden=ms(e)&&t!==e.active;for(const t of e.splits)t.hidden=ms(e);o.hidden=!ms(e)||e.cells.length<2;const n=e=>`${e.widget.symbol()} ${e.widget.interval()}`.trim();o.replaceChildren(...o.hidden?[]:e.cells.map((o,a)=>{const i=u(t,"button","oac-grid__tab",{type:"button",role:"tab","aria-selected":String(o===e.active),tabindex:o===e.active?"0":"-1"});return i.textContent=n(o),e.cells.some(e=>e!==o&&n(e)===n(o))&&i.setAttribute("aria-label",`${n(o)} (${a+1})`),i.addEventListener("click",()=>e.grid.setActive(o.id,{focus:!0})),i})),e.bar?.refresh()}function Bs(e){for(const t of e.cells)t.element.dataset.active=String(t===e.active),t===e.active?t.element.setAttribute("aria-current","true"):t.element.removeAttribute("aria-current");Ws(e)}function Us(e){if(e.destroyed)return;gs(e);const t=e.root.getBoundingClientRect().width,o=e.options.compactWidth??640,n=o>0&&t>0&&t<=o;e.root.dataset.compact=String(n),n!==e.compact&&(e.compact=n,Ws(e),gs(e),zs(e,"layout",{reason:"compact"}))}function qs(e,t){return t!==e.maxed&&(e.maxed=t,null!==e.active&&(e.active.hold=!0),e.root.dataset.maximized=String(t),Ws(e),gs(e),zs(e,"layout",{reason:"maximize"}),!0)}function Ks(e){return e.cells.length<2?R(e.text,"There is only one chart"):e.compact?R(e.text,"The grid shows one chart at a time at this width"):null}function Gs(e,t=e.active){null!==t&&(e.maxed&&t===e.active?e.grid.restore():e.grid.maximize(t.id))}const Vs=(e,t)=>t.name??R(e.text,"Group {letter}",{letter:t.letter}),Hs=e=>{return t=e.links,o=e.cells,n=t=>Vs(e,t),t.groups.map(e=>({id:e.id,name:n(e),letter:e.letter,links:e.links.options(),cells:o.filter(t=>t.group===e).map(e=>e.id)}));var t,o,n},Js=(e,t)=>Hs(e).find(e=>e.id===t?.id)??null;function Zs(e){const{doc:t,text:o}=e,n=e.links.trivial(e.cells);e.cells.forEach((a,i)=>{const r=i+1;if(a.element.setAttribute("aria-label",n?R(o,"Chart {index}",{index:r}):null===a.group?R(o,"Chart {index}, not linked",{index:r}):R(o,"Chart {index}, linked in {name}",{index:r,name:Vs(e,a.group)})),n)return a.mark?.remove(),void(a.mark=null);if(null===a.mark){const o=a.mark=u(t,"button","oac-grid__mark",{type:"button","aria-haspopup":"menu"});o.addEventListener("click",()=>{e.grid.setActive(a.id),e.barHost.openMenu("link",o)});const n=a.widget.root.querySelector(".oac-topbar");null!==n?n.prepend(o):(o.classList.add("oac-grid__mark--float"),a.element.appendChild(o))}a.mark.replaceChildren(As(t,Js(e,a.group)));const s=null===a.group?R(o,"Not linked"):R(o,"Linked in {name}",{name:Vs(e,a.group)});a.mark.setAttribute("aria-label",s),a.mark.title=s,null===a.group?delete a.mark.dataset.group:a.mark.dataset.group=a.group.letter}),e.bar?.refresh()}function Ys(e){e.links.prune(e.cells),Zs(e),ss(e),zs(e,"links",e.grid.linkOptions())}function Qs(e){const{doc:t,body:o}=e;o.style.gridTemplateColumns=hs(e.colW),o.style.gridTemplateRows=hs(e.rowW);for(const t of e.splits.splice(0))t.remove();const n=t.activeElement;e.cells.forEach((e,t)=>{e.element.style.gridArea=`${2*e.row+1} / ${2*e.column+1} / ${2*(e.row+e.rowSpan)} / ${2*(e.column+e.columnSpan)}`;const n=o.children[t]??null;n!==e.element&&o.insertBefore(e.element,n)}),null!==n&&n!==t.activeElement&&e.cells.some(e=>e.element.contains(n))&&n.focus({preventScroll:!0}),ws(e,"column"),ws(e,"row"),e.root.dataset.single=String(1===e.cells.length),Zs(e),Bs(e),gs(e)}function Xs(e,t,o,n,a,i){const{footEl:r}=e,s=u(e.doc,"div","oac-grid__cell",{role:"group"});s.dataset.paneId=t,n.appendChild(s);const{historyPeriod:l}=o,c=e.options.feed,d={id:t,element:s,row:0,column:0,rowSpan:1,columnSpan:1,offs:[],span:0,hold:!1,historyPeriod:l,group:null,mark:null,type:""},p={...e.cellOptions,theme:a,symbol:e.restoring?void 0:o.symbol,exchange:o.exchange,interval:o.interval,variant:o.variant,chartType:o.chartType,keyboardRoute:()=>function(e,t){if(t!==e.active)return!1;const o=e.doc.activeElement;return null===o||o===e.doc.body||o===e.doc.documentElement?!!e.pointerIn||void 0:!(e.root.contains(o)&&!e.cells.some(e=>e.element.contains(o)))&&void 0}(e,d),feed:"function"==typeof c?c({id:t,historyPeriod:l}):c,drawingStore:qr(t,i)};null!==r&&Lr.set(p,t=>Fs(e,t,()=>r.querySelector(".oac-bottombar__goto")));try{d.widget=zr(s,p)}catch(e){throw s.remove(),e}return d.type=d.widget.chartType(),Object.defineProperty(d,"linkGroup",{enumerable:!0,get:()=>d.group?.id??null}),d}const el=e=>{const t=e.widget.chart.getVisibleLogicalRange();return t.to-t.from},tl=e=>{const t=e.group;if(null===t)return;const o=e.widget.chart,n=o.getVisibleLogicalRange(),a=o.dataLayer,i=a.indexToTimeFloat(n.from),r=a.indexToTimeFloat(n.to);r>i&&(t.view={from:i,to:r},t.keeper=e)},ol=e=>{null!==e&&(e.view=null,e.keeper=null)};function nl(e,t){const{widget:o}=t,n=o.chart;!function(e,t){if(!1===e.options.shortcutsEditor)return;const o=t.widget.context.keymap;o.applyOverrides(e.chords),t.offs.push(o.onChange(()=>{if(!e.sharing){e.sharing=!0;try{const n=o.overrides();e.chords=n;for(const o of e.cells)o!==t&&o.widget.context.keymap.applyOverrides(n);0===Object.keys(n).length?e.storage.remove(fe):e.storage.set(fe,n)}finally{e.sharing=!1}}}))}(e,t);let a=!1,i=!1;const r=()=>a||e.syncing||i;t.offs.push(n.on("data:update",()=>{a=!0,queueMicrotask(()=>{a=!1}),t.span=el(t),t===t.group?.keeper&&tl(t)})),t.member=function(e,t,o){return{on:(o,n)=>e.on(o,"pan"===o||"zoom"===o?e=>{t()||n(e)}:"symbol"===o?e=>{const t=e;n({symbol:Fr(t.symbol,t.exchange)})}:n),getVisibleLogicalRange:()=>e.getVisibleLogicalRange(),setVisibleLogicalRange:t=>o(()=>e.setVisibleLogicalRange(t)),get dataLayer(){return e.dataLayer},get isDestroyed(){return e.isDestroyed},panes:()=>e.panes(),addPrimitive:(t,o)=>e.addPrimitive(t,o),removePrimitive:t=>e.removePrimitive(t),setLinkedCrosshairIndex:t=>e.setLinkedCrosshairIndex(t)}}(n,r,e=>{i=!0;try{e()}finally{i=!1}});const s=()=>{t===t.group?.keeper&&ol(t.group),Ws(e),ss(e)},l=()=>{const o=!r();t.span=el(t),(o||t===t.group?.keeper)&&tl(t),!o&&e.held||rs(e)},c=()=>ss(e),d=()=>rs(e);t.offs.push(o.on("interval",({interval:e})=>t.group?.links.setInterval(t.member,e)),o.on("theme",({chartTheme:t})=>{e.themeSync||e.grid.setTheme(t)}),o.on("symbol",s),o.on("interval",s),o.on("variant",s),o.on("layout",()=>{const e=o.chartType();e!==t.type&&(t.type=e,t.group?.links.setChartType(t.member,e))}),o.on("layout",d),n.on("pan",l),n.on("zoom",l),n.on("resize",()=>function(e,t){const o=t.widget.chart,n=o.getVisibleLogicalRange(),a=o.dataLayer,i=t.span,r=t.group,s=null!==r&&r.links.options().viewport?r.view:null,l=t.hold&&i>0;if(t.hold=!1,l||null!==s&&(i>0||t!==r?.keeper)){e.syncing=!0;try{o.setVisibleLogicalRange(i>0||null===s?{from:n.to-i,to:n.to}:{from:a.timeToIndexFloat(s.from),to:a.timeToIndexFloat(s.to)})}finally{e.syncing=!1}}t.span=el(t),(t===r?.keeper||null!==s&&0===i)&&tl(t)}(e,t)),...function(e){const t=e.keymap,o=e.text,n="Chart grid",a=[t.register("Alt+Enter",()=>e.toggleMaximize(),"widget",{label:R(o,"Maximize or restore the chart"),group:n}),t.register("Escape",()=>!!e.maximized()&&(e.restore(),!0),"widget",{label:R(o,"Restore the grid"),group:n,layered:!0})];for(const i of["left","right","up","down"])a.push(t.register(`Alt+Shift+${Es[i]}`,()=>e.focus(i),"widget",{label:R(o,Ls[i]),group:n}),t.register(`Mod+Shift+${Es[i]}`,()=>e.swap(i),"widget",{label:R(o,Os[i]),group:n}));return a}({keymap:o.context.keymap,text:e.text,maximized:()=>e.maxed,toggleMaximize:()=>!(!e.maxed&&null!==Ks(e))&&(Gs(e,t),!0),restore:()=>qs(e,!1),focus:o=>{const n=Ts(e.cells,t,o);return void 0!==n&&(queueMicrotask(()=>{e.destroyed||e.grid.setActive(n.id,{focus:!0})}),!0)},swap:o=>{const n=Ts(e.cells,t,o);return void 0!==n&&!ms(e)&&(e.grid.swap(t.id,n.id),!0)}}));for(const e of["draw:add","draw:remove","alert:created","alert:removed"])t.offs.push(n.on(e,c));for(const e of["draw:update","alert:updated","objects:change"])t.offs.push(n.on(e,d))}function al(e,t){t===t.group?.keeper&&ol(t.group);for(const e of t.offs.splice(0))e();void 0!==t.member&&e.links.leave(t),t.widget.destroy(),t.element.remove()}function il(e,t){const o=e.cells.find(e=>e.element.contains(t));void 0!==o&&e.grid.setActive(o.id)}const rl=(e,t)=>e.active?.group===t?e.active:e.cells.find(e=>e.group===t);function sl(e,t,o){const n=rl(e,t);void 0!==n&&(o.symbol&&t.links.setSymbol(n.member,Fr(n.widget.symbol(),n.widget.exchange())),o.interval&&t.links.setInterval(n.member,n.widget.interval()),o.chartType&&t.links.setChartType(n.member,n.widget.chartType()))}function ll(e,t,o){o.viewport&&!t.links.options().viewport&&ol(t),sl(e,t,o),t.links.setOptions(o)}function cl(e,t,o){if(e.destroyed)return{applied:!1,reason:"the grid is destroyed"};const n=Gr(t);if(""!==n)return{applied:!1,reason:n};const{links:a}=e,i=t.panes.find(e=>e.id===t.activePaneId)?.settings?.[Wo],r="dark"===i||"light"===i?i:e.theme,s=e.doc.createElement("div"),l=[];try{for(const n of t.layout.slots.slice().sort((e,t)=>e.row-t.row||e.column-t.column)){const a=t.panes.find(e=>e.id===n.paneId),i=Xs(e,a.id,a,s,r,o);l.push(i),Object.assign(i,{row:n.row,column:n.column,rowSpan:n.rowSpan??1,columnSpan:n.columnSpan??1});const c=Ho(i.widget,a,!1);if(!c.applied)throw new Error(`${a.id}: ${c.reason??"the chart state could not be restored"}`);i.type=i.widget.chartType()}}catch(t){return l.reverse().forEach(t=>al(e,t)),{applied:!1,reason:t instanceof Error?t.message:String(t)}}e.maxed=!1,e.root.dataset.maximized="false",e.cells.forEach(t=>al(e,t)),a.destroy(),e.cells=l,e.drawings=o;const{layout:c,sync:d}=t;e.rows=c.rows,e.cols=c.columns,e.rowW=c.rowWeights?.slice()??Ms(e.rows),e.colW=c.columnWeights?.slice()??Ms(e.cols),e.preset=c.preset??null,e.theme=r,Rs(e),e.active=l.find(e=>e.id===t.activePaneId),l.forEach(t=>nl(e,t));const u=void 0===d.groups?[{id:void 0,name:null,channels:Br(d),panes:t.panes}]:d.groups.map(e=>({id:e.id,name:e.name,channels:Br(e),panes:t.panes.filter(t=>t.linkGroup===e.id)}));for(const t of u){const o=a.create({id:t.id,name:t.name,links:Rr});o.name===R(e.text,"Group {letter}",{letter:o.letter})&&(o.name=null);for(const e of t.panes)a.join(l.find(t=>t.id===e.id),o);sl(e,o,{symbol:!0,interval:!0,chartType:!0}),o.links.setOptions(t.channels)}return a.prune(e.cells),Qs(e),ss(e),zs(e,"layout",{reason:"workspace"}),zs(e,"active",{id:e.active.id}),zs(e,"links",e.grid.linkOptions()),{applied:!0}}const dl={"1x1":"One chart","1x2":"Two columns","2x1":"Two rows","1x3":"Three columns","3x1":"Three rows","left-2":"Large left, two on the right","right-2":"Large right, two on the left","top-2":"Large top, two below","bottom-2":"Large bottom, two above","2x2":"Two by two","1x4":"Four columns","4x1":"Four rows","left-3":"Large left, three on the right","top-3":"Large top, three below","left-4":"Large left, four on the right","top-4":"Large top, four below","2x3":"Two rows of three","3x2":"Three rows of two","corner-5":"Large corner, five around","2x4":"Two rows of four","4x2":"Four rows of two","corner-7":"Large corner, seven around","3x3":"Three by three","3x4":"Three rows of four","4x3":"Four rows of three","4x4":"Four by four"};function ul(e,t){return R(e,dl[t])}function pl(e,t){return 1===t?R(e,"1 chart"):R(e,"{count} charts",{count:t})}const hl="entries",ml="copied:",gl="oac-widget-store:";function fl(e,t,o){const n=void 0===o.journal?C():o.journal,a=void 0===o.migrateFrom?wl():o.migrateFrom;let i=null,r=!1;const s=new Set;let l=null;const c=(e,t)=>{for(const o of[...s])try{o(e,t)}catch{}},d=(e,o)=>{c(e,o);const n=bl();if(null!==n)try{if(null!==l)return void l.postMessage({key:e,value:o});const a=new n(gl+t);a.postMessage({key:e,value:o}),a.close()}catch{}},u=()=>{null!==l&&(l.onmessage=null,l.close(),l=null)},p=async(o,n)=>{const a=await(()=>{if(r)return Promise.reject(new Error("The widget storage is closed"));if(null!==i)return i;const o=new Promise((n,a)=>{const s=e.open(t,1);s.onupgradeneeded=()=>{s.result.objectStoreNames.contains(hl)||s.result.createObjectStore(hl)},s.onblocked=()=>a(new Error("The widget storage is held open by another tab")),s.onerror=()=>a(s.error??new Error("The widget storage could not be opened")),s.onsuccess=()=>{const e=s.result;if(r)return e.close(),void a(new Error("The widget storage is closed"));e.onversionchange=()=>{e.close(),i===o&&(i=null)},e.onclose=()=>{i===o&&(i=null)},n(e)}}).catch(e=>{throw i===o&&(i=null),e});return i=o,o})();return new Promise((e,t)=>{const i=a.transaction(hl,o);let r;i.oncomplete=()=>e(r),i.onabort=()=>t(i.error??new Error("The widget storage transaction was aborted")),n(i.objectStore(hl),e=>{r=e})})};return{journal:n,entries:e=>p("readwrite",(t,o)=>{const n=[];o(n);const i=function(e){const t=globalThis.IDBKeyRange;try{return void 0===t?null:t.bound(e,e+"￿")}catch{return null}}(e),r=null===i?t.openCursor():t.openCursor(i);r.onsuccess=()=>{const o=r.result;if(null!==o)return"string"==typeof o.key&&o.key.startsWith(e)&&"string"==typeof o.value&&n.push([o.key,o.value]),void o.continue();if(n.length>0||null===a)return;const i=t.get(ml+e);i.onsuccess=()=>{if(void 0!==i.result)return;const o=vl(a,e);if(0!==o.length){for(const[e,a]of o)t.put(a,e),n.push([e,a]);t.put((new Date).toISOString(),ml+e)}}}}),setItem:(e,t)=>p("readwrite",o=>{o.put(t,e)}).then(()=>d(e,t)),removeItem:e=>p("readwrite",t=>{t.delete(e)}).then(()=>d(e,null)),subscribe:e=>(s.add(e),(()=>{const e=bl();if(null===l&&null!==e&&!r)try{l=new e(gl+t),l.onmessage=e=>{const t=e.data;"string"!=typeof t?.key||"string"!=typeof t.value&&null!==t.value||c(t.key,t.value)}}catch{l=null}})(),()=>{s.delete(e),0===s.size&&u()}),close:()=>{r=!0,s.clear(),u();const e=i;i=null,e?.then(e=>e.close(),()=>{})}}}function bl(){const e=globalThis.BroadcastChannel;return"function"==typeof e?e:null}function vl(e,t){const o=[];try{for(let n=0;n<e.length;n++){const a=e.key(n);if(null===a||!a.startsWith(t))continue;const i=e.getItem(a);null!==i&&o.push([a,i])}}catch{return[]}return o}function wl(){const e=C();return null!==e&&"function"==typeof e.key&&"number"==typeof e.length?e:null}var yl=Object.freeze({__proto__:null,openIndexedDbStore:fl,openPageDefault:function(e){return function(e){const t=wl();if(null===t)return e;let o=null;const n=e=>{try{return e(),Promise.resolve()}catch(e){return Promise.reject(e)}};return{journal:e.journal,subscribe:n=>{const a=e.subscribe((e,t)=>{"page"!==o&&n(e,t)}),i=globalThis,r=e=>{"page"===o&&e.storageArea===t&&!0===e.key?.startsWith(_)&&n(e.key,e.newValue)};try{i.addEventListener?.("storage",r)}catch{}return()=>{a();try{i.removeEventListener?.("storage",r)}catch{}}},entries:n=>"page"===o?Promise.resolve(vl(t,n)):e.entries(n).then(e=>(o="idb",e),e=>{if("idb"===o)throw e;return o="page",vl(t,n)}),setItem:(a,i)=>"page"===o?n(()=>t.setItem(a,i)):e.setItem(a,i),removeItem:a=>"page"===o?n(()=>t.removeItem(a)):e.removeItem(a)}}(fl(e,Z,{}))}});const _l=/(^|\+)(Dead|Process|Compose)$/;function xl(e,t){const o=Intl.ListFormat;if(void 0===o)return e.join(", ");try{return new o(t,{type:"conjunction"}).format(e)}catch{return e.join(", ")}}const kl="\n.oac-widget .oac-keys-dialog { width: 880px; }\n.oac-widget .oac-keys { columns: 2; column-gap: 28px; min-width: 0; }\n.oac-widget .oac-keys__group { margin-bottom: 0; padding-bottom: 8px; }\n.oac-widget .oac-keys__row { min-height: 30px; padding: 2px 0; }\n.oac-widget .oac-keys__row > kbd { min-width: 44px; text-align: center; }\n.oac-widget .oac-keys__row.is-changed > kbd { color: var(--oac-acc-2); border-color: var(--oac-on-bd); background: var(--oac-on-bg); }\n.oac-widget .oac-keys__row > kbd.is-empty { border-style: dashed; font-family: inherit; }\n.oac-widget .oac-keys__row:not(.is-changed) > kbd.is-empty { background: transparent; color: var(--oac-faint); }\n.oac-widget .oac-keys__acts { flex: none; display: flex; align-items: center; gap: 2px; min-width: 118px; }\n.oac-widget .oac-keys__row.is-listening > kbd { color: var(--oac-acc-2); border-color: var(--oac-acc); border-style: solid; font-family: inherit; }\n.oac-widget .oac-keys__change, .oac-widget .oac-keys__reset { flex: none; height: 24px; padding: 0 8px; font-size: 11.5px; color: var(--oac-mut); }\n.oac-widget .oac-keys__change:hover, .oac-widget .oac-keys__reset:hover { color: var(--oac-tx); }\n.oac-widget .oac-keys__row.is-listening .oac-keys__change { color: var(--oac-acc-2); border-color: var(--oac-on-bd); }\n.oac-widget .oac-keys__reset.is-idle { visibility: hidden; }\n.oac-widget .oac-keys__conflict { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 2px 0 6px; padding: 6px 8px;\n  border: 1px solid var(--oac-bd-soft); border-left: 3px solid var(--oac-amber); border-radius: 6px; background: var(--oac-elev); break-inside: avoid; }\n.oac-widget .oac-keys__conflict > span { flex: 1 1 180px; min-width: 0; color: var(--oac-tx); font-size: 12px; overflow-wrap: anywhere; }\n.oac-widget .oac-keys__conflict > .oac-btn { height: 24px; font-size: 11.5px; }\n.oac-widget .oac-keys__status { flex: 1 1 200px; min-width: 0; color: var(--oac-mut); font-size: 12px; overflow-wrap: anywhere; }\n.oac-widget .oac-keys__note:empty { display: none; }\n@container oac-widget (max-width: 920px) {\n  .oac-widget .oac-keys { columns: 1; }\n}\n";var Cl=Object.freeze({__proto__:null,mountShortcutsPanel:function(e,n){const a=e.document,i=e.keymap;qn(a,kl);const r=u(a,"div","oac-keys-dialog",{"aria-label":R(e,"Keyboard shortcuts")}),s=u(a,"div","oac-dialog__head"),l=u(a,"div","oac-dialog__title");l.textContent=R(e,"Keyboard shortcuts");const c=u(a,"button","oac-btn oac-btn--icon",{type:"button","aria-label":R(e,"Close")});c.innerHTML=o.chromeIconSvg("close"),s.appendChild(l),s.appendChild(c);const d=u(a,"div","oac-dialog__body"),p=u(a,"div","oac-keys"),h=u(a,"div","oac-keys__note");d.appendChild(p),d.appendChild(h),r.appendChild(s),r.appendChild(d);const m=u(a,"div","oac-dialog__foot"),g=u(a,"button","oac-btn oac-keys__reset-all",{type:"button"}),f=u(a,"div","oac-keys__status",{role:"status","aria-live":"polite"}),b=u(a,"button","oac-btn",{type:"button"}),v=u(a,"button","oac-btn oac-btn--primary",{type:"button"}),w=u(a,"button","oac-btn",{type:"button"});if(b.textContent=R(e,"Cancel"),v.textContent=R(e,"Reset all"),w.textContent=R(e,"Close"),n){for(const e of[g,f,b,v,w])m.appendChild(e);r.appendChild(m)}let y=null,_=!1,x=!1,k=null,C="";const S=new Map,A=new Map,T=e=>(null!==e.command?S.get(e.command):void 0)??e.label,E=e=>{C=e,f.textContent=e},L=()=>{k?.(),k=null,"capture"===y?.kind&&(y=null)},O=(t,o)=>R(e,`schema.shortcuts.${t}.${o.defaultCombo??o.combo}`,{},o.label),I=t=>{p.textContent="",A.clear(),S.clear();let o=0;const r=i.describe();for(const e of r)for(const t of e.rows)void 0!==t.command&&S.set(t.command,O(e.group,t));for(const t of r){const r=u(a,"div","oac-keys__group"),s=u(a,"div","oac-head");s.textContent=R(e,`schema.shortcuts.group.${t.group}`,{},"Widget"===t.group?"General":t.group),r.appendChild(s);for(const s of t.rows){const l=O(t.group,s),c=u(a,"div","oac-keys__row"),d=u(a,"span");d.textContent=l;const p=u(a,"kbd"),h="capture"===y?.kind&&y.command===s.command;p.textContent=h?R(e,"Press keys"):""!==s.display?s.display:R(e,"Not set"),p.classList.toggle("is-empty",!h&&""===s.display),c.appendChild(d),c.appendChild(p),void 0!==s.shadowedBy&&(c.classList.add("is-shadowed"),c.title=R(e,"Claimed by {name}",{name:s.shadowedBy}),o++);const m=s.command;if(void 0!==m&&(c.dataset.command=m,c.classList.toggle("is-changed",!0===s.changed)),c.classList.toggle("is-listening",h),r.appendChild(c),!n)continue;const g=u(a,"div","oac-keys__acts");if(c.appendChild(g),void 0===m||!0!==s.rebindable)continue;const f=u(a,"button","oac-btn oac-keys__change",{type:"button"});f.textContent=R(e,h?"Cancel":"Change"),f.setAttribute("aria-label",R(e,h?"Cancel changing {name}":"Change {name}",{name:l})),f.addEventListener("click",()=>{h?(L(),E(""),I({command:m,part:"change"})):D(m)});const b=u(a,"button","oac-btn oac-keys__reset",{type:"button"});b.textContent=R(e,"Reset");const v=void 0===s.defaultCombo||""===s.defaultCombo?R(e,"Not set"):i.format(s.defaultCombo);b.setAttribute("aria-label",R(e,"Reset {name} to {chord}",{name:l,chord:v})),b.disabled=!0!==s.changed,b.classList.toggle("is-idle",!0!==s.changed),b.addEventListener("click",()=>{j(m,null,v,!0,!1)}),g.appendChild(f),g.appendChild(b),A.set(m,{change:f,reset:b}),"conflict"===y?.kind&&y.command===m&&r.appendChild(P(y))}p.appendChild(r)}if(h.textContent=0===o?"":R(e,1===o?"{count} chart shortcut struck through: another shortcut uses the same chord here and takes precedence.":"{count} chart shortcuts struck through: another shortcut uses the same chord here and takes precedence.",{count:o}),h.hidden=0===o,$(),void 0!==t){const e=A.get(t.command),o=e?.[t.part];(void 0===o||o.disabled?e?.change:o)?.focus()}},P=t=>{const o=u(a,"div","oac-keys__conflict",{role:"group"}),n=u(a,"span");n.textContent=R(e,"{chord} is used by {names}.",{chord:t.chord,names:xl(t.holders.map(T),e.locale)});const i=u(a,"button","oac-btn",{type:"button"});i.textContent=R(e,"Cancel");const r=u(a,"button","oac-btn oac-btn--primary",{type:"button"});r.textContent=R(e,"Replace"),o.setAttribute("aria-label",n.textContent),i.addEventListener("click",()=>{y=null,E(""),I({command:t.command,part:"change"})}),r.addEventListener("click",()=>{j(t.command,t.combo,t.chord,t.reset,!0)}),o.appendChild(n),o.appendChild(i),o.appendChild(r);const s=A.get(t.command);return void 0!==s&&(s.replace=r),o},$=()=>{const t=Object.keys(i.overrides()).length>0;g.textContent=R(e,"Reset all"),g.disabled=!t,g.hidden=_,b.hidden=!_,v.hidden=!_,w.hidden=_,f.textContent=_?R(e,"Put every shortcut back to its default?"):C},j=(t,o,n,a,r)=>{let s;x=!0;try{s=a?i.reset(t,{replace:r}):i.rebind(t,o,{replace:r})}finally{x=!1}const l=xl(s.conflicts.map(T),e.locale);if(s.ok){L(),y=null;const o=S.get(t)??t;E(R(e,a?"{name} is back to {chord}.":"{name} is now {chord}.",{name:o,chord:n})+(s.conflicts.length>0?" "+R(e,"Taken from {names}.",{names:l}):"")),I({command:t,part:"change"})}else if("taken"===s.reason&&s.conflicts.every(e=>e.rebindable))L(),y={kind:"conflict",command:t,combo:o??"",chord:n,holders:s.conflicts,reset:a},E(""),I({command:t,part:"replace"});else if("taken"===s.reason){const t=s.conflicts.filter(e=>!e.rebindable).map(T);E(R(e,"{chord} belongs to {names}, which cannot change. Press another.",{chord:n,names:xl(t,e.locale)}))}else"reserved"===s.reason?E(R(e,"{chord} belongs to the browser. Press another.",{chord:n})):E(R(e,"That key cannot be used here. Press another."))},D=o=>{L(),_=!1,y={kind:"capture",command:o},k=i.capture((o=>n=>{const a=!0===n.ctrlKey||!0===n.metaKey||!0===n.altKey||!0===n.shiftKey;if("Tab"===n.key)return L(),E(""),I({command:o,part:"change"}),!1;if("Escape"===n.key&&!a)return L(),E(R(e,"Nothing changed.")),void I({command:o,part:"change"});const r=ke(n);if(""===r)return;if(_l.test(r))return void E(R(e,"That key cannot be used here. Press another."));const s=i.format(r),l=i.isMac?"Cmd":"Ctrl",c=i.isMac?"Opt":"Alt";if(/^(Shift\+)?[a-z0-9]$/.test(r))return void E(R(e,"{chord} types into the chart. Add {mod} or {alt}.",{chord:s,mod:l,alt:c}));if(/^(Shift\+)?Space$/.test(r))return void E(R(e,"{chord} presses the focused control. Add {mod} or {alt}.",{chord:s,mod:l,alt:c}));const d=o.startsWith("chart:"),u=n.ctrlKey||n.metaKey,p=d?t.eventToCombo({code:n.code,key:n.key,altKey:n.altKey,shiftKey:n.shiftKey,ctrlKey:!i.isMac&&u,metaKey:i.isMac&&u},i.isMac):"";d&&""===p?E(R(e,"That key cannot be used here. Press another.")):j(o,d?p:r,s,!1,!1)})(o)),E(R(e,"Press the new shortcut for {name}. Esc cancels.",{name:S.get(o)??o})),I({command:o,part:"change"})};g.addEventListener("click",()=>{L(),y=null,_=!0,I(),b.focus()}),b.addEventListener("click",()=>{_=!1,$(),g.focus()}),v.addEventListener("click",()=>{_=!1,x=!0;try{i.resetAll()}finally{x=!1}E(R(e,"Every shortcut is back to its default.")),I(),w.focus()});const M=i.onChange(()=>{x||I((()=>{const e=a.activeElement;for(const[t,o]of A)for(const n of["change","reset","replace"])if(void 0!==o[n]&&o[n]===e)return{command:t,part:n}})())});I();const z=e.openOverlay(r,{placement:"center",dismissOnOutside:!0,initialFocus:n?r:void 0,onClose:()=>{L(),M()}});return c.addEventListener("click",z),w.addEventListener("click",z),z}});const Sl={save:"The layout could not be saved: {error}",open:"The layout could not be opened: {error}",rename:"The layout could not be renamed: {error}",delete:"The layout could not be deleted: {error}",reload:"The saved layouts could not be read: {error}",overwrite:"The layout could not be overwritten: {error}",autosave:"Autosave could not be changed: {error}"};let Al=0;const Tl=e=>null===e.layoutId?null:e.catalog?.workspaces.find(t=>t.id===e.layoutId)?.name??null;function El(e,t,o=Date.now()){const n=e.chart.timezone(),a=e=>new Intl.DateTimeFormat("en-CA",{timeZone:n,year:"numeric",month:"2-digit",day:"2-digit"}).format(e),i=a(t)===a(o)?{timeZone:n,hour:"2-digit",minute:"2-digit"}:{timeZone:n,day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"};try{return new Intl.DateTimeFormat(e.locale,i).format(t)}catch{return new Intl.DateTimeFormat("en-US",i).format(t)}}const Ll='\n.oac-widget .oac-layouts { width: 380px; }\n.oac-widget .oac-layouts .oac-dialog__body { display: flex; flex-direction: column; gap: 8px; padding-top: 2px; }\n.oac-widget .oac-layouts__current { display: grid; gap: 2px; padding: 8px 10px; border: 1px solid var(--oac-bd-soft); border-radius: 8px; background: var(--oac-elev); }\n.oac-widget .oac-layouts__heading { display: flex; align-items: center; gap: 6px; min-width: 0; }\n.oac-widget .oac-layouts__name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--oac-tx-strong); font-size: 13px; }\n.oac-widget .oac-layouts__name.is-none { color: var(--oac-mut); font-weight: 500; }\n.oac-widget .oac-layouts__tools { display: flex; gap: 2px; flex: none; }\n.oac-widget .oac-layouts__tools .oac-btn { height: 24px; padding: 0 6px; font-size: 11.5px; }\n.oac-widget .oac-layouts__line { color: var(--oac-mut); font-size: 11px; }\n.oac-widget .oac-layouts__line[data-state="dirty"] { color: var(--oac-amber); }\n.oac-widget .oac-layouts__line[data-state="failed"], .oac-widget .oac-layouts__line[data-state="conflict"] { color: var(--oac-danger); }\n.oac-widget .oac-layouts__form, .oac-widget .oac-layouts__confirm, .oac-widget .oac-layouts__conflict { display: grid; gap: 6px; padding: 8px 10px;\n  border: 1px solid var(--oac-bd-soft); border-radius: 8px; }\n.oac-widget .oac-layouts__conflict { border-color: var(--oac-danger); }\n.oac-widget .oac-layouts__label { color: var(--oac-mut); font-size: 11px; }\n.oac-widget .oac-layouts__row-controls { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 6px; min-width: 0; }\n.oac-widget .oac-layouts__row-controls .oac-btn:not(.oac-btn--primary) { border-color: var(--oac-bd-soft); }\n/* Nothing to save: the primary button steps back rather than show faint text on the accent, and a\n   disabled Delete takes no danger colour from a hover or a tap. */\n.oac-widget .oac-layouts .oac-btn--primary[aria-disabled="true"] { background: var(--oac-elev); color: var(--oac-faint); }\n.oac-widget .oac-layouts .oac-btn[aria-disabled="true"]:hover { color: var(--oac-faint); }\n.oac-widget .oac-layouts__input { flex: 1 1 160px; min-width: 0; }\n.oac-widget .oac-layouts__confirm-text, .oac-widget .oac-layouts__conflict-text { margin: 0; line-height: 1.45; overflow-wrap: anywhere; }\n.oac-widget .oac-layouts__error { margin: 0; color: var(--oac-danger); font-size: 11px; overflow-wrap: anywhere; }\n.oac-widget .oac-layouts__lists { display: flex; flex-direction: column; min-height: 0; }\n.oac-widget .oac-layouts__lists > .oac-head { padding: 6px 2px 3px; }\n.oac-widget .oac-layouts__list { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; }\n.oac-widget .oac-layouts__row { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 30px; padding: 5px 8px; border: 0; border-radius: 6px;\n  background: transparent; color: var(--oac-tx); text-align: left; }\n.oac-widget .oac-layouts__row:hover, .oac-widget .oac-layouts__row:focus-visible { background: var(--oac-elev-2); outline: none; }\n.oac-widget .oac-layouts__row[aria-current="true"] { color: var(--oac-acc-2); box-shadow: inset 2px 0 0 var(--oac-acc); }\n.oac-widget .oac-layouts__row[aria-disabled="true"] { color: var(--oac-faint); cursor: default; background: transparent; }\n.oac-widget .oac-layouts__row-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.oac-widget .oac-layouts__row-meta { flex: none; color: var(--oac-mut); font-size: 11px; }\n.oac-widget .oac-layouts__switch { display: inline-flex; align-items: center; gap: 7px; height: var(--oac-ctl-h); padding: 0 8px 0 4px; border: 1px solid transparent;\n  border-radius: var(--oac-radius); background: transparent; color: var(--oac-tx); }\n.oac-widget .oac-layouts__switch:hover { background: var(--oac-elev); border-color: var(--oac-bd-soft); }\n.oac-widget .oac-layouts__switch[aria-disabled="true"] { color: var(--oac-faint); cursor: default; background: transparent; border-color: transparent; }\n.oac-widget .oac-layouts__track { position: relative; width: 26px; height: 15px; flex: none; border-radius: 999px; background: var(--oac-elev-3);\n  border: 1px solid var(--oac-bd); transition: background .12s, border-color .12s; }\n.oac-widget .oac-layouts__track::after { content: \'\'; position: absolute; top: 2px; left: 2px; width: 9px; height: 9px; border-radius: 50%;\n  background: var(--oac-mut); transition: transform .12s, background .12s; }\n.oac-widget .oac-layouts__switch[aria-checked="true"] .oac-layouts__track { background: var(--oac-acc); border-color: var(--oac-acc); }\n.oac-widget .oac-layouts__switch[aria-checked="true"] .oac-layouts__track::after { transform: translateX(11px); background: var(--oac-bg); }\n.oac-widget .oac-layouts__switch-value { color: var(--oac-mut); font-size: 11px; }\n.oac-widget .oac-layouts__autosave-state { color: var(--oac-mut); font-size: 11px; }\n.oac-widget .oac-layouts__autosave-state[data-state="failed"] { color: var(--oac-danger); }\n.oac-widget.is-mobile .oac-layouts { width: 100%; }\n.oac-widget.is-mobile .oac-layouts__row { min-height: 44px; }\n.oac-widget.is-mobile .oac-layouts .oac-btn, .oac-widget.is-mobile .oac-layouts__switch { min-height: 40px; }\n@media (prefers-reduced-motion: reduce) {\n  .oac-widget .oac-layouts__track, .oac-widget .oac-layouts__track::after { transition: none; }\n}\n';var Ol=Object.freeze({__proto__:null,mountLayoutsMenu:function(e,t,o){const n=e.document;qn(n,Ll);const a=nn(e),i=a("title","Layouts"),r=ct(n,{translate:e.translate,title:i,className:"oac-layouts",onClose:()=>le.close()}),s=nt(n,"div","oac-layouts__current"),l=nt(n,"div","oac-layouts__heading"),c=nt(n,"strong","oac-layouts__name"),d=nt(n,"div","oac-layouts__tools"),u=it(n,{label:a("rename","Rename"),icon:"rename",onClick:()=>Y("rename",u)});u.dataset.action="rename";const p=it(n,{label:a("delete","Delete"),icon:"trash",onClick:()=>function(){const o=t.state(),n=o.layoutId;if(null===n||o.busy)return;X(a("deleteQuestion","Delete {name}? The chart stays as it is.",{name:Tl(o)??""}),[{label:R(e,"Cancel"),action:"keep",run:()=>Z()},{label:a("delete","Delete"),action:"confirm-delete",variant:"danger",run:()=>{U=()=>z,Z(),J("delete",()=>t.remove(n)).then(()=>{W||z.focus()})}}],()=>p)}()});p.dataset.action="delete",p.classList.add("oac-btn--danger"),d.append(u,p),l.append(c,d);const h=nt(n,"div","oac-layouts__line");h.setAttribute("role","status"),h.setAttribute("aria-live","polite"),s.append(l,h);const m=nt(n,"form","oac-layouts__form");m.hidden=!0;const g=nt(n,"label","oac-layouts__label"),f=nt(n,"input","oac-layouts__input");f.type="text",f.maxLength=120,f.autocomplete="off",f.id="oac-layouts-name-"+ ++Al,g.htmlFor=f.id;const b=nt(n,"p","oac-input-error");b.setAttribute("role","alert"),b.hidden=!0;const v=nt(n,"div","oac-layouts__row-controls"),w=it(n,{label:R(e,"Cancel"),onClick:()=>Z()}),y=it(n,{label:R(e,"Save"),variant:"primary",onClick:()=>{Q()}});w.dataset.action="cancel-name",y.dataset.action="submit-name",v.append(f,w,y),m.append(g,v,b);const _=nt(n,"div","oac-layouts__confirm");_.hidden=!0,_.setAttribute("role","alertdialog");const x=nt(n,"p","oac-layouts__confirm-text");x.id=`oac-layouts-confirm-${Al}`,_.setAttribute("aria-describedby",x.id);const k=nt(n,"div","oac-layouts__row-controls");_.append(x,k);const C=nt(n,"div","oac-layouts__conflict");C.hidden=!0,C.setAttribute("role","alert");const S=nt(n,"p","oac-layouts__conflict-text"),A=nt(n,"div","oac-layouts__row-controls"),T=it(n,{label:a("reload","Reload list"),icon:"refresh",onClick:()=>{J("reload",()=>t.reload())}});T.dataset.action="reload";const E=it(n,{label:a("copy","Save as a copy"),onClick:()=>Y("copy",E)});E.dataset.action="copy";const L=it(n,{label:a("overwrite","Overwrite"),variant:"danger",onClick:()=>{J("overwrite",()=>t.overwrite())}});L.dataset.action="overwrite",A.append(T,E,L),C.append(S,A);const O=nt(n,"p","oac-layouts__error");O.setAttribute("role","alert"),O.hidden=!0;const I=nt(n,"div","oac-layouts__lists");r.body.append(s,m,_,C,O,I);const P=nt(n,"button","oac-layouts__switch");P.type="button",P.setAttribute("role","switch"),P.dataset.action="autosave";const $=nt(n,"span","oac-layouts__switch-label",a("autosave","Autosave")),j=nt(n,"span","oac-layouts__switch-value");P.append(nt(n,"span","oac-layouts__track"),$,j),P.addEventListener("click",()=>{if("true"===P.getAttribute("aria-disabled"))return;const e=!0===t.state().catalog?.autosave;J("autosave",()=>t.setAutosave(!e))});const D=nt(n,"span","oac-layouts__autosave-state");D.setAttribute("aria-live","polite"),r.lead.append(P,D);const M=it(n,{label:a("saveAs","Save as..."),icon:"save-as",onClick:()=>Y("save-as",M)});M.dataset.action="save-as";const z=it(n,{label:R(e,"Save"),variant:"primary",onClick:()=>{"true"!==z.getAttribute("aria-disabled")&&(null===t.state().layoutId?Y("save-as",z):J("save",()=>t.save()))}});z.dataset.action="save",r.actions.append(M,z);let N=null,W=!1,B=null,U=null;const q=(e,t,o)=>{e.setAttribute("aria-disabled",String(t)),t&&void 0!==o?e.title=o:e.removeAttribute("title")},K=t=>F(e,t),G=e=>Array.from(I.querySelectorAll(".oac-layouts__row")).find(t=>t.dataset.layoutId===e)??null,V=(e,t)=>{const o=!t&&!e.hidden&&e.contains(n.activeElement);return e.hidden=!t,o},H=()=>{if(W)return;const e=U?.()??null;(null===e||C.hidden&&C.contains(e)?z:e).focus()};async function J(e,t){B=null;try{return await t(),!0}catch(t){return B=a(`failed.${e}`,Sl[e],{error:K(t)}),!1}finally{ne()}}function Z(){N=null;const e=[V(m,!1),V(_,!1)].includes(!0);b.hidden=!0,f.removeAttribute("aria-invalid"),ne(),e&&H(),U=null}function Y(o,n){const r=t.state();if(r.busy)return;if("rename"===o&&null===r.layoutId)return;Z(),N=o,U=()=>n;const s=Tl(r),l=e.symbol();g.textContent="rename"===o?a("renameLabel","New name for {name}",{name:s??""}):"copy"===o?a("copyLabel","Name for the copy"):a("nameLabel","Layout name"),f.value="rename"===o?s??"":"copy"===o?a("copyName","{name} copy",{name:s??i}):[l.symbol,e.interval()].filter(e=>""!==e).join(" "),y.textContent="rename"===o?a("renameSubmit","Rename"):R(e,"Save"),m.hidden=!1,f.focus(),f.select()}async function Q(){const o=N,n=f.value.trim();if(null===o||t.state().busy)return;if(""===n)return b.textContent=R(e,"Enter a name"),b.hidden=!1,f.setAttribute("aria-invalid","true"),void f.focus();const a=t.state().layoutId;await J("rename"===o?"rename":"save",()=>"rename"===o&&null!==a?t.rename(a,n):t.saveAs(n))&&!W&&(U=()=>z,Z())}function X(e,t,o){Z(),U=o,x.textContent=e,k.textContent="";for(const e of t){const t=it(n,{label:e.label,variant:e.variant,onClick:e.run});t.dataset.action=e.action,k.appendChild(t)}_.hidden=!1,k.querySelector("button")?.focus()}async function ee(e){V(_,!1)&&H();let o=!1;const n=await J("open",async()=>{const n=await t.open(e);if(o=n.applied,!n.applied)throw new Error(n.reason??a("notShown","the layout cannot show here"))});n&&o&&le.close()}function te(o,i,r){const s=nt(n,"button","oac-layouts__row");s.type="button",s.dataset.layoutId=o.id;const l=o.id===i.layoutId;l&&s.setAttribute("aria-current","true"),s.append(nt(n,"span","oac-layouts__row-name",o.name)),s.append(nt(n,"span","oac-layouts__row-meta",l?a("current","on the chart"):El(e,o.updatedAt))),q(s,i.busy||i.suspended,i.suspended?a("suspendedOpen","Stop the replay to open a layout"):void 0),s.addEventListener("click",()=>{"true"!==s.getAttribute("aria-disabled")&&async function(o){if(t.state().busy||t.state().suspended)return;if(B=null,await t.flush(),W)return;const n=t.state();if(null!==n.layoutId&&n.dirty){const i=Tl(n)??"",r=[{label:R(e,"Cancel"),action:"stay",run:()=>Z()},{label:a("discard","Open without saving"),action:"discard",variant:"danger",run:()=>{ee(o)}}];return n.conflict||r.push({label:a("saveAndOpen","Save and open"),action:"save-and-open",variant:"primary",run:()=>{J("save",()=>t.save()).then(e=>{e&&ee(o)})}}),void X(o===n.layoutId?a("revertQuestion","{name} has unsaved changes. Open the saved version?",{name:i}):a("discardQuestion","{name} has unsaved changes. Save them before opening {target}?",{name:i,target:n.catalog?.workspaces.find(e=>e.id===o)?.name??""}),r,()=>G(o))}await ee(o)}(o.id)});const c=nt(n,"li","oac-layouts__item");c.appendChild(s),r.appendChild(c)}function oe(e,t,o,a){if(0===t.length)return;const i=nt(n,"div","oac-head",e);i.id=`oac-layouts-${a}-${Al}`;const r=nt(n,"ul","oac-layouts__list");r.setAttribute("aria-labelledby",i.id),r.dataset.list=a;for(const e of t)te(e,o,r);I.append(i,r)}function ne(){if(W)return;const o=t.state(),i=n.activeElement,r=i?.dataset.layoutId,s=Tl(o);c.textContent=s??a("none","No layout open"),c.classList.toggle("is-none",null===s);const l=o.catalog?.workspaces.find(e=>e.id===o.layoutId);h.textContent=void 0===l||o.conflict||o.dirty||"failed"===o.autosave||"saving"===o.autosave?an(e,o):a("savedAt","Saved {time}",{time:El(e,l.updatedAt)}),h.dataset.state=o.conflict?"conflict":"failed"===o.autosave?"failed":o.dirty?"dirty":"clean",q(u,null===o.layoutId||o.busy),q(p,null===o.layoutId||o.busy),q(z,o.busy||o.conflict||null!==o.layoutId&&!o.dirty&&"failed"!==o.autosave,o.conflict?a("conflictSave","Choose how to settle the change from the other window"):void 0),q(M,o.busy);const d=!0===o.catalog?.autosave;P.setAttribute("aria-checked",String(d)),j.textContent=d?a("on","On"):a("off","Off"),q(P,o.busy||null===o.catalog),D.textContent=d&&null!==o.layoutId&&!o.conflict?an(e,o):"",D.dataset.state=o.autosave,V(C,o.conflict)&&z.focus(),S.textContent=a("conflictText","{name} was changed in another window. This chart is not saved over it.",{name:s??""});for(const e of[T,E,L])q(e,o.busy);const m=B??("failed"!==o.autosave||null===o.error||o.conflict?null:a("failed.autosaveWrite","Autosave could not save the layout: {error}",{error:K(o.error)}));O.hidden=null===m,O.textContent=m??"",I.textContent="";const g=o.catalog?.workspaces??[];null===o.catalog?o.busy&&I.appendChild(nt(n,"p","oac-empty",a("loading","Loading layouts"))):0===g.length&&I.appendChild(nt(n,"p","oac-empty",a("empty","No saved layouts yet. Save this chart to start one.")));const f=(o.catalog?.recentWorkspaceIds??[]).slice(0,10).map(e=>g.find(t=>t.id===e)).filter(e=>void 0!==e),b=g.filter(e=>!f.includes(e)).sort((e,t)=>e.name.localeCompare(t.name));oe(a("recent","Recent"),f,o,"recent"),oe(f.length>0?a("others","Other layouts"):a("all","Layouts"),b,o,"others"),void 0!==r&&Array.from(I.querySelectorAll(".oac-layouts__row")).find(e=>e.dataset.layoutId===r)?.focus()}I.addEventListener("keydown",e=>{const t=e.key;if("ArrowDown"!==t&&"ArrowUp"!==t)return;const o=Array.from(I.querySelectorAll(".oac-layouts__row")),a=o.indexOf(n.activeElement);0!==o.length&&(e.preventDefault(),o[(a+("ArrowDown"===t?1:-1)+o.length)%o.length].focus())}),m.addEventListener("submit",e=>{e.preventDefault(),Q()}),f.addEventListener("input",()=>{b.hidden=!0,f.removeAttribute("aria-invalid")});const ae=t.subscribe(()=>ne());ne();const ie=e.root.classList.contains("is-mobile"),re=ut(e,r.el,void 0===o||ie?{placement:"center",modal:!0,initialFocus:z}:{anchor:o,placement:"below",initialFocus:z},()=>se());function se(){W||(W=!0,ae())}const le={el:re.el,isOpen:re.isOpen,close:()=>{re.isOpen()&&(se(),re.close())}};return J("reload",async()=>{await t.reload(),await t.flush()}),le}});let Il=0;var Pl=Object.freeze({__proto__:null,openChartDataExportDialog:function(e,t,o){const n=e.chart,a=Pa(n),i=n.indicators().map(e=>({id:e.id,name:a.get(e.id),hidden:!e.visible()})),r=n.getVisibleLogicalRange(),s=n.primaryBars().filter(e=>{const t=n.dataLayer.timeToIndex(e.time);return Number.isFinite(e.time)&&void 0!==t&&t>=r.from&&t<=r.to}),l=s.length?{from:s[0].time,to:s[s.length-1].time}:null,c=n.timezone(),d=e=>{const t=ta(e,c,!0);return`${t.date}T${t.time}`};let u=!1,p=null,h=()=>{};const m=ct(e.document,{translate:e.translate,title:R(e,"Download chart data (CSV)"),className:"oac-csv",onClose:A}),g=nt(e.document,"p","oac-csv__hint",R(e,"Only loaded rows are exported. Blank bounds include all loaded times.")),f=nt(e.document,"div","oac-csv__ranges"),b=nt(e.document,"div"),v=nt(e.document,"p","oac-csv__error");v.setAttribute("role","alert");const w=nt(e.document,"p","oac-csv__hint",R(e,"Times are on the chart clock, {zone}.",{zone:c}));m.body.append(g,w,f,b,v);const y=ft(b,[{key:"from",kind:"text",label:R(e,"From")},{key:"to",kind:"text",label:R(e,"To")},{key:"alignment",kind:"select",label:R(e,"Study alignment"),options:[{value:"source",label:R(e,"Source rows")},{value:"display",label:R(e,"Displayed rows")}]},...i.map((t,o)=>({key:`study-${o}`,kind:"boolean",group:R(e,"Studies"),label:t.hidden?R(e,"{name}, hidden",{name:t.name}):t.name}))],{idPrefix:"oac-csv-"+ ++Il,translate:e.translate,openOverlay:e.openOverlay,values:{from:"",to:"",alignment:"source",...Object.fromEntries(i.map((e,t)=>[`study-${t}`,!0]))},onChange:e=>{y.setError(e,null),v.textContent=""}});for(const e of["from","to"]){const t=b.querySelector(`[data-key="${e}"] input`);null!==t&&(t.type="datetime-local",t.step="1")}const _=(e,t)=>{y.setError("from",null),y.setError("to",null),v.textContent="",y.sync({from:e,to:t})},x=it(e.document,{label:R(e,"Use captured visible range"),onClick:()=>{l&&_(d(l.from),d(l.to))}});x.dataset.action="csv-visible",x.disabled=null===l;const k=it(e.document,{label:R(e,"All loaded rows"),onClick:()=>_("","")});k.dataset.action="csv-all",f.append(x,k);const C=it(e.document,{label:R(e,"Cancel"),onClick:A}),S=it(e.document,{label:R(e,"Download CSV"),variant:"primary",onClick:function(){if(u)return;const t=y.values(),n={};try{for(const o of["from","to"]){y.setError(o,null);const a=String(t[o]??"").trim();if(""===a)continue;const[i="",r=""]=a.split("T"),s=oa(i,r,c,"to"===o?{end:!0}:{});if(null===s){const t=R(e,"Enter a date and a time on the chart clock");throw y.setError(o,t),new Error(t)}n[o]=s}if(void 0!==n.from&&void 0!==n.to&&n.from>n.to){const t=R(e,"The From bound must be before or equal to the To bound");throw y.setError("to",t),new Error(t)}o({indicators:i.filter((e,o)=>!0===t[`study-${o}`]).map(e=>e.id),range:n,alignment:"display"===t.alignment?"display":"source"}),A()}catch(t){const o=F(e,t);v.textContent=o,e.status(R(e,"Data export failed: {error}",{error:o}),"error")}}});function A(){u||(u=!0,h(),y.destroy(),p?.close())}return S.dataset.action="download-csv",m.actions.append(C,S),h=n.on("destroy",A),p=ut(e,m.el,{anchor:t,modal:!0,placement:"center"},A),u&&p.close(),{el:m.el,close:A,isOpen:()=>!u&&p.isOpen()}}});const $l={"point-figure":[.05,.1,.15,.25,.5,1,2,3],renko:[.05,.1,.25,.5,1,2,3,5]},jl={"point-figure":["symbol.body"],renko:["symbol.body","symbol.borders"]},Dl=["fixed","percent","atr","atrPercent"],Ml={fixed:"boxSize",percent:"percent",atr:"atrMultiplier",atrPercent:"percent"},zl=e=>`${e<1?e.toFixed(2):String(e)}%`;let Nl=0;function Rl(e,t,o,n,a,i){const r=()=>a.mode,s=new Map,l=(t,n)=>{const a=nt(e,"input","oac-input--num");return a.type="text",a.inputMode=n,a.id=`${o}-${t}`,a},c=l("size","decimal"),d=l("atr","numeric"),u=nt(e,"span","oac-ctset__unit"),{wrap:p,select:h}=rt(e);h.setAttribute("aria-label",t("method","Sizing method"));const m={fixed:t("mode.fixed","Absolute"),percent:t("mode.percent","Percent"),atr:t("mode.atr","ATR"),atrPercent:t("mode.atrPercent","ATR %")};for(const t of Dl)h.appendChild(Object.assign(nt(e,"option",void 0,m[t]),{value:t}));const g=nt(e,"span","oac-ctset__size");g.append(c,u,p);const f=nt(e,"div","oac-ctset__presets");f.setAttribute("role","group"),f.setAttribute("aria-label",t("presets","Percent presets"));const b=$l[n].map(t=>{const o=it(e,{label:zl(t),onClick:()=>{a.mode="percent",a.percent=t,s.delete("size"),i()}});return o.classList.add("oac-ctset__preset"),o.dataset.percent=String(t),f.appendChild(o),{b:o,p:t}}),v=e=>{const o=(e=>{const o=("size"===e?c:d).value.trim(),n=""===o?"size"===e&&"fixed"===r()?0:NaN:Number(o);if("atrPeriod"===e){if(!Number.isInteger(n)||n<1)return t("error.length","Enter a whole number, 1 or more");a.atrPeriod=n}else{if(!Number.isFinite(n)||("fixed"===r()?n<0:n<=0))return"fixed"===r()?t("error.fixed","Enter 0 or a positive number"):t("error.positive","Enter a number above 0");a[Ml[r()]]=n}return null})(e);null===o?s.delete(e):s.set(e,o),i()};c.addEventListener("input",()=>v("size")),d.addEventListener("input",()=>v("atrPeriod")),h.addEventListener("change",()=>{a.mode=h.value,s.delete("size"),i()});const w=new Map;return{presets:f,size:g,atrPeriod:d,attach:t=>{for(const[o,n]of[["size",c],["atrPeriod",d]]){const a=t.querySelector(`[data-key="${o}"]`),i=a?.querySelector("label");i&&(i.htmlFor=n.id);const r=nt(e,"div","oac-input-error");r.id=`${n.id}-error`,r.setAttribute("role","status"),n.setAttribute("aria-describedby",r.id),a?.appendChild(r),w.set(o,r)}},paint:()=>{const e=r();h.value=e,s.has("size")||(c.value="fixed"===e&&0===a.boxSize?"":String(a[Ml[e]]??"")),s.has("atrPeriod")||(d.value=String(a.atrPeriod??14)),c.placeholder="fixed"===e?t("auto","Auto"):"",c.title="fixed"===e?t("autoHint","Blank or 0 sizes it from the loaded history"):"",u.textContent="percent"===e||"atrPercent"===e?"%":"atr"===e?t("unit.atr","x ATR"):"",u.hidden=""===u.textContent;for(const{b:t,p:o}of b)t.setAttribute("aria-pressed",String("percent"===e&&a.percent===o&&!s.has("size")));for(const[e,t]of w){const o=s.get(e)??null;("size"===e?c:d).setAttribute("aria-invalid",String(null!==o)),t.textContent=o??"",t.hidden=null===o}},invalid:()=>s.has("size")?c:s.has("atrPeriod")&&(e=>"atr"===e||"atrPercent"===e)(r())?d:null,refuse:e=>{s.set("size",e),i()}}}var Fl=Object.freeze({__proto__:null,openChartTypeSettings:function(e,o){const{chart:n}=e,a=e.document,i=(t,o,n={})=>R(e,`schema.ui.chartTypeSettings.${t}`,n,o),r=Kt(n),s=n.primarySeries(),l=null===s?null:n.seriesTransform(s);if(null===r||null===l)return dt(e,i("unavailable","This chart type has no box settings"));const c=r,d=t.getSeriesTransform(c),u=i("title","{name} settings",{name:R(e,`schema.chartType.${c}`,{},d.name)}),p={};for(const e of d.inputs)p[e.key]=l.options?.[e.key]??e.default;Dl.includes(p.mode)||(p.mode="fixed");const h={},m="oac-ctset-"+ ++Nl,g=Rl(a,i,m,c,p,()=>T()),f=function(e,t,o,n,a){const i=nt(e,"div","oac-ctset__radios");i.setAttribute("role","radiogroup"),i.setAttribute("aria-label",t("prices","Prices"));const r=["close","hl"].map(r=>{const s=nt(e,"label","oac-ctset__radio"),l=Object.assign(nt(e,"input"),{type:"radio",name:`${o}-method`,value:r});return l.addEventListener("change",()=>{l.checked&&(n.method=r,a())}),s.append(l,nt(e,"span",void 0,"close"===r?t("method.close","Close only"):t("method.hl","High and low"))),i.appendChild(s),l});return{el:i,paint:()=>{for(const e of r)e.checked=n.method===e.value}}}(a,i,m,p,()=>T()),b="renko"===c?i("group.brick","Brick size"):i("group.box","Box size"),v=i("group.construction","Construction"),w=t.chartSettingsSchema(n).find(e=>"price"===e.id)?.inputs??[],y=[...Xe(jl[c].flatMap(e=>w.filter(t=>t.key===e)),{translate:e.translate,scope:"settings"}).map(e=>({...e,group:i("group.colors","Colors")})),{key:"presets",kind:"custom",label:i("presetsLabel","Presets"),group:b},{key:"size",kind:"custom",label:i("size","Size"),group:b},{key:"atrPeriod",kind:"custom",label:i("atrPeriod","ATR length"),group:b,visibleWhen:{key:"mode",is:["atr","atrPercent"]}},..."renko"===c?[]:[{key:"reversal",kind:"select",label:i("reversal","Reversal"),group:v,options:Array.from({length:10},(e,t)=>({value:String(t+1),label:0===t?i("box","1 box"):i("boxes","{count} boxes",{count:String(t+1)})}))}],{key:"method",kind:"custom",label:i("prices","Prices"),group:v}],_={presets:g.presets,size:g.size,atrPeriod:g.atrPeriod,method:f.el};let x=!1,k=null;const C=ct(a,{translate:e.translate,title:u,className:"oac-ctset",onClose:E}),S=nt(a,"div","oac-ctset__form");C.body.appendChild(S);const A=ft(S,y,{idPrefix:m,translate:e.translate,openOverlay:e.openOverlay,values:{...t.readChartSettings(n),mode:p.mode,reversal:String(p.reversal??3)},onChange:(e,t)=>{"reversal"===e?p.reversal=Number(t):h[e]=t},custom:e=>_[e.key]??null});function T(){g.paint(),f.paint(),A.sync({mode:p.mode})}function E(){x||(x=!0,I(),A.destroy(),k?.close())}function L(){if(x)return;const o=g.invalid();if(null!==o)return void o.focus();const n=function(e,o,n,a,i){const{chart:r}=e,s=r.primarySeries(),l=null===s?null:r.seriesTransform(s);if(null===s||l?.type!==o)return null;const c={...l.options};for(const e of t.getSeriesTransform(o).inputs){const t=n[e.key];void 0!==t&&(t===e.default?delete c[e.key]:c[e.key]=t)}const d=Object.keys(c).length>0?{type:o,options:c}:{type:o};try{O(e,i,()=>{JSON.stringify(d)!==JSON.stringify(l)&&r.setSeriesTransform(s,d),Object.keys(a).length>0&&t.applyChartSettings(r,a)})}catch(e){return e instanceof Error?e.message:String(e)}return null}(e,c,p,h,u);null===n?E():g.refuse(n)}g.attach(S),C.actions.append(it(a,{label:R(e,"Cancel"),onClick:E}),it(a,{label:R(e,"OK"),variant:"primary",onClick:L})),S.addEventListener("keydown",e=>{"Enter"===e.key&&e.target.classList.contains("oac-input--num")&&L()});const I=n.on("destroy",E);return T(),k=ut(e,C.el,{anchor:o,modal:!0,placement:"center"},E),{el:C.el,close:E,isOpen:()=>!x&&k.isOpen()}}});const Wl="\n.oac-widget .oac-templates { width: 360px; max-width: calc(100% - 16px); max-height: min(420px, calc(100% - 16px)); display: flex; flex-direction: column;\n  padding: 4px 6px 6px; background: var(--oac-panel); border: 1px solid var(--oac-bd); border-radius: 10px; box-shadow: var(--oac-shadow); outline: none; }\n.oac-widget .oac-templates__list { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; display: grid; gap: 1px; align-content: start; }\n.oac-widget .oac-templates__row { display: flex; align-items: center; gap: 4px; min-height: 32px; padding: 2px 2px 2px 8px; border-radius: 6px; }\n.oac-widget .oac-templates__row:hover, .oac-widget .oac-templates__row:focus-within { background: var(--oac-elev); }\n.oac-widget .oac-templates__name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.oac-widget .oac-templates__meta { flex: none; color: var(--oac-mut); font-size: 11px; margin-right: 4px; }\n.oac-widget .oac-templates__row .oac-btn { height: 24px; padding: 0 7px; font-size: 11.5px; border-color: var(--oac-bd-soft); }\n.oac-widget .oac-templates__row .oac-btn--icon { width: 24px; padding: 0; border-color: transparent; color: var(--oac-mut); }\n.oac-widget .oac-templates__row .oac-btn--icon:hover { color: var(--oac-danger); }\n.oac-widget .oac-templates__row.is-confirm { background: var(--oac-elev); }\n.oac-widget .oac-templates__message { margin: 4px 8px 0; font-size: 11px; color: var(--oac-mut); overflow-wrap: anywhere; }\n.oac-widget .oac-templates__message:empty { display: none; }\n.oac-widget .oac-templates__message.is-error { color: var(--oac-danger); }\n.oac-widget .oac-templates__foot { display: flex; padding: 6px 2px 0; margin-top: 4px; border-top: 1px solid var(--oac-bd-soft); }\n.oac-widget.is-mobile .oac-templates__row { min-height: 44px; }\n.oac-widget.is-mobile .oac-templates__row .oac-btn { height: 36px; }\n.oac-widget.is-mobile .oac-templates__row .oac-btn--icon { width: 36px; }\n";var Bl=Object.freeze({__proto__:null,openTemplatesMenu:function(e,o,n){const a=e.document;qn(a,Wl);const i=(t,o,n={})=>R(e,`schema.ui.templates.${t}`,n,o),r=nt(a,"div","oac-templates");r.setAttribute("role","dialog"),r.setAttribute("aria-label",i("title","Indicator templates"));const s=nt(a,"div","oac-head",R(e,"Templates")),l=nt(a,"div","oac-templates__list");l.setAttribute("role","list"),l.setAttribute("aria-label",R(e,"Templates"));const c=nt(a,"p","oac-templates__message");c.setAttribute("role","status"),c.setAttribute("aria-live","polite");const d=nt(a,"div","oac-templates__foot"),u=it(a,{label:i("save","Save studies as template..."),icon:"save",onClick:()=>function(){if("true"===u.getAttribute("aria-disabled"))return;g?.close(),g=Zn(e,u,async t=>{const o=await on(e,n,t);b(R(e,"Saved the template {name}",{name:o.name})),k()})}()});u.dataset.action="save-template",d.appendChild(u),r.append(s,l,c,d),st(r);let p=null,h=!1,m=null,g=null,f=!1;const b=(e,t=!1)=>{c.textContent=e,c.classList.toggle("is-error",t),c.setAttribute("role",t?"alert":"status")},v=t=>F(e,t),w=(e,t)=>{e.setAttribute("aria-disabled",String(null!==t)),null===t?e.removeAttribute("title"):e.title=t};function y(){const o=a.activeElement,n=null!==o&&l.contains(o)?{id:o.closest("[data-template-id]")?.dataset.templateId,action:o.dataset.action}:null;l.textContent="";const r=t.isReplaying(e.chart),s=p?.templates??[];null===p?l.appendChild(nt(a,"div","oac-empty",h?i("loadFailed","Templates could not be loaded"):i("loading","Loading templates"))):0===s.length&&l.appendChild(nt(a,"div","oac-empty",i("empty","No saved templates yet")));for(const e of s){const t=nt(a,"div","oac-templates__row");t.setAttribute("role","listitem"),t.dataset.templateId=e.id;const o=nt(a,"span","oac-templates__name",e.name),n=e.indicators.length,s=nt(a,"span","oac-templates__meta",1===n?i("one","1 study"):i("count","{count} studies",{count:n}));if(m===e.id){t.classList.add("is-confirm");const o=it(a,{label:i("keep","Keep"),onClick:()=>{m=null,y()}});o.dataset.action="keep";const n=it(a,{label:i("delete","Delete"),variant:"danger",onClick:()=>{x(e)}});n.dataset.action="confirm-delete",t.append(nt(a,"span","oac-templates__name",i("confirm","Delete {name}?",{name:e.name})),o,n),l.appendChild(t);continue}const c=r?i("replay","Stop the replay to apply a template"):null,d=it(a,{label:i("replace","Replace"),onClick:()=>_(e,"replace")});d.dataset.action="replace",d.setAttribute("aria-label",i("replaceNamed","Replace the studies with {name}",{name:e.name}));const u=it(a,{label:i("append","Append"),onClick:()=>_(e,"append")});u.dataset.action="append",u.setAttribute("aria-label",i("appendNamed","Add {name} to the studies",{name:e.name})),w(d,c),w(u,c);const p=it(a,{label:i("deleteNamed","Delete {name}",{name:e.name}),icon:"trash",iconOnly:!0,onClick:()=>{m=e.id,y(),l.querySelector('[data-action="keep"]')?.focus()}});p.dataset.action="delete",t.append(o,s,d,u,p),l.appendChild(t)}if(w(u,0===(e=>e.chart.indicators().filter(e=>!Zo(e.policy?.())).length)(e)?i("nothing","Add a study to save a template"):null),null!==n){const e=Array.from(l.querySelectorAll("[data-template-id]")).find(e=>e.dataset.templateId===n.id)??null,t="keep"===n.action?"delete":n.action;(e?.querySelector(`[data-action="${t}"]`)??e?.querySelector("button")??l.querySelector("button")??u).focus()}}function _(o,a){if(!t.isReplaying(e.chart))try{const t=void 0===o.layout?o.indicators:{indicators:o.indicators,layout:o.layout},r=tn(e,n,t,a,R(e,"Apply {name}",{name:o.name}));e.toast(r?i("applied","Applied {name}",{name:o.name}):i("nothingNew","{name} added nothing new",{name:o.name}),r?"success":"info"),T.close()}catch(e){b(i("applyFailed","{name} could not be applied: {error}",{name:o.name,error:v(e)}),!0)}}async function x(e){m=null;try{await n.remove("indicator-template",e.id),b(i("removed","Deleted {name}",{name:e.name})),await k()}catch(t){b(i("removeFailed","{name} could not be deleted: {error}",{name:e.name,error:v(t)}),!0),y()}}async function k(){try{const e=await n.load();(null===p||e.revision>=p.revision)&&(p=e),h=!1}catch(e){h=!0,null===p&&b(i("loadFailedWith","Templates could not be loaded: {error}",{error:v(e)}),!0)}f||y()}const C=n.subscribe(e=>{null!==p&&e.revision<=p.revision||(p=e,f||y())}),S=["replay:start","replay:stop","objects:change"].map(t=>e.chart.on(t,()=>{f||y()}));y(),k();const A=e.openOverlay(r,{anchor:o,placement:"below",initialFocus:null,onClose:()=>{f=!0,C();for(const e of S)e();g?.close()}});(l.querySelector("button")??u).focus();const T={el:r,isOpen:()=>!f,close:()=>{f||A()}};return T}});function Ul(e){const t=Xr[e];return n=o.layoutIconPath(t.rows,t.columns,t.slots),`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16" fill="none" stroke="currentColor" stroke-width="${o.CHROME_ICON_STROKE}" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="${n}"/></svg>`;var n}const ql=(e,t)=>{const o=u(e,"span","oac-glyph oac-glyph--chrome",{"aria-hidden":"true"});return o.innerHTML=t,o};const Kl="\n.oac-grid__bar .oac-grid__bar-text { max-width: 22ch; overflow: hidden; text-overflow: ellipsis; }\n.oac-grid__bar-mark { display: inline-flex; }\n.oac-grid__spacer { flex: 1 1 auto; }\n.oac-grid__saved { min-width: 0; }\n.oac-grid__saved[data-attention=\"true\"]::after { content: ''; width: 6px; height: 6px; flex: none; border-radius: 50%; background: var(--oac-amber); }\n/* A phone's bar keeps the glyph and the mark; the held layout's name stays in the tip and the accessible name. */\n@container oac-grid-bar (max-width: 520px) { .oac-grid__saved > .oac-grid__bar-text { display: none; } }\n";var Gl=Object.freeze({__proto__:null,attachGridSaved:function(e){const{grid:o}=e,n=!1===e.layouts?null:e.layouts??null;if(!1===e.layouts||null===n&&void 0===e.workspaces)return null;const a=(t,o,n={})=>R(e.context(),`schema.ui.layouts.${t}`,n,o),i=t=>{o.isDestroyed||e.context().status(t,"error")};let r=null,s=[];const l=()=>{for(const e of s.splice(0))e();const e=r;null!==e&&(s=o.cells().map(t=>Jo(t.widget).subscribe(e)))},c={capture(){const e=o.getWorkspace();return{...e,activePaneId:e.panes[0].id,panes:e.panes.map(e=>({...e,chart:Go(e.chart)}))}},apply:e=>o.applyWorkspace(e),subscribe(e){r=e,l();const t=[o.on("layout",({reason:t})=>{"preset"!==t&&"workspace"!==t||l(),e()}),o.on("links",e)];return()=>{r=null,l();for(const e of t)e()}},suspended:()=>o.cells().some(e=>t.isReplaying(e.widget.chart))},d=null===n?so(e.workspaces,c):null,u=n??d,p={handle:null,waiting:null};let h=!1;return null!==d&&(rn(d,a,i),e.ready.then(()=>h?null:d.reload()).then(async t=>{if(h||null==t||null===t.activeWorkspaceId||e.opened())return;const o=await d.open(t.activeWorkspaceId);o.applied||h||i(a("notReopened","The last layout could not open here: {error}",{error:o.reason??""}))}).catch(t=>{h||i(a("notLoaded","Saved layouts could not be read: {error}",{error:F(e.context(),t)}))})),{controller:u,open(t){h||cn(e.context(),u,t,p,()=>!h&&!o.isDestroyed)},status:()=>an(e.context(),u.state()),flush(){h||d?.flush()},destroy(){h||(h=!0,d?.destroy())}}},chrome:ql,layoutTileSvg:Ul,mountGridBar:function(e,t){const n=e.doc,a=(e=>e.text)(e);qn(n,Kl);const i=(e,t)=>u(n,"button",`oac-btn ${e}`,{type:"button","aria-label":t}),r=()=>{const e=u(n,"span","oac-chev",{"aria-hidden":"true"});return e.innerHTML=o.chromeIconSvg("chevron-down"),e},s=i("oac-grid__layout",R(a,"Arrange charts"));s.setAttribute("aria-haspopup","menu");const l=ql(n,o.chromeIconSvg("layout")),c=u(n,"span","oac-grid__bar-text");s.append(l,c,r()),e.tips.attach(s,()=>{const t=e.layout();return{title:os(t)?R(a,"Arrange charts: {name}",{name:ul(a,t)}):R(a,"Arrange charts"),side:"bottom"}}),s.addEventListener("click",()=>e.openMenu("layouts",s)),s.hidden=0===e.layouts.length;const d=i("oac-btn--icon oac-grid__max",R(a,"Maximize the chart")),p=ql(n,o.chromeIconSvg("maximize"));d.appendChild(p),e.tips.attach(d,()=>({title:R(a,e.maximized()?"Restore the grid":"Maximize the chart"),sub:e.maximizeBlocked()??void 0,side:"bottom"})),d.addEventListener("click",()=>{null===e.maximizeBlocked()&&e.toggleMaximize()});const h=i("oac-grid__link",R(a,"Link"));h.setAttribute("aria-haspopup","menu");const m=u(n,"span","oac-grid__bar-text");m.textContent=R(a,"Link");const g=u(n,"span","oac-grid__bar-mark");h.append(ql(n,o.chromeIconSvg("link")),m,g,r()),e.tips.attach(h,()=>{const t=e.links.current();return{title:R(a,"Link: {name}",{name:null===t?R(a,"Not linked"):t.name}),side:"bottom"}}),h.addEventListener("click",()=>e.openMenu("link",h));const f=i("oac-btn--icon oac-grid__capture",R(a,"Capture every chart"));f.setAttribute("aria-haspopup","menu"),f.appendChild(ql(n,o.chromeIconSvg("capture-grid"))),e.tips.attach(f,()=>({title:R(a,"Capture every chart"),sub:e.capture.blocked()??void 0,side:"bottom"})),f.addEventListener("click",()=>e.openMenu("capture",f));const b=()=>u(n,"span","oac-sep",{role:"separator"});t.append(s,d,b(),h,b(),f);let v=null,w=null;if(void 0!==e.saved){const{controller:r}=e.saved,s=R(a,"schema.ui.layouts.title",{},"Layouts"),l=()=>{const e=r.state();return e.catalog?.workspaces.find(t=>t.id===e.layoutId)?.name??null},c=v=i("oac-grid__saved",s);c.setAttribute("aria-haspopup","dialog");const d=u(n,"span","oac-grid__bar-text");c.append(ql(n,o.chromeIconSvg("folder")),d),e.tips.attach(c,()=>{const t=l(),o=null===t?s:`${s}: ${t}`,n=e.saved?.status();return{title:o,label:sn(r.state())?`${o}, ${n??""}`:void 0,sub:n,side:"bottom"}});const p=()=>{d.textContent=l()??s,c.dataset.attention=String(sn(r.state())),e.tips.refreshLabel(c)};w=r.subscribe(p),p(),c.addEventListener("click",()=>e.saved?.open(c)),t.append(u(n,"span","oac-grid__spacer"),c)}const y=[s,d,h,f,v].filter(e=>null!==e&&!e.hidden);t.addEventListener("keydown",e=>{const t=y.indexOf(n.activeElement),o=Ps(e.key,t,y.length,["ArrowLeft","ArrowRight"]);o<0||(e.preventDefault(),e.stopPropagation(),y[o].focus())});const _=()=>{const t=e.layout(),i=os(t);l.innerHTML=i?Ul(t):o.chromeIconSvg("layout"),c.textContent=i?ul(a,t):"",c.hidden=!i;const r=e.maximized();p.innerHTML=o.chromeIconSvg(r?"restore":"maximize");const u=e.maximizeBlocked();d.classList.toggle("is-off",null!==u),d.setAttribute("aria-disabled",String(null!==u));const m=e.links.current();g.replaceChildren(As(n,m)),f.classList.toggle("is-off",null!==e.capture.blocked());for(const t of[s,d,h,f])e.tips.refreshLabel(t);const b=e.tips.target();b!==s&&b!==d&&b!==h&&b!==f||e.tips.show(b)};return _(),{el:t,refresh:_,destroy:()=>{w?.(),t.textContent=""}}}});const Vl=e=>e.text;let Hl=0;const Jl={crosshair:o.chromeIconSvg("crosshair"),viewport:o.chromeIconSvg("time-range"),symbol:o.chromeIconSvg("search"),interval:o.chromeIconSvg("clock"),chartType:o.chromeIconSvg("chart-candlestick"),appearance:o.chromeIconSvg("palette"),drawings:o.chromeIconSvg("drawing-sync")},Zl={crosshair:"Crosshair",viewport:"Time range",symbol:"Symbol",interval:"Interval",chartType:"Chart type",appearance:"Appearance",drawings:"Drawings"};function Yl(e,t,n,a,i,r){const s=e.doc;qn(s,Ql);const l=u(s,"div","oac-menu oac-grid__menu",{role:"menu","aria-label":n}),c="oac-grid-note-"+ ++Hl;let d=()=>{};const p=(e=-1)=>{l.textContent="";let t=0;for(const e of a()){if("string"==typeof e){const t=u(s,"div","oac-head",{role:"presentation"});t.textContent=e,l.appendChild(t);continue}const n=u(s,"button","oac-menu__row",{type:"button",role:"radio"===e.kind?"menuitemradio":"check"===e.kind?"menuitemcheckbox":"menuitem","aria-disabled":String(!0===e.disabled)});if("action"!==e.kind&&n.setAttribute("aria-checked",String(!0===e.checked)),"check"===e.kind){const e=u(s,"span","oac-grid__box",{"aria-hidden":"true"});e.innerHTML=o.chromeIconSvg("check"),n.appendChild(e)}void 0!==e.icon&&n.appendChild(e.icon);const a=u(s,"span","oac-menu__label");if(a.textContent=e.label,n.appendChild(a),void 0!==e.sub){const t=u(s,"span","oac-menu__sub");t.textContent=e.sub,n.appendChild(t)}!0===e.disabled&&null!=r&&n.setAttribute("aria-describedby",c);const i=t++;n.addEventListener("click",t=>{t.stopPropagation(),!0!==e.disabled&&(!0!==e.stay&&d(),e.onSelect(),!0===e.stay&&p(i))}),l.appendChild(n)}if(null!=r){const e=u(s,"div","oac-grid__note",{role:"none",id:c});e.textContent=r,l.appendChild(e)}i?.(l,()=>p()),e>=0&&l.querySelectorAll(".oac-menu__row")[e]?.focus()};return p(),l.addEventListener("keydown",e=>{const t=Array.from(l.querySelectorAll(".oac-menu__row")),o=t.indexOf(s.activeElement),n=Ps(e.key,o,t.length,["ArrowUp","ArrowDown"],!0);n<0||(e.preventDefault(),e.stopPropagation(),t[n].focus())}),d=e.overlays.open(l,{anchor:t,placement:"below",initialFocus:l.querySelector('.oac-menu__row[aria-checked="true"]')??void 0}),d}const Ql='\n.oac-widget .oac-grid__menu { max-width: 380px; }\n.oac-grid__menu .oac-menu__row > .oac-glyph { color: var(--oac-mut); }\n.oac-grid__indent { width: 16px; flex: none; }\n.oac-grid__menu .oac-menu__row[role="menuitemcheckbox"]::before { display: none; }\n.oac-grid__menu .oac-menu__row[role="menuitemcheckbox"][aria-checked="true"] { color: var(--oac-tx); }\n.oac-grid__box { display: grid; place-items: center; width: 15px; height: 15px; flex: none; border: 1px solid var(--oac-bd);\n  border-radius: 4px; background: var(--oac-elev); }\n.oac-grid__box > svg { width: 11px; height: 11px; fill: none; stroke: var(--oac-bg); stroke-width: 2.4; stroke-linecap: round;\n  stroke-linejoin: round; opacity: 0; }\n.oac-grid__menu .oac-menu__row[aria-checked="true"] > .oac-grid__box { background: var(--oac-acc); border-color: var(--oac-acc); }\n.oac-grid__menu .oac-menu__row[aria-checked="true"] > .oac-grid__box > svg { opacity: 1; }\n.oac-grid__menu .oac-menu__row[aria-disabled="true"] > .oac-grid__box { opacity: .45; }\n.oac-grid__menu .oac-menu__row[role="menuitem"]::before { content: \'\'; width: 6px; margin: 0 2px 0 -2px; flex: none; }\n.oac-grid__rename { display: flex; align-items: center; gap: 6px; padding: 4px; }\n.oac-grid__rename > input { flex: 1 1 auto; min-width: 140px; }\n\n/* The layout picker: one row of tiles per chart count. */\n.oac-grid__picker { display: flex; flex-direction: column; gap: 2px; padding: 6px 8px 6px 6px; max-height: calc(100% - 16px);\n  overflow-y: auto; background: var(--oac-panel); border: 1px solid var(--oac-bd); border-radius: 10px; box-shadow: var(--oac-shadow); outline: none; }\n.oac-grid__picker-row { display: flex; align-items: center; gap: 3px; }\n.oac-grid__picker-count { width: 20px; margin-right: 4px; text-align: right; color: var(--oac-faint); font-size: 11px;\n  font-variant-numeric: tabular-nums; }\n.oac-grid__tile { display: grid; place-items: center; width: 34px; height: 30px; padding: 0; border: 1px solid transparent;\n  border-radius: 6px; background: transparent; color: var(--oac-mut); transition: background .1s, color .1s; }\n.oac-grid__tile > .oac-glyph > svg { width: 22px; height: 22px; stroke-width: 1.5; }\n.oac-grid__tile:hover, .oac-grid__tile:focus-visible { background: var(--oac-elev-2); color: var(--oac-tx); }\n.oac-grid__tile:focus-visible { outline: 2px solid var(--oac-ring); outline-offset: -2px; }\n.oac-grid__tile[aria-checked="true"] { background: var(--oac-on-bg); border-color: var(--oac-on-bd); color: var(--oac-acc-2); }\n.oac-grid__picker-caption { min-height: 16px; margin: 4px 0 0; padding: 5px 2px 0 28px; border-top: 1px solid var(--oac-bd-soft);\n  color: var(--oac-mut); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }\n.oac-grid__note { max-width: 260px; padding: 6px 8px 4px 31px; border-top: 1px solid var(--oac-bd-soft); margin-top: 3px;\n  color: var(--oac-faint); font-size: 11.5px; line-height: 1.4; }\n\n@media (prefers-reduced-motion: reduce) {\n  .oac-grid__tile { transition: none; }\n}\n';var Xl=Object.freeze({__proto__:null,openCaptureMenu:function(e,t){const n=Vl(e),a=e.capture.blocked(),i=e.capture.canCopy();return Yl(e,t,R(n,"Capture every chart"),()=>[{kind:"action",label:R(n,"Download PNG of every chart"),disabled:null!==a,icon:ql(e.doc,o.chromeIconSvg("download")),onSelect:()=>e.capture.download()},{kind:"action",label:R(n,"Copy image of every chart"),disabled:null!==a||!i,sub:null!==a?void 0:R(n,i?"paste it anywhere":"needs https or localhost"),icon:ql(e.doc,o.chromeIconSvg("copy")),onSelect:()=>e.capture.copy()}],void 0,a)},openLayoutPicker:function(e,t){const o=e.doc;qn(o,Ql);const n=u(o,"div","oac-grid__picker",{role:"menu","aria-label":R(Vl(e),"Arrange charts")}),a=[],i=e.layout(),r=new Map;for(const t of e.layouts){const e=Xr[t].slots.length;r.set(e,[...r.get(e)??[],t])}let s=()=>{};const l=t=>1===Xr[t].slots.length?ul(Vl(e),t):R(Vl(e),"{name}, {count} charts",{name:ul(Vl(e),t),count:Xr[t].slots.length}),c=u(o,"div","oac-grid__picker-caption",{"aria-hidden":"true"}),d=()=>{c.textContent=null!==i&&os(i)?l(i):""};for(const[t,d]of r){const r=u(o,"div","oac-grid__picker-row",{role:"group","aria-label":pl(Vl(e),t)}),p=u(o,"span","oac-grid__picker-count",{"aria-hidden":"true"});p.textContent=String(t),r.appendChild(p);const h=[];for(const t of d){const n=ul(Vl(e),t),a=u(o,"button","oac-grid__tile",{type:"button",role:"menuitemradio","aria-checked":String(t===i),"aria-label":n});a.dataset.layout=t,a.appendChild(ql(o,Ul(t)));const d=()=>{c.textContent=l(t)};a.addEventListener("pointerenter",d),a.addEventListener("focus",d),a.addEventListener("click",o=>{o.stopPropagation(),s(),e.setLayout(t)}),h.push(a),r.appendChild(a)}a.push(h),n.appendChild(r)}d(),n.appendChild(c),n.addEventListener("pointerleave",()=>{n.contains(o.activeElement)||d()});const p=a.flat();return n.addEventListener("keydown",e=>{const t=p.indexOf(o.activeElement);if(t<0)return;const n=a.findIndex(e=>e.includes(p[t])),i=a[n].indexOf(p[t]);let r;if("ArrowRight"===e.key)r=p[(t+1)%p.length];else if("ArrowLeft"===e.key)r=p[(t-1+p.length)%p.length];else if("ArrowDown"===e.key||"ArrowUp"===e.key){const t=a[(n+("ArrowDown"===e.key?1:a.length-1))%a.length];r=t[Math.min(i,t.length-1)]}else"Home"===e.key?r=p[0]:"End"===e.key&&(r=p[p.length-1]);void 0!==r&&(e.preventDefault(),e.stopPropagation(),r.focus())}),s=e.overlays.open(n,{anchor:t,placement:"below",initialFocus:p.find(e=>"true"===e.getAttribute("aria-checked"))??p[0]??void 0}),s},openLinkMenu:function(e,t){const n=e.doc,a=Vl(e);let i=!1;return Yl(e,t,R(a,"Linking"),()=>{const t=e.links.current(),r=[R(a,"Link group")];r.push({kind:"radio",label:R(a,"Not linked"),checked:null===t,icon:As(n,null),stay:!0,onSelect:()=>e.links.setGroup(null)});for(const o of e.links.groups())r.push({kind:"radio",label:o.name,sub:pl(a,o.cells.length),checked:t?.id===o.id,icon:As(n,o),stay:!0,onSelect:()=>e.links.setGroup(o.id)});if(r.push({kind:"action",label:R(a,"New group"),icon:ql(n,o.chromeIconSvg("plus")),stay:!0,onSelect:()=>e.links.newGroup()}),r.push({kind:"action",label:R(a,"Rename group"),icon:ql(n,o.chromeIconSvg("rename")),disabled:null===t,sub:null===t?R(a,"Link this chart to a group first"):void 0,stay:!0,onSelect:()=>{i=!0}}),null===t)return r;r.push(R(a,"Links in {group}",{group:t.name}));const s=t.links;for(const t of["crosshair","viewport","symbol","interval","chartType","appearance","drawings"])r.push({kind:"check",label:R(a,Zl[t]),checked:s[t],stay:!0,icon:ql(n,Jl[t]),sub:"drawings"===t?R(a,"same instrument only"):void 0,onSelect:()=>e.links.setChannel(t,!s[t])}),"crosshair"===t&&r.push({kind:"check",label:R(a,"Nearest bar"),sub:R(a,"where a chart has no bar at that time"),checked:"nearest"===s.whenMissing,disabled:!s.crosshair,stay:!0,icon:u(n,"span","oac-grid__indent"),onSelect:()=>e.links.setChannel("nearest","nearest"!==s.whenMissing)});return r.push({kind:"action",label:R(a,"Share this chart's drawings"),icon:ql(n,o.chromeIconSvg("drawing-sync")),disabled:!s.drawings,sub:s.drawings?void 0:R(a,"Switch Drawings on first"),onSelect:()=>e.links.share()}),r},(t,o)=>{const r=e.links.current();if(!i||null===r)return;t.textContent="";const s=u(n,"div","oac-grid__rename"),l=u(n,"input",void 0,{type:"text","aria-label":R(a,"Group name"),maxlength:"120"});l.value=r.name;const c=n=>{n&&""!==l.value.trim()&&e.links.rename(r.id,l.value.trim()),i=!1,o(),t.querySelector('.oac-menu__row[aria-checked="true"]')?.focus()};l.addEventListener("keydown",e=>{"Enter"===e.key&&(e.preventDefault(),c(!0))});const d=u(n,"button","oac-btn oac-btn--primary",{type:"button"});d.textContent=R(a,"Save"),d.addEventListener("click",e=>{e.stopPropagation(),c(!0)});const p=u(n,"button","oac-btn",{type:"button"});p.textContent=R(a,"Cancel"),p.addEventListener("click",e=>{e.stopPropagation(),c(!1)}),s.append(l,p,d),t.appendChild(s),l.focus(),l.select()})}});return e.ACCOUNT_SUMMARY_CSS=Cr,e.BOTTOMBAR_CSS=Oi,e.BOTTOMBAR_HEIGHT=28,e.CHART_GRID_CSS=lr,e.CHART_GRID_LAYOUTS=Xr,e.CHART_GRID_LAYOUT_NAMES=dl,e.CHART_GRID_PRESETS={"1x1":[1,1],"1x2":[1,2],"1x3":[1,3],"2x1":[2,1],"3x1":[3,1],"2x2":[2,2],"1x4":[1,4],"4x1":[4,1],"2x3":[2,3],"3x2":[3,2],"2x4":[2,4],"4x2":[4,2],"3x3":[3,3],"3x4":[3,4],"4x3":[4,3],"4x4":[4,4]},e.CHART_TYPE_LABELS=gn,e.COLOR_PICKER_CSS=Ve,e.ChartHistory=me,e.DATA_WINDOW_CSS=ar,e.DATE_NAVIGATION_CSS=fi,e.DEFAULT_INTERVALS=Er,e.DEFAULT_LOOKBACK_BARS=500,e.DEFAULT_RANGES=wi,e.DIALOG_CSS=pi,e.DRAWINGS_KEY_PREFIX="drawings:",e.DRAWING_COORDINATES_CSS=ia,e.DRAWING_TEMPLATES_CSS=Yn,e.DRAWING_TOOLBAR_CSS=Ui,e.DateNavigator=oo,e.EVENT_DETAILS_CSS=Xi,e.EventDetailsPopup=tr,e.KEYMAP_KEY=fe,e.Keymap=De,e.MAGNET_MODES=Ct,e.MIN_PRICE_DIGITS=2,e.NEWS_PANEL_CSS=Zi,e.NewsReader=Vi,e.OBJECTS_PANEL_CSS=Da,e.PANEL_DOCK_CSS=mo,e.QUICK_ENTRY_CSS=rr,e.QuoteBoard=gr,e.RAIL_GROUPS=St,e.RAIL_PREFS_KEY=Tt,e.RAIL_WIDTH=42,e.SAVE_DEBOUNCE_MS=250,e.SEARCH_DEBOUNCE_MS=150,e.STATE_KEY="state",e.STATUSLINE_HEIGHT=24,e.STORAGE_PREFIX=_,e.SYMBOL_PICKER_CSS=Jt,e.TEXT_CONTRAST=4.5,e.TIP_DWELL_MS=600,e.TOAST_LEAVE_MS=160,e.TOAST_MAX=5,e.TOAST_MS=xn,e.TOKEN_PREFIX=Sn,e.TOOLBAR_LINE_WIDTHS=zi,e.TOPBAR_HEIGHT=40,e.WATCHLIST_PANEL_CSS=xr,e.WIDGET_COMPONENT_CSS=Sr,e.WIDGET_CSS=Bn,e.WIDGET_DIALOGS=ui,e.WIDGET_FONT=Mn,e.WIDGET_MONO=zn,e.WIDGET_STATE_VERSION=1,e.WIDGET_STYLE_ID=Wn,e.WIDGET_TIER="widget",e.WidgetBus=P,e.WidgetStorage=x,e.applyIndicatorTemplate=tn,e.applyTokens=Rn,e.attachContextMenu=di,e.boxIn=w,e.captureName=yt,e.chartTypeChoices=bn,e.chartTypeLabel=fn,e.contextMenuEntries=ri,e.contrastRatio=In,e.controlsFromFields=ot,e.controlsFromInputs=Xe,e.createAlertUi=function(e,o){const n=e.ownerDocument;Un(n,Sr,o.styleNonce);const a=u(n,"div","oac-widget oac-alert-host");e.appendChild(a);const i=S(a,n),r=A(a,i.layer,n),s=u(n,"div","oac-toasts");a.appendChild(s);const l=kn(s,n,o);let c=o.theme??"dark",d=o.chartTheme??("light"===c?t.lightTheme:t.darkTheme),p=!1,h=!1,m=null;function g(){const e=i.size()>0;e!==h&&(h=e,o.onOpenChange?.(h))}const f={chart:o.chart,draw:o.draw,alerts:o.alerts,root:a,document:n,get theme(){return c},get chartTheme(){return d},keymap:new De,bus:new P,storage:new x("alert-ui",null),locale:o.locale,translate:o.translate,tips:r,overlays:i,toast:(e,t)=>l.toast(e,t),status:(e,t)=>{l.toast(e,t)},symbol:()=>({symbol:o.chart.getDataContext()?.symbol??"",exchange:o.chart.getDataContext()?.exchange??""}),interval:()=>o.chart.getDataContext()?.interval??"",openOverlay:(e,t)=>{const o=i.open(e,{...t,onClose:()=>{t?.onClose?.(),g()}});return g(),o}},b=e=>{e.stopPropagation()};a.addEventListener("keydown",b);const v=o.chart.on("destroy",()=>w.destroy()),w={root:a,context:f,openList:e=>!p&&(m?.isOpen()?(m.el.focus(),!0):(m=ei(f,e,{onClose:()=>{m=null}}),!0)),openEditor:e=>!p&&(Xa(f,void 0,e),!0),isOpen:()=>!p&&i.size()>0,close:()=>i.closeAll(),setTheme:(e,o)=>{p||(c=e,d=o??("light"===e?t.lightTheme:t.darkTheme),a.dataset.theme=e,Rn(a,Nn(d,e)))},destroy:()=>{p||(p=!0,v(),i.destroy(),r.destroy(),l.destroy(),f.keymap.destroy(),f.bus.clear(),a.removeEventListener("keydown",b),a.remove())}};return w.setTheme(c,d),w},e.createChartGrid=function(e,t={}){if("string"==typeof e){const o=(t.document??globalThis.document)?.querySelector(e);if(!o)throw new Error(`openalgo-charts grid: no element matches "${e}"`);e=o}const o=t.document??e.ownerDocument,n=t,a={...t};for(const e of Ds)delete a[e];Object.assign(a,{document:o,mobile:t.mobile??"never",captureRows:()=>function(e){if(e.cells.length<2)return[];const{text:t}=e,o=ys(e);return[R(t,"Every chart"),{label:R(t,"Download PNG of every chart"),sub:o??void 0,disabled:null!==o,onSelect:()=>xs(e)},{label:R(t,"Copy image of every chart"),sub:o??void 0,disabled:null!==o||!un(),onSelect:()=>ks(e)}]}(p)}),a.bottombar=!1,a.layouts=!0!==t.toolbar&&(t.layouts??!1);const i=u(o,"div","oac-grid"),r=u(o,"div","oac-grid__tabs",{role:"tablist","aria-label":R(n,"Charts")}),s=u(o,"div","oac-grid__cells");r.hidden=!0;const l=!0===t.toolbar?u(o,"div","oac-widget oac-grid__bar",{role:"toolbar","aria-label":R(n,"Chart grid")}):null,c=!0===t.bottombar?u(o,"div","oac-widget oac-grid__foot"):null;i.append(...null===l?[]:[l],r,s,...null===c?[]:[c]);const p={doc:o,options:t,text:n,cellOptions:a,bus:new P,links:new Ur(t.links),offs:[],root:i,tabs:r,body:s,barEl:l,footEl:c,splits:[],given:!1,cells:[],chords:null,sharing:!1,active:null,rows:1,cols:1,rowW:[1],colW:[1],preset:null,theme:t.theme??"dark",themeSync:!1,compact:!1,maxed:!1,pointerIn:!1,destroyed:!1,syncing:!1,nextId:0,saveTimer:0,saveQueued:!1,saveRefused:!1,held:!1,restored:null,drawings:new Map,chromeLayer:null,bar:null,foot:null,saved:null,ready:Promise.resolve()};p.storage=function(e){const{options:t,text:o}=e,n=t.persist?void 0===t.storage?ee():t.storage:null;return new x("string"==typeof t.persist?t.persist:"default",n,{onError:t=>{if(e.destroyed||null===e.active)return;const n=F(o,t.error),a=e.active.widget.context;if("load"!==t.operation)return void a.status(R(o,"Saved chart settings could not be written: {error}",{error:n}),"error");const i=R(o,"Saved chart settings could not be read, so changes are kept for this session only: {error}",{error:n});a.status(i,"error"),a.toast(i,"error")}})}(p),p.timeframePreferences=t.timeframePreferences??d(p.storage,t.intervals??Er),p.cellOptions.timeframePreferences=p.timeframePreferences,t.timeframePreferences||p.offs.push(()=>p.timeframePreferences.destroy()),p.restoring=!p.storage.loaded;const h=p.grid=function(e){const{links:t}=e,o={root:e.root,get ready(){return e.ready},get isDestroyed(){return e.destroyed},restored:()=>e.restored,cells:()=>e.cells.slice(),active:()=>e.active,theme:()=>Ir(e.theme).name,compact:()=>e.compact,maximized:()=>e.maxed&&null!==e.active?e.active.id:null,linkOptions:()=>t.optionsOf(e.active),linkGroups:()=>Hs(e),layout:()=>({rows:e.rows,columns:e.cols,preset:e.preset,rowWeights:e.rowW.slice(),columnWeights:e.colW.slice()}),on:(t,o)=>e.bus.on(t,o),setActive:(t,o)=>function(e,t,o={}){const n=e.cells.find(e=>e.id===t);if(void 0===n||e.destroyed)return!1;const a=n!==e.active,i=e.active?.group??null;e.active=n,Bs(e),o.focus&&n.widget.root.querySelector(".oac-chart")?.focus({preventScroll:!0});a&&(e.held||ss(e),zs(e,"active",{id:t}),i!==n.group&&zs(e,"links",e.grid.linkOptions()));return!0}(e,t,o),setPreset:t=>function(e,t){if(!os(t))throw new Error(`openalgo-charts grid: "${String(t)}" is not a preset or layout`);if(e.destroyed)return;const{links:o}=e,n=Xr[t],a=n.slots.length,i=e.cells.slice(0,a),r=function(e){const t=e.slots.map(t=>ns(e.rowWeights,t.row,t.rowSpan)*ns(e.columnWeights,t.column,t.columnSpan)),o=Math.max(...t);return t.every(e=>e===o)?-1:t.indexOf(o)}(n);r>=0&&null!==e.active&&!i.includes(e.active)&&i.splice(a-1,1,e.active);const s=e.active,l=null===s?o.groups[0]??o.create():s.group,c=e.active?.widget,d=void 0===c?e.options:{symbol:c.symbol(),exchange:c.exchange(),interval:c.interval(),variant:c.variant(),chartType:c.chartType(),historyPeriod:e.active?.historyPeriod},u=[];try{for(;i.length+u.length<a;){let t;do{t="p"+e.nextId++}while(e.cells.some(e=>e.id===t));u.push(Xs(e,t,d,e.body,e.theme,e.drawings))}}catch(t){throw u.forEach(t=>al(e,t)),t}e.maxed=!1,e.root.dataset.maximized="false";for(const t of e.cells.filter(e=>!i.includes(e)))al(e,t),e.drawings.delete(t.id);null!==e.active&&i.includes(e.active)||(e.active=i[0]??u[0]);const p=[...i,...u];r>=0&&(p.splice(p.indexOf(e.active),1),p.splice(r,0,e.active));if(p.forEach((e,t)=>Object.assign(e,n.slots[t])),e.cells=p,u.forEach(t=>nl(e,t)),null!==l)for(const e of u)o.join(e,l);o.prune(e.cells),e.rows=n.rows,e.cols=n.columns,e.rowW=n.rowWeights.slice(),e.colW=n.columnWeights.slice(),e.preset=t,Qs(e),ss(e),zs(e,"layout",{reason:"preset"}),e.active!==s&&zs(e,"active",{id:e.active.id})}(e,t),maximize(t){const n=void 0===t?e.active:e.cells.find(e=>e.id===t);return!(e.destroyed||null==n||e.cells.length<2)&&(o.setActive(n.id),qs(e,!0),!0)},restore(){e.destroyed||qs(e,!1)},swap:(t,o)=>function(e,t,o){const n=e.cells.find(e=>e.id===t),a=e.cells.find(e=>e.id===o);if(e.destroyed||void 0===n||void 0===a||n===a)return!1;const i=e=>({row:e.row,column:e.column,rowSpan:e.rowSpan,columnSpan:e.columnSpan}),[r,s]=[i(n),i(a)];return Object.assign(n,s),Object.assign(a,r),e.cells.sort((e,t)=>e.row-t.row||e.column-t.column),Qs(e),ss(e),zs(e,"layout",{reason:"swap"}),!0}(e,t,o),setLinks(n){const a=null!=e.active?.group?[e.active.group]:t.groups;for(const t of a)ll(e,t,n);ss(e),Zs(e),zs(e,"links",o.linkOptions())},setLinkGroup(o,n){const a=e.cells.find(e=>e.id===o),i=null===n?null:t.find(n);return!e.destroyed&&void 0!==a&&void 0!==i&&(null===i?t.leave(a):t.join(a,i),Ys(e),!0)},addLinkGroup(o,n={}){const a=e.cells.find(e=>e.id===o);if(e.destroyed||void 0===a)return null;const i=n.name?.trim(),r=t.create({name:void 0===i||""===i?null:i.slice(0,120),links:n.links});return null===r?null:(t.join(a,r),Ys(e),r.id)},setGroupLinks(n,a){const i=t.find(n);return!e.destroyed&&void 0!==i&&(ll(e,i,a),ss(e),Zs(e),zs(e,"links",o.linkOptions()),!0)},renameLinkGroup(o,n){const a=t.find(o),i=n.trim();return!(e.destroyed||void 0===a||""===i||i.length>120)&&(a.name=i,Ys(e),!0)},shareDrawings(t){const o=e.cells.find(e=>e.id===t),n=o?.group;return e.destroyed||void 0===o||null==n||!n.links.options().drawings?0:n.drawings.share(o.widget.chart)},setTheme(t){e.theme=t,Rs(e),e.themeSync=!0;try{for(const o of e.cells)o.widget.setTheme(t)}finally{e.themeSync=!1}ss(e),zs(e,"theme",{theme:Ir(t).name})},takeScreenshot:()=>Cs(e),downloadScreenshot:t=>Ss(e,t),getWorkspace:()=>function(e){const t=e.links.trivial(e.cells),o={layout:{rows:e.rows,columns:e.cols,slots:e.cells.map(e=>({paneId:e.id,row:e.row,column:e.column,rowSpan:e.rowSpan,columnSpan:e.columnSpan})),...null===e.preset?{}:{preset:e.preset},rowWeights:e.rowW.slice(),columnWeights:e.colW.slice()},panes:e.cells.map(e=>{const o=e.widget.getState();return{...Vo(e.id,o,o.chart),historyPeriod:e.historyPeriod,...t||null===e.group?{}:{linkGroup:e.group.id}}}),activePaneId:e.active.id,sync:e.links.sync(e.cells,t=>Vs(e,t))};return JSON.parse(JSON.stringify(o))}(e),applyWorkspace(t){const o=cl(e,t,new Map);return o.applied&&(e.given=!0),o},destroy:()=>function(e){if(e.destroyed)return;ls(e),e.storage.flush(),e.storage.close(),e.destroyed=!0;for(const t of e.offs.splice(0))t();e.saved?.destroy(),e.foot?.destroy(),e.chromeLayer?.overlays.destroy(),e.chromeLayer?.tips.destroy(),e.bar?.destroy(),e.cells.splice(0).forEach(t=>al(e,t)),e.links.destroy(),e.root.remove(),e.bus.clear()}(e)};return o}(p);if(p.barHost=function(e){const{doc:t,text:o,options:n}=e,a={waiting:null},i={doc:t,text:o,get overlays(){return Ns(e).overlays},get tips(){return Ns(e).tips},layouts:(n.presets??Object.keys(Xr)).filter(os),layout:()=>e.preset,setLayout:t=>e.grid.setPreset(t),maximized:()=>e.maxed,maximizeBlocked:()=>Ks(e),toggleMaximize:()=>Gs(e),links:{groups:()=>Hs(e),current:()=>Js(e,e.active?.group??null),setGroup:t=>{null!==e.active&&e.grid.setLinkGroup(e.active.id,t)},newGroup:()=>{null!==e.active&&e.grid.addLinkGroup(e.active.id)},rename:(t,o)=>e.grid.renameLinkGroup(t,o),setChannel:(t,o)=>{const n=e.active?.group;null!=n&&e.grid.setGroupLinks(n.id,"nearest"===t?{whenMissing:o?"nearest":"hide"}:{[t]:o})},share:()=>{const t=null===e.active?0:e.grid.shareDrawings(e.active.id);return _s(e,t>0?R(o,1===t?"Shared {count} drawing":"Shared {count} drawings",{count:t}):R(o,"No drawing here can be shared")),t}},capture:{blocked:()=>ys(e),download:()=>xs(e),copy:()=>ks(e),canCopy:un},get saved(){return e.saved??void 0},openMenu:(n,r)=>H(js,e=>{"layouts"===n?e.openLayoutPicker(i,r):"link"===n?e.openLinkMenu(i,r):e.openCaptureMenu(i,r)},t=>_s(e,J(o,R(o,"layouts"===n?"Arrange charts":"link"===n?"Linking":"Capture every chart"),t),"error"),()=>!e.destroyed&&r.isConnected,{slot:a,doc:t,from:r})};return i}(p),Rs(p),e.appendChild(i),function(e){const{doc:t,root:o,tabs:n,offs:a}=e,i=(e,t,o,n=!1)=>{e.addEventListener(t,o,n),a.push(()=>e.removeEventListener(t,o,n))};i(n,"keydown",o=>{const a=Array.from(n.children),i=Ps(o.key,a.indexOf(t.activeElement),a.length,["ArrowLeft","ArrowRight"]),r=e.cells[i];i<0||void 0===r||(o.preventDefault(),o.stopPropagation(),e.grid.setActive(r.id),n.children[i]?.focus())}),i(o,"pointerdown",t=>il(e,t.target),!0),i(o,"focusin",t=>il(e,t.target)),i(o,"pointerenter",()=>{e.pointerIn=!0}),i(o,"pointerleave",()=>{e.pointerIn=!1}),a.push(Is({doc:t,body:e.body,root:o,cells:()=>e.cells,enabled:()=>!ms(e)&&e.cells.length>1,swap:(t,o)=>e.grid.swap(t.id,o.id),toggleMaximize:t=>{e.cells.length>1&&!e.compact&&(e.grid.setActive(t.id),Gs(e,t))}}));const r=t.defaultView,s=r?.ResizeObserver;if(void 0!==s){const t=new s(()=>Us(e));t.observe(o),a.push(()=>t.disconnect())}null!=r&&"function"==typeof r.addEventListener&&(void 0===s&&i(r,"resize",()=>Us(e)),i(r,"pagehide",()=>ds(e,!1)));i(t,"visibilitychange",()=>{"hidden"===t.visibilityState&&ds(e,!0)})}(p),function(e,t){e.restoring?(e.grid.setPreset(e.options.preset??"1x1"),e.root.style.visibility="hidden",e.ready=e.storage.load().then(()=>{if(!e.destroyed){e.timeframePreferences.reload(),e.restoring=!1;try{us(e,!0,t)}catch(t){e.grid.active().widget.context.toast(R(e.text,"The saved layout could not be restored: {error}",{error:F(e.text,t)}),"error")}finally{e.root.style.visibility=""}}})):us(e,!1,t)}(p,(e,t)=>cl(p,e,t)),null!==c){const{tips:e,overlays:n}=Ns(p),a=c.appendChild(u(o,"div"));p.foot=Li({document:o,locale:t.locale,translate:t.translate,tips:e,openOverlay:n.open,status:(e,t)=>p.active?.widget.context.status(e,t)},a,{target:()=>p.active?.widget??null,ranges:t.ranges,now:t.now,onGoTo:()=>p.active?.widget.openDateNavigation()}),p.offs.push(p.bus.on("active",()=>p.foot?.refresh()))}return null!==l&&H($s,e=>{p.saved=e.attachGridSaved({grid:h,ready:p.ready,workspaces:t.workspaces,layouts:t.layouts,context:()=>Fs(p,p.active.widget.context),opened:()=>p.given}),p.bar=e.mountGridBar(p.barHost,l)},e=>_s(p,J(n,R(n,"Chart grid"),e),"error"),()=>!p.destroyed),Us(p),h},e.createColorPicker=Ge,e.createDrawingTemplates=Vn,e.createIndexedDbWidgetStorage=function(e,t=Z,o={}){const n=void 0===o.journal?C():o.journal;return Q(a=>a.openIndexedDbStore(e,t,{...o,journal:n}),n)},e.createLayoutsController=so,e.createObjectsPanelContent=$a,e.createOverlayStack=S,e.createTimeframePreferences=c,e.createTipController=A,e.createWidget=zr,e.customTimeframeCode=a,e.defaultStorage=C,e.downloadText=wt,e.esc=e=>String(e).replace(/[&<>"]/g,e=>"&"===e?"&amp;":"<"===e?"&lt;":">"===e?"&gt;":"&quot;"),e.eventKeyCombo=ke,e.focusable=m,e.focusables=g,e.formatColor=Ln,e.formatKeyCombo=Se,e.fromChartCombo=Te,e.glyph=p,e.h=u,e.historyPress=L,e.historyReady=I,e.inTextField=h,e.injectWidgetStyles=Un,e.inputConditionMet=He,e.inputStates=Ze,e.intervalLabel=vn,e.loadWindow=Pr,e.luminance=On,e.mix=jn,e.mountAccountSummary=kr,e.mountAlertEditor=Xa,e.mountAlertsPanel=ei,e.mountBottombar=Li,e.mountContextMenu=ci,e.mountDataWindow=nr,e.mountDrawingCoordinates=aa,e.mountDrawingProperties=_a,e.mountDrawingToolbar=Bi,e.mountIndicatorInputControls=Sa,e.mountIndicatorPicker=ka,e.mountIndicatorSettings=Fa,e.mountLevelEditor=la,e.mountMobile=Mi,e.mountNewsPanel=Ji,e.mountObjectsPanel=ja,e.mountPanelDock=ho,e.mountQuickEntry=ir,e.mountRail=It,e.mountSettingsDialog=Ba,e.mountStatusline=Ut,e.mountSymbolPicker=Ht,e.mountTextEditor=ga,e.mountToasts=kn,e.mountTopbar=_n,e.mountWatchlistPanel=_r,e.openCustomTimeframeDialog=K,e.openDateNavigation=gi,e.openLayoutsMenu=function(e,t,o){return ln.load().then(n=>{if(e.chart.isDestroyed)throw new Error("The widget was destroyed before its Layouts menu opened");return n.mountLayoutsMenu(e,t,o)})},e.openMenu=vt,e.openShortcutsPanel=We,e.openTimeframeMenu=G,e.parseColor=Tn,e.parseKeyCombo=xe,e.placeBelow=b,e.placeBeside=f,e.placeTip=v,e.priceDigits=Wt,e.quoteChange=hr,e.rangeInterval=_i,e.rangeWindow=Si,e.readDataWindow=function(e,t,o={}){const n=e.primaryBars();return or(e,n,t,o,n.some(e=>Number.isFinite(e.oi)))},e.readableOn=Pn,e.registerWidgetDialog=j,e.registerWidgetDialogs=D,e.registeredWidgetDialogs=function(){return Array.from($.keys())},e.renderForm=ft,e.resolveTheme=Ir,e.safeNewsUrl=Hi,e.safeSymbolIconUrl=Gt,e.sanitizePanelDockState=po,e.sanitizeRailPrefs=Ot,e.saveIndicatorTemplate=on,e.stripView=function(e){return _o(e)},e.themeMode=$n,e.token=Fn,e.toolGlyph=Lt,e.toolName=At,e.unregisterWidgetDialog=function(e){return $.delete(e)},e.widgetDialog=M,e.widgetLayoutTarget=Jo,e.widgetText=R,e.widgetTokens=Nn,e.withAlpha=Dn,e}({},OpenAlgoCharts,OpenAlgoCharts.draw);