var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
define(["require", "exports"], function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    /**
     * Utilities that don't require a DOM to run.
     * @author Louis-Dominique Dubeau
     * @license MPL 2.0
     * @copyright Mangalam Research Center for Buddhist Languages
     */
    // tslint:disable-next-line:completed-docs
    class DataProvider {
        constructor(base) {
            this.base = base;
            this.cache = Object.create(null);
            this.parser = new DOMParser();
            this.registered = Object.create(null);
        }
        register(name, path) {
            this.registered[name] = path;
        }
        getNamed(name) {
            const path = this.registered[name];
            return this.getText(path);
        }
        getNamedDoc(name) {
            const path = this.registered[name];
            return this.getDoc(path);
        }
        getText(path) {
            return this._getText(this.base + path);
        }
        _getText(path) {
            return __awaiter(this, void 0, void 0, function* () {
                const cached = this.cache[path];
                if (cached !== undefined) {
                    return cached;
                }
                const data = yield (yield fetch(path)).text();
                this.cache[path] = data;
                return data;
            });
        }
        getDoc(path) {
            return __awaiter(this, void 0, void 0, function* () {
                const data = yield this._getText(this.base + path);
                return this.parser.parseFromString(data, "text/xml");
            });
        }
    }
    exports.DataProvider = DataProvider;
    // tslint:disable-next-line:no-any
    function makeFakePasteEvent(clipboardData) {
        const event = new $.Event("paste");
        event.originalEvent = {
            clipboardData,
            // tslint:disable-next-line:no-empty
            stopImmediatePropagation: () => { },
            // tslint:disable-next-line:no-empty
            preventDefault: () => { },
            // tslint:disable-next-line:no-empty
            stopPropagation: () => { },
        };
        return event;
    }
    exports.makeFakePasteEvent = makeFakePasteEvent;
});
//# sourceMappingURL=util.js.map