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.
Files changed (76) hide show
  1. package/client-base.d.ts +26 -1
  2. package/components/Code.astro +46 -21
  3. package/components/shiki-languages.js +172 -2016
  4. package/components/shiki-themes.js +41 -31
  5. package/dist/@types/app.d.js +0 -0
  6. package/dist/@types/astro.d.ts +108 -1
  7. package/dist/assets/internal.d.ts +6 -17
  8. package/dist/assets/internal.js +37 -4
  9. package/dist/content/runtime.js +8 -3
  10. package/dist/content/vite-plugin-content-assets.js +14 -4
  11. package/dist/content/vite-plugin-content-imports.js +1 -1
  12. package/dist/core/app/index.js +50 -10
  13. package/dist/core/app/types.d.ts +10 -1
  14. package/dist/core/build/generate.js +65 -30
  15. package/dist/core/build/internal.d.ts +10 -6
  16. package/dist/core/build/internal.js +31 -39
  17. package/dist/core/build/page-data.js +2 -2
  18. package/dist/core/build/plugins/plugin-component-entry.d.ts +1 -0
  19. package/dist/core/build/plugins/plugin-component-entry.js +1 -0
  20. package/dist/core/build/plugins/plugin-css.d.ts +1 -8
  21. package/dist/core/build/plugins/plugin-css.js +185 -150
  22. package/dist/core/build/plugins/plugin-pages.d.ts +1 -1
  23. package/dist/core/build/plugins/plugin-pages.js +13 -2
  24. package/dist/core/build/plugins/plugin-ssr.d.ts +2 -2
  25. package/dist/core/build/plugins/plugin-ssr.js +20 -7
  26. package/dist/core/build/static-build.js +4 -3
  27. package/dist/core/build/types.d.ts +15 -6
  28. package/dist/core/compile/compile.js +1 -0
  29. package/dist/core/config/config.js +5 -1
  30. package/dist/core/config/schema.d.ts +40 -0
  31. package/dist/core/config/schema.js +10 -2
  32. package/dist/core/constants.d.ts +1 -0
  33. package/dist/core/constants.js +3 -1
  34. package/dist/core/dev/dev.js +1 -1
  35. package/dist/core/endpoint/dev/index.js +7 -4
  36. package/dist/core/endpoint/index.d.ts +9 -2
  37. package/dist/core/endpoint/index.js +42 -24
  38. package/dist/core/errors/errors-data.d.ts +81 -0
  39. package/dist/core/errors/errors-data.js +84 -0
  40. package/dist/core/messages.js +2 -2
  41. package/dist/core/middleware/callMiddleware.d.ts +36 -0
  42. package/dist/core/middleware/callMiddleware.js +38 -0
  43. package/dist/core/middleware/index.d.ts +4 -0
  44. package/dist/core/middleware/index.js +8 -0
  45. package/dist/core/middleware/loadMiddleware.d.ts +8 -0
  46. package/dist/core/middleware/loadMiddleware.js +13 -0
  47. package/dist/core/middleware/sequence.d.ts +6 -0
  48. package/dist/core/middleware/sequence.js +27 -0
  49. package/dist/core/path.js +9 -1
  50. package/dist/core/render/context.d.ts +7 -2
  51. package/dist/core/render/context.js +13 -2
  52. package/dist/core/render/core.d.ts +22 -2
  53. package/dist/core/render/core.js +68 -32
  54. package/dist/core/render/dev/index.d.ts +5 -1
  55. package/dist/core/render/dev/index.js +23 -3
  56. package/dist/core/render/index.d.ts +1 -1
  57. package/dist/core/render/index.js +7 -1
  58. package/dist/core/render/result.d.ts +1 -0
  59. package/dist/core/render/result.js +2 -1
  60. package/dist/core/render/ssr-element.d.ts +3 -2
  61. package/dist/core/render/ssr-element.js +22 -15
  62. package/dist/core/request.js +2 -0
  63. package/dist/integrations/index.js +1 -1
  64. package/dist/runtime/server/endpoint.js +1 -1
  65. package/dist/runtime/server/index.d.ts +1 -1
  66. package/dist/runtime/server/index.js +0 -2
  67. package/dist/runtime/server/render/head.js +3 -1
  68. package/dist/runtime/server/render/index.d.ts +1 -1
  69. package/dist/runtime/server/render/index.js +1 -2
  70. package/dist/runtime/server/render/tags.d.ts +2 -7
  71. package/dist/runtime/server/render/tags.js +9 -27
  72. package/dist/vite-plugin-astro-server/response.js +3 -3
  73. package/dist/vite-plugin-astro-server/route.js +7 -0
  74. package/dist/vite-plugin-env/index.js +6 -1
  75. package/dist/vite-plugin-jsx/index.js +2 -1
  76. 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: typeof import('./dist/assets/index.js').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
+ }
@@ -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 { code, lang = 'plaintext', theme = 'github-dark', wrap = false } = Astro.props;
36
-
37
- /** Replace the shiki class name with a custom astro class name. */
38
- function repairShikiTheme(html: string): string {
39
- // Replace "shiki" class naming with "astro"
40
- html = html.replace(/<pre class="(.*?)shiki(.*?)"/, '<pre class="$1astro-code$2"');
41
- // Handle code wrapping
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
- const _html = highlighter.codeToHtml(code, {
60
- lang: typeof lang === 'string' ? lang : lang.id,
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} />