@bchconnect/ui 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +280 -2
- package/custom-elements.json +1771 -0
- package/dist/assets.generated.js +28 -0
- package/dist/assets.generated.js.map +1 -0
- package/dist/bchconnect-modal.d.ts +89 -0
- package/dist/bchconnect-modal.js +121 -0
- package/dist/bchconnect-modal.js.map +1 -0
- package/dist/code.js +130 -0
- package/dist/code.js.map +1 -0
- package/dist/defaults.d.ts +50 -0
- package/dist/defaults.js +139 -0
- package/dist/defaults.js.map +1 -0
- package/dist/define.d.ts +17 -0
- package/dist/define.js +23 -0
- package/dist/define.js.map +1 -0
- package/dist/directory.js +37 -0
- package/dist/directory.js.map +1 -0
- package/dist/faces.js +80 -0
- package/dist/faces.js.map +1 -0
- package/dist/gesture.js +78 -0
- package/dist/gesture.js.map +1 -0
- package/dist/headless.d.ts +99 -0
- package/dist/headless.js +190 -0
- package/dist/headless.js.map +1 -0
- package/dist/html.js +17 -0
- package/dist/html.js.map +1 -0
- package/dist/icons.js +21 -0
- package/dist/icons.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +8 -0
- package/dist/locales/es.d.ts +12 -0
- package/dist/locales/es.js +50 -0
- package/dist/locales/es.js.map +1 -0
- package/dist/messages.d.ts +95 -0
- package/dist/messages.js +63 -0
- package/dist/messages.js.map +1 -0
- package/dist/modal.d.ts +112 -0
- package/dist/modal.js +700 -0
- package/dist/modal.js.map +1 -0
- package/dist/motion.js +160 -0
- package/dist/motion.js.map +1 -0
- package/dist/page-scroll.js +28 -0
- package/dist/page-scroll.js.map +1 -0
- package/dist/register.js +14 -0
- package/dist/register.js.map +1 -0
- package/dist/sheet-query.js +8 -0
- package/dist/sheet-query.js.map +1 -0
- package/dist/sheet.js +329 -0
- package/dist/sheet.js.map +1 -0
- package/dist/state.d.ts +175 -0
- package/dist/state.js +11 -0
- package/dist/state.js.map +1 -0
- package/dist/styles/modal.css.sheet.js +13 -0
- package/dist/styles/modal.css.sheet.js.map +1 -0
- package/dist/styles/theme.generated.css.sheet.js +13 -0
- package/dist/styles/theme.generated.css.sheet.js.map +1 -0
- package/dist/styles/toast.css.sheet.js +13 -0
- package/dist/styles/toast.css.sheet.js.map +1 -0
- package/dist/styles/tokens.css.sheet.js +13 -0
- package/dist/styles/tokens.css.sheet.js.map +1 -0
- package/dist/theme.generated.d.ts +105 -0
- package/dist/theme.generated.js +96 -0
- package/dist/theme.generated.js.map +1 -0
- package/dist/toast.d.ts +96 -0
- package/dist/toast.js +180 -0
- package/dist/toast.js.map +1 -0
- package/package.json +87 -3
package/dist/defaults.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
|
|
2
|
+
import { LOGO_CASHONIZE, LOGO_OPTN, LOGO_PAYTACA, LOGO_SELENE, MARK_CASHCONNECT, MARK_WALLETCONNECT, MARK_WIZARDCONNECT } from "./assets.generated.js";
|
|
3
|
+
//#region src/defaults.ts
|
|
4
|
+
/**
|
|
5
|
+
* The session types BCH Connect ships marks for, in the order the
|
|
6
|
+
* session-type control shows them.
|
|
7
|
+
*
|
|
8
|
+
* @beta
|
|
9
|
+
*/
|
|
10
|
+
const BCHC_PROTOCOLS = [
|
|
11
|
+
{
|
|
12
|
+
id: "wizardconnect",
|
|
13
|
+
name: "WizardConnect",
|
|
14
|
+
mark: {
|
|
15
|
+
src: MARK_WIZARDCONNECT,
|
|
16
|
+
shape: "glyph"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
id: "bch-wc2",
|
|
21
|
+
name: "WalletConnect",
|
|
22
|
+
mark: {
|
|
23
|
+
src: MARK_WALLETCONNECT,
|
|
24
|
+
shape: "tile"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
id: "cashconnect",
|
|
29
|
+
name: "CashConnect",
|
|
30
|
+
mark: {
|
|
31
|
+
src: MARK_CASHCONNECT,
|
|
32
|
+
shape: "glyph"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
];
|
|
36
|
+
/**
|
|
37
|
+
* The wallets BCH Connect ships logos, a support matrix and desktop links
|
|
38
|
+
* for, in the order the wallet list shows them.
|
|
39
|
+
*
|
|
40
|
+
* A session names the wallet picked in the modal but doesn't carry its
|
|
41
|
+
* logo; look the logo up here by `session.wallet.id`.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* const logo =
|
|
46
|
+
* BCHC_WALLETS.find((wallet) => wallet.id === session.wallet.id)?.logo ??
|
|
47
|
+
* session.wallet.icon;
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* const enabled = view.protocols.map((protocol) => protocol.id);
|
|
53
|
+
* const wallets: WalletOption[] = BCHC_WALLETS.filter((wallet) =>
|
|
54
|
+
* wallet.protocols.some((protocol) => enabled.includes(protocol)),
|
|
55
|
+
* ).map((wallet) => ({
|
|
56
|
+
* ...wallet,
|
|
57
|
+
* protocols: wallet.protocols.filter((protocol) => enabled.includes(protocol)),
|
|
58
|
+
* }));
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @beta
|
|
62
|
+
*/
|
|
63
|
+
const BCHC_WALLETS = [
|
|
64
|
+
{
|
|
65
|
+
id: "cashonize",
|
|
66
|
+
name: "Cashonize",
|
|
67
|
+
logo: LOGO_CASHONIZE,
|
|
68
|
+
protocols: [
|
|
69
|
+
"wizardconnect",
|
|
70
|
+
"bch-wc2",
|
|
71
|
+
"cashconnect"
|
|
72
|
+
],
|
|
73
|
+
href: "https://cashonize.com/?uri={link}"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
id: "paytaca",
|
|
77
|
+
name: "Paytaca",
|
|
78
|
+
logo: LOGO_PAYTACA,
|
|
79
|
+
protocols: ["wizardconnect", "bch-wc2"],
|
|
80
|
+
href: null
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
id: "selene",
|
|
84
|
+
name: "Selene",
|
|
85
|
+
logo: LOGO_SELENE,
|
|
86
|
+
protocols: ["wizardconnect", "bch-wc2"],
|
|
87
|
+
href: null
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
id: "optn",
|
|
91
|
+
name: "OPTN",
|
|
92
|
+
logo: LOGO_OPTN,
|
|
93
|
+
protocols: [
|
|
94
|
+
"wizardconnect",
|
|
95
|
+
"bch-wc2",
|
|
96
|
+
"cashconnect"
|
|
97
|
+
],
|
|
98
|
+
href: null
|
|
99
|
+
}
|
|
100
|
+
];
|
|
101
|
+
/**
|
|
102
|
+
* Where to actually get each wallet in {@link BCHC_WALLETS}, for the "Get a
|
|
103
|
+
* wallet" screen.
|
|
104
|
+
*
|
|
105
|
+
* Official sites only: app-store links are unsupplied, and guessing them
|
|
106
|
+
* risks pointing users to the wrong app.
|
|
107
|
+
*
|
|
108
|
+
* @beta
|
|
109
|
+
*/
|
|
110
|
+
const BCHC_DIRECTORY = [
|
|
111
|
+
{
|
|
112
|
+
id: "cashonize",
|
|
113
|
+
name: "Cashonize",
|
|
114
|
+
logo: LOGO_CASHONIZE,
|
|
115
|
+
link: { href: "https://about.cashonize.com/" }
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
id: "selene",
|
|
119
|
+
name: "Selene",
|
|
120
|
+
logo: LOGO_SELENE,
|
|
121
|
+
link: { href: "https://selene.cash" }
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
id: "paytaca",
|
|
125
|
+
name: "Paytaca",
|
|
126
|
+
logo: LOGO_PAYTACA,
|
|
127
|
+
link: { href: "https://paytaca.com" }
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
id: "optn",
|
|
131
|
+
name: "OPTN",
|
|
132
|
+
logo: LOGO_OPTN,
|
|
133
|
+
link: { href: "https://optn.cash" }
|
|
134
|
+
}
|
|
135
|
+
];
|
|
136
|
+
//#endregion
|
|
137
|
+
export { BCHC_DIRECTORY, BCHC_PROTOCOLS, BCHC_WALLETS };
|
|
138
|
+
|
|
139
|
+
//# sourceMappingURL=defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.js","names":[],"sources":["../src/defaults.ts"],"sourcesContent":["// A dapp can pass its own ProtocolOption, WalletSupport and\n// WalletDirectoryEntry lists instead. Touches neither `qr-code-styling` nor\n// the DOM, so it's as server-safe as `state.ts`.\n\nimport {\n\tLOGO_CASHONIZE,\n\tLOGO_OPTN,\n\tLOGO_PAYTACA,\n\tLOGO_SELENE,\n\tMARK_CASHCONNECT,\n\tMARK_WALLETCONNECT,\n\tMARK_WIZARDCONNECT,\n} from \"./assets.generated.ts\";\nimport type {\n\tProtocolOption,\n\tWalletDirectoryEntry,\n\tWalletSupport,\n} from \"./state.ts\";\n\n/**\n * The session types BCH Connect ships marks for, in the order the\n * session-type control shows them.\n *\n * @beta\n */\nexport const BCHC_PROTOCOLS: readonly ProtocolOption[] = [\n\t{\n\t\tid: \"wizardconnect\",\n\t\tname: \"WizardConnect\",\n\t\tmark: { src: MARK_WIZARDCONNECT, shape: \"glyph\" },\n\t},\n\t{\n\t\tid: \"bch-wc2\",\n\t\tname: \"WalletConnect\",\n\t\tmark: { src: MARK_WALLETCONNECT, shape: \"tile\" },\n\t},\n\t{\n\t\tid: \"cashconnect\",\n\t\tname: \"CashConnect\",\n\t\tmark: { src: MARK_CASHCONNECT, shape: \"glyph\" },\n\t},\n];\n\n/**\n * The wallets BCH Connect ships logos, a support matrix and desktop links\n * for, in the order the wallet list shows them.\n *\n * A session names the wallet picked in the modal but doesn't carry its\n * logo; look the logo up here by `session.wallet.id`.\n *\n * @example\n * ```ts\n * const logo =\n * BCHC_WALLETS.find((wallet) => wallet.id === session.wallet.id)?.logo ??\n * session.wallet.icon;\n * ```\n *\n * @example\n * ```ts\n * const enabled = view.protocols.map((protocol) => protocol.id);\n * const wallets: WalletOption[] = BCHC_WALLETS.filter((wallet) =>\n * wallet.protocols.some((protocol) => enabled.includes(protocol)),\n * ).map((wallet) => ({\n * ...wallet,\n * protocols: wallet.protocols.filter((protocol) => enabled.includes(protocol)),\n * }));\n * ```\n *\n * @beta\n */\nexport const BCHC_WALLETS: readonly WalletSupport[] = [\n\t{\n\t\tid: \"cashonize\",\n\t\tname: \"Cashonize\",\n\t\tlogo: LOGO_CASHONIZE,\n\t\tprotocols: [\"wizardconnect\", \"bch-wc2\", \"cashconnect\"],\n\t\t// The web app reads `uri` on its root route.\n\t\thref: \"https://cashonize.com/?uri={link}\",\n\t},\n\t{\n\t\tid: \"paytaca\",\n\t\tname: \"Paytaca\",\n\t\tlogo: LOGO_PAYTACA,\n\t\tprotocols: [\"wizardconnect\", \"bch-wc2\"],\n\t\thref: null,\n\t},\n\t{\n\t\tid: \"selene\",\n\t\tname: \"Selene\",\n\t\tlogo: LOGO_SELENE,\n\t\tprotocols: [\"wizardconnect\", \"bch-wc2\"],\n\t\thref: null,\n\t},\n\t{\n\t\tid: \"optn\",\n\t\tname: \"OPTN\",\n\t\tlogo: LOGO_OPTN,\n\t\tprotocols: [\"wizardconnect\", \"bch-wc2\", \"cashconnect\"],\n\t\t// optn.cash is the project's site, not the wallet.\n\t\thref: null,\n\t},\n];\n\n/**\n * Where to actually get each wallet in {@link BCHC_WALLETS}, for the \"Get a\n * wallet\" screen.\n *\n * Official sites only: app-store links are unsupplied, and guessing them\n * risks pointing users to the wrong app.\n *\n * @beta\n */\nexport const BCHC_DIRECTORY: readonly WalletDirectoryEntry[] = [\n\t{\n\t\tid: \"cashonize\",\n\t\tname: \"Cashonize\",\n\t\tlogo: LOGO_CASHONIZE,\n\t\tlink: { href: \"https://about.cashonize.com/\" },\n\t},\n\t{\n\t\tid: \"selene\",\n\t\tname: \"Selene\",\n\t\tlogo: LOGO_SELENE,\n\t\tlink: { href: \"https://selene.cash\" },\n\t},\n\t{\n\t\tid: \"paytaca\",\n\t\tname: \"Paytaca\",\n\t\tlogo: LOGO_PAYTACA,\n\t\tlink: { href: \"https://paytaca.com\" },\n\t},\n\t{\n\t\tid: \"optn\",\n\t\tname: \"OPTN\",\n\t\tlogo: LOGO_OPTN,\n\t\tlink: { href: \"https://optn.cash\" },\n\t},\n];\n"],"mappings":";;;;;;;;;AAyBA,MAAa,iBAA4C;CACxD;EACC,IAAI;EACJ,MAAM;EACN,MAAM;GAAE,KAAK;GAAoB,OAAO;EAAQ;CACjD;CACA;EACC,IAAI;EACJ,MAAM;EACN,MAAM;GAAE,KAAK;GAAoB,OAAO;EAAO;CAChD;CACA;EACC,IAAI;EACJ,MAAM;EACN,MAAM;GAAE,KAAK;GAAkB,OAAO;EAAQ;CAC/C;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,MAAa,eAAyC;CACrD;EACC,IAAI;EACJ,MAAM;EACN,MAAM;EACN,WAAW;GAAC;GAAiB;GAAW;EAAa;EAErD,MAAM;CACP;CACA;EACC,IAAI;EACJ,MAAM;EACN,MAAM;EACN,WAAW,CAAC,iBAAiB,SAAS;EACtC,MAAM;CACP;CACA;EACC,IAAI;EACJ,MAAM;EACN,MAAM;EACN,WAAW,CAAC,iBAAiB,SAAS;EACtC,MAAM;CACP;CACA;EACC,IAAI;EACJ,MAAM;EACN,MAAM;EACN,WAAW;GAAC;GAAiB;GAAW;EAAa;EAErD,MAAM;CACP;AACD;;;;;;;;;;AAWA,MAAa,iBAAkD;CAC9D;EACC,IAAI;EACJ,MAAM;EACN,MAAM;EACN,MAAM,EAAE,MAAM,+BAA+B;CAC9C;CACA;EACC,IAAI;EACJ,MAAM;EACN,MAAM;EACN,MAAM,EAAE,MAAM,sBAAsB;CACrC;CACA;EACC,IAAI;EACJ,MAAM;EACN,MAAM;EACN,MAAM,EAAE,MAAM,sBAAsB;CACrC;CACA;EACC,IAAI;EACJ,MAAM;EACN,MAAM;EACN,MAAM,EAAE,MAAM,oBAAoB;CACnC;AACD"}
|
package/dist/define.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/define.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Registers `<bchc-modal>` and `<bchc-toast>`. Idempotent; on a server it
|
|
5
|
+
* registers them in Lit's server registry, so it's safe to call from shared code.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* defineElements();
|
|
10
|
+
* const modal = document.createElement("bchc-modal");
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @beta
|
|
14
|
+
*/
|
|
15
|
+
export declare function defineElements(): void;
|
|
16
|
+
//#endregion
|
|
17
|
+
//# sourceMappingURL=define.d.ts.map
|
package/dist/define.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
import { register } from "./register.js";
|
|
3
|
+
import QrCodeStyling from "qr-code-styling";
|
|
4
|
+
//#region src/define.ts
|
|
5
|
+
/**
|
|
6
|
+
* Registers `<bchc-modal>` and `<bchc-toast>`. Idempotent; on a server it
|
|
7
|
+
* registers them in Lit's server registry, so it's safe to call from shared code.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* defineElements();
|
|
12
|
+
* const modal = document.createElement("bchc-modal");
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @beta
|
|
16
|
+
*/
|
|
17
|
+
function defineElements() {
|
|
18
|
+
register(QrCodeStyling);
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { defineElements };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=define.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define.js","names":[],"sources":["../src/define.ts"],"sourcesContent":["// qr-code-styling is imported only here, so an import that skips\n// defineElements never loads it (every module ships side-effect free).\nimport QrCodeStyling from \"qr-code-styling\";\nimport type { CodeRenderer } from \"./code.ts\";\nimport { register } from \"./register.ts\";\n\n/**\n * Registers `<bchc-modal>` and `<bchc-toast>`. Idempotent; on a server it\n * registers them in Lit's server registry, so it's safe to call from shared code.\n *\n * @example\n * ```ts\n * defineElements();\n * const modal = document.createElement(\"bchc-modal\");\n * ```\n *\n * @beta\n */\nexport function defineElements(): void {\n\t// Cast narrowly here rather than widening `CodeRenderer` to match this one library's shape.\n\tregister(QrCodeStyling as unknown as CodeRenderer);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkBA,SAAgB,iBAAuB;CAEtC,SAAS,aAAwC;AAClD"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
|
|
2
|
+
import { safeHref } from "./html.js";
|
|
3
|
+
import { icon } from "./icons.js";
|
|
4
|
+
import { html } from "lit";
|
|
5
|
+
//#region src/directory.ts
|
|
6
|
+
/** The directory screen's body. @internal */
|
|
7
|
+
function directoryScreen(directory, messages, logoTemplate) {
|
|
8
|
+
return html`
|
|
9
|
+
<div class="single">
|
|
10
|
+
<p class="section-label">${messages.directoryHeading}</p>
|
|
11
|
+
<div class="directory">
|
|
12
|
+
${directory.map((entry) => {
|
|
13
|
+
const href = entry.link === null ? null : safeHref(entry.link.href);
|
|
14
|
+
const logo = logoTemplate(entry.logo, 36, "directory-logo");
|
|
15
|
+
const name = html`<span class="wallet-name" title=${entry.name}>${entry.name}</span>`;
|
|
16
|
+
if (href === null) return html`
|
|
17
|
+
<div class="directory-row">
|
|
18
|
+
${logo}
|
|
19
|
+
${name}
|
|
20
|
+
</div>`;
|
|
21
|
+
return html`
|
|
22
|
+
<a class="directory-row" href=${href} target="_blank" rel="noreferrer">
|
|
23
|
+
${logo}
|
|
24
|
+
${name}
|
|
25
|
+
<span class="directory-links">
|
|
26
|
+
<span class="button pill">${entry.link?.label ?? messages.getWallet(entry.name)}${icon("arrowUpRight", 14)}</span>
|
|
27
|
+
</span>
|
|
28
|
+
</a>`;
|
|
29
|
+
})}
|
|
30
|
+
</div>
|
|
31
|
+
</div>
|
|
32
|
+
`;
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
export { directoryScreen };
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=directory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directory.js","names":[],"sources":["../src/directory.ts"],"sourcesContent":["// The \"Get a wallet\" screen: wallets to install, never ones to connect.\n\nimport { html, type TemplateResult } from \"lit\";\nimport { safeHref } from \"./html.ts\";\nimport { icon } from \"./icons.ts\";\nimport type { BchcMessages } from \"./messages.ts\";\nimport type { WalletDirectoryEntry } from \"./state.ts\";\n\n/** Draws a logo, falling back to the generic wallet tile. @internal */\nexport type LogoTemplate = (\n\tlogo: string | null,\n\tsize: number,\n\textraClass: string,\n) => TemplateResult;\n\n/** The directory screen's body. @internal */\nexport function directoryScreen(\n\tdirectory: readonly WalletDirectoryEntry[],\n\tmessages: BchcMessages,\n\tlogoTemplate: LogoTemplate,\n): TemplateResult {\n\treturn html`\n\t\t<div class=\"single\">\n\t\t\t<p class=\"section-label\">${messages.directoryHeading}</p>\n\t\t\t<div class=\"directory\">\n\t\t\t\t${directory.map((entry) => {\n\t\t\t\t\tconst href = entry.link === null ? null : safeHref(entry.link.href);\n\t\t\t\t\tconst logo = logoTemplate(entry.logo, 36, \"directory-logo\");\n\t\t\t\t\tconst name = html`<span class=\"wallet-name\" title=${entry.name}>${entry.name}</span>`;\n\t\t\t\t\tif (href === null)\n\t\t\t\t\t\treturn html`\n\t\t\t\t\t<div class=\"directory-row\">\n\t\t\t\t\t\t${logo}\n\t\t\t\t\t\t${name}\n\t\t\t\t\t</div>`;\n\t\t\t\t\treturn html`\n\t\t\t\t\t<a class=\"directory-row\" href=${href} target=\"_blank\" rel=\"noreferrer\">\n\t\t\t\t\t\t${logo}\n\t\t\t\t\t\t${name}\n\t\t\t\t\t\t<span class=\"directory-links\">\n\t\t\t\t\t\t\t<span class=\"button pill\">${entry.link?.label ?? messages.getWallet(entry.name)}${icon(\"arrowUpRight\", 14)}</span>\n\t\t\t\t\t\t</span>\n\t\t\t\t\t</a>`;\n\t\t\t\t})}\n\t\t\t</div>\n\t\t</div>\n\t`;\n}\n"],"mappings":";;;;;;AAgBA,SAAgB,gBACf,WACA,UACA,cACiB;CACjB,OAAO,IAAI;;8BAEkB,SAAS,iBAAiB;;MAElD,UAAU,KAAK,UAAU;EAC1B,MAAM,OAAO,MAAM,SAAS,OAAO,OAAO,SAAS,MAAM,KAAK,IAAI;EAClE,MAAM,OAAO,aAAa,MAAM,MAAM,IAAI,gBAAgB;EAC1D,MAAM,OAAO,IAAI,mCAAmC,MAAM,KAAK,GAAG,MAAM,KAAK;EAC7E,IAAI,SAAS,MACZ,OAAO,IAAI;;QAET,KAAK;QACL,KAAK;;EAER,OAAO,IAAI;qCACqB,KAAK;QAClC,KAAK;QACL,KAAK;;mCAEsB,MAAM,MAAM,SAAS,SAAS,UAAU,MAAM,IAAI,IAAI,KAAK,gBAAgB,EAAE,EAAE;;;CAG9G,CAAC,EAAE;;;;AAIP"}
|
package/dist/faces.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
|
|
2
|
+
import { icon } from "./icons.js";
|
|
3
|
+
import { html, nothing, svg } from "lit";
|
|
4
|
+
//#region src/faces.ts
|
|
5
|
+
const FAILURE_MESSAGE_KEYS = {
|
|
6
|
+
rejected: {
|
|
7
|
+
title: "rejectedTitle",
|
|
8
|
+
detail: "rejectedDetail"
|
|
9
|
+
},
|
|
10
|
+
timeout: {
|
|
11
|
+
title: "timeoutTitle",
|
|
12
|
+
detail: "timeoutDetail"
|
|
13
|
+
},
|
|
14
|
+
aborted: {
|
|
15
|
+
title: "abortedTitle",
|
|
16
|
+
detail: "abortedDetail"
|
|
17
|
+
},
|
|
18
|
+
transport: {
|
|
19
|
+
title: "transportTitle",
|
|
20
|
+
detail: "transportDetail"
|
|
21
|
+
},
|
|
22
|
+
"network-mismatch": {
|
|
23
|
+
title: "networkMismatchTitle",
|
|
24
|
+
detail: "networkMismatchDetail"
|
|
25
|
+
},
|
|
26
|
+
unsupported: {
|
|
27
|
+
title: "unsupportedTitle",
|
|
28
|
+
detail: "unsupportedDetail"
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
/** Which caption the phase calls for. @internal */
|
|
32
|
+
function captionKind(view, linkFailed) {
|
|
33
|
+
switch (view.phase.kind) {
|
|
34
|
+
case "initiating": return "initiating";
|
|
35
|
+
case "awaiting-approval": return linkFailed ? "hint" : "scan";
|
|
36
|
+
default: return "none";
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** The copy button's contents. @internal */
|
|
40
|
+
function copyFace(messages, copied) {
|
|
41
|
+
return copied ? html`${icon("check")}${messages.linkCopied}` : html`${icon("link")}${messages.copyLink}`;
|
|
42
|
+
}
|
|
43
|
+
const WALLET_MARKER = "";
|
|
44
|
+
function scanWith(messages, wallet) {
|
|
45
|
+
const parts = messages.scanWith(WALLET_MARKER).split(WALLET_MARKER);
|
|
46
|
+
if (parts.length !== 2) return messages.scanWith(wallet.name);
|
|
47
|
+
return html`${parts[0]}${wallet.template}${parts[1]}`;
|
|
48
|
+
}
|
|
49
|
+
/** The caption's contents; `wallet` is `null` on the drawer, which names none. @internal */
|
|
50
|
+
function caption(messages, kind, wallet) {
|
|
51
|
+
switch (kind) {
|
|
52
|
+
case "initiating": return html`<span class="dots"><i></i><i></i><i></i></span><span class="caption-text">${messages.initiating}</span>`;
|
|
53
|
+
case "hint": return html`${icon("info")}<span class="caption-text">${messages.linkFailed}</span>`;
|
|
54
|
+
case "scan": return html`${icon("scanLine")}<span class="caption-text">${wallet === null ? messages.scan : scanWith(messages, wallet)}</span>`;
|
|
55
|
+
default: return nothing;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const RING_DOTS = 14;
|
|
59
|
+
/** Each dot carries its index (`--i`) so the stylesheet can animate them in order. */
|
|
60
|
+
const RING = html`<svg class="ring" width="96" height="96" viewBox="0 0 96 96" fill="currentColor" aria-hidden="true">${Array.from({ length: RING_DOTS }, (_, index) => {
|
|
61
|
+
const angle = index / RING_DOTS * Math.PI * 2 - Math.PI / 2;
|
|
62
|
+
const x = (48 + Math.cos(angle) * 41).toFixed(2);
|
|
63
|
+
const y = (48 + Math.sin(angle) * 41).toFixed(2);
|
|
64
|
+
return svg`<circle cx=${x} cy=${y} r="3.6" style="--i:${index}"/>`;
|
|
65
|
+
})}</svg>`;
|
|
66
|
+
/** The failure face for `reason`, or nothing. @internal */
|
|
67
|
+
function statusFace(messages, reason) {
|
|
68
|
+
if (reason === null) return nothing;
|
|
69
|
+
const keys = FAILURE_MESSAGE_KEYS[reason];
|
|
70
|
+
return html`
|
|
71
|
+
<span class="status-mark">${RING}${icon("x", 34)}</span>
|
|
72
|
+
<strong class="status-title">${messages[keys.title]}</strong>
|
|
73
|
+
<p class="status-detail">${messages[keys.detail]}</p>
|
|
74
|
+
<button class="button primary pill retry" type="button" data-act="retry">${icon("rotateCcw", 15)}${messages.tryAgain}</button>
|
|
75
|
+
`;
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
export { caption, captionKind, copyFace, statusFace };
|
|
79
|
+
|
|
80
|
+
//# sourceMappingURL=faces.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"faces.js","names":[],"sources":["../src/faces.ts"],"sourcesContent":["// The code tile's changing faces: the caption under it, the copy button and the failure face.\n\nimport { html, nothing, svg, type TemplateResult } from \"lit\";\nimport { icon } from \"./icons.ts\";\nimport type { BchcMessages } from \"./messages.ts\";\nimport type { FailureReason, ModalView } from \"./state.ts\";\n\n/** @internal */\nexport type CaptionKind = \"initiating\" | \"hint\" | \"scan\" | \"none\";\n\n// The catalogue's copy keys: `lang` is a tag, and the function keys need a value.\n/** @internal */\nexport type MessageTextKey = Exclude<\n\t{\n\t\t[K in keyof BchcMessages]: BchcMessages[K] extends string ? K : never;\n\t}[keyof BchcMessages],\n\t\"lang\"\n>;\n\n// Exhaustive on FailureReason, so a new reason fails typecheck here first.\nconst FAILURE_MESSAGE_KEYS: Readonly<\n\tRecord<\n\t\tFailureReason,\n\t\t{ readonly title: MessageTextKey; readonly detail: MessageTextKey }\n\t>\n> = {\n\trejected: { title: \"rejectedTitle\", detail: \"rejectedDetail\" },\n\ttimeout: { title: \"timeoutTitle\", detail: \"timeoutDetail\" },\n\taborted: { title: \"abortedTitle\", detail: \"abortedDetail\" },\n\ttransport: { title: \"transportTitle\", detail: \"transportDetail\" },\n\t\"network-mismatch\": {\n\t\ttitle: \"networkMismatchTitle\",\n\t\tdetail: \"networkMismatchDetail\",\n\t},\n\tunsupported: { title: \"unsupportedTitle\", detail: \"unsupportedDetail\" },\n};\n\n/** Which caption the phase calls for. @internal */\nexport function captionKind(view: ModalView, linkFailed: boolean): CaptionKind {\n\tswitch (view.phase.kind) {\n\t\tcase \"initiating\":\n\t\t\treturn \"initiating\";\n\t\tcase \"awaiting-approval\":\n\t\t\treturn linkFailed ? \"hint\" : \"scan\";\n\t\tdefault:\n\t\t\treturn \"none\";\n\t}\n}\n\n/** The copy button's contents. @internal */\nexport function copyFace(\n\tmessages: BchcMessages,\n\tcopied: boolean,\n): TemplateResult {\n\treturn copied\n\t\t? html`${icon(\"check\")}${messages.linkCopied}`\n\t\t: html`${icon(\"link\")}${messages.copyLink}`;\n}\n\n/** The selected wallet as the scan caption names it: its name, and its mark and name as rendered. @internal */\nexport interface CaptionWallet {\n\treadonly name: string;\n\treadonly template: TemplateResult;\n}\n\n// `scanWith` is called with this in place of the name, so the wallet's mark lands\n// wherever the language puts the name. Private use: no catalogue would type it.\nconst WALLET_MARKER = \"\\u{E000}\";\n\nfunction scanWith(messages: BchcMessages, wallet: CaptionWallet): unknown {\n\tconst parts = messages.scanWith(WALLET_MARKER).split(WALLET_MARKER);\n\t// A wording that drops or repeats the name gets plain text instead.\n\tif (parts.length !== 2) return messages.scanWith(wallet.name);\n\treturn html`${parts[0]}${wallet.template}${parts[1]}`;\n}\n\n/** The caption's contents; `wallet` is `null` on the drawer, which names none. @internal */\nexport function caption(\n\tmessages: BchcMessages,\n\tkind: CaptionKind,\n\twallet: CaptionWallet | null,\n): unknown {\n\tswitch (kind) {\n\t\tcase \"initiating\":\n\t\t\treturn html`<span class=\"dots\"><i></i><i></i><i></i></span><span class=\"caption-text\">${messages.initiating}</span>`;\n\t\tcase \"hint\":\n\t\t\treturn html`${icon(\"info\")}<span class=\"caption-text\">${messages.linkFailed}</span>`;\n\t\tcase \"scan\":\n\t\t\treturn html`${icon(\"scanLine\")}<span class=\"caption-text\">${wallet === null ? messages.scan : scanWith(messages, wallet)}</span>`;\n\t\tdefault:\n\t\t\treturn nothing;\n\t}\n}\n\nconst RING_DOTS = 14;\n\n/** Each dot carries its index (`--i`) so the stylesheet can animate them in order. */\nconst RING = html`<svg class=\"ring\" width=\"96\" height=\"96\" viewBox=\"0 0 96 96\" fill=\"currentColor\" aria-hidden=\"true\">${Array.from(\n\t{ length: RING_DOTS },\n\t(_, index) => {\n\t\tconst angle = (index / RING_DOTS) * Math.PI * 2 - Math.PI / 2;\n\t\tconst x = (48 + Math.cos(angle) * 41).toFixed(2);\n\t\tconst y = (48 + Math.sin(angle) * 41).toFixed(2);\n\t\treturn svg`<circle cx=${x} cy=${y} r=\"3.6\" style=\"--i:${index}\"/>`;\n\t},\n)}</svg>`;\n\n/** The failure face for `reason`, or nothing. @internal */\nexport function statusFace(\n\tmessages: BchcMessages,\n\treason: FailureReason | null,\n): unknown {\n\tif (reason === null) return nothing;\n\tconst keys = FAILURE_MESSAGE_KEYS[reason];\n\treturn html`\n\t\t<span class=\"status-mark\">${RING}${icon(\"x\", 34)}</span>\n\t\t<strong class=\"status-title\">${messages[keys.title]}</strong>\n\t\t<p class=\"status-detail\">${messages[keys.detail]}</p>\n\t\t<button class=\"button primary pill retry\" type=\"button\" data-act=\"retry\">${icon(\"rotateCcw\", 15)}${messages.tryAgain}</button>\n\t`;\n}\n"],"mappings":";;;;AAoBA,MAAM,uBAKF;CACH,UAAU;EAAE,OAAO;EAAiB,QAAQ;CAAiB;CAC7D,SAAS;EAAE,OAAO;EAAgB,QAAQ;CAAgB;CAC1D,SAAS;EAAE,OAAO;EAAgB,QAAQ;CAAgB;CAC1D,WAAW;EAAE,OAAO;EAAkB,QAAQ;CAAkB;CAChE,oBAAoB;EACnB,OAAO;EACP,QAAQ;CACT;CACA,aAAa;EAAE,OAAO;EAAoB,QAAQ;CAAoB;AACvE;;AAGA,SAAgB,YAAY,MAAiB,YAAkC;CAC9E,QAAQ,KAAK,MAAM,MAAnB;EACC,KAAK,cACJ,OAAO;EACR,KAAK,qBACJ,OAAO,aAAa,SAAS;EAC9B,SACC,OAAO;CACT;AACD;;AAGA,SAAgB,SACf,UACA,QACiB;CACjB,OAAO,SACJ,IAAI,GAAG,KAAK,OAAO,IAAI,SAAS,eAChC,IAAI,GAAG,KAAK,MAAM,IAAI,SAAS;AACnC;AAUA,MAAM,gBAAgB;AAEtB,SAAS,SAAS,UAAwB,QAAgC;CACzE,MAAM,QAAQ,SAAS,SAAS,aAAa,CAAC,CAAC,MAAM,aAAa;CAElE,IAAI,MAAM,WAAW,GAAG,OAAO,SAAS,SAAS,OAAO,IAAI;CAC5D,OAAO,IAAI,GAAG,MAAM,KAAK,OAAO,WAAW,MAAM;AAClD;;AAGA,SAAgB,QACf,UACA,MACA,QACU;CACV,QAAQ,MAAR;EACC,KAAK,cACJ,OAAO,IAAI,6EAA6E,SAAS,WAAW;EAC7G,KAAK,QACJ,OAAO,IAAI,GAAG,KAAK,MAAM,EAAE,6BAA6B,SAAS,WAAW;EAC7E,KAAK,QACJ,OAAO,IAAI,GAAG,KAAK,UAAU,EAAE,6BAA6B,WAAW,OAAO,SAAS,OAAO,SAAS,UAAU,MAAM,EAAE;EAC1H,SACC,OAAO;CACT;AACD;AAEA,MAAM,YAAY;;AAGlB,MAAM,OAAO,IAAI,uGAAuG,MAAM,KAC7H,EAAE,QAAQ,UAAU,IACnB,GAAG,UAAU;CACb,MAAM,QAAS,QAAQ,YAAa,KAAK,KAAK,IAAI,KAAK,KAAK;CAC5D,MAAM,KAAK,KAAK,KAAK,IAAI,KAAK,IAAI,GAAA,CAAI,QAAQ,CAAC;CAC/C,MAAM,KAAK,KAAK,KAAK,IAAI,KAAK,IAAI,GAAA,CAAI,QAAQ,CAAC;CAC/C,OAAO,GAAG,cAAc,EAAE,MAAM,EAAE,sBAAsB,MAAM;AAC/D,CACD,EAAE;;AAGF,SAAgB,WACf,UACA,QACU;CACV,IAAI,WAAW,MAAM,OAAO;CAC5B,MAAM,OAAO,qBAAqB;CAClC,OAAO,IAAI;8BACkB,OAAO,KAAK,KAAK,EAAE,EAAE;iCAClB,SAAS,KAAK,OAAO;6BACzB,SAAS,KAAK,QAAQ;6EAC0B,KAAK,aAAa,EAAE,IAAI,SAAS,SAAS;;AAEvH"}
|
package/dist/gesture.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
|
|
2
|
+
/** Past this fraction of the sheet's height, releasing dismisses it. */
|
|
3
|
+
const DISMISS_RATIO = .25;
|
|
4
|
+
/** Past this speed (px/ms) a flick dismisses regardless of distance. */
|
|
5
|
+
const DISMISS_VELOCITY = .4;
|
|
6
|
+
function rubberBand(overshoot) {
|
|
7
|
+
return overshoot * 48 / (48 + Math.abs(overshoot));
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Arbitrates a press that has moved (dx, dy) from its start. `scrolled` and
|
|
11
|
+
* `scrollable` describe the nearest scroll container between the press and
|
|
12
|
+
* the sheet: whether it is scrolled away from its top, and whether it can
|
|
13
|
+
* still scroll further down.
|
|
14
|
+
*/
|
|
15
|
+
function intent(dx, dy, scrolled, scrollable) {
|
|
16
|
+
if (Math.max(Math.abs(dx), Math.abs(dy)) < 8) return null;
|
|
17
|
+
if (Math.abs(dx) >= Math.abs(dy)) return "pass";
|
|
18
|
+
if (dy > 0) return scrolled ? "pass" : "drag";
|
|
19
|
+
return scrollable ? "pass" : "drag";
|
|
20
|
+
}
|
|
21
|
+
/** Appends a sample and drops every sample older than the window relative to it. */
|
|
22
|
+
function recordVelocitySample(samples, time, y) {
|
|
23
|
+
const cutoff = time - 80;
|
|
24
|
+
return [...samples.filter((sample) => sample.time >= cutoff), {
|
|
25
|
+
time,
|
|
26
|
+
y
|
|
27
|
+
}];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Velocity (px/ms) across the sliding window, as of `time`. Zero with fewer
|
|
31
|
+
* than two samples, a zero-length span, or when the newest sample is older
|
|
32
|
+
* than the window relative to `time` (the finger paused before this call).
|
|
33
|
+
*/
|
|
34
|
+
function velocityAt(samples, time) {
|
|
35
|
+
const newest = samples[samples.length - 1];
|
|
36
|
+
const oldest = samples[0];
|
|
37
|
+
if (newest === void 0 || oldest === void 0) return 0;
|
|
38
|
+
if (samples.length < 2) return 0;
|
|
39
|
+
if (time - newest.time > 80) return 0;
|
|
40
|
+
const span = newest.time - oldest.time;
|
|
41
|
+
if (span === 0) return 0;
|
|
42
|
+
return (newest.y - oldest.y) / span;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Whether releasing now dismisses the sheet: past the distance ratio or
|
|
46
|
+
* flicking down fast enough, but never while flicking back up.
|
|
47
|
+
*/
|
|
48
|
+
function decideRelease(offset, height, velocity) {
|
|
49
|
+
if (offset <= 0) return false;
|
|
50
|
+
if (velocity < -.4) return false;
|
|
51
|
+
return offset > height * .25 || velocity > .4;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* How visible the scrim stays at a given drag offset: opaque at rest,
|
|
55
|
+
* fading linearly to nothing as the sheet nears fully off-screen. An upward
|
|
56
|
+
* pull (a negative offset, past rest) keeps it fully visible.
|
|
57
|
+
*/
|
|
58
|
+
function scrimOpacity(offset, height) {
|
|
59
|
+
if (offset <= 0 || height <= 0) return 1;
|
|
60
|
+
return Math.max(0, Math.min(1, 1 - offset / height));
|
|
61
|
+
}
|
|
62
|
+
const EASE_SHEET_INITIAL_SLOPE = 2.25;
|
|
63
|
+
/**
|
|
64
|
+
* A release animation's duration (ms), continuing the finger's speed. `distance`
|
|
65
|
+
* is the remaining travel (px, absolute); `speed` is the release speed toward
|
|
66
|
+
* the target (px/ms, zero or negative when the finger was still or moving
|
|
67
|
+
* away); `longest` is the ceiling (a still or receding finger gets exactly
|
|
68
|
+
* `longest`). Clamped to between 30% of `longest` and `longest`.
|
|
69
|
+
*/
|
|
70
|
+
function releaseDuration(distance, speed, longest) {
|
|
71
|
+
if (speed <= 0) return longest;
|
|
72
|
+
const continued = EASE_SHEET_INITIAL_SLOPE * distance / speed;
|
|
73
|
+
return Math.min(Math.max(continued, longest * .3), longest);
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
76
|
+
export { DISMISS_RATIO, DISMISS_VELOCITY, EASE_SHEET_INITIAL_SLOPE, decideRelease, intent, recordVelocitySample, releaseDuration, rubberBand, scrimOpacity, velocityAt };
|
|
77
|
+
|
|
78
|
+
//# sourceMappingURL=gesture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gesture.js","names":[],"sources":["../src/gesture.ts"],"sourcesContent":["/**\n * Pure decision rules for the drawer's drag gesture. `sheet.ts` owns the DOM\n * events and calls into these; nothing here touches the DOM, so it runs the\n * same in a browser or under Node in tests.\n */\n\n/** Below this travel (px, the larger of |dx| and |dy|) the gesture's direction is undecided. */\nexport const DECISION_DISTANCE = 8;\n\n/** Past this fraction of the sheet's height, releasing dismisses it. */\nexport const DISMISS_RATIO = 0.25;\n\n/** Past this speed (px/ms) a flick dismisses regardless of distance. */\nexport const DISMISS_VELOCITY = 0.4;\n\n/** How far the sheet may be pulled above its resting place before it stops. */\nexport const RUBBER_LIMIT = 48;\n\n/** How long a velocity sample stays in the sliding window (ms). */\nexport const VELOCITY_WINDOW = 80;\n\n// Divides overshoot by an amount that grows with it, so the sheet stiffens instead of hitting a wall.\nexport function rubberBand(overshoot: number): number {\n\treturn (overshoot * RUBBER_LIMIT) / (RUBBER_LIMIT + Math.abs(overshoot));\n}\n\nexport type GestureIntent = \"drag\" | \"pass\" | null;\n\n/**\n * Arbitrates a press that has moved (dx, dy) from its start. `scrolled` and\n * `scrollable` describe the nearest scroll container between the press and\n * the sheet: whether it is scrolled away from its top, and whether it can\n * still scroll further down.\n */\nexport function intent(\n\tdx: number,\n\tdy: number,\n\tscrolled: boolean,\n\tscrollable: boolean,\n): GestureIntent {\n\tif (Math.max(Math.abs(dx), Math.abs(dy)) < DECISION_DISTANCE) return null;\n\tif (Math.abs(dx) >= Math.abs(dy)) return \"pass\";\n\tif (dy > 0) return scrolled ? \"pass\" : \"drag\";\n\treturn scrollable ? \"pass\" : \"drag\";\n}\n\nexport interface VelocitySample {\n\treadonly time: number;\n\treadonly y: number;\n}\n\n/** Appends a sample and drops every sample older than the window relative to it. */\nexport function recordVelocitySample(\n\tsamples: readonly VelocitySample[],\n\ttime: number,\n\ty: number,\n): readonly VelocitySample[] {\n\tconst cutoff = time - VELOCITY_WINDOW;\n\treturn [...samples.filter((sample) => sample.time >= cutoff), { time, y }];\n}\n\n/**\n * Velocity (px/ms) across the sliding window, as of `time`. Zero with fewer\n * than two samples, a zero-length span, or when the newest sample is older\n * than the window relative to `time` (the finger paused before this call).\n */\nexport function velocityAt(\n\tsamples: readonly VelocitySample[],\n\ttime: number,\n): number {\n\tconst newest = samples[samples.length - 1];\n\tconst oldest = samples[0];\n\tif (newest === undefined || oldest === undefined) return 0;\n\tif (samples.length < 2) return 0;\n\tif (time - newest.time > VELOCITY_WINDOW) return 0;\n\tconst span = newest.time - oldest.time;\n\tif (span === 0) return 0;\n\treturn (newest.y - oldest.y) / span;\n}\n\n/**\n * Whether releasing now dismisses the sheet: past the distance ratio or\n * flicking down fast enough, but never while flicking back up.\n */\nexport function decideRelease(\n\toffset: number,\n\theight: number,\n\tvelocity: number,\n): boolean {\n\tif (offset <= 0) return false;\n\tif (velocity < -DISMISS_VELOCITY) return false;\n\treturn offset > height * DISMISS_RATIO || velocity > DISMISS_VELOCITY;\n}\n\n/**\n * How visible the scrim stays at a given drag offset: opaque at rest,\n * fading linearly to nothing as the sheet nears fully off-screen. An upward\n * pull (a negative offset, past rest) keeps it fully visible.\n */\nexport function scrimOpacity(offset: number, height: number): number {\n\tif (offset <= 0 || height <= 0) return 1;\n\treturn Math.max(0, Math.min(1, 1 - offset / height));\n}\n\n// --bchc-ease-sheet's initial slope (0.72 / 0.32): how many px of its curve\n// an animation covers per ms at t=0, so a duration computed from it starts\n// at exactly the finger's release speed instead of snapping.\nexport const EASE_SHEET_INITIAL_SLOPE = 2.25;\n\n/**\n * A release animation's duration (ms), continuing the finger's speed. `distance`\n * is the remaining travel (px, absolute); `speed` is the release speed toward\n * the target (px/ms, zero or negative when the finger was still or moving\n * away); `longest` is the ceiling (a still or receding finger gets exactly\n * `longest`). Clamped to between 30% of `longest` and `longest`.\n */\nexport function releaseDuration(\n\tdistance: number,\n\tspeed: number,\n\tlongest: number,\n): number {\n\tif (speed <= 0) return longest;\n\tconst continued = (EASE_SHEET_INITIAL_SLOPE * distance) / speed;\n\treturn Math.min(Math.max(continued, longest * 0.3), longest);\n}\n"],"mappings":";;AAUA,MAAa,gBAAgB;;AAG7B,MAAa,mBAAmB;AAShC,SAAgB,WAAW,WAA2B;CACrD,OAAQ,YAAA,MAAA,KAA4C,KAAK,IAAI,SAAS;AACvE;;;;;;;AAUA,SAAgB,OACf,IACA,IACA,UACA,YACgB;CAChB,IAAI,KAAK,IAAI,KAAK,IAAI,EAAE,GAAG,KAAK,IAAI,EAAE,CAAC,IAAA,GAAuB,OAAO;CACrE,IAAI,KAAK,IAAI,EAAE,KAAK,KAAK,IAAI,EAAE,GAAG,OAAO;CACzC,IAAI,KAAK,GAAG,OAAO,WAAW,SAAS;CACvC,OAAO,aAAa,SAAS;AAC9B;;AAQA,SAAgB,qBACf,SACA,MACA,GAC4B;CAC5B,MAAM,SAAS,OAAA;CACf,OAAO,CAAC,GAAG,QAAQ,QAAQ,WAAW,OAAO,QAAQ,MAAM,GAAG;EAAE;EAAM;CAAE,CAAC;AAC1E;;;;;;AAOA,SAAgB,WACf,SACA,MACS;CACT,MAAM,SAAS,QAAQ,QAAQ,SAAS;CACxC,MAAM,SAAS,QAAQ;CACvB,IAAI,WAAW,KAAA,KAAa,WAAW,KAAA,GAAW,OAAO;CACzD,IAAI,QAAQ,SAAS,GAAG,OAAO;CAC/B,IAAI,OAAO,OAAO,OAAA,IAAwB,OAAO;CACjD,MAAM,OAAO,OAAO,OAAO,OAAO;CAClC,IAAI,SAAS,GAAG,OAAO;CACvB,QAAQ,OAAO,IAAI,OAAO,KAAK;AAChC;;;;;AAMA,SAAgB,cACf,QACA,QACA,UACU;CACV,IAAI,UAAU,GAAG,OAAO;CACxB,IAAI,WAAW,KAAmB,OAAO;CACzC,OAAO,SAAS,SAAA,OAA0B,WAAA;AAC3C;;;;;;AAOA,SAAgB,aAAa,QAAgB,QAAwB;CACpE,IAAI,UAAU,KAAK,UAAU,GAAG,OAAO;CACvC,OAAO,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,IAAI,SAAS,MAAM,CAAC;AACpD;AAKA,MAAa,2BAA2B;;;;;;;;AASxC,SAAgB,gBACf,UACA,OACA,SACS;CACT,IAAI,SAAS,GAAG,OAAO;CACvB,MAAM,YAAa,2BAA2B,WAAY;CAC1D,OAAO,KAAK,IAAI,KAAK,IAAI,WAAW,UAAU,EAAG,GAAG,OAAO;AAC5D"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
|
|
2
|
+
import { ConnectPhase, FailureReason, MarkShape, ModalScreen, ModalView, Network, ProtocolId, ProtocolMark, ProtocolOption, WalletDirectoryEntry, WalletOption } from "./state.js";
|
|
3
|
+
import { ConnectUi } from "@bchconnect/core";
|
|
4
|
+
//#region src/headless.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* What the person did in the modal, reported by a {@link ModalRenderer}.
|
|
7
|
+
*
|
|
8
|
+
* @beta
|
|
9
|
+
*/
|
|
10
|
+
export interface ModalActions {
|
|
11
|
+
/** The person selected a wallet, by id. */
|
|
12
|
+
selectWallet(wallet: string): void;
|
|
13
|
+
/** The person picked a session type. */
|
|
14
|
+
selectProtocol(protocol: ProtocolId): void;
|
|
15
|
+
/** The person moved between the connect and wallets screens. */
|
|
16
|
+
showScreen(screen: ModalScreen): void;
|
|
17
|
+
/** The person pressed Try again after a failure. */
|
|
18
|
+
retry(): void;
|
|
19
|
+
/** The person dismissed the modal: close button, Escape, backdrop or drag. */
|
|
20
|
+
dismiss(): void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Draws the modal for {@link headlessModal}. It keeps no connection state:
|
|
24
|
+
* it draws each view and reports what the person does.
|
|
25
|
+
*
|
|
26
|
+
* @beta
|
|
27
|
+
*/
|
|
28
|
+
export interface ModalRenderer {
|
|
29
|
+
/** Shows the modal with its first view. */
|
|
30
|
+
open(view: ModalView, actions: ModalActions): void;
|
|
31
|
+
/** Replaces the view, each time with a new object. */
|
|
32
|
+
update(view: ModalView): void;
|
|
33
|
+
/** Plays the exit and removes the modal; resolves once it is gone. */
|
|
34
|
+
close(): Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Whether the person can see the wallet list now. When `false`, the
|
|
37
|
+
* selection is not reported as the session's wallet. Defaults to `true`.
|
|
38
|
+
*/
|
|
39
|
+
showsWallets?(): boolean;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The protocol and wallet a {@link headlessModal} opens on.
|
|
43
|
+
*
|
|
44
|
+
* @beta
|
|
45
|
+
*/
|
|
46
|
+
export interface ModalDefaults {
|
|
47
|
+
/** The initial protocol. Defaults to the first enabled one the default wallet speaks. */
|
|
48
|
+
protocol?: ProtocolId;
|
|
49
|
+
/** The initially selected wallet, by id. Defaults to the first listed wallet that speaks the initial protocol. */
|
|
50
|
+
wallet?: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Options for {@link headlessModal}.
|
|
54
|
+
*
|
|
55
|
+
* @beta
|
|
56
|
+
*/
|
|
57
|
+
export interface HeadlessModalOptions {
|
|
58
|
+
/**
|
|
59
|
+
* Wallets to list, in order, with the one selected on open moved first.
|
|
60
|
+
* Defaults to the curated wallets that speak an enabled protocol.
|
|
61
|
+
*/
|
|
62
|
+
wallets?: readonly WalletOption[];
|
|
63
|
+
/** Session type order. */
|
|
64
|
+
protocols?: readonly ProtocolId[];
|
|
65
|
+
/**
|
|
66
|
+
* What the modal opens on. An explicit protocol wins over a wallet that
|
|
67
|
+
* lacks it; a default that is not enabled or not listed falls back.
|
|
68
|
+
*/
|
|
69
|
+
defaults?: ModalDefaults;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The modal's connection logic as a `ConnectUi`, drawn by any renderer. Pass
|
|
73
|
+
* the result as the client's `ui`.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* import { createClient } from "@bchconnect/core";
|
|
78
|
+
* import { headlessModal } from "@bchconnect/ui/headless";
|
|
79
|
+
*
|
|
80
|
+
* const client = createClient({
|
|
81
|
+
* connectors,
|
|
82
|
+
* network: "mainnet",
|
|
83
|
+
* appMetadata,
|
|
84
|
+
* ui: headlessModal({
|
|
85
|
+
* open(view, actions) { myModal.show(view, actions); },
|
|
86
|
+
* update(view) { myModal.render(view); },
|
|
87
|
+
* close() { return myModal.hide(); },
|
|
88
|
+
* }),
|
|
89
|
+
* });
|
|
90
|
+
* await client.init();
|
|
91
|
+
* const session = await client.connect();
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* @beta
|
|
95
|
+
*/
|
|
96
|
+
export declare function headlessModal(renderer: ModalRenderer, options?: HeadlessModalOptions): ConnectUi;
|
|
97
|
+
//#endregion
|
|
98
|
+
export type { ConnectPhase, FailureReason, MarkShape, ModalScreen, ModalView, Network, ProtocolId, ProtocolMark, ProtocolOption, WalletDirectoryEntry, WalletOption };
|
|
99
|
+
//# sourceMappingURL=headless.d.ts.map
|