UNPKG

payoff-chart

Version:

A lightweight and interactive JavaScript library to visualize option payoff diagrams based on TradingView's powerful Lightweight Charts. Perfect for traders, educators, and developers building financial tools or option strategy visualizations.

1,452 lines (1,445 loc) 349 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Payoffchart = factory()); })(this, (function () { 'use strict'; function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); } function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; } function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || false, o.configurable = true, "value" in o && (o.writable = true), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: false }), e; } function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) { t && (r = t); var n = 0, F = function () {}; return { s: F, n: function () { return n >= r.length ? { done: true } : { done: false, value: r[n++] }; }, e: function (r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = true, u = false; return { s: function () { t = t.call(r); }, n: function () { var r = t.next(); return a = r.done, r; }, e: function (r) { u = true, o = r; }, f: function () { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e; } function _get() { return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) { var p = _superPropBase(e, t); if (p) { var n = Object.getOwnPropertyDescriptor(p, t); return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value; } }, _get.apply(null, arguments); } function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); } function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: true, configurable: true } }), Object.defineProperty(t, "prototype", { writable: false }), e && _setPrototypeOf(t, e); } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function () { return !!t; })(); } function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); } function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = true, o = false; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = true, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; } function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; } function _possibleConstructorReturn(t, e) { if (e && ("object" == typeof e || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); } function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = false, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function (t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = true, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), true), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine(u), _regeneratorDefine(u, o, "Generator"), _regeneratorDefine(u, n, function () { return this; }), _regeneratorDefine(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function () { return { w: i, m: f }; })(); } function _regeneratorDefine(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine = function (e, r, n, t) { if (r) i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n;else { function o(r, n) { _regeneratorDefine(e, r, function (e) { return this._invoke(r, n, e); }); } o("next", 0), o("throw", 1), o("return", 2); } }, _regeneratorDefine(e, r, n, t); } function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); } function _superPropBase(t, o) { for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t));); return t; } function _superPropGet(t, o, e, r) { var p = _get(_getPrototypeOf(t.prototype ), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; } function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); } function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; } function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function size(_a) { var width = _a.width, height = _a.height; if (width < 0) { throw new Error('Negative width is not allowed for Size'); } if (height < 0) { throw new Error('Negative height is not allowed for Size'); } return { width: width, height: height }; } function equalSizes(first, second) { return first.width === second.width && first.height === second.height; } var Observable = /** @class */function () { function Observable(win) { var _this = this; this._resolutionListener = function () { return _this._onResolutionChanged(); }; this._resolutionMediaQueryList = null; this._observers = []; this._window = win; this._installResolutionListener(); } Observable.prototype.dispose = function () { this._uninstallResolutionListener(); this._window = null; }; Object.defineProperty(Observable.prototype, "value", { get: function get() { return this._window.devicePixelRatio; }, enumerable: false, configurable: true }); Observable.prototype.subscribe = function (next) { var _this = this; var observer = { next: next }; this._observers.push(observer); return { unsubscribe: function unsubscribe() { _this._observers = _this._observers.filter(function (o) { return o !== observer; }); } }; }; Observable.prototype._installResolutionListener = function () { if (this._resolutionMediaQueryList !== null) { throw new Error('Resolution listener is already installed'); } var dppx = this._window.devicePixelRatio; this._resolutionMediaQueryList = this._window.matchMedia("all and (resolution: ".concat(dppx, "dppx)")); // IE and some versions of Edge do not support addEventListener/removeEventListener, and we are going to use the deprecated addListener/removeListener this._resolutionMediaQueryList.addListener(this._resolutionListener); }; Observable.prototype._uninstallResolutionListener = function () { if (this._resolutionMediaQueryList !== null) { // IE and some versions of Edge do not support addEventListener/removeEventListener, and we are going to use the deprecated addListener/removeListener this._resolutionMediaQueryList.removeListener(this._resolutionListener); this._resolutionMediaQueryList = null; } }; Observable.prototype._reinstallResolutionListener = function () { this._uninstallResolutionListener(); this._installResolutionListener(); }; Observable.prototype._onResolutionChanged = function () { var _this = this; this._observers.forEach(function (observer) { return observer.next(_this._window.devicePixelRatio); }); this._reinstallResolutionListener(); }; return Observable; }(); function createObservable(win) { return new Observable(win); } var DevicePixelContentBoxBinding = /** @class */function () { function DevicePixelContentBoxBinding(canvasElement, transformBitmapSize, options) { var _a; this._canvasElement = null; this._bitmapSizeChangedListeners = []; this._suggestedBitmapSize = null; this._suggestedBitmapSizeChangedListeners = []; // devicePixelRatio approach this._devicePixelRatioObservable = null; // ResizeObserver approach this._canvasElementResizeObserver = null; this._canvasElement = canvasElement; this._canvasElementClientSize = size({ width: this._canvasElement.clientWidth, height: this._canvasElement.clientHeight }); this._transformBitmapSize = transformBitmapSize !== null && transformBitmapSize !== void 0 ? transformBitmapSize : function (size) { return size; }; this._allowResizeObserver = (_a = options === null || options === void 0 ? void 0 : options.allowResizeObserver) !== null && _a !== void 0 ? _a : true; this._chooseAndInitObserver(); // we MAY leave the constuctor without any bitmap size observation mechanics initialized } DevicePixelContentBoxBinding.prototype.dispose = function () { var _a, _b; if (this._canvasElement === null) { throw new Error('Object is disposed'); } (_a = this._canvasElementResizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect(); this._canvasElementResizeObserver = null; (_b = this._devicePixelRatioObservable) === null || _b === void 0 ? void 0 : _b.dispose(); this._devicePixelRatioObservable = null; this._suggestedBitmapSizeChangedListeners.length = 0; this._bitmapSizeChangedListeners.length = 0; this._canvasElement = null; }; Object.defineProperty(DevicePixelContentBoxBinding.prototype, "canvasElement", { get: function get() { if (this._canvasElement === null) { throw new Error('Object is disposed'); } return this._canvasElement; }, enumerable: false, configurable: true }); Object.defineProperty(DevicePixelContentBoxBinding.prototype, "canvasElementClientSize", { get: function get() { return this._canvasElementClientSize; }, enumerable: false, configurable: true }); Object.defineProperty(DevicePixelContentBoxBinding.prototype, "bitmapSize", { get: function get() { return size({ width: this.canvasElement.width, height: this.canvasElement.height }); }, enumerable: false, configurable: true }); /** * Use this function to change canvas element client size until binding is disposed * @param clientSize New client size for bound HTMLCanvasElement */ DevicePixelContentBoxBinding.prototype.resizeCanvasElement = function (clientSize) { this._canvasElementClientSize = size(clientSize); this.canvasElement.style.width = "".concat(this._canvasElementClientSize.width, "px"); this.canvasElement.style.height = "".concat(this._canvasElementClientSize.height, "px"); this._invalidateBitmapSize(); }; DevicePixelContentBoxBinding.prototype.subscribeBitmapSizeChanged = function (listener) { this._bitmapSizeChangedListeners.push(listener); }; DevicePixelContentBoxBinding.prototype.unsubscribeBitmapSizeChanged = function (listener) { this._bitmapSizeChangedListeners = this._bitmapSizeChangedListeners.filter(function (l) { return l !== listener; }); }; Object.defineProperty(DevicePixelContentBoxBinding.prototype, "suggestedBitmapSize", { get: function get() { return this._suggestedBitmapSize; }, enumerable: false, configurable: true }); DevicePixelContentBoxBinding.prototype.subscribeSuggestedBitmapSizeChanged = function (listener) { this._suggestedBitmapSizeChangedListeners.push(listener); }; DevicePixelContentBoxBinding.prototype.unsubscribeSuggestedBitmapSizeChanged = function (listener) { this._suggestedBitmapSizeChangedListeners = this._suggestedBitmapSizeChangedListeners.filter(function (l) { return l !== listener; }); }; DevicePixelContentBoxBinding.prototype.applySuggestedBitmapSize = function () { if (this._suggestedBitmapSize === null) { // nothing to apply return; } var oldSuggestedSize = this._suggestedBitmapSize; this._suggestedBitmapSize = null; this._resizeBitmap(oldSuggestedSize); this._emitSuggestedBitmapSizeChanged(oldSuggestedSize, this._suggestedBitmapSize); }; DevicePixelContentBoxBinding.prototype._resizeBitmap = function (newSize) { var oldSize = this.bitmapSize; if (equalSizes(oldSize, newSize)) { return; } this.canvasElement.width = newSize.width; this.canvasElement.height = newSize.height; this._emitBitmapSizeChanged(oldSize, newSize); }; DevicePixelContentBoxBinding.prototype._emitBitmapSizeChanged = function (oldSize, newSize) { var _this = this; this._bitmapSizeChangedListeners.forEach(function (listener) { return listener.call(_this, oldSize, newSize); }); }; DevicePixelContentBoxBinding.prototype._suggestNewBitmapSize = function (newSize) { var oldSuggestedSize = this._suggestedBitmapSize; var finalNewSize = size(this._transformBitmapSize(newSize, this._canvasElementClientSize)); var newSuggestedSize = equalSizes(this.bitmapSize, finalNewSize) ? null : finalNewSize; if (oldSuggestedSize === null && newSuggestedSize === null) { return; } if (oldSuggestedSize !== null && newSuggestedSize !== null && equalSizes(oldSuggestedSize, newSuggestedSize)) { return; } this._suggestedBitmapSize = newSuggestedSize; this._emitSuggestedBitmapSizeChanged(oldSuggestedSize, newSuggestedSize); }; DevicePixelContentBoxBinding.prototype._emitSuggestedBitmapSizeChanged = function (oldSize, newSize) { var _this = this; this._suggestedBitmapSizeChangedListeners.forEach(function (listener) { return listener.call(_this, oldSize, newSize); }); }; DevicePixelContentBoxBinding.prototype._chooseAndInitObserver = function () { var _this = this; if (!this._allowResizeObserver) { this._initDevicePixelRatioObservable(); return; } isDevicePixelContentBoxSupported().then(function (isSupported) { return isSupported ? _this._initResizeObserver() : _this._initDevicePixelRatioObservable(); }); }; // devicePixelRatio approach DevicePixelContentBoxBinding.prototype._initDevicePixelRatioObservable = function () { var _this = this; if (this._canvasElement === null) { // it looks like we are already dead return; } var win = canvasElementWindow(this._canvasElement); if (win === null) { throw new Error('No window is associated with the canvas'); } this._devicePixelRatioObservable = createObservable(win); this._devicePixelRatioObservable.subscribe(function () { return _this._invalidateBitmapSize(); }); this._invalidateBitmapSize(); }; DevicePixelContentBoxBinding.prototype._invalidateBitmapSize = function () { var _a, _b; if (this._canvasElement === null) { // it looks like we are already dead return; } var win = canvasElementWindow(this._canvasElement); if (win === null) { return; } var ratio = (_b = (_a = this._devicePixelRatioObservable) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : win.devicePixelRatio; var canvasRects = this._canvasElement.getClientRects(); var newSize = // eslint-disable-next-line no-negated-condition canvasRects[0] !== undefined ? predictedBitmapSize(canvasRects[0], ratio) : size({ width: this._canvasElementClientSize.width * ratio, height: this._canvasElementClientSize.height * ratio }); this._suggestNewBitmapSize(newSize); }; // ResizeObserver approach DevicePixelContentBoxBinding.prototype._initResizeObserver = function () { var _this = this; if (this._canvasElement === null) { // it looks like we are already dead return; } this._canvasElementResizeObserver = new ResizeObserver(function (entries) { var entry = entries.find(function (entry) { return entry.target === _this._canvasElement; }); if (!entry || !entry.devicePixelContentBoxSize || !entry.devicePixelContentBoxSize[0]) { return; } var entrySize = entry.devicePixelContentBoxSize[0]; var newSize = size({ width: entrySize.inlineSize, height: entrySize.blockSize }); _this._suggestNewBitmapSize(newSize); }); this._canvasElementResizeObserver.observe(this._canvasElement, { box: 'device-pixel-content-box' }); }; return DevicePixelContentBoxBinding; }(); function bindTo(canvasElement, target) { { return new DevicePixelContentBoxBinding(canvasElement, target.transform, target.options); } } function canvasElementWindow(canvasElement) { // According to DOM Level 2 Core specification, ownerDocument should never be null for HTMLCanvasElement // see https://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#node-ownerDoc // eslint-disable-next-line @typescript-eslint/no-non-null-assertion return canvasElement.ownerDocument.defaultView; } function isDevicePixelContentBoxSupported() { return new Promise(function (resolve) { var ro = new ResizeObserver(function (entries) { resolve(entries.every(function (entry) { return 'devicePixelContentBoxSize' in entry; })); ro.disconnect(); }); ro.observe(document.body, { box: 'device-pixel-content-box' }); })["catch"](function () { return false; }); } function predictedBitmapSize(canvasRect, ratio) { return size({ width: Math.round(canvasRect.left * ratio + canvasRect.width * ratio) - Math.round(canvasRect.left * ratio), height: Math.round(canvasRect.top * ratio + canvasRect.height * ratio) - Math.round(canvasRect.top * ratio) }); } /** * @experimental */ var CanvasRenderingTarget2D = /** @class */function () { function CanvasRenderingTarget2D(context, mediaSize, bitmapSize) { if (mediaSize.width === 0 || mediaSize.height === 0) { throw new TypeError('Rendering target could only be created on a media with positive width and height'); } this._mediaSize = mediaSize; // !Number.isInteger(bitmapSize.width) || !Number.isInteger(bitmapSize.height) if (bitmapSize.width === 0 || bitmapSize.height === 0) { throw new TypeError('Rendering target could only be created using a bitmap with positive integer width and height'); } this._bitmapSize = bitmapSize; this._context = context; } CanvasRenderingTarget2D.prototype.useMediaCoordinateSpace = function (f) { try { this._context.save(); // do not use resetTransform to support old versions of Edge this._context.setTransform(1, 0, 0, 1, 0, 0); this._context.scale(this._horizontalPixelRatio, this._verticalPixelRatio); return f({ context: this._context, mediaSize: this._mediaSize }); } finally { this._context.restore(); } }; CanvasRenderingTarget2D.prototype.useBitmapCoordinateSpace = function (f) { try { this._context.save(); // do not use resetTransform to support old versions of Edge this._context.setTransform(1, 0, 0, 1, 0, 0); return f({ context: this._context, mediaSize: this._mediaSize, bitmapSize: this._bitmapSize, horizontalPixelRatio: this._horizontalPixelRatio, verticalPixelRatio: this._verticalPixelRatio }); } finally { this._context.restore(); } }; Object.defineProperty(CanvasRenderingTarget2D.prototype, "_horizontalPixelRatio", { get: function get() { return this._bitmapSize.width / this._mediaSize.width; }, enumerable: false, configurable: true }); Object.defineProperty(CanvasRenderingTarget2D.prototype, "_verticalPixelRatio", { get: function get() { return this._bitmapSize.height / this._mediaSize.height; }, enumerable: false, configurable: true }); return CanvasRenderingTarget2D; }(); /** * @experimental */ function tryCreateCanvasRenderingTarget2D(binding, contextOptions) { var mediaSize = binding.canvasElementClientSize; if (mediaSize.width === 0 || mediaSize.height === 0) { return null; } var bitmapSize = binding.bitmapSize; if (bitmapSize.width === 0 || bitmapSize.height === 0) { return null; } var context = binding.canvasElement.getContext('2d', contextOptions); if (context === null) { return null; } return new CanvasRenderingTarget2D(context, mediaSize, bitmapSize); } var _excluded = ["time", "color"]; var _navigator; var e = { title: "", visible: true, lastValueVisible: true, priceLineVisible: true, priceLineSource: 0, priceLineWidth: 1, priceLineColor: "", priceLineStyle: 2, baseLineVisible: true, baseLineWidth: 1, baseLineColor: "#B2B5BE", baseLineStyle: 0, priceFormat: { type: "price", precision: 2, minMove: .01 } }; var r, h; function a(t, i) { var s = { 0: [], 1: [t.lineWidth, t.lineWidth], 2: [2 * t.lineWidth, 2 * t.lineWidth], 3: [6 * t.lineWidth, 6 * t.lineWidth], 4: [t.lineWidth, 4 * t.lineWidth] }[i]; t.setLineDash(s); } function l(t, i, s, n) { t.beginPath(); var e = t.lineWidth % 2 ? .5 : 0; t.moveTo(s, i + e), t.lineTo(n, i + e), t.stroke(); } function o(t, i) { if (!t) throw new Error("Assertion failed" + (i ? ": " + i : "")); } function _(t) { if (void 0 === t) throw new Error("Value is undefined"); return t; } function u(t) { if (null === t) throw new Error("Value is null"); return t; } function c(t) { return u(_(t)); } !function (t) { t[t.Simple = 0] = "Simple", t[t.WithSteps = 1] = "WithSteps", t[t.Curved = 2] = "Curved"; }(r || (r = {})), function (t) { t[t.Solid = 0] = "Solid", t[t.Dotted = 1] = "Dotted", t[t.Dashed = 2] = "Dashed", t[t.LargeDashed = 3] = "LargeDashed", t[t.SparseDotted = 4] = "SparseDotted"; }(h || (h = {})); var d = /*#__PURE__*/function () { function d() { _classCallCheck(this, d); this.t = []; } return _createClass(d, [{ key: "i", value: function i(t, _i2, s) { var n = { h: t, l: _i2, o: true === s }; this.t.push(n); } }, { key: "_", value: function _(t) { var i = this.t.findIndex(function (i) { return t === i.h; }); i > -1 && this.t.splice(i, 1); } }, { key: "u", value: function u(t) { this.t = this.t.filter(function (i) { return i.l !== t; }); } }, { key: "p", value: function p(t, i, s) { var n = _toConsumableArray(this.t); this.t = this.t.filter(function (t) { return !t.o; }), n.forEach(function (n) { return n.h(t, i, s); }); } }, { key: "v", value: function v() { return this.t.length > 0; } }, { key: "m", value: function m() { this.t = []; } }]); }(); function f(t) { for (var _len = arguments.length, i = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { i[_key - 1] = arguments[_key]; } for (var _i4 = 0, _i3 = i; _i4 < _i3.length; _i4++) { var _s2 = _i3[_i4]; for (var _i5 in _s2) void 0 !== _s2[_i5] && Object.prototype.hasOwnProperty.call(_s2, _i5) && !["__proto__", "constructor", "prototype"].includes(_i5) && ("object" != _typeof(_s2[_i5]) || void 0 === t[_i5] || Array.isArray(_s2[_i5]) ? t[_i5] = _s2[_i5] : f(t[_i5], _s2[_i5])); } return t; } function p(t) { return "number" == typeof t && isFinite(t); } function v(t) { return "number" == typeof t && t % 1 == 0; } function m(t) { return "string" == typeof t; } function w(t) { return "boolean" == typeof t; } function g(t) { var i = t; if (!i || "object" != _typeof(i)) return i; var s, n, e; for (n in s = Array.isArray(i) ? [] : {}, i) i.hasOwnProperty(n) && (e = i[n], s[n] = e && "object" == _typeof(e) ? g(e) : e); return s; } function M(t) { return null !== t; } function b(t) { return null === t ? void 0 : t; } var S = "-apple-system, BlinkMacSystemFont, 'Trebuchet MS', Roboto, Ubuntu, sans-serif"; function x(t, i, s) { return void 0 === i && (i = S), "".concat(s = void 0 !== s ? "".concat(s, " ") : "").concat(t, "px ").concat(i); } var C = /*#__PURE__*/function () { function C(t) { _classCallCheck(this, C); this.M = { S: 1, C: 5, k: NaN, P: "", T: "", R: "", D: "", V: 0, I: 0, B: 0, A: 0, L: 0 }, this.O = t; } return _createClass(C, [{ key: "N", value: function N() { var t = this.M, i = this.W(), s = this.F(); return t.k === i && t.T === s || (t.k = i, t.T = s, t.P = x(i, s), t.A = 2.5 / 12 * i, t.V = t.A, t.I = i / 12 * t.C, t.B = i / 12 * t.C, t.L = 0), t.R = this.H(), t.D = this.U(), this.M; } }, { key: "H", value: function H() { return this.O.N().layout.textColor; } }, { key: "U", value: function U() { return this.O.$(); } }, { key: "W", value: function W() { return this.O.N().layout.fontSize; } }, { key: "F", value: function F() { return this.O.N().layout.fontFamily; } }]); }(); function y(t) { return t < 0 ? 0 : t > 255 ? 255 : Math.round(t) || 0; } function k(t) { return .199 * t[0] + .687 * t[1] + .114 * t[2]; } var P = /*#__PURE__*/function () { function P(t, i) { _classCallCheck(this, P); this.q = new Map(), this.Y = t, i && (this.q = i); } return _createClass(P, [{ key: "j", value: function j(t, i) { if ("transparent" === t) return t; var s = this.K(t), n = s[3]; return "rgba(".concat(s[0], ", ").concat(s[1], ", ").concat(s[2], ", ").concat(i * n, ")"); } }, { key: "X", value: function X(t) { var i = this.K(t); return { Z: "rgb(".concat(i[0], ", ").concat(i[1], ", ").concat(i[2], ")"), G: k(i) > 160 ? "black" : "white" }; } }, { key: "J", value: function J(t) { return k(this.K(t)); } }, { key: "tt", value: function tt(t, i, s) { var _this$K = this.K(t), _this$K2 = _slicedToArray(_this$K, 4), n = _this$K2[0], e = _this$K2[1], r = _this$K2[2], h = _this$K2[3], _this$K3 = this.K(i), _this$K4 = _slicedToArray(_this$K3, 4), a = _this$K4[0], l = _this$K4[1], o = _this$K4[2], _ = _this$K4[3], u = [y(n + s * (a - n)), y(e + s * (l - e)), y(r + s * (o - r)), (c = h + s * (_ - h), c <= 0 || c > 1 ? Math.min(Math.max(c, 0), 1) : Math.round(1e4 * c) / 1e4)]; var c; return "rgba(".concat(u[0], ", ").concat(u[1], ", ").concat(u[2], ", ").concat(u[3], ")"); } }, { key: "K", value: function K(t) { var i = this.q.get(t); if (i) return i; var s = function (t) { var i = document.createElement("div"); i.style.display = "none", document.body.appendChild(i), i.style.color = t; var s = window.getComputedStyle(i).color; return document.body.removeChild(i), s; }(t), n = s.match(/^rgba?\s*\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d*\.?\d+))?\)$/); if (!n) { if (this.Y.length) { var _iterator = _createForOfIteratorHelper(this.Y), _step; try { for (_iterator.s(); !(_step = _iterator.n()).done;) { var _i6 = _step.value; var _s3 = _i6(t); if (_s3) return this.q.set(t, _s3), _s3; } } catch (err) { _iterator.e(err); } finally { _iterator.f(); } } throw new Error("Failed to parse color: ".concat(t)); } var e = [parseInt(n[1], 10), parseInt(n[2], 10), parseInt(n[3], 10), n[4] ? parseFloat(n[4]) : 1]; return this.q.set(t, e), e; } }]); }(); var T = /*#__PURE__*/function () { function T() { _classCallCheck(this, T); this.it = []; } return _createClass(T, [{ key: "st", value: function st(t) { this.it = t; } }, { key: "nt", value: function nt(t, i, s) { this.it.forEach(function (n) { n.nt(t, i, s); }); } }]); }(); var R = /*#__PURE__*/function () { function R() { _classCallCheck(this, R); } return _createClass(R, [{ key: "nt", value: function nt(t, i, s) { var _this = this; t.useBitmapCoordinateSpace(function (t) { return _this.et(t, i, s); }); } }]); }(); var D = /*#__PURE__*/function (_R) { function D() { var _this2; _classCallCheck(this, D); _this2 = _callSuper(this, D, arguments), _this2.rt = null; return _this2; } _inherits(D, _R); return _createClass(D, [{ key: "ht", value: function ht(t) { this.rt = t; } }, { key: "et", value: function et(_ref) { var t = _ref.context, i = _ref.horizontalPixelRatio, s = _ref.verticalPixelRatio; if (null === this.rt || null === this.rt.lt) return; var n = this.rt.lt, e = this.rt, r = Math.max(1, Math.floor(i)) % 2 / 2, h = function h(_h) { t.beginPath(); for (var _a = n.to - 1; _a >= n.from; --_a) { var _n2 = e.ot[_a], _l = Math.round(_n2._t * i) + r, _o = _n2.ut * s, _2 = _h * s + r; t.moveTo(_l, _o), t.arc(_l, _o, _2, 0, 2 * Math.PI); } t.fill(); }; e.ct > 0 && (t.fillStyle = e.dt, h(e.ft + e.ct)), t.fillStyle = e.vt, h(e.ft); } }]); }(R); function V() { return { ot: [{ _t: 0, ut: 0, wt: 0, gt: 0 }], vt: "", dt: "", ft: 0, ct: 0, lt: null }; } var I = { from: 0, to: 1 }; var B = /*#__PURE__*/function () { function B(t, i, s) { _classCallCheck(this, B); this.Mt = new T(), this.bt = [], this.St = [], this.xt = true, this.O = t, this.Ct = i, this.yt = s, this.Mt.st(this.bt); } return _createClass(B, [{ key: "kt", value: function kt(t) { this.Pt(), this.xt = true; } }, { key: "Tt", value: function Tt() { return this.xt && (this.Rt(), this.xt = false), this.Mt; } }, { key: "Pt", value: function Pt() { var t = this.yt.Dt(); t.length !== this.bt.length && (this.St = t.map(V), this.bt = this.St.map(function (t) { var i = new D(); return i.ht(t), i; }), this.Mt.st(this.bt)); } }, { key: "Rt", value: function Rt() { var _this3 = this; var t = 2 === this.Ct.N().mode || !this.Ct.Vt(), i = this.yt.It(), s = this.Ct.Bt(), n = this.O.At(); this.Pt(), i.forEach(function (i, e) { var _h$Ht; var r = _this3.St[e], h = i.Et(s), a = i.zt(); !t && null !== h && i.Vt() && null !== a ? (r.vt = h.Lt, r.ft = h.ft, r.ct = h.Ot, r.ot[0].gt = h.gt, r.ot[0].ut = i.Wt().Nt(h.gt, a.Ft), r.dt = (_h$Ht = h.Ht) !== null && _h$Ht !== void 0 ? _h$Ht : _this3.O.Ut(r.ot[0].ut / i.Wt().$t()), r.ot[0].wt = s, r.ot[0]._t = n.qt(s), r.lt = I) : r.lt = null; }); } }]); }(); var A = /*#__PURE__*/function (_R2) { function A(t) { var _this4; _classCallCheck(this, A); _this4 = _callSuper(this, A), _this4.Yt = t; return _this4; } _inherits(A, _R2); return _createClass(A, [{ key: "et", value: function et(_ref2) { var t = _ref2.context, i = _ref2.bitmapSize, s = _ref2.horizontalPixelRatio, n = _ref2.verticalPixelRatio; if (null === this.Yt) return; var e = this.Yt.jt.Vt, r = this.Yt.Kt.Vt; if (!e && !r) return; var h = Math.round(this.Yt._t * s), o = Math.round(this.Yt.ut * n); t.lineCap = "butt", e && h >= 0 && (t.lineWidth = Math.floor(this.Yt.jt.ct * s), t.strokeStyle = this.Yt.jt.R, t.fillStyle = this.Yt.jt.R, a(t, this.Yt.jt.Xt), function (t, i, s, n) { t.beginPath(); var e = t.lineWidth % 2 ? .5 : 0; t.moveTo(i + e, s), t.lineTo(i + e, n), t.stroke(); }(t, h, 0, i.height)), r && o >= 0 && (t.lineWidth = Math.floor(this.Yt.Kt.ct * n), t.strokeStyle = this.Yt.Kt.R, t.fillStyle = this.Yt.Kt.R, a(t, this.Yt.Kt.Xt), l(t, o, 0, i.width)); } }]); }(R); var E = /*#__PURE__*/function () { function E(t, i) { _classCallCheck(this, E); this.xt = true, this.Zt = { jt: { ct: 1, Xt: 0, R: "", Vt: false }, Kt: { ct: 1, Xt: 0, R: "", Vt: false }, _t: 0, ut: 0 }, this.Gt = new A(this.Zt), this.Jt = t, this.yt = i; } return _createClass(E, [{ key: "kt", value: function kt() { this.xt = true; } }, { key: "Tt", value: function Tt(t) { return this.xt && (this.Rt(), this.xt = false), this.Gt; } }, { key: "Rt", value: function Rt() { var t = this.Jt.Vt(), i = this.yt.Qt().N().crosshair, s = this.Zt; if (2 === i.mode) return s.Kt.Vt = false, void (s.jt.Vt = false); s.Kt.Vt = t && this.Jt.ti(this.yt), s.jt.Vt = t && this.Jt.ii(), s.Kt.ct = i.horzLine.width, s.Kt.Xt = i.horzLine.style, s.Kt.R = i.horzLine.color, s.jt.ct = i.vertLine.width, s.jt.Xt = i.vertLine.style, s.jt.R = i.vertLine.color, s._t = this.Jt.si(), s.ut = this.Jt.ni(); } }]); }(); function L(t, i, s, n, e, r) { t.save(), t.globalCompositeOperation = "copy", t.fillStyle = r, t.fillRect(i, s, n, e), t.restore(); } function O(t, i, s, n, e, r) { t.beginPath(), t.roundRect ? t.roundRect(i, s, n, e, r) : (t.lineTo(i + n - r[1], s), 0 !== r[1] && t.arcTo(i + n, s, i + n, s + r[1], r[1]), t.lineTo(i + n, s + e - r[2]), 0 !== r[2] && t.arcTo(i + n, s + e, i + n - r[2], s + e, r[2]), t.lineTo(i + r[3], s + e), 0 !== r[3] && t.arcTo(i, s + e, i, s + e - r[3], r[3]), t.lineTo(i, s + r[0]), 0 !== r[0] && t.arcTo(i, s, i + r[0], s, r[0])); } function N(t, i, s, n, e, r) { var h = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 0; var a = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : [0, 0, 0, 0]; var l = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : ""; if (t.save(), !h || !l || l === r) return O(t, i, s, n, e, a), t.fillStyle = r, t.fill(), void t.restore(); var o = h / 2; var _; O(t, i + o, s + o, n - h, e - h, (_ = -o, a.map(function (t) { return 0 === t ? t : t + _; }))), "transparent" !== r && (t.fillStyle = r, t.fill()), "transparent" !== l && (t.lineWidth = h, t.strokeStyle = l, t.closePath(), t.stroke()), t.restore(); } function W(t, i, s, n, e, r, h) { t.save(), t.globalCompositeOperation = "copy"; var a = t.createLinearGradient(0, 0, 0, e); a.addColorStop(0, r), a.addColorStop(1, h), t.fillStyle = a, t.fillRect(i, s, n, e), t.restore(); } var F = /*#__PURE__*/function () { function F(t, i) { _classCallCheck(this, F); this.ht(t, i); } return _createClass(F, [{ key: "ht", value: function ht(t, i) { this.Yt = t, this.ei = i; } }, { key: "$t", value: function $t(t, i) { return this.Yt.Vt ? t.k + t.A + t.V : 0; } }, { key: "nt", value: function nt(t, i, s, n) { var _this5 = this; if (!this.Yt.Vt || 0 === this.Yt.ri.length) return; var e = this.Yt.R, r = this.ei.Z, h = t.useBitmapCoordinateSpace(function (t) { var h = t.context; h.font = i.P; var a = _this5.hi(t, i, s, n), l = a.ai; return a.li ? N(h, l.oi, l._i, l.ui, l.ci, r, l.di, [l.ft, 0, 0, l.ft], r) : N(h, l.fi, l._i, l.ui, l.ci, r, l.di, [0, l.ft, l.ft, 0], r), _this5.Yt.pi && (h.fillStyle = e, h.fillRect(l.fi, l.mi, l.wi - l.fi, l.gi)), _this5.Yt.Mi && (h.fillStyle = i.D, h.fillRect(a.li ? l.bi - l.di : 0, l._i, l.di, l.Si - l._i)), a; }); t.useMediaCoordinateSpace(function (_ref3) { var t = _ref3.context; var s = h.xi; t.font = i.P, t.textAlign = h.li ? "right" : "left", t.textBaseline = "middle", t.fillStyle = e, t.fillText(_this5.Yt.ri, s.Ci, (s._i + s.Si) / 2 + s.yi); }); } }, { key: "hi", value: function hi(t, i, s, n) { var _this$ei$Ii; var e = t.context, r = t.bitmapSize, h = t.mediaSize, a = t.horizontalPixelRatio, l = t.verticalPixelRatio, o = this.Yt.pi || !this.Yt.ki ? i.C : 0, _ = this.Yt.Pi ? i.S : 0, u = i.A + this.ei.Ti, c = i.V + this.ei.Ri, d = i.I, f = i.B, p = this.Yt.ri, v = i.k, m = s.Di(e, p), w = Math.ceil(s.Vi(e, p)), g = v + u + c, M = i.S + d + f + w + o, b = Math.max(1, Math.floor(l)); var S = Math.round(g * l); S % 2 != b % 2 && (S += 1); var x = _ > 0 ? Math.max(1, Math.floor(_ * a)) : 0, C = Math.round(M * a), y = Math.round(o * a), k = (_this$ei$Ii = this.ei.Ii) !== null && _this$ei$Ii !== void 0 ? _this$ei$Ii : this.ei.Bi, P = Math.round(k * l) - Math.floor(.5 * l), T = Math.floor(P + b / 2 - S / 2), R = T + S, D = "right" === n, V = D ? h.width - _ : _, I = D ? r.width - x : x; var B, A, E; return D ? (B = I - C, A = I - y, E = V - o - d - _) : (B = I + C, A = I + y, E = V + o + d), { li: D, ai: { _i: T, mi: P, Si: R, ui: C, ci: S, ft: 2 * a, di: x, oi: B, fi: I, wi: A, gi: b, bi: r.width }, xi: { _i: T / l, Si: R / l, Ci: E, yi: m } }; } }]); }(); var H = /*#__PURE__*/function () { function H(t) { _classCallCheck(this, H); this.Ai = { Bi: 0, Z: "#000", Ri: 0, Ti: 0 }, this.Ei = { ri: "", Vt: false, pi: true, ki: false, Ht: "", R: "#FFF", Mi: false, Pi: false }, this.zi = { ri: "", Vt: false, pi: false, ki: true, Ht: "", R: "#FFF", Mi: true, Pi: true }, this.xt = true, this.Li = new (t || F)(this.Ei, this.Ai), this.Oi = new (t || F)(this.zi, this.Ai); } return _createClass(H, [{ key: "ri", value: function ri() { return this.Ni(), this.Ei.ri; } }, { key: "Bi", value: function Bi() { return this.Ni(), this.Ai.Bi; } }, { key: "kt", value: function kt() { this.xt = true; } }, { key: "$t", value: function $t(t) { var i = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; return Math.max(this.Li.$t(t, i), this.Oi.$t(t, i)); } }, { key: "Wi", value: function Wi() { return this.Ai.Ii || 0; } }, { key: "Fi", value: function Fi(t) { this.Ai.Ii = t; } }, { key: "Hi", value: function Hi() { return this.Ni(), this.Ei.Vt || this.