@next-library/theme 1.0.9 → 1.0.11

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,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, ChevronDownIcon, CookieIcon, 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
  }
@@ -2617,7 +2616,7 @@ function PageHeader({
2617
2616
  translations: translations2,
2618
2617
  showCopyButton = true
2619
2618
  }) {
2620
- return /* @__PURE__ */ jsxs("div", { className: `flex flex-col gap-2 lg:gap-4 pb-8 font-bold prose prose-md max-w-none dark:prose-invert ${className}`, children: [
2619
+ return /* @__PURE__ */ jsxs("div", { className: `flex flex-col gap-2 lg:gap-4 pb-8 prose prose-md max-w-none dark:prose-invert ${className}`, children: [
2621
2620
  showCopyButton && /* @__PURE__ */ jsx(
2622
2621
  CopyPageButton,
2623
2622
  {
@@ -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) {