@ax-design/reveal-highlight 0.4.2 → 0.5.3

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.
Files changed (74) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +75 -75
  3. package/build/BaseConfig.d.ts +5 -1
  4. package/build/BaseConfig.d.ts.map +1 -1
  5. package/build/CanvasConfig.d.ts +7 -1
  6. package/build/CanvasConfig.d.ts.map +1 -1
  7. package/build/ComputedStyleStorage.d.ts.map +1 -1
  8. package/build/CustomElements.d.ts +20 -4
  9. package/build/CustomElements.d.ts.map +1 -1
  10. package/build/RevealBoundryStore.d.ts +4 -0
  11. package/build/RevealBoundryStore.d.ts.map +1 -1
  12. package/build/RevealStateManager.d.ts +5 -1
  13. package/build/RevealStateManager.d.ts.map +1 -1
  14. package/build/main.js +113 -82
  15. package/build/utils/types.d.ts +2 -10
  16. package/build/utils/types.d.ts.map +1 -1
  17. package/es/BaseConfig.d.ts +46 -42
  18. package/es/BaseConfig.d.ts.map +1 -1
  19. package/es/BaseConfig.js +241 -219
  20. package/es/BaseConfig.js.map +1 -1
  21. package/es/CanvasConfig.d.ts +21 -15
  22. package/es/CanvasConfig.d.ts.map +1 -1
  23. package/es/CanvasConfig.js +332 -320
  24. package/es/CanvasConfig.js.map +1 -1
  25. package/es/ComputedStyleStorage.d.ts +8 -8
  26. package/es/ComputedStyleStorage.d.ts.map +1 -1
  27. package/es/ComputedStyleStorage.js +68 -58
  28. package/es/ComputedStyleStorage.js.map +1 -1
  29. package/es/CustomElements.d.ts +75 -59
  30. package/es/CustomElements.d.ts.map +1 -1
  31. package/es/CustomElements.js +296 -233
  32. package/es/CustomElements.js.map +1 -1
  33. package/es/Profiler.d.ts +12 -12
  34. package/es/Profiler.js +31 -31
  35. package/es/RevealBoundryStore.d.ts +80 -76
  36. package/es/RevealBoundryStore.d.ts.map +1 -1
  37. package/es/RevealBoundryStore.js +269 -248
  38. package/es/RevealBoundryStore.js.map +1 -1
  39. package/es/RevealStateManager.d.ts +19 -15
  40. package/es/RevealStateManager.d.ts.map +1 -1
  41. package/es/RevealStateManager.js +99 -73
  42. package/es/RevealStateManager.js.map +1 -1
  43. package/es/SvgConfig.d.ts +16 -16
  44. package/es/SvgConfig.js +345 -345
  45. package/es/config.d.ts +4 -4
  46. package/es/config.js +21 -21
  47. package/es/index.d.ts +5 -5
  48. package/es/index.js +205 -205
  49. package/es/tsconfig.tsbuildinfo +1 -1
  50. package/es/utils/extractRGBValue.d.ts +1 -1
  51. package/es/utils/extractRGBValue.js +47 -47
  52. package/es/utils/isValidateBorderDecorationType.d.ts +2 -2
  53. package/es/utils/isValidateBorderDecorationType.js +9 -9
  54. package/es/utils/types.d.ts +94 -102
  55. package/es/utils/types.d.ts.map +1 -1
  56. package/es/utils/types.js +1 -1
  57. package/es/variables.d.ts +1 -1
  58. package/es/variables.js +1 -1
  59. package/package.json +35 -34
  60. package/src/BaseConfig.ts +332 -310
  61. package/src/CanvasConfig.ts +420 -415
  62. package/src/ComputedStyleStorage.ts +102 -89
  63. package/src/CustomElements.ts +344 -272
  64. package/src/Profiler.ts +44 -44
  65. package/src/RevealBoundryStore.ts +315 -291
  66. package/src/RevealStateManager.ts +109 -86
  67. package/src/SvgConfig.ts +422 -422
  68. package/src/config.ts +26 -26
  69. package/src/cssTypedOM.d.ts +52 -52
  70. package/src/index.ts +219 -219
  71. package/src/utils/extractRGBValue.ts +58 -58
  72. package/src/utils/isValidateBorderDecorationType.ts +8 -8
  73. package/src/utils/types.ts +97 -105
  74. package/src/variables.ts +1 -1
