@zag-js/splitter 1.39.1 → 1.41.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.
Files changed (37) hide show
  1. package/dist/index.d.mts +1 -1
  2. package/dist/index.d.ts +1 -1
  3. package/dist/splitter.connect.js +61 -29
  4. package/dist/splitter.connect.mjs +61 -29
  5. package/dist/splitter.dom.d.mts +4 -3
  6. package/dist/splitter.dom.d.ts +4 -3
  7. package/dist/splitter.dom.js +31 -2
  8. package/dist/splitter.dom.mjs +31 -3
  9. package/dist/splitter.machine.js +168 -59
  10. package/dist/splitter.machine.mjs +169 -61
  11. package/dist/splitter.types.d.mts +27 -8
  12. package/dist/splitter.types.d.ts +27 -8
  13. package/dist/utils/aria.d.mts +9 -3
  14. package/dist/utils/aria.d.ts +9 -3
  15. package/dist/utils/aria.js +9 -0
  16. package/dist/utils/aria.mjs +9 -0
  17. package/dist/utils/panel.d.mts +13 -12
  18. package/dist/utils/panel.d.ts +13 -12
  19. package/dist/utils/panel.js +41 -7
  20. package/dist/utils/panel.mjs +41 -7
  21. package/dist/utils/preserve-fixed-panel-sizes.d.mts +18 -0
  22. package/dist/utils/preserve-fixed-panel-sizes.d.ts +18 -0
  23. package/dist/utils/preserve-fixed-panel-sizes.js +91 -0
  24. package/dist/utils/preserve-fixed-panel-sizes.mjs +68 -0
  25. package/dist/utils/registry.js +1 -1
  26. package/dist/utils/registry.mjs +2 -2
  27. package/dist/utils/resize-by-delta.d.mts +2 -2
  28. package/dist/utils/resize-by-delta.d.ts +2 -2
  29. package/dist/utils/resize-panel.d.mts +2 -2
  30. package/dist/utils/resize-panel.d.ts +2 -2
  31. package/dist/utils/size.d.mts +17 -0
  32. package/dist/utils/size.d.ts +17 -0
  33. package/dist/utils/size.js +138 -0
  34. package/dist/utils/size.mjs +111 -0
  35. package/dist/utils/validate-sizes.d.mts +2 -2
  36. package/dist/utils/validate-sizes.d.ts +2 -2
  37. package/package.json +6 -6
@@ -1,4 +1,4 @@
1
- import { PanelData } from '../splitter.types.mjs';
1
+ import { NormalizedPanelData } from '../splitter.types.mjs';
2
2
  import '@zag-js/core';
3
3
  import '@zag-js/types';
4
4
  import './registry.mjs';
@@ -10,14 +10,20 @@ import './registry.mjs';
10
10
 
11
11
  declare function calculateAriaValues({ size, panels, pivotIndices, }: {
12
12
  size: number[];
13
- panels: PanelData[];
13
+ panels: NormalizedPanelData[];
14
14
  pivotIndices: number[];
15
15
  }): {
16
16
  valueMax: number;
17
17
  valueMin: number;
18
18
  valueNow: number;
19
19
  };
