@seanyeh77/ui 0.31.0 → 0.32.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
1
  "use client";
2
- import { a as parseDate, c as addMessages, d as unitFor, i as format, l as setLocale, n as fileSize, o as sameDay, r as fmtDate, s as I18N, t as dayAdd, u as tr } from "./format-entry-BohS-vNb.js";
2
+ import { a as parseDate, c as addMessages, d as unitFor, i as format, l as setLocale, n as fileSize, o as sameDay, r as fmtDate, s as I18N, t as dayAdd, u as tr } from "./format-entry-B9oxzJvw.js";
3
3
  import * as React from "react";
4
4
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
5
  import { Tooltip as Tooltip$1 } from "@base-ui/react/tooltip";
@@ -2267,7 +2267,7 @@ function CodeText({ text, refHref, onRef, isRef = isCodeRef, as: Tag = "span", c
2267
2267
  }
2268
2268
  // src/internal/FloatingPanel.tsx
2269
2269
  /** A positioned panel next to its trigger: flips when there is no room, closes on Esc and outside press, returns focus. */
2270
- function FloatingPanel({ open, onOpenChange, trigger, side = "bottom", align = "start", sideOffset = 6, className, openOnHover, anchor, boundary, children, ...aria }) {
2270
+ function FloatingPanel({ open, onOpenChange, trigger, side = "bottom", align = "start", sideOffset = 6, className, openOnHover, anchor, boundary, delay = 0, id, focusOnOpen = true, children, ...aria }) {
2271
2271
  const within = boundary?.current ?? void 0;
2272
2272
  return /* @__PURE__ */ jsxs(Popover$1.Root, {
2273
2273
  open,
@@ -2275,7 +2275,7 @@ function FloatingPanel({ open, onOpenChange, trigger, side = "bottom", align = "
2275
2275
  children: [/* @__PURE__ */ jsx(Popover$1.Trigger, {
2276
2276
  render: trigger,
2277
2277
  openOnHover,
2278
- delay: 0,
2278
+ delay,
2279
2279
  closeDelay: 150
2280
2280
  }), /* @__PURE__ */ jsx(Popover$1.Portal, { children: /* @__PURE__ */ jsx(Popover$1.Positioner, {
2281
2281
  className: "ui-float",
@@ -2290,13 +2290,197 @@ function FloatingPanel({ open, onOpenChange, trigger, side = "bottom", align = "
2290
2290
  align: "shift"
2291
2291
  } : void 0,
2292
2292
  children: /* @__PURE__ */ jsx(Popover$1.Popup, {
2293
+ id,
2293
2294
  className,
2294
2295
  "aria-label": aria["aria-label"],
2296
+ initialFocus: focusOnOpen ? void 0 : false,
2295
2297
  children
2296
2298
  })
2297
2299
  }) })]
2298
2300
  });
2299
2301
  }
2302
+ /** A word that opens its explanation: a floating card from 600 px, a sheet from the bottom on phones. `icon` adds a small
2303
+ * question mark; `inline` marks the word with a dashed underline and opens on hover or keyboard focus. */
2304
+ function Term({ children, title, text, content, code, action, refHref, onRef, isRef, variant = "icon", openOnFocus = true, tabIndex, className }) {
2305
+ const [open, setOpen] = React.useState(false);
2306
+ const narrow = useNarrow();
2307
+ const inlineV = variant === "inline";
2308
+ const cardId = React.useId();
2309
+ const ref = React.useRef(null);
2310
+ const [inline, setInline] = React.useState(false);
2311
+ React.useLayoutEffect(() => {
2312
+ const par = ref.current?.parentNode;
2313
+ const txt = !!par && Array.from(par.childNodes).some((n) => n.nodeType === 3 && !!n.textContent?.trim());
2314
+ setInline(txt);
2315
+ }, [children]);
2316
+ const block = React.useRef(null);
2317
+ const toggle = (next) => {
2318
+ if (next) {
2319
+ const el = ref.current?.closest(".ui-card, .ui-split-a, .ui-split-b, .ui-shell-main, main") ?? null;
2320
+ block.current = el && el.getBoundingClientRect().width >= 240 ? el : null;
2321
+ }
2322
+ setOpen(next);
2323
+ };
2324
+ const heading = title || (typeof children === "string" ? children : "");
2325
+ const onFocus = (e) => {
2326
+ if (openOnFocus && !narrow && e.currentTarget.matches(":focus-visible")) toggle(true);
2327
+ };
2328
+ const onBlur = (e) => {
2329
+ const to = e.relatedTarget;
2330
+ if (to && (ref.current?.contains(to) || document.getElementById(cardId)?.contains(to))) return;
2331
+ if (!narrow) setOpen(false);
2332
+ };
2333
+ const trigger = inlineV ? /* @__PURE__ */ jsxs("button", {
2334
+ type: "button",
2335
+ ref,
2336
+ className: cx("ui-term", "is-word", open && "is-open", className),
2337
+ tabIndex,
2338
+ "aria-describedby": open && !narrow ? cardId : void 0,
2339
+ onFocus,
2340
+ onBlur,
2341
+ children: [children, /* @__PURE__ */ jsx("span", {
2342
+ className: "ui-visually-hidden",
2343
+ children: tr(",有說明")
2344
+ })]
2345
+ }) : /* @__PURE__ */ jsxs("button", {
2346
+ type: "button",
2347
+ ref,
2348
+ className: cx("ui-term", inline && "is-inline", open && "is-open", className),
2349
+ children: [
2350
+ /* @__PURE__ */ jsx("span", {
2351
+ className: "ui-visually-hidden",
2352
+ children: tr("說明") + " "
2353
+ }),
2354
+ children,
2355
+ /* @__PURE__ */ jsx(Icon, {
2356
+ name: "question",
2357
+ size: 14,
2358
+ className: "ui-term-q"
2359
+ })
2360
+ ]
2361
+ });
2362
+ const body = (Title, Close) => /* @__PURE__ */ jsxs(Fragment, { children: [
2363
+ /* @__PURE__ */ jsxs("div", {
2364
+ className: "ui-term-head",
2365
+ children: [/* @__PURE__ */ jsx(Title, {
2366
+ className: "ui-term-title",
2367
+ children: heading
2368
+ }), /* @__PURE__ */ jsx(Close, {
2369
+ className: "ui-dialog-close ui-term-close",
2370
+ "aria-label": tr("關閉說明"),
2371
+ children: /* @__PURE__ */ jsx(Icon, { name: "x" })
2372
+ })]
2373
+ }),
2374
+ text ? /* @__PURE__ */ jsx(CodeText, {
2375
+ as: "div",
2376
+ className: "ui-term-body",
2377
+ text,
2378
+ refHref,
2379
+ onRef,
2380
+ isRef
2381
+ }) : null,
2382
+ content ? /* @__PURE__ */ jsx("div", {
2383
+ className: "ui-term-body",
2384
+ children: content
2385
+ }) : null,
2386
+ code ? /* @__PURE__ */ jsx("pre", {
2387
+ className: "ui-term-code",
2388
+ children: code
2389
+ }) : null,
2390
+ action ? /* @__PURE__ */ jsx("button", {
2391
+ type: "button",
2392
+ className: "ui-link-btn ui-term-action",
2393
+ onClick: () => {
2394
+ setOpen(false);
2395
+ action.onClick?.();
2396
+ },
2397
+ children: action.label
2398
+ }) : null
2399
+ ] });
2400
+ if (narrow) return /* @__PURE__ */ jsxs(Dialog$1.Root, {
2401
+ open,
2402
+ onOpenChange: setOpen,
2403
+ children: [/* @__PURE__ */ jsx(Dialog$1.Trigger, { render: trigger }), /* @__PURE__ */ jsxs(Dialog$1.Portal, { children: [/* @__PURE__ */ jsx(Dialog$1.Backdrop, { className: "ui-term-backdrop" }), /* @__PURE__ */ jsx(Dialog$1.Popup, {
2404
+ className: "ui-term-sheet",
2405
+ children: body(Dialog$1.Title, Dialog$1.Close)
2406
+ })] })]
2407
+ });
2408
+ return /* @__PURE__ */ jsx(FloatingPanel, {
2409
+ open,
2410
+ onOpenChange: toggle,
2411
+ sideOffset: 8,
2412
+ className: "ui-term-pop",
2413
+ trigger,
2414
+ boundary: block,
2415
+ ...inlineV ? {
2416
+ openOnHover: true,
2417
+ delay: 500,
2418
+ id: cardId,
2419
+ focusOnOpen: false
2420
+ } : {},
2421
+ children: inlineV ? /* @__PURE__ */ jsx("div", {
2422
+ onBlur,
2423
+ children: body(Popover$1.Title, Popover$1.Close)
2424
+ }) : body(Popover$1.Title, Popover$1.Close)
2425
+ });
2426
+ }
2427
+ // src/internal/terms.tsx
2428
+ const esc = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
2429
+ const WORDY = /^[\p{Script=Latin}\p{N}_]$/u;
2430
+ /** One pattern for all the words, longest first, so 「cookie jar」 wins over 「cookie」. */
2431
+ function termPattern(terms) {
2432
+ const list = (terms ?? []).filter((t) => t.term);
2433
+ if (!list.length) return null;
2434
+ const alts = [...list].sort((a, b) => b.term.length - a.term.length).map((t) => {
2435
+ const w = [...t.term];
2436
+ const pre = WORDY.test(w[0]) ? "(?<![\\p{Script=Latin}\\p{N}_])" : "";
2437
+ const post = WORDY.test(w[w.length - 1]) ? "(?![\\p{Script=Latin}\\p{N}_])" : "";
2438
+ return pre + esc(t.term) + post;
2439
+ });
2440
+ return new RegExp(alts.join("|"), "gu");
2441
+ }
2442
+ /** The words in a piece of text. `seen` holds the words already marked in this block; with `first` they are skipped
2443
+ * and the new ones added. */
2444
+ function findTerms(text, terms, re, mark, seen) {
2445
+ const out = [];
2446
+ for (const m of text.matchAll(re)) {
2447
+ const i = terms.findIndex((t) => t.term === m[0]);
2448
+ if (i < 0) continue;
2449
+ if (mark === "first") {
2450
+ if (seen.has(m[0])) continue;
2451
+ seen.add(m[0]);
2452
+ }
2453
+ out.push({
2454
+ from: m.index,
2455
+ to: m.index + m[0].length,
2456
+ i
2457
+ });
2458
+ }
2459
+ return out;
2460
+ }
2461
+ /** The word as an inline Term. */
2462
+ function termNode(t, key, children, extra) {
2463
+ return /* @__PURE__ */ jsx(Term, {
2464
+ variant: "inline",
2465
+ title: t.title,
2466
+ text: t.text,
2467
+ action: t.action,
2468
+ ...extra,
2469
+ children: children ?? t.term
2470
+ }, key);
2471
+ }
2472
+ /** Text with its words as inline Terms; `rest` renders the text between them. */
2473
+ function withTerms(text, hits, terms, key, rest = (s) => s, extra) {
2474
+ const out = [];
2475
+ let at = 0;
2476
+ for (const h of hits) {
2477
+ if (h.from > at) out.push(/* @__PURE__ */ jsx(React.Fragment, { children: rest(text.slice(at, h.from)) }, key()));
2478
+ out.push(termNode(terms[h.i], key(), text.slice(h.from, h.to), extra));
2479
+ at = h.to;
2480
+ }
2481
+ if (at < text.length) out.push(/* @__PURE__ */ jsx(React.Fragment, { children: rest(text.slice(at)) }, key()));
2482
+ return out;
2483
+ }
2300
2484
  // src/components/CodeView/tokens.ts
2301
2485
  const KEYWORDS = {
2302
2486
  c: new Set("auto break case char const continue default do double else enum extern float for goto if inline int long register restrict return short signed sizeof static struct switch typedef union unsigned void volatile while bool true false NULL nullptr class namespace template typename public private protected virtual new delete".split(" ")),
@@ -2487,6 +2671,42 @@ function matchLinks(lines, start, links) {
2487
2671
  for (const list of out.values()) list.sort((a, b) => a.from - b.from);
2488
2672
  return out;
2489
2673
  }
2674
+ /** Each line's words from `terms`: only in comments and strings, never where a name link or a path is. With 'first',
2675
+ * each word once per file, at its first place. */
2676
+ function matchTerms(toks, start, links, terms, mark) {
2677
+ const out = /* @__PURE__ */ new Map();
2678
+ const re = termPattern(terms);
2679
+ if (!re || !terms) return out;
2680
+ const seen = /* @__PURE__ */ new Set();
2681
+ toks.forEach((line, i) => {
2682
+ const n = start + i;
2683
+ const taken = links.get(n) ?? [];
2684
+ let at = 0;
2685
+ for (const [cls, text] of line) {
2686
+ if (cls === "is-comment" || cls === "is-string") {
2687
+ const paths = [...text.matchAll(PATH_IN_CODE)].map((m) => ({
2688
+ from: at + m.index,
2689
+ to: at + m.index + m[0].length
2690
+ }));
2691
+ const free = (from, to) => ![...taken, ...paths].some((h) => h.from < to && from < h.to);
2692
+ const found = findTerms(text, terms, re, "all", /* @__PURE__ */ new Set()).map((w) => ({
2693
+ ...w,
2694
+ from: w.from + at,
2695
+ to: w.to + at
2696
+ })).filter((w) => free(w.from, w.to)).filter((w) => {
2697
+ if (mark === "all") return true;
2698
+ const t = terms[w.i].term;
2699
+ if (seen.has(t)) return false;
2700
+ seen.add(t);
2701
+ return true;
2702
+ });
2703
+ if (found.length) out.set(n, [...out.get(n) ?? [], ...found]);
2704
+ }
2705
+ at += text.length;
2706
+ }
2707
+ });
2708
+ return out;
2709
+ }
2490
2710
  /** What the keys do: a small panel opened from the keyboard button or with ?; nothing on screen until asked. */
2491
2711
  function KeysPanel(p) {
2492
2712
  return /* @__PURE__ */ jsx(FloatingPanel, {
@@ -2504,7 +2724,7 @@ function KeysPanel(p) {
2504
2724
  });
2505
2725
  }
2506
2726
  /** Source with line numbers and an optional target line: soft accent background, long lines wrap, light syntax colors. */
2507
- function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile, title, language, languageLabel, highlight = true, tokenizer = tokenize, refHref, onRef, links, onLink, preview, maxHeight, sections, copy, header = true, lineNumbers = true, onCopy, onCopyError, className, ref }) {
2727
+ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile, title, language, languageLabel, highlight = true, tokenizer = tokenize, refHref, onRef, links, onLink, preview, terms, termsMark = "first", maxHeight, sections, copy, header = true, lineNumbers = true, onCopy, onCopyError, className, ref }) {
2508
2728
  const lines = React.useMemo(() => String(code || "").replace(/\n$/, "").split("\n"), [code]);
2509
2729
  const lang = language || languageOf(file);
2510
2730
  const toks = React.useMemo(() => highlight ? tokenizer(lines, lang) : lines.map((l) => [["", l]]), [
@@ -2518,7 +2738,14 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
2518
2738
  start,
2519
2739
  links
2520
2740
  ]);
2521
- const nav = hits.size > 0;
2741
+ const termHits = React.useMemo(() => matchTerms(toks, start, hits, terms, termsMark), [
2742
+ toks,
2743
+ start,
2744
+ hits,
2745
+ terms,
2746
+ termsMark
2747
+ ]);
2748
+ const nav = hits.size > 0 || termHits.size > 0;
2522
2749
  const [armed, setArmed] = React.useState(false);
2523
2750
  const inside = React.useRef(false);
2524
2751
  React.useEffect(() => {
@@ -2606,10 +2833,24 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
2606
2833
  if (b && el && b.scrollHeight > b.clientHeight) b.scrollTop += el.getBoundingClientRect().top - b.getBoundingClientRect().top - b.clientHeight / 2 + el.offsetHeight / 2;
2607
2834
  }, [ta, code]);
2608
2835
  const digits = String(start + lines.length - 1).length;
2609
- const piece = (cls, text, key, inLink) => cls ? /* @__PURE__ */ jsx("span", {
2610
- className: cls,
2611
- children: !inLink && (refHref || onRef) && (cls === "is-comment" || cls === "is-string") ? withPaths(text, refHref, onRef, nav ? -1 : void 0) : breakable(text)
2612
- }, key) : /* @__PURE__ */ jsx(React.Fragment, { children: breakable(text) }, key);
2836
+ const prose = (cls, text, inLink) => !inLink && (refHref || onRef) && (cls === "is-comment" || cls === "is-string") ? withPaths(text, refHref, onRef, nav ? -1 : void 0) : breakable(text);
2837
+ const piece = (cls, text, key, inLink, at = 0, words) => {
2838
+ const mine = !inLink && terms && words ? words.filter((w) => w.from >= at && w.to <= at + text.length) : [];
2839
+ let k = 0;
2840
+ const kids = mine.length && terms ? withTerms(text, mine.map((w) => ({
2841
+ ...w,
2842
+ from: w.from - at,
2843
+ to: w.to - at
2844
+ })), terms, () => key + "t" + k++, (t) => prose(cls, t, false), {
2845
+ className: "ui-cv-term",
2846
+ tabIndex: -1,
2847
+ openOnFocus: false
2848
+ }) : prose(cls, text, inLink);
2849
+ return cls ? /* @__PURE__ */ jsx("span", {
2850
+ className: cls,
2851
+ children: kids
2852
+ }, key) : /* @__PURE__ */ jsx(React.Fragment, { children: kids }, key);
2853
+ };
2613
2854
  const nameLink = (hit, kids) => {
2614
2855
  const link = links?.[hit.i];
2615
2856
  if (!link) return null;
@@ -2626,8 +2867,15 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
2626
2867
  children: kids
2627
2868
  }, "n" + hit.i);
2628
2869
  };
2629
- const lineContent = (line, lineHits) => {
2630
- if (!lineHits) return line.map(([cls, text], j) => piece(cls, text, String(j), false));
2870
+ const lineContent = (line, lineHits, words) => {
2871
+ if (!lineHits) {
2872
+ let at = 0;
2873
+ return line.map(([cls, text], j) => {
2874
+ const el = piece(cls, text, String(j), false, at, words);
2875
+ at += text.length;
2876
+ return el;
2877
+ });
2878
+ }
2631
2879
  const out = [];
2632
2880
  let group = [];
2633
2881
  let open = null;
@@ -2655,7 +2903,7 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
2655
2903
  group.push(piece(cls, text.slice(k, end - pos), key, true));
2656
2904
  } else {
2657
2905
  flush();
2658
- out.push(piece(cls, text.slice(k, end - pos), key, false));
2906
+ out.push(piece(cls, text.slice(k, end - pos), key, false, at, words));
2659
2907
  }
2660
2908
  k = end - pos;
2661
2909
  }
@@ -2684,7 +2932,7 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
2684
2932
  children: [/* @__PURE__ */ jsx("span", {
2685
2933
  className: "ui-visually-hidden ui-cv-sr",
2686
2934
  children: tr("第 {n} 行", { n }) + indentText(lines[i]) + tr(":")
2687
- }), lineContent(toks[i], hits.get(n))]
2935
+ }), lineContent(toks[i], hits.get(n), termHits.get(n))]
2688
2936
  })]
