ranui
Version:
A framework-agnostic Web Components UI library built on native custom elements, with TypeScript types, light/dark theming, SSR and PWA support.
1,388 lines (1,387 loc) • 41.6 kB
JavaScript
function U(t, s, e) {
if (t && t.length) {
const [a, n] = s, o = Math.PI / 180 * e, r = Math.cos(o), h = Math.sin(o);
for (const i of t) {
const [c, l] = i;
i[0] = (c - a) * r - (l - n) * h + a, i[1] = (c - a) * h + (l - n) * r + n;
}
}
}
function Ot(t, s) {
return t[0] === s[0] && t[1] === s[1];
}
function Lt(t, s, e, a = 1) {
const n = e, o = Math.max(s, 0.1), r = t[0] && t[0][0] && typeof t[0][0] == "number" ? [t] : t, h = [0, 0];
if (n) for (const c of r) U(c, h, n);
const i = (function(c, l, d) {
const f = [];
for (const M of c) {
const y = [...M];
Ot(y[0], y[y.length - 1]) || y.push([y[0][0], y[0][1]]), y.length > 2 && f.push(y);
}
const u = [];
l = Math.max(l, 0.1);
const p = [];
for (const M of f) for (let y = 0; y < M.length - 1; y++) {
const w = M[y], v = M[y + 1];
if (w[1] !== v[1]) {
const P = Math.min(w[1], v[1]);
p.push({
ymin: P,
ymax: Math.max(w[1], v[1]),
x: P === w[1] ? w[0] : v[0],
islope: (v[0] - w[0]) / (v[1] - w[1])
});
}
}
if (p.sort(((M, y) => M.ymin < y.ymin ? -1 : M.ymin > y.ymin ? 1 : M.x < y.x ? -1 : M.x > y.x ? 1 : M.ymax === y.ymax ? 0 : (M.ymax - y.ymax) / Math.abs(M.ymax - y.ymax))), !p.length) return u;
let k = [], g = p[0].ymin, m = 0;
for (; k.length || p.length; ) {
if (p.length) {
let M = -1;
for (let y = 0; y < p.length && !(p[y].ymin > g); y++) M = y;
p.splice(0, M + 1).forEach(((y) => {
k.push({
s: g,
edge: y
});
}));
}
if (k = k.filter(((M) => !(M.edge.ymax <= g))), k.sort(((M, y) => M.edge.x === y.edge.x ? 0 : (M.edge.x - y.edge.x) / Math.abs(M.edge.x - y.edge.x))), (d !== 1 || m % l == 0) && k.length > 1) for (let M = 0; M < k.length; M += 2) {
const y = M + 1;
if (y >= k.length) break;
const w = k[M].edge, v = k[y].edge;
u.push([[Math.round(w.x), g], [Math.round(v.x), g]]);
}
g += d, k.forEach(((M) => {
M.edge.x = M.edge.x + d * M.edge.islope;
})), m++;
}
return u;
})(r, o, a);
if (n) {
for (const c of r) U(c, h, -n);
(function(c, l, d) {
const f = [];
c.forEach(((u) => f.push(...u))), U(f, l, d);
})(i, h, -n);
}
return i;
}
function R(t, s) {
var e;
const a = s.hachureAngle + 90;
let n = s.hachureGap;
n < 0 && (n = 4 * s.strokeWidth), n = Math.round(Math.max(n, 0.1));
let o = 1;
return s.roughness >= 1 && (((e = s.randomizer) === null || e === void 0 ? void 0 : e.next()) || Math.random()) > 0.7 && (o = n), Lt(t, n, a, o || 1);
}
var ot = class {
constructor(t) {
this.helper = t;
}
fillPolygons(t, s) {
return this._fillPolygons(t, s);
}
_fillPolygons(t, s) {
const e = R(t, s);
return {
type: "fillSketch",
ops: this.renderLines(e, s)
};
}
renderLines(t, s) {
const e = [];
for (const a of t) e.push(...this.helper.doubleLineOps(a[0][0], a[0][1], a[1][0], a[1][1], s));
return e;
}
};
function K(t) {
const s = t[0], e = t[1];
return Math.sqrt(Math.pow(s[0] - e[0], 2) + Math.pow(s[1] - e[1], 2));
}
var Tt = class extends ot {
fillPolygons(t, s) {
let e = s.hachureGap;
e < 0 && (e = 4 * s.strokeWidth), e = Math.max(e, 0.1);
const a = R(t, Object.assign({}, s, { hachureGap: e })), n = Math.PI / 180 * s.hachureAngle, o = [], r = 0.5 * e * Math.cos(n), h = 0.5 * e * Math.sin(n);
for (const [i, c] of a) K([i, c]) && o.push([[i[0] - r, i[1] + h], [...c]], [[i[0] + r, i[1] - h], [...c]]);
return {
type: "fillSketch",
ops: this.renderLines(o, s)
};
}
}, Dt = class extends ot {
fillPolygons(t, s) {
const e = this._fillPolygons(t, s), a = Object.assign({}, s, { hachureAngle: s.hachureAngle + 90 }), n = this._fillPolygons(t, a);
return e.ops = e.ops.concat(n.ops), e;
}
}, At = class {
constructor(t) {
this.helper = t;
}
fillPolygons(t, s) {
const e = R(t, s = Object.assign({}, s, { hachureAngle: 0 }));
return this.dotsOnLines(e, s);
}
dotsOnLines(t, s) {
const e = [];
let a = s.hachureGap;
a < 0 && (a = 4 * s.strokeWidth), a = Math.max(a, 0.1);
let n = s.fillWeight;
n < 0 && (n = s.strokeWidth / 2);
const o = a / 4;
for (const r of t) {
const h = K(r), i = h / a, c = Math.ceil(i) - 1, l = h - c * a, d = (r[0][0] + r[1][0]) / 2 - a / 4, f = Math.min(r[0][1], r[1][1]);
for (let u = 0; u < c; u++) {
const p = f + l + u * a, k = d - o + 2 * Math.random() * o, g = p - o + 2 * Math.random() * o, m = this.helper.ellipse(k, g, n, n, s);
e.push(...m.ops);
}
}
return {
type: "fillSketch",
ops: e
};
}
}, _t = class {
constructor(t) {
this.helper = t;
}
fillPolygons(t, s) {
const e = R(t, s);
return {
type: "fillSketch",
ops: this.dashedLine(e, s)
};
}
dashedLine(t, s) {
const e = s.dashOffset < 0 ? s.hachureGap < 0 ? 4 * s.strokeWidth : s.hachureGap : s.dashOffset, a = s.dashGap < 0 ? s.hachureGap < 0 ? 4 * s.strokeWidth : s.hachureGap : s.dashGap, n = [];
return t.forEach(((o) => {
const r = K(o), h = Math.floor(r / (e + a)), i = (r + a - h * (e + a)) / 2;
let c = o[0], l = o[1];
c[0] > l[0] && (c = o[1], l = o[0]);
const d = Math.atan((l[1] - c[1]) / (l[0] - c[0]));
for (let f = 0; f < h; f++) {
const u = f * (e + a), p = u + e, k = [c[0] + u * Math.cos(d) + i * Math.cos(d), c[1] + u * Math.sin(d) + i * Math.sin(d)], g = [c[0] + p * Math.cos(d) + i * Math.cos(d), c[1] + p * Math.sin(d) + i * Math.sin(d)];
n.push(...this.helper.doubleLineOps(k[0], k[1], g[0], g[1], s));
}
})), n;
}
}, It = class {
constructor(t) {
this.helper = t;
}
fillPolygons(t, s) {
const e = s.hachureGap < 0 ? 4 * s.strokeWidth : s.hachureGap, a = s.zigzagOffset < 0 ? e : s.zigzagOffset, n = R(t, s = Object.assign({}, s, { hachureGap: e + a }));
return {
type: "fillSketch",
ops: this.zigzagLines(n, a, s)
};
}
zigzagLines(t, s, e) {
const a = [];
return t.forEach(((n) => {
const o = K(n), r = Math.round(o / (2 * s));
let h = n[0], i = n[1];
h[0] > i[0] && (h = n[1], i = n[0]);
const c = Math.atan((i[1] - h[1]) / (i[0] - h[0]));
for (let l = 0; l < r; l++) {
const d = 2 * l * s, f = 2 * (l + 1) * s, u = Math.sqrt(2 * Math.pow(s, 2)), p = [h[0] + d * Math.cos(c), h[1] + d * Math.sin(c)], k = [h[0] + f * Math.cos(c), h[1] + f * Math.sin(c)], g = [p[0] + u * Math.cos(c + Math.PI / 4), p[1] + u * Math.sin(c + Math.PI / 4)];
a.push(...this.helper.doubleLineOps(p[0], p[1], g[0], g[1], e), ...this.helper.doubleLineOps(g[0], g[1], k[0], k[1], e));
}
})), a;
}
}, S = {}, Ct = class {
constructor(t) {
this.seed = t;
}
next() {
return this.seed ? (2 ** 31 - 1 & (this.seed = Math.imul(48271, this.seed))) / 2 ** 31 : Math.random();
}
}, zt = 0, X = 1, lt = 2, q = {
A: 7,
a: 7,
C: 6,
c: 6,
H: 1,
h: 1,
L: 2,
l: 2,
M: 2,
m: 2,
Q: 4,
q: 4,
S: 4,
s: 4,
T: 2,
t: 2,
V: 1,
v: 1,
Z: 0,
z: 0
};
function Y(t, s) {
return t.type === s;
}
function ht(t) {
const s = [], e = (function(r) {
const h = new Array();
for (; r !== ""; ) if (r.match(/^([ \t\r\n,]+)/)) r = r.substr(RegExp.$1.length);
else if (r.match(/^([aAcChHlLmMqQsStTvVzZ])/)) h[h.length] = {
type: zt,
text: RegExp.$1
}, r = r.substr(RegExp.$1.length);
else {
if (!r.match(/^(([-+]?[0-9]+(\.[0-9]*)?|[-+]?\.[0-9]+)([eE][-+]?[0-9]+)?)/)) return [];
h[h.length] = {
type: X,
text: `${parseFloat(RegExp.$1)}`
}, r = r.substr(RegExp.$1.length);
}
return h[h.length] = {
type: lt,
text: ""
}, h;
})(t);
let a = "BOD", n = 0, o = e[n];
for (; !Y(o, lt); ) {
let r = 0;
const h = [];
if (a === "BOD") {
if (o.text !== "M" && o.text !== "m") return ht("M0,0" + t);
n++, r = q[o.text], a = o.text;
} else Y(o, X) ? r = q[a] : (n++, r = q[o.text], a = o.text);
if (!(n + r < e.length)) throw new Error("Path data ended short");
for (let i = n; i < n + r; i++) {
const c = e[i];
if (!Y(c, X)) throw new Error("Param not a number: " + a + "," + c.text);
h[h.length] = +c.text;
}
if (typeof q[a] != "number") throw new Error("Bad segment: " + a);
{
const i = {
key: a,
data: h
};
s.push(i), n += r, o = e[n], a === "M" && (a = "L"), a === "m" && (a = "l");
}
}
return s;
}
function bt(t) {
let s = 0, e = 0, a = 0, n = 0;
const o = [];
for (const { key: r, data: h } of t) switch (r) {
case "M":
o.push({
key: "M",
data: [...h]
}), [s, e] = h, [a, n] = h;
break;
case "m":
s += h[0], e += h[1], o.push({
key: "M",
data: [s, e]
}), a = s, n = e;
break;
case "L":
o.push({
key: "L",
data: [...h]
}), [s, e] = h;
break;
case "l":
s += h[0], e += h[1], o.push({
key: "L",
data: [s, e]
});
break;
case "C":
o.push({
key: "C",
data: [...h]
}), s = h[4], e = h[5];
break;
case "c": {
const i = h.map(((c, l) => l % 2 ? c + e : c + s));
o.push({
key: "C",
data: i
}), s = i[4], e = i[5];
break;
}
case "Q":
o.push({
key: "Q",
data: [...h]
}), s = h[2], e = h[3];
break;
case "q": {
const i = h.map(((c, l) => l % 2 ? c + e : c + s));
o.push({
key: "Q",
data: i
}), s = i[2], e = i[3];
break;
}
case "A":
o.push({
key: "A",
data: [...h]
}), s = h[5], e = h[6];
break;
case "a":
s += h[5], e += h[6], o.push({
key: "A",
data: [
h[0],
h[1],
h[2],
h[3],
h[4],
s,
e
]
});
break;
case "H":
o.push({
key: "H",
data: [...h]
}), s = h[0];
break;
case "h":
s += h[0], o.push({
key: "H",
data: [s]
});
break;
case "V":
o.push({
key: "V",
data: [...h]
}), e = h[0];
break;
case "v":
e += h[0], o.push({
key: "V",
data: [e]
});
break;
case "S":
o.push({
key: "S",
data: [...h]
}), s = h[2], e = h[3];
break;
case "s": {
const i = h.map(((c, l) => l % 2 ? c + e : c + s));
o.push({
key: "S",
data: i
}), s = i[2], e = i[3];
break;
}
case "T":
o.push({
key: "T",
data: [...h]
}), s = h[0], e = h[1];
break;
case "t":
s += h[0], e += h[1], o.push({
key: "T",
data: [s, e]
});
break;
case "Z":
case "z":
o.push({
key: "Z",
data: []
}), s = a, e = n;
}
return o;
}
function yt(t) {
const s = [];
let e = "", a = 0, n = 0, o = 0, r = 0, h = 0, i = 0;
for (const { key: c, data: l } of t) {
switch (c) {
case "M":
s.push({
key: "M",
data: [...l]
}), [a, n] = l, [o, r] = l;
break;
case "C":
s.push({
key: "C",
data: [...l]
}), a = l[4], n = l[5], h = l[2], i = l[3];
break;
case "L":
s.push({
key: "L",
data: [...l]
}), [a, n] = l;
break;
case "H":
a = l[0], s.push({
key: "L",
data: [a, n]
});
break;
case "V":
n = l[0], s.push({
key: "L",
data: [a, n]
});
break;
case "S": {
let d = 0, f = 0;
e === "C" || e === "S" ? (d = a + (a - h), f = n + (n - i)) : (d = a, f = n), s.push({
key: "C",
data: [
d,
f,
...l
]
}), h = l[0], i = l[1], a = l[2], n = l[3];
break;
}
case "T": {
const [d, f] = l;
let u = 0, p = 0;
e === "Q" || e === "T" ? (u = a + (a - h), p = n + (n - i)) : (u = a, p = n);
const k = a + 2 * (u - a) / 3, g = n + 2 * (p - n) / 3, m = d + 2 * (u - d) / 3, M = f + 2 * (p - f) / 3;
s.push({
key: "C",
data: [
k,
g,
m,
M,
d,
f
]
}), h = u, i = p, a = d, n = f;
break;
}
case "Q": {
const [d, f, u, p] = l, k = a + 2 * (d - a) / 3, g = n + 2 * (f - n) / 3, m = u + 2 * (d - u) / 3, M = p + 2 * (f - p) / 3;
s.push({
key: "C",
data: [
k,
g,
m,
M,
u,
p
]
}), h = d, i = f, a = u, n = p;
break;
}
case "A": {
const d = Math.abs(l[0]), f = Math.abs(l[1]), u = l[2], p = l[3], k = l[4], g = l[5], m = l[6];
d === 0 || f === 0 ? (s.push({
key: "C",
data: [
a,
n,
g,
m,
g,
m
]
}), a = g, n = m) : (a !== g || n !== m) && (mt(a, n, g, m, d, f, u, p, k).forEach((function(M) {
s.push({
key: "C",
data: M
});
})), a = g, n = m);
break;
}
case "Z":
s.push({
key: "Z",
data: []
}), a = o, n = r;
}
e = c;
}
return s;
}
function G(t, s, e) {
return [t * Math.cos(e) - s * Math.sin(e), t * Math.sin(e) + s * Math.cos(e)];
}
function mt(t, s, e, a, n, o, r, h, i, c) {
const l = (d = r, Math.PI * d / 180);
var d;
let f = [], u = 0, p = 0, k = 0, g = 0;
if (c) [u, p, k, g] = c;
else {
[t, s] = G(t, s, -l), [e, a] = G(e, a, -l);
const L = (t - e) / 2, x = (s - a) / 2;
let A = L * L / (n * n) + x * x / (o * o);
A > 1 && (A = Math.sqrt(A), n *= A, o *= A);
const z = n * n, W = o * o, Pt = z * W - z * x * x - W * L * L, St = z * x * x + W * L * L, ct = (h === i ? -1 : 1) * Math.sqrt(Math.abs(Pt / St));
k = ct * n * x / o + (t + e) / 2, g = ct * -o * L / n + (s + a) / 2, u = Math.asin(parseFloat(((s - g) / o).toFixed(9))), p = Math.asin(parseFloat(((a - g) / o).toFixed(9))), t < k && (u = Math.PI - u), e < k && (p = Math.PI - p), u < 0 && (u = 2 * Math.PI + u), p < 0 && (p = 2 * Math.PI + p), i && u > p && (u -= 2 * Math.PI), !i && p > u && (p -= 2 * Math.PI);
}
let m = p - u;
if (Math.abs(m) > 120 * Math.PI / 180) {
const L = p, x = e, A = a;
p = i && p > u ? u + 120 * Math.PI / 180 * 1 : u + 120 * Math.PI / 180 * -1, f = mt(e = k + n * Math.cos(p), a = g + o * Math.sin(p), x, A, n, o, r, 0, i, [
p,
L,
k,
g
]);
}
m = p - u;
const M = Math.cos(u), y = Math.sin(u), w = Math.cos(p), v = Math.sin(p), P = Math.tan(m / 4), D = 4 / 3 * n * P, j = 4 / 3 * o * P, I = [t, s], T = [t + D * y, s - j * M], rt = [e + D * v, a - j * w], it = [e, a];
if (T[0] = 2 * I[0] - T[0], T[1] = 2 * I[1] - T[1], c) return [
T,
rt,
it
].concat(f);
{
f = [
T,
rt,
it
].concat(f);
const L = [];
for (let x = 0; x < f.length; x += 3) {
const A = G(f[x][0], f[x][1], l), z = G(f[x + 1][0], f[x + 1][1], l), W = G(f[x + 2][0], f[x + 2][1], l);
L.push([
A[0],
A[1],
z[0],
z[1],
W[0],
W[1]
]);
}
return L;
}
}
var Wt = {
randOffset: function(t, s) {
return b(t, s);
},
randOffsetWithRange: function(t, s, e) {
return H(t, s, e);
},
ellipse: function(t, s, e, a, n) {
return st(t, s, n, wt(e, a, n)).opset;
},
doubleLineOps: function(t, s, e, a, n) {
return _(t, s, e, a, n, !0);
}
};
function vt(t, s, e, a, n) {
return {
type: "path",
ops: _(t, s, e, a, n)
};
}
function Z(t, s, e) {
const a = (t || []).length;
if (a > 2) {
const n = [];
for (let o = 0; o < a - 1; o++) n.push(..._(t[o][0], t[o][1], t[o + 1][0], t[o + 1][1], e));
return s && n.push(..._(t[a - 1][0], t[a - 1][1], t[0][0], t[0][1], e)), {
type: "path",
ops: n
};
}
return a === 2 ? vt(t[0][0], t[0][1], t[1][0], t[1][1], e) : {
type: "path",
ops: []
};
}
function Et(t, s, e, a, n) {
return (function(o, r) {
return Z(o, !0, r);
})([
[t, s],
[t + e, s],
[t + e, s + a],
[t, s + a]
], n);
}
function ut(t, s) {
if (t.length) {
const e = typeof t[0][0] == "number" ? [t] : t, a = F(e[0], 1 * (1 + 0.2 * s.roughness), s), n = s.disableMultiStroke ? [] : F(e[0], 1.5 * (1 + 0.22 * s.roughness), dt(s));
for (let o = 1; o < e.length; o++) {
const r = e[o];
if (r.length) {
const h = F(r, 1 * (1 + 0.2 * s.roughness), s), i = s.disableMultiStroke ? [] : F(r, 1.5 * (1 + 0.22 * s.roughness), dt(s));
for (const c of h) c.op !== "move" && a.push(c);
for (const c of i) c.op !== "move" && n.push(c);
}
}
return {
type: "path",
ops: a.concat(n)
};
}
return {
type: "path",
ops: []
};
}
function wt(t, s, e) {
const a = Math.sqrt(2 * Math.PI * Math.sqrt((Math.pow(t / 2, 2) + Math.pow(s / 2, 2)) / 2)), n = Math.ceil(Math.max(e.curveStepCount, e.curveStepCount / Math.sqrt(200) * a)), o = 2 * Math.PI / n;
let r = Math.abs(t / 2), h = Math.abs(s / 2);
const i = 1 - e.curveFitting;
return r += b(r * i, e), h += b(h * i, e), {
increment: o,
rx: r,
ry: h
};
}
function st(t, s, e, a) {
const [n, o] = gt(a.increment, t, s, a.rx, a.ry, 1, a.increment * H(0.1, H(0.4, 1, e), e), e);
let r = N(n, null, e);
if (!e.disableMultiStroke && e.roughness !== 0) {
const [h] = gt(a.increment, t, s, a.rx, a.ry, 1.5, 0, e), i = N(h, null, e);
r = r.concat(i);
}
return {
estimatedPoints: o,
opset: {
type: "path",
ops: r
}
};
}
function pt(t, s, e, a, n, o, r, h, i) {
const c = t, l = s;
let d = Math.abs(e / 2), f = Math.abs(a / 2);
d += b(0.01 * d, i), f += b(0.01 * f, i);
let u = n, p = o;
for (; u < 0; ) u += 2 * Math.PI, p += 2 * Math.PI;
p - u > 2 * Math.PI && (u = 0, p = 2 * Math.PI);
const k = 2 * Math.PI / i.curveStepCount, g = Math.min(k / 2, (p - u) / 2), m = Mt(g, c, l, d, f, u, p, 1, i);
if (!i.disableMultiStroke) {
const M = Mt(g, c, l, d, f, u, p, 1.5, i);
m.push(...M);
}
return r && (h ? m.push(..._(c, l, c + d * Math.cos(u), l + f * Math.sin(u), i), ..._(c, l, c + d * Math.cos(p), l + f * Math.sin(p), i)) : m.push({
op: "lineTo",
data: [c, l]
}, {
op: "lineTo",
data: [c + d * Math.cos(u), l + f * Math.sin(u)]
})), {
type: "path",
ops: m
};
}
function ft(t, s) {
const e = yt(bt(ht(t))), a = [];
let n = [0, 0], o = [0, 0];
for (const { key: r, data: h } of e) switch (r) {
case "M":
o = [h[0], h[1]], n = [h[0], h[1]];
break;
case "L":
a.push(..._(o[0], o[1], h[0], h[1], s)), o = [h[0], h[1]];
break;
case "C": {
const [i, c, l, d, f, u] = h;
a.push(...Gt(i, c, l, d, f, u, o, s)), o = [f, u];
break;
}
case "Z":
a.push(..._(o[0], o[1], n[0], n[1], s)), o = [n[0], n[1]];
}
return {
type: "path",
ops: a
};
}
function tt(t, s) {
const e = [];
for (const a of t) if (a.length) {
const n = s.maxRandomnessOffset || 0, o = a.length;
if (o > 2) {
e.push({
op: "move",
data: [a[0][0] + b(n, s), a[0][1] + b(n, s)]
});
for (let r = 1; r < o; r++) e.push({
op: "lineTo",
data: [a[r][0] + b(n, s), a[r][1] + b(n, s)]
});
}
}
return {
type: "fillPath",
ops: e
};
}
function E(t, s) {
return (function(e, a) {
let n = e.fillStyle || "hachure";
if (!S[n]) switch (n) {
case "zigzag":
S[n] || (S[n] = new Tt(a));
break;
case "cross-hatch":
S[n] || (S[n] = new Dt(a));
break;
case "dots":
S[n] || (S[n] = new At(a));
break;
case "dashed":
S[n] || (S[n] = new _t(a));
break;
case "zigzag-line":
S[n] || (S[n] = new It(a));
break;
default:
n = "hachure", S[n] || (S[n] = new ot(a));
}
return S[n];
})(s, Wt).fillPolygons(t, s);
}
function dt(t) {
const s = Object.assign({}, t);
return s.randomizer = void 0, t.seed && (s.seed = t.seed + 1), s;
}
function xt(t) {
return t.randomizer || (t.randomizer = new Ct(t.seed || 0)), t.randomizer.next();
}
function H(t, s, e, a = 1) {
return e.roughness * a * (xt(e) * (s - t) + t);
}
function b(t, s, e = 1) {
return H(-t, t, s, e);
}
function _(t, s, e, a, n, o = !1) {
const r = o ? n.disableMultiStrokeFill : n.disableMultiStroke, h = nt(t, s, e, a, n, !0, !1);
if (r) return h;
const i = nt(t, s, e, a, n, !0, !0);
return h.concat(i);
}
function nt(t, s, e, a, n, o, r) {
const h = Math.pow(t - e, 2) + Math.pow(s - a, 2), i = Math.sqrt(h);
let c = 1;
c = i < 200 ? 1 : i > 500 ? 0.4 : -16668e-7 * i + 1.233334;
let l = n.maxRandomnessOffset || 0;
l * l * 100 > h && (l = i / 10);
const d = l / 2, f = 0.2 + 0.2 * xt(n);
let u = n.bowing * n.maxRandomnessOffset * (a - s) / 200, p = n.bowing * n.maxRandomnessOffset * (t - e) / 200;
u = b(u, n, c), p = b(p, n, c);
const k = [], g = () => b(d, n, c), m = () => b(l, n, c), M = n.preserveVertices;
return o && (r ? k.push({
op: "move",
data: [t + (M ? 0 : g()), s + (M ? 0 : g())]
}) : k.push({
op: "move",
data: [t + (M ? 0 : b(l, n, c)), s + (M ? 0 : b(l, n, c))]
})), r ? k.push({
op: "bcurveTo",
data: [
u + t + (e - t) * f + g(),
p + s + (a - s) * f + g(),
u + t + 2 * (e - t) * f + g(),
p + s + 2 * (a - s) * f + g(),
e + (M ? 0 : g()),
a + (M ? 0 : g())
]
}) : k.push({
op: "bcurveTo",
data: [
u + t + (e - t) * f + m(),
p + s + (a - s) * f + m(),
u + t + 2 * (e - t) * f + m(),
p + s + 2 * (a - s) * f + m(),
e + (M ? 0 : m()),
a + (M ? 0 : m())
]
}), k;
}
function F(t, s, e) {
if (!t.length) return [];
const a = [];
a.push([t[0][0] + b(s, e), t[0][1] + b(s, e)]), a.push([t[0][0] + b(s, e), t[0][1] + b(s, e)]);
for (let n = 1; n < t.length; n++) a.push([t[n][0] + b(s, e), t[n][1] + b(s, e)]), n === t.length - 1 && a.push([t[n][0] + b(s, e), t[n][1] + b(s, e)]);
return N(a, null, e);
}
function N(t, s, e) {
const a = t.length, n = [];
if (a > 3) {
const o = [], r = 1 - e.curveTightness;
n.push({
op: "move",
data: [t[1][0], t[1][1]]
});
for (let h = 1; h + 2 < a; h++) {
const i = t[h];
o[0] = [i[0], i[1]], o[1] = [i[0] + (r * t[h + 1][0] - r * t[h - 1][0]) / 6, i[1] + (r * t[h + 1][1] - r * t[h - 1][1]) / 6], o[2] = [t[h + 1][0] + (r * t[h][0] - r * t[h + 2][0]) / 6, t[h + 1][1] + (r * t[h][1] - r * t[h + 2][1]) / 6], o[3] = [t[h + 1][0], t[h + 1][1]], n.push({
op: "bcurveTo",
data: [
o[1][0],
o[1][1],
o[2][0],
o[2][1],
o[3][0],
o[3][1]
]
});
}
if (s && s.length === 2) {
const h = e.maxRandomnessOffset;
n.push({
op: "lineTo",
data: [s[0] + b(h, e), s[1] + b(h, e)]
});
}
} else a === 3 ? (n.push({
op: "move",
data: [t[1][0], t[1][1]]
}), n.push({
op: "bcurveTo",
data: [
t[1][0],
t[1][1],
t[2][0],
t[2][1],
t[2][0],
t[2][1]
]
})) : a === 2 && n.push(...nt(t[0][0], t[0][1], t[1][0], t[1][1], e, !0, !0));
return n;
}
function gt(t, s, e, a, n, o, r, h) {
const i = [], c = [];
if (h.roughness === 0) {
t /= 4, c.push([s + a * Math.cos(-t), e + n * Math.sin(-t)]);
for (let l = 0; l <= 2 * Math.PI; l += t) {
const d = [s + a * Math.cos(l), e + n * Math.sin(l)];
i.push(d), c.push(d);
}
c.push([s + a * Math.cos(0), e + n * Math.sin(0)]), c.push([s + a * Math.cos(t), e + n * Math.sin(t)]);
} else {
const l = b(0.5, h) - Math.PI / 2;
c.push([b(o, h) + s + 0.9 * a * Math.cos(l - t), b(o, h) + e + 0.9 * n * Math.sin(l - t)]);
const d = 2 * Math.PI + l - 0.01;
for (let f = l; f < d; f += t) {
const u = [b(o, h) + s + a * Math.cos(f), b(o, h) + e + n * Math.sin(f)];
i.push(u), c.push(u);
}
c.push([b(o, h) + s + a * Math.cos(l + 2 * Math.PI + 0.5 * r), b(o, h) + e + n * Math.sin(l + 2 * Math.PI + 0.5 * r)]), c.push([b(o, h) + s + 0.98 * a * Math.cos(l + r), b(o, h) + e + 0.98 * n * Math.sin(l + r)]), c.push([b(o, h) + s + 0.9 * a * Math.cos(l + 0.5 * r), b(o, h) + e + 0.9 * n * Math.sin(l + 0.5 * r)]);
}
return [c, i];
}
function Mt(t, s, e, a, n, o, r, h, i) {
const c = o + b(0.1, i), l = [];
l.push([b(h, i) + s + 0.9 * a * Math.cos(c - t), b(h, i) + e + 0.9 * n * Math.sin(c - t)]);
for (let d = c; d <= r; d += t) l.push([b(h, i) + s + a * Math.cos(d), b(h, i) + e + n * Math.sin(d)]);
return l.push([s + a * Math.cos(r), e + n * Math.sin(r)]), l.push([s + a * Math.cos(r), e + n * Math.sin(r)]), N(l, null, i);
}
function Gt(t, s, e, a, n, o, r, h) {
const i = [], c = [h.maxRandomnessOffset || 1, (h.maxRandomnessOffset || 1) + 0.3];
let l = [0, 0];
const d = h.disableMultiStroke ? 1 : 2, f = h.preserveVertices;
for (let u = 0; u < d; u++) u === 0 ? i.push({
op: "move",
data: [r[0], r[1]]
}) : i.push({
op: "move",
data: [r[0] + (f ? 0 : b(c[0], h)), r[1] + (f ? 0 : b(c[0], h))]
}), l = f ? [n, o] : [n + b(c[u], h), o + b(c[u], h)], i.push({
op: "bcurveTo",
data: [
t + b(c[u], h),
s + b(c[u], h),
e + b(c[u], h),
a + b(c[u], h),
l[0],
l[1]
]
});
return i;
}
function $(t) {
return [...t];
}
function kt(t, s = 0) {
const e = t.length;
if (e < 3) throw new Error("A curve must have at least three points.");
const a = [];
if (e === 3) a.push($(t[0]), $(t[1]), $(t[2]), $(t[2]));
else {
const n = [];
n.push(t[0], t[0]);
for (let h = 1; h < t.length; h++) n.push(t[h]), h === t.length - 1 && n.push(t[h]);
const o = [], r = 1 - s;
a.push($(n[0]));
for (let h = 1; h + 2 < n.length; h++) {
const i = n[h];
o[0] = [i[0], i[1]], o[1] = [i[0] + (r * n[h + 1][0] - r * n[h - 1][0]) / 6, i[1] + (r * n[h + 1][1] - r * n[h - 1][1]) / 6], o[2] = [n[h + 1][0] + (r * n[h][0] - r * n[h + 2][0]) / 6, n[h + 1][1] + (r * n[h][1] - r * n[h + 2][1]) / 6], o[3] = [n[h + 1][0], n[h + 1][1]], a.push(o[1], o[2], o[3]);
}
}
return a;
}
function Q(t, s) {
return Math.pow(t[0] - s[0], 2) + Math.pow(t[1] - s[1], 2);
}
function $t(t, s, e) {
const a = Q(s, e);
if (a === 0) return Q(t, s);
let n = ((t[0] - s[0]) * (e[0] - s[0]) + (t[1] - s[1]) * (e[1] - s[1])) / a;
return n = Math.max(0, Math.min(1, n)), Q(t, C(s, e, n));
}
function C(t, s, e) {
return [t[0] + (s[0] - t[0]) * e, t[1] + (s[1] - t[1]) * e];
}
function at(t, s, e, a) {
const n = a || [];
if ((function(h, i) {
const c = h[i + 0], l = h[i + 1], d = h[i + 2], f = h[i + 3];
let u = 3 * l[0] - 2 * c[0] - f[0];
u *= u;
let p = 3 * l[1] - 2 * c[1] - f[1];
p *= p;
let k = 3 * d[0] - 2 * f[0] - c[0];
k *= k;
let g = 3 * d[1] - 2 * f[1] - c[1];
return g *= g, u < k && (u = k), p < g && (p = g), u + p;
})(t, s) < e) {
const h = t[s + 0];
n.length ? (o = n[n.length - 1], r = h, Math.sqrt(Q(o, r)) > 1 && n.push(h)) : n.push(h), n.push(t[s + 3]);
} else {
const i = t[s + 0], c = t[s + 1], l = t[s + 2], d = t[s + 3], f = C(i, c, 0.5), u = C(c, l, 0.5), p = C(l, d, 0.5), k = C(f, u, 0.5), g = C(u, p, 0.5), m = C(k, g, 0.5);
at([
i,
f,
k,
m
], 0, e, n), at([
m,
g,
p,
d
], 0, e, n);
}
var o, r;
return n;
}
function Rt(t, s) {
return B(t, 0, t.length, s);
}
function B(t, s, e, a, n) {
const o = n || [], r = t[s], h = t[e - 1];
let i = 0, c = 1;
for (let l = s + 1; l < e - 1; ++l) {
const d = $t(t[l], r, h);
d > i && (i = d, c = l);
}
return Math.sqrt(i) > a ? (B(t, s, c + 1, a, o), B(t, c, e, a, o)) : (o.length || o.push(r), o.push(h)), o;
}
function et(t, s = 0.15, e) {
const a = [], n = (t.length - 1) / 3;
for (let o = 0; o < n; o++) at(t, 3 * o, s, a);
return e && e > 0 ? B(a, 0, a.length, e) : a;
}
var O = "none", J = class {
constructor(t) {
this.defaultOptions = {
maxRandomnessOffset: 2,
roughness: 1,
bowing: 1,
stroke: "#000",
strokeWidth: 1,
curveTightness: 0,
curveFitting: 0.95,
curveStepCount: 9,
fillStyle: "hachure",
fillWeight: -1,
hachureAngle: -41,
hachureGap: -1,
dashOffset: -1,
dashGap: -1,
zigzagOffset: -1,
seed: 0,
disableMultiStroke: !1,
disableMultiStrokeFill: !1,
preserveVertices: !1,
fillShapeRoughnessGain: 0.8
}, this.config = t || {}, this.config.options && (this.defaultOptions = this._o(this.config.options));
}
static newSeed() {
return Math.floor(Math.random() * 2 ** 31);
}
_o(t) {
return t ? Object.assign({}, this.defaultOptions, t) : this.defaultOptions;
}
_d(t, s, e) {
return {
shape: t,
sets: s || [],
options: e || this.defaultOptions
};
}
line(t, s, e, a, n) {
const o = this._o(n);
return this._d("line", [vt(t, s, e, a, o)], o);
}
rectangle(t, s, e, a, n) {
const o = this._o(n), r = [], h = Et(t, s, e, a, o);
if (o.fill) {
const i = [
[t, s],
[t + e, s],
[t + e, s + a],
[t, s + a]
];
o.fillStyle === "solid" ? r.push(tt([i], o)) : r.push(E([i], o));
}
return o.stroke !== O && r.push(h), this._d("rectangle", r, o);
}
ellipse(t, s, e, a, n) {
const o = this._o(n), r = [], h = wt(e, a, o), i = st(t, s, o, h);
if (o.fill) if (o.fillStyle === "solid") {
const c = st(t, s, o, h).opset;
c.type = "fillPath", r.push(c);
} else r.push(E([i.estimatedPoints], o));
return o.stroke !== O && r.push(i.opset), this._d("ellipse", r, o);
}
circle(t, s, e, a) {
const n = this.ellipse(t, s, e, e, a);
return n.shape = "circle", n;
}
linearPath(t, s) {
const e = this._o(s);
return this._d("linearPath", [Z(t, !1, e)], e);
}
arc(t, s, e, a, n, o, r = !1, h) {
const i = this._o(h), c = [], l = pt(t, s, e, a, n, o, r, !0, i);
if (r && i.fill) if (i.fillStyle === "solid") {
const d = Object.assign({}, i);
d.disableMultiStroke = !0;
const f = pt(t, s, e, a, n, o, !0, !1, d);
f.type = "fillPath", c.push(f);
} else c.push((function(d, f, u, p, k, g, m) {
const M = d, y = f;
let w = Math.abs(u / 2), v = Math.abs(p / 2);
w += b(0.01 * w, m), v += b(0.01 * v, m);
let P = k, D = g;
for (; P < 0; ) P += 2 * Math.PI, D += 2 * Math.PI;
D - P > 2 * Math.PI && (P = 0, D = 2 * Math.PI);
const j = (D - P) / m.curveStepCount, I = [];
for (let T = P; T <= D; T += j) I.push([M + w * Math.cos(T), y + v * Math.sin(T)]);
return I.push([M + w * Math.cos(D), y + v * Math.sin(D)]), I.push([M, y]), E([I], m);
})(t, s, e, a, n, o, i));
return i.stroke !== O && c.push(l), this._d("arc", c, i);
}
curve(t, s) {
const e = this._o(s), a = [], n = ut(t, e);
if (e.fill && e.fill !== O) if (e.fillStyle === "solid") {
const o = ut(t, Object.assign(Object.assign({}, e), {
disableMultiStroke: !0,
roughness: e.roughness ? e.roughness + e.fillShapeRoughnessGain : 0
}));
a.push({
type: "fillPath",
ops: this._mergedShape(o.ops)
});
} else {
const o = [], r = t;
if (r.length) {
const h = typeof r[0][0] == "number" ? [r] : r;
for (const i of h) i.length < 3 ? o.push(...i) : i.length === 3 ? o.push(...et(kt([
i[0],
i[0],
i[1],
i[2]
]), 10, (1 + e.roughness) / 2)) : o.push(...et(kt(i), 10, (1 + e.roughness) / 2));
}
o.length && a.push(E([o], e));
}
return e.stroke !== O && a.push(n), this._d("curve", a, e);
}
polygon(t, s) {
const e = this._o(s), a = [], n = Z(t, !0, e);
return e.fill && (e.fillStyle === "solid" ? a.push(tt([t], e)) : a.push(E([t], e))), e.stroke !== O && a.push(n), this._d("polygon", a, e);
}
path(t, s) {
const e = this._o(s), a = [];
if (!t) return this._d("path", a, e);
t = (t || "").replace(/\n/g, " ").replace(/(-\s)/g, "-").replace("/(ss)/g", " ");
const n = e.fill && e.fill !== "transparent" && e.fill !== O, o = e.stroke !== O, r = !!(e.simplification && e.simplification < 1), h = (function(c, l, d) {
const f = yt(bt(ht(c))), u = [];
let p = [], k = [0, 0], g = [];
const m = () => {
g.length >= 4 && p.push(...et(g, l)), g = [];
}, M = () => {
m(), p.length && (u.push(p), p = []);
};
for (const { key: w, data: v } of f) switch (w) {
case "M":
M(), k = [v[0], v[1]], p.push(k);
break;
case "L":
m(), p.push([v[0], v[1]]);
break;
case "C":
if (!g.length) {
const P = p.length ? p[p.length - 1] : k;
g.push([P[0], P[1]]);
}
g.push([v[0], v[1]]), g.push([v[2], v[3]]), g.push([v[4], v[5]]);
break;
case "Z":
m(), p.push([k[0], k[1]]);
}
if (M(), !d) return u;
const y = [];
for (const w of u) {
const v = Rt(w, d);
v.length && y.push(v);
}
return y;
})(t, 1, r ? 4 - 4 * (e.simplification || 1) : (1 + e.roughness) / 2), i = ft(t, e);
if (n) if (e.fillStyle === "solid") if (h.length === 1) {
const c = ft(t, Object.assign(Object.assign({}, e), {
disableMultiStroke: !0,
roughness: e.roughness ? e.roughness + e.fillShapeRoughnessGain : 0
}));
a.push({
type: "fillPath",
ops: this._mergedShape(c.ops)
});
} else a.push(tt(h, e));
else a.push(E(h, e));
return o && (r ? h.forEach(((c) => {
a.push(Z(c, !1, e));
})) : a.push(i)), this._d("path", a, e);
}
opsToPath(t, s) {
let e = "";
for (const a of t.ops) {
const n = typeof s == "number" && s >= 0 ? a.data.map(((o) => +o.toFixed(s))) : a.data;
switch (a.op) {
case "move":
e += `M${n[0]} ${n[1]} `;
break;
case "bcurveTo":
e += `C${n[0]} ${n[1]}, ${n[2]} ${n[3]}, ${n[4]} ${n[5]} `;
break;
case "lineTo":
e += `L${n[0]} ${n[1]} `;
}
}
return e.trim();
}
toPaths(t) {
const s = t.sets || [], e = t.options || this.defaultOptions, a = [];
for (const n of s) {
let o = null;
switch (n.type) {
case "path":
o = {
d: this.opsToPath(n),
stroke: e.stroke,
strokeWidth: e.strokeWidth,
fill: O
};
break;
case "fillPath":
o = {
d: this.opsToPath(n),
stroke: O,
strokeWidth: 0,
fill: e.fill || O
};
break;
case "fillSketch":
o = this.fillSketch(n, e);
}
o && a.push(o);
}
return a;
}
fillSketch(t, s) {
let e = s.fillWeight;
return e < 0 && (e = s.strokeWidth / 2), {
d: this.opsToPath(t),
stroke: s.fill || O,
strokeWidth: e,
fill: O
};
}
_mergedShape(t) {
return t.filter(((s, e) => e === 0 || s.op !== "move"));
}
}, jt = class {
constructor(t, s) {
this.canvas = t, this.ctx = this.canvas.getContext("2d"), this.gen = new J(s);
}
draw(t) {
const s = t.sets || [], e = t.options || this.getDefaultOptions(), a = this.ctx, n = t.options.fixedDecimalPlaceDigits;
for (const o of s) switch (o.type) {
case "path":
a.save(), a.strokeStyle = e.stroke === "none" ? "transparent" : e.stroke, a.lineWidth = e.strokeWidth, e.strokeLineDash && a.setLineDash(e.strokeLineDash), e.strokeLineDashOffset && (a.lineDashOffset = e.strokeLineDashOffset), this._drawToContext(a, o, n), a.restore();
break;
case "fillPath": {
a.save(), a.fillStyle = e.fill || "";
const r = t.shape === "curve" || t.shape === "polygon" || t.shape === "path" ? "evenodd" : "nonzero";
this._drawToContext(a, o, n, r), a.restore();
break;
}
case "fillSketch":
this.fillSketch(a, o, e);
}
}
fillSketch(t, s, e) {
let a = e.fillWeight;
a < 0 && (a = e.strokeWidth / 2), t.save(), e.fillLineDash && t.setLineDash(e.fillLineDash), e.fillLineDashOffset && (t.lineDashOffset = e.fillLineDashOffset), t.strokeStyle = e.fill || "", t.lineWidth = a, this._drawToContext(t, s, e.fixedDecimalPlaceDigits), t.restore();
}
_drawToContext(t, s, e, a = "nonzero") {
t.beginPath();
for (const n of s.ops) {
const o = typeof e == "number" && e >= 0 ? n.data.map(((r) => +r.toFixed(e))) : n.data;
switch (n.op) {
case "move":
t.moveTo(o[0], o[1]);
break;
case "bcurveTo":
t.bezierCurveTo(o[0], o[1], o[2], o[3], o[4], o[5]);
break;
case "lineTo":
t.lineTo(o[0], o[1]);
}
}
s.type === "fillPath" ? t.fill(a) : t.stroke();
}
get generator() {
return this.gen;
}
getDefaultOptions() {
return this.gen.defaultOptions;
}
line(t, s, e, a, n) {
const o = this.gen.line(t, s, e, a, n);
return this.draw(o), o;
}
rectangle(t, s, e, a, n) {
const o = this.gen.rectangle(t, s, e, a, n);
return this.draw(o), o;
}
ellipse(t, s, e, a, n) {
const o = this.gen.ellipse(t, s, e, a, n);
return this.draw(o), o;
}
circle(t, s, e, a) {
const n = this.gen.circle(t, s, e, a);
return this.draw(n), n;
}
linearPath(t, s) {
const e = this.gen.linearPath(t, s);
return this.draw(e), e;
}
polygon(t, s) {
const e = this.gen.polygon(t, s);
return this.draw(e), e;
}
arc(t, s, e, a, n, o, r = !1, h) {
const i = this.gen.arc(t, s, e, a, n, o, r, h);
return this.draw(i), i;
}
curve(t, s) {
const e = this.gen.curve(t, s);
return this.draw(e), e;
}
path(t, s) {
const e = this.gen.path(t, s);
return this.draw(e), e;
}
}, V = "http://www.w3.org/2000/svg", qt = class {
constructor(t, s) {
this.svg = t, this.gen = new J(s);
}
draw(t) {
const s = t.sets || [], e = t.options || this.getDefaultOptions(), a = this.svg.ownerDocument || window.document, n = a.createElementNS(V, "g"), o = t.options.fixedDecimalPlaceDigits;
for (const r of s) {
let h = null;
switch (r.type) {
case "path":
h = a.createElementNS(V, "path"), h.setAttribute("d", this.opsToPath(r, o)), h.setAttribute("stroke", e.stroke), h.setAttribute("stroke-width", e.strokeWidth + ""), h.setAttribute("fill", "none"), e.strokeLineDash && h.setAttribute("stroke-dasharray", e.strokeLineDash.join(" ").trim()), e.strokeLineDashOffset && h.setAttribute("stroke-dashoffset", `${e.strokeLineDashOffset}`);
break;
case "fillPath":
h = a.createElementNS(V, "path"), h.setAttribute("d", this.opsToPath(r, o)), h.setAttribute("stroke", "none"), h.setAttribute("stroke-width", "0"), h.setAttribute("fill", e.fill || ""), t.shape !== "curve" && t.shape !== "polygon" || h.setAttribute("fill-rule", "evenodd");
break;
case "fillSketch":
h = this.fillSketch(a, r, e);
}
h && n.appendChild(h);
}
return n;
}
fillSketch(t, s, e) {
let a = e.fillWeight;
a < 0 && (a = e.strokeWidth / 2);
const n = t.createElementNS(V, "path");
return n.setAttribute("d", this.opsToPath(s, e.fixedDecimalPlaceDigits)), n.setAttribute("stroke", e.fill || ""), n.setAttribute("stroke-width", a + ""), n.setAttribute("fill", "none"), e.fillLineDash && n.setAttribute("stroke-dasharray", e.fillLineDash.join(" ").trim()), e.fillLineDashOffset && n.setAttribute("stroke-dashoffset", `${e.fillLineDashOffset}`), n;
}
get generator() {
return this.gen;
}
getDefaultOptions() {
return this.gen.defaultOptions;
}
opsToPath(t, s) {
return this.gen.opsToPath(t, s);
}
line(t, s, e, a, n) {
const o = this.gen.line(t, s, e, a, n);
return this.draw(o);
}
rectangle(t, s, e, a, n) {
const o = this.gen.rectangle(t, s, e, a, n);
return this.draw(o);
}
ellipse(t, s, e, a, n) {
const o = this.gen.ellipse(t, s, e, a, n);
return this.draw(o);
}
circle(t, s, e, a) {
const n = this.gen.circle(t, s, e, a);
return this.draw(n);
}
linearPath(t, s) {
const e = this.gen.linearPath(t, s);
return this.draw(e);
}
polygon(t, s) {
const e = this.gen.polygon(t, s);
return this.draw(e);
}
arc(t, s, e, a, n, o, r = !1, h) {
const i = this.gen.arc(t, s, e, a, n, o, r, h);
return this.draw(i);
}
curve(t, s) {
const e = this.gen.curve(t, s);
return this.draw(e);
}
path(t, s) {
const e = this.gen.path(t, s);
return this.draw(e);
}
}, Ft = {
canvas: (t, s) => new jt(t, s),
svg: (t, s) => new qt(t, s),
generator: (t) => new J(t),
newSeed: () => J.newSeed()
};
export {
Ft as t
};