astro 6.0.0-beta.11 → 6.0.0-beta.13

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 (83) hide show
  1. package/README.md +1 -1
  2. package/client.d.ts +5 -0
  3. package/components/Code.astro +26 -2
  4. package/components/ResponsiveImage.astro +0 -2
  5. package/components/ResponsivePicture.astro +0 -1
  6. package/dist/assets/consts.d.ts +2 -0
  7. package/dist/assets/consts.js +4 -0
  8. package/dist/assets/fonts/providers/index.d.ts +19 -15
  9. package/dist/assets/fonts/providers/index.js +23 -1
  10. package/dist/assets/internal.d.ts +1 -0
  11. package/dist/assets/internal.js +8 -8
  12. package/dist/assets/utils/generateImageStylesCSS.d.ts +1 -0
  13. package/dist/assets/utils/generateImageStylesCSS.js +38 -0
  14. package/dist/assets/vite-plugin-assets.js +60 -30
  15. package/dist/cli/add/index.js +45 -64
  16. package/dist/cli/index.js +3 -3
  17. package/dist/cli/info/infra/{prompts-prompt.d.ts → clack-prompt.d.ts} +1 -1
  18. package/dist/cli/info/infra/{prompts-prompt.js → clack-prompt.js} +7 -8
  19. package/dist/cli/infra/build-time-astro-version-provider.js +1 -1
  20. package/dist/cli/install-package.js +16 -21
  21. package/dist/container/index.js +1 -0
  22. package/dist/content/content-layer.js +3 -3
  23. package/dist/content/vite-plugin-content-imports.js +2 -1
  24. package/dist/content/vite-plugin-content-virtual-mod.js +2 -1
  25. package/dist/core/app/entrypoints/index.d.ts +7 -0
  26. package/dist/core/app/{index.js → entrypoints/index.js} +6 -6
  27. package/dist/core/app/entrypoints/manifest.d.ts +1 -0
  28. package/dist/core/app/entrypoints/manifest.js +14 -0
  29. package/dist/core/app/entrypoints/node.d.ts +1 -0
  30. package/dist/core/app/entrypoints/node.js +8 -0
  31. package/dist/core/app/entrypoints/virtual/dev.d.ts +2 -0
  32. package/dist/core/app/{entrypoint → entrypoints/virtual}/dev.js +5 -5
  33. package/dist/core/app/entrypoints/virtual/index.d.ts +2 -0
  34. package/dist/core/app/entrypoints/virtual/index.js +5 -0
  35. package/dist/core/app/entrypoints/virtual/prod.d.ts +2 -0
  36. package/dist/core/app/entrypoints/virtual/prod.js +8 -0
  37. package/dist/core/app/node.d.ts +48 -7
  38. package/dist/core/app/node.js +138 -134
  39. package/dist/core/app/types.d.ts +10 -0
  40. package/dist/core/build/app.d.ts +1 -1
  41. package/dist/core/build/app.js +1 -1
  42. package/dist/core/build/pipeline.js +1 -1
  43. package/dist/core/build/plugins/plugin-manifest.js +6 -1
  44. package/dist/core/build/plugins/plugin-ssr.d.ts +6 -0
  45. package/dist/core/build/plugins/plugin-ssr.js +2 -1
  46. package/dist/core/build/static-build.js +7 -7
  47. package/dist/core/config/merge.js +2 -1
  48. package/dist/core/constants.js +1 -1
  49. package/dist/core/create-vite.js +8 -2
  50. package/dist/core/dev/adapter-validation.js +10 -0
  51. package/dist/core/dev/dev.js +2 -1
  52. package/dist/core/dev/restart.d.ts +1 -0
  53. package/dist/core/dev/restart.js +18 -16
  54. package/dist/core/messages.js +2 -2
  55. package/dist/core/render-context.js +12 -8
  56. package/dist/core/routing/manifest/create.js +1 -1
  57. package/dist/manifest/serialized.js +6 -1
  58. package/dist/manifest/virtual-module.js +20 -1
  59. package/dist/runtime/server/render/util.js +4 -1
  60. package/dist/types/public/integrations.d.ts +76 -31
  61. package/dist/types/public/manifest.d.ts +2 -0
  62. package/dist/virtual-modules/i18n.js +1 -1
  63. package/dist/vite-plugin-adapter-config/index.js +1 -1
  64. package/dist/vite-plugin-app/app.d.ts +1 -1
  65. package/dist/vite-plugin-app/app.js +1 -1
  66. package/dist/vite-plugin-astro-server/plugin.js +6 -1
  67. package/dist/vite-plugin-markdown/index.js +6 -3
  68. package/dist/vite-plugin-renderers/index.d.ts +4 -2
  69. package/dist/vite-plugin-renderers/index.js +9 -0
  70. package/dist/vite-plugin-routes/index.js +1 -1
  71. package/dist/vite-plugin-shiki-styles/index.d.ts +9 -0
  72. package/dist/vite-plugin-shiki-styles/index.js +44 -0
  73. package/package.json +16 -19
  74. package/types/content.d.ts +0 -1
  75. package/components/image.css +0 -11
  76. package/dist/assets/utils/imageAttributes.d.ts +0 -2
  77. package/dist/assets/utils/imageAttributes.js +0 -14
  78. package/dist/core/app/entrypoint/dev.d.ts +0 -2
  79. package/dist/core/app/entrypoint/prod.d.ts +0 -2
  80. package/dist/core/app/entrypoint/prod.js +0 -8
  81. package/dist/core/app/entrypoint.d.ts +0 -1
  82. package/dist/core/app/entrypoint.js +0 -4
  83. package/dist/core/app/index.d.ts +0 -7
