uicore-ts 1.1.388 → 1.1.390

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.
@@ -2,6 +2,24 @@ import { UIObject } from "./UIObject";
2
2
  import { UIPoint } from "./UIPoint";
3
3
  import { UIView } from "./UIView";
4
4
  export type SizeNumberOrFunctionOrView = number | ((constrainingOrthogonalSize: number) => number) | UIView;
5
+ /** A position along an axis (0 = start, 0.5 = centered, 1 = end), or "stretch" to fill the available space instead. */
6
+ export type UIRectanglePositionOrStretch = number | "stretch";
7
+ export interface UIRectangleFlowLayoutOptions {
8
+ /** Horizontal spacing between views on the same row. Defaults to 0. */
9
+ itemGap?: number;
10
+ /** Vertical spacing between wrapped rows. Defaults to 0. */
11
+ lineGap?: number;
12
+ /** Caps how many views a row may hold before wrapping, even if more would fit by width. Defaults to unlimited. */
13
+ maxViewsPerRow?: number;
14
+ /** Position of a row within this rectangle's width when that row holds more than one view. Defaults to 0 (left). */
15
+ centeredOnPosition?: number;
16
+ /**
17
+ * Position (or "stretch" to fill the row) of a view that wrapping isolated onto a row of its
18
+ * own - never consulted for a view still sharing a row with another. A single value broadcasts
19
+ * to every isolated view; an array is matched by index against `views`. Defaults to 0 (left).
20
+ */
21
+ positionOrStretchWhenIsolatedOnOwnWrappedRow?: UIRectanglePositionOrStretch | UIRectanglePositionOrStretch[];
22
+ }
5
23
  export type UIGroupingWrapperFrameConfiguration = {
6
24
  /** Stable identity used to reuse the same wrapper when surrounding conditional layout changes. */
7
25
  identifier?: string;
@@ -154,6 +172,25 @@ export declare class UIRectangle extends UIObject {
154
172
  * @returns Array of rectangles representing the frame for each view
155
173
  */
156
174
  framesByDistributingViewsAsRow(views: UIView[], paddings?: SizeNumberOrFunctionOrView | SizeNumberOrFunctionOrView[], absoluteWidths?: SizeNumberOrFunctionOrView | SizeNumberOrFunctionOrView[], centeredOnPosition?: number): UIRectangle[];
175
+ /**
176
+ * Flows views left-to-right at their preferred widths, wrapping to a new row below this
177
+ * rectangle whenever the next view no longer fits on the current row - the same idea as HTML
178
+ * inline/flow layout or a UICollectionView flow layout. Rows are packed greedily: each row
179
+ * holds as many views as actually fit before wrapping (up to `options.maxViewsPerRow`, if
180
+ * given), so this degenerates to a single row when everything fits, and to one view per row
181
+ * when nothing does.
182
+ * @param views - Array of views to distribute, in flow order
183
+ * @param preferredWidths - Preferred width for each view, matched by index
184
+ * @param itemHeight - Height applied to every row
185
+ * @param options - Wrapping and alignment settings, all optional
186
+ * @param options.itemGap - Horizontal spacing between views on the same row
187
+ * @param options.lineGap - Vertical spacing between wrapped rows
188
+ * @param options.maxViewsPerRow - Caps views per row even if more would fit by width
189
+ * @param options.centeredOnPosition - Position of a row holding more than one view
190
+ * @param options.positionOrStretchWhenIsolatedOnOwnWrappedRow - Position or stretch for a view wrapping isolated alone
191
+ * @returns Array of rectangles representing the frame for each view, matching `views`' order
192
+ */
193
+ framesByFlowingViewsAlongWidth(views: UIView[], preferredWidths: number[], itemHeight: SizeNumberOrFunctionOrView, options?: UIRectangleFlowLayoutOptions): UIRectangle[];
157
194
  /**
158
195
  * Distributes views as a grid (2D array), assigning frames and returning them.
159
196
  * The first index represents rows (vertical), the second index represents columns (horizontal).
@@ -671,6 +671,67 @@ const _UIRectangle = class extends import_UIObject.UIObject {
671
671
  frames.forEach((frame, index) => _UIRectangle._assignFrameToView(frame, views[index]));
672
672
  return frames;
673
673
  }
674
+ framesByFlowingViewsAlongWidth(views, preferredWidths, itemHeight, options = {}) {
675
+ const {
676
+ itemGap = 0,
677
+ lineGap = 0,
678
+ maxViewsPerRow = Infinity,
679
+ centeredOnPosition = 0,
680
+ positionOrStretchWhenIsolatedOnOwnWrappedRow = 0
681
+ } = options;
682
+ const heightNumber = this._heightNumberFromSizeNumberOrFunctionOrView(itemHeight);
683
+ const rowsOfIndices = [];
684
+ let currentRow = [];
685
+ let currentRowWidth = 0;
686
+ views.forEach((_view, index) => {
687
+ const width = preferredWidths[index];
688
+ const widthIfAdded = currentRow.length === 0 ? width : currentRowWidth + itemGap + width;
689
+ const overflowsWidth = currentRow.length > 0 && widthIfAdded > this.width;
690
+ const overflowsCount = currentRow.length >= maxViewsPerRow;
691
+ if (currentRow.length > 0 && (overflowsWidth || overflowsCount)) {
692
+ rowsOfIndices.push(currentRow);
693
+ currentRow = [];
694
+ currentRowWidth = 0;
695
+ }
696
+ currentRow.push(index);
697
+ currentRowWidth = currentRow.length === 1 ? width : currentRowWidth + itemGap + width;
698
+ });
699
+ if (currentRow.length > 0) {
700
+ rowsOfIndices.push(currentRow);
701
+ }
702
+ const frames = new Array(views.length);
703
+ let rowRectangle = this.rectangleWithHeight(heightNumber);
704
+ rowsOfIndices.forEach((rowIndices, rowNumber) => {
705
+ if (rowNumber > 0) {
706
+ rowRectangle = rowRectangle.rectangleForNextRow(lineGap);
707
+ }
708
+ if (rowIndices.length === 1) {
709
+ const index = rowIndices[0];
710
+ const isolatedValue = Array.isArray(positionOrStretchWhenIsolatedOnOwnWrappedRow) ? positionOrStretchWhenIsolatedOnOwnWrappedRow[index] : positionOrStretchWhenIsolatedOnOwnWrappedRow;
711
+ if (isolatedValue === "stretch") {
712
+ const frame = rowRectangle.lazyCopy();
713
+ _UIRectangle._assignFrameToView(frame, views[index]);
714
+ frames[index] = frame;
715
+ return;
716
+ }
717
+ const rowFrames2 = rowRectangle.framesByDistributingViewsAsRow(
718
+ [views[index]],
719
+ itemGap,
720
+ [preferredWidths[index]],
721
+ isolatedValue
722
+ );
723
+ frames[index] = rowFrames2[0];
724
+ return;
725
+ }
726
+ const rowViews = rowIndices.map((index) => views[index]);
727
+ const rowWidths = rowIndices.map((index) => preferredWidths[index]);
728
+ const rowFrames = rowRectangle.framesByDistributingViewsAsRow(rowViews, itemGap, rowWidths, centeredOnPosition);
729
+ rowIndices.forEach((index, position) => {
730
+ frames[index] = rowFrames[position];
731
+ });
732
+ });
733
+ return frames;
734
+ }
674
735
  framesByDistributingViewsAsGrid(views, paddings = 0, absoluteHeights = import_UIObject.nil) {
675
736
  const frames = [];
676
737
  let currentRowRectangle = this.lazyCopy();
@@ -806,6 +867,9 @@ const _UIRectangle = class extends import_UIObject.UIObject {
806
867
  var _a;
807
868
  const owner = layoutPass.owner;
808
869
  const previousRecords = (_a = _UIRectangle._groupingWrapperFrameRecordsByOwner.get(owner)) != null ? _a : [];
870
+ if (!layoutPass.requests.length && !previousRecords.length) {
871
+ return;
872
+ }
809
873
  const availablePreviousRecords = previousRecords.copy();
810
874
  const nextRecords = [];
811
875
  const groupedViews = /* @__PURE__ */ new Set();