@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/es/SvgConfig.js CHANGED
@@ -1,346 +1,346 @@
1
- import { BaseConfig } from './BaseConfig.js';
2
- export class SvgConfig extends BaseConfig {
3
- constructor(store, $svg, $container) {
4
- super(store, $svg, $container);
5
- this.updateCachedBitmap = () => {
6
- };
7
- this.updateCachedReveal = () => {
8
- const c = this.cachedStyle;
9
- const stops = this.cachedImg.cachedGradientStop;
10
- stops.borderReveal[0].style.stopColor = c.borderColor;
11
- stops.borderReveal[1].style.stopColor = c.borderColor;
12
- stops.borderReveal[0].style.stopOpacity = c.opacity.toString();
13
- stops.borderReveal[1].style.stopOpacity = '0';
14
- stops.fillReveal[0].style.stopColor = c.hoverLightColor;
15
- stops.fillReveal[1].style.stopColor = c.hoverLightColor;
16
- stops.fillReveal[0].style.stopOpacity = (c.opacity * 0.5).toString();
17
- stops.fillReveal[1].style.stopOpacity = '0';
18
- stops.rippleReveal[0].style.stopColor = c.pressAnimationColor;
19
- stops.rippleReveal[1].style.stopColor = c.pressAnimationColor;
20
- stops.rippleReveal[2].style.stopColor = c.pressAnimationColor;
21
- const grads = this.cachedImg.cachedGradient;
22
- const isAbsoluteFill = c.trueFillRadius[0] === -1;
23
- grads.borderReveal.r.baseVal.value = isAbsoluteFill
24
- ? c.borderFillRadius
25
- : c.borderFillRadius * c.trueFillRadius[1];
26
- grads.fillReveal.r.baseVal.value = isAbsoluteFill
27
- ? c.hoverLightFillRadius
28
- : c.hoverLightFillRadius * c.trueFillRadius[0];
29
- this.fillDirty = false;
30
- };
31
- this.updateAnimateGrd = (frame, x, y, radius) => {
32
- const { opacity } = this.cachedStyle;
33
- const _innerAlpha = opacity * (0.2 - frame);
34
- const _outerAlpha = opacity * (0.1 - frame * 0.07);
35
- const _outerBorder = 0.1 + frame * 0.8;
36
- const innerAlpha = _innerAlpha < 0 ? 0 : _innerAlpha;
37
- const outerAlpha = _outerAlpha < 0 ? 0 : _outerAlpha;
38
- let outerBorder = 0;
39
- outerBorder = _outerBorder > 1 ? 1 : _outerBorder;
40
- outerBorder = _outerBorder < 0 ? 0 : _outerBorder;
41
- const stops = this.cachedImg.cachedGradientStop;
42
- stops.rippleReveal[0].style.stopOpacity = innerAlpha.toString();
43
- stops.rippleReveal[1].style.stopOpacity = outerAlpha.toString();
44
- stops.rippleReveal[2].style.stopOpacity = '0';
45
- stops.rippleReveal[0].offset.baseVal = 0;
46
- stops.rippleReveal[1].offset.baseVal = outerBorder * 0.55;
47
- stops.rippleReveal[2].offset.baseVal = outerBorder;
48
- const grads = this.cachedImg.cachedGradient;
49
- grads.rippleReveal.r.baseVal.value = radius;
50
- grads.rippleReveal.cx.baseVal.value = x;
51
- grads.rippleReveal.cy.baseVal.value = y;
52
- };
53
- this.updateGradientPosition = (x, y) => {
54
- const grads = this.cachedImg.cachedGradient;
55
- grads.borderReveal.cx.baseVal.value = x;
56
- grads.borderReveal.cy.baseVal.value = y;
57
- grads.fillReveal.cx.baseVal.value = x;
58
- grads.fillReveal.cy.baseVal.value = y;
59
- };
60
- this.drawShape = (hollow, $target) => {
61
- const b = this.cachedBoundingRect;
62
- const w = b.width;
63
- const h = b.height;
64
- const c = this.cachedStyle;
65
- const bw = c.borderWidth;
66
- const tl = c.topLeftBorderDecorationRadius;
67
- const tr = c.topRightBorderDecorationRadius;
68
- const bl = c.bottomLeftBorderDecorationRadius;
69
- const br = c.bottomRightBorderDecorationRadius;
70
- const wlf = c.withLeftBorderFactor;
71
- const wrf = c.withRightBorderFactor;
72
- const wtf = c.withTopBorderFactor;
73
- const wbf = c.withBottomBorderFactor;
74
- const rwlf = c.withLeftBorderFactor ? 0 : 1;
75
- const rwrf = c.withRightBorderFactor ? 0 : 1;
76
- const rwtf = c.withTopBorderFactor ? 0 : 1;
77
- const rwbf = c.withBottomBorderFactor ? 0 : 1;
78
- const ntlc = !c.withTopBorderFactor && !c.withLeftBorderFactor;
79
- const ntrc = !c.withTopBorderFactor && !c.withRightBorderFactor;
80
- const nblc = !c.withBottomBorderFactor && !c.withLeftBorderFactor;
81
- const nbrc = !c.withBottomBorderFactor && !c.withRightBorderFactor;
82
- const tl2 = bw < tl ? tl - bw : 0;
83
- const tr2 = bw < tr ? tr - bw : 0;
84
- const bl2 = bw < bl ? bl - bw : 0;
85
- const br2 = bw < br ? br - bw : 0;
86
- let d = '';
87
- // Step 1: Starting point
88
- d += hollow ? `M ${tl}, 0 ` : `M ${bw}, ${tl2 + bw} `;
89
- switch (c.borderDecorationType) {
90
- // Oh... Fuck again...
91
- case 'round':
92
- // Step 2: Draw shape
93
- if (hollow) {
94
- // Step 2-1: This is outer path, drawing clockwise
95
- d += `
96
- h ${w - tl - tr}
97
- a ${tr}, ${tr} 0 0 1 ${tr}, ${tr}
98
- v ${h - tr - br}
99
- a ${br}, ${br} 0 0 1 ${-br}, ${br}
100
- h ${-w + bl + br}
101
- a ${bl}, ${bl} 0 0 1 ${-bl}, ${-bl}
102
- v ${-h + tr + br}
103
- a ${tl}, ${tl} 0 0 1 ${tl}, ${-tl}
104
- Z
105
- `;
106
- }
107
- // Step 2-2: This is the inner path, drawing anti-clockwise
108
- d += `
109
- M ${bw * wlf}, ${tl2 + bw}
110
- v ${h - tl2 - bl2 - bw * 2 + rwbf * bw}
111
- a ${bl2}, ${bl2} 0 0 0 ${bl2}, ${bl2}
112
- h ${w - bl2 - br2 - bw * 2 + rwlf * bw + rwrf * bw}
113
- a ${br2}, ${br2} 0 0 0 ${br2}, ${-br2}
114
- v ${-h + tr2 + br2 + bw * 2 - rwtf * bw - rwbf * bw}
115
- a ${tr2}, ${tr2} 0 0 0 ${-tr2}, ${-tr2}
116
- h ${-w + bl2 + br2 + bw * 2 - rwlf * bw - rwrf * bw}
117
- a ${tl2}, ${tl2} 0 0 0 ${-tl2}, ${tl2}
118
- L ${bw * wlf}, ${tl2 + bw}
119
- `;
120
- break;
121
- case 'bevel':
122
- if (hollow) {
123
- // Step 2-1: This is outer path, drawing clockwise
124
- d += `
125
- h ${w - tl - tr}
126
- l ${tr} ${tr}
127
- v ${h - tr - br}
128
- l ${-br} ${br}
129
- h ${-w + tr + br}
130
- l ${-bl} ${-bl}
131
- v ${-h + tr + br}
132
- l ${tl} ${-tl}
133
- Z
134
- `;
135
- }
136
- // // Step 2-2: This is the inner path, drawing anti-clockwise
137
- d += `
138
- M ${bw}, ${tl2 + bw}
139
- ${rwlf ? `h ${-bw}` : ''}
140
- v ${h - tl2 - bl2 - bw * 2}
141
- ${rwlf ? `h ${bw}` : ''}
142
- ${nblc ? `l ${-bw} 0` : ''}
143
- l ${bl2} ${bl2}
144
- ${nblc ? `l ${bw} 0` : ''}
145
- ${rwbf ? `v ${bw}` : ''}
146
- h ${w - bl2 - br2 - bw * 2}
147
- ${rwbf ? `v ${-bw}` : ''}
148
- ${nbrc ? `l ${bw} 0` : ''}
149
- l ${br2} ${-br2}
150
- ${nbrc ? `l ${-bw} 0` : ''}
151
- ${rwrf ? `h ${bw}` : ''}
152
- v ${-h + tl2 + bl2 + bw * 2}
153
- ${rwrf ? `h ${-bw}` : ''}
154
- ${ntrc ? `l 0 ${-bw}` : ''}
155
- l ${-tr2} ${-tr2}
156
- ${ntrc ? `l 0 ${bw}` : ''}
157
- ${rwtf ? `v ${-bw}` : ''}
158
- h ${-w + bl2 + br2 + bw * 2}
159
- ${rwtf ? `v ${bw}` : ''}
160
- ${ntlc ? `l 0 ${-bw}` : ''}
161
- l ${-tl2} ${tl2}
162
- ${ntlc ? `l 0 ${bw}` : ''}
163
- `;
164
- break;
165
- case 'miter':
166
- // Step 2: Draw shape
167
- if (hollow) {
168
- // Step 2-1: This is outer path, drawing clockwise
169
- d += `
170
- M 0, 0
171
- h ${w}
172
- v ${h}
173
- h ${0 - w}
174
- v ${0 - h}
175
- Z
176
- `;
177
- }
178
- // Step 2-2: This is the inner path, drawing anti-clockwise
179
- d += `
180
- M ${bw * wlf}, ${bw * wtf}
181
- v ${h - wtf * bw - wbf * bw}
182
- h ${w - wlf * bw - wrf * bw}
183
- v ${-h + wtf * bw + wbf * bw}
184
- h ${-w + wlf * bw + wrf * bw}
185
- `;
186
- }
187
- // Step 3: Close the path
188
- if (c.borderDecorationType === 'miter') {
189
- d += hollow ? `L ${bw}, ${bw}` : `z`;
190
- }
191
- else {
192
- d += hollow ? `L ${tl2 + bw}, ${tl2 + bw}` : `z`;
193
- }
194
- $target.setAttribute('d', d);
195
- };
196
- this.syncSizeToElement = (x) => {
197
- const b = this.cachedBoundingRect;
198
- const width = x.width.baseVal;
199
- const height = x.height.baseVal;
200
- if (width.value !== b.width || height.value !== b.height) {
201
- width.value = b.width;
202
- height.value = b.height;
203
- }
204
- };
205
- this.clear = (forAnimation) => {
206
- if (!forAnimation) {
207
- this.internalClear();
208
- }
209
- };
210
- this.internalClear = () => {
211
- if (!this.dirty)
212
- return false;
213
- const paths = this.cachedImg.cachedPath;
214
- paths.borderReveal.style.fill = 'transparent';
215
- paths.fillReveal.style.fill = 'transparent';
216
- paths.rippleReveal.style.fill = 'transparent';
217
- this.dirty = false;
218
- return true;
219
- };
220
- this.paint = (skipSamePointerPositionCheck) => {
221
- const store = this._store;
222
- const animationPlaying = store.animationQueue.includes(this);
223
- const samePosition = store.clientX === store.paintedClientX && store.clientY === store.paintedClientY;
224
- if (samePosition && !skipSamePointerPositionCheck && !animationPlaying) {
225
- return false;
226
- }
227
- if (!store.mouseInBoundary && !animationPlaying) {
228
- this.internalClear();
229
- return false;
230
- }
231
- this.syncSizeToElement(this.element);
232
- this.cacheBoundingRect();
233
- const b = this.cachedBoundingRect;
234
- const relativeX = store.clientX - b.left;
235
- const relativeY = store.clientY - b.top;
236
- if (Number.isNaN(relativeX) || Number.isNaN(relativeY)) {
237
- return false;
238
- }
239
- const c = this.cachedStyle;
240
- this.getTrueFillRadius(c.trueFillRadius);
241
- this.paintedWidth = b.width;
242
- this.paintedHeight = b.height;
243
- const grads = this.cachedImg.cachedGradient;
244
- const maxRadius = Math.max(grads.borderReveal.r.baseVal.value, grads.fillReveal.r.baseVal.value);
245
- this._store.updateMaxRadius(maxRadius);
246
- this.cacheCanvasPaintingStyle();
247
- if (this.fillDirty) {
248
- this.updateCachedReveal();
249
- }
250
- const inLeftBound = relativeX + maxRadius > 0;
251
- const inRightBound = relativeX - maxRadius < b.width;
252
- const inTopBound = relativeY + maxRadius > 0;
253
- const inBottomBound = relativeY - maxRadius < b.height;
254
- const mouseInRenderArea = inLeftBound && inRightBound && inTopBound && inBottomBound;
255
- if (!mouseInRenderArea && !animationPlaying) {
256
- this.internalClear();
257
- return false;
258
- }
259
- this.dirty = true;
260
- this.updateGradientPosition(relativeX, relativeY);
261
- if (this.shapeDirty) {
262
- this.drawShape(true, this.cachedImg.cachedPath.borderReveal);
263
- this.drawShape(false, this.cachedImg.cachedPath.fillReveal);
264
- this.drawShape(false, this.cachedImg.cachedPath.rippleReveal);
265
- this.shapeDirty = false;
266
- }
267
- if (store.mouseInBoundary) {
268
- const mouseInElement = relativeX > 0 && relativeY > 0 && relativeX < b.width && relativeY < b.height;
269
- if (c.hoverLight && mouseInElement) {
270
- // draw fill.
271
- this.cachedImg.cachedPath.fillReveal.style.fill = 'url(#fillGrad)';
272
- }
273
- else if (this.cachedImg.cachedPath.fillReveal.style.fill !== 'transparent') {
274
- this.cachedImg.cachedPath.fillReveal.style.fill = 'transparent';
275
- }
276
- const diffuse = (c.diffuse && mouseInRenderArea) || mouseInElement;
277
- if (c.borderWidth !== 0 && diffuse) {
278
- // Draw border.
279
- this.cachedImg.cachedPath.borderReveal.style.fill = 'url(#borderGrad)';
280
- }
281
- else if (this.cachedImg.cachedPath.borderReveal.style.fill !== 'transparent') {
282
- this.cachedImg.cachedPath.borderReveal.style.fill = 'transparent';
283
- }
284
- }
285
- if (c.pressAnimation && this.mousePressed && this.mouseDownAnimateLogicFrame) {
286
- const grdRadius = c.pressAnimationFillMode === 'constrained' ? c.trueFillRadius[1] : Math.max(b.width, b.height);
287
- this.mouseReleased && this.mouseUpClientX && this.mouseUpClientY
288
- ? this.updateAnimateGrd(this.mouseDownAnimateLogicFrame, this.mouseUpClientX - b.left, this.mouseUpClientY - b.top, grdRadius)
289
- : this.updateAnimateGrd(this.mouseDownAnimateLogicFrame, relativeX, relativeY, grdRadius);
290
- this.cachedImg.cachedPath.rippleReveal.style.fill = 'url(#rippleGrad)';
291
- }
292
- else if (this.cachedImg.cachedPath.rippleReveal.style.fill !== 'transparent') {
293
- this.cachedImg.cachedPath.rippleReveal.style.fill = 'transparent';
294
- }
295
- return true;
296
- };
297
- this._store = store;
298
- const cachedPath = {
299
- borderReveal: $svg.querySelector('#borderPath'),
300
- fillReveal: $svg.querySelector('#fillPath'),
301
- rippleReveal: $svg.querySelector('#ripplePath'),
302
- };
303
- const cachedGradient = {
304
- borderReveal: $svg.querySelector('#borderGrad'),
305
- fillReveal: $svg.querySelector('#fillGrad'),
306
- rippleReveal: $svg.querySelector('#rippleGrad'),
307
- };
308
- const cachedGradientStop = {
309
- borderReveal: [
310
- $svg.querySelector('#borderCenter'),
311
- $svg.querySelector('#borderOut'),
312
- ],
313
- fillReveal: [
314
- $svg.querySelector('#fillCenter'),
315
- $svg.querySelector('#fillOut'),
316
- ],
317
- rippleReveal: [
318
- $svg.querySelector('#rippleCenter'),
319
- $svg.querySelector('#rippleMiddle'),
320
- $svg.querySelector('#rippleOut'),
321
- ],
322
- };
323
- this.cachedImg = {
324
- cachedReveal: {
325
- borderReveal: {
326
- radiusFactor: -1,
327
- radius: -1,
328
- color: 'INVALID',
329
- opacity: 0,
330
- pattern: null,
331
- },
332
- fillReveal: {
333
- radiusFactor: -1,
334
- radius: -1,
335
- color: 'INVALID',
336
- opacity: 0,
337
- pattern: null,
338
- },
339
- },
340
- cachedPath,
341
- cachedGradient,
342
- cachedGradientStop,
343
- };
344
- }
345
- }
1
+ import { BaseConfig } from './BaseConfig.js';
2
+ export class SvgConfig extends BaseConfig {
3
+ constructor(store, $svg, $container) {
4
+ super(store, $svg, $container);
5
+ this.updateCachedBitmap = () => {
6
+ };
7
+ this.updateCachedReveal = () => {
8
+ const c = this.cachedStyle;
9
+ const stops = this.cachedImg.cachedGradientStop;
10
+ stops.borderReveal[0].style.stopColor = c.borderColor;
11
+ stops.borderReveal[1].style.stopColor = c.borderColor;
12
+ stops.borderReveal[0].style.stopOpacity = c.opacity.toString();
13
+ stops.borderReveal[1].style.stopOpacity = '0';
14
+ stops.fillReveal[0].style.stopColor = c.hoverLightColor;
15
+ stops.fillReveal[1].style.stopColor = c.hoverLightColor;
16
+ stops.fillReveal[0].style.stopOpacity = (c.opacity * 0.5).toString();
17
+ stops.fillReveal[1].style.stopOpacity = '0';
18
+ stops.rippleReveal[0].style.stopColor = c.pressAnimationColor;
19
+ stops.rippleReveal[1].style.stopColor = c.pressAnimationColor;
20
+ stops.rippleReveal[2].style.stopColor = c.pressAnimationColor;
21
+ const grads = this.cachedImg.cachedGradient;
22
+ const isAbsoluteFill = c.trueFillRadius[0] === -1;
23
+ grads.borderReveal.r.baseVal.value = isAbsoluteFill
24
+ ? c.borderFillRadius
25
+ : c.borderFillRadius * c.trueFillRadius[1];
26
+ grads.fillReveal.r.baseVal.value = isAbsoluteFill
27
+ ? c.hoverLightFillRadius
28
+ : c.hoverLightFillRadius * c.trueFillRadius[0];
29
+ this.fillDirty = false;
30
+ };
31
+ this.updateAnimateGrd = (frame, x, y, radius) => {
32
+ const { opacity } = this.cachedStyle;
33
+ const _innerAlpha = opacity * (0.2 - frame);
34
+ const _outerAlpha = opacity * (0.1 - frame * 0.07);
35
+ const _outerBorder = 0.1 + frame * 0.8;
36
+ const innerAlpha = _innerAlpha < 0 ? 0 : _innerAlpha;
37
+ const outerAlpha = _outerAlpha < 0 ? 0 : _outerAlpha;
38
+ let outerBorder = 0;
39
+ outerBorder = _outerBorder > 1 ? 1 : _outerBorder;
40
+ outerBorder = _outerBorder < 0 ? 0 : _outerBorder;
41
+ const stops = this.cachedImg.cachedGradientStop;
42
+ stops.rippleReveal[0].style.stopOpacity = innerAlpha.toString();
43
+ stops.rippleReveal[1].style.stopOpacity = outerAlpha.toString();
44
+ stops.rippleReveal[2].style.stopOpacity = '0';
45
+ stops.rippleReveal[0].offset.baseVal = 0;
46
+ stops.rippleReveal[1].offset.baseVal = outerBorder * 0.55;
47
+ stops.rippleReveal[2].offset.baseVal = outerBorder;
48
+ const grads = this.cachedImg.cachedGradient;
49
+ grads.rippleReveal.r.baseVal.value = radius;
50
+ grads.rippleReveal.cx.baseVal.value = x;
51
+ grads.rippleReveal.cy.baseVal.value = y;
52
+ };
53
+ this.updateGradientPosition = (x, y) => {
54
+ const grads = this.cachedImg.cachedGradient;
55
+ grads.borderReveal.cx.baseVal.value = x;
56
+ grads.borderReveal.cy.baseVal.value = y;
57
+ grads.fillReveal.cx.baseVal.value = x;
58
+ grads.fillReveal.cy.baseVal.value = y;
59
+ };
60
+ this.drawShape = (hollow, $target) => {
61
+ const b = this.cachedBoundingRect;
62
+ const w = b.width;
63
+ const h = b.height;
64
+ const c = this.cachedStyle;
65
+ const bw = c.borderWidth;
66
+ const tl = c.topLeftBorderDecorationRadius;
67
+ const tr = c.topRightBorderDecorationRadius;
68
+ const bl = c.bottomLeftBorderDecorationRadius;
69
+ const br = c.bottomRightBorderDecorationRadius;
70
+ const wlf = c.withLeftBorderFactor;
71
+ const wrf = c.withRightBorderFactor;
72
+ const wtf = c.withTopBorderFactor;
73
+ const wbf = c.withBottomBorderFactor;
74
+ const rwlf = c.withLeftBorderFactor ? 0 : 1;
75
+ const rwrf = c.withRightBorderFactor ? 0 : 1;
76
+ const rwtf = c.withTopBorderFactor ? 0 : 1;
77
+ const rwbf = c.withBottomBorderFactor ? 0 : 1;
78
+ const ntlc = !c.withTopBorderFactor && !c.withLeftBorderFactor;
79
+ const ntrc = !c.withTopBorderFactor && !c.withRightBorderFactor;
80
+ const nblc = !c.withBottomBorderFactor && !c.withLeftBorderFactor;
81
+ const nbrc = !c.withBottomBorderFactor && !c.withRightBorderFactor;
82
+ const tl2 = bw < tl ? tl - bw : 0;
83
+ const tr2 = bw < tr ? tr - bw : 0;
84
+ const bl2 = bw < bl ? bl - bw : 0;
85
+ const br2 = bw < br ? br - bw : 0;
86
+ let d = '';
87
+ // Step 1: Starting point
88
+ d += hollow ? `M ${tl}, 0 ` : `M ${bw}, ${tl2 + bw} `;
89
+ switch (c.borderDecorationType) {
90
+ // Oh... Fuck again...
91
+ case 'round':
92
+ // Step 2: Draw shape
93
+ if (hollow) {
94
+ // Step 2-1: This is outer path, drawing clockwise
95
+ d += `
96
+ h ${w - tl - tr}
97
+ a ${tr}, ${tr} 0 0 1 ${tr}, ${tr}
98
+ v ${h - tr - br}
99
+ a ${br}, ${br} 0 0 1 ${-br}, ${br}
100
+ h ${-w + bl + br}
101
+ a ${bl}, ${bl} 0 0 1 ${-bl}, ${-bl}
102
+ v ${-h + tr + br}
103
+ a ${tl}, ${tl} 0 0 1 ${tl}, ${-tl}
104
+ Z
105
+ `;
106
+ }
107
+ // Step 2-2: This is the inner path, drawing anti-clockwise
108
+ d += `
109
+ M ${bw * wlf}, ${tl2 + bw}
110
+ v ${h - tl2 - bl2 - bw * 2 + rwbf * bw}
111
+ a ${bl2}, ${bl2} 0 0 0 ${bl2}, ${bl2}
112
+ h ${w - bl2 - br2 - bw * 2 + rwlf * bw + rwrf * bw}
113
+ a ${br2}, ${br2} 0 0 0 ${br2}, ${-br2}
114
+ v ${-h + tr2 + br2 + bw * 2 - rwtf * bw - rwbf * bw}
115
+ a ${tr2}, ${tr2} 0 0 0 ${-tr2}, ${-tr2}
116
+ h ${-w + bl2 + br2 + bw * 2 - rwlf * bw - rwrf * bw}
117
+ a ${tl2}, ${tl2} 0 0 0 ${-tl2}, ${tl2}
118
+ L ${bw * wlf}, ${tl2 + bw}
119
+ `;
120
+ break;
121
+ case 'bevel':
122
+ if (hollow) {
123
+ // Step 2-1: This is outer path, drawing clockwise
124
+ d += `
125
+ h ${w - tl - tr}
126
+ l ${tr} ${tr}
127
+ v ${h - tr - br}
128
+ l ${-br} ${br}
129
+ h ${-w + tr + br}
130
+ l ${-bl} ${-bl}
131
+ v ${-h + tr + br}
132
+ l ${tl} ${-tl}
133
+ Z
134
+ `;
135
+ }
136
+ // // Step 2-2: This is the inner path, drawing anti-clockwise
137
+ d += `
138
+ M ${bw}, ${tl2 + bw}
139
+ ${rwlf ? `h ${-bw}` : ''}
140
+ v ${h - tl2 - bl2 - bw * 2}
141
+ ${rwlf ? `h ${bw}` : ''}
142
+ ${nblc ? `l ${-bw} 0` : ''}
143
+ l ${bl2} ${bl2}
144
+ ${nblc ? `l ${bw} 0` : ''}
145
+ ${rwbf ? `v ${bw}` : ''}
146
+ h ${w - bl2 - br2 - bw * 2}
147
+ ${rwbf ? `v ${-bw}` : ''}
148
+ ${nbrc ? `l ${bw} 0` : ''}
149
+ l ${br2} ${-br2}
150
+ ${nbrc ? `l ${-bw} 0` : ''}
151
+ ${rwrf ? `h ${bw}` : ''}
152
+ v ${-h + tl2 + bl2 + bw * 2}
153
+ ${rwrf ? `h ${-bw}` : ''}
154
+ ${ntrc ? `l 0 ${-bw}` : ''}
155
+ l ${-tr2} ${-tr2}
156
+ ${ntrc ? `l 0 ${bw}` : ''}
157
+ ${rwtf ? `v ${-bw}` : ''}
158
+ h ${-w + bl2 + br2 + bw * 2}
159
+ ${rwtf ? `v ${bw}` : ''}
160
+ ${ntlc ? `l 0 ${-bw}` : ''}
161
+ l ${-tl2} ${tl2}
162
+ ${ntlc ? `l 0 ${bw}` : ''}
163
+ `;
164
+ break;
165
+ case 'miter':
166
+ // Step 2: Draw shape
167
+ if (hollow) {
168
+ // Step 2-1: This is outer path, drawing clockwise
169
+ d += `
170
+ M 0, 0
171
+ h ${w}
172
+ v ${h}
173
+ h ${0 - w}
174
+ v ${0 - h}
175
+ Z
176
+ `;
177
+ }
178
+ // Step 2-2: This is the inner path, drawing anti-clockwise
179
+ d += `
180
+ M ${bw * wlf}, ${bw * wtf}
181
+ v ${h - wtf * bw - wbf * bw}
182
+ h ${w - wlf * bw - wrf * bw}
183
+ v ${-h + wtf * bw + wbf * bw}
184
+ h ${-w + wlf * bw + wrf * bw}
185
+ `;
186
+ }
187
+ // Step 3: Close the path
188
+ if (c.borderDecorationType === 'miter') {
189
+ d += hollow ? `L ${bw}, ${bw}` : `z`;
190
+ }
191
+ else {
192
+ d += hollow ? `L ${tl2 + bw}, ${tl2 + bw}` : `z`;
193
+ }
194
+ $target.setAttribute('d', d);
195
+ };
196
+ this.syncSizeToElement = (x) => {
197
+ const b = this.cachedBoundingRect;
198
+ const width = x.width.baseVal;
199
+ const height = x.height.baseVal;
200
+ if (width.value !== b.width || height.value !== b.height) {
201
+ width.value = b.width;
202
+ height.value = b.height;
203
+ }
204
+ };
205
+ this.clear = (forAnimation) => {
206
+ if (!forAnimation) {
207
+ this.internalClear();
208
+ }
209
+ };
210
+ this.internalClear = () => {
211
+ if (!this.dirty)
212
+ return false;
213
+ const paths = this.cachedImg.cachedPath;
214
+ paths.borderReveal.style.fill = 'transparent';
215
+ paths.fillReveal.style.fill = 'transparent';
216
+ paths.rippleReveal.style.fill = 'transparent';
217
+ this.dirty = false;
218
+ return true;
219
+ };
220
+ this.paint = (skipSamePointerPositionCheck) => {
221
+ const store = this._store;
222
+ const animationPlaying = store.animationQueue.includes(this);
223
+ const samePosition = store.clientX === store.paintedClientX && store.clientY === store.paintedClientY;
224
+ if (samePosition && !skipSamePointerPositionCheck && !animationPlaying) {
225
+ return false;
226
+ }
227
+ if (!store.mouseInBoundary && !animationPlaying) {
228
+ this.internalClear();
229
+ return false;
230
+ }
231
+ this.syncSizeToElement(this.element);
232
+ this.cacheBoundingRect();
233
+ const b = this.cachedBoundingRect;
234
+ const relativeX = store.clientX - b.left;
235
+ const relativeY = store.clientY - b.top;
236
+ if (Number.isNaN(relativeX) || Number.isNaN(relativeY)) {
237
+ return false;
238
+ }
239
+ const c = this.cachedStyle;
240
+ this.getTrueFillRadius(c.trueFillRadius);
241
+ this.paintedWidth = b.width;
242
+ this.paintedHeight = b.height;
243
+ const grads = this.cachedImg.cachedGradient;
244
+ const maxRadius = Math.max(grads.borderReveal.r.baseVal.value, grads.fillReveal.r.baseVal.value);
245
+ this._store.updateMaxRadius(maxRadius);
246
+ this.cacheCanvasPaintingStyle();
247
+ if (this.fillDirty) {
248
+ this.updateCachedReveal();
249
+ }
250
+ const inLeftBound = relativeX + maxRadius > 0;
251
+ const inRightBound = relativeX - maxRadius < b.width;
252
+ const inTopBound = relativeY + maxRadius > 0;
253
+ const inBottomBound = relativeY - maxRadius < b.height;
254
+ const mouseInRenderArea = inLeftBound && inRightBound && inTopBound && inBottomBound;
255
+ if (!mouseInRenderArea && !animationPlaying) {
256
+ this.internalClear();
257
+ return false;
258
+ }
259
+ this.dirty = true;
260
+ this.updateGradientPosition(relativeX, relativeY);
261
+ if (this.shapeDirty) {
262
+ this.drawShape(true, this.cachedImg.cachedPath.borderReveal);
263
+ this.drawShape(false, this.cachedImg.cachedPath.fillReveal);
264
+ this.drawShape(false, this.cachedImg.cachedPath.rippleReveal);
265
+ this.shapeDirty = false;
266
+ }
267
+ if (store.mouseInBoundary) {
268
+ const mouseInElement = relativeX > 0 && relativeY > 0 && relativeX < b.width && relativeY < b.height;
269
+ if (c.hoverLight && mouseInElement) {
270
+ // draw fill.
271
+ this.cachedImg.cachedPath.fillReveal.style.fill = 'url(#fillGrad)';
272
+ }
273
+ else if (this.cachedImg.cachedPath.fillReveal.style.fill !== 'transparent') {
274
+ this.cachedImg.cachedPath.fillReveal.style.fill = 'transparent';
275
+ }
276
+ const diffuse = (c.diffuse && mouseInRenderArea) || mouseInElement;
277
+ if (c.borderWidth !== 0 && diffuse) {
278
+ // Draw border.
279
+ this.cachedImg.cachedPath.borderReveal.style.fill = 'url(#borderGrad)';
280
+ }
281
+ else if (this.cachedImg.cachedPath.borderReveal.style.fill !== 'transparent') {
282
+ this.cachedImg.cachedPath.borderReveal.style.fill = 'transparent';
283
+ }
284
+ }
285
+ if (c.pressAnimation && this.mousePressed && this.mouseDownAnimateLogicFrame) {
286
+ const grdRadius = c.pressAnimationFillMode === 'constrained' ? c.trueFillRadius[1] : Math.max(b.width, b.height);
287
+ this.mouseReleased && this.mouseUpClientX && this.mouseUpClientY
288
+ ? this.updateAnimateGrd(this.mouseDownAnimateLogicFrame, this.mouseUpClientX - b.left, this.mouseUpClientY - b.top, grdRadius)
289
+ : this.updateAnimateGrd(this.mouseDownAnimateLogicFrame, relativeX, relativeY, grdRadius);
290
+ this.cachedImg.cachedPath.rippleReveal.style.fill = 'url(#rippleGrad)';
291
+ }
292
+ else if (this.cachedImg.cachedPath.rippleReveal.style.fill !== 'transparent') {
293
+ this.cachedImg.cachedPath.rippleReveal.style.fill = 'transparent';
294
+ }
295
+ return true;
296
+ };
297
+ this._store = store;
298
+ const cachedPath = {
299
+ borderReveal: $svg.querySelector('#borderPath'),
300
+ fillReveal: $svg.querySelector('#fillPath'),
301
+ rippleReveal: $svg.querySelector('#ripplePath'),
302
+ };
303
+ const cachedGradient = {
304
+ borderReveal: $svg.querySelector('#borderGrad'),
305
+ fillReveal: $svg.querySelector('#fillGrad'),
306
+ rippleReveal: $svg.querySelector('#rippleGrad'),
307
+ };
308
+ const cachedGradientStop = {
309
+ borderReveal: [
310
+ $svg.querySelector('#borderCenter'),
311
+ $svg.querySelector('#borderOut'),
312
+ ],
313
+ fillReveal: [
314
+ $svg.querySelector('#fillCenter'),
315
+ $svg.querySelector('#fillOut'),
316
+ ],
317
+ rippleReveal: [
318
+ $svg.querySelector('#rippleCenter'),
319
+ $svg.querySelector('#rippleMiddle'),
320
+ $svg.querySelector('#rippleOut'),
321
+ ],
322
+ };
323
+ this.cachedImg = {
324
+ cachedReveal: {
325
+ borderReveal: {
326
+ radiusFactor: -1,
327
+ radius: -1,
328
+ color: 'INVALID',
329
+ opacity: 0,
330
+ pattern: null,
331
+ },
332
+ fillReveal: {
333
+ radiusFactor: -1,
334
+ radius: -1,
335
+ color: 'INVALID',
336
+ opacity: 0,
337
+ pattern: null,
338
+ },
339
+ },
340
+ cachedPath,
341
+ cachedGradient,
342
+ cachedGradientStop,
343
+ };
344
+ }
345
+ }
346
346
  //# sourceMappingURL=SvgConfig.js.map