@aparte/core 0.31.0 → 0.32.1

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.
@@ -1412,6 +1412,7 @@ function fill(root, code, entry, renderer, ctx, key, move = true) {
1412
1412
  drawing.className = DRAWING_CLASS;
1413
1413
  if (ctx.display) drawing.setAttribute("data-aparte-display", "");
1414
1414
  if (renderer.bare) drawing.setAttribute("data-aparte-bare", "");
1415
+ else drawing.setAttribute("dir", "ltr");
1415
1416
  code.after(drawing);
1416
1417
  drawingOwner.set(drawing, code);
1417
1418
  if (code.parentElement?.tagName === "PRE") code.parentElement.setAttribute(DRAWN_ATTR, "");
@@ -1548,10 +1549,16 @@ function drawOpen(root, code, renderer, ctx, pos) {
1548
1549
  else if (html == null) forget();
1549
1550
  }, forget);
1550
1551
  }
1552
+ function markLeftToRight(root) {
1553
+ for (const tag of ["code", "kbd", "samp"]) {
1554
+ for (const el2 of Array.from(root.getElementsByTagName(tag))) if (!el2.hasAttribute("dir")) el2.setAttribute("dir", "ltr");
1555
+ }
1556
+ }
1551
1557
  function renderCodeLanguages(root, options = {}) {
1552
1558
  if (typeof document === "undefined") return;
1553
1559
  const { streaming = false, refresh = false, language } = options;
1554
1560
  if (!refresh) {
1561
+ markLeftToRight(root);
1555
1562
  lastOptions.set(root, { streaming });
1556
1563
  if (!streaming) asked.delete(root);
1557
1564
  if (!contextConfig(root).hasCodeLanguageRenderer()) {
@@ -2145,6 +2152,8 @@ function openCard(chip) {
2145
2152
  const el2 = document.createElement("div");
2146
2153
  el2.className = "aparte-citation-card aparte-popover";
2147
2154
  el2.id = `aparte-citation-card-${++cards}`;
2155
+ const transcript = chip.closest(".aparte-viewport-container, aparte-chat-viewport") ?? chip.ownerDocument.documentElement;
2156
+ el2.dir = getComputedStyle(transcript).direction === "rtl" ? "rtl" : "ltr";
2148
2157
  el2.setAttribute("role", "dialog");
2149
2158
  el2.setAttribute("aria-label", config.getLocale().sourcesCard ?? "Sources");
2150
2159
  const body = document.createElement("div");
@@ -2286,6 +2295,7 @@ function drawCard() {
2286
2295
  link.rel = "noopener noreferrer";
2287
2296
  link.dataset.aparteCardPart = "link";
2288
2297
  link.textContent = title;
2298
+ link.dir = "auto";
2289
2299
  const hint = document.createElement("span");
2290
2300
  hint.className = "aparte-sr-only";
2291
2301
  hint.textContent = ` ${locale.opensInNewTab ?? "(opens in a new tab)"}`;
@@ -2295,6 +2305,7 @@ function drawCard() {
2295
2305
  const plain = document.createElement("p");
2296
2306
  plain.className = "aparte-citation-card__title";
2297
2307
  plain.textContent = title;
2308
+ plain.dir = "auto";
2298
2309
  body.append(plain);
2299
2310
  }
2300
2311
  const domain = sourceDomain(source);
@@ -2302,12 +2313,14 @@ function drawCard() {
2302
2313
  const p = document.createElement("p");
2303
2314
  p.className = "aparte-citation-card__domain";
2304
2315
  p.textContent = domain;
2316
+ p.dir = "auto";
2305
2317
  body.append(p);
2306
2318
  }
2307
2319
  if (source.snippet) {
2308
2320
  const p = document.createElement("p");
2309
2321
  p.className = "aparte-citation-card__snippet";
2310
2322
  p.textContent = source.snippet;
2323
+ p.dir = "auto";
2311
2324
  body.append(p);
2312
2325
  }
2313
2326
  if (sources2.length > 1) {
@@ -2378,18 +2391,20 @@ function renderSourceList(container, after, sources2, config) {
2378
2391
  link.target = "_blank";
2379
2392
  link.rel = "noopener noreferrer";
2380
2393
  link.textContent = title;
2394
+ link.dir = "auto";
2381
2395
  const hint = document.createElement("span");
2382
2396
  hint.className = "aparte-sr-only";
2383
2397
  hint.textContent = ` ${hintText}`;
2384
2398
  link.append(hint);
2385
2399
  item.append(link);
2386
2400
  } else {
2387
- item.append(title);
2401
+ item.append(Object.assign(document.createElement("span"), { textContent: title, dir: "auto" }));
2388
2402
  }
2389
2403
  if (domain && domain !== title) {
2390
2404
  const d = document.createElement("span");
2391
2405
  d.className = "aparte-sources__domain";
2392
2406
  d.textContent = domain;
2407
+ d.dir = "auto";
2393
2408
  item.append(" ", d);
2394
2409
  }
2395
2410
  items.append(item);
@@ -2477,7 +2492,7 @@ function replaceHighlighted(pre, html) {
2477
2492
  }
2478
2493
  const textRenderer = {
2479
2494
  type: "text",
2480
- render: (segment) => `<div class="aparte-segment aparte-segment-text" data-segment-id="${escapeHtml(segment.id)}"><div class="aparte-segment-content">${contextConfig().renderMarkdown(segment.content)}</div></div>`,
2495
+ render: (segment) => `<div class="aparte-segment aparte-segment-text" data-segment-id="${escapeHtml(segment.id)}"><div class="aparte-segment-content" dir="auto">${contextConfig().renderMarkdown(segment.content)}</div></div>`,
2481
2496
  /*
2482
2497
  * A fence in a settled text segment is highlighted, as the thinking renderer does for
2483
2498
  * its own. The parser turns a streamed fence into a `code` segment, so this only ever
@@ -2566,7 +2581,7 @@ const thinkingRenderer = {
2566
2581
  * only part that is genuinely about reasoning rather than about disclosure.
2567
2582
  * `.aparte-thinking-label` stays too: `relabel` below queries it.
2568
2583
  */
2569
- render: (segment) => `<details class="aparte-segment aparte-segment-thinking aparte-accordion__item" data-segment-id="${escapeHtml(segment.id)}" ${segment.collapsed === false ? "open" : ""}><summary class="aparte-accordion__header aparte-thinking-header"><span class="aparte-thinking-label${escapeAttr(arriving(segment) ? " aparte-shimmer" : "")}">${escapeHtml(labelOf(segment))}</span><span class="aparte-accordion__icon">${contextConfig().getIcon("expand")}</span></summary><div class="aparte-accordion__panel aparte-thinking-content" role="region" tabindex="0" aria-label="${escapeAttr(labelOf(segment))}">${contextConfig().renderMarkdown(segment.content)}</div></details>`,
2584
+ render: (segment) => `<details class="aparte-segment aparte-segment-thinking aparte-accordion__item" data-segment-id="${escapeHtml(segment.id)}" ${segment.collapsed === false ? "open" : ""}><summary class="aparte-accordion__header aparte-thinking-header"><span class="aparte-thinking-label${escapeAttr(arriving(segment) ? " aparte-shimmer" : "")}">${escapeHtml(labelOf(segment))}</span><span class="aparte-accordion__icon">${contextConfig().getIcon("expand")}</span></summary><div class="aparte-accordion__panel aparte-thinking-content" dir="auto" role="region" tabindex="0" aria-label="${escapeAttr(labelOf(segment))}">${contextConfig().renderMarkdown(segment.content)}</div></details>`,
2570
2585
  /**
2571
2586
  * The default label is the only config-derived text here — and `segment.label`
2572
2587
  * still wins, exactly as in `render`, because that string is the app's.
@@ -2725,7 +2740,8 @@ function highlightSettled(element, segment) {
2725
2740
  const languageOf = (segment) => (segment.language || "").trim().split(/\s+/)[0] ?? "";
2726
2741
  function markBare(element, segment) {
2727
2742
  const language = languageOf(segment);
2728
- element.toggleAttribute("data-aparte-bare", !!language && contextConfig(element).getCodeLanguageRenderer(language)?.bare === true);
2743
+ const renderer = language ? contextConfig(element).getCodeLanguageRenderer(language) : void 0;
2744
+ element.toggleAttribute("data-aparte-bare", !!renderer && renderer.card !== true);
2729
2745
  }
2730
2746
  function drawSettledOrStreaming(element, segment) {
2731
2747
  const wrapper = element.querySelector(".aparte-code-content-wrapper");
@@ -7974,6 +7990,7 @@ function el$1(tag, className, text) {
7974
7990
  function optionBody(label, description, recommended) {
7975
7991
  const body = el$1("span", "aparte-elic-option-body");
7976
7992
  const title = el$1("span", "aparte-elic-option-title", label);
7993
+ title.dir = "auto";
7977
7994
  if (recommended) {
7978
7995
  const badge = el$1(
7979
7996
  "span",
@@ -7983,7 +8000,7 @@ function optionBody(label, description, recommended) {
7983
8000
  title.append(" ", badge);
7984
8001
  }
7985
8002
  body.appendChild(title);
7986
- if (description) body.appendChild(el$1("span", "aparte-elic-option-desc", description));
8003
+ if (description) body.appendChild(Object.assign(el$1("span", "aparte-elic-option-desc", description), { dir: "auto" }));
7987
8004
  return body;
7988
8005
  }
7989
8006
  function commandOption(label, description, recommended) {
@@ -7996,11 +8013,12 @@ function fieldHeader(parent, field, skipTitle) {
7996
8013
  let titleId;
7997
8014
  if (field.title && field.title.trim() !== skipTitle?.trim()) {
7998
8015
  const title = el$1("p", "aparte-elic-title", field.title);
8016
+ title.dir = "auto";
7999
8017
  titleId = `elic-title-${uuid()}`;
8000
8018
  title.id = titleId;
8001
8019
  parent.appendChild(title);
8002
8020
  }
8003
- if (field.description) parent.appendChild(el$1("p", "aparte-elic-desc", field.description));
8021
+ if (field.description) parent.appendChild(Object.assign(el$1("p", "aparte-elic-desc", field.description), { dir: "auto" }));
8004
8022
  return titleId;
8005
8023
  }
8006
8024
  function labelGroup(list, opts) {
@@ -8179,6 +8197,7 @@ function buildBooleanField(field, onChange, fallbackLabel, settle) {
8179
8197
  if (field.default != null && String(field.default) === val) control.checked = true;
8180
8198
  const body = el$1("span", "aparte-elic-option-body");
8181
8199
  const title = el$1("span", "aparte-elic-option-title", label);
8200
+ title.dir = "auto";
8182
8201
  if (defaulted) onRelabel(() => {
8183
8202
  title.textContent = contextConfig().t(defaulted);
8184
8203
  });
@@ -8266,7 +8285,7 @@ function buildElicitationPanel(message, schema, onChange) {
8266
8285
  function buildPanel(message, schema, onChange) {
8267
8286
  const panel = el$1("div", "aparte-elic-panel");
8268
8287
  const asked2 = typeof message === "function" ? message() : message;
8269
- if (asked2) panel.appendChild(el$1("p", "aparte-elic-message", asked2));
8288
+ if (asked2) panel.appendChild(Object.assign(el$1("p", "aparte-elic-message", asked2), { dir: "auto" }));
8270
8289
  let settleCb = null;
8271
8290
  let settled2 = false;
8272
8291
  const settle = (content) => {
@@ -8301,7 +8320,7 @@ function buildPanel(message, schema, onChange) {
8301
8320
  const fields = entries.map(([key, field2]) => {
8302
8321
  const built = buildField(field2, notify, void 0, key);
8303
8322
  if (!field2.title && !built.el.querySelector(".aparte-elic-title")) {
8304
- built.el.insertBefore(el$1("p", "aparte-elic-title", key), built.el.firstChild);
8323
+ built.el.insertBefore(Object.assign(el$1("p", "aparte-elic-title", key), { dir: "auto" }), built.el.firstChild);
8305
8324
  }
8306
8325
  body.appendChild(built.el);
8307
8326
  return { key, field: built, required: requiredKeys.has(key), header: field2.header };
@@ -8334,6 +8353,7 @@ function buildPanel(message, schema, onChange) {
8334
8353
  chip.type = "button";
8335
8354
  chip.setAttribute("role", "tab");
8336
8355
  chip.textContent = f.header?.trim() || String(i + 1);
8356
+ chip.dir = "auto";
8337
8357
  chip.addEventListener("click", () => {
8338
8358
  show(i);
8339
8359
  f.field.focus();
@@ -8344,7 +8364,9 @@ function buildPanel(message, schema, onChange) {
8344
8364
  f.field.el.setAttribute("aria-labelledby", chip.id);
8345
8365
  chip.setAttribute("aria-controls", f.field.el.id);
8346
8366
  chip.addEventListener("keydown", (e) => {
8347
- const step = e.key === "ArrowRight" ? 1 : e.key === "ArrowLeft" ? -1 : 0;
8367
+ const forward = getComputedStyle(steps).direction === "rtl" ? "ArrowLeft" : "ArrowRight";
8368
+ const back = forward === "ArrowRight" ? "ArrowLeft" : "ArrowRight";
8369
+ const step = e.key === forward ? 1 : e.key === back ? -1 : 0;
8348
8370
  let next = -1;
8349
8371
  if (step) next = (i + step + fields.length) % fields.length;
8350
8372
  else if (e.key === "Home") next = 0;
@@ -8411,7 +8433,7 @@ function buildApprovalPanel(message, options, onChange, details, allowOther = tr
8411
8433
  const body = el("div", "aparte-elic-body");
8412
8434
  panel.appendChild(body);
8413
8435
  const askText = () => typeof message === "function" ? message() : message;
8414
- const ask = askText() ? el("p", "aparte-elic-message", askText()) : null;
8436
+ const ask = askText() ? Object.assign(el("p", "aparte-elic-message", askText()), { dir: "auto" }) : null;
8415
8437
  if (ask) body.appendChild(ask);
8416
8438
  let argsLabel = null;
8417
8439
  if (details) {
@@ -10541,4 +10563,4 @@ export {
10541
10563
  collectRendererStyles as y,
10542
10564
  contentToText as z
10543
10565
  };
10544
- //# sourceMappingURL=defer-hydration-C3Fzto-K.js.map
10566
+ //# sourceMappingURL=defer-hydration-DQKULLmH.js.map