2689
2937
  }, i));
2690
2938
  }
@@ -2698,7 +2946,7 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
2698
2946
  {
2699
2947
  k: "ArrowLeft ArrowRight",
2700
2948
  label: "←→",
2701
- what: tr("上一個/下一個連結")
2949
+ what: tr(!termHits.size ? "上一個/下一個連結" : hits.size ? "上一個/下一個連結或名詞" : "上一個/下一個名詞")
2702
2950
  },
2703
2951
  {
2704
2952
  k: "Enter",
@@ -2763,9 +3011,10 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
2763
3011
  el.focus();
2764
3012
  };
2765
3013
  if (nav) {
2766
- const stops = [...pre.querySelectorAll(".ui-cv-name, .ui-cv-ref")];
3014
+ const stops = [...pre.querySelectorAll(".ui-cv-name, .ui-cv-ref, .ui-cv-term")];
2767
3015
  const onStop = act ? stops.indexOf(act) : -1;
2768
3016
  if (e.key === "Escape") {
3017
+ if (act?.classList.contains("ui-cv-term") && act.getAttribute("aria-expanded") === "true") return;
2769
3018
  if (pv) setPv(null);
2770
3019
  else if (onStop >= 0) focusLine(curLine ?? void 0);
2771
3020
  else if (curLine) pre.focus();
@@ -5562,100 +5811,6 @@ function FormGrid({ children, className }) {
5562
5811
  children
5563
5812
  });
5564
5813
  }
