diff options
Diffstat (limited to 'src/client/views/smartdraw/SmartDrawHandler.tsx')
-rw-r--r-- | src/client/views/smartdraw/SmartDrawHandler.tsx | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/client/views/smartdraw/SmartDrawHandler.tsx b/src/client/views/smartdraw/SmartDrawHandler.tsx index 52df598ee..4ec787e07 100644 --- a/src/client/views/smartdraw/SmartDrawHandler.tsx +++ b/src/client/views/smartdraw/SmartDrawHandler.tsx @@ -208,6 +208,9 @@ export class SmartDrawHandler extends ObservableReactComponent<{}> { this._canInteract = true; }; + /** + * Calls GPT API to create a drawing based on user input + */ @action drawWithGPT = async (startPt: { X: number; Y: number }, input: string, complexity: number, size: number, autoColor: boolean) => { if (input === '') return; @@ -226,6 +229,9 @@ export class SmartDrawHandler extends ObservableReactComponent<{}> { return strokeData; }; + /** + * Regenerates drawings with the option to add a specific regenerate prompt/request. + */ @action regenerate = async (lastInput?: DrawingOptions, lastResponse?: string, regenInput?: string) => { if (lastInput) this._lastInput = lastInput; @@ -256,6 +262,9 @@ export class SmartDrawHandler extends ObservableReactComponent<{}> { } }; + /** + * Parses the svg code that GPT returns into Bezier curves. + */ @action parseSvg = async (res: string, startPoint: { X: number; Y: number }, regenerate: boolean, autoColor: boolean) => { const svg = res.match(/<svg[^>]*>([\s\S]*?)<\/svg>/g); @@ -278,6 +287,9 @@ export class SmartDrawHandler extends ObservableReactComponent<{}> { } }; + /** + * Sends request to GPT API to recolor a selected ink document or group of ink documents. + */ colorWithGPT = async (drawing: Doc) => { const img = await this.getIcon(drawing); const { href } = (img as URLField).url; @@ -310,6 +322,9 @@ export class SmartDrawHandler extends ObservableReactComponent<{}> { } }; + /** + * Function that parses the GPT color response and sets the selected stroke(s) to the new color. + */ @undoBatch colorStrokes = (res: string, drawing: Doc) => { const colorList = res.match(/\{.*?\}/g); @@ -320,13 +335,14 @@ export class SmartDrawHandler extends ObservableReactComponent<{}> { strokes[index][DocData].color = strokeAndFill[0]; const inkStroke = DocumentView.getDocumentView(strokes[index])?.ComponentView as InkingStroke; const { inkData } = inkStroke.inkScaledData(); - if (InkingStroke.IsClosed(inkData)) { - strokes[index][DocData].fillColor = strokeAndFill[1]; - } + InkingStroke.IsClosed(inkData) ? (strokes[index][DocData].fillColor = strokeAndFill[1]) : (strokes[index][DocData].fillColor = undefined); } }); }; + /** + * Gets an image snapshot of a doc. In this class, it's used to snapshot a selected ink stroke/group to use for GPT color. + */ async getIcon(doc: Doc) { const docView = DocumentView.getDocumentView(doc); console.log(doc); |