@dynamix-layout/core 1.1.1 → 2.0.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.
package/dist/index.js ADDED
@@ -0,0 +1,1338 @@
1
+ /*! @dynamix-layout/core | MIT License */ function tt() {
2
+ return typeof process > "u" || // Read at runtime by consumers' bundlers, not a build input of this repo.
3
+ // eslint-disable-next-line turbo/no-undeclared-env-vars
4
+ process.env.NODE_ENV !== "production";
5
+ }
6
+ const Ut = (t) => {
7
+ tt() && console.warn(`[dynamix-layout] ${t.message}`);
8
+ }, w = (t) => t.type === "row";
9
+ function E(t) {
10
+ const e = [], n = (i) => {
11
+ w(i) ? i.children.forEach(n) : e.push(i);
12
+ };
13
+ return t.children.forEach(n), e;
14
+ }
15
+ function Wt(t) {
16
+ return E(t).flatMap(
17
+ (e) => e.children.map((n) => n.id)
18
+ );
19
+ }
20
+ function xt(t) {
21
+ const e = [], n = (i) => {
22
+ e.push(i.id), w(i) && i.children.forEach(n);
23
+ };
24
+ return n(t), e;
25
+ }
26
+ function T(t, e) {
27
+ return E(t).find((n) => n.id === e);
28
+ }
29
+ function S(t, e) {
30
+ return E(t).find(
31
+ (n) => n.children.some((i) => i.id === e)
32
+ );
33
+ }
34
+ function et(t, e) {
35
+ for (const n of t.children) {
36
+ if (n.id === e) return t;
37
+ if (w(n)) {
38
+ const i = et(n, e);
39
+ if (i) return i;
40
+ }
41
+ }
42
+ }
43
+ const jt = 6;
44
+ function It(t, e, n, i) {
45
+ if (n.type === "root") return ct(e.container, n.position);
46
+ if (n.type === "tabset") {
47
+ const f = e.tabsets.get(n.tabsetId);
48
+ return f ? n.position !== "center" ? ct(f, n.position) : T(t.root, n.tabsetId)?.isFolded ? f : {
49
+ x: f.x + f.width * 0.1,
50
+ y: f.y + f.height * 0.1,
51
+ width: f.width * 0.8,
52
+ height: f.height * 0.8
53
+ } : null;
54
+ }
55
+ const o = S(t.root, n.tabId), r = o && i?.tabBars.get(o.id)?.tabs, a = r?.findIndex((f) => f.id === n.tabId) ?? -1;
56
+ if (!r || a < 0) return null;
57
+ const d = r.length > 1 ? Math.max(
58
+ 2,
59
+ r[1].rect.x - (r[0].rect.x + r[0].rect.width)
60
+ ) : jt, { rect: s } = r[a];
61
+ return {
62
+ x: n.position === "before" ? s.x - d + 1 : s.x + s.width + 1,
63
+ y: s.y,
64
+ width: Math.max(2, d - 2),
65
+ height: s.height
66
+ };
67
+ }
68
+ function ct(t, e) {
69
+ const { x: n, y: i, width: o, height: r } = t;
70
+ switch (e) {
71
+ case "left":
72
+ return { x: n, y: i, width: o / 2, height: r };
73
+ case "right":
74
+ return { x: n + o / 2, y: i, width: o / 2, height: r };
75
+ case "top":
76
+ return { x: n, y: i, width: o, height: r / 2 };
77
+ case "bottom":
78
+ return { x: n, y: i + r / 2, width: o, height: r / 2 };
79
+ }
80
+ }
81
+ const Kt = (t, e) => t.length === e.length && t.every((n, i) => n === e[i]);
82
+ function F(t, e) {
83
+ return Kt(t.children, e) ? t : { ...t, children: e };
84
+ }
85
+ function O(t, e, n) {
86
+ if (t.id === e) {
87
+ const o = n(t);
88
+ if (Array.isArray(o) || !w(o))
89
+ throw new Error("The root can only be replaced by a row.");
90
+ return o;
91
+ }
92
+ const i = (o) => {
93
+ const r = [];
94
+ for (const a of o.children)
95
+ if (a.id === e) {
96
+ const d = n(a);
97
+ Array.isArray(d) ? r.push(...d) : r.push(d);
98
+ } else
99
+ r.push(w(a) ? i(a) : a);
100
+ return F(o, r);
101
+ };
102
+ return i(t);
103
+ }
104
+ const $ = 100, Tt = (t) => Number.isFinite(t) && t >= 0 ? t : $;
105
+ function Gt(t) {
106
+ if (t.children.length === 0) return null;
107
+ const e = Tt(t.weight), n = t.children.some(
108
+ (i) => i.id === t.activeTabId
109
+ );
110
+ return e === t.weight && n ? t : {
111
+ ...t,
112
+ weight: e,
113
+ activeTabId: n ? t.activeTabId : t.children[0].id
114
+ };
115
+ }
116
+ function zt(t) {
117
+ const e = [];
118
+ for (const o of t.children) {
119
+ if (!w(o)) {
120
+ const a = Gt(o);
121
+ a && e.push(a);
122
+ continue;
123
+ }
124
+ let r = zt(o);
125
+ w(r) && r.children.length === 1 && (r = r.children[0]), !(w(r) && r.children.length === 0) && (w(r) && r.direction === t.direction ? e.push(...r.children) : e.push(r));
126
+ }
127
+ const n = Tt(t.weight), i = F(t, e);
128
+ return n === t.weight ? i : { ...i, weight: n };
129
+ }
130
+ function V(t) {
131
+ let e = zt(t);
132
+ for (; e.children.length === 1 && w(e.children[0]); ) {
133
+ const i = e.children[0];
134
+ e = {
135
+ ...e,
136
+ weight: i.weight,
137
+ direction: i.direction,
138
+ children: i.children
139
+ };
140
+ }
141
+ return (e.children.length <= 1 || e.direction === "horizontal") && (e.direction !== "horizontal" || e.weight !== $) && (e = { ...e, direction: "horizontal", weight: $ }), e;
142
+ }
143
+ const Ht = (t) => t === "horizontal" ? "vertical" : "horizontal";
144
+ function P(t, e) {
145
+ return {
146
+ type: "tabset",
147
+ id: e("tabset", t),
148
+ weight: $,
149
+ activeTabId: t,
150
+ isFolded: !1,
151
+ children: [{ type: "tab", id: t }]
152
+ };
153
+ }
154
+ function Jt(t, e, n = "root") {
155
+ const i = (o, r, a) => {
156
+ const d = o.length <= 2 ? o.map((s) => P(s, e)) : [
157
+ P(o[0], e),
158
+ i(o.slice(1), Ht(r), e("row"))
159
+ ];
160
+ return { type: "row", id: a, weight: $, direction: r, children: d };
161
+ };
162
+ return i(t, "horizontal", n);
163
+ }
164
+ const St = (t) => t === "horizontal" ? "vertical" : "horizontal", q = (t) => t === "top" || t === "left", vt = (t, e) => (t === "left" || t === "right") == (e === "horizontal");
165
+ function j(t, e, n, i, o) {
166
+ return O(t, e, (r) => {
167
+ const a = r, d = [...a.children];
168
+ return d.splice(i, 0, ...n), { ...a, children: d, activeTabId: o, isFolded: !1 };
169
+ });
170
+ }
171
+ function At(t, e, n, i, o) {
172
+ const r = et(t, e), a = T(t, e);
173
+ if (!r || !a) return t;
174
+ if (vt(i, r.direction)) {
175
+ const f = r.children.indexOf(a) + (q(i) ? 0 : 1), p = [...r.children];
176
+ return p.splice(f, 0, n), O(
177
+ t,
178
+ r.id,
179
+ () => F(r, p)
180
+ );
181
+ }
182
+ const d = {
183
+ ...a,
184
+ weight: $,
185
+ isFolded: !1
186
+ }, s = {
187
+ type: "row",
188
+ id: o("row"),
189
+ weight: a.weight,
190
+ direction: St(r.direction),
191
+ children: q(i) ? [n, d] : [d, n]
192
+ };
193
+ return O(t, e, () => s);
194
+ }
195
+ function Dt(t, e, n, i) {
196
+ const o = q(n);
197
+ if (t.children.length === 0) return F(t, [e]);
198
+ if (vt(n, t.direction))
199
+ return F(
200
+ t,
201
+ o ? [e, ...t.children] : [...t.children, e]
202
+ );
203
+ const r = t.children.length === 1 ? t.children[0] : {
204
+ type: "row",
205
+ id: i("row"),
206
+ weight: t.weight,
207
+ direction: t.direction,
208
+ children: t.children
209
+ };
210
+ return {
211
+ ...t,
212
+ weight: $,
213
+ direction: St(t.direction),
214
+ children: o ? [e, r] : [r, e]
215
+ };
216
+ }
217
+ function it(t, e) {
218
+ const n = S(t, e);
219
+ if (!n) return t;
220
+ const i = n.children.filter((r) => r.id !== e), o = O(
221
+ t,
222
+ n.id,
223
+ () => i.length === 0 ? [] : {
224
+ ...n,
225
+ children: i,
226
+ activeTabId: n.activeTabId === e ? i[0].id : n.activeTabId
227
+ }
228
+ );
229
+ return V(o);
230
+ }
231
+ function Yt(t, e) {
232
+ return V(O(t, e, () => []));
233
+ }
234
+ const dt = (t, e) => t.foldOrder.indexOf(e) + 1;
235
+ function Ot(t, e, n) {
236
+ let i = null;
237
+ for (const o of e)
238
+ o.id === n || w(o) || !o.isFolded || (!i || dt(t, o.id) > dt(t, i.id)) && (i = o);
239
+ return e.map(
240
+ (o) => o === i ? { ...i, isFolded: !1 } : o
241
+ );
242
+ }
243
+ const Et = (t) => !w(t) && t.isFolded;
244
+ function kt(t) {
245
+ return E(t).length > 1;
246
+ }
247
+ function M(t) {
248
+ const e = (d) => {
249
+ let s = d.children;
250
+ return s.length > 0 && s.every(Et) && (s = Ot(t, s)), s = s.map((f) => w(f) ? e(f) : f.isFolded && s.length < 2 ? { ...f, isFolded: !1 } : f), F(d, s);
251
+ }, n = e(t.root), i = new Set(xt(n)), o = t.maximizedTabsetId && T(n, t.maximizedTabsetId) ? t.maximizedTabsetId : null, r = t.foldOrder.filter((d) => i.has(d)), a = t.lastActiveTabsetId && T(n, t.lastActiveTabsetId) ? t.lastActiveTabsetId : null;
252
+ return n === t.root && o === t.maximizedTabsetId && r.length === t.foldOrder.length && a === t.lastActiveTabsetId ? t : { root: n, maximizedTabsetId: o, foldOrder: r, lastActiveTabsetId: a };
253
+ }
254
+ function qt(t, e) {
255
+ return t.maximizedTabsetId === e || !T(t.root, e) || !kt(t.root) ? null : { ...t, maximizedTabsetId: e };
256
+ }
257
+ function Ft(t) {
258
+ return t.maximizedTabsetId ? { ...t, maximizedTabsetId: null } : null;
259
+ }
260
+ function Zt(t, e) {
261
+ const n = T(t.root, e), i = et(t.root, e);
262
+ if (!n || !i || n.isFolded || i.children.length < 2)
263
+ return null;
264
+ const o = [
265
+ ...t.foldOrder.filter((s) => s !== e),
266
+ e
267
+ ], r = { ...t, foldOrder: o, maximizedTabsetId: null };
268
+ let a = i.children.map(
269
+ (s) => s === n ? { ...n, isFolded: !0 } : s
270
+ );
271
+ a.every(Et) && (a = Ot(r, a, e));
272
+ const d = O(
273
+ t.root,
274
+ i.id,
275
+ () => F(i, a)
276
+ );
277
+ return M({ ...r, root: d });
278
+ }
279
+ function Xt(t, e) {
280
+ const n = T(t.root, e);
281
+ if (!n || !n.isFolded) return null;
282
+ const i = O(t.root, e, () => ({
283
+ ...n,
284
+ isFolded: !1
285
+ }));
286
+ return M({ ...t, root: i });
287
+ }
288
+ function Nt(t, e) {
289
+ return e.type === "tab" ? S(t, e.tabId) : T(t, e.tabsetId);
290
+ }
291
+ function nt(t, e, n) {
292
+ const i = Nt(t, e);
293
+ if (!i || E(t).length === 1 && (e.type === "tabset" || i.children.length === 1)) return !1;
294
+ switch (n.type) {
295
+ case "root":
296
+ return !0;
297
+ case "tab": {
298
+ const a = S(t, n.tabId);
299
+ return a ? e.type === "tab" ? e.tabId !== n.tabId : a !== i : !1;
300
+ }
301
+ case "tabset": {
302
+ const a = T(t, n.tabsetId);
303
+ return a ? e.type === "tabset" ? a !== i : a !== i ? !0 : i.children.length < 2 ? !1 : n.position !== "center" || i.children[i.children.length - 1].id !== e.tabId : !1;
304
+ }
305
+ }
306
+ }
307
+ function Z(t, e, n, i) {
308
+ if (!nt(t.root, e, n)) return null;
309
+ const o = Nt(t.root, e), r = e.type === "tab" ? [{ type: "tab", id: e.tabId }] : o.children, a = e.type === "tab" ? e.tabId : r[r.length - 1].id, d = () => e.type === "tab" ? P(e.tabId, i) : { ...o, isFolded: !1 };
310
+ let s = e.type === "tab" ? it(t.root, e.tabId) : Yt(t.root, o.id);
311
+ switch (n.type) {
312
+ case "tab": {
313
+ const f = S(s, n.tabId), p = f.children.findIndex((c) => c.id === n.tabId) + (n.position === "after" ? 1 : 0);
314
+ s = j(s, f.id, r, p, a);
315
+ break;
316
+ }
317
+ case "tabset": {
318
+ if (n.position === "center") {
319
+ const f = T(s, n.tabsetId);
320
+ s = j(
321
+ s,
322
+ f.id,
323
+ r,
324
+ f.children.length,
325
+ a
326
+ );
327
+ } else
328
+ s = At(
329
+ s,
330
+ n.tabsetId,
331
+ d(),
332
+ n.position,
333
+ i
334
+ );
335
+ break;
336
+ }
337
+ case "root":
338
+ s = Dt(s, d(), n.position, i);
339
+ break;
340
+ }
341
+ return s = V(s), M({
342
+ ...t,
343
+ root: s,
344
+ maximizedTabsetId: null,
345
+ lastActiveTabsetId: S(s, a)?.id ?? null
346
+ });
347
+ }
348
+ const Qt = ["left", "right", "top", "bottom"], H = (t, e) => e.x >= t.x && e.x <= t.x + t.width && e.y >= t.y && e.y <= t.y + t.height;
349
+ function te(t, e, n = {}) {
350
+ const { length: i = 0.25, thickness: o = 8 } = n, { x: r, y: a, width: d, height: s } = t;
351
+ switch (e) {
352
+ case "left":
353
+ return {
354
+ x: r,
355
+ y: a + s * (1 - i) / 2,
356
+ width: o,
357
+ height: s * i
358
+ };
359
+ case "right":
360
+ return {
361
+ x: r + d - o,
362
+ y: a + s * (1 - i) / 2,
363
+ width: o,
364
+ height: s * i
365
+ };
366
+ case "top":
367
+ return {
368
+ x: r + d * (1 - i) / 2,
369
+ y: a,
370
+ width: d * i,
371
+ height: o
372
+ };
373
+ case "bottom":
374
+ return {
375
+ x: r + d * (1 - i) / 2,
376
+ y: a + s - o,
377
+ width: d * i,
378
+ height: o
379
+ };
380
+ }
381
+ }
382
+ function ee(t, e) {
383
+ const n = e.x - t.x, i = e.y - t.y;
384
+ return n < t.width / 3 ? "left" : n > 2 * t.width / 3 ? "right" : i < t.height / 3 ? "top" : i > 2 * t.height / 3 ? "bottom" : "center";
385
+ }
386
+ function ie(t, e) {
387
+ if (t.length === 0) return null;
388
+ const n = t[t.length - 1];
389
+ if (e.x > n.rect.x + n.rect.width)
390
+ return { type: "tab", tabId: n.id, position: "after" };
391
+ if (e.x < t[0].rect.x)
392
+ return { type: "tab", tabId: t[0].id, position: "before" };
393
+ let i = t[0], o = 1 / 0;
394
+ for (const a of t) {
395
+ const d = a.rect.x + a.rect.width / 2;
396
+ Math.abs(e.x - d) < o && (o = Math.abs(e.x - d), i = a);
397
+ }
398
+ const r = i.rect.x + i.rect.width / 2;
399
+ return {
400
+ type: "tab",
401
+ tabId: i.id,
402
+ position: e.x < r ? "before" : "after"
403
+ };
404
+ }
405
+ function $t(t, e, n, i, o, r) {
406
+ const a = (s) => s && nt(t.root, i, s) ? s : null;
407
+ for (const s of Qt)
408
+ if (H(te(e.container, s, r), n))
409
+ return a({ type: "root", position: s });
410
+ const d = E(t.root);
411
+ for (const s of d) {
412
+ const f = o?.tabBars.get(s.id);
413
+ if (!(!f || !H(f.rect, n)))
414
+ return f.isRotated || s.isFolded ? a({
415
+ type: "tabset",
416
+ tabsetId: s.id,
417
+ position: "center"
418
+ }) : a(ie(f.tabs, n));
419
+ }
420
+ for (const s of d) {
421
+ if (t.maximizedTabsetId && t.maximizedTabsetId !== s.id)
422
+ continue;
423
+ const f = e.tabsets.get(s.id);
424
+ if (!f || !H(f, n)) continue;
425
+ const p = s.isFolded ? "center" : ee(f, n);
426
+ return a({ type: "tabset", tabsetId: s.id, position: p });
427
+ }
428
+ return null;
429
+ }
430
+ function rt(t, e) {
431
+ const n = /* @__PURE__ */ new Map(), { width: i, height: o } = e.minPanelSize, r = (a, d) => {
432
+ let s;
433
+ if (w(a)) {
434
+ let f = 0, p = 0, c = 0, l = 0;
435
+ for (const u of a.children) {
436
+ const h = r(u, a.direction);
437
+ c += h.horizontalCount, l += h.verticalCount, a.direction === "horizontal" ? (f += h.width, p = Math.max(p, h.height)) : (p += h.height, f = Math.max(f, h.width));
438
+ }
439
+ const b = (a.children.length - 1) * e.splitterSize;
440
+ a.direction === "horizontal" ? f += b : p += b, s = { width: f, height: p, horizontalCount: c, verticalCount: l };
441
+ } else {
442
+ const f = d === "horizontal";
443
+ s = a.isFolded ? f ? {
444
+ width: e.foldedSize,
445
+ height: o,
446
+ horizontalCount: 0,
447
+ verticalCount: 0
448
+ } : {
449
+ width: i,
450
+ height: e.foldedSize,
451
+ horizontalCount: 0,
452
+ verticalCount: 0
453
+ } : {
454
+ width: i,
455
+ height: o,
456
+ horizontalCount: f ? 1 : 0,
457
+ verticalCount: f ? 0 : 1
458
+ };
459
+ }
460
+ return n.set(a.id, s), s;
461
+ };
462
+ return r(t, t.direction), n;
463
+ }
464
+ function ne(t, e) {
465
+ const n = (i, o) => i * o + Math.max(0, i - 1) * e.splitterSize;
466
+ return {
467
+ width: Math.max(
468
+ t.width,
469
+ n(t.horizontalCount, e.minPanelSize.width)
470
+ ),
471
+ height: Math.max(
472
+ t.height,
473
+ n(t.verticalCount, e.minPanelSize.height)
474
+ )
475
+ };
476
+ }
477
+ const ot = (t, e) => `${t}~${e}`, J = (t, e) => {
478
+ if (t.size !== e.size) return !1;
479
+ const n = e.entries();
480
+ for (const [i, o] of t) {
481
+ const [r, a] = n.next().value;
482
+ if (i !== r || o !== a) return !1;
483
+ }
484
+ return !0;
485
+ }, lt = (t, e) => !!t && t.x === e.x && t.y === e.y && t.width === e.width && t.height === e.height;
486
+ function ft(t, e, n, i, o) {
487
+ const r = rt(t, n), a = ne(r.get(t.id), n), d = {
488
+ x: e.x,
489
+ y: e.y,
490
+ width: Math.max(e.width, a.width),
491
+ height: Math.max(e.height, a.height)
492
+ }, s = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map(), c = (u, h, g, m) => u.set(g, lt(h?.get(g), m) ? h.get(g) : m), l = (u, h) => {
493
+ c(s, o?.rows, u.id, h);
494
+ const g = u.direction === "horizontal", m = r.get(u.id), y = g ? h.width - m.width : h.height - m.height, x = y < 0;
495
+ let v = 0, A, C = 0;
496
+ for (const I of u.children)
497
+ !w(I) && I.isFolded || (v += I.weight, A = I.id, C++);
498
+ const N = v === 0, R = (I) => N ? 1 : I;
499
+ N && (v = C);
500
+ let _ = 0, B = 0, U = 0;
501
+ u.children.forEach((I, Vt) => {
502
+ const st = r.get(I.id), Bt = w(I) || !I.isFolded;
503
+ let G = 0;
504
+ if (!x && Bt && v > 0) {
505
+ B += R(I.weight);
506
+ const W = I.id === A ? y : Math.round(
507
+ y * B / v
508
+ );
509
+ G = W - U, U = W;
510
+ }
511
+ const z = g ? {
512
+ x: h.x + _,
513
+ y: h.y,
514
+ width: st.width + G,
515
+ height: h.height
516
+ } : {
517
+ x: h.x,
518
+ y: h.y + _,
519
+ width: h.width,
520
+ height: st.height + G
521
+ };
522
+ _ += (g ? z.width : z.height) + n.splitterSize, w(I) ? l(I, z) : c(f, o?.tabsets, I.id, z);
523
+ const at = u.children[Vt + 1];
524
+ if (at) {
525
+ const W = g ? {
526
+ x: z.x + z.width,
527
+ y: z.y,
528
+ width: n.splitterSize,
529
+ height: z.height
530
+ } : {
531
+ x: z.x,
532
+ y: z.y + z.height,
533
+ width: z.width,
534
+ height: n.splitterSize
535
+ };
536
+ c(
537
+ p,
538
+ o?.splitters,
539
+ ot(I.id, at.id),
540
+ W
541
+ );
542
+ }
543
+ });
544
+ };
545
+ l(t, d), i && f.has(i) && c(f, o?.tabsets, i, d);
546
+ const b = lt(o?.container, d) ? o.container : d;
547
+ return o && b === o.container && J(s, o.rows) && J(f, o.tabsets) && J(p, o.splitters) ? o : { container: b, rows: s, tabsets: f, splitters: p };
548
+ }
549
+ function Mt(t, e) {
550
+ const n = (i) => {
551
+ for (let o = 0; o < i.children.length; o++) {
552
+ const r = i.children[o], a = i.children[o + 1];
553
+ if (a && ot(r.id, a.id) === e)
554
+ return { row: i, before: r, after: a };
555
+ if (w(r)) {
556
+ const d = n(r);
557
+ if (d) return d;
558
+ }
559
+ }
560
+ return null;
561
+ };
562
+ return n(t);
563
+ }
564
+ const ht = (t) => !w(t) && t.isFolded;
565
+ function re(t) {
566
+ return ht(t.before) || ht(t.after);
567
+ }
568
+ const K = (t, e) => (w(e) ? t.rows : t.tabsets).get(e.id);
569
+ function oe(t, e, n, i) {
570
+ const o = Mt(t, i);
571
+ if (!o) return null;
572
+ const r = K(e, o.before), a = K(e, o.after);
573
+ if (!r || !a) return null;
574
+ const d = rt(t, n), s = o.row.direction === "horizontal", f = (c) => s ? c.width : c.height, p = (c) => {
575
+ const l = d.get(c.id);
576
+ return s ? l.width : l.height;
577
+ };
578
+ return {
579
+ value: f(r),
580
+ min: p(o.before),
581
+ max: f(r) + f(a) - p(o.after)
582
+ };
583
+ }
584
+ function Rt(t, e, n, i, o) {
585
+ const r = Mt(t, i);
586
+ if (!r || re(r)) return null;
587
+ const a = K(e, r.before), d = K(e, r.after);
588
+ if (!a || !d) return null;
589
+ const s = rt(t, n), f = r.row.direction === "horizontal", p = f ? a.x : a.y, c = f ? d.x + d.width : d.y + d.height, l = s.get(r.before.id), b = s.get(r.after.id), u = f ? l.width : l.height, h = f ? b.width : b.height, g = n.splitterSize / 2, m = f ? o.x : o.y, y = Math.max(
590
+ p + u + g,
591
+ Math.min(c - h - g, m)
592
+ ), x = y - g - p, v = c - (y + g), A = Math.max(0, x - u), C = Math.max(0, v - h), N = A + C, R = r.before.weight + r.after.weight, _ = N > 0 ? A / N * R : R / 2, B = N > 0 ? C / N * R : R / 2, U = r.row.children.map(
593
+ (I) => I === r.before ? { ...I, weight: _ } : I === r.after ? { ...I, weight: B } : I
594
+ );
595
+ return O(
596
+ t,
597
+ r.row.id,
598
+ () => F(r.row, U)
599
+ );
600
+ }
601
+ const se = (t) => ({
602
+ type: "tabset",
603
+ id: t.id,
604
+ weight: t.weight,
605
+ activeTabId: t.activeTabId,
606
+ ...t.isFolded ? { isFolded: !0 } : {},
607
+ children: t.children.map((e) => ({ type: "tab", id: e.id }))
608
+ }), Lt = (t) => ({
609
+ type: "row",
610
+ id: t.id,
611
+ weight: t.weight,
612
+ direction: t.direction,
613
+ children: t.children.map(
614
+ (e) => w(e) ? Lt(e) : se(e)
615
+ )
616
+ });
617
+ function Ct(t) {
618
+ return {
619
+ version: 2,
620
+ root: Lt(t.root),
621
+ ...t.maximizedTabsetId ? { maximizedTabsetId: t.maximizedTabsetId } : {}
622
+ };
623
+ }
624
+ const ae = (t, e) => {
625
+ for (const n of Object.keys(t)) {
626
+ const i = t[n], o = e[n];
627
+ if (Array.isArray(i) && Array.isArray(o)) {
628
+ if (i.length !== o.length || i.some((r, a) => r !== o[a]))
629
+ return !1;
630
+ } else if (i !== o) return !1;
631
+ }
632
+ return !0;
633
+ }, X = (t) => tt() ? Object.freeze(t) : t;
634
+ function Y(t, e) {
635
+ if (!e)
636
+ return t.forEach((r) => X(r)), t;
637
+ let n = t.size !== e.size;
638
+ const i = [...e.keys()];
639
+ let o = 0;
640
+ for (const [r, a] of t) {
641
+ const d = e.get(r);
642
+ d && ae(d, a) ? t.set(r, d) : (X(a), n = !0), i[o++] !== r && (n = !0);
643
+ }
644
+ return n ? t : e;
645
+ }
646
+ function ut(t, e, n, i) {
647
+ if (i && i.root === t.root && i.maximizedTabsetId === t.maximizedTabsetId && i.rects === e && i.drag === n)
648
+ return i;
649
+ const o = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), d = t.maximizedTabsetId;
650
+ let s = 0;
651
+ const f = (c) => c.children.forEach(
652
+ (l) => w(l) ? f(l) : s++
653
+ );
654
+ f(t.root);
655
+ const p = (c) => {
656
+ c.children.forEach((l, b) => {
657
+ if (w(l)) p(l);
658
+ else {
659
+ const h = l.id === d, g = !!d && !h, m = l.isFolded && !h;
660
+ o.set(l.id, {
661
+ id: l.id,
662
+ tabIds: l.children.map((y) => y.id),
663
+ activeTabId: l.activeTabId,
664
+ parentDirection: c.direction,
665
+ isFolded: m,
666
+ isMaximized: h,
667
+ isHidden: g,
668
+ canFold: c.children.length > 1,
669
+ canMaximize: s > 1
670
+ });
671
+ for (const y of l.children) {
672
+ const x = y.id === l.activeTabId;
673
+ a.set(y.id, {
674
+ id: y.id,
675
+ tabsetId: l.id,
676
+ isActive: x,
677
+ isVisible: x && !m && !g
678
+ });
679
+ }
680
+ }
681
+ const u = c.children[b + 1];
682
+ if (u) {
683
+ const h = ot(l.id, u.id), g = (m) => !w(m) && m.isFolded;
684
+ r.set(h, {
685
+ id: h,
686
+ rowId: c.id,
687
+ direction: c.direction,
688
+ beforeId: l.id,
689
+ afterId: u.id,
690
+ isLocked: g(l) || g(u),
691
+ isHidden: !!d
692
+ });
693
+ }
694
+ });
695
+ };
696
+ return p(t.root), X({
697
+ root: t.root,
698
+ tabsets: Y(o, i?.tabsets),
699
+ splitters: Y(r, i?.splitters),
700
+ tabs: Y(a, i?.tabs),
701
+ rects: e,
702
+ maximizedTabsetId: d,
703
+ drag: n
704
+ });
705
+ }
706
+ function ce(t, e, n, i) {
707
+ const o = /* @__PURE__ */ new Set();
708
+ let r = t, a = e, d = { x: 0, y: 0, width: 0, height: 0 }, s = ft(
709
+ r.root,
710
+ d,
711
+ a,
712
+ r.maximizedTabsetId
713
+ ), f = null, p = ut(r, s, null), c = !1, l = null;
714
+ const b = () => {
715
+ s = ft(
716
+ r.root,
717
+ d,
718
+ a,
719
+ r.maximizedTabsetId,
720
+ s
721
+ );
722
+ const h = le(p.drag, f) ? p.drag : f && de(f), g = ut(r, s, h, p);
723
+ g !== p && (p = g, o.forEach((m) => m(p)));
724
+ }, u = () => (l && l.model.root === r.root && l.model.maximizedTabsetId === r.maximizedTabsetId || (l = { model: r, value: Ct(r) }), l.value);
725
+ return {
726
+ get model() {
727
+ return r;
728
+ },
729
+ get rects() {
730
+ return s;
731
+ },
732
+ get config() {
733
+ return a;
734
+ },
735
+ get snapshot() {
736
+ return p;
737
+ },
738
+ get drag() {
739
+ return f;
740
+ },
741
+ get isDestroyed() {
742
+ return c;
743
+ },
744
+ subscribe(h) {
745
+ return o.add(h), () => o.delete(h);
746
+ },
747
+ setContainer(h) {
748
+ d = h, c || b();
749
+ },
750
+ setConfig(h) {
751
+ a = h, c || b();
752
+ },
753
+ update(h) {
754
+ c || (h.model && (r = h.model), h.drag !== void 0 && (f = h.drag), b());
755
+ },
756
+ commit(h, g) {
757
+ return c ? (i({
758
+ code: "DESTROYED",
759
+ message: "This layout was destroyed; the call was ignored."
760
+ }), !1) : !h || h === r ? !1 : (r = h, b(), g && n?.(u(), g), !0);
761
+ },
762
+ report(h) {
763
+ c || n?.(u(), h);
764
+ },
765
+ toJSON: u,
766
+ destroy() {
767
+ c = !0, f = null, o.clear();
768
+ }
769
+ };
770
+ }
771
+ const de = ({ source: t, target: e, indicator: n }) => ({
772
+ source: t,
773
+ target: e,
774
+ indicator: n
775
+ });
776
+ function le(t, e) {
777
+ return !t || !e ? t === e : t.source === e.source && t.target === e.target && t.indicator === e.indicator;
778
+ }
779
+ function fe(t, e) {
780
+ return t === e ? !0 : !t || !e || t.type !== e.type || t.position !== e.position ? !1 : t.type === "tab" ? t.tabId === e.tabId : t.type === "tabset" ? t.tabsetId === e.tabsetId : !0;
781
+ }
782
+ function he(t, e) {
783
+ const n = {
784
+ startDrag(i) {
785
+ if (t.isDestroyed) return !1;
786
+ const { snapshot: o, model: r } = t;
787
+ if (i.type === "splitter") {
788
+ const a = o.splitters.get(i.splitterId);
789
+ if (!a || a.isLocked || r.maximizedTabsetId)
790
+ return !1;
791
+ } else {
792
+ if (!(i.type === "tab" ? o.tabs.has(i.tabId) : o.tabsets.has(i.tabsetId))) return !1;
793
+ t.commit(Ft(r), "maximize");
794
+ }
795
+ return t.update({
796
+ drag: {
797
+ source: i,
798
+ target: null,
799
+ indicator: null,
800
+ startRoot: t.model.root
801
+ }
802
+ }), !0;
803
+ },
804
+ updateDrag(i, o) {
805
+ const { drag: r, model: a, rects: d, config: s } = t;
806
+ if (r) {
807
+ if (r.source.type === "splitter") {
808
+ const f = Rt(
809
+ a.root,
810
+ d,
811
+ s,
812
+ r.source.splitterId,
813
+ i
814
+ );
815
+ f && t.update({ model: { ...a, root: f } });
816
+ return;
817
+ }
818
+ n.setDragTarget(
819
+ $t(a, d, i, r.source, o),
820
+ o
821
+ );
822
+ }
823
+ },
824
+ setDragTarget(i, o) {
825
+ const { drag: r, model: a, rects: d } = t;
826
+ if (!r || r.source.type === "splitter" || fe(r.target, i))
827
+ return;
828
+ const s = i && It(a, d, i, o);
829
+ t.update({ drag: { ...r, target: i, indicator: s } });
830
+ },
831
+ endDrag() {
832
+ const { drag: i, model: o } = t;
833
+ if (!i) return !1;
834
+ if (t.update({ drag: null }), i.source.type === "splitter")
835
+ return o.root === i.startRoot ? !1 : (t.report("resize"), !0);
836
+ const r = i.target && Z(o, i.source, i.target, e);
837
+ return t.commit(r, "move");
838
+ },
839
+ cancelDrag() {
840
+ const { drag: i, model: o } = t;
841
+ if (!i) return;
842
+ const r = i.source.type === "splitter" && o.root !== i.startRoot;
843
+ t.update({
844
+ drag: null,
845
+ ...r ? { model: { ...o, root: i.startRoot } } : {}
846
+ });
847
+ }
848
+ };
849
+ return n;
850
+ }
851
+ const ue = [
852
+ "center",
853
+ "left",
854
+ "right",
855
+ "top",
856
+ "bottom"
857
+ ], be = ["left", "right", "top", "bottom"];
858
+ function ge(t, e) {
859
+ const n = [];
860
+ for (const i of E(t.root))
861
+ for (const o of ue)
862
+ n.push({ type: "tabset", tabsetId: i.id, position: o });
863
+ for (const i of be) n.push({ type: "root", position: i });
864
+ return n.filter((i) => nt(t.root, e, i));
865
+ }
866
+ class L extends Error {
867
+ code;
868
+ /** Where in the input the problem is, e.g. `root.children[1].weight`. */
869
+ path;
870
+ constructor(e, n, i) {
871
+ super(i ? `${n} (at ${i})` : n), this.name = "DynamixLayoutError", this.code = e, this.path = i;
872
+ }
873
+ }
874
+ const pe = {
875
+ minPanelSize: { width: 40, height: 40 },
876
+ splitterSize: 10,
877
+ foldedSize: 40
878
+ }, bt = { row: "row", tabset: "ts" };
879
+ function me(t) {
880
+ const e = /* @__PURE__ */ new Set();
881
+ let n = 0;
882
+ return {
883
+ createId: (o, r) => {
884
+ if (t) {
885
+ const d = t(o, r);
886
+ return e.add(d), d;
887
+ }
888
+ let a = r === void 0 ? "" : `${bt[o]}-${r}`;
889
+ for (; a === "" || e.has(a); ) a = `${bt[o]}-${++n}`;
890
+ return e.add(a), a;
891
+ },
892
+ reserve(o) {
893
+ for (const r of o) e.add(r);
894
+ },
895
+ reset() {
896
+ e.clear(), n = 0;
897
+ }
898
+ };
899
+ }
900
+ const k = (t) => typeof t == "object" && t !== null && !Array.isArray(t), D = (t, e) => {
901
+ throw new L("INVALID_LAYOUT", t, e);
902
+ }, ye = ["horizontal", "vertical"];
903
+ function Q(t, e) {
904
+ const n = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set(), o = (c, l) => {
905
+ (typeof c.id != "string" || c.id === "") && D("Expected a non-empty string id", `${l}.id`);
906
+ const b = c.id;
907
+ return n.has(b) && D(`Duplicate node id "${b}"`, `${l}.id`), n.add(b), b;
908
+ }, r = (c, l) => {
909
+ const b = c.weight;
910
+ return typeof b == "number" && Number.isFinite(b) && b >= 0 ? b : (e({
911
+ code: "INVALID_WEIGHT",
912
+ message: "Invalid weight replaced by 100",
913
+ path: `${l}.weight`
914
+ }), 100);
915
+ }, a = (c, l) => {
916
+ const b = o(c, l);
917
+ Array.isArray(c.children) || D("Expected a children array", `${l}.children`);
918
+ const u = c.children.flatMap((g, m) => {
919
+ const y = `${l}.children[${m}]`;
920
+ (!k(g) || g.type !== "tab" || typeof g.id != "string" || g.id === "") && D('Expected { type: "tab", id: string }', y);
921
+ const x = g.id;
922
+ return i.has(x) ? (e({
923
+ code: "DUPLICATE_TAB_ID",
924
+ message: `Duplicate tab "${x}" dropped`,
925
+ path: y
926
+ }), []) : (i.add(x), [{ type: "tab", id: x }]);
927
+ }), h = c.activeTabId;
928
+ return h !== void 0 && !u.some((g) => g.id === h) && e({
929
+ code: "INVALID_ACTIVE_TAB",
930
+ message: `Active tab "${String(h)}" is not in the tabset`,
931
+ path: `${l}.activeTabId`
932
+ }), {
933
+ type: "tabset",
934
+ id: b,
935
+ weight: r(c, l),
936
+ activeTabId: typeof h == "string" ? h : u[0]?.id ?? "",
937
+ isFolded: c.isFolded === !0,
938
+ children: u
939
+ };
940
+ }, d = (c, l) => {
941
+ const b = o(c, l);
942
+ ye.includes(c.direction) || D(
943
+ 'Expected direction "horizontal" or "vertical"',
944
+ `${l}.direction`
945
+ ), Array.isArray(c.children) || D("Expected a children array", `${l}.children`);
946
+ const u = c.children.map(
947
+ (h, g) => {
948
+ const m = `${l}.children[${g}]`;
949
+ return k(h) ? h.type === "row" ? d(h, m) : h.type === "tabset" ? a(h, m) : D(
950
+ 'Expected type "row" or "tabset"',
951
+ `${m}.type`
952
+ ) : D("Expected a row or tabset", m);
953
+ }
954
+ );
955
+ return {
956
+ type: "row",
957
+ id: b,
958
+ weight: r(c, l),
959
+ direction: c.direction,
960
+ children: u
961
+ };
962
+ };
963
+ (!k(t.root) || t.root.type !== "row") && D("Expected a root row", "root");
964
+ const s = V(d(t.root, "root")), f = typeof t.maximizedTabsetId == "string" ? t.maximizedTabsetId : null, p = M({
965
+ root: s,
966
+ maximizedTabsetId: f,
967
+ lastActiveTabsetId: null,
968
+ foldOrder: []
969
+ });
970
+ return { root: p.root, maximizedTabsetId: p.maximizedTabsetId };
971
+ }
972
+ function _t(t) {
973
+ return typeof t == "object" && t !== null && !("version" in t) && typeof t.typNode == "string";
974
+ }
975
+ const we = (t) => typeof t == "number" && Number.isFinite(t) && t >= 0;
976
+ function xe(t, e = {}) {
977
+ const n = e.onWarning ?? (() => {
978
+ }), i = (u, h) => we(u.nodPart) ? u.nodPart : (n({
979
+ code: "INVALID_WEIGHT",
980
+ message: "Invalid weight replaced by 100",
981
+ path: `${h}.nodPart`
982
+ }), 100);
983
+ if (!_t(t))
984
+ throw new L("INVALID_LAYOUT", "Not a v1 layout", "");
985
+ const o = /* @__PURE__ */ new Set(), r = (u) => {
986
+ typeof u.uidNode == "string" && o.add(u.uidNode), u.nodKids?.forEach(r);
987
+ };
988
+ r(t);
989
+ const a = (u) => {
990
+ let h = u;
991
+ for (let g = 1; o.has(h); g++) h = `${u}-${g}`;
992
+ return o.add(h), h;
993
+ }, d = (u, h) => typeof u.uidNode == "string" && u.uidNode !== "" ? u.uidNode : a(h), s = /* @__PURE__ */ new Set(), f = (u, h) => u.flatMap((g, m) => {
994
+ if (g?.typNode !== "tab") return [];
995
+ const y = g.nodName;
996
+ return typeof y != "string" || y === "" || s.has(y) ? (n({
997
+ code: "DUPLICATE_TAB_ID",
998
+ message: `Duplicate or unnamed tab "${String(y)}" dropped`,
999
+ path: `${h}.nodKids[${m}]`
1000
+ }), []) : (s.add(y), [{ type: "tab", id: y }]);
1001
+ }), p = (u, h) => {
1002
+ const g = f(u.nodKids ?? [], h), m = typeof u.nodOpen == "string" ? u.nodOpen : "", y = g.some((x) => x.id === m);
1003
+ return m && !y && g.length > 0 && n({
1004
+ code: "INVALID_ACTIVE_TAB",
1005
+ message: `Active tab "${m}" is not in the tabset`,
1006
+ path: `${h}.nodOpen`
1007
+ }), {
1008
+ type: "tabset",
1009
+ id: d(u, "ts"),
1010
+ weight: i(u, h),
1011
+ ...g.length > 0 ? { activeTabId: y ? m : g[0].id } : {},
1012
+ ...u.nodFold === !0 ? { isFolded: !0 } : {},
1013
+ children: g
1014
+ };
1015
+ }, c = (u, h, g) => {
1016
+ const m = h % 2 === 0 ? "horizontal" : "vertical", y = [];
1017
+ return (u.nodKids ?? []).forEach((x, v) => {
1018
+ const A = `${g}.nodKids[${v}]`;
1019
+ x?.typNode === "row" ? y.push(c(x, h + 1, A)) : x?.typNode === "tabset" ? y.push(p(x, A)) : x?.typNode === "tab" && y.push({
1020
+ ...p(
1021
+ {
1022
+ ...x,
1023
+ uidNode: a(`ts-${x.nodName}`),
1024
+ nodKids: [x],
1025
+ nodOpen: x.nodName
1026
+ },
1027
+ A
1028
+ )
1029
+ });
1030
+ }), {
1031
+ type: "row",
1032
+ id: d(u, "row"),
1033
+ weight: i(u, g),
1034
+ direction: m,
1035
+ children: y
1036
+ };
1037
+ }, b = {
1038
+ root: t.typNode === "row" ? c(t, 0, "root") : t.typNode === "tabset" ? {
1039
+ type: "row",
1040
+ id: a("root"),
1041
+ weight: 100,
1042
+ direction: "horizontal",
1043
+ children: [p(t, "root")]
1044
+ } : (() => {
1045
+ throw new L(
1046
+ "INVALID_LAYOUT",
1047
+ `A v1 layout root must be a row, not "${t.typNode}"`,
1048
+ "root"
1049
+ );
1050
+ })(),
1051
+ ...typeof t.nodMaxd == "string" ? { maximizedTabsetId: t.nodMaxd } : {}
1052
+ };
1053
+ return Ct(Q(b, n));
1054
+ }
1055
+ const gt = 2, Ie = (t) => typeof t == "object" && t !== null && !Array.isArray(t);
1056
+ function Te(t, e) {
1057
+ if (_t(t))
1058
+ return e({
1059
+ code: "MIGRATED_FROM_V1",
1060
+ message: "Loaded a v1 layout; save it again to store the v2 format."
1061
+ }), Q(
1062
+ xe(t, { onWarning: e }),
1063
+ e
1064
+ );
1065
+ if (!Ie(t))
1066
+ throw new L(
1067
+ "INVALID_LAYOUT",
1068
+ "Expected a layout object"
1069
+ );
1070
+ if (t.version !== gt)
1071
+ throw new L(
1072
+ "UNSUPPORTED_VERSION",
1073
+ `Unsupported layout version ${String(t.version)}; expected ${gt}`,
1074
+ "version"
1075
+ );
1076
+ return Q(t, e);
1077
+ }
1078
+ function ze(t, e) {
1079
+ return t.lastActiveTabsetId && T(e, t.lastActiveTabsetId) ? t.lastActiveTabsetId : E(e)[0]?.id;
1080
+ }
1081
+ function Pt(t, e, n, i = !0) {
1082
+ if (S(t.root, e.id)) return t;
1083
+ const o = { type: "tab", id: e.id }, r = e.target;
1084
+ let a = t.root;
1085
+ const d = (s) => {
1086
+ const f = T(a, s), p = i ? e.id : f.activeTabId;
1087
+ return j(
1088
+ a,
1089
+ s,
1090
+ [o],
1091
+ f.children.length,
1092
+ p
1093
+ );
1094
+ };
1095
+ if (r?.type === "tab" && S(a, r.tabId)) {
1096
+ const s = S(a, r.tabId), f = s.children.findIndex((p) => p.id === r.tabId) + (r.position === "after" ? 1 : 0);
1097
+ a = j(
1098
+ a,
1099
+ s.id,
1100
+ [o],
1101
+ f,
1102
+ i ? e.id : s.activeTabId
1103
+ );
1104
+ } else r?.type === "tabset" && T(a, r.tabsetId) ? a = r.position === "center" ? d(r.tabsetId) : At(
1105
+ a,
1106
+ r.tabsetId,
1107
+ P(e.id, n),
1108
+ r.position,
1109
+ n
1110
+ ) : r?.type === "root" || E(a).length === 0 ? a = Dt(
1111
+ a,
1112
+ P(e.id, n),
1113
+ r?.type === "root" ? r.position : "right",
1114
+ n
1115
+ ) : a = d(ze(t, a));
1116
+ return a = V(a), M({
1117
+ ...t,
1118
+ root: a,
1119
+ lastActiveTabsetId: i ? S(a, e.id)?.id ?? null : t.lastActiveTabsetId
1120
+ });
1121
+ }
1122
+ function pt(t, e, n, i = !0) {
1123
+ const o = new Set(e.map((d) => d.id));
1124
+ let r = t.root;
1125
+ for (const d of Wt(r))
1126
+ o.has(d) || (r = it(r, d));
1127
+ let a = r === t.root ? t : M({ ...t, root: r });
1128
+ for (const d of e) a = Pt(a, d, n, i);
1129
+ return a;
1130
+ }
1131
+ const mt = "root";
1132
+ function Se(t) {
1133
+ const e = t.onWarning ?? Ut, n = me(t.createId), { createId: i, reserve: o } = n;
1134
+ let r = wt(t.tabs, e);
1135
+ const a = (c) => {
1136
+ const l = Te(c, e);
1137
+ o(xt(l.root));
1138
+ const b = { ...l, lastActiveTabsetId: null, foldOrder: [] };
1139
+ return pt(b, r, i, !1);
1140
+ }, d = () => {
1141
+ if (t.initialLayout) return a(t.initialLayout);
1142
+ o([mt]);
1143
+ const c = r.map((l) => l.id);
1144
+ return {
1145
+ root: Jt(c, i, mt),
1146
+ maximizedTabsetId: null,
1147
+ lastActiveTabsetId: null,
1148
+ foldOrder: []
1149
+ };
1150
+ }, s = ce(
1151
+ d(),
1152
+ yt(t, pe),
1153
+ t.onLayoutChange,
1154
+ e
1155
+ ), f = (c, l) => (e({ code: "UNKNOWN_ID", message: `Unknown ${c} "${l}"` }), !1), p = {
1156
+ getSnapshot: () => s.snapshot,
1157
+ subscribe: (c) => s.subscribe(c),
1158
+ setContainerRect: (c) => s.setContainer(c),
1159
+ setOptions: (c) => s.setConfig(yt(c, s.config)),
1160
+ setTabs(c) {
1161
+ r = wt(c, e), s.commit(
1162
+ pt(s.model, r, i, !0),
1163
+ "tabs"
1164
+ );
1165
+ },
1166
+ moveTab: (c, l) => s.commit(
1167
+ Z(s.model, { type: "tab", tabId: c }, l, i),
1168
+ "move"
1169
+ ),
1170
+ moveTabset: (c, l) => s.commit(
1171
+ Z(
1172
+ s.model,
1173
+ { type: "tabset", tabsetId: c },
1174
+ l,
1175
+ i
1176
+ ),
1177
+ "move"
1178
+ ),
1179
+ selectTab(c) {
1180
+ const { model: l } = s, b = S(l.root, c);
1181
+ if (!b) return f("tab", c);
1182
+ if (b.activeTabId === c && l.lastActiveTabsetId === b.id)
1183
+ return !1;
1184
+ const u = O(l.root, b.id, () => ({
1185
+ ...b,
1186
+ activeTabId: c
1187
+ }));
1188
+ return s.commit(
1189
+ { ...l, root: u, lastActiveTabsetId: b.id },
1190
+ "select"
1191
+ );
1192
+ },
1193
+ addTab(c, l) {
1194
+ if (r.some((u) => u.id === c.id)) return !1;
1195
+ const b = l ? { ...c, target: l } : c;
1196
+ return r = [...r, b], s.commit(
1197
+ Pt(s.model, b, i, !0),
1198
+ "tabs"
1199
+ );
1200
+ },
1201
+ removeTab(c) {
1202
+ if (!r.some((u) => u.id === c)) return f("tab", c);
1203
+ r = r.filter((u) => u.id !== c);
1204
+ const { model: l } = s, b = it(l.root, c);
1205
+ return s.commit(
1206
+ M({ ...l, root: b }),
1207
+ "tabs"
1208
+ );
1209
+ },
1210
+ resizeSplitter(c, l) {
1211
+ const { model: b, rects: u, config: h } = s;
1212
+ if (b.maximizedTabsetId) return !1;
1213
+ const g = Rt(
1214
+ b.root,
1215
+ u,
1216
+ h,
1217
+ c,
1218
+ l
1219
+ );
1220
+ return s.commit(g && { ...b, root: g }, "resize");
1221
+ },
1222
+ moveSplitterBy(c, l) {
1223
+ const b = s.rects.splitters.get(c), u = s.snapshot.splitters.get(c);
1224
+ if (!b || !u) return f("splitter", c);
1225
+ const h = b.x + b.width / 2, g = b.y + b.height / 2, m = u.direction === "horizontal" ? { x: h + l, y: g } : { x: h, y: g + l };
1226
+ return p.resizeSplitter(c, m);
1227
+ },
1228
+ maximize: (c) => s.commit(qt(s.model, c), "maximize"),
1229
+ restore: () => s.commit(Ft(s.model), "maximize"),
1230
+ toggleMaximize: (c) => s.model.maximizedTabsetId === c ? p.restore() : p.maximize(c),
1231
+ fold: (c) => s.commit(Zt(s.model, c), "fold"),
1232
+ unfold: (c) => s.commit(Xt(s.model, c), "fold"),
1233
+ toggleFold(c) {
1234
+ const l = s.snapshot.tabsets.get(c);
1235
+ return l ? l.isFolded ? p.unfold(c) : p.fold(c) : f("tabset", c);
1236
+ },
1237
+ ...he(s, i),
1238
+ getDropTarget: (c, l, b) => l.type === "splitter" ? null : $t(
1239
+ s.model,
1240
+ s.rects,
1241
+ c,
1242
+ l,
1243
+ b
1244
+ ),
1245
+ getDropIndicatorRect: (c, l) => It(
1246
+ s.model,
1247
+ s.rects,
1248
+ c,
1249
+ l
1250
+ ),
1251
+ listDropTargets: (c) => c.type === "splitter" ? [] : ge(s.model, c),
1252
+ getSplitterBounds: (c) => oe(s.model.root, s.rects, s.config, c),
1253
+ load: (c) => {
1254
+ s.commit(a(c));
1255
+ },
1256
+ reset() {
1257
+ n.reset(), s.commit(d(), "reset");
1258
+ },
1259
+ toJSON: () => s.toJSON(),
1260
+ destroy: () => s.destroy()
1261
+ };
1262
+ return p;
1263
+ }
1264
+ function yt(t, e) {
1265
+ return {
1266
+ minPanelSize: t.minPanelSize ?? e.minPanelSize,
1267
+ splitterSize: t.splitterSize ?? e.splitterSize,
1268
+ foldedSize: t.foldedSize ?? t.minPanelSize?.height ?? e.foldedSize
1269
+ };
1270
+ }
1271
+ function wt(t, e) {
1272
+ const n = /* @__PURE__ */ new Set();
1273
+ return t.filter((i) => {
1274
+ if (!n.has(i.id))
1275
+ return n.add(i.id), !0;
1276
+ if (tt())
1277
+ throw new L(
1278
+ "DUPLICATE_TAB_ID",
1279
+ `Duplicate tab id "${i.id}"`
1280
+ );
1281
+ return e({
1282
+ code: "DUPLICATE_TAB_ID",
1283
+ message: `Duplicate tab id "${i.id}" ignored`
1284
+ }), !1;
1285
+ });
1286
+ }
1287
+ function ve(t, e, n) {
1288
+ const { x: i, y: o, width: r, height: a } = t;
1289
+ return e.isFolded && e.parentDirection === "horizontal" ? {
1290
+ rect: { x: i + r, y: o, width: a, height: r },
1291
+ isRotated: !0
1292
+ } : { rect: { x: i, y: o, width: r, height: n }, isRotated: !1 };
1293
+ }
1294
+ function Ae(t, e) {
1295
+ return {
1296
+ x: t.x,
1297
+ y: t.y + e,
1298
+ width: t.width,
1299
+ height: Math.max(0, t.height - e)
1300
+ };
1301
+ }
1302
+ function De(t, e) {
1303
+ const { style: n } = t;
1304
+ n.left = `${e.x}px`, n.top = `${e.y}px`, n.width = `${e.width}px`, n.height = `${e.height}px`;
1305
+ }
1306
+ function Oe(t) {
1307
+ let e = null, n = null;
1308
+ const i = () => {
1309
+ n = null;
1310
+ const o = e;
1311
+ e = null, o && t(o.value);
1312
+ };
1313
+ return {
1314
+ schedule(o) {
1315
+ e = { value: o }, n === null && (n = requestAnimationFrame(i));
1316
+ },
1317
+ flush() {
1318
+ n !== null && (cancelAnimationFrame(n), i());
1319
+ },
1320
+ cancel() {
1321
+ n !== null && cancelAnimationFrame(n), n = null, e = null;
1322
+ }
1323
+ };
1324
+ }
1325
+ const Ee = "2.0.0";
1326
+ export {
1327
+ L as DynamixLayoutError,
1328
+ gt as LAYOUT_VERSION,
1329
+ De as applyRect,
1330
+ Oe as createFrameScheduler,
1331
+ Se as createLayout,
1332
+ te as getRootDropZoneRect,
1333
+ ve as getTabBarPlacement,
1334
+ Ae as getTabContentRect,
1335
+ _t as isLayoutV1,
1336
+ xe as migrateLayoutFromV1,
1337
+ Ee as version
1338
+ };