package/README.md CHANGED
@@ -15,7 +15,7 @@
15
15
  npm create astro@latest
16
16
 
17
17
  # Manual:
18
- npm install --save-dev astro
18
+ npm install astro
19
19
  ```
20
20
 
21
21
  Looking for help? Start with our [Getting Started](https://docs.astro.build/en/getting-started/) guide.
package/client.d.ts CHANGED
@@ -84,6 +84,11 @@ declare module 'astro:assets' {
84
84
  }: AstroAssets;
85
85
  }
86
86
 
87
+ declare module 'virtual:astro:image-styles.css' {
88
+ const styles: string;
89
+ export default styles;
90
+ }
91
+
87
92
  type ImageMetadata = import('./dist/assets/types.js').ImageMetadata;
88
93
 
89
94
  declare module '*.gif' {
@@ -1,10 +1,18 @@
1
1
  ---
2
- import { type ThemePresets, createShikiHighlighter } from '@astrojs/markdown-remark';
2
+ import {
3
+ type ThemePresets,
4
+ createShikiHighlighter,
5
+ globalShikiStyleCollector,
6
+ transformerStyleToClass,
7
+ } from '@astrojs/markdown-remark';
3
8
  import type { ShikiTransformer, ThemeRegistration, ThemeRegistrationRaw } from 'shiki';
4
9
  import { bundledLanguages } from 'shiki/langs';
5
10
  import type { CodeLanguage } from '../dist/types/public/common.js';
6
11
  import type { HTMLAttributes } from '../types.js';
7
12
 
13
+ // Code.astro always uses Shiki, so import the virtual CSS module
14
+ import 'virtual:astro:shiki-styles.css';
15
+
8
16
  interface Props extends Omit<HTMLAttributes<'pre'>, 'lang'> {
9
17
  /** The code to highlight. Required. */
10
18
  code: string;
@@ -16,6 +24,14 @@ interface Props extends Omit<HTMLAttributes<'pre'>, 'lang'> {
16
24
  * @default "plaintext"
17
25
  */
18
26
  lang?: CodeLanguage;
27
+ /**
28
+ * Additional languages to load.
29
+ * Useful if `code` embeds languages not included by the given `lang`
30
+ * For example, TSX in Vue
31
+ *
32
+ * @default []
33
+ */
34
+ embeddedLangs?: CodeLanguage[];
19
35
  /**
20
36
  * A metastring to pass to the highlighter.
21
37
  * Allows passing information to transformers: https://shiki.style/guide/transformers#meta
@@ -72,6 +88,7 @@ interface Props extends Omit<HTMLAttributes<'pre'>, 'lang'> {
72
88
  const {
73
89
  code,
74
90
  lang = 'plaintext',
91
+ embeddedLangs = [],
75
92
  meta,
76
93
  theme = 'github-dark',
77
94
  themes = {},
@@ -101,16 +118,23 @@ const highlighter = await createShikiHighlighter({
101
118
  ? lang
102
119
  : 'plaintext'
103
120
  : (lang as any),
121
+ ...embeddedLangs,
104
122
  ],
105
123
  theme,
106
124
  themes,
107
125
  });
108
126
 
127
+ // Combine style-to-class transformer with user-provided transformers
128
+ const allTransformers = [
129
+ globalShikiStyleCollector.register(transformerStyleToClass()),
130
+ ...transformers,
131
+ ];
132
+
109
133
  const html = await highlighter.codeToHtml(code, typeof lang === 'string' ? lang : lang.name, {
110
134
  defaultColor,
111
135
  wrap,
112
136
  inline,
113
- transformers,
137
+ transformers: allTransformers,
114
138
  meta,
115
139
  attributes: rest as any,
116
140
  });
@@ -5,8 +5,6 @@ import Image from './Image.astro';
5
5
  type Props = LocalImageProps | RemoteImageProps;
6
6
 
7
7
  const { class: className, ...props } = Astro.props;
8
-
9
- import './image.css';
10
8
  ---
11
9
 
12
10
  {/* Applying class outside of the spread prevents it from applying unnecessary astro-* classes */}
@@ -4,7 +4,6 @@ import { default as Picture, type Props as PictureProps } from './Picture.astro'
4
4
  type Props = PictureProps;
5
5
 
6
6
  const { class: className, ...props } = Astro.props;
7
- import './image.css';
8
7
  ---
9
8
 
10
9
  {/* Applying class outside of the spread prevents it from applying unnecessary astro-* classes */}
@@ -1,6 +1,8 @@
1
1
  export declare const VIRTUAL_MODULE_ID = "astro:assets";
2
2
  export declare const RESOLVED_VIRTUAL_MODULE_ID: string;
3
3
  export declare const VIRTUAL_SERVICE_ID = "virtual:image-service";
4
+ export declare const VIRTUAL_IMAGE_STYLES_ID = "virtual:astro:image-styles.css";
5
+ export declare const RESOLVED_VIRTUAL_IMAGE_STYLES_ID: string;
4
6
  export declare const VALID_INPUT_FORMATS: readonly ["jpeg", "jpg", "png", "tiff", "webp", "gif", "svg", "avif"];
5
7
  /**
6
8
  * Valid formats that our base services support.
@@ -1,6 +1,8 @@
1
1
  const VIRTUAL_MODULE_ID = "astro:assets";
2
2
  const RESOLVED_VIRTUAL_MODULE_ID = "\0" + VIRTUAL_MODULE_ID;
3
3
  const VIRTUAL_SERVICE_ID = "virtual:image-service";
4
+ const VIRTUAL_IMAGE_STYLES_ID = "virtual:astro:image-styles.css";
5
+ const RESOLVED_VIRTUAL_IMAGE_STYLES_ID = "\0" + VIRTUAL_IMAGE_STYLES_ID;
4
6
  const VALID_INPUT_FORMATS = [
5
7
  "jpeg",
6
8
  "jpg",
@@ -36,10 +38,12 @@ const DEFAULT_HASH_PROPS = [
36
38
  export {
37
39
  DEFAULT_HASH_PROPS,
38
40
  DEFAULT_OUTPUT_FORMAT,
41
+ RESOLVED_VIRTUAL_IMAGE_STYLES_ID,
39
42
  RESOLVED_VIRTUAL_MODULE_ID,
40
43
  VALID_INPUT_FORMATS,
41
44
  VALID_OUTPUT_FORMATS,
42
45
  VALID_SUPPORTED_FORMATS,
46
+ VIRTUAL_IMAGE_STYLES_ID,
43
47
  VIRTUAL_MODULE_ID,
44
48
  VIRTUAL_SERVICE_ID
45
49
  };
@@ -1,29 +1,32 @@
1
- import { type AdobeProviderOptions, type GoogleFamilyOptions, type GoogleiconsFamilyOptions } from 'unifont';
1
+ import { type AdobeProviderOptions, type GoogleFamilyOptions, type GoogleiconsFamilyOptions, type NpmProviderOptions, type NpmFamilyOptions } from 'unifont';
2
2
  import type { FontProvider } from '../types.js';
3
3
  import { type LocalFamilyOptions } from './local.js';
4
- /** [Adobe](https://fonts.adobe.com/) */
4
+ /** [Adobe](https://v6.docs.astro.build/en/reference/font-provider-reference/#adobe) */
5
5
  declare function adobe(config: AdobeProviderOptions): FontProvider;
6
- /** [Bunny](https://fonts.bunny.net/) */
6
+ /** [Bunny](https://v6.docs.astro.build/en/reference/font-provider-reference/#bunny) */
7
7
  declare function bunny(): FontProvider;
8
- /** [Fontshare](https://www.fontshare.com/) */
8
+ /** [Fontshare](https://v6.docs.astro.build/en/reference/font-provider-reference/#fontshare) */
9
9
  declare function fontshare(): FontProvider;
10
- /** [Fontsource](https://fontsource.org/) */
10
+ /** [Fontsource](https://v6.docs.astro.build/en/reference/font-provider-reference/#fontsource) */
11
11
  declare function fontsource(): FontProvider;
12
- /** [Google](https://fonts.google.com/) */
12
+ /** [Google](https://v6.docs.astro.build/en/reference/font-provider-reference/#google) */
13
13
  declare function google(): FontProvider<GoogleFamilyOptions | undefined>;
14
- /** [Google Icons](https://fonts.google.com/icons) */
14
+ /** [Google Icons](https://v6.docs.astro.build/en/reference/font-provider-reference/#google-icons) */
15
15
  declare function googleicons(): FontProvider<GoogleiconsFamilyOptions | undefined>;
16
- /** A provider that handles local files. */
16
+ /** [Local](https://v6.docs.astro.build/en/reference/font-provider-reference/#local) */
17
17
  declare function local(): FontProvider<LocalFamilyOptions>;
18
+ /** [NPM](https://v6.docs.astro.build/en/reference/font-provider-reference/#npm) */
19
+ declare function npm(options?: Omit<NpmProviderOptions, 'root' | 'readFile'>): FontProvider<NpmFamilyOptions | undefined>;
18
20
  /**
19
21
  * Astro exports a few built-in providers:
20
- * - [Adobe](https://fonts.adobe.com/)
21
- * - [Bunny](https://fonts.bunny.net/)
22
- * - [Fontshare](https://www.fontshare.com/)
23
- * - [Fontsource](https://fontsource.org/)
24
- * - [Google](https://fonts.google.com/)
25
- * - [Google Icons](https://fonts.google.com/icons)
26
- * - Local
22
+ * - [Adobe](https://v6.docs.astro.build/en/reference/font-provider-reference/#adobe)
23
+ * - [Bunny](https://v6.docs.astro.build/en/reference/font-provider-reference/#bunny)
24
+ * - [Fontshare](https://v6.docs.astro.build/en/reference/font-provider-reference/#fontshare)
25
+ * - [Fontsource](https://v6.docs.astro.build/en/reference/font-provider-reference/#fontsource)
26
+ * - [Google](https://v6.docs.astro.build/en/reference/font-provider-reference/#google)
27
+ * - [Google Icons](https://v6.docs.astro.build/en/reference/font-provider-reference/#google-icons)
28
+ * - [Local](https://v6.docs.astro.build/en/reference/font-provider-reference/#local)
29
+ * - [NPM](TODO:)
27
30
  */
28
31
  export declare const fontProviders: {
29
32
  adobe: typeof adobe;
@@ -33,5 +36,6 @@ export declare const fontProviders: {
33
36
  google: typeof google;
34
37
  googleicons: typeof googleicons;
35
38
  local: typeof local;
39
+ npm: typeof npm;
36
40
  };
37
41
  export {};
@@ -3,6 +3,8 @@ import {
3
3
  } from "unifont";
4
4
  import { FontaceFontFileReader } from "../infra/fontace-font-file-reader.js";
5
5
  import { LocalFontProvider } from "./local.js";
6
+ import { fileURLToPath } from "node:url";
7
+ import { readFile } from "node:fs/promises";
6
8
  function adobe(config) {
7
9
  const provider = providers.adobe(config);
8
10
  let initializedProvider;
@@ -105,6 +107,25 @@ function local() {
105
107
  fontFileReader: new FontaceFontFileReader()
106
108
  });
107
109
  }
110
+ function npm(options) {
111
+ let initializedProvider;
112
+ return {
113
+ name: providers.npm()._name,
114
+ async init(context) {
115
+ initializedProvider = await providers.npm({
116
+ ...options,
117
+ root: fileURLToPath(context.root),
118
+ readFile: (path) => readFile(path, "utf-8").catch(() => null)
119
+ })(context);
120
+ },
121
+ async resolveFont({ familyName, ...rest }) {
122
+ return await initializedProvider?.resolveFont(familyName, rest);
123
+ },
124
+ async listFonts() {
125
+ return await initializedProvider?.listFonts?.();
126
+ }
127
+ };
128
+ }
108
129
  const fontProviders = {
109
130
  adobe,
110
131
  bunny,
@@ -112,7 +133,8 @@ const fontProviders = {
112
133
  fontsource,
113
134
  google,
114
135
  googleicons,
115
- local
136
+ local,
137
+ npm
116
138
  };
117
139
  export {
118
140
  fontProviders
@@ -2,5 +2,6 @@ import type { AstroConfig } from '../types/public/config.js';
2
2
  import type { AstroAdapterClientConfig } from '../types/public/integrations.js';
3
3
  import { type ImageService } from './services/service.js';
4
4
  import { type GetImageResult, type UnresolvedImageTransform } from './types.js';
5
+ export declare const cssFitValues: string[];
5
6
  export declare function getConfiguredImageService(): Promise<ImageService>;
6
7
  export declare function getImage(options: UnresolvedImageTransform, imageConfig: AstroConfig['image'] & AstroAdapterClientConfig): Promise<GetImageResult>;
@@ -11,10 +11,10 @@ import { isLocalService } from "./services/service.js";
11
11
  import {
12
12
  isImageMetadata
13
13
  } from "./types.js";
14
- import { addCSSVarsToStyle, cssFitValues } from "./utils/imageAttributes.js";
15
14
  import { isESMImportedImage, isRemoteImage, resolveSrc } from "./utils/imageKind.js";
16
15
  import { inferRemoteSize } from "./utils/remoteProbe.js";
17
16
  import { createPlaceholderURL, stringifyPlaceholderURL } from "./utils/url.js";
17
+ const cssFitValues = ["fill", "contain", "cover", "scale-down"];
18
18
  async function getConfiguredImageService() {
19
19
  if (!globalThis?.astroAsset?.imageService) {
20
20
  const { default: service } = await import(
@@ -110,14 +110,13 @@ async function getImage(options, imageConfig) {
110
110
  });
111
111
  resolvedOptions.sizes ||= getSizesAttribute({ width: resolvedOptions.width, layout });
112
112
  delete resolvedOptions.densities;
113
- resolvedOptions.style = addCSSVarsToStyle(
114
- {
115
- fit: cssFitValues.includes(resolvedOptions.fit ?? "") && resolvedOptions.fit,
116
- pos: resolvedOptions.position
117
- },
118
- resolvedOptions.style
119
- );
120
113
  resolvedOptions["data-astro-image"] = layout;
114
+ if (resolvedOptions.fit && cssFitValues.includes(resolvedOptions.fit)) {
115
+ resolvedOptions["data-astro-image-fit"] = resolvedOptions.fit;
116
+ }
117
+ if (resolvedOptions.position) {
118
+ resolvedOptions["data-astro-image-pos"] = resolvedOptions.position.replace(/\s+/g, "-");
119
+ }
121
120
  }
122
121
  const validatedOptions = service.validateOptions ? await service.validateOptions(resolvedOptions, imageConfig) : resolvedOptions;
123
122
  const srcSetTransforms = service.getSrcSet ? await service.getSrcSet(validatedOptions, imageConfig) : [];
@@ -182,6 +181,7 @@ async function getImage(options, imageConfig) {
182
181
  };
183
182
  }
184
183
  export {
184
+ cssFitValues,
185
185
  getConfiguredImageService,
186
186
  getImage
187
187
  };
@@ -0,0 +1 @@
1
+ export declare function generateImageStylesCSS(defaultObjectFit?: string, defaultObjectPosition?: string): string;
@@ -0,0 +1,38 @@
1
+ import { cssFitValues } from "../internal.js";
2
+ function generateImageStylesCSS(defaultObjectFit, defaultObjectPosition) {
3
+ const fitStyles = cssFitValues.map(
4
+ (fit) => `
5
+ [data-astro-image-fit="${fit}"] {
6
+ object-fit: ${fit};
7
+ }`
8
+ ).join("\n");
9
+ const defaultFitStyle = defaultObjectFit && cssFitValues.includes(defaultObjectFit) ? `
10
+ :where([data-astro-image]:not([data-astro-image-fit])) {
11
+ object-fit: ${defaultObjectFit};
12
+ }` : "";
13
+ const positionStyle = defaultObjectPosition ? `
14
+ [data-astro-image-pos="${defaultObjectPosition.replace(/\s+/g, "-")}"] {
15
+ object-position: ${defaultObjectPosition};
16
+ }
17
+
18
+ :where([data-astro-image]:not([data-astro-image-pos])) {
19
+ object-position: ${defaultObjectPosition};
20
+ }` : "";
21
+ return `
22
+ :where([data-astro-image]) {
23
+ height: auto;
24
+ }
25
+ :where([data-astro-image="full-width"]) {
26
+ width: 100%;
27
+ }
28
+ :where([data-astro-image="constrained"]) {
29
+ max-width: 100%;
30
+ }
31
+ ${fitStyles}
32
+ ${defaultFitStyle}
33
+ ${positionStyle}
34
+ `.trim();
35
+ }
36
+ export {
37
+ generateImageStylesCSS
38
+ };
@@ -11,8 +11,10 @@ import {
11
11
  import { normalizePath } from "../core/viteUtils.js";
12
12
  import { isAstroServerEnvironment } from "../environments.js";
13
13
  import {
14
+ RESOLVED_VIRTUAL_IMAGE_STYLES_ID,
14
15
  RESOLVED_VIRTUAL_MODULE_ID,
15
16
  VALID_INPUT_FORMATS,
17
+ VIRTUAL_IMAGE_STYLES_ID,
16
18
  VIRTUAL_MODULE_ID,
17
19
  VIRTUAL_SERVICE_ID
18
20
  } from "./consts.js";
@@ -114,46 +116,46 @@ function assets({ fs, settings, sync, logger }) {
114
116
  handler() {
115
117
  return {
116
118
  code: `
