@orangecheck/me-client 0.46.0 → 0.47.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/dist/button.mjs CHANGED
@@ -6,7 +6,7 @@ var MARK_POINTS = {
6
6
  };
7
7
  var MARK_VIEWBOX = "0 0 16 8";
8
8
  var MARK_FACES = { top: "#FED8AB", left: "#FB933C", right: "#EA580B" };
9
- var MARK_MONO_OPACITY = { top: 1, left: 0.7, right: 0.45 };
9
+ var MARK_MONO_OPACITY = { top: 1, left: 0.6, right: 0.3 };
10
10
  var MARK_TILE = {
11
11
  viewBox: "0 0 24 24",
12
12
  radius: 6.25,
@@ -14,6 +14,9 @@ var MARK_TILE = {
14
14
  transform: "translate(4.25 8.1) scale(0.97)"
15
15
  };
16
16
  var ORDER = ["left", "right", "top"];
17
+ function opacity(face, flat) {
18
+ return flat ? 1 : MARK_MONO_OPACITY[face];
19
+ }
17
20
  function heightFor(variant, width) {
18
21
  if (variant === "tile") return width;
19
22
  const m = /^(-?[\d.]+)([a-z%]*)$/i.exec(width.trim());
@@ -23,7 +26,7 @@ var SVG_NS = "http://www.w3.org/2000/svg";
23
26
  function markElement(doc, options = {}) {
24
27
  const variant = options.variant ?? "mono";
25
28
  if (variant !== "mono" && variant !== "brand" && variant !== "tile") throw new TypeError(`markElement: unknown variant ${String(variant)}`);
26
- const width = options.width ?? (variant === "tile" ? "1.25em" : "1.5em");
29
+ const width = options.width ?? (variant === "tile" ? "1.25em" : "1.75em");
27
30
  const color = options.color ?? "currentColor";
28
31
  const el = (tag, attrs) => {
29
32
  const node = doc.createElementNS(SVG_NS, tag);
@@ -52,7 +55,7 @@ function markElement(doc, options = {}) {
52
55
  const attrs = { points: MARK_POINTS[face] };
53
56
  if (variant === "mono") {
54
57
  attrs.fill = color;
55
- if (MARK_MONO_OPACITY[face] !== 1) attrs["fill-opacity"] = String(MARK_MONO_OPACITY[face]);
58
+ if (opacity(face, !!options.flat) !== 1) attrs["fill-opacity"] = String(opacity(face, !!options.flat));
56
59
  } else attrs.fill = MARK_FACES[face];
57
60
  parent.append(el("polygon", attrs));
58
61
  }
@@ -136,49 +139,88 @@ var OUTCOME_COPY = {
136
139
  closed: "The sign-in window closed before you finished.",
137
140
  failed: "Sign-in didn't finish. Try again."
138
141
  };
139
- var LABELS = new Set(Object.values(SIGN_IN_LABELS));
140
142
  var MARKS = /* @__PURE__ */ new Set(["mono", "brand", "tile", false]);
141
- var KEYS = /* @__PURE__ */ new Set(["onSignedIn", "onOutcome", "mark", "label", "appearance", "popup"]);
143
+ var KEYS = /* @__PURE__ */ new Set(["onSignedIn", "onOutcome", "mark", "label", "busyLabel", "accessibleLabel", "appearance", "popup"]);
144
+ var NAMED = /(^|[^\p{L}\p{N}])orangecheck($|[^\p{L}\p{N}])/u;
142
145
  function checkSignInOptions(options) {
143
146
  for (const key of Object.keys(options)) if (!KEYS.has(key)) throw new TypeError(`sign-in button: unknown option ${key}`);
144
147
  if (typeof options.onSignedIn !== "function") throw new TypeError("sign-in button: onSignedIn is required");
145
148
  const label = options.label ?? SIGN_IN_LABELS.signIn;
146
- if (!LABELS.has(label)) throw new TypeError(`sign-in button: "${label}" is not an approved label; use one of SIGN_IN_LABELS`);
149
+ if (label !== false && (typeof label !== "string" || !NAMED.test(label))) {
150
+ throw new TypeError(`sign-in button: "${String(label)}" must say "orangecheck", lowercase, as written; see SIGN_IN_LABELS`);
151
+ }
152
+ const accessibleLabel = options.accessibleLabel ?? SIGN_IN_LABELS.signIn;
153
+ if (!NAMED.test(accessibleLabel)) throw new TypeError(`sign-in button: accessibleLabel "${accessibleLabel}" must say "orangecheck"`);
154
+ const busyLabel = options.busyLabel ?? SIGN_IN_BUSY_LABEL;
155
+ if (typeof busyLabel !== "string" || !busyLabel.trim()) throw new TypeError("sign-in button: busyLabel must be words");
147
156
  const mark = options.mark ?? "mono";
148
157
  if (!MARKS.has(mark)) throw new TypeError(`sign-in button: unknown mark ${String(mark)}`);
158
+ if (label === false && mark === false) throw new TypeError("sign-in button: with no label it needs the mark");
149
159
  const appearance = options.appearance ?? "inherit";
150
160
  if (appearance !== "inherit" && appearance !== "brand") throw new TypeError(`sign-in button: unknown appearance ${String(appearance)}`);
151
- return { label, mark, appearance };
161
+ return { label, mark, busyLabel, accessibleLabel, appearance };
162
+ }
163
+ function holdWidth(button) {
164
+ const { width: was, minWidth: wasMin } = button.style;
165
+ const width = button.getBoundingClientRect().width;
166
+ if (width > 0) button.style.width = button.style.minWidth = `${width}px`;
167
+ return () => {
168
+ button.style.width = was;
169
+ button.style.minWidth = wasMin;
170
+ };
152
171
  }
153
172
  function enhanceSignInButton(button, options) {
154
173
  if (!button || button.tagName !== "BUTTON") throw new TypeError("sign-in button: pass a <button> element");
155
- const { label, mark, appearance } = checkSignInOptions(options);
156
- const before = { nodes: [...button.childNodes], type: button.getAttribute("type") };
157
174
  const doc = button.ownerDocument;
175
+ const own = (button.querySelector("[data-oc-label]")?.textContent ?? button.textContent ?? "").trim();
176
+ const iconOnly = options.label === false || options.label === void 0 && button.getAttribute("data-label") === "none";
177
+ const written = options.label === void 0 && !iconOnly && NAMED.test(own) ? own : options.label;
178
+ const hinted = button.querySelector("[data-oc-mark]")?.getAttribute("data-oc-mark");
179
+ const variant = options.mark === void 0 && hinted && MARKS.has(hinted) ? hinted : options.mark;
180
+ const checked = checkSignInOptions({ ...options, mark: variant, label: iconOnly ? false : written });
181
+ const { label, mark, appearance, busyLabel, accessibleLabel } = checked;
182
+ const before = {
183
+ nodes: [...button.childNodes],
184
+ type: button.getAttribute("type"),
185
+ aria: button.getAttribute("aria-label"),
186
+ dataLabel: button.getAttribute("data-label")
187
+ };
158
188
  if (!before.type) button.type = "button";
159
189
  button.setAttribute("data-oc-sign-in", "");
160
190
  button.setAttribute("data-appearance", appearance);
191
+ const markEl = mark ? markElement(doc, { variant: mark }) : null;
161
192
  const text = doc.createElement("span");
162
193
  text.setAttribute("data-oc-label", "");
163
- text.textContent = label;
164
- button.replaceChildren(...mark ? [markElement(doc, { variant: mark })] : [], text);
194
+ if (label === false) {
195
+ button.setAttribute("data-label", "none");
196
+ button.setAttribute("aria-label", accessibleLabel);
197
+ button.replaceChildren(markEl);
198
+ } else {
199
+ text.textContent = label;
200
+ button.replaceChildren(...markEl ? [markEl] : [], text);
201
+ }
165
202
  let busy = false;
203
+ let release = null;
166
204
  const setBusy = (on) => {
167
205
  busy = on;
168
- text.textContent = on ? SIGN_IN_BUSY_LABEL : label;
169
206
  if (on) {
207
+ release = holdWidth(button);
208
+ if (label !== false) text.textContent = busyLabel;
170
209
  button.setAttribute("aria-disabled", "true");
171
210
  button.setAttribute("aria-busy", "true");
172
211
  } else {
212
+ if (label !== false) text.textContent = label;
173
213
  button.removeAttribute("aria-disabled");
174
214
  button.removeAttribute("aria-busy");
215
+ release?.();
216
+ release = null;
175
217
  }
176
218
  };
177
219
  const onClick = async (event) => {
178
220
  event.preventDefault();
179
221
  if (busy || button.disabled) return;
180
- setBusy(true);
181
222
  const pending = signInWithOcOutcome(options.popup);
223
+ setBusy(true);
182
224
  try {
183
225
  const outcome = await pending;
184
226
  options.onOutcome?.(outcome);
@@ -193,9 +235,13 @@ function enhanceSignInButton(button, options) {
193
235
  button.replaceChildren(...before.nodes);
194
236
  if (before.type === null) button.removeAttribute("type");
195
237
  for (const a of ["data-oc-sign-in", "data-appearance", "aria-disabled", "aria-busy"]) button.removeAttribute(a);
238
+ if (before.aria === null) button.removeAttribute("aria-label");
239
+ else button.setAttribute("aria-label", before.aria);
240
+ if (before.dataLabel === null) button.removeAttribute("data-label");
241
+ else button.setAttribute("data-label", before.dataLabel);
196
242
  };
197
243
  }
198
244
 
199
- export { OUTCOME_COPY, SIGN_IN_BUSY_LABEL, SIGN_IN_LABELS, checkSignInOptions, enhanceSignInButton };
245
+ export { OUTCOME_COPY, SIGN_IN_BUSY_LABEL, SIGN_IN_LABELS, checkSignInOptions, enhanceSignInButton, holdWidth };
200
246
  //# sourceMappingURL=button.mjs.map
201
247
  //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AgB,MAAM,CAAA;AACvD,IAAA,KAAA,MAAW,CAAA,IAAK,CAAC,iBAAA,EAAmB,iBAAA,EAAmB,iBAAiB,WAAW,CAAA,EAAG,MAAA,CAAO,eAAA,CAAgB,CAAC,CAAA;AAAA,EAClH,CAAA;AACJ","file":"button.mjs","sourcesContent":["/**\n * The orangecheck mark: an isometric check on a 16×8 grid, three faces.\n *\n * Framework-free and dependency-free: SVG strings for any page, a data URI\n * for CSS and images, and the geometry for a renderer that draws its own.\n * The React component is in `@orangecheck/mark/react`.\n */\n\n/** The three faces as SVG points in the 16×8 box. */\nexport const MARK_POINTS = {\n top: '0,3 2,2 6,4 14,0 16,1 6,6',\n left: '0,3 6,6 6,8 0,5',\n right: '6,6 16,1 16,3 6,8',\n} as const;\n\nexport const MARK_VIEWBOX = '0 0 16 8';\n\n/** The faces as drawn. For dark grounds only: the top face is about 1.3:1 on white. */\nexport const MARK_FACES = { top: '#FED8AB', left: '#FB933C', right: '#EA580B' } as const;\n\n/** One colour, three weights: the check at full strength, the sides as depth. */\nexport const MARK_MONO_OPACITY = { top: 1, left: 0.7, right: 0.45 } as const;\n\n/** The tile: the faces on an ink square with rounded corners, 24×24. Reads on any ground. */\nexport const MARK_TILE = {\n viewBox: '0 0 24 24',\n radius: 6.25,\n fill: '#0A0A0A',\n transform: 'translate(4.25 8.1) scale(0.97)',\n} as const;\n\n/** Smallest width the bare mark may be drawn at, in CSS pixels (the tile: the same, square). */\nexport const MARK_MIN_PX = 16;\n\n/** `mono`: the host's text colour. `brand`: as drawn, on dark grounds. `tile`: the faces on their own ink tile. */\nexport type MarkVariant = 'mono' | 'brand' | 'tile';\n\nexport interface MarkSvgOptions {\n variant?: MarkVariant;\n /** An accessible name. Without one the mark is decoration, hidden from assistive technology. */\n title?: string;\n /** Width as a CSS length, `1.5em` by default (the tile `1.25em`); the height follows. Overridable from CSS. */\n width?: string;\n /** The mono colour. Default `currentColor`; a data URI needs a real colour, since an image inherits none. */\n color?: string;\n /** Added to the `<svg>` element. */\n className?: string;\n}\n\nconst ORDER = ['left', 'right', 'top'] as const;\n\nfunction escape(s: string): string {\n return s.replace(/[&<>\"']/g, (c) => `&#${c.charCodeAt(0)};`);\n}\n\nfunction faces(variant: MarkVariant, color: string): string {\n return ORDER.map((face) =>\n variant === 'mono'\n ? `<polygon points=\"${MARK_POINTS[face]}\" fill=\"${escape(color)}\"${MARK_MONO_OPACITY[face] === 1 ? '' : ` fill-opacity=\"${MARK_MONO_OPACITY[face]}\"`}/>`\n : `<polygon points=\"${MARK_POINTS[face]}\" fill=\"${MARK_FACES[face]}\"/>`\n ).join('');\n}\n\n/** The height that keeps a CSS length's aspect for the variant: half for the mark, equal for the tile. */\nfunction heightFor(variant: MarkVariant, width: string): string {\n if (variant === 'tile') return width;\n const m = /^(-?[\\d.]+)([a-z%]*)$/i.exec(width.trim());\n return m ? `${Number(m[1]) / 2}${m[2]}` : 'auto';\n}\n\n/**\n * The mark as an SVG string. Sized in em by default, so it follows the\n * font size of the text beside it; a stylesheet can still set its size,\n * since width and height are attributes, not inline styles (no CSP needed).\n */\nexport function markSvg(options: MarkSvgOptions = {}): string {\n const variant = options.variant ?? 'mono';\n if (variant !== 'mono' && variant !== 'brand' && variant !== 'tile') throw new TypeError(`markSvg: unknown variant ${String(variant)}`);\n const width = options.width ?? (variant === 'tile' ? '1.25em' : '1.5em');\n const color = options.color ?? 'currentColor';\n const label = options.title ? `<title>${escape(options.title)}</title>` : '';\n const a11y = options.title ? 'role=\"img\"' : 'aria-hidden=\"true\" focusable=\"false\"';\n const cls = options.className ? ` class=\"${escape(options.className)}\"` : '';\n const size = `width=\"${escape(width)}\" height=\"${escape(heightFor(variant, width))}\"`;\n if (variant === 'tile') {\n return (\n `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"${MARK_TILE.viewBox}\" ${size} ${a11y} data-oc-mark=\"tile\"${cls}>${label}` +\n `<rect width=\"24\" height=\"24\" rx=\"${MARK_TILE.radius}\" fill=\"${MARK_TILE.fill}\"/>` +\n `<g transform=\"${MARK_TILE.transform}\">${faces('brand', color)}</g></svg>`\n );\n }\n return `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"${MARK_VIEWBOX}\" ${size} ${a11y} data-oc-mark=\"${variant}\"${cls}>${label}${faces(variant, color)}</svg>`;\n}\n\n/** The mark as a `data:image/svg+xml` URI, for CSS backgrounds and `<img>`. Mono needs an explicit `color`. */\nexport function markDataUri(options: MarkSvgOptions = {}): string {\n if ((options.variant ?? 'mono') === 'mono' && (!options.color || options.color === 'currentColor')) {\n throw new TypeError('markDataUri: a mono mark in an image needs a colour; an image inherits none');\n }\n return `data:image/svg+xml,${encodeURIComponent(markSvg({ ...options, width: options.width ?? '16' }))}`;\n}\n\nconst SVG_NS = 'http://www.w3.org/2000/svg';\n\n/**\n * The mark as an `<svg>` element, built node by node: no HTML parsing, so\n * it works under Trusted Types and any Content-Security-Policy. Same\n * drawing and attributes as markSvg.\n */\nexport function markElement(doc: Document, options: Omit<MarkSvgOptions, 'className'> & { className?: string } = {}): SVGSVGElement {\n const variant = options.variant ?? 'mono';\n if (variant !== 'mono' && variant !== 'brand' && variant !== 'tile') throw new TypeError(`markElement: unknown variant ${String(variant)}`);\n const width = options.width ?? (variant === 'tile' ? '1.25em' : '1.5em');\n const color = options.color ?? 'currentColor';\n const el = <K extends keyof SVGElementTagNameMap>(tag: K, attrs: Record<string, string>) => {\n const node = doc.createElementNS(SVG_NS, tag);\n for (const [k, v] of Object.entries(attrs)) node.setAttribute(k, v);\n return node;\n };\n const svg = el('svg', {\n viewBox: variant === 'tile' ? MARK_TILE.viewBox : MARK_VIEWBOX,\n width,\n height: heightFor(variant, width),\n 'data-oc-mark': variant,\n });\n if (options.className) svg.setAttribute('class', options.className);\n if (options.title) {\n svg.setAttribute('role', 'img');\n const title = el('title', {});\n title.textContent = options.title;\n svg.append(title);\n } else {\n svg.setAttribute('aria-hidden', 'true');\n svg.setAttribute('focusable', 'false');\n }\n const parent = variant === 'tile' ? el('g', { transform: MARK_TILE.transform }) : svg;\n if (variant === 'tile') svg.append(el('rect', { width: '24', height: '24', rx: String(MARK_TILE.radius), fill: MARK_TILE.fill }), parent);\n for (const face of ORDER) {\n const attrs: Record<string, string> = { points: MARK_POINTS[face] };\n if (variant === 'mono') {\n attrs.fill = color;\n if (MARK_MONO_OPACITY[face] !== 1) attrs['fill-opacity'] = String(MARK_MONO_OPACITY[face]);\n } else attrs.fill = MARK_FACES[face];\n parent.append(el('polygon', attrs));\n }\n return svg;\n}\n","/**\n * Browser only: `signInWithOc` opens the orangecheck sign-in popup and resolves\n * with a token bound to your origin; `signInWithOcOutcome` says why when it\n * does not. Verify the token on your server with\n * [`@orangecheck/me-client/server`](/sdk/me-client/server/README).\n *\n * @packageDocumentation\n */\n\n/**\n * @orangecheck/me-client/popup\n *\n * Browser-side helper that opens the OC sign-in popup, listens for the\n * postMessage from me.ochk.io, and resolves with the verified session.\n *\n * import { signInWithOc } from '@orangecheck/me-client/popup';\n *\n * document.querySelector('#oc-signin')!.addEventListener('click', async () => {\n * const result = await signInWithOc();\n * if (!result) return;\n * // Your server verifies it and keeps it in an httpOnly cookie.\n * const r = await fetch('/api/auth/session', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ token: result.token }),\n * });\n * if (r.ok) location.assign('/app');\n * });\n *\n * Why this lives in a separate entry point: it's browser-only (uses\n * window.open / addEventListener) and integrators that only need the\n * server-side verifier shouldn't pull popup orchestration into their\n * server bundle.\n */\n\nconst DEFAULT_POPUP_ORIGIN = 'https://me.ochk.io';\nconst DEFAULT_POPUP_PATH = '/popup/signin';\nconst DEFAULT_FEATURES = 'width=480,height=720,resizable=yes,scrollbars=yes';\n\nexport interface OcPopupAccount {\n id?: string;\n /** Opaque public identity · `did:oc:<32-hex>`. Stable across linking\n * events. The canonical identifier post auth-refactor (Dec 2025\n * +). */\n did_oc?: string;\n /** Primary linked Bitcoin address, if the user has one and is\n * surfacing it (same-origin family integrators get it inline;\n * cross-domain integrators need the bitcoin_address scope). */\n primary_btc?: string | null;\n /** Whether the user has a primary email linked (plaintext stays\n * on auth host; only the boolean reaches integrators). */\n has_email?: boolean;\n /** Legacy fields kept for back-compat with pre-refactor consumers.\n * Prefer did_oc + primary_btc. Removed in a future major. */\n address?: string;\n btc_address?: string;\n display_name?: string | null;\n nostr_npub?: string | null;\n wallet_provisioned?: boolean;\n email?: string;\n}\n\nexport interface OcPopupResult {\n /** Account payload from the auth host, unsigned: trust only the\n * verified token. `did_oc` is the account's opaque identifier, the\n * same at every site; the email and Bitcoin address stay private\n * unless the user grants a scope. */\n account: OcPopupAccount;\n /** The session JWT, bound to your origin. Hand it once to your own\n * server, which verifies it and keeps it in an httpOnly cookie; never\n * in localStorage, where any script on the page can read it. Family\n * sites (*.ochk.io) can ignore it: the Domain=.ochk.io cookie rides\n * home on its own. */\n token: string;\n}\n\nexport interface SignInWithOcOptions {\n /** Origin of the OC popup page. Defaults to https://me.ochk.io.\n * Override only for staging / preview environments. */\n popupOrigin?: string;\n /** Path on the popup origin. Defaults to /popup/signin. */\n popupPath?: string;\n /** window.open features string. Defaults to a 480x720 resizable\n * popup with scrollbars. */\n features?: string;\n /** AbortSignal that cancels the wait and closes the popup. */\n signal?: AbortSignal;\n}\n\n/**\n * How a sign-in popup ended:\n * - `signed_in` · the person signed in; `account` and `token` as from signInWithOc.\n * - `blocked` · the browser refused to open the window. Ask the person to\n * allow pop-ups for your site, then try again from a click.\n * - `closed` · the person closed the window without signing in.\n * - `aborted` · your AbortSignal fired.\n * - `failed` · not in a browser, or the popup's answer was malformed.\n */\nexport type OcPopupOutcome =\n | ({ status: 'signed_in' } & OcPopupResult)\n | { status: 'blocked' }\n | { status: 'closed' }\n | { status: 'aborted' }\n | { status: 'failed' };\n\n/**\n * Open the OC signin popup and resolve with how it ended (OcPopupOutcome),\n * so a blocked window and a closed one can be told apart.\n *\n * MUST be called inside a user-gesture handler (e.g. a button onClick).\n * Browsers block `window.open` outside of user gestures.\n */\nexport function signInWithOcOutcome(options: SignInWithOcOptions = {}): Promise<OcPopupOutcome> {\n const popupOrigin = options.popupOrigin ?? DEFAULT_POPUP_ORIGIN;\n const popupPath = options.popupPath ?? DEFAULT_POPUP_PATH;\n const features = options.features ?? DEFAULT_FEATURES;\n\n return new Promise((resolve) => {\n if (typeof window === 'undefined') {\n resolve({ status: 'failed' });\n return;\n }\n\n const url = new URL(popupPath, popupOrigin);\n url.searchParams.set('opener_origin', window.location.origin);\n const popup = window.open(url.toString(), 'oc-signin', features);\n if (!popup) {\n resolve({ status: 'blocked' });\n return;\n }\n popup.focus();\n\n let settled = false;\n const cleanup = () => {\n window.removeEventListener('message', onMessage);\n clearInterval(closedTimer);\n if (options.signal) options.signal.removeEventListener('abort', onAbort);\n };\n\n function settle(value: OcPopupOutcome) {\n if (settled) return;\n settled = true;\n cleanup();\n try {\n if (popup && !popup.closed) popup.close();\n } catch {\n /* popup may have closed itself first */\n }\n resolve(value);\n }\n\n function onMessage(event: MessageEvent) {\n // Origin pinning is necessary but not sufficient — same-origin\n // pages other than our popup can post the same shape. Pin both\n // origin AND source window so only the popup we opened can\n // settle this promise.\n if (event.origin !== popupOrigin) return;\n if (event.source !== popup) return;\n const data = event.data as\n | { type?: string; account?: OcPopupAccount; token?: string }\n | null;\n if (!data || data.type !== 'oc-signin-success') return;\n if (!data.account || !data.token) {\n settle({ status: 'failed' });\n return;\n }\n settle({ status: 'signed_in', account: data.account, token: data.token });\n }\n\n function onAbort() {\n settle({ status: 'aborted' });\n }\n\n window.addEventListener('message', onMessage);\n if (options.signal) {\n if (options.signal.aborted) {\n settle({ status: 'aborted' });\n return;\n }\n options.signal.addEventListener('abort', onAbort);\n }\n\n // Detect the person closing the popup without completing signin.\n const closedTimer = setInterval(() => {\n if (popup && popup.closed) settle({ status: 'closed' });\n }, 500);\n });\n}\n\n/**\n * Open the OC signin popup and resolve with the session result. Returns\n * `null` if the user closed the popup without completing signin, if the\n * browser blocked it, or if the AbortSignal fired. To tell those apart,\n * use signInWithOcOutcome.\n *\n * MUST be called inside a user-gesture handler (e.g. a button onClick).\n * Browsers block `window.open` outside of user gestures.\n */\nexport async function signInWithOc(options: SignInWithOcOptions = {}): Promise<OcPopupResult | null> {\n const outcome = await signInWithOcOutcome(options);\n return outcome.status === 'signed_in' ? { account: outcome.account, token: outcome.token } : null;\n}\n","/**\n * Browser only, no framework: a \"Sign in with orangecheck\" button that keeps\n * your site's own look. Write your button as you write every other one, add\n * `data-oc-sign-in`, and enhance it: this adds the orangecheck mark and the\n * label, opens the sign-in popup inside the click, holds the busy state, and\n * says how the popup ended. Optional stylesheet: `@orangecheck/me-client/button.css`.\n *\n * <button class=\"cta ghost\" data-oc-sign-in>Sign in with orangecheck</button>\n *\n * import { enhanceSignInButton } from '@orangecheck/me-client/button';\n * enhanceSignInButton(document.querySelector('[data-oc-sign-in]'), {\n * onSignedIn: async ({ token }) => { … },\n * });\n *\n * The file has no imports at run time (the mark and the popup are bundled\n * in), so it can be copied onto your own origin under a strict CSP.\n *\n * @packageDocumentation\n */\n\nimport { markElement, type MarkVariant } from '@orangecheck/mark';\n\nimport { signInWithOcOutcome, type OcPopupOutcome, type OcPopupResult, type SignInWithOcOptions } from './popup';\n\nexport type { MarkVariant } from '@orangecheck/mark';\nexport type { OcPopupOutcome, OcPopupResult, SignInWithOcOptions } from './popup';\n\n/** The labels a sign-in button may carry. \"orangecheck\" is always lowercase, never \"OC\". */\nexport const SIGN_IN_LABELS = {\n signIn: 'Sign in with orangecheck',\n continue: 'Continue with orangecheck',\n signUp: 'Sign up with orangecheck',\n} as const;\nexport type SignInLabel = (typeof SIGN_IN_LABELS)[keyof typeof SIGN_IN_LABELS];\n\n/** What the button says while the sign-in window is open. */\nexport const SIGN_IN_BUSY_LABEL = 'Signing in…';\n\n/** What to tell the person when the window did not end in a sign-in. Show it near the button. */\nexport const OUTCOME_COPY = {\n blocked: 'Your browser blocked the sign-in window. Allow pop-ups for this site, then try again.',\n closed: 'The sign-in window closed before you finished.',\n failed: \"Sign-in didn't finish. Try again.\",\n} as const;\n\n/** `inherit`: no colour, font or radius of its own; your classes draw it. `brand`: orangecheck's button, themed by --oc-* properties. */\nexport type SignInAppearance = 'inherit' | 'brand';\n\nexport interface EnhanceSignInButtonOptions {\n /** Called with the popup's account and token once the person signs in; the button stays busy until it settles. */\n onSignedIn: (result: OcPopupResult) => void | Promise<void>;\n /** Called with how every popup ended, sign-in included. Use OUTCOME_COPY for the words. */\n onOutcome?: (outcome: OcPopupOutcome) => void;\n /** The mark beside the label: `mono` (your text colour, the default), `brand` (dark buttons), `tile`, or `false` for none. */\n mark?: MarkVariant | false;\n /** One of SIGN_IN_LABELS. Default \"Sign in with orangecheck\". */\n label?: SignInLabel;\n appearance?: SignInAppearance;\n /** Passed to the popup (a preview origin, say). */\n popup?: Omit<SignInWithOcOptions, 'signal'>;\n}\n\nconst LABELS = new Set<string>(Object.values(SIGN_IN_LABELS));\nconst MARKS = new Set<unknown>(['mono', 'brand', 'tile', false]);\nconst KEYS = new Set(['onSignedIn', 'onOutcome', 'mark', 'label', 'appearance', 'popup']);\n\n/** The options, checked: a misspelt key or a label outside the approved set fails loudly, not quietly. */\nexport function checkSignInOptions(options: EnhanceSignInButtonOptions): Required<Pick<EnhanceSignInButtonOptions, 'mark' | 'label' | 'appearance'>> {\n for (const key of Object.keys(options)) if (!KEYS.has(key)) throw new TypeError(`sign-in button: unknown option ${key}`);\n if (typeof options.onSignedIn !== 'function') throw new TypeError('sign-in button: onSignedIn is required');\n const label = options.label ?? SIGN_IN_LABELS.signIn;\n if (!LABELS.has(label)) throw new TypeError(`sign-in button: \"${label}\" is not an approved label; use one of SIGN_IN_LABELS`);\n const mark = options.mark ?? 'mono';\n if (!MARKS.has(mark)) throw new TypeError(`sign-in button: unknown mark ${String(mark)}`);\n const appearance = options.appearance ?? 'inherit';\n if (appearance !== 'inherit' && appearance !== 'brand') throw new TypeError(`sign-in button: unknown appearance ${String(appearance)}`);\n return { label, mark, appearance };\n}\n\n/**\n * Make `button` an orangecheck sign-in button. Its classes and styles stay\n * yours; its content becomes the mark and the label. While the window is\n * open it is `aria-disabled` and `aria-busy`, and still focusable. Returns a\n * function that undoes it.\n */\nexport function enhanceSignInButton(button: HTMLButtonElement, options: EnhanceSignInButtonOptions): () => void {\n if (!button || button.tagName !== 'BUTTON') throw new TypeError('sign-in button: pass a <button> element');\n const { label, mark, appearance } = checkSignInOptions(options);\n const before = { nodes: [...button.childNodes], type: button.getAttribute('type') };\n const doc = button.ownerDocument;\n\n if (!before.type) button.type = 'button';\n button.setAttribute('data-oc-sign-in', '');\n button.setAttribute('data-appearance', appearance);\n // Built node by node: no HTML is parsed, so Trusted Types and strict CSPs allow it.\n const text = doc.createElement('span');\n text.setAttribute('data-oc-label', '');\n text.textContent = label;\n button.replaceChildren(...(mark ? [markElement(doc, { variant: mark })] : []), text);\n\n let busy = false;\n const setBusy = (on: boolean) => {\n busy = on;\n text.textContent = on ? SIGN_IN_BUSY_LABEL : label;\n if (on) {\n button.setAttribute('aria-disabled', 'true');\n button.setAttribute('aria-busy', 'true');\n } else {\n button.removeAttribute('aria-disabled');\n button.removeAttribute('aria-busy');\n }\n };\n\n const onClick = async (event: MouseEvent) => {\n event.preventDefault();\n if (busy || button.disabled) return;\n setBusy(true);\n // Opened before anything is awaited: a window opened later is blocked.\n const pending = signInWithOcOutcome(options.popup);\n try {\n const outcome = await pending;\n options.onOutcome?.(outcome);\n if (outcome.status === 'signed_in') await options.onSignedIn({ account: outcome.account, token: outcome.token });\n } finally {\n setBusy(false);\n }\n };\n button.addEventListener('click', onClick);\n\n return () => {\n button.removeEventListener('click', onClick);\n button.replaceChildren(...before.nodes);\n if (before.type === null) button.removeAttribute('type');\n for (const a of ['data-oc-sign-in', 'data-appearance', 'aria-disabled', 'aria-busy']) button.removeAttribute(a);\n };\n}\n"]}
1
+ {"version":3,"sources":["../node_modules/@orangecheck/mark/src/index.ts","../src/popup.ts","../src/button.ts"],"names":[],"mappings":";AASO,I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G,MAAA,CAAO,KAAK,CAAA;AACtC,IAAA,IAAI,MAAA,CAAO,IAAA,KAAS,IAAA,EAAM,MAAA,CAAO,gBAAgB,MAAM,CAAA;AACvD,IAAA,KAAA,MAAW,CAAA,IAAK,CAAC,iBAAA,EAAmB,iBAAA,EAAmB,iBAAiB,WAAW,CAAA,EAAG,MAAA,CAAO,eAAA,CAAgB,CAAC,CAAA;AAC9G,IAAA,IAAI,MAAA,CAAO,IAAA,KAAS,IAAA,EAAM,MAAA,CAAO,gBAAgB,YAAY,CAAA;AAAA,SACxD,MAAA,CAAO,YAAA,CAAa,YAAA,EAAc,MAAA,CAAO,IAAI,CAAA;AAClD,IAAA,IAAI,MAAA,CAAO,SAAA,KAAc,IAAA,EAAM,MAAA,CAAO,gBAAgB,YAAY,CAAA;AAAA,SAC7D,MAAA,CAAO,YAAA,CAAa,YAAA,EAAc,MAAA,CAAO,SAAS,CAAA;AAAA,EAC3D,CAAA;AACJ","file":"button.mjs","sourcesContent":["/**\n * The orangecheck mark: an isometric check on a 16×8 grid, three faces.\n *\n * Framework-free and dependency-free: SVG strings for any page, a data URI\n * for CSS and images, and the geometry for a renderer that draws its own.\n * The React component is in `@orangecheck/mark/react`.\n */\n\n/** The three faces as SVG points in the 16×8 box. */\nexport const MARK_POINTS = {\n top: '0,3 2,2 6,4 14,0 16,1 6,6',\n left: '0,3 6,6 6,8 0,5',\n right: '6,6 16,1 16,3 6,8',\n} as const;\n\nexport const MARK_VIEWBOX = '0 0 16 8';\n\n/** The faces as drawn. For dark grounds only: the top face is about 1.3:1 on white. */\nexport const MARK_FACES = { top: '#FED8AB', left: '#FB933C', right: '#EA580B' } as const;\n\n/**\n * One colour, three weights: the check at full strength, the sides as depth.\n * Chosen for the widest smallest step between neighbouring faces and the\n * ground across light, dark and mid-tone (amber, brown) buttons.\n */\nexport const MARK_MONO_OPACITY = { top: 1, left: 0.6, right: 0.3 } as const;\n\n/** The tile: the faces on an ink square with rounded corners, 24×24. Reads on any ground. */\nexport const MARK_TILE = {\n viewBox: '0 0 24 24',\n radius: 6.25,\n fill: '#0A0A0A',\n transform: 'translate(4.25 8.1) scale(0.97)',\n} as const;\n\n/** Smallest width the bare mark may be drawn at, in CSS pixels (the tile: the same, square). */\nexport const MARK_MIN_PX = 16;\n\n/** `mono`: the host's text colour. `brand`: as drawn, on dark grounds. `tile`: the faces on their own ink tile. */\nexport type MarkVariant = 'mono' | 'brand' | 'tile';\n\nexport interface MarkSvgOptions {\n variant?: MarkVariant;\n /** An accessible name. Without one the mark is decoration, hidden from assistive technology. */\n title?: string;\n /** Width as a CSS length, `1.75em` by default (the tile `1.25em`); the height follows. Overridable from CSS. */\n width?: string;\n /** Mono only: every face at full strength, one flat shape. For forced colours and anything that cannot shade. */\n flat?: boolean;\n /** The mono colour. Default `currentColor`; a data URI needs a real colour, since an image inherits none. */\n color?: string;\n /** Added to the `<svg>` element. */\n className?: string;\n}\n\nconst ORDER = ['left', 'right', 'top'] as const;\n\nfunction escape(s: string): string {\n return s.replace(/[&<>\"']/g, (c) => `&#${c.charCodeAt(0)};`);\n}\n\n/** A face's opacity in mono: stepped, or full for a flat mark. */\nfunction opacity(face: (typeof ORDER)[number], flat: boolean): number {\n return flat ? 1 : MARK_MONO_OPACITY[face];\n}\n\nfunction faces(variant: MarkVariant, color: string, flat = false): string {\n return ORDER.map((face) =>\n variant === 'mono'\n ? `<polygon points=\"${MARK_POINTS[face]}\" fill=\"${escape(color)}\"${opacity(face, flat) === 1 ? '' : ` fill-opacity=\"${opacity(face, flat)}\"`}/>`\n : `<polygon points=\"${MARK_POINTS[face]}\" fill=\"${MARK_FACES[face]}\"/>`\n ).join('');\n}\n\n/** The height that keeps a CSS length's aspect for the variant: half for the mark, equal for the tile. */\nfunction heightFor(variant: MarkVariant, width: string): string {\n if (variant === 'tile') return width;\n const m = /^(-?[\\d.]+)([a-z%]*)$/i.exec(width.trim());\n return m ? `${Number(m[1]) / 2}${m[2]}` : 'auto';\n}\n\n/**\n * The mark as an SVG string. Sized in em by default, so it follows the\n * font size of the text beside it; a stylesheet can still set its size,\n * since width and height are attributes, not inline styles (no CSP needed).\n */\nexport function markSvg(options: MarkSvgOptions = {}): string {\n const variant = options.variant ?? 'mono';\n if (variant !== 'mono' && variant !== 'brand' && variant !== 'tile') throw new TypeError(`markSvg: unknown variant ${String(variant)}`);\n const width = options.width ?? (variant === 'tile' ? '1.25em' : '1.75em');\n const color = options.color ?? 'currentColor';\n const label = options.title ? `<title>${escape(options.title)}</title>` : '';\n const a11y = options.title ? 'role=\"img\"' : 'aria-hidden=\"true\" focusable=\"false\"';\n const cls = options.className ? ` class=\"${escape(options.className)}\"` : '';\n const size = `width=\"${escape(width)}\" height=\"${escape(heightFor(variant, width))}\"`;\n if (variant === 'tile') {\n return (\n `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"${MARK_TILE.viewBox}\" ${size} ${a11y} data-oc-mark=\"tile\"${cls}>${label}` +\n `<rect width=\"24\" height=\"24\" rx=\"${MARK_TILE.radius}\" fill=\"${MARK_TILE.fill}\"/>` +\n `<g transform=\"${MARK_TILE.transform}\">${faces('brand', color)}</g></svg>`\n );\n }\n return `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"${MARK_VIEWBOX}\" ${size} ${a11y} data-oc-mark=\"${variant}\"${cls}>${label}${faces(variant, color, options.flat)}</svg>`;\n}\n\n/** The mark as a `data:image/svg+xml` URI, for CSS backgrounds and `<img>`. Mono needs an explicit `color`. */\nexport function markDataUri(options: MarkSvgOptions = {}): string {\n if ((options.variant ?? 'mono') === 'mono' && (!options.color || options.color === 'currentColor')) {\n throw new TypeError('markDataUri: a mono mark in an image needs a colour; an image inherits none');\n }\n return `data:image/svg+xml,${encodeURIComponent(markSvg({ ...options, width: options.width ?? '16' }))}`;\n}\n\nconst SVG_NS = 'http://www.w3.org/2000/svg';\n\n/**\n * The mark as an `<svg>` element, built node by node: no HTML parsing, so\n * it works under Trusted Types and any Content-Security-Policy. Same\n * drawing and attributes as markSvg.\n */\nexport function markElement(doc: Document, options: Omit<MarkSvgOptions, 'className'> & { className?: string } = {}): SVGSVGElement {\n const variant = options.variant ?? 'mono';\n if (variant !== 'mono' && variant !== 'brand' && variant !== 'tile') throw new TypeError(`markElement: unknown variant ${String(variant)}`);\n const width = options.width ?? (variant === 'tile' ? '1.25em' : '1.75em');\n const color = options.color ?? 'currentColor';\n const el = <K extends keyof SVGElementTagNameMap>(tag: K, attrs: Record<string, string>) => {\n const node = doc.createElementNS(SVG_NS, tag);\n for (const [k, v] of Object.entries(attrs)) node.setAttribute(k, v);\n return node;\n };\n const svg = el('svg', {\n viewBox: variant === 'tile' ? MARK_TILE.viewBox : MARK_VIEWBOX,\n width,\n height: heightFor(variant, width),\n 'data-oc-mark': variant,\n });\n if (options.className) svg.setAttribute('class', options.className);\n if (options.title) {\n svg.setAttribute('role', 'img');\n const title = el('title', {});\n title.textContent = options.title;\n svg.append(title);\n } else {\n svg.setAttribute('aria-hidden', 'true');\n svg.setAttribute('focusable', 'false');\n }\n const parent = variant === 'tile' ? el('g', { transform: MARK_TILE.transform }) : svg;\n if (variant === 'tile') svg.append(el('rect', { width: '24', height: '24', rx: String(MARK_TILE.radius), fill: MARK_TILE.fill }), parent);\n for (const face of ORDER) {\n const attrs: Record<string, string> = { points: MARK_POINTS[face] };\n if (variant === 'mono') {\n attrs.fill = color;\n if (opacity(face, !!options.flat) !== 1) attrs['fill-opacity'] = String(opacity(face, !!options.flat));\n } else attrs.fill = MARK_FACES[face];\n parent.append(el('polygon', attrs));\n }\n return svg;\n}\n","/**\n * Browser only: `signInWithOc` opens the orangecheck sign-in popup and resolves\n * with a token bound to your origin; `signInWithOcOutcome` says why when it\n * does not. Verify the token on your server with\n * [`@orangecheck/me-client/server`](/sdk/me-client/server/README).\n *\n * @packageDocumentation\n */\n\n/**\n * @orangecheck/me-client/popup\n *\n * Browser-side helper that opens the OC sign-in popup, listens for the\n * postMessage from me.ochk.io, and resolves with the verified session.\n *\n * import { signInWithOc } from '@orangecheck/me-client/popup';\n *\n * document.querySelector('#oc-signin')!.addEventListener('click', async () => {\n * const result = await signInWithOc();\n * if (!result) return;\n * // Your server verifies it and keeps it in an httpOnly cookie.\n * const r = await fetch('/api/auth/session', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ token: result.token }),\n * });\n * if (r.ok) location.assign('/app');\n * });\n *\n * Why this lives in a separate entry point: it's browser-only (uses\n * window.open / addEventListener) and integrators that only need the\n * server-side verifier shouldn't pull popup orchestration into their\n * server bundle.\n */\n\nconst DEFAULT_POPUP_ORIGIN = 'https://me.ochk.io';\nconst DEFAULT_POPUP_PATH = '/popup/signin';\nconst DEFAULT_FEATURES = 'width=480,height=720,resizable=yes,scrollbars=yes';\n\nexport interface OcPopupAccount {\n id?: string;\n /** Opaque public identity · `did:oc:<32-hex>`. Stable across linking\n * events. The canonical identifier post auth-refactor (Dec 2025\n * +). */\n did_oc?: string;\n /** Primary linked Bitcoin address, if the user has one and is\n * surfacing it (same-origin family integrators get it inline;\n * cross-domain integrators need the bitcoin_address scope). */\n primary_btc?: string | null;\n /** Whether the user has a primary email linked (plaintext stays\n * on auth host; only the boolean reaches integrators). */\n has_email?: boolean;\n /** Legacy fields kept for back-compat with pre-refactor consumers.\n * Prefer did_oc + primary_btc. Removed in a future major. */\n address?: string;\n btc_address?: string;\n display_name?: string | null;\n nostr_npub?: string | null;\n wallet_provisioned?: boolean;\n email?: string;\n}\n\nexport interface OcPopupResult {\n /** Account payload from the auth host, unsigned: trust only the\n * verified token. `did_oc` is the account's opaque identifier, the\n * same at every site; the email and Bitcoin address stay private\n * unless the user grants a scope. */\n account: OcPopupAccount;\n /** The session JWT, bound to your origin. Hand it once to your own\n * server, which verifies it and keeps it in an httpOnly cookie; never\n * in localStorage, where any script on the page can read it. Family\n * sites (*.ochk.io) can ignore it: the Domain=.ochk.io cookie rides\n * home on its own. */\n token: string;\n}\n\nexport interface SignInWithOcOptions {\n /** Origin of the OC popup page. Defaults to https://me.ochk.io.\n * Override only for staging / preview environments. */\n popupOrigin?: string;\n /** Path on the popup origin. Defaults to /popup/signin. */\n popupPath?: string;\n /** window.open features string. Defaults to a 480x720 resizable\n * popup with scrollbars. */\n features?: string;\n /** AbortSignal that cancels the wait and closes the popup. */\n signal?: AbortSignal;\n}\n\n/**\n * How a sign-in popup ended:\n * - `signed_in` · the person signed in; `account` and `token` as from signInWithOc.\n * - `blocked` · the browser refused to open the window. Ask the person to\n * allow pop-ups for your site, then try again from a click.\n * - `closed` · the person closed the window without signing in.\n * - `aborted` · your AbortSignal fired.\n * - `failed` · not in a browser, or the popup's answer was malformed.\n */\nexport type OcPopupOutcome =\n | ({ status: 'signed_in' } & OcPopupResult)\n | { status: 'blocked' }\n | { status: 'closed' }\n | { status: 'aborted' }\n | { status: 'failed' };\n\n/**\n * Open the OC signin popup and resolve with how it ended (OcPopupOutcome),\n * so a blocked window and a closed one can be told apart.\n *\n * MUST be called inside a user-gesture handler (e.g. a button onClick).\n * Browsers block `window.open` outside of user gestures.\n */\nexport function signInWithOcOutcome(options: SignInWithOcOptions = {}): Promise<OcPopupOutcome> {\n const popupOrigin = options.popupOrigin ?? DEFAULT_POPUP_ORIGIN;\n const popupPath = options.popupPath ?? DEFAULT_POPUP_PATH;\n const features = options.features ?? DEFAULT_FEATURES;\n\n return new Promise((resolve) => {\n if (typeof window === 'undefined') {\n resolve({ status: 'failed' });\n return;\n }\n\n const url = new URL(popupPath, popupOrigin);\n url.searchParams.set('opener_origin', window.location.origin);\n const popup = window.open(url.toString(), 'oc-signin', features);\n if (!popup) {\n resolve({ status: 'blocked' });\n return;\n }\n popup.focus();\n\n let settled = false;\n const cleanup = () => {\n window.removeEventListener('message', onMessage);\n clearInterval(closedTimer);\n if (options.signal) options.signal.removeEventListener('abort', onAbort);\n };\n\n function settle(value: OcPopupOutcome) {\n if (settled) return;\n settled = true;\n cleanup();\n try {\n if (popup && !popup.closed) popup.close();\n } catch {\n /* popup may have closed itself first */\n }\n resolve(value);\n }\n\n function onMessage(event: MessageEvent) {\n // Origin pinning is necessary but not sufficient — same-origin\n // pages other than our popup can post the same shape. Pin both\n // origin AND source window so only the popup we opened can\n // settle this promise.\n if (event.origin !== popupOrigin) return;\n if (event.source !== popup) return;\n const data = event.data as\n | { type?: string; account?: OcPopupAccount; token?: string }\n | null;\n if (!data || data.type !== 'oc-signin-success') return;\n if (!data.account || !data.token) {\n settle({ status: 'failed' });\n return;\n }\n settle({ status: 'signed_in', account: data.account, token: data.token });\n }\n\n function onAbort() {\n settle({ status: 'aborted' });\n }\n\n window.addEventListener('message', onMessage);\n if (options.signal) {\n if (options.signal.aborted) {\n settle({ status: 'aborted' });\n return;\n }\n options.signal.addEventListener('abort', onAbort);\n }\n\n // Detect the person closing the popup without completing signin.\n const closedTimer = setInterval(() => {\n if (popup && popup.closed) settle({ status: 'closed' });\n }, 500);\n });\n}\n\n/**\n * Open the OC signin popup and resolve with the session result. Returns\n * `null` if the user closed the popup without completing signin, if the\n * browser blocked it, or if the AbortSignal fired. To tell those apart,\n * use signInWithOcOutcome.\n *\n * MUST be called inside a user-gesture handler (e.g. a button onClick).\n * Browsers block `window.open` outside of user gestures.\n */\nexport async function signInWithOc(options: SignInWithOcOptions = {}): Promise<OcPopupResult | null> {\n const outcome = await signInWithOcOutcome(options);\n return outcome.status === 'signed_in' ? { account: outcome.account, token: outcome.token } : null;\n}\n","/**\n * Browser only, no framework: a \"Sign in with orangecheck\" button that keeps\n * your site's own look. Write your button as you write every other one, add\n * `data-oc-sign-in`, and enhance it: this adds the orangecheck mark and the\n * label, opens the sign-in popup inside the click, holds the busy state, and\n * says how the popup ended. Optional stylesheet: `@orangecheck/me-client/button.css`.\n *\n * <button class=\"cta ghost\" data-oc-sign-in>Sign in with orangecheck</button>\n *\n * import { enhanceSignInButton } from '@orangecheck/me-client/button';\n * enhanceSignInButton(document.querySelector('[data-oc-sign-in]'), {\n * onSignedIn: async ({ token }) => { … },\n * });\n *\n * The file has no imports at run time (the mark and the popup are bundled\n * in), so it can be copied onto your own origin under a strict CSP.\n *\n * @packageDocumentation\n */\n\nimport { markElement, type MarkVariant } from '@orangecheck/mark';\n\nimport { signInWithOcOutcome, type OcPopupOutcome, type OcPopupResult, type SignInWithOcOptions } from './popup';\n\nexport type { MarkVariant } from '@orangecheck/mark';\nexport type { OcPopupOutcome, OcPopupResult, SignInWithOcOptions } from './popup';\n\n/**\n * The approved English labels. A label in another language is fine too, as\n * long as it keeps the word \"orangecheck\", lowercase, as written.\n */\nexport const SIGN_IN_LABELS = {\n signIn: 'Sign in with orangecheck',\n continue: 'Continue with orangecheck',\n signUp: 'Sign up with orangecheck',\n} as const;\nexport type SignInLabel = string;\n\n/** What the button says while the sign-in window is open (the default; `busyLabel` sets your own). */\nexport const SIGN_IN_BUSY_LABEL = 'Signing in…';\n\n/** What to tell the person when the window did not end in a sign-in. Show it near the button. */\nexport const OUTCOME_COPY = {\n blocked: 'Your browser blocked the sign-in window. Allow pop-ups for this site, then try again.',\n closed: 'The sign-in window closed before you finished.',\n failed: \"Sign-in didn't finish. Try again.\",\n} as const;\n\n/** `inherit`: no colour, font or radius of its own; your classes draw it. `brand`: orangecheck's button, themed by --oc-* properties. */\nexport type SignInAppearance = 'inherit' | 'brand';\n\nexport interface EnhanceSignInButtonOptions {\n /** Called with the popup's account and token once the person signs in; the button stays busy until it settles. */\n onSignedIn: (result: OcPopupResult) => void | Promise<void>;\n /** Called with how every popup ended, sign-in included. Use OUTCOME_COPY for the words. */\n onOutcome?: (outcome: OcPopupOutcome) => void;\n /** The mark beside the label: `mono` (your text colour, the default), `brand` (dark buttons), `tile`, or `false` for none. */\n mark?: MarkVariant | false;\n /**\n * The words: one of SIGN_IN_LABELS (default \"Sign in with orangecheck\"), or\n * the same in your language, keeping \"orangecheck\" as written. `false` draws\n * the mark alone, square, named by `accessibleLabel`.\n */\n label?: SignInLabel | false;\n /** What it says while the window is open. Default \"Signing in…\". */\n busyLabel?: string;\n /** The accessible name of a mark-only button (`label: false`). Default \"Sign in with orangecheck\". */\n accessibleLabel?: string;\n appearance?: SignInAppearance;\n /** Passed to the popup (a preview origin, say). */\n popup?: Omit<SignInWithOcOptions, 'signal'>;\n}\n\nconst MARKS = new Set<unknown>(['mono', 'brand', 'tile', false]);\nconst KEYS = new Set(['onSignedIn', 'onOutcome', 'mark', 'label', 'busyLabel', 'accessibleLabel', 'appearance', 'popup']);\n/** The name, as written: lowercase, a word of its own. */\nconst NAMED = /(^|[^\\p{L}\\p{N}])orangecheck($|[^\\p{L}\\p{N}])/u;\n\nexport interface CheckedSignInOptions {\n mark: MarkVariant | false;\n label: string | false;\n busyLabel: string;\n accessibleLabel: string;\n appearance: SignInAppearance;\n}\n\n/** The options, checked: a misspelt key, or words without \"orangecheck\" in them, fail loudly, not quietly. */\nexport function checkSignInOptions(options: EnhanceSignInButtonOptions): CheckedSignInOptions {\n for (const key of Object.keys(options)) if (!KEYS.has(key)) throw new TypeError(`sign-in button: unknown option ${key}`);\n if (typeof options.onSignedIn !== 'function') throw new TypeError('sign-in button: onSignedIn is required');\n const label = options.label ?? SIGN_IN_LABELS.signIn;\n if (label !== false && (typeof label !== 'string' || !NAMED.test(label))) {\n throw new TypeError(`sign-in button: \"${String(label)}\" must say \"orangecheck\", lowercase, as written; see SIGN_IN_LABELS`);\n }\n const accessibleLabel = options.accessibleLabel ?? SIGN_IN_LABELS.signIn;\n if (!NAMED.test(accessibleLabel)) throw new TypeError(`sign-in button: accessibleLabel \"${accessibleLabel}\" must say \"orangecheck\"`);\n const busyLabel = options.busyLabel ?? SIGN_IN_BUSY_LABEL;\n if (typeof busyLabel !== 'string' || !busyLabel.trim()) throw new TypeError('sign-in button: busyLabel must be words');\n const mark = options.mark ?? 'mono';\n if (!MARKS.has(mark)) throw new TypeError(`sign-in button: unknown mark ${String(mark)}`);\n if (label === false && mark === false) throw new TypeError('sign-in button: with no label it needs the mark');\n const appearance = options.appearance ?? 'inherit';\n if (appearance !== 'inherit' && appearance !== 'brand') throw new TypeError(`sign-in button: unknown appearance ${String(appearance)}`);\n return { label, mark, busyLabel, accessibleLabel, appearance };\n}\n\n/**\n * Holds the button's width while its words change, so nothing beside it moves.\n * Set through the CSS object model, which no Content-Security-Policy blocks.\n */\nexport function holdWidth(button: HTMLElement): () => void {\n const { width: was, minWidth: wasMin } = button.style;\n const width = button.getBoundingClientRect().width;\n // The minimum too: shorter words would otherwise let a flex row shrink it.\n if (width > 0) button.style.width = button.style.minWidth = `${width}px`;\n return () => {\n button.style.width = was;\n button.style.minWidth = wasMin;\n };\n}\n\n/**\n * Make `button` an orangecheck sign-in button. Its classes and styles stay\n * yours; its content becomes the mark and the label. A `[data-oc-mark]`\n * already in the button (a placeholder `<span>`, sized by button.css exactly as\n * the mark is) is replaced by the mark, so the button's size does not change as\n * it is drawn; its value, if any, names the variant. With no\n * `label` given, words already in the button that say \"orangecheck\" are kept.\n * While the window is open it is `aria-disabled` and `aria-busy`, still\n * focusable, and holds its width. Returns a function that undoes it.\n */\nexport function enhanceSignInButton(button: HTMLButtonElement, options: EnhanceSignInButtonOptions): () => void {\n if (!button || button.tagName !== 'BUTTON') throw new TypeError('sign-in button: pass a <button> element');\n const doc = button.ownerDocument;\n const own = (button.querySelector('[data-oc-label]')?.textContent ?? button.textContent ?? '').trim();\n const iconOnly = options.label === false || (options.label === undefined && button.getAttribute('data-label') === 'none');\n const written = options.label === undefined && !iconOnly && NAMED.test(own) ? own : options.label;\n // A placeholder may name the variant: <span data-oc-mark=\"brand\"></span>.\n const hinted = button.querySelector('[data-oc-mark]')?.getAttribute('data-oc-mark');\n const variant = options.mark === undefined && hinted && MARKS.has(hinted) ? (hinted as MarkVariant) : options.mark;\n const checked = checkSignInOptions({ ...options, mark: variant, label: iconOnly ? false : written });\n const { label, mark, appearance, busyLabel, accessibleLabel } = checked;\n const before = {\n nodes: [...button.childNodes],\n type: button.getAttribute('type'),\n aria: button.getAttribute('aria-label'),\n dataLabel: button.getAttribute('data-label'),\n };\n\n if (!before.type) button.type = 'button';\n button.setAttribute('data-oc-sign-in', '');\n button.setAttribute('data-appearance', appearance);\n // Built node by node: no HTML is parsed, so Trusted Types and strict CSPs allow it.\n const markEl = mark ? markElement(doc, { variant: mark }) : null;\n const text = doc.createElement('span');\n text.setAttribute('data-oc-label', '');\n if (label === false) {\n button.setAttribute('data-label', 'none');\n button.setAttribute('aria-label', accessibleLabel);\n button.replaceChildren(markEl!);\n } else {\n text.textContent = label;\n button.replaceChildren(...(markEl ? [markEl] : []), text);\n }\n\n let busy = false;\n let release: (() => void) | null = null;\n const setBusy = (on: boolean) => {\n busy = on;\n if (on) {\n release = holdWidth(button);\n if (label !== false) text.textContent = busyLabel;\n button.setAttribute('aria-disabled', 'true');\n button.setAttribute('aria-busy', 'true');\n } else {\n if (label !== false) text.textContent = label;\n button.removeAttribute('aria-disabled');\n button.removeAttribute('aria-busy');\n release?.();\n release = null;\n }\n };\n\n const onClick = async (event: MouseEvent) => {\n event.preventDefault();\n if (busy || button.disabled) return;\n // Opened before anything is awaited: a window opened later is blocked.\n const pending = signInWithOcOutcome(options.popup);\n setBusy(true);\n try {\n const outcome = await pending;\n options.onOutcome?.(outcome);\n if (outcome.status === 'signed_in') await options.onSignedIn({ account: outcome.account, token: outcome.token });\n } finally {\n setBusy(false);\n }\n };\n button.addEventListener('click', onClick);\n\n return () => {\n button.removeEventListener('click', onClick);\n button.replaceChildren(...before.nodes);\n if (before.type === null) button.removeAttribute('type');\n for (const a of ['data-oc-sign-in', 'data-appearance', 'aria-disabled', 'aria-busy']) button.removeAttribute(a);\n if (before.aria === null) button.removeAttribute('aria-label');\n else button.setAttribute('aria-label', before.aria);\n if (before.dataLabel === null) button.removeAttribute('data-label');\n else button.setAttribute('data-label', before.dataLabel);\n };\n}\n"]}
package/dist/react.d.mts CHANGED
@@ -6,6 +6,6 @@ export { MarkVariant } from '@orangecheck/mark';
6
6
  export { OcPopupOutcome, OcPopupResult } from './popup.mjs';
7
7
 
8
8
  type SignInWithOrangecheckProps = EnhanceSignInButtonOptions & Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'onClick' | 'children' | 'type'>;
9
- declare function SignInWithOrangecheck({ onSignedIn, onOutcome, mark, label, appearance, popup, disabled, ...rest }: SignInWithOrangecheckProps): react_jsx_runtime.JSX.Element;
9
+ declare function SignInWithOrangecheck({ onSignedIn, onOutcome, mark, label, busyLabel, accessibleLabel, appearance, popup, disabled, ...rest }: SignInWithOrangecheckProps): react_jsx_runtime.JSX.Element;
10
10
 
11
11
  export { EnhanceSignInButtonOptions, SignInWithOrangecheck, type SignInWithOrangecheckProps };
package/dist/react.d.ts CHANGED
@@ -6,6 +6,6 @@ export { MarkVariant } from '@orangecheck/mark';
6
6
  export { OcPopupOutcome, OcPopupResult } from './popup.js';
7
7
 
8
8
  type SignInWithOrangecheckProps = EnhanceSignInButtonOptions & Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'onClick' | 'children' | 'type'>;
9
- declare function SignInWithOrangecheck({ onSignedIn, onOutcome, mark, label, appearance, popup, disabled, ...rest }: SignInWithOrangecheckProps): react_jsx_runtime.JSX.Element;
9
+ declare function SignInWithOrangecheck({ onSignedIn, onOutcome, mark, label, busyLabel, accessibleLabel, appearance, popup, disabled, ...rest }: SignInWithOrangecheckProps): react_jsx_runtime.JSX.Element;
10
10
 
11
11
  export { EnhanceSignInButtonOptions, SignInWithOrangecheck, type SignInWithOrangecheckProps };
package/dist/react.js CHANGED
@@ -11,7 +11,7 @@ var MARK_POINTS = {
11
11
  };
12
12
  var MARK_VIEWBOX = "0 0 16 8";
13
13
  var MARK_FACES = { top: "#FED8AB", left: "#FB933C", right: "#EA580B" };
14
- var MARK_MONO_OPACITY = { top: 1, left: 0.7, right: 0.45 };
14
+ var MARK_MONO_OPACITY = { top: 1, left: 0.6, right: 0.3 };
15
15
  var MARK_TILE = {
16
16
  viewBox: "0 0 24 24",
17
17
  radius: 6.25,
@@ -24,11 +24,11 @@ function half(size) {
24
24
  const m = /^(-?[\d.]+)([a-z%]*)$/i.exec(size.trim());
25
25
  return m ? `${Number(m[1]) / 2}${m[2]}` : "auto";
26
26
  }
27
- function OrangecheckMark({ variant = "mono", title, size, color = "currentColor", ...rest }) {
28
- const width = size ?? (variant === "tile" ? "1.25em" : "1.5em");
27
+ function OrangecheckMark({ variant = "mono", title, size, color = "currentColor", flat = false, ...rest }) {
28
+ const width = size ?? (variant === "tile" ? "1.25em" : "1.75em");
29
29
  const a11y = title ? { role: "img" } : { "aria-hidden": true, focusable: false };
30
30
  const polys = ORDER2.map(
31
- (face) => variant === "mono" ? /* @__PURE__ */ jsxRuntime.jsx("polygon", { points: MARK_POINTS[face], fill: color, fillOpacity: MARK_MONO_OPACITY[face] === 1 ? void 0 : MARK_MONO_OPACITY[face] }, face) : /* @__PURE__ */ jsxRuntime.jsx("polygon", { points: MARK_POINTS[face], fill: MARK_FACES[face] }, face)
31
+ (face) => variant === "mono" ? /* @__PURE__ */ jsxRuntime.jsx("polygon", { points: MARK_POINTS[face], fill: color, fillOpacity: flat || MARK_MONO_OPACITY[face] === 1 ? void 0 : MARK_MONO_OPACITY[face] }, face) : /* @__PURE__ */ jsxRuntime.jsx("polygon", { points: MARK_POINTS[face], fill: MARK_FACES[face] }, face)
32
32
  );
33
33
  if (variant === "tile") {
34
34
  return /* @__PURE__ */ jsxRuntime.jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: MARK_TILE.viewBox, width, height: width, "data-oc-mark": "tile", ...a11y, ...rest, children: [
@@ -120,49 +120,84 @@ var OUTCOME_COPY = {
120
120
  closed: "The sign-in window closed before you finished.",
121
121
  failed: "Sign-in didn't finish. Try again."
122
122
  };
123
- var LABELS = new Set(Object.values(SIGN_IN_LABELS));
124
123
  var MARKS = /* @__PURE__ */ new Set(["mono", "brand", "tile", false]);
125
- var KEYS = /* @__PURE__ */ new Set(["onSignedIn", "onOutcome", "mark", "label", "appearance", "popup"]);
124
+ var KEYS = /* @__PURE__ */ new Set(["onSignedIn", "onOutcome", "mark", "label", "busyLabel", "accessibleLabel", "appearance", "popup"]);
125
+ var NAMED = /(^|[^\p{L}\p{N}])orangecheck($|[^\p{L}\p{N}])/u;
126
126
  function checkSignInOptions(options) {
127
127
  for (const key of Object.keys(options)) if (!KEYS.has(key)) throw new TypeError(`sign-in button: unknown option ${key}`);
128
128
  if (typeof options.onSignedIn !== "function") throw new TypeError("sign-in button: onSignedIn is required");
129
129
  const label = options.label ?? SIGN_IN_LABELS.signIn;
130
- if (!LABELS.has(label)) throw new TypeError(`sign-in button: "${label}" is not an approved label; use one of SIGN_IN_LABELS`);
130
+ if (label !== false && (typeof label !== "string" || !NAMED.test(label))) {
131
+ throw new TypeError(`sign-in button: "${String(label)}" must say "orangecheck", lowercase, as written; see SIGN_IN_LABELS`);
132
+ }
133
+ const accessibleLabel = options.accessibleLabel ?? SIGN_IN_LABELS.signIn;
134
+ if (!NAMED.test(accessibleLabel)) throw new TypeError(`sign-in button: accessibleLabel "${accessibleLabel}" must say "orangecheck"`);
135
+ const busyLabel = options.busyLabel ?? SIGN_IN_BUSY_LABEL;
136
+ if (typeof busyLabel !== "string" || !busyLabel.trim()) throw new TypeError("sign-in button: busyLabel must be words");
131
137
  const mark = options.mark ?? "mono";
132
138
  if (!MARKS.has(mark)) throw new TypeError(`sign-in button: unknown mark ${String(mark)}`);
139
+ if (label === false && mark === false) throw new TypeError("sign-in button: with no label it needs the mark");
133
140
  const appearance = options.appearance ?? "inherit";
134
141
  if (appearance !== "inherit" && appearance !== "brand") throw new TypeError(`sign-in button: unknown appearance ${String(appearance)}`);
135
- return { label, mark, appearance };
142
+ return { label, mark, busyLabel, accessibleLabel, appearance };
143
+ }
144
+ function holdWidth(button) {
145
+ const { width: was, minWidth: wasMin } = button.style;
146
+ const width = button.getBoundingClientRect().width;
147
+ if (width > 0) button.style.width = button.style.minWidth = `${width}px`;
148
+ return () => {
149
+ button.style.width = was;
150
+ button.style.minWidth = wasMin;
151
+ };
136
152
  }
137
- function SignInWithOrangecheck({ onSignedIn, onOutcome, mark, label, appearance, popup, disabled, ...rest }) {
138
- const options = checkSignInOptions({ onSignedIn, onOutcome, mark, label, appearance, popup });
153
+ function SignInWithOrangecheck({
154
+ onSignedIn,
155
+ onOutcome,
156
+ mark,
157
+ label,
158
+ busyLabel,
159
+ accessibleLabel,
160
+ appearance,
161
+ popup,
162
+ disabled,
163
+ ...rest
164
+ }) {
165
+ const options = checkSignInOptions({ onSignedIn, onOutcome, mark, label, busyLabel, accessibleLabel, appearance, popup });
139
166
  const [busy, setBusy] = react.useState(false);
167
+ const ref = react.useRef(null);
140
168
  async function onClick() {
141
169
  if (busy || disabled) return;
142
- setBusy(true);
143
170
  const pending = signInWithOcOutcome(popup);
171
+ const release = ref.current ? holdWidth(ref.current) : () => {
172
+ };
173
+ setBusy(true);
144
174
  try {
145
175
  const outcome = await pending;
146
176
  onOutcome?.(outcome);
147
177
  if (outcome.status === "signed_in") await onSignedIn({ account: outcome.account, token: outcome.token });
148
178
  } finally {
149
179
  setBusy(false);
180
+ release();
150
181
  }
151
182
  }
183
+ const iconOnly = options.label === false;
152
184
  return /* @__PURE__ */ jsxRuntime.jsxs(
153
185
  "button",
154
186
  {
155
187
  ...rest,
188
+ ref,
156
189
  type: "button",
157
190
  disabled,
158
191
  "data-oc-sign-in": "",
159
192
  "data-appearance": options.appearance,
193
+ "data-label": iconOnly ? "none" : void 0,
194
+ "aria-label": iconOnly ? options.accessibleLabel : rest["aria-label"],
160
195
  "aria-disabled": busy || void 0,
161
196
  "aria-busy": busy || void 0,
162
197
  onClick: () => void onClick(),
163
198
  children: [
164
199
  options.mark ? /* @__PURE__ */ jsxRuntime.jsx(OrangecheckMark, { variant: options.mark }) : null,
165
- /* @__PURE__ */ jsxRuntime.jsx("span", { "data-oc-label": "", children: busy ? SIGN_IN_BUSY_LABEL : options.label })
200
+ iconOnly ? null : /* @__PURE__ */ jsxRuntime.jsx("span", { "data-oc-label": "", children: busy ? options.busyLabel : options.label })
166
201
  ]
167
202
  }
168
203
  );