@orangecheck/design 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/format.d.mts +19 -0
- package/dist/format.d.ts +19 -0
- package/dist/format.js +68 -0
- package/dist/format.js.map +1 -0
- package/dist/format.mjs +58 -0
- package/dist/format.mjs.map +1 -0
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +490 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +471 -3
- package/dist/index.mjs.map +1 -1
- package/dist/primitives.d.mts +92 -1
- package/dist/primitives.d.ts +92 -1
- package/dist/primitives.js +319 -0
- package/dist/primitives.js.map +1 -1
- package/dist/primitives.mjs +310 -3
- package/dist/primitives.mjs.map +1 -1
- package/dist/tokens.d.mts +8 -1
- package/dist/tokens.d.ts +8 -1
- package/dist/tokens.js +110 -0
- package/dist/tokens.js.map +1 -1
- package/dist/tokens.mjs +111 -2
- package/dist/tokens.mjs.map +1 -1
- package/package.json +8 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
declare const REFERENCE_BTC_USD = 95000;
|
|
2
|
+
declare function formatSats(sats: number): string;
|
|
3
|
+
declare function formatSatsCompact(sats: number): string;
|
|
4
|
+
declare function satsToUsd(sats: number, btcUsd?: number): string;
|
|
5
|
+
declare function usdToSats(usd: number, btcUsd?: number): number;
|
|
6
|
+
declare function priceBoth(sats: number, btcUsd?: number): string;
|
|
7
|
+
declare function relativeTime(when: string | number | Date): string;
|
|
8
|
+
declare function shortenAddress(value: string, head?: number, tail?: number): string;
|
|
9
|
+
type ExplorerNetwork = 'mainnet' | 'testnet' | 'signet';
|
|
10
|
+
type ExplorerTarget = {
|
|
11
|
+
address: string;
|
|
12
|
+
} | {
|
|
13
|
+
tx: string;
|
|
14
|
+
} | {
|
|
15
|
+
block: string | number;
|
|
16
|
+
};
|
|
17
|
+
declare function explorerUrl(target: ExplorerTarget, network?: ExplorerNetwork): string;
|
|
18
|
+
|
|
19
|
+
export { type ExplorerNetwork, type ExplorerTarget, REFERENCE_BTC_USD, explorerUrl, formatSats, formatSatsCompact, priceBoth, relativeTime, satsToUsd, shortenAddress, usdToSats };
|
package/dist/format.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
declare const REFERENCE_BTC_USD = 95000;
|
|
2
|
+
declare function formatSats(sats: number): string;
|
|
3
|
+
declare function formatSatsCompact(sats: number): string;
|
|
4
|
+
declare function satsToUsd(sats: number, btcUsd?: number): string;
|
|
5
|
+
declare function usdToSats(usd: number, btcUsd?: number): number;
|
|
6
|
+
declare function priceBoth(sats: number, btcUsd?: number): string;
|
|
7
|
+
declare function relativeTime(when: string | number | Date): string;
|
|
8
|
+
declare function shortenAddress(value: string, head?: number, tail?: number): string;
|
|
9
|
+
type ExplorerNetwork = 'mainnet' | 'testnet' | 'signet';
|
|
10
|
+
type ExplorerTarget = {
|
|
11
|
+
address: string;
|
|
12
|
+
} | {
|
|
13
|
+
tx: string;
|
|
14
|
+
} | {
|
|
15
|
+
block: string | number;
|
|
16
|
+
};
|
|
17
|
+
declare function explorerUrl(target: ExplorerTarget, network?: ExplorerNetwork): string;
|
|
18
|
+
|
|
19
|
+
export { type ExplorerNetwork, type ExplorerTarget, REFERENCE_BTC_USD, explorerUrl, formatSats, formatSatsCompact, priceBoth, relativeTime, satsToUsd, shortenAddress, usdToSats };
|
package/dist/format.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/format/index.ts
|
|
4
|
+
var REFERENCE_BTC_USD = 95e3;
|
|
5
|
+
function formatSats(sats) {
|
|
6
|
+
return new Intl.NumberFormat("en-US").format(Math.round(sats));
|
|
7
|
+
}
|
|
8
|
+
function formatSatsCompact(sats) {
|
|
9
|
+
const n = Math.round(sats);
|
|
10
|
+
if (n < 1e3) return `${n} sats`;
|
|
11
|
+
const k = n / 1e3;
|
|
12
|
+
return `${Number.isInteger(k) ? k : k.toFixed(1)}k sats`;
|
|
13
|
+
}
|
|
14
|
+
function satsToUsd(sats, btcUsd = REFERENCE_BTC_USD) {
|
|
15
|
+
const usd = sats / 1e8 * btcUsd;
|
|
16
|
+
if (usd > 0 && usd < 0.01) return "< $0.01";
|
|
17
|
+
const fractionDigits = usd >= 100 ? 0 : 2;
|
|
18
|
+
return new Intl.NumberFormat("en-US", {
|
|
19
|
+
style: "currency",
|
|
20
|
+
currency: "USD",
|
|
21
|
+
minimumFractionDigits: fractionDigits,
|
|
22
|
+
maximumFractionDigits: fractionDigits
|
|
23
|
+
}).format(usd);
|
|
24
|
+
}
|
|
25
|
+
function usdToSats(usd, btcUsd = REFERENCE_BTC_USD) {
|
|
26
|
+
return Math.round(usd / btcUsd * 1e8);
|
|
27
|
+
}
|
|
28
|
+
function priceBoth(sats, btcUsd = REFERENCE_BTC_USD) {
|
|
29
|
+
return `${formatSats(sats)} sats \xB7 ${satsToUsd(sats, btcUsd)}`;
|
|
30
|
+
}
|
|
31
|
+
function relativeTime(when) {
|
|
32
|
+
const t = when instanceof Date ? when.getTime() : new Date(when).getTime();
|
|
33
|
+
if (Number.isNaN(t)) return "";
|
|
34
|
+
const diff = Date.now() - t;
|
|
35
|
+
const m = Math.floor(diff / 6e4);
|
|
36
|
+
if (m < 1) return "now";
|
|
37
|
+
if (m < 60) return `${m}m ago`;
|
|
38
|
+
const h = Math.floor(m / 60);
|
|
39
|
+
if (h < 24) return `${h}h ago`;
|
|
40
|
+
const d = Math.floor(h / 24);
|
|
41
|
+
if (d < 30) return `${d}d ago`;
|
|
42
|
+
const mo = Math.floor(d / 30);
|
|
43
|
+
if (mo < 12) return `${mo}mo ago`;
|
|
44
|
+
return `${Math.floor(mo / 12)}y ago`;
|
|
45
|
+
}
|
|
46
|
+
function shortenAddress(value, head = 8, tail = 4) {
|
|
47
|
+
if (!value) return "";
|
|
48
|
+
if (value.length <= head + tail + 1) return value;
|
|
49
|
+
return `${value.slice(0, head)}\u2026${value.slice(-tail)}`;
|
|
50
|
+
}
|
|
51
|
+
function explorerUrl(target, network = "mainnet") {
|
|
52
|
+
const base = network === "mainnet" ? "https://mempool.space" : `https://mempool.space/${network}`;
|
|
53
|
+
if ("address" in target) return `${base}/address/${target.address}`;
|
|
54
|
+
if ("tx" in target) return `${base}/tx/${target.tx}`;
|
|
55
|
+
return `${base}/block/${target.block}`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
exports.REFERENCE_BTC_USD = REFERENCE_BTC_USD;
|
|
59
|
+
exports.explorerUrl = explorerUrl;
|
|
60
|
+
exports.formatSats = formatSats;
|
|
61
|
+
exports.formatSatsCompact = formatSatsCompact;
|
|
62
|
+
exports.priceBoth = priceBoth;
|
|
63
|
+
exports.relativeTime = relativeTime;
|
|
64
|
+
exports.satsToUsd = satsToUsd;
|
|
65
|
+
exports.shortenAddress = shortenAddress;
|
|
66
|
+
exports.usdToSats = usdToSats;
|
|
67
|
+
//# sourceMappingURL=format.js.map
|
|
68
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/format/index.ts"],"names":[],"mappings":";;;AAYO,IAAM,iBAAA,GAAoB;AAG1B,SAAS,WAAW,IAAA,EAAsB;AAC7C,EAAA,OAAO,IAAI,KAAK,YAAA,CAAa,OAAO,EAAE,MAAA,CAAO,IAAA,CAAK,KAAA,CAAM,IAAI,CAAC,CAAA;AACjE;AAGO,SAAS,kBAAkB,IAAA,EAAsB;AACpD,EAAA,MAAM,CAAA,GAAI,IAAA,CAAK,KAAA,CAAM,IAAI,CAAA;AACzB,EAAA,IAAI,CAAA,GAAI,GAAA,EAAM,OAAO,CAAA,EAAG,CAAC,CAAA,KAAA,CAAA;AACzB,EAAA,MAAM,IAAI,CAAA,GAAI,GAAA;AACd,EAAA,OAAO,CAAA,EAAG,OAAO,SAAA,CAAU,CAAC,IAAI,CAAA,GAAI,CAAA,CAAE,OAAA,CAAQ,CAA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,CAAA,CAAA;AAC1C,EAAA,IAAI,aAAa,MAAA,EAAQ,OAAO,GAAG,IAAI,CAAA,SAAA,EAAY,OAAO,OAAO,CAAA,CAAA;AACjE,EAAA,IAAI,QAAQ,MAAA,EAAQ,OAAO,GAAG,IAAI,CAAA,IAAA,EAAO,OAAO,EAAE,CAAA,CAAA;AAClD,EAAA,OAAO,CAAA,EAAG,IAAI,CAAA,OAAA,EAAU,MAAA,CAAO,KAAK,CAAA,CAAA;AACxC","file":"format.js","sourcesContent":["/**\n * @orangecheck/design/format — Bitcoin/money display + formatting utilities.\n *\n * Presentational only. Lifted from the canonical implementations across the\n * family (oc-me-web's utils, oc-vault-web's billing) and standardized so every\n * site formats sats, prices, addresses, and times identically. NOTE: crypto\n * (BIP-322 signing, bech32 validation) deliberately does NOT live here — that\n * belongs in a bitcoin/crypto library, not the design system.\n */\n\n/** Reference BTC/USD rate for sats↔USD display. Override per call when a live\n * rate is available; this is a display affordance, not a price oracle. */\nexport const REFERENCE_BTC_USD = 95_000;\n\n/** Format a satoshi integer as a thousands-separated string (\"12,408\"). */\nexport function formatSats(sats: number): string {\n return new Intl.NumberFormat('en-US').format(Math.round(sats));\n}\n\n/** Compact sats for buttons/chips: \"7k sats\", \"1.5k sats\", \"999 sats\". */\nexport function formatSatsCompact(sats: number): string {\n const n = Math.round(sats);\n if (n < 1000) return `${n} sats`;\n const k = n / 1000;\n return `${Number.isInteger(k) ? k : k.toFixed(1)}k sats`;\n}\n\n/** Convert sats to a USD currency string using the reference (or given) rate. */\nexport function satsToUsd(sats: number, btcUsd: number = REFERENCE_BTC_USD): string {\n const usd = (sats / 100_000_000) * btcUsd;\n if (usd > 0 && usd < 0.01) return '< $0.01';\n // Whole dollars once >= $100, cents below. min must never exceed max.\n const fractionDigits = usd >= 100 ? 0 : 2;\n return new Intl.NumberFormat('en-US', {\n style: 'currency',\n currency: 'USD',\n minimumFractionDigits: fractionDigits,\n maximumFractionDigits: fractionDigits,\n }).format(usd);\n}\n\n/** Convert a USD amount to sats using the reference (or given) rate. */\nexport function usdToSats(usd: number, btcUsd: number = REFERENCE_BTC_USD): number {\n return Math.round((usd / btcUsd) * 100_000_000);\n}\n\n/** Both denominations as one label: \"7,000 sats · $6.65\". */\nexport function priceBoth(sats: number, btcUsd: number = REFERENCE_BTC_USD): string {\n return `${formatSats(sats)} sats · ${satsToUsd(sats, btcUsd)}`;\n}\n\n/** Compact relative time — \"now\", \"3m ago\", \"2h ago\", \"4d ago\", or a date. */\nexport function relativeTime(when: string | number | Date): string {\n const t = when instanceof Date ? when.getTime() : new Date(when).getTime();\n if (Number.isNaN(t)) return '';\n const diff = Date.now() - t;\n const m = Math.floor(diff / 60_000);\n if (m < 1) return 'now';\n if (m < 60) return `${m}m ago`;\n const h = Math.floor(m / 60);\n if (h < 24) return `${h}h ago`;\n const d = Math.floor(h / 24);\n if (d < 30) return `${d}d ago`;\n const mo = Math.floor(d / 30);\n if (mo < 12) return `${mo}mo ago`;\n return `${Math.floor(mo / 12)}y ago`;\n}\n\n/**\n * Truncate a Bitcoin/Lightning address (or any long id) for display:\n * \"bc1qxy…wxyz\". Defaults match the family's most common rule (8 head / 4 tail).\n */\nexport function shortenAddress(value: string, head = 8, tail = 4): string {\n if (!value) return '';\n if (value.length <= head + tail + 1) return value;\n return `${value.slice(0, head)}…${value.slice(-tail)}`;\n}\n\nexport type ExplorerNetwork = 'mainnet' | 'testnet' | 'signet';\nexport type ExplorerTarget =\n | { address: string }\n | { tx: string }\n | { block: string | number };\n\n/** A mempool.space explorer URL for an address, tx, or block. */\nexport function explorerUrl(target: ExplorerTarget, network: ExplorerNetwork = 'mainnet'): string {\n const base =\n network === 'mainnet'\n ? 'https://mempool.space'\n : `https://mempool.space/${network}`;\n if ('address' in target) return `${base}/address/${target.address}`;\n if ('tx' in target) return `${base}/tx/${target.tx}`;\n return `${base}/block/${target.block}`;\n}\n"]}
|
package/dist/format.mjs
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// src/format/index.ts
|
|
2
|
+
var REFERENCE_BTC_USD = 95e3;
|
|
3
|
+
function formatSats(sats) {
|
|
4
|
+
return new Intl.NumberFormat("en-US").format(Math.round(sats));
|
|
5
|
+
}
|
|
6
|
+
function formatSatsCompact(sats) {
|
|
7
|
+
const n = Math.round(sats);
|
|
8
|
+
if (n < 1e3) return `${n} sats`;
|
|
9
|
+
const k = n / 1e3;
|
|
10
|
+
return `${Number.isInteger(k) ? k : k.toFixed(1)}k sats`;
|
|
11
|
+
}
|
|
12
|
+
function satsToUsd(sats, btcUsd = REFERENCE_BTC_USD) {
|
|
13
|
+
const usd = sats / 1e8 * btcUsd;
|
|
14
|
+
if (usd > 0 && usd < 0.01) return "< $0.01";
|
|
15
|
+
const fractionDigits = usd >= 100 ? 0 : 2;
|
|
16
|
+
return new Intl.NumberFormat("en-US", {
|
|
17
|
+
style: "currency",
|
|
18
|
+
currency: "USD",
|
|
19
|
+
minimumFractionDigits: fractionDigits,
|
|
20
|
+
maximumFractionDigits: fractionDigits
|
|
21
|
+
}).format(usd);
|
|
22
|
+
}
|
|
23
|
+
function usdToSats(usd, btcUsd = REFERENCE_BTC_USD) {
|
|
24
|
+
return Math.round(usd / btcUsd * 1e8);
|
|
25
|
+
}
|
|
26
|
+
function priceBoth(sats, btcUsd = REFERENCE_BTC_USD) {
|
|
27
|
+
return `${formatSats(sats)} sats \xB7 ${satsToUsd(sats, btcUsd)}`;
|
|
28
|
+
}
|
|
29
|
+
function relativeTime(when) {
|
|
30
|
+
const t = when instanceof Date ? when.getTime() : new Date(when).getTime();
|
|
31
|
+
if (Number.isNaN(t)) return "";
|
|
32
|
+
const diff = Date.now() - t;
|
|
33
|
+
const m = Math.floor(diff / 6e4);
|
|
34
|
+
if (m < 1) return "now";
|
|
35
|
+
if (m < 60) return `${m}m ago`;
|
|
36
|
+
const h = Math.floor(m / 60);
|
|
37
|
+
if (h < 24) return `${h}h ago`;
|
|
38
|
+
const d = Math.floor(h / 24);
|
|
39
|
+
if (d < 30) return `${d}d ago`;
|
|
40
|
+
const mo = Math.floor(d / 30);
|
|
41
|
+
if (mo < 12) return `${mo}mo ago`;
|
|
42
|
+
return `${Math.floor(mo / 12)}y ago`;
|
|
43
|
+
}
|
|
44
|
+
function shortenAddress(value, head = 8, tail = 4) {
|
|
45
|
+
if (!value) return "";
|
|
46
|
+
if (value.length <= head + tail + 1) return value;
|
|
47
|
+
return `${value.slice(0, head)}\u2026${value.slice(-tail)}`;
|
|
48
|
+
}
|
|
49
|
+
function explorerUrl(target, network = "mainnet") {
|
|
50
|
+
const base = network === "mainnet" ? "https://mempool.space" : `https://mempool.space/${network}`;
|
|
51
|
+
if ("address" in target) return `${base}/address/${target.address}`;
|
|
52
|
+
if ("tx" in target) return `${base}/tx/${target.tx}`;
|
|
53
|
+
return `${base}/block/${target.block}`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export { REFERENCE_BTC_USD, explorerUrl, formatSats, formatSatsCompact, priceBoth, relativeTime, satsToUsd, shortenAddress, usdToSats };
|
|
57
|
+
//# sourceMappingURL=format.mjs.map
|
|
58
|
+
//# sourceMappingURL=format.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/format/index.ts"],"names":[],"mappings":";AAYO,IAAM,iBAAA,GAAoB;AAG1B,SAAS,WAAW,IAAA,EAAsB;AAC7C,EAAA,OAAO,IAAI,KAAK,YAAA,CAAa,OAAO,EAAE,MAAA,CAAO,IAAA,CAAK,KAAA,CAAM,IAAI,CAAC,CAAA;AACjE;AAGO,SAAS,kBAAkB,IAAA,EAAsB;AACpD,EAAA,MAAM,CAAA,GAAI,IAAA,CAAK,KAAA,CAAM,IAAI,CAAA;AACzB,EAAA,IAAI,CAAA,GAAI,GAAA,EAAM,OAAO,CAAA,EAAG,CAAC,CAAA,KAAA,CAAA;AACzB,EAAA,MAAM,IAAI,CAAA,GAAI,GAAA;AACd,EAAA,OAAO,CAAA,EAAG,OAAO,SAAA,CAAU,CAAC,IA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A,KAAY,SAAA,GACN,uBAAA,GACA,yBAAyB,OAAO,CAAA,CAAA;AAC1C,EAAA,IAAI,aAAa,MAAA,EAAQ,OAAO,GAAG,IAAI,CAAA,SAAA,EAAY,OAAO,OAAO,CAAA,CAAA;AACjE,EAAA,IAAI,QAAQ,MAAA,EAAQ,OAAO,GAAG,IAAI,CAAA,IAAA,EAAO,OAAO,EAAE,CAAA,CAAA;AAClD,EAAA,OAAO,CAAA,EAAG,IAAI,CAAA,OAAA,EAAU,MAAA,CAAO,KAAK,CAAA,CAAA;AACxC","file":"format.mjs","sourcesContent":["/**\n * @orangecheck/design/format — Bitcoin/money display + formatting utilities.\n *\n * Presentational only. Lifted from the canonical implementations across the\n * family (oc-me-web's utils, oc-vault-web's billing) and standardized so every\n * site formats sats, prices, addresses, and times identically. NOTE: crypto\n * (BIP-322 signing, bech32 validation) deliberately does NOT live here — that\n * belongs in a bitcoin/crypto library, not the design system.\n */\n\n/** Reference BTC/USD rate for sats↔USD display. Override per call when a live\n * rate is available; this is a display affordance, not a price oracle. */\nexport const REFERENCE_BTC_USD = 95_000;\n\n/** Format a satoshi integer as a thousands-separated string (\"12,408\"). */\nexport function formatSats(sats: number): string {\n return new Intl.NumberFormat('en-US').format(Math.round(sats));\n}\n\n/** Compact sats for buttons/chips: \"7k sats\", \"1.5k sats\", \"999 sats\". */\nexport function formatSatsCompact(sats: number): string {\n const n = Math.round(sats);\n if (n < 1000) return `${n} sats`;\n const k = n / 1000;\n return `${Number.isInteger(k) ? k : k.toFixed(1)}k sats`;\n}\n\n/** Convert sats to a USD currency string using the reference (or given) rate. */\nexport function satsToUsd(sats: number, btcUsd: number = REFERENCE_BTC_USD): string {\n const usd = (sats / 100_000_000) * btcUsd;\n if (usd > 0 && usd < 0.01) return '< $0.01';\n // Whole dollars once >= $100, cents below. min must never exceed max.\n const fractionDigits = usd >= 100 ? 0 : 2;\n return new Intl.NumberFormat('en-US', {\n style: 'currency',\n currency: 'USD',\n minimumFractionDigits: fractionDigits,\n maximumFractionDigits: fractionDigits,\n }).format(usd);\n}\n\n/** Convert a USD amount to sats using the reference (or given) rate. */\nexport function usdToSats(usd: number, btcUsd: number = REFERENCE_BTC_USD): number {\n return Math.round((usd / btcUsd) * 100_000_000);\n}\n\n/** Both denominations as one label: \"7,000 sats · $6.65\". */\nexport function priceBoth(sats: number, btcUsd: number = REFERENCE_BTC_USD): string {\n return `${formatSats(sats)} sats · ${satsToUsd(sats, btcUsd)}`;\n}\n\n/** Compact relative time — \"now\", \"3m ago\", \"2h ago\", \"4d ago\", or a date. */\nexport function relativeTime(when: string | number | Date): string {\n const t = when instanceof Date ? when.getTime() : new Date(when).getTime();\n if (Number.isNaN(t)) return '';\n const diff = Date.now() - t;\n const m = Math.floor(diff / 60_000);\n if (m < 1) return 'now';\n if (m < 60) return `${m}m ago`;\n const h = Math.floor(m / 60);\n if (h < 24) return `${h}h ago`;\n const d = Math.floor(h / 24);\n if (d < 30) return `${d}d ago`;\n const mo = Math.floor(d / 30);\n if (mo < 12) return `${mo}mo ago`;\n return `${Math.floor(mo / 12)}y ago`;\n}\n\n/**\n * Truncate a Bitcoin/Lightning address (or any long id) for display:\n * \"bc1qxy…wxyz\". Defaults match the family's most common rule (8 head / 4 tail).\n */\nexport function shortenAddress(value: string, head = 8, tail = 4): string {\n if (!value) return '';\n if (value.length <= head + tail + 1) return value;\n return `${value.slice(0, head)}…${value.slice(-tail)}`;\n}\n\nexport type ExplorerNetwork = 'mainnet' | 'testnet' | 'signet';\nexport type ExplorerTarget =\n | { address: string }\n | { tx: string }\n | { block: string | number };\n\n/** A mempool.space explorer URL for an address, tx, or block. */\nexport function explorerUrl(target: ExplorerTarget, network: ExplorerNetwork = 'mainnet'): string {\n const base =\n network === 'mainnet'\n ? 'https://mempool.space'\n : `https://mempool.space/${network}`;\n if ('address' in target) return `${base}/address/${target.address}`;\n if ('tx' in target) return `${base}/tx/${target.tx}`;\n return `${base}/block/${target.block}`;\n}\n"]}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export { DEFAULT_OC_THEME, OC_SKIN_COOKIE, OC_THEMES, OcTheme, OcThemeBridge, OcThemeId, OcThemePicker, OcThemePickerProps, OcThemeProvider, OcThemeProviderProps, cn, getOcThemeInitScript, isKnownTheme, resolveTheme, useOcSkin } from './tokens.mjs';
|
|
2
|
-
export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, Alert, AlertDescription, AlertTitle, AlertWithAction, AlertWithActionProps, AlertWithCountdown, AlertWithCountdownProps, Badge, Button, ConfirmHost, ConfirmOptions, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, ErrorBoundary, Input, Label, Modal, ModalProps, Pagination, PaginationProps, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, PromptHost, PromptOptions, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, Sheet, SheetContent, SheetDescription, SheetHeader, SheetOverlay, SheetPortal, SheetTitle, SheetTrigger, Skeleton, SkeletonProps, Textarea, ThemeToggle, ThemeToggleLink, Toaster, Working, WorkingPanel, WorkingProps, badgeVariants, buttonVariants, confirm, prompt } from './primitives.mjs';
|
|
1
|
+
export { DEFAULT_OC_THEME, OC_SKIN_COOKIE, OC_THEMES, OcAppearanceMenu, OcAppearanceMenuProps, OcTheme, OcThemeBridge, OcThemeId, OcThemePicker, OcThemePickerProps, OcThemeProvider, OcThemeProviderProps, cn, getOcThemeInitScript, isKnownTheme, resolveTheme, useOcSkin } from './tokens.mjs';
|
|
2
|
+
export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, Alert, AlertDescription, AlertTitle, AlertWithAction, AlertWithActionProps, AlertWithCountdown, AlertWithCountdownProps, Badge, Bar, BarProps, BitcoinAddress, BitcoinAddressProps, Button, Card, CardProps, ConfirmHost, ConfirmOptions, CopyButton, CopyButtonProps, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, ErrorBoundary, Input, Label, Modal, ModalProps, Pagination, PaginationProps, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, PromptHost, PromptOptions, QrCode, QrCodeProps, SatsAmount, SatsAmountProps, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, Sheet, SheetContent, SheetDescription, SheetHeader, SheetOverlay, SheetPortal, SheetTitle, SheetTrigger, Skeleton, SkeletonProps, Sparkline, SparklineProps, StatBlock, StatBlockProps, StatusPill, StatusPillProps, StatusTone, Textarea, ThemeToggle, ThemeToggleLink, Toaster, Working, WorkingPanel, WorkingProps, badgeVariants, buttonVariants, confirm, prompt } from './primitives.mjs';
|
|
3
3
|
export * from '@orangecheck/ui';
|
|
4
|
+
export { ExplorerNetwork, ExplorerTarget, REFERENCE_BTC_USD, explorerUrl, formatSats, formatSatsCompact, priceBoth, relativeTime, satsToUsd, shortenAddress, usdToSats } from './format.mjs';
|
|
4
5
|
import 'clsx';
|
|
5
6
|
import 'react/jsx-runtime';
|
|
6
7
|
import 'react';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export { DEFAULT_OC_THEME, OC_SKIN_COOKIE, OC_THEMES, OcTheme, OcThemeBridge, OcThemeId, OcThemePicker, OcThemePickerProps, OcThemeProvider, OcThemeProviderProps, cn, getOcThemeInitScript, isKnownTheme, resolveTheme, useOcSkin } from './tokens.js';
|
|
2
|
-
export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, Alert, AlertDescription, AlertTitle, AlertWithAction, AlertWithActionProps, AlertWithCountdown, AlertWithCountdownProps, Badge, Button, ConfirmHost, ConfirmOptions, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, ErrorBoundary, Input, Label, Modal, ModalProps, Pagination, PaginationProps, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, PromptHost, PromptOptions, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, Sheet, SheetContent, SheetDescription, SheetHeader, SheetOverlay, SheetPortal, SheetTitle, SheetTrigger, Skeleton, SkeletonProps, Textarea, ThemeToggle, ThemeToggleLink, Toaster, Working, WorkingPanel, WorkingProps, badgeVariants, buttonVariants, confirm, prompt } from './primitives.js';
|
|
1
|
+
export { DEFAULT_OC_THEME, OC_SKIN_COOKIE, OC_THEMES, OcAppearanceMenu, OcAppearanceMenuProps, OcTheme, OcThemeBridge, OcThemeId, OcThemePicker, OcThemePickerProps, OcThemeProvider, OcThemeProviderProps, cn, getOcThemeInitScript, isKnownTheme, resolveTheme, useOcSkin } from './tokens.js';
|
|
2
|
+
export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, Alert, AlertDescription, AlertTitle, AlertWithAction, AlertWithActionProps, AlertWithCountdown, AlertWithCountdownProps, Badge, Bar, BarProps, BitcoinAddress, BitcoinAddressProps, Button, Card, CardProps, ConfirmHost, ConfirmOptions, CopyButton, CopyButtonProps, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, ErrorBoundary, Input, Label, Modal, ModalProps, Pagination, PaginationProps, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, PromptHost, PromptOptions, QrCode, QrCodeProps, SatsAmount, SatsAmountProps, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, Sheet, SheetContent, SheetDescription, SheetHeader, SheetOverlay, SheetPortal, SheetTitle, SheetTrigger, Skeleton, SkeletonProps, Sparkline, SparklineProps, StatBlock, StatBlockProps, StatusPill, StatusPillProps, StatusTone, Textarea, ThemeToggle, ThemeToggleLink, Toaster, Working, WorkingPanel, WorkingProps, badgeVariants, buttonVariants, confirm, prompt } from './primitives.js';
|
|
3
3
|
export * from '@orangecheck/ui';
|
|
4
|
+
export { ExplorerNetwork, ExplorerTarget, REFERENCE_BTC_USD, explorerUrl, formatSats, formatSatsCompact, priceBoth, relativeTime, satsToUsd, shortenAddress, usdToSats } from './format.js';
|
|
4
5
|
import 'clsx';
|
|
5
6
|
import 'react/jsx-runtime';
|
|
6
7
|
import 'react';
|