@fses/workbench-app 0.1.2 → 0.2.0

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.
@@ -0,0 +1,1932 @@
1
+ import { L as Ft, a as it, r as Kt, l as zt, b as Vt } from "./cardFactory-CoDF-zsR.js";
2
+ const bt = [
3
+ { id: "card.header.left", kind: "slot", status: "active", displayName: "Card header left slot", userFacingName: "卡片标题左侧位置", description: "在卡片标题左侧挂载状态、图标或标签。", riskLevel: "low", sideEffects: [] },
4
+ { id: "card.header.right", kind: "slot", status: "active", displayName: "Card header right slot", userFacingName: "卡片标题右侧位置", description: "在卡片标题右侧挂载按钮、菜单或搜索入口。", riskLevel: "low", sideEffects: [] },
5
+ { id: "card.body.toolbar", kind: "slot", status: "active", displayName: "Card body toolbar slot", userFacingName: "卡片内容工具条位置", description: "在卡片内容顶部挂载筛选、排序或视图切换。", riskLevel: "low", sideEffects: [] },
6
+ { id: "card.body.inline", kind: "slot", status: "active", displayName: "Card body inline slot", userFacingName: "卡片内容内嵌位置", description: "在卡片内容区域内嵌搜索框、表单或结果列表。", riskLevel: "low", sideEffects: [] },
7
+ { id: "card.body.emptyState", kind: "slot", status: "active", displayName: "Card empty state slot", userFacingName: "卡片空态位置", description: "在卡片空态区域挂载创建、导入或引导动作。", riskLevel: "low", sideEffects: [] },
8
+ { id: "card.footer.actions", kind: "slot", status: "active", displayName: "Card footer action slot", userFacingName: "卡片底部动作位置", description: "在卡片底部挂载提交、打开页面或批量处理动作。", riskLevel: "low", sideEffects: [] },
9
+ { id: "card.detail.panel", kind: "slot", status: "active", displayName: "Card detail panel slot", userFacingName: "卡片详情面板位置", description: "在卡片详情面板中挂载扩展能力。", riskLevel: "low", sideEffects: [] },
10
+ { id: "workspace.banner.topRight", kind: "slot", status: "active", displayName: "Workspace banner top right slot", userFacingName: "欢迎横幅右上角位置", description: "在欢迎横幅右上角挂载全局入口。", riskLevel: "low", sideEffects: [] },
11
+ { id: "iconButton+popover", kind: "ui", status: "active", displayName: "Icon button with popover", userFacingName: "图标按钮和弹出面板", description: "点击图标按钮后打开一个小面板。", riskLevel: "low", sideEffects: [] },
12
+ { id: "inlinePanel", kind: "ui", status: "active", displayName: "Inline panel", userFacingName: "卡片内嵌面板", description: "在卡片内容中直接展示输入和结果区域。", riskLevel: "low", sideEffects: [] },
13
+ { id: "filterBar", kind: "ui", status: "active", displayName: "Filter bar", userFacingName: "筛选条", description: "用于组合多个筛选条件。", riskLevel: "low", sideEffects: [] },
14
+ { id: "dropdownMenu", kind: "ui", status: "planned", displayName: "Dropdown menu", userFacingName: "更多菜单", description: "用于承载一组次级操作。", riskLevel: "low", sideEffects: [] },
15
+ { id: "drawerPanel", kind: "ui", status: "active", displayName: "Drawer panel", userFacingName: "详情抽屉", description: "从页面侧边打开详情或操作面板。", riskLevel: "medium", sideEffects: [] },
16
+ { id: "cardSearchIndex", kind: "data", status: "active", displayName: "Card search index", userFacingName: "当前工作台卡片索引", description: "搜索当前工作台内的卡片名称、说明和摘要。", riskLevel: "low", sideEffects: [] },
17
+ { id: "routeTargetRegistry", kind: "data", status: "active", displayName: "Route target registry", userFacingName: "可打开页面目录", description: "读取系统中允许跳转的页面和参数。", riskLevel: "low", sideEffects: [] },
18
+ { id: "businessObjectQuery", kind: "data", status: "active", displayName: "Business object query", userFacingName: "业务数据查询", description: "读取销售明细、客户、流程等业务对象数据。", riskLevel: "medium", sideEffects: [] },
19
+ { id: "metricQuery", kind: "data", status: "planned", displayName: "Metric query", userFacingName: "指标数据查询", description: "读取企业指标、口径和趋势数据。", riskLevel: "medium", sideEffects: [] },
20
+ { id: "focusCard", kind: "action", status: "active", displayName: "Focus card", userFacingName: "定位到卡片", description: "把画布定位到指定卡片。", riskLevel: "low", sideEffects: [] },
21
+ { id: "openRoute", kind: "action", status: "active", displayName: "Open route", userFacingName: "打开页面", description: "打开已注册的系统页面并传递允许参数。", riskLevel: "medium", sideEffects: ["navigate"] },
22
+ { id: "refreshData", kind: "action", status: "active", displayName: "Refresh data", userFacingName: "刷新数据", description: "重新读取卡片或数据源内容。", riskLevel: "low", sideEffects: [] },
23
+ { id: "toggleFavorite", kind: "action", status: "active", displayName: "Toggle favorite", userFacingName: "收藏或取消收藏", description: "把卡片、记录或视图加入个人收藏。", riskLevel: "low", sideEffects: ["workspace_mutation"] },
24
+ { id: "exportData", kind: "action", status: "active", displayName: "Export data", userFacingName: "导出文件", description: "把查询结果导出为 Excel、CSV 或其他文件。", riskLevel: "medium", sideEffects: ["export"] },
25
+ { id: "tableSelection", kind: "action", status: "active", displayName: "Table selection", userFacingName: "选择表格行", description: "在表格卡片中选择一行或多行数据。", riskLevel: "low", sideEffects: [] },
26
+ { id: "openDrawer", kind: "action", status: "active", displayName: "Open drawer", userFacingName: "打开详情抽屉", description: "打开侧边详情面板展示记录详情。", riskLevel: "low", sideEffects: [] },
27
+ { id: "callApiAction", kind: "action", status: "active", displayName: "Call API action", userFacingName: "调用受控业务动作", description: "调用平台允许的业务动作接口,并记录审计。", riskLevel: "high", sideEffects: ["business_mutation"] },
28
+ { id: "submitForm", kind: "action", status: "planned", displayName: "Submit form", userFacingName: "提交表单", description: "提交业务表单并进入确认和审计链路。", riskLevel: "high", sideEffects: ["business_mutation"] },
29
+ { id: "approveTask", kind: "action", status: "planned", displayName: "Approve task", userFacingName: "审批通过", description: "对审批任务执行通过动作。", riskLevel: "high", sideEffects: ["workflow"] },
30
+ { id: "onSelectResult", kind: "trigger", status: "active", displayName: "On select result", userFacingName: "选择结果时", description: "用户选择搜索或查询结果时触发。", riskLevel: "low", sideEffects: [] },
31
+ { id: "onSubmit", kind: "trigger", status: "active", displayName: "On submit", userFacingName: "提交时", description: "用户点击查询、提交或确认按钮时触发。", riskLevel: "low", sideEffects: [] },
32
+ { id: "onClick", kind: "trigger", status: "active", displayName: "On click", userFacingName: "点击时", description: "用户点击按钮或菜单项时触发。", riskLevel: "low", sideEffects: [] },
33
+ { id: "onChange", kind: "trigger", status: "active", displayName: "On change", userFacingName: "内容变化时", description: "用户修改输入、筛选或选择时触发。", riskLevel: "low", sideEffects: [] },
34
+ { id: "processCenter", kind: "routeTarget", status: "active", displayName: "Process center", userFacingName: "流程中心", description: "打开流程中心并传递查询参数。", riskLevel: "medium", sideEffects: ["navigate"] }
35
+ ], ya = {
36
+ processCenter: {
37
+ id: "processCenter",
38
+ name: "流程中心",
39
+ route: "/process-center",
40
+ acceptedParams: ["keyword", "source"]
41
+ }
42
+ };
43
+ function Lt(t, e) {
44
+ return bt.find(
45
+ (a) => a.id === t && (!e || a.kind === e)
46
+ );
47
+ }
48
+ function ga(t) {
49
+ return bt.filter((e) => e.kind === t && e.status === "active").map((e) => e.id);
50
+ }
51
+ function $(t, e) {
52
+ var a;
53
+ return ((a = Lt(t, e)) == null ? void 0 : a.status) === "active";
54
+ }
55
+ function $t(t) {
56
+ return {
57
+ slot: t.slot,
58
+ ui: t.ui.kind,
59
+ icon: t.ui.icon,
60
+ data: t.data.source,
61
+ actions: t.actions.map((e) => e.type),
62
+ triggers: t.actions.map((e) => e.trigger),
63
+ routeTargets: t.actions.filter((e) => e.type === "openRoute").map((e) => e.target).filter((e) => !!e)
64
+ };
65
+ }
66
+ function qt(t) {
67
+ const e = $t(t), a = [];
68
+ return $(e.slot, "slot") || a.push(e.slot), $(e.ui, "ui") || a.push(e.ui), $(e.data, "data") || a.push(e.data), e.actions.forEach((n) => {
69
+ $(n, "action") || a.push(n);
70
+ }), e.triggers.forEach((n) => {
71
+ $(n, "trigger") || a.push(n);
72
+ }), e.routeTargets.forEach((n) => {
73
+ $(n, "routeTarget") || a.push(n);
74
+ }), [...new Set(a)];
75
+ }
76
+ function jt(t) {
77
+ return [...new Set(t)].map((e) => {
78
+ const a = Lt(e);
79
+ return {
80
+ id: e,
81
+ userFacingName: (a == null ? void 0 : a.userFacingName) || pt(e),
82
+ description: (a == null ? void 0 : a.description) || `系统还没有开放“${pt(e)}”这项基础能力。`,
83
+ status: (a == null ? void 0 : a.status) === "disabled" ? "disabled" : (a == null ? void 0 : a.status) === "planned" ? "planned" : "unknown"
84
+ };
85
+ });
86
+ }
87
+ function pt(t) {
88
+ const e = {
89
+ exportData: "导出文件",
90
+ exportFile: "导出文件",
91
+ tableSelection: "选择表格行",
92
+ businessObjectQuery: "业务数据查询",
93
+ metricQuery: "指标数据查询",
94
+ refreshData: "刷新数据",
95
+ toggleFavorite: "收藏或取消收藏",
96
+ submitForm: "提交表单",
97
+ approveTask: "审批通过",
98
+ drawerPanel: "详情抽屉",
99
+ filterBar: "筛选条"
100
+ };
101
+ return e[t] ? e[t] : t.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/[._-]+/g, " ").trim() || "未知基础能力";
102
+ }
103
+ function Yt(t, e = "") {
104
+ return {
105
+ missingPrimitives: [...new Set(t)],
106
+ gapType: "runtime_capability_primitives",
107
+ userNeed: e,
108
+ missingCapabilities: jt(t)
109
+ };
110
+ }
111
+ const Ut = /* @__PURE__ */ new Set(["callApiAction", "submitForm", "approveTask"]);
112
+ function Xt(t) {
113
+ return !!(t && typeof t == "object" && !Array.isArray(t));
114
+ }
115
+ function et(t, e) {
116
+ return Yt(t, e);
117
+ }
118
+ function Jt(t, e = "挂载卡片内部能力") {
119
+ if (!Xt(t))
120
+ return {
121
+ allowed: !1,
122
+ error: {
123
+ code: "INVALID_PARAMS",
124
+ message: "Runtime capability 必须是结构化对象。"
125
+ }
126
+ };
127
+ const a = t, n = Array.isArray(a.actions) ? a.actions.map((s) => s.type).filter((s) => Ut.has(s)) : [];
128
+ if (n.length > 0)
129
+ return {
130
+ allowed: !1,
131
+ gap: et(n, e),
132
+ error: {
133
+ code: "POLICY_REJECTED",
134
+ message: `左画布默认禁用高风险业务动作:${n.join("、")}`,
135
+ details: { highRisk: n }
136
+ }
137
+ };
138
+ const i = qt(a);
139
+ return i.length > 0 ? {
140
+ allowed: !1,
141
+ gap: et(i, e),
142
+ error: {
143
+ code: "PRIMITIVE_GAP",
144
+ message: "缺少或禁用了必要的 Runtime Primitive,已拒绝写入半成品能力。",
145
+ details: et(i, e)
146
+ }
147
+ } : {
148
+ allowed: !0,
149
+ capability: a
150
+ };
151
+ }
152
+ const U = 4, N = Ft, S = 12, Ot = 8, Wt = 6, xa = 4, ht = "card.custom.nestedContainer", Qt = "nested-card-container", Zt = 240, Tt = 16, Ht = 0.35, ft = 8, rt = 2, ct = 1, te = 1, ee = 12, j = 12, ae = 3;
153
+ function H(t) {
154
+ return Math.round(t * 1e3) / 1e3;
155
+ }
156
+ function z(t, e, a) {
157
+ return Math.min(a, Math.max(e, t));
158
+ }
159
+ function h(t) {
160
+ return Math.max(0, Math.round(Number.isFinite(t) ? t : 0));
161
+ }
162
+ function yt(t) {
163
+ return Math.max(0, Math.round(Number.isFinite(t) ? t : 0));
164
+ }
165
+ function p(t) {
166
+ return Math.max(1, Math.round(Number.isFinite(t) ? t : 1));
167
+ }
168
+ function ne(t, e) {
169
+ const a = p(e), n = p(t);
170
+ return n > S ? n : p(n / S * a);
171
+ }
172
+ function ie(t, e, a) {
173
+ const n = p(t.w), s = e && a && n <= p(a.w) && n <= S ? ne(t.w, e.w) : n;
174
+ return {
175
+ i: t.i,
176
+ x: z(h(t.x), 0, Math.max(0, N - s)),
177
+ y: h(t.y),
178
+ w: s,
179
+ h: p(t.h),
180
+ static: t.static
181
+ };
182
+ }
183
+ function J(t, e, a) {
184
+ const n = e > 0 ? e : a;
185
+ return H(t / n * a);
186
+ }
187
+ function B(t, e, a) {
188
+ a !== void 0 && (t[e] = a);
189
+ }
190
+ function E(t, e) {
191
+ const a = t.y - e.y;
192
+ if (a !== 0) return a;
193
+ const n = t.x - e.x;
194
+ return n !== 0 ? n : t.i.localeCompare(e.i);
195
+ }
196
+ function re(t) {
197
+ const e = /* @__PURE__ */ new Map();
198
+ t.forEach((n) => {
199
+ e.set(n.y, [...e.get(n.y) || [], n]);
200
+ });
201
+ const a = /* @__PURE__ */ new Map();
202
+ return e.forEach((n) => {
203
+ var d;
204
+ const i = n.slice().sort(E), s = i[i.length - 1];
205
+ !s || (d = s.children) != null && d.length || Math.max(...i.map((r) => r.x + r.w)) !== N - 1 || a.set(s.i, {
206
+ ...s,
207
+ w: N - s.x
208
+ });
209
+ }), t.map((n) => a.get(n.i) || n);
210
+ }
211
+ function dt(t, e) {
212
+ return t.x < e.x + e.w && t.x + t.w > e.x;
213
+ }
214
+ function _t(t, e) {
215
+ return Math.max(0, Math.min(t.x + t.w, e.x + e.w) - Math.max(t.x, e.x));
216
+ }
217
+ function q(t, e) {
218
+ if (!dt(t, e)) return !1;
219
+ const a = _t(t, e);
220
+ return a <= 0 ? !1 : a / Math.max(1, Math.min(t.w, e.w)) >= 0.25;
221
+ }
222
+ function gt(t, e) {
223
+ return q(t, e) && t.y < e.y + e.h;
224
+ }
225
+ function se(t, e) {
226
+ if (_t(t, e) <= 0 || q(t, e) || !(t.y < e.y + e.h && e.y < t.y + t.h) || t.x <= e.x || t.x >= e.x + e.w) return null;
227
+ const i = Math.max(1, t.x - e.x);
228
+ return i < e.w ? { ...e, w: i } : null;
229
+ }
230
+ function X(t) {
231
+ const e = [];
232
+ return t.slice().sort(E).forEach((a) => {
233
+ const n = e.find((i) => {
234
+ const s = Math.min(...i.map((r) => r.y)), c = Math.max(...i.map((r) => r.y + r.h)), d = Math.max(0, Math.min(a.y + a.h, c) - Math.max(a.y, s));
235
+ return Math.abs(a.y - s) <= 1 || d / Math.max(1, Math.min(a.h, c - s)) >= 0.7;
236
+ });
237
+ n ? (n.push(a), n.sort(E)) : e.push([a]);
238
+ }), e;
239
+ }
240
+ function oe(t) {
241
+ if (t.length < 3 || t.some((l) => {
242
+ var f;
243
+ return (f = l.children) == null ? void 0 : f.length;
244
+ })) return t;
245
+ const e = t.slice().sort(E), a = e[0], n = e[e.length - 1];
246
+ if (!a || !n) return t;
247
+ const i = n.x + n.w - a.x, s = e.reduce((l, f) => l + f.w, 0), c = e.slice(1).map((l, f) => l.x - (e[f].x + e[f].w));
248
+ if (c.length < 2) return t;
249
+ const d = Math.max(...c), r = Math.min(...c);
250
+ if (d - r <= 0) return t;
251
+ const o = i - s;
252
+ if (o < 0) return t;
253
+ const m = Math.max(0, Math.round(o / Math.max(1, e.length - 1)));
254
+ let u = a.x;
255
+ return e.map((l, f) => {
256
+ const x = z(u, 0, Math.max(0, N - l.w));
257
+ return u = x + l.w + m, f === e.length - 1 && x + l.w > N ? l : { ...l, x };
258
+ });
259
+ }
260
+ function ce(t) {
261
+ const e = /* @__PURE__ */ new Map();
262
+ return X(t).forEach((a) => {
263
+ oe(a).forEach((n) => e.set(n.i, n));
264
+ }), t.map((a) => e.get(a.i) || a);
265
+ }
266
+ function Ia(t, e) {
267
+ const a = Math.max(1, e.maxGapRows ?? 4), n = Math.max(0, e.targetGapRows ?? 0), i = t.filter((g) => !g.parentId).slice().sort(E), s = i.find(e.isHeader);
268
+ if (!s) return t;
269
+ const c = h(s.y), d = c + p(s.h), o = X(i).map((g) => g.slice().sort(E)).filter((g) => Math.min(...g.map((y) => h(y.y))) > c && g.some(e.isSuccessorStrip)).sort((g, C) => {
270
+ const y = Math.min(...g.map((R) => h(R.y))), w = Math.min(...C.map((R) => h(R.y)));
271
+ return y - w;
272
+ })[0];
273
+ if (!o || o.length < 2) return t;
274
+ const m = Math.min(...o.map((g) => h(g.y)));
275
+ if (m - d <= a) return t;
276
+ const l = d + n, f = m - l;
277
+ if (f <= 0) return t;
278
+ const x = new Set(
279
+ i.filter((g) => h(g.y) >= m).map((g) => String(g.i))
280
+ );
281
+ return t.map((g) => x.has(String(g.i)) ? { ...g, y: Math.max(0, h(g.y) - f) } : g);
282
+ }
283
+ function de(t, e) {
284
+ if (t.length < 3) return;
285
+ const a = t.slice().sort(E), n = a[0];
286
+ if (!n || Math.abs(e.x - n.x) > ct) return;
287
+ const i = e.x + e.w;
288
+ let s = n.x + n.w, c = 1;
289
+ for (let d = 1; d < a.length; d += 1) {
290
+ const r = a[d];
291
+ if (!r || r.x >= i) break;
292
+ s = Math.max(s, r.x + r.w), c += 1;
293
+ }
294
+ if (!(c < 2 || c >= a.length))
295
+ return s;
296
+ }
297
+ function ue(t) {
298
+ var a, n;
299
+ const e = [];
300
+ for (let i = 1; i < t.length; i += 1) {
301
+ const s = (t[i - 1] || []).slice().sort(E), c = (t[i] || []).slice().sort(E);
302
+ if (s.length < 3 || c.length !== 2) continue;
303
+ const d = c[0], r = c[1];
304
+ if (!d || !r || (a = d.children) != null && a.length || (n = r.children) != null && n.length || d.w < r.w * 1.35) continue;
305
+ const o = de(s, d);
306
+ if (o === void 0) continue;
307
+ const u = Math.min(o, r.x - ct) - d.x;
308
+ !Number.isFinite(u) || u <= d.w || e.push({
309
+ ...d,
310
+ w: z(u, 1, N - d.x)
311
+ });
312
+ }
313
+ return e;
314
+ }
315
+ function me(t) {
316
+ const e = X(t), a = new Map(ue(e).map((n) => [n.i, n]));
317
+ return a.size === 0 ? t : t.map((n) => a.get(n.i) || n);
318
+ }
319
+ function k(t) {
320
+ return /(?:recognized|image-fallback)-\d+/.test(t.i);
321
+ }
322
+ function le(t) {
323
+ return new Set(t.filter((e) => {
324
+ var a, n, i, s;
325
+ return k({ i: e.id }) && (((a = e.meta) == null ? void 0 : a.imageLayoutManualOverride) === !0 && ((n = e.meta) == null ? void 0 : n.imageLayoutManualOverrideSource) === "gridstack" || ((i = e.meta) == null ? void 0 : i.manualCanvasLayout) === !0 && ((s = e.meta) == null ? void 0 : s.layoutManualOverrideSource) === "gridstack");
326
+ }).map((e) => e.id));
327
+ }
328
+ function Q(t) {
329
+ const e = t.i.match(/(?:recognized|image-fallback)-(\d+)/), a = e ? Number(e[1]) : Number.POSITIVE_INFINITY;
330
+ return Number.isFinite(a) ? a : Number.POSITIVE_INFINITY;
331
+ }
332
+ function pe(t, e) {
333
+ const a = Q(t) - Q(e);
334
+ return a !== 0 ? a : E(t, e);
335
+ }
336
+ function he(t, e) {
337
+ const a = Q(t);
338
+ return e.some((n) => Q(n) > a && q(t, n) && n.y < t.y);
339
+ }
340
+ function fe(t, e) {
341
+ const a = e.filter((n) => q(t, n)).map((n) => n.y + n.h);
342
+ if (a.length !== 0)
343
+ return Math.max(...a);
344
+ }
345
+ function ut(t, e = /* @__PURE__ */ new Set()) {
346
+ const a = t.filter((d) => !d.parentId && k(d) && !e.has(String(d.i))).sort(pe);
347
+ if (a.length < 2) return t;
348
+ const n = /* @__PURE__ */ new Map(), i = Math.min(...a.map((d) => d.y));
349
+ a.forEach((d) => {
350
+ const r = {
351
+ ...d,
352
+ y: n.size === 0 ? i : d.y
353
+ }, o = [...n.values()];
354
+ if (he(r, a)) {
355
+ const m = fe(r, o);
356
+ m !== void 0 && r.y > m && (r.y = m);
357
+ }
358
+ for (; o.some((m) => gt(r, m)); ) {
359
+ const m = Math.max(
360
+ ...o.filter((u) => gt(r, u)).map((u) => u.y + u.h)
361
+ );
362
+ r.y = m;
363
+ }
364
+ o.forEach((m) => {
365
+ const u = se(r, m);
366
+ u && n.set(u.i, u);
367
+ }), n.set(d.i, r);
368
+ });
369
+ const s = me(
370
+ ce([...n.values()])
371
+ ), c = new Map(s.map((d) => [d.i, d]));
372
+ return [...c.entries()].some(([d, r]) => {
373
+ const o = a.find((m) => m.i === d);
374
+ return r.y !== (o == null ? void 0 : o.y) || r.x !== (o == null ? void 0 : o.x) || r.w !== (o == null ? void 0 : o.w);
375
+ }) ? t.map((d) => c.get(d.i) || d) : t;
376
+ }
377
+ function ye(t, e) {
378
+ if (!e || t.parentId || e.parentId || !k(t)) return !1;
379
+ const a = h(t.x), n = h(e.x), i = h(t.y), s = h(e.y), c = p(t.w), d = p(e.w), r = p(t.h), o = p(e.h), m = n >= N * 0.15 && n + d >= N * 0.85, u = n >= N * 0.15 && d >= N * 0.45, l = a < Math.max(0, n - 4), f = c < Math.max(d * 0.7, d - 12), x = c > Math.max(d * 1.25, d + 12), g = a < Math.max(0, n - 4) && Math.abs(a + c - (n + d)) <= Math.max(6, d * 0.25), C = Math.abs(i - s) <= Math.max(2, Math.round(o * 0.15)), y = Math.max(0, Math.min(i + r, s + o) - Math.max(i, s)), w = C || y / Math.max(1, Math.min(r, o)) >= 0.65 || i > s && i < s + o, R = Array.isArray(t.children) && t.children.length > 0 && o > r && o >= Math.max(r + 4, r * 1.8);
380
+ return (m || u) && w && l && (f || g || x) || R;
381
+ }
382
+ function ge(t, e) {
383
+ const a = h(t.y), n = h(e.y), i = p(t.h), s = p(e.h), c = Math.max(0, Math.min(a + i, n + s) - Math.max(a, n));
384
+ return Math.abs(a - n) <= Math.max(2, Math.round(Math.min(i, s) * 0.25)) || c / Math.max(1, Math.min(i, s)) >= 0.7;
385
+ }
386
+ function xe(t, e) {
387
+ if (!q(t, e)) return !1;
388
+ const a = h(t.y) <= h(e.y) ? t : e, n = a === t ? e : t, i = h(a.y) + p(a.h), s = h(n.y), c = Math.max(2, Math.min(p(a.h), p(n.h)));
389
+ return s >= i - 1 && s <= i + c;
390
+ }
391
+ function Ie(t, e) {
392
+ if (t.length < 2) return !1;
393
+ const a = t.slice().sort(E), n = Math.min(...a.map((s) => h(s.x)));
394
+ if (Math.max(...a.map((s) => h(s.x) + p(s.w))) - n < N * 0.75) return !1;
395
+ for (let s = 0; s < a.length; s += 1)
396
+ for (let c = s + 1; c < a.length; c += 1) {
397
+ const d = a[s], r = a[c];
398
+ if (!d || !r || !ge(d, r) || dt(d, r)) continue;
399
+ const o = e.get(String(d.i)), m = e.get(String(r.i));
400
+ if (!(!o || !m) && xe(o, m))
401
+ return !0;
402
+ }
403
+ return !1;
404
+ }
405
+ function ve(t, e) {
406
+ const a = p(t.h), n = p(e.h), i = Array.isArray(t.children) ? t.children : [];
407
+ if (i.length === 0) return Math.max(a, n);
408
+ const s = i.reduce((r, o) => Math.max(r, h(o.y) + p(o.h)), 0), c = Math.max(10, s + 6), d = a <= 8 && i.length <= 2 ? 18 : Number.POSITIVE_INFINITY;
409
+ return Math.min(
410
+ Math.max(a, n, c),
411
+ d
412
+ );
413
+ }
414
+ function Me(t) {
415
+ return k(t) && !t.parentId && h(t.x) <= ct && p(t.w) >= N * 0.45 && p(t.h) >= 36 && h(t.y) > 20 && h(t.x) + p(t.w) < N * 0.85;
416
+ }
417
+ function Se(t, e) {
418
+ const a = h(t.x), n = h(t.y), i = p(t.w), s = p(t.h);
419
+ return e.some((c) => {
420
+ if (String(c.i) === String(t.i) || c.parentId || !k(c)) return !1;
421
+ const d = h(c.x), r = h(c.y), o = p(c.h);
422
+ return !(d >= a + Math.min(i, N * 0.45) - 1) || o < s * 0.55 ? !1 : Math.max(0, Math.min(n + s, r + o) - Math.max(n, r)) / Math.max(1, Math.min(s, o)) >= 0.35;
423
+ });
424
+ }
425
+ function we(t) {
426
+ const e = X(t.filter((n) => !n.parentId && k(n))), a = /* @__PURE__ */ new Set();
427
+ return e.forEach((n) => {
428
+ const i = n.slice().sort(E);
429
+ i.filter(Me).forEach((c) => {
430
+ const d = p(c.h);
431
+ i.filter((m) => String(m.i) !== String(c.i)).some((m) => p(m.h) >= d * 0.55) || Se(c, t) || a.add(String(c.i));
432
+ });
433
+ }), a.size === 0 ? t : t.map((n) => {
434
+ if (!a.has(String(n.i))) return n;
435
+ const i = h(n.x), s = Math.max(p(n.w), N - i);
436
+ return {
437
+ ...n,
438
+ x: i,
439
+ w: s,
440
+ minW: Math.min(s, p(n.minW ?? s)),
441
+ maxW: Math.max(s, p(n.maxW ?? s))
442
+ };
443
+ });
444
+ }
445
+ function va(t, e) {
446
+ if ((e == null ? void 0 : e.version) !== U) return t;
447
+ const a = new Map(e.nodes.filter((r) => !r.parentId).map((r) => [String(r.i), r])), n = new Map(t.nodes.filter((r) => !r.parentId && k(r)).map((r) => [String(r.i), r])), i = /* @__PURE__ */ new Set();
448
+ if (t.nodes.forEach((r) => {
449
+ ye(r, a.get(String(r.i))) && i.add(String(r.i));
450
+ }), X([...a.values()].filter((r) => k(r))).forEach((r) => {
451
+ Ie(r, n) && r.forEach((o) => i.add(String(o.i)));
452
+ }), i.size === 0) return t;
453
+ const s = new Set(i);
454
+ t.nodes.filter((r) => !r.parentId && k(r)).forEach((r) => {
455
+ if (s.has(String(r.i))) return;
456
+ const o = a.get(String(r.i));
457
+ if (!o) return;
458
+ [...i].some((u) => {
459
+ const l = a.get(u);
460
+ if (!l) return !1;
461
+ const f = Math.abs(h(o.y) - h(l.y)) <= Math.max(
462
+ 1,
463
+ Math.round(Math.min(p(o.h), p(l.h)) * 0.2)
464
+ ), x = !dt(o, l);
465
+ return f && x && q(r, l);
466
+ }) && s.add(String(r.i));
467
+ });
468
+ const c = t.nodes.map((r) => {
469
+ const o = a.get(String(r.i));
470
+ if (!s.has(String(r.i)) || !o) return r;
471
+ const m = ve(r, o), u = {
472
+ ...r,
473
+ x: o.x,
474
+ y: o.y,
475
+ w: o.w,
476
+ h: m
477
+ }, l = o.minW ?? r.minW, f = o.maxW ?? r.maxW, x = o.maxH ?? r.maxH;
478
+ return l !== void 0 && (u.minW = l), u.minH = Math.min(
479
+ Math.max(1, p(o.minH ?? o.h), Array.isArray(r.children) ? m : 1),
480
+ m
481
+ ), f !== void 0 && (u.maxW = f), x !== void 0 && (u.maxH = x), u;
482
+ }), d = we(c);
483
+ return mt({
484
+ ...t,
485
+ nodes: ut(d).sort(E)
486
+ });
487
+ }
488
+ function Z(t, e, a = N, n) {
489
+ const i = J(t.x, e, a), s = J(t.x + t.w, e, a), c = z(
490
+ yt(i),
491
+ 0,
492
+ Math.max(0, a - 1)
493
+ ), r = z(yt(s), c + 1, a) - c, o = {
494
+ i: t.i,
495
+ x: c,
496
+ y: h(t.y),
497
+ w: r,
498
+ h: p(t.h)
499
+ };
500
+ return B(o, "minW", t.minW === void 0 ? void 0 : z(p(J(t.minW, e, a)), 1, a)), B(o, "maxW", t.maxW === void 0 ? void 0 : z(p(J(t.maxW, e, a)), 1, a)), B(o, "minH", t.minH === void 0 ? void 0 : p(t.minH)), B(o, "maxH", t.maxH === void 0 ? void 0 : p(t.maxH)), B(o, "static", t.static), n && (o.parentId = n), o;
501
+ }
502
+ function Ma(t, e) {
503
+ const a = e.cols || e.maxCols || N, n = re(t.map((i) => {
504
+ const s = Z({ ...i.layout, i: i.id }, a, N), c = Dt(i);
505
+ return c.length > 0 ? { ...s, children: c } : s;
506
+ }).sort(E));
507
+ return {
508
+ version: U,
509
+ cols: N,
510
+ rowHeight: Ot,
511
+ gap: Wt,
512
+ nodes: ut(n, le(t)).sort(E)
513
+ };
514
+ }
515
+ function xt(t, e, a) {
516
+ if (!Number.isFinite(t.x) || !Number.isFinite(t.y) || !Number.isFinite(t.w) || !Number.isFinite(t.h) || t.w < 1 || t.h < 1) return !0;
517
+ if (!e) return t.h > a || t.y > a;
518
+ const n = Math.max(1, e.h), i = Math.max(0, e.y), s = Math.max(a, n * 4 + 20);
519
+ return t.h > Math.max(a, n * 4 + 20) || Math.abs(t.y - i) > s;
520
+ }
521
+ function Ne(t, e) {
522
+ if (!e || !/(?:recognized|image-fallback)-\d+/.test(t.i)) return !1;
523
+ const a = Math.abs(t.y - e.y), n = Math.max(t.h, e.h) / Math.max(1, Math.min(t.h, e.h)), i = Math.max(t.w, e.w) / Math.max(1, Math.min(t.w, e.w));
524
+ return a > Math.max(6, e.h * 0.5) || n > 1.65 || i > 1.45;
525
+ }
526
+ function at(t, e, a, n, i, s) {
527
+ const c = Z({
528
+ i: t.i,
529
+ x: t.x,
530
+ y: t.y,
531
+ w: t.w,
532
+ h: t.h,
533
+ minW: t.minW,
534
+ minH: t.minH,
535
+ maxW: t.maxW,
536
+ maxH: t.maxH,
537
+ static: t.static
538
+ }, e, a, t.parentId), d = n ? Z({
539
+ i: n.i,
540
+ x: n.x,
541
+ y: n.y,
542
+ w: n.w,
543
+ h: n.h,
544
+ minW: n.minW,
545
+ minH: n.minH,
546
+ maxW: n.maxW,
547
+ maxH: n.maxH,
548
+ static: n.static
549
+ }, a, a, n.parentId) : void 0, r = d && xt(d, void 0, i) ? { ...d, h: Math.min(d.h, i) } : d, o = xt(c, r, i) || s && Ne(c, r) ? r || { ...c, h: Math.min(c.h, i) } : c;
550
+ return {
551
+ ...t,
552
+ ...o,
553
+ i: t.i,
554
+ ...t.parentId ? { parentId: t.parentId } : {}
555
+ };
556
+ }
557
+ function Sa(t, e = {}) {
558
+ var C;
559
+ const a = t.cols || N, n = e.maxItemRows || Zt, i = e.repairStaleImageFallback !== !1, s = e.preserveManualImageNodeIds || /* @__PURE__ */ new Set(), c = e.preserveManualNestedImageParentIds || /* @__PURE__ */ new Set(), d = new Map(
560
+ (((C = e.fallbackTree) == null ? void 0 : C.nodes) || []).filter((y) => !y.parentId).map((y) => [y.i, y])
561
+ ), r = t.nodes.map((y) => {
562
+ const w = !y.parentId, R = w ? N : S, A = w ? a : S, _ = w ? d.get(y.i) : void 0, P = at(
563
+ y,
564
+ A,
565
+ R,
566
+ _,
567
+ n,
568
+ i && !s.has(String(y.i))
569
+ ), D = new Map(((_ == null ? void 0 : _.children) || []).map((I) => [I.i, I])), G = Array.isArray(y.children) ? y.children.map((I) => at(
570
+ { ...I, parentId: I.parentId || y.i },
571
+ S,
572
+ S,
573
+ D.get(I.i),
574
+ n,
575
+ i && !c.has(String(y.i))
576
+ )) : y.children;
577
+ return G === void 0 ? P : { ...P, children: G };
578
+ }), o = new Set(r.filter((y) => !y.parentId).map((y) => y.i)), m = e.missingNodeFallbackTree || e.fallbackTree, u = ((m == null ? void 0 : m.nodes) || []).filter((y) => !y.parentId && !o.has(y.i)).map((y) => at(
579
+ y,
580
+ N,
581
+ N,
582
+ void 0,
583
+ n,
584
+ i
585
+ )), l = new Set(u.map((y) => y.i)), x = [
586
+ ...l.size === 0 ? r : r.map((y) => {
587
+ if (!Array.isArray(y.children)) return y;
588
+ const w = y.children.filter((R) => !l.has(R.i));
589
+ return w.length === y.children.length ? y : { ...y, children: w };
590
+ }),
591
+ ...u
592
+ ], g = i ? ut(x, /* @__PURE__ */ new Set([
593
+ ...s,
594
+ ...[...c].filter((y) => !s.has(y))
595
+ ])) : x;
596
+ return mt({
597
+ ...t,
598
+ version: U,
599
+ cols: N,
600
+ rowHeight: Ot,
601
+ gap: Wt,
602
+ nodes: g.sort(E)
603
+ });
604
+ }
605
+ function wa(t) {
606
+ const e = (a) => {
607
+ const n = {
608
+ ...a,
609
+ static: !1
610
+ };
611
+ return n.minW !== void 0 && n.minW >= n.w && delete n.minW, n.minH !== void 0 && n.minH >= n.h && delete n.minH, n.maxW !== void 0 && n.maxW <= n.w && delete n.maxW, n.maxH !== void 0 && n.maxH <= n.h && delete n.maxH, n;
612
+ };
613
+ return {
614
+ ...t,
615
+ nodes: t.nodes.map((a) => ({
616
+ ...e(a),
617
+ children: Array.isArray(a.children) ? a.children.map(e) : a.children
618
+ }))
619
+ };
620
+ }
621
+ function Na(t) {
622
+ const e = {
623
+ id: t.i,
624
+ x: t.x,
625
+ y: t.y,
626
+ w: t.w,
627
+ h: t.h,
628
+ minW: t.minW,
629
+ minH: t.minH,
630
+ maxW: t.maxW,
631
+ maxH: t.maxH
632
+ };
633
+ return t.static ? (e.noMove = !0, e.noResize = !0, e.locked = !0) : t.static === !1 && (e.noMove = !1, e.noResize = !1, e.locked = !1), e;
634
+ }
635
+ function Ce(t) {
636
+ return {
637
+ id: String(t.i),
638
+ x: h(t.x),
639
+ y: h(t.y),
640
+ w: p(t.w),
641
+ h: p(t.h)
642
+ };
643
+ }
644
+ function Re(t, e) {
645
+ return {
646
+ id: String(t.id || (e == null ? void 0 : e.i) || ""),
647
+ x: h(t.x ?? (e == null ? void 0 : e.x) ?? 0),
648
+ y: h(t.y ?? (e == null ? void 0 : e.y) ?? 0),
649
+ w: p(t.w ?? (e == null ? void 0 : e.w) ?? 1),
650
+ h: p(t.h ?? (e == null ? void 0 : e.h) ?? 1)
651
+ };
652
+ }
653
+ function Ee(t, e) {
654
+ return t.x < e.x + e.w && t.x + t.w > e.x && t.y < e.y + e.h && t.y + t.h > e.y;
655
+ }
656
+ function Ae(t, e) {
657
+ return e.y > t.y && e.x === t.x && e.w === t.w && e.h === t.h;
658
+ }
659
+ function be(t, e, a) {
660
+ return Ae(t, e) ? a.some((n) => Ee(t, n) && e.y >= n.y + n.h - 1) : !1;
661
+ }
662
+ function Le(t, e, a) {
663
+ if (!a || a.size === 0) return /* @__PURE__ */ new Set();
664
+ const n = new Map(
665
+ t.filter((c) => typeof c.id == "string" && c.id.length > 0).map((c) => {
666
+ const d = String(c.id);
667
+ return [d, Re(c, e.get(d))];
668
+ })
669
+ ), i = /* @__PURE__ */ new Map();
670
+ a.forEach((c) => {
671
+ const d = n.get(String(c));
672
+ d && i.set(String(c), d);
673
+ });
674
+ let s = !0;
675
+ for (; s; )
676
+ s = !1, n.forEach((c, d) => {
677
+ if (i.has(d)) return;
678
+ const r = e.get(d);
679
+ if (!r) return;
680
+ const o = Ce(r);
681
+ be(o, c, [...i.values()]) && (i.set(d, c), s = !0);
682
+ });
683
+ return new Set([...i.keys()].filter((c) => !a.has(c)));
684
+ }
685
+ function Ca(t, e, a = {}) {
686
+ const n = new Map(e.nodes.map((d) => [String(d.i), d])), i = a.editedWidgetIds, s = Le(t, n, i), c = t.filter((d) => typeof d.id == "string" && d.id.length > 0).map((d) => {
687
+ const r = d.id, o = n.get(r), m = !i || i.has(r) || s.has(r) || !o, u = {
688
+ ...o || { i: r, x: 0, y: 0, w: 1, h: 1 },
689
+ i: r,
690
+ x: H(m ? d.x ?? (o == null ? void 0 : o.x) ?? 0 : o.x),
691
+ y: H(m ? d.y ?? (o == null ? void 0 : o.y) ?? 0 : o.y),
692
+ w: H(m ? d.w ?? (o == null ? void 0 : o.w) ?? 1 : o.w),
693
+ h: H(m ? d.h ?? (o == null ? void 0 : o.h) ?? 1 : o.h)
694
+ };
695
+ return B(u, "minW", d.minW ?? (o == null ? void 0 : o.minW)), B(u, "maxW", d.maxW ?? (o == null ? void 0 : o.maxW)), B(u, "minH", d.minH ?? (o == null ? void 0 : o.minH)), B(u, "maxH", d.maxH ?? (o == null ? void 0 : o.maxH)), B(u, "static", o == null ? void 0 : o.static), u;
696
+ });
697
+ return mt({
698
+ ...e,
699
+ version: U,
700
+ cols: N,
701
+ nodes: c.sort(E)
702
+ });
703
+ }
704
+ function Ra(t) {
705
+ return {
706
+ ...t,
707
+ cols: N,
708
+ maxCols: N,
709
+ isSquareCell: !1,
710
+ layoutVersion: U
711
+ };
712
+ }
713
+ function Ea(t, e) {
714
+ return {
715
+ ...t || {},
716
+ layoutTree: e
717
+ };
718
+ }
719
+ function M(t) {
720
+ return t && typeof t == "object" && !Array.isArray(t) ? t : {};
721
+ }
722
+ function Oe(t) {
723
+ const e = M(t.data), a = M(t.meta), n = M(t.source);
724
+ return a.capabilityId === ht || e.containerRole === Qt || n.resourceKey === ht;
725
+ }
726
+ function mt(t) {
727
+ const e = /* @__PURE__ */ new Set();
728
+ if (t.nodes.forEach((n) => {
729
+ n.parentId && e.add(String(n.i)), (n.children || []).forEach((i) => {
730
+ e.add(String(i.i));
731
+ });
732
+ }), e.size === 0) return t;
733
+ const a = t.nodes.filter((n) => n.parentId || !e.has(String(n.i)));
734
+ return a.length === t.nodes.length ? t : { ...t, nodes: a };
735
+ }
736
+ function W(t) {
737
+ return M(t).shape === "customCanvas";
738
+ }
739
+ function Bt(t) {
740
+ if (!t) return !1;
741
+ const e = M(t.data), a = M(t.renderer), n = typeof t.title == "string" ? t.title.trim() : "", i = !t.data && !t.dataShape && !t.visualKind && !a.rendererKey, s = !n || n === t.id || /(?:recognized|image-fallback)-\d+/.test(n);
742
+ return i || s || Object.keys(e).length === 0 && !t.capabilityId;
743
+ }
744
+ function It(t) {
745
+ var a;
746
+ if (!t) return -1;
747
+ let e = 0;
748
+ return t.title && t.title !== t.id && !/(?:recognized|image-fallback)-\d+/.test(t.title) && (e += 3), t.data && (e += 4), t.dataShape && (e += 2), t.visualKind && (e += 2), (a = t.renderer) != null && a.rendererKey && (e += 2), t.capabilityId && (e += 2), (t.dataBinding || t.dataBindingId) && (e += 2), t.dataBindingStatus && t.dataBindingStatus !== "ready" && (e += 1), t.humanIntervention && (e += 1), Bt(t) && (e -= 4), e;
749
+ }
750
+ function We(t, e, a) {
751
+ return [t, e, a].filter((i) => !!i).sort((i, s) => It(s) - It(i))[0] || a;
752
+ }
753
+ function Te(t) {
754
+ return {
755
+ columns: ["事项", "状态"],
756
+ rows: t.map((e, a) => ({
757
+ id: `fallback-row-${a + 1}`,
758
+ cells: [
759
+ typeof e.label == "string" && e.label.trim() ? e.label.trim() : `事项 ${a + 1}`,
760
+ typeof e.value == "string" && e.value.trim() ? e.value.trim() : "待问数"
761
+ ]
762
+ }))
763
+ };
764
+ }
765
+ function He(t, e) {
766
+ var n;
767
+ const a = `${t.id} ${t.title || ""} ${e.title || ""} ${((n = e.meta) == null ? void 0 : n.capabilityId) || ""}`;
768
+ return /image-fallback-16|asset|资产台账|资产 & 成本|资产&成本/i.test(a) ? {
769
+ title: "全域 IT 资产台账",
770
+ visualKind: "todoGrid",
771
+ dataShape: "rows",
772
+ rendererKey: "metricTiles",
773
+ capabilityId: "card.metric.combo",
774
+ items: [
775
+ { label: "终端与办公设备", value: "待问数", tone: "warning" },
776
+ { label: "服务器与机房设备", value: "待问数", tone: "warning" },
777
+ { label: "商业软件 License", value: "待问数", tone: "warning" },
778
+ { label: "云主机与存储资源", value: "待问数", tone: "warning" }
779
+ ]
780
+ } : /image-fallback-18|成本分析|费用分析|donut/i.test(a) ? {
781
+ title: "IT 成本分析",
782
+ visualKind: "donut",
783
+ dataShape: "rows",
784
+ rendererKey: "donut",
785
+ capabilityId: "card.chart.donut",
786
+ items: [
787
+ { label: "云资源费用", value: "待问数", share: 42, tone: "info" },
788
+ { label: "软件采购", value: "待问数", share: 25, tone: "violet" },
789
+ { label: "外包服务", value: "待问数", share: 17, tone: "warning" },
790
+ { label: "维保与机房", value: "待问数", share: 16, tone: "neutral" }
791
+ ]
792
+ } : /image-fallback-19|image-fallback-21|成本优化|预算执行|cost/i.test(a) ? {
793
+ title: "成本优化",
794
+ visualKind: "simpleList",
795
+ dataShape: "rows",
796
+ rendererKey: "simpleList",
797
+ capabilityId: "card.analysis.businessSuggestion",
798
+ items: [
799
+ { label: "本月云费用环比", value: "待问数", tone: "warning" },
800
+ { label: "可释放资源降本空间", value: "待问数", tone: "healthy" },
801
+ { label: "预算执行偏差", value: "待问数", tone: "healthy" }
802
+ ]
803
+ } : /image-fallback-17|资产异常|异常/i.test(a) ? {
804
+ title: "资产异常",
805
+ visualKind: "simpleList",
806
+ dataShape: "rows",
807
+ rendererKey: "simpleList",
808
+ capabilityId: "card.table.list",
809
+ items: [
810
+ { label: "闲置云主机待回收", value: "待问数", tone: "warning" },
811
+ { label: "License 即将到期", value: "待问数", tone: "critical" },
812
+ { label: "资产盘点完成率", value: "待问数", tone: "healthy" }
813
+ ]
814
+ } : {
815
+ title: e.title ? `${e.title}子卡` : "待补口径子卡",
816
+ visualKind: "simpleList",
817
+ dataShape: "rows",
818
+ rendererKey: "simpleList",
819
+ capabilityId: "card.table.list",
820
+ items: [
821
+ { label: "待补充业务口径", value: "待问数", tone: "warning" },
822
+ { label: "补充指标、表或字段后重试", value: "需补口径", tone: "info" }
823
+ ]
824
+ };
825
+ }
826
+ function _e(t, e) {
827
+ var r, o, m, u, l;
828
+ const a = `${((r = e.meta) == null ? void 0 : r.composeSource) || ""} ${String(M(e.data).source || "")}`;
829
+ if (!/image/i.test(a) || !Bt(t)) return t;
830
+ const n = He(t, e), i = t.dataBindingId || st(t.dataBinding) || `${t.id}-binding`, s = t.humanIntervention || {
831
+ required: !0,
832
+ reason: "missing_business_context",
833
+ message: `${n.title} 需要补充指标、表、字段或系统口径后再问数`
834
+ }, c = Array.isArray((o = t.data) == null ? void 0 : o.items) ? t.data.items : n.items, d = Te(c);
835
+ return {
836
+ ...t,
837
+ title: n.title,
838
+ kind: t.kind || "display",
839
+ capabilityId: t.capabilityId || n.capabilityId,
840
+ dataShape: t.dataShape || n.dataShape,
841
+ visualKind: t.visualKind || n.visualKind,
842
+ slot: t.slot || "main",
843
+ dataBindingId: i,
844
+ dataBindingStatus: "error",
845
+ dataBinding: {
846
+ ...t.dataBinding || {},
847
+ bindingId: i,
848
+ status: "error",
849
+ queryIntent: t.queryIntent || `查询${n.title}`,
850
+ humanIntervention: s
851
+ },
852
+ dataBindingError: t.dataBindingError || "需要补充业务口径后再问数",
853
+ humanIntervention: s,
854
+ queryIntent: t.queryIntent || `查询${n.title}`,
855
+ renderer: t.renderer || { engine: "custom", rendererKey: n.rendererKey },
856
+ state: t.state || {
857
+ mode: "final",
858
+ status: "failed",
859
+ refreshable: !0,
860
+ cacheable: !0
861
+ },
862
+ data: {
863
+ ...t.data || {},
864
+ shape: n.dataShape,
865
+ items: c,
866
+ columns: Array.isArray((m = t.data) == null ? void 0 : m.columns) ? t.data.columns : d.columns,
867
+ rows: Array.isArray((u = t.data) == null ? void 0 : u.rows) ? t.data.rows : d.rows,
868
+ dataBindingId: i,
869
+ dataBindingStatus: "error",
870
+ dataBindingError: t.dataBindingError || "需要补充业务口径后再问数",
871
+ humanIntervention: s,
872
+ dataBindingHumanIntervention: s,
873
+ capabilityId: t.capabilityId || n.capabilityId,
874
+ dataShape: t.dataShape || n.dataShape,
875
+ visualKind: t.visualKind || n.visualKind,
876
+ rendererKey: ((l = t.renderer) == null ? void 0 : l.rendererKey) || n.rendererKey,
877
+ queryIntent: t.queryIntent || `查询${n.title}`
878
+ }
879
+ };
880
+ }
881
+ function Be(t) {
882
+ const e = M(t.meta), a = M(t.data), n = M(e.visual), i = M(t.renderer), s = M(e.v2), c = Array.isArray(a.nestedBlocks) ? a.nestedBlocks : [], d = `${t.title} ${t.subtitle || ""} ${JSON.stringify(a.elements || [])}`;
883
+ return c.length === 0 && !Oe(t) || e.organizationKind === "welcome_banner" || e.imageCanvasChromeOnly === !0 || n.businessSummaryBand === "risk" || a.nestedLayoutMode === "absolute" || i.rendererKey === "customCanvas" && /GLOBAL RISK POSTURE|risk posture|风险总览|经营健康综合得分/i.test(d) || s.referenceCompositeKind !== void 0;
884
+ }
885
+ function Aa(t) {
886
+ return W(t.data) ? !Be(t) : !1;
887
+ }
888
+ function kt(t, e) {
889
+ const a = _e(t, e), n = a.layout ? { ...a.layout, i: a.id } : Pt(a, 0), i = M(a.meta), s = a.renderer || {
890
+ engine: "custom",
891
+ rendererKey: a.dataShape || "customCanvas"
892
+ }, c = M(a.dataBinding), d = a.dataBinding ? {
893
+ ...c,
894
+ humanIntervention: c.humanIntervention || a.humanIntervention
895
+ } : void 0, r = {
896
+ shape: a.dataShape || s.rendererKey,
897
+ title: a.title
898
+ };
899
+ return {
900
+ id: a.id,
901
+ version: e.version,
902
+ blockType: "display",
903
+ subType: a.subType || a.dataShape || "customCanvas",
904
+ title: a.title || a.id,
905
+ layout: n,
906
+ intent: e.intent,
907
+ source: e.source,
908
+ renderer: s,
909
+ state: a.state || {
910
+ mode: "final",
911
+ status: "ready",
912
+ refreshable: !1,
913
+ cacheable: !0
914
+ },
915
+ meta: {
916
+ ...i,
917
+ parentBlockId: e.id,
918
+ parentBlockTitle: e.title,
919
+ slot: a.slot,
920
+ dataBindingId: a.dataBindingId,
921
+ dataBindingError: a.dataBindingError,
922
+ dataBindingStatus: a.dataBindingStatus,
923
+ humanIntervention: a.humanIntervention,
924
+ capabilityId: a.capabilityId,
925
+ dataShape: a.dataShape,
926
+ visualKind: a.visualKind,
927
+ rendererKey: s.rendererKey,
928
+ queryIntent: a.queryIntent,
929
+ visual: a.visual
930
+ },
931
+ data: {
932
+ ...a.data || r,
933
+ dataBinding: d,
934
+ dataBindingStatus: a.dataBindingStatus,
935
+ dataBindingError: a.dataBindingError,
936
+ humanIntervention: a.humanIntervention,
937
+ dataBindingHumanIntervention: a.humanIntervention,
938
+ capabilityId: a.capabilityId,
939
+ dataShape: a.dataShape,
940
+ visualKind: a.visualKind,
941
+ rendererKey: s.rendererKey,
942
+ queryIntent: a.queryIntent
943
+ }
944
+ };
945
+ }
946
+ function st(t) {
947
+ const e = M(t), a = e.bindingId || e.id;
948
+ return typeof a == "string" && a.trim() ? a : void 0;
949
+ }
950
+ function lt(t, e = {}) {
951
+ var y, w, R, A;
952
+ const a = M(t.data), n = M(t.meta), i = t.renderer || {
953
+ engine: "custom",
954
+ rendererKey: typeof n.rendererKey == "string" ? n.rendererKey : "customCanvas"
955
+ }, s = typeof n.capabilityId == "string" ? n.capabilityId : typeof a.capabilityId == "string" ? a.capabilityId : typeof ((w = (y = t.source) == null ? void 0 : y.params) == null ? void 0 : w.capabilityId) == "string" ? t.source.params.capabilityId : void 0, c = typeof n.dataShape == "string" ? n.dataShape : typeof a.dataShape == "string" ? a.dataShape : typeof a.shape == "string" ? a.shape : i.rendererKey, d = typeof n.visualKind == "string" ? n.visualKind : typeof a.visualKind == "string" ? a.visualKind : void 0, r = M(a.dataBinding), o = M(n.dataBinding), m = typeof a.dataBindingId == "string" ? a.dataBindingId : typeof n.dataBindingId == "string" ? n.dataBindingId : st(r) ?? st(o), u = typeof a.dataBindingStatus == "string" ? a.dataBindingStatus : typeof n.dataBindingStatus == "string" ? n.dataBindingStatus : typeof r.status == "string" ? r.status : ((R = t.state) == null ? void 0 : R.status) || "ready", l = M(a.humanIntervention), f = M(n.humanIntervention), x = typeof a.queryIntent == "string" ? a.queryIntent : typeof n.queryIntent == "string" ? n.queryIntent : typeof r.queryIntent == "string" ? r.queryIntent : void 0, g = e.layout || t.layout, C = {
956
+ i: t.id,
957
+ x: g.x,
958
+ y: g.y,
959
+ w: g.w,
960
+ h: g.h,
961
+ minW: g.minW,
962
+ minH: g.minH,
963
+ maxW: g.maxW,
964
+ maxH: g.maxH,
965
+ static: g.static,
966
+ ...e.parentId ? { parentId: e.parentId } : {}
967
+ };
968
+ return {
969
+ id: t.id,
970
+ title: t.title,
971
+ kind: t.subType || t.blockType || "display",
972
+ capabilityId: s,
973
+ dataShape: c,
974
+ registryTitle: typeof n.registryTitle == "string" ? n.registryTitle : void 0,
975
+ visualKind: d,
976
+ meta: {
977
+ ...n,
978
+ parentBlockId: void 0,
979
+ parentBlockTitle: void 0
980
+ },
981
+ slot: "main",
982
+ composeSource: typeof a.composeSource == "string" ? a.composeSource : void 0,
983
+ dataBindingId: m,
984
+ ...Object.keys(r).length > 0 ? { dataBinding: r } : {},
985
+ dataBindingStatus: u,
986
+ dataBindingError: typeof a.dataBindingError == "string" ? a.dataBindingError : typeof n.dataBindingError == "string" ? n.dataBindingError : void 0,
987
+ humanIntervention: Object.keys(l).length > 0 ? l : Object.keys(f).length > 0 ? f : void 0,
988
+ queryIntent: x,
989
+ subType: t.subType,
990
+ renderer: i,
991
+ state: t.state,
992
+ layout: C,
993
+ visual: (A = t.meta) == null ? void 0 : A.visual,
994
+ data: {
995
+ ...a,
996
+ dataBindingStatus: u,
997
+ ...m ? { dataBindingId: m } : {},
998
+ ...Object.keys(r).length > 0 ? { dataBinding: r } : {},
999
+ ...Object.keys(l).length > 0 ? { humanIntervention: l } : {},
1000
+ ...x ? { queryIntent: x } : {},
1001
+ capabilityId: s,
1002
+ dataShape: c,
1003
+ visualKind: d,
1004
+ rendererKey: i.rendererKey
1005
+ }
1006
+ };
1007
+ }
1008
+ function ke(t, e, a = {}) {
1009
+ const n = kt(t, e), i = a.layout || n.layout, s = { ...n.meta || {} };
1010
+ return delete s.parentBlockId, delete s.parentBlockTitle, delete s.slot, {
1011
+ ...n,
1012
+ layout: {
1013
+ ...n.layout,
1014
+ ...i,
1015
+ i: t.id
1016
+ },
1017
+ meta: s
1018
+ };
1019
+ }
1020
+ function Pt(t, e) {
1021
+ return t.layout ? { ...t.layout, i: t.id } : {
1022
+ i: t.id,
1023
+ x: e % 2 * 6,
1024
+ y: Math.floor(e / 2) * 5,
1025
+ w: 6,
1026
+ h: 5
1027
+ };
1028
+ }
1029
+ function O(t) {
1030
+ const e = Number(t);
1031
+ return Number.isFinite(e) ? e : void 0;
1032
+ }
1033
+ function Pe(t) {
1034
+ const e = M(t.layout), a = M(t.meta), n = M(t.data);
1035
+ return typeof e.parentId == "string" && e.parentId.trim() ? e.parentId.trim() : typeof a.parentBlockId == "string" && a.parentBlockId.trim() ? a.parentBlockId.trim() : typeof n.parentBlockId == "string" && n.parentBlockId.trim() ? n.parentBlockId.trim() : "";
1036
+ }
1037
+ function De(t) {
1038
+ var n, i;
1039
+ const e = M(t.data), a = `${((n = t.meta) == null ? void 0 : n.composeSource) || ""} ${typeof e.source == "string" ? e.source : ""} ${((i = t.source) == null ? void 0 : i.service) || ""}`;
1040
+ return W(t.data) && /image/i.test(a) && Array.isArray(t.data.nestedBlocks) && t.data.nestedBlocks.length > 0;
1041
+ }
1042
+ function Ge(t) {
1043
+ return !W(t.data) || !Array.isArray(t.data.nestedBlocks) ? [] : De(t) ? t.data.nestedBlocks : t.data.nestedBlocks.filter((e) => {
1044
+ const a = Pe(e);
1045
+ return !a || a === t.id;
1046
+ });
1047
+ }
1048
+ function tt(t, e, a, n) {
1049
+ return a > 0 && t >= a && t < a + n ? Math.max(0, t - a) : t;
1050
+ }
1051
+ function Fe(t, e, a, n) {
1052
+ var K;
1053
+ if (!W(e.data) || e.data.nestedLayoutMode === "grid") return null;
1054
+ const i = M(e.data.nestedLayoutBasis), s = O(i.w), c = O(i.h);
1055
+ if (s === void 0 || c === void 0) return null;
1056
+ const d = O(i.x) ?? 0, r = O(i.y) ?? 0, o = Math.max(1, s), m = Math.max(1, c), u = O(t.x), l = O(t.y), f = O(t.w), x = O(t.h);
1057
+ if (u === void 0 || l === void 0 || f === void 0 || x === void 0) return null;
1058
+ const g = Math.max(
1059
+ S,
1060
+ p(O((K = e.layout) == null ? void 0 : K.h) ?? S)
1061
+ ), C = tt(u, f, d, o), y = tt(l, x, r, m), w = Math.max(1, n ?? o), R = Math.max(1, a ?? m), A = S / w, _ = g / R, P = H(y * _), D = Math.max(1, g - P), G = D > ft ? ft : 0, I = Math.max(1, x * _), T = Math.max(1, D - G), v = H(Math.min(I, T)), b = t.minH === void 0 ? void 0 : p(t.minH), F = b === void 0 ? Math.max(2, Math.min(v, Math.ceil(v * 0.4))) : Math.min(v, b);
1062
+ return {
1063
+ ...t,
1064
+ x: h(C * A),
1065
+ y: P,
1066
+ w: H(Math.max(1, f * A)),
1067
+ h: v,
1068
+ minW: t.minW === void 0 ? void 0 : H(Math.max(1, t.minW * A)),
1069
+ minH: H(F),
1070
+ maxW: t.maxW === void 0 ? void 0 : H(Math.max(1, t.maxW * A)),
1071
+ maxH: t.maxH === void 0 ? void 0 : H(Math.max(1, t.maxH * _))
1072
+ };
1073
+ }
1074
+ function Ke(t, e) {
1075
+ if (!W(e.data) || e.data.nestedLayoutMode === "grid") return null;
1076
+ const a = M(e.data.nestedLayoutBasis), n = O(a.w), i = O(a.h);
1077
+ if (n === void 0 || i === void 0) return null;
1078
+ const s = O(a.x) ?? 0, c = O(a.y) ?? 0, d = Math.max(1, n), r = Math.max(1, i), o = t.flatMap((f) => {
1079
+ const x = O(f.x), g = O(f.y), C = O(f.w), y = O(f.h);
1080
+ if (x === void 0 || g === void 0 || C === void 0 || y === void 0) return [];
1081
+ const w = tt(x, C, s, d), R = tt(g, y, c, r);
1082
+ return [{ right: w + C, bottom: R + y }];
1083
+ });
1084
+ if (o.length === 0) return null;
1085
+ const m = Math.max(...o.map((f) => f.right)), u = Math.max(...o.map((f) => f.bottom)), l = m <= d && u <= r;
1086
+ return {
1087
+ cols: l ? d : Math.max(d, m),
1088
+ rows: l ? r : Math.max(r, u)
1089
+ };
1090
+ }
1091
+ function ze(t, e) {
1092
+ var i, s;
1093
+ if (!W(t.data)) return !1;
1094
+ const a = M(t.data), n = `${((i = t.meta) == null ? void 0 : i.composeSource) || ""} ${typeof a.source == "string" ? a.source : ""} ${((s = t.source) == null ? void 0 : s.service) || ""}`;
1095
+ return !/image/i.test(n) || t.data.nestedLayoutMode === "stack" || t.data.nestedLayoutMode === "grid" ? !1 : e.length > rt;
1096
+ }
1097
+ function Ve(t, e) {
1098
+ var r;
1099
+ if (t.length === 0) return [];
1100
+ const a = [...t].sort(E), n = Math.min(2, Math.max(1, a.length)), i = Math.max(1, Math.ceil(a.length / n)), s = Math.max(i, p(((r = e.layout) == null ? void 0 : r.h) ?? i)), c = Math.max(1, Math.floor(s / i)), d = Math.floor(S / n);
1101
+ return a.map((o, m) => {
1102
+ const u = m % n, l = Math.floor(m / n), f = u === n - 1 ? S - d : u * d, x = u === n - 1 ? S - f : d, g = l * c, C = l === i - 1 ? s : (l + 1) * c, y = Math.max(1, C - g);
1103
+ return {
1104
+ ...o,
1105
+ x: f,
1106
+ y: g,
1107
+ w: x,
1108
+ h: y,
1109
+ minW: o.minW === void 0 ? void 0 : Math.min(x, p(o.minW)),
1110
+ minH: o.minH === void 0 ? void 0 : Math.min(y, p(o.minH)),
1111
+ maxW: o.maxW === void 0 ? void 0 : Math.max(x, p(o.maxW)),
1112
+ maxH: o.maxH === void 0 ? void 0 : Math.max(y, p(o.maxH))
1113
+ };
1114
+ });
1115
+ }
1116
+ function $e(t, e) {
1117
+ const a = Math.max(
1118
+ 0,
1119
+ Math.min(h(t.x) + p(t.w), h(e.x) + p(e.w)) - Math.max(h(t.x), h(e.x))
1120
+ ), n = Math.max(
1121
+ 0,
1122
+ Math.min(h(t.y) + p(t.h), h(e.y) + p(e.h)) - Math.max(h(t.y), h(e.y))
1123
+ );
1124
+ return a * n;
1125
+ }
1126
+ function qe(t) {
1127
+ for (let e = 0; e < t.length; e += 1) {
1128
+ const a = t[e];
1129
+ if (a)
1130
+ for (let n = e + 1; n < t.length; n += 1) {
1131
+ const i = t[n];
1132
+ if (!i) continue;
1133
+ const s = $e(a, i);
1134
+ if (s <= 0) continue;
1135
+ const c = p(a.w) * p(a.h), d = p(i.w) * p(i.h);
1136
+ if (s / Math.max(1, Math.min(c, d)) >= 0.6) return !0;
1137
+ }
1138
+ }
1139
+ return !1;
1140
+ }
1141
+ function ba(t, e = {}) {
1142
+ if (t.length < 2 || !qe(t))
1143
+ return t.map((o) => ({ ...o }));
1144
+ const a = t.map((o, m) => ({ child: o, index: m })).sort((o, m) => h(o.child.y) - h(m.child.y) || h(o.child.x) - h(m.child.x) || o.index - m.index).map((o) => o.child), n = Math.min(2, Math.max(1, a.length)), i = Math.max(1, Math.ceil(a.length / n)), s = a.reduce((o, m) => Math.max(
1145
+ o,
1146
+ h(m.y) + p(m.h)
1147
+ ), 0), c = Math.max(
1148
+ S,
1149
+ i,
1150
+ p(e.parentRows ?? 0),
1151
+ s
1152
+ ), d = Math.max(1, Math.floor(c / i)), r = Math.floor(S / n);
1153
+ return a.map((o, m) => {
1154
+ const u = m % n, l = Math.floor(m / n), f = u === n - 1 ? S - r : u * r, x = u === n - 1 ? S - f : r, g = l * d, C = l === i - 1 ? c : (l + 1) * d, y = Math.max(1, C - g);
1155
+ return {
1156
+ ...o,
1157
+ x: f,
1158
+ y: g,
1159
+ w: x,
1160
+ h: y,
1161
+ minW: o.minW === void 0 ? void 0 : Math.min(x, p(o.minW)),
1162
+ minH: o.minH === void 0 ? void 0 : Math.min(y, p(o.minH)),
1163
+ maxW: o.maxW === void 0 ? void 0 : Math.max(x, p(o.maxW)),
1164
+ maxH: o.maxH === void 0 ? void 0 : Math.max(y, p(o.maxH))
1165
+ };
1166
+ });
1167
+ }
1168
+ function je(t, e) {
1169
+ if (t.length < te || t.length > ee) return !1;
1170
+ const a = Math.min(...t.map((o) => h(o.y))), n = Math.max(...t.map((o) => h(o.y) + p(o.h))), i = Math.max(1, n - a), s = Math.max(...t.map((o) => p(o.h))), c = t.length === 1 ? 1 : t.length >= 7 ? 3 : 2, d = Math.ceil(t.length / c) * j, r = e >= d + j;
1171
+ return i >= d + j || s > j * 1.5 || r;
1172
+ }
1173
+ function La(t, e = {}) {
1174
+ const a = p(e.parentRows ?? 0);
1175
+ if (!je(t, a))
1176
+ return t.map((c) => ({ ...c }));
1177
+ const n = t.map((c, d) => ({ child: c, index: d })).sort((c, d) => h(c.child.y) - h(d.child.y) || h(c.child.x) - h(d.child.x) || c.index - d.index).map((c) => c.child), i = n.length === 1 ? 1 : n.length >= 7 ? 3 : 2, s = Math.floor(S / i);
1178
+ return n.map((c, d) => {
1179
+ const r = d % i, o = Math.floor(d / i), m = r === i - 1 ? S - s : r * s, u = r === i - 1 ? S - m : s, l = j;
1180
+ return {
1181
+ ...c,
1182
+ x: m,
1183
+ y: o * l,
1184
+ w: u,
1185
+ h: l,
1186
+ minW: c.minW === void 0 ? void 0 : Math.min(u, p(c.minW)),
1187
+ minH: c.minH === void 0 ? void 0 : Math.min(l, p(c.minH)),
1188
+ maxW: c.maxW === void 0 ? void 0 : Math.max(u, p(c.maxW)),
1189
+ maxH: c.maxH === void 0 ? void 0 : Math.max(l, p(c.maxH))
1190
+ };
1191
+ });
1192
+ }
1193
+ function Oa(t) {
1194
+ const e = t.reduce((a, n) => Math.max(
1195
+ a,
1196
+ h(n.y) + p(n.h)
1197
+ ), 0);
1198
+ return e > 0 ? e + ae : 0;
1199
+ }
1200
+ function Ye(t, e) {
1201
+ if (t.length === 0 || e < 12) return !1;
1202
+ const a = Math.min(...t.map((s) => h(s.y))), n = Math.max(...t.map((s) => h(s.y) + p(s.h))), i = Math.max(1, n - a);
1203
+ return i <= Tt || i / Math.max(1, e) < Ht;
1204
+ }
1205
+ function Ue(t) {
1206
+ const e = /* @__PURE__ */ new Map();
1207
+ return t.forEach((a) => {
1208
+ const n = h(a.x), i = Math.min(S - 1, Math.max(0, n));
1209
+ e.set(i, [...e.get(i) || [], a]);
1210
+ }), [...e.entries()].sort(([a], [n]) => a - n).map(([, a]) => a.sort((n, i) => h(n.y) - h(i.y) || h(n.x) - h(i.x) || String(n.i).localeCompare(String(i.i))));
1211
+ }
1212
+ function Xe(t, e, a, n, i) {
1213
+ const s = Math.max(S, i), c = Math.max(1, Math.floor(S / Math.max(1, a))), d = e === a - 1 ? S - c : e * c, r = Math.min(...n.map((x) => h(x.y))), o = Math.max(...n.map((x) => h(x.y) + p(x.h))), m = Math.max(1, o - r), u = s / m, l = Math.max(0, Math.round((h(t.y) - r) * u)), f = Math.max(
1214
+ p(t.minH ?? 1),
1215
+ Math.round(p(t.h) * u)
1216
+ );
1217
+ return {
1218
+ ...t,
1219
+ x: d,
1220
+ w: e === a - 1 ? S - d : c,
1221
+ y: l,
1222
+ h: f,
1223
+ minW: Math.min(c, p(t.minW ?? Math.min(3, c))),
1224
+ minH: Math.min(f, p(t.minH ?? 2))
1225
+ };
1226
+ }
1227
+ function Je(t, e) {
1228
+ var d, r;
1229
+ const a = M(e.data), n = `${((d = e.meta) == null ? void 0 : d.composeSource) || ""} ${typeof a.source == "string" ? a.source : ""}`;
1230
+ if (!/image/i.test(n)) return [...t];
1231
+ const i = p(((r = e.layout) == null ? void 0 : r.h) ?? 0);
1232
+ if (!Ye(t, i)) return [...t];
1233
+ const s = Ue(t).slice(0, S), c = /* @__PURE__ */ new Map();
1234
+ return s.forEach((o, m) => {
1235
+ o.forEach((u) => {
1236
+ c.set(String(u.i), Xe(
1237
+ u,
1238
+ m,
1239
+ s.length,
1240
+ o,
1241
+ i
1242
+ ));
1243
+ });
1244
+ }), t.map((o) => c.get(String(o.i)) || o);
1245
+ }
1246
+ function vt(t) {
1247
+ return !t || t.length === 0 ? 0 : t.reduce((e, a) => Math.max(
1248
+ e,
1249
+ h(a.y) + p(a.h)
1250
+ ), 0);
1251
+ }
1252
+ function Mt(t) {
1253
+ return t.map((e) => e.i).sort().join("|");
1254
+ }
1255
+ function Qe(t, e) {
1256
+ return h(t.x) === h(e.x) && h(t.y) === h(e.y) && p(t.w) === p(e.w) && p(t.h) === p(e.h);
1257
+ }
1258
+ function St(t) {
1259
+ return t.length === 0 ? 0 : Math.min(...t.map((e) => h(e.y)));
1260
+ }
1261
+ function Wa(t, e) {
1262
+ if (!t || t.length === 0 || e.length === 0 || Mt(t) !== Mt(e)) return !1;
1263
+ const a = new Map(e.map((l) => [l.i, l])), n = t.filter((l) => {
1264
+ const f = a.get(l.i);
1265
+ return f ? !Qe(l, f) : !0;
1266
+ }).length;
1267
+ if (n === 0) return !1;
1268
+ const i = vt(t), s = vt(e);
1269
+ if (s < 12) return !1;
1270
+ const c = St(t), d = St(e), r = t.reduce((l, f) => Math.max(l, p(f.h)), 0), o = e.reduce((l, f) => Math.max(l, p(f.h)), 0), m = r / Math.max(1, i), u = o / Math.max(1, s);
1271
+ return i <= Tt || i / Math.max(1, s) < Ht || o >= 16 && r <= 8 || t.length > rt && c >= Math.max(4, d + 6) && n >= Math.max(1, Math.ceil(t.length * 0.5)) || t.length > rt && n >= Math.max(1, Math.ceil(t.length * 0.5)) && r > o * 1.5 && m > u * 1.4;
1272
+ }
1273
+ function Dt(t) {
1274
+ const e = Ge(t);
1275
+ if (e.length === 0) return [];
1276
+ const a = e.map((c, d) => Pt(c, d)), n = ze(t, e), i = n ? null : Ke(a, t);
1277
+ return (n ? Ve(a, t) : i ? a : Je(a, t)).map((c) => Z(
1278
+ i && Fe(c, t, i.rows, i.cols) || c,
1279
+ S,
1280
+ S,
1281
+ t.id
1282
+ )).sort(E);
1283
+ }
1284
+ function Ze(t, e, a = /* @__PURE__ */ new Map()) {
1285
+ const n = W(t.data) && Array.isArray(t.data.nestedBlocks) ? t.data.nestedBlocks : [], i = new Map(n.map((s) => [s.id, s]));
1286
+ return [...e].sort(E).map((s) => {
1287
+ const c = {
1288
+ id: s.i,
1289
+ title: s.i,
1290
+ kind: "display",
1291
+ slot: "main",
1292
+ dataBindingStatus: "error",
1293
+ dataBindingError: "需要补充业务口径后再问数",
1294
+ humanIntervention: { required: !0, reason: "missing_nested_payload" }
1295
+ };
1296
+ return {
1297
+ ...We(i.get(s.i), a.get(s.i), c),
1298
+ id: s.i,
1299
+ layout: {
1300
+ i: s.i,
1301
+ x: s.x,
1302
+ y: s.y,
1303
+ w: s.w,
1304
+ h: s.h,
1305
+ minW: s.minW,
1306
+ minH: s.minH,
1307
+ maxW: s.maxW,
1308
+ maxH: s.maxH,
1309
+ static: s.static,
1310
+ parentId: s.parentId || t.id
1311
+ }
1312
+ };
1313
+ });
1314
+ }
1315
+ function ta(t) {
1316
+ const e = /* @__PURE__ */ new Map();
1317
+ return t.forEach((a) => {
1318
+ !W(a.data) || !Array.isArray(a.data.nestedBlocks) || a.data.nestedBlocks.forEach((n) => {
1319
+ e.set(n.id, n);
1320
+ });
1321
+ }), e;
1322
+ }
1323
+ function ea(t, e, a) {
1324
+ const n = new Map(e.map((i) => [i.id, i]));
1325
+ a.forEach(({ node: i }) => {
1326
+ if (t.has(i.i) || !i.parentId) return;
1327
+ const s = n.get(i.i);
1328
+ s && t.set(i.i, lt(s, {
1329
+ parentId: i.parentId,
1330
+ layout: {
1331
+ ...s.layout,
1332
+ ...i,
1333
+ i: s.id
1334
+ }
1335
+ }));
1336
+ });
1337
+ }
1338
+ function aa(t) {
1339
+ const e = /* @__PURE__ */ new Map();
1340
+ return t.forEach((a) => {
1341
+ !W(a.data) || !Array.isArray(a.data.nestedBlocks) || a.data.nestedBlocks.forEach((n) => {
1342
+ e.set(n.id, a.id);
1343
+ });
1344
+ }), e;
1345
+ }
1346
+ function na(t, e, a, n, i) {
1347
+ const s = new Map(t.map((d) => [d.id, d])), c = [];
1348
+ return e.forEach((d, r) => {
1349
+ if (s.has(r) || i.has(r)) return;
1350
+ const o = n.get(r), m = o ? s.get(o) : void 0, u = a.get(r);
1351
+ !m || !u || c.push(ke(u, m, {
1352
+ layout: ie(
1353
+ { ...d, i: r },
1354
+ o ? e.get(o) : void 0,
1355
+ u.layout ? { ...u.layout } : void 0
1356
+ )
1357
+ }));
1358
+ }), c.sort((d, r) => E({
1359
+ i: d.id,
1360
+ x: d.layout.x,
1361
+ y: d.layout.y,
1362
+ w: d.layout.w,
1363
+ h: d.layout.h
1364
+ }, {
1365
+ i: r.id,
1366
+ x: r.layout.x,
1367
+ y: r.layout.y,
1368
+ w: r.layout.w,
1369
+ h: r.layout.h
1370
+ }));
1371
+ }
1372
+ function ia(t) {
1373
+ return Object.prototype.hasOwnProperty.call(t, "children");
1374
+ }
1375
+ function wt(t, e) {
1376
+ return (e == null ? void 0 : e.origin) === "replacement" && e.listingParentId === t && e.node.parentId === t;
1377
+ }
1378
+ function Nt(t, e) {
1379
+ const a = t.get(e.node.i);
1380
+ (a == null ? void 0 : a.parentSource) === "explicitParentId" && e.parentSource === "inferredParent" || t.set(e.node.i, e);
1381
+ }
1382
+ function ra(t) {
1383
+ const e = /* @__PURE__ */ new Map();
1384
+ return t.forEach(({ node: a }) => {
1385
+ const n = a.parentId;
1386
+ if (!n) return;
1387
+ const i = e.get(n) || [];
1388
+ i.push(a), e.set(n, i);
1389
+ }), e;
1390
+ }
1391
+ function sa(t, e, a) {
1392
+ const n = /* @__PURE__ */ new Map();
1393
+ return Dt(t).forEach((i) => {
1394
+ var c;
1395
+ const s = (c = e.get(i.i)) == null ? void 0 : c.node;
1396
+ s && s.parentId !== t.id || n.set(i.i, i);
1397
+ }), (a.get(t.id) || []).forEach((i) => {
1398
+ n.set(i.i, i);
1399
+ }), [...n.values()].sort(E);
1400
+ }
1401
+ function Ta(t, e) {
1402
+ const a = new Map(e.nodes.filter((u) => !u.parentId).map((u) => [u.i, u])), n = ta(t), i = aa(t), s = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Set(), d = /* @__PURE__ */ new Map();
1403
+ e.nodes.forEach((u) => {
1404
+ ia(u) && s.add(u.i);
1405
+ }), e.nodes.forEach((u) => {
1406
+ u.parentId && (s.has(u.parentId) || Nt(d, {
1407
+ node: u,
1408
+ parentSource: "explicitParentId",
1409
+ origin: "flat"
1410
+ })), (Array.isArray(u.children) ? u.children : []).forEach((f) => {
1411
+ const x = f.parentId || u.i, g = f.parentId ? "explicitParentId" : "inferredParent";
1412
+ Nt(d, {
1413
+ node: { ...f, parentId: x },
1414
+ parentSource: g,
1415
+ origin: "replacement",
1416
+ listingParentId: u.i
1417
+ });
1418
+ });
1419
+ });
1420
+ const r = ra(d);
1421
+ ea(n, t, d), d.forEach(({ node: u }) => {
1422
+ const l = u.parentId;
1423
+ if (!l) return;
1424
+ const f = i.get(u.i);
1425
+ f && f !== l && c.add(f);
1426
+ });
1427
+ const o = na(
1428
+ t,
1429
+ a,
1430
+ n,
1431
+ i,
1432
+ d
1433
+ );
1434
+ return o.forEach((u) => {
1435
+ const l = i.get(u.id);
1436
+ l && c.add(l);
1437
+ }), [...t.filter((u) => !d.has(u.id)).map((u) => {
1438
+ const l = a.get(u.id), f = l ? {
1439
+ ...u.layout,
1440
+ i: u.id,
1441
+ x: l.x,
1442
+ y: l.y,
1443
+ w: l.w,
1444
+ h: l.h,
1445
+ minW: l.minW,
1446
+ minH: l.minH,
1447
+ maxW: l.maxW,
1448
+ maxH: l.maxH,
1449
+ static: l.static
1450
+ } : u.layout;
1451
+ if (!W(u.data))
1452
+ return { ...u, layout: f };
1453
+ const x = s.has(u.id), g = r.get(u.id) || [], C = g.some((R) => {
1454
+ const A = d.get(R.i);
1455
+ return A ? x ? wt(u.id, A) : A.origin === "flat" || A.parentSource === "explicitParentId" : !1;
1456
+ });
1457
+ if (!(x || C || c.has(u.id)))
1458
+ return { ...u, layout: f };
1459
+ const w = x ? g.filter((R) => {
1460
+ const A = d.get(R.i);
1461
+ return wt(u.id, A);
1462
+ }) : sa(u, d, r);
1463
+ return {
1464
+ ...u,
1465
+ layout: f,
1466
+ meta: {
1467
+ ...u.meta,
1468
+ manualCanvasLayout: !0,
1469
+ layoutManualOverride: !0,
1470
+ layoutManualOverrideSource: "gridstack"
1471
+ },
1472
+ data: {
1473
+ ...u.data,
1474
+ nestedLayoutMode: "grid",
1475
+ nestedBlocks: Ze(u, w, n)
1476
+ }
1477
+ };
1478
+ }), ...o];
1479
+ }
1480
+ const Ct = {
1481
+ patch: "modifyCard",
1482
+ updateData: "changeDataSource",
1483
+ updateStyle: "modifyCard",
1484
+ updateTitle: "renameTitle",
1485
+ updateSize: "adjustLayout",
1486
+ updatePosition: "adjustLayout",
1487
+ replaceRenderer: "changeChart"
1488
+ };
1489
+ function oa(t) {
1490
+ return {
1491
+ ...t,
1492
+ blocks: t.blocks.map((e) => ({
1493
+ ...e,
1494
+ layout: { ...e.layout },
1495
+ data: ot(e.data),
1496
+ meta: ot(e.meta),
1497
+ renderer: e.renderer ? { ...e.renderer } : void 0,
1498
+ state: { ...e.state }
1499
+ }))
1500
+ };
1501
+ }
1502
+ function ot(t) {
1503
+ return !t || typeof t != "object" ? t : JSON.parse(JSON.stringify(t));
1504
+ }
1505
+ function L(t, e, a) {
1506
+ return {
1507
+ status: "failed",
1508
+ affectedCardIds: [],
1509
+ error: { code: t, message: e, details: a }
1510
+ };
1511
+ }
1512
+ function ca(t) {
1513
+ return (t == null ? void 0 : t.scope) || "card";
1514
+ }
1515
+ function da(t, e) {
1516
+ return e ? t.blocks.findIndex((a) => a.id === e) : -1;
1517
+ }
1518
+ function ua(t, e) {
1519
+ if (!e) return null;
1520
+ for (let a = 0; a < t.blocks.length; a += 1) {
1521
+ const n = t.blocks[a];
1522
+ if (!W(n.data) || !Array.isArray(n.data.nestedBlocks)) continue;
1523
+ const i = n.data.nestedBlocks.findIndex((c) => c.id === e);
1524
+ if (i < 0) continue;
1525
+ const s = n.data.nestedBlocks[i];
1526
+ return {
1527
+ parentIndex: a,
1528
+ childIndex: i,
1529
+ parentBlock: n,
1530
+ nestedBlock: s,
1531
+ materializedBlock: kt(s, n)
1532
+ };
1533
+ }
1534
+ return null;
1535
+ }
1536
+ function ma(t, e, a) {
1537
+ const n = t.blocks[e.parentIndex];
1538
+ if (!W(n.data)) return;
1539
+ const i = n.data, s = Array.isArray(i.nestedBlocks) ? [...i.nestedBlocks] : [];
1540
+ s[e.childIndex] = lt(a, {
1541
+ parentId: n.id,
1542
+ layout: {
1543
+ ...a.layout,
1544
+ i: a.id,
1545
+ parentId: n.id
1546
+ }
1547
+ }), t.blocks[e.parentIndex] = {
1548
+ ...n,
1549
+ data: {
1550
+ ...i,
1551
+ nestedLayoutMode: "grid",
1552
+ nestedBlocks: s
1553
+ }
1554
+ };
1555
+ }
1556
+ function la(t, e) {
1557
+ const a = t.blocks[e.parentIndex];
1558
+ if (!W(a.data)) return;
1559
+ const n = a.data, i = Array.isArray(n.nestedBlocks) ? [...n.nestedBlocks] : [];
1560
+ i.splice(e.childIndex, 1), t.blocks[e.parentIndex] = {
1561
+ ...a,
1562
+ data: {
1563
+ ...n,
1564
+ nestedLayoutMode: "grid",
1565
+ nestedBlocks: i
1566
+ }
1567
+ };
1568
+ }
1569
+ function Rt(t, e) {
1570
+ const a = { ...t };
1571
+ return typeof e.title == "string" && (a.title = e.title), typeof e.subtitle == "string" && (a.subtitle = e.subtitle), e.data && typeof e.data == "object" && (a.data = ot(e.data)), e.meta && typeof e.meta == "object" && (a.meta = { ...a.meta || {}, ...e.meta }), e.renderer && typeof e.renderer == "object" && (a.renderer = { ...a.renderer || { engine: "echarts", rendererKey: "customCanvas" }, ...e.renderer }), e.layout && typeof e.layout == "object" && (a.layout = { ...a.layout, ...e.layout }), a;
1572
+ }
1573
+ function nt(t) {
1574
+ var a, n, i, s;
1575
+ const e = String(((a = t.meta) == null ? void 0 : a.capabilityId) || ((n = t.source) == null ? void 0 : n.resourceKey) || "");
1576
+ return ((i = t.meta) == null ? void 0 : i.workbenchOrganizationCard) === !0 || String(((s = t.meta) == null ? void 0 : s.macroCapabilityId) || "").includes("workbench") || e.startsWith("card.workbench.") || t.id.startsWith("workbench-org-");
1577
+ }
1578
+ function pa(t) {
1579
+ return `canvas-tx-${t}-${Date.now()}-${Math.random().toString(36).slice(2)}`;
1580
+ }
1581
+ function ha(t) {
1582
+ return t in Ct ? Ct[t] : [
1583
+ "freeModify",
1584
+ "renameTitle",
1585
+ "editBodyText",
1586
+ "editText",
1587
+ "changeChart",
1588
+ "changeDataSource",
1589
+ "adjustLayout",
1590
+ "replaceCard",
1591
+ "locateCard",
1592
+ "modifyCard",
1593
+ "deleteCard",
1594
+ "clearCanvas",
1595
+ "overwriteCanvas",
1596
+ "rollback",
1597
+ "mutateCapability"
1598
+ ].includes(t) ? t : null;
1599
+ }
1600
+ async function Gt(t, e) {
1601
+ var l, f, x, g, C, y, w, R, A, _, P, D, G;
1602
+ const a = ha(e.operation);
1603
+ if (!a) return L("UNSUPPORTED_OPERATION", `不支持的改卡操作:${e.operation}`);
1604
+ if (e.baseSnapshotVersion !== void 0 && e.baseSnapshotVersion !== t.version)
1605
+ return L("VERSION_CONFLICT", "画布快照版本已变化,请基于最新快照重试。", {
1606
+ expected: e.baseSnapshotVersion,
1607
+ actual: t.version
1608
+ });
1609
+ const n = oa(t), i = e.payload || {}, s = ca(e.target), c = da(n, (l = e.target) == null ? void 0 : l.cardId), d = c >= 0 ? null : ua(n, (f = e.target) == null ? void 0 : f.cardId), r = c >= 0 ? n.blocks[c] : d == null ? void 0 : d.materializedBlock, o = (I) => {
1610
+ if (c >= 0) {
1611
+ n.blocks[c] = I;
1612
+ return;
1613
+ }
1614
+ d && ma(n, d, I);
1615
+ };
1616
+ if (!["clearCanvas", "overwriteCanvas", "rollback"].includes(a) && !r)
1617
+ return L("CARD_NOT_FOUND", "改卡目标不存在或缺少 cardId。", e.target);
1618
+ const m = [], u = pa(a);
1619
+ if (a === "locateCard")
1620
+ return r ? {
1621
+ status: "success",
1622
+ snapshot: t,
1623
+ affectedCardIds: [r.id],
1624
+ locatedCardId: r.id,
1625
+ transactionId: u
1626
+ } : L("CARD_NOT_FOUND", "定位目标不存在。", e.target);
1627
+ if (a === "clearCanvas") {
1628
+ const I = i.includeSystemCards === !0, T = n.blocks.length;
1629
+ return n.blocks = I ? [] : n.blocks.filter(nt), m.push(...t.blocks.filter((v) => I || !nt(v)).map((v) => v.id)), {
1630
+ status: "success",
1631
+ snapshot: { ...n, version: t.version + 1, updatedAt: (/* @__PURE__ */ new Date()).toISOString() },
1632
+ affectedCardIds: m,
1633
+ transactionId: u,
1634
+ error: T === n.blocks.length ? { code: "OBJECT_NOT_FOUND", message: "画布中没有可清空的业务卡片。" } : void 0
1635
+ };
1636
+ }
1637
+ if (a === "overwriteCanvas") {
1638
+ const I = Array.isArray(i.blocks) ? i.blocks : [];
1639
+ if (I.length === 0) return L("INVALID_PARAMS", "overwriteCanvas 需要 payload.blocks。");
1640
+ const v = i.keepSystemCards !== !1 ? n.blocks.filter(nt) : [], b = [];
1641
+ for (const F of I) {
1642
+ const K = await it(F, [
1643
+ ...v.map((V) => V.layout),
1644
+ ...b.map((V) => V.layout)
1645
+ ]);
1646
+ K.block && b.push(K.block);
1647
+ }
1648
+ return n.blocks = [...v, ...b], m.push(...b.map((F) => F.id)), {
1649
+ status: "success",
1650
+ snapshot: { ...n, version: t.version + 1, updatedAt: (/* @__PURE__ */ new Date()).toISOString() },
1651
+ affectedCardIds: m,
1652
+ transactionId: u
1653
+ };
1654
+ }
1655
+ if (a === "rollback") {
1656
+ const I = i.snapshot;
1657
+ return !I || typeof I != "object" ? L("INVALID_PARAMS", "rollback 需要 payload.snapshot。") : {
1658
+ status: "success",
1659
+ snapshot: { ...I, version: t.version + 1, updatedAt: (/* @__PURE__ */ new Date()).toISOString() },
1660
+ affectedCardIds: ((x = I.blocks) == null ? void 0 : x.map((T) => T.id)) || [],
1661
+ transactionId: u
1662
+ };
1663
+ }
1664
+ if (!r) return L("CARD_NOT_FOUND", "改卡目标不存在。", e.target);
1665
+ if (a === "deleteCard") {
1666
+ if (s === "canvas") return await Gt(t, { ...e, operation: "clearCanvas" });
1667
+ s === "cardObject" ? (o({
1668
+ ...r,
1669
+ meta: {
1670
+ ...r.meta || {},
1671
+ removedObjects: [
1672
+ ...Array.isArray((g = r.meta) == null ? void 0 : g.removedObjects) ? r.meta.removedObjects : [],
1673
+ ((C = e.target) == null ? void 0 : C.objectSelector) || i.objectSelector || { deletedAt: (/* @__PURE__ */ new Date()).toISOString() }
1674
+ ]
1675
+ }
1676
+ }), m.push(r.id)) : (d ? la(n, d) : n.blocks.splice(c, 1), m.push(r.id));
1677
+ }
1678
+ if (a === "replaceCard") {
1679
+ const I = i.insertCard || i.card || i, T = i.keepLayout !== !1, v = await it({
1680
+ ...I,
1681
+ layout: T ? r.layout : I.layout
1682
+ }, n.blocks.filter((b) => b.id !== r.id).map((b) => b.layout));
1683
+ if (!v.block) return L("CAPABILITY_NOT_FOUND", v.reason || "替换卡片能力不存在。", v);
1684
+ o(v.block), m.push(r.id, v.block.id);
1685
+ }
1686
+ if (a === "renameTitle") {
1687
+ const I = typeof i.title == "string" ? i.title : typeof i.text == "string" ? i.text : "";
1688
+ if (!I.trim()) return L("INVALID_PARAMS", "renameTitle 需要 payload.title。");
1689
+ o({ ...r, title: I }), m.push(r.id);
1690
+ }
1691
+ if (a === "editBodyText" || a === "editText") {
1692
+ const I = typeof i.text == "string" ? i.text : typeof i.bodyText == "string" ? i.bodyText : "";
1693
+ if (!I.trim()) return L("INVALID_PARAMS", `${a} 需要 payload.text。`);
1694
+ o({
1695
+ ...r,
1696
+ meta: {
1697
+ ...r.meta || {},
1698
+ bodyText: a === "editBodyText" ? I : (y = r.meta) == null ? void 0 : y.bodyText,
1699
+ editedText: a === "editText" ? I : (w = r.meta) == null ? void 0 : w.editedText
1700
+ }
1701
+ }), m.push(r.id);
1702
+ }
1703
+ if (a === "changeChart") {
1704
+ const I = typeof i.rendererKey == "string" ? i.rendererKey : "";
1705
+ if (!I.trim()) return L("INVALID_PARAMS", "changeChart 需要 payload.rendererKey。");
1706
+ o({
1707
+ ...r,
1708
+ renderer: { ...r.renderer || { engine: "echarts", rendererKey: I }, rendererKey: I },
1709
+ meta: { ...r.meta || {}, chartChangedAt: (/* @__PURE__ */ new Date()).toISOString() }
1710
+ }), m.push(r.id);
1711
+ }
1712
+ if (a === "changeDataSource") {
1713
+ if (!i.data && !i.source) return L("INVALID_PARAMS", "changeDataSource 需要 payload.data 或 payload.source。");
1714
+ o(Rt(r, i)), m.push(r.id);
1715
+ }
1716
+ if (a === "adjustLayout") {
1717
+ const I = i.layout;
1718
+ if (!I) return L("INVALID_PARAMS", "adjustLayout 需要 payload.layout。");
1719
+ const T = n.blocks.filter((b) => b.id !== r.id).map((b) => b.layout), v = Kt({
1720
+ preset: "medium",
1721
+ layout: { ...r.layout, ...I },
1722
+ placed: T
1723
+ });
1724
+ o({ ...r, layout: zt(r.id, v) }), m.push(r.id);
1725
+ }
1726
+ if (a === "modifyCard" || a === "freeModify") {
1727
+ if (a === "freeModify" && !(((R = e.target) == null ? void 0 : R.cardId) && i.scope && i.content && i.expectedResult))
1728
+ return L("INVALID_PARAMS", "freeModify 缺目标、修改范围、修改内容或预期结果,已拒绝模糊写入。");
1729
+ o(Rt(r, i)), m.push(r.id);
1730
+ }
1731
+ if (a === "mutateCapability") {
1732
+ const I = i.mutation;
1733
+ if (!I || typeof I != "object") return L("INVALID_PARAMS", "mutateCapability 需要 payload.mutation。");
1734
+ const T = I.capabilitySpec;
1735
+ if (I.action === "mount" || I.action === "replace") {
1736
+ const v = Jt(T, String(i.userNeed || "修改卡片内部能力"));
1737
+ if (!v.allowed || !v.capability) return L(((A = v.error) == null ? void 0 : A.code) || "POLICY_REJECTED", ((_ = v.error) == null ? void 0 : _.message) || "Primitive Policy 拒绝。", v.gap || ((P = v.error) == null ? void 0 : P.details));
1738
+ const b = Array.isArray((D = r.meta) == null ? void 0 : D.capabilityMounts) ? r.meta.capabilityMounts : [], F = I.action === "replace" ? [...b.filter((K) => {
1739
+ var V;
1740
+ return K.id !== ((V = v.capability) == null ? void 0 : V.id);
1741
+ }), v.capability] : [...b, v.capability];
1742
+ o({ ...r, meta: { ...r.meta || {}, capabilityMounts: F } }), m.push(r.id);
1743
+ } else
1744
+ o({
1745
+ ...r,
1746
+ meta: {
1747
+ ...r.meta || {},
1748
+ capabilityMutationLog: [
1749
+ ...Array.isArray((G = r.meta) == null ? void 0 : G.capabilityMutationLog) ? r.meta.capabilityMutationLog : [],
1750
+ I
1751
+ ]
1752
+ }
1753
+ }), m.push(r.id);
1754
+ }
1755
+ return m.length === 0 ? L("UNSUPPORTED_OPERATION", `生命周期操作未产生修改:${a}`) : {
1756
+ status: "success",
1757
+ snapshot: {
1758
+ ...n,
1759
+ version: t.version + 1,
1760
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
1761
+ },
1762
+ affectedCardIds: [...new Set(m)],
1763
+ transactionId: u
1764
+ };
1765
+ }
1766
+ function Et(t) {
1767
+ return t || `canvas-req-${Date.now()}-${Math.random().toString(36).slice(2)}`;
1768
+ }
1769
+ function Y(t, e, a) {
1770
+ return {
1771
+ success: !1,
1772
+ requestId: e,
1773
+ operation: t,
1774
+ affectedCardIds: [],
1775
+ error: a
1776
+ };
1777
+ }
1778
+ function At(t, e, a) {
1779
+ return t ? null : Y(e, a, {
1780
+ code: "INVALID_PARAMS",
1781
+ message: "画布快照尚未初始化,不能执行出卡或改卡。"
1782
+ });
1783
+ }
1784
+ function Ha(t) {
1785
+ return {
1786
+ async insertCard(e) {
1787
+ const a = Et(e.requestId), n = t.getSnapshot(), i = At(n, "insertCard", a);
1788
+ if (i || !n) return i;
1789
+ if (e.baseSnapshotVersion !== void 0 && e.baseSnapshotVersion !== n.version)
1790
+ return Y("insertCard", a, {
1791
+ code: "VERSION_CONFLICT",
1792
+ message: "画布快照版本已变化,请基于最新快照重试。",
1793
+ details: { expected: e.baseSnapshotVersion, actual: n.version }
1794
+ });
1795
+ const s = await it(e, n.blocks.map((o) => o.layout));
1796
+ if (!s.block)
1797
+ return Y("insertCard", a, {
1798
+ code: "CAPABILITY_NOT_FOUND",
1799
+ message: s.reason || "卡片能力不存在或不可创建。",
1800
+ details: s
1801
+ });
1802
+ const c = n.version;
1803
+ if (e.targetScope === "nested" || e.targetParentId) {
1804
+ const o = e.targetParentId, m = n.blocks.findIndex((w) => w.id === o), u = m >= 0 ? n.blocks[m] : void 0;
1805
+ if (!o || !u || !W(u.data))
1806
+ return Y("insertCard", a, {
1807
+ code: "CARD_NOT_FOUND",
1808
+ message: "未找到可插入嵌套卡片的父卡。",
1809
+ details: { targetParentId: o }
1810
+ });
1811
+ const l = lt(s.block, {
1812
+ parentId: o,
1813
+ layout: {
1814
+ ...s.block.layout,
1815
+ ...e.layout,
1816
+ i: s.block.id
1817
+ }
1818
+ }), f = u.data, x = Array.isArray(f.nestedBlocks) ? f.nestedBlocks : [], g = n.blocks.map((w, R) => R === m ? {
1819
+ ...w,
1820
+ data: {
1821
+ ...f,
1822
+ nestedLayoutMode: "grid",
1823
+ nestedBlocks: [...x, l]
1824
+ }
1825
+ } : w), C = {
1826
+ ...n,
1827
+ version: n.version + 1,
1828
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
1829
+ blocks: g
1830
+ }, y = await t.commitSnapshot(C, {
1831
+ ...e.persistence || {},
1832
+ baseSnapshotVersion: c
1833
+ });
1834
+ return {
1835
+ success: !0,
1836
+ requestId: a,
1837
+ operation: "insertCard",
1838
+ affectedCardIds: [s.block.id],
1839
+ snapshotVersion: y.version,
1840
+ data: {
1841
+ card: s.block,
1842
+ snapshot: y
1843
+ }
1844
+ };
1845
+ }
1846
+ const d = {
1847
+ ...n,
1848
+ version: n.version + 1,
1849
+ layoutVersion: 3,
1850
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
1851
+ blocks: Vt([...n.blocks, s.block])
1852
+ }, r = await t.commitSnapshot(d, {
1853
+ ...e.persistence || {},
1854
+ baseSnapshotVersion: c
1855
+ });
1856
+ return {
1857
+ success: !0,
1858
+ requestId: a,
1859
+ operation: "insertCard",
1860
+ affectedCardIds: [s.block.id],
1861
+ snapshotVersion: r.version,
1862
+ data: {
1863
+ card: s.block,
1864
+ snapshot: r
1865
+ }
1866
+ };
1867
+ },
1868
+ async updateCard(e) {
1869
+ var o;
1870
+ const a = Et(e.requestId), n = t.getSnapshot(), i = At(n, "updateCard", a);
1871
+ if (i || !n) return i;
1872
+ const s = n.version, c = await Gt(n, e);
1873
+ if (c.status !== "success" || !c.snapshot)
1874
+ return Y("updateCard", a, c.error || {
1875
+ code: "UNSUPPORTED_OPERATION",
1876
+ message: "改卡操作失败。",
1877
+ details: c
1878
+ });
1879
+ c.locatedCardId && ((o = t.locateCard) == null || o.call(t, c.locatedCardId));
1880
+ const r = e.operation !== "locateCard" ? await t.commitSnapshot(c.snapshot, {
1881
+ ...e.persistence || {},
1882
+ baseSnapshotVersion: s
1883
+ }) : c.snapshot;
1884
+ return {
1885
+ success: !0,
1886
+ requestId: a,
1887
+ operation: "updateCard",
1888
+ affectedCardIds: c.affectedCardIds,
1889
+ snapshotVersion: r.version,
1890
+ data: {
1891
+ snapshot: r,
1892
+ transactionId: c.transactionId,
1893
+ locatedCardId: c.locatedCardId
1894
+ }
1895
+ };
1896
+ }
1897
+ };
1898
+ }
1899
+ export {
1900
+ Sa as A,
1901
+ Wa as B,
1902
+ va as C,
1903
+ N as D,
1904
+ ya as R,
1905
+ U as W,
1906
+ Ma as a,
1907
+ Ot as b,
1908
+ Ha as c,
1909
+ ga as d,
1910
+ qt as e,
1911
+ Ze as f,
1912
+ Ra as g,
1913
+ Dt as h,
1914
+ $ as i,
1915
+ xa as j,
1916
+ S as k,
1917
+ Na as l,
1918
+ Ta as m,
1919
+ kt as n,
1920
+ La as o,
1921
+ jt as p,
1922
+ Ca as q,
1923
+ ba as r,
1924
+ ut as s,
1925
+ Ia as t,
1926
+ wa as u,
1927
+ Ea as v,
1928
+ Wt as w,
1929
+ Oa as x,
1930
+ Aa as y,
1931
+ ie as z
1932
+ };