@orangecheck/me-client 0.46.1 → 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/README.md +20 -10
- package/dist/button.css +37 -8
- package/dist/button.d.mts +14 -4
- package/dist/button.d.ts +14 -4
- package/dist/button.js +60 -13
- package/dist/button.js.map +1 -1
- package/dist/button.mjs +60 -14
- package/dist/button.mjs.map +1 -1
- package/dist/react.d.mts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +47 -12
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +48 -13
- package/dist/react.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -342,7 +342,7 @@ approved label, the popup inside the click, and the busy state. Rules and live
|
|
|
342
342
|
examples: [ochk.io/docs/integration/sign-in-button](https://ochk.io/docs/integration/sign-in-button).
|
|
343
343
|
|
|
344
344
|
```html
|
|
345
|
-
<button class="your-button" data-oc-sign-in>Sign in with orangecheck</button>
|
|
345
|
+
<button class="your-button" data-oc-sign-in><span data-oc-mark></span>Sign in with orangecheck</button>
|
|
346
346
|
<script type="module">
|
|
347
347
|
import { enhanceSignInButton, OUTCOME_COPY } from '/vendor/oc-sign-in.mjs'; // dist/button.mjs, copied
|
|
348
348
|
enhanceSignInButton(document.querySelector('[data-oc-sign-in]'), {
|
|
@@ -355,25 +355,35 @@ examples: [ochk.io/docs/integration/sign-in-button](https://ochk.io/docs/integra
|
|
|
355
355
|
</script>
|
|
356
356
|
```
|
|
357
357
|
|
|
358
|
+
The `<span data-oc-mark>` holds the mark's place, so drawing it moves nothing.
|
|
359
|
+
|
|
358
360
|
```tsx
|
|
359
361
|
import { SignInWithOrangecheck } from '@orangecheck/me-client/react';
|
|
360
|
-
import '@orangecheck/me-client/button.css'; // optional:
|
|
362
|
+
import '@orangecheck/me-client/button.css'; // optional: the mark's size, one line, a 44px target
|
|
361
363
|
|
|
362
364
|
<SignInWithOrangecheck className="btn btn-outline" onSignedIn={({ token }) => keepSession(token)} />;
|
|
363
365
|
```
|
|
364
366
|
|
|
365
|
-
- `appearance`: `inherit` (default) sets no colour, font, border or
|
|
366
|
-
your class draws it. `brand` is orangecheck's
|
|
367
|
-
`--oc-button-bg`, `-fg`, `-border`, `-radius`, `-font`,
|
|
368
|
-
`-pad`, `-hover-bg` and `--oc-focus`.
|
|
367
|
+
- `appearance`: `inherit` (default) sets no colour, font, border, radius or
|
|
368
|
+
focus ring; your class draws it, your ring shows. `brand` is orangecheck's
|
|
369
|
+
ink button, themed by `--oc-button-bg`, `-fg`, `-border`, `-radius`, `-font`,
|
|
370
|
+
`-size`, `-weight`, `-pad`, `-hover-bg` and `--oc-focus`.
|
|
369
371
|
- `mark`: `mono` (default, your text colour), `brand` (dark buttons), `tile`
|
|
370
372
|
(any button), or `false`.
|
|
371
|
-
- `label`:
|
|
372
|
-
|
|
373
|
+
- `label`: "Sign in with orangecheck" by default, or "Continue with
|
|
374
|
+
orangecheck", "Sign up with orangecheck" (`SIGN_IN_LABELS`), or the same in
|
|
375
|
+
your language, as long as it keeps "orangecheck", lowercase, as written.
|
|
376
|
+
Words without it throw. `busyLabel` is what it says while the window is open
|
|
377
|
+
("Signing in…" by default). `label: false` draws the mark alone, named by
|
|
378
|
+
`accessibleLabel` for screen readers.
|
|
373
379
|
- While the window is open the button is `aria-busy` and `aria-disabled`, still
|
|
374
|
-
focusable,
|
|
380
|
+
focusable, keeps its width, and opens no second window.
|
|
375
381
|
- `button.css` is optional and has zero specificity: every rule of yours wins.
|
|
376
|
-
|
|
382
|
+
It keeps the words on one line, sizes the mark before it paints (1.75em),
|
|
383
|
+
gives a 44px target, and draws the mark flat in your text colour when the
|
|
384
|
+
system forces colours. Tune it with `--oc-mark-gap` and `--oc-mark-size`.
|
|
385
|
+
`--oc-target` lowers the 44px minimum; 44px is the rule, so keep it unless
|
|
386
|
+
your own buttons already give a 44px target.
|
|
377
387
|
- `dist/button.mjs` has no imports, so it can be served from your own origin
|
|
378
388
|
under `script-src 'self'`. It builds the mark node by node: no `innerHTML`, so
|
|
379
389
|
Trusted Types are fine too.
|
package/dist/button.css
CHANGED
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
* hover) and your own rules win. Optional: without it the button is your
|
|
5
5
|
* button with the mark in it.
|
|
6
6
|
*
|
|
7
|
-
* appearance "inherit" (the default) sets no colour, font, border
|
|
8
|
-
* only the mark's
|
|
9
|
-
*
|
|
7
|
+
* appearance "inherit" (the default) sets no colour, font, border, radius,
|
|
8
|
+
* alignment or focus ring: only the mark's size and spacing, one line of words
|
|
9
|
+
* and a 44px target. appearance "brand" is orangecheck's button, themed by
|
|
10
|
+
* --oc-* properties, with its own focus ring.
|
|
10
11
|
*/
|
|
11
12
|
|
|
12
13
|
:where([data-oc-sign-in]) {
|
|
@@ -14,22 +15,29 @@
|
|
|
14
15
|
align-items: center;
|
|
15
16
|
gap: var(--oc-mark-gap, 0.5em);
|
|
16
17
|
min-block-size: var(--oc-target, 44px);
|
|
18
|
+
white-space: nowrap;
|
|
17
19
|
cursor: pointer;
|
|
18
20
|
}
|
|
19
21
|
|
|
22
|
+
/* Sized before it paints, and the same size as a placeholder <span data-oc-mark>: drawing the mark moves nothing. */
|
|
20
23
|
:where([data-oc-sign-in]) :where([data-oc-mark]) {
|
|
24
|
+
display: inline-block;
|
|
21
25
|
flex: none;
|
|
22
|
-
inline-size: var(--oc-mark-size, 1.
|
|
26
|
+
inline-size: var(--oc-mark-size, 1.75em);
|
|
23
27
|
block-size: auto;
|
|
28
|
+
aspect-ratio: 2 / 1;
|
|
24
29
|
}
|
|
25
30
|
|
|
26
31
|
:where([data-oc-sign-in]) :where([data-oc-mark='tile']) {
|
|
27
32
|
inline-size: var(--oc-mark-size, 1.25em);
|
|
33
|
+
aspect-ratio: 1 / 1;
|
|
28
34
|
}
|
|
29
35
|
|
|
30
|
-
:
|
|
31
|
-
|
|
32
|
-
|
|
36
|
+
/* The mark alone: centred, at least the target wide; a 44px square unless your class gives it padding. */
|
|
37
|
+
:where([data-oc-sign-in][data-label='none']) {
|
|
38
|
+
justify-content: center;
|
|
39
|
+
min-inline-size: var(--oc-target, 44px);
|
|
40
|
+
padding-inline: 0;
|
|
33
41
|
}
|
|
34
42
|
|
|
35
43
|
:where([data-oc-sign-in][aria-busy='true']) {
|
|
@@ -59,13 +67,34 @@
|
|
|
59
67
|
}
|
|
60
68
|
|
|
61
69
|
:where([data-oc-sign-in][data-appearance='brand']):focus-visible {
|
|
62
|
-
outline
|
|
70
|
+
outline: 2px solid var(--oc-focus, #fb933c);
|
|
71
|
+
outline-offset: 2px;
|
|
63
72
|
}
|
|
64
73
|
|
|
65
74
|
:where([data-oc-sign-in][data-appearance='brand']:disabled) {
|
|
66
75
|
opacity: 0.55;
|
|
67
76
|
}
|
|
68
77
|
|
|
78
|
+
/* Forced colours: one flat shape in the text colour, no ink tile, system colours for the ring. */
|
|
79
|
+
@media (forced-colors: active) {
|
|
80
|
+
:where([data-oc-sign-in]) :where([data-oc-mark]) :where(polygon) {
|
|
81
|
+
fill: currentColor;
|
|
82
|
+
fill-opacity: 1;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
:where([data-oc-sign-in]) :where([data-oc-mark='tile']) :where(rect) {
|
|
86
|
+
fill: transparent;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
:where([data-oc-sign-in][data-appearance='brand']) {
|
|
90
|
+
border-color: ButtonText;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
:where([data-oc-sign-in][data-appearance='brand']):focus-visible {
|
|
94
|
+
outline-color: Highlight;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
69
98
|
@media (prefers-reduced-motion: reduce) {
|
|
70
99
|
:where([data-oc-sign-in][data-appearance='brand']) {
|
|
71
100
|
transition: none;
|
package/dist/button.d.mts
CHANGED
|
@@ -7,7 +7,7 @@ declare const SIGN_IN_LABELS: {
|
|
|
7
7
|
readonly continue: "Continue with orangecheck";
|
|
8
8
|
readonly signUp: "Sign up with orangecheck";
|
|
9
9
|
};
|
|
10
|
-
type SignInLabel =
|
|
10
|
+
type SignInLabel = string;
|
|
11
11
|
declare const SIGN_IN_BUSY_LABEL = "Signing in\u2026";
|
|
12
12
|
declare const OUTCOME_COPY: {
|
|
13
13
|
readonly blocked: "Your browser blocked the sign-in window. Allow pop-ups for this site, then try again.";
|
|
@@ -19,11 +19,21 @@ interface EnhanceSignInButtonOptions {
|
|
|
19
19
|
onSignedIn: (result: OcPopupResult) => void | Promise<void>;
|
|
20
20
|
onOutcome?: (outcome: OcPopupOutcome) => void;
|
|
21
21
|
mark?: MarkVariant | false;
|
|
22
|
-
label?: SignInLabel;
|
|
22
|
+
label?: SignInLabel | false;
|
|
23
|
+
busyLabel?: string;
|
|
24
|
+
accessibleLabel?: string;
|
|
23
25
|
appearance?: SignInAppearance;
|
|
24
26
|
popup?: Omit<SignInWithOcOptions, 'signal'>;
|
|
25
27
|
}
|
|
26
|
-
|
|
28
|
+
interface CheckedSignInOptions {
|
|
29
|
+
mark: MarkVariant | false;
|
|
30
|
+
label: string | false;
|
|
31
|
+
busyLabel: string;
|
|
32
|
+
accessibleLabel: string;
|
|
33
|
+
appearance: SignInAppearance;
|
|
34
|
+
}
|
|
35
|
+
declare function checkSignInOptions(options: EnhanceSignInButtonOptions): CheckedSignInOptions;
|
|
36
|
+
declare function holdWidth(button: HTMLElement): () => void;
|
|
27
37
|
declare function enhanceSignInButton(button: HTMLButtonElement, options: EnhanceSignInButtonOptions): () => void;
|
|
28
38
|
|
|
29
|
-
export { type EnhanceSignInButtonOptions, OUTCOME_COPY, OcPopupOutcome, OcPopupResult, SIGN_IN_BUSY_LABEL, SIGN_IN_LABELS, type SignInAppearance, type SignInLabel, SignInWithOcOptions, checkSignInOptions, enhanceSignInButton };
|
|
39
|
+
export { type CheckedSignInOptions, type EnhanceSignInButtonOptions, OUTCOME_COPY, OcPopupOutcome, OcPopupResult, SIGN_IN_BUSY_LABEL, SIGN_IN_LABELS, type SignInAppearance, type SignInLabel, SignInWithOcOptions, checkSignInOptions, enhanceSignInButton, holdWidth };
|
package/dist/button.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ declare const SIGN_IN_LABELS: {
|
|
|
7
7
|
readonly continue: "Continue with orangecheck";
|
|
8
8
|
readonly signUp: "Sign up with orangecheck";
|
|
9
9
|
};
|
|
10
|
-
type SignInLabel =
|
|
10
|
+
type SignInLabel = string;
|
|
11
11
|
declare const SIGN_IN_BUSY_LABEL = "Signing in\u2026";
|
|
12
12
|
declare const OUTCOME_COPY: {
|
|
13
13
|
readonly blocked: "Your browser blocked the sign-in window. Allow pop-ups for this site, then try again.";
|
|
@@ -19,11 +19,21 @@ interface EnhanceSignInButtonOptions {
|
|
|
19
19
|
onSignedIn: (result: OcPopupResult) => void | Promise<void>;
|
|
20
20
|
onOutcome?: (outcome: OcPopupOutcome) => void;
|
|
21
21
|
mark?: MarkVariant | false;
|
|
22
|
-
label?: SignInLabel;
|
|
22
|
+
label?: SignInLabel | false;
|
|
23
|
+
busyLabel?: string;
|
|
24
|
+
accessibleLabel?: string;
|
|
23
25
|
appearance?: SignInAppearance;
|
|
24
26
|
popup?: Omit<SignInWithOcOptions, 'signal'>;
|
|
25
27
|
}
|
|
26
|
-
|
|
28
|
+
interface CheckedSignInOptions {
|
|
29
|
+
mark: MarkVariant | false;
|
|
30
|
+
label: string | false;
|
|
31
|
+
busyLabel: string;
|
|
32
|
+
accessibleLabel: string;
|
|
33
|
+
appearance: SignInAppearance;
|
|
34
|
+
}
|
|
35
|
+
declare function checkSignInOptions(options: EnhanceSignInButtonOptions): CheckedSignInOptions;
|
|
36
|
+
declare function holdWidth(button: HTMLElement): () => void;
|
|
27
37
|
declare function enhanceSignInButton(button: HTMLButtonElement, options: EnhanceSignInButtonOptions): () => void;
|
|
28
38
|
|
|
29
|
-
export { type EnhanceSignInButtonOptions, OUTCOME_COPY, OcPopupOutcome, OcPopupResult, SIGN_IN_BUSY_LABEL, SIGN_IN_LABELS, type SignInAppearance, type SignInLabel, SignInWithOcOptions, checkSignInOptions, enhanceSignInButton };
|
|
39
|
+
export { type CheckedSignInOptions, type EnhanceSignInButtonOptions, OUTCOME_COPY, OcPopupOutcome, OcPopupResult, SIGN_IN_BUSY_LABEL, SIGN_IN_LABELS, type SignInAppearance, type SignInLabel, SignInWithOcOptions, checkSignInOptions, enhanceSignInButton, holdWidth };
|
package/dist/button.js
CHANGED
|
@@ -8,7 +8,7 @@ var MARK_POINTS = {
|
|
|
8
8
|
};
|
|
9
9
|
var MARK_VIEWBOX = "0 0 16 8";
|
|
10
10
|
var MARK_FACES = { top: "#FED8AB", left: "#FB933C", right: "#EA580B" };
|
|
11
|
-
var MARK_MONO_OPACITY = { top: 1, left: 0.
|
|
11
|
+
var MARK_MONO_OPACITY = { top: 1, left: 0.6, right: 0.3 };
|
|
12
12
|
var MARK_TILE = {
|
|
13
13
|
viewBox: "0 0 24 24",
|
|
14
14
|
radius: 6.25,
|
|
@@ -16,6 +16,9 @@ var MARK_TILE = {
|
|
|
16
16
|
transform: "translate(4.25 8.1) scale(0.97)"
|
|
17
17
|
};
|
|
18
18
|
var ORDER = ["left", "right", "top"];
|
|
19
|
+
function opacity(face, flat) {
|
|
20
|
+
return flat ? 1 : MARK_MONO_OPACITY[face];
|
|
21
|
+
}
|
|
19
22
|
function heightFor(variant, width) {
|
|
20
23
|
if (variant === "tile") return width;
|
|
21
24
|
const m = /^(-?[\d.]+)([a-z%]*)$/i.exec(width.trim());
|
|
@@ -25,7 +28,7 @@ var SVG_NS = "http://www.w3.org/2000/svg";
|
|
|
25
28
|
function markElement(doc, options = {}) {
|
|
26
29
|
const variant = options.variant ?? "mono";
|
|
27
30
|
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.
|
|
31
|
+
const width = options.width ?? (variant === "tile" ? "1.25em" : "1.75em");
|
|
29
32
|
const color = options.color ?? "currentColor";
|
|
30
33
|
const el = (tag, attrs) => {
|
|
31
34
|
const node = doc.createElementNS(SVG_NS, tag);
|
|
@@ -54,7 +57,7 @@ function markElement(doc, options = {}) {
|
|
|
54
57
|
const attrs = { points: MARK_POINTS[face] };
|
|
55
58
|
if (variant === "mono") {
|
|
56
59
|
attrs.fill = color;
|
|
57
|
-
if (
|
|
60
|
+
if (opacity(face, !!options.flat) !== 1) attrs["fill-opacity"] = String(opacity(face, !!options.flat));
|
|
58
61
|
} else attrs.fill = MARK_FACES[face];
|
|
59
62
|
parent.append(el("polygon", attrs));
|
|
60
63
|
}
|
|
@@ -138,49 +141,88 @@ var OUTCOME_COPY = {
|
|
|
138
141
|
closed: "The sign-in window closed before you finished.",
|
|
139
142
|
failed: "Sign-in didn't finish. Try again."
|
|
140
143
|
};
|
|
141
|
-
var LABELS = new Set(Object.values(SIGN_IN_LABELS));
|
|
142
144
|
var MARKS = /* @__PURE__ */ new Set(["mono", "brand", "tile", false]);
|
|
143
|
-
var KEYS = /* @__PURE__ */ new Set(["onSignedIn", "onOutcome", "mark", "label", "appearance", "popup"]);
|
|
145
|
+
var KEYS = /* @__PURE__ */ new Set(["onSignedIn", "onOutcome", "mark", "label", "busyLabel", "accessibleLabel", "appearance", "popup"]);
|
|
146
|
+
var NAMED = /(^|[^\p{L}\p{N}])orangecheck($|[^\p{L}\p{N}])/u;
|
|
144
147
|
function checkSignInOptions(options) {
|
|
145
148
|
for (const key of Object.keys(options)) if (!KEYS.has(key)) throw new TypeError(`sign-in button: unknown option ${key}`);
|
|
146
149
|
if (typeof options.onSignedIn !== "function") throw new TypeError("sign-in button: onSignedIn is required");
|
|
147
150
|
const label = options.label ?? SIGN_IN_LABELS.signIn;
|
|
148
|
-
if (
|
|
151
|
+
if (label !== false && (typeof label !== "string" || !NAMED.test(label))) {
|
|
152
|
+
throw new TypeError(`sign-in button: "${String(label)}" must say "orangecheck", lowercase, as written; see SIGN_IN_LABELS`);
|
|
153
|
+
}
|
|
154
|
+
const accessibleLabel = options.accessibleLabel ?? SIGN_IN_LABELS.signIn;
|
|
155
|
+
if (!NAMED.test(accessibleLabel)) throw new TypeError(`sign-in button: accessibleLabel "${accessibleLabel}" must say "orangecheck"`);
|
|
156
|
+
const busyLabel = options.busyLabel ?? SIGN_IN_BUSY_LABEL;
|
|
157
|
+
if (typeof busyLabel !== "string" || !busyLabel.trim()) throw new TypeError("sign-in button: busyLabel must be words");
|
|
149
158
|
const mark = options.mark ?? "mono";
|
|
150
159
|
if (!MARKS.has(mark)) throw new TypeError(`sign-in button: unknown mark ${String(mark)}`);
|
|
160
|
+
if (label === false && mark === false) throw new TypeError("sign-in button: with no label it needs the mark");
|
|
151
161
|
const appearance = options.appearance ?? "inherit";
|
|
152
162
|
if (appearance !== "inherit" && appearance !== "brand") throw new TypeError(`sign-in button: unknown appearance ${String(appearance)}`);
|
|
153
|
-
return { label, mark, appearance };
|
|
163
|
+
return { label, mark, busyLabel, accessibleLabel, appearance };
|
|
164
|
+
}
|
|
165
|
+
function holdWidth(button) {
|
|
166
|
+
const { width: was, minWidth: wasMin } = button.style;
|
|
167
|
+
const width = button.getBoundingClientRect().width;
|
|
168
|
+
if (width > 0) button.style.width = button.style.minWidth = `${width}px`;
|
|
169
|
+
return () => {
|
|
170
|
+
button.style.width = was;
|
|
171
|
+
button.style.minWidth = wasMin;
|
|
172
|
+
};
|
|
154
173
|
}
|
|
155
174
|
function enhanceSignInButton(button, options) {
|
|
156
175
|
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
176
|
const doc = button.ownerDocument;
|
|
177
|
+
const own = (button.querySelector("[data-oc-label]")?.textContent ?? button.textContent ?? "").trim();
|
|
178
|
+
const iconOnly = options.label === false || options.label === void 0 && button.getAttribute("data-label") === "none";
|
|
179
|
+
const written = options.label === void 0 && !iconOnly && NAMED.test(own) ? own : options.label;
|
|
180
|
+
const hinted = button.querySelector("[data-oc-mark]")?.getAttribute("data-oc-mark");
|
|
181
|
+
const variant = options.mark === void 0 && hinted && MARKS.has(hinted) ? hinted : options.mark;
|
|
182
|
+
const checked = checkSignInOptions({ ...options, mark: variant, label: iconOnly ? false : written });
|
|
183
|
+
const { label, mark, appearance, busyLabel, accessibleLabel } = checked;
|
|
184
|
+
const before = {
|
|
185
|
+
nodes: [...button.childNodes],
|
|
186
|
+
type: button.getAttribute("type"),
|
|
187
|
+
aria: button.getAttribute("aria-label"),
|
|
188
|
+
dataLabel: button.getAttribute("data-label")
|
|
189
|
+
};
|
|
160
190
|
if (!before.type) button.type = "button";
|
|
161
191
|
button.setAttribute("data-oc-sign-in", "");
|
|
162
192
|
button.setAttribute("data-appearance", appearance);
|
|
193
|
+
const markEl = mark ? markElement(doc, { variant: mark }) : null;
|
|
163
194
|
const text = doc.createElement("span");
|
|
164
195
|
text.setAttribute("data-oc-label", "");
|
|
165
|
-
|
|
166
|
-
|
|
196
|
+
if (label === false) {
|
|
197
|
+
button.setAttribute("data-label", "none");
|
|
198
|
+
button.setAttribute("aria-label", accessibleLabel);
|
|
199
|
+
button.replaceChildren(markEl);
|
|
200
|
+
} else {
|
|
201
|
+
text.textContent = label;
|
|
202
|
+
button.replaceChildren(...markEl ? [markEl] : [], text);
|
|
203
|
+
}
|
|
167
204
|
let busy = false;
|
|
205
|
+
let release = null;
|
|
168
206
|
const setBusy = (on) => {
|
|
169
207
|
busy = on;
|
|
170
|
-
text.textContent = on ? SIGN_IN_BUSY_LABEL : label;
|
|
171
208
|
if (on) {
|
|
209
|
+
release = holdWidth(button);
|
|
210
|
+
if (label !== false) text.textContent = busyLabel;
|
|
172
211
|
button.setAttribute("aria-disabled", "true");
|
|
173
212
|
button.setAttribute("aria-busy", "true");
|
|
174
213
|
} else {
|
|
214
|
+
if (label !== false) text.textContent = label;
|
|
175
215
|
button.removeAttribute("aria-disabled");
|
|
176
216
|
button.removeAttribute("aria-busy");
|
|
217
|
+
release?.();
|
|
218
|
+
release = null;
|
|
177
219
|
}
|
|
178
220
|
};
|
|
179
221
|
const onClick = async (event) => {
|
|
180
222
|
event.preventDefault();
|
|
181
223
|
if (busy || button.disabled) return;
|
|
182
|
-
setBusy(true);
|
|
183
224
|
const pending = signInWithOcOutcome(options.popup);
|
|
225
|
+
setBusy(true);
|
|
184
226
|
try {
|
|
185
227
|
const outcome = await pending;
|
|
186
228
|
options.onOutcome?.(outcome);
|
|
@@ -195,6 +237,10 @@ function enhanceSignInButton(button, options) {
|
|
|
195
237
|
button.replaceChildren(...before.nodes);
|
|
196
238
|
if (before.type === null) button.removeAttribute("type");
|
|
197
239
|
for (const a of ["data-oc-sign-in", "data-appearance", "aria-disabled", "aria-busy"]) button.removeAttribute(a);
|
|
240
|
+
if (before.aria === null) button.removeAttribute("aria-label");
|
|
241
|
+
else button.setAttribute("aria-label", before.aria);
|
|
242
|
+
if (before.dataLabel === null) button.removeAttribute("data-label");
|
|
243
|
+
else button.setAttribute("data-label", before.dataLabel);
|
|
198
244
|
};
|
|
199
245
|
}
|
|
200
246
|
|
|
@@ -203,5 +249,6 @@ exports.SIGN_IN_BUSY_LABEL = SIGN_IN_BUSY_LABEL;
|
|
|
203
249
|
exports.SIGN_IN_LABELS = SIGN_IN_LABELS;
|
|
204
250
|
exports.checkSignInOptions = checkSignInOptions;
|
|
205
251
|
exports.enhanceSignInButton = enhanceSignInButton;
|
|
252
|
+
exports.holdWidth = holdWidth;
|
|
206
253
|
//# sourceMappingURL=button.js.map
|
|
207
254
|
//# sourceMappingURL=button.js.map
|
package/dist/button.js.map
CHANGED
|
@@ -1 +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;EACN,KAAA,EA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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,IAAM,WAAA,GAAc;EACvB,GAAA,EAAK,2BAAA;EACL,IAAA,EAAM,iBAAA;EACN,KAAA,EAAO;AACX,CAAA;AAEO,IAAM,YAAA,GAAe,UAAA;AAGrB,IAAM,aAAa,EAAE,GAAA,EAAK,WAAW,IAAA,EAAM,SAAA,EAAW,OA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AAW,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.js","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"]}
|