astro 3.4.3 → 3.5.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.d.ts +86 -0
- package/components/Code.astro +37 -4
- package/components/Image.astro +2 -2
- package/components/Picture.astro +19 -5
- package/components/ViewTransitions.astro +39 -38
- package/content-module.template.mjs +4 -14
- package/dist/@types/astro.d.ts +223 -5
- package/dist/assets/build/generate.d.ts +2 -1
- package/dist/assets/build/generate.js +16 -5
- package/dist/assets/consts.d.ts +1 -0
- package/dist/assets/consts.js +2 -0
- package/dist/assets/endpoint/generic.js +6 -2
- package/dist/assets/internal.js +11 -2
- package/dist/assets/services/service.d.ts +10 -10
- package/dist/assets/services/service.js +2 -1
- package/dist/assets/services/vendor/squoosh/image-pool.d.ts +1 -2
- package/dist/assets/types.d.ts +19 -9
- package/dist/assets/utils/emitAsset.js +5 -0
- package/dist/assets/utils/metadata.d.ts +1 -2
- package/dist/assets/utils/proxy.d.ts +1 -0
- package/dist/assets/utils/proxy.js +16 -0
- package/dist/assets/utils/queryParams.d.ts +1 -1
- package/dist/assets/utils/transformToPath.d.ts +1 -1
- package/dist/assets/utils/transformToPath.js +8 -3
- package/dist/assets/vite-plugin-assets.js +26 -11
- package/dist/cli/build/index.js +1 -1
- package/dist/content/consts.d.ts +1 -0
- package/dist/content/consts.js +2 -0
- package/dist/content/runtime-assets.d.ts +9 -1
- package/dist/content/runtime-assets.js +1 -1
- package/dist/content/runtime.d.ts +1 -0
- package/dist/content/runtime.js +8 -2
- package/dist/content/utils.d.ts +1 -0
- package/dist/content/utils.js +9 -0
- package/dist/content/vite-plugin-content-assets.js +49 -23
- package/dist/content/vite-plugin-content-imports.js +9 -3
- package/dist/content/vite-plugin-content-virtual-mod.d.ts +17 -12
- package/dist/content/vite-plugin-content-virtual-mod.js +136 -57
- package/dist/core/app/index.js +19 -4
- package/dist/core/app/types.d.ts +7 -1
- package/dist/core/build/buildPipeline.js +17 -4
- package/dist/core/build/common.js +2 -0
- package/dist/core/build/generate.js +64 -34
- package/dist/core/build/index.d.ts +0 -8
- package/dist/core/build/index.js +9 -2
- package/dist/core/build/internal.d.ts +11 -1
- package/dist/core/build/internal.js +23 -1
- package/dist/core/build/page-data.js +46 -18
- package/dist/core/build/plugin.d.ts +12 -10
- package/dist/core/build/plugin.js +14 -22
- package/dist/core/build/plugins/index.js +4 -0
- package/dist/core/build/plugins/plugin-alias-resolve.js +1 -1
- package/dist/core/build/plugins/plugin-analyzer.js +1 -1
- package/dist/core/build/plugins/plugin-chunks.d.ts +4 -0
- package/dist/core/build/plugins/plugin-chunks.js +31 -0
- package/dist/core/build/plugins/plugin-component-entry.js +1 -1
- package/dist/core/build/plugins/plugin-content.d.ts +4 -0
- package/dist/core/build/plugins/plugin-content.js +273 -0
- package/dist/core/build/plugins/plugin-css.js +9 -4
- package/dist/core/build/plugins/plugin-hoisted-scripts.js +1 -1
- package/dist/core/build/plugins/plugin-internals.js +1 -1
- package/dist/core/build/plugins/plugin-manifest.js +14 -5
- package/dist/core/build/plugins/plugin-middleware.d.ts +1 -3
- package/dist/core/build/plugins/plugin-middleware.js +5 -57
- package/dist/core/build/plugins/plugin-pages.js +3 -3
- package/dist/core/build/plugins/plugin-prerender.js +2 -5
- package/dist/core/build/plugins/plugin-renderers.js +1 -1
- package/dist/core/build/plugins/plugin-ssr.js +6 -5
- package/dist/core/build/plugins/util.d.ts +3 -3
- package/dist/core/build/static-build.d.ts +2 -1
- package/dist/core/build/static-build.js +52 -28
- package/dist/core/build/types.d.ts +1 -1
- package/dist/core/build/util.d.ts +7 -0
- package/dist/core/build/util.js +37 -1
- package/dist/core/compile/compile.js +1 -0
- package/dist/core/config/config.js +3 -0
- package/dist/core/config/schema.d.ts +208 -0
- package/dist/core/config/schema.js +72 -4
- package/dist/core/config/settings.js +1 -0
- package/dist/core/constants.js +1 -1
- package/dist/core/create-vite.js +9 -3
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/endpoint/index.d.ts +4 -3
- package/dist/core/endpoint/index.js +29 -3
- package/dist/core/errors/errors-data.d.ts +11 -0
- package/dist/core/errors/errors-data.js +17 -0
- package/dist/core/messages.js +2 -2
- package/dist/core/middleware/index.d.ts +7 -3
- package/dist/core/middleware/index.js +3 -2
- package/dist/core/middleware/loadMiddleware.d.ts +1 -2
- package/dist/core/middleware/loadMiddleware.js +3 -4
- package/dist/core/middleware/sequence.d.ts +2 -2
- package/dist/core/middleware/sequence.js +3 -2
- package/dist/core/middleware/vite-plugin.d.ts +9 -0
- package/dist/core/middleware/vite-plugin.js +101 -0
- package/dist/core/pipeline.d.ts +1 -1
- package/dist/core/pipeline.js +6 -4
- package/dist/core/preview/static-preview-server.js +3 -1
- package/dist/core/preview/vite-plugin-astro-preview.js +13 -2
- package/dist/core/redirects/helpers.d.ts +1 -0
- package/dist/core/redirects/helpers.js +4 -0
- package/dist/core/render/context.d.ts +24 -1
- package/dist/core/render/context.js +96 -2
- package/dist/core/render/core.d.ts +2 -14
- package/dist/core/render/core.js +12 -52
- package/dist/core/render/index.d.ts +2 -3
- package/dist/core/render/index.js +3 -4
- package/dist/core/render/params-and-props.d.ts +1 -1
- package/dist/core/render/params-and-props.js +5 -2
- package/dist/core/render/result.d.ts +1 -0
- package/dist/core/render/result.js +23 -0
- package/dist/core/render/route-cache.d.ts +1 -1
- package/dist/core/render/route-cache.js +17 -11
- package/dist/core/routing/manifest/create.js +118 -4
- package/dist/core/sync/index.d.ts +2 -24
- package/dist/i18n/index.d.ts +54 -0
- package/dist/i18n/index.js +91 -0
- package/dist/i18n/middleware.d.ts +2 -0
- package/dist/i18n/middleware.js +62 -0
- package/dist/i18n/vite-plugin-i18n.d.ts +7 -0
- package/dist/i18n/vite-plugin-i18n.js +62 -0
- package/dist/integrations/astroFeaturesValidation.js +4 -1
- package/dist/integrations/index.js +12 -0
- package/dist/prefetch/index.d.ts +31 -0
- package/dist/prefetch/index.js +176 -0
- package/dist/prefetch/vite-plugin-prefetch.d.ts +5 -0
- package/dist/prefetch/vite-plugin-prefetch.js +43 -0
- package/dist/runtime/client/dev-overlay/entrypoint.js +2 -2
- package/dist/runtime/client/dev-overlay/overlay.d.ts +10 -2
- package/dist/runtime/client/dev-overlay/overlay.js +47 -28
- package/dist/runtime/client/dev-overlay/plugins/astro.d.ts +1 -0
- package/dist/runtime/client/dev-overlay/plugins/astro.js +44 -9
- package/dist/runtime/client/dev-overlay/plugins/audit.d.ts +2 -1
- package/dist/runtime/client/dev-overlay/plugins/audit.js +101 -24
- package/dist/runtime/client/dev-overlay/plugins/xray.d.ts +1 -0
- package/dist/runtime/client/dev-overlay/plugins/xray.js +22 -0
- package/dist/runtime/client/dev-overlay/ui-library/card.js +2 -0
- package/dist/runtime/client/dev-overlay/ui-library/icons.d.ts +3 -0
- package/dist/runtime/client/dev-overlay/ui-library/icons.js +4 -1
- package/dist/runtime/client/dev-overlay/ui-library/tooltip.js +1 -0
- package/dist/runtime/client/dev-overlay/ui-library/window.js +1 -0
- package/dist/runtime/server/index.d.ts +0 -2
- package/dist/runtime/server/render/component.js +3 -5
- package/dist/transitions/router.d.ts +1 -0
- package/dist/transitions/router.js +10 -5
- package/dist/transitions/vite-plugin-transitions.d.ts +4 -1
- package/dist/transitions/vite-plugin-transitions.js +7 -1
- package/dist/vite-plugin-astro-server/devPipeline.d.ts +1 -0
- package/dist/vite-plugin-astro-server/devPipeline.js +2 -0
- package/dist/vite-plugin-astro-server/plugin.js +11 -1
- package/dist/vite-plugin-astro-server/route.js +113 -51
- package/dist/vite-plugin-head/index.js +1 -1
- package/dist/vite-plugin-markdown/index.js +1 -0
- package/dist/vite-plugin-scripts/index.js +2 -1
- package/package.json +7 -5
- package/tsconfigs/base.json +1 -1
- package/dist/core/endpoint/dev/index.d.ts +0 -2
- package/dist/core/endpoint/dev/index.js +0 -17
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import * as vite from "vite";
|
|
2
|
+
const virtualModuleId = "astro:i18n";
|
|
3
|
+
const resolvedVirtualModuleId = "\0" + virtualModuleId;
|
|
4
|
+
function astroInternationalization({
|
|
5
|
+
settings
|
|
6
|
+
}) {
|
|
7
|
+
return {
|
|
8
|
+
name: "astro:i18n",
|
|
9
|
+
enforce: "pre",
|
|
10
|
+
async resolveId(id) {
|
|
11
|
+
if (id === virtualModuleId) {
|
|
12
|
+
return resolvedVirtualModuleId;
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
load(id) {
|
|
16
|
+
if (id === resolvedVirtualModuleId) {
|
|
17
|
+
return `
|
|
18
|
+
import {
|
|
19
|
+
getLocaleRelativeUrl as _getLocaleRelativeUrl,
|
|
20
|
+
getLocaleRelativeUrlList as _getLocaleRelativeUrlList,
|
|
21
|
+
getLocaleAbsoluteUrl as _getLocaleAbsoluteUrl,
|
|
22
|
+
getLocaleAbsoluteUrlList as _getLocaleAbsoluteUrlList,
|
|
23
|
+
|
|
24
|
+
} from "astro/i18n";
|
|
25
|
+
|
|
26
|
+
const base = ${JSON.stringify(settings.config.base)};
|
|
27
|
+
const trailingSlash = ${JSON.stringify(settings.config.trailingSlash)};
|
|
28
|
+
const format = ${JSON.stringify(settings.config.build.format)};
|
|
29
|
+
const site = ${JSON.stringify(settings.config.site)};
|
|
30
|
+
const i18n = ${JSON.stringify(settings.config.experimental.i18n)};
|
|
31
|
+
|
|
32
|
+
export const getRelativeLocaleUrl = (locale, path = "", opts) => _getLocaleRelativeUrl({
|
|
33
|
+
locale,
|
|
34
|
+
path,
|
|
35
|
+
base,
|
|
36
|
+
trailingSlash,
|
|
37
|
+
format,
|
|
38
|
+
...i18n,
|
|
39
|
+
...opts
|
|
40
|
+
});
|
|
41
|
+
export const getAbsoluteLocaleUrl = (locale, path = "", opts) => _getLocaleAbsoluteUrl({
|
|
42
|
+
locale,
|
|
43
|
+
path,
|
|
44
|
+
base,
|
|
45
|
+
trailingSlash,
|
|
46
|
+
format,
|
|
47
|
+
site,
|
|
48
|
+
...i18n,
|
|
49
|
+
...opts
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
export const getRelativeLocaleUrlList = (path = "", opts) => _getLocaleRelativeUrlList({
|
|
53
|
+
base, path, trailingSlash, format, ...i18n, ...opts });
|
|
54
|
+
export const getAbsoluteLocaleUrlList = (path = "", opts) => _getLocaleAbsoluteUrlList({ base, path, trailingSlash, format, site, ...i18n, ...opts });
|
|
55
|
+
`;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export {
|
|
61
|
+
astroInternationalization as default
|
|
62
|
+
};
|
|
@@ -11,7 +11,10 @@ const ALL_UNSUPPORTED = {
|
|
|
11
11
|
serverOutput: UNSUPPORTED,
|
|
12
12
|
staticOutput: UNSUPPORTED,
|
|
13
13
|
hybridOutput: UNSUPPORTED,
|
|
14
|
-
assets: UNSUPPORTED_ASSETS_FEATURE
|
|
14
|
+
assets: UNSUPPORTED_ASSETS_FEATURE,
|
|
15
|
+
i18n: {
|
|
16
|
+
detectBrowserLanguage: UNSUPPORTED
|
|
17
|
+
}
|
|
15
18
|
};
|
|
16
19
|
function validateSupportedFeatures(adapterName, featureMap = ALL_UNSUPPORTED, config, logger) {
|
|
17
20
|
const {
|
|
@@ -94,6 +94,18 @@ async function runHookConfigSetup({
|
|
|
94
94
|
}
|
|
95
95
|
addedClientDirectives.set(name, buildClientDirectiveEntrypoint(name, entrypoint));
|
|
96
96
|
},
|
|
97
|
+
addMiddleware: ({ order, entrypoint }) => {
|
|
98
|
+
if (typeof updatedSettings.middlewares[order] === "undefined") {
|
|
99
|
+
throw new Error(
|
|
100
|
+
`The "${integration.name}" integration is trying to add middleware but did not specify an order.`
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
logger.debug(
|
|
104
|
+
"middleware",
|
|
105
|
+
`The integration ${integration.name} has added middleware that runs ${order === "pre" ? "before" : "after"} any application middleware you define.`
|
|
106
|
+
);
|
|
107
|
+
updatedSettings.middlewares[order].push(entrypoint);
|
|
108
|
+
},
|
|
97
109
|
logger: integrationLogger
|
|
98
110
|
};
|
|
99
111
|
Object.defineProperty(hooks, "addPageExtension", {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
interface InitOptions {
|
|
2
|
+
defaultStrategy?: string;
|
|
3
|
+
prefetchAll?: boolean;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Initialize the prefetch script, only works once.
|
|
7
|
+
*
|
|
8
|
+
* @param defaultOpts Default options for prefetching if not already set by the user config.
|
|
9
|
+
*/
|
|
10
|
+
export declare function init(defaultOpts?: InitOptions): void;
|
|
11
|
+
export interface PrefetchOptions {
|
|
12
|
+
/**
|
|
13
|
+
* How the prefetch should prioritize the URL. (default `'link'`)
|
|
14
|
+
* - `'link'`: use `<link rel="prefetch">`, has lower loading priority.
|
|
15
|
+
* - `'fetch'`: use `fetch()`, has higher loading priority.
|
|
16
|
+
*/
|
|
17
|
+
with?: 'link' | 'fetch';
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Prefetch a URL so it's cached when the user navigates to it.
|
|
21
|
+
*
|
|
22
|
+
* @param url A full or partial URL string based on the current `location.href`. They are only fetched if:
|
|
23
|
+
* - The user is online
|
|
24
|
+
* - The user is not in data saver mode
|
|
25
|
+
* - The URL is within the same origin
|
|
26
|
+
* - The URL is not the current page
|
|
27
|
+
* - The URL has not already been prefetched
|
|
28
|
+
* @param opts Additional options for prefetching.
|
|
29
|
+
*/
|
|
30
|
+
export declare function prefetch(url: string, opts?: PrefetchOptions): void;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
const debug = import.meta.env.DEV ? console.debug : void 0;
|
|
2
|
+
const inBrowser = import.meta.env.SSR === false;
|
|
3
|
+
const prefetchedUrls = /* @__PURE__ */ new Set();
|
|
4
|
+
const listenedAnchors = /* @__PURE__ */ new WeakSet();
|
|
5
|
+
let prefetchAll = __PREFETCH_PREFETCH_ALL__;
|
|
6
|
+
let defaultStrategy = __PREFETCH_DEFAULT_STRATEGY__;
|
|
7
|
+
let inited = false;
|
|
8
|
+
function init(defaultOpts) {
|
|
9
|
+
if (!inBrowser)
|
|
10
|
+
return;
|
|
11
|
+
if (inited)
|
|
12
|
+
return;
|
|
13
|
+
inited = true;
|
|
14
|
+
debug?.(`[astro] Initializing prefetch script`);
|
|
15
|
+
prefetchAll ??= defaultOpts?.prefetchAll ?? false;
|
|
16
|
+
defaultStrategy ??= defaultOpts?.defaultStrategy ?? "hover";
|
|
17
|
+
initTapStrategy();
|
|
18
|
+
initHoverStrategy();
|
|
19
|
+
initViewportStrategy();
|
|
20
|
+
}
|
|
21
|
+
function initTapStrategy() {
|
|
22
|
+
for (const event of ["touchstart", "mousedown"]) {
|
|
23
|
+
document.body.addEventListener(
|
|
24
|
+
event,
|
|
25
|
+
(e) => {
|
|
26
|
+
if (elMatchesStrategy(e.target, "tap")) {
|
|
27
|
+
prefetch(e.target.href, { with: "fetch" });
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
{ passive: true }
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function initHoverStrategy() {
|
|
35
|
+
let timeout;
|
|
36
|
+
document.body.addEventListener(
|
|
37
|
+
"focusin",
|
|
38
|
+
(e) => {
|
|
39
|
+
if (elMatchesStrategy(e.target, "hover")) {
|
|
40
|
+
handleHoverIn(e);
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
{ passive: true }
|
|
44
|
+
);
|
|
45
|
+
document.body.addEventListener("focusout", handleHoverOut, { passive: true });
|
|
46
|
+
onPageLoad(() => {
|
|
47
|
+
for (const anchor of document.getElementsByTagName("a")) {
|
|
48
|
+
if (listenedAnchors.has(anchor))
|
|
49
|
+
continue;
|
|
50
|
+
if (elMatchesStrategy(anchor, "hover")) {
|
|
51
|
+
listenedAnchors.add(anchor);
|
|
52
|
+
anchor.addEventListener("mouseenter", handleHoverIn, { passive: true });
|
|
53
|
+
anchor.addEventListener("mouseleave", handleHoverOut, { passive: true });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
function handleHoverIn(e) {
|
|
58
|
+
const href = e.target.href;
|
|
59
|
+
if (timeout) {
|
|
60
|
+
clearTimeout(timeout);
|
|
61
|
+
}
|
|
62
|
+
timeout = setTimeout(() => {
|
|
63
|
+
prefetch(href, { with: "fetch" });
|
|
64
|
+
}, 80);
|
|
65
|
+
}
|
|
66
|
+
function handleHoverOut() {
|
|
67
|
+
if (timeout) {
|
|
68
|
+
clearTimeout(timeout);
|
|
69
|
+
timeout = 0;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function initViewportStrategy() {
|
|
74
|
+
let observer;
|
|
75
|
+
onPageLoad(() => {
|
|
76
|
+
for (const anchor of document.getElementsByTagName("a")) {
|
|
77
|
+
if (listenedAnchors.has(anchor))
|
|
78
|
+
continue;
|
|
79
|
+
if (elMatchesStrategy(anchor, "viewport")) {
|
|
80
|
+
listenedAnchors.add(anchor);
|
|
81
|
+
observer ??= createViewportIntersectionObserver();
|
|
82
|
+
observer.observe(anchor);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
function createViewportIntersectionObserver() {
|
|
88
|
+
const timeouts = /* @__PURE__ */ new WeakMap();
|
|
89
|
+
return new IntersectionObserver((entries, observer) => {
|
|
90
|
+
for (const entry of entries) {
|
|
91
|
+
const anchor = entry.target;
|
|
92
|
+
const timeout = timeouts.get(anchor);
|
|
93
|
+
if (entry.isIntersecting) {
|
|
94
|
+
if (timeout) {
|
|
95
|
+
clearTimeout(timeout);
|
|
96
|
+
}
|
|
97
|
+
timeouts.set(
|
|
98
|
+
anchor,
|
|
99
|
+
setTimeout(() => {
|
|
100
|
+
observer.unobserve(anchor);
|
|
101
|
+
timeouts.delete(anchor);
|
|
102
|
+
prefetch(anchor.href, { with: "link" });
|
|
103
|
+
}, 300)
|
|
104
|
+
);
|
|
105
|
+
} else {
|
|
106
|
+
if (timeout) {
|
|
107
|
+
clearTimeout(timeout);
|
|
108
|
+
timeouts.delete(anchor);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
function prefetch(url, opts) {
|
|
115
|
+
if (!canPrefetchUrl(url))
|
|
116
|
+
return;
|
|
117
|
+
prefetchedUrls.add(url);
|
|
118
|
+
const priority = opts?.with ?? "link";
|
|
119
|
+
debug?.(`[astro] Prefetching ${url} with ${priority}`);
|
|
120
|
+
if (priority === "link") {
|
|
121
|
+
const link = document.createElement("link");
|
|
122
|
+
link.rel = "prefetch";
|
|
123
|
+
link.setAttribute("href", url);
|
|
124
|
+
document.head.append(link);
|
|
125
|
+
} else {
|
|
126
|
+
fetch(url).catch((e) => {
|
|
127
|
+
console.log(`[astro] Failed to prefetch ${url}`);
|
|
128
|
+
console.error(e);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function canPrefetchUrl(url) {
|
|
133
|
+
if (!navigator.onLine)
|
|
134
|
+
return false;
|
|
135
|
+
if ("connection" in navigator) {
|
|
136
|
+
const conn = navigator.connection;
|
|
137
|
+
if (conn.saveData || /(2|3)g/.test(conn.effectiveType))
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
try {
|
|
141
|
+
const urlObj = new URL(url, location.href);
|
|
142
|
+
return location.origin === urlObj.origin && location.pathname !== urlObj.pathname && !prefetchedUrls.has(url);
|
|
143
|
+
} catch {
|
|
144
|
+
}
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
function elMatchesStrategy(el, strategy) {
|
|
148
|
+
if (el?.tagName !== "A")
|
|
149
|
+
return false;
|
|
150
|
+
const attrValue = el.dataset.astroPrefetch;
|
|
151
|
+
if (attrValue === "false") {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
if (attrValue == null && prefetchAll || attrValue === "") {
|
|
155
|
+
return strategy === defaultStrategy;
|
|
156
|
+
}
|
|
157
|
+
if (attrValue === strategy) {
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
function onPageLoad(cb) {
|
|
163
|
+
cb();
|
|
164
|
+
let firstLoad = false;
|
|
165
|
+
document.addEventListener("astro:page-load", () => {
|
|
166
|
+
if (!firstLoad) {
|
|
167
|
+
firstLoad = true;
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
cb();
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
export {
|
|
174
|
+
init,
|
|
175
|
+
prefetch
|
|
176
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as vite from "vite";
|
|
2
|
+
const virtualModuleId = "astro:prefetch";
|
|
3
|
+
const resolvedVirtualModuleId = "\0" + virtualModuleId;
|
|
4
|
+
const prefetchInternalModuleFsSubpath = "astro/dist/prefetch/index.js";
|
|
5
|
+
const prefetchCode = `import { init } from 'astro/prefetch';init()`;
|
|
6
|
+
function astroPrefetch({ settings }) {
|
|
7
|
+
const prefetchOption = settings.config.prefetch;
|
|
8
|
+
const prefetch = prefetchOption ? typeof prefetchOption === "object" ? prefetchOption : {} : void 0;
|
|
9
|
+
if (prefetch && settings.scripts.every((s) => s.content !== prefetchCode)) {
|
|
10
|
+
settings.scripts.push({
|
|
11
|
+
stage: "page",
|
|
12
|
+
content: `import { init } from 'astro/prefetch';init()`
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
const throwPrefetchNotEnabledError = () => {
|
|
16
|
+
throw new Error("You need to enable the `prefetch` Astro config to import `astro:prefetch`");
|
|
17
|
+
};
|
|
18
|
+
return {
|
|
19
|
+
name: "astro:prefetch",
|
|
20
|
+
async resolveId(id) {
|
|
21
|
+
if (id === virtualModuleId) {
|
|
22
|
+
if (!prefetch)
|
|
23
|
+
throwPrefetchNotEnabledError();
|
|
24
|
+
return resolvedVirtualModuleId;
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
load(id) {
|
|
28
|
+
if (id === resolvedVirtualModuleId) {
|
|
29
|
+
if (!prefetch)
|
|
30
|
+
throwPrefetchNotEnabledError();
|
|
31
|
+
return `export { prefetch } from "astro/prefetch";`;
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
transform(code, id) {
|
|
35
|
+
if (id.includes(prefetchInternalModuleFsSubpath)) {
|
|
36
|
+
return code.replace("__PREFETCH_PREFETCH_ALL__", JSON.stringify(prefetch?.prefetchAll)).replace("__PREFETCH_DEFAULT_STRATEGY__", JSON.stringify(prefetch?.defaultStrategy));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export {
|
|
42
|
+
astroPrefetch as default
|
|
43
|
+
};
|
|
@@ -49,12 +49,12 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|
|
49
49
|
}
|
|
50
50
|
target.querySelector(".notification")?.toggleAttribute("data-active", newState);
|
|
51
51
|
});
|
|
52
|
-
eventTarget.addEventListener("toggle-plugin", (evt) => {
|
|
52
|
+
eventTarget.addEventListener("toggle-plugin", async (evt) => {
|
|
53
53
|
let newState = void 0;
|
|
54
54
|
if (evt instanceof CustomEvent) {
|
|
55
55
|
newState = evt.detail.state ?? true;
|
|
56
56
|
}
|
|
57
|
-
overlay.togglePluginStatus(plugin, newState);
|
|
57
|
+
await overlay.togglePluginStatus(plugin, newState);
|
|
58
58
|
});
|
|
59
59
|
return plugin;
|
|
60
60
|
};
|
|
@@ -22,12 +22,20 @@ export declare class AstroDevOverlay extends HTMLElement {
|
|
|
22
22
|
getPluginTemplate(plugin: DevOverlayPlugin): string;
|
|
23
23
|
getPluginIcon(icon: Icon): string | undefined;
|
|
24
24
|
getPluginById(id: string): DevOverlayPlugin | undefined;
|
|
25
|
-
getPluginCanvasById(id: string):
|
|
26
|
-
|
|
25
|
+
getPluginCanvasById(id: string): HTMLElement | null;
|
|
26
|
+
/**
|
|
27
|
+
* @param plugin The plugin to toggle the status of
|
|
28
|
+
* @param newStatus Optionally, force the plugin into a specific state
|
|
29
|
+
*/
|
|
30
|
+
togglePluginStatus(plugin: DevOverlayPlugin, newStatus?: boolean): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* @param newStatus Optionally, force the minimize button into a specific state
|
|
33
|
+
*/
|
|
27
34
|
toggleMinimizeButton(newStatus?: boolean): void;
|
|
28
35
|
toggleOverlay(newStatus?: boolean): void;
|
|
29
36
|
}
|
|
30
37
|
export declare class DevOverlayCanvas extends HTMLElement {
|
|
31
38
|
shadowRoot: ShadowRoot;
|
|
32
39
|
constructor();
|
|
40
|
+
connectedCallback(): void;
|
|
33
41
|
}
|
|
@@ -38,7 +38,7 @@ class AstroDevOverlay extends HTMLElement {
|
|
|
38
38
|
display: flex;
|
|
39
39
|
gap: 8px;
|
|
40
40
|
align-items: center;
|
|
41
|
-
transition: bottom 0.
|
|
41
|
+
transition: bottom 0.35s cubic-bezier(0.485, -0.050, 0.285, 1.505);
|
|
42
42
|
pointer-events: none;
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -59,11 +59,10 @@ class AstroDevOverlay extends HTMLElement {
|
|
|
59
59
|
height: 56px;
|
|
60
60
|
overflow: hidden;
|
|
61
61
|
pointer-events: auto;
|
|
62
|
-
|
|
63
62
|
background: linear-gradient(180deg, #13151A 0%, rgba(19, 21, 26, 0.88) 100%);
|
|
64
|
-
box-shadow: 0px 0px 0px 0px #13151A4D;
|
|
65
63
|
border: 1px solid #343841;
|
|
66
64
|
border-radius: 9999px;
|
|
65
|
+
box-shadow: 0px 0px 0px 0px rgba(19, 21, 26, 0.30), 0px 1px 2px 0px rgba(19, 21, 26, 0.29), 0px 4px 4px 0px rgba(19, 21, 26, 0.26), 0px 10px 6px 0px rgba(19, 21, 26, 0.15), 0px 17px 7px 0px rgba(19, 21, 26, 0.04), 0px 26px 7px 0px rgba(19, 21, 26, 0.01);
|
|
67
66
|
}
|
|
68
67
|
|
|
69
68
|
#dev-bar .item {
|
|
@@ -174,16 +173,6 @@ class AstroDevOverlay extends HTMLElement {
|
|
|
174
173
|
width: 1px;
|
|
175
174
|
}
|
|
176
175
|
|
|
177
|
-
astro-dev-overlay-plugin-canvas {
|
|
178
|
-
position: absolute;
|
|
179
|
-
top: 0;
|
|
180
|
-
left: 0;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
astro-dev-overlay-plugin-canvas:not([data-active]) {
|
|
184
|
-
display: none;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
176
|
#minimize-button {
|
|
188
177
|
width: 32px;
|
|
189
178
|
height: 32px;
|
|
@@ -242,14 +231,14 @@ class AstroDevOverlay extends HTMLElement {
|
|
|
242
231
|
this.devOverlay = this.shadowRoot.querySelector("#dev-overlay");
|
|
243
232
|
this.attachEvents();
|
|
244
233
|
}
|
|
245
|
-
this.plugins.forEach((plugin) => {
|
|
234
|
+
this.plugins.forEach(async (plugin) => {
|
|
246
235
|
if (!this.hasBeenInitialized) {
|
|
247
236
|
console.log(`Creating plugin canvas for ${plugin.id}`);
|
|
248
237
|
const pluginCanvas = document.createElement("astro-dev-overlay-plugin-canvas");
|
|
249
238
|
pluginCanvas.dataset.pluginId = plugin.id;
|
|
250
239
|
this.shadowRoot?.append(pluginCanvas);
|
|
251
240
|
}
|
|
252
|
-
this.togglePluginStatus(plugin, plugin.active);
|
|
241
|
+
await this.togglePluginStatus(plugin, plugin.active);
|
|
253
242
|
});
|
|
254
243
|
if ("requestIdleCallback" in window) {
|
|
255
244
|
window.requestIdleCallback(async () => {
|
|
@@ -278,7 +267,7 @@ class AstroDevOverlay extends HTMLElement {
|
|
|
278
267
|
if (plugin.status === "loading") {
|
|
279
268
|
await this.initPlugin(plugin);
|
|
280
269
|
}
|
|
281
|
-
this.togglePluginStatus(plugin);
|
|
270
|
+
await this.togglePluginStatus(plugin);
|
|
282
271
|
});
|
|
283
272
|
});
|
|
284
273
|
const minimizeButton = this.shadowRoot.querySelector("#minimize-button");
|
|
@@ -367,27 +356,47 @@ class AstroDevOverlay extends HTMLElement {
|
|
|
367
356
|
return this.plugins.find((plugin) => plugin.id === id);
|
|
368
357
|
}
|
|
369
358
|
getPluginCanvasById(id) {
|
|
370
|
-
return this.shadowRoot.querySelector(
|
|
359
|
+
return this.shadowRoot.querySelector(
|
|
360
|
+
`astro-dev-overlay-plugin-canvas[data-plugin-id="${id}"]`
|
|
361
|
+
);
|
|
371
362
|
}
|
|
372
|
-
|
|
373
|
-
|
|
363
|
+
/**
|
|
364
|
+
* @param plugin The plugin to toggle the status of
|
|
365
|
+
* @param newStatus Optionally, force the plugin into a specific state
|
|
366
|
+
*/
|
|
367
|
+
async togglePluginStatus(plugin, newStatus) {
|
|
368
|
+
const pluginCanvas = this.getPluginCanvasById(plugin.id);
|
|
369
|
+
if (!pluginCanvas)
|
|
370
|
+
return;
|
|
371
|
+
if (plugin.active && !newStatus && plugin.beforeTogglingOff) {
|
|
372
|
+
const shouldToggleOff = await plugin.beforeTogglingOff(pluginCanvas.shadowRoot);
|
|
373
|
+
if (!shouldToggleOff)
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
plugin.active = newStatus ?? !plugin.active;
|
|
374
377
|
const target = this.shadowRoot.querySelector(`[data-plugin-id="${plugin.id}"]`);
|
|
375
378
|
if (!target)
|
|
376
379
|
return;
|
|
377
380
|
target.classList.toggle("active", plugin.active);
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
381
|
+
pluginCanvas.style.display = plugin.active ? "block" : "none";
|
|
382
|
+
window.requestAnimationFrame(() => {
|
|
383
|
+
pluginCanvas.toggleAttribute("data-active", plugin.active);
|
|
384
|
+
plugin.eventTarget.dispatchEvent(
|
|
385
|
+
new CustomEvent("plugin-toggled", {
|
|
386
|
+
detail: {
|
|
387
|
+
state: plugin.active,
|
|
388
|
+
plugin
|
|
389
|
+
}
|
|
390
|
+
})
|
|
391
|
+
);
|
|
392
|
+
});
|
|
387
393
|
if (import.meta.hot) {
|
|
388
394
|
import.meta.hot.send(`${WS_EVENT_NAME}:${plugin.id}:toggled`, { state: plugin.active });
|
|
389
395
|
}
|
|
390
396
|
}
|
|
397
|
+
/**
|
|
398
|
+
* @param newStatus Optionally, force the minimize button into a specific state
|
|
399
|
+
*/
|
|
391
400
|
toggleMinimizeButton(newStatus) {
|
|
392
401
|
const minimizeButton = this.shadowRoot.querySelector("#minimize-button");
|
|
393
402
|
if (!minimizeButton)
|
|
@@ -435,6 +444,16 @@ class DevOverlayCanvas extends HTMLElement {
|
|
|
435
444
|
super();
|
|
436
445
|
this.shadowRoot = this.attachShadow({ mode: "open" });
|
|
437
446
|
}
|
|
447
|
+
connectedCallback() {
|
|
448
|
+
this.shadowRoot.innerHTML = `
|
|
449
|
+
<style>
|
|
450
|
+
:host {
|
|
451
|
+
position: absolute;
|
|
452
|
+
top: 0;
|
|
453
|
+
left: 0;
|
|
454
|
+
}
|
|
455
|
+
</style>`;
|
|
456
|
+
}
|
|
438
457
|
}
|
|
439
458
|
export {
|
|
440
459
|
AstroDevOverlay,
|
|
@@ -3,10 +3,37 @@ var astro_default = {
|
|
|
3
3
|
name: "Astro",
|
|
4
4
|
icon: "astro:logo",
|
|
5
5
|
init(canvas) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
createWindow();
|
|
7
|
+
document.addEventListener("astro:after-swap", createWindow);
|
|
8
|
+
function createWindow() {
|
|
9
|
+
const style = document.createElement("style");
|
|
10
|
+
style.textContent = `
|
|
11
|
+
:host {
|
|
12
|
+
opacity: 0;
|
|
13
|
+
transition: opacity 0.15s ease-in-out;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
:host([data-active]) {
|
|
17
|
+
opacity: 1;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@media screen and (prefers-reduced-motion: no-preference) {
|
|
21
|
+
:host astro-dev-overlay-window {
|
|
22
|
+
transform: translateY(55px) translate(-50%, -50%);
|
|
23
|
+
transition: transform 0.15s ease-in-out;
|
|
24
|
+
transform-origin: center bottom;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
:host([data-active]) astro-dev-overlay-window {
|
|
28
|
+
transform: translateY(0) translate(-50%, -50%);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
`;
|
|
32
|
+
canvas.append(style);
|
|
33
|
+
const astroWindow = document.createElement("astro-dev-overlay-window");
|
|
34
|
+
astroWindow.windowTitle = "Astro";
|
|
35
|
+
astroWindow.windowIcon = "astro:logo";
|
|
36
|
+
astroWindow.innerHTML = `
|
|
10
37
|
<style>
|
|
11
38
|
#buttons-container {
|
|
12
39
|
display: flex;
|
|
@@ -48,17 +75,25 @@ var astro_default = {
|
|
|
48
75
|
<div>
|
|
49
76
|
<p>Welcome to Astro!</p>
|
|
50
77
|
<div id="buttons-container">
|
|
51
|
-
<astro-dev-overlay-card icon="
|
|
52
|
-
<astro-dev-overlay-card icon="
|
|
78
|
+
<astro-dev-overlay-card icon="bug" link="https://github.com/withastro/astro/issues/new/choose">Report an issue</astro-dev-overlay-card>
|
|
79
|
+
<astro-dev-overlay-card icon="file-search" link="https://docs.astro.build/en/getting-started/">View Astro Docs</astro-dev-overlay-card>
|
|
53
80
|
</div>
|
|
54
81
|
</div>
|
|
55
82
|
<footer>
|
|
56
|
-
<a href="https://
|
|
57
|
-
<a href="https://astro.build" target="_blank">Visit Astro
|
|
83
|
+
<a href="https://astro.build/chat" target="_blank">Join us on Discord</a>
|
|
84
|
+
<a href="https://astro.build" target="_blank">Visit the Astro website</a>
|
|
58
85
|
</footer>
|
|
59
86
|
</div>
|
|
60
87
|
`;
|
|
61
|
-
|
|
88
|
+
canvas.append(astroWindow);
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
async beforeTogglingOff(canvas) {
|
|
92
|
+
canvas.host?.removeAttribute("data-active");
|
|
93
|
+
await new Promise((resolve) => {
|
|
94
|
+
canvas.host.addEventListener("transitionend", resolve);
|
|
95
|
+
});
|
|
96
|
+
return true;
|
|
62
97
|
}
|
|
63
98
|
};
|
|
64
99
|
export {
|
|
@@ -2,6 +2,7 @@ declare const _default: {
|
|
|
2
2
|
id: string;
|
|
3
3
|
name: string;
|
|
4
4
|
icon: "<svg xmlns=\"http://www.w3.org/2000/svg\" fill=\"none\" viewBox=\"0 0 24 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>";
|
|
5
|
-
init(canvas: ShadowRoot, eventTarget: EventTarget): void
|
|
5
|
+
init(canvas: ShadowRoot, eventTarget: EventTarget): Promise<void>;
|
|
6
|
+
beforeTogglingOff(canvas: ShadowRoot): Promise<boolean>;
|
|
6
7
|
};
|
|
7
8
|
export default _default;
|