starting canvas module
This commit is contained in:
parent
7ccbdac37b
commit
e6d46b593b
5 changed files with 67 additions and 2 deletions
|
@ -1,7 +1,7 @@
|
|||
let EventEmitter = require('events').EventEmitter
|
||||
let LoadIndicator = require('./view/load-indicator')
|
||||
|
||||
module.exports = class ComicBook extends EventEmitter {
|
||||
class ComicBook extends EventEmitter {
|
||||
|
||||
constructor (srcs = []) {
|
||||
super()
|
||||
|
@ -45,3 +45,5 @@ module.exports = class ComicBook extends EventEmitter {
|
|||
|
||||
}
|
||||
|
||||
module.exports = ComicBook
|
||||
|
||||
|
|
28
app/view/canvas.js
Normal file
28
app/view/canvas.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
let EventEmitter = require('events').EventEmitter
|
||||
|
||||
class Canvas extends EventEmitter {
|
||||
|
||||
constructor (options) {
|
||||
super()
|
||||
|
||||
this.options = Object.assign({
|
||||
// fitWidth, fitWindow, manua
|
||||
zoomMode: 'fitWidth',
|
||||
// ltr, rtl
|
||||
readDirection: 'ltr'
|
||||
}, options)
|
||||
|
||||
this.canvas = document.createElement('canvas')
|
||||
this.context = this.canvas.getContext('2d')
|
||||
}
|
||||
|
||||
draw (image, doublePage, image2) {
|
||||
if (!(image instanceof window.Image) || (doublePage && !(image2 instanceof window.Image))) {
|
||||
throw new Error('Invalid image')
|
||||
}
|
||||
|
||||
this.emit('draw')
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Canvas
|
|
@ -48,5 +48,8 @@ describe('ComicBook', function () {
|
|||
comic.loadIndicator.on('show', () => done())
|
||||
comic.preload()
|
||||
})
|
||||
|
||||
it('should scroll to the top of the page on page turn')
|
||||
|
||||
})
|
||||
})
|
||||
|
|
32
test/view/canvas.test.js
Normal file
32
test/view/canvas.test.js
Normal file
|
@ -0,0 +1,32 @@
|
|||
let assert = require('assert')
|
||||
let Canvas = require('../../app/view/canvas')
|
||||
|
||||
describe('Canvas', function () {
|
||||
|
||||
it('should draw only Image objects', function () {
|
||||
let canvas = new Canvas()
|
||||
let image = new window.Image()
|
||||
|
||||
assert.throws(canvas.draw, 'Invalid image')
|
||||
assert.throws(canvas.draw.bind(canvas, image, true), 'Invalid image')
|
||||
assert.doesNotThrow(canvas.draw.bind(canvas, image, true, image), 'Invalid image')
|
||||
})
|
||||
|
||||
it('should draw a single page')
|
||||
|
||||
it('should draw a double page')
|
||||
|
||||
it('should draw a manga double page')
|
||||
|
||||
it('should draw a single double page spread')
|
||||
|
||||
it('should show a blank last page if the last double page only has one image')
|
||||
|
||||
it('should auto-fit to window width')
|
||||
|
||||
it('should auto-fit to window height')
|
||||
|
||||
it('should manual zoom')
|
||||
|
||||
it('should always center pages')
|
||||
})
|
|
@ -1,7 +1,7 @@
|
|||
let assert = require('assert')
|
||||
let LoadIndicator = require('../../app/view/load-indicator')
|
||||
|
||||
describe('#loadIndicator()', function () {
|
||||
describe('LoadIndicator', function () {
|
||||
|
||||
it('should render on init', function () {
|
||||
let indicator = new LoadIndicator()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue