astro 4.3.7 → 4.4.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/Image.astro +4 -0
- package/components/Picture.astro +4 -0
- package/dist/@types/astro.d.ts +42 -42
- package/dist/assets/build/generate.d.ts +1 -1
- package/dist/assets/build/generate.js +1 -2
- package/dist/assets/internal.js +14 -0
- package/dist/assets/types.d.ts +23 -2
- package/dist/assets/utils/metadata.js +3 -3
- package/dist/assets/utils/remoteProbe.d.ts +2 -0
- package/dist/assets/utils/remoteProbe.js +35 -0
- package/dist/assets/utils/vendor/image-size/detector.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/detector.js +24 -0
- package/dist/assets/utils/vendor/image-size/lookup.d.ts +10 -0
- package/dist/assets/utils/vendor/image-size/lookup.js +26 -0
- package/dist/assets/utils/vendor/image-size/types/bmp.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/bmp.js +11 -0
- package/dist/assets/utils/vendor/image-size/types/cur.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/cur.js +17 -0
- package/dist/assets/utils/vendor/image-size/types/dds.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/dds.js +11 -0
- package/dist/assets/utils/vendor/image-size/types/gif.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/gif.js +12 -0
- package/dist/assets/utils/vendor/image-size/types/heif.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/heif.js +53 -0
- package/dist/assets/utils/vendor/image-size/types/icns.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/icns.js +85 -0
- package/dist/assets/utils/vendor/image-size/types/ico.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/ico.js +43 -0
- package/dist/assets/utils/vendor/image-size/types/index.d.ts +3 -0
- package/dist/assets/utils/vendor/image-size/types/index.js +43 -0
- package/dist/assets/utils/vendor/image-size/types/interface.d.ts +13 -0
- package/dist/assets/utils/vendor/image-size/types/interface.js +0 -0
- package/dist/assets/utils/vendor/image-size/types/j2c.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/j2c.js +12 -0
- package/dist/assets/utils/vendor/image-size/types/jp2.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/jp2.js +25 -0
- package/dist/assets/utils/vendor/image-size/types/jpg.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/jpg.js +97 -0
- package/dist/assets/utils/vendor/image-size/types/ktx.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/ktx.js +19 -0
- package/dist/assets/utils/vendor/image-size/types/png.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/png.js +34 -0
- package/dist/assets/utils/vendor/image-size/types/pnm.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/pnm.js +69 -0
- package/dist/assets/utils/vendor/image-size/types/psd.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/psd.js +11 -0
- package/dist/assets/utils/vendor/image-size/types/svg.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/svg.js +94 -0
- package/dist/assets/utils/vendor/image-size/types/tga.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/tga.js +15 -0
- package/dist/assets/utils/vendor/image-size/types/tiff.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/tiff.js +66 -0
- package/dist/assets/utils/vendor/image-size/types/utils.d.ts +15 -0
- package/dist/assets/utils/vendor/image-size/types/utils.js +60 -0
- package/dist/assets/utils/vendor/image-size/types/webp.d.ts +2 -0
- package/dist/assets/utils/vendor/image-size/types/webp.js +52 -0
- package/dist/cli/add/babel.d.ts +1 -1
- package/dist/cli/add/index.js +10 -3
- package/dist/cli/db/index.js +2 -0
- package/dist/cli/info/index.js +2 -0
- package/dist/cli/preferences/index.js +2 -0
- package/dist/content/runtime.js +3 -1
- package/dist/content/types-generator.js +7 -27
- package/dist/core/app/index.js +39 -122
- package/dist/core/app/pipeline.d.ts +7 -0
- package/dist/core/app/pipeline.js +39 -0
- package/dist/core/base-pipeline.d.ts +59 -0
- package/dist/core/base-pipeline.js +27 -0
- package/dist/core/build/generate.d.ts +1 -1
- package/dist/core/build/generate.js +39 -109
- package/dist/core/build/index.js +0 -4
- package/dist/core/build/{buildPipeline.d.ts → pipeline.d.ts} +13 -13
- package/dist/core/build/pipeline.js +180 -0
- package/dist/core/build/plugins/plugin-css.js +6 -5
- package/dist/core/build/plugins/plugin-hoisted-scripts.js +6 -5
- package/dist/core/build/plugins/util.d.ts +2 -1
- package/dist/core/build/plugins/util.js +12 -1
- package/dist/core/build/types.d.ts +0 -2
- package/dist/core/constants.d.ts +10 -1
- package/dist/core/constants.js +14 -4
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/dev/restart.js +1 -1
- package/dist/core/endpoint/index.d.ts +5 -4
- package/dist/core/endpoint/index.js +7 -34
- package/dist/core/errors/errors-data.d.ts +16 -3
- package/dist/core/errors/errors-data.js +9 -2
- package/dist/core/messages.js +2 -2
- package/dist/core/middleware/callMiddleware.d.ts +1 -1
- package/dist/core/middleware/callMiddleware.js +2 -9
- package/dist/core/middleware/index.d.ts +2 -2
- package/dist/core/middleware/index.js +74 -9
- package/dist/core/module-loader/vite.js +4 -4
- package/dist/core/preview/index.js +2 -0
- package/dist/core/preview/static-preview-server.js +1 -7
- package/dist/core/redirects/helpers.d.ts +1 -3
- package/dist/core/redirects/helpers.js +0 -29
- package/dist/core/redirects/index.d.ts +2 -1
- package/dist/core/redirects/index.js +3 -3
- package/dist/core/redirects/render.d.ts +2 -0
- package/dist/core/redirects/render.js +33 -0
- package/dist/core/render/index.d.ts +7 -13
- package/dist/core/render/index.js +7 -7
- package/dist/core/render/params-and-props.d.ts +8 -3
- package/dist/core/render/params-and-props.js +24 -16
- package/dist/core/render/result.d.ts +6 -5
- package/dist/core/render/result.js +3 -4
- package/dist/core/render-context.d.ts +32 -0
- package/dist/core/render-context.js +219 -0
- package/dist/core/routing/index.d.ts +0 -1
- package/dist/core/routing/index.js +0 -2
- package/dist/core/routing/manifest/create.js +11 -27
- package/dist/core/routing/params.d.ts +1 -7
- package/dist/core/routing/params.js +0 -15
- package/dist/core/sync/index.js +3 -3
- package/dist/i18n/middleware.d.ts +0 -5
- package/dist/i18n/middleware.js +61 -69
- package/dist/i18n/utils.d.ts +25 -0
- package/dist/{core/render/context.js → i18n/utils.js} +3 -49
- package/dist/prerender/routing.d.ts +1 -1
- package/dist/prerender/routing.js +20 -21
- package/dist/runtime/client/dev-toolbar/apps/astro.js +14 -10
- package/dist/runtime/client/dev-toolbar/apps/audit/a11y.js +2 -2
- package/dist/runtime/client/dev-toolbar/apps/audit/index.d.ts +1 -1
- package/dist/runtime/client/dev-toolbar/apps/audit/index.js +115 -6
- package/dist/runtime/client/dev-toolbar/apps/audit/perf.d.ts +2 -0
- package/dist/runtime/client/dev-toolbar/apps/audit/perf.js +110 -0
- package/dist/runtime/client/dev-toolbar/apps/utils/highlight.d.ts +1 -1
- package/dist/runtime/client/dev-toolbar/apps/utils/highlight.js +6 -1
- package/dist/runtime/client/dev-toolbar/ui-library/card.js +1 -1
- package/dist/runtime/server/astro-island.js +10 -1
- package/dist/runtime/server/astro-island.prebuilt-dev.d.ts +7 -0
- package/dist/runtime/server/astro-island.prebuilt-dev.js +4 -0
- package/dist/runtime/server/astro-island.prebuilt.d.ts +1 -1
- package/dist/runtime/server/astro-island.prebuilt.js +1 -1
- package/dist/runtime/server/endpoint.js +2 -2
- package/dist/runtime/server/render/astro/render.d.ts +1 -0
- package/dist/runtime/server/render/astro/render.js +81 -2
- package/dist/runtime/server/render/component.js +6 -0
- package/dist/runtime/server/render/page.js +15 -2
- package/dist/runtime/server/render/util.d.ts +7 -0
- package/dist/runtime/server/render/util.js +15 -0
- package/dist/runtime/server/scripts.js +2 -4
- package/dist/runtime/server/transition.js +14 -1
- package/dist/vite-plugin-astro/hmr.d.ts +1 -0
- package/dist/vite-plugin-astro/hmr.js +7 -4
- package/dist/vite-plugin-astro-server/error.d.ts +2 -2
- package/dist/vite-plugin-astro-server/error.js +2 -5
- package/dist/vite-plugin-astro-server/index.d.ts +0 -6
- package/dist/vite-plugin-astro-server/index.js +0 -19
- package/dist/vite-plugin-astro-server/pipeline.d.ts +19 -0
- package/dist/vite-plugin-astro-server/pipeline.js +117 -0
- package/dist/vite-plugin-astro-server/plugin.js +3 -4
- package/dist/vite-plugin-astro-server/request.d.ts +3 -4
- package/dist/vite-plugin-astro-server/request.js +6 -9
- package/dist/vite-plugin-astro-server/route.d.ts +3 -4
- package/dist/vite-plugin-astro-server/route.js +34 -162
- package/dist/vite-plugin-dev-toolbar/vite-plugin-dev-toolbar.js +3 -3
- package/package.json +7 -12
- package/dist/core/app/ssrPipeline.d.ts +0 -3
- package/dist/core/app/ssrPipeline.js +0 -6
- package/dist/core/build/buildPipeline.js +0 -150
- package/dist/core/pipeline.d.ts +0 -39
- package/dist/core/pipeline.js +0 -107
- package/dist/core/render/context.d.ts +0 -52
- package/dist/core/render/core.d.ts +0 -10
- package/dist/core/render/core.js +0 -65
- package/dist/core/render/environment.d.ts +0 -34
- package/dist/core/render/environment.js +0 -6
- package/dist/runtime/server/consts.d.ts +0 -1
- package/dist/runtime/server/consts.js +0 -4
- package/dist/vite-plugin-astro-server/devPipeline.d.ts +0 -22
- package/dist/vite-plugin-astro-server/devPipeline.js +0 -65
package/dist/i18n/middleware.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { appendForwardSlash, joinPaths } from "@astrojs/internal-helpers/path";
|
|
2
2
|
import { getPathByLocale, normalizeTheLocale } from "./index.js";
|
|
3
3
|
import { shouldAppendForwardSlash } from "../core/build/util.js";
|
|
4
|
-
import {
|
|
5
|
-
const routeDataSymbol = Symbol.for(ROUTE_DATA_SYMBOL);
|
|
4
|
+
import { ROUTE_TYPE_HEADER } from "../core/constants.js";
|
|
6
5
|
function pathnameHasLocale(pathname, locales) {
|
|
7
6
|
const segments = pathname.split("/");
|
|
8
7
|
for (const segment of segments) {
|
|
@@ -65,99 +64,93 @@ function createI18nMiddleware(i18n, base, trailingSlash, buildFormat) {
|
|
|
65
64
|
return void 0;
|
|
66
65
|
};
|
|
67
66
|
return async (context, next) => {
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
const response = await next();
|
|
68
|
+
const type = response.headers.get(ROUTE_TYPE_HEADER);
|
|
69
|
+
if (type !== "page" && type !== "fallback") {
|
|
70
|
+
return response;
|
|
71
71
|
}
|
|
72
|
-
const currentLocale = context
|
|
73
|
-
const url = context.url;
|
|
72
|
+
const { url, currentLocale } = context;
|
|
74
73
|
const { locales, defaultLocale, fallback, routing } = i18n;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
case "domains-prefix-other-locales": {
|
|
79
|
-
if (localeHasntDomain(i18n, currentLocale)) {
|
|
80
|
-
const result = prefixOtherLocales(url, response);
|
|
81
|
-
if (result) {
|
|
82
|
-
return result;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
case "pathname-prefix-other-locales": {
|
|
74
|
+
switch (i18n.routing) {
|
|
75
|
+
case "domains-prefix-other-locales": {
|
|
76
|
+
if (localeHasntDomain(i18n, currentLocale)) {
|
|
88
77
|
const result = prefixOtherLocales(url, response);
|
|
89
78
|
if (result) {
|
|
90
79
|
return result;
|
|
91
80
|
}
|
|
92
|
-
break;
|
|
93
81
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
break;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
case "pathname-prefix-other-locales": {
|
|
85
|
+
const result = prefixOtherLocales(url, response);
|
|
86
|
+
if (result) {
|
|
87
|
+
return result;
|
|
102
88
|
}
|
|
103
|
-
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
case "domains-prefix-always-no-redirect": {
|
|
92
|
+
if (localeHasntDomain(i18n, currentLocale)) {
|
|
104
93
|
const result = prefixAlwaysNoRedirect(url, response);
|
|
105
94
|
if (result) {
|
|
106
95
|
return result;
|
|
107
96
|
}
|
|
108
|
-
break;
|
|
109
97
|
}
|
|
110
|
-
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
case "pathname-prefix-always-no-redirect": {
|
|
101
|
+
const result = prefixAlwaysNoRedirect(url, response);
|
|
102
|
+
if (result) {
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
case "pathname-prefix-always": {
|
|
108
|
+
const result = prefixAlways(url, response, context);
|
|
109
|
+
if (result) {
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
case "domains-prefix-always": {
|
|
115
|
+
if (localeHasntDomain(i18n, currentLocale)) {
|
|
111
116
|
const result = prefixAlways(url, response, context);
|
|
112
117
|
if (result) {
|
|
113
118
|
return result;
|
|
114
119
|
}
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
case "domains-prefix-always": {
|
|
118
|
-
if (localeHasntDomain(i18n, currentLocale)) {
|
|
119
|
-
const result = prefixAlways(url, response, context);
|
|
120
|
-
if (result) {
|
|
121
|
-
return result;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
break;
|
|
125
120
|
}
|
|
121
|
+
break;
|
|
126
122
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
} else if (locale.path === segment) {
|
|
123
|
+
}
|
|
124
|
+
if (response.status >= 300 && fallback) {
|
|
125
|
+
const fallbackKeys = i18n.fallback ? Object.keys(i18n.fallback) : [];
|
|
126
|
+
const segments = url.pathname.split("/");
|
|
127
|
+
const urlLocale = segments.find((segment) => {
|
|
128
|
+
for (const locale of locales) {
|
|
129
|
+
if (typeof locale === "string") {
|
|
130
|
+
if (locale === segment) {
|
|
137
131
|
return true;
|
|
138
132
|
}
|
|
133
|
+
} else if (locale.path === segment) {
|
|
134
|
+
return true;
|
|
139
135
|
}
|
|
140
|
-
return false;
|
|
141
|
-
});
|
|
142
|
-
if (urlLocale && fallbackKeys.includes(urlLocale)) {
|
|
143
|
-
const fallbackLocale = fallback[urlLocale];
|
|
144
|
-
const pathFallbackLocale = getPathByLocale(fallbackLocale, locales);
|
|
145
|
-
let newPathname;
|
|
146
|
-
if (pathFallbackLocale === defaultLocale && routing === "pathname-prefix-other-locales") {
|
|
147
|
-
newPathname = url.pathname.replace(`/${urlLocale}`, ``);
|
|
148
|
-
} else {
|
|
149
|
-
newPathname = url.pathname.replace(`/${urlLocale}`, `/${pathFallbackLocale}`);
|
|
150
|
-
}
|
|
151
|
-
return context.redirect(newPathname);
|
|
152
136
|
}
|
|
137
|
+
return false;
|
|
138
|
+
});
|
|
139
|
+
if (urlLocale && fallbackKeys.includes(urlLocale)) {
|
|
140
|
+
const fallbackLocale = fallback[urlLocale];
|
|
141
|
+
const pathFallbackLocale = getPathByLocale(fallbackLocale, locales);
|
|
142
|
+
let newPathname;
|
|
143
|
+
if (pathFallbackLocale === defaultLocale && routing === "pathname-prefix-other-locales") {
|
|
144
|
+
newPathname = url.pathname.replace(`/${urlLocale}`, ``);
|
|
145
|
+
} else {
|
|
146
|
+
newPathname = url.pathname.replace(`/${urlLocale}`, `/${pathFallbackLocale}`);
|
|
147
|
+
}
|
|
148
|
+
return context.redirect(newPathname);
|
|
153
149
|
}
|
|
154
150
|
}
|
|
155
151
|
return response;
|
|
156
152
|
};
|
|
157
153
|
}
|
|
158
|
-
const i18nPipelineHook = (ctx) => {
|
|
159
|
-
Reflect.set(ctx.request, routeDataSymbol, ctx.route);
|
|
160
|
-
};
|
|
161
154
|
function localeHasntDomain(i18n, currentLocale) {
|
|
162
155
|
for (const domainLocale of Object.values(i18n.domainLookupTable)) {
|
|
163
156
|
if (domainLocale === currentLocale) {
|
|
@@ -167,6 +160,5 @@ function localeHasntDomain(i18n, currentLocale) {
|
|
|
167
160
|
return true;
|
|
168
161
|
}
|
|
169
162
|
export {
|
|
170
|
-
createI18nMiddleware
|
|
171
|
-
i18nPipelineHook
|
|
163
|
+
createI18nMiddleware
|
|
172
164
|
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Locales } from '../@types/astro.js';
|
|
2
|
+
import type { RoutingStrategies } from '../core/config/schema.js';
|
|
3
|
+
type BrowserLocale = {
|
|
4
|
+
locale: string;
|
|
5
|
+
qualityValue: number | undefined;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Parses the value of the `Accept-Header` language:
|
|
9
|
+
*
|
|
10
|
+
* More info: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language
|
|
11
|
+
*
|
|
12
|
+
* Complex example: `fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5`
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseLocale(header: string): BrowserLocale[];
|
|
16
|
+
/**
|
|
17
|
+
* Set the current locale by parsing the value passed from the `Accept-Header`.
|
|
18
|
+
*
|
|
19
|
+
* If multiple locales are present in the header, they are sorted by their quality value and the highest is selected as current locale.
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
export declare function computePreferredLocale(request: Request, locales: Locales): string | undefined;
|
|
23
|
+
export declare function computePreferredLocaleList(request: Request, locales: Locales): string[];
|
|
24
|
+
export declare function computeCurrentLocale(pathname: string, locales: Locales, routingStrategy: RoutingStrategies | undefined, defaultLocale: string | undefined): undefined | string;
|
|
25
|
+
export {};
|
|
@@ -1,44 +1,4 @@
|
|
|
1
|
-
import { normalizeTheLocale, toCodes } from "
|
|
2
|
-
import { AstroError, AstroErrorData } from "../errors/index.js";
|
|
3
|
-
import { getParamsAndProps } from "./params-and-props.js";
|
|
4
|
-
import { ROUTE_DATA_SYMBOL } from "../constants.js";
|
|
5
|
-
const clientLocalsSymbol = Symbol.for("astro.locals");
|
|
6
|
-
const routeDataSymbol = Symbol.for(ROUTE_DATA_SYMBOL);
|
|
7
|
-
async function createRenderContext(options) {
|
|
8
|
-
const request = options.request;
|
|
9
|
-
const pathname = options.pathname ?? new URL(request.url).pathname;
|
|
10
|
-
const [params, props] = await getParamsAndProps({
|
|
11
|
-
mod: options.mod,
|
|
12
|
-
route: options.route,
|
|
13
|
-
routeCache: options.env.routeCache,
|
|
14
|
-
pathname,
|
|
15
|
-
logger: options.env.logger,
|
|
16
|
-
ssr: options.env.ssr
|
|
17
|
-
});
|
|
18
|
-
const context = {
|
|
19
|
-
...options,
|
|
20
|
-
pathname,
|
|
21
|
-
params,
|
|
22
|
-
props,
|
|
23
|
-
locales: options.locales,
|
|
24
|
-
routing: options.routing,
|
|
25
|
-
defaultLocale: options.defaultLocale
|
|
26
|
-
};
|
|
27
|
-
Object.defineProperty(context, "locals", {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
get() {
|
|
30
|
-
return Reflect.get(request, clientLocalsSymbol);
|
|
31
|
-
},
|
|
32
|
-
set(val) {
|
|
33
|
-
if (typeof val !== "object") {
|
|
34
|
-
throw new AstroError(AstroErrorData.LocalsNotAnObject);
|
|
35
|
-
} else {
|
|
36
|
-
Reflect.set(request, clientLocalsSymbol, val);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
return context;
|
|
41
|
-
}
|
|
1
|
+
import { normalizeTheLocale, toCodes } from "./index.js";
|
|
42
2
|
function parseLocale(header) {
|
|
43
3
|
if (header === "*") {
|
|
44
4
|
return [{ locale: header, qualityValue: void 0 }];
|
|
@@ -149,13 +109,8 @@ function computePreferredLocaleList(request, locales) {
|
|
|
149
109
|
}
|
|
150
110
|
return result;
|
|
151
111
|
}
|
|
152
|
-
function computeCurrentLocale(
|
|
153
|
-
const
|
|
154
|
-
if (!routeData) {
|
|
155
|
-
return defaultLocale;
|
|
156
|
-
}
|
|
157
|
-
const pathname = routeData.pathname ?? new URL(request.url).pathname;
|
|
158
|
-
for (const segment of pathname.split("/").filter(Boolean)) {
|
|
112
|
+
function computeCurrentLocale(pathname, locales, routingStrategy, defaultLocale) {
|
|
113
|
+
for (const segment of pathname.split("/")) {
|
|
159
114
|
for (const locale of locales) {
|
|
160
115
|
if (typeof locale === "string") {
|
|
161
116
|
if (!segment.includes(locale))
|
|
@@ -185,6 +140,5 @@ export {
|
|
|
185
140
|
computeCurrentLocale,
|
|
186
141
|
computePreferredLocale,
|
|
187
142
|
computePreferredLocaleList,
|
|
188
|
-
createRenderContext,
|
|
189
143
|
parseLocale
|
|
190
144
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AstroSettings, ComponentInstance, RouteData } from '../@types/astro.js';
|
|
2
|
-
import type DevPipeline from '../vite-plugin-astro-server/
|
|
2
|
+
import type { DevPipeline } from '../vite-plugin-astro-server/pipeline.js';
|
|
3
3
|
type GetSortedPreloadedMatchesParams = {
|
|
4
4
|
pipeline: DevPipeline;
|
|
5
5
|
matches: RouteData[];
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { RedirectComponentInstance, routeIsRedirect } from "../core/redirects/index.js";
|
|
2
|
-
import { preload } from "../vite-plugin-astro-server/index.js";
|
|
3
2
|
import { getPrerenderStatus } from "./metadata.js";
|
|
4
3
|
async function getSortedPreloadedMatches({
|
|
5
4
|
pipeline,
|
|
@@ -17,27 +16,27 @@ async function preloadAndSetPrerenderStatus({
|
|
|
17
16
|
matches,
|
|
18
17
|
settings
|
|
19
18
|
}) {
|
|
20
|
-
const preloaded =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
const preloadedComponent = await preload({ pipeline, filePath });
|
|
31
|
-
const prerenderStatus = getPrerenderStatus({
|
|
32
|
-
filePath,
|
|
33
|
-
loader: pipeline.getModuleLoader()
|
|
19
|
+
const preloaded = new Array();
|
|
20
|
+
for (const route of matches) {
|
|
21
|
+
const filePath = new URL(`./${route.component}`, settings.config.root);
|
|
22
|
+
if (routeIsRedirect(route)) {
|
|
23
|
+
preloaded.push({
|
|
24
|
+
preloadedComponent: RedirectComponentInstance,
|
|
25
|
+
route,
|
|
26
|
+
filePath
|
|
34
27
|
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const preloadedComponent = await pipeline.preload(filePath);
|
|
31
|
+
const prerenderStatus = getPrerenderStatus({
|
|
32
|
+
filePath,
|
|
33
|
+
loader: pipeline.loader
|
|
34
|
+
});
|
|
35
|
+
if (prerenderStatus !== void 0) {
|
|
36
|
+
route.prerender = prerenderStatus;
|
|
37
|
+
}
|
|
38
|
+
preloaded.push({ preloadedComponent, route, filePath });
|
|
39
|
+
}
|
|
41
40
|
return preloaded;
|
|
42
41
|
}
|
|
43
42
|
function prioritizePrerenderedMatchesComparator(a, b) {
|
|
@@ -4,29 +4,33 @@ import { createWindowElement } from "./utils/window.js";
|
|
|
4
4
|
const astroLogo = '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 99 26" width="100"><path fill="#fff" d="M6.70402 22.1453c-1.17459-1.0737-1.51748-3.3297-1.02811-4.9641.84853 1.0304 2.02424 1.3569 3.24204 1.5411 1.88005.2844 3.72635.178 5.47285-.6813.1998-.0984.3844-.2292.6027-.3617.1639.4755.2065.9554.1493 1.4439-.1392 1.1898-.7313 2.1088-1.673 2.8054-.3765.2787-.775.5278-1.1639.7905-1.1948.8075-1.518 1.7544-1.0691 3.1318.0107.0336.0202.0671.0444.149-.6101-.273-1.0557-.6705-1.39518-1.1931-.3586-.5517-.52921-1.1619-.53819-1.8221-.00449-.3213-.00449-.6455-.0477-.9623-.10551-.7722-.46804-1.118-1.15102-1.1379-.70094-.0205-1.2554.4129-1.40244 1.0953-.01122.0523-.02749.1041-.04377.1649l.00112.0006Z"/><path fill="url(#paint0_linear_386_2739)" d="M6.70402 22.1453c-1.17459-1.0737-1.51748-3.3297-1.02811-4.9641.84853 1.0304 2.02424 1.3569 3.24204 1.5411 1.88005.2844 3.72635.178 5.47285-.6813.1998-.0984.3844-.2292.6027-.3617.1639.4755.2065.9554.1493 1.4439-.1392 1.1898-.7313 2.1088-1.673 2.8054-.3765.2787-.775.5278-1.1639.7905-1.1948.8075-1.518 1.7544-1.0691 3.1318.0107.0336.0202.0671.0444.149-.6101-.273-1.0557-.6705-1.39518-1.1931-.3586-.5517-.52921-1.1619-.53819-1.8221-.00449-.3213-.00449-.6455-.0477-.9623-.10551-.7722-.46804-1.118-1.15102-1.1379-.70094-.0205-1.2554.4129-1.40244 1.0953-.01122.0523-.02749.1041-.04377.1649l.00112.0006Z"/><path fill="#fff" d="M0 16.909s3.47815-1.6944 6.96603-1.6944l2.62973-8.13858c.09846-.39359.38592-.66106.71044-.66106.3246 0 .612.26747.7105.66106l2.6297 8.13858c4.1309 0 6.966 1.6944 6.966 1.6944S14.7045.814589 14.693.782298C14.5234.306461 14.2371 0 13.8512 0H6.76183c-.38593 0-.66063.306461-.84174.782298C5.90733.81398 0 16.909 0 16.909ZM36.671 11.7318c0 1.4262-1.7739 2.2779-4.2302 2.2779-1.5985 0-2.1638-.3962-2.1638-1.2281 0-.8715.7018-1.2875 2.3003-1.2875 1.4426 0 2.6707.0198 4.0937.1981v.0396Zm.0195-1.7629c-.8772-.19808-2.2028-.31693-3.7818-.31693-4.6006 0-6.7644 1.08943-6.7644 3.62483 0 2.6344 1.4815 3.6446 4.9125 3.6446 2.9046 0 4.8735-.7328 5.5947-2.5354h.117c-.0195.4358-.039.8716-.039 1.2083 0 .931.156 1.0102.9162 1.0102h3.5869c-.1949-.5546-.3119-2.1194-.3119-3.4663 0-1.446.0585-2.5355.0585-4.00123 0-2.99098-1.7934-4.89253-7.4077-4.89253-2.4173 0-5.1074.41596-7.1543 1.03.1949.81213.4679 2.45617.6043 3.5258 1.774-.83193 4.2887-1.18847 6.2381-1.18847 2.6902 0 3.4309.61404 3.4309 1.86193v.4952ZM46.5325 12.5637c-.4874.0594-1.1502.0594-1.8325.0594-.7213 0-1.3841-.0198-1.8324-.0792 0 .1585-.0195.3367-.0195.4952 0 2.476 1.618 3.922 7.3102 3.922 5.3609 0 7.0958-1.4262 7.0958-3.9418 0-2.3769-1.1501-3.5456-6.238-3.8031-3.9573-.17827-4.3082-.61404-4.3082-1.10924 0-.57442.5068-.87154 3.158-.87154 2.7487 0 3.4894.37635 3.4894 1.16866v.17827c.3899-.01981 1.0917-.03961 1.813-.03961.6823 0 1.423.0198 1.8519.05942 0-.17827.0195-.33674.0195-.47539 0-2.91175-2.4172-3.86252-7.0958-3.86252-5.2634 0-7.0373 1.2875-7.0373 3.8031 0 2.25805 1.423 3.66445 6.472 3.88235 3.7233.1188 4.1327.5348 4.1327 1.1092 0 .6141-.6043.8914-3.2165.8914-3.0021 0-3.7623-.416-3.7623-1.2677v-.1189ZM63.6883 2.125c-1.423 1.32712-3.9768 2.65425-5.3998 3.01079.0195.73289.0195 2.07982.0195 2.81271l1.3061.01981c-.0195 1.40635-.039 3.10979-.039 4.23889 0 2.6344 1.3841 4.6152 5.6922 4.6152 1.813 0 3.0216-.1981 4.5226-.515-.1559-.9706-.3314-2.4562-.3898-3.5852-.8968.2971-2.0274.4556-3.275.4556-1.735 0-2.4368-.4754-2.4368-1.8422 0-1.1884 0-2.29767.0195-3.32768 2.2223.01981 4.4446.05943 5.7507.09904-.0195-1.03.0195-2.51559.078-3.50598-1.8909.03961-4.0157.05942-5.7702.05942.0195-.87154.039-1.70347.0585-2.5354h-.1365ZM75.3313 7.35427c.0195-1.03001.039-1.90156.0585-2.75329h-3.9183c.0585 1.70347.0585 3.44656.0585 6.00172 0 2.5553-.0195 4.3182-.0585 6.0018h4.4836c-.078-1.1885-.0975-3.189-.0975-4.8925 0-2.69388 1.0917-3.46638 3.5674-3.46638 1.1502 0 1.9689.13865 2.6902.39615.0195-1.01019.2144-2.97117.3314-3.84271-.7408-.21789-1.5595-.35655-2.5537-.35655-2.1249-.0198-3.6844.85174-4.4056 2.93156l-.156-.0198ZM94.8501 10.5235c0 2.1591-1.5595 3.1693-4.0157 3.1693-2.4368 0-3.9963-.9508-3.9963-3.1693 0-2.21846 1.579-3.05039 3.9963-3.05039 2.4367 0 4.0157.89135 4.0157 3.05039Zm4.0743-.099c0-4.29832-3.353-6.21968-8.09-6.21968-4.7566 0-7.9926 1.92136-7.9926 6.21968 0 4.2785 3.0216 6.5762 7.9731 6.5762 4.9904 0 8.1095-2.2977 8.1095-6.5762Z"/><defs><linearGradient id="paint0_linear_386_2739" x1="5.46011" x2="16.8017" y1="25.9999" y2="20.6412" gradientUnits="userSpaceOnUse"><stop stop-color="#D83333"/><stop offset="1" stop-color="#F041FF"/></linearGradient></defs></svg>';
|
|
5
5
|
let integrationData;
|
|
6
6
|
var astro_default = {
|
|
7
|
-
id: "astro",
|
|
7
|
+
id: "astro:home",
|
|
8
8
|
name: "Menu",
|
|
9
9
|
icon: "astro:logo",
|
|
10
10
|
async init(canvas, eventTarget) {
|
|
11
11
|
createCanvas();
|
|
12
12
|
document.addEventListener("astro:after-swap", createCanvas);
|
|
13
|
+
document.addEventListener("astro:after-swap", fetchIntegrationData);
|
|
13
14
|
eventTarget.addEventListener("app-toggled", async (event) => {
|
|
14
15
|
resetDebugButton();
|
|
15
16
|
if (!(event instanceof CustomEvent))
|
|
16
17
|
return;
|
|
17
18
|
if (event.detail.state === true) {
|
|
18
19
|
if (!integrationData)
|
|
19
|
-
|
|
20
|
-
cache: "no-cache"
|
|
21
|
-
}).then((res) => res.json()).then((data) => {
|
|
22
|
-
integrationData = data;
|
|
23
|
-
integrationData.data = integrationData.data.map((integration) => {
|
|
24
|
-
return integration;
|
|
25
|
-
});
|
|
26
|
-
refreshIntegrationList();
|
|
27
|
-
});
|
|
20
|
+
fetchIntegrationData();
|
|
28
21
|
}
|
|
29
22
|
});
|
|
23
|
+
function fetchIntegrationData() {
|
|
24
|
+
fetch("https://astro.build/api/v1/dev-overlay/", {
|
|
25
|
+
cache: "no-cache"
|
|
26
|
+
}).then((res) => res.json()).then((data) => {
|
|
27
|
+
integrationData = data;
|
|
28
|
+
integrationData.data = integrationData.data.map((integration) => {
|
|
29
|
+
return integration;
|
|
30
|
+
});
|
|
31
|
+
refreshIntegrationList();
|
|
32
|
+
});
|
|
33
|
+
}
|
|
30
34
|
function createCanvas() {
|
|
31
35
|
const links = [
|
|
32
36
|
{
|
|
@@ -307,8 +307,8 @@ const a11y = [
|
|
|
307
307
|
message: "Headings and anchors must have an accessible name, which can come from: inner text, aria-label, aria-labelledby, an img with alt property, or an svg with a tag <title></title>.",
|
|
308
308
|
selector: a11y_required_content.join(","),
|
|
309
309
|
match(element) {
|
|
310
|
-
const innerText = element.innerText
|
|
311
|
-
if (innerText !== "")
|
|
310
|
+
const innerText = element.innerText?.trim();
|
|
311
|
+
if (innerText && innerText !== "")
|
|
312
312
|
return false;
|
|
313
313
|
const ariaLabel = element.getAttribute("aria-label")?.trim();
|
|
314
314
|
if (ariaLabel && ariaLabel !== "")
|
|
@@ -11,7 +11,7 @@ export interface ResolvedAuditRule {
|
|
|
11
11
|
}
|
|
12
12
|
export interface AuditRuleWithSelector extends AuditRule {
|
|
13
13
|
selector: string;
|
|
14
|
-
match?: (element: Element) => boolean | null | undefined | void
|
|
14
|
+
match?: (element: Element) => boolean | null | undefined | void | Promise<boolean> | Promise<void> | Promise<null> | Promise<undefined>;
|
|
15
15
|
}
|
|
16
16
|
declare const _default: {
|
|
17
17
|
id: string;
|
|
@@ -6,8 +6,10 @@ import {
|
|
|
6
6
|
} from "../utils/highlight.js";
|
|
7
7
|
import { createWindowElement } from "../utils/window.js";
|
|
8
8
|
import { a11y } from "./a11y.js";
|
|
9
|
+
import { finder } from "@medv/finder";
|
|
10
|
+
import { perf } from "./perf.js";
|
|
9
11
|
const icon = '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 1 20 16"><path fill="#fff" d="M.6 2A1.1 1.1 0 0 1 1.7.9h16.6a1.1 1.1 0 1 1 0 2.2H1.6A1.1 1.1 0 0 1 .8 2Zm1.1 7.1h6a1.1 1.1 0 0 0 0-2.2h-6a1.1 1.1 0 0 0 0 2.2ZM9.3 13H1.8a1.1 1.1 0 1 0 0 2.2h7.5a1.1 1.1 0 1 0 0-2.2Zm11.3 1.9a1.1 1.1 0 0 1-1.5 0l-1.7-1.7a4.1 4.1 0 1 1 1.6-1.6l1.6 1.7a1.1 1.1 0 0 1 0 1.6Zm-5.3-3.4a1.9 1.9 0 1 0 0-3.8 1.9 1.9 0 0 0 0 3.8Z"/></svg>';
|
|
10
|
-
const rules = [...a11y];
|
|
12
|
+
const rules = [...a11y, ...perf];
|
|
11
13
|
const dynamicAuditRuleKeys = ["title", "message"];
|
|
12
14
|
function resolveAuditRule(rule, element) {
|
|
13
15
|
let resolved = { ...rule };
|
|
@@ -65,12 +67,14 @@ var audit_default = {
|
|
|
65
67
|
matches = Array.from(elements);
|
|
66
68
|
} else {
|
|
67
69
|
for (const element of elements) {
|
|
68
|
-
if (rule.match(element)) {
|
|
70
|
+
if (await rule.match(element)) {
|
|
69
71
|
matches.push(element);
|
|
70
72
|
}
|
|
71
73
|
}
|
|
72
74
|
}
|
|
73
75
|
for (const element of matches) {
|
|
76
|
+
if (audits.some((audit) => audit.auditedElement === element))
|
|
77
|
+
continue;
|
|
74
78
|
await createAuditProblem(rule, element);
|
|
75
79
|
}
|
|
76
80
|
}
|
|
@@ -82,6 +86,107 @@ var audit_default = {
|
|
|
82
86
|
}
|
|
83
87
|
})
|
|
84
88
|
);
|
|
89
|
+
const auditListWindow = createWindowElement(
|
|
90
|
+
`
|
|
91
|
+
<style>
|
|
92
|
+
astro-dev-toolbar-window {
|
|
93
|
+
left: initial;
|
|
94
|
+
top: 8px;
|
|
95
|
+
right: 8px;
|
|
96
|
+
transform: none;
|
|
97
|
+
width: 320px;
|
|
98
|
+
max-height: 320px;
|
|
99
|
+
padding: 0;
|
|
100
|
+
overflow: hidden;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
hr {
|
|
104
|
+
margin: 0;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
header {
|
|
108
|
+
display: flex;
|
|
109
|
+
justify-content: space-between;
|
|
110
|
+
align-items: center;
|
|
111
|
+
padding: 18px;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
h1 {
|
|
115
|
+
font-size: 22px;
|
|
116
|
+
font-weight: 600;
|
|
117
|
+
color: #fff;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
ul, li {
|
|
121
|
+
margin: 0;
|
|
122
|
+
padding: 0;
|
|
123
|
+
list-style: none;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
h1, h2 {
|
|
127
|
+
margin: 0;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
h3 {
|
|
131
|
+
margin: 0;
|
|
132
|
+
margin-bottom: 8px;
|
|
133
|
+
color: white;
|
|
134
|
+
white-space: nowrap;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.audit-title {
|
|
138
|
+
font-weight: bold;
|
|
139
|
+
color: white;
|
|
140
|
+
margin-right: 1ch;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
#audit-list {
|
|
144
|
+
display: flex;
|
|
145
|
+
flex-direction: column;
|
|
146
|
+
overflow: auto;
|
|
147
|
+
}
|
|
148
|
+
</style>
|
|
149
|
+
|
|
150
|
+
<header>
|
|
151
|
+
<h1>Audits</h1>
|
|
152
|
+
<astro-dev-toolbar-badge size="large">${audits.length} problem${audits.length > 1 ? "s" : ""} found</astro-dev-toolbar-badge>
|
|
153
|
+
</header>
|
|
154
|
+
<hr />`
|
|
155
|
+
);
|
|
156
|
+
const auditListUl = document.createElement("ul");
|
|
157
|
+
auditListUl.id = "audit-list";
|
|
158
|
+
audits.forEach((audit, index) => {
|
|
159
|
+
const resolvedRule = resolveAuditRule(audit.rule, audit.auditedElement);
|
|
160
|
+
const card = document.createElement("astro-dev-toolbar-card");
|
|
161
|
+
card.shadowRoot.innerHTML = `
|
|
162
|
+
<style>
|
|
163
|
+
:host>button {
|
|
164
|
+
text-align: left;
|
|
165
|
+
box-shadow: none !important;
|
|
166
|
+
${index + 1 < audits.length ? "border-radius: 0 !important;" : "border-radius: 0 0 8px 8px !important;"}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
:host>button:hover {
|
|
170
|
+
cursor: pointer;
|
|
171
|
+
}
|
|
172
|
+
</style>`;
|
|
173
|
+
card.clickAction = () => {
|
|
174
|
+
audit.highlightElement.scrollIntoView();
|
|
175
|
+
audit.highlightElement.focus();
|
|
176
|
+
};
|
|
177
|
+
const h3 = document.createElement("h3");
|
|
178
|
+
h3.innerText = finder(audit.auditedElement);
|
|
179
|
+
card.appendChild(h3);
|
|
180
|
+
const div = document.createElement("div");
|
|
181
|
+
const title = document.createElement("span");
|
|
182
|
+
title.classList.add("audit-title");
|
|
183
|
+
title.innerHTML = resolvedRule.title;
|
|
184
|
+
div.appendChild(title);
|
|
185
|
+
card.appendChild(div);
|
|
186
|
+
auditListUl.appendChild(card);
|
|
187
|
+
});
|
|
188
|
+
auditListWindow.appendChild(auditListUl);
|
|
189
|
+
canvas.append(auditListWindow);
|
|
85
190
|
} else {
|
|
86
191
|
eventTarget.dispatchEvent(
|
|
87
192
|
new CustomEvent("toggle-notification", {
|
|
@@ -116,10 +221,10 @@ var audit_default = {
|
|
|
116
221
|
}
|
|
117
222
|
</style>
|
|
118
223
|
<header>
|
|
119
|
-
<h1><astro-dev-toolbar-icon icon="check-circle"></astro-dev-toolbar-icon>No accessibility issues detected.</h1>
|
|
224
|
+
<h1><astro-dev-toolbar-icon icon="check-circle"></astro-dev-toolbar-icon>No accessibility or performance issues detected.</h1>
|
|
120
225
|
</header>
|
|
121
226
|
<p>
|
|
122
|
-
Nice work! This app scans the page and highlights common accessibility issues for you, like a missing "alt" attribute on an image.
|
|
227
|
+
Nice work! This app scans the page and highlights common accessibility and performance issues for you, like a missing "alt" attribute on an image, or a image not using performant attributes.
|
|
123
228
|
</p>
|
|
124
229
|
`
|
|
125
230
|
);
|
|
@@ -150,7 +255,7 @@ var audit_default = {
|
|
|
150
255
|
return;
|
|
151
256
|
}
|
|
152
257
|
const rect = originalElement.getBoundingClientRect();
|
|
153
|
-
const highlight = createHighlight(rect, "warning");
|
|
258
|
+
const highlight = createHighlight(rect, "warning", { "data-audit-code": rule.code });
|
|
154
259
|
const tooltip = buildAuditTooltip(rule, originalElement);
|
|
155
260
|
const { isFixed } = getElementsPositionInDocument(originalElement);
|
|
156
261
|
if (isFixed) {
|
|
@@ -158,7 +263,11 @@ var audit_default = {
|
|
|
158
263
|
}
|
|
159
264
|
attachTooltipToHighlight(highlight, tooltip, originalElement);
|
|
160
265
|
canvas.append(highlight);
|
|
161
|
-
audits.push({
|
|
266
|
+
audits.push({
|
|
267
|
+
highlightElement: highlight,
|
|
268
|
+
auditedElement: originalElement,
|
|
269
|
+
rule
|
|
270
|
+
});
|
|
162
271
|
}
|
|
163
272
|
function buildAuditTooltip(rule, element) {
|
|
164
273
|
const tooltip = document.createElement("astro-dev-toolbar-tooltip");
|