(main)
| 3 | |
| 4 | export default class Inserter { |
| 5 | constructor(main) { |
| 6 | this.main = main; |
| 7 | const extendObj = { |
| 8 | extend_top: { |
| 9 | internalName: 'extend_top', |
| 10 | handle: (img) => { |
| 11 | this.tmpImg = img; |
| 12 | const oldH = this.main.size.h; |
| 13 | const oldW = this.main.size.w; |
| 14 | const newH = oldH + img.naturalHeight; |
| 15 | const newW = Math.max(oldW, img.naturalWidth); |
| 16 | const tmpData = this.ctx.getImageData(0, 0, this.main.size.w, this.main.size.h); |
| 17 | this.main.resize(newW, newH); |
| 18 | this.main.clearBackground(); |
| 19 | this.ctx.putImageData(tmpData, 0, img.naturalHeight); |
| 20 | this.main.adjustSizeFull(); |
| 21 | if (img.naturalWidth < oldW) { |
| 22 | const offset = Math.round((oldW - img.naturalWidth) / 2); |
| 23 | this.main.select.placeAt(offset, 0, offset, oldH, img); |
| 24 | } else { |
| 25 | this.main.select.placeAt(0, 0, 0, oldH, img); |
| 26 | } |
| 27 | this.worklog.captureState(); |
| 28 | }, |
| 29 | }, |
| 30 | extend_left: { |
| 31 | internalName: 'extend_left', |
| 32 | handle: (img) => { |
| 33 | this.tmpImg = img; |
| 34 | const oldH = this.main.size.h; |
| 35 | const oldW = this.main.size.w; |
| 36 | const newW = oldW + img.naturalWidth; |
| 37 | const newH = Math.max(oldH, img.naturalHeight); |
| 38 | const tmpData = this.ctx.getImageData(0, 0, this.main.size.w, this.main.size.h); |
| 39 | this.main.resize(newW, newH); |
| 40 | this.main.clearBackground(); |
| 41 | this.ctx.putImageData(tmpData, img.naturalWidth, 0); |
| 42 | this.main.adjustSizeFull(); |
| 43 | if (img.naturalHeight < oldH) { |
| 44 | const offset = Math.round((oldH - img.naturalHeight) / 2); |
| 45 | this.main.select.placeAt(0, offset, oldW, offset, img); |
| 46 | } else { |
| 47 | this.main.select.placeAt(0, 0, oldW, 0, img); |
| 48 | } |
| 49 | this.worklog.captureState(); |
| 50 | }, |
| 51 | }, |
| 52 | extend_right: { |
| 53 | internalName: 'extend_right', |
| 54 | handle: (img) => { |
| 55 | this.tmpImg = img; |
| 56 | const oldH = this.main.size.h; |
| 57 | const oldW = this.main.size.w; |
| 58 | const newW = oldW + img.naturalWidth; |
| 59 | const newH = Math.max(oldH, img.naturalHeight); |
| 60 | const tmpData = this.ctx.getImageData(0, 0, this.main.size.w, this.main.size.h); |
| 61 | this.main.resize(newW, newH); |
| 62 | this.main.clearBackground(); |
nothing calls this directly
no test coverage detected