@bigmistqke/whiteboard 0.6.0 → 0.7.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.
Files changed (61) hide show
  1. package/README.md +13 -7
  2. package/dist/bin/whiteboard.js +0 -0
  3. package/dist/client/runtime.js +235 -58
  4. package/dist/plugins/badge/README.md +3 -1
  5. package/dist/plugins/badge/public/style.css +17 -0
  6. package/dist/plugins/chat/public/client.js +2 -2
  7. package/dist/plugins/chat/public/style.css +9 -0
  8. package/dist/plugins/comments/public/client.js +7 -2
  9. package/dist/plugins/comments/public/style.css +4 -0
  10. package/dist/plugins/grid/public/style.css +0 -5
  11. package/dist/plugins/index.js +5 -1
  12. package/dist/plugins/timeline/README.md +40 -0
  13. package/dist/plugins/timeline/index.js +82 -0
  14. package/dist/plugins/timeline/public/style.css +118 -0
  15. package/dist/plugins/toc/README.md +13 -13
  16. package/dist/plugins/toc/index.js +5 -3
  17. package/dist/plugins/toc/public/client.js +1 -1
  18. package/dist/plugins/toc/public/style.css +19 -2
  19. package/dist/solid/index.js +2 -1
  20. package/dist/src/auth.js +7 -3
  21. package/dist/src/client/page/base.css +74 -35
  22. package/dist/src/client/page/main.js +15 -4
  23. package/dist/src/entries.js +9 -3
  24. package/dist/src/events.js +4 -2
  25. package/dist/src/hub.js +43 -18
  26. package/dist/src/serve.js +2 -0
  27. package/dist/src/server.js +49 -11
  28. package/dist/src/ws.js +128 -0
  29. package/package.json +1 -1
  30. package/plugins/badge/README.md +3 -1
  31. package/plugins/badge/public/style.css +17 -0
  32. package/plugins/chat/client.tsx +34 -6
  33. package/plugins/chat/public/style.css +9 -0
  34. package/plugins/comments/client.ts +48 -5
  35. package/plugins/comments/public/style.css +4 -0
  36. package/plugins/grid/public/style.css +0 -5
  37. package/plugins/index.ts +6 -1
  38. package/plugins/timeline/README.md +40 -0
  39. package/plugins/timeline/index.ts +92 -0
  40. package/plugins/timeline/public/style.css +118 -0
  41. package/plugins/toc/README.md +13 -13
  42. package/plugins/toc/client.ts +49 -30
  43. package/plugins/toc/index.ts +12 -12
  44. package/plugins/toc/public/style.css +19 -2
  45. package/skills/whiteboard/SKILL.md +1 -2
  46. package/solid/index.tsx +3 -0
  47. package/src/auth.ts +7 -2
  48. package/src/client/forms.ts +102 -5
  49. package/src/client/page/base.css +74 -35
  50. package/src/client/page/elsewhere.ts +12 -3
  51. package/src/client/page/waiting.ts +10 -5
  52. package/src/client/read.ts +16 -3
  53. package/src/client/runtime.ts +134 -45
  54. package/src/client/toast.ts +35 -5
  55. package/src/define.ts +10 -0
  56. package/src/entries.ts +14 -3
  57. package/src/events.ts +7 -1
  58. package/src/hub.ts +54 -22
  59. package/src/serve.ts +2 -0
  60. package/src/server.ts +73 -17
  61. package/src/ws.ts +155 -0
package/README.md CHANGED
@@ -211,7 +211,13 @@ A form with a `name` and no `action` attribute is recorded when submitted:
211
211
  events of other types too, through `api.append(type, data)`. Those types
