Line data Source code
1 : import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode'
2 : import { SUBGRAPH_INPUT_ID } from '@/lib/litegraph/src/constants'
3 : import { inputLink } from '@/lib/litegraph/src/node/slotLinks'
4 :
5 2355 : export const GLSL_NODE_TYPE = 'GLSLShader'
6 : export const DEBOUNCE_MS = 50
7 : export const DEFAULT_SIZE = 512
8 2355 : const MAX_PREVIEW_DIMENSION = 1024
9 :
10 22 : export function normalizeDimension(value: unknown): number {
11 22 : const parsed = Number(value)
12 22 : if (!Number.isFinite(parsed) || parsed <= 0) return DEFAULT_SIZE
13 22 : return parsed
14 : }
15 :
16 13 : export function clampResolution(w: number, h: number): [number, number] {
17 13 : const maxDim = Math.max(w, h)
18 13 : if (maxDim <= MAX_PREVIEW_DIMENSION) return [w, h]
19 0 : const scale = MAX_PREVIEW_DIMENSION / maxDim
20 0 : return [Math.round(w * scale), Math.round(h * scale)]
21 : }
22 :
23 0 : export function getInputNodeThroughSubgraphBoundary(
24 : node: LGraphNode,
25 : slot: number,
26 : ownerSubgraphNode: LGraphNode
27 : ): LGraphNode | null {
28 : const graph = node.graph
29 0 : if (!graph) return null
30 :
31 0 : const link = node.getInputLink(slot)
32 0 : if (!link || link.origin_id !== SUBGRAPH_INPUT_ID) return null
33 :
34 0 : const outerGraph = ownerSubgraphNode.graph
35 0 : if (!outerGraph) return null
36 0 : const outerLink = inputLink(
37 : outerGraph,
38 : ownerSubgraphNode.id,
39 : link.origin_slot
40 : )
41 0 : return outerLink ? outerGraph.getNodeById(outerLink.origin_id) : null
42 : }
|