(function (window, document) {
	'use strict';

	if (window.pdfjsLib && typeof window.pdfjsLib.getDocument === 'function') {
		window.noesiaSwaPdfJsReadyPromise = Promise.resolve(window.pdfjsLib);
		return;
	}

	function getBaseUrl() {
		var script = document.currentScript;
		var src = script && script.src ? String(script.src) : '';

		if (!src) {
			return '';
		}

		return src.slice(0, src.lastIndexOf('/') + 1);
	}

	var baseUrl = getBaseUrl();

	window.noesiaSwaPdfJsReadyPromise = import(baseUrl + 'pdf.min.js')
		.then(function (pdfjsLib) {
			var config = window.noesiaSwaImageToolsConverterConfig || {};

			window.pdfjsLib = pdfjsLib;

			if (pdfjsLib.GlobalWorkerOptions) {
				pdfjsLib.GlobalWorkerOptions.workerSrc = config.pdfWorkerSrc || (baseUrl + 'pdf.worker.min.js');
			}

			return pdfjsLib;
		})
		.catch(function (error) {
			window.noesiaSwaPdfJsReadyError = error;
			throw error;
		});
})(window, document);