@bchconnect/ui 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +269 -2
  3. package/custom-elements.json +1771 -0
  4. package/dist/assets.generated.js +28 -0
  5. package/dist/assets.generated.js.map +1 -0
  6. package/dist/bchconnect-modal.d.ts +69 -0
  7. package/dist/bchconnect-modal.js +96 -0
  8. package/dist/bchconnect-modal.js.map +1 -0
  9. package/dist/code.js +130 -0
  10. package/dist/code.js.map +1 -0
  11. package/dist/defaults.d.ts +50 -0
  12. package/dist/defaults.js +139 -0
  13. package/dist/defaults.js.map +1 -0
  14. package/dist/define.d.ts +17 -0
  15. package/dist/define.js +23 -0
  16. package/dist/define.js.map +1 -0
  17. package/dist/directory.js +37 -0
  18. package/dist/directory.js.map +1 -0
  19. package/dist/faces.js +80 -0
  20. package/dist/faces.js.map +1 -0
  21. package/dist/gesture.js +78 -0
  22. package/dist/gesture.js.map +1 -0
  23. package/dist/headless.d.ts +99 -0
  24. package/dist/headless.js +190 -0
  25. package/dist/headless.js.map +1 -0
  26. package/dist/html.js +17 -0
  27. package/dist/html.js.map +1 -0
  28. package/dist/icons.js +21 -0
  29. package/dist/icons.js.map +1 -0
  30. package/dist/index.d.ts +32 -0
  31. package/dist/index.js +8 -0
  32. package/dist/locales/es.d.ts +12 -0
  33. package/dist/locales/es.js +50 -0
  34. package/dist/locales/es.js.map +1 -0
  35. package/dist/messages.d.ts +95 -0
  36. package/dist/messages.js +63 -0
  37. package/dist/messages.js.map +1 -0
  38. package/dist/modal.d.ts +112 -0
  39. package/dist/modal.js +694 -0
  40. package/dist/modal.js.map +1 -0
  41. package/dist/motion.js +160 -0
  42. package/dist/motion.js.map +1 -0
  43. package/dist/page-scroll.js +28 -0
  44. package/dist/page-scroll.js.map +1 -0
  45. package/dist/register.js +14 -0
  46. package/dist/register.js.map +1 -0
  47. package/dist/sheet-query.js +8 -0
  48. package/dist/sheet-query.js.map +1 -0
  49. package/dist/sheet.js +329 -0
  50. package/dist/sheet.js.map +1 -0
  51. package/dist/state.d.ts +175 -0
  52. package/dist/state.js +11 -0
  53. package/dist/state.js.map +1 -0
  54. package/dist/styles/modal.css.sheet.js +13 -0
  55. package/dist/styles/modal.css.sheet.js.map +1 -0
  56. package/dist/styles/theme.generated.css.sheet.js +13 -0
  57. package/dist/styles/theme.generated.css.sheet.js.map +1 -0
  58. package/dist/styles/toast.css.sheet.js +13 -0
  59. package/dist/styles/toast.css.sheet.js.map +1 -0
  60. package/dist/styles/tokens.css.sheet.js +13 -0
  61. package/dist/styles/tokens.css.sheet.js.map +1 -0
  62. package/dist/theme.generated.d.ts +105 -0
  63. package/dist/theme.generated.js +96 -0
  64. package/dist/theme.generated.js.map +1 -0
  65. package/dist/toast.d.ts +96 -0
  66. package/dist/toast.js +180 -0
  67. package/dist/toast.js.map +1 -0
  68. package/package.json +87 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modal.js","names":["theme","tokens","modal"],"sources":["../src/modal.ts"],"sourcesContent":["// Renders a ModalView and emits intents; holds no connection logic.\n// Close is requested here but performed by the caller on `bchc-close`.\n\nimport {\n\ttype CSSResultGroup,\n\thtml,\n\tLitElement,\n\tnothing,\n\ttype PropertyDeclarations,\n\ttype PropertyValues,\n\ttype TemplateResult,\n} from \"lit\";\nimport { classMap } from \"lit/directives/class-map.js\";\nimport { keyed } from \"lit/directives/keyed.js\";\nimport { live } from \"lit/directives/live.js\";\nimport { createRef, ref } from \"lit/directives/ref.js\";\nimport { repeat } from \"lit/directives/repeat.js\";\nimport { type CodeRenderer, renderCode } from \"./code.ts\";\nimport { directoryScreen } from \"./directory.ts\";\nimport {\n\ttype CaptionKind,\n\ttype CaptionWallet,\n\tcaption,\n\tcaptionKind,\n\tcopyFace,\n\ttype MessageTextKey,\n\tstatusFace,\n} from \"./faces.ts\";\nimport { safeHref } from \"./html.ts\";\nimport { icon } from \"./icons.ts\";\nimport { type BchcMessages, mergeMessages } from \"./messages.ts\";\nimport {\n\tanimationsFinished,\n\tcrossfade,\n\tenter,\n\tmorphHeight,\n\tnamedAnimationsFinished,\n\tretext,\n\tslideSheet,\n\ttempoOf,\n} from \"./motion.ts\";\nimport { lockPageScroll, unlockPageScroll } from \"./page-scroll.ts\";\nimport { type DraggableSheet, draggableSheet } from \"./sheet.ts\";\nimport { SHEET_QUERY } from \"./sheet-query.ts\";\nimport {\n\ttype FailureReason,\n\ttype ModalScreen,\n\ttype ModalView,\n\tNETWORK_LABEL,\n\ttype ProtocolId,\n\ttype ProtocolOption,\n\ttype WalletOption,\n} from \"./state.ts\";\nimport modal from \"./styles/modal.css\" with { type: \"css\" };\nimport theme from \"./styles/theme.generated.css\" with { type: \"css\" };\nimport tokens from \"./styles/tokens.css\" with { type: \"css\" };\n\n/**\n * Events representing what the modal asks the caller to do.\n *\n * @beta\n */\nexport interface BchcModalEvents {\n\t/**\n\t * Fired when the visitor selects a wallet, and before `bchc-protocol` when a\n\t * tab change pins the default wallet. When the selected wallet lacks the\n\t * current session type, `bchc-protocol` follows with the first one it speaks.\n\t */\n\t\"bchc-wallet\": CustomEvent<{ wallet: string }>;\n\t/** Fired when the visitor picks a different session type. */\n\t\"bchc-protocol\": CustomEvent<{ protocol: ProtocolId }>;\n\t/** Fired when the visitor moves between the connect and wallets screens. */\n\t\"bchc-screen\": CustomEvent<{ screen: ModalScreen }>;\n\t/** Fired once the exit has played. Remove the element on it. */\n\t\"bchc-close\": CustomEvent<void>;\n\t/** Fired when \"Try again\" is pressed after a failure. */\n\t\"bchc-retry\": CustomEvent<void>;\n}\n\n/** How long to wait after a deep link before assuming nothing opened (a failed handler gives no signal). */\nconst DEEP_LINK_GRACE = 1500;\nconst PLACEHOLDER_LINK =\n\t\"bchconnect://placeholder/kqzvxwtnmrhpbdgjsfcylakqzvxwtnmrhpbdgjsfcylakqzvxwtnmrhpbdgjsfcylakqzvxwtnmrhpbdgjsfcyla\";\nconst COPIED_FOR = 1800;\n/** `@keyframes` names. See `#close`. */\nconst EXIT_ANIMATIONS = new Set([\"lift\", \"sink\", \"sheet-out\", \"scrim-out\"]);\nconst NO_BROKEN_LOGOS: ReadonlySet<string> = new Set();\n\n// Shorter shaft and a heavier, rounder stroke than the icon set's arrow, to sit with bold text.\nconst OPEN_ARROW = html`<svg class=\"open-arrow\" width=\"13\" height=\"13\" viewBox=\"0 0 12 12\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\"><path d=\"M3.5 8.5 8.5 3.5\"/><path d=\"M4.75 3.5H8.5v3.75\"/></svg>`;\n\nconst TITLE_KEYS: Readonly<Record<ModalScreen, MessageTextKey>> = {\n\tconnect: \"connectTitle\",\n\twallets: \"getWalletTitle\",\n};\n\n/** The view's wallet, or the default: the first listed that speaks the protocol. */\nfunction selectedWallet(view: ModalView): WalletOption | undefined {\n\treturn (\n\t\tview.wallets.find((entry) => entry.id === view.wallet) ??\n\t\tview.wallets.find((entry) => entry.protocols.includes(view.protocol)) ??\n\t\tview.wallets[0]\n\t);\n}\n\n// The drawer lists no wallets, so it offers every session type. The current one\n// always stays, so the code is never left without the tab that names it.\nfunction offeredProtocols(\n\tview: ModalView,\n\tsheet: boolean,\n): readonly ProtocolOption[] {\n\tconst wallet = sheet ? undefined : selectedWallet(view);\n\tif (wallet === undefined) return view.protocols;\n\treturn view.protocols.filter(\n\t\t(entry) =>\n\t\t\tentry.id === view.protocol || wallet.protocols.includes(entry.id),\n\t);\n}\n\nfunction linkOf(view: ModalView): string | null {\n\treturn view.phase.kind === \"awaiting-approval\" ? view.phase.link : null;\n}\n\n// `{link}` takes the live connection link, so the wallet opens with it filled in.\n// \"\" until there is one: the action shows but can't be used.\nfunction desktopLink(wallet: WalletOption, view: ModalView): string | null {\n\tif (wallet.href === null) return null;\n\tif (!wallet.href.includes(\"{link}\")) return safeHref(wallet.href);\n\tif (view.phase.kind !== \"awaiting-approval\") return \"\";\n\tconst link = encodeURIComponent(view.phase.link);\n\treturn safeHref(wallet.href.replaceAll(\"{link}\", () => link));\n}\n\n// Injected by register.ts instead of importing code.ts directly, so\n// qr-code-styling stays out of modal.ts's own module graph.\nlet codeRenderer: CodeRenderer | null = null;\n\n/** Sets the renderer, once, before any modal is created. @internal */\nexport function useCodeRenderer(renderer: CodeRenderer): void {\n\tcodeRenderer = renderer;\n}\n\n/**\n * The `<bchc-modal>` web component\n *\n * @tag bchc-modal\n *\n * @attr {BchcAccent} data-bchc-accent - Curated accent color.\n * @attr {BchcNeutral} data-bchc-neutral - Neutral family override; each accent has a default pairing.\n * @attr {BchcRadius} data-bchc-radius - Corner radius preset applied to every rounded part.\n * @attr {BchcFont} data-bchc-font - Font stack; `brand` falls back to `system` until a face is injected.\n * @attr {BchcBlur} data-bchc-blur - Backdrop blur behind the modal.\n * @attr {BchcMode} data-bchc-mode - Color scheme; `auto` follows `prefers-color-scheme`.\n *\n * @fires {CustomEvent<{ wallet: string }>} bchc-wallet - Fired when the visitor selects a wallet, and before `bchc-protocol` when a tab change pins the default wallet; `bchc-protocol` follows when the selected wallet lacks the current session type.\n * @fires {CustomEvent<{ protocol: ProtocolId }>} bchc-protocol - Fired when the visitor picks a different session type.\n * @fires {CustomEvent<{ screen: ModalScreen }>} bchc-screen - Fired when the visitor moves between the connect and wallets screens.\n * @fires {CustomEvent<void>} bchc-close - Fired once the exit has played. Remove the element on it, or set `view` to `null` before showing it again.\n * @fires {CustomEvent<void>} bchc-retry - Fired when \"Try again\" is pressed after a failure.\n *\n * @cssprop --bchc-font-brand-family - Brand font family read when `data-bchc-font=\"brand\"`; falls back to the system stack until set.\n *\n * @example\n * ```ts\n * defineElements();\n * const modal = document.createElement(\"bchc-modal\") as BchcModal;\n * modal.view = view;\n * modal.addEventListener(\"bchc-wallet\", (event) => { ... });\n * modal.addEventListener(\"bchc-protocol\", (event) => { ... });\n * modal.addEventListener(\"bchc-close\", () => modal.remove());\n * document.body.append(modal);\n * ```\n *\n * @beta\n */\nexport class BchcModal extends LitElement {\n\t/** Lit's reactive property declarations. @internal */\n\tstatic override properties: PropertyDeclarations = {\n\t\tview: { attribute: false },\n\t\tmessages: { attribute: false },\n\t\t_appearance: { state: true },\n\t\t_bodyView: { state: true },\n\t\t_bodyKey: { state: true },\n\t\t_sheet: { state: true },\n\t\t_rtl: { state: true },\n\t\t_title: { state: true },\n\t\t_caption: { state: true },\n\t\t_captionWallet: { state: true },\n\t\t_status: { state: true },\n\t\t_copied: { state: true },\n\t\t_linkFailed: { state: true },\n\t\t_brokenLogos: { state: true },\n\t};\n\n\t/** Lit's adopted style sheets. @internal */\n\tstatic override styles: CSSResultGroup = [theme, tokens, modal];\n\n\t/** The state to render. Setting it re-renders the modal. */\n\tdeclare view: ModalView | null;\n\n\t/**\n\t * Overrides for the strings this element shows and announces.\n\t *\n\t * @defaultValue `null`\n\t */\n\tdeclare messages: Partial<BchcMessages> | null;\n\n\t// One per shown shell: a new key makes Lit build a fresh shell, which enters again.\n\tdeclare private _appearance: number | null;\n\t// The view the body shows; held back once connected, so the body stays still while the modal exits.\n\tdeclare private _bodyView: ModalView | null;\n\t// A new key rebuilds the body; any other change patches it in place.\n\tdeclare private _bodyKey: string | null;\n\tdeclare private _sheet: boolean;\n\t// `:dir()` doesn't reliably see directionality inherited from outside the\n\t// shadow tree; the `direction` property itself does, so CSS reads it from `.is-rtl`.\n\tdeclare private _rtl: boolean;\n\t// What the title, caption and status show; `retext` moves them to the view's values after a fade.\n\tdeclare private _title: string;\n\tdeclare private _caption: CaptionKind;\n\t// The wallet the scan caption names, by id; `null` names none.\n\tdeclare private _captionWallet: string | null;\n\tdeclare private _status: FailureReason | null;\n\tdeclare private _copied: boolean;\n\tdeclare private _linkFailed: boolean;\n\t// Logo URLs that failed to load this appearance; they render the generic tile instead.\n\tdeclare private _brokenLogos: ReadonlySet<string>;\n\n\t#copyResetTimer: ReturnType<typeof setTimeout> | null = null;\n\t#deepLinkTimer: ReturnType<typeof setTimeout> | null = null;\n\t#closing = false;\n\t#closed: Promise<void> | null = null;\n\t#entered = false;\n\t#appearances = 0;\n\t// Set in `willUpdate` when the next body rebuild crossfades; played around the commit in `update`.\n\t#crossfade: { readonly sheet: boolean } | null = null;\n\t// Counts wallet-only caption swaps; see `#retextBody`.\n\t#walletSwaps = 0;\n\t// Set only while this shell holds the page scroll lock, so unlocking twice is a no-op.\n\t#scrollLocked = false;\n\treadonly #overlay = createRef<HTMLDialogElement>();\n\treadonly #card = createRef<HTMLDivElement>();\n\treadonly #scrim = createRef<HTMLDivElement>();\n\treadonly #body = createRef<HTMLDivElement>();\n\t#drag: DraggableSheet | null = null;\n\treadonly #media: MediaQueryList = matchMedia(SHEET_QUERY);\n\t// Outlives every re-render, so the renderer updates the existing drawing instead of restarting it.\n\treadonly #codeHost: HTMLButtonElement = document.createElement(\"button\");\n\n\tget #messages(): BchcMessages {\n\t\treturn mergeMessages(this.messages);\n\t}\n\n\tconstructor() {\n\t\tsuper();\n\t\t// Assigned here, not as class fields, which would shadow the reactive accessors.\n\t\tthis.view = null;\n\t\tthis.messages = null;\n\t\tthis._appearance = null;\n\t\tthis._bodyView = null;\n\t\tthis._bodyKey = null;\n\t\tthis._sheet = false;\n\t\tthis._rtl = false;\n\t\tthis._title = \"\";\n\t\tthis._caption = \"none\";\n\t\tthis._captionWallet = null;\n\t\tthis._status = null;\n\t\tthis._copied = false;\n\t\tthis._linkFailed = false;\n\t\tthis._brokenLogos = NO_BROKEN_LOGOS;\n\t\tthis.#codeHost.className = \"code\";\n\t\tthis.#codeHost.type = \"button\";\n\t\tthis.#codeHost.setAttribute(\"data-act\", \"copy\");\n\t}\n\n\t/** Called by the browser when the element is attached. @internal */\n\toverride connectedCallback(): void {\n\t\tsuper.connectedCallback();\n\t\tthis.#media.addEventListener(\"change\", this.#onMediaChange);\n\t\tdocument.addEventListener(\"visibilitychange\", this.#onLeft);\n\t\tdocument.addEventListener(\"keydown\", this.#onKey);\n\t\taddEventListener(\"blur\", this.#onLeft);\n\t\t// Lit updates by itself only on the first attach; a re-attached modal must render again.\n\t\tthis.requestUpdate();\n\t}\n\n\t/** Called by the browser when the element is detached. @internal */\n\toverride disconnectedCallback(): void {\n\t\tsuper.disconnectedCallback();\n\t\tthis.#media.removeEventListener(\"change\", this.#onMediaChange);\n\t\tdocument.removeEventListener(\"visibilitychange\", this.#onLeft);\n\t\tdocument.removeEventListener(\"keydown\", this.#onKey);\n\t\tremoveEventListener(\"blur\", this.#onLeft);\n\t\t// A re-attached modal is a new appearance: it enters again.\n\t\tthis.#hide();\n\t\tthis.requestUpdate();\n\t}\n\n\t/**\n\t * Plays the exit, then emits `bchc-close`. A second call while the first\n\t * is still playing does nothing.\n\t */\n\tasync close(): Promise<void> {\n\t\t// A close right after setting `view` must still find the shell.\n\t\tif (this.isConnected) await this.updateComplete;\n\t\tawait this.#close(false);\n\t}\n\n\t// `dragged`: the sheet already left under its own release animation\n\t// (`settled` resolves once it ends); no CSS exit animation runs for it.\n\t// A close already playing is returned, so every caller waits for the same exit.\n\t#close(dragged: boolean, settled?: Promise<void>): Promise<void> {\n\t\tif (this.#closing) return this.#closed ?? Promise.resolve();\n\t\tconst overlay = this.#overlay.value;\n\t\tif (overlay === undefined) return Promise.resolve();\n\t\tthis.#closing = true;\n\t\tthis.#closed = this.#playClose(overlay, dragged, settled);\n\t\treturn this.#closed;\n\t}\n\n\tasync #playClose(\n\t\toverlay: HTMLDialogElement,\n\t\tdragged: boolean,\n\t\tsettled?: Promise<void>,\n\t): Promise<void> {\n\t\t// A programmatic close can land mid-drag or mid-settle: freeze it\n\t\t// inline first, so the CSS exit starts from exactly where it is.\n\t\tif (!dragged) this.#drag?.commit();\n\t\toverlay.classList.add(\"is-closing\");\n\t\tif (dragged) {\n\t\t\toverlay.classList.add(\"is-dragged\");\n\t\t\tawait settled;\n\t\t} else {\n\t\t\t// Waits only for the exit keyframes, not e.g. the code's write-in animation.\n\t\t\tawait namedAnimationsFinished(overlay, EXIT_ANIMATIONS);\n\t\t}\n\t\t// `close` is queued as a task; awaiting it keeps `close()` resolving after `bchc-close`.\n\t\t// A dialog the browser already closed fires no second one.\n\t\tif (!overlay.open) return;\n\t\tconst closed = new Promise((resolve) =>\n\t\t\toverlay.addEventListener(\"close\", resolve, { once: true }),\n\t\t);\n\t\toverlay.close();\n\t\tawait closed;\n\t}\n\n\t// A sheet/split switch changes markup, not just layout, so it must re-render.\n\treadonly #onMediaChange = (): void => {\n\t\tthis.requestUpdate();\n\t};\n\n\t// Plays the exit before the dialog closes. Shared by Escape and the dialog's own `cancel`.\n\treadonly #onKey = (event: KeyboardEvent): void => {\n\t\tif (event.key !== \"Escape\" || event.defaultPrevented) return;\n\t\t// Also keeps the dialog's close watcher from firing `cancel` for this same keypress\n\t\tevent.preventDefault();\n\t\tvoid this.close();\n\t};\n\n\t// Catches a close request with no keydown of its own, e.g. a mobile back gesture\n\treadonly #onCancel = (event: Event): void => {\n\t\tif (event.defaultPrevented || !event.cancelable) return;\n\t\tevent.preventDefault();\n\t\tvoid this.close();\n\t};\n\n\treadonly #onDialogClose = (event: Event): void => {\n\t\tif (event.currentTarget !== this.#overlay.value) return;\n\t\tthis.#closing = true;\n\t\tthis.#unlockScroll();\n\t\tthis.#emit(\"bchc-close\");\n\t};\n\n\t// Focus leaving means the deep link opened something; don't report it failed.\n\treadonly #onLeft = (): void => {\n\t\tif (this.#deepLinkTimer !== null) {\n\t\t\tclearTimeout(this.#deepLinkTimer);\n\t\t\tthis.#deepLinkTimer = null;\n\t\t}\n\t};\n\n\t#emit<K extends keyof BchcModalEvents>(\n\t\ttype: K,\n\t\tdetail?: BchcModalEvents[K][\"detail\"],\n\t): void {\n\t\tthis.dispatchEvent(\n\t\t\tnew CustomEvent(type, { detail, bubbles: true, composed: true }),\n\t\t);\n\t}\n\n\t#onOverlayClick(event: MouseEvent): void {\n\t\tconst target = event.target;\n\t\tif (target === event.currentTarget) {\n\t\t\tvoid this.close();\n\t\t\treturn;\n\t\t}\n\t\tif (!(target instanceof Element)) return;\n\t\tif (target.closest(\".close\") !== null) {\n\t\t\tvoid this.close();\n\t\t\treturn;\n\t\t}\n\t\tconst tab = target.closest(\".tab\");\n\t\tif (tab !== null) {\n\t\t\tthis.#selectProtocol(tab);\n\t\t\treturn;\n\t\t}\n\t\tconst row = target.closest(\"[data-wallet]\");\n\t\tif (row !== null) {\n\t\t\tthis.#selectWallet(row);\n\t\t\treturn;\n\t\t}\n\t\tconst actionTarget = target.closest(\"[data-act]\");\n\t\tconst action = actionTarget?.getAttribute(\"data-act\");\n\t\tif (action === \"retry\") this.#emit(\"bchc-retry\");\n\t\tif (action === \"copy\") void this.#copyLink();\n\t\tif (action === \"back\") this.#emit(\"bchc-screen\", { screen: \"connect\" });\n\t\tif (action === \"wallets\") this.#emit(\"bchc-screen\", { screen: \"wallets\" });\n\t\tif (\n\t\t\taction === \"open\" &&\n\t\t\tthis.view?.phase.kind === \"awaiting-approval\" &&\n\t\t\tactionTarget instanceof HTMLAnchorElement &&\n\t\t\tactionTarget.hasAttribute(\"href\")\n\t\t) {\n\t\t\tthis.#armDeepLinkHint();\n\t\t}\n\t}\n\n\t// Roving focus for the wallet radiogroup and the tablist. Manual activation for both:\n\t// arrows only move focus, since a selection can switch protocol and restart the attempt.\n\t#onOverlayKeydown(event: KeyboardEvent): void {\n\t\tconst target = event.target;\n\t\tif (!(target instanceof Element)) return;\n\t\tconst radio = target.closest(\"[data-wallet]\");\n\t\tconst tab = target.closest(\".tab\");\n\t\tconst item = radio ?? tab;\n\t\tconst group = item?.parentElement?.closest(\".wallets, .tabs\");\n\t\tif (item === null || group === null || group === undefined) return;\n\t\tif (event.key === \"Enter\" || event.key === \" \") {\n\t\t\tevent.preventDefault();\n\t\t\tif (tab !== null) this.#selectProtocol(tab);\n\t\t\telse this.#selectWallet(item);\n\t\t\treturn;\n\t\t}\n\t\tconst items = [\n\t\t\t...group.querySelectorAll<HTMLElement>(\n\t\t\t\tradio !== null ? \"[data-wallet]\" : \".tab\",\n\t\t\t),\n\t\t];\n\t\tconst at = items.indexOf(item as HTMLElement);\n\t\tconst forward = this._rtl ? \"ArrowLeft\" : \"ArrowRight\";\n\t\tconst back = this._rtl ? \"ArrowRight\" : \"ArrowLeft\";\n\t\tlet next: number;\n\t\tif (event.key === forward || (radio !== null && event.key === \"ArrowDown\"))\n\t\t\tnext = (at + 1) % items.length;\n\t\telse if (event.key === back || (radio !== null && event.key === \"ArrowUp\"))\n\t\t\tnext = (at - 1 + items.length) % items.length;\n\t\telse if (event.key === \"Home\") next = 0;\n\t\telse if (event.key === \"End\") next = items.length - 1;\n\t\telse return;\n\t\tevent.preventDefault();\n\t\tconst nextItem = items[next];\n\t\tif (nextItem === undefined) return;\n\t\tfor (const entry of items) entry.tabIndex = entry === nextItem ? 0 : -1;\n\t\tnextItem.focus({ preventScroll: true });\n\t}\n\n\t// Drops the shell; the next update removes it from the shadow root.\n\t#hide(): void {\n\t\t// Closing before the shell goes lets the browser return focus to the opener.\n\t\tthis.#overlay.value?.close();\n\t\tthis.#unlockScroll();\n\t\tthis.#drag?.release();\n\t\tthis.#drag = null;\n\t\tif (this.#copyResetTimer !== null) {\n\t\t\tclearTimeout(this.#copyResetTimer);\n\t\t\tthis.#copyResetTimer = null;\n\t\t}\n\t\tif (this.#deepLinkTimer !== null) {\n\t\t\tclearTimeout(this.#deepLinkTimer);\n\t\t\tthis.#deepLinkTimer = null;\n\t\t}\n\t\tthis._copied = false;\n\t\tthis.#closing = false;\n\t\tthis.#closed = null;\n\t\tthis.#entered = false;\n\t\tthis.#crossfade = null;\n\t\tthis._appearance = null;\n\t\tthis._bodyView = null;\n\t\tthis._bodyKey = null;\n\t\tthis._brokenLogos = NO_BROKEN_LOGOS;\n\t}\n\n\t#lockScroll(): void {\n\t\tif (this.#scrollLocked) return;\n\t\tthis.#scrollLocked = true;\n\t\tlockPageScroll();\n\t}\n\n\t#unlockScroll(): void {\n\t\tif (!this.#scrollLocked) return;\n\t\tthis.#scrollLocked = false;\n\t\tunlockPageScroll();\n\t}\n\n\t/** Lit hook run before each render; derives the shell and body state from `view`. @internal */\n\tprotected override willUpdate(changed: PropertyValues<this>): void {\n\t\t// Before the early returns: `messages` set while closed or detached must still reach the code host.\n\t\tthis.#codeHost.setAttribute(\"aria-label\", this.#messages.copyLinkLabel);\n\t\tconst view = this.view;\n\t\tif (view === null) {\n\t\t\tthis.#hide();\n\t\t\treturn;\n\t\t}\n\t\t// A shadow tree built while detached answers computed styles with the page's defaults in WebKit, even right after attaching. Attaching renders again instead.\n\t\tif (!this.isConnected) return;\n\t\tif (this._appearance === null) {\n\t\t\t// First paint already connected: no shell, `updated` closes directly.\n\t\t\tif (view.phase.kind === \"connected\") return;\n\t\t\tthis.#appearances += 1;\n\t\t\tthis._appearance = this.#appearances;\n\t\t\tthis._title = this.#messages[TITLE_KEYS[view.screen]];\n\t\t} else if (changed.has(\"messages\")) {\n\t\t\t// New wording for the screen still on display; `updated` then animates any screen change as usual.\n\t\t\tconst shown = changed.get(\"view\") ?? view;\n\t\t\tthis._title = this.#messages[TITLE_KEYS[shown.screen]];\n\t\t}\n\t\tconst previousSheet = this._sheet;\n\t\t// Bound rather than toggled after render, so the first style pass already sees them.\n\t\tthis._sheet = this.#media.matches;\n\t\tthis._rtl = getComputedStyle(this).direction === \"rtl\";\n\t\t// Success isn't a screen: the body keeps its last face while the modal exits.\n\t\tif (view.phase.kind !== \"connected\") this.#prepareBody(view, previousSheet);\n\t}\n\n\t// Runs while the old body is still in the DOM, so motion can measure it before the commit.\n\t#prepareBody(view: ModalView, previousSheet: boolean): void {\n\t\tconst previous = this._bodyView;\n\t\tconst previousKey = this._bodyKey;\n\t\tconst sheet = this._sheet;\n\t\t// Wallets don't follow the protocol, so a protocol switch or a selection\n\t\t// patches the body in place while the code rewrites.\n\t\tconst key = `${view.screen}:${sheet}`;\n\t\tthis._bodyView = view;\n\t\t// The hint is about the link it watched: another link, or none, drops it.\n\t\tif (linkOf(view) !== (previous === null ? null : linkOf(previous))) {\n\t\t\tthis._linkFailed = false;\n\t\t\tif (this.#deepLinkTimer !== null) {\n\t\t\t\tclearTimeout(this.#deepLinkTimer);\n\t\t\t\tthis.#deepLinkTimer = null;\n\t\t\t}\n\t\t}\n\t\tif (key === previousKey) return;\n\t\tthis._bodyKey = key;\n\t\tthis._linkFailed = false;\n\t\tthis._caption = captionKind(view, false);\n\t\tthis._captionWallet = this.#captionWalletOf(view);\n\t\tthis._status = view.phase.kind === \"failed\" ? view.phase.reason : null;\n\t\tthis.#crossfade = null;\n\n\t\t// The first body of a shell, or one rebuilt for a sheet/split switch, appears without motion.\n\t\tif (previous === null || previousKey === null || previousSheet !== sheet)\n\t\t\treturn;\n\t\tthis.#crossfade = { sheet };\n\t}\n\n\t/** Lit hook committing the template; a body rebuild is committed inside its motion. @internal */\n\tprotected override update(changed: PropertyValues<this>): void {\n\t\tconst motion = this.#crossfade;\n\t\tthis.#crossfade = null;\n\t\tconst card = this.#card.value;\n\t\tconst body = this.#body.value;\n\t\tif (motion === null || card === undefined || body === undefined) {\n\t\t\tsuper.update(changed);\n\t\t\treturn;\n\t\t}\n\t\tconst resize = motion.sheet ? slideSheet : morphHeight;\n\t\t// Direction 0: the card's width never changes, so nothing should slide sideways.\n\t\tresize(card, () => crossfade(body, () => super.update(changed), 0));\n\t}\n\n\t/** Lit hook producing the template. @internal */\n\tprotected override render(): unknown {\n\t\tconst view = this.view;\n\t\tif (this._appearance === null || view === null) return nothing;\n\t\tconst messages = this.#messages;\n\t\treturn keyed(\n\t\t\tthis._appearance,\n\t\t\thtml`<dialog\n\t\t\t\tclass=\"overlay ${classMap({ \"is-sheet\": this._sheet, \"is-rtl\": this._rtl })}\"\n\t\t\t\tlang=${messages.lang}\n\t\t\t\taria-labelledby=\"modal-title\"\n\t\t\t\t${ref(this.#overlay)}\n\t\t\t\t@click=${this.#onOverlayClick}\n\t\t\t\t@keydown=${this.#onOverlayKeydown}\n\t\t\t\t@cancel=${this.#onCancel}\n\t\t\t\t@close=${this.#onDialogClose}\n\t\t\t>\n\t\t\t\t<div class=\"scrim\" aria-hidden=\"true\" ${ref(this.#scrim)}></div>\n\t\t\t\t<div class=\"card\" tabindex=\"-1\" autofocus ${ref(this.#card)}>\n\t\t\t\t\t<div class=\"grabber\" aria-hidden=\"true\"></div>\n\t\t\t\t\t<div class=\"head\">\n\t\t\t\t\t\t<button class=\"back\" type=\"button\" data-act=\"back\" aria-label=${messages.back} .hidden=${view.screen !== \"wallets\"}>${icon(\"chevronLeft\")}</button>\n\t\t\t\t\t\t<h2 class=\"title\" id=\"modal-title\">${this._title}</h2>\n\t\t\t\t\t\t<span class=\"badge\" .hidden=${view.network === \"mainnet\" || view.screen === \"wallets\"}>${NETWORK_LABEL[view.network]}</span>\n\t\t\t\t\t\t<button class=\"close\" type=\"button\" aria-label=${messages.close}>${icon(\"x\")}</button>\n\t\t\t\t\t</div>\n\t\t\t\t\t<div class=\"body\" ${ref(this.#body)}>${this.#bodyTemplate()}</div>\n\t\t\t\t</div>\n\t\t\t</dialog>`,\n\t\t);\n\t}\n\n\t// `classMap` only touches the classes it names, so the overlay's `is-closing`/`is-entering` can be toggled directly.\n\t/** Lit hook run after each render. @internal */\n\tprotected override updated(): void {\n\t\tconst view = this.view;\n\t\tif (view === null || !this.isConnected) return;\n\t\tconst overlay = this.#overlay.value;\n\t\tconst card = this.#card.value;\n\t\tconst scrim = this.#scrim.value;\n\t\tconst body = this.#body.value;\n\t\tif (\n\t\t\toverlay === undefined ||\n\t\t\tcard === undefined ||\n\t\t\tscrim === undefined ||\n\t\t\tbody === undefined\n\t\t) {\n\t\t\t// No shell means the first paint was already connected (distinct\n\t\t\t// from the success-closes-modal case handled further down).\n\t\t\tif (view.phase.kind === \"connected\") this.#emit(\"bchc-close\");\n\t\t\treturn;\n\t\t}\n\n\t\t// The drag is created with each shell, so its absence marks the shell's first paint.\n\t\tif (this.#drag === null) {\n\t\t\toverlay.showModal();\n\t\t\tthis.#lockScroll();\n\t\t\tthis.#drag = draggableSheet(card, scrim, {\n\t\t\t\tisActive: () => this.#media.matches,\n\t\t\t\tonDismiss: (settled) => void this.#close(true, settled),\n\t\t\t});\n\t\t}\n\n\t\tconst sheet = this._sheet;\n\n\t\tconst title = overlay.querySelector(\".title\");\n\t\tconst titleText = this.#messages[TITLE_KEYS[view.screen]];\n\t\tif (title instanceof HTMLElement && titleText !== this._title) {\n\t\t\tretext(title, titleText, () => {\n\t\t\t\tthis._title = titleText;\n\t\t\t\treturn this.updateComplete;\n\t\t\t});\n\t\t}\n\n\t\t// Success isn't a screen: the modal exits and the caller takes over\n\t\t// (first-paint case handled above, before a shell exists).\n\t\tif (view.phase.kind === \"connected\") {\n\t\t\tvoid this.#close(false);\n\t\t\treturn;\n\t\t}\n\n\t\tif (view.screen === \"connect\") {\n\t\t\tthis.#retextBody(body, view);\n\t\t\tthis.#codeHost.disabled = view.phase.kind !== \"awaiting-approval\";\n\t\t\tthis.#paintCode(view);\n\t\t\tif (sheet) this.#measureSheetRest(card, body);\n\t\t}\n\n\t\tif (!this.#entered) {\n\t\t\tthis.#entered = true;\n\t\t\t// The drawer's contents ride with the sheet instead of staggering in.\n\t\t\tif (!sheet) {\n\t\t\t\tenter(\n\t\t\t\t\t// .tile excluded: its own write-in animation is its entrance.\n\t\t\t\t\toverlay.querySelectorAll(\n\t\t\t\t\t\t\".head, .split > :not(.cell-tile), .single > :not(.tile)\",\n\t\t\t\t\t),\n\t\t\t\t\ttempoOf(card),\n\t\t\t\t);\n\t\t\t\t// Entering content starts below its place, showing as scroll overflow until clipped.\n\t\t\t\toverlay.classList.add(\"is-entering\");\n\t\t\t\tvoid animationsFinished(overlay).then(() =>\n\t\t\t\t\toverlay.classList.remove(\"is-entering\"),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t// A swap from a body that was rebuilt meanwhile is dropped; the new body already shows the view.\n\t#retextBody(body: HTMLElement, view: ModalView): void {\n\t\tconst nextCaption = captionKind(view, this._linkFailed);\n\t\tconst nextWallet = this.#captionWalletOf(view);\n\t\tconst captionElement = body.querySelector(\".caption\");\n\t\t// Another wallet on the same scan caption: only its mark and name swap.\n\t\tconst walletElement = body.querySelector(\".caption-wallet\");\n\t\tif (\n\t\t\twalletElement instanceof HTMLElement &&\n\t\t\tnextCaption === \"scan\" &&\n\t\t\tthis._caption === \"scan\" &&\n\t\t\tnextWallet !== null &&\n\t\t\tnextWallet !== this._captionWallet\n\t\t) {\n\t\t\tretext(walletElement, nextWallet, () => {\n\t\t\t\tif (!walletElement.isConnected) return;\n\t\t\t\tthis._captionWallet = nextWallet;\n\t\t\t\treturn this.updateComplete;\n\t\t\t});\n\t\t\tthis.#walletSwaps += 1;\n\t\t} else if (\n\t\t\tcaptionElement instanceof HTMLElement &&\n\t\t\t(nextCaption !== this._caption ||\n\t\t\t\t(nextCaption === \"scan\" && nextWallet !== this._captionWallet))\n\t\t) {\n\t\t\t// The count keeps a whole-caption swap from matching a key it saw before a wallet-only swap.\n\t\t\tretext(\n\t\t\t\tcaptionElement,\n\t\t\t\t`${nextCaption}|${nextWallet}|${this.#walletSwaps}`,\n\t\t\t\t() => {\n\t\t\t\t\tif (!captionElement.isConnected) return;\n\t\t\t\t\tthis._caption = nextCaption;\n\t\t\t\t\tthis._captionWallet = nextWallet;\n\t\t\t\t\treturn this.updateComplete;\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\t\t// The failure face stays in place after a retry, so it is only ever swapped for another.\n\t\tconst reason = view.phase.kind === \"failed\" ? view.phase.reason : null;\n\t\tconst status = body.querySelector(\".status\");\n\t\tif (\n\t\t\tstatus instanceof HTMLElement &&\n\t\t\treason !== null &&\n\t\t\treason !== this._status\n\t\t) {\n\t\t\tretext(status, reason, () => {\n\t\t\t\tif (!status.isConnected) return;\n\t\t\t\tthis._status = reason;\n\t\t\t\treturn this.updateComplete;\n\t\t\t});\n\t\t}\n\t}\n\n\t#bodyTemplate(): unknown {\n\t\tconst view = this._bodyView;\n\t\tif (view === null) return nothing;\n\t\treturn keyed(\n\t\t\tthis._bodyKey,\n\t\t\tview.screen === \"wallets\"\n\t\t\t\t? directoryScreen(view.directory, this.#messages, (logo, size, extra) =>\n\t\t\t\t\t\tthis.#logo(logo, size, extra),\n\t\t\t\t\t)\n\t\t\t\t: this.#connectScreen(view, this._sheet),\n\t\t);\n\t}\n\n\t// One tab per offered session type; with one, nothing to choose, so an informational label.\n\t#sessionType(view: ModalView): TemplateResult {\n\t\tconst protocols = offeredProtocols(view, this._sheet);\n\t\tconst sessionType = this.#messages.sessionType;\n\t\tconst mark = (entry: ProtocolOption): unknown =>\n\t\t\tentry.mark === null\n\t\t\t\t? nothing\n\t\t\t\t: html`<img class=\"tab-mark\" src=${entry.mark.src} alt=\"\" width=\"16\" height=\"16\" />`;\n\t\tconst only = protocols.length === 1 ? protocols[0] : undefined;\n\t\tif (only !== undefined) {\n\t\t\treturn html`\n\t\t\t\t<div class=\"session is-info\">\n\t\t\t\t\t<span class=\"label\" id=\"session-type\">${sessionType}</span>\n\t\t\t\t\t<span class=\"session-value\" aria-labelledby=\"session-type\">${mark(only)}<span>${only.name}</span></span>\n\t\t\t\t</div>\n\t\t\t`;\n\t\t}\n\t\t// Past two, only the active tab spells its name (see the stylesheet).\n\t\treturn html`\n\t\t\t<div class=\"session is-tabs\">\n\t\t\t\t<span class=\"visually-hidden\" id=\"session-type\">${sessionType}</span>\n\t\t\t\t<div class=\"tabs ${classMap({ \"is-dense\": protocols.length > 2 })}\" role=\"tablist\" aria-labelledby=\"session-type\" style=\"--count:${protocols.length}\">\n\t\t\t\t\t${repeat(\n\t\t\t\t\t\tprotocols,\n\t\t\t\t\t\t(entry) => entry.id,\n\t\t\t\t\t\t(entry) => {\n\t\t\t\t\t\t\tconst active = entry.id === view.protocol;\n\t\t\t\t\t\t\treturn html`\n\t\t\t\t\t\t<button class=${classMap({ tab: true, \"no-mark\": entry.mark === null })} type=\"button\" role=\"tab\" id=\"tab-${entry.id}\" data-protocol=${entry.id} aria-selected=${String(active)} aria-controls=\"code-tile\" .tabIndex=${live(active ? 0 : -1)} title=${entry.name}>\n\t\t\t\t\t\t\t${mark(entry)}\n\t\t\t\t\t\t\t<span class=\"tab-name\"><span class=\"tab-name-inner\">${entry.name}</span></span>\n\t\t\t\t\t\t</button>`;\n\t\t\t\t\t\t},\n\t\t\t\t\t)}\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t`;\n\t}\n\n\t// The default wallet follows the protocol, so it is pinned first; the selection\n\t// changes only when the visitor picks a wallet.\n\t#selectProtocol(tab: Element): void {\n\t\tconst view = this.view;\n\t\tconst protocol = tab.getAttribute(\"data-protocol\");\n\t\tif (view === null || protocol === null || protocol === view.protocol)\n\t\t\treturn;\n\t\tconst pinned = view.wallets.some((entry) => entry.id === view.wallet);\n\t\tconst wallet = selectedWallet(view);\n\t\tif (!pinned && wallet !== undefined && !this._sheet)\n\t\t\tthis.#emit(\"bchc-wallet\", { wallet: wallet.id });\n\t\tthis.#emit(\"bchc-protocol\", { protocol: protocol as ProtocolId });\n\t}\n\n\t// Order is contract: the wallet first, then the protocol it falls back to.\n\t#selectWallet(row: Element): void {\n\t\tconst view = this.view;\n\t\tconst id = row.getAttribute(\"data-wallet\");\n\t\tif (view === null || id === null || id === selectedWallet(view)?.id) return;\n\t\tconst wallet = view.wallets.find((entry) => entry.id === id);\n\t\tif (wallet === undefined) return;\n\t\tthis.#emit(\"bchc-wallet\", { wallet: id });\n\t\tif (wallet.protocols.includes(view.protocol)) return;\n\t\tconst fallback = view.protocols.find((entry) =>\n\t\t\twallet.protocols.includes(entry.id),\n\t\t);\n\t\tif (fallback !== undefined)\n\t\t\tthis.#emit(\"bchc-protocol\", { protocol: fallback.id });\n\t}\n\n\t// The drawer lists no wallets, so its caption never names one.\n\t#captionWalletOf(view: ModalView): string | null {\n\t\treturn this._sheet ? null : (selectedWallet(view)?.id ?? null);\n\t}\n\n\t#walletPrompt(): TemplateResult {\n\t\treturn html`<p class=\"get-one\"><button type=\"button\" data-act=\"wallets\">${this.#messages.noWallet}</button></p>`;\n\t}\n\n\t// `null`, empty, whitespace-only or failed renders the generic wallet tile in place of an `<img>`.\n\t#logo(logo: string | null, size: number, extraClass: string): TemplateResult {\n\t\tconst trimmed = logo?.trim();\n\t\tif (\n\t\t\ttrimmed === undefined ||\n\t\t\ttrimmed === \"\" ||\n\t\t\tthis._brokenLogos.has(trimmed)\n\t\t) {\n\t\t\tconst className =\n\t\t\t\textraClass === \"\" ? \"logo-fallback\" : `logo-fallback ${extraClass}`;\n\t\t\treturn html`<span class=${className} aria-hidden=\"true\">${icon(\"wallet\")}</span>`;\n\t\t}\n\t\treturn html`<img class=${extraClass === \"\" ? nothing : extraClass} src=${trimmed} alt=\"\" width=${size} height=${size} @error=${this.#onLogoError} />`;\n\t}\n\n\t// Bound with `@error`: inline `onerror` is blocked by CSP.\n\t#onLogoError(event: Event): void {\n\t\tconst img = event.currentTarget;\n\t\tconst src =\n\t\t\timg instanceof HTMLImageElement ? img.getAttribute(\"src\") : null;\n\t\tif (src === null || this._brokenLogos.has(src)) return;\n\t\tthis._brokenLogos = new Set([...this._brokenLogos, src]);\n\t}\n\n\t// The component-owned code host goes where the slot was, so the drawing survives rebuilds.\n\t#tile(view: ModalView): TemplateResult {\n\t\tconst tabbed = offeredProtocols(view, this._sheet).length > 1;\n\t\treturn html`\n\t\t\t<div class=\"tile ${classMap({ \"is-initiating\": view.phase.kind === \"initiating\", \"is-failed\": view.phase.kind === \"failed\" })}\" id=\"code-tile\" role=${tabbed ? \"tabpanel\" : nothing} aria-labelledby=${tabbed ? `tab-${view.protocol}` : nothing}>\n\t\t\t\t<span class=\"probe\" aria-hidden=\"true\"></span>\n\t\t\t\t<span class=\"skeleton\" aria-hidden=\"true\"></span>\n\t\t\t\t${codeRenderer === null ? html`<div class=\"code\"></div>` : this.#codeHost}\n\t\t\t\t<div class=\"status\" role=\"status\">${statusFace(this.#messages, this._status)}</div>\n\t\t\t</div>\n\t\t`;\n\t}\n\n\t#footer(view: ModalView): TemplateResult {\n\t\tconst messages = this.#messages;\n\t\tconst named = view.wallets.find(\n\t\t\t(entry) => entry.id === this._captionWallet,\n\t\t);\n\t\tconst wallet: CaptionWallet | null =\n\t\t\tnamed === undefined\n\t\t\t\t? null\n\t\t\t\t: {\n\t\t\t\t\t\tname: named.name,\n\t\t\t\t\t\ttemplate: html`<span class=\"caption-wallet\">${this.#logo(named.logo, 16, \"caption-mark\")}<span class=\"caption-name\">${named.name}</span></span>`,\n\t\t\t\t\t};\n\t\treturn html`\n\t\t\t<div class=${classMap({ footer: true, \"is-void\": view.phase.kind === \"failed\" })}>\n\t\t\t\t<p class=\"caption\">${caption(messages, this._caption, wallet)}</p>\n\t\t\t\t<button class=\"button pill ${classMap({ \"is-copied\": this._copied })}\" type=\"button\" data-act=\"copy\" .disabled=${view.phase.kind !== \"awaiting-approval\"}>${copyFace(messages, this._copied)}</button>\n\t\t\t</div>\n\t\t`;\n\t}\n\n\t#connectScreen(view: ModalView, sheet: boolean): TemplateResult {\n\t\tconst failed = view.phase.kind === \"failed\";\n\t\tconst messages = this.#messages;\n\t\t// No href keeps the anchor inert and unfocusable, instead of navigating to `#`.\n\t\tconst link =\n\t\t\tview.phase.kind === \"awaiting-approval\"\n\t\t\t\t? safeHref(view.phase.link)\n\t\t\t\t: null;\n\n\t\tif (sheet) {\n\t\t\treturn html`\n\t\t\t\t<div class=\"single\">\n\t\t\t\t\t${this.#sessionType(view)}\n\t\t\t\t\t${this.#tile(view)}\n\t\t\t\t\t${this.#footer(view)}\n\t\t\t\t\t<div class=\"primary-slot ${classMap({ \"is-failed\": failed })}\">\n\t\t\t\t\t\t<a class=\"button primary block\" data-act=\"open\" href=${link ?? nothing} aria-disabled=${link === null ? \"true\" : nothing}>${messages.openInWallet}</a>\n\t\t\t\t\t\t<button class=\"button primary block retry\" type=\"button\" data-act=\"retry\">${icon(\"rotateCcw\", 15)}${messages.tryAgain}</button>\n\t\t\t\t\t</div>\n\t\t\t\t\t${this.#walletPrompt()}\n\t\t\t\t</div>\n\t\t\t`;\n\t\t}\n\n\t\tconst selectedId = selectedWallet(view)?.id;\n\t\t// `repeat` keeps each row's node with its wallet, so a loaded or failed logo stays with it.\n\t\treturn html`\n\t\t\t<div class=\"split\">\n\t\t\t\t<p class=\"cell-label section-label\" id=\"wallets-heading\">${messages.walletsHeading}</p>\n\t\t\t\t<div class=\"cell-control\">${this.#sessionType(view)}</div>\n\t\t\t\t<div class=\"cell-list\">\n\t\t\t\t\t<div class=\"wallets\" role=\"radiogroup\" aria-labelledby=\"wallets-heading\">\n\t\t\t\t\t\t${repeat(\n\t\t\t\t\t\t\tview.wallets,\n\t\t\t\t\t\t\t(wallet) => wallet.id,\n\t\t\t\t\t\t\t(wallet) => {\n\t\t\t\t\t\t\t\tconst selected = wallet.id === selectedId;\n\t\t\t\t\t\t\t\t// Rendered on every row with a desktop link and shown on the selected one,\n\t\t\t\t\t\t\t\t// so it leaves with the tint instead of vanishing. Hidden ones carry no live link.\n\t\t\t\t\t\t\t\tconst desktop = desktopLink(wallet, view);\n\t\t\t\t\t\t\t\tconst href = desktop === null ? null : selected ? desktop : \"\";\n\t\t\t\t\t\t\t\treturn html`\n\t\t\t\t\t\t\t<div class=\"wallet-row ${classMap({ \"has-open\": href !== null && selected })}\">\n\t\t\t\t\t\t\t\t<button class=\"wallet\" type=\"button\" role=\"radio\" aria-checked=${String(selected)} data-wallet=${wallet.id} .tabIndex=${live(selected ? 0 : -1)}>\n\t\t\t\t\t\t\t\t\t${this.#logo(wallet.logo, 32, \"\")}\n\t\t\t\t\t\t\t\t\t<span class=\"wallet-name\" title=${wallet.name}>${wallet.name}</span>\n\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t\t${\n\t\t\t\t\t\t\t\t\thref === null\n\t\t\t\t\t\t\t\t\t\t? nothing\n\t\t\t\t\t\t\t\t\t\t: html`<a class=\"open ${classMap({ \"is-shown\": selected })}\" tabindex=${selected ? nothing : -1} aria-hidden=${selected ? nothing : \"true\"} href=${href === \"\" ? nothing : href} role=${href === \"\" ? \"link\" : nothing} aria-disabled=${href === \"\" ? \"true\" : nothing} target=\"_blank\" rel=\"noreferrer\" aria-label=${messages.openWalletLabel(wallet.name)}><span class=\"open-text\">${messages.open}</span>${OPEN_ARROW}</a>`\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t</div>`;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t)}\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t\t<div class=\"cell-tile\">${this.#tile(view)}</div>\n\t\t\t\t<div class=\"cell-prompt\">${this.#walletPrompt()}</div>\n\t\t\t\t${this.#footer(view)}\n\t\t\t</div>\n\t\t`;\n\t}\n\n\t// The code and the button share this handler via data-act=\"copy\".\n\tasync #copyLink(): Promise<void> {\n\t\tconst view = this.view;\n\t\tif (view === null || view.phase.kind !== \"awaiting-approval\") return;\n\t\ttry {\n\t\t\tawait navigator.clipboard.writeText(view.phase.link);\n\t\t} catch {\n\t\t\t// No error state: the code is still on screen and scannable.\n\t\t\treturn;\n\t\t}\n\t\tthis.#setCopied(true);\n\t\tif (this.#copyResetTimer !== null) clearTimeout(this.#copyResetTimer);\n\t\tthis.#copyResetTimer = setTimeout(() => this.#setCopied(false), COPIED_FOR);\n\t}\n\n\t#setCopied(copied: boolean): void {\n\t\tthis._copied = copied;\n\t}\n\n\t// Only watches whether the deep link opened something; never blocks the navigation.\n\t#armDeepLinkHint(): void {\n\t\tif (this._linkFailed) return;\n\t\tif (this.#deepLinkTimer !== null) clearTimeout(this.#deepLinkTimer);\n\t\tthis.#deepLinkTimer = setTimeout(() => {\n\t\t\tthis.#deepLinkTimer = null;\n\t\t\tif (document.visibilityState !== \"visible\") return;\n\t\t\t// `updated` fades the caption over to the hint.\n\t\t\tthis._linkFailed = true;\n\t\t}, DEEP_LINK_GRACE);\n\t}\n\n\t// Everything in the sheet but the tile, which sizes itself from what is left of the viewport.\n\t#measureSheetRest(card: HTMLElement, body: HTMLElement): void {\n\t\tconst tile = body.querySelector(\".tile\");\n\t\tif (!(tile instanceof HTMLElement)) return;\n\t\t// Rounded up: a fraction short would leave the body scrollable by that fraction.\n\t\tconst rest = Math.ceil(\n\t\t\tcard.offsetHeight -\n\t\t\t\tbody.clientHeight +\n\t\t\t\t(body.scrollHeight - tile.offsetHeight),\n\t\t);\n\t\tcard.style.setProperty(\"--bchc-sheet-rest\", `${rest}px`);\n\t}\n\n\t#paintCode(view: ModalView): void {\n\t\tconst renderer = codeRenderer;\n\t\tif (renderer === null) return;\n\n\t\tconst initiating = view.phase.kind === \"initiating\";\n\t\tif (view.phase.kind !== \"awaiting-approval\" && !initiating) return;\n\n\t\t// Colours come from the probe, not the tile, whose colours transition on failure/retry.\n\t\tconst probe = this.#codeHost.parentElement?.querySelector(\".probe\");\n\t\tif (!(probe instanceof HTMLElement)) return;\n\t\tconst tileStyles = getComputedStyle(probe);\n\n\t\tconst protocol = view.protocols.find((entry) => entry.id === view.protocol);\n\t\tvoid renderCode(renderer, this.#codeHost, {\n\t\t\tlink:\n\t\t\t\tview.phase.kind === \"awaiting-approval\"\n\t\t\t\t\t? view.phase.link\n\t\t\t\t\t: PLACEHOLDER_LINK,\n\t\t\t// Placeholder carries the real mark too, so nothing shifts when the link arrives.\n\t\t\tmark: protocol?.mark ?? null,\n\t\t\tforeground: tileStyles.color,\n\t\t\tbackground: tileStyles.backgroundColor,\n\t\t\taccent: tileStyles.accentColor,\n\t\t\tplaceholder: initiating,\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAgFA,MAAM,kBAAkB;AACxB,MAAM,mBACL;AACD,MAAM,aAAa;;AAEnB,MAAM,kCAAkB,IAAI,IAAI;CAAC;CAAQ;CAAQ;CAAa;AAAW,CAAC;AAC1E,MAAM,kCAAuC,IAAI,IAAI;AAGrD,MAAM,aAAa,IAAI;AAEvB,MAAM,aAA4D;CACjE,SAAS;CACT,SAAS;AACV;;AAGA,SAAS,eAAe,MAA2C;CAClE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@@