117
- import { getConfiguredImageService as _getConfiguredImageService } from "astro/assets";
118
- export { isLocalService } from "astro/assets";
119
- import { getImage as getImageInternal } from "astro/assets";
120
- export { default as Image } from "astro/components/${imageComponentPrefix}Image.astro";
121
- export { default as Picture } from "astro/components/${imageComponentPrefix}Picture.astro";
122
- import { inferRemoteSize as inferRemoteSizeInternal } from "astro/assets/utils/inferRemoteSize.js";
119
+ import { getConfiguredImageService as _getConfiguredImageService } from "astro/assets";
120
+ export { isLocalService } from "astro/assets";
121
+ import { getImage as getImageInternal } from "astro/assets";
122
+ ${settings.config.image.responsiveStyles ? `import "${VIRTUAL_IMAGE_STYLES_ID}";` : ""}
123
+ export { default as Image } from "astro/components/${imageComponentPrefix}Image.astro";
124
+ export { default as Picture } from "astro/components/${imageComponentPrefix}Picture.astro";
125
+ import { inferRemoteSize as inferRemoteSizeInternal } from "astro/assets/utils/inferRemoteSize.js";
123
126
 
124
- export { default as Font } from "astro/components/Font.astro";
125
- export * from "${RUNTIME_VIRTUAL_MODULE_ID}";
126
-
127
- export const getConfiguredImageService = _getConfiguredImageService;
127
+ export { default as Font } from "astro/components/Font.astro";
128
+ export * from "${RUNTIME_VIRTUAL_MODULE_ID}";
129
+
130
+ export const getConfiguredImageService = _getConfiguredImageService;
128
131
 
