@kya-os/consent 0.5.0 → 0.5.2

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.
Files changed (100) hide show
  1. package/README.md +5 -1
  2. package/dist/bundle/inline.d.ts.map +1 -1
  3. package/dist/bundle/inline.js +4 -4
  4. package/dist/bundle/inline.js.map +1 -1
  5. package/dist/cjs/bundle/inline.js +4 -4
  6. package/dist/cjs/bundle/inline.js.map +1 -1
  7. package/dist/cjs/components/consent-action-bar.js +4 -0
  8. package/dist/cjs/components/consent-action-bar.js.map +1 -1
  9. package/dist/cjs/components/consent-capabilities-screen.js +1 -1
  10. package/dist/cjs/components/consent-capabilities-screen.js.map +1 -1
  11. package/dist/cjs/components/consent-connector-header.js +1 -0
  12. package/dist/cjs/components/consent-connector-header.js.map +1 -1
  13. package/dist/cjs/components/consent-flow.js +403 -13
  14. package/dist/cjs/components/consent-flow.js.map +1 -1
  15. package/dist/cjs/components/consent-wallet-orb.js +6 -1
  16. package/dist/cjs/components/consent-wallet-orb.js.map +1 -1
  17. package/dist/cjs/components/flow-blocks.js +162 -35
  18. package/dist/cjs/components/flow-blocks.js.map +1 -1
  19. package/dist/cjs/flow/copy.js +15 -0
  20. package/dist/cjs/flow/copy.js.map +1 -1
  21. package/dist/cjs/flow/index.js +5 -2
  22. package/dist/cjs/flow/index.js.map +1 -1
  23. package/dist/cjs/flow/model.js +46 -1
  24. package/dist/cjs/flow/model.js.map +1 -1
  25. package/dist/cjs/flow/page.js +282 -0
  26. package/dist/cjs/flow/page.js.map +1 -0
  27. package/dist/cjs/flow/presets.js +4 -0
  28. package/dist/cjs/flow/presets.js.map +1 -1
  29. package/dist/cjs/flow/schema.js +1 -0
  30. package/dist/cjs/flow/schema.js.map +1 -1
  31. package/dist/cjs/mcp-app/inline.js +2 -2
  32. package/dist/cjs/mcp-app/inline.js.map +1 -1
  33. package/dist/cjs/react/index.js +1 -0
  34. package/dist/cjs/react/index.js.map +1 -1
  35. package/dist/cjs/styles/brand.js +135 -38
  36. package/dist/cjs/styles/brand.js.map +1 -1
  37. package/dist/cjs/styles/theme.js +29 -3
  38. package/dist/cjs/styles/theme.js.map +1 -1
  39. package/dist/components/consent-action-bar.d.ts.map +1 -1
  40. package/dist/components/consent-action-bar.js +4 -0
  41. package/dist/components/consent-action-bar.js.map +1 -1
  42. package/dist/components/consent-capabilities-screen.d.ts.map +1 -1
  43. package/dist/components/consent-capabilities-screen.js +1 -1
  44. package/dist/components/consent-capabilities-screen.js.map +1 -1
  45. package/dist/components/consent-connector-header.d.ts.map +1 -1
  46. package/dist/components/consent-connector-header.js +1 -0
  47. package/dist/components/consent-connector-header.js.map +1 -1
  48. package/dist/components/consent-flow.d.ts +61 -3
  49. package/dist/components/consent-flow.d.ts.map +1 -1
  50. package/dist/components/consent-flow.js +405 -15
  51. package/dist/components/consent-flow.js.map +1 -1
  52. package/dist/components/consent-wallet-orb.d.ts +4 -0
  53. package/dist/components/consent-wallet-orb.d.ts.map +1 -1
  54. package/dist/components/consent-wallet-orb.js +6 -1
  55. package/dist/components/consent-wallet-orb.js.map +1 -1
  56. package/dist/components/flow-blocks.d.ts +10 -1
  57. package/dist/components/flow-blocks.d.ts.map +1 -1
  58. package/dist/components/flow-blocks.js +162 -36
  59. package/dist/components/flow-blocks.js.map +1 -1
  60. package/dist/consent.js +856 -272
  61. package/dist/consent.min.js +634 -397
  62. package/dist/flow/copy.d.ts +2 -0
  63. package/dist/flow/copy.d.ts.map +1 -1
  64. package/dist/flow/copy.js +14 -0
  65. package/dist/flow/copy.js.map +1 -1
  66. package/dist/flow/index.d.ts +5 -2
  67. package/dist/flow/index.d.ts.map +1 -1
  68. package/dist/flow/index.js +5 -2
  69. package/dist/flow/index.js.map +1 -1
  70. package/dist/flow/model.d.ts +53 -2
  71. package/dist/flow/model.d.ts.map +1 -1
  72. package/dist/flow/model.js +45 -0
  73. package/dist/flow/model.js.map +1 -1
  74. package/dist/flow/page.d.ts +110 -0
  75. package/dist/flow/page.d.ts.map +1 -0
  76. package/dist/flow/page.js +276 -0
  77. package/dist/flow/page.js.map +1 -0
  78. package/dist/flow/presets.d.ts.map +1 -1
  79. package/dist/flow/presets.js +4 -0
  80. package/dist/flow/presets.js.map +1 -1
  81. package/dist/flow/schema.d.ts +19 -14
  82. package/dist/flow/schema.d.ts.map +1 -1
  83. package/dist/flow/schema.js +1 -0
  84. package/dist/flow/schema.js.map +1 -1
  85. package/dist/mcp-app/inline.d.ts.map +1 -1
  86. package/dist/mcp-app/inline.js +2 -2
  87. package/dist/mcp-app/inline.js.map +1 -1
  88. package/dist/react/index.d.ts +2 -1
  89. package/dist/react/index.d.ts.map +1 -1
  90. package/dist/react/index.js +1 -0
  91. package/dist/react/index.js.map +1 -1
  92. package/dist/styles/brand.d.ts +53 -18
  93. package/dist/styles/brand.d.ts.map +1 -1
  94. package/dist/styles/brand.js +136 -39
  95. package/dist/styles/brand.js.map +1 -1
  96. package/dist/styles/theme.d.ts +10 -1
  97. package/dist/styles/theme.d.ts.map +1 -1
  98. package/dist/styles/theme.js +28 -2
  99. package/dist/styles/theme.js.map +1 -1
  100. package/package.json +2 -2
