@orangecheck/me-client 0.44.0 → 0.46.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/README.md CHANGED
@@ -24,6 +24,10 @@ import { withOcAuth, ocAuthExpress, ocAuthHono } from '@orangecheck/me-client/se
24
24
  // Browser-only popup orchestrator — same shape Google / GitHub use.
25
25
  import { signInWithOc } from '@orangecheck/me-client/popup';
26
26
 
27
+ // The "Sign in with orangecheck" button, in your site's own style.
28
+ import { enhanceSignInButton } from '@orangecheck/me-client/button'; // any page
29
+ import { SignInWithOrangecheck } from '@orangecheck/me-client/react'; // React
30
+
27
31
  // Keep your own login: make an orangecheck account for your user (OC Connect).
28
32
  import { connectProvision } from '@orangecheck/me-client/server';
29
33
  import { CONNECT_CONSENT_LABEL } from '@orangecheck/me-client/connect-consent';
@@ -330,6 +334,50 @@ if (outcome.status === 'signed_in') await keepSession(outcome.token);
330
334
  // 'closed' (the person closed the window), 'aborted' (your signal), 'failed' (not a browser, or a malformed answer)
331
335
  ``` Pins both `event.origin` AND `event.source === popup` on the postMessage handler so a same-origin attacker can't settle the promise.
332
336
 
337
+ ## The sign-in button
338
+
339
+ Your button, your style: the package adds the orangecheck mark (from
340
+ [`@orangecheck/mark`](https://www.npmjs.com/package/@orangecheck/mark)), an
341
+ approved label, the popup inside the click, and the busy state. Rules and live
342
+ examples: [ochk.io/docs/integration/sign-in-button](https://ochk.io/docs/integration/sign-in-button).
343
+
344
+ ```html
345
+ <button class="your-button" data-oc-sign-in>Sign in with orangecheck</button>
346
+ <script type="module">
347
+ import { enhanceSignInButton, OUTCOME_COPY } from '/vendor/oc-sign-in.mjs'; // dist/button.mjs, copied
348
+ enhanceSignInButton(document.querySelector('[data-oc-sign-in]'), {
349
+ onSignedIn: async ({ token }) => {
350
+ const r = await fetch('/api/auth/session', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ token }) });
351
+ if (r.ok) location.assign('/dashboard');
352
+ },
353
+ onOutcome: (o) => { if (o.status !== 'signed_in' && o.status !== 'aborted') showNote(OUTCOME_COPY[o.status]); },
354
+ });
355
+ </script>
356
+ ```
357
+
358
+ ```tsx
359
+ import { SignInWithOrangecheck } from '@orangecheck/me-client/react';
360
+ import '@orangecheck/me-client/button.css'; // optional: spacing, a 44px target, a focus ring
361
+
362
+ <SignInWithOrangecheck className="btn btn-outline" onSignedIn={({ token }) => keepSession(token)} />;
363
+ ```
364
+
365
+ - `appearance`: `inherit` (default) sets no colour, font, border or radius;
366
+ your class draws it. `brand` is orangecheck's ink button, themed by
367
+ `--oc-button-bg`, `-fg`, `-border`, `-radius`, `-font`, `-size`, `-weight`,
368
+ `-pad`, `-hover-bg` and `--oc-focus`.
369
+ - `mark`: `mono` (default, your text colour), `brand` (dark buttons), `tile`
370
+ (any button), or `false`.
371
+ - `label`: one of `SIGN_IN_LABELS`: "Sign in with orangecheck" (default),
372
+ "Continue with orangecheck", "Sign up with orangecheck". Anything else throws.
373
+ - While the window is open the button is `aria-busy` and `aria-disabled`, still
374
+ focusable, says "Signing in…", and opens no second window.
375
+ - `button.css` is optional and has zero specificity: every rule of yours wins.
376
+ Tune it with `--oc-mark-gap`, `--oc-mark-size`, `--oc-target` and `--oc-focus`.
377
+ - `dist/button.mjs` has no imports, so it can be served from your own origin
378
+ under `script-src 'self'`. It builds the mark node by node: no `innerHTML`, so
379
+ Trusted Types are fine too.
380
+
333
381
  ## Custom origin
334
382
 
335
383
  For staging, self-hosted me-equivalents, or local dev:
@@ -0,0 +1,73 @@
1
+ /*
2
+ * @orangecheck/me-client/button.css: the sign-in button's own rules, inside
3
+ * :where(), so their specificity is zero (one pseudo-class for focus and
4
+ * hover) and your own rules win. Optional: without it the button is your
5
+ * button with the mark in it.
6
+ *
7
+ * appearance "inherit" (the default) sets no colour, font, border or radius:
8
+ * only the mark's spacing, a 44px target and a focus ring for a site that has
9
+ * none. appearance "brand" is orangecheck's button, themed by --oc-* properties.
10
+ */
11
+
12
+ :where([data-oc-sign-in]) {
13
+ display: inline-flex;
14
+ align-items: center;
15
+ justify-content: center;
16
+ gap: var(--oc-mark-gap, 0.5em);
17
+ min-block-size: var(--oc-target, 44px);
18
+ cursor: pointer;
19
+ }
20
+
21
+ :where([data-oc-sign-in]) :where([data-oc-mark]) {
22
+ flex: none;
23
+ inline-size: var(--oc-mark-size, 1.5em);
24
+ block-size: auto;
25
+ }
26
+
27
+ :where([data-oc-sign-in]) :where([data-oc-mark='tile']) {
28
+ inline-size: var(--oc-mark-size, 1.25em);
29
+ }
30
+
31
+ :where([data-oc-sign-in]):focus-visible {
32
+ outline: 2px solid var(--oc-focus, currentColor);
33
+ outline-offset: 2px;
34
+ }
35
+
36
+ :where([data-oc-sign-in][aria-busy='true']) {
37
+ cursor: progress;
38
+ }
39
+
40
+ :where([data-oc-sign-in]:disabled) {
41
+ cursor: not-allowed;
42
+ }
43
+
44
+ :where([data-oc-sign-in][data-appearance='brand']) {
45
+ padding-inline: var(--oc-button-pad, 1.25em);
46
+ border: 1px solid var(--oc-button-border, #262626);
47
+ border-radius: var(--oc-button-radius, 10px);
48
+ background: var(--oc-button-bg, #0a0a0a);
49
+ color: var(--oc-button-fg, #fafafa);
50
+ font-family: var(--oc-button-font, inherit);
51
+ font-size: var(--oc-button-size, 1rem);
52
+ font-weight: var(--oc-button-weight, 600);
53
+ line-height: 1.2;
54
+ transition: background-color 120ms ease;
55
+ }
56
+
57
+ :where([data-oc-sign-in][data-appearance='brand']):hover {
58
+ background: var(--oc-button-hover-bg, #262626);
59
+ }
60
+
61
+ :where([data-oc-sign-in][data-appearance='brand']):focus-visible {
62
+ outline-color: var(--oc-focus, #fb933c);
63
+ }
64
+
65
+ :where([data-oc-sign-in][data-appearance='brand']:disabled) {
66
+ opacity: 0.55;
67
+ }
68
+
69
+ @media (prefers-reduced-motion: reduce) {
70
+ :where([data-oc-sign-in][data-appearance='brand']) {
71
+ transition: none;
72
+ }
73
+ }
@@ -0,0 +1,29 @@
1
+ import { MarkVariant } from '@orangecheck/mark';
2
+ export { MarkVariant } from '@orangecheck/mark';
3
+ import { OcPopupResult, OcPopupOutcome, SignInWithOcOptions } from './popup.mjs';
4
+
5
+ declare const SIGN_IN_LABELS: {
6
+ readonly signIn: "Sign in with orangecheck";
7
+ readonly continue: "Continue with orangecheck";
8
+ readonly signUp: "Sign up with orangecheck";
9
+ };
10
+ type SignInLabel = (typeof SIGN_IN_LABELS)[keyof typeof SIGN_IN_LABELS];
11
+ declare const SIGN_IN_BUSY_LABEL = "Signing in\u2026";
12
+ declare const OUTCOME_COPY: {
13
+ readonly blocked: "Your browser blocked the sign-in window. Allow pop-ups for this site, then try again.";
14
+ readonly closed: "The sign-in window closed before you finished.";
15
+ readonly failed: "Sign-in didn't finish. Try again.";
16
+ };
17
+ type SignInAppearance = 'inherit' | 'brand';
18
+ interface EnhanceSignInButtonOptions {
19
+ onSignedIn: (result: OcPopupResult) => void | Promise<void>;
20
+ onOutcome?: (outcome: OcPopupOutcome) => void;
21
+ mark?: MarkVariant | false;
22
+ label?: SignInLabel;
23
+ appearance?: SignInAppearance;
24
+ popup?: Omit<SignInWithOcOptions, 'signal'>;
25
+ }
26
+ declare function checkSignInOptions(options: EnhanceSignInButtonOptions): Required<Pick<EnhanceSignInButtonOptions, 'mark' | 'label' | 'appearance'>>;
27
+ declare function enhanceSignInButton(button: HTMLButtonElement, options: EnhanceSignInButtonOptions): () => void;
28
+
29
+ export { type EnhanceSignInButtonOptions, OUTCOME_COPY, OcPopupOutcome, OcPopupResult, SIGN_IN_BUSY_LABEL, SIGN_IN_LABELS, type SignInAppearance, type SignInLabel, SignInWithOcOptions, checkSignInOptions, enhanceSignInButton };
@@ -0,0 +1,29 @@
1
+ import { MarkVariant } from '@orangecheck/mark';
2
+ export { MarkVariant } from '@orangecheck/mark';
3
+ import { OcPopupResult, OcPopupOutcome, SignInWithOcOptions } from './popup.js';
4
+
5
+ declare const SIGN_IN_LABELS: {
6
+ readonly signIn: "Sign in with orangecheck";
7
+ readonly continue: "Continue with orangecheck";
8
+ readonly signUp: "Sign up with orangecheck";
9
+ };
10
+ type SignInLabel = (typeof SIGN_IN_LABELS)[keyof typeof SIGN_IN_LABELS];
11
+ declare const SIGN_IN_BUSY_LABEL = "Signing in\u2026";
12
+ declare const OUTCOME_COPY: {
13
+ readonly blocked: "Your browser blocked the sign-in window. Allow pop-ups for this site, then try again.";
14
+ readonly closed: "The sign-in window closed before you finished.";
15
+ readonly failed: "Sign-in didn't finish. Try again.";
16
+ };
17
+ type SignInAppearance = 'inherit' | 'brand';
18
+ interface EnhanceSignInButtonOptions {
19
+ onSignedIn: (result: OcPopupResult) => void | Promise<void>;
20
+ onOutcome?: (outcome: OcPopupOutcome) => void;
21
+ mark?: MarkVariant | false;
22
+ label?: SignInLabel;
23
+ appearance?: SignInAppearance;
24
+ popup?: Omit<SignInWithOcOptions, 'signal'>;
25
+ }
26
+ declare function checkSignInOptions(options: EnhanceSignInButtonOptions): Required<Pick<EnhanceSignInButtonOptions, 'mark' | 'label' | 'appearance'>>;
27
+ declare function enhanceSignInButton(button: HTMLButtonElement, options: EnhanceSignInButtonOptions): () => void;
28
+
29
+ export { type EnhanceSignInButtonOptions, OUTCOME_COPY, OcPopupOutcome, OcPopupResult, SIGN_IN_BUSY_LABEL, SIGN_IN_LABELS, type SignInAppearance, type SignInLabel, SignInWithOcOptions, checkSignInOptions, enhanceSignInButton };
package/dist/button.js ADDED
@@ -0,0 +1,207 @@
1
+ 'use strict';
2
+
3
+ // node_modules/@orangecheck/mark/dist/index.mjs
4
+ var MARK_POINTS = {
5
+ top: "0,3 2,2 6,4 14,0 16,1 6,6",
6
+ left: "0,3 6,6 6,8 0,5",
7
+ right: "6,6 16,1 16,3 6,8"
8
+ };
9
+ var MARK_VIEWBOX = "0 0 16 8";
10
+ var MARK_FACES = { top: "#FED8AB", left: "#FB933C", right: "#EA580B" };
11
+ var MARK_MONO_OPACITY = { top: 1, left: 0.7, right: 0.45 };
12
+ var MARK_TILE = {
13
+ viewBox: "0 0 24 24",
14
+ radius: 6.25,
15
+ fill: "#0A0A0A",
16
+ transform: "translate(4.25 8.1) scale(0.97)"
17
+ };
18
+ var ORDER = ["left", "right", "top"];
19
+ function heightFor(variant, width) {
20
+ if (variant === "tile") return width;
21
+ const m = /^(-?[\d.]+)([a-z%]*)$/i.exec(width.trim());
22
+ return m ? `${Number(m[1]) / 2}${m[2]}` : "auto";
23
+ }
24
+ var SVG_NS = "http://www.w3.org/2000/svg";
25
+ function markElement(doc, options = {}) {
26
+ const variant = options.variant ?? "mono";
27
+ if (variant !== "mono" && variant !== "brand" && variant !== "tile") throw new TypeError(`markElement: unknown variant ${String(variant)}`);
28
+ const width = options.width ?? (variant === "tile" ? "1.25em" : "1.5em");
29
+ const color = options.color ?? "currentColor";
30
+ const el = (tag, attrs) => {
31
+ const node = doc.createElementNS(SVG_NS, tag);
32
+ for (const [k, v] of Object.entries(attrs)) node.setAttribute(k, v);
33
+ return node;
34
+ };
35
+ const svg = el("svg", {
36
+ viewBox: variant === "tile" ? MARK_TILE.viewBox : MARK_VIEWBOX,
37
+ width,
38
+ height: heightFor(variant, width),
39
+ "data-oc-mark": variant
40
+ });
41
+ if (options.className) svg.setAttribute("class", options.className);
42
+ if (options.title) {
43
+ svg.setAttribute("role", "img");
44
+ const title = el("title", {});
45
+ title.textContent = options.title;
46
+ svg.append(title);
47
+ } else {
48
+ svg.setAttribute("aria-hidden", "true");
49
+ svg.setAttribute("focusable", "false");
50
+ }
51
+ const parent = variant === "tile" ? el("g", { transform: MARK_TILE.transform }) : svg;
52
+ if (variant === "tile") svg.append(el("rect", { width: "24", height: "24", rx: String(MARK_TILE.radius), fill: MARK_TILE.fill }), parent);
53
+ for (const face of ORDER) {
54
+ const attrs = { points: MARK_POINTS[face] };
55
+ if (variant === "mono") {
56
+ attrs.fill = color;
57
+ if (MARK_MONO_OPACITY[face] !== 1) attrs["fill-opacity"] = String(MARK_MONO_OPACITY[face]);
58
+ } else attrs.fill = MARK_FACES[face];
59
+ parent.append(el("polygon", attrs));
60
+ }
61
+ return svg;
62
+ }
63
+
64
+ // src/popup.ts
65
+ var DEFAULT_POPUP_ORIGIN = "https://me.ochk.io";
66
+ var DEFAULT_POPUP_PATH = "/popup/signin";
67
+ var DEFAULT_FEATURES = "width=480,height=720,resizable=yes,scrollbars=yes";
68
+ function signInWithOcOutcome(options = {}) {
69
+ const popupOrigin = options.popupOrigin ?? DEFAULT_POPUP_ORIGIN;
70
+ const popupPath = options.popupPath ?? DEFAULT_POPUP_PATH;
71
+ const features = options.features ?? DEFAULT_FEATURES;
72
+ return new Promise((resolve) => {
73
+ if (typeof window === "undefined") {
74
+ resolve({ status: "failed" });
75
+ return;
76
+ }
77
+ const url = new URL(popupPath, popupOrigin);
78
+ url.searchParams.set("opener_origin", window.location.origin);
79
+ const popup = window.open(url.toString(), "oc-signin", features);
80
+ if (!popup) {
81
+ resolve({ status: "blocked" });
82
+ return;
83
+ }
84
+ popup.focus();
85
+ let settled = false;
86
+ const cleanup = () => {
87
+ window.removeEventListener("message", onMessage);
88
+ clearInterval(closedTimer);
89
+ if (options.signal) options.signal.removeEventListener("abort", onAbort);
90
+ };
91
+ function settle(value) {
92
+ if (settled) return;
93
+ settled = true;
94
+ cleanup();
95
+ try {
96
+ if (popup && !popup.closed) popup.close();
97
+ } catch {
98
+ }
99
+ resolve(value);
100
+ }
101
+ function onMessage(event) {
102
+ if (event.origin !== popupOrigin) return;
103
+ if (event.source !== popup) return;
104
+ const data = event.data;
105
+ if (!data || data.type !== "oc-signin-success") return;
106
+ if (!data.account || !data.token) {
107
+ settle({ status: "failed" });
108
+ return;
109
+ }
110
+ settle({ status: "signed_in", account: data.account, token: data.token });
111
+ }
112
+ function onAbort() {
113
+ settle({ status: "aborted" });
114
+ }
115
+ window.addEventListener("message", onMessage);
116
+ if (options.signal) {
117
+ if (options.signal.aborted) {
118
+ settle({ status: "aborted" });
119
+ return;
120
+ }
121
+ options.signal.addEventListener("abort", onAbort);
122
+ }
123
+ const closedTimer = setInterval(() => {
124
+ if (popup && popup.closed) settle({ status: "closed" });
125
+ }, 500);
126
+ });
127
+ }
128
+
129
+ // src/button.ts
130
+ var SIGN_IN_LABELS = {
131
+ signIn: "Sign in with orangecheck",
132
+ continue: "Continue with orangecheck",
133
+ signUp: "Sign up with orangecheck"
134
+ };
135
+ var SIGN_IN_BUSY_LABEL = "Signing in\u2026";
136
+ var OUTCOME_COPY = {
137
+ blocked: "Your browser blocked the sign-in window. Allow pop-ups for this site, then try again.",
138
+ closed: "The sign-in window closed before you finished.",
139
+ failed: "Sign-in didn't finish. Try again."
140
+ };
141
+ var LABELS = new Set(Object.values(SIGN_IN_LABELS));
142
+ var MARKS = /* @__PURE__ */ new Set(["mono", "brand", "tile", false]);
143
+ var KEYS = /* @__PURE__ */ new Set(["onSignedIn", "onOutcome", "mark", "label", "appearance", "popup"]);
144
+ function checkSignInOptions(options) {
145
+ for (const key of Object.keys(options)) if (!KEYS.has(key)) throw new TypeError(`sign-in button: unknown option ${key}`);
146
+ if (typeof options.onSignedIn !== "function") throw new TypeError("sign-in button: onSignedIn is required");
147
+ const label = options.label ?? SIGN_IN_LABELS.signIn;
148
+ if (!LABELS.has(label)) throw new TypeError(`sign-in button: "${label}" is not an approved label; use one of SIGN_IN_LABELS`);
149
+ const mark = options.mark ?? "mono";
150
+ if (!MARKS.has(mark)) throw new TypeError(`sign-in button: unknown mark ${String(mark)}`);
151
+ const appearance = options.appearance ?? "inherit";
152
+ if (appearance !== "inherit" && appearance !== "brand") throw new TypeError(`sign-in button: unknown appearance ${String(appearance)}`);
153
+ return { label, mark, appearance };
154
+ }
155
+ function enhanceSignInButton(button, options) {
156
+ if (!button || button.tagName !== "BUTTON") throw new TypeError("sign-in button: pass a <button> element");
157
+ const { label, mark, appearance } = checkSignInOptions(options);
158
+ const before = { nodes: [...button.childNodes], type: button.getAttribute("type") };
159
+ const doc = button.ownerDocument;
160
+ if (!before.type) button.type = "button";
161
+ button.setAttribute("data-oc-sign-in", "");
162
+ button.setAttribute("data-appearance", appearance);
163
+ const text = doc.createElement("span");
164
+ text.setAttribute("data-oc-label", "");
165
+ text.textContent = label;
166
+ button.replaceChildren(...mark ? [markElement(doc, { variant: mark })] : [], text);
167
+ let busy = false;
168
+ const setBusy = (on) => {
169
+ busy = on;
170
+ text.textContent = on ? SIGN_IN_BUSY_LABEL : label;
171
+ if (on) {
172
+ button.setAttribute("aria-disabled", "true");
173
+ button.setAttribute("aria-busy", "true");
174
+ } else {
175
+ button.removeAttribute("aria-disabled");
176
+ button.removeAttribute("aria-busy");
177
+ }
178
+ };
179
+ const onClick = async (event) => {
180
+ event.preventDefault();
181
+ if (busy || button.disabled) return;
182
+ setBusy(true);
183
+ const pending = signInWithOcOutcome(options.popup);
184
+ try {
185
+ const outcome = await pending;
186
+ options.onOutcome?.(outcome);
187
+ if (outcome.status === "signed_in") await options.onSignedIn({ account: outcome.account, token: outcome.token });
188
+ } finally {
189
+ setBusy(false);
190
+ }
191
+ };
192
+ button.addEventListener("click", onClick);
193
+ return () => {
194
+ button.removeEventListener("click", onClick);
195
+ button.replaceChildren(...before.nodes);
196
+ if (before.type === null) button.removeAttribute("type");
197
+ for (const a of ["data-oc-sign-in", "data-appearance", "aria-disabled", "aria-busy"]) button.removeAttribute(a);
198
+ };
199
+ }
200
+
201
+ exports.OUTCOME_COPY = OUTCOME_COPY;
202
+ exports.SIGN_IN_BUSY_LABEL = SIGN_IN_BUSY_LABEL;
203
+ exports.SIGN_IN_LABELS = SIGN_IN_LABELS;
204
+ exports.checkSignInOptions = checkSignInOptions;
205
+ exports.enhanceSignInButton = enhanceSignInButton;
206
+ //# sourceMappingURL=button.js.map
207
+ //# sourceMappingURL=button.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../node_modules/@orangecheck/mark/src/index.ts","../src/popup.ts","../src/button.ts"],"names":[],"mappings":";;;AASO,IAAM,WAAA,GAAc;EACvB,GAAA,EAAK,2BAAA;EACL,IAAA,EAAM,iBAAA;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esContent":["/**\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"]}