@monkeyplus/flow 6.0.8 → 6.0.9
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/modules/images/runtime/server.d.ts +2 -0
- package/modules/images/runtime/server.mjs +11 -0
- package/package.json +1 -1
- package/server/lib/render.mjs +3 -2
- package/src/runtime/boot.d.ts +7 -0
- package/src/runtime/components/MkImage.d.ts +2 -2
- package/src/runtime/components/MkPicture.d.ts +2 -2
- package/src/runtime/components/image-shared.d.ts +2 -0
- package/src/runtime/components/image-shared.mjs +24 -2
- package/src/runtime/islands.mjs +3 -0
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { FlowImageBootPayload } from '../../../src/runtime/boot.ts';
|
|
1
2
|
import type { FlowImageRuntimeUtils, FlowImagesRuntimeConfig } from './types.ts';
|
|
3
|
+
export declare function getFlowImageBootPayload(config?: FlowImagesRuntimeConfig | undefined): FlowImageBootPayload | undefined;
|
|
2
4
|
export declare function getFlowImageRuntimeUtils(config?: FlowImagesRuntimeConfig | undefined): FlowImageRuntimeUtils | undefined;
|
|
3
5
|
export declare function resetFlowImageRuntimeState(): void;
|
|
@@ -28,6 +28,17 @@ function getFlowImagesRuntimeConfig() {
|
|
|
28
28
|
return getEnvFlowImagesRuntimeConfig();
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
+
export function getFlowImageBootPayload(config = getFlowImagesRuntimeConfig()) {
|
|
32
|
+
if (!config) {
|
|
33
|
+
return void 0;
|
|
34
|
+
}
|
|
35
|
+
const renameSources = [config.dirRenames, config.publicDir].filter(Boolean);
|
|
36
|
+
return {
|
|
37
|
+
all: loadImageRenames(renameSources),
|
|
38
|
+
options: { ...config.options },
|
|
39
|
+
generateOutput: !!config.generate
|
|
40
|
+
};
|
|
41
|
+
}
|
|
31
42
|
export function getFlowImageRuntimeUtils(config = getFlowImagesRuntimeConfig()) {
|
|
32
43
|
if (!config) {
|
|
33
44
|
return void 0;
|
package/package.json
CHANGED
package/server/lib/render.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import bases from "virtual:flow/bases";
|
|
|
5
5
|
import layouts from "virtual:flow/layouts";
|
|
6
6
|
import templates from "virtual:flow/templates";
|
|
7
7
|
import { createSSRApp, defineComponent, h } from "vue";
|
|
8
|
-
import { getFlowImageRuntimeUtils } from "../../modules/images/runtime/server.mjs";
|
|
8
|
+
import { getFlowImageBootPayload, getFlowImageRuntimeUtils } from "../../modules/images/runtime/server.mjs";
|
|
9
9
|
import { installFlowVuePlugins } from "../../src/runtime/vue";
|
|
10
10
|
import { getUrl, getUrls } from "./pages.mjs";
|
|
11
11
|
function escapeHtml(value) {
|
|
@@ -152,7 +152,8 @@ export async function renderDocument(page, clientAssets) {
|
|
|
152
152
|
template: page.definition.view.template,
|
|
153
153
|
title: fallbackTitle,
|
|
154
154
|
locale: page.locale,
|
|
155
|
-
mode
|
|
155
|
+
mode,
|
|
156
|
+
images: getFlowImageBootPayload()
|
|
156
157
|
};
|
|
157
158
|
const rendered = await renderBody(page);
|
|
158
159
|
const body = stripVueFragmentMarkers(rendered.body);
|
package/src/runtime/boot.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
+
import type { FlowImageMeta, FlowImageOptions } from '../../modules/images/runtime/types.ts';
|
|
1
2
|
import type { FlowHydrationMode, FlowLocale } from './pages';
|
|
3
|
+
export interface FlowImageBootPayload {
|
|
4
|
+
all: Record<string, FlowImageMeta>;
|
|
5
|
+
options: FlowImageOptions;
|
|
6
|
+
generateOutput: boolean;
|
|
7
|
+
}
|
|
2
8
|
export interface FlowBootPayload {
|
|
3
9
|
path: string;
|
|
4
10
|
bundle: string;
|
|
@@ -6,4 +12,5 @@ export interface FlowBootPayload {
|
|
|
6
12
|
title: string;
|
|
7
13
|
locale: FlowLocale;
|
|
8
14
|
mode: FlowHydrationMode;
|
|
15
|
+
images?: FlowImageBootPayload;
|
|
9
16
|
}
|
|
@@ -173,14 +173,14 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
|
|
|
173
173
|
preset: string;
|
|
174
174
|
modifiers: Record<string, any>;
|
|
175
175
|
sizes: string | Record<string, any>;
|
|
176
|
+
background: string;
|
|
177
|
+
quality: string | number;
|
|
176
178
|
alt: string;
|
|
177
179
|
referrerpolicy: string;
|
|
178
180
|
usemap: string;
|
|
179
181
|
longdesc: string;
|
|
180
182
|
ismap: boolean;
|
|
181
183
|
loading: string;
|
|
182
|
-
quality: string | number;
|
|
183
|
-
background: string;
|
|
184
184
|
title: string;
|
|
185
185
|
sync: boolean;
|
|
186
186
|
thumbnail: string | boolean;
|
|
@@ -183,14 +183,14 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
|
|
|
183
183
|
preset: string;
|
|
184
184
|
modifiers: Record<string, any>;
|
|
185
185
|
sizes: string | Record<string, any>;
|
|
186
|
+
background: string;
|
|
187
|
+
quality: string | number;
|
|
186
188
|
alt: string;
|
|
187
189
|
referrerpolicy: string;
|
|
188
190
|
usemap: string;
|
|
189
191
|
longdesc: string;
|
|
190
192
|
ismap: boolean;
|
|
191
193
|
loading: string;
|
|
192
|
-
quality: string | number;
|
|
193
|
-
background: string;
|
|
194
194
|
title: string;
|
|
195
195
|
sync: boolean;
|
|
196
196
|
thumbnail: string | boolean;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { FlowImageMeta, FlowImageOptions, GetImageFunction } from '../../../modules/images/runtime/types.ts';
|
|
2
|
+
import type { FlowBootPayload } from '../boot.ts';
|
|
2
3
|
export interface InjectedImageUtils {
|
|
3
4
|
getImage?: GetImageFunction;
|
|
4
5
|
getImageMeta?: (src: string) => FlowImageMeta | undefined;
|
|
@@ -6,6 +7,7 @@ export interface InjectedImageUtils {
|
|
|
6
7
|
}
|
|
7
8
|
export declare function useInjectedImageUtils(): InjectedImageUtils;
|
|
8
9
|
export declare function useLazySizes(enabled: () => unknown): void;
|
|
10
|
+
export declare function createBootImageUtils(boot?: FlowBootPayload): InjectedImageUtils;
|
|
9
11
|
export declare function useImage(props: Record<string, any>): {
|
|
10
12
|
imageUtils: InjectedImageUtils;
|
|
11
13
|
image: import("vue").ComputedRef<FlowImageMeta>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { computed, inject } from "vue";
|
|
2
|
-
import { watchEffect } from "vue";
|
|
1
|
+
import { computed, inject, watchEffect } from "vue";
|
|
3
2
|
import { getNormalName, parseSize } from "../../../modules/images/runtime/helpers.mjs";
|
|
3
|
+
import { createImageResolver } from "../../../modules/images/runtime/image.mjs";
|
|
4
4
|
let lazySizesLoadPromise;
|
|
5
5
|
function loadLazySizes() {
|
|
6
6
|
if (lazySizesLoadPromise) {
|
|
@@ -20,6 +20,28 @@ export function useLazySizes(enabled) {
|
|
|
20
20
|
void loadLazySizes();
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
|
+
export function createBootImageUtils(boot) {
|
|
24
|
+
const snapshot = boot?.images;
|
|
25
|
+
if (!snapshot) {
|
|
26
|
+
return {};
|
|
27
|
+
}
|
|
28
|
+
const stateImages = {
|
|
29
|
+
all: snapshot.all || {},
|
|
30
|
+
generate: {}
|
|
31
|
+
};
|
|
32
|
+
const resolver = createImageResolver(snapshot.options, stateImages, {
|
|
33
|
+
generateOutput: snapshot.generateOutput
|
|
34
|
+
});
|
|
35
|
+
return {
|
|
36
|
+
getImage: resolver.getImage,
|
|
37
|
+
getImageMeta(src) {
|
|
38
|
+
return stateImages.all[src];
|
|
39
|
+
},
|
|
40
|
+
getImageOptions() {
|
|
41
|
+
return { ...snapshot.options };
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
23
45
|
export function useImage(props) {
|
|
24
46
|
const imageUtils = useInjectedImageUtils();
|
|
25
47
|
const nImgAttrs = computed(() => ({
|
package/src/runtime/islands.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import islands from "virtual:flow/islands";
|
|
2
2
|
import { createSSRApp } from "vue";
|
|
3
|
+
import { createBootImageUtils } from "./components/image-shared.mjs";
|
|
3
4
|
import { getClientHead } from "./head.mjs";
|
|
4
5
|
import { installFlowVuePlugins } from "./vue.mjs";
|
|
5
6
|
function parseIslandProps(value) {
|
|
@@ -39,7 +40,9 @@ async function hydrateIsland(element, boot) {
|
|
|
39
40
|
return;
|
|
40
41
|
}
|
|
41
42
|
const app = createSSRApp(mod.default, props);
|
|
43
|
+
const imageUtils = createBootImageUtils(boot);
|
|
42
44
|
app.use(getClientHead());
|
|
45
|
+
app.provide("utils", imageUtils);
|
|
43
46
|
installFlowVuePlugins(app);
|
|
44
47
|
app.mount(element);
|
|
45
48
|
element.dataset.flowIslandHydrated = "true";
|