File size: 1,849 Bytes
c225a63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { app } from '../../scripts/app.js';

const _al = Array.isArray([]);

app.registerExtension({
	name: 'Comfy.INSTARAW.DynamicAPINodes',
	async beforeRegisterNodeDef(nodeType, nodeData, app) {
		if (nodeData.name === 'INSTARAW_APITextToImage' || nodeData.name === 'INSTARAW_APIImageToImage') {
			
			const onNodeCreated = nodeType.prototype.onNodeCreated;
			nodeType.prototype.onNodeCreated = function () {
                onNodeCreated?.apply(this, arguments);
				this.last_model = null; // Cache property
			};

			const onDrawForeground = nodeType.prototype.onDrawForeground;
			nodeType.prototype.onDrawForeground = function(ctx) {
				onDrawForeground?.apply(this, arguments);

				const modelInput = this.inputs?.find((i) => i.name === 'model');
				let current_model = null;
				
				if (modelInput && modelInput.link != null) {
					const link = app.graph.links[modelInput.link];
					if (link) {
						const origin_node = app.graph.getNodeById(link.origin_id);
						const origin_widget = origin_node?.widgets.find(w => w.name === 'model');
						if (origin_widget) current_model = origin_widget.value;
					}
				}
				
				if (this.last_model === current_model) {
					return; // No change, do nothing
				}
				this.last_model = current_model;

				const isSeeDream = current_model?.startsWith('SeeDream');

				this.widgets.find(w => w.name === 'width').hidden = !isSeeDream;
				this.widgets.find(w => w.name === 'height').hidden = !isSeeDream;
				this.widgets.find(w => w.name === 'enable_safety_checker').hidden = !isSeeDream;
				
				const aspectRatioWidget = this.widgets.find(w => w.name === 'aspect_ratio');
				if (aspectRatioWidget) { 
					aspectRatioWidget.hidden = isSeeDream;
				}

				this.computeSize();
				this.setDirtyCanvas(true, true);
			};
		}
	},
});