@ax-design/reveal-highlight 0.3.0-alpha.6 → 0.4.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 +0 -8
- package/build/BaseConfig.d.ts +43 -0
- package/build/BaseConfig.d.ts.map +1 -0
- package/build/CanvasConfig.d.ts +7 -92
- package/build/CanvasConfig.d.ts.map +1 -1
- package/build/CustomElements.d.ts +18 -4
- package/build/CustomElements.d.ts.map +1 -1
- package/build/Profiler.d.ts.map +1 -1
- package/build/RevealBoundryStore.d.ts +50 -10
- package/build/RevealBoundryStore.d.ts.map +1 -1
- package/build/RevealStateManager.d.ts +3 -0
- package/build/RevealStateManager.d.ts.map +1 -1
- package/build/SvgConfig.d.ts +17 -0
- package/build/SvgConfig.d.ts.map +1 -0
- package/build/index.d.ts.map +1 -1
- package/build/main.js +169 -17
- package/build/utils/extractRGBValue.d.ts +2 -0
- package/build/utils/extractRGBValue.d.ts.map +1 -0
- package/build/utils/isValidateBorderDecorationType.d.ts +3 -0
- package/build/utils/isValidateBorderDecorationType.d.ts.map +1 -0
- package/build/utils/types.d.ts +103 -0
- package/build/utils/types.d.ts.map +1 -0
- package/build/variables.d.ts +1 -1
- package/build/variables.d.ts.map +1 -1
- package/docs/demo/index.html +70 -143
- package/docs/demo/ng.html +992 -0
- package/es/BaseConfig.d.ts +43 -0
- package/es/BaseConfig.d.ts.map +1 -0
- package/es/BaseConfig.js +220 -0
- package/es/BaseConfig.js.map +1 -0
- package/es/CanvasConfig.d.ts +7 -92
- package/es/CanvasConfig.d.ts.map +1 -1
- package/es/CanvasConfig.js +35 -233
- package/es/CanvasConfig.js.map +1 -1
- package/es/CustomElements.d.ts +18 -4
- package/es/CustomElements.d.ts.map +1 -1
- package/es/CustomElements.js +82 -7
- package/es/CustomElements.js.map +1 -1
- package/es/Profiler.d.ts.map +1 -1
- package/es/Profiler.js +0 -2
- package/es/Profiler.js.map +1 -1
- package/es/RevealBoundryStore.d.ts +50 -10
- package/es/RevealBoundryStore.d.ts.map +1 -1
- package/es/RevealBoundryStore.js +129 -35
- package/es/RevealBoundryStore.js.map +1 -1
- package/es/RevealStateManager.d.ts +3 -0
- package/es/RevealStateManager.d.ts.map +1 -1
- package/es/RevealStateManager.js +35 -8
- package/es/RevealStateManager.js.map +1 -1
- package/es/SvgConfig.d.ts +17 -0
- package/es/SvgConfig.d.ts.map +1 -0
- package/es/SvgConfig.js +346 -0
- package/es/SvgConfig.js.map +1 -0
- package/es/index.d.ts.map +1 -1
- package/es/index.js +15 -21
- package/es/index.js.map +1 -1
- package/es/utils/extractRGBValue.d.ts +2 -0
- package/es/utils/extractRGBValue.d.ts.map +1 -0
- package/es/utils/extractRGBValue.js +48 -0
- package/es/utils/extractRGBValue.js.map +1 -0
- package/es/utils/isValidateBorderDecorationType.d.ts +3 -0
- package/es/utils/isValidateBorderDecorationType.d.ts.map +1 -0
- package/es/utils/isValidateBorderDecorationType.js +10 -0
- package/es/utils/isValidateBorderDecorationType.js.map +1 -0
- package/es/utils/types.d.ts +103 -0
- package/es/utils/types.d.ts.map +1 -0
- package/es/utils/types.js +2 -0
- package/es/utils/types.js.map +1 -0
- package/es/variables.d.ts +1 -1
- package/es/variables.d.ts.map +1 -1
- package/es/variables.js +1 -1
- package/es/variables.js.map +1 -1
- package/package.json +30 -30
- package/src/BaseConfig.ts +311 -0
- package/src/CanvasConfig.ts +66 -377
- package/src/CustomElements.ts +97 -14
- package/src/Profiler.ts +0 -3
- package/src/RevealBoundryStore.ts +138 -39
- package/src/RevealStateManager.ts +40 -10
- package/src/SvgConfig.ts +422 -0
- package/src/index.ts +15 -21
- package/src/utils/extractRGBValue.ts +58 -0
- package/src/utils/isValidateBorderDecorationType.ts +8 -0
- package/src/utils/types.ts +106 -0
- package/src/variables.ts +1 -1
- package/.yarnrc.yml +0 -1
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
export declare type BorderDecoration = 'round' | 'bevel' | 'miter';
|
|
2
|
+
export interface CachedBoundingRect {
|
|
3
|
+
top: number;
|
|
4
|
+
left: number;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
}
|
|
8
|
+
export interface CachedStyle {
|
|
9
|
+
color: string;
|
|
10
|
+
opacity: number;
|
|
11
|
+
trueFillRadius: [number, number];
|
|
12
|
+
borderColor: string;
|
|
13
|
+
borderFillRadius: number;
|
|
14
|
+
borderDecorationType: BorderDecoration;
|
|
15
|
+
borderDecorationRadius: number;
|
|
16
|
+
topLeftBorderDecorationRadius: number;
|
|
17
|
+
topRightBorderDecorationRadius: number;
|
|
18
|
+
bottomLeftBorderDecorationRadius: number;
|
|
19
|
+
bottomRightBorderDecorationRadius: number;
|
|
20
|
+
/**
|
|
21
|
+
* @param withLeftBorderFactor
|
|
22
|
+
* If the left border is shown, this value is 1, or the value is 0.
|
|
23
|
+
*/
|
|
24
|
+
withLeftBorderFactor: number;
|
|
25
|
+
/**
|
|
26
|
+
* @param withRightBorderFactor
|
|
27
|
+
* If the right border is shown, this value is 1, or the value is 0.
|
|
28
|
+
*/
|
|
29
|
+
withRightBorderFactor: number;
|
|
30
|
+
/**
|
|
31
|
+
* @param withTopBorderFactor
|
|
32
|
+
* If the top border is shown, this value is 1, or the value is 0.
|
|
33
|
+
*/
|
|
34
|
+
withTopBorderFactor: number;
|
|
35
|
+
/**
|
|
36
|
+
* @param withBottomBorderFactor
|
|
37
|
+
* If the bottom border is shown, this value is 1, or the value is 0.
|
|
38
|
+
*/
|
|
39
|
+
withBottomBorderFactor: number;
|
|
40
|
+
borderWidth: number;
|
|
41
|
+
hoverLight: boolean;
|
|
42
|
+
hoverLightColor: string;
|
|
43
|
+
hoverLightFillMode: string;
|
|
44
|
+
hoverLightFillRadius: number;
|
|
45
|
+
diffuse: boolean;
|
|
46
|
+
pressAnimation: boolean;
|
|
47
|
+
pressAnimationFillMode: string;
|
|
48
|
+
pressAnimationColor: string;
|
|
49
|
+
pressAnimationSpeed: number;
|
|
50
|
+
releaseAnimationAccelerateRate: number;
|
|
51
|
+
}
|
|
52
|
+
interface CachedReveal {
|
|
53
|
+
radius: number;
|
|
54
|
+
radiusFactor: number;
|
|
55
|
+
color: string;
|
|
56
|
+
opacity: number;
|
|
57
|
+
pattern: CanvasPattern | null;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Cached border and body pattern, for faster painting on the canvas.
|
|
61
|
+
* @interface CachedRevealBitmap
|
|
62
|
+
*/
|
|
63
|
+
export interface CachedRevealBitmap {
|
|
64
|
+
cachedReveal: {
|
|
65
|
+
borderReveal: CachedReveal;
|
|
66
|
+
fillReveal: CachedReveal;
|
|
67
|
+
};
|
|
68
|
+
cachedCanvas: {
|
|
69
|
+
borderReveal: HTMLCanvasElement;
|
|
70
|
+
fillReveal: HTMLCanvasElement;
|
|
71
|
+
};
|
|
72
|
+
cachedCtx: {
|
|
73
|
+
borderReveal: CanvasRenderingContext2D | null;
|
|
74
|
+
fillReveal: CanvasRenderingContext2D | null;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Cached border and body pattern, just to store something in similar way.
|
|
79
|
+
* @interface CachedRevealPath
|
|
80
|
+
*/
|
|
81
|
+
export interface CachedRevealPath {
|
|
82
|
+
cachedReveal: {
|
|
83
|
+
readonly borderReveal: CachedReveal;
|
|
84
|
+
readonly fillReveal: CachedReveal;
|
|
85
|
+
};
|
|
86
|
+
cachedPath: {
|
|
87
|
+
readonly borderReveal: SVGPathElement;
|
|
88
|
+
readonly fillReveal: SVGPathElement;
|
|
89
|
+
readonly rippleReveal: SVGPathElement;
|
|
90
|
+
};
|
|
91
|
+
cachedGradient: {
|
|
92
|
+
readonly borderReveal: SVGRadialGradientElement;
|
|
93
|
+
readonly fillReveal: SVGRadialGradientElement;
|
|
94
|
+
readonly rippleReveal: SVGRadialGradientElement;
|
|
95
|
+
};
|
|
96
|
+
cachedGradientStop: {
|
|
97
|
+
readonly borderReveal: Readonly<[SVGStopElement, SVGStopElement]>;
|
|
98
|
+
readonly fillReveal: Readonly<[SVGStopElement, SVGStopElement]>;
|
|
99
|
+
readonly rippleReveal: Readonly<[SVGStopElement, SVGStopElement, SVGStopElement]>;
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
export {};
|
|
103
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":""}
|
package/es/variables.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const MAGIC_DEFAULT_COLOR = "
|
|
1
|
+
export declare const MAGIC_DEFAULT_COLOR = "magic";
|
|
2
2
|
//# sourceMappingURL=variables.d.ts.map
|
package/es/variables.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variables.d.ts","sourceRoot":"","sources":["../src/variables.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,
|
|
1
|
+
{"version":3,"file":"variables.d.ts","sourceRoot":"","sources":["../src/variables.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,UAAU,CAAC"}
|
package/es/variables.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const MAGIC_DEFAULT_COLOR = '
|
|
1
|
+
export const MAGIC_DEFAULT_COLOR = 'magic';
|
|
2
2
|
//# sourceMappingURL=variables.js.map
|
package/es/variables.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variables.js","sourceRoot":"","sources":["../src/variables.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,mBAAmB,GAAG,
|
|
1
|
+
{"version":3,"file":"variables.js","sourceRoot":"","sources":["../src/variables.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,mBAAmB,GAAG,OAAO,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@ax-design/reveal-highlight",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Web component that implement Reveal Highlight of Axiom Design System.",
|
|
5
|
+
"main": "build/main.js",
|
|
6
|
+
"module": "es/index.js",
|
|
7
|
+
"typings": "es/index.d.ts",
|
|
8
|
+
"repository": "https://github.com/ax-design/reveal-highlight",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"sideEffects": false,
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"npm-run-all": "^4.1.5",
|
|
13
|
+
"prettier": "2.2.1",
|
|
14
|
+
"rimraf": "^2.6.3",
|
|
15
|
+
"rollup": "^2.38.5",
|
|
16
|
+
"rollup-plugin-babel-minify": "^10.0.0",
|
|
17
|
+
"rollup-plugin-typescript2": "^0.29.0",
|
|
18
|
+
"typescript": "^4.1.5"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"start": "npm-run-all --parallel start-tsc start-rollup",
|
|
22
|
+
"start-tsc": "tsc --watch",
|
|
23
|
+
"start-rollup": "rollup -c -w",
|
|
24
|
+
"build": "npm-run-all clean --parallel build-tsc build-rollup",
|
|
25
|
+
"build-tsc": "tsc",
|
|
26
|
+
"build-rollup": "rollup -c",
|
|
27
|
+
"clean": "rimraf ./es ./build",
|
|
28
|
+
"prepublishOnly": "npm run build"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import { ComputedStyleStorage, createStorage } from './ComputedStyleStorage.js';
|
|
2
|
+
import { RevealBoundaryStore } from './RevealBoundryStore.js';
|
|
3
|
+
|
|
4
|
+
import { extractRGBValue } from './utils/extractRGBValue.js'
|
|
5
|
+
import { isValidateBorderDecorationType } from './utils/isValidateBorderDecorationType.js';
|
|
6
|
+
import type { BorderDecoration, CachedBoundingRect, CachedStyle } from './utils/types.js';
|
|
7
|
+
|
|
8
|
+
export class BaseConfig<T extends Element> {
|
|
9
|
+
protected _store: RevealBoundaryStore;
|
|
10
|
+
|
|
11
|
+
pxRatio = window.devicePixelRatio || 1;
|
|
12
|
+
|
|
13
|
+
readonly container: HTMLElement;
|
|
14
|
+
readonly element: T;
|
|
15
|
+
|
|
16
|
+
protected readonly computedStyle: ComputedStyleStorage;
|
|
17
|
+
|
|
18
|
+
paintedWidth = 0;
|
|
19
|
+
paintedHeight = 0;
|
|
20
|
+
|
|
21
|
+
currentFrameId: number = -1;
|
|
22
|
+
|
|
23
|
+
cachedBoundingRectFrameId: number = -2;
|
|
24
|
+
|
|
25
|
+
cachedBoundingRect: CachedBoundingRect = {
|
|
26
|
+
top: -1,
|
|
27
|
+
left: -1,
|
|
28
|
+
width: -1,
|
|
29
|
+
height: -1,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
cachedStyleFrameId: number = -2;
|
|
33
|
+
|
|
34
|
+
cachedStyle: CachedStyle = {
|
|
35
|
+
trueFillRadius: [0, 0],
|
|
36
|
+
color: '',
|
|
37
|
+
opacity: 1,
|
|
38
|
+
borderColor: '',
|
|
39
|
+
borderFillRadius: 0,
|
|
40
|
+
borderDecorationType: 'miter',
|
|
41
|
+
borderDecorationRadius: 0,
|
|
42
|
+
topLeftBorderDecorationRadius: 0,
|
|
43
|
+
topRightBorderDecorationRadius: 0,
|
|
44
|
+
bottomLeftBorderDecorationRadius: 0,
|
|
45
|
+
bottomRightBorderDecorationRadius: 0,
|
|
46
|
+
withLeftBorderFactor: 1,
|
|
47
|
+
withRightBorderFactor: 1,
|
|
48
|
+
withTopBorderFactor: 1,
|
|
49
|
+
withBottomBorderFactor: 1,
|
|
50
|
+
borderWidth: 1,
|
|
51
|
+
hoverLight: true,
|
|
52
|
+
hoverLightColor: '',
|
|
53
|
+
hoverLightFillMode: '',
|
|
54
|
+
hoverLightFillRadius: 0,
|
|
55
|
+
diffuse: true,
|
|
56
|
+
pressAnimation: true,
|
|
57
|
+
pressAnimationFillMode: '',
|
|
58
|
+
pressAnimationColor: '',
|
|
59
|
+
pressAnimationSpeed: 0,
|
|
60
|
+
releaseAnimationAccelerateRate: 0,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
dirty: boolean = false;
|
|
64
|
+
|
|
65
|
+
shapeDirty: boolean = true;
|
|
66
|
+
fillDirty: boolean = true;
|
|
67
|
+
animationDirty: boolean = true;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* If is cleaned up by `RevealBoundaryStore` during animation
|
|
71
|
+
* duration checkup.
|
|
72
|
+
*/
|
|
73
|
+
cleanedUpForAnimation: boolean = false;
|
|
74
|
+
|
|
75
|
+
mouseUpClientX: number | null = null;
|
|
76
|
+
mouseUpClientY: number | null = null;
|
|
77
|
+
mouseDownAnimateStartFrame: number | null = null;
|
|
78
|
+
mouseDownAnimateCurrentFrame: number | null = null;
|
|
79
|
+
mouseDownAnimateReleasedFrame: number | null = null;
|
|
80
|
+
mouseDownAnimateLogicFrame: number | null = null;
|
|
81
|
+
mousePressed = false;
|
|
82
|
+
|
|
83
|
+
mouseReleased = false;
|
|
84
|
+
|
|
85
|
+
constructor(store: RevealBoundaryStore, $canvas: T, $container: HTMLElement) {
|
|
86
|
+
this._store = store;
|
|
87
|
+
|
|
88
|
+
this.container = $container;
|
|
89
|
+
this.element = $canvas;
|
|
90
|
+
|
|
91
|
+
this.computedStyle = createStorage($container);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
cacheBoundingRect = () => {
|
|
95
|
+
if (this.currentFrameId === this.cachedBoundingRectFrameId) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const boundingRect = this.container.getBoundingClientRect();
|
|
100
|
+
|
|
101
|
+
this.cachedBoundingRect.top = Math.floor(boundingRect.top);
|
|
102
|
+
this.cachedBoundingRect.left = Math.floor(boundingRect.left);
|
|
103
|
+
this.cachedBoundingRect.width = Math.floor(boundingRect.width);
|
|
104
|
+
this.cachedBoundingRect.height = Math.floor(boundingRect.height);
|
|
105
|
+
|
|
106
|
+
this.cachedBoundingRectFrameId = this.currentFrameId;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
getTrueFillRadius = (
|
|
110
|
+
trueFillRadius = [0, 0] as [number, number],
|
|
111
|
+
fillMode = this.computedStyle.get('--reveal-hover-light-fill-radius-mode') || 'relative'
|
|
112
|
+
) => {
|
|
113
|
+
const b = this.cachedBoundingRect;
|
|
114
|
+
|
|
115
|
+
switch (fillMode) {
|
|
116
|
+
case 'relative':
|
|
117
|
+
trueFillRadius[0] = Math.min(b.width, b.height);
|
|
118
|
+
trueFillRadius[1] = Math.max(b.width, b.height);
|
|
119
|
+
break;
|
|
120
|
+
case 'absolute':
|
|
121
|
+
trueFillRadius[0] = -1;
|
|
122
|
+
trueFillRadius[1] = -1;
|
|
123
|
+
break;
|
|
124
|
+
default:
|
|
125
|
+
throw new SyntaxError(
|
|
126
|
+
'The value of `--reveal-hover-light-fill-radius-mode` must be `relative`, `absolute`, but got `' + fillMode + '`!'
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return trueFillRadius;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
getPropFromMultipleSource = (domPropsName: string, cssPropsName: string) => {
|
|
134
|
+
const domProps = this.container.dataset[domPropsName];
|
|
135
|
+
if (domProps) return domProps;
|
|
136
|
+
|
|
137
|
+
return this.computedStyle.get(cssPropsName);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
getNumberPropFromMultipleSource = (domPropsName: string, cssPropsName: string) => {
|
|
141
|
+
const domProps = this.container.dataset[domPropsName];
|
|
142
|
+
if (domProps) return Number.parseFloat(domProps);
|
|
143
|
+
|
|
144
|
+
return this.computedStyle.getNumber(cssPropsName);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
cacheCanvasPaintingStyle = () => {
|
|
148
|
+
if (this.currentFrameId === this.cachedStyleFrameId) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (this.computedStyle.size() === 0) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const parsedBaseColor = extractRGBValue(this.computedStyle.getColor('--reveal-color')) || '0, 0, 0';
|
|
157
|
+
const parsedBorderColor =
|
|
158
|
+
extractRGBValue(this.computedStyle.getColor('--reveal-border-color')) || parsedBaseColor;
|
|
159
|
+
const parsedHoverLightColor =
|
|
160
|
+
extractRGBValue(this.computedStyle.getColor('--reveal-hover-light-color')) || parsedBaseColor;
|
|
161
|
+
const parsedPressAnimationColor =
|
|
162
|
+
extractRGBValue(this.computedStyle.getColor('--reveal-press-animation-color')) || parsedBaseColor;
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
const nextColor = parsedBaseColor;
|
|
166
|
+
const nextOpacity = this.computedStyle.getNumber('--reveal-opacity');
|
|
167
|
+
|
|
168
|
+
// Border related configurations
|
|
169
|
+
const nextBorderColor = parsedBorderColor;
|
|
170
|
+
|
|
171
|
+
const nextBorderFillRadius = this.computedStyle.getNumber('--reveal-border-fill-radius');
|
|
172
|
+
const nextBorderDecorationType =
|
|
173
|
+
(this.computedStyle.get('--reveal-border-decoration-type') as BorderDecoration) || 'miter';
|
|
174
|
+
const nextBorderWidth = this.computedStyle.getNumber('--reveal-border-width');
|
|
175
|
+
|
|
176
|
+
const nextWithLeftBorderFactor =
|
|
177
|
+
this.getPropFromMultipleSource('leftBorder', '--reveal-border-left-type') === 'line' ? 1 : 0;
|
|
178
|
+
const nextWithRightBorderFactor =
|
|
179
|
+
this.getPropFromMultipleSource('rightBorder', '--reveal-border-right-type') === 'line' ? 1 : 0;
|
|
180
|
+
const nextWithTopBorderFactor = this.getPropFromMultipleSource('topBorder', '--reveal-border-top-type') === 'line' ? 1 : 0;
|
|
181
|
+
const nextWithBottomBorderFactor =
|
|
182
|
+
this.getPropFromMultipleSource('bottomBorder', '--reveal-border-bottom-type') === 'line' ? 1 : 0;
|
|
183
|
+
|
|
184
|
+
// Hover light related configurations
|
|
185
|
+
const nextHoverLight = this.computedStyle.get('--reveal-hover-light') === 'true';
|
|
186
|
+
const nextHoverLightColor = parsedHoverLightColor;
|
|
187
|
+
const nextHoverLightFillRadius = this.computedStyle.getNumber('--reveal-hover-light-fill-radius');
|
|
188
|
+
const nextHoverLightFillMode = this.computedStyle.get('--reveal-hover-light-fill-radius-mode') || 'relative';
|
|
189
|
+
|
|
190
|
+
// Press animation related configurations
|
|
191
|
+
const nextDiffuse = this.computedStyle.get('--reveal-diffuse') === 'true';
|
|
192
|
+
const nextPressAnimation = this.computedStyle.get('--reveal-press-animation') === 'true';
|
|
193
|
+
const nextPressAnimationFillMode = this.computedStyle.get('--reveal-press-animation-radius-mode');
|
|
194
|
+
const nextPressAnimationColor = parsedPressAnimationColor;
|
|
195
|
+
const nextPressAnimationSpeed = this.computedStyle.getNumber('--reveal-press-animation-speed');
|
|
196
|
+
const nextReleaseAnimationAccelerateRate = this.computedStyle.getNumber('--reveal-release-animation-accelerate-rate');
|
|
197
|
+
|
|
198
|
+
// Border decoration related configurations
|
|
199
|
+
const r = this.computedStyle.getNumber('--reveal-border-decoration-radius');
|
|
200
|
+
const tl = this.getNumberPropFromMultipleSource(
|
|
201
|
+
'topLeftBorderRadius',
|
|
202
|
+
'--reveal-border-decoration-top-left-radius'
|
|
203
|
+
);
|
|
204
|
+
const tr = this.getNumberPropFromMultipleSource(
|
|
205
|
+
'topRightBorderRadius',
|
|
206
|
+
'--reveal-border-decoration-top-right-radius'
|
|
207
|
+
);
|
|
208
|
+
const bl = this.getNumberPropFromMultipleSource(
|
|
209
|
+
'bottomLeftBorderRadius',
|
|
210
|
+
'--reveal-border-decoration-bottom-left-radius'
|
|
211
|
+
);
|
|
212
|
+
const br = this.getNumberPropFromMultipleSource(
|
|
213
|
+
'bottomRightBorderRadius',
|
|
214
|
+
'--reveal-border-decoration-bottom-right-radius'
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
const nextTopLeftBorderDecorationRadius = tl >= 0 ? tl : r;
|
|
218
|
+
const nextTopRightBorderDecorationRadius = tr >= 0 ? tr : r;
|
|
219
|
+
const nextBottomLeftBorderDecorationRadius = bl >= 0 ? bl : r;
|
|
220
|
+
const nextBottomRightBorderDecorationRadius = br >= 0 ? br : r;
|
|
221
|
+
|
|
222
|
+
const c = this.cachedStyle;
|
|
223
|
+
|
|
224
|
+
this.fillDirty = this.fillDirty || c.color !== nextColor;
|
|
225
|
+
this.fillDirty = this.fillDirty || c.opacity !== nextOpacity;
|
|
226
|
+
this.fillDirty = this.fillDirty || c.borderColor !== nextBorderColor;
|
|
227
|
+
this.fillDirty = this.fillDirty || c.borderFillRadius !== nextBorderFillRadius;
|
|
228
|
+
this.fillDirty = this.fillDirty || c.hoverLightColor !== nextHoverLightColor;
|
|
229
|
+
this.fillDirty = this.fillDirty || c.hoverLightFillRadius !== nextHoverLightFillRadius;
|
|
230
|
+
this.fillDirty = this.fillDirty || c.hoverLightFillMode !== nextHoverLightFillMode;
|
|
231
|
+
|
|
232
|
+
this.shapeDirty = this.shapeDirty || c.borderDecorationType !== nextBorderDecorationType;
|
|
233
|
+
this.shapeDirty = this.shapeDirty || c.borderWidth !== nextBorderWidth;
|
|
234
|
+
this.shapeDirty = this.shapeDirty || c.withLeftBorderFactor !== nextWithLeftBorderFactor;
|
|
235
|
+
this.shapeDirty = this.shapeDirty || c.withRightBorderFactor !== nextWithRightBorderFactor;
|
|
236
|
+
this.shapeDirty = this.shapeDirty || c.withTopBorderFactor !== nextWithTopBorderFactor;
|
|
237
|
+
this.shapeDirty = this.shapeDirty || c.withBottomBorderFactor !== nextWithBottomBorderFactor;
|
|
238
|
+
this.shapeDirty = this.shapeDirty || c.topLeftBorderDecorationRadius !== nextTopLeftBorderDecorationRadius;
|
|
239
|
+
this.shapeDirty = this.shapeDirty || c.topRightBorderDecorationRadius !== nextTopRightBorderDecorationRadius;
|
|
240
|
+
this.shapeDirty = this.shapeDirty || c.bottomLeftBorderDecorationRadius !== nextBottomLeftBorderDecorationRadius;
|
|
241
|
+
this.shapeDirty = this.shapeDirty || c.bottomRightBorderDecorationRadius !== nextBottomRightBorderDecorationRadius;
|
|
242
|
+
|
|
243
|
+
this.animationDirty = this.animationDirty || c.pressAnimation !== nextPressAnimation;
|
|
244
|
+
this.animationDirty = this.animationDirty || c.pressAnimationFillMode !== nextPressAnimationFillMode;
|
|
245
|
+
this.animationDirty = this.animationDirty || c.pressAnimationColor !== nextPressAnimationColor;
|
|
246
|
+
this.animationDirty = this.animationDirty || c.pressAnimationSpeed !== nextPressAnimationSpeed;
|
|
247
|
+
this.animationDirty = this.animationDirty || c.releaseAnimationAccelerateRate !== nextReleaseAnimationAccelerateRate;
|
|
248
|
+
|
|
249
|
+
c.color = nextColor;
|
|
250
|
+
c.opacity = nextOpacity;
|
|
251
|
+
|
|
252
|
+
c.borderColor = nextBorderColor;
|
|
253
|
+
|
|
254
|
+
c.borderFillRadius = nextBorderFillRadius;
|
|
255
|
+
c.borderDecorationType = nextBorderDecorationType;
|
|
256
|
+
c.borderWidth = nextBorderWidth;
|
|
257
|
+
|
|
258
|
+
c.withLeftBorderFactor = nextWithLeftBorderFactor;
|
|
259
|
+
c.withRightBorderFactor = nextWithRightBorderFactor;
|
|
260
|
+
c.withTopBorderFactor = nextWithTopBorderFactor;
|
|
261
|
+
c.withBottomBorderFactor = nextWithBottomBorderFactor;
|
|
262
|
+
|
|
263
|
+
c.hoverLight = nextHoverLight;
|
|
264
|
+
c.hoverLightColor = nextHoverLightColor;
|
|
265
|
+
c.hoverLightFillRadius = nextHoverLightFillRadius;
|
|
266
|
+
c.hoverLightFillMode = nextHoverLightFillMode;
|
|
267
|
+
|
|
268
|
+
c.diffuse = nextDiffuse;
|
|
269
|
+
c.pressAnimation = nextPressAnimation;
|
|
270
|
+
c.pressAnimationFillMode = nextPressAnimationFillMode;
|
|
271
|
+
c.pressAnimationColor = nextPressAnimationColor;
|
|
272
|
+
c.pressAnimationSpeed = nextPressAnimationSpeed;
|
|
273
|
+
c.releaseAnimationAccelerateRate = nextReleaseAnimationAccelerateRate;
|
|
274
|
+
|
|
275
|
+
c.topLeftBorderDecorationRadius = nextTopLeftBorderDecorationRadius;
|
|
276
|
+
c.topRightBorderDecorationRadius = nextTopRightBorderDecorationRadius;
|
|
277
|
+
c.bottomLeftBorderDecorationRadius = nextBottomLeftBorderDecorationRadius;
|
|
278
|
+
c.bottomRightBorderDecorationRadius = nextBottomRightBorderDecorationRadius;
|
|
279
|
+
|
|
280
|
+
this.getTrueFillRadius(c.trueFillRadius, c.hoverLightFillMode);
|
|
281
|
+
|
|
282
|
+
if (!isValidateBorderDecorationType(c.borderDecorationType)) {
|
|
283
|
+
throw new SyntaxError(
|
|
284
|
+
'The value of `--reveal-border-decoration-type` must be `round`, `bevel` or `miter`!'
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
this.cachedStyleFrameId = this.currentFrameId;
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
mouseInCanvas = () => {
|
|
292
|
+
const b = this.cachedBoundingRect;
|
|
293
|
+
|
|
294
|
+
const relativeX = this._store.clientX - b.left;
|
|
295
|
+
const relativeY = this._store.clientY - b.top;
|
|
296
|
+
|
|
297
|
+
return relativeX > 0 && relativeY > 0 && relativeX < b.width && relativeY < b.height;
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
syncSizeToRevealRadius = (x: HTMLCanvasElement, factor: number) => {
|
|
301
|
+
const { trueFillRadius } = this.cachedStyle;
|
|
302
|
+
|
|
303
|
+
const radius = trueFillRadius[1] || 1;
|
|
304
|
+
const size = radius * 2 * this.pxRatio * factor;
|
|
305
|
+
|
|
306
|
+
if (x.width !== size || x.height !== size) {
|
|
307
|
+
x.width = size;
|
|
308
|
+
x.height = size;
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
}
|