package/src/BaseConfig.ts CHANGED
@@ -1,311 +1,333 @@
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
+ /**
66
+ * Bumped whenever `cacheCanvasPaintingStyle` sees any value change, so
67
+ * painters can tell whether the last painted frame is still valid.
68
+ */
69
+ styleVersion: number = 0;
70
+
71
+ shapeDirty: boolean = true;
72
+ fillDirty: boolean = true;
73
+ animationDirty: boolean = true;
74
+
75
+ /**
76
+ * If is cleaned up by `RevealBoundaryStore` during animation
77
+ * duration checkup.
78
+ */
79
+ cleanedUpForAnimation: boolean = false;
80
+
81
+ mouseUpClientX: number | null = null;
82
+ mouseUpClientY: number | null = null;
83
+ mouseDownAnimateStartFrame: number | null = null;
84
+ mouseDownAnimateCurrentFrame: number | null = null;
85
+ mouseDownAnimateReleasedFrame: number | null = null;
86
+ mouseDownAnimateLogicFrame: number | null = null;
87
+ mousePressed = false;
88
+
89
+ mouseReleased = false;
90
+
91
+ constructor(store: RevealBoundaryStore, $canvas: T, $container: HTMLElement) {
92
+ this._store = store;
93
+
94
+ this.container = $container;
95
+ this.element = $canvas;
96
+
97
+ this.computedStyle = createStorage($container);
98
+ }
99
+
100
+ cacheBoundingRect = () => {
101
+ if (this.currentFrameId === this.cachedBoundingRectFrameId) {
102
+ return;
103
+ }
104
+
105
+ const boundingRect = this.container.getBoundingClientRect();
106
+
107
+ this.cachedBoundingRect.top = Math.floor(boundingRect.top);
108
+ this.cachedBoundingRect.left = Math.floor(boundingRect.left);
109
+ this.cachedBoundingRect.width = Math.floor(boundingRect.width);
110
+ this.cachedBoundingRect.height = Math.floor(boundingRect.height);
111
+
112
+ this.cachedBoundingRectFrameId = this.currentFrameId;
113
+ };
114
+
115
+ getTrueFillRadius = (
116
+ trueFillRadius = [0, 0] as [number, number],
117
+ fillMode = this.computedStyle.get('--reveal-hover-light-fill-radius-mode') || 'relative'
118
+ ) => {
119
+ const b = this.cachedBoundingRect;
120
+
121
+ switch (fillMode) {
122
+ case 'relative':
123
+ trueFillRadius[0] = Math.min(b.width, b.height);
124
+ trueFillRadius[1] = Math.max(b.width, b.height);
125
+ break;
126
+ case 'absolute':
127
+ trueFillRadius[0] = -1;
128
+ trueFillRadius[1] = -1;
129
+ break;
130
+ default:
131
+ throw new SyntaxError(
132
+ 'The value of `--reveal-hover-light-fill-radius-mode` must be `relative`, `absolute`, but got `' + fillMode + '`!'
133
+ );
134
+ }
135
+
136
+ return trueFillRadius;
137
+ };
138
+
139
+ getPropFromMultipleSource = (domPropsName: string, cssPropsName: string) => {
140
+ const domProps = this.container.dataset[domPropsName];
141
+ if (domProps) return domProps;
142
+
143
+ return this.computedStyle.get(cssPropsName);
144
+ };
145
+
146
+ getNumberPropFromMultipleSource = (domPropsName: string, cssPropsName: string) => {
147
+ const domProps = this.container.dataset[domPropsName];
148
+ if (domProps) return Number.parseFloat(domProps);
149
+
150
+ return this.computedStyle.getNumber(cssPropsName);
151
+ };
152
+
153
+ cacheCanvasPaintingStyle = () => {
154
+ if (this.currentFrameId === this.cachedStyleFrameId) {
155
+ return;
156
+ }
157
+
158
+ if (this.computedStyle.size() === 0) {
159
+ return;
160
+ }
161
+
162
+ const parsedBaseColor = extractRGBValue(this.computedStyle.getColor('--reveal-color')) || '0, 0, 0';
163
+ const parsedBorderColor =
164
+ extractRGBValue(this.computedStyle.getColor('--reveal-border-color')) || parsedBaseColor;
165
+ const parsedHoverLightColor =
166
+ extractRGBValue(this.computedStyle.getColor('--reveal-hover-light-color')) || parsedBaseColor;
167
+ const parsedPressAnimationColor =
168
+ extractRGBValue(this.computedStyle.getColor('--reveal-press-animation-color')) || parsedBaseColor;
169
+
170
+
171
+ const nextColor = parsedBaseColor;
172
+ const nextOpacity = this.computedStyle.getNumber('--reveal-opacity');
173
+
174
+ // Border related configurations
175
+ const nextBorderColor = parsedBorderColor;
176
+
177
+ const nextBorderFillRadius = this.computedStyle.getNumber('--reveal-border-fill-radius');
178
+ const nextBorderDecorationType =
179
+ (this.computedStyle.get('--reveal-border-decoration-type') as BorderDecoration) || 'miter';
180
+ const nextBorderWidth = this.computedStyle.getNumber('--reveal-border-width');
181
+
182
+ const nextWithLeftBorderFactor =
183
+ this.getPropFromMultipleSource('leftBorder', '--reveal-border-left-type') === 'line' ? 1 : 0;
184
+ const nextWithRightBorderFactor =
185
+ this.getPropFromMultipleSource('rightBorder', '--reveal-border-right-type') === 'line' ? 1 : 0;
186
+ const nextWithTopBorderFactor = this.getPropFromMultipleSource('topBorder', '--reveal-border-top-type') === 'line' ? 1 : 0;
187
+ const nextWithBottomBorderFactor =
188
+ this.getPropFromMultipleSource('bottomBorder', '--reveal-border-bottom-type') === 'line' ? 1 : 0;
189
+
190
+ // Hover light related configurations
191
+ const nextHoverLight = this.computedStyle.get('--reveal-hover-light') === 'true';
192
+ const nextHoverLightColor = parsedHoverLightColor;
193
+ const nextHoverLightFillRadius = this.computedStyle.getNumber('--reveal-hover-light-fill-radius');
194
+ const nextHoverLightFillMode = this.computedStyle.get('--reveal-hover-light-fill-radius-mode') || 'relative';
195
+
196
+ // Press animation related configurations
197
+ const nextDiffuse = this.computedStyle.get('--reveal-diffuse') === 'true';
198
+ const nextPressAnimation = this.computedStyle.get('--reveal-press-animation') === 'true';
199
+ const nextPressAnimationFillMode = this.computedStyle.get('--reveal-press-animation-radius-mode');
200
+ const nextPressAnimationColor = parsedPressAnimationColor;
201
+ const nextPressAnimationSpeed = this.computedStyle.getNumber('--reveal-press-animation-speed');
202
+ const nextReleaseAnimationAccelerateRate = this.computedStyle.getNumber('--reveal-release-animation-accelerate-rate');
203
+
204
+ // Border decoration related configurations
205
+ const r = this.computedStyle.getNumber('--reveal-border-decoration-radius');
206
+ const tl = this.getNumberPropFromMultipleSource(
207
+ 'topLeftBorderRadius',
208
+ '--reveal-border-decoration-top-left-radius'
209
+ );
210
+ const tr = this.getNumberPropFromMultipleSource(
211
+ 'topRightBorderRadius',
212
+ '--reveal-border-decoration-top-right-radius'
213
+ );
214
+ const bl = this.getNumberPropFromMultipleSource(
215
+ 'bottomLeftBorderRadius',
216
+ '--reveal-border-decoration-bottom-left-radius'
217
+ );
218
+ const br = this.getNumberPropFromMultipleSource(
219
+ 'bottomRightBorderRadius',
220
+ '--reveal-border-decoration-bottom-right-radius'
221
+ );
222
+
223
+ const nextTopLeftBorderDecorationRadius = tl >= 0 ? tl : r;
224
+ const nextTopRightBorderDecorationRadius = tr >= 0 ? tr : r;
225
+ const nextBottomLeftBorderDecorationRadius = bl >= 0 ? bl : r;
226
+ const nextBottomRightBorderDecorationRadius = br >= 0 ? br : r;
227
+
228
+ const c = this.cachedStyle;
229
+
230
+ const styleChanged =
231
+ c.color !== nextColor ||
232
+ c.opacity !== nextOpacity ||
233
+ c.borderColor !== nextBorderColor ||
234
+ c.borderFillRadius !== nextBorderFillRadius ||
235
+ c.borderDecorationType !== nextBorderDecorationType ||
236
+ c.borderWidth !== nextBorderWidth ||
237
+ c.withLeftBorderFactor !== nextWithLeftBorderFactor ||
238
+ c.withRightBorderFactor !== nextWithRightBorderFactor ||
239
+ c.withTopBorderFactor !== nextWithTopBorderFactor ||
240
+ c.withBottomBorderFactor !== nextWithBottomBorderFactor ||
241
+ c.hoverLight !== nextHoverLight ||
242
+ c.hoverLightColor !== nextHoverLightColor ||
243
+ c.hoverLightFillRadius !== nextHoverLightFillRadius ||
244
+ c.hoverLightFillMode !== nextHoverLightFillMode ||
245
+ c.diffuse !== nextDiffuse ||
246
+ c.pressAnimation !== nextPressAnimation ||
247
+ c.pressAnimationFillMode !== nextPressAnimationFillMode ||
248
+ c.pressAnimationColor !== nextPressAnimationColor ||
249
+ c.pressAnimationSpeed !== nextPressAnimationSpeed ||
250
+ c.releaseAnimationAccelerateRate !== nextReleaseAnimationAccelerateRate ||
251
+ c.topLeftBorderDecorationRadius !== nextTopLeftBorderDecorationRadius ||
252
+ c.topRightBorderDecorationRadius !== nextTopRightBorderDecorationRadius ||
253
+ c.bottomLeftBorderDecorationRadius !== nextBottomLeftBorderDecorationRadius ||
254
+ c.bottomRightBorderDecorationRadius !== nextBottomRightBorderDecorationRadius;
255
+
256
+ if (styleChanged) this.styleVersion++;
257
+
258
+ this.fillDirty = this.fillDirty || c.color !== nextColor;
259
+ this.fillDirty = this.fillDirty || c.opacity !== nextOpacity;
260
+ this.fillDirty = this.fillDirty || c.borderColor !== nextBorderColor;
261
+ this.fillDirty = this.fillDirty || c.borderFillRadius !== nextBorderFillRadius;
262
+ this.fillDirty = this.fillDirty || c.hoverLightColor !== nextHoverLightColor;
263
+ this.fillDirty = this.fillDirty || c.hoverLightFillRadius !== nextHoverLightFillRadius;
264
+ this.fillDirty = this.fillDirty || c.hoverLightFillMode !== nextHoverLightFillMode;
265
+
266
+ this.shapeDirty = this.shapeDirty || c.borderDecorationType !== nextBorderDecorationType;
267
+ this.shapeDirty = this.shapeDirty || c.borderWidth !== nextBorderWidth;
268
+ this.shapeDirty = this.shapeDirty || c.withLeftBorderFactor !== nextWithLeftBorderFactor;
269
+ this.shapeDirty = this.shapeDirty || c.withRightBorderFactor !== nextWithRightBorderFactor;
270
+ this.shapeDirty = this.shapeDirty || c.withTopBorderFactor !== nextWithTopBorderFactor;
271
+ this.shapeDirty = this.shapeDirty || c.withBottomBorderFactor !== nextWithBottomBorderFactor;
272
+ this.shapeDirty = this.shapeDirty || c.topLeftBorderDecorationRadius !== nextTopLeftBorderDecorationRadius;
273
+ this.shapeDirty = this.shapeDirty || c.topRightBorderDecorationRadius !== nextTopRightBorderDecorationRadius;
274
+ this.shapeDirty = this.shapeDirty || c.bottomLeftBorderDecorationRadius !== nextBottomLeftBorderDecorationRadius;
275
+ this.shapeDirty = this.shapeDirty || c.bottomRightBorderDecorationRadius !== nextBottomRightBorderDecorationRadius;
276
+
277
+ this.animationDirty = this.animationDirty || c.pressAnimation !== nextPressAnimation;
278
+ this.animationDirty = this.animationDirty || c.pressAnimationFillMode !== nextPressAnimationFillMode;
279
+ this.animationDirty = this.animationDirty || c.pressAnimationColor !== nextPressAnimationColor;
280
+ this.animationDirty = this.animationDirty || c.pressAnimationSpeed !== nextPressAnimationSpeed;
281
+ this.animationDirty = this.animationDirty || c.releaseAnimationAccelerateRate !== nextReleaseAnimationAccelerateRate;
282
+
283
+ c.color = nextColor;
284
+ c.opacity = nextOpacity;
285
+
286
+ c.borderColor = nextBorderColor;
287
+
288
+ c.borderFillRadius = nextBorderFillRadius;
289
+ c.borderDecorationType = nextBorderDecorationType;
290
+ c.borderWidth = nextBorderWidth;
291
+
292
+ c.withLeftBorderFactor = nextWithLeftBorderFactor;
293
+ c.withRightBorderFactor = nextWithRightBorderFactor;
294
+ c.withTopBorderFactor = nextWithTopBorderFactor;
295
+ c.withBottomBorderFactor = nextWithBottomBorderFactor;
296
+
297
+ c.hoverLight = nextHoverLight;
298
+ c.hoverLightColor = nextHoverLightColor;
299
+ c.hoverLightFillRadius = nextHoverLightFillRadius;
300
+ c.hoverLightFillMode = nextHoverLightFillMode;
301
+
302
+ c.diffuse = nextDiffuse;
303
+ c.pressAnimation = nextPressAnimation;
304
+ c.pressAnimationFillMode = nextPressAnimationFillMode;
305
+ c.pressAnimationColor = nextPressAnimationColor;
306
+ c.pressAnimationSpeed = nextPressAnimationSpeed;
307
+ c.releaseAnimationAccelerateRate = nextReleaseAnimationAccelerateRate;
308
+
309
+ c.topLeftBorderDecorationRadius = nextTopLeftBorderDecorationRadius;
310
+ c.topRightBorderDecorationRadius = nextTopRightBorderDecorationRadius;
311
+ c.bottomLeftBorderDecorationRadius = nextBottomLeftBorderDecorationRadius;
312
+ c.bottomRightBorderDecorationRadius = nextBottomRightBorderDecorationRadius;
313
+
314
+ this.getTrueFillRadius(c.trueFillRadius, c.hoverLightFillMode);
315
+
316
+ if (!isValidateBorderDecorationType(c.borderDecorationType)) {
317
+ throw new SyntaxError(
318
+ 'The value of `--reveal-border-decoration-type` must be `round`, `bevel` or `miter`!'
319
+ );
320
+ }
321
+
322
+ this.cachedStyleFrameId = this.currentFrameId;
323
+ };
324
+
325
+ mouseInCanvas = () => {
326
+ const b = this.cachedBoundingRect;
327
+
328
+ const relativeX = this._store.clientX - b.left;
329
+ const relativeY = this._store.clientY - b.top;
330
+
331
+ return relativeX > 0 && relativeY > 0 && relativeX < b.width && relativeY < b.height;
332
+ };
311
333
  }