astro 2.3.3 → 2.4.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/client-base.d.ts +26 -1
- package/components/Code.astro +46 -21
- package/components/shiki-languages.js +172 -2016
- package/components/shiki-themes.js +41 -31
- package/dist/@types/app.d.js +0 -0
- package/dist/@types/astro.d.ts +108 -1
- package/dist/assets/internal.d.ts +6 -17
- package/dist/assets/internal.js +37 -4
- package/dist/content/runtime.js +8 -3
- package/dist/content/vite-plugin-content-assets.js +14 -4
- package/dist/content/vite-plugin-content-imports.js +1 -1
- package/dist/core/app/index.js +50 -10
- package/dist/core/app/types.d.ts +10 -1
- package/dist/core/build/generate.js +65 -30
- package/dist/core/build/internal.d.ts +10 -6
- package/dist/core/build/internal.js +31 -39
- package/dist/core/build/page-data.js +2 -2
- package/dist/core/build/plugins/plugin-component-entry.d.ts +1 -0
- package/dist/core/build/plugins/plugin-component-entry.js +1 -0
- package/dist/core/build/plugins/plugin-css.d.ts +1 -8
- package/dist/core/build/plugins/plugin-css.js +185 -150
- package/dist/core/build/plugins/plugin-pages.d.ts +1 -1
- package/dist/core/build/plugins/plugin-pages.js +13 -2
- package/dist/core/build/plugins/plugin-ssr.d.ts +2 -2
- package/dist/core/build/plugins/plugin-ssr.js +20 -7
- package/dist/core/build/static-build.js +4 -3
- package/dist/core/build/types.d.ts +15 -6
- package/dist/core/compile/compile.js +1 -0
- package/dist/core/config/config.js +5 -1
- package/dist/core/config/schema.d.ts +40 -0
- package/dist/core/config/schema.js +10 -2
- package/dist/core/constants.d.ts +1 -0
- package/dist/core/constants.js +3 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/endpoint/dev/index.js +7 -4
- package/dist/core/endpoint/index.d.ts +9 -2
- package/dist/core/endpoint/index.js +42 -24
- package/dist/core/errors/errors-data.d.ts +81 -0
- package/dist/core/errors/errors-data.js +84 -0
- package/dist/core/messages.js +2 -2
- package/dist/core/middleware/callMiddleware.d.ts +36 -0
- package/dist/core/middleware/callMiddleware.js +38 -0
- package/dist/core/middleware/index.d.ts +4 -0
- package/dist/core/middleware/index.js +8 -0
- package/dist/core/middleware/loadMiddleware.d.ts +8 -0
- package/dist/core/middleware/loadMiddleware.js +13 -0
- package/dist/core/middleware/sequence.d.ts +6 -0
- package/dist/core/middleware/sequence.js +27 -0
- package/dist/core/path.js +9 -1
- package/dist/core/render/context.d.ts +7 -2
- package/dist/core/render/context.js +13 -2
- package/dist/core/render/core.d.ts +22 -2
- package/dist/core/render/core.js +68 -32
- package/dist/core/render/dev/index.d.ts +5 -1
- package/dist/core/render/dev/index.js +23 -3
- package/dist/core/render/index.d.ts +1 -1
- package/dist/core/render/index.js +7 -1
- package/dist/core/render/result.d.ts +1 -0
- package/dist/core/render/result.js +2 -1
- package/dist/core/render/ssr-element.d.ts +3 -2
- package/dist/core/render/ssr-element.js +22 -15
- package/dist/core/request.js +2 -0
- package/dist/integrations/index.js +1 -1
- package/dist/runtime/server/endpoint.js +1 -1
- package/dist/runtime/server/index.d.ts +1 -1
- package/dist/runtime/server/index.js +0 -2
- package/dist/runtime/server/render/head.js +3 -1
- package/dist/runtime/server/render/index.d.ts +1 -1
- package/dist/runtime/server/render/index.js +1 -2
- package/dist/runtime/server/render/tags.d.ts +2 -7
- package/dist/runtime/server/render/tags.js +9 -27
- package/dist/vite-plugin-astro-server/response.js +3 -3
- package/dist/vite-plugin-astro-server/route.js +7 -0
- package/dist/vite-plugin-env/index.js +6 -1
- package/dist/vite-plugin-jsx/index.js +2 -1
- package/package.json +12 -9
package/client-base.d.ts
CHANGED
|
@@ -3,7 +3,26 @@
|
|
|
3
3
|
declare module 'astro:assets' {
|
|
4
4
|
// Exporting things one by one is a bit cumbersome, not sure if there's a better way - erika, 2023-02-03
|
|
5
5
|
type AstroAssets = {
|
|
6
|
-
getImage
|
|
6
|
+
// getImage's type here is different from the internal function since the Vite module implicitly pass the service config
|
|
7
|
+
/**
|
|
8
|
+
* Get an optimized image and the necessary attributes to render it.
|
|
9
|
+
*
|
|
10
|
+
* **Example**
|
|
11
|
+
* ```astro
|
|
12
|
+
* ---
|
|
13
|
+
* import { getImage } from 'astro:assets';
|
|
14
|
+
* import originalImage from '../assets/image.png';
|
|
15
|
+
*
|
|
16
|
+
* const optimizedImage = await getImage({src: originalImage, width: 1280 });
|
|
17
|
+
* ---
|
|
18
|
+
* <img src={optimizedImage.src} {...optimizedImage.attributes} />
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* This is functionally equivalent to using the `<Image />` component, as the component calls this function internally.
|
|
22
|
+
*/
|
|
23
|
+
getImage: (
|
|
24
|
+
options: import('./dist/assets/types.js').ImageTransform
|
|
25
|
+
) => Promise<import('./dist/assets/types.js').GetImageResult>;
|
|
7
26
|
getConfiguredImageService: typeof import('./dist/assets/index.js').getConfiguredImageService;
|
|
8
27
|
Image: typeof import('./components/Image.astro').default;
|
|
9
28
|
};
|
|
@@ -368,3 +387,9 @@ declare module '*?inline' {
|
|
|
368
387
|
const src: string;
|
|
369
388
|
export default src;
|
|
370
389
|
}
|
|
390
|
+
|
|
391
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
392
|
+
export namespace App {
|
|
393
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
394
|
+
export interface Locals {}
|
|
395
|
+
}
|
package/components/Code.astro
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
import type * as shiki from 'shiki';
|
|
3
|
+
import { renderToHtml } from 'shiki';
|
|
3
4
|
import { getHighlighter } from './Shiki.js';
|
|
4
5
|
|
|
5
6
|
export interface Props {
|
|
@@ -30,36 +31,60 @@ export interface Props {
|
|
|
30
31
|
* @default false
|
|
31
32
|
*/
|
|
32
33
|
wrap?: boolean | null;
|
|
34
|
+
/**
|
|
35
|
+
* Generate inline code element only, without the pre element wrapper.
|
|
36
|
+
*
|
|
37
|
+
* @default false
|
|
38
|
+
*/
|
|
39
|
+
inline?: boolean;
|
|
33
40
|
}
|
|
34
41
|
|
|
35
|
-
const {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
// if wrap=null, do nothing.
|
|
43
|
-
if (wrap === false) {
|
|
44
|
-
html = html.replace(/style="(.*?)"/, 'style="$1; overflow-x: auto;"');
|
|
45
|
-
} else if (wrap === true) {
|
|
46
|
-
html = html.replace(
|
|
47
|
-
/style="(.*?)"/,
|
|
48
|
-
'style="$1; overflow-x: auto; white-space: pre-wrap; word-wrap: break-word;"'
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
return html;
|
|
52
|
-
}
|
|
42
|
+
const {
|
|
43
|
+
code,
|
|
44
|
+
lang = 'plaintext',
|
|
45
|
+
theme = 'github-dark',
|
|
46
|
+
wrap = false,
|
|
47
|
+
inline = false,
|
|
48
|
+
} = Astro.props;
|
|
53
49
|
|
|
50
|
+
// 1. Get the shiki syntax highlighter
|
|
54
51
|
const highlighter = await getHighlighter({
|
|
55
52
|
theme,
|
|
56
53
|
// Load custom lang if passed an object, otherwise load the default
|
|
57
54
|
langs: typeof lang !== 'string' ? [lang] : undefined,
|
|
58
55
|
});
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
|
|
57
|
+
// 2. Turn code into shiki theme tokens
|
|
58
|
+
const tokens = highlighter.codeToThemedTokens(code, typeof lang === 'string' ? lang : lang.id);
|
|
59
|
+
|
|
60
|
+
// 3. Get shiki theme object
|
|
61
|
+
const _theme = highlighter.getTheme();
|
|
62
|
+
|
|
63
|
+
// 4. Render the theme tokens as html
|
|
64
|
+
const html = renderToHtml(tokens, {
|
|
65
|
+
themeName: _theme.name,
|
|
66
|
+
fg: _theme.fg,
|
|
67
|
+
bg: _theme.bg,
|
|
68
|
+
elements: {
|
|
69
|
+
pre({ className, style, children }) {
|
|
70
|
+
// Swap to `code` tag if inline
|
|
71
|
+
const tag = inline ? 'code' : 'pre';
|
|
72
|
+
// Replace "shiki" class naming with "astro-code"
|
|
73
|
+
className = className.replace(/shiki/g, 'astro-code');
|
|
74
|
+
// Handle code wrapping
|
|
75
|
+
// if wrap=null, do nothing.
|
|
76
|
+
if (wrap === false) {
|
|
77
|
+
style += '; overflow-x: auto;"';
|
|
78
|
+
} else if (wrap === true) {
|
|
79
|
+
style += '; overflow-x: auto; white-space: pre-wrap; word-wrap: break-word;"';
|
|
80
|
+
}
|
|
81
|
+
return `<${tag} class="${className}" style="${style}" tabindex="0">${children}</${tag}>`;
|
|
82
|
+
},
|
|
83
|
+
code({ children }) {
|
|
84
|
+
return inline ? children : `<code>${children}</code>`;
|
|
85
|
+
},
|
|
86
|
+
},
|
|
61
87
|
});
|
|
62
|
-
const html = repairShikiTheme(_html);
|
|
63
88
|
---
|
|
64
89
|
|
|
65
90
|
<Fragment set:html={html} />
|