@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.
- package/LICENSE +21 -21
- package/README.md +75 -75
- package/build/BaseConfig.d.ts +5 -1
- package/build/BaseConfig.d.ts.map +1 -1
- package/build/CanvasConfig.d.ts +7 -1
- package/build/CanvasConfig.d.ts.map +1 -1
- package/build/ComputedStyleStorage.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 +4 -0
- package/build/RevealBoundryStore.d.ts.map +1 -1
- package/build/RevealStateManager.d.ts +5 -1
- package/build/RevealStateManager.d.ts.map +1 -1
- package/build/main.js +113 -82
- package/build/utils/types.d.ts +2 -10
- package/build/utils/types.d.ts.map +1 -1
- package/es/BaseConfig.d.ts +46 -42
- package/es/BaseConfig.d.ts.map +1 -1
- package/es/BaseConfig.js +241 -219
- package/es/BaseConfig.js.map +1 -1
- package/es/CanvasConfig.d.ts +21 -15
- package/es/CanvasConfig.d.ts.map +1 -1
- package/es/CanvasConfig.js +332 -320
- package/es/CanvasConfig.js.map +1 -1
- package/es/ComputedStyleStorage.d.ts +8 -8
- package/es/ComputedStyleStorage.d.ts.map +1 -1
- package/es/ComputedStyleStorage.js +68 -58
- package/es/ComputedStyleStorage.js.map +1 -1
- package/es/CustomElements.d.ts +75 -59
- package/es/CustomElements.d.ts.map +1 -1
- package/es/CustomElements.js +296 -233
- package/es/CustomElements.js.map +1 -1
- package/es/Profiler.d.ts +12 -12
- package/es/Profiler.js +31 -31
- package/es/RevealBoundryStore.d.ts +80 -76
- package/es/RevealBoundryStore.d.ts.map +1 -1
- package/es/RevealBoundryStore.js +269 -248
- package/es/RevealBoundryStore.js.map +1 -1
- package/es/RevealStateManager.d.ts +19 -15
- package/es/RevealStateManager.d.ts.map +1 -1
- package/es/RevealStateManager.js +99 -73
- package/es/RevealStateManager.js.map +1 -1
- package/es/SvgConfig.d.ts +16 -16
- package/es/SvgConfig.js +345 -345
- package/es/config.d.ts +4 -4
- package/es/config.js +21 -21
- package/es/index.d.ts +5 -5
- package/es/index.js +205 -205
- package/es/tsconfig.tsbuildinfo +1 -1
- package/es/utils/extractRGBValue.d.ts +1 -1
- package/es/utils/extractRGBValue.js +47 -47
- package/es/utils/isValidateBorderDecorationType.d.ts +2 -2
- package/es/utils/isValidateBorderDecorationType.js +9 -9
- package/es/utils/types.d.ts +94 -102
- package/es/utils/types.d.ts.map +1 -1
- package/es/utils/types.js +1 -1
- package/es/variables.d.ts +1 -1
- package/es/variables.js +1 -1
- package/package.json +35 -34
- package/src/BaseConfig.ts +332 -310
- package/src/CanvasConfig.ts +420 -415
- package/src/ComputedStyleStorage.ts +102 -89
- package/src/CustomElements.ts +344 -272
- package/src/Profiler.ts +44 -44
- package/src/RevealBoundryStore.ts +315 -291
- package/src/RevealStateManager.ts +109 -86
- 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 +97 -105
- package/src/variables.ts +1 -1
|
@@ -1,86 +1,109 @@
|
|
|
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
|
-
//
|
|
19
|
-
|
|
20
|
-
//
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
//
|
|
27
|
-
window
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
//
|
|
33
|
-
// image
|
|
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
|
-
this.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
+
// A finger landing on the screen without moving fires no `pointermove`.
|
|
19
|
+
window.addEventListener('pointerdown', this.handlePointerMove);
|
|
20
|
+
// This is for touch screen
|
|
21
|
+
// Window.pointerleave won't be triggered if the finger
|
|
22
|
+
// leave the screen, so we use pointer up here.
|
|
23
|
+
window.addEventListener('pointerup', (ev) => {
|
|
24
|
+
if (ev.pointerType !== 'mouse') this.handlePointerLeave();
|
|
25
|
+
});
|
|
26
|
+
// This is for desktop
|
|
27
|
+
// If the mouse leave the window, we need to terminate
|
|
28
|
+
// all animations and clean up the canvas.
|
|
29
|
+
window.addEventListener('pointerleave', (ev) => {
|
|
30
|
+
if (ev.pointerType === 'mouse') this.handlePointerLeave();
|
|
31
|
+
});
|
|
32
|
+
// Handles boundary conditions such as the user scrolling
|
|
33
|
+
// the page, dragging the image, which can cause mouse events
|
|
34
|
+
// to fail, when Reveal should disappear to prevent the
|
|
35
|
+
// image from getting stuck.
|
|
36
|
+
window.addEventListener('pointercancel', (ev) => {
|
|
37
|
+
// The browser took over the touch for scrolling, keep following
|
|
38
|
+
// the finger with touch events until it leaves the screen.
|
|
39
|
+
if (ev.pointerType === 'touch') {
|
|
40
|
+
this.touchScrolling = true;
|
|
41
|
+
for (let i = 0; i < this._storage.length; i++) {
|
|
42
|
+
this._storage[i].anchorPointer();
|
|
43
|
+
}
|
|
44
|
+
} else {
|
|
45
|
+
this.handlePointerLeave();
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
window.addEventListener('touchmove', (ev) => {
|
|
49
|
+
if (this.touchScrolling && ev.touches.length) this.handlePointerMove(ev.touches[0]);
|
|
50
|
+
}, { passive: true });
|
|
51
|
+
const handleTouchEnd = (ev: TouchEvent) => {
|
|
52
|
+
if (!this.touchScrolling || ev.touches.length) return;
|
|
53
|
+
this.touchScrolling = false;
|
|
54
|
+
this.handlePointerLeave();
|
|
55
|
+
};
|
|
56
|
+
window.addEventListener('touchend', handleTouchEnd, { passive: true });
|
|
57
|
+
window.addEventListener('touchcancel', handleTouchEnd, { passive: true });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
touchScrolling = false;
|
|
62
|
+
|
|
63
|
+
pointerLeaveScheduled = false;
|
|
64
|
+
|
|
65
|
+
handlePointerLeave = () => {
|
|
66
|
+
if (this.pointerLeaveScheduled) return;
|
|
67
|
+
|
|
68
|
+
this.pointerLeaveScheduled = true;
|
|
69
|
+
|
|
70
|
+
window.requestAnimationFrame(() => {
|
|
71
|
+
for (let i = 0; i < this._storage.length; i++) {
|
|
72
|
+
this._storage[i].onPointerLeaveBoundary();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
this.pointerLeaveScheduled = false;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
handlePointerMove = (event: { clientX: number; clientY: number }) => {
|
|
80
|
+
this.cachedMouseX = event.clientX;
|
|
81
|
+
this.cachedMouseY = event.clientY;
|
|
82
|
+
|
|
83
|
+
if (!this.requestedTraverseBoundaries) {
|
|
84
|
+
window.requestAnimationFrame(this.traverseBoundaries);
|
|
85
|
+
this.requestedTraverseBoundaries = true;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
traverseBoundaries = () => {
|
|
90
|
+
this.requestedTraverseBoundaries = false;
|
|
91
|
+
for (let i = 0; i < this._storage.length; i++) {
|
|
92
|
+
this._storage[i].onPointerMoveOnScreen(this.cachedMouseX, this.cachedMouseY);
|
|
93
|
+
if (this.touchScrolling) this._storage[i].anchorPointer();
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
newBoundary = ($el: HTMLElement) => {
|
|
98
|
+
const hashId = this._currentHashId++;
|
|
99
|
+
|
|
100
|
+
const store = new RevealBoundaryStore(hashId, $el);
|
|
101
|
+
this._storage.push(store);
|
|
102
|
+
|
|
103
|
+
return store;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
removeBoundary = (store: RevealBoundaryStore) => {
|
|
107
|
+
this._storage = this._storage.filter((x) => x !== store);
|
|
108
|
+
};
|
|
109
|
+
}
|