@traefik-labs/faency 12.1.0 → 12.2.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.
- package/dist/components/Blockquote/Blockquote.vanilla.css.cjs +0 -1
- package/dist/components/Blockquote/Blockquote.vanilla.css.cjs.map +1 -1
- package/dist/components/Blockquote/Blockquote.vanilla.css.js +0 -1
- package/dist/components/Blockquote/Blockquote.vanilla.css.js.map +1 -1
- package/dist/components/CodeBlock/CodeBlock.cjs +114 -44
- package/dist/components/CodeBlock/CodeBlock.cjs.map +1 -1
- package/dist/components/CodeBlock/CodeBlock.js +116 -46
- package/dist/components/CodeBlock/CodeBlock.js.map +1 -1
- package/dist/components/CodeBlock/CodeBlock.themes.cjs +18 -0
- package/dist/components/CodeBlock/CodeBlock.themes.cjs.map +1 -0
- package/dist/components/CodeBlock/CodeBlock.themes.js +19 -0
- package/dist/components/CodeBlock/CodeBlock.themes.js.map +1 -0
- package/dist/components/CodeBlock/CodeBlock.vanilla.cjs +113 -56
- package/dist/components/CodeBlock/CodeBlock.vanilla.cjs.map +1 -1
- package/dist/components/CodeBlock/CodeBlock.vanilla.css.cjs +13 -9
- package/dist/components/CodeBlock/CodeBlock.vanilla.css.cjs.map +1 -1
- package/dist/components/CodeBlock/CodeBlock.vanilla.css.js +14 -10
- package/dist/components/CodeBlock/CodeBlock.vanilla.css.js.map +1 -1
- package/dist/components/CodeBlock/CodeBlock.vanilla.js +116 -59
- package/dist/components/CodeBlock/CodeBlock.vanilla.js.map +1 -1
- package/dist/components/Label/Label.vanilla.css.cjs +1 -0
- package/dist/components/Label/Label.vanilla.css.cjs.map +1 -1
- package/dist/components/Label/Label.vanilla.css.js +1 -0
- package/dist/components/Label/Label.vanilla.css.js.map +1 -1
- package/dist/faency.css +1830 -1801
- package/dist/index.d.ts +104 -6
- package/dist/stitches.config.cjs +4 -0
- package/dist/stitches.config.cjs.map +1 -1
- package/dist/stitches.config.js +19 -15
- package/dist/stitches.config.js.map +1 -1
- package/dist/styles/themes.css.cjs +1 -0
- package/dist/styles/themes.css.cjs.map +1 -1
- package/dist/styles/themes.css.js +1 -0
- package/dist/styles/themes.css.js.map +1 -1
- package/package.json +3 -1
|
@@ -12,12 +12,13 @@ const Button_vanilla = require("../Button/Button.vanilla.cjs");
|
|
|
12
12
|
const AccessibleIcon = require("../AccessibleIcon/AccessibleIcon.cjs");
|
|
13
13
|
const CodeBlockVanilla = React.forwardRef(
|
|
14
14
|
({
|
|
15
|
-
lang,
|
|
15
|
+
lang = "text",
|
|
16
16
|
code,
|
|
17
17
|
copyable = false,
|
|
18
18
|
copyText,
|
|
19
19
|
copiedText,
|
|
20
|
-
copyButtonAlign = "top",
|
|
20
|
+
copyButtonAlign = "top right",
|
|
21
|
+
onCopy,
|
|
21
22
|
noBorder,
|
|
22
23
|
wrapText = false,
|
|
23
24
|
colorScheme,
|
|
@@ -30,72 +31,128 @@ const CodeBlockVanilla = React.forwardRef(
|
|
|
30
31
|
const { colors, resolvedTheme } = themeContext.useVanillaExtractTheme();
|
|
31
32
|
const effectiveScheme = colorScheme ?? resolvedTheme;
|
|
32
33
|
const prismTheme = effectiveScheme === "dark" ? prismReactRenderer.themes.nightOwl : prismReactRenderer.themes.nightOwlLight;
|
|
34
|
+
const isBottom = copyButtonAlign.includes("bottom");
|
|
35
|
+
const isLeft = copyButtonAlign.includes("left");
|
|
33
36
|
const { style: cssStyles, vars } = cssProps.processCSSProp(css, colors);
|
|
34
|
-
const
|
|
37
|
+
const containerStyles = {
|
|
38
|
+
position: "relative",
|
|
39
|
+
...cssStyles,
|
|
40
|
+
...dynamic.assignInlineVars(vars)
|
|
41
|
+
};
|
|
35
42
|
const [copied, setCopied] = React.useState(false);
|
|
43
|
+
const preRef = React.useRef(
|
|
44
|
+
null
|
|
45
|
+
);
|
|
46
|
+
const buttonWrapperRef = React.useRef(null);
|
|
47
|
+
const setPreRef = React.useCallback(
|
|
48
|
+
(node) => {
|
|
49
|
+
preRef.current = node;
|
|
50
|
+
if (typeof ref === "function") ref(node);
|
|
51
|
+
else if (ref) ref.current = node;
|
|
52
|
+
},
|
|
53
|
+
[ref]
|
|
54
|
+
);
|
|
55
|
+
React.useLayoutEffect(() => {
|
|
56
|
+
if (!copyable) return;
|
|
57
|
+
const pre2 = preRef.current;
|
|
58
|
+
const wrapper = buttonWrapperRef.current;
|
|
59
|
+
if (!pre2 || !wrapper) return;
|
|
60
|
+
const borderH = noBorder ? 0 : 2;
|
|
61
|
+
const update = () => {
|
|
62
|
+
if (!isLeft) {
|
|
63
|
+
const vScrollbar = Math.max(0, pre2.offsetWidth - pre2.clientWidth - borderH);
|
|
64
|
+
wrapper.style.right = `${16 + vScrollbar}px`;
|
|
65
|
+
}
|
|
66
|
+
if (isBottom) {
|
|
67
|
+
const hScrollbar = Math.max(0, pre2.offsetHeight - pre2.clientHeight - borderH);
|
|
68
|
+
wrapper.style.bottom = `${8 + hScrollbar}px`;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
update();
|
|
72
|
+
const observer = new ResizeObserver(update);
|
|
73
|
+
observer.observe(pre2);
|
|
74
|
+
return () => observer.disconnect();
|
|
75
|
+
}, [copyable, isBottom, isLeft, noBorder]);
|
|
36
76
|
const handleCopy = async () => {
|
|
37
77
|
try {
|
|
38
78
|
await navigator.clipboard.writeText(code);
|
|
39
79
|
setCopied(true);
|
|
80
|
+
onCopy?.();
|
|
40
81
|
setTimeout(() => setCopied(false), 1500);
|
|
41
82
|
} catch {
|
|
42
83
|
}
|
|
43
84
|
};
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
{
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
85
|
+
const buttonPositionClass = isBottom ? isLeft ? CodeBlock_vanilla_css.copyButtonWrapperBottomLeft : CodeBlock_vanilla_css.copyButtonWrapperBottomRight : isLeft ? CodeBlock_vanilla_css.copyButtonWrapperTopLeft : CodeBlock_vanilla_css.copyButtonWrapperTop;
|
|
86
|
+
const copyButton = copyable ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
87
|
+
Button_vanilla.ButtonVanilla,
|
|
88
|
+
{
|
|
89
|
+
variant: "secondary",
|
|
90
|
+
ghost: true,
|
|
91
|
+
size: "small",
|
|
92
|
+
type: "button",
|
|
93
|
+
onClick: handleCopy,
|
|
94
|
+
css: {
|
|
95
|
+
color: "$hiContrast",
|
|
96
|
+
gap: "$1",
|
|
97
|
+
backgroundColor: "$codeBlockCopyButtonBg",
|
|
98
|
+
height: "32px"
|
|
99
|
+
},
|
|
100
|
+
children: [
|
|
101
|
+
/* @__PURE__ */ jsxRuntime.jsx(AccessibleIcon.AccessibleIcon, { label: copied ? "Copied" : "Copy", children: copied ? /* @__PURE__ */ jsxRuntime.jsx(reactIcons.CheckIcon, {}) : /* @__PURE__ */ jsxRuntime.jsx(reactIcons.CopyIcon, {}) }),
|
|
102
|
+
copied ? copiedText : copyText
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
) : null;
|
|
106
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
107
|
+
prismReactRenderer.Highlight,
|
|
108
|
+
{
|
|
109
|
+
theme: prismTheme,
|
|
110
|
+
code,
|
|
111
|
+
language: prismReactRenderer.Prism.languages[lang] != null ? lang : "text",
|
|
112
|
+
children: ({
|
|
113
|
+
className: highlightClass,
|
|
114
|
+
style: highlightStyle,
|
|
115
|
+
tokens,
|
|
116
|
+
getLineProps,
|
|
117
|
+
getTokenProps
|
|
118
|
+
}) => /* @__PURE__ */ jsxRuntime.jsxs("div", { style: containerStyles, children: [
|
|
119
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
120
|
+
"pre",
|
|
60
121
|
{
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
122
|
+
ref: setPreRef,
|
|
123
|
+
className: [CodeBlock_vanilla_css.pre, noBorder ? CodeBlock_vanilla_css.preNoBorder : "", highlightClass, className].filter(Boolean).join(" "),
|
|
124
|
+
style: {
|
|
125
|
+
maxHeight,
|
|
126
|
+
...highlightStyle,
|
|
127
|
+
backgroundColor: "inherit",
|
|
128
|
+
...style
|
|
129
|
+
},
|
|
130
|
+
...props,
|
|
131
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
132
|
+
"div",
|
|
133
|
+
{
|
|
134
|
+
className: [
|
|
135
|
+
CodeBlock_vanilla_css.codeContent,
|
|
136
|
+
copyable && isLeft && isBottom ? CodeBlock_vanilla_css.codeContentBottomPadding : "",
|
|
137
|
+
copyable && isLeft && !isBottom ? CodeBlock_vanilla_css.codeContentTopPadding : ""
|
|
138
|
+
].filter(Boolean).join(" "),
|
|
139
|
+
children: tokens.map((line, i) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
140
|
+
"div",
|
|
141
|
+
{
|
|
142
|
+
...getLineProps({ line }),
|
|
143
|
+
style: wrapText ? { whiteSpace: "pre-wrap", wordBreak: "break-all" } : void 0,
|
|
144
|
+
children: line.map((token, key) => /* @__PURE__ */ jsxRuntime.jsx("span", { ...getTokenProps({ token }) }, key))
|
|
145
|
+
},
|
|
146
|
+
i
|
|
147
|
+
))
|
|
148
|
+
}
|
|
149
|
+
)
|
|
71
150
|
}
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
{
|
|
78
|
-
ref,
|
|
79
|
-
className: [CodeBlock_vanilla_css.pre, noBorder ? CodeBlock_vanilla_css.preNoBorder : "", highlightClass, className].filter(Boolean).join(" "),
|
|
80
|
-
style: {
|
|
81
|
-
maxHeight,
|
|
82
|
-
...highlightStyle,
|
|
83
|
-
backgroundColor: "transparent",
|
|
84
|
-
...mergedStyles
|
|
85
|
-
},
|
|
86
|
-
...props,
|
|
87
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: CodeBlock_vanilla_css.codeContent, children: tokens.map((line, i) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
88
|
-
"div",
|
|
89
|
-
{
|
|
90
|
-
...getLineProps({ line }),
|
|
91
|
-
style: wrapText ? { whiteSpace: "normal" } : void 0,
|
|
92
|
-
children: line.map((token, key) => /* @__PURE__ */ jsxRuntime.jsx("span", { ...getTokenProps({ token }) }, key))
|
|
93
|
-
},
|
|
94
|
-
i
|
|
95
|
-
)) })
|
|
96
|
-
}
|
|
97
|
-
)
|
|
98
|
-
] }) });
|
|
151
|
+
),
|
|
152
|
+
copyButton && /* @__PURE__ */ jsxRuntime.jsx("div", { ref: buttonWrapperRef, className: buttonPositionClass, children: copyButton })
|
|
153
|
+
] })
|
|
154
|
+
}
|
|
155
|
+
);
|
|
99
156
|
}
|
|
100
157
|
);
|
|
101
158
|
CodeBlockVanilla.displayName = "CodeBlockVanilla";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeBlock.vanilla.cjs","sources":["../../../components/CodeBlock/CodeBlock.vanilla.tsx"],"sourcesContent":["import { CheckIcon, CopyIcon } from '@radix-ui/react-icons';\nimport { assignInlineVars } from '@vanilla-extract/dynamic';\nimport { Highlight, Language, themes } from 'prism-react-renderer';\nimport React, { forwardRef, HTMLAttributes, useState } from 'react';\n\nimport { CSSProps, processCSSProp } from '../../styles/cssProps';\nimport { useVanillaExtractTheme } from '../../styles/themeContext';\nimport { AccessibleIcon } from '../AccessibleIcon';\nimport { ButtonVanilla } from '../Button';\nimport {\n codeContent,\n copyButtonWrapper,\n copyButtonWrapperBottom,\n copyButtonWrapperTop,\n pre,\n preNoBorder,\n wrapper,\n} from './CodeBlock.vanilla.css';\n\nexport interface CodeBlockVanillaProps\n extends Omit<HTMLAttributes<HTMLPreElement>, 'css'>,\n CSSProps {\n lang: Language;\n code: string;\n copyable?: boolean;\n copyText?: string;\n copiedText?: string;\n copyButtonAlign?: 'top' | 'bottom';\n noBorder?: boolean;\n wrapText?: boolean;\n colorScheme?: 'light' | 'dark';\n maxHeight?: number | string;\n}\n\nexport const CodeBlockVanilla = forwardRef<HTMLPreElement, CodeBlockVanillaProps>(\n (\n {\n lang,\n code,\n copyable = false,\n copyText,\n copiedText,\n copyButtonAlign = 'top',\n noBorder,\n wrapText = false,\n colorScheme,\n maxHeight = 424,\n css,\n style,\n className,\n ...props\n },\n ref,\n ) => {\n const { colors, resolvedTheme } = useVanillaExtractTheme();\n const effectiveScheme = colorScheme ?? resolvedTheme;\n const prismTheme = effectiveScheme === 'dark' ? themes.nightOwl : themes.nightOwlLight;\n\n const { style: cssStyles, vars } = processCSSProp(css, colors);\n const mergedStyles = { ...cssStyles, ...style, ...assignInlineVars(vars) };\n\n const [copied, setCopied] = useState(false);\n\n const handleCopy = async () => {\n try {\n await navigator.clipboard.writeText(code);\n setCopied(true);\n setTimeout(() => setCopied(false), 1500);\n } catch {\n // clipboard write failed (e.g. permission denied) — leave UI unchanged\n }\n };\n\n return (\n <Highlight theme={prismTheme} code={code} language={lang}>\n {({\n className: highlightClass,\n style: highlightStyle,\n tokens,\n getLineProps,\n getTokenProps,\n }) => (\n <div className={wrapper}>\n {copyable && (\n <div\n className={[\n copyButtonWrapper,\n copyButtonAlign === 'bottom' ? copyButtonWrapperBottom : copyButtonWrapperTop,\n ].join(' ')}\n >\n <ButtonVanilla\n variant=\"secondary\"\n ghost\n size=\"small\"\n type=\"button\"\n onClick={handleCopy}\n css={{ color: '$hiContrast', gap: '$1' }}\n >\n <AccessibleIcon label={copied ? 'Copied' : 'Copy'}>\n {copied ? <CheckIcon /> : <CopyIcon />}\n </AccessibleIcon>\n {copied ? copiedText : copyText}\n </ButtonVanilla>\n </div>\n )}\n <pre\n ref={ref}\n className={[pre, noBorder ? preNoBorder : '', highlightClass, className]\n .filter(Boolean)\n .join(' ')}\n style={{\n maxHeight,\n ...highlightStyle,\n backgroundColor: 'transparent',\n ...mergedStyles,\n }}\n {...props}\n >\n <div className={codeContent}>\n {tokens.map((line, i) => (\n <div\n key={i}\n {...getLineProps({ line })}\n style={wrapText ? { whiteSpace: 'normal' } : undefined}\n >\n {line.map((token, key) => (\n <span key={key} {...getTokenProps({ token })} />\n ))}\n </div>\n ))}\n </div>\n </pre>\n </div>\n )}\n </Highlight>\n );\n },\n);\n\nCodeBlockVanilla.displayName = 'CodeBlockVanilla';\n"],"names":["forwardRef","useVanillaExtractTheme","themes","processCSSProp","assignInlineVars","useState","Highlight","jsxs","wrapper","jsx","copyButtonWrapper","copyButtonWrapperBottom","copyButtonWrapperTop","ButtonVanilla","AccessibleIcon","CheckIcon","CopyIcon","pre","preNoBorder","codeContent"],"mappings":";;;;;;;;;;;;AAkCO,MAAM,mBAAmBA,MAAAA;AAAAA,EAC9B,CACE;AAAA,IACE;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX;AAAA,IACA;AAAA,IACA,kBAAkB;AAAA,IAClB;AAAA,IACA,WAAW;AAAA,IACX;AAAA,IACA,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,GAEL,QACG;AACH,UAAM,EAAE,QAAQ,cAAA,IAAkBC,oCAAA;AAClC,UAAM,kBAAkB,eAAe;AACvC,UAAM,aAAa,oBAAoB,SAASC,mBAAAA,OAAO,WAAWA,mBAAAA,OAAO;AAEzE,UAAM,EAAE,OAAO,WAAW,SAASC,SAAAA,eAAe,KAAK,MAAM;AAC7D,UAAM,eAAe,EAAE,GAAG,WAAW,GAAG,OAAO,GAAGC,QAAAA,iBAAiB,IAAI,EAAA;AAEvE,UAAM,CAAC,QAAQ,SAAS,IAAIC,MAAAA,SAAS,KAAK;AAE1C,UAAM,aAAa,YAAY;AAC7B,UAAI;AACF,cAAM,UAAU,UAAU,UAAU,IAAI;AACxC,kBAAU,IAAI;AACd,mBAAW,MAAM,UAAU,KA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,sBAAAA,aACb,iBAAO,IAAI,CAAC,MAAM,MACjBV,2BAAAA;AAAAA,YAAC;AAAA,YAAA;AAAA,cAEE,GAAG,aAAa,EAAE,MAAM;AAAA,cACzB,OAAO,WAAW,EAAE,YAAY,aAAa;AAAA,cAE5C,UAAA,KAAK,IAAI,CAAC,OAAO,QAChBA,2BAAAA,IAAC,QAAA,EAAgB,GAAG,cAAc,EAAE,MAAA,CAAO,EAAA,GAAhC,GAAmC,CAC/C;AAAA,YAAA;AAAA,YANI;AAAA,UAAA,CAQR,EAAA,CACH;AAAA,QAAA;AAAA,MAAA;AAAA,IACF,EAAA,CACF,EAAA,CAEJ;AAAA,EAEJ;AACF;AAEA,iBAAiB,cAAc;;"}
|
|
1
|
+
{"version":3,"file":"CodeBlock.vanilla.cjs","sources":["../../../components/CodeBlock/CodeBlock.vanilla.tsx"],"sourcesContent":["import './prism-extend';\n\nimport { CheckIcon, CopyIcon } from '@radix-ui/react-icons';\nimport { assignInlineVars } from '@vanilla-extract/dynamic';\nimport { Highlight, Language, Prism, themes } from 'prism-react-renderer';\nimport React, {\n forwardRef,\n HTMLAttributes,\n useCallback,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\n\nimport { CSSProps, processCSSProp } from '../../styles/cssProps';\nimport { useVanillaExtractTheme } from '../../styles/themeContext';\nimport { AccessibleIcon } from '../AccessibleIcon';\nimport { ButtonVanilla } from '../Button';\nimport {\n codeContent,\n codeContentBottomPadding,\n codeContentTopPadding,\n copyButtonWrapperBottomLeft,\n copyButtonWrapperBottomRight,\n copyButtonWrapperTop,\n copyButtonWrapperTopLeft,\n pre,\n preNoBorder,\n} from './CodeBlock.vanilla.css';\nimport type { CodeBlockCopyButtonAlign, CodeBlockLanguage } from './index';\n\nexport interface CodeBlockVanillaProps\n extends Omit<HTMLAttributes<HTMLPreElement>, 'css'>,\n CSSProps {\n lang?: CodeBlockLanguage;\n code: string;\n copyable?: boolean;\n copyText?: string;\n copiedText?: string;\n copyButtonAlign?: CodeBlockCopyButtonAlign;\n onCopy?: () => void;\n noBorder?: boolean;\n wrapText?: boolean;\n colorScheme?: 'light' | 'dark';\n maxHeight?: number | string;\n}\n\nexport const CodeBlockVanilla = forwardRef<HTMLPreElement, CodeBlockVanillaProps>(\n (\n {\n lang = 'text',\n code,\n copyable = false,\n copyText,\n copiedText,\n copyButtonAlign = 'top right',\n onCopy,\n noBorder,\n wrapText = false,\n colorScheme,\n maxHeight = 424,\n css,\n style,\n className,\n ...props\n },\n ref,\n ) => {\n const { colors, resolvedTheme } = useVanillaExtractTheme();\n const effectiveScheme = colorScheme ?? resolvedTheme;\n const prismTheme = effectiveScheme === 'dark' ? themes.nightOwl : themes.nightOwlLight;\n\n const isBottom = copyButtonAlign.includes('bottom');\n const isLeft = copyButtonAlign.includes('left');\n\n const { style: cssStyles, vars } = processCSSProp(css, colors);\n const containerStyles = {\n position: 'relative' as const,\n ...cssStyles,\n ...assignInlineVars(vars),\n };\n\n const [copied, setCopied] = useState(false);\n\n const preRef = useRef<HTMLPreElement | null>(\n null,\n ) as React.MutableRefObject<HTMLPreElement | null>;\n const buttonWrapperRef = useRef<HTMLDivElement>(null);\n\n const setPreRef = useCallback(\n (node: HTMLPreElement | null) => {\n preRef.current = node;\n if (typeof ref === 'function') ref(node);\n else if (ref) (ref as React.MutableRefObject<HTMLPreElement | null>).current = node;\n },\n [ref],\n );\n\n useLayoutEffect(() => {\n if (!copyable) return;\n const pre = preRef.current;\n const wrapper = buttonWrapperRef.current;\n if (!pre || !wrapper) return;\n\n const borderH = noBorder ? 0 : 2;\n\n const update = () => {\n if (!isLeft) {\n const vScrollbar = Math.max(0, pre.offsetWidth - pre.clientWidth - borderH);\n wrapper.style.right = `${16 + vScrollbar}px`;\n }\n if (isBottom) {\n const hScrollbar = Math.max(0, pre.offsetHeight - pre.clientHeight - borderH);\n wrapper.style.bottom = `${8 + hScrollbar}px`;\n }\n };\n\n update();\n const observer = new ResizeObserver(update);\n observer.observe(pre);\n return () => observer.disconnect();\n }, [copyable, isBottom, isLeft, noBorder]);\n\n const handleCopy = async () => {\n try {\n await navigator.clipboard.writeText(code);\n setCopied(true);\n onCopy?.();\n setTimeout(() => setCopied(false), 1500);\n } catch {\n // clipboard write failed (e.g. permission denied) — leave UI unchanged\n }\n };\n\n const buttonPositionClass = isBottom\n ? isLeft\n ? copyButtonWrapperBottomLeft\n : copyButtonWrapperBottomRight\n : isLeft\n ? copyButtonWrapperTopLeft\n : copyButtonWrapperTop;\n\n const copyButton = copyable ? (\n <ButtonVanilla\n variant=\"secondary\"\n ghost\n size=\"small\"\n type=\"button\"\n onClick={handleCopy}\n css={{\n color: '$hiContrast',\n gap: '$1',\n backgroundColor: '$codeBlockCopyButtonBg',\n height: '32px',\n }}\n >\n <AccessibleIcon label={copied ? 'Copied' : 'Copy'}>\n {copied ? <CheckIcon /> : <CopyIcon />}\n </AccessibleIcon>\n {copied ? copiedText : copyText}\n </ButtonVanilla>\n ) : null;\n\n return (\n <Highlight\n theme={prismTheme}\n code={code}\n language={(Prism.languages[lang] != null ? lang : 'text') as Language}\n >\n {({\n className: highlightClass,\n style: highlightStyle,\n tokens,\n getLineProps,\n getTokenProps,\n }) => (\n <div style={containerStyles}>\n <pre\n ref={setPreRef}\n className={[pre, noBorder ? preNoBorder : '', highlightClass, className]\n .filter(Boolean)\n .join(' ')}\n style={{\n maxHeight,\n ...highlightStyle,\n backgroundColor: 'inherit',\n ...style,\n }}\n {...props}\n >\n <div\n className={[\n codeContent,\n copyable && isLeft && isBottom ? codeContentBottomPadding : '',\n copyable && isLeft && !isBottom ? codeContentTopPadding : '',\n ]\n .filter(Boolean)\n .join(' ')}\n >\n {tokens.map((line, i) => (\n <div\n key={i}\n {...getLineProps({ line })}\n style={\n wrapText ? { whiteSpace: 'pre-wrap', wordBreak: 'break-all' } : undefined\n }\n >\n {line.map((token, key) => (\n <span key={key} {...getTokenProps({ token })} />\n ))}\n </div>\n ))}\n </div>\n </pre>\n {copyButton && (\n <div ref={buttonWrapperRef} className={buttonPositionClass}>\n {copyButton}\n </div>\n )}\n </div>\n )}\n </Highlight>\n );\n },\n);\n\nCodeBlockVanilla.displayName = 'CodeBlockVanilla';\n"],"names":["forwardRef","useVanillaExtractTheme","themes","processCSSProp","assignInlineVars","useState","useRef","useCallback","useLayoutEffect","pre","copyButtonWrapperBottomLeft","copyButtonWrapperBottomRight","copyButtonWrapperTopLeft","copyButtonWrapperTop","jsxs","ButtonVanilla","jsx","AccessibleIcon","CheckIcon","CopyIcon","Highlight","Prism","preNoBorder","codeContent","codeContentBottomPadding","codeContentTopPadding"],"mappings":";;;;;;;;;;;;AA+CO,MAAM,mBAAmBA,MAAAA;AAAAA,EAC9B,CACE;AAAA,IACE,OAAO;AAAA,IACP;AAAA,IACA,WAAW;AAAA,IACX;AAAA,IACA;AAAA,IACA,kBAAkB;AAAA,IAClB;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX;AAAA,IACA,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,GAEL,QACG;AACH,UAAM,EAAE,QAAQ,cAAA,IAAkBC,oCAAA;AAClC,UAAM,kBAAkB,eAAe;AACvC,UAAM,aAAa,oBAAoB,SAASC,mBAAAA,OAAO,WAAWA,mBAAAA,OAAO;AAEzE,UAAM,WAAW,gBAAgB,SAAS,QAAQ;AAClD,UAAM,SAAS,gBAAgB,SAAS,MAAM;AAE9C,UAAM,EAAE,OAAO,WAAW,SAASC,SAAAA,eAAe,KAAK,MAAM;AAC7D,UAAM,kBAAkB;AAAA,MACtB,UAAU;AAAA,MACV,GAAG;AAAA,MACH,GAAGC,QAAAA,iBAAiB,IAAI;AAAA,IAAA;AAG1B,UAAM,CAAC,QAAQ,SAAS,IAAIC,MAAAA,SAAS,KAAK;AAE1C,UAAM,SAASC,MAAAA;AAAAA,MACb;AAAA,IAAA;AAEF,UAAM,mBAAmBA,MAAAA,OAAuB,IAAI;AAEpD,UAAM,YAAYC,MAAAA;AAAA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V,UAAA,OAAO,IAAI,CAAC,MAAM,MACjBT,2BAAAA;AAAAA,oBAAC;AAAA,oBAAA;AAAA,sBAEE,GAAG,aAAa,EAAE,MAAM;AAAA,sBACzB,OACE,WAAW,EAAE,YAAY,YAAY,WAAW,gBAAgB;AAAA,sBAGjE,UAAA,KAAK,IAAI,CAAC,OAAO,QAChBA,2BAAAA,IAAC,QAAA,EAAgB,GAAG,cAAc,EAAE,MAAA,CAAO,EAAA,GAAhC,GAAmC,CAC/C;AAAA,oBAAA;AAAA,oBARI;AAAA,kBAAA,CAUR;AAAA,gBAAA;AAAA,cAAA;AAAA,YACH;AAAA,UAAA;AAAA,UAED,cACCA,2BAAAA,IAAC,OAAA,EAAI,KAAK,kBAAkB,WAAW,qBACpC,UAAA,WAAA,CACH;AAAA,QAAA,EAAA,CAEJ;AAAA,MAAA;AAAA,IAAA;AAAA,EAIR;AACF;AAEA,iBAAiB,cAAc;;"}
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
;/* empty css */
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
4
|
+
var pre = "_1krwcuz0";
|
|
5
|
+
var preNoBorder = "_1krwcuz1";
|
|
6
|
+
var codeContent = "_1krwcuz2";
|
|
7
|
+
var codeContentBottomPadding = "_1krwcuz3";
|
|
8
|
+
var codeContentTopPadding = "_1krwcuz4";
|
|
9
9
|
var copyButtonWrapperTop = "_1krwcuz5";
|
|
10
|
-
var
|
|
10
|
+
var copyButtonWrapperTopLeft = "_1krwcuz6";
|
|
11
|
+
var copyButtonWrapperBottomRight = "_1krwcuz7";
|
|
12
|
+
var copyButtonWrapperBottomLeft = "_1krwcuz8";
|
|
11
13
|
exports.codeContent = codeContent;
|
|
12
|
-
exports.
|
|
13
|
-
exports.
|
|
14
|
+
exports.codeContentBottomPadding = codeContentBottomPadding;
|
|
15
|
+
exports.codeContentTopPadding = codeContentTopPadding;
|
|
16
|
+
exports.copyButtonWrapperBottomLeft = copyButtonWrapperBottomLeft;
|
|
17
|
+
exports.copyButtonWrapperBottomRight = copyButtonWrapperBottomRight;
|
|
14
18
|
exports.copyButtonWrapperTop = copyButtonWrapperTop;
|
|
19
|
+
exports.copyButtonWrapperTopLeft = copyButtonWrapperTopLeft;
|
|
15
20
|
exports.pre = pre;
|
|
16
21
|
exports.preNoBorder = preNoBorder;
|
|
17
|
-
exports.wrapper = wrapper;
|
|
18
22
|
//# sourceMappingURL=CodeBlock.vanilla.css.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeBlock.vanilla.css.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CodeBlock.vanilla.css.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
/* empty css */
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
2
|
+
var pre = "_1krwcuz0";
|
|
3
|
+
var preNoBorder = "_1krwcuz1";
|
|
4
|
+
var codeContent = "_1krwcuz2";
|
|
5
|
+
var codeContentBottomPadding = "_1krwcuz3";
|
|
6
|
+
var codeContentTopPadding = "_1krwcuz4";
|
|
7
7
|
var copyButtonWrapperTop = "_1krwcuz5";
|
|
8
|
-
var
|
|
8
|
+
var copyButtonWrapperTopLeft = "_1krwcuz6";
|
|
9
|
+
var copyButtonWrapperBottomRight = "_1krwcuz7";
|
|
10
|
+
var copyButtonWrapperBottomLeft = "_1krwcuz8";
|
|
9
11
|
export {
|
|
10
12
|
codeContent,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
codeContentBottomPadding,
|
|
14
|
+
codeContentTopPadding,
|
|
15
|
+
copyButtonWrapperBottomLeft,
|
|
16
|
+
copyButtonWrapperBottomRight,
|
|
13
17
|
copyButtonWrapperTop,
|
|
18
|
+
copyButtonWrapperTopLeft,
|
|
14
19
|
pre,
|
|
15
|
-
preNoBorder
|
|
16
|
-
wrapper
|
|
20
|
+
preNoBorder
|
|
17
21
|
};
|
|
18
22
|
//# sourceMappingURL=CodeBlock.vanilla.css.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeBlock.vanilla.css.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CodeBlock.vanilla.css.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { CheckIcon, CopyIcon } from "@radix-ui/react-icons";
|
|
3
3
|
import { assignInlineVars } from "@vanilla-extract/dynamic";
|
|
4
|
-
import { themes, Highlight } from "prism-react-renderer";
|
|
5
|
-
import { forwardRef, useState } from "react";
|
|
4
|
+
import { themes, Highlight, Prism } from "prism-react-renderer";
|
|
5
|
+
import { forwardRef, useState, useRef, useCallback, useLayoutEffect } from "react";
|
|
6
6
|
import { processCSSProp } from "../../styles/cssProps.js";
|
|
7
7
|
import { useVanillaExtractTheme } from "../../styles/themeContext.js";
|
|
8
|
-
import {
|
|
8
|
+
import { pre, preNoBorder, codeContent, codeContentBottomPadding, codeContentTopPadding, copyButtonWrapperBottomLeft, copyButtonWrapperBottomRight, copyButtonWrapperTopLeft, copyButtonWrapperTop } from "./CodeBlock.vanilla.css.js";
|
|
9
9
|
import { ButtonVanilla } from "../Button/Button.vanilla.js";
|
|
10
10
|
import { AccessibleIcon } from "../AccessibleIcon/AccessibleIcon.js";
|
|
11
11
|
const CodeBlockVanilla = forwardRef(
|
|
12
12
|
({
|
|
13
|
-
lang,
|
|
13
|
+
lang = "text",
|
|
14
14
|
code,
|
|
15
15
|
copyable = false,
|
|
16
16
|
copyText,
|
|
17
17
|
copiedText,
|
|
18
|
-
copyButtonAlign = "top",
|
|
18
|
+
copyButtonAlign = "top right",
|
|
19
|
+
onCopy,
|
|
19
20
|
noBorder,
|
|
20
21
|
wrapText = false,
|
|
21
22
|
colorScheme,
|
|
@@ -28,72 +29,128 @@ const CodeBlockVanilla = forwardRef(
|
|
|
28
29
|
const { colors, resolvedTheme } = useVanillaExtractTheme();
|
|
29
30
|
const effectiveScheme = colorScheme ?? resolvedTheme;
|
|
30
31
|
const prismTheme = effectiveScheme === "dark" ? themes.nightOwl : themes.nightOwlLight;
|
|
32
|
+
const isBottom = copyButtonAlign.includes("bottom");
|
|
33
|
+
const isLeft = copyButtonAlign.includes("left");
|
|
31
34
|
const { style: cssStyles, vars } = processCSSProp(css, colors);
|
|
32
|
-
const
|
|
35
|
+
const containerStyles = {
|
|
36
|
+
position: "relative",
|
|
37
|
+
...cssStyles,
|
|
38
|
+
...assignInlineVars(vars)
|
|
39
|
+
};
|
|
33
40
|
const [copied, setCopied] = useState(false);
|
|
41
|
+
const preRef = useRef(
|
|
42
|
+
null
|
|
43
|
+
);
|
|
44
|
+
const buttonWrapperRef = useRef(null);
|
|
45
|
+
const setPreRef = useCallback(
|
|
46
|
+
(node) => {
|
|
47
|
+
preRef.current = node;
|
|
48
|
+
if (typeof ref === "function") ref(node);
|
|
49
|
+
else if (ref) ref.current = node;
|
|
50
|
+
},
|
|
51
|
+
[ref]
|
|
52
|
+
);
|
|
53
|
+
useLayoutEffect(() => {
|
|
54
|
+
if (!copyable) return;
|
|
55
|
+
const pre2 = preRef.current;
|
|
56
|
+
const wrapper = buttonWrapperRef.current;
|
|
57
|
+
if (!pre2 || !wrapper) return;
|
|
58
|
+
const borderH = noBorder ? 0 : 2;
|
|
59
|
+
const update = () => {
|
|
60
|
+
if (!isLeft) {
|
|
61
|
+
const vScrollbar = Math.max(0, pre2.offsetWidth - pre2.clientWidth - borderH);
|
|
62
|
+
wrapper.style.right = `${16 + vScrollbar}px`;
|
|
63
|
+
}
|
|
64
|
+
if (isBottom) {
|
|
65
|
+
const hScrollbar = Math.max(0, pre2.offsetHeight - pre2.clientHeight - borderH);
|
|
66
|
+
wrapper.style.bottom = `${8 + hScrollbar}px`;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
update();
|
|
70
|
+
const observer = new ResizeObserver(update);
|
|
71
|
+
observer.observe(pre2);
|
|
72
|
+
return () => observer.disconnect();
|
|
73
|
+
}, [copyable, isBottom, isLeft, noBorder]);
|
|
34
74
|
const handleCopy = async () => {
|
|
35
75
|
try {
|
|
36
76
|
await navigator.clipboard.writeText(code);
|
|
37
77
|
setCopied(true);
|
|
78
|
+
onCopy?.();
|
|
38
79
|
setTimeout(() => setCopied(false), 1500);
|
|
39
80
|
} catch {
|
|
40
81
|
}
|
|
41
82
|
};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
{
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
83
|
+
const buttonPositionClass = isBottom ? isLeft ? copyButtonWrapperBottomLeft : copyButtonWrapperBottomRight : isLeft ? copyButtonWrapperTopLeft : copyButtonWrapperTop;
|
|
84
|
+
const copyButton = copyable ? /* @__PURE__ */ jsxs(
|
|
85
|
+
ButtonVanilla,
|
|
86
|
+
{
|
|
87
|
+
variant: "secondary",
|
|
88
|
+
ghost: true,
|
|
89
|
+
size: "small",
|
|
90
|
+
type: "button",
|
|
91
|
+
onClick: handleCopy,
|
|
92
|
+
css: {
|
|
93
|
+
color: "$hiContrast",
|
|
94
|
+
gap: "$1",
|
|
95
|
+
backgroundColor: "$codeBlockCopyButtonBg",
|
|
96
|
+
height: "32px"
|
|
97
|
+
},
|
|
98
|
+
children: [
|
|
99
|
+
/* @__PURE__ */ jsx(AccessibleIcon, { label: copied ? "Copied" : "Copy", children: copied ? /* @__PURE__ */ jsx(CheckIcon, {}) : /* @__PURE__ */ jsx(CopyIcon, {}) }),
|
|
100
|
+
copied ? copiedText : copyText
|
|
101
|
+
]
|
|
102
|
+
}
|
|
103
|
+
) : null;
|
|
104
|
+
return /* @__PURE__ */ jsx(
|
|
105
|
+
Highlight,
|
|
106
|
+
{
|
|
107
|
+
theme: prismTheme,
|
|
108
|
+
code,
|
|
109
|
+
language: Prism.languages[lang] != null ? lang : "text",
|
|
110
|
+
children: ({
|
|
111
|
+
className: highlightClass,
|
|
112
|
+
style: highlightStyle,
|
|
113
|
+
tokens,
|
|
114
|
+
getLineProps,
|
|
115
|
+
getTokenProps
|
|
116
|
+
}) => /* @__PURE__ */ jsxs("div", { style: containerStyles, children: [
|
|
117
|
+
/* @__PURE__ */ jsx(
|
|
118
|
+
"pre",
|
|
58
119
|
{
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
120
|
+
ref: setPreRef,
|
|
121
|
+
className: [pre, noBorder ? preNoBorder : "", highlightClass, className].filter(Boolean).join(" "),
|
|
122
|
+
style: {
|
|
123
|
+
maxHeight,
|
|
124
|
+
...highlightStyle,
|
|
125
|
+
backgroundColor: "inherit",
|
|
126
|
+
...style
|
|
127
|
+
},
|
|
128
|
+
...props,
|
|
129
|
+
children: /* @__PURE__ */ jsx(
|
|
130
|
+
"div",
|
|
131
|
+
{
|
|
132
|
+
className: [
|
|
133
|
+
codeContent,
|
|
134
|
+
copyable && isLeft && isBottom ? codeContentBottomPadding : "",
|
|
135
|
+
copyable && isLeft && !isBottom ? codeContentTopPadding : ""
|
|
136
|
+
].filter(Boolean).join(" "),
|
|
137
|
+
children: tokens.map((line, i) => /* @__PURE__ */ jsx(
|
|
138
|
+
"div",
|
|
139
|
+
{
|
|
140
|
+
...getLineProps({ line }),
|
|
141
|
+
style: wrapText ? { whiteSpace: "pre-wrap", wordBreak: "break-all" } : void 0,
|
|
142
|
+
children: line.map((token, key) => /* @__PURE__ */ jsx("span", { ...getTokenProps({ token }) }, key))
|
|
143
|
+
},
|
|
144
|
+
i
|
|
145
|
+
))
|
|
146
|
+
}
|
|
147
|
+
)
|
|
69
148
|
}
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
{
|
|
76
|
-
ref,
|
|
77
|
-
className: [pre, noBorder ? preNoBorder : "", highlightClass, className].filter(Boolean).join(" "),
|
|
78
|
-
style: {
|
|
79
|
-
maxHeight,
|
|
80
|
-
...highlightStyle,
|
|
81
|
-
backgroundColor: "transparent",
|
|
82
|
-
...mergedStyles
|
|
83
|
-
},
|
|
84
|
-
...props,
|
|
85
|
-
children: /* @__PURE__ */ jsx("div", { className: codeContent, children: tokens.map((line, i) => /* @__PURE__ */ jsx(
|
|
86
|
-
"div",
|
|
87
|
-
{
|
|
88
|
-
...getLineProps({ line }),
|
|
89
|
-
style: wrapText ? { whiteSpace: "normal" } : void 0,
|
|
90
|
-
children: line.map((token, key) => /* @__PURE__ */ jsx("span", { ...getTokenProps({ token }) }, key))
|
|
91
|
-
},
|
|
92
|
-
i
|
|
93
|
-
)) })
|
|
94
|
-
}
|
|
95
|
-
)
|
|
96
|
-
] }) });
|
|
149
|
+
),
|
|
150
|
+
copyButton && /* @__PURE__ */ jsx("div", { ref: buttonWrapperRef, className: buttonPositionClass, children: copyButton })
|
|
151
|
+
] })
|
|
152
|
+
}
|
|
153
|
+
);
|
|
97
154
|
}
|
|
98
155
|
);
|
|
99
156
|
CodeBlockVanilla.displayName = "CodeBlockVanilla";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeBlock.vanilla.js","sources":["../../../components/CodeBlock/CodeBlock.vanilla.tsx"],"sourcesContent":["import { CheckIcon, CopyIcon } from '@radix-ui/react-icons';\nimport { assignInlineVars } from '@vanilla-extract/dynamic';\nimport { Highlight, Language, themes } from 'prism-react-renderer';\nimport React, {
|
|
1
|
+
{"version":3,"file":"CodeBlock.vanilla.js","sources":["../../../components/CodeBlock/CodeBlock.vanilla.tsx"],"sourcesContent":["import './prism-extend';\n\nimport { CheckIcon, CopyIcon } from '@radix-ui/react-icons';\nimport { assignInlineVars } from '@vanilla-extract/dynamic';\nimport { Highlight, Language, Prism, themes } from 'prism-react-renderer';\nimport React, {\n forwardRef,\n HTMLAttributes,\n useCallback,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\n\nimport { CSSProps, processCSSProp } from '../../styles/cssProps';\nimport { useVanillaExtractTheme } from '../../styles/themeContext';\nimport { AccessibleIcon } from '../AccessibleIcon';\nimport { ButtonVanilla } from '../Button';\nimport {\n codeContent,\n codeContentBottomPadding,\n codeContentTopPadding,\n copyButtonWrapperBottomLeft,\n copyButtonWrapperBottomRight,\n copyButtonWrapperTop,\n copyButtonWrapperTopLeft,\n pre,\n preNoBorder,\n} from './CodeBlock.vanilla.css';\nimport type { CodeBlockCopyButtonAlign, CodeBlockLanguage } from './index';\n\nexport interface CodeBlockVanillaProps\n extends Omit<HTMLAttributes<HTMLPreElement>, 'css'>,\n CSSProps {\n lang?: CodeBlockLanguage;\n code: string;\n copyable?: boolean;\n copyText?: string;\n copiedText?: string;\n copyButtonAlign?: CodeBlockCopyButtonAlign;\n onCopy?: () => void;\n noBorder?: boolean;\n wrapText?: boolean;\n colorScheme?: 'light' | 'dark';\n maxHeight?: number | string;\n}\n\nexport const CodeBlockVanilla = forwardRef<HTMLPreElement, CodeBlockVanillaProps>(\n (\n {\n lang = 'text',\n code,\n copyable = false,\n copyText,\n copiedText,\n copyButtonAlign = 'top right',\n onCopy,\n noBorder,\n wrapText = false,\n colorScheme,\n maxHeight = 424,\n css,\n style,\n className,\n ...props\n },\n ref,\n ) => {\n const { colors, resolvedTheme } = useVanillaExtractTheme();\n const effectiveScheme = colorScheme ?? resolvedTheme;\n const prismTheme = effectiveScheme === 'dark' ? themes.nightOwl : themes.nightOwlLight;\n\n const isBottom = copyButtonAlign.includes('bottom');\n const isLeft = copyButtonAlign.includes('left');\n\n const { style: cssStyles, vars } = processCSSProp(css, colors);\n const containerStyles = {\n position: 'relative' as const,\n ...cssStyles,\n ...assignInlineVars(vars),\n };\n\n const [copied, setCopied] = useState(false);\n\n const preRef = useRef<HTMLPreElement | null>(\n null,\n ) as React.MutableRefObject<HTMLPreElement | null>;\n const buttonWrapperRef = useRef<HTMLDivElement>(null);\n\n const setPreRef = useCallback(\n (node: HTMLPreElement | null) => {\n preRef.current = node;\n if (typeof ref === 'function') ref(node);\n else if (ref) (ref as React.MutableRefObject<HTMLPreElement | null>).current = node;\n },\n [ref],\n );\n\n useLayoutEffect(() => {\n if (!copyable) return;\n const pre = preRef.current;\n const wrapper = buttonWrapperRef.current;\n if (!pre || !wrapper) return;\n\n const borderH = noBorder ? 0 : 2;\n\n const update = () => {\n if (!isLeft) {\n const vScrollbar = Math.max(0, pre.offsetWidth - pre.clientWidth - borderH);\n wrapper.style.right = `${16 + vScrollbar}px`;\n }\n if (isBottom) {\n const hScrollbar = Math.max(0, pre.offsetHeight - pre.clientHeight - borderH);\n wrapper.style.bottom = `${8 + hScrollbar}px`;\n }\n };\n\n update();\n const observer = new ResizeObserver(update);\n observer.observe(pre);\n return () => observer.disconnect();\n }, [copyable, isBottom, isLeft, noBorder]);\n\n const handleCopy = async () => {\n try {\n await navigator.clipboard.writeText(code);\n setCopied(true);\n onCopy?.();\n setTimeout(() => setCopied(false), 1500);\n } catch {\n // clipboard write failed (e.g. permission denied) — leave UI unchanged\n }\n };\n\n const buttonPositionClass = isBottom\n ? isLeft\n ? copyButtonWrapperBottomLeft\n : copyButtonWrapperBottomRight\n : isLeft\n ? copyButtonWrapperTopLeft\n : copyButtonWrapperTop;\n\n const copyButton = copyable ? (\n <ButtonVanilla\n variant=\"secondary\"\n ghost\n size=\"small\"\n type=\"button\"\n onClick={handleCopy}\n css={{\n color: '$hiContrast',\n gap: '$1',\n backgroundColor: '$codeBlockCopyButtonBg',\n height: '32px',\n }}\n >\n <AccessibleIcon label={copied ? 'Copied' : 'Copy'}>\n {copied ? <CheckIcon /> : <CopyIcon />}\n </AccessibleIcon>\n {copied ? copiedText : copyText}\n </ButtonVanilla>\n ) : null;\n\n return (\n <Highlight\n theme={prismTheme}\n code={code}\n language={(Prism.languages[lang] != null ? lang : 'text') as Language}\n >\n {({\n className: highlightClass,\n style: highlightStyle,\n tokens,\n getLineProps,\n getTokenProps,\n }) => (\n <div style={containerStyles}>\n <pre\n ref={setPreRef}\n className={[pre, noBorder ? preNoBorder : '', highlightClass, className]\n .filter(Boolean)\n .join(' ')}\n style={{\n maxHeight,\n ...highlightStyle,\n backgroundColor: 'inherit',\n ...style,\n }}\n {...props}\n >\n <div\n className={[\n codeContent,\n copyable && isLeft && isBottom ? codeContentBottomPadding : '',\n copyable && isLeft && !isBottom ? codeContentTopPadding : '',\n ]\n .filter(Boolean)\n .join(' ')}\n >\n {tokens.map((line, i) => (\n <div\n key={i}\n {...getLineProps({ line })}\n style={\n wrapText ? { whiteSpace: 'pre-wrap', wordBreak: 'break-all' } : undefined\n }\n >\n {line.map((token, key) => (\n <span key={key} {...getTokenProps({ token })} />\n ))}\n </div>\n ))}\n </div>\n </pre>\n {copyButton && (\n <div ref={buttonWrapperRef} className={buttonPositionClass}>\n {copyButton}\n </div>\n )}\n </div>\n )}\n </Highlight>\n );\n },\n);\n\nCodeBlockVanilla.displayName = 'CodeBlockVanilla';\n"],"names":["pre"],"mappings":";;;;;;;;;;AA+CO,MAAM,mBAAmB;AAAA,EAC9B,CACE;AAAA,IACE,OAAO;AAAA,IACP;AAAA,IACA,WAAW;AAAA,IACX;AAAA,IACA;AAAA,IACA,kBAAkB;AAAA,IAClB;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX;AAAA,IACA,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,GAEL,QACG;AACH,UAAM,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AAA,gBACH,iBAAiB;AAAA,gBACjB,GAAG;AAAA,cAAA;AAAA,cAEJ,GAAG;AAAA,cAEJ,UAAA;AAAA,gBAAC;AAAA,gBAAA;AAAA,kBACC,WAAW;AAAA,oBACT;AAAA,oBACA,YAAY,UAAU,WAAW,2BAA2B;AAAA,oBAC5D,YAAY,UAAU,CAAC,WAAW,wBAAwB;AAAA,kBAAA,EAEzD,OAAO,OAAO,EACd,KAAK,GAAG;AAAA,kBAEV,UAAA,OAAO,IAAI,CAAC,MAAM,MACjB;AAAA,oBAAC;AAAA,oBAAA;AAAA,sBAEE,GAAG,aAAa,EAAE,MAAM;AAAA,sBACzB,OACE,WAAW,EAAE,YAAY,YAAY,WAAW,gBAAgB;AAAA,sBAGjE,UAAA,KAAK,IAAI,CAAC,OAAO,QAChB,oBAAC,QAAA,EAAgB,GAAG,cAAc,EAAE,MAAA,CAAO,EAAA,GAAhC,GAAmC,CAC/C;AAAA,oBAAA;AAAA,oBARI;AAAA,kBAAA,CAUR;AAAA,gBAAA;AAAA,cAAA;AAAA,YACH;AAAA,UAAA;AAAA,UAED,cACC,oBAAC,OAAA,EAAI,KAAK,kBAAkB,WAAW,qBACpC,UAAA,WAAA,CACH;AAAA,QAAA,EAAA,CAEJ;AAAA,MAAA;AAAA,IAAA;AAAA,EAIR;AACF;AAEA,iBAAiB,cAAc;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
;/* empty css */
|
|
3
4
|
;/* empty css */
|
|
4
5
|
const createRuntimeFn = require("@vanilla-extract/recipes/createRuntimeFn");
|
|
5
6
|
var labelRecipe = createRuntimeFn.createRuntimeFn({ defaultClassName: "_14umx1r1 _14umx1r0", variantClassNames: { size: { "0": "_14umx1r2", "1": "_14umx1r3", "2": "_14umx1r4", "3": "_14umx1r5", "4": "_14umx1r6", "5": "_14umx1r7", "6": "_14umx1r8", "7": "_14umx1r9", "8": "_14umx1ra", "9": "_14umx1rb", "10": "_14umx1rc", "11": "_14umx1rd", "12": "_14umx1re", inherit: "_14umx1rf" }, weight: { light: "_14umx1rg", regular: "_14umx1rh", medium: "_14umx1ri", semiBold: "_14umx1rj", bold: "_14umx1rk" }, variant: { red: "_14umx1rl", subtle: "_14umx1rm", "default": "_14umx1rn", contrast: "_14umx1ro", inherit: "_14umx1rp", invalid: "_14umx1rq" }, gradient: { true: "_14umx1rr" }, transform: { uppercase: "_14umx1rs", capitalize: "_14umx1rt", capitalizeWords: "_14umx1ru" }, noWrap: { true: "_14umx1rv" } }, defaultVariants: { size: "0", variant: "subtle", transform: "capitalize" }, compoundVariants: [] });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Label.vanilla.css.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Label.vanilla.css.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* empty css */
|
|
1
2
|
/* empty css */
|
|
2
3
|
import { createRuntimeFn } from "@vanilla-extract/recipes/createRuntimeFn";
|
|
3
4
|
var labelRecipe = createRuntimeFn({ defaultClassName: "_14umx1r1 _14umx1r0", variantClassNames: { size: { "0": "_14umx1r2", "1": "_14umx1r3", "2": "_14umx1r4", "3": "_14umx1r5", "4": "_14umx1r6", "5": "_14umx1r7", "6": "_14umx1r8", "7": "_14umx1r9", "8": "_14umx1ra", "9": "_14umx1rb", "10": "_14umx1rc", "11": "_14umx1rd", "12": "_14umx1re", inherit: "_14umx1rf" }, weight: { light: "_14umx1rg", regular: "_14umx1rh", medium: "_14umx1ri", semiBold: "_14umx1rj", bold: "_14umx1rk" }, variant: { red: "_14umx1rl", subtle: "_14umx1rm", "default": "_14umx1rn", contrast: "_14umx1ro", inherit: "_14umx1rp", invalid: "_14umx1rq" }, gradient: { true: "_14umx1rr" }, transform: { uppercase: "_14umx1rs", capitalize: "_14umx1rt", capitalizeWords: "_14umx1ru" }, noWrap: { true: "_14umx1rv" } }, defaultVariants: { size: "0", variant: "subtle", transform: "capitalize" }, compoundVariants: [] });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Label.vanilla.css.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Label.vanilla.css.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|