129
132
  export const viteFSConfig = ${JSON.stringify(resolvedConfig.server.fs ?? {})};
130
133
 
131
- export const safeModulePaths = new Set(${JSON.stringify(
134
+ export const safeModulePaths = new Set(${JSON.stringify(
132
135
  // @ts-expect-error safeModulePaths is internal to Vite
133
136
  Array.from(resolvedConfig.safeModulePaths ?? [])
134
137
  )});
135
138
 
136
- const assetQueryParams = ${settings.adapter?.client?.assetQueryParams ? `new URLSearchParams(${JSON.stringify(
139
+ const assetQueryParams = ${settings.adapter?.client?.assetQueryParams ? `new URLSearchParams(${JSON.stringify(
137
140
  Array.from(settings.adapter.client.assetQueryParams.entries())
138
141
  )})` : "undefined"};
139
- export const imageConfig = ${JSON.stringify(settings.config.image)};
140
- Object.defineProperty(imageConfig, 'assetQueryParams', {
141
- value: assetQueryParams,
142
- enumerable: false,
143
- configurable: true,
144
- });
145
- export const inferRemoteSize = async (url) => {
142
+ export const imageConfig = ${JSON.stringify(settings.config.image)};
143
+ Object.defineProperty(imageConfig, 'assetQueryParams', {
144
+ value: assetQueryParams,
145
+ enumerable: false,
146
+ configurable: true,
147
+ });
148
+ export const inferRemoteSize = async (url) => {
146
149
  const service = await _getConfiguredImageService()
147
150
 
148
151
  return service.getRemoteSize?.(url, imageConfig) ?? inferRemoteSizeInternal(url)
149
- }
150
- // This is used by the @astrojs/node integration to locate images.
151
- // It's unused on other platforms, but on some platforms like Netlify (and presumably also Vercel)
152
- // new URL("dist/...") is interpreted by the bundler as a signal to include that directory
153
- // in the Lambda bundle, which would bloat the bundle with images.
154
- // To prevent this, we mark the URL construction as pure,
155
- // so that it's tree-shaken away for all platforms that don't need it.
156
- export const outDir = /* #__PURE__ */ new URL(${JSON.stringify(
152
+ } // This is used by the @astrojs/node integration to locate images.
153
+ // It's unused on other platforms, but on some platforms like Netlify (and presumably also Vercel)
154
+ // new URL("dist/...") is interpreted by the bundler as a signal to include that directory
155
+ // in the Lambda bundle, which would bloat the bundle with images.
156
+ // To prevent this, we mark the URL construction as pure,
157
+ // so that it's tree-shaken away for all platforms that don't need it.
158
+ export const outDir = /* #__PURE__ */ new URL(${JSON.stringify(
157
159
  new URL(
158
160
  settings.buildOutput === "server" ? settings.config.build.client : settings.config.outDir
159
161
  )
@@ -161,8 +163,8 @@ function assets({ fs, settings, sync, logger }) {
161
163
  export const serverDir = /* #__PURE__ */ new URL(${JSON.stringify(
162
164
  new URL(settings.config.build.server)
163
165
  )});
164
- export const getImage = async (options) => await getImageInternal(options, imageConfig);
165
- `
166
+ export const getImage = async (options) => await getImageInternal(options, imageConfig);
167
+ `
166
168
  };
167
169
  }
168
170
  },
@@ -251,7 +253,35 @@ function assets({ fs, settings, sync, logger }) {
251
253
  }
252
254
  }
253
255
  },
254
- fontsPlugin({ settings, sync, logger })
256
+ fontsPlugin({ settings, sync, logger }),
257
+ {
258
+ name: "astro:image-styles",
259
+ resolveId: {
260
+ filter: {
261
+ id: new RegExp(`^${VIRTUAL_IMAGE_STYLES_ID}$`)
262
+ },
263
+ handler(id) {
264
+ if (id === VIRTUAL_IMAGE_STYLES_ID) {
265
+ return RESOLVED_VIRTUAL_IMAGE_STYLES_ID;
266
+ }
267
+ }
268
+ },
269
+ load: {
270
+ filter: {
271
+ id: new RegExp(`^${RESOLVED_VIRTUAL_IMAGE_STYLES_ID}$`)
272
+ },
273
+ async handler(id) {
274
+ if (id === RESOLVED_VIRTUAL_IMAGE_STYLES_ID) {
275
+ const { generateImageStylesCSS } = await import("./utils/generateImageStylesCSS.js");
276
+ const css = generateImageStylesCSS(
277
+ settings.config.image.objectFit,
278
+ settings.config.image.objectPosition
279
+ );
280
+ return { code: css };
281
+ }
282
+ }
283
+ }
284
+ }
255
285
  ];
256
286
  }
257
287
  export {