1 | import {
|
2 | LocalizeController
|
3 | } from "./chunk.6WMYSCDC.js";
|
4 | import {
|
5 | e,
|
6 | n
|
7 | } from "./chunk.VKNZYXSO.js";
|
8 | import {
|
9 | s
|
10 | } from "./chunk.WWAD5WF4.js";
|
11 | import {
|
12 | __decorateClass
|
13 | } from "./chunk.K2NRSETB.js";
|
14 |
|
15 |
|
16 | var SlFormatBytes = class extends s {
|
17 | constructor() {
|
18 | super(...arguments);
|
19 | this.localize = new LocalizeController(this);
|
20 | this.value = 0;
|
21 | this.unit = "byte";
|
22 | this.display = "short";
|
23 | }
|
24 | render() {
|
25 | if (isNaN(this.value)) {
|
26 | return "";
|
27 | }
|
28 | const bitPrefixes = ["", "kilo", "mega", "giga", "tera"];
|
29 | const bytePrefixes = ["", "kilo", "mega", "giga", "tera", "peta"];
|
30 | const prefix = this.unit === "bit" ? bitPrefixes : bytePrefixes;
|
31 | const index = Math.max(0, Math.min(Math.floor(Math.log10(this.value) / 3), prefix.length - 1));
|
32 | const unit = prefix[index] + this.unit;
|
33 | const valueToFormat = parseFloat((this.value / Math.pow(1e3, index)).toPrecision(3));
|
34 | return this.localize.number(valueToFormat, {
|
35 | style: "unit",
|
36 | unit,
|
37 | unitDisplay: this.display
|
38 | });
|
39 | }
|
40 | };
|
41 | __decorateClass([
|
42 | e({ type: Number })
|
43 | ], SlFormatBytes.prototype, "value", 2);
|
44 | __decorateClass([
|
45 | e()
|
46 | ], SlFormatBytes.prototype, "unit", 2);
|
47 | __decorateClass([
|
48 | e()
|
49 | ], SlFormatBytes.prototype, "display", 2);
|
50 | __decorateClass([
|
51 | e()
|
52 | ], SlFormatBytes.prototype, "lang", 2);
|
53 | SlFormatBytes = __decorateClass([
|
54 | n("sl-format-bytes")
|
55 | ], SlFormatBytes);
|
56 |
|
57 | export {
|
58 | SlFormatBytes
|
59 | };
|