212
212
  are named after their plugin, `<plugin>:<what>` (`chat:message`,
213
213
  `comments:reply`, whiteboard's own `whiteboard:picked`), so a form's name
214
- can't contain a colon and its answers never mix with them. The built-in
214
+ can't contain a colon and its answers never mix with them. Appending is
215
+ optimistic: the event is in `api.events()` at once, with `sending: true`
216
+ until the server has it, so show it then as on its way, not as done: in
217
+ `--wb-sending` (grey), as the core does for a form's button and the chat
218
+ for a message. A send that heard nothing back is tried again, without being
219
+ appended twice; only when none gets through does the event leave the
220
+ events again and the promise `api.append` returned reject. The built-in
215
221
  `form` plugin writes forms as markdown with inputs inline
216
222
  (`:::form{name=ship}` … `:radio[this week]{name=when}` … `:::`); a
217
223
  hand-written `<form name="…">` works without it.
@@ -424,12 +430,12 @@ Every colour is a `light-dark()` pair, so one line sets it for both themes:
424
430
  ```
425
431
 
426
432
  The built-in plugins are ansi, badge, callout, chat, code, comments, details, draft,
427
- forge, form, grid, iframe, lightbox, mermaid, quiet, steps and window: every project has them, and
428
- `whiteboard docs` shows how to write each. A config's `plugins` add to them,
429
- and one with a built-in's name replaces it. The terminal and the Claude Code
430
- plugin are opt-in, since they run code or are about one agent, and so is the
431
- table of contents (`toc`), which a page then asks for in its frontmatter
432
- (`plugins: { toc: true }`).
433
+ forge, form, grid, iframe, lightbox, mermaid, quiet, steps, timeline, toc and window: every
434
+ project has them, and `whiteboard docs` shows how to write each. A config's `plugins` add to
435
+ them, and one with a built-in's name replaces it. The table of contents (`toc`) shows on a page
436
+ that asks for it in its frontmatter (`plugins: { toc: true }`), or on every page with
437
+ `toc({ always: true })` in the config. The terminal and the Claude Code plugin are opt-in, since
438
+ they run code or are about one agent.
433
439
 
434
440
  Named forms need nothing in the config: the core sends a submit of any
435
441
  `<form name>` as an event, on any page.
File without changes
@@ -201,26 +201,96 @@ function restoreLast(prefill) {
201
201
  if (prefill && !keepsOwnFields(form)) writeForm(form, last.data);
202
202
  }
203
203
  }
204
+ /** What each form is sending now, as sent: the same answer again is not sent twice. */
205
+ const inFlight = /* @__PURE__ */ new WeakMap();
206
+ /** A button's own label, while it says how a send goes. */
207
+ const labelOf = (button) => {
208
+ const el = document.createElement("div");
209
+ el.innerHTML = labels.get(button).html;
210
+ return el.textContent?.trim() ?? "";
211
+ };
212
+ const SEND_TEXT = {
213
+ sending: "Sending…",
214
+ sent: "✓ Sent",
215
+ failed: "Try again"
216
+ };
217
+ const labels = /* @__PURE__ */ new WeakMap();
218
+ function sendState(button, state) {
219
+ if (!button) return;
220
+ let saved = labels.get(button);
221
+ clearTimeout(saved?.timer);
222
+ if (!state) {
223
+ if (!saved) return;
224
+ button.innerHTML = saved.html;
225
+ button.style.minWidth = "";
226
+ delete button.dataset.wbSend;
227
+ labels.delete(button);
228
+ return;
229
+ }
230
+ if (!saved) {
231
+ saved = { html: button.innerHTML };
232
+ labels.set(button, saved);
233
+ button.style.minWidth = `${button.getBoundingClientRect().width}px`;
234
+ }
235
+ button.dataset.wbSend = state;
236
+ button.textContent = SEND_TEXT[state];
237
+ if (state === "sent") saved.timer = setTimeout(() => sendState(button, null), 2e3);
238
+ }
204
239
  async function onSubmit(e) {
205
240
  const form = e.target;
206
241
  if (!managed(form) || !root$1.contains(form)) return;
207
242
  e.preventDefault();
208
243
  const button = e.submitter;
209
- const action = button ? button.value || button.textContent?.trim() || null : null;
244
+ const label = button ? labels.get(button) ? labelOf(button) : button.textContent?.trim() : null;
245
+ const action = button ? button.value || label || null : null;
246
+ const data = readForm(form);
247
+ const sent = JSON.stringify([action, data]);
248
+ if (inFlight.get(form) === sent) return;
249
+ inFlight.set(form, sent);
250
+ const before = form.dataset.wbSent;
210
251
  form.dataset.wbState = "sending";
252
+ form.dataset.wbSent = action ?? "";
253
+ form.removeAttribute("data-wb-just-sent");
254
+ sendState(button, "sending");
255
+ showStatus(form);
211
256
  try {
212
- await api$1.append(form.getAttribute("name"), readForm(form), action);
257
+ await api$1.append(form.getAttribute("name"), data, action);
258
+ if (inFlight.get(form) !== sent) return;
213
259
  dropDraft(form);
214
260
  form.dataset.wbState = "sent";
215
- form.dataset.wbSent = action ?? "";
261
+ sendState(button, "sent");
216
262
  form.toggleAttribute("data-wb-just-sent", true);
217
263
  clearTimeout(justSent.get(form));
218
- justSent.set(form, setTimeout(() => form.removeAttribute("data-wb-just-sent"), 3e3));
264
+ justSent.set(form, setTimeout(() => {
265
+ form.removeAttribute("data-wb-just-sent");
266
+ showStatus(form);
267
+ }, 3e3));
268
+ showStatus(form);
219
269
  } catch (err) {
270
+ if (inFlight.get(form) !== sent) return;
220
271
  form.dataset.wbState = "failed";
272
+ sendState(button, "failed");
273
+ if (before == null) delete form.dataset.wbSent;
274
+ else form.dataset.wbSent = before;
275
+ showStatus(form);
221
276
  console.error(err);
277
+ } finally {
278
+ if (inFlight.get(form) === sent) inFlight.delete(form);
222
279
  }
223
280
  }
281
+ const sendButtons = (form) => [...form.querySelectorAll("button, input[type=submit]")].filter((b) => (b instanceof HTMLInputElement || b.type !== "button" && b.type !== "reset") && b.form === form);
282
+ function showStatus(form) {
283
+ const text = form.dataset.wbState === "failed" ? ["couldn't send it", "bad"] : form.dataset.wbState === "sending" || !form.hasAttribute("data-wb-pending") ? null : ["waiting for the agent to pick it up", null];
284
+ let el = form.querySelector(".wb-form-status");
285
+ const last = sendButtons(form).at(-1);
286
+ if (!text || !last) return void el?.remove();
287
+ if (!el) el = Object.assign(document.createElement("span"), { className: "wb-form-status" });
288
+ el.setAttribute("role", "status");
289
+ if (el.previousElementSibling !== last) last.after(el);
290
+ el.textContent = text[0];
291
+ if (text[1]) el.dataset.kind = text[1];
292
+ else delete el.dataset.kind;
293
+ }
224
294
  const ATTR = {
225
295
  open: "data-wb-open",
226
296
  pending: "data-wb-pending",
@@ -263,6 +333,7 @@ function mark() {
263
333
  for (const st of STATES) form.toggleAttribute(ATTR[st], st === state);
264
334
  if (state === "decided") form.dataset.wbOutcome = outcome(last.data, last.action);
265
335
  else delete form.dataset.wbOutcome;
336
+ showStatus(form);
266
337
  return {
267
338
  form,
268
339
  name,
@@ -312,8 +383,13 @@ function place(corner) {
312
383
  return box;
313
384
  }
314
385
  function createToast(corner) {
315
- return function toast(text, { kind = "info", ms = 7e3, onClick, onDismiss, name, order = 0 } = {}) {
386
+ return function toast(text, { kind = "info", ms = 7e3, onClick, onDismiss, name, order = 0, details } = {}) {
316
387
  const el = document.createElement("button");
388
+ let timer;
389
+ const close = () => {
390
+ clearTimeout(timer);
391
+ el.remove();
392
+ };
317
393
  el.type = "button";
318
394
  el.className = "wb-toast";
319
395
  el.dataset.kind = kind;
@@ -323,6 +399,26 @@ function createToast(corner) {
323
399
  label.className = "wb-toast-text";
324
400
  label.textContent = text;
325
401
  el.append(label);
402
+ let more = null;
403
+ let detail = null;
404
+ if (details) {
405
+ more = document.createElement("span");
406
+ more.className = "wb-toast-more";
407
+ detail = document.createElement("span");
408
+ detail.className = "wb-toast-details";
409
+ detail.textContent = details;
410
+ el.setAttribute("aria-description", details);
411
+ el.append(more, detail);
412
+ fold(false);
413
+ }
414
+ function fold(open) {
415
+ el.toggleAttribute("data-open", open);
416
+ detail.hidden = !open;
417
+ more.textContent = open ? "▾" : "▸";
418
+ more.title = open ? "Less" : "More";
419
+ clearTimeout(timer);
420
+ if (!open && ms) timer = setTimeout(close, ms);
421
+ }
326
422
  if (onDismiss) {
327
423
  const x = document.createElement("span");
328
424
  x.className = "wb-toast-dismiss";
@@ -330,17 +426,18 @@ function createToast(corner) {
330
426
  x.title = x.ariaLabel = "Dismiss";
331
427
  el.append(x);
332
428
  }
333
- const close = () => el.remove();
334
429
  el.addEventListener("click", (e) => {
335
- if (onDismiss && e.target.closest(".wb-toast-dismiss")) {
430
+ const target = e.target;
431
+ if (onDismiss && target.closest(".wb-toast-dismiss")) {
336
432
  close();
337
433
  onDismiss();
338
434
  return;
339
435
  }
436
+ if (details && target.closest(".wb-toast-more, .wb-toast-details")) return fold(!el.hasAttribute("data-open"));
340
437
  if (ms) close();
341
438
  onClick?.();
342
439
  });
343
- if (ms) setTimeout(close, ms);
440
+ if (ms && !details) timer = setTimeout(close, ms);
344
441
  place(corner()).append(el);
345
442
  return {
346
443
  close,
@@ -361,8 +458,8 @@ function createToast(corner) {
361
458
  let isMessage = () => false;
362
459
  let getEvents = () => [];
363
460
  let send = () => {};
364
- const sending = /* @__PURE__ */ new Set();
365
- const unread$1 = () => unreadMessages(getEvents(), isMessage).filter((e) => !sending.has(e.id));
461
+ const sending$1 = /* @__PURE__ */ new Set();
462
+ const unread$1 = () => unreadMessages(getEvents(), isMessage).filter((e) => !sending$1.has(e.id));
366
463
  const queued = /* @__PURE__ */ new Set();
367
464
  let timer = 0;
368
465
  function markRead(ids) {
@@ -370,7 +467,7 @@ function markRead(ids) {
370
467
  const fresh = ids.filter((id) => open.has(id));
371
468
  if (!fresh.length) return;
372
469
  for (const id of fresh) {
373
- sending.add(id);
470
+ sending$1.add(id);
374
471
  queued.add(id);
375
472
  }
376
473
  clearTimeout(timer);
@@ -382,17 +479,24 @@ function markRead(ids) {
382
479
  }
383
480
  /** Once the log has the reads, they need no holding. */
384
481
  function readsArrived(events) {
385
- for (const e of events) if (e.type === "whiteboard:read") for (const id of e.data?.ids ?? []) sending.delete(String(id));
482
+ for (const e of events) if (e.type === "whiteboard:read") for (const id of e.data?.ids ?? []) sending$1.delete(String(id));
483
+ }
484
+ const MOSTLY = .6;
485
+ function mostlyInView(entry) {
486
+ if (!entry.isIntersecting) return false;
487
+ if (entry.intersectionRatio >= MOSTLY) return true;
488
+ const viewport = entry.rootBounds?.height ?? window.innerHeight;
489
+ return entry.intersectionRect.height >= MOSTLY * viewport;
386
490
  }
387
491
  const inView = /* @__PURE__ */ new Set();
388
492
  const seen = new IntersectionObserver((entries) => {
389
493
  for (const entry of entries) {
390
494
  const id = entry.target.dataset.wbMessage;
391
- if (entry.isIntersecting) inView.add(id);
495
+ if (mostlyInView(entry)) inView.add(id);
392
496
  else inView.delete(id);
393
497
  }
394
498
  readVisible();
395
- }, { threshold: .6 });
499
+ }, { threshold: Array.from({ length: 21 }, (_, i) => i / 20) });
396
500
  function readVisible() {
397
501
  if (document.visibilityState === "visible" && inView.size) markRead([...inView]);
398
502
  }
@@ -512,25 +616,69 @@ function setEvents(next) {
512
616
  }
513
617
  async function loadEvents() {
514
618
  if (!live) return;
515
- setEvents((await (await fetch(url(`/api/events?page=${encodeURIComponent(page)}`))).json()).filter((e) => e.page === page));
516
- }
619
+ const all = (await (await fetch(url(`/api/events?page=${encodeURIComponent(page)}`))).json()).filter((e) => e.page === page);
620
+ const known = new Set(all.map((e) => e.id));
621
+ for (const [id, e] of sending) if (known.has(id)) sending.delete(id);
622
+ setEvents([...all, ...[...sending.values()]]);
623
+ }
624
+ /** How long one send may take before it is tried again, in ms; and how many tries in all. */
625
+ const SEND_TIMEOUT = 8e3;
626
+ const TRIES = 4;
627
+ /** Events appended here that the server hasn't confirmed: kept in the events when they are loaded. */
628
+ const sending = /* @__PURE__ */ new Map();
629
+ /** An id as the server makes them (isEventId): the time in base 36, a dash, random hex. */
630
+ const newId = () => `${Date.now().toString(36)}-${[...crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(6))].map((b) => b.toString(16).padStart(2, "0")).join("")}`;
517
631
  async function append(type, data = {}, action = null) {
518
632
  if (!live) throw new Error("a built page is a file: there is no log to append to");
519
- const res = await fetch(url("/api/events"), {
520
- method: "POST",
521
- headers: { "content-type": "application/json" },
522
- body: JSON.stringify({
523
- page,
524
- type,
525
- action,
526
- data
527
- })
633
+ const id = newId();
634
+ const shown = {
635
+ id,
636
+ ts: (/* @__PURE__ */ new Date()).toISOString(),
637
+ page,
638
+ type,
639
+ action,
640
+ data,
641
+ sending: true
642
+ };
643
+ sending.set(id, shown);
644
+ setEvents([...events, shown]);
645
+ const body = JSON.stringify({
646
+ id,
647
+ page,
648
+ type,
649
+ action,
650
+ data
528
651
  });
529
- if (!res.ok) throw new Error(await res.text());
530
- const saved = await res.json();
531
- if (!events.some((e) => e.id === saved.id)) setEvents([...events, saved]);
532
- return saved;
652
+ let failure;
653
+ for (let attempt = 0; attempt < TRIES; attempt++) {
654
+ if (attempt) await new Promise((r) => setTimeout(r, 500 * 2 ** attempt));
655
+ try {
656
+ const res = await fetch(url("/api/events"), {
657
+ method: "POST",
658
+ headers: { "content-type": "application/json" },
659
+ body,
660
+ signal: AbortSignal.timeout(SEND_TIMEOUT)
661
+ });
662
+ if (res.status >= 400 && res.status < 500) {
663
+ failure = new Error(await res.text());
664
+ break;
665
+ }
666
+ if (!res.ok) throw new Error(await res.text());
667
+ const saved = await res.json();
668
+ sending.delete(id);
669
+ setEvents([...events.filter((e) => e.id !== id && e.id !== saved.id), saved].toSorted(byTime));
670
+ return saved;
671
+ } catch (err) {
672
+ failure = err;
673
+ }
674
+ }
675
+ const arrived = !sending.has(id) && events.find((e) => e.id === id && !e.sending);
676
+ if (arrived) return arrived;
677
+ sending.delete(id);
678
+ setEvents(events.filter((e) => e.id !== id));
679
+ throw failure;
533
680
  }
681
+ const byTime = (a, b) => a.ts < b.ts ? -1 : a.ts > b.ts ? 1 : 0;
534
682
  let listeners = [];
535
683
  const listenersValue = reactive(() => listeners);
536
684
  async function loadListeners() {
@@ -636,44 +784,73 @@ if (!handoff.client) handle.onChange(async () => {
636
784
  root.innerHTML = (await handle.render()).html;
637
785
  api.rendered();
638
786
  });
639
- function connect() {
640
- const es = new EventSource(url(`/api/watch?page=${encodeURIComponent(page)}${isDir ? "&dir" : ""}`));
641
- es.onopen = () => {
642
- document.documentElement.dataset.wbLive = "";
643
- loadListeners();
644
- loadEvents();
645
- caughtUp();
646
- };
647
- es.onerror = () => {
648
- delete document.documentElement.dataset.wbLive;
649
- };
650
- es.addEventListener("change", () => {
787
+ const reloadWhenUp = async () => {
788
+ try {
789
+ if ((await fetch(url("/api/health"), { cache: "no-store" })).ok) return location.reload();
790
+ } catch {}
791
+ setTimeout(reloadWhenUp, 500);
792
+ };
793
+ /** What the server says on the live channel, by its name. */
794
+ const onLive = {
795
+ change: () => {
651
796
  for (const fn of changeListeners) fn();
652
- });
653
- es.addEventListener("events", () => loadEvents());
654
- es.addEventListener("listeners", () => loadListeners());
655
- es.addEventListener("reload", () => {
656
- const go = async () => {
657
- try {
658
- if ((await fetch(url("/api/health"), { cache: "no-store" })).ok) return location.reload();
659
- } catch {}
660
- setTimeout(go, 500);
661
- };
662
- go();
663
- });
664
- es.addEventListener("scroll", (e) => {
665
- const { to } = JSON.parse(e.data);
797
+ },
798
+ events: () => loadEvents(),
799
+ listeners: () => loadListeners(),
800
+ elsewhere: () => document.dispatchEvent(new Event("wb-elsewhere")),
801
+ reload: () => reloadWhenUp(),
802
+ scroll: (data) => {
803
+ const { to } = data;
666
804
  if (!scrollToTarget(root, to)) console.warn(`whiteboard scroll: nothing on the page matches ${JSON.stringify(to)}`);
667
- });
668
- es.addEventListener("style", () => {
805
+ },
806
+ style: () => {
669
807
  for (const link of document.querySelectorAll("link[rel=stylesheet]")) {
670
808
  const url = new URL(link.href);
671
809
  if (url.origin !== location.origin) continue;
672
810
  url.searchParams.set("t", String(Date.now()));
673
811
  link.href = url.pathname + url.search;
674
812
  }
675
- });
813
+ }
814
+ };
815
+ let socket = null;
816
+ let retries = 0;
817
+ let retryTimer;
818
+ function connect() {
819
+ clearTimeout(retryTimer);
820
+ if (socket && socket.readyState <= WebSocket.OPEN) return;
821
+ const at = new URL(url(`/api/live?page=${encodeURIComponent(page)}${isDir ? "&dir" : ""}`), location.href);
822
+ at.protocol = location.protocol === "https:" ? "wss:" : "ws:";
823
+ const ws = socket = new WebSocket(at);
824
+ ws.onopen = () => {
825
+ retries = 0;
826
+ document.documentElement.dataset.wbLive = "";
827
+ loadListeners();
828
+ loadEvents();
829
+ document.dispatchEvent(new Event("wb-elsewhere"));
830
+ caughtUp();
831
+ };
832
+ ws.onmessage = (e) => {
833
+ let message;
834
+ try {
835
+ message = JSON.parse(String(e.data));
836
+ } catch {
837
+ return;
838
+ }
839
+ if (message.event) onLive[message.event]?.(message.data);
840
+ };
841
+ ws.onclose = () => {
842
+ if (socket !== ws) return;
843
+ socket = null;
844
+ delete document.documentElement.dataset.wbLive;
845
+ retryTimer = setTimeout(connect, Math.min(250 * 2 ** retries++, 5e3));
846
+ };
676
847
  }
848
+ document.addEventListener("visibilitychange", () => {
849
+ if (document.visibilityState === "visible" && !socket) connect();
850
+ });
851
+ addEventListener("online", () => {
852
+ if (!socket) connect();
853
+ });
677
854
  await Promise.all([loadEvents(), loadListeners()]);
678
855
  if (handoff.client) try {
679
856
  const mount = (await import(moduleUrl(handoff.client))).default;
@@ -15,7 +15,9 @@ green, `active new info` blue, `open todo maybe warning` amber,
15
15
  The release is :badge[blocked] on review.
16
16
  ```
