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