import { Reporter } from '../../reporter/reporter.js';
import { LoadableComponent } from '../component/loadable_component.js';
import { checkPropTypes, UUIDRegex } from '../../lib.js';
import { ImageLoader } from '../../../node_modules/three/build/three.module.js';
import { LoadingBase } from '../loader/loading_base.js';
const imageLoader = new ImageLoader();
//imageLoader.setCrossOrigin ( 'anonymous' );
/** ProductBuilder Image */
class WrappedImage extends LoadableComponent {
/**
* @param {Reporter} reporter
* @param {Object} settings
* @param {UUID} [settings.id]
* @param {string} [settings.name]
* @param {QualitySourceMap} settings.source
* @property {...any} [settings.other]
*/
constructor(reporter, settings) {
super(reporter, settings);
checkPropTypes(
settings,
{},
{}
);
// this.exportName = 'images';
}
static _exportName = {
singular: 'image',
plural: 'images'
};
/**
* @param {LoadingBase} base
* @param {LoadingQuality} quality
* @returns {Promise<Image>}
*/
async _load(base, quality) {
/** @type { LoadableComponent } */
const component = this;
// scoped references to be used from inside the promise
const componentStatus = this._status;
const setComponentContent = this._setContent.bind( this );
const imageURL = new URL(base.url.href + this.source[quality].path);
this.report({ msg: `Loading image from ${imageURL}` })
return new Promise((resolve, reject) => {
imageLoader.load(
imageURL.href,
// onLoad callback
function (image) {
//console.log( image )
resolve( image );
},
// onProgress callback currently not supported
undefined,
// onError callback
function (err) {
// console.error(err);
reject(`Could not load image from ${imageURL}${err.message ? ', ' + err.message : ''}`);
}
);
});
}
}
export { WrappedImage };