@farming-labs/theme 0.1.103 → 0.1.105
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/code-block-spacing.mjs +49 -0
- package/dist/mdx.mjs +5 -2
- package/package.json +2 -2
- package/styles/base.css +26 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as React$1 from "react";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
|
|
4
|
+
//#region src/code-block-spacing.tsx
|
|
5
|
+
const leadingWhitespacePattern = /^[\t ]+/;
|
|
6
|
+
function whitespaceColumnCount(value) {
|
|
7
|
+
let columns = 0;
|
|
8
|
+
for (const char of value) columns += char === " " ? 4 : 1;
|
|
9
|
+
return columns;
|
|
10
|
+
}
|
|
11
|
+
function splitLeadingWhitespace(value, key) {
|
|
12
|
+
const match = value.match(leadingWhitespacePattern);
|
|
13
|
+
if (!match) return value;
|
|
14
|
+
const leadingWhitespace = match[0] ?? "";
|
|
15
|
+
const rest = value.slice(leadingWhitespace.length);
|
|
16
|
+
if (!rest.startsWith("--")) return value;
|
|
17
|
+
const isSingleWordGap = leadingWhitespace === " ";
|
|
18
|
+
return [/* @__PURE__ */ jsx("span", {
|
|
19
|
+
"data-fd-code-space": isSingleWordGap ? "gap" : "indent",
|
|
20
|
+
style: { "--fd-code-space-count": whitespaceColumnCount(leadingWhitespace) },
|
|
21
|
+
children: leadingWhitespace
|
|
22
|
+
}, `${key}-space`), rest];
|
|
23
|
+
}
|
|
24
|
+
function normalizeNode(node, key) {
|
|
25
|
+
if (typeof node === "string") return splitLeadingWhitespace(node, key);
|
|
26
|
+
if (!React$1.isValidElement(node)) return node;
|
|
27
|
+
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}`)));
|
|
30
|
+
}
|
|
31
|
+
function normalizeCodeSpacing(children) {
|
|
32
|
+
return React$1.Children.map(children, (child, index) => normalizeNode(child, `${index}`));
|
|
33
|
+
}
|
|
34
|
+
function createPreWithCodeSpacing(DefaultPre) {
|
|
35
|
+
return function PreWithCodeSpacing(props) {
|
|
36
|
+
const normalizedChildren = normalizeCodeSpacing(props.children);
|
|
37
|
+
if (typeof DefaultPre === "string") return /* @__PURE__ */ jsx("pre", {
|
|
38
|
+
...props,
|
|
39
|
+
children: normalizedChildren
|
|
40
|
+
});
|
|
41
|
+
return /* @__PURE__ */ jsx(DefaultPre, {
|
|
42
|
+
...props,
|
|
43
|
+
children: normalizedChildren
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
export { createPreWithCodeSpacing };
|
package/dist/mdx.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { MDXImg } from "./mdx-img.mjs";
|
|
2
|
+
import { createPreWithCodeSpacing } from "./code-block-spacing.mjs";
|
|
2
3
|
import { createPreWithCopyCallback } from "./code-block-copy-wrapper.mjs";
|
|
3
4
|
import { HoverLink } from "./hover-link.mjs";
|
|
4
5
|
import { extractPromptText } from "./prompt-text.mjs";
|
|
@@ -94,6 +95,8 @@ function getMDXComponents(overrides, options) {
|
|
|
94
95
|
...applyBuiltInComponentDefaults(options),
|
|
95
96
|
...overrides
|
|
96
97
|
};
|
|
98
|
+
const DefaultPre = base.pre;
|
|
99
|
+
if (DefaultPre) base.pre = createPreWithCodeSpacing(DefaultPre);
|
|
97
100
|
if (base.Prompt) {
|
|
98
101
|
const DefaultPrompt = base.Prompt;
|
|
99
102
|
base.Prompt = function PromptWithDocsContext(props) {
|
|
@@ -108,8 +111,8 @@ function getMDXComponents(overrides, options) {
|
|
|
108
111
|
};
|
|
109
112
|
}
|
|
110
113
|
if (options?.onCopyClick) {
|
|
111
|
-
const
|
|
112
|
-
if (
|
|
114
|
+
const CopyPre = base.pre;
|
|
115
|
+
if (CopyPre) base.pre = createPreWithCopyCallback(CopyPre, options.onCopyClick);
|
|
113
116
|
}
|
|
114
117
|
return base;
|
|
115
118
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@farming-labs/theme",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.105",
|
|
4
4
|
"description": "Theme package for @farming-labs/docs — layout, provider, MDX components, and styles",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"docs",
|
|
@@ -139,7 +139,7 @@
|
|
|
139
139
|
"tsdown": "^0.20.3",
|
|
140
140
|
"typescript": "^5.9.3",
|
|
141
141
|
"vitest": "^3.2.4",
|
|
142
|
-
"@farming-labs/docs": "0.1.
|
|
142
|
+
"@farming-labs/docs": "0.1.105"
|
|
143
143
|
},
|
|
144
144
|
"peerDependencies": {
|
|
145
145
|
"@farming-labs/docs": ">=0.0.1",
|
package/styles/base.css
CHANGED
|
@@ -139,12 +139,38 @@ article small,
|
|
|
139
139
|
|
|
140
140
|
figure.shiki pre {
|
|
141
141
|
padding: 0.15rem 0.5rem;
|
|
142
|
+
white-space: pre;
|
|
142
143
|
}
|
|
143
144
|
|
|
144
145
|
figure.shiki pre > code {
|
|
146
|
+
display: block;
|
|
147
|
+
white-space: inherit;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/* Wrapped Shiki lines can use grid rows; unwrapped token spans need inline flow for spaces. */
|
|
151
|
+
figure.shiki pre > code:has(> .line),
|
|
152
|
+
figure.shiki pre > code:has(> [data-line]) {
|
|
145
153
|
display: grid;
|
|
146
154
|
}
|
|
147
155
|
|
|
156
|
+
figure.shiki pre > code > .line,
|
|
157
|
+
figure.shiki pre > code > [data-line] {
|
|
158
|
+
white-space: inherit;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
figure.shiki [data-fd-code-space] {
|
|
162
|
+
display: inline-block;
|
|
163
|
+
white-space: pre;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
figure.shiki [data-fd-code-space="gap"] {
|
|
167
|
+
width: var(--fd-code-token-gap, 1.75ch);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
figure.shiki [data-fd-code-space="indent"] {
|
|
171
|
+
width: calc(var(--fd-code-space-count, 1) * 1ch);
|
|
172
|
+
}
|
|
173
|
+
|
|
148
174
|
figure.shiki pre > code > [data-line] {
|
|
149
175
|
padding: 0 0.25rem;
|
|
150
176
|
}
|