@latchprotocol/widgets 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 (132) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +649 -0
  3. package/dist/adapters/binDistribution.d.ts +19 -0
  4. package/dist/adapters/binDistribution.d.ts.map +1 -0
  5. package/dist/adapters/protocol.d.ts +409 -0
  6. package/dist/adapters/protocol.d.ts.map +1 -0
  7. package/dist/adapters/sale.d.ts +142 -0
  8. package/dist/adapters/sale.d.ts.map +1 -0
  9. package/dist/adapters/viem.d.ts +89 -0
  10. package/dist/adapters/viem.d.ts.map +1 -0
  11. package/dist/callpath/constants.d.ts +218 -0
  12. package/dist/callpath/constants.d.ts.map +1 -0
  13. package/dist/callpath/launch.d.ts +1979 -0
  14. package/dist/callpath/launch.d.ts.map +1 -0
  15. package/dist/callpath/liquidity.d.ts +103 -0
  16. package/dist/callpath/liquidity.d.ts.map +1 -0
  17. package/dist/callpath/plan.d.ts +34 -0
  18. package/dist/callpath/plan.d.ts.map +1 -0
  19. package/dist/callpath/swap.d.ts +129 -0
  20. package/dist/callpath/swap.d.ts.map +1 -0
  21. package/dist/chunks/SwapWidget-DgyHAVc8.js +2404 -0
  22. package/dist/chunks/SwapWidget-DgyHAVc8.js.map +1 -0
  23. package/dist/chunks/scan-Dhu7f4Nl.js +2497 -0
  24. package/dist/chunks/scan-Dhu7f4Nl.js.map +1 -0
  25. package/dist/chunks/useLocker-D1c_NTk-.js +1613 -0
  26. package/dist/chunks/useLocker-D1c_NTk-.js.map +1 -0
  27. package/dist/components/LaunchWidget.d.ts +117 -0
  28. package/dist/components/LaunchWidget.d.ts.map +1 -0
  29. package/dist/components/LiquidityWidget.d.ts +33 -0
  30. package/dist/components/LiquidityWidget.d.ts.map +1 -0
  31. package/dist/components/LockerWidget.d.ts +51 -0
  32. package/dist/components/LockerWidget.d.ts.map +1 -0
  33. package/dist/components/LocksWidgets.d.ts +61 -0
  34. package/dist/components/LocksWidgets.d.ts.map +1 -0
  35. package/dist/components/SwapWidget.d.ts +165 -0
  36. package/dist/components/SwapWidget.d.ts.map +1 -0
  37. package/dist/components/TokenTrustPanel.d.ts +32 -0
  38. package/dist/components/TokenTrustPanel.d.ts.map +1 -0
  39. package/dist/components/lockCharts.d.ts +29 -0
  40. package/dist/components/lockCharts.d.ts.map +1 -0
  41. package/dist/components/portal.d.ts +10 -0
  42. package/dist/components/portal.d.ts.map +1 -0
  43. package/dist/components/primitives.d.ts +139 -0
  44. package/dist/components/primitives.d.ts.map +1 -0
  45. package/dist/components/swap/SwapSettings.d.ts +12 -0
  46. package/dist/components/swap/SwapSettings.d.ts.map +1 -0
  47. package/dist/components/swap/TokenSelect.d.ts +61 -0
  48. package/dist/components/swap/TokenSelect.d.ts.map +1 -0
  49. package/dist/components/swap/state.d.ts +208 -0
  50. package/dist/components/swap/state.d.ts.map +1 -0
  51. package/dist/config/chain.d.ts +163 -0
  52. package/dist/config/chain.d.ts.map +1 -0
  53. package/dist/config/integrator.d.ts +121 -0
  54. package/dist/config/integrator.d.ts.map +1 -0
  55. package/dist/context/WidgetProvider.d.ts +78 -0
  56. package/dist/context/WidgetProvider.d.ts.map +1 -0
  57. package/dist/core/clMath.d.ts +98 -0
  58. package/dist/core/clMath.d.ts.map +1 -0
  59. package/dist/core/errors.d.ts +18 -0
  60. package/dist/core/errors.d.ts.map +1 -0
  61. package/dist/core/format.d.ts +47 -0
  62. package/dist/core/format.d.ts.map +1 -0
  63. package/dist/core/liquidityGuards.d.ts +53 -0
  64. package/dist/core/liquidityGuards.d.ts.map +1 -0
  65. package/dist/core/liquidityRefresh.d.ts +35 -0
  66. package/dist/core/liquidityRefresh.d.ts.map +1 -0
  67. package/dist/core/math.d.ts +129 -0
  68. package/dist/core/math.d.ts.map +1 -0
  69. package/dist/core/pool.d.ts +33 -0
  70. package/dist/core/pool.d.ts.map +1 -0
  71. package/dist/core/tokenLists.d.ts +46 -0
  72. package/dist/core/tokenLists.d.ts.map +1 -0
  73. package/dist/embed/iframe.d.ts +185 -0
  74. package/dist/embed/iframe.d.ts.map +1 -0
  75. package/dist/embed/lockBadge.d.ts +55 -0
  76. package/dist/embed/lockBadge.d.ts.map +1 -0
  77. package/dist/embed/webComponent.d.ts +83 -0
  78. package/dist/embed/webComponent.d.ts.map +1 -0
  79. package/dist/embed.d.ts +25 -0
  80. package/dist/embed.d.ts.map +1 -0
  81. package/dist/embed.js +543 -0
  82. package/dist/embed.js.map +1 -0
  83. package/dist/headless.d.ts +60 -0
  84. package/dist/headless.d.ts.map +1 -0
  85. package/dist/headless.js +223 -0
  86. package/dist/headless.js.map +1 -0
  87. package/dist/hooks/useAsyncResource.d.ts +38 -0
  88. package/dist/hooks/useAsyncResource.d.ts.map +1 -0
  89. package/dist/hooks/useLaunch.d.ts +140 -0
  90. package/dist/hooks/useLaunch.d.ts.map +1 -0
  91. package/dist/hooks/useLiquidity.d.ts +91 -0
  92. package/dist/hooks/useLiquidity.d.ts.map +1 -0
  93. package/dist/hooks/useLocker.d.ts +77 -0
  94. package/dist/hooks/useLocker.d.ts.map +1 -0
  95. package/dist/hooks/useLocks.d.ts +33 -0
  96. package/dist/hooks/useLocks.d.ts.map +1 -0
  97. package/dist/hooks/useSwapExecute.d.ts +46 -0
  98. package/dist/hooks/useSwapExecute.d.ts.map +1 -0
  99. package/dist/hooks/useSwapQuote.d.ts +51 -0
  100. package/dist/hooks/useSwapQuote.d.ts.map +1 -0
  101. package/dist/hooks/useTokenLists.d.ts +26 -0
  102. package/dist/hooks/useTokenLists.d.ts.map +1 -0
  103. package/dist/hooks/useTokenTrust.d.ts +40 -0
  104. package/dist/hooks/useTokenTrust.d.ts.map +1 -0
  105. package/dist/hooks/useTokens.d.ts +15 -0
  106. package/dist/hooks/useTokens.d.ts.map +1 -0
  107. package/dist/index.d.ts +59 -0
  108. package/dist/index.d.ts.map +1 -0
  109. package/dist/index.js +1052 -0
  110. package/dist/index.js.map +1 -0
  111. package/dist/latch-embed.d.ts +19 -0
  112. package/dist/latch-embed.d.ts.map +1 -0
  113. package/dist/latch-embed.js +950 -0
  114. package/dist/latch-embed.js.map +1 -0
  115. package/dist/latch-embed.mjs +13162 -0
  116. package/dist/latch-embed.mjs.map +1 -0
  117. package/dist/locker/model.d.ts +73 -0
  118. package/dist/locker/model.d.ts.map +1 -0
  119. package/dist/locks/embedModel.d.ts +22 -0
  120. package/dist/locks/embedModel.d.ts.map +1 -0
  121. package/dist/locks/fetch.d.ts +60 -0
  122. package/dist/locks/fetch.d.ts.map +1 -0
  123. package/dist/locks/model.d.ts +143 -0
  124. package/dist/locks/model.d.ts.map +1 -0
  125. package/dist/locks/scan.d.ts +25 -0
  126. package/dist/locks/scan.d.ts.map +1 -0
  127. package/dist/styles/css.d.ts +32 -0
  128. package/dist/styles/css.d.ts.map +1 -0
  129. package/dist/styles.css +895 -0
  130. package/dist/trust/model.d.ts +48 -0
  131. package/dist/trust/model.d.ts.map +1 -0
  132. package/package.json +102 -0
