@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
@@ -0,0 +1,138 @@
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/size.ts
21
+ var size_exports = {};
22
+ __export(size_exports, {
23
+ getGroupSize: () => getGroupSize,
24
+ normalizePanels: () => normalizePanels,
25
+ parsePanelSize: () => parsePanelSize,
26
+ resolvePanelSizes: () => resolvePanelSizes,
27
+ toCssPanelSize: () => toCssPanelSize
28
+ });
29
+ module.exports = __toCommonJS(size_exports);
30
+ var sizeRegex = /^(-?\d*\.?\d+)(%|px|em|rem|vw|vh)?$/;
31
+ var percentRegex = /^(-?\d*\.?\d+)%$/;
32
+ function getRootSize(rootEl, orientation) {
33
+ if (!rootEl) return 0;
34
+ const rect = rootEl.getBoundingClientRect();
35
+ return orientation === "horizontal" ? rect.width : rect.height;
36
+ }
37
+ function getGroupSize(rootEl, orientation) {
38
+ return getRootSize(rootEl, orientation);
39
+ }
40
+ function toPixelValue(value, unit, rootEl) {
41
+ const win = rootEl.ownerDocument.defaultView;
42
+ if (!win) return void 0;
43
+ switch (unit) {
44
+ case "px":
45
+ return value;
46
+ case "em": {
47
+ const fontSize = Number.parseFloat(win.getComputedStyle(rootEl).fontSize);
48
+ return value * fontSize;
49
+ }
50
+ case "rem": {
51
+ const fontSize = Number.parseFloat(win.getComputedStyle(rootEl.ownerDocument.documentElement).fontSize);
52
+ return value * fontSize;
53
+ }
54
+ case "vw":
55
+ return value / 100 * win.innerWidth;
56
+ case "vh":
57
+ return value / 100 * win.innerHeight;
58
+ default:
59
+ return void 0;
60
+ }
61
+ }
62
+ function parsePanelSize(size, rootEl, orientation) {
63
+ if (size == null) return void 0;
64
+ if (typeof size === "number") {
65
+ return size;
66
+ }
67
+ const match = size.trim().match(sizeRegex);
68
+ if (!match) return void 0;
69
+ const value = Number.parseFloat(match[1]);
70
+ if (!Number.isFinite(value)) return void 0;
71
+ const unit = match[2];
72
+ if (unit == null || unit === "%") {
73
+ return value;
74
+ }
75
+ if (!rootEl) return void 0;
76
+ const rootSize = getRootSize(rootEl, orientation);
77
+ if (rootSize === 0) return void 0;
78
+ const px = toPixelValue(value, unit, rootEl);
79
+ return px == null ? void 0 : px / rootSize * 100;
80
+ }
81
+ function toCssPanelSize(size) {
82
+ if (size == null) return void 0;
83
+ if (typeof size === "number") {
84
+ return `${size}%`;
85
+ }
86
+ const trimmed = size.trim();
87
+ if (percentRegex.test(trimmed)) {
88
+ return trimmed;
89
+ }
90
+ const match = trimmed.match(sizeRegex);
91
+ if (!match) return void 0;
92
+ const value = Number.parseFloat(match[1]);
93
+ if (!Number.isFinite(value)) return void 0;
94
+ const unit = match[2];
95
+ return unit == null ? `${value}%` : `${value}${unit}`;
96
+ }
97
+ function resolvePanelSizes({
98
+ sizes,
99
+ panels,
100
+ rootEl,
101
+ orientation
102
+ }) {
103
+ const nextSize = Array(panels.length);
104
+ let remainingSize = 100;
105
+ let numPanelsWithSizes = 0;
106
+ for (let index = 0; index < panels.length; index++) {
107
+ const size = parsePanelSize(sizes?.[index], rootEl, orientation);
108
+ if (size == null) continue;
109
+ numPanelsWithSizes++;
110
+ nextSize[index] = size;
111
+ remainingSize -= size;
112
+ }
113
+ for (let index = 0; index < panels.length; index++) {
114
+ if (nextSize[index] != null) continue;
115
+ const numRemainingPanels = panels.length - numPanelsWithSizes;
116
+ const size = numRemainingPanels > 0 ? remainingSize / numRemainingPanels : 0;
117
+ numPanelsWithSizes++;
118
+ nextSize[index] = size;
119
+ remainingSize -= size;
120
+ }
121
+ return nextSize;
122
+ }
123
+ function normalizePanels(panels, rootEl, orientation) {
124
+ return panels.map((panel) => ({
125
+ ...panel,
126
+ minSize: parsePanelSize(panel.minSize, rootEl, orientation),
127
+ maxSize: parsePanelSize(panel.maxSize, rootEl, orientation),
128
+ collapsedSize: parsePanelSize(panel.collapsedSize, rootEl, orientation)
129
+ }));
130
+ }
131
+ // Annotate the CommonJS export names for ESM import in node:
132
+ 0 && (module.exports = {
133
+ getGroupSize,
134
+ normalizePanels,
135
+ parsePanelSize,
136
+ resolvePanelSizes,
137
+ toCssPanelSize
138
+ });
@@ -0,0 +1,111 @@
1
+ import "../chunk-QZ7TP4HQ.mjs";
2
+
3
+ // src/utils/size.ts
4
+ var sizeRegex = /^(-?\d*\.?\d+)(%|px|em|rem|vw|vh)?$/;
5
+ var percentRegex = /^(-?\d*\.?\d+)%$/;
6
+ function getRootSize(rootEl, orientation) {
7
+ if (!rootEl) return 0;
8
+ const rect = rootEl.getBoundingClientRect();
9
+ return orientation === "horizontal" ? rect.width : rect.height;
10
+ }
11
+ function getGroupSize(rootEl, orientation) {
12
+ return getRootSize(rootEl, orientation);
13
+ }
14
+ function toPixelValue(value, unit, rootEl) {
15
+ const win = rootEl.ownerDocument.defaultView;
16
+ if (!win) return void 0;
17
+ switch (unit) {
18
+ case "px":
19
+ return value;
20
+ case "em": {
21
+ const fontSize = Number.parseFloat(win.getComputedStyle(rootEl).fontSize);
22
+ return value * fontSize;
23
+ }
24
+ case "rem": {
25
+ const fontSize = Number.parseFloat(win.getComputedStyle(rootEl.ownerDocument.documentElement).fontSize);
26
+ return value * fontSize;
27
+ }
28
+ case "vw":
29
+ return value / 100 * win.innerWidth;
30
+ case "vh":
31
+ return value / 100 * win.innerHeight;
32
+ default:
33
+ return void 0;
34
+ }
35
+ }
36
+ function parsePanelSize(size, rootEl, orientation) {
37
+ if (size == null) return void 0;
38
+ if (typeof size === "number") {
39
+ return size;
40
+ }
41
+ const match = size.trim().match(sizeRegex);
42
+ if (!match) return void 0;
43
+ const value = Number.parseFloat(match[1]);
44
+ if (!Number.isFinite(value)) return void 0;
45
+ const unit = match[2];
46
+ if (unit == null || unit === "%") {
47
+ return value;
48
+ }
49
+ if (!rootEl) return void 0;
50
+ const rootSize = getRootSize(rootEl, orientation);
51
+ if (rootSize === 0) return void 0;
52
+ const px = toPixelValue(value, unit, rootEl);
53
+ return px == null ? void 0 : px / rootSize * 100;
54
+ }
55
+ function toCssPanelSize(size) {
56
+ if (size == null) return void 0;
57
+ if (typeof size === "number") {
58
+ return `${size}%`;
59
+ }
60
+ const trimmed = size.trim();
61
+ if (percentRegex.test(trimmed)) {
62
+ return trimmed;
63
+ }
64
+ const match = trimmed.match(sizeRegex);
65
+ if (!match) return void 0;
66
+ const value = Number.parseFloat(match[1]);
67
+ if (!Number.isFinite(value)) return void 0;
68
+ const unit = match[2];
69
+ return unit == null ? `${value}%` : `${value}${unit}`;
70
+ }
71
+ function resolvePanelSizes({
72
+ sizes,
73
+ panels,
74
+ rootEl,
75
+ orientation
76
+ }) {
77
+ const nextSize = Array(panels.length);
78
+ let remainingSize = 100;
79
+ let numPanelsWithSizes = 0;
80
+ for (let index = 0; index < panels.length; index++) {
81
+ const size = parsePanelSize(sizes?.[index], rootEl, orientation);
82
+ if (size == null) continue;
83
+ numPanelsWithSizes++;
84
+ nextSize[index] = size;
85
+ remainingSize -= size;
86
+ }
87
+ for (let index = 0; index < panels.length; index++) {
88
+ if (nextSize[index] != null) continue;
89
+ const numRemainingPanels = panels.length - numPanelsWithSizes;
90
+ const size = numRemainingPanels > 0 ? remainingSize / numRemainingPanels : 0;
91
+ numPanelsWithSizes++;
92
+ nextSize[index] = size;
93
+ remainingSize -= size;
94
+ }
95
+ return nextSize;
96
+ }
97
+ function normalizePanels(panels, rootEl, orientation) {
98
+ return panels.map((panel) => ({
99
+ ...panel,
100
+ minSize: parsePanelSize(panel.minSize, rootEl, orientation),
101
+ maxSize: parsePanelSize(panel.maxSize, rootEl, orientation),
102
+ collapsedSize: parsePanelSize(panel.collapsedSize, rootEl, orientation)
103
+ }));
104
+ }
105
+ export {
106
+ getGroupSize,
107
+ normalizePanels,
108
+ parsePanelSize,
109
+ resolvePanelSizes,
110
+ toCssPanelSize
111
+ };
@@ -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,7 +10,7 @@ import './registry.mjs';
10
10
 
