UNPKG

ranui

Version:

A framework-agnostic Web Components UI library built on native custom elements, with TypeScript types, light/dark theming, SSR and PWA support.

83 lines (82 loc) 3.13 kB
var M = Math.PI, c = 2 * M, p = 1e-6, m = c - p; function E(t) { this._ += t[0]; for (let i = 1, h = t.length; i < h; ++i) this._ += arguments[i] + t[i]; } function A(t) { let i = Math.floor(t); if (!(i >= 0)) throw new Error(`invalid digits: ${t}`); if (i > 15) return E; const h = 10 ** i; return function(s) { this._ += s[0]; for (let n = 1, e = s.length; n < e; ++n) this._ += Math.round(arguments[n] * h) / h + s[n]; }; } var x = class { constructor(t) { this._x0 = this._y0 = this._x1 = this._y1 = null, this._ = "", this._append = t == null ? E : A(t); } moveTo(t, i) { this._append`M${this._x0 = this._x1 = +t},${this._y0 = this._y1 = +i}`; } closePath() { this._x1 !== null && (this._x1 = this._x0, this._y1 = this._y0, this._append`Z`); } lineTo(t, i) { this._append`L${this._x1 = +t},${this._y1 = +i}`; } quadraticCurveTo(t, i, h, s) { this._append`Q${+t},${+i},${this._x1 = +h},${this._y1 = +s}`; } bezierCurveTo(t, i, h, s, n, e) { this._append`C${+t},${+i},${+h},${+s},${this._x1 = +n},${this._y1 = +e}`; } arcTo(t, i, h, s, n) { if (t = +t, i = +i, h = +h, s = +s, n = +n, n < 0) throw new Error(`negative radius: ${n}`); let e = this._x1, r = this._y1, l = h - t, $ = s - i, a = e - t, o = r - i, _ = a * a + o * o; if (this._x1 === null) this._append`M${this._x1 = t},${this._y1 = i}`; else if (_ > p) if (!(Math.abs(o * l - $ * a) > p) || !n) this._append`L${this._x1 = t},${this._y1 = i}`; else { let u = h - e, d = s - r, v = l * l + $ * $, T = u * u + d * d, y = Math.sqrt(v), g = Math.sqrt(_), w = n * Math.tan((M - Math.acos((v + _ - T) / (2 * y * g))) / 2), f = w / g, b = w / y; Math.abs(f - 1) > p && this._append`L${t + f * a},${i + f * o}`, this._append`A${n},${n},0,0,${+(o * u > a * d)},${this._x1 = t + b * l},${this._y1 = i + b * $}`; } } arc(t, i, h, s, n, e) { if (t = +t, i = +i, h = +h, e = !!e, h < 0) throw new Error(`negative radius: ${h}`); let r = h * Math.cos(s), l = h * Math.sin(s), $ = t + r, a = i + l, o = 1 ^ e, _ = e ? s - n : n - s; this._x1 === null ? this._append`M${$},${a}` : (Math.abs(this._x1 - $) > p || Math.abs(this._y1 - a) > p) && this._append`L${$},${a}`, h && (_ < 0 && (_ = _ % c + c), _ > m ? this._append`A${h},${h},0,1,${o},${t - r},${i - l}A${h},${h},0,1,${o},${this._x1 = $},${this._y1 = a}` : _ > p && this._append`A${h},${h},0,${+(_ >= M)},${o},${this._x1 = t + h * Math.cos(n)},${this._y1 = i + h * Math.sin(n)}`); } rect(t, i, h, s) { this._append`M${this._x0 = this._x1 = +t},${this._y0 = this._y1 = +i}h${h = +h}v${+s}h${-h}Z`; } toString() { return this._; } }; function L() { return new x(); } L.prototype = x.prototype; function P(t) { return function() { return t; }; } function q(t) { let i = 3; return t.digits = function(h) { if (!arguments.length) return i; if (h == null) i = null; else { const s = Math.floor(h); if (!(s >= 0)) throw new RangeError(`invalid digits: ${h}`); i = s; } return t; }, () => new x(i); } export { P as n, q as t };