class Options { constructor(opts) { this.scaleIndex = 0; this.scaleList = [ 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.2, 1.4, 1.6, 1.8, 2, 2.2, 2.4, 2.6, 2.8, 3, 3.2, 3.4, 3.6, 3.8, 4, 4.2, 4.4, 4.6, 4.8, 5, 5.2, 5.4, 5.6, 5.8, 6, 6.2, 6.4, 6.6, 6.8, 7, 7.2, 7.4, 7.6, 7.8, 8, 8.2, 8.4, 8.6, 8.8 ]; if (Number.isFinite(opts.scaleRate)) { const idx = this.scaleList.indexOf(opts.scaleRate); if (idx >= 0) { this.scaleIndex = idx; } } this.scaleRate = opts.scaleRate || this.scaleList[this.scaleIndex]; // 缩放比例 this.offsetX = opts.offsetX || 0; // x偏移 this.offsetY = opts.offsetY || 0; // y偏移 this.throttle = opts.throttle || 17; // 刷新频率 } update(payload) { if (Number.isFinite(payload.dx)) { this.offsetX -= payload.dx; } if (Number.isFinite(payload.dy)) { this.offsetY -= payload.dy; } if (Number.isFinite(payload.offsetX)) { this.offsetX = payload.offsetX; } if (Number.isFinite(payload.offsetY)) { this.offsetY = payload.offsetY; } if (Number.isFinite(payload.scale)) { if (Number.isFinite(payload.scale)) { if ((this.scaleIndex + payload.scale) >= 0 && (this.scaleIndex + payload.scale) < this.scaleList.length) { this.scaleIndex = this.scaleIndex + payload.scale; } } this.scaleRate = this.scaleList[this.scaleIndex]; } if (Number.isFinite(payload.scaleRate)) { const idx = this.scaleList.indexOf(payload.scaleRate); if (idx < 0) { return; } this.scaleIndex = idx; this.scaleRate = payload.scaleRate; } } getScaleRate(scale) { if (Number.isFinite(scale)) { if ((this.scaleIndex + scale) >= 0 && (this.scaleIndex + scale) < this.scaleList.length) { return this.scaleList[this.scaleIndex + scale]; } } return this.scaleList[this.scaleIndex]; } } export default Options;