@aparte/core 1.1.2 → 1.3.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 (38) hide show
  1. package/README.md +3 -2
  2. package/dist/client/aparte-client.d.ts.map +1 -1
  3. package/dist/client/wire-history.d.ts +3 -1
  4. package/dist/client/wire-history.d.ts.map +1 -1
  5. package/dist/components/launcher/aparte-launcher.d.ts +151 -13
  6. package/dist/components/launcher/aparte-launcher.d.ts.map +1 -1
  7. package/dist/components/split/aparte-split.d.ts +26 -0
  8. package/dist/components/split/aparte-split.d.ts.map +1 -1
  9. package/dist/config/aparte-config.d.ts +6 -1
  10. package/dist/config/aparte-config.d.ts.map +1 -1
  11. package/dist/config/icon-provider.d.ts +4 -0
  12. package/dist/config/icon-provider.d.ts.map +1 -1
  13. package/dist/config/locale.d.ts +15 -1
  14. package/dist/config/locale.d.ts.map +1 -1
  15. package/dist/config/sanitize.d.ts +1 -1
  16. package/dist/context/measure.d.ts.map +1 -1
  17. package/dist/custom-elements.json +543 -13
  18. package/dist/{defer-hydration-BBdqAZej.js → defer-hydration-lK-7XQXf.js} +43 -10
  19. package/dist/defer-hydration-lK-7XQXf.js.map +1 -0
  20. package/dist/generated/element-attributes.d.ts +12 -0
  21. package/dist/generated/element-attributes.d.ts.map +1 -1
  22. package/dist/{glyphs-DFp-825O.js → glyphs-LolG04CC.js} +20 -14
  23. package/dist/glyphs-LolG04CC.js.map +1 -0
  24. package/dist/icons/glyphs.d.ts +6 -0
  25. package/dist/icons/glyphs.d.ts.map +1 -1
  26. package/dist/icons.js +17 -15
  27. package/dist/index.css +1 -1
  28. package/dist/index.js +372 -33
  29. package/dist/index.js.map +1 -1
  30. package/dist/index.node.js +1 -1
  31. package/dist/interop/default-on-attributes.d.ts +17 -0
  32. package/dist/interop/default-on-attributes.d.ts.map +1 -0
  33. package/dist/interop/element-props.d.ts.map +1 -1
  34. package/dist/types/segments.d.ts +12 -0
  35. package/dist/types/segments.d.ts.map +1 -1
  36. package/package.json +2 -2
  37. package/dist/defer-hydration-BBdqAZej.js.map +0 -1
  38. package/dist/glyphs-DFp-825O.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { K as deferHydrationOf, ae as resolveConfig, ap as eventOrigin, aq as activeElementIn, ak as subscribeConfigChange, ag as runWithConfig, o as AparteElicitationAbortError, w as buildApprovalPanel, x as buildElicitationPanel, ar as gateGlide, O as escapeAttr, H as cssEscape, ai as segmentTiming, as as chatBoundaryOf, at as relabelCodeLanguages, au as relabelCitations, av as toolCallRenderer, aw as toolRendererThatDrew, t as aparteGlobalConfig, ax as isMountedRenderer, ay as renderingVersionOf, az as onRenderersChange, aA as renderSourceList, aB as mergeSegmentUpdate, a0 as isSegmentSettled, aC as formatDuration, P as escapeHtml, aD as writeStreamedMarkdown, aE as replaceHighlighted, $ as isSafeUrl, C as copyText, V as getSegmentRenderer, X as installDefaultRenderersOnce, r as AparteMessageRepository, aF as CheckpointStateWatcher, aG as chatIdOf, aH as stampSegmentActivity, aI as stampSegmentOnInsert, aJ as stampSegmentOnUpdate, aK as renumberSegments, aL as openSegmentIds, aM as isTerminalStatus, aN as adoptMessageSegments, Z as isAwaitingReply, a6 as populateBubbleFromMessage, ao as uuid, af as revokeAttachmentUrls, a4 as parseMarkdownToSegments, aO as APARTE_DERIVED_SEGMENTS, aP as rememberConversationStatus, aQ as tellConversationStatus, aR as conversationStatusOf, e as APARTE_DEFAULT_LOCALE, a5 as placeFloating, aS as visibleReply, aT as usageTokens, q as AparteErrorCode, a1 as measureContext, aU as rootOf, aV as inRenderedContent, g as APARTE_HOST_ATTR, Y as installDialogTriggersOnce } from "./defer-hydration-BBdqAZej.js";
