@unterberg/nivel 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/assets/nivel/brands/bluesky.svg +4 -0
  2. package/assets/nivel/brands/discord.svg +3 -0
  3. package/assets/nivel/brands/github.svg +2 -0
  4. package/assets/nivel/brands/linkedin.svg +3 -0
  5. package/assets/nivel/brands/typescript.svg +26 -0
  6. package/assets/nivel/brands/x.svg +4 -0
  7. package/assets/nivel/decorators/pattern-light.png +0 -0
  8. package/assets/nivel/decorators/pattern.png +0 -0
  9. package/assets/nivel/fonts/fonts-inter.css +26 -0
  10. package/assets/nivel/fonts/inter-v20-latin-600.woff2 +0 -0
  11. package/assets/nivel/fonts/inter-v20-latin-800.woff2 +0 -0
  12. package/assets/nivel/fonts/inter-v20-latin-regular.woff2 +0 -0
  13. package/dist/chunk-3JJ6TYWL.js +614 -0
  14. package/dist/chunk-3JJ6TYWL.js.map +1 -0
  15. package/dist/chunk-45CLUNJW.js +657 -0
  16. package/dist/chunk-45CLUNJW.js.map +1 -0
  17. package/dist/chunk-4WTEOEV2.js +36 -0
  18. package/dist/chunk-4WTEOEV2.js.map +1 -0
  19. package/dist/chunk-62MBEYU7.js +1091 -0
  20. package/dist/chunk-62MBEYU7.js.map +1 -0
  21. package/dist/chunk-73NPVCDQ.js +353 -0
  22. package/dist/chunk-73NPVCDQ.js.map +1 -0
  23. package/dist/chunk-FLO5CJZH.js +42 -0
  24. package/dist/chunk-FLO5CJZH.js.map +1 -0
  25. package/dist/chunk-PHHK2BAF.js +350 -0
  26. package/dist/chunk-PHHK2BAF.js.map +1 -0
  27. package/dist/client.d.ts +70 -0
  28. package/dist/client.js +26 -0
  29. package/dist/client.js.map +1 -0
  30. package/dist/code-blocks.d.ts +35 -0
  31. package/dist/code-blocks.js +21 -0
  32. package/dist/code-blocks.js.map +1 -0
  33. package/dist/config.d.ts +16 -0
  34. package/dist/config.js +101 -0
  35. package/dist/config.js.map +1 -0
  36. package/dist/index.d.ts +143 -0
  37. package/dist/index.js +45 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/mdx.d.ts +6 -0
  40. package/dist/mdx.js +35 -0
  41. package/dist/mdx.js.map +1 -0
  42. package/dist/runtime/client.d.ts +7 -0
  43. package/dist/runtime/client.js +26 -0
  44. package/dist/runtime/client.js.map +1 -0
  45. package/dist/runtime/index.d.ts +15 -0
  46. package/dist/runtime/index.js +18 -0
  47. package/dist/runtime/index.js.map +1 -0
  48. package/dist/types-mvLNHHrf.d.ts +177 -0
  49. package/package.json +90 -0
