@ax-design/reveal-highlight 0.3.0-alpha.8 → 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/README.md +8 -167
- 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 +20 -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/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 +20 -4
- package/es/CustomElements.d.ts.map +1 -1
- package/es/CustomElements.js +115 -18
- 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 +43 -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/tsconfig.tsbuildinfo +1 -0
- 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 +35 -30
- package/src/BaseConfig.ts +311 -0
- package/src/CanvasConfig.ts +66 -380
- package/src/CustomElements.ts +137 -29
- package/src/RevealBoundryStore.ts +138 -39
- package/src/RevealStateManager.ts +48 -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/.prettierrc +0 -6
- package/.travis.yml +0 -26
- package/.yarnrc.yml +0 -1
- package/docs/demo/debug.html +0 -73
- package/docs/demo/index.html +0 -1065
- package/docs/demo/performance-inspector.html +0 -60
- package/docs/demo/shapes-demo.html +0 -93
- package/docs/demo/single-unit.html +0 -39
- package/docs/logo.png +0 -0
- package/docs/logo.svg +0 -1
- package/docs/screen-record.gif +0 -0
- package/docs/src/logo.afdesign +0 -0
- package/rollup.config.js +0 -14
- package/tsconfig.json +0 -18
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,133 +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
|
-
cacheCanvasPaintingStyle = () => {
|
|
296
|
-
if (this.currentFrameId === this.cachedStyleFrameId) {
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
if (this.computedStyle.size() === 0) {
|
|
301
|
-
return;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
const parsedBaseColor = extractRGBValue(this.computedStyle.getColor('--reveal-color')) || '0, 0, 0';
|
|
305
|
-
const parsedBorderColor =
|
|
306
|
-
extractRGBValue(this.computedStyle.getColor('--reveal-border-color')) || parsedBaseColor;
|
|
307
|
-
const parsedHoverLightColor =
|
|
308
|
-
extractRGBValue(this.computedStyle.getColor('--reveal-hover-light-color')) || parsedBaseColor;
|
|
309
|
-
const parsedPressAnimationColor =
|
|
310
|
-
extractRGBValue(this.computedStyle.getColor('--reveal-press-animation-color')) || parsedBaseColor;
|
|
311
|
-
|
|
312
|
-
const c = this.cachedStyle;
|
|
313
|
-
|
|
314
|
-
c.color = parsedBaseColor;
|
|
315
|
-
c.opacity = this.computedStyle.getNumber('--reveal-opacity');
|
|
316
|
-
|
|
317
|
-
// Border related configurations
|
|
318
|
-
c.borderStyle = this.computedStyle.get('--reveal-border-style');
|
|
319
|
-
c.borderColor = parsedBorderColor;
|
|
320
|
-
|
|
321
|
-
c.borderFillRadius = this.computedStyle.getNumber('--reveal-border-fill-radius');
|
|
322
|
-
c.borderDecorationType =
|
|
323
|
-
(this.computedStyle.get('--reveal-border-decoration-type') as BorderDecoration) || 'miter';
|
|
324
|
-
c.borderWidth = this.computedStyle.getNumber('--reveal-border-width');
|
|
325
|
-
|
|
326
|
-
c.withLeftBorderFactor =
|
|
327
|
-
this.getPropFromMultipleSource('leftBorder', '--reveal-border-left') === 'line' ? 1 : 0;
|
|
328
|
-
c.withRightBorderFactor =
|
|
329
|
-
this.getPropFromMultipleSource('rightBorder', '--reveal-border-right') === 'line' ? 1 : 0;
|
|
330
|
-
c.withTopBorderFactor = this.getPropFromMultipleSource('topBorder', '--reveal-border-top') === 'line' ? 1 : 0;
|
|
331
|
-
c.withBottomBorderFactor =
|
|
332
|
-
this.getPropFromMultipleSource('bottomBorder', '--reveal-border-bottom') === 'line' ? 1 : 0;
|
|
333
|
-
|
|
334
|
-
// Hover light related configurations
|
|
335
|
-
c.hoverLight = this.computedStyle.get('--reveal-hover-light') === 'true';
|
|
336
|
-
c.hoverLightColor = parsedHoverLightColor;
|
|
337
|
-
c.hoverLightFillRadius = this.computedStyle.getNumber('--reveal-hover-light-fill-radius');
|
|
338
|
-
c.hoverLightFillMode = this.computedStyle.get('--reveal-hover-light-fill-radius-mode');
|
|
339
|
-
|
|
340
|
-
// Press animation related configurations
|
|
341
|
-
c.diffuse = this.computedStyle.get('--reveal-diffuse') === 'true';
|
|
342
|
-
c.pressAnimation = this.computedStyle.get('--reveal-press-animation') === 'true';
|
|
343
|
-
c.pressAnimationFillMode = this.computedStyle.get('--reveal-press-animation-radius-mode');
|
|
344
|
-
c.pressAnimationColor = parsedPressAnimationColor;
|
|
345
|
-
c.pressAnimationSpeed = this.computedStyle.getNumber('--reveal-press-animation-speed');
|
|
346
|
-
c.releaseAnimationAccelerateRate = this.computedStyle.getNumber('--reveal-release-animation-accelerate-rate');
|
|
347
|
-
|
|
348
|
-
// Border decoration related configurations
|
|
349
|
-
const r = this.computedStyle.getNumber('--reveal-border-decoration-radius');
|
|
350
|
-
const tl = this.computedStyle.getNumber('--reveal-border-decoration-top-left-radius');
|
|
351
|
-
const tr = this.computedStyle.getNumber('--reveal-border-decoration-top-right-radius');
|
|
352
|
-
const bl = this.computedStyle.getNumber('--reveal-border-decoration-bottom-left-radius');
|
|
353
|
-
const br = this.computedStyle.getNumber('--reveal-border-decoration-bottom-right-radius');
|
|
354
|
-
|
|
355
|
-
c.topLeftBorderDecorationRadius = tl >= 0 ? tl : r;
|
|
356
|
-
c.topRightBorderDecorationRadius = tr >= 0 ? tr : r;
|
|
357
|
-
c.bottomLeftBorderDecorationRadius = bl >= 0 ? bl : r;
|
|
358
|
-
c.bottomRightBorderDecorationRadius = br >= 0 ? br : r;
|
|
359
|
-
|
|
360
|
-
this.getTrueFillRadius(c.trueFillRadius, c.hoverLightFillMode);
|
|
361
|
-
|
|
362
|
-
if (!isValidateBorderDecorationType(c.borderDecorationType)) {
|
|
363
|
-
throw new SyntaxError(
|
|
364
|
-
'The value of `--reveal-border-decoration-type` must be `round`, `bevel` or `miter`!'
|
|
365
|
-
);
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
this.cachedStyleFrameId = this.currentFrameId;
|
|
369
|
-
};
|
|
370
|
-
|
|
371
51
|
updateCachedReveal = () => {
|
|
52
|
+
if (!this.fillDirty) return;
|
|
53
|
+
|
|
372
54
|
const c = this.cachedStyle;
|
|
373
55
|
const radius = c.trueFillRadius[1] * this.pxRatio;
|
|
374
56
|
const size = radius * 2;
|
|
@@ -378,6 +60,8 @@ export class CanvasConfig {
|
|
|
378
60
|
const { borderReveal, fillReveal } = this.cachedImg.cachedCanvas;
|
|
379
61
|
const { borderReveal: borderRevealCtx, fillReveal: fillRevealCtx } = this.cachedImg.cachedCtx;
|
|
380
62
|
|
|
63
|
+
this._store.updateMaxRadius(c.trueFillRadius[1] * c.borderFillRadius);
|
|
64
|
+
|
|
381
65
|
for (let i = 0; i < 2; i++) {
|
|
382
66
|
// 0 means border, 1 means hover light.
|
|
383
67
|
//-----------------------------------------
|
|
@@ -388,7 +72,6 @@ export class CanvasConfig {
|
|
|
388
72
|
|
|
389
73
|
const doNotNeedUpdateReveal =
|
|
390
74
|
color === ls.color && c.opacity === ls.opacity && fillRadiusFactor === ls.radiusFactor;
|
|
391
|
-
if (doNotNeedUpdateReveal) return;
|
|
392
75
|
|
|
393
76
|
if (doNotNeedUpdateReveal) continue;
|
|
394
77
|
|
|
@@ -421,6 +104,8 @@ export class CanvasConfig {
|
|
|
421
104
|
if (!this.ctx) continue;
|
|
422
105
|
ls.pattern = this.ctx.createPattern(reveal, 'no-repeat');
|
|
423
106
|
}
|
|
107
|
+
|
|
108
|
+
this.fillDirty = false;
|
|
424
109
|
};
|
|
425
110
|
|
|
426
111
|
updateCachedBitmap = () => {
|
|
@@ -428,39 +113,7 @@ export class CanvasConfig {
|
|
|
428
113
|
this.updateCachedReveal();
|
|
429
114
|
};
|
|
430
115
|
|
|
431
|
-
|
|
432
|
-
const b = this.cachedBoundingRect;
|
|
433
|
-
|
|
434
|
-
const relativeX = this._store.clientX - b.left;
|
|
435
|
-
const relativeY = this._store.clientY - b.top;
|
|
436
|
-
|
|
437
|
-
return relativeX > 0 && relativeY > 0 && relativeX < b.width && relativeY < b.height;
|
|
438
|
-
};
|
|
439
|
-
|
|
440
|
-
syncSizeToElement = (x: HTMLCanvasElement) => {
|
|
441
|
-
const b = this.cachedBoundingRect;
|
|
442
|
-
|
|
443
|
-
if (x.width !== b.width || x.height !== b.height) {
|
|
444
|
-
x.width = b.width * this.pxRatio;
|
|
445
|
-
x.height = b.height * this.pxRatio;
|
|
446
|
-
x.style.width = `${b.width}px`;
|
|
447
|
-
x.style.height = `${b.height}px`;
|
|
448
|
-
}
|
|
449
|
-
};
|
|
450
|
-
|
|
451
|
-
syncSizeToRevealRadius = (x: HTMLCanvasElement, factor: number) => {
|
|
452
|
-
const { trueFillRadius } = this.cachedStyle;
|
|
453
|
-
|
|
454
|
-
const radius = trueFillRadius[1] || 1;
|
|
455
|
-
const size = radius * 2 * this.pxRatio * factor;
|
|
456
|
-
|
|
457
|
-
if (x.width !== size || x.height !== size) {
|
|
458
|
-
x.width = size;
|
|
459
|
-
x.height = size;
|
|
460
|
-
}
|
|
461
|
-
};
|
|
462
|
-
|
|
463
|
-
updateAnimateGrd = (frame: number, grd: CanvasGradient) => {
|
|
116
|
+
private updateAnimateGrd = (frame: number, grd: CanvasGradient) => {
|
|
464
117
|
const { pressAnimationColor, opacity } = this.cachedStyle;
|
|
465
118
|
|
|
466
119
|
const _innerAlpha = opacity * (0.2 - frame);
|
|
@@ -469,7 +122,9 @@ export class CanvasConfig {
|
|
|
469
122
|
|
|
470
123
|
const innerAlpha = _innerAlpha < 0 ? 0 : _innerAlpha;
|
|
471
124
|
const outerAlpha = _outerAlpha < 0 ? 0 : _outerAlpha;
|
|
472
|
-
|
|
125
|
+
let outerBorder = 0;
|
|
126
|
+
outerBorder = _outerBorder > 1 ? 1 : _outerBorder;
|
|
127
|
+
outerBorder = _outerBorder < 0 ? 0 : _outerBorder;
|
|
473
128
|
|
|
474
129
|
grd.addColorStop(0, `rgba(${pressAnimationColor},${innerAlpha})`);
|
|
475
130
|
grd.addColorStop(outerBorder * 0.55, `rgba(${pressAnimationColor},${outerAlpha})`);
|
|
@@ -536,7 +191,7 @@ export class CanvasConfig {
|
|
|
536
191
|
this.ctx.lineTo(w - bw * wrf, bw * wtf + tr2); // ⑦
|
|
537
192
|
this.ctx.arcTo(w - bw * wrf, bw * wtf, w - bw * wrf - tr2, bw * wtf, tr2); // ⑧
|
|
538
193
|
this.ctx.lineTo(tl2, bw * wtf); // ①
|
|
539
|
-
/* prettier-ignore-
|
|
194
|
+
/* prettier-ignore-end */
|
|
540
195
|
}
|
|
541
196
|
break;
|
|
542
197
|
case 'bevel':
|
|
@@ -604,22 +259,53 @@ export class CanvasConfig {
|
|
|
604
259
|
this.ctx.closePath();
|
|
605
260
|
};
|
|
606
261
|
|
|
607
|
-
|
|
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 => {
|
|
608
291
|
const store = this._store;
|
|
609
292
|
|
|
610
293
|
const animationPlaying = store.animationQueue.includes(this);
|
|
611
294
|
const samePosition = store.clientX === store.paintedClientX && store.clientY === store.paintedClientY;
|
|
612
295
|
|
|
613
|
-
if (samePosition && !
|
|
296
|
+
if (samePosition && !skipSamePointerPositionCheck && !animationPlaying) {
|
|
614
297
|
return false;
|
|
615
298
|
}
|
|
616
299
|
|
|
617
300
|
if (!this.ctx) return false;
|
|
618
301
|
|
|
302
|
+
this.dirty = true;
|
|
619
303
|
this.ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
620
|
-
this.ctx.clearRect(
|
|
621
|
-
|
|
622
|
-
|
|
304
|
+
this.ctx.clearRect(
|
|
305
|
+
0, 0,
|
|
306
|
+
this.paintedWidth,
|
|
307
|
+
this.paintedHeight
|
|
308
|
+
);
|
|
623
309
|
|
|
624
310
|
if (!store.mouseInBoundary && !animationPlaying) {
|
|
625
311
|
return false;
|
|
@@ -629,7 +315,7 @@ export class CanvasConfig {
|
|
|
629
315
|
return false;
|
|
630
316
|
}
|
|
631
317
|
|
|
632
|
-
this.syncSizeToElement(this.
|
|
318
|
+
this.syncSizeToElement(this.element);
|
|
633
319
|
this.cacheBoundingRect();
|
|
634
320
|
|
|
635
321
|
const b = this.cachedBoundingRect;
|
|
@@ -702,21 +388,21 @@ export class CanvasConfig {
|
|
|
702
388
|
const animateGrd =
|
|
703
389
|
this.mouseReleased && this.mouseUpClientX && this.mouseUpClientY
|
|
704
390
|
? this.ctx.createRadialGradient(
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
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
|
+
)
|
|
712
398
|
: this.ctx.createRadialGradient(
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
399
|
+
relativeX * this.pxRatio,
|
|
400
|
+
relativeY * this.pxRatio,
|
|
401
|
+
0,
|
|
402
|
+
relativeX * this.pxRatio,
|
|
403
|
+
relativeY * this.pxRatio,
|
|
404
|
+
grdRadius * this.pxRatio
|
|
405
|
+
);
|
|
720
406
|
this.updateAnimateGrd(this.mouseDownAnimateLogicFrame, animateGrd);
|
|
721
407
|
|
|
722
408
|
this.drawShape(false);
|