2
- import { A, a, b, c, d, f, h, i, j, k, l, m, n, p, s, S, u, v, y, z, B, D, E, F, G, I, J, L, M, N, Q, R, T, U, W, _, a2, a3, a7, a8, a9, aa, ab, ac, ad, ah, aj, al, am, an } from "./defer-hydration-BBdqAZej.js";
1
+ import { K as deferHydrationOf, ae as resolveConfig, ap as eventOrigin, aq as activeElementIn, ak as subscribeConfigChange, ag as runWithConfig, o as AparteElicitationAbortError, w as buildApprovalPanel, x as buildElicitationPanel, ar as gateGlide, O as escapeAttr, H as cssEscape, ai as segmentTiming, as as chatBoundaryOf, at as relabelCodeLanguages, au as relabelCitations, av as toolCallRenderer, aw as toolRendererThatDrew, t as aparteGlobalConfig, ax as isMountedRenderer, ay as renderingVersionOf, az as onRenderersChange, aA as renderSourceList, aB as mergeSegmentUpdate, a0 as isSegmentSettled, aC as formatDuration, P as escapeHtml, aD as writeStreamedMarkdown, aE as replaceHighlighted, $ as isSafeUrl, C as copyText, V as getSegmentRenderer, X as installDefaultRenderersOnce, r as AparteMessageRepository, aF as CheckpointStateWatcher, aG as chatIdOf, aH as stampSegmentActivity, aI as stampSegmentOnInsert, aJ as stampSegmentOnUpdate, aK as renumberSegments, aL as openSegmentIds, aM as isTerminalStatus, aN as adoptMessageSegments, Z as isAwaitingReply, a6 as populateBubbleFromMessage, ao as uuid, af as revokeAttachmentUrls, a4 as parseMarkdownToSegments, aO as APARTE_DERIVED_SEGMENTS, aP as rememberConversationStatus, aQ as tellConversationStatus, aR as conversationStatusOf, e as APARTE_DEFAULT_LOCALE, a5 as placeFloating, aS as visibleReply, aT as usageTokens, q as AparteErrorCode, a1 as measureContext, aU as rootOf, aV as inRenderedContent, g as APARTE_HOST_ATTR, Y as installDialogTriggersOnce } from "./defer-hydration-lK-7XQXf.js";
2
+ import { A, a, b, c, d, f, h, i, j, k, l, m, n, p, s, S, u, v, y, z, B, D, E, F, G, I, J, L, M, N, Q, R, T, U, W, _, a2, a3, a7, a8, a9, aa, ab, ac, ad, ah, aj, al, am, an } from "./defer-hydration-lK-7XQXf.js";
3
3
  function presenceOn(value) {
4
4
  return value === "" ? true : Boolean(value);
5
5
  }
@@ -9903,6 +9903,7 @@ class AparteSplit extends HTMLElement {
9903
9903
  this._measureRafId = null;
9904
9904
  }
9905
9905
  this._removeScrim();
9906
+ this._endMove?.();
9906
9907
  this._handle?.removeAttribute("data-dragging");
9907
9908
  this._dragging = false;
9908
9909
  this._keying = false;
@@ -9954,6 +9955,7 @@ class AparteSplit extends HTMLElement {
9954
9955
  if (this.single && this._dragging) this._endDrag("pointer", this._dragStartPercent);
9955
9956
  this._stampHandle();
9956
9957
  this._syncPaneControls();
9958
+ this._moveBetweenOneAndTwo();
9957
9959
  return;
9958
9960
  case "breakpoint":
9959
9961
  this._watchBreakpoint();
@@ -9962,6 +9964,85 @@ class AparteSplit extends HTMLElement {
9962
9964
  this._relabel();
9963
9965
  }
9964
9966
  }
