@multiplatform.one/markdown 11.12.2 → 11.13.1

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 (35) hide show
  1. package/dist/cjs/MdxCodeBlock/index.cjs +20 -98
  2. package/dist/cjs/MdxCodeBlock/index.native.cjs +23 -104
  3. package/dist/cjs/MdxCodeBlock/index.native.js +23 -104
  4. package/dist/cjs/MdxCodeBlock/index.native.js.map +1 -1
  5. package/dist/cjs/components/CodeBlock.cjs +4 -25
  6. package/dist/cjs/components/CodeBlock.native.cjs +4 -26
  7. package/dist/cjs/components/CodeBlock.native.js +4 -26
  8. package/dist/cjs/components/CodeBlock.native.js.map +1 -1
  9. package/dist/esm/MdxCodeBlock/index.mjs +23 -101
  10. package/dist/esm/MdxCodeBlock/index.mjs.map +1 -1
  11. package/dist/esm/MdxCodeBlock/index.native.js +26 -107
  12. package/dist/esm/MdxCodeBlock/index.native.js.map +1 -1
  13. package/dist/esm/components/CodeBlock.mjs +5 -26
  14. package/dist/esm/components/CodeBlock.mjs.map +1 -1
  15. package/dist/esm/components/CodeBlock.native.js +5 -27
  16. package/dist/esm/components/CodeBlock.native.js.map +1 -1
  17. package/dist/jsx/MdxCodeBlock/index.mjs +23 -101
  18. package/dist/jsx/MdxCodeBlock/index.mjs.map +1 -1
  19. package/dist/jsx/MdxCodeBlock/index.native.cjs +23 -104
  20. package/dist/jsx/MdxCodeBlock/index.native.js +23 -104
  21. package/dist/jsx/MdxCodeBlock/index.native.js.map +1 -1
  22. package/dist/jsx/components/CodeBlock.mjs +5 -26
  23. package/dist/jsx/components/CodeBlock.mjs.map +1 -1
  24. package/dist/jsx/components/CodeBlock.native.cjs +4 -26
  25. package/dist/jsx/components/CodeBlock.native.js +4 -26
  26. package/dist/jsx/components/CodeBlock.native.js.map +1 -1
  27. package/package.json +10 -10
  28. package/src/MdxCodeBlock/index.tsx +33 -127
  29. package/src/MdxCodeBlock/mdxCodeBlock.spec.tsx +50 -49
  30. package/src/components/CodeBlock.tsx +12 -46
  31. package/src/stories/Code.stories.tsx +2 -1
  32. package/types/MdxCodeBlock/index.d.ts +6 -0
  33. package/types/MdxCodeBlock/index.d.ts.map +1 -1
  34. package/types/components/CodeBlock.d.ts +4 -6
  35. package/types/components/CodeBlock.d.ts.map +1 -1
@@ -28,17 +28,11 @@ var MdxCodeBlock_exports = {};
28
28
  __export(MdxCodeBlock_exports, { MDXCodeBlock: () => MDXCodeBlock });
29
29
  module.exports = __toCommonJS(MdxCodeBlock_exports);
30
30
  var import_components = require("@multiplatform.one/components");
31
- var import_theme = require("@multiplatform.one/theme");
32
- var import_linear_gradient = require("@tamagui/linear-gradient");
33
31
  var import_parse_numeric_range = __toESM(require("parse-numeric-range"));
34
32
  var import_react = require("react");
35
33
  var import_tamagui = require("tamagui");
36
- var import_icons = require("../icons/index.cjs");
37
- var import_cutoffGradient = require("../shared/cutoffGradient.cjs");
38
- var import_tokenPx = require("../shared/tokenPx.cjs");
39
34
  var import_mdxCodeBlockContext = require("./mdxCodeBlockContext.cjs");
40
35
  var import_jsx_runtime = require("react/jsx-runtime");
41
- const zIndex = { localTop: 100 };
42
36
  function extractCodeText(children) {
43
37
  if (typeof children === "string") return children;
44
38
  if (Array.isArray(children)) return children.map(extractCodeText).join("");
@@ -53,108 +47,36 @@ function extractLanguage(className) {
53
47
  return match?.[1] || "text";
54
48
  }
55
49
  function MDXCodeBlock(props) {
56
- const { children, className, copyable, id, isCollapsible, isHighlightingLines, showLineNumbers: propShowLineNumbers, size, line, ...codeProps } = {
50
+ const { children, className, copyable, id, isCollapsible, isHighlightingLines, showLineNumbers, size, line } = {
57
51
  ...(0, import_react.useContext)(import_mdxCodeBlockContext.MDXCodeBlockContext),
58
52
  ...props
59
53
  };
60
- const { knobProps } = (0, import_theme.useResolvedKnobs)();
61
- const gradientColors = (0, import_cutoffGradient.useCutoffGradientColors)();
62
- const cutoffMaxHeight = (0, import_tokenPx.tokenPx)(knobProps.sizeToken, 24) * 16;
63
- const gradientHeight = (0, import_tokenPx.tokenPx)(knobProps.sizeToken, 24) * 8;
64
- const iconPx = (0, import_tokenPx.tokenPx)(knobProps.label.fontSize, 14, "fontSize");
65
54
  const codeText = (0, import_react.useMemo)(() => extractCodeText(children).replace(/\n$/, ""), [children]);
66
55
  const language = (0, import_react.useMemo)(() => extractLanguage(className), [className]);
67
- const tokens = (0, import_components.useShikiTokens)(codeText, language);
68
- const lines = tokens?.length ?? codeText.split("\n").length;
69
- const showLineNumbers = propShowLineNumbers ?? lines > 10;
70
56
  const [isCollapsed, setIsCollapsed] = (0, import_react.useState)(isCollapsible);
71
- const isLong = lines > 22;
72
- const [isCutoff, setIsCutoff] = (0, import_react.useState)(isLong && !isCollapsible);
73
- const { hasCopied, onCopy } = (0, import_components.useClipboard)(codeText);
74
57
  const highlightLines = (0, import_react.useMemo)(() => {
75
58
  if (!isHighlightingLines || !line) return [];
76
59
  return (0, import_parse_numeric_range.default)(line);
77
60
  }, [isHighlightingLines, line]);
78
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tamagui.YStack, {
79
- position: "relative",
61
+ const shown = !isCollapsed || !isCollapsible;
62
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_tamagui.YStack, {
80
63
  marginBottom: "4",
81
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.ErrorBoundary, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_tamagui.YStack, {
82
- position: "relative",
83
- ...isCutoff && {
84
- maxHeight: cutoffMaxHeight,
85
- overflow: "hidden",
86
- ...knobProps.borderRadiusNested
87
- },
88
- children: [
89
- (!isCollapsed || !isCollapsible) && isCutoff && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_linear_gradient.LinearGradient, {
90
- position: "absolute",
91
- bottom: 0,
92
- left: 0,
93
- right: 0,
94
- height: gradientHeight,
95
- colors: gradientColors,
96
- pointerEvents: "none",
97
- zIndex: zIndex.localTop
98
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tamagui.XStack, {
99
- position: "absolute",
100
- bottom: "4",
101
- left: 0,
102
- right: 0,
103
- justifyContent: "center",
104
- zIndex: zIndex.localTop + 1,
105
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Button, {
106
- onPress: () => setIsCutoff(false),
107
- children: "Show more"
108
- })
109
- })] }),
110
- (!isCollapsed || !isCollapsible) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Pre, {
111
- padding: 0,
112
- marginBottom: 0,
113
- id,
114
- "data-line-numbers": showLineNumbers ? "true" : "false",
115
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.ScrollView, {
116
- style: { width: "100%" },
117
- contentContainerStyle: { minWidth: "100%" },
118
- horizontal: true,
119
- showsHorizontalScrollIndicator: false,
120
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Code, {
121
- backgroundColor: "transparent",
122
- flex: 1,
123
- borderWidth: 0,
124
- ...knobProps.panelPadding,
125
- size: size ?? knobProps.sizeToken,
126
- ...codeProps,
127
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.HighlightedCode, {
128
- tokens,
129
- highlightLines,
130
- showLineNumbers,
131
- children: codeText
132
- })
133
- })
134
- })
135
- }),
136
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_tamagui.XStack, {
137
- position: "absolute",
138
- top: "3",
139
- insetInlineEnd: "3",
140
- ...knobProps.gap,
141
- children: [(!isCollapsed || !isCollapsible) && (copyable ?? true) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tamagui.TooltipSimple, {
142
- label: hasCopied ? "Copied" : "Copy to clipboard",
143
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Button, {
144
- "aria-label": "Copy code to clipboard",
145
- size: "2",
146
- display: "max-xs:none",
147
- icon: hasCopied ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.CheckCircleIcon, { size: iconPx }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.ClipboardIcon, { size: iconPx }),
148
- onPress: onCopy
149
- })
150
- }), isCollapsible && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Button, {
151
- "aria-label": "Show or hide code",
152
- size: "2",
153
- onPress: () => setIsCollapsed((x) => !x),
154
- children: isCollapsed ? "Show code" : "Hide code"
155
- })]
156
- })
157
- ]
158
- }) })
64
+ gap: "2",
65
+ id,
66
+ "data-mdx-code-block": "",
67
+ children: [isCollapsible ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tamagui.XStack, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Button, {
68
+ "aria-label": "Show or hide code",
69
+ "aria-expanded": shown,
70
+ size: "2",
71
+ onPress: () => setIsCollapsed((x) => !x),
72
+ children: shown ? "Hide code" : "Show code"
73
+ }) }) : null, shown ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.CodeBlock, {
74
+ language,
75
+ copyable,
76
+ showLineNumbers,
77
+ highlightLines,
78
+ size,
79
+ children: codeText
80
+ }) : null]
159
81
  });
160
82
  }
@@ -31,16 +31,10 @@ __export(MdxCodeBlock_exports, { MDXCodeBlock: () => MDXCodeBlock });
31
31
  module.exports = __toCommonJS(MdxCodeBlock_exports);
32
32
  var import_jsx_runtime = require("react/jsx-runtime");
33
33
  var import_components = require("@multiplatform.one/components");
34
- var import_theme = require("@multiplatform.one/theme");
35
- var import_linear_gradient = require("@tamagui/linear-gradient");
36
34
  var import_parse_numeric_range = __toESM(require("parse-numeric-range"));
37
35
  var import_react = require("react");
38
36
  var import_tamagui = require("tamagui");
39
- var import_icons = require("../icons/index.native.js");
40
- var import_cutoffGradient = require("../shared/cutoffGradient.native.js");
41
- var import_tokenPx = require("../shared/tokenPx.native.js");
42
37
  var import_mdxCodeBlockContext = require("./mdxCodeBlockContext.native.js");
