@gild-ui/vue-markdown 0.0.0 → 0.1.0-alpha.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/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
|
@@ -0,0 +1,561 @@
|
|
|
1
|
+
// \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
const require_CodeBlock = require("./CodeBlock-NGTCYbfS.cjs");
|
|
23
|
+
let vue = require("vue");
|
|
24
|
+
let _gild_ui_vue = require("@gild-ui/vue");
|
|
25
|
+
let _gild_ui_vue_View = require("@gild-ui/vue/View");
|
|
26
|
+
let _gild_ui_vue_useTheme = require("@gild-ui/vue/useTheme");
|
|
27
|
+
let _soroush_tech_styled_system = require("@soroush.tech/styled-system");
|
|
28
|
+
let _soroush_tech_styled_system_should_forward_prop = require("@soroush.tech/styled-system/should-forward-prop");
|
|
29
|
+
let _gild_ui_core_theme = require("@gild-ui/core/theme");
|
|
30
|
+
let rehype_highlight = require("rehype-highlight");
|
|
31
|
+
rehype_highlight = __toESM(rehype_highlight, 1);
|
|
32
|
+
let rehype_slug = require("rehype-slug");
|
|
33
|
+
rehype_slug = __toESM(rehype_slug, 1);
|
|
34
|
+
let remark_gfm = require("remark-gfm");
|
|
35
|
+
remark_gfm = __toESM(remark_gfm, 1);
|
|
36
|
+
let remark_parse = require("remark-parse");
|
|
37
|
+
remark_parse = __toESM(remark_parse, 1);
|
|
38
|
+
let remark_rehype = require("remark-rehype");
|
|
39
|
+
remark_rehype = __toESM(remark_rehype, 1);
|
|
40
|
+
let unified = require("unified");
|
|
41
|
+
let property_information = require("property-information");
|
|
42
|
+
let _gild_ui_vue_Typography = require("@gild-ui/vue/Typography");
|
|
43
|
+
// ../react-markdown/src/tree/parseMarkdown.ts
|
|
44
|
+
const processor = (0, unified.unified)().use(remark_parse.default).use(remark_gfm.default).use(remark_rehype.default, { allowDangerousHtml: true }).use(rehype_slug.default).use(rehype_highlight.default);
|
|
45
|
+
function rawToText(parent) {
|
|
46
|
+
for (const [index, child] of parent.children.entries()) if (child.type === "raw") parent.children[index] = {
|
|
47
|
+
type: "text",
|
|
48
|
+
value: child.value
|
|
49
|
+
};
|
|
50
|
+
else if (child.type === "element") rawToText(child);
|
|
51
|
+
}
|
|
52
|
+
/** The tree of a markdown string. */
|
|
53
|
+
function parseMarkdown(source) {
|
|
54
|
+
const tree = processor.runSync(processor.parse(source), source);
|
|
55
|
+
rawToText(tree);
|
|
56
|
+
return tree;
|
|
57
|
+
}
|
|
58
|
+
// ../react-markdown/src/tree/elements.ts
|
|
59
|
+
/** The props of the `Typography` of each element that is text. */
|
|
60
|
+
const TEXT = {
|
|
61
|
+
h1: {
|
|
62
|
+
mt: 2,
|
|
63
|
+
variant: "h1",
|
|
64
|
+
color: "primary",
|
|
65
|
+
gutterBottom: true
|
|
66
|
+
},
|
|
67
|
+
h2: {
|
|
68
|
+
mt: 2,
|
|
69
|
+
variant: "h2",
|
|
70
|
+
color: "primary",
|
|
71
|
+
gutterBottom: true
|
|
72
|
+
},
|
|
73
|
+
h3: {
|
|
74
|
+
mt: 2,
|
|
75
|
+
variant: "h3",
|
|
76
|
+
color: "primary",
|
|
77
|
+
gutterBottom: true
|
|
78
|
+
},
|
|
79
|
+
h4: {
|
|
80
|
+
mt: 2,
|
|
81
|
+
variant: "h4",
|
|
82
|
+
gutterBottom: true
|
|
83
|
+
},
|
|
84
|
+
h5: {
|
|
85
|
+
mt: 2,
|
|
86
|
+
variant: "h5",
|
|
87
|
+
gutterBottom: true
|
|
88
|
+
},
|
|
89
|
+
h6: {
|
|
90
|
+
mt: 2,
|
|
91
|
+
variant: "h6",
|
|
92
|
+
gutterBottom: true
|
|
93
|
+
},
|
|
94
|
+
p: {
|
|
95
|
+
variant: "body1",
|
|
96
|
+
color: "secondary",
|
|
97
|
+
mb: 2,
|
|
98
|
+
lineHeight: "relaxed"
|
|
99
|
+
},
|
|
100
|
+
strong: {
|
|
101
|
+
variant: "inherit",
|
|
102
|
+
fontWeight: "extraBold"
|
|
103
|
+
},
|
|
104
|
+
em: {
|
|
105
|
+
variant: "inherit",
|
|
106
|
+
fontStyle: "italic"
|
|
107
|
+
},
|
|
108
|
+
li: {
|
|
109
|
+
color: "secondary",
|
|
110
|
+
lineHeight: "base",
|
|
111
|
+
variant: "body1",
|
|
112
|
+
gutterBottom: true
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
/** The props of the `View` of each element that is a box. */
|
|
116
|
+
const BOX = {
|
|
117
|
+
ul: {
|
|
118
|
+
pl: 3,
|
|
119
|
+
mb: 2
|
|
120
|
+
},
|
|
121
|
+
ol: {
|
|
122
|
+
pl: 3,
|
|
123
|
+
mb: 2
|
|
124
|
+
},
|
|
125
|
+
blockquote: {
|
|
126
|
+
pl: 3,
|
|
127
|
+
py: 1,
|
|
128
|
+
my: 2
|
|
129
|
+
},
|
|
130
|
+
hr: {
|
|
131
|
+
my: 2,
|
|
132
|
+
height: "1px",
|
|
133
|
+
bg: "grid",
|
|
134
|
+
width: "100%",
|
|
135
|
+
border: "none"
|
|
136
|
+
},
|
|
137
|
+
table: { my: 2 },
|
|
138
|
+
tableBody: {
|
|
139
|
+
bg: "terminal",
|
|
140
|
+
borderRadius: "md"
|
|
141
|
+
},
|
|
142
|
+
thead: {
|
|
143
|
+
bg: "grid",
|
|
144
|
+
color: "primary"
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
/** The props of the `Typography` of a code element: a block takes none of a chip's. */
|
|
148
|
+
const CODE = {
|
|
149
|
+
block: {
|
|
150
|
+
color: "initial",
|
|
151
|
+
variant: "inherit",
|
|
152
|
+
fontFamily: "mono",
|
|
153
|
+
bg: "transparent",
|
|
154
|
+
px: 0
|
|
155
|
+
},
|
|
156
|
+
inline: {
|
|
157
|
+
color: "initial",
|
|
158
|
+
variant: "inherit",
|
|
159
|
+
fontFamily: "mono",
|
|
160
|
+
bg: "paper",
|
|
161
|
+
px: 1
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
const isElement = (node) => node.type === "element";
|
|
165
|
+
/** The class names of an element. */
|
|
166
|
+
const classesOf = (node) => Array.isArray(node.properties.className) ? node.properties.className.map(String) : [];
|
|
167
|
+
/** The elements among the children of an element. */
|
|
168
|
+
const elementsOf = (node, tagName) => node.children.filter(isElement).filter((child) => tagName === void 0 || child.tagName === tagName);
|
|
169
|
+
const TABLE_PARTS = /* @__PURE__ */ new Set([
|
|
170
|
+
"table",
|
|
171
|
+
"thead",
|
|
172
|
+
"tbody",
|
|
173
|
+
"tfoot",
|
|
174
|
+
"tr"
|
|
175
|
+
]);
|
|
176
|
+
/** What an element holds, as a renderer draws it: a part of a table holds its parts only. */
|
|
177
|
+
const childrenOf = (node) => TABLE_PARTS.has(node.tagName) ? elementsOf(node) : node.children;
|
|
178
|
+
/** The language a code element was fenced with (` ```ts ` is `ts`), if it was. */
|
|
179
|
+
const languageOf = (node) => classesOf(node).find((name) => name.startsWith("language-"))?.slice(9);
|
|
180
|
+
/** Whether a list item is a task of a task list (`- [ ] todo`). */
|
|
181
|
+
const isTask = (node) => classesOf(node).includes("task-list-item");
|
|
182
|
+
/** The alignment of a table cell, as its column was written (`:--`, `:-:`, `--:`). */
|
|
183
|
+
function alignOf(cell) {
|
|
184
|
+
const { align } = cell.properties;
|
|
185
|
+
return align === "left" || align === "center" || align === "right" ? align : void 0;
|
|
186
|
+
}
|
|
187
|
+
const SAFE_PROTOCOL = /^(?:https?|ircs?|mailto|xmpp)$/i;
|
|
188
|
+
/** A URL of the document, or `undefined` for one that is not safe (`javascript:`...). A relative one is safe. */
|
|
189
|
+
function safeUrl(value) {
|
|
190
|
+
if (typeof value !== "string") return void 0;
|
|
191
|
+
const colon = value.indexOf(":");
|
|
192
|
+
const before = (mark) => {
|
|
193
|
+
const at = value.indexOf(mark);
|
|
194
|
+
return at !== -1 && colon > at;
|
|
195
|
+
};
|
|
196
|
+
return colon === -1 || before("/") || before("?") || before("#") || SAFE_PROTOCOL.test(value.slice(0, colon)) ? value : void 0;
|
|
197
|
+
}
|
|
198
|
+
// src/Preview/parts.ts
|
|
199
|
+
const underlineStyles = {
|
|
200
|
+
always: { textDecoration: "underline" },
|
|
201
|
+
none: { textDecoration: "none" },
|
|
202
|
+
hover: {
|
|
203
|
+
textDecoration: "none",
|
|
204
|
+
position: "relative",
|
|
205
|
+
"&::after": {
|
|
206
|
+
content: "\"\"",
|
|
207
|
+
position: "absolute",
|
|
208
|
+
bottom: 0,
|
|
209
|
+
left: 0,
|
|
210
|
+
width: "100%",
|
|
211
|
+
height: "1px",
|
|
212
|
+
background: "currentColor",
|
|
213
|
+
transform: "scaleX(0)",
|
|
214
|
+
transformOrigin: "right",
|
|
215
|
+
transition: "transform 0.2s ease"
|
|
216
|
+
},
|
|
217
|
+
"&:hover::after": {
|
|
218
|
+
transform: "scaleX(1)",
|
|
219
|
+
transformOrigin: "left"
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
const Link = (0, _gild_ui_vue.styled)(_gild_ui_vue_Typography.Typography, {
|
|
224
|
+
name: "Link",
|
|
225
|
+
label: "Link"
|
|
226
|
+
})(({ underline = "always" }) => underlineStyles[underline], ({ theme }) => ({
|
|
227
|
+
"&:hover": { color: theme.palette[(0, _gild_ui_core_theme.themeDefault)(theme, "color", "primary")].main },
|
|
228
|
+
"&:focus-visible": {
|
|
229
|
+
outline: `2px solid ${theme.palette[(0, _gild_ui_core_theme.themeDefault)(theme, "color", "primary")].main}`,
|
|
230
|
+
outlineOffset: "4px",
|
|
231
|
+
borderRadius: theme.radii.sm
|
|
232
|
+
}
|
|
233
|
+
}));
|
|
234
|
+
const Quote = (0, _gild_ui_vue.styled)(_gild_ui_vue_View.View, {
|
|
235
|
+
name: "Quote",
|
|
236
|
+
label: "Quote"
|
|
237
|
+
})(({ theme }) => ({ borderLeft: `2px solid ${theme.border.primary}` }));
|
|
238
|
+
const imageSystem = (0, _soroush_tech_styled_system.system)({
|
|
239
|
+
objectFit: { property: "objectFit" },
|
|
240
|
+
objectPosition: { property: "objectPosition" },
|
|
241
|
+
borderRadius: {
|
|
242
|
+
property: "borderRadius",
|
|
243
|
+
scale: "radii"
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
const Image = (0, _gild_ui_vue.styled)("img", {
|
|
247
|
+
name: "Image",
|
|
248
|
+
label: "image",
|
|
249
|
+
shouldForwardProp: (0, _soroush_tech_styled_system_should_forward_prop.createShouldForwardProp)([
|
|
250
|
+
..._soroush_tech_styled_system_should_forward_prop.props,
|
|
251
|
+
"fallback",
|
|
252
|
+
"objectFit",
|
|
253
|
+
"objectPosition",
|
|
254
|
+
"borderRadius"
|
|
255
|
+
]),
|
|
256
|
+
systemProps: [
|
|
257
|
+
_soroush_tech_styled_system.layout,
|
|
258
|
+
_soroush_tech_styled_system.space,
|
|
259
|
+
_soroush_tech_styled_system.background,
|
|
260
|
+
_soroush_tech_styled_system.position,
|
|
261
|
+
imageSystem
|
|
262
|
+
]
|
|
263
|
+
})();
|
|
264
|
+
const colorSystem = (0, _soroush_tech_styled_system.system)({
|
|
265
|
+
color: {
|
|
266
|
+
property: "color",
|
|
267
|
+
scale: "text"
|
|
268
|
+
},
|
|
269
|
+
bg: {
|
|
270
|
+
property: "backgroundColor",
|
|
271
|
+
scale: "background"
|
|
272
|
+
},
|
|
273
|
+
borderColor: {
|
|
274
|
+
property: "borderColor",
|
|
275
|
+
scale: "border"
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
const TableContainer = (0, _gild_ui_vue.styled)(_gild_ui_vue_View.View, {
|
|
279
|
+
name: "TableContainer",
|
|
280
|
+
label: "TableContainer"
|
|
281
|
+
})({
|
|
282
|
+
width: "100%",
|
|
283
|
+
overflowX: "auto"
|
|
284
|
+
});
|
|
285
|
+
const Table = (0, _gild_ui_vue.styled)("table", {
|
|
286
|
+
name: "Table",
|
|
287
|
+
label: "Table",
|
|
288
|
+
shouldForwardProp: (0, _soroush_tech_styled_system_should_forward_prop.createShouldForwardProp)([..._soroush_tech_styled_system_should_forward_prop.props]),
|
|
289
|
+
systemProps: [
|
|
290
|
+
_soroush_tech_styled_system.space,
|
|
291
|
+
_soroush_tech_styled_system.layout,
|
|
292
|
+
colorSystem,
|
|
293
|
+
_soroush_tech_styled_system.border
|
|
294
|
+
]
|
|
295
|
+
})({
|
|
296
|
+
width: "100%",
|
|
297
|
+
borderCollapse: "separate",
|
|
298
|
+
borderSpacing: 0,
|
|
299
|
+
overflow: "hidden"
|
|
300
|
+
});
|
|
301
|
+
const TableHead = (0, _gild_ui_vue.styled)("thead", {
|
|
302
|
+
name: "TableHead",
|
|
303
|
+
label: "TableHead",
|
|
304
|
+
shouldForwardProp: (0, _soroush_tech_styled_system_should_forward_prop.createShouldForwardProp)([..._soroush_tech_styled_system_should_forward_prop.props]),
|
|
305
|
+
systemProps: [colorSystem]
|
|
306
|
+
})();
|
|
307
|
+
const TableRow = (0, _gild_ui_vue.styled)("tr", {
|
|
308
|
+
name: "TableRow",
|
|
309
|
+
label: "TableRow",
|
|
310
|
+
shouldForwardProp: (0, _soroush_tech_styled_system_should_forward_prop.createShouldForwardProp)([..._soroush_tech_styled_system_should_forward_prop.props]),
|
|
311
|
+
systemProps: [
|
|
312
|
+
_soroush_tech_styled_system.space,
|
|
313
|
+
_soroush_tech_styled_system.border,
|
|
314
|
+
colorSystem
|
|
315
|
+
]
|
|
316
|
+
})(({ theme }) => ({ "&:hover": {
|
|
317
|
+
backgroundColor: theme.palette[(0, _gild_ui_core_theme.themeDefault)(theme, "color", "primary")].light,
|
|
318
|
+
color: theme.palette[(0, _gild_ui_core_theme.themeDefault)(theme, "color", "primary")].contrastText
|
|
319
|
+
} }));
|
|
320
|
+
const TableCell = (0, _gild_ui_vue.styled)("td", {
|
|
321
|
+
name: "TableCell",
|
|
322
|
+
label: "TableCell",
|
|
323
|
+
shouldForwardProp: (0, _soroush_tech_styled_system_should_forward_prop.createShouldForwardProp)([..._soroush_tech_styled_system_should_forward_prop.props, "align"]),
|
|
324
|
+
systemProps: [
|
|
325
|
+
_soroush_tech_styled_system.space,
|
|
326
|
+
colorSystem,
|
|
327
|
+
_soroush_tech_styled_system.border
|
|
328
|
+
]
|
|
329
|
+
})(({ theme, align = "inherit" }) => {
|
|
330
|
+
const size = theme.sizes[(0, _gild_ui_core_theme.themeDefault)(theme, "size", "md")];
|
|
331
|
+
return {
|
|
332
|
+
padding: `${theme.space[size.paddingTop]} ${theme.space[size.paddingRight]} ${theme.space[size.paddingBottom]} ${theme.space[size.paddingLeft]}`,
|
|
333
|
+
fontSize: theme.fontSizes[size.fontSize],
|
|
334
|
+
textAlign: align,
|
|
335
|
+
borderBottom: `1px solid ${theme.border.light}`
|
|
336
|
+
};
|
|
337
|
+
});
|
|
338
|
+
const Checkbox = (0, _gild_ui_vue.styled)("label", {
|
|
339
|
+
name: "Checkbox",
|
|
340
|
+
label: "Checkbox",
|
|
341
|
+
shouldForwardProp: (0, _soroush_tech_styled_system_should_forward_prop.createShouldForwardProp)([..._soroush_tech_styled_system_should_forward_prop.props]),
|
|
342
|
+
systemProps: [_soroush_tech_styled_system.space]
|
|
343
|
+
})(({ theme }) => ({
|
|
344
|
+
display: "inline-flex",
|
|
345
|
+
alignItems: "center",
|
|
346
|
+
verticalAlign: "middle",
|
|
347
|
+
color: theme.palette.primary.main,
|
|
348
|
+
fontSize: "1.25em"
|
|
349
|
+
}));
|
|
350
|
+
const CheckboxInput = (0, _gild_ui_vue.styled)("input", {
|
|
351
|
+
name: "Checkbox",
|
|
352
|
+
slot: "input",
|
|
353
|
+
label: "CheckboxInput"
|
|
354
|
+
})({
|
|
355
|
+
position: "absolute",
|
|
356
|
+
opacity: 0,
|
|
357
|
+
width: 0,
|
|
358
|
+
height: 0
|
|
359
|
+
});
|
|
360
|
+
const CheckboxIcon = (0, _gild_ui_vue.styled)("span", {
|
|
361
|
+
name: "Checkbox",
|
|
362
|
+
slot: "icon",
|
|
363
|
+
label: "CheckboxIcon"
|
|
364
|
+
})({
|
|
365
|
+
display: "inline-flex",
|
|
366
|
+
"& .cb-checked, & .cb-indeterminate": { display: "none" },
|
|
367
|
+
"input:checked + &": {
|
|
368
|
+
"& .cb-unchecked": { display: "none" },
|
|
369
|
+
"& .cb-checked": { display: "inline-flex" }
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
const mark = (className, svg, ...shapes) => (0, vue.h)("span", { class: className }, (0, vue.h)("svg", {
|
|
373
|
+
viewBox: "0 0 18 18",
|
|
374
|
+
width: "1em",
|
|
375
|
+
height: "1em",
|
|
376
|
+
...svg,
|
|
377
|
+
"aria-hidden": "true"
|
|
378
|
+
}, shapes));
|
|
379
|
+
/** The read-only checkbox of a task of a task list. */
|
|
380
|
+
const checkbox = (checked, attributes) => (0, vue.h)(Checkbox, { ...attributes }, () => [(0, vue.h)(CheckboxInput, {
|
|
381
|
+
type: "checkbox",
|
|
382
|
+
disabled: true,
|
|
383
|
+
"aria-label": "Task item",
|
|
384
|
+
checked
|
|
385
|
+
}), (0, vue.h)(CheckboxIcon, null, () => [
|
|
386
|
+
mark("cb-unchecked", { fill: "none" }, (0, vue.h)("rect", {
|
|
387
|
+
x: "1.5",
|
|
388
|
+
y: "1.5",
|
|
389
|
+
width: "15",
|
|
390
|
+
height: "15",
|
|
391
|
+
rx: "2.5",
|
|
392
|
+
stroke: "currentColor",
|
|
393
|
+
"stroke-width": "1.5"
|
|
394
|
+
})),
|
|
395
|
+
mark("cb-checked", {}, (0, vue.h)("rect", {
|
|
396
|
+
width: "18",
|
|
397
|
+
height: "18",
|
|
398
|
+
rx: "3",
|
|
399
|
+
fill: "currentColor"
|
|
400
|
+
}), (0, vue.h)("path", {
|
|
401
|
+
d: "M4.5 9L7.5 12L13.5 6",
|
|
402
|
+
stroke: "white",
|
|
403
|
+
"stroke-width": "1.8",
|
|
404
|
+
"stroke-linecap": "round",
|
|
405
|
+
"stroke-linejoin": "round",
|
|
406
|
+
fill: "none"
|
|
407
|
+
})),
|
|
408
|
+
mark("cb-indeterminate", {}, (0, vue.h)("rect", {
|
|
409
|
+
width: "18",
|
|
410
|
+
height: "18",
|
|
411
|
+
rx: "3",
|
|
412
|
+
fill: "currentColor"
|
|
413
|
+
}), (0, vue.h)("rect", {
|
|
414
|
+
x: "4.5",
|
|
415
|
+
y: "8.1",
|
|
416
|
+
width: "9",
|
|
417
|
+
height: "1.8",
|
|
418
|
+
rx: "0.9",
|
|
419
|
+
fill: "white"
|
|
420
|
+
}))
|
|
421
|
+
])]);
|
|
422
|
+
// src/Preview/render.ts
|
|
423
|
+
const taskItem = _gild_ui_vue.StyleSheet.create({ item: { listStyleType: "none" } });
|
|
424
|
+
const isTextTag = (tag) => Object.hasOwn(TEXT, tag);
|
|
425
|
+
const isHeading = (tag) => /^h[1-6]$/.test(tag);
|
|
426
|
+
const isBoxTag = (tag) => tag === "ul" || tag === "ol";
|
|
427
|
+
/** The attributes of an element of the tree, as the element takes them. */
|
|
428
|
+
function attributesOf(node) {
|
|
429
|
+
return Object.fromEntries(Object.entries(node.properties).map(([name, value]) => {
|
|
430
|
+
return [(0, property_information.find)(property_information.html, name).attribute, Array.isArray(value) ? value.join(" ") : value];
|
|
431
|
+
}));
|
|
432
|
+
}
|
|
433
|
+
function renderElement(node, context) {
|
|
434
|
+
const { slotProps } = context;
|
|
435
|
+
const { tagName, properties } = node;
|
|
436
|
+
const children = () => childrenOf(node).map((child) => renderNode(child, context));
|
|
437
|
+
if (isTextTag(tagName)) {
|
|
438
|
+
const as = isHeading(tagName) || tagName === "p" ? void 0 : tagName;
|
|
439
|
+
return (0, vue.h)(_gild_ui_vue_Typography.Typography, {
|
|
440
|
+
id: isHeading(tagName) ? properties.id : void 0,
|
|
441
|
+
as,
|
|
442
|
+
...TEXT[tagName],
|
|
443
|
+
...tagName === "li" && isTask(node) ? { style: taskItem.item } : {},
|
|
444
|
+
...slotProps[tagName]
|
|
445
|
+
}, children);
|
|
446
|
+
}
|
|
447
|
+
if (isBoxTag(tagName)) return (0, vue.h)(_gild_ui_vue_View.View, {
|
|
448
|
+
as: tagName,
|
|
449
|
+
...BOX[tagName],
|
|
450
|
+
...slotProps[tagName]
|
|
451
|
+
}, children);
|
|
452
|
+
switch (tagName) {
|
|
453
|
+
case "a": return (0, vue.h)(Link, {
|
|
454
|
+
as: "a",
|
|
455
|
+
href: safeUrl(properties.href),
|
|
456
|
+
underline: "hover",
|
|
457
|
+
color: context.accent,
|
|
458
|
+
variant: "inherit",
|
|
459
|
+
...slotProps.a
|
|
460
|
+
}, children);
|
|
461
|
+
case "blockquote": return (0, vue.h)(Quote, {
|
|
462
|
+
as: "blockquote",
|
|
463
|
+
...BOX.blockquote,
|
|
464
|
+
...slotProps.blockquote
|
|
465
|
+
}, children);
|
|
466
|
+
case "input": return checkbox(Boolean(properties.checked), {
|
|
467
|
+
mr: 1,
|
|
468
|
+
...slotProps.input
|
|
469
|
+
});
|
|
470
|
+
case "code": {
|
|
471
|
+
const isBlock = languageOf(node) !== void 0;
|
|
472
|
+
return (0, vue.h)(_gild_ui_vue_Typography.Typography, {
|
|
473
|
+
as: "code",
|
|
474
|
+
class: classesOf(node),
|
|
475
|
+
...CODE[isBlock ? "block" : "inline"],
|
|
476
|
+
display: isBlock ? "block" : "inline",
|
|
477
|
+
borderRadius: "sm",
|
|
478
|
+
...slotProps.code
|
|
479
|
+
}, children);
|
|
480
|
+
}
|
|
481
|
+
case "pre": return (0, vue.h)(require_CodeBlock.CodeBlock, { ...slotProps.pre }, children);
|
|
482
|
+
case "table": return (0, vue.h)(TableContainer, { my: BOX.table.my }, () => (0, vue.h)(Table, {
|
|
483
|
+
...BOX.tableBody,
|
|
484
|
+
...slotProps.table
|
|
485
|
+
}, children));
|
|
486
|
+
case "thead": return (0, vue.h)(TableHead, {
|
|
487
|
+
...BOX.thead,
|
|
488
|
+
...slotProps.thead
|
|
489
|
+
}, children);
|
|
490
|
+
case "tbody": return (0, vue.h)("tbody", { ...slotProps.tbody }, children());
|
|
491
|
+
case "tr": return (0, vue.h)(TableRow, { ...slotProps.tr }, children);
|
|
492
|
+
case "th": return (0, vue.h)(TableCell, {
|
|
493
|
+
as: "th",
|
|
494
|
+
scope: "col",
|
|
495
|
+
align: alignOf(node),
|
|
496
|
+
...slotProps.th
|
|
497
|
+
}, children);
|
|
498
|
+
case "td": return (0, vue.h)(TableCell, {
|
|
499
|
+
align: alignOf(node),
|
|
500
|
+
...slotProps.td
|
|
501
|
+
}, children);
|
|
502
|
+
case "hr": return (0, vue.h)(_gild_ui_vue_View.View, {
|
|
503
|
+
as: "hr",
|
|
504
|
+
...BOX.hr,
|
|
505
|
+
...slotProps.hr
|
|
506
|
+
});
|
|
507
|
+
case "img": return (0, vue.h)(Image, {
|
|
508
|
+
src: safeUrl(properties.src),
|
|
509
|
+
alt: properties.alt,
|
|
510
|
+
maxWidth: "100%",
|
|
511
|
+
...slotProps.img
|
|
512
|
+
});
|
|
513
|
+
default: return (0, vue.h)(tagName, attributesOf(node), children());
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
function renderNode(node, context) {
|
|
517
|
+
if (node.type === "text") return node.value;
|
|
518
|
+
return isElement(node) ? renderElement(node, context) : null;
|
|
519
|
+
}
|
|
520
|
+
/** The nodes of a tree as Vue nodes. */
|
|
521
|
+
const renderNodes = (nodes, context) => nodes.map((node) => renderNode(node, context));
|
|
522
|
+
// src/Preview/Preview.ts
|
|
523
|
+
const PreviewRoot = (0, _gild_ui_vue.styled)(_gild_ui_vue_View.View, {
|
|
524
|
+
name: "MarkdownPreview",
|
|
525
|
+
label: "MarkdownPreview"
|
|
526
|
+
})({
|
|
527
|
+
minWidth: 0,
|
|
528
|
+
maxWidth: "100%",
|
|
529
|
+
overflowWrap: "break-word"
|
|
530
|
+
});
|
|
531
|
+
/** The text of what a slot holds: the markdown source. */
|
|
532
|
+
function sourceOf(child) {
|
|
533
|
+
if (Array.isArray(child)) return child.map(sourceOf).join("");
|
|
534
|
+
if (typeof child === "string") return child;
|
|
535
|
+
if (!(0, vue.isVNode)(child) || child.type === vue.Comment) return "";
|
|
536
|
+
if (typeof child.children === "string") return child.children;
|
|
537
|
+
return Array.isArray(child.children) ? sourceOf(child.children) : "";
|
|
538
|
+
}
|
|
539
|
+
/** Renders a markdown string - the default slot - with every element drawn by a primitive of the design system. */
|
|
540
|
+
const Preview = (0, vue.defineComponent)((props, { attrs, slots }) => {
|
|
541
|
+
const theme = (0, _gild_ui_vue_useTheme.useTheme)();
|
|
542
|
+
return () => {
|
|
543
|
+
const tree = parseMarkdown(sourceOf(slots.default?.()));
|
|
544
|
+
const context = {
|
|
545
|
+
slotProps: props.slotProps ?? {},
|
|
546
|
+
accent: (0, _gild_ui_core_theme.themeDefault)(theme.value, "accentTextColor", "primary")
|
|
547
|
+
};
|
|
548
|
+
return (0, vue.h)(PreviewRoot, require_CodeBlock.rootProps(props, attrs), () => renderNodes(tree.children, context));
|
|
549
|
+
};
|
|
550
|
+
}, {
|
|
551
|
+
name: "MarkdownPreview",
|
|
552
|
+
inheritAttrs: false,
|
|
553
|
+
props: require_CodeBlock.declare("slotProps", "style"),
|
|
554
|
+
slots: {}
|
|
555
|
+
});
|
|
556
|
+
Object.defineProperty(exports, "Preview", {
|
|
557
|
+
enumerable: true,
|
|
558
|
+
get: function() {
|
|
559
|
+
return Preview;
|
|
560
|
+
}
|
|
561
|
+
});
|
package/dist/Preview.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as PreviewSlotProps, i as PreviewProps, n as ImageProps, o as PreviewSlots, r as LinkProps, s as TableCellProps, t as Preview } from "./index-B8VJeFJ1.cjs";
|
|
2
|
+
export { type ImageProps, type LinkProps, Preview, type PreviewProps, type PreviewSlotProps, type PreviewSlots, type TableCellProps };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as PreviewSlotProps, i as PreviewProps, n as ImageProps, o as PreviewSlots, r as LinkProps, s as TableCellProps, t as Preview } from "./index-DTkt5qf4.mjs";
|
|
2
|
+
export { type ImageProps, type LinkProps, Preview, type PreviewProps, type PreviewSlotProps, type PreviewSlots, type TableCellProps };
|
package/dist/Preview.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as Preview } from "./Preview-CDeDFn2m.mjs";
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { ComponentConfig, SlotProps } from "@gild-ui/vue";
|
|
2
|
+
import { SlotsType, VNodeChild } from "vue";
|
|
3
|
+
import { ViewProps } from "@gild-ui/vue/View";
|
|
4
|
+
/**
|
|
5
|
+
* Syntax-highlighting tokens for `CodeBlock` - mapped onto highlight.js token classes.
|
|
6
|
+
* Not part of design-system's own scales; `../themeTypes.ts` augments
|
|
7
|
+
* `@gild-ui/core/theme` so `theme.syntax` is available wherever this
|
|
8
|
+
* package is imported. Merge one of the presets below into your theme via
|
|
9
|
+
* `createTheme(baseTheme, { syntax: syntaxDark })`, or supply your own.
|
|
10
|
+
*/
|
|
11
|
+
interface ThemeSyntax {
|
|
12
|
+
/** Default code text - plain identifiers, operators, punctuation. */
|
|
13
|
+
base: string;
|
|
14
|
+
/** Keywords, built-ins, types, literals, selector tags. */
|
|
15
|
+
keyword: string;
|
|
16
|
+
/** Strings, template literals, regular expressions. */
|
|
17
|
+
string: string;
|
|
18
|
+
/** Numbers, symbols, links. */
|
|
19
|
+
number: string;
|
|
20
|
+
/** Function / class titles, section headings, attributes. */
|
|
21
|
+
title: string;
|
|
22
|
+
/** Fields, constants, and property keys. */
|
|
23
|
+
constant: string;
|
|
24
|
+
/** Type and class names. */
|
|
25
|
+
type: string;
|
|
26
|
+
/** Comments and quotes - rendered dimmed and italic. */
|
|
27
|
+
comment: string;
|
|
28
|
+
/** Markup tags/names, meta, variables, deletions. */
|
|
29
|
+
tag: string;
|
|
30
|
+
/** Font family for the code surface - independent of `theme.fonts.mono`. */
|
|
31
|
+
font: string;
|
|
32
|
+
}
|
|
33
|
+
/** Matched to the JetBrains "Islands Dark" editor scheme. */
|
|
34
|
+
declare const syntaxDark: ThemeSyntax;
|
|
35
|
+
/** Matched to the JetBrains "Islands Light" editor scheme. */
|
|
36
|
+
declare const syntaxLight: ThemeSyntax;
|
|
37
|
+
/** The slots of `CodeBlock` a theme can style, and `slotProps` can override. */
|
|
38
|
+
type CodeBlockSlot = 'root' | 'surface';
|
|
39
|
+
declare module '@gild-ui/vue' {
|
|
40
|
+
interface ThemeComponents {
|
|
41
|
+
MarkdownPreview?: ComponentConfig;
|
|
42
|
+
CodeBlock?: ComponentConfig<Record<string, unknown>, CodeBlockSlot>;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
declare module '@gild-ui/core/theme' {
|
|
46
|
+
interface Theme {
|
|
47
|
+
/**
|
|
48
|
+
* Syntax-highlighting tokens for `CodeBlock` - see `syntaxDark`/`syntaxLight`. Optional only so the
|
|
49
|
+
* base theme still satisfies `Theme`; `CodeBlock` requires it in practice (no fallback).
|
|
50
|
+
*/
|
|
51
|
+
syntax?: ThemeSyntax;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** The props of `CodeBlock`: those of `View`, and the slots a theme can style. */
|
|
55
|
+
type CodeBlockProps = Omit<ViewProps, 'slotProps'> & {
|
|
56
|
+
/** Overrides for the slots a theme can style: `style`, `className`, `data-*` and `aria-*`. */
|
|
57
|
+
slotProps?: SlotProps<CodeBlockSlot>;
|
|
58
|
+
};
|
|
59
|
+
/** The slots of the `CodeBlock` component: the code. */
|
|
60
|
+
interface CodeBlockSlots {
|
|
61
|
+
default?: () => VNodeChild;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Fenced-code block: a horizontally scrollable, syntax-highlighted surface with a copy-to-clipboard
|
|
65
|
+
* button that sticks to the top-right while the block is in view.
|
|
66
|
+
*/
|
|
67
|
+
declare const CodeBlock: import("vue").DefineSetupFnComponent<CodeBlockProps, Record<never, never>, SlotsType<CodeBlockSlots>, Omit<ViewProps, "slotProps"> & {
|
|
68
|
+
/** Overrides for the slots a theme can style: `style`, `className`, `data-*` and `aria-*`. */
|
|
69
|
+
slotProps?: SlotProps<CodeBlockSlot>;
|
|
70
|
+
} & {}, import("vue").PublicProps>;
|
|
71
|
+
export { ThemeSyntax as a, CodeBlockSlot as i, CodeBlockProps as n, syntaxDark as o, CodeBlockSlots as r, syntaxLight as s, CodeBlock as t };
|