9967
+ // ─── One pane ↔ two, in motion ────────────────────────────────────────
9968
+ /**
9969
+ * No layout worth reading: one pane is shown, or the tracks are in motion between one
9970
+ * and two. Whatever measures the panes or moves the seam asks this, not `stacked`
9971
+ * alone: a `pane` named while the split moves commits a position, and read from tracks
9972
+ * that are halfway it wrote the full width into `position`, so the split came back at
9973
+ * its maximum instead of the size it had.
9974
+ */
9975
+ get _unmeasurable() {
9976
+ return this.stacked || this.hasAttribute("data-moving");
9977
+ }
9978
+ /** Ends the move in flight: the inline tracks and the marker go, the sheet's state stays. */
9979
+ _endMove = null;
9980
+ /**
9981
+ * `single` just changed: move between one pane and two instead of jumping.
9982
+ *
9983
+ * The sheet's one-pane state takes the other pane out with `display: none`, which
9984
+ * cannot be animated. So for the length of the move the element keeps its three tracks
9985
+ * (`data-moving` holds the one-pane rules off) and drives them itself, in pixels it
9986
+ * measured: from what is on screen to what the sheet will show. When the move ends the
9987
+ * inline tracks and the marker are removed and the sheet's state is all that is left,
9988
+ * exactly as if nothing had been animated.
9989
+ *
9990
+ * It does nothing, and the change is immediate as before, when the reader asked for
9991
+ * less motion, when the split is stacked by its breakpoint (one pane either way), and
9992
+ * where there is no layout to measure.
9993
+ */
9994
+ _moveBetweenOneAndTwo() {
9995
+ this._endMove?.();
9996
+ if (!this.isConnected || this.hasAttribute("data-stacked")) return;
9997
+ if (this.classList.contains("aparte-split--only-start") || this.classList.contains("aparte-split--only-end")) return;
9998
+ if (typeof matchMedia !== "function" || matchMedia("(prefers-reduced-motion: reduce)").matches) return;
9999
+ const vertical = this.orientation === "vertical";
10000
+ const tracks = vertical ? "gridTemplateRows" : "gridTemplateColumns";
10001
+ const full = vertical ? this.clientHeight : this.clientWidth;
10002
+ if (full <= 0) return;
10003
+ this.setAttribute("data-moving", "");
10004
+ const two = getComputedStyle(this)[tracks];
10005
+ if (two.trim().split(/\s+/).length !== 3) {
10006
+ this.removeAttribute("data-moving");
10007
+ return;
10008
+ }
10009
+ const shownAlone = this.pane === "end" ? "end" : "start";
10010
+ const one = shownAlone === "end" ? `0px 0px ${full}px` : `${full}px 0px 0px`;
10011
+ const toSingle = this.single;
10012
+ const sizes = two.trim().split(/\s+/);
10013
+ const other = this.children[shownAlone === "end" ? 0 : 2];
10014
+ const size = vertical ? "blockSize" : "inlineSize";
10015
+ const align = vertical ? "alignSelf" : "justifySelf";
10016
+ const kept = other ? { size: other.style[size], align: other.style[align] } : null;
10017
+ if (other) {
10018
+ other.style[size] = sizes[shownAlone === "end" ? 0 : 2];
10019
+ other.style[align] = shownAlone === "end" ? "end" : "start";
10020
+ }
10021
+ this.style[tracks] = toSingle ? two : one;
10022
+ void this.offsetWidth;
10023
+ this.setAttribute("data-moving", "run");
10024
+ this.style[tracks] = toSingle ? one : two;
10025
+ let timer = null;
10026
+ const onEnd = (event) => {
10027
+ if (event.target === this && event.propertyName.startsWith("grid-template")) end();
10028
+ };
10029
+ const end = () => {
10030
+ if (timer !== null) clearTimeout(timer);
10031
+ this.removeEventListener("transitionend", onEnd);
10032
+ this.style.removeProperty(vertical ? "grid-template-rows" : "grid-template-columns");
10033
+ if (other && kept) {
10034
+ other.style[size] = kept.size;
10035
+ other.style[align] = kept.align;
10036
+ }
10037
+ this.removeAttribute("data-moving");
10038
+ this._endMove = null;
10039
+ this._measureBounds();
10040
+ };
10041
+ this._endMove = end;
10042
+ this.addEventListener("transitionend", onEnd);
10043
+ const seconds = Number.parseFloat(getComputedStyle(this).transitionDuration) || 0;
10044
+ timer = setTimeout(end, seconds * 1e3 + 120);
10045
+ }
9965
10046
  // ─── Structure ────────────────────────────────────────────────────────
9966
10047
  /**
9967
10048
  * The seam. An author-written `.aparte-split__handle` is ADOPTED — a second one
@@ -10040,7 +10121,7 @@ class AparteSplit extends HTMLElement {
10040
10121
  * host's storage when "Preview" is tapped on a phone.
10041
10122
  */
