can-can-word-bug
Version:
can-can-word-bug 是一个 TS 编写的工具库
190 lines (189 loc) • 9.56 kB
JavaScript
import { g as E } from "../_commonjsHelpers-BkfeUUK-.js";
import { c as N } from "../index-BQfkcx47.js";
var B = { exports: {} }, D = { exports: {} };
/**
* A handy class to calculate color values.
*
* @version 1.0
* @author Robert Eisele <robert@xarg.org>
* @copyright Copyright (c) 2010, Robert Eisele
* @link http://www.xarg.org/2010/03/generate-client-side-png-files-using-javascript/
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
*
*/
var I;
function P() {
return I || (I = 1, function(S) {
(function() {
function a(t, s) {
for (var e = 2; e < arguments.length; e++)
for (var u = 0; u < arguments[e].length; u++)
t[s++] = arguments[e].charAt(u);
}
function x(t) {
return String.fromCharCode(t >> 8 & 255, t & 255);
}
function l(t) {
return String.fromCharCode(t >> 24 & 255, t >> 16 & 255, t >> 8 & 255, t & 255);
}
function i(t) {
return String.fromCharCode(t & 255, t >> 8 & 255);
}
var r = function(t, s, e) {
this.width = t, this.height = s, this.depth = e, this.pix_size = s * (t + 1), this.data_size = 2 + this.pix_size + 5 * Math.floor((65534 + this.pix_size) / 65535) + 4, this.ihdr_offs = 0, this.ihdr_size = 25, this.plte_offs = this.ihdr_offs + this.ihdr_size, this.plte_size = 8 + 3 * e + 4, this.trns_offs = this.plte_offs + this.plte_size, this.trns_size = 8 + e + 4, this.idat_offs = this.trns_offs + this.trns_size, this.idat_size = 8 + this.data_size + 4, this.iend_offs = this.idat_offs + this.idat_size, this.iend_size = 12, this.buffer_size = this.iend_offs + this.iend_size, this.buffer = new Array(), this.palette = new Object(), this.pindex = 0;
for (var u = new Array(), f = 0; f < this.buffer_size; f++)
this.buffer[f] = "\0";
a(this.buffer, this.ihdr_offs, l(this.ihdr_size - 12), "IHDR", l(t), l(s), "\b"), a(this.buffer, this.plte_offs, l(this.plte_size - 12), "PLTE"), a(this.buffer, this.trns_offs, l(this.trns_size - 12), "tRNS"), a(this.buffer, this.idat_offs, l(this.idat_size - 12), "IDAT"), a(this.buffer, this.iend_offs, l(this.iend_size - 12), "IEND");
var n = 30912;
n += 31 - n % 31, a(this.buffer, this.idat_offs + 8, x(n));
for (var f = 0; (f << 16) - 1 < this.pix_size; f++) {
var c, w;
f + 65535 < this.pix_size ? (c = 65535, w = "\0") : (c = this.pix_size - (f << 16) - f, w = ""), a(this.buffer, this.idat_offs + 8 + 2 + (f << 16) + (f << 2), w, i(c), i(~c));
}
for (var f = 0; f < 256; f++) {
for (var z = f, M = 0; M < 8; M++)
z & 1 ? z = -306674912 ^ z >> 1 & 2147483647 : z = z >> 1 & 2147483647;
u[f] = z;
}
this.index = function(g, d) {
var o = d * (this.width + 1) + g + 1, h = this.idat_offs + 8 + 2 + 5 * Math.floor(o / 65535 + 1) + o;
return h;
}, this.color = function(g, d, o, h) {
h = h >= 0 ? h : 255;
var p = ((h << 8 | g) << 8 | d) << 8 | o;
if (typeof this.palette[p] > "u") {
if (this.pindex == this.depth) return "\0";
var v = this.plte_offs + 8 + 3 * this.pindex;
this.buffer[v + 0] = String.fromCharCode(g), this.buffer[v + 1] = String.fromCharCode(d), this.buffer[v + 2] = String.fromCharCode(o), this.buffer[this.trns_offs + 8 + this.pindex] = String.fromCharCode(h), this.palette[p] = String.fromCharCode(this.pindex++);
}
return this.palette[p];
}, this.getBase64 = function() {
var g = this.getDump(), d = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", o, h, p, v, C, _, y, A = g.length, b = 0, m = "";
do
o = g.charCodeAt(b), v = o >> 2, h = g.charCodeAt(b + 1), C = (o & 3) << 4 | h >> 4, p = g.charCodeAt(b + 2), A < b + 2 ? _ = 64 : _ = (h & 15) << 2 | p >> 6, A < b + 3 ? y = 64 : y = p & 63, m += d.charAt(v) + d.charAt(C) + d.charAt(_) + d.charAt(y);
while ((b += 3) < A);
return m;
}, this.getDump = function() {
for (var g = 65521, d = 5552, o = 1, h = 0, p = d, v = 0; v < this.height; v++)
for (var C = -1; C < this.width; C++)
o += this.buffer[this.index(C, v)].charCodeAt(0), h += o, (p -= 1) == 0 && (o %= g, h %= g, p = d);
o %= g, h %= g, a(this.buffer, this.idat_offs + this.idat_size - 8, l(h << 16 | o));
function _(y, A, b) {
for (var m = -1, k = 4; k < b - 4; k += 1)
m = u[(m ^ y[A + k].charCodeAt(0)) & 255] ^ m >> 8 & 16777215;
a(y, A + b - 4, l(m ^ -1));
}
return _(this.buffer, this.ihdr_offs, this.ihdr_size), _(this.buffer, this.plte_offs, this.plte_size), _(this.buffer, this.trns_offs, this.trns_size), _(this.buffer, this.idat_offs, this.idat_size), _(this.buffer, this.iend_offs, this.iend_size), `PNG\r
` + this.buffer.join("");
};
};
S.exports = r;
})();
}(D)), D.exports;
}
(function(S) {
(function() {
var a;
a = P();
var x = function(i, r) {
if (typeof i != "string" || i.length < 15)
throw "A hash of at least 15 characters is required.";
this.defaults = {
background: [240, 240, 240, 255],
margin: 0.08,
size: 64,
saturation: 0.7,
brightness: 0.5,
format: "png"
}, this.options = typeof r == "object" ? r : this.defaults, typeof arguments[1] == "number" && (this.options.size = arguments[1]), arguments[2] && (this.options.margin = arguments[2]), this.hash = i, this.background = this.options.background || this.defaults.background, this.size = this.options.size || this.defaults.size, this.format = this.options.format || this.defaults.format, this.margin = this.options.margin !== void 0 ? this.options.margin : this.defaults.margin;
var t = parseInt(this.hash.substr(-7), 16) / 268435455, s = this.options.saturation || this.defaults.saturation, e = this.options.brightness || this.defaults.brightness;
this.foreground = this.options.foreground || this.hsl2rgb(t, s, e);
};
x.prototype = {
background: null,
foreground: null,
hash: null,
margin: null,
size: null,
format: null,
image: function() {
return this.isSvg() ? new l(this.size, this.foreground, this.background) : new a(this.size, this.size, 256);
},
render: function() {
var i = this.image(), r = this.size, t = Math.floor(r * this.margin), s = Math.floor((r - t * 2) / 5), e = Math.floor((r - s * 5) / 2), u = i.color.apply(i, this.background), f = i.color.apply(i, this.foreground), n, c;
for (n = 0; n < 15; n++)
c = parseInt(this.hash.charAt(n), 16) % 2 ? u : f, n < 5 ? this.rectangle(2 * s + e, n * s + e, s, s, c, i) : n < 10 ? (this.rectangle(1 * s + e, (n - 5) * s + e, s, s, c, i), this.rectangle(3 * s + e, (n - 5) * s + e, s, s, c, i)) : n < 15 && (this.rectangle(0 * s + e, (n - 10) * s + e, s, s, c, i), this.rectangle(4 * s + e, (n - 10) * s + e, s, s, c, i));
return i;
},
rectangle: function(i, r, t, s, e, u) {
if (this.isSvg())
u.rectangles.push({ x: i, y: r, w: t, h: s, color: e });
else {
var f, n;
for (f = i; f < i + t; f++)
for (n = r; n < r + s; n++)
u.buffer[u.index(f, n)] = e;
}
},
// adapted from: https://gist.github.com/aemkei/1325937
hsl2rgb: function(i, r, t) {
return i *= 6, r = [
t += r *= t < 0.5 ? t : 1 - t,
t - i % 1 * r * 2,
t -= r *= 2,
t,
t + i % 1 * r,
t + r
], [
r[~~i % 6] * 255,
// red
r[(i | 16) % 6] * 255,
// green
r[(i | 8) % 6] * 255
// blue
];
},
toString: function(i) {
return i ? this.render().getDump() : this.render().getBase64();
},
isSvg: function() {
return this.format.match(/svg/i);
}
};
var l = function(i, r, t) {
this.size = i, this.foreground = this.color.apply(this, r), this.background = this.color.apply(this, t), this.rectangles = [];
};
l.prototype = {
size: null,
foreground: null,
background: null,
rectangles: null,
color: function(i, r, t, s) {
var e = [i, r, t].map(Math.round);
return e.push(s >= 0 && s <= 255 ? s / 255 : 1), "rgba(" + e.join(",") + ")";
},
getDump: function() {
var i, r, t, s = this.foreground, e = this.background, u = this.size * 5e-3;
for (r = "<svg xmlns='http://www.w3.org/2000/svg' width='" + this.size + "' height='" + this.size + "' style='background-color:" + e + ";'><g style='fill:" + s + "; stroke:" + s + "; stroke-width:" + u + ";'>", i = 0; i < this.rectangles.length; i++)
t = this.rectangles[i], t.color != e && (r += "<rect x='" + t.x + "' y='" + t.y + "' width='" + t.w + "' height='" + t.h + "'/>");
return r += "</g></svg>", r;
},
getBase64: function() {
if (typeof btoa == "function")
return btoa(this.getDump());
if (Buffer)
return new Buffer(this.getDump(), "binary").toString("base64");
throw "Cannot generate base64 output";
}
}, S.exports = x;
})();
})(B);
var q = B.exports;
const G = /* @__PURE__ */ E(q), F = (S, a) => {
const x = N.MD5(S).toString();
return `data:image/png;base64,${new G(x, a)}`;
};
export {
F as default
};