astro 3.3.0 → 3.3.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/components/Code.astro +1 -1
- package/components/Picture.astro +26 -16
- package/dist/assets/services/service.js +47 -43
- package/dist/assets/utils/transformToPath.js +2 -1
- package/dist/cli/add/index.js +3 -3
- package/dist/core/constants.js +1 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/errors/dev/vite.js +9 -1
- package/dist/core/errors/errors-data.d.ts +12 -0
- package/dist/core/errors/errors-data.js +6 -0
- package/dist/core/errors/overlay.js +20 -20
- package/dist/core/messages.js +2 -2
- package/dist/core/shiki.d.ts +8 -0
- package/dist/core/shiki.js +35 -0
- package/package.json +3 -2
- package/components/shiki.ts +0 -46
package/components/Code.astro
CHANGED
|
@@ -8,7 +8,7 @@ import type {
|
|
|
8
8
|
ThemeRegistrationRaw,
|
|
9
9
|
} from 'shikiji';
|
|
10
10
|
import { visit } from 'unist-util-visit';
|
|
11
|
-
import { getCachedHighlighter, replaceCssVariables } from '
|
|
11
|
+
import { getCachedHighlighter, replaceCssVariables } from '../dist/core/shiki.js';
|
|
12
12
|
|
|
13
13
|
interface Props {
|
|
14
14
|
/** The code to highlight. Required. */
|
package/components/Picture.astro
CHANGED
|
@@ -11,7 +11,16 @@ type Props = (LocalImageProps | RemoteImageProps) & {
|
|
|
11
11
|
pictureAttributes?: HTMLAttributes<'picture'>;
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
const
|
|
14
|
+
const defaultFormats = ['webp'] as const;
|
|
15
|
+
const defaultFallbackFormat = 'png' as const;
|
|
16
|
+
|
|
17
|
+
// Certain formats don't want PNG fallbacks:
|
|
18
|
+
// - GIF will typically want to stay as a gif, either for animation or for the lower amount of colors
|
|
19
|
+
// - SVGs can't be converted to raster formats in most cases
|
|
20
|
+
// For those, we'll use the original format as the fallback instead.
|
|
21
|
+
const specialFormatsFallback = ['gif', 'svg'] as const;
|
|
22
|
+
|
|
23
|
+
const { formats = defaultFormats, pictureAttributes = {}, fallbackFormat, ...props } = Astro.props;
|
|
15
24
|
|
|
16
25
|
if (props.alt === undefined || props.alt === null) {
|
|
17
26
|
throw new AstroError(AstroErrorData.ImageMissingAlt);
|
|
@@ -24,16 +33,18 @@ const optimizedImages: GetImageResult[] = await Promise.all(
|
|
|
24
33
|
)
|
|
25
34
|
);
|
|
26
35
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
36
|
+
let resultFallbackFormat = fallbackFormat ?? defaultFallbackFormat;
|
|
37
|
+
if (
|
|
38
|
+
!fallbackFormat &&
|
|
39
|
+
isESMImportedImage(props.src) &&
|
|
40
|
+
specialFormatsFallback.includes(props.src.format)
|
|
41
|
+
) {
|
|
42
|
+
resultFallbackFormat = props.src.format;
|
|
43
|
+
}
|
|
33
44
|
|
|
34
45
|
const fallbackImage = await getImage({
|
|
35
46
|
...props,
|
|
36
|
-
format:
|
|
47
|
+
format: resultFallbackFormat,
|
|
37
48
|
widths: props.widths,
|
|
38
49
|
densities: props.densities,
|
|
39
50
|
});
|
|
@@ -46,14 +57,13 @@ if (fallbackImage.srcSet.values.length > 0) {
|
|
|
46
57
|
|
|
47
58
|
<picture {...pictureAttributes}>
|
|
48
59
|
{
|
|
49
|
-
Object.entries(optimizedImages).map(([_, image]) =>
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
image.srcSet.values.length > 0 ? '
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
))
|
|
60
|
+
Object.entries(optimizedImages).map(([_, image]) => {
|
|
61
|
+
const srcsetAttribute =
|
|
62
|
+
props.densities || (!props.densities && !props.widths)
|
|
63
|
+
? `${image.src}${image.srcSet.values.length > 0 ? ', ' + image.srcSet.attribute : ''}`
|
|
64
|
+
: image.srcSet.attribute;
|
|
65
|
+
return <source srcset={srcsetAttribute} type={'image/' + image.options.format} />;
|
|
66
|
+
})
|
|
57
67
|
}
|
|
58
68
|
<img src={fallbackImage.src} {...additionalAttributes} {...fallbackImage.attributes} />
|
|
59
69
|
</picture>
|
|
@@ -65,10 +65,17 @@ const baseService = {
|
|
|
65
65
|
if (options.src.format === "svg") {
|
|
66
66
|
options.format = "svg";
|
|
67
67
|
}
|
|
68
|
+
if (options.src.format === "svg" && options.format !== "svg" || options.src.format !== "svg" && options.format === "svg") {
|
|
69
|
+
throw new AstroError(AstroErrorData.UnsupportedImageConversion);
|
|
70
|
+
}
|
|
68
71
|
}
|
|
69
72
|
if (!options.format) {
|
|
70
73
|
options.format = DEFAULT_OUTPUT_FORMAT;
|
|
71
74
|
}
|
|
75
|
+
if (options.width)
|
|
76
|
+
options.width = Math.round(options.width);
|
|
77
|
+
if (options.height)
|
|
78
|
+
options.height = Math.round(options.height);
|
|
72
79
|
return options;
|
|
73
80
|
},
|
|
74
81
|
getHTMLAttributes(options) {
|
|
@@ -84,12 +91,21 @@ const baseService = {
|
|
|
84
91
|
},
|
|
85
92
|
getSrcSet(options) {
|
|
86
93
|
const srcSet = [];
|
|
87
|
-
const { targetWidth
|
|
94
|
+
const { targetWidth } = getTargetDimensions(options);
|
|
88
95
|
const { widths, densities } = options;
|
|
89
96
|
const targetFormat = options.format ?? DEFAULT_OUTPUT_FORMAT;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
97
|
+
let imageWidth = options.width;
|
|
98
|
+
let maxWidth = Infinity;
|
|
99
|
+
if (isESMImportedImage(options.src)) {
|
|
100
|
+
imageWidth = options.src.width;
|
|
101
|
+
maxWidth = imageWidth;
|
|
102
|
+
}
|
|
103
|
+
const {
|
|
104
|
+
width: transformWidth,
|
|
105
|
+
height: transformHeight,
|
|
106
|
+
...transformWithoutDimensions
|
|
107
|
+
} = options;
|
|
108
|
+
const allWidths = [];
|
|
93
109
|
if (densities) {
|
|
94
110
|
const densityValues = densities.map((density) => {
|
|
95
111
|
if (typeof density === "number") {
|
|
@@ -99,48 +115,36 @@ const baseService = {
|
|
|
99
115
|
}
|
|
100
116
|
});
|
|
101
117
|
const densityWidths = densityValues.sort().map((density) => Math.round(targetWidth * density));
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
},
|
|
109
|
-
descriptor: `${densityValues[index]}x`,
|
|
110
|
-
attributes: {
|
|
111
|
-
type: `image/${targetFormat}`
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
if (maxTargetWidth !== imageWidth) {
|
|
115
|
-
srcSetValue.transform.width = maxTargetWidth;
|
|
116
|
-
srcSetValue.transform.height = Math.round(maxTargetWidth / aspectRatio);
|
|
117
|
-
}
|
|
118
|
-
if (targetFormat !== options.format) {
|
|
119
|
-
srcSetValue.transform.format = targetFormat;
|
|
120
|
-
}
|
|
121
|
-
srcSet.push(srcSetValue);
|
|
122
|
-
});
|
|
118
|
+
allWidths.push(
|
|
119
|
+
...densityWidths.map((width, index) => ({
|
|
120
|
+
maxTargetWidth: Math.min(width, maxWidth),
|
|
121
|
+
descriptor: `${densityValues[index]}x`
|
|
122
|
+
}))
|
|
123
|
+
);
|
|
123
124
|
} else if (widths) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if (
|
|
137
|
-
|
|
138
|
-
|
|
125
|
+
allWidths.push(
|
|
126
|
+
...widths.map((width) => ({
|
|
127
|
+
maxTargetWidth: Math.min(width, maxWidth),
|
|
128
|
+
descriptor: `${width}w`
|
|
129
|
+
}))
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
for (const { maxTargetWidth, descriptor } of allWidths) {
|
|
133
|
+
const srcSetTransform = { ...transformWithoutDimensions };
|
|
134
|
+
if (maxTargetWidth !== imageWidth) {
|
|
135
|
+
srcSetTransform.width = maxTargetWidth;
|
|
136
|
+
} else {
|
|
137
|
+
if (options.width && options.height) {
|
|
138
|
+
srcSetTransform.width = options.width;
|
|
139
|
+
srcSetTransform.height = options.height;
|
|
139
140
|
}
|
|
140
|
-
|
|
141
|
-
|
|
141
|
+
}
|
|
142
|
+
srcSet.push({
|
|
143
|
+
transform: srcSetTransform,
|
|
144
|
+
descriptor,
|
|
145
|
+
attributes: {
|
|
146
|
+
type: `image/${targetFormat}`
|
|
142
147
|
}
|
|
143
|
-
srcSet.push(srcSetValue);
|
|
144
148
|
});
|
|
145
149
|
}
|
|
146
150
|
return srcSet;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { deterministicString } from "deterministic-object-hash";
|
|
1
2
|
import { basename, extname } from "node:path";
|
|
2
3
|
import { removeQueryString } from "../../core/path.js";
|
|
3
4
|
import { shorthash } from "../../runtime/server/shorthash.js";
|
|
@@ -14,7 +15,7 @@ function propsToFilename(transform, hash) {
|
|
|
14
15
|
function hashTransform(transform, imageService) {
|
|
15
16
|
const { alt, class: className, style, widths, densities, ...rest } = transform;
|
|
16
17
|
const hashFields = { ...rest, imageService };
|
|
17
|
-
return shorthash(
|
|
18
|
+
return shorthash(deterministicString(hashFields));
|
|
18
19
|
}
|
|
19
20
|
export {
|
|
20
21
|
hashTransform,
|
package/dist/cli/add/index.js
CHANGED
|
@@ -602,10 +602,10 @@ async function fetchPackageJson(scope, name, tag) {
|
|
|
602
602
|
const packageName = `${scope ? `${scope}/` : ""}${name}`;
|
|
603
603
|
const registry = await getRegistry();
|
|
604
604
|
const res = await fetch(`${registry}/${packageName}/${tag}`);
|
|
605
|
-
if (res.status
|
|
606
|
-
return new Error();
|
|
607
|
-
} else {
|
|
605
|
+
if (res.status >= 200 && res.status < 300) {
|
|
608
606
|
return await res.json();
|
|
607
|
+
} else {
|
|
608
|
+
return new Error();
|
|
609
609
|
}
|
|
610
610
|
}
|
|
611
611
|
async function validateIntegrations(integrations) {
|
package/dist/core/constants.js
CHANGED
package/dist/core/dev/dev.js
CHANGED
|
@@ -20,7 +20,7 @@ async function dev(inlineConfig) {
|
|
|
20
20
|
base: restart.container.settings.config.base
|
|
21
21
|
})
|
|
22
22
|
);
|
|
23
|
-
const currentVersion = "3.3.
|
|
23
|
+
const currentVersion = "3.3.1";
|
|
24
24
|
if (currentVersion.includes("-")) {
|
|
25
25
|
logger.warn(null, msg.prerelease({ currentVersion }));
|
|
26
26
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
2
|
import { fileURLToPath } from "node:url";
|
|
3
3
|
import { codeToHtml } from "shikiji";
|
|
4
|
+
import { replaceCssVariables } from "../../shiki.js";
|
|
4
5
|
import { FailedToLoadModuleSSR, InvalidGlob, MdxIntegrationMissingError } from "../errors-data.js";
|
|
5
6
|
import { AstroError } from "../errors.js";
|
|
6
7
|
import { createSafeError } from "../utils.js";
|
|
@@ -70,6 +71,7 @@ function enhanceViteSSRError({
|
|
|
70
71
|
}
|
|
71
72
|
const ALTERNATIVE_JS_EXTS = ["cjs", "mjs"];
|
|
72
73
|
const ALTERNATIVE_MD_EXTS = ["mdoc"];
|
|
74
|
+
const INLINE_STYLE_SELECTOR_GLOBAL = /style="(.*?)"/g;
|
|
73
75
|
async function getViteErrorPayload(err) {
|
|
74
76
|
let plugin = err.plugin;
|
|
75
77
|
if (!plugin && err.hint) {
|
|
@@ -85,12 +87,18 @@ async function getViteErrorPayload(err) {
|
|
|
85
87
|
if (ALTERNATIVE_MD_EXTS.includes(highlighterLang ?? "")) {
|
|
86
88
|
highlighterLang = "md";
|
|
87
89
|
}
|
|
88
|
-
|
|
90
|
+
let highlightedCode = err.fullCode ? await codeToHtml(err.fullCode, {
|
|
89
91
|
// @ts-expect-error always assume that shiki can accept the lang string
|
|
90
92
|
lang: highlighterLang,
|
|
91
93
|
theme: "css-variables",
|
|
92
94
|
lineOptions: err.loc?.line ? [{ line: err.loc.line, classes: ["error-line"] }] : void 0
|
|
93
95
|
}) : void 0;
|
|
96
|
+
if (highlightedCode) {
|
|
97
|
+
highlightedCode = highlightedCode.replace(
|
|
98
|
+
INLINE_STYLE_SELECTOR_GLOBAL,
|
|
99
|
+
(m) => replaceCssVariables(m)
|
|
100
|
+
);
|
|
101
|
+
}
|
|
94
102
|
return {
|
|
95
103
|
type: "error",
|
|
96
104
|
err: {
|
|
@@ -488,6 +488,18 @@ export declare const UnsupportedImageFormat: {
|
|
|
488
488
|
message: (format: string, imagePath: string, supportedFormats: readonly string[]) => string;
|
|
489
489
|
hint: string;
|
|
490
490
|
};
|
|
491
|
+
/**
|
|
492
|
+
* @docs
|
|
493
|
+
* @see
|
|
494
|
+
* - [Images](https://docs.astro.build/en/guides/images/)
|
|
495
|
+
* @description
|
|
496
|
+
* Astro does not currently supporting converting between vector (such as SVGs) and raster (such as PNGs and JPEGs) images.
|
|
497
|
+
*/
|
|
498
|
+
export declare const UnsupportedImageConversion: {
|
|
499
|
+
name: string;
|
|
500
|
+
title: string;
|
|
501
|
+
message: string;
|
|
502
|
+
};
|
|
491
503
|
/**
|
|
492
504
|
* @docs
|
|
493
505
|
* @see
|
|
@@ -175,6 +175,11 @@ const UnsupportedImageFormat = {
|
|
|
175
175
|
)} are supported by our image services.`,
|
|
176
176
|
hint: "Using an `img` tag directly instead of the `Image` component might be what you're looking for."
|
|
177
177
|
};
|
|
178
|
+
const UnsupportedImageConversion = {
|
|
179
|
+
name: "UnsupportedImageConversion",
|
|
180
|
+
title: "Unsupported image conversion",
|
|
181
|
+
message: "Converting between vector (such as SVGs) and raster (such as PNGs and JPEGs) images is not currently supported."
|
|
182
|
+
};
|
|
178
183
|
const PrerenderDynamicEndpointPathCollide = {
|
|
179
184
|
name: "PrerenderDynamicEndpointPathCollide",
|
|
180
185
|
title: "Prerendered dynamic endpoint has path collision.",
|
|
@@ -492,5 +497,6 @@ export {
|
|
|
492
497
|
UnknownMarkdownError,
|
|
493
498
|
UnknownViteError,
|
|
494
499
|
UnsupportedConfigTransformError,
|
|
500
|
+
UnsupportedImageConversion,
|
|
495
501
|
UnsupportedImageFormat
|
|
496
502
|
};
|
|
@@ -68,16 +68,16 @@ const style = (
|
|
|
68
68
|
--toggle-border-color: #C3CADB;
|
|
69
69
|
|
|
70
70
|
/* Syntax Highlighting */
|
|
71
|
-
--
|
|
72
|
-
--
|
|
73
|
-
--
|
|
74
|
-
--
|
|
75
|
-
--
|
|
76
|
-
--
|
|
77
|
-
--
|
|
78
|
-
--
|
|
79
|
-
--
|
|
80
|
-
--
|
|
71
|
+
--astro-code-color-text: #000000;
|
|
72
|
+
--astro-code-token-constant: #4ca48f;
|
|
73
|
+
--astro-code-token-string: #9f722a;
|
|
74
|
+
--astro-code-token-comment: #8490b5;
|
|
75
|
+
--astro-code-token-keyword: var(--accent);
|
|
76
|
+
--astro-code-token-parameter: #aa0000;
|
|
77
|
+
--astro-code-token-function: #4ca48f;
|
|
78
|
+
--astro-code-token-string-expression: #9f722a;
|
|
79
|
+
--astro-code-token-punctuation: #ffffff;
|
|
80
|
+
--astro-code-token-link: #9f722a;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
:host(.astro-dark) {
|
|
@@ -121,16 +121,16 @@ const style = (
|
|
|
121
121
|
--toggle-border-color: #3D4663;
|
|
122
122
|
|
|
123
123
|
/* Syntax Highlighting */
|
|
124
|
-
--
|
|
125
|
-
--
|
|
126
|
-
--
|
|
127
|
-
--
|
|
128
|
-
--
|
|
129
|
-
--
|
|
130
|
-
--
|
|
131
|
-
--
|
|
132
|
-
--
|
|
133
|
-
--
|
|
124
|
+
--astro-code-color-text: #ffffff;
|
|
125
|
+
--astro-code-token-constant: #90f4e3;
|
|
126
|
+
--astro-code-token-string: #f4cf90;
|
|
127
|
+
--astro-code-token-comment: #8490b5;
|
|
128
|
+
--astro-code-token-keyword: var(--accent);
|
|
129
|
+
--astro-code-token-parameter: #aa0000;
|
|
130
|
+
--astro-code-token-function: #90f4e3;
|
|
131
|
+
--astro-code-token-string-expression: #f4cf90;
|
|
132
|
+
--astro-code-token-punctuation: #ffffff;
|
|
133
|
+
--astro-code-token-link: #f4cf90;
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
#theme-toggle-wrapper{
|
package/dist/core/messages.js
CHANGED
|
@@ -50,7 +50,7 @@ function serverStart({
|
|
|
50
50
|
base,
|
|
51
51
|
isRestart = false
|
|
52
52
|
}) {
|
|
53
|
-
const version = "3.3.
|
|
53
|
+
const version = "3.3.1";
|
|
54
54
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
55
55
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
56
56
|
const emptyPrefix = " ".repeat(11);
|
|
@@ -235,7 +235,7 @@ function printHelp({
|
|
|
235
235
|
message.push(
|
|
236
236
|
linebreak(),
|
|
237
237
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
238
|
-
`v${"3.3.
|
|
238
|
+
`v${"3.3.1"}`
|
|
239
239
|
)} ${headline}`
|
|
240
240
|
);
|
|
241
241
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { getHighlighter, type Highlighter } from 'shikiji';
|
|
2
|
+
type HighlighterOptions = NonNullable<Parameters<typeof getHighlighter>[0]>;
|
|
3
|
+
/**
|
|
4
|
+
* shiki -> shikiji compat as we need to manually replace it
|
|
5
|
+
*/
|
|
6
|
+
export declare function replaceCssVariables(str: string): string;
|
|
7
|
+
export declare function getCachedHighlighter(opts: HighlighterOptions): Promise<Highlighter>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { getHighlighter } from "shikiji";
|
|
2
|
+
const ASTRO_COLOR_REPLACEMENTS = {
|
|
3
|
+
"#000001": "var(--astro-code-color-text)",
|
|
4
|
+
"#000002": "var(--astro-code-color-background)",
|
|
5
|
+
"#000004": "var(--astro-code-token-constant)",
|
|
6
|
+
"#000005": "var(--astro-code-token-string)",
|
|
7
|
+
"#000006": "var(--astro-code-token-comment)",
|
|
8
|
+
"#000007": "var(--astro-code-token-keyword)",
|
|
9
|
+
"#000008": "var(--astro-code-token-parameter)",
|
|
10
|
+
"#000009": "var(--astro-code-token-function)",
|
|
11
|
+
"#000010": "var(--astro-code-token-string-expression)",
|
|
12
|
+
"#000011": "var(--astro-code-token-punctuation)",
|
|
13
|
+
"#000012": "var(--astro-code-token-link)"
|
|
14
|
+
};
|
|
15
|
+
const COLOR_REPLACEMENT_REGEX = new RegExp(
|
|
16
|
+
`(${Object.keys(ASTRO_COLOR_REPLACEMENTS).join("|")})`,
|
|
17
|
+
"g"
|
|
18
|
+
);
|
|
19
|
+
const cachedHighlighters = /* @__PURE__ */ new Map();
|
|
20
|
+
function replaceCssVariables(str) {
|
|
21
|
+
return str.replace(COLOR_REPLACEMENT_REGEX, (match) => ASTRO_COLOR_REPLACEMENTS[match] || match);
|
|
22
|
+
}
|
|
23
|
+
function getCachedHighlighter(opts) {
|
|
24
|
+
const key = JSON.stringify(opts, Object.keys(opts).sort());
|
|
25
|
+
if (cachedHighlighters.has(key)) {
|
|
26
|
+
return cachedHighlighters.get(key);
|
|
27
|
+
}
|
|
28
|
+
const highlighter = getHighlighter(opts);
|
|
29
|
+
cachedHighlighters.set(key, highlighter);
|
|
30
|
+
return highlighter;
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
getCachedHighlighter,
|
|
34
|
+
replaceCssVariables
|
|
35
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.1",
|
|
4
4
|
"description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "withastro",
|
|
@@ -123,6 +123,7 @@
|
|
|
123
123
|
"common-ancestor-path": "^1.0.1",
|
|
124
124
|
"cookie": "^0.5.0",
|
|
125
125
|
"debug": "^4.3.4",
|
|
126
|
+
"deterministic-object-hash": "^1.3.1",
|
|
126
127
|
"devalue": "^4.3.2",
|
|
127
128
|
"diff": "^5.1.0",
|
|
128
129
|
"es-module-lexer": "^1.3.0",
|
|
@@ -151,7 +152,7 @@
|
|
|
151
152
|
"shikiji": "^0.6.8",
|
|
152
153
|
"string-width": "^6.1.0",
|
|
153
154
|
"strip-ansi": "^7.1.0",
|
|
154
|
-
"tsconfck": "3.0.0
|
|
155
|
+
"tsconfck": "^3.0.0",
|
|
155
156
|
"unist-util-visit": "^4.1.2",
|
|
156
157
|
"vfile": "^5.3.7",
|
|
157
158
|
"vite": "^4.4.9",
|
package/components/shiki.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { type Highlighter, getHighlighter } from 'shikiji';
|
|
2
|
-
|
|
3
|
-
type HighlighterOptions = NonNullable<Parameters<typeof getHighlighter>[0]>;
|
|
4
|
-
|
|
5
|
-
const ASTRO_COLOR_REPLACEMENTS: Record<string, string> = {
|
|
6
|
-
'#000001': 'var(--astro-code-color-text)',
|
|
7
|
-
'#000002': 'var(--astro-code-color-background)',
|
|
8
|
-
'#000004': 'var(--astro-code-token-constant)',
|
|
9
|
-
'#000005': 'var(--astro-code-token-string)',
|
|
10
|
-
'#000006': 'var(--astro-code-token-comment)',
|
|
11
|
-
'#000007': 'var(--astro-code-token-keyword)',
|
|
12
|
-
'#000008': 'var(--astro-code-token-parameter)',
|
|
13
|
-
'#000009': 'var(--astro-code-token-function)',
|
|
14
|
-
'#000010': 'var(--astro-code-token-string-expression)',
|
|
15
|
-
'#000011': 'var(--astro-code-token-punctuation)',
|
|
16
|
-
'#000012': 'var(--astro-code-token-link)',
|
|
17
|
-
};
|
|
18
|
-
const COLOR_REPLACEMENT_REGEX = new RegExp(
|
|
19
|
-
`(${Object.keys(ASTRO_COLOR_REPLACEMENTS).join('|')})`,
|
|
20
|
-
'g'
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
// Caches Promise<Highlighter> for reuse when the same theme and langs are provided
|
|
24
|
-
const cachedHighlighters = new Map();
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* shiki -> shikiji compat as we need to manually replace it
|
|
28
|
-
*/
|
|
29
|
-
export function replaceCssVariables(str: string) {
|
|
30
|
-
return str.replace(COLOR_REPLACEMENT_REGEX, (match) => ASTRO_COLOR_REPLACEMENTS[match] || match);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function getCachedHighlighter(opts: HighlighterOptions): Promise<Highlighter> {
|
|
34
|
-
// Always sort keys before stringifying to make sure objects match regardless of parameter ordering
|
|
35
|
-
const key = JSON.stringify(opts, Object.keys(opts).sort());
|
|
36
|
-
|
|
37
|
-
// Highlighter has already been requested, reuse the same instance
|
|
38
|
-
if (cachedHighlighters.has(key)) {
|
|
39
|
-
return cachedHighlighters.get(key);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const highlighter = getHighlighter(opts);
|
|
43
|
-
cachedHighlighters.set(key, highlighter);
|
|
44
|
-
|
|
45
|
-
return highlighter;
|
|
46
|
-
}
|