10042
10123
  _achievedPercent() {
10043
- if (this.stacked) return this._position;
10124
+ if (this._unmeasurable) return this._position;
10044
10125
  const total = this._measure(this);
10045
10126
  const pane = this._primaryPane();
10046
10127
  if (!pane || !(total > 0)) return this._position;
@@ -10065,7 +10146,7 @@ class AparteSplit extends HTMLElement {
10065
10146
  */
10066
10147
  _measureBounds() {
10067
10148
  const handle = this._handle;
10068
- if (!handle || this._dragging || this.stacked) return;
10149
+ if (!handle || this._dragging || this._unmeasurable) return;
10069
10150
  const pane = this._primaryPane();
10070
10151
  const total = this._measure(this);
10071
10152
  if (!pane || !(total > 0)) {
@@ -10146,7 +10227,7 @@ class AparteSplit extends HTMLElement {
10146
10227
  return getComputedStyle(this).direction === "rtl";
10147
10228
  }
10148
10229
  _onPointerDown = (event) => {
10149
- if (this.disabled || this.stacked || this._dragging) return;
10230
+ if (this.disabled || this._unmeasurable || this._dragging) return;
10150
10231
  if (event.button > 0) return;
10151
10232
  event.preventDefault();
10152
10233
  this._handle?.focus();
@@ -10276,7 +10357,7 @@ class AparteSplit extends HTMLElement {
10276
10357
  setTimeout(() => scrim.remove(), SCRIM_RETIRE_MS);
10277
10358
  }
10278
10359
  _onDoubleClick = () => {
10279
- if (this.disabled || this.stacked) return;
10360
+ if (this.disabled || this._unmeasurable) return;
10280
10361
  this.reset();
10281
10362
  };
10282
10363
  // ─── Keyboard ─────────────────────────────────────────────────────────
@@ -10286,7 +10367,7 @@ class AparteSplit extends HTMLElement {
10286
10367
  this._endDrag("pointer", this._dragStartPercent);
10287
10368
  return;
10288
10369
  }
10289
- if (this.disabled || this.stacked || event.target !== this._handle) return;
10370
+ if (this.disabled || this._unmeasurable || event.target !== this._handle) return;
10290
10371
  if (event.key === "Enter") {
10291
10372
  event.preventDefault();
10292
10373
  this._source = "keyboard";
@@ -10455,9 +10536,23 @@ const FOCUSABLE = [
10455
10536
  ].join(",");
10456
10537
  class AparteLauncher extends HTMLElement {
10457
10538
  static get observedAttributes() {
10458
- return ["open", "label", "breakpoint"];
10539
+ return ["open", "label", "breakpoint", "header", "heading", "subheading", "maximizable", "maximized"];
10459
10540
  }
10460
10541
  _button = null;
10542
+ /**
10543
+ * The element's header and the parts of it a render updates. Built once and updated in
10544
+ * place, never redrawn: the maximize button is what the person just pressed, and a new
10545
+ * node would take the focus out from under them.
10546
+ */
10547
+ _header = null;
10548
+ _avatar = null;
10549
+ /** The provider that drew the header's avatar, and what it returned to undo it. */
10550
+ _avatarDrawnBy = null;
10551
+ _avatarCleanup = null;
10552
+ _title = null;
10553
+ _subtitle = null;
10554
+ _maximize = null;
10555
+ _closeControl = null;
10461
10556
  /**
10462
10557
  * Watches the element's own children. The button is the one child that is not the host's,
10463
10558
  * so it is the one a framework reconciling the others knows nothing about: Vue's
@@ -10493,6 +10588,42 @@ class AparteLauncher extends HTMLElement {
10493
10588
  get sheet() {
10494
10589
  return this.hasAttribute("data-sheet");
10495
10590
  }
10591
+ /** The open chat is maximized: the whole window, or a panel along its edge with `maximizable="panel"`. */
10592
+ get maximized() {
10593
+ return this.hasAttribute("maximized");
10594
+ }
10595
+ set maximized(value) {
10596
+ this.toggleAttribute("maximized", presenceOn(value));
10597
+ }
10598
+ /**
10599
+ * The open chat covers the whole window: a sheet under the breakpoint, or maximized
10600
+ * without `maximizable="panel"`. What a page reads to take itself out of reach — the
10601
+ * launcher keeps Tab inside it meanwhile, and does not own the page.
10602
+ */
10603
+ get covers() {
10604
+ if (!this.open) return false;
10605
+ if (this.sheet) return true;
10606
+ if (!this.maximized) return false;
10607
+ if (!this._panel) return true;
10608
+ const width = this.getBoundingClientRect().width;
10609
+ return width > 0 && width >= document.documentElement.clientWidth - 1;
10610
+ }
10611
+ /** Maximized, the chat is a panel along the window's edge rather than the whole window. */
10612
+ get _panel() {
10613
+ return this.getAttribute("maximizable") === "panel";
10614
+ }
10615
+ /**
10616
+ * The element draws its header over a card that has none. A property as well as the
10617
+ * attribute because the attribute's OFF is a value, `"false"`, and a framework handed
10618
+ * `header={false}` removes a boolean attribute instead — which here means ON.
10619
+ */
10620
+ get header() {
10621
+ return this.getAttribute("header") !== "false";
10622
+ }
10623
+ set header(value) {
10624
+ if (value === false || value === "false") this.setAttribute("header", "false");
10625
+ else this.removeAttribute("header");
10626
+ }
10496
10627
  connectedCallback() {
10497
10628
  if (!this.classList.contains("aparte-launcher")) this.classList.add("aparte-launcher");
10498
10629
  if (!this._button) {
@@ -10501,14 +10632,16 @@ class AparteLauncher extends HTMLElement {
10501
10632
  this._button.type = "button";
10502
10633
  this._button.addEventListener("click", this._onButtonClick);
10503
10634
  }
10504
- for (const stale of this.querySelectorAll(":scope > .aparte-launcher__button")) {
10505
- if (stale !== this._button) stale.remove();
10635
+ for (const stale of this.querySelectorAll(":scope > .aparte-launcher__button, :scope > .aparte-launcher__header")) {
10636
+ if (stale !== this._button && stale !== this._header) stale.remove();
10506
10637
  }
10507
10638
  if (this._button.parentNode !== this) this.appendChild(this._button);
10508
10639
  if (typeof MutationObserver === "function") {
10509
- this._childWatch ??= new MutationObserver(() => this._keepButton());
10510
- this._childWatch.observe(this, { childList: true });
10511
- this._hostWatch ??= new MutationObserver(() => this._renderButton());
10640
+ this._childWatch ??= new MutationObserver((records) => {
10641
+ if (records.some((r) => r.target === this || AparteLauncher._touchesParts(r))) this._onChildren();
10642
+ });
10643
+ this._childWatch.observe(this, { childList: true, subtree: true });
10644
+ this._hostWatch ??= new MutationObserver(() => this._render());
10512
10645
  this._hostWatch.observe(this, { attributes: true, attributeFilter: [APARTE_HOST_ATTR], subtree: true });
10513
10646
  }
10514
10647
  this.addEventListener("click", this._onClick);
@@ -10516,7 +10649,7 @@ class AparteLauncher extends HTMLElement {
10516
10649
  window.addEventListener("aparte-config-change", this._onConfigChange);
10517
10650
  this._watchBreakpoint();
10518
10651
  this._lastOpen = this.open;
10519
- this._renderButton();
10652
+ this._render();
10520
10653
  this._ready = true;
10521
10654
  }
10522
10655
  disconnectedCallback() {
@@ -10527,15 +10660,24 @@ class AparteLauncher extends HTMLElement {
10527
10660
  this._hostWatch?.disconnect();
10528
10661
  this._media?.removeEventListener("change", this._onMediaChange);
10529
10662
  this._media = null;
10663
+ this._clearAvatar();
10530
10664
  this._ready = false;
10531
10665
  }
10532
- attributeChangedCallback(name) {
10666
+ attributeChangedCallback(name, previous, value) {
10533
10667
  if (!this._ready) return;
10534
10668
  if (name === "breakpoint") {
10535
10669
  this._watchBreakpoint();
10536
10670
  return;
10537
10671
  }
10538
- this._renderButton();
10672
+ this._render();
10673
+ if (name === "maximized") {
10674
+ if (previous === null !== (value === null)) this._announce();
10675
+ return;
10676
+ }
10677
+ if (name === "maximizable") {
10678
+ if (this.open && this.maximized && previous === "panel" !== (value === "panel")) this._announce();
10679
+ return;
10680
+ }
10539
10681
  if (name !== "open") return;
10540
10682
  const open = this.open;
10541
10683
  if (open === this._lastOpen) return;
@@ -10545,7 +10687,7 @@ class AparteLauncher extends HTMLElement {
10545
10687
  }
10546
10688
  _announce() {
10547
10689
  this.dispatchEvent(new CustomEvent("aparte-launcher-toggle", {
10548
- detail: { open: this.open, sheet: this.sheet },
10690
+ detail: { open: this.open, sheet: this.sheet, maximized: this.maximized, covers: this.covers },
10549
10691
  bubbles: true,
10550
10692
  composed: true
10551
10693
  }));
@@ -10563,6 +10705,17 @@ class AparteLauncher extends HTMLElement {
10563
10705
  toggle() {
10564
10706
  this.open = !this.open;
10565
10707
  }
10708
+ /**
10709
+ * Maximize the chat: the whole window, or a panel along its edge with
10710
+ * `maximizable="panel"`. Kept while the chat is closed, so it opens maximized.
10711
+ */
10712
+ maximize() {
10713
+ this.maximized = true;
10714
+ }
10715
+ /** Bring the chat back to its card. */
10716
+ restore() {
10717
+ this.maximized = false;
10718
+ }
10566
10719
  // ─── Button ───────────────────────────────────────────────────────────
10567
10720
  /**
10568
10721
  * The one opening that is a person's: the composer takes the focus, since they opened the
@@ -10576,7 +10729,24 @@ class AparteLauncher extends HTMLElement {
10576
10729
  this.toggle();
10577
10730
  if (opening) this._focusChat();
10578
10731
  };
10579
- _onConfigChange = () => this._renderButton();
10732
+ _onConfigChange = () => this._render();
10733
+ /** Everything the element draws, for the state it is in and the config it answers to. */
10734
+ _render() {
10735
+ const config = this._config();
10736
+ this._renderButton(config);
10737
+ this._renderHeader(config);
10738
+ this._syncMaximizeControls();
10739
+ }
10740
+ /**
10741
+ * The children changed: a framework reconciled them, hydration took out what it did not
10742
+ * render, a card arrived late. The button and the header go back if they were taken out,
10743
+ * and a card that now brings a header of its own is no longer given a second one.
10744
+ */
10745
+ _onChildren() {
10746
+ this._keepButton();
10747
+ this._renderHeader(this._config());
10748
+ this._syncMaximizeControls();
10749
+ }
10580
10750
  /**
10581
10751
  * The config the button answers to: the chat's own when the chat inside carries an
10582
10752
  * instance config (a wrapper's `config` prop, `attachConfig(chat, config)`), else the
@@ -10606,11 +10776,10 @@ class AparteLauncher extends HTMLElement {
10606
10776
  * contract: there is no `aria-controls`, since the one element it could name without
10607
10777
  * writing an id on the host's card is the launcher itself, the button's own ancestor.
10608
10778
  */
10609
- _renderButton() {
10779
+ _renderButton(config) {
10610
10780
  const button2 = this._button;
10611
10781
  if (!button2) return;
10612
10782
  this._keepButton();
10613
- const config = this._config();
10614
10783
  const locale = config.getLocale();
10615
10784
  const open = this.open;
10616
10785
  const label = open ? "" : (this.getAttribute("label") ?? "").trim();
@@ -10619,11 +10788,7 @@ class AparteLauncher extends HTMLElement {
10619
10788
  button2.setAttribute("aria-expanded", String(open));
10620
10789
  if (label) button2.removeAttribute("aria-label");
10621
10790
  else button2.setAttribute("aria-label", open ? locale.launcherClose ?? "Close the chat" : locale.launcherOpen ?? "Open the chat");
10622
- const icon = document.createElement("span");
10623
- icon.className = "aparte-launcher__icon";
10624
- icon.setAttribute("aria-hidden", "true");
10625
- icon.innerHTML = open ? config.getIcon("launcherClose") ?? config.getIcon("close") : config.getIcon("launcherOpen") ?? config.getIcon("messageSquare");
10626
- const parts = [icon];
10791
+ const parts = [AparteLauncher._glyph(open ? config.getIcon("launcherClose") ?? config.getIcon("close") : config.getIcon("launcherOpen") ?? config.getIcon("messageSquare"))];
10627
10792
  if (label) {
10628
10793
  const text = document.createElement("span");
10629
10794
  text.className = "aparte-launcher__label";
@@ -10632,6 +10797,158 @@ class AparteLauncher extends HTMLElement {
10632
10797
  }
10633
10798
  button2.replaceChildren(...parts);
10634
10799
  }
10800
+ /** A glyph, out of the accessibility tree: what holds it is named by its label. */
10801
+ static _glyph(svg) {
10802
+ const icon = document.createElement("span");
10803
+ icon.className = "aparte-launcher__icon";
10804
+ icon.setAttribute("aria-hidden", "true");
10805
+ icon.innerHTML = svg;
10806
+ return icon;
10807
+ }
10808
+ // ─── Header ───────────────────────────────────────────────────────────
10809
+ /**
10810
+ * A card that brings its own header: a `<header>` at its top level — how every card in
10811
+ * this repository with a header of its own is written, so they keep theirs and are not
10812
+ * given a second. A close control alone is not one: an "End chat" in a card's footer is a
10813
+ * close control too, and took the header away when it counted.
10814
+ */
10815
+ _cardHasHeader() {
10816
+ return Array.from(this.children).some((child) => child !== this._button && child !== this._header && child.querySelector(":scope > header") !== null);
10817
+ }
10818
+ /**
10819
+ * A change deeper in the card that the element answers: a header, or a maximize
10820
+ * control, arriving or leaving — a framework rendering a card's header after the card,
10821
+ * a conditional control. A streamed reply adds text and spans, so it calls for nothing.
10822
+ */
10823
+ static _touchesParts(record) {
10824
+ const parts = "header, [data-aparte-launcher-maximize]";
10825
+ return [...record.addedNodes, ...record.removedNodes].some((node) => node instanceof Element && (node.matches(parts) || node.querySelector(parts) !== null));
10826
+ }
10827
+ /** An icon-only control of the header: the recipe's ghost icon button. */
10828
+ static _headerButton(part) {
10829
+ const button2 = document.createElement("button");
10830
+ button2.type = "button";
10831
+ button2.className = `aparte-btn aparte-btn--icon aparte-btn--ghost aparte-launcher__${part}`;
10832
+ return button2;
10833
+ }
10834
+ /** A control's name, spoken and shown on hover: an icon alone says nothing to a pointer. */
10835
+ static _name(button2, name, svg) {
10836
+ button2.setAttribute("aria-label", name);
10837
+ button2.setAttribute("title", name);
10838
+ button2.replaceChildren(AparteLauncher._glyph(svg));
10839
+ }
10840
+ _buildHeader() {
10841
+ const header = document.createElement("div");
10842
+ header.className = "aparte-app-header aparte-launcher__header";
10843
+ this._avatar = document.createElement("span");
10844
+ this._avatar.className = "aparte-avatar aparte-launcher__avatar";
10845
+ this._avatar.setAttribute("data-role", "assistant");
10846
+ this._avatar.setAttribute("aria-hidden", "true");
10847
+ const heading = document.createElement("div");
10848
+ heading.className = "aparte-launcher__heading";
10849
+ this._title = document.createElement("span");
10850
+ this._title.className = "aparte-app-header__title aparte-launcher__title";
10851
+ this._title.setAttribute("role", "heading");
10852
+ this._title.setAttribute("aria-level", "2");
10853
+ this._subtitle = document.createElement("span");
10854
+ this._subtitle.className = "aparte-launcher__subheading";
10855
+ heading.append(this._title, this._subtitle);
10856
+ const actions = document.createElement("div");
10857
+ actions.className = "aparte-app-header__actions";
10858
+ this._maximize = AparteLauncher._headerButton("maximize");
10859
+ this._maximize.setAttribute("data-aparte-launcher-maximize", "");
10860
+ this._closeControl = AparteLauncher._headerButton("close");
10861
+ this._closeControl.setAttribute("data-aparte-launcher-close", "");
10862
+ actions.append(this._maximize, this._closeControl);
10863
+ header.append(this._avatar, heading, actions);
10864
+ return header;
10865
+ }
10866
+ /**
10867
+ * The header, when the element draws one: the title, the line under it, the maximize
10868
+ * button for its state, the ✕. It goes first among the children, and the stylesheet
10869
+ * joins it to the card under it.
10870
+ */
10871
+ _renderHeader(config) {
10872
+ if (!this.header || this._cardHasHeader()) {
10873
+ const hadFocus = !!this._header?.contains(activeElementIn(this));
10874
+ this._clearAvatar();
10875
+ this._header?.remove();
10876
+ if (hadFocus) (this._focusTarget() ?? this._button)?.focus();
10877
+ return;
10878
+ }
10879
+ const header = this._header ??= this._buildHeader();
10880
+ const locale = config.getLocale();
10881
+ const label = (this.getAttribute("label") ?? "").trim();
10882
+ const title = (this.getAttribute("heading") ?? (label || (locale.launcherHeading ?? "Chat"))).trim();
10883
+ this._title.textContent = title;
10884
+ this._title.hidden = !title;
10885
+ this._drawAvatar(config);
10886
+ const subtitle = (this.getAttribute("subheading") ?? "").trim();
10887
+ this._subtitle.textContent = subtitle;
10888
+ this._subtitle.hidden = !subtitle;
10889
+ const maximize = this._maximize;
10890
+ maximize.hidden = !this.hasAttribute("maximizable");
10891
+ AparteLauncher._name(
10892
+ maximize,
10893
+ this.maximized ? locale.launcherRestore ?? "Shrink the chat" : locale.launcherMaximize ?? "Expand the chat",
10894
+ config.getIcon(this.maximized ? "minimize" : "maximize")
10895
+ );
10896
+ AparteLauncher._name(this._closeControl, locale.launcherClose ?? "Close the chat", config.getIcon("close"));
10897
+ if (this.firstElementChild !== header) this.prepend(header);
10898
+ this._markAvatarImage();
10899
+ }
10900
+ /**
10901
+ * The assistant's avatar, by the provider that draws it in the messages — the one place an
10902
+ * app says what its assistant looks like, a framework component included. Drawn again only
10903
+ * when the provider changes, since a render runs on every attribute and a provider may
10904
+ * mount a component. Empty without one, and the stylesheet folds an empty slot away.
10905
+ */
10906
+ _drawAvatar(config) {
10907
+ const provider = config.getAvatarProvider();
10908
+ if (provider === this._avatarDrawnBy) return;
10909
+ this._clearAvatar();
10910
+ if (!provider || !this._avatar) return;
10911
+ this._avatarDrawnBy = provider;
10912
+ try {
10913
+ const cleanup = provider.render("assistant", this._avatar);
10914
+ if (typeof cleanup === "function") this._avatarCleanup = cleanup;
10915
+ } catch (error) {
10916
+ this._avatar.replaceChildren();
10917
+ console.error("[aparte] The avatar provider failed for the launcher's header, which shows no avatar. It is called with a host outside any message there.", error);
10918
+ }
10919
+ }
10920
+ /**
10921
+ * A picture from the stylesheet alone (`--aparte-avatar-image-assistant`), as a message's
10922
+ * slot shows it: an empty slot that has one is marked, which lifts the rule folding an empty
10923
+ * slot away. Read after the header is in the document, where its style resolves.
10924
+ */
10925
+ _markAvatarImage() {
10926
+ const slot = this._avatar;
10927
+ if (!slot) return;
10928
+ const image = typeof getComputedStyle === "function" ? getComputedStyle(slot).backgroundImage : "";
10929
+ slot.toggleAttribute("data-image", !slot.firstChild && !!image && image !== "none");
10930
+ }
10931
+ _clearAvatar() {
10932
+ try {
10933
+ this._avatarCleanup?.();
10934
+ } catch {
10935
+ }
10936
+ this._avatarCleanup = null;
10937
+ this._avatarDrawnBy = null;
10938
+ this._avatar?.replaceChildren();
10939
+ }
10940
+ /**
10941
+ * A maximize control of the host's says what it does: `aria-pressed` follows the state.
10942
+ * The element's own button is the exception, because it changes its NAME with the state
10943
+ * instead, and a toggle whose name changes must not also say it is pressed.
10944
+ */
10945
+ _syncMaximizeControls() {
10946
+ const pressed = String(this.maximized);
10947
+ for (const control of this.querySelectorAll("[data-aparte-launcher-maximize]")) {
10948
+ if (control === this._maximize || inRenderedContent(control)) continue;
10949
+ control.setAttribute("aria-pressed", pressed);
10950
+ }
10951
+ }
10635
10952
  // ─── Sheet ────────────────────────────────────────────────────────────
10636
10953
  _onMediaChange = (e) => this._applySheet(e.matches);
10637
10954
  /** The sheet's media query, from `breakpoint`: a length, or `none` for a card at any width. */
@@ -10656,6 +10973,10 @@ class AparteLauncher extends HTMLElement {
10656
10973
  _applySheet(sheet) {
10657
10974
  if (sheet === this.sheet) return;
10658
10975
  this.toggleAttribute("data-sheet", sheet);
10976
+ const active = activeElementIn(this);
10977
+ if (sheet && active?.matches("[data-aparte-launcher-maximize]") && this.contains(active)) {
10978
+ (this._closeControl?.isConnected ? this._closeControl : this._focusTarget())?.focus();
10979
+ }
10659
10980
  if (this._ready && this.open) this._announce();
10660
10981
  }
10661
10982
  // ─── Focus and keys ───────────────────────────────────────────────────
@@ -10666,17 +10987,34 @@ class AparteLauncher extends HTMLElement {
10666
10987
  /**
10667
10988
  * The composer when there is one — the person opened the chat to write — else the
10668
10989
  * first thing in the card that holds focus. The button itself never: it is what the
10669
- * person just pressed.
10990
+ * person just pressed. Nor the element's header, which comes first in the DOM: its ✕
10991
+ * is not what anyone opened the chat for, and focus landing there would read the way
10992
+ * out before the way in.
10670
10993
  */
10671
10994
  _focusChat() {
10995
+ this._focusTarget()?.focus();
10996
+ }
10997
+ /**
10998
+ * Where the focus goes in the chat: the composer, else the card's first control, else —
10999
+ * when the chat covers the window and its button is hidden — the header's ✕, the one way
11000
+ * out left on screen.
11001
+ */
11002
+ _focusTarget() {
10672
11003
  const composer = Array.from(this.querySelectorAll('[role="textbox"]:not([aria-disabled="true"])')).find((el2) => !inRenderedContent(el2) && !el2.closest("[hidden]") && el2.checkVisibility?.() !== false);
10673
- const target = composer ?? this._focusables().find((el2) => el2 !== this._button);
10674
- target?.focus();
11004
+ return composer ?? this._focusables().find((el2) => el2 !== this._button && !this._header?.contains(el2)) ?? (this.covers && this._closeControl?.isConnected ? this._closeControl : void 0);
10675
11005
  }
10676
- /** A `[data-aparte-launcher-close]` inside closes the chat — no script in your card. */
11006
+ /**
11007
+ * A `[data-aparte-launcher-close]` inside closes the chat, and a
11008
+ * `[data-aparte-launcher-maximize]` enlarges it or brings it back — no script in your card.
11009
+ */
10677
11010
  _onClick = (e) => {
10678
- const control = eventOrigin(e)?.closest?.("[data-aparte-launcher-close]");
10679
- if (control && this.contains(control) && !inRenderedContent(control)) this.close();
11011
+ const origin = eventOrigin(e);
11012
+ const placed = (selector) => {
11013
+ const control = origin?.closest?.(selector);
11014
+ return !!control && this.contains(control) && !inRenderedContent(control);
11015
+ };
11016
+ if (placed("[data-aparte-launcher-close]")) this.close();
11017
+ else if (placed("[data-aparte-launcher-maximize]")) this.maximized = !this.maximized;
10680
11018
  };
10681
11019
  /**
10682
11020
  * A modal dialog open inside the card, with the key pressed inside it. The browser
@@ -10699,10 +11037,11 @@ class AparteLauncher extends HTMLElement {
10699
11037
  if (e.key === "Escape") {
10700
11038
  if (e.defaultPrevented || e.isComposing || e.keyCode === 229 || this._inModalDialog(e)) return;
10701
11039
  e.preventDefault();
10702
- this.close();
11040
+ if (this.maximized && !this.sheet) this.maximized = false;
11041
+ else this.close();
10703
11042
  return;
10704
11043
  }
10705
- if (e.key !== "Tab" || !this.sheet) return;
11044
+ if (e.key !== "Tab" || !this.covers) return;
10706
11045
  const focusable = this._focusables();
10707
11046
  if (focusable.length === 0) return;
10708
11047
  const first = focusable[0];