43
- var zIndex = { localTop: 100 };
44
38
  function extractCodeText(children) {
45
39
  if (typeof children === "string") return children;
46
40
  if (Array.isArray(children)) return children.map(extractCodeText).join("");
@@ -56,119 +50,44 @@ function extractLanguage(className) {
56
50
  return (match === null || match === void 0 ? void 0 : match[1]) || "text";
57
51
  }
58
52
  function MDXCodeBlock(props) {
59
- var _ref;
60
- var { children, className, copyable, id, isCollapsible, isHighlightingLines, showLineNumbers: propShowLineNumbers, size, line, ...codeProps } = {
53
+ var { children, className, copyable, id, isCollapsible, isHighlightingLines, showLineNumbers, size, line } = {
61
54
  ...(0, import_react.useContext)(import_mdxCodeBlockContext.MDXCodeBlockContext),
62
55
  ...props
63
56
  };
64
- var { knobProps } = (0, import_theme.useResolvedKnobs)();
65
- var gradientColors = (0, import_cutoffGradient.useCutoffGradientColors)();
66
- var cutoffMaxHeight = (0, import_tokenPx.tokenPx)(knobProps.sizeToken, 24) * 16;
67
- var gradientHeight = (0, import_tokenPx.tokenPx)(knobProps.sizeToken, 24) * 8;
68
- var iconPx = (0, import_tokenPx.tokenPx)(knobProps.label.fontSize, 14, "fontSize");
69
57
  var codeText = (0, import_react.useMemo)(function() {
70
58
  return extractCodeText(children).replace(/\n$/, "");
71
59
  }, [children]);
72
60
  var language = (0, import_react.useMemo)(function() {
73
61
  return extractLanguage(className);
74
62
  }, [className]);
75
- var tokens = (0, import_components.useShikiTokens)(codeText, language);
76
- var lines = (_ref = tokens === null || tokens === void 0 ? void 0 : tokens.length) !== null && _ref !== void 0 ? _ref : codeText.split("\n").length;
77
- var showLineNumbers = propShowLineNumbers !== null && propShowLineNumbers !== void 0 ? propShowLineNumbers : lines > 10;
78
63
  var [isCollapsed, setIsCollapsed] = (0, import_react.useState)(isCollapsible);
79
- var isLong = lines > 22;
80
- var [isCutoff, setIsCutoff] = (0, import_react.useState)(isLong && !isCollapsible);
81
- var { hasCopied, onCopy } = (0, import_components.useClipboard)(codeText);
82
64
  var highlightLines = (0, import_react.useMemo)(function() {
83
65
  if (!isHighlightingLines || !line) return [];
84
66
  return (0, import_parse_numeric_range.default)(line);
85
67
  }, [isHighlightingLines, line]);
86
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tamagui.YStack, {
87
- position: "relative",
68
+ var shown = !isCollapsed || !isCollapsible;
69
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_tamagui.YStack, {
88
70
  marginBottom: "4",
89
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.ErrorBoundary, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_tamagui.YStack, {
90
- position: "relative",
91
- ...isCutoff && {
92
- maxHeight: cutoffMaxHeight,
93
- overflow: "hidden",
94
- ...knobProps.borderRadiusNested
71
+ gap: "2",
72
+ id,
73
+ "data-mdx-code-block": "",
74
+ children: [isCollapsible ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tamagui.XStack, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Button, {
75
+ "aria-label": "Show or hide code",
76
+ "aria-expanded": shown,
77
+ size: "2",
78
+ onPress: function onPress() {
79
+ return setIsCollapsed(function(x) {
80
+ return !x;
81
+ });
95
82
  },
96
- children: [
97
- (!isCollapsed || !isCollapsible) && isCutoff && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_linear_gradient.LinearGradient, {
98
- position: "absolute",
99
- bottom: 0,
100
- left: 0,
101
- right: 0,
102
- height: gradientHeight,
103
- colors: gradientColors,
104
- pointerEvents: "none",
105
- zIndex: zIndex.localTop
106
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tamagui.XStack, {
107
- position: "absolute",
108
- bottom: "4",
109
- left: 0,
110
- right: 0,
111
- justifyContent: "center",
112
- zIndex: zIndex.localTop + 1,
113
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Button, {
114
- onPress: function onPress() {
115
- return setIsCutoff(false);
116
- },
117
- children: "Show more"
118
- })
119
- })] }),
120
- (!isCollapsed || !isCollapsible) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Pre, {
121
- padding: 0,
122
- marginBottom: 0,
123
- id,
124
- "data-line-numbers": showLineNumbers ? "true" : "false",
125
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.ScrollView, {
126
- style: { width: "100%" },
127
- contentContainerStyle: { minWidth: "100%" },
128
- horizontal: true,
129
- showsHorizontalScrollIndicator: false,
130
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Code, {
131
- backgroundColor: "transparent",
132
- flex: 1,
133
- borderWidth: 0,
134
- ...knobProps.panelPadding,
135
- size: size !== null && size !== void 0 ? size : knobProps.sizeToken,
136
- ...codeProps,
137
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.HighlightedCode, {
138
- tokens,
139
- highlightLines,
140
- showLineNumbers,
141
- children: codeText
142
- })
143
- })
144
- })
145
- }),
146
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_tamagui.XStack, {
147
- position: "absolute",
148
- top: "3",
149
- insetInlineEnd: "3",
150
- ...knobProps.gap,
151
- children: [(!isCollapsed || !isCollapsible) && (copyable !== null && copyable !== void 0 ? copyable : true) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tamagui.TooltipSimple, {
152
- label: hasCopied ? "Copied" : "Copy to clipboard",
153
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Button, {
154
- "aria-label": "Copy code to clipboard",
155
- size: "2",
156
- display: "max-xs:none",
157
- icon: hasCopied ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.CheckCircleIcon, { size: iconPx }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.ClipboardIcon, { size: iconPx }),
158
- onPress: onCopy
159
- })
160
- }), isCollapsible && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Button, {
161
- "aria-label": "Show or hide code",
162
- size: "2",
163
- onPress: function onPress() {
164
- return setIsCollapsed(function(x) {
165
- return !x;
166
- });
167
- },
168
- children: isCollapsed ? "Show code" : "Hide code"
169
- })]
170
- })
171
- ]
172
- }) })
83
+ children: shown ? "Hide code" : "Show code"
84
+ }) }) : null, shown ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.CodeBlock, {
85
+ language,
86
+ copyable,
87
+ showLineNumbers,
88
+ highlightLines,
89
+ size,
90
+ children: codeText
91
+ }) : null]
173
92
  });
