UNPKG

lwc-plugin-visible-price-range-util

Version:

A plugin for providing a utility API to retrieve the visible range of a price scale, and subscribe to changes.

2 lines (1 loc) 2.16 kB
(function(i,t){typeof exports=="object"&&typeof module<"u"?t(exports):typeof define=="function"&&define.amd?define(["exports"],t):(i=typeof globalThis<"u"?globalThis:i||self,t(i.VisiblePriceRangeUtil={}))})(this,function(i){"use strict";var d=Object.defineProperty;var _=(i,t,r)=>t in i?d(i,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):i[t]=r;var o=(i,t,r)=>(_(i,typeof t!="symbol"?t+"":t,r),r);const t={};function r(h){if(h===void 0)throw new Error("Value is undefined");return h}class l{constructor(){o(this,"_chart");o(this,"_series")}attached({chart:n,series:e}){this._chart=n,this._series=e}detached(){this._chart=void 0,this._series=void 0}get chart(){return r(this._chart)}get series(){return r(this._series)}}class a{constructor(){o(this,"_listeners",[])}subscribe(n,e,s){const c={callback:n,linkedObject:e,singleshot:s===!0};this._listeners.push(c)}unsubscribe(n){const e=this._listeners.findIndex(s=>n===s.callback);e>-1&&this._listeners.splice(e,1)}unsubscribeAll(n){this._listeners=this._listeners.filter(e=>e.linkedObject!==n)}fire(n){const e=[...this._listeners];this._listeners=this._listeners.filter(s=>!s.singleshot),e.forEach(s=>s.callback(n))}hasListeners(){return this._listeners.length>0}destroy(){this._listeners=[]}}class u extends l{constructor(e={}){super();o(this,"_options");o(this,"_currentRange",null);o(this,"_changed",new a);this._options={...t,...e}}updateAllViews(){this._checkPriceRange()}get options(){return this._options}applyOptions(e){this._options={...this._options,...e}}priceRangeChanged(){return this._changed}getVisiblePriceRange(){return this._currentRange}_checkPriceRange(){const e=this._measurePriceRange(),s=e===null||this._currentRange===null,c=s&&e===this._currentRange;(s&&!c||e.bottom!==this._currentRange.bottom||e.top!==this._currentRange.top)&&this._changed.fire(e),this._currentRange=e}_measurePriceRange(){if(!this.chart||!this.series)return null;const e=this.chart.paneSize(),s=this.series.coordinateToPrice(0),c=this.series.coordinateToPrice(e.height);return s===null||c===null?null:{top:s,bottom:c}}}i.VisiblePriceRangeUtil=u,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});