@@ -30,9 +30,10 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
30
30
  import { LitElement, css, html, nothing, } from "lit";
31
31
  import { customElement, property } from "lit/decorators.js";
32
32
  import { repeat } from "lit/directives/repeat.js";
33
- import { fillTemplate, flowCopy, group } from "../flow/copy.js";
34
- import { FLOW_HOST_ATTRIBUTES, } from "../flow/model.js";
33
+ import { fillTemplate, flowCopy, group, httpsUrl } from "../flow/copy.js";
34
+ import { FLOW_FIELDS, FLOW_HOST_ATTRIBUTES, } from "../flow/model.js";
35
35
  import { DECISION_FLOW } from "../flow/presets.js";
36
+ import { brandTokens } from "../styles/brand.js";
36
37
  import { getConsentTheme, themeScopeStyle } from "../styles/theme.js";
37
38
  import { BLOCK_MORPH_FROM, FLOW_BLOCK_RENDERERS, flowBlockStyles, flowValues, } from "./flow-blocks.js";
38
39
  import * as motion from "./flow-motion.js";
@@ -82,8 +83,67 @@ function signatureOf(value) {
82
83
  return String(value);
83
84
  }
84
85
  const blockName = (key) => key.split("#")[0];
85
- /** The properties that redraw the card, and so may move it. */
86
- const DRAWN = ["flow", "data", "copy", "step", "preview"];
86
+ /**
87
+ * The properties whose change moves the card: a new step, or a new flow.
88
+ * Words, data, terms or preview changing on the same step redraw in place,
89
+ * so an editor's typing never plays motion.
90
+ */
91
+ const MOVES = ["flow", "step"];
92
+ /** The highlight's room around its region, in CSS pixels. */
93
+ const SPOT_X = 8;
94
+ const SPOT_Y = 6;
95
+ /** The room a label needs above the ring's top edge, or it sits on the bottom one. */
96
+ const LABEL_ROOM = 10;
97
+ /** Whether `node` is drawn inside `container`, through shadow roots. */
98
+ function within(container, node) {
99
+ while (node) {
100
+ if (node === container)
101
+ return true;
102
+ node = node.parentNode ?? node.host ?? null;
103
+ }
104
+ return false;
105
+ }
106
+ /** A rect pulled in by `by` on every side. */
107
+ function inset(rect, by) {
108
+ return new DOMRect(rect.left + by, rect.top + by, rect.width - 2 * by, rect.height - 2 * by);
109
+ }
110
+ /** The ring's radius: the region's own (or its one box's) plus the room, else 8px. */
111
+ function ringRadius(region) {
112
+ const box = region.getBoundingClientRect();
113
+ for (const el of [region, region.firstElementChild]) {
114
+ if (!el)
115
+ continue;
116
+ const r = el.getBoundingClientRect();
117
+ if (Math.abs(r.width - box.width) > 1 ||
118
+ Math.abs(r.height - box.height) > 1)
119
+ continue;
120
+ const radius = parseFloat(getComputedStyle(el).borderTopLeftRadius) || 0;
121
+ if (radius > 0)
122
+ return radius + SPOT_Y;
123
+ }
124
+ return 8;
125
+ }
126
+ const isField = (name) => FLOW_FIELDS.includes(name ?? "");
127
+ /** The terms as the box knows them: a change to any of these asks again. */
128
+ const termsKey = (terms) => terms ? JSON.stringify([terms.label, terms.href, terms.version]) : "";
129
+ /**
130
+ * The brand as `:host` properties, or nothing for a set the package refuses.
131
+ * Properties only: the page paints its own background (`brandStyle` on its
132
+ * body), and a preview paints the host from `--cs-surface-bg`.
133
+ */
134
+ function brandRule(brand, theme) {
135
+ if (!brand)
136
+ return "";
137
+ try {
138
+ const declarations = Object.entries(brandTokens(brand, theme))
139
+ .map(([property, value]) => `${property}: ${value};`)
140
+ .join(" ");
141
+ return `:host { ${declarations} }`;
142
+ }
143
+ catch {
144
+ return "";
145
+ }
146
+ }
87
147
  let ConsentFlow = class ConsentFlow extends LitElement {
88
148
  constructor() {
89
149
  super();
@@ -96,9 +156,24 @@ let ConsentFlow = class ConsentFlow extends LitElement {
96
156
  * `initial` (or `consent`, when swapping flows mid-way). Reflected.
97
157
  */
98
158
  this.step = "";
99
- /** `light` or `dark`. Brand colours come in as `--cs-*` properties, as on the screen. */
159
+ /** `light` or `dark`. */
100
160
  this.theme = "light";
101
- /** An editor's preview: links don't navigate, and every event says `preview: true`. */
161
+ /** The links under the card: Terms, then Privacy. https only. */
162
+ this.legal = [];
163
+ /**
164
+ * In a preview, the region to outline (`FLOW_FIELDS`), for the editor's
165
+ * focused field. Ignored outside a preview.
166
+ */
167
+ this.highlight = "";
168
+ /** How the highlight draws: `select` (a solid ring with a tint) for a focused field, `hover` (a dashed ring). */
169
+ this.highlightMode = "select";
170
+ /** The highlighted field's name, in a small tag on the ring ("Description"); none when empty. */
171
+ this.highlightLabel = "";
172
+ /**
173
+ * An editor's preview: nothing the person presses acts (no sign-in, approve,
174
+ * deny or retry) and links don't navigate. The events it still sends (`step`,
175
+ * `motion`, `expire`) say `preview: true`.
176
+ */
102
177
  this.preview = false;
103
178
  this.selected = new Set();
104
179
  this.resolved = null;
@@ -107,6 +182,10 @@ let ConsentFlow = class ConsentFlow extends LitElement {
107
182
  this.atRest = null;
108
183
  this.pointerInside = false;
109
184
  this.generation = 0;
185
+ this.motionDone = Promise.resolve();
186
+ this.termsAccepted = false;
187
+ this.acceptedTerms = "";
188
+ this.resizes = null;
110
189
  this.onDocumentPointer = (event) => {
111
190
  this.pointerInside = event.composedPath().includes(this);
112
191
  };
@@ -114,13 +193,92 @@ let ConsentFlow = class ConsentFlow extends LitElement {
114
193
  event.stopPropagation();
115
194
  if (this.fromLeaving(event))
116
195
  return;
196
+ const terms = this.terms;
197
+ // Allow waits for the terms; a stray allow before the box is ticked is not consent.
198
+ if (terms && !this.termsAccepted)
199
+ return;
117
200
  const ticked = (this.data?.capabilities ?? []).filter((cap) => this.selected.has(cap.id));
118
201
  this.dispatchEvent(new CustomEvent("consent-flow-approve", this.init({
119
202
  capabilities: ticked.map((cap) => cap.id),
120
203
  scopes: [...new Set(ticked.flatMap((cap) => cap.scopes))],
121
204
  approvalMethod: this.flow.approvalMethod,
205
+ // Without terms the fields stay out: a server reads an explicit
206
+ // false as refused.
207
+ ...(terms ? { termsAccepted: true } : {}),
208
+ ...(terms?.version !== undefined
209
+ ? { termsVersion: terms.version }
210
+ : {}),
122
211
  })));
123
212
  };
213
+ /** The terms box: its tick is the person's, in a preview too. */
214
+ this.onChange = (event) => {
215
+ const target = event.target;
216
+ if (target?.dataset?.action !== "terms" || this.fromLeaving(event))
217
+ return;
218
+ this.termsAccepted = target.checked;
219
+ this.requestUpdate();
220
+ };
221
+ /** In a preview, a click names the region it landed in, for the editor's rail. */
222
+ this.onFieldClick = (event) => {
223
+ if (!this.preview || this.fromLeaving(event))
224
+ return;
225
+ const field = this.fieldAt(event);
226
+ if (!field)
227
+ return;
228
+ this.dispatchEvent(new CustomEvent("consent-flow-field", this.init({ field })));
229
+ };
230
+ /** Outlines the highlighted region, in a preview; fades the outline out otherwise. */
231
+ this.placeSpotlight = () => {
232
+ const spot = this.renderRoot.querySelector(".spotlight");
233
+ const flow = this.renderRoot.querySelector(".flow");
234
+ const card = this.card;
235
+ if (!spot || !flow || !card)
236
+ return;
237
+ const region = this.preview && this.highlight ? this.regionOf(this.highlight) : null;
238
+ if (!region) {
239
+ delete spot.dataset.shown;
240
+ return;
241
+ }
242
+ // Viewport pixels to the flow's own: a zoomed or scaled canvas draws it smaller.
243
+ const outer = flow.getBoundingClientRect();
244
+ const scale = flow.offsetWidth > 0 ? outer.width / flow.offsetWidth : 1;
245
+ const box = region.getBoundingClientRect();
246
+ // Room around the region, inside the card's inner edge when it is in the card.
247
+ const clip = within(card, region)
248
+ ? inset(card.getBoundingClientRect(), card.clientLeft * scale)
249
+ : outer;
250
+ const left = Math.max(box.left - SPOT_X * scale, clip.left);
251
+ const top = Math.max(box.top - SPOT_Y * scale, clip.top);
252
+ const right = Math.min(box.right + SPOT_X * scale, clip.right);
253
+ const bottom = Math.min(box.bottom + SPOT_Y * scale, clip.bottom);
254
+ const x = (left - outer.left) / scale;
255
+ const y = (top - outer.top) / scale;
256
+ const first = spot.dataset.shown === undefined;
257
+ // A first show lands in place and fades in; a move glides.
258
+ if (first)
259
+ spot.classList.add("placing");
260
+ spot.style.transform = `translate(${x}px, ${y}px)`;
261
+ spot.style.width = `${(right - left) / scale}px`;
262
+ spot.style.height = `${(bottom - top) / scale}px`;
263
+ spot.style.borderRadius = `${ringRadius(region)}px`;
264
+ spot.dataset.mode = this.highlightMode === "hover" ? "hover" : "select";
265
+ const ghost = Boolean(region.querySelector(":scope > .ghost"));
266
+ const label = [this.highlightLabel.trim(), ghost ? "Empty" : ""]
267
+ .filter(Boolean)
268
+ .join(" · ");
269
+ const tag = spot.querySelector(".spot-label");
270
+ if (tag) {
271
+ tag.textContent = label;
272
+ tag.hidden = !label;
273
+ // On the bottom edge when the top one has no room above it in the flow.
274
+ tag.dataset.below = String(y < LABEL_ROOM);
275
+ }
276
+ if (first) {
277
+ void spot.offsetWidth;
278
+ spot.classList.remove("placing");
279
+ }
280
+ spot.dataset.shown = "";
281
+ };
124
282
  this.onDeny = (event) => {
125
283
  event.stopPropagation();
126
284
  if (!this.fromLeaving(event))
@@ -150,7 +308,8 @@ let ConsentFlow = class ConsentFlow extends LitElement {
150
308
  };
151
309
  this.onClick = (event) => {
152
310
  const target = event.target?.closest?.("[data-action]");
153
- if (!target || this.fromLeaving(event))
311
+ // A preview acts on nothing the person presses, as the action bar's does.
312
+ if (!target || this.preview || this.fromLeaving(event))
154
313
  return;
155
314
  if (target.dataset.action === "sign-in") {
156
315
  this.dispatchEvent(new CustomEvent("consent-flow-sign-in", this.init({
@@ -168,6 +327,28 @@ let ConsentFlow = class ConsentFlow extends LitElement {
168
327
  get currentStep() {
169
328
  return this.resolved;
170
329
  }
330
+ /**
331
+ * Where a region is drawn now, in viewport coordinates: the box `highlight`
332
+ * outlines (Approve and Deny each their own button). Null when this step
333
+ * draws no such region. A box that is moving between steps reads where it
334
+ * is drawn this frame, so after a step change read it once `whenSettled()`
335
+ * resolves.
336
+ *
337
+ * @example
338
+ * flowEl.step = "granted";
339
+ * await flowEl.whenSettled();
340
+ * flowEl.fieldRect("headline"); // DOMRect
341
+ */
342
+ fieldRect(field) {
343
+ return isField(field)
344
+ ? (this.regionOf(field)?.getBoundingClientRect() ?? null)
345
+ : null;
346
+ }
347
+ /** Resolves once the last change is drawn and its motion has finished (at once when nothing moves). */
348
+ async whenSettled() {
349
+ await this.updateComplete;
350
+ await this.motionDone;
351
+ }
171
352
  connectedCallback() {
172
353
  super.connectedCallback();
173
354
  document.addEventListener("pointerdown", this.onDocumentPointer, true);
@@ -175,6 +356,8 @@ let ConsentFlow = class ConsentFlow extends LitElement {
175
356
  disconnectedCallback() {
176
357
  super.disconnectedCallback();
177
358
  document.removeEventListener("pointerdown", this.onDocumentPointer, true);
359
+ this.resizes?.disconnect();
360
+ this.resizes = null;
178
361
  }
179
362
  get card() {
180
363
  return this.renderRoot.querySelector(".card");
@@ -185,11 +368,18 @@ let ConsentFlow = class ConsentFlow extends LitElement {
185
368
  willUpdate(changed) {
186
369
  if (changed.has("data"))
187
370
  this.reselect(changed.get("data"));
371
+ if (changed.has("terms") && termsKey(this.terms) !== this.acceptedTerms) {
372
+ this.termsAccepted = false;
373
+ this.acceptedTerms = termsKey(this.terms);
374
+ }
188
375
  const steps = this.flow.steps;
189
376
  const wanted = this.step;
377
+ // Swapping flows mid-way keeps the person on the request; any other
378
+ // step this flow lacks starts it over.
379
+ const swapped = this.hasUpdated && changed.has("flow");
190
380
  const resolved = wanted && steps[wanted]
191
381
  ? wanted
192
- : wanted && steps.consent
382
+ : swapped && wanted && steps.consent
193
383
  ? "consent"
194
384
  : this.flow.initial;
195
385
  if (this.step !== resolved)
@@ -201,7 +391,7 @@ let ConsentFlow = class ConsentFlow extends LitElement {
201
391
  if (!this.hasUpdated ||
202
392
  !card ||
203
393
  !fx ||
204
- !DRAWN.some((key) => changed.has(key)))
394
+ !MOVES.some((key) => changed.has(key)))
205
395
  return;
206
396
  // Land the last transition, so every box is measured at rest.
207
397
  motion.settle(card);
@@ -247,6 +437,34 @@ let ConsentFlow = class ConsentFlow extends LitElement {
247
437
  const fx = this.fx;
248
438
  return Boolean(fx && event.composedPath().includes(fx));
249
439
  }
440
+ /** The innermost region on an event's path, through the package's own shadow roots. */
441
+ fieldAt(event) {
442
+ for (const node of event.composedPath()) {
443
+ if (node === this)
444
+ return null;
445
+ if (!(node instanceof HTMLElement))
446
+ continue;
447
+ const name = node.dataset.field ?? node.dataset.block;
448
+ if (isField(name))
449
+ return name;
450
+ }
451
+ return null;
452
+ }
453
+ /** The element a region is drawn by: the innermost one, inside the package's own parts too. */
454
+ regionOf(field) {
455
+ const selector = `[data-field="${field}"]`;
456
+ const root = this.renderRoot;
457
+ const own = root.querySelector(selector) ??
458
+ root.querySelector(`.card > [data-block="${field}"]`);
459
+ if (own)
460
+ return own;
461
+ for (const host of root.querySelectorAll("consent-action-bar, consent-connector-header")) {
462
+ const inner = host.shadowRoot?.querySelector(selector);
463
+ if (inner)
464
+ return inner;
465
+ }
466
+ return null;
467
+ }
250
468
  specs(data, step, copy) {
251
469
  const ctx = {
252
470
  data,
@@ -256,6 +474,8 @@ let ConsentFlow = class ConsentFlow extends LitElement {
256
474
  method: this.flow.approvalMethod,
257
475
  preview: this.preview,
258
476
  values: flowValues(data),
477
+ ...(this.terms ? { terms: this.terms } : {}),
478
+ termsAccepted: this.termsAccepted,
259
479
  };
260
480
  const seen = new Map();
261
481
  const specs = [];
@@ -264,7 +484,10 @@ let ConsentFlow = class ConsentFlow extends LitElement {
264
484
  const draw = FLOW_BLOCK_RENDERERS[name];
265
485
  if (!draw)
266
486
  continue;
267
- const result = draw(variant ? { ...ctx, variant } : ctx);
487
+ let result = draw(variant ? { ...ctx, variant } : ctx);
488
+ // In a preview, a highlighted block with no words yet shows where they will go.
489
+ if (result === nothing && this.preview && this.highlight === name)
490
+ result = html `<div class="ghost" part="ghost"></div>`;
268
491
  if (result === nothing)
269
492
  continue;
270
493
  const n = (seen.get(name) ?? 0) + 1;
@@ -285,12 +508,20 @@ let ConsentFlow = class ConsentFlow extends LitElement {
285
508
  this.signatures = new Map(specs.map((spec) => [spec.key, signatureOf(spec.result)]));
286
509
  const seal = fillTemplate(group(copy, "seal")[def.connector] ?? "", values);
287
510
  const announce = fillTemplate(group(copy, "announce")[step] ?? "", values);
511
+ const legal = this.legal.filter((link) => httpsUrl(link.href));
288
512
  return html `<style>
289
- ${themeScopeStyle(getConsentTheme(this.theme), ".card, consent-connector-header, .below")}
513
+ ${themeScopeStyle(getConsentTheme(this.theme), ".card", "consent-connector-header, .below")}
514
+ ${brandRule(this.brand, this.theme)}
290
515
  </style>
291
- <div class="flow" data-step=${step}>
516
+ <div
517
+ class="flow"
518
+ data-step=${step}
519
+ data-motion=${this.flow.motion}
520
+ @click=${this.onFieldClick}
521
+ >
292
522
  <consent-connector-header
293
523
  part="connector"
524
+ data-field="connector"
294
525
  variant="bridge"
295
526
  .clientName=${data.agent.name}
296
527
  .clientLogoUrl=${data.agent.logoUrl ?? ""}
@@ -310,6 +541,7 @@ let ConsentFlow = class ConsentFlow extends LitElement {
310
541
  class="card"
311
542
  part="card"
312
543
  @click=${this.onClick}
544
+ @change=${this.onChange}
313
545
  @consent-allow=${this.onAllow}
314
546
  @consent-deny=${this.onDeny}
315
547
  @consent-request-expired=${this.onExpired}
@@ -326,11 +558,31 @@ let ConsentFlow = class ConsentFlow extends LitElement {
326
558
  </div>
327
559
  <div class="below" part="below">
328
560
  <consent-secured-by></consent-secured-by>
561
+ ${legal.length > 0
562
+ ? html `<nav
563
+ class="legal"
564
+ part="legal"
565
+ data-field="legal"
566
+ aria-label=${group(copy, "legal").label ?? "Legal"}
567
+ >
568
+ ${legal.map((link) => html `<a
569
+ href=${link.href}
570
+ target="_blank"
571
+ rel="noopener noreferrer"
572
+ >${link.label}</a
573
+ >`)}
574
+ </nav>`
575
+ : nothing}
329
576
  </div>
330
577
  <p class="sr" role="status">${announce}</p>
578
+ <div class="spotlight" aria-hidden="true">
579
+ <span class="spot-label" hidden></span>
580
+ </div>
331
581
  </div>`;
332
582
  }
333
583
  updated(changed) {
584
+ this.watchLayout();
585
+ this.placeSpotlight();
334
586
  this.setAttribute(FLOW_HOST_ATTRIBUTES.version, String(this.flow.version));
335
587
  this.setAttribute(FLOW_HOST_ATTRIBUTES.approvalMethod, this.flow.approvalMethod);
336
588
  const step = this.resolved;
@@ -348,6 +600,17 @@ let ConsentFlow = class ConsentFlow extends LitElement {
348
600
  if (before)
349
601
  this.animateStep(before);
350
602
  }
603
+ /** Moves the outline with the card: a resize, a font loading, a step settling. */
604
+ watchLayout() {
605
+ if (this.resizes || typeof ResizeObserver === "undefined")
606
+ return;
607
+ const card = this.card;
608
+ if (!card)
609
+ return;
610
+ this.resizes = new ResizeObserver(this.placeSpotlight);
611
+ this.resizes.observe(card);
612
+ this.resizes.observe(this);
613
+ }
351
614
  /** The step's `focus` block takes focus: its own target (`tabindex="-1"`), else its first control. */
352
615
  focusStep(step) {
353
616
  const key = this.flow.steps[step]?.focus;
@@ -404,9 +667,11 @@ let ConsentFlow = class ConsentFlow extends LitElement {
404
667
  }
405
668
  // The card clips what moves only while it moves, so a tooltip can overhang it at rest.
406
669
  const generation = ++this.generation;
407
- void Promise.allSettled(started.map((animation) => animation.finished)).then(() => {
408
- if (generation === this.generation)
409
- card.classList.remove("moving");
670
+ this.motionDone = Promise.allSettled(started.map((animation) => animation.finished)).then(() => {
671
+ if (generation !== this.generation)
672
+ return;
673
+ card.classList.remove("moving");
674
+ this.placeSpotlight();
410
675
  });
411
676
  }
412
677
  };
@@ -417,12 +682,104 @@ ConsentFlow.styles = css `
417
682
  text-wrap: pretty;
418
683
  }
419
684
 
685
+ /* A preview shows the brand's page behind the card, which a live page
686
+ paints on its body; with none, the editor's own shows through. */
687
+ :host([preview]) {
688
+ background-color: var(--cs-surface-bg);
689
+ }
690
+
420
691
  .flow {
692
+ position: relative;
421
693
  box-sizing: border-box;
422
694
  max-width: var(--cs-screen-max-width, 576px);
423
695
  margin: 0 auto;
424
696
  }
425
697
 
698
+ /* The editor's focused field, outlined over the flow in a preview. */
699
+ /* The editor's highlight: a selection over the flow, in an editor
700
+ accent (not the brand, not ink). It never takes layout. */
701
+ .spotlight {
702
+ --_accent: var(--cs-edit-focus-ring, #6d5ae6);
703
+ position: absolute;
704
+ top: 0;
705
+ left: 0;
706
+ box-sizing: border-box;
707
+ border: 1.5px solid var(--_accent);
708
+ border-radius: 8px;
709
+ background: var(
710
+ --cs-edit-wash,
711
+ color-mix(in srgb, var(--_accent) 6%, transparent)
712
+ );
713
+ opacity: 0;
714
+ pointer-events: none;
715
+ z-index: 6;
716
+ transition:
717
+ opacity 120ms ease-out,
718
+ transform 180ms ease-out,
719
+ width 180ms ease-out,
720
+ height 180ms ease-out;
721
+ }
722
+
723
+ .spotlight[data-shown] {
724
+ opacity: 1;
725
+ }
726
+
727
+ .spotlight[data-mode="hover"] {
728
+ border: 1px dashed var(--cs-edit-hover-ring, var(--_accent));
729
+ background: none;
730
+ }
731
+
732
+ /* A first show lands in place; reduced motion and the none preset fade only. */
733
+ .spotlight.placing,
734
+ .flow[data-motion="none"] .spotlight {
735
+ transition: opacity 120ms ease-out;
736
+ }
737
+
738
+ @media (prefers-reduced-motion: reduce) {
739
+ .spotlight {
740
+ transition: opacity 120ms ease-out;
741
+ }
742
+ }
743
+
744
+ /* The field's name, on the ring's top edge like a legend, so it reaches
745
+ into the gap above rather than over the block before. */
746
+ .spot-label {
747
+ position: absolute;
748
+ top: 0;
749
+ left: 10px;
750
+ transform: translateY(-50%);
751
+ padding: 2px 6px;
752
+ border-radius: 4px;
753
+ background: var(--_accent);
754
+ /* Themable with the accent: text on it stays readable. */
755
+ color: var(--cs-edit-on-accent, #ffffff);
756
+ font:
757
+ 600 10px/14px system-ui,
758
+ -apple-system,
759
+ "Segoe UI",
760
+ sans-serif;
761
+ letter-spacing: 0.06em;
762
+ text-transform: uppercase;
763
+ white-space: nowrap;
764
+ }
765
+
766
+ .spot-label[data-below="true"] {
767
+ top: 100%;
768
+ }
769
+
770
+ .spot-label[hidden] {
771
+ display: none;
772
+ }
773
+
774
+ /* Where a highlighted field's words will go, before it has any. */
775
+ .ghost {
776
+ box-sizing: border-box;
777
+ height: 28px;
778
+ border: 1px dashed
779
+ color-mix(in srgb, var(--cs-edit-focus-ring, #6d5ae6) 55%, transparent);
780
+ border-radius: 6px;
781
+ }
782
+
426
783
  .card {
427
784
  position: relative;
428
785
  display: flex;
@@ -463,10 +820,25 @@ ConsentFlow.styles = css `
463
820
  display: flex;
464
821
  flex-direction: column;
465
822
  align-items: center;
823
+ gap: 10px;
466
824
  margin-top: 16px;
467
825
  color: var(--cs-text-tertiary);
468
826
  }
469
827
 
828
+ .legal {
829
+ display: flex;
830
+ flex-wrap: wrap;
831
+ justify-content: center;
832
+ gap: 4px 20px;
833
+ font-size: 12px;
834
+ }
835
+
836
+ .legal a {
837
+ color: inherit;
838
+ text-decoration: underline;
839
+ text-underline-offset: 2px;
840
+ }
841
+
470
842
  .sr {
471
843
  position: absolute;
472
844
  width: 1px;
@@ -494,6 +866,24 @@ __decorate([
494
866
  __decorate([
495
867
  property({ type: String })
496
868
  ], ConsentFlow.prototype, "theme", void 0);
869
+ __decorate([
870
+ property({ attribute: false })
871
+ ], ConsentFlow.prototype, "brand", void 0);
872
+ __decorate([
873
+ property({ attribute: false })
874
+ ], ConsentFlow.prototype, "legal", void 0);
875
+ __decorate([
876
+ property({ attribute: false })
877
+ ], ConsentFlow.prototype, "terms", void 0);
878
+ __decorate([
879
+ property({ type: String })
880
+ ], ConsentFlow.prototype, "highlight", void 0);
881
+ __decorate([
882
+ property({ type: String, attribute: "highlight-mode" })
883
+ ], ConsentFlow.prototype, "highlightMode", void 0);
884
+ __decorate([
885
+ property({ type: String, attribute: "highlight-label" })
886
+ ], ConsentFlow.prototype, "highlightLabel", void 0);
497
887
  __decorate([
498
888
  property({ type: Boolean, reflect: true })
499
889
  ], ConsentFlow.prototype, "preview", void 0);