From a9dd631d528b2530e5e31d6a73ad712c8323c71d Mon Sep 17 00:00:00 2001 From: Justin Date: Wed, 11 Oct 2023 15:36:52 +0800 Subject: [PATCH] cl --- src/Viewport.ts | 2 ++ src/plugins/ClampZoom.ts | 16 ++++++++++++---- src/plugins/Wheel.ts | 1 + 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Viewport.ts b/src/Viewport.ts index e9efd821..4c6bced1 100644 --- a/src/Viewport.ts +++ b/src/Viewport.ts @@ -194,6 +194,8 @@ export class Viewport extends Container private _worldHeight?: number | null; private _disableOnContextMenu = (e: MouseEvent) => e.preventDefault(); + public _wheelAxis?: 'all' | 'x' | 'y'; + /** * @param {IViewportOptions} ViewportOptions * @param {number} [options.screenWidth=window.innerWidth] diff --git a/src/plugins/ClampZoom.ts b/src/plugins/ClampZoom.ts index 080f5966..3afc4268 100644 --- a/src/plugins/ClampZoom.ts +++ b/src/plugins/ClampZoom.ts @@ -78,21 +78,29 @@ export class ClampZoom extends Plugin if (this.options.minWidth !== null && width < this.options.minWidth) { const original = this.parent.scale.x; + console.log('-- minwidth', this.parent._wheelAxis); this.parent.fitWidth(this.options.minWidth, false, false, true); - this.parent.scale.y *= this.parent.scale.x / original; width = this.parent.worldScreenWidth; - height = this.parent.worldScreenHeight; + + if (this.parent._wheelAxis && ['all', 'y'].includes(this.parent._wheelAxis)) { + this.parent.scale.y *= this.parent.scale.x / original; + height = this.parent.worldScreenHeight; + } this.parent.emit('zoomed', { viewport: this.parent, type: 'clamp-zoom' }); } if (this.options.maxWidth !== null && width > this.options.maxWidth) { const original = this.parent.scale.x; + console.log('-- maxwidth', this.parent._wheelAxis); this.parent.fitWidth(this.options.maxWidth, false, false, true); - this.parent.scale.y *= this.parent.scale.x / original; width = this.parent.worldScreenWidth; - height = this.parent.worldScreenHeight; + + if (this.parent._wheelAxis && ['all', 'y'].includes(this.parent._wheelAxis)) { + this.parent.scale.y *= this.parent.scale.x / original; + height = this.parent.worldScreenHeight; + } this.parent.emit('zoomed', { viewport: this.parent, type: 'clamp-zoom' }); } if (this.options.minHeight !== null && height < this.options.minHeight) diff --git a/src/plugins/Wheel.ts b/src/plugins/Wheel.ts index d48a8254..48c60932 100644 --- a/src/plugins/Wheel.ts +++ b/src/plugins/Wheel.ts @@ -110,6 +110,7 @@ export class Wheel extends Plugin { super(parent); this.options = Object.assign({}, DEFAULT_WHEEL_OPTIONS, options); + this.parent._wheelAxis = this.options.axis; this.keyIsPressed = false; if (this.options.keyToPress)