@agentconsent/react 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs ADDED
@@ -0,0 +1,2292 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ AUTHORITY_LEVELS: () => AUTHORITY_LEVELS,
34
+ ActionPreview: () => ActionPreview,
35
+ ActionReceipt: () => ActionReceipt,
36
+ AuthorityBoundary: () => AuthorityBoundary,
37
+ BatchApproval: () => BatchApproval,
38
+ ConnectionCard: () => ConnectionCard,
39
+ ConsentMemory: () => ConsentMemory,
40
+ CredentialHandoff: () => CredentialHandoff,
41
+ InjectionFlag: () => InjectionFlag,
42
+ IrreversibilityGate: () => IrreversibilityGate,
43
+ ProgressiveScope: () => ProgressiveScope,
44
+ ScopedGrant: () => ScopedGrant,
45
+ SpendLimits: () => SpendLimits
46
+ });
47
+ module.exports = __toCommonJS(index_exports);
48
+
49
+ // src/action-preview/action-preview.tsx
50
+ var React = __toESM(require("react"), 1);
51
+ var AlertDialog = __toESM(require("@radix-ui/react-alert-dialog"), 1);
52
+ var import_jsx_runtime = require("react/jsx-runtime");
53
+ var ActionPreviewContext = React.createContext(null);
54
+ function useActionPreviewContext(part) {
55
+ const ctx = React.useContext(ActionPreviewContext);
56
+ if (!ctx) {
57
+ throw new Error(
58
+ `ActionPreview.${part} must be rendered inside ActionPreview.Root`
59
+ );
60
+ }
61
+ return ctx;
62
+ }
63
+ var Root2 = React.forwardRef(
64
+ function ActionPreviewRoot({
65
+ onApprove,
66
+ onReject,
67
+ consequence = "reversible",
68
+ asModal = false,
69
+ open,
70
+ onOpenChange,
71
+ children,
72
+ ...rest
73
+ }, ref) {
74
+ const titleId = React.useId();
75
+ const ctx = React.useMemo(
76
+ () => ({ consequence, onApprove, onReject, asModal, titleId }),
77
+ [consequence, onApprove, onReject, asModal, titleId]
78
+ );
79
+ if (asModal) {
80
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ActionPreviewContext.Provider, { value: ctx, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlertDialog.Root, { open, onOpenChange, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(AlertDialog.Portal, { children: [
81
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlertDialog.Overlay, { "data-acp": "overlay" }),
82
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
83
+ AlertDialog.Content,
84
+ {
85
+ ref,
86
+ "data-acp": "root",
87
+ "data-modal": "",
88
+ "data-consequence": consequence,
89
+ "aria-describedby": void 0,
90
+ onEscapeKeyDown: onReject,
91
+ ...rest,
92
+ children
93
+ }
94
+ )
95
+ ] }) }) });
96
+ }
97
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ActionPreviewContext.Provider, { value: ctx, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
98
+ "section",
99
+ {
100
+ ref,
101
+ role: "group",
102
+ "aria-labelledby": titleId,
103
+ "data-acp": "root",
104
+ "data-consequence": consequence,
105
+ ...rest,
106
+ children
107
+ }
108
+ ) });
109
+ }
110
+ );
111
+ function Header(props) {
112
+ useActionPreviewContext("Header");
113
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { "data-acp": "header", ...props });
114
+ }
115
+ function Icon(props) {
116
+ useActionPreviewContext("Icon");
117
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { "aria-hidden": true, "data-acp": "icon", ...props });
118
+ }
119
+ function Title2(props) {
120
+ const { asModal, titleId } = useActionPreviewContext("Title");
121
+ if (asModal) {
122
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlertDialog.Title, { "data-acp": "title", ...props });
123
+ }
124
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { id: titleId, "data-acp": "title", ...props });
125
+ }
126
+ function Fields(props) {
127
+ useActionPreviewContext("Fields");
128
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("dl", { "data-acp": "fields", ...props });
129
+ }
130
+ function Field({ label, children, ...rest }) {
131
+ useActionPreviewContext("Field");
132
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { "data-acp": "field", ...rest, children: [
133
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("dt", { "data-acp": "field-label", children: label }),
134
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("dd", { "data-acp": "field-value", children })
135
+ ] });
136
+ }
137
+ function Content2({
138
+ label,
139
+ defaultExpanded = false,
140
+ children,
141
+ ...rest
142
+ }) {
143
+ useActionPreviewContext("Content");
144
+ const [expanded, setExpanded] = React.useState(defaultExpanded);
145
+ const bodyId = React.useId();
146
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { "data-acp": "content", "data-expanded": expanded ? "" : void 0, ...rest, children: [
147
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
148
+ "button",
149
+ {
150
+ type: "button",
151
+ "data-acp": "content-toggle",
152
+ "aria-expanded": expanded,
153
+ "aria-controls": bodyId,
154
+ onClick: () => setExpanded((v) => !v),
155
+ children: label
156
+ }
157
+ ),
158
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { id: bodyId, "data-acp": "content-body", hidden: !expanded, children })
159
+ ] });
160
+ }
161
+ function Source({ agent, authority, children, ...rest }) {
162
+ useActionPreviewContext("Source");
163
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { "data-acp": "source", ...rest, children: [
164
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { "data-acp": "source-agent", children: agent }),
165
+ authority != null && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { "data-acp": "source-authority", children: authority }),
166
+ children
167
+ ] });
168
+ }
169
+ function Actions(props) {
170
+ useActionPreviewContext("Actions");
171
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { "data-acp": "actions", ...props });
172
+ }
173
+ var Approve = React.forwardRef(
174
+ function ActionPreviewApprove({ onClick, ...rest }, ref) {
175
+ const { onApprove, asModal, consequence } = useActionPreviewContext("Approve");
176
+ const handleClick = (event) => {
177
+ onClick?.(event);
178
+ if (!event.defaultPrevented) onApprove();
179
+ };
180
+ const button = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
181
+ "button",
182
+ {
183
+ ref,
184
+ type: "button",
185
+ "data-acp": "approve",
186
+ "data-consequence": consequence,
187
+ onClick: handleClick,
188
+ ...rest
189
+ }
190
+ );
191
+ return asModal ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlertDialog.Action, { asChild: true, children: button }) : button;
192
+ }
193
+ );
194
+ var Reject = React.forwardRef(
195
+ function ActionPreviewReject({ onClick, ...rest }, ref) {
196
+ const { onReject, asModal } = useActionPreviewContext("Reject");
197
+ const handleClick = (event) => {
198
+ onClick?.(event);
199
+ if (!event.defaultPrevented) onReject();
200
+ };
201
+ const button = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
202
+ "button",
203
+ {
204
+ ref,
205
+ type: "button",
206
+ "data-acp": "reject",
207
+ onClick: handleClick,
208
+ ...rest
209
+ }
210
+ );
211
+ return asModal ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AlertDialog.Cancel, { asChild: true, children: button }) : button;
212
+ }
213
+ );
214
+ var ActionPreview = {
215
+ Root: Root2,
216
+ Header,
217
+ Icon,
218
+ Title: Title2,
219
+ Fields,
220
+ Field,
221
+ Content: Content2,
222
+ Source,
223
+ Actions,
224
+ Approve,
225
+ Reject
226
+ };
227
+
228
+ // src/irreversibility-gate/irreversibility-gate.tsx
229
+ var React2 = __toESM(require("react"), 1);
230
+ var AlertDialog2 = __toESM(require("@radix-ui/react-alert-dialog"), 1);
231
+ var import_jsx_runtime2 = require("react/jsx-runtime");
232
+ var IrreversibilityGateContext = React2.createContext(null);
233
+ function useGateContext(part) {
234
+ const ctx = React2.useContext(IrreversibilityGateContext);
235
+ if (!ctx) {
236
+ throw new Error(
237
+ `IrreversibilityGate.${part} must be rendered inside IrreversibilityGate.Root`
238
+ );
239
+ }
240
+ return ctx;
241
+ }
242
+ var Root4 = React2.forwardRef(
243
+ function IrreversibilityGateRoot({
244
+ onConfirm,
245
+ onCancel,
246
+ severity = "irreversible",
247
+ confirmPhrase,
248
+ asModal = false,
249
+ open,
250
+ onOpenChange,
251
+ children,
252
+ ...rest
253
+ }, ref) {
254
+ const titleId = React2.useId();
255
+ const descId = React2.useId();
256
+ const fieldId = React2.useId();
257
+ const [typed, setTyped] = React2.useState("");
258
+ const requirePhrase = severity === "irreversible" && confirmPhrase ? confirmPhrase : null;
259
+ const canConfirm = requirePhrase === null || typed.trim() === requirePhrase;
260
+ const [prevOpen, setPrevOpen] = React2.useState(open);
261
+ if (asModal && open !== prevOpen) {
262
+ setPrevOpen(open);
263
+ if (open === false && typed !== "") setTyped("");
264
+ }
265
+ const ctx = React2.useMemo(
266
+ () => ({
267
+ severity,
268
+ onConfirm,
269
+ onCancel,
270
+ asModal,
271
+ titleId,
272
+ descId,
273
+ fieldId,
274
+ requirePhrase,
275
+ typed,
276
+ setTyped,
277
+ canConfirm
278
+ }),
279
+ [
280
+ severity,
281
+ onConfirm,
282
+ onCancel,
283
+ asModal,
284
+ titleId,
285
+ descId,
286
+ fieldId,
287
+ requirePhrase,
288
+ typed,
289
+ canConfirm
290
+ ]
291
+ );
292
+ if (asModal) {
293
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IrreversibilityGateContext.Provider, { value: ctx, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AlertDialog2.Root, { open, onOpenChange, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(AlertDialog2.Portal, { children: [
294
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AlertDialog2.Overlay, { "data-acp": "overlay" }),
295
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
296
+ AlertDialog2.Content,
297
+ {
298
+ ref,
299
+ "data-acp": "root",
300
+ "data-gate": "",
301
+ "data-modal": "",
302
+ "data-severity": severity,
303
+ "aria-describedby": void 0,
304
+ onEscapeKeyDown: onCancel,
305
+ ...rest,
306
+ children
307
+ }
308
+ )
309
+ ] }) }) });
310
+ }
311
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(IrreversibilityGateContext.Provider, { value: ctx, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
312
+ "section",
313
+ {
314
+ ref,
315
+ role: "group",
316
+ "aria-labelledby": titleId,
317
+ "data-acp": "root",
318
+ "data-gate": "",
319
+ "data-severity": severity,
320
+ ...rest,
321
+ children
322
+ }
323
+ ) });
324
+ }
325
+ );
326
+ function Header2(props) {
327
+ useGateContext("Header");
328
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { "data-acp": "header", ...props });
329
+ }
330
+ function Icon2(props) {
331
+ const { severity } = useGateContext("Icon");
332
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { "aria-hidden": true, "data-acp": "gate-icon", "data-severity": severity, ...props });
333
+ }
334
+ function Title4(props) {
335
+ const { asModal, titleId } = useGateContext("Title");
336
+ if (asModal) {
337
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AlertDialog2.Title, { "data-acp": "title", ...props });
338
+ }
339
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h2", { id: titleId, "data-acp": "title", ...props });
340
+ }
341
+ function Description(props) {
342
+ const { descId } = useGateContext("Description");
343
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { id: descId, "data-acp": "gate-description", ...props });
344
+ }
345
+ function Consequences(props) {
346
+ useGateContext("Consequences");
347
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("ul", { "data-acp": "gate-consequences", ...props });
348
+ }
349
+ function Consequence({ children, ...rest }) {
350
+ useGateContext("Consequence");
351
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("li", { "data-acp": "gate-consequence", ...rest, children: [
352
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { "aria-hidden": true, "data-acp": "gate-consequence-marker" }),
353
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { "data-acp": "gate-consequence-text", children })
354
+ ] });
355
+ }
356
+ function ConfirmField({
357
+ children,
358
+ ...rest
359
+ }) {
360
+ const { requirePhrase, typed, setTyped, fieldId } = useGateContext("ConfirmField");
361
+ if (requirePhrase === null) return null;
362
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { "data-acp": "confirm-field", children: [
363
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { htmlFor: fieldId, "data-acp": "confirm-field-label", children: children ?? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
364
+ "Type ",
365
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("code", { "data-acp": "confirm-field-phrase", children: requirePhrase }),
366
+ " to confirm"
367
+ ] }) }),
368
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
369
+ "input",
370
+ {
371
+ id: fieldId,
372
+ "data-acp": "confirm-field-input",
373
+ type: "text",
374
+ autoComplete: "off",
375
+ autoCapitalize: "off",
376
+ autoCorrect: "off",
377
+ spellCheck: false,
378
+ value: typed,
379
+ onChange: (event) => setTyped(event.target.value),
380
+ ...rest
381
+ }
382
+ )
383
+ ] });
384
+ }
385
+ function Actions2(props) {
386
+ useGateContext("Actions");
387
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { "data-acp": "actions", ...props });
388
+ }
389
+ var Confirm = React2.forwardRef(function IrreversibilityGateConfirm({ onClick, disabled, ...rest }, ref) {
390
+ const { onConfirm, asModal, severity, canConfirm } = useGateContext("Confirm");
391
+ const isDisabled = disabled || !canConfirm;
392
+ const handleClick = (event) => {
393
+ onClick?.(event);
394
+ if (!event.defaultPrevented) onConfirm();
395
+ };
396
+ const button = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
397
+ "button",
398
+ {
399
+ ref,
400
+ type: "button",
401
+ "data-acp": "confirm",
402
+ "data-severity": severity,
403
+ disabled: isDisabled,
404
+ "aria-disabled": isDisabled || void 0,
405
+ onClick: handleClick,
406
+ ...rest
407
+ }
408
+ );
409
+ return asModal ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AlertDialog2.Action, { asChild: true, children: button }) : button;
410
+ });
411
+ var Cancel3 = React2.forwardRef(function IrreversibilityGateCancel({ onClick, ...rest }, ref) {
412
+ const { onCancel, asModal } = useGateContext("Cancel");
413
+ const handleClick = (event) => {
414
+ onClick?.(event);
415
+ if (!event.defaultPrevented) onCancel();
416
+ };
417
+ const button = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
418
+ "button",
419
+ {
420
+ ref,
421
+ type: "button",
422
+ "data-acp": "cancel",
423
+ onClick: handleClick,
424
+ ...rest
425
+ }
426
+ );
427
+ return asModal ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AlertDialog2.Cancel, { asChild: true, children: button }) : button;
428
+ });
429
+ var IrreversibilityGate = {
430
+ Root: Root4,
431
+ Header: Header2,
432
+ Icon: Icon2,
433
+ Title: Title4,
434
+ Description,
435
+ Consequences,
436
+ Consequence,
437
+ ConfirmField,
438
+ Actions: Actions2,
439
+ Confirm,
440
+ Cancel: Cancel3
441
+ };
442
+
443
+ // src/scoped-grant/scoped-grant.tsx
444
+ var React3 = __toESM(require("react"), 1);
445
+ var import_jsx_runtime3 = require("react/jsx-runtime");
446
+ var ScopedGrantContext = React3.createContext(null);
447
+ function useScopedGrantContext(part) {
448
+ const ctx = React3.useContext(ScopedGrantContext);
449
+ if (!ctx) {
450
+ throw new Error(
451
+ `ScopedGrant.${part} must be rendered inside ScopedGrant.Root`
452
+ );
453
+ }
454
+ return ctx;
455
+ }
456
+ function useGrantedSet(value, defaultValue, onValueChange) {
457
+ const isControlled = value !== void 0;
458
+ const [internal, setInternal] = React3.useState(
459
+ () => new Set(defaultValue ?? [])
460
+ );
461
+ const current = React3.useMemo(
462
+ () => isControlled ? new Set(value) : internal,
463
+ [isControlled, value, internal]
464
+ );
465
+ const setValue = React3.useCallback(
466
+ (updater) => {
467
+ const next = updater(current);
468
+ if (!isControlled) setInternal(next);
469
+ onValueChange?.([...next]);
470
+ },
471
+ [current, isControlled, onValueChange]
472
+ );
473
+ return [current, setValue];
474
+ }
475
+ var Root5 = React3.forwardRef(
476
+ function ScopedGrantRoot({
477
+ value,
478
+ defaultValue,
479
+ onValueChange,
480
+ requiredScopes,
481
+ onGrant,
482
+ onCancel,
483
+ children,
484
+ ...rest
485
+ }, ref) {
486
+ const titleId = React3.useId();
487
+ const [selected, setSelected] = useGrantedSet(
488
+ value,
489
+ defaultValue,
490
+ onValueChange
491
+ );
492
+ const requiredSet = React3.useMemo(
493
+ () => new Set(requiredScopes ?? []),
494
+ [requiredScopes]
495
+ );
496
+ const granted = React3.useMemo(() => {
497
+ const set = new Set(selected);
498
+ for (const id of requiredSet) set.add(id);
499
+ return [...set];
500
+ }, [selected, requiredSet]);
501
+ const ctx = React3.useMemo(() => {
502
+ const grantedSet = new Set(granted);
503
+ return {
504
+ isGranted: (id) => grantedSet.has(id),
505
+ isRequired: (id) => requiredSet.has(id),
506
+ toggle: (id) => {
507
+ if (requiredSet.has(id)) return;
508
+ setSelected((prev) => {
509
+ const next = new Set(prev);
510
+ if (next.has(id)) next.delete(id);
511
+ else next.add(id);
512
+ return next;
513
+ });
514
+ },
515
+ granted,
516
+ count: grantedSet.size,
517
+ onGrant,
518
+ onCancel,
519
+ titleId
520
+ };
521
+ }, [granted, requiredSet, setSelected, onGrant, onCancel, titleId]);
522
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ScopedGrantContext.Provider, { value: ctx, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
523
+ "form",
524
+ {
525
+ ref,
526
+ "data-acp": "root",
527
+ "data-grant": "",
528
+ "aria-labelledby": titleId,
529
+ onSubmit: (event) => {
530
+ event.preventDefault();
531
+ onGrant(granted);
532
+ },
533
+ ...rest,
534
+ children
535
+ }
536
+ ) });
537
+ }
538
+ );
539
+ function Header3(props) {
540
+ useScopedGrantContext("Header");
541
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { "data-acp": "header", ...props });
542
+ }
543
+ function Icon3(props) {
544
+ useScopedGrantContext("Icon");
545
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { "aria-hidden": true, "data-acp": "icon", ...props });
546
+ }
547
+ function Title5(props) {
548
+ const { titleId } = useScopedGrantContext("Title");
549
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h2", { id: titleId, "data-acp": "title", ...props });
550
+ }
551
+ function Description2(props) {
552
+ useScopedGrantContext("Description");
553
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { "data-acp": "grant-description", ...props });
554
+ }
555
+ function Group({ label, resource, children, ...rest }) {
556
+ useScopedGrantContext("Group");
557
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("fieldset", { "data-acp": "grant-group", ...rest, children: [
558
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("legend", { "data-acp": "grant-group-legend", children: [
559
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { "data-acp": "grant-group-label", children: label }),
560
+ resource != null && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { "data-acp": "grant-group-resource", children: resource })
561
+ ] }),
562
+ children
563
+ ] });
564
+ }
565
+ var ACCESS_LABEL = {
566
+ read: "Read",
567
+ write: "Write",
568
+ delete: "Delete"
569
+ };
570
+ function Scope({
571
+ id,
572
+ access,
573
+ label,
574
+ description,
575
+ ...rest
576
+ }) {
577
+ const { isGranted, isRequired, toggle } = useScopedGrantContext("Scope");
578
+ const inputId = React3.useId();
579
+ const descId = React3.useId();
580
+ const granted = isGranted(id);
581
+ const required = isRequired(id);
582
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
583
+ "div",
584
+ {
585
+ "data-acp": "scope",
586
+ "data-access": access,
587
+ "data-granted": granted ? "" : void 0,
588
+ "data-required": required ? "" : void 0,
589
+ ...rest,
590
+ children: [
591
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
592
+ "input",
593
+ {
594
+ type: "checkbox",
595
+ id: inputId,
596
+ "data-acp": "scope-checkbox",
597
+ checked: granted,
598
+ disabled: required,
599
+ "aria-describedby": description != null ? descId : void 0,
600
+ onChange: () => toggle(id)
601
+ }
602
+ ),
603
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { "data-acp": "scope-body", children: [
604
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("label", { htmlFor: inputId, "data-acp": "scope-label", children: [
605
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { "data-acp": "scope-access", "data-access": access, children: ACCESS_LABEL[access] }),
606
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { "data-acp": "scope-name", children: label }),
607
+ required && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { "data-acp": "scope-required-tag", children: " \xB7 required" })
608
+ ] }),
609
+ description != null && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { id: descId, "data-acp": "scope-description", children: description })
610
+ ] })
611
+ ]
612
+ }
613
+ );
614
+ }
615
+ function Actions3(props) {
616
+ useScopedGrantContext("Actions");
617
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { "data-acp": "actions", ...props });
618
+ }
619
+ var Grant = React3.forwardRef(
620
+ function ScopedGrantGrant({ children, ...rest }, ref) {
621
+ const { count } = useScopedGrantContext("Grant");
622
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { ref, type: "submit", "data-acp": "grant", ...rest, children: typeof children === "function" ? children({ count }) : children });
623
+ }
624
+ );
625
+ var Cancel4 = React3.forwardRef(
626
+ function ScopedGrantCancel({ onClick, ...rest }, ref) {
627
+ const { onCancel } = useScopedGrantContext("Cancel");
628
+ const handleClick = (event) => {
629
+ onClick?.(event);
630
+ if (!event.defaultPrevented) onCancel?.();
631
+ };
632
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
633
+ "button",
634
+ {
635
+ ref,
636
+ type: "button",
637
+ "data-acp": "cancel",
638
+ onClick: handleClick,
639
+ ...rest
640
+ }
641
+ );
642
+ }
643
+ );
644
+ var ScopedGrant = {
645
+ Root: Root5,
646
+ Header: Header3,
647
+ Icon: Icon3,
648
+ Title: Title5,
649
+ Description: Description2,
650
+ Group,
651
+ Scope,
652
+ Actions: Actions3,
653
+ Grant,
654
+ Cancel: Cancel4
655
+ };
656
+
657
+ // src/progressive-scope/progressive-scope.tsx
658
+ var React4 = __toESM(require("react"), 1);
659
+ var AlertDialog3 = __toESM(require("@radix-ui/react-alert-dialog"), 1);
660
+ var import_jsx_runtime4 = require("react/jsx-runtime");
661
+ var ProgressiveScopeContext = React4.createContext(null);
662
+ function useProgressiveScopeContext(part) {
663
+ const ctx = React4.useContext(ProgressiveScopeContext);
664
+ if (!ctx) {
665
+ throw new Error(
666
+ `ProgressiveScope.${part} must be rendered inside ProgressiveScope.Root`
667
+ );
668
+ }
669
+ return ctx;
670
+ }
671
+ var Root7 = React4.forwardRef(
672
+ function ProgressiveScopeRoot({
673
+ access = "read",
674
+ onAllowOnce,
675
+ onAllowAlways,
676
+ onDeny,
677
+ asModal = false,
678
+ open,
679
+ onOpenChange,
680
+ children,
681
+ ...rest
682
+ }, ref) {
683
+ const titleId = React4.useId();
684
+ const ctx = React4.useMemo(
685
+ () => ({
686
+ access,
687
+ onAllowOnce,
688
+ onAllowAlways,
689
+ onDeny,
690
+ asModal,
691
+ titleId
692
+ }),
693
+ [access, onAllowOnce, onAllowAlways, onDeny, asModal, titleId]
694
+ );
695
+ if (asModal) {
696
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ProgressiveScopeContext.Provider, { value: ctx, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AlertDialog3.Root, { open, onOpenChange, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(AlertDialog3.Portal, { children: [
697
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AlertDialog3.Overlay, { "data-acp": "overlay" }),
698
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
699
+ AlertDialog3.Content,
700
+ {
701
+ ref,
702
+ "data-acp": "root",
703
+ "data-escalation": "",
704
+ "data-modal": "",
705
+ "data-access": access,
706
+ "aria-describedby": void 0,
707
+ onEscapeKeyDown: onDeny,
708
+ ...rest,
709
+ children
710
+ }
711
+ )
712
+ ] }) }) });
713
+ }
714
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ProgressiveScopeContext.Provider, { value: ctx, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
715
+ "section",
716
+ {
717
+ ref,
718
+ role: "group",
719
+ "aria-labelledby": titleId,
720
+ "data-acp": "root",
721
+ "data-escalation": "",
722
+ "data-access": access,
723
+ ...rest,
724
+ children
725
+ }
726
+ ) });
727
+ }
728
+ );
729
+ function Header4(props) {
730
+ useProgressiveScopeContext("Header");
731
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { "data-acp": "header", ...props });
732
+ }
733
+ function Icon4(props) {
734
+ useProgressiveScopeContext("Icon");
735
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "aria-hidden": true, "data-acp": "icon", ...props });
736
+ }
737
+ function Title7(props) {
738
+ const { asModal, titleId } = useProgressiveScopeContext("Title");
739
+ if (asModal) {
740
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AlertDialog3.Title, { "data-acp": "title", ...props });
741
+ }
742
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("h2", { id: titleId, "data-acp": "title", ...props });
743
+ }
744
+ function Reason(props) {
745
+ useProgressiveScopeContext("Reason");
746
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { "data-acp": "escalation-reason", ...props });
747
+ }
748
+ var ACCESS_LABEL2 = {
749
+ read: "Read",
750
+ write: "Write",
751
+ delete: "Delete"
752
+ };
753
+ function Request({ label, description, ...rest }) {
754
+ const { access } = useProgressiveScopeContext("Request");
755
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { "data-acp": "request", "data-access": access, ...rest, children: [
756
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { "data-acp": "request-head", children: [
757
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-acp": "request-access", "data-access": access, children: ACCESS_LABEL2[access] }),
758
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "data-acp": "request-name", children: label })
759
+ ] }),
760
+ description != null && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { "data-acp": "request-description", children: description })
761
+ ] });
762
+ }
763
+ function Current({ children, ...rest }) {
764
+ useProgressiveScopeContext("Current");
765
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { "data-acp": "escalation-current", ...rest, children: [
766
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { "aria-hidden": true, "data-acp": "escalation-current-marker" }),
767
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children })
768
+ ] });
769
+ }
770
+ function Actions4(props) {
771
+ useProgressiveScopeContext("Actions");
772
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { "data-acp": "actions", "data-escalation-actions": "", ...props });
773
+ }
774
+ function makeAllowButton(displayName, hook, pick) {
775
+ const Component = React4.forwardRef(function AllowButton({ onClick, ...rest }, ref) {
776
+ const ctx = useProgressiveScopeContext(displayName);
777
+ const action = pick(ctx);
778
+ const handleClick = (event) => {
779
+ onClick?.(event);
780
+ if (!event.defaultPrevented) action();
781
+ };
782
+ const button = /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
783
+ "button",
784
+ {
785
+ ref,
786
+ type: "button",
787
+ "data-acp": hook,
788
+ onClick: handleClick,
789
+ ...rest
790
+ }
791
+ );
792
+ return ctx.asModal ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AlertDialog3.Action, { asChild: true, children: button }) : button;
793
+ });
794
+ Component.displayName = displayName;
795
+ return Component;
796
+ }
797
+ var AllowOnce = makeAllowButton(
798
+ "ProgressiveScopeAllowOnce",
799
+ "allow-once",
800
+ (ctx) => ctx.onAllowOnce
801
+ );
802
+ var AllowAlways = makeAllowButton(
803
+ "ProgressiveScopeAllowAlways",
804
+ "allow-always",
805
+ (ctx) => ctx.onAllowAlways
806
+ );
807
+ var Deny = React4.forwardRef(
808
+ function ProgressiveScopeDeny({ onClick, ...rest }, ref) {
809
+ const { onDeny, asModal } = useProgressiveScopeContext("Deny");
810
+ const handleClick = (event) => {
811
+ onClick?.(event);
812
+ if (!event.defaultPrevented) onDeny();
813
+ };
814
+ const button = /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
815
+ "button",
816
+ {
817
+ ref,
818
+ type: "button",
819
+ "data-acp": "deny",
820
+ onClick: handleClick,
821
+ ...rest
822
+ }
823
+ );
824
+ return asModal ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AlertDialog3.Cancel, { asChild: true, children: button }) : button;
825
+ }
826
+ );
827
+ var ProgressiveScope = {
828
+ Root: Root7,
829
+ Header: Header4,
830
+ Icon: Icon4,
831
+ Title: Title7,
832
+ Reason,
833
+ Request,
834
+ Current,
835
+ Actions: Actions4,
836
+ AllowOnce,
837
+ AllowAlways,
838
+ Deny
839
+ };
840
+
841
+ // src/batch-approval/batch-approval.tsx
842
+ var React5 = __toESM(require("react"), 1);
843
+ var import_jsx_runtime5 = require("react/jsx-runtime");
844
+ var BatchApprovalContext = React5.createContext(null);
845
+ function useBatchApprovalContext(part) {
846
+ const ctx = React5.useContext(BatchApprovalContext);
847
+ if (!ctx) {
848
+ throw new Error(
849
+ `BatchApproval.${part} must be rendered inside BatchApproval.Root`
850
+ );
851
+ }
852
+ return ctx;
853
+ }
854
+ var BatchApprovalItemContext = React5.createContext(
855
+ null
856
+ );
857
+ function useItemId(part) {
858
+ const ctx = React5.useContext(BatchApprovalItemContext);
859
+ if (!ctx) {
860
+ throw new Error(
861
+ `BatchApproval.${part} must be rendered inside BatchApproval.Item`
862
+ );
863
+ }
864
+ return ctx.id;
865
+ }
866
+ function useSelectedSet(value, defaultValue, onValueChange) {
867
+ const isControlled = value !== void 0;
868
+ const [internal, setInternal] = React5.useState(
869
+ () => new Set(defaultValue ?? [])
870
+ );
871
+ const current = React5.useMemo(
872
+ () => isControlled ? new Set(value) : internal,
873
+ [isControlled, value, internal]
874
+ );
875
+ const setValue = React5.useCallback(
876
+ (updater) => {
877
+ const next = updater(current);
878
+ if (!isControlled) setInternal(next);
879
+ onValueChange?.([...next]);
880
+ },
881
+ [current, isControlled, onValueChange]
882
+ );
883
+ return [current, setValue];
884
+ }
885
+ var Root8 = React5.forwardRef(
886
+ function BatchApprovalRoot({
887
+ items,
888
+ value,
889
+ defaultValue,
890
+ onValueChange,
891
+ onApprove,
892
+ onReject,
893
+ children,
894
+ ...rest
895
+ }, ref) {
896
+ const titleId = React5.useId();
897
+ const [selected, setSelected] = useSelectedSet(
898
+ value,
899
+ defaultValue,
900
+ onValueChange
901
+ );
902
+ const reviewSet = React5.useMemo(
903
+ () => new Set(items.filter((i) => i.requiresReview).map((i) => i.id)),
904
+ [items]
905
+ );
906
+ const selectableIds = React5.useMemo(
907
+ () => items.filter((i) => !i.requiresReview).map((i) => i.id),
908
+ [items]
909
+ );
910
+ const ctx = React5.useMemo(() => {
911
+ const selectedSelectable = selectableIds.filter(
912
+ (id) => selected.has(id)
913
+ );
914
+ const selectedCount = selectedSelectable.length;
915
+ const selectableCount = selectableIds.length;
916
+ const clearFrom = (prev, ids) => {
917
+ const next = new Set(prev);
918
+ for (const id of ids) next.delete(id);
919
+ return next;
920
+ };
921
+ return {
922
+ isSelected: (id) => selected.has(id),
923
+ toggle: (id) => {
924
+ if (reviewSet.has(id)) return;
925
+ setSelected((prev) => {
926
+ const next = new Set(prev);
927
+ if (next.has(id)) next.delete(id);
928
+ else next.add(id);
929
+ return next;
930
+ });
931
+ },
932
+ requiresReview: (id) => reviewSet.has(id),
933
+ selectableIds,
934
+ selectedIds: selectedSelectable,
935
+ selectedCount,
936
+ selectableCount,
937
+ allSelected: selectableCount > 0 && selectedCount === selectableCount,
938
+ someSelected: selectedCount > 0 && selectedCount < selectableCount,
939
+ setAllSelected: (checked) => {
940
+ setSelected((prev) => {
941
+ if (!checked) return clearFrom(prev, selectableIds);
942
+ const next = new Set(prev);
943
+ for (const id of selectableIds) next.add(id);
944
+ return next;
945
+ });
946
+ },
947
+ approve: (ids) => {
948
+ onApprove(ids);
949
+ setSelected((prev) => clearFrom(prev, ids));
950
+ },
951
+ reject: (ids) => {
952
+ onReject(ids);
953
+ setSelected((prev) => clearFrom(prev, ids));
954
+ },
955
+ titleId
956
+ };
957
+ }, [
958
+ selected,
959
+ selectableIds,
960
+ reviewSet,
961
+ setSelected,
962
+ onApprove,
963
+ onReject,
964
+ titleId
965
+ ]);
966
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(BatchApprovalContext.Provider, { value: ctx, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
967
+ "section",
968
+ {
969
+ ref,
970
+ role: "group",
971
+ "aria-labelledby": titleId,
972
+ "data-acp": "root",
973
+ "data-batch": "",
974
+ ...rest,
975
+ children
976
+ }
977
+ ) });
978
+ }
979
+ );
980
+ function Header5(props) {
981
+ useBatchApprovalContext("Header");
982
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { "data-acp": "header", ...props });
983
+ }
984
+ function Icon5(props) {
985
+ useBatchApprovalContext("Icon");
986
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { "aria-hidden": true, "data-acp": "icon", ...props });
987
+ }
988
+ function Title8(props) {
989
+ const { titleId } = useBatchApprovalContext("Title");
990
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h2", { id: titleId, "data-acp": "title", ...props });
991
+ }
992
+ function Description3(props) {
993
+ useBatchApprovalContext("Description");
994
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { "data-acp": "batch-description", ...props });
995
+ }
996
+ function Toolbar(props) {
997
+ useBatchApprovalContext("Toolbar");
998
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { "data-acp": "batch-toolbar", role: "group", ...props });
999
+ }
1000
+ function SelectAll({ children, ...rest }) {
1001
+ const { allSelected, someSelected, setAllSelected, selectableCount } = useBatchApprovalContext("SelectAll");
1002
+ const inputRef = React5.useRef(null);
1003
+ const inputId = React5.useId();
1004
+ React5.useEffect(() => {
1005
+ if (inputRef.current) inputRef.current.indeterminate = someSelected;
1006
+ }, [someSelected]);
1007
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { "data-acp": "batch-select-all", ...rest, children: [
1008
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1009
+ "input",
1010
+ {
1011
+ ref: inputRef,
1012
+ id: inputId,
1013
+ type: "checkbox",
1014
+ "data-acp": "batch-select-all-checkbox",
1015
+ checked: allSelected,
1016
+ disabled: selectableCount === 0,
1017
+ onChange: (event) => setAllSelected(event.target.checked)
1018
+ }
1019
+ ),
1020
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { htmlFor: inputId, "data-acp": "batch-select-all-label", children: children ?? "Select all reviewable" })
1021
+ ] });
1022
+ }
1023
+ function SelectionCount({ children, ...rest }) {
1024
+ const { selectedCount, selectableCount } = useBatchApprovalContext("SelectionCount");
1025
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { "data-acp": "batch-selection-count", "aria-live": "polite", ...rest, children: children ? children({ selectedCount, selectableCount }) : `${selectedCount} selected` });
1026
+ }
1027
+ var BatchApprove = React5.forwardRef(function BatchApprovalBatchApprove({ onClick, disabled, ...rest }, ref) {
1028
+ const { approve, selectedIds, selectedCount } = useBatchApprovalContext("BatchApprove");
1029
+ const isDisabled = disabled || selectedCount === 0;
1030
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1031
+ "button",
1032
+ {
1033
+ ref,
1034
+ type: "button",
1035
+ "data-acp": "approve",
1036
+ "data-batch-action": "approve",
1037
+ disabled: isDisabled,
1038
+ "aria-disabled": isDisabled || void 0,
1039
+ onClick: (event) => {
1040
+ onClick?.(event);
1041
+ if (!event.defaultPrevented) approve(selectedIds);
1042
+ },
1043
+ ...rest
1044
+ }
1045
+ );
1046
+ });
1047
+ var BatchReject = React5.forwardRef(function BatchApprovalBatchReject({ onClick, disabled, ...rest }, ref) {
1048
+ const { reject, selectedIds, selectedCount } = useBatchApprovalContext("BatchReject");
1049
+ const isDisabled = disabled || selectedCount === 0;
1050
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1051
+ "button",
1052
+ {
1053
+ ref,
1054
+ type: "button",
1055
+ "data-acp": "reject",
1056
+ "data-batch-action": "reject",
1057
+ disabled: isDisabled,
1058
+ "aria-disabled": isDisabled || void 0,
1059
+ onClick: (event) => {
1060
+ onClick?.(event);
1061
+ if (!event.defaultPrevented) reject(selectedIds);
1062
+ },
1063
+ ...rest
1064
+ }
1065
+ );
1066
+ });
1067
+ function List(props) {
1068
+ useBatchApprovalContext("List");
1069
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("ul", { "data-acp": "batch-list", ...props });
1070
+ }
1071
+ function Item({ id, title, detail, children, ...rest }) {
1072
+ const { isSelected, toggle, requiresReview } = useBatchApprovalContext("Item");
1073
+ const inputId = React5.useId();
1074
+ const detailId = React5.useId();
1075
+ const selected = isSelected(id);
1076
+ const review = requiresReview(id);
1077
+ const itemCtx = React5.useMemo(() => ({ id }), [id]);
1078
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(BatchApprovalItemContext.Provider, { value: itemCtx, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1079
+ "li",
1080
+ {
1081
+ "data-acp": "batch-item",
1082
+ "data-selected": selected ? "" : void 0,
1083
+ "data-review": review ? "" : void 0,
1084
+ ...rest,
1085
+ children: [
1086
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { "data-acp": "batch-item-select", children: review ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { "data-acp": "batch-item-flag", children: "Review individually" }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1087
+ "input",
1088
+ {
1089
+ id: inputId,
1090
+ type: "checkbox",
1091
+ "data-acp": "batch-item-checkbox",
1092
+ checked: selected,
1093
+ "aria-describedby": detail != null ? detailId : void 0,
1094
+ onChange: () => toggle(id)
1095
+ }
1096
+ ) }),
1097
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { "data-acp": "batch-item-body", children: [
1098
+ review ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { "data-acp": "batch-item-title", children: title }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { htmlFor: inputId, "data-acp": "batch-item-title", children: title }),
1099
+ detail != null && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { id: detailId, "data-acp": "batch-item-detail", children: detail })
1100
+ ] }),
1101
+ children != null && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { "data-acp": "batch-item-actions", children })
1102
+ ]
1103
+ }
1104
+ ) });
1105
+ }
1106
+ var ItemApprove = React5.forwardRef(function BatchApprovalItemApprove({ onClick, ...rest }, ref) {
1107
+ const { approve } = useBatchApprovalContext("Item.Approve");
1108
+ const id = useItemId("Item.Approve");
1109
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1110
+ "button",
1111
+ {
1112
+ ref,
1113
+ type: "button",
1114
+ "data-acp": "batch-item-approve",
1115
+ onClick: (event) => {
1116
+ onClick?.(event);
1117
+ if (!event.defaultPrevented) approve([id]);
1118
+ },
1119
+ ...rest
1120
+ }
1121
+ );
1122
+ });
1123
+ var ItemReject = React5.forwardRef(function BatchApprovalItemReject({ onClick, ...rest }, ref) {
1124
+ const { reject } = useBatchApprovalContext("Item.Reject");
1125
+ const id = useItemId("Item.Reject");
1126
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1127
+ "button",
1128
+ {
1129
+ ref,
1130
+ type: "button",
1131
+ "data-acp": "batch-item-reject",
1132
+ onClick: (event) => {
1133
+ onClick?.(event);
1134
+ if (!event.defaultPrevented) reject([id]);
1135
+ },
1136
+ ...rest
1137
+ }
1138
+ );
1139
+ });
1140
+ var BatchApproval = {
1141
+ Root: Root8,
1142
+ Header: Header5,
1143
+ Icon: Icon5,
1144
+ Title: Title8,
1145
+ Description: Description3,
1146
+ Toolbar,
1147
+ SelectAll,
1148
+ SelectionCount,
1149
+ BatchApprove,
1150
+ BatchReject,
1151
+ List,
1152
+ Item,
1153
+ ItemApprove,
1154
+ ItemReject
1155
+ };
1156
+
1157
+ // src/consent-memory/consent-memory.tsx
1158
+ var React6 = __toESM(require("react"), 1);
1159
+ var import_jsx_runtime6 = require("react/jsx-runtime");
1160
+ var ConsentMemoryContext = React6.createContext(null);
1161
+ function useConsentMemoryContext(part) {
1162
+ const ctx = React6.useContext(ConsentMemoryContext);
1163
+ if (!ctx) {
1164
+ throw new Error(
1165
+ `ConsentMemory.${part} must be rendered inside ConsentMemory.Root`
1166
+ );
1167
+ }
1168
+ return ctx;
1169
+ }
1170
+ function useControllableValue(value, defaultValue, onValueChange) {
1171
+ const isControlled = value !== void 0;
1172
+ const [internal, setInternal] = React6.useState(defaultValue);
1173
+ const current = isControlled ? value : internal;
1174
+ const setValue = React6.useCallback(
1175
+ (next) => {
1176
+ if (!isControlled) setInternal(next);
1177
+ onValueChange?.(next);
1178
+ },
1179
+ [isControlled, onValueChange]
1180
+ );
1181
+ return [current, setValue];
1182
+ }
1183
+ var Root9 = React6.forwardRef(
1184
+ function ConsentMemoryRoot({ value, defaultValue, onValueChange, onAllow, onDeny, children, ...rest }, ref) {
1185
+ const titleId = React6.useId();
1186
+ const name = React6.useId();
1187
+ const [selected, setSelected] = useControllableValue(
1188
+ value,
1189
+ defaultValue,
1190
+ onValueChange
1191
+ );
1192
+ const durabilityRef = React6.useRef(
1193
+ /* @__PURE__ */ new Map()
1194
+ );
1195
+ const ctx = React6.useMemo(
1196
+ () => ({
1197
+ value: selected ?? null,
1198
+ register: (next, durability) => {
1199
+ durabilityRef.current.set(next, durability);
1200
+ },
1201
+ getDurability: () => selected != null ? durabilityRef.current.get(selected) ?? null : null,
1202
+ select: setSelected,
1203
+ name,
1204
+ onAllow,
1205
+ onDeny,
1206
+ titleId
1207
+ }),
1208
+ [selected, setSelected, name, onAllow, onDeny, titleId]
1209
+ );
1210
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ConsentMemoryContext.Provider, { value: ctx, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1211
+ "form",
1212
+ {
1213
+ ref,
1214
+ "data-acp": "root",
1215
+ "data-memory": "",
1216
+ "aria-labelledby": titleId,
1217
+ onSubmit: (event) => {
1218
+ event.preventDefault();
1219
+ if (selected != null) onAllow(selected);
1220
+ },
1221
+ ...rest,
1222
+ children
1223
+ }
1224
+ ) });
1225
+ }
1226
+ );
1227
+ function Header6(props) {
1228
+ useConsentMemoryContext("Header");
1229
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { "data-acp": "header", ...props });
1230
+ }
1231
+ function Icon6(props) {
1232
+ useConsentMemoryContext("Icon");
1233
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { "aria-hidden": true, "data-acp": "icon", ...props });
1234
+ }
1235
+ function Title9(props) {
1236
+ const { titleId } = useConsentMemoryContext("Title");
1237
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("h2", { id: titleId, "data-acp": "title", ...props });
1238
+ }
1239
+ function Description4(props) {
1240
+ useConsentMemoryContext("Description");
1241
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { "data-acp": "memory-description", ...props });
1242
+ }
1243
+ function Options({ legend, children, ...rest }) {
1244
+ useConsentMemoryContext("Options");
1245
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("fieldset", { "data-acp": "memory-options", ...rest, children: [
1246
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("legend", { "data-acp": "memory-options-legend", children: legend ?? "Apply this decision:" }),
1247
+ children
1248
+ ] });
1249
+ }
1250
+ var DURABILITY_HINT = {
1251
+ once: "This time",
1252
+ session: "This session",
1253
+ scoped: "Standing \xB7 scoped",
1254
+ always: "Standing \xB7 always"
1255
+ };
1256
+ function Option({
1257
+ value,
1258
+ durability,
1259
+ label,
1260
+ consequence,
1261
+ ...rest
1262
+ }) {
1263
+ const { value: selected, select, register, name } = useConsentMemoryContext("Option");
1264
+ register(value, durability);
1265
+ const inputId = React6.useId();
1266
+ const consequenceId = React6.useId();
1267
+ const checked = selected === value;
1268
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
1269
+ "div",
1270
+ {
1271
+ "data-acp": "memory-option",
1272
+ "data-durability": durability,
1273
+ "data-selected": checked ? "" : void 0,
1274
+ ...rest,
1275
+ children: [
1276
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1277
+ "input",
1278
+ {
1279
+ id: inputId,
1280
+ type: "radio",
1281
+ name,
1282
+ value,
1283
+ "data-acp": "memory-option-radio",
1284
+ checked,
1285
+ "aria-describedby": consequenceId,
1286
+ onChange: () => select(value)
1287
+ }
1288
+ ),
1289
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { "data-acp": "memory-option-body", children: [
1290
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("label", { htmlFor: inputId, "data-acp": "memory-option-label", children: [
1291
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { "data-acp": "memory-option-name", children: label }),
1292
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { "data-acp": "memory-option-hint", "data-durability": durability, children: DURABILITY_HINT[durability] })
1293
+ ] }),
1294
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { id: consequenceId, "data-acp": "memory-option-consequence", children: consequence })
1295
+ ] })
1296
+ ]
1297
+ }
1298
+ );
1299
+ }
1300
+ function Actions5(props) {
1301
+ useConsentMemoryContext("Actions");
1302
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { "data-acp": "actions", ...props });
1303
+ }
1304
+ var Allow = React6.forwardRef(
1305
+ function ConsentMemoryAllow({ children, ...rest }, ref) {
1306
+ const { getDurability } = useConsentMemoryContext("Allow");
1307
+ const durability = getDurability();
1308
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1309
+ "button",
1310
+ {
1311
+ ref,
1312
+ type: "submit",
1313
+ "data-acp": "allow-once",
1314
+ "data-memory-allow": "",
1315
+ "data-durability": durability ?? void 0,
1316
+ ...rest,
1317
+ children: typeof children === "function" ? children({ durability }) : children
1318
+ }
1319
+ );
1320
+ }
1321
+ );
1322
+ var Deny2 = React6.forwardRef(
1323
+ function ConsentMemoryDeny({ onClick, ...rest }, ref) {
1324
+ const { onDeny } = useConsentMemoryContext("Deny");
1325
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1326
+ "button",
1327
+ {
1328
+ ref,
1329
+ type: "button",
1330
+ "data-acp": "deny",
1331
+ onClick: (event) => {
1332
+ onClick?.(event);
1333
+ if (!event.defaultPrevented) onDeny();
1334
+ },
1335
+ ...rest
1336
+ }
1337
+ );
1338
+ }
1339
+ );
1340
+ var ConsentMemory = {
1341
+ Root: Root9,
1342
+ Header: Header6,
1343
+ Icon: Icon6,
1344
+ Title: Title9,
1345
+ Description: Description4,
1346
+ Options,
1347
+ Option,
1348
+ Actions: Actions5,
1349
+ Allow,
1350
+ Deny: Deny2
1351
+ };
1352
+
1353
+ // src/authority-boundary/authority-boundary.tsx
1354
+ var React7 = __toESM(require("react"), 1);
1355
+ var import_jsx_runtime7 = require("react/jsx-runtime");
1356
+ var AUTHORITY_LEVELS = ["auto", "ask", "never"];
1357
+ var LEVEL_LABEL = {
1358
+ auto: "Automatic",
1359
+ ask: "Ask first",
1360
+ never: "Never"
1361
+ };
1362
+ var AuthorityBoundaryContext = React7.createContext(null);
1363
+ function useAuthorityBoundaryContext(part) {
1364
+ const ctx = React7.useContext(AuthorityBoundaryContext);
1365
+ if (!ctx) {
1366
+ throw new Error(
1367
+ `AuthorityBoundary.${part} must be rendered inside AuthorityBoundary.Root`
1368
+ );
1369
+ }
1370
+ return ctx;
1371
+ }
1372
+ function useControllableMap(value, defaultValue, onValueChange) {
1373
+ const isControlled = value !== void 0;
1374
+ const [internal, setInternal] = React7.useState(() => defaultValue ?? {});
1375
+ const current = isControlled ? value : internal;
1376
+ const setLevel = React7.useCallback(
1377
+ (id, level) => {
1378
+ const next = { ...current, [id]: level };
1379
+ if (!isControlled) setInternal(next);
1380
+ onValueChange?.(next);
1381
+ },
1382
+ [current, isControlled, onValueChange]
1383
+ );
1384
+ return [current, setLevel];
1385
+ }
1386
+ var Root10 = React7.forwardRef(
1387
+ function AuthorityBoundaryRoot({ value, defaultValue, onValueChange, children, ...rest }, ref) {
1388
+ const titleId = React7.useId();
1389
+ const [levels, setLevel] = useControllableMap(
1390
+ value,
1391
+ defaultValue,
1392
+ onValueChange
1393
+ );
1394
+ const ctx = React7.useMemo(() => {
1395
+ const counts = {
1396
+ auto: 0,
1397
+ ask: 0,
1398
+ never: 0
1399
+ };
1400
+ for (const level of Object.values(levels)) counts[level] += 1;
1401
+ return {
1402
+ getLevel: (id) => levels[id] ?? "ask",
1403
+ setLevel,
1404
+ counts,
1405
+ titleId
1406
+ };
1407
+ }, [levels, setLevel, titleId]);
1408
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(AuthorityBoundaryContext.Provider, { value: ctx, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1409
+ "section",
1410
+ {
1411
+ ref,
1412
+ role: "group",
1413
+ "aria-labelledby": titleId,
1414
+ "data-acp": "root",
1415
+ "data-authority": "",
1416
+ ...rest,
1417
+ children
1418
+ }
1419
+ ) });
1420
+ }
1421
+ );
1422
+ function Header7(props) {
1423
+ useAuthorityBoundaryContext("Header");
1424
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { "data-acp": "header", ...props });
1425
+ }
1426
+ function Icon7(props) {
1427
+ useAuthorityBoundaryContext("Icon");
1428
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { "aria-hidden": true, "data-acp": "icon", ...props });
1429
+ }
1430
+ function Title10(props) {
1431
+ const { titleId } = useAuthorityBoundaryContext("Title");
1432
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("h2", { id: titleId, "data-acp": "title", ...props });
1433
+ }
1434
+ function Description5(props) {
1435
+ useAuthorityBoundaryContext("Description");
1436
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { "data-acp": "authority-description", ...props });
1437
+ }
1438
+ function Summary({ children, ...rest }) {
1439
+ const { counts } = useAuthorityBoundaryContext("Summary");
1440
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { "data-acp": "authority-summary", "aria-live": "polite", ...rest, children: children(counts) });
1441
+ }
1442
+ function List2(props) {
1443
+ useAuthorityBoundaryContext("List");
1444
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("ul", { "data-acp": "authority-list", ...props });
1445
+ }
1446
+ var ACCESS_LABEL3 = {
1447
+ read: "Read",
1448
+ write: "Write",
1449
+ delete: "Delete"
1450
+ };
1451
+ function Capability({
1452
+ id,
1453
+ access,
1454
+ label,
1455
+ description,
1456
+ disallow,
1457
+ ...rest
1458
+ }) {
1459
+ const { getLevel, setLevel } = useAuthorityBoundaryContext("Capability");
1460
+ const name = React7.useId();
1461
+ const descId = React7.useId();
1462
+ const level = getLevel(id);
1463
+ const disallowed = new Set(disallow ?? []);
1464
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
1465
+ "li",
1466
+ {
1467
+ "data-acp": "authority-capability",
1468
+ "data-access": access,
1469
+ "data-level": level,
1470
+ ...rest,
1471
+ children: [
1472
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { "data-acp": "authority-capability-body", children: [
1473
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { "data-acp": "authority-capability-head", children: [
1474
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { "data-acp": "authority-access", "data-access": access, children: ACCESS_LABEL3[access] }),
1475
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { "data-acp": "authority-capability-name", children: label })
1476
+ ] }),
1477
+ description != null && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { id: descId, "data-acp": "authority-capability-description", children: description })
1478
+ ] }),
1479
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
1480
+ "fieldset",
1481
+ {
1482
+ "data-acp": "authority-control",
1483
+ "aria-describedby": description != null ? descId : void 0,
1484
+ children: [
1485
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("legend", { "data-acp": "authority-control-legend", children: [
1486
+ "Authority for ",
1487
+ typeof label === "string" ? label : "this capability"
1488
+ ] }),
1489
+ AUTHORITY_LEVELS.map((option) => {
1490
+ const optionId = `${name}-${option}`;
1491
+ const blocked = disallowed.has(option);
1492
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(React7.Fragment, { children: [
1493
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1494
+ "input",
1495
+ {
1496
+ id: optionId,
1497
+ type: "radio",
1498
+ name,
1499
+ value: option,
1500
+ "data-acp": "authority-radio",
1501
+ "data-level": option,
1502
+ checked: level === option,
1503
+ disabled: blocked,
1504
+ onChange: () => setLevel(id, option)
1505
+ }
1506
+ ),
1507
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1508
+ "label",
1509
+ {
1510
+ htmlFor: optionId,
1511
+ "data-acp": "authority-level-label",
1512
+ "data-level": option,
1513
+ children: LEVEL_LABEL[option]
1514
+ }
1515
+ )
1516
+ ] }, option);
1517
+ })
1518
+ ]
1519
+ }
1520
+ )
1521
+ ]
1522
+ }
1523
+ );
1524
+ }
1525
+ var AuthorityBoundary = {
1526
+ Root: Root10,
1527
+ Header: Header7,
1528
+ Icon: Icon7,
1529
+ Title: Title10,
1530
+ Description: Description5,
1531
+ Summary,
1532
+ List: List2,
1533
+ Capability
1534
+ };
1535
+
1536
+ // src/spend-limits/spend-limits.tsx
1537
+ var React8 = __toESM(require("react"), 1);
1538
+ var import_jsx_runtime8 = require("react/jsx-runtime");
1539
+ var SpendLimitsContext = React8.createContext(null);
1540
+ function useSpendLimitsContext(part) {
1541
+ const ctx = React8.useContext(SpendLimitsContext);
1542
+ if (!ctx) {
1543
+ throw new Error(
1544
+ `SpendLimits.${part} must be rendered inside SpendLimits.Root`
1545
+ );
1546
+ }
1547
+ return ctx;
1548
+ }
1549
+ function useControllableMap2(value, defaultValue, onValueChange) {
1550
+ const isControlled = value !== void 0;
1551
+ const [internal, setInternal] = React8.useState(
1552
+ () => defaultValue ?? {}
1553
+ );
1554
+ const current = isControlled ? value : internal;
1555
+ const setCap = React8.useCallback(
1556
+ (id, cap) => {
1557
+ const next = { ...current, [id]: cap };
1558
+ if (!isControlled) setInternal(next);
1559
+ onValueChange?.(next);
1560
+ },
1561
+ [current, isControlled, onValueChange]
1562
+ );
1563
+ return [current, setCap];
1564
+ }
1565
+ var WARNING_RATIO = 0.8;
1566
+ function stateFor(used, cap) {
1567
+ if (cap == null) return "none";
1568
+ if (used >= cap) return "reached";
1569
+ if (used / cap >= WARNING_RATIO) return "warning";
1570
+ return "ok";
1571
+ }
1572
+ var Root11 = React8.forwardRef(
1573
+ function SpendLimitsRoot({ limits, value, defaultValue, onValueChange, children, ...rest }, ref) {
1574
+ const titleId = React8.useId();
1575
+ const [caps, setCap] = useControllableMap2(
1576
+ value,
1577
+ defaultValue,
1578
+ onValueChange
1579
+ );
1580
+ const ctx = React8.useMemo(() => {
1581
+ const usage = new Map(limits.map((l) => [l.id, l.used]));
1582
+ const getUsed = (id) => usage.get(id) ?? 0;
1583
+ const getCap = (id) => Object.prototype.hasOwnProperty.call(caps, id) ? caps[id] : null;
1584
+ const summary = {
1585
+ total: limits.length,
1586
+ ok: 0,
1587
+ warning: 0,
1588
+ reached: 0
1589
+ };
1590
+ for (const limit of limits) {
1591
+ const state = stateFor(limit.used, getCap(limit.id));
1592
+ if (state === "ok") summary.ok += 1;
1593
+ else if (state === "warning") summary.warning += 1;
1594
+ else if (state === "reached") summary.reached += 1;
1595
+ }
1596
+ return {
1597
+ getUsed,
1598
+ getCap,
1599
+ setCap,
1600
+ getState: (id) => stateFor(getUsed(id), getCap(id)),
1601
+ summary,
1602
+ titleId
1603
+ };
1604
+ }, [limits, caps, setCap, titleId]);
1605
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(SpendLimitsContext.Provider, { value: ctx, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1606
+ "section",
1607
+ {
1608
+ ref,
1609
+ role: "group",
1610
+ "aria-labelledby": titleId,
1611
+ "data-acp": "root",
1612
+ "data-limits": "",
1613
+ ...rest,
1614
+ children
1615
+ }
1616
+ ) });
1617
+ }
1618
+ );
1619
+ function Header8(props) {
1620
+ useSpendLimitsContext("Header");
1621
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { "data-acp": "header", ...props });
1622
+ }
1623
+ function Icon8(props) {
1624
+ useSpendLimitsContext("Icon");
1625
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { "aria-hidden": true, "data-acp": "icon", ...props });
1626
+ }
1627
+ function Title11(props) {
1628
+ const { titleId } = useSpendLimitsContext("Title");
1629
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("h2", { id: titleId, "data-acp": "title", ...props });
1630
+ }
1631
+ function Description6(props) {
1632
+ useSpendLimitsContext("Description");
1633
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { "data-acp": "limits-description", ...props });
1634
+ }
1635
+ function Summary2({ children, ...rest }) {
1636
+ const { summary } = useSpendLimitsContext("Summary");
1637
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { "data-acp": "limits-summary", "aria-live": "polite", ...rest, children: children(summary) });
1638
+ }
1639
+ function List3(props) {
1640
+ useSpendLimitsContext("List");
1641
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("ul", { "data-acp": "limits-list", ...props });
1642
+ }
1643
+ var KIND_LABEL = {
1644
+ spend: "Budget",
1645
+ rate: "Rate"
1646
+ };
1647
+ var STATE_NOTE = {
1648
+ none: null,
1649
+ ok: null,
1650
+ warning: "Near cap",
1651
+ reached: "Cap reached \u2014 agent will ask before doing more"
1652
+ };
1653
+ var PERIOD_PHRASE = {
1654
+ day: "today",
1655
+ week: "this week",
1656
+ month: "this month"
1657
+ };
1658
+ function formatAmount(kind, unit, n) {
1659
+ return kind === "spend" ? `${unit}${n.toLocaleString()}` : `${n.toLocaleString()} ${unit}`;
1660
+ }
1661
+ function formatRange(kind, unit, used, cap) {
1662
+ return kind === "spend" ? `${unit}${used.toLocaleString()} of ${unit}${cap.toLocaleString()}` : `${used.toLocaleString()} of ${cap.toLocaleString()} ${unit}`;
1663
+ }
1664
+ function Limit({
1665
+ id,
1666
+ kind,
1667
+ unit,
1668
+ period,
1669
+ label,
1670
+ description,
1671
+ ...rest
1672
+ }) {
1673
+ const { getUsed, getCap, setCap, getState } = useSpendLimitsContext("Limit");
1674
+ const descId = React8.useId();
1675
+ const capId = React8.useId();
1676
+ const readoutId = React8.useId();
1677
+ const used = getUsed(id);
1678
+ const cap = getCap(id);
1679
+ const state = getState(id);
1680
+ const pct = cap == null ? 0 : cap > 0 ? Math.min(100, used / cap * 100) : 100;
1681
+ const readout = cap != null ? `${formatRange(kind, unit, used, cap)} ${PERIOD_PHRASE[period]}` : `${formatAmount(kind, unit, used)} used \xB7 no limit set`;
1682
+ const note = STATE_NOTE[state];
1683
+ const labelText = typeof label === "string" ? label : "this limit";
1684
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
1685
+ "li",
1686
+ {
1687
+ "data-acp": "limits-limit",
1688
+ "data-kind": kind,
1689
+ "data-state": state,
1690
+ ...rest,
1691
+ children: [
1692
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { "data-acp": "limits-limit-body", children: [
1693
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { "data-acp": "limits-limit-head", children: [
1694
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { "data-acp": "limits-kind", "data-kind": kind, children: KIND_LABEL[kind] }),
1695
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { "data-acp": "limits-limit-name", children: label })
1696
+ ] }),
1697
+ description != null && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { id: descId, "data-acp": "limits-limit-description", children: description }),
1698
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { "data-acp": "limits-meter", "data-state": state, children: [
1699
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { "data-acp": "limits-meter-track", "aria-hidden": "true", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1700
+ "span",
1701
+ {
1702
+ "data-acp": "limits-meter-fill",
1703
+ "data-state": state,
1704
+ style: { width: `${pct}%` }
1705
+ }
1706
+ ) }),
1707
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { id: readoutId, "data-acp": "limits-meter-readout", children: readout })
1708
+ ] }),
1709
+ note != null && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { "data-acp": "limits-status", "data-state": state, children: note })
1710
+ ] }),
1711
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { "data-acp": "limits-cap", children: [
1712
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("label", { htmlFor: capId, "data-acp": "limits-cap-label", children: "Cap" }),
1713
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { "data-acp": "limits-cap-field", children: [
1714
+ kind === "spend" && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { "data-acp": "limits-cap-unit", "aria-hidden": "true", children: unit }),
1715
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1716
+ "input",
1717
+ {
1718
+ id: capId,
1719
+ type: "number",
1720
+ min: 0,
1721
+ inputMode: "numeric",
1722
+ "data-acp": "limits-cap-input",
1723
+ "aria-label": `${labelText} cap, per ${period}`,
1724
+ "aria-describedby": description != null ? descId : void 0,
1725
+ value: cap ?? "",
1726
+ onChange: (event) => {
1727
+ const next = event.target.valueAsNumber;
1728
+ setCap(id, Number.isNaN(next) ? 0 : Math.max(0, next));
1729
+ }
1730
+ }
1731
+ ),
1732
+ kind === "rate" && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { "data-acp": "limits-cap-unit", children: unit }),
1733
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { "data-acp": "limits-cap-period", children: [
1734
+ "per ",
1735
+ period
1736
+ ] })
1737
+ ] })
1738
+ ] })
1739
+ ]
1740
+ }
1741
+ );
1742
+ }
1743
+ var SpendLimits = {
1744
+ Root: Root11,
1745
+ Header: Header8,
1746
+ Icon: Icon8,
1747
+ Title: Title11,
1748
+ Description: Description6,
1749
+ Summary: Summary2,
1750
+ List: List3,
1751
+ Limit
1752
+ };
1753
+
1754
+ // src/credential-handoff/credential-handoff.tsx
1755
+ var React9 = __toESM(require("react"), 1);
1756
+ var import_jsx_runtime9 = require("react/jsx-runtime");
1757
+ var CredentialHandoffContext = React9.createContext(null);
1758
+ function useCredentialHandoffContext(part) {
1759
+ const ctx = React9.useContext(CredentialHandoffContext);
1760
+ if (!ctx) {
1761
+ throw new Error(
1762
+ `CredentialHandoff.${part} must be rendered inside CredentialHandoff.Root`
1763
+ );
1764
+ }
1765
+ return ctx;
1766
+ }
1767
+ var Root12 = React9.forwardRef(
1768
+ function CredentialHandoffRoot({ onHandoff, onCancel, children, ...rest }, ref) {
1769
+ const titleId = React9.useId();
1770
+ const ctx = React9.useMemo(
1771
+ () => ({ onHandoff, onCancel, titleId }),
1772
+ [onHandoff, onCancel, titleId]
1773
+ );
1774
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(CredentialHandoffContext.Provider, { value: ctx, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1775
+ "section",
1776
+ {
1777
+ ref,
1778
+ role: "group",
1779
+ "aria-labelledby": titleId,
1780
+ "data-acp": "root",
1781
+ "data-handoff": "",
1782
+ ...rest,
1783
+ children
1784
+ }
1785
+ ) });
1786
+ }
1787
+ );
1788
+ function Header9(props) {
1789
+ useCredentialHandoffContext("Header");
1790
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { "data-acp": "header", ...props });
1791
+ }
1792
+ function Icon9(props) {
1793
+ useCredentialHandoffContext("Icon");
1794
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { "aria-hidden": true, "data-acp": "icon", ...props });
1795
+ }
1796
+ function Title12(props) {
1797
+ const { titleId } = useCredentialHandoffContext("Title");
1798
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("h2", { id: titleId, "data-acp": "title", ...props });
1799
+ }
1800
+ function Description7(props) {
1801
+ useCredentialHandoffContext("Description");
1802
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("p", { "data-acp": "handoff-description", ...props });
1803
+ }
1804
+ var HANDLER_LABEL = {
1805
+ "password-manager": "Password manager",
1806
+ passkey: "Passkey",
1807
+ payment: "Payment",
1808
+ provider: "Provider"
1809
+ };
1810
+ function Handler({ kind, name, children, ...rest }) {
1811
+ useCredentialHandoffContext("Handler");
1812
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { "data-acp": "handoff-handler", "data-kind": kind, ...rest, children: [
1813
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { "data-acp": "handoff-handler-kind", "data-kind": kind, children: HANDLER_LABEL[kind] }),
1814
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { "data-acp": "handoff-handler-name", children: name }),
1815
+ children
1816
+ ] });
1817
+ }
1818
+ function Boundary(props) {
1819
+ useCredentialHandoffContext("Boundary");
1820
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { role: "note", "data-acp": "handoff-boundary", ...props });
1821
+ }
1822
+ function Returns({ legend, children, ...rest }) {
1823
+ useCredentialHandoffContext("Returns");
1824
+ const labelId = React9.useId();
1825
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { "data-acp": "handoff-returns", children: [
1826
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("p", { id: labelId, "data-acp": "handoff-returns-legend", children: legend ?? "The agent receives:" }),
1827
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("ul", { "aria-labelledby": labelId, "data-acp": "handoff-returns-list", ...rest, children })
1828
+ ] });
1829
+ }
1830
+ function Return(props) {
1831
+ useCredentialHandoffContext("Return");
1832
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("li", { "data-acp": "handoff-return", ...props });
1833
+ }
1834
+ function Actions6(props) {
1835
+ useCredentialHandoffContext("Actions");
1836
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { "data-acp": "actions", ...props });
1837
+ }
1838
+ var Handoff = React9.forwardRef(function CredentialHandoffHandoff({ onClick, ...rest }, ref) {
1839
+ const { onHandoff } = useCredentialHandoffContext("Handoff");
1840
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1841
+ "button",
1842
+ {
1843
+ ref,
1844
+ type: "button",
1845
+ "data-acp": "handoff-continue",
1846
+ onClick: (event) => {
1847
+ onClick?.(event);
1848
+ if (!event.defaultPrevented) onHandoff();
1849
+ },
1850
+ ...rest
1851
+ }
1852
+ );
1853
+ });
1854
+ var Cancel6 = React9.forwardRef(function CredentialHandoffCancel({ onClick, ...rest }, ref) {
1855
+ const { onCancel } = useCredentialHandoffContext("Cancel");
1856
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1857
+ "button",
1858
+ {
1859
+ ref,
1860
+ type: "button",
1861
+ "data-acp": "handoff-cancel",
1862
+ onClick: (event) => {
1863
+ onClick?.(event);
1864
+ if (!event.defaultPrevented) onCancel();
1865
+ },
1866
+ ...rest
1867
+ }
1868
+ );
1869
+ });
1870
+ var CredentialHandoff = {
1871
+ Root: Root12,
1872
+ Header: Header9,
1873
+ Icon: Icon9,
1874
+ Title: Title12,
1875
+ Description: Description7,
1876
+ Handler,
1877
+ Boundary,
1878
+ Returns,
1879
+ Return,
1880
+ Actions: Actions6,
1881
+ Handoff,
1882
+ Cancel: Cancel6
1883
+ };
1884
+
1885
+ // src/action-receipt/action-receipt.tsx
1886
+ var React10 = __toESM(require("react"), 1);
1887
+ var import_jsx_runtime10 = require("react/jsx-runtime");
1888
+ var ActionReceiptContext = React10.createContext(null);
1889
+ function useActionReceiptContext(part) {
1890
+ const ctx = React10.useContext(ActionReceiptContext);
1891
+ if (!ctx) {
1892
+ throw new Error(
1893
+ `ActionReceipt.${part} must be rendered inside ActionReceipt.Root`
1894
+ );
1895
+ }
1896
+ return ctx;
1897
+ }
1898
+ var Root13 = React10.forwardRef(
1899
+ function ActionReceiptRoot({ outcome = "completed", reversibility = "reversible", children, ...rest }, ref) {
1900
+ const titleId = React10.useId();
1901
+ const ctx = React10.useMemo(
1902
+ () => ({ outcome, reversibility, titleId }),
1903
+ [outcome, reversibility, titleId]
1904
+ );
1905
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ActionReceiptContext.Provider, { value: ctx, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1906
+ "article",
1907
+ {
1908
+ ref,
1909
+ "aria-labelledby": titleId,
1910
+ "data-acp": "root",
1911
+ "data-receipt": "",
1912
+ "data-outcome": outcome,
1913
+ ...rest,
1914
+ children
1915
+ }
1916
+ ) });
1917
+ }
1918
+ );
1919
+ function Header10(props) {
1920
+ useActionReceiptContext("Header");
1921
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { "data-acp": "header", "data-receipt-header": "", ...props });
1922
+ }
1923
+ function Icon10(props) {
1924
+ useActionReceiptContext("Icon");
1925
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { "aria-hidden": true, "data-acp": "icon", ...props });
1926
+ }
1927
+ function Title13(props) {
1928
+ const { titleId } = useActionReceiptContext("Title");
1929
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { id: titleId, "data-acp": "title", ...props });
1930
+ }
1931
+ var OUTCOME_LABEL = {
1932
+ completed: "Completed",
1933
+ undone: "Undone",
1934
+ failed: "Failed"
1935
+ };
1936
+ function Outcome({ children, ...rest }) {
1937
+ const { outcome } = useActionReceiptContext("Outcome");
1938
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { "data-acp": "receipt-outcome", "data-outcome": outcome, ...rest, children: children ?? OUTCOME_LABEL[outcome] });
1939
+ }
1940
+ function Details(props) {
1941
+ useActionReceiptContext("Details");
1942
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("dl", { "data-acp": "receipt-details", ...props });
1943
+ }
1944
+ function Detail({ label, children, ...rest }) {
1945
+ useActionReceiptContext("Detail");
1946
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { "data-acp": "receipt-detail", ...rest, children: [
1947
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("dt", { "data-acp": "receipt-detail-label", children: label }),
1948
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("dd", { "data-acp": "receipt-detail-value", children })
1949
+ ] });
1950
+ }
1951
+ function Authority({ grant, via, children, ...rest }) {
1952
+ useActionReceiptContext("Authority");
1953
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { "data-acp": "receipt-authority", ...rest, children: [
1954
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { "data-acp": "receipt-authority-label", children: "Under authority" }),
1955
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { "data-acp": "receipt-authority-grant", children: grant }),
1956
+ via != null && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { "data-acp": "receipt-authority-via", children: via }),
1957
+ children
1958
+ ] });
1959
+ }
1960
+ function Meta(props) {
1961
+ useActionReceiptContext("Meta");
1962
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("dl", { "data-acp": "receipt-meta", ...props });
1963
+ }
1964
+ function MetaItem({ label, children, ...rest }) {
1965
+ useActionReceiptContext("MetaItem");
1966
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { "data-acp": "receipt-meta-item", ...rest, children: [
1967
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("dt", { "data-acp": "receipt-meta-label", children: label }),
1968
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("dd", { "data-acp": "receipt-meta-value", children })
1969
+ ] });
1970
+ }
1971
+ function Actions7(props) {
1972
+ useActionReceiptContext("Actions");
1973
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { "data-acp": "actions", "data-receipt-actions": "", ...props });
1974
+ }
1975
+ var Undo = React10.forwardRef(
1976
+ function ActionReceiptUndo({ children, irreversibleNote, undoneNote, ...rest }, ref) {
1977
+ const { outcome, reversibility } = useActionReceiptContext("Undo");
1978
+ if (outcome === "undone") {
1979
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { "data-acp": "receipt-undo-note", "data-state": "undone", children: undoneNote ?? "Undone" });
1980
+ }
1981
+ if (reversibility === "irreversible") {
1982
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { "data-acp": "receipt-undo-note", "data-state": "permanent", children: irreversibleNote ?? "Can't be undone" });
1983
+ }
1984
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { ref, type: "button", "data-acp": "receipt-undo", ...rest, children: children ?? "Undo" });
1985
+ }
1986
+ );
1987
+ var ActionReceipt = {
1988
+ Root: Root13,
1989
+ Header: Header10,
1990
+ Icon: Icon10,
1991
+ Title: Title13,
1992
+ Outcome,
1993
+ Details,
1994
+ Detail,
1995
+ Authority,
1996
+ Meta,
1997
+ MetaItem,
1998
+ Actions: Actions7,
1999
+ Undo
2000
+ };
2001
+
2002
+ // src/injection-flag/injection-flag.tsx
2003
+ var React11 = __toESM(require("react"), 1);
2004
+ var AlertDialog4 = __toESM(require("@radix-ui/react-alert-dialog"), 1);
2005
+ var import_jsx_runtime11 = require("react/jsx-runtime");
2006
+ var InjectionFlagContext = React11.createContext(null);
2007
+ function useInjectionFlagContext(part) {
2008
+ const ctx = React11.useContext(InjectionFlagContext);
2009
+ if (!ctx) {
2010
+ throw new Error(
2011
+ `InjectionFlag.${part} must be rendered inside InjectionFlag.Root`
2012
+ );
2013
+ }
2014
+ return ctx;
2015
+ }
2016
+ var Root15 = React11.forwardRef(
2017
+ function InjectionFlagRoot({ onProceed, onDismiss, asModal = false, open, onOpenChange, children, ...rest }, ref) {
2018
+ const titleId = React11.useId();
2019
+ const ctx = React11.useMemo(
2020
+ () => ({ onProceed, onDismiss, asModal, titleId }),
2021
+ [onProceed, onDismiss, asModal, titleId]
2022
+ );
2023
+ if (asModal) {
2024
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(InjectionFlagContext.Provider, { value: ctx, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(AlertDialog4.Root, { open, onOpenChange, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(AlertDialog4.Portal, { children: [
2025
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(AlertDialog4.Overlay, { "data-acp": "overlay" }),
2026
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2027
+ AlertDialog4.Content,
2028
+ {
2029
+ ref,
2030
+ "data-acp": "root",
2031
+ "data-injection": "",
2032
+ "data-modal": "",
2033
+ "aria-describedby": void 0,
2034
+ onEscapeKeyDown: onDismiss,
2035
+ ...rest,
2036
+ children
2037
+ }
2038
+ )
2039
+ ] }) }) });
2040
+ }
2041
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(InjectionFlagContext.Provider, { value: ctx, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2042
+ "section",
2043
+ {
2044
+ ref,
2045
+ role: "group",
2046
+ "aria-labelledby": titleId,
2047
+ "data-acp": "root",
2048
+ "data-injection": "",
2049
+ ...rest,
2050
+ children
2051
+ }
2052
+ ) });
2053
+ }
2054
+ );
2055
+ function Header11(props) {
2056
+ useInjectionFlagContext("Header");
2057
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { "data-acp": "header", ...props });
2058
+ }
2059
+ function Icon11(props) {
2060
+ useInjectionFlagContext("Icon");
2061
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { "aria-hidden": true, "data-acp": "icon", ...props });
2062
+ }
2063
+ function Title15(props) {
2064
+ const { asModal, titleId } = useInjectionFlagContext("Title");
2065
+ if (asModal) {
2066
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(AlertDialog4.Title, { "data-acp": "title", ...props });
2067
+ }
2068
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("h2", { id: titleId, "data-acp": "title", ...props });
2069
+ }
2070
+ function Description8(props) {
2071
+ useInjectionFlagContext("Description");
2072
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("p", { "data-acp": "injection-description", ...props });
2073
+ }
2074
+ function Source2({ origin, location, children, ...rest }) {
2075
+ useInjectionFlagContext("Source");
2076
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { "data-acp": "injection-source", ...rest, children: [
2077
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { "data-acp": "injection-source-label", children: "Came from" }),
2078
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { "data-acp": "injection-origin", children: origin }),
2079
+ location != null && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { "data-acp": "injection-location", children: location }),
2080
+ children
2081
+ ] });
2082
+ }
2083
+ function Quote({ label, children, ...rest }) {
2084
+ useInjectionFlagContext("Quote");
2085
+ const labelId = React11.useId();
2086
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("figure", { "data-acp": "injection-quote-figure", children: [
2087
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("figcaption", { id: labelId, "data-acp": "injection-quote-label", children: label ?? "The instruction reads:" }),
2088
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2089
+ "blockquote",
2090
+ {
2091
+ "data-acp": "injection-quote",
2092
+ "aria-labelledby": labelId,
2093
+ ...rest,
2094
+ children
2095
+ }
2096
+ )
2097
+ ] });
2098
+ }
2099
+ function Consequence2(props) {
2100
+ useInjectionFlagContext("Consequence");
2101
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("p", { "data-acp": "injection-consequence", ...props });
2102
+ }
2103
+ function Actions8(props) {
2104
+ useInjectionFlagContext("Actions");
2105
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { "data-acp": "actions", ...props });
2106
+ }
2107
+ var Proceed = React11.forwardRef(
2108
+ function InjectionFlagProceed({ onClick, ...rest }, ref) {
2109
+ const { onProceed, asModal } = useInjectionFlagContext("Proceed");
2110
+ const handleClick = (event) => {
2111
+ onClick?.(event);
2112
+ if (!event.defaultPrevented) onProceed();
2113
+ };
2114
+ const button = /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2115
+ "button",
2116
+ {
2117
+ ref,
2118
+ type: "button",
2119
+ "data-acp": "injection-proceed",
2120
+ onClick: handleClick,
2121
+ ...rest
2122
+ }
2123
+ );
2124
+ return asModal ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(AlertDialog4.Action, { asChild: true, children: button }) : button;
2125
+ }
2126
+ );
2127
+ var Dismiss = React11.forwardRef(
2128
+ function InjectionFlagDismiss({ onClick, ...rest }, ref) {
2129
+ const { onDismiss, asModal } = useInjectionFlagContext("Dismiss");
2130
+ const handleClick = (event) => {
2131
+ onClick?.(event);
2132
+ if (!event.defaultPrevented) onDismiss();
2133
+ };
2134
+ const button = /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
2135
+ "button",
2136
+ {
2137
+ ref,
2138
+ type: "button",
2139
+ "data-acp": "injection-dismiss",
2140
+ onClick: handleClick,
2141
+ ...rest
2142
+ }
2143
+ );
2144
+ return asModal ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(AlertDialog4.Cancel, { asChild: true, children: button }) : button;
2145
+ }
2146
+ );
2147
+ var InjectionFlag = {
2148
+ Root: Root15,
2149
+ Header: Header11,
2150
+ Icon: Icon11,
2151
+ Title: Title15,
2152
+ Description: Description8,
2153
+ Source: Source2,
2154
+ Quote,
2155
+ Consequence: Consequence2,
2156
+ Actions: Actions8,
2157
+ Proceed,
2158
+ Dismiss
2159
+ };
2160
+
2161
+ // src/connection-card/connection-card.tsx
2162
+ var React12 = __toESM(require("react"), 1);
2163
+ var import_jsx_runtime12 = require("react/jsx-runtime");
2164
+ var ConnectionCardContext = React12.createContext(null);
2165
+ function useConnectionCardContext(part) {
2166
+ const ctx = React12.useContext(ConnectionCardContext);
2167
+ if (!ctx) {
2168
+ throw new Error(
2169
+ `ConnectionCard.${part} must be rendered inside ConnectionCard.Root`
2170
+ );
2171
+ }
2172
+ return ctx;
2173
+ }
2174
+ var Root16 = React12.forwardRef(
2175
+ function ConnectionCardRoot({ status = "active", children, ...rest }, ref) {
2176
+ const titleId = React12.useId();
2177
+ const ctx = React12.useMemo(
2178
+ () => ({ status, titleId }),
2179
+ [status, titleId]
2180
+ );
2181
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(ConnectionCardContext.Provider, { value: ctx, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
2182
+ "article",
2183
+ {
2184
+ ref,
2185
+ "aria-labelledby": titleId,
2186
+ "data-acp": "root",
2187
+ "data-connection": "",
2188
+ "data-status": status,
2189
+ ...rest,
2190
+ children
2191
+ }
2192
+ ) });
2193
+ }
2194
+ );
2195
+ function Header12(props) {
2196
+ useConnectionCardContext("Header");
2197
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { "data-acp": "header", "data-connection-header": "", ...props });
2198
+ }
2199
+ function Icon12(props) {
2200
+ useConnectionCardContext("Icon");
2201
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { "aria-hidden": true, "data-acp": "icon", ...props });
2202
+ }
2203
+ function Title16(props) {
2204
+ const { titleId } = useConnectionCardContext("Title");
2205
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { id: titleId, "data-acp": "title", ...props });
2206
+ }
2207
+ var STATUS_LABEL = {
2208
+ active: "Active",
2209
+ paused: "Paused",
2210
+ "needs-reauth": "Needs re-auth",
2211
+ expired: "Expired"
2212
+ };
2213
+ function Status({ children, ...rest }) {
2214
+ const { status } = useConnectionCardContext("Status");
2215
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { "data-acp": "connection-status", "data-status": status, ...rest, children: children ?? STATUS_LABEL[status] });
2216
+ }
2217
+ function Scopes(props) {
2218
+ useConnectionCardContext("Scopes");
2219
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("ul", { "data-acp": "connection-scopes", ...props });
2220
+ }
2221
+ var ACCESS_LABEL4 = {
2222
+ read: "Read",
2223
+ write: "Write",
2224
+ delete: "Delete"
2225
+ };
2226
+ function Scope2({ access, children, ...rest }) {
2227
+ useConnectionCardContext("Scope");
2228
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("li", { "data-acp": "connection-scope", "data-access": access, ...rest, children: [
2229
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { "data-acp": "connection-access", "data-access": access, children: ACCESS_LABEL4[access] }),
2230
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { "data-acp": "connection-scope-name", children })
2231
+ ] });
2232
+ }
2233
+ function Meta2(props) {
2234
+ useConnectionCardContext("Meta");
2235
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("dl", { "data-acp": "connection-meta", ...props });
2236
+ }
2237
+ function MetaItem2({ label, children, ...rest }) {
2238
+ useConnectionCardContext("MetaItem");
2239
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { "data-acp": "connection-meta-item", ...rest, children: [
2240
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("dt", { "data-acp": "connection-meta-label", children: label }),
2241
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("dd", { "data-acp": "connection-meta-value", children })
2242
+ ] });
2243
+ }
2244
+ function Actions9(props) {
2245
+ useConnectionCardContext("Actions");
2246
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { "data-acp": "actions", "data-connection-actions": "", ...props });
2247
+ }
2248
+ var Action5 = React12.forwardRef(
2249
+ function ConnectionCardAction({ tone = "default", type, ...rest }, ref) {
2250
+ useConnectionCardContext("Action");
2251
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
2252
+ "button",
2253
+ {
2254
+ ref,
2255
+ type: type ?? "button",
2256
+ "data-acp": "connection-action",
2257
+ "data-tone": tone,
2258
+ ...rest
2259
+ }
2260
+ );
2261
+ }
2262
+ );
2263
+ var ConnectionCard = {
2264
+ Root: Root16,
2265
+ Header: Header12,
2266
+ Icon: Icon12,
2267
+ Title: Title16,
2268
+ Status,
2269
+ Scopes,
2270
+ Scope: Scope2,
2271
+ Meta: Meta2,
2272
+ MetaItem: MetaItem2,
2273
+ Actions: Actions9,
2274
+ Action: Action5
2275
+ };
2276
+ // Annotate the CommonJS export names for ESM import in node:
2277
+ 0 && (module.exports = {
2278
+ AUTHORITY_LEVELS,
2279
+ ActionPreview,
2280
+ ActionReceipt,
2281
+ AuthorityBoundary,
2282
+ BatchApproval,
2283
+ ConnectionCard,
2284
+ ConsentMemory,
2285
+ CredentialHandoff,
2286
+ InjectionFlag,
2287
+ IrreversibilityGate,
2288
+ ProgressiveScope,
2289
+ ScopedGrant,
2290
+ SpendLimits
2291
+ });
2292
+ //# sourceMappingURL=index.cjs.map