| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- import { __awaiter } from "tslib";
- import { PromiseQueue } from "./PromiseQueue";
- export class DynamicTagQueue {
- constructor(krpanoRenderer) {
- // krpano 1.19 版本不支持动态插入 include,只能在文本中插入后重新加载
- this.queue = new PromiseQueue();
- this.syncTagsLoaded = false;
- this.syncTagStack = [];
- this.krpanoRenderer = krpanoRenderer;
- }
- /**
- * 等待 include 标签加载完成
- */
- waitIncludeLoaded(push) {
- return this.syncTagsLoaded
- ? Promise.resolve()
- : // 先进后出
- this.queue[push ? "push" : "unshift"]();
- }
- pushSyncTag(tagName, attribute) {
- this.syncTagStack.unshift({
- tagName,
- attribute,
- });
- }
- createSyncTags() {
- return __awaiter(this, void 0, void 0, function* () {
- const xmlDoc = yield this.getXMLContent();
- const krpanoElement = xmlDoc.querySelector("krpano");
- while (this.syncTagStack.length) {
- const tag = this.syncTagStack.pop();
- const element = xmlDoc.createElement(tag.tagName);
- for (const key in tag.attribute) {
- element.setAttribute(key, tag.attribute[key]);
- }
- krpanoElement === null || krpanoElement === void 0 ? void 0 : krpanoElement.insertBefore(element, null);
- }
- return xmlDoc;
- });
- }
- getXMLContent() {
- var _a;
- return __awaiter(this, void 0, void 0, function* () {
- let contentText = "";
- const xml = (_a = this.krpanoRenderer) === null || _a === void 0 ? void 0 : _a.get("xml");
- const parser = new DOMParser();
- if (xml.content) {
- contentText = xml.content;
- }
- else if (xml.url) {
- contentText = yield fetch(xml.url).then((res) => res.text());
- }
- return parser.parseFromString(contentText, "text/xml");
- });
- }
- }
|