@ax-design/reveal-highlight 0.4.1 → 0.5.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/LICENSE +21 -21
- package/README.md +75 -75
- package/build/RevealStateManager.d.ts.map +1 -1
- package/build/main.js +1 -1
- package/es/CustomElements.js +60 -60
- package/es/RevealStateManager.d.ts.map +1 -1
- package/es/RevealStateManager.js +8 -0
- package/es/RevealStateManager.js.map +1 -1
- package/es/SvgConfig.js +70 -70
- package/es/tsconfig.tsbuildinfo +1 -1
- package/package.json +35 -34
- package/src/BaseConfig.ts +310 -310
- package/src/CanvasConfig.ts +415 -415
- package/src/ComputedStyleStorage.ts +89 -89
- package/src/CustomElements.ts +272 -272
- package/src/Profiler.ts +44 -44
- package/src/RevealBoundryStore.ts +291 -291
- package/src/RevealStateManager.ts +86 -78
- package/src/SvgConfig.ts +422 -422
- package/src/config.ts +26 -26
- package/src/cssTypedOM.d.ts +52 -52
- package/src/index.ts +219 -219
- package/src/utils/extractRGBValue.ts +58 -58
- package/src/utils/isValidateBorderDecorationType.ts +8 -8
- package/src/utils/types.ts +105 -105
- package/src/variables.ts +1 -1
|
@@ -1,78 +1,86 @@
|
|
|
1
|
-
import { RevealBoundaryStore } from './RevealBoundryStore.js';
|
|
2
|
-
|
|
3
|
-
import { config } from './config.js';
|
|
4
|
-
|
|
5
|
-
export class RevealStateManager {
|
|
6
|
-
private _currentHashId = 0;
|
|
7
|
-
private _storage: RevealBoundaryStore[] = [];
|
|
8
|
-
|
|
9
|
-
private requestedTraverseBoundaries = false;
|
|
10
|
-
cachedMouseX = -1;
|
|
11
|
-
cachedMouseY = -1;
|
|
12
|
-
|
|
13
|
-
constructor() {
|
|
14
|
-
if (config.borderDetectionMode === 'experimentalAutoFit') {
|
|
15
|
-
if (typeof Window === 'undefined') return;
|
|
16
|
-
|
|
17
|
-
window.addEventListener('pointermove', this.handlePointerMove);
|
|
18
|
-
// This is for touch screen
|
|
19
|
-
// Window.pointerleave won't be triggered if the finger
|
|
20
|
-
// leave the screen, so we use pointer up here.
|
|
21
|
-
window.addEventListener('pointerup', (ev) => {
|
|
22
|
-
if (ev.pointerType !== 'mouse') this.handlePointerLeave();
|
|
23
|
-
});
|
|
24
|
-
// This is for desktop
|
|
25
|
-
// If the mouse leave the window, we need to terminate
|
|
26
|
-
// all animations and clean up the canvas.
|
|
27
|
-
window.addEventListener('pointerleave', (ev) => {
|
|
28
|
-
if (ev.pointerType === 'mouse') this.handlePointerLeave();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
1
|
+
import { RevealBoundaryStore } from './RevealBoundryStore.js';
|
|
2
|
+
|
|
3
|
+
import { config } from './config.js';
|
|
4
|
+
|
|
5
|
+
export class RevealStateManager {
|
|
6
|
+
private _currentHashId = 0;
|
|
7
|
+
private _storage: RevealBoundaryStore[] = [];
|
|
8
|
+
|
|
9
|
+
private requestedTraverseBoundaries = false;
|
|
10
|
+
cachedMouseX = -1;
|
|
11
|
+
cachedMouseY = -1;
|
|
12
|
+
|
|
13
|
+
constructor() {
|
|
14
|
+
if (config.borderDetectionMode === 'experimentalAutoFit') {
|
|
15
|
+
if (typeof Window === 'undefined') return;
|
|
16
|
+
|
|
17
|
+
window.addEventListener('pointermove', this.handlePointerMove);
|
|
18
|
+
// This is for touch screen
|
|
19
|
+
// Window.pointerleave won't be triggered if the finger
|
|
20
|
+
// leave the screen, so we use pointer up here.
|
|
21
|
+
window.addEventListener('pointerup', (ev) => {
|
|
22
|
+
if (ev.pointerType !== 'mouse') this.handlePointerLeave();
|
|
23
|
+
});
|
|
24
|
+
// This is for desktop
|
|
25
|
+
// If the mouse leave the window, we need to terminate
|
|
26
|
+
// all animations and clean up the canvas.
|
|
27
|
+
window.addEventListener('pointerleave', (ev) => {
|
|
28
|
+
if (ev.pointerType === 'mouse') this.handlePointerLeave();
|
|
29
|
+
});
|
|
30
|
+
// Handles boundary conditions such as the user scrolling
|
|
31
|
+
// the page, dragging the image, which can cause mouse events
|
|
32
|
+
// to fail, when Reveal should disappear to prevent the
|
|
33
|
+
// image from getting stuck.
|
|
34
|
+
window.addEventListener('pointercancel', (ev) => {
|
|
35
|
+
console.log('pointer cancel');
|
|
36
|
+
this.handlePointerLeave();
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
pointerLeaveScheduled = false;
|
|
42
|
+
|
|
43
|
+
handlePointerLeave = () => {
|
|
44
|
+
if (this.pointerLeaveScheduled) return;
|
|
45
|
+
|
|
46
|
+
this.pointerLeaveScheduled = true;
|
|
47
|
+
|
|
48
|
+
window.requestAnimationFrame(() => {
|
|
49
|
+
for (let i = 0; i < this._storage.length; i++) {
|
|
50
|
+
this._storage[i].onPointerLeaveBoundary();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
this.pointerLeaveScheduled = false;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
handlePointerMove = (event: PointerEvent) => {
|
|
58
|
+
this.cachedMouseX = event.clientX;
|
|
59
|
+
this.cachedMouseY = event.clientY;
|
|
60
|
+
|
|
61
|
+
if (!this.requestedTraverseBoundaries) {
|
|
62
|
+
window.requestAnimationFrame(this.traverseBoundaries);
|
|
63
|
+
this.requestedTraverseBoundaries = true;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
traverseBoundaries = () => {
|
|
68
|
+
this.requestedTraverseBoundaries = false;
|
|
69
|
+
for (let i = 0; i < this._storage.length; i++) {
|
|
70
|
+
this._storage[i].onPointerMoveOnScreen(this.cachedMouseX, this.cachedMouseY);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
newBoundary = ($el: HTMLElement) => {
|
|
75
|
+
const hashId = this._currentHashId++;
|
|
76
|
+
|
|
77
|
+
const store = new RevealBoundaryStore(hashId, $el);
|
|
78
|
+
this._storage.push(store);
|
|
79
|
+
|
|
80
|
+
return store;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
removeBoundary = (store: RevealBoundaryStore) => {
|
|
84
|
+
this._storage = this._storage.filter((x) => x !== store);
|
|
85
|
+
};
|
|
86
|
+
}
|