@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
package/src/CanvasConfig.ts
CHANGED
|
@@ -1,211 +1,19 @@
|
|
|
1
|
-
import { ComputedStyleStorage, createStorage } from './ComputedStyleStorage.js';
|
|
2
1
|
import { RevealBoundaryStore } from './RevealBoundryStore.js';
|
|
3
|
-
import { MAGIC_DEFAULT_COLOR } from './variables.js';
|
|
4
|
-
|
|
5
|
-
type BorderDecoration = 'round' | 'bevel' | 'miter';
|
|
6
|
-
|
|
7
|
-
const isValidateBorderDecorationType = (x: string): x is BorderDecoration => {
|
|
8
|
-
if (x === 'round') return true;
|
|
9
|
-
if (x === 'bevel') return true;
|
|
10
|
-
if (x === 'miter') return true;
|
|
11
|
-
return false;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const extractRGBValue = (x: string) => {
|
|
15
|
-
if (x[0] === '#') {
|
|
16
|
-
// Thanks bro:
|
|
17
|
-
// https://stackoverflow.com/a/11508164/3931936
|
|
18
|
-
const hexVal = parseInt(x.substring(1), 16);
|
|
19
|
-
|
|
20
|
-
var r = (hexVal >> 16) & 255;
|
|
21
|
-
var g = (hexVal >> 8) & 255;
|
|
22
|
-
var b = hexVal & 255;
|
|
23
|
-
|
|
24
|
-
return r + ',' + g + ',' + b;
|
|
25
|
-
} else {
|
|
26
|
-
let result = '';
|
|
27
|
-
let beginSearch = false;
|
|
28
|
-
let numberPointer = 0;
|
|
29
|
-
|
|
30
|
-
for (let i = 0; i < x.length; i++) {
|
|
31
|
-
const char = x[i];
|
|
32
|
-
const charCode = char.charCodeAt(0) - 48;
|
|
33
|
-
const charIsNumber = charCode >= 0 && charCode < 10;
|
|
34
|
-
|
|
35
|
-
if (char === ' ') {
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (beginSearch && !charIsNumber && char !== ',' && char !== ')') {
|
|
40
|
-
throw new SyntaxError(`${x} is not a validate color value!`);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (!beginSearch && char === '(') {
|
|
44
|
-
beginSearch = true;
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
2
|
|
|
48
|
-
|
|
49
|
-
throw new SyntaxError(`${x} should have at least three color channel`);
|
|
50
|
-
}
|
|
3
|
+
import type { CachedRevealBitmap } from './utils/types.js';
|
|
51
4
|
|
|
52
|
-
|
|
53
|
-
numberPointer++;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (char === ')') {
|
|
57
|
-
return result;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (beginSearch) {
|
|
61
|
-
result += char;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return result;
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export interface CachedBoundingRect {
|
|
70
|
-
top: number;
|
|
71
|
-
left: number;
|
|
72
|
-
width: number;
|
|
73
|
-
height: number;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export interface CachedStyle {
|
|
77
|
-
color: string;
|
|
78
|
-
opacity: number;
|
|
79
|
-
trueFillRadius: [number, number];
|
|
80
|
-
borderStyle: string;
|
|
81
|
-
borderColor: string;
|
|
82
|
-
borderFillRadius: number;
|
|
83
|
-
borderDecorationType: BorderDecoration;
|
|
84
|
-
borderDecorationRadius: number;
|
|
85
|
-
topLeftBorderDecorationRadius: number;
|
|
86
|
-
topRightBorderDecorationRadius: number;
|
|
87
|
-
bottomLeftBorderDecorationRadius: number;
|
|
88
|
-
bottomRightBorderDecorationRadius: number;
|
|
89
|
-
withLeftBorderFactor: number;
|
|
90
|
-
withRightBorderFactor: number;
|
|
91
|
-
withTopBorderFactor: number;
|
|
92
|
-
withBottomBorderFactor: number;
|
|
93
|
-
borderWidth: number;
|
|
94
|
-
hoverLight: boolean;
|
|
95
|
-
hoverLightColor: string;
|
|
96
|
-
hoverLightFillMode: string;
|
|
97
|
-
hoverLightFillRadius: number;
|
|
98
|
-
diffuse: boolean;
|
|
99
|
-
pressAnimation: boolean;
|
|
100
|
-
pressAnimationFillMode: string;
|
|
101
|
-
pressAnimationColor: string;
|
|
102
|
-
pressAnimationSpeed: number;
|
|
103
|
-
releaseAnimationAccelerateRate: number;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
interface CachedReveal {
|
|
107
|
-
radius: number;
|
|
108
|
-
radiusFactor: number;
|
|
109
|
-
color: string;
|
|
110
|
-
opacity: number;
|
|
111
|
-
pattern: CanvasPattern | null;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Cached border and body pattern, for faster painting on the canvas.
|
|
116
|
-
* @interface CachedRevealBitmap
|
|
117
|
-
*/
|
|
118
|
-
export interface CachedRevealBitmap {
|
|
119
|
-
cachedReveal: {
|
|
120
|
-
borderReveal: CachedReveal;
|
|
121
|
-
fillReveal: CachedReveal;
|
|
122
|
-
};
|
|
123
|
-
cachedCanvas: {
|
|
124
|
-
borderReveal: HTMLCanvasElement;
|
|
125
|
-
fillReveal: HTMLCanvasElement;
|
|
126
|
-
};
|
|
127
|
-
cachedCtx: {
|
|
128
|
-
borderReveal: CanvasRenderingContext2D | null;
|
|
129
|
-
fillReveal: CanvasRenderingContext2D | null;
|
|
130
|
-
};
|
|
131
|
-
}
|
|
5
|
+
import { BaseConfig } from './BaseConfig.js';
|
|
132
6
|
|
|
133
7
|
const createEmptyCanvas = () => document.createElement('canvas') as HTMLCanvasElement;
|
|
134
8
|
|
|
135
|
-
export class CanvasConfig {
|
|
136
|
-
protected _store: RevealBoundaryStore;
|
|
137
|
-
|
|
138
|
-
pxRatio = window.devicePixelRatio || 1;
|
|
139
|
-
|
|
140
|
-
readonly container: HTMLElement;
|
|
141
|
-
readonly canvas: HTMLCanvasElement;
|
|
9
|
+
export class CanvasConfig extends BaseConfig<HTMLCanvasElement> {
|
|
142
10
|
ctx: CanvasRenderingContext2D | null;
|
|
143
11
|
|
|
144
|
-
private readonly computedStyle: ComputedStyleStorage;
|
|
145
|
-
|
|
146
|
-
paintedWidth = 0;
|
|
147
|
-
paintedHeight = 0;
|
|
148
|
-
|
|
149
12
|
protected cachedImg: CachedRevealBitmap;
|
|
150
13
|
|
|
151
|
-
currentFrameId: number = -1;
|
|
152
|
-
|
|
153
|
-
cachedBoundingRectFrameId: number = -2;
|
|
154
|
-
|
|
155
|
-
cachedBoundingRect: CachedBoundingRect = {
|
|
156
|
-
top: -1,
|
|
157
|
-
left: -1,
|
|
158
|
-
width: -1,
|
|
159
|
-
height: -1,
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
cachedStyleFrameId: number = -2;
|
|
163
|
-
|
|
164
|
-
cachedStyle: CachedStyle = {
|
|
165
|
-
trueFillRadius: [0, 0],
|
|
166
|
-
color: '',
|
|
167
|
-
opacity: 1,
|
|
168
|
-
borderStyle: '',
|
|
169
|
-
borderColor: '',
|
|
170
|
-
borderFillRadius: 0,
|
|
171
|
-
borderDecorationType: 'miter',
|
|
172
|
-
borderDecorationRadius: 0,
|
|
173
|
-
topLeftBorderDecorationRadius: 0,
|
|
174
|
-
topRightBorderDecorationRadius: 0,
|
|
175
|
-
bottomLeftBorderDecorationRadius: 0,
|
|
176
|
-
bottomRightBorderDecorationRadius: 0,
|
|
177
|
-
withLeftBorderFactor: 1,
|
|
178
|
-
withRightBorderFactor: 1,
|
|
179
|
-
withTopBorderFactor: 1,
|
|
180
|
-
withBottomBorderFactor: 1,
|
|
181
|
-
borderWidth: 1,
|
|
182
|
-
hoverLight: true,
|
|
183
|
-
hoverLightColor: '',
|
|
184
|
-
hoverLightFillMode: '',
|
|
185
|
-
hoverLightFillRadius: 0,
|
|
186
|
-
diffuse: true,
|
|
187
|
-
pressAnimation: true,
|
|
188
|
-
pressAnimationFillMode: '',
|
|
189
|
-
pressAnimationColor: '',
|
|
190
|
-
pressAnimationSpeed: 0,
|
|
191
|
-
releaseAnimationAccelerateRate: 0,
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
mouseUpClientX: number | null = null;
|
|
195
|
-
mouseUpClientY: number | null = null;
|
|
196
|
-
mouseDownAnimateStartFrame: number | null = null;
|
|
197
|
-
mouseDownAnimateCurrentFrame: number | null = null;
|
|
198
|
-
mouseDownAnimateReleasedFrame: number | null = null;
|
|
199
|
-
mouseDownAnimateLogicFrame: number | null = null;
|
|
200
|
-
mousePressed = false;
|
|
201
|
-
|
|
202
|
-
mouseReleased = false;
|
|
203
|
-
|
|
204
14
|
constructor(store: RevealBoundaryStore, $canvas: HTMLCanvasElement, $container: HTMLElement) {
|
|
205
|
-
|
|
15
|
+
super(store, $canvas, $container);
|
|
206
16
|
|
|
207
|
-
this.container = $container;
|
|
208
|
-
this.canvas = $canvas;
|
|
209
17
|
this.ctx = $canvas.getContext('2d');
|
|
210
18
|
|
|
211
19
|
const cachedCanvas = {
|
|
@@ -213,9 +21,6 @@ export class CanvasConfig {
|
|
|
213
21
|
fillReveal: createEmptyCanvas(),
|
|
214
22
|
};
|
|
215
23
|
|
|
216
|
-
document.body.appendChild(cachedCanvas.borderReveal);
|
|
217
|
-
document.body.appendChild(cachedCanvas.fillReveal);
|
|
218
|
-
|
|
219
24
|
const cachedCtx = {
|
|
220
25
|
borderReveal: cachedCanvas.borderReveal.getContext('2d'),
|
|
221
26
|
fillReveal: cachedCanvas.fillReveal.getContext('2d'),
|
|
@@ -241,131 +46,11 @@ export class CanvasConfig {
|
|
|
241
46
|
cachedCanvas,
|
|
242
47
|
cachedCtx,
|
|
243
48
|
};
|
|
244
|
-
|
|
245
|
-
this.computedStyle = createStorage($container);
|
|
246
49
|
}
|
|
247
50
|
|
|
248
|
-
cacheBoundingRect = () => {
|
|
249
|
-
if (this.currentFrameId === this.cachedBoundingRectFrameId) {
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
const boundingRect = this.canvas.getBoundingClientRect();
|
|
254
|
-
|
|
255
|
-
this.cachedBoundingRect.top = Math.floor(boundingRect.top);
|
|
256
|
-
this.cachedBoundingRect.left = Math.floor(boundingRect.left);
|
|
257
|
-
this.cachedBoundingRect.width = Math.floor(boundingRect.width);
|
|
258
|
-
this.cachedBoundingRect.height = Math.floor(boundingRect.height);
|
|
259
|
-
|
|
260
|
-
this.cachedBoundingRectFrameId = this.currentFrameId;
|
|
261
|
-
};
|
|
262
|
-
|
|
263
|
-
getTrueFillRadius = (
|
|
264
|
-
trueFillRadius = [0, 0] as [number, number],
|
|
265
|
-
fillMode = this.computedStyle.get('--reveal-hover-light-fill-radius-mode')
|
|
266
|
-
) => {
|
|
267
|
-
const b = this.cachedBoundingRect;
|
|
268
|
-
|
|
269
|
-
switch (fillMode) {
|
|
270
|
-
case 'relative':
|
|
271
|
-
trueFillRadius[0] = Math.min(b.width, b.height);
|
|
272
|
-
trueFillRadius[1] = Math.max(b.width, b.height);
|
|
273
|
-
break;
|
|
274
|
-
case 'absolute':
|
|
275
|
-
trueFillRadius[0] = -1;
|
|
276
|
-
trueFillRadius[1] = -1;
|
|
277
|
-
break;
|
|
278
|
-
default:
|
|
279
|
-
throw new SyntaxError('The value of `--reveal-border-style` must be `relative`, `absolute`!');
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
this._store.updateMaxRadius(Math.max(trueFillRadius[0], trueFillRadius[1]));
|
|
283
|
-
|
|
284
|
-
return trueFillRadius;
|
|
285
|
-
};
|
|
286
|
-
|
|
287
|
-
getPropFromMultipleSource = (domPropsName: string, cssPropsName: string) => {
|
|
288
|
-
const domProps = this.container.dataset[domPropsName];
|
|
289
|
-
if (domProps) return domProps;
|
|
290
|
-
|
|
291
|
-
return this.computedStyle.get(cssPropsName);
|
|
292
|
-
};
|
|
293
|
-
|
|
294
|
-
cacheCanvasPaintingStyle = () => {
|
|
295
|
-
if (this.currentFrameId === this.cachedStyleFrameId) {
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
if (this.computedStyle.size() === 0) {
|
|
300
|
-
return;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
const parsedBaseColor = extractRGBValue(this.computedStyle.getColor('--reveal-color')) || '0, 0, 0';
|
|
304
|
-
const parsedBorderColor = extractRGBValue(this.computedStyle.getColor('--reveal-border-color'));
|
|
305
|
-
const parsedHoverLightColor = extractRGBValue(this.computedStyle.getColor('--reveal-hover-light-color'));
|
|
306
|
-
const parsedPressAnimationColor = extractRGBValue(
|
|
307
|
-
this.computedStyle.getColor('--reveal-press-animation-color')
|
|
308
|
-
);
|
|
309
|
-
|
|
310
|
-
const c = this.cachedStyle;
|
|
311
|
-
|
|
312
|
-
c.color = parsedBaseColor;
|
|
313
|
-
c.opacity = this.computedStyle.getNumber('--reveal-opacity');
|
|
314
|
-
|
|
315
|
-
// Border related configurations
|
|
316
|
-
c.borderStyle = this.computedStyle.get('--reveal-border-style');
|
|
317
|
-
c.borderColor = parsedBorderColor !== MAGIC_DEFAULT_COLOR ? parsedBorderColor : parsedBaseColor;
|
|
318
|
-
c.borderFillRadius = this.computedStyle.getNumber('--reveal-border-fill-radius');
|
|
319
|
-
c.borderDecorationType =
|
|
320
|
-
(this.computedStyle.get('--reveal-border-decoration-type') as BorderDecoration) || 'miter';
|
|
321
|
-
c.borderWidth = this.computedStyle.getNumber('--reveal-border-width');
|
|
322
|
-
|
|
323
|
-
c.withLeftBorderFactor = this.getPropFromMultipleSource('leftBorder', '--reveal-border-left') === 'line' ? 1 : 0;
|
|
324
|
-
c.withRightBorderFactor =
|
|
325
|
-
this.getPropFromMultipleSource('rightBorder', '--reveal-border-right') === 'line' ? 1 : 0;
|
|
326
|
-
c.withTopBorderFactor = this.getPropFromMultipleSource('topBorder', '--reveal-border-top') === 'line' ? 1 : 0;
|
|
327
|
-
c.withBottomBorderFactor =
|
|
328
|
-
this.getPropFromMultipleSource('bottomBorder', '--reveal-border-bottom') === 'line' ? 1 : 0;
|
|
329
|
-
|
|
330
|
-
// Hover light related configurations
|
|
331
|
-
c.hoverLight = this.computedStyle.get('--reveal-hover-light') === 'true';
|
|
332
|
-
c.hoverLightColor = parsedHoverLightColor !== MAGIC_DEFAULT_COLOR ? parsedHoverLightColor : parsedBaseColor;
|
|
333
|
-
c.hoverLightFillRadius = this.computedStyle.getNumber('--reveal-hover-light-fill-radius');
|
|
334
|
-
c.hoverLightFillMode = this.computedStyle.get('--reveal-hover-light-fill-radius-mode');
|
|
335
|
-
|
|
336
|
-
// Press animation related configurations
|
|
337
|
-
c.diffuse = this.computedStyle.get('--reveal-diffuse') === 'true';
|
|
338
|
-
c.pressAnimation = this.computedStyle.get('--reveal-press-animation') === 'true';
|
|
339
|
-
c.pressAnimationFillMode = this.computedStyle.get('--reveal-press-animation-radius-mode');
|
|
340
|
-
c.pressAnimationColor =
|
|
341
|
-
parsedPressAnimationColor !== MAGIC_DEFAULT_COLOR ? parsedPressAnimationColor : parsedBaseColor;
|
|
342
|
-
c.pressAnimationSpeed = this.computedStyle.getNumber('--reveal-press-animation-speed');
|
|
343
|
-
c.releaseAnimationAccelerateRate = this.computedStyle.getNumber('--reveal-release-animation-accelerate-rate');
|
|
344
|
-
|
|
345
|
-
// Border decoration related configurations
|
|
346
|
-
const r = this.computedStyle.getNumber('--reveal-border-decoration-radius');
|
|
347
|
-
const tl = this.computedStyle.getNumber('--reveal-border-decoration-top-left-radius');
|
|
348
|
-
const tr = this.computedStyle.getNumber('--reveal-border-decoration-top-right-radius');
|
|
349
|
-
const bl = this.computedStyle.getNumber('--reveal-border-decoration-bottom-left-radius');
|
|
350
|
-
const br = this.computedStyle.getNumber('--reveal-border-decoration-bottom-right-radius');
|
|
351
|
-
|
|
352
|
-
c.topLeftBorderDecorationRadius = tl >= 0 ? tl : r;
|
|
353
|
-
c.topRightBorderDecorationRadius = tr >= 0 ? tr : r;
|
|
354
|
-
c.bottomLeftBorderDecorationRadius = bl >= 0 ? bl : r;
|
|
355
|
-
c.bottomRightBorderDecorationRadius = br >= 0 ? br : r;
|
|
356
|
-
|
|
357
|
-
this.getTrueFillRadius(c.trueFillRadius, c.hoverLightFillMode);
|
|
358
|
-
|
|
359
|
-
if (!isValidateBorderDecorationType(c.borderDecorationType)) {
|
|
360
|
-
throw new SyntaxError(
|
|
361
|
-
'The value of `--reveal-border-decoration-type` must be `round`, `bevel` or `miter`!'
|
|
362
|
-
);
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
this.cachedStyleFrameId = this.currentFrameId;
|
|
366
|
-
};
|
|
367
|
-
|
|
368
51
|
updateCachedReveal = () => {
|
|
52
|
+
if (!this.fillDirty) return;
|
|
53
|
+
|
|
369
54
|
const c = this.cachedStyle;
|
|
370
55
|
const radius = c.trueFillRadius[1] * this.pxRatio;
|
|
371
56
|
const size = radius * 2;
|
|
@@ -375,6 +60,8 @@ export class CanvasConfig {
|
|
|
375
60
|
const { borderReveal, fillReveal } = this.cachedImg.cachedCanvas;
|
|
376
61
|
const { borderReveal: borderRevealCtx, fillReveal: fillRevealCtx } = this.cachedImg.cachedCtx;
|
|
377
62
|
|
|
63
|
+
this._store.updateMaxRadius(c.trueFillRadius[1] * c.borderFillRadius);
|
|
64
|
+
|
|
378
65
|
for (let i = 0; i < 2; i++) {
|
|
379
66
|
// 0 means border, 1 means hover light.
|
|
380
67
|
//-----------------------------------------
|
|
@@ -385,7 +72,6 @@ export class CanvasConfig {
|
|
|
385
72
|
|
|
386
73
|
const doNotNeedUpdateReveal =
|
|
387
74
|
color === ls.color && c.opacity === ls.opacity && fillRadiusFactor === ls.radiusFactor;
|
|
388
|
-
if (doNotNeedUpdateReveal) return;
|
|
389
75
|
|
|
390
76
|
if (doNotNeedUpdateReveal) continue;
|
|
391
77
|
|
|
@@ -418,6 +104,8 @@ export class CanvasConfig {
|
|
|
418
104
|
if (!this.ctx) continue;
|
|
419
105
|
ls.pattern = this.ctx.createPattern(reveal, 'no-repeat');
|
|
420
106
|
}
|
|
107
|
+
|
|
108
|
+
this.fillDirty = false;
|
|
421
109
|
};
|
|
422
110
|
|
|
423
111
|
updateCachedBitmap = () => {
|
|
@@ -425,39 +113,7 @@ export class CanvasConfig {
|
|
|
425
113
|
this.updateCachedReveal();
|
|
426
114
|
};
|
|
427
115
|
|
|
428
|
-
|
|
429
|
-
const b = this.cachedBoundingRect;
|
|
430
|
-
|
|
431
|
-
const relativeX = this._store.clientX - b.left;
|
|
432
|
-
const relativeY = this._store.clientY - b.top;
|
|
433
|
-
|
|
434
|
-
return relativeX > 0 && relativeY > 0 && relativeX < b.width && relativeY < b.height;
|
|
435
|
-
};
|
|
436
|
-
|
|
437
|
-
syncSizeToElement = (x: HTMLCanvasElement) => {
|
|
438
|
-
const b = this.cachedBoundingRect;
|
|
439
|
-
|
|
440
|
-
if (x.width !== b.width || x.height !== b.height) {
|
|
441
|
-
x.width = b.width * this.pxRatio;
|
|
442
|
-
x.height = b.height * this.pxRatio;
|
|
443
|
-
x.style.width = `${b.width}px`;
|
|
444
|
-
x.style.height = `${b.height}px`;
|
|
445
|
-
}
|
|
446
|
-
};
|
|
447
|
-
|
|
448
|
-
syncSizeToRevealRadius = (x: HTMLCanvasElement, factor: number) => {
|
|
449
|
-
const { trueFillRadius } = this.cachedStyle;
|
|
450
|
-
|
|
451
|
-
const radius = trueFillRadius[1] || 1;
|
|
452
|
-
const size = radius * 2 * this.pxRatio * factor;
|
|
453
|
-
|
|
454
|
-
if (x.width !== size || x.height !== size) {
|
|
455
|
-
x.width = size;
|
|
456
|
-
x.height = size;
|
|
457
|
-
}
|
|
458
|
-
};
|
|
459
|
-
|
|
460
|
-
updateAnimateGrd = (frame: number, grd: CanvasGradient) => {
|
|
116
|
+
private updateAnimateGrd = (frame: number, grd: CanvasGradient) => {
|
|
461
117
|
const { pressAnimationColor, opacity } = this.cachedStyle;
|
|
462
118
|
|
|
463
119
|
const _innerAlpha = opacity * (0.2 - frame);
|
|
@@ -466,7 +122,9 @@ export class CanvasConfig {
|
|
|
466
122
|
|
|
467
123
|
const innerAlpha = _innerAlpha < 0 ? 0 : _innerAlpha;
|
|
468
124
|
const outerAlpha = _outerAlpha < 0 ? 0 : _outerAlpha;
|
|
469
|
-
|
|
125
|
+
let outerBorder = 0;
|
|
126
|
+
outerBorder = _outerBorder > 1 ? 1 : _outerBorder;
|
|
127
|
+
outerBorder = _outerBorder < 0 ? 0 : _outerBorder;
|
|
470
128
|
|
|
471
129
|
grd.addColorStop(0, `rgba(${pressAnimationColor},${innerAlpha})`);
|
|
472
130
|
grd.addColorStop(outerBorder * 0.55, `rgba(${pressAnimationColor},${outerAlpha})`);
|
|
@@ -533,7 +191,7 @@ export class CanvasConfig {
|
|
|
533
191
|
this.ctx.lineTo(w - bw * wrf, bw * wtf + tr2); // ⑦
|
|
534
192
|
this.ctx.arcTo(w - bw * wrf, bw * wtf, w - bw * wrf - tr2, bw * wtf, tr2); // ⑧
|
|
535
193
|
this.ctx.lineTo(tl2, bw * wtf); // ①
|
|
536
|
-
/* prettier-ignore-
|
|
194
|
+
/* prettier-ignore-end */
|
|
537
195
|
}
|
|
538
196
|
break;
|
|
539
197
|
case 'bevel':
|
|
@@ -601,22 +259,53 @@ export class CanvasConfig {
|
|
|
601
259
|
this.ctx.closePath();
|
|
602
260
|
};
|
|
603
261
|
|
|
604
|
-
|
|
262
|
+
syncSizeToElement = (x: HTMLCanvasElement) => {
|
|
263
|
+
const b = this.cachedBoundingRect;
|
|
264
|
+
|
|
265
|
+
if (x.width !== b.width || x.height !== b.height) {
|
|
266
|
+
x.width = b.width * this.pxRatio;
|
|
267
|
+
x.height = b.height * this.pxRatio;
|
|
268
|
+
x.style.width = `${b.width}px`;
|
|
269
|
+
x.style.height = `${b.height}px`;
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
clear = () => {
|
|
274
|
+
if (!this.ctx) return false;
|
|
275
|
+
if (!this.dirty) return false;
|
|
276
|
+
|
|
277
|
+
const { width, height } = this.cachedBoundingRect;
|
|
278
|
+
|
|
279
|
+
this.ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
280
|
+
this.ctx.clearRect(
|
|
281
|
+
0,
|
|
282
|
+
0,
|
|
283
|
+
width * window.devicePixelRatio,
|
|
284
|
+
height * window.devicePixelRatio,
|
|
285
|
+
);
|
|
286
|
+
this.dirty = false;
|
|
287
|
+
return true;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
paint = (skipSamePointerPositionCheck?: boolean): boolean => {
|
|
605
291
|
const store = this._store;
|
|
606
292
|
|
|
607
293
|
const animationPlaying = store.animationQueue.includes(this);
|
|
608
294
|
const samePosition = store.clientX === store.paintedClientX && store.clientY === store.paintedClientY;
|
|
609
295
|
|
|
610
|
-
if (samePosition && !
|
|
296
|
+
if (samePosition && !skipSamePointerPositionCheck && !animationPlaying) {
|
|
611
297
|
return false;
|
|
612
298
|
}
|
|
613
299
|
|
|
614
300
|
if (!this.ctx) return false;
|
|
615
301
|
|
|
302
|
+
this.dirty = true;
|
|
616
303
|
this.ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
617
|
-
this.ctx.clearRect(
|
|
618
|
-
|
|
619
|
-
|
|
304
|
+
this.ctx.clearRect(
|
|
305
|
+
0, 0,
|
|
306
|
+
this.paintedWidth,
|
|
307
|
+
this.paintedHeight
|
|
308
|
+
);
|
|
620
309
|
|
|
621
310
|
if (!store.mouseInBoundary && !animationPlaying) {
|
|
622
311
|
return false;
|
|
@@ -626,7 +315,7 @@ export class CanvasConfig {
|
|
|
626
315
|
return false;
|
|
627
316
|
}
|
|
628
317
|
|
|
629
|
-
this.syncSizeToElement(this.
|
|
318
|
+
this.syncSizeToElement(this.element);
|
|
630
319
|
this.cacheBoundingRect();
|
|
631
320
|
|
|
632
321
|
const b = this.cachedBoundingRect;
|
|
@@ -699,21 +388,21 @@ export class CanvasConfig {
|
|
|
699
388
|
const animateGrd =
|
|
700
389
|
this.mouseReleased && this.mouseUpClientX && this.mouseUpClientY
|
|
701
390
|
? this.ctx.createRadialGradient(
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
391
|
+
(this.mouseUpClientX - b.left) * this.pxRatio,
|
|
392
|
+
(this.mouseUpClientY - b.top) * this.pxRatio,
|
|
393
|
+
0,
|
|
394
|
+
(this.mouseUpClientX - b.left) * this.pxRatio,
|
|
395
|
+
(this.mouseUpClientY - b.top) * this.pxRatio,
|
|
396
|
+
grdRadius * this.pxRatio
|
|
397
|
+
)
|
|
709
398
|
: this.ctx.createRadialGradient(
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
399
|
+
relativeX * this.pxRatio,
|
|
400
|
+
relativeY * this.pxRatio,
|
|
401
|
+
0,
|
|
402
|
+
relativeX * this.pxRatio,
|
|
403
|
+
relativeY * this.pxRatio,
|
|
404
|
+
grdRadius * this.pxRatio
|
|
405
|
+
);
|
|
717
406
|
this.updateAnimateGrd(this.mouseDownAnimateLogicFrame, animateGrd);
|
|
718
407
|
|
|
719
408
|
this.drawShape(false);
|