@next-library/theme 1.0.10 → 1.0.12

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.
@@ -1 +1 @@
1
- {"version":3,"file":"copy-page-button.d.ts","sourceRoot":"","sources":["../../../src/components/markdown/copy-page-button.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAyCjD,UAAU,0BAA0B;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,UAAU,mBAAmB;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,0BAA0B,CAAC;CAC3C;AAED,wBAAgB,cAAc,CAAC,EAC7B,UAAU,EACV,OAAO,EACP,YAAY,EACZ,SAAS,EACT,MAAa,EACb,YAAiB,GAClB,EAAE,mBAAmB,2CAmIrB"}
1
+ {"version":3,"file":"copy-page-button.d.ts","sourceRoot":"","sources":["../../../src/components/markdown/copy-page-button.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAyCjD,UAAU,0BAA0B;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,UAAU,mBAAmB;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,0BAA0B,CAAC;CAC3C;AAED,wBAAgB,cAAc,CAAC,EAC7B,UAAU,EACV,OAAO,EACP,YAAY,EACZ,SAAS,EACT,MAAa,EACb,YAAiB,GAClB,EAAE,mBAAmB,2CAkHrB"}
@@ -1,6 +1,16 @@
1
1
  interface GithubStarProps {
2
2
  repoUrl?: string;
3
3
  }
4
+ /** `https://github.com/owner/repo[/...]` -> `owner/repo`, or null. */
5
+ export declare function parseGithubRepo(repoUrl: string): string | null;
6
+ /** 1234 -> "1.2k", 999 -> "999". */
7
+ export declare function formatStarCount(count: number): string;
8
+ /**
9
+ * "Star on GitHub" control for the navbar, styled like the other navbar
10
+ * controls (32px tall, bordered, design tokens) instead of GitHub's embedded
11
+ * iframe button, which was 20px tall, used GitHub's own typography and never
12
+ * lined up with its neighbours. The star count is fetched once per session.
13
+ */
4
14
  export declare function GithubStar({ repoUrl }: GithubStarProps): import("react/jsx-runtime").JSX.Element | null;
5
15
  export {};
6
16
  //# sourceMappingURL=github-star.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"github-star.d.ts","sourceRoot":"","sources":["../../../../src/components/navigation/navbar/github-star.tsx"],"names":[],"mappings":"AAMA,UAAU,eAAe;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,UAAU,CAAC,EAAE,OAAO,EAAE,EAAE,eAAe,kDA2CtD"}
1
+ {"version":3,"file":"github-star.d.ts","sourceRoot":"","sources":["../../../../src/components/navigation/navbar/github-star.tsx"],"names":[],"mappings":"AAKA,UAAU,eAAe;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAKD,sEAAsE;AACtE,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAI9D;AAED,oCAAoC;AACpC,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAIrD;AAqBD;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,EAAE,OAAO,EAAE,EAAE,eAAe,kDAsDtD"}
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ import Link2 from 'next/link';
8
8
  import Image from 'next/image';
9
9
  import { clsx } from 'clsx';
10
10
  import { twMerge } from 'tailwind-merge';
11
- import { ArrowLeft, ArrowRight, Pencil, AlertTriangle, Search, Loader2, ArrowUp, ArrowDown, CornerDownLeft, CheckIcon, CircleIcon, ChevronRightIcon, LanguagesIcon, XIcon, PanelLeftIcon, FolderOpenIcon, FolderClosedIcon, ChevronRight, ChevronDown, FileTextIcon, Menu, GithubIcon, MoreHorizontal, Home, ExternalLinkIcon, CopyIcon, ChevronDownIcon, CookieIcon, ChevronUpIcon, FolderUp, ChevronLeft, Check, Copy } from 'lucide-react';
11
+ import { ArrowLeft, ArrowRight, Pencil, AlertTriangle, Search, Loader2, ArrowUp, ArrowDown, CornerDownLeft, CheckIcon, CircleIcon, ChevronRightIcon, LanguagesIcon, XIcon, PanelLeftIcon, FolderOpenIcon, FolderClosedIcon, ChevronRight, ChevronDown, FileTextIcon, Menu, Star, GithubIcon, MoreHorizontal, Home, ExternalLinkIcon, CopyIcon, CookieIcon, ChevronDownIcon, ChevronUpIcon, FolderUp, ChevronLeft, Check, Copy } from 'lucide-react';
12
12
  import { useScroll, useMotionValueEvent, motion } from 'motion/react';
13
13
  import { createPortal } from 'react-dom';
14
14
  import { useRouter } from 'next/navigation';
@@ -22,7 +22,6 @@ import * as SeparatorPrimitive from '@radix-ui/react-separator';
22
22
  import * as SheetPrimitive from '@radix-ui/react-dialog';
23
23
  import * as TooltipPrimitive from '@radix-ui/react-tooltip';
24
24
  import * as CollapsiblePrimitive from '@radix-ui/react-collapsible';
25
- import GitHubButton from 'react-github-btn';
26
25
  import * as AvatarPrimitive from '@radix-ui/react-avatar';
27
26
  import ReactMarkdown from 'react-markdown';
28
27
  import remarkGfm from 'remark-gfm';
@@ -78,7 +77,7 @@ function NavigationBar({
78
77
  /* @__PURE__ */ jsx(LanguageSwitcher, { availableLocales, localeConfigs }),
79
78
  accountSlot,
80
79
  /* @__PURE__ */ jsx(MobileMenu, { pageData }),
81
- /* @__PURE__ */ jsx("div", { className: "h-5 m-auto mx-1 hidden md:flex", children: /* @__PURE__ */ jsx(GithubStar, { repoUrl }) })
80
+ /* @__PURE__ */ jsx("div", { className: "hidden md:flex items-center", children: /* @__PURE__ */ jsx(GithubStar, { repoUrl }) })
82
81
  ] })
83
82
  ] })
