@knotx/plugins-canvas-scrollbar 0.5.7 → 0.5.8
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/dist/index.cjs +53 -40
- package/dist/index.js +53 -40
- package/package.json +10 -10
package/dist/index.cjs
CHANGED
|
@@ -104,56 +104,69 @@ class CanvasScrollbar extends (_a = core.BasePlugin, _showScrollbars_dec = [deco
|
|
|
104
104
|
__publicField(this, "handleMouseDown", (e, type) => {
|
|
105
105
|
e.preventDefault();
|
|
106
106
|
e.stopPropagation();
|
|
107
|
-
if (
|
|
107
|
+
if (!this.transform || !this.contentSize)
|
|
108
|
+
return;
|
|
109
|
+
const isHorizontal = type === "horizontal";
|
|
110
|
+
const tracker = this.getScrollTracker(type);
|
|
111
|
+
const thumb = this.getScrollThumb(type);
|
|
112
|
+
if (!tracker || !thumb)
|
|
113
|
+
return;
|
|
114
|
+
const trackRect = tracker.getBoundingClientRect();
|
|
115
|
+
const thumbRect = thumb.getBoundingClientRect();
|
|
116
|
+
const trackSize = isHorizontal ? trackRect.width : trackRect.height;
|
|
117
|
+
const thumbSize = isHorizontal ? thumbRect.width : thumbRect.height;
|
|
118
|
+
const contentSize = isHorizontal ? this.contentSize.width * this.transform.scale : this.contentSize.height * this.transform.scale;
|
|
119
|
+
const containerSize = isHorizontal ? this.container.width : this.container.height;
|
|
120
|
+
const maxScroll = contentSize - containerSize;
|
|
121
|
+
const scrollableTrackSize = trackSize - thumbSize;
|
|
122
|
+
if (scrollableTrackSize <= 0)
|
|
123
|
+
return;
|
|
124
|
+
const ratio = maxScroll / scrollableTrackSize;
|
|
125
|
+
const startMousePos = isHorizontal ? e.clientX : e.clientY;
|
|
126
|
+
const startScrollPos = isHorizontal ? -this.transform.positionX : -this.transform.positionY;
|
|
127
|
+
if (isHorizontal) {
|
|
108
128
|
this.isDraggingHorizontal = true;
|
|
109
129
|
this.startDragPos.x = e.clientX;
|
|
110
|
-
this.startScrollPos.x =
|
|
130
|
+
this.startScrollPos.x = startScrollPos;
|
|
111
131
|
} else {
|
|
112
132
|
this.isDraggingVertical = true;
|
|
113
133
|
this.startDragPos.y = e.clientY;
|
|
114
|
-
this.startScrollPos.y =
|
|
134
|
+
this.startScrollPos.y = startScrollPos;
|
|
115
135
|
}
|
|
136
|
+
let rafId = null;
|
|
116
137
|
const handleMouseMove = (e2) => {
|
|
117
|
-
if (
|
|
138
|
+
if (rafId)
|
|
118
139
|
return;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const
|
|
123
|
-
const
|
|
124
|
-
const
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const maxScroll = contentHeight - this.container.height;
|
|
144
|
-
const deltaY = e2.clientY - this.startDragPos.y;
|
|
145
|
-
const deltaScrollPercentage = deltaY / (trackHeight - thumbHeight);
|
|
146
|
-
const deltaScroll = deltaScrollPercentage * maxScroll;
|
|
147
|
-
const newScrollY = Math.max(0, Math.min(maxScroll, this.startScrollPos.y + deltaScroll));
|
|
148
|
-
this.callTool("canvas", "setTransform", {
|
|
149
|
-
positionX: this.transform.positionX,
|
|
150
|
-
positionY: -newScrollY,
|
|
151
|
-
scale: this.transform.scale,
|
|
152
|
-
animationTime: 0
|
|
153
|
-
});
|
|
154
|
-
}
|
|
140
|
+
rafId = requestAnimationFrame(() => {
|
|
141
|
+
if (!this.transform)
|
|
142
|
+
return;
|
|
143
|
+
const currentMousePos = isHorizontal ? e2.clientX : e2.clientY;
|
|
144
|
+
const deltaMouse = currentMousePos - startMousePos;
|
|
145
|
+
const deltaScroll = deltaMouse * ratio;
|
|
146
|
+
const newScroll = Math.max(0, Math.min(maxScroll, startScrollPos + deltaScroll));
|
|
147
|
+
if (isHorizontal) {
|
|
148
|
+
this.callTool("canvas", "setTransform", {
|
|
149
|
+
positionX: -newScroll,
|
|
150
|
+
positionY: this.transform.positionY,
|
|
151
|
+
scale: this.transform.scale,
|
|
152
|
+
animationTime: 0
|
|
153
|
+
});
|
|
154
|
+
} else {
|
|
155
|
+
this.callTool("canvas", "setTransform", {
|
|
156
|
+
positionX: this.transform.positionX,
|
|
157
|
+
positionY: -newScroll,
|
|
158
|
+
scale: this.transform.scale,
|
|
159
|
+
animationTime: 0
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
rafId = null;
|
|
163
|
+
});
|
|
155
164
|
};
|
|
156
165
|
const handleMouseUp = () => {
|
|
166
|
+
if (rafId) {
|
|
167
|
+
cancelAnimationFrame(rafId);
|
|
168
|
+
rafId = null;
|
|
169
|
+
}
|
|
157
170
|
this.isDraggingHorizontal = false;
|
|
158
171
|
this.isDraggingVertical = false;
|
|
159
172
|
document.removeEventListener("mousemove", handleMouseMove);
|
package/dist/index.js
CHANGED
|
@@ -102,56 +102,69 @@ class CanvasScrollbar extends (_a = BasePlugin, _showScrollbars_dec = [observabl
|
|
|
102
102
|
__publicField(this, "handleMouseDown", (e, type) => {
|
|
103
103
|
e.preventDefault();
|
|
104
104
|
e.stopPropagation();
|
|
105
|
-
if (
|
|
105
|
+
if (!this.transform || !this.contentSize)
|
|
106
|
+
return;
|
|
107
|
+
const isHorizontal = type === "horizontal";
|
|
108
|
+
const tracker = this.getScrollTracker(type);
|
|
109
|
+
const thumb = this.getScrollThumb(type);
|
|
110
|
+
if (!tracker || !thumb)
|
|
111
|
+
return;
|
|
112
|
+
const trackRect = tracker.getBoundingClientRect();
|
|
113
|
+
const thumbRect = thumb.getBoundingClientRect();
|
|
114
|
+
const trackSize = isHorizontal ? trackRect.width : trackRect.height;
|
|
115
|
+
const thumbSize = isHorizontal ? thumbRect.width : thumbRect.height;
|
|
116
|
+
const contentSize = isHorizontal ? this.contentSize.width * this.transform.scale : this.contentSize.height * this.transform.scale;
|
|
117
|
+
const containerSize = isHorizontal ? this.container.width : this.container.height;
|
|
118
|
+
const maxScroll = contentSize - containerSize;
|
|
119
|
+
const scrollableTrackSize = trackSize - thumbSize;
|
|
120
|
+
if (scrollableTrackSize <= 0)
|
|
121
|
+
return;
|
|
122
|
+
const ratio = maxScroll / scrollableTrackSize;
|
|
123
|
+
const startMousePos = isHorizontal ? e.clientX : e.clientY;
|
|
124
|
+
const startScrollPos = isHorizontal ? -this.transform.positionX : -this.transform.positionY;
|
|
125
|
+
if (isHorizontal) {
|
|
106
126
|
this.isDraggingHorizontal = true;
|
|
107
127
|
this.startDragPos.x = e.clientX;
|
|
108
|
-
this.startScrollPos.x =
|
|
128
|
+
this.startScrollPos.x = startScrollPos;
|
|
109
129
|
} else {
|
|
110
130
|
this.isDraggingVertical = true;
|
|
111
131
|
this.startDragPos.y = e.clientY;
|
|
112
|
-
this.startScrollPos.y =
|
|
132
|
+
this.startScrollPos.y = startScrollPos;
|
|
113
133
|
}
|
|
134
|
+
let rafId = null;
|
|
114
135
|
const handleMouseMove = (e2) => {
|
|
115
|
-
if (
|
|
136
|
+
if (rafId)
|
|
116
137
|
return;
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
const
|
|
122
|
-
const
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const maxScroll = contentHeight - this.container.height;
|
|
142
|
-
const deltaY = e2.clientY - this.startDragPos.y;
|
|
143
|
-
const deltaScrollPercentage = deltaY / (trackHeight - thumbHeight);
|
|
144
|
-
const deltaScroll = deltaScrollPercentage * maxScroll;
|
|
145
|
-
const newScrollY = Math.max(0, Math.min(maxScroll, this.startScrollPos.y + deltaScroll));
|
|
146
|
-
this.callTool("canvas", "setTransform", {
|
|
147
|
-
positionX: this.transform.positionX,
|
|
148
|
-
positionY: -newScrollY,
|
|
149
|
-
scale: this.transform.scale,
|
|
150
|
-
animationTime: 0
|
|
151
|
-
});
|
|
152
|
-
}
|
|
138
|
+
rafId = requestAnimationFrame(() => {
|
|
139
|
+
if (!this.transform)
|
|
140
|
+
return;
|
|
141
|
+
const currentMousePos = isHorizontal ? e2.clientX : e2.clientY;
|
|
142
|
+
const deltaMouse = currentMousePos - startMousePos;
|
|
143
|
+
const deltaScroll = deltaMouse * ratio;
|
|
144
|
+
const newScroll = Math.max(0, Math.min(maxScroll, startScrollPos + deltaScroll));
|
|
145
|
+
if (isHorizontal) {
|
|
146
|
+
this.callTool("canvas", "setTransform", {
|
|
147
|
+
positionX: -newScroll,
|
|
148
|
+
positionY: this.transform.positionY,
|
|
149
|
+
scale: this.transform.scale,
|
|
150
|
+
animationTime: 0
|
|
151
|
+
});
|
|
152
|
+
} else {
|
|
153
|
+
this.callTool("canvas", "setTransform", {
|
|
154
|
+
positionX: this.transform.positionX,
|
|
155
|
+
positionY: -newScroll,
|
|
156
|
+
scale: this.transform.scale,
|
|
157
|
+
animationTime: 0
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
rafId = null;
|
|
161
|
+
});
|
|
153
162
|
};
|
|
154
163
|
const handleMouseUp = () => {
|
|
164
|
+
if (rafId) {
|
|
165
|
+
cancelAnimationFrame(rafId);
|
|
166
|
+
rafId = null;
|
|
167
|
+
}
|
|
155
168
|
this.isDraggingHorizontal = false;
|
|
156
169
|
this.isDraggingVertical = false;
|
|
157
170
|
document.removeEventListener("mousemove", handleMouseMove);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knotx/plugins-canvas-scrollbar",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.8",
|
|
4
4
|
"description": "Canvas Scrollbar Plugin for Knotx",
|
|
5
5
|
"author": "boenfu",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,21 +29,21 @@
|
|
|
29
29
|
],
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"react": ">=17.0.0",
|
|
32
|
-
"@knotx/jsx": "0.5.
|
|
33
|
-
"@knotx/plugins-canvas": "0.5.
|
|
32
|
+
"@knotx/jsx": "0.5.8",
|
|
33
|
+
"@knotx/plugins-canvas": "0.5.8"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@knotx/core": "0.5.
|
|
37
|
-
"@knotx/decorators": "0.5.
|
|
36
|
+
"@knotx/core": "0.5.8",
|
|
37
|
+
"@knotx/decorators": "0.5.8"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/react": "^17.0.0",
|
|
41
41
|
"react": "^17.0.0",
|
|
42
|
-
"@knotx/build-config": "0.5.
|
|
43
|
-
"@knotx/eslint-config": "0.5.
|
|
44
|
-
"@knotx/jsx": "0.5.
|
|
45
|
-
"@knotx/plugins-canvas": "0.5.
|
|
46
|
-
"@knotx/typescript-config": "0.5.
|
|
42
|
+
"@knotx/build-config": "0.5.8",
|
|
43
|
+
"@knotx/eslint-config": "0.5.8",
|
|
44
|
+
"@knotx/jsx": "0.5.8",
|
|
45
|
+
"@knotx/plugins-canvas": "0.5.8",
|
|
46
|
+
"@knotx/typescript-config": "0.5.8"
|
|
47
47
|
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"build": "unbuild",
|