@clarify-labs/renderer 0.7.2 → 0.8.2

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.
Files changed (59) hide show
  1. package/output/{ThemeRoot-UWj0iK1X.cjs → ClarifyShell-B74Fq4UU.cjs} +389 -161
  2. package/output/ClarifyShell-B74Fq4UU.cjs.map +1 -0
  3. package/output/{ThemeRoot-QULrwQf6.js → ClarifyShell-BPv2bxI4.js} +361 -157
  4. package/output/ClarifyShell-BPv2bxI4.js.map +1 -0
  5. package/output/{OpenApiOperation-BcyW_ULy.cjs → OpenApiOperation-BMXfV15v.cjs} +209 -7
  6. package/output/OpenApiOperation-BMXfV15v.cjs.map +1 -0
  7. package/output/{OpenApiOperation-tUKf7lZ4.js → OpenApiOperation-fJ3QQOJX.js} +205 -9
  8. package/output/OpenApiOperation-fJ3QQOJX.js.map +1 -0
  9. package/output/{PageActions-yoDRjkq8.js → PageActions-BwY7ierv.js} +55 -81
  10. package/output/PageActions-BwY7ierv.js.map +1 -0
  11. package/output/{PageActions-1RDCHcUY.cjs → PageActions-DOKkt2zo.cjs} +59 -79
  12. package/output/PageActions-DOKkt2zo.cjs.map +1 -0
  13. package/output/app/AppShell.d.ts +2 -3
  14. package/output/app/PageBanner.d.ts +0 -2
  15. package/output/app/PageFooter.d.ts +1 -5
  16. package/output/client.cjs +8 -8
  17. package/output/client.js +3 -3
  18. package/output/components/Code.d.ts +5 -1
  19. package/output/components/Mermaid.d.ts +7 -0
  20. package/output/components/index.d.ts +1 -0
  21. package/output/context.d.ts +1 -1
  22. package/output/core/i18n.d.ts +1 -1
  23. package/output/core/types.d.ts +8 -14
  24. package/output/index.cjs +27 -24
  25. package/output/index.cjs.map +1 -1
  26. package/output/index.d.ts +7 -4
  27. package/output/index.js +14 -14
  28. package/output/index.js.map +1 -1
  29. package/output/mdx/components.d.ts +3 -0
  30. package/output/mdx/primitives.d.ts +1 -0
  31. package/output/preview.cjs +3 -2
  32. package/output/preview.cjs.map +1 -1
  33. package/output/preview.js +3 -2
  34. package/output/preview.js.map +1 -1
  35. package/output/{render-psutGbsg.js → render-Cghgq1AQ.js} +10 -20
  36. package/output/render-Cghgq1AQ.js.map +1 -0
  37. package/output/{render-ByWbJbrA.cjs → render-ZSckbg74.cjs} +10 -20
  38. package/output/render-ZSckbg74.cjs.map +1 -0
  39. package/output/renderer.css +77 -21
  40. package/output/runtime/ClarifyShell.d.ts +22 -0
  41. package/output/server.cjs +10 -19
  42. package/output/server.cjs.map +1 -1
  43. package/output/server.js +10 -19
  44. package/output/server.js.map +1 -1
  45. package/output/shell/search/pagefind.d.ts +0 -1
  46. package/output/slots/RuntimeSlot.d.ts +58 -0
  47. package/output/slots/context.d.ts +20 -0
  48. package/output/slots/index.d.ts +5 -0
  49. package/output/slots/types.d.ts +50 -0
  50. package/output/utils/localized-text.d.ts +7 -0
  51. package/package.json +8 -3
  52. package/output/OpenApiOperation-BcyW_ULy.cjs.map +0 -1
  53. package/output/OpenApiOperation-tUKf7lZ4.js.map +0 -1
  54. package/output/PageActions-1RDCHcUY.cjs.map +0 -1
  55. package/output/PageActions-yoDRjkq8.js.map +0 -1
  56. package/output/ThemeRoot-QULrwQf6.js.map +0 -1
  57. package/output/ThemeRoot-UWj0iK1X.cjs.map +0 -1
  58. package/output/render-ByWbJbrA.cjs.map +0 -1
  59. package/output/render-psutGbsg.js.map +0 -1
