@devexperts/dxcharts-lite 2.5.6 → 2.5.8
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/dist/chart/bootstrap.js +3 -3
- package/dist/chart/canvas/canvas-bounds-container.d.ts +21 -0
- package/dist/chart/canvas/canvas-bounds-container.js +30 -0
- package/dist/chart/chart.js +2 -1
- package/dist/chart/components/chart/basic-scale.d.ts +5 -1
- package/dist/chart/components/chart/basic-scale.js +10 -6
- package/dist/chart/components/chart/chart.model.d.ts +1 -22
- package/dist/chart/components/chart/chart.model.js +12 -36
- package/dist/chart/components/pan/chart-pan.component.js +2 -1
- package/dist/chart/components/pane/pane-manager.component.d.ts +3 -1
- package/dist/chart/components/pane/pane-manager.component.js +3 -2
- package/dist/chart/components/pane/pane.component.d.ts +3 -1
- package/dist/chart/components/pane/pane.component.js +6 -5
- 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 +6 -6
- package/dist/chart/components/x_axis/x-axis-scale.handler.d.ts +4 -2
- package/dist/chart/components/x_axis/x-axis-scale.handler.js +16 -8
- package/dist/chart/components/x_axis/x-axis.component.js +1 -1
- package/dist/chart/components/y_axis/price_labels/y-axis-labels.model.d.ts +3 -1
- package/dist/chart/components/y_axis/price_labels/y-axis-labels.model.js +5 -3
- package/dist/chart/components/y_axis/y-axis-scale.handler.d.ts +1 -0
- package/dist/chart/components/y_axis/y-axis-scale.handler.js +18 -1
- package/dist/chart/components/y_axis/y-axis.component.d.ts +3 -1
- package/dist/chart/components/y_axis/y-axis.component.js +3 -2
- package/dist/chart/components/y_axis/y-axis.model.d.ts +2 -1
- package/dist/chart/components/y_axis/y-axis.model.js +2 -2
- package/dist/chart/inputhandlers/main-canvas-touch.handler.d.ts +3 -1
- package/dist/chart/inputhandlers/main-canvas-touch.handler.js +5 -4
- package/dist/chart/model/scale.model.d.ts +4 -4
- package/dist/chart/model/scale.model.js +14 -12
- package/dist/chart/utils/color.utils.d.ts +3 -0
- package/dist/chart/utils/color.utils.js +5 -1
- package/dist/dxchart.min.js +4 -4
- package/package.json +1 -1
|
@@ -31,6 +31,7 @@ export declare class YAxisScaleHandler extends ChartBaseElement {
|
|
|
31
31
|
lastYHeight: Unit;
|
|
32
32
|
lastYPxHeight: Pixel;
|
|
33
33
|
private dblClickCallback;
|
|
34
|
+
private touches;
|
|
34
35
|
private dblTapCallback;
|
|
35
36
|
constructor(bus: EventBus, config: YAxisConfig, panning: ChartPanComponent, scale: ScaleModel, canvasInputListener: CanvasInputListenerComponent, bounds: CanvasBoundsContainer, hitTest: HitBoundsTest, hitTestCanvasModel: HitTestCanvasModel);
|
|
36
37
|
protected doActivate(): void;
|
|
@@ -39,7 +39,15 @@ export class YAxisScaleHandler extends ChartBaseElement {
|
|
|
39
39
|
this.hitTestCanvasModel.hitTestDrawersPredicateSubject.next(false);
|
|
40
40
|
};
|
|
41
41
|
this.onYDragTick = (dragInfo) => {
|
|
42
|
-
|
|
42
|
+
let { delta: absoluteYDelta } = dragInfo;
|
|
43
|
+
// check how many touch events are at the axis
|
|
44
|
+
// if multitouch - take the first two and apply delta the following way:
|
|
45
|
+
// the touch above keeps the initial delta because top => bottom gesture
|
|
46
|
+
// the touch below has the reversed delta because the gesture is bottom => top
|
|
47
|
+
if (this.touches && this.touches.length > 1) {
|
|
48
|
+
const top = Math.min(this.touches[0].clientY, this.touches[1].clientY);
|
|
49
|
+
absoluteYDelta = top === this.touches[0].clientY ? absoluteYDelta : -absoluteYDelta;
|
|
50
|
+
}
|
|
43
51
|
// 1/3..3
|
|
44
52
|
let zoomYMult;
|
|
45
53
|
if (absoluteYDelta < 0) {
|
|
@@ -88,9 +96,18 @@ export class YAxisScaleHandler extends ChartBaseElement {
|
|
|
88
96
|
this.bus.fireDraw();
|
|
89
97
|
}));
|
|
90
98
|
this.addRxSubscription(this.canvasInputListener.observeDbTap(this.hitTest).subscribe(() => {
|
|
99
|
+
var _a;
|
|
100
|
+
// apply dbl tap only if single finger taps are made
|
|
101
|
+
if (this.touches && ((_a = this.touches) === null || _a === void 0 ? void 0 : _a.length) > 1) {
|
|
102
|
+
this.touches = undefined;
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
91
105
|
this.dblTapCallback();
|
|
92
106
|
this.bus.fireDraw();
|
|
93
107
|
}));
|
|
108
|
+
this.addRxSubscription(this.canvasInputListener.observeTouchStart(this.hitTest).subscribe(e => {
|
|
109
|
+
this.touches = e.touches;
|
|
110
|
+
}));
|
|
94
111
|
}
|
|
95
112
|
}
|
|
96
113
|
}
|
|
@@ -22,6 +22,7 @@ import { VisualYAxisLabel, YAxisLabelsProvider } from './price_labels/y-axis-lab
|
|
|
22
22
|
import { YAxisScaleHandler } from './y-axis-scale.handler';
|
|
23
23
|
import { YAxisModel } from './y-axis.model';
|
|
24
24
|
import { HitTestCanvasModel } from '../../model/hit-test-canvas.model';
|
|
25
|
+
import { ChartResizeHandler } from '../../inputhandlers/chart-resize.handler';
|
|
25
26
|
export type LabelColorResolver = (priceMovement: PriceMovement, colors: FullChartColors) => string;
|
|
26
27
|
/**
|
|
27
28
|
* Y axis component. Contains all Y axis related logic.
|
|
@@ -35,12 +36,13 @@ export declare class YAxisComponent extends ChartBaseElement {
|
|
|
35
36
|
private cursors;
|
|
36
37
|
paneUUID: string;
|
|
37
38
|
extentIdx: number;
|
|
39
|
+
private chartResizeHandler;
|
|
38
40
|
private labelsColorByChartTypeMap;
|
|
39
41
|
yAxisScaleHandler: YAxisScaleHandler;
|
|
40
42
|
model: YAxisModel;
|
|
41
43
|
axisTypeSetSubject: Subject<PriceAxisType>;
|
|
42
44
|
readonly state: YAxisConfig;
|
|
43
|
-
constructor(eventBus: EventBus, config: FullChartConfig, canvasModel: CanvasModel, scale: ScaleModel, canvasInputListeners: CanvasInputListenerComponent, canvasBoundsContainer: CanvasBoundsContainer, chartPanComponent: ChartPanComponent, cursors: CursorHandler, valueFormatter: (value: number) => string, dataSeriesProvider: () => DataSeriesModel | undefined, paneUUID: string, extentIdx: number, hitTestCanvasModel: HitTestCanvasModel, initialState?: YAxisConfig);
|
|
45
|
+
constructor(eventBus: EventBus, config: FullChartConfig, canvasModel: CanvasModel, scale: ScaleModel, canvasInputListeners: CanvasInputListenerComponent, canvasBoundsContainer: CanvasBoundsContainer, chartPanComponent: ChartPanComponent, cursors: CursorHandler, valueFormatter: (value: number) => string, dataSeriesProvider: () => DataSeriesModel | undefined, paneUUID: string, extentIdx: number, hitTestCanvasModel: HitTestCanvasModel, chartResizeHandler: ChartResizeHandler, initialState?: YAxisConfig);
|
|
44
46
|
/**
|
|
45
47
|
* Registers default label color resolvers for different chart types.
|
|
46
48
|
* @private
|
|
@@ -17,7 +17,7 @@ import { cloneUnsafe } from '../../utils/object.utils';
|
|
|
17
17
|
* Y axis component. Contains all Y axis related logic.
|
|
18
18
|
*/
|
|
19
19
|
export class YAxisComponent extends ChartBaseElement {
|
|
20
|
-
constructor(eventBus, config, canvasModel, scale, canvasInputListeners, canvasBoundsContainer, chartPanComponent, cursors, valueFormatter, dataSeriesProvider, paneUUID, extentIdx, hitTestCanvasModel, initialState) {
|
|
20
|
+
constructor(eventBus, config, canvasModel, scale, canvasInputListeners, canvasBoundsContainer, chartPanComponent, cursors, valueFormatter, dataSeriesProvider, paneUUID, extentIdx, hitTestCanvasModel, chartResizeHandler, initialState) {
|
|
21
21
|
super();
|
|
22
22
|
this.eventBus = eventBus;
|
|
23
23
|
this.config = config;
|
|
@@ -27,6 +27,7 @@ export class YAxisComponent extends ChartBaseElement {
|
|
|
27
27
|
this.cursors = cursors;
|
|
28
28
|
this.paneUUID = paneUUID;
|
|
29
29
|
this.extentIdx = extentIdx;
|
|
30
|
+
this.chartResizeHandler = chartResizeHandler;
|
|
30
31
|
this.labelsColorByChartTypeMap = {};
|
|
31
32
|
this.axisTypeSetSubject = new Subject();
|
|
32
33
|
/* This function assigns a callback to be executed when a double-click event is detected.
|
|
@@ -50,7 +51,7 @@ export class YAxisComponent extends ChartBaseElement {
|
|
|
50
51
|
this.yAxisScaleHandler = new YAxisScaleHandler(eventBus, this.state, chartPanComponent, scale, canvasInputListeners, canvasBoundsContainer, canvasBoundsContainer.getBoundsHitTest(CanvasElement.PANE_UUID_Y_AXIS(paneUUID, extentIdx)), hitTestCanvasModel);
|
|
51
52
|
this.addChildEntity(this.yAxisScaleHandler);
|
|
52
53
|
//#endregion
|
|
53
|
-
this.model = new YAxisModel(this.paneUUID, eventBus, this.state, canvasBoundsContainer, canvasModel, scale, valueFormatter, dataSeriesProvider, extentIdx);
|
|
54
|
+
this.model = new YAxisModel(this.paneUUID, eventBus, this.state, canvasBoundsContainer, canvasModel, scale, valueFormatter, dataSeriesProvider, extentIdx, this.chartResizeHandler);
|
|
54
55
|
this.addChildEntity(this.model);
|
|
55
56
|
this.updateCursor();
|
|
56
57
|
this.registerDefaultLabelColorResolvers();
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { CanvasBoundsContainer } from '../../canvas/canvas-bounds-container';
|
|
7
7
|
import { YAxisConfig } from '../../chart.config';
|
|
8
8
|
import EventBus from '../../events/event-bus';
|
|
9
|
+
import { ChartResizeHandler } from '../../inputhandlers/chart-resize.handler';
|
|
9
10
|
import { CanvasModel } from '../../model/canvas.model';
|
|
10
11
|
import { ChartBaseElement } from '../../model/chart-base-element';
|
|
11
12
|
import { DataSeriesModel } from '../../model/data-series.model';
|
|
@@ -21,6 +22,6 @@ export declare class YAxisModel extends ChartBaseElement {
|
|
|
21
22
|
labelsGenerator: NumericYAxisLabelsGenerator;
|
|
22
23
|
baseLabelsModel: YAxisBaseLabelsModel;
|
|
23
24
|
fancyLabelsModel: FancyYAxisLabelsModel;
|
|
24
|
-
constructor(paneUUID: string, eventBus: EventBus, state: YAxisConfig, canvasBoundsContainer: CanvasBoundsContainer, canvasModel: CanvasModel, scale: ScaleModel, valueFormatter: (value: number) => string, dataSeriesProvider: () => DataSeriesModel | undefined, extentIdx: number);
|
|
25
|
+
constructor(paneUUID: string, eventBus: EventBus, state: YAxisConfig, canvasBoundsContainer: CanvasBoundsContainer, canvasModel: CanvasModel, scale: ScaleModel, valueFormatter: (value: number) => string, dataSeriesProvider: () => DataSeriesModel | undefined, extentIdx: number, chartResizeHandler: ChartResizeHandler);
|
|
25
26
|
protected doActivate(): void;
|
|
26
27
|
}
|
|
@@ -8,7 +8,7 @@ import { NumericYAxisLabelsGenerator } from './numeric-y-axis-labels.generator';
|
|
|
8
8
|
import { FancyYAxisLabelsModel } from './price_labels/y-axis-labels.model';
|
|
9
9
|
import { YAxisBaseLabelsModel } from './y-axis-base-labels.model';
|
|
10
10
|
export class YAxisModel extends ChartBaseElement {
|
|
11
|
-
constructor(paneUUID, eventBus, state, canvasBoundsContainer, canvasModel, scale, valueFormatter, dataSeriesProvider, extentIdx) {
|
|
11
|
+
constructor(paneUUID, eventBus, state, canvasBoundsContainer, canvasModel, scale, valueFormatter, dataSeriesProvider, extentIdx, chartResizeHandler) {
|
|
12
12
|
super();
|
|
13
13
|
this.paneUUID = paneUUID;
|
|
14
14
|
this.state = state;
|
|
@@ -17,7 +17,7 @@ export class YAxisModel extends ChartBaseElement {
|
|
|
17
17
|
this.labelsGenerator = new NumericYAxisLabelsGenerator(null, dataSeriesProvider, scale, valueFormatter, () => this.state.type, state.labelHeight);
|
|
18
18
|
this.baseLabelsModel = new YAxisBaseLabelsModel(scale, this.labelsGenerator, this.canvasBoundsContainer, paneUUID, extentIdx);
|
|
19
19
|
this.addChildEntity(this.baseLabelsModel);
|
|
20
|
-
this.fancyLabelsModel = new FancyYAxisLabelsModel(eventBus, scale, canvasBoundsContainer, state, canvasModel, paneUUID, () => this.canvasBoundsContainer.updateYAxisWidths());
|
|
20
|
+
this.fancyLabelsModel = new FancyYAxisLabelsModel(eventBus, scale, canvasBoundsContainer, state, canvasModel, paneUUID, () => this.canvasBoundsContainer.updateYAxisWidths(), chartResizeHandler);
|
|
21
21
|
this.addChildEntity(this.fancyLabelsModel);
|
|
22
22
|
}
|
|
23
23
|
doActivate() {
|
|
@@ -7,6 +7,7 @@ import { ChartBaseElement } from '../model/chart-base-element';
|
|
|
7
7
|
import { CanvasInputListenerComponent } from '../inputlisteners/canvas-input-listener.component';
|
|
8
8
|
import { ScaleModel } from '../model/scale.model';
|
|
9
9
|
import { ChartAreaPanHandler } from '../components/chart/chart-area-pan.handler';
|
|
10
|
+
import { HitBoundsTest } from '../canvas/canvas-bounds-container';
|
|
10
11
|
/**
|
|
11
12
|
* Handles chart touch events.
|
|
12
13
|
*/
|
|
@@ -15,8 +16,9 @@ export declare class MainCanvasTouchHandler extends ChartBaseElement {
|
|
|
15
16
|
private scale;
|
|
16
17
|
private canvasInputListeners;
|
|
17
18
|
private mainCanvasParent;
|
|
19
|
+
private hitTest;
|
|
18
20
|
private touchedCandleIndexes;
|
|
19
|
-
constructor(chartAreaPanHandler: ChartAreaPanHandler, scale: ScaleModel, canvasInputListeners: CanvasInputListenerComponent, mainCanvasParent: Element);
|
|
21
|
+
constructor(chartAreaPanHandler: ChartAreaPanHandler, scale: ScaleModel, canvasInputListeners: CanvasInputListenerComponent, mainCanvasParent: Element, hitTest: HitBoundsTest);
|
|
20
22
|
/**
|
|
21
23
|
* Activates canvas input listeners for touch start and touch move events.
|
|
22
24
|
* @protected
|
|
@@ -8,12 +8,13 @@ import { ChartBaseElement } from '../model/chart-base-element';
|
|
|
8
8
|
* Handles chart touch events.
|
|
9
9
|
*/
|
|
10
10
|
export class MainCanvasTouchHandler extends ChartBaseElement {
|
|
11
|
-
constructor(chartAreaPanHandler, scale, canvasInputListeners, mainCanvasParent) {
|
|
11
|
+
constructor(chartAreaPanHandler, scale, canvasInputListeners, mainCanvasParent, hitTest) {
|
|
12
12
|
super();
|
|
13
13
|
this.chartAreaPanHandler = chartAreaPanHandler;
|
|
14
14
|
this.scale = scale;
|
|
15
15
|
this.canvasInputListeners = canvasInputListeners;
|
|
16
16
|
this.mainCanvasParent = mainCanvasParent;
|
|
17
|
+
this.hitTest = hitTest;
|
|
17
18
|
// 2 candles indexes touched by 2 fingers when pinching
|
|
18
19
|
this.touchedCandleIndexes = [0, 0];
|
|
19
20
|
}
|
|
@@ -23,8 +24,8 @@ export class MainCanvasTouchHandler extends ChartBaseElement {
|
|
|
23
24
|
* @returns {void}
|
|
24
25
|
*/
|
|
25
26
|
doActivate() {
|
|
26
|
-
this.addRxSubscription(this.canvasInputListeners.observeTouchStart().subscribe(e => this.handleTouchStartEvent(e)));
|
|
27
|
-
this.addRxSubscription(this.canvasInputListeners.observeTouchMove().subscribe(e => this.handleTouchMoveEvent(e)));
|
|
27
|
+
this.addRxSubscription(this.canvasInputListeners.observeTouchStart(this.hitTest).subscribe(e => this.handleTouchStartEvent(e)));
|
|
28
|
+
this.addRxSubscription(this.canvasInputListeners.observeTouchMove(this.hitTest).subscribe(e => this.handleTouchMoveEvent(e)));
|
|
28
29
|
this.addRxSubscription(this.canvasInputListeners.observeTouchEndDocument().subscribe(e => this.handleTouchEndEvent(e)));
|
|
29
30
|
}
|
|
30
31
|
/**
|
|
@@ -88,7 +89,7 @@ export class MainCanvasTouchHandler extends ChartBaseElement {
|
|
|
88
89
|
const last = first +
|
|
89
90
|
((candleIndexes[0] - candleIndexes[1]) / (touchPositions[0] - touchPositions[1])) *
|
|
90
91
|
this.scale.getBounds().width;
|
|
91
|
-
if (first >= last) {
|
|
92
|
+
if (first >= last || touchPositions[0] === touchPositions[1]) {
|
|
92
93
|
return;
|
|
93
94
|
}
|
|
94
95
|
this.scale.setXScale(first, last);
|
|
@@ -25,8 +25,8 @@ export declare const getDefaultHighLowWithIndex: () => HighLowWithIndex;
|
|
|
25
25
|
export type ViewportPercent = number;
|
|
26
26
|
type Constraints = (initialState: ViewportModelState, state: ViewportModelState) => ViewportModelState;
|
|
27
27
|
export interface ZoomReached {
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
zoomIn: boolean;
|
|
29
|
+
zoomOut: boolean;
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* The ScaleModel class represents the state of a chart's scale, including the current viewport, zoom level, and auto-scaling settings.
|
|
@@ -86,8 +86,8 @@ export declare class ScaleModel extends ViewportModel {
|
|
|
86
86
|
haltAnimation(): void;
|
|
87
87
|
private zoomXTo;
|
|
88
88
|
calculateZoomReached(zoomX: Unit, zoomIn?: boolean): {
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
zoomIn: boolean;
|
|
90
|
+
zoomOut: boolean;
|
|
91
91
|
};
|
|
92
92
|
/**
|
|
93
93
|
* Moves the viewport to exactly xStart..xEnd place.
|
|
@@ -36,7 +36,7 @@ export class ScaleModel extends ViewportModel {
|
|
|
36
36
|
this.scaleInversedSubject = new Subject();
|
|
37
37
|
// y-axis component needs this subject in order to halt prev animation if axis type is percent
|
|
38
38
|
this.beforeStartAnimationSubject = new Subject();
|
|
39
|
-
this.zoomReached = {
|
|
39
|
+
this.zoomReached = { zoomIn: false, zoomOut: false };
|
|
40
40
|
// TODO rework, make a new history based on units
|
|
41
41
|
this.history = [];
|
|
42
42
|
this.xConstraints = [];
|
|
@@ -128,7 +128,7 @@ export class ScaleModel extends ViewportModel {
|
|
|
128
128
|
const initialStateCopy = Object.assign({}, state);
|
|
129
129
|
const constrainedState = this.scalePostProcessor(initialStateCopy, state);
|
|
130
130
|
this.zoomReached = this.calculateZoomReached(constrainedState.zoomX, zoomIn);
|
|
131
|
-
if (this.zoomReached.
|
|
131
|
+
if (this.zoomReached.zoomIn || this.zoomReached.zoomOut) {
|
|
132
132
|
return;
|
|
133
133
|
}
|
|
134
134
|
if (this.state.lockPriceToBarRatio) {
|
|
@@ -148,15 +148,17 @@ export class ScaleModel extends ViewportModel {
|
|
|
148
148
|
const chartWidth = this.getBounds().width;
|
|
149
149
|
const delta = 0.001; // zoom values are very precise and should be compared with some precision delta
|
|
150
150
|
if (chartWidth > 0) {
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
const
|
|
157
|
-
|
|
151
|
+
const maxZoomIn = calculateZoom(this.config.components.chart.minCandles, chartWidth);
|
|
152
|
+
const maxZoomInReached = zoomX !== maxZoomIn && zoomX - maxZoomIn <= delta;
|
|
153
|
+
// max zoom in reached and trying to zoom in further
|
|
154
|
+
const maxZoomInDisabled = maxZoomInReached && zoomIn;
|
|
155
|
+
const maxZoomOut = calculateZoom(chartWidth / this.config.components.chart.minWidth, chartWidth);
|
|
156
|
+
const maxZoomOutReached = zoomX - maxZoomOut >= delta;
|
|
157
|
+
// max zoom out reached and trying to zoom out further
|
|
158
|
+
const maxZoomOutDisabled = maxZoomOutReached && !zoomIn;
|
|
159
|
+
return { zoomIn: maxZoomInDisabled, zoomOut: maxZoomOutDisabled };
|
|
158
160
|
}
|
|
159
|
-
return {
|
|
161
|
+
return { zoomIn: false, zoomOut: false };
|
|
160
162
|
}
|
|
161
163
|
/**
|
|
162
164
|
* Moves the viewport to exactly xStart..xEnd place.
|
|
@@ -176,7 +178,7 @@ export class ScaleModel extends ViewportModel {
|
|
|
176
178
|
const constrainedState = this.scalePostProcessor(initialState, state);
|
|
177
179
|
const zoomIn = constrainedState.xEnd - constrainedState.xStart < initialState.xEnd - initialState.xStart;
|
|
178
180
|
this.zoomReached = this.calculateZoomReached(zoomX, zoomIn);
|
|
179
|
-
if (this.zoomReached.
|
|
181
|
+
if (this.zoomReached.zoomIn || this.zoomReached.zoomOut) {
|
|
180
182
|
return;
|
|
181
183
|
}
|
|
182
184
|
if (this.state.lockPriceToBarRatio) {
|
|
@@ -212,7 +214,7 @@ export class ScaleModel extends ViewportModel {
|
|
|
212
214
|
}
|
|
213
215
|
setLockedYScale(yStart, yEnd, fire = false, initialState) {
|
|
214
216
|
const zoomIn = yEnd < initialState.yEnd;
|
|
215
|
-
if ((this.zoomReached.
|
|
217
|
+
if ((this.zoomReached.zoomOut && zoomIn === false) || (this.zoomReached.zoomIn && zoomIn === true)) {
|
|
216
218
|
return;
|
|
217
219
|
}
|
|
218
220
|
super.setYScale(yStart, yEnd, fire);
|
|
@@ -3,4 +3,7 @@
|
|
|
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 declare const isHex: (color: string) => RegExpExecArray | null;
|
|
7
|
+
export declare const isRgb: (color: string) => RegExpExecArray | null;
|
|
8
|
+
export declare const isRgba: (color: string) => RegExpExecArray | null;
|
|
6
9
|
export declare function toRGBA(color: string, alpha: number): string;
|
|
@@ -5,8 +5,12 @@
|
|
|
5
5
|
*/
|
|
6
6
|
const HEX_COLOR_REGEXP = /^(#)([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i;
|
|
7
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
|
+
const RGBA_COLOR_REGEXP = /^rgba[(](?:\s*0*(?:\d\d?(?:\.\d+)?(?:\s*%)?|\.\d+\s*%|100(?:\.0*)?\s*%|(?:1\d\d|2[0-4]\d|25[0-5])(?:\.\d+)?)\s*,){3}\s*0*(?:\.\d+|1(?:\.0*)?)\s*[)]$/;
|
|
9
|
+
export const isHex = (color) => HEX_COLOR_REGEXP.exec(color);
|
|
10
|
+
export const isRgb = (color) => RGB_COLOR_REGEXP.exec(color);
|
|
11
|
+
export const isRgba = (color) => RGBA_COLOR_REGEXP.exec(color);
|
|
8
12
|
function parseColor(color) {
|
|
9
|
-
const match =
|
|
13
|
+
const match = isHex(color) || isRgb(color);
|
|
10
14
|
let colors = [];
|
|
11
15
|
if (match) {
|
|
12
16
|
colors = match.slice(2, 5);
|