astro 4.7.1 → 4.8.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 +1 -0
- package/content-module.template.mjs +2 -0
- package/dist/@types/astro.d.ts +219 -3
- package/dist/actions/consts.d.ts +3 -0
- package/dist/actions/consts.js +8 -0
- package/dist/actions/index.d.ts +2 -0
- package/dist/actions/index.js +72 -0
- package/dist/actions/runtime/middleware.d.ts +7 -0
- package/dist/actions/runtime/middleware.js +38 -0
- package/dist/actions/runtime/route.d.ts +2 -0
- package/dist/actions/runtime/route.js +37 -0
- package/dist/actions/runtime/store.d.ts +6 -0
- package/dist/actions/runtime/store.js +18 -0
- package/dist/actions/runtime/utils.d.ts +4 -0
- package/dist/actions/runtime/utils.js +23 -0
- package/dist/actions/runtime/virtual/client.d.ts +4 -0
- package/dist/actions/runtime/virtual/client.js +20 -0
- package/dist/actions/runtime/virtual/server.d.ts +21 -0
- package/dist/actions/runtime/virtual/server.js +98 -0
- package/dist/actions/runtime/virtual/shared.d.ts +37 -0
- package/dist/actions/runtime/virtual/shared.js +104 -0
- package/dist/actions/utils.d.ts +2 -0
- package/dist/actions/utils.js +18 -0
- package/dist/assets/build/generate.js +1 -1
- package/dist/assets/internal.js +1 -2
- package/dist/assets/services/service.js +2 -4
- package/dist/assets/services/sharp.js +2 -4
- package/dist/assets/services/squoosh.js +2 -4
- package/dist/assets/services/vendor/squoosh/avif/avif_node_dec.js +34 -68
- package/dist/assets/services/vendor/squoosh/avif/avif_node_enc.js +39 -78
- package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_dec.js +32 -64
- package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_enc.js +32 -64
- package/dist/assets/services/vendor/squoosh/png/squoosh_png.js +2 -4
- package/dist/assets/services/vendor/squoosh/webp/webp_node_dec.js +29 -58
- package/dist/assets/services/vendor/squoosh/webp/webp_node_enc.js +29 -58
- package/dist/assets/utils/getAssetsPrefix.js +2 -4
- package/dist/assets/utils/remotePattern.js +1 -2
- package/dist/assets/utils/remoteProbe.js +1 -2
- package/dist/assets/utils/vendor/image-size/types/cur.js +1 -2
- package/dist/assets/utils/vendor/image-size/types/icns.js +1 -2
- package/dist/assets/utils/vendor/image-size/types/ico.js +2 -4
- package/dist/assets/utils/vendor/image-size/types/jp2.js +2 -4
- package/dist/assets/utils/vendor/image-size/types/utils.js +4 -8
- package/dist/assets/vite-plugin-assets.js +1 -1
- package/dist/cli/add/babel.d.ts +1 -1
- package/dist/cli/add/imports.js +4 -8
- package/dist/cli/add/index.js +23 -46
- package/dist/cli/add/wrapper.js +1 -2
- package/dist/cli/index.js +1 -2
- package/dist/cli/info/index.js +1 -2
- package/dist/cli/install-package.js +3 -6
- package/dist/cli/throw-and-exit.js +1 -2
- package/dist/config/index.d.ts +2 -2
- package/dist/config/index.js +2 -2
- package/dist/content/index.d.ts +1 -1
- package/dist/content/index.js +1 -7
- package/dist/content/runtime.d.ts +2 -1
- package/dist/content/runtime.js +11 -20
- package/dist/content/server-listeners.js +5 -10
- package/dist/content/types-generator.js +5 -10
- package/dist/content/utils.d.ts +0 -4
- package/dist/content/utils.js +4 -15
- package/dist/content/vite-plugin-content-assets.d.ts +1 -1
- package/dist/content/vite-plugin-content-assets.js +14 -47
- package/dist/content/vite-plugin-content-imports.js +6 -11
- package/dist/content/vite-plugin-content-virtual-mod.js +7 -14
- package/dist/core/app/index.js +11 -46
- package/dist/core/app/node.js +4 -3
- package/dist/core/app/pipeline.d.ts +7 -2
- package/dist/core/app/pipeline.js +70 -2
- package/dist/core/app/types.d.ts +1 -0
- package/dist/core/base-pipeline.d.ts +16 -1
- package/dist/core/build/generate.js +15 -61
- package/dist/core/build/index.js +2 -4
- package/dist/core/build/internal.d.ts +39 -9
- package/dist/core/build/internal.js +43 -54
- package/dist/core/build/page-data.js +6 -6
- package/dist/core/build/pipeline.d.ts +7 -3
- package/dist/core/build/pipeline.js +134 -23
- package/dist/core/build/plugins/plugin-analyzer.js +11 -32
- package/dist/core/build/plugins/plugin-content.d.ts +1 -0
- package/dist/core/build/plugins/plugin-content.js +34 -32
- package/dist/core/build/plugins/plugin-css.js +23 -51
- package/dist/core/build/plugins/plugin-manifest.js +7 -8
- package/dist/core/build/plugins/plugin-pages.d.ts +0 -1
- package/dist/core/build/plugins/plugin-pages.js +10 -12
- package/dist/core/build/plugins/plugin-ssr.js +15 -13
- package/dist/core/build/plugins/util.d.ts +26 -11
- package/dist/core/build/plugins/util.js +22 -6
- package/dist/core/build/static-build.js +30 -25
- package/dist/core/build/types.d.ts +6 -6
- package/dist/core/client-directive/build.js +1 -2
- package/dist/core/config/config.js +2 -7
- package/dist/core/config/logging.js +1 -2
- package/dist/core/config/schema.d.ts +92 -60
- package/dist/core/config/schema.js +6 -2
- package/dist/core/config/settings.js +1 -2
- package/dist/core/config/timer.js +4 -8
- package/dist/core/constants.js +1 -1
- package/dist/core/cookies/cookies.js +3 -6
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/dev/restart.js +1 -2
- package/dist/core/errors/errors-data.d.ts +24 -0
- package/dist/core/errors/errors-data.js +13 -2
- package/dist/core/errors/errors.js +1 -2
- package/dist/core/errors/overlay.js +1 -2
- package/dist/core/errors/printer.js +2 -4
- package/dist/core/errors/zod-error-map.js +2 -4
- package/dist/core/fs/index.js +2 -4
- package/dist/core/logger/vite.js +9 -18
- package/dist/core/messages.js +2 -2
- package/dist/core/middleware/callMiddleware.d.ts +3 -2
- package/dist/core/middleware/callMiddleware.js +13 -3
- package/dist/core/middleware/index.js +12 -8
- package/dist/core/middleware/sequence.js +22 -4
- package/dist/core/module-loader/vite.js +1 -2
- package/dist/core/render/params-and-props.js +2 -4
- package/dist/core/render/slots.js +4 -8
- package/dist/core/render-context.d.ts +15 -5
- package/dist/core/render-context.js +134 -28
- package/dist/core/request.js +1 -2
- package/dist/core/routing/manifest/create.js +3 -6
- package/dist/core/sync/index.js +10 -3
- package/dist/core/util.d.ts +2 -0
- package/dist/core/util.js +18 -19
- package/dist/i18n/index.js +2 -4
- package/dist/i18n/middleware.js +1 -2
- package/dist/i18n/utils.js +1 -2
- package/dist/i18n/vite-plugin-i18n.js +1 -2
- package/dist/integrations/hooks.js +5 -1
- package/dist/jsx/babel.d.ts +3 -0
- package/dist/jsx/babel.js +9 -18
- package/dist/jsx/rehype.d.ts +11 -0
- package/dist/jsx/rehype.js +197 -0
- package/dist/jsx/server.js +20 -14
- package/dist/jsx/transform-options.d.ts +3 -0
- package/dist/jsx-runtime/index.js +8 -16
- package/dist/preferences/index.js +3 -6
- package/dist/preferences/store.js +3 -6
- package/dist/prefetch/index.js +8 -16
- package/dist/prefetch/vite-plugin-prefetch.js +2 -4
- package/dist/prerender/metadata.js +1 -2
- package/dist/prerender/routing.js +1 -1
- package/dist/prerender/utils.d.ts +0 -1
- package/dist/prerender/utils.js +2 -5
- package/dist/runtime/client/dev-toolbar/apps/astro.js +5 -10
- package/dist/runtime/client/dev-toolbar/apps/audit/index.js +5 -10
- package/dist/runtime/client/dev-toolbar/apps/audit/rules/a11y.js +45 -90
- package/dist/runtime/client/dev-toolbar/apps/audit/rules/index.js +1 -2
- package/dist/runtime/client/dev-toolbar/apps/audit/rules/perf.js +16 -32
- package/dist/runtime/client/dev-toolbar/apps/audit/ui/audit-list-window.js +2 -4
- package/dist/runtime/client/dev-toolbar/apps/audit/ui/audit-ui.js +3 -6
- package/dist/runtime/client/dev-toolbar/apps/utils/highlight.js +1 -2
- package/dist/runtime/client/dev-toolbar/apps/utils/window.js +4 -8
- package/dist/runtime/client/dev-toolbar/entrypoint.js +8 -11
- package/dist/runtime/client/dev-toolbar/helpers.js +2 -4
- package/dist/runtime/client/dev-toolbar/toolbar.js +11 -22
- package/dist/runtime/client/dev-toolbar/ui-library/badge.js +1 -2
- package/dist/runtime/client/dev-toolbar/ui-library/button.d.ts +5 -0
- package/dist/runtime/client/dev-toolbar/ui-library/button.js +26 -5
- package/dist/runtime/client/dev-toolbar/ui-library/index.d.ts +1 -0
- package/dist/runtime/client/dev-toolbar/ui-library/index.js +2 -0
- package/dist/runtime/client/dev-toolbar/ui-library/radio-checkbox.d.ts +13 -0
- package/dist/runtime/client/dev-toolbar/ui-library/radio-checkbox.js +109 -0
- package/dist/runtime/client/visible.js +1 -2
- package/dist/runtime/server/astro-component.js +2 -4
- package/dist/runtime/server/astro-island.js +7 -14
- package/dist/runtime/server/astro-island.prebuilt-dev.d.ts +1 -1
- package/dist/runtime/server/astro-island.prebuilt-dev.js +1 -1
- 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/index.js +3 -6
- package/dist/runtime/server/jsx.js +1 -2
- package/dist/runtime/server/render/any.js +1 -2
- package/dist/runtime/server/render/astro/instance.js +1 -2
- package/dist/runtime/server/render/astro/render.js +5 -10
- package/dist/runtime/server/render/component.js +6 -11
- package/dist/runtime/server/render/dom.js +1 -2
- package/dist/runtime/server/render/page.js +1 -2
- package/dist/runtime/server/render/script.js +1 -2
- package/dist/runtime/server/render/slot.js +1 -2
- package/dist/runtime/server/render/tags.js +2 -4
- package/dist/runtime/server/render/util.js +2 -4
- package/dist/runtime/server/shorthash.js +1 -2
- package/dist/runtime/server/transition.js +4 -8
- package/dist/runtime/server/util.js +1 -2
- package/dist/transitions/events.d.ts +3 -3
- package/dist/transitions/events.js +5 -4
- package/dist/transitions/router.js +22 -113
- package/dist/transitions/swap-functions.d.ts +12 -0
- package/dist/transitions/swap-functions.js +105 -0
- package/dist/vite-plugin-astro/compile.js +1 -2
- package/dist/vite-plugin-astro/hmr.js +5 -10
- package/dist/vite-plugin-astro/index.js +2 -4
- package/dist/vite-plugin-astro-server/pipeline.d.ts +8 -3
- package/dist/vite-plugin-astro-server/pipeline.js +59 -11
- package/dist/vite-plugin-astro-server/plugin.js +6 -6
- package/dist/vite-plugin-astro-server/response.js +1 -2
- package/dist/vite-plugin-astro-server/route.js +36 -42
- package/dist/vite-plugin-astro-server/vite.js +1 -2
- package/dist/vite-plugin-config-alias/index.js +7 -14
- package/dist/vite-plugin-head/index.js +3 -6
- package/dist/vite-plugin-html/index.js +1 -2
- package/dist/vite-plugin-html/transform/escape.js +2 -4
- package/dist/vite-plugin-html/transform/slots.js +1 -2
- package/dist/vite-plugin-html/transform/utils.js +1 -2
- package/dist/vite-plugin-inject-env-ts/index.js +37 -11
- package/dist/vite-plugin-integrations-container/index.js +3 -6
- package/dist/vite-plugin-load-fallback/index.js +1 -2
- package/dist/vite-plugin-markdown/index.js +1 -2
- package/dist/vite-plugin-mdx/index.d.ts +3 -0
- package/dist/vite-plugin-mdx/tag.d.ts +2 -0
- package/dist/vite-plugin-mdx/tag.js +3 -6
- package/dist/vite-plugin-mdx/transform-jsx.d.ts +3 -0
- package/dist/vite-plugin-mdx/transform-jsx.js +1 -2
- package/dist/vite-plugin-scanner/index.js +4 -6
- package/dist/vite-plugin-scanner/scan.js +2 -4
- package/dist/vite-plugin-scripts/page-ssr.js +3 -6
- package/package.json +18 -14
- package/templates/actions.mjs +61 -0
- package/types/actions.d.ts +3 -0
- package/types/content.d.ts +2 -2
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { visit } from "unist-util-visit";
|
|
2
|
+
import { AstroError } from "../core/errors/errors.js";
|
|
3
|
+
import { AstroErrorData } from "../core/errors/index.js";
|
|
4
|
+
import { resolvePath } from "../core/util.js";
|
|
5
|
+
const ClientOnlyPlaceholder = "astro-client-only";
|
|
6
|
+
const rehypeAnalyzeAstroMetadata = () => {
|
|
7
|
+
return (tree, file) => {
|
|
8
|
+
const metadata = {
|
|
9
|
+
clientOnlyComponents: [],
|
|
10
|
+
hydratedComponents: [],
|
|
11
|
+
scripts: [],
|
|
12
|
+
containsHead: false,
|
|
13
|
+
propagation: "none",
|
|
14
|
+
pageOptions: {}
|
|
15
|
+
};
|
|
16
|
+
const imports = parseImports(tree.children);
|
|
17
|
+
visit(tree, (node) => {
|
|
18
|
+
if (node.type !== "mdxJsxFlowElement" && node.type !== "mdxJsxTextElement") return;
|
|
19
|
+
const tagName = node.name;
|
|
20
|
+
if (!tagName || !isComponent(tagName) || !hasClientDirective(node)) return;
|
|
21
|
+
const matchedImport = findMatchingImport(tagName, imports);
|
|
22
|
+
if (!matchedImport) {
|
|
23
|
+
throw new AstroError({
|
|
24
|
+
...AstroErrorData.NoMatchingImport,
|
|
25
|
+
message: AstroErrorData.NoMatchingImport.message(node.name)
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
if (matchedImport.path.endsWith(".astro")) {
|
|
29
|
+
const clientAttribute = node.attributes.find(
|
|
30
|
+
(attr) => attr.type === "mdxJsxAttribute" && attr.name.startsWith("client:")
|
|
31
|
+
);
|
|
32
|
+
if (clientAttribute) {
|
|
33
|
+
console.warn(
|
|
34
|
+
`You are attempting to render <${node.name} ${clientAttribute.name} />, but ${node.name} is an Astro component. Astro components do not render in the client and should not have a hydration directive. Please use a framework component for client rendering.`
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const resolvedPath = resolvePath(matchedImport.path, file.path);
|
|
39
|
+
if (hasClientOnlyDirective(node)) {
|
|
40
|
+
metadata.clientOnlyComponents.push({
|
|
41
|
+
exportName: matchedImport.name,
|
|
42
|
+
specifier: tagName,
|
|
43
|
+
resolvedPath
|
|
44
|
+
});
|
|
45
|
+
addClientOnlyMetadata(node, matchedImport, resolvedPath);
|
|
46
|
+
} else {
|
|
47
|
+
metadata.hydratedComponents.push({
|
|
48
|
+
exportName: "*",
|
|
49
|
+
specifier: tagName,
|
|
50
|
+
resolvedPath
|
|
51
|
+
});
|
|
52
|
+
addClientMetadata(node, matchedImport, resolvedPath);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
file.data.__astroMetadata = metadata;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
function getAstroMetadata(file) {
|
|
59
|
+
return file.data.__astroMetadata;
|
|
60
|
+
}
|
|
61
|
+
function parseImports(children) {
|
|
62
|
+
const imports = /* @__PURE__ */ new Map();
|
|
63
|
+
for (const child of children) {
|
|
64
|
+
if (child.type !== "mdxjsEsm") continue;
|
|
65
|
+
const body = child.data?.estree?.body;
|
|
66
|
+
if (!body) continue;
|
|
67
|
+
for (const ast of body) {
|
|
68
|
+
if (ast.type !== "ImportDeclaration") continue;
|
|
69
|
+
const source = ast.source.value;
|
|
70
|
+
const specs = ast.specifiers.map((spec) => {
|
|
71
|
+
switch (spec.type) {
|
|
72
|
+
case "ImportDefaultSpecifier":
|
|
73
|
+
return { local: spec.local.name, imported: "default" };
|
|
74
|
+
case "ImportNamespaceSpecifier":
|
|
75
|
+
return { local: spec.local.name, imported: "*" };
|
|
76
|
+
case "ImportSpecifier":
|
|
77
|
+
return { local: spec.local.name, imported: spec.imported.name };
|
|
78
|
+
default:
|
|
79
|
+
throw new Error("Unknown import declaration specifier: " + spec);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
let specSet = imports.get(source);
|
|
83
|
+
if (!specSet) {
|
|
84
|
+
specSet = /* @__PURE__ */ new Set();
|
|
85
|
+
imports.set(source, specSet);
|
|
86
|
+
}
|
|
87
|
+
for (const spec of specs) {
|
|
88
|
+
specSet.add(spec);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return imports;
|
|
93
|
+
}
|
|
94
|
+
function isComponent(tagName) {
|
|
95
|
+
return tagName[0] && tagName[0].toLowerCase() !== tagName[0] || tagName.includes(".") || /[^a-zA-Z]/.test(tagName[0]);
|
|
96
|
+
}
|
|
97
|
+
function hasClientDirective(node) {
|
|
98
|
+
return node.attributes.some(
|
|
99
|
+
(attr) => attr.type === "mdxJsxAttribute" && attr.name.startsWith("client:")
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
function hasClientOnlyDirective(node) {
|
|
103
|
+
return node.attributes.some(
|
|
104
|
+
(attr) => attr.type === "mdxJsxAttribute" && attr.name === "client:only"
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
function findMatchingImport(tagName, imports) {
|
|
108
|
+
const tagSpecifier = tagName.split(".")[0];
|
|
109
|
+
for (const [source, specs] of imports) {
|
|
110
|
+
for (const { imported, local } of specs) {
|
|
111
|
+
if (local === tagSpecifier) {
|
|
112
|
+
if (tagSpecifier !== tagName) {
|
|
113
|
+
switch (imported) {
|
|
114
|
+
case "*": {
|
|
115
|
+
const accessPath = tagName.slice(tagSpecifier.length + 1);
|
|
116
|
+
return { name: accessPath, path: source };
|
|
117
|
+
}
|
|
118
|
+
case "default": {
|
|
119
|
+
const accessPath = tagName.slice(tagSpecifier.length + 1);
|
|
120
|
+
return { name: `default.${accessPath}`, path: source };
|
|
121
|
+
}
|
|
122
|
+
default: {
|
|
123
|
+
return { name: tagName, path: source };
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return { name: imported, path: source };
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function addClientMetadata(node, meta, resolvedPath) {
|
|
133
|
+
const attributeNames = node.attributes.map((attr) => attr.type === "mdxJsxAttribute" ? attr.name : null).filter(Boolean);
|
|
134
|
+
if (!attributeNames.includes("client:component-path")) {
|
|
135
|
+
node.attributes.push({
|
|
136
|
+
type: "mdxJsxAttribute",
|
|
137
|
+
name: "client:component-path",
|
|
138
|
+
value: resolvedPath
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
if (!attributeNames.includes("client:component-export")) {
|
|
142
|
+
if (meta.name === "*") {
|
|
143
|
+
meta.name = node.name.split(".").slice(1).join(".");
|
|
144
|
+
}
|
|
145
|
+
node.attributes.push({
|
|
146
|
+
type: "mdxJsxAttribute",
|
|
147
|
+
name: "client:component-export",
|
|
148
|
+
value: meta.name
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
if (!attributeNames.includes("client:component-hydration")) {
|
|
152
|
+
node.attributes.push({
|
|
153
|
+
type: "mdxJsxAttribute",
|
|
154
|
+
name: "client:component-hydration",
|
|
155
|
+
value: null
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function addClientOnlyMetadata(node, meta, resolvedPath) {
|
|
160
|
+
const attributeNames = node.attributes.map((attr) => attr.type === "mdxJsxAttribute" ? attr.name : null).filter(Boolean);
|
|
161
|
+
if (!attributeNames.includes("client:display-name")) {
|
|
162
|
+
node.attributes.push({
|
|
163
|
+
type: "mdxJsxAttribute",
|
|
164
|
+
name: "client:display-name",
|
|
165
|
+
value: node.name
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
if (!attributeNames.includes("client:component-hydpathation")) {
|
|
169
|
+
node.attributes.push({
|
|
170
|
+
type: "mdxJsxAttribute",
|
|
171
|
+
name: "client:component-path",
|
|
172
|
+
value: resolvedPath
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
if (!attributeNames.includes("client:component-export")) {
|
|
176
|
+
if (meta.name === "*") {
|
|
177
|
+
meta.name = node.name.split(".").slice(1).join(".");
|
|
178
|
+
}
|
|
179
|
+
node.attributes.push({
|
|
180
|
+
type: "mdxJsxAttribute",
|
|
181
|
+
name: "client:component-export",
|
|
182
|
+
value: meta.name
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
if (!attributeNames.includes("client:component-hydration")) {
|
|
186
|
+
node.attributes.push({
|
|
187
|
+
type: "mdxJsxAttribute",
|
|
188
|
+
name: "client:component-hydration",
|
|
189
|
+
value: null
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
node.name = ClientOnlyPlaceholder;
|
|
193
|
+
}
|
|
194
|
+
export {
|
|
195
|
+
getAstroMetadata,
|
|
196
|
+
rehypeAnalyzeAstroMetadata
|
|
197
|
+
};
|
package/dist/jsx/server.js
CHANGED
|
@@ -3,8 +3,7 @@ import { AstroJSX, jsx } from "../jsx-runtime/index.js";
|
|
|
3
3
|
import { renderJSX } from "../runtime/server/jsx.js";
|
|
4
4
|
const slotName = (str) => str.trim().replace(/[-_]([a-z])/g, (_, w) => w.toUpperCase());
|
|
5
5
|
async function check(Component, props, { default: children = null, ...slotted } = {}) {
|
|
6
|
-
if (typeof Component !== "function")
|
|
7
|
-
return false;
|
|
6
|
+
if (typeof Component !== "function") return false;
|
|
8
7
|
const slots = {};
|
|
9
8
|
for (const [key, value] of Object.entries(slotted)) {
|
|
10
9
|
const name = slotName(key);
|
|
@@ -14,16 +13,7 @@ async function check(Component, props, { default: children = null, ...slotted }
|
|
|
14
13
|
const result = await Component({ ...props, ...slots, children });
|
|
15
14
|
return result[AstroJSX];
|
|
16
15
|
} catch (e) {
|
|
17
|
-
|
|
18
|
-
if (Component[Symbol.for("mdx-component")]) {
|
|
19
|
-
throw new AstroError({
|
|
20
|
-
message: error.message,
|
|
21
|
-
title: error.name,
|
|
22
|
-
hint: `This issue often occurs when your MDX component encounters runtime errors.`,
|
|
23
|
-
name: error.name,
|
|
24
|
-
stack: error.stack
|
|
25
|
-
});
|
|
26
|
-
}
|
|
16
|
+
throwEnhancedErrorIfMdxComponent(e, Component);
|
|
27
17
|
}
|
|
28
18
|
return false;
|
|
29
19
|
}
|
|
@@ -34,8 +24,24 @@ async function renderToStaticMarkup(Component, props = {}, { default: children =
|
|
|
34
24
|
slots[name] = value;
|
|
35
25
|
}
|
|
36
26
|
const { result } = this;
|
|
37
|
-
|
|
38
|
-
|
|
27
|
+
try {
|
|
28
|
+
const html = await renderJSX(result, jsx(Component, { ...props, ...slots, children }));
|
|
29
|
+
return { html };
|
|
30
|
+
} catch (e) {
|
|
31
|
+
throwEnhancedErrorIfMdxComponent(e, Component);
|
|
32
|
+
throw e;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function throwEnhancedErrorIfMdxComponent(error, Component) {
|
|
36
|
+
if (Component[Symbol.for("mdx-component")]) {
|
|
37
|
+
throw new AstroError({
|
|
38
|
+
message: error.message,
|
|
39
|
+
title: error.name,
|
|
40
|
+
hint: `This issue often occurs when your MDX component encounters runtime errors.`,
|
|
41
|
+
name: error.name,
|
|
42
|
+
stack: error.stack
|
|
43
|
+
});
|
|
44
|
+
}
|
|
39
45
|
}
|
|
40
46
|
var server_default = {
|
|
41
47
|
check,
|
|
@@ -6,15 +6,12 @@ function isVNode(vnode) {
|
|
|
6
6
|
return vnode && typeof vnode === "object" && vnode[AstroJSX];
|
|
7
7
|
}
|
|
8
8
|
function transformSlots(vnode) {
|
|
9
|
-
if (typeof vnode.type === "string")
|
|
10
|
-
return vnode;
|
|
9
|
+
if (typeof vnode.type === "string") return vnode;
|
|
11
10
|
const slots = {};
|
|
12
11
|
if (isVNode(vnode.props.children)) {
|
|
13
12
|
const child = vnode.props.children;
|
|
14
|
-
if (!isVNode(child))
|
|
15
|
-
|
|
16
|
-
if (!("slot" in child.props))
|
|
17
|
-
return;
|
|
13
|
+
if (!isVNode(child)) return;
|
|
14
|
+
if (!("slot" in child.props)) return;
|
|
18
15
|
const name = toSlotName(child.props.slot);
|
|
19
16
|
slots[name] = [child];
|
|
20
17
|
slots[name]["$$slot"] = true;
|
|
@@ -23,10 +20,8 @@ function transformSlots(vnode) {
|
|
|
23
20
|
}
|
|
24
21
|
if (Array.isArray(vnode.props.children)) {
|
|
25
22
|
vnode.props.children = vnode.props.children.map((child) => {
|
|
26
|
-
if (!isVNode(child))
|
|
27
|
-
|
|
28
|
-
if (!("slot" in child.props))
|
|
29
|
-
return child;
|
|
23
|
+
if (!isVNode(child)) return child;
|
|
24
|
+
if (!("slot" in child.props)) return child;
|
|
30
25
|
const name = toSlotName(child.props.slot);
|
|
31
26
|
if (Array.isArray(slots[name])) {
|
|
32
27
|
slots[name].push(child);
|
|
@@ -41,15 +36,12 @@ function transformSlots(vnode) {
|
|
|
41
36
|
Object.assign(vnode.props, slots);
|
|
42
37
|
}
|
|
43
38
|
function markRawChildren(child) {
|
|
44
|
-
if (typeof child === "string")
|
|
45
|
-
|
|
46
|
-
if (Array.isArray(child))
|
|
47
|
-
return child.map((c) => markRawChildren(c));
|
|
39
|
+
if (typeof child === "string") return markHTMLString(child);
|
|
40
|
+
if (Array.isArray(child)) return child.map((c) => markRawChildren(c));
|
|
48
41
|
return child;
|
|
49
42
|
}
|
|
50
43
|
function transformSetDirectives(vnode) {
|
|
51
|
-
if (!("set:html" in vnode.props || "set:text" in vnode.props))
|
|
52
|
-
return;
|
|
44
|
+
if (!("set:html" in vnode.props || "set:text" in vnode.props)) return;
|
|
53
45
|
if ("set:html" in vnode.props) {
|
|
54
46
|
const children = markRawChildren(vnode.props["set:html"]);
|
|
55
47
|
delete vnode.props["set:html"];
|
|
@@ -16,10 +16,8 @@ function coerce(key, value) {
|
|
|
16
16
|
case "number":
|
|
17
17
|
return Number(value);
|
|
18
18
|
case "boolean": {
|
|
19
|
-
if (value === "true" || value === 1)
|
|
20
|
-
|
|
21
|
-
if (value === "false" || value === 0)
|
|
22
|
-
return false;
|
|
19
|
+
if (value === "true" || value === 1) return true;
|
|
20
|
+
if (value === "false" || value === 0) return false;
|
|
23
21
|
break;
|
|
24
22
|
}
|
|
25
23
|
default:
|
|
@@ -33,8 +31,7 @@ function createPreferences(config) {
|
|
|
33
31
|
const stores = { global, project };
|
|
34
32
|
return {
|
|
35
33
|
async get(key, { location } = {}) {
|
|
36
|
-
if (!location)
|
|
37
|
-
return project.get(key) ?? global.get(key) ?? dget(DEFAULT_PREFERENCES, key);
|
|
34
|
+
if (!location) return project.get(key) ?? global.get(key) ?? dget(DEFAULT_PREFERENCES, key);
|
|
38
35
|
return stores[location].get(key);
|
|
39
36
|
},
|
|
40
37
|
async set(key, value, { location = "project", reloadServer = true } = {}) {
|
|
@@ -10,8 +10,7 @@ class PreferenceStore {
|
|
|
10
10
|
file;
|
|
11
11
|
_store;
|
|
12
12
|
get store() {
|
|
13
|
-
if (this._store)
|
|
14
|
-
return this._store;
|
|
13
|
+
if (this._store) return this._store;
|
|
15
14
|
if (fs.existsSync(this.file)) {
|
|
16
15
|
try {
|
|
17
16
|
this._store = JSON.parse(fs.readFileSync(this.file).toString());
|
|
@@ -29,8 +28,7 @@ class PreferenceStore {
|
|
|
29
28
|
this.write();
|
|
30
29
|
}
|
|
31
30
|
write() {
|
|
32
|
-
if (!this._store || Object.keys(this._store).length === 0)
|
|
33
|
-
return;
|
|
31
|
+
if (!this._store || Object.keys(this._store).length === 0) return;
|
|
34
32
|
fs.mkdirSync(this.dir, { recursive: true });
|
|
35
33
|
fs.writeFileSync(this.file, JSON.stringify(this.store, null, " "));
|
|
36
34
|
}
|
|
@@ -50,8 +48,7 @@ class PreferenceStore {
|
|
|
50
48
|
return typeof this.get(key) !== "undefined";
|
|
51
49
|
}
|
|
52
50
|
set(key, value) {
|
|
53
|
-
if (this.get(key) === value)
|
|
54
|
-
return;
|
|
51
|
+
if (this.get(key) === value) return;
|
|
55
52
|
dset(this.store, key, value);
|
|
56
53
|
this.write();
|
|
57
54
|
}
|
package/dist/prefetch/index.js
CHANGED
|
@@ -7,10 +7,8 @@ let defaultStrategy = __PREFETCH_DEFAULT_STRATEGY__;
|
|
|
7
7
|
let clientPrerender = __EXPERIMENTAL_CLIENT_PRERENDER__;
|
|
8
8
|
let inited = false;
|
|
9
9
|
function init(defaultOpts) {
|
|
10
|
-
if (!inBrowser)
|
|
11
|
-
|
|
12
|
-
if (inited)
|
|
13
|
-
return;
|
|
10
|
+
if (!inBrowser) return;
|
|
11
|
+
if (inited) return;
|
|
14
12
|
inited = true;
|
|
15
13
|
debug?.(`[astro] Initializing prefetch script`);
|
|
16
14
|
prefetchAll ??= defaultOpts?.prefetchAll ?? false;
|
|
@@ -47,8 +45,7 @@ function initHoverStrategy() {
|
|
|
47
45
|
document.body.addEventListener("focusout", handleHoverOut, { passive: true });
|
|
48
46
|
onPageLoad(() => {
|
|
49
47
|
for (const anchor of document.getElementsByTagName("a")) {
|
|
50
|
-
if (listenedAnchors.has(anchor))
|
|
51
|
-
continue;
|
|
48
|
+
if (listenedAnchors.has(anchor)) continue;
|
|
52
49
|
if (elMatchesStrategy(anchor, "hover")) {
|
|
53
50
|
listenedAnchors.add(anchor);
|
|
54
51
|
anchor.addEventListener("mouseenter", handleHoverIn, { passive: true });
|
|
@@ -76,8 +73,7 @@ function initViewportStrategy() {
|
|
|
76
73
|
let observer;
|
|
77
74
|
onPageLoad(() => {
|
|
78
75
|
for (const anchor of document.getElementsByTagName("a")) {
|
|
79
|
-
if (listenedAnchors.has(anchor))
|
|
80
|
-
continue;
|
|
76
|
+
if (listenedAnchors.has(anchor)) continue;
|
|
81
77
|
if (elMatchesStrategy(anchor, "viewport")) {
|
|
82
78
|
listenedAnchors.add(anchor);
|
|
83
79
|
observer ??= createViewportIntersectionObserver();
|
|
@@ -124,8 +120,7 @@ function initLoadStrategy() {
|
|
|
124
120
|
}
|
|
125
121
|
function prefetch(url, opts) {
|
|
126
122
|
const ignoreSlowConnection = opts?.ignoreSlowConnection ?? false;
|
|
127
|
-
if (!canPrefetchUrl(url, ignoreSlowConnection))
|
|
128
|
-
return;
|
|
123
|
+
if (!canPrefetchUrl(url, ignoreSlowConnection)) return;
|
|
129
124
|
prefetchedUrls.add(url);
|
|
130
125
|
const priority = opts?.with ?? "link";
|
|
131
126
|
debug?.(`[astro] Prefetching ${url} with ${priority}`);
|
|
@@ -144,10 +139,8 @@ function prefetch(url, opts) {
|
|
|
144
139
|
}
|
|
145
140
|
}
|
|
146
141
|
function canPrefetchUrl(url, ignoreSlowConnection) {
|
|
147
|
-
if (!navigator.onLine)
|
|
148
|
-
|
|
149
|
-
if (!ignoreSlowConnection && isSlowConnection())
|
|
150
|
-
return false;
|
|
142
|
+
if (!navigator.onLine) return false;
|
|
143
|
+
if (!ignoreSlowConnection && isSlowConnection()) return false;
|
|
151
144
|
try {
|
|
152
145
|
const urlObj = new URL(url, location.href);
|
|
153
146
|
return location.origin === urlObj.origin && (location.pathname !== urlObj.pathname || location.search !== urlObj.search) && !prefetchedUrls.has(url);
|
|
@@ -156,8 +149,7 @@ function canPrefetchUrl(url, ignoreSlowConnection) {
|
|
|
156
149
|
return false;
|
|
157
150
|
}
|
|
158
151
|
function elMatchesStrategy(el, strategy) {
|
|
159
|
-
if (el?.tagName !== "A")
|
|
160
|
-
return false;
|
|
152
|
+
if (el?.tagName !== "A") return false;
|
|
161
153
|
const attrValue = el.dataset.astroPrefetch;
|
|
162
154
|
if (attrValue === "false") {
|
|
163
155
|
return false;
|
|
@@ -18,15 +18,13 @@ function astroPrefetch({ settings }) {
|
|
|
18
18
|
name: "astro:prefetch",
|
|
19
19
|
async resolveId(id) {
|
|
20
20
|
if (id === virtualModuleId) {
|
|
21
|
-
if (!prefetch)
|
|
22
|
-
throwPrefetchNotEnabledError();
|
|
21
|
+
if (!prefetch) throwPrefetchNotEnabledError();
|
|
23
22
|
return resolvedVirtualModuleId;
|
|
24
23
|
}
|
|
25
24
|
},
|
|
26
25
|
load(id) {
|
|
27
26
|
if (id === resolvedVirtualModuleId) {
|
|
28
|
-
if (!prefetch)
|
|
29
|
-
throwPrefetchNotEnabledError();
|
|
27
|
+
if (!prefetch) throwPrefetchNotEnabledError();
|
|
30
28
|
return `export { prefetch } from "astro/virtual-modules/prefetch.js";`;
|
|
31
29
|
}
|
|
32
30
|
},
|
|
@@ -5,8 +5,7 @@ function getPrerenderStatus({
|
|
|
5
5
|
}) {
|
|
6
6
|
const fileID = viteID(filePath);
|
|
7
7
|
const moduleInfo = loader.getModuleInfo(fileID);
|
|
8
|
-
if (!moduleInfo)
|
|
9
|
-
return;
|
|
8
|
+
if (!moduleInfo) return;
|
|
10
9
|
const prerenderStatus = getPrerenderMetadata(moduleInfo);
|
|
11
10
|
return prerenderStatus;
|
|
12
11
|
}
|
|
@@ -28,7 +28,7 @@ async function preloadAndSetPrerenderStatus({
|
|
|
28
28
|
});
|
|
29
29
|
continue;
|
|
30
30
|
}
|
|
31
|
-
const preloadedComponent = await pipeline.preload(filePath);
|
|
31
|
+
const preloadedComponent = await pipeline.preload(route, filePath);
|
|
32
32
|
const prerenderStatus = getPrerenderStatus({
|
|
33
33
|
filePath,
|
|
34
34
|
loader: pipeline.loader
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { AstroConfig } from '../@types/astro.js';
|
|
2
|
-
export declare function isServerLikeOutput(config: AstroConfig): boolean;
|
|
3
2
|
export declare function getPrerenderDefault(config: AstroConfig): boolean;
|
|
4
3
|
/**
|
|
5
4
|
* Returns the correct output directory of the SSR build based on the configuration
|
package/dist/prerender/utils.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { getOutDirWithinCwd } from "../core/build/common.js";
|
|
2
|
-
|
|
3
|
-
return config.output === "server" || config.output === "hybrid";
|
|
4
|
-
}
|
|
2
|
+
import { isServerLikeOutput } from "../core/util.js";
|
|
5
3
|
function getPrerenderDefault(config) {
|
|
6
4
|
return config.output !== "server";
|
|
7
5
|
}
|
|
@@ -15,6 +13,5 @@ function getOutputDirectory(config) {
|
|
|
15
13
|
}
|
|
16
14
|
export {
|
|
17
15
|
getOutputDirectory,
|
|
18
|
-
getPrerenderDefault
|
|
19
|
-
isServerLikeOutput
|
|
16
|
+
getPrerenderDefault
|
|
20
17
|
};
|
|
@@ -16,11 +16,9 @@ var astro_default = {
|
|
|
16
16
|
document.addEventListener("astro:after-swap", createCanvas);
|
|
17
17
|
eventTarget.addEventListener("app-toggled", async (event) => {
|
|
18
18
|
resetDebugButton();
|
|
19
|
-
if (!(event instanceof CustomEvent))
|
|
20
|
-
return;
|
|
19
|
+
if (!(event instanceof CustomEvent)) return;
|
|
21
20
|
if (event.detail.state === true) {
|
|
22
|
-
if (!integrationData)
|
|
23
|
-
fetchIntegrationData();
|
|
21
|
+
if (!integrationData) fetchIntegrationData();
|
|
24
22
|
}
|
|
25
23
|
});
|
|
26
24
|
closeOnOutsideClick(eventTarget);
|
|
@@ -341,19 +339,16 @@ var astro_default = {
|
|
|
341
339
|
}, 3500);
|
|
342
340
|
});
|
|
343
341
|
canvas.append(windowComponent);
|
|
344
|
-
if (integrationData)
|
|
345
|
-
refreshIntegrationList();
|
|
342
|
+
if (integrationData) refreshIntegrationList();
|
|
346
343
|
}
|
|
347
344
|
function resetDebugButton() {
|
|
348
345
|
const copyDebugButton = canvas.querySelector("#copy-debug-button");
|
|
349
|
-
if (!copyDebugButton)
|
|
350
|
-
return;
|
|
346
|
+
if (!copyDebugButton) return;
|
|
351
347
|
copyDebugButton.innerHTML = 'Copy debug info <astro-dev-toolbar-icon icon="copy" />';
|
|
352
348
|
}
|
|
353
349
|
function refreshIntegrationList() {
|
|
354
350
|
const integrationList = canvas.querySelector("#integration-list");
|
|
355
|
-
if (!integrationList)
|
|
356
|
-
return;
|
|
351
|
+
if (!integrationList) return;
|
|
357
352
|
integrationList.innerHTML = "";
|
|
358
353
|
const fragment = document.createDocumentFragment();
|
|
359
354
|
for (const integration of integrationData.data) {
|
|
@@ -35,8 +35,7 @@ var audit_default = {
|
|
|
35
35
|
window.requestIdleCallback(
|
|
36
36
|
async () => {
|
|
37
37
|
lint().then(() => {
|
|
38
|
-
if (showState)
|
|
39
|
-
createAuditsUI();
|
|
38
|
+
if (showState) createAuditsUI();
|
|
40
39
|
});
|
|
41
40
|
},
|
|
42
41
|
{ timeout: 300 }
|
|
@@ -44,8 +43,7 @@ var audit_default = {
|
|
|
44
43
|
} else {
|
|
45
44
|
setTimeout(async () => {
|
|
46
45
|
lint().then(() => {
|
|
47
|
-
if (showState)
|
|
48
|
-
createAuditsUI();
|
|
46
|
+
if (showState) createAuditsUI();
|
|
49
47
|
});
|
|
50
48
|
}, 150);
|
|
51
49
|
}
|
|
@@ -83,8 +81,7 @@ var audit_default = {
|
|
|
83
81
|
return false;
|
|
84
82
|
});
|
|
85
83
|
async function createAuditsUI() {
|
|
86
|
-
if (hasCreatedUI)
|
|
87
|
-
return;
|
|
84
|
+
if (hasCreatedUI) return;
|
|
88
85
|
const fragment = document.createDocumentFragment();
|
|
89
86
|
for (const audit of audits) {
|
|
90
87
|
const { card, highlight } = createAuditUI(audit, audits);
|
|
@@ -124,8 +121,7 @@ var audit_default = {
|
|
|
124
121
|
}
|
|
125
122
|
}
|
|
126
123
|
for (const element of matches) {
|
|
127
|
-
if (audits.some((audit) => audit.auditedElement === element))
|
|
128
|
-
continue;
|
|
124
|
+
if (audits.some((audit) => audit.auditedElement === element)) continue;
|
|
129
125
|
await createAuditProblem(rule, element);
|
|
130
126
|
}
|
|
131
127
|
}
|
|
@@ -157,8 +153,7 @@ var audit_default = {
|
|
|
157
153
|
function refreshLintPositions() {
|
|
158
154
|
audits.forEach(({ highlight, auditedElement }) => {
|
|
159
155
|
const rect = auditedElement.getBoundingClientRect();
|
|
160
|
-
if (highlight)
|
|
161
|
-
positionHighlight(highlight, rect);
|
|
156
|
+
if (highlight) positionHighlight(highlight, rect);
|
|
162
157
|
});
|
|
163
158
|
}
|
|
164
159
|
["scroll", "resize"].forEach((event) => {
|