174
93
  }
@@ -31,16 +31,10 @@ __export(MdxCodeBlock_exports, { MDXCodeBlock: () => MDXCodeBlock });
31
31
  module.exports = __toCommonJS(MdxCodeBlock_exports);
32
32
  var import_jsx_runtime = require("react/jsx-runtime");
33
33
  var import_components = require("@multiplatform.one/components");
34
- var import_theme = require("@multiplatform.one/theme");
35
- var import_linear_gradient = require("@tamagui/linear-gradient");
36
34
  var import_parse_numeric_range = __toESM(require("parse-numeric-range"));
37
35
  var import_react = require("react");
38
36
  var import_tamagui = require("tamagui");
39
- var import_icons = require("../icons/index.native.js");
40
- var import_cutoffGradient = require("../shared/cutoffGradient.native.js");
41
- var import_tokenPx = require("../shared/tokenPx.native.js");
42
37
  var import_mdxCodeBlockContext = require("./mdxCodeBlockContext.native.js");
43
- var zIndex = { localTop: 100 };
44
38
  function extractCodeText(children) {
45
39
  if (typeof children === "string") return children;
46
40
  if (Array.isArray(children)) return children.map(extractCodeText).join("");
@@ -56,120 +50,45 @@ function extractLanguage(className) {
56
50
  return (match === null || match === void 0 ? void 0 : match[1]) || "text";
57
51
  }
58
52
  function MDXCodeBlock(props) {
59
- var _ref;
60
- var { children, className, copyable, id, isCollapsible, isHighlightingLines, showLineNumbers: propShowLineNumbers, size, line, ...codeProps } = {
53
+ var { children, className, copyable, id, isCollapsible, isHighlightingLines, showLineNumbers, size, line } = {
61
54
  ...(0, import_react.useContext)(import_mdxCodeBlockContext.MDXCodeBlockContext),
62
55
  ...props
63
56
  };
64
- var { knobProps } = (0, import_theme.useResolvedKnobs)();
65
- var gradientColors = (0, import_cutoffGradient.useCutoffGradientColors)();
66
- var cutoffMaxHeight = (0, import_tokenPx.tokenPx)(knobProps.sizeToken, 24) * 16;
67
- var gradientHeight = (0, import_tokenPx.tokenPx)(knobProps.sizeToken, 24) * 8;
68
- var iconPx = (0, import_tokenPx.tokenPx)(knobProps.label.fontSize, 14, "fontSize");
69
57
  var codeText = (0, import_react.useMemo)(function() {
70
58
  return extractCodeText(children).replace(/\n$/, "");
71
59
  }, [children]);
72
60
  var language = (0, import_react.useMemo)(function() {
73
61
  return extractLanguage(className);
74
62
  }, [className]);
75
- var tokens = (0, import_components.useShikiTokens)(codeText, language);
76
- var lines = (_ref = tokens === null || tokens === void 0 ? void 0 : tokens.length) !== null && _ref !== void 0 ? _ref : codeText.split("\n").length;
77
- var showLineNumbers = propShowLineNumbers !== null && propShowLineNumbers !== void 0 ? propShowLineNumbers : lines > 10;
78
63
  var [isCollapsed, setIsCollapsed] = (0, import_react.useState)(isCollapsible);
79
- var isLong = lines > 22;
80
- var [isCutoff, setIsCutoff] = (0, import_react.useState)(isLong && !isCollapsible);
81
- var { hasCopied, onCopy } = (0, import_components.useClipboard)(codeText);
82
64
  var highlightLines = (0, import_react.useMemo)(function() {
83
65
  if (!isHighlightingLines || !line) return [];
84
66
  return (0, import_parse_numeric_range.default)(line);
85
67
  }, [isHighlightingLines, line]);
86
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tamagui.YStack, {
87
- position: "relative",
68
+ var shown = !isCollapsed || !isCollapsible;
69
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_tamagui.YStack, {
88
70
  marginBottom: "4",
89
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.ErrorBoundary, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_tamagui.YStack, {
90
- position: "relative",
91
- ...isCutoff && {
92
- maxHeight: cutoffMaxHeight,
93
- overflow: "hidden",
94
- ...knobProps.borderRadiusNested
71
+ gap: "2",
72
+ id,
73
+ "data-mdx-code-block": "",
74
+ children: [isCollapsible ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tamagui.XStack, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Button, {
75
+ "aria-label": "Show or hide code",
76
+ "aria-expanded": shown,
77
+ size: "2",
78
+ onPress: function onPress() {
79
+ return setIsCollapsed(function(x) {
80
+ return !x;
81
+ });
95
82
  },
96
- children: [
97
- (!isCollapsed || !isCollapsible) && isCutoff && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_linear_gradient.LinearGradient, {
98
- position: "absolute",
99
- bottom: 0,
100
- left: 0,
101
- right: 0,
102
- height: gradientHeight,
103
- colors: gradientColors,
104
- pointerEvents: "none",
105
- zIndex: zIndex.localTop
106
- }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tamagui.XStack, {
107
- position: "absolute",
108
- bottom: "4",
109
- left: 0,
110
- right: 0,
111
- justifyContent: "center",
112
- zIndex: zIndex.localTop + 1,
113
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Button, {
114
- onPress: function onPress() {
115
- return setIsCutoff(false);
116
- },
117
- children: "Show more"
118
- })
119
- })] }),
120
- (!isCollapsed || !isCollapsible) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Pre, {
121
- padding: 0,
122
- marginBottom: 0,
123
- id,
124
- "data-line-numbers": showLineNumbers ? "true" : "false",
125
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.ScrollView, {
126
- style: { width: "100%" },
127
- contentContainerStyle: { minWidth: "100%" },
128
- horizontal: true,
129
- showsHorizontalScrollIndicator: false,
130
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Code, {
131
- backgroundColor: "transparent",
132
- flex: 1,
133
- borderWidth: 0,
134
- ...knobProps.panelPadding,
135
- size: size !== null && size !== void 0 ? size : knobProps.sizeToken,
136
- ...codeProps,
137
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.HighlightedCode, {
138
- tokens,
139
- highlightLines,
140
- showLineNumbers,
141
- children: codeText
142
- })
143
- })
144
- })
145
- }),
146
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_tamagui.XStack, {
147
- position: "absolute",
148
- top: "3",
149
- insetInlineEnd: "3",
150
- ...knobProps.gap,
151
- children: [(!isCollapsed || !isCollapsible) && (copyable !== null && copyable !== void 0 ? copyable : true) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tamagui.TooltipSimple, {
152
- label: hasCopied ? "Copied" : "Copy to clipboard",
153
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Button, {
154
- "aria-label": "Copy code to clipboard",
155
- size: "2",
156
- display: "max-xs:none",
157
- icon: hasCopied ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.CheckCircleIcon, { size: iconPx }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.ClipboardIcon, { size: iconPx }),
158
- onPress: onCopy
159
- })
160
- }), isCollapsible && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Button, {
161
- "aria-label": "Show or hide code",
162
- size: "2",
163
- onPress: function onPress() {
164
- return setIsCollapsed(function(x) {
165
- return !x;
166
- });
167
- },
168
- children: isCollapsed ? "Show code" : "Hide code"
169
- })]
170
- })
171
- ]
172
- }) })
83
+ children: shown ? "Hide code" : "Show code"
84
+ }) }) : null, shown ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.CodeBlock, {
85
+ language,
86
+ copyable,
87
+ showLineNumbers,
88
+ highlightLines,
89
+ size,
90
+ children: codeText
91
+ }) : null]
173
92
  });