1
+
2
+ //#region src/motion.ts
3
+ function milliseconds(value, fallback) {
4
+ const trimmed = value.trim();
5
+ if (trimmed.endsWith("ms")) return Number.parseFloat(trimmed);
6
+ if (trimmed.endsWith("s")) return Number.parseFloat(trimmed) * 1e3;
7
+ return fallback;
8
+ }
9
+ function tempoOf(element) {
10
+ const styles = getComputedStyle(element);
11
+ const read = (name) => styles.getPropertyValue(name);
12
+ const base = milliseconds(read("--bchc-duration-base"), 320);
13
+ const slow = milliseconds(read("--bchc-duration-slow"), 560);
14
+ return {
15
+ fast: milliseconds(read("--bchc-duration-fast"), 160),
16
+ base,
17
+ slow,
18
+ out: read("--bchc-ease-out").trim() || "ease-out",
19
+ settle: read("--bchc-ease-settle").trim() || "ease-out",
20
+ spring: read("--bchc-ease-spring").trim() || "ease-out",
21
+ enter: read("--bchc-ease-enter").trim() || "ease-out",
22
+ sheet: read("--bchc-ease-sheet").trim() || "ease-out",
23
+ sheetIn: slow * .9,
24
+ sheetOut: base * 1.1
25
+ };
26
+ }
27
+ /** Wait for every animation under `root` to finish, however it finishes (a cancelled one rejects its `finished` promise). */
28
+ async function animationsFinished(root) {
29
+ root.offsetHeight;
30
+ const finite = root.getAnimations({ subtree: true }).filter((animation) => animation.effect?.getTiming().iterations !== Infinity);
31
+ await Promise.allSettled(finite.map((animation) => animation.finished));
32
+ }
33
+ async function namedAnimationsFinished(root, names) {
34
+ root.offsetHeight;
35
+ const matching = root.getAnimations({ subtree: true }).filter((animation) => "animationName" in animation && names.has(animation.animationName));
36
+ await Promise.allSettled(matching.map((animation) => animation.finished));
37
+ }
38
+ function enter(elements, tempo) {
39
+ let index = 0;
40
+ for (const element of elements) {
41
+ const heavy = element.classList.contains("footer");
42
+ element.animate([
43
+ {
44
+ opacity: 0,
45
+ transform: `translateY(${heavy ? 22 : 12}px)`
46
+ },
47
+ {
48
+ opacity: 1,
49
+ offset: .3
50
+ },
51
+ {
52
+ opacity: 1,
53
+ transform: "none"
54
+ }
55
+ ], {
56
+ duration: tempo.base,
57
+ easing: tempo.out,
58
+ delay: tempo.fast / 5 + Math.min(index, 8) * 12,
59
+ fill: "backwards"
60
+ });
61
+ index += 1;
62
+ }
63
+ }
64
+ function morphHeight(element, mutate) {
65
+ const before = element.getBoundingClientRect().height;
66
+ mutate();
67
+ const after = element.getBoundingClientRect().height;
68
+ if (Math.abs(after - before) < 1) return;
69
+ const tempo = tempoOf(element);
70
+ element.style.overflow = "clip";
71
+ element.animate([{ height: `${before}px` }, { height: `${after}px` }], {
72
+ duration: tempo.base,
73
+ easing: tempo.settle
74
+ }).finished.catch(() => void 0).finally(() => {
75
+ element.style.overflow = "";
76
+ });
77
+ }
78
+ function slideSheet(card, mutate) {
79
+ const before = card.getBoundingClientRect().height;
80
+ mutate();
81
+ const delta = card.getBoundingClientRect().height - before;
82
+ if (Math.abs(delta) < 1) return;
83
+ const tempo = tempoOf(card);
84
+ if (delta < 0) card.style.setProperty("--bchc-sheet-travel", `${-delta}px`);
85
+ card.animate([{ transform: `translate3d(0, ${delta}px, 0)` }, { transform: "none" }], {
86
+ duration: delta > 0 ? tempo.sheetIn : tempo.sheetOut,
87
+ easing: tempo.sheet
88
+ }).finished.catch(() => void 0).finally(() => card.style.removeProperty("--bchc-sheet-travel"));
89
+ }
90
+ function crossfade(host, mutate, direction) {
91
+ const tempo = tempoOf(host);
92
+ const outgoing = host.cloneNode(true);
93
+ outgoing.classList.add("outgoing");
94
+ outgoing.setAttribute("aria-hidden", "true");
95
+ outgoing.inert = true;
96
+ outgoing.style.top = `${host.offsetTop}px`;
97
+ outgoing.style.left = `${host.offsetLeft}px`;
98
+ outgoing.style.width = `${host.offsetWidth}px`;
99
+ mutate();
100
+ host.parentElement?.insertBefore(outgoing, host);
101
+ const sign = getComputedStyle(host).direction === "rtl" ? -1 : 1;
102
+ const away = direction === 0 ? "translateY(-6px)" : `translateX(${-14 * direction * sign}px)`;
103
+ const from = direction === 0 ? "translateY(8px)" : `translateX(${14 * direction * sign}px)`;
104
+ outgoing.animate([{
105
+ opacity: 1,
106
+ transform: "none"
107
+ }, {
108
+ opacity: 0,
109
+ transform: away
110
+ }], {
111
+ duration: tempo.fast,
112
+ easing: tempo.out,
113
+ fill: "forwards"
114
+ }).finished.catch(() => void 0).finally(() => outgoing.remove());
115
+ host.animate([{
116
+ opacity: 0,
117
+ transform: from
118
+ }, {
119
+ opacity: 1,
120
+ transform: "none"
121
+ }], {
122
+ duration: tempo.base,
123
+ easing: tempo.out,
124
+ delay: tempo.fast / 2,
125
+ fill: "backwards"
126
+ });
127
+ }
128
+ const lastRetext = /* @__PURE__ */ new WeakMap();
129
+ /**
130
+ * Fade an element's content out, let `swap` replace it, then fade it back in,
131
+ * so a label never just flips. `key` names the new content; `swap` may return
132
+ * a promise that settles once the new content is in place.
133
+ */
134
+ function retext(element, key, swap) {
135
+ if (lastRetext.get(element) === key) return;
136
+ lastRetext.set(element, key);
137
+ const tempo = tempoOf(element);
138
+ const fade = element.animate([{ opacity: 1 }, { opacity: 0 }], {
139
+ duration: tempo.fast / 2,
140
+ easing: "linear",
141
+ fill: "forwards"
142
+ });
143
+ fade.finished.catch(() => void 0).then(swap).finally(() => {
144
+ fade.cancel();
145
+ element.animate([{
146
+ opacity: 0,
147
+ transform: "translateY(3px)"
148
+ }, {
149
+ opacity: 1,
150
+ transform: "none"
151
+ }], {
152
+ duration: tempo.base,
153
+ easing: tempo.out
154
+ });
155
+ });
156
+ }
157
+ //#endregion
158
+ export { animationsFinished, crossfade, enter, morphHeight, namedAnimationsFinished, retext, slideSheet, tempoOf };
159
+
160
+ //# sourceMappingURL=motion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"motion.js","names":[],"sources":["../src/motion.ts"],"sourcesContent":["// Web Animations API for motion CSS can't express: transitions from where\n// something was, measured before/after a mutation. CSS owns the rest, and\n// tempoOf() reads durations/curves so tokens.css stays the single tuning spot.\n\n/** Motion tokens as the stylesheet resolved them for this element. */\nexport interface Tempo {\n\treadonly fast: number;\n\treadonly base: number;\n\treadonly slow: number;\n\treadonly out: string;\n\treadonly settle: string;\n\treadonly spring: string;\n\treadonly enter: string;\n\treadonly sheet: string;\n\t// The drawer's entrance and exit, as its keyframes in modal.css time them.\n\treadonly sheetIn: number;\n\treadonly sheetOut: number;\n}\n\nfunction milliseconds(value: string, fallback: number): number {\n\tconst trimmed = value.trim();\n\tif (trimmed.endsWith(\"ms\")) return Number.parseFloat(trimmed);\n\tif (trimmed.endsWith(\"s\")) return Number.parseFloat(trimmed) * 1000;\n\treturn fallback;\n}\n\nexport function tempoOf(element: Element): Tempo {\n\tconst styles = getComputedStyle(element);\n\tconst read = (name: string) => styles.getPropertyValue(name);\n\tconst base = milliseconds(read(\"--bchc-duration-base\"), 320);\n\tconst slow = milliseconds(read(\"--bchc-duration-slow\"), 560);\n\treturn {\n\t\tfast: milliseconds(read(\"--bchc-duration-fast\"), 160),\n\t\tbase,\n\t\tslow,\n\t\tout: read(\"--bchc-ease-out\").trim() || \"ease-out\",\n\t\tsettle: read(\"--bchc-ease-settle\").trim() || \"ease-out\",\n\t\tspring: read(\"--bchc-ease-spring\").trim() || \"ease-out\",\n\t\tenter: read(\"--bchc-ease-enter\").trim() || \"ease-out\",\n\t\tsheet: read(\"--bchc-ease-sheet\").trim() || \"ease-out\",\n\t\tsheetIn: slow * 0.9,\n\t\tsheetOut: base * 1.1,\n\t};\n}\n\n/** Wait for every animation under `root` to finish, however it finishes (a cancelled one rejects its `finished` promise). */\nexport async function animationsFinished(root: Element): Promise<void> {\n\t// Forces the next style pass, so a class toggled this tick has already produced its animations below.\n\tvoid (root as HTMLElement).offsetHeight;\n\tconst finite = root\n\t\t.getAnimations({ subtree: true })\n\t\t// A loop (a pulse, a sweep) never finishes.\n\t\t.filter(\n\t\t\t(animation) => animation.effect?.getTiming().iterations !== Infinity,\n\t\t);\n\tawait Promise.allSettled(finite.map((animation) => animation.finished));\n}\n\n// Waits only for CSS animations named in `names`; script-driven animations\n// carry no `animationName` and are never waited on.\nexport async function namedAnimationsFinished(\n\troot: Element,\n\tnames: ReadonlySet<string>,\n): Promise<void> {\n\tvoid (root as HTMLElement).offsetHeight;\n\tconst matching = root\n\t\t.getAnimations({ subtree: true })\n\t\t.filter(\n\t\t\t(animation): animation is CSSAnimation =>\n\t\t\t\t\"animationName\" in animation &&\n\t\t\t\tnames.has((animation as CSSAnimation).animationName),\n\t\t);\n\tawait Promise.allSettled(matching.map((animation) => animation.finished));\n}\n\n// Script-driven, not a stylesheet rule, so a body rebuilt mid-entrance\n// doesn't replay it on new rows; runs only on elements present at first paint.\nexport function enter(elements: Iterable<Element>, tempo: Tempo): void {\n\tlet index = 0;\n\tfor (const element of elements) {\n\t\tconst heavy = element.classList.contains(\"footer\");\n\t\telement.animate(\n\t\t\t[\n\t\t\t\t{ opacity: 0, transform: `translateY(${heavy ? 22 : 12}px)` },\n\t\t\t\t{ opacity: 1, offset: 0.3 },\n\t\t\t\t{ opacity: 1, transform: \"none\" },\n\t\t\t],\n\t\t\t{\n\t\t\t\tduration: tempo.base,\n\t\t\t\teasing: tempo.out,\n\t\t\t\tdelay: tempo.fast / 5 + Math.min(index, 8) * 12,\n\t\t\t\tfill: \"backwards\",\n\t\t\t},\n\t\t);\n\t\tindex += 1;\n\t}\n}\n\n// Animating `height` is normally avoided, but this runs once, briefly, on\n// one element; `overflow: clip` keeps incoming content from spilling out.\nexport function morphHeight(element: HTMLElement, mutate: () => void): void {\n\tconst before = element.getBoundingClientRect().height;\n\tmutate();\n\tconst after = element.getBoundingClientRect().height;\n\tif (Math.abs(after - before) < 1) return;\n\n\tconst tempo = tempoOf(element);\n\telement.style.overflow = \"clip\";\n\tconst animation = element.animate(\n\t\t[{ height: `${before}px` }, { height: `${after}px` }],\n\t\t{ duration: tempo.base, easing: tempo.settle },\n\t);\n\tanimation.finished\n\t\t.catch(() => undefined)\n\t\t.finally(() => {\n\t\t\telement.style.overflow = \"\";\n\t\t});\n}\n\n// The drawer is anchored to the bottom of the viewport, so a height change moves its top\n// edge. The new layout applies at once and the card travels from where that edge was.\nexport function slideSheet(card: HTMLElement, mutate: () => void): void {\n\tconst before = card.getBoundingClientRect().height;\n\tmutate();\n\tconst delta = card.getBoundingClientRect().height - before;\n\tif (Math.abs(delta) < 1) return;\n\n\tconst tempo = tempoOf(card);\n\t// A shorter sheet starts raised, which would show the page under its bottom edge.\n\tif (delta < 0) card.style.setProperty(\"--bchc-sheet-travel\", `${-delta}px`);\n\tcard\n\t\t.animate(\n\t\t\t[{ transform: `translate3d(0, ${delta}px, 0)` }, { transform: \"none\" }],\n\t\t\t{\n\t\t\t\tduration: delta > 0 ? tempo.sheetIn : tempo.sheetOut,\n\t\t\t\teasing: tempo.sheet,\n\t\t\t},\n\t\t)\n\t\t.finished.catch(() => undefined)\n\t\t.finally(() => card.style.removeProperty(\"--bchc-sheet-travel\"));\n}\n\n// `direction`: forward into a sub-screen, back out of one, or 0 for a\n// same-screen change, which rises instead of sliding sideways.\nexport function crossfade(\n\thost: HTMLElement,\n\tmutate: () => void,\n\tdirection: -1 | 0 | 1,\n): void {\n\tconst tempo = tempoOf(host);\n\tconst outgoing = host.cloneNode(true) as HTMLElement;\n\toutgoing.classList.add(\"outgoing\");\n\toutgoing.setAttribute(\"aria-hidden\", \"true\");\n\toutgoing.inert = true;\n\t// `.outgoing` is absolute via CSS; only geometry is set here so it stays pinned.\n\toutgoing.style.top = `${host.offsetTop}px`;\n\toutgoing.style.left = `${host.offsetLeft}px`;\n\toutgoing.style.width = `${host.offsetWidth}px`;\n\n\tmutate();\n\n\thost.parentElement?.insertBefore(outgoing, host);\n\t// Forward/back is relative to reading order, so it flips with direction.\n\tconst sign = getComputedStyle(host).direction === \"rtl\" ? -1 : 1;\n\tconst away =\n\t\tdirection === 0\n\t\t\t? \"translateY(-6px)\"\n\t\t\t: `translateX(${-14 * direction * sign}px)`;\n\tconst from =\n\t\tdirection === 0\n\t\t\t? \"translateY(8px)\"\n\t\t\t: `translateX(${14 * direction * sign}px)`;\n\n\toutgoing\n\t\t.animate(\n\t\t\t[\n\t\t\t\t{ opacity: 1, transform: \"none\" },\n\t\t\t\t{ opacity: 0, transform: away },\n\t\t\t],\n\t\t\t{ duration: tempo.fast, easing: tempo.out, fill: \"forwards\" },\n\t\t)\n\t\t.finished.catch(() => undefined)\n\t\t.finally(() => outgoing.remove());\n\n\thost.animate(\n\t\t[\n\t\t\t{ opacity: 0, transform: from },\n\t\t\t{ opacity: 1, transform: \"none\" },\n\t\t],\n\t\t{\n\t\t\tduration: tempo.base,\n\t\t\teasing: tempo.out,\n\t\t\tdelay: tempo.fast / 2,\n\t\t\tfill: \"backwards\",\n\t\t},\n\t);\n}\n\n// Keyed by element: the same key while a swap is under way, or after it, is not swapped again.\nconst lastRetext = new WeakMap<Element, string>();\n\n/**\n * Fade an element's content out, let `swap` replace it, then fade it back in,\n * so a label never just flips. `key` names the new content; `swap` may return\n * a promise that settles once the new content is in place.\n */\nexport function retext(\n\telement: HTMLElement,\n\tkey: string,\n\tswap: () => unknown,\n): void {\n\tif (lastRetext.get(element) === key) return;\n\tlastRetext.set(element, key);\n\tconst tempo = tempoOf(element);\n\tconst fade = element.animate([{ opacity: 1 }, { opacity: 0 }], {\n\t\tduration: tempo.fast / 2,\n\t\teasing: \"linear\",\n\t\tfill: \"forwards\",\n\t});\n\tfade.finished\n\t\t.catch(() => undefined)\n\t\t.then(swap)\n\t\t.finally(() => {\n\t\t\tfade.cancel();\n\t\t\telement.animate(\n\t\t\t\t[\n\t\t\t\t\t{ opacity: 0, transform: \"translateY(3px)\" },\n\t\t\t\t\t{ opacity: 1, transform: \"none\" },\n\t\t\t\t],\n\t\t\t\t{ duration: tempo.base, easing: tempo.out },\n\t\t\t);\n\t\t});\n}\n"],"mappings":";;AAmBA,SAAS,aAAa,OAAe,UAA0B;CAC9D,MAAM,UAAU,MAAM,KAAK;CAC3B,IAAI,QAAQ,SAAS,IAAI,GAAG,OAAO,OAAO,WAAW,OAAO;CAC5D,IAAI,QAAQ,SAAS,GAAG,GAAG,OAAO,O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AM,QAAQ,QAAQ,OAAO;CAC7B,MAAM,OAAO,QAAQ,QAAQ,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,GAAG;EAC9D,UAAU,MAAM,OAAO;EACvB,QAAQ;EACR,MAAM;CACP,CAAC;CACD,KAAK,SACH,YAAY,KAAA,CAAS,CAAC,CACtB,KAAK,IAAI,CAAC,CACV,cAAc;EACd,KAAK,OAAO;EACZ,QAAQ,QACP,CACC;GAAE,SAAS;GAAG,WAAW;EAAkB,GAC3C;GAAE,SAAS;GAAG,WAAW;EAAO,CACjC,GACA;GAAE,UAAU,MAAM;GAAM,QAAQ,MAAM;EAAI,CAC3C;CACD,CAAC;AACH"}
@@ -0,0 +1,28 @@
1
+
2
+ //#region src/page-scroll.ts
3
+ let pageScrollLocks = 0;
4
+ let savedOverflow = "";
5
+ let savedScrollbarGutter = "";
6
+ /** Stops the page behind the modal from scrolling. @internal */
7
+ function lockPageScroll() {
8
+ pageScrollLocks += 1;
9
+ if (pageScrollLocks > 1) return;
10
+ const root = document.documentElement;
11
+ savedOverflow = root.style.overflow;
12
+ savedScrollbarGutter = root.style.scrollbarGutter;
13
+ const hasScrollbar = innerWidth - root.clientWidth > 0;
14
+ root.style.overflow = "hidden";
15
+ if (hasScrollbar) root.style.scrollbarGutter = "stable";
16
+ }
17
+ /** Releases one {@link lockPageScroll}. @internal */
18
+ function unlockPageScroll() {
19
+ pageScrollLocks -= 1;
20
+ if (pageScrollLocks > 0) return;
21
+ const root = document.documentElement;
22
+ root.style.overflow = savedOverflow;
23
+ root.style.scrollbarGutter = savedScrollbarGutter;
24
+ }
25
+ //#endregion
26
+ export { lockPageScroll, unlockPageScroll };
27
+
28
+ //# sourceMappingURL=page-scroll.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-scroll.js","names":[],"sources":["../src/page-scroll.ts"],"sourcesContent":["// Shared by every modal, so overlapping ones can't restore each other's lock: the first lock\n// saves the page's own inline values and the last unlock restores them.\nlet pageScrollLocks = 0;\nlet savedOverflow = \"\";\nlet savedScrollbarGutter = \"\";\n\n/** Stops the page behind the modal from scrolling. @internal */\nexport function lockPageScroll(): void {\n\tpageScrollLocks += 1;\n\tif (pageScrollLocks > 1) return;\n\tconst root = document.documentElement;\n\tsavedOverflow = root.style.overflow;\n\tsavedScrollbarGutter = root.style.scrollbarGutter;\n\t// Measured before hiding overflow, which would itself remove the scrollbar.\n\tconst hasScrollbar = innerWidth - root.clientWidth > 0;\n\troot.style.overflow = \"hidden\";\n\tif (hasScrollbar) root.style.scrollbarGutter = \"stable\";\n}\n\n/** Releases one {@link lockPageScroll}. @internal */\nexport function unlockPageScroll(): void {\n\tpageScrollLocks -= 1;\n\tif (pageScrollLocks > 0) return;\n\tconst root = document.documentElement;\n\troot.style.overflow = savedOverflow;\n\troot.style.scrollbarGutter = savedScrollbarGutter;\n}\n"],"mappings":";;AAEA,IAAI,kBAAkB;AACtB,IAAI,gBAAgB;AACpB,IAAI,uBAAuB;;AAG3B,SAAgB,iBAAuB;CACtC,mBAAmB;CACnB,IAAI,kBAAkB,GAAG;CACzB,MAAM,OAAO,SAAS;CACtB,gBAAgB,KAAK,MAAM;CAC3B,uBAAuB,KAAK,MAAM;CAElC,MAAM,eAAe,aAAa,KAAK,cAAc;CACrD,KAAK,MAAM,WAAW;CACtB,IAAI,cAAc,KAAK,MAAM,kBAAkB;AAChD;;AAGA,SAAgB,mBAAyB;CACxC,mBAAmB;CACnB,IAAI,kBAAkB,GAAG;CACzB,MAAM,OAAO,SAAS;CACtB,KAAK,MAAM,WAAW;CACtB,KAAK,MAAM,kBAAkB;AAC9B"}
@@ -0,0 +1,14 @@
1
+
2
+ import { BchcModal, useCodeRenderer } from "./modal.js";
3
+ import { BchcToast } from "./toast.js";
4
+ //#region src/register.ts
5
+ /** Wires `renderer` in and defines both elements, idempotently. @internal */
6
+ function register(renderer) {
7
+ useCodeRenderer(renderer);
8
+ if (customElements.get("bchc-modal") === void 0) customElements.define("bchc-modal", BchcModal);
9
+ if (customElements.get("bchc-toast") === void 0) customElements.define("bchc-toast", BchcToast);
10
+ }
11
+ //#endregion
12
+ export { register };
13
+
14
+ //# sourceMappingURL=register.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"register.js","names":[],"sources":["../src/register.ts"],"sourcesContent":["// modal.ts draws through a renderer supplied here, never importing\n// qr-code-styling itself, so its specifier never reaches modal.ts.\n\nimport type { CodeRenderer } from \"./code.ts\";\nimport { BchcModal, useCodeRenderer } from \"./modal.ts\";\nimport { BchcToast } from \"./toast.ts\";\n\n/** Wires `renderer` in and defines both elements, idempotently. @internal */\nexport function register(renderer: CodeRenderer): void {\n\tuseCodeRenderer(renderer);\n\tif (customElements.get(\"bchc-modal\") === undefined) {\n\t\tcustomElements.define(\"bchc-modal\", BchcModal);\n\t}\n\tif (customElements.get(\"bchc-toast\") === undefined) {\n\t\tcustomElements.define(\"bchc-toast\", BchcToast);\n\t}\n}\n"],"mappings":";;;;;AAQA,SAAgB,SAAS,UAA8B;CACtD,gBAAgB,QAAQ;CACxB,IAAI,eAAe,IAAI,YAAY,MAAM,KAAA,GACxC,eAAe,OAAO,cAAc,SAAS;CAE9C,IAAI,eAAe,IAAI,YAAY,MAAM,KAAA,GACxC,eAAe,OAAO,cAAc,SAAS;AAE/C"}
@@ -0,0 +1,8 @@
1
+
2
+ //#region src/sheet-query.ts
3
+ /** Below this the modal is a drawer: the dialog needs its 760px card plus 16px overlay padding each side. */
4
+ const SHEET_QUERY = "(max-width: 791px)";
5
+ //#endregion
6
+ export { SHEET_QUERY };
7
+
8
+ //# sourceMappingURL=sheet-query.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sheet-query.js","names":[],"sources":["../src/sheet-query.ts"],"sourcesContent":["/** Below this the modal is a drawer: the dialog needs its 760px card plus 16px overlay padding each side. */\nexport const SHEET_QUERY = \"(max-width: 791px)\";\n"],"mappings":";;;AACA,MAAa,cAAc"}