17
17
 
18
- A grid card whose heading ends in a badge shows it at the card's right edge.
18
+ A badge that ends a heading sits at its right edge: a page's heading, a grid
19
+ card's, a timeline step's. A block of your own can have the same for a title
20
+ that isn't a heading, with a `data-wb-title` attribute on it.
19
21
 
20
22
  ### Parser :badge[done]
21
23
 
@@ -28,3 +28,20 @@
28
28
  .wb-badge:is([data-badge='blocked'], [data-badge='no'], [data-badge='bad'], [data-badge='error']) {
29
29
  --c: var(--bad);
30
30
  }
31
+
32
+ /* a badge that ends a title sits at its right edge, centred on its first line: in any heading,
33
+ and in anything a block marks as a title (data-wb-title: a timeline's step). --wb-title-line is
34
+ the title's line height in px (registered, so 1lh resolves on the title, not on the badge) */
35
+ @property --wb-title-line {
36
+ syntax: '<length>';
37
+ inherits: true;
38
+ initial-value: 0px;
39
+ }
40
+ :is(h1, h2, h3, h4, h5, h6, [data-wb-title]):has(> .wb-badge:last-child) {
41
+ --wb-title-line: 1lh;
42
+ }
43
+ :is(h1, h2, h3, h4, h5, h6, [data-wb-title]) > .wb-badge:last-child {
44
+ float: right;
45
+ margin: calc(var(--wb-title-line) / 2 - 0.5em) 0 0 var(--space-lg);
46
+ vertical-align: baseline;
47
+ }