84
83
  }
@@ -5127,43 +5126,82 @@ function MobileMenu2({ pageData, translations: translations2 = {} }) {
5127
5126
  ] })
5128
5127
  ] }) });
5129
5128
  }
5129
+ var CACHE_TTL_MS = 60 * 60 * 1e3;
5130
+ function parseGithubRepo(repoUrl) {
5131
+ const match = repoUrl.match(/^https?:\/\/(?:www\.)?github\.com\/([^/\s]+)\/([^/\s#?]+)/i);
5132
+ if (!match) return null;
5133
+ return `${match[1]}/${match[2].replace(/\.git$/, "")}`;
5134
+ }
5135
+ function formatStarCount(count) {
5136
+ if (count < 1e3) return String(count);
5137
+ const k = count / 1e3;
5138
+ return `${k >= 10 ? Math.round(k) : Math.round(k * 10) / 10}k`;
5139
+ }
5140
+ function readCachedCount(repo) {
5141
+ try {
5142
+ const raw = sessionStorage.getItem(`nl-stars:${repo}`);
5143
+ if (!raw) return null;
5144
+ const { count, at } = JSON.parse(raw);
5145
+ return Date.now() - at < CACHE_TTL_MS ? count : null;
5146
+ } catch {
5147
+ return null;
5148
+ }
5149
+ }
5150
+ function writeCachedCount(repo, count) {
5151
+ try {
5152
+ sessionStorage.setItem(`nl-stars:${repo}`, JSON.stringify({ count, at: Date.now() }));
5153
+ } catch {
5154
+ }
5155
+ }
5130
5156
  function GithubStar2({ repoUrl }) {
5131
- const [isVisible, setIsVisible] = useState(false);
5157
+ const repo = repoUrl ? parseGithubRepo(repoUrl) : null;
5158
+ const [count, setCount] = useState(null);
5132
5159
  useEffect(() => {
5133
- const timer = setTimeout(() => {
5134
- setIsVisible(true);
5135
- }, 500);
5136
- return () => clearTimeout(timer);
5137
- }, []);
5160
+ if (!repo) return;
5161
+ const cached = readCachedCount(repo);
5162
+ if (cached !== null) {
5163
+ setCount(cached);
5164
+ return;
5165
+ }
5166
+ const controller = new AbortController();
5167
+ fetch(`https://api.github.com/repos/${repo}`, {
5168
+ signal: controller.signal,
5169
+ headers: { Accept: "application/vnd.github+json" }
5170
+ }).then((res) => res.ok ? res.json() : null).then((data) => {
5171
+ if (data && typeof data.stargazers_count === "number") {
5172
+ writeCachedCount(repo, data.stargazers_count);
5173
+ setCount(data.stargazers_count);
5174
+ }
5175
+ }).catch(() => {
5176
+ });
5177
+ return () => controller.abort();
5178
+ }, [repo]);
5138
5179
  if (!repoUrl) {
5139
5180
  return null;
5140
5181
  }
5141
- return /* @__PURE__ */ jsxs("div", { className: "h-5 relative flex items-center", children: [
5142
- !isVisible && /* @__PURE__ */ jsx(Skeleton, { className: "w-16 h-5 rounded-xs" }),
5143
- /* @__PURE__ */ jsx(
5144
- "div",
5145
- {
5146
- className: isVisible ? "opacity-100" : "opacity-0",
5147
- style: {
5148
- transition: "opacity 0.3s ease-in",
5149
- pointerEvents: isVisible ? "auto" : "none",
5150
- minHeight: "20px"
5151
- // Prevent layout shift
5152
- },
5153
- children: /* @__PURE__ */ jsx(
5154
- GitHubButton,
5182
+ return /* @__PURE__ */ jsxs(
5183
+ "a",
5184
+ {
5185
+ href: repoUrl,
5186
+ target: "_blank",
5187
+ rel: "noopener noreferrer",
5188
+ "aria-label": "Star on GitHub",
5189
+ "data-testid": "github-star-link",
5190
+ className: "ml-1 inline-flex h-8 items-center gap-1.5 rounded-md border px-2.5 text-[13px] font-medium text-foreground transition-colors hover:bg-accent",
5191
+ children: [
5192
+ /* @__PURE__ */ jsx(Star, { className: "size-3.5", "aria-hidden": "true" }),
5193
+ /* @__PURE__ */ jsx("span", { children: "Star" }),
5194
+ count !== null && /* @__PURE__ */ jsx(
5195
+ "span",
5155
5196
  {
5156
- href: repoUrl,
5157
- "data-color-scheme": "no-preference: dark-high-contrast; light: light; dark: dark-high-contrast;",
5158
- "data-icon": "octicon-star",
5159
- "data-show-count": "true",
5160
- "aria-label": "Star on GitHub",
5161
- children: "Star"
5197
+ className: "ml-0.5 border-l pl-2 tabular-nums text-muted-foreground",
5198
+ "data-testid": "github-star-count",
5199
+ children: formatStarCount(count)
5162
5200
  }
5163
5201
  )
5164
- }
5165
- )
5166
- ] });
5202
+ ]
5203
+ }
5204
+ );
5167
5205
  }
5168
5206
  function GithubLink2({ language = "en", repoUrl }) {
5169
5207
  if (!repoUrl) {
@@ -5869,56 +5907,47 @@ function CopyPageButton2({
5869
5907
  const claudeUrl = `https://claude.ai/new?q=${encodedMessage}`;
5870
5908
  window.open(claudeUrl, "_blank", "noopener,noreferrer");
5871
5909
  }
5872
- return /* @__PURE__ */ jsxs(DropdownMenu, { children: [
5873
- /* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(
5874
- Button,
5875
- {
5876
- variant: "outline",
5877
- size: "sm",
5878
- className: cn(
5879
- "flex gap-2 text-sm font-medium items-center",
5880
- isCopied && "opacity-70",
5881
- className
5910
+ const segment = "inline-flex h-8 items-center gap-1.5 whitespace-nowrap px-2.5 text-[13px] font-medium text-foreground transition-colors hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50";
5911
+ return /* @__PURE__ */ jsxs(
5912
+ "div",
5913
+ {
5914
+ role: "group",
5915
+ "aria-label": _askAboutThisPage,
5916
+ className: cn(
5917
+ // Segmented control: one border, dividers between the three actions.
5918
+ "inline-flex items-stretch overflow-hidden rounded-md border bg-card shadow-xs divide-x divide-border",
5919
+ className
5920
+ ),
5921
+ children: [
5922
+ /* @__PURE__ */ jsxs(
5923
+ "button",
5924
+ {
5925
+ type: "button",
5926
+ onClick: handleCopy,
5927
+ title: copyPageDescription,
5928
+ "aria-live": "polite",
5929
+ className: cn(segment, isCopied && "text-muted-foreground"),
5930
+ children: [
5931
+ isCopied ? /* @__PURE__ */ jsx(CheckIcon, { className: "size-3.5", "aria-hidden": true }) : /* @__PURE__ */ jsx(CopyIcon, { className: "size-3.5", "aria-hidden": true }),
5932
+ isCopied ? copied : copyPage
5933
+ ]
5934
+ }
5882
5935
  ),
5883
- children: [
5884
- /* @__PURE__ */ jsx(CopyIcon, { width: "16" }),
5885
- isCopied ? copied : copyPage,
5886
- /* @__PURE__ */ jsx(ChevronDownIcon, { width: "14", className: "opacity-50" })
5887
- ]
5888
- }
5889
- ) }),
5890
- /* @__PURE__ */ jsxs(DropdownMenuContent, { align: "end", className: "min-w-[200px]", children: [
5891
- /* @__PURE__ */ jsxs(DropdownMenuItem, { onClick: handleCopy, children: [
5892
- /* @__PURE__ */ jsx(CopyIcon, { width: "16", className: "mr-2" }),
5893
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
5894
- /* @__PURE__ */ jsx("span", { className: "text-sm font-medium", children: copyPage }),
5895
- /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: copyPageDescription })
5896
- ] })
5897
- ] }),
5898
- pageUrl && /* @__PURE__ */ jsxs(Fragment, { children: [
5899
- /* @__PURE__ */ jsx(DropdownMenuItem, { onClick: handleOpenInChatGPT, children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
5900
- /* @__PURE__ */ jsx(ChatGPTIcon, { className: "w-4 h-4 shrink-0" }),
5901
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col flex-1", children: [
5902
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
5903
- /* @__PURE__ */ jsx("span", { className: "text-sm font-medium", children: openInChatGPT }),
5904
- /* @__PURE__ */ jsx(ExternalLinkIcon, { width: "12", className: "text-muted-foreground shrink-0" })
5905
- ] }),
5906
- /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: askQuestionsDescription })
5907
- ] })
5908
- ] }) }),
5909
- /* @__PURE__ */ jsx(DropdownMenuItem, { onClick: handleOpenInClaude, children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
5910
- /* @__PURE__ */ jsx(ClaudeIcon, { className: "w-4 h-4 shrink-0" }),
5911
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col flex-1", children: [
5912
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
5913
- /* @__PURE__ */ jsx("span", { className: "text-sm font-medium", children: openInClaude }),
5914
- /* @__PURE__ */ jsx(ExternalLinkIcon, { width: "12", className: "text-muted-foreground shrink-0" })
5915
- ] }),
5916
- /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: askQuestionsDescription })
5936
+ pageUrl && /* @__PURE__ */ jsxs(Fragment, { children: [
5937
+ /* @__PURE__ */ jsxs("button", { type: "button", onClick: handleOpenInChatGPT, title: askQuestionsDescription, className: segment, children: [
5938
+ /* @__PURE__ */ jsx(ChatGPTIcon, { className: "size-3.5 shrink-0" }),
5939
+ /* @__PURE__ */ jsx("span", { children: openInChatGPT }),
5940
+ /* @__PURE__ */ jsx(ExternalLinkIcon, { className: "size-3 text-muted-foreground", "aria-hidden": true })
5941
+ ] }),
5942
+ /* @__PURE__ */ jsxs("button", { type: "button", onClick: handleOpenInClaude, title: askQuestionsDescription, className: segment, children: [
5943
+ /* @__PURE__ */ jsx(ClaudeIcon, { className: "size-3.5 shrink-0" }),
5944
+ /* @__PURE__ */ jsx("span", { children: openInClaude }),
5945
+ /* @__PURE__ */ jsx(ExternalLinkIcon, { className: "size-3 text-muted-foreground", "aria-hidden": true })
5917
5946
  ] })
5918
- ] }) })
5919
- ] })
5920
- ] })
5921
- ] });
5947
+ ] })
5948
+ ]
5949
+ }
5950
+ );
5922
5951
  }
5923
5952
  function track(event, data) {
5924
5953
  if (typeof window !== "undefined") {