@styleflow.app/flowpress-astro-core 1.0.0-beta.15 → 1.0.0-beta.17
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/CHANGELOG.md +16 -0
- package/README.md +19 -1
- package/dist/astro/BaseLayout.astro +6 -6
- package/dist/astro/CompositionRenderer.astro +23 -7
- package/dist/astro/GutenbergRenderer.astro +33 -20
- package/dist/astro/blocks/CarouselBlock.astro +3 -3
- package/dist/astro/blocks/CarouselItemBlock.astro +1 -1
- package/dist/astro/blocks/ColumnBlock.astro +1 -1
- package/dist/astro/blocks/CoverBlock.astro +3 -3
- package/dist/astro/blocks/FormBlock.astro +13 -11
- package/dist/astro/blocks/GridBlock.astro +1 -1
- package/dist/astro/blocks/HeroBlock.astro +1 -1
- package/dist/astro/blocks/ImageBlock.astro +1 -1
- package/dist/astro/blocks/NumberSpinnerBlock.astro +1 -1
- package/dist/astro/blocks/SemanticElement.astro +2 -2
- package/dist/astro/blocks/SiteLogoBlock.astro +4 -4
- package/dist/astro/blocks/TextBlock.astro +2 -2
- package/dist/astro/blocks/cover.d.ts +2 -1
- package/dist/astro/blocks/cover.d.ts.map +1 -1
- package/dist/astro/blocks/cover.js.map +1 -1
- package/dist/astro/blocks/cover.ts +3 -2
- package/dist/astro/native/Blob.astro +113 -0
- package/dist/astro/native/BlobBlock.astro +52 -0
- package/dist/astro/native/CustomFieldValue.astro +86 -0
- package/dist/astro/native/LevelTag.astro +20 -0
- package/dist/astro/native/MapBlock.astro +41 -0
- package/dist/astro/native/NativeHtmlBlock.astro +12 -0
- package/dist/astro/native/NativeIconBlock.astro +33 -0
- package/dist/astro/native/ProjectTimelineBlock.astro +34 -0
- package/dist/astro/native/ResolvedBlocks.astro +89 -0
- package/dist/astro/native/SyncedPatternContent.astro +92 -0
- package/dist/astro/native/TermFieldValue.astro +37 -0
- package/dist/astro/native/Timeline.astro +20 -0
- package/dist/astro/native/TimelineCardBlock.astro +7 -0
- package/dist/astro/native/blob/blob-shapes.generated.d.ts +2 -0
- package/dist/astro/native/blob/blob-shapes.generated.d.ts.map +1 -0
- package/dist/astro/native/blob/blob-shapes.generated.js +2 -0
- package/dist/astro/native/blob/blob-shapes.generated.js.map +1 -0
- package/dist/astro/native/blob/blob-shapes.generated.ts +1 -0
- package/dist/astro/native/blob/config.d.ts +49 -0
- package/dist/astro/native/blob/config.d.ts.map +1 -0
- package/dist/astro/native/blob/config.js +86 -0
- package/dist/astro/native/blob/config.js.map +1 -0
- package/dist/astro/native/blob/config.ts +132 -0
- package/dist/astro/native/blob/controller.d.ts +11 -0
- package/dist/astro/native/blob/controller.d.ts.map +1 -0
- package/dist/astro/native/blob/controller.js +240 -0
- package/dist/astro/native/blob/controller.js.map +1 -0
- package/dist/astro/native/blob/controller.ts +248 -0
- package/dist/astro/native/blob/geometry.d.ts +2 -0
- package/dist/astro/native/blob/geometry.d.ts.map +1 -0
- package/dist/astro/native/blob/geometry.js +2 -0
- package/dist/astro/native/blob/geometry.js.map +1 -0
- package/dist/astro/native/blob/geometry.ts +1 -0
- package/dist/astro/native/blob/ids.d.ts +7 -0
- package/dist/astro/native/blob/ids.d.ts.map +1 -0
- package/dist/astro/native/blob/ids.js +11 -0
- package/dist/astro/native/blob/ids.js.map +1 -0
- package/dist/astro/native/blob/ids.ts +11 -0
- package/dist/astro/native/blob.css +83 -0
- package/dist/astro/native/button.d.ts +13 -0
- package/dist/astro/native/button.d.ts.map +1 -0
- package/dist/astro/native/button.js +26 -0
- package/dist/astro/native/button.js.map +1 -0
- package/dist/astro/native/button.ts +26 -0
- package/dist/astro/native/core-block.astro +18 -0
- package/dist/astro/native/core-button.astro +43 -0
- package/dist/astro/native/core-buttons.astro +14 -0
- package/dist/astro/native/core-group.astro +23 -0
- package/dist/astro/native/core-home-link.astro +11 -0
- package/dist/astro/native/core-html.astro +8 -0
- package/dist/astro/native/core-icon.astro +7 -0
- package/dist/astro/native/core-image.astro +124 -0
- package/dist/astro/native/core-navigation-link.astro +70 -0
- package/dist/astro/native/core-navigation-submenu.astro +32 -0
- package/dist/astro/native/core-navigation.astro +94 -0
- package/dist/astro/native/core-page-list-data-item.astro +18 -0
- package/dist/astro/native/core-page-list-item.astro +7 -0
- package/dist/astro/native/core-page-list.astro +40 -0
- package/dist/astro/native/core-post-date.astro +20 -0
- package/dist/astro/native/core-post-excerpt.astro +25 -0
- package/dist/astro/native/core-post-featured-image.astro +37 -0
- package/dist/astro/native/core-post-template.astro +30 -0
- package/dist/astro/native/core-post-terms.astro +46 -0
- package/dist/astro/native/core-post-title.astro +23 -0
- package/dist/astro/native/core-query-no-results.astro +12 -0
- package/dist/astro/native/core-query.astro +22 -0
- package/dist/astro/native/core-site-title.astro +15 -0
- package/dist/astro/native/core-term-description.astro +12 -0
- package/dist/astro/native/core-term-name.astro +20 -0
- package/dist/astro/native/core-term-template.astro +30 -0
- package/dist/astro/native/core-terms-query.astro +19 -0
- package/dist/astro/native/flowpress-navigation-controller.d.ts +2 -0
- package/dist/astro/native/flowpress-navigation-controller.d.ts.map +1 -0
- package/dist/astro/native/flowpress-navigation-controller.js +217 -0
- package/dist/astro/native/flowpress-navigation-controller.js.map +1 -0
- package/dist/astro/native/flowpress-navigation-controller.ts +215 -0
- package/dist/astro/native/flowpress-navigation.css +17 -0
- package/dist/astro/native/grid-bleed.js +106 -0
- package/dist/astro/native/grid.css +180 -0
- package/dist/astro/native/grid.d.ts +17 -0
- package/dist/astro/native/grid.d.ts.map +1 -0
- package/dist/astro/native/grid.js +103 -0
- package/dist/astro/native/grid.js.map +1 -0
- package/dist/astro/native/grid.ts +118 -0
- package/dist/astro/native/html.d.ts +6 -0
- package/dist/astro/native/html.d.ts.map +1 -0
- package/dist/astro/native/html.js +10 -0
- package/dist/astro/native/html.js.map +1 -0
- package/dist/astro/native/html.ts +9 -0
- package/dist/astro/native/icon.d.ts +3 -0
- package/dist/astro/native/icon.d.ts.map +1 -0
- package/dist/astro/native/icon.js +23 -0
- package/dist/astro/native/icon.js.map +1 -0
- package/dist/astro/native/icon.ts +21 -0
- package/dist/astro/native/map.d.ts +14 -0
- package/dist/astro/native/map.d.ts.map +1 -0
- package/dist/astro/native/map.js +60 -0
- package/dist/astro/native/map.js.map +1 -0
- package/dist/astro/native/map.ts +70 -0
- package/dist/astro/native/motion-preference.d.ts +50 -0
- package/dist/astro/native/motion-preference.d.ts.map +1 -0
- package/dist/astro/native/motion-preference.js +132 -0
- package/dist/astro/native/motion-preference.js.map +1 -0
- package/dist/astro/native/motion-preference.ts +158 -0
- package/dist/astro/native/motion.d.ts +101 -0
- package/dist/astro/native/motion.d.ts.map +1 -0
- package/dist/astro/native/motion.js +168 -0
- package/dist/astro/native/motion.js.map +1 -0
- package/dist/astro/native/motion.ts +312 -0
- package/dist/astro/native/query-loop.d.ts +38 -0
- package/dist/astro/native/query-loop.d.ts.map +1 -0
- package/dist/astro/native/query-loop.js +20 -0
- package/dist/astro/native/query-loop.js.map +1 -0
- package/dist/astro/native/query-loop.ts +67 -0
- package/dist/astro/native/registry.d.ts +3 -0
- package/dist/astro/native/registry.d.ts.map +1 -0
- package/dist/astro/native/registry.js +72 -0
- package/dist/astro/native/registry.js.map +1 -0
- package/dist/astro/native/registry.ts +72 -0
- package/dist/astro/native/sf-block-binding.astro +20 -0
- package/dist/astro/native/sf-post-field.astro +9 -0
- package/dist/astro/native/sf-term-field.astro +9 -0
- package/dist/astro/native/timeline.css +4 -0
- package/dist/astro/native/timeline.d.ts +28 -0
- package/dist/astro/native/timeline.d.ts.map +1 -0
- package/dist/astro/native/timeline.js +43 -0
- package/dist/astro/native/timeline.js.map +1 -0
- package/dist/astro/native/timeline.ts +79 -0
- package/dist/block-renderers.d.ts +3 -3
- package/dist/block-renderers.d.ts.map +1 -1
- package/dist/block-renderers.js.map +1 -1
- package/dist/default-blocks.d.ts +1 -1
- package/dist/default-blocks.d.ts.map +1 -1
- package/dist/default-blocks.js +36 -2
- package/dist/default-blocks.js.map +1 -1
- package/dist/media.d.ts +13 -0
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +72 -12
- package/dist/media.js.map +1 -1
- package/dist/templates.d.ts +16 -16
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -3
package/dist/media.js
CHANGED
|
@@ -1,5 +1,59 @@
|
|
|
1
1
|
export const FLOWPRESS_UPLOADS_PREFIX = "/app/uploads/";
|
|
2
2
|
export const FLOWPRESS_MEDIA_PREFIX = "/media/";
|
|
3
|
+
/** Keep owned media on the current frontend without changing external assets. */
|
|
4
|
+
export function rewriteFlowpressMediaUrl(value, options) {
|
|
5
|
+
try {
|
|
6
|
+
if (!value || /\s/.test(value))
|
|
7
|
+
return value;
|
|
8
|
+
const frontend = new URL(options.frontendOrigin);
|
|
9
|
+
const source = new URL(value, frontend);
|
|
10
|
+
if (!/^https?:$/.test(source.protocol) || source.username || source.password)
|
|
11
|
+
return value;
|
|
12
|
+
const backend = options.backendUrl ? new URL(options.backendUrl) : undefined;
|
|
13
|
+
const media = options.mediaUrl ? new URL(options.mediaUrl) : undefined;
|
|
14
|
+
const origins = new Set([frontend.origin, backend?.origin, ...(options.frontendUrls ?? []).map((url) => new URL(url).origin)]);
|
|
15
|
+
let pathname;
|
|
16
|
+
if (origins.has(source.origin) && (isFlowpressUploadPath(source.pathname) || isFlowpressMediaPath(source.pathname))) {
|
|
17
|
+
pathname = source.pathname;
|
|
18
|
+
}
|
|
19
|
+
else if (media && media.origin !== backend?.origin && source.origin === media.origin) {
|
|
20
|
+
const base = media.pathname.replace(/\/+$/, "");
|
|
21
|
+
if (base && !source.pathname.startsWith(`${base}/`))
|
|
22
|
+
return value;
|
|
23
|
+
pathname = `${FLOWPRESS_MEDIA_PREFIX.slice(0, -1)}${source.pathname.slice(base.length)}`;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
return `${frontend.origin}${pathname}${source.search}${source.hash}`;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** Normalize JSON media data, including nested query items and responsive sources.
|
|
35
|
+
* HTML, CSS and scripts are left intact: only URL values and srcset fields change.
|
|
36
|
+
*/
|
|
37
|
+
export function rewriteFlowpressMediaUrls(value, options) {
|
|
38
|
+
function rewrite(item, key = "") {
|
|
39
|
+
if (typeof item === "string") {
|
|
40
|
+
if (/^srcset$/i.test(key)) {
|
|
41
|
+
return item.replace(/\S+/g, (token) => {
|
|
42
|
+
const url = token.replace(/,+$/, "");
|
|
43
|
+
return `${rewriteFlowpressMediaUrl(url, options)}${token.slice(url.length)}`;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return rewriteFlowpressMediaUrl(item, options);
|
|
47
|
+
}
|
|
48
|
+
if (Array.isArray(item))
|
|
49
|
+
return item.map((entry) => rewrite(entry));
|
|
50
|
+
if (item && typeof item === "object") {
|
|
51
|
+
return Object.fromEntries(Object.entries(item).map(([name, entry]) => [name, rewrite(entry, name)]));
|
|
52
|
+
}
|
|
53
|
+
return item;
|
|
54
|
+
}
|
|
55
|
+
return rewrite(value);
|
|
56
|
+
}
|
|
3
57
|
const requestHeaders = [
|
|
4
58
|
"accept",
|
|
5
59
|
"if-match",
|
|
@@ -61,20 +115,28 @@ async function proxyFlowpressAsset(request, upstreamUrl, fetchImpl, options) {
|
|
|
61
115
|
headers.set(name, value);
|
|
62
116
|
}
|
|
63
117
|
try {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
118
|
+
// Follow storage redirects on the server: Location must never reveal the
|
|
119
|
+
// backend/CDN origin to the browser or move it off the public media URL.
|
|
120
|
+
let upstream;
|
|
121
|
+
for (let redirects = 0;; redirects++) {
|
|
122
|
+
upstream = await fetchImpl(target, { method: request.method, headers, redirect: "manual" });
|
|
123
|
+
const location = upstream.headers.get("location");
|
|
124
|
+
if (![301, 302, 303, 307, 308].includes(upstream.status) || !location)
|
|
125
|
+
break;
|
|
126
|
+
await upstream.body?.cancel();
|
|
127
|
+
if (redirects >= 5)
|
|
128
|
+
throw new Error("Too many media redirects.");
|
|
129
|
+
target = new URL(location, target);
|
|
130
|
+
if (!/^https?:$/.test(target.protocol) || target.username || target.password) {
|
|
131
|
+
throw new Error("Invalid media redirect.");
|
|
132
|
+
}
|
|
133
|
+
}
|
|
69
134
|
const safeHeaders = new Headers();
|
|
70
135
|
for (const name of responseHeaders) {
|
|
71
136
|
const value = upstream.headers.get(name);
|
|
72
137
|
if (value)
|
|
73
138
|
safeHeaders.set(name, value);
|
|
74
139
|
}
|
|
75
|
-
const location = upstream.headers.get("location");
|
|
76
|
-
if (location)
|
|
77
|
-
safeHeaders.set("location", options.rewriteLocation(location, target));
|
|
78
140
|
return new Response(request.method === "HEAD" ? null : upstream.body, {
|
|
79
141
|
status: upstream.status,
|
|
80
142
|
statusText: upstream.statusText,
|
|
@@ -89,8 +151,7 @@ export function proxyFlowpressUpload(request, backendUrl, fetchImpl = fetch) {
|
|
|
89
151
|
return proxyFlowpressAsset(request, backendUrl, fetchImpl, {
|
|
90
152
|
prefix: FLOWPRESS_UPLOADS_PREFIX,
|
|
91
153
|
preserveUpstreamPath: false,
|
|
92
|
-
stripPrefix: false
|
|
93
|
-
rewriteLocation: (location) => rewriteFlowpressBackendUrl(location, backendUrl)
|
|
154
|
+
stripPrefix: false
|
|
94
155
|
});
|
|
95
156
|
}
|
|
96
157
|
/**
|
|
@@ -103,8 +164,7 @@ export function proxyFlowpressMedia(request, mediaUrl, fetchImpl = fetch) {
|
|
|
103
164
|
return proxyFlowpressAsset(request, mediaUrl, fetchImpl, {
|
|
104
165
|
prefix: FLOWPRESS_MEDIA_PREFIX,
|
|
105
166
|
preserveUpstreamPath: true,
|
|
106
|
-
stripPrefix: true
|
|
107
|
-
rewriteLocation: (location, target) => new URL(location, target).toString()
|
|
167
|
+
stripPrefix: true
|
|
108
168
|
});
|
|
109
169
|
}
|
|
110
170
|
function assetTarget(requestUrl, upstreamUrl, prefix, preserveUpstreamPath, stripPrefix) {
|
package/dist/media.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"media.js","sourceRoot":"","sources":["../src/media.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,wBAAwB,GAAG,eAAe,CAAC;AACxD,MAAM,CAAC,MAAM,sBAAsB,GAAG,SAAS,CAAC;AAEhD,MAAM,cAAc,GAAG;IACrB,QAAQ;IACR,UAAU;IACV,mBAAmB;IACnB,eAAe;IACf,qBAAqB;IACrB,OAAO;CACC,CAAC;AAEX,MAAM,eAAe,GAAG;IACtB,eAAe;IACf,eAAe;IACf,qBAAqB;IACrB,kBAAkB;IAClB,gBAAgB;IAChB,eAAe;IACf,cAAc;IACd,MAAM;IACN,eAAe;IACf,MAAM;CACE,CAAC;AAEX,MAAM,UAAU,qBAAqB,CAAC,QAAgB;IACpD,OAAO,QAAQ,KAAK,wBAAwB,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;WACpD,QAAQ,CAAC,UAAU,CAAC,wBAAwB,CAAC,CAAC;AACrD,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,QAAgB;IACnD,OAAO,QAAQ,KAAK,sBAAsB,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;WAClD,QAAQ,CAAC,UAAU,CAAC,sBAAsB,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,0BAA0B,CACxC,KAAa,EACb,UAAkB,EAClB,cAAc,GAAG,EAAE;IAEnB,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;QAC9B,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC;QACpC,IAAI,MAAM,CAAC,MAAM,KAAK,OAAO,CAAC,MAAM;YAAE,OAAO,KAAK,CAAC;QACnD,OAAO,GAAG,cAAc,CAAC,OAAO,CAAC,KAAK,EAA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,CAAC,MAAM,CAAC,CAAC;IACxC,MAAM,YAAY,GAAG,oBAAoB,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACvF,MAAM,CAAC,QAAQ,GAAG,GAAG,YAAY,GAAG,WAAW,EAAE,CAAC;IAClD,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC/B,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["export const FLOWPRESS_UPLOADS_PREFIX = \"/app/uploads/\";\nexport const FLOWPRESS_MEDIA_PREFIX = \"/media/\";\n\nconst requestHeaders = [\n \"accept\",\n \"if-match\",\n \"if-modified-since\",\n \"if-none-match\",\n \"if-unmodified-since\",\n \"range\"\n] as const;\n\nconst responseHeaders = [\n \"accept-ranges\",\n \"cache-control\",\n \"content-disposition\",\n \"content-encoding\",\n \"content-length\",\n \"content-range\",\n \"content-type\",\n \"etag\",\n \"last-modified\",\n \"vary\"\n] as const;\n\nexport function isFlowpressUploadPath(pathname: string): boolean {\n return pathname === FLOWPRESS_UPLOADS_PREFIX.slice(0, -1)\n || pathname.startsWith(FLOWPRESS_UPLOADS_PREFIX);\n}\n\nexport function isFlowpressMediaPath(pathname: string): boolean {\n return pathname === FLOWPRESS_MEDIA_PREFIX.slice(0, -1)\n || pathname.startsWith(FLOWPRESS_MEDIA_PREFIX);\n}\n\nexport function rewriteFlowpressBackendUrl(\n value: string,\n backendUrl: string,\n frontendOrigin = \"\"\n): string {\n try {\n const source = new URL(value);\n const backend = new URL(backendUrl);\n if (source.origin !== backend.origin) return value;\n return `${frontendOrigin.replace(/\\/$/, \"\")}${source.pathname}${source.search}${source.hash}`;\n } catch {\n return value;\n }\n}\n\ninterface AssetProxyOptions {\n prefix: string;\n preserveUpstreamPath: boolean;\n stripPrefix: boolean;\n rewriteLocation: (location: string, target: URL) => string;\n}\n\nasync function proxyFlowpressAsset(\n request: Request,\n upstreamUrl: string,\n fetchImpl: typeof fetch,\n options: AssetProxyOptions\n): Promise<Response> {\n if (request.method !== \"GET\" && request.method !== \"HEAD\") {\n return new Response(\"Method Not Allowed\", {\n status: 405,\n headers: { allow: \"GET, HEAD\" }\n });\n }\n let target: URL;\n try {\n target = assetTarget(\n request.url,\n upstreamUrl,\n options.prefix,\n options.preserveUpstreamPath,\n options.stripPrefix\n );\n } catch {\n return new Response(\"Bad Gateway\", { status: 502 });\n }\n\n const headers = new Headers();\n for (const name of requestHeaders) {\n const value = request.headers.get(name);\n if (value) headers.set(name, value);\n }\n try {\n const upstream = await fetchImpl(target, {\n method: request.method,\n headers,\n redirect: \"manual\"\n });\n const safeHeaders = new Headers();\n for (const name of responseHeaders) {\n const value = upstream.headers.get(name);\n if (value) safeHeaders.set(name, value);\n }\n const location = upstream.headers.get(\"location\");\n if (location) safeHeaders.set(\"location\", options.rewriteLocation(location, target));\n return new Response(request.method === \"HEAD\" ? null : upstream.body, {\n status: upstream.status,\n statusText: upstream.statusText,\n headers: safeHeaders\n });\n } catch {\n return new Response(\"Bad Gateway\", { status: 502 });\n }\n}\n\nexport function proxyFlowpressUpload(\n request: Request,\n backendUrl: string,\n fetchImpl: typeof fetch = fetch\n): Promise<Response> {\n return proxyFlowpressAsset(request, backendUrl, fetchImpl, {\n prefix: FLOWPRESS_UPLOADS_PREFIX,\n preserveUpstreamPath: false,\n stripPrefix: false,\n rewriteLocation: (location) => rewriteFlowpressBackendUrl(location, backendUrl)\n });\n}\n\n/**\n * Proxy /media/<path> to the current FLOWPRESS_MEDIA origin (an offload CDN,\n * or the WordPress backend as a fallback). /media/ is a frontend-only routing\n * marker with no equivalent on either upstream, so it is stripped before the\n * request is forwarded: /media/2026/09/x.jpg becomes <origin>/2026/09/x.jpg.\n */\nexport function proxyFlowpressMedia(\n request: Request,\n mediaUrl: string,\n fetchImpl: typeof fetch = fetch\n): Promise<Response> {\n return proxyFlowpressAsset(request, mediaUrl, fetchImpl, {\n prefix: FLOWPRESS_MEDIA_PREFIX,\n preserveUpstreamPath: true,\n stripPrefix: true,\n rewriteLocation: (location, target) => new URL(location, target).toString()\n });\n}\n\nfunction assetTarget(\n requestUrl: string,\n upstreamUrl: string,\n prefix: string,\n preserveUpstreamPath: boolean,\n stripPrefix: boolean\n): URL {\n const request = new URL(requestUrl);\n if (request.pathname !== prefix.slice(0, -1) && !request.pathname.startsWith(prefix)) {\n throw new Error(\"Unsupported FlowPress asset path.\");\n }\n const upstream = new URL(upstreamUrl);\n if (\n !/^https?:$/.test(upstream.protocol)\n || upstream.username\n || upstream.password\n || upstream.search\n || upstream.hash\n ) {\n throw new Error(\"Invalid FlowPress asset upstream.\");\n }\n const requestPath = stripPrefix\n ? request.pathname.slice(prefix.length - 1) || \"/\"\n : request.pathname;\n const target = new URL(upstream.origin);\n const upstreamPath = preserveUpstreamPath ? upstream.pathname.replace(/\\/+$/, \"\") : \"\";\n target.pathname = `${upstreamPath}${requestPath}`;\n target.search = request.search;\n return target;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"media.js","sourceRoot":"","sources":["../src/media.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,wBAAwB,GAAG,eAAe,CAAC;AACxD,MAAM,CAAC,MAAM,sBAAsB,GAAG,SAAS,CAAC;AAUhD,iFAAiF;AACjF,MAAM,UAAU,wBAAwB,CACtC,KAAa,EACb,OAAsC;IAEtC,IAAI,CAAC;QACH,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QAC7C,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QACjD,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QACxC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,QAAQ,IAAI,MAAM,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jB,QAAQ,CAAC,MAAM;WACf,QAAQ,CAAC,IAAI,EAChB,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IACvD,CAAC;IACD,MAAM,WAAW,GAAG,WAAW;QAC7B,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,GAAG;QAClD,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;IACrB,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IACxC,MAAM,YAAY,GAAG,oBAAoB,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IACvF,MAAM,CAAC,QAAQ,GAAG,GAAG,YAAY,GAAG,WAAW,EAAE,CAAC;IAClD,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC/B,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["export const FLOWPRESS_UPLOADS_PREFIX = \"/app/uploads/\";\nexport const FLOWPRESS_MEDIA_PREFIX = \"/media/\";\n\nexport interface FlowpressFrontendMediaOptions {\n frontendOrigin: string;\n backendUrl?: string | undefined;\n mediaUrl?: string | undefined;\n /** Canonical frontend URLs and aliases owned by the selected backend. */\n frontendUrls?: readonly string[] | undefined;\n}\n\n/** Keep owned media on the current frontend without changing external assets. */\nexport function rewriteFlowpressMediaUrl(\n value: string,\n options: FlowpressFrontendMediaOptions\n): string {\n try {\n if (!value || /\\s/.test(value)) return value;\n const frontend = new URL(options.frontendOrigin);\n const source = new URL(value, frontend);\n if (!/^https?:$/.test(source.protocol) || source.username || source.password) return value;\n const backend = options.backendUrl ? new URL(options.backendUrl) : undefined;\n const media = options.mediaUrl ? new URL(options.mediaUrl) : undefined;\n const origins = new Set([frontend.origin, backend?.origin, ...(options.frontendUrls ?? []).map((url) => new URL(url).origin)]);\n let pathname: string;\n if (origins.has(source.origin) && (isFlowpressUploadPath(source.pathname) || isFlowpressMediaPath(source.pathname))) {\n pathname = source.pathname;\n } else if (media && media.origin !== backend?.origin && source.origin === media.origin) {\n const base = media.pathname.replace(/\\/+$/, \"\");\n if (base && !source.pathname.startsWith(`${base}/`)) return value;\n pathname = `${FLOWPRESS_MEDIA_PREFIX.slice(0, -1)}${source.pathname.slice(base.length)}`;\n } else {\n return value;\n }\n return `${frontend.origin}${pathname}${source.search}${source.hash}`;\n } catch {\n return value;\n }\n}\n\n/** Normalize JSON media data, including nested query items and responsive sources.\n * HTML, CSS and scripts are left intact: only URL values and srcset fields change.\n */\nexport function rewriteFlowpressMediaUrls<T>(\n value: T,\n options: FlowpressFrontendMediaOptions\n): T {\n function rewrite(item: unknown, key = \"\"): unknown {\n if (typeof item === \"string\") {\n if (/^srcset$/i.test(key)) {\n return item.replace(/\\S+/g, (token) => {\n const url = token.replace(/,+$/, \"\");\n return `${rewriteFlowpressMediaUrl(url, options)}${token.slice(url.length)}`;\n });\n }\n return rewriteFlowpressMediaUrl(item, options);\n }\n if (Array.isArray(item)) return item.map((entry) => rewrite(entry));\n if (item && typeof item === \"object\") {\n return Object.fromEntries(Object.entries(item).map(([name, entry]) => [name, rewrite(entry, name)]));\n }\n return item;\n }\n return rewrite(value) as T;\n}\n\nconst requestHeaders = [\n \"accept\",\n \"if-match\",\n \"if-modified-since\",\n \"if-none-match\",\n \"if-unmodified-since\",\n \"range\"\n] as const;\n\nconst responseHeaders = [\n \"accept-ranges\",\n \"cache-control\",\n \"content-disposition\",\n \"content-encoding\",\n \"content-length\",\n \"content-range\",\n \"content-type\",\n \"etag\",\n \"last-modified\",\n \"vary\"\n] as const;\n\nexport function isFlowpressUploadPath(pathname: string): boolean {\n return pathname === FLOWPRESS_UPLOADS_PREFIX.slice(0, -1)\n || pathname.startsWith(FLOWPRESS_UPLOADS_PREFIX);\n}\n\nexport function isFlowpressMediaPath(pathname: string): boolean {\n return pathname === FLOWPRESS_MEDIA_PREFIX.slice(0, -1)\n || pathname.startsWith(FLOWPRESS_MEDIA_PREFIX);\n}\n\nexport function rewriteFlowpressBackendUrl(\n value: string,\n backendUrl: string,\n frontendOrigin = \"\"\n): string {\n try {\n const source = new URL(value);\n const backend = new URL(backendUrl);\n if (source.origin !== backend.origin) return value;\n return `${frontendOrigin.replace(/\\/$/, \"\")}${source.pathname}${source.search}${source.hash}`;\n } catch {\n return value;\n }\n}\n\ninterface AssetProxyOptions {\n prefix: string;\n preserveUpstreamPath: boolean;\n stripPrefix: boolean;\n}\n\nasync function proxyFlowpressAsset(\n request: Request,\n upstreamUrl: string,\n fetchImpl: typeof fetch,\n options: AssetProxyOptions\n): Promise<Response> {\n if (request.method !== \"GET\" && request.method !== \"HEAD\") {\n return new Response(\"Method Not Allowed\", {\n status: 405,\n headers: { allow: \"GET, HEAD\" }\n });\n }\n let target: URL;\n try {\n target = assetTarget(\n request.url,\n upstreamUrl,\n options.prefix,\n options.preserveUpstreamPath,\n options.stripPrefix\n );\n } catch {\n return new Response(\"Bad Gateway\", { status: 502 });\n }\n\n const headers = new Headers();\n for (const name of requestHeaders) {\n const value = request.headers.get(name);\n if (value) headers.set(name, value);\n }\n try {\n // Follow storage redirects on the server: Location must never reveal the\n // backend/CDN origin to the browser or move it off the public media URL.\n let upstream: Response;\n for (let redirects = 0; ; redirects++) {\n upstream = await fetchImpl(target, { method: request.method, headers, redirect: \"manual\" });\n const location = upstream.headers.get(\"location\");\n if (![301, 302, 303, 307, 308].includes(upstream.status) || !location) break;\n await upstream.body?.cancel();\n if (redirects >= 5) throw new Error(\"Too many media redirects.\");\n target = new URL(location, target);\n if (!/^https?:$/.test(target.protocol) || target.username || target.password) {\n throw new Error(\"Invalid media redirect.\");\n }\n }\n const safeHeaders = new Headers();\n for (const name of responseHeaders) {\n const value = upstream.headers.get(name);\n if (value) safeHeaders.set(name, value);\n }\n return new Response(request.method === \"HEAD\" ? null : upstream.body, {\n status: upstream.status,\n statusText: upstream.statusText,\n headers: safeHeaders\n });\n } catch {\n return new Response(\"Bad Gateway\", { status: 502 });\n }\n}\n\nexport function proxyFlowpressUpload(\n request: Request,\n backendUrl: string,\n fetchImpl: typeof fetch = fetch\n): Promise<Response> {\n return proxyFlowpressAsset(request, backendUrl, fetchImpl, {\n prefix: FLOWPRESS_UPLOADS_PREFIX,\n preserveUpstreamPath: false,\n stripPrefix: false\n });\n}\n\n/**\n * Proxy /media/<path> to the current FLOWPRESS_MEDIA origin (an offload CDN,\n * or the WordPress backend as a fallback). /media/ is a frontend-only routing\n * marker with no equivalent on either upstream, so it is stripped before the\n * request is forwarded: /media/2026/09/x.jpg becomes <origin>/2026/09/x.jpg.\n */\nexport function proxyFlowpressMedia(\n request: Request,\n mediaUrl: string,\n fetchImpl: typeof fetch = fetch\n): Promise<Response> {\n return proxyFlowpressAsset(request, mediaUrl, fetchImpl, {\n prefix: FLOWPRESS_MEDIA_PREFIX,\n preserveUpstreamPath: true,\n stripPrefix: true\n });\n}\n\nfunction assetTarget(\n requestUrl: string,\n upstreamUrl: string,\n prefix: string,\n preserveUpstreamPath: boolean,\n stripPrefix: boolean\n): URL {\n const request = new URL(requestUrl);\n if (request.pathname !== prefix.slice(0, -1) && !request.pathname.startsWith(prefix)) {\n throw new Error(\"Unsupported FlowPress asset path.\");\n }\n const upstream = new URL(upstreamUrl);\n if (\n !/^https?:$/.test(upstream.protocol)\n || upstream.username\n || upstream.password\n || upstream.search\n || upstream.hash\n ) {\n throw new Error(\"Invalid FlowPress asset upstream.\");\n }\n const requestPath = stripPrefix\n ? request.pathname.slice(prefix.length - 1) || \"/\"\n : request.pathname;\n const target = new URL(upstream.origin);\n const upstreamPath = preserveUpstreamPath ? upstream.pathname.replace(/\\/+$/, \"\") : \"\";\n target.pathname = `${upstreamPath}${requestPath}`;\n target.search = request.search;\n return target;\n}\n"]}
|
package/dist/templates.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
export declare const coreTemplates: {
|
|
2
|
-
readonly index:
|
|
3
|
-
readonly singular:
|
|
4
|
-
readonly single:
|
|
5
|
-
readonly page:
|
|
6
|
-
readonly archive:
|
|
7
|
-
readonly taxonomy:
|
|
8
|
-
readonly category:
|
|
9
|
-
readonly tag:
|
|
10
|
-
readonly author:
|
|
11
|
-
readonly date:
|
|
12
|
-
readonly search:
|
|
13
|
-
readonly home:
|
|
14
|
-
readonly attachment:
|
|
15
|
-
readonly embed:
|
|
16
|
-
readonly "privacy-policy":
|
|
17
|
-
readonly "404":
|
|
2
|
+
readonly index: import("astro/runtime/server/index.js").AstroComponentFactory;
|
|
3
|
+
readonly singular: import("astro/runtime/server/index.js").AstroComponentFactory;
|
|
4
|
+
readonly single: import("astro/runtime/server/index.js").AstroComponentFactory;
|
|
5
|
+
readonly page: import("astro/runtime/server/index.js").AstroComponentFactory;
|
|
6
|
+
readonly archive: import("astro/runtime/server/index.js").AstroComponentFactory;
|
|
7
|
+
readonly taxonomy: import("astro/runtime/server/index.js").AstroComponentFactory;
|
|
8
|
+
readonly category: import("astro/runtime/server/index.js").AstroComponentFactory;
|
|
9
|
+
readonly tag: import("astro/runtime/server/index.js").AstroComponentFactory;
|
|
10
|
+
readonly author: import("astro/runtime/server/index.js").AstroComponentFactory;
|
|
11
|
+
readonly date: import("astro/runtime/server/index.js").AstroComponentFactory;
|
|
12
|
+
readonly search: import("astro/runtime/server/index.js").AstroComponentFactory;
|
|
13
|
+
readonly home: import("astro/runtime/server/index.js").AstroComponentFactory;
|
|
14
|
+
readonly attachment: import("astro/runtime/server/index.js").AstroComponentFactory;
|
|
15
|
+
readonly embed: import("astro/runtime/server/index.js").AstroComponentFactory;
|
|
16
|
+
readonly "privacy-policy": import("astro/runtime/server/index.js").AstroComponentFactory;
|
|
17
|
+
readonly "404": import("astro/runtime/server/index.js").AstroComponentFactory;
|
|
18
18
|
};
|
|
19
19
|
//# sourceMappingURL=templates.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../src/astro.d.ts","../src/block-renderers.ts","../src/carousel.ts","../src/client.ts","../src/composition.ts","../src/default-blocks.ts","../src/env.ts","../src/index.ts","../src/links.ts","../src/media.ts","../src/number-spinner.ts","../src/style-classes.ts","../src/styleflow.ts","../src/template-hierarchy.ts","../src/templates.ts","../src/theme-runtime.ts","../src/types.ts","../src/astro/blocks/cover.ts","../src/astro/blocks/helpers.ts"],"version":"5.9.3"}
|
|
1
|
+
{"root":["../src/astro.d.ts","../src/block-renderers.ts","../src/carousel.ts","../src/client.ts","../src/composition.ts","../src/default-blocks.ts","../src/env.ts","../src/index.ts","../src/links.ts","../src/media.ts","../src/number-spinner.ts","../src/style-classes.ts","../src/styleflow.ts","../src/template-hierarchy.ts","../src/templates.ts","../src/theme-runtime.ts","../src/types.ts","../src/astro/blocks/cover.ts","../src/astro/blocks/helpers.ts","../src/astro/native/button.ts","../src/astro/native/flowpress-navigation-controller.ts","../src/astro/native/grid.ts","../src/astro/native/html.ts","../src/astro/native/icon.ts","../src/astro/native/map.ts","../src/astro/native/motion-preference.ts","../src/astro/native/motion.ts","../src/astro/native/query-loop.ts","../src/astro/native/registry.ts","../src/astro/native/timeline.ts","../src/astro/native/blob/blob-shapes.generated.ts","../src/astro/native/blob/config.ts","../src/astro/native/blob/controller.ts","../src/astro/native/blob/geometry.ts","../src/astro/native/blob/ids.ts"],"version":"5.9.3"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@styleflow.app/flowpress-astro-core",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.17",
|
|
4
4
|
"description": "Project-agnostic WordPress routing, templates, SEO and GraphQL runtime for FlowPress Astro apps.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
"./ThemeRuntime.astro": "./dist/astro/ThemeRuntime.astro",
|
|
34
34
|
"./blocks/ThemeToggleBlock.astro": "./dist/astro/blocks/ThemeToggleBlock.astro",
|
|
35
35
|
"./blocks/CoverBlock.astro": "./dist/astro/blocks/CoverBlock.astro",
|
|
36
|
-
"./blocks/SiteLogoBlock.astro": "./dist/astro/blocks/SiteLogoBlock.astro"
|
|
36
|
+
"./blocks/SiteLogoBlock.astro": "./dist/astro/blocks/SiteLogoBlock.astro",
|
|
37
|
+
"./native/*": "./dist/astro/native/*"
|
|
37
38
|
},
|
|
38
39
|
"files": [
|
|
39
40
|
"dist",
|
|
@@ -52,7 +53,8 @@
|
|
|
52
53
|
},
|
|
53
54
|
"dependencies": {
|
|
54
55
|
"@splidejs/splide": "4.1.4",
|
|
55
|
-
"@styleflow.app/astro": "1.0.0-beta.
|
|
56
|
+
"@styleflow.app/astro": "1.0.0-beta.8",
|
|
57
|
+
"@styleflow.app/flowpress-components": "1.0.0-beta.9"
|
|
56
58
|
},
|
|
57
59
|
"peerDependencies": {
|
|
58
60
|
"astro": ">=7.0.0"
|