verstak 0.22.508 → 0.22.510

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.
@@ -6,3 +6,4 @@ export interface CellRange {
6
6
  }
7
7
  export declare function parseCellRange(text: string, result: CellRange): CellRange;
8
8
  export declare function emitCellRange(value: CellRange): string;
9
+ export declare function equalCellRanges(a: CellRange, b: CellRange): boolean;
@@ -134,6 +134,9 @@ export function emitCellRange(value) {
134
134
  const p2 = emitCellPosition(value.x2, value.y2);
135
135
  return `${p1}${p2 !== "" ? `:${p2}` : ""}`;
136
136
  }
137
+ export function equalCellRanges(a, b) {
138
+ return a.x1 === b.x1 && a.y1 === b.y1 && a.x2 === b.x2 && a.y1 === b.y2;
139
+ }
137
140
  function isWhitespace(char) {
138
141
  return char === 32 || (char >= 9 && char <= 13) || char === 133 || char === 160;
139
142
  }
@@ -1,6 +1,6 @@
1
1
  import { CellRange } from "./CellRange";
2
- export declare enum To {
3
- Fit = 0,
2
+ export declare enum Align {
3
+ Stretch = 0,
4
4
  Left = 1,
5
5
  Center = 2,
6
6
  Right = 3,
@@ -18,6 +18,12 @@ export interface ElasticSize {
18
18
  export interface TrackSize extends ElasticSize {
19
19
  track?: string | number;
20
20
  }
21
+ export declare type Cells = undefined | string | number | {
22
+ right?: number;
23
+ horizontalOverlap?: boolean;
24
+ down?: number;
25
+ verticalOverlap?: boolean;
26
+ };
21
27
  export interface Bounds {
22
28
  place?: string;
23
29
  widthSpan?: number;
@@ -30,28 +36,23 @@ export interface Bounds {
30
36
  heightMax?: string;
31
37
  heightGrowth?: number;
32
38
  heightOverlap?: boolean;
33
- alignContent?: To;
34
- alignFrame?: To;
35
- flowWrap?: boolean;
39
+ alignContent?: Align;
40
+ alignFrame?: Align;
41
+ wrapping?: boolean;
42
+ dangling?: boolean;
36
43
  }
37
- export interface Place {
38
- exact: CellRange | undefined;
39
- widthMin: string;
40
- widthMax: string;
41
- widthGrowth: number;
42
- heightMin: string;
43
- heightMax: string;
44
- heightGrowth: number;
45
- alignContent: To;
46
- alignFrame: To;
47
- flowWrap: boolean;
48
- }
49
- export declare class Allocator {
44
+ export declare class Cursor {
45
+ static readonly UndefinedCellRange: Readonly<{
46
+ x1: 0;
47
+ y1: 0;
48
+ x2: 0;
49
+ y2: 0;
50
+ }>;
50
51
  reset(): void;
52
+ onwards(cells: Cells): CellRange;
51
53
  lineFeed(): void;
52
- allocate(bounds: Bounds | undefined): Place | undefined;
53
54
  }
54
- export declare class GridBasedAllocator implements Allocator {
55
+ export declare class GridCursor extends Cursor {
55
56
  private maxColumnCount;
56
57
  private maxRowCount;
57
58
  private actualColumnCount;
@@ -60,7 +61,6 @@ export declare class GridBasedAllocator implements Allocator {
60
61
  private rowCursor;
61
62
  private newRowCursor;
62
63
  reset(): void;
64
+ onwards(cells: Cells): CellRange;
63
65
  lineFeed(): void;
64
- allocate(bounds: Bounds | undefined): Place | undefined;
65
66
  }
66
- export declare function equalPlaces(a: Place | undefined, b: Place | undefined): boolean;
@@ -0,0 +1,125 @@
1
+ import { parseCellRange } from "./CellRange";
2
+ export var Align;
3
+ (function (Align) {
4
+ Align[Align["Stretch"] = 0] = "Stretch";
5
+ Align[Align["Left"] = 1] = "Left";
6
+ Align[Align["Center"] = 2] = "Center";
7
+ Align[Align["Right"] = 3] = "Right";
8
+ Align[Align["Top"] = 4] = "Top";
9
+ Align[Align["CenterV"] = 8] = "CenterV";
10
+ Align[Align["Bottom"] = 12] = "Bottom";
11
+ Align[Align["Default"] = 16] = "Default";
12
+ })(Align || (Align = {}));
13
+ export class Cursor {
14
+ reset() { }
15
+ onwards(cells) { return Cursor.UndefinedCellRange; }
16
+ lineFeed() { }
17
+ }
18
+ Cursor.UndefinedCellRange = Object.freeze({ x1: 0, y1: 0, x2: 0, y2: 0 });
19
+ export class GridCursor extends Cursor {
20
+ constructor() {
21
+ super(...arguments);
22
+ this.maxColumnCount = 0;
23
+ this.maxRowCount = 0;
24
+ this.actualColumnCount = 0;
25
+ this.actualRowCount = 0;
26
+ this.columnCursor = 0;
27
+ this.rowCursor = 0;
28
+ this.newRowCursor = 0;
29
+ }
30
+ reset() {
31
+ this.maxColumnCount = 0;
32
+ this.maxRowCount = 0;
33
+ this.actualColumnCount = 0;
34
+ this.actualRowCount = 0;
35
+ this.columnCursor = 0;
36
+ this.rowCursor = 0;
37
+ this.newRowCursor = 0;
38
+ }
39
+ onwards(cells) {
40
+ var _a, _b, _c, _d;
41
+ let result;
42
+ if (typeof (cells) === "string") {
43
+ result = parseCellRange(cells, { x1: 0, y1: 0, x2: 0, y2: 0 });
44
+ absolutizeCellRange(result, this.columnCursor + 1, this.rowCursor + 1, this.maxColumnCount || Infinity, this.maxRowCount || Infinity, result);
45
+ }
46
+ else {
47
+ let columns;
48
+ let rows;
49
+ let columnsOverlap;
50
+ let rowsOverlap;
51
+ if (typeof (cells) === "number") {
52
+ columns = cells;
53
+ rows = 1;
54
+ columnsOverlap = rowsOverlap = false;
55
+ }
56
+ else if (cells) {
57
+ columns = (_a = cells.right) !== null && _a !== void 0 ? _a : 1;
58
+ rows = (_b = cells.down) !== null && _b !== void 0 ? _b : 1;
59
+ columnsOverlap = (_c = cells.horizontalOverlap) !== null && _c !== void 0 ? _c : false;
60
+ rowsOverlap = (_d = cells.verticalOverlap) !== null && _d !== void 0 ? _d : false;
61
+ }
62
+ else {
63
+ columns = 1;
64
+ rows = 1;
65
+ columnsOverlap = rowsOverlap = false;
66
+ }
67
+ const totalColumnCount = this.maxColumnCount !== 0 ? this.maxColumnCount : this.actualColumnCount;
68
+ const totalRowCount = this.maxRowCount !== 0 ? this.maxRowCount : this.actualRowCount;
69
+ result = { x1: 0, y1: 0, x2: 0, y2: 0 };
70
+ if (columns === 0)
71
+ columns = totalColumnCount || 1;
72
+ if (columns >= 0) {
73
+ result.x1 = this.columnCursor + 1;
74
+ result.x2 = absolutizePosition(result.x1 + columns - 1, 0, this.maxColumnCount || Infinity);
75
+ if (!columnsOverlap)
76
+ this.columnCursor = result.x2;
77
+ }
78
+ else {
79
+ result.x1 = Math.max(this.columnCursor + columns, 1);
80
+ result.x2 = this.columnCursor;
81
+ }
82
+ if (rows === 0)
83
+ rows = totalRowCount || 1;
84
+ if (rows >= 0) {
85
+ result.y1 = this.rowCursor + 1;
86
+ result.y2 = absolutizePosition(result.y1 + rows - 1, 0, this.maxRowCount || Infinity);
87
+ if (!rowsOverlap && result.y2 > this.newRowCursor)
88
+ this.newRowCursor = result.y2;
89
+ }
90
+ else {
91
+ result.y1 = Math.max(this.rowCursor + rows, 1);
92
+ result.y2 = this.rowCursor;
93
+ }
94
+ }
95
+ return result;
96
+ }
97
+ lineFeed() {
98
+ this.columnCursor = 0;
99
+ this.rowCursor = this.newRowCursor;
100
+ }
101
+ }
102
+ function absolutizeCellRange(area, cursorX, cursorY, maxWidth, maxHeight, result) {
103
+ const x1 = absolutizePosition(area.x1, cursorX, maxWidth);
104
+ const x2 = absolutizePosition(area.x2, x1, maxWidth);
105
+ if (x1 <= x2)
106
+ result.x1 = x1, result.x2 = x2;
107
+ else
108
+ result.x1 = x2, result.x2 = x1;
109
+ const y1 = absolutizePosition(area.y1, cursorY, maxHeight);
110
+ const y2 = absolutizePosition(area.y2, y1, maxHeight);
111
+ if (y1 <= y2)
112
+ result.y1 = y1, result.y2 = y2;
113
+ else
114
+ result.y1 = y2, result.y2 = y1;
115
+ return result;
116
+ }
117
+ function absolutizePosition(pos, cursor, max) {
118
+ if (pos === 0)
119
+ pos = cursor;
120
+ else if (pos < 0)
121
+ pos = Math.max(max + pos, 1);
122
+ else
123
+ pos = Math.min(pos, max);
124
+ return pos;
125
+ }
@@ -1,14 +1,16 @@
1
1
  import { Monitor, LoggingOptions, Item, CollectionReader } from "reactronic";
2
- import { Bounds, Place, Allocator } from "./Allocator";
2
+ import { CellRange } from "./CellRange";
3
+ import { Cursor, Align, Cells } from "./Cursor";
3
4
  export declare type Callback<T = unknown> = (native: T) => void;
4
- export declare type Render<T = unknown, M = unknown, R = void> = (native: T, block: VBlock<T, M, R>) => R;
5
+ export declare type Render<T = unknown, M = unknown, R = void> = (native: T, block: VBlock<T, M, R>, base: () => R) => R;
5
6
  export declare type AsyncRender<T = unknown, M = unknown> = (native: T, block: VBlock<T, M, Promise<void>>) => Promise<void>;
6
7
  export declare const enum Priority {
7
8
  SyncP0 = 0,
8
9
  AsyncP1 = 1,
9
10
  AsyncP2 = 2
10
11
  }
11
- export interface BlockArgs<T = unknown, M = unknown, R = void> extends Bounds {
12
+ export declare type Type<T> = new (...args: any[]) => T;
13
+ export interface BlockArgs<T = unknown, M = unknown, R = void> {
12
14
  reacting?: boolean;
13
15
  triggers?: unknown;
14
16
  priority?: Priority;
@@ -16,13 +18,14 @@ export interface BlockArgs<T = unknown, M = unknown, R = void> extends Bounds {
16
18
  throttling?: number;
17
19
  logging?: Partial<LoggingOptions>;
18
20
  shuffle?: boolean;
19
- initialize?: Render<T, M, R> | Array<Render<T, M, R>>;
21
+ initialize?: Render<T, M, R>;
20
22
  override?: Render<T, M, R>;
21
- render: Render<T, M, R>;
22
- finalize?: Render<T, M, R> | Array<Render<T, M, R>>;
23
+ render?: Render<T, M, R>;
24
+ finalize?: Render<T, M, R>;
23
25
  }
24
- export declare function setContext<T extends Object>(type: new (...args: any[]) => T, context: T): void;
25
- export declare function use<T extends Object>(type: new (...args: any[]) => T): T;
26
+ export declare function asComponent<T, M, R>(outer: BlockArgs<T, M, R> | undefined, base: BlockArgs<T, M, R>): BlockArgs<T, M, R>;
27
+ export declare function setContext<T extends Object>(type: Type<T>, context: T): void;
28
+ export declare function use<T extends Object>(type: Type<T>): T;
26
29
  export declare abstract class VBlock<T = unknown, M = unknown, R = void> {
27
30
  static readonly shortFrameDuration = 16;
28
31
  static readonly longFrameDuration = 300;
@@ -32,27 +35,36 @@ export declare abstract class VBlock<T = unknown, M = unknown, R = void> {
32
35
  abstract readonly driver: AbstractDriver<T>;
33
36
  abstract readonly args: Readonly<BlockArgs<T, M, R>>;
34
37
  abstract model: M;
38
+ abstract cells: Cells;
39
+ abstract widthGrowth: number;
40
+ abstract widthMin: string;
41
+ abstract widthMax: string;
42
+ abstract heightGrowth: number;
43
+ abstract heightMin: string;
44
+ abstract heightMax: string;
45
+ abstract alignContent: Align;
46
+ abstract alignFrame: Align;
47
+ abstract wrapping: boolean;
48
+ abstract dangling: boolean;
35
49
  abstract readonly level: number;
36
50
  abstract readonly host: VBlock;
37
51
  abstract readonly children: CollectionReader<VBlock>;
38
52
  abstract readonly item: Item<VBlock> | undefined;
39
53
  abstract readonly stamp: number;
40
54
  abstract readonly native: T | undefined;
41
- abstract readonly place: Readonly<Place> | undefined;
42
- render(): R;
43
55
  get isInitialRendering(): boolean;
44
56
  static root(render: () => void): void;
45
57
  static get current(): VBlock;
46
58
  static renderNestedTreesThenDo(action: (error: unknown) => void): void;
47
59
  static runForAllBlocks<T>(action: (e: T) => void): void;
48
- static claim<T = undefined, M = unknown, R = void, C = void>(name: string, args: BlockArgs<T, M, R>, driver?: AbstractDriver<T>): VBlock<T, M, R>;
60
+ static claim<T = undefined, M = unknown, R = void>(name: string, driver: AbstractDriver<T> | undefined, args: BlockArgs<T, M, R>): VBlock<T, M, R>;
49
61
  static getDefaultLoggingOptions(): LoggingOptions | undefined;
50
62
  static setDefaultLoggingOptions(logging?: LoggingOptions): void;
51
63
  }
52
64
  export declare enum LayoutKind {
53
65
  Block = 0,
54
66
  Grid = 1,
55
- Part = 2,
67
+ Row = 2,
56
68
  Group = 3,
57
69
  Text = 4
58
70
  }
@@ -60,21 +72,31 @@ export declare class AbstractDriver<T> {
60
72
  static readonly group: AbstractDriver<any>;
61
73
  readonly name: string;
62
74
  readonly layout: LayoutKind;
63
- readonly createAllocator: () => Allocator;
75
+ readonly createCursor: () => Cursor;
64
76
  get isSequential(): boolean;
65
77
  get isAuxiliary(): boolean;
66
78
  get isBlock(): boolean;
67
79
  get isGrid(): boolean;
68
- get isPart(): boolean;
69
- constructor(name: string, layout: LayoutKind, createAllocator?: () => Allocator);
80
+ get isRow(): boolean;
81
+ constructor(name: string, layout: LayoutKind, createCursor?: () => Cursor);
70
82
  initialize(block: VBlock<T>, native: T | undefined): void;
71
83
  finalize(block: VBlock<T>, isLeader: boolean): boolean;
72
84
  deploy(block: VBlock<T>, sequential: boolean): void;
73
- arrange(block: VBlock<T>, place: Place | undefined, heightGrowth: number | undefined): void;
85
+ applyCellRange(block: VBlock<T, any, any>, cellRange: CellRange | undefined): void;
86
+ applyWidthGrowth(block: VBlock<T, any, any>, widthGrowth: number): void;
87
+ applyWidthMin(block: VBlock<T, any, any>, widthMin: string): void;
88
+ applyWidthMax(block: VBlock<T, any, any>, widthMax: string): void;
89
+ applyHeightGrowth(block: VBlock<T, any, any>, heightGrowth: number): void;
90
+ applyHeightMin(block: VBlock<T, any, any>, heightMin: string): void;
91
+ applyHeightMax(block: VBlock<T, any, any>, heightMax: string): void;
92
+ applyAlignContent(block: VBlock<T, any, any>, alignContent: Align): void;
93
+ applyAlignFrame(block: VBlock<T, any, any>, alignFrame: Align): void;
94
+ applyWrapping(block: VBlock<T, any, any>, wrapping: boolean): void;
95
+ applyDangling(block: VBlock<T, any, any>, dangling: boolean): void;
74
96
  render(block: VBlock<T>): void | Promise<void>;
75
97
  }
76
98
  export declare class StaticDriver<T> extends AbstractDriver<T> {
77
99
  readonly element: T;
78
- constructor(element: T, name: string, layout: LayoutKind, createAllocator?: () => Allocator);
100
+ constructor(element: T, name: string, layout: LayoutKind, createCursor?: () => Cursor);
79
101
  initialize(block: VBlock<T>, element: T | undefined): void;
80
102
  }