@aparte/core 1.2.0 → 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.
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-Oh04ScDm.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-Oh04ScDm.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
  }
@@ -10536,9 +10536,23 @@ const FOCUSABLE = [
10536
10536
  ].join(",");
10537
10537
  class AparteLauncher extends HTMLElement {
10538
10538
  static get observedAttributes() {
10539
- return ["open", "label", "breakpoint"];
10539
+ return ["open", "label", "breakpoint", "header", "heading", "subheading", "maximizable", "maximized"];
10540
10540
  }
10541
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;
10542
10556
  /**
10543
10557
  * Watches the element's own children. The button is the one child that is not the host's,
10544
10558
  * so it is the one a framework reconciling the others knows nothing about: Vue's
@@ -10574,6 +10588,42 @@ class AparteLauncher extends HTMLElement {
10574
10588
  get sheet() {
10575
10589
  return this.hasAttribute("data-sheet");
10576
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
+ }
10577
10627
  connectedCallback() {
10578
10628
  if (!this.classList.contains("aparte-launcher")) this.classList.add("aparte-launcher");
10579
10629
  if (!this._button) {
@@ -10582,14 +10632,16 @@ class AparteLauncher extends HTMLElement {
10582
10632
  this._button.type = "button";
10583
10633
  this._button.addEventListener("click", this._onButtonClick);
10584
10634
  }
10585
- for (const stale of this.querySelectorAll(":scope > .aparte-launcher__button")) {
10586
- 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();
10587
10637
  }
10588
10638
  if (this._button.parentNode !== this) this.appendChild(this._button);
10589
10639
  if (typeof MutationObserver === "function") {
10590
- this._childWatch ??= new MutationObserver(() => this._keepButton());
10591
- this._childWatch.observe(this, { childList: true });
10592
- 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());
10593
10645
  this._hostWatch.observe(this, { attributes: true, attributeFilter: [APARTE_HOST_ATTR], subtree: true });
10594
10646
  }
10595
10647
  this.addEventListener("click", this._onClick);
@@ -10597,7 +10649,7 @@ class AparteLauncher extends HTMLElement {
10597
10649
  window.addEventListener("aparte-config-change", this._onConfigChange);
10598
10650
  this._watchBreakpoint();
10599
10651
  this._lastOpen = this.open;
10600
- this._renderButton();
10652
+ this._render();
10601
10653
  this._ready = true;
10602
10654
  }
10603
10655
  disconnectedCallback() {
@@ -10608,15 +10660,24 @@ class AparteLauncher extends HTMLElement {
10608
10660
  this._hostWatch?.disconnect();
10609
10661
  this._media?.removeEventListener("change", this._onMediaChange);
10610
10662
  this._media = null;
10663
+ this._clearAvatar();
10611
10664
  this._ready = false;
10612
10665
  }
10613
- attributeChangedCallback(name) {
10666
+ attributeChangedCallback(name, previous, value) {
10614
10667
  if (!this._ready) return;
10615
10668
  if (name === "breakpoint") {
10616
10669
  this._watchBreakpoint();
10617
10670
  return;
10618
10671
  }
10619
- 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
+ }
10620
10681
  if (name !== "open") return;
10621
10682
  const open = this.open;
10622
10683
  if (open === this._lastOpen) return;
@@ -10626,7 +10687,7 @@ class AparteLauncher extends HTMLElement {
10626
10687
  }
10627
10688
  _announce() {
10628
10689
  this.dispatchEvent(new CustomEvent("aparte-launcher-toggle", {
10629
- detail: { open: this.open, sheet: this.sheet },
10690
+ detail: { open: this.open, sheet: this.sheet, maximized: this.maximized, covers: this.covers },
10630
10691
  bubbles: true,
10631
10692
  composed: true
10632
10693
  }));
@@ -10644,6 +10705,17 @@ class AparteLauncher extends HTMLElement {
10644
10705
  toggle() {
10645
10706
  this.open = !this.open;
10646
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
+ }
10647
10719
  // ─── Button ───────────────────────────────────────────────────────────
10648
10720
  /**
10649
10721
  * The one opening that is a person's: the composer takes the focus, since they opened the
@@ -10657,7 +10729,24 @@ class AparteLauncher extends HTMLElement {
10657
10729
  this.toggle();
10658
10730
  if (opening) this._focusChat();
10659
10731
  };
10660
- _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
+ }
10661
10750
  /**
10662
10751
  * The config the button answers to: the chat's own when the chat inside carries an
10663
10752
  * instance config (a wrapper's `config` prop, `attachConfig(chat, config)`), else the
@@ -10687,11 +10776,10 @@ class AparteLauncher extends HTMLElement {
10687
10776
  * contract: there is no `aria-controls`, since the one element it could name without
10688
10777
  * writing an id on the host's card is the launcher itself, the button's own ancestor.
10689
10778
  */
10690
- _renderButton() {
10779
+ _renderButton(config) {
10691
10780
  const button2 = this._button;
10692
10781
  if (!button2) return;
10693
10782
  this._keepButton();
10694
- const config = this._config();
10695
10783
  const locale = config.getLocale();
10696
10784
  const open = this.open;
10697
10785
  const label = open ? "" : (this.getAttribute("label") ?? "").trim();
@@ -10700,11 +10788,7 @@ class AparteLauncher extends HTMLElement {
10700
10788
  button2.setAttribute("aria-expanded", String(open));
10701
10789
  if (label) button2.removeAttribute("aria-label");
10702
10790
  else button2.setAttribute("aria-label", open ? locale.launcherClose ?? "Close the chat" : locale.launcherOpen ?? "Open the chat");
10703
- const icon = document.createElement("span");
10704
- icon.className = "aparte-launcher__icon";
10705
- icon.setAttribute("aria-hidden", "true");
10706
- icon.innerHTML = open ? config.getIcon("launcherClose") ?? config.getIcon("close") : config.getIcon("launcherOpen") ?? config.getIcon("messageSquare");
10707
- const parts = [icon];
10791
+ const parts = [AparteLauncher._glyph(open ? config.getIcon("launcherClose") ?? config.getIcon("close") : config.getIcon("launcherOpen") ?? config.getIcon("messageSquare"))];
10708
10792
  if (label) {
10709
10793
  const text = document.createElement("span");
10710
10794
  text.className = "aparte-launcher__label";
@@ -10713,6 +10797,158 @@ class AparteLauncher extends HTMLElement {
10713
10797
  }
10714
10798
  button2.replaceChildren(...parts);
10715
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
+ }
10716
10952
  // ─── Sheet ────────────────────────────────────────────────────────────
10717
10953
  _onMediaChange = (e) => this._applySheet(e.matches);
10718
10954
  /** The sheet's media query, from `breakpoint`: a length, or `none` for a card at any width. */
@@ -10737,6 +10973,10 @@ class AparteLauncher extends HTMLElement {
10737
10973
  _applySheet(sheet) {
10738
10974
  if (sheet === this.sheet) return;
10739
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
+ }
10740
10980
  if (this._ready && this.open) this._announce();
10741
10981
  }
10742
10982
  // ─── Focus and keys ───────────────────────────────────────────────────
@@ -10747,17 +10987,34 @@ class AparteLauncher extends HTMLElement {
10747
10987
  /**
10748
10988
  * The composer when there is one — the person opened the chat to write — else the
10749
10989
  * first thing in the card that holds focus. The button itself never: it is what the
10750
- * 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.
10751
10993
  */
10752
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() {
10753
11003
  const composer = Array.from(this.querySelectorAll('[role="textbox"]:not([aria-disabled="true"])')).find((el2) => !inRenderedContent(el2) && !el2.closest("[hidden]") && el2.checkVisibility?.() !== false);
10754
- const target = composer ?? this._focusables().find((el2) => el2 !== this._button);
10755
- 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);
10756
11005
  }
10757
- /** 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
+ */
10758
11010
  _onClick = (e) => {
10759
- const control = eventOrigin(e)?.closest?.("[data-aparte-launcher-close]");
10760
- 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;
10761
11018
  };
10762
11019
  /**
10763
11020
  * A modal dialog open inside the card, with the key pressed inside it. The browser
@@ -10780,10 +11037,11 @@ class AparteLauncher extends HTMLElement {
10780
11037
  if (e.key === "Escape") {
10781
11038
  if (e.defaultPrevented || e.isComposing || e.keyCode === 229 || this._inModalDialog(e)) return;
10782
11039
  e.preventDefault();
10783
- this.close();
11040
+ if (this.maximized && !this.sheet) this.maximized = false;
11041
+ else this.close();
10784
11042
  return;
10785
11043
  }
10786
- if (e.key !== "Tab" || !this.sheet) return;
11044
+ if (e.key !== "Tab" || !this.covers) return;
10787
11045
  const focusable = this._focusables();
10788
11046
  if (focusable.length === 0) return;
10789
11047
  const first = focusable[0];