@pirireis/webglobeplugins 1.5.2 → 1.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -11,11 +11,39 @@ export class PngBlobMapPart {
|
|
|
11
11
|
}
|
|
12
12
|
return source;
|
|
13
13
|
}
|
|
14
|
+
inferMimeType(base64Payload) {
|
|
15
|
+
const payload = base64Payload.trim();
|
|
16
|
+
if (payload.startsWith("/9j/")) {
|
|
17
|
+
return "image/jpeg";
|
|
18
|
+
}
|
|
19
|
+
if (payload.startsWith("iVBOR")) {
|
|
20
|
+
return "image/png";
|
|
21
|
+
}
|
|
22
|
+
if (payload.startsWith("R0lGOD")) {
|
|
23
|
+
return "image/gif";
|
|
24
|
+
}
|
|
25
|
+
if (payload.startsWith("UklGR")) {
|
|
26
|
+
return "image/webp";
|
|
27
|
+
}
|
|
28
|
+
if (payload.startsWith("PHN2Zy") || payload.startsWith("PD94bWw")) {
|
|
29
|
+
return "image/svg+xml";
|
|
30
|
+
}
|
|
31
|
+
return "image/png";
|
|
32
|
+
}
|
|
14
33
|
toDataUri(base64Source) {
|
|
15
|
-
|
|
16
|
-
|
|
34
|
+
const rawSource = base64Source.trim();
|
|
35
|
+
if (rawSource.startsWith("data:")) {
|
|
36
|
+
return rawSource;
|
|
37
|
+
}
|
|
38
|
+
const compactSource = rawSource.replace(/\s+/g, "");
|
|
39
|
+
const repairedDataUri = compactSource.match(/^data:?([a-z]+\/[a-z0-9.+-]+);base64,?(.+)$/i) ||
|
|
40
|
+
compactSource.match(/^data:?([a-z]+\/[a-z0-9.+-]+)base64(.+)$/i);
|
|
41
|
+
if (repairedDataUri) {
|
|
42
|
+
const [, mimeType, payload] = repairedDataUri;
|
|
43
|
+
return `data:${mimeType};base64,${payload}`;
|
|
17
44
|
}
|
|
18
|
-
|
|
45
|
+
const mimeType = this.inferMimeType(compactSource);
|
|
46
|
+
return `data:${mimeType};base64,${compactSource}`;
|
|
19
47
|
}
|
|
20
48
|
loadImage(base64Source) {
|
|
21
49
|
const src = this.toDataUri(base64Source);
|