@styleflow.app/flowpress-astro-core 1.0.0-beta.16 → 1.0.0-beta.19
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 +17 -0
- package/README.md +4 -0
- package/dist/astro/BaseLayout.astro +6 -6
- package/dist/astro/CompositionRenderer.astro +14 -9
- package/dist/astro/GutenbergRenderer.astro +50 -35
- 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/client.d.ts +16 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +23 -4
- package/dist/client.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 +4 -3
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +56 -36
- 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/default-blocks.js
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
|
-
export const FLOWPRESS_DEFAULT_BLOCK_CATALOG_VERSION = "
|
|
1
|
+
export const FLOWPRESS_DEFAULT_BLOCK_CATALOG_VERSION = "3";
|
|
2
2
|
const blockNames = [
|
|
3
|
+
"core/term-name",
|
|
4
|
+
"core/post-terms",
|
|
5
|
+
"core/button",
|
|
6
|
+
"core/post-date",
|
|
7
|
+
"core/icon",
|
|
8
|
+
"core/post-excerpt",
|
|
9
|
+
"core/term-description",
|
|
10
|
+
"core/post-template",
|
|
11
|
+
"core/html",
|
|
12
|
+
"core/block",
|
|
13
|
+
"core/site-title",
|
|
14
|
+
"core/post-featured-image",
|
|
15
|
+
"core/page-list",
|
|
16
|
+
"core/terms-query",
|
|
17
|
+
"core/buttons",
|
|
18
|
+
"core/image",
|
|
19
|
+
"core/query-no-results",
|
|
20
|
+
"core/term-template",
|
|
21
|
+
"core/navigation",
|
|
22
|
+
"core/navigation-submenu",
|
|
23
|
+
"core/query",
|
|
24
|
+
"core/home-link",
|
|
25
|
+
"core/page-list-item",
|
|
26
|
+
"core/navigation-link",
|
|
27
|
+
"core/post-title",
|
|
28
|
+
"sf/post-field",
|
|
29
|
+
"project/post-field",
|
|
30
|
+
"sf/block-binding",
|
|
31
|
+
"project/block-binding",
|
|
32
|
+
"sf/term-field",
|
|
33
|
+
"project/term-field",
|
|
34
|
+
"sf/timeline",
|
|
3
35
|
"core/cover",
|
|
4
36
|
"core/group",
|
|
5
37
|
"core/heading",
|
|
@@ -23,6 +55,8 @@ const blockNames = [
|
|
|
23
55
|
"sf/hero",
|
|
24
56
|
"sf/icon",
|
|
25
57
|
"sf/image",
|
|
58
|
+
"sf/blob",
|
|
59
|
+
"sf/timeline-card",
|
|
26
60
|
"sf/map",
|
|
27
61
|
"sf/number-spinner",
|
|
28
62
|
"sf/quote",
|
|
@@ -33,7 +67,7 @@ const blockNames = [
|
|
|
33
67
|
"sf/video",
|
|
34
68
|
"sf/video-youtube"
|
|
35
69
|
];
|
|
36
|
-
export const flowpressDefaultBlockCatalog = blockNames.map((blockName) => ({ blockName, template: "DefaultBlockAdapter.astro" }));
|
|
70
|
+
export const flowpressDefaultBlockCatalog = [...blockNames].sort().map((blockName) => ({ blockName, template: "DefaultBlockAdapter.astro" }));
|
|
37
71
|
const supported = new Set(blockNames);
|
|
38
72
|
export function hasFlowpressDefaultBlockAdapter(blockName) {
|
|
39
73
|
return supported.has(blockName);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-blocks.js","sourceRoot":"","sources":["../src/default-blocks.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,uCAAuC,GAAG,GAAY,CAAC;AAOpE,MAAM,UAAU,GAAG;IACjB,YAAY;IACZ,YAAY;IACZ,cAAc;IACd,WAAW;IACX,gBAAgB;IAChB,gBAAgB;IAChB,YAAY;IACZ,mBAAmB;IACnB,WAAW;IACX,SAAS;IACT,aAAa;IACb,kBAAkB;IAClB,SAAS;IACT,SAAS;IACT,WAAW;IACX,iBAAiB;IACjB,SAAS;IACT,YAAY;IACZ,SAAS;IACT,YAAY;IACZ,SAAS;IACT,SAAS;IACT,UAAU;IACV,QAAQ;IACR,mBAAmB;IACnB,UAAU;IACV,cAAc;IACd,YAAY;IACZ,aAAa;IACb,cAAc;IACd,UAAU;IACV,kBAAkB;CACV,CAAC;AAEX,MAAM,CAAC,MAAM,4BAA4B,GACvC,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,2BAA2B,EAAE,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"default-blocks.js","sourceRoot":"","sources":["../src/default-blocks.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,uCAAuC,GAAG,GAAY,CAAC;AAOpE,MAAM,UAAU,GAAG;IACjB,gBAAgB;IAChB,iBAAiB;IACjB,aAAa;IACb,gBAAgB;IAChB,WAAW;IACX,mBAAmB;IACnB,uBAAuB;IACvB,oBAAoB;IACpB,WAAW;IACX,YAAY;IACZ,iBAAiB;IACjB,0BAA0B;IAC1B,gBAAgB;IAChB,kBAAkB;IAClB,cAAc;IACd,YAAY;IACZ,uBAAuB;IACvB,oBAAoB;IACpB,iBAAiB;IACjB,yBAAyB;IACzB,YAAY;IACZ,gBAAgB;IAChB,qBAAqB;IACrB,sBAAsB;IACtB,iBAAiB;IACjB,eAAe;IACf,oBAAoB;IACpB,kBAAkB;IAClB,uBAAuB;IACvB,eAAe;IACf,oBAAoB;IACpB,aAAa;IACb,YAAY;IACZ,YAAY;IACZ,cAAc;IACd,WAAW;IACX,gBAAgB;IAChB,gBAAgB;IAChB,YAAY;IACZ,mBAAmB;IACnB,WAAW;IACX,SAAS;IACT,aAAa;IACb,kBAAkB;IAClB,SAAS;IACT,SAAS;IACT,WAAW;IACX,iBAAiB;IACjB,SAAS;IACT,YAAY;IACZ,SAAS;IACT,YAAY;IACZ,SAAS;IACT,SAAS;IACT,UAAU;IACV,SAAS;IACT,kBAAkB;IAClB,QAAQ;IACR,mBAAmB;IACnB,UAAU;IACV,cAAc;IACd,YAAY;IACZ,aAAa;IACb,cAAc;IACd,UAAU;IACV,kBAAkB;CACV,CAAC;AAEX,MAAM,CAAC,MAAM,4BAA4B,GACvC,CAAC,GAAG,UAAU,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,2BAA2B,EAAE,CAAC,CAAC,CAAC;AAEpG,MAAM,SAAS,GAAG,IAAI,GAAG,CAAS,UAAU,CAAC,CAAC;AAE9C,MAAM,UAAU,+BAA+B,CAAC,SAAiB;IAC/D,OAAO,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,wCAAwC,CAAC,SAAiB;IACxE,IAAI,CAAC,+BAA+B,CAAC,SAAS,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CAAC,iDAAiD,SAAS,GAAG,CAAC,CAAC;IACjF,CAAC;IACD,IAAI,SAAS,KAAK,YAAY,EAAE,CAAC;QAC/B,OAAO;;;;;;;;;;;;;;;CAeV,CAAC;IACA,CAAC;IACD,OAAO;;;;;;;;CAQR,CAAC;AACF,CAAC","sourcesContent":["export const FLOWPRESS_DEFAULT_BLOCK_CATALOG_VERSION = \"3\" as const;\n\nexport interface FlowpressDefaultBlockCatalogEntry {\n blockName: string;\n template: \"DefaultBlockAdapter.astro\";\n}\n\nconst blockNames = [\n \"core/term-name\",\n \"core/post-terms\",\n \"core/button\",\n \"core/post-date\",\n \"core/icon\",\n \"core/post-excerpt\",\n \"core/term-description\",\n \"core/post-template\",\n \"core/html\",\n \"core/block\",\n \"core/site-title\",\n \"core/post-featured-image\",\n \"core/page-list\",\n \"core/terms-query\",\n \"core/buttons\",\n \"core/image\",\n \"core/query-no-results\",\n \"core/term-template\",\n \"core/navigation\",\n \"core/navigation-submenu\",\n \"core/query\",\n \"core/home-link\",\n \"core/page-list-item\",\n \"core/navigation-link\",\n \"core/post-title\",\n \"sf/post-field\",\n \"project/post-field\",\n \"sf/block-binding\",\n \"project/block-binding\",\n \"sf/term-field\",\n \"project/term-field\",\n \"sf/timeline\",\n \"core/cover\",\n \"core/group\",\n \"core/heading\",\n \"core/list\",\n \"core/list-item\",\n \"core/paragraph\",\n \"core/quote\",\n \"sf/accordion-item\",\n \"sf/button\",\n \"sf/card\",\n \"sf/carousel\",\n \"sf/carousel-item\",\n \"sf/chip\",\n \"sf/code\",\n \"sf/column\",\n \"sf/content-list\",\n \"sf/form\",\n \"sf/gallery\",\n \"sf/grid\",\n \"sf/heading\",\n \"sf/hero\",\n \"sf/icon\",\n \"sf/image\",\n \"sf/blob\",\n \"sf/timeline-card\",\n \"sf/map\",\n \"sf/number-spinner\",\n \"sf/quote\",\n \"sf/rich-text\",\n \"sf/section\",\n \"sf/template\",\n \"sf/term-list\",\n \"sf/video\",\n \"sf/video-youtube\"\n] as const;\n\nexport const flowpressDefaultBlockCatalog: readonly FlowpressDefaultBlockCatalogEntry[] =\n [...blockNames].sort().map((blockName) => ({ blockName, template: \"DefaultBlockAdapter.astro\" }));\n\nconst supported = new Set<string>(blockNames);\n\nexport function hasFlowpressDefaultBlockAdapter(blockName: string): boolean {\n return supported.has(blockName);\n}\n\nexport function createFlowpressDefaultBlockAdapterSource(blockName: string): string {\n if (!hasFlowpressDefaultBlockAdapter(blockName)) {\n throw new Error(`FlowPress has no official default adapter for ${blockName}.`);\n }\n if (blockName === \"core/cover\") {\n return `---\nimport CoverBlock from \"@styleflow.app/flowpress-astro-core/blocks/CoverBlock.astro\";\nimport type { FlowpressBlockRendererProps } from \"@styleflow.app/flowpress-astro-core\";\n\nconst { block, contract, htmlProps, styleflowProps } = Astro.props as FlowpressBlockRendererProps;\n---\n\n<CoverBlock\n block={block}\n contract={contract}\n htmlProps={htmlProps}\n styleflowProps={styleflowProps}\n>\n <slot />\n</CoverBlock>\n`;\n }\n return `---\nimport DefaultBlockAdapter from \"@styleflow.app/flowpress-astro-core/DefaultBlockAdapter.astro\";\nimport type { FlowpressBlockRendererProps } from \"@styleflow.app/flowpress-astro-core\";\n\nconst props = Astro.props as FlowpressBlockRendererProps;\n---\n\n<DefaultBlockAdapter {...props} />\n`;\n}\n"]}
|
package/dist/media.d.ts
CHANGED
|
@@ -7,15 +7,15 @@ export interface FlowpressFrontendMediaOptions {
|
|
|
7
7
|
/** Canonical frontend URLs and aliases owned by the selected backend. */
|
|
8
8
|
frontendUrls?: readonly string[] | undefined;
|
|
9
9
|
}
|
|
10
|
-
/** Keep owned media on the current frontend without changing external assets. */
|
|
11
10
|
export declare function rewriteFlowpressMediaUrl(value: string, options: FlowpressFrontendMediaOptions): string;
|
|
12
|
-
/** Normalize
|
|
13
|
-
* HTML, CSS and scripts
|
|
11
|
+
/** Normalize media data once, sharing unchanged branches and parsing origins
|
|
12
|
+
* once per payload. HTML, CSS and scripts remain intact.
|
|
14
13
|
*/
|
|
15
14
|
export declare function rewriteFlowpressMediaUrls<T>(value: T, options: FlowpressFrontendMediaOptions): T;
|
|
16
15
|
export declare function isFlowpressUploadPath(pathname: string): boolean;
|
|
17
16
|
export declare function isFlowpressMediaPath(pathname: string): boolean;
|
|
18
17
|
export declare function rewriteFlowpressBackendUrl(value: string, backendUrl: string, frontendOrigin?: string): string;
|
|
18
|
+
/** @deprecated Deliver media directly from WordPress or storage. Kept for existing consumers. */
|
|
19
19
|
export declare function proxyFlowpressUpload(request: Request, backendUrl: string, fetchImpl?: typeof fetch): Promise<Response>;
|
|
20
20
|
/**
|
|
21
21
|
* Proxy /media/<path> to the current FLOWPRESS_MEDIA origin (an offload CDN,
|
|
@@ -23,5 +23,6 @@ export declare function proxyFlowpressUpload(request: Request, backendUrl: strin
|
|
|
23
23
|
* marker with no equivalent on either upstream, so it is stripped before the
|
|
24
24
|
* request is forwarded: /media/2026/09/x.jpg becomes <origin>/2026/09/x.jpg.
|
|
25
25
|
*/
|
|
26
|
+
/** @deprecated Deliver media directly from storage. Kept for existing consumers. */
|
|
26
27
|
export declare function proxyFlowpressMedia(request: Request, mediaUrl: string, fetchImpl?: typeof fetch): Promise<Response>;
|
|
27
28
|
//# sourceMappingURL=media.d.ts.map
|
package/dist/media.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../src/media.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wBAAwB,kBAAkB,CAAC;AACxD,eAAO,MAAM,sBAAsB,YA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CAAC,CAMnB;AAED;;;;;GAKG;AACH,oFAAoF;AACpF,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,EAChB,SAAS,GAAE,OAAO,KAAa,GAC9B,OAAO,CAAC,QAAQ,CAAC,CAMnB"}
|
package/dist/media.js
CHANGED
|
@@ -1,54 +1,72 @@
|
|
|
1
1
|
export const FLOWPRESS_UPLOADS_PREFIX = "/app/uploads/";
|
|
2
2
|
export const FLOWPRESS_MEDIA_PREFIX = "/media/";
|
|
3
|
-
/**
|
|
4
|
-
|
|
3
|
+
/** Resolve legacy frontend media aliases to their real origin. Absolute URLs
|
|
4
|
+
* supplied by WordPress/offload plugins remain authoritative, even in a mixed
|
|
5
|
+
* library. FLOWPRESS_MEDIA is only used to undo the old /media/ alias.
|
|
6
|
+
*/
|
|
7
|
+
function mediaResolver(options) {
|
|
5
8
|
try {
|
|
6
|
-
if (!value || /\s/.test(value))
|
|
7
|
-
return value;
|
|
8
9
|
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
10
|
const backend = options.backendUrl ? new URL(options.backendUrl) : undefined;
|
|
13
|
-
const media = options.mediaUrl ? new URL(options.mediaUrl) :
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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}/`))
|
|
11
|
+
const media = options.mediaUrl ? new URL(options.mediaUrl) : backend;
|
|
12
|
+
const frontends = new Set([frontend.origin, ...(options.frontendUrls ?? []).map((url) => new URL(url).origin)]);
|
|
13
|
+
return (value) => {
|
|
14
|
+
// Most JSON strings are labels, HTML or CSS: avoid parsing these as URLs.
|
|
15
|
+
if (!value || /\s/.test(value) || !/^(?:https?:\/\/|\/)/i.test(value))
|
|
22
16
|
return value;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
try {
|
|
18
|
+
const source = new URL(value, frontend);
|
|
19
|
+
if (!/^https?:$/.test(source.protocol) || source.username || source.password)
|
|
20
|
+
return value;
|
|
21
|
+
const relative = value.startsWith("/") && !value.startsWith("//");
|
|
22
|
+
if (!relative && !frontends.has(source.origin))
|
|
23
|
+
return value;
|
|
24
|
+
const uploads = /\/(?:wp-content\/)?uploads\//i.test(source.pathname);
|
|
25
|
+
if (uploads && backend)
|
|
26
|
+
return `${backend.origin}${source.pathname}${source.search}${source.hash}`;
|
|
27
|
+
// Do not mistake a page such as /media/gallery/ for an asset alias.
|
|
28
|
+
if (source.pathname.startsWith(FLOWPRESS_MEDIA_PREFIX) && /\.[a-z0-9]+$/i.test(source.pathname) && media) {
|
|
29
|
+
const base = media.pathname.replace(/\/+$/, "");
|
|
30
|
+
return `${media.origin}${base}/${source.pathname.slice(FLOWPRESS_MEDIA_PREFIX.length)}${source.search}${source.hash}`;
|
|
31
|
+
}
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
29
38
|
}
|
|
30
39
|
catch {
|
|
31
|
-
return value;
|
|
40
|
+
return (value) => value;
|
|
32
41
|
}
|
|
33
42
|
}
|
|
34
|
-
|
|
35
|
-
|
|
43
|
+
export function rewriteFlowpressMediaUrl(value, options) {
|
|
44
|
+
return mediaResolver(options)(value);
|
|
45
|
+
}
|
|
46
|
+
/** Normalize media data once, sharing unchanged branches and parsing origins
|
|
47
|
+
* once per payload. HTML, CSS and scripts remain intact.
|
|
36
48
|
*/
|
|
37
49
|
export function rewriteFlowpressMediaUrls(value, options) {
|
|
50
|
+
const resolve = mediaResolver(options);
|
|
38
51
|
function rewrite(item, key = "") {
|
|
39
52
|
if (typeof item === "string") {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
53
|
+
return /^srcset$/i.test(key) ? item.replace(/\S+/g, (token) => {
|
|
54
|
+
const url = token.replace(/,+$/, "");
|
|
55
|
+
return `${resolve(url)}${token.slice(url.length)}`;
|
|
56
|
+
}) : resolve(item);
|
|
57
|
+
}
|
|
58
|
+
if (Array.isArray(item)) {
|
|
59
|
+
const next = item.map((entry) => rewrite(entry));
|
|
60
|
+
return next.some((entry, i) => entry !== item[i]) ? next : item;
|
|
47
61
|
}
|
|
48
|
-
if (Array.isArray(item))
|
|
49
|
-
return item.map((entry) => rewrite(entry));
|
|
50
62
|
if (item && typeof item === "object") {
|
|
51
|
-
|
|
63
|
+
let changed = false;
|
|
64
|
+
const next = Object.fromEntries(Object.entries(item).map(([name, entry]) => {
|
|
65
|
+
const result = rewrite(entry, name);
|
|
66
|
+
changed ||= result !== entry;
|
|
67
|
+
return [name, result];
|
|
68
|
+
}));
|
|
69
|
+
return changed ? next : item;
|
|
52
70
|
}
|
|
53
71
|
return item;
|
|
54
72
|
}
|
|
@@ -86,7 +104,7 @@ export function rewriteFlowpressBackendUrl(value, backendUrl, frontendOrigin = "
|
|
|
86
104
|
try {
|
|
87
105
|
const source = new URL(value);
|
|
88
106
|
const backend = new URL(backendUrl);
|
|
89
|
-
if (source.origin !== backend.origin)
|
|
107
|
+
if (source.origin !== backend.origin || /\/(?:wp-content\/)?uploads\//i.test(source.pathname))
|
|
90
108
|
return value;
|
|
91
109
|
return `${frontendOrigin.replace(/\/$/, "")}${source.pathname}${source.search}${source.hash}`;
|
|
92
110
|
}
|
|
@@ -147,6 +165,7 @@ async function proxyFlowpressAsset(request, upstreamUrl, fetchImpl, options) {
|
|
|
147
165
|
return new Response("Bad Gateway", { status: 502 });
|
|
148
166
|
}
|
|
149
167
|
}
|
|
168
|
+
/** @deprecated Deliver media directly from WordPress or storage. Kept for existing consumers. */
|
|
150
169
|
export function proxyFlowpressUpload(request, backendUrl, fetchImpl = fetch) {
|
|
151
170
|
return proxyFlowpressAsset(request, backendUrl, fetchImpl, {
|
|
152
171
|
prefix: FLOWPRESS_UPLOADS_PREFIX,
|
|
@@ -160,6 +179,7 @@ export function proxyFlowpressUpload(request, backendUrl, fetchImpl = fetch) {
|
|
|
160
179
|
* marker with no equivalent on either upstream, so it is stripped before the
|
|
161
180
|
* request is forwarded: /media/2026/09/x.jpg becomes <origin>/2026/09/x.jpg.
|
|
162
181
|
*/
|
|
182
|
+
/** @deprecated Deliver media directly from storage. Kept for existing consumers. */
|
|
163
183
|
export function proxyFlowpressMedia(request, mediaUrl, fetchImpl = fetch) {
|
|
164
184
|
return proxyFlowpressAsset(request, mediaUrl, fetchImpl, {
|
|
165
185
|
prefix: FLOWPRESS_MEDIA_PREFIX,
|
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;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,CAAC,QAAQ;YAAE,OAAO,KAAK,CAAC;QAC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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"]}
|
|
1
|
+
{"version":3,"file":"media.js","sourceRoot":"","sources":["../src/media.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,w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,CAAC,CAAC;IACtC,IACE,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;WACjC,QAAQ,CAAC,QAAQ;WACjB,QAAQ,CAAC,QAAQ;WACjB,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/** Resolve legacy frontend media aliases to their real origin. Absolute URLs\n * supplied by WordPress/offload plugins remain authoritative, even in a mixed\n * library. FLOWPRESS_MEDIA is only used to undo the old /media/ alias.\n */\nfunction mediaResolver(options: FlowpressFrontendMediaOptions): (value: string) => string {\n try {\n const frontend = new URL(options.frontendOrigin);\n const backend = options.backendUrl ? new URL(options.backendUrl) : undefined;\n const media = options.mediaUrl ? new URL(options.mediaUrl) : backend;\n const frontends = new Set([frontend.origin, ...(options.frontendUrls ?? []).map((url) => new URL(url).origin)]);\n return (value) => {\n // Most JSON strings are labels, HTML or CSS: avoid parsing these as URLs.\n if (!value || /\\s/.test(value) || !/^(?:https?:\\/\\/|\\/)/i.test(value)) return value;\n try {\n const source = new URL(value, frontend);\n if (!/^https?:$/.test(source.protocol) || source.username || source.password) return value;\n const relative = value.startsWith(\"/\") && !value.startsWith(\"//\");\n if (!relative && !frontends.has(source.origin)) return value;\n const uploads = /\\/(?:wp-content\\/)?uploads\\//i.test(source.pathname);\n if (uploads && backend) return `${backend.origin}${source.pathname}${source.search}${source.hash}`;\n // Do not mistake a page such as /media/gallery/ for an asset alias.\n if (source.pathname.startsWith(FLOWPRESS_MEDIA_PREFIX) && /\\.[a-z0-9]+$/i.test(source.pathname) && media) {\n const base = media.pathname.replace(/\\/+$/, \"\");\n return `${media.origin}${base}/${source.pathname.slice(FLOWPRESS_MEDIA_PREFIX.length)}${source.search}${source.hash}`;\n }\n return value;\n } catch { return value; }\n };\n } catch { return (value) => value; }\n}\n\nexport function rewriteFlowpressMediaUrl(value: string, options: FlowpressFrontendMediaOptions): string {\n return mediaResolver(options)(value);\n}\n\n/** Normalize media data once, sharing unchanged branches and parsing origins\n * once per payload. HTML, CSS and scripts remain intact.\n */\nexport function rewriteFlowpressMediaUrls<T>(value: T, options: FlowpressFrontendMediaOptions): T {\n const resolve = mediaResolver(options);\n function rewrite(item: unknown, key = \"\"): unknown {\n if (typeof item === \"string\") {\n return /^srcset$/i.test(key) ? item.replace(/\\S+/g, (token) => {\n const url = token.replace(/,+$/, \"\");\n return `${resolve(url)}${token.slice(url.length)}`;\n }) : resolve(item);\n }\n if (Array.isArray(item)) {\n const next = item.map((entry) => rewrite(entry));\n return next.some((entry, i) => entry !== item[i]) ? next : item;\n }\n if (item && typeof item === \"object\") {\n let changed = false;\n const next = Object.fromEntries(Object.entries(item).map(([name, entry]) => {\n const result = rewrite(entry, name);\n changed ||= result !== entry;\n return [name, result];\n }));\n return changed ? next : item;\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 || /\\/(?:wp-content\\/)?uploads\\//i.test(source.pathname)) 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\n/** @deprecated Deliver media directly from WordPress or storage. Kept for existing consumers. */\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 */\n/** @deprecated Deliver media directly from storage. Kept for existing consumers. */\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.19",
|
|
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.9",
|
|
57
|
+
"@styleflow.app/flowpress-components": "1.0.0-beta.9"
|
|
56
58
|
},
|
|
57
59
|
"peerDependencies": {
|
|
58
60
|
"astro": ">=7.0.0"
|