@aparte/core 1.1.1 → 1.2.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-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-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";
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";
@@ -10496,11 +10577,15 @@ class AparteLauncher extends HTMLElement {
10496
10577
  connectedCallback() {
10497
10578
  if (!this.classList.contains("aparte-launcher")) this.classList.add("aparte-launcher");
10498
10579
  if (!this._button) {
10499
- this._button = document.createElement("button");
10580
+ const drawn = this.querySelector(":scope > button.aparte-launcher__button");
10581
+ this._button = drawn instanceof HTMLButtonElement ? drawn : document.createElement("button");
10500
10582
  this._button.type = "button";
10501
10583
  this._button.addEventListener("click", this._onButtonClick);
10502
10584
  }
10503
- this.appendChild(this._button);
10585
+ for (const stale of this.querySelectorAll(":scope > .aparte-launcher__button")) {
10586
+ if (stale !== this._button) stale.remove();
10587
+ }
10588
+ if (this._button.parentNode !== this) this.appendChild(this._button);
10504
10589
  if (typeof MutationObserver === "function") {
10505
10590
  this._childWatch ??= new MutationObserver(() => this._keepButton());
10506
10591
  this._childWatch.observe(this, { childList: true });