@terrawallet/pay-js 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.
- package/LICENSE +202 -0
- package/NOTICE +15 -0
- package/README.md +77 -2
- package/dist/cdn/manifest.json +20 -0
- package/dist/cdn/sbom.cdx.json +50 -0
- package/dist/cdn/terra-pay.esm.js +52 -0
- package/dist/cdn/terra-pay.iife.js +52 -0
- package/dist/cdn-esm.d.ts +2 -0
- package/dist/cdn.d.ts +1 -0
- package/dist/checkout.d.ts +56 -0
- package/dist/dom.d.ts +21 -0
- package/dist/errors.d.ts +14 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +491 -0
- package/dist/protocol.d.ts +43 -0
- package/dist/sbom.cdx.json +26 -0
- package/dist/styles.d.ts +6 -0
- package/package.json +57 -3
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type TerraPayErrorCode = "SECRET_KEY_REFUSED" | "INVALID_PUBLISHABLE_KEY" | "INVALID_CHECKOUT" | "POPUP_BLOCKED" | "UNSUPPORTED_ENVIRONMENT" | "CHECKOUT_ERROR";
|
|
2
|
+
export declare const DOCS_ERRORS_URL = "https://developers.terrawallet.us/docs/errors";
|
|
3
|
+
export declare class TerraPayError extends Error {
|
|
4
|
+
readonly name = "TerraPayError";
|
|
5
|
+
readonly code: TerraPayErrorCode;
|
|
6
|
+
readonly docUrl: string;
|
|
7
|
+
constructor(code: TerraPayErrorCode, message?: string);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Browser code takes publishable keys only. The key is never echoed in errors.
|
|
11
|
+
* - Refused as a secret: `_sk_` anywhere (or `sk_` at the start) and `whsec_` anywhere, case-insensitive.
|
|
12
|
+
* - Accepted: `tw_test_pk_` / `tw_live_pk_` plus base64url (the API mints 43 characters, `-` and `_` included).
|
|
13
|
+
*/
|
|
14
|
+
export declare function assertPublishableKey(key: unknown): asserts key is string;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { openCheckout, type CheckoutHandle, type OpenOptions } from "./checkout.js";
|
|
2
|
+
import { TerraPayError, assertPublishableKey } from "./errors.js";
|
|
3
|
+
import { CHECKOUT_ORIGIN } from "./protocol.js";
|
|
4
|
+
export declare const VERSION: string;
|
|
5
|
+
export type SubscribeOptions = Omit<OpenOptions, "checkoutUrl" | "paymentIntentId" | "planId"> & {
|
|
6
|
+
planId: string;
|
|
7
|
+
};
|
|
8
|
+
export interface ButtonOptions extends Omit<OpenOptions, "theme"> {
|
|
9
|
+
/** Button text. Defaults to "Pay with Terra" or "Subscribe with Terra" for plans. */
|
|
10
|
+
label?: string;
|
|
11
|
+
/** Corner radius in px (0 to 24). */
|
|
12
|
+
radius?: number;
|
|
13
|
+
}
|
|
14
|
+
/** Opens a subscription checkout for a plan (pay.terrawallet.us/s/plan_...). */
|
|
15
|
+
declare function subscribe(opts: SubscribeOptions): CheckoutHandle;
|
|
16
|
+
/**
|
|
17
|
+
* Renders a self-contained Terra Pay button (closed shadow root, so host CSS cannot restyle or hide its text) into
|
|
18
|
+
* `target`. Returns a function that removes it. For a themable button use <terra-pay-button> from the elements
|
|
19
|
+
* package.
|
|
20
|
+
*/
|
|
21
|
+
declare function mountButton(target: Element, opts: ButtonOptions): () => void;
|
|
22
|
+
/** A subscribe button for a plan. */
|
|
23
|
+
declare function mountSubscribeButton(target: Element, opts: Omit<ButtonOptions, "checkoutUrl" | "paymentIntentId"> & {
|
|
24
|
+
planId: string;
|
|
25
|
+
}): () => void;
|
|
26
|
+
export declare const TerraPay: Readonly<{
|
|
27
|
+
open: typeof openCheckout;
|
|
28
|
+
subscribe: typeof subscribe;
|
|
29
|
+
mountButton: typeof mountButton;
|
|
30
|
+
mountSubscribeButton: typeof mountSubscribeButton;
|
|
31
|
+
CHECKOUT_ORIGIN: "https://pay.terrawallet.us";
|
|
32
|
+
VERSION: string;
|
|
33
|
+
}>;
|
|
34
|
+
export { openCheckout, subscribe, mountButton, mountSubscribeButton, CHECKOUT_ORIGIN, TerraPayError, assertPublishableKey };
|
|
35
|
+
export { IFRAME_SANDBOX, DEFAULT_READY_TIMEOUT_MS, type CheckoutHandle, type CheckoutResult, type CheckoutStatus, type OpenOptions } from "./checkout.js";
|
|
36
|
+
export { buildCheckoutUrl, checkoutPath, parseCheckoutMessage, type CheckoutMessage, type CheckoutMode, type CheckoutTarget } from "./protocol.js";
|
|
37
|
+
export type { TerraPayErrorCode } from "./errors.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,491 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
|
|
5
|
+
// src/styles.ts
|
|
6
|
+
var CHECKOUT_CSS = `
|
|
7
|
+
:host{all:initial}
|
|
8
|
+
*{box-sizing:border-box}
|
|
9
|
+
.t{--canvas:#060912;--l1:#0C1322;--l2:#111A2E;--l3:#18233C;--line:rgba(255,255,255,.08);--line2:rgba(255,255,255,.14);--fg:#F5F7FF;--muted:#93A0B8;--brand:#0A5BFF;--brand2:#5B8BFF;--ok:#2ECC71;--shadow:0 16px 48px rgba(0,0,0,.55);color-scheme:dark}
|
|
10
|
+
.t[data-theme=light]{--canvas:#F7F9FC;--l1:#fff;--l2:#F1F4F9;--l3:#E6EBF4;--line:rgba(11,18,33,.08);--line2:rgba(11,18,33,.14);--fg:#0B1221;--muted:#5B6577;--brand2:#0A5BFF;--ok:#13703D;--shadow:0 16px 48px rgba(11,18,33,.18);color-scheme:light}
|
|
11
|
+
@media (prefers-color-scheme:light){.t[data-theme=auto]{--canvas:#F7F9FC;--l1:#fff;--l2:#F1F4F9;--l3:#E6EBF4;--line:rgba(11,18,33,.08);--line2:rgba(11,18,33,.14);--fg:#0B1221;--muted:#5B6577;--brand2:#0A5BFF;--ok:#13703D;--shadow:0 16px 48px rgba(11,18,33,.18);color-scheme:light}}
|
|
12
|
+
dialog{position:fixed;inset:0;margin:0;padding:0;border:0;background:transparent;max-width:none;max-height:none;width:100%;height:100%;overflow:hidden;font:14px/20px Inter,ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;-webkit-font-smoothing:antialiased}
|
|
13
|
+
dialog::backdrop{background:rgba(3,6,14,.62)}
|
|
14
|
+
dialog:not([open]){display:none}
|
|
15
|
+
.scrim{position:absolute;inset:0}
|
|
16
|
+
.panel{position:absolute;left:0;right:0;bottom:0;display:flex;flex-direction:column;height:min(92dvh,92vh);background:var(--l1);color:var(--fg);border-top:1px solid var(--line2);border-radius:24px 24px 0 0;box-shadow:var(--shadow);overflow:hidden;animation:sheet .24s cubic-bezier(.32,.72,0,1)}
|
|
17
|
+
.card{position:absolute;left:16px;right:16px;bottom:16px;padding:20px;background:var(--l1);color:var(--fg);border:1px solid var(--line2);border-radius:24px;box-shadow:var(--shadow);animation:sheet .24s cubic-bezier(.32,.72,0,1)}
|
|
18
|
+
@media (min-width:641px){
|
|
19
|
+
.panel{left:50%;top:50%;bottom:auto;width:440px;height:min(720px,calc(100vh - 48px));border:1px solid var(--line2);border-radius:24px;transform:translate(-50%,-50%);animation:pop .16s ease-out}
|
|
20
|
+
.card{left:50%;top:50%;bottom:auto;right:auto;width:380px;transform:translate(-50%,-50%);animation:pop .16s ease-out}
|
|
21
|
+
}
|
|
22
|
+
.bar{display:flex;align-items:center;gap:10px;padding:12px 12px 12px 16px;border-bottom:1px solid var(--line);background:var(--l1)}
|
|
23
|
+
.lock{display:flex;align-items:center;justify-content:center;width:32px;height:32px;border-radius:10px;background:rgba(46,204,113,.12);color:var(--ok);flex:none}
|
|
24
|
+
.who{display:flex;flex-direction:column;min-width:0;flex:1}
|
|
25
|
+
.who strong{font-size:14px;line-height:18px;font-weight:600}
|
|
26
|
+
.origin{font-size:12px;line-height:16px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
|
|
27
|
+
.x{all:unset;display:flex;align-items:center;justify-content:center;width:36px;height:36px;border-radius:12px;color:var(--muted);cursor:pointer;flex:none}
|
|
28
|
+
.x:hover{background:var(--l2);color:var(--fg)}
|
|
29
|
+
.x:focus-visible,.btn:focus-visible{outline:none;box-shadow:0 0 0 3px rgba(91,139,255,.45)}
|
|
30
|
+
.frame{position:relative;flex:1;background:var(--canvas)}
|
|
31
|
+
iframe{position:absolute;inset:0;width:100%;height:100%;border:0;background:transparent;color-scheme:normal}
|
|
32
|
+
.loading{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:12px;color:var(--muted);font-size:13px}
|
|
33
|
+
.loading[hidden]{display:none}
|
|
34
|
+
.spin{width:28px;height:28px;border-radius:50%;border:2.5px solid var(--line2);border-top-color:var(--brand2);animation:spin .8s linear infinite}
|
|
35
|
+
h2{margin:12px 0 4px;font-size:18px;line-height:24px;font-weight:700;letter-spacing:-.01em}
|
|
36
|
+
p{margin:0;color:var(--muted)}
|
|
37
|
+
.row{display:grid;grid-template-columns:1fr 1fr;gap:8px;margin-top:20px}
|
|
38
|
+
.btn{all:unset;box-sizing:border-box;display:flex;align-items:center;justify-content:center;gap:8px;height:44px;padding:0 16px;border-radius:14px;font-weight:600;font-size:14px;cursor:pointer;text-align:center;transition:transform .15s ease-out,filter .15s ease-out}
|
|
39
|
+
.btn:active{transform:scale(.98)}
|
|
40
|
+
.primary{background:linear-gradient(135deg,#0A5BFF 0%,#5B8BFF 100%);color:#fff;box-shadow:0 8px 22px rgba(10,91,255,.38)}
|
|
41
|
+
.primary:hover{filter:brightness(1.1)}
|
|
42
|
+
.secondary{background:var(--l2);color:var(--fg);border:1px solid var(--line2)}
|
|
43
|
+
.secondary:hover{background:var(--l3)}
|
|
44
|
+
@keyframes sheet{from{transform:translateY(100%)}to{transform:translateY(0)}}
|
|
45
|
+
@keyframes pop{from{opacity:0;transform:translate(-50%,-50%) scale(.96)}to{opacity:1;transform:translate(-50%,-50%) scale(1)}}
|
|
46
|
+
@keyframes spin{to{transform:rotate(360deg)}}
|
|
47
|
+
@media (prefers-reduced-motion:reduce){*{animation-duration:1ms!important;transition-duration:1ms!important}}
|
|
48
|
+
`;
|
|
49
|
+
var BUTTON_CSS = `
|
|
50
|
+
:host{all:initial;display:inline-block;vertical-align:middle}
|
|
51
|
+
*{box-sizing:border-box}
|
|
52
|
+
button{all:unset;box-sizing:border-box;display:inline-flex;align-items:center;justify-content:center;gap:8px;min-height:44px;padding:0 20px;border-radius:var(--terra-radius,14px);font:600 15px/20px Inter,ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;color:#fff;background:linear-gradient(135deg,#0A5BFF 0%,#5B8BFF 100%);box-shadow:0 8px 22px rgba(10,91,255,.32);cursor:pointer;transition:transform .15s ease-out,filter .15s ease-out;-webkit-font-smoothing:antialiased}
|
|
53
|
+
button:hover{filter:brightness(1.1)}
|
|
54
|
+
button:active{transform:scale(.98)}
|
|
55
|
+
button:focus-visible{outline:none;box-shadow:0 0 0 3px rgba(91,139,255,.45)}
|
|
56
|
+
button[disabled]{opacity:.5;cursor:default}
|
|
57
|
+
@media (prefers-reduced-motion:reduce){button{transition:none}}
|
|
58
|
+
`;
|
|
59
|
+
|
|
60
|
+
// src/dom.ts
|
|
61
|
+
function h(tag, attrs = {}, ...children) {
|
|
62
|
+
const el = document.createElement(tag);
|
|
63
|
+
for (const [k, v] of Object.entries(attrs)) if (v !== void 0) el.setAttribute(k, v);
|
|
64
|
+
for (const c of children) if (c !== null && c !== void 0 && c !== false) el.append(c);
|
|
65
|
+
return el;
|
|
66
|
+
}
|
|
67
|
+
var SVG_NS = "http://www.w3.org/2000/svg";
|
|
68
|
+
function icon(paths, size = 20, opts = {}) {
|
|
69
|
+
const svg = document.createElementNS(SVG_NS, "svg");
|
|
70
|
+
svg.setAttribute("viewBox", "0 0 24 24");
|
|
71
|
+
svg.setAttribute("width", String(size));
|
|
72
|
+
svg.setAttribute("height", String(size));
|
|
73
|
+
svg.setAttribute("aria-hidden", "true");
|
|
74
|
+
svg.setAttribute("focusable", "false");
|
|
75
|
+
if (opts.cls) svg.setAttribute("class", opts.cls);
|
|
76
|
+
svg.setAttribute("fill", opts.fill ? "currentColor" : "none");
|
|
77
|
+
if (!opts.fill) {
|
|
78
|
+
svg.setAttribute("stroke", "currentColor");
|
|
79
|
+
svg.setAttribute("stroke-width", "2");
|
|
80
|
+
svg.setAttribute("stroke-linecap", "round");
|
|
81
|
+
svg.setAttribute("stroke-linejoin", "round");
|
|
82
|
+
}
|
|
83
|
+
for (const d of paths) {
|
|
84
|
+
const p = document.createElementNS(SVG_NS, "path");
|
|
85
|
+
p.setAttribute("d", d);
|
|
86
|
+
svg.append(p);
|
|
87
|
+
}
|
|
88
|
+
return svg;
|
|
89
|
+
}
|
|
90
|
+
var ICONS = {
|
|
91
|
+
lock: ["M7 11V8a5 5 0 0 1 10 0v3", "M5 11h14v10H5z"],
|
|
92
|
+
close: ["M18 6 6 18", "M6 6l12 12"],
|
|
93
|
+
external: ["M14 4h6v6", "M20 4 10 14", "M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5"]
|
|
94
|
+
};
|
|
95
|
+
function adoptStyles(root, css) {
|
|
96
|
+
try {
|
|
97
|
+
const sheet = new CSSStyleSheet();
|
|
98
|
+
sheet.replaceSync(css);
|
|
99
|
+
root.adoptedStyleSheets = [...root.adoptedStyleSheets, sheet];
|
|
100
|
+
return;
|
|
101
|
+
} catch {
|
|
102
|
+
}
|
|
103
|
+
const style = document.createElement("style");
|
|
104
|
+
style.textContent = css;
|
|
105
|
+
root.prepend(style);
|
|
106
|
+
}
|
|
107
|
+
var isPhone = () => typeof matchMedia === "function" && matchMedia("(max-width: 640px), (pointer: coarse) and (max-width: 900px)").matches;
|
|
108
|
+
|
|
109
|
+
// src/errors.ts
|
|
110
|
+
var DOCS_ERRORS_URL = "https://developers.terrawallet.us/docs/errors";
|
|
111
|
+
var MESSAGES = {
|
|
112
|
+
SECRET_KEY_REFUSED: "A secret key was passed to browser code and was refused. Use your publishable key (tw_test_pk_ or tw_live_pk_) here, and rotate that secret key in the Terra dashboard now: anything shipped to a browser is public.",
|
|
113
|
+
INVALID_PUBLISHABLE_KEY: "Use a publishable key that starts with tw_test_pk_ or tw_live_pk_.",
|
|
114
|
+
INVALID_CHECKOUT: "Pass a checkout URL on https://pay.terrawallet.us, a payment intent id (pi_...), or a plan id (plan_...).",
|
|
115
|
+
POPUP_BLOCKED: "The browser blocked the checkout window. Open checkout from a click.",
|
|
116
|
+
UNSUPPORTED_ENVIRONMENT: "Terra Pay checkout needs a browser.",
|
|
117
|
+
CHECKOUT_ERROR: "Checkout reported an error."
|
|
118
|
+
};
|
|
119
|
+
var TerraPayError = class extends Error {
|
|
120
|
+
constructor(code, message) {
|
|
121
|
+
super(message || MESSAGES[code]);
|
|
122
|
+
__publicField(this, "name", "TerraPayError");
|
|
123
|
+
__publicField(this, "code");
|
|
124
|
+
__publicField(this, "docUrl");
|
|
125
|
+
this.code = code;
|
|
126
|
+
this.docUrl = `${DOCS_ERRORS_URL}#${code.toLowerCase()}`;
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
function assertPublishableKey(key) {
|
|
130
|
+
if (typeof key === "string" && /(^|_)sk_|whsec_/i.test(key)) throw new TerraPayError("SECRET_KEY_REFUSED");
|
|
131
|
+
if (typeof key !== "string" || !/^tw_(test|live)_pk_[A-Za-z0-9_-]{8,128}$/.test(key)) throw new TerraPayError("INVALID_PUBLISHABLE_KEY");
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// src/protocol.ts
|
|
135
|
+
var CHECKOUT_ORIGIN = "https://pay.terrawallet.us";
|
|
136
|
+
var ID = {
|
|
137
|
+
pi: /^pi_[A-Za-z0-9]{6,64}$/,
|
|
138
|
+
plink: /^plink_[A-Za-z0-9]{6,64}$/,
|
|
139
|
+
inv: /^inv_[A-Za-z0-9]{6,64}$/,
|
|
140
|
+
plan: /^plan_[A-Za-z0-9]{6,64}$/,
|
|
141
|
+
sub: /^sub_[A-Za-z0-9]{6,64}$/
|
|
142
|
+
};
|
|
143
|
+
var PATH_KIND = { c: "pi", l: "plink", i: "inv", s: "plan" };
|
|
144
|
+
function newSessionId() {
|
|
145
|
+
const b = new Uint8Array(16);
|
|
146
|
+
crypto.getRandomValues(b);
|
|
147
|
+
return Array.from(b, (x) => x.toString(16).padStart(2, "0")).join("");
|
|
148
|
+
}
|
|
149
|
+
function checkoutPath(target) {
|
|
150
|
+
const given = [target.checkoutUrl, target.paymentIntentId, target.planId].filter((x) => x !== void 0);
|
|
151
|
+
if (given.length !== 1) throw new TerraPayError("INVALID_CHECKOUT");
|
|
152
|
+
if (target.paymentIntentId !== void 0) {
|
|
153
|
+
if (!ID.pi.test(target.paymentIntentId)) throw new TerraPayError("INVALID_CHECKOUT", "paymentIntentId must look like pi_...");
|
|
154
|
+
return `/c/${target.paymentIntentId}`;
|
|
155
|
+
}
|
|
156
|
+
if (target.planId !== void 0) {
|
|
157
|
+
if (!ID.plan.test(target.planId)) throw new TerraPayError("INVALID_CHECKOUT", "planId must look like plan_...");
|
|
158
|
+
return `/s/${target.planId}`;
|
|
159
|
+
}
|
|
160
|
+
let url;
|
|
161
|
+
try {
|
|
162
|
+
url = new URL(String(target.checkoutUrl));
|
|
163
|
+
} catch {
|
|
164
|
+
throw new TerraPayError("INVALID_CHECKOUT");
|
|
165
|
+
}
|
|
166
|
+
if (url.origin !== CHECKOUT_ORIGIN || url.username || url.password) {
|
|
167
|
+
throw new TerraPayError("INVALID_CHECKOUT", "checkoutUrl must be on https://pay.terrawallet.us.");
|
|
168
|
+
}
|
|
169
|
+
const m = /^\/([clis])\/([A-Za-z0-9_]+)\/?$/.exec(url.pathname);
|
|
170
|
+
const kind = m ? PATH_KIND[m[1]] : void 0;
|
|
171
|
+
if (!m || !kind || !ID[kind].test(m[2])) throw new TerraPayError("INVALID_CHECKOUT", "Unrecognised checkout URL path.");
|
|
172
|
+
return `/${m[1]}/${m[2]}`;
|
|
173
|
+
}
|
|
174
|
+
function buildCheckoutUrl(target, p) {
|
|
175
|
+
const url = new URL(checkoutPath(target), CHECKOUT_ORIGIN);
|
|
176
|
+
url.searchParams.set("embed", p.mode);
|
|
177
|
+
url.searchParams.set("pk", p.publishableKey);
|
|
178
|
+
url.searchParams.set("sid", p.sid);
|
|
179
|
+
url.searchParams.set("origin", p.parentOrigin);
|
|
180
|
+
if (p.theme === "light" || p.theme === "dark") url.searchParams.set("theme", p.theme);
|
|
181
|
+
return url.toString();
|
|
182
|
+
}
|
|
183
|
+
var TYPES = /* @__PURE__ */ new Set(["ready", "resize", "success", "cancel", "expire", "error", "close"]);
|
|
184
|
+
var pick = (v, re) => typeof v === "string" && re.test(v) ? v : void 0;
|
|
185
|
+
function parseCheckoutMessage(ev, expected) {
|
|
186
|
+
if (ev.origin !== CHECKOUT_ORIGIN) return null;
|
|
187
|
+
if (!expected.source || ev.source !== expected.source) return null;
|
|
188
|
+
const d = ev.data;
|
|
189
|
+
if (!d || typeof d !== "object" || Array.isArray(d)) return null;
|
|
190
|
+
if (d.terraPay !== 1 || d.sid !== expected.sid || typeof d.type !== "string" || !TYPES.has(d.type)) return null;
|
|
191
|
+
const out = { type: d.type };
|
|
192
|
+
if (d.status === "succeeded" || d.status === "processing") out.status = d.status;
|
|
193
|
+
const pi = pick(d.paymentIntentId, ID.pi);
|
|
194
|
+
if (pi) out.paymentIntentId = pi;
|
|
195
|
+
const sub = pick(d.subscriptionId, ID.sub);
|
|
196
|
+
if (sub) out.subscriptionId = sub;
|
|
197
|
+
const inv = pick(d.invoiceId, ID.inv);
|
|
198
|
+
if (inv) out.invoiceId = inv;
|
|
199
|
+
const tx = pick(d.txHash, /^(0x)?[A-Za-z0-9]{16,128}$/);
|
|
200
|
+
if (tx) out.txHash = tx;
|
|
201
|
+
const chain = pick(d.chain, /^[a-z0-9-]{2,32}$/);
|
|
202
|
+
if (chain) out.chain = chain;
|
|
203
|
+
if (typeof d.height === "number" && Number.isFinite(d.height)) out.height = Math.min(4e3, Math.max(120, Math.round(d.height)));
|
|
204
|
+
const code = pick(d.errorCode, /^[A-Z][A-Z0-9_]{1,63}$/);
|
|
205
|
+
if (code) out.errorCode = code;
|
|
206
|
+
if (typeof d.errorMessage === "string") out.errorMessage = d.errorMessage.replace(/[\u0000-\u001f\u007f]/g, " ").slice(0, 300);
|
|
207
|
+
if (out.type === "success" && !out.status) out.status = "succeeded";
|
|
208
|
+
return out;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// src/checkout.ts
|
|
212
|
+
var IFRAME_SANDBOX = "allow-scripts allow-same-origin allow-popups allow-forms";
|
|
213
|
+
var DEFAULT_READY_TIMEOUT_MS = 2e4;
|
|
214
|
+
var current = null;
|
|
215
|
+
function openCheckout(opts) {
|
|
216
|
+
if (typeof window === "undefined" || typeof document === "undefined") throw new TerraPayError("UNSUPPORTED_ENVIRONMENT");
|
|
217
|
+
assertPublishableKey(opts.publishableKey);
|
|
218
|
+
if (current) {
|
|
219
|
+
current.focus();
|
|
220
|
+
return current;
|
|
221
|
+
}
|
|
222
|
+
const sid = newSessionId();
|
|
223
|
+
const theme = opts.theme ?? "auto";
|
|
224
|
+
const wanted = opts.mode ?? "auto";
|
|
225
|
+
const make = (mode2) => buildCheckoutUrl(opts, { publishableKey: opts.publishableKey, mode: mode2, sid, parentOrigin: location.origin, theme });
|
|
226
|
+
make("modal");
|
|
227
|
+
let mode = wanted === "auto" ? isPhone() ? "modal" : "popup" : wanted;
|
|
228
|
+
let popup = null;
|
|
229
|
+
const openWindow = () => {
|
|
230
|
+
const w = 460;
|
|
231
|
+
const hgt = 760;
|
|
232
|
+
const left = Math.max(0, Math.round((window.screenX ?? 0) + ((window.outerWidth ?? w) - w) / 2));
|
|
233
|
+
const top = Math.max(0, Math.round((window.screenY ?? 0) + ((window.outerHeight ?? hgt) - hgt) / 2));
|
|
234
|
+
return window.open(make("popup"), `terra_pay_${newSessionId().slice(0, 12)}`, `popup=yes,width=${w},height=${hgt},left=${left},top=${top}`);
|
|
235
|
+
};
|
|
236
|
+
if (mode === "popup") {
|
|
237
|
+
popup = openWindow();
|
|
238
|
+
if (!popup) {
|
|
239
|
+
if (wanted === "popup") throw new TerraPayError("POPUP_BLOCKED");
|
|
240
|
+
mode = "modal";
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
let resolveClosed;
|
|
244
|
+
const closed = new Promise((r) => resolveClosed = r);
|
|
245
|
+
let outcome = null;
|
|
246
|
+
let finished = false;
|
|
247
|
+
const trigger = document.activeElement;
|
|
248
|
+
const host = document.createElement("terra-pay-checkout");
|
|
249
|
+
const root = host.attachShadow({ mode: "closed" });
|
|
250
|
+
adoptStyles(root, CHECKOUT_CSS);
|
|
251
|
+
const dialog = h("dialog", { "aria-labelledby": "t", "aria-describedby": "d" });
|
|
252
|
+
const wrap = h("div", { class: "t", "data-theme": theme });
|
|
253
|
+
const closeBtn = h("button", { class: "x", type: "button", "aria-label": "Close checkout" }, icon(ICONS.close, 20));
|
|
254
|
+
let iframe = null;
|
|
255
|
+
let loading = null;
|
|
256
|
+
const scrim = h("div", { class: "scrim" });
|
|
257
|
+
function modalPanel() {
|
|
258
|
+
loading = h("div", { class: "loading", role: "status" }, h("span", { class: "spin" }), "Loading secure checkout");
|
|
259
|
+
iframe = h("iframe", { title: "Terra Pay checkout", sandbox: IFRAME_SANDBOX, allow: "clipboard-write", referrerpolicy: "strict-origin-when-cross-origin" });
|
|
260
|
+
iframe.src = make("modal");
|
|
261
|
+
return h(
|
|
262
|
+
"div",
|
|
263
|
+
{ class: "panel" },
|
|
264
|
+
h(
|
|
265
|
+
"header",
|
|
266
|
+
{ class: "bar" },
|
|
267
|
+
h("span", { class: "lock" }, icon(ICONS.lock, 18)),
|
|
268
|
+
h("div", { class: "who" }, h("strong", { id: "t" }, "Secure checkout"), h("span", { class: "origin", id: "d" }, "pay.terrawallet.us")),
|
|
269
|
+
closeBtn
|
|
270
|
+
),
|
|
271
|
+
h("div", { class: "frame" }, loading, iframe)
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
function popupCard() {
|
|
275
|
+
const show = h("button", { class: "btn primary", type: "button" }, icon(ICONS.external, 18), "Show window");
|
|
276
|
+
const cancel = h("button", { class: "btn secondary", type: "button" }, "Cancel payment");
|
|
277
|
+
show.addEventListener("click", () => popup?.focus());
|
|
278
|
+
cancel.addEventListener("click", () => finish({ status: "canceled" }, true));
|
|
279
|
+
return h(
|
|
280
|
+
"div",
|
|
281
|
+
{ class: "card", role: "document" },
|
|
282
|
+
h("span", { class: "lock" }, icon(ICONS.lock, 18)),
|
|
283
|
+
h("h2", { id: "t" }, "Finish paying in the Terra Pay window"),
|
|
284
|
+
h("p", { id: "d" }, "Secure checkout opened on pay.terrawallet.us. Your payment continues there."),
|
|
285
|
+
h("div", { class: "row" }, cancel, show)
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
wrap.append(scrim, mode === "modal" ? modalPanel() : popupCard());
|
|
289
|
+
dialog.append(wrap);
|
|
290
|
+
root.append(dialog);
|
|
291
|
+
document.body.append(host);
|
|
292
|
+
const prevOverflow = document.documentElement.style.getPropertyValue("overflow");
|
|
293
|
+
document.documentElement.style.setProperty("overflow", "hidden");
|
|
294
|
+
if (typeof dialog.showModal === "function") {
|
|
295
|
+
try {
|
|
296
|
+
dialog.showModal();
|
|
297
|
+
} catch {
|
|
298
|
+
dialog.setAttribute("open", "");
|
|
299
|
+
}
|
|
300
|
+
} else dialog.setAttribute("open", "");
|
|
301
|
+
(mode === "modal" ? closeBtn : wrap.querySelector(".primary"))?.focus();
|
|
302
|
+
closeBtn.addEventListener("click", () => finish(outcome ?? { status: "canceled" }, true));
|
|
303
|
+
wrap.querySelector(".scrim")?.addEventListener("click", () => popup && !popup.closed ? popup.focus() : void 0);
|
|
304
|
+
dialog.addEventListener("cancel", (e) => {
|
|
305
|
+
e.preventDefault();
|
|
306
|
+
finish(outcome ?? { status: "canceled" }, true);
|
|
307
|
+
});
|
|
308
|
+
dialog.addEventListener("keydown", (e) => {
|
|
309
|
+
if (e.key !== "Tab") return;
|
|
310
|
+
const items = [...root.querySelectorAll("button, iframe")];
|
|
311
|
+
const first = items[0];
|
|
312
|
+
const last = items[items.length - 1];
|
|
313
|
+
const active = root.activeElement;
|
|
314
|
+
if (!first || !last) return;
|
|
315
|
+
if (e.shiftKey && (active === first || !active)) {
|
|
316
|
+
e.preventDefault();
|
|
317
|
+
last.focus();
|
|
318
|
+
} else if (!e.shiftKey && active === last) {
|
|
319
|
+
e.preventDefault();
|
|
320
|
+
first.focus();
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
const source = () => mode === "modal" ? iframe?.contentWindow ?? null : popup;
|
|
324
|
+
const onMessage = (ev) => {
|
|
325
|
+
const msg = parseCheckoutMessage(ev, { source: source(), sid });
|
|
326
|
+
if (msg) handle(msg);
|
|
327
|
+
};
|
|
328
|
+
window.addEventListener("message", onMessage);
|
|
329
|
+
let poll;
|
|
330
|
+
const watchPopup = () => {
|
|
331
|
+
poll = setInterval(() => popup?.closed && finish(outcome ?? { status: "canceled" }, false), 400);
|
|
332
|
+
};
|
|
333
|
+
if (mode === "popup") watchPopup();
|
|
334
|
+
let ready = false;
|
|
335
|
+
const readyMs = typeof opts.readyTimeoutMs === "number" && Number.isFinite(opts.readyTimeoutMs) && opts.readyTimeoutMs > 0 ? opts.readyTimeoutMs : DEFAULT_READY_TIMEOUT_MS;
|
|
336
|
+
let watchdog;
|
|
337
|
+
const arm = () => {
|
|
338
|
+
clearTimeout(watchdog);
|
|
339
|
+
watchdog = setTimeout(notReady, readyMs);
|
|
340
|
+
};
|
|
341
|
+
function notReady() {
|
|
342
|
+
if (finished || ready) return;
|
|
343
|
+
const https = location.protocol === "https:";
|
|
344
|
+
if (mode === "modal") {
|
|
345
|
+
const why2 = https ? "The checkout could not load in a frame on this page: check that this site is an allowed origin of the publishable key (dashboard, project settings)." : "The checkout sends its messages only to https pages.";
|
|
346
|
+
opts.onError?.(new TerraPayError("CHECKOUT_ERROR", `The checkout did not connect to this page. ${why2} The shopper can continue in a new window.`));
|
|
347
|
+
const go = h("button", { class: "btn primary", type: "button" }, icon(ICONS.external, 18), "Continue in a new window");
|
|
348
|
+
go.addEventListener("click", () => toPopup(go));
|
|
349
|
+
loading?.replaceChildren(h("p", {}, "The secure checkout could not open here."), go);
|
|
350
|
+
go.focus();
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
const why = https ? "Check that this site is an allowed origin of the publishable key (dashboard, project settings)." : "The checkout sends its messages only to https pages.";
|
|
354
|
+
opts.onError?.(new TerraPayError("CHECKOUT_ERROR", `The checkout did not connect to this page. ${why}`));
|
|
355
|
+
}
|
|
356
|
+
arm();
|
|
357
|
+
function toPopup(button) {
|
|
358
|
+
if (finished || mode !== "modal") return;
|
|
359
|
+
const w = openWindow();
|
|
360
|
+
if (!w) {
|
|
361
|
+
opts.onError?.(new TerraPayError("POPUP_BLOCKED"));
|
|
362
|
+
button.focus();
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
popup = w;
|
|
366
|
+
mode = "popup";
|
|
367
|
+
iframe?.remove();
|
|
368
|
+
iframe = null;
|
|
369
|
+
loading = null;
|
|
370
|
+
const card = popupCard();
|
|
371
|
+
wrap.replaceChildren(scrim, card);
|
|
372
|
+
card.querySelector(".primary")?.focus();
|
|
373
|
+
watchPopup();
|
|
374
|
+
arm();
|
|
375
|
+
}
|
|
376
|
+
function resultOf(m, status) {
|
|
377
|
+
const r = { status };
|
|
378
|
+
for (const k of ["paymentIntentId", "subscriptionId", "invoiceId", "txHash", "chain"]) if (m[k]) r[k] = m[k];
|
|
379
|
+
return r;
|
|
380
|
+
}
|
|
381
|
+
function handle(m) {
|
|
382
|
+
switch (m.type) {
|
|
383
|
+
case "ready":
|
|
384
|
+
ready = true;
|
|
385
|
+
clearTimeout(watchdog);
|
|
386
|
+
loading?.setAttribute("hidden", "");
|
|
387
|
+
opts.onReady?.();
|
|
388
|
+
break;
|
|
389
|
+
case "resize":
|
|
390
|
+
if (iframe && m.height && !isPhone()) iframe.style.setProperty("min-height", `${Math.min(m.height, window.innerHeight - 120)}px`);
|
|
391
|
+
break;
|
|
392
|
+
case "success":
|
|
393
|
+
outcome = resultOf(m, m.status ?? "succeeded");
|
|
394
|
+
opts.onSuccess?.(outcome);
|
|
395
|
+
break;
|
|
396
|
+
case "expire":
|
|
397
|
+
outcome = resultOf(m, "expired");
|
|
398
|
+
opts.onExpire?.(outcome);
|
|
399
|
+
break;
|
|
400
|
+
case "error":
|
|
401
|
+
opts.onError?.(new TerraPayError("CHECKOUT_ERROR", m.errorMessage ? `Checkout: ${m.errorMessage}` : void 0));
|
|
402
|
+
break;
|
|
403
|
+
case "cancel":
|
|
404
|
+
finish({ status: "canceled" }, true);
|
|
405
|
+
break;
|
|
406
|
+
case "close":
|
|
407
|
+
finish(outcome ?? { status: "canceled" }, true);
|
|
408
|
+
break;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
function finish(result, closeWindow) {
|
|
412
|
+
if (finished) return;
|
|
413
|
+
finished = true;
|
|
414
|
+
window.removeEventListener("message", onMessage);
|
|
415
|
+
if (poll) clearInterval(poll);
|
|
416
|
+
clearTimeout(watchdog);
|
|
417
|
+
if (closeWindow && popup && !popup.closed) popup.close();
|
|
418
|
+
try {
|
|
419
|
+
dialog.close();
|
|
420
|
+
} catch {
|
|
421
|
+
}
|
|
422
|
+
host.remove();
|
|
423
|
+
if (prevOverflow) document.documentElement.style.setProperty("overflow", prevOverflow);
|
|
424
|
+
else document.documentElement.style.removeProperty("overflow");
|
|
425
|
+
if (trigger && document.contains(trigger)) trigger.focus({ preventScroll: true });
|
|
426
|
+
current = null;
|
|
427
|
+
if (result.status === "canceled") opts.onCancel?.();
|
|
428
|
+
opts.onClose?.(result);
|
|
429
|
+
resolveClosed(result);
|
|
430
|
+
}
|
|
431
|
+
const handle_ = {
|
|
432
|
+
get mode() {
|
|
433
|
+
return mode;
|
|
434
|
+
},
|
|
435
|
+
closed,
|
|
436
|
+
close: () => finish(outcome ?? { status: "canceled" }, true),
|
|
437
|
+
focus: () => popup && !popup.closed ? popup.focus() : closeBtn.focus()
|
|
438
|
+
};
|
|
439
|
+
current = handle_;
|
|
440
|
+
return handle_;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// src/index.ts
|
|
444
|
+
var VERSION = true ? "0.1.0" : "0.0.0-dev";
|
|
445
|
+
function subscribe(opts) {
|
|
446
|
+
return openCheckout(opts);
|
|
447
|
+
}
|
|
448
|
+
function mountButton(target, opts) {
|
|
449
|
+
assertPublishableKey(opts.publishableKey);
|
|
450
|
+
const host = document.createElement("terra-pay-js-button");
|
|
451
|
+
const root = host.attachShadow({ mode: "closed" });
|
|
452
|
+
adoptStyles(root, BUTTON_CSS);
|
|
453
|
+
if (typeof opts.radius === "number") host.style.setProperty("--terra-radius", `${Math.min(24, Math.max(0, opts.radius))}px`);
|
|
454
|
+
const label = (opts.label ?? (opts.planId ? "Subscribe with Terra" : "Pay with Terra")).slice(0, 60);
|
|
455
|
+
const button = h("button", { type: "button" }, icon(["M7 11V8a5 5 0 0 1 10 0v3", "M5 11h14v10H5z"], 18), label);
|
|
456
|
+
button.addEventListener("click", () => {
|
|
457
|
+
button.disabled = true;
|
|
458
|
+
const handle = openCheckout(opts);
|
|
459
|
+
void handle.closed.finally(() => button.disabled = false);
|
|
460
|
+
});
|
|
461
|
+
root.append(button);
|
|
462
|
+
target.append(host);
|
|
463
|
+
return () => host.remove();
|
|
464
|
+
}
|
|
465
|
+
function mountSubscribeButton(target, opts) {
|
|
466
|
+
return mountButton(target, opts);
|
|
467
|
+
}
|
|
468
|
+
var TerraPay = Object.freeze({
|
|
469
|
+
open: openCheckout,
|
|
470
|
+
subscribe,
|
|
471
|
+
mountButton,
|
|
472
|
+
mountSubscribeButton,
|
|
473
|
+
CHECKOUT_ORIGIN,
|
|
474
|
+
VERSION
|
|
475
|
+
});
|
|
476
|
+
export {
|
|
477
|
+
CHECKOUT_ORIGIN,
|
|
478
|
+
DEFAULT_READY_TIMEOUT_MS,
|
|
479
|
+
IFRAME_SANDBOX,
|
|
480
|
+
TerraPay,
|
|
481
|
+
TerraPayError,
|
|
482
|
+
VERSION,
|
|
483
|
+
assertPublishableKey,
|
|
484
|
+
buildCheckoutUrl,
|
|
485
|
+
checkoutPath,
|
|
486
|
+
mountButton,
|
|
487
|
+
mountSubscribeButton,
|
|
488
|
+
openCheckout,
|
|
489
|
+
parseCheckoutMessage,
|
|
490
|
+
subscribe
|
|
491
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export declare const CHECKOUT_ORIGIN = "https://pay.terrawallet.us";
|
|
2
|
+
export type CheckoutMode = "modal" | "popup";
|
|
3
|
+
export interface CheckoutTarget {
|
|
4
|
+
checkoutUrl?: string;
|
|
5
|
+
paymentIntentId?: string;
|
|
6
|
+
planId?: string;
|
|
7
|
+
}
|
|
8
|
+
/** A random 128-bit session id that ties every message to one open() call. */
|
|
9
|
+
export declare function newSessionId(): string;
|
|
10
|
+
/** Resolves the checkout path (/c/pi_..., /l/plink_..., /i/inv_..., /s/plan_...) from the caller's input. */
|
|
11
|
+
export declare function checkoutPath(target: CheckoutTarget): string;
|
|
12
|
+
export declare function buildCheckoutUrl(target: CheckoutTarget, p: {
|
|
13
|
+
publishableKey: string;
|
|
14
|
+
mode: CheckoutMode;
|
|
15
|
+
sid: string;
|
|
16
|
+
parentOrigin: string;
|
|
17
|
+
theme?: string;
|
|
18
|
+
}): string;
|
|
19
|
+
export type CheckoutMessageType = "ready" | "resize" | "success" | "cancel" | "expire" | "error" | "close";
|
|
20
|
+
export interface CheckoutMessage {
|
|
21
|
+
type: CheckoutMessageType;
|
|
22
|
+
status?: "succeeded" | "processing";
|
|
23
|
+
paymentIntentId?: string;
|
|
24
|
+
subscriptionId?: string;
|
|
25
|
+
invoiceId?: string;
|
|
26
|
+
txHash?: string;
|
|
27
|
+
chain?: string;
|
|
28
|
+
height?: number;
|
|
29
|
+
errorCode?: string;
|
|
30
|
+
errorMessage?: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Validates a MessageEvent against the exact checkout origin, the expected source window and the session id.
|
|
34
|
+
* Returns a sanitised copy, or null when the message must be ignored.
|
|
35
|
+
*/
|
|
36
|
+
export declare function parseCheckoutMessage(ev: {
|
|
37
|
+
origin: string;
|
|
38
|
+
source: unknown;
|
|
39
|
+
data: unknown;
|
|
40
|
+
}, expected: {
|
|
41
|
+
source: unknown;
|
|
42
|
+
sid: string;
|
|
43
|
+
}): CheckoutMessage | null;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"bomFormat": "CycloneDX",
|
|
3
|
+
"specVersion": "1.5",
|
|
4
|
+
"serialNumber": "urn:uuid:524d89a0-4c6d-4d98-8096-745e72c3ef40",
|
|
5
|
+
"version": 1,
|
|
6
|
+
"metadata": {
|
|
7
|
+
"timestamp": "2026-11-27T23:03:05.321Z",
|
|
8
|
+
"tools": {
|
|
9
|
+
"components": [
|
|
10
|
+
{
|
|
11
|
+
"type": "application",
|
|
12
|
+
"name": "terra-sdk-sbom",
|
|
13
|
+
"version": "1"
|
|
14
|
+
}
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
"component": {
|
|
18
|
+
"type": "library",
|
|
19
|
+
"name": "@terrawallet/pay-js",
|
|
20
|
+
"version": "0.1.0",
|
|
21
|
+
"bom-ref": "terra-sdk:@terrawallet/pay-js@0.1.0"
|
|
22
|
+
},
|
|
23
|
+
"properties": []
|
|
24
|
+
},
|
|
25
|
+
"components": []
|
|
26
|
+
}
|
package/dist/styles.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checkout overlay styles, in the browser extension's visual language (same tokens: canvas, layers, lines,
|
|
3
|
+
* brand blue, 14/18/24 px radii, 160-240 ms motion). Lives in a closed shadow root, so host CSS cannot reach it.
|
|
4
|
+
*/
|
|
5
|
+
export declare const CHECKOUT_CSS = "\n:host{all:initial}\n*{box-sizing:border-box}\n.t{--canvas:#060912;--l1:#0C1322;--l2:#111A2E;--l3:#18233C;--line:rgba(255,255,255,.08);--line2:rgba(255,255,255,.14);--fg:#F5F7FF;--muted:#93A0B8;--brand:#0A5BFF;--brand2:#5B8BFF;--ok:#2ECC71;--shadow:0 16px 48px rgba(0,0,0,.55);color-scheme:dark}\n.t[data-theme=light]{--canvas:#F7F9FC;--l1:#fff;--l2:#F1F4F9;--l3:#E6EBF4;--line:rgba(11,18,33,.08);--line2:rgba(11,18,33,.14);--fg:#0B1221;--muted:#5B6577;--brand2:#0A5BFF;--ok:#13703D;--shadow:0 16px 48px rgba(11,18,33,.18);color-scheme:light}\n@media (prefers-color-scheme:light){.t[data-theme=auto]{--canvas:#F7F9FC;--l1:#fff;--l2:#F1F4F9;--l3:#E6EBF4;--line:rgba(11,18,33,.08);--line2:rgba(11,18,33,.14);--fg:#0B1221;--muted:#5B6577;--brand2:#0A5BFF;--ok:#13703D;--shadow:0 16px 48px rgba(11,18,33,.18);color-scheme:light}}\ndialog{position:fixed;inset:0;margin:0;padding:0;border:0;background:transparent;max-width:none;max-height:none;width:100%;height:100%;overflow:hidden;font:14px/20px Inter,ui-sans-serif,system-ui,-apple-system,\"Segoe UI\",Roboto,sans-serif;-webkit-font-smoothing:antialiased}\ndialog::backdrop{background:rgba(3,6,14,.62)}\ndialog:not([open]){display:none}\n.scrim{position:absolute;inset:0}\n.panel{position:absolute;left:0;right:0;bottom:0;display:flex;flex-direction:column;height:min(92dvh,92vh);background:var(--l1);color:var(--fg);border-top:1px solid var(--line2);border-radius:24px 24px 0 0;box-shadow:var(--shadow);overflow:hidden;animation:sheet .24s cubic-bezier(.32,.72,0,1)}\n.card{position:absolute;left:16px;right:16px;bottom:16px;padding:20px;background:var(--l1);color:var(--fg);border:1px solid var(--line2);border-radius:24px;box-shadow:var(--shadow);animation:sheet .24s cubic-bezier(.32,.72,0,1)}\n@media (min-width:641px){\n.panel{left:50%;top:50%;bottom:auto;width:440px;height:min(720px,calc(100vh - 48px));border:1px solid var(--line2);border-radius:24px;transform:translate(-50%,-50%);animation:pop .16s ease-out}\n.card{left:50%;top:50%;bottom:auto;right:auto;width:380px;transform:translate(-50%,-50%);animation:pop .16s ease-out}\n}\n.bar{display:flex;align-items:center;gap:10px;padding:12px 12px 12px 16px;border-bottom:1px solid var(--line);background:var(--l1)}\n.lock{display:flex;align-items:center;justify-content:center;width:32px;height:32px;border-radius:10px;background:rgba(46,204,113,.12);color:var(--ok);flex:none}\n.who{display:flex;flex-direction:column;min-width:0;flex:1}\n.who strong{font-size:14px;line-height:18px;font-weight:600}\n.origin{font-size:12px;line-height:16px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}\n.x{all:unset;display:flex;align-items:center;justify-content:center;width:36px;height:36px;border-radius:12px;color:var(--muted);cursor:pointer;flex:none}\n.x:hover{background:var(--l2);color:var(--fg)}\n.x:focus-visible,.btn:focus-visible{outline:none;box-shadow:0 0 0 3px rgba(91,139,255,.45)}\n.frame{position:relative;flex:1;background:var(--canvas)}\niframe{position:absolute;inset:0;width:100%;height:100%;border:0;background:transparent;color-scheme:normal}\n.loading{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:12px;color:var(--muted);font-size:13px}\n.loading[hidden]{display:none}\n.spin{width:28px;height:28px;border-radius:50%;border:2.5px solid var(--line2);border-top-color:var(--brand2);animation:spin .8s linear infinite}\nh2{margin:12px 0 4px;font-size:18px;line-height:24px;font-weight:700;letter-spacing:-.01em}\np{margin:0;color:var(--muted)}\n.row{display:grid;grid-template-columns:1fr 1fr;gap:8px;margin-top:20px}\n.btn{all:unset;box-sizing:border-box;display:flex;align-items:center;justify-content:center;gap:8px;height:44px;padding:0 16px;border-radius:14px;font-weight:600;font-size:14px;cursor:pointer;text-align:center;transition:transform .15s ease-out,filter .15s ease-out}\n.btn:active{transform:scale(.98)}\n.primary{background:linear-gradient(135deg,#0A5BFF 0%,#5B8BFF 100%);color:#fff;box-shadow:0 8px 22px rgba(10,91,255,.38)}\n.primary:hover{filter:brightness(1.1)}\n.secondary{background:var(--l2);color:var(--fg);border:1px solid var(--line2)}\n.secondary:hover{background:var(--l3)}\n@keyframes sheet{from{transform:translateY(100%)}to{transform:translateY(0)}}\n@keyframes pop{from{opacity:0;transform:translate(-50%,-50%) scale(.96)}to{opacity:1;transform:translate(-50%,-50%) scale(1)}}\n@keyframes spin{to{transform:rotate(360deg)}}\n@media (prefers-reduced-motion:reduce){*{animation-duration:1ms!important;transition-duration:1ms!important}}\n";
|
|
6
|
+
export declare const BUTTON_CSS = "\n:host{all:initial;display:inline-block;vertical-align:middle}\n*{box-sizing:border-box}\nbutton{all:unset;box-sizing:border-box;display:inline-flex;align-items:center;justify-content:center;gap:8px;min-height:44px;padding:0 20px;border-radius:var(--terra-radius,14px);font:600 15px/20px Inter,ui-sans-serif,system-ui,-apple-system,\"Segoe UI\",Roboto,sans-serif;color:#fff;background:linear-gradient(135deg,#0A5BFF 0%,#5B8BFF 100%);box-shadow:0 8px 22px rgba(10,91,255,.32);cursor:pointer;transition:transform .15s ease-out,filter .15s ease-out;-webkit-font-smoothing:antialiased}\nbutton:hover{filter:brightness(1.1)}\nbutton:active{transform:scale(.98)}\nbutton:focus-visible{outline:none;box-shadow:0 0 0 3px rgba(91,139,255,.45)}\nbutton[disabled]{opacity:.5;cursor:default}\n@media (prefers-reduced-motion:reduce){button{transition:none}}\n";
|