@@ -0,0 +1,185 @@
1
+ /**
2
+ * Iframe embedding: the postMessage contract.
3
+ *
4
+ * The web component is the right answer for most hosts. The iframe exists for
5
+ * the case the web component cannot serve: a host that will not run third-party
6
+ * script in its own realm - which, for a widget asking users to sign
7
+ * transactions, is a reasonable position for a host to take.
8
+ *
9
+ * ## The split
10
+ *
11
+ * The **widget** runs inside the iframe and owns only rendering. It holds no
12
+ * keys and opens no RPC connections. Every chain read and write is a request to
13
+ * the host.
14
+ *
15
+ * The **host** runs in the parent page, owns the wallet and a real
16
+ * {@link ../adapters/protocol.js | ProtocolAdapter}, and answers those requests.
17
+ *
18
+ * ```text
19
+ * iframe (widget) parent (host)
20
+ * ──────────────── ─────────────
21
+ * ready ─────────────────────────────────▶
22
+ * ◀───────────────────────────── init { chain, integrator, theme }
23
+ * invoke { id, method, args } ───────────▶
24
+ * ◀────────── result { id, ok, value } | { id, ok: false, error }
25
+ * resize { height } ─────────────────────▶
26
+ * event { name, payload } ──────────────▶
27
+ * ```
28
+ *
29
+ * ## Message contract
30
+ *
31
+ * Every message is `{ channel: "latch-widget", version: 1, ... }`. Anything
32
+ * without that envelope is ignored. Both sides pin the counterpart origin -
33
+ * the host passes the widget's origin, the widget receives the host's in
34
+ * `init` - and every later message is checked against it. `event.origin` is the
35
+ * only trustworthy field on a `MessageEvent`; nothing inside `data` is trusted
36
+ * for identity.
37
+ *
38
+ * `BigInt` survives structured clone, so amounts cross the boundary as exact
39
+ * integers. Never stringify them for transport - a float round-trip is how
40
+ * money goes missing.
41
+ *
42
+ * ## What the host must validate
43
+ *
44
+ * The host is the security boundary. Before signing anything it should check:
45
+ *
46
+ * - the transaction's `to` is a contract it expects (its own router address);
47
+ * - `value` matches what the user was shown;
48
+ * - `integratorFee.referrer` is the host's own address, if it configured one.
49
+ *
50
+ * A widget in an iframe is still third-party code. This contract makes it
51
+ * *inspectable*, not trusted.
52
+ */
53
+ import type { ProtocolAdapter, WidgetTransactionRequest } from "../adapters/protocol.js";
54
+ import type { IntegratorConfig } from "../config/integrator.js";
55
+ import type { WidgetTheme } from "../context/WidgetProvider.js";
56
+ /** Channel name on every message in this protocol. */
57
+ export declare const WIDGET_CHANNEL = "latch-widget";
58
+ /** Version of the message contract. Bumped on any breaking change. */
59
+ export declare const WIDGET_PROTOCOL_VERSION = 1;
60
+ /** Adapter methods the widget may invoke on the host. */
61
+ export type BridgeMethod = Extract<keyof ProtocolAdapter, "getAccount" | "listTokens" | "getToken" | "getBalance" | "listPools" | "getPoolState" | "getApprovalRequirements" | "buildApproval" | "quoteSwap" | "buildSwap" | "quoteAddLiquidity" | "buildAddLiquidity" | "listPositions" | "quoteRemoveLiquidity" | "buildRemoveLiquidity" | "listLaunches" | "getLaunch" | "getLaunchesForToken" | "sendTransaction" | "waitForTransaction">;
62
+ /** Sent by the widget once it has mounted and is ready for `init`. */
63
+ export interface WidgetReadyMessage {
64
+ readonly channel: typeof WIDGET_CHANNEL;
65
+ readonly version: number;
66
+ readonly type: "ready";
67
+ }
68
+ /** Sent by the host in response to `ready`. */
69
+ export interface HostInitMessage {
70
+ readonly channel: typeof WIDGET_CHANNEL;
71
+ readonly version: number;
72
+ readonly type: "init";
73
+ readonly widget: "swap" | "liquidity" | "launch";
74
+ readonly integrator: IntegratorConfig | null;
75
+ readonly theme: WidgetTheme;
76
+ /** Chain metadata, minus anything unserialisable (no transport). */
77
+ readonly chain: {
78
+ readonly chainId: number;
79
+ readonly name: string;
80
+ readonly nativeCurrency: {
81
+ name: string;
82
+ symbol: string;
83
+ decimals: number;
84
+ };
85
+ readonly blockExplorerUrl?: string;
86
+ };
87
+ /** `true` when the host's adapter is a mock, so the widget can warn. */
88
+ readonly isMock: boolean;
89
+ }
90
+ /** A remote adapter call, widget to host. */
91
+ export interface WidgetInvokeMessage {
92
+ readonly channel: typeof WIDGET_CHANNEL;
93
+ readonly version: number;
94
+ readonly type: "invoke";
95
+ readonly id: string;
96
+ readonly method: BridgeMethod;
97
+ readonly args: readonly unknown[];
98
+ }
99
+ /** The host's answer to an `invoke`. */
100
+ export type HostResultMessage = {
101
+ readonly channel: typeof WIDGET_CHANNEL;
102
+ readonly version: number;
103
+ readonly type: "result";
104
+ readonly id: string;
105
+ readonly ok: true;
106
+ readonly value: unknown;
107
+ } | {
108
+ readonly channel: typeof WIDGET_CHANNEL;
109
+ readonly version: number;
110
+ readonly type: "result";
111
+ readonly id: string;
112
+ readonly ok: false;
113
+ readonly error: {
114
+ readonly name: string;
115
+ readonly message: string;
116
+ };
117
+ };
118
+ /** Height report, so the host can size the iframe without scrollbars. */
119
+ export interface WidgetResizeMessage {
120
+ readonly channel: typeof WIDGET_CHANNEL;
121
+ readonly version: number;
122
+ readonly type: "resize";
123
+ readonly height: number;
124
+ }
125
+ /** Lifecycle notifications the host may log or act on. */
126
+ export interface WidgetEventMessage {
127
+ readonly channel: typeof WIDGET_CHANNEL;
128
+ readonly version: number;
129
+ readonly type: "event";
130
+ readonly name: "quote" | "transaction-submitted" | "transaction-confirmed" | "error";
131
+ readonly payload: Record<string, unknown>;
132
+ }
133
+ /** Anything the widget sends. */
134
+ export type WidgetMessage = WidgetReadyMessage | WidgetInvokeMessage | WidgetResizeMessage | WidgetEventMessage;
135
+ /** Anything the host sends. */
136
+ export type HostMessage = HostInitMessage | HostResultMessage;
137
+ /** Options for {@link serveWidgetIframe}. */
138
+ export interface ServeWidgetIframeOptions {
139
+ /** The iframe element the widget is running in. */
140
+ readonly iframe: HTMLIFrameElement;
141
+ /** Exact origin the iframe is served from. Never `"*"`. */
142
+ readonly widgetOrigin: string;
143
+ /** The adapter that answers the widget's requests. */
144
+ readonly adapter: ProtocolAdapter;
145
+ readonly widget: "swap" | "liquidity" | "launch";
146
+ readonly integrator?: IntegratorConfig;
147
+ readonly theme?: WidgetTheme;
148
+ /**
149
+ * Last-line inspection before a transaction is signed. Return `false` to
150
+ * refuse. Use it to assert the fee recipient is you.
151
+ */
152
+ readonly approveTransaction?: (request: WidgetTransactionRequest) => boolean | Promise<boolean>;
153
+ /** Called on every widget event, for analytics. */
154
+ readonly onEvent?: (message: WidgetEventMessage) => void;
155
+ /** Called when the widget reports its height. */
156
+ readonly onResize?: (height: number) => void;
157
+ }
158
+ /**
159
+ * Host side of the bridge: answers the widget's adapter calls.
160
+ *
161
+ * @returns a disposer that removes the listener.
162
+ */
163
+ export declare function serveWidgetIframe(options: ServeWidgetIframeOptions): () => void;
164
+ /** Options for {@link createIframeBridgeAdapter}. */
165
+ export interface IframeBridgeOptions {
166
+ /** Exact origin of the host page. */
167
+ readonly hostOrigin: string;
168
+ /** How long to wait for a reply before failing, in ms. */
169
+ readonly timeoutMs?: number;
170
+ }
171
+ /**
172
+ * Widget side of the bridge: a {@link ProtocolAdapter} that forwards every call
173
+ * to the host page.
174
+ *
175
+ * Runs inside the iframe. Resolves once the host's `init` arrives, so a widget
176
+ * never renders against a half-configured bridge.
177
+ */
178
+ export declare function createIframeBridgeAdapter(options: IframeBridgeOptions): Promise<{
179
+ adapter: ProtocolAdapter;
180
+ init: HostInitMessage;
181
+ dispose(): void;
182
+ }>;
183
+ /** Reports the widget's height to the host, so the iframe can be sized to it. */
184
+ export declare function reportWidgetHeight(hostOrigin: string, element: HTMLElement): () => void;
185
+ //# sourceMappingURL=iframe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iframe.d.ts","sourceRoot":"","sources":["../../src/embed/iframe.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,wBAAwB,EACzB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAEhE,sDAAsD;AACtD,eAAO,MAAM,cAAc,iBAAiB,CAAC;AAE7C,sEAAsE;AACtE,eAAO,MAAM,uBAAuB,IAAI,CAAC;AAEzC,yDAAyD;AACzD,MAAM,MAAM,YAAY,GAAG,OAAO,CAChC,MAAM,eAAe,EACnB,YAAY,GACZ,YAAY,GACZ,UAAU,GACV,YAAY,GACZ,WAAW,GACX,cAAc,GACd,yBAAyB,GACzB,eAAe,GACf,WAAW,GACX,WAAW,GACX,mBAAmB,GACnB,mBAAmB,GACnB,eAAe,GACf,sBAAsB,GACtB,sBAAsB,GACtB,cAAc,GACd,WAAW,GACX,qBAAqB,GACrB,iBAAiB,GACjB,oBAAoB,CACvB,CAAC;AAEF,sEAAsE;AACtE,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,OAAO,EAAE,OAAO,cAAc,CAAC;IACxC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;CACxB;AAED,+CAA+C;AAC/C,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,OAAO,EAAE,OAAO,cAAc,CAAC;IACxC,QAAQ,CAA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@@
1
+ /**
2
+ * `<latch-lock-badge>`: the lock badge for any web page, with no framework.
3
+ *
4
+ * ```html
5
+ * <script src="https://<latch site>/embed/latch-embed.js" defer></script>
6
+ * <latch-lock-badge chain="4663" pool="0x…"></latch-lock-badge>
7
+ * <latch-lock-badge chain="4663" token="0x…" site="https://<latch site>"></latch-lock-badge>
8
+ * ```
9
+ *
10
+ * Attributes:
11
+ * chain chain id (required); must be a chain in the SDK's address book
12
+ * pool a pool id (bytes32), or
13
+ * token a token address
14
+ * pool-type `cl` (default) or `bin`
15
+ * rpc an RPC URL to read through instead of the chain's public RPCs
16
+ * site the Latch site origin; with it the badge links to its public
17
+ * lock page (`/locks/pool/<id>?net=<chain>`); without it, no link
18
+ * theme `light` | `dark` | `system` (default)
19
+ * refresh seconds between re-reads (default 60, 0 = never)
20
+ *
21
+ * It reads the chain directly, through the MIT SDK, with the same readers as
22
+ * `LocksBadge`, and renders plain DOM into a shadow root: no React, no wallet,
23
+ * no writes. The words are only what was read (see `../locks/embedModel.ts`).
24
+ */
25
+ import { type Address, type Hex } from "viem";
26
+ export declare const LOCK_BADGE_TAG = "latch-lock-badge";
27
+ declare const ElementBase: typeof HTMLElement;
28
+ type Parsed = {
29
+ readonly ok: false;
30
+ readonly message: string;
31
+ } | {
32
+ readonly ok: true;
33
+ readonly chainId: number;
34
+ readonly target: {
35
+ readonly kind: "pool";
36
+ readonly poolId: Hex;
37
+ readonly poolType: "cl" | "bin";
38
+ } | {
39
+ readonly kind: "token";
40
+ readonly token: Address;
41
+ };
42
+ };
43
+ /** Pure: the element's attributes, validated. */
44
+ export declare function parseLockBadgeAttributes(get: (name: string) => string | null): Parsed;
45
+ export declare class LatchLockBadgeElement extends ElementBase {
46
+ #private;
47
+ static get observedAttributes(): readonly string[];
48
+ connectedCallback(): void;
49
+ disconnectedCallback(): void;
50
+ attributeChangedCallback(): void;
51
+ }
52
+ /** Registers `<latch-lock-badge>`. Safe to call twice. */
53
+ export declare function defineLatchLockBadge(): void;
54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
1
+ /**
2
+ * Custom-element wrappers, for hosts that are not React.
3
+ *
4
+ * Vue, Svelte, Angular, Astro and plain HTML can all render a custom element.
5
+ * These mount the same React components into a shadow root, so the widget's CSS
6
+ * cannot leak into the host page and the host's CSS cannot break the widget -
7
+ * while `--latch-*` custom properties still inherit through the shadow boundary,
8
+ * which is exactly the theming behaviour an embedder wants.
9
+ *
10
+ * ```html
11
+ * <script type="module" src="/latch-widgets.js"></script>
12
+ * <latch-swap-widget theme="dark"></latch-swap-widget>
13
+ * ```
14
+ *
15
+ * The adapter cannot come from an attribute - a viem transport is not JSON -
16
+ * so set it as a property:
17
+ *
18
+ * ```js
19
+ * document.querySelector("latch-swap-widget").adapter = createViemAdapter({...});
20
+ * ```
21
+ */
22
+ import { type ComponentType } from "react";
23
+ import type { ProtocolAdapter } from "../adapters/protocol.js";
24
+ /**
25
+ * SSR-safe `HTMLElement`.
26
+ *
27
+ * `class X extends HTMLElement` is evaluated at module load, so importing this
28
+ * file in Node - which any host doing server-side rendering does - would throw
29
+ * `HTMLElement is not defined` before a single line of user code ran. On the
30
+ * server the classes extend an inert stand-in instead. They are never
31
+ * instantiated there: `defineLatchWidgets` no-ops without `customElements`, and
32
+ * only the browser's custom-element machinery constructs them.
33
+ */
34
+ declare const ElementBase: typeof HTMLElement;
35
+ /** Base class shared by every widget element. */
36
+ declare abstract class LatchWidgetElement extends ElementBase {
37
+ #private;
38
+ /** Observed attributes, extended by each subclass. */
39
+ static get observedAttributes(): readonly string[];
40
+ /** The adapter, when set imperatively. Takes precedence over the attribute. */
41
+ get adapter(): ProtocolAdapter | null;
42
+ set adapter(value: ProtocolAdapter | null);
43
+ connectedCallback(): void;
44
+ disconnectedCallback(): void;
45
+ attributeChangedCallback(): void;
46
+ /** The React component this element renders. */
47
+ protected abstract component(): ComponentType<Record<string, unknown>>;
48
+ /** Extra props derived from element attributes. */
49
+ protected widgetProps(): Record<string, unknown>;
50
+ }
51
+ /** `<latch-swap-widget>`. */
52
+ export declare class LatchSwapWidgetElement extends LatchWidgetElement {
53
+ static get observedAttributes(): readonly string[];
54
+ protected component(): ComponentType<Record<string, unknown>>;
55
+ protected widgetProps(): Record<string, unknown>;
56
+ }
57
+ /** `<latch-liquidity-widget>`. */
58
+ export declare class LatchLiquidityWidgetElement extends LatchWidgetElement {
59
+ static get observedAttributes(): readonly string[];
60
+ protected component(): ComponentType<Record<string, unknown>>;
61
+ protected widgetProps(): Record<string, unknown>;
62
+ }
63
+ /** `<latch-launch-widget>`. */
64
+ export declare class LatchLaunchWidgetElement extends LatchWidgetElement {
65
+ static get observedAttributes(): readonly string[];
66
+ protected component(): ComponentType<Record<string, unknown>>;
67
+ protected widgetProps(): Record<string, unknown>;
68
+ }
69
+ /** Element tag names, so hosts do not have to hardcode strings. */
70
+ export declare const WIDGET_TAG_NAMES: {
71
+ readonly swap: "latch-swap-widget";
72
+ readonly liquidity: "latch-liquidity-widget";
73
+ readonly launch: "latch-launch-widget";
74
+ };
75
+ /**
76
+ * Registers every widget element.
77
+ *
78
+ * Safe to call more than once; already-registered tags are skipped rather than
79
+ * throwing, so two copies of the bundle on one page do not break it.
80
+ */
81
+ export declare function defineLatchWidgets(): void;
82
+ export {};
83
+ //# sourceMappingURL=webComponent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webComponent.d.ts","sourceRoot":"","sources":["../../src/embed/webComponent.tsx"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAiB,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAE1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AA2B/D;;;;;;;;;GASG;AACH,QAAA,MAAM,WAAW,EAAE,OAAO,WAGT,CAAC;AAElB,iDAAiD;AACjD,uBAAe,kBAAmB,SAAQ,WAAW;;IAMnD,sDAAsD;IACtD,MAAM,KAAK,kBAAkB,IAAI,SAAS,MAAM,EAAE,CAEjD;IAED,+EAA+E;IAC/E,IA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,25 @@
1
+ /**
2
+ * Framework-agnostic embedding.
3
+ *
4
+ * Two escape hatches for hosts that are not React:
5
+ *
6
+ * - **Custom elements** - `<latch-swap-widget>`, `<latch-liquidity-widget>` and
7
+ * `<latch-launch-widget>`, rendered into a shadow root. Works anywhere a
8
+ * browser runs, including plain HTML.
9
+ * - **`<latch-lock-badge>`** - the read-only lock badge as plain DOM, no React
10
+ * and no wallet; {@link defineLatchLockBadge} registers it. The standalone
11
+ * `latch-embed.js` bundle registers it on load for pages with no bundler.
12
+ * - **Iframe bridge** - the widget runs in its own realm and asks the host page
13
+ * to perform every chain read and write over a documented postMessage
14
+ * contract. For hosts that will not execute third-party script in their realm.
15
+ *
16
+ * Importing this module does not register anything. Call
17
+ * {@link defineLatchWidgets} when you want the elements defined.
18
+ *
19
+ * @packageDocumentation
20
+ */
21
+ export { defineLatchWidgets, WIDGET_TAG_NAMES, LatchSwapWidgetElement, LatchLiquidityWidgetElement, LatchLaunchWidgetElement, } from "./embed/webComponent.js";
22
+ export { WIDGET_CHANNEL, WIDGET_PROTOCOL_VERSION, createIframeBridgeAdapter, reportWidgetHeight, serveWidgetIframe, type BridgeMethod, type HostInitMessage, type HostMessage, type HostResultMessage, type IframeBridgeOptions, type ServeWidgetIframeOptions, type WidgetEventMessage, type WidgetInvokeMessage, type WidgetMessage, type WidgetReadyMessage, type WidgetResizeMessage, } from "./embed/iframe.js";
23
+ export { LOCK_BADGE_TAG, LatchLockBadgeElement, defineLatchLockBadge, parseLockBadgeAttributes, } from "./embed/lockBadge.js";
24
+ export { WIDGET_CSS, injectWidgetStyles } from "./styles/css.js";
25
+ //# sourceMappingURL=embed.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"embed.d.ts","sourceRoot":"","sources":["../src/embed.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,sBAAsB,EACtB,2BAA2B,EAC3B,wBAAwB,GACzB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,cAAc,EACd,uBAAuB,EACvB,yBAAyB,EACzB,kBAAkB,EAClB,iBAAiB,EACjB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,GACzB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC"}