@devexperts/dxcharts-lite 1.0.2 → 2.0.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.
- package/README.md +2 -2
- package/dist/chart/animation/canvas-animation.js +134 -1
- package/dist/chart/animation/types/animation.js +43 -1
- package/dist/chart/animation/types/color-alpha-animation.d.ts +1 -1
- package/dist/chart/animation/types/color-alpha-animation.js +60 -1
- package/dist/chart/animation/types/color-transition-animation.d.ts +1 -1
- package/dist/chart/animation/types/color-transition-animation.js +86 -1
- package/dist/chart/animation/types/viewport-movement-animation.js +63 -1
- package/dist/chart/animation/viewport-model-animation.js +20 -1
- package/dist/chart/bootstrap.d.ts +51 -48
- package/dist/chart/bootstrap.js +449 -1
- package/dist/chart/canvas/canvas-bounds-container.d.ts +0 -5
- package/dist/chart/canvas/canvas-bounds-container.js +815 -1
- package/dist/chart/canvas/canvas-chart-html.js +16 -18
- package/dist/chart/canvas/chart-elements.d.ts +1 -4
- package/dist/chart/canvas/chart-elements.js +22 -1
- package/dist/chart/canvas/cursor.handler.js +122 -1
- package/dist/chart/canvas/layout-creator.js +34 -1
- package/dist/chart/canvas/y-axis-bounds.container.d.ts +2 -2
- package/dist/chart/canvas/y-axis-bounds.container.js +67 -1
- package/dist/chart/chart-container.js +1 -1
- package/dist/chart/chart.config.d.ts +4 -5
- package/dist/chart/chart.config.js +645 -1
- package/dist/chart/chart.d.ts +62 -0
- package/dist/chart/chart.js +106 -0
- package/dist/chart/components/chart/basic-scale.d.ts +2 -2
- package/dist/chart/components/chart/basic-scale.js +31 -1
- package/dist/chart/components/chart/candle-transformer.functions.js +15 -1
- package/dist/chart/components/chart/candle-width-calculator.functions.js +2 -1
- package/dist/chart/components/chart/candle.functions.js +44 -1
- package/dist/chart/components/chart/chart-area-pan.handler.d.ts +3 -3
- package/dist/chart/components/chart/chart-area-pan.handler.js +197 -1
- package/dist/chart/components/chart/chart-base.model.js +66 -1
- package/dist/chart/components/chart/chart.component.d.ts +7 -3
- package/dist/chart/components/chart/chart.component.js +408 -1
- package/dist/chart/components/chart/chart.model.d.ts +4 -11
- package/dist/chart/components/chart/chart.model.js +954 -1
- package/dist/chart/components/chart/data-series.high-low-provider.js +34 -1
- package/dist/chart/components/chart/fake-candles.js +97 -1
- package/dist/chart/components/chart/price.formatter.js +35 -1
- package/dist/chart/components/chart/secondary-chart-colors-pool.js +68 -1
- package/dist/chart/components/cross_tool/cross-tool.component.js +85 -1
- package/dist/chart/components/cross_tool/cross-tool.drawer.js +32 -1
- package/dist/chart/components/cross_tool/cross-tool.model.js +107 -1
- package/dist/chart/components/cross_tool/types/cross-and-labels.drawer.js +137 -1
- package/dist/chart/components/cross_tool/types/none.drawer.js +3 -1
- package/dist/chart/components/dran-n-drop_helper/drag-n-drop-x.component.js +28 -1
- package/dist/chart/components/dran-n-drop_helper/drag-n-drop-y.component.js +24 -1
- package/dist/chart/components/dran-n-drop_helper/drag-n-drop.component.js +53 -1
- package/dist/chart/components/dynamic-objects/dynamic-objects.component.d.ts +13 -0
- package/dist/chart/components/dynamic-objects/dynamic-objects.component.js +20 -0
- package/dist/chart/components/dynamic-objects/dynamic-objects.drawer.d.ts +18 -0
- package/dist/chart/components/dynamic-objects/dynamic-objects.drawer.js +23 -0
- package/dist/chart/components/dynamic-objects/dynamic-objects.model.d.ts +63 -0
- package/dist/chart/components/dynamic-objects/dynamic-objects.model.js +136 -0
- package/dist/chart/components/events/events-hit-test.drawer.js +63 -1
- package/dist/chart/components/events/events.component.js +61 -1
- package/dist/chart/components/events/events.drawer.js +195 -1
- package/dist/chart/components/events/events.model.js +69 -1
- package/dist/chart/components/grid/grid.component.d.ts +2 -2
- package/dist/chart/components/grid/grid.component.js +31 -1
- package/dist/chart/components/grid/grid.drawer.d.ts +4 -3
- package/dist/chart/components/grid/grid.drawer.js +106 -1
- package/dist/chart/components/high_low/high-low.component.js +12 -1
- package/dist/chart/components/high_low/high-low.drawer.js +126 -1
- package/dist/chart/components/highlights/highlights.component.js +46 -1
- package/dist/chart/components/highlights/highlights.drawer.js +154 -1
- package/dist/chart/components/highlights/highlights.model.js +75 -1
- package/dist/chart/components/labels_generator/numeric-axis-labels.generator.d.ts +1 -1
- package/dist/chart/components/labels_generator/numeric-axis-labels.generator.js +199 -1
- package/dist/chart/components/navigation_map/navigation-map-move.handler.d.ts +2 -2
- package/dist/chart/components/navigation_map/navigation-map-move.handler.js +108 -1
- package/dist/chart/components/navigation_map/navigation-map.component.js +112 -1
- package/dist/chart/components/navigation_map/navigation-map.drawer.js +244 -1
- package/dist/chart/components/navigation_map/navigation-map.model.js +33 -2
- package/dist/chart/components/pan/chart-pan.component.d.ts +2 -2
- package/dist/chart/components/pan/chart-pan.component.js +51 -1
- package/dist/chart/components/pane/extent/y-extent-component.d.ts +12 -18
- package/dist/chart/components/pane/extent/y-extent-component.js +120 -1
- package/dist/chart/components/pane/pane-hit-test.controller.js +55 -1
- package/dist/chart/components/pane/pane-manager.component.d.ts +10 -5
- package/dist/chart/components/pane/pane-manager.component.js +148 -1
- package/dist/chart/components/pane/pane.component.d.ts +16 -32
- package/dist/chart/components/pane/pane.component.js +278 -1
- package/dist/chart/components/resizer/bar-resizer.component.js +139 -1
- package/dist/chart/components/resizer/bar-resizer.drawer.js +46 -1
- package/dist/chart/components/snapshot/snapshot.component.js +48 -1
- package/dist/chart/components/volumes/separate-volumes.component.d.ts +6 -10
- package/dist/chart/components/volumes/separate-volumes.component.js +63 -1
- package/dist/chart/components/volumes/volume-color-resolvers.functions.js +18 -1
- package/dist/chart/components/volumes/volumes.component.d.ts +6 -7
- package/dist/chart/components/volumes/volumes.component.js +94 -1
- package/dist/chart/components/volumes/volumes.drawer.d.ts +5 -12
- package/dist/chart/components/volumes/volumes.drawer.js +140 -1
- package/dist/chart/components/volumes/volumes.formatter.js +31 -1
- package/dist/chart/components/volumes/volumes.model.d.ts +2 -2
- package/dist/chart/components/volumes/volumes.model.js +43 -1
- package/dist/chart/components/watermark/water-mark.component.js +103 -1
- package/dist/chart/components/watermark/water-mark.drawer.js +187 -1
- package/dist/chart/components/x_axis/numeric-x-axis-labels.generator.js +27 -1
- package/dist/chart/components/x_axis/time/parser/time-formats-matchers.functions.js +187 -1
- package/dist/chart/components/x_axis/time/parser/time-formats-parser.functions.js +76 -1
- package/dist/chart/components/x_axis/time/parser/time-formats-validators.functions.js +79 -1
- package/dist/chart/components/x_axis/time/parser/time-formats.model.js +14 -1
- package/dist/chart/components/x_axis/time/x-axis-weights.functions.d.ts +1 -1
- package/dist/chart/components/x_axis/time/x-axis-weights.functions.js +143 -1
- package/dist/chart/components/x_axis/time/x-axis-weights.generator.js +73 -1
- package/dist/chart/components/x_axis/x-axis-draw.functions.js +49 -1
- package/dist/chart/components/x_axis/x-axis-labels.drawer.js +70 -1
- package/dist/chart/components/x_axis/x-axis-labels.generator.d.ts +2 -2
- package/dist/chart/components/x_axis/x-axis-labels.generator.js +332 -1
- package/dist/chart/components/x_axis/x-axis-labels.model.js +35 -1
- package/dist/chart/components/x_axis/x-axis-scale.handler.d.ts +2 -2
- package/dist/chart/components/x_axis/x-axis-scale.handler.js +60 -1
- package/dist/chart/components/x_axis/x-axis-time-labels.drawer.js +82 -1
- package/dist/chart/components/x_axis/x-axis.component.d.ts +2 -2
- package/dist/chart/components/x_axis/x-axis.component.js +119 -1
- package/dist/chart/components/y_axis/label-color.functions.js +53 -1
- package/dist/chart/components/y_axis/numeric-y-axis-labels.generator.d.ts +4 -4
- package/dist/chart/components/y_axis/numeric-y-axis-labels.generator.js +33 -1
- package/dist/chart/components/y_axis/price_labels/data-series-y-axis-labels.provider.d.ts +3 -3
- package/dist/chart/components/y_axis/price_labels/data-series-y-axis-labels.provider.js +67 -1
- package/dist/chart/components/y_axis/price_labels/labels-positions-calculator.js +56 -1
- package/dist/chart/components/y_axis/price_labels/last-candle-labels.provider.js +95 -1
- package/dist/chart/components/y_axis/price_labels/price-label.drawer.d.ts +2 -2
- package/dist/chart/components/y_axis/price_labels/price-label.drawer.js +119 -1
- package/dist/chart/components/y_axis/price_labels/y-axis-labels.model.d.ts +9 -8
- package/dist/chart/components/y_axis/price_labels/y-axis-labels.model.js +201 -1
- package/dist/chart/components/y_axis/price_labels/y-axis-price-labels.drawer.d.ts +6 -7
- package/dist/chart/components/y_axis/price_labels/y-axis-price-labels.drawer.js +58 -1
- package/dist/chart/components/y_axis/y-axis-base-labels.model.d.ts +6 -4
- package/dist/chart/components/y_axis/y-axis-base-labels.model.js +47 -1
- package/dist/chart/components/y_axis/y-axis-labels.drawer.d.ts +4 -4
- package/dist/chart/components/y_axis/y-axis-labels.drawer.js +161 -1
- package/dist/chart/components/y_axis/y-axis-scale.handler.d.ts +2 -2
- package/dist/chart/components/y_axis/y-axis-scale.handler.js +72 -1
- package/dist/chart/components/y_axis/y-axis.component.d.ts +32 -41
- package/dist/chart/components/y_axis/y-axis.component.js +220 -1
- package/dist/chart/components/y_axis/y-axis.drawer.d.ts +9 -12
- package/dist/chart/components/y_axis/y-axis.drawer.js +96 -1
- package/dist/chart/components/y_axis/y-axis.model.d.ts +9 -17
- package/dist/chart/components/y_axis/y-axis.model.js +33 -1
- package/dist/chart/drawers/chart-background.drawer.js +69 -1
- package/dist/chart/drawers/chart-type-drawers/area.drawer.js +69 -1
- package/dist/chart/drawers/chart-type-drawers/bar.drawer.js +57 -1
- package/dist/chart/drawers/chart-type-drawers/baseline.drawer.js +84 -1
- package/dist/chart/drawers/chart-type-drawers/candle.drawer.js +162 -1
- package/dist/chart/drawers/chart-type-drawers/histogram.drawer.js +57 -1
- package/dist/chart/drawers/chart-type-drawers/line.drawer.js +38 -1
- package/dist/chart/drawers/chart-type-drawers/scatter-plot.drawer.js +19 -1
- package/dist/chart/drawers/clear-canvas.drawer.js +14 -1
- package/dist/chart/drawers/composite.drawer.js +67 -1
- package/dist/chart/drawers/data-series-drawers/candle-series-wrapper.js +50 -1
- package/dist/chart/drawers/data-series-drawers/color-candle.drawer.js +35 -1
- package/dist/chart/drawers/data-series-drawers/data-series-drawers.utils.js +16 -1
- package/dist/chart/drawers/data-series-drawers/difference-cloud.drawer.js +106 -1
- package/dist/chart/drawers/data-series-drawers/histogram.drawer.js +23 -1
- package/dist/chart/drawers/data-series-drawers/linear.drawer.js +19 -1
- package/dist/chart/drawers/data-series-drawers/points.drawer.js +19 -1
- package/dist/chart/drawers/data-series-drawers/rectangular-tool.drawer.js +7 -1
- package/dist/chart/drawers/data-series-drawers/text.drawer.js +25 -1
- package/dist/chart/drawers/data-series-drawers/trend-histogram.drawer.js +35 -1
- package/dist/chart/drawers/data-series-drawers/triangle.drawer.js +22 -1
- package/dist/chart/drawers/data-series.drawer.d.ts +5 -7
- package/dist/chart/drawers/data-series.drawer.js +56 -1
- package/dist/chart/drawers/drawing-manager.d.ts +1 -1
- package/dist/chart/drawers/drawing-manager.js +177 -1
- package/dist/chart/drawers/ht-data-series.drawer.js +37 -1
- package/dist/chart/events/event-bus.js +73 -1
- package/dist/chart/events/events.js +3 -1
- package/dist/chart/inputhandlers/candle-tap.handler.js +46 -1
- package/dist/chart/inputhandlers/chart-resize.handler.js +98 -1
- package/dist/chart/inputhandlers/cross-event-producer.component.js +67 -1
- package/dist/chart/inputhandlers/hover-producer.component.d.ts +2 -2
- package/dist/chart/inputhandlers/hover-producer.component.js +228 -1
- package/dist/chart/inputhandlers/main-canvas-touch.handler.d.ts +2 -2
- package/dist/chart/inputhandlers/main-canvas-touch.handler.js +80 -1
- package/dist/chart/inputlisteners/canvas-input-listener.component.js +629 -1
- package/dist/chart/model/baseline.model.js +88 -1
- package/dist/chart/model/bounds.model.js +1 -1
- package/dist/chart/model/candle-hover.js +70 -1
- package/dist/chart/model/candle-series-high-low.provider.js +45 -1
- package/dist/chart/model/candle-series.model.d.ts +3 -3
- package/dist/chart/model/candle-series.model.js +245 -1
- package/dist/chart/model/candle.model.js +69 -1
- package/dist/chart/model/canvas.model.js +228 -1
- package/dist/chart/model/chart-base-element.js +129 -1
- package/dist/chart/model/compare-series-hover.js +25 -1
- package/dist/chart/model/data-series-view.d.ts +5 -5
- package/dist/chart/model/data-series-view.js +111 -1
- package/dist/chart/model/data-series.config.js +14 -1
- package/dist/chart/model/data-series.model.d.ts +4 -4
- package/dist/chart/model/data-series.model.js +281 -1
- package/dist/chart/model/date-time.formatter.js +151 -1
- package/dist/chart/model/hit-test-canvas.model.d.ts +1 -1
- package/dist/chart/model/hit-test-canvas.model.js +256 -1
- package/dist/chart/model/main-candle-series.model.d.ts +1 -1
- package/dist/chart/model/main-candle-series.model.js +29 -1
- package/dist/chart/model/scale.model.d.ts +2 -1
- package/dist/chart/model/scale.model.js +316 -1
- package/dist/chart/model/scaling/auto-scale.model.js +97 -1
- package/dist/chart/model/scaling/constrait.functions.js +61 -1
- package/dist/chart/model/scaling/lock-ratio.model.js +17 -1
- package/dist/chart/model/scaling/move-chart.functions.js +22 -1
- package/dist/chart/model/scaling/viewport.model.d.ts +2 -2
- package/dist/chart/model/scaling/viewport.model.js +279 -1
- package/dist/chart/model/scaling/x-zooming.functions.js +35 -1
- package/dist/chart/model/time-zone.model.js +109 -1
- package/dist/chart/model/visual-candle.js +134 -1
- package/dist/chart/utils/__tests__/array.utils.test.js +135 -1
- package/dist/chart/utils/__tests__/math.utils.test.js +14 -1
- package/dist/chart/utils/__tests__/object.utils.test.js +11 -1
- package/dist/chart/utils/__tests__/priceIncrementsUtils.test.js +29 -1
- package/dist/chart/utils/array.utils.d.ts +1 -1
- package/dist/chart/utils/array.utils.js +269 -1
- package/dist/chart/utils/auto-period-detector.utils.js +39 -1
- package/dist/chart/utils/candles-generator-ts.utils.js +20 -1
- package/dist/chart/utils/candles-generator.utils.js +161 -1
- package/dist/chart/utils/candles.utils.js +42 -1
- package/dist/chart/utils/canvas/canvas-drawing-functions.utils.js +144 -1
- package/dist/chart/utils/canvas/canvas-font-measure-tool.utils.js +51 -1
- package/dist/chart/utils/canvas/canvas-text-functions.utils.js +156 -1
- package/dist/chart/utils/color.utils.js +31 -1
- package/dist/chart/utils/device/browser.utils.js +10 -1
- package/dist/chart/utils/device/device-detector.utils.js +24 -1
- package/dist/chart/utils/device/device-pixel-ratio.utils.js +21 -1
- package/dist/chart/utils/device/touchpad.utils.js +91 -1
- package/dist/chart/utils/dom.utils.js +15 -1
- package/dist/chart/utils/function.utils.js +16 -1
- package/dist/chart/utils/linkedList.utils.d.ts +28 -0
- package/dist/chart/utils/linkedList.utils.js +138 -0
- package/dist/chart/utils/math.utils.js +115 -1
- package/dist/chart/utils/merge.utils.js +56 -1
- package/dist/chart/utils/object.utils.js +43 -1
- package/dist/chart/utils/performance/animation-frame-cache.utils.js +77 -0
- package/dist/chart/utils/{perfomance → performance}/debounce.utils.js +7 -1
- package/dist/chart/utils/performance/memoize.utils.js +74 -0
- package/dist/chart/utils/performance/request-animation-frame-throttle.utils.js +43 -0
- package/dist/chart/utils/performance/throttle.utils.js +26 -0
- package/dist/chart/utils/price-increments.utils.d.ts +1 -0
- package/dist/chart/utils/price-increments.utils.js +127 -1
- package/dist/chart/utils/uuid.utils.js +4 -1
- package/dist/dxchart.min.js +9 -12
- package/dist/index.d.ts +3 -3
- package/dist/index.js +20 -1
- package/package.json +4 -4
- package/dist/chart/utils/perfomance/animation-frame-cache.utils.js +0 -6
- package/dist/chart/utils/perfomance/memoize.utils.js +0 -6
- package/dist/chart/utils/perfomance/request-animation-frame-throttle.utils.js +0 -6
- package/dist/chart/utils/perfomance/throttle.utils.js +0 -6
- /package/dist/chart/utils/{perfomance → performance}/animation-frame-cache.utils.d.ts +0 -0
- /package/dist/chart/utils/{perfomance → performance}/debounce.utils.d.ts +0 -0
- /package/dist/chart/utils/{perfomance → performance}/memoize.utils.d.ts +0 -0
- /package/dist/chart/utils/{perfomance → performance}/request-animation-frame-throttle.utils.d.ts +0 -0
- /package/dist/chart/utils/{perfomance → performance}/throttle.utils.d.ts +0 -0
|
@@ -3,4 +3,34 @@
|
|
|
3
3
|
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
|
4
4
|
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
5
|
*/
|
|
6
|
-
const
|
|
6
|
+
const HEX_COLOR_REGEXP = /^(#)([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i;
|
|
7
|
+
const RGB_COLOR_REGEXP = /^\s*(rgba?)\s*[(]\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*[\d.]+\s*)?[)]\s*$/i;
|
|
8
|
+
function parseColor(color) {
|
|
9
|
+
const match = HEX_COLOR_REGEXP.exec(color) || RGB_COLOR_REGEXP.exec(color);
|
|
10
|
+
let colors = [];
|
|
11
|
+
if (match) {
|
|
12
|
+
colors = match.slice(2, 5);
|
|
13
|
+
if (match[1] === '#') {
|
|
14
|
+
return colors.map(function (s) {
|
|
15
|
+
return parseInt(s, 16);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return colors;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @param {String} color
|
|
24
|
+
* @param {Number} alpha
|
|
25
|
+
* @returns {String}
|
|
26
|
+
*/
|
|
27
|
+
const rgbaCache = {};
|
|
28
|
+
export function toRGBA(color, alpha) {
|
|
29
|
+
let result = rgbaCache[color + alpha];
|
|
30
|
+
if (!result) {
|
|
31
|
+
const colors = parseColor(color);
|
|
32
|
+
result = colors && 'rgba(' + colors.join(',') + ',' + alpha + ')';
|
|
33
|
+
rgbaCache[color + alpha] = result;
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
@@ -3,4 +3,13 @@
|
|
|
3
3
|
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
|
4
4
|
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
5
|
*/
|
|
6
|
-
let
|
|
6
|
+
let isMobileCache = undefined;
|
|
7
|
+
/**
|
|
8
|
+
* @doc-tags utility,mobile
|
|
9
|
+
*/
|
|
10
|
+
export const isMobile = () => {
|
|
11
|
+
if (!isMobileCache) {
|
|
12
|
+
isMobileCache = !!navigator.userAgent.match(/Android|iPhone|Opera Mini/) || false;
|
|
13
|
+
}
|
|
14
|
+
return isMobileCache;
|
|
15
|
+
};
|
|
@@ -3,4 +3,27 @@
|
|
|
3
3
|
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
|
4
4
|
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Detects the user device. Naive approach.
|
|
8
|
+
* @doc-tags tricky,mobile
|
|
9
|
+
*/
|
|
10
|
+
export const deviceDetector = () => {
|
|
11
|
+
const isApple = /Mac|iPod|iPhone|iPad/i.test(navigator.userAgent);
|
|
12
|
+
const mobileMatch = [/Android/i, /webOS/i, /BlackBerry/i, /Windows Phone/i];
|
|
13
|
+
const isMobile = mobileMatch.some(os => {
|
|
14
|
+
return navigator.userAgent.match(os);
|
|
15
|
+
});
|
|
16
|
+
if (isApple) {
|
|
17
|
+
return 'apple';
|
|
18
|
+
}
|
|
19
|
+
if (isMobile) {
|
|
20
|
+
return 'mobile';
|
|
21
|
+
}
|
|
22
|
+
return 'other';
|
|
23
|
+
};
|
|
24
|
+
export const multiplyZoomByDevice = (device, defaultValue) => {
|
|
25
|
+
if (device === 'apple' || device === 'mobile') {
|
|
26
|
+
return 3;
|
|
27
|
+
}
|
|
28
|
+
return defaultValue;
|
|
29
|
+
};
|
|
@@ -3,4 +3,24 @@
|
|
|
3
3
|
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
|
4
4
|
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
5
|
*/
|
|
6
|
-
import{ceil
|
|
6
|
+
import { ceil, floor, round } from '../math.utils';
|
|
7
|
+
export let dpr = window.devicePixelRatio;
|
|
8
|
+
// A media matcher which watches for changes in the device pixel ratio.
|
|
9
|
+
let mediaMatcher = window.matchMedia(`screen and (resolution: ${window.devicePixelRatio}dppx)`);
|
|
10
|
+
const updateDevicePixelRatio = () => {
|
|
11
|
+
mediaMatcher.removeEventListener('change', updateDevicePixelRatio);
|
|
12
|
+
dpr = window.devicePixelRatio;
|
|
13
|
+
mediaMatcher = window.matchMedia(`screen and (resolution: ${window.devicePixelRatio}dppx)`);
|
|
14
|
+
mediaMatcher.addEventListener('change', updateDevicePixelRatio);
|
|
15
|
+
};
|
|
16
|
+
mediaMatcher.addEventListener('change', updateDevicePixelRatio);
|
|
17
|
+
export const getDPR = () => dpr;
|
|
18
|
+
/**
|
|
19
|
+
* Rounds a given number according to the inverse of current DPR.
|
|
20
|
+
* For example, DPR = 2, num = 2, res => 2; DPR = 2, num = 2.5, res => 2.5; DPR = 2, num = 2.333, res => 2.5
|
|
21
|
+
* @param num
|
|
22
|
+
* @doc-tags chart-core,math,dpr
|
|
23
|
+
*/
|
|
24
|
+
export const roundToDPR = (num) => round(dpr * num) / dpr;
|
|
25
|
+
export const floorToDPR = (num) => floor(dpr * num) / dpr;
|
|
26
|
+
export const ceilToDPR = (num) => ceil(dpr * num) / dpr;
|
|
@@ -3,4 +3,94 @@
|
|
|
3
3
|
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
|
4
4
|
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
5
|
*/
|
|
6
|
-
const
|
|
6
|
+
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
|
7
|
+
//@ts-ignore
|
|
8
|
+
const isChrome = !!window.chrome;
|
|
9
|
+
//@ts-ignore
|
|
10
|
+
export const isFirefox = typeof InstallTrigger !== 'undefined';
|
|
11
|
+
const isWindows = navigator.platform.indexOf('Win') > -1;
|
|
12
|
+
/**
|
|
13
|
+
* this function determines whether the event was triggered with the mouse or the touchpad
|
|
14
|
+
*
|
|
15
|
+
* This works because wheelDeltaY measures the physical distance that the actual hardware mouse wheel has travelled,
|
|
16
|
+
* while deltaY measures the amount of scrolling produced on screen.
|
|
17
|
+
* A conventional mouse typically has a much lower "scroll resolution" than a trackpad.
|
|
18
|
+
* The wheelDeltaY is exactly 3x the deltaY value(in most browsers)
|
|
19
|
+
* This function consist a lot of empiric if statements for some cases in different browsers and systems
|
|
20
|
+
* @param {WheelEvent} e
|
|
21
|
+
* @returns {boolean}
|
|
22
|
+
*
|
|
23
|
+
* @doc-tags chart-core, utility,
|
|
24
|
+
*/
|
|
25
|
+
export const touchpadDetector = (e) => {
|
|
26
|
+
let isTouchpad = false;
|
|
27
|
+
// this is essential prop to separate touchpad from mouse wheel
|
|
28
|
+
//@ts-ignore
|
|
29
|
+
const { wheelDeltaY, wheelDeltaX } = e;
|
|
30
|
+
if (wheelDeltaY || wheelDeltaX) {
|
|
31
|
+
let condition;
|
|
32
|
+
if (isSafari) {
|
|
33
|
+
condition =
|
|
34
|
+
wheelDeltaY === e.deltaY * -3 ||
|
|
35
|
+
Math.abs(wheelDeltaY + Math.sign(wheelDeltaY)) === Math.abs(Math.round(e.deltaY) * 3) ||
|
|
36
|
+
Math.abs(wheelDeltaY - Math.sign(wheelDeltaY)) === Math.abs(Math.round(e.deltaY) * 3);
|
|
37
|
+
}
|
|
38
|
+
else if (isChrome) {
|
|
39
|
+
condition =
|
|
40
|
+
wheelDeltaY + Math.sign(wheelDeltaY) === e.deltaY * -3
|
|
41
|
+
? wheelDeltaY + Math.sign(wheelDeltaY) === e.deltaY * -3
|
|
42
|
+
: wheelDeltaY === e.deltaY * -3;
|
|
43
|
+
// Chrome windows case
|
|
44
|
+
if (isWindows) {
|
|
45
|
+
const diapazoneCondition = Math.round(e.deltaY) === wheelDeltaY ||
|
|
46
|
+
Math.abs(Math.round(e.deltaY) + Math.sign(e.deltaY)) === Math.abs(wheelDeltaY) ||
|
|
47
|
+
Math.abs(Math.round(e.deltaY) - Math.sign(e.deltaY)) === Math.abs(wheelDeltaY);
|
|
48
|
+
const equalCondition = Math.abs(wheelDeltaY) === Math.abs(e.deltaY);
|
|
49
|
+
condition = equalCondition || diapazoneCondition;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else if (isFirefox) {
|
|
53
|
+
if (Math.abs(e.deltaY) > Math.abs(e.deltaX)) {
|
|
54
|
+
// disable vertical scroll in Firefox bcs it is unstable
|
|
55
|
+
condition = false;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
condition = wheelDeltaX === e.deltaX * -3;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
// basic rule
|
|
63
|
+
condition = wheelDeltaY === e.deltaY * -3;
|
|
64
|
+
}
|
|
65
|
+
if (condition) {
|
|
66
|
+
isTouchpad = true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else if (e.deltaMode === 0) {
|
|
70
|
+
isTouchpad = true;
|
|
71
|
+
}
|
|
72
|
+
// Firefox for some reason is not obey to rules above
|
|
73
|
+
// so we just this trigger this as mouse wheel event
|
|
74
|
+
if (isFirefox && e.deltaY >= 16 && Math.abs(e.deltaY) % 16 === 0) {
|
|
75
|
+
isTouchpad = false;
|
|
76
|
+
}
|
|
77
|
+
// it is necessary to correctly recognize pinch on touchpad
|
|
78
|
+
// could be emulated mouse wheel + ctrl key BE AWARE!!
|
|
79
|
+
if (e.ctrlKey) {
|
|
80
|
+
isTouchpad = true;
|
|
81
|
+
}
|
|
82
|
+
return isTouchpad;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* this function returns different ящщь sensitivity for the percent axis and the others
|
|
86
|
+
* @param config
|
|
87
|
+
* @param isTouchpad
|
|
88
|
+
* @returns {number}
|
|
89
|
+
*
|
|
90
|
+
* @doc-tags chart-core, zoom
|
|
91
|
+
*/
|
|
92
|
+
export const getTouchpadSensitivity = (config) => {
|
|
93
|
+
const isPercentAxisType = config.components.yAxis.type === 'percent';
|
|
94
|
+
const zoomSensitivity = isPercentAxisType ? config.scale.zoomSensitivity / 4 : config.scale.zoomSensitivity;
|
|
95
|
+
return zoomSensitivity;
|
|
96
|
+
};
|
|
@@ -3,4 +3,18 @@
|
|
|
3
3
|
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
|
4
4
|
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* @param {Element} element
|
|
8
|
+
* @param {function} listener
|
|
9
|
+
* @param {string} eventType
|
|
10
|
+
* @param {boolean?} useCapture
|
|
11
|
+
* @return {Function}
|
|
12
|
+
*/
|
|
13
|
+
export function subscribeListener(element, listener, eventType, useCapture) {
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
element.addEventListener(eventType, listener, useCapture);
|
|
16
|
+
return function () {
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
element.removeEventListener(eventType, listener, useCapture);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -3,4 +3,19 @@
|
|
|
3
3
|
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
|
4
4
|
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
5
|
*/
|
|
6
|
-
export function clearerSafe(
|
|
6
|
+
export function clearerSafe(arr) {
|
|
7
|
+
return function doClearSafe() {
|
|
8
|
+
arr.forEach(f => typeof f === 'function' && f());
|
|
9
|
+
arr.length = 0;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export function identity(x) {
|
|
13
|
+
return x;
|
|
14
|
+
}
|
|
15
|
+
export function notEmpty(value) {
|
|
16
|
+
return value !== null && value !== undefined;
|
|
17
|
+
}
|
|
18
|
+
export const constVoid = () => void 0;
|
|
19
|
+
export function nonNullableTypeGuard(x) {
|
|
20
|
+
return x !== undefined && x !== null;
|
|
21
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2019 - 2023 Devexperts Solutions IE Limited
|
|
3
|
+
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
|
4
|
+
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ListNode<T> {
|
|
7
|
+
data: T;
|
|
8
|
+
next: ListNode<T> | null;
|
|
9
|
+
constructor(data: T);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Implementation of Linked list data structure.
|
|
13
|
+
* @param _head
|
|
14
|
+
*/
|
|
15
|
+
export declare class LinkedList<T> {
|
|
16
|
+
private _head;
|
|
17
|
+
private _tail;
|
|
18
|
+
private length;
|
|
19
|
+
constructor(head?: ListNode<T>);
|
|
20
|
+
insertAtEnd(data: T): ListNode<T>;
|
|
21
|
+
insertAt(position: number, data: T): ListNode<T> | null;
|
|
22
|
+
removeAt(position: number): ListNode<T> | null;
|
|
23
|
+
getNodePosition(node: ListNode<T>): number;
|
|
24
|
+
size(): number;
|
|
25
|
+
get head(): ListNode<T> | null;
|
|
26
|
+
get tail(): ListNode<T> | null;
|
|
27
|
+
[Symbol.iterator](): Generator<T, void, unknown>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2019 - 2023 Devexperts Solutions IE Limited
|
|
3
|
+
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
|
4
|
+
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
|
+
*/
|
|
6
|
+
export class ListNode {
|
|
7
|
+
constructor(data) {
|
|
8
|
+
this.data = data;
|
|
9
|
+
this.next = null;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Implementation of Linked list data structure.
|
|
14
|
+
* @param _head
|
|
15
|
+
*/
|
|
16
|
+
export class LinkedList {
|
|
17
|
+
constructor(head) {
|
|
18
|
+
this._head = null;
|
|
19
|
+
this._tail = null;
|
|
20
|
+
this.length = 0;
|
|
21
|
+
this._head = head !== null && head !== void 0 ? head : null;
|
|
22
|
+
// init tail
|
|
23
|
+
if (this.head !== null) {
|
|
24
|
+
let current;
|
|
25
|
+
current = this.head;
|
|
26
|
+
while (current.next) {
|
|
27
|
+
current = current.next;
|
|
28
|
+
}
|
|
29
|
+
this._tail = current;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
insertAtEnd(data) {
|
|
33
|
+
const node = new ListNode(data);
|
|
34
|
+
let current;
|
|
35
|
+
if (this.head === null) {
|
|
36
|
+
this._head = node;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
current = this.head;
|
|
40
|
+
while (current.next) {
|
|
41
|
+
current = current.next;
|
|
42
|
+
}
|
|
43
|
+
current.next = node;
|
|
44
|
+
}
|
|
45
|
+
this._tail = node;
|
|
46
|
+
this.length++;
|
|
47
|
+
return node;
|
|
48
|
+
}
|
|
49
|
+
insertAt(position, data) {
|
|
50
|
+
if (position > -1 && position < this.length && this.head) {
|
|
51
|
+
let current = this.head;
|
|
52
|
+
let index = 0;
|
|
53
|
+
let previous = null;
|
|
54
|
+
const node = new ListNode(data);
|
|
55
|
+
if (position === this.length - 1) {
|
|
56
|
+
this._tail = node;
|
|
57
|
+
}
|
|
58
|
+
if (position === 0) {
|
|
59
|
+
node.next = current;
|
|
60
|
+
this._head = node;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
while (index < position && current.next) {
|
|
64
|
+
index++;
|
|
65
|
+
previous = current;
|
|
66
|
+
current = current.next;
|
|
67
|
+
}
|
|
68
|
+
node.next = current;
|
|
69
|
+
if (previous) {
|
|
70
|
+
previous.next = node;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
this.length++;
|
|
74
|
+
return current;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
this._head = new ListNode(data);
|
|
78
|
+
this.length++;
|
|
79
|
+
return this.head;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
removeAt(position) {
|
|
83
|
+
if (position > -1 && position < this.length && this.head) {
|
|
84
|
+
let current = this.head;
|
|
85
|
+
let previous = null;
|
|
86
|
+
let index = 0;
|
|
87
|
+
if (position === 0) {
|
|
88
|
+
this._head = current.next;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
while (index < position && current.next) {
|
|
92
|
+
index++;
|
|
93
|
+
previous = current;
|
|
94
|
+
current = current.next;
|
|
95
|
+
}
|
|
96
|
+
if (previous) {
|
|
97
|
+
previous.next = current.next;
|
|
98
|
+
}
|
|
99
|
+
if (position === this.length - 1) {
|
|
100
|
+
this._tail = current;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
this.length--;
|
|
104
|
+
return current;
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
getNodePosition(node) {
|
|
111
|
+
let index = 0;
|
|
112
|
+
let current = this.head;
|
|
113
|
+
while (node) {
|
|
114
|
+
if ((current === null || current === void 0 ? void 0 : current.data) === node.data) {
|
|
115
|
+
return index;
|
|
116
|
+
}
|
|
117
|
+
current = current && current.next;
|
|
118
|
+
index++;
|
|
119
|
+
}
|
|
120
|
+
return -1;
|
|
121
|
+
}
|
|
122
|
+
size() {
|
|
123
|
+
return this.length;
|
|
124
|
+
}
|
|
125
|
+
get head() {
|
|
126
|
+
return this._head;
|
|
127
|
+
}
|
|
128
|
+
get tail() {
|
|
129
|
+
return this._tail;
|
|
130
|
+
}
|
|
131
|
+
*[Symbol.iterator]() {
|
|
132
|
+
let current = this.head;
|
|
133
|
+
while (current) {
|
|
134
|
+
yield current.data;
|
|
135
|
+
current = current.next;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
@@ -3,4 +3,118 @@
|
|
|
3
3
|
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
|
4
4
|
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
5
|
*/
|
|
6
|
-
export const MAX_DECIMAL_DIGITS
|
|
6
|
+
export const MAX_DECIMAL_DIGITS = 14;
|
|
7
|
+
// Array of powers of 10. Used in roundDecimal to walk through mantissa.
|
|
8
|
+
const POW10 = [];
|
|
9
|
+
for (let i = 0; i < MAX_DECIMAL_DIGITS + 1; i++) {
|
|
10
|
+
POW10.push(Math.pow(10, i));
|
|
11
|
+
}
|
|
12
|
+
const EPS = 5e-13;
|
|
13
|
+
export class MathUtils {
|
|
14
|
+
static roundToNearest(value, precision) {
|
|
15
|
+
if (!isFinite(value)) {
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
if (MathUtils.isZero(value)) {
|
|
19
|
+
return 0.0;
|
|
20
|
+
}
|
|
21
|
+
if (value > 0) {
|
|
22
|
+
value += EPS;
|
|
23
|
+
}
|
|
24
|
+
else if (value < 0) {
|
|
25
|
+
value -= EPS;
|
|
26
|
+
}
|
|
27
|
+
return MathUtils.roundDecimal(Math.round(MathUtils.roundDecimal(value / precision)) * precision);
|
|
28
|
+
}
|
|
29
|
+
static roundUpToNearest(value, precision) {
|
|
30
|
+
return MathUtils.roundDecimal(Math.ceil(value / precision)) * precision;
|
|
31
|
+
}
|
|
32
|
+
static roundDecimal(x) {
|
|
33
|
+
if (isNaN(x) || x === Math.floor(x)) {
|
|
34
|
+
return x;
|
|
35
|
+
} // integer, NaN, or +/- inf
|
|
36
|
+
const signum = Math.sign(x);
|
|
37
|
+
const abs = Math.abs(x);
|
|
38
|
+
const pow = Math.min(MAX_DECIMAL_DIGITS, MAX_DECIMAL_DIGITS - 1 - Math.floor(Math.log10(abs)));
|
|
39
|
+
for (let i = pow; i >= 0; i--) {
|
|
40
|
+
const mantissa = Math.floor(POW10[i] * abs + 0.5);
|
|
41
|
+
if (mantissa < POW10[MAX_DECIMAL_DIGITS]) {
|
|
42
|
+
return (signum * mantissa) / POW10[i];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// Mantissa >= 10^14 with fractions -- just round
|
|
46
|
+
return Math.round(x);
|
|
47
|
+
}
|
|
48
|
+
static makeDecimal(value, precision, decimal) {
|
|
49
|
+
if (isFinite(value)) {
|
|
50
|
+
const stringValue = value.toFixed(precision);
|
|
51
|
+
return decimal ? stringValue.replace('.', decimal) : stringValue;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
return '';
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
static compare(a, b, eps) {
|
|
58
|
+
if (a > b + eps) {
|
|
59
|
+
return +1;
|
|
60
|
+
}
|
|
61
|
+
else if (a < b - eps) {
|
|
62
|
+
return -1;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
return (isNaN(a) ? 1 : 0) - (isNaN(b) ? 1 : 0);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
static isZero(a) {
|
|
69
|
+
return MathUtils.compare(a, 0, EPS) === 0;
|
|
70
|
+
}
|
|
71
|
+
static cutNumber(value, amountToCut, zeros = 0) {
|
|
72
|
+
const cutMap = {
|
|
73
|
+
K: v => v / 1000,
|
|
74
|
+
M: v => v / 1000000,
|
|
75
|
+
};
|
|
76
|
+
return cutMap[amountToCut](value).toFixed(zeros) + amountToCut;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Checks if first and second number are differs by specified times
|
|
81
|
+
* @param first {number}
|
|
82
|
+
* @param second {number}
|
|
83
|
+
* @param times {number}
|
|
84
|
+
* @doc-tags utility,math
|
|
85
|
+
*/
|
|
86
|
+
export function isDiffersBy(first, second, times) {
|
|
87
|
+
const diff = first / second;
|
|
88
|
+
return diff >= times || diff <= 1 / times;
|
|
89
|
+
}
|
|
90
|
+
export function clamp(value, min, max) {
|
|
91
|
+
return Math.max(min, Math.min(value, max));
|
|
92
|
+
}
|
|
93
|
+
export function easeExpOut(value) {
|
|
94
|
+
return 1 - (Math.pow(2, -10 * value) - 0.0009765625) * 1.0009775171065494;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Returns the first finite number in a list of numbers. If no finite number is found,
|
|
98
|
+
* returns NaN.
|
|
99
|
+
* @param {...number} args - A list of numbers to search for a finite value.
|
|
100
|
+
* @returns {number} The first finite number in the list, or NaN if no finite number is found.
|
|
101
|
+
*/
|
|
102
|
+
export function finite(...args) {
|
|
103
|
+
for (const arg of args) {
|
|
104
|
+
if (arg !== undefined && isFinite(arg)) {
|
|
105
|
+
return arg;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return NaN;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* These functions can be used only for chart coordinates because they all are working in positive coordinates!!!
|
|
112
|
+
*/
|
|
113
|
+
// eslint-disable-next-line no-bitwise
|
|
114
|
+
export const floor = (value) => ~~value;
|
|
115
|
+
// eslint-disable-next-line no-bitwise
|
|
116
|
+
export const ceil = (value) => ~~(value + 1);
|
|
117
|
+
// eslint-disable-next-line no-bitwise
|
|
118
|
+
export const round = (value) => ~~(value + 0.5);
|
|
119
|
+
// eslint-disable-next-line no-bitwise
|
|
120
|
+
export const shiftRight = (value, shift) => value >> shift;
|
|
@@ -3,4 +3,59 @@
|
|
|
3
3
|
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
|
4
4
|
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Merges 2 js objects recursively with all properties.
|
|
8
|
+
* - does not modify base object
|
|
9
|
+
* - can override or only add missing ones
|
|
10
|
+
*
|
|
11
|
+
* @param base - base object to merge data into
|
|
12
|
+
* @param override - object with new data which should be merged
|
|
13
|
+
* @param options - merge options
|
|
14
|
+
* @doc-tags tricky,utility
|
|
15
|
+
*/
|
|
16
|
+
export function merge(base, override, options = DEFAULT_MERGE_OPTIONS) {
|
|
17
|
+
function doMerge(base, override) {
|
|
18
|
+
for (const k in override) {
|
|
19
|
+
if (k in base) {
|
|
20
|
+
if (typeof base[k] === 'object' && base[k] !== null && !Array.isArray(base[k])) {
|
|
21
|
+
doMerge(base[k], override[k]);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
// do not merge arrays or functions
|
|
25
|
+
if (options === null || options === void 0 ? void 0 : options.overrideExisting) {
|
|
26
|
+
base[k] = override[k];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
if (options === null || options === void 0 ? void 0 : options.addIfMissing) {
|
|
32
|
+
base[k] = override[k];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return base;
|
|
37
|
+
}
|
|
38
|
+
return doMerge(base, override);
|
|
39
|
+
}
|
|
40
|
+
export function mergeArray(base, override, hashFn, mergeObjects = false) {
|
|
41
|
+
if (!base || !override || override.length === 0) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
override.forEach(o => {
|
|
45
|
+
const hash = hashFn(o);
|
|
46
|
+
const existingIndex = base.findIndex(b => hashFn(b) === hash);
|
|
47
|
+
if (existingIndex === -1) {
|
|
48
|
+
base.push(o);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
if (mergeObjects) {
|
|
52
|
+
// try merging objects in array
|
|
53
|
+
merge(base[existingIndex], o, { overrideExisting: true, addIfMissing: true });
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
base.splice(existingIndex, 1, o);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
export const DEFAULT_MERGE_OPTIONS = { overrideExisting: false, addIfMissing: true };
|
|
@@ -3,4 +3,46 @@
|
|
|
3
3
|
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
|
4
4
|
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
5
|
*/
|
|
6
|
-
export const cloneUnsafe=
|
|
6
|
+
export const cloneUnsafe = (value) => JSON.parse(JSON.stringify(value));
|
|
7
|
+
export function typedEntries_UNSAFE(obj) {
|
|
8
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
9
|
+
return Object.entries(obj);
|
|
10
|
+
}
|
|
11
|
+
export const findKeyFromValue = (map, mapValue) => {
|
|
12
|
+
for (const [key, value] of Array.from(map.entries())) {
|
|
13
|
+
if (value === mapValue) {
|
|
14
|
+
return key;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
export function keys(r) {
|
|
19
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
20
|
+
return Object.keys(r);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Deeply compares two objects
|
|
24
|
+
* @param {*} objA
|
|
25
|
+
* @param {*} objB
|
|
26
|
+
* @returns {Boolean}
|
|
27
|
+
*/
|
|
28
|
+
export function deepEqual(objA, objB) {
|
|
29
|
+
if (Object.is(objA, objB)) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
const keysA = Object.keys(objA);
|
|
36
|
+
const keysB = Object.keys(objB);
|
|
37
|
+
if (keysA.length !== keysB.length) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
// Test for A's keys different from B.
|
|
41
|
+
for (let i = 0, len = keysA.length; i < len; i++) {
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
if (!hasOwnProperty.call(objB, keysA[i]) || !deepEqual(objA[keysA[i]], objB[keysA[i]])) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return true;
|
|
48
|
+
}
|