@knotx/plugins-canvas-scrollbar 0.4.6

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 格桑
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.cjs ADDED
@@ -0,0 +1,377 @@
1
+ 'use strict';
2
+
3
+ const jsxRuntime = require('@knotx/jsx/jsx-runtime');
4
+ const core = require('@knotx/core');
5
+ const decorators = require('@knotx/decorators');
6
+ const react = require('react');
7
+
8
+ var __create = Object.create;
9
+ var __defProp = Object.defineProperty;
10
+ var __defProps = Object.defineProperties;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
13
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
14
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
15
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
16
+ var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
17
+ var __typeError = (msg) => {
18
+ throw TypeError(msg);
19
+ };
20
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
21
+ var __spreadValues = (a, b) => {
22
+ for (var prop in b || (b = {}))
23
+ if (__hasOwnProp.call(b, prop))
24
+ __defNormalProp(a, prop, b[prop]);
25
+ if (__getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(b)) {
27
+ if (__propIsEnum.call(b, prop))
28
+ __defNormalProp(a, prop, b[prop]);
29
+ }
30
+ return a;
31
+ };
32
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
33
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
34
+ var __decoratorStart = (base) => {
35
+ var _a2;
36
+ return [, , , __create((_a2 = base == null ? void 0 : base[__knownSymbol("metadata")]) != null ? _a2 : null)];
37
+ };
38
+ var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
39
+ var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
40
+ var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
41
+ var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
42
+ var __runInitializers = (array, flags, self, value) => {
43
+ for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
44
+ return value;
45
+ };
46
+ var __decorateElement = (array, flags, name, decorators, target, extra) => {
47
+ var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
48
+ var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
49
+ var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
50
+ var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
51
+ return __privateGet(this, extra);
52
+ }, set [name](x) {
53
+ return __privateSet(this, extra, x);
54
+ } }, name));
55
+ k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
56
+ for (var i = decorators.length - 1; i >= 0; i--) {
57
+ ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
58
+ if (k) {
59
+ ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
60
+ if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
61
+ if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
62
+ }
63
+ it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
64
+ if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
65
+ else if (typeof it !== "object" || it === null) __typeError("Object expected");
66
+ else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
67
+ }
68
+ return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
69
+ };
70
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
71
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
72
+ var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
73
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
74
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
75
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
76
+ var _render_dec, _init_dec, _addListener_dec, _transform_dec, _contentSize_dec, _container_dec, _showScrollbars_dec, _a, _init;
77
+ const defaultProps = {
78
+ style: {
79
+ track: {},
80
+ thumb: {}
81
+ },
82
+ offset: 3,
83
+ size: 8,
84
+ minThumbSize: 30,
85
+ hideTimeout: 0
86
+ };
87
+ class CanvasScrollbar extends (_a = core.BasePlugin, _showScrollbars_dec = [decorators.observable()], _container_dec = [decorators.inject.container()], _contentSize_dec = [decorators.inject.canvas.contentSize()], _transform_dec = [decorators.inject.canvas.transform()], _addListener_dec = [decorators.inject.canvas.addListener()], _init_dec = [decorators.OnInit], _render_dec = [decorators.layer(core.Layer.Canvas)], _a) {
88
+ constructor() {
89
+ super(...arguments);
90
+ __runInitializers(_init, 5, this);
91
+ __publicField(this, "config");
92
+ __publicField(this, "scrollbarTimeout", null);
93
+ __publicField(this, "isDraggingHorizontal", false);
94
+ __publicField(this, "isDraggingVertical", false);
95
+ __publicField(this, "startDragPos", { x: 0, y: 0 });
96
+ __publicField(this, "startScrollPos", { x: 0, y: 0 });
97
+ __publicField(this, "name", "canvasScrollbar");
98
+ __publicField(this, "showScrollbars", __runInitializers(_init, 8, this, false)), __runInitializers(_init, 11, this);
99
+ __publicField(this, "container", __runInitializers(_init, 12, this)), __runInitializers(_init, 15, this);
100
+ __publicField(this, "contentSize", __runInitializers(_init, 16, this)), __runInitializers(_init, 19, this);
101
+ __publicField(this, "transform", __runInitializers(_init, 20, this)), __runInitializers(_init, 23, this);
102
+ __publicField(this, "addListener", __runInitializers(_init, 24, this)), __runInitializers(_init, 27, this);
103
+ // 滚动条拖拽事件处理
104
+ __publicField(this, "handleMouseDown", (e, type) => {
105
+ e.preventDefault();
106
+ e.stopPropagation();
107
+ if (type === "horizontal") {
108
+ this.isDraggingHorizontal = true;
109
+ this.startDragPos.x = e.clientX;
110
+ this.startScrollPos.x = -this.transform.positionX;
111
+ } else {
112
+ this.isDraggingVertical = true;
113
+ this.startDragPos.y = e.clientY;
114
+ this.startScrollPos.y = -this.transform.positionY;
115
+ }
116
+ const handleMouseMove = (e2) => {
117
+ if (!this.transform || !this.contentSize)
118
+ return;
119
+ if (this.isDraggingHorizontal) {
120
+ const horizontalTracker = this.getScrollTracker("horizontal");
121
+ const horizontalThumb = this.getScrollThumb("vertical");
122
+ const trackWidth = (horizontalTracker == null ? void 0 : horizontalTracker.clientWidth) || 0;
123
+ const thumbWidth = (horizontalThumb == null ? void 0 : horizontalThumb.clientWidth) || 0;
124
+ const contentWidth = this.contentSize.width * this.transform.scale;
125
+ const maxScroll = contentWidth - this.container.width;
126
+ const deltaX = e2.clientX - this.startDragPos.x;
127
+ const deltaScrollPercentage = deltaX / (trackWidth - thumbWidth);
128
+ const deltaScroll = deltaScrollPercentage * maxScroll;
129
+ const newScrollX = Math.max(0, Math.min(maxScroll, this.startScrollPos.x + deltaScroll));
130
+ this.callTool("canvas", "setTransform", {
131
+ positionX: -newScrollX,
132
+ positionY: this.transform.positionY,
133
+ scale: this.transform.scale,
134
+ animationTime: 0
135
+ });
136
+ }
137
+ if (this.isDraggingVertical) {
138
+ const verticalTracker = this.getScrollTracker("vertical");
139
+ const verticalThumb = this.getScrollThumb("vertical");
140
+ const trackHeight = (verticalTracker == null ? void 0 : verticalTracker.clientHeight) || 0;
141
+ const thumbHeight = (verticalThumb == null ? void 0 : verticalThumb.clientHeight) || 0;
142
+ const contentHeight = this.contentSize.height * this.transform.scale;
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
+ }
155
+ };
156
+ const handleMouseUp = () => {
157
+ this.isDraggingHorizontal = false;
158
+ this.isDraggingVertical = false;
159
+ document.removeEventListener("mousemove", handleMouseMove);
160
+ document.removeEventListener("mouseup", handleMouseUp);
161
+ };
162
+ document.addEventListener("mousemove", handleMouseMove);
163
+ document.addEventListener("mouseup", handleMouseUp);
164
+ });
165
+ // 滚动条轨道点击事件
166
+ __publicField(this, "handleTrackerClick", (e, direction) => {
167
+ const horizontalTracker = this.getScrollTracker("horizontal");
168
+ const verticalTracker = this.getScrollTracker("vertical");
169
+ const horizontalThumb = this.getScrollThumb("horizontal");
170
+ const verticalThumb = this.getScrollThumb("vertical");
171
+ if (direction === "horizontal" && e.target === horizontalThumb || direction === "vertical" && e.target === verticalThumb) {
172
+ return;
173
+ }
174
+ if (!this.contentSize)
175
+ return;
176
+ if (direction === "horizontal" && horizontalTracker && horizontalThumb) {
177
+ const trackRect = horizontalTracker.getBoundingClientRect();
178
+ const thumbRect = horizontalThumb.getBoundingClientRect();
179
+ const clickPosition = e.clientX - trackRect.left;
180
+ const thumbHalfWidth = thumbRect.width / 2;
181
+ const trackWidth = trackRect.width;
182
+ const contentWidth = this.contentSize.width * this.transform.scale;
183
+ const maxScroll = contentWidth - this.container.width;
184
+ const clickPercentage = (clickPosition - thumbHalfWidth) / (trackWidth - thumbRect.width);
185
+ const newScrollX = Math.max(0, Math.min(maxScroll, clickPercentage * maxScroll));
186
+ this.callTool("canvas", "setTransform", {
187
+ positionX: -newScrollX,
188
+ positionY: this.transform.positionY,
189
+ scale: this.transform.scale
190
+ });
191
+ }
192
+ if (direction === "vertical" && verticalTracker && verticalThumb) {
193
+ const trackRect = verticalTracker.getBoundingClientRect();
194
+ const thumbRect = verticalThumb.getBoundingClientRect();
195
+ const clickPosition = e.clientY - trackRect.top;
196
+ const thumbHalfHeight = thumbRect.height / 2;
197
+ const trackHeight = trackRect.height;
198
+ const contentHeight = this.contentSize.height * this.transform.scale;
199
+ const maxScroll = contentHeight - this.container.height;
200
+ const clickPercentage = (clickPosition - thumbHalfHeight) / (trackHeight - thumbRect.height);
201
+ const newScrollY = Math.max(0, Math.min(maxScroll, clickPercentage * maxScroll));
202
+ this.callTool("canvas", "setTransform", {
203
+ positionX: this.transform.positionX,
204
+ positionY: -newScrollY,
205
+ scale: this.transform.scale
206
+ });
207
+ }
208
+ });
209
+ __publicField(this, "getScrollTracker", (direction) => {
210
+ return document.querySelector(`[data-plugin-id="${this.pluginId}"][data-tracker-type="${direction}"]`);
211
+ });
212
+ __publicField(this, "getScrollThumb", (direction) => {
213
+ return document.querySelector(`[data-plugin-id="${this.pluginId}"][data-thumb-type="${direction}"]`);
214
+ });
215
+ __publicField(this, "handleMouseEnter", () => {
216
+ this.showScrollbars = true;
217
+ if (this.scrollbarTimeout) {
218
+ clearTimeout(this.scrollbarTimeout);
219
+ this.scrollbarTimeout = null;
220
+ }
221
+ });
222
+ __publicField(this, "handleMouseLeave", () => {
223
+ if (this.scrollbarTimeout) {
224
+ clearTimeout(this.scrollbarTimeout);
225
+ }
226
+ this.scrollbarTimeout = window.setTimeout(() => {
227
+ this.showScrollbars = false;
228
+ }, this.config.hideTimeout);
229
+ });
230
+ }
231
+ init(config) {
232
+ this.config = __spreadValues(__spreadValues({}, defaultProps), config);
233
+ this.addListener("mouseenter", this.handleMouseEnter);
234
+ this.addListener("mouseleave", this.handleMouseLeave);
235
+ }
236
+ // 更新滚动条位置与状态
237
+ getUpdatedScrollbarsStyle(config, container, transform, contentSize, showScrollbars) {
238
+ if (!contentSize) {
239
+ return [void 0, void 0];
240
+ }
241
+ const basicTrackStyle = __spreadValues({
242
+ position: "absolute",
243
+ borderRadius: "6px",
244
+ backgroundColor: "rgba(0, 0, 0, 0.1)",
245
+ transition: showScrollbars ? "opacity 0.2s" : "opacity 0.2s",
246
+ pointerEvents: showScrollbars ? "auto" : "none",
247
+ opacity: showScrollbars ? 0.6 : 0,
248
+ zIndex: core.Layer.Foreground
249
+ }, config.style.track);
250
+ const basicThumbStyle = __spreadValues({
251
+ position: "absolute",
252
+ borderRadius: "6px",
253
+ backgroundColor: "rgba(0, 0, 0, 0.5)",
254
+ cursor: "pointer",
255
+ transition: "background-color 0.2s"
256
+ }, config.style.thumb);
257
+ const { scale, positionX, positionY } = transform;
258
+ let [horizontalStyle, verticalStyle] = [void 0, void 0];
259
+ const contentWidth = contentSize.width * scale;
260
+ if (container.width < contentWidth) {
261
+ const thumbWidthPercentage = Math.min(1, container.width / contentWidth);
262
+ const thumbWidth = Math.max(config.minThumbSize, container.width * thumbWidthPercentage);
263
+ const maxScrollX = contentWidth - container.width;
264
+ const scrollPercentage = maxScrollX > 0 ? Math.max(0, Math.min(1, -positionX / maxScrollX)) : 0;
265
+ const maxThumbOffset = container.width - thumbWidth;
266
+ const horizontalThumbOffset = scrollPercentage * maxThumbOffset;
267
+ horizontalStyle = {
268
+ track: __spreadProps(__spreadValues({}, basicTrackStyle), {
269
+ bottom: 0,
270
+ left: 0,
271
+ right: 0,
272
+ height: config.size
273
+ }),
274
+ thumb: __spreadProps(__spreadValues({}, basicThumbStyle), {
275
+ transform: `translateX(${horizontalThumbOffset}px)`,
276
+ height: "100%",
277
+ width: `${thumbWidth}px`
278
+ })
279
+ };
280
+ }
281
+ const contentHeight = contentSize.height * scale;
282
+ if (container.height < contentHeight) {
283
+ const thumbHeightPercentage = Math.min(1, container.height / contentHeight);
284
+ const thumbHeight = Math.max(config.minThumbSize, container.height * thumbHeightPercentage);
285
+ const maxScrollY = contentHeight - container.height;
286
+ const scrollPercentage = maxScrollY > 0 ? Math.max(0, Math.min(1, -positionY / maxScrollY)) : 0;
287
+ const maxThumbOffset = container.height - thumbHeight;
288
+ const verticalThumbOffset = scrollPercentage * maxThumbOffset;
289
+ verticalStyle = {
290
+ track: __spreadProps(__spreadValues({}, basicTrackStyle), {
291
+ top: 0,
292
+ right: 0,
293
+ bottom: 0,
294
+ width: config.size
295
+ }),
296
+ thumb: __spreadProps(__spreadValues({}, basicThumbStyle), {
297
+ transform: `translateY(${verticalThumbOffset}px)`,
298
+ height: `${thumbHeight}px`,
299
+ width: "100%"
300
+ })
301
+ };
302
+ }
303
+ return [horizontalStyle, verticalStyle];
304
+ }
305
+ render({ children } = { children: null }) {
306
+ const config = core.use(() => this.config);
307
+ const container = core.use(() => this.container);
308
+ const transform = core.use(() => this.transform);
309
+ const contentSize = core.use(() => this.contentSize);
310
+ const showScrollbars = core.use(() => this.showScrollbars);
311
+ const [horizontalStyle, verticalStyle] = this.getUpdatedScrollbarsStyle(
312
+ config,
313
+ container,
314
+ transform,
315
+ contentSize,
316
+ showScrollbars
317
+ );
318
+ return /* @__PURE__ */ jsxRuntime.jsxs(react.Fragment, { children: [
319
+ children,
320
+ horizontalStyle && /* @__PURE__ */ jsxRuntime.jsx(
321
+ "div",
322
+ {
323
+ "data-plugin-id": this.pluginId,
324
+ "data-tracker-type": "horizontal",
325
+ className: core.bem(this.name, "track-horizontal"),
326
+ style: horizontalStyle.track,
327
+ onClick: (e) => this.handleTrackerClick(e, "horizontal"),
328
+ onMouseEnter: this.handleMouseEnter,
329
+ onMouseLeave: this.handleMouseLeave,
330
+ children: /* @__PURE__ */ jsxRuntime.jsx(
331
+ "div",
332
+ {
333
+ "data-plugin-id": this.pluginId,
334
+ "data-thumb-type": "horizontal",
335
+ className: core.bem(this.name, "thumb-horizontal"),
336
+ style: horizontalStyle.thumb,
337
+ onMouseDown: (e) => this.handleMouseDown(e, "horizontal")
338
+ }
339
+ )
340
+ }
341
+ ),
342
+ verticalStyle && /* @__PURE__ */ jsxRuntime.jsx(
343
+ "div",
344
+ {
345
+ "data-plugin-id": this.pluginId,
346
+ "data-tracker-type": "vertical",
347
+ className: core.bem(this.name, "track-vertical"),
348
+ style: verticalStyle.track,
349
+ onClick: (e) => this.handleTrackerClick(e, "vertical"),
350
+ onMouseEnter: this.handleMouseEnter,
351
+ onMouseLeave: this.handleMouseLeave,
352
+ children: /* @__PURE__ */ jsxRuntime.jsx(
353
+ "div",
354
+ {
355
+ "data-plugin-id": this.pluginId,
356
+ "data-thumb-type": "vertical",
357
+ className: core.bem(this.name, "thumb-vertical"),
358
+ style: verticalStyle.thumb,
359
+ onMouseDown: (e) => this.handleMouseDown(e, "vertical")
360
+ }
361
+ )
362
+ }
363
+ )
364
+ ] });
365
+ }
366
+ }
367
+ _init = __decoratorStart(_a);
368
+ __decorateElement(_init, 1, "init", _init_dec, CanvasScrollbar);
369
+ __decorateElement(_init, 1, "render", _render_dec, CanvasScrollbar);
370
+ __decorateElement(_init, 5, "showScrollbars", _showScrollbars_dec, CanvasScrollbar);
371
+ __decorateElement(_init, 5, "container", _container_dec, CanvasScrollbar);
372
+ __decorateElement(_init, 5, "contentSize", _contentSize_dec, CanvasScrollbar);
373
+ __decorateElement(_init, 5, "transform", _transform_dec, CanvasScrollbar);
374
+ __decorateElement(_init, 5, "addListener", _addListener_dec, CanvasScrollbar);
375
+ __decoratorMetadata(_init, CanvasScrollbar);
376
+
377
+ exports.CanvasScrollbar = CanvasScrollbar;
@@ -0,0 +1,57 @@
1
+ import { BasePlugin, Container, PluginData } from '@knotx/core';
2
+ import { CanvasEventType, CanvasEventListener } from '@knotx/plugins-canvas';
3
+ import { CSSProperties, ReactNode } from 'react';
4
+
5
+ interface ScrollbarStyle {
6
+ track: CSSProperties;
7
+ thumb: CSSProperties;
8
+ }
9
+ interface CanvasScrollbarConfig {
10
+ /**
11
+ * 轨道以及滑块的css样式
12
+ */
13
+ style?: ScrollbarStyle;
14
+ /**
15
+ * 轨道以及滑块的宽度/高度
16
+ */
17
+ size?: number;
18
+ /**
19
+ * 距离边界的距离
20
+ */
21
+ offset?: number;
22
+ /**
23
+ * 滑块的最小宽度/高度
24
+ */
25
+ minThumbSize?: number;
26
+ /**
27
+ * 滚动条消失延迟
28
+ */
29
+ hideTimeout?: number;
30
+ }
31
+ declare class CanvasScrollbar extends BasePlugin<'canvasScrollbar', CanvasScrollbarConfig> {
32
+ private config;
33
+ private scrollbarTimeout;
34
+ private isDraggingHorizontal;
35
+ private isDraggingVertical;
36
+ private startDragPos;
37
+ private startScrollPos;
38
+ name: "canvasScrollbar";
39
+ showScrollbars: boolean;
40
+ container: Container;
41
+ contentSize: PluginData['canvas']['contentSize'];
42
+ transform: PluginData['canvas']['transform'];
43
+ addListener: (type: CanvasEventType, listener: CanvasEventListener) => void;
44
+ init(config: CanvasScrollbarConfig): void;
45
+ private getUpdatedScrollbarsStyle;
46
+ private handleMouseDown;
47
+ private handleTrackerClick;
48
+ private getScrollTracker;
49
+ private getScrollThumb;
50
+ render({ children }?: {
51
+ children: ReactNode;
52
+ }): JSX.Element;
53
+ private handleMouseEnter;
54
+ private handleMouseLeave;
55
+ }
56
+
57
+ export { CanvasScrollbar, type CanvasScrollbarConfig, type ScrollbarStyle };
@@ -0,0 +1,57 @@
1
+ import { BasePlugin, Container, PluginData } from '@knotx/core';
2
+ import { CanvasEventType, CanvasEventListener } from '@knotx/plugins-canvas';
3
+ import { CSSProperties, ReactNode } from 'react';
4
+
5
+ interface ScrollbarStyle {
6
+ track: CSSProperties;
7
+ thumb: CSSProperties;
8
+ }
9
+ interface CanvasScrollbarConfig {
10
+ /**
11
+ * 轨道以及滑块的css样式
12
+ */
13
+ style?: ScrollbarStyle;
14
+ /**
15
+ * 轨道以及滑块的宽度/高度
16
+ */
17
+ size?: number;
18
+ /**
19
+ * 距离边界的距离
20
+ */
21
+ offset?: number;
22
+ /**
23
+ * 滑块的最小宽度/高度
24
+ */
25
+ minThumbSize?: number;
26
+ /**
27
+ * 滚动条消失延迟
28
+ */
29
+ hideTimeout?: number;
30
+ }
31
+ declare class CanvasScrollbar extends BasePlugin<'canvasScrollbar', CanvasScrollbarConfig> {
32
+ private config;
33
+ private scrollbarTimeout;
34
+ private isDraggingHorizontal;
35
+ private isDraggingVertical;
36
+ private startDragPos;
37
+ private startScrollPos;
38
+ name: "canvasScrollbar";
39
+ showScrollbars: boolean;
40
+ container: Container;
41
+ contentSize: PluginData['canvas']['contentSize'];
42
+ transform: PluginData['canvas']['transform'];
43
+ addListener: (type: CanvasEventType, listener: CanvasEventListener) => void;
44
+ init(config: CanvasScrollbarConfig): void;
45
+ private getUpdatedScrollbarsStyle;
46
+ private handleMouseDown;
47
+ private handleTrackerClick;
48
+ private getScrollTracker;
49
+ private getScrollThumb;
50
+ render({ children }?: {
51
+ children: ReactNode;
52
+ }): JSX.Element;
53
+ private handleMouseEnter;
54
+ private handleMouseLeave;
55
+ }
56
+
57
+ export { CanvasScrollbar, type CanvasScrollbarConfig, type ScrollbarStyle };
@@ -0,0 +1,57 @@
1
+ import { BasePlugin, Container, PluginData } from '@knotx/core';
2
+ import { CanvasEventType, CanvasEventListener } from '@knotx/plugins-canvas';
3
+ import { CSSProperties, ReactNode } from 'react';
4
+
5
+ interface ScrollbarStyle {
6
+ track: CSSProperties;
7
+ thumb: CSSProperties;
8
+ }
9
+ interface CanvasScrollbarConfig {
10
+ /**
11
+ * 轨道以及滑块的css样式
12
+ */
13
+ style?: ScrollbarStyle;
14
+ /**
15
+ * 轨道以及滑块的宽度/高度
16
+ */
17
+ size?: number;
18
+ /**
19
+ * 距离边界的距离
20
+ */
21
+ offset?: number;
22
+ /**
23
+ * 滑块的最小宽度/高度
24
+ */
25
+ minThumbSize?: number;
26
+ /**
27
+ * 滚动条消失延迟
28
+ */
29
+ hideTimeout?: number;
30
+ }
31
+ declare class CanvasScrollbar extends BasePlugin<'canvasScrollbar', CanvasScrollbarConfig> {
32
+ private config;
33
+ private scrollbarTimeout;
34
+ private isDraggingHorizontal;
35
+ private isDraggingVertical;
36
+ private startDragPos;
37
+ private startScrollPos;
38
+ name: "canvasScrollbar";
39
+ showScrollbars: boolean;
40
+ container: Container;
41
+ contentSize: PluginData['canvas']['contentSize'];
42
+ transform: PluginData['canvas']['transform'];
43
+ addListener: (type: CanvasEventType, listener: CanvasEventListener) => void;
44
+ init(config: CanvasScrollbarConfig): void;
45
+ private getUpdatedScrollbarsStyle;
46
+ private handleMouseDown;
47
+ private handleTrackerClick;
48
+ private getScrollTracker;
49
+ private getScrollThumb;
50
+ render({ children }?: {
51
+ children: ReactNode;
52
+ }): JSX.Element;
53
+ private handleMouseEnter;
54
+ private handleMouseLeave;
55
+ }
56
+
57
+ export { CanvasScrollbar, type CanvasScrollbarConfig, type ScrollbarStyle };
package/dist/index.js ADDED
@@ -0,0 +1,375 @@
1
+ import { jsxs, jsx } from '@knotx/jsx/jsx-runtime';
2
+ import { Layer, use, bem, BasePlugin } from '@knotx/core';
3
+ import { observable, inject, layer, OnInit } from '@knotx/decorators';
4
+ import { Fragment } from 'react';
5
+
6
+ var __create = Object.create;
7
+ var __defProp = Object.defineProperty;
8
+ var __defProps = Object.defineProperties;
9
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
10
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
11
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
12
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
13
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
14
+ var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
15
+ var __typeError = (msg) => {
16
+ throw TypeError(msg);
17
+ };
18
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
19
+ var __spreadValues = (a, b) => {
20
+ for (var prop in b || (b = {}))
21
+ if (__hasOwnProp.call(b, prop))
22
+ __defNormalProp(a, prop, b[prop]);
23
+ if (__getOwnPropSymbols)
24
+ for (var prop of __getOwnPropSymbols(b)) {
25
+ if (__propIsEnum.call(b, prop))
26
+ __defNormalProp(a, prop, b[prop]);
27
+ }
28
+ return a;
29
+ };
30
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
31
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
32
+ var __decoratorStart = (base) => {
33
+ var _a2;
34
+ return [, , , __create((_a2 = base == null ? void 0 : base[__knownSymbol("metadata")]) != null ? _a2 : null)];
35
+ };
36
+ var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
37
+ var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
38
+ var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
39
+ var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
40
+ var __runInitializers = (array, flags, self, value) => {
41
+ for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
42
+ return value;
43
+ };
44
+ var __decorateElement = (array, flags, name, decorators, target, extra) => {
45
+ var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
46
+ var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
47
+ var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
48
+ var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
49
+ return __privateGet(this, extra);
50
+ }, set [name](x) {
51
+ return __privateSet(this, extra, x);
52
+ } }, name));
53
+ k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
54
+ for (var i = decorators.length - 1; i >= 0; i--) {
55
+ ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
56
+ if (k) {
57
+ ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
58
+ if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
59
+ if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
60
+ }
61
+ it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
62
+ if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
63
+ else if (typeof it !== "object" || it === null) __typeError("Object expected");
64
+ else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
65
+ }
66
+ return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
67
+ };
68
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
69
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
70
+ var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
71
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
72
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
73
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
74
+ var _render_dec, _init_dec, _addListener_dec, _transform_dec, _contentSize_dec, _container_dec, _showScrollbars_dec, _a, _init;
75
+ const defaultProps = {
76
+ style: {
77
+ track: {},
78
+ thumb: {}
79
+ },
80
+ offset: 3,
81
+ size: 8,
82
+ minThumbSize: 30,
83
+ hideTimeout: 0
84
+ };
85
+ class CanvasScrollbar extends (_a = BasePlugin, _showScrollbars_dec = [observable()], _container_dec = [inject.container()], _contentSize_dec = [inject.canvas.contentSize()], _transform_dec = [inject.canvas.transform()], _addListener_dec = [inject.canvas.addListener()], _init_dec = [OnInit], _render_dec = [layer(Layer.Canvas)], _a) {
86
+ constructor() {
87
+ super(...arguments);
88
+ __runInitializers(_init, 5, this);
89
+ __publicField(this, "config");
90
+ __publicField(this, "scrollbarTimeout", null);
91
+ __publicField(this, "isDraggingHorizontal", false);
92
+ __publicField(this, "isDraggingVertical", false);
93
+ __publicField(this, "startDragPos", { x: 0, y: 0 });
94
+ __publicField(this, "startScrollPos", { x: 0, y: 0 });
95
+ __publicField(this, "name", "canvasScrollbar");
96
+ __publicField(this, "showScrollbars", __runInitializers(_init, 8, this, false)), __runInitializers(_init, 11, this);
97
+ __publicField(this, "container", __runInitializers(_init, 12, this)), __runInitializers(_init, 15, this);
98
+ __publicField(this, "contentSize", __runInitializers(_init, 16, this)), __runInitializers(_init, 19, this);
99
+ __publicField(this, "transform", __runInitializers(_init, 20, this)), __runInitializers(_init, 23, this);
100
+ __publicField(this, "addListener", __runInitializers(_init, 24, this)), __runInitializers(_init, 27, this);
101
+ // 滚动条拖拽事件处理
102
+ __publicField(this, "handleMouseDown", (e, type) => {
103
+ e.preventDefault();
104
+ e.stopPropagation();
105
+ if (type === "horizontal") {
106
+ this.isDraggingHorizontal = true;
107
+ this.startDragPos.x = e.clientX;
108
+ this.startScrollPos.x = -this.transform.positionX;
109
+ } else {
110
+ this.isDraggingVertical = true;
111
+ this.startDragPos.y = e.clientY;
112
+ this.startScrollPos.y = -this.transform.positionY;
113
+ }
114
+ const handleMouseMove = (e2) => {
115
+ if (!this.transform || !this.contentSize)
116
+ return;
117
+ if (this.isDraggingHorizontal) {
118
+ const horizontalTracker = this.getScrollTracker("horizontal");
119
+ const horizontalThumb = this.getScrollThumb("vertical");
120
+ const trackWidth = (horizontalTracker == null ? void 0 : horizontalTracker.clientWidth) || 0;
121
+ const thumbWidth = (horizontalThumb == null ? void 0 : horizontalThumb.clientWidth) || 0;
122
+ const contentWidth = this.contentSize.width * this.transform.scale;
123
+ const maxScroll = contentWidth - this.container.width;
124
+ const deltaX = e2.clientX - this.startDragPos.x;
125
+ const deltaScrollPercentage = deltaX / (trackWidth - thumbWidth);
126
+ const deltaScroll = deltaScrollPercentage * maxScroll;
127
+ const newScrollX = Math.max(0, Math.min(maxScroll, this.startScrollPos.x + deltaScroll));
128
+ this.callTool("canvas", "setTransform", {
129
+ positionX: -newScrollX,
130
+ positionY: this.transform.positionY,
131
+ scale: this.transform.scale,
132
+ animationTime: 0
133
+ });
134
+ }
135
+ if (this.isDraggingVertical) {
136
+ const verticalTracker = this.getScrollTracker("vertical");
137
+ const verticalThumb = this.getScrollThumb("vertical");
138
+ const trackHeight = (verticalTracker == null ? void 0 : verticalTracker.clientHeight) || 0;
139
+ const thumbHeight = (verticalThumb == null ? void 0 : verticalThumb.clientHeight) || 0;
140
+ const contentHeight = this.contentSize.height * this.transform.scale;
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
+ }
153
+ };
154
+ const handleMouseUp = () => {
155
+ this.isDraggingHorizontal = false;
156
+ this.isDraggingVertical = false;
157
+ document.removeEventListener("mousemove", handleMouseMove);
158
+ document.removeEventListener("mouseup", handleMouseUp);
159
+ };
160
+ document.addEventListener("mousemove", handleMouseMove);
161
+ document.addEventListener("mouseup", handleMouseUp);
162
+ });
163
+ // 滚动条轨道点击事件
164
+ __publicField(this, "handleTrackerClick", (e, direction) => {
165
+ const horizontalTracker = this.getScrollTracker("horizontal");
166
+ const verticalTracker = this.getScrollTracker("vertical");
167
+ const horizontalThumb = this.getScrollThumb("horizontal");
168
+ const verticalThumb = this.getScrollThumb("vertical");
169
+ if (direction === "horizontal" && e.target === horizontalThumb || direction === "vertical" && e.target === verticalThumb) {
170
+ return;
171
+ }
172
+ if (!this.contentSize)
173
+ return;
174
+ if (direction === "horizontal" && horizontalTracker && horizontalThumb) {
175
+ const trackRect = horizontalTracker.getBoundingClientRect();
176
+ const thumbRect = horizontalThumb.getBoundingClientRect();
177
+ const clickPosition = e.clientX - trackRect.left;
178
+ const thumbHalfWidth = thumbRect.width / 2;
179
+ const trackWidth = trackRect.width;
180
+ const contentWidth = this.contentSize.width * this.transform.scale;
181
+ const maxScroll = contentWidth - this.container.width;
182
+ const clickPercentage = (clickPosition - thumbHalfWidth) / (trackWidth - thumbRect.width);
183
+ const newScrollX = Math.max(0, Math.min(maxScroll, clickPercentage * maxScroll));
184
+ this.callTool("canvas", "setTransform", {
185
+ positionX: -newScrollX,
186
+ positionY: this.transform.positionY,
187
+ scale: this.transform.scale
188
+ });
189
+ }
190
+ if (direction === "vertical" && verticalTracker && verticalThumb) {
191
+ const trackRect = verticalTracker.getBoundingClientRect();
192
+ const thumbRect = verticalThumb.getBoundingClientRect();
193
+ const clickPosition = e.clientY - trackRect.top;
194
+ const thumbHalfHeight = thumbRect.height / 2;
195
+ const trackHeight = trackRect.height;
196
+ const contentHeight = this.contentSize.height * this.transform.scale;
197
+ const maxScroll = contentHeight - this.container.height;
198
+ const clickPercentage = (clickPosition - thumbHalfHeight) / (trackHeight - thumbRect.height);
199
+ const newScrollY = Math.max(0, Math.min(maxScroll, clickPercentage * maxScroll));
200
+ this.callTool("canvas", "setTransform", {
201
+ positionX: this.transform.positionX,
202
+ positionY: -newScrollY,
203
+ scale: this.transform.scale
204
+ });
205
+ }
206
+ });
207
+ __publicField(this, "getScrollTracker", (direction) => {
208
+ return document.querySelector(`[data-plugin-id="${this.pluginId}"][data-tracker-type="${direction}"]`);
209
+ });
210
+ __publicField(this, "getScrollThumb", (direction) => {
211
+ return document.querySelector(`[data-plugin-id="${this.pluginId}"][data-thumb-type="${direction}"]`);
212
+ });
213
+ __publicField(this, "handleMouseEnter", () => {
214
+ this.showScrollbars = true;
215
+ if (this.scrollbarTimeout) {
216
+ clearTimeout(this.scrollbarTimeout);
217
+ this.scrollbarTimeout = null;
218
+ }
219
+ });
220
+ __publicField(this, "handleMouseLeave", () => {
221
+ if (this.scrollbarTimeout) {
222
+ clearTimeout(this.scrollbarTimeout);
223
+ }
224
+ this.scrollbarTimeout = window.setTimeout(() => {
225
+ this.showScrollbars = false;
226
+ }, this.config.hideTimeout);
227
+ });
228
+ }
229
+ init(config) {
230
+ this.config = __spreadValues(__spreadValues({}, defaultProps), config);
231
+ this.addListener("mouseenter", this.handleMouseEnter);
232
+ this.addListener("mouseleave", this.handleMouseLeave);
233
+ }
234
+ // 更新滚动条位置与状态
235
+ getUpdatedScrollbarsStyle(config, container, transform, contentSize, showScrollbars) {
236
+ if (!contentSize) {
237
+ return [void 0, void 0];
238
+ }
239
+ const basicTrackStyle = __spreadValues({
240
+ position: "absolute",
241
+ borderRadius: "6px",
242
+ backgroundColor: "rgba(0, 0, 0, 0.1)",
243
+ transition: showScrollbars ? "opacity 0.2s" : "opacity 0.2s",
244
+ pointerEvents: showScrollbars ? "auto" : "none",
245
+ opacity: showScrollbars ? 0.6 : 0,
246
+ zIndex: Layer.Foreground
247
+ }, config.style.track);
248
+ const basicThumbStyle = __spreadValues({
249
+ position: "absolute",
250
+ borderRadius: "6px",
251
+ backgroundColor: "rgba(0, 0, 0, 0.5)",
252
+ cursor: "pointer",
253
+ transition: "background-color 0.2s"
254
+ }, config.style.thumb);
255
+ const { scale, positionX, positionY } = transform;
256
+ let [horizontalStyle, verticalStyle] = [void 0, void 0];
257
+ const contentWidth = contentSize.width * scale;
258
+ if (container.width < contentWidth) {
259
+ const thumbWidthPercentage = Math.min(1, container.width / contentWidth);
260
+ const thumbWidth = Math.max(config.minThumbSize, container.width * thumbWidthPercentage);
261
+ const maxScrollX = contentWidth - container.width;
262
+ const scrollPercentage = maxScrollX > 0 ? Math.max(0, Math.min(1, -positionX / maxScrollX)) : 0;
263
+ const maxThumbOffset = container.width - thumbWidth;
264
+ const horizontalThumbOffset = scrollPercentage * maxThumbOffset;
265
+ horizontalStyle = {
266
+ track: __spreadProps(__spreadValues({}, basicTrackStyle), {
267
+ bottom: 0,
268
+ left: 0,
269
+ right: 0,
270
+ height: config.size
271
+ }),
272
+ thumb: __spreadProps(__spreadValues({}, basicThumbStyle), {
273
+ transform: `translateX(${horizontalThumbOffset}px)`,
274
+ height: "100%",
275
+ width: `${thumbWidth}px`
276
+ })
277
+ };
278
+ }
279
+ const contentHeight = contentSize.height * scale;
280
+ if (container.height < contentHeight) {
281
+ const thumbHeightPercentage = Math.min(1, container.height / contentHeight);
282
+ const thumbHeight = Math.max(config.minThumbSize, container.height * thumbHeightPercentage);
283
+ const maxScrollY = contentHeight - container.height;
284
+ const scrollPercentage = maxScrollY > 0 ? Math.max(0, Math.min(1, -positionY / maxScrollY)) : 0;
285
+ const maxThumbOffset = container.height - thumbHeight;
286
+ const verticalThumbOffset = scrollPercentage * maxThumbOffset;
287
+ verticalStyle = {
288
+ track: __spreadProps(__spreadValues({}, basicTrackStyle), {
289
+ top: 0,
290
+ right: 0,
291
+ bottom: 0,
292
+ width: config.size
293
+ }),
294
+ thumb: __spreadProps(__spreadValues({}, basicThumbStyle), {
295
+ transform: `translateY(${verticalThumbOffset}px)`,
296
+ height: `${thumbHeight}px`,
297
+ width: "100%"
298
+ })
299
+ };
300
+ }
301
+ return [horizontalStyle, verticalStyle];
302
+ }
303
+ render({ children } = { children: null }) {
304
+ const config = use(() => this.config);
305
+ const container = use(() => this.container);
306
+ const transform = use(() => this.transform);
307
+ const contentSize = use(() => this.contentSize);
308
+ const showScrollbars = use(() => this.showScrollbars);
309
+ const [horizontalStyle, verticalStyle] = this.getUpdatedScrollbarsStyle(
310
+ config,
311
+ container,
312
+ transform,
313
+ contentSize,
314
+ showScrollbars
315
+ );
316
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
317
+ children,
318
+ horizontalStyle && /* @__PURE__ */ jsx(
319
+ "div",
320
+ {
321
+ "data-plugin-id": this.pluginId,
322
+ "data-tracker-type": "horizontal",
323
+ className: bem(this.name, "track-horizontal"),
324
+ style: horizontalStyle.track,
325
+ onClick: (e) => this.handleTrackerClick(e, "horizontal"),
326
+ onMouseEnter: this.handleMouseEnter,
327
+ onMouseLeave: this.handleMouseLeave,
328
+ children: /* @__PURE__ */ jsx(
329
+ "div",
330
+ {
331
+ "data-plugin-id": this.pluginId,
332
+ "data-thumb-type": "horizontal",
333
+ className: bem(this.name, "thumb-horizontal"),
334
+ style: horizontalStyle.thumb,
335
+ onMouseDown: (e) => this.handleMouseDown(e, "horizontal")
336
+ }
337
+ )
338
+ }
339
+ ),
340
+ verticalStyle && /* @__PURE__ */ jsx(
341
+ "div",
342
+ {
343
+ "data-plugin-id": this.pluginId,
344
+ "data-tracker-type": "vertical",
345
+ className: bem(this.name, "track-vertical"),
346
+ style: verticalStyle.track,
347
+ onClick: (e) => this.handleTrackerClick(e, "vertical"),
348
+ onMouseEnter: this.handleMouseEnter,
349
+ onMouseLeave: this.handleMouseLeave,
350
+ children: /* @__PURE__ */ jsx(
351
+ "div",
352
+ {
353
+ "data-plugin-id": this.pluginId,
354
+ "data-thumb-type": "vertical",
355
+ className: bem(this.name, "thumb-vertical"),
356
+ style: verticalStyle.thumb,
357
+ onMouseDown: (e) => this.handleMouseDown(e, "vertical")
358
+ }
359
+ )
360
+ }
361
+ )
362
+ ] });
363
+ }
364
+ }
365
+ _init = __decoratorStart(_a);
366
+ __decorateElement(_init, 1, "init", _init_dec, CanvasScrollbar);
367
+ __decorateElement(_init, 1, "render", _render_dec, CanvasScrollbar);
368
+ __decorateElement(_init, 5, "showScrollbars", _showScrollbars_dec, CanvasScrollbar);
369
+ __decorateElement(_init, 5, "container", _container_dec, CanvasScrollbar);
370
+ __decorateElement(_init, 5, "contentSize", _contentSize_dec, CanvasScrollbar);
371
+ __decorateElement(_init, 5, "transform", _transform_dec, CanvasScrollbar);
372
+ __decorateElement(_init, 5, "addListener", _addListener_dec, CanvasScrollbar);
373
+ __decoratorMetadata(_init, CanvasScrollbar);
374
+
375
+ export { CanvasScrollbar };
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@knotx/plugins-canvas-scrollbar",
3
+ "version": "0.4.6",
4
+ "description": "Canvas Scrollbar Plugin for Knotx",
5
+ "author": "boenfu",
6
+ "license": "MIT",
7
+ "homepage": "https://github.com/boenfu/knotx#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/boenfu/knotx.git",
11
+ "directory": "packages/plugins-canvas-scrollbar"
12
+ },
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "sideEffects": false,
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js",
21
+ "require": "./dist/index.cjs"
22
+ }
23
+ },
24
+ "main": "./dist/index.cjs",
25
+ "module": "./dist/index.js",
26
+ "types": "./dist/index.d.ts",
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "peerDependencies": {
31
+ "react": ">=17.0.0",
32
+ "@knotx/jsx": "0.4.6",
33
+ "@knotx/plugins-canvas": "0.4.6"
34
+ },
35
+ "dependencies": {
36
+ "@knotx/core": "0.4.6",
37
+ "@knotx/decorators": "0.4.6"
38
+ },
39
+ "devDependencies": {
40
+ "@types/react": "^17.0.0",
41
+ "react": "^17.0.0",
42
+ "@knotx/build-config": "0.4.6",
43
+ "@knotx/eslint-config": "0.4.6",
44
+ "@knotx/jsx": "0.4.6",
45
+ "@knotx/plugins-canvas": "0.4.6",
46
+ "@knotx/typescript-config": "0.4.6"
47
+ },
48
+ "scripts": {
49
+ "build": "unbuild",
50
+ "dev": "unbuild --stub",
51
+ "lint": "eslint .",
52
+ "typecheck": "tsc --noEmit"
53
+ }
54
+ }