@tradecanvas/chart 1.62.0 → 1.63.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/Chart.d.ts +6 -0
  2. package/dist/Chart.d.ts.map +1 -1
  3. package/dist/{LayoutSession-D1OOl-zS.js → LayoutSession-B65QLG6S.js} +139 -121
  4. package/dist/LayoutSession-B65QLG6S.js.map +1 -0
  5. package/dist/LayoutSession-K38h-AF0.cjs +2 -0
  6. package/dist/LayoutSession-K38h-AF0.cjs.map +1 -0
  7. package/dist/{i18n-CbKY8gH2.js → i18n-D5fU6Iwy.js} +9 -1
  8. package/dist/i18n-D5fU6Iwy.js.map +1 -0
  9. package/dist/i18n-DxRoJCYV.cjs +2 -0
  10. package/dist/i18n-DxRoJCYV.cjs.map +1 -0
  11. package/dist/index.cjs +1 -1
  12. package/dist/index.js +1 -1
  13. package/dist/widget/WidgetHotkeySheet.d.ts.map +1 -1
  14. package/dist/widget/index.cjs +2 -2
  15. package/dist/widget/index.cjs.map +1 -1
  16. package/dist/widget/index.js +23 -2
  17. package/dist/widget/index.js.map +1 -1
  18. package/dist/widget/locales/ar.d.ts.map +1 -1
  19. package/dist/widget/locales/cs.d.ts.map +1 -1
  20. package/dist/widget/locales/da.d.ts.map +1 -1
  21. package/dist/widget/locales/de.d.ts.map +1 -1
  22. package/dist/widget/locales/el.d.ts.map +1 -1
  23. package/dist/widget/locales/en.d.ts +4 -0
  24. package/dist/widget/locales/en.d.ts.map +1 -1
  25. package/dist/widget/locales/es.d.ts.map +1 -1
  26. package/dist/widget/locales/et.d.ts.map +1 -1
  27. package/dist/widget/locales/fa.d.ts.map +1 -1
  28. package/dist/widget/locales/fr.d.ts.map +1 -1
  29. package/dist/widget/locales/he.d.ts.map +1 -1
  30. package/dist/widget/locales/hu.d.ts.map +1 -1
  31. package/dist/widget/locales/id.d.ts.map +1 -1
  32. package/dist/widget/locales/index.cjs +1 -1
  33. package/dist/widget/locales/index.cjs.map +1 -1
  34. package/dist/widget/locales/index.js +113 -1
  35. package/dist/widget/locales/index.js.map +1 -1
  36. package/dist/widget/locales/it.d.ts.map +1 -1
  37. package/dist/widget/locales/ja.d.ts.map +1 -1
  38. package/dist/widget/locales/ko.d.ts.map +1 -1
  39. package/dist/widget/locales/ms.d.ts.map +1 -1
  40. package/dist/widget/locales/nb.d.ts.map +1 -1
  41. package/dist/widget/locales/nl.d.ts.map +1 -1
  42. package/dist/widget/locales/pl.d.ts.map +1 -1
  43. package/dist/widget/locales/pt.d.ts.map +1 -1
  44. package/dist/widget/locales/ro.d.ts.map +1 -1
  45. package/dist/widget/locales/ru.d.ts.map +1 -1
  46. package/dist/widget/locales/sk.d.ts.map +1 -1
  47. package/dist/widget/locales/sv.d.ts.map +1 -1
  48. package/dist/widget/locales/th.d.ts.map +1 -1
  49. package/dist/widget/locales/tr.d.ts.map +1 -1
  50. package/dist/widget/locales/vi.d.ts.map +1 -1
  51. package/dist/widget/locales/zh.d.ts.map +1 -1
  52. package/dist/widget/locales/zhHant.d.ts.map +1 -1
  53. package/package.json +3 -3
  54. package/dist/LayoutSession-D1OOl-zS.js.map +0 -1
  55. package/dist/LayoutSession-D4mWBj_P.cjs +0 -2
  56. package/dist/LayoutSession-D4mWBj_P.cjs.map +0 -1
  57. package/dist/i18n-BISr49ZU.cjs +0 -2
  58. package/dist/i18n-BISr49ZU.cjs.map +0 -1
  59. package/dist/i18n-CbKY8gH2.js.map +0 -1
@@ -1,4 +1,4 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../LayoutSession-D4mWBj_P.cjs`),t=require(`../i18n-BISr49ZU.cjs`);let n=require(`@tradecanvas/commons`),r=require(`@tradecanvas/core`);function i(e,t,r={}){return(0,n.resampleBars)(e,t,{weekStartsOn:r.weekStartsOn??1,timeZone:r.timeZone})}function a(e){if(e.length<2)return 0;let t=[];for(let n=1;n<e.length;n++){let r=e[n].time-e[n-1].time;r>0&&t.push(r)}return t.length===0?0:(t.sort((e,t)=>e-t),t[Math.floor(t.length/2)])}var o=[{zone:`Pacific/Honolulu`,city:`Honolulu`},{zone:`America/Los_Angeles`,city:`Los Angeles`},{zone:`America/Denver`,city:`Denver`},{zone:`America/Chicago`,city:`Chicago`},{zone:`America/New_York`,city:`New York`},{zone:`America/Toronto`,city:`Toronto`},{zone:`America/Sao_Paulo`,city:`São Paulo`},{zone:`UTC`,city:`UTC`},{zone:`Europe/London`,city:`London`},{zone:`Europe/Berlin`,city:`Frankfurt`},{zone:`Europe/Paris`,city:`Paris`},{zone:`Europe/Zurich`,city:`Zurich`},{zone:`Africa/Johannesburg`,city:`Johannesburg`},{zone:`Europe/Istanbul`,city:`Istanbul`},{zone:`Europe/Moscow`,city:`Moscow`},{zone:`Asia/Dubai`,city:`Dubai`},{zone:`Asia/Kolkata`,city:`Mumbai`},{zone:`Asia/Bangkok`,city:`Bangkok`},{zone:`Asia/Ho_Chi_Minh`,city:`Ho Chi Minh City`},{zone:`Asia/Jakarta`,city:`Jakarta`},{zone:`Asia/Singapore`,city:`Singapore`},{zone:`Asia/Hong_Kong`,city:`Hong Kong`},{zone:`Asia/Shanghai`,city:`Shanghai`},{zone:`Asia/Taipei`,city:`Taipei`},{zone:`Asia/Seoul`,city:`Seoul`},{zone:`Asia/Tokyo`,city:`Tokyo`},{zone:`Australia/Sydney`,city:`Sydney`},{zone:`Pacific/Auckland`,city:`Auckland`}],s=/^-?\d+$/,c=840;function l(e){if(!s.test(e))return null;let t=Number(e);return Math.abs(t)<=c?t:null}function u(e){return!e||e===`local`?null:e===`exchange`?`exchange`:s.test(e)?l(e):(0,n.isValidTimeZone)(e)?e:null}function d(e){return e===null?`local`:String(e)}function f(e,t,r,i){let a=(0,n.offsetAt)(null,t),s=o.filter(({zone:e})=>(0,n.isValidTimeZone)(e)).map(({zone:e,city:r})=>{let i=(0,n.offsetAt)(e,t);return{value:e,label:e===`UTC`?`UTC`:`(${(0,n.tzLabel)(i)}) ${r}`,offset:i}}),c=u(e);typeof c==`number`&&s.push({value:e,label:(0,n.tzLabel)(c),offset:c}),s.sort((e,t)=>e.offset-t.offset);let l=[{value:`local`,label:`${r} (${(0,n.tzLabel)(a)})`,offset:a}];if(i){let e=(0,n.offsetAt)(i.zone&&(0,n.isValidTimeZone)(i.zone)?i.zone:`UTC`,t);l.push({value:`exchange`,label:`${i.label} (${(0,n.tzLabel)(e)})`,offset:e})}return[...l,...s]}var p=6,m=8,h=120;function ee(e,t,n=`left`){let r=e.style,i=t.getBoundingClientRect();r.position=`fixed`,r.margin=`0`,r.top=r.bottom=r.left=r.right=``;let a=window.innerHeight-i.bottom-p-m,o=i.top-p-m;e.scrollHeight<=a||a>=o?(r.top=`${i.bottom+p}px`,r.bottom=`auto`,r.maxHeight=`${Math.max(h,a)}px`):(r.top=`auto`,r.bottom=`${window.innerHeight-i.top+p}px`,r.maxHeight=`${Math.max(h,o)}px`);let s=getComputedStyle(t).direction===`rtl`,c=n===`right`!==s,l=e.offsetWidth,u=c?i.right-l:i.left;r.left=`${Math.max(m,Math.min(u,window.innerWidth-l-m))}px`}var te=700,g=class{select=null;panel=null;rows=[];active=-1;typed=``;typedAt=0;onOutside=e=>{let t=e.target;this.panel?.contains(t)||this.select?.contains(t)||this.close(!1)};onAway=()=>this.close(!1);onScroll=e=>{e.target instanceof Node&&this.panel?.contains(e.target)||this.close(!1)};watch=new MutationObserver(()=>{this.select&&!this.select.isConnected&&this.close(!1)});constructor(e){this.layer=e}isOpenFor(e){return this.select===e}owns(e){return e!==null&&(e===this.select||this.panel?.contains(e)===!0)}open(e){this.close(!1),this.select=e;let t=document.createElement(`div`);t.className=`tcw-dropdown tcw-select-menu`,t.setAttribute(`role`,`listbox`),t.id=`tcw-select-menu-${Math.random().toString(36).slice(2,9)}`;let n=e.getAttribute(`aria-label`)??e.labels?.[0]?.textContent??``;n&&t.setAttribute(`aria-label`,n.trim()),t.style.minWidth=`${e.getBoundingClientRect().width}px`,this.rows=[];for(let n of e.children)if(n instanceof HTMLOptGroupElement){let e=document.createElement(`div`);e.className=`tcw-select-group`,e.textContent=n.label,t.appendChild(e);for(let e of n.querySelectorAll(`option`))this.addRow(t,e,n.disabled)}else n instanceof HTMLOptionElement&&this.addRow(t,n,!1);t.addEventListener(`mousedown`,e=>e.preventDefault());let r=e=>this.rows.findIndex(t=>t.el.contains(e.target));t.addEventListener(`click`,e=>{let t=r(e);t>=0&&this.pick(t)}),t.addEventListener(`mousemove`,e=>{let t=r(e);t>=0&&t!==this.active&&this.enabled(t)&&this.setActive(t,!1)}),this.layer().appendChild(t),this.panel=t,ee(t,e),e.setAttribute(`aria-expanded`,`true`),e.setAttribute(`aria-controls`,t.id),this.setActive(this.rows.findIndex(e=>e.option.selected)),document.addEventListener(`pointerdown`,this.onOutside,!0),window.addEventListener(`resize`,this.onAway),document.addEventListener(`scroll`,this.onScroll,{capture:!0,passive:!0}),this.watch.observe(document.documentElement,{childList:!0,subtree:!0})}close(e){let t=this.select;t&&(document.removeEventListener(`pointerdown`,this.onOutside,!0),window.removeEventListener(`resize`,this.onAway),document.removeEventListener(`scroll`,this.onScroll,{capture:!0}),this.watch.disconnect(),this.panel?.remove(),this.panel=null,this.rows=[],this.select=null,t.setAttribute(`aria-expanded`,`false`),t.removeAttribute(`aria-controls`),t.removeAttribute(`aria-activedescendant`),e&&t.isConnected&&t.focus())}key(e){if(!this.select)return!1;switch(e.key){case`ArrowDown`:return this.step(1),!0;case`ArrowUp`:return this.step(-1),!0;case`Home`:return this.setActive(this.nextEnabled(-1,1)),!0;case`End`:return this.setActive(this.nextEnabled(this.rows.length,-1)),!0;case`PageDown`:return this.step(8),!0;case`PageUp`:return this.step(-8),!0;case` `:return this.typed&&Date.now()-this.typedAt<=te?(this.typeahead(` `),!0):(this.active>=0?this.pick(this.active):this.close(!0),!0);case`Enter`:return this.active>=0?this.pick(this.active):this.close(!0),!0;case`Escape`:return this.close(!0),!0;case`Tab`:return this.close(!1),!1;default:return e.key.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey?(this.typeahead(e.key),!0):!1}}destroy(){this.close(!1)}addRow(e,t,n){let r=document.createElement(`div`);r.className=`tcw-select-option`,r.id=`${e.id}-${this.rows.length}`,r.setAttribute(`role`,`option`),r.setAttribute(`aria-selected`,String(t.selected)),(t.disabled||n)&&r.setAttribute(`aria-disabled`,`true`);let i=document.createElement(`span`);i.className=`tcw-select-option-text`,i.textContent=t.label||t.textContent||``,t.dir&&(i.dir=t.dir);let a=document.createElement(`span`);a.className=`tcw-select-check`,a.setAttribute(`aria-hidden`,`true`),r.append(a,i),e.appendChild(r),this.rows.push({option:t,el:r})}enabled(e){return this.rows[e]?.el.getAttribute(`aria-disabled`)!==`true`}nextEnabled(e,t){for(let n=e+t;n>=0&&n<this.rows.length;n+=t)if(this.enabled(n))return n;return-1}step(e){let t=e>0?1:-1,n=this.active;for(let r=0;r<Math.abs(e);r++){let e=this.nextEnabled(n,t);if(e<0)break;n=e}n>=0&&this.setActive(n)}setActive(e,t=!0){this.rows[this.active]?.el.classList.remove(`tcw-active`),this.active=e;let n=this.rows[e];n&&(n.el.classList.add(`tcw-active`),this.select?.setAttribute(`aria-activedescendant`,n.el.id),t&&n.el.scrollIntoView?.({block:`nearest`}))}typeahead(e){let t=Date.now();this.typed=t-this.typedAt>te?e.toLowerCase():this.typed+e.toLowerCase(),this.typedAt=t;let n=e=>this.enabled(e)&&(this.rows[e].el.textContent??``).trim().toLowerCase().startsWith(this.typed),r=this.typed.length===1?this.active+1:Math.max(0,this.active);for(let e=0;e<this.rows.length;e++){let t=(r+e)%this.rows.length;if(n(t)){this.setActive(t);return}}}pick(e){let t=this.select,n=this.rows[e];if(!t||!n||!this.enabled(e))return;let r=!n.option.selected;n.option.selected=!0,this.close(!0),r&&(t.dispatchEvent(new Event(`input`,{bubbles:!0})),t.dispatchEvent(new Event(`change`,{bubbles:!0})))}},_=42,v=7,y=new Set([`US`,`CA`,`MX`,`BR`,`JP`,`KR`,`TW`,`HK`,`IL`,`PH`,`IN`,`ZA`,`AU`,`TH`,`SA`,`PE`,`CO`]);function b(e){try{let t=new Intl.Locale(e),n=t.getWeekInfo?.()??t.weekInfo;return n?n.firstDay===7?0:1:+!y.has(t.maximize().region??``)}catch{return 1}}function x(e,t,n){let r=(new Date(Date.UTC(e,t,1)).getUTCDay()-n+v)%v,i=[];for(let n=0;n<_;n++){let a=new Date(Date.UTC(e,t,1-r+n));i.push({year:a.getUTCFullYear(),month:a.getUTCMonth(),day:a.getUTCDate()})}return i}var ne=e=>String(e).padStart(2,`0`),S=e=>`${String(e.year).padStart(4,`0`)}-${ne(e.month+1)}-${ne(e.day)}`;function re(e){let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e??``);return t?{year:Number(t[1]),month:Number(t[2])-1,day:Number(t[3])}:null}function ie(){let e=new Date;return{year:e.getFullYear(),month:e.getMonth(),day:e.getDate()}}function ae(e,t){let n=new Date(Date.UTC(e.year,e.month,e.day+t));return{year:n.getUTCFullYear(),month:n.getUTCMonth(),day:n.getUTCDate()}}var oe=class{element;grid;titleEl;chosen=``;limits={};today=S(ie());view={year:0,month:0};focusDay=ie();constructor(e,t,n){this.locale=t,this.onPick=n;let r=document.createElement(`div`);r.className=`tcw-calendar`;let i=document.createElement(`div`);i.className=`tcw-calendar-head`;let a=document.createElement(`div`);a.className=`tcw-calendar-title`,a.setAttribute(`aria-live`,`polite`),i.append(this.navButton(e.prevMonth,-1),a,this.navButton(e.nextMonth,1));let o=document.createElement(`div`);o.className=`tcw-calendar-weekdays`,o.setAttribute(`aria-hidden`,`true`);let s=b(t),c=new Intl.DateTimeFormat(t,{weekday:`narrow`,timeZone:`UTC`});for(let e=0;e<v;e++){let t=document.createElement(`span`);t.className=`tcw-calendar-weekday`,t.textContent=c.format(new Date(Date.UTC(2023,0,1+(s+e)%v))),o.appendChild(t)}let l=document.createElement(`div`);l.className=`tcw-calendar-grid`,l.setAttribute(`role`,`grid`),l.addEventListener(`keydown`,e=>this.onKey(e)),l.addEventListener(`click`,e=>{let t=e.target.closest(`.tcw-calendar-day`);t&&!t.disabled&&t.dataset.date&&this.pick(t.dataset.date)});let u=document.createElement(`div`);u.className=`tcw-calendar-foot`;let d=document.createElement(`button`);d.type=`button`,d.className=`tcw-calendar-today`,d.textContent=e.today,d.addEventListener(`click`,()=>this.pick(this.today)),u.appendChild(d),r.append(i,o,l,u),this.element=r,this.grid=l,this.titleEl=a}show(e,t={}){this.chosen=e,this.limits=t,this.today=re(t.today)?t.today:S(ie());let n=this.clamp(re(e)??re(this.today));this.focusDay=n,this.view={year:n.year,month:n.month},this.render()}focusGrid(){this.grid.querySelector(`[tabindex="0"]`)?.focus()}navButton(e,t){let n=document.createElement(`button`);return n.type=`button`,n.className=`tcw-calendar-nav`,n.setAttribute(`aria-label`,e),n.innerHTML=t<0?`<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M10 3.5L5.5 8l4.5 4.5"/></svg>`:`<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M6 3.5L10.5 8 6 12.5"/></svg>`,n.addEventListener(`click`,()=>this.turn(t)),n}turn(e){let t=new Date(Date.UTC(this.view.year,this.view.month+e,1));this.view={year:t.getUTCFullYear(),month:t.getUTCMonth()};let n=new Date(Date.UTC(this.view.year,this.view.month+1,0)).getUTCDate();this.focusDay=this.clamp({...this.view,day:Math.min(this.focusDay.day,n)}),this.view={year:this.focusDay.year,month:this.focusDay.month},this.render()}clamp(e){let t=S(e),n=re(this.limits.min),r=re(this.limits.max);return n&&t<S(n)?n:r&&t>S(r)?r:e}allowed(e){let{min:t,max:n}=this.limits;return!(t&&e<t)&&!(n&&e>n)}render(){let e=this.locale;this.titleEl.textContent=new Intl.DateTimeFormat(e,{month:`long`,year:`numeric`,timeZone:`UTC`}).format(new Date(Date.UTC(this.view.year,this.view.month,1)));let t=this.today,n=S(this.focusDay),r=new Intl.DateTimeFormat(e,{dateStyle:`full`,timeZone:`UTC`});this.grid.textContent=``;let i=null;for(let[a,o]of x(this.view.year,this.view.month,b(e)).entries()){a%v===0&&(i=document.createElement(`div`),i.className=`tcw-calendar-week`,i.setAttribute(`role`,`row`),this.grid.appendChild(i));let e=S(o),s=document.createElement(`button`);s.type=`button`,s.className=`tcw-calendar-day`,s.dataset.date=e,s.setAttribute(`role`,`gridcell`),s.textContent=String(o.day),s.setAttribute(`aria-label`,r.format(new Date(Date.UTC(o.year,o.month,o.day)))),s.setAttribute(`aria-selected`,String(e===this.chosen)),s.tabIndex=e===n?0:-1,o.month!==this.view.month&&s.classList.add(`tcw-outside`),e===t&&s.classList.add(`tcw-today`),this.allowed(e)||(s.disabled=!0),i?.appendChild(s)}}onKey(e){let t={ArrowLeft:-1,ArrowRight:1,ArrowUp:-v,ArrowDown:v},n=this.element.isConnected&&getComputedStyle(this.element).direction===`rtl`;if(e.key in t){let r=n&&(e.key===`ArrowLeft`||e.key===`ArrowRight`)?-t[e.key]:t[e.key];this.moveFocus(ae(this.focusDay,r))}else if(e.key===`PageUp`||e.key===`PageDown`)this.turn(e.key===`PageUp`?-1:1),this.focusGrid();else if(e.key===`Home`||e.key===`End`){let t=new Date(Date.UTC(this.view.year,this.view.month+1,0)).getUTCDate();this.moveFocus({...this.view,day:e.key===`Home`?1:t})}else if(e.key===`Enter`||e.key===` `)this.pick(S(this.focusDay));else return;e.preventDefault()}moveFocus(e){let t=this.clamp(e);this.focusDay=t,(t.year!==this.view.year||t.month!==this.view.month)&&(this.view={year:t.year,month:t.month}),this.render(),this.focusGrid()}pick(e){this.allowed(e)&&this.onPick(e)}},se=class{input=null;view=null;onOutside=e=>{let t=e.target;this.view?.element.contains(t)||this.input?.contains(t)||this.close(!1)};onAway=()=>this.close(!1);onScroll=e=>{e.target instanceof Node&&this.view?.element.contains(e.target)||this.close(!1)};watch=new MutationObserver(()=>{this.input&&!this.input.isConnected&&this.close(!1)});constructor(e,t,n){this.layer=e,this.labels=t,this.locale=n}isOpenFor(e){return this.input===e}owns(e){return e!==null&&(e===this.input||this.view?.element.contains(e)===!0)}open(e){this.close(!1),this.input=e;let t=new oe(this.labels(),this.locale(),e=>this.pick(e));t.show(e.value,{min:e.min||void 0,max:e.max||void 0});let n=t.element;n.setAttribute(`role`,`dialog`);let r=e.getAttribute(`aria-label`)??e.labels?.[0]?.textContent??``;r&&n.setAttribute(`aria-label`,r.trim()),n.addEventListener(`mousedown`,e=>{e.target.closest(`button`)||e.preventDefault()}),n.addEventListener(`keydown`,e=>{e.stopPropagation(),e.key===`Escape`&&(e.preventDefault(),this.close(!0))}),this.view=t,this.layer().appendChild(n),ee(n,e),document.addEventListener(`pointerdown`,this.onOutside,!0),window.addEventListener(`resize`,this.onAway),document.addEventListener(`scroll`,this.onScroll,{capture:!0,passive:!0}),this.watch.observe(document.documentElement,{childList:!0,subtree:!0})}close(e){let t=this.input;t&&(document.removeEventListener(`pointerdown`,this.onOutside,!0),window.removeEventListener(`resize`,this.onAway),document.removeEventListener(`scroll`,this.onScroll,{capture:!0}),this.watch.disconnect(),this.view?.element.remove(),this.view=null,this.input=null,e&&t.isConnected&&t.focus())}focusGrid(){this.view?.focusGrid()}destroy(){this.close(!1)}pick(e){let t=this.input;if(!t)return;let n=t.value!==e;t.value=e,this.close(!0),n&&(t.dispatchEvent(new Event(`input`,{bubbles:!0})),t.dispatchEvent(new Event(`change`,{bubbles:!0})))}},ce=()=>typeof matchMedia==`function`&&matchMedia(`(pointer: coarse)`).matches,le=()=>typeof CSS>`u`||typeof CSS.supports!=`function`||CSS.supports(`selector(::-webkit-calendar-picker-indicator)`);function ue(e){if(!(e instanceof Element))return null;let t=e.closest(`select`);return!t||t.matches(`:disabled`)||t.multiple||t.size>1?null:t}function de(e){return!(e instanceof HTMLInputElement)||e.type!==`date`||e.dataset.tcwCalendar===`inline`||e.matches(`:disabled`)||e.readOnly?null:e}function fe(e,t){let n=new g(t.layer),r=new se(t.layer,t.labels,t.locale),i=t.native??ce,a=t.calendar??le,o=new WeakSet,s=e=>o.has(e)?!1:(o.add(e),!0),c=e=>{if(e.button!==0||i()||!s(e))return;let t=ue(e.target);if(t){if(e.preventDefault(),n.isOpenFor(t)){n.close(!0);return}t.focus(),n.open(t)}},l=e=>{if(i()||!a()||!s(e))return;let t=de(e.target);t&&(e.preventDefault(),r.isOpenFor(t)||r.open(t))},u=e=>{if(i()||!s(e))return;let t=ue(e.target);if(t){if(n.isOpenFor(t)){n.key(e)&&(e.preventDefault(),e.stopPropagation());return}(e.key===`Enter`||e.key===` `||e.altKey&&(e.key===`ArrowDown`||e.key===`ArrowUp`)||e.key===`F4`)&&(e.preventDefault(),e.stopPropagation(),n.open(t));return}let o=de(e.target);!o||!a()||(e.key===`Escape`&&r.isOpenFor(o)?(e.preventDefault(),e.stopPropagation(),r.close(!0)):(e.altKey&&e.key===`ArrowDown`||e.key===`F4`)&&(e.preventDefault(),r.isOpenFor(o)||r.open(o),r.focusGrid()))},d=e=>{if(!s(e))return;let t=e.target instanceof Node?e.target:null,i=e.relatedTarget instanceof Node?e.relatedTarget:null;n.owns(t)&&!n.owns(i)&&n.close(!1),r.owns(t)&&!r.owns(i)&&r.close(!1)};for(let t of e)t.addEventListener(`mousedown`,c,!0),t.addEventListener(`click`,l,!0),t.addEventListener(`keydown`,u,!0),t.addEventListener(`focusout`,d,!0);return()=>{for(let t of e)t.removeEventListener(`mousedown`,c,!0),t.removeEventListener(`click`,l,!0),t.removeEventListener(`keydown`,u,!0),t.removeEventListener(`focusout`,d,!0);n.destroy(),r.destroy()}}var pe=[{label:`Candlestick`,value:`candlestick`},{label:`Line`,value:`line`},{label:`Area`,value:`area`},{label:`Bar`,value:`bar`},{label:`Heikin-Ashi`,value:`heikinAshi`},{label:`Hollow Candle`,value:`hollowCandle`},{label:`Baseline`,value:`baseline`},{label:`Volume Candles`,value:`volumeCandles`},{label:`Equivolume`,value:`equivolume`},{label:`HLC Area`,value:`hlcArea`},{label:`Step Line`,value:`stepLine`},{label:`Line + Markers`,value:`lineWithMarkers`},{label:`High-Low`,value:`hiLo`},{label:`Renko`,value:`renko`},{label:`Line Break`,value:`lineBreak`},{label:`Kagi`,value:`kagi`},{label:`Point & Figure`,value:`pointAndFigure`},{label:`Range Bars`,value:`rangeBars`}],me=[{label:`Lines`,section:`lines`,tools:[{label:`Trend Line`,value:`trendLine`},{label:`Ray`,value:`ray`},{label:`Extended Line`,value:`extendedLine`},{label:`Info Line`,value:`infoLine`},{label:`Trend Angle`,value:`trendAngle`}]},{label:`Horizontal/Vertical`,section:`lines`,tools:[{label:`Horizontal Line`,value:`horizontalLine`},{label:`Horizontal Ray`,value:`horizontalRay`},{label:`Vertical Line`,value:`verticalLine`},{label:`Cross Line`,value:`crossLine`}]},{label:`Channels`,section:`lines`,tools:[{label:`Parallel Channel`,value:`parallelChannel`},{label:`Regression Channel`,value:`regressionChannel`}]},{label:`Fibonacci`,section:`fibonacci`,tools:[{label:`Fib Retracement`,value:`fibRetracement`},{label:`Fib Extension`,value:`fibExtension`},{label:`Fib Channel`,value:`fibChannel`},{label:`Fib Time Zones`,value:`fibTimeZones`},{label:`Fib Speed Resistance Fan`,value:`fibSpeedResistanceFan`},{label:`Fib Speed Resistance Arcs`,value:`fibArcs`},{label:`Fib Circles`,value:`fibCircles`},{label:`Fib Spiral`,value:`fibSpiral`},{label:`Fib Wedge`,value:`fibWedge`}]},{label:`Gann & Pitchforks`,section:`fibonacci`,tools:[{label:`Pitchfork`,value:`pitchfork`},{label:`Schiff Pitchfork`,value:`schiffPitchfork`},{label:`Modified Schiff Pitchfork`,value:`modifiedSchiffPitchfork`},{label:`Gann Fan`,value:`gannFan`},{label:`Gann Box`,value:`gannBox`},{label:`Gann Square`,value:`gannSquare`},{label:`Pitchfan`,value:`pitchfan`}]},{label:`Cycles`,section:`fibonacci`,tools:[{label:`Cyclic Lines`,value:`cyclicLines`},{label:`Time Cycles`,value:`timeCycles`},{label:`Sine Line`,value:`sineLine`}]},{label:`Patterns`,section:`patterns`,tools:[{label:`XABCD Pattern`,value:`xabcdPattern`},{label:`ABCD Pattern`,value:`abcdPattern`},{label:`Head and Shoulders`,value:`headAndShoulders`},{label:`Cypher Pattern`,value:`cypherPattern`},{label:`Three Drives Pattern`,value:`threeDrives`}]},{label:`Elliott Waves`,section:`patterns`,tools:[{label:`Elliott Wave`,value:`elliottWave`},{label:`Elliott Impulse Wave`,value:`elliottImpulse`},{label:`Elliott Correction Wave`,value:`elliottCorrection`},{label:`Elliott Triangle Wave`,value:`elliottTriangle`},{label:`Elliott Double Combo Wave`,value:`elliottDoubleCombo`},{label:`Elliott Triple Combo Wave`,value:`elliottTripleCombo`}]},{label:`Forecasting`,section:`forecasting`,tools:[{label:`Long/Short Position`,value:`riskReward`},{label:`Anchored VWAP`,value:`anchoredVWAP`},{label:`Fixed Range Volume Profile`,value:`volumeProfileRange`},{label:`Forecast`,value:`forecast`},{label:`Projection`,value:`projection`},{label:`Bars Pattern`,value:`barsPattern`}]},{label:`Measure`,section:`forecasting`,tools:[{label:`Price Range`,value:`priceRange`},{label:`Date Range`,value:`dateRange`},{label:`Date and Price Range`,value:`dateAndPriceRange`},{label:`Measure`,value:`measure`}]},{label:`Shapes`,section:`annotation`,tools:[{label:`Rectangle`,value:`rectangle`},{label:`Circle`,value:`circle`},{label:`Ellipse`,value:`ellipse`},{label:`Triangle`,value:`triangle`},{label:`Polyline`,value:`polyline`},{label:`Curve`,value:`curve`},{label:`Arc`,value:`arc`}]},{label:`Brushes`,section:`annotation`,tools:[{label:`Brush`,value:`brush`},{label:`Highlighter`,value:`highlighter`},{label:`Path`,value:`path`}]},{label:`Annotation`,section:`annotation`,tools:[{label:`Text`,value:`text`},{label:`Price Label`,value:`priceLabel`},{label:`Arrow`,value:`arrow`},{label:`Note`,value:`note`},{label:`Callout`,value:`callout`},{label:`Flag Mark`,value:`flag`},{label:`Arrow Mark`,value:`arrowMark`},{label:`Icon`,value:`icon`}]}],he=[`BTCUSDT`,`ETHUSDT`,`SOLUSDT`,`BNBUSDT`],ge={gridVisible:!0,volumeVisible:!0,volumeProfileVisible:!1,marketProfileVisible:!1,marketProfileSplit:!1,marketProfileLetters:!1,marketProfileBuckets:48,marketProfileOpacity:.32,depthHeatmapVisible:!1,depthHeatmapOpacity:.7,sessionShadingVisible:!1,pivotMarkersVisible:!1,pivotStrength:5,pivotStructureLabels:!1,periodLevelsVisible:!1,periodLevelsPeriod:`day`,legendVisible:!0,barCountdown:!0,indicatorValueLabels:!1,alignAxisLabels:!0,logScale:!1,scaleMode:`regular`,autoScale:!0,invertScale:!1,leftPriceScale:!1,crosshairMode:`magnet`,numberLocale:`en-US`,timezone:`local`,highLowLines:!1,mainSeriesVisible:!0,extendedHours:!0,chartTypeOptions:{}},C=(e,...t)=>({label:e,keys:t}),w=(e,t,n={})=>({label:e,keys:[t],auto:n}),T=e=>({hint:e}),_e={from:`panes.titleColor`},ve={title:`settings.section.lastPrice`,rows:[C(`settings.priceLine`,`lastPrice.visible`),C(`settings.up`,`lastPrice.upColor`),C(`settings.down`,`lastPrice.downColor`),C(`drawingSettings.lineStyle`,`lastPrice.style`),C(`drawingSettings.lineWidth`,`lastPrice.width`)]},ye={title:`settings.volume`,rows:[C(`settings.up`,`volume.upColor`),C(`settings.down`,`volume.downColor`)]},be={title:`settings.highLowLines`,rows:[w(`drawingSettings.color`,`highLow.color`,_e)]},xe=[ve,ye,be],Se=[C(`settings.legendText`,`legend.textColor`),C(`settings.legendLabels`,`legend.labelColor`)],Ce=[...Se,C(`settings.paneTitles`,`panes.titleColor`)],we=[C(`drawingSettings.text`,`axis.price.textColor`,`axis.time.textColor`),C(`settings.scaleLines`,`axis.price.lineColor`,`axis.time.lineColor`)],Te=[{title:`settings.section.background`,rows:[C(`settings.background`,`background.color`),C(`settings.paneBackground`,`panes.background`),C(`settings.paneSeparator`,`panes.separatorColor`),w(`settings.watermark`,`watermark.color`,_e)]},{title:`settings.gridLines`,rows:[C(`settings.horizontal`,`grid.horizontal.visible`),C(`settings.vertical`,`grid.vertical.visible`),C(`drawingSettings.color`,`grid.horizontal.color`,`grid.vertical.color`),C(`drawingSettings.lineStyle`,`grid.horizontal.style`,`grid.vertical.style`),C(`drawingSettings.lineWidth`,`grid.horizontal.width`,`grid.vertical.width`)]},{title:`settings.crosshairMode`,rows:[C(`settings.horizontal`,`crosshair.horizontal.visible`),C(`settings.vertical`,`crosshair.vertical.visible`),C(`drawingSettings.color`,`crosshair.horizontal.color`,`crosshair.vertical.color`),C(`drawingSettings.lineStyle`,`crosshair.horizontal.style`,`crosshair.vertical.style`),C(`drawingSettings.lineWidth`,`crosshair.horizontal.width`,`crosshair.vertical.width`),C(`settings.labelBackground`,`crosshair.labelBackground`),C(`settings.labelText`,`crosshair.labelTextColor`)]},{title:`settings.sessionBreaks`,rows:[w(`drawingSettings.color`,`sessionBreaks.color`,{from:`axis.price.lineColor`}),w(`drawingSettings.lineStyle`,`sessionBreaks.style`),w(`drawingSettings.lineWidth`,`sessionBreaks.width`)]},{title:`objects.drawings`,rows:[w(`settings.handles`,`drawings.handleColor`,T(`#ffffff`))]}],Ee=[{title:`settings.section.orders`,trading:!0,rows:[w(`ticket.buy`,`trading.buyColor`,T(n.DEFAULT_TRADING_CONFIG.orderColors?.buy)),w(`ticket.sell`,`trading.sellColor`,T(n.DEFAULT_TRADING_CONFIG.orderColors?.sell)),w(`settings.profit`,`trading.profitColor`,T(n.DEFAULT_TRADING_CONFIG.positionColors?.profit)),w(`settings.loss`,`trading.lossColor`,T(n.DEFAULT_TRADING_CONFIG.positionColors?.loss)),w(`account.entry`,`trading.entryColor`,T(n.DEFAULT_TRADING_CONFIG.positionColors?.entry))]},{title:`settings.section.signals`,rows:[w(`account.long`,`markers.longColor`,T(n.DEFAULT_SIGNAL_STYLE.longColor)),w(`account.short`,`markers.shortColor`,T(n.DEFAULT_SIGNAL_STYLE.shortColor)),w(`markers.neutral`,`markers.neutralColor`,T(n.DEFAULT_SIGNAL_STYLE.neutralColor))]},{title:`settings.section.tradeZones`,rows:[w(`settings.profit`,`tradeZones.profitColor`,T(n.DEFAULT_TRADE_ZONE_STYLE.profitColor)),w(`settings.loss`,`tradeZones.lossColor`,T(n.DEFAULT_TRADE_ZONE_STYLE.lossColor)),w(`settings.openTrade`,`tradeZones.activeColor`,T(n.DEFAULT_TRADE_ZONE_STYLE.activeColor))]}],De={upColor:`settings.up`,downColor:`settings.down`,wickUpColor:`settings.upWick`,wickDownColor:`settings.downWick`,color:`drawingSettings.color`,lineColor:`drawingSettings.color`,lineWidth:`drawingSettings.lineWidth`,topColor:`settings.areaTop`,bottomColor:`settings.areaBottom`},Oe=new Set([`candlestick`,`heikinAshi`,`volumeCandles`,`equivolume`]);function ke(e){let t=`series.${e}.`;return Object.keys(n.CHART_STYLE_KEYS).filter(e=>e.startsWith(t)).map(n=>{let r=n.slice(t.length),i=De[r]??`drawingSettings.color`;return Oe.has(e)&&r===`upColor`&&(i=`settings.upBody`),Oe.has(e)&&r===`downColor`&&(i=`settings.downBody`),e===`baseline`&&r===`upColor`&&(i=`settings.aboveBase`),e===`baseline`&&r===`downColor`&&(i=`settings.belowBase`),C(i,n)})}var E=[...new Set([...Object.keys(n.CHART_STYLE_KEYS).filter(e=>e.startsWith(`series.`)),...[...xe,...Te,...Ee].flatMap(e=>e.rows.flatMap(e=>e.keys)),...[...Ce,...we].flatMap(e=>e.keys)])],Ae=`/* === TradeCanvas Widget — Premium Styles === */
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../LayoutSession-K38h-AF0.cjs`),t=require(`../i18n-DxRoJCYV.cjs`);let n=require(`@tradecanvas/commons`),r=require(`@tradecanvas/core`);function i(e,t,r={}){return(0,n.resampleBars)(e,t,{weekStartsOn:r.weekStartsOn??1,timeZone:r.timeZone})}function a(e){if(e.length<2)return 0;let t=[];for(let n=1;n<e.length;n++){let r=e[n].time-e[n-1].time;r>0&&t.push(r)}return t.length===0?0:(t.sort((e,t)=>e-t),t[Math.floor(t.length/2)])}var o=[{zone:`Pacific/Honolulu`,city:`Honolulu`},{zone:`America/Los_Angeles`,city:`Los Angeles`},{zone:`America/Denver`,city:`Denver`},{zone:`America/Chicago`,city:`Chicago`},{zone:`America/New_York`,city:`New York`},{zone:`America/Toronto`,city:`Toronto`},{zone:`America/Sao_Paulo`,city:`São Paulo`},{zone:`UTC`,city:`UTC`},{zone:`Europe/London`,city:`London`},{zone:`Europe/Berlin`,city:`Frankfurt`},{zone:`Europe/Paris`,city:`Paris`},{zone:`Europe/Zurich`,city:`Zurich`},{zone:`Africa/Johannesburg`,city:`Johannesburg`},{zone:`Europe/Istanbul`,city:`Istanbul`},{zone:`Europe/Moscow`,city:`Moscow`},{zone:`Asia/Dubai`,city:`Dubai`},{zone:`Asia/Kolkata`,city:`Mumbai`},{zone:`Asia/Bangkok`,city:`Bangkok`},{zone:`Asia/Ho_Chi_Minh`,city:`Ho Chi Minh City`},{zone:`Asia/Jakarta`,city:`Jakarta`},{zone:`Asia/Singapore`,city:`Singapore`},{zone:`Asia/Hong_Kong`,city:`Hong Kong`},{zone:`Asia/Shanghai`,city:`Shanghai`},{zone:`Asia/Taipei`,city:`Taipei`},{zone:`Asia/Seoul`,city:`Seoul`},{zone:`Asia/Tokyo`,city:`Tokyo`},{zone:`Australia/Sydney`,city:`Sydney`},{zone:`Pacific/Auckland`,city:`Auckland`}],s=/^-?\d+$/,c=840;function l(e){if(!s.test(e))return null;let t=Number(e);return Math.abs(t)<=c?t:null}function u(e){return!e||e===`local`?null:e===`exchange`?`exchange`:s.test(e)?l(e):(0,n.isValidTimeZone)(e)?e:null}function d(e){return e===null?`local`:String(e)}function f(e,t,r,i){let a=(0,n.offsetAt)(null,t),s=o.filter(({zone:e})=>(0,n.isValidTimeZone)(e)).map(({zone:e,city:r})=>{let i=(0,n.offsetAt)(e,t);return{value:e,label:e===`UTC`?`UTC`:`(${(0,n.tzLabel)(i)}) ${r}`,offset:i}}),c=u(e);typeof c==`number`&&s.push({value:e,label:(0,n.tzLabel)(c),offset:c}),s.sort((e,t)=>e.offset-t.offset);let l=[{value:`local`,label:`${r} (${(0,n.tzLabel)(a)})`,offset:a}];if(i){let e=(0,n.offsetAt)(i.zone&&(0,n.isValidTimeZone)(i.zone)?i.zone:`UTC`,t);l.push({value:`exchange`,label:`${i.label} (${(0,n.tzLabel)(e)})`,offset:e})}return[...l,...s]}var p=6,m=8,h=120;function ee(e,t,n=`left`){let r=e.style,i=t.getBoundingClientRect();r.position=`fixed`,r.margin=`0`,r.top=r.bottom=r.left=r.right=``;let a=window.innerHeight-i.bottom-p-m,o=i.top-p-m;e.scrollHeight<=a||a>=o?(r.top=`${i.bottom+p}px`,r.bottom=`auto`,r.maxHeight=`${Math.max(h,a)}px`):(r.top=`auto`,r.bottom=`${window.innerHeight-i.top+p}px`,r.maxHeight=`${Math.max(h,o)}px`);let s=getComputedStyle(t).direction===`rtl`,c=n===`right`!==s,l=e.offsetWidth,u=c?i.right-l:i.left;r.left=`${Math.max(m,Math.min(u,window.innerWidth-l-m))}px`}var te=700,g=class{select=null;panel=null;rows=[];active=-1;typed=``;typedAt=0;onOutside=e=>{let t=e.target;this.panel?.contains(t)||this.select?.contains(t)||this.close(!1)};onAway=()=>this.close(!1);onScroll=e=>{e.target instanceof Node&&this.panel?.contains(e.target)||this.close(!1)};watch=new MutationObserver(()=>{this.select&&!this.select.isConnected&&this.close(!1)});constructor(e){this.layer=e}isOpenFor(e){return this.select===e}owns(e){return e!==null&&(e===this.select||this.panel?.contains(e)===!0)}open(e){this.close(!1),this.select=e;let t=document.createElement(`div`);t.className=`tcw-dropdown tcw-select-menu`,t.setAttribute(`role`,`listbox`),t.id=`tcw-select-menu-${Math.random().toString(36).slice(2,9)}`;let n=e.getAttribute(`aria-label`)??e.labels?.[0]?.textContent??``;n&&t.setAttribute(`aria-label`,n.trim()),t.style.minWidth=`${e.getBoundingClientRect().width}px`,this.rows=[];for(let n of e.children)if(n instanceof HTMLOptGroupElement){let e=document.createElement(`div`);e.className=`tcw-select-group`,e.textContent=n.label,t.appendChild(e);for(let e of n.querySelectorAll(`option`))this.addRow(t,e,n.disabled)}else n instanceof HTMLOptionElement&&this.addRow(t,n,!1);t.addEventListener(`mousedown`,e=>e.preventDefault());let r=e=>this.rows.findIndex(t=>t.el.contains(e.target));t.addEventListener(`click`,e=>{let t=r(e);t>=0&&this.pick(t)}),t.addEventListener(`mousemove`,e=>{let t=r(e);t>=0&&t!==this.active&&this.enabled(t)&&this.setActive(t,!1)}),this.layer().appendChild(t),this.panel=t,ee(t,e),e.setAttribute(`aria-expanded`,`true`),e.setAttribute(`aria-controls`,t.id),this.setActive(this.rows.findIndex(e=>e.option.selected)),document.addEventListener(`pointerdown`,this.onOutside,!0),window.addEventListener(`resize`,this.onAway),document.addEventListener(`scroll`,this.onScroll,{capture:!0,passive:!0}),this.watch.observe(document.documentElement,{childList:!0,subtree:!0})}close(e){let t=this.select;t&&(document.removeEventListener(`pointerdown`,this.onOutside,!0),window.removeEventListener(`resize`,this.onAway),document.removeEventListener(`scroll`,this.onScroll,{capture:!0}),this.watch.disconnect(),this.panel?.remove(),this.panel=null,this.rows=[],this.select=null,t.setAttribute(`aria-expanded`,`false`),t.removeAttribute(`aria-controls`),t.removeAttribute(`aria-activedescendant`),e&&t.isConnected&&t.focus())}key(e){if(!this.select)return!1;switch(e.key){case`ArrowDown`:return this.step(1),!0;case`ArrowUp`:return this.step(-1),!0;case`Home`:return this.setActive(this.nextEnabled(-1,1)),!0;case`End`:return this.setActive(this.nextEnabled(this.rows.length,-1)),!0;case`PageDown`:return this.step(8),!0;case`PageUp`:return this.step(-8),!0;case` `:return this.typed&&Date.now()-this.typedAt<=te?(this.typeahead(` `),!0):(this.active>=0?this.pick(this.active):this.close(!0),!0);case`Enter`:return this.active>=0?this.pick(this.active):this.close(!0),!0;case`Escape`:return this.close(!0),!0;case`Tab`:return this.close(!1),!1;default:return e.key.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey?(this.typeahead(e.key),!0):!1}}destroy(){this.close(!1)}addRow(e,t,n){let r=document.createElement(`div`);r.className=`tcw-select-option`,r.id=`${e.id}-${this.rows.length}`,r.setAttribute(`role`,`option`),r.setAttribute(`aria-selected`,String(t.selected)),(t.disabled||n)&&r.setAttribute(`aria-disabled`,`true`);let i=document.createElement(`span`);i.className=`tcw-select-option-text`,i.textContent=t.label||t.textContent||``,t.dir&&(i.dir=t.dir);let a=document.createElement(`span`);a.className=`tcw-select-check`,a.setAttribute(`aria-hidden`,`true`),r.append(a,i),e.appendChild(r),this.rows.push({option:t,el:r})}enabled(e){return this.rows[e]?.el.getAttribute(`aria-disabled`)!==`true`}nextEnabled(e,t){for(let n=e+t;n>=0&&n<this.rows.length;n+=t)if(this.enabled(n))return n;return-1}step(e){let t=e>0?1:-1,n=this.active;for(let r=0;r<Math.abs(e);r++){let e=this.nextEnabled(n,t);if(e<0)break;n=e}n>=0&&this.setActive(n)}setActive(e,t=!0){this.rows[this.active]?.el.classList.remove(`tcw-active`),this.active=e;let n=this.rows[e];n&&(n.el.classList.add(`tcw-active`),this.select?.setAttribute(`aria-activedescendant`,n.el.id),t&&n.el.scrollIntoView?.({block:`nearest`}))}typeahead(e){let t=Date.now();this.typed=t-this.typedAt>te?e.toLowerCase():this.typed+e.toLowerCase(),this.typedAt=t;let n=e=>this.enabled(e)&&(this.rows[e].el.textContent??``).trim().toLowerCase().startsWith(this.typed),r=this.typed.length===1?this.active+1:Math.max(0,this.active);for(let e=0;e<this.rows.length;e++){let t=(r+e)%this.rows.length;if(n(t)){this.setActive(t);return}}}pick(e){let t=this.select,n=this.rows[e];if(!t||!n||!this.enabled(e))return;let r=!n.option.selected;n.option.selected=!0,this.close(!0),r&&(t.dispatchEvent(new Event(`input`,{bubbles:!0})),t.dispatchEvent(new Event(`change`,{bubbles:!0})))}},_=42,v=7,y=new Set([`US`,`CA`,`MX`,`BR`,`JP`,`KR`,`TW`,`HK`,`IL`,`PH`,`IN`,`ZA`,`AU`,`TH`,`SA`,`PE`,`CO`]);function b(e){try{let t=new Intl.Locale(e),n=t.getWeekInfo?.()??t.weekInfo;return n?n.firstDay===7?0:1:+!y.has(t.maximize().region??``)}catch{return 1}}function x(e,t,n){let r=(new Date(Date.UTC(e,t,1)).getUTCDay()-n+v)%v,i=[];for(let n=0;n<_;n++){let a=new Date(Date.UTC(e,t,1-r+n));i.push({year:a.getUTCFullYear(),month:a.getUTCMonth(),day:a.getUTCDate()})}return i}var ne=e=>String(e).padStart(2,`0`),S=e=>`${String(e.year).padStart(4,`0`)}-${ne(e.month+1)}-${ne(e.day)}`;function re(e){let t=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e??``);return t?{year:Number(t[1]),month:Number(t[2])-1,day:Number(t[3])}:null}function ie(){let e=new Date;return{year:e.getFullYear(),month:e.getMonth(),day:e.getDate()}}function ae(e,t){let n=new Date(Date.UTC(e.year,e.month,e.day+t));return{year:n.getUTCFullYear(),month:n.getUTCMonth(),day:n.getUTCDate()}}var oe=class{element;grid;titleEl;chosen=``;limits={};today=S(ie());view={year:0,month:0};focusDay=ie();constructor(e,t,n){this.locale=t,this.onPick=n;let r=document.createElement(`div`);r.className=`tcw-calendar`;let i=document.createElement(`div`);i.className=`tcw-calendar-head`;let a=document.createElement(`div`);a.className=`tcw-calendar-title`,a.setAttribute(`aria-live`,`polite`),i.append(this.navButton(e.prevMonth,-1),a,this.navButton(e.nextMonth,1));let o=document.createElement(`div`);o.className=`tcw-calendar-weekdays`,o.setAttribute(`aria-hidden`,`true`);let s=b(t),c=new Intl.DateTimeFormat(t,{weekday:`narrow`,timeZone:`UTC`});for(let e=0;e<v;e++){let t=document.createElement(`span`);t.className=`tcw-calendar-weekday`,t.textContent=c.format(new Date(Date.UTC(2023,0,1+(s+e)%v))),o.appendChild(t)}let l=document.createElement(`div`);l.className=`tcw-calendar-grid`,l.setAttribute(`role`,`grid`),l.addEventListener(`keydown`,e=>this.onKey(e)),l.addEventListener(`click`,e=>{let t=e.target.closest(`.tcw-calendar-day`);t&&!t.disabled&&t.dataset.date&&this.pick(t.dataset.date)});let u=document.createElement(`div`);u.className=`tcw-calendar-foot`;let d=document.createElement(`button`);d.type=`button`,d.className=`tcw-calendar-today`,d.textContent=e.today,d.addEventListener(`click`,()=>this.pick(this.today)),u.appendChild(d),r.append(i,o,l,u),this.element=r,this.grid=l,this.titleEl=a}show(e,t={}){this.chosen=e,this.limits=t,this.today=re(t.today)?t.today:S(ie());let n=this.clamp(re(e)??re(this.today));this.focusDay=n,this.view={year:n.year,month:n.month},this.render()}focusGrid(){this.grid.querySelector(`[tabindex="0"]`)?.focus()}navButton(e,t){let n=document.createElement(`button`);return n.type=`button`,n.className=`tcw-calendar-nav`,n.setAttribute(`aria-label`,e),n.innerHTML=t<0?`<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M10 3.5L5.5 8l4.5 4.5"/></svg>`:`<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M6 3.5L10.5 8 6 12.5"/></svg>`,n.addEventListener(`click`,()=>this.turn(t)),n}turn(e){let t=new Date(Date.UTC(this.view.year,this.view.month+e,1));this.view={year:t.getUTCFullYear(),month:t.getUTCMonth()};let n=new Date(Date.UTC(this.view.year,this.view.month+1,0)).getUTCDate();this.focusDay=this.clamp({...this.view,day:Math.min(this.focusDay.day,n)}),this.view={year:this.focusDay.year,month:this.focusDay.month},this.render()}clamp(e){let t=S(e),n=re(this.limits.min),r=re(this.limits.max);return n&&t<S(n)?n:r&&t>S(r)?r:e}allowed(e){let{min:t,max:n}=this.limits;return!(t&&e<t)&&!(n&&e>n)}render(){let e=this.locale;this.titleEl.textContent=new Intl.DateTimeFormat(e,{month:`long`,year:`numeric`,timeZone:`UTC`}).format(new Date(Date.UTC(this.view.year,this.view.month,1)));let t=this.today,n=S(this.focusDay),r=new Intl.DateTimeFormat(e,{dateStyle:`full`,timeZone:`UTC`});this.grid.textContent=``;let i=null;for(let[a,o]of x(this.view.year,this.view.month,b(e)).entries()){a%v===0&&(i=document.createElement(`div`),i.className=`tcw-calendar-week`,i.setAttribute(`role`,`row`),this.grid.appendChild(i));let e=S(o),s=document.createElement(`button`);s.type=`button`,s.className=`tcw-calendar-day`,s.dataset.date=e,s.setAttribute(`role`,`gridcell`),s.textContent=String(o.day),s.setAttribute(`aria-label`,r.format(new Date(Date.UTC(o.year,o.month,o.day)))),s.setAttribute(`aria-selected`,String(e===this.chosen)),s.tabIndex=e===n?0:-1,o.month!==this.view.month&&s.classList.add(`tcw-outside`),e===t&&s.classList.add(`tcw-today`),this.allowed(e)||(s.disabled=!0),i?.appendChild(s)}}onKey(e){let t={ArrowLeft:-1,ArrowRight:1,ArrowUp:-v,ArrowDown:v},n=this.element.isConnected&&getComputedStyle(this.element).direction===`rtl`;if(e.key in t){let r=n&&(e.key===`ArrowLeft`||e.key===`ArrowRight`)?-t[e.key]:t[e.key];this.moveFocus(ae(this.focusDay,r))}else if(e.key===`PageUp`||e.key===`PageDown`)this.turn(e.key===`PageUp`?-1:1),this.focusGrid();else if(e.key===`Home`||e.key===`End`){let t=new Date(Date.UTC(this.view.year,this.view.month+1,0)).getUTCDate();this.moveFocus({...this.view,day:e.key===`Home`?1:t})}else if(e.key===`Enter`||e.key===` `)this.pick(S(this.focusDay));else return;e.preventDefault()}moveFocus(e){let t=this.clamp(e);this.focusDay=t,(t.year!==this.view.year||t.month!==this.view.month)&&(this.view={year:t.year,month:t.month}),this.render(),this.focusGrid()}pick(e){this.allowed(e)&&this.onPick(e)}},se=class{input=null;view=null;onOutside=e=>{let t=e.target;this.view?.element.contains(t)||this.input?.contains(t)||this.close(!1)};onAway=()=>this.close(!1);onScroll=e=>{e.target instanceof Node&&this.view?.element.contains(e.target)||this.close(!1)};watch=new MutationObserver(()=>{this.input&&!this.input.isConnected&&this.close(!1)});constructor(e,t,n){this.layer=e,this.labels=t,this.locale=n}isOpenFor(e){return this.input===e}owns(e){return e!==null&&(e===this.input||this.view?.element.contains(e)===!0)}open(e){this.close(!1),this.input=e;let t=new oe(this.labels(),this.locale(),e=>this.pick(e));t.show(e.value,{min:e.min||void 0,max:e.max||void 0});let n=t.element;n.setAttribute(`role`,`dialog`);let r=e.getAttribute(`aria-label`)??e.labels?.[0]?.textContent??``;r&&n.setAttribute(`aria-label`,r.trim()),n.addEventListener(`mousedown`,e=>{e.target.closest(`button`)||e.preventDefault()}),n.addEventListener(`keydown`,e=>{e.stopPropagation(),e.key===`Escape`&&(e.preventDefault(),this.close(!0))}),this.view=t,this.layer().appendChild(n),ee(n,e),document.addEventListener(`pointerdown`,this.onOutside,!0),window.addEventListener(`resize`,this.onAway),document.addEventListener(`scroll`,this.onScroll,{capture:!0,passive:!0}),this.watch.observe(document.documentElement,{childList:!0,subtree:!0})}close(e){let t=this.input;t&&(document.removeEventListener(`pointerdown`,this.onOutside,!0),window.removeEventListener(`resize`,this.onAway),document.removeEventListener(`scroll`,this.onScroll,{capture:!0}),this.watch.disconnect(),this.view?.element.remove(),this.view=null,this.input=null,e&&t.isConnected&&t.focus())}focusGrid(){this.view?.focusGrid()}destroy(){this.close(!1)}pick(e){let t=this.input;if(!t)return;let n=t.value!==e;t.value=e,this.close(!0),n&&(t.dispatchEvent(new Event(`input`,{bubbles:!0})),t.dispatchEvent(new Event(`change`,{bubbles:!0})))}},ce=()=>typeof matchMedia==`function`&&matchMedia(`(pointer: coarse)`).matches,le=()=>typeof CSS>`u`||typeof CSS.supports!=`function`||CSS.supports(`selector(::-webkit-calendar-picker-indicator)`);function ue(e){if(!(e instanceof Element))return null;let t=e.closest(`select`);return!t||t.matches(`:disabled`)||t.multiple||t.size>1?null:t}function de(e){return!(e instanceof HTMLInputElement)||e.type!==`date`||e.dataset.tcwCalendar===`inline`||e.matches(`:disabled`)||e.readOnly?null:e}function fe(e,t){let n=new g(t.layer),r=new se(t.layer,t.labels,t.locale),i=t.native??ce,a=t.calendar??le,o=new WeakSet,s=e=>o.has(e)?!1:(o.add(e),!0),c=e=>{if(e.button!==0||i()||!s(e))return;let t=ue(e.target);if(t){if(e.preventDefault(),n.isOpenFor(t)){n.close(!0);return}t.focus(),n.open(t)}},l=e=>{if(i()||!a()||!s(e))return;let t=de(e.target);t&&(e.preventDefault(),r.isOpenFor(t)||r.open(t))},u=e=>{if(i()||!s(e))return;let t=ue(e.target);if(t){if(n.isOpenFor(t)){n.key(e)&&(e.preventDefault(),e.stopPropagation());return}(e.key===`Enter`||e.key===` `||e.altKey&&(e.key===`ArrowDown`||e.key===`ArrowUp`)||e.key===`F4`)&&(e.preventDefault(),e.stopPropagation(),n.open(t));return}let o=de(e.target);!o||!a()||(e.key===`Escape`&&r.isOpenFor(o)?(e.preventDefault(),e.stopPropagation(),r.close(!0)):(e.altKey&&e.key===`ArrowDown`||e.key===`F4`)&&(e.preventDefault(),r.isOpenFor(o)||r.open(o),r.focusGrid()))},d=e=>{if(!s(e))return;let t=e.target instanceof Node?e.target:null,i=e.relatedTarget instanceof Node?e.relatedTarget:null;n.owns(t)&&!n.owns(i)&&n.close(!1),r.owns(t)&&!r.owns(i)&&r.close(!1)};for(let t of e)t.addEventListener(`mousedown`,c,!0),t.addEventListener(`click`,l,!0),t.addEventListener(`keydown`,u,!0),t.addEventListener(`focusout`,d,!0);return()=>{for(let t of e)t.removeEventListener(`mousedown`,c,!0),t.removeEventListener(`click`,l,!0),t.removeEventListener(`keydown`,u,!0),t.removeEventListener(`focusout`,d,!0);n.destroy(),r.destroy()}}var pe=[{label:`Candlestick`,value:`candlestick`},{label:`Line`,value:`line`},{label:`Area`,value:`area`},{label:`Bar`,value:`bar`},{label:`Heikin-Ashi`,value:`heikinAshi`},{label:`Hollow Candle`,value:`hollowCandle`},{label:`Baseline`,value:`baseline`},{label:`Volume Candles`,value:`volumeCandles`},{label:`Equivolume`,value:`equivolume`},{label:`HLC Area`,value:`hlcArea`},{label:`Step Line`,value:`stepLine`},{label:`Line + Markers`,value:`lineWithMarkers`},{label:`High-Low`,value:`hiLo`},{label:`Renko`,value:`renko`},{label:`Line Break`,value:`lineBreak`},{label:`Kagi`,value:`kagi`},{label:`Point & Figure`,value:`pointAndFigure`},{label:`Range Bars`,value:`rangeBars`}],me=[{label:`Lines`,section:`lines`,tools:[{label:`Trend Line`,value:`trendLine`},{label:`Ray`,value:`ray`},{label:`Extended Line`,value:`extendedLine`},{label:`Info Line`,value:`infoLine`},{label:`Trend Angle`,value:`trendAngle`}]},{label:`Horizontal/Vertical`,section:`lines`,tools:[{label:`Horizontal Line`,value:`horizontalLine`},{label:`Horizontal Ray`,value:`horizontalRay`},{label:`Vertical Line`,value:`verticalLine`},{label:`Cross Line`,value:`crossLine`}]},{label:`Channels`,section:`lines`,tools:[{label:`Parallel Channel`,value:`parallelChannel`},{label:`Regression Channel`,value:`regressionChannel`}]},{label:`Fibonacci`,section:`fibonacci`,tools:[{label:`Fib Retracement`,value:`fibRetracement`},{label:`Fib Extension`,value:`fibExtension`},{label:`Fib Channel`,value:`fibChannel`},{label:`Fib Time Zones`,value:`fibTimeZones`},{label:`Fib Speed Resistance Fan`,value:`fibSpeedResistanceFan`},{label:`Fib Speed Resistance Arcs`,value:`fibArcs`},{label:`Fib Circles`,value:`fibCircles`},{label:`Fib Spiral`,value:`fibSpiral`},{label:`Fib Wedge`,value:`fibWedge`}]},{label:`Gann & Pitchforks`,section:`fibonacci`,tools:[{label:`Pitchfork`,value:`pitchfork`},{label:`Schiff Pitchfork`,value:`schiffPitchfork`},{label:`Modified Schiff Pitchfork`,value:`modifiedSchiffPitchfork`},{label:`Gann Fan`,value:`gannFan`},{label:`Gann Box`,value:`gannBox`},{label:`Gann Square`,value:`gannSquare`},{label:`Pitchfan`,value:`pitchfan`}]},{label:`Cycles`,section:`fibonacci`,tools:[{label:`Cyclic Lines`,value:`cyclicLines`},{label:`Time Cycles`,value:`timeCycles`},{label:`Sine Line`,value:`sineLine`}]},{label:`Patterns`,section:`patterns`,tools:[{label:`XABCD Pattern`,value:`xabcdPattern`},{label:`ABCD Pattern`,value:`abcdPattern`},{label:`Head and Shoulders`,value:`headAndShoulders`},{label:`Cypher Pattern`,value:`cypherPattern`},{label:`Three Drives Pattern`,value:`threeDrives`}]},{label:`Elliott Waves`,section:`patterns`,tools:[{label:`Elliott Wave`,value:`elliottWave`},{label:`Elliott Impulse Wave`,value:`elliottImpulse`},{label:`Elliott Correction Wave`,value:`elliottCorrection`},{label:`Elliott Triangle Wave`,value:`elliottTriangle`},{label:`Elliott Double Combo Wave`,value:`elliottDoubleCombo`},{label:`Elliott Triple Combo Wave`,value:`elliottTripleCombo`}]},{label:`Forecasting`,section:`forecasting`,tools:[{label:`Long/Short Position`,value:`riskReward`},{label:`Anchored VWAP`,value:`anchoredVWAP`},{label:`Fixed Range Volume Profile`,value:`volumeProfileRange`},{label:`Forecast`,value:`forecast`},{label:`Projection`,value:`projection`},{label:`Bars Pattern`,value:`barsPattern`}]},{label:`Measure`,section:`forecasting`,tools:[{label:`Price Range`,value:`priceRange`},{label:`Date Range`,value:`dateRange`},{label:`Date and Price Range`,value:`dateAndPriceRange`},{label:`Measure`,value:`measure`}]},{label:`Shapes`,section:`annotation`,tools:[{label:`Rectangle`,value:`rectangle`},{label:`Circle`,value:`circle`},{label:`Ellipse`,value:`ellipse`},{label:`Triangle`,value:`triangle`},{label:`Polyline`,value:`polyline`},{label:`Curve`,value:`curve`},{label:`Arc`,value:`arc`}]},{label:`Brushes`,section:`annotation`,tools:[{label:`Brush`,value:`brush`},{label:`Highlighter`,value:`highlighter`},{label:`Path`,value:`path`}]},{label:`Annotation`,section:`annotation`,tools:[{label:`Text`,value:`text`},{label:`Price Label`,value:`priceLabel`},{label:`Arrow`,value:`arrow`},{label:`Note`,value:`note`},{label:`Callout`,value:`callout`},{label:`Flag Mark`,value:`flag`},{label:`Arrow Mark`,value:`arrowMark`},{label:`Icon`,value:`icon`}]}],he=[`BTCUSDT`,`ETHUSDT`,`SOLUSDT`,`BNBUSDT`],ge={gridVisible:!0,volumeVisible:!0,volumeProfileVisible:!1,marketProfileVisible:!1,marketProfileSplit:!1,marketProfileLetters:!1,marketProfileBuckets:48,marketProfileOpacity:.32,depthHeatmapVisible:!1,depthHeatmapOpacity:.7,sessionShadingVisible:!1,pivotMarkersVisible:!1,pivotStrength:5,pivotStructureLabels:!1,periodLevelsVisible:!1,periodLevelsPeriod:`day`,legendVisible:!0,barCountdown:!0,indicatorValueLabels:!1,alignAxisLabels:!0,logScale:!1,scaleMode:`regular`,autoScale:!0,invertScale:!1,leftPriceScale:!1,crosshairMode:`magnet`,numberLocale:`en-US`,timezone:`local`,highLowLines:!1,mainSeriesVisible:!0,extendedHours:!0,chartTypeOptions:{}},C=(e,...t)=>({label:e,keys:t}),w=(e,t,n={})=>({label:e,keys:[t],auto:n}),T=e=>({hint:e}),_e={from:`panes.titleColor`},ve={title:`settings.section.lastPrice`,rows:[C(`settings.priceLine`,`lastPrice.visible`),C(`settings.up`,`lastPrice.upColor`),C(`settings.down`,`lastPrice.downColor`),C(`drawingSettings.lineStyle`,`lastPrice.style`),C(`drawingSettings.lineWidth`,`lastPrice.width`)]},ye={title:`settings.volume`,rows:[C(`settings.up`,`volume.upColor`),C(`settings.down`,`volume.downColor`)]},be={title:`settings.highLowLines`,rows:[w(`drawingSettings.color`,`highLow.color`,_e)]},xe=[ve,ye,be],Se=[C(`settings.legendText`,`legend.textColor`),C(`settings.legendLabels`,`legend.labelColor`)],Ce=[...Se,C(`settings.paneTitles`,`panes.titleColor`)],we=[C(`drawingSettings.text`,`axis.price.textColor`,`axis.time.textColor`),C(`settings.scaleLines`,`axis.price.lineColor`,`axis.time.lineColor`)],Te=[{title:`settings.section.background`,rows:[C(`settings.background`,`background.color`),C(`settings.paneBackground`,`panes.background`),C(`settings.paneSeparator`,`panes.separatorColor`),w(`settings.watermark`,`watermark.color`,_e)]},{title:`settings.gridLines`,rows:[C(`settings.horizontal`,`grid.horizontal.visible`),C(`settings.vertical`,`grid.vertical.visible`),C(`drawingSettings.color`,`grid.horizontal.color`,`grid.vertical.color`),C(`drawingSettings.lineStyle`,`grid.horizontal.style`,`grid.vertical.style`),C(`drawingSettings.lineWidth`,`grid.horizontal.width`,`grid.vertical.width`)]},{title:`settings.crosshairMode`,rows:[C(`settings.horizontal`,`crosshair.horizontal.visible`),C(`settings.vertical`,`crosshair.vertical.visible`),C(`drawingSettings.color`,`crosshair.horizontal.color`,`crosshair.vertical.color`),C(`drawingSettings.lineStyle`,`crosshair.horizontal.style`,`crosshair.vertical.style`),C(`drawingSettings.lineWidth`,`crosshair.horizontal.width`,`crosshair.vertical.width`),C(`settings.labelBackground`,`crosshair.labelBackground`),C(`settings.labelText`,`crosshair.labelTextColor`)]},{title:`settings.sessionBreaks`,rows:[w(`drawingSettings.color`,`sessionBreaks.color`,{from:`axis.price.lineColor`}),w(`drawingSettings.lineStyle`,`sessionBreaks.style`),w(`drawingSettings.lineWidth`,`sessionBreaks.width`)]},{title:`objects.drawings`,rows:[w(`settings.handles`,`drawings.handleColor`,T(`#ffffff`))]}],Ee=[{title:`settings.section.orders`,trading:!0,rows:[w(`ticket.buy`,`trading.buyColor`,T(n.DEFAULT_TRADING_CONFIG.orderColors?.buy)),w(`ticket.sell`,`trading.sellColor`,T(n.DEFAULT_TRADING_CONFIG.orderColors?.sell)),w(`settings.profit`,`trading.profitColor`,T(n.DEFAULT_TRADING_CONFIG.positionColors?.profit)),w(`settings.loss`,`trading.lossColor`,T(n.DEFAULT_TRADING_CONFIG.positionColors?.loss)),w(`account.entry`,`trading.entryColor`,T(n.DEFAULT_TRADING_CONFIG.positionColors?.entry))]},{title:`settings.section.signals`,rows:[w(`account.long`,`markers.longColor`,T(n.DEFAULT_SIGNAL_STYLE.longColor)),w(`account.short`,`markers.shortColor`,T(n.DEFAULT_SIGNAL_STYLE.shortColor)),w(`markers.neutral`,`markers.neutralColor`,T(n.DEFAULT_SIGNAL_STYLE.neutralColor))]},{title:`settings.section.tradeZones`,rows:[w(`settings.profit`,`tradeZones.profitColor`,T(n.DEFAULT_TRADE_ZONE_STYLE.profitColor)),w(`settings.loss`,`tradeZones.lossColor`,T(n.DEFAULT_TRADE_ZONE_STYLE.lossColor)),w(`settings.openTrade`,`tradeZones.activeColor`,T(n.DEFAULT_TRADE_ZONE_STYLE.activeColor))]}],De={upColor:`settings.up`,downColor:`settings.down`,wickUpColor:`settings.upWick`,wickDownColor:`settings.downWick`,color:`drawingSettings.color`,lineColor:`drawingSettings.color`,lineWidth:`drawingSettings.lineWidth`,topColor:`settings.areaTop`,bottomColor:`settings.areaBottom`},Oe=new Set([`candlestick`,`heikinAshi`,`volumeCandles`,`equivolume`]);function ke(e){let t=`series.${e}.`;return Object.keys(n.CHART_STYLE_KEYS).filter(e=>e.startsWith(t)).map(n=>{let r=n.slice(t.length),i=De[r]??`drawingSettings.color`;return Oe.has(e)&&r===`upColor`&&(i=`settings.upBody`),Oe.has(e)&&r===`downColor`&&(i=`settings.downBody`),e===`baseline`&&r===`upColor`&&(i=`settings.aboveBase`),e===`baseline`&&r===`downColor`&&(i=`settings.belowBase`),C(i,n)})}var E=[...new Set([...Object.keys(n.CHART_STYLE_KEYS).filter(e=>e.startsWith(`series.`)),...[...xe,...Te,...Ee].flatMap(e=>e.rows.flatMap(e=>e.keys)),...[...Ce,...we].flatMap(e=>e.keys)])],Ae=`/* === TradeCanvas Widget — Premium Styles === */
2
2
 
3
3
  /*
4
4
  * The HTML \`hidden\` attribute only sets \`display: none\` via the UA stylesheet,
@@ -7658,7 +7658,7 @@ img.tcw-ss-badge {
7658
7658
  ${je}
7659
7659
  ${Me}
7660
7660
  ${Ne}
7661
- ${Ge()}`,document.head.insertBefore(e,document.head.firstChild)}function $e(){if(Xe--,Xe>0)return;let e=document.getElementById(Ze);e&&e.remove()}var et=(e,t)=>Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0;function O(e,t=14){let r=et(n.UI_ICONS,e);return r?(0,n.iconSvg)(r,t):``}function tt(e,t=16){return(0,n.iconSvg)(et(n.DRAWING_TOOL_ICONS,e)??n.UI_ICONS.penLine,t)}function nt(e,t=14){return(0,n.iconSvg)(et(n.CHART_TYPE_ICONS,e)??n.UI_ICONS.barChart,t)}function k(e){return e.replace(/[&<>"']/g,e=>({"&":`&amp;`,"<":`&lt;`,">":`&gt;`,'"':`&quot;`,"'":`&#39;`})[e])}var rt=class{trigger;panel;_isOpen=!1;onOutsideClick;onEscapeKey;onTriggerClick;layer;align;onAway=()=>this.close();onScroll=e=>{e.target instanceof Node&&this.panel.contains(e.target)||this.close()};constructor(e,t={}){this.trigger=e,this.layer=t.layer??null,this.align=t.align??`left`,this.panel=document.createElement(`div`),this.panel.className=`tcw-dropdown`,this.panel.style.minWidth=t.width??`200px`,this.panel.style.display=`none`,this.layer?(this.layer().appendChild(this.panel),this.panel.addEventListener(`click`,()=>this.close())):(this.align===`right`?this.panel.style.insetInlineEnd=`0px`:this.panel.style.insetInlineStart=`0px`,e.style.position=`relative`,e.appendChild(this.panel)),this.onTriggerClick=()=>{this._isOpen?this.close():this.open()},this.onOutsideClick=e=>{let t=e.target;!this.trigger.contains(t)&&!this.panel.contains(t)&&this.close()},this.onEscapeKey=e=>{e.key===`Escape`&&this.close()},e.addEventListener(`click`,this.onTriggerClick)}setContent(e){this.panel.innerHTML=e}open(){if(!this._isOpen){if(this._isOpen=!0,this.layer){let e=this.layer();this.panel.parentElement!==e&&e.appendChild(this.panel)}this.panel.style.display=``,this.layer&&(this.place(),window.addEventListener(`resize`,this.onAway),document.addEventListener(`scroll`,this.onScroll,{capture:!0,passive:!0})),document.addEventListener(`pointerdown`,this.onOutsideClick),document.addEventListener(`keydown`,this.onEscapeKey)}}close(){this._isOpen&&(this._isOpen=!1,this.panel.style.display=`none`,document.removeEventListener(`pointerdown`,this.onOutsideClick),document.removeEventListener(`keydown`,this.onEscapeKey),window.removeEventListener(`resize`,this.onAway),document.removeEventListener(`scroll`,this.onScroll,{capture:!0}))}isOpen(){return this._isOpen}destroy(){this.close(),this.trigger.removeEventListener(`click`,this.onTriggerClick),this.panel.remove()}place(){ee(this.panel,this.trigger,this.align)}},it=4,at=2,ot=150,st=`[role=menuitem], [role=menuitemcheckbox], [role=menuitemradio]`,ct=`(max-width: 640px)`,lt=`tcw:back`,ut=new Set;function dt(e,t,n,r=e,i=!1){let a=i?r-t>=0?r-t:e:e+t>n?r-t:e;return Math.max(0,Math.min(a,n-t))}function ft(e){return e.radio?`menuitemradio`:e.checked===void 0?`menuitem`:`menuitemcheckbox`}function pt(e){let t=`<span class="tcw-context-icon"></span>`;return e.radio?e.checked?`<span class="tcw-context-icon tcw-context-dot"></span>`:t:e.checked?O(`check`,14):e.icon&&O(e.icon,14)||t}var A=class e{el;onPick=null;onRemove=null;returnFocus=null;anchor=null;child=null;parent=null;hoverTimer=null;hoverItem=null;onDocPointer=e=>{let t=e.target;this.holds(t)||this.anchor?.contains(t)||this.close()};onWheel=e=>{this.holds(e.target)||this.close()};onAway=()=>this.close();constructor(e,t,n=``){this.host=e,this.backLabel=n,this.el=document.createElement(`div`),this.el.className=`tcw-context-menu`,this.el.setAttribute(`role`,`menu`),this.el.setAttribute(`aria-label`,t),this.el.hidden=!0,this.el.addEventListener(`keydown`,e=>this.onKeyDown(e)),e.appendChild(this.el)}open(e,t,n,r,i,a,o=t,s=!1){this.show(e,{x:t,y:n,xBack:o,yBack:n,before:s},r,i,a,!0)}openUnder(e,t,n,r=`start`,i=at){let a=t.getBoundingClientRect(),o=this.host.getBoundingClientRect(),s=r===`end`!==this.rtl();this.open(e,a.left-o.left,a.bottom-o.top+i,n,t,void 0,a.right-o.left,s)}openBeside(e,t,n){let r=t.getBoundingClientRect(),i=this.host.getBoundingClientRect(),a=r.right-i.left+at,o=r.left-i.left-at;this.show(e,{x:a,y:r.top-i.top,xBack:o,yBack:r.bottom-i.top,before:this.rtl()},n,t,void 0,!0),this.returnFocus=t}static closeAnchoredTo(e){let t=[...ut].filter(t=>t.anchor===e);for(let e of t)e.close();return t.length>0}static focusedAnchor(){return[...ut].find(e=>e.anchor!==null&&e.hasFocus())?.anchor??null}close(){if(this.clearHover(),this.child?.close(),this.el.hidden)return;ut.delete(this);let e=!this.parent||this.el.contains(document.activeElement);this.el.hidden=!0,this.onPick=null,this.onRemove=null,this.anchor?.setAttribute(`aria-expanded`,`false`),this.anchor=null,document.removeEventListener(`pointerdown`,this.onDocPointer,!0),document.removeEventListener(`wheel`,this.onWheel,{capture:!0}),window.removeEventListener(`resize`,this.onAway),window.removeEventListener(`blur`,this.onAway),e&&this.returnFocus?.isConnected&&this.returnFocus.focus({preventScroll:!0}),this.returnFocus=null}isOpen(){return!this.el.hidden}hasFocus(){return document.activeElement!==null&&this.holds(document.activeElement)}destroy(){this.close(),this.child?.destroy(),this.el.remove()}show(e,t,n,r,i,a){this.clearHover(),this.child?.close(),this.returnFocus=document.activeElement instanceof HTMLElement?document.activeElement:null,this.onPick=n,this.onRemove=i??null,this.anchor=r??null,this.anchor?.setAttribute(`aria-expanded`,`true`),this.el.replaceChildren(...e.map(e=>this.entry(e))),this.el.hidden=!1,ut.add(this);let o=this.host.getBoundingClientRect(),s=Math.min(this.host.clientWidth,window.innerWidth-o.left)-it,c=Math.min(this.host.clientHeight,window.innerHeight-o.top)-it;this.el.style.maxHeight=`${Math.max(0,c-this.frameHeight())}px`,this.el.style.left=`${dt(t.x,this.el.offsetWidth,s,t.xBack,t.before)}px`,this.el.style.top=`${dt(t.y,this.el.offsetHeight,c,t.yBack)}px`,document.addEventListener(`pointerdown`,this.onDocPointer,!0),document.addEventListener(`wheel`,this.onWheel,{capture:!0,passive:!0}),window.addEventListener(`resize`,this.onAway),window.addEventListener(`blur`,this.onAway);let l=this.revealChoice();a&&(l??this.items()[0])?.focus({preventScroll:!0})}frameHeight(){let e=getComputedStyle(this.el);if(e.boxSizing===`border-box`)return 0;let t=e=>parseFloat(e)||0;return t(e.paddingTop)+t(e.paddingBottom)+t(e.borderTopWidth)+t(e.borderBottomWidth)}revealChoice(){let e=this.el.querySelector(`[role=menuitemradio][aria-checked=true]`);return!e||e.offsetTop+e.offsetHeight<=this.el.clientHeight?null:(this.el.scrollTop=e.offsetTop-(this.el.clientHeight-e.offsetHeight)/2,e)}rtl(){return this.host.closest(`[dir]`)?.getAttribute(`dir`)===`rtl`}holds(e){return this.el.contains(e)||(this.child?.holds(e)??!1)}entry(e){if(e===`separator`){let e=document.createElement(`div`);return e.className=`tcw-context-sep`,e.setAttribute(`role`,`separator`),e}let t=document.createElement(`button`);t.type=`button`,t.className=`tcw-context-item${e.danger?` tcw-context-danger`:``}`,t.setAttribute(`role`,ft(e)),(e.radio||e.checked!==void 0)&&t.setAttribute(`aria-checked`,String(e.checked??!1)),t.tabIndex=-1,t.dataset.id=e.id,t.innerHTML=pt(e);let n=document.createElement(`span`);n.className=`tcw-context-label`,n.textContent=e.label,t.appendChild(n),this.appendEnd(t,e);let r=e.submenu;return t.addEventListener(`pointermove`,n=>{n.pointerType!==`touch`&&this.hover(t,e.label,r)}),t.addEventListener(`click`,()=>{r?this.openSubmenu(t,e.label,r,!0):this.pick(e.id)}),e.remove?this.removableRow(t,e.remove):t}appendEnd(e,t){if(t.count!==void 0){let n=document.createElement(`span`);n.className=`tcw-context-count`,n.textContent=String(t.count),e.appendChild(n)}if(t.shortcut){e.setAttribute(`aria-keyshortcuts`,t.shortcut);let n=document.createElement(`kbd`);n.className=`tcw-context-key`,n.setAttribute(`aria-hidden`,`true`),n.textContent=t.shortcut,e.appendChild(n)}t.submenu&&(e.setAttribute(`aria-haspopup`,`menu`),e.setAttribute(`aria-expanded`,`false`),e.insertAdjacentHTML(`beforeend`,O(`chevronRight`,12)),e.lastElementChild?.classList.add(`tcw-context-more`))}removableRow(e,t){e.setAttribute(`aria-keyshortcuts`,`Delete`);let n=document.createElement(`button`);n.type=`button`,n.className=`tcw-context-remove`,n.tabIndex=-1,n.setAttribute(`aria-hidden`,`true`),n.title=t,n.innerHTML=O(`x`,12),n.addEventListener(`click`,()=>this.remove(e));let r=document.createElement(`div`);return r.className=`tcw-context-row`,r.setAttribute(`role`,`none`),r.append(e,n),r}openSubmenu(e,t,n,r){this.clearHover();let i=this.child??this.makeChild();if(i.isOpen()&&i.anchor===e){r&&i.items()[0]?.focus({preventScroll:!0});return}i.close(),i.el.setAttribute(`aria-label`,t);let a=this.host.getBoundingClientRect(),o=e.getBoundingClientRect(),s={x:o.right-a.left,y:o.top-a.top,xBack:o.left-a.left,yBack:o.bottom-a.top,before:this.rtl()},c=window.matchMedia?.(ct).matches??!1,l=c?[{id:lt,label:t,icon:`chevronLeft`},`separator`,...n]:n;i.show(l,s,e=>{e!==lt&&this.pick(e)},e,e=>this.onRemove?.(e),r);let u=c?i.el.querySelector(`[data-id="${lt}"]`):null;u?.classList.add(`tcw-context-back`),u&&this.backLabel&&u.setAttribute(`aria-label`,`${this.backLabel}: ${t}`),i.returnFocus=e}makeChild(){let t=new e(this.host,``,this.backLabel);return t.parent=this,t.el.addEventListener(`pointerenter`,()=>this.clearHover()),this.child=t,t}hover(e,t,n){if(this.hoverTimer!==null&&this.hoverItem===e)return;this.clearHover();let r=this.child?.isOpen()?this.child.anchor:null;(n?r===e:r===null)||(this.hoverItem=e,this.hoverTimer=setTimeout(()=>{this.hoverTimer=null,this.hoverItem=null,n?this.openSubmenu(e,t,n,!1):this.child?.close()},ot))}clearHover(){this.hoverItem=null,this.hoverTimer!==null&&(clearTimeout(this.hoverTimer),this.hoverTimer=null)}remove(e){let t=e.dataset.id,n=e.closest(`.tcw-context-row`);if(!t||!n)return;let r=this.items().indexOf(e);this.onRemove?.(t),n.remove();let i=[...this.el.children].filter((e,t,n)=>e.classList.contains(`tcw-context-sep`)&&(t===0||t===n.length-1||n[t-1].classList.contains(`tcw-context-sep`)));for(let e of i)e.remove();let a=this.items();if(a.length===0){this.close();return}a[Math.min(r,a.length-1)].focus({preventScroll:!0})}pick(e){let t=this.onPick;this.close(),t?.(e)}items(){return[...this.el.querySelectorAll(st)]}onKeyDown(e){let t=this.items(),n=t.indexOf(document.activeElement),[r,i]=this.rtl()?[`ArrowLeft`,`ArrowRight`]:[`ArrowRight`,`ArrowLeft`],a=-1;if(e.key===`ArrowDown`)a=(n+1)%t.length;else if(e.key===`ArrowUp`)a=(n-1+t.length)%t.length;else if(e.key===`Home`)a=0;else if(e.key===`End`)a=t.length-1;else if(e.key===r&&t[n]?.hasAttribute(`aria-haspopup`)){e.preventDefault(),t[n].click();return}else if(e.key===i&&this.parent){e.preventDefault(),this.close();return}else if(e.key===`Delete`&&n>=0){e.preventDefault(),this.remove(t[n]);return}else if(e.key===`Escape`||e.key===`Tab`){e.preventDefault(),e.stopPropagation();let t=this;for(;e.key===`Tab`&&t.parent;)t=t.parent;t.close();return}else return;e.preventDefault(),this.child?.close(),t[a]?.focus({preventScroll:!0})}},mt=[`en-US`,`en-GB`,`en-IN`,`de-DE`,`fr-FR`,`es-ES`,`it-IT`,`pt-BR`,`ru-RU`,`tr-TR`,`vi-VN`,`id-ID`,`th-TH`,`zh-CN`,`zh-TW`,`ja-JP`,`ko-KR`],ht=65234;function gt(e){return(e&&!mt.includes(e)?[e,...mt]:mt).map(e=>{let t;try{t=new Intl.NumberFormat(e,{minimumFractionDigits:2,maximumFractionDigits:2}).format(ht)}catch{t=``}return{value:e,label:t?`${e} (${t})`:e}})}var _t={Lines:`toolGroup.lines`,"Horizontal/Vertical":`toolGroup.horizontalVertical`,Channels:`toolGroup.channels`,Fibonacci:`toolGroup.fibonacci`,Shapes:`toolGroup.shapes`,"Gann & Pitchforks":`toolGroup.gannPitchforks`,Patterns:`toolGroup.patterns`,Measure:`toolGroup.measure`,Annotation:`toolGroup.annotation`,Forecasting:`toolGroup.forecasting`,Brushes:`toolGroup.brushes`,Cycles:`toolGroup.cycles`,"Elliott Waves":`toolGroup.elliott`};function vt(e,t){let n=`chartType.${e.value}`,r=t(n);return r===n?e.label:r}function yt(e,t){return e.map(e=>({...e,label:_t[e.label]?t(_t[e.label]):e.label,tools:e.tools.map(e=>{let n=`tool.${e.value}`,r=t(n);return{...e,label:r===n?e.label:r}})}))}var bt=[`1m`,`3m`,`5m`,`15m`,`30m`,`1h`,`2h`,`4h`,`1d`,`1w`,`1M`],xt=[`1m`,`5m`,`15m`,`1h`,`4h`,`1d`],St=6;function Ct(e){let t=e.slice(-1);return t===`h`||t===`d`||t===`w`?e.slice(0,-1)+t.toUpperCase():e}var wt=e=>Number.isFinite((0,n.timeframeToMs)(e))||(0,n.tickBarCount)(e)!==null,Tt=(e,t)=>{let r=(0,n.tickBarCount)(e),i=(0,n.tickBarCount)(t);return r!==null||i!==null?r===null?1:i===null?-1:r-i:(0,n.timeframeToMs)(e)-(0,n.timeframeToMs)(t)};function Et(e,t){let n=t?.length?t:null,r=e?.length?e:n??bt;return[...new Set(r)].filter(e=>wt(e)&&(!n||n.includes(e))).sort(Tt)}function Dt(e,t,n=!1){if(t?.length)return e.filter(e=>t.includes(e));if(n)return[...e];let r=e.filter(e=>xt.includes(e));return r.length>0?r:e.slice(0,St)}var Ot=9999,kt={"":`m`,s:`s`,S:`s`,m:`m`,h:`h`,H:`h`,d:`d`,D:`d`,w:`w`,W:`w`,M:`M`},At={s:[`m`,60],m:[`h`,60],h:[`d`,24]};function jt(e){let t=/^(\d+)([a-zA-Z]?)$/.exec(e.trim());if(!t)return null;if(t[2]===`T`||t[2]===`t`){let e=`${Number(t[1])}T`;return Number(t[1])<=Ot&&(0,n.tickBarCount)(e)!==null?e:null}let r=Number(t[1]),i=kt[t[2]];if(!i||!Number.isSafeInteger(r)||r<1)return null;for(let e=At[i];e&&r%e[1]===0;e=At[i])r/=e[1],i=e[0];if(r>Ot)return null;let a=`${r}${i}`;return(0,n.isTimeFrame)(a)?a:null}function Mt(e,t,n){let r=n?.length?n:null,i=t.filter(e=>wt(e)&&(!r||r.includes(e)));return[...new Set([...e,...i])].sort(Tt)}var Nt=[`T`,`s`,`m`,`h`,`d`,`w`,`M`];function Pt(e){let t=e=>{let t=e.slice(-1);return Nt.includes(t)?t:`m`};return Nt.map(n=>({unit:n,timeframes:e.filter(e=>t(e.value)===n)})).filter(e=>e.timeframes.length>0)}var Ft=864e5,It=5/7;function Lt(e){let t=(0,n.timeframeToMs)(e.current),r=(0,n.timeframeToMs)(e.chosen);if(!Number.isFinite(t)||!Number.isFinite(r)||!(e.width>0)||!(e.spanMs>0))return e.current;let i=n=>{if(n===t)return e.barsInSpan;if(n<Ft)return e.barsInSpan*t/n;let r=e.spanMs/n;return n===Ft?r*(e.dayShare??It):r},a=[...new Set([...e.available,e.current])].filter(e=>{let t=(0,n.timeframeToMs)(e);return Number.isFinite(t)&&t>=r}).sort(Tt);for(let t of a)if(i((0,n.timeframeToMs)(t))*2<=e.width)return t;return a[a.length-1]??e.current}var Rt={ticket:`receipt`,long:`trendingUp`,short:`trendingDown`,ladder:`ladder`,account:`layers`},zt=[`ladder`,`account`];function Bt(e,t){let n=[];e.onOrderTicket&&n.push({id:`ticket`,label:t(`chartMenu.orderTicket`),parts:[`orderTicket`],run:e.onOrderTicket});let r=e.onBracket;return r&&(n.push({id:`long`,label:t(`toolbar.longBracket`),parts:[`bracketOrders`,`toolbar.bracketOrders`],run:()=>r(`buy`)}),n.push({id:`short`,label:t(`toolbar.shortBracket`),parts:[`bracketOrders`,`toolbar.bracketOrders`],run:()=>r(`sell`)})),e.onToggleLadder&&n.push({id:`ladder`,label:t(`toolbar.depthLadder`),parts:[`depthLadder`,`toolbar.depthLadder`],run:e.onToggleLadder}),e.onToggleAccount&&n.push({id:`account`,label:t(`toolbar.account`),parts:[`accountPanel`,`toolbar.accountPanel`],run:e.onToggleAccount}),n}var Vt=class e{button;menu=null;open=new Set;static create(t,n,r,i){let a=Bt(t,n);return a.length>0?new e(a,n,r,i):null}constructor(e,t,n,r){this.items=e,this.t=t,this.root=n;let i=document.createElement(`button`);i.type=`button`,i.className=`tcw-dropdown-trigger tcw-toolbar-overflow`,i.dataset.role=`trade`,i.dataset.icon=`trendingUp`,i.title=t(`toolbar.trade`),i.setAttribute(`aria-haspopup`,`menu`),i.setAttribute(`aria-expanded`,`false`),D(i,`toolbar.trade`),i.innerHTML=`${O(`trendingUp`,14)} <span class="tcw-trigger-label">${k(t(`toolbar.trade`))}</span> ${O(`chevronDown`,12)}`,i.addEventListener(`click`,()=>this.toggle(r(i))),this.button=i}tidy(){this.button.hidden=this.items.every(e=>this.isOff(e.parts))}setOpen(e,t){let n=zt.find(t=>t===e);n&&(t?this.open.add(n):this.open.delete(n))}destroy(){this.menu?.destroy(),this.button.remove()}isOff(e){let t=new Set((this.root().getAttribute(`data-tcw-off`)??``).split(/\s+/).filter(Boolean));return e.some(e=>t.has(e))}toggle(e){if(this.menu?.isOpen()){this.menu.close();return}let t=this.items.filter(e=>!this.isOff(e.parts));if(t.length===0)return;let n=t.filter(e=>!zt.includes(e.id)),r=t.filter(e=>zt.includes(e.id)),i=[...n.map(e=>({id:e.id,label:e.label,icon:Rt[e.id]})),...n.length>0&&r.length>0?[`separator`]:[],...r.map(e=>({id:e.id,label:e.label,checked:this.open.has(e.id)}))],a=this.root();this.menu??=new A(a,this.t(`toolbar.trade`)),this.menu.openUnder(i,e,e=>{t.find(t=>t.id===e)?.run()})}},Ht=2048,Ut=65536,Wt=/^data:image\/(png|jpeg|gif|webp|avif|svg\+xml)[;,]/i,Gt=new Set([`https:`,`http:`,`blob:`]),Kt=new Set([`description`,`exchange`,`type`,`logo`]);function qt(e){if(typeof e!=`string`)return null;let t=e.trim();return t&&t.length<=64?t:null}function Jt(e){let t=[],n=new Map;if(!Array.isArray(e))return{names:t,info:n};let r=new Set;for(let i of e){let e=typeof i==`object`&&!!i,a=qt(e?i.symbol:i);!a||r.has(a)||(r.add(a),t.push(a),e&&n.set(a,Yt(i,a)))}return{names:t,info:n}}function Yt(e,t){return{...Object.fromEntries(Object.entries(e).filter(([e,t])=>e!==`__proto__`&&(!Kt.has(e)||typeof t==`string`&&t.trim()!==``))),symbol:t}}function Xt(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.symbol==`string`&&e.symbol!==``).map(e=>Yt(e,e.symbol)):[]}function Zt(e,t){if(!t)return e;if(!e)return t;let n=Object.entries(t).filter(([,e])=>e!=null);return Object.fromEntries([...Object.entries(e),...n])}function Qt(e){let t=e.lastIndexOf(`:`);return t<=0||t===e.length-1?{venue:``,ticker:e}:{venue:e.slice(0,t+1),ticker:e.slice(t+1)}}var $t=e=>Qt(e).ticker.toUpperCase();function en(e,t){return!t||typeof t.symbol!=`string`?null:t.symbol.toUpperCase()===e.toUpperCase()||t.symbol.includes(`:`)!==e.includes(`:`)&&$t(t.symbol)===$t(e)?t:null}function tn(e){return[e?.description,e?.exchange].filter(Boolean).join(` · `)||null}var nn=()=>typeof document>`u`?void 0:document.baseURI;function rn(e,t=nn()){if(typeof e!=`string`)return null;let n=e.trim();if(!n||n.length>Ut)return null;let r;try{r=new URL(n,t)}catch{return null}return r.protocol===`data:`?Wt.test(r.href)&&r.href.length<=Ut?r.href:null:Gt.has(r.protocol)&&r.href.length<=Ht?r.href:null}var an=0,j=`data-tcw-folded`,on=1/64,sn=[`venue`,`ticker`,`cut`],cn={T:`toolbar.timeframes.ticks`,s:`toolbar.timeframes.seconds`,m:`toolbar.timeframes.minutes`,h:`toolbar.timeframes.hours`,d:`toolbar.timeframes.days`,w:`toolbar.timeframes.weeks`,M:`toolbar.timeframes.months`};function ln(e,t){let n=e.querySelector(`.tcw-host-btn-text`)?.textContent??``;n===t?e.removeAttribute(`aria-label`):e.setAttribute(`aria-label`,n?`${t}: ${n}`:t)}var un=class{config;callbacks;t;el;chartTypeDropdown=null;tfGroup=null;tfDropdown=null;tfFavorites=[];uid=(an++).toString(36);tfRendered=``;themeBtn=null;fullscreenBtn=null;hostLeft=null;hostRight=null;moreMenu=null;tfCurrent=null;resizeObserver=null;hostObserver=null;moreBtn=null;fitFrame=0;destroyed=!1;undoBtn=null;redoBtn=null;trade=null;layoutShown=``;symbolShown=null;constructor(e,t,n,r,i){if(this.host=e,this.layer=i,this.config=t,this.callbacks=n,this.t=r,this.el=document.createElement(`div`),this.el.className=`tcw-toolbar`,D(this.el,`toolbar`),this.build(),e.appendChild(this.el),typeof ResizeObserver<`u`){this.resizeObserver=new ResizeObserver(()=>this.fit()),this.resizeObserver.observe(this.el),this.hostObserver=new ResizeObserver(()=>this.scheduleFit());for(let e of[this.hostLeft,this.hostRight])e&&this.hostObserver.observe(e)}document.fonts?.ready.then(()=>this.scheduleFit())}scheduleFit(){this.destroyed||this.fitFrame||typeof requestAnimationFrame>`u`||(this.fitFrame=requestAnimationFrame(()=>{this.fitFrame=0,this.destroyed||this.fit()}))}menuAnchor(e){return(e.hasAttribute(j)||this.el.closest(`[data-tcw-narrow]`)!==null)&&this.moreBtn?this.moreBtn:e}fit(){let e=this.toolbarFocus(),t=this.foldedState();this.refit(),this.foldedState()!==t&&this.closeStaleMenus(),e&&this.keepFocus(e)}refit(){let{el:e}=this,t=()=>this.fits(),n=[...e.querySelectorAll(`.tcw-toolbar-overflow`)];for(let e of n)e.removeAttribute(j);if(e.classList.remove(`tcw-toolbar--collapsed`,`tcw-toolbar--icons`),delete e.dataset.tcwSqueeze,!(e.clientWidth===0||t())){e.classList.add(`tcw-toolbar--collapsed`);for(let e=n.length-1;e>=0;e--)if(n[e].setAttribute(j,``),t())return;e.classList.add(`tcw-toolbar--icons`);for(let e of n)if(e.removeAttribute(j),!t()){e.setAttribute(j,``);break}for(let n of sn){if(t())return;e.dataset.tcwSqueeze=n}}}fits(){let{el:e}=this,t=e.getBoundingClientRect(),n=e.offsetWidth>0&&Math.abs(t.width-e.offsetWidth)>=1?t.width/e.offsetWidth:1,r=getComputedStyle(e),i=r.direction===`rtl`,a=e=>parseFloat(e)||0,o=t.width/n-(i?a(r.borderLeftWidth)+a(r.paddingLeft):a(r.borderRightWidth)+a(r.paddingRight)),s=0;for(let r of e.children){if(r.getClientRects().length===0)continue;let e=r.getBoundingClientRect();s=Math.max(s,(i?t.right-e.left:e.right-t.left)/n)}return Math.ceil(s-on)<=Math.floor(o+on)}foldedState(){let e=[...this.el.querySelectorAll(`.tcw-toolbar-overflow`)];return`${this.el.classList.contains(`tcw-toolbar--collapsed`)}:${e.map(e=>Number(e.hasAttribute(j))).join(``)}`}closeStaleMenus(){this.moreBtn&&A.closeAnchoredTo(this.moreBtn);for(let e of this.el.querySelectorAll(`[${j}], [${j}] button`))A.closeAnchoredTo(e)}toolbarFocus(){let e=A.focusedAnchor();if(e&&this.el.contains(e))return e;let t=document.activeElement;return t instanceof HTMLElement&&this.el.contains(t)?t:null}keepFocus(e){if(A.focusedAnchor())return;let t=e;this.shows(e)||(t=(this.moreBtn&&e!==this.moreBtn&&this.shows(this.moreBtn)?this.moreBtn:null)??this.overflowButtons().filter(e=>this.shows(e)).at(-1)),t&&document.activeElement!==t&&t.focus({preventScroll:!0})}overflowButtons(){return[...this.el.querySelectorAll(`button.tcw-toolbar-overflow, .tcw-toolbar-overflow button`)]}shows(e){if(e.closest(`[hidden]`)||e.closest(`[${j}]`)||this.isOff(e))return!1;let t=this.el.closest(`[data-tcw-narrow]`)!==null;return e===this.moreBtn?t||this.el.classList.contains(`tcw-toolbar--collapsed`):!(t&&e.closest(`.tcw-toolbar-overflow`))}isOff(e){let t=new Set((this.rootEl().getAttribute(`data-tcw-off`)??``).split(/\s+/).filter(Boolean));for(let n=e;n&&n!==this.el;n=n.parentElement)if((n.dataset.tcwPart??``).split(/\s+/).some(e=>t.has(e)))return!0;return!1}build(){let{config:e,callbacks:t,el:n}=this,r=document.createElement(`button`);if(r.className=`tcw-toolbar-symbol`,r.dataset.role=`symbol`,r.dir=`ltr`,D(r,`toolbar.symbol`),r.addEventListener(`click`,t.onSymbolClick),n.appendChild(r),t.onSymbolInfo){let e=this.iconBtn(`info`,this.t(`symbolInfo.title`),t.onSymbolInfo);e.classList.remove(`tcw-toolbar-overflow`),e.dataset.role=`symbolInfo`,D(e,`symbolInfo`,`toolbar.symbolInfo`),n.appendChild(e)}if(n.appendChild(this.sep()),this.tfFavorites=[...e.timeframeFavorites??e.timeframes.map(e=>e.value)],this.tfGroup=document.createElement(`div`),this.tfGroup.className=`tcw-toolbar-group tcw-tf-group`,D(this.tfGroup,`toolbar.timeframes`),n.appendChild(this.tfGroup),t.onToggleTimeframeFavorite&&e.timeframes.length>0){let e=document.createElement(`div`);e.style.position=`relative`,e.style.display=`inline-flex`,D(e,`toolbar.timeframeMenu`);let t=document.createElement(`button`);t.className=`tcw-btn tcw-tf-more`,t.dataset.role=`timeframes`,t.title=this.t(`toolbar.timeframes`),t.setAttribute(`aria-label`,this.t(`toolbar.timeframes`)),this.tfCurrent=document.createElement(`span`),this.tfCurrent.className=`tcw-tf-current`,t.appendChild(this.tfCurrent),t.insertAdjacentHTML(`beforeend`,O(`chevronDown`,12)),e.appendChild(t),n.appendChild(e),this.tfDropdown=new rt(e,{width:`150px`,layer:this.layer}),n.classList.add(`tcw-toolbar--tf-menu`),this.buildTimeframeMenu()}n.appendChild(this.sep());let i=document.createElement(`div`);i.style.position=`relative`,i.style.display=`inline-flex`,D(i,`toolbar.chartType`);let a=document.createElement(`button`);a.className=`tcw-dropdown-trigger`,a.dataset.role=`charttype`,i.appendChild(a),n.appendChild(i),this.chartTypeDropdown=new rt(i,{width:`160px`,layer:this.layer}),this.buildChartTypeMenu(),n.appendChild(this.sep());let o=document.createElement(`button`);if(o.type=`button`,o.className=`tcw-dropdown-trigger`,o.dataset.role=`indicators`,o.setAttribute(`aria-haspopup`,`dialog`),o.setAttribute(`aria-expanded`,`false`),D(o,`toolbar.indicators`),o.addEventListener(`click`,()=>t.onIndicators()),n.appendChild(o),t.onCompare){let e=document.createElement(`button`);e.type=`button`,e.className=`tcw-dropdown-trigger`,e.dataset.role=`compare`,D(e,`compare`,`toolbar.compare`);let r=this.t(`objects.compare`);e.setAttribute(`aria-label`,r),e.title=r,e.innerHTML=`${O(`plus`,14)} <span class="tcw-trigger-label">${k(r)}</span>`,e.addEventListener(`click`,t.onCompare),n.appendChild(e)}if(this.hostLeft=this.hostGroup(),n.appendChild(this.hostLeft),t.onUndo&&t.onRedo&&(n.appendChild(this.sep()),this.undoBtn=this.iconBtn(`undo`,this.t(`drawing.undo`),t.onUndo),this.undoBtn.dataset.role=`undo`,D(this.undoBtn,`toolbar.undo`,`sidebar.undo`),this.redoBtn=this.iconBtn(`redo`,this.t(`drawing.redo`),t.onRedo),this.redoBtn.dataset.role=`redo`,D(this.redoBtn,`toolbar.redo`,`sidebar.redo`),n.append(this.undoBtn,this.redoBtn),this.setHistory(!1,!1)),n.appendChild(this.spacer()),t.onLayouts){let e=t.onLayouts,r=document.createElement(`button`);r.type=`button`,r.className=`tcw-dropdown-trigger tcw-layouts-btn tcw-toolbar-overflow`,r.dataset.role=`layouts`,r.dataset.icon=`save`,D(r,`layouts`,`toolbar.layouts`),r.setAttribute(`aria-haspopup`,`menu`),r.addEventListener(`click`,()=>e(this.menuAnchor(r))),n.appendChild(r),this.setLayout(null,!1)}if(this.hostRight=this.hostGroup(),n.appendChild(this.hostRight),n.appendChild(this.sep()),t.onToggleReplay){let e=this.iconBtn(`play`,this.t(`toolbar.replay`),t.onToggleReplay);e.dataset.role=`replay`,D(e,`replay`,`toolbar.replay`),n.appendChild(e)}if(t.onToggleObjects){let e=this.iconBtn(`layers`,this.t(`toolbar.objects`),t.onToggleObjects);e.dataset.role=`objects`,e.setAttribute(`aria-pressed`,`false`),D(e,`objectTree`,`toolbar.objectTree`),n.appendChild(e)}if(t.onToggleAlerts){let e=this.iconBtn(`bell`,this.t(`toolbar.priceAlerts`),t.onToggleAlerts);e.dataset.role=`alerts`,e.setAttribute(`aria-pressed`,`false`),D(e,`alerts`,`toolbar.alerts`),n.appendChild(e)}this.trade=Vt.create(t,this.t,()=>this.rootEl(),e=>this.menuAnchor(e)),this.trade&&n.appendChild(this.trade.button),n.appendChild(this.sep());let s=this.iconBtn(`camera`,this.t(`toolbar.screenshot`),t.onScreenshot);D(s,`screenshot`,`toolbar.screenshot`),n.appendChild(s);let c=this.iconBtn(`settings`,this.t(`toolbar.settings`),t.onSettings);D(c,`settings`,`toolbar.settings`),n.appendChild(c),this.themeBtn=this.iconBtn(`moon`,this.t(`toolbar.toggleTheme`),t.onToggleTheme),this.themeBtn.dataset.role=`theme`,D(this.themeBtn,`themeToggle`,`toolbar.themeToggle`),n.appendChild(this.themeBtn),t.onToggleFullscreen&&(this.fullscreenBtn=this.iconBtn(`maximize`,this.t(`toolbar.fullscreen`),t.onToggleFullscreen),this.fullscreenBtn.dataset.role=`fullscreen`,D(this.fullscreenBtn,`fullscreen`,`toolbar.fullscreen`),this.fullscreenBtn.setAttribute(`aria-pressed`,`false`),n.appendChild(this.fullscreenBtn));let l=document.createElement(`button`);l.type=`button`,l.className=`tcw-btn-icon tcw-toolbar-more`,l.title=this.t(`toolbar.more`),l.setAttribute(`aria-haspopup`,`menu`),l.setAttribute(`aria-expanded`,`false`),l.innerHTML=O(`more`,16),l.addEventListener(`click`,()=>this.toggleMore(l)),n.appendChild(l),this.moreBtn=l}toggleMore(e){if(A.closeAnchoredTo(e))return;let t=this.rootEl(),n=this.el.closest(`[data-tcw-narrow]`)!==null,r=[];for(let e of this.el.querySelectorAll(`.tcw-toolbar-overflow`)){if(this.isOff(e)||!n&&!e.hasAttribute(j))continue;let t=e instanceof HTMLButtonElement?[e]:[...e.querySelectorAll(`button`)];r.push(...t.filter(e=>!e.hidden&&!e.disabled&&!this.isOff(e)))}if(r.length===0)return;let i=r.map((e,t)=>{let n=e.getAttribute(`aria-label`)||e.title||e.textContent?.trim()||``,r=e.getAttribute(`aria-pressed`);return r===null?{id:String(t),label:n,icon:e.dataset.icon}:{id:String(t),label:n,icon:e.dataset.icon,checked:r===`true`}});this.moreMenu??=new A(t,this.t(`toolbar.more`)),this.moreMenu.openUnder(i,e,e=>r[Number(e)]?.click(),`end`)}addHostButton(e){let t=document.createElement(`button`);t.type=`button`,t.className=`${e.text||!e.icon?`tcw-btn`:`tcw-btn-icon`} tcw-host-btn tcw-toolbar-overflow`,t.dataset.hostButton=e.id,typeof e.icon==`string`&&(t.dataset.icon=e.icon),t.title=e.label,e.toggle&&t.setAttribute(`aria-pressed`,`false`),typeof e.icon==`string`?t.innerHTML=O(e.icon,14):e.icon&&t.appendChild(e.icon);let n=e.text??(e.icon?``:e.label);if(n){let e=document.createElement(`span`);e.className=`tcw-host-btn-text`,e.textContent=n,t.appendChild(e)}return ln(t,e.label),t.addEventListener(`click`,()=>e.onClick(t)),(e.side===`left`?this.hostLeft:this.hostRight)?.appendChild(t),this.scheduleFit(),t}hostSlot(e){return e===`left`?this.hostLeft:this.hostRight}hostGroup(){let e=document.createElement(`div`);return e.className=`tcw-toolbar-host`,e}setSymbolSearch(e){let t=this.el.querySelector(`[data-role="symbol"]`);t&&(e?t.removeAttribute(`aria-disabled`):t.setAttribute(`aria-disabled`,`true`))}tidy(){this.trade?.tidy(),Je(this.el,`tcw-toolbar-sep`,`tcw-toolbar-spacer`),this.scheduleFit()}setHistory(e,t){this.undoBtn&&(this.undoBtn.disabled=!e),this.redoBtn&&(this.redoBtn.disabled=!t)}rootEl(){return this.el.closest(`.tcw-root`)??this.host}setActive(e,t){this.trade?.setOpen(e,t);let n=this.el.querySelector(`[data-role="${e}"]`);n&&(n.classList.toggle(`tcw-active`,t),n.setAttribute(`aria-pressed`,String(t)))}setRailed(e,t){let n=this.el.querySelector(`[data-role="${e}"]`);n&&(n.hidden=t)}setLayout(e,t){let n=this.el.querySelector(`[data-role="layouts"]`);if(!n)return;let r=e??this.t(`layouts.unnamed`);if(this.layoutShown===`${t}:${r}`)return;this.layoutShown=`${t}:${r}`;let i=`${this.t(`toolbar.layouts`)}: ${r}${t?` (${this.t(`layouts.unsavedChanges`)})`:``}`;n.innerHTML=`${O(`save`,14)}<span class="tcw-layouts-label">${k(r)}</span>`+(t?`<span class="tcw-layouts-dirty" aria-hidden="true"></span>`:``)+O(`chevronDown`,12),n.title=i,n.setAttribute(`aria-label`,i),this.scheduleFit()}setFullscreen(e){if(!this.fullscreenBtn)return;let t=this.t(e?`toolbar.exitFullscreen`:`toolbar.fullscreen`);this.fullscreenBtn.innerHTML=O(e?`minimize`:`maximize`,14),this.fullscreenBtn.title=t,this.fullscreenBtn.setAttribute(`aria-pressed`,String(e))}chartTypeLabel(e){return vt(e,this.t)}buildChartTypeMenu(){if(!this.chartTypeDropdown)return;let e=this.config.chartTypes.map(e=>`<button class="tcw-dropdown-item tcw-dropdown-item--icon" data-ct="${k(e.value)}">${nt(e.value,16)}<span>${k(this.chartTypeLabel(e))}</span></button>`).join(``);this.chartTypeDropdown.setContent(e),this.chartTypeDropdown.panel.querySelectorAll(`.tcw-dropdown-item`).forEach(e=>{e.addEventListener(`click`,e=>{let t=e.currentTarget.dataset.ct;this.callbacks.onChartType(t),this.chartTypeDropdown?.close()})})}setSymbolDescription(e){let t=this.el.querySelector(`[data-role="symbol"]`);t&&(e?t.title=e:t.removeAttribute(`title`))}setTimeframes(e,t){this.config={...this.config,timeframes:e},this.setTimeframeFavorites(t)}setTimeframeFavorites(e){this.tfFavorites=[...e],this.tfRendered=``,this.buildTimeframeMenu()}buildTimeframeMenu(){if(!this.tfDropdown)return;let e=k(this.t(`toolbar.timeframes.pin`)),t=k(this.t(`toolbar.timeframes.remove`)),n=``;for(let{unit:r,timeframes:i}of Pt(this.config.timeframes)){n+=`<div class="tcw-tf-section" data-tf-section="${r}" role="group" aria-label="${k(this.t(cn[r]))}"><div class="tcw-dropdown-label">${k(this.t(cn[r]))}</div>`;for(let r of i){let i=this.tfFavorites.includes(r.value),[a,o]=[k(r.value),k(r.label)];n+=`<div class="tcw-tf-row"><button class="tcw-dropdown-item" data-tf-pick="${a}">${o}</button>`+(r.custom&&this.callbacks.onRemoveTimeframe?`<button class="tcw-tf-remove" data-tf-remove="${a}" title="${t}" aria-label="${t}: ${o}">${O(`x`,12)}</button>`:``)+`<button class="tcw-tf-star${i?` tcw-active`:``}" data-tf-star="${a}" aria-pressed="${i}" title="${e}" aria-label="${e}: ${o}">${O(`star`,12)}</button></div>`}n+=`</div>`}if(this.callbacks.onAddTimeframe){let e=k(this.t(`toolbar.timeframes.custom`)),t=k(this.t(`toolbar.timeframes.add`));n+=`<form class="tcw-tf-custom" ${Ke(`customTimeframes`)} novalidate><input class="tcw-tf-custom-input" type="text" autocomplete="off" spellcheck="false" maxlength="6" placeholder="7m, 90m, 2h…" aria-label="${e}" aria-describedby="tcw-tf-hint-${this.uid}"><button type="submit" class="tcw-tf-custom-add" title="${t}" aria-label="${t}">${O(`plus`,12)}</button><div class="tcw-tf-custom-hint" id="tcw-tf-hint-${this.uid}" role="status"></div></form>`}this.tfDropdown.setContent(n);let r=this.tfDropdown.panel;r.querySelectorAll(`[data-tf-pick]`).forEach(e=>{e.addEventListener(`click`,()=>this.callbacks.onTimeframe(e.dataset.tfPick))}),r.querySelectorAll(`[data-tf-star]`).forEach(e=>{e.addEventListener(`click`,t=>{t.stopPropagation(),this.callbacks.onToggleTimeframeFavorite?.(e.dataset.tfStar)})}),r.querySelectorAll(`[data-tf-remove]`).forEach(e=>{e.addEventListener(`click`,t=>{t.stopPropagation(),this.callbacks.onRemoveTimeframe?.(e.dataset.tfRemove)})});let i=r.querySelector(`.tcw-tf-custom`);i&&this.wireCustomTimeframe(i)}wireCustomTimeframe(e){let t=e.querySelector(`.tcw-tf-custom-input`),n=e.querySelector(`.tcw-tf-custom-hint`);e.addEventListener(`click`,e=>e.stopPropagation()),t.addEventListener(`input`,()=>{t.removeAttribute(`aria-invalid`),n.textContent=``}),e.addEventListener(`submit`,e=>{e.preventDefault(),e.stopPropagation(),this.callbacks.onAddTimeframe?.(t.value)?(t.value=``,n.textContent=``,this.tfDropdown?.close(),this.el.querySelector(`[data-role="timeframes"]`)?.focus()):(t.setAttribute(`aria-invalid`,`true`),n.textContent=this.t(`toolbar.timeframes.invalid`))})}renderTimeframes(e){if(!this.tfGroup)return;let t=this.config.timeframes.filter(t=>this.tfFavorites.includes(t.value)||t.value===e),n=`${t.map(e=>e.value).join(`,`)}|${e}`;n!==this.tfRendered&&(this.tfRendered=n,this.tfCurrent&&(this.tfCurrent.textContent=this.config.timeframes.find(t=>t.value===e)?.label??e),this.tfGroup.replaceChildren(...t.map(t=>{let n=document.createElement(`button`);return n.className=`tcw-btn`,n.textContent=t.label,n.dataset.tf=t.value,n.classList.toggle(`tcw-active`,t.value===e),n.addEventListener(`click`,()=>this.callbacks.onTimeframe(t.value)),n})),(this.tfDropdown?.panel)?.querySelectorAll(`[data-tf-pick]`).forEach(t=>{t.classList.toggle(`tcw-active`,t.dataset.tfPick===e)}))}setIndicatorsOpen(e){this.el.querySelector(`[data-role="indicators"]`)?.setAttribute(`aria-expanded`,String(e))}renderSymbol(e){let t=this.el.querySelector(`[data-role="symbol"]`);if(!t||this.symbolShown===e)return;this.symbolShown=e;let{venue:n,ticker:r}=Qt(e),i=(e,t)=>{let n=document.createElement(`span`);return n.className=e,n.textContent=t,n};t.replaceChildren(...n?[i(`tcw-toolbar-venue`,n)]:[],i(`tcw-toolbar-ticker`,r)),t.classList.toggle(`tcw-toolbar-symbol--venue`,n!==``),t.setAttribute(`aria-label`,e)}update(e){this.renderSymbol(e.symbol),this.renderTimeframes(e.timeframe);let t=this.el.querySelector(`[data-role="charttype"]`);if(t){let n=this.config.chartTypes.find(t=>t.value===e.chartType),r=n?this.chartTypeLabel(n):e.chartType;t.innerHTML=nt(e.chartType,16),t.title=r,t.setAttribute(`aria-label`,r)}let n=this.el.querySelector(`[data-role="indicators"]`);if(n){let t=[...e.activeIndicators.values()].filter(e=>!r.SYMBOL_INDICATOR_IDS.has(e.id)).length,i=`${O(`trendingUp`,14)} <span class="tcw-trigger-label">${k(this.t(`toolbar.indicators`))}</span>`;n.setAttribute(`aria-label`,this.t(`toolbar.indicators`)),t>0&&(i+=` <span class="tcw-badge-count">${t}</span>`),n.innerHTML=i}if(this.themeBtn){let t=e.isDark?`moon`:`sun`;this.themeBtn.innerHTML=O(t,14),this.themeBtn.dataset.icon=t}this.scheduleFit()}sep(){let e=document.createElement(`span`);return e.className=`tcw-toolbar-sep`,e}spacer(){let e=document.createElement(`span`);return e.className=`tcw-toolbar-spacer`,e}iconBtn(e,t,n){let r=document.createElement(`button`);return r.className=`tcw-btn-icon tcw-toolbar-overflow`,r.dataset.icon=e,r.title=t,r.innerHTML=O(e,14),r.addEventListener(`click`,n),r}destroy(){this.destroyed=!0,this.resizeObserver?.disconnect(),this.hostObserver?.disconnect(),this.fitFrame&&cancelAnimationFrame(this.fitFrame),this.chartTypeDropdown?.destroy(),this.tfDropdown?.destroy(),this.moreMenu?.destroy(),this.trade?.destroy(),this.el.remove()}};function dn(e,t,n){e.classList.toggle(`tcw-active`,t),n&&e.setAttribute(`aria-pressed`,String(t))}function fn(e,t,n){let r=n==null?``:String(n),i=e.querySelector(`.tcw-host-btn-text`);return(i?.textContent??``)===r?!1:(i||(i=document.createElement(`span`),i.className=`tcw-host-btn-text`,e.appendChild(i)),i.textContent=r,ln(e,t),!0)}var pn=16,mn=150,hn=4;function gn(e){let t=`sidebar.${e}`;return Pe.includes(t)?t:null}function _n(e,t){for(let n of e){let e=n.tools.find(e=>e.value===t);if(e)return e.label}return t}var vn=`--tcw-fab-plot-left`,yn=class{config;callbacks;el;groupWraps=[];groupButtons=[];groupIcons=[];groupTools=[];cursorBtn=null;magnetBtn=null;eraserBtn=null;zoomBtn=null;stayBtn=null;lockAllBtn=null;hideAllBtn=null;drawings={locked:!1,hidden:!1};flyoutEl=null;flyoutIdx=-1;flyoutHideTimer=null;hostEl=null;favoritesEl=null;favoritesDivider=null;favorites=[];fab;fabShows=``;onPressAway=e=>{let t=e.target;t&&(this.el.contains(t)||this.fab.contains(t)||this.flyoutEl?.contains(t))||this.setOpen(!1)};onEscape=e=>{e.key===`Escape`&&!this.flyoutEl&&this.setOpen(!1)};constructor(e,n,r,i=t.t){this.host=e,this.t=i,this.config=n,this.callbacks=r,this.el=document.createElement(`div`),this.el.className=`tcw-sidebar`,D(this.el,`sidebar`),this.build(),this.el.addEventListener(`scroll`,()=>this.hideFlyout(),{passive:!0}),e.appendChild(this.el),this.fab=document.createElement(`button`),this.fab.type=`button`,this.fab.className=`tcw-sidebar-fab`,this.fab.setAttribute(`aria-label`,this.t(`drawing.tools`)),this.fab.setAttribute(`aria-expanded`,`false`),this.fab.innerHTML=O(`penLine`,18),D(this.fab,`sidebar`),this.fab.addEventListener(`click`,()=>this.setOpen(!this.isOpen())),e.appendChild(this.fab)}setPlotLeft(e){let t=`${Math.max(0,Math.round(e))}px`;this.fab.style.getPropertyValue(vn)!==t&&this.fab.style.setProperty(vn,t)}isNarrow(){return this.el.closest(`[data-tcw-narrow]`)!==null}isOpen(){return this.el.classList.contains(`tcw-sidebar-open`)}setOpen(e){if(e!==this.isOpen())if(this.el.classList.toggle(`tcw-sidebar-open`,e),this.fab.setAttribute(`aria-expanded`,String(e)),e)document.addEventListener(`pointerdown`,this.onPressAway,!0),document.addEventListener(`keydown`,this.onEscape);else{let e=this.el.contains(document.activeElement)||!!this.flyoutEl?.contains(document.activeElement);this.hideFlyout(),document.removeEventListener(`pointerdown`,this.onPressAway,!0),document.removeEventListener(`keydown`,this.onEscape),e&&this.isNarrow()&&this.fab.focus({preventScroll:!0})}}closeOverlay(){this.setOpen(!1)}closeForChart(){this.isNarrow()&&this.setOpen(!1)}pick(e){this.callbacks.onDrawingTool(e),this.closeForChart()}build(){let{config:e,callbacks:t,el:n}=this;this.cursorBtn=document.createElement(`button`),this.cursorBtn.className=`tcw-sidebar-btn`,this.cursorBtn.title=this.t(`drawing.cursor`),this.cursorBtn.innerHTML=O(`cursor`,14),this.cursorBtn.addEventListener(`click`,()=>{t.onCancelDrawing(),this.closeForChart()}),D(this.cursorBtn,`sidebar.cursor`),n.appendChild(this.cursorBtn),n.appendChild(this.divider()),t.onToggleFavorite&&(this.favorites=[...e.favorites??[]],this.favoritesEl=document.createElement(`div`),this.favoritesEl.className=`tcw-sidebar-favorites`,D(this.favoritesEl,`sidebar.favorites`),n.appendChild(this.favoritesEl),this.favoritesDivider=this.divider(),D(this.favoritesDivider,`sidebar.favorites`),n.appendChild(this.favoritesDivider),this.renderFavorites());let r;e.drawingToolGroups.forEach((e,t)=>{if(!e.tools[0])return;e.section!==void 0&&r!==void 0&&e.section!==r&&this.appendDivider(),r=e.section;let i=document.createElement(`div`);i.className=`tcw-tool-group-wrap`;let a=gn(e.section);a&&D(i,a);let o=document.createElement(`button`);o.className=`tcw-sidebar-btn`;let s=e.tools[0].value;e.tools.length>1?o.setAttribute(`aria-label`,`${e.label}: ${e.tools[0].label}`):o.title=e.label;let c=document.createElement(`span`);if(c.className=`tcw-sidebar-icon`,c.innerHTML=tt(s,pn),o.appendChild(c),this.groupIcons.push(c),this.groupTools.push(s),e.tools.length>1){let e=document.createElement(`span`);e.className=`tcw-multi-dot`,o.appendChild(e)}o.addEventListener(`click`,()=>{if(this.isNarrow()&&e.tools.length>1){this.flyoutEl&&this.flyoutIdx===t?this.hideFlyout():this.showFlyout(t);return}this.pick(this.groupTools[t])}),i.appendChild(o),i.addEventListener(`mouseenter`,()=>{this.isNarrow()||this.showFlyout(t)}),i.addEventListener(`mouseleave`,()=>{this.isNarrow()||this.scheduleHideFlyout()}),e.tools.length>1&&(o.setAttribute(`aria-haspopup`,`menu`),o.setAttribute(`aria-expanded`,`false`),o.addEventListener(`keydown`,e=>{e.key===`ArrowRight`||e.key===`ArrowDown`?(e.preventDefault(),this.showFlyout(t),this.focusFlyoutItem(0)):e.key===`Escape`&&this.flyoutEl&&(e.stopPropagation(),this.hideFlyout())})),i.addEventListener(`focusout`,e=>{let t=e.relatedTarget;!i.contains(t)&&!this.flyoutEl?.contains(t)&&this.scheduleHideFlyout()}),n.appendChild(i),this.groupWraps.push(i),this.groupButtons.push(o)});let i=document.createElement(`div`);if(i.className=`tcw-sidebar-spacer`,n.appendChild(i),n.appendChild(this.divider()),t.onToggleStyle){let e=document.createElement(`button`);e.className=`tcw-sidebar-btn`,e.title=this.t(`drawing.style`),e.dataset.role=`style`,D(e,`sidebar.style`),e.innerHTML=O(`palette`,14);let r=t.onToggleStyle;e.addEventListener(`click`,()=>{r(),this.closeForChart()}),n.appendChild(e)}if(t.onToggleMagnet&&(this.magnetBtn=document.createElement(`button`),this.magnetBtn.className=`tcw-sidebar-btn`,this.magnetBtn.title=this.t(`drawing.magnet`),this.magnetBtn.innerHTML=O(`magnet`,14),this.magnetBtn.addEventListener(`click`,t.onToggleMagnet),D(this.magnetBtn,`sidebar.magnet`),n.appendChild(this.magnetBtn)),t.onToggleEraser){let e=t.onToggleEraser;this.eraserBtn=this.toggleButton(`eraser`,this.t(`drawing.eraser`),()=>{e(),this.closeForChart()}),D(this.eraserBtn,`sidebar.eraser`),n.appendChild(this.eraserBtn)}if(t.onToggleZoomArea){let e=t.onToggleZoomArea;this.zoomBtn=this.toggleButton(`zoomIn`,this.t(`drawing.zoomArea`),()=>{e(),this.closeForChart()}),D(this.zoomBtn,`sidebar.zoomArea`),n.appendChild(this.zoomBtn)}if(t.onToggleStayInDrawing&&(this.stayBtn=document.createElement(`button`),this.stayBtn.className=`tcw-sidebar-btn`,this.stayBtn.dataset.role=`stay`,this.stayBtn.title=this.t(`drawing.stay`),this.stayBtn.setAttribute(`aria-pressed`,`false`),this.stayBtn.innerHTML=O(`repeat`,14),this.stayBtn.addEventListener(`click`,t.onToggleStayInDrawing),D(this.stayBtn,`sidebar.stayInDrawing`),n.appendChild(this.stayBtn)),this.hostEl=document.createElement(`div`),this.hostEl.className=`tcw-sidebar-host`,n.appendChild(this.hostEl),this.appendDivider(),t.onLockAll){let e=t.onLockAll;this.lockAllBtn=this.toggleButton(`lock`,this.t(`drawing.lockAll`),()=>e(!this.drawings.locked)),this.lockAllBtn.dataset.role=`lockAll`,D(this.lockAllBtn,`sidebar.lockAll`),n.appendChild(this.lockAllBtn)}if(t.onHideAll){let e=t.onHideAll;this.hideAllBtn=this.toggleButton(`eyeOff`,this.t(`drawing.hideAll`),()=>e(!this.drawings.hidden)),this.hideAllBtn.dataset.role=`hideAll`,D(this.hideAllBtn,`sidebar.hideAll`),n.appendChild(this.hideAllBtn)}let a=document.createElement(`button`);a.className=`tcw-sidebar-btn tcw-danger`,a.title=this.t(`drawing.clearAll`),a.innerHTML=O(`trash`,14),a.setAttribute(`aria-haspopup`,`menu`),a.setAttribute(`aria-expanded`,`false`),a.addEventListener(`click`,()=>t.onClear(a)),D(a,`sidebar.clear`),n.appendChild(a)}setDrawingsState(e){if(!(e.locked===this.drawings.locked&&e.hidden===this.drawings.hidden)){this.drawings={...e};for(let[t,n]of[[this.lockAllBtn,e.locked],[this.hideAllBtn,e.hidden]])t?.setAttribute(`aria-pressed`,String(n)),t?.classList.toggle(`tcw-active`,n)}}setFavorites(e){this.favorites=[...e],this.renderFavorites();for(let e of this.flyoutEl?.querySelectorAll(`.tcw-flyout-row`)??[]){let t=this.favorites.includes(e.dataset.toolValue??``);e.classList.toggle(`tcw-flyout-faved`,t),e.querySelector(`[data-pin]`)?.setAttribute(`aria-pressed`,String(t))}}renderFavorites(){if(!this.favoritesEl)return;this.favoritesEl.replaceChildren();let e=this.favorites.length>0;this.favoritesEl.style.display=e?``:`none`,this.favoritesDivider&&(this.favoritesDivider.style.display=e?``:`none`);for(let e of this.favorites){let n=document.createElement(`button`);n.className=`tcw-sidebar-btn`,n.title=t.r(this.t(`sidebar.unpinHint`),{tool:_n(this.config.drawingToolGroups,e)}),n.dataset.toolValue=e,n.innerHTML=tt(e,pn),n.addEventListener(`click`,()=>this.pick(e)),n.addEventListener(`contextmenu`,t=>{t.preventDefault(),this.callbacks.onToggleFavorite?.(e)}),this.favoritesEl.appendChild(n)}}showFlyout(e){if(this.cancelHideFlyout(),this.flyoutEl&&this.flyoutIdx===e)return;let t=this.config.drawingToolGroups[e];if(!t||t.tools.length<=1){this.hideFlyout();return}this.hideFlyout();let n=document.createElement(`div`);n.className=`tcw-flyout`,n.setAttribute(`role`,`menu`),n.setAttribute(`aria-label`,t.label),n.addEventListener(`keydown`,t=>this.onFlyoutKey(t,e));let r=document.createElement(`div`);r.className=`tcw-flyout-header`,r.textContent=t.label,n.appendChild(r);let i=this.t(`drawing.pinFavorite`);for(let e of t.tools){let t=document.createElement(`div`);t.className=`tcw-flyout-row`,t.setAttribute(`role`,`none`),t.dataset.toolValue=e.value;let r=document.createElement(`button`);r.className=`tcw-flyout-item`,r.setAttribute(`role`,`menuitem`),r.tabIndex=-1,r.innerHTML=tt(e.value,pn);let a=document.createElement(`span`);a.className=`tcw-flyout-name`,a.textContent=e.label,r.appendChild(a);let o=this.config.shortcuts?.[e.value];if(o){let e=document.createElement(`kbd`);e.className=`tcw-flyout-key`,e.textContent=o,D(e,`hotkeys`,`hotkeys.tools`),r.appendChild(e)}if(r.dataset.toolValue=e.value,r.addEventListener(`click`,()=>{this.hideFlyout(),this.pick(e.value)}),t.appendChild(r),this.callbacks.onToggleFavorite){let n=this.favorites.includes(e.value);t.classList.toggle(`tcw-flyout-faved`,n);let a=document.createElement(`button`);a.type=`button`,a.className=`tcw-flyout-pin`,a.dataset.pin=e.value,a.tabIndex=-1,a.title=i,a.setAttribute(`aria-label`,`${i}: ${e.label}`),a.setAttribute(`aria-pressed`,String(n)),a.innerHTML=O(`star`,12),a.addEventListener(`click`,t=>{t.stopPropagation(),this.callbacks.onToggleFavorite?.(e.value)}),t.appendChild(a),r.addEventListener(`contextmenu`,t=>{t.preventDefault(),this.callbacks.onToggleFavorite?.(e.value)})}n.appendChild(t)}n.addEventListener(`mouseenter`,()=>this.cancelHideFlyout()),n.addEventListener(`mouseleave`,()=>this.scheduleHideFlyout()),n.addEventListener(`focusout`,t=>{let r=t.relatedTarget;!n.contains(r)&&!this.groupWraps[e].contains(r)&&this.scheduleHideFlyout()}),this.flyoutEl=n,this.flyoutIdx=e,this.host.appendChild(n),this.placeFlyout(n,this.groupButtons[e]),this.groupButtons[e].setAttribute(`aria-expanded`,`true`)}flyoutItems(){return this.flyoutEl?[...this.flyoutEl.querySelectorAll(`.tcw-flyout-item`)]:[]}focusFlyoutItem(e){let t=this.flyoutItems();t.length!==0&&t[(e+t.length)%t.length].focus()}onFlyoutKey(e,t){let n=this.flyoutItems(),r=n.indexOf(document.activeElement);switch(e.key){case`ArrowDown`:this.focusFlyoutItem(r+1);break;case`ArrowUp`:this.focusFlyoutItem(r-1);break;case`Home`:this.focusFlyoutItem(0);break;case`End`:this.focusFlyoutItem(n.length-1);break;case`Escape`:case`ArrowLeft`:e.stopPropagation(),this.hideFlyout(),this.groupButtons[t]?.focus();break;case`Tab`:this.hideFlyout(),this.groupButtons[t]?.focus();return;default:return}e.preventDefault()}placeFlyout(e,t){let n=this.host.getBoundingClientRect(),r=t.getBoundingClientRect();e.style.maxHeight=`${Math.max(0,this.host.clientHeight-hn*2)}px`;let i=this.host.clientHeight-e.offsetHeight-hn;this.host.closest(`[dir]`)?.getAttribute(`dir`)===`rtl`?(e.style.left=``,e.style.right=`${n.right-r.left}px`):(e.style.right=``,e.style.left=`${r.right-n.left}px`),e.style.top=`${Math.max(0,Math.min(r.top-n.top,i))}px`}scheduleHideFlyout(){this.cancelHideFlyout(),this.flyoutHideTimer=setTimeout(()=>{this.flyoutHideTimer=null,this.hideFlyout()},mn)}cancelHideFlyout(){this.flyoutHideTimer!==null&&(clearTimeout(this.flyoutHideTimer),this.flyoutHideTimer=null)}hideFlyout(){this.cancelHideFlyout(),this.flyoutEl&&=(this.flyoutEl.remove(),null),this.groupButtons[this.flyoutIdx]?.setAttribute(`aria-expanded`,`false`),this.flyoutIdx=-1}update(e){this.cursorBtn&&this.cursorBtn.classList.toggle(`tcw-active`,e.activeTool===null);let t=e.activeTool??``;t!==this.fabShows&&(this.fabShows=t,this.fab.innerHTML=e.activeTool?tt(e.activeTool,18):O(`penLine`,18)),this.fab.classList.toggle(`tcw-active`,e.activeTool!==null||e.eraser||e.zoomArea);let{drawingToolGroups:n}=this.config;for(let t=0;t<n.length;t++){let r=n[t].tools.some(t=>t.value===e.activeTool);this.groupButtons[t].classList.toggle(`tcw-active`,r),r&&e.activeTool&&e.activeTool!==this.groupTools[t]&&(this.groupTools[t]=e.activeTool,this.groupIcons[t].innerHTML=tt(e.activeTool,pn),n[t].tools.length>1&&this.groupButtons[t].setAttribute(`aria-label`,`${n[t].label}: ${_n(n,e.activeTool)}`))}if(this.flyoutEl&&this.flyoutEl.querySelectorAll(`.tcw-flyout-item`).forEach(t=>{let n=t;n.classList.toggle(`tcw-active`,n.dataset.toolValue===e.activeTool)}),this.magnetBtn){let t=e.magnetEnabled&&e.magnetStrong;this.magnetBtn.classList.toggle(`tcw-active`,e.magnetEnabled),this.magnetBtn.innerHTML=O(t?`magnetStrong`:`magnet`,14),this.magnetBtn.title=t?this.t(`drawing.magnetStrong`):e.magnetEnabled?this.t(`drawing.magnetOn`):this.t(`drawing.magnetOff`),this.magnetBtn.setAttribute(`aria-label`,this.magnetBtn.title)}for(let[t,n]of[[this.eraserBtn,e.eraser],[this.zoomBtn,e.zoomArea]])t&&(t.classList.toggle(`tcw-active`,n),t.setAttribute(`aria-pressed`,String(n)));this.stayBtn&&(this.stayBtn.classList.toggle(`tcw-active`,e.stayInDrawing),this.stayBtn.setAttribute(`aria-pressed`,String(e.stayInDrawing)))}addHostButton(e){let t=document.createElement(`button`);return t.type=`button`,t.className=`tcw-sidebar-btn tcw-host-btn`,t.dataset.hostButton=e.id,t.title=e.label,t.setAttribute(`aria-label`,e.label),e.toggle&&t.setAttribute(`aria-pressed`,`false`),typeof e.icon==`string`?t.innerHTML=O(e.icon,14):t.appendChild(e.icon),t.addEventListener(`click`,()=>e.onClick(t)),this.hostEl?.appendChild(t),this.tidy(),t}hostSlot(){return this.hostEl}tidy(){Je(this.el,`tcw-sidebar-divider`,`tcw-sidebar-spacer`)}toggleButton(e,t,n){let r=document.createElement(`button`);return r.className=`tcw-sidebar-btn`,r.title=t,r.setAttribute(`aria-label`,t),r.setAttribute(`aria-pressed`,`false`),r.innerHTML=O(e,14),r.addEventListener(`click`,n),r}appendDivider(){this.el.lastElementChild?.classList.contains(`tcw-sidebar-divider`)||this.el.appendChild(this.divider())}divider(){let e=document.createElement(`div`);return e.className=`tcw-sidebar-divider`,e}destroy(){this.setOpen(!1),this.hideFlyout(),this.fab.remove(),this.el.remove()}},bn=`button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])`;function M(e,t){if(e.key!==`Tab`)return;let n=document.activeElement,r=[...t.querySelectorAll(bn)].filter(e=>e.tabIndex>=0&&(e.getClientRects().length>0||e===n));if(r.length===0)return;let i=r[0],a=r[r.length-1],o=n instanceof Node&&t.contains(n),s=(e,t)=>(e.compareDocumentPosition(t)&Node.DOCUMENT_POSITION_PRECEDING)!==0;e.shiftKey&&(!o||n===i||s(i,n))?(e.preventDefault(),a.focus()):!e.shiftKey&&(!o||n===a||s(n,a))&&(e.preventDefault(),i.focus())}function xn(e,t){let n=document.createElement(`label`);n.className=`tcw-settings-row`;let r=document.createElement(`span`);return r.className=`tcw-settings-label`,r.textContent=e,n.append(r,t),n}function Sn(e,t,n){let r=document.createElement(`label`);r.className=`tcw-settings-row tcw-check-row`;let i=document.createElement(`input`);i.type=`checkbox`,i.checked=t,i.addEventListener(`change`,()=>n(i.checked));let a=document.createElement(`span`);return a.className=`tcw-settings-label`,a.textContent=e,r.append(i,a),r}function Cn(e,t){let n=document.createElement(`button`);return n.type=`button`,n.className=`tcw-toggle${e?` tcw-on`:``}`,n.setAttribute(`role`,`switch`),n.setAttribute(`aria-checked`,String(e)),n.addEventListener(`click`,()=>{let e=!n.classList.contains(`tcw-on`);n.classList.toggle(`tcw-on`,e),n.setAttribute(`aria-checked`,String(e)),t(e)}),n}function N(e,t,n){let r=document.createElement(`input`);return r.type=`number`,r.className=`tcw-indi-input`,r.value=String(e),r.step=String(t.step??(Number.isInteger(e)?1:.001)),t.min!==void 0&&(r.min=String(t.min)),t.max!==void 0&&(r.max=String(t.max)),r.addEventListener(`change`,()=>{if(r.value.trim()===``)return;let e=Number(r.value);Number.isFinite(e)&&(t.min!==void 0&&(e=Math.max(t.min,e)),t.max!==void 0&&(e=Math.min(t.max,e)),r.value=String(e),n(e))}),r}function P(e,t){let n=document.createElement(`input`);return n.type=`color`,n.className=`tcw-indi-color`,n.value=I(e),n.addEventListener(`input`,()=>t(n.value)),n}function F(e,t,n){let r=document.createElement(`select`);r.className=`tcw-indi-input tcw-indi-select`;for(let t of e){let e=document.createElement(`option`);e.value=t.value,e.textContent=t.label,r.appendChild(e)}return r.value=t,r.addEventListener(`change`,()=>n(r.value)),r}function I(e){if(typeof e!=`string`)return`#000000`;let t=e.trim();if(/^#[0-9a-f]{6}$/i.test(t))return t.toLowerCase();if(/^#[0-9a-f]{8}$/i.test(t))return t.slice(0,7).toLowerCase();if(/^#[0-9a-f]{3,4}$/i.test(t))return`#${t[1]}${t[1]}${t[2]}${t[2]}${t[3]}${t[3]}`.toLowerCase();let n=/^rgba?\(\s*(\d+)[\s,]+(\d+)[\s,]+(\d+)/i.exec(t);if(n)return`#${[n[1],n[2],n[3]].map(e=>Math.min(255,Number(e)).toString(16).padStart(2,`0`)).join(``)}`;let r=wn(t);return r!==null&&r!==t?I(r):`#000000`}var L;function wn(e){if(L===void 0)try{L=typeof document<`u`?document.createElement(`canvas`).getContext(`2d`):null}catch{L=null}if(!L)return null;L.fillStyle=`#010203`,L.fillStyle=e;let t=String(L.fillStyle);return t===`#010203`?null:t}function Tn(e){if(typeof e!=`string`)return 1;let t=/^rgba\([^)]*,\s*([\d.]+)\s*\)$/i.exec(e.trim());return t?Math.max(0,Math.min(1,Number(t[1]))):1}function En(e,t){let n=I(e),[r,i,a]=[1,3,5].map(e=>parseInt(n.slice(e,e+2),16));return`rgba(${r}, ${i}, ${a}, ${Math.round(t*100)/100})`}var Dn={ArrowRight:1,ArrowDown:1,ArrowLeft:-1,ArrowUp:-1};function On(e,t,n,r){let i=document.createElement(`div`);i.className=`tcw-segmented`,i.setAttribute(`role`,`radiogroup`),i.setAttribute(`aria-label`,r);let a=e.map(e=>{let t=document.createElement(`button`);return t.type=`button`,t.className=`tcw-segment`,t.setAttribute(`role`,`radio`),t.dataset.value=e.value,t.textContent=e.label,t.addEventListener(`click`,()=>s(e.value)),t}),o=e=>{let t=Math.max(0,a.findIndex(t=>t.dataset.value===e));a.forEach((n,r)=>{n.setAttribute(`aria-checked`,String(n.dataset.value===e)),n.tabIndex=r===t?0:-1})},s=e=>{o(e),n(e)};return i.addEventListener(`keydown`,t=>{let n=a.findIndex(e=>e===t.target);if(n<0||t.altKey||t.ctrlKey||t.metaKey)return;let r=a.length-1,o;if(t.key===`Home`)o=0;else if(t.key===`End`)o=r;else if(t.key in Dn){let e=i.closest(`[dir]`)?.getAttribute(`dir`)===`rtl`,r=t.key===`ArrowLeft`||t.key===`ArrowRight`;o=(n+(e&&r?-Dn[t.key]:Dn[t.key])+a.length)%a.length}else return;t.preventDefault(),a[o].focus(),s(e[o].value)}),o(t),i.append(...a),i}function kn(e,t,r){if(!(r>0)||!Number.isFinite(e))return e;let i=e/r,a=Math.round(i),o=Math.abs(i-a)<1e-9*Math.max(1,Math.abs(i)),s=t>0?o?a+1:Math.ceil(i):o?a-1:Math.floor(i);return s<1?e:Number((s*r).toFixed((0,n.stepDecimals)(r)))}function An(e,t){let n=document.createElement(`div`);n.className=`tcw-stepper`,n.dir=`ltr`;let r=n=>{let r=Number(e.value),i=e.value.trim()!==``&&Number.isFinite(r)?r:t.fallback?.()??0,a=kn(i,n,t.step(i,n));e.value=t.format?t.format(a):String(a),e.dispatchEvent(new Event(`input`))},i=(e,t)=>{let n=document.createElement(`button`);return n.type=`button`,n.className=`tcw-stepper-btn`,n.tabIndex=-1,n.setAttribute(`aria-label`,t),n.innerHTML=O(e>0?`plus`:`minus`,14),n.addEventListener(`click`,()=>r(e)),n};e.addEventListener(`keydown`,e=>{e.key!==`ArrowUp`&&e.key!==`ArrowDown`||(e.preventDefault(),r(e.key===`ArrowUp`?1:-1))});let a=i(-1,t.labels.down),o=i(1,t.labels.up);return n.append(a,e,o),{element:n,down:a,up:o}}var jn=0,Mn=0,Nn=20;function Pn(e){let t=document.createElement(`div`);if(t.className=`tcw-settings-section`,e){let n=document.createElement(`div`);n.className=`tcw-settings-section-title`,n.textContent=e,t.appendChild(n),t.setAttribute(`role`,`group`),t.setAttribute(`aria-label`,e)}return t}function Fn(e){let t=document.createElement(`div`);t.className=`tcw-settings-row`;let n=document.createElement(`span`);return n.className=`tcw-settings-label`,n.textContent=e,t.appendChild(n),t}function In(e,t,n,r,i){let a=Fn(e),o=document.createElement(`div`);o.className=`tcw-color-picker-wrap`;let s=document.createElement(`input`);s.type=`color`,s.setAttribute(`aria-label`,e);let c=document.createElement(`span`);c.className=`tcw-color-hex`,c.id=`tcw-color-${++jn}`,s.setAttribute(`aria-describedby`,c.id);let l=null,u=t=>{s.value=I(t??r.start?.()),c.textContent=t??i(`settings.auto`),a.classList.toggle(`tcw-color-auto`,t===null),t!==null&&r.start&&!l?(l=document.createElement(`button`),l.type=`button`,l.className=`tcw-color-auto-btn`,l.textContent=i(`settings.auto`),l.setAttribute(`aria-label`,`${e}: ${i(`settings.auto`)}`),l.addEventListener(`click`,()=>{n(null),s.focus(),u(r.read())}),o.appendChild(l)):t===null&&l&&(l.remove(),l=null)};return s.addEventListener(`input`,()=>{n(s.value),u(s.value)}),o.append(s,c),a.appendChild(o),u(t),{row:a,sync:()=>u(r.read())}}function R(e,t,n){let r=Fn(e),i=document.createElement(`button`);return i.type=`button`,i.className=`tcw-toggle${t?` tcw-on`:``}`,i.setAttribute(`role`,`switch`),i.setAttribute(`aria-checked`,String(t)),i.setAttribute(`aria-label`,e),i.addEventListener(`click`,()=>{let e=!i.classList.contains(`tcw-on`);i.classList.toggle(`tcw-on`,e),i.setAttribute(`aria-checked`,String(e)),n(e)}),r.appendChild(i),r}function z(e,t,n,r){let i=Fn(e),a=document.createElement(`select`);a.className=`tcw-settings-select`,a.setAttribute(`aria-label`,e);for(let e of n){let n=document.createElement(`option`);n.value=e.value,n.textContent=e.label,e.value===t&&(n.selected=!0),a.appendChild(n)}return n.some(e=>e.value===t)||(a.selectedIndex=-1),a.addEventListener(`change`,()=>r(a.value)),i.appendChild(a),i}function Ln(e,t,n,r,i=e=>String(e)){let a=Fn(e),o=document.createElement(`div`);o.className=`tcw-settings-range`;let s=document.createElement(`input`);s.type=`range`,s.min=String(n.min),s.max=String(n.max),s.step=String(n.step),s.value=String(t),s.setAttribute(`aria-label`,e);let c=document.createElement(`span`);return c.className=`tcw-settings-range-val`,c.textContent=i(t),s.addEventListener(`input`,()=>{let e=Number(s.value);c.textContent=i(e),r(e)}),o.append(s,c),a.appendChild(o),a}function Rn(e,n,r){let i=new Intl.NumberFormat(r,{maximumFractionDigits:Nn}).format;return e.step===`1`&&Number.isFinite(e.max)?t.r(n(`settings.numberWhole`),{min:i(Math.max(1,e.min??1)),max:i(e.max)}):t.r(n(`settings.numberAtLeast`),{min:i(e.min??0)})}function zn(e,t,n,r,i,a=`en-US`){let o=document.createElement(`div`);o.className=`tcw-settings-row tcw-settings-row--number`;let s=document.createElement(`label`);s.className=`tcw-settings-label`,s.textContent=e,o.appendChild(s);let c=document.createElement(`input`);c.type=`number`,c.className=`tcw-settings-number`,c.min=`0`,c.step=n.step,Number.isFinite(n.max)&&(c.max=String(n.max)),c.placeholder=i(`settings.auto`),c.value=t===null?``:String(t),c.setAttribute(`aria-label`,e);let l=document.createElement(`div`);l.className=`tcw-settings-hint`,l.id=`tcw-number-hint-${++Mn}`,l.setAttribute(`role`,`status`),c.setAttribute(`aria-describedby`,l.id);let u=e=>{e?c.removeAttribute(`aria-invalid`):c.setAttribute(`aria-invalid`,`true`),l.textContent=e?``:Rn(n,i,a)};return c.addEventListener(`change`,()=>{if(c.value.trim()===``){u(!0),r(null);return}let e=Number(c.value),t=Number.isFinite(e)&&e>0&&e>=(n.min??0)&&e<=n.max&&(n.step!==`1`||Number.isInteger(e));u(t),t&&r(e)}),o.append(c,l),o}var B=[{id:`symbol`,icon:`chartType:candlestick`},{id:`statusLine`,icon:`type`},{id:`scales`,icon:`ruler`},{id:`appearance`,icon:`palette`},{id:`layers`,icon:`layers`},{id:`trading`,icon:`trendingUp`}],Bn=[1,2,3,4],Vn=`t:`,Hn={step:`any`,max:1/0,min:1e-8},Un=1,Wn=class{callbacks;t;backdrop=null;modal=null;bodyEl=null;tabButtons=[];templateBtn=null;menu=null;currentTab=`symbol`;currentSettings=null;chartType=null;lookRows=[];returnFocus=null;uid=Un++;constructor(e,t,n={},r=()=>document.body){this.available=n,this.host=r,this.callbacks=e,this.t=t}open(e,t=null,n=`symbol`){this.modal&&this.remove(),this.returnFocus=document.activeElement instanceof HTMLElement?document.activeElement:null,this.currentSettings={...e},this.chartType=t,this.currentTab=n,this.buildModal(),this.tabButtons.find(e=>e.dataset.tab===n)?.focus()}isOpen(){return this.modal!==null}refresh(e,t){if(!this.modal)return;this.currentSettings={...e},t!==void 0&&(this.chartType=t);let n=this.focusedControl();this.renderTabContent(),n!==null&&this.focusControl(n)}focusedControl(){let e=document.activeElement;if(!this.bodyEl||!(e instanceof HTMLElement)||!this.bodyEl.contains(e))return null;let t=this.panelControls().indexOf(e);return t<0?null:t}focusControl(e){let t=this.panelControls();(t[Math.min(e,t.length-1)]??this.tabButtons.find(e=>e.dataset.tab===this.currentTab))?.focus()}panelControls(){return this.bodyEl?[...this.bodyEl.querySelectorAll(bn)]:[]}close(){this.finish(!0)}destroy(){this.remove()}finish(e){this.modal&&(e?this.callbacks.onClose():this.callbacks.onCancel?.(),this.remove(),this.returnFocus?.isConnected&&this.returnFocus.focus(),this.returnFocus=null)}remove(){this.menu?.destroy(),this.menu=null,this.backdrop?.remove(),this.backdrop=this.modal=this.bodyEl=this.templateBtn=null,this.tabButtons=[]}buildModal(){let e=document.createElement(`div`);e.className=`tcw-modal-backdrop`;let t=!1;e.addEventListener(`pointerdown`,n=>{t=n.target===e}),e.addEventListener(`click`,n=>{n.target===e&&t&&this.finish(!1),t=!1});let n=document.createElement(`div`);n.className=`tcw-modal tcw-set`,n.setAttribute(`role`,`dialog`),n.setAttribute(`aria-modal`,`true`),n.setAttribute(`aria-labelledby`,`tcw-set-title-${this.uid}`),n.tabIndex=-1,n.addEventListener(`keydown`,e=>{if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),this.finish(!1);return}M(e,n)}),this.backdrop=e,this.modal=n,n.append(this.buildHeader(),this.buildBody(),this.buildFooter()),e.appendChild(n),this.host().appendChild(e),this.markTabs(),this.renderTabContent()}buildHeader(){let e=document.createElement(`div`);e.className=`tcw-modal-header`;let t=document.createElement(`h3`);t.id=`tcw-set-title-${this.uid}`,t.textContent=this.t(`settings.title`);let n=document.createElement(`button`);return n.type=`button`,n.className=`tcw-modal-close`,n.setAttribute(`aria-label`,this.t(`common.close`)),n.innerHTML=O(`x`,16),n.addEventListener(`click`,()=>this.finish(!1)),e.append(t,n),e}buildBody(){let e=document.createElement(`div`);e.className=`tcw-set-body`;let t=document.createElement(`div`);t.className=`tcw-set-nav`,t.setAttribute(`role`,`tablist`),t.setAttribute(`aria-orientation`,`vertical`),t.setAttribute(`aria-label`,this.t(`settings.title`)),t.addEventListener(`keydown`,e=>this.onTabKey(e)),this.tabButtons=B.map(({id:e,icon:t})=>{let n=document.createElement(`button`);return n.type=`button`,n.className=`tcw-set-tab`,n.id=`tcw-set-tab-${this.uid}-${e}`,n.dataset.tab=e,n.setAttribute(`role`,`tab`),n.setAttribute(`aria-controls`,`tcw-set-panel-${this.uid}`),n.innerHTML=`${t.startsWith(`chartType:`)?nt(t.slice(10),16):O(t,16)}<span></span>`,n.querySelector(`span`).textContent=this.t(`settings.tab.${e}`),n.addEventListener(`click`,()=>this.selectTab(e)),n}),t.append(...this.tabButtons);let n=document.createElement(`div`);return n.className=`tcw-modal-body tcw-set-panel`,n.id=`tcw-set-panel-${this.uid}`,n.setAttribute(`role`,`tabpanel`),this.bodyEl=n,e.append(t,n),e}buildFooter(){let e=document.createElement(`div`);e.className=`tcw-modal-footer`;let t=this.footerButton(`template`,`tcw-footer-menu`,()=>this.openTemplates());t.setAttribute(`aria-haspopup`,`menu`),t.setAttribute(`aria-expanded`,`false`),t.innerHTML=`<span></span>${O(`chevronDown`,12)}`,t.querySelector(`span`).textContent=this.t(`settings.template`),this.templateBtn=t;let n=document.createElement(`div`);return n.className=`tcw-footer-end`,n.append(this.footerButton(`cancel`,`tcw-footer-cancel`,()=>this.finish(!1),this.t(`common.cancel`)),this.footerButton(`ok`,`tcw-done-btn`,()=>this.finish(!0),this.t(`drawingSettings.ok`))),e.append(t,n),e}footerButton(e,t,n,r){let i=document.createElement(`button`);return i.type=`button`,i.className=t,i.dataset.act=e,r&&(i.textContent=r),i.addEventListener(`click`,n),i}markTabs(){for(let e of this.tabButtons){let t=e.dataset.tab===this.currentTab;e.classList.toggle(`tcw-active`,t),e.setAttribute(`aria-selected`,String(t)),e.tabIndex=t?0:-1,t&&this.bodyEl?.setAttribute(`aria-labelledby`,e.id)}}selectTab(e,t=!1){this.currentTab=e,this.markTabs(),this.renderTabContent(),t&&this.tabButtons.find(t=>t.dataset.tab===e)?.focus()}onTabKey(e){let t=B.findIndex(e=>e.id===this.currentTab),n=e.key===`ArrowDown`||e.key===`ArrowRight`?(t+1)%B.length:e.key===`ArrowUp`||e.key===`ArrowLeft`?(t-1+B.length)%B.length:e.key===`Home`?0:e.key===`End`?B.length-1:-1;n<0||(e.preventDefault(),this.selectTab(B[n].id,!0))}openTemplates(){let e=this.templateBtn;if(!this.modal||!e)return;if(this.menu?.isOpen()){this.menu.close();return}let n=this.callbacks.templates,r=(n?.list()??[]).map(e=>({id:`${Vn}${e}`,label:e,icon:`layers`,remove:t.r(this.t(`templates.delete`),{name:e})})),i=[...r,...r.length>0?[`separator`]:[],...n?[{id:`save`,label:this.t(`settings.saveTemplate`),icon:`save`}]:[],{id:`reset`,label:this.t(`settings.resetToDefaults`),icon:`reset`}];this.menu??=new A(this.modal,this.t(`settings.template`));let a=e.getBoundingClientRect(),o=this.modal.getBoundingClientRect();this.menu.open(i,a.left-o.left,a.top-o.top,e=>{e===`reset`?this.callbacks.onReset():e===`save`?n?.save():e.startsWith(Vn)&&n?.apply(e.slice(2))},e,e=>n?.remove(e.slice(2)))}renderTabContent(){if(!(!this.bodyEl||!this.currentSettings))switch(this.bodyEl.replaceChildren(),this.lookRows=[],this.currentTab){case`symbol`:this.renderSymbolTab(this.currentSettings);break;case`statusLine`:this.renderStatusLineTab(this.currentSettings);break;case`scales`:this.renderScalesTab(this.currentSettings);break;case`appearance`:this.renderAppearanceTab(this.currentSettings);break;case`layers`:this.renderLayersTab(this.currentSettings);break;case`trading`:for(let e of Ee)(!e.trading||this.available.trading!==!1)&&this.renderLookSection(e);break}}renderSymbolTab(e){this.renderChartTypeSection(),this.addSection(void 0,[R(this.t(`settings.mainSeries`),e.mainSeriesVisible,e=>this.patch({mainSeriesVisible:e})),R(this.t(`settings.extendedHours`),e.extendedHours,e=>this.patch({extendedHours:e}))]);let t=this.t(`common.show`);this.renderLookSection(ve),this.available.volume!==!1&&this.renderLookSection(ye,[R(t,e.volumeVisible,e=>this.patch({volumeVisible:e}))]),this.renderLookSection(be,[R(t,e.highLowLines,e=>this.patch({highLowLines:e}))])}renderStatusLineTab(e){let t=this.available.legend!==!1,n=t?Ce:Ce.filter(e=>!Se.includes(e));this.addSection(void 0,[...t?[R(this.t(`settings.ohlcLegend`),e.legendVisible,e=>this.patch({legendVisible:e}))]:[],...n.map(e=>this.lookRow(e))])}renderScalesTab(e){let t=[{value:`regular`,label:this.t(`settings.scale.regular`)},{value:`logarithmic`,label:this.t(`settings.scale.logarithmic`)},{value:`percentage`,label:this.t(`settings.scale.percentage`)},{value:`indexedTo100`,label:this.t(`settings.scale.indexedTo100`)}].filter(e=>e.value!==`logarithmic`||this.available.logScale!==!1),n=this.available.exchangeZone?.(),r=f(e.timezone,Date.now(),this.t(`settings.timezone.local`),n===void 0?void 0:{label:this.t(`settings.timezone.exchange`),zone:n});this.addSection(void 0,[z(this.t(`settings.priceScale`),e.scaleMode,t,e=>this.patch({scaleMode:e})),R(this.t(`settings.autoScale`),e.autoScale,e=>this.patch({autoScale:e})),R(this.t(`settings.invertScale`),e.invertScale,e=>this.patch({invertScale:e})),R(this.t(`settings.leftScale`),e.leftPriceScale,e=>this.patch({leftPriceScale:e})),R(this.t(`settings.indicatorValues`),e.indicatorValueLabels,e=>this.patch({indicatorValueLabels:e})),R(this.t(`settings.alignAxisLabels`),e.alignAxisLabels,e=>this.patch({alignAxisLabels:e})),...this.available.barCountdown===!1?[]:[R(this.t(`settings.barCountdown`),e.barCountdown,e=>this.patch({barCountdown:e}))],z(this.t(`settings.timezone`),e.timezone,r,e=>this.patch({timezone:e})),z(this.t(`settings.numberLocale`),e.numberLocale,gt(e.numberLocale),e=>this.patch({numberLocale:e}))]),this.addSection(this.t(`settings.section.axes`),we.map(e=>this.lookRow(e)))}renderAppearanceTab(e){let[t,n,r,...i]=Te;this.renderLookSection(t),this.renderLookSection(n,[R(this.t(`common.show`),e.gridVisible,e=>this.patch({gridVisible:e}))]),this.renderLookSection(r,[z(this.t(`settings.crosshairMode`),e.crosshairMode,[{label:this.t(`settings.crosshair.magnet`),value:`magnet`},{label:this.t(`settings.crosshair.normal`),value:`normal`},{label:this.t(`settings.crosshair.hidden`),value:`hidden`}],e=>this.patch({crosshairMode:e}))]);for(let e of i)this.renderLookSection(e)}renderLayersTab(e){let t=e=>`${Math.round(e*100)}%`,n=e=>this.t(e);this.addSection(void 0,[R(n(`settings.volumeProfile`),e.volumeProfileVisible,e=>this.patch({volumeProfileVisible:e}))]),this.addSection(void 0,[R(n(`settings.marketProfile`),e.marketProfileVisible,e=>this.patch({marketProfileVisible:e})),R(n(`settings.marketProfileSplit`),e.marketProfileSplit,e=>this.patch({marketProfileSplit:e})),R(n(`settings.marketProfileLetters`),e.marketProfileLetters,e=>this.patch({marketProfileLetters:e})),Ln(n(`settings.marketProfileBuckets`),e.marketProfileBuckets,{min:8,max:200,step:1},e=>this.patch({marketProfileBuckets:e})),Ln(n(`settings.marketProfileOpacity`),e.marketProfileOpacity,{min:.05,max:1,step:.05},e=>this.patch({marketProfileOpacity:e}),t)]),this.addSection(void 0,[R(n(`settings.depthHeatmap`),e.depthHeatmapVisible,e=>this.patch({depthHeatmapVisible:e})),Ln(n(`settings.depthHeatmapOpacity`),e.depthHeatmapOpacity,{min:.1,max:1,step:.05},e=>this.patch({depthHeatmapOpacity:e}),t)]),this.addSection(void 0,[R(n(`settings.swingMarkers`),e.pivotMarkersVisible,e=>this.patch({pivotMarkersVisible:e})),Ln(n(`settings.swingStrength`),e.pivotStrength,{min:2,max:20,step:1},e=>this.patch({pivotStrength:e})),R(n(`settings.swingStructure`),e.pivotStructureLabels,e=>this.patch({pivotStructureLabels:e}))]),this.addSection(void 0,[R(n(`settings.sessionShading`),e.sessionShadingVisible,e=>this.patch({sessionShadingVisible:e})),R(n(`settings.periodLevels`),e.periodLevelsVisible,e=>this.patch({periodLevelsVisible:e})),z(n(`settings.periodLevelsBasis`),e.periodLevelsPeriod,[{value:`day`,label:n(`settings.priorDay`)},{value:`week`,label:n(`settings.priorWeek`)}],e=>this.patch({periodLevelsPeriod:e}))])}addSection(e,t){let n=Pn(e);return n.append(...t),this.bodyEl?.appendChild(n),n}renderLookSection(e,t=[]){this.addSection(this.t(e.title),[...t,...e.rows.map(e=>this.lookRow(e))])}lookRow(e){let t=this.t(e.label),r=()=>this.callbacks.styleValue(e.keys[0]),i=()=>{let t=e.keys.map(e=>this.callbacks.styleValue(e));return t.every(e=>e===t[0])&&t[0]!==null?String(t[0]):``},a,o=t=>{this.callbacks.onStyleChange(Object.fromEntries(e.keys.map(e=>[e,t])));for(let e of this.lookRows)e.el!==a&&e.sync()},s=e.auto?[{value:``,label:this.t(`settings.auto`)}]:[],c;switch(n.CHART_STYLE_KEYS[e.keys[0]]){case`boolean`:{a=R(t,r()===!0,o);let e=a.querySelector(`button`);c=()=>{let t=r()===!0;e.classList.toggle(`tcw-on`,t),e.setAttribute(`aria-checked`,String(t))};break}case`lineStyle`:a=z(t,i(),[...s,...this.lineStyles()],e=>o(e===``?null:Kn(e))),c=()=>{a.querySelector(`select`).value=i()};break;case`width`:{let e=r(),n=typeof e==`number`&&!Bn.includes(e)?[...Bn,e].sort((e,t)=>e-t):Bn;a=z(t,i(),[...s,...n.map(e=>({value:String(e),label:`${e}px`}))],e=>o(e===``?null:Number(e))),c=()=>{a.querySelector(`select`).value=i()};break}default:{let n=r(),i=In(t,typeof n==`string`?n:null,o,{read:()=>{let e=r();return typeof e==`string`?e:null},start:e.auto?()=>(e.auto?.from?this.callbacks.styleValue(e.auto.from):e.auto?.hint)??null:void 0},this.t);a=i.row,c=i.sync}}return this.lookRows.push({el:a,sync:c}),a}lineStyles(){return[{value:`solid`,label:this.t(`drawingSettings.lineStyle.solid`)},{value:`dashed`,label:this.t(`drawingSettings.lineStyle.dashed`)},{value:`dotted`,label:this.t(`drawingSettings.lineStyle.dotted`)}]}renderChartTypeSection(){if(!this.bodyEl||!this.currentSettings||!this.chartType)return;let e=this.chartType,t=this.currentSettings.chartTypeOptions??{},n=pe.find(t=>t.value===e),r=Pn(n?vt(n,this.t):e),i=()=>this.currentSettings?.chartTypeOptions??{},a=(e,t)=>this.patch({chartTypeOptions:{...i(),[e]:t}}),o=(e,t,n,i)=>r.appendChild(zn(this.t(e),t,n,i,this.t,this.currentSettings?.numberLocale||void 0));switch(e){case`renko`:{let e=t.renko??{};o(`settings.boxSize`,typeof e.boxSize==`number`?e.boxSize:null,Hn,e=>a(`renko`,{...i().renko??{},boxSize:e??`atr`})),o(`settings.atrPeriod`,e.atrPeriod??null,{step:`1`,max:500},e=>a(`renko`,Gn(i().renko,`atrPeriod`,e)));break}case`lineBreak`:o(`settings.lineBreakLines`,t.lineBreak?.lines??null,{step:`1`,max:10},e=>a(`lineBreak`,Gn(i().lineBreak,`lines`,e)));break;case`kagi`:o(`settings.reversal`,t.kagi?.reversal??null,Hn,e=>a(`kagi`,Gn(i().kagi,`reversal`,e))),r.appendChild(z(this.t(`settings.reversalType`),t.kagi?.reversalType??`percent`,[{value:`percent`,label:this.t(`settings.reversalType.percent`)},{value:`price`,label:this.t(`settings.reversalType.price`)}],e=>a(`kagi`,{...i().kagi??{},reversalType:e===`price`?`price`:`percent`})));break;case`pointAndFigure`:o(`settings.boxSize`,typeof t.pointAndFigure?.boxSize==`number`?t.pointAndFigure.boxSize:null,Hn,e=>a(`pointAndFigure`,{...i().pointAndFigure??{},boxSize:e??`auto`})),o(`settings.reversalBoxes`,t.pointAndFigure?.reversal??null,{step:`1`,max:10},e=>a(`pointAndFigure`,Gn(i().pointAndFigure,`reversal`,e)));break;case`rangeBars`:o(`settings.barRange`,typeof t.rangeBars?.range==`number`?t.rangeBars.range:null,Hn,e=>a(`rangeBars`,{range:e??`auto`}));break;default:break}for(let t of ke(e))r.appendChild(this.lookRow(t));this.bodyEl.appendChild(r)}patch(e){this.currentSettings&&Object.assign(this.currentSettings,e),this.callbacks.onChange(e)}};function Gn(e,t,n){let r={...e??{}};return n===null?delete r[t]:r[t]=n,r}function Kn(e){return e===`dashed`||e===`dotted`?e:`solid`}var qn=`data-tcw-folded`,Jn=`tcw-statusbar--folded`,Yn=`tcw-statusbar--short-market`,Xn=1,Zn=13,Qn=`goto`,$n=`Alt+G`,er=e=>e.goToKeys?e.goToKeys():$n;function tr(e,t){let n=document.createElement(`span`);return n.className=e,n.textContent=t,n}var nr=class{el;dotEl;messageEl;marketEl;hostLeft;hostRight;clockBtn=null;clockMenu=null;scaleBtns=null;scaleShown=``;marketShown=``;rightEl;rangeEl=null;presetBtns=[];moreBtn=null;goToBtn=null;rangeMenu=null;resizeObserver=null;fitFrame=0;destroyed=!1;constructor(e,t,n={}){this.host=e,this.extras=n,this.el=document.createElement(`div`),this.el.className=`tcw-statusbar`,D(this.el,`statusBar`),n.label&&(this.el.setAttribute(`role`,`group`),this.el.setAttribute(`aria-label`,n.label)),t&&this.el.appendChild(this.buildRange(t)),this.hostLeft=this.hostGroup(),this.el.appendChild(this.hostLeft);let r=document.createElement(`div`);r.className=`tcw-status-right`,this.rightEl=r,this.hostRight=this.hostGroup(),r.appendChild(this.hostRight);let i=document.createElement(`div`);i.className=`tcw-status-indicator`,D(i,`statusBar.connection`),this.dotEl=document.createElement(`span`),this.dotEl.className=`tcw-status-dot`,i.appendChild(this.dotEl),this.messageEl=document.createElement(`span`),i.appendChild(this.messageEl),this.marketEl=document.createElement(`span`),this.marketEl.className=`tcw-status-market`,this.marketEl.hidden=!0,D(this.marketEl,`statusBar.market`),r.appendChild(this.marketEl),r.appendChild(i),n.clock&&r.appendChild(this.buildClock(n.clock)),n.scale&&r.appendChild(this.buildScale(n.scale)),this.el.appendChild(r),e.appendChild(this.el),this.watchWidths(r)}watchWidths(e){if(typeof ResizeObserver<`u`){this.resizeObserver=new ResizeObserver(()=>this.scheduleFit());for(let t of[this.el,e,this.hostLeft])this.resizeObserver.observe(t)}document.fonts?.ready.then(()=>this.scheduleFit())}scheduleFit(){this.destroyed||this.fitFrame||typeof requestAnimationFrame>`u`||(this.fitFrame=requestAnimationFrame(()=>{this.fitFrame=0,this.destroyed||this.fit()}))}fit(){let e=this.foldedCount(),t=this.rangeFocus();this.refit(),this.foldedCount()!==e&&this.rangeMenu?.close(),this.keepFocus(t)}refit(){let e=this.foldSteps(),t=this.goToBtn?[...this.presetBtns,this.goToBtn]:this.presetBtns,n=n=>{let r=new Set(e.slice(0,n));for(let e of t)e.toggleAttribute(qn,r.has(e));this.el.classList.toggle(Jn,n>0)};if(n(0),this.el.classList.remove(Yn),this.el.clientWidth===0||this.fits())return;let r=0;for(;r<e.length;)if(n(++r),this.fits())return;if(!(this.marketEl.hidden||this.isOff(this.marketEl))){for(this.el.classList.add(Yn);r>0;r--)if(n(r-1),!this.fits()){n(r);return}}}fits(){return this.rangeFits()&&this.rightFits()}rangeFits(){let e=this.rangeEl;return!e||e.scrollWidth<=e.clientWidth+Xn}rightFits(){if(this.rightEl.offsetParent!==this.el)return!0;let e=getComputedStyle(this.el),t=this.rightEl.offsetLeft;return(e.direction===`rtl`?(parseFloat(e.paddingLeft)||0)-t:t+this.rightEl.offsetWidth-(this.el.clientWidth-(parseFloat(e.paddingRight)||0)))<=Xn}foldedCount(){return this.rangeEl?.querySelectorAll(`[${qn}]`).length??0}rangeFocus(){if(this.rangeMenu?.hasFocus())return this.moreBtn;let e=document.activeElement;return e instanceof HTMLElement&&this.rangeEl?.contains(e)?e:null}keepFocus(e){if(!e||this.rangeMenu?.isOpen())return;let t=this.focusAfterRefit(e);t===this.el?this.focusBar():document.activeElement!==t&&t.focus({preventScroll:!0})}focusAfterRefit(e){if(this.shows(e))return e;let t=this.presetBtns.filter(e=>this.shows(e)).at(-1);return[e===this.moreBtn?null:this.moreBtn,this.goToBtn,t].find(e=>e!=null&&this.shows(e))??this.firstOtherControl()??this.el}firstOtherControl(){return[...this.el.querySelectorAll(`button`)].filter(e=>!this.rangeEl?.contains(e)).find(e=>!e.disabled&&e.getClientRects().length>0)??null}focusBar(){if(document.activeElement===this.el)return;let e=()=>this.el.removeAttribute(`tabindex`);this.el.tabIndex=-1,this.el.addEventListener(`blur`,e,{once:!0}),this.el.focus({preventScroll:!0}),document.activeElement!==this.el&&(this.el.removeEventListener(`blur`,e),e())}shows(e){return e===this.moreBtn&&!this.el.classList.contains(Jn)?!1:!e.hasAttribute(qn)&&!this.isOff(e)}foldSteps(){if(this.presetBtns.length===0||this.isOff(this.presetBtns[0]))return[];let e=[...this.presetBtns].reverse();return this.goToBtn&&e.push(this.goToBtn),e}isOff(e){let t=((this.el.closest(`.tcw-root`)??this.host).getAttribute(`data-tcw-off`)??``).split(/\s+/).filter(Boolean);return(e.dataset.tcwPart??``).split(/\s+/).some(e=>t.includes(e))}update(e){this.dotEl.className=`tcw-status-dot`,e.connectionState===`connected`?this.dotEl.classList.add(`tcw-connected`):e.connectionState===`error`&&this.dotEl.classList.add(`tcw-error`),this.messageEl.textContent=e.message}tick(){if(!this.clockBtn||!this.extras.clock)return;let{time:e,zone:t}=this.extras.clock.now(),n=`${e} ${t}`;this.clockBtn.textContent!==n&&(this.clockBtn.textContent=n)}setScale(e){let t=`${e.mode}|${e.auto}`;!this.scaleBtns||t===this.scaleShown||(this.scaleShown=t,this.scaleBtns.percent?.setAttribute(`aria-pressed`,String(e.mode===`percentage`)),this.scaleBtns.log?.setAttribute(`aria-pressed`,String(e.mode===`logarithmic`)),this.scaleBtns.auto?.setAttribute(`aria-pressed`,String(e.auto)))}setMarket(e,t,n=t){let r=`${e}|${t}|${n}`;if(r===this.marketShown)return;if(this.marketShown=r,this.marketEl.hidden=e===`always`,this.marketEl.dataset.state=e,e===`always`){this.marketEl.replaceChildren(),this.marketEl.removeAttribute(`title`);return}this.marketEl.title=t;let i=tr(`tcw-status-market-short`,n);i.setAttribute(`aria-hidden`,`true`),this.marketEl.replaceChildren(tr(`tcw-status-market-text`,t),i)}addHostItem(e){let t=e.onClick,n=t?document.createElement(`button`):document.createElement(`span`);return n.className=t?`tcw-status-host-item tcw-status-host-btn`:`tcw-status-host-item`,n.dataset.hostItem=e.id,n.dir=`auto`,n.textContent=e.text,e.label&&(n.title=e.label,t||n.setAttribute(`role`,`group`),e.label!==e.text&&n.setAttribute(`aria-label`,`${e.label}: ${e.text}`)),n instanceof HTMLButtonElement&&t&&(n.type=`button`,n.addEventListener(`click`,()=>t(n))),(e.side===`left`?this.hostLeft:this.hostRight).appendChild(n),n}hostSlot(e){return e===`left`?this.hostLeft:this.hostRight}destroy(){this.destroyed=!0,this.resizeObserver?.disconnect(),this.fitFrame&&cancelAnimationFrame(this.fitFrame),this.clockMenu?.destroy(),this.rangeMenu?.destroy(),this.el.remove()}buildClock(e){let t=document.createElement(`button`);return t.type=`button`,t.className=`tcw-status-clock`,t.dataset.role=`clock`,t.dir=`auto`,t.title=e.label,t.setAttribute(`aria-haspopup`,`menu`),D(t,`statusBar.clock`),t.addEventListener(`click`,()=>this.toggleZones(t,e)),this.clockBtn=t,this.tick(),t}toggleRangeMenu(e,t){if(this.rangeMenu?.isOpen()){this.rangeMenu.close();return}let n=e=>e.hasAttribute(qn)&&!this.isOff(e),r=t.presets.filter((e,t)=>n(this.presetBtns[t])).map(e=>({id:e,label:t.presetLabels?.[e]??e}));if(this.goToBtn&&n(this.goToBtn)&&(r.length>0&&r.push(`separator`),r.push({id:Qn,label:t.goToLabel,icon:`calendar`,shortcut:er(t)})),r.length===0)return;this.rangeMenu??=new A(this.host,t.groupLabel);let i=e.getBoundingClientRect(),a=this.host.getBoundingClientRect();this.rangeMenu.open(r,i.left-a.left,i.top-a.top,e=>e===Qn?t.onGoTo():t.onPreset(e),e,void 0,i.right-a.left)}toggleZones(e,t){if(this.clockMenu?.isOpen()){this.clockMenu.close();return}let{current:n,list:r}=t.options();this.clockMenu??=new A(this.host,t.label);let i=e.getBoundingClientRect(),a=this.host.getBoundingClientRect();this.clockMenu.open(r.map(e=>({id:e.value,label:e.label,checked:e.value===n})),i.left-a.left,i.top-a.top,e=>t.onPick(e),e,void 0,i.right-a.left)}buildScale(e){let t=document.createElement(`div`);t.className=`tcw-status-scale`,t.setAttribute(`role`,`group`),e.labels.group&&t.setAttribute(`aria-label`,e.labels.group),D(t,`statusBar.scale`);let n=(n,r,i)=>{let a=document.createElement(`button`);return a.type=`button`,a.className=`tcw-status-scale-btn`,a.dataset.scale=n,a.textContent=r,a.title=e.labels[n],a.setAttribute(`aria-label`,e.labels[n]),a.setAttribute(`aria-pressed`,`false`),a.addEventListener(`click`,i),t.appendChild(a),a};return this.scaleBtns={percent:n(`percent`,`%`,e.onPercent),...e.onLog?{log:n(`log`,e.texts?.log??`log`,e.onLog)}:{},auto:n(`auto`,e.texts?.auto??`auto`,e.onAuto)},t}hostGroup(){let e=document.createElement(`div`);return e.className=`tcw-status-host`,e}buildRange(e){let t=document.createElement(`div`);t.className=`tcw-range-bar`,t.setAttribute(`role`,`group`),t.setAttribute(`aria-label`,e.groupLabel);for(let n of e.presets){let r=document.createElement(`button`);r.type=`button`,r.className=`tcw-range-btn`,r.dataset.range=n,D(r,`statusBar.range`),r.textContent=e.presetLabels?.[n]??n,r.addEventListener(`click`,()=>e.onPreset(n)),t.appendChild(r),this.presetBtns.push(r)}let n=this.rangeIconBtn(`tcw-range-more`,`rangeMore`,`more`,e.moreLabel);D(n,`statusBar.range`),n.setAttribute(`aria-haspopup`,`menu`),n.setAttribute(`aria-expanded`,`false`),n.addEventListener(`click`,()=>this.toggleRangeMenu(n,e)),t.appendChild(n),this.moreBtn=n;let r=this.rangeIconBtn(`tcw-range-goto`,`goto`,`calendar`,e.goToLabel);D(r,`goToDate`,`statusBar.goToDate`);let i=()=>{let t=er(e);r.title=t?`${e.goToLabel} (${t})`:e.goToLabel};return i(),r.addEventListener(`pointerover`,i),r.addEventListener(`focusin`,i),r.addEventListener(`click`,e.onGoTo),t.appendChild(r),this.goToBtn=r,this.rangeEl=t,t}rangeIconBtn(e,t,n,r){let i=document.createElement(`button`);return i.type=`button`,i.className=`tcw-range-btn ${e}`,i.dataset.role=t,i.title=r,i.setAttribute(`aria-label`,r),i.innerHTML=O(n,Zn),i}},rr=typeof navigator<`u`&&/mac|iphone|ipad|ipod/i.test(navigator.platform||navigator.userAgent)?`⌘`:`Ctrl`,ir=e=>e.toLowerCase().replace(/[\s+]+/g,``).replace(/[\u2010-\u2015\u2212]/g,`-`),ar=5,or=229,sr=[`action`,`drawing`,`chartType`,`timeframe`,`indicator`],cr={indicator:`palette.group.indicator`,chartType:`palette.group.chartType`,drawing:`palette.group.drawing`,timeframe:`palette.group.timeframe`,action:`palette.group.action`},lr=e=>`${e.category}:${e.id}`;function ur(e,t){let n=e.label.toLowerCase(),r=ir(n);return e.id.toLowerCase()===t||r===t?5:r.startsWith(t)?4:n.split(/[\s/()-]+/).some(e=>e.startsWith(t))?3:r.includes(t)||e.id.toLowerCase().includes(t)?2:e.shortcut&&ir(e.shortcut).includes(t)?1:0}var dr=0,fr=class{backdrop=null;input=null;list=null;emptyEl=null;liveEl=null;items=[];shown=[];selectedIndex=0;returnFocus=null;uid=++dr;constructor(e,n=()=>document.body,r=t.t,i){this.callbacks=e,this.host=n,this.t=r,this.recents=i}open(e){this.backdrop||(this.returnFocus=document.activeElement instanceof HTMLElement?document.activeElement:null,this.items=e,this.build(),this.render(),this.input?.focus())}close(){if(!this.backdrop)return;this.backdrop.remove(),this.backdrop=this.input=this.list=this.emptyEl=this.liveEl=null,this.callbacks.onClose();let e=this.returnFocus;this.returnFocus=null,e?.isConnected&&e.focus()}isOpen(){return this.backdrop!==null}destroy(){this.close()}build(){let e=document.createElement(`div`);e.className=`tcw-modal-backdrop`;let t=!1;e.addEventListener(`pointerdown`,n=>{t=n.target===e}),e.addEventListener(`click`,n=>{n.target===e&&t&&this.close(),t=!1});let n=document.createElement(`div`);n.className=`tcw-modal tcw-cp`,n.setAttribute(`role`,`dialog`),n.setAttribute(`aria-modal`,`true`),n.setAttribute(`aria-label`,this.t(`hotkeys.commandPalette`)),n.tabIndex=-1,n.addEventListener(`keydown`,e=>this.onKeyDown(e,n));let r=document.createElement(`label`);r.className=`tcw-ss-search tcw-cp-search`,r.innerHTML=O(`search`,16);let i=document.createElement(`input`);i.type=`search`,i.className=`tcw-cp-input`,i.placeholder=this.t(`palette.placeholder`),i.setAttribute(`aria-label`,this.t(`palette.placeholder`)),i.setAttribute(`role`,`combobox`),i.setAttribute(`aria-expanded`,`true`),i.setAttribute(`aria-autocomplete`,`list`),i.setAttribute(`aria-controls`,`tcw-cp-list-${this.uid}`),i.autocomplete=`off`,i.spellcheck=!1,i.addEventListener(`input`,()=>this.render()),r.appendChild(i);let a=document.createElement(`div`);a.className=`tcw-cp-results`;let o=document.createElement(`div`);o.className=`tcw-cp-list`,o.id=`tcw-cp-list-${this.uid}`,o.setAttribute(`role`,`listbox`),o.setAttribute(`aria-label`,this.t(`hotkeys.commandPalette`));let s=document.createElement(`div`);s.className=`tcw-cp-empty`,a.append(o,s),a.addEventListener(`mousedown`,e=>e.preventDefault());let c=document.createElement(`div`);c.className=`tcw-cp-live tcw-visually-hidden`,c.setAttribute(`aria-live`,`polite`),n.append(r,a,c),e.appendChild(n),this.host().appendChild(e),this.backdrop=e,this.input=i,this.list=o,this.emptyEl=s,this.liveEl=c}groups(){let e=ir((this.input?.value??``).trim()),t=[];if(!e){let e=new Map(this.items.map(e=>[lr(e),e])),n=(this.recents?.list()??[]).map(t=>e.get(t)).filter(e=>!!e).slice(0,ar);n.length>0&&t.push({key:`recent`,label:this.t(`palette.group.recent`),items:n})}for(let n of sr){let r=this.items.filter(e=>e.category===n);e&&(r=r.map((t,n)=>({item:t,at:n,s:ur(t,e)})).filter(e=>e.s>0).sort((e,t)=>t.s-e.s||e.at-t.at).map(e=>e.item)),r.length>0&&t.push({key:n,label:this.t(cr[n]),items:r})}return e&&t.sort((t,n)=>ur(n.items[0],e)-ur(t.items[0],e)),t}render(){let e=this.list;if(!e)return;let t=this.groups();this.shown=t.flatMap(e=>e.items),this.selectedIndex=0;let n=0;e.replaceChildren(...t.map(e=>{let t=document.createElement(`div`);t.setAttribute(`role`,`group`),t.className=`tcw-cp-group`;let r=document.createElement(`div`);return r.className=`tcw-cp-heading`,r.id=`tcw-cp-${e.key}-${this.uid}`,r.setAttribute(`role`,`presentation`),r.textContent=e.label,t.setAttribute(`aria-labelledby`,r.id),t.append(r,...e.items.map(e=>this.row(e,n++))),t}));let r=this.shown.length===0?this.t(`palette.empty`):``;this.emptyEl&&(this.emptyEl.textContent=r),this.emptyEl?.toggleAttribute(`hidden`,this.shown.length>0),this.liveEl&&(this.liveEl.textContent=r),this.markSelection()}row(e,t){let n=document.createElement(`div`);n.className=`tcw-cp-row`,n.id=`tcw-cp-opt-${this.uid}-${t}`,n.dataset.id=e.id,n.setAttribute(`role`,`option`),n.classList.toggle(`tcw-on`,!!e.active);let r=document.createElement(`span`);if(r.className=`tcw-cp-label`,r.textContent=e.label,n.appendChild(r),e.shortcut){let t=document.createElement(`kbd`);t.className=`tcw-cp-key`,t.dir=`ltr`,t.textContent=e.shortcut,n.appendChild(t)}if(e.active){let e=document.createElement(`span`);e.className=`tcw-cp-check`,e.innerHTML=O(`check`,14),n.appendChild(e)}return n.addEventListener(`click`,()=>this.run(t)),n.addEventListener(`mousemove`,()=>{this.selectedIndex!==t&&(this.selectedIndex=t,this.markSelection())}),n}markSelection(){let e=this.list?.querySelectorAll(`.tcw-cp-row`)??[],t=null;e.forEach((e,n)=>{let r=n===this.selectedIndex;e.setAttribute(`aria-selected`,String(r)),e.classList.toggle(`tcw-selected`,r),r&&(t=e)});let n=t;n?(this.input?.setAttribute(`aria-activedescendant`,n.id),n.scrollIntoView?.({block:`nearest`})):this.input?.removeAttribute(`aria-activedescendant`)}run(e){let t=this.shown[e];if(t)switch(this.recents?.add(lr(t)),this.close(),t.category){case`indicator`:this.callbacks.onIndicator(t.id);break;case`chartType`:this.callbacks.onChartType(t.id);break;case`drawing`:this.callbacks.onDrawingTool(t.id);break;case`timeframe`:this.callbacks.onTimeframe(t.id);break;case`action`:this.callbacks.onAction(t.id);break}}onKeyDown(e,t){if(e.stopPropagation(),e.isComposing||e.keyCode===or)return;let n=(e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`k`;if(e.key===`Escape`||n){e.preventDefault(),this.close();return}if(M(e,t),e.target!==this.input)return;let r=this.shown.length;if(e.key===`ArrowDown`||e.key===`ArrowUp`){if(e.preventDefault(),r===0)return;this.selectedIndex=(this.selectedIndex+(e.key===`ArrowDown`?1:-1)+r)%r,this.markSelection()}else e.key===`Enter`&&(e.preventDefault(),e.repeat||this.run(this.selectedIndex))}},pr=20,mr=1e3,hr=new Set,gr={stock:1,stocks:1,equity:1,share:1,shares:1,"cổ phiếu":1,株式:1,株:1,股票:1,주식:1,futures:2,future:2,derivative:2,derivatives:2,option:2,options:2,"phái sinh":2,先物:2,期货:2,期貨:2,선물:2,warrant:2,warrants:2,"covered warrant":2,"chứng quyền":2,index:3,indices:3,"chỉ số":3,指数:3,指數:3,지수:3,fund:3,funds:3,etf:3,etfs:3,"chứng chỉ quỹ":3,crypto:4,cryptocurrency:4,perpetual:4,perpetuals:4,perp:4,perps:4,"tiền mã hóa":4,"tiền mã hoá":4,"tiền điện tử":4,暗号資産:4,仮想通貨:4,加密货币:4,加密貨幣:4,数字货币:4,數字貨幣:4,虚拟货币:4,虛擬貨幣:4,암호화폐:4,가상자산:4,가상화폐:4,forex:5,fx:5,currency:5,"ngoại hối":5,為替:5,外国為替:5,外汇:5,外匯:5,외환:5,bond:5,bonds:5,"trái phiếu":5},_r=1e3,vr=new Map,yr=/i\u0307|\u0131/g;function br(e){if(typeof e!=`string`)return``;let t=vr.get(e);return t===void 0&&(t=e.trim().normalize(`NFC`).toLowerCase().replace(yr,`i`),vr.size>=_r&&vr.clear(),vr.set(e,t)),t}function xr(e){let t=br(e);return t?Object.prototype.hasOwnProperty.call(gr,t)?gr[t]:1+Sr(t)%5:0}function Sr(e){let t=2166136261;for(let n of e)t^=n.codePointAt(0),t=Math.imul(t,16777619)>>>0;return t}function Cr(e){let{ticker:t}=Qt(e),n=/[\p{L}\p{N}]/u.exec(t);return n?n[0].toUpperCase():``}function wr(e,t){let n=rn(t?.logo);if(!n||hr.has(n))return Er(e,t);let r=document.createElement(`img`);return r.className=`tcw-ss-badge`,r.alt=``,r.width=pr,r.height=pr,r.draggable=!1,r.setAttribute(`aria-hidden`,`true`),r.setAttribute(`loading`,`lazy`),r.setAttribute(`decoding`,`async`),r.setAttribute(`referrerpolicy`,`no-referrer`),r.addEventListener(`error`,()=>{Tr(n),r.replaceWith(Er(e,t))},{once:!0}),r.src=n,r}function Tr(e){hr.size>=mr&&hr.clear(),hr.add(e)}function Er(e,t){let n=document.createElement(`span`);return n.className=`tcw-ss-badge`,n.setAttribute(`aria-hidden`,`true`),n.dataset.kind=String(xr(t?.type)),n.textContent=Cr(e),n}var Dr=180,Or=150,kr=50;function Ar(e){return{upper:e.toUpperCase(),folded:Pr(e)}}function jr(e,t,n){return Math.max(Mr(e.toUpperCase(),n.upper),Nr(t,n.folded))}function Mr(e,t){if(e===t)return 1e3;if(e.startsWith(t))return 500+(50-Math.min(50,e.length-t.length));if(e.includes(t))return 200+(50-Math.min(50,e.length-t.length));let n=0,r=-1,i=0;for(let a=0;a<e.length&&n<t.length;a++)e[a]===t[n]&&(r>=0&&(i+=a-r-1),r=a,n++);return n<t.length?0:100-Math.min(99,i)}function Nr(e,t){if(!e||!t)return 0;if(e.startsWith(t))return Dr;let n=e.indexOf(t);return n<0?0:Or-Math.min(kr,n)}function Pr(e){return e.normalize(`NFD`).replace(/\p{M}+/gu,``).replace(/[đĐ]/g,`D`).toUpperCase()}function Fr(e,t,n=0,r=e.length){let i=t?Ir(e.toUpperCase(),t):new Set,a=``;for(let t=n;t<r;t++)a+=i.has(t)?`<mark>${k(e[t])}</mark>`:k(e[t]);return a}function Ir(e,t){let n=new Set,r=e.indexOf(t);if(r>=0){for(let e=r;e<r+t.length;e++)n.add(e);return n}let i=0;for(let r=0;r<e.length&&i<t.length;r++)e[r]===t[i]&&(n.add(r),i++);return i<t.length?new Set:n}function Lr(e,t){let n=document.createElement(`span`);n.className=`tcw-ss-symbol`,n.dir=`ltr`;let{venue:r}=Qt(e),i=(n,r,i)=>{let a=document.createElement(`span`);return a.className=n,a.innerHTML=Fr(e,t,r,i),a};return r&&n.appendChild(i(`tcw-ss-venue`,0,r.length)),n.appendChild(i(`tcw-ss-ticker`,r.length,e.length)),n}var Rr=br,zr=2,Br=1,Vr=class{el;kindsEl;exchangeEl;kinds=new Map;exchanges=new Map;kind=null;exchange=null;resize;constructor(e,t){this.t=e,this.onChange=t,this.el=document.createElement(`div`),this.el.className=`tcw-ss-filters`,this.el.hidden=!0,this.kindsEl=document.createElement(`div`),this.kindsEl.className=`tcw-ss-kinds`,this.kindsEl.setAttribute(`role`,`group`),this.kindsEl.setAttribute(`aria-label`,e(`symbolSearch.kinds`)),this.kindsEl.hidden=!0,this.kindsEl.addEventListener(`scroll`,()=>this.markMore(),{passive:!0}),this.resize=typeof ResizeObserver>`u`?null:new ResizeObserver(()=>this.markMore()),this.resize?.observe(this.kindsEl),this.exchangeEl=document.createElement(`select`),this.exchangeEl.className=`tcw-settings-select tcw-ss-exchange-filter`,this.exchangeEl.setAttribute(`aria-label`,e(`symbolSearch.exchange`)),this.exchangeEl.hidden=!0,this.exchangeEl.addEventListener(`change`,()=>{this.exchange=Rr(this.exchangeEl.value)||null,this.onChange(!1)}),this.el.append(this.kindsEl,this.exchangeEl)}see(e){let t=this.kinds.size,n=this.exchanges.size;for(let t of e)Hr(this.kinds,t?.type),Hr(this.exchanges,t?.exchange);this.kinds.size!==t&&this.renderKinds(),this.exchanges.size!==n&&this.renderExchanges(),this.kindsEl.hidden=this.kinds.size===0,this.exchangeEl.hidden=this.exchanges.size<zr,this.el.hidden=this.kindsEl.hidden&&this.exchangeEl.hidden,this.markMore()}destroy(){this.resize?.disconnect()}markMore(){let e=this.kindsEl,t=Math.abs(e.scrollLeft),n=e.scrollWidth-e.clientWidth,r=[t>Br?`start`:``,t<n-Br?`end`:``].filter(Boolean);r.length>0?e.dataset.more=r.join(` `):delete e.dataset.more}passes(e,t){return Ur(this.kind,Rr(e?.type),t)&&Ur(this.exchange,Rr(e?.exchange),t)}renderKinds(){let e=(e,t)=>{let n=document.createElement(`button`);return n.type=`button`,n.className=`tcw-ss-type`,n.textContent=t,e!==null&&(n.dir=`auto`),n.setAttribute(`aria-pressed`,String(this.kind===e)),n.addEventListener(`click`,()=>{this.kind=e;for(let e of this.kindsEl.children)e.setAttribute(`aria-pressed`,String(e===n));this.onChange(!0)}),n},t=[...this.kinds].map(([t,n])=>e(t,n));this.kindsEl.replaceChildren(e(null,this.t(`symbolSearch.allKinds`)),...t)}renderExchanges(){let e=(e,t)=>{let n=document.createElement(`option`);return n.value=e,n.textContent=t,e&&(n.dir=`auto`),n},t=[...this.exchanges.values()].map(t=>e(t,t));this.exchangeEl.replaceChildren(e(``,this.t(`symbolSearch.allExchanges`)),...t),this.exchangeEl.value=this.exchange===null?``:this.exchanges.get(this.exchange)??``}};function Hr(e,t){let n=Rr(t);n&&!e.has(n)&&e.set(n,t.trim())}function Ur(e,t,n){return e===null||t===e||n&&t===``}var Wr=229,Gr=1,Kr=class{backdrop=null;input=null;list=null;results=null;live=null;columns=null;filters=null;mode=null;given=[];rows=[];rowsGiven=!1;shown=[];compared=[];way=``;selectedIndex=0;searchFn=null;searchTimer=null;searchAbort=null;status=`idle`;pickOnResults=!1;heard=new Map;givenInfo=new Map;foldedNames=new Map;returnFocus=null;uid=Gr++;constructor(e,n=()=>document.body,r=t.t){this.callbacks=e,this.host=n,this.t=r}open(e){this.begin({kind:`search`,start:e})}openCompare(e){this.compared=e.compared,this.way=e.ways.some(t=>t.id===e.way)?e.way:e.ways[0]?.id??``,this.begin({kind:`compare`,start:e})}setCompared(e){if(this.compared=e,this.mode?.kind!==`compare`||!this.results)return;let t=this.results.contains(document.activeElement);this.renderList(),t&&!this.results.contains(document.activeElement)&&this.input?.focus()}close(){if(!this.backdrop)return;this.cancelSearch(),this.pickOnResults=!1,this.searchFn=null,this.backdrop.remove(),this.backdrop=this.input=this.list=this.results=this.live=this.columns=null,this.filters?.destroy(),this.filters=null,this.mode=null,this.callbacks.onClose();let e=this.returnFocus;this.returnFocus=null,e?.isConnected&&e.focus()}isOpen(){return this.backdrop!==null}isComparing(){return this.mode?.kind===`compare`}destroy(){this.close()}begin(e){this.backdrop&&this.close(),this.returnFocus=document.activeElement instanceof HTMLElement?document.activeElement:null,this.mode=e,this.searchFn=e.start.search??null,this.status=`idle`,this.learnGiven(e),this.build(e);let t=e.kind===`search`?e.start.query??``:``;this.input&&(this.input.value=t),t?(this.filter(),this.searchFn&&this.searchNow()):this.listGiven(),this.input?.focus()}learnGiven(e){let t=Jt(e.start.symbols);this.given=t.names,this.givenInfo=t.info,this.foldedNames=new Map;let n=e.start.current,r=e.kind===`search`?e.start.currentInfo:null;if(r&&typeof r==`object`&&n){let{description:e,logo:t}=Yt(r,n);this.givenInfo.set(n,Zt({symbol:n,description:e,logo:t},this.givenInfo.get(n)))}}infoOf(e){return Zt(this.givenInfo.get(e),this.heard.get(e))}build(e){let t=document.createElement(`div`);t.className=`tcw-modal-backdrop`;let n=!1;t.addEventListener(`pointerdown`,e=>{n=e.target===t}),t.addEventListener(`click`,e=>{e.target===t&&n&&this.close(),n=!1});let r=document.createElement(`div`);r.className=`tcw-modal tcw-ss${e.kind===`compare`?` tcw-ss--compare`:``}`,D(r,e.kind===`compare`?`compare`:`symbolSearch`),r.setAttribute(`role`,`dialog`),r.setAttribute(`aria-modal`,`true`),r.setAttribute(`aria-labelledby`,`tcw-ss-title-${this.uid}`),r.tabIndex=-1,r.addEventListener(`keydown`,e=>this.onKeyDown(e,r)),r.append(this.buildHeader(e),this.buildSearch()),e.kind===`compare`&&r.appendChild(this.buildWay(e.start));let i=new Vr(this.t,e=>{this.afterResults(!1),e&&this.input?.focus()}),a=document.createElement(`div`);a.className=`tcw-ss-list`,a.id=`tcw-ss-list-${this.uid}`,a.setAttribute(`role`,`listbox`);let o=document.createElement(`div`);o.className=`tcw-ss-results`;let s=this.buildColumns();o.append(s,a),o.addEventListener(`mousedown`,e=>{e.target.closest(`button`)||e.preventDefault()});let c=document.createElement(`div`);c.className=`tcw-ss-live tcw-visually-hidden`,c.setAttribute(`aria-live`,`polite`),r.append(i.el,o,c);let l=e.kind===`search`?e.start.hint:void 0;if(l){let e=document.createElement(`div`);e.className=`tcw-ss-foot`,e.textContent=l,r.appendChild(e)}t.appendChild(r),this.host().appendChild(t),this.backdrop=t,this.filters=i,this.columns=s,this.list=a,this.results=o,this.live=c}buildColumns(){let e=document.createElement(`div`);e.className=`tcw-ss-columns`,e.setAttribute(`aria-hidden`,`true`);let t=[``,this.t(`symbolSearch.symbol`),this.t(`symbolSearch.description`),this.t(`symbolSearch.type`),this.t(`symbolSearch.exchange`)];return e.append(...t.map(e=>this.tag(`tcw-ss-head`,e))),e}buildHeader(e){let t=document.createElement(`div`);t.className=`tcw-modal-header`;let n=document.createElement(`h3`);n.id=`tcw-ss-title-${this.uid}`,n.textContent=this.t(e.kind===`compare`?`compare.title`:`symbolSearch.title`);let r=document.createElement(`button`);return r.type=`button`,r.className=`tcw-modal-close`,r.setAttribute(`aria-label`,this.t(`common.close`)),r.innerHTML=O(`x`,16),r.addEventListener(`click`,()=>this.close()),t.append(n,r),t}buildSearch(){let e=document.createElement(`label`);e.className=`tcw-ss-search`,e.innerHTML=O(`search`,16);let t=document.createElement(`input`);return t.type=`search`,t.className=`tcw-ss-input`,t.placeholder=this.t(`symbolSearch.placeholder`),t.setAttribute(`aria-label`,this.t(`symbolSearch.placeholder`)),t.setAttribute(`role`,`combobox`),t.setAttribute(`aria-expanded`,`true`),t.setAttribute(`aria-controls`,`tcw-ss-list-${this.uid}`),t.setAttribute(`aria-autocomplete`,`list`),t.autocomplete=`off`,t.spellcheck=!1,t.addEventListener(`input`,()=>this.filter()),e.appendChild(t),this.input=t,e}buildWay(e){let t=document.createElement(`label`);t.className=`tcw-ss-way`;let n=document.createElement(`span`);n.textContent=this.t(`compare.addAs`);let r=document.createElement(`select`);r.className=`tcw-settings-select tcw-ss-way-select`;for(let t of e.ways){let e=document.createElement(`option`);e.value=t.id,e.textContent=t.label,r.appendChild(e)}return r.value=this.way,r.addEventListener(`change`,()=>{this.way=r.value}),t.append(n,r),t}listGiven(){this.rows=this.given.map(e=>({symbol:e,score:0,info:this.infoOf(e)})),this.rowsGiven=!0,this.afterResults(!0)}filter(){this.pickOnResults=!1;let e=this.input?.value.trim()??``;if(this.searchFn&&e){this.scheduleSearch(e);return}if(this.cancelSearch(),this.status=`idle`,!e){this.listGiven();return}let t=Ar(e);this.rows=this.given.map(e=>{let n=this.infoOf(e);return{symbol:e,score:jr(e,this.foldedName(n?.description),t),info:n}}).filter(e=>e.score>0).sort((e,t)=>t.score-e.score),this.rowsGiven=!0,this.afterResults(!1)}foldedName(e){if(!e)return``;let t=this.foldedNames.get(e);return t===void 0&&(t=Pr(e),this.foldedNames.set(e,t)),t}scheduleSearch(e){this.searchTimer!==null&&clearTimeout(this.searchTimer),this.searchTimer=setTimeout(()=>{this.searchTimer=null,this.runSearch(e)},150)}searchNow(){this.searchTimer!==null&&clearTimeout(this.searchTimer),this.searchTimer=null,this.runSearch(this.input?.value.trim()??``)}async runSearch(e){let t=this.searchFn;if(!t)return;this.searchAbort?.abort();let n=new AbortController;this.searchAbort=n,this.status=`searching`,this.shown.length===0&&this.renderList();try{let r=await t(e,n.signal);if(n.signal.aborted)return;let i=Xt(r);for(let e of i)this.heard.set(e.symbol,Zt(this.heard.get(e.symbol),e));this.rows=i.map(e=>({symbol:e.symbol,score:0,info:this.infoOf(e.symbol)})),this.status=`idle`}catch{if(n.signal.aborted)return;this.rows=[],this.status=`failed`}this.rowsGiven=!1,this.afterResults(!1),this.pickOnResults&&(this.pickOnResults=!1,this.pick(0))}cancelSearch(){this.searchTimer!==null&&clearTimeout(this.searchTimer),this.searchTimer=null,this.searchAbort?.abort(),this.searchAbort=null}afterResults(e){let t=this.listableRows();this.filters?.see(t.map(e=>e.info)),this.shown=this.visibleRows(t);let n=e?this.shown.findIndex(e=>e.symbol===this.mode?.start.current):-1;this.selectedIndex=n>=0&&n<this.listedCount()?n:0,this.renderList()}listedCount(){return Math.min(this.shown.length,200)}listableRows(){if(this.mode?.kind!==`compare`)return this.rows;let e=this.mode.start.current;return this.rows.filter(t=>t.symbol!==e)}visibleRows(e){let t=this.filters;return t?e.filter(e=>t.passes(e.info,this.rowsGiven)):[...e]}renderList(){let e=this.list,t=this.results;if(!e||!t)return;let n=(this.input?.value??``).trim(),r=this.mode?.kind===`compare`,i=[];if(r&&!n&&this.compared.length>0){let t=this.heading(this.t(`compare.onChart`),`added`),n=document.createElement(`div`);n.className=`tcw-ss-added`,n.setAttribute(`role`,`group`),n.setAttribute(`aria-labelledby`,t.id),n.append(...this.compared.map(e=>this.addedRow(e)));let r=this.heading(this.t(`compare.symbols`),`symbols`);r.hidden=this.shown.length===0,i.push(t,n,r),e.setAttribute(`aria-labelledby`,r.id)}else e.setAttribute(`aria-labelledby`,`tcw-ss-title-${this.uid}`);let a=n.toUpperCase(),o=new Set(this.compared.map(e=>e.symbol)),s=this.shown.slice(0,200);e.replaceChildren(...s.map((e,t)=>this.row(e,t,a,r&&o.has(e.symbol))));let c=this.shown.length===0?this.emptyNote(n,r):this.moreNote(this.shown.length-s.length);t.replaceChildren(...this.columns?[this.columns]:[],...i,e,...c?[c]:[]),this.live&&(this.live.textContent=this.shown.length===0?c?.textContent??``:``),this.markSelection()}emptyNote(e,t){let n;if(this.status===`searching`)n=this.t(`symbolSearch.searching`);else if(this.status===`failed`)n=this.t(`symbolSearch.failed`);else if(t&&!e){if(this.compared.length>0)return null;n=this.t(`compare.empty`)}else n=this.t(`symbolSearch.empty`);let r=document.createElement(`div`);return r.className=`tcw-ss-empty`,r.textContent=n,r}moreNote(e){if(e<=0)return null;let n=document.createElement(`div`);return n.className=`tcw-ss-more`,n.textContent=t.r(this.t(`symbolSearch.more`),{count:e}),n}heading(e,t){let n=document.createElement(`div`);return n.className=`tcw-ss-heading`,n.id=`tcw-ss-${t}-${this.uid}`,n.textContent=e,n}row(e,t,n,r){let i=document.createElement(`div`);i.className=`tcw-ss-row`,i.id=`tcw-ss-opt-${this.uid}-${t}`,i.dataset.symbol=e.symbol,i.setAttribute(`role`,`option`);let a=this.mode?.kind===`search`&&e.symbol===this.mode.start.current;i.classList.toggle(`tcw-current`,a),i.classList.toggle(`tcw-on-chart`,r),a&&i.setAttribute(`aria-current`,`true`);let o=this.tag(`tcw-ss-kind`,e.info?.type?.trim()??``),s=this.tag(`tcw-ss-exchange`,e.info?.exchange?.trim()??``);if(o.dir=s.dir=`auto`,i.append(wr(e.symbol,e.info),Lr(e.symbol,n),this.descriptionCell(e),o,s),a||r){let e=document.createElement(`span`);e.className=`tcw-ss-check`,e.innerHTML=O(`check`,14),i.appendChild(e)}return r&&i.appendChild(this.tag(`tcw-visually-hidden`,this.t(`compare.onChart`))),i.addEventListener(`click`,()=>this.pick(t)),i.addEventListener(`mousemove`,()=>{this.selectedIndex!==t&&(this.selectedIndex=t,this.markSelection())}),i}descriptionCell(e){let t=document.createElement(`span`);t.className=`tcw-ss-desc-cell`;let n=e.info?.description&&e.info.description!==e.symbol?e.info.description:``;if(n){let e=this.tag(`tcw-ss-desc`,n);e.dir=`auto`,t.appendChild(e)}return t}addedRow(e){let n=document.createElement(`div`);if(n.className=`tcw-ss-added-row`,n.setAttribute(`role`,`presentation`),e.color){let t=document.createElement(`span`);t.className=`tcw-ss-swatch`,t.style.background=e.color,n.appendChild(t)}let r=document.createElement(`span`);r.className=`tcw-ss-way-cell`,r.appendChild(this.tag(`tcw-ss-way-label`,e.way));let i=document.createElement(`button`);i.type=`button`,i.className=`tcw-ss-remove`;let a=t.r(this.t(`compare.remove`),{symbol:e.symbol});return i.title=a,i.setAttribute(`aria-label`,a),i.innerHTML=O(`x`,12),i.addEventListener(`click`,()=>{this.mode?.kind===`compare`&&this.mode.start.onRemove(e.id)}),n.append(Lr(e.symbol,``),r,i),n}tag(e,t){let n=document.createElement(`span`);return n.className=e,n.textContent=t,n}markSelection(){let e=this.list?.querySelectorAll(`.tcw-ss-row`)??[],t=null;e.forEach((e,n)=>{let r=n===this.selectedIndex;e.setAttribute(`aria-selected`,String(r)),e.classList.toggle(`tcw-selected`,r),r&&(t=e)});let n=t;n?(this.input?.setAttribute(`aria-activedescendant`,n.id),n.scrollIntoView?.({block:`nearest`})):this.input?.removeAttribute(`aria-activedescendant`)}pick(e){let t=this.shown[e],n=this.mode;if(!t||!n)return;if(n.kind===`compare`){this.selectedIndex=e,this.markSelection(),n.start.onAdd(t.symbol,this.way);return}let r=n.start.onPick??this.callbacks.onPick;this.close(),r(t.symbol)}onKeyDown(e,t){if(e.stopPropagation(),e.isComposing||e.keyCode===Wr)return;if(e.key===`Escape`){e.preventDefault(),this.close();return}if(M(e,t),e.target!==this.input)return;let n=this.listedCount();if(e.key===`ArrowDown`||e.key===`ArrowUp`){if(e.preventDefault(),n===0)return;this.selectedIndex=(this.selectedIndex+(e.key===`ArrowDown`?1:-1)+n)%n,this.markSelection()}else if(e.key===`Enter`){if(e.preventDefault(),e.repeat&&this.mode?.kind===`compare`)return;if(this.searchTimer!==null||this.status===`searching`){this.pickOnResults=!0,this.searchTimer!==null&&this.searchNow();return}this.pick(this.selectedIndex)}}},qr=229,Jr={"Search & navigation":`hotkeys.group.searchNavigation`,"Chart manipulation":`hotkeys.group.chartManipulation`,"Touch (mobile / tablet)":`hotkeys.group.touch`,Keyboard:`hotkeys.group.keyboard`,"Bar replay":`toolbar.replay`,Drawing:`hotkeys.group.drawing`,More:`hotkeys.group.more`},V=rr,Yr=[{title:`Search & navigation`,entries:[{keys:[V,`K`],label:`hotkeys.commandPalette`,feature:`hotkeys.commandPalette`},{keys:[V,`P`],label:`hotkeys.symbolSearch`,feature:`hotkeys.symbolSearch`},{keys:[`Alt`,`G`],label:`hotkeys.goToDate`,feature:`hotkeys.goToDate`},{keys:[`Alt`,`I`],label:`hotkeys.invertScale`,feature:`hotkeys.invertScale`},{keys:[`Alt`,`R`],label:`chartMenu.resetView`,feature:`hotkeys.resetView`},{keys:[V,`S`],label:`hotkeys.saveLayout`,feature:`hotkeys.save`},{keys:[`0–9`],label:`hotkeys.typeInterval`,feature:`intervalTyping`},{keys:[`A–Z`],label:`hotkeys.typeSymbol`,feature:`symbolTyping`},{keys:[`?`],label:`hotkeys.showSheet`,feature:`hotkeys.help`}]},{title:`Chart manipulation`,entries:[{keys:[`key.drag`],label:`hotkeys.pan`},{keys:[V,`key.drag`],label:`hotkeys.boxSelect`},{keys:[V,`key.click`],label:`hotkeys.toggleSelect`},{keys:[`Shift`,`key.drag`],label:`hotkeys.measure`},{keys:[`key.drag`,`key.priceAxis`],label:`hotkeys.scalePrice`},{keys:[`key.drag`,`key.timeAxis`],label:`hotkeys.zoomTime`},{keys:[`key.doubleClick`,`key.priceAxis`],label:`hotkeys.autoScale`},{keys:[`key.doubleClick`,`key.timeAxis`],label:`hotkeys.fit`},{keys:[`key.scroll`],label:`hotkeys.zoomCursor`}]},{title:`Touch (mobile / tablet)`,entries:[{keys:[`key.oneFinger`,`key.drag`],label:`hotkeys.touchPan`},{keys:[`key.twoFingers`,`key.pinch`],label:`hotkeys.pinch`},{keys:[`key.longPress`],label:`hotkeys.longPress`},{keys:[`key.drag`,`key.axisStrip`],label:`hotkeys.touchAxis`}]},{title:`Keyboard`,entries:[{keys:[`←`,`→`],label:`hotkeys.panBar`},{keys:[`+`,`−`],label:`hotkeys.zoomInOut`},{keys:[`Home`],label:`hotkeys.toStart`},{keys:[`End`],label:`hotkeys.toEnd`},{keys:[`Space`],label:`hotkeys.fit`}]},{title:`Bar replay`,entries:[{keys:[`Shift`,`←`,`→`],label:`hotkeys.replayStep`,feature:`replay`},{keys:[`Space`],label:`hotkeys.replayPlay`,feature:`replay`},{keys:[`Esc`],label:`hotkeys.replayCancel`,feature:`replay`}]},{title:`Drawing`,entries:[{keys:[V,`Z`],label:`hotkeys.undo`},{keys:[V,`Shift`,`Z`],label:`hotkeys.redo`},{keys:[`Esc`],label:`hotkeys.cancelDrawing`},{keys:[V,`C`],label:`hotkeys.copy`},{keys:[V,`V`],label:`hotkeys.paste`},{keys:[`key.rightClick`],label:`hotkeys.drawingMenu`},{keys:[`key.doubleClick`],label:`hotkeys.drawingSettings`},{keys:[V,`G`],label:`hotkeys.group`},{keys:[V,`Shift`,`G`],label:`hotkeys.ungroup`},{keys:[V,`]`,`[`],label:`hotkeys.orderStep`},{keys:[V,`Shift`,`]`,`[`],label:`hotkeys.orderEnd`},{keys:[`Enter`],label:`hotkeys.finishPath`},{keys:[`Alt`,`T`],label:`tool.trendLine`,feature:`hotkeys.tools`},{keys:[`Alt`,`H`],label:`tool.horizontalLine`,feature:`hotkeys.tools`},{keys:[`Alt`,`J`],label:`tool.horizontalRay`,feature:`hotkeys.tools`},{keys:[`Alt`,`V`],label:`tool.verticalLine`,feature:`hotkeys.tools`},{keys:[`Alt`,`C`],label:`tool.crossLine`,feature:`hotkeys.tools`},{keys:[`Alt`,`F`],label:`tool.fibRetracement`,feature:`hotkeys.tools`}]}],Xr=0,Zr=class{backdrop=null;bodyEl=null;searchEl=null;liveEl=null;groups=[];returnFocus=null;uid=++Xr;constructor(e,t,n=()=>document.body){this.callbacks=e,this.t=t,this.host=n}open(e={}){if(this.backdrop)return;this.returnFocus=document.activeElement instanceof HTMLElement?document.activeElement:null;let t=e.isOn??(()=>!0),n=new Set((e.extra??[]).map(e=>e.keys.join(`+`).toLowerCase()));this.groups=Yr.map(e=>({title:e.title,entries:e.entries.filter(e=>(!e.feature||t(e.feature))&&!n.has(e.keys.join(`+`).toLowerCase()))})).filter(e=>e.entries.length>0),e.extra&&e.extra.length>0&&this.groups.push({title:`More`,entries:[...e.extra]}),this.build(t(`hotkeys.help`)),this.render(),this.searchEl?.focus()}close(){if(!this.backdrop)return;this.backdrop.remove(),this.backdrop=this.bodyEl=this.searchEl=this.liveEl=null,this.callbacks.onClose();let e=this.returnFocus;this.returnFocus=null,e?.isConnected&&e.focus()}isOpen(){return this.backdrop!==null}destroy(){this.close()}build(e){let t=document.createElement(`div`);t.className=`tcw-modal-backdrop`;let n=!1;t.addEventListener(`pointerdown`,e=>{n=e.target===t}),t.addEventListener(`click`,e=>{e.target===t&&n&&this.close(),n=!1});let r=document.createElement(`div`);r.className=`tcw-modal tcw-hotkey-sheet`,r.setAttribute(`role`,`dialog`),r.setAttribute(`aria-modal`,`true`),r.setAttribute(`aria-labelledby`,`tcw-hotkey-title-${this.uid}`),r.tabIndex=-1,r.addEventListener(`keydown`,e=>{if(e.stopPropagation(),e.key===`Escape`&&!e.isComposing&&e.keyCode!==qr){e.preventDefault(),this.close();return}M(e,r)});let i=document.createElement(`div`);i.className=`tcw-modal-header`;let a=document.createElement(`h3`);a.id=`tcw-hotkey-title-${this.uid}`,a.textContent=this.t(`hotkeys.title`);let o=document.createElement(`button`);o.type=`button`,o.className=`tcw-modal-close`,o.setAttribute(`aria-label`,this.t(`hotkeys.close`)),o.innerHTML=O(`x`,16),o.addEventListener(`click`,()=>this.close()),i.append(a,o);let s=document.createElement(`label`);s.className=`tcw-ss-search tcw-hotkey-search`,s.innerHTML=O(`search`,16);let c=document.createElement(`input`);c.type=`search`,c.placeholder=this.t(`hotkeys.search`),c.setAttribute(`aria-label`,this.t(`hotkeys.search`)),c.autocomplete=`off`,c.spellcheck=!1,c.addEventListener(`input`,()=>this.render()),s.appendChild(c);let l=document.createElement(`div`);l.className=`tcw-hotkey-body`;let u=document.createElement(`div`);if(u.className=`tcw-hotkey-live tcw-visually-hidden`,u.setAttribute(`aria-live`,`polite`),r.append(i,s,l,u),e){let e=document.createElement(`div`);e.className=`tcw-hotkey-foot`,e.textContent=this.t(`hotkeys.footer`),r.appendChild(e)}t.appendChild(r),this.host().appendChild(t),this.backdrop=t,this.bodyEl=l,this.searchEl=c,this.liveEl=u}render(){let e=this.bodyEl;if(!e)return;let t=ir((this.searchEl?.value??``).trim()),n=[];for(let e of this.groups){let r=t?e.entries.filter(e=>this.matches(e,t)):e.entries;if(r.length===0)continue;let i=document.createElement(`section`);i.className=`tcw-hotkey-group`;let a=document.createElement(`div`);a.className=`tcw-hotkey-heading`;let o=Jr[e.title];a.textContent=o?this.t(o):e.title,i.append(a,...r.map(e=>this.row(e))),n.push(i)}if(this.liveEl&&(this.liveEl.textContent=n.length===0?this.t(`hotkeys.noMatch`):``),n.length===0){let t=document.createElement(`div`);t.className=`tcw-hotkey-empty`,t.textContent=this.t(`hotkeys.noMatch`),e.replaceChildren(t);return}let r=document.createElement(`div`);r.className=`tcw-hotkey-columns`,r.append(...n),e.replaceChildren(r)}label(e){return`text`in e?e.text:this.t(e.label)}keyText(e){return e.startsWith(`key.`)?this.t(e):e}matches(e,t){return ir(this.label(e)).includes(t)?!0:ir(e.keys.map(e=>this.keyText(e)).join(`+`)).includes(t)}row(e){let t=document.createElement(`div`);t.className=`tcw-hotkey-row`;let n=document.createElement(`span`);n.className=`tcw-hotkey-label`,n.textContent=this.label(e);let r=document.createElement(`span`);return r.className=`tcw-hotkey-keys`,r.dir=`ltr`,e.keys.forEach((e,t)=>{if(t>0){let e=document.createElement(`span`);e.className=`tcw-hotkey-sep`,e.textContent=`+`,r.appendChild(e)}let n=e.startsWith(`key.`),i=document.createElement(n?`span`:`kbd`);i.className=n?`tcw-hotkey-gesture`:`tcw-hotkey-key`,i.textContent=this.keyText(e),r.appendChild(i)}),t.append(n,r),t}},Qr={selectHint:`Click a bar to start the replay`,random:`Random bar`,realtime:`Back to realtime`,play:`Play`,pause:`Pause`,stepBack:`Step back (Shift+←)`,stepForward:`Step forward (Shift+→)`,replay:`Replay`,position:`Replay position`,speed:`Speed`,step:`Step`,loading:`Loading chart...`,selectBar:`Select bar`,cancel:`Cancel`,rate:`{rate}×`,rateHint:`1× plays one bar a second`,playingAt:`Playing at {rate}`,pausedAt:`Paused at {time}`,endedAt:`Replay ended at {time}`},$r=[.1,.2,.3,.5,1,2,3,5,10,20,30,50],ei=[`full`,`compact`,`stack`],ti=300,ni=2,ri=[`random`,`stepBack`,`stepForward`,`seek`,`step`,`selectBar`],ii=class{root=null;scrubber=null;timeLabel=null;playBtn=null;realtimeBtn=null;liveRegion=null;hintText=null;state=`stopped`;mode=`select`;ended=!1;pending=!1;total=0;rate=1;steps=[];step=`bar`;dir=`ltr`;formatRate;where=``;announceTimer=null;widths=new Map;labels;constructor(e,t={}){this.callbacks=e,this.labels={...Qr,...t},this.formatRate=e=>this.labels.rate.replace(`{rate}`,String(e))}mount(e,t){this.root||(this.total=Math.max(0,t.total),this.rate=t.rate??1,this.steps=t.steps??[],this.step=t.step??`bar`,this.dir=t.dir??`ltr`,t.formatRate&&(this.formatRate=t.formatRate),this.state=`paused`,this.mode=t.mode??`select`,this.root=document.createElement(`div`),this.root.className=`tcw-replay-bar`,D(this.root,`replay`),this.root.setAttribute(`role`,`group`),this.root.setAttribute(`aria-label`,this.labels.replay),this.root.dataset.fit=`full`,this.root.innerHTML=this.markup(),e.appendChild(this.root),this.wireEvents(),this.syncUi())}unmount(){this.announceTimer&&clearTimeout(this.announceTimer),this.announceTimer=null,this.root?.remove(),this.root=null,this.hintText=null,this.scrubber=null,this.timeLabel=null,this.playBtn=null,this.realtimeBtn=null,this.liveRegion=null,this.state=`stopped`,this.ended=!1,this.where=``}isMounted(){return this.root!==null}element(){return this.root}getMode(){return this.mode}setMode(e){let t=!!this.root?.contains(document.activeElement);this.mode=e,this.syncUi(),t&&(e===`replay`?(this.playBtn&&!this.playBtn.disabled?this.playBtn:this.realtimeBtn)?.focus():this.root?.querySelector(`[data-act="random"]`)?.focus())}setState(e){e!==this.state&&(this.state=e,this.syncUi(),this.mode===`replay`&&(e===`playing`?this.announce(this.labels.playingAt.replace(`{rate}`,this.formatRate(this.rate))):e===`paused`&&this.where&&this.announce(this.labels.pausedAt.replace(`{time}`,this.where))))}setEnded(e){this.ended!==e&&(this.ended=e,this.syncUi(),e&&this.where&&this.announce(this.labels.endedAt.replace(`{time}`,this.where)))}setPending(e){if(this.pending===e)return;this.pending=e;let t=document.activeElement;e&&t&&t!==this.playBtn&&this.root?.contains(t)&&ri.includes(t.dataset.act??``)&&this.playBtn?.focus(),this.syncUi(),e&&this.mode===`replay`&&this.announce(this.labels.loading)}isPending(){return this.pending}setSteps(e,t){this.steps=e,this.step=t,this.widths.clear();let n=this.root?.querySelector(`[data-tcw="stepSlot"]`);n&&(n.innerHTML=this.stepMarkup(),this.wireStep(),this.syncUi())}setProgress(e,t,n){this.total=t;let r=n??`${Math.min(e+1,t)} / ${t}`,i=r!==this.where;if(this.where=r,this.scrubber){this.scrubber.max=String(Math.max(0,t-1)),this.scrubber.value=String(e),this.scrubber.setAttribute(`aria-valuetext`,r);let n=t>1?Math.min(e,t-1)/(t-1)*100:0;this.scrubber.style.setProperty(`--tcw-replay-done`,`${Number(n.toFixed(ni))}%`)}if(this.timeLabel){this.timeLabel.textContent=r;let e=Number.parseFloat(this.timeLabel.style.minInlineSize)||0;r.length>e&&(this.timeLabel.style.minInlineSize=`${r.length}ch`)}let a=this.scrubber!==null&&document.activeElement===this.scrubber;i&&this.mode===`replay`&&this.state!==`playing`&&!a&&this.announce(r)}setRoom(e){let t=this.root;if(t){for(let n of ei)if(n===`stack`||this.widthIn(n)<=e){t.dataset.fit=n,this.orderFor(n);return}}}orderFor(e){let t=this.root,n=t?.querySelector(`.tcw-replay-timeline`),r=t?.querySelector(`.tcw-replay-transport`),i=this.realtimeBtn;if(!t||!n||!r||!i)return;let a=e===`stack`;if(a===(n.nextElementSibling===i))return;let o=document.activeElement;a?r.before(n,i):(r.nextElementSibling?.after(n),t.querySelector(`[data-act="cancel"]`)?.before(i)),o&&t.contains(o)&&document.activeElement!==o&&o.focus()}getFit(){return this.root?.dataset.fit??`full`}destroy(){this.unmount()}widthIn(e){let t=this.root,n=`${this.mode}|${this.steps.length}|${e}`,r=this.widths.get(n);if(r!==void 0)return r;let i=t.dataset.fit;t.dataset.fit=e,t.dataset.measure=``;let a=t.getBoundingClientRect().width;return delete t.dataset.measure,i&&(t.dataset.fit=i),a>0&&this.widths.set(n,a),a}markup(){let e=this.labels,t=`dir="${this.dir}"`,n=$r.map(e=>`<option value="${e}"${e===this.rate?` selected`:``}>${k(this.formatRate(e))}</option>`).join(``),r=(e,t,n,r=`tcw-replay-btn`,i=``)=>`<button type="button" class="${r}" data-act="${e}" title="${k(t)}" aria-label="${k(t)}"${i}>${n}</button>`;return`
7661
+ ${Ge()}`,document.head.insertBefore(e,document.head.firstChild)}function $e(){if(Xe--,Xe>0)return;let e=document.getElementById(Ze);e&&e.remove()}var et=(e,t)=>Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0;function O(e,t=14){let r=et(n.UI_ICONS,e);return r?(0,n.iconSvg)(r,t):``}function tt(e,t=16){return(0,n.iconSvg)(et(n.DRAWING_TOOL_ICONS,e)??n.UI_ICONS.penLine,t)}function nt(e,t=14){return(0,n.iconSvg)(et(n.CHART_TYPE_ICONS,e)??n.UI_ICONS.barChart,t)}function k(e){return e.replace(/[&<>"']/g,e=>({"&":`&amp;`,"<":`&lt;`,">":`&gt;`,'"':`&quot;`,"'":`&#39;`})[e])}var rt=class{trigger;panel;_isOpen=!1;onOutsideClick;onEscapeKey;onTriggerClick;layer;align;onAway=()=>this.close();onScroll=e=>{e.target instanceof Node&&this.panel.contains(e.target)||this.close()};constructor(e,t={}){this.trigger=e,this.layer=t.layer??null,this.align=t.align??`left`,this.panel=document.createElement(`div`),this.panel.className=`tcw-dropdown`,this.panel.style.minWidth=t.width??`200px`,this.panel.style.display=`none`,this.layer?(this.layer().appendChild(this.panel),this.panel.addEventListener(`click`,()=>this.close())):(this.align===`right`?this.panel.style.insetInlineEnd=`0px`:this.panel.style.insetInlineStart=`0px`,e.style.position=`relative`,e.appendChild(this.panel)),this.onTriggerClick=()=>{this._isOpen?this.close():this.open()},this.onOutsideClick=e=>{let t=e.target;!this.trigger.contains(t)&&!this.panel.contains(t)&&this.close()},this.onEscapeKey=e=>{e.key===`Escape`&&this.close()},e.addEventListener(`click`,this.onTriggerClick)}setContent(e){this.panel.innerHTML=e}open(){if(!this._isOpen){if(this._isOpen=!0,this.layer){let e=this.layer();this.panel.parentElement!==e&&e.appendChild(this.panel)}this.panel.style.display=``,this.layer&&(this.place(),window.addEventListener(`resize`,this.onAway),document.addEventListener(`scroll`,this.onScroll,{capture:!0,passive:!0})),document.addEventListener(`pointerdown`,this.onOutsideClick),document.addEventListener(`keydown`,this.onEscapeKey)}}close(){this._isOpen&&(this._isOpen=!1,this.panel.style.display=`none`,document.removeEventListener(`pointerdown`,this.onOutsideClick),document.removeEventListener(`keydown`,this.onEscapeKey),window.removeEventListener(`resize`,this.onAway),document.removeEventListener(`scroll`,this.onScroll,{capture:!0}))}isOpen(){return this._isOpen}destroy(){this.close(),this.trigger.removeEventListener(`click`,this.onTriggerClick),this.panel.remove()}place(){ee(this.panel,this.trigger,this.align)}},it=4,at=2,ot=150,st=`[role=menuitem], [role=menuitemcheckbox], [role=menuitemradio]`,ct=`(max-width: 640px)`,lt=`tcw:back`,ut=new Set;function dt(e,t,n,r=e,i=!1){let a=i?r-t>=0?r-t:e:e+t>n?r-t:e;return Math.max(0,Math.min(a,n-t))}function ft(e){return e.radio?`menuitemradio`:e.checked===void 0?`menuitem`:`menuitemcheckbox`}function pt(e){let t=`<span class="tcw-context-icon"></span>`;return e.radio?e.checked?`<span class="tcw-context-icon tcw-context-dot"></span>`:t:e.checked?O(`check`,14):e.icon&&O(e.icon,14)||t}var A=class e{el;onPick=null;onRemove=null;returnFocus=null;anchor=null;child=null;parent=null;hoverTimer=null;hoverItem=null;onDocPointer=e=>{let t=e.target;this.holds(t)||this.anchor?.contains(t)||this.close()};onWheel=e=>{this.holds(e.target)||this.close()};onAway=()=>this.close();constructor(e,t,n=``){this.host=e,this.backLabel=n,this.el=document.createElement(`div`),this.el.className=`tcw-context-menu`,this.el.setAttribute(`role`,`menu`),this.el.setAttribute(`aria-label`,t),this.el.hidden=!0,this.el.addEventListener(`keydown`,e=>this.onKeyDown(e)),e.appendChild(this.el)}open(e,t,n,r,i,a,o=t,s=!1){this.show(e,{x:t,y:n,xBack:o,yBack:n,before:s},r,i,a,!0)}openUnder(e,t,n,r=`start`,i=at){let a=t.getBoundingClientRect(),o=this.host.getBoundingClientRect(),s=r===`end`!==this.rtl();this.open(e,a.left-o.left,a.bottom-o.top+i,n,t,void 0,a.right-o.left,s)}openBeside(e,t,n){let r=t.getBoundingClientRect(),i=this.host.getBoundingClientRect(),a=r.right-i.left+at,o=r.left-i.left-at;this.show(e,{x:a,y:r.top-i.top,xBack:o,yBack:r.bottom-i.top,before:this.rtl()},n,t,void 0,!0),this.returnFocus=t}static closeAnchoredTo(e){let t=[...ut].filter(t=>t.anchor===e);for(let e of t)e.close();return t.length>0}static focusedAnchor(){return[...ut].find(e=>e.anchor!==null&&e.hasFocus())?.anchor??null}close(){if(this.clearHover(),this.child?.close(),this.el.hidden)return;ut.delete(this);let e=!this.parent||this.el.contains(document.activeElement);this.el.hidden=!0,this.onPick=null,this.onRemove=null,this.anchor?.setAttribute(`aria-expanded`,`false`),this.anchor=null,document.removeEventListener(`pointerdown`,this.onDocPointer,!0),document.removeEventListener(`wheel`,this.onWheel,{capture:!0}),window.removeEventListener(`resize`,this.onAway),window.removeEventListener(`blur`,this.onAway),e&&this.returnFocus?.isConnected&&this.returnFocus.focus({preventScroll:!0}),this.returnFocus=null}isOpen(){return!this.el.hidden}hasFocus(){return document.activeElement!==null&&this.holds(document.activeElement)}destroy(){this.close(),this.child?.destroy(),this.el.remove()}show(e,t,n,r,i,a){this.clearHover(),this.child?.close(),this.returnFocus=document.activeElement instanceof HTMLElement?document.activeElement:null,this.onPick=n,this.onRemove=i??null,this.anchor=r??null,this.anchor?.setAttribute(`aria-expanded`,`true`),this.el.replaceChildren(...e.map(e=>this.entry(e))),this.el.hidden=!1,ut.add(this);let o=this.host.getBoundingClientRect(),s=Math.min(this.host.clientWidth,window.innerWidth-o.left)-it,c=Math.min(this.host.clientHeight,window.innerHeight-o.top)-it;this.el.style.maxHeight=`${Math.max(0,c-this.frameHeight())}px`,this.el.style.left=`${dt(t.x,this.el.offsetWidth,s,t.xBack,t.before)}px`,this.el.style.top=`${dt(t.y,this.el.offsetHeight,c,t.yBack)}px`,document.addEventListener(`pointerdown`,this.onDocPointer,!0),document.addEventListener(`wheel`,this.onWheel,{capture:!0,passive:!0}),window.addEventListener(`resize`,this.onAway),window.addEventListener(`blur`,this.onAway);let l=this.revealChoice();a&&(l??this.items()[0])?.focus({preventScroll:!0})}frameHeight(){let e=getComputedStyle(this.el);if(e.boxSizing===`border-box`)return 0;let t=e=>parseFloat(e)||0;return t(e.paddingTop)+t(e.paddingBottom)+t(e.borderTopWidth)+t(e.borderBottomWidth)}revealChoice(){let e=this.el.querySelector(`[role=menuitemradio][aria-checked=true]`);return!e||e.offsetTop+e.offsetHeight<=this.el.clientHeight?null:(this.el.scrollTop=e.offsetTop-(this.el.clientHeight-e.offsetHeight)/2,e)}rtl(){return this.host.closest(`[dir]`)?.getAttribute(`dir`)===`rtl`}holds(e){return this.el.contains(e)||(this.child?.holds(e)??!1)}entry(e){if(e===`separator`){let e=document.createElement(`div`);return e.className=`tcw-context-sep`,e.setAttribute(`role`,`separator`),e}let t=document.createElement(`button`);t.type=`button`,t.className=`tcw-context-item${e.danger?` tcw-context-danger`:``}`,t.setAttribute(`role`,ft(e)),(e.radio||e.checked!==void 0)&&t.setAttribute(`aria-checked`,String(e.checked??!1)),t.tabIndex=-1,t.dataset.id=e.id,t.innerHTML=pt(e);let n=document.createElement(`span`);n.className=`tcw-context-label`,n.textContent=e.label,t.appendChild(n),this.appendEnd(t,e);let r=e.submenu;return t.addEventListener(`pointermove`,n=>{n.pointerType!==`touch`&&this.hover(t,e.label,r)}),t.addEventListener(`click`,()=>{r?this.openSubmenu(t,e.label,r,!0):this.pick(e.id)}),e.remove?this.removableRow(t,e.remove):t}appendEnd(e,t){if(t.count!==void 0){let n=document.createElement(`span`);n.className=`tcw-context-count`,n.textContent=String(t.count),e.appendChild(n)}if(t.shortcut){e.setAttribute(`aria-keyshortcuts`,t.shortcut);let n=document.createElement(`kbd`);n.className=`tcw-context-key`,n.setAttribute(`aria-hidden`,`true`),n.textContent=t.shortcut,e.appendChild(n)}t.submenu&&(e.setAttribute(`aria-haspopup`,`menu`),e.setAttribute(`aria-expanded`,`false`),e.insertAdjacentHTML(`beforeend`,O(`chevronRight`,12)),e.lastElementChild?.classList.add(`tcw-context-more`))}removableRow(e,t){e.setAttribute(`aria-keyshortcuts`,`Delete`);let n=document.createElement(`button`);n.type=`button`,n.className=`tcw-context-remove`,n.tabIndex=-1,n.setAttribute(`aria-hidden`,`true`),n.title=t,n.innerHTML=O(`x`,12),n.addEventListener(`click`,()=>this.remove(e));let r=document.createElement(`div`);return r.className=`tcw-context-row`,r.setAttribute(`role`,`none`),r.append(e,n),r}openSubmenu(e,t,n,r){this.clearHover();let i=this.child??this.makeChild();if(i.isOpen()&&i.anchor===e){r&&i.items()[0]?.focus({preventScroll:!0});return}i.close(),i.el.setAttribute(`aria-label`,t);let a=this.host.getBoundingClientRect(),o=e.getBoundingClientRect(),s={x:o.right-a.left,y:o.top-a.top,xBack:o.left-a.left,yBack:o.bottom-a.top,before:this.rtl()},c=window.matchMedia?.(ct).matches??!1,l=c?[{id:lt,label:t,icon:`chevronLeft`},`separator`,...n]:n;i.show(l,s,e=>{e!==lt&&this.pick(e)},e,e=>this.onRemove?.(e),r);let u=c?i.el.querySelector(`[data-id="${lt}"]`):null;u?.classList.add(`tcw-context-back`),u&&this.backLabel&&u.setAttribute(`aria-label`,`${this.backLabel}: ${t}`),i.returnFocus=e}makeChild(){let t=new e(this.host,``,this.backLabel);return t.parent=this,t.el.addEventListener(`pointerenter`,()=>this.clearHover()),this.child=t,t}hover(e,t,n){if(this.hoverTimer!==null&&this.hoverItem===e)return;this.clearHover();let r=this.child?.isOpen()?this.child.anchor:null;(n?r===e:r===null)||(this.hoverItem=e,this.hoverTimer=setTimeout(()=>{this.hoverTimer=null,this.hoverItem=null,n?this.openSubmenu(e,t,n,!1):this.child?.close()},ot))}clearHover(){this.hoverItem=null,this.hoverTimer!==null&&(clearTimeout(this.hoverTimer),this.hoverTimer=null)}remove(e){let t=e.dataset.id,n=e.closest(`.tcw-context-row`);if(!t||!n)return;let r=this.items().indexOf(e);this.onRemove?.(t),n.remove();let i=[...this.el.children].filter((e,t,n)=>e.classList.contains(`tcw-context-sep`)&&(t===0||t===n.length-1||n[t-1].classList.contains(`tcw-context-sep`)));for(let e of i)e.remove();let a=this.items();if(a.length===0){this.close();return}a[Math.min(r,a.length-1)].focus({preventScroll:!0})}pick(e){let t=this.onPick;this.close(),t?.(e)}items(){return[...this.el.querySelectorAll(st)]}onKeyDown(e){let t=this.items(),n=t.indexOf(document.activeElement),[r,i]=this.rtl()?[`ArrowLeft`,`ArrowRight`]:[`ArrowRight`,`ArrowLeft`],a=-1;if(e.key===`ArrowDown`)a=(n+1)%t.length;else if(e.key===`ArrowUp`)a=(n-1+t.length)%t.length;else if(e.key===`Home`)a=0;else if(e.key===`End`)a=t.length-1;else if(e.key===r&&t[n]?.hasAttribute(`aria-haspopup`)){e.preventDefault(),t[n].click();return}else if(e.key===i&&this.parent){e.preventDefault(),this.close();return}else if(e.key===`Delete`&&n>=0){e.preventDefault(),this.remove(t[n]);return}else if(e.key===`Escape`||e.key===`Tab`){e.preventDefault(),e.stopPropagation();let t=this;for(;e.key===`Tab`&&t.parent;)t=t.parent;t.close();return}else return;e.preventDefault(),this.child?.close(),t[a]?.focus({preventScroll:!0})}},mt=[`en-US`,`en-GB`,`en-IN`,`de-DE`,`fr-FR`,`es-ES`,`it-IT`,`pt-BR`,`ru-RU`,`tr-TR`,`vi-VN`,`id-ID`,`th-TH`,`zh-CN`,`zh-TW`,`ja-JP`,`ko-KR`],ht=65234;function gt(e){return(e&&!mt.includes(e)?[e,...mt]:mt).map(e=>{let t;try{t=new Intl.NumberFormat(e,{minimumFractionDigits:2,maximumFractionDigits:2}).format(ht)}catch{t=``}return{value:e,label:t?`${e} (${t})`:e}})}var _t={Lines:`toolGroup.lines`,"Horizontal/Vertical":`toolGroup.horizontalVertical`,Channels:`toolGroup.channels`,Fibonacci:`toolGroup.fibonacci`,Shapes:`toolGroup.shapes`,"Gann & Pitchforks":`toolGroup.gannPitchforks`,Patterns:`toolGroup.patterns`,Measure:`toolGroup.measure`,Annotation:`toolGroup.annotation`,Forecasting:`toolGroup.forecasting`,Brushes:`toolGroup.brushes`,Cycles:`toolGroup.cycles`,"Elliott Waves":`toolGroup.elliott`};function vt(e,t){let n=`chartType.${e.value}`,r=t(n);return r===n?e.label:r}function yt(e,t){return e.map(e=>({...e,label:_t[e.label]?t(_t[e.label]):e.label,tools:e.tools.map(e=>{let n=`tool.${e.value}`,r=t(n);return{...e,label:r===n?e.label:r}})}))}var bt=[`1m`,`3m`,`5m`,`15m`,`30m`,`1h`,`2h`,`4h`,`1d`,`1w`,`1M`],xt=[`1m`,`5m`,`15m`,`1h`,`4h`,`1d`],St=6;function Ct(e){let t=e.slice(-1);return t===`h`||t===`d`||t===`w`?e.slice(0,-1)+t.toUpperCase():e}var wt=e=>Number.isFinite((0,n.timeframeToMs)(e))||(0,n.tickBarCount)(e)!==null,Tt=(e,t)=>{let r=(0,n.tickBarCount)(e),i=(0,n.tickBarCount)(t);return r!==null||i!==null?r===null?1:i===null?-1:r-i:(0,n.timeframeToMs)(e)-(0,n.timeframeToMs)(t)};function Et(e,t){let n=t?.length?t:null,r=e?.length?e:n??bt;return[...new Set(r)].filter(e=>wt(e)&&(!n||n.includes(e))).sort(Tt)}function Dt(e,t,n=!1){if(t?.length)return e.filter(e=>t.includes(e));if(n)return[...e];let r=e.filter(e=>xt.includes(e));return r.length>0?r:e.slice(0,St)}var Ot=9999,kt={"":`m`,s:`s`,S:`s`,m:`m`,h:`h`,H:`h`,d:`d`,D:`d`,w:`w`,W:`w`,M:`M`},At={s:[`m`,60],m:[`h`,60],h:[`d`,24]};function jt(e){let t=/^(\d+)([a-zA-Z]?)$/.exec(e.trim());if(!t)return null;if(t[2]===`T`||t[2]===`t`){let e=`${Number(t[1])}T`;return Number(t[1])<=Ot&&(0,n.tickBarCount)(e)!==null?e:null}let r=Number(t[1]),i=kt[t[2]];if(!i||!Number.isSafeInteger(r)||r<1)return null;for(let e=At[i];e&&r%e[1]===0;e=At[i])r/=e[1],i=e[0];if(r>Ot)return null;let a=`${r}${i}`;return(0,n.isTimeFrame)(a)?a:null}function Mt(e,t,n){let r=n?.length?n:null,i=t.filter(e=>wt(e)&&(!r||r.includes(e)));return[...new Set([...e,...i])].sort(Tt)}var Nt=[`T`,`s`,`m`,`h`,`d`,`w`,`M`];function Pt(e){let t=e=>{let t=e.slice(-1);return Nt.includes(t)?t:`m`};return Nt.map(n=>({unit:n,timeframes:e.filter(e=>t(e.value)===n)})).filter(e=>e.timeframes.length>0)}var Ft=864e5,It=5/7;function Lt(e){let t=(0,n.timeframeToMs)(e.current),r=(0,n.timeframeToMs)(e.chosen);if(!Number.isFinite(t)||!Number.isFinite(r)||!(e.width>0)||!(e.spanMs>0))return e.current;let i=n=>{if(n===t)return e.barsInSpan;if(n<Ft)return e.barsInSpan*t/n;let r=e.spanMs/n;return n===Ft?r*(e.dayShare??It):r},a=[...new Set([...e.available,e.current])].filter(e=>{let t=(0,n.timeframeToMs)(e);return Number.isFinite(t)&&t>=r}).sort(Tt);for(let t of a)if(i((0,n.timeframeToMs)(t))*2<=e.width)return t;return a[a.length-1]??e.current}var Rt={ticket:`receipt`,long:`trendingUp`,short:`trendingDown`,ladder:`ladder`,account:`layers`},zt=[`ladder`,`account`];function Bt(e,t){let n=[];e.onOrderTicket&&n.push({id:`ticket`,label:t(`chartMenu.orderTicket`),parts:[`orderTicket`],run:e.onOrderTicket});let r=e.onBracket;return r&&(n.push({id:`long`,label:t(`toolbar.longBracket`),parts:[`bracketOrders`,`toolbar.bracketOrders`],run:()=>r(`buy`)}),n.push({id:`short`,label:t(`toolbar.shortBracket`),parts:[`bracketOrders`,`toolbar.bracketOrders`],run:()=>r(`sell`)})),e.onToggleLadder&&n.push({id:`ladder`,label:t(`toolbar.depthLadder`),parts:[`depthLadder`,`toolbar.depthLadder`],run:e.onToggleLadder}),e.onToggleAccount&&n.push({id:`account`,label:t(`toolbar.account`),parts:[`accountPanel`,`toolbar.accountPanel`],run:e.onToggleAccount}),n}var Vt=class e{button;menu=null;open=new Set;static create(t,n,r,i){let a=Bt(t,n);return a.length>0?new e(a,n,r,i):null}constructor(e,t,n,r){this.items=e,this.t=t,this.root=n;let i=document.createElement(`button`);i.type=`button`,i.className=`tcw-dropdown-trigger tcw-toolbar-overflow`,i.dataset.role=`trade`,i.dataset.icon=`trendingUp`,i.title=t(`toolbar.trade`),i.setAttribute(`aria-haspopup`,`menu`),i.setAttribute(`aria-expanded`,`false`),D(i,`toolbar.trade`),i.innerHTML=`${O(`trendingUp`,14)} <span class="tcw-trigger-label">${k(t(`toolbar.trade`))}</span> ${O(`chevronDown`,12)}`,i.addEventListener(`click`,()=>this.toggle(r(i))),this.button=i}tidy(){this.button.hidden=this.items.every(e=>this.isOff(e.parts))}setOpen(e,t){let n=zt.find(t=>t===e);n&&(t?this.open.add(n):this.open.delete(n))}destroy(){this.menu?.destroy(),this.button.remove()}isOff(e){let t=new Set((this.root().getAttribute(`data-tcw-off`)??``).split(/\s+/).filter(Boolean));return e.some(e=>t.has(e))}toggle(e){if(this.menu?.isOpen()){this.menu.close();return}let t=this.items.filter(e=>!this.isOff(e.parts));if(t.length===0)return;let n=t.filter(e=>!zt.includes(e.id)),r=t.filter(e=>zt.includes(e.id)),i=[...n.map(e=>({id:e.id,label:e.label,icon:Rt[e.id]})),...n.length>0&&r.length>0?[`separator`]:[],...r.map(e=>({id:e.id,label:e.label,checked:this.open.has(e.id)}))],a=this.root();this.menu??=new A(a,this.t(`toolbar.trade`)),this.menu.openUnder(i,e,e=>{t.find(t=>t.id===e)?.run()})}},Ht=2048,Ut=65536,Wt=/^data:image\/(png|jpeg|gif|webp|avif|svg\+xml)[;,]/i,Gt=new Set([`https:`,`http:`,`blob:`]),Kt=new Set([`description`,`exchange`,`type`,`logo`]);function qt(e){if(typeof e!=`string`)return null;let t=e.trim();return t&&t.length<=64?t:null}function Jt(e){let t=[],n=new Map;if(!Array.isArray(e))return{names:t,info:n};let r=new Set;for(let i of e){let e=typeof i==`object`&&!!i,a=qt(e?i.symbol:i);!a||r.has(a)||(r.add(a),t.push(a),e&&n.set(a,Yt(i,a)))}return{names:t,info:n}}function Yt(e,t){return{...Object.fromEntries(Object.entries(e).filter(([e,t])=>e!==`__proto__`&&(!Kt.has(e)||typeof t==`string`&&t.trim()!==``))),symbol:t}}function Xt(e){return Array.isArray(e)?e.filter(e=>typeof e==`object`&&!!e&&typeof e.symbol==`string`&&e.symbol!==``).map(e=>Yt(e,e.symbol)):[]}function Zt(e,t){if(!t)return e;if(!e)return t;let n=Object.entries(t).filter(([,e])=>e!=null);return Object.fromEntries([...Object.entries(e),...n])}function Qt(e){let t=e.lastIndexOf(`:`);return t<=0||t===e.length-1?{venue:``,ticker:e}:{venue:e.slice(0,t+1),ticker:e.slice(t+1)}}var $t=e=>Qt(e).ticker.toUpperCase();function en(e,t){return!t||typeof t.symbol!=`string`?null:t.symbol.toUpperCase()===e.toUpperCase()||t.symbol.includes(`:`)!==e.includes(`:`)&&$t(t.symbol)===$t(e)?t:null}function tn(e){return[e?.description,e?.exchange].filter(Boolean).join(` · `)||null}var nn=()=>typeof document>`u`?void 0:document.baseURI;function rn(e,t=nn()){if(typeof e!=`string`)return null;let n=e.trim();if(!n||n.length>Ut)return null;let r;try{r=new URL(n,t)}catch{return null}return r.protocol===`data:`?Wt.test(r.href)&&r.href.length<=Ut?r.href:null:Gt.has(r.protocol)&&r.href.length<=Ht?r.href:null}var an=0,j=`data-tcw-folded`,on=1/64,sn=[`venue`,`ticker`,`cut`],cn={T:`toolbar.timeframes.ticks`,s:`toolbar.timeframes.seconds`,m:`toolbar.timeframes.minutes`,h:`toolbar.timeframes.hours`,d:`toolbar.timeframes.days`,w:`toolbar.timeframes.weeks`,M:`toolbar.timeframes.months`};function ln(e,t){let n=e.querySelector(`.tcw-host-btn-text`)?.textContent??``;n===t?e.removeAttribute(`aria-label`):e.setAttribute(`aria-label`,n?`${t}: ${n}`:t)}var un=class{config;callbacks;t;el;chartTypeDropdown=null;tfGroup=null;tfDropdown=null;tfFavorites=[];uid=(an++).toString(36);tfRendered=``;themeBtn=null;fullscreenBtn=null;hostLeft=null;hostRight=null;moreMenu=null;tfCurrent=null;resizeObserver=null;hostObserver=null;moreBtn=null;fitFrame=0;destroyed=!1;undoBtn=null;redoBtn=null;trade=null;layoutShown=``;symbolShown=null;constructor(e,t,n,r,i){if(this.host=e,this.layer=i,this.config=t,this.callbacks=n,this.t=r,this.el=document.createElement(`div`),this.el.className=`tcw-toolbar`,D(this.el,`toolbar`),this.build(),e.appendChild(this.el),typeof ResizeObserver<`u`){this.resizeObserver=new ResizeObserver(()=>this.fit()),this.resizeObserver.observe(this.el),this.hostObserver=new ResizeObserver(()=>this.scheduleFit());for(let e of[this.hostLeft,this.hostRight])e&&this.hostObserver.observe(e)}document.fonts?.ready.then(()=>this.scheduleFit())}scheduleFit(){this.destroyed||this.fitFrame||typeof requestAnimationFrame>`u`||(this.fitFrame=requestAnimationFrame(()=>{this.fitFrame=0,this.destroyed||this.fit()}))}menuAnchor(e){return(e.hasAttribute(j)||this.el.closest(`[data-tcw-narrow]`)!==null)&&this.moreBtn?this.moreBtn:e}fit(){let e=this.toolbarFocus(),t=this.foldedState();this.refit(),this.foldedState()!==t&&this.closeStaleMenus(),e&&this.keepFocus(e)}refit(){let{el:e}=this,t=()=>this.fits(),n=[...e.querySelectorAll(`.tcw-toolbar-overflow`)];for(let e of n)e.removeAttribute(j);if(e.classList.remove(`tcw-toolbar--collapsed`,`tcw-toolbar--icons`),delete e.dataset.tcwSqueeze,!(e.clientWidth===0||t())){e.classList.add(`tcw-toolbar--collapsed`);for(let e=n.length-1;e>=0;e--)if(n[e].setAttribute(j,``),t())return;e.classList.add(`tcw-toolbar--icons`);for(let e of n)if(e.removeAttribute(j),!t()){e.setAttribute(j,``);break}for(let n of sn){if(t())return;e.dataset.tcwSqueeze=n}}}fits(){let{el:e}=this,t=e.getBoundingClientRect(),n=e.offsetWidth>0&&Math.abs(t.width-e.offsetWidth)>=1?t.width/e.offsetWidth:1,r=getComputedStyle(e),i=r.direction===`rtl`,a=e=>parseFloat(e)||0,o=t.width/n-(i?a(r.borderLeftWidth)+a(r.paddingLeft):a(r.borderRightWidth)+a(r.paddingRight)),s=0;for(let r of e.children){if(r.getClientRects().length===0)continue;let e=r.getBoundingClientRect();s=Math.max(s,(i?t.right-e.left:e.right-t.left)/n)}return Math.ceil(s-on)<=Math.floor(o+on)}foldedState(){let e=[...this.el.querySelectorAll(`.tcw-toolbar-overflow`)];return`${this.el.classList.contains(`tcw-toolbar--collapsed`)}:${e.map(e=>Number(e.hasAttribute(j))).join(``)}`}closeStaleMenus(){this.moreBtn&&A.closeAnchoredTo(this.moreBtn);for(let e of this.el.querySelectorAll(`[${j}], [${j}] button`))A.closeAnchoredTo(e)}toolbarFocus(){let e=A.focusedAnchor();if(e&&this.el.contains(e))return e;let t=document.activeElement;return t instanceof HTMLElement&&this.el.contains(t)?t:null}keepFocus(e){if(A.focusedAnchor())return;let t=e;this.shows(e)||(t=(this.moreBtn&&e!==this.moreBtn&&this.shows(this.moreBtn)?this.moreBtn:null)??this.overflowButtons().filter(e=>this.shows(e)).at(-1)),t&&document.activeElement!==t&&t.focus({preventScroll:!0})}overflowButtons(){return[...this.el.querySelectorAll(`button.tcw-toolbar-overflow, .tcw-toolbar-overflow button`)]}shows(e){if(e.closest(`[hidden]`)||e.closest(`[${j}]`)||this.isOff(e))return!1;let t=this.el.closest(`[data-tcw-narrow]`)!==null;return e===this.moreBtn?t||this.el.classList.contains(`tcw-toolbar--collapsed`):!(t&&e.closest(`.tcw-toolbar-overflow`))}isOff(e){let t=new Set((this.rootEl().getAttribute(`data-tcw-off`)??``).split(/\s+/).filter(Boolean));for(let n=e;n&&n!==this.el;n=n.parentElement)if((n.dataset.tcwPart??``).split(/\s+/).some(e=>t.has(e)))return!0;return!1}build(){let{config:e,callbacks:t,el:n}=this,r=document.createElement(`button`);if(r.className=`tcw-toolbar-symbol`,r.dataset.role=`symbol`,r.dir=`ltr`,D(r,`toolbar.symbol`),r.addEventListener(`click`,t.onSymbolClick),n.appendChild(r),t.onSymbolInfo){let e=this.iconBtn(`info`,this.t(`symbolInfo.title`),t.onSymbolInfo);e.classList.remove(`tcw-toolbar-overflow`),e.dataset.role=`symbolInfo`,D(e,`symbolInfo`,`toolbar.symbolInfo`),n.appendChild(e)}if(n.appendChild(this.sep()),this.tfFavorites=[...e.timeframeFavorites??e.timeframes.map(e=>e.value)],this.tfGroup=document.createElement(`div`),this.tfGroup.className=`tcw-toolbar-group tcw-tf-group`,D(this.tfGroup,`toolbar.timeframes`),n.appendChild(this.tfGroup),t.onToggleTimeframeFavorite&&e.timeframes.length>0){let e=document.createElement(`div`);e.style.position=`relative`,e.style.display=`inline-flex`,D(e,`toolbar.timeframeMenu`);let t=document.createElement(`button`);t.className=`tcw-btn tcw-tf-more`,t.dataset.role=`timeframes`,t.title=this.t(`toolbar.timeframes`),t.setAttribute(`aria-label`,this.t(`toolbar.timeframes`)),this.tfCurrent=document.createElement(`span`),this.tfCurrent.className=`tcw-tf-current`,t.appendChild(this.tfCurrent),t.insertAdjacentHTML(`beforeend`,O(`chevronDown`,12)),e.appendChild(t),n.appendChild(e),this.tfDropdown=new rt(e,{width:`150px`,layer:this.layer}),n.classList.add(`tcw-toolbar--tf-menu`),this.buildTimeframeMenu()}n.appendChild(this.sep());let i=document.createElement(`div`);i.style.position=`relative`,i.style.display=`inline-flex`,D(i,`toolbar.chartType`);let a=document.createElement(`button`);a.className=`tcw-dropdown-trigger`,a.dataset.role=`charttype`,i.appendChild(a),n.appendChild(i),this.chartTypeDropdown=new rt(i,{width:`160px`,layer:this.layer}),this.buildChartTypeMenu(),n.appendChild(this.sep());let o=document.createElement(`button`);if(o.type=`button`,o.className=`tcw-dropdown-trigger`,o.dataset.role=`indicators`,o.setAttribute(`aria-haspopup`,`dialog`),o.setAttribute(`aria-expanded`,`false`),D(o,`toolbar.indicators`),o.addEventListener(`click`,()=>t.onIndicators()),n.appendChild(o),t.onCompare){let e=document.createElement(`button`);e.type=`button`,e.className=`tcw-dropdown-trigger`,e.dataset.role=`compare`,D(e,`compare`,`toolbar.compare`);let r=this.t(`objects.compare`);e.setAttribute(`aria-label`,r),e.title=r,e.innerHTML=`${O(`plus`,14)} <span class="tcw-trigger-label">${k(r)}</span>`,e.addEventListener(`click`,t.onCompare),n.appendChild(e)}if(this.hostLeft=this.hostGroup(),n.appendChild(this.hostLeft),t.onUndo&&t.onRedo&&(n.appendChild(this.sep()),this.undoBtn=this.iconBtn(`undo`,this.t(`drawing.undo`),t.onUndo),this.undoBtn.dataset.role=`undo`,D(this.undoBtn,`toolbar.undo`,`sidebar.undo`),this.redoBtn=this.iconBtn(`redo`,this.t(`drawing.redo`),t.onRedo),this.redoBtn.dataset.role=`redo`,D(this.redoBtn,`toolbar.redo`,`sidebar.redo`),n.append(this.undoBtn,this.redoBtn),this.setHistory(!1,!1)),n.appendChild(this.spacer()),t.onLayouts){let e=t.onLayouts,r=document.createElement(`button`);r.type=`button`,r.className=`tcw-dropdown-trigger tcw-layouts-btn tcw-toolbar-overflow`,r.dataset.role=`layouts`,r.dataset.icon=`save`,D(r,`layouts`,`toolbar.layouts`),r.setAttribute(`aria-haspopup`,`menu`),r.addEventListener(`click`,()=>e(this.menuAnchor(r))),n.appendChild(r),this.setLayout(null,!1)}if(this.hostRight=this.hostGroup(),n.appendChild(this.hostRight),n.appendChild(this.sep()),t.onToggleReplay){let e=this.iconBtn(`play`,this.t(`toolbar.replay`),t.onToggleReplay);e.dataset.role=`replay`,D(e,`replay`,`toolbar.replay`),n.appendChild(e)}if(t.onToggleObjects){let e=this.iconBtn(`layers`,this.t(`toolbar.objects`),t.onToggleObjects);e.dataset.role=`objects`,e.setAttribute(`aria-pressed`,`false`),D(e,`objectTree`,`toolbar.objectTree`),n.appendChild(e)}if(t.onToggleAlerts){let e=this.iconBtn(`bell`,this.t(`toolbar.priceAlerts`),t.onToggleAlerts);e.dataset.role=`alerts`,e.setAttribute(`aria-pressed`,`false`),D(e,`alerts`,`toolbar.alerts`),n.appendChild(e)}this.trade=Vt.create(t,this.t,()=>this.rootEl(),e=>this.menuAnchor(e)),this.trade&&n.appendChild(this.trade.button),n.appendChild(this.sep());let s=this.iconBtn(`camera`,this.t(`toolbar.screenshot`),t.onScreenshot);D(s,`screenshot`,`toolbar.screenshot`),n.appendChild(s);let c=this.iconBtn(`settings`,this.t(`toolbar.settings`),t.onSettings);D(c,`settings`,`toolbar.settings`),n.appendChild(c),this.themeBtn=this.iconBtn(`moon`,this.t(`toolbar.toggleTheme`),t.onToggleTheme),this.themeBtn.dataset.role=`theme`,D(this.themeBtn,`themeToggle`,`toolbar.themeToggle`),n.appendChild(this.themeBtn),t.onToggleFullscreen&&(this.fullscreenBtn=this.iconBtn(`maximize`,this.t(`toolbar.fullscreen`),t.onToggleFullscreen),this.fullscreenBtn.dataset.role=`fullscreen`,D(this.fullscreenBtn,`fullscreen`,`toolbar.fullscreen`),this.fullscreenBtn.setAttribute(`aria-pressed`,`false`),n.appendChild(this.fullscreenBtn));let l=document.createElement(`button`);l.type=`button`,l.className=`tcw-btn-icon tcw-toolbar-more`,l.title=this.t(`toolbar.more`),l.setAttribute(`aria-haspopup`,`menu`),l.setAttribute(`aria-expanded`,`false`),l.innerHTML=O(`more`,16),l.addEventListener(`click`,()=>this.toggleMore(l)),n.appendChild(l),this.moreBtn=l}toggleMore(e){if(A.closeAnchoredTo(e))return;let t=this.rootEl(),n=this.el.closest(`[data-tcw-narrow]`)!==null,r=[];for(let e of this.el.querySelectorAll(`.tcw-toolbar-overflow`)){if(this.isOff(e)||!n&&!e.hasAttribute(j))continue;let t=e instanceof HTMLButtonElement?[e]:[...e.querySelectorAll(`button`)];r.push(...t.filter(e=>!e.hidden&&!e.disabled&&!this.isOff(e)))}if(r.length===0)return;let i=r.map((e,t)=>{let n=e.getAttribute(`aria-label`)||e.title||e.textContent?.trim()||``,r=e.getAttribute(`aria-pressed`);return r===null?{id:String(t),label:n,icon:e.dataset.icon}:{id:String(t),label:n,icon:e.dataset.icon,checked:r===`true`}});this.moreMenu??=new A(t,this.t(`toolbar.more`)),this.moreMenu.openUnder(i,e,e=>r[Number(e)]?.click(),`end`)}addHostButton(e){let t=document.createElement(`button`);t.type=`button`,t.className=`${e.text||!e.icon?`tcw-btn`:`tcw-btn-icon`} tcw-host-btn tcw-toolbar-overflow`,t.dataset.hostButton=e.id,typeof e.icon==`string`&&(t.dataset.icon=e.icon),t.title=e.label,e.toggle&&t.setAttribute(`aria-pressed`,`false`),typeof e.icon==`string`?t.innerHTML=O(e.icon,14):e.icon&&t.appendChild(e.icon);let n=e.text??(e.icon?``:e.label);if(n){let e=document.createElement(`span`);e.className=`tcw-host-btn-text`,e.textContent=n,t.appendChild(e)}return ln(t,e.label),t.addEventListener(`click`,()=>e.onClick(t)),(e.side===`left`?this.hostLeft:this.hostRight)?.appendChild(t),this.scheduleFit(),t}hostSlot(e){return e===`left`?this.hostLeft:this.hostRight}hostGroup(){let e=document.createElement(`div`);return e.className=`tcw-toolbar-host`,e}setSymbolSearch(e){let t=this.el.querySelector(`[data-role="symbol"]`);t&&(e?t.removeAttribute(`aria-disabled`):t.setAttribute(`aria-disabled`,`true`))}tidy(){this.trade?.tidy(),Je(this.el,`tcw-toolbar-sep`,`tcw-toolbar-spacer`),this.scheduleFit()}setHistory(e,t){this.undoBtn&&(this.undoBtn.disabled=!e),this.redoBtn&&(this.redoBtn.disabled=!t)}rootEl(){return this.el.closest(`.tcw-root`)??this.host}setActive(e,t){this.trade?.setOpen(e,t);let n=this.el.querySelector(`[data-role="${e}"]`);n&&(n.classList.toggle(`tcw-active`,t),n.setAttribute(`aria-pressed`,String(t)))}setRailed(e,t){let n=this.el.querySelector(`[data-role="${e}"]`);n&&(n.hidden=t)}setLayout(e,t){let n=this.el.querySelector(`[data-role="layouts"]`);if(!n)return;let r=e??this.t(`layouts.unnamed`);if(this.layoutShown===`${t}:${r}`)return;this.layoutShown=`${t}:${r}`;let i=`${this.t(`toolbar.layouts`)}: ${r}${t?` (${this.t(`layouts.unsavedChanges`)})`:``}`;n.innerHTML=`${O(`save`,14)}<span class="tcw-layouts-label">${k(r)}</span>`+(t?`<span class="tcw-layouts-dirty" aria-hidden="true"></span>`:``)+O(`chevronDown`,12),n.title=i,n.setAttribute(`aria-label`,i),this.scheduleFit()}setFullscreen(e){if(!this.fullscreenBtn)return;let t=this.t(e?`toolbar.exitFullscreen`:`toolbar.fullscreen`);this.fullscreenBtn.innerHTML=O(e?`minimize`:`maximize`,14),this.fullscreenBtn.title=t,this.fullscreenBtn.setAttribute(`aria-pressed`,String(e))}chartTypeLabel(e){return vt(e,this.t)}buildChartTypeMenu(){if(!this.chartTypeDropdown)return;let e=this.config.chartTypes.map(e=>`<button class="tcw-dropdown-item tcw-dropdown-item--icon" data-ct="${k(e.value)}">${nt(e.value,16)}<span>${k(this.chartTypeLabel(e))}</span></button>`).join(``);this.chartTypeDropdown.setContent(e),this.chartTypeDropdown.panel.querySelectorAll(`.tcw-dropdown-item`).forEach(e=>{e.addEventListener(`click`,e=>{let t=e.currentTarget.dataset.ct;this.callbacks.onChartType(t),this.chartTypeDropdown?.close()})})}setSymbolDescription(e){let t=this.el.querySelector(`[data-role="symbol"]`);t&&(e?t.title=e:t.removeAttribute(`title`))}setTimeframes(e,t){this.config={...this.config,timeframes:e},this.setTimeframeFavorites(t)}setTimeframeFavorites(e){this.tfFavorites=[...e],this.tfRendered=``,this.buildTimeframeMenu()}buildTimeframeMenu(){if(!this.tfDropdown)return;let e=k(this.t(`toolbar.timeframes.pin`)),t=k(this.t(`toolbar.timeframes.remove`)),n=``;for(let{unit:r,timeframes:i}of Pt(this.config.timeframes)){n+=`<div class="tcw-tf-section" data-tf-section="${r}" role="group" aria-label="${k(this.t(cn[r]))}"><div class="tcw-dropdown-label">${k(this.t(cn[r]))}</div>`;for(let r of i){let i=this.tfFavorites.includes(r.value),[a,o]=[k(r.value),k(r.label)];n+=`<div class="tcw-tf-row"><button class="tcw-dropdown-item" data-tf-pick="${a}">${o}</button>`+(r.custom&&this.callbacks.onRemoveTimeframe?`<button class="tcw-tf-remove" data-tf-remove="${a}" title="${t}" aria-label="${t}: ${o}">${O(`x`,12)}</button>`:``)+`<button class="tcw-tf-star${i?` tcw-active`:``}" data-tf-star="${a}" aria-pressed="${i}" title="${e}" aria-label="${e}: ${o}">${O(`star`,12)}</button></div>`}n+=`</div>`}if(this.callbacks.onAddTimeframe){let e=k(this.t(`toolbar.timeframes.custom`)),t=k(this.t(`toolbar.timeframes.add`));n+=`<form class="tcw-tf-custom" ${Ke(`customTimeframes`)} novalidate><input class="tcw-tf-custom-input" type="text" autocomplete="off" spellcheck="false" maxlength="6" placeholder="7m, 90m, 2h…" aria-label="${e}" aria-describedby="tcw-tf-hint-${this.uid}"><button type="submit" class="tcw-tf-custom-add" title="${t}" aria-label="${t}">${O(`plus`,12)}</button><div class="tcw-tf-custom-hint" id="tcw-tf-hint-${this.uid}" role="status"></div></form>`}this.tfDropdown.setContent(n);let r=this.tfDropdown.panel;r.querySelectorAll(`[data-tf-pick]`).forEach(e=>{e.addEventListener(`click`,()=>this.callbacks.onTimeframe(e.dataset.tfPick))}),r.querySelectorAll(`[data-tf-star]`).forEach(e=>{e.addEventListener(`click`,t=>{t.stopPropagation(),this.callbacks.onToggleTimeframeFavorite?.(e.dataset.tfStar)})}),r.querySelectorAll(`[data-tf-remove]`).forEach(e=>{e.addEventListener(`click`,t=>{t.stopPropagation(),this.callbacks.onRemoveTimeframe?.(e.dataset.tfRemove)})});let i=r.querySelector(`.tcw-tf-custom`);i&&this.wireCustomTimeframe(i)}wireCustomTimeframe(e){let t=e.querySelector(`.tcw-tf-custom-input`),n=e.querySelector(`.tcw-tf-custom-hint`);e.addEventListener(`click`,e=>e.stopPropagation()),t.addEventListener(`input`,()=>{t.removeAttribute(`aria-invalid`),n.textContent=``}),e.addEventListener(`submit`,e=>{e.preventDefault(),e.stopPropagation(),this.callbacks.onAddTimeframe?.(t.value)?(t.value=``,n.textContent=``,this.tfDropdown?.close(),this.el.querySelector(`[data-role="timeframes"]`)?.focus()):(t.setAttribute(`aria-invalid`,`true`),n.textContent=this.t(`toolbar.timeframes.invalid`))})}renderTimeframes(e){if(!this.tfGroup)return;let t=this.config.timeframes.filter(t=>this.tfFavorites.includes(t.value)||t.value===e),n=`${t.map(e=>e.value).join(`,`)}|${e}`;n!==this.tfRendered&&(this.tfRendered=n,this.tfCurrent&&(this.tfCurrent.textContent=this.config.timeframes.find(t=>t.value===e)?.label??e),this.tfGroup.replaceChildren(...t.map(t=>{let n=document.createElement(`button`);return n.className=`tcw-btn`,n.textContent=t.label,n.dataset.tf=t.value,n.classList.toggle(`tcw-active`,t.value===e),n.addEventListener(`click`,()=>this.callbacks.onTimeframe(t.value)),n})),(this.tfDropdown?.panel)?.querySelectorAll(`[data-tf-pick]`).forEach(t=>{t.classList.toggle(`tcw-active`,t.dataset.tfPick===e)}))}setIndicatorsOpen(e){this.el.querySelector(`[data-role="indicators"]`)?.setAttribute(`aria-expanded`,String(e))}renderSymbol(e){let t=this.el.querySelector(`[data-role="symbol"]`);if(!t||this.symbolShown===e)return;this.symbolShown=e;let{venue:n,ticker:r}=Qt(e),i=(e,t)=>{let n=document.createElement(`span`);return n.className=e,n.textContent=t,n};t.replaceChildren(...n?[i(`tcw-toolbar-venue`,n)]:[],i(`tcw-toolbar-ticker`,r)),t.classList.toggle(`tcw-toolbar-symbol--venue`,n!==``),t.setAttribute(`aria-label`,e)}update(e){this.renderSymbol(e.symbol),this.renderTimeframes(e.timeframe);let t=this.el.querySelector(`[data-role="charttype"]`);if(t){let n=this.config.chartTypes.find(t=>t.value===e.chartType),r=n?this.chartTypeLabel(n):e.chartType;t.innerHTML=nt(e.chartType,16),t.title=r,t.setAttribute(`aria-label`,r)}let n=this.el.querySelector(`[data-role="indicators"]`);if(n){let t=[...e.activeIndicators.values()].filter(e=>!r.SYMBOL_INDICATOR_IDS.has(e.id)).length,i=`${O(`trendingUp`,14)} <span class="tcw-trigger-label">${k(this.t(`toolbar.indicators`))}</span>`;n.setAttribute(`aria-label`,this.t(`toolbar.indicators`)),t>0&&(i+=` <span class="tcw-badge-count">${t}</span>`),n.innerHTML=i}if(this.themeBtn){let t=e.isDark?`moon`:`sun`;this.themeBtn.innerHTML=O(t,14),this.themeBtn.dataset.icon=t}this.scheduleFit()}sep(){let e=document.createElement(`span`);return e.className=`tcw-toolbar-sep`,e}spacer(){let e=document.createElement(`span`);return e.className=`tcw-toolbar-spacer`,e}iconBtn(e,t,n){let r=document.createElement(`button`);return r.className=`tcw-btn-icon tcw-toolbar-overflow`,r.dataset.icon=e,r.title=t,r.innerHTML=O(e,14),r.addEventListener(`click`,n),r}destroy(){this.destroyed=!0,this.resizeObserver?.disconnect(),this.hostObserver?.disconnect(),this.fitFrame&&cancelAnimationFrame(this.fitFrame),this.chartTypeDropdown?.destroy(),this.tfDropdown?.destroy(),this.moreMenu?.destroy(),this.trade?.destroy(),this.el.remove()}};function dn(e,t,n){e.classList.toggle(`tcw-active`,t),n&&e.setAttribute(`aria-pressed`,String(t))}function fn(e,t,n){let r=n==null?``:String(n),i=e.querySelector(`.tcw-host-btn-text`);return(i?.textContent??``)===r?!1:(i||(i=document.createElement(`span`),i.className=`tcw-host-btn-text`,e.appendChild(i)),i.textContent=r,ln(e,t),!0)}var pn=16,mn=150,hn=4;function gn(e){let t=`sidebar.${e}`;return Pe.includes(t)?t:null}function _n(e,t){for(let n of e){let e=n.tools.find(e=>e.value===t);if(e)return e.label}return t}var vn=`--tcw-fab-plot-left`,yn=class{config;callbacks;el;groupWraps=[];groupButtons=[];groupIcons=[];groupTools=[];cursorBtn=null;magnetBtn=null;eraserBtn=null;zoomBtn=null;stayBtn=null;lockAllBtn=null;hideAllBtn=null;drawings={locked:!1,hidden:!1};flyoutEl=null;flyoutIdx=-1;flyoutHideTimer=null;hostEl=null;favoritesEl=null;favoritesDivider=null;favorites=[];fab;fabShows=``;onPressAway=e=>{let t=e.target;t&&(this.el.contains(t)||this.fab.contains(t)||this.flyoutEl?.contains(t))||this.setOpen(!1)};onEscape=e=>{e.key===`Escape`&&!this.flyoutEl&&this.setOpen(!1)};constructor(e,n,r,i=t.t){this.host=e,this.t=i,this.config=n,this.callbacks=r,this.el=document.createElement(`div`),this.el.className=`tcw-sidebar`,D(this.el,`sidebar`),this.build(),this.el.addEventListener(`scroll`,()=>this.hideFlyout(),{passive:!0}),e.appendChild(this.el),this.fab=document.createElement(`button`),this.fab.type=`button`,this.fab.className=`tcw-sidebar-fab`,this.fab.setAttribute(`aria-label`,this.t(`drawing.tools`)),this.fab.setAttribute(`aria-expanded`,`false`),this.fab.innerHTML=O(`penLine`,18),D(this.fab,`sidebar`),this.fab.addEventListener(`click`,()=>this.setOpen(!this.isOpen())),e.appendChild(this.fab)}setPlotLeft(e){let t=`${Math.max(0,Math.round(e))}px`;this.fab.style.getPropertyValue(vn)!==t&&this.fab.style.setProperty(vn,t)}isNarrow(){return this.el.closest(`[data-tcw-narrow]`)!==null}isOpen(){return this.el.classList.contains(`tcw-sidebar-open`)}setOpen(e){if(e!==this.isOpen())if(this.el.classList.toggle(`tcw-sidebar-open`,e),this.fab.setAttribute(`aria-expanded`,String(e)),e)document.addEventListener(`pointerdown`,this.onPressAway,!0),document.addEventListener(`keydown`,this.onEscape);else{let e=this.el.contains(document.activeElement)||!!this.flyoutEl?.contains(document.activeElement);this.hideFlyout(),document.removeEventListener(`pointerdown`,this.onPressAway,!0),document.removeEventListener(`keydown`,this.onEscape),e&&this.isNarrow()&&this.fab.focus({preventScroll:!0})}}closeOverlay(){this.setOpen(!1)}closeForChart(){this.isNarrow()&&this.setOpen(!1)}pick(e){this.callbacks.onDrawingTool(e),this.closeForChart()}build(){let{config:e,callbacks:t,el:n}=this;this.cursorBtn=document.createElement(`button`),this.cursorBtn.className=`tcw-sidebar-btn`,this.cursorBtn.title=this.t(`drawing.cursor`),this.cursorBtn.innerHTML=O(`cursor`,14),this.cursorBtn.addEventListener(`click`,()=>{t.onCancelDrawing(),this.closeForChart()}),D(this.cursorBtn,`sidebar.cursor`),n.appendChild(this.cursorBtn),n.appendChild(this.divider()),t.onToggleFavorite&&(this.favorites=[...e.favorites??[]],this.favoritesEl=document.createElement(`div`),this.favoritesEl.className=`tcw-sidebar-favorites`,D(this.favoritesEl,`sidebar.favorites`),n.appendChild(this.favoritesEl),this.favoritesDivider=this.divider(),D(this.favoritesDivider,`sidebar.favorites`),n.appendChild(this.favoritesDivider),this.renderFavorites());let r;e.drawingToolGroups.forEach((e,t)=>{if(!e.tools[0])return;e.section!==void 0&&r!==void 0&&e.section!==r&&this.appendDivider(),r=e.section;let i=document.createElement(`div`);i.className=`tcw-tool-group-wrap`;let a=gn(e.section);a&&D(i,a);let o=document.createElement(`button`);o.className=`tcw-sidebar-btn`;let s=e.tools[0].value;e.tools.length>1?o.setAttribute(`aria-label`,`${e.label}: ${e.tools[0].label}`):o.title=e.label;let c=document.createElement(`span`);if(c.className=`tcw-sidebar-icon`,c.innerHTML=tt(s,pn),o.appendChild(c),this.groupIcons.push(c),this.groupTools.push(s),e.tools.length>1){let e=document.createElement(`span`);e.className=`tcw-multi-dot`,o.appendChild(e)}o.addEventListener(`click`,()=>{if(this.isNarrow()&&e.tools.length>1){this.flyoutEl&&this.flyoutIdx===t?this.hideFlyout():this.showFlyout(t);return}this.pick(this.groupTools[t])}),i.appendChild(o),i.addEventListener(`mouseenter`,()=>{this.isNarrow()||this.showFlyout(t)}),i.addEventListener(`mouseleave`,()=>{this.isNarrow()||this.scheduleHideFlyout()}),e.tools.length>1&&(o.setAttribute(`aria-haspopup`,`menu`),o.setAttribute(`aria-expanded`,`false`),o.addEventListener(`keydown`,e=>{e.key===`ArrowRight`||e.key===`ArrowDown`?(e.preventDefault(),this.showFlyout(t),this.focusFlyoutItem(0)):e.key===`Escape`&&this.flyoutEl&&(e.stopPropagation(),this.hideFlyout())})),i.addEventListener(`focusout`,e=>{let t=e.relatedTarget;!i.contains(t)&&!this.flyoutEl?.contains(t)&&this.scheduleHideFlyout()}),n.appendChild(i),this.groupWraps.push(i),this.groupButtons.push(o)});let i=document.createElement(`div`);if(i.className=`tcw-sidebar-spacer`,n.appendChild(i),n.appendChild(this.divider()),t.onToggleStyle){let e=document.createElement(`button`);e.className=`tcw-sidebar-btn`,e.title=this.t(`drawing.style`),e.dataset.role=`style`,D(e,`sidebar.style`),e.innerHTML=O(`palette`,14);let r=t.onToggleStyle;e.addEventListener(`click`,()=>{r(),this.closeForChart()}),n.appendChild(e)}if(t.onToggleMagnet&&(this.magnetBtn=document.createElement(`button`),this.magnetBtn.className=`tcw-sidebar-btn`,this.magnetBtn.title=this.t(`drawing.magnet`),this.magnetBtn.innerHTML=O(`magnet`,14),this.magnetBtn.addEventListener(`click`,t.onToggleMagnet),D(this.magnetBtn,`sidebar.magnet`),n.appendChild(this.magnetBtn)),t.onToggleEraser){let e=t.onToggleEraser;this.eraserBtn=this.toggleButton(`eraser`,this.t(`drawing.eraser`),()=>{e(),this.closeForChart()}),D(this.eraserBtn,`sidebar.eraser`),n.appendChild(this.eraserBtn)}if(t.onToggleZoomArea){let e=t.onToggleZoomArea;this.zoomBtn=this.toggleButton(`zoomIn`,this.t(`drawing.zoomArea`),()=>{e(),this.closeForChart()}),D(this.zoomBtn,`sidebar.zoomArea`),n.appendChild(this.zoomBtn)}if(t.onToggleStayInDrawing&&(this.stayBtn=document.createElement(`button`),this.stayBtn.className=`tcw-sidebar-btn`,this.stayBtn.dataset.role=`stay`,this.stayBtn.title=this.t(`drawing.stay`),this.stayBtn.setAttribute(`aria-pressed`,`false`),this.stayBtn.innerHTML=O(`repeat`,14),this.stayBtn.addEventListener(`click`,t.onToggleStayInDrawing),D(this.stayBtn,`sidebar.stayInDrawing`),n.appendChild(this.stayBtn)),this.hostEl=document.createElement(`div`),this.hostEl.className=`tcw-sidebar-host`,n.appendChild(this.hostEl),this.appendDivider(),t.onLockAll){let e=t.onLockAll;this.lockAllBtn=this.toggleButton(`lock`,this.t(`drawing.lockAll`),()=>e(!this.drawings.locked)),this.lockAllBtn.dataset.role=`lockAll`,D(this.lockAllBtn,`sidebar.lockAll`),n.appendChild(this.lockAllBtn)}if(t.onHideAll){let e=t.onHideAll;this.hideAllBtn=this.toggleButton(`eyeOff`,this.t(`drawing.hideAll`),()=>e(!this.drawings.hidden)),this.hideAllBtn.dataset.role=`hideAll`,D(this.hideAllBtn,`sidebar.hideAll`),n.appendChild(this.hideAllBtn)}let a=document.createElement(`button`);a.className=`tcw-sidebar-btn tcw-danger`,a.title=this.t(`drawing.clearAll`),a.innerHTML=O(`trash`,14),a.setAttribute(`aria-haspopup`,`menu`),a.setAttribute(`aria-expanded`,`false`),a.addEventListener(`click`,()=>t.onClear(a)),D(a,`sidebar.clear`),n.appendChild(a)}setDrawingsState(e){if(!(e.locked===this.drawings.locked&&e.hidden===this.drawings.hidden)){this.drawings={...e};for(let[t,n]of[[this.lockAllBtn,e.locked],[this.hideAllBtn,e.hidden]])t?.setAttribute(`aria-pressed`,String(n)),t?.classList.toggle(`tcw-active`,n)}}setFavorites(e){this.favorites=[...e],this.renderFavorites();for(let e of this.flyoutEl?.querySelectorAll(`.tcw-flyout-row`)??[]){let t=this.favorites.includes(e.dataset.toolValue??``);e.classList.toggle(`tcw-flyout-faved`,t),e.querySelector(`[data-pin]`)?.setAttribute(`aria-pressed`,String(t))}}renderFavorites(){if(!this.favoritesEl)return;this.favoritesEl.replaceChildren();let e=this.favorites.length>0;this.favoritesEl.style.display=e?``:`none`,this.favoritesDivider&&(this.favoritesDivider.style.display=e?``:`none`);for(let e of this.favorites){let n=document.createElement(`button`);n.className=`tcw-sidebar-btn`,n.title=t.r(this.t(`sidebar.unpinHint`),{tool:_n(this.config.drawingToolGroups,e)}),n.dataset.toolValue=e,n.innerHTML=tt(e,pn),n.addEventListener(`click`,()=>this.pick(e)),n.addEventListener(`contextmenu`,t=>{t.preventDefault(),this.callbacks.onToggleFavorite?.(e)}),this.favoritesEl.appendChild(n)}}showFlyout(e){if(this.cancelHideFlyout(),this.flyoutEl&&this.flyoutIdx===e)return;let t=this.config.drawingToolGroups[e];if(!t||t.tools.length<=1){this.hideFlyout();return}this.hideFlyout();let n=document.createElement(`div`);n.className=`tcw-flyout`,n.setAttribute(`role`,`menu`),n.setAttribute(`aria-label`,t.label),n.addEventListener(`keydown`,t=>this.onFlyoutKey(t,e));let r=document.createElement(`div`);r.className=`tcw-flyout-header`,r.textContent=t.label,n.appendChild(r);let i=this.t(`drawing.pinFavorite`);for(let e of t.tools){let t=document.createElement(`div`);t.className=`tcw-flyout-row`,t.setAttribute(`role`,`none`),t.dataset.toolValue=e.value;let r=document.createElement(`button`);r.className=`tcw-flyout-item`,r.setAttribute(`role`,`menuitem`),r.tabIndex=-1,r.innerHTML=tt(e.value,pn);let a=document.createElement(`span`);a.className=`tcw-flyout-name`,a.textContent=e.label,r.appendChild(a);let o=this.config.shortcuts?.[e.value];if(o){let e=document.createElement(`kbd`);e.className=`tcw-flyout-key`,e.textContent=o,D(e,`hotkeys`,`hotkeys.tools`),r.appendChild(e)}if(r.dataset.toolValue=e.value,r.addEventListener(`click`,()=>{this.hideFlyout(),this.pick(e.value)}),t.appendChild(r),this.callbacks.onToggleFavorite){let n=this.favorites.includes(e.value);t.classList.toggle(`tcw-flyout-faved`,n);let a=document.createElement(`button`);a.type=`button`,a.className=`tcw-flyout-pin`,a.dataset.pin=e.value,a.tabIndex=-1,a.title=i,a.setAttribute(`aria-label`,`${i}: ${e.label}`),a.setAttribute(`aria-pressed`,String(n)),a.innerHTML=O(`star`,12),a.addEventListener(`click`,t=>{t.stopPropagation(),this.callbacks.onToggleFavorite?.(e.value)}),t.appendChild(a),r.addEventListener(`contextmenu`,t=>{t.preventDefault(),this.callbacks.onToggleFavorite?.(e.value)})}n.appendChild(t)}n.addEventListener(`mouseenter`,()=>this.cancelHideFlyout()),n.addEventListener(`mouseleave`,()=>this.scheduleHideFlyout()),n.addEventListener(`focusout`,t=>{let r=t.relatedTarget;!n.contains(r)&&!this.groupWraps[e].contains(r)&&this.scheduleHideFlyout()}),this.flyoutEl=n,this.flyoutIdx=e,this.host.appendChild(n),this.placeFlyout(n,this.groupButtons[e]),this.groupButtons[e].setAttribute(`aria-expanded`,`true`)}flyoutItems(){return this.flyoutEl?[...this.flyoutEl.querySelectorAll(`.tcw-flyout-item`)]:[]}focusFlyoutItem(e){let t=this.flyoutItems();t.length!==0&&t[(e+t.length)%t.length].focus()}onFlyoutKey(e,t){let n=this.flyoutItems(),r=n.indexOf(document.activeElement);switch(e.key){case`ArrowDown`:this.focusFlyoutItem(r+1);break;case`ArrowUp`:this.focusFlyoutItem(r-1);break;case`Home`:this.focusFlyoutItem(0);break;case`End`:this.focusFlyoutItem(n.length-1);break;case`Escape`:case`ArrowLeft`:e.stopPropagation(),this.hideFlyout(),this.groupButtons[t]?.focus();break;case`Tab`:this.hideFlyout(),this.groupButtons[t]?.focus();return;default:return}e.preventDefault()}placeFlyout(e,t){let n=this.host.getBoundingClientRect(),r=t.getBoundingClientRect();e.style.maxHeight=`${Math.max(0,this.host.clientHeight-hn*2)}px`;let i=this.host.clientHeight-e.offsetHeight-hn;this.host.closest(`[dir]`)?.getAttribute(`dir`)===`rtl`?(e.style.left=``,e.style.right=`${n.right-r.left}px`):(e.style.right=``,e.style.left=`${r.right-n.left}px`),e.style.top=`${Math.max(0,Math.min(r.top-n.top,i))}px`}scheduleHideFlyout(){this.cancelHideFlyout(),this.flyoutHideTimer=setTimeout(()=>{this.flyoutHideTimer=null,this.hideFlyout()},mn)}cancelHideFlyout(){this.flyoutHideTimer!==null&&(clearTimeout(this.flyoutHideTimer),this.flyoutHideTimer=null)}hideFlyout(){this.cancelHideFlyout(),this.flyoutEl&&=(this.flyoutEl.remove(),null),this.groupButtons[this.flyoutIdx]?.setAttribute(`aria-expanded`,`false`),this.flyoutIdx=-1}update(e){this.cursorBtn&&this.cursorBtn.classList.toggle(`tcw-active`,e.activeTool===null);let t=e.activeTool??``;t!==this.fabShows&&(this.fabShows=t,this.fab.innerHTML=e.activeTool?tt(e.activeTool,18):O(`penLine`,18)),this.fab.classList.toggle(`tcw-active`,e.activeTool!==null||e.eraser||e.zoomArea);let{drawingToolGroups:n}=this.config;for(let t=0;t<n.length;t++){let r=n[t].tools.some(t=>t.value===e.activeTool);this.groupButtons[t].classList.toggle(`tcw-active`,r),r&&e.activeTool&&e.activeTool!==this.groupTools[t]&&(this.groupTools[t]=e.activeTool,this.groupIcons[t].innerHTML=tt(e.activeTool,pn),n[t].tools.length>1&&this.groupButtons[t].setAttribute(`aria-label`,`${n[t].label}: ${_n(n,e.activeTool)}`))}if(this.flyoutEl&&this.flyoutEl.querySelectorAll(`.tcw-flyout-item`).forEach(t=>{let n=t;n.classList.toggle(`tcw-active`,n.dataset.toolValue===e.activeTool)}),this.magnetBtn){let t=e.magnetEnabled&&e.magnetStrong;this.magnetBtn.classList.toggle(`tcw-active`,e.magnetEnabled),this.magnetBtn.innerHTML=O(t?`magnetStrong`:`magnet`,14),this.magnetBtn.title=t?this.t(`drawing.magnetStrong`):e.magnetEnabled?this.t(`drawing.magnetOn`):this.t(`drawing.magnetOff`),this.magnetBtn.setAttribute(`aria-label`,this.magnetBtn.title)}for(let[t,n]of[[this.eraserBtn,e.eraser],[this.zoomBtn,e.zoomArea]])t&&(t.classList.toggle(`tcw-active`,n),t.setAttribute(`aria-pressed`,String(n)));this.stayBtn&&(this.stayBtn.classList.toggle(`tcw-active`,e.stayInDrawing),this.stayBtn.setAttribute(`aria-pressed`,String(e.stayInDrawing)))}addHostButton(e){let t=document.createElement(`button`);return t.type=`button`,t.className=`tcw-sidebar-btn tcw-host-btn`,t.dataset.hostButton=e.id,t.title=e.label,t.setAttribute(`aria-label`,e.label),e.toggle&&t.setAttribute(`aria-pressed`,`false`),typeof e.icon==`string`?t.innerHTML=O(e.icon,14):t.appendChild(e.icon),t.addEventListener(`click`,()=>e.onClick(t)),this.hostEl?.appendChild(t),this.tidy(),t}hostSlot(){return this.hostEl}tidy(){Je(this.el,`tcw-sidebar-divider`,`tcw-sidebar-spacer`)}toggleButton(e,t,n){let r=document.createElement(`button`);return r.className=`tcw-sidebar-btn`,r.title=t,r.setAttribute(`aria-label`,t),r.setAttribute(`aria-pressed`,`false`),r.innerHTML=O(e,14),r.addEventListener(`click`,n),r}appendDivider(){this.el.lastElementChild?.classList.contains(`tcw-sidebar-divider`)||this.el.appendChild(this.divider())}divider(){let e=document.createElement(`div`);return e.className=`tcw-sidebar-divider`,e}destroy(){this.setOpen(!1),this.hideFlyout(),this.fab.remove(),this.el.remove()}},bn=`button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])`;function M(e,t){if(e.key!==`Tab`)return;let n=document.activeElement,r=[...t.querySelectorAll(bn)].filter(e=>e.tabIndex>=0&&(e.getClientRects().length>0||e===n));if(r.length===0)return;let i=r[0],a=r[r.length-1],o=n instanceof Node&&t.contains(n),s=(e,t)=>(e.compareDocumentPosition(t)&Node.DOCUMENT_POSITION_PRECEDING)!==0;e.shiftKey&&(!o||n===i||s(i,n))?(e.preventDefault(),a.focus()):!e.shiftKey&&(!o||n===a||s(n,a))&&(e.preventDefault(),i.focus())}function xn(e,t){let n=document.createElement(`label`);n.className=`tcw-settings-row`;let r=document.createElement(`span`);return r.className=`tcw-settings-label`,r.textContent=e,n.append(r,t),n}function Sn(e,t,n){let r=document.createElement(`label`);r.className=`tcw-settings-row tcw-check-row`;let i=document.createElement(`input`);i.type=`checkbox`,i.checked=t,i.addEventListener(`change`,()=>n(i.checked));let a=document.createElement(`span`);return a.className=`tcw-settings-label`,a.textContent=e,r.append(i,a),r}function Cn(e,t){let n=document.createElement(`button`);return n.type=`button`,n.className=`tcw-toggle${e?` tcw-on`:``}`,n.setAttribute(`role`,`switch`),n.setAttribute(`aria-checked`,String(e)),n.addEventListener(`click`,()=>{let e=!n.classList.contains(`tcw-on`);n.classList.toggle(`tcw-on`,e),n.setAttribute(`aria-checked`,String(e)),t(e)}),n}function N(e,t,n){let r=document.createElement(`input`);return r.type=`number`,r.className=`tcw-indi-input`,r.value=String(e),r.step=String(t.step??(Number.isInteger(e)?1:.001)),t.min!==void 0&&(r.min=String(t.min)),t.max!==void 0&&(r.max=String(t.max)),r.addEventListener(`change`,()=>{if(r.value.trim()===``)return;let e=Number(r.value);Number.isFinite(e)&&(t.min!==void 0&&(e=Math.max(t.min,e)),t.max!==void 0&&(e=Math.min(t.max,e)),r.value=String(e),n(e))}),r}function P(e,t){let n=document.createElement(`input`);return n.type=`color`,n.className=`tcw-indi-color`,n.value=I(e),n.addEventListener(`input`,()=>t(n.value)),n}function F(e,t,n){let r=document.createElement(`select`);r.className=`tcw-indi-input tcw-indi-select`;for(let t of e){let e=document.createElement(`option`);e.value=t.value,e.textContent=t.label,r.appendChild(e)}return r.value=t,r.addEventListener(`change`,()=>n(r.value)),r}function I(e){if(typeof e!=`string`)return`#000000`;let t=e.trim();if(/^#[0-9a-f]{6}$/i.test(t))return t.toLowerCase();if(/^#[0-9a-f]{8}$/i.test(t))return t.slice(0,7).toLowerCase();if(/^#[0-9a-f]{3,4}$/i.test(t))return`#${t[1]}${t[1]}${t[2]}${t[2]}${t[3]}${t[3]}`.toLowerCase();let n=/^rgba?\(\s*(\d+)[\s,]+(\d+)[\s,]+(\d+)/i.exec(t);if(n)return`#${[n[1],n[2],n[3]].map(e=>Math.min(255,Number(e)).toString(16).padStart(2,`0`)).join(``)}`;let r=wn(t);return r!==null&&r!==t?I(r):`#000000`}var L;function wn(e){if(L===void 0)try{L=typeof document<`u`?document.createElement(`canvas`).getContext(`2d`):null}catch{L=null}if(!L)return null;L.fillStyle=`#010203`,L.fillStyle=e;let t=String(L.fillStyle);return t===`#010203`?null:t}function Tn(e){if(typeof e!=`string`)return 1;let t=/^rgba\([^)]*,\s*([\d.]+)\s*\)$/i.exec(e.trim());return t?Math.max(0,Math.min(1,Number(t[1]))):1}function En(e,t){let n=I(e),[r,i,a]=[1,3,5].map(e=>parseInt(n.slice(e,e+2),16));return`rgba(${r}, ${i}, ${a}, ${Math.round(t*100)/100})`}var Dn={ArrowRight:1,ArrowDown:1,ArrowLeft:-1,ArrowUp:-1};function On(e,t,n,r){let i=document.createElement(`div`);i.className=`tcw-segmented`,i.setAttribute(`role`,`radiogroup`),i.setAttribute(`aria-label`,r);let a=e.map(e=>{let t=document.createElement(`button`);return t.type=`button`,t.className=`tcw-segment`,t.setAttribute(`role`,`radio`),t.dataset.value=e.value,t.textContent=e.label,t.addEventListener(`click`,()=>s(e.value)),t}),o=e=>{let t=Math.max(0,a.findIndex(t=>t.dataset.value===e));a.forEach((n,r)=>{n.setAttribute(`aria-checked`,String(n.dataset.value===e)),n.tabIndex=r===t?0:-1})},s=e=>{o(e),n(e)};return i.addEventListener(`keydown`,t=>{let n=a.findIndex(e=>e===t.target);if(n<0||t.altKey||t.ctrlKey||t.metaKey)return;let r=a.length-1,o;if(t.key===`Home`)o=0;else if(t.key===`End`)o=r;else if(t.key in Dn){let e=i.closest(`[dir]`)?.getAttribute(`dir`)===`rtl`,r=t.key===`ArrowLeft`||t.key===`ArrowRight`;o=(n+(e&&r?-Dn[t.key]:Dn[t.key])+a.length)%a.length}else return;t.preventDefault(),a[o].focus(),s(e[o].value)}),o(t),i.append(...a),i}function kn(e,t,r){if(!(r>0)||!Number.isFinite(e))return e;let i=e/r,a=Math.round(i),o=Math.abs(i-a)<1e-9*Math.max(1,Math.abs(i)),s=t>0?o?a+1:Math.ceil(i):o?a-1:Math.floor(i);return s<1?e:Number((s*r).toFixed((0,n.stepDecimals)(r)))}function An(e,t){let n=document.createElement(`div`);n.className=`tcw-stepper`,n.dir=`ltr`;let r=n=>{let r=Number(e.value),i=e.value.trim()!==``&&Number.isFinite(r)?r:t.fallback?.()??0,a=kn(i,n,t.step(i,n));e.value=t.format?t.format(a):String(a),e.dispatchEvent(new Event(`input`))},i=(e,t)=>{let n=document.createElement(`button`);return n.type=`button`,n.className=`tcw-stepper-btn`,n.tabIndex=-1,n.setAttribute(`aria-label`,t),n.innerHTML=O(e>0?`plus`:`minus`,14),n.addEventListener(`click`,()=>r(e)),n};e.addEventListener(`keydown`,e=>{e.key!==`ArrowUp`&&e.key!==`ArrowDown`||(e.preventDefault(),r(e.key===`ArrowUp`?1:-1))});let a=i(-1,t.labels.down),o=i(1,t.labels.up);return n.append(a,e,o),{element:n,down:a,up:o}}var jn=0,Mn=0,Nn=20;function Pn(e){let t=document.createElement(`div`);if(t.className=`tcw-settings-section`,e){let n=document.createElement(`div`);n.className=`tcw-settings-section-title`,n.textContent=e,t.appendChild(n),t.setAttribute(`role`,`group`),t.setAttribute(`aria-label`,e)}return t}function Fn(e){let t=document.createElement(`div`);t.className=`tcw-settings-row`;let n=document.createElement(`span`);return n.className=`tcw-settings-label`,n.textContent=e,t.appendChild(n),t}function In(e,t,n,r,i){let a=Fn(e),o=document.createElement(`div`);o.className=`tcw-color-picker-wrap`;let s=document.createElement(`input`);s.type=`color`,s.setAttribute(`aria-label`,e);let c=document.createElement(`span`);c.className=`tcw-color-hex`,c.id=`tcw-color-${++jn}`,s.setAttribute(`aria-describedby`,c.id);let l=null,u=t=>{s.value=I(t??r.start?.()),c.textContent=t??i(`settings.auto`),a.classList.toggle(`tcw-color-auto`,t===null),t!==null&&r.start&&!l?(l=document.createElement(`button`),l.type=`button`,l.className=`tcw-color-auto-btn`,l.textContent=i(`settings.auto`),l.setAttribute(`aria-label`,`${e}: ${i(`settings.auto`)}`),l.addEventListener(`click`,()=>{n(null),s.focus(),u(r.read())}),o.appendChild(l)):t===null&&l&&(l.remove(),l=null)};return s.addEventListener(`input`,()=>{n(s.value),u(s.value)}),o.append(s,c),a.appendChild(o),u(t),{row:a,sync:()=>u(r.read())}}function R(e,t,n){let r=Fn(e),i=document.createElement(`button`);return i.type=`button`,i.className=`tcw-toggle${t?` tcw-on`:``}`,i.setAttribute(`role`,`switch`),i.setAttribute(`aria-checked`,String(t)),i.setAttribute(`aria-label`,e),i.addEventListener(`click`,()=>{let e=!i.classList.contains(`tcw-on`);i.classList.toggle(`tcw-on`,e),i.setAttribute(`aria-checked`,String(e)),n(e)}),r.appendChild(i),r}function z(e,t,n,r){let i=Fn(e),a=document.createElement(`select`);a.className=`tcw-settings-select`,a.setAttribute(`aria-label`,e);for(let e of n){let n=document.createElement(`option`);n.value=e.value,n.textContent=e.label,e.value===t&&(n.selected=!0),a.appendChild(n)}return n.some(e=>e.value===t)||(a.selectedIndex=-1),a.addEventListener(`change`,()=>r(a.value)),i.appendChild(a),i}function Ln(e,t,n,r,i=e=>String(e)){let a=Fn(e),o=document.createElement(`div`);o.className=`tcw-settings-range`;let s=document.createElement(`input`);s.type=`range`,s.min=String(n.min),s.max=String(n.max),s.step=String(n.step),s.value=String(t),s.setAttribute(`aria-label`,e);let c=document.createElement(`span`);return c.className=`tcw-settings-range-val`,c.textContent=i(t),s.addEventListener(`input`,()=>{let e=Number(s.value);c.textContent=i(e),r(e)}),o.append(s,c),a.appendChild(o),a}function Rn(e,n,r){let i=new Intl.NumberFormat(r,{maximumFractionDigits:Nn}).format;return e.step===`1`&&Number.isFinite(e.max)?t.r(n(`settings.numberWhole`),{min:i(Math.max(1,e.min??1)),max:i(e.max)}):t.r(n(`settings.numberAtLeast`),{min:i(e.min??0)})}function zn(e,t,n,r,i,a=`en-US`){let o=document.createElement(`div`);o.className=`tcw-settings-row tcw-settings-row--number`;let s=document.createElement(`label`);s.className=`tcw-settings-label`,s.textContent=e,o.appendChild(s);let c=document.createElement(`input`);c.type=`number`,c.className=`tcw-settings-number`,c.min=`0`,c.step=n.step,Number.isFinite(n.max)&&(c.max=String(n.max)),c.placeholder=i(`settings.auto`),c.value=t===null?``:String(t),c.setAttribute(`aria-label`,e);let l=document.createElement(`div`);l.className=`tcw-settings-hint`,l.id=`tcw-number-hint-${++Mn}`,l.setAttribute(`role`,`status`),c.setAttribute(`aria-describedby`,l.id);let u=e=>{e?c.removeAttribute(`aria-invalid`):c.setAttribute(`aria-invalid`,`true`),l.textContent=e?``:Rn(n,i,a)};return c.addEventListener(`change`,()=>{if(c.value.trim()===``){u(!0),r(null);return}let e=Number(c.value),t=Number.isFinite(e)&&e>0&&e>=(n.min??0)&&e<=n.max&&(n.step!==`1`||Number.isInteger(e));u(t),t&&r(e)}),o.append(c,l),o}var B=[{id:`symbol`,icon:`chartType:candlestick`},{id:`statusLine`,icon:`type`},{id:`scales`,icon:`ruler`},{id:`appearance`,icon:`palette`},{id:`layers`,icon:`layers`},{id:`trading`,icon:`trendingUp`}],Bn=[1,2,3,4],Vn=`t:`,Hn={step:`any`,max:1/0,min:1e-8},Un=1,Wn=class{callbacks;t;backdrop=null;modal=null;bodyEl=null;tabButtons=[];templateBtn=null;menu=null;currentTab=`symbol`;currentSettings=null;chartType=null;lookRows=[];returnFocus=null;uid=Un++;constructor(e,t,n={},r=()=>document.body){this.available=n,this.host=r,this.callbacks=e,this.t=t}open(e,t=null,n=`symbol`){this.modal&&this.remove(),this.returnFocus=document.activeElement instanceof HTMLElement?document.activeElement:null,this.currentSettings={...e},this.chartType=t,this.currentTab=n,this.buildModal(),this.tabButtons.find(e=>e.dataset.tab===n)?.focus()}isOpen(){return this.modal!==null}refresh(e,t){if(!this.modal)return;this.currentSettings={...e},t!==void 0&&(this.chartType=t);let n=this.focusedControl();this.renderTabContent(),n!==null&&this.focusControl(n)}focusedControl(){let e=document.activeElement;if(!this.bodyEl||!(e instanceof HTMLElement)||!this.bodyEl.contains(e))return null;let t=this.panelControls().indexOf(e);return t<0?null:t}focusControl(e){let t=this.panelControls();(t[Math.min(e,t.length-1)]??this.tabButtons.find(e=>e.dataset.tab===this.currentTab))?.focus()}panelControls(){return this.bodyEl?[...this.bodyEl.querySelectorAll(bn)]:[]}close(){this.finish(!0)}destroy(){this.remove()}finish(e){this.modal&&(e?this.callbacks.onClose():this.callbacks.onCancel?.(),this.remove(),this.returnFocus?.isConnected&&this.returnFocus.focus(),this.returnFocus=null)}remove(){this.menu?.destroy(),this.menu=null,this.backdrop?.remove(),this.backdrop=this.modal=this.bodyEl=this.templateBtn=null,this.tabButtons=[]}buildModal(){let e=document.createElement(`div`);e.className=`tcw-modal-backdrop`;let t=!1;e.addEventListener(`pointerdown`,n=>{t=n.target===e}),e.addEventListener(`click`,n=>{n.target===e&&t&&this.finish(!1),t=!1});let n=document.createElement(`div`);n.className=`tcw-modal tcw-set`,n.setAttribute(`role`,`dialog`),n.setAttribute(`aria-modal`,`true`),n.setAttribute(`aria-labelledby`,`tcw-set-title-${this.uid}`),n.tabIndex=-1,n.addEventListener(`keydown`,e=>{if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),this.finish(!1);return}M(e,n)}),this.backdrop=e,this.modal=n,n.append(this.buildHeader(),this.buildBody(),this.buildFooter()),e.appendChild(n),this.host().appendChild(e),this.markTabs(),this.renderTabContent()}buildHeader(){let e=document.createElement(`div`);e.className=`tcw-modal-header`;let t=document.createElement(`h3`);t.id=`tcw-set-title-${this.uid}`,t.textContent=this.t(`settings.title`);let n=document.createElement(`button`);return n.type=`button`,n.className=`tcw-modal-close`,n.setAttribute(`aria-label`,this.t(`common.close`)),n.innerHTML=O(`x`,16),n.addEventListener(`click`,()=>this.finish(!1)),e.append(t,n),e}buildBody(){let e=document.createElement(`div`);e.className=`tcw-set-body`;let t=document.createElement(`div`);t.className=`tcw-set-nav`,t.setAttribute(`role`,`tablist`),t.setAttribute(`aria-orientation`,`vertical`),t.setAttribute(`aria-label`,this.t(`settings.title`)),t.addEventListener(`keydown`,e=>this.onTabKey(e)),this.tabButtons=B.map(({id:e,icon:t})=>{let n=document.createElement(`button`);return n.type=`button`,n.className=`tcw-set-tab`,n.id=`tcw-set-tab-${this.uid}-${e}`,n.dataset.tab=e,n.setAttribute(`role`,`tab`),n.setAttribute(`aria-controls`,`tcw-set-panel-${this.uid}`),n.innerHTML=`${t.startsWith(`chartType:`)?nt(t.slice(10),16):O(t,16)}<span></span>`,n.querySelector(`span`).textContent=this.t(`settings.tab.${e}`),n.addEventListener(`click`,()=>this.selectTab(e)),n}),t.append(...this.tabButtons);let n=document.createElement(`div`);return n.className=`tcw-modal-body tcw-set-panel`,n.id=`tcw-set-panel-${this.uid}`,n.setAttribute(`role`,`tabpanel`),this.bodyEl=n,e.append(t,n),e}buildFooter(){let e=document.createElement(`div`);e.className=`tcw-modal-footer`;let t=this.footerButton(`template`,`tcw-footer-menu`,()=>this.openTemplates());t.setAttribute(`aria-haspopup`,`menu`),t.setAttribute(`aria-expanded`,`false`),t.innerHTML=`<span></span>${O(`chevronDown`,12)}`,t.querySelector(`span`).textContent=this.t(`settings.template`),this.templateBtn=t;let n=document.createElement(`div`);return n.className=`tcw-footer-end`,n.append(this.footerButton(`cancel`,`tcw-footer-cancel`,()=>this.finish(!1),this.t(`common.cancel`)),this.footerButton(`ok`,`tcw-done-btn`,()=>this.finish(!0),this.t(`drawingSettings.ok`))),e.append(t,n),e}footerButton(e,t,n,r){let i=document.createElement(`button`);return i.type=`button`,i.className=t,i.dataset.act=e,r&&(i.textContent=r),i.addEventListener(`click`,n),i}markTabs(){for(let e of this.tabButtons){let t=e.dataset.tab===this.currentTab;e.classList.toggle(`tcw-active`,t),e.setAttribute(`aria-selected`,String(t)),e.tabIndex=t?0:-1,t&&this.bodyEl?.setAttribute(`aria-labelledby`,e.id)}}selectTab(e,t=!1){this.currentTab=e,this.markTabs(),this.renderTabContent(),t&&this.tabButtons.find(t=>t.dataset.tab===e)?.focus()}onTabKey(e){let t=B.findIndex(e=>e.id===this.currentTab),n=e.key===`ArrowDown`||e.key===`ArrowRight`?(t+1)%B.length:e.key===`ArrowUp`||e.key===`ArrowLeft`?(t-1+B.length)%B.length:e.key===`Home`?0:e.key===`End`?B.length-1:-1;n<0||(e.preventDefault(),this.selectTab(B[n].id,!0))}openTemplates(){let e=this.templateBtn;if(!this.modal||!e)return;if(this.menu?.isOpen()){this.menu.close();return}let n=this.callbacks.templates,r=(n?.list()??[]).map(e=>({id:`${Vn}${e}`,label:e,icon:`layers`,remove:t.r(this.t(`templates.delete`),{name:e})})),i=[...r,...r.length>0?[`separator`]:[],...n?[{id:`save`,label:this.t(`settings.saveTemplate`),icon:`save`}]:[],{id:`reset`,label:this.t(`settings.resetToDefaults`),icon:`reset`}];this.menu??=new A(this.modal,this.t(`settings.template`));let a=e.getBoundingClientRect(),o=this.modal.getBoundingClientRect();this.menu.open(i,a.left-o.left,a.top-o.top,e=>{e===`reset`?this.callbacks.onReset():e===`save`?n?.save():e.startsWith(Vn)&&n?.apply(e.slice(2))},e,e=>n?.remove(e.slice(2)))}renderTabContent(){if(!(!this.bodyEl||!this.currentSettings))switch(this.bodyEl.replaceChildren(),this.lookRows=[],this.currentTab){case`symbol`:this.renderSymbolTab(this.currentSettings);break;case`statusLine`:this.renderStatusLineTab(this.currentSettings);break;case`scales`:this.renderScalesTab(this.currentSettings);break;case`appearance`:this.renderAppearanceTab(this.currentSettings);break;case`layers`:this.renderLayersTab(this.currentSettings);break;case`trading`:for(let e of Ee)(!e.trading||this.available.trading!==!1)&&this.renderLookSection(e);break}}renderSymbolTab(e){this.renderChartTypeSection(),this.addSection(void 0,[R(this.t(`settings.mainSeries`),e.mainSeriesVisible,e=>this.patch({mainSeriesVisible:e})),R(this.t(`settings.extendedHours`),e.extendedHours,e=>this.patch({extendedHours:e}))]);let t=this.t(`common.show`);this.renderLookSection(ve),this.available.volume!==!1&&this.renderLookSection(ye,[R(t,e.volumeVisible,e=>this.patch({volumeVisible:e}))]),this.renderLookSection(be,[R(t,e.highLowLines,e=>this.patch({highLowLines:e}))])}renderStatusLineTab(e){let t=this.available.legend!==!1,n=t?Ce:Ce.filter(e=>!Se.includes(e));this.addSection(void 0,[...t?[R(this.t(`settings.ohlcLegend`),e.legendVisible,e=>this.patch({legendVisible:e}))]:[],...n.map(e=>this.lookRow(e))])}renderScalesTab(e){let t=[{value:`regular`,label:this.t(`settings.scale.regular`)},{value:`logarithmic`,label:this.t(`settings.scale.logarithmic`)},{value:`percentage`,label:this.t(`settings.scale.percentage`)},{value:`indexedTo100`,label:this.t(`settings.scale.indexedTo100`)}].filter(e=>e.value!==`logarithmic`||this.available.logScale!==!1),n=this.available.exchangeZone?.(),r=f(e.timezone,Date.now(),this.t(`settings.timezone.local`),n===void 0?void 0:{label:this.t(`settings.timezone.exchange`),zone:n});this.addSection(void 0,[z(this.t(`settings.priceScale`),e.scaleMode,t,e=>this.patch({scaleMode:e})),R(this.t(`settings.autoScale`),e.autoScale,e=>this.patch({autoScale:e})),R(this.t(`settings.invertScale`),e.invertScale,e=>this.patch({invertScale:e})),R(this.t(`settings.leftScale`),e.leftPriceScale,e=>this.patch({leftPriceScale:e})),R(this.t(`settings.indicatorValues`),e.indicatorValueLabels,e=>this.patch({indicatorValueLabels:e})),R(this.t(`settings.alignAxisLabels`),e.alignAxisLabels,e=>this.patch({alignAxisLabels:e})),...this.available.barCountdown===!1?[]:[R(this.t(`settings.barCountdown`),e.barCountdown,e=>this.patch({barCountdown:e}))],z(this.t(`settings.timezone`),e.timezone,r,e=>this.patch({timezone:e})),z(this.t(`settings.numberLocale`),e.numberLocale,gt(e.numberLocale),e=>this.patch({numberLocale:e}))]),this.addSection(this.t(`settings.section.axes`),we.map(e=>this.lookRow(e)))}renderAppearanceTab(e){let[t,n,r,...i]=Te;this.renderLookSection(t),this.renderLookSection(n,[R(this.t(`common.show`),e.gridVisible,e=>this.patch({gridVisible:e}))]),this.renderLookSection(r,[z(this.t(`settings.crosshairMode`),e.crosshairMode,[{label:this.t(`settings.crosshair.magnet`),value:`magnet`},{label:this.t(`settings.crosshair.normal`),value:`normal`},{label:this.t(`settings.crosshair.hidden`),value:`hidden`}],e=>this.patch({crosshairMode:e}))]);for(let e of i)this.renderLookSection(e)}renderLayersTab(e){let t=e=>`${Math.round(e*100)}%`,n=e=>this.t(e);this.addSection(void 0,[R(n(`settings.volumeProfile`),e.volumeProfileVisible,e=>this.patch({volumeProfileVisible:e}))]),this.addSection(void 0,[R(n(`settings.marketProfile`),e.marketProfileVisible,e=>this.patch({marketProfileVisible:e})),R(n(`settings.marketProfileSplit`),e.marketProfileSplit,e=>this.patch({marketProfileSplit:e})),R(n(`settings.marketProfileLetters`),e.marketProfileLetters,e=>this.patch({marketProfileLetters:e})),Ln(n(`settings.marketProfileBuckets`),e.marketProfileBuckets,{min:8,max:200,step:1},e=>this.patch({marketProfileBuckets:e})),Ln(n(`settings.marketProfileOpacity`),e.marketProfileOpacity,{min:.05,max:1,step:.05},e=>this.patch({marketProfileOpacity:e}),t)]),this.addSection(void 0,[R(n(`settings.depthHeatmap`),e.depthHeatmapVisible,e=>this.patch({depthHeatmapVisible:e})),Ln(n(`settings.depthHeatmapOpacity`),e.depthHeatmapOpacity,{min:.1,max:1,step:.05},e=>this.patch({depthHeatmapOpacity:e}),t)]),this.addSection(void 0,[R(n(`settings.swingMarkers`),e.pivotMarkersVisible,e=>this.patch({pivotMarkersVisible:e})),Ln(n(`settings.swingStrength`),e.pivotStrength,{min:2,max:20,step:1},e=>this.patch({pivotStrength:e})),R(n(`settings.swingStructure`),e.pivotStructureLabels,e=>this.patch({pivotStructureLabels:e}))]),this.addSection(void 0,[R(n(`settings.sessionShading`),e.sessionShadingVisible,e=>this.patch({sessionShadingVisible:e})),R(n(`settings.periodLevels`),e.periodLevelsVisible,e=>this.patch({periodLevelsVisible:e})),z(n(`settings.periodLevelsBasis`),e.periodLevelsPeriod,[{value:`day`,label:n(`settings.priorDay`)},{value:`week`,label:n(`settings.priorWeek`)}],e=>this.patch({periodLevelsPeriod:e}))])}addSection(e,t){let n=Pn(e);return n.append(...t),this.bodyEl?.appendChild(n),n}renderLookSection(e,t=[]){this.addSection(this.t(e.title),[...t,...e.rows.map(e=>this.lookRow(e))])}lookRow(e){let t=this.t(e.label),r=()=>this.callbacks.styleValue(e.keys[0]),i=()=>{let t=e.keys.map(e=>this.callbacks.styleValue(e));return t.every(e=>e===t[0])&&t[0]!==null?String(t[0]):``},a,o=t=>{this.callbacks.onStyleChange(Object.fromEntries(e.keys.map(e=>[e,t])));for(let e of this.lookRows)e.el!==a&&e.sync()},s=e.auto?[{value:``,label:this.t(`settings.auto`)}]:[],c;switch(n.CHART_STYLE_KEYS[e.keys[0]]){case`boolean`:{a=R(t,r()===!0,o);let e=a.querySelector(`button`);c=()=>{let t=r()===!0;e.classList.toggle(`tcw-on`,t),e.setAttribute(`aria-checked`,String(t))};break}case`lineStyle`:a=z(t,i(),[...s,...this.lineStyles()],e=>o(e===``?null:Kn(e))),c=()=>{a.querySelector(`select`).value=i()};break;case`width`:{let e=r(),n=typeof e==`number`&&!Bn.includes(e)?[...Bn,e].sort((e,t)=>e-t):Bn;a=z(t,i(),[...s,...n.map(e=>({value:String(e),label:`${e}px`}))],e=>o(e===``?null:Number(e))),c=()=>{a.querySelector(`select`).value=i()};break}default:{let n=r(),i=In(t,typeof n==`string`?n:null,o,{read:()=>{let e=r();return typeof e==`string`?e:null},start:e.auto?()=>(e.auto?.from?this.callbacks.styleValue(e.auto.from):e.auto?.hint)??null:void 0},this.t);a=i.row,c=i.sync}}return this.lookRows.push({el:a,sync:c}),a}lineStyles(){return[{value:`solid`,label:this.t(`drawingSettings.lineStyle.solid`)},{value:`dashed`,label:this.t(`drawingSettings.lineStyle.dashed`)},{value:`dotted`,label:this.t(`drawingSettings.lineStyle.dotted`)}]}renderChartTypeSection(){if(!this.bodyEl||!this.currentSettings||!this.chartType)return;let e=this.chartType,t=this.currentSettings.chartTypeOptions??{},n=pe.find(t=>t.value===e),r=Pn(n?vt(n,this.t):e),i=()=>this.currentSettings?.chartTypeOptions??{},a=(e,t)=>this.patch({chartTypeOptions:{...i(),[e]:t}}),o=(e,t,n,i)=>r.appendChild(zn(this.t(e),t,n,i,this.t,this.currentSettings?.numberLocale||void 0));switch(e){case`renko`:{let e=t.renko??{};o(`settings.boxSize`,typeof e.boxSize==`number`?e.boxSize:null,Hn,e=>a(`renko`,{...i().renko??{},boxSize:e??`atr`})),o(`settings.atrPeriod`,e.atrPeriod??null,{step:`1`,max:500},e=>a(`renko`,Gn(i().renko,`atrPeriod`,e)));break}case`lineBreak`:o(`settings.lineBreakLines`,t.lineBreak?.lines??null,{step:`1`,max:10},e=>a(`lineBreak`,Gn(i().lineBreak,`lines`,e)));break;case`kagi`:o(`settings.reversal`,t.kagi?.reversal??null,Hn,e=>a(`kagi`,Gn(i().kagi,`reversal`,e))),r.appendChild(z(this.t(`settings.reversalType`),t.kagi?.reversalType??`percent`,[{value:`percent`,label:this.t(`settings.reversalType.percent`)},{value:`price`,label:this.t(`settings.reversalType.price`)}],e=>a(`kagi`,{...i().kagi??{},reversalType:e===`price`?`price`:`percent`})));break;case`pointAndFigure`:o(`settings.boxSize`,typeof t.pointAndFigure?.boxSize==`number`?t.pointAndFigure.boxSize:null,Hn,e=>a(`pointAndFigure`,{...i().pointAndFigure??{},boxSize:e??`auto`})),o(`settings.reversalBoxes`,t.pointAndFigure?.reversal??null,{step:`1`,max:10},e=>a(`pointAndFigure`,Gn(i().pointAndFigure,`reversal`,e)));break;case`rangeBars`:o(`settings.barRange`,typeof t.rangeBars?.range==`number`?t.rangeBars.range:null,Hn,e=>a(`rangeBars`,{range:e??`auto`}));break;default:break}for(let t of ke(e))r.appendChild(this.lookRow(t));this.bodyEl.appendChild(r)}patch(e){this.currentSettings&&Object.assign(this.currentSettings,e),this.callbacks.onChange(e)}};function Gn(e,t,n){let r={...e??{}};return n===null?delete r[t]:r[t]=n,r}function Kn(e){return e===`dashed`||e===`dotted`?e:`solid`}var qn=`data-tcw-folded`,Jn=`tcw-statusbar--folded`,Yn=`tcw-statusbar--short-market`,Xn=1,Zn=13,Qn=`goto`,$n=`Alt+G`,er=e=>e.goToKeys?e.goToKeys():$n;function tr(e,t){let n=document.createElement(`span`);return n.className=e,n.textContent=t,n}var nr=class{el;dotEl;messageEl;marketEl;hostLeft;hostRight;clockBtn=null;clockMenu=null;scaleBtns=null;scaleShown=``;marketShown=``;rightEl;rangeEl=null;presetBtns=[];moreBtn=null;goToBtn=null;rangeMenu=null;resizeObserver=null;fitFrame=0;destroyed=!1;constructor(e,t,n={}){this.host=e,this.extras=n,this.el=document.createElement(`div`),this.el.className=`tcw-statusbar`,D(this.el,`statusBar`),n.label&&(this.el.setAttribute(`role`,`group`),this.el.setAttribute(`aria-label`,n.label)),t&&this.el.appendChild(this.buildRange(t)),this.hostLeft=this.hostGroup(),this.el.appendChild(this.hostLeft);let r=document.createElement(`div`);r.className=`tcw-status-right`,this.rightEl=r,this.hostRight=this.hostGroup(),r.appendChild(this.hostRight);let i=document.createElement(`div`);i.className=`tcw-status-indicator`,D(i,`statusBar.connection`),this.dotEl=document.createElement(`span`),this.dotEl.className=`tcw-status-dot`,i.appendChild(this.dotEl),this.messageEl=document.createElement(`span`),i.appendChild(this.messageEl),this.marketEl=document.createElement(`span`),this.marketEl.className=`tcw-status-market`,this.marketEl.hidden=!0,D(this.marketEl,`statusBar.market`),r.appendChild(this.marketEl),r.appendChild(i),n.clock&&r.appendChild(this.buildClock(n.clock)),n.scale&&r.appendChild(this.buildScale(n.scale)),this.el.appendChild(r),e.appendChild(this.el),this.watchWidths(r)}watchWidths(e){if(typeof ResizeObserver<`u`){this.resizeObserver=new ResizeObserver(()=>this.scheduleFit());for(let t of[this.el,e,this.hostLeft])this.resizeObserver.observe(t)}document.fonts?.ready.then(()=>this.scheduleFit())}scheduleFit(){this.destroyed||this.fitFrame||typeof requestAnimationFrame>`u`||(this.fitFrame=requestAnimationFrame(()=>{this.fitFrame=0,this.destroyed||this.fit()}))}fit(){let e=this.foldedCount(),t=this.rangeFocus();this.refit(),this.foldedCount()!==e&&this.rangeMenu?.close(),this.keepFocus(t)}refit(){let e=this.foldSteps(),t=this.goToBtn?[...this.presetBtns,this.goToBtn]:this.presetBtns,n=n=>{let r=new Set(e.slice(0,n));for(let e of t)e.toggleAttribute(qn,r.has(e));this.el.classList.toggle(Jn,n>0)};if(n(0),this.el.classList.remove(Yn),this.el.clientWidth===0||this.fits())return;let r=0;for(;r<e.length;)if(n(++r),this.fits())return;if(!(this.marketEl.hidden||this.isOff(this.marketEl))){for(this.el.classList.add(Yn);r>0;r--)if(n(r-1),!this.fits()){n(r);return}}}fits(){return this.rangeFits()&&this.rightFits()}rangeFits(){let e=this.rangeEl;return!e||e.scrollWidth<=e.clientWidth+Xn}rightFits(){if(this.rightEl.offsetParent!==this.el)return!0;let e=getComputedStyle(this.el),t=this.rightEl.offsetLeft;return(e.direction===`rtl`?(parseFloat(e.paddingLeft)||0)-t:t+this.rightEl.offsetWidth-(this.el.clientWidth-(parseFloat(e.paddingRight)||0)))<=Xn}foldedCount(){return this.rangeEl?.querySelectorAll(`[${qn}]`).length??0}rangeFocus(){if(this.rangeMenu?.hasFocus())return this.moreBtn;let e=document.activeElement;return e instanceof HTMLElement&&this.rangeEl?.contains(e)?e:null}keepFocus(e){if(!e||this.rangeMenu?.isOpen())return;let t=this.focusAfterRefit(e);t===this.el?this.focusBar():document.activeElement!==t&&t.focus({preventScroll:!0})}focusAfterRefit(e){if(this.shows(e))return e;let t=this.presetBtns.filter(e=>this.shows(e)).at(-1);return[e===this.moreBtn?null:this.moreBtn,this.goToBtn,t].find(e=>e!=null&&this.shows(e))??this.firstOtherControl()??this.el}firstOtherControl(){return[...this.el.querySelectorAll(`button`)].filter(e=>!this.rangeEl?.contains(e)).find(e=>!e.disabled&&e.getClientRects().length>0)??null}focusBar(){if(document.activeElement===this.el)return;let e=()=>this.el.removeAttribute(`tabindex`);this.el.tabIndex=-1,this.el.addEventListener(`blur`,e,{once:!0}),this.el.focus({preventScroll:!0}),document.activeElement!==this.el&&(this.el.removeEventListener(`blur`,e),e())}shows(e){return e===this.moreBtn&&!this.el.classList.contains(Jn)?!1:!e.hasAttribute(qn)&&!this.isOff(e)}foldSteps(){if(this.presetBtns.length===0||this.isOff(this.presetBtns[0]))return[];let e=[...this.presetBtns].reverse();return this.goToBtn&&e.push(this.goToBtn),e}isOff(e){let t=((this.el.closest(`.tcw-root`)??this.host).getAttribute(`data-tcw-off`)??``).split(/\s+/).filter(Boolean);return(e.dataset.tcwPart??``).split(/\s+/).some(e=>t.includes(e))}update(e){this.dotEl.className=`tcw-status-dot`,e.connectionState===`connected`?this.dotEl.classList.add(`tcw-connected`):e.connectionState===`error`&&this.dotEl.classList.add(`tcw-error`),this.messageEl.textContent=e.message}tick(){if(!this.clockBtn||!this.extras.clock)return;let{time:e,zone:t}=this.extras.clock.now(),n=`${e} ${t}`;this.clockBtn.textContent!==n&&(this.clockBtn.textContent=n)}setScale(e){let t=`${e.mode}|${e.auto}`;!this.scaleBtns||t===this.scaleShown||(this.scaleShown=t,this.scaleBtns.percent?.setAttribute(`aria-pressed`,String(e.mode===`percentage`)),this.scaleBtns.log?.setAttribute(`aria-pressed`,String(e.mode===`logarithmic`)),this.scaleBtns.auto?.setAttribute(`aria-pressed`,String(e.auto)))}setMarket(e,t,n=t){let r=`${e}|${t}|${n}`;if(r===this.marketShown)return;if(this.marketShown=r,this.marketEl.hidden=e===`always`,this.marketEl.dataset.state=e,e===`always`){this.marketEl.replaceChildren(),this.marketEl.removeAttribute(`title`);return}this.marketEl.title=t;let i=tr(`tcw-status-market-short`,n);i.setAttribute(`aria-hidden`,`true`),this.marketEl.replaceChildren(tr(`tcw-status-market-text`,t),i)}addHostItem(e){let t=e.onClick,n=t?document.createElement(`button`):document.createElement(`span`);return n.className=t?`tcw-status-host-item tcw-status-host-btn`:`tcw-status-host-item`,n.dataset.hostItem=e.id,n.dir=`auto`,n.textContent=e.text,e.label&&(n.title=e.label,t||n.setAttribute(`role`,`group`),e.label!==e.text&&n.setAttribute(`aria-label`,`${e.label}: ${e.text}`)),n instanceof HTMLButtonElement&&t&&(n.type=`button`,n.addEventListener(`click`,()=>t(n))),(e.side===`left`?this.hostLeft:this.hostRight).appendChild(n),n}hostSlot(e){return e===`left`?this.hostLeft:this.hostRight}destroy(){this.destroyed=!0,this.resizeObserver?.disconnect(),this.fitFrame&&cancelAnimationFrame(this.fitFrame),this.clockMenu?.destroy(),this.rangeMenu?.destroy(),this.el.remove()}buildClock(e){let t=document.createElement(`button`);return t.type=`button`,t.className=`tcw-status-clock`,t.dataset.role=`clock`,t.dir=`auto`,t.title=e.label,t.setAttribute(`aria-haspopup`,`menu`),D(t,`statusBar.clock`),t.addEventListener(`click`,()=>this.toggleZones(t,e)),this.clockBtn=t,this.tick(),t}toggleRangeMenu(e,t){if(this.rangeMenu?.isOpen()){this.rangeMenu.close();return}let n=e=>e.hasAttribute(qn)&&!this.isOff(e),r=t.presets.filter((e,t)=>n(this.presetBtns[t])).map(e=>({id:e,label:t.presetLabels?.[e]??e}));if(this.goToBtn&&n(this.goToBtn)&&(r.length>0&&r.push(`separator`),r.push({id:Qn,label:t.goToLabel,icon:`calendar`,shortcut:er(t)})),r.length===0)return;this.rangeMenu??=new A(this.host,t.groupLabel);let i=e.getBoundingClientRect(),a=this.host.getBoundingClientRect();this.rangeMenu.open(r,i.left-a.left,i.top-a.top,e=>e===Qn?t.onGoTo():t.onPreset(e),e,void 0,i.right-a.left)}toggleZones(e,t){if(this.clockMenu?.isOpen()){this.clockMenu.close();return}let{current:n,list:r}=t.options();this.clockMenu??=new A(this.host,t.label);let i=e.getBoundingClientRect(),a=this.host.getBoundingClientRect();this.clockMenu.open(r.map(e=>({id:e.value,label:e.label,checked:e.value===n})),i.left-a.left,i.top-a.top,e=>t.onPick(e),e,void 0,i.right-a.left)}buildScale(e){let t=document.createElement(`div`);t.className=`tcw-status-scale`,t.setAttribute(`role`,`group`),e.labels.group&&t.setAttribute(`aria-label`,e.labels.group),D(t,`statusBar.scale`);let n=(n,r,i)=>{let a=document.createElement(`button`);return a.type=`button`,a.className=`tcw-status-scale-btn`,a.dataset.scale=n,a.textContent=r,a.title=e.labels[n],a.setAttribute(`aria-label`,e.labels[n]),a.setAttribute(`aria-pressed`,`false`),a.addEventListener(`click`,i),t.appendChild(a),a};return this.scaleBtns={percent:n(`percent`,`%`,e.onPercent),...e.onLog?{log:n(`log`,e.texts?.log??`log`,e.onLog)}:{},auto:n(`auto`,e.texts?.auto??`auto`,e.onAuto)},t}hostGroup(){let e=document.createElement(`div`);return e.className=`tcw-status-host`,e}buildRange(e){let t=document.createElement(`div`);t.className=`tcw-range-bar`,t.setAttribute(`role`,`group`),t.setAttribute(`aria-label`,e.groupLabel);for(let n of e.presets){let r=document.createElement(`button`);r.type=`button`,r.className=`tcw-range-btn`,r.dataset.range=n,D(r,`statusBar.range`),r.textContent=e.presetLabels?.[n]??n,r.addEventListener(`click`,()=>e.onPreset(n)),t.appendChild(r),this.presetBtns.push(r)}let n=this.rangeIconBtn(`tcw-range-more`,`rangeMore`,`more`,e.moreLabel);D(n,`statusBar.range`),n.setAttribute(`aria-haspopup`,`menu`),n.setAttribute(`aria-expanded`,`false`),n.addEventListener(`click`,()=>this.toggleRangeMenu(n,e)),t.appendChild(n),this.moreBtn=n;let r=this.rangeIconBtn(`tcw-range-goto`,`goto`,`calendar`,e.goToLabel);D(r,`goToDate`,`statusBar.goToDate`);let i=()=>{let t=er(e);r.title=t?`${e.goToLabel} (${t})`:e.goToLabel};return i(),r.addEventListener(`pointerover`,i),r.addEventListener(`focusin`,i),r.addEventListener(`click`,e.onGoTo),t.appendChild(r),this.goToBtn=r,this.rangeEl=t,t}rangeIconBtn(e,t,n,r){let i=document.createElement(`button`);return i.type=`button`,i.className=`tcw-range-btn ${e}`,i.dataset.role=t,i.title=r,i.setAttribute(`aria-label`,r),i.innerHTML=O(n,Zn),i}},rr=typeof navigator<`u`&&/mac|iphone|ipad|ipod/i.test(navigator.platform||navigator.userAgent)?`⌘`:`Ctrl`,ir=e=>e.toLowerCase().replace(/[\s+]+/g,``).replace(/[\u2010-\u2015\u2212]/g,`-`),ar=5,or=229,sr=[`action`,`drawing`,`chartType`,`timeframe`,`indicator`],cr={indicator:`palette.group.indicator`,chartType:`palette.group.chartType`,drawing:`palette.group.drawing`,timeframe:`palette.group.timeframe`,action:`palette.group.action`},lr=e=>`${e.category}:${e.id}`;function ur(e,t){let n=e.label.toLowerCase(),r=ir(n);return e.id.toLowerCase()===t||r===t?5:r.startsWith(t)?4:n.split(/[\s/()-]+/).some(e=>e.startsWith(t))?3:r.includes(t)||e.id.toLowerCase().includes(t)?2:e.shortcut&&ir(e.shortcut).includes(t)?1:0}var dr=0,fr=class{backdrop=null;input=null;list=null;emptyEl=null;liveEl=null;items=[];shown=[];selectedIndex=0;returnFocus=null;uid=++dr;constructor(e,n=()=>document.body,r=t.t,i){this.callbacks=e,this.host=n,this.t=r,this.recents=i}open(e){this.backdrop||(this.returnFocus=document.activeElement instanceof HTMLElement?document.activeElement:null,this.items=e,this.build(),this.render(),this.input?.focus())}close(){if(!this.backdrop)return;this.backdrop.remove(),this.backdrop=this.input=this.list=this.emptyEl=this.liveEl=null,this.callbacks.onClose();let e=this.returnFocus;this.returnFocus=null,e?.isConnected&&e.focus()}isOpen(){return this.backdrop!==null}destroy(){this.close()}build(){let e=document.createElement(`div`);e.className=`tcw-modal-backdrop`;let t=!1;e.addEventListener(`pointerdown`,n=>{t=n.target===e}),e.addEventListener(`click`,n=>{n.target===e&&t&&this.close(),t=!1});let n=document.createElement(`div`);n.className=`tcw-modal tcw-cp`,n.setAttribute(`role`,`dialog`),n.setAttribute(`aria-modal`,`true`),n.setAttribute(`aria-label`,this.t(`hotkeys.commandPalette`)),n.tabIndex=-1,n.addEventListener(`keydown`,e=>this.onKeyDown(e,n));let r=document.createElement(`label`);r.className=`tcw-ss-search tcw-cp-search`,r.innerHTML=O(`search`,16);let i=document.createElement(`input`);i.type=`search`,i.className=`tcw-cp-input`,i.placeholder=this.t(`palette.placeholder`),i.setAttribute(`aria-label`,this.t(`palette.placeholder`)),i.setAttribute(`role`,`combobox`),i.setAttribute(`aria-expanded`,`true`),i.setAttribute(`aria-autocomplete`,`list`),i.setAttribute(`aria-controls`,`tcw-cp-list-${this.uid}`),i.autocomplete=`off`,i.spellcheck=!1,i.addEventListener(`input`,()=>this.render()),r.appendChild(i);let a=document.createElement(`div`);a.className=`tcw-cp-results`;let o=document.createElement(`div`);o.className=`tcw-cp-list`,o.id=`tcw-cp-list-${this.uid}`,o.setAttribute(`role`,`listbox`),o.setAttribute(`aria-label`,this.t(`hotkeys.commandPalette`));let s=document.createElement(`div`);s.className=`tcw-cp-empty`,a.append(o,s),a.addEventListener(`mousedown`,e=>e.preventDefault());let c=document.createElement(`div`);c.className=`tcw-cp-live tcw-visually-hidden`,c.setAttribute(`aria-live`,`polite`),n.append(r,a,c),e.appendChild(n),this.host().appendChild(e),this.backdrop=e,this.input=i,this.list=o,this.emptyEl=s,this.liveEl=c}groups(){let e=ir((this.input?.value??``).trim()),t=[];if(!e){let e=new Map(this.items.map(e=>[lr(e),e])),n=(this.recents?.list()??[]).map(t=>e.get(t)).filter(e=>!!e).slice(0,ar);n.length>0&&t.push({key:`recent`,label:this.t(`palette.group.recent`),items:n})}for(let n of sr){let r=this.items.filter(e=>e.category===n);e&&(r=r.map((t,n)=>({item:t,at:n,s:ur(t,e)})).filter(e=>e.s>0).sort((e,t)=>t.s-e.s||e.at-t.at).map(e=>e.item)),r.length>0&&t.push({key:n,label:this.t(cr[n]),items:r})}return e&&t.sort((t,n)=>ur(n.items[0],e)-ur(t.items[0],e)),t}render(){let e=this.list;if(!e)return;let t=this.groups();this.shown=t.flatMap(e=>e.items),this.selectedIndex=0;let n=0;e.replaceChildren(...t.map(e=>{let t=document.createElement(`div`);t.setAttribute(`role`,`group`),t.className=`tcw-cp-group`;let r=document.createElement(`div`);return r.className=`tcw-cp-heading`,r.id=`tcw-cp-${e.key}-${this.uid}`,r.setAttribute(`role`,`presentation`),r.textContent=e.label,t.setAttribute(`aria-labelledby`,r.id),t.append(r,...e.items.map(e=>this.row(e,n++))),t}));let r=this.shown.length===0?this.t(`palette.empty`):``;this.emptyEl&&(this.emptyEl.textContent=r),this.emptyEl?.toggleAttribute(`hidden`,this.shown.length>0),this.liveEl&&(this.liveEl.textContent=r),this.markSelection()}row(e,t){let n=document.createElement(`div`);n.className=`tcw-cp-row`,n.id=`tcw-cp-opt-${this.uid}-${t}`,n.dataset.id=e.id,n.setAttribute(`role`,`option`),n.classList.toggle(`tcw-on`,!!e.active);let r=document.createElement(`span`);if(r.className=`tcw-cp-label`,r.textContent=e.label,n.appendChild(r),e.shortcut){let t=document.createElement(`kbd`);t.className=`tcw-cp-key`,t.dir=`ltr`,t.textContent=e.shortcut,n.appendChild(t)}if(e.active){let e=document.createElement(`span`);e.className=`tcw-cp-check`,e.innerHTML=O(`check`,14),n.appendChild(e)}return n.addEventListener(`click`,()=>this.run(t)),n.addEventListener(`mousemove`,()=>{this.selectedIndex!==t&&(this.selectedIndex=t,this.markSelection())}),n}markSelection(){let e=this.list?.querySelectorAll(`.tcw-cp-row`)??[],t=null;e.forEach((e,n)=>{let r=n===this.selectedIndex;e.setAttribute(`aria-selected`,String(r)),e.classList.toggle(`tcw-selected`,r),r&&(t=e)});let n=t;n?(this.input?.setAttribute(`aria-activedescendant`,n.id),n.scrollIntoView?.({block:`nearest`})):this.input?.removeAttribute(`aria-activedescendant`)}run(e){let t=this.shown[e];if(t)switch(this.recents?.add(lr(t)),this.close(),t.category){case`indicator`:this.callbacks.onIndicator(t.id);break;case`chartType`:this.callbacks.onChartType(t.id);break;case`drawing`:this.callbacks.onDrawingTool(t.id);break;case`timeframe`:this.callbacks.onTimeframe(t.id);break;case`action`:this.callbacks.onAction(t.id);break}}onKeyDown(e,t){if(e.stopPropagation(),e.isComposing||e.keyCode===or)return;let n=(e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`k`;if(e.key===`Escape`||n){e.preventDefault(),this.close();return}if(M(e,t),e.target!==this.input)return;let r=this.shown.length;if(e.key===`ArrowDown`||e.key===`ArrowUp`){if(e.preventDefault(),r===0)return;this.selectedIndex=(this.selectedIndex+(e.key===`ArrowDown`?1:-1)+r)%r,this.markSelection()}else e.key===`Enter`&&(e.preventDefault(),e.repeat||this.run(this.selectedIndex))}},pr=20,mr=1e3,hr=new Set,gr={stock:1,stocks:1,equity:1,share:1,shares:1,"cổ phiếu":1,株式:1,株:1,股票:1,주식:1,futures:2,future:2,derivative:2,derivatives:2,option:2,options:2,"phái sinh":2,先物:2,期货:2,期貨:2,선물:2,warrant:2,warrants:2,"covered warrant":2,"chứng quyền":2,index:3,indices:3,"chỉ số":3,指数:3,指數:3,지수:3,fund:3,funds:3,etf:3,etfs:3,"chứng chỉ quỹ":3,crypto:4,cryptocurrency:4,perpetual:4,perpetuals:4,perp:4,perps:4,"tiền mã hóa":4,"tiền mã hoá":4,"tiền điện tử":4,暗号資産:4,仮想通貨:4,加密货币:4,加密貨幣:4,数字货币:4,數字貨幣:4,虚拟货币:4,虛擬貨幣:4,암호화폐:4,가상자산:4,가상화폐:4,forex:5,fx:5,currency:5,"ngoại hối":5,為替:5,外国為替:5,外汇:5,外匯:5,외환:5,bond:5,bonds:5,"trái phiếu":5},_r=1e3,vr=new Map,yr=/i\u0307|\u0131/g;function br(e){if(typeof e!=`string`)return``;let t=vr.get(e);return t===void 0&&(t=e.trim().normalize(`NFC`).toLowerCase().replace(yr,`i`),vr.size>=_r&&vr.clear(),vr.set(e,t)),t}function xr(e){let t=br(e);return t?Object.prototype.hasOwnProperty.call(gr,t)?gr[t]:1+Sr(t)%5:0}function Sr(e){let t=2166136261;for(let n of e)t^=n.codePointAt(0),t=Math.imul(t,16777619)>>>0;return t}function Cr(e){let{ticker:t}=Qt(e),n=/[\p{L}\p{N}]/u.exec(t);return n?n[0].toUpperCase():``}function wr(e,t){let n=rn(t?.logo);if(!n||hr.has(n))return Er(e,t);let r=document.createElement(`img`);return r.className=`tcw-ss-badge`,r.alt=``,r.width=pr,r.height=pr,r.draggable=!1,r.setAttribute(`aria-hidden`,`true`),r.setAttribute(`loading`,`lazy`),r.setAttribute(`decoding`,`async`),r.setAttribute(`referrerpolicy`,`no-referrer`),r.addEventListener(`error`,()=>{Tr(n),r.replaceWith(Er(e,t))},{once:!0}),r.src=n,r}function Tr(e){hr.size>=mr&&hr.clear(),hr.add(e)}function Er(e,t){let n=document.createElement(`span`);return n.className=`tcw-ss-badge`,n.setAttribute(`aria-hidden`,`true`),n.dataset.kind=String(xr(t?.type)),n.textContent=Cr(e),n}var Dr=180,Or=150,kr=50;function Ar(e){return{upper:e.toUpperCase(),folded:Pr(e)}}function jr(e,t,n){return Math.max(Mr(e.toUpperCase(),n.upper),Nr(t,n.folded))}function Mr(e,t){if(e===t)return 1e3;if(e.startsWith(t))return 500+(50-Math.min(50,e.length-t.length));if(e.includes(t))return 200+(50-Math.min(50,e.length-t.length));let n=0,r=-1,i=0;for(let a=0;a<e.length&&n<t.length;a++)e[a]===t[n]&&(r>=0&&(i+=a-r-1),r=a,n++);return n<t.length?0:100-Math.min(99,i)}function Nr(e,t){if(!e||!t)return 0;if(e.startsWith(t))return Dr;let n=e.indexOf(t);return n<0?0:Or-Math.min(kr,n)}function Pr(e){return e.normalize(`NFD`).replace(/\p{M}+/gu,``).replace(/[đĐ]/g,`D`).toUpperCase()}function Fr(e,t,n=0,r=e.length){let i=t?Ir(e.toUpperCase(),t):new Set,a=``;for(let t=n;t<r;t++)a+=i.has(t)?`<mark>${k(e[t])}</mark>`:k(e[t]);return a}function Ir(e,t){let n=new Set,r=e.indexOf(t);if(r>=0){for(let e=r;e<r+t.length;e++)n.add(e);return n}let i=0;for(let r=0;r<e.length&&i<t.length;r++)e[r]===t[i]&&(n.add(r),i++);return i<t.length?new Set:n}function Lr(e,t){let n=document.createElement(`span`);n.className=`tcw-ss-symbol`,n.dir=`ltr`;let{venue:r}=Qt(e),i=(n,r,i)=>{let a=document.createElement(`span`);return a.className=n,a.innerHTML=Fr(e,t,r,i),a};return r&&n.appendChild(i(`tcw-ss-venue`,0,r.length)),n.appendChild(i(`tcw-ss-ticker`,r.length,e.length)),n}var Rr=br,zr=2,Br=1,Vr=class{el;kindsEl;exchangeEl;kinds=new Map;exchanges=new Map;kind=null;exchange=null;resize;constructor(e,t){this.t=e,this.onChange=t,this.el=document.createElement(`div`),this.el.className=`tcw-ss-filters`,this.el.hidden=!0,this.kindsEl=document.createElement(`div`),this.kindsEl.className=`tcw-ss-kinds`,this.kindsEl.setAttribute(`role`,`group`),this.kindsEl.setAttribute(`aria-label`,e(`symbolSearch.kinds`)),this.kindsEl.hidden=!0,this.kindsEl.addEventListener(`scroll`,()=>this.markMore(),{passive:!0}),this.resize=typeof ResizeObserver>`u`?null:new ResizeObserver(()=>this.markMore()),this.resize?.observe(this.kindsEl),this.exchangeEl=document.createElement(`select`),this.exchangeEl.className=`tcw-settings-select tcw-ss-exchange-filter`,this.exchangeEl.setAttribute(`aria-label`,e(`symbolSearch.exchange`)),this.exchangeEl.hidden=!0,this.exchangeEl.addEventListener(`change`,()=>{this.exchange=Rr(this.exchangeEl.value)||null,this.onChange(!1)}),this.el.append(this.kindsEl,this.exchangeEl)}see(e){let t=this.kinds.size,n=this.exchanges.size;for(let t of e)Hr(this.kinds,t?.type),Hr(this.exchanges,t?.exchange);this.kinds.size!==t&&this.renderKinds(),this.exchanges.size!==n&&this.renderExchanges(),this.kindsEl.hidden=this.kinds.size===0,this.exchangeEl.hidden=this.exchanges.size<zr,this.el.hidden=this.kindsEl.hidden&&this.exchangeEl.hidden,this.markMore()}destroy(){this.resize?.disconnect()}markMore(){let e=this.kindsEl,t=Math.abs(e.scrollLeft),n=e.scrollWidth-e.clientWidth,r=[t>Br?`start`:``,t<n-Br?`end`:``].filter(Boolean);r.length>0?e.dataset.more=r.join(` `):delete e.dataset.more}passes(e,t){return Ur(this.kind,Rr(e?.type),t)&&Ur(this.exchange,Rr(e?.exchange),t)}renderKinds(){let e=(e,t)=>{let n=document.createElement(`button`);return n.type=`button`,n.className=`tcw-ss-type`,n.textContent=t,e!==null&&(n.dir=`auto`),n.setAttribute(`aria-pressed`,String(this.kind===e)),n.addEventListener(`click`,()=>{this.kind=e;for(let e of this.kindsEl.children)e.setAttribute(`aria-pressed`,String(e===n));this.onChange(!0)}),n},t=[...this.kinds].map(([t,n])=>e(t,n));this.kindsEl.replaceChildren(e(null,this.t(`symbolSearch.allKinds`)),...t)}renderExchanges(){let e=(e,t)=>{let n=document.createElement(`option`);return n.value=e,n.textContent=t,e&&(n.dir=`auto`),n},t=[...this.exchanges.values()].map(t=>e(t,t));this.exchangeEl.replaceChildren(e(``,this.t(`symbolSearch.allExchanges`)),...t),this.exchangeEl.value=this.exchange===null?``:this.exchanges.get(this.exchange)??``}};function Hr(e,t){let n=Rr(t);n&&!e.has(n)&&e.set(n,t.trim())}function Ur(e,t,n){return e===null||t===e||n&&t===``}var Wr=229,Gr=1,Kr=class{backdrop=null;input=null;list=null;results=null;live=null;columns=null;filters=null;mode=null;given=[];rows=[];rowsGiven=!1;shown=[];compared=[];way=``;selectedIndex=0;searchFn=null;searchTimer=null;searchAbort=null;status=`idle`;pickOnResults=!1;heard=new Map;givenInfo=new Map;foldedNames=new Map;returnFocus=null;uid=Gr++;constructor(e,n=()=>document.body,r=t.t){this.callbacks=e,this.host=n,this.t=r}open(e){this.begin({kind:`search`,start:e})}openCompare(e){this.compared=e.compared,this.way=e.ways.some(t=>t.id===e.way)?e.way:e.ways[0]?.id??``,this.begin({kind:`compare`,start:e})}setCompared(e){if(this.compared=e,this.mode?.kind!==`compare`||!this.results)return;let t=this.results.contains(document.activeElement);this.renderList(),t&&!this.results.contains(document.activeElement)&&this.input?.focus()}close(){if(!this.backdrop)return;this.cancelSearch(),this.pickOnResults=!1,this.searchFn=null,this.backdrop.remove(),this.backdrop=this.input=this.list=this.results=this.live=this.columns=null,this.filters?.destroy(),this.filters=null,this.mode=null,this.callbacks.onClose();let e=this.returnFocus;this.returnFocus=null,e?.isConnected&&e.focus()}isOpen(){return this.backdrop!==null}isComparing(){return this.mode?.kind===`compare`}destroy(){this.close()}begin(e){this.backdrop&&this.close(),this.returnFocus=document.activeElement instanceof HTMLElement?document.activeElement:null,this.mode=e,this.searchFn=e.start.search??null,this.status=`idle`,this.learnGiven(e),this.build(e);let t=e.kind===`search`?e.start.query??``:``;this.input&&(this.input.value=t),t?(this.filter(),this.searchFn&&this.searchNow()):this.listGiven(),this.input?.focus()}learnGiven(e){let t=Jt(e.start.symbols);this.given=t.names,this.givenInfo=t.info,this.foldedNames=new Map;let n=e.start.current,r=e.kind===`search`?e.start.currentInfo:null;if(r&&typeof r==`object`&&n){let{description:e,logo:t}=Yt(r,n);this.givenInfo.set(n,Zt({symbol:n,description:e,logo:t},this.givenInfo.get(n)))}}infoOf(e){return Zt(this.givenInfo.get(e),this.heard.get(e))}build(e){let t=document.createElement(`div`);t.className=`tcw-modal-backdrop`;let n=!1;t.addEventListener(`pointerdown`,e=>{n=e.target===t}),t.addEventListener(`click`,e=>{e.target===t&&n&&this.close(),n=!1});let r=document.createElement(`div`);r.className=`tcw-modal tcw-ss${e.kind===`compare`?` tcw-ss--compare`:``}`,D(r,e.kind===`compare`?`compare`:`symbolSearch`),r.setAttribute(`role`,`dialog`),r.setAttribute(`aria-modal`,`true`),r.setAttribute(`aria-labelledby`,`tcw-ss-title-${this.uid}`),r.tabIndex=-1,r.addEventListener(`keydown`,e=>this.onKeyDown(e,r)),r.append(this.buildHeader(e),this.buildSearch()),e.kind===`compare`&&r.appendChild(this.buildWay(e.start));let i=new Vr(this.t,e=>{this.afterResults(!1),e&&this.input?.focus()}),a=document.createElement(`div`);a.className=`tcw-ss-list`,a.id=`tcw-ss-list-${this.uid}`,a.setAttribute(`role`,`listbox`);let o=document.createElement(`div`);o.className=`tcw-ss-results`;let s=this.buildColumns();o.append(s,a),o.addEventListener(`mousedown`,e=>{e.target.closest(`button`)||e.preventDefault()});let c=document.createElement(`div`);c.className=`tcw-ss-live tcw-visually-hidden`,c.setAttribute(`aria-live`,`polite`),r.append(i.el,o,c);let l=e.kind===`search`?e.start.hint:void 0;if(l){let e=document.createElement(`div`);e.className=`tcw-ss-foot`,e.textContent=l,r.appendChild(e)}t.appendChild(r),this.host().appendChild(t),this.backdrop=t,this.filters=i,this.columns=s,this.list=a,this.results=o,this.live=c}buildColumns(){let e=document.createElement(`div`);e.className=`tcw-ss-columns`,e.setAttribute(`aria-hidden`,`true`);let t=[``,this.t(`symbolSearch.symbol`),this.t(`symbolSearch.description`),this.t(`symbolSearch.type`),this.t(`symbolSearch.exchange`)];return e.append(...t.map(e=>this.tag(`tcw-ss-head`,e))),e}buildHeader(e){let t=document.createElement(`div`);t.className=`tcw-modal-header`;let n=document.createElement(`h3`);n.id=`tcw-ss-title-${this.uid}`,n.textContent=this.t(e.kind===`compare`?`compare.title`:`symbolSearch.title`);let r=document.createElement(`button`);return r.type=`button`,r.className=`tcw-modal-close`,r.setAttribute(`aria-label`,this.t(`common.close`)),r.innerHTML=O(`x`,16),r.addEventListener(`click`,()=>this.close()),t.append(n,r),t}buildSearch(){let e=document.createElement(`label`);e.className=`tcw-ss-search`,e.innerHTML=O(`search`,16);let t=document.createElement(`input`);return t.type=`search`,t.className=`tcw-ss-input`,t.placeholder=this.t(`symbolSearch.placeholder`),t.setAttribute(`aria-label`,this.t(`symbolSearch.placeholder`)),t.setAttribute(`role`,`combobox`),t.setAttribute(`aria-expanded`,`true`),t.setAttribute(`aria-controls`,`tcw-ss-list-${this.uid}`),t.setAttribute(`aria-autocomplete`,`list`),t.autocomplete=`off`,t.spellcheck=!1,t.addEventListener(`input`,()=>this.filter()),e.appendChild(t),this.input=t,e}buildWay(e){let t=document.createElement(`label`);t.className=`tcw-ss-way`;let n=document.createElement(`span`);n.textContent=this.t(`compare.addAs`);let r=document.createElement(`select`);r.className=`tcw-settings-select tcw-ss-way-select`;for(let t of e.ways){let e=document.createElement(`option`);e.value=t.id,e.textContent=t.label,r.appendChild(e)}return r.value=this.way,r.addEventListener(`change`,()=>{this.way=r.value}),t.append(n,r),t}listGiven(){this.rows=this.given.map(e=>({symbol:e,score:0,info:this.infoOf(e)})),this.rowsGiven=!0,this.afterResults(!0)}filter(){this.pickOnResults=!1;let e=this.input?.value.trim()??``;if(this.searchFn&&e){this.scheduleSearch(e);return}if(this.cancelSearch(),this.status=`idle`,!e){this.listGiven();return}let t=Ar(e);this.rows=this.given.map(e=>{let n=this.infoOf(e);return{symbol:e,score:jr(e,this.foldedName(n?.description),t),info:n}}).filter(e=>e.score>0).sort((e,t)=>t.score-e.score),this.rowsGiven=!0,this.afterResults(!1)}foldedName(e){if(!e)return``;let t=this.foldedNames.get(e);return t===void 0&&(t=Pr(e),this.foldedNames.set(e,t)),t}scheduleSearch(e){this.searchTimer!==null&&clearTimeout(this.searchTimer),this.searchTimer=setTimeout(()=>{this.searchTimer=null,this.runSearch(e)},150)}searchNow(){this.searchTimer!==null&&clearTimeout(this.searchTimer),this.searchTimer=null,this.runSearch(this.input?.value.trim()??``)}async runSearch(e){let t=this.searchFn;if(!t)return;this.searchAbort?.abort();let n=new AbortController;this.searchAbort=n,this.status=`searching`,this.shown.length===0&&this.renderList();try{let r=await t(e,n.signal);if(n.signal.aborted)return;let i=Xt(r);for(let e of i)this.heard.set(e.symbol,Zt(this.heard.get(e.symbol),e));this.rows=i.map(e=>({symbol:e.symbol,score:0,info:this.infoOf(e.symbol)})),this.status=`idle`}catch{if(n.signal.aborted)return;this.rows=[],this.status=`failed`}this.rowsGiven=!1,this.afterResults(!1),this.pickOnResults&&(this.pickOnResults=!1,this.pick(0))}cancelSearch(){this.searchTimer!==null&&clearTimeout(this.searchTimer),this.searchTimer=null,this.searchAbort?.abort(),this.searchAbort=null}afterResults(e){let t=this.listableRows();this.filters?.see(t.map(e=>e.info)),this.shown=this.visibleRows(t);let n=e?this.shown.findIndex(e=>e.symbol===this.mode?.start.current):-1;this.selectedIndex=n>=0&&n<this.listedCount()?n:0,this.renderList()}listedCount(){return Math.min(this.shown.length,200)}listableRows(){if(this.mode?.kind!==`compare`)return this.rows;let e=this.mode.start.current;return this.rows.filter(t=>t.symbol!==e)}visibleRows(e){let t=this.filters;return t?e.filter(e=>t.passes(e.info,this.rowsGiven)):[...e]}renderList(){let e=this.list,t=this.results;if(!e||!t)return;let n=(this.input?.value??``).trim(),r=this.mode?.kind===`compare`,i=[];if(r&&!n&&this.compared.length>0){let t=this.heading(this.t(`compare.onChart`),`added`),n=document.createElement(`div`);n.className=`tcw-ss-added`,n.setAttribute(`role`,`group`),n.setAttribute(`aria-labelledby`,t.id),n.append(...this.compared.map(e=>this.addedRow(e)));let r=this.heading(this.t(`compare.symbols`),`symbols`);r.hidden=this.shown.length===0,i.push(t,n,r),e.setAttribute(`aria-labelledby`,r.id)}else e.setAttribute(`aria-labelledby`,`tcw-ss-title-${this.uid}`);let a=n.toUpperCase(),o=new Set(this.compared.map(e=>e.symbol)),s=this.shown.slice(0,200);e.replaceChildren(...s.map((e,t)=>this.row(e,t,a,r&&o.has(e.symbol))));let c=this.shown.length===0?this.emptyNote(n,r):this.moreNote(this.shown.length-s.length);t.replaceChildren(...this.columns?[this.columns]:[],...i,e,...c?[c]:[]),this.live&&(this.live.textContent=this.shown.length===0?c?.textContent??``:``),this.markSelection()}emptyNote(e,t){let n;if(this.status===`searching`)n=this.t(`symbolSearch.searching`);else if(this.status===`failed`)n=this.t(`symbolSearch.failed`);else if(t&&!e){if(this.compared.length>0)return null;n=this.t(`compare.empty`)}else n=this.t(`symbolSearch.empty`);let r=document.createElement(`div`);return r.className=`tcw-ss-empty`,r.textContent=n,r}moreNote(e){if(e<=0)return null;let n=document.createElement(`div`);return n.className=`tcw-ss-more`,n.textContent=t.r(this.t(`symbolSearch.more`),{count:e}),n}heading(e,t){let n=document.createElement(`div`);return n.className=`tcw-ss-heading`,n.id=`tcw-ss-${t}-${this.uid}`,n.textContent=e,n}row(e,t,n,r){let i=document.createElement(`div`);i.className=`tcw-ss-row`,i.id=`tcw-ss-opt-${this.uid}-${t}`,i.dataset.symbol=e.symbol,i.setAttribute(`role`,`option`);let a=this.mode?.kind===`search`&&e.symbol===this.mode.start.current;i.classList.toggle(`tcw-current`,a),i.classList.toggle(`tcw-on-chart`,r),a&&i.setAttribute(`aria-current`,`true`);let o=this.tag(`tcw-ss-kind`,e.info?.type?.trim()??``),s=this.tag(`tcw-ss-exchange`,e.info?.exchange?.trim()??``);if(o.dir=s.dir=`auto`,i.append(wr(e.symbol,e.info),Lr(e.symbol,n),this.descriptionCell(e),o,s),a||r){let e=document.createElement(`span`);e.className=`tcw-ss-check`,e.innerHTML=O(`check`,14),i.appendChild(e)}return r&&i.appendChild(this.tag(`tcw-visually-hidden`,this.t(`compare.onChart`))),i.addEventListener(`click`,()=>this.pick(t)),i.addEventListener(`mousemove`,()=>{this.selectedIndex!==t&&(this.selectedIndex=t,this.markSelection())}),i}descriptionCell(e){let t=document.createElement(`span`);t.className=`tcw-ss-desc-cell`;let n=e.info?.description&&e.info.description!==e.symbol?e.info.description:``;if(n){let e=this.tag(`tcw-ss-desc`,n);e.dir=`auto`,t.appendChild(e)}return t}addedRow(e){let n=document.createElement(`div`);if(n.className=`tcw-ss-added-row`,n.setAttribute(`role`,`presentation`),e.color){let t=document.createElement(`span`);t.className=`tcw-ss-swatch`,t.style.background=e.color,n.appendChild(t)}let r=document.createElement(`span`);r.className=`tcw-ss-way-cell`,r.appendChild(this.tag(`tcw-ss-way-label`,e.way));let i=document.createElement(`button`);i.type=`button`,i.className=`tcw-ss-remove`;let a=t.r(this.t(`compare.remove`),{symbol:e.symbol});return i.title=a,i.setAttribute(`aria-label`,a),i.innerHTML=O(`x`,12),i.addEventListener(`click`,()=>{this.mode?.kind===`compare`&&this.mode.start.onRemove(e.id)}),n.append(Lr(e.symbol,``),r,i),n}tag(e,t){let n=document.createElement(`span`);return n.className=e,n.textContent=t,n}markSelection(){let e=this.list?.querySelectorAll(`.tcw-ss-row`)??[],t=null;e.forEach((e,n)=>{let r=n===this.selectedIndex;e.setAttribute(`aria-selected`,String(r)),e.classList.toggle(`tcw-selected`,r),r&&(t=e)});let n=t;n?(this.input?.setAttribute(`aria-activedescendant`,n.id),n.scrollIntoView?.({block:`nearest`})):this.input?.removeAttribute(`aria-activedescendant`)}pick(e){let t=this.shown[e],n=this.mode;if(!t||!n)return;if(n.kind===`compare`){this.selectedIndex=e,this.markSelection(),n.start.onAdd(t.symbol,this.way);return}let r=n.start.onPick??this.callbacks.onPick;this.close(),r(t.symbol)}onKeyDown(e,t){if(e.stopPropagation(),e.isComposing||e.keyCode===Wr)return;if(e.key===`Escape`){e.preventDefault(),this.close();return}if(M(e,t),e.target!==this.input)return;let n=this.listedCount();if(e.key===`ArrowDown`||e.key===`ArrowUp`){if(e.preventDefault(),n===0)return;this.selectedIndex=(this.selectedIndex+(e.key===`ArrowDown`?1:-1)+n)%n,this.markSelection()}else if(e.key===`Enter`){if(e.preventDefault(),e.repeat&&this.mode?.kind===`compare`)return;if(this.searchTimer!==null||this.status===`searching`){this.pickOnResults=!0,this.searchTimer!==null&&this.searchNow();return}this.pick(this.selectedIndex)}}},qr=229,Jr={"Search & navigation":`hotkeys.group.searchNavigation`,"Chart manipulation":`hotkeys.group.chartManipulation`,"Touch (mobile / tablet)":`hotkeys.group.touch`,Keyboard:`hotkeys.group.keyboard`,"Bar replay":`toolbar.replay`,Drawing:`hotkeys.group.drawing`,More:`hotkeys.group.more`},V=rr,Yr=[{title:`Search & navigation`,entries:[{keys:[V,`K`],label:`hotkeys.commandPalette`,feature:`hotkeys.commandPalette`},{keys:[V,`P`],label:`hotkeys.symbolSearch`,feature:`hotkeys.symbolSearch`},{keys:[`Alt`,`G`],label:`hotkeys.goToDate`,feature:`hotkeys.goToDate`},{keys:[`Alt`,`I`],label:`hotkeys.invertScale`,feature:`hotkeys.invertScale`},{keys:[`Alt`,`R`],label:`chartMenu.resetView`,feature:`hotkeys.resetView`},{keys:[V,`S`],label:`hotkeys.saveLayout`,feature:`hotkeys.save`},{keys:[`0–9`],label:`hotkeys.typeInterval`,feature:`intervalTyping`},{keys:[`A–Z`],label:`hotkeys.typeSymbol`,feature:`symbolTyping`},{keys:[`?`],label:`hotkeys.showSheet`,feature:`hotkeys.help`}]},{title:`Chart manipulation`,entries:[{keys:[`key.drag`],label:`hotkeys.pan`},{keys:[V,`key.drag`],label:`hotkeys.boxSelect`},{keys:[V,`key.click`],label:`hotkeys.toggleSelect`},{keys:[`Shift`,`key.drag`],label:`hotkeys.measure`},{keys:[`key.drag`,`key.priceAxis`],label:`hotkeys.scalePrice`},{keys:[`key.drag`,`key.timeAxis`],label:`hotkeys.zoomTime`},{keys:[`key.doubleClick`,`key.priceAxis`],label:`hotkeys.autoScale`},{keys:[`key.doubleClick`,`key.timeAxis`],label:`hotkeys.fit`},{keys:[`key.scroll`],label:`hotkeys.zoomCursor`}]},{title:`Touch (mobile / tablet)`,entries:[{keys:[`key.oneFinger`,`key.drag`],label:`hotkeys.touchPan`},{keys:[`key.twoFingers`,`key.pinch`],label:`hotkeys.pinch`},{keys:[`key.longPress`],label:`hotkeys.longPress`},{keys:[`key.drag`,`key.axisStrip`],label:`hotkeys.touchAxis`}]},{title:`Keyboard`,entries:[{keys:[`←`,`→`],label:`hotkeys.panBar`},{keys:[`+`,`−`],label:`hotkeys.zoomInOut`},{keys:[`Home`],label:`hotkeys.toStart`},{keys:[`End`],label:`hotkeys.toEnd`},{keys:[`Space`],label:`hotkeys.fit`}]},{title:`Bar replay`,entries:[{keys:[`Shift`,`←`,`→`],label:`hotkeys.replayStep`,feature:`replay`},{keys:[`Space`],label:`hotkeys.replayPlay`,feature:`replay`},{keys:[`Esc`],label:`hotkeys.replayCancel`,feature:`replay`}]},{title:`Drawing`,entries:[{keys:[V,`Z`],label:`hotkeys.undo`},{keys:[V,`Shift`,`Z`],label:`hotkeys.redo`},{keys:[`Esc`],label:`hotkeys.cancelDrawing`},{keys:[V,`C`],label:`hotkeys.copy`},{keys:[V,`V`],label:`hotkeys.paste`},{keys:[`key.rightClick`],label:`hotkeys.drawingMenu`},{keys:[`key.doubleClick`],label:`hotkeys.drawingSettings`},{keys:[V,`G`],label:`hotkeys.group`},{keys:[V,`Shift`,`G`],label:`hotkeys.ungroup`},{keys:[V,`]`,`[`],label:`hotkeys.orderStep`},{keys:[V,`Shift`,`]`,`[`],label:`hotkeys.orderEnd`},{keys:[`Enter`],label:`hotkeys.finishPath`},{keys:[V,`key.drag`],label:`hotkeys.copyDrag`},{keys:[`Shift`],label:`hotkeys.keepAngle`},{keys:[V],label:`hotkeys.flipMagnet`},{keys:[`←`,`→`,`↑`,`↓`],label:`hotkeys.nudge`},{keys:[`Alt`,`T`],label:`tool.trendLine`,feature:`hotkeys.tools`},{keys:[`Alt`,`H`],label:`tool.horizontalLine`,feature:`hotkeys.tools`},{keys:[`Alt`,`J`],label:`tool.horizontalRay`,feature:`hotkeys.tools`},{keys:[`Alt`,`V`],label:`tool.verticalLine`,feature:`hotkeys.tools`},{keys:[`Alt`,`C`],label:`tool.crossLine`,feature:`hotkeys.tools`},{keys:[`Alt`,`F`],label:`tool.fibRetracement`,feature:`hotkeys.tools`}]}],Xr=0,Zr=class{backdrop=null;bodyEl=null;searchEl=null;liveEl=null;groups=[];returnFocus=null;uid=++Xr;constructor(e,t,n=()=>document.body){this.callbacks=e,this.t=t,this.host=n}open(e={}){if(this.backdrop)return;this.returnFocus=document.activeElement instanceof HTMLElement?document.activeElement:null;let t=e.isOn??(()=>!0),n=new Set((e.extra??[]).map(e=>e.keys.join(`+`).toLowerCase()));this.groups=Yr.map(e=>({title:e.title,entries:e.entries.filter(e=>(!e.feature||t(e.feature))&&!n.has(e.keys.join(`+`).toLowerCase()))})).filter(e=>e.entries.length>0),e.extra&&e.extra.length>0&&this.groups.push({title:`More`,entries:[...e.extra]}),this.build(t(`hotkeys.help`)),this.render(),this.searchEl?.focus()}close(){if(!this.backdrop)return;this.backdrop.remove(),this.backdrop=this.bodyEl=this.searchEl=this.liveEl=null,this.callbacks.onClose();let e=this.returnFocus;this.returnFocus=null,e?.isConnected&&e.focus()}isOpen(){return this.backdrop!==null}destroy(){this.close()}build(e){let t=document.createElement(`div`);t.className=`tcw-modal-backdrop`;let n=!1;t.addEventListener(`pointerdown`,e=>{n=e.target===t}),t.addEventListener(`click`,e=>{e.target===t&&n&&this.close(),n=!1});let r=document.createElement(`div`);r.className=`tcw-modal tcw-hotkey-sheet`,r.setAttribute(`role`,`dialog`),r.setAttribute(`aria-modal`,`true`),r.setAttribute(`aria-labelledby`,`tcw-hotkey-title-${this.uid}`),r.tabIndex=-1,r.addEventListener(`keydown`,e=>{if(e.stopPropagation(),e.key===`Escape`&&!e.isComposing&&e.keyCode!==qr){e.preventDefault(),this.close();return}M(e,r)});let i=document.createElement(`div`);i.className=`tcw-modal-header`;let a=document.createElement(`h3`);a.id=`tcw-hotkey-title-${this.uid}`,a.textContent=this.t(`hotkeys.title`);let o=document.createElement(`button`);o.type=`button`,o.className=`tcw-modal-close`,o.setAttribute(`aria-label`,this.t(`hotkeys.close`)),o.innerHTML=O(`x`,16),o.addEventListener(`click`,()=>this.close()),i.append(a,o);let s=document.createElement(`label`);s.className=`tcw-ss-search tcw-hotkey-search`,s.innerHTML=O(`search`,16);let c=document.createElement(`input`);c.type=`search`,c.placeholder=this.t(`hotkeys.search`),c.setAttribute(`aria-label`,this.t(`hotkeys.search`)),c.autocomplete=`off`,c.spellcheck=!1,c.addEventListener(`input`,()=>this.render()),s.appendChild(c);let l=document.createElement(`div`);l.className=`tcw-hotkey-body`;let u=document.createElement(`div`);if(u.className=`tcw-hotkey-live tcw-visually-hidden`,u.setAttribute(`aria-live`,`polite`),r.append(i,s,l,u),e){let e=document.createElement(`div`);e.className=`tcw-hotkey-foot`,e.textContent=this.t(`hotkeys.footer`),r.appendChild(e)}t.appendChild(r),this.host().appendChild(t),this.backdrop=t,this.bodyEl=l,this.searchEl=c,this.liveEl=u}render(){let e=this.bodyEl;if(!e)return;let t=ir((this.searchEl?.value??``).trim()),n=[];for(let e of this.groups){let r=t?e.entries.filter(e=>this.matches(e,t)):e.entries;if(r.length===0)continue;let i=document.createElement(`section`);i.className=`tcw-hotkey-group`;let a=document.createElement(`div`);a.className=`tcw-hotkey-heading`;let o=Jr[e.title];a.textContent=o?this.t(o):e.title,i.append(a,...r.map(e=>this.row(e))),n.push(i)}if(this.liveEl&&(this.liveEl.textContent=n.length===0?this.t(`hotkeys.noMatch`):``),n.length===0){let t=document.createElement(`div`);t.className=`tcw-hotkey-empty`,t.textContent=this.t(`hotkeys.noMatch`),e.replaceChildren(t);return}let r=document.createElement(`div`);r.className=`tcw-hotkey-columns`,r.append(...n),e.replaceChildren(r)}label(e){return`text`in e?e.text:this.t(e.label)}keyText(e){return e.startsWith(`key.`)?this.t(e):e}matches(e,t){return ir(this.label(e)).includes(t)?!0:ir(e.keys.map(e=>this.keyText(e)).join(`+`)).includes(t)}row(e){let t=document.createElement(`div`);t.className=`tcw-hotkey-row`;let n=document.createElement(`span`);n.className=`tcw-hotkey-label`,n.textContent=this.label(e);let r=document.createElement(`span`);return r.className=`tcw-hotkey-keys`,r.dir=`ltr`,e.keys.forEach((e,t)=>{if(t>0){let e=document.createElement(`span`);e.className=`tcw-hotkey-sep`,e.textContent=`+`,r.appendChild(e)}let n=e.startsWith(`key.`),i=document.createElement(n?`span`:`kbd`);i.className=n?`tcw-hotkey-gesture`:`tcw-hotkey-key`,i.textContent=this.keyText(e),r.appendChild(i)}),t.append(n,r),t}},Qr={selectHint:`Click a bar to start the replay`,random:`Random bar`,realtime:`Back to realtime`,play:`Play`,pause:`Pause`,stepBack:`Step back (Shift+←)`,stepForward:`Step forward (Shift+→)`,replay:`Replay`,position:`Replay position`,speed:`Speed`,step:`Step`,loading:`Loading chart...`,selectBar:`Select bar`,cancel:`Cancel`,rate:`{rate}×`,rateHint:`1× plays one bar a second`,playingAt:`Playing at {rate}`,pausedAt:`Paused at {time}`,endedAt:`Replay ended at {time}`},$r=[.1,.2,.3,.5,1,2,3,5,10,20,30,50],ei=[`full`,`compact`,`stack`],ti=300,ni=2,ri=[`random`,`stepBack`,`stepForward`,`seek`,`step`,`selectBar`],ii=class{root=null;scrubber=null;timeLabel=null;playBtn=null;realtimeBtn=null;liveRegion=null;hintText=null;state=`stopped`;mode=`select`;ended=!1;pending=!1;total=0;rate=1;steps=[];step=`bar`;dir=`ltr`;formatRate;where=``;announceTimer=null;widths=new Map;labels;constructor(e,t={}){this.callbacks=e,this.labels={...Qr,...t},this.formatRate=e=>this.labels.rate.replace(`{rate}`,String(e))}mount(e,t){this.root||(this.total=Math.max(0,t.total),this.rate=t.rate??1,this.steps=t.steps??[],this.step=t.step??`bar`,this.dir=t.dir??`ltr`,t.formatRate&&(this.formatRate=t.formatRate),this.state=`paused`,this.mode=t.mode??`select`,this.root=document.createElement(`div`),this.root.className=`tcw-replay-bar`,D(this.root,`replay`),this.root.setAttribute(`role`,`group`),this.root.setAttribute(`aria-label`,this.labels.replay),this.root.dataset.fit=`full`,this.root.innerHTML=this.markup(),e.appendChild(this.root),this.wireEvents(),this.syncUi())}unmount(){this.announceTimer&&clearTimeout(this.announceTimer),this.announceTimer=null,this.root?.remove(),this.root=null,this.hintText=null,this.scrubber=null,this.timeLabel=null,this.playBtn=null,this.realtimeBtn=null,this.liveRegion=null,this.state=`stopped`,this.ended=!1,this.where=``}isMounted(){return this.root!==null}element(){return this.root}getMode(){return this.mode}setMode(e){let t=!!this.root?.contains(document.activeElement);this.mode=e,this.syncUi(),t&&(e===`replay`?(this.playBtn&&!this.playBtn.disabled?this.playBtn:this.realtimeBtn)?.focus():this.root?.querySelector(`[data-act="random"]`)?.focus())}setState(e){e!==this.state&&(this.state=e,this.syncUi(),this.mode===`replay`&&(e===`playing`?this.announce(this.labels.playingAt.replace(`{rate}`,this.formatRate(this.rate))):e===`paused`&&this.where&&this.announce(this.labels.pausedAt.replace(`{time}`,this.where))))}setEnded(e){this.ended!==e&&(this.ended=e,this.syncUi(),e&&this.where&&this.announce(this.labels.endedAt.replace(`{time}`,this.where)))}setPending(e){if(this.pending===e)return;this.pending=e;let t=document.activeElement;e&&t&&t!==this.playBtn&&this.root?.contains(t)&&ri.includes(t.dataset.act??``)&&this.playBtn?.focus(),this.syncUi(),e&&this.mode===`replay`&&this.announce(this.labels.loading)}isPending(){return this.pending}setSteps(e,t){this.steps=e,this.step=t,this.widths.clear();let n=this.root?.querySelector(`[data-tcw="stepSlot"]`);n&&(n.innerHTML=this.stepMarkup(),this.wireStep(),this.syncUi())}setProgress(e,t,n){this.total=t;let r=n??`${Math.min(e+1,t)} / ${t}`,i=r!==this.where;if(this.where=r,this.scrubber){this.scrubber.max=String(Math.max(0,t-1)),this.scrubber.value=String(e),this.scrubber.setAttribute(`aria-valuetext`,r);let n=t>1?Math.min(e,t-1)/(t-1)*100:0;this.scrubber.style.setProperty(`--tcw-replay-done`,`${Number(n.toFixed(ni))}%`)}if(this.timeLabel){this.timeLabel.textContent=r;let e=Number.parseFloat(this.timeLabel.style.minInlineSize)||0;r.length>e&&(this.timeLabel.style.minInlineSize=`${r.length}ch`)}let a=this.scrubber!==null&&document.activeElement===this.scrubber;i&&this.mode===`replay`&&this.state!==`playing`&&!a&&this.announce(r)}setRoom(e){let t=this.root;if(t){for(let n of ei)if(n===`stack`||this.widthIn(n)<=e){t.dataset.fit=n,this.orderFor(n);return}}}orderFor(e){let t=this.root,n=t?.querySelector(`.tcw-replay-timeline`),r=t?.querySelector(`.tcw-replay-transport`),i=this.realtimeBtn;if(!t||!n||!r||!i)return;let a=e===`stack`;if(a===(n.nextElementSibling===i))return;let o=document.activeElement;a?r.before(n,i):(r.nextElementSibling?.after(n),t.querySelector(`[data-act="cancel"]`)?.before(i)),o&&t.contains(o)&&document.activeElement!==o&&o.focus()}getFit(){return this.root?.dataset.fit??`full`}destroy(){this.unmount()}widthIn(e){let t=this.root,n=`${this.mode}|${this.steps.length}|${e}`,r=this.widths.get(n);if(r!==void 0)return r;let i=t.dataset.fit;t.dataset.fit=e,t.dataset.measure=``;let a=t.getBoundingClientRect().width;return delete t.dataset.measure,i&&(t.dataset.fit=i),a>0&&this.widths.set(n,a),a}markup(){let e=this.labels,t=`dir="${this.dir}"`,n=$r.map(e=>`<option value="${e}"${e===this.rate?` selected`:``}>${k(this.formatRate(e))}</option>`).join(``),r=(e,t,n,r=`tcw-replay-btn`,i=``)=>`<button type="button" class="${r}" data-act="${e}" title="${k(t)}" aria-label="${k(t)}"${i}>${n}</button>`;return`
7662
7662
  <span class="tcw-replay-group tcw-replay-picking" data-mode="select">
7663
7663
  <span class="tcw-replay-hint" ${t}>${O(`cursor`,14)}<span data-tcw="hint">${k(e.selectHint)}</span></span>
7664
7664
  <button type="button" class="tcw-replay-text-btn tcw-replay-ghost" data-act="random" ${t}>${k(e.random)}</button>