@driftory/viewer
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -42,2 +42,3 @@ /// <reference types="openseadragon" /> | ||
frameIndex: number; | ||
frameIndexHint: number; | ||
lastScrollTime: number; | ||
@@ -44,0 +45,0 @@ scrollDelay: number; |
@@ -28,2 +28,3 @@ "use strict"; | ||
this.frameIndex = -1; | ||
this.frameIndexHint = -1; | ||
this.lastScrollTime = 0; | ||
@@ -193,16 +194,16 @@ this.scrollDelay = 2000; | ||
var _this = this; | ||
var frameHandler = function () { | ||
var frameIndex = _this._figureFrameIndex(false); | ||
if (frameIndex !== -1 && frameIndex !== _this.frameIndex) { | ||
_this.frameIndex = frameIndex; | ||
_this._updateImageVisibility(); | ||
if (_this.onFrameChange) { | ||
_this.onFrameChange({ | ||
frameIndex: frameIndex, | ||
isLastFrame: frameIndex === _this.getFrameCount() - 1 | ||
}); | ||
if (this.viewer) { | ||
var frameHandler = function () { | ||
var frameIndex = _this._figureFrameIndex(false); | ||
if (frameIndex !== -1 && frameIndex !== _this.frameIndex) { | ||
_this.frameIndex = frameIndex; | ||
_this._updateImageVisibility(); | ||
if (_this.onFrameChange) { | ||
_this.onFrameChange({ | ||
frameIndex: frameIndex, | ||
isLastFrame: frameIndex === _this.getFrameCount() - 1 | ||
}); | ||
} | ||
} | ||
} | ||
}; | ||
if (this.viewer) { | ||
}; | ||
this.viewer.addHandler('zoom', frameHandler); | ||
@@ -243,2 +244,3 @@ this.viewer.addHandler('pan', frameHandler); | ||
if (frame) { | ||
this.frameIndexHint = index; | ||
var box = frame.clone(); | ||
@@ -267,2 +269,6 @@ box.width *= 1 + bufferFactor; | ||
if (frame.containsPoint(viewportCenter)) { | ||
if (this.frameIndexHint === i) { | ||
bestIndex = i; | ||
break; | ||
} | ||
var distance = viewportCenter.squaredDistanceTo(frame.getCenter()); | ||
@@ -280,2 +286,3 @@ if (distance < bestDistance) { | ||
Driftory.prototype._getHitFrame = function (point) { | ||
var bestIndex = -1; | ||
if (this.viewer) { | ||
@@ -285,7 +292,13 @@ for (var i = 0; i < this.frames.length; i++) { | ||
if (frame.containsPoint(point)) { | ||
return i; | ||
if (this.frameIndex === i) { | ||
bestIndex = i; | ||
break; | ||
} | ||
if (bestIndex === -1) { | ||
bestIndex = i; | ||
} | ||
} | ||
} | ||
} | ||
return -1; | ||
return bestIndex; | ||
}; | ||
@@ -292,0 +305,0 @@ // ---------- |
{ | ||
"name": "@driftory/viewer", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "A viewer for comics created with https://www.driftory.com/", | ||
@@ -5,0 +5,0 @@ "main": "./dist/driftory.js", |
61773
1746