import { Tile_default } from "./chunk-MESSQWK4.js"; import { TileState_default } from "./chunk-5D2XPBR2.js"; import { createCanvasContext2D } from "./chunk-YWIWRQT2.js"; import { assert } from "./chunk-QFCIXVZ3.js"; import { Disposable_default } from "./chunk-KJXIHBKT.js"; // node_modules/ol/structs/LRUCache.js var LRUCache = class { /** * @param {number} [highWaterMark] High water mark. */ constructor(highWaterMark) { this.highWaterMark = highWaterMark !== void 0 ? highWaterMark : 2048; this.count_ = 0; this.entries_ = {}; this.oldest_ = null; this.newest_ = null; } deleteOldest() { const entry = this.pop(); if (entry instanceof Disposable_default) { entry.dispose(); } } /** * @return {boolean} Can expire cache. */ canExpireCache() { return this.highWaterMark > 0 && this.getCount() > this.highWaterMark; } /** * Expire the cache. When the cache entry is a {@link module:ol/Disposable~Disposable}, * the entry will be disposed. * @param {!Object} [keep] Keys to keep. To be implemented by subclasses. */ expireCache(keep) { while (this.canExpireCache()) { this.deleteOldest(); } } /** * FIXME empty description for jsdoc */ clear() { while (this.oldest_) { this.deleteOldest(); } } /** * @param {string} key Key. * @return {boolean} Contains key. */ containsKey(key) { return this.entries_.hasOwnProperty(key); } /** * @param {function(T, string, LRUCache): ?} f The function * to call for every entry from the oldest to the newer. This function takes * 3 arguments (the entry value, the entry key and the LRUCache object). * The return value is ignored. */ forEach(f) { let entry = this.oldest_; while (entry) { f(entry.value_, entry.key_, this); entry = entry.newer; } } /** * @param {string} key Key. * @param {*} [options] Options (reserved for subclasses). * @return {T} Value. */ get(key, options) { const entry = this.entries_[key]; assert( entry !== void 0, "Tried to get a value for a key that does not exist in the cache" ); if (entry === this.newest_) { return entry.value_; } if (entry === this.oldest_) { this.oldest_ = /** @type {Entry} */ this.oldest_.newer; this.oldest_.older = null; } else { entry.newer.older = entry.older; entry.older.newer = entry.newer; } entry.newer = null; entry.older = this.newest_; this.newest_.newer = entry; this.newest_ = entry; return entry.value_; } /** * Remove an entry from the cache. * @param {string} key The entry key. * @return {T} The removed entry. */ remove(key) { const entry = this.entries_[key]; assert( entry !== void 0, "Tried to get a value for a key that does not exist in the cache" ); if (entry === this.newest_) { this.newest_ = /** @type {Entry} */ entry.older; if (this.newest_) { this.newest_.newer = null; } } else if (entry === this.oldest_) { this.oldest_ = /** @type {Entry} */ entry.newer; if (this.oldest_) { this.oldest_.older = null; } } else { entry.newer.older = entry.older; entry.older.newer = entry.newer; } delete this.entries_[key]; --this.count_; return entry.value_; } /** * @return {number} Count. */ getCount() { return this.count_; } /** * @return {Array} Keys. */ getKeys() { const keys = new Array(this.count_); let i = 0; let entry; for (entry = this.newest_; entry; entry = entry.older) { keys[i++] = entry.key_; } return keys; } /** * @return {Array} Values. */ getValues() { const values = new Array(this.count_); let i = 0; let entry; for (entry = this.newest_; entry; entry = entry.older) { values[i++] = entry.value_; } return values; } /** * @return {T} Last value. */ peekLast() { return this.oldest_.value_; } /** * @return {string} Last key. */ peekLastKey() { return this.oldest_.key_; } /** * Get the key of the newest item in the cache. Throws if the cache is empty. * @return {string} The newest key. */ peekFirstKey() { return this.newest_.key_; } /** * Return an entry without updating least recently used time. * @param {string} key Key. * @return {T|undefined} Value. */ peek(key) { var _a; return (_a = this.entries_[key]) == null ? void 0 : _a.value_; } /** * @return {T} value Value. */ pop() { const entry = this.oldest_; delete this.entries_[entry.key_]; if (entry.newer) { entry.newer.older = null; } this.oldest_ = /** @type {Entry} */ entry.newer; if (!this.oldest_) { this.newest_ = null; } --this.count_; return entry.value_; } /** * @param {string} key Key. * @param {T} value Value. */ replace(key, value) { this.get(key); this.entries_[key].value_ = value; } /** * @param {string} key Key. * @param {T} value Value. */ set(key, value) { assert( !(key in this.entries_), "Tried to set a value for a key that is used already" ); const entry = { key_: key, newer: null, older: this.newest_, value_: value }; if (!this.newest_) { this.oldest_ = entry; } else { this.newest_.newer = entry; } this.newest_ = entry; this.entries_[key] = entry; ++this.count_; } /** * Set a maximum number of entries for the cache. * @param {number} size Cache size. * @api */ setSize(size) { this.highWaterMark = size; } }; var LRUCache_default = LRUCache; // node_modules/ol/DataTile.js function asImageLike(data) { return data instanceof Image || data instanceof HTMLCanvasElement || data instanceof HTMLVideoElement || data instanceof ImageBitmap ? data : null; } function asArrayLike(data) { return data instanceof Uint8Array || data instanceof Uint8ClampedArray || data instanceof Float32Array || data instanceof DataView ? data : null; } var disposedError = new Error("disposed"); var sharedContext = null; function toArray(image) { if (!sharedContext) { sharedContext = createCanvasContext2D( image.width, image.height, void 0, { willReadFrequently: true } ); } const canvas = sharedContext.canvas; const width = image.width; if (canvas.width !== width) { canvas.width = width; } const height = image.height; if (canvas.height !== height) { canvas.height = height; } sharedContext.clearRect(0, 0, width, height); sharedContext.drawImage(image, 0, 0); return sharedContext.getImageData(0, 0, width, height).data; } var defaultSize = [256, 256]; var DataTile = class extends Tile_default { /** * @param {Options} options Tile options. */ constructor(options) { const state = TileState_default.IDLE; super(options.tileCoord, state, { transition: options.transition, interpolate: options.interpolate }); this.loader_ = options.loader; this.data_ = null; this.error_ = null; this.size_ = options.size || null; this.controller_ = options.controller || null; } /** * Get the tile size. * @return {import('./size.js').Size} Tile size. */ getSize() { if (this.size_) { return this.size_; } const imageData = asImageLike(this.data_); if (imageData) { return [imageData.width, imageData.height]; } return defaultSize; } /** * Get the data for the tile. * @return {Data} Tile data. * @api */ getData() { return this.data_; } /** * Get any loading error. * @return {Error} Loading error. * @api */ getError() { return this.error_; } /** * Load the tile data. * @api * @override */ load() { if (this.state !== TileState_default.IDLE && this.state !== TileState_default.ERROR) { return; } this.state = TileState_default.LOADING; this.changed(); const self = this; this.loader_().then(function(data) { self.data_ = data; self.state = TileState_default.LOADED; self.changed(); }).catch(function(error) { self.error_ = error; self.state = TileState_default.ERROR; self.changed(); }); } /** * Clean up. * @override */ disposeInternal() { if (this.controller_) { this.controller_.abort(disposedError); this.controller_ = null; } super.disposeInternal(); } }; var DataTile_default = DataTile; export { asImageLike, asArrayLike, toArray, DataTile_default, LRUCache_default }; //# sourceMappingURL=chunk-FPVJKBJO.js.map