@@ -0,0 +1,657 @@
1
+ // src/components/code-blocks/index.ts
2
+ import { transformerNotationHighlight } from "@brillout/shiki-transformers";
3
+ import { transformerNotationDiff, transformerNotationWordHighlight } from "@shikijs/transformers";
4
+ import rehypePrettyCode from "rehype-pretty-code";
5
+ import remarkDirective from "remark-directive";
6
+
7
+ // src/components/code-blocks/rehypeMetaToProps.ts
8
+ import { visit } from "unist-util-visit";
9
+
10
+ // src/components/code-blocks/meta.ts
11
+ var kebabCase = (value) => {
12
+ return value.replace(/([a-z])([A-Z])/g, "$1-$2").replaceAll("_", "-").toLowerCase();
13
+ };
14
+ var KEY_VALUE_PAIR_RE = /(?<name>[a-zA-Z_-]+)(?:=([^"'\s]+))?/g;
15
+ var RESERVED_CODE_BLOCK_META_NAMES = /* @__PURE__ */ new Set([
16
+ "choice",
17
+ "file-added",
18
+ "file-removed",
19
+ "hide-menu",
20
+ "max-width",
21
+ "ts-only"
22
+ ]);
23
+ var parseMetaString = (meta, propNames) => {
24
+ if (typeof meta !== "string" || meta.trim() === "") {
25
+ return { props: {}, rest: "", tokens: [] };
26
+ }
27
+ const props = {};
28
+ const tokens = [];
29
+ const rest = meta.replaceAll(KEY_VALUE_PAIR_RE, (match, name, value) => {
30
+ const normalizedName = kebabCase(name);
31
+ tokens.push({
32
+ hasExplicitValue: value !== void 0,
33
+ name: normalizedName,
34
+ raw: match,
35
+ value
36
+ });
37
+ if (propNames && !propNames.includes(normalizedName)) {
38
+ return match;
39
+ }
40
+ props[normalizedName] = value || "true";
41
+ return "";
42
+ });
43
+ return {
44
+ props,
45
+ rest: rest.trim(),
46
+ tokens
47
+ };
48
+ };
49
+ var getCodeBlockPropsFromMeta = (meta) => {
50
+ const parsed = parseMetaString(meta);
51
+ const props = { ...parsed.props };
52
+ const implicitTitleToken = parsed.tokens.find(
53
+ (token) => !token.hasExplicitValue && !RESERVED_CODE_BLOCK_META_NAMES.has(token.name)
54
+ );
55
+ const explicitTitle = typeof props.title === "string" && props.title.trim() ? props.title.trim() : null;
56
+ delete props.title;
57
+ if (implicitTitleToken) {
58
+ delete props[implicitTitleToken.name];
59
+ }
60
+ return {
61
+ props,
62
+ title: explicitTitle ?? implicitTitleToken?.raw.trim() ?? null
63
+ };
64
+ };
65
+
66
+ // src/components/code-blocks/rehypeMetaToProps.ts
67
+ var rehypeMetaToProps = () => {
68
+ return (tree) => {
69
+ visit(tree, "element", (node, _index, parent) => {
70
+ if (node.tagName !== "code" || parent?.type !== "element" || parent.tagName !== "pre") {
71
+ return;
72
+ }
73
+ const meta = getCodeBlockPropsFromMeta(node.data?.meta);
74
+ parent.properties ??= {};
75
+ parent.properties = {
76
+ ...parent.properties,
77
+ ...meta.props,
78
+ ...meta.title ? { "data-code-title": meta.title } : {}
79
+ };
80
+ });
81
+ };
82
+ };
83
+
84
+ // src/components/code-blocks/remarkChoiceGroup.ts
85
+ import { visit as visit2 } from "unist-util-visit";
86
+
87
+ // src/components/code-blocks/generateChoiceGroupCode.ts
88
+ import { valueToEstree } from "estree-util-value-to-estree";
89
+ var BUILT_IN_CHOICE_GROUPS = {
90
+ codeLang: {
91
+ choices: ["JavaScript", "TypeScript"],
92
+ default: "JavaScript"
93
+ },
94
+ pkgManager: {
95
+ choices: ["npm", "pnpm", "Bun", "Yarn"],
96
+ default: "npm"
97
+ }
98
+ };
99
+ var getChoiceGroup = (choicesRaw) => {
100
+ const choices = [...new Set(choicesRaw.filter(Boolean))];
101
+ for (const [name, group] of Object.entries(BUILT_IN_CHOICE_GROUPS)) {
102
+ if (!choices.every((choice) => group.choices.includes(choice))) {
103
+ continue;
104
+ }
105
+ return {
106
+ name,
107
+ choices: group.choices,
108
+ default: group.default,
109
+ disabled: group.choices.filter((choice) => !choices.includes(choice))
110
+ };
111
+ }
112
+ return {
113
+ name: `custom:${choices.join("|")}`,
114
+ choices,
115
+ default: choices[0] ?? "",
116
+ disabled: []
117
+ };
118
+ };
119
+ var generateChoiceGroupCode = (choiceNodes, parent) => {
120
+ const choiceGroup = getChoiceGroup(choiceNodes.map((choiceNode) => choiceNode.choiceValue));
121
+ const mergedChoiceNodes = choiceGroup.choices.map((choice) => {
122
+ const choiceNode = choiceNodes.find((node) => node.choiceValue === choice);
123
+ return {
124
+ choiceValue: choice,
125
+ children: choiceNode?.children ?? []
126
+ };
127
+ });
128
+ const attributes = [
129
+ {
130
+ type: "mdxJsxAttribute",
131
+ name: "choiceGroup",
132
+ value: {
133
+ type: "mdxJsxAttributeValueExpression",
134
+ value: "",
135
+ data: {
136
+ estree: {
137
+ type: "Program",
138
+ sourceType: "module",
139
+ comments: [],
140
+ body: [
141
+ {
142
+ type: "ExpressionStatement",
143
+ expression: valueToEstree(choiceGroup)
144
+ }
145
+ ]
146
+ }
147
+ }
148
+ }
149
+ }
150
+ ];
151
+ if (choiceNodes.length === 1) {
152
+ attributes.push({ type: "mdxJsxAttribute", name: "hide" });
153
+ }
154
+ attributes.push({
155
+ type: "mdxJsxAttribute",
156
+ name: "lvl",
157
+ value: `${parent?.type === "mdxJsxFlowElement" ? 1 : 0}`
158
+ });
159
+ const children = mergedChoiceNodes.map((choiceNode) => {
160
+ const choiceChildren = choiceNode.children.length > 0 && choiceNode.children.every((node) => node.type === "containerDirective") ? choiceNode.children.flatMap((node) => node.children ?? []) : choiceNode.children;
161
+ for (const child of choiceChildren) {
162
+ increaseLvl(child);
163
+ }
164
+ return {
165
+ type: "mdxJsxFlowElement",
166
+ name: "div",
167
+ attributes: [
168
+ {
169
+ type: "mdxJsxAttribute",
170
+ name: "data-choice-value",
171
+ value: choiceNode.choiceValue
172
+ },
173
+ { type: "mdxJsxAttribute", name: "className", value: "choice" }
174
+ ],
175
+ children: choiceChildren
176
+ };
177
+ });
178
+ return {
179
+ type: "mdxJsxFlowElement",
180
+ name: "ChoiceGroup",
181
+ attributes,
182
+ children
183
+ };
184
+ };
185
+ var increaseLvl = (node) => {
186
+ if (node?.type !== "mdxJsxFlowElement" || node.name !== "ChoiceGroup") {
187
+ return;
188
+ }
189
+ const attribute = node.attributes.find(
190
+ (candidate) => candidate.type === "mdxJsxAttribute" && candidate.name === "lvl"
191
+ );
192
+ if (typeof attribute?.value === "string") {
193
+ attribute.value = `${Number(attribute.value) + 1}`;
194
+ }
195
+ };
196
+
197
+ // src/components/code-blocks/remarkChoiceGroup.ts
198
+ var remarkChoiceGroup = () => {
199
+ return (tree) => {
200
+ visit2(tree, (node) => {
201
+ if (node.type === "code" && node.meta) {
202
+ const meta = parseMetaString(node.meta, ["choice"]);
203
+ const choice = meta.props.choice;
204
+ node.meta = meta.rest;
205
+ if (choice) {
206
+ node.data ??= {};
207
+ node.data.customDataChoice = choice;
208
+ node.data.customDataFilter = "explicitChoice";
209
+ }
210
+ }
211
+ if (node.type === "containerDirective" && node.name === "Choice") {
212
+ const choice = typeof node.attributes?.id === "string" ? node.attributes.id : null;
213
+ if (!choice) {
214
+ return;
215
+ }
216
+ node.data ??= {};
217
+ node.data.customDataChoice = choice;
218
+ node.data.customDataFilter = node.type;
219
+ node.attributes = {};
220
+ }
221
+ });
222
+ visit2(tree, (node) => {
223
+ if (!Array.isArray(node.children)) {
224
+ return;
225
+ }
226
+ let start = -1;
227
+ let end = 0;
228
+ const processRange = () => {
229
+ if (start === -1 || start === end) {
230
+ return;
231
+ }
232
+ const nodes = node.children.slice(start, end);
233
+ const replacements = filterChoices(nodes).map((choiceNodes) => generateChoiceGroupCode(choiceNodes, node));
234
+ node.children.splice(start, end - start, ...replacements);
235
+ end = start + replacements.length;
236
+ start = -1;
237
+ };
238
+ for (; end < node.children.length; end += 1) {
239
+ const child = node.children[end];
240
+ if (!["code", "mdxJsxFlowElement", "containerDirective"].includes(child?.type)) {
241
+ processRange();
242
+ continue;
243
+ }
244
+ if (!child.data?.customDataChoice) {
245
+ processRange();
246
+ continue;
247
+ }
248
+ if (start === -1) {
249
+ start = end;
250
+ }
251
+ }
252
+ processRange();
253
+ });
254
+ };
255
+ };
256
+ var filterChoices = (nodes) => {
257
+ const filteredChoices = [];
258
+ const filters = [...new Set(nodes.map((node) => node.data?.customDataFilter).filter(Boolean))];
259
+ for (const filter of filters) {
260
+ const nodesByChoice = /* @__PURE__ */ new Map();
261
+ for (const node of nodes.filter((candidate) => candidate.data?.customDataFilter === filter)) {
262
+ const choice = node.data?.customDataChoice;
263
+ if (!choice) {
264
+ continue;
265
+ }
266
+ node.data.customDataChoice = void 0;
267
+ const choiceNodes = nodesByChoice.get(choice) ?? [];
268
+ choiceNodes.push(node);
269
+ nodesByChoice.set(choice, choiceNodes);
270
+ }
271
+ filteredChoices.push(
272
+ [...nodesByChoice].map(([choiceValue, children]) => ({
273
+ choiceValue,
274
+ children
275
+ }))
276
+ );
277
+ }
278
+ return filteredChoices;
279
+ };
280
+
281
+ // src/components/code-blocks/remarkDetype.ts
282
+ import { transform as detype } from "detype";
283
+ import { visit as visit3 } from "unist-util-visit";
284
+ var prettierOptions = {
285
+ semi: false,
286
+ singleQuote: true,
287
+ trailingComma: "none"
288
+ };
289
+ var remarkDetype = () => {
290
+ return async (tree, file) => {
291
+ const codeNodes = [];
292
+ visit3(tree, "code", (node, index, parent) => {
293
+ if (!parent || typeof index !== "number") {
294
+ return;
295
+ }
296
+ if (!["ts", "tsx", "vue", "yaml"].includes(node.lang ?? "")) {
297
+ return;
298
+ }
299
+ if (typeof node.meta === "string" && node.meta.includes("ts-only")) {
300
+ return;
301
+ }
302
+ codeNodes.push({ codeBlock: node, index, parent });
303
+ });
304
+ for (const node of [...codeNodes].reverse()) {
305
+ if (node.codeBlock.lang === "yaml") {
306
+ transformYaml(node);
307
+ } else {
308
+ await transformTsToJs(node, file);
309
+ }
310
+ }
311
+ };
312
+ };
313
+ var transformYaml = (node) => {
314
+ const { codeBlock, index, parent } = node;
315
+ const codeBlockContentJs = replaceFileNameSuffixes(codeBlock.value);
316
+ if (codeBlockContentJs === codeBlock.value) {
317
+ return;
318
+ }
319
+ const meta = parseMetaString(codeBlock.meta, ["choice"]);
320
+ const choice = meta.props.choice;
321
+ codeBlock.meta = meta.rest;
322
+ const yamlJsCode = {
323
+ ...codeBlock,
324
+ value: codeBlockContentJs
325
+ };
326
+ const replacement = generateChoiceGroupCode([
327
+ { choiceValue: "JavaScript", children: [yamlJsCode] },
328
+ { choiceValue: "TypeScript", children: [codeBlock] }
329
+ ]);
330
+ replacement.attributes.push({ type: "mdxJsxAttribute", name: "hide" });
331
+ replacement.data ??= {};
332
+ replacement.data.customDataChoice = choice;
333
+ replacement.data.customDataFilter = "codeLang";
334
+ parent.children.splice(index, 1, replacement);
335
+ };
336
+ var transformTsToJs = async (node, file) => {
337
+ const { codeBlock, index, parent } = node;
338
+ const meta = parseMetaString(codeBlock.meta, ["max-width", "choice"]);
339
+ const maxWidth = Number(meta.props["max-width"]);
340
+ const choice = meta.props.choice;
341
+ codeBlock.meta = meta.rest;
342
+ codeBlock.data ??= {};
343
+ codeBlock.data.customDataChoice = choice;
344
+ codeBlock.data.customDataFilter = "codeLang";
345
+ if (choice === "TypeScript") {
346
+ return;
347
+ }
348
+ const codeBlockReplacedJs = replaceFileNameSuffixes(codeBlock.value);
349
+ let codeBlockContentJs = "";
350
+ try {
351
+ codeBlockContentJs = await detype(codeBlockReplacedJs, `snippet.${codeBlock.lang}`, {
352
+ customizeBabelConfig(config) {
353
+ if (!config.presets || config.presets.length !== 1) {
354
+ return;
355
+ }
356
+ config.presets = [[config.presets[0], { onlyRemoveTypeImports: true }]];
357
+ },
358
+ removeTsComments: true,
359
+ prettierOptions: {
360
+ ...prettierOptions,
361
+ printWidth: Number.isFinite(maxWidth) && maxWidth > 0 ? maxWidth : 99
362
+ }
363
+ });
364
+ } catch (error) {
365
+ console.error(
366
+ [
367
+ `Failed to detype code block in ${file?.path ?? "an MDX file"}.`,
368
+ error instanceof Error ? error.message : String(error)
369
+ ].join("\n")
370
+ );
371
+ return;
372
+ }
373
+ codeBlockContentJs = cleanUpCode(codeBlockContentJs.trimEnd(), true);
374
+ codeBlock.value = cleanUpCode(codeBlock.value);
375
+ codeBlockContentJs = preserveSourceLineBreaks(codeBlock.value, codeBlockContentJs);
376
+ codeBlockContentJs = preserveSourceBlankLines(codeBlock.value, codeBlockContentJs);
377
+ if (codeBlockContentJs === codeBlock.value) {
378
+ return;
379
+ }
380
+ const tsCode = { ...codeBlock, lang: codeBlock.lang };
381
+ const jsCode = {
382
+ ...codeBlock,
383
+ lang: String(codeBlock.lang).replace("t", "j"),
384
+ value: codeBlockContentJs
385
+ };
386
+ const replacement = generateChoiceGroupCode([
387
+ { choiceValue: "JavaScript", children: [jsCode] },
388
+ { choiceValue: "TypeScript", children: [tsCode] }
389
+ ]);
390
+ if (codeBlockReplacedJs === codeBlockContentJs) {
391
+ replacement.attributes.push({ type: "mdxJsxAttribute", name: "hide" });
392
+ }
393
+ replacement.data ??= {};
394
+ replacement.data.customDataChoice = codeBlock.data.customDataChoice;
395
+ replacement.data.customDataFilter = codeBlock.data.customDataFilter;
396
+ parent.children.splice(index, 1, replacement);
397
+ };
398
+ var replaceFileNameSuffixes = (value) => value.replaceAll(".ts", ".js");
399
+ var cleanUpCode = (code, isJsCode = false) => {
400
+ if (isJsCode) {
401
+ code = correctCodeDiffComments(code);
402
+ }
403
+ return processMagicComments(code);
404
+ };
405
+ var processMagicComments = (code) => {
406
+ const renameCommentRe = /^\s*\/\/\s@docpress-replace\s([^ ]+) ([^ ]+)\n/gm;
407
+ const matches = Array.from(code.matchAll(renameCommentRe));
408
+ for (let index = matches.length - 1; index >= 0; index -= 1) {
409
+ const match = matches[index];
410
+ if (!match) {
411
+ continue;
412
+ }
413
+ const [fullMatch, renameFrom, renameTo] = match;
414
+ code = code.split(fullMatch).join("").replaceAll(renameFrom, renameTo);
415
+ }
416
+ return code.replaceAll("// @docpress-uncomment ", "");
417
+ };
418
+ var correctCodeDiffComments = (code) => {
419
+ return code.replaceAll(/\n\s*\/\/\s\[!code.+\]/g, (codeDiff) => codeDiff.trimStart());
420
+ };
421
+ var preserveSourceLineBreaks = (sourceCode, outputCode) => {
422
+ const multilineSegments = collectMultilineSourceSegments(sourceCode);
423
+ if (multilineSegments.length === 0) {
424
+ return outputCode;
425
+ }
426
+ const outputLines = outputCode.split("\n");
427
+ for (const segmentLines of multilineSegments) {
428
+ const segmentNormalized = normalizeCodeSegment(segmentLines.join("\n"));
429
+ if (!segmentNormalized) {
430
+ continue;
431
+ }
432
+ for (let start = 0; start < outputLines.length; start += 1) {
433
+ let replaced = false;
434
+ for (let size = 1; size <= segmentLines.length; size += 1) {
435
+ if (start + size > outputLines.length) {
436
+ break;
437
+ }
438
+ const outputSegment = outputLines.slice(start, start + size);
439
+ if (normalizeCodeSegment(outputSegment.join("\n")) !== segmentNormalized) {
440
+ continue;
441
+ }
442
+ if (outputSegment.join("\n") !== segmentLines.join("\n")) {
443
+ outputLines.splice(start, size, ...segmentLines);
444
+ }
445
+ start += segmentLines.length - 1;
446
+ replaced = true;
447
+ break;
448
+ }
449
+ if (replaced) {
450
+ break;
451
+ }
452
+ }
453
+ }
454
+ return outputLines.join("\n");
455
+ };
456
+ var collectMultilineSourceSegments = (code) => {
457
+ const lines = code.split("\n");
458
+ const segments = [];
459
+ let paragraphStart = -1;
460
+ for (let index = 0; index <= lines.length; index += 1) {
461
+ if (index < lines.length && lines[index]?.trim() !== "") {
462
+ if (paragraphStart === -1) {
463
+ paragraphStart = index;
464
+ }
465
+ continue;
466
+ }
467
+ if (paragraphStart !== -1) {
468
+ const paragraphEnd = index - 1;
469
+ for (let size = paragraphEnd - paragraphStart + 1; size >= 2; size -= 1) {
470
+ for (let start = paragraphStart; start + size - 1 <= paragraphEnd; start += 1) {
471
+ segments.push(lines.slice(start, start + size).map(replaceFileNameSuffixes));
472
+ }
473
+ }
474
+ }
475
+ paragraphStart = -1;
476
+ }
477
+ return segments;
478
+ };
479
+ var preserveSourceBlankLines = (sourceCode, outputCode) => {
480
+ const blankLineAnchors = collectBlankLineAnchors(sourceCode);
481
+ if (blankLineAnchors.length === 0) {
482
+ return outputCode;
483
+ }
484
+ const outputLines = outputCode.split("\n");
485
+ let searchFrom = 0;
486
+ for (const anchor of blankLineAnchors) {
487
+ const lineIndex = outputLines.findIndex((line, index) => index >= searchFrom && normalizeCodeLine(line) === anchor);
488
+ if (lineIndex <= 0) {
489
+ continue;
490
+ }
491
+ if (outputLines[lineIndex - 1]?.trim() !== "") {
492
+ outputLines.splice(lineIndex, 0, "");
493
+ searchFrom = lineIndex + 2;
494
+ } else {
495
+ searchFrom = lineIndex + 1;
496
+ }
497
+ }
498
+ return outputLines.join("\n");
499
+ };
500
+ var collectBlankLineAnchors = (code) => {
501
+ const lines = code.split("\n");
502
+ const anchors = [];
503
+ for (let index = 1; index < lines.length; index += 1) {
504
+ if (lines[index]?.trim() !== "" || lines[index - 1]?.trim() === "") {
505
+ continue;
506
+ }
507
+ let nextLineIndex = index + 1;
508
+ while (nextLineIndex < lines.length && lines[nextLineIndex]?.trim() === "") {
509
+ nextLineIndex += 1;
510
+ }
511
+ const anchor = lines[nextLineIndex];
512
+ if (anchor) {
513
+ anchors.push(normalizeCodeLine(anchor));
514
+ }
515
+ }
516
+ return anchors;
517
+ };
518
+ var normalizeCodeLine = (line) => {
519
+ return stripTypeSyntax(replaceFileNameSuffixes(line)).trim().replace(/\s+/g, " ");
520
+ };
521
+ var normalizeCodeSegment = (code) => {
522
+ return replaceFileNameSuffixes(code).replace(/\s+/g, "");
523
+ };
524
+ var stripTypeSyntax = (line) => {
525
+ return line.replace(/\??:\s*[A-Za-z_$][\w$.<>, |&[\]]*/g, "").replace(/\s+as\s+const\b/g, "").replace(/\s+as\s+[A-Za-z_$][\w$.<>, |&[\]]*/g, "");
526
+ };
527
+
528
+ // src/components/code-blocks/remarkPkgManager.ts
529
+ import convert_ from "npm-to-yarn";
530
+ import { visit as visit4 } from "unist-util-visit";
531
+ var convert = convert_;
532
+ var PACKAGE_MANAGERS = ["pnpm", "Bun", "Yarn"];
533
+ var remarkPkgManager = () => {
534
+ return (tree) => {
535
+ visit4(tree, "code", (node, index, parent) => {
536
+ if (!parent || typeof index !== "number") {
537
+ return;
538
+ }
539
+ if (!["bash", "sh", "shell"].includes(node.lang ?? "")) {
540
+ return;
541
+ }
542
+ if (node.value.includes("pnpm")) {
543
+ return;
544
+ }
545
+ if (!node.value.includes("npm ") && !node.value.includes("npx ")) {
546
+ return;
547
+ }
548
+ let choice;
549
+ if (node.meta) {
550
+ const meta = parseMetaString(node.meta, ["choice"]);
551
+ choice = meta.props.choice;
552
+ node.meta = meta.rest;
553
+ }
554
+ node.value = node.value.replaceAll("npm i ", "npm install ");
555
+ const nodes = /* @__PURE__ */ new Map();
556
+ nodes.set("npm", node);
557
+ for (const packageManager of PACKAGE_MANAGERS) {
558
+ nodes.set(packageManager, {
559
+ ...node,
560
+ value: convert(node.value, packageManager.toLowerCase())
561
+ });
562
+ }
563
+ const replacement = generateChoiceGroupCode(
564
+ [...nodes].map(([choiceValue, childNode]) => ({
565
+ choiceValue,
566
+ children: [childNode]
567
+ }))
568
+ );
569
+ replacement.data ??= {};
570
+ replacement.data.customDataChoice = choice;
571
+ replacement.data.customDataFilter = replacement.type;
572
+ parent.children.splice(index, 1, replacement);
573
+ });
574
+ };
575
+ };
576
+
577
+ // src/components/code-blocks/shikiTransformerAutoLinks.ts
578
+ var LINK_RE = /https:\/\/[^\s]*[^.,\s"'`]/g;
579
+ var shikiTransformerAutoLinks = () => {
580
+ return {
581
+ name: "solid-docpress-shiki-autolinks",
582
+ span(span) {
583
+ if (span.children.length !== 1) {
584
+ return;
585
+ }
586
+ let child = span.children[0];
587
+ if (child.type !== "text") {
588
+ return;
589
+ }
590
+ const matches = Array.from(child.value.matchAll(LINK_RE)).filter(([href]) => !href.includes("${"));
591
+ if (matches.length === 0) {
592
+ return;
593
+ }
594
+ const links = matches.map((match) => ({ href: match[0], index: match.index ?? 0 })).sort((left, right) => right.index - left.index);
595
+ const nextChildren = [];
596
+ for (const { href, index } of links) {
597
+ const endIndex = index + href.length;
598
+ const trailingText = child.value.slice(endIndex);
599
+ if (trailingText) {
600
+ nextChildren.unshift({ type: "text", value: trailingText });
601
+ }
602
+ nextChildren.unshift({
603
+ type: "element",
604
+ tagName: "a",
605
+ properties: { href },
606
+ children: [{ type: "text", value: href }]
607
+ });
608
+ child = {
609
+ type: "text",
610
+ value: child.value.slice(0, index)
611
+ };
612
+ }
613
+ if (child.value) {
614
+ nextChildren.unshift(child);
615
+ }
616
+ span.children = nextChildren;
617
+ }
618
+ };
619
+ };
620
+
621
+ // src/components/code-blocks/index.ts
622
+ var getCodeBlockMdxPlugins = () => {
623
+ return {
624
+ remarkPlugins: [remarkDirective, remarkDetype, remarkPkgManager, remarkChoiceGroup],
625
+ rehypePlugins: [
626
+ [
627
+ rehypePrettyCode,
628
+ {
629
+ keepBackground: false,
630
+ theme: {
631
+ light: "github-light",
632
+ dark: "one-dark-pro"
633
+ },
634
+ transformers: [
635
+ transformerNotationDiff(),
636
+ transformerNotationHighlight(),
637
+ transformerNotationWordHighlight(),
638
+ shikiTransformerAutoLinks()
639
+ ]
640
+ }
641
+ ],
642
+ rehypeMetaToProps
643
+ ]
644
+ };
645
+ };
646
+
647
+ export {
648
+ parseMetaString,
649
+ getCodeBlockPropsFromMeta,
650
+ rehypeMetaToProps,
651
+ remarkChoiceGroup,
652
+ remarkDetype,
653
+ remarkPkgManager,
654
+ shikiTransformerAutoLinks,
655
+ getCodeBlockMdxPlugins
656
+ };
657
+ //# sourceMappingURL=chunk-45CLUNJW.js.map