174
93
  }
175
94
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.native.js","names":[],"sources":["cjs/MdxCodeBlock/index.native.js"],"sourcesContent":["\"use strict\";\nvar __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar MdxCodeBlock_exports = {};\n__export(MdxCodeBlock_exports, {\n MDXCodeBlock: () => MDXCodeBlock\n});\nmodule.exports = __toCommonJS(MdxCodeBlock_exports);\nvar import_jsx_runtime = require(\"react/jsx-runtime\");\nvar import_components = require(\"@multiplatform.one/components\");\nvar import_theme = require(\"@multiplatform.one/theme\");\nvar import_linear_gradient = require(\"@tamagui/linear-gradient\");\nvar import_parse_numeric_range = __toESM(require(\"parse-numeric-range\"));\nvar import_react = require(\"react\");\nvar import_tamagui = require(\"tamagui\");\nvar import_icons = require(\"../icons\");\nvar import_cutoffGradient = require(\"../shared/cutoffGradient\");\nvar import_tokenPx = require(\"../shared/tokenPx\");\nvar import_mdxCodeBlockContext = require(\"./mdxCodeBlockContext\");\nvar zIndex = {\n localTop: 100\n};\nfunction extractCodeText(children) {\n if (typeof children === \"string\") return children;\n if (Array.isArray(children)) return children.map(extractCodeText).join(\"\");\n if (children && typeof children === \"object\" && \"props\" in children) {\n var _children_props;\n return extractCodeText((_children_props = children.props) === null || _children_props === void 0 ? void 0 : _children_props.children);\n }\n return String(children !== null && children !== void 0 ? children : \"\");\n}\nfunction extractLanguage(className) {\n if (!className) return \"text\";\n var match = className.match(/language-(\\w+)/);\n return (match === null || match === void 0 ? void 0 : match[1]) || \"text\";\n}\nfunction MDXCodeBlock(props) {\n var _ref;\n var { children, className, copyable, id, isCollapsible, isHighlightingLines, showLineNumbers: propShowLineNumbers, size, line, ...codeProps } = {\n ...(0, import_react.useContext)(import_mdxCodeBlockContext.MDXCodeBlockContext),\n ...props\n };\n var { knobProps } = (0, import_theme.useResolvedKnobs)();\n var gradientColors = (0, import_cutoffGradient.useCutoffGradientColors)();\n var cutoffMaxHeight = (0, import_tokenPx.tokenPx)(knobProps.sizeToken, 24) * 16;\n var gradientHeight = (0, import_tokenPx.tokenPx)(knobProps.sizeToken, 24) * 8;\n var iconPx = (0, import_tokenPx.tokenPx)(knobProps.label.fontSize, 14, \"fontSize\");\n var codeText = (0, import_react.useMemo)(function() {\n return extractCodeText(children).replace(/\\n$/, \"\");\n }, [\n children\n ]);\n var language = (0, import_react.useMemo)(function() {\n return extractLanguage(className);\n }, [\n className\n ]);\n var tokens = (0, import_components.useShikiTokens)(codeText, language);\n var lines = (_ref = tokens === null || tokens === void 0 ? void 0 : tokens.length) !== null && _ref !== void 0 ? _ref : codeText.split(\"\\n\").length;\n var showLineNumbers = propShowLineNumbers !== null && propShowLineNumbers !== void 0 ? propShowLineNumbers : lines > 10;\n var [isCollapsed, setIsCollapsed] = (0, import_react.useState)(isCollapsible);\n var isLong = lines > 22;\n var [isCutoff, setIsCutoff] = (0, import_react.useState)(isLong && !isCollapsible);\n var { hasCopied, onCopy } = (0, import_components.useClipboard)(codeText);\n var highlightLines = (0, import_react.useMemo)(function() {\n if (!isHighlightingLines || !line) return [];\n return (0, import_parse_numeric_range.default)(line);\n }, [\n isHighlightingLines,\n line\n ]);\n return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tamagui.YStack, {\n position: \"relative\",\n marginBottom: \"4\",\n children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.ErrorBoundary, {\n children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_tamagui.YStack, {\n position: \"relative\",\n ...isCutoff && {\n maxHeight: cutoffMaxHeight,\n overflow: \"hidden\",\n ...knobProps.borderRadiusNested\n },\n children: [\n (!isCollapsed || !isCollapsible) && isCutoff && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {\n children: [\n /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_linear_gradient.LinearGradient, {\n position: \"absolute\",\n bottom: 0,\n left: 0,\n right: 0,\n height: gradientHeight,\n colors: gradientColors,\n pointerEvents: \"none\",\n zIndex: zIndex.localTop\n }),\n /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tamagui.XStack, {\n position: \"absolute\",\n bottom: \"4\",\n left: 0,\n right: 0,\n justifyContent: \"center\",\n zIndex: zIndex.localTop + 1,\n children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Button, {\n onPress: function onPress() {\n return setIsCutoff(false);\n },\n children: \"Show more\"\n })\n })\n ]\n }),\n (!isCollapsed || !isCollapsible) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Pre, {\n padding: 0,\n marginBottom: 0,\n id,\n \"data-line-numbers\": showLineNumbers ? \"true\" : \"false\",\n children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.ScrollView, {\n style: {\n width: \"100%\"\n },\n contentContainerStyle: {\n minWidth: \"100%\"\n },\n horizontal: true,\n showsHorizontalScrollIndicator: false,\n children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Code, {\n backgroundColor: \"transparent\",\n flex: 1,\n borderWidth: 0,\n // SP-PAD + T-VALUE via sizeToken (spec MdxCodeBlock; LC-18):\n // inset is the panelPadding role, content type rides the size\n // token — components-CodeBlock parity. Explicit props eject.\n ...knobProps.panelPadding,\n size: size !== null && size !== void 0 ? size : knobProps.sizeToken,\n ...codeProps,\n children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.HighlightedCode, {\n tokens,\n highlightLines,\n showLineNumbers,\n children: codeText\n })\n })\n })\n }),\n /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_tamagui.XStack, {\n position: \"absolute\",\n top: \"3\",\n insetInlineEnd: \"3\",\n ...knobProps.gap,\n children: [\n (!isCollapsed || !isCollapsible) && (copyable !== null && copyable !== void 0 ? copyable : true) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tamagui.TooltipSimple, {\n label: hasCopied ? \"Copied\" : \"Copy to clipboard\",\n children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Button, {\n \"aria-label\": \"Copy code to clipboard\",\n size: \"2\",\n display: \"max-xs:none\",\n icon: hasCopied ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.CheckCircleIcon, {\n size: iconPx\n }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icons.ClipboardIcon, {\n size: iconPx\n }),\n onPress: onCopy\n })\n }),\n isCollapsible && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Button, {\n \"aria-label\": \"Show or hide code\",\n size: \"2\",\n onPress: function onPress() {\n return setIsCollapsed(function(x) {\n return !x;\n });\n },\n children: isCollapsed ? \"Show code\" : \"Hide code\"\n })\n ]\n })\n ]\n })\n })\n });\n}\n//# sourceMappingURL=index.js.map\n"],"mappings":";;;AACA,IAAI,WAAW,OAAO;AACtB,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO;AAC1B,IAA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,KAAK,IAAI,WAAW,SAAyB,iBAAC,GAAG,mBAAmB,IAAG,CAAE,eAAe,eAAe;MAC5K,OAAO,YAAY,WAAW;MAC9B,UAA0B,iBAAC,GAAG,mBAAmB,IAAG,CAAE,kBAAkB,QAAQ;OAC9E,cAAc;OACd,MAAM;OACN,SAAS;OACT,MAAM,YAA4B,iBAAC,GAAG,mBAAmB,IAAG,CAAE,aAAa,iBAAiB,EAC1F,MAAM,OACR,CAAC,IAAoB,iBAAC,GAAG,mBAAmB,IAAG,CAAE,aAAa,eAAe,EAC3E,MAAM,OACR,CAAC;OACD,SAAS;MACX,CAAC;KACH,CAAC,GACD,iBAAiC,iBAAC,GAAG,mBAAmB,IAAG,CAAE,kBAAkB,QAAQ;MACrF,cAAc;MACd,MAAM;MACN,SAAS,SAAS,UAAU;OAC1B,OAAO,eAAe,SAAS,GAAG;QAChC,OAAO,CAAC;OACV,CAAC;MACH;MACA,UAAU,cAAc,cAAc;KACxC,CAAC,CACH;IACF,CAAC;GACH;EACF,CAAC,EACH,CAAC;CACH,CAAC;AACH"}
1
+ {"version":3,"file":"index.native.js","names":[],"sources":["cjs/MdxCodeBlock/index.native.js"],"sourcesContent":["\"use strict\";\nvar __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar MdxCodeBlock_exports = {};\n__export(MdxCodeBlock_exports, {\n MDXCodeBlock: () => MDXCodeBlock\n});\nmodule.exports = __toCommonJS(MdxCodeBlock_exports);\nvar import_jsx_runtime = require(\"react/jsx-runtime\");\nvar import_components = require(\"@multiplatform.one/components\");\nvar import_parse_numeric_range = __toESM(require(\"parse-numeric-range\"));\nvar import_react = require(\"react\");\nvar import_tamagui = require(\"tamagui\");\nvar import_mdxCodeBlockContext = require(\"./mdxCodeBlockContext\");\nfunction extractCodeText(children) {\n if (typeof children === \"string\") return children;\n if (Array.isArray(children)) return children.map(extractCodeText).join(\"\");\n if (children && typeof children === \"object\" && \"props\" in children) {\n var _children_props;\n return extractCodeText((_children_props = children.props) === null || _children_props === void 0 ? void 0 : _children_props.children);\n }\n return String(children !== null && children !== void 0 ? children : \"\");\n}\nfunction extractLanguage(className) {\n if (!className) return \"text\";\n var match = className.match(/language-(\\w+)/);\n return (match === null || match === void 0 ? void 0 : match[1]) || \"text\";\n}\nfunction MDXCodeBlock(props) {\n var { children, className, copyable, id, isCollapsible, isHighlightingLines, showLineNumbers, size, line } = {\n ...(0, import_react.useContext)(import_mdxCodeBlockContext.MDXCodeBlockContext),\n ...props\n };\n var codeText = (0, import_react.useMemo)(function() {\n return extractCodeText(children).replace(/\\n$/, \"\");\n }, [\n children\n ]);\n var language = (0, import_react.useMemo)(function() {\n return extractLanguage(className);\n }, [\n className\n ]);\n var [isCollapsed, setIsCollapsed] = (0, import_react.useState)(isCollapsible);\n var highlightLines = (0, import_react.useMemo)(function() {\n if (!isHighlightingLines || !line) return [];\n return (0, import_parse_numeric_range.default)(line);\n }, [\n isHighlightingLines,\n line\n ]);\n var shown = !isCollapsed || !isCollapsible;\n return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_tamagui.YStack, {\n marginBottom: \"4\",\n gap: \"2\",\n id,\n \"data-mdx-code-block\": \"\",\n children: [\n isCollapsible ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tamagui.XStack, {\n children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Button, {\n \"aria-label\": \"Show or hide code\",\n \"aria-expanded\": shown,\n size: \"2\",\n onPress: function onPress() {\n return setIsCollapsed(function(x) {\n return !x;\n });\n },\n children: shown ? \"Hide code\" : \"Show code\"\n })\n }) : null,\n shown ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.CodeBlock, {\n language,\n copyable,\n showLineNumbers,\n highlightLines,\n size,\n children: codeText\n }) : null\n ]\n });\n}\n//# sourceMappingURL=index.js.map\n"],"mappings":";;;AACA,IAAI,WAAW,OAAO;AACtB,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO;AAC1B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,YAAY,QAAQ,QAAQ;CAC9B,KAAK,IAAI,QAAQ,KACf,UAAU,QAAQ,MAAM;EAAE,KAAK,IAAI;EAAO,YAAY;CAAK,CAAC;AAChE;AACA,IAAI,eAAe,IAAI,MAAM,QAAQ,SAAS;CAC5C,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,SAAS,YAAY;EAClE,KAAK,IAAI,OAAO,kBAAkB,IAAI,GACpC,IAAI,CAAC,aAAa,KAAK,IAAI,GAAG,KAAK,QAAQ,QACzC,UAAU,IAAI,KAAK;GAAE,WAAW,KAAK;GAAM,YAAY,EAAE,OAAO,iBAAiB,MAAM,GAAG,MAAM,KAAK;EAAW,CAAC;CACvH;CACA,OAAO;AACT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22
22
  __export(CodeBlock_exports, { CodeBlock: () => CodeBlock });
23
23
  module.exports = __toCommonJS(CodeBlock_exports);
24
24
  var import_components = require("@multiplatform.one/components");
25
- var import_theme = require("@multiplatform.one/theme");
26
25
  var import_tamagui = require("tamagui");
27
- var import_colorRamps = require("../shared/colorRamps.cjs");
28
26
  var import_jsx_runtime = require("react/jsx-runtime");
29
27
  function CodeBlock({ children, lang, theme: themeProp = "auto" }) {
30
- const { knobProps } = (0, import_theme.useResolvedKnobs)();
31
- const tokens = (0, import_components.useShikiTokens)(children, lang || "text", themeProp === "auto" ? void 0 : themeProp);
32
28
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tamagui.View, {
33
- ...knobProps.borderRadiusNested ?? { borderRadius: "4" },
34
- backgroundColor: import_colorRamps.markdownCodeColors.background.base,
35
- borderWidth: knobProps.borderRadius.borderWidth,
36
- borderColor: (0, import_theme.edgeColorAt)(import_colorRamps.markdownCodeColors.border.base, knobProps.borderWidthStop),
37
- ...knobProps.panelPadding,
38
29
  marginVertical: "2",
39
- overflow: "hidden",
40
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.ScrollView, {
41
- horizontal: true,
42
- showsHorizontalScrollIndicator: false,
43
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Code, {
44
- backgroundColor: "transparent",
45
- borderWidth: 0,
46
- padding: 0,
47
- color: import_colorRamps.markdownCodeColors.text.base,
48
- fontSize: knobProps.sizeToken,
49
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.HighlightedCode, {
50
- tokens,
51
- fontSize: knobProps.sizeToken,
52
- children
53
- })
54
- })
30
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.CodeBlock, {
31
+ language: lang || "text",
32
+ theme: themeProp === "auto" ? void 0 : themeProp,
33
+ children
55
34
  })
56
35
  });
