@ax-design/reveal-highlight 0.4.1 → 0.4.2

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/src/BaseConfig.ts CHANGED
@@ -1,311 +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
- };
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
311
  }