5565
- // src/components/Term/Term.tsx
5566
- /** A word followed by a small question mark that opens its explanation: a floating card from 600 px, a sheet from the bottom on phones. */
5567
- function Term({ children, title, text, content, code, action, refHref, onRef, isRef, className }) {
5568
- const [open, setOpen] = React.useState(false);
5569
- const narrow = useNarrow();
5570
- const ref = React.useRef(null);
5571
- const [inline, setInline] = React.useState(false);
5572
- React.useLayoutEffect(() => {
5573
- const par = ref.current?.parentNode;
5574
- const txt = !!par && Array.from(par.childNodes).some((n) => n.nodeType === 3 && !!n.textContent?.trim());
5575
- setInline(txt);
5576
- }, [children]);
5577
- const block = React.useRef(null);
5578
- const toggle = (next) => {
5579
- if (next) {
5580
- const el = ref.current?.closest(".ui-card, .ui-split-a, .ui-split-b, .ui-shell-main, main") ?? null;
5581
- block.current = el && el.getBoundingClientRect().width >= 240 ? el : null;
5582
- }
5583
- setOpen(next);
5584
- };
5585
- const heading = title || (typeof children === "string" ? children : "");
5586
- const trigger = /* @__PURE__ */ jsxs("button", {
5587
- type: "button",
5588
- ref,
5589
- className: cx("ui-term", inline && "is-inline", open && "is-open", className),
5590
- children: [
5591
- /* @__PURE__ */ jsx("span", {
5592
- className: "ui-visually-hidden",
5593
- children: tr("說明") + " "
5594
- }),
5595
- children,
5596
- /* @__PURE__ */ jsx(Icon, {
5597
- name: "question",
5598
- size: 14,
5599
- className: "ui-term-q"
5600
- })
5601
- ]
5602
- });
5603
- const body = (Title, Close) => /* @__PURE__ */ jsxs(Fragment, { children: [
5604
- /* @__PURE__ */ jsxs("div", {
5605
- className: "ui-term-head",
5606
- children: [/* @__PURE__ */ jsx(Title, {
5607
- className: "ui-term-title",
5608
- children: heading
5609
- }), /* @__PURE__ */ jsx(Close, {
5610
- className: "ui-dialog-close ui-term-close",
5611
- "aria-label": tr("關閉說明"),
5612
- children: /* @__PURE__ */ jsx(Icon, { name: "x" })
5613
- })]
5614
- }),
5615
- text ? /* @__PURE__ */ jsx(CodeText, {
5616
- as: "div",
5617
- className: "ui-term-body",
5618
- text,
5619
- refHref,
5620
- onRef,
5621
- isRef
5622
- }) : null,
5623
- content ? /* @__PURE__ */ jsx("div", {
5624
- className: "ui-term-body",
5625
- children: content
5626
- }) : null,
5627
- code ? /* @__PURE__ */ jsx("pre", {
5628
- className: "ui-term-code",
5629
- children: code
5630
- }) : null,
5631
- action ? /* @__PURE__ */ jsx("button", {
5632
- type: "button",
5633
- className: "ui-link-btn ui-term-action",
5634
- onClick: () => {
5635
- setOpen(false);
5636
- action.onClick?.();
5637
- },
5638
- children: action.label
5639
- }) : null
5640
- ] });
5641
- if (narrow) return /* @__PURE__ */ jsxs(Dialog$1.Root, {
5642
- open,
5643
- onOpenChange: setOpen,
5644
- children: [/* @__PURE__ */ jsx(Dialog$1.Trigger, { render: trigger }), /* @__PURE__ */ jsxs(Dialog$1.Portal, { children: [/* @__PURE__ */ jsx(Dialog$1.Backdrop, { className: "ui-term-backdrop" }), /* @__PURE__ */ jsx(Dialog$1.Popup, {
5645
- className: "ui-term-sheet",
5646
- children: body(Dialog$1.Title, Dialog$1.Close)
5647
- })] })]
5648
- });
5649
- return /* @__PURE__ */ jsx(FloatingPanel, {
5650
- open,
5651
- onOpenChange: toggle,
5652
- sideOffset: 8,
5653
- className: "ui-term-pop",
5654
- trigger,
5655
- boundary: block,
5656
- children: body(Popover$1.Title, Popover$1.Close)
5657
- });
5658
- }
5659
5814
  // src/components/Graph/Graph.tsx
