@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
@@ -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
- // 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
- }
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
+ }