@ngneers/controls 0.0.1-pre5 → 0.0.1-pre6
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/fesm2022/ngneers-controls-accordion.mjs +32 -32
- package/fesm2022/ngneers-controls-accordion.mjs.map +1 -1
- package/fesm2022/ngneers-controls-api-ng.mjs +19 -19
- package/fesm2022/ngneers-controls-api-ng.mjs.map +1 -1
- package/fesm2022/ngneers-controls-api-resize.mjs +706 -0
- package/fesm2022/ngneers-controls-api-resize.mjs.map +1 -0
- package/fesm2022/ngneers-controls-avatar.mjs +13 -13
- package/fesm2022/ngneers-controls-avatar.mjs.map +1 -1
- package/fesm2022/ngneers-controls-base.mjs +89 -64
- package/fesm2022/ngneers-controls-base.mjs.map +1 -1
- package/fesm2022/ngneers-controls-breadcrumb.mjs +18 -18
- package/fesm2022/ngneers-controls-breadcrumb.mjs.map +1 -1
- package/fesm2022/ngneers-controls-button-group.mjs +8 -8
- package/fesm2022/ngneers-controls-button-group.mjs.map +1 -1
- package/fesm2022/ngneers-controls-button.mjs +15 -10
- package/fesm2022/ngneers-controls-button.mjs.map +1 -1
- package/fesm2022/{ngneers-controls-calendar-time-BEeJIqIX.mjs → ngneers-controls-calendar-time-Bzlv9Vkn.mjs} +9 -9
- package/fesm2022/{ngneers-controls-calendar-time-BEeJIqIX.mjs.map → ngneers-controls-calendar-time-Bzlv9Vkn.mjs.map} +1 -1
- package/fesm2022/ngneers-controls-calendar.mjs +54 -54
- package/fesm2022/ngneers-controls-calendar.mjs.map +1 -1
- package/fesm2022/ngneers-controls-checkbox.mjs +9 -9
- package/fesm2022/ngneers-controls-checkbox.mjs.map +1 -1
- package/fesm2022/ngneers-controls-chip.mjs +6 -6
- package/fesm2022/ngneers-controls-chip.mjs.map +1 -1
- package/fesm2022/ngneers-controls-defer.mjs +10 -10
- package/fesm2022/ngneers-controls-defer.mjs.map +1 -1
- package/fesm2022/ngneers-controls-dialog.mjs +37 -39
- package/fesm2022/ngneers-controls-dialog.mjs.map +1 -1
- package/fesm2022/ngneers-controls-directives.mjs +45 -39
- package/fesm2022/ngneers-controls-directives.mjs.map +1 -1
- package/fesm2022/ngneers-controls-drawer.mjs +28 -28
- package/fesm2022/ngneers-controls-drawer.mjs.map +1 -1
- package/fesm2022/ngneers-controls-edit-inplace.mjs +15 -15
- package/fesm2022/ngneers-controls-edit-inplace.mjs.map +1 -1
- package/fesm2022/ngneers-controls-filter.mjs +192 -44
- package/fesm2022/ngneers-controls-filter.mjs.map +1 -1
- package/fesm2022/{ngneers-controls-i18n-de-CdTPeBiR.mjs → ngneers-controls-i18n-de-CF0xTWEX.mjs} +9 -5
- package/fesm2022/ngneers-controls-i18n-de-CF0xTWEX.mjs.map +1 -0
- package/fesm2022/{ngneers-controls-i18n-en-Cfp2pOLY.mjs → ngneers-controls-i18n-en-8B7xAjH2.mjs} +9 -5
- package/fesm2022/ngneers-controls-i18n-en-8B7xAjH2.mjs.map +1 -0
- package/fesm2022/ngneers-controls-i18n.mjs +5 -5
- package/fesm2022/ngneers-controls-i18n.mjs.map +1 -1
- package/fesm2022/ngneers-controls-icon.mjs +10 -10
- package/fesm2022/ngneers-controls-icon.mjs.map +1 -1
- package/fesm2022/ngneers-controls-inplace.mjs +18 -18
- package/fesm2022/ngneers-controls-inplace.mjs.map +1 -1
- package/fesm2022/ngneers-controls-input-field.mjs +14 -14
- package/fesm2022/ngneers-controls-input-field.mjs.map +1 -1
- package/fesm2022/ngneers-controls-input-mask.mjs +8 -8
- package/fesm2022/ngneers-controls-input-mask.mjs.map +1 -1
- package/fesm2022/ngneers-controls-input.mjs +6 -6
- package/fesm2022/ngneers-controls-input.mjs.map +1 -1
- package/fesm2022/ngneers-controls-item-view.mjs +33 -33
- package/fesm2022/ngneers-controls-item-view.mjs.map +1 -1
- package/fesm2022/ngneers-controls-list-box.mjs +31 -31
- package/fesm2022/ngneers-controls-list-box.mjs.map +1 -1
- package/fesm2022/ngneers-controls-menu.mjs +32 -32
- package/fesm2022/ngneers-controls-menu.mjs.map +1 -1
- package/fesm2022/ngneers-controls-message.mjs +4 -4
- package/fesm2022/ngneers-controls-message.mjs.map +1 -1
- package/fesm2022/ngneers-controls-paginator.mjs +12 -12
- package/fesm2022/ngneers-controls-paginator.mjs.map +1 -1
- package/fesm2022/ngneers-controls-popover.mjs +13 -13
- package/fesm2022/ngneers-controls-popover.mjs.map +1 -1
- package/fesm2022/ngneers-controls-progress.mjs +16 -16
- package/fesm2022/ngneers-controls-progress.mjs.map +1 -1
- package/fesm2022/ngneers-controls-scroller.mjs +74 -39
- package/fesm2022/ngneers-controls-scroller.mjs.map +1 -1
- package/fesm2022/ngneers-controls-select-button.mjs +6 -6
- package/fesm2022/ngneers-controls-select-button.mjs.map +1 -1
- package/fesm2022/ngneers-controls-select.mjs +46 -46
- package/fesm2022/ngneers-controls-select.mjs.map +1 -1
- package/fesm2022/ngneers-controls-slider.mjs +11 -11
- package/fesm2022/ngneers-controls-slider.mjs.map +1 -1
- package/fesm2022/ngneers-controls-spinner.mjs +7 -7
- package/fesm2022/ngneers-controls-spinner.mjs.map +1 -1
- package/fesm2022/ngneers-controls-splitter.mjs +141 -328
- package/fesm2022/ngneers-controls-splitter.mjs.map +1 -1
- package/fesm2022/ngneers-controls-switch.mjs +3 -3
- package/fesm2022/ngneers-controls-table.mjs +1520 -80
- package/fesm2022/ngneers-controls-table.mjs.map +1 -1
- package/fesm2022/ngneers-controls-tabs.mjs +40 -39
- package/fesm2022/ngneers-controls-tabs.mjs.map +1 -1
- package/fesm2022/ngneers-controls-tag.mjs +4 -4
- package/fesm2022/ngneers-controls-tag.mjs.map +1 -1
- package/fesm2022/ngneers-controls-toast.mjs +18 -18
- package/fesm2022/ngneers-controls-toast.mjs.map +1 -1
- package/fesm2022/ngneers-controls-toggle-button.mjs +9 -9
- package/fesm2022/ngneers-controls-toggle-button.mjs.map +1 -1
- package/fesm2022/ngneers-controls-tooltip.mjs +36 -36
- package/fesm2022/ngneers-controls-tooltip.mjs.map +1 -1
- package/fesm2022/ngneers-controls-utils-ng.mjs +9 -9
- package/fesm2022/ngneers-controls-utils-ng.mjs.map +1 -1
- package/package.json +14 -10
- package/types/ngneers-controls-api-ng.d.ts +2 -2
- package/types/ngneers-controls-api-resize.d.ts +318 -0
- package/types/ngneers-controls-base.d.ts +8 -0
- package/types/ngneers-controls-breadcrumb.d.ts +1 -1
- package/types/ngneers-controls-button.d.ts +13 -8
- package/types/ngneers-controls-calendar.d.ts +5 -1
- package/types/ngneers-controls-checkbox.d.ts +1 -1
- package/types/ngneers-controls-directives.d.ts +7 -1
- package/types/ngneers-controls-drawer.d.ts +4 -0
- package/types/ngneers-controls-edit-inplace.d.ts +4 -0
- package/types/ngneers-controls-filter.d.ts +53 -4
- package/types/ngneers-controls-i18n.d.ts +4 -0
- package/types/ngneers-controls-icon.d.ts +1 -1
- package/types/ngneers-controls-input-field.d.ts +4 -0
- package/types/ngneers-controls-list-box.d.ts +5 -1
- package/types/ngneers-controls-menu.d.ts +1 -1
- package/types/ngneers-controls-paginator.d.ts +4 -0
- package/types/ngneers-controls-popover.d.ts +1 -1
- package/types/ngneers-controls-scroller.d.ts +12 -2
- package/types/ngneers-controls-select.d.ts +6 -2
- package/types/ngneers-controls-spinner.d.ts +1 -1
- package/types/ngneers-controls-splitter.d.ts +29 -59
- package/types/ngneers-controls-table.d.ts +392 -24
- package/types/ngneers-controls-toast.d.ts +1 -1
- package/fesm2022/ngneers-controls-i18n-de-CdTPeBiR.mjs.map +0 -1
- package/fesm2022/ngneers-controls-i18n-en-Cfp2pOLY.mjs.map +0 -1
|
@@ -0,0 +1,706 @@
|
|
|
1
|
+
import { signal, computed, afterRenderEffect, untracked } from '@angular/core';
|
|
2
|
+
|
|
3
|
+
// --- Size parsing ---
|
|
4
|
+
function isResizeSize(value) {
|
|
5
|
+
if (typeof value !== 'string')
|
|
6
|
+
return false;
|
|
7
|
+
const m = value.match(/^(.+)(px|fr|%)$/);
|
|
8
|
+
if (!m || !m[1])
|
|
9
|
+
return false;
|
|
10
|
+
if (isNaN(parseFloat(m[1])))
|
|
11
|
+
return false;
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
function getResizeSizeUnit(value) {
|
|
15
|
+
if (value.endsWith('px'))
|
|
16
|
+
return 'px';
|
|
17
|
+
if (value.endsWith('fr'))
|
|
18
|
+
return 'fr';
|
|
19
|
+
return '%';
|
|
20
|
+
}
|
|
21
|
+
function getResizeSizeValue(value) {
|
|
22
|
+
const unit = getResizeSizeUnit(value);
|
|
23
|
+
return parseFloat(value.slice(0, -unit.length));
|
|
24
|
+
}
|
|
25
|
+
function expandResizeSize(value) {
|
|
26
|
+
return {
|
|
27
|
+
value: getResizeSizeValue(value),
|
|
28
|
+
unit: getResizeSizeUnit(value),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function collapseResizeSize(size) {
|
|
32
|
+
return `${size.value}${size.unit}`;
|
|
33
|
+
}
|
|
34
|
+
// --- Limit parsing ---
|
|
35
|
+
function isResizeLimit(value) {
|
|
36
|
+
if (typeof value !== 'string')
|
|
37
|
+
return false;
|
|
38
|
+
const m = value.match(/^(.+)(px|%)$/);
|
|
39
|
+
if (!m || !m[1])
|
|
40
|
+
return false;
|
|
41
|
+
if (isNaN(parseFloat(m[1])))
|
|
42
|
+
return false;
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
function getResizeLimitUnit(value) {
|
|
46
|
+
return value.endsWith('px') ? 'px' : '%';
|
|
47
|
+
}
|
|
48
|
+
function getResizeLimitValue(value) {
|
|
49
|
+
return value.endsWith('px') ? parseFloat(value.slice(0, -2)) : parseFloat(value.slice(0, -1));
|
|
50
|
+
}
|
|
51
|
+
function getResizeLimitInPx(value, containerSize) {
|
|
52
|
+
const unit = getResizeLimitUnit(value);
|
|
53
|
+
const sizeValue = getResizeLimitValue(value);
|
|
54
|
+
return unit === 'px' ? sizeValue : (sizeValue / 100) * containerSize;
|
|
55
|
+
}
|
|
56
|
+
function expandResizeLimit(value) {
|
|
57
|
+
return {
|
|
58
|
+
value: getResizeLimitValue(value),
|
|
59
|
+
unit: getResizeLimitUnit(value),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function collapseResizeLimit(size) {
|
|
63
|
+
return `${size.value}${size.unit}`;
|
|
64
|
+
}
|
|
65
|
+
// --- Pixel resolution ---
|
|
66
|
+
/**
|
|
67
|
+
* Resolves a size to its pixel equivalent given the current fraction factors and container size.
|
|
68
|
+
*/
|
|
69
|
+
function resolveSizeToPx(size, pxPerFr, containerSize) {
|
|
70
|
+
switch (size.unit) {
|
|
71
|
+
case 'px':
|
|
72
|
+
return size.value;
|
|
73
|
+
case 'fr':
|
|
74
|
+
return pxPerFr * size.value;
|
|
75
|
+
case '%':
|
|
76
|
+
return (size.value / 100) * containerSize;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Converts a pixel delta to the appropriate value delta for the given unit.
|
|
81
|
+
*/
|
|
82
|
+
function pxDeltaToUnitDelta(pxDelta, unit, frPerPx, percentPerPx) {
|
|
83
|
+
switch (unit) {
|
|
84
|
+
case 'px':
|
|
85
|
+
return pxDelta;
|
|
86
|
+
case 'fr':
|
|
87
|
+
return pxDelta * frPerPx;
|
|
88
|
+
case '%':
|
|
89
|
+
return pxDelta * percentPerPx;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const LAST_CALC_SIZE_SYMBOL = Symbol('lastCalcSize');
|
|
94
|
+
/**
|
|
95
|
+
* A generic, control-agnostic resize engine for CSS grid layouts.
|
|
96
|
+
*
|
|
97
|
+
* Handles drag-based resizing of a list of {@link ResizableItem}s with support for:
|
|
98
|
+
* - **Size units**: `px`, `fr`, `%`
|
|
99
|
+
* - **Distribution modes**:
|
|
100
|
+
* - `adjacent` — transfers space between the two items neighbouring the divider (zero-sum).
|
|
101
|
+
* - `proportional` — only the dragged item changes to `px`; other items keep their `fr`/`%`
|
|
102
|
+
* units and CSS grid redistributes the remaining space. Optionally locks the resized item
|
|
103
|
+
* to `px` via {@link ResizeEngineConfig.lockSizes}.
|
|
104
|
+
* - `push` — the dragged item grows/shrinks independently; the container total changes
|
|
105
|
+
* (requires `containerConstrained = false`).
|
|
106
|
+
* - **Commit modes** (for `adjacent`/`push`): `preserve`, `bakeAll`, `bakeAffected`
|
|
107
|
+
* - **Min-size floor** ({@link ResizeEngineConfig.minItemSizePx}): an absolute `px` floor
|
|
108
|
+
* enforced even when a relative min-size resolves smaller. In `proportional` mode, emitted
|
|
109
|
+
* as CSS `minmax(floor, size)` so the grid natively prevents columns from shrinking below it.
|
|
110
|
+
*
|
|
111
|
+
* Consumers (splitter, table) provide items and configuration via signals.
|
|
112
|
+
* The engine outputs a ready-to-use `grid-template-columns`/`grid-template-rows` string
|
|
113
|
+
* via {@link gridTemplateSizes}.
|
|
114
|
+
*/
|
|
115
|
+
class ResizeEngine {
|
|
116
|
+
items;
|
|
117
|
+
containerSize;
|
|
118
|
+
gapSizes;
|
|
119
|
+
distributionMode;
|
|
120
|
+
containerConstrained;
|
|
121
|
+
lockSizes;
|
|
122
|
+
minItemSizePx;
|
|
123
|
+
resolveItemSizes;
|
|
124
|
+
constructor(config) {
|
|
125
|
+
this.items = config.items;
|
|
126
|
+
this.containerSize = config.containerSize;
|
|
127
|
+
this.gapSizes = config.gapSizes;
|
|
128
|
+
this.distributionMode = config.distributionMode;
|
|
129
|
+
this.containerConstrained = config.containerConstrained;
|
|
130
|
+
this.lockSizes = config.lockSizes ?? signal(false);
|
|
131
|
+
this.minItemSizePx = config.minItemSizePx ?? 0;
|
|
132
|
+
this.resolveItemSizes = config.resolveItemSizes;
|
|
133
|
+
// Signal fires when any item size is not calculated (external change detected)
|
|
134
|
+
const hasUncalculatedSizes = computed(() => this.items().some(item => !this.isItemSizeCalculated(item)), { equal: (_, b) => b === false });
|
|
135
|
+
// Ensure min/max limits are respected on external changes and container resize
|
|
136
|
+
afterRenderEffect(() => {
|
|
137
|
+
hasUncalculatedSizes();
|
|
138
|
+
this.containerSize();
|
|
139
|
+
untracked(() => {
|
|
140
|
+
// Skip during active drag — sizes are managed by the drag handler
|
|
141
|
+
if (this.dragContext())
|
|
142
|
+
return;
|
|
143
|
+
this.ensureMinMaxSizes();
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
// --- Public signals ---
|
|
148
|
+
/** The active drag state, or `null` when idle. */
|
|
149
|
+
dragContext = signal(null, ...(ngDevMode ? [{ debugName: "dragContext" }] : /* istanbul ignore next */ []));
|
|
150
|
+
/** Whether a drag operation is currently in progress. */
|
|
151
|
+
isDragging = computed(() => this.dragContext() !== null, ...(ngDevMode ? [{ debugName: "isDragging" }] : /* istanbul ignore next */ []));
|
|
152
|
+
/**
|
|
153
|
+
* Whether any completed (non-cancelled) drag has occurred in this engine's lifetime.
|
|
154
|
+
*
|
|
155
|
+
* Used by `push` mode to defer resolving `fr`/`%` → `px` until the first drag.
|
|
156
|
+
* Before the first drag, original units are preserved so CSS grid can distribute
|
|
157
|
+
* space without rounding-induced overflow.
|
|
158
|
+
*/
|
|
159
|
+
hasBeenResized = signal(false, ...(ngDevMode ? [{ debugName: "hasBeenResized" }] : /* istanbul ignore next */ []));
|
|
160
|
+
/**
|
|
161
|
+
* CSS grid template string with item sizes interleaved with gap sizes.
|
|
162
|
+
*
|
|
163
|
+
* Example output: `"100px 4px minmax(50px, 2fr) 4px minmax(50px, 1fr)"`.
|
|
164
|
+
*
|
|
165
|
+
* **Output strategy per distribution mode:**
|
|
166
|
+
* - `adjacent` — resolves all sizes to `px`. CSS grid cannot constrain adjacent
|
|
167
|
+
* resizing correctly with `fr` units.
|
|
168
|
+
* - `proportional` — keeps `fr`/`%` as-is, wrapped in `minmax(floor, size)` when
|
|
169
|
+
* {@link minItemSizePx} > 0. This lets CSS grid redistribute remaining space
|
|
170
|
+
* while enforcing the minimum floor natively. Locked (`px`) columns pass through.
|
|
171
|
+
* - `push` — keeps original units until the first completed drag, then resolves
|
|
172
|
+
* everything to `px` so the total can exceed the container and trigger scrolling.
|
|
173
|
+
*/
|
|
174
|
+
gridTemplateSizes = computed(() => {
|
|
175
|
+
const items = this.items();
|
|
176
|
+
const gaps = this.gapSizes();
|
|
177
|
+
if (items.length === 0)
|
|
178
|
+
return 'none';
|
|
179
|
+
const containerSize = this.containerSize();
|
|
180
|
+
const constrained = this.containerConstrained();
|
|
181
|
+
const mode = this.distributionMode();
|
|
182
|
+
// Resolve strategy:
|
|
183
|
+
// - adjacent (constrained): resolve ALL to px — CSS grid can't constrain adjacent resizing with fr.
|
|
184
|
+
// - push (unconstrained): keep original units until first movement bakes to px, then resolve for scrolling.
|
|
185
|
+
// - proportional: NEVER resolve fr→px. Use minmax(floor, size) so CSS grid handles min widths
|
|
186
|
+
// natively, both during and after drag. This allows columns that still have room to shrink
|
|
187
|
+
// while already-at-minimum columns stay at the floor.
|
|
188
|
+
const shouldResolve = containerSize > 0 &&
|
|
189
|
+
((constrained && mode === 'adjacent') || (!constrained && this.hasBeenResized()));
|
|
190
|
+
const useMinmax = mode === 'proportional' && this.minItemSizePx > 0;
|
|
191
|
+
const frFactors = shouldResolve ? this.getCurrentFractionFactors() : null;
|
|
192
|
+
const result = [];
|
|
193
|
+
for (let i = 0; i < items.length; i++) {
|
|
194
|
+
const size = items[i].size();
|
|
195
|
+
const expanded = expandResizeSize(size);
|
|
196
|
+
if (shouldResolve && expanded.unit !== 'px') {
|
|
197
|
+
result.push(`${resolveSizeToPx(expanded, frFactors.pxPerFr, containerSize)}px`);
|
|
198
|
+
}
|
|
199
|
+
else if (useMinmax && expanded.unit !== 'px') {
|
|
200
|
+
result.push(`minmax(${this.minItemSizePx}px, ${size})`);
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
result.push(size);
|
|
204
|
+
}
|
|
205
|
+
if (i < gaps.length) {
|
|
206
|
+
result.push(`${gaps[i] || 0}px`);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return result.join(' ');
|
|
210
|
+
}, ...(ngDevMode ? [{ debugName: "gridTemplateSizes" }] : /* istanbul ignore next */ []));
|
|
211
|
+
/**
|
|
212
|
+
* The total gap size in pixels.
|
|
213
|
+
*/
|
|
214
|
+
totalGapSize = computed(() => this.gapSizes().reduce((acc, size) => acc + size, 0), ...(ngDevMode ? [{ debugName: "totalGapSize" }] : /* istanbul ignore next */ []));
|
|
215
|
+
/**
|
|
216
|
+
* Aggregated item sizes by unit.
|
|
217
|
+
*/
|
|
218
|
+
totalItemSizes = computed(() => this.items().reduce((acc, item) => {
|
|
219
|
+
const { unit, value } = expandResizeSize(item.size());
|
|
220
|
+
acc[unit] += value;
|
|
221
|
+
return acc;
|
|
222
|
+
}, { px: 0, fr: 0, '%': 0 }), ...(ngDevMode ? [{ debugName: "totalItemSizes" }] : /* istanbul ignore next */ []));
|
|
223
|
+
/**
|
|
224
|
+
* Minimum total size of all items combined (as a CSS calc expression).
|
|
225
|
+
*/
|
|
226
|
+
minTotalSize = computed(() => this.computeLimitTotalSize('minSize'), ...(ngDevMode ? [{ debugName: "minTotalSize" }] : /* istanbul ignore next */ []));
|
|
227
|
+
/**
|
|
228
|
+
* Maximum total size of all items combined (as a CSS calc expression).
|
|
229
|
+
*/
|
|
230
|
+
maxTotalSize = computed(() => this.computeLimitTotalSize('maxSize'), ...(ngDevMode ? [{ debugName: "maxTotalSize" }] : /* istanbul ignore next */ []));
|
|
231
|
+
// --- Drag operations ---
|
|
232
|
+
/**
|
|
233
|
+
* Begins a drag at the given divider. Original sizes are saved for reverting
|
|
234
|
+
* on no-op clicks or cancellation. In push mode, baking to `px` is deferred
|
|
235
|
+
* to the first {@link drag} call to avoid a visual shift on mousedown.
|
|
236
|
+
*/
|
|
237
|
+
startDrag(dividerIndex, startPositionPx) {
|
|
238
|
+
const items = this.items();
|
|
239
|
+
if (dividerIndex < 0 || items.length < 2 || dividerIndex >= items.length)
|
|
240
|
+
return;
|
|
241
|
+
const preBakeSizes = items.map(item => item.size());
|
|
242
|
+
this.dragContext.set({
|
|
243
|
+
dividerIndex,
|
|
244
|
+
startPosition: startPositionPx,
|
|
245
|
+
preBakeSizes,
|
|
246
|
+
items: items.map(item => this.createContextItem(item)),
|
|
247
|
+
fractionFactors: this.getCurrentFractionFactors(),
|
|
248
|
+
percentPerPx: this.getCurrentPercentPerPx(),
|
|
249
|
+
baked: this.containerConstrained(),
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
/** Updates item sizes during an active drag based on the current pointer position. */
|
|
253
|
+
drag(dividerIndex, currentPositionPx) {
|
|
254
|
+
const ctx = this.dragContext();
|
|
255
|
+
if (!ctx || ctx.dividerIndex !== dividerIndex)
|
|
256
|
+
return;
|
|
257
|
+
// In push mode, bake all items to px on the first movement so non-dragged
|
|
258
|
+
// items keep their absolute widths. Deferred from startDrag to avoid a
|
|
259
|
+
// visual column shift on mousedown (CSS Grid fr→px rounding mismatch).
|
|
260
|
+
if (!ctx.baked) {
|
|
261
|
+
this.bakeAllItemsToPx();
|
|
262
|
+
ctx.items = this.items().map(item => this.createContextItem(item));
|
|
263
|
+
ctx.fractionFactors = this.getCurrentFractionFactors();
|
|
264
|
+
ctx.percentPerPx = this.getCurrentPercentPerPx();
|
|
265
|
+
ctx.baked = true;
|
|
266
|
+
}
|
|
267
|
+
const pxDelta = currentPositionPx - ctx.startPosition;
|
|
268
|
+
this.applyDelta(dividerIndex, pxDelta, ctx.items, ctx.fractionFactors, ctx.percentPerPx);
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Ends a drag. If cancelled or no movement occurred, sizes revert to their
|
|
272
|
+
* pre-drag values (including undoing any push-mode baking). Otherwise,
|
|
273
|
+
* post-drag finalization runs (commit mode or proportional locking).
|
|
274
|
+
*/
|
|
275
|
+
endDrag(dividerIndex, cancel) {
|
|
276
|
+
const ctx = this.dragContext();
|
|
277
|
+
if (!ctx || ctx.dividerIndex !== dividerIndex)
|
|
278
|
+
return;
|
|
279
|
+
const hasMoved = ctx.items.some(ci => {
|
|
280
|
+
const current = expandResizeSize(ci.item.size());
|
|
281
|
+
return current.value !== ci.startSize.value || current.unit !== ci.startSize.unit;
|
|
282
|
+
});
|
|
283
|
+
if (cancel || !hasMoved) {
|
|
284
|
+
// Reset to pre-bake sizes (restores original fr/% units on no-op clicks)
|
|
285
|
+
ctx.items.forEach((ci, i) => ci.item.size.set(ctx.preBakeSizes[i]));
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
this.finalizeResize(ctx);
|
|
289
|
+
this.hasBeenResized.set(true);
|
|
290
|
+
}
|
|
291
|
+
this.dragContext.set(null);
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Applies a single instantaneous move (e.g. keyboard step) at the given divider.
|
|
295
|
+
* Requires that the relevant items already have engine-calculated sizes.
|
|
296
|
+
*/
|
|
297
|
+
moveDivider(dividerIndex, pxDelta) {
|
|
298
|
+
const items = this.items();
|
|
299
|
+
if (dividerIndex < 0 || items.length < 2 || dividerIndex >= items.length)
|
|
300
|
+
return;
|
|
301
|
+
// Check that relevant items have calculated sizes
|
|
302
|
+
if (!this.isItemSizeCalculated(items[dividerIndex]))
|
|
303
|
+
return;
|
|
304
|
+
if (dividerIndex < items.length - 1 && !this.isItemSizeCalculated(items[dividerIndex + 1]))
|
|
305
|
+
return;
|
|
306
|
+
const contextItems = items.map(item => this.createContextItem(item));
|
|
307
|
+
this.applyDelta(dividerIndex, pxDelta, contextItems, this.getCurrentFractionFactors(), this.getCurrentPercentPerPx());
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Clamps all items to their min/max constraints, respecting {@link minItemSizePx}.
|
|
311
|
+
*
|
|
312
|
+
* Called automatically via `afterRenderEffect` when item sizes change externally
|
|
313
|
+
* or the container resizes. Skipped during an active drag (sizes are managed
|
|
314
|
+
* by the drag handler). For `fr`-sized items, clamping is done iteratively
|
|
315
|
+
* with redistribution to maintain total fraction balance.
|
|
316
|
+
*/
|
|
317
|
+
ensureMinMaxSizes() {
|
|
318
|
+
const items = this.items();
|
|
319
|
+
if (items.length === 0)
|
|
320
|
+
return;
|
|
321
|
+
const containerSize = this.containerSize();
|
|
322
|
+
const itemSizes = items.map(item => {
|
|
323
|
+
const expanded = expandResizeSize(item.size());
|
|
324
|
+
return {
|
|
325
|
+
item,
|
|
326
|
+
size: { unit: expanded.unit, value: expanded.value },
|
|
327
|
+
minSizePx: Math.max(this.minItemSizePx, getResizeLimitInPx(item.minSize(), containerSize)),
|
|
328
|
+
maxSizePx: getResizeLimitInPx(item.maxSize(), containerSize),
|
|
329
|
+
};
|
|
330
|
+
});
|
|
331
|
+
// Clamp px and % items
|
|
332
|
+
for (const entry of itemSizes) {
|
|
333
|
+
if (entry.size.unit === 'px') {
|
|
334
|
+
entry.size.value = clamp(entry.size.value, entry.minSizePx, entry.maxSizePx);
|
|
335
|
+
}
|
|
336
|
+
else if (entry.size.unit === '%') {
|
|
337
|
+
const pxValue = (entry.size.value / 100) * containerSize;
|
|
338
|
+
if (pxValue < entry.minSizePx) {
|
|
339
|
+
entry.size.value = (entry.minSizePx / containerSize) * 100;
|
|
340
|
+
}
|
|
341
|
+
else if (pxValue > entry.maxSizePx) {
|
|
342
|
+
entry.size.value = (entry.maxSizePx / containerSize) * 100;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
// Calculate fraction factors for fr-sized items
|
|
347
|
+
const totalPx = itemSizes.reduce((acc, { size }) => (size.unit === 'px' ? acc + size.value : acc), 0);
|
|
348
|
+
const totalPercent = itemSizes.reduce((acc, { size }) => (size.unit === '%' ? acc + size.value : acc), 0);
|
|
349
|
+
const totalFr = itemSizes.reduce((acc, { size }) => (size.unit === 'fr' ? acc + size.value : acc), 0);
|
|
350
|
+
const frArea = containerSize - this.totalGapSize() - totalPx - (totalPercent / 100) * containerSize;
|
|
351
|
+
const frPerPx = totalFr / (frArea || 1);
|
|
352
|
+
const pxPerFr = (frArea || 1) / (totalFr || 1);
|
|
353
|
+
// Iteratively clamp fr-sized items and redistribute
|
|
354
|
+
let frPanelsWithoutClamping = itemSizes.filter(p => p.size.unit === 'fr');
|
|
355
|
+
let frToDistribute = undefined;
|
|
356
|
+
while (frPanelsWithoutClamping.length > 0 && frToDistribute !== 0) {
|
|
357
|
+
const frToAddPerPanel = frToDistribute ? frToDistribute / frPanelsWithoutClamping.length : 0;
|
|
358
|
+
const next = [];
|
|
359
|
+
let currentTotalFrSize = totalFr;
|
|
360
|
+
for (const p of frPanelsWithoutClamping) {
|
|
361
|
+
const minSizeFr = p.minSizePx * frPerPx;
|
|
362
|
+
const maxSizeFr = p.maxSizePx * frPerPx;
|
|
363
|
+
p.size.value += frToAddPerPanel;
|
|
364
|
+
if (p.size.value < minSizeFr) {
|
|
365
|
+
currentTotalFrSize = currentTotalFrSize - p.size.value + minSizeFr;
|
|
366
|
+
p.size.value = minSizeFr;
|
|
367
|
+
}
|
|
368
|
+
else if (p.size.value > maxSizeFr) {
|
|
369
|
+
currentTotalFrSize = currentTotalFrSize - p.size.value + maxSizeFr;
|
|
370
|
+
p.size.value = maxSizeFr;
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
373
|
+
next.push(p);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
frToDistribute = totalFr - currentTotalFrSize;
|
|
377
|
+
if (Math.abs(frToDistribute * pxPerFr) < 1) {
|
|
378
|
+
frToDistribute = 0;
|
|
379
|
+
}
|
|
380
|
+
frPanelsWithoutClamping = next;
|
|
381
|
+
}
|
|
382
|
+
// Write back
|
|
383
|
+
for (const { item, size } of itemSizes) {
|
|
384
|
+
this.setItemSize(item, `${size.value}${size.unit}`);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
// --- Item size tracking ---
|
|
388
|
+
/**
|
|
389
|
+
* Sets the item's size and marks it as engine-calculated via an internal symbol.
|
|
390
|
+
* This mark is used by {@link isItemSizeCalculated} to detect external size changes.
|
|
391
|
+
*/
|
|
392
|
+
setItemSize(item, size) {
|
|
393
|
+
item.size.set(size);
|
|
394
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
395
|
+
item[LAST_CALC_SIZE_SYMBOL] = size;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Returns `true` if the item's current size matches the last value written by the engine.
|
|
399
|
+
* Returns `false` if the size was changed externally (e.g. by an input binding or state restore).
|
|
400
|
+
*/
|
|
401
|
+
isItemSizeCalculated(item) {
|
|
402
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
403
|
+
return item[LAST_CALC_SIZE_SYMBOL] === item.size();
|
|
404
|
+
}
|
|
405
|
+
// --- Private: delta application ---
|
|
406
|
+
/**
|
|
407
|
+
* Routes a px delta to the appropriate distribution strategy.
|
|
408
|
+
*
|
|
409
|
+
* For last-item edge resizing (dividerIndex === items.length - 1), the delta is
|
|
410
|
+
* remapped to the previous divider with negated direction. This allows the last
|
|
411
|
+
* column's handle in push mode to resize it directly.
|
|
412
|
+
*/
|
|
413
|
+
applyDelta(dividerIndex, pxDelta, items, fractionFactors, percentPerPx) {
|
|
414
|
+
const mode = this.distributionMode();
|
|
415
|
+
// Right-edge resize of the last item: remap to the previous divider with negated delta.
|
|
416
|
+
const isLastItemEdge = dividerIndex === items.length - 1;
|
|
417
|
+
const effectiveDividerIndex = isLastItemEdge ? dividerIndex - 1 : dividerIndex;
|
|
418
|
+
const effectiveDelta = isLastItemEdge ? -pxDelta : pxDelta;
|
|
419
|
+
if (mode === 'push' && !this.containerConstrained()) {
|
|
420
|
+
this.applyPushDelta(dividerIndex, pxDelta, items, fractionFactors, percentPerPx);
|
|
421
|
+
}
|
|
422
|
+
else if (mode === 'proportional') {
|
|
423
|
+
this.applyProportionalDelta(effectiveDividerIndex, effectiveDelta, items, fractionFactors);
|
|
424
|
+
}
|
|
425
|
+
else {
|
|
426
|
+
this.applyAdjacentDelta(effectiveDividerIndex, effectiveDelta, items, fractionFactors, percentPerPx);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Adjacent mode: transfers the delta between the two items neighbouring the divider.
|
|
431
|
+
*
|
|
432
|
+
* Grows the left item and shrinks the right item (or vice versa). When an item
|
|
433
|
+
* hits its min/max constraint, the unapplied remainder cascades to the next item
|
|
434
|
+
* in that direction. A second pass resolves any asymmetry between left and right.
|
|
435
|
+
* The total container width is always preserved (zero-sum).
|
|
436
|
+
*/
|
|
437
|
+
applyAdjacentDelta(dividerIndex, pxDelta, items, fractionFactors, percentPerPx) {
|
|
438
|
+
const containerSize = this.containerSize();
|
|
439
|
+
const appliedPanelDeltas = Array(items.length).fill(0);
|
|
440
|
+
const recursion = (pxDelta, itemIndex, itemIndexIncrement) => {
|
|
441
|
+
if (itemIndex >= items.length || itemIndex < 0)
|
|
442
|
+
return 0;
|
|
443
|
+
const ci = items[itemIndex];
|
|
444
|
+
const startPx = resolveSizeToPx(ci.startSize, fractionFactors.pxPerFr, containerSize);
|
|
445
|
+
const newPx = startPx + pxDelta;
|
|
446
|
+
const limitPx = getLimitPxForDelta(ci, pxDelta, containerSize, this.minItemSizePx);
|
|
447
|
+
const unappliedDelta = pxDelta < 0
|
|
448
|
+
? limitPx > newPx
|
|
449
|
+
? -(limitPx - newPx)
|
|
450
|
+
: 0
|
|
451
|
+
: limitPx < newPx
|
|
452
|
+
? newPx - limitPx
|
|
453
|
+
: 0;
|
|
454
|
+
const appliedDelta = pxDelta - unappliedDelta;
|
|
455
|
+
appliedPanelDeltas[itemIndex] = appliedDelta;
|
|
456
|
+
return unappliedDelta === 0
|
|
457
|
+
? pxDelta
|
|
458
|
+
: appliedDelta +
|
|
459
|
+
recursion(unappliedDelta, itemIndex + itemIndexIncrement, itemIndexIncrement);
|
|
460
|
+
};
|
|
461
|
+
let appliedLeft = recursion(pxDelta, dividerIndex, -1);
|
|
462
|
+
let appliedRight = -recursion(-pxDelta, dividerIndex + 1, 1);
|
|
463
|
+
if (appliedLeft !== pxDelta || appliedRight !== pxDelta) {
|
|
464
|
+
const resolvedDelta = pxDelta < 0 ? Math.max(appliedLeft, appliedRight) : Math.min(appliedLeft, appliedRight);
|
|
465
|
+
appliedPanelDeltas.fill(0);
|
|
466
|
+
appliedLeft = recursion(resolvedDelta, dividerIndex, -1);
|
|
467
|
+
appliedRight = -recursion(-resolvedDelta, dividerIndex + 1, 1);
|
|
468
|
+
if (appliedLeft !== resolvedDelta || appliedRight !== resolvedDelta) {
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
this.commitItemDeltas(items, appliedPanelDeltas, fractionFactors, percentPerPx);
|
|
473
|
+
}
|
|
474
|
+
/**
|
|
475
|
+
* Proportional mode: only the item at `dividerIndex` changes size (set to absolute `px`).
|
|
476
|
+
* All other items keep their original units (`fr`, `%`), and CSS grid's `minmax(floor, size)`
|
|
477
|
+
* naturally redistributes the remaining space — columns with room shrink while those
|
|
478
|
+
* already at the floor stay put.
|
|
479
|
+
*
|
|
480
|
+
* Growth is capped so the total never overflows the container: each other `fr` column
|
|
481
|
+
* needs at least {@link minItemSizePx}, and locked `px` columns keep their size.
|
|
482
|
+
*
|
|
483
|
+
* After the drag ends, {@link applyProportionalLocking} determines whether the
|
|
484
|
+
* resized column stays as `px` (locked) or is converted back to `fr` (dynamic).
|
|
485
|
+
*/
|
|
486
|
+
applyProportionalDelta(dividerIndex, pxDelta, items, fractionFactors) {
|
|
487
|
+
const containerSize = this.containerSize();
|
|
488
|
+
const floor = this.minItemSizePx;
|
|
489
|
+
const item = items[dividerIndex];
|
|
490
|
+
const startPx = resolveSizeToPx(item.startSize, fractionFactors.pxPerFr, containerSize);
|
|
491
|
+
// Clamp to own min/max
|
|
492
|
+
let newPx = clampToLimits(startPx + pxDelta, item, containerSize, floor);
|
|
493
|
+
// Cap so the total doesn't overflow. With minmax(floor, Xfr), each other
|
|
494
|
+
// column needs at least `floor` px. Locked px columns keep their size.
|
|
495
|
+
if (floor > 0) {
|
|
496
|
+
const totalGaps = this.totalGapSize();
|
|
497
|
+
let otherLockedPx = 0;
|
|
498
|
+
let otherFrCount = 0;
|
|
499
|
+
for (let i = 0; i < items.length; i++) {
|
|
500
|
+
if (i === dividerIndex)
|
|
501
|
+
continue;
|
|
502
|
+
const { unit, value } = expandResizeSize(items[i].item.size());
|
|
503
|
+
if (unit === 'px') {
|
|
504
|
+
otherLockedPx += value;
|
|
505
|
+
}
|
|
506
|
+
else {
|
|
507
|
+
otherFrCount++;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
newPx = Math.min(newPx, containerSize - totalGaps - otherLockedPx - otherFrCount * floor);
|
|
511
|
+
}
|
|
512
|
+
this.setItemSize(item.item, `${Math.max(0, newPx)}px`);
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Push mode: only the dragged item changes size. All other items stay at their
|
|
516
|
+
* baked `px` values (set during {@link startDrag}). The container total changes,
|
|
517
|
+
* causing horizontal overflow/scrolling. Only valid when `containerConstrained` is `false`.
|
|
518
|
+
*/
|
|
519
|
+
applyPushDelta(dividerIndex, pxDelta, items, fractionFactors, percentPerPx) {
|
|
520
|
+
const containerSize = this.containerSize();
|
|
521
|
+
const appliedPanelDeltas = Array(items.length).fill(0);
|
|
522
|
+
const item = items[dividerIndex];
|
|
523
|
+
const startPx = resolveSizeToPx(item.startSize, fractionFactors.pxPerFr, containerSize);
|
|
524
|
+
appliedPanelDeltas[dividerIndex] =
|
|
525
|
+
clampToLimits(startPx + pxDelta, item, containerSize, this.minItemSizePx) - startPx;
|
|
526
|
+
this.commitItemDeltas(items, appliedPanelDeltas, fractionFactors, percentPerPx);
|
|
527
|
+
}
|
|
528
|
+
// --- Private: post-drag finalization ---
|
|
529
|
+
/**
|
|
530
|
+
* Post-drag finalization. Behaviour depends on {@link lockSizes} and the distribution mode.
|
|
531
|
+
*
|
|
532
|
+
* When `lockSizes` is `false`:
|
|
533
|
+
* - `adjacent` / `push` — no-op; items keep their original units.
|
|
534
|
+
* - `proportional` — the resized column is converted back to `fr` so it stays dynamic.
|
|
535
|
+
*
|
|
536
|
+
* When `lockSizes` is `true`:
|
|
537
|
+
* - `adjacent` / `push` — items whose size changed are converted to absolute `px`.
|
|
538
|
+
* - `proportional` — no-op; the resized column is already `px` from the drag.
|
|
539
|
+
*/
|
|
540
|
+
finalizeResize(ctx) {
|
|
541
|
+
const lock = this.lockSizes();
|
|
542
|
+
if (this.distributionMode() === 'proportional') {
|
|
543
|
+
if (!lock)
|
|
544
|
+
this.unlockProportionalColumn(ctx);
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
// Adjacent / push: lock affected items to px when enabled
|
|
548
|
+
if (!lock)
|
|
549
|
+
return;
|
|
550
|
+
const containerSize = this.containerSize();
|
|
551
|
+
const fractionFactors = this.getCurrentFractionFactors();
|
|
552
|
+
for (const ci of ctx.items) {
|
|
553
|
+
const currentSize = expandResizeSize(ci.item.size());
|
|
554
|
+
const sizeChanged = currentSize.value !== ci.startSize.value || currentSize.unit !== ci.startSize.unit;
|
|
555
|
+
if (sizeChanged) {
|
|
556
|
+
const pxValue = resolveSizeToPx(currentSize, fractionFactors.pxPerFr, containerSize);
|
|
557
|
+
this.setItemSize(ci.item, `${Math.max(0, pxValue)}px`);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Converts the resized column back to `fr` after a proportional drag so it
|
|
563
|
+
* continues to flex with the container. Computes a new `fr` value that would
|
|
564
|
+
* resolve to the same pixel width given the current container and other `fr` columns.
|
|
565
|
+
*/
|
|
566
|
+
unlockProportionalColumn(ctx) {
|
|
567
|
+
const items = ctx.items;
|
|
568
|
+
const containerSize = this.containerSize();
|
|
569
|
+
const resizedItem = items[ctx.dividerIndex];
|
|
570
|
+
const resizedPx = expandResizeSize(resizedItem.item.size()).value;
|
|
571
|
+
// Sum up all other fr values (from pre-bake, since they weren't changed)
|
|
572
|
+
let otherFrTotal = 0;
|
|
573
|
+
let otherPxTotal = 0;
|
|
574
|
+
for (let i = 0; i < items.length; i++) {
|
|
575
|
+
if (i === ctx.dividerIndex)
|
|
576
|
+
continue;
|
|
577
|
+
const preBake = expandResizeSize(ctx.preBakeSizes[i]);
|
|
578
|
+
if (preBake.unit === 'fr') {
|
|
579
|
+
otherFrTotal += preBake.value;
|
|
580
|
+
}
|
|
581
|
+
else if (preBake.unit === 'px') {
|
|
582
|
+
otherPxTotal += preBake.value;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
const availableForFr = containerSize - this.totalGapSize() - otherPxTotal;
|
|
586
|
+
if (otherFrTotal > 0 && availableForFr > resizedPx) {
|
|
587
|
+
// Solve: newFr / otherFrTotal = resizedPx / (availableForFr - resizedPx)
|
|
588
|
+
const newFr = (resizedPx * otherFrTotal) / (availableForFr - resizedPx);
|
|
589
|
+
this.setItemSize(resizedItem.item, `${Math.max(0, +newFr.toFixed(4))}fr`);
|
|
590
|
+
}
|
|
591
|
+
// If we can't compute a valid fr (edge case), leave as px
|
|
592
|
+
}
|
|
593
|
+
// --- Private: helpers ---
|
|
594
|
+
createContextItem(item) {
|
|
595
|
+
return {
|
|
596
|
+
item,
|
|
597
|
+
startSize: expandResizeSize(item.size()),
|
|
598
|
+
minSize: expandResizeLimit(item.minSize()),
|
|
599
|
+
maxSize: expandResizeLimit(item.maxSize()),
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
getCurrentFractionFactors() {
|
|
603
|
+
const totals = this.totalItemSizes();
|
|
604
|
+
const cs = this.containerSize();
|
|
605
|
+
const percentPx = (totals['%'] / 100) * cs;
|
|
606
|
+
const frArea = cs - this.totalGapSize() - totals.px - percentPx || 1;
|
|
607
|
+
const totalFr = totals.fr || 1;
|
|
608
|
+
return {
|
|
609
|
+
frPerPx: totalFr / frArea,
|
|
610
|
+
pxPerFr: frArea / totalFr,
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
getCurrentPercentPerPx() {
|
|
614
|
+
return 100 / (this.containerSize() || 1);
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* Bakes all non-px items to absolute px values. Used by push mode on first drag movement.
|
|
618
|
+
* Prefers DOM-measured sizes (via {@link resolveItemSizes}) over JS-computed conversions
|
|
619
|
+
* to avoid sub-pixel mismatches with CSS Grid's internal track sizing.
|
|
620
|
+
*/
|
|
621
|
+
bakeAllItemsToPx() {
|
|
622
|
+
const items = this.items();
|
|
623
|
+
const measured = this.resolveItemSizes?.();
|
|
624
|
+
if (measured && measured.length === items.length) {
|
|
625
|
+
for (let i = 0; i < items.length; i++) {
|
|
626
|
+
this.setItemSize(items[i], `${measured[i]}px`);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
else {
|
|
630
|
+
const frFactors = this.getCurrentFractionFactors();
|
|
631
|
+
const containerSize = this.containerSize();
|
|
632
|
+
for (const item of items) {
|
|
633
|
+
const size = expandResizeSize(item.size());
|
|
634
|
+
if (size.unit !== 'px') {
|
|
635
|
+
this.setItemSize(item, `${resolveSizeToPx(size, frFactors.pxPerFr, containerSize)}px`);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* Writes computed px deltas back to items, converting to each item's original unit.
|
|
642
|
+
*/
|
|
643
|
+
commitItemDeltas(items, appliedPanelDeltas, fractionFactors, percentPerPx) {
|
|
644
|
+
items.forEach((ci, i) => {
|
|
645
|
+
const pxDelta = appliedPanelDeltas[i] || 0;
|
|
646
|
+
const unitDelta = pxDeltaToUnitDelta(pxDelta, ci.startSize.unit, fractionFactors.frPerPx, percentPerPx);
|
|
647
|
+
const newValue = ci.startSize.value + unitDelta;
|
|
648
|
+
this.setItemSize(ci.item, `${Math.max(0, newValue)}${ci.startSize.unit}`);
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* Builds a CSS `calc()` expression summing all items' min or max limits.
|
|
653
|
+
* Items already in `px` contribute their current size; `fr`/`%` items contribute
|
|
654
|
+
* their `minSize`/`maxSize` limit. Used by {@link minTotalSize} and {@link maxTotalSize}.
|
|
655
|
+
*/
|
|
656
|
+
computeLimitTotalSize(limitProp) {
|
|
657
|
+
const { px, '%': pc } = this.items().reduce((acc, item) => {
|
|
658
|
+
const { unit, value } = expandResizeSize(item.size());
|
|
659
|
+
if (unit === 'px') {
|
|
660
|
+
acc.px += value;
|
|
661
|
+
}
|
|
662
|
+
else {
|
|
663
|
+
const limitStr = item[limitProp]();
|
|
664
|
+
acc[getResizeLimitUnit(limitStr)] += getResizeLimitValue(limitStr);
|
|
665
|
+
}
|
|
666
|
+
return acc;
|
|
667
|
+
}, { px: 0, '%': 0 });
|
|
668
|
+
return `calc(${px + this.totalGapSize()}px + ${pc}%)`;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
// --- Module-level helpers ---
|
|
672
|
+
/** Clamps a value between min and max. */
|
|
673
|
+
function clamp(value, min, max) {
|
|
674
|
+
return Math.max(min, Math.min(max, value));
|
|
675
|
+
}
|
|
676
|
+
/** Resolves an expanded limit to px. */
|
|
677
|
+
function limitToPx(limit, containerSize) {
|
|
678
|
+
return limit.unit === 'px' ? limit.value : (limit.value / 100) * containerSize;
|
|
679
|
+
}
|
|
680
|
+
/**
|
|
681
|
+
* Resolves a min limit to px, enforcing the given absolute floor.
|
|
682
|
+
* Even if a relative limit (e.g. `5%`) resolves to less than the floor, the floor wins.
|
|
683
|
+
*/
|
|
684
|
+
function minLimitToPx(limit, containerSize, floorPx) {
|
|
685
|
+
return Math.max(floorPx, limitToPx(limit, containerSize));
|
|
686
|
+
}
|
|
687
|
+
/** Clamps a px value to the item's min/max limits (with floor on min). */
|
|
688
|
+
function clampToLimits(px, ci, containerSize, floorPx) {
|
|
689
|
+
return clamp(px, minLimitToPx(ci.minSize, containerSize, floorPx), limitToPx(ci.maxSize, containerSize));
|
|
690
|
+
}
|
|
691
|
+
/**
|
|
692
|
+
* Returns the relevant limit (min or max) in px for the direction of a delta.
|
|
693
|
+
* Negative delta → min limit (with floor), positive delta → max limit.
|
|
694
|
+
*/
|
|
695
|
+
function getLimitPxForDelta(ci, pxDelta, containerSize, floorPx) {
|
|
696
|
+
return pxDelta < 0
|
|
697
|
+
? minLimitToPx(ci.minSize, containerSize, floorPx)
|
|
698
|
+
: limitToPx(ci.maxSize, containerSize);
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* Generated bundle index. Do not edit.
|
|
703
|
+
*/
|
|
704
|
+
|
|
705
|
+
export { ResizeEngine, collapseResizeLimit, collapseResizeSize, expandResizeLimit, expandResizeSize, getResizeLimitInPx, getResizeLimitUnit, getResizeLimitValue, getResizeSizeUnit, getResizeSizeValue, isResizeLimit, isResizeSize, pxDeltaToUnitDelta, resolveSizeToPx };
|
|
706
|
+
//# sourceMappingURL=ngneers-controls-api-resize.mjs.map
|