|
|
@ -20,54 +20,51 @@ import { |
|
|
|
|
|
|
|
|
|
|
|
var DEFAULT_LINK_REL = 'noopener noreferrer nofollow'; |
|
|
|
var DEFAULT_LINK_REL = 'noopener noreferrer nofollow'; |
|
|
|
|
|
|
|
|
|
|
|
function DOMCanvasFactory() {} |
|
|
|
class DOMCanvasFactory { |
|
|
|
DOMCanvasFactory.prototype = { |
|
|
|
create(width, height) { |
|
|
|
create: function DOMCanvasFactory_create(width, height) { |
|
|
|
|
|
|
|
assert(width > 0 && height > 0, 'invalid canvas size'); |
|
|
|
assert(width > 0 && height > 0, 'invalid canvas size'); |
|
|
|
var canvas = document.createElement('canvas'); |
|
|
|
let canvas = document.createElement('canvas'); |
|
|
|
var context = canvas.getContext('2d'); |
|
|
|
let context = canvas.getContext('2d'); |
|
|
|
canvas.width = width; |
|
|
|
canvas.width = width; |
|
|
|
canvas.height = height; |
|
|
|
canvas.height = height; |
|
|
|
return { |
|
|
|
return { |
|
|
|
canvas, |
|
|
|
canvas, |
|
|
|
context, |
|
|
|
context, |
|
|
|
}; |
|
|
|
}; |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
reset: function DOMCanvasFactory_reset(canvasAndContextPair, width, height) { |
|
|
|
reset(canvasAndContext, width, height) { |
|
|
|
assert(canvasAndContextPair.canvas, 'canvas is not specified'); |
|
|
|
assert(canvasAndContext.canvas, 'canvas is not specified'); |
|
|
|
assert(width > 0 && height > 0, 'invalid canvas size'); |
|
|
|
assert(width > 0 && height > 0, 'invalid canvas size'); |
|
|
|
canvasAndContextPair.canvas.width = width; |
|
|
|
canvasAndContext.canvas.width = width; |
|
|
|
canvasAndContextPair.canvas.height = height; |
|
|
|
canvasAndContext.canvas.height = height; |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
destroy: function DOMCanvasFactory_destroy(canvasAndContextPair) { |
|
|
|
destroy(canvasAndContext) { |
|
|
|
assert(canvasAndContextPair.canvas, 'canvas is not specified'); |
|
|
|
assert(canvasAndContext.canvas, 'canvas is not specified'); |
|
|
|
// Zeroing the width and height cause Firefox to release graphics
|
|
|
|
// Zeroing the width and height cause Firefox to release graphics
|
|
|
|
// resources immediately, which can greatly reduce memory consumption.
|
|
|
|
// resources immediately, which can greatly reduce memory consumption.
|
|
|
|
canvasAndContextPair.canvas.width = 0; |
|
|
|
canvasAndContext.canvas.width = 0; |
|
|
|
canvasAndContextPair.canvas.height = 0; |
|
|
|
canvasAndContext.canvas.height = 0; |
|
|
|
canvasAndContextPair.canvas = null; |
|
|
|
canvasAndContext.canvas = null; |
|
|
|
canvasAndContextPair.context = null; |
|
|
|
canvasAndContext.context = null; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var DOMCMapReaderFactory = (function DOMCMapReaderFactoryClosure() { |
|
|
|
class DOMCMapReaderFactory { |
|
|
|
function DOMCMapReaderFactory(params) { |
|
|
|
constructor({ baseUrl = null, isCompressed = false, }) { |
|
|
|
this.baseUrl = params.baseUrl || null; |
|
|
|
this.baseUrl = baseUrl; |
|
|
|
this.isCompressed = params.isCompressed || false; |
|
|
|
this.isCompressed = isCompressed; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
DOMCMapReaderFactory.prototype = { |
|
|
|
fetch({ name, }) { |
|
|
|
fetch(params) { |
|
|
|
|
|
|
|
var name = params.name; |
|
|
|
|
|
|
|
if (!name) { |
|
|
|
if (!name) { |
|
|
|
return Promise.reject(new Error('CMap name must be specified.')); |
|
|
|
return Promise.reject(new Error('CMap name must be specified.')); |
|
|
|
} |
|
|
|
} |
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
var url = this.baseUrl + name + (this.isCompressed ? '.bcmap' : ''); |
|
|
|
let url = this.baseUrl + name + (this.isCompressed ? '.bcmap' : ''); |
|
|
|
|
|
|
|
|
|
|
|
var request = new XMLHttpRequest(); |
|
|
|
let request = new XMLHttpRequest(); |
|
|
|
request.open('GET', url, true); |
|
|
|
request.open('GET', url, true); |
|
|
|
|
|
|
|
|
|
|
|
if (this.isCompressed) { |
|
|
|
if (this.isCompressed) { |
|
|
@ -78,7 +75,7 @@ var DOMCMapReaderFactory = (function DOMCMapReaderFactoryClosure() { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if (request.status === 200 || request.status === 0) { |
|
|
|
if (request.status === 200 || request.status === 0) { |
|
|
|
var data; |
|
|
|
let data; |
|
|
|
if (this.isCompressed && request.response) { |
|
|
|
if (this.isCompressed && request.response) { |
|
|
|
data = new Uint8Array(request.response); |
|
|
|
data = new Uint8Array(request.response); |
|
|
|
} else if (!this.isCompressed && request.responseText) { |
|
|
|
} else if (!this.isCompressed && request.responseText) { |
|
|
@ -100,11 +97,8 @@ var DOMCMapReaderFactory = (function DOMCMapReaderFactoryClosure() { |
|
|
|
|
|
|
|
|
|
|
|
request.send(null); |
|
|
|
request.send(null); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return DOMCMapReaderFactory; |
|
|
|
|
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Optimised CSS custom property getter/setter. |
|
|
|
* Optimised CSS custom property getter/setter. |
|
|
|