57
36
  }
@@ -25,37 +25,15 @@ __export(CodeBlock_exports, { CodeBlock: () => CodeBlock });
25
25
  module.exports = __toCommonJS(CodeBlock_exports);
26
26
  var import_jsx_runtime = require("react/jsx-runtime");
27
27
  var import_components = require("@multiplatform.one/components");
28
- var import_theme = require("@multiplatform.one/theme");
29
28
  var import_tamagui = require("tamagui");
30
- var import_colorRamps = require("../shared/colorRamps.native.js");
31
29
  function CodeBlock(param) {
32
30
  var { children, lang, theme: themeProp = "auto" } = param;
33
- var _knobProps_borderRadiusNested;
34
- var { knobProps } = (0, import_theme.useResolvedKnobs)();
35
- var tokens = (0, import_components.useShikiTokens)(children, lang || "text", themeProp === "auto" ? void 0 : themeProp);
36
31
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tamagui.View, {
37
- ...(_knobProps_borderRadiusNested = knobProps.borderRadiusNested) !== null && _knobProps_borderRadiusNested !== void 0 ? _knobProps_borderRadiusNested : { borderRadius: "4" },
38
- backgroundColor: import_colorRamps.markdownCodeColors.background.base,
39
- borderWidth: knobProps.borderRadius.borderWidth,
40
- borderColor: (0, import_theme.edgeColorAt)(import_colorRamps.markdownCodeColors.border.base, knobProps.borderWidthStop),
41
- ...knobProps.panelPadding,
42
32
  marginVertical: "2",
43
- overflow: "hidden",
44
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.ScrollView, {
45
- horizontal: true,
46
- showsHorizontalScrollIndicator: false,
47
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Code, {
48
- backgroundColor: "transparent",
49
- borderWidth: 0,
50
- padding: 0,
51
- color: import_colorRamps.markdownCodeColors.text.base,
52
- fontSize: knobProps.sizeToken,
53
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.HighlightedCode, {
54
- tokens,
55
- fontSize: knobProps.sizeToken,
56
- children
57
- })
58
- })
33
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.CodeBlock, {
34
+ language: lang || "text",
35
+ theme: themeProp === "auto" ? void 0 : themeProp,
36
+ children
59
37
  })
