bizydraft 0.2.49__py3-none-any.whl → 0.2.87__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of bizydraft might be problematic. Click here for more details.

@@ -7,147 +7,159 @@ let keyboardListener = null;
7
7
  let contextMenuListener = null;
8
8
 
9
9
  // 设置全局变量引用
10
- export function setGlobalReferences(overlay, eventBlocked, kListener, cListener) {
11
- freezeOverlay = overlay;
12
- globalEventBlocked = eventBlocked;
13
- keyboardListener = kListener;
14
- contextMenuListener = cListener;
10
+ export function setGlobalReferences(
11
+ overlay,
12
+ eventBlocked,
13
+ kListener,
14
+ cListener
15
+ ) {
16
+ freezeOverlay = overlay;
17
+ globalEventBlocked = eventBlocked;
18
+ keyboardListener = kListener;
19
+ contextMenuListener = cListener;
15
20
  }
16
21
 
17
22
  // 只聚焦节点,不高亮
18
23
  export function focusNodeOnly(nodeId) {
19
- console.log('[nodeFocusHandler] focusNodeOnly called with nodeId:', nodeId);
24
+ console.log("[nodeFocusHandler] focusNodeOnly called with nodeId:", nodeId);
20
25
 
21
- if (!app || !app.graph) {
22
- console.error('[nodeFocusHandler] app or app.graph not available');
23
- return false;
24
- }
26
+ if (!app || !app.graph) {
27
+ console.error("[nodeFocusHandler] app or app.graph not available");
28
+ return false;
29
+ }
25
30
 
26
- const node = app.graph.getNodeById(parseInt(nodeId, 10));
27
- if (!node) {
28
- console.error('[nodeFocusHandler] 找不到节点:', nodeId);
29
- return false;
30
- }
31
+ const node = app.graph.getNodeById(parseInt(nodeId, 10));
32
+ if (!node) {
33
+ console.error("[nodeFocusHandler] 找不到节点:", nodeId);
34
+ return false;
35
+ }
31
36
 
32
- console.log('[nodeFocusHandler] 找到节点:', node);
37
+ console.log("[nodeFocusHandler] 找到节点:", node);
33
38
 
34
- // 临时禁用冻结模式
35
- const wasFreezed = !!freezeOverlay;
36
- let originalOverlayDisplay = null;
39
+ // 临时禁用冻结模式
40
+ const wasFreezed = !!freezeOverlay;
41
+ let originalOverlayDisplay = null;
37
42
 
38
- if (wasFreezed && freezeOverlay) {
39
- originalOverlayDisplay = freezeOverlay.style.display;
40
- freezeOverlay.style.display = 'none';
41
-
42
- // 临时解除事件阻止
43
- if (globalEventBlocked) {
44
- document.removeEventListener('keydown', keyboardListener, true);
45
- document.removeEventListener('contextmenu', contextMenuListener, true);
46
- }
47
- }
43
+ if (wasFreezed && freezeOverlay) {
44
+ originalOverlayDisplay = freezeOverlay.style.display;
45
+ freezeOverlay.style.display = "none";
48
46
 
49
- // 只设置节点的 selected 属性,不改变颜色
50
- for (const n of app.graph._nodes) {
51
- n.selected = n.id === node.id;
47
+ // 临时解除事件阻止
48
+ if (globalEventBlocked) {
49
+ document.removeEventListener("keydown", keyboardListener, true);
50
+ document.removeEventListener("contextmenu", contextMenuListener, true);
52
51
  }
53
-
54
- // 设置 selected_nodes
55
- if (app.canvas) {
56
- app.canvas.selected_nodes = [node];
52
+ }
53
+
54
+ // 只设置节点的 selected 属性,不改变颜色
55
+ for (const n of app.graph._nodes) {
56
+ n.selected = n.id === node.id;
57
+ }
58
+
59
+ // 设置 selected_nodes
60
+ if (app.canvas) {
61
+ app.canvas.selected_nodes = [node];
62
+ }
63
+
64
+ // 聚焦到节点 - 使用与selectNodeAndFocus相同的方法
65
+ if (app.canvas && typeof app.canvas.centerOnNode === "function") {
66
+ console.log("[nodeFocusHandler] 使用 centerOnNode 方法聚焦节点");
67
+ app.canvas.centerOnNode(node);
68
+ }
69
+
70
+ // 刷新画布
71
+ if (app.canvas) {
72
+ app.canvas.setDirty(true, true);
73
+ if (typeof app.canvas.draw === "function") {
74
+ app.canvas.draw(true, true);
57
75
  }
76
+ }
58
77
 
59
- // 聚焦到节点 - 使用与selectNodeAndFocus相同的方法
60
- if (app.canvas && typeof app.canvas.centerOnNode === 'function') {
61
- console.log('[nodeFocusHandler] 使用 centerOnNode 方法聚焦节点');
62
- app.canvas.centerOnNode(node);
78
+ // 恢复冻结模式
79
+ setTimeout(() => {
80
+ if (wasFreezed && freezeOverlay) {
81
+ freezeOverlay.style.display = originalOverlayDisplay;
82
+
83
+ // 恢复事件阻止
84
+ if (globalEventBlocked) {
85
+ document.addEventListener("keydown", keyboardListener, true);
86
+ document.addEventListener("contextmenu", contextMenuListener, true);
87
+ }
63
88
  }
64
89
 
65
- // 刷新画布
90
+ // 再次刷新画布
66
91
  if (app.canvas) {
67
- app.canvas.setDirty(true, true);
68
- if (typeof app.canvas.draw === 'function') {
69
- app.canvas.draw(true, true);
70
- }
92
+ app.canvas.setDirty(true, true);
93
+ if (typeof app.canvas.draw === "function") {
94
+ app.canvas.draw(true, true);
95
+ }
71
96
  }
97
+ }, 100);
72
98
 
73
- // 恢复冻结模式
74
- setTimeout(() => {
75
- if (wasFreezed && freezeOverlay) {
76
- freezeOverlay.style.display = originalOverlayDisplay;
77
-
78
- // 恢复事件阻止
79
- if (globalEventBlocked) {
80
- document.addEventListener('keydown', keyboardListener, true);
81
- document.addEventListener('contextmenu', contextMenuListener, true);
82
- }
83
- }
84
-
85
- // 再次刷新画布
86
- if (app.canvas) {
87
- app.canvas.setDirty(true, true);
88
- if (typeof app.canvas.draw === 'function') {
89
- app.canvas.draw(true, true);
90
- }
91
- }
92
- }, 100);
93
-
94
- console.log('[nodeFocusHandler] focusNodeOnly 完成');
95
- return true;
99
+ console.log("[nodeFocusHandler] focusNodeOnly 完成");
100
+ return true;
96
101
  }
97
102
 
98
103
  // 处理画布节点点击事件
99
104
  export function handleCanvasNodeClick(e) {
100
- if (!app || !app.graph) return;
101
-
102
- // 获取点击的节点
103
- const nodeUnderMouse = getNodeUnderMouse(e);
104
- if (!nodeUnderMouse) return;
105
-
106
- console.log('[nodeFocusHandler] 画布点击节点:', nodeUnderMouse.id, nodeUnderMouse.title);
107
-
108
- // 发送消息到前端,通知节点被点击
109
- window.parent.postMessage({
110
- type: 'CANVAS_NODE_CLICKED',
111
- nodeId: nodeUnderMouse.id,
112
- nodeTitle: nodeUnderMouse.title,
113
- nodeType: nodeUnderMouse.type
114
- }, '*');
105
+ if (!app || !app.graph) return;
106
+
107
+ // 获取点击的节点
108
+ const nodeUnderMouse = getNodeUnderMouse(e);
109
+ if (!nodeUnderMouse) return;
110
+
111
+ console.log(
112
+ "[nodeFocusHandler] 画布点击节点:",
113
+ nodeUnderMouse.id,
114
+ nodeUnderMouse.title
115
+ );
116
+
117
+ // 发送消息到前端,通知节点被点击
118
+ window.parent.postMessage(
119
+ {
120
+ type: "CANVAS_NODE_CLICKED",
121
+ nodeId: nodeUnderMouse.id,
122
+ nodeTitle: nodeUnderMouse.title,
123
+ nodeType: nodeUnderMouse.type,
124
+ },
125
+ "*"
126
+ );
115
127
  }
116
128
 
117
129
  // 获取鼠标下方的节点
118
130
  function getNodeUnderMouse(e) {
119
- if (!app || !app.graph) return null;
131
+ if (!app || !app.graph) return null;
120
132
 
121
- // 获取画布位置
122
- const canvas = document.querySelector('canvas');
123
- if (!canvas) return null;
133
+ // 获取画布位置
134
+ const canvas = document.querySelector("canvas");
135
+ if (!canvas) return null;
124
136
 
125
- // 转换为图形坐标
126
- const pos = app.canvas.convertEventToCanvasOffset(e);
137
+ // 转换为图形坐标
138
+ const pos = app.canvas.convertEventToCanvasOffset(e);
127
139
 
128
- // 检查点击位置是否在某个节点上
129
- const node = app.graph.getNodeOnPos(pos[0], pos[1]);
130
- return node;
140
+ // 检查点击位置是否在某个节点上
141
+ const node = app.graph.getNodeOnPos(pos[0], pos[1]);
142
+ return node;
131
143
  }
132
144
 
133
145
  // 设置画布点击事件监听
134
146
  export function setupCanvasClickHandler() {
135
- // 移除现有的事件监听器
136
- removeCanvasClickHandler();
137
-
138
- // 添加画布点击事件监听
139
- const canvas = document.querySelector('canvas');
140
- if (canvas) {
141
- canvas.addEventListener('click', handleCanvasNodeClick);
142
- console.log('[nodeFocusHandler] 画布点击事件监听器已设置');
143
- }
147
+ // 移除现有的事件监听器
148
+ removeCanvasClickHandler();
149
+
150
+ // 添加画布点击事件监听
151
+ const canvas = document.querySelector("canvas");
152
+ if (canvas) {
153
+ canvas.addEventListener("click", handleCanvasNodeClick);
154
+ console.log("[nodeFocusHandler] 画布点击事件监听器已设置");
155
+ }
144
156
  }
145
157
 
146
158
  // 移除画布点击事件监听
147
159
  export function removeCanvasClickHandler() {
148
- const canvas = document.querySelector('canvas');
149
- if (canvas) {
150
- canvas.removeEventListener('click', handleCanvasNodeClick);
151
- console.log('[nodeFocusHandler] 画布点击事件监听器已移除');
152
- }
160
+ const canvas = document.querySelector("canvas");
161
+ if (canvas) {
162
+ canvas.removeEventListener("click", handleCanvasNodeClick);
163
+ console.log("[nodeFocusHandler] 画布点击事件监听器已移除");
164
+ }
153
165
  }
@@ -11,29 +11,29 @@ let nodeParamsMap = new Map();
11
11
  * @param {Array} inputsData - 服务端返回的inputs数组
12
12
  */
13
13
  function setNodeParams(inputsData) {
14
- if (!Array.isArray(inputsData)) {
15
- console.error('Invalid inputs data format:', inputsData);
16
- return;
14
+ if (!Array.isArray(inputsData)) {
15
+ console.error("Invalid inputs data format:", inputsData);
16
+ return;
17
+ }
18
+
19
+ // 清空现有映射
20
+ nodeParamsMap.clear();
21
+
22
+ // 构建新的映射
23
+ inputsData.forEach((nodeInfo) => {
24
+ if (nodeInfo && nodeInfo.nodeId && Array.isArray(nodeInfo.params)) {
25
+ // 以nodeId为键,存储参数信息
26
+ const paramNames = nodeInfo.params.map((param) => param.name);
27
+ nodeParamsMap.set(nodeInfo.nodeId, {
28
+ name: nodeInfo.name,
29
+ displayName: nodeInfo.displayName,
30
+ paramNames: paramNames,
31
+ params: nodeInfo.params,
32
+ });
17
33
  }
34
+ });
18
35
 
19
- // 清空现有映射
20
- nodeParamsMap.clear();
21
-
22
- // 构建新的映射
23
- inputsData.forEach(nodeInfo => {
24
- if (nodeInfo && nodeInfo.nodeId && Array.isArray(nodeInfo.params)) {
25
- // 以nodeId为键,存储参数信息
26
- const paramNames = nodeInfo.params.map(param => param.name);
27
- nodeParamsMap.set(nodeInfo.nodeId, {
28
- name: nodeInfo.name,
29
- displayName: nodeInfo.displayName,
30
- paramNames: paramNames,
31
- params: nodeInfo.params
32
- });
33
- }
34
- });
35
-
36
- console.log('节点参数映射已更新:', nodeParamsMap);
36
+ console.log("节点参数映射已更新:", nodeParamsMap);
37
37
  }
38
38
 
39
39
  /**
@@ -42,71 +42,73 @@ function setNodeParams(inputsData) {
42
42
  * @returns {Object|null} - 过滤后的节点信息,如果节点不符合条件则返回null
43
43
  */
44
44
  function filterNodeWidgets(node) {
45
- if (!node || !node.id) return null;
46
-
47
- // 如果节点ID不在参数映射中,则不是可配置节点
48
- if (!nodeParamsMap.has(String(node.id))) {
49
- console.log(`节点 ${node.id} 不在可配置列表中`);
50
- return null;
51
- }
45
+ if (!node || !node.id) return null;
46
+
47
+ // 如果节点ID不在参数映射中,则不是可配置节点
48
+ if (!nodeParamsMap.has(String(node.id))) {
49
+ console.log(`节点 ${node.id} 不在可配置列表中`);
50
+ return null;
51
+ }
52
+
53
+ // 获取节点的允许参数列表
54
+ const nodeParamsInfo = nodeParamsMap.get(String(node.id));
55
+ const allowedParamNames = nodeParamsInfo.paramNames;
56
+
57
+ // 提取节点信息
58
+ const nodeInfo = {
59
+ id: node.id,
60
+ type: node.type,
61
+ comfyClass: node.comfyClass,
62
+ title: node.title || nodeParamsInfo.displayName,
63
+ widgets: [],
64
+ };
65
+
66
+ // 过滤widgets,只保留在allowedParamNames中的widget
67
+ if (node.widgets && node.widgets.length > 0) {
68
+ nodeInfo.widgets = node.widgets
69
+ .filter((widget) => {
70
+ return (
71
+ widget.type !== "hidden" &&
72
+ !widget.disabled &&
73
+ allowedParamNames.includes(String(widget.name))
74
+ );
75
+ })
76
+ .map((widget) => {
77
+ const widgetInfo = {
78
+ name: String(widget.name || ""),
79
+ value: widget.value != null ? widget.value : "",
80
+ type: String(widget.type || ""),
81
+ };
82
+
83
+ // 处理options属性
84
+ if (widget.options && widget.options.values) {
85
+ widgetInfo.options = { values: [] };
86
+
87
+ if (Array.isArray(widget.options.values)) {
88
+ widgetInfo.options.values = [...widget.options.values];
89
+ } else if (typeof widget.options.values === "function") {
90
+ try {
91
+ const values = widget.options.values();
92
+ if (Array.isArray(values)) {
93
+ widgetInfo.options.values = [...values];
94
+ }
95
+ } catch (e) {
96
+ // 忽略错误
97
+ }
98
+ }
99
+ }
52
100
 
53
- // 获取节点的允许参数列表
54
- const nodeParamsInfo = nodeParamsMap.get(String(node.id));
55
- const allowedParamNames = nodeParamsInfo.paramNames;
56
-
57
- // 提取节点信息
58
- const nodeInfo = {
59
- id: node.id,
60
- type: node.type,
61
- comfyClass: node.comfyClass,
62
- title: node.title || nodeParamsInfo.displayName,
63
- widgets: []
64
- };
65
-
66
- // 过滤widgets,只保留在allowedParamNames中的widget
67
- if (node.widgets && node.widgets.length > 0) {
68
- nodeInfo.widgets = node.widgets
69
- .filter(widget => {
70
- return widget.type !== "hidden" &&
71
- !widget.disabled &&
72
- allowedParamNames.includes(String(widget.name));
73
- })
74
- .map(widget => {
75
- const widgetInfo = {
76
- name: String(widget.name || ""),
77
- value: widget.value != null ? widget.value : "",
78
- type: String(widget.type || "")
79
- };
80
-
81
- // 处理options属性
82
- if (widget.options && widget.options.values) {
83
- widgetInfo.options = { values: [] };
84
-
85
- if (Array.isArray(widget.options.values)) {
86
- widgetInfo.options.values = [...widget.options.values];
87
- } else if (typeof widget.options.values === 'function') {
88
- try {
89
- const values = widget.options.values();
90
- if (Array.isArray(values)) {
91
- widgetInfo.options.values = [...values];
92
- }
93
- } catch (e) {
94
- // 忽略错误
95
- }
96
- }
97
- }
98
-
99
- return widgetInfo;
100
- });
101
- }
101
+ return widgetInfo;
102
+ });
103
+ }
102
104
 
103
- // 如果过滤后没有可配置的参数,则不符合条件
104
- if (nodeInfo.widgets.length === 0) {
105
- console.log(`节点 ${node.id} 没有可配置的参数`);
106
- return null;
107
- }
105
+ // 如果过滤后没有可配置的参数,则不符合条件
106
+ if (nodeInfo.widgets.length === 0) {
107
+ console.log(`节点 ${node.id} 没有可配置的参数`);
108
+ return null;
109
+ }
108
110
 
109
- return nodeInfo;
111
+ return nodeInfo;
110
112
  }
111
113
 
112
114
  /**
@@ -115,7 +117,7 @@ function filterNodeWidgets(node) {
115
117
  * @returns {boolean} - 节点是否可配置
116
118
  */
117
119
  function isConfigurableNode(nodeId) {
118
- return nodeParamsMap.has(String(nodeId));
120
+ return nodeParamsMap.has(String(nodeId));
119
121
  }
120
122
 
121
123
  /**
@@ -124,13 +126,13 @@ function isConfigurableNode(nodeId) {
124
126
  * @returns {Object|null} - 节点参数信息
125
127
  */
126
128
  function getNodeParamsInfo(nodeId) {
127
- return nodeParamsMap.get(String(nodeId)) || null;
129
+ return nodeParamsMap.get(String(nodeId)) || null;
128
130
  }
129
131
 
130
132
  // 导出模块
131
133
  export {
132
- setNodeParams,
133
- filterNodeWidgets,
134
- isConfigurableNode,
135
- getNodeParamsInfo
134
+ setNodeParams,
135
+ filterNodeWidgets,
136
+ isConfigurableNode,
137
+ getNodeParamsInfo,
136
138
  };