@farming-labs/theme 0.2.124 → 0.2.125

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.
@@ -2,7 +2,7 @@ import * as React$1 from "react";
2
2
  import { jsx } from "react/jsx-runtime";
3
3
 
4
4
  //#region src/code-block-spacing.tsx
5
- const leadingWhitespacePattern = /^[\t ]+/;
5
+ const leadingWhitespacePattern = /^[\t ]+(?=--)/;
6
6
  function whitespaceColumnCount(value) {
7
7
  let columns = 0;
8
8
  for (const char of value) columns += char === " " ? 4 : 1;
@@ -13,7 +13,6 @@ function splitLeadingWhitespace(value, key) {
13
13
  if (!match) return value;
14
14
  const leadingWhitespace = match[0] ?? "";
15
15
  const rest = value.slice(leadingWhitespace.length);
16
- if (!rest.startsWith("--")) return value;
17
16
  const isSingleWordGap = leadingWhitespace === " ";
18
17
  return [/* @__PURE__ */ jsx("span", {
19
18
  "data-fd-code-space": isSingleWordGap ? "gap" : "indent",
@@ -25,11 +24,30 @@ function normalizeNode(node, key) {
25
24
  if (typeof node === "string") return splitLeadingWhitespace(node, key);
26
25
  if (!React$1.isValidElement(node)) return node;
27
26
  const props = node.props;
28
- if (props.children === void 0) return node;
29
- return React$1.cloneElement(node, void 0, React$1.Children.map(props.children, (child, index) => normalizeNode(child, `${key}-${index}`)));
27
+ if (props.children === void 0 || typeof props.children === "string" && !leadingWhitespacePattern.test(props.children)) return node;
28
+ const children = normalizeCodeSpacing(props.children, key);
29
+ if (children === props.children) return node;
30
+ return React$1.cloneElement(node, void 0, children);
30
31
  }
31
- function normalizeCodeSpacing(children) {
32
- return React$1.Children.map(children, (child, index) => normalizeNode(child, `${index}`));
32
+ function canReuseChildren(children) {
33
+ if (Array.isArray(children)) return children.every(canReuseChildren);
34
+ return children === null || typeof children !== "object" || React$1.isValidElement(children);
35
+ }
36
+ function normalizeCodeSpacing(children, key) {
37
+ const childKey = (index) => key === void 0 ? `${index}` : `${key}-${index}`;
38
+ if (typeof children === "string") {
39
+ const next = splitLeadingWhitespace(children, childKey(0));
40
+ return next === children ? children : React$1.Children.map(children, () => next);
41
+ }
42
+ if (!canReuseChildren(children)) return React$1.Children.map(children, (child, index) => normalizeNode(child, childKey(index)));
43
+ let changed = false;
44
+ const normalized = [];
45
+ React$1.Children.forEach(children, (child, index) => {
46
+ const next = normalizeNode(child, childKey(index));
47
+ changed ||= next !== child;
48
+ normalized.push(next);
49
+ });
50
+ return changed ? React$1.Children.map(children, (_, index) => normalized[index]) : children;
33
51
  }
34
52
  function createPreWithCodeSpacing(DefaultPre) {
35
53
  return function PreWithCodeSpacing(props) {
package/dist/docs-api.mjs CHANGED
@@ -958,13 +958,59 @@ function resolveDocsSearchPageSource(dir) {
958
958
  candidate
959
959
  ));
960
960
  }
961
- function hasVisibleDescendantDocsSearchPage(dir) {
961
+ function createDocsSearchScanReader() {
962
+ const directories = /* @__PURE__ */ new Map();
963
+ const stats = /* @__PURE__ */ new Map();
964
+ const documents = /* @__PURE__ */ new Map();
965
+ return {
966
+ visibility: /* @__PURE__ */ new Map(),
967
+ directory(dir) {
968
+ const cached = directories.get(dir);
969
+ if (cached) return cached;
970
+ const entries = fs.readdirSync(
971
+ /* turbopackIgnore: true */
972
+ dir
973
+ ).sort();
974
+ directories.set(dir, entries);
975
+ return entries;
976
+ },
977
+ stat(file) {
978
+ const cached = stats.get(file);
979
+ if (cached) return cached;
980
+ const stat = fs.statSync(
981
+ /* turbopackIgnore: true */
982
+ file
983
+ );
984
+ stats.set(file, stat);
985
+ return stat;
986
+ },
987
+ document(file) {
988
+ const cached = documents.get(file);
989
+ if (cached) return cached;
990
+ const { data, content } = matter(fs.readFileSync(
991
+ /* turbopackIgnore: true */
992
+ file,
993
+ "utf-8"
994
+ ));
995
+ const document = {
996
+ data,
997
+ content
998
+ };
999
+ documents.set(file, document);
1000
+ return document;
1001
+ }
1002
+ };
1003
+ }
1004
+ function hasVisibleDescendantDocsSearchPage(dir, reader = createDocsSearchScanReader()) {
1005
+ const cached = reader.visibility.get(dir);
1006
+ if (cached !== void 0) return cached;
1007
+ const remember = (visible) => {
1008
+ reader.visibility.set(dir, visible);
1009
+ return visible;
1010
+ };
962
1011
  let entries;
963
1012
  try {
964
- entries = fs.readdirSync(
965
- /* turbopackIgnore: true */
966
- dir
967
- );
1013
+ entries = reader.directory(dir);
968
1014
  } catch {
969
1015
  return false;
970
1016
  }
@@ -975,28 +1021,21 @@ function hasVisibleDescendantDocsSearchPage(dir) {
975
1021
  name
976
1022
  );
977
1023
  try {
978
- if (!fs.statSync(
979
- /* turbopackIgnore: true */
980
- full
981
- ).isDirectory()) continue;
1024
+ if (!reader.stat(full).isDirectory()) continue;
982
1025
  } catch {
983
1026
  continue;
984
1027
  }
985
1028
  const pageSource = resolveDocsSearchPageSource(full);
986
1029
  if (pageSource) try {
987
- const data = matter(fs.readFileSync(
988
- /* turbopackIgnore: true */
989
- pageSource,
990
- "utf-8"
991
- )).data;
1030
+ const data = reader.document(pageSource).data;
992
1031
  const hiddenFolderIndex = resolvePageSidebarFolderIndexBehavior(data.sidebar) === "hidden";
993
- if (data.hidden !== true && !hiddenFolderIndex) return true;
1032
+ if (data.hidden !== true && !hiddenFolderIndex) return remember(true);
994
1033
  } catch {
995
- return true;
1034
+ return remember(true);
996
1035
  }
997
- if (hasVisibleDescendantDocsSearchPage(full)) return true;
1036
+ if (hasVisibleDescendantDocsSearchPage(full, reader)) return remember(true);
998
1037
  }
999
- return false;
1038
+ return remember(false);
1000
1039
  }
1001
1040
  function isHiddenFolderIndexPageDir(dir) {
1002
1041
  const pageSource = resolveDocsSearchPageSource(dir);
@@ -1047,6 +1086,7 @@ function normalizeFrontmatterLastmod(value) {
1047
1086
  }
1048
1087
  function scanDocsDir(docsDir, entry, locale, excludedDirs = [], publicPath = `/${normalizePathSegment(entry) || "docs"}`) {
1049
1088
  const indexes = [];
1089
+ const reader = createDocsSearchScanReader();
1050
1090
  function isExcluded(dir) {
1051
1091
  const resolved = path.resolve(
1052
1092
  /* turbopackIgnore: true */
@@ -1065,19 +1105,13 @@ function scanDocsDir(docsDir, entry, locale, excludedDirs = [], publicPath = `/$
1065
1105
  if (isExcluded(dir)) return;
1066
1106
  const pageSource = resolveDocsSearchPageSource(dir);
1067
1107
  if (pageSource) try {
1068
- const raw = fs.readFileSync(
1069
- /* turbopackIgnore: true */
1070
- pageSource,
1071
- "utf-8"
1072
- );
1073
- const { data } = matter(raw);
1074
- if (resolvePageSidebarFolderIndexBehavior(data.sidebar) === "hidden" && hasVisibleDescendantDocsSearchPage(dir)) {} else {
1108
+ const { data, content: fileContent } = reader.document(pageSource);
1109
+ if (resolvePageSidebarFolderIndexBehavior(data.sidebar) === "hidden" && hasVisibleDescendantDocsSearchPage(dir, reader)) {} else {
1075
1110
  const title = data.title || slugParts[slugParts.length - 1]?.replace(/-/g, " ") || "Documentation";
1076
1111
  const description = data.description;
1077
1112
  const framework = typeof data.framework === "string" ? data.framework : void 0;
1078
1113
  const version = typeof data.version === "string" ? data.version : void 0;
1079
1114
  const tags = Array.isArray(data.tags) ? data.tags.filter((value) => typeof value === "string") : void 0;
1080
- const { content: fileContent } = matter(raw);
1081
1115
  const rawContent = resolveDocsAudienceMdxContent(fileContent, "human");
1082
1116
  const agentRawContent = resolveDocsAudienceMdxContent(fileContent, "agent");
1083
1117
  const agentDoc = readAudienceAgentDoc(dir);
@@ -1095,10 +1129,7 @@ function scanDocsDir(docsDir, entry, locale, excludedDirs = [], publicPath = `/$
1095
1129
  url,
1096
1130
  sourcePath: pageSource.replace(/\\/g, "/"),
1097
1131
  lastmod: normalizeFrontmatterLastmod(data.lastmod),
1098
- lastModified: fs.statSync(
1099
- /* turbopackIgnore: true */
1100
- pageSource
1101
- ).mtime.toISOString(),
1132
+ lastModified: reader.stat(pageSource).mtime.toISOString(),
1102
1133
  locale,
1103
1134
  framework,
1104
1135
  version,
@@ -1109,10 +1140,7 @@ function scanDocsDir(docsDir, entry, locale, excludedDirs = [], publicPath = `/$
1109
1140
  } catch {}
1110
1141
  let entries;
1111
1142
  try {
1112
- entries = fs.readdirSync(
1113
- /* turbopackIgnore: true */
1114
- dir
1115
- );
1143
+ entries = reader.directory(dir);
1116
1144
  } catch {
1117
1145
  return;
1118
1146
  }
@@ -1123,10 +1151,7 @@ function scanDocsDir(docsDir, entry, locale, excludedDirs = [], publicPath = `/$
1123
1151
  name
1124
1152
  );
1125
1153
  try {
1126
- if (fs.statSync(
1127
- /* turbopackIgnore: true */
1128
- full
1129
- ).isDirectory()) scan(full, [...slugParts, name]);
1154
+ if (reader.stat(full).isDirectory()) scan(full, [...slugParts, name]);
1130
1155
  } catch {}
1131
1156
  }
1132
1157
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farming-labs/theme",
3
- "version": "0.2.124",
3
+ "version": "0.2.125",
4
4
  "description": "Theme package for @farming-labs/docs — layout, provider, MDX components, and styles",
5
5
  "keywords": [
6
6
  "docs",
@@ -161,7 +161,7 @@
161
161
  "tsdown": "^0.20.3",
162
162
  "typescript": "^5.9.3",
163
163
  "vitest": "^4.1.8",
164
- "@farming-labs/docs": "0.2.124"
164
+ "@farming-labs/docs": "0.2.125"
165
165
  },
166
166
  "peerDependencies": {
167
167
  "@farming-labs/docs": ">=0.0.1",