60
38
  });
61
39
  }
@@ -25,37 +25,15 @@ __export(CodeBlock_exports, { CodeBlock: () => CodeBlock });
25
25
  module.exports = __toCommonJS(CodeBlock_exports);
26
26
  var import_jsx_runtime = require("react/jsx-runtime");
27
27
  var import_components = require("@multiplatform.one/components");
28
- var import_theme = require("@multiplatform.one/theme");
29
28
  var import_tamagui = require("tamagui");
30
- var import_colorRamps = require("../shared/colorRamps.native.js");
31
29
  function CodeBlock(param) {
32
30
  var { children, lang, theme: themeProp = "auto" } = param;
33
- var _knobProps_borderRadiusNested;
34
- var { knobProps } = (0, import_theme.useResolvedKnobs)();
35
- var tokens = (0, import_components.useShikiTokens)(children, lang || "text", themeProp === "auto" ? void 0 : themeProp);
36
31
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tamagui.View, {
37
- ...(_knobProps_borderRadiusNested = knobProps.borderRadiusNested) !== null && _knobProps_borderRadiusNested !== void 0 ? _knobProps_borderRadiusNested : { borderRadius: "4" },
38
- backgroundColor: import_colorRamps.markdownCodeColors.background.base,
39
- borderWidth: knobProps.borderRadius.borderWidth,
40
- borderColor: (0, import_theme.edgeColorAt)(import_colorRamps.markdownCodeColors.border.base, knobProps.borderWidthStop),
41
- ...knobProps.panelPadding,
42
32
  marginVertical: "2",
43
- overflow: "hidden",
44
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.ScrollView, {
45
- horizontal: true,
46
- showsHorizontalScrollIndicator: false,
47
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Code, {
48
- backgroundColor: "transparent",
49
- borderWidth: 0,
50
- padding: 0,
51
- color: import_colorRamps.markdownCodeColors.text.base,
52
- fontSize: knobProps.sizeToken,
53
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.HighlightedCode, {
54
- tokens,
55
- fontSize: knobProps.sizeToken,
56
- children
57
- })
58
- })
33
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.CodeBlock, {
34
+ language: lang || "text",
35
+ theme: themeProp === "auto" ? void 0 : themeProp,
36
+ children
59
37
  })
60
38
  });
61
39
  }