@wallet-ui/core 4.1.1 → 4.2.0-canary-20260602204251
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/README.md +0 -4
- package/dist/index.browser.cjs +76 -0
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.mjs +71 -1
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.development.js +1494 -3
- package/dist/index.development.js.map +1 -1
- package/dist/index.native.mjs +71 -1
- package/dist/index.native.mjs.map +1 -1
- package/dist/index.node.cjs +76 -0
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +71 -1
- package/dist/index.node.mjs.map +1 -1
- package/dist/index.production.min.js +37 -16
- package/dist/types/create-qr-code-svg.d.ts +14 -0
- package/dist/types/create-qr-code-svg.d.ts.map +1 -0
- package/dist/types/create-qr-code.d.ts +14 -0
- package/dist/types/create-qr-code.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +7 -9
package/README.md
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
[![npm][npm-image]][npm-url]
|
|
2
2
|
[![npm-downloads][npm-downloads-image]][npm-url]
|
|
3
|
-
<br />
|
|
4
|
-
[![code-style-prettier][code-style-prettier-image]][code-style-prettier-url]
|
|
5
3
|
|
|
6
|
-
[code-style-prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square
|
|
7
|
-
[code-style-prettier-url]: https://github.com/prettier/prettier
|
|
8
4
|
[npm-downloads-image]: https://img.shields.io/npm/dm/@wallet-ui/core/latest.svg?style=flat
|
|
9
5
|
[npm-image]: https://img.shields.io/npm/v/@wallet-ui/core/latest.svg?style=flat
|
|
10
6
|
[npm-url]: https://www.npmjs.com/package/@wallet-ui/core/v/latest
|
package/dist/index.browser.cjs
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var kit = require('@solana/kit');
|
|
4
|
+
var encodeQR = require('qr');
|
|
4
5
|
var persistent = require('@nanostores/persistent');
|
|
5
6
|
var nanostores = require('nanostores');
|
|
6
7
|
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var encodeQR__default = /*#__PURE__*/_interopDefault(encodeQR);
|
|
11
|
+
|
|
7
12
|
// src/clusters.ts
|
|
8
13
|
|
|
9
14
|
// src/types/solana-cluster.ts
|
|
@@ -57,6 +62,75 @@ function createSolanaTestnet(props = "https://api.testnet.solana.com") {
|
|
|
57
62
|
url: kit.testnet(typeof props === "string" ? props : props.url)
|
|
58
63
|
});
|
|
59
64
|
}
|
|
65
|
+
var DEFAULT_QR_CODE_BORDER = 4;
|
|
66
|
+
var DEFAULT_QR_CODE_ERROR_CORRECTION = "medium";
|
|
67
|
+
function createQrCode(value, options = {}) {
|
|
68
|
+
const border = options.border ?? DEFAULT_QR_CODE_BORDER;
|
|
69
|
+
const errorCorrection = options.errorCorrection ?? DEFAULT_QR_CODE_ERROR_CORRECTION;
|
|
70
|
+
const cells = encodeQR__default.default(value, "raw", { border, ecc: errorCorrection }).map((row) => row.map(Boolean));
|
|
71
|
+
return {
|
|
72
|
+
border,
|
|
73
|
+
cells,
|
|
74
|
+
errorCorrection,
|
|
75
|
+
size: cells.length,
|
|
76
|
+
value
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// src/create-qr-code-svg.ts
|
|
81
|
+
var DEFAULT_QR_CODE_BACKGROUND_COLOR = "#fff";
|
|
82
|
+
var DEFAULT_QR_CODE_FOREGROUND_COLOR = "#000";
|
|
83
|
+
var DEFAULT_QR_CODE_LOGO_SIZE = 0.2;
|
|
84
|
+
var LOGO_BACKGROUND_PADDING = 1;
|
|
85
|
+
var MAX_QR_CODE_LOGO_SIZE = 0.25;
|
|
86
|
+
function createQrCodeSvg(value, options = {}) {
|
|
87
|
+
const backgroundColor = options.backgroundColor ?? DEFAULT_QR_CODE_BACKGROUND_COLOR;
|
|
88
|
+
const foregroundColor = options.foregroundColor ?? DEFAULT_QR_CODE_FOREGROUND_COLOR;
|
|
89
|
+
const logo = options.logo;
|
|
90
|
+
const qrCode = createQrCode(value, {
|
|
91
|
+
border: options.border,
|
|
92
|
+
errorCorrection: options.errorCorrection ?? (logo ? "high" : void 0)
|
|
93
|
+
});
|
|
94
|
+
const title = options.title ? `<title>${escapeSvgText(options.title)}</title>` : "";
|
|
95
|
+
const background = `<rect fill="${escapeSvgAttribute(backgroundColor)}" height="${qrCode.size}" width="${qrCode.size}" x="0" y="0"/>`;
|
|
96
|
+
const foreground = `<path d="${createQrCodeSvgPath(qrCode.cells)}" fill="${escapeSvgAttribute(foregroundColor)}"/>`;
|
|
97
|
+
const logoSvg = logo ? createQrCodeLogoSvg({ backgroundColor, logo, size: qrCode.size }) : "";
|
|
98
|
+
const accessibility = options.title ? 'role="img"' : 'aria-hidden="true"';
|
|
99
|
+
return `<svg ${accessibility} shape-rendering="crispEdges" viewBox="0 0 ${qrCode.size} ${qrCode.size}" xmlns="http://www.w3.org/2000/svg">${title}${background}${foreground}${logoSvg}</svg>`;
|
|
100
|
+
}
|
|
101
|
+
function createQrCodeLogoSvg({
|
|
102
|
+
backgroundColor,
|
|
103
|
+
logo,
|
|
104
|
+
size
|
|
105
|
+
}) {
|
|
106
|
+
const logoSize = size * getQrCodeLogoSize(logo.size);
|
|
107
|
+
const logoPosition = (size - logoSize) / 2;
|
|
108
|
+
const logoBackgroundPosition = Math.max(0, Math.floor(logoPosition) - LOGO_BACKGROUND_PADDING);
|
|
109
|
+
const logoBackgroundEnd = Math.min(size, Math.ceil(logoPosition + logoSize) + LOGO_BACKGROUND_PADDING);
|
|
110
|
+
const logoBackgroundSize = logoBackgroundEnd - logoBackgroundPosition;
|
|
111
|
+
const logoBackgroundColor = logo.backgroundColor ?? backgroundColor;
|
|
112
|
+
return [
|
|
113
|
+
`<rect fill="${escapeSvgAttribute(logoBackgroundColor)}" height="${formatSvgNumber(logoBackgroundSize)}" width="${formatSvgNumber(logoBackgroundSize)}" x="${formatSvgNumber(logoBackgroundPosition)}" y="${formatSvgNumber(logoBackgroundPosition)}"/>`,
|
|
114
|
+
`<image height="${formatSvgNumber(logoSize)}" href="${escapeSvgAttribute(logo.href)}" preserveAspectRatio="xMidYMid meet" width="${formatSvgNumber(logoSize)}" x="${formatSvgNumber(logoPosition)}" y="${formatSvgNumber(logoPosition)}"/>`
|
|
115
|
+
].join("");
|
|
116
|
+
}
|
|
117
|
+
function createQrCodeSvgPath(cells) {
|
|
118
|
+
return cells.flatMap(
|
|
119
|
+
(row, rowIndex) => row.map((cell, columnIndex) => cell ? `M${columnIndex} ${rowIndex}h1v1H${columnIndex}z` : "")
|
|
120
|
+
).join("");
|
|
121
|
+
}
|
|
122
|
+
function escapeSvgAttribute(value) {
|
|
123
|
+
return value.replace(/&/g, "&").replace(/"/g, """).replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">");
|
|
124
|
+
}
|
|
125
|
+
function escapeSvgText(value) {
|
|
126
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
127
|
+
}
|
|
128
|
+
function formatSvgNumber(value) {
|
|
129
|
+
return Number(value.toFixed(6)).toString();
|
|
130
|
+
}
|
|
131
|
+
function getQrCodeLogoSize(size = DEFAULT_QR_CODE_LOGO_SIZE) {
|
|
132
|
+
return Math.min(size, MAX_QR_CODE_LOGO_SIZE);
|
|
133
|
+
}
|
|
60
134
|
var Storage = class {
|
|
61
135
|
constructor(key, initial) {
|
|
62
136
|
this.key = key;
|
|
@@ -162,6 +236,8 @@ function stringToUint8Array(value) {
|
|
|
162
236
|
}
|
|
163
237
|
|
|
164
238
|
exports.Storage = Storage;
|
|
239
|
+
exports.createQrCode = createQrCode;
|
|
240
|
+
exports.createQrCodeSvg = createQrCodeSvg;
|
|
165
241
|
exports.createSolanaDevnet = createSolanaDevnet;
|
|
166
242
|
exports.createSolanaLocalnet = createSolanaLocalnet;
|
|
167
243
|
exports.createSolanaMainnet = createSolanaMainnet;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types/solana-cluster.ts","../src/clusters.ts","../src/storage.ts","../src/create-storage.ts","../src/create-storage-account.ts","../src/create-storage-cluster.ts","../src/get-explorer-url.ts","../src/handle-copy-text.ts","../src/string-to-uint8-array.ts"],"names":["devnet","mainnet","testnet","persistentAtom","computed"],"mappings":";;;;;;;;;AAYO,SAAS,SAAS,GAAA,EAAa;AAClC,EAAA,OAAO,GAAA;AACX;;;ACRA,SAAS,mBAAA,CACL,OACA,EAAE,EAAA,EAAI,OAAO,GAAA,EAAK,UAAA,EAAY,KAAA,EAAO,YAAA,EAAa,EACrC;AACb,EAAA,IAAI,OAAO,UAAU,QAAA,EAAU;AAC3B,IAAA,OAAO,EAAE,EAAA,EAAI,KAAA,EAAO,GAAA,EAAK,KAAA,EAAM;AAAA,EACnC;AAEA,EAAA,OAAO;AAAA,IACH,EAAA;AAAA,IACA,KAAA,EAAO,MAAM,KAAA,IAAS,KAAA;AAAA,IACtB,GAAA,EAAK,MAAM,GAAA,IAAO,UAAA;AAAA,IAClB,KAAA,EAAO,MAAM,KAAA,IAAS;AAAA,GAC1B;AACJ;AAEO,SAAS,kBAAA,CAAmB,QAA2B,+BAAA,EAAgD;AAC1G,EAAA,OAAO,oBAAoB,KAAA,EAAO;AAAA,IAC9B,EAAA,EAAI,eAAA;AAAA,IACJ,KAAA,EAAO,QAAA;AAAA,IACP,KAAKA,UAAA,CAAO,OAAO,UAAU,QAAA,GAAW,KAAA,GAAQ,MAAM,GAAG;AAAA,GAC5D,CAAA;AACL;AAEO,SAAS,oBAAA,CAAqB,QAA2B,uBAAA,EAAwC;AACpG,EAAA,MAAM,GAAA,GAAM,OAAO,KAAA,KAAU,QAAA,GAAW,QAAQ,KAAA,CAAM,GAAA;AACtD,EAAA,MAAM,KAAA,GAAQ,OAAO,KAAA,KAAU,Q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A,EAAW,SAAA,EAAW,EAAA,EAAG;AAAA,IAC/C;AACI,MAAA,OAAO,EAAE,OAAA,EAAS,EAAA,EAAI,SAAA,EAAW,EAAA,EAAG;AAAA;AAEhD;;;AC7DO,SAAS,eAAe,IAAA,EAAe;AAC1C,EAAA,IAAI,CAAC,IAAA,EAAM;AACP,IAAA;AAAA,EACJ;AACA,EAAA,IACI,OAAO,UAAA,KAAe,WAAA,IACtB,CAAC,WAAW,SAAA,IACZ,CAAC,UAAA,CAAW,SAAA,CAAU,SAAA,IACtB,CAAC,UAAA,CAAW,SAAA,CAAU,UAAU,SAAA,EAClC;AACE,IAAA;AAAA,EACJ;AACA,EAAA,KAAK,UAAA,CAAW,SAAA,CAAU,SAAA,CAAU,SAAA,CAAU,IAAI,CAAA;AACtD;;;ACbO,SAAS,mBAAmB,KAAA,EAAwC;AACvE,EAAA,OAAO,iBAAiB,UAAA,GAAa,KAAA,GAAQ,IAAI,WAAA,EAAY,CAAE,OAAO,KAAK,CAAA;AAC/E","file":"index.browser.cjs","sourcesContent":["import type {\n DevnetUrl as SolanaDevnetUrl,\n MainnetUrl as SolanaMainnetUrl,\n TestnetUrl as SolanaTestnetUrl,\n} from '@solana/kit';\n\nimport { SolanaClusterId } from './solana-cluster-id';\n\nexport type { SolanaDevnetUrl, SolanaMainnetUrl, SolanaTestnetUrl };\n\nexport type SolanaLocalnetUrl = string & { '~cluster': 'localnet' };\n\nexport function localnet(url: string) {\n return url as SolanaLocalnetUrl;\n}\n\nexport interface SolanaCluster {\n id: SolanaClusterId;\n label: string;\n url: SolanaDevnetUrl | SolanaLocalnetUrl | SolanaMainnetUrl | SolanaTestnetUrl | string;\n urlWs?: string;\n}\n","import { devnet, mainnet, testnet } from '@solana/kit';\n\nimport { localnet, SolanaCluster } from './types/solana-cluster';\n\nexport type CreateSolanaProps = string | (Partial<Pick<SolanaCluster, 'label' | 'url' | 'urlWs'>> & { url: string });\n\nfunction createSolanaCluster(\n props: CreateSolanaProps,\n { id, label, url: defaultUrl, urlWs: defaultUrlWs }: Pick<SolanaCluster, 'id' | 'label' | 'url' | 'urlWs'>,\n): SolanaCluster {\n if (typeof props === 'string') {\n return { id, label, url: props };\n }\n\n return {\n id,\n label: props.label ?? label,\n url: props.url ?? defaultUrl,\n urlWs: props.urlWs ?? defaultUrlWs,\n };\n}\n\nexport function createSolanaDevnet(props: CreateSolanaProps = 'https://api.devnet.solana.com'): SolanaCluster {\n return createSolanaCluster(props, {\n id: 'solana:devnet',\n label: 'Devnet',\n url: devnet(typeof props === 'string' ? props : props.url),\n });\n}\n\nexport function createSolanaLocalnet(props: CreateSolanaProps = 'http://localhost:8899'): SolanaCluster {\n const url = typeof props === 'string' ? props : props.url;\n const urlWs = typeof props !== 'string' ? (props.urlWs ?? getLocalUrlWs(url)) : undefined;\n return createSolanaCluster(props, {\n id: 'solana:localnet',\n label: 'Localnet',\n url: localnet(url),\n urlWs,\n });\n}\n\nfunction getLocalUrlWs(url: string) {\n return url.endsWith(':8899') ? url.replace(':8899', ':8900').replace('http', 'ws') : undefined;\n}\nexport function createSolanaMainnet(props: CreateSolanaProps): SolanaCluster {\n return createSolanaCluster(props, {\n id: 'solana:mainnet',\n label: 'Mainnet',\n url: mainnet(typeof props === 'string' ? props : props.url),\n });\n}\n\nexport function createSolanaTestnet(props: CreateSolanaProps = 'https://api.testnet.solana.com'): SolanaCluster {\n return createSolanaCluster(props, {\n id: 'solana:testnet',\n label: 'Testnet',\n url: testnet(typeof props === 'string' ? props : props.url),\n });\n}\n","import { persistentAtom } from '@nanostores/persistent';\nimport { computed, WritableAtom } from 'nanostores';\n\nexport class Storage<T> {\n private readonly atom: WritableAtom<T>;\n\n constructor(\n readonly key: string,\n readonly initial: T,\n ) {\n this.atom = persistentAtom<T>(key, initial, { decode: JSON.parse, encode: JSON.stringify });\n }\n\n get() {\n return this.atom.get();\n }\n\n set(value: T) {\n this.atom.set(value);\n }\n\n get value() {\n return computed(this.atom, value => value);\n }\n}\n","import { Storage } from './storage';\n\nexport function createStorage<T>({ initial, key }: { initial: T; key: string }) {\n return new Storage(key, initial);\n}\n","import { createStorage } from './create-storage';\nimport { Storage } from './storage';\n\nexport type StorageAccount = Storage<string | undefined>;\n\nexport function createStorageAccount({\n initial,\n key,\n}: {\n initial?: string | undefined;\n key?: string;\n} = {}): StorageAccount {\n return createStorage<string | undefined>({\n initial,\n key: key ?? 'wallet-ui:account',\n });\n}\n","import { createStorage } from './create-storage';\nimport { Storage } from './storage';\nimport { SolanaClusterId } from './types/solana-cluster-id';\n\nexport type StorageCluster = Storage<SolanaClusterId>;\n\nexport function createStorageCluster({\n initial,\n key,\n}: {\n initial?: SolanaClusterId;\n key?: string;\n} = {}): StorageCluster {\n return createStorage<SolanaClusterId>({\n initial: initial ?? 'solana:devnet',\n key: key ?? 'wallet-ui:cluster',\n });\n}\n","import { SolanaClusterId } from './types/solana-cluster-id';\n\nexport type ExplorerPath = `/address/${string}` | `/block/${string}` | `/tx/${string}`;\nexport type ExplorerProvider = 'orb' | 'solana' | 'solscan';\nexport const explorerProviders: ExplorerProvider[] = ['solana', 'solscan', 'orb'] as const;\n\nexport interface GetNetworkSuffixProps {\n id: SolanaClusterId;\n url: string;\n}\n\nexport interface GetExplorerUrlProps {\n network: GetNetworkSuffixProps;\n path: ExplorerPath;\n provider: ExplorerProvider;\n}\n\nexport function getExplorerUrl({ network, path, provider }: GetExplorerUrlProps) {\n if (!(path.startsWith('/address') || path.startsWith('/block') || path.startsWith('/tx'))) {\n throw new Error('Invalid path. Must be /address/{address}, /block/{id}, or /tx/{signature}.');\n }\n if (!explorerProviders.includes(provider)) {\n throw new Error(`Invalid provider. Must be one of ${explorerProviders.join(', ')}.`);\n }\n const url = new URL(getExplorerBaseUrl(provider));\n url.pathname = path;\n const params = getExplorerSuffix(network);\n if (params.cluster.length) {\n url.searchParams.set('cluster', params.cluster);\n }\n if (params.customUrl.length) {\n url.searchParams.set('customUrl', params.customUrl);\n }\n return url.toString();\n}\n\nfunction getExplorerBaseUrl(provider: ExplorerProvider) {\n switch (provider) {\n case 'orb':\n return 'https://orbmarkets.io';\n case 'solscan':\n return 'https://solscan.io';\n default:\n return 'https://explorer.solana.com';\n }\n}\n\nfunction getExplorerSuffix(props: GetNetworkSuffixProps): {\n cluster: string;\n customUrl: string;\n} {\n switch (props.id) {\n case 'solana:devnet':\n return { cluster: 'devnet', customUrl: '' };\n case 'solana:localnet':\n return { cluster: 'custom', customUrl: props.url };\n case 'solana:testnet':\n return { cluster: 'testnet', customUrl: '' };\n default:\n return { cluster: '', customUrl: '' };\n }\n}\n","export function handleCopyText(text?: string) {\n if (!text) {\n return;\n }\n if (\n typeof globalThis === 'undefined' ||\n !globalThis.navigator ||\n !globalThis.navigator.clipboard ||\n !globalThis.navigator.clipboard.writeText\n ) {\n return;\n }\n void globalThis.navigator.clipboard.writeText(text);\n}\n","export function stringToUint8Array(value: Uint8Array | string): Uint8Array {\n return value instanceof Uint8Array ? value : new TextEncoder().encode(value);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/types/solana-cluster.ts","../src/clusters.ts","../src/create-qr-code.ts","../src/create-qr-code-svg.ts","../src/storage.ts","../src/create-storage.ts","../src/create-storage-account.ts","../src/create-storage-cluster.ts","../src/get-explorer-url.ts","../src/handle-copy-text.ts","../src/string-to-uint8-array.ts"],"names":["devnet","mainnet","testnet","encodeQR","persistentAtom","computed"],"mappings":";;;;;;;;;;;;;;AAYO,SAAS,SAAS,GAAA,EAAa;AAClC,EAAA,OAAO,GAAA;AACX;;;ACRA,SAAS,mBAAA,CACL,OACA,EAAE,EAAA,EAAI,OAAO,GAAA,EAAK,UAAA,EAAY,KAAA,EAAO,YAAA,EAAa,EACrC;AACb,EAAA,IAAI,OAAO,UAAU,QAAA,EAAU;AAC3B,IAAA,OAAO,EAAE,EAAA,EAAI,KAAA,EAAO,GAAA,EAAK,KAAA,EAAM;AAAA,EACnC;AAEA,EAAA,OAAO;AAAA,IACH,EAAA;AAAA,IACA,KAAA,EAAO,MAAM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CAAC,WAAW,SAAA,IACZ,CAAC,UAAA,CAAW,SAAA,CAAU,SAAA,IACtB,CAAC,UAAA,CAAW,SAAA,CAAU,UAAU,SAAA,EAClC;AACE,IAAA;AAAA,EACJ;AACA,EAAA,KAAK,UAAA,CAAW,SAAA,CAAU,SAAA,CAAU,SAAA,CAAU,IAAI,CAAA;AACtD;;;ACbO,SAAS,mBAAmB,KAAA,EAAwC;AACvE,EAAA,OAAO,iBAAiB,UAAA,GAAa,KAAA,GAAQ,IAAI,WAAA,EAAY,CAAE,OAAO,KAAK,CAAA;AAC/E","file":"index.browser.cjs","sourcesContent":["import type {\n DevnetUrl as SolanaDevnetUrl,\n MainnetUrl as SolanaMainnetUrl,\n TestnetUrl as SolanaTestnetUrl,\n} from '@solana/kit';\n\nimport { SolanaClusterId } from './solana-cluster-id';\n\nexport type { SolanaDevnetUrl, SolanaMainnetUrl, SolanaTestnetUrl };\n\nexport type SolanaLocalnetUrl = string & { '~cluster': 'localnet' };\n\nexport function localnet(url: string) {\n return url as SolanaLocalnetUrl;\n}\n\nexport interface SolanaCluster {\n id: SolanaClusterId;\n label: string;\n url: SolanaDevnetUrl | SolanaLocalnetUrl | SolanaMainnetUrl | SolanaTestnetUrl | string;\n urlWs?: string;\n}\n","import { devnet, mainnet, testnet } from '@solana/kit';\n\nimport { localnet, SolanaCluster } from './types/solana-cluster';\n\nexport type CreateSolanaProps = string | (Partial<Pick<SolanaCluster, 'label' | 'url' | 'urlWs'>> & { url: string });\n\nfunction createSolanaCluster(\n props: CreateSolanaProps,\n { id, label, url: defaultUrl, urlWs: defaultUrlWs }: Pick<SolanaCluster, 'id' | 'label' | 'url' | 'urlWs'>,\n): SolanaCluster {\n if (typeof props === 'string') {\n return { id, label, url: props };\n }\n\n return {\n id,\n label: props.label ?? label,\n url: props.url ?? defaultUrl,\n urlWs: props.urlWs ?? defaultUrlWs,\n };\n}\n\nexport function createSolanaDevnet(props: CreateSolanaProps = 'https://api.devnet.solana.com'): SolanaCluster {\n return createSolanaCluster(props, {\n id: 'solana:devnet',\n label: 'Devnet',\n url: devnet(typeof props === 'string' ? props : props.url),\n });\n}\n\nexport function createSolanaLocalnet(props: CreateSolanaProps = 'http://localhost:8899'): SolanaCluster {\n const url = typeof props === 'string' ? props : props.url;\n const urlWs = typeof props !== 'string' ? (props.urlWs ?? getLocalUrlWs(url)) : undefined;\n return createSolanaCluster(props, {\n id: 'solana:localnet',\n label: 'Localnet',\n url: localnet(url),\n urlWs,\n });\n}\n\nfunction getLocalUrlWs(url: string) {\n return url.endsWith(':8899') ? url.replace(':8899', ':8900').replace('http', 'ws') : undefined;\n}\nexport function createSolanaMainnet(props: CreateSolanaProps): SolanaCluster {\n return createSolanaCluster(props, {\n id: 'solana:mainnet',\n label: 'Mainnet',\n url: mainnet(typeof props === 'string' ? props : props.url),\n });\n}\n\nexport function createSolanaTestnet(props: CreateSolanaProps = 'https://api.testnet.solana.com'): SolanaCluster {\n return createSolanaCluster(props, {\n id: 'solana:testnet',\n label: 'Testnet',\n url: testnet(typeof props === 'string' ? props : props.url),\n });\n}\n","import encodeQR from 'qr';\n\nexport type QrCodeErrorCorrection = 'high' | 'low' | 'medium' | 'quartile';\n\nexport interface QrCode {\n border: number;\n cells: boolean[][];\n errorCorrection: QrCodeErrorCorrection;\n size: number;\n value: string;\n}\n\nexport interface QrCodeOptions {\n border?: number;\n errorCorrection?: QrCodeErrorCorrection;\n}\n\nconst DEFAULT_QR_CODE_BORDER = 4;\nconst DEFAULT_QR_CODE_ERROR_CORRECTION: QrCodeErrorCorrection = 'medium';\n\nexport function createQrCode(value: string, options: QrCodeOptions = {}): QrCode {\n const border = options.border ?? DEFAULT_QR_CODE_BORDER;\n const errorCorrection = options.errorCorrection ?? DEFAULT_QR_CODE_ERROR_CORRECTION;\n const cells = encodeQR(value, 'raw', { border, ecc: errorCorrection }).map(row => row.map(Boolean));\n\n return {\n border,\n cells,\n errorCorrection,\n size: cells.length,\n value,\n };\n}\n","import { createQrCode, type QrCodeOptions } from './create-qr-code';\n\nexport interface QrCodeLogoOptions {\n backgroundColor?: string;\n href: string;\n size?: number;\n}\n\nexport interface QrCodeSvgOptions extends QrCodeOptions {\n backgroundColor?: string;\n foregroundColor?: string;\n logo?: QrCodeLogoOptions;\n title?: string;\n}\n\nconst DEFAULT_QR_CODE_BACKGROUND_COLOR = '#fff';\nconst DEFAULT_QR_CODE_FOREGROUND_COLOR = '#000';\nconst DEFAULT_QR_CODE_LOGO_SIZE = 0.2;\nconst LOGO_BACKGROUND_PADDING = 1;\nconst MAX_QR_CODE_LOGO_SIZE = 0.25;\n\nexport function createQrCodeSvg(value: string, options: QrCodeSvgOptions = {}): string {\n const backgroundColor = options.backgroundColor ?? DEFAULT_QR_CODE_BACKGROUND_COLOR;\n const foregroundColor = options.foregroundColor ?? DEFAULT_QR_CODE_FOREGROUND_COLOR;\n const logo = options.logo;\n const qrCode = createQrCode(value, {\n border: options.border,\n errorCorrection: options.errorCorrection ?? (logo ? 'high' : undefined),\n });\n const title = options.title ? `<title>${escapeSvgText(options.title)}</title>` : '';\n const background = `<rect fill=\"${escapeSvgAttribute(backgroundColor)}\" height=\"${qrCode.size}\" width=\"${qrCode.size}\" x=\"0\" y=\"0\"/>`;\n const foreground = `<path d=\"${createQrCodeSvgPath(qrCode.cells)}\" fill=\"${escapeSvgAttribute(foregroundColor)}\"/>`;\n const logoSvg = logo ? createQrCodeLogoSvg({ backgroundColor, logo, size: qrCode.size }) : '';\n const accessibility = options.title ? 'role=\"img\"' : 'aria-hidden=\"true\"';\n\n return `<svg ${accessibility} shape-rendering=\"crispEdges\" viewBox=\"0 0 ${qrCode.size} ${qrCode.size}\" xmlns=\"http://www.w3.org/2000/svg\">${title}${background}${foreground}${logoSvg}</svg>`;\n}\n\nfunction createQrCodeLogoSvg({\n backgroundColor,\n logo,\n size,\n}: {\n backgroundColor: string;\n logo: QrCodeLogoOptions;\n size: number;\n}): string {\n const logoSize = size * getQrCodeLogoSize(logo.size);\n const logoPosition = (size - logoSize) / 2;\n const logoBackgroundPosition = Math.max(0, Math.floor(logoPosition) - LOGO_BACKGROUND_PADDING);\n const logoBackgroundEnd = Math.min(size, Math.ceil(logoPosition + logoSize) + LOGO_BACKGROUND_PADDING);\n const logoBackgroundSize = logoBackgroundEnd - logoBackgroundPosition;\n const logoBackgroundColor = logo.backgroundColor ?? backgroundColor;\n\n return [\n `<rect fill=\"${escapeSvgAttribute(logoBackgroundColor)}\" height=\"${formatSvgNumber(logoBackgroundSize)}\" width=\"${formatSvgNumber(logoBackgroundSize)}\" x=\"${formatSvgNumber(logoBackgroundPosition)}\" y=\"${formatSvgNumber(logoBackgroundPosition)}\"/>`,\n `<image height=\"${formatSvgNumber(logoSize)}\" href=\"${escapeSvgAttribute(logo.href)}\" preserveAspectRatio=\"xMidYMid meet\" width=\"${formatSvgNumber(logoSize)}\" x=\"${formatSvgNumber(logoPosition)}\" y=\"${formatSvgNumber(logoPosition)}\"/>`,\n ].join('');\n}\n\nfunction createQrCodeSvgPath(cells: boolean[][]): string {\n return cells\n .flatMap((row, rowIndex) =>\n row.map((cell, columnIndex) => (cell ? `M${columnIndex} ${rowIndex}h1v1H${columnIndex}z` : '')),\n )\n .join('');\n}\n\nfunction escapeSvgAttribute(value: string): string {\n return value\n .replace(/&/g, '&')\n .replace(/\"/g, '"')\n .replace(/'/g, ''')\n .replace(/</g, '<')\n .replace(/>/g, '>');\n}\n\nfunction escapeSvgText(value: string): string {\n return value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');\n}\n\nfunction formatSvgNumber(value: number): string {\n return Number(value.toFixed(6)).toString();\n}\n\nfunction getQrCodeLogoSize(size = DEFAULT_QR_CODE_LOGO_SIZE): number {\n return Math.min(size, MAX_QR_CODE_LOGO_SIZE);\n}\n","import { persistentAtom } from '@nanostores/persistent';\nimport { computed, WritableAtom } from 'nanostores';\n\nexport class Storage<T> {\n private readonly atom: WritableAtom<T>;\n\n constructor(\n readonly key: string,\n readonly initial: T,\n ) {\n this.atom = persistentAtom<T>(key, initial, { decode: JSON.parse, encode: JSON.stringify });\n }\n\n get() {\n return this.atom.get();\n }\n\n set(value: T) {\n this.atom.set(value);\n }\n\n get value() {\n return computed(this.atom, value => value);\n }\n}\n","import { Storage } from './storage';\n\nexport function createStorage<T>({ initial, key }: { initial: T; key: string }) {\n return new Storage(key, initial);\n}\n","import { createStorage } from './create-storage';\nimport { Storage } from './storage';\n\nexport type StorageAccount = Storage<string | undefined>;\n\nexport function createStorageAccount({\n initial,\n key,\n}: {\n initial?: string | undefined;\n key?: string;\n} = {}): StorageAccount {\n return createStorage<string | undefined>({\n initial,\n key: key ?? 'wallet-ui:account',\n });\n}\n","import { createStorage } from './create-storage';\nimport { Storage } from './storage';\nimport { SolanaClusterId } from './types/solana-cluster-id';\n\nexport type StorageCluster = Storage<SolanaClusterId>;\n\nexport function createStorageCluster({\n initial,\n key,\n}: {\n initial?: SolanaClusterId;\n key?: string;\n} = {}): StorageCluster {\n return createStorage<SolanaClusterId>({\n initial: initial ?? 'solana:devnet',\n key: key ?? 'wallet-ui:cluster',\n });\n}\n","import { SolanaClusterId } from './types/solana-cluster-id';\n\nexport type ExplorerPath = `/address/${string}` | `/block/${string}` | `/tx/${string}`;\nexport type ExplorerProvider = 'orb' | 'solana' | 'solscan';\nexport const explorerProviders: ExplorerProvider[] = ['solana', 'solscan', 'orb'] as const;\n\nexport interface GetNetworkSuffixProps {\n id: SolanaClusterId;\n url: string;\n}\n\nexport interface GetExplorerUrlProps {\n network: GetNetworkSuffixProps;\n path: ExplorerPath;\n provider: ExplorerProvider;\n}\n\nexport function getExplorerUrl({ network, path, provider }: GetExplorerUrlProps) {\n if (!(path.startsWith('/address') || path.startsWith('/block') || path.startsWith('/tx'))) {\n throw new Error('Invalid path. Must be /address/{address}, /block/{id}, or /tx/{signature}.');\n }\n if (!explorerProviders.includes(provider)) {\n throw new Error(`Invalid provider. Must be one of ${explorerProviders.join(', ')}.`);\n }\n const url = new URL(getExplorerBaseUrl(provider));\n url.pathname = path;\n const params = getExplorerSuffix(network);\n if (params.cluster.length) {\n url.searchParams.set('cluster', params.cluster);\n }\n if (params.customUrl.length) {\n url.searchParams.set('customUrl', params.customUrl);\n }\n return url.toString();\n}\n\nfunction getExplorerBaseUrl(provider: ExplorerProvider) {\n switch (provider) {\n case 'orb':\n return 'https://orbmarkets.io';\n case 'solscan':\n return 'https://solscan.io';\n default:\n return 'https://explorer.solana.com';\n }\n}\n\nfunction getExplorerSuffix(props: GetNetworkSuffixProps): {\n cluster: string;\n customUrl: string;\n} {\n switch (props.id) {\n case 'solana:devnet':\n return { cluster: 'devnet', customUrl: '' };\n case 'solana:localnet':\n return { cluster: 'custom', customUrl: props.url };\n case 'solana:testnet':\n return { cluster: 'testnet', customUrl: '' };\n default:\n return { cluster: '', customUrl: '' };\n }\n}\n","export function handleCopyText(text?: string) {\n if (!text) {\n return;\n }\n if (\n typeof globalThis === 'undefined' ||\n !globalThis.navigator ||\n !globalThis.navigator.clipboard ||\n !globalThis.navigator.clipboard.writeText\n ) {\n return;\n }\n void globalThis.navigator.clipboard.writeText(text);\n}\n","export function stringToUint8Array(value: Uint8Array | string): Uint8Array {\n return value instanceof Uint8Array ? value : new TextEncoder().encode(value);\n}\n"]}
|
package/dist/index.browser.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { devnet, mainnet, testnet } from '@solana/kit';
|
|
2
|
+
import encodeQR from 'qr';
|
|
2
3
|
import { persistentAtom } from '@nanostores/persistent';
|
|
3
4
|
import { computed } from 'nanostores';
|
|
4
5
|
|
|
@@ -55,6 +56,75 @@ function createSolanaTestnet(props = "https://api.testnet.solana.com") {
|
|
|
55
56
|
url: testnet(typeof props === "string" ? props : props.url)
|
|
56
57
|
});
|
|
57
58
|
}
|
|
59
|
+
var DEFAULT_QR_CODE_BORDER = 4;
|
|
60
|
+
var DEFAULT_QR_CODE_ERROR_CORRECTION = "medium";
|
|
61
|
+
function createQrCode(value, options = {}) {
|
|
62
|
+
const border = options.border ?? DEFAULT_QR_CODE_BORDER;
|
|
63
|
+
const errorCorrection = options.errorCorrection ?? DEFAULT_QR_CODE_ERROR_CORRECTION;
|
|
64
|
+
const cells = encodeQR(value, "raw", { border, ecc: errorCorrection }).map((row) => row.map(Boolean));
|
|
65
|
+
return {
|
|
66
|
+
border,
|
|
67
|
+
cells,
|
|
68
|
+
errorCorrection,
|
|
69
|
+
size: cells.length,
|
|
70
|
+
value
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// src/create-qr-code-svg.ts
|
|
75
|
+
var DEFAULT_QR_CODE_BACKGROUND_COLOR = "#fff";
|
|
76
|
+
var DEFAULT_QR_CODE_FOREGROUND_COLOR = "#000";
|
|
77
|
+
var DEFAULT_QR_CODE_LOGO_SIZE = 0.2;
|
|
78
|
+
var LOGO_BACKGROUND_PADDING = 1;
|
|
79
|
+
var MAX_QR_CODE_LOGO_SIZE = 0.25;
|
|
80
|
+
function createQrCodeSvg(value, options = {}) {
|
|
81
|
+
const backgroundColor = options.backgroundColor ?? DEFAULT_QR_CODE_BACKGROUND_COLOR;
|
|
82
|
+
const foregroundColor = options.foregroundColor ?? DEFAULT_QR_CODE_FOREGROUND_COLOR;
|
|
83
|
+
const logo = options.logo;
|
|
84
|
+
const qrCode = createQrCode(value, {
|
|
85
|
+
border: options.border,
|
|
86
|
+
errorCorrection: options.errorCorrection ?? (logo ? "high" : void 0)
|
|
87
|
+
});
|
|
88
|
+
const title = options.title ? `<title>${escapeSvgText(options.title)}</title>` : "";
|
|
89
|
+
const background = `<rect fill="${escapeSvgAttribute(backgroundColor)}" height="${qrCode.size}" width="${qrCode.size}" x="0" y="0"/>`;
|
|
90
|
+
const foreground = `<path d="${createQrCodeSvgPath(qrCode.cells)}" fill="${escapeSvgAttribute(foregroundColor)}"/>`;
|
|
91
|
+
const logoSvg = logo ? createQrCodeLogoSvg({ backgroundColor, logo, size: qrCode.size }) : "";
|
|
92
|
+
const accessibility = options.title ? 'role="img"' : 'aria-hidden="true"';
|
|
93
|
+
return `<svg ${accessibility} shape-rendering="crispEdges" viewBox="0 0 ${qrCode.size} ${qrCode.size}" xmlns="http://www.w3.org/2000/svg">${title}${background}${foreground}${logoSvg}</svg>`;
|
|
94
|
+
}
|
|
95
|
+
function createQrCodeLogoSvg({
|
|
96
|
+
backgroundColor,
|
|
97
|
+
logo,
|
|
98
|
+
size
|
|
99
|
+
}) {
|
|
100
|
+
const logoSize = size * getQrCodeLogoSize(logo.size);
|
|
101
|
+
const logoPosition = (size - logoSize) / 2;
|
|
102
|
+
const logoBackgroundPosition = Math.max(0, Math.floor(logoPosition) - LOGO_BACKGROUND_PADDING);
|
|
103
|
+
const logoBackgroundEnd = Math.min(size, Math.ceil(logoPosition + logoSize) + LOGO_BACKGROUND_PADDING);
|
|
104
|
+
const logoBackgroundSize = logoBackgroundEnd - logoBackgroundPosition;
|
|
105
|
+
const logoBackgroundColor = logo.backgroundColor ?? backgroundColor;
|
|
106
|
+
return [
|
|
107
|
+
`<rect fill="${escapeSvgAttribute(logoBackgroundColor)}" height="${formatSvgNumber(logoBackgroundSize)}" width="${formatSvgNumber(logoBackgroundSize)}" x="${formatSvgNumber(logoBackgroundPosition)}" y="${formatSvgNumber(logoBackgroundPosition)}"/>`,
|
|
108
|
+
`<image height="${formatSvgNumber(logoSize)}" href="${escapeSvgAttribute(logo.href)}" preserveAspectRatio="xMidYMid meet" width="${formatSvgNumber(logoSize)}" x="${formatSvgNumber(logoPosition)}" y="${formatSvgNumber(logoPosition)}"/>`
|
|
109
|
+
].join("");
|
|
110
|
+
}
|
|
111
|
+
function createQrCodeSvgPath(cells) {
|
|
112
|
+
return cells.flatMap(
|
|
113
|
+
(row, rowIndex) => row.map((cell, columnIndex) => cell ? `M${columnIndex} ${rowIndex}h1v1H${columnIndex}z` : "")
|
|
114
|
+
).join("");
|
|
115
|
+
}
|
|
116
|
+
function escapeSvgAttribute(value) {
|
|
117
|
+
return value.replace(/&/g, "&").replace(/"/g, """).replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">");
|
|
118
|
+
}
|
|
119
|
+
function escapeSvgText(value) {
|
|
120
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
121
|
+
}
|
|
122
|
+
function formatSvgNumber(value) {
|
|
123
|
+
return Number(value.toFixed(6)).toString();
|
|
124
|
+
}
|
|
125
|
+
function getQrCodeLogoSize(size = DEFAULT_QR_CODE_LOGO_SIZE) {
|
|
126
|
+
return Math.min(size, MAX_QR_CODE_LOGO_SIZE);
|
|
127
|
+
}
|
|
58
128
|
var Storage = class {
|
|
59
129
|
constructor(key, initial) {
|
|
60
130
|
this.key = key;
|
|
@@ -159,6 +229,6 @@ function stringToUint8Array(value) {
|
|
|
159
229
|
return value instanceof Uint8Array ? value : new TextEncoder().encode(value);
|
|
160
230
|
}
|
|
161
231
|
|
|
162
|
-
export { Storage, createSolanaDevnet, createSolanaLocalnet, createSolanaMainnet, createSolanaTestnet, createStorage, createStorageAccount, createStorageCluster, explorerProviders, getExplorerUrl, handleCopyText, localnet, stringToUint8Array };
|
|
232
|
+
export { Storage, createQrCode, createQrCodeSvg, createSolanaDevnet, createSolanaLocalnet, createSolanaMainnet, createSolanaTestnet, createStorage, createStorageAccount, createStorageCluster, explorerProviders, getExplorerUrl, handleCopyText, localnet, stringToUint8Array };
|
|
163
233
|
//# sourceMappingURL=index.browser.mjs.map
|
|
164
234
|
//# sourceMappingURL=index.browser.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types/solana-cluster.ts","../src/clusters.ts","../src/storage.ts","../src/create-storage.ts","../src/create-storage-account.ts","../src/create-storage-cluster.ts","../src/get-explorer-url.ts","../src/handle-copy-text.ts","../src/string-to-uint8-array.ts"],"names":[],"mappings":";;;;;;;AAYO,SAAS,SAAS,GAAA,EAAa;AAClC,EAAA,OAAO,GAAA;AACX;;;ACRA,SAAS,mBAAA,CACL,OACA,EAAE,EAAA,EAAI,OAAO,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AW,SAAA,CAAU,SAAA,CAAU,SAAA,CAAU,IAAI,CAAA;AACtD;;;ACbO,SAAS,mBAAmB,KAAA,EAAwC;AACvE,EAAA,OAAO,iBAAiB,UAAA,GAAa,KAAA,GAAQ,IAAI,WAAA,EAAY,CAAE,OAAO,KAAK,CAAA;AAC/E","file":"index.browser.mjs","sourcesContent":["import type {\n DevnetUrl as SolanaDevnetUrl,\n MainnetUrl as SolanaMainnetUrl,\n TestnetUrl as SolanaTestnetUrl,\n} from '@solana/kit';\n\nimport { SolanaClusterId } from './solana-cluster-id';\n\nexport type { SolanaDevnetUrl, SolanaMainnetUrl, SolanaTestnetUrl };\n\nexport type SolanaLocalnetUrl = string & { '~cluster': 'localnet' };\n\nexport function localnet(url: string) {\n return url as SolanaLocalnetUrl;\n}\n\nexport interface SolanaCluster {\n id: SolanaClusterId;\n label: string;\n url: SolanaDevnetUrl | SolanaLocalnetUrl | SolanaMainnetUrl | SolanaTestnetUrl | string;\n urlWs?: string;\n}\n","import { devnet, mainnet, testnet } from '@solana/kit';\n\nimport { localnet, SolanaCluster } from './types/solana-cluster';\n\nexport type CreateSolanaProps = string | (Partial<Pick<SolanaCluster, 'label' | 'url' | 'urlWs'>> & { url: string });\n\nfunction createSolanaCluster(\n props: CreateSolanaProps,\n { id, label, url: defaultUrl, urlWs: defaultUrlWs }: Pick<SolanaCluster, 'id' | 'label' | 'url' | 'urlWs'>,\n): SolanaCluster {\n if (typeof props === 'string') {\n return { id, label, url: props };\n }\n\n return {\n id,\n label: props.label ?? label,\n url: props.url ?? defaultUrl,\n urlWs: props.urlWs ?? defaultUrlWs,\n };\n}\n\nexport function createSolanaDevnet(props: CreateSolanaProps = 'https://api.devnet.solana.com'): SolanaCluster {\n return createSolanaCluster(props, {\n id: 'solana:devnet',\n label: 'Devnet',\n url: devnet(typeof props === 'string' ? props : props.url),\n });\n}\n\nexport function createSolanaLocalnet(props: CreateSolanaProps = 'http://localhost:8899'): SolanaCluster {\n const url = typeof props === 'string' ? props : props.url;\n const urlWs = typeof props !== 'string' ? (props.urlWs ?? getLocalUrlWs(url)) : undefined;\n return createSolanaCluster(props, {\n id: 'solana:localnet',\n label: 'Localnet',\n url: localnet(url),\n urlWs,\n });\n}\n\nfunction getLocalUrlWs(url: string) {\n return url.endsWith(':8899') ? url.replace(':8899', ':8900').replace('http', 'ws') : undefined;\n}\nexport function createSolanaMainnet(props: CreateSolanaProps): SolanaCluster {\n return createSolanaCluster(props, {\n id: 'solana:mainnet',\n label: 'Mainnet',\n url: mainnet(typeof props === 'string' ? props : props.url),\n });\n}\n\nexport function createSolanaTestnet(props: CreateSolanaProps = 'https://api.testnet.solana.com'): SolanaCluster {\n return createSolanaCluster(props, {\n id: 'solana:testnet',\n label: 'Testnet',\n url: testnet(typeof props === 'string' ? props : props.url),\n });\n}\n","import { persistentAtom } from '@nanostores/persistent';\nimport { computed, WritableAtom } from 'nanostores';\n\nexport class Storage<T> {\n private readonly atom: WritableAtom<T>;\n\n constructor(\n readonly key: string,\n readonly initial: T,\n ) {\n this.atom = persistentAtom<T>(key, initial, { decode: JSON.parse, encode: JSON.stringify });\n }\n\n get() {\n return this.atom.get();\n }\n\n set(value: T) {\n this.atom.set(value);\n }\n\n get value() {\n return computed(this.atom, value => value);\n }\n}\n","import { Storage } from './storage';\n\nexport function createStorage<T>({ initial, key }: { initial: T; key: string }) {\n return new Storage(key, initial);\n}\n","import { createStorage } from './create-storage';\nimport { Storage } from './storage';\n\nexport type StorageAccount = Storage<string | undefined>;\n\nexport function createStorageAccount({\n initial,\n key,\n}: {\n initial?: string | undefined;\n key?: string;\n} = {}): StorageAccount {\n return createStorage<string | undefined>({\n initial,\n key: key ?? 'wallet-ui:account',\n });\n}\n","import { createStorage } from './create-storage';\nimport { Storage } from './storage';\nimport { SolanaClusterId } from './types/solana-cluster-id';\n\nexport type StorageCluster = Storage<SolanaClusterId>;\n\nexport function createStorageCluster({\n initial,\n key,\n}: {\n initial?: SolanaClusterId;\n key?: string;\n} = {}): StorageCluster {\n return createStorage<SolanaClusterId>({\n initial: initial ?? 'solana:devnet',\n key: key ?? 'wallet-ui:cluster',\n });\n}\n","import { SolanaClusterId } from './types/solana-cluster-id';\n\nexport type ExplorerPath = `/address/${string}` | `/block/${string}` | `/tx/${string}`;\nexport type ExplorerProvider = 'orb' | 'solana' | 'solscan';\nexport const explorerProviders: ExplorerProvider[] = ['solana', 'solscan', 'orb'] as const;\n\nexport interface GetNetworkSuffixProps {\n id: SolanaClusterId;\n url: string;\n}\n\nexport interface GetExplorerUrlProps {\n network: GetNetworkSuffixProps;\n path: ExplorerPath;\n provider: ExplorerProvider;\n}\n\nexport function getExplorerUrl({ network, path, provider }: GetExplorerUrlProps) {\n if (!(path.startsWith('/address') || path.startsWith('/block') || path.startsWith('/tx'))) {\n throw new Error('Invalid path. Must be /address/{address}, /block/{id}, or /tx/{signature}.');\n }\n if (!explorerProviders.includes(provider)) {\n throw new Error(`Invalid provider. Must be one of ${explorerProviders.join(', ')}.`);\n }\n const url = new URL(getExplorerBaseUrl(provider));\n url.pathname = path;\n const params = getExplorerSuffix(network);\n if (params.cluster.length) {\n url.searchParams.set('cluster', params.cluster);\n }\n if (params.customUrl.length) {\n url.searchParams.set('customUrl', params.customUrl);\n }\n return url.toString();\n}\n\nfunction getExplorerBaseUrl(provider: ExplorerProvider) {\n switch (provider) {\n case 'orb':\n return 'https://orbmarkets.io';\n case 'solscan':\n return 'https://solscan.io';\n default:\n return 'https://explorer.solana.com';\n }\n}\n\nfunction getExplorerSuffix(props: GetNetworkSuffixProps): {\n cluster: string;\n customUrl: string;\n} {\n switch (props.id) {\n case 'solana:devnet':\n return { cluster: 'devnet', customUrl: '' };\n case 'solana:localnet':\n return { cluster: 'custom', customUrl: props.url };\n case 'solana:testnet':\n return { cluster: 'testnet', customUrl: '' };\n default:\n return { cluster: '', customUrl: '' };\n }\n}\n","export function handleCopyText(text?: string) {\n if (!text) {\n return;\n }\n if (\n typeof globalThis === 'undefined' ||\n !globalThis.navigator ||\n !globalThis.navigator.clipboard ||\n !globalThis.navigator.clipboard.writeText\n ) {\n return;\n }\n void globalThis.navigator.clipboard.writeText(text);\n}\n","export function stringToUint8Array(value: Uint8Array | string): Uint8Array {\n return value instanceof Uint8Array ? value : new TextEncoder().encode(value);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/types/solana-cluster.ts","../src/clusters.ts","../src/create-qr-code.ts","../src/create-qr-code-svg.ts","../src/storage.ts","../src/create-storage.ts","../src/create-storage-account.ts","../src/create-storage-cluster.ts","../src/get-explorer-url.ts","../src/handle-copy-text.ts","../src/string-to-uint8-array.ts"],"names":[],"mappings":";;;;;;;;AAYO,SAAS,SAAS,GAAA,EAAa;AAClC,EAAA,OAAO,GAAA;AACX;;;ACRA,SAAS,mBAAA,CACL,OACA,EAAE,EAAA,EAAI,OAAO,GAAA,EAAK,UAAA,EAAY,KAAA,EAAO,YAAA,EAAa,EACrC;AACb,EAAA,IAAI,OAAO,UAAU,QAAA,EAAU;AAC3B,IAAA,OAAO,EAAE,EAAA,EAAI,KAAA,EAAO,GAAA,EAAK,KAAA,EAAM;AAAA,EACnC;AAEA,EAAA,OAAO;AAAA,IACH,EAAA;AAAA,IACA,KAAA,EAAO,MAAM,KAAA,IAAS,KAAA;AAAA,IACtB,GAAA,EAAK,MAAM,GAAA,IAAO,UAAA;AAAA,IAClB,KAAA,EAAO,MAAM,KAAA,IAAS;AAAA,GAC1B;AACJ;AAEO,SAAS,kBAAA,CAAmB,QAA2B,+BAAA,EAAgD;AAC1G,EAAA,OAAO,oBAAoB,KAAA,EAAO;AAAA,IAC9B,EAAA,EAAI,eAAA;AAAA,IACJ,KAAA,EAAO,QAAA;AAAA,IACP,KAAK,MAAA,CAAO,OAAO,UAAU,QAAA,GAAW,KAAA,GAAQ,MAAM,GAAG;AAAA,GAC5D,CAAA;AACL;AAEO,SAAS,oBAAA,CAAqB,QAA2B,uBAAA,EAAwC;AACpG,EAAA,MAAM,GAAA,GAAM,OAAO,KAAA,KAA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import { SolanaClusterId } from './solana-cluster-id';\n\nexport type { SolanaDevnetUrl, SolanaMainnetUrl, SolanaTestnetUrl };\n\nexport type SolanaLocalnetUrl = string & { '~cluster': 'localnet' };\n\nexport function localnet(url: string) {\n return url as SolanaLocalnetUrl;\n}\n\nexport interface SolanaCluster {\n id: SolanaClusterId;\n label: string;\n url: SolanaDevnetUrl | SolanaLocalnetUrl | SolanaMainnetUrl | SolanaTestnetUrl | string;\n urlWs?: string;\n}\n","import { devnet, mainnet, testnet } from '@solana/kit';\n\nimport { localnet, SolanaCluster } from './types/solana-cluster';\n\nexport type CreateSolanaProps = string | (Partial<Pick<SolanaCluster, 'label' | 'url' | 'urlWs'>> & { url: string });\n\nfunction createSolanaCluster(\n props: CreateSolanaProps,\n { id, label, url: defaultUrl, urlWs: defaultUrlWs }: Pick<SolanaCluster, 'id' | 'label' | 'url' | 'urlWs'>,\n): SolanaCluster {\n if (typeof props === 'string') {\n return { id, label, url: props };\n }\n\n return {\n id,\n label: props.label ?? label,\n url: props.url ?? defaultUrl,\n urlWs: props.urlWs ?? defaultUrlWs,\n };\n}\n\nexport function createSolanaDevnet(props: CreateSolanaProps = 'https://api.devnet.solana.com'): SolanaCluster {\n return createSolanaCluster(props, {\n id: 'solana:devnet',\n label: 'Devnet',\n url: devnet(typeof props === 'string' ? props : props.url),\n });\n}\n\nexport function createSolanaLocalnet(props: CreateSolanaProps = 'http://localhost:8899'): SolanaCluster {\n const url = typeof props === 'string' ? props : props.url;\n const urlWs = typeof props !== 'string' ? (props.urlWs ?? getLocalUrlWs(url)) : undefined;\n return createSolanaCluster(props, {\n id: 'solana:localnet',\n label: 'Localnet',\n url: localnet(url),\n urlWs,\n });\n}\n\nfunction getLocalUrlWs(url: string) {\n return url.endsWith(':8899') ? url.replace(':8899', ':8900').replace('http', 'ws') : undefined;\n}\nexport function createSolanaMainnet(props: CreateSolanaProps): SolanaCluster {\n return createSolanaCluster(props, {\n id: 'solana:mainnet',\n label: 'Mainnet',\n url: mainnet(typeof props === 'string' ? props : props.url),\n });\n}\n\nexport function createSolanaTestnet(props: CreateSolanaProps = 'https://api.testnet.solana.com'): SolanaCluster {\n return createSolanaCluster(props, {\n id: 'solana:testnet',\n label: 'Testnet',\n url: testnet(typeof props === 'string' ? props : props.url),\n });\n}\n","import encodeQR from 'qr';\n\nexport type QrCodeErrorCorrection = 'high' | 'low' | 'medium' | 'quartile';\n\nexport interface QrCode {\n border: number;\n cells: boolean[][];\n errorCorrection: QrCodeErrorCorrection;\n size: number;\n value: string;\n}\n\nexport interface QrCodeOptions {\n border?: number;\n errorCorrection?: QrCodeErrorCorrection;\n}\n\nconst DEFAULT_QR_CODE_BORDER = 4;\nconst DEFAULT_QR_CODE_ERROR_CORRECTION: QrCodeErrorCorrection = 'medium';\n\nexport function createQrCode(value: string, options: QrCodeOptions = {}): QrCode {\n const border = options.border ?? DEFAULT_QR_CODE_BORDER;\n const errorCorrection = options.errorCorrection ?? DEFAULT_QR_CODE_ERROR_CORRECTION;\n const cells = encodeQR(value, 'raw', { border, ecc: errorCorrection }).map(row => row.map(Boolean));\n\n return {\n border,\n cells,\n errorCorrection,\n size: cells.length,\n value,\n };\n}\n","import { createQrCode, type QrCodeOptions } from './create-qr-code';\n\nexport interface QrCodeLogoOptions {\n backgroundColor?: string;\n href: string;\n size?: number;\n}\n\nexport interface QrCodeSvgOptions extends QrCodeOptions {\n backgroundColor?: string;\n foregroundColor?: string;\n logo?: QrCodeLogoOptions;\n title?: string;\n}\n\nconst DEFAULT_QR_CODE_BACKGROUND_COLOR = '#fff';\nconst DEFAULT_QR_CODE_FOREGROUND_COLOR = '#000';\nconst DEFAULT_QR_CODE_LOGO_SIZE = 0.2;\nconst LOGO_BACKGROUND_PADDING = 1;\nconst MAX_QR_CODE_LOGO_SIZE = 0.25;\n\nexport function createQrCodeSvg(value: string, options: QrCodeSvgOptions = {}): string {\n const backgroundColor = options.backgroundColor ?? DEFAULT_QR_CODE_BACKGROUND_COLOR;\n const foregroundColor = options.foregroundColor ?? DEFAULT_QR_CODE_FOREGROUND_COLOR;\n const logo = options.logo;\n const qrCode = createQrCode(value, {\n border: options.border,\n errorCorrection: options.errorCorrection ?? (logo ? 'high' : undefined),\n });\n const title = options.title ? `<title>${escapeSvgText(options.title)}</title>` : '';\n const background = `<rect fill=\"${escapeSvgAttribute(backgroundColor)}\" height=\"${qrCode.size}\" width=\"${qrCode.size}\" x=\"0\" y=\"0\"/>`;\n const foreground = `<path d=\"${createQrCodeSvgPath(qrCode.cells)}\" fill=\"${escapeSvgAttribute(foregroundColor)}\"/>`;\n const logoSvg = logo ? createQrCodeLogoSvg({ backgroundColor, logo, size: qrCode.size }) : '';\n const accessibility = options.title ? 'role=\"img\"' : 'aria-hidden=\"true\"';\n\n return `<svg ${accessibility} shape-rendering=\"crispEdges\" viewBox=\"0 0 ${qrCode.size} ${qrCode.size}\" xmlns=\"http://www.w3.org/2000/svg\">${title}${background}${foreground}${logoSvg}</svg>`;\n}\n\nfunction createQrCodeLogoSvg({\n backgroundColor,\n logo,\n size,\n}: {\n backgroundColor: string;\n logo: QrCodeLogoOptions;\n size: number;\n}): string {\n const logoSize = size * getQrCodeLogoSize(logo.size);\n const logoPosition = (size - logoSize) / 2;\n const logoBackgroundPosition = Math.max(0, Math.floor(logoPosition) - LOGO_BACKGROUND_PADDING);\n const logoBackgroundEnd = Math.min(size, Math.ceil(logoPosition + logoSize) + LOGO_BACKGROUND_PADDING);\n const logoBackgroundSize = logoBackgroundEnd - logoBackgroundPosition;\n const logoBackgroundColor = logo.backgroundColor ?? backgroundColor;\n\n return [\n `<rect fill=\"${escapeSvgAttribute(logoBackgroundColor)}\" height=\"${formatSvgNumber(logoBackgroundSize)}\" width=\"${formatSvgNumber(logoBackgroundSize)}\" x=\"${formatSvgNumber(logoBackgroundPosition)}\" y=\"${formatSvgNumber(logoBackgroundPosition)}\"/>`,\n `<image height=\"${formatSvgNumber(logoSize)}\" href=\"${escapeSvgAttribute(logo.href)}\" preserveAspectRatio=\"xMidYMid meet\" width=\"${formatSvgNumber(logoSize)}\" x=\"${formatSvgNumber(logoPosition)}\" y=\"${formatSvgNumber(logoPosition)}\"/>`,\n ].join('');\n}\n\nfunction createQrCodeSvgPath(cells: boolean[][]): string {\n return cells\n .flatMap((row, rowIndex) =>\n row.map((cell, columnIndex) => (cell ? `M${columnIndex} ${rowIndex}h1v1H${columnIndex}z` : '')),\n )\n .join('');\n}\n\nfunction escapeSvgAttribute(value: string): string {\n return value\n .replace(/&/g, '&')\n .replace(/\"/g, '"')\n .replace(/'/g, ''')\n .replace(/</g, '<')\n .replace(/>/g, '>');\n}\n\nfunction escapeSvgText(value: string): string {\n return value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');\n}\n\nfunction formatSvgNumber(value: number): string {\n return Number(value.toFixed(6)).toString();\n}\n\nfunction getQrCodeLogoSize(size = DEFAULT_QR_CODE_LOGO_SIZE): number {\n return Math.min(size, MAX_QR_CODE_LOGO_SIZE);\n}\n","import { persistentAtom } from '@nanostores/persistent';\nimport { computed, WritableAtom } from 'nanostores';\n\nexport class Storage<T> {\n private readonly atom: WritableAtom<T>;\n\n constructor(\n readonly key: string,\n readonly initial: T,\n ) {\n this.atom = persistentAtom<T>(key, initial, { decode: JSON.parse, encode: JSON.stringify });\n }\n\n get() {\n return this.atom.get();\n }\n\n set(value: T) {\n this.atom.set(value);\n }\n\n get value() {\n return computed(this.atom, value => value);\n }\n}\n","import { Storage } from './storage';\n\nexport function createStorage<T>({ initial, key }: { initial: T; key: string }) {\n return new Storage(key, initial);\n}\n","import { createStorage } from './create-storage';\nimport { Storage } from './storage';\n\nexport type StorageAccount = Storage<string | undefined>;\n\nexport function createStorageAccount({\n initial,\n key,\n}: {\n initial?: string | undefined;\n key?: string;\n} = {}): StorageAccount {\n return createStorage<string | undefined>({\n initial,\n key: key ?? 'wallet-ui:account',\n });\n}\n","import { createStorage } from './create-storage';\nimport { Storage } from './storage';\nimport { SolanaClusterId } from './types/solana-cluster-id';\n\nexport type StorageCluster = Storage<SolanaClusterId>;\n\nexport function createStorageCluster({\n initial,\n key,\n}: {\n initial?: SolanaClusterId;\n key?: string;\n} = {}): StorageCluster {\n return createStorage<SolanaClusterId>({\n initial: initial ?? 'solana:devnet',\n key: key ?? 'wallet-ui:cluster',\n });\n}\n","import { SolanaClusterId } from './types/solana-cluster-id';\n\nexport type ExplorerPath = `/address/${string}` | `/block/${string}` | `/tx/${string}`;\nexport type ExplorerProvider = 'orb' | 'solana' | 'solscan';\nexport const explorerProviders: ExplorerProvider[] = ['solana', 'solscan', 'orb'] as const;\n\nexport interface GetNetworkSuffixProps {\n id: SolanaClusterId;\n url: string;\n}\n\nexport interface GetExplorerUrlProps {\n network: GetNetworkSuffixProps;\n path: ExplorerPath;\n provider: ExplorerProvider;\n}\n\nexport function getExplorerUrl({ network, path, provider }: GetExplorerUrlProps) {\n if (!(path.startsWith('/address') || path.startsWith('/block') || path.startsWith('/tx'))) {\n throw new Error('Invalid path. Must be /address/{address}, /block/{id}, or /tx/{signature}.');\n }\n if (!explorerProviders.includes(provider)) {\n throw new Error(`Invalid provider. Must be one of ${explorerProviders.join(', ')}.`);\n }\n const url = new URL(getExplorerBaseUrl(provider));\n url.pathname = path;\n const params = getExplorerSuffix(network);\n if (params.cluster.length) {\n url.searchParams.set('cluster', params.cluster);\n }\n if (params.customUrl.length) {\n url.searchParams.set('customUrl', params.customUrl);\n }\n return url.toString();\n}\n\nfunction getExplorerBaseUrl(provider: ExplorerProvider) {\n switch (provider) {\n case 'orb':\n return 'https://orbmarkets.io';\n case 'solscan':\n return 'https://solscan.io';\n default:\n return 'https://explorer.solana.com';\n }\n}\n\nfunction getExplorerSuffix(props: GetNetworkSuffixProps): {\n cluster: string;\n customUrl: string;\n} {\n switch (props.id) {\n case 'solana:devnet':\n return { cluster: 'devnet', customUrl: '' };\n case 'solana:localnet':\n return { cluster: 'custom', customUrl: props.url };\n case 'solana:testnet':\n return { cluster: 'testnet', customUrl: '' };\n default:\n return { cluster: '', customUrl: '' };\n }\n}\n","export function handleCopyText(text?: string) {\n if (!text) {\n return;\n }\n if (\n typeof globalThis === 'undefined' ||\n !globalThis.navigator ||\n !globalThis.navigator.clipboard ||\n !globalThis.navigator.clipboard.writeText\n ) {\n return;\n }\n void globalThis.navigator.clipboard.writeText(text);\n}\n","export function stringToUint8Array(value: Uint8Array | string): Uint8Array {\n return value instanceof Uint8Array ? value : new TextEncoder().encode(value);\n}\n"]}
|