aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/smartdraw/DrawingFillHandler.tsx
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2025-03-06 16:17:47 -0500
committerbobzel <zzzman@gmail.com>2025-03-06 16:17:47 -0500
commit5ad858090f3006631062877d90120e3cc505fada (patch)
tree9f87a8e1e7098a1025f6f4aac332dbc854db5be3 /src/client/views/smartdraw/DrawingFillHandler.tsx
parent9c2a7c14fd9d0e44609aab30c6323583162009db (diff)
parentadaa107aac8558fa6f46e6ba1263c650c212d506 (diff)
Merge branch 'master' into aarav_edit
Diffstat (limited to 'src/client/views/smartdraw/DrawingFillHandler.tsx')
-rw-r--r--src/client/views/smartdraw/DrawingFillHandler.tsx33
1 files changed, 18 insertions, 15 deletions
diff --git a/src/client/views/smartdraw/DrawingFillHandler.tsx b/src/client/views/smartdraw/DrawingFillHandler.tsx
index d0a840883..c672bc718 100644
--- a/src/client/views/smartdraw/DrawingFillHandler.tsx
+++ b/src/client/views/smartdraw/DrawingFillHandler.tsx
@@ -1,6 +1,7 @@
import { imageUrlToBase64 } from '../../../ClientUtils';
import { Doc, StrListCast } from '../../../fields/Doc';
import { DocData } from '../../../fields/DocSymbols';
+import { List } from '../../../fields/List';
import { DocCast, ImageCast } from '../../../fields/Types';
import { ImageField } from '../../../fields/URLField';
import { Upload } from '../../../server/SharedMediaTypes';
@@ -28,41 +29,43 @@ export class DrawingFillHandler {
const hrefParts = ImageCast(styleImg).url.href.split('.');
return `${hrefParts.slice(0, -1).join('.')}_o.${hrefParts.lastElement()}`;
});
- DocumentView.GetDocImage(drawing)?.then(imageField => {
+ return DocumentView.GetDocImage(drawing)?.then(imageField => {
if (imageField) {
const aspectRatio = (drawing.width as number) / (drawing.height as number);
- let dims: { width: number; height: number };
- if (aspectRatio > AspectRatioLimits[FireflyImageDimensions.Widescreen]) {
- dims = FireflyDimensionsMap[FireflyImageDimensions.Widescreen];
- } else if (aspectRatio > AspectRatioLimits[FireflyImageDimensions.Landscape]) {
- dims = FireflyDimensionsMap[FireflyImageDimensions.Landscape];
- } else if (aspectRatio < AspectRatioLimits[FireflyImageDimensions.Portrait]) {
- dims = FireflyDimensionsMap[FireflyImageDimensions.Portrait];
- } else {
- dims = FireflyDimensionsMap[FireflyImageDimensions.Square];
- }
+ const dims = (() => {
+ if (aspectRatio > AspectRatioLimits[FireflyImageDimensions.Widescreen]) return FireflyDimensionsMap[FireflyImageDimensions.Widescreen];
+ if (aspectRatio > AspectRatioLimits[FireflyImageDimensions.Landscape]) return FireflyDimensionsMap[FireflyImageDimensions.Landscape];
+ if (aspectRatio < AspectRatioLimits[FireflyImageDimensions.Portrait]) return FireflyDimensionsMap[FireflyImageDimensions.Portrait];
+ return FireflyDimensionsMap[FireflyImageDimensions.Square];
+ })();
const { href } = ImageCast(imageField).url;
const hrefParts = href.split('.');
const structureUrl = `${hrefParts.slice(0, -1).join('.')}_o.${hrefParts.lastElement()}`;
return imageUrlToBase64(structureUrl)
.then(gptDescribeImage)
.then((prompt, newPrompt = user_prompt || prompt) =>
- Networking.PostToServer('/queryFireflyImageFromStructure', { prompt: `${newPrompt}`, width: dims.width, height: dims.height, structure: structureUrl, strength, presets: styles, styleUrl })
- .then((infos: Upload.ImageInformation[]) => {
+ Networking.PostToServer('/queryFireflyImageFromStructure', { prompt: `${newPrompt}`, width: dims.width, height: dims.height, structureUrl, strength, presets: styles, styleUrl })
+ .then(res => {
const genratedDocs = DocCast(drawing.ai_firefly_generatedDocs) ?? Docs.Create.MasonryDocument([], { _width: 400, _height: 400 });
drawing[DocData].ai_firefly_generatedDocs = genratedDocs;
- infos.map(info =>
+ (res as Upload.ImageInformation[]).map(info =>
Doc.AddDocToList(
genratedDocs,
undefined,
Docs.Create.ImageDocument(info.accessPaths.agnostic.client, {
ai: 'firefly',
+ tags: new List<string>(['@ai']),
title: newPrompt,
+ _data_usePath: 'alternate:hover',
+ data_alternates: new List<Doc>([drawing]),
ai_firefly_prompt: newPrompt,
_width: 500,
data_nativeWidth: info.nativeWidth,
data_nativeHeight: info.nativeHeight,
- })
+ }),
+ undefined,
+ undefined,
+ true
)
);
if (!DocumentView.getFirstDocumentView(genratedDocs)) DocumentViewInternal.addDocTabFunc(genratedDocs, OpenWhere.addRight);