@stridge/pay-kit 0.0.0-stage → 0.1.0-alpha.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 +339 -2
- package/dist/account.d.ts +4 -0
- package/dist/account.js +1 -0
- package/dist/channel/createAppChannel.js +1 -0
- package/dist/channel/createDialogAriaHiddenIntent.js +1 -0
- package/dist/channel/createDialogHost.js +1 -0
- package/dist/channel/createScrollLock.js +2 -0
- package/dist/channel/iframeTransport.js +1 -0
- package/dist/channel/popupTransport.js +1 -0
- package/dist/channel/presentation.js +1 -0
- package/dist/channel/types.d.ts +225 -0
- package/dist/core/buildElementUrl.js +1 -0
- package/dist/core/createElementClient.js +1 -0
- package/dist/core/createElementHandle.js +1 -0
- package/dist/core/createElementLedger.js +1 -0
- package/dist/core/createElementLifetimeBridge.js +1 -0
- package/dist/core/elementClientTypes.d.ts +20 -0
- package/dist/core/elementGeometry.js +1 -0
- package/dist/core/elementLoadState.d.ts +1 -0
- package/dist/core/elementLoadState.js +1 -0
- package/dist/core/elementSizing.js +1 -0
- package/dist/core/elementStartGate.js +1 -0
- package/dist/core/types.d.ts +1 -0
- package/dist/errors/PayError.d.ts +37 -0
- package/dist/errors/PayError.js +1 -0
- package/dist/hooks/keypairState.js +1 -0
- package/dist/hooks/types.d.ts +104 -0
- package/dist/hooks/usePayAccount.d.ts +16 -0
- package/dist/hooks/usePayAccount.js +1 -0
- package/dist/hooks/usePaySnapshot.d.ts +13 -0
- package/dist/hooks/usePaySnapshot.js +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +1 -0
- package/dist/provider/PayProvider.d.ts +47 -0
- package/dist/provider/PayProvider.js +1 -0
- package/dist/provider/context.js +1 -0
- package/dist/provider/createProviderLifetime.js +1 -0
- package/dist/provider/elementContext.js +1 -0
- package/dist/provider/hubAddress.js +1 -0
- package/dist/provider/types.d.ts +73 -0
- package/dist/react/ElementDefault.d.ts +23 -0
- package/dist/react/ElementDefault.js +1 -0
- package/dist/react/ElementHost.js +1 -0
- package/dist/react/ElementLanes.js +1 -0
- package/dist/react/PayElement.d.ts +13 -0
- package/dist/react/PayElement.js +1 -0
- package/dist/react/compileElementOptions.js +1 -0
- package/dist/react/compilePayRequest.js +1 -0
- package/dist/react/elementDefaultStyles.d.ts +15 -0
- package/dist/react/elementDefaultStyles.js +69 -0
- package/dist/react/elementSwap.js +1 -0
- package/dist/react/payEvents.d.ts +139 -0
- package/dist/react/payEvents.js +1 -0
- package/dist/react/presentElement.js +1 -0
- package/dist/react/stridgeLockup.js +1 -0
- package/dist/react/types.d.ts +118 -0
- package/dist/react/useElementHandle.js +1 -0
- package/dist/shared/presentation/hubWindow.js +1 -0
- package/dist/shared/presentation/subscribeToNothing.js +1 -0
- package/package.json +124 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Stridge Foundation
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,340 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @stridge/pay-kit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Staging-only. Pin an exact version. Use the newest kit.
|
|
4
|
+
|
|
5
|
+
Put a Stridge payment in your React page. `PayElement` shows a pay card for one order or one deposit. When the customer pays, the Stridge window opens on the Stridge origin. Sign-in and signing run there, and the private keys never leave it. The account hook gives your page the customer's address after a sign-in, and the signature of a message that your page asks the customer to sign. The money goes to a destination saved for your app on the Stridge server, not to an address that your page chooses.
|
|
6
|
+
|
|
7
|
+
## Read this first: the page event is not proof of payment
|
|
8
|
+
|
|
9
|
+
`PayElement` tells your page what the Stridge window saw, through one `onEvent` callback. Each event has a `type`:
|
|
10
|
+
|
|
11
|
+
| `type` | What it means |
|
|
12
|
+
| --- | --- |
|
|
13
|
+
| `payment.observed` | The window saw a delivery for this payment. It carries `referenceId`, `mode`, `amount`, `method`, `receiptCode`, `transactionHash` (or `null`), `received` and `short`. `short` is `true` when less than the payment's target arrived. A short delivery does not pay the order. |
|
|
14
|
+
| `checkout.closed` | The backend's checkout for this payment reached a final state: `completed`, `failed`, `canceled` or `expired`. It carries `approvedBaseUnits`, `deliveredBaseUnits` and `destinationTxs`. A `completed` checkout can still be short, and `destinationTxs` can be empty. One payment can have more than one checkout. |
|
|
15
|
+
| `payment.on_hold` | The payment needs Stridge support and stays locked. Show the customer its `receiptCode`. A new order needs a new `referenceId`. |
|
|
16
|
+
| `payment.unconfirmed` | The customer's wallet may have sent, and the window cannot confirm it yet. Never retry this `referenceId`. Check it on your server. |
|
|
17
|
+
| `request.failed` | A sign-in or a fund request that the card ran for the customer failed. Read `error.code`. It says nothing about the payment. |
|
|
18
|
+
|
|
19
|
+
No event proves that money arrived. The event runs in the customer's browser, so any script on the page can call your handler with any values. An event can also come again after a reload. Stridge gives your server no status read and no webhook for these payments today.
|
|
20
|
+
|
|
21
|
+
So your server must check each payment on the chain before you ship the order. Do these steps:
|
|
22
|
+
|
|
23
|
+
1. Keep a copy of your saved destination in your server's configuration: the chain, the coin's contract address, the coin's decimals and your receiving address. Use the same values that Stridge saved for your app.
|
|
24
|
+
2. In `onEvent`, send the `referenceId` and the transaction hashes to your server. A `payment.observed` event has `transactionHash`. A `checkout.closed` event has `destinationTxs`.
|
|
25
|
+
3. On your server, claim each hash for one order, once. Refuse a hash that another order already claimed.
|
|
26
|
+
4. Read each transaction's receipt from the destination chain. Skip a transaction that did not succeed.
|
|
27
|
+
5. In the receipt, add up the ERC-20 `Transfer` logs whose contract is your coin and whose recipient is your address.
|
|
28
|
+
6. Convert the order's price to the coin's base units: the price in USD times 10 to the power of the coin's decimals. USDC and USDT on BSC have 18 decimals. Each other supported coin has 6.
|
|
29
|
+
7. Mark the order paid only when the sum is equal to or more than the price.
|
|
30
|
+
|
|
31
|
+
A delivery can be less than the price, because fees come off on some ways to pay. The event then has `short: true`. Your own policy decides what to do with a short payment.
|
|
32
|
+
|
|
33
|
+
An event can carry no delivery hash, or only some of them. A Manual deposit can arrive as several transfers, and its `payment.observed` event names only the last one in `transactionHash`. So when the hashes you verified do not cover the price, keep the order pending. Then find each transfer to your address in a block explorer and match it to the order by hand, also when `transactionHash` is not `null`. Never use the event's `received` amount to fill the gap.
|
|
34
|
+
|
|
35
|
+
This check has a weak point. A transaction hash is public, and nothing on the chain ties a transfer to your `referenceId`. A stranger can send another customer's hash for a different order of the same amount, before that customer's page sends it. The first claim wins. Examine each refused claim by hand.
|
|
36
|
+
|
|
37
|
+
Later stages are not available yet. First, the backend will refuse a destination that your app did not save, and your server will read a payment's status by your own `referenceId`. After that, your server will create each payment.
|
|
38
|
+
|
|
39
|
+
## Install
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
pnpm add --save-exact @stridge/pay-kit
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
> **Warning:** Packages with near names and no `@stridge/` scope exist on the public registry. They are not ours. Install only `@stridge/pay-kit`.
|
|
46
|
+
|
|
47
|
+
The kit needs React 19 and React DOM 19 as peer dependencies. It installs `@stridge/pay-sdk` as its own dependency. You import no stylesheet.
|
|
48
|
+
|
|
49
|
+
## Quick start
|
|
50
|
+
|
|
51
|
+
`PayProvider` and `PayElement` are client components. Put them in a file that starts with `"use client"` when you use the Next.js App Router.
|
|
52
|
+
|
|
53
|
+
```tsx
|
|
54
|
+
"use client";
|
|
55
|
+
|
|
56
|
+
import { PayElement, PayProvider, type PayEvent } from "@stridge/pay-kit";
|
|
57
|
+
|
|
58
|
+
/** Sends the page's report to your server, which checks the payment on the chain. */
|
|
59
|
+
function reportToServer(referenceId: string, hashes: readonly string[]): void {
|
|
60
|
+
void fetch("/api/orders/check", {
|
|
61
|
+
method: "POST",
|
|
62
|
+
headers: { "Content-Type": "application/json" },
|
|
63
|
+
body: JSON.stringify({ referenceId, hashes }),
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function handlePayEvent(event: PayEvent): void {
|
|
68
|
+
switch (event.type) {
|
|
69
|
+
case "payment.observed":
|
|
70
|
+
reportToServer(event.referenceId, event.transactionHash === null ? [] : [event.transactionHash]);
|
|
71
|
+
break;
|
|
72
|
+
case "checkout.closed":
|
|
73
|
+
reportToServer(event.referenceId, event.destinationTxs);
|
|
74
|
+
break;
|
|
75
|
+
case "payment.on_hold":
|
|
76
|
+
case "payment.unconfirmed":
|
|
77
|
+
console.info(`Order ${event.referenceId} needs a check. Receipt code: ${event.receiptCode}`);
|
|
78
|
+
break;
|
|
79
|
+
case "request.failed":
|
|
80
|
+
console.info(`The ${event.request} request failed: ${event.error.code}`);
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function Checkout({ order }: { order: { id: string; total: string } }) {
|
|
86
|
+
return (
|
|
87
|
+
<PayProvider appId="app_…" environment="sandbox">
|
|
88
|
+
<PayElement referenceId={order.id} amount={order.total} description="Blue shirt" onEvent={handlePayEvent} />
|
|
89
|
+
</PayProvider>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Replace `app_…` with the app id that Stridge issued for your app, and copy it exactly. It is `app_` followed by a 26-character uppercase ULID. Stridge must also register your page's origin for that app id.
|
|
95
|
+
|
|
96
|
+
Keep `referenceId` the same for one order. The same `referenceId` with another mode, amount or description is refused, so a new order needs a new `referenceId`. `amount` is a decimal string in USD, with at most two decimals, more than 0 and at most `100000.00`.
|
|
97
|
+
|
|
98
|
+
### A deposit where the customer chooses the amount
|
|
99
|
+
|
|
100
|
+
Set `mode="deposit"` and leave `amount` out. The window then asks "How much?".
|
|
101
|
+
|
|
102
|
+
```tsx
|
|
103
|
+
<PayElement referenceId={topUp.id} mode="deposit" description="Account top-up" onEvent={handlePayEvent} />
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
You can add `min` and `max` (decimal strings, as `amount`). `firstStep="method"` opens the window on the ways to pay and asks the amount after. A deposit with a fixed `amount` takes no `min`, `max` or `firstStep`.
|
|
107
|
+
|
|
108
|
+
### The account hook
|
|
109
|
+
|
|
110
|
+
The customer's Stridge sign-in, signing and Fund are in a second entry, `@stridge/pay-kit/account`. Call `usePayAccount` in a component inside `PayProvider`.
|
|
111
|
+
|
|
112
|
+
```tsx
|
|
113
|
+
"use client";
|
|
114
|
+
|
|
115
|
+
import { isPayError } from "@stridge/pay-kit";
|
|
116
|
+
import { usePayAccount } from "@stridge/pay-kit/account";
|
|
117
|
+
|
|
118
|
+
export function SignInButton() {
|
|
119
|
+
const account = usePayAccount();
|
|
120
|
+
if (account.status === "signed-in") return <p>{account.evmAddress}</p>;
|
|
121
|
+
return (
|
|
122
|
+
<button
|
|
123
|
+
type="button"
|
|
124
|
+
disabled={account.busy}
|
|
125
|
+
onClick={() => {
|
|
126
|
+
account.signIn().catch((error: unknown) => {
|
|
127
|
+
if (!isPayError(error, "cancelled")) console.error(error);
|
|
128
|
+
});
|
|
129
|
+
}}
|
|
130
|
+
>
|
|
131
|
+
Sign in
|
|
132
|
+
</button>
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Call `signIn`, `sign`, `signOut`, `disconnect` and `fund` directly in the customer's click, before any `await`. A request can open the Stridge window, and the browser blocks a window that does not open from a click.
|
|
138
|
+
|
|
139
|
+
- `signIn()` resolves with `{ evmAddress }`.
|
|
140
|
+
- `sign(message)` shows the Stridge confirm screen and resolves with the signature. With no session, it signs the customer in first.
|
|
141
|
+
- `signOut()` ends the Stridge session in this browser, for every app that shares it. `disconnect()` removes this app only.
|
|
142
|
+
- `fund({ start })` opens Fund on the `"fund"` or `"home"` screen. It needs a signed-in session, and it resolves when the customer closes Fund.
|
|
143
|
+
|
|
144
|
+
## Props
|
|
145
|
+
|
|
146
|
+
### `PayProvider`
|
|
147
|
+
|
|
148
|
+
| Prop | Type | Required | Meaning |
|
|
149
|
+
| --- | --- | --- | --- |
|
|
150
|
+
| `appId` | `string` | Yes | The app id that Stridge issued for your app. A change starts a new provider lifetime. |
|
|
151
|
+
| `environment` | `"sandbox" \| "live"` | Yes | The Stridge environment to connect to. See [Environments](#environments). |
|
|
152
|
+
| `children` | `ReactNode` | Yes | Your tree. `PayElement` and the hooks work anywhere inside it. |
|
|
153
|
+
| `theme` | `"dark" \| "light" \| "system"` | No | The colour scheme of the card and the Stridge window. `"system"` follows the browser. The default is `"dark"`. |
|
|
154
|
+
| `onConnected` | `(event: PayConnectedEvent) => void` | No | Called once for each new address that the provider sees signed in. It is not proof of a live signing session. |
|
|
155
|
+
| `dialogAriaHiddenAdapter` | `PayDialogAriaHiddenAdapter` | No | Lets your modal manager set the `aria-hidden` value of the kit's dialog. See [Host modal accessibility](#host-modal-accessibility). |
|
|
156
|
+
|
|
157
|
+
### `PayElement`
|
|
158
|
+
|
|
159
|
+
| Prop | Type | Required | Meaning |
|
|
160
|
+
| --- | --- | --- | --- |
|
|
161
|
+
| `referenceId` | `string` | Yes | Your own id for this payment, 1 to 128 characters. Keep it the same for one order. |
|
|
162
|
+
| `amount` | `string` | Yes, except for a deposit with a chosen amount | The price in USD, as a decimal string such as `"24.00"`. |
|
|
163
|
+
| `mode` | `"payment" \| "deposit"` | No | What the request is. The default is `"payment"`. |
|
|
164
|
+
| `min` | `string` | No | The least amount a customer can choose, for a deposit with no `amount`. |
|
|
165
|
+
| `max` | `string` | No | The most a customer can choose, for a deposit with no `amount`. |
|
|
166
|
+
| `firstStep` | `"amount" \| "method"` | No | For a deposit with no `amount`: ask the amount first (the default) or the way to pay first. |
|
|
167
|
+
| `description` | `string` | No | The line the window shows for what the customer pays for. The kit trims it. It must then be 1 to 64 UTF-16 code units, with no control character, bidirectional override or isolate mark. A changed `description` needs a new `referenceId`. |
|
|
168
|
+
| `destination` | `` `ckr_${string}` `` or `{ address, asset }` | No | Which saved destination pays. Leave it out to use your app's default. See [Where the money goes](#where-the-money-goes). |
|
|
169
|
+
| `onEvent` | `(event: PayEvent) => void` | No | Called with each event of the payment. See [the events](#read-this-first-the-page-event-is-not-proof-of-payment). |
|
|
170
|
+
| `loading` | `ReactNode` | No | Shown in place of the kit's placeholder while the card loads. |
|
|
171
|
+
| `fallback` | `ReactNode` or `(context) => ReactNode` | No | Shown in place of each failure view. A function gets `retry` and `reason` (`"hub-frame"`, `"internal"` or `"unreachable"`). |
|
|
172
|
+
| `className` | `string` | No | A class on the card's outer node. |
|
|
173
|
+
| `style` | `CSSProperties` | No | Inline styles on the card's outer node. |
|
|
174
|
+
|
|
175
|
+
`PayElement` throws a `TypeError` during render for a prop it does not take and for a value it refuses.
|
|
176
|
+
|
|
177
|
+
## The words that mean two things
|
|
178
|
+
|
|
179
|
+
| Word | Its one meaning in this kit | The other meaning it is not |
|
|
180
|
+
| --- | --- | --- |
|
|
181
|
+
| deposit | `mode="deposit"`: a request where the customer adds money, such as an account top-up, with a fixed or chosen amount. It goes to the same saved destination as a payment. | "Manual deposit", one of the ways to pay, where the customer sends coins to an address made for one order (`method: "transfer"` in the event). |
|
|
182
|
+
| checkout | The backend's checkout: the route that pays your destination. `checkout.closed` reports its final state. One payment can have more than one. | Your shop's checkout page, or the Stridge window. Neither of them closes a checkout. |
|
|
183
|
+
| account | The customer's Stridge sign-in and Stridge Wallet (`@stridge/pay-kit/account`, `usePayAccount`). `method: "account"` means that the customer paid from the Stridge Wallet. | Your business's own Stridge setup, or the customer's account in your app. |
|
|
184
|
+
| reference | `referenceId`: your own id for the payment. | The short code on the customer's receipt. That code is `receiptCode`. |
|
|
185
|
+
|
|
186
|
+
## Environments
|
|
187
|
+
|
|
188
|
+
`environment` is `"sandbox"` or `"live"`.
|
|
189
|
+
|
|
190
|
+
- `"sandbox"` connects to the Stridge hub at `https://universal.stridge.dev/`. Real coins move on it.
|
|
191
|
+
- `"live"` has no hub yet. `PayProvider` throws a `TypeError` during render: `PayProvider: the "live" environment has no hub yet. Use environment="sandbox".`
|
|
192
|
+
|
|
193
|
+
Any other value throws a `TypeError` too.
|
|
194
|
+
|
|
195
|
+
## Where the money goes
|
|
196
|
+
|
|
197
|
+
Your destination (a chain, a coin and your address) is saved on the Stridge server as a checkout rule of your app. Your page names no address.
|
|
198
|
+
|
|
199
|
+
- **No `destination`.** The server pays your app's default rule. This is the normal case. If your app has no default rule, the window stops and shows the developer line "This app has no default destination. Save one, or pass `destination`."
|
|
200
|
+
- **A rule id, such as `destination="ckr_…"`.** That saved rule pays.
|
|
201
|
+
- **`{ address, asset }`.** The address with its CAIP-19 asset id, such as `eip155:8453/erc20:0x…`. It pays only when it is one of your app's saved rules. An address never goes without its asset.
|
|
202
|
+
|
|
203
|
+
> **Warning:** An app that Stridge's hub list marks as a test app can also pay an address that is not saved. This test-app mark is not the `"sandbox"` environment, and real coins move under both. Never rely on the test-app mark to pay a free address. A business app has no test-app mark, so it pays only its saved destinations.
|
|
204
|
+
|
|
205
|
+
The saved default never replaces a destination that your page names. When the server answers another rule, asset or address, the window refuses the payment, sends nothing and shows a developer line that names both. Today the server answers with the default rule whenever the app has one. So, for an app with a default rule, a page that names another rule always stops.
|
|
206
|
+
|
|
207
|
+
The window pays only a dollar token on an EVM chain: USDC or USDT, and on Tempo only USDC (listed as `USDC.e`). The server's asset registry must list it.
|
|
208
|
+
|
|
209
|
+
A changed `destination` takes effect with the next Pay of the same `referenceId`.
|
|
210
|
+
|
|
211
|
+
## Ways to pay
|
|
212
|
+
|
|
213
|
+
The customer picks a way to pay in the window's "Pay with" list. Which rows show depends on your app's setup, the customer, your destination's coin and chain, and the amount.
|
|
214
|
+
|
|
215
|
+
"Card or bank" and "Manual deposit" stay in the list when they cannot serve this payment. The row is then dimmed and does nothing, and its second line gives the reason. The reason is "Starts at" and the least amount, "Can’t pay in" and the coin and chain that the payment network lacks, or "Not available here". A Stridge Wallet row whose balance cannot be read is also disabled. It keeps its usual second line.
|
|
216
|
+
|
|
217
|
+
The Stridge Wallet row shows only for an app that Stridge marks as a test app. For any other app, the row is not in the list.
|
|
218
|
+
|
|
219
|
+
## Content security policy and the frame
|
|
220
|
+
|
|
221
|
+
The kit frames the Stridge hub and adds inline `<style>` elements to your page. A strict content security policy needs these values:
|
|
222
|
+
|
|
223
|
+
| Directive | Value | Why |
|
|
224
|
+
| --- | --- | --- |
|
|
225
|
+
| `frame-src` | `https://universal.stridge.dev` for `"sandbox"` | The provider's hidden hub frame and each card's frame load from the hub's origin. |
|
|
226
|
+
| `style-src` | `'unsafe-inline'` | The kit adds `<style>` elements and has no nonce option. See the list below. |
|
|
227
|
+
|
|
228
|
+
The kit adds these `<style>` elements:
|
|
229
|
+
|
|
230
|
+
- one stylesheet for each card's outer node and the kit's default views, added once for each document;
|
|
231
|
+
- one backdrop rule inside the provider's `<dialog>`, for the provider's lifetime;
|
|
232
|
+
- one scroll-lock rule while the Stridge overlay shows.
|
|
233
|
+
|
|
234
|
+
Two more rules apply to the frame and the window:
|
|
235
|
+
|
|
236
|
+
- The hub sends its own `frame-ancestors`. It lists your origin only when Stridge registers that origin for your app id. An unregistered origin gets no hub frame, or the `app-suspended` error.
|
|
237
|
+
- The Stridge window needs its opener. Do not send `Cross-Origin-Opener-Policy: same-origin`, because it cuts the link to every window your page opens. Send `same-origin-allow-popups`.
|
|
238
|
+
|
|
239
|
+
## Errors
|
|
240
|
+
|
|
241
|
+
A failed request rejects with a `PayError`. Read its `code`. `isPayError(error)` returns `true` for a `PayError`, also for a copy from a second bundle, and `isPayError(error, code)` also checks the code. With `rate-limited`, `retryAfterSeconds` is the wait in seconds when the hub sent one.
|
|
242
|
+
|
|
243
|
+
| Code | Meaning |
|
|
244
|
+
| --- | --- |
|
|
245
|
+
| `cancelled` | The customer closed the dialog. |
|
|
246
|
+
| `busy` | Another request is still in progress. |
|
|
247
|
+
| `not-initialized` | A request arrived before the hub's connection started. |
|
|
248
|
+
| `signed-out` | The request needs a session, and there is none. |
|
|
249
|
+
| `refused` | The signature was refused, by the provider or by the hub. |
|
|
250
|
+
| `outcome-unknown` | The signature's outcome is unknown. Never retry it automatically. |
|
|
251
|
+
| `cosignature-required` | The request waits for a second approval that nothing will give. |
|
|
252
|
+
| `session-locked` | The session's `csrf_token` is lost. |
|
|
253
|
+
| `app-suspended` | The backend refuses this app id, or the hub refuses your page's origin for it. |
|
|
254
|
+
| `rate-limited` | Too many requests. |
|
|
255
|
+
| `wallet-closed` | The customer's wallet is closed. |
|
|
256
|
+
| `wallet-not-ready` | The customer's wallet is still being created after the wait ran out. |
|
|
257
|
+
| `network` | The hub could not reach the Stridge server. |
|
|
258
|
+
| `internal` | Any other failure. |
|
|
259
|
+
| `unavailable` | The hub never completed its connection, reloaded during the request, or never opened Fund in time. |
|
|
260
|
+
| `popup-blocked` | The browser refused to open the Stridge window, usually because the request did not start in the customer's click. |
|
|
261
|
+
|
|
262
|
+
These are configuration faults. Correct them in your code or your setup, not with a retry:
|
|
263
|
+
|
|
264
|
+
- A `TypeError` during render: a wrong `environment`, an `appId` that is not the issued id copied exactly (`app_` and a 26-character uppercase ULID), or a wrong `PayElement` prop. The message names the fault.
|
|
265
|
+
- `app-suspended`: ask Stridge to register your page's origin for your app id, and check the app id.
|
|
266
|
+
- `unavailable` on every request: the hub frame never connected. The kit writes one console warning that starts with `[pay-kit]` and names the cause. Check `frame-src`, the registered origin and `Cross-Origin-Opener-Policy`.
|
|
267
|
+
- `popup-blocked`: start the request in the click handler, before any `await`.
|
|
268
|
+
|
|
269
|
+
Invalid local arguments, such as an empty `sign` message, reject with a `TypeError`. Never retry a signature or a payment automatically after an unknown outcome.
|
|
270
|
+
|
|
271
|
+
## Styling
|
|
272
|
+
|
|
273
|
+
You can style the card's outer node today. It has:
|
|
274
|
+
|
|
275
|
+
- the class `stridge-pay-element`, plus your `className`;
|
|
276
|
+
- the attribute `data-stridge-pay-element`;
|
|
277
|
+
- `data-view`: `"frame"` while the card shows, or `"skeleton"`, `"loading"`, `"fallback"`, `"failed"` or `"connecting"` while a view covers it;
|
|
278
|
+
- `data-shape`: `"lanes"` for the Pay card, `"bar"` for every other element;
|
|
279
|
+
- `aria-busy="true"` while the card loads;
|
|
280
|
+
- your `style`.
|
|
281
|
+
|
|
282
|
+
The kit reserves a block size on the outer node while a view covers the frame: 184 px for the Pay card, 62 px for every other element. Its layout rules use `:where()`, so any class of yours wins over them. The card's content inside the frame is drawn by the hub. Change its colours with `theme` and `accent`.
|
|
283
|
+
|
|
284
|
+
## Host modal accessibility
|
|
285
|
+
|
|
286
|
+
Pause your own focus trap while `usePaySnapshot().overlayOpen` is `true`.
|
|
287
|
+
|
|
288
|
+
If your app's modal manager sets `aria-hidden` on page content, pass `dialogAriaHiddenAdapter` to `PayProvider`. The adapter tells the kit which `aria-hidden` value its dialog must have while the kit is not presenting. The kit restores that exact value each time its overlay closes.
|
|
289
|
+
|
|
290
|
+
```tsx
|
|
291
|
+
import type { PayDialogAriaHiddenAdapter } from "@stridge/pay-kit";
|
|
292
|
+
|
|
293
|
+
/** Define it once, outside any component. `readHostIntent` and `subscribeToHostIntent` come from your modal manager. */
|
|
294
|
+
const dialogAriaHiddenAdapter: PayDialogAriaHiddenAdapter = (register) => {
|
|
295
|
+
const signal = register(readHostIntent());
|
|
296
|
+
const unsubscribe = subscribeToHostIntent((value) => signal(value));
|
|
297
|
+
signal(readHostIntent());
|
|
298
|
+
return unsubscribe;
|
|
299
|
+
};
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
### The adapter contract
|
|
303
|
+
|
|
304
|
+
A value is `null`, `"false"`, or `"true"`. `null` means the dialog has no `aria-hidden` attribute.
|
|
305
|
+
|
|
306
|
+
- The kit calls the adapter once, after the provider first commits. StrictMode does not call it a second time.
|
|
307
|
+
- The adapter calls `register` synchronously with the initial value and returns a cleanup function. An adapter that holds no resources returns a cleanup that does nothing.
|
|
308
|
+
- `register` returns a signal. Call the signal each time the host's value changes, and also when the host repeats the same value. Each call replaces the previous value.
|
|
309
|
+
- One adapter covers every host modal. The host combines them into one value.
|
|
310
|
+
- An invalid value throws a `TypeError`. After the provider is disposed, the signal returns `false` and checks nothing.
|
|
311
|
+
- Keep the adapter function stable for the provider's lifetime. A different function throws a `TypeError`. To add, replace, or remove the adapter, change the provider's `key`, `environment`, or `appId`.
|
|
312
|
+
- If the adapter throws before it returns its cleanup, the adapter must release its own host resources.
|
|
313
|
+
|
|
314
|
+
### What the kit does with the value
|
|
315
|
+
|
|
316
|
+
- While the kit presents, a signal stores the new value. The kit does not hide its dialog.
|
|
317
|
+
- Before the kit opens the dialog and moves focus into it, the kit removes the dialog's `aria-hidden` attribute.
|
|
318
|
+
- On close, the kit closes the dialog with no attribute and then writes the latest value. A signal that the native close sends synchronously, before that write, counts.
|
|
319
|
+
- While the dialog is closed, a signal stores the value for the next close or for disposal. The kit does not write to the closed dialog.
|
|
320
|
+
- A direct write to the attribute never replaces a signaled value.
|
|
321
|
+
- A temporary unmount, such as StrictMode's effect replay, keeps the registration. On final disposal of the provider or of the channel, the kit retires the signal before any callback runs. The kit then writes the last value to the old dialog, removes what it owns, and calls the adapter's cleanup once.
|
|
322
|
+
|
|
323
|
+
### Without an adapter
|
|
324
|
+
|
|
325
|
+
The kit records the attribute's value before it opens and watches later writes to the attribute. On close, the kit restores the value it saw last.
|
|
326
|
+
|
|
327
|
+
One case goes wrong. If the host set `"true"` before the kit opened or while it was open, the host's later removal can come after the attribute is already gone. That removal changes nothing, so the kit does not see it and restores the old `"true"`. To get no attribute through this path, write `"false"` and then remove the attribute in the same synchronous block. If the kit's observer runs between the two writes, the kit restores `"false"`.
|
|
328
|
+
|
|
329
|
+
### Host requirements and limits
|
|
330
|
+
|
|
331
|
+
The kit changes only the `aria-hidden` attribute of its own dialog. The dialog and its iframe stay in the page for the provider's lifetime. The kit does not change siblings or ancestors.
|
|
332
|
+
|
|
333
|
+
Your modal manager must:
|
|
334
|
+
|
|
335
|
+
- leave the presenting kit dialog out of its own `aria-hidden` writes, or send those changes through the adapter;
|
|
336
|
+
- pause its focus trap while `usePaySnapshot().overlayOpen` is `true`.
|
|
337
|
+
|
|
338
|
+
The kit does not support `aria-hidden` on an ancestor of its dialog, `inert` on its dialog, a focus trap that does not pause, or repeated competing writes.
|
|
339
|
+
|
|
340
|
+
No modal library or library version is tested yet, and no native accessibility behavior is verified. Chrome focus, the accessibility tree, screen readers, background isolation, zoom, and scrolling need separate checks. Other browsers are not covered yet.
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { PayDiagnosticsDisconnectTarget, PayDisconnectOptions, PayFundOptions, PayFundStartScreen } from "./channel/types.js";
|
|
2
|
+
import { PayAccount, PayAccountStatus, PayKeypairState, PayTransport } from "./hooks/types.js";
|
|
3
|
+
import { usePayAccount } from "./hooks/usePayAccount.js";
|
|
4
|
+
export { type PayAccount, type PayAccountStatus, type PayDiagnosticsDisconnectTarget, type PayDisconnectOptions, type PayFundOptions, type PayFundStartScreen, type PayKeypairState, type PayTransport, usePayAccount };
|
package/dist/account.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{usePayAccount as e}from"./hooks/usePayAccount.js";export{e as usePayAccount};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{PayError as e}from"../errors/PayError.js";import{createIframeTransport as t}from"./iframeTransport.js";import{createPopupTransport as n}from"./popupTransport.js";import{APP_ID_PATTERN as r,HUB_NEEDS_POPUP_MESSAGE as i,MAX_MESSAGE_ID_LENGTH as a,MAX_SIGN_MESSAGE_BYTES as o,PAY_FUND_MESSAGE_TYPES as s,PAY_FUND_REQUEST_TYPE as c,PAY_FUND_START_SCREENS as l,PAY_PROTOCOL as u,SUA_PROTOCOL_VERSION as d,decodeHubFrameAppMessage as f,decodeHubMessage as p,isSignText as m}from"@stridge/pay-sdk";const h=3e4;function g(e,t){if(typeof e!=`object`||!e)throw TypeError(`${t}: appearance must be an object`);let{theme:n}=e;if(n!==`dark`&&n!==`light`)throw TypeError(`${t}: appearance.theme must be "dark" or "light"`);return{theme:n}}function _(e){let t;try{t=new URL(e)}catch{throw TypeError(`createAppChannel: hubUrl must be an absolute URL`)}if(t.protocol!==`https:`&&t.protocol!==`http:`)throw TypeError(`createAppChannel: hubUrl must use https: or http:`);return t.origin}function v(e){if(e===void 0)return l.fund;if(typeof e!=`object`||!e)throw TypeError(`fund: options must be an object`);let{start:t}=e;if(t===void 0)return l.fund;if(t!==l.fund&&t!==l.home)throw TypeError(`fund: start must be "fund" or "home"`);return t}function y(e,t){return e.connection===t.connection&&e.connectionError===t.connectionError&&e.hub===t.hub&&e.hubActivity===t.hubActivity&&e.overlayOpen===t.overlayOpen&&e.pending===t.pending&&e.currentTransport===t.currentTransport&&e.diagnostics===t.diagnostics}function b(e,t){return x(e,t)}function x(l,b){if(typeof l!=`object`||!l)throw TypeError(`createAppChannel: options must be an object`);let x=l.hubUrl;if(typeof x!=`string`)throw TypeError(`createAppChannel: hubUrl must be a string`);let S=_(x);if(typeof l.appId!=`string`||!r.test(l.appId))throw TypeError(`createAppChannel: appId must be an app id (app_ and a 26-character uppercase ULID)`);let C=l.appId,w=g(l.appearance,`createAppChannel`),T=l.title??`Stridge Wallet`,E=l.handshakeTimeoutMs??1e4,D=l.createId??(()=>crypto.randomUUID()),O=new Set;function k(){let e=D();return O.add(e),e}let A={connection:`idle`,connectionError:null,hub:null,hubActivity:null,overlayOpen:!1,pending:null,currentTransport:null},j=A,M=new Set,N=!1,P=!1,F=null,I=0,L=null,R=null,z=null;function B(e){let t={...j,...e};if(!y(t,j)){j=t;for(let e of M)e()}}function V(e,t){return t!==null&&e.source!==null&&e.source===t&&e.origin===S}function H(e){let t=L;if(t!==null){L=null,t.receiptTimer!==void 0&&clearTimeout(t.receiptTimer);try{B({pending:null})}finally{t.reject(e)}}}let U={hubUrl:x,hubOrigin:S,appId:C,handshakeTimeoutMs:E,appearance:()=>w,createId:k,createMenuId(){let e=D();return typeof e!=`string`||e.length===0||e.length>a||O.has(e)?null:(O.add(e),e)},getSnapshot:()=>j,update(e){e.connection===`connecting`||e.connection===`failed`||e.connection===`idle`?B({...e,currentTransport:null,...j.diagnostics===void 0?{}:{diagnostics:{state:j.diagnostics.state===`off`?`off`:`waiting`}}}):B(e)},post(e,t,n,r){try{e.postMessage({protocol:u,version:d,id:t,type:n,payload:r},S)}catch{return!1}let i=L;return i!==null&&i.id===t&&i.type===c&&(i.postedTo=e,W(i)),!0},accept(e,t){return N||!V(e,t)?null:p(e.data)??null},acceptFrame(e,t){if(N||!V(e,t))return null;let n=f(e.data);return N||!V(e,t)?null:n??null},inflight(e){return L!==null&&L.route===e?L:null},settle(t,n){if(n.id===R&&n.payload.request===c){R=null;return}let r=L;if(r===null||r.route!==t||!r.posted||r.id!==n.id||r.type!==n.payload.request)return;if(L=null,r.receiptTimer!==void 0&&clearTimeout(r.receiptTimer),n.type===`result`){B({pending:null}),r.resolve(n.payload);return}let{code:a,message:o,retryAfterSeconds:s}=n.payload;B(r.diagnosticsTarget===void 0&&t===`iframe`&&a===`internal`&&o===i?{pending:null,currentTransport:`popup`}:{pending:null}),r.reject(new e(a,o,s))},fail(e,t){L!==null&&L.route===e&&H(t)},receipt(e,t){let n=L;n===null||n.id!==t||n.route!==e||!n.posted||n.type!==c||(n.receiptTimer!==void 0&&clearTimeout(n.receiptTimer),n.receiptTimer=void 0,n.received=!0)},suppressFundOverlay:()=>R!==null,restartIframe(e){R=null;let t=L!==null&&L.route===`iframe`?L:null;t!==null&&(L=null,t.receiptTimer!==void 0&&clearTimeout(t.receiptTimer));try{B({connection:`connecting`,currentTransport:null,hub:null,hubActivity:null,...j.diagnostics===void 0?{}:{diagnostics:{state:j.diagnostics.state===`off`?`off`:`waiting`}},...t===null?{}:{pending:null}})}finally{t?.reject(e)}}};function W(t){t.received||t.receiptTimer!==void 0||(t.receiptTimer=setTimeout(()=>{if(L!==t)return;R=t.id;let n=t.postedTo;H(new e(`unavailable`,`The hub did not open Fund in time; it may predate the fund request`)),n!==void 0&&U.post(n,t.id,s.cancel,{})},h))}let G=t(U,T,b?.dialogAriaHiddenIntent),K=n(U);b?.bindDiagnostics?.({setEnabled(e){!N&&!P&&G.setDiagnosticsEnabled(e)}}),b?.bindMenu?.({showMenu(t,n,r){return N||P?Promise.reject(new e(`cancelled`,`The hub is not mounted`)):G.showMenu(t,n,r)}});function q(t,n,r,i){if(N||P)return Promise.reject(new e(`cancelled`,`The hub is not mounted`));let a=G.frame;if(G.reconcilePresentation(),G.frame!==a)return Promise.reject(new e(`cancelled`,`The hub mount changed during admission`));if(N||P||G.frame===null||z===null)return Promise.reject(new e(`cancelled`,`The hub is not mounted`));if(G.presentationLost)return Promise.reject(new e(`unavailable`,`The browser closed the Stridge dialog`));if(L!==null)return Promise.reject(new e(`busy`,`Another request is in progress`));if(R!==null)return Promise.reject(new e(`unavailable`,`The hub has not retired the timed-out Fund request`));let o=j.currentTransport===`overlay`?`iframe`:`popup`;if(o===`iframe`&&j.connection===`failed`)return Promise.reject(new e(`unavailable`,`The hub did not complete the handshake`));if(i!==void 0&&!G.canDisconnect(i))return Promise.reject(new e(`unavailable`,`The diagnostics disconnect target is unavailable or changed`));let s=z,c=I;return new Promise((l,u)=>{let d={id:``,type:t,payload:n,route:o,posted:!1,...i===void 0?{}:{diagnosticsTarget:i},resolve:e=>l(r(e)),reject:u};L=d;let f=()=>L===d&&!N&&!P&&I===c&&G.frame===a&&z===s;try{if(d.id=k(),!f())return;if(o===`popup`&&!K.open(s)){f()&&H(new e(`popup-blocked`,`The browser blocked the Stridge window`));return}if(!f())return;i!==void 0&&(d.receiptTimer=setTimeout(()=>{if(!f())return;let t=j.diagnostics;H(new e(`unavailable`,`Disconnect this app outcome is unknown; observe current app status`)),j.diagnostics===t&&t?.state===`ready`&&B({diagnostics:{...t,details:{state:`unavailable`}}})},1e4)),B({pending:t}),f()&&o===`iframe`&&G.send()}catch(e){if(L===d){L=null,d.receiptTimer!==void 0&&clearTimeout(d.receiptTimer);try{B({pending:null})}finally{u(e)}}}})}function J(){if(P)return;R=null,P=!0,I+=1,z=null;let t=[];try{for(let n of[()=>G.unmount(),()=>K.close(),()=>H(new e(`cancelled`,`The hub was unmounted`)),()=>B({...A,...j.diagnostics===void 0?{}:{diagnostics:{state:j.diagnostics.state===`off`?`off`:`waiting`}}})])try{n()}catch(e){t.push(e)}}finally{if(N){M.clear();let e=F;F=null;try{e?.()}catch(e){t.push(e)}}P=!1}if(t.length>0)throw t[0]}return{hubOrigin:S,get iframe(){return G.frame},getSnapshot(){return j},subscribe(e){return M.add(e),()=>{M.delete(e)}},mount(e){if(N)throw Error(`createAppChannel: mount() after dispose()`);if(P)throw Error(`createAppChannel: mount() during unmount()`);if(G.frame!==null)return G.frame;let t=++I,n=()=>{if(N||P||t!==I)throw Error(`createAppChannel: mount() ended during a lifecycle callback`)},r=l.document??globalThis.document,i=l.window??globalThis.window;z=i;let a=G.mount(e,r,i);return n(),a},unmount:J,setAppearance(e){w=g(e,`setAppearance`),G.sendAppearance(),K.sendAppearance()},signIn(){return q(`sign-in`,{},e=>({evmAddress:e.request===`sign-in`?e.evmAddress:``}))},sign(e){return m(e)?q(`sign`,{message:e},e=>e.request===`sign`?e.signature:``):Promise.reject(TypeError(`sign: message must be a non-empty string of at most ${o} UTF-8 bytes`))},signOut(){return q(`sign-out`,{},()=>void 0)},disconnect(t){if(t===void 0)return q(`disconnect`,{},()=>void 0);let n;try{n=Object.freeze({subscriptionId:t.diagnosticsTarget.subscriptionId,targetId:t.diagnosticsTarget.targetId})}catch{return Promise.reject(new e(`unavailable`,`The diagnostics disconnect target cannot be read`))}return q(`disconnect`,{},()=>void 0,n)},fund(e){let t;try{t=v(e)}catch(e){return Promise.reject(e)}return q(c,{start:t},()=>void 0)},dispose(){N||(N=!0,I+=1,z=null,F=b?.disposalBridge.begin()??null,J())}}}export{h as FUND_RECEIPT_TIMEOUT_MS,b as createProviderChannel};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e){if(e!==null&&e!==`false`&&e!==`true`)throw TypeError(`PayProvider: dialog aria-hidden intent must be null, "false" or "true"`)}function t(t){let n=null,r=!1,i=!1,a=!1,o=null,s=t=>i?!1:(e(t),n=Object.freeze({value:t,revision:(n?.revision??0)+1}),!0);function c(){i=!0,a=!1}function l(){c();let e=o;o=null,e?.()}return{getSnapshot:()=>n,retire:c,cleanup:l,activate(e){if(i)throw Error(`PayProvider: dialog intent lifetime already ended`);if(!r){r=!0,a=!0;try{let e=t(e=>{if(!a||n!==null)throw Error(`PayProvider: register dialog intent exactly once during adapter setup`);return s(e),s});if(a=!1,typeof e!=`function`)throw TypeError(`PayProvider: dialogAriaHiddenAdapter must return a cleanup function`);if(o=e,n===null)throw TypeError(`PayProvider: dialogAriaHiddenAdapter must register an initial intent`);if(i)throw l(),Error(`PayProvider: dialog intent lifetime ended during setup`)}catch(t){c();try{e?.()}catch{}try{l()}catch{}throw t}finally{a=!1}}}}}export{t as createDialogAriaHiddenIntent};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createScrollLock as e}from"./createScrollLock.js";const t=`data-stridge-pay-hub-dialog`,n=[[`position`,`fixed`],[`inset`,`0`],[`inline-size`,`100%`],[`block-size`,`100%`],[`max-inline-size`,`none`],[`max-block-size`,`none`],[`margin`,`0`],[`padding`,`0`],[`border`,`0`],[`background`,`transparent`],[`overflow`,`hidden`],[`z-index`,`2147483647`]],r=`dialog[${t}]::backdrop { background: transparent !important; }`,i=`aria-hidden`;function a(e,t,n){let r=null,a=null,o=0,s=0;function c(t){t.forEach((n,r)=>{let s=r+1<t.length?t[r+1]?.oldValue??null:e.getAttribute(i);if(s!==null){a=s;return}if(o>0){--o;return}a=null})}function l(){e.hasAttribute(i)&&(o+=1,e.removeAttribute(i))}function u(){s+=1;let e=r;r=null,e!==null&&(n===void 0&&c(e.takeRecords()),e.disconnect()),o=0}function d(){let t=n===void 0?a:n.getSnapshot()?.value??null;t===null?e.removeAttribute(i):e.setAttribute(i,t)}return{suspend:u,restore:d,ensureAbsent:()=>{n!==void 0&&l()},start(){if(n!==void 0&&n.getSnapshot()===null)throw Error(`PayProvider: dialog intent must register before presentation`);let u=++s;n===void 0&&(a=e.getAttribute(i)),e.removeAttribute(i),o=0,t!==void 0&&(r=new t(e=>{u===s&&(n===void 0&&c(e),l())}),r.observe(e,{attributes:!0,attributeFilter:[i],attributeOldValue:!0}))},stop(){u(),d()}}}function o(e){try{return e.matches(`:modal`)}catch{return!1}}function s(i){let{document:s,frame:c,onPresentationLost:l}=i,u=s.defaultView,d=s.createElement(`dialog`);d.setAttribute(t,``),d.setAttribute(`closedby`,`none`);for(let[e,t]of n)d.style.setProperty(e,t,`important`);let f=s.createElement(`style`);f.textContent=r,d.append(f,c);let p=e(s),m=a(d,u?.MutationObserver,i.dialogAriaHiddenIntent),h=!1,g=!1,_=!1,v=0,y=0,b=null,x=null,S=null;function C(){return typeof d.showModal==`function`&&typeof d.close==`function`}function w(e){if(!e.isConnected||e.ownerDocument!==s||d.contains(e)||typeof e.focus!=`function`||e.closest(`[inert], [hidden]`)!==null||e.disabled===!0)return!1;let t=e.closest(`dialog`);return!(t!==null&&!t.open)}function T(e){return e.focus({preventScroll:!0}),s.activeElement===e}function E(){let e=S;e!==null&&(S=null,e.removeEventListener(`blur`,E),e.getAttribute(`tabindex`)===`-1`&&e.removeAttribute(`tabindex`))}function D(){let e=s.body;e!==null&&(e.hasAttribute(`tabindex`)||(e.setAttribute(`tabindex`,`-1`),S=e,e.addEventListener(`blur`,E)),e.focus({preventScroll:!0}))}function O(e,t,n){if(e!==null&&w(e)&&T(e)||n!==v||!k())return;let r=[...s.querySelectorAll(`dialog[open]`)].filter(e=>e!==d&&o(e));t!==null&&t.isConnected&&t.open&&r.unshift(t);for(let e of new Set(r))for(let t of e.querySelectorAll(`a[href], button, input, select, textarea, summary, iframe, [contenteditable=""], [contenteditable="true"], [tabindex]`))if(n!==v||!k()||t.getAttribute(`tabindex`)!==`-1`&&w(t)&&T(t))return;n===v&&k()&&D()}function k(){let e=s.activeElement;return s.hasFocus()&&(e===null||e===s.body||d.contains(e))}function A(e,t,n=!1){let r=++v;h=!1;let a=b,o=x;b=null,x=null;let s=[],c=e=>{try{e()}catch(e){s.push(e)}};if(c(()=>i.dialogAriaHiddenIntent===void 0?m.stop():m.suspend()),c(()=>p.unlock()),c(E),n&&(c(()=>m.ensureAbsent()),c(F)),r===v&&i.dialogAriaHiddenIntent!==void 0&&c(()=>m.restore()),r===v&&t!==void 0&&c(()=>l(t)),r===v&&e&&k()&&c(()=>O(a,o,r)),s.length>0)throw s[0]}function j(e){g||_||(_=!0,A(k(),e,e===`open-failed`))}function M(){h&&!d.open&&j(`native-close`)}function N(e){e.preventDefault()}function P(){if(y>0){--y;return}h&&j(`native-close`)}d.addEventListener(`cancel`,N),d.addEventListener(`close`,P);function F(){if(d.open){if(C()){y+=1,d.close();return}d.removeAttribute(`open`)}}return{dialog:d,get isOpen(){return h},reconcile:M,open(){if(M(),g||_)return!1;if(h)return!0;E();let e=s.activeElement,t=e!==null&&e!==s.body&&!d.contains(e)?e:null,n=++v;h=!0,b=t,x=t?.closest(`dialog[open]`)??null,m.start(),p.lock();try{C()?d.showModal():d.setAttribute(`open`,``)}catch{return n===v&&j(`open-failed`),!1}return n!==v||(M(),!h)?!1:(m.ensureAbsent(),c.focus({preventScroll:!0}),M(),h&&n===v)},close(){M(),h&&A(k(),void 0,!0)},dispose(){if(g)return;g=!0,v+=1;let e=[],t=t=>{try{t()}catch(t){e.push(t)}};if(h?t(()=>A(k(),void 0,!0)):(t(()=>m.suspend()),t(()=>p.unlock()),i.dialogAriaHiddenIntent!==void 0&&t(()=>m.restore())),t(()=>d.removeEventListener(`cancel`,N)),t(()=>d.removeEventListener(`close`,P)),t(E),t(()=>d.remove()),e.length>0)throw e[0]}}}export{s as createDialogHost};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=`data-stridge-pay-scroll-lock`;function t(e){return e.replace(/["\\\n]/g,e=>e===`
|
|
2
|
+
`?`\\a `:`\\${e}`)}function n(n,r=()=>crypto.randomUUID()){let i=null,a=null;return{get locked(){return i!==null},lock(){if(i!==null)return;let o=r(),s=n.createElement(`style`);s.textContent=`:root[${e}="${t(o)}"] { overflow: hidden !important; }`,(n.head??n.documentElement).appendChild(s),n.documentElement.setAttribute(e,o),i=s,a=o},unlock(){i!==null&&(i.remove(),i=null,n.documentElement.getAttribute(`data-stridge-pay-scroll-lock`)===a&&n.documentElement.removeAttribute(e),a=null)}}}export{e as SCROLL_LOCK_ATTRIBUTE,n as createScrollLock};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{PayError as e}from"../errors/PayError.js";import{buildHubFrameUrl as t,createHubFrameName as n}from"../shared/presentation/hubWindow.js";import{createDialogHost as r}from"./createDialogHost.js";import{applyIframePresentation as i}from"./presentation.js";import{PAY_FUND_MESSAGE_TYPES as a,PAY_HUB_FRAME_MESSAGE_TYPES as o,createPayEnvelope as s,isAppHubFrameMessage as c}from"@stridge/pay-sdk";const l=1e4;function u(e,t,n){if(e===`timeout`)return`no answer to init within ${t} ms (is the hub running, and does its frame-ancestors list this origin?)`;let r=n===``?``:`: ${n}`;return e===`app-suspended`?`init refused with app-suspended (is this app id registered for this origin?)${r}`:`init refused with ${e}${r}`}function d(d,f,p){let m=null,h=null,g=null,_=null,v=new Set,y=!1,b=!1,x=0,S=0,C=new Set,w=null,T=null,E=!1,D=0,O=null;function k(e){let t=O;if(O=null,t!==null&&(t.timer!==null&&clearTimeout(t.timer),t.timer=null,t.detailsTimer!==null&&clearTimeout(t.detailsTimer),t.detailsTimer=null,e&&G(t.frame))){let e=d.createMenuId();e!==null&&G(t.frame)&&d.post(t.target,e,o.diagnosticsUnsubscribe,{subscriptionId:t.id})}}function A(e){return E&&O===e&&G(e.frame)&&e.frame.contentWindow===e.target&&d.getSnapshot().connection===`ready`}function j(){let e=m;if(!E||O!==null||e===null||!G(e)||d.getSnapshot().connection!==`ready`)return;let t=e.contentWindow,n=d.createMenuId();if(t===null||n===null||!E||O!==null||!G(e)||e.contentWindow!==t||d.getSnapshot().connection!==`ready`)return;let r={id:n,frame:e,target:t,sequence:-1,detailsSequence:-1,inspected:!1,detailsTimer:null,consumedTargets:new Set,timer:null};O=r,d.update({diagnostics:{state:`waiting`}}),A(r)&&(r.timer=setTimeout(()=>{r.timer=null,A(r)&&d.update({diagnostics:{state:`unsupported`}})},2e3),d.post(t,n,o.diagnosticsSubscribe,{}))}function M(e){let t=O;if(t===null||!A(t))return;let n=e.payload,{subscriptionId:r,sequence:i,observedAt:a}=n;if(e.id!==t.id||r!==t.id||i<=t.sequence)return;let s=d.getSnapshot().diagnostics,c=n.state===`disabled`?{state:`disabled`}:{state:`ready`,phase:n.phase,hubStatus:n.hubStatus,session:n.session,storage:n.storage,source:n.source,sequence:i,observedAt:a,details:s?.state===`ready`&&n.phase===`connected`&&n.storage===`unpartitioned`&&n.hubStatus===s.hubStatus?s.details:{state:`waiting`}};if(!A(t))return;if(t.sequence=i,t.timer!==null&&clearTimeout(t.timer),t.timer=null,d.update({diagnostics:c}),n.state===`disabled`){t.detailsTimer!==null&&clearTimeout(t.detailsTimer),t.detailsTimer=null;return}if(!A(t)||t.inspected)return;t.inspected=!0,t.detailsTimer=setTimeout(()=>{t.detailsTimer=null;let e=d.getSnapshot().diagnostics;A(t)&&e?.state===`ready`&&d.update({diagnostics:{...e,details:{state:`unsupported`}}})},2e3);let l=d.createMenuId();l!==null&&A(t)&&d.post(t.target,l,o.diagnosticsInspect,{subscriptionId:t.id})}function N(e){let t=O,n=d.getSnapshot().diagnostics;if(t===null||!t.inspected||!A(t)||n?.state!==`ready`||e.id!==t.id||e.payload.subscriptionId!==t.id||e.payload.sequence<=t.detailsSequence||e.payload.state===`available`&&(n.phase!==`connected`||n.storage!==`unpartitioned`))return;t.detailsSequence=e.payload.sequence,t.detailsTimer!==null&&clearTimeout(t.detailsTimer),t.detailsTimer=null;let r=e.payload,i=r.state===`withheld`?{...r}:{...r,heldKey:{...r.heldKey},sessionRead:{...r.sessionRead},disconnect:r.disconnect===null?null:{...r.disconnect}};A(t)&&d.update({diagnostics:{...n,details:i}})}function P(e){let t=O,n=d.getSnapshot(),r=n.diagnostics?.state===`ready`?n.diagnostics.details:void 0;return t!==null&&A(t)&&t.frame.isConnected&&!b&&e.subscriptionId===t.id&&!t.consumedTargets.has(e.targetId)&&n.currentTransport===`overlay`&&n.diagnostics?.state===`ready`&&n.diagnostics.phase===`connected`&&n.diagnostics.storage===`unpartitioned`&&r?.state===`available`&&r.disconnect?.targetId===e.targetId}function F(e,t=!1){if(w===e){w=null,T=null,C.has(e)||z(e);try{e.completion?.onEnd(t)}catch{}}}function I(e){return w===e&&e.generation===S&&e.frame===m&&e.frame.isConnected&&!e.signal.aborted&&!b&&d.getSnapshot().connection===`ready`}function L(e){let t=e.completion?.element;return t!==void 0&&t.isConnected&&t.ownerDocument===m?.ownerDocument&&t.ownerDocument.activeElement===t}function R(e){let t=w;if(t===null||t.id!==e.id||!t.posted)return;let n=T;F(t,e.payload.restoreFocus&&n?.owner===t&&n.id===e.payload.closeId&&n.revision===x&&_!==null&&!_.dialog.open&&!d.getSnapshot().overlayOpen&&I(t)&&L(t))}function z(e){e.timer!==null&&clearTimeout(e.timer),e.timer=null,e.signal.removeEventListener(`abort`,e.abort)}function B(e,t){if(!C.delete(e)){t!==void 0&&F(e);return}e.timer!==null&&clearTimeout(e.timer),e.timer=null,(t!==void 0||w!==e)&&z(e),t===void 0?e.resolve():(F(e),e.reject(t))}function V(e){S+=1;let t=new Set(C),n=w;return n!==null&&t.add(n),w=null,T=null,C.clear(),()=>{for(let n of t)z(n),n.reject(e);try{n?.completion?.onEnd(!1)}catch{}}}function H(e){return C.has(e)&&e.generation===S&&e.frame===m&&e.frame.isConnected&&!e.signal.aborted&&d.getSnapshot().connection===`ready`}function U(t,n,r){if(n.aborted)return Promise.reject(new e(`cancelled`,`The menu request was cancelled`));let i=m;if(i===null||!i.isConnected||b||d.getSnapshot().connection!==`ready`)return i!==null&&!i.isConnected&&V(new e(`unavailable`,`The hub frame was removed`))(),Promise.reject(new e(`unavailable`,`The hub frame is unavailable for menus`));let a=S,u;try{if(u=Object.freeze({...t}),!c(s(`menu`,o.showMenu,{anchor:u})))return Promise.reject(new e(`unavailable`,`The menu anchor is invalid`))}catch{return Promise.reject(new e(`unavailable`,`The menu anchor cannot be read`))}return a!==S||m!==i||!i.isConnected||n.aborted||d.getSnapshot().connection!==`ready`?Promise.reject(new e(`cancelled`,`The menu owner changed during admission`)):new Promise((t,s)=>{let c={completion:r,id:``,frame:i,generation:a,posted:!1,signal:n,abort:()=>B(c,new e(`cancelled`,`The menu request was cancelled`)),timer:null,resolve:t,reject:s},f=w;if(w=c,T=null,C.add(c),f!==null){C.has(f)||z(f);try{f.completion?.onEnd(!1)}catch{}}if(w!==c||!H(c)){B(c,new e(`cancelled`,`The menu admission was superseded`));return}n.addEventListener(`abort`,c.abort,{once:!0}),c.timer=setTimeout(()=>B(c,new e(`unavailable`,`No menu reply within ${l} ms`)),l);try{let t=d.createMenuId();if(!H(c)){B(c,new e(`cancelled`,`The menu owner changed while allocating its id`));return}if(t===null){B(c,new e(`unavailable`,`A fresh menu id could not be reserved`));return}c.id=t;let n=i.contentWindow;if(!H(c)||n===null){B(c,new e(`unavailable`,`The hub frame cannot receive menus`));return}c.posted=!0;let r=d.post(n,t,o.showMenu,{anchor:u});C.has(c)&&(!r||!H(c))&&B(c,new e(`unavailable`,`The hub frame could not receive the menu`))}catch{B(c,new e(`unavailable`,`The menu request could not be posted`))}})}function W(t){if(m!==null&&!m.isConnected){V(new e(`unavailable`,`The hub frame was removed`))();return}let n=[...C].find(e=>e.posted&&e.id===t.id&&H(e));if(n!==void 0)if(t.type===o.menuAccepted)B(n);else{let{code:r,message:i,retryAfterSeconds:a}=t.payload;B(n,new e(r,i,a))}}function G(e){return e!==null&&e===m}function K(e,t,n){let r=m?.contentWindow;return r!=null&&d.post(r,e,t,n)}function q(){g!==null&&(clearTimeout(g),g=null)}function J(t,n=``){let r=m;if(!G(r))return;q(),k(!1);let i=V(new e(`unavailable`,`The hub did not complete the handshake`));try{d.update({connection:`failed`,connectionError:t,hubActivity:null})}finally{i()}if(!G(r))return;y||(y=!0,console.warn(`[pay-kit] The Stridge hub at ${d.hubOrigin} did not complete the handshake for app ${d.appId}: ${u(t,d.handshakeTimeoutMs,n)}.`));let a=d.inflight(`iframe`);a!==null&&!a.posted&&d.fail(`iframe`,new e(`unavailable`,`The hub did not complete the handshake`))}function Y(){let e=m;G(e)&&(q(),g=setTimeout(()=>{G(e)&&(g=null,d.getSnapshot().connection===`connecting`&&J(`timeout`))},d.handshakeTimeoutMs))}function X(){let t=d.inflight(`iframe`);if(t===null||t.posted||d.getSnapshot().connection!==`ready`)return;let n=t.diagnosticsTarget;if(n!==void 0&&!P(n)){d.fail(`iframe`,new e(`unavailable`,`The diagnostics disconnect target is unavailable or changed`));return}t.posted=!0,n!==void 0&&O?.consumedTargets.add(n.targetId),(n===void 0?K(t.id,t.type,t.payload):K(t.id,o.diagnosticsDisconnect,{subscriptionId:n.subscriptionId,targetId:n.targetId}))||d.fail(`iframe`,new e(`unavailable`,`The hub frame cannot receive messages`))}function Z(e,t){let n=w,r=_?.dialog.open===!0;T=null;let a=++x,s=m,c=_;if(!e){if(c?.close(),a!==x)return;s!==null&&i(s,`hidden`),d.update({overlayOpen:!1}),t!==void 0&&r&&n!==null&&c!==null&&c===_&&s===m&&a===x&&!c.dialog.open&&!d.getSnapshot().overlayOpen&&I(n)&&L(n)&&(T={owner:n,id:t,revision:a}),t!==void 0&&r&&s!==null&&c!==null&&s===m&&c===_&&a===x&&!c.dialog.open&&!d.getSnapshot().overlayOpen&&K(t,o.overlayHidden,{});return}if(s===null||c===null||b||(d.update({overlayOpen:!0}),a!==x))return;i(s,`overlay`);let l=c.open();a===x&&(l||(i(s,`hidden`),d.update({overlayOpen:!1})))}function Q(t){let n=m,r=!b;b=!0;let a=V(new e(`unavailable`,`The menu presentation was lost`));x+=1,m!==null&&i(m,`hidden`);try{d.update({overlayOpen:!1})}finally{a()}G(n)&&r&&console.warn(`[pay-kit] The browser ${t===`native-close`?`closed the Stridge dialog without the hub`:`could not show the Stridge dialog`} for app ${d.appId}; Stridge stays unavailable on this page until PayProvider mounts again.`)}function ee(){let t=m;if(!G(t))return;let n=d.getSnapshot().connection;if(n===`ready`){k(!1);let n=new e(`unavailable`,`The hub reloaded`),r=V(n);try{d.restartIframe(n)}finally{r()}if(!G(t)||(Z(!1),!G(t)))return;Y()}else if(n===`failed`){if(d.update({connection:`connecting`,connectionError:null,hubActivity:null}),!G(t))return;Y()}let r=d.createId();G(t)&&(v.add(r),K(r,`init`,{appId:d.appId,appearance:d.appearance()}))}function te(e){let t=m;switch(e.type){case`ready`:ee();return;case`transport`:d.update({currentTransport:e.payload.mode});return;case`state`:{let t=d.getSnapshot().diagnostics;d.update({hub:{...e.payload},...e.payload.status!==`signed-in`&&t?.state===`ready`&&t.details?.state===`available`?{diagnostics:{...t,details:{state:`waiting`}}}:{}});return}case`overlay-open`:if(d.suppressFundOverlay())return;Z(!0);return;case a.received:d.receipt(`iframe`,e.id);return;case`overlay-close`:Z(!1,e.id);return;case o.menuEnded:R(e);return;case o.diagnosticsDetails:N(e);return;case o.diagnosticsStatus:M(e);return;case o.menuAccepted:case o.menuRefused:W(e);return;case`result`:case`error`:if(e.payload.request!==`init`){d.settle(`iframe`,e);return}if(!v.has(e.id))return;if(e.type===`error`){v.delete(e.id),J(e.payload.code,e.payload.message);return}if(v=new Set,q(),d.update({connection:`ready`}),!G(t)||(X(),!G(t)))return;j();return;case o.activity:d.getSnapshot().connection===`ready`&&d.update({hubActivity:e.payload.pending});return;default:return}}function $(e){if(m===null)return;let t=d.acceptFrame(e,m.contentWindow);t!==null&&te(t)}return{setDiagnosticsEnabled(e){if(E===e&&d.getSnapshot().diagnostics!==void 0)return;let t=++D;E=e,k(!0),t===D&&(d.update({diagnostics:{state:e?`waiting`:`off`}}),e&&E&&j())},get frame(){return m},get presentationLost(){return b},reconcilePresentation(){_?.reconcile()},mount(e,a,o){if(m!==null)return m;let s=a.createElement(`iframe`);s.setAttribute(`allow`,`clipboard-read; clipboard-write`),s.name=n(),s.title=f,s.src=t(d.hubUrl,d.appearance(),d.appId),i(s,`hidden`);let c=r({document:a,frame:s,onPresentationLost:Q,...p===void 0?{}:{dialogAriaHiddenIntent:p}});if(m=s,_=c,b=!1,h=o,o.addEventListener(`message`,$),e.appendChild(c.dialog),!G(s))throw Error(`createAppChannel: mount() ended while attaching the frame`);if(d.update({connection:`connecting`,hubActivity:null}),!G(s))throw Error(`createAppChannel: mount() ended during connection notification`);return Y(),s},unmount(){k(!0);let t=V(new e(`cancelled`,`The hub was unmounted`));x+=1,q(),h!==null&&(h.removeEventListener(`message`,$),h=null);let n=_;_=null,m=null,v=new Set,y=!1,b=!1,t(),n?.dispose()},canDisconnect:P,showMenu:U,send:X,sendAppearance(){d.getSnapshot().connection===`ready`&&K(d.createId(),`appearance`,{appearance:d.appearance()})}}}export{d as createIframeTransport};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{PayError as e}from"../errors/PayError.js";import{buildHubPopupUrl as t,createHubPopupName as n,hubPopupFeatures as r}from"../shared/presentation/hubWindow.js";import{PAY_FUND_MESSAGE_TYPES as i}from"@stridge/pay-sdk";function a(e){try{return e.closed}catch{return null}}function o(o){let s=null,c=null,l=null,u=null,d=null,f=new Set,p=!1,m=!1,h=!1,g=0,_=!1,v=null,y=0,b=null;function x(e,t,n){return y===t&&s===n&&o.inflight(`popup`)===e}function S(e){if(e!==null&&e!==b&&e!==s)try{e.close()}catch{}}function C(){y+=1;let e=c;c=null,s=null,f=new Set,p=!1,m=!1,h=!1,l!==null&&(clearTimeout(l),l=null),u!==null&&(clearInterval(u),u=null),d!==null&&(clearTimeout(d),d=null),e?.removeEventListener(`message`,A)}function w(){let e=s;try{C()}finally{S(e)}}function T(e){let t=o.inflight(`popup`);w(),t!==null&&o.inflight(`popup`)===t&&o.fail(`popup`,e)}function E(e,t,n){return s!==null&&o.post(s,e,t,n)}function D(){let t=s,n=y,r=o.inflight(`popup`);if(m=!0,p&&o.inflight(`popup`)===null&&b!==t){w();return}let i=o.createId();if(y!==n||s!==t||o.inflight(`popup`)!==r)return;let a=o.appearance();if(y!==n||s!==t||o.inflight(`popup`)!==r)return;f.add(i);let c=E(i,`init`,{appId:o.appId,appearance:a});y===n&&s===t&&o.inflight(`popup`)===r&&(c||T(new e(`unavailable`,`The Stridge window cannot receive messages`)))}function O(t){if(!f.has(t.id))return;if(t.type===`error`){let{code:n,message:r,retryAfterSeconds:i}=t.payload;T(new e(n,r,i));return}f=new Set,p=!0;let n=s,r=y,i=o.inflight(`popup`);if(l!==null&&(clearTimeout(l),l=null),h){h=!1;let t=o.createId();if(i===null||!x(i,r,n))return;let a=o.appearance();if(!x(i,r,n))return;let s=E(t,`appearance`,{appearance:a});if(!x(i,r,n))return;if(!s){T(new e(`unavailable`,`The Stridge window cannot receive messages`));return}}if(i===null||i.posted||n===null||!x(i,r,n))return;i.posted=!0,b=n;let a=o.post(n,i.id,i.type,i.payload);x(i,r,n)&&(a||T(new e(`unavailable`,`The Stridge window cannot receive messages`)))}function k(e){switch(e.type){case`ready`:D();return;case`state`:o.update({hub:{...e.payload}});return;case`overlay-open`:return;case i.received:o.receipt(`popup`,e.id);return;case`result`:case`error`:if(e.payload.request===`init`){O(e);return}o.settle(`popup`,e);return;default:return}}function A(e){if(s===null)return;let t=s,n=y,r=o.accept(e,t);r!==null&&y===n&&s===t&&k(r)}function j(){_||(_=!0,console.warn(`[pay-kit] The Stridge window lost its link to this page before the hub at ${o.hubOrigin} loaded, so it cannot answer. This page likely sends "Cross-Origin-Opener-Policy: same-origin", which cuts the link to every window it opens; send "same-origin-allow-popups" instead.`))}function M(){let t=s,n=y;if(t===null||d!==null)return;let r=a(t);if(y!==n||s!==t||r===!1)return;r===!0&&b===t&&(b=null),u!==null&&(clearInterval(u),u=null);let i=!m&&Date.now()-g<=1e3;d=setTimeout(()=>{if(y!==n||s!==t)return;let r=o.inflight(`popup`);if(d=null,C(),r!==null&&o.inflight(`popup`)===r){if(!i){o.fail(`popup`,new e(`cancelled`,`The Stridge window was closed`));return}o.inflight(`popup`)!==null&&j(),o.inflight(`popup`)===r&&o.fail(`popup`,new e(`unavailable`,`The Stridge window lost its link to this page`))}},250)}function N(){l!==null&&clearTimeout(l),l=setTimeout(()=>{l=null,p||T(new e(`unavailable`,`The Stridge window did not complete the handshake`))},o.handshakeTimeoutMs)}function P(t){let n=s,r=y;if(n===null||!p||d!==null)return!1;let i=a(n);if(!x(t,r,n))return!0;if(i!==!1)return!1;let c=o.createId();if(!x(t,r,n))return!0;let l=o.appearance();if(!x(t,r,n))return!0;f=new Set([c]),p=!1,h=!0;let u=o.post(n,c,`init`,{appId:o.appId,appearance:l});if(!x(t,r,n))return!0;if(!u)return T(new e(`unavailable`,`The Stridge window cannot receive messages`)),!0;try{n.focus()}catch{}return x(t,r,n)&&!p&&N(),!0}return{get window(){return s},open(i){let l=o.inflight(`popup`);if(l===null)return!1;let f=y,m=s;if(b!==null){let t=b,n=a(t);if(!x(l,f,m))return!1;if(n===!0)b=null;else if(m!==t||!p||d!==null)throw new e(`unavailable`,`The previous Stridge window still owns posted work`)}if(P(l))return!0;if(!x(l,f,m))return!1;if(b!==null)throw new e(`unavailable`,`The previous Stridge window still owns posted work`);let h=t(o.hubUrl,o.appearance(),o.appId,i.location.origin);if(!x(l,f,m))return!1;let _;try{v??=n();let e=r(i);if(!x(l,f,m))return!1;_=i.open(h,v,e)}catch{_=null}if(_==null||a(_)!==!1)return!1;if(!x(l,f,m)||(C(),o.inflight(`popup`)!==l))return S(_),!1;s=_;let w=y;if(c=i,i.addEventListener(`message`,A),!x(l,w,_))return!1;try{_.focus()}catch{}return x(l,w,_)?(g=Date.now(),N(),u=setInterval(M,250),!0):!1},close:w,sendAppearance(){if(p&&s!==null){let e=s,t=y,n=o.createId();if(y!==t||s!==e)return;let r=o.appearance();y===t&&s===e&&o.post(e,n,`appearance`,{appearance:r})}}}}export{o as createPopupTransport};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e={hidden:[[`position`,`fixed`],[`inset-block-start`,`0`],[`inset-inline-start`,`0`],[`width`,`0`],[`height`,`0`],[`border`,`0`],[`opacity`,`0`],[`pointer-events`,`none`],[`color-scheme`,`light`]],overlay:[[`position`,`fixed`],[`inset`,`0`],[`width`,`100vw`],[`height`,`100dvh`],[`border`,`0`],[`opacity`,`1`],[`pointer-events`,`auto`],[`background`,`transparent`],[`z-index`,`2147483647`],[`color-scheme`,`light`]]},t=[...new Set([...e.hidden,...e.overlay].map(([e])=>e))];function n(n,r){let i=n.style;for(let e of t)i.removeProperty(e);for(let[t,n]of e[r])i.setProperty(t,n,`important`);r===`hidden`?(n.setAttribute(`aria-hidden`,`true`),n.setAttribute(`tabindex`,`-1`)):(n.removeAttribute(`aria-hidden`),n.setAttribute(`tabindex`,`0`))}export{n as applyIframePresentation};
|