@@ -3,7 +3,7 @@ import { Fragment, Suspense, createContext, forwardRef, useContext, useEffect, u
3
3
  import { Link, useLocation, useNavigate } from "react-router-dom";
4
4
  import { CloseButton, Dialog, DialogBackdrop, DialogPanel, Menu, MenuButton, MenuItem, MenuItems, TransitionChild } from "@headlessui/react";
5
5
  import * as LucideIcons from "lucide-react";
6
- import { Check, ChevronDown, Copy, ExternalLink, FileText, Globe2, Link2, LoaderCircle, Menu as Menu$1, Moon, MoreHorizontal, PencilLine, Search, SearchX, Sun, X } from "lucide-react";
6
+ import { Check, ChevronDown, Copy, ExternalLink, FileText, Globe2, Link2, LoaderCircle, Menu as Menu$1, Monitor, Moon, MoreHorizontal, PencilLine, Search, SearchX, Sun, X } from "lucide-react";
7
7
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
8
8
  import { AnimatePresence, motion, useIsPresent, useScroll, useTransform } from "framer-motion";
9
9
  import { create, createStore, useStore } from "zustand";
@@ -114,7 +114,13 @@ var builtInText = {
114
114
  "renderError.type": "Error type",
115
115
  "theme.switchToDark": "Switch to dark theme",
116
116
  "theme.switchToLight": "Switch to light theme",
117
- "language.switch": "Switch language"
117
+ "theme.switchToSystem": "Follow system theme",
118
+ "language.switch": "Switch language",
119
+ "mermaid.zoomIn": "Zoom in",
120
+ "mermaid.zoomOut": "Zoom out",
121
+ "mermaid.resetZoom": "Reset zoom",
122
+ "mermaid.renderError": "Mermaid render error",
123
+ "mermaid.scrollHint": "Click the diagram to enable scroll-to-zoom"
118
124
  },
119
125
  "zh-CN": {
120
126
  "actions.code": "代码",
@@ -205,7 +211,13 @@ var builtInText = {
205
211
  "renderError.type": "错误类型",
206
212
  "theme.switchToDark": "切换到深色主题",
207
213
  "theme.switchToLight": "切换到浅色主题",
208
- "language.switch": "切换语言"
214
+ "theme.switchToSystem": "跟随系统主题",
215
+ "language.switch": "切换语言",
216
+ "mermaid.zoomIn": "放大",
217
+ "mermaid.zoomOut": "缩小",
218
+ "mermaid.resetZoom": "重置缩放",
219
+ "mermaid.renderError": "Mermaid 渲染错误",
220
+ "mermaid.scrollHint": "点击图表后即可滚轮缩放"
209
221
  }
210
222
  };
211
223
  function resolveBuiltInLocale(locale) {
@@ -257,7 +269,8 @@ function hasLocalePrefix(href, config) {
257
269
  }
258
270
  function localizeHref(href, config, locale) {
259
271
  if (!locale || !config.i18n || isExternalHref(href) || href.startsWith("#")) return href;
260
- if (locale === config.i18n.defaultLocale || hasLocalePrefix(href, config)) return href;
272
+ if (hasLocalePrefix(href, config)) return href;
273
+ if (locale === config.i18n.defaultLocale) return href.startsWith("/") ? href : `/${href}`;
261
274
  const cleanHref = href === "/" ? "" : href.replace(/^\/+/, "");
262
275
  return `/${locale}${cleanHref ? `/${cleanHref}` : ""}`;
263
276
  }
@@ -645,21 +658,45 @@ function useTheme() {
645
658
  //#endregion
646
659
  //#region source/theme/ThemeToggle.tsx
647
660
  function ThemeToggle() {
648
- const { resolvedTheme, setTheme } = useTheme();
661
+ const { theme, setTheme } = useTheme();
649
662
  const t = useBuiltInText();
650
- const otherTheme = resolvedTheme === "dark" ? "light" : "dark";
663
+ const nextTheme = getNextTheme(theme);
664
+ const label = getThemeLabel(nextTheme, t);
651
665
  return /* @__PURE__ */ jsxs("button", {
652
666
  type: "button",
653
667
  className: "clarify-theme-toggle relative flex size-8 items-center justify-center rounded-(--clarify-theme-tokens-radius-md) transition hover:bg-(--clarify-ui-hover-background)",
654
- "aria-label": otherTheme === "dark" ? t("theme.switchToDark") : t("theme.switchToLight"),
655
- onClick: () => setTheme(otherTheme),
668
+ "aria-label": label,
669
+ title: label,
670
+ onClick: () => setTheme(nextTheme),
656
671
  children: [
657
672
  /* @__PURE__ */ jsx("span", { className: "absolute size-12 pointer-fine:hidden" }),
658
- /* @__PURE__ */ jsx(Sun, { className: "h-5 w-5 stroke-(--clarify-theme-tokens-colors-foreground) dark:hidden" }),
659
- /* @__PURE__ */ jsx(Moon, { className: "hidden h-5 w-5 stroke-white dark:block" })
673
+ theme === "system" ? /* @__PURE__ */ jsx(Monitor, { className: "h-5 w-5 stroke-(--clarify-theme-tokens-colors-foreground)" }) : null,
674
+ theme === "light" ? /* @__PURE__ */ jsx(Sun, { className: "h-5 w-5 stroke-(--clarify-theme-tokens-colors-foreground)" }) : null,
675
+ theme === "dark" ? /* @__PURE__ */ jsx(Moon, { className: "h-5 w-5 stroke-white" }) : null
660
676
  ]
661
677
  });
662
678
  }
679
+ function getNextTheme(theme) {
680
+ if (theme === "system") return "light";
681
+ if (theme === "light") return "dark";
682
+ return "system";
683
+ }
684
+ function getThemeLabel(theme, t) {
685
+ if (theme === "dark") return t("theme.switchToDark");
686
+ if (theme === "light") return t("theme.switchToLight");
687
+ return t("theme.switchToSystem");
688
+ }
689
+ //#endregion
690
+ //#region source/utils/localized-text.ts
691
+ /**
692
+ * Resolve a localized text value for the given locale.
693
+ * Falls back to the fallback locale, then the first available value,
694
+ * then an empty string.
695
+ */
696
+ function resolveLocalizedText(text, locale, fallbackLocale) {
697
+ if (typeof text === "string") return text;
698
+ return (locale ? text[locale] : void 0) ?? (fallbackLocale ? text[fallbackLocale] : void 0) ?? Object.values(text)[0] ?? "";
699
+ }
663
700
  //#endregion
664
701
  //#region source/utils/path.ts
665
702
  function normalizeRoutePath(path) {
@@ -1038,7 +1075,6 @@ function isActiveTab$1(tab, pathname) {
1038
1075
  function MobileTabsSelect(arg0) {
1039
1076
  const { tabs } = arg0;
1040
1077
  const pathname = normalizeRoutePath(useLocation().pathname);
1041
- const { close } = useMobileNavigationStore();
1042
1078
  if (!tabs?.length) return null;
1043
1079
  const activeTab = tabs.find((tab) => isActiveTab$1(tab, pathname)) ?? tabs[0];
1044
1080
  return /* @__PURE__ */ jsxs(Menu, {
@@ -1062,7 +1098,6 @@ function MobileTabsSelect(arg0) {
1062
1098
  const active = isActiveTab$1(tab, pathname);
1063
1099
  return /* @__PURE__ */ jsx(MenuItem, { children: /* @__PURE__ */ jsxs(Link, {
1064
1100
  to: tab.path,
1065
- onClick: close,
1066
1101
  className: clsx("clarify-mobile-tabs-select-item clarify-ui-menu-item flex items-center justify-between gap-3 rounded-(--clarify-theme-tokens-radius-lg) px-3 py-2.5 no-underline transition", active && "clarify-ui-menu-item-active"),
1067
1102
  "aria-current": active ? "page" : void 0,
1068
1103
  children: [/* @__PURE__ */ jsxs("span", {
@@ -1124,7 +1159,7 @@ function MobileNavigation(arg0) {
1124
1159
  value: true,
1125
1160
  children: [/* @__PURE__ */ jsxs("button", {
1126
1161
  type: "button",
1127
- className: "clarify-mobile-navigation-button clarify-ui-icon-button relative flex size-6 items-center justify-center rounded-(--clarify-theme-tokens-radius-md) transition",
1162
+ className: "clarify-mobile-navigation-button clarify-ui-icon-button relative flex size-8 items-center justify-center rounded-(--clarify-theme-tokens-radius-md) transition",
1128
1163
  "aria-label": t("navigation.toggle"),
1129
1164
  onClick: toggle,
1130
1165
  children: [/* @__PURE__ */ jsx("span", { className: "absolute size-12 pointer-fine:hidden" }), /* @__PURE__ */ jsx(ToggleIcon, { className: "h-4 w-4 stroke-(--clarify-theme-tokens-colors-foreground) dark:stroke-white" })]
@@ -1187,48 +1222,21 @@ var pagefindPromises = /* @__PURE__ */ new Map();
1187
1222
  function pagefindCacheKey(routePrefix, locale) {
1188
1223
  return `${routePrefix || "/"}:${locale || "default"}`;
1189
1224
  }
1190
- function logSearchDebug(message, data) {
1191
- if (typeof window === "undefined") return;
1192
- console.info(`[clarify:search] ${message}`, data ?? "");
1193
- }
1194
1225
  function loadPagefind(routePrefix, locale) {
1195
1226
  if (typeof window === "undefined") return Promise.resolve(null);
1196
1227
  const language = locale ?? document.documentElement.lang;
1197
1228
  const cacheKey = pagefindCacheKey(routePrefix, language);
1198
1229
  const cachedPagefind = pagefindPromises.get(cacheKey);
1199
- if (cachedPagefind) {
1200
- logSearchDebug("reuse Pagefind instance promise", {
1201
- cacheKey,
1202
- language,
1203
- routePrefix
1204
- });
1205
- return cachedPagefind;
1206
- }
1207
- const pagefindUrl = prefixHref("/pagefind/pagefind.js", routePrefix);
1208
- logSearchDebug("create Pagefind instance promise", {
1209
- cacheKey,
1210
- language,
1211
- pagefindUrl,
1212
- routePrefix
1213
- });
1230
+ if (cachedPagefind) return cachedPagefind;
1214
1231
  const pagefindPromise = import(
1215
1232
  /* @vite-ignore */
1216
- pagefindUrl
1233
+ prefixHref("/pagefind/pagefind.js", routePrefix)
1217
1234
  ).then(async (module) => {
1218
1235
  const previousLanguage = document.documentElement.lang;
1219
1236
  if (language) document.documentElement.lang = language;
1220
- logSearchDebug("create Pagefind instance", {
1221
- cacheKey,
1222
- detectedLanguage: document.documentElement.lang,
1223
- previousLanguage
1224
- });
1225
1237
  const pagefind = module.createInstance();
1226
1238
  if (previousLanguage && previousLanguage !== language) document.documentElement.lang = previousLanguage;
1227
1239
  await pagefind.init?.();
1228
- logSearchDebug("Pagefind instance ready", {
1229
- cacheKey,
1230
- language
1231
- });
1232
1240
  return pagefind;
1233
1241
  }).catch((error) => {
1234
1242
  pagefindPromises.delete(cacheKey);
@@ -1405,24 +1413,8 @@ function SearchDialog(arg0) {
1405
1413
  ]);
1406
1414
  useEffect(() => {
1407
1415
  let cancelled = false;
1408
- logSearchDebug("locale or route prefix changed; reload Pagefind", {
1409
- currentLocale,
1410
- routePrefix,
1411
- documentLanguage: document.documentElement.lang
1412
- });
1413
1416
  loadPagefind(routePrefix, currentLocale).then((loadedPagefind) => {
1414
- if (cancelled) {
1415
- logSearchDebug("ignore stale Pagefind load", {
1416
- currentLocale,
1417
- routePrefix
1418
- });
1419
- return;
1420
- }
1421
- logSearchDebug("Pagefind load applied", {
1422
- currentLocale,
1423
- routePrefix,
1424
- available: Boolean(loadedPagefind)
1425
- });
1417
+ if (cancelled) return;
1426
1418
  setPagefindState({
1427
1419
  key: pagefindKey,
1428
1420
  pagefind: loadedPagefind,
@@ -1431,10 +1423,6 @@ function SearchDialog(arg0) {
1431
1423
  });
1432
1424
  return () => {
1433
1425
  cancelled = true;
1434
- logSearchDebug("cancel Pagefind load effect", {
1435
- currentLocale,
1436
- routePrefix
1437
- });
1438
1426
  };
1439
1427
  }, [
1440
1428
  currentLocale,
@@ -1447,22 +1435,12 @@ function SearchDialog(arg0) {
1447
1435
  Promise.resolve().then(async () => {
1448
1436
  if (cancelled) return;
1449
1437
  try {
1450
- logSearchDebug("run Pagefind search", {
1451
- currentLocale,
1452
- query: trimmedQuery,
1453
- routePrefix
1454
- });
1455
1438
  const search = await pagefind.search(trimmedQuery, { limit: 8 });
1456
1439
  const data = await Promise.all(search.results.map(async (result) => ({
1457
1440
  id: result.id,
1458
1441
  data: await result.data()
1459
1442
  })));
1460
1443
  if (cancelled) return;
1461
- logSearchDebug("Pagefind search results", {
1462
- currentLocale,
1463
- query: trimmedQuery,
1464
- count: data.length
1465
- });
1466
1444
  setFullTextState({
1467
1445
  key: fullTextKey,
1468
1446
  results: data.map(({ id, data }) => ({
@@ -1644,7 +1622,7 @@ function MobileSearch(arg0) {
1644
1622
  className: "clarify-mobile-search contents lg:hidden",
1645
1623
  children: [/* @__PURE__ */ jsxs("button", {
1646
1624
  type: "button",
1647
- className: "clarify-mobile-search-button clarify-ui-control relative flex size-6 items-center justify-center rounded-(--clarify-theme-tokens-radius-md) transition lg:hidden",
1625
+ className: "clarify-mobile-search-button clarify-ui-control relative flex size-8 items-center justify-center rounded-(--clarify-theme-tokens-radius-md) transition lg:hidden",
1648
1626
  "aria-label": t("search.placeholder"),
1649
1627
  ...buttonProps,
1650
1628
  children: [/* @__PURE__ */ jsx("span", { className: "absolute size-12 pointer-fine:hidden" }), /* @__PURE__ */ jsx(Search, { className: "h-5 w-5 stroke-(--clarify-theme-tokens-colors-foreground) dark:stroke-white" })]
@@ -1692,10 +1670,6 @@ function SiteLogo(arg0) {
1692
1670
  }
1693
1671
  //#endregion
1694
1672
  //#region source/shell/Header.tsx
1695
- function resolveLocalizedText(text, locale, fallbackLocale) {
1696
- if (typeof text === "string") return text;
1697
- return (locale ? text[locale] : void 0) ?? (fallbackLocale ? text[fallbackLocale] : void 0) ?? Object.values(text)[0] ?? "";
1698
- }
1699
1673
  function localizedRoutePath(config, locale, route) {
1700
1674
  const alternatePath = route?.alternates?.[locale];
1701
1675
  if (alternatePath) return alternatePath;
@@ -1715,7 +1689,7 @@ function LanguageSwitcher(arg0) {
1715
1689
  as: "div",
1716
1690
  className: "clarify-language-switcher relative",
1717
1691
  children: [/* @__PURE__ */ jsxs(MenuButton, {
1718
- className: "clarify-language-switcher-button clarify-ui-control flex h-7 items-center gap-1.5 rounded-(--clarify-theme-tokens-radius-md) px-1.5 transition",
1692
+ className: "clarify-language-switcher-button clarify-ui-control flex h-8 items-center gap-1.5 rounded-(--clarify-theme-tokens-radius-md) px-1.5 transition",
1719
1693
  "aria-label": t("language.switch"),
1720
1694
  children: [
1721
1695
  /* @__PURE__ */ jsx("span", { className: "absolute size-12 pointer-fine:hidden" }),
@@ -1979,6 +1953,6 @@ function PageTitleActions() {
1979
1953
  });
1980
1954
  }
1981
1955
  //#endregion
1982
- export { OpenApisContext as A, isExternalHref as C, useBuiltInText as D, copyTextToClipboard as E, useLocale as M, useOpenApis as N, ConfigContext as O, themeCookieName as S, prefixHref as T, getStoredThemePreference as _, safeDecodeURIComponent as a, storeLocalePreference as b, remToPx as c, isSameRoutePath as d, normalizeRoutePath as f, getStoredLocalePreference as g, useTheme as h, Navigation as i, useConfig as j, LocaleContext as k, lucideIconRegistry as l, ThemeProvider as m, PageTitleActions as n, SectionProvider as o, ThemeToggle as p, Header as r, useSectionStore as s, PageActionsProvider as t, resolveLucideIconName as u, localeCookieName as v, localizeHref as w, storeThemePreference as x, readLocaleCookie as y };
1956
+ export { LocaleContext as A, themeCookieName as C, copyTextToClipboard as D, prefixHref as E, useConfig as M, useLocale as N, useBuiltInText as O, useOpenApis as P, storeThemePreference as S, localizeHref as T, getStoredLocalePreference as _, safeDecodeURIComponent as a, readLocaleCookie as b, remToPx as c, isSameRoutePath as d, normalizeRoutePath as f, useTheme as g, ThemeProvider as h, Navigation as i, OpenApisContext as j, ConfigContext as k, lucideIconRegistry as l, ThemeToggle as m, PageTitleActions as n, SectionProvider as o, resolveLocalizedText as p, Header as r, useSectionStore as s, PageActionsProvider as t, resolveLucideIconName as u, getStoredThemePreference as v, isExternalHref as w, storeLocalePreference as x, localeCookieName as y };
1983
1957
 
1984
- //# sourceMappingURL=PageActions-yoDRjkq8.js.map
1958
+ //# sourceMappingURL=PageActions-BwY7ierv.js.map