gengx
This commit is contained in:
@@ -1,48 +1,2 @@
|
||||
"use strict";
|
||||
const common_vendor = require("../../common/vendor.js");
|
||||
function utf8ToBytes(str) {
|
||||
const encoded = encodeURIComponent(str);
|
||||
const bytes = [];
|
||||
for (let i = 0; i < encoded.length; i++) {
|
||||
if (encoded.charCodeAt(i) === 37) {
|
||||
bytes.push(parseInt(encoded.substring(i + 1, i + 3), 16));
|
||||
i += 2;
|
||||
} else {
|
||||
bytes.push(encoded.charCodeAt(i));
|
||||
}
|
||||
}
|
||||
return new Uint8Array(bytes);
|
||||
}
|
||||
function bytesToBase64(bytes) {
|
||||
if (typeof common_vendor.index !== "undefined" && typeof common_vendor.index.arrayBufferToBase64 === "function") {
|
||||
return common_vendor.index.arrayBufferToBase64(bytes.buffer);
|
||||
}
|
||||
if (typeof btoa !== "undefined") {
|
||||
let binary = "";
|
||||
for (let i = 0; i < bytes.length; i++) {
|
||||
binary += String.fromCharCode(bytes[i]);
|
||||
}
|
||||
return btoa(binary);
|
||||
}
|
||||
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
let result = "";
|
||||
for (let i = 0; i < bytes.length; i += 3) {
|
||||
const a = bytes[i];
|
||||
const b = i + 1 < bytes.length ? bytes[i + 1] : 0;
|
||||
const c = i + 2 < bytes.length ? bytes[i + 2] : 0;
|
||||
result += chars[a >> 2];
|
||||
result += chars[(a & 3) << 4 | b >> 4];
|
||||
result += i + 1 < bytes.length ? chars[(b & 15) << 2 | c >> 6] : "=";
|
||||
result += i + 2 < bytes.length ? chars[c & 63] : "=";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function svgToDataUrl(svg) {
|
||||
const normalized = String(svg || "").trim();
|
||||
if (!normalized)
|
||||
return "";
|
||||
const base64 = bytesToBase64(utf8ToBytes(normalized));
|
||||
return `data:image/svg+xml;base64,${base64}`;
|
||||
}
|
||||
exports.svgToDataUrl = svgToDataUrl;
|
||||
"use strict";const a=require("../../common/vendor.js");function u(e){const t=encodeURIComponent(e),r=[];for(let n=0;n<t.length;n++)t.charCodeAt(n)===37?(r.push(parseInt(t.substring(n+1,n+3),16)),n+=2):r.push(t.charCodeAt(n));return new Uint8Array(r)}function c(e){if(typeof a.index<"u"&&typeof a.index.arrayBufferToBase64=="function")return a.index.arrayBufferToBase64(e.buffer);if(typeof btoa<"u"){let n="";for(let o=0;o<e.length;o++)n+=String.fromCharCode(e[o]);return btoa(n)}const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";let r="";for(let n=0;n<e.length;n+=3){const o=e[n],i=n+1<e.length?e[n+1]:0,f=n+2<e.length?e[n+2]:0;r+=t[o>>2],r+=t[(o&3)<<4|i>>4],r+=n+1<e.length?t[(i&15)<<2|f>>6]:"=",r+=n+2<e.length?t[f&63]:"="}return r}function s(e){const t=String(e||"").trim();return t?`data:image/svg+xml;base64,${c(u(t))}`:""}exports.svgToDataUrl=s;
|
||||
//# sourceMappingURL=../../../.sourcemap/mp-weixin/tongji/utils/svgDataUrl.js.map
|
||||
|
||||
Reference in New Issue
Block a user