20
- declare function getAriaValue(size: number[], panels: PanelData[], handleId: string): {
20
+ declare function getAriaValue(size: number[], panels: NormalizedPanelData[], handleId: string): {
21
+ beforeId: string | undefined;
22
+ afterId: string | undefined;
23
+ valueMax: undefined;
24
+ valueMin: undefined;
25
+ valueNow: undefined;
26
+ } | {
21
27
  beforeId: string;
22
28
  afterId: string;
23
29
  valueMax: number;
@@ -1,4 +1,4 @@
1
- import { PanelData } from '../splitter.types.js';
1
+ import { NormalizedPanelData } from '../splitter.types.js';
2
2
  import '@zag-js/core';
3
3
  import '@zag-js/types';
4
4
  import './registry.js';
@@ -10,14 +10,20 @@ import './registry.js';
10
10
 
11
11
  declare function calculateAriaValues({ size, panels, pivotIndices, }: {
12
12
  size: number[];
13
- panels: PanelData[];
13
+ panels: NormalizedPanelData[];
14
14
  pivotIndices: number[];
15
15
  }): {
16
16
  valueMax: number;
17
17
  valueMin: number;
18
18
  valueNow: number;
19
19
  };
20
- declare function getAriaValue(size: number[], panels: PanelData[], handleId: string): {
20
+ declare function getAriaValue(size: number[], panels: NormalizedPanelData[], handleId: string): {
21
+ beforeId: string | undefined;
22
+ afterId: string | undefined;
23
+ valueMax: undefined;
24
+ valueMin: undefined;
25
+ valueNow: undefined;
26
+ } | {
21
27
  beforeId: string;
22
28
  afterId: string;
23
29
  valueMax: number;
@@ -59,6 +59,15 @@ function getAriaValue(size, panels, handleId) {
59
59
  const [beforeId, afterId] = handleId.split(":");
60
60
  const beforeIndex = panels.findIndex((panel) => panel.id === beforeId);
61
61
  const afterIndex = panels.findIndex((panel) => panel.id === afterId);
62
+ if (beforeIndex === -1 || afterIndex === -1) {
63
+ return {
64
+ beforeId: beforeId || void 0,
65
+ afterId: afterId || void 0,
66
+ valueMax: void 0,
67
+ valueMin: void 0,
68
+ valueNow: void 0
69
+ };
70
+ }
62
71
  const { valueMax, valueMin, valueNow } = calculateAriaValues({
63
72
  size,
64
73
  panels,
@@ -36,6 +36,15 @@ function getAriaValue(size, panels, handleId) {
36
36
  const [beforeId, afterId] = handleId.split(":");
37
37
  const beforeIndex = panels.findIndex((panel) => panel.id === beforeId);
38
38
  const afterIndex = panels.findIndex((panel) => panel.id === afterId);
39
+ if (beforeIndex === -1 || afterIndex === -1) {
40
+ return {
41
+ beforeId: beforeId || void 0,
42
+ afterId: afterId || void 0,
43
+ valueMax: void 0,
44
+ valueMin: void 0,
45
+ valueNow: void 0
46
+ };
47
+ }
39
48
  const { valueMax, valueMin, valueNow } = calculateAriaValues({
40
49
  size,
41
50
  panels,
@@ -1,30 +1,31 @@
1
1
  import { Style } from '@zag-js/types';
2
- import { PanelData, DragState, PanelId } from '../splitter.types.mjs';
2
+ import { PanelData, PanelSize, DragState } from '../splitter.types.mjs';
3
3
  import '@zag-js/core';
4
4
  import './registry.mjs';
5
5
 
6
- declare function getPanelById(panels: PanelData[], id: string): PanelData;
6
+ /**
7
+ * This code was modified from react-resizable-panels by Brian Vaughn
8
+ * @see https://github.com/bvaughn/react-resizable-panels
9
+ */
10
+
11
+ declare function getPanelById<T extends PanelData>(panels: T[], id: string): T;
7
12
  declare function findPanelDataIndex(panels: PanelData[], panel: PanelData): number;
8
13
  declare function findPanelIndex(panels: PanelData[], id: string): number;
9
- declare function panelDataHelper(panels: PanelData[], panel: PanelData, sizes: number[]): {
14
+ declare function panelDataHelper<T extends PanelData>(panels: T[], panel: T, sizes: number[]): T & {
10
15
  panelSize: number;
11
16
  pivotIndices: number[];
12
- id: PanelId;
13
- order?: number | undefined;
14
- minSize?: number | undefined;
15
- maxSize?: number | undefined;
16
- collapsible?: boolean | undefined;
17
- collapsedSize?: number | undefined;
18
17
  };
19
18
  declare function sortPanels(panels: PanelData[]): PanelData[];
20
19
  declare function getPanelLayout(panels: PanelData[]): string;
21
20
  declare function serializePanels(panels: PanelData[]): string;
22
- declare function getPanelFlexBoxStyle({ defaultSize, dragState, sizes, panels, panelIndex, precision, }: {
23
- defaultSize: number | undefined;
24
- sizes: number[];
21
+ declare function getPanelFlexBoxStyle({ size, defaultSize, dragState, resolvedSizes, panels, panelIndex, horizontal, precision, }: {
22
+ size: PanelSize | undefined;
23
+ defaultSize: PanelSize | undefined;
24
+ resolvedSizes: number[];
25
25
  dragState: DragState | null;
26
26
  panels: PanelData[];
27
27
  panelIndex: number;
28
+ horizontal: boolean;
28
29
  precision?: number | undefined;
29
30
  }): Style;
30
31
  declare function getUnsafeDefaultSize({ panels, size: sizes }: {
@@ -1,30 +1,31 @@
1
1
  import { Style } from '@zag-js/types';
2
- import { PanelData, DragState, PanelId } from '../splitter.types.js';
2
+ import { PanelData, PanelSize, DragState } from '../splitter.types.js';
3
3
  import '@zag-js/core';
4
4
  import './registry.js';
5
5
 
6
- declare function getPanelById(panels: PanelData[], id: string): PanelData;
6
+ /**
7
+ * This code was modified from react-resizable-panels by Brian Vaughn
8
+ * @see https://github.com/bvaughn/react-resizable-panels
9
+ */
10
+
11
+ declare function getPanelById<T extends PanelData>(panels: T[], id: string): T;
7
12
  declare function findPanelDataIndex(panels: PanelData[], panel: PanelData): number;
8
13
  declare function findPanelIndex(panels: PanelData[], id: string): number;
9
- declare function panelDataHelper(panels: PanelData[], panel: PanelData, sizes: number[]): {
14
+ declare function panelDataHelper<T extends PanelData>(panels: T[], panel: T, sizes: number[]): T & {
10
15
  panelSize: number;
11
16
  pivotIndices: number[];
12
- id: PanelId;
13
- order?: number | undefined;
14
- minSize?: number | undefined;
15
- maxSize?: number | undefined;
16
- collapsible?: boolean | undefined;
17
- collapsedSize?: number | undefined;
18
17
  };
19
18
  declare function sortPanels(panels: PanelData[]): PanelData[];
20
19
  declare function getPanelLayout(panels: PanelData[]): string;
21
20
  declare function serializePanels(panels: PanelData[]): string;
22
- declare function getPanelFlexBoxStyle({ defaultSize, dragState, sizes, panels, panelIndex, precision, }: {
23
- defaultSize: number | undefined;
24
- sizes: number[];
21
+ declare function getPanelFlexBoxStyle({ size, defaultSize, dragState, resolvedSizes, panels, panelIndex, horizontal, precision, }: {
22
+ size: PanelSize | undefined;
23
+ defaultSize: PanelSize | undefined;
24
+ resolvedSizes: number[];
25
25
  dragState: DragState | null;
26
26
  panels: PanelData[];
27
27
  panelIndex: number;
28
+ horizontal: boolean;
28
29
  precision?: number | undefined;
29
30
  }): Style;
30
31
  declare function getUnsafeDefaultSize({ panels, size: sizes }: {
@@ -32,6 +32,7 @@ __export(panel_exports, {
32
32
  });
33
33
  module.exports = __toCommonJS(panel_exports);
34
34
  var import_utils = require("@zag-js/utils");
35
+ var import_size = require("./size.js");
35
36
  function getPanelById(panels, id) {
36
37
  const panel = panels.find((panel2) => panel2.id === id);
37
38
  (0, import_utils.ensure)(panel, () => `Panel data not found for id "${id}"`);
@@ -77,26 +78,52 @@ function serializePanels(panels) {
77
78
  return serialized.join(",");
78
79
  }
79
80
  function getPanelFlexBoxStyle({
81
+ size,
80
82
  defaultSize,
81
83
  dragState,
82
- sizes,
84
+ resolvedSizes,
83
85
  panels,
84
86
  panelIndex,
87
+ horizontal,
85
88
  precision = 3
86
89
  }) {
87
- const size = sizes[panelIndex];
90
+ const resolvedSize = resolvedSizes[panelIndex];
91
+ const layoutSize = size ?? defaultSize;
92
+ const panel = panels[panelIndex];
88
93
  let flexGrow;
89
- if (size == null) {
90
- flexGrow = defaultSize != void 0 ? defaultSize.toPrecision(precision) : "1";
94
+ let flexBasis;
95
+ let flexShrink = 1;
96
+ const constraintAxis = horizontal ? "Width" : "Height";
97
+ const minSize = panel ? (0, import_size.toCssPanelSize)(panel.minSize) : void 0;
98
+ const maxSize = panel ? (0, import_size.toCssPanelSize)(panel.maxSize) : void 0;
99
+ const layoutCssSize = (0, import_size.toCssPanelSize)(layoutSize);
100
+ if (resolvedSize == null) {
101
+ if (layoutCssSize != null) {
102
+ if (layoutCssSize.endsWith("%")) {
103
+ flexGrow = Number.parseFloat(layoutCssSize).toPrecision(precision);
104
+ } else {
105
+ flexBasis = getClampedFlexBasis({
106
+ basis: layoutCssSize,
107
+ minSize,
108
+ maxSize
109
+ });
110
+ flexGrow = "0";
111
+ flexShrink = 0;
112
+ }
113
+ } else {
114
+ flexGrow = "1";
115
+ }
91
116
  } else if (panels.length === 1) {
92
117
  flexGrow = "1";
93
118
  } else {
94
- flexGrow = size.toPrecision(precision);
119
+ flexGrow = resolvedSize.toPrecision(precision);
95
120
  }
96
121
  return {
97
- flexBasis: 0,
122
+ flexBasis: flexBasis ?? 0,
98
123
  flexGrow,
99
- flexShrink: 1,
124
+ flexShrink,
125
+ ...minSize ? { [`min${constraintAxis}`]: minSize } : {},
126
+ ...maxSize ? { [`max${constraintAxis}`]: maxSize } : {},
100
127
  // Without this, Panel sizes may be unintentionally overridden by their content
101
128
  overflow: "hidden",
102
129
  // Disable pointer events inside of a panel during resize
@@ -104,6 +131,13 @@ function getPanelFlexBoxStyle({
104
131
  pointerEvents: dragState !== null ? "none" : void 0
105
132
  };
106
133
  }
134
+ function getClampedFlexBasis({
135
+ basis,
136
+ minSize,
137
+ maxSize
138
+ }) {
139
+ return `clamp(${minSize ?? "0%"}, ${basis}, ${maxSize ?? "100%"})`;
140
+ }
107
141
  function getUnsafeDefaultSize({ panels, size: sizes }) {
108
142
  const finalSizes = Array(panels.length);
109
143
  let numPanelsWithSizes = 0;
@@ -2,6 +2,7 @@ import "../chunk-QZ7TP4HQ.mjs";
2
2
 
3
3
  // src/utils/panel.ts
4
4
  import { ensure } from "@zag-js/utils";
5
+ import { toCssPanelSize } from "./size.mjs";
5
6
  function getPanelById(panels, id) {
6
7
  const panel = panels.find((panel2) => panel2.id === id);
7
8
  ensure(panel, () => `Panel data not found for id "${id}"`);
@@ -47,26 +48,52 @@ function serializePanels(panels) {
47
48
  return serialized.join(",");
48
49
  }
49
50
  function getPanelFlexBoxStyle({
51
+ size,
50
52
  defaultSize,
51
53
  dragState,
52
- sizes,
54
+ resolvedSizes,
53
55
  panels,
54
56
  panelIndex,
57
+ horizontal,
55
58
  precision = 3
56
59
  }) {
57
- const size = sizes[panelIndex];
60
+ const resolvedSize = resolvedSizes[panelIndex];
61
+ const layoutSize = size ?? defaultSize;
62
+ const panel = panels[panelIndex];
58
63
  let flexGrow;
59
- if (size == null) {
60
- flexGrow = defaultSize != void 0 ? defaultSize.toPrecision(precision) : "1";
64
+ let flexBasis;
65
+ let flexShrink = 1;
66
+ const constraintAxis = horizontal ? "Width" : "Height";
67
+ const minSize = panel ? toCssPanelSize(panel.minSize) : void 0;
68
+ const maxSize = panel ? toCssPanelSize(panel.maxSize) : void 0;
69
+ const layoutCssSize = toCssPanelSize(layoutSize);
70
+ if (resolvedSize == null) {
71
+ if (layoutCssSize != null) {
72
+ if (layoutCssSize.endsWith("%")) {
73
+ flexGrow = Number.parseFloat(layoutCssSize).toPrecision(precision);
74
+ } else {
75
+ flexBasis = getClampedFlexBasis({
76
+ basis: layoutCssSize,
77
+ minSize,
78
+ maxSize
79
+ });
80
+ flexGrow = "0";
81
+ flexShrink = 0;
82
+ }
83
+ } else {
84
+ flexGrow = "1";
85
+ }
61
86
  } else if (panels.length === 1) {
62
87
  flexGrow = "1";
63
88
  } else {
64
- flexGrow = size.toPrecision(precision);
89
+ flexGrow = resolvedSize.toPrecision(precision);
65
90
  }
66
91
  return {
67
- flexBasis: 0,
92
+ flexBasis: flexBasis ?? 0,
68
93
  flexGrow,
69
- flexShrink: 1,
94
+ flexShrink,
95
+ ...minSize ? { [`min${constraintAxis}`]: minSize } : {},
96
+ ...maxSize ? { [`max${constraintAxis}`]: maxSize } : {},
70
97
  // Without this, Panel sizes may be unintentionally overridden by their content
71
98
  overflow: "hidden",
72
99
  // Disable pointer events inside of a panel during resize
@@ -74,6 +101,13 @@ function getPanelFlexBoxStyle({
74
101
  pointerEvents: dragState !== null ? "none" : void 0
75
102
  };
76
103
  }
104
+ function getClampedFlexBasis({
105
+ basis,
106
+ minSize,
107
+ maxSize
108
+ }) {
109
+ return `clamp(${minSize ?? "0%"}, ${basis}, ${maxSize ?? "100%"})`;
110
+ }
77
111
  function getUnsafeDefaultSize({ panels, size: sizes }) {
78
112
  const finalSizes = Array(panels.length);
79
113
  let numPanelsWithSizes = 0;
@@ -0,0 +1,18 @@
1
+ import { NormalizedPanelData } from '../splitter.types.mjs';
2
+ import '@zag-js/core';
3
+ import '@zag-js/types';
4
+ import './registry.mjs';
5
+
6
+ /**
7
+ * This code was modified from react-resizable-panels by Brian Vaughn
8
+ * @see https://github.com/bvaughn/react-resizable-panels
9
+ */
10
+
11
+ declare function preserveFixedPanelSizes({ panels, prevLayout, prevGroupSize, nextGroupSize, }: {
12
+ panels: NormalizedPanelData[];
13
+ prevLayout: number[];
14
+ prevGroupSize: number;
15
+ nextGroupSize: number;
16
+ }): number[];
17
+
18
+ export { preserveFixedPanelSizes };
@@ -0,0 +1,18 @@
1
+ import { NormalizedPanelData } from '../splitter.types.js';
2
+ import '@zag-js/core';
3
+ import '@zag-js/types';
4
+ import './registry.js';
5
+
6
+ /**
7
+ * This code was modified from react-resizable-panels by Brian Vaughn
8
+ * @see https://github.com/bvaughn/react-resizable-panels
9
+ */
10
+
11
+ declare function preserveFixedPanelSizes({ panels, prevLayout, prevGroupSize, nextGroupSize, }: {
12
+ panels: NormalizedPanelData[];
13
+ prevLayout: number[];
14
+ prevGroupSize: number;
15
+ nextGroupSize: number;
16
+ }): number[];
17
+
18
+ export { preserveFixedPanelSizes };
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/utils/preserve-fixed-panel-sizes.ts
21
+ var preserve_fixed_panel_sizes_exports = {};
22
+ __export(preserve_fixed_panel_sizes_exports, {
23
+ preserveFixedPanelSizes: () => preserveFixedPanelSizes
24
+ });
25
+ module.exports = __toCommonJS(preserve_fixed_panel_sizes_exports);
26
+ var import_fuzzy = require("./fuzzy.js");
27
+ function preserveFixedPanelSizes({
28
+ panels,
29
+ prevLayout,
30
+ prevGroupSize,
31
+ nextGroupSize
32
+ }) {
33
+ if (prevGroupSize <= 0 || nextGroupSize <= 0) {
34
+ return prevLayout;
35
+ }
36
+ const nextLayout = [...prevLayout];
37
+ const relativeIndices = [];
38
+ let fixedTotal = 0;
39
+ let relativeTotal = 0;
40
+ panels.forEach((panel, index) => {
41
+ if (panel.resizeBehavior === "preserve-pixel-size") {
42
+ const prevPixelSize = prevLayout[index] / 100 * prevGroupSize;
43
+ const nextPercentSize = prevPixelSize / nextGroupSize * 100;
44
+ nextLayout[index] = nextPercentSize;
45
+ fixedTotal += nextPercentSize;
46
+ } else {
47
+ relativeIndices.push(index);
48
+ relativeTotal += prevLayout[index];
49
+ }
50
+ });
51
+ if (relativeIndices.length === 0) {
52
+ const total2 = nextLayout.reduce((accumulated, current) => accumulated + current, 0);
53
+ if ((0, import_fuzzy.fuzzyNumbersEqual)(total2, 100)) {
54
+ return nextLayout;
55
+ }
56
+ if (total2 <= 0) {
57
+ return prevLayout;
58
+ }
59
+ const scale2 = 100 / total2;
60
+ return nextLayout.map((size) => size * scale2);
61
+ }
62
+ const remainingSize = 100 - fixedTotal;
63
+ if (remainingSize <= 0) {
64
+ const total2 = nextLayout.reduce((accumulated, current) => accumulated + current, 0);
65
+ if ((0, import_fuzzy.fuzzyNumbersEqual)(total2, 100)) {
66
+ return nextLayout;
67
+ }
68
+ const scale2 = 100 / Math.max(total2, 1);
69
+ return nextLayout.map((size) => size * scale2);
70
+ }
71
+ if ((0, import_fuzzy.fuzzyNumbersEqual)(relativeTotal, 0)) {
72
+ const size = remainingSize / relativeIndices.length;
73
+ relativeIndices.forEach((index) => {
74
+ nextLayout[index] = size;
75
+ });
76
+ return nextLayout;
77
+ }
78
+ relativeIndices.forEach((index) => {
79
+ nextLayout[index] = prevLayout[index] / relativeTotal * remainingSize;
80
+ });
81
+ const total = nextLayout.reduce((accumulated, current) => accumulated + current, 0);
82
+ if ((0, import_fuzzy.fuzzyNumbersEqual)(total, 100)) {
83
+ return nextLayout;
84
+ }
85
+ const scale = 100 / total;
86
+ return nextLayout.map((size) => size * scale);
87
+ }
88
+ // Annotate the CommonJS export names for ESM import in node:
89
+ 0 && (module.exports = {
90
+ preserveFixedPanelSizes
91
+ });
@@ -0,0 +1,68 @@
1
+ import "../chunk-QZ7TP4HQ.mjs";
2
+
3
+ // src/utils/preserve-fixed-panel-sizes.ts
4
+ import { fuzzyNumbersEqual } from "./fuzzy.mjs";
5
+ function preserveFixedPanelSizes({
6
+ panels,
7
+ prevLayout,
8
+ prevGroupSize,
9
+ nextGroupSize
10
+ }) {
11
+ if (prevGroupSize <= 0 || nextGroupSize <= 0) {
12
+ return prevLayout;
13
+ }
14
+ const nextLayout = [...prevLayout];
15
+ const relativeIndices = [];
16
+ let fixedTotal = 0;
17
+ let relativeTotal = 0;
18
+ panels.forEach((panel, index) => {
19
+ if (panel.resizeBehavior === "preserve-pixel-size") {
20
+ const prevPixelSize = prevLayout[index] / 100 * prevGroupSize;
21
+ const nextPercentSize = prevPixelSize / nextGroupSize * 100;
22
+ nextLayout[index] = nextPercentSize;
23
+ fixedTotal += nextPercentSize;
24
+ } else {
25
+ relativeIndices.push(index);
26
+ relativeTotal += prevLayout[index];
27
+ }
28
+ });
29
+ if (relativeIndices.length === 0) {
30
+ const total2 = nextLayout.reduce((accumulated, current) => accumulated + current, 0);
31
+ if (fuzzyNumbersEqual(total2, 100)) {
32
+ return nextLayout;
33
+ }
34
+ if (total2 <= 0) {
35
+ return prevLayout;
36
+ }
37
+ const scale2 = 100 / total2;
38
+ return nextLayout.map((size) => size * scale2);
39
+ }
40
+ const remainingSize = 100 - fixedTotal;
41
+ if (remainingSize <= 0) {
42
+ const total2 = nextLayout.reduce((accumulated, current) => accumulated + current, 0);
43
+ if (fuzzyNumbersEqual(total2, 100)) {
44
+ return nextLayout;
45
+ }
46
+ const scale2 = 100 / Math.max(total2, 1);
47
+ return nextLayout.map((size) => size * scale2);
48
+ }
49
+ if (fuzzyNumbersEqual(relativeTotal, 0)) {
50
+ const size = remainingSize / relativeIndices.length;
51
+ relativeIndices.forEach((index) => {
52
+ nextLayout[index] = size;
53
+ });
54
+ return nextLayout;
55
+ }
56
+ relativeIndices.forEach((index) => {
57
+ nextLayout[index] = prevLayout[index] / relativeTotal * remainingSize;
58
+ });
59
+ const total = nextLayout.reduce((accumulated, current) => accumulated + current, 0);
60
+ if (fuzzyNumbersEqual(total, 100)) {
61
+ return nextLayout;
62
+ }
63
+ const scale = 100 / total;
64
+ return nextLayout.map((size) => size * scale);
65
+ }
66
+ export {
67
+ preserveFixedPanelSizes
68
+ };
@@ -135,7 +135,7 @@ var SplitterRegistry = class {
135
135
  */
136
136
  findIntersectingHandles(x, y, pointerType, eventTarget) {
137
137
  const hits = this.findHitHandles(x, y, pointerType);
138
- const targetElement = eventTarget instanceof HTMLElement || eventTarget instanceof SVGElement ? eventTarget : null;
138
+ const targetElement = (0, import_dom_query.isElement)(eventTarget) ? eventTarget : null;
139
139
  if (!targetElement || !(0, import_dom_query.contains)(this.doc, targetElement)) return hits;
140
140
  return hits.filter((handle) => {
141
141
  const dragHandleElement = handle.element;
@@ -3,7 +3,7 @@ import {
3
3
  } from "../chunk-QZ7TP4HQ.mjs";
4
4
 
5
5
  // src/utils/registry.ts
6
- import { contains, getDocument, getParentElement } from "@zag-js/dom-query";
6
+ import { contains, getDocument, getParentElement, isElement } from "@zag-js/dom-query";
7
7
  import { intersects, toRect } from "./intersects.mjs";
8
8
  import { compareStackingOrder } from "./stacking-order.mjs";
9
9
  var SplitterRegistry = class {
@@ -112,7 +112,7 @@ var SplitterRegistry = class {
112
112
  */
113
113
  findIntersectingHandles(x, y, pointerType, eventTarget) {
114
114
  const hits = this.findHitHandles(x, y, pointerType);
115
- const targetElement = eventTarget instanceof HTMLElement || eventTarget instanceof SVGElement ? eventTarget : null;
115
+ const targetElement = isElement(eventTarget) ? eventTarget : null;
116
116
  if (!targetElement || !contains(this.doc, targetElement)) return hits;
117
117
  return hits.filter((handle) => {
118
118
  const dragHandleElement = handle.element;
@@ -1,4 +1,4 @@
1
- import { PanelData } from '../splitter.types.mjs';
1
+ import { NormalizedPanelData } from '../splitter.types.mjs';
2
2
  import '@zag-js/core';
3
3
  import '@zag-js/types';
4
4
  import './registry.mjs';
@@ -11,7 +11,7 @@ import './registry.mjs';
11
11
  interface Layout {
12
12
  delta: number;
13
13
  initialSize: number[];
14
- panels: PanelData[];
14
+ panels: NormalizedPanelData[];
15
15
  pivotIndices: number[];
16
16
  prevSize: number[];
17
17
  trigger: "imperative-api" | "keyboard" | "mouse-or-touch";
@@ -1,4 +1,4 @@
1
- import { PanelData } from '../splitter.types.js';
1
+ import { NormalizedPanelData } from '../splitter.types.js';
2
2
  import '@zag-js/core';
3
3
  import '@zag-js/types';
4
4
  import './registry.js';
@@ -11,7 +11,7 @@ import './registry.js';
11
11
  interface Layout {
12
12
  delta: number;
13
13
  initialSize: number[];
14
- panels: PanelData[];
14
+ panels: NormalizedPanelData[];
15
15
  pivotIndices: number[];
16
16
  prevSize: number[];
17
17
  trigger: "imperative-api" | "keyboard" | "mouse-or-touch";
@@ -1,4 +1,4 @@
1
- import { PanelData } from '../splitter.types.mjs';
1
+ import { NormalizedPanelData } from '../splitter.types.mjs';
2
2
  import '@zag-js/core';
3
3
  import '@zag-js/types';
4
4
  import './registry.mjs';
@@ -9,7 +9,7 @@ import './registry.mjs';
9
9
  */
10
10
 
11
11
  declare function resizePanel({ panels, index, size }: {
12
- panels: PanelData[];
12
+ panels: NormalizedPanelData[];
13
13
  index: number;
14
14
  size: number;
15
15
  }): number;
@@ -1,4 +1,4 @@
1
- import { PanelData } from '../splitter.types.js';
1
+ import { NormalizedPanelData } from '../splitter.types.js';
2
2
  import '@zag-js/core';
3
3
  import '@zag-js/types';
4
4
  import './registry.js';
@@ -9,7 +9,7 @@ import './registry.js';
9
9
  */
10
10
 
11
11
  declare function resizePanel({ panels, index, size }: {
12
- panels: PanelData[];
12
+ panels: NormalizedPanelData[];
13
13
  index: number;
14
14
  size: number;
15
15
  }): number;
@@ -0,0 +1,17 @@
1
+ import { PanelData, NormalizedPanelData, PanelSize } from '../splitter.types.mjs';
2
+ import '@zag-js/core';
3
+ import '@zag-js/types';
4
+ import './registry.mjs';
5
+
6
+ declare function getGroupSize(rootEl: HTMLElement | null, orientation: "horizontal" | "vertical"): number;
7
+ declare function parsePanelSize(size: PanelSize | undefined, rootEl: HTMLElement | null, orientation: "horizontal" | "vertical"): number | undefined;
8
+ declare function toCssPanelSize(size: PanelSize | undefined): string | undefined;
9
+ declare function resolvePanelSizes({ sizes, panels, rootEl, orientation, }: {
10
+ sizes: PanelSize[] | undefined;
11
+ panels: PanelData[];
12
+ rootEl: HTMLElement | null;
13
+ orientation: "horizontal" | "vertical";
14
+ }): number[];
15
+ declare function normalizePanels(panels: PanelData[], rootEl: HTMLElement | null, orientation: "horizontal" | "vertical"): NormalizedPanelData[];
16
+
17
+ export { getGroupSize, normalizePanels, parsePanelSize, resolvePanelSizes, toCssPanelSize };
@@ -0,0 +1,17 @@
1
+ import { PanelData, NormalizedPanelData, PanelSize } from '../splitter.types.js';
2
+ import '@zag-js/core';
3
+ import '@zag-js/types';
4
+ import './registry.js';
5
+
6
+ declare function getGroupSize(rootEl: HTMLElement | null, orientation: "horizontal" | "vertical"): number;
7
+ declare function parsePanelSize(size: PanelSize | undefined, rootEl: HTMLElement | null, orientation: "horizontal" | "vertical"): number | undefined;
8
+ declare function toCssPanelSize(size: PanelSize | undefined): string | undefined;
9
+ declare function resolvePanelSizes({ sizes, panels, rootEl, orientation, }: {
10
+ sizes: PanelSize[] | undefined;
11
+ panels: PanelData[];
12
+ rootEl: HTMLElement | null;
13
+ orientation: "horizontal" | "vertical";
14
+ }): number[];
15
+ declare function normalizePanels(panels: PanelData[], rootEl: HTMLElement | null, orientation: "horizontal" | "vertical"): NormalizedPanelData[];
16
+
17
+ export { getGroupSize, normalizePanels, parsePanelSize, resolvePanelSizes, toCssPanelSize };