Repository navigation
Expand file tree
/
Copy pathplugin.js
More file actions
97 lines (97 loc) · 3.13 KB
/
Copy pathplugin.js
File metadata and controls
97 lines (97 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
(function () {
const name = "Commodore 64 D64";
const description =
"Exports rendered page graphics and assets into Commodore 64 disk images.";
const baseMessage = `Storage medium "${name}" could not register.`;
const supportUrl =
typeof document !== "undefined" &&
document.currentScript &&
document.currentScript.src
? new URL("./support.js", document.currentScript.src).toString()
: "support.js";
const logError = function (message, err) {
if (typeof console !== "undefined" && typeof console.error === "function") {
if (arguments.length > 1) console.error(message, err);
else console.error(message);
}
};
const ensureSupport = function () {
if (
window.TPP &&
window.TPP.d64 &&
typeof window.TPP.d64.buildImage === "function" &&
typeof window.TPP.d64.estimateImageUsage === "function" &&
typeof window.TPP.d64.fileName === "function" &&
typeof window.TPP.d64.diskFileName === "function"
) {
return Promise.resolve();
}
if (window.TPP && window.TPP.d64StorageSupportLoadPromise) {
return window.TPP.d64StorageSupportLoadPromise;
}
const promise = new Promise(function (resolve, reject) {
if (typeof document === "undefined") {
reject(new Error("Document not available for D64 support loading."));
return;
}
const script = document.createElement("script");
script.src = supportUrl;
script.async = true;
script.onload = function () {
if (
window.TPP &&
window.TPP.d64 &&
typeof window.TPP.d64.buildImage === "function" &&
typeof window.TPP.d64.estimateImageUsage === "function" &&
typeof window.TPP.d64.fileName === "function" &&
typeof window.TPP.d64.diskFileName === "function"
) {
resolve();
return;
}
reject(
new Error("D64 support script loaded without required helpers."),
);
};
script.onerror = function () {
reject(new Error("D64 support script load failed."));
};
document.head.appendChild(script);
})
.catch(function (err) {
logError(`${baseMessage} Support script could not load.`, err);
throw err;
})
.finally(function () {
if (window.TPP) delete window.TPP.d64StorageSupportLoadPromise;
});
if (window.TPP) {
window.TPP.d64StorageSupportLoadPromise = promise;
}
return promise;
};
const registerStorage = window.TPP && window.TPP.registerStorage;
if (typeof registerStorage !== "function") {
logError(`${baseMessage} TPP.registerStorage not found.`);
return;
}
try {
registerStorage({
id: "d64",
name: name,
description: description,
export: async function (options) {
await ensureSupport();
if (
!window.TPP ||
typeof window.TPP.exportImagesD64Core !== "function"
) {
throw new Error("TPP.exportImagesD64Core not found.");
}
return window.TPP.exportImagesD64Core(options || {});
},
});
} catch (err) {
logError(baseMessage, err);
}
})();