11
11
  declare function validateSizes({ size: prevSize, panels }: {
12
12
  size: number[];
13
- panels: PanelData[];
13
+ panels: NormalizedPanelData[];
14
14
  }): number[];
15
15
 
16
16
  export { validateSizes };
@@ -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,7 +10,7 @@ import './registry.js';
10
10
 
11
11
  declare function validateSizes({ size: prevSize, panels }: {
12
12
  size: number[];
13
- panels: PanelData[];
13
+ panels: NormalizedPanelData[];
14
14
  }): number[];
15
15
 
16
16
  export { validateSizes };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/splitter",
3
- "version": "1.39.1",
3
+ "version": "1.41.0",
4
4
  "description": "Core logic for the splitter widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -27,11 +27,11 @@
27
27
  "url": "https://github.com/chakra-ui/zag/issues"
28
28
  },
29
29
  "dependencies": {
30
- "@zag-js/anatomy": "1.39.1",
31
- "@zag-js/core": "1.39.1",
32
- "@zag-js/dom-query": "1.39.1",
33
- "@zag-js/types": "1.39.1",
34
- "@zag-js/utils": "1.39.1"
30
+ "@zag-js/anatomy": "1.41.0",
31
+ "@zag-js/core": "1.41.0",
32
+ "@zag-js/dom-query": "1.41.0",
33
+ "@zag-js/types": "1.41.0",
34
+ "@zag-js/utils": "1.41.0"
35
35
  },
36
36
  "devDependencies": {
37
37
  "clean-package": "2.2.0"