Compare commits
1 Commits
plugin-res
...
dependabot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
64abc0ef34 |
@@ -191,11 +191,6 @@ export type Plugin<P extends PluginTypeHelper = PluginTypeHelperDefault> = {
|
||||
StableDiffusionStyle[] | undefined
|
||||
>;
|
||||
|
||||
/** If you want to provide a list of resolutions in pixels to choose from, you can return them via this function and they will be presented as a slider in the UI */
|
||||
getStableDiffusionAllowedResolutions?: (
|
||||
model?: ID
|
||||
) => MaybePromise<{ width: number; height: number }[] | undefined>;
|
||||
|
||||
/** Determines the default count passed to `createStableDiffusionImages` */
|
||||
getStableDiffusionDefaultCount?: () => number | undefined;
|
||||
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import * as ReactQuery from "@tanstack/react-query";
|
||||
|
||||
import { Generation } from "~/Generation";
|
||||
import { Size } from "~/Geometry";
|
||||
import { Plugin } from "~/Plugin";
|
||||
import { Theme } from "~/Theme";
|
||||
|
||||
export type Ratio = Size & { label?: string };
|
||||
@@ -154,30 +151,8 @@ export namespace Ratios {
|
||||
{ width: 4, height: 1 },
|
||||
] as const;
|
||||
|
||||
const gcd = (a: number, b: number): number => (b ? gcd(b, a % b) : a);
|
||||
const simplifyAspectRatio = (width: number, height: number) => {
|
||||
const divisor = gcd(width, height);
|
||||
return { width: width / divisor, height: height / divisor } as Ratio;
|
||||
};
|
||||
|
||||
export const usePluginResolutions = (model?: ID) => {
|
||||
const getStableDiffusionAllowedResolutions = Plugin.use(
|
||||
({ getStableDiffusionAllowedResolutions }) =>
|
||||
getStableDiffusionAllowedResolutions
|
||||
);
|
||||
|
||||
return ReactQuery.useQuery({
|
||||
enabled: !!getStableDiffusionAllowedResolutions,
|
||||
|
||||
queryKey: ["Generation.Image.Ratio.PluginResolutions.use"],
|
||||
queryFn: async () =>
|
||||
(await getStableDiffusionAllowedResolutions?.(model)) ?? [],
|
||||
});
|
||||
};
|
||||
|
||||
export const use = (id?: ID, fullControl = false) => {
|
||||
const { input } = Generation.Image.Input.use(id);
|
||||
const { data: pluginResolutions } = usePluginResolutions(input?.model);
|
||||
const bounds = Generation.Image.Size.Bounds.use(id);
|
||||
const ratios = useMemo(() => {
|
||||
if (!input?.width || !input?.height || !bounds) return [];
|
||||
@@ -193,19 +168,9 @@ export namespace Ratios {
|
||||
};
|
||||
};
|
||||
|
||||
const ratios = pluginResolutions
|
||||
? pluginResolutions.map(({ width, height }) => ({
|
||||
...simplifyAspectRatio(width, height),
|
||||
input: {
|
||||
width,
|
||||
height,
|
||||
},
|
||||
}))
|
||||
: (fullControl ? presets : presets.slice(0, -2))
|
||||
.map(sizing)
|
||||
.filter(
|
||||
({ input }) => input.width * input.height <= bounds.area.max
|
||||
);
|
||||
const ratios = (fullControl ? presets : presets.slice(0, -2))
|
||||
.map(sizing)
|
||||
.filter(({ input }) => input.width * input.height <= bounds.area.max);
|
||||
|
||||
const flipped = ratios.map(({ width, height, input }) => ({
|
||||
width: height,
|
||||
|
||||
@@ -6307,8 +6307,8 @@ __metadata:
|
||||
linkType: hard
|
||||
|
||||
"protobufjs@npm:^6.11.3, protobufjs@npm:^6.8.8":
|
||||
version: 6.11.3
|
||||
resolution: "protobufjs@npm:6.11.3"
|
||||
version: 6.11.4
|
||||
resolution: "protobufjs@npm:6.11.4"
|
||||
dependencies:
|
||||
"@protobufjs/aspromise": ^1.1.2
|
||||
"@protobufjs/base64": ^1.1.2
|
||||
@@ -6326,7 +6326,7 @@ __metadata:
|
||||
bin:
|
||||
pbjs: bin/pbjs
|
||||
pbts: bin/pbts
|
||||
checksum: 4a6ce1964167e4c45c53fd8a312d7646415c777dd31b4ba346719947b88e61654912326101f927da387d6b6473ab52a7ea4f54d6f15d63b31130ce28e2e15070
|
||||
checksum: b2fc6a01897b016c2a7e43a854ab4a3c57080f61be41e552235436e7a730711b8e89e47cb4ae52f0f065b5ab5d5989fc932f390337ce3a8ccf07203415700850
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
|
||||
Reference in New Issue
Block a user