@gild-ui/vue-markdown 0.0.0 → 0.1.0-alpha.0
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/LICENSE +21 -0
- package/README.md +71 -2
- package/dist/CodeBlock-C-5omHoJ.mjs +216 -0
- package/dist/CodeBlock-NGTCYbfS.cjs +245 -0
- package/dist/CodeBlock.cjs +5 -0
- package/dist/CodeBlock.d.cts +2 -0
- package/dist/CodeBlock.d.mts +2 -0
- package/dist/CodeBlock.mjs +1 -0
- package/dist/Preview-CDeDFn2m.mjs +530 -0
- package/dist/Preview-D5Xn7LOO.cjs +561 -0
- package/dist/Preview.cjs +3 -0
- package/dist/Preview.d.cts +2 -0
- package/dist/Preview.d.mts +2 -0
- package/dist/Preview.mjs +1 -0
- package/dist/index-B5H8ATjj.d.cts +71 -0
- package/dist/index-B8VJeFJ1.d.cts +81 -0
- package/dist/index-DTkt5qf4.d.mts +82 -0
- package/dist/index-KyNhFQ61.d.mts +71 -0
- package/dist/index.cjs +7 -0
- package/dist/index.d.cts +3 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.mjs +3 -0
- package/package.json +106 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Masoud Soroush <https://soroush.tech>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,72 @@
|
|
|
1
|
-
|
|
1
|
+
[](https://www.npmjs.com/package/@gild-ui/vue-markdown)
|
|
2
|
+
[](https://app.codecov.io/gh/soroush-tech/design-system?flags%5B0%5D=vue-markdown)
|
|
3
|
+
[](./LICENSE)
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
## The markdown viewer of Gild UI for **Vue**
|
|
6
|
+
|
|
7
|
+
`Preview` renders a markdown string with the components of [`@gild-ui/vue`](../vue), and `CodeBlock` is
|
|
8
|
+
the syntax-highlighted code surface it uses. They have the names, props, theme slots and theme
|
|
9
|
+
configuration of [`@gild-ui/react-markdown`](../react-markdown), and the markup of `Preview` is the same for
|
|
10
|
+
the same document.
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npm install @gild-ui/vue @gild-ui/core @gild-ui/vue-markdown
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
It needs `vue` `^3.5.0` and `@gild-ui/vue` (a peer: the theme exists once in an app).
|
|
17
|
+
|
|
18
|
+
```vue
|
|
19
|
+
<script setup lang="ts">
|
|
20
|
+
import { ThemeProvider } from '@gild-ui/vue/ThemeProvider'
|
|
21
|
+
import { Preview } from '@gild-ui/vue-markdown/Preview'
|
|
22
|
+
import { themes } from './theme/themes'
|
|
23
|
+
|
|
24
|
+
const source =
|
|
25
|
+
'# Hello\n\nRendered through your **theme** - tables, `code`, and [links](https://soroush.tech).'
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<template>
|
|
29
|
+
<ThemeProvider :theme="themes.light">
|
|
30
|
+
<Preview>{{ source }}</Preview>
|
|
31
|
+
</ThemeProvider>
|
|
32
|
+
</template>
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The markdown source is the **default slot** (the `children` of the React component). Every other prop is
|
|
36
|
+
the same: `slotProps` and `style`.
|
|
37
|
+
|
|
38
|
+
## The theme
|
|
39
|
+
|
|
40
|
+
`CodeBlock` colours its code from `theme.syntax`, which a theme must have: merge `syntaxDark` or
|
|
41
|
+
`syntaxLight` (exported by `@gild-ui/vue-markdown/CodeBlock`), or your own.
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import { baseTheme, createTheme } from '@gild-ui/core/theme'
|
|
45
|
+
import { syntaxLight } from '@gild-ui/vue-markdown/CodeBlock'
|
|
46
|
+
|
|
47
|
+
export const light = createTheme(baseTheme, {
|
|
48
|
+
name: 'light',
|
|
49
|
+
colorScheme: 'light',
|
|
50
|
+
syntax: syntaxLight,
|
|
51
|
+
})
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`MarkdownPreview` and `CodeBlock` (slots `root` and `surface`) are keys of `theme.components`, typed once an
|
|
55
|
+
entry of the package is imported.
|
|
56
|
+
|
|
57
|
+
## What is not in this release
|
|
58
|
+
|
|
59
|
+
The editor (`Control`, `Toolbar`, `Editor`), live editing (`LiveEdit`) and Mermaid diagrams are not in
|
|
60
|
+
this package yet: they follow under
|
|
61
|
+
[#123](https://github.com/soroush-tech/gild-ui/issues/123) once the viewer is proven. A ` ```mermaid `
|
|
62
|
+
fence is drawn as a code block. Raw HTML in the source is shown as text, as in the React package.
|
|
63
|
+
|
|
64
|
+
## Where it differs from the React package
|
|
65
|
+
|
|
66
|
+
- The source is the default slot, not `children`; `class` is the Vue form of `className`.
|
|
67
|
+
- A link, an image, a quote, the checkbox of a task and the parts of a table are drawn by parts of this
|
|
68
|
+
package until `@gild-ui/vue` ships those components: they have the markup of the web components and the
|
|
69
|
+
tokens of the theme. Their `slotProps` values are the Vue props of the primitive that draws them.
|
|
70
|
+
- The copy button of `CodeBlock` uses `navigator.clipboard` through a listener of its own.
|
|
71
|
+
|
|
72
|
+
See [`vue-markdown.md`](./vue-markdown.md) for how it shares the parsing with the React package.
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { defineComponent, h, onBeforeUnmount, ref } from "vue";
|
|
2
|
+
import { styled } from "@gild-ui/vue";
|
|
3
|
+
import { Button } from "@gild-ui/vue/Button";
|
|
4
|
+
import { View } from "@gild-ui/vue/View";
|
|
5
|
+
import { useTheme } from "@gild-ui/vue/useTheme";
|
|
6
|
+
import { layout, space, system } from "@soroush.tech/styled-system";
|
|
7
|
+
import { createShouldForwardProp, props } from "@soroush.tech/styled-system/should-forward-prop";
|
|
8
|
+
// ../react-markdown/src/CodeBlock/CodeBlock.syntax.ts
|
|
9
|
+
const syntaxStyles = ({ theme }) => ({
|
|
10
|
+
color: theme.syntax.base,
|
|
11
|
+
fontFamily: theme.syntax.font,
|
|
12
|
+
"& .hljs-comment, & .hljs-quote, & .hljs-doctag, & .hljs-meta.prompt_": {
|
|
13
|
+
color: theme.syntax.comment,
|
|
14
|
+
fontStyle: "italic"
|
|
15
|
+
},
|
|
16
|
+
"& .hljs-keyword, & .hljs-built_in, & .hljs-literal, & .hljs-selector-tag, & .hljs-selector-pseudo, & .hljs-selector-attr": { color: theme.syntax.keyword },
|
|
17
|
+
"& .hljs-type, & .hljs-title.class_": { color: theme.syntax.type },
|
|
18
|
+
"& .hljs-string, & .hljs-regexp, & .hljs-char, & .hljs-meta .hljs-string, & .hljs-addition": { color: theme.syntax.string },
|
|
19
|
+
"& .hljs-number, & .hljs-symbol, & .hljs-bullet, & .hljs-link": { color: theme.syntax.number },
|
|
20
|
+
"& .hljs-variable.constant_, & .hljs-property": { color: theme.syntax.constant },
|
|
21
|
+
"& .hljs-title, & .hljs-section, & .hljs-attr, & .hljs-attribute, & .hljs-selector-id": { color: theme.syntax.title },
|
|
22
|
+
"& .hljs-tag, & .hljs-name, & .hljs-meta, & .hljs-variable, & .hljs-selector-class, & .hljs-deletion": { color: theme.syntax.tag },
|
|
23
|
+
"& .hljs-emphasis": { fontStyle: "italic" },
|
|
24
|
+
"& .hljs-strong": { fontWeight: "bold" }
|
|
25
|
+
});
|
|
26
|
+
// src/props.ts
|
|
27
|
+
/**
|
|
28
|
+
* Several overrides of one element, merged in order: the later wins. The attributes are spread, the
|
|
29
|
+
* classes (`className` and `class`) joined, and the styles become one list (one style stays as it is,
|
|
30
|
+
* so an entry given alone keeps its own class). The root merges `slotProps.root` first and the
|
|
31
|
+
* component's own `style` and `class` after, so they win.
|
|
32
|
+
*/
|
|
33
|
+
function mergeOverrides(...parts) {
|
|
34
|
+
const styles = parts.flatMap((part) => part?.style ? [part.style] : []);
|
|
35
|
+
return {
|
|
36
|
+
...Object.assign({}, ...parts),
|
|
37
|
+
class: parts.flatMap((part) => [part?.className, part?.class]),
|
|
38
|
+
style: styles.length > 1 ? styles : styles[0]
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The runtime declaration of props, which Vue needs to read a prop apart from the attributes. A
|
|
43
|
+
* component declares its own props and none of the style props (`m`, `flexDirection`, ...), which stay
|
|
44
|
+
* attributes, in the order they are given.
|
|
45
|
+
*/
|
|
46
|
+
const declare = (...names) => Object.fromEntries(names.map((name) => [name, null]));
|
|
47
|
+
/** What a component gives its root element: its attributes, and the overrides of `slotProps.root`, `style` and `class` merged. */
|
|
48
|
+
function rootProps(props, attrs) {
|
|
49
|
+
return {
|
|
50
|
+
...attrs,
|
|
51
|
+
...mergeOverrides(props.slotProps?.root, {
|
|
52
|
+
style: props.style,
|
|
53
|
+
class: attrs.class
|
|
54
|
+
})
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
// src/icons.ts
|
|
58
|
+
const colorSystem = system({ color: {
|
|
59
|
+
property: "color",
|
|
60
|
+
scale: "text"
|
|
61
|
+
} });
|
|
62
|
+
const StyledIcon = styled("svg", {
|
|
63
|
+
name: "Icon",
|
|
64
|
+
label: "icon",
|
|
65
|
+
shouldForwardProp: createShouldForwardProp([...props]),
|
|
66
|
+
systemProps: [
|
|
67
|
+
layout,
|
|
68
|
+
space,
|
|
69
|
+
colorSystem
|
|
70
|
+
]
|
|
71
|
+
})({ fill: "currentColor" });
|
|
72
|
+
const icon = (path) => {
|
|
73
|
+
const Icon = ({ color, size }) => {
|
|
74
|
+
const theme = useTheme();
|
|
75
|
+
const resolved = Object.entries(theme.value.icon).find(([name]) => name === size)?.[1] ?? size;
|
|
76
|
+
return h(StyledIcon, {
|
|
77
|
+
viewBox: "0 -960 960 960",
|
|
78
|
+
fill: "currentColor",
|
|
79
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
80
|
+
color,
|
|
81
|
+
width: resolved,
|
|
82
|
+
height: resolved,
|
|
83
|
+
"aria-hidden": "true"
|
|
84
|
+
}, () => h("path", { d: path }));
|
|
85
|
+
};
|
|
86
|
+
return Icon;
|
|
87
|
+
};
|
|
88
|
+
const CopyIcon = icon("M360-240q-33 0-56.5-23.5T280-320v-480q0-33 23.5-56.5T360-880h360q33 0 56.5 23.5T800-800v480q0 33-23.5 56.5T720-240H360Zm0-80h360v-480H360v480ZM200-80q-33 0-56.5-23.5T120-160v-560h80v560h440v80H200Zm160-240v-480 480Z");
|
|
89
|
+
const CheckIcon = icon("M382-240 154-468l57-57 171 171 367-367 57 57-424 424Z");
|
|
90
|
+
// ../react-markdown/src/CodeBlock/CodeBlock.data.ts
|
|
91
|
+
const font = "'JetBrains Mono Variable', 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace";
|
|
92
|
+
/** Matched to the JetBrains "Islands Dark" editor scheme. */
|
|
93
|
+
const syntaxDark = {
|
|
94
|
+
base: "#BBBBBB",
|
|
95
|
+
keyword: "#CF8E6D",
|
|
96
|
+
string: "#6AAB73",
|
|
97
|
+
number: "#2AACB8",
|
|
98
|
+
title: "#6BA9FA",
|
|
99
|
+
constant: "#C77DBB",
|
|
100
|
+
type: "#2AACB8",
|
|
101
|
+
comment: "#919191",
|
|
102
|
+
tag: "#D5B778",
|
|
103
|
+
font
|
|
104
|
+
};
|
|
105
|
+
/** Matched to the JetBrains "Islands Light" editor scheme. */
|
|
106
|
+
const syntaxLight = {
|
|
107
|
+
base: "#080808",
|
|
108
|
+
keyword: "#0033B3",
|
|
109
|
+
string: "#067D17",
|
|
110
|
+
number: "#1750EB",
|
|
111
|
+
title: "#00627A",
|
|
112
|
+
constant: "#871094",
|
|
113
|
+
type: "#007E8A",
|
|
114
|
+
comment: "#8C8C8C",
|
|
115
|
+
tag: "#008077",
|
|
116
|
+
font
|
|
117
|
+
};
|
|
118
|
+
// src/CodeBlock/CodeBlock.ts
|
|
119
|
+
/** The text without the newlines that end it (a scan from the end: no pattern to backtrack). */
|
|
120
|
+
function withoutTrailingNewlines(text) {
|
|
121
|
+
let end = text.length;
|
|
122
|
+
while (end > 0 && text[end - 1] === "\n") end--;
|
|
123
|
+
return text.slice(0, end);
|
|
124
|
+
}
|
|
125
|
+
const CodeSurface = styled(View, {
|
|
126
|
+
name: "CodeBlock",
|
|
127
|
+
slot: "surface",
|
|
128
|
+
label: "CodeSurface"
|
|
129
|
+
})(syntaxStyles);
|
|
130
|
+
const Wrapper = styled(View, {
|
|
131
|
+
name: "CodeBlock",
|
|
132
|
+
label: "CodeBlock"
|
|
133
|
+
})({
|
|
134
|
+
display: "grid",
|
|
135
|
+
gridTemplateColumns: "minmax(0, 1fr)",
|
|
136
|
+
"& .code-copy": {
|
|
137
|
+
opacity: 0,
|
|
138
|
+
transition: "opacity 120ms ease"
|
|
139
|
+
},
|
|
140
|
+
"&:hover .code-copy, &:focus-within .code-copy": { opacity: 1 },
|
|
141
|
+
"@media (hover: none)": { "& .code-copy": { opacity: 1 } }
|
|
142
|
+
});
|
|
143
|
+
/** How long the "copied" confirmation stays before reverting, in ms. */
|
|
144
|
+
const COPIED_RESET_MS = 2e3;
|
|
145
|
+
/**
|
|
146
|
+
* Fenced-code block: a horizontally scrollable, syntax-highlighted surface with a copy-to-clipboard
|
|
147
|
+
* button that sticks to the top-right while the block is in view.
|
|
148
|
+
*/
|
|
149
|
+
const CodeBlock = defineComponent((props, { attrs, slots }) => {
|
|
150
|
+
const control = ref();
|
|
151
|
+
const copied = ref(false);
|
|
152
|
+
let timer;
|
|
153
|
+
onBeforeUnmount(() => clearTimeout(timer));
|
|
154
|
+
const copy = () => {
|
|
155
|
+
const content = control.value?.$el.nextElementSibling?.textContent;
|
|
156
|
+
const text = content && withoutTrailingNewlines(content);
|
|
157
|
+
if (!text || !navigator.clipboard?.writeText) return;
|
|
158
|
+
navigator.clipboard.writeText(text).then(() => {
|
|
159
|
+
clearTimeout(timer);
|
|
160
|
+
copied.value = true;
|
|
161
|
+
timer = setTimeout(() => copied.value = false, COPIED_RESET_MS);
|
|
162
|
+
}, () => void 0);
|
|
163
|
+
};
|
|
164
|
+
return () => {
|
|
165
|
+
const { slotProps, style } = props;
|
|
166
|
+
return h(Wrapper, {
|
|
167
|
+
my: 2,
|
|
168
|
+
position: "relative",
|
|
169
|
+
...attrs,
|
|
170
|
+
...mergeOverrides(slotProps?.root, {
|
|
171
|
+
style,
|
|
172
|
+
class: attrs.class
|
|
173
|
+
})
|
|
174
|
+
}, () => [h(View, {
|
|
175
|
+
position: "absolute",
|
|
176
|
+
top: "8px",
|
|
177
|
+
right: "8px",
|
|
178
|
+
zIndex: 1,
|
|
179
|
+
bg: "paper",
|
|
180
|
+
borderRadius: "sm",
|
|
181
|
+
class: "code-copy",
|
|
182
|
+
ref: control
|
|
183
|
+
}, () => h(Button, {
|
|
184
|
+
type: "button",
|
|
185
|
+
variant: "outlined",
|
|
186
|
+
color: "default",
|
|
187
|
+
size: "sm",
|
|
188
|
+
borderRadius: "sm",
|
|
189
|
+
onClick: copy,
|
|
190
|
+
"aria-label": copied.value ? "Copied" : "Copy code"
|
|
191
|
+
}, () => copied.value ? h(CheckIcon, {
|
|
192
|
+
color: "success",
|
|
193
|
+
size: "1.1rem"
|
|
194
|
+
}) : h(CopyIcon, {
|
|
195
|
+
color: "primary",
|
|
196
|
+
size: "1.1rem"
|
|
197
|
+
}))), h(CodeSurface, {
|
|
198
|
+
...mergeOverrides(slotProps?.surface),
|
|
199
|
+
as: "pre",
|
|
200
|
+
tabIndex: 0,
|
|
201
|
+
bg: "terminal",
|
|
202
|
+
p: 3,
|
|
203
|
+
borderRadius: "md",
|
|
204
|
+
borderColor: "light",
|
|
205
|
+
borderWidth: "thin",
|
|
206
|
+
maxWidth: "100%",
|
|
207
|
+
overflow: "auto"
|
|
208
|
+
}, slots)]);
|
|
209
|
+
};
|
|
210
|
+
}, {
|
|
211
|
+
name: "CodeBlock",
|
|
212
|
+
inheritAttrs: false,
|
|
213
|
+
props: declare("slotProps", "style"),
|
|
214
|
+
slots: {}
|
|
215
|
+
});
|
|
216
|
+
export { rootProps as a, declare as i, syntaxDark as n, syntaxLight as r, CodeBlock as t };
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
let vue = require("vue");
|
|
2
|
+
let _gild_ui_vue = require("@gild-ui/vue");
|
|
3
|
+
let _gild_ui_vue_Button = require("@gild-ui/vue/Button");
|
|
4
|
+
let _gild_ui_vue_View = require("@gild-ui/vue/View");
|
|
5
|
+
let _gild_ui_vue_useTheme = require("@gild-ui/vue/useTheme");
|
|
6
|
+
let _soroush_tech_styled_system = require("@soroush.tech/styled-system");
|
|
7
|
+
let _soroush_tech_styled_system_should_forward_prop = require("@soroush.tech/styled-system/should-forward-prop");
|
|
8
|
+
// ../react-markdown/src/CodeBlock/CodeBlock.syntax.ts
|
|
9
|
+
const syntaxStyles = ({ theme }) => ({
|
|
10
|
+
color: theme.syntax.base,
|
|
11
|
+
fontFamily: theme.syntax.font,
|
|
12
|
+
"& .hljs-comment, & .hljs-quote, & .hljs-doctag, & .hljs-meta.prompt_": {
|
|
13
|
+
color: theme.syntax.comment,
|
|
14
|
+
fontStyle: "italic"
|
|
15
|
+
},
|
|
16
|
+
"& .hljs-keyword, & .hljs-built_in, & .hljs-literal, & .hljs-selector-tag, & .hljs-selector-pseudo, & .hljs-selector-attr": { color: theme.syntax.keyword },
|
|
17
|
+
"& .hljs-type, & .hljs-title.class_": { color: theme.syntax.type },
|
|
18
|
+
"& .hljs-string, & .hljs-regexp, & .hljs-char, & .hljs-meta .hljs-string, & .hljs-addition": { color: theme.syntax.string },
|
|
19
|
+
"& .hljs-number, & .hljs-symbol, & .hljs-bullet, & .hljs-link": { color: theme.syntax.number },
|
|
20
|
+
"& .hljs-variable.constant_, & .hljs-property": { color: theme.syntax.constant },
|
|
21
|
+
"& .hljs-title, & .hljs-section, & .hljs-attr, & .hljs-attribute, & .hljs-selector-id": { color: theme.syntax.title },
|
|
22
|
+
"& .hljs-tag, & .hljs-name, & .hljs-meta, & .hljs-variable, & .hljs-selector-class, & .hljs-deletion": { color: theme.syntax.tag },
|
|
23
|
+
"& .hljs-emphasis": { fontStyle: "italic" },
|
|
24
|
+
"& .hljs-strong": { fontWeight: "bold" }
|
|
25
|
+
});
|
|
26
|
+
// src/props.ts
|
|
27
|
+
/**
|
|
28
|
+
* Several overrides of one element, merged in order: the later wins. The attributes are spread, the
|
|
29
|
+
* classes (`className` and `class`) joined, and the styles become one list (one style stays as it is,
|
|
30
|
+
* so an entry given alone keeps its own class). The root merges `slotProps.root` first and the
|
|
31
|
+
* component's own `style` and `class` after, so they win.
|
|
32
|
+
*/
|
|
33
|
+
function mergeOverrides(...parts) {
|
|
34
|
+
const styles = parts.flatMap((part) => part?.style ? [part.style] : []);
|
|
35
|
+
return {
|
|
36
|
+
...Object.assign({}, ...parts),
|
|
37
|
+
class: parts.flatMap((part) => [part?.className, part?.class]),
|
|
38
|
+
style: styles.length > 1 ? styles : styles[0]
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The runtime declaration of props, which Vue needs to read a prop apart from the attributes. A
|
|
43
|
+
* component declares its own props and none of the style props (`m`, `flexDirection`, ...), which stay
|
|
44
|
+
* attributes, in the order they are given.
|
|
45
|
+
*/
|
|
46
|
+
const declare = (...names) => Object.fromEntries(names.map((name) => [name, null]));
|
|
47
|
+
/** What a component gives its root element: its attributes, and the overrides of `slotProps.root`, `style` and `class` merged. */
|
|
48
|
+
function rootProps(props, attrs) {
|
|
49
|
+
return {
|
|
50
|
+
...attrs,
|
|
51
|
+
...mergeOverrides(props.slotProps?.root, {
|
|
52
|
+
style: props.style,
|
|
53
|
+
class: attrs.class
|
|
54
|
+
})
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
// src/icons.ts
|
|
58
|
+
const colorSystem = (0, _soroush_tech_styled_system.system)({ color: {
|
|
59
|
+
property: "color",
|
|
60
|
+
scale: "text"
|
|
61
|
+
} });
|
|
62
|
+
const StyledIcon = (0, _gild_ui_vue.styled)("svg", {
|
|
63
|
+
name: "Icon",
|
|
64
|
+
label: "icon",
|
|
65
|
+
shouldForwardProp: (0, _soroush_tech_styled_system_should_forward_prop.createShouldForwardProp)([..._soroush_tech_styled_system_should_forward_prop.props]),
|
|
66
|
+
systemProps: [
|
|
67
|
+
_soroush_tech_styled_system.layout,
|
|
68
|
+
_soroush_tech_styled_system.space,
|
|
69
|
+
colorSystem
|
|
70
|
+
]
|
|
71
|
+
})({ fill: "currentColor" });
|
|
72
|
+
const icon = (path) => {
|
|
73
|
+
const Icon = ({ color, size }) => {
|
|
74
|
+
const theme = (0, _gild_ui_vue_useTheme.useTheme)();
|
|
75
|
+
const resolved = Object.entries(theme.value.icon).find(([name]) => name === size)?.[1] ?? size;
|
|
76
|
+
return (0, vue.h)(StyledIcon, {
|
|
77
|
+
viewBox: "0 -960 960 960",
|
|
78
|
+
fill: "currentColor",
|
|
79
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
80
|
+
color,
|
|
81
|
+
width: resolved,
|
|
82
|
+
height: resolved,
|
|
83
|
+
"aria-hidden": "true"
|
|
84
|
+
}, () => (0, vue.h)("path", { d: path }));
|
|
85
|
+
};
|
|
86
|
+
return Icon;
|
|
87
|
+
};
|
|
88
|
+
const CopyIcon = icon("M360-240q-33 0-56.5-23.5T280-320v-480q0-33 23.5-56.5T360-880h360q33 0 56.5 23.5T800-800v480q0 33-23.5 56.5T720-240H360Zm0-80h360v-480H360v480ZM200-80q-33 0-56.5-23.5T120-160v-560h80v560h440v80H200Zm160-240v-480 480Z");
|
|
89
|
+
const CheckIcon = icon("M382-240 154-468l57-57 171 171 367-367 57 57-424 424Z");
|
|
90
|
+
// ../react-markdown/src/CodeBlock/CodeBlock.data.ts
|
|
91
|
+
const font = "'JetBrains Mono Variable', 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace";
|
|
92
|
+
/** Matched to the JetBrains "Islands Dark" editor scheme. */
|
|
93
|
+
const syntaxDark = {
|
|
94
|
+
base: "#BBBBBB",
|
|
95
|
+
keyword: "#CF8E6D",
|
|
96
|
+
string: "#6AAB73",
|
|
97
|
+
number: "#2AACB8",
|
|
98
|
+
title: "#6BA9FA",
|
|
99
|
+
constant: "#C77DBB",
|
|
100
|
+
type: "#2AACB8",
|
|
101
|
+
comment: "#919191",
|
|
102
|
+
tag: "#D5B778",
|
|
103
|
+
font
|
|
104
|
+
};
|
|
105
|
+
/** Matched to the JetBrains "Islands Light" editor scheme. */
|
|
106
|
+
const syntaxLight = {
|
|
107
|
+
base: "#080808",
|
|
108
|
+
keyword: "#0033B3",
|
|
109
|
+
string: "#067D17",
|
|
110
|
+
number: "#1750EB",
|
|
111
|
+
title: "#00627A",
|
|
112
|
+
constant: "#871094",
|
|
113
|
+
type: "#007E8A",
|
|
114
|
+
comment: "#8C8C8C",
|
|
115
|
+
tag: "#008077",
|
|
116
|
+
font
|
|
117
|
+
};
|
|
118
|
+
// src/CodeBlock/CodeBlock.ts
|
|
119
|
+
/** The text without the newlines that end it (a scan from the end: no pattern to backtrack). */
|
|
120
|
+
function withoutTrailingNewlines(text) {
|
|
121
|
+
let end = text.length;
|
|
122
|
+
while (end > 0 && text[end - 1] === "\n") end--;
|
|
123
|
+
return text.slice(0, end);
|
|
124
|
+
}
|
|
125
|
+
const CodeSurface = (0, _gild_ui_vue.styled)(_gild_ui_vue_View.View, {
|
|
126
|
+
name: "CodeBlock",
|
|
127
|
+
slot: "surface",
|
|
128
|
+
label: "CodeSurface"
|
|
129
|
+
})(syntaxStyles);
|
|
130
|
+
const Wrapper = (0, _gild_ui_vue.styled)(_gild_ui_vue_View.View, {
|
|
131
|
+
name: "CodeBlock",
|
|
132
|
+
label: "CodeBlock"
|
|
133
|
+
})({
|
|
134
|
+
display: "grid",
|
|
135
|
+
gridTemplateColumns: "minmax(0, 1fr)",
|
|
136
|
+
"& .code-copy": {
|
|
137
|
+
opacity: 0,
|
|
138
|
+
transition: "opacity 120ms ease"
|
|
139
|
+
},
|
|
140
|
+
"&:hover .code-copy, &:focus-within .code-copy": { opacity: 1 },
|
|
141
|
+
"@media (hover: none)": { "& .code-copy": { opacity: 1 } }
|
|
142
|
+
});
|
|
143
|
+
/** How long the "copied" confirmation stays before reverting, in ms. */
|
|
144
|
+
const COPIED_RESET_MS = 2e3;
|
|
145
|
+
/**
|
|
146
|
+
* Fenced-code block: a horizontally scrollable, syntax-highlighted surface with a copy-to-clipboard
|
|
147
|
+
* button that sticks to the top-right while the block is in view.
|
|
148
|
+
*/
|
|
149
|
+
const CodeBlock = (0, vue.defineComponent)((props, { attrs, slots }) => {
|
|
150
|
+
const control = (0, vue.ref)();
|
|
151
|
+
const copied = (0, vue.ref)(false);
|
|
152
|
+
let timer;
|
|
153
|
+
(0, vue.onBeforeUnmount)(() => clearTimeout(timer));
|
|
154
|
+
const copy = () => {
|
|
155
|
+
const content = control.value?.$el.nextElementSibling?.textContent;
|
|
156
|
+
const text = content && withoutTrailingNewlines(content);
|
|
157
|
+
if (!text || !navigator.clipboard?.writeText) return;
|
|
158
|
+
navigator.clipboard.writeText(text).then(() => {
|
|
159
|
+
clearTimeout(timer);
|
|
160
|
+
copied.value = true;
|
|
161
|
+
timer = setTimeout(() => copied.value = false, COPIED_RESET_MS);
|
|
162
|
+
}, () => void 0);
|
|
163
|
+
};
|
|
164
|
+
return () => {
|
|
165
|
+
const { slotProps, style } = props;
|
|
166
|
+
return (0, vue.h)(Wrapper, {
|
|
167
|
+
my: 2,
|
|
168
|
+
position: "relative",
|
|
169
|
+
...attrs,
|
|
170
|
+
...mergeOverrides(slotProps?.root, {
|
|
171
|
+
style,
|
|
172
|
+
class: attrs.class
|
|
173
|
+
})
|
|
174
|
+
}, () => [(0, vue.h)(_gild_ui_vue_View.View, {
|
|
175
|
+
position: "absolute",
|
|
176
|
+
top: "8px",
|
|
177
|
+
right: "8px",
|
|
178
|
+
zIndex: 1,
|
|
179
|
+
bg: "paper",
|
|
180
|
+
borderRadius: "sm",
|
|
181
|
+
class: "code-copy",
|
|
182
|
+
ref: control
|
|
183
|
+
}, () => (0, vue.h)(_gild_ui_vue_Button.Button, {
|
|
184
|
+
type: "button",
|
|
185
|
+
variant: "outlined",
|
|
186
|
+
color: "default",
|
|
187
|
+
size: "sm",
|
|
188
|
+
borderRadius: "sm",
|
|
189
|
+
onClick: copy,
|
|
190
|
+
"aria-label": copied.value ? "Copied" : "Copy code"
|
|
191
|
+
}, () => copied.value ? (0, vue.h)(CheckIcon, {
|
|
192
|
+
color: "success",
|
|
193
|
+
size: "1.1rem"
|
|
194
|
+
}) : (0, vue.h)(CopyIcon, {
|
|
195
|
+
color: "primary",
|
|
196
|
+
size: "1.1rem"
|
|
197
|
+
}))), (0, vue.h)(CodeSurface, {
|
|
198
|
+
...mergeOverrides(slotProps?.surface),
|
|
199
|
+
as: "pre",
|
|
200
|
+
tabIndex: 0,
|
|
201
|
+
bg: "terminal",
|
|
202
|
+
p: 3,
|
|
203
|
+
borderRadius: "md",
|
|
204
|
+
borderColor: "light",
|
|
205
|
+
borderWidth: "thin",
|
|
206
|
+
maxWidth: "100%",
|
|
207
|
+
overflow: "auto"
|
|
208
|
+
}, slots)]);
|
|
209
|
+
};
|
|
210
|
+
}, {
|
|
211
|
+
name: "CodeBlock",
|
|
212
|
+
inheritAttrs: false,
|
|
213
|
+
props: declare("slotProps", "style"),
|
|
214
|
+
slots: {}
|
|
215
|
+
});
|
|
216
|
+
Object.defineProperty(exports, "CodeBlock", {
|
|
217
|
+
enumerable: true,
|
|
218
|
+
get: function() {
|
|
219
|
+
return CodeBlock;
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
Object.defineProperty(exports, "declare", {
|
|
223
|
+
enumerable: true,
|
|
224
|
+
get: function() {
|
|
225
|
+
return declare;
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
Object.defineProperty(exports, "rootProps", {
|
|
229
|
+
enumerable: true,
|
|
230
|
+
get: function() {
|
|
231
|
+
return rootProps;
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
Object.defineProperty(exports, "syntaxDark", {
|
|
235
|
+
enumerable: true,
|
|
236
|
+
get: function() {
|
|
237
|
+
return syntaxDark;
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
Object.defineProperty(exports, "syntaxLight", {
|
|
241
|
+
enumerable: true,
|
|
242
|
+
get: function() {
|
|
243
|
+
return syntaxLight;
|
|
244
|
+
}
|
|
245
|
+
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_CodeBlock = require("./CodeBlock-NGTCYbfS.cjs");
|
|
3
|
+
exports.CodeBlock = require_CodeBlock.CodeBlock;
|
|
4
|
+
exports.syntaxDark = require_CodeBlock.syntaxDark;
|
|
5
|
+
exports.syntaxLight = require_CodeBlock.syntaxLight;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as ThemeSyntax, i as CodeBlockSlot, n as CodeBlockProps, o as syntaxDark, r as CodeBlockSlots, s as syntaxLight, t as CodeBlock } from "./index-B5H8ATjj.cjs";
|
|
2
|
+
export { CodeBlock, CodeBlockProps, type CodeBlockSlot, CodeBlockSlots, ThemeSyntax, syntaxDark, syntaxLight };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as ThemeSyntax, i as CodeBlockSlot, n as CodeBlockProps, o as syntaxDark, r as CodeBlockSlots, s as syntaxLight, t as CodeBlock } from "./index-KyNhFQ61.mjs";
|
|
2
|
+
export { CodeBlock, CodeBlockProps, type CodeBlockSlot, CodeBlockSlots, ThemeSyntax, syntaxDark, syntaxLight };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as CodeBlock, n as syntaxDark, r as syntaxLight } from "./CodeBlock-C-5omHoJ.mjs";
|