5660
5815
  /** <defs> with the arrowheads #ui-arrow and #ui-arrow-accent; put it first inside your diagram's <svg>. */
5661
5816
  function GraphDefs() {
@@ -5970,13 +6125,24 @@ const BLOCKED = [
5970
6125
  "data",
5971
6126
  "vbscript"
5972
6127
  ];
6128
+ /** A new block: its own count of marked words. */
6129
+ const block = (c) => ({
6130
+ ...c,
6131
+ seen: /* @__PURE__ */ new Set()
6132
+ });
6133
+ /** No words marked inside (headings, link text, a summary button). */
6134
+ const noTerms = (c) => ({
6135
+ ...c,
6136
+ seen: void 0
6137
+ });
5973
6138
  const CJK = /[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\u3000-\u303f\uff00-\uffef]/u;
5974
6139
  /** Inline Markdown: code spans, links, autolinks, bold, italic, hard breaks; HTML tags dropped, their text kept. */
5975
6140
  function inline(src, c) {
5976
6141
  const out = [];
5977
6142
  let text = "";
5978
6143
  const flush = () => {
5979
- if (text) out.push(text);
6144
+ if (text && c.termRe && c.terms && c.seen) out.push(...withTerms(text, findTerms(text, c.terms, c.termRe, c.termsMark, c.seen), c.terms, c.k));
6145
+ else if (text) out.push(text);
5980
6146
  text = "";
5981
6147
  };
5982
6148
  let i = 0;
@@ -6054,8 +6220,21 @@ function inline(src, c) {
6054
6220
  continue;
6055
6221
  }
6056
6222
  flush();
6223
+ const termId = /^term:(.*)$/i.exec(m.href.trim())?.[1];
6224
+ if (termId !== void 0) {
6225
+ let id = termId;
6226
+ try {
6227
+ id = decodeURIComponent(termId);
6228
+ } catch {}
6229
+ const t = c.terms?.find((x) => x.term === id);
6230
+ devWarn(!t, "Markdown", `[${m.text}](term:${termId}) 找不到 terms 裡 term 為「${id}」的項目,只顯示文字。把它加進 terms,或改 term: 後面的字。`);
6231
+ c.seen?.add(id);
6232
+ out.push(t ? termNode(t, c.k(), inline(m.text, noTerms(c))) : /* @__PURE__ */ jsx(React.Fragment, { children: inline(m.text, noTerms(c)) }, c.k()));
6233
+ i = m.end;
6234
+ continue;
6235
+ }
6057
6236
  const name = /^\s*`([^`]+)`\s*$/.exec(m.text)?.[1];
6058
- out.push(link(m.href, inline(m.text, c), c, name));
6237
+ out.push(link(m.href, inline(m.text, noTerms(c)), c, name));
6059
6238
  i = m.end;
6060
6239
  continue;
6061
6240
  }
@@ -6211,19 +6390,24 @@ const NUM = /^[-+]?(?:NT\$\s?)?[\d,]+(?:\.\d+)?\s?(?:%|[A-Za-z]{1,3}|\p{Script=H
6211
6390
  * tags are dropped and their text kept; links only to http, https, mailto and relative addresses. */
6212
6391
  function Markdown(p) {
6213
6392
  let n = 0;
6393
+ const termsMark = p.termsMark ?? "first";
6394
+ const termRe = React.useMemo(() => termPattern(p.terms), [p.terms]);
6214
6395
  const c = {
6215
6396
  k: () => "m" + n++,
6216
6397
  schemes: p.schemes,
6217
6398
  linkHref: p.linkHref,
6218
6399
  onLink: p.onLink,
6219
6400
  refHref: p.refHref,
6220
- onRef: p.onRef
6401
+ onRef: p.onRef,
6402
+ terms: p.terms,
6403
+ termsMark,
6404
+ termRe
6221
6405
  };
6222
6406
  const src = String(p.children ?? "").replace(/\r\n?/g, "\n");
6223
6407
  const cls = cx("ui-md", p.size === "small" && "is-small", p.className);
6224
6408
  if (p.inline) return /* @__PURE__ */ jsx("span", {
6225
6409
  className: cx(cls, "is-inline"),
6226
- children: inline(src.trim().replace(/\n\s*\n/g, "\n"), c)
6410
+ children: inline(src.trim().replace(/\n\s*\n/g, "\n"), block(c))
6227
6411
  });
6228
6412
  const top = p.topLevel ?? 4;
6229
6413
  const render = (blocks) => blocks.map((b) => {
@@ -6232,13 +6416,13 @@ function Markdown(p) {
6232
6416
  const H = `h${Math.min(6, top + b.level - 1)}`;
6233
6417
  return /* @__PURE__ */ jsx(H, {
6234
6418
  className: "ui-md-h",
6235
- children: inline(b.text, c)
6419
+ children: inline(b.text, noTerms(c))
6236
6420
  }, c.k());
6237
6421
  }
6238
- case "p": return /* @__PURE__ */ jsx("p", { children: inline(b.text, c) }, c.k());
6422
+ case "p": return /* @__PURE__ */ jsx("p", { children: inline(b.text, block(c)) }, c.k());
6239
6423
  case "hr": return /* @__PURE__ */ jsx("hr", {}, c.k());
6240
6424
  case "details": return /* @__PURE__ */ jsx(MdDetails, {
6241
- summary: inline(b.summary, c),
6425
+ summary: inline(b.summary, noTerms(c)),
6242
6426
  children: render(b.blocks)
6243
6427
  }, c.k());
6244
6428
  case "alert": return /* @__PURE__ */ jsx(Alert, {
@@ -6248,7 +6432,7 @@ function Markdown(p) {
6248
6432
  }, c.k());
6249
6433
  case "quote": return /* @__PURE__ */ jsx("blockquote", { children: render(b.blocks) }, c.k());
6250
6434
  case "list": {
6251
- const items = b.items.map((it) => /* @__PURE__ */ jsx("li", { children: it.length === 1 && it[0].t === "p" ? inline(it[0].text, c) : render(it) }, c.k()));
6435
+ const items = b.items.map((it) => /* @__PURE__ */ jsx("li", { children: it.length === 1 && it[0].t === "p" ? inline(it[0].text, block(c)) : render(it) }, c.k()));
6252
6436
  return b.ordered ? /* @__PURE__ */ jsx("ol", {
6253
6437
  start: b.start === 1 ? void 0 : b.start,
6254
6438
  children: items
@@ -6262,7 +6446,9 @@ function Markdown(p) {
6262
6446
  copy: true,
6263
6447
  lineNumbers: false,
6264
6448
  refHref: p.refHref,
6265
- onRef: p.onRef
6449
+ onRef: p.onRef,
6450
+ terms: p.terms,
6451
+ termsMark
6266
6452
  }, c.k());
6267
6453
  case "table": {
6268
6454
  const n = b.head.length;
@@ -6273,9 +6459,9 @@ function Markdown(p) {
6273
6459
  };
6274
6460
  return /* @__PURE__ */ jsx(MdTable, {
6275
6461
  label: b.head.map(plain).join("、"),
6276
- heads: b.head.map((h) => inline(h, c)),
6462
+ heads: b.head.map((h) => inline(h, noTerms(c))),
6277
6463
  headText: b.head.map(plain),
6278
- rows: b.rows.map((r) => Array.from({ length: n }, (_, j) => inline(r[j] ?? "", c))),
6464
+ rows: b.rows.map((r) => Array.from({ length: n }, (_, j) => inline(r[j] ?? "", block(c)))),
6279
6465
  numeric,
6280
6466
  align
6281
6467
  }, c.k());