/* * Extracted from browser-delivered Turbopack chunk: fd0220e4d10052af.701bdafa2d.js * Module id: 414356 * For reading/searching only; this factory depends on the original Turbopack runtime. */ const moduleFactory = (e) => { "use strict"; var t = e.i(462214), n = e.i(358379), i = e.i(768924), r = e.i(41671), a = e.i(777784), o = e.i(944733), s = e.i(485615), c = e.i(703962), l = e.i(713118), u = e.i(182004), h = e.i(677588), f = e.i(216257), d = e.i(898823), p = e.i(111581), g = e.i(959248), b = e.i(464025), m = e.i(233038), w = e.i(44980), v = e.i(41114), x = e.i(463672), y = e.i(210550), _ = e.i(970683), S = e.i(185264), E = e.i(745705), M = e.i(523520), T = e.i(855847), k = e.i(234954), C = e.i(848024), A = e.i(91134), N = e.i(299750), I = e.i(875707), P = e.i(136036), R = e.i(10036), L = e.i(174008); let D = "kling-v3-omni", j = [ { label: "1:1", threshold: 1 }, { label: "16:9", threshold: 16 / 9 }, { label: "9:16", threshold: 9 / 16 }, { label: "4:3", threshold: 4 / 3 }, { label: "3:4", threshold: 3 / 4 }, { label: "3:2", threshold: 1.5 }, { label: "2:3", threshold: 2 / 3 }, ]; function O(e, t) { let n; if (!e || !t || e <= 0 || t <= 0) return; let i = e / t, r = 1 / 0; for (let e of j) { let t = Math.abs(i - e.threshold); t < r && ((r = t), (n = e)); } return r < 0.15 ? n?.label : void 0; } function F({ totalCount: e, onClose: i, onGenerate: a, nodeId: o, initialImageSettings: s, firstChildDimensions: c, }) { let u = (0, f.useGlobalStore)((e) => e.defaultModel.video), h = (0, f.useGlobalStore)((e) => e.getModel), d = (0, S.useUserVipInfo)((e) => e.rateLimitBenefitStatus), p = (0, f.useGlobalStore)((e) => e.support?.storyboardVideo), g = (0, n.useMemo)(() => { let e = p?.map((e) => e.modelKey) ?? []; return e.includes(D) ? D : e.length > 0 ? e[0] : u; }, [p, u]), b = (0, n.useMemo)(() => (c ? O(c.width, c.height) : void 0), [c]), [m, w] = (0, n.useState)(() => { let e = {}; s && s.resolution && (e.resolution = s.resolution); let t = (0, l.extractRatioFromSettings)(s) ?? (c ? O(c.width, c.height) : void 0); if (t) { let n = h("storyboardVideo", g), i = n?.properties; if (i) { let n = Object.keys(i).find((e) => e.startsWith("ratio")); n && (e[n] = t); } } return { model: g, modeType: "singleImage2video", settings: e }; }), v = m.model || g, x = (0, n.useMemo)(() => h("storyboardVideo", v), [h, v]), y = (0, n.useMemo)( () => (0, P.buildStrikethroughEvaluationContextFromParams)({ settings: m.settings, }), [m.settings], ), _ = (0, P.isStrikethroughPriceEnabled)(h("storyboardVideo", v), y), j = (0, I.getActivePromotionTooltipText)(x), F = (0, n.useMemo)(() => { let e = ((x?.properties ?? {}).modeType ?? {}).items ?? {}; return "singleImage2video" in e ? "singleImage2video" : "image2video" in e ? "image2video" : "text2video"; }, [x]); (0, n.useEffect)(() => { if (!b || !x) return; let e = x.properties; if (!e) return; let t = Object.keys(e).find((e) => e.startsWith("ratio")); if (!t) return; let n = e[t]; !n?.enum || (n.enum .map((e) => ("string" == typeof e ? e : e?.value)) .includes(b) && w((e) => e.settings?.[t] ? e : { ...e, settings: { ...e.settings, [t]: b } }, )); }, [b, x]), (0, n.useEffect)(() => { w((e) => (e.modeType === F ? e : { ...e, modeType: F })); }, [F]); let U = (0, n.useCallback)( (e) => { e !== v && w((t) => ({ ...t, model: e })); }, [v], ), B = (0, n.useMemo)( () => ({ prompt: "", model: v, modeType: F, count: 1, settings: m.settings ?? {}, }), [v, F, m.settings], ), H = (0, n.useCallback)((e) => { void 0 !== e.settings && w((t) => ({ ...t, settings: { ...t.settings, ...e.settings } })); }, []), z = (0, n.useMemo)(() => { let e = m.cameraControl; return ( e || (e = (0, A.loadCameraControlStorage)() ?? void 0), { prompt: "", model: v, count: 1, settings: {}, cameraControl: e } ); }, [m.cameraControl, v]), G = (0, n.useCallback)((e) => { void 0 !== e.cameraControl && w((t) => ({ ...t, cameraControl: e.cameraControl })); }, []), $ = (0, f.useCanvasStore)((e) => e.projectId), [V, W] = (0, n.useState)(null), K = (0, n.useRef)(h); K.current = h; let q = (0, n.useMemo)( () => JSON.stringify(m.settings ?? {}), [m.settings], ); (0, n.useEffect)(() => { let e = !1, t = setTimeout(() => { let t = { prompt: "", model: v, modeType: F, count: 1, settings: m.settings ?? {}, }, n = (0, R.buildRequestData)( t, "video", o ?? "", $ ?? "", K.current, ); (0, N.calculatePower)(n) .then((t) => { if (!e && t?.code === 0) { let e = t.data; W({ power: e?.power ?? 0, originalPrice: e?.originalPrice }); } }) .catch(() => { e || W(null); }); }, 300); return () => { (e = !0), clearTimeout(t); }; }, [v, q, o, $, d]); let X = V?.power ?? null, [Y, J] = (0, n.useState)(!1), Z = (0, n.useCallback)(async () => { if (!Y) { J(!0); try { await a({ ...m, modelSchema: x }); } finally { J(!1); } } }, [m, x, a, Y]); return (0, t.jsx)(k.PopoverManagerProvider, { children: (0, t.jsx)("div", { className: "nodrag nopan nowheel flex w-max items-center gap-0", onPointerDown: (e) => e.stopPropagation(), onMouseDown: (e) => e.stopPropagation(), onClick: (e) => e.stopPropagation(), children: (0, t.jsxs)("div", { className: "flex items-center justify-center gap-1 px-1", style: L.FLOATING_TOOLBAR_STYLE, children: [ (0, t.jsx)("button", { type: "button", onClick: i, className: "flex h-8 w-8 min-w-8 shrink-0 items-center justify-center rounded-lg text-neutral-50 transition-colors hover:bg-white/10", children: (0, t.jsx)(r.Icons.x, { className: "h-3 w-3" }), }), (0, t.jsx)("div", { className: "mx-0.5 h-5", style: { width: 0, borderLeft: "0.5px solid rgba(255, 255, 255, 0.08)", }, }), (0, t.jsx)(T.default, { type: "storyboardVideo", value: v, onChange: U, }), (0, t.jsx)("div", { className: "mx-0.5 h-5", style: { width: 0, borderLeft: "0.5px solid rgba(255, 255, 255, 0.08)", }, }), (0, t.jsx)(C.default, { params: B, modelSchema: x, onParamsChange: H, }), (0, t.jsx)("div", { className: "mx-0.5 h-5", style: { width: 0, borderLeft: "0.5px solid rgba(255, 255, 255, 0.08)", }, }), (0, t.jsx)(M.default, { params: z, modelSchema: x, onParamsChange: G, }), (0, t.jsx)("div", { className: "mx-0.5 h-5", style: { width: 0, borderLeft: "0.5px solid rgba(255, 255, 255, 0.08)", }, }), (0, t.jsxs)("span", { className: "whitespace-nowrap px-2 text-[13px] text-neutral-50/70", children: ["全部 ", e, " 个分镜"], }), (0, t.jsx)("div", { className: "mx-0.5 h-5", style: { width: 0, borderLeft: "0.5px solid rgba(255, 255, 255, 0.08)", }, }), (0, t.jsx)("button", { type: "button", onClick: () => { Z(); }, disabled: Y, className: `bg-btn-invert-bg text-btn-invert-text flex h-8 items-center justify-center gap-1 rounded-lg px-3 py-2 transition-all ${Y ? "cursor-not-allowed opacity-60" : "hover:bg-btn-invert-bg-hover active:bg-btn-invert-bg-active cursor-pointer"}`, children: Y ? (0, t.jsx)("span", { className: "text-btn-invert-text text-xs font-normal leading-none", children: "审核中…", }) : (0, t.jsxs)(t.Fragment, { children: [ (0, t.jsx)(E.GeneratorPowerCostDisplay, { strikethroughPrice: _, power: null != X ? X : "-", originalPrice: V?.originalPrice, scale: e, isCalculating: !1, promotionTooltip: j, iconClassName: "text-btn-invert-text", valueClassName: "text-btn-invert-text min-w-[14px] text-xs leading-none", }), (0, t.jsx)("span", { className: "text-btn-invert-text text-xs font-normal leading-none", children: "生成视频", }), ], }), }), ], }), }), }); } var U = e.i(978783); async function B(e) { let { children: t, signal: n, onAssetIdResolved: i, onCheckingStateChange: r, } = e, o = new Map(); for (let e of t) { let t = e.data; t?.portraitAssetId && o.set(e.id, t.portraitAssetId); } let s = []; for (let e of t) { let t = e.data; if (!t?.scriptRowHiddenUuid) continue; let n = t.url?.[0]; n && (t.portraitAssetId || s.push({ nodeId: e.id, url: n })); } if (0 === s.length) return { ok: !0, portraitAssetIdByChildId: o }; for (let e of s) r?.(e.nodeId, !0); try { let e = await Promise.all( s.map((e) => (0, U.createComplianceAsset)(e.url, "image").catch(() => null), ), ); if (n.aborted) return { ok: !1, portraitAssetIdByChildId: o }; let t = new Map(), r = new Set(); for (let n = 0; n < s.length; n++) { let i = e[n]; i ? t.set(i, s[n].nodeId) : r.add(s[n].nodeId); } if (0 === t.size) return ( a.Notify.error("合规审核发起失败,请稍后重试"), { ok: !1, portraitAssetIdByChildId: o } ); let c = await (0, U.pollComplianceUntilDone)([...t.keys()], n); if (n.aborted) return { ok: !1, portraitAssetIdByChildId: o }; let l = new Set(r); for (let [e, n] of c) { let r = t.get(e); r && (1 === n.status && n.assetId ? (o.set(r, n.assetId), i(r, n.assetId)) : l.add(r)); } for (let [e, n] of t) c.has(e) || l.add(n); if (l.size > 0) return ( a.Notify.error( `有 ${l.size} 张分镜图未通过 Seedance 合规检测,若为真人图片,请前往角色库录入真人资产后重试`, ), { ok: !1, portraitAssetIdByChildId: o } ); return { ok: !0, portraitAssetIdByChildId: o }; } finally { for (let e of s) r?.(e.nodeId, !1); } } function H(e) { return { w: e.measured?.width ?? e.width ?? 200, h: e.measured?.height ?? e.height ?? 120, }; } function z({ groupNodeId: e }) { let [i, a] = (0, n.useState)(null), [o, s] = (0, n.useState)(!0); return ((0, n.useEffect)(() => { let t = !1; return ( (0, d.calculateGroupPower)(e) .then((e) => { t || a(e); }) .catch(() => { t || a({ totalPower: 0, nodeCount: 0, hasError: !0 }); }) .finally(() => { t || s(!1); }), () => { t = !0; } ); }, [e]), o) ? (0, t.jsxs)("div", { className: "text-fg-muted flex items-center gap-2 text-[13px]", children: [ (0, t.jsx)(r.Icons.loader2, { className: "size-4 animate-spin" }), (0, t.jsx)("span", { children: "正在计算算力消耗…" }), ], }) : !i || i.hasError ? (0, t.jsxs)("div", { className: "text-fg-muted flex flex-col gap-1 text-[13px]", children: [ (0, t.jsxs)("span", { children: [ "即将对组内 ", i?.nodeCount ?? 0, " 个生成节点依次执行,算力消耗计算异常,是否继续?", ], }), (0, t.jsx)("span", { className: "text-fg-subtle text-[12px]", children: "仅生成节点会被执行,特殊节点需手动执行。", }), ], }) : (0, t.jsxs)("div", { className: "text-fg-muted flex flex-col gap-1 text-[13px]", children: [ (0, t.jsxs)("span", { children: [ "即将对组内 ", (0, t.jsx)("span", { className: "text-fg-default font-medium", children: i.nodeCount, }), " ", "个生成节点依次执行,预计消耗 ", (0, t.jsx)("span", { className: "text-fg-default font-medium", children: i.totalPower, }), " ", "算力,是否继续?", ], }), (0, t.jsx)("span", { className: "text-fg-subtle text-[12px]", children: "仅生成节点会被执行,特殊节点需手动执行。", }), ], }); } function G({ id: e, data: r, selected: d }) { let { ungroupNode: S, openCreateAssetModal: E, openCreateWorkflowModal: M, takeSnapshot: T, runGroupPipeline: k, regenGridGroup: C, stopGroupPipeline: A, resetGroupPipelineState: N, pipelineStates: I, downloadNodesAsZip: P, } = (0, p.useCanvasCallbacks)(), { getNodes: R } = (0, i.useReactFlow)(), L = (0, f.useCanvasStore)((e) => e.updateNode), D = (0, f.useCanvasStore)((e) => e.updateNodeData), j = (0, f.useCanvasStore)((e) => e.updateNodes), O = (0, f.useCanvasStore)((e) => e.isReadonly), U = (0, b.useShouldShowGenerator)(d, e), G = (0, i.useReactFlow)(), $ = r?.groupColor ?? null, V = r?.workflowUuid || void 0, W = r?.sourceScriptNodeId || void 0, K = r?.storyboardGroupType || void 0, q = !!W, X = q && "image" === K, Y = q && "video" === K, J = r?.name || r?.label || (q ? "分镜图" : "分组"), Z = (0, n.useMemo)(() => { let e = r?.name; return "string" == typeof e ? e.startsWith("宫格生图组") : null != e && JSON.stringify(e).startsWith("宫格生图组"); }, [r?.name]), Q = (0, f.useCanvasStore)( (0, n.useCallback)( (t) => !!Z && t.nodes.some((t) => t.parentId === e && t.data?.isStale === !0), [e, Z], ), ), ee = (0, n.useCallback)(() => { for (let t of f.stores.canvas?.nodes ?? []) t.parentId === e && t.data?.isStale && D(t.id, { isStale: !1 }); }, [e, D]), et = (0, n.useCallback)(() => { ee(), Z ? C(e) : k(e); }, [e, Z, ee, C, k]), en = (0, i.useStore)((e) => e.transform[2]), ei = (0, f.useCanvasStore)( (0, n.useCallback)( (t) => { let n = t.getNode(e); return n?.measured?.width ?? n?.width ?? void 0; }, [e], ), ), er = (0, n.useMemo)(() => { if (Z && Q && ei) return ei / Math.min(1 / en, 2); }, [Z, Q, ei, en]), [ea, eo] = (0, n.useState)(!1), [es, ec] = (0, n.useState)(!1), el = (0, n.useRef)(null), eu = (0, n.useRef)(null), eh = (0, n.useRef)(!1), ef = (0, n.useCallback)((t) => D(e, { name: t }), [e, D]), ed = I[e], ep = !!ed?.running, eg = !!ed; (0, n.useEffect)(() => { L(e, { zIndex: d ? 1e3 : -1001 }); }, [e, d, L]); let eb = (0, n.useRef)(d); (0, n.useEffect)(() => { eb.current && !d && eg && !ep && N(e), eb.current && !d && ea && (eu.current?.abort(), (eu.current = null), eo(!1)), (eb.current = d); }, [d, e, eg, ep, N, ea]), (0, n.useEffect)( () => () => { eu.current?.abort(); }, [], ), (0, n.useEffect)(() => { if (ea) { el.current || (el.current = G.getViewport()); let t = f.stores.canvas?.nodes?.find((t) => t.id === e); if (t) { let e = t.measured?.width ?? t.width ?? 500, n = t.measured?.height ?? t.height ?? 300, i = document.querySelector(".react-flow"), r = i?.clientWidth ?? window.innerWidth, a = (i?.clientHeight ?? window.innerHeight) - 100 - 120 - 32, o = Math.min((r - 160) / e, a / n, 1.2), s = r / 2 - (t.position.x + e / 2) * o, c = 116 + a / 2 - (t.position.y + n / 2) * o; G.setViewport({ x: s, y: c, zoom: o }, { duration: 300 }); } } else el.current && (G.setViewport(el.current, { duration: 300 }), (el.current = null)); }, [ea]), (0, n.useEffect)(() => { if (!ea) return; let e = (e) => { "Escape" === e.key && (e.stopPropagation(), eo(!1)); }; return ( window.addEventListener("keydown", e), () => window.removeEventListener("keydown", e) ); }, [ea]); let em = (0, n.useCallback)(() => { (0, h.reportLog)({ e: "libtv.canvas.storyboard.generate_video_group.click", }), eo(!0); }, []), ew = (0, n.useCallback)(() => { eu.current?.abort(), (eu.current = null), eo(!1); }, []), ev = (0, n.useCallback)(() => { if (W) { for (let t of (D(W, { linkedImageGroupId: void 0 }), (f.stores.canvas?.nodes ?? []).filter((t) => t.parentId === e))) { let e = t.data; e?.scriptRowHiddenUuid && D(t.id, { scriptRowHiddenUuid: void 0, taskInfo: void 0 }); } D(e, { sourceScriptNodeId: void 0, storyboardTitle: void 0 }); } }, [e, W, D]), ex = (0, n.useCallback)(() => { let t; (t = Y ? "解组后脚本关联关系将消失,重新生成时将不再关联脚本信息了。确定要解组吗?" : q ? "解组后关联关系将消失,无法重新生成关联分镜图和批量生视频了。确定要解组吗?" : ep ? "解组将终止当前整组执行,确定解组并终止整组执行吗?" : "确定要解散当前分组吗?解组后节点将恢复为独立状态。"), (0, h.reportLog)({ e: "libtv.canvas.storyboard.ungroup.click" }), (0, o.confirm)({ title: "解组", message: t, confirmText: "确定解组", cancelText: "取消", onConfirm: () => { eg && N(e), q && ev(), S(e); }, }); }, [e, S, ep, q, Y, eg, N, ev]), ey = (0, n.useCallback)( (t) => { let n = t ? `${t}1A` : "var(--canvas-group-bg)", i = t ? `${t}33` : "var(--canvas-group-border)", r = { background: n, border: `1px solid ${i}` }; D(e, { groupColor: t }), L(e, { zIndex: -1001, style: r }); }, [e, D, L], ), e_ = (0, n.useCallback)(async () => { let t = await k(e); t.failed ? a.Notify.error(`执行失败:节点 ${t.failed}`) : t.completed.length > 0 && a.Notify.success(`执行完成:${t.completed.length} 个节点`); }, [e, k]), eS = (0, n.useCallback)(() => { if (!W) return; let t = f.stores.canvas?.nodes ?? [], n = t.find((e) => e.id === W); if (!n) return; let i = n.data, r = i?.rows ?? [], o = t.filter((t) => t.parentId === e), s = o .filter((e) => { let t = e.data; return t?.scriptRowHiddenUuid; }) .sort((e, t) => { let n = e.data?.name, i = t.data?.name; return (n ?? "").localeCompare(i ?? "", void 0, { numeric: !0, }); }); if ( !s.some((e) => { let t = e.data; return r.some((e) => e.hiddenUuid === t.scriptRowHiddenUuid); }) && s.length > 0 && r.length > 0 ) { let t = f.stores.canvas?.deleteNodes, n = f.stores.canvas?.addNode; if (!t || !n) return; if (r.length === s.length) { for (let e = 0; e < s.length; e++) { let t = r[e]; D(s[e].id, { action: u.NodeAction.IMAGE_GENERATE, scriptRowHiddenUuid: t.hiddenUuid, name: `分镜 #${t.shotNumber}`, params: { ...(s[e].data.params ?? {}), prompt: t.imageGenerationPrompt || t.plotDescription || "", }, taskInfo: { taskId: "", loading: !0, status: 0 }, }); } a.Notify.info( `脚本已变更,已按新脚本重新绑定并触发 ${s.length} 张分镜图生成`, ); } else { let o = i.imageGenConfig, c = (0, l.extractRatioFromNodeParams)(o), h = (0, l.computeNodeDimensionsFromRatio)(c), f = { ...o?.settings }, d = Math.ceil(Math.sqrt(r.length)); t(s.map((e) => e.id)); for (let t = 0; t < r.length; t++) { let i = r[t], a = t % d, s = Math.floor(t / d); n( { id: crypto.randomUUID(), type: u.NodeType.IMAGE, data: { type: u.NodeType.IMAGE, name: `分镜 #${i.shotNumber}`, url: [], action: u.NodeAction.IMAGE_GENERATE, scriptRowHiddenUuid: i.hiddenUuid, taskInfo: { taskId: "", loading: !0, status: 0 }, params: { prompt: i.imageGenerationPrompt || i.plotDescription || "", model: o?.model ?? "", modeType: "text2image", settings: f, scene: "group-generate", ...(o?.model === "z-image" ? { promptMagic: 1 } : {}), }, }, position: { x: m.GROUP_PADDING + a * (h.width + m.GROUP_PADDING), y: m.GROUP_PADDING + s * (h.height + m.GROUP_PADDING), }, parentId: e, width: h.width, height: h.height, }, { skipOverlapResolution: !0 }, ); } let p = Math.ceil(r.length / d); L(e, { style: { width: 2 * m.GROUP_PADDING + d * h.width + (d - 1) * m.GROUP_PADDING, height: 2 * m.GROUP_PADDING + p * h.height + (p - 1) * m.GROUP_PADDING, }, }), a.Notify.info( `脚本结构已变更(${s.length}→${r.length}),已重新创建分镜图并触发生成`, ); } return; } let c = []; for (let e of r) { let t = o.find((t) => { let n = t.data; return n?.scriptRowHiddenUuid === e.hiddenUuid; }); if (t) { let e = t.data; c.push({ id: t.id, needsRegen: !e.url?.length || (0, g.isTaskFailed)(e.taskInfo), }); } } let h = c.filter((e) => e.needsRegen), d = h.length > 0 ? h : c; for (let e of d) D(e.id, { taskInfo: { taskId: "", loading: !0, status: 0 } }); a.Notify.info( h.length > 0 ? `已触发 ${d.length} 张未完成分镜图重新生成` : `已触发全部 ${d.length} 张分镜图重新生成`, ); }, [e, W, D, L]), eE = (0, n.useCallback)(() => { let t = (f.stores.canvas?.nodes ?? []) .filter((t) => t.parentId === e) .filter((e) => e.type === u.NodeType.VIDEO); if (0 === t.length) return; let n = t.filter((e) => { let t = e.data; return !t.url?.length || (0, g.isTaskFailed)(t.taskInfo); }), i = n.length > 0 ? n : t; for (let e of i) D(e.id, { taskInfo: { taskId: "", loading: !0, status: 0 } }); a.Notify.info( n.length > 0 ? `已触发 ${i.length} 个未完成视频重新生成` : `已触发全部 ${i.length} 个视频重新生成`, ); }, [e, D]), eM = (0, n.useCallback)(() => { if (ep) return void A(e); if (X) { (0, h.reportLog)({ e: "libtv.canvas.storyboard.regenerate.click" }), (0, o.confirm)({ title: "重新生成分镜图", message: "将对未生成或失败的分镜图重新生成,是否继续?", confirmText: "开始生成", cancelText: "取消", onConfirm: eS, }); return; } if (Y) { let t = (f.stores.canvas?.nodes ?? []) .filter((t) => t.parentId === e && t.type === u.NodeType.VIDEO) .filter((e) => { let t = e.data; return !t.url?.length || (0, g.isTaskFailed)(t.taskInfo); }).length; (0, o.confirm)({ title: "重新生成视频", message: t > 0 ? `将对 ${t} 个未完成视频重新生成,是否继续?` : `所有视频重新生成,是否继续?`, confirmText: "开始生成", cancelText: "取消", onConfirm: eE, }); return; } (0, o.confirm)({ title: "整组执行", message: (0, t.jsx)(z, { groupNodeId: e }), confirmText: "开始执行", cancelText: "取消", onConfirm: () => { e_(); }, }); }, [e, ep, X, Y, A, e_, eS, eE]), eT = (0, n.useCallback)(() => { V ? M(e, { initialTab: "update", initialWorkflowId: V }) : M(e); }, [e, V, M]), ek = (0, n.useCallback)( (t, n) => { let i = R().filter((t) => t.parentId === e); if (0 === i.length) return void L(e, { position: { x: n.x, y: n.y }, width: n.width, height: n.height, }); let r = 1 / 0, a = 1 / 0, o = -1 / 0, s = -1 / 0; i.forEach((e) => { let { w: t, h: n } = H(e); (r = Math.min(r, e.position.x)), (a = Math.min(a, e.position.y)), (o = Math.max(o, e.position.x + t)), (s = Math.max(s, e.position.y + n)); }); let c = r < m.GROUP_MIN_PADDING ? m.GROUP_MIN_PADDING - r : 0, l = a < m.GROUP_MIN_PADDING ? m.GROUP_MIN_PADDING - a : 0; L(e, { position: { x: n.x - c, y: n.y - l }, width: Math.max(n.width + c, o + m.GROUP_MIN_PADDING), height: Math.max(n.height + l, s + m.GROUP_MIN_PADDING), }), (c > 0 || l > 0) && j( i.map((e) => ({ id: e.id, updates: { position: { x: e.position.x + c, y: e.position.y + l }, }, })), ); }, [e, R, L, j], ), eC = (0, n.useCallback)( async (t) => { if (eh.current || !W || O) return !1; eh.current = !0; try { let n, i = R() .filter((t) => t.parentId === e) .sort((e, t) => { let n = e.data?.name, i = t.data?.name; return (n ?? "").localeCompare(i ?? "", void 0, { numeric: !0, }); }), r = (f.stores.canvas?.nodes ?? []).find((e) => e.id === W); if (!r) return !1; let o = r.data, s = o?.rows ?? [], c = i.filter((e) => { let t = e.data; return t?.scriptRowHiddenUuid; }); if ( c.length > 0 && s.length > 0 && !c.some((e) => { let t = e.data; return s.some((e) => e.hiddenUuid === t.scriptRowHiddenUuid); }) ) return ( a.Notify.warn( "脚本已变更,请先重新生成分镜图后再批量生成视频", ), !1 ); let h = new Map(); if (((n = t.modelSchema?.properties), n?.portrait === !0)) { let e = new AbortController(); eu.current = e; try { let t = await B({ children: i, signal: e.signal, onAssetIdResolved: (e, t) => D(e, { portraitAssetId: t }), onCheckingStateChange: (e, t) => D(e, { _starVideoCheckStatus: t ? "checking" : void 0 }), }); if (!t.ok) return !1; h = t.portraitAssetIdByChildId; } finally { eu.current = null; } } else for (let e of i) { let t = e.data; t?.portraitAssetId && h.set(e.id, t.portraitAssetId); } let d = crypto.randomUUID(), { videoNodes: p, gridWidth: g, gridHeight: b, } = (function (e) { let { children: t, rows: n, config: i, portraitAssetIdByChildId: r, groupNodeId: a, } = e, o = (0, l.extractRatioFromNodeParams)(i), s = (0, l.computeNodeDimensionsFromRatio)(o), c = s.width, h = s.height, f = Math.ceil(Math.sqrt(t.length)), d = []; for (let e of t) { let t = e.data; if (!t?.scriptRowHiddenUuid) continue; let o = n.find( (e) => e.hiddenUuid === t.scriptRowHiddenUuid, ), s = o?.videoMotionPrompt || "", l = t.url?.[0] || "", p = r.get(e.id), g = d.length, b = g % f, m = Math.floor(g / f), w = l ? [ p ? { nodeId: e.id, url: l, assetId: p } : { nodeId: e.id, url: l }, ] : []; d.push({ id: crypto.randomUUID(), type: "video", data: { type: "video", action: u.NodeAction.VIDEO_GENERATE, name: `分镜视频-#${o?.shotNumber ?? g + 1}`, url: [], poster: l, scriptRowHiddenUuid: t.scriptRowHiddenUuid, taskInfo: { taskId: "", loading: !0, status: 0 }, params: { prompt: s, model: i.model || "", modeType: l ? i.modeType || "singleImage2video" : "text2video", settings: i.settings ?? {}, image: l, imageList: w, scene: "group-generate", }, }, position: { x: 40 + b * (c + 40), y: 70 + m * (h + 40) }, parentId: a, width: c, height: h, }); } let p = Math.ceil(d.length / f); return { videoNodes: d, gridWidth: 80 + f * c + (f - 1) * 40, gridHeight: 110 + p * h + (p - 1) * 40, cols: f, }; })({ children: i, rows: s, config: t, portraitAssetIdByChildId: h, groupNodeId: d, }); if (0 === p.length) return !1; let m = R(), v = m.find((t) => t.id === e), x = v?.measured?.width ?? 500, y = (0, w.findRightSidePosition)( v?.position ?? { x: 0, y: 0 }, x, { width: g, height: b }, m, f.stores.canvas?.edges ?? [], e, ), _ = f.stores.canvas?.addNode, S = f.stores.canvas?.addEdge; if (!_ || !S) return !1; for (let e of (_({ id: d, type: "group", data: { type: "group", name: `视频组 \xb7 ${J}`, groupColor: null, sourceScriptNodeId: W, storyboardTitle: `视频组 \xb7 ${J}`, storyboardGroupType: "video", }, position: y, zIndex: -1001, style: { background: "var(--canvas-group-bg)", border: "1px solid var(--canvas-group-border)", }, width: g, height: b, measured: { width: g, height: b }, }), p)) _(e, { skipOverlapResolution: !0 }); return ( S({ id: crypto.randomUUID(), source: e, sourceHandle: "source", target: d, targetHandle: "target", }), f.stores.canvas?.requestImmediateFlush(), eo(!1), setTimeout(() => { let e = R().map((e) => ({ type: "select", id: e.id, selected: e.id === d, })); e.push({ type: "select", id: d, selected: !0 }), f.stores.canvas?.applyNodeChanges(e), G.fitBounds( { x: y.x, y: y.y, width: g, height: b }, { duration: 400, padding: 0.15 }, ); }, 100), !0 ); } finally { eh.current = !1; } }, [e, W, O, R, J, D, G], ), eA = (0, n.useCallback)( (t) => { T(); let n = R(), i = n .filter((t) => t.parentId === e) .sort((e, t) => { let n = e.data?.name, i = t.data?.name; return (n ?? "").localeCompare(i ?? "", void 0, { numeric: !0, }); }); if (0 === i.length) return; let { positions: r, width: a, height: o, } = "grid" === t ? (function (e) { if (0 === e.length) return { positions: new Map(), width: 0, height: 0 }; let t = e.map((e) => H(e)), n = Math.max(...t.map((e) => e.w)), i = Math.max(...t.map((e) => e.h)), r = Math.ceil(Math.sqrt(e.length)), a = Math.ceil(e.length / r), o = new Map(); return ( e.forEach((e, t) => { let a = Math.floor(t / r); o.set(e.id, { x: m.GROUP_LAYOUT_PADDING + (t % r) * (n + m.GROUP_LAYOUT_GAP), y: m.GROUP_LAYOUT_TOP_PADDING + a * (i + m.GROUP_LAYOUT_GAP), }); }), { positions: o, width: 2 * m.GROUP_LAYOUT_PADDING + r * n + (r - 1) * m.GROUP_LAYOUT_GAP, height: m.GROUP_LAYOUT_TOP_PADDING + m.GROUP_LAYOUT_PADDING + a * i + (a - 1) * m.GROUP_LAYOUT_GAP, } ); })(i) : "horizontal" === t ? (function (e) { if (0 === e.length) return { positions: new Map(), width: 0, height: 0 }; let t = new Map(), n = m.GROUP_LAYOUT_PADDING, i = 0; return ( e.forEach((e) => { let { w: r, h: a } = H(e); t.set(e.id, { x: n, y: m.GROUP_LAYOUT_TOP_PADDING }), (n += r + m.GROUP_LAYOUT_GAP), (i = Math.max(i, a)); }), { positions: t, width: n - m.GROUP_LAYOUT_GAP + m.GROUP_LAYOUT_PADDING, height: m.GROUP_LAYOUT_TOP_PADDING + i + m.GROUP_LAYOUT_PADDING, } ); })(i) : (function (e) { if (0 === e.length) return { positions: new Map(), width: 0, height: 0 }; let t = new Map(), n = m.GROUP_LAYOUT_TOP_PADDING, i = 0; return ( e.forEach((e) => { let { w: r, h: a } = H(e); t.set(e.id, { x: m.GROUP_LAYOUT_PADDING, y: n }), (n += a + m.GROUP_LAYOUT_GAP), (i = Math.max(i, r)); }), { positions: t, width: 2 * m.GROUP_LAYOUT_PADDING + i, height: n - m.GROUP_LAYOUT_GAP + m.GROUP_LAYOUT_PADDING, } ); })(i), s = { width: a, height: o, measured: { width: a, height: o }, style: { ...(n.find((t) => t.id === e)?.style ?? {}) }, }, c = i .map((e) => { let t = r.get(e.id); return t ? { id: e.id, updates: { position: t } } : null; }) .filter(Boolean); L(e, s), c.length > 0 && j(c); }, [e, R, L, j, T], ); return (0, t.jsxs)(t.Fragment, { children: [ !O && (0, t.jsx)(i.NodeResizer, { isVisible: !!U, minWidth: 120, minHeight: 80, onResizeEnd: ek, lineStyle: { borderColor: d ? "var(--canvas-node-border-selected)" : "transparent", }, handleStyle: { width: 8, height: 8, borderRadius: 2, backgroundColor: "var(--canvas-node-border-selected)", border: "none", }, }), !O && U && !ea && (0, t.jsx)(c.default, { nodeId: e, baseOffset: 20, zIndex: 1e3, children: (0, t.jsx)(_.GroupNodeToolbar, { groupColor: $, workflowUuid: V, isGroupRunning: ep, isStoryboardGroup: q, isStoryboardImageGroup: X, pipelineProgress: ep && ed ? `${ed.currentIndex + 1}/${ed.plan.length}` : void 0, onColorChange: ey, onUngroup: ex, onRunGroup: eM, onCreateWorkflow: eT, onLayoutChange: eA, onBatchGenerateVideo: em, groupNodeId: e, onDownloadAll: () => { let t = r?.childNodeIds ?? R() .filter((t) => t.parentId === e) .map((e) => e.id); t.length > 0 && P?.(t, { type: "group", groupId: e }); }, }), }), (0, t.jsx)(s.default, { className: (0, v.cn)( "absolute left-0 origin-bottom-left", es && "nopan nowheel", ), style: { bottom: "calc(100% + 10px)" }, hideWhenDragging: !1, noPan: es, noWheel: es, maxScale: 2, children: (0, t.jsx)(x.default, { nodeId: e, label: J, isStale: Z ? Q : void 0, onDismissStale: Z ? ee : void 0, onRetry: Z ? et : void 0, noPowerCost: Z || void 0, onLabelChange: ef, onEditingChange: ec, readOnly: O, maxWidth: er, variant: "inline", textClassName: "text-[13px] text-fg-muted", }), }), q && (0, t.jsx)(y.TargetHandle, { visible: !!d }), q && (0, t.jsx)(y.SourceHandle, { visible: !!d }), ea && X && U && (0, t.jsx)(s.default, { className: "absolute left-1/2 origin-top -translate-x-1/2", style: { top: "calc(100% + 16px)" }, children: (0, t.jsx)(F, { totalCount: R().filter((t) => t.parentId === e).length, onClose: ew, onGenerate: eC, nodeId: e, initialImageSettings: (() => { let t = (f.stores.canvas?.nodes ?? []).filter( (t) => t.parentId === e, )[0]; if (!t) return; let n = t.data; return n?.params?.settings ?? void 0; })(), firstChildDimensions: (() => { let t = (f.stores.canvas?.nodes ?? []).filter( (t) => t.parentId === e, )[0]; if (!t) return; let n = t.data, i = n?.contentWidth, r = n?.contentHeight; if ( "number" == typeof i && "number" == typeof r && i > 0 && r > 0 ) return { width: i, height: r }; })(), }), }), ], }); } e.s(["default", () => G], 414356); }; export default moduleFactory;