diff options
| author | eleanor-park <eleanor_park@brown.edu> | 2025-01-10 15:07:42 -0500 |
|---|---|---|
| committer | eleanor-park <eleanor_park@brown.edu> | 2025-01-10 15:07:42 -0500 |
| commit | fd922d7898ed7a405ed47a7e48b85c582d787c07 (patch) | |
| tree | 51110ea8358d8bd9898dce2aa1fcce83b2d1f584 /src/client/views/smartdraw/DrawingFillHandler.tsx | |
| parent | c2312afe4ee969043ba3ce4cb9c275a48b0f1ee0 (diff) | |
working on merge conflicts
Diffstat (limited to 'src/client/views/smartdraw/DrawingFillHandler.tsx')
| -rw-r--r-- | src/client/views/smartdraw/DrawingFillHandler.tsx | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/src/client/views/smartdraw/DrawingFillHandler.tsx b/src/client/views/smartdraw/DrawingFillHandler.tsx index 423e3b2ac..57327631a 100644 --- a/src/client/views/smartdraw/DrawingFillHandler.tsx +++ b/src/client/views/smartdraw/DrawingFillHandler.tsx @@ -1,7 +1,7 @@ import { imageUrlToBase64 } from '../../../ClientUtils'; import { Doc } from '../../../fields/Doc'; import { DocData } from '../../../fields/DocSymbols'; -import { ImageCast } from '../../../fields/Types'; +import { DocCast, ImageCast } from '../../../fields/Types'; import { Upload } from '../../../server/SharedMediaTypes'; import { gptDescribeImage } from '../../apis/gpt/GPT'; import { Docs } from '../../documents/Documents'; @@ -11,10 +11,23 @@ import { OpenWhere } from '../nodes/OpenWhere'; import { AspectRatioLimits, FireflyDimensionsMap, FireflyImageDimensions, FireflyStylePresets } from './FireflyConstants'; export class DrawingFillHandler { - static drawingToImage = (drawing: Doc, strength: number, user_prompt: string) => { + static drawingToImage = async (drawing: Doc, strength: number, user_prompt: string) => { const docData = drawing[DocData]; const tags: string[] = ((docData?.tags as unknown as string[]) ?? []).map(tag => tag.slice(1)) ?? []; const styles = tags.filter(tag => FireflyStylePresets.has(tag)); + const styleDocs = Doc.Links(drawing) + .map(link => Doc.getOppositeAnchor(link, drawing)) + .map(anchor => anchor && DocCast(anchor.embedContainer)); + const styleRef = styleDocs.filter(doc => doc !== undefined && doc.type === 'image').lastElement(); + let styleUrl: string | undefined; + if (styleRef) { + const styleImg = await DocumentView.GetDocImage(styleRef); + if (styleImg) { + const { href } = ImageCast(styleImg).url; + const hrefParts = href.split('.'); + styleUrl = `${hrefParts.slice(0, -1).join('.')}_o.${hrefParts.lastElement()}`; + } + } DocumentView.GetDocImage(drawing)?.then(imageField => { if (imageField) { const aspectRatio = (drawing.width as number) / (drawing.height as number); @@ -35,7 +48,7 @@ export class DrawingFillHandler { .then((hrefBase64: string) => gptDescribeImage(hrefBase64)) .then(prompt => { Networking.PostToServer('/queryFireflyImageFromStructure', - { prompt: `${user_prompt}, ${prompt}`, width: dims.width, height: dims.height, structureUrl, strength, styles }) + { prompt: `${user_prompt}, ${prompt}`, width: dims.width, height: dims.height, structure: structureUrl, strength: strength, presets: styles, styleRef: styleUrl}) .then((info: Upload.ImageInformation) => DocumentViewInternal.addDocTabFunc(Docs.Create.ImageDocument(info.accessPaths.agnostic.client, { ai: 'firefly', ai_firefly_prompt: user_prompt || prompt, _width: 500, data_nativeWidth: info.nativeWidth, data_nativeHeight: info.nativeHeight }), OpenWhere.addRight) |
