verstak 0.22.509 → 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,30 +36,23 @@ export interface Bounds {
30
36
  heightMax?: string;
31
37
  heightGrowth?: number;
32
38
  heightOverlap?: boolean;
33
- alignContent?: To;
34
- alignFrame?: To;
39
+ alignContent?: Align;
40
+ alignFrame?: Align;
35
41
  wrapping?: boolean;
36
- floating?: boolean;
42
+ dangling?: boolean;
37
43
  }
38
- export interface Place {
39
- exact: CellRange | undefined;
40
- widthMin: string;
41
- widthMax: string;
42
- widthGrowth: number;
43
- heightMin: string;
44
- heightMax: string;
45
- heightGrowth: number;
46
- alignContent: To;
47
- alignFrame: To;
48
- wrapping: boolean;
49
- floating: boolean;
50
- }
51
- 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
+ }>;
52
51
  reset(): void;
52
+ onwards(cells: Cells): CellRange;
53
53
  lineFeed(): void;
54
- allocate(bounds: Bounds | undefined): Place | undefined;
55
54
  }
56
- export declare class GridBasedAllocator implements Allocator {
55
+ export declare class GridCursor extends Cursor {
57
56
  private maxColumnCount;
58
57
  private maxRowCount;
59
58
  private actualColumnCount;
@@ -62,7 +61,6 @@ export declare class GridBasedAllocator implements Allocator {
62
61
  private rowCursor;
63
62
  private newRowCursor;
64
63
  reset(): void;
64
+ onwards(cells: Cells): CellRange;
65
65
  lineFeed(): void;
66
- allocate(bounds: Bounds | undefined): Place | undefined;
67
66
  }
68
- 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,5 +1,6 @@
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
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>;
@@ -9,7 +10,7 @@ export declare const enum Priority {
9
10
  AsyncP2 = 2
10
11
  }
11
12
  export declare type Type<T> = new (...args: any[]) => T;
12
- export interface BlockArgs<T = unknown, M = unknown, R = void> extends Bounds {
13
+ export interface BlockArgs<T = unknown, M = unknown, R = void> {
13
14
  reacting?: boolean;
14
15
  triggers?: unknown;
15
16
  priority?: Priority;
@@ -34,14 +35,23 @@ export declare abstract class VBlock<T = unknown, M = unknown, R = void> {
34
35
  abstract readonly driver: AbstractDriver<T>;
35
36
  abstract readonly args: Readonly<BlockArgs<T, M, R>>;
36
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;
37
49
  abstract readonly level: number;
38
50
  abstract readonly host: VBlock;
39
51
  abstract readonly children: CollectionReader<VBlock>;
40
52
  abstract readonly item: Item<VBlock> | undefined;
41
53
  abstract readonly stamp: number;
42
54
  abstract readonly native: T | undefined;
43
- abstract readonly place: Readonly<Place> | undefined;
44
- render(): R;
45
55
  get isInitialRendering(): boolean;
46
56
  static root(render: () => void): void;
47
57
  static get current(): VBlock;
@@ -62,21 +72,31 @@ export declare class AbstractDriver<T> {
62
72
  static readonly group: AbstractDriver<any>;
63
73
  readonly name: string;
64
74
  readonly layout: LayoutKind;
65
- readonly createAllocator: () => Allocator;
75
+ readonly createCursor: () => Cursor;
66
76
  get isSequential(): boolean;
67
77
  get isAuxiliary(): boolean;
68
78
  get isBlock(): boolean;
69
79
  get isGrid(): boolean;
70
- get isPart(): boolean;
71
- constructor(name: string, layout: LayoutKind, createAllocator?: () => Allocator);
80
+ get isRow(): boolean;
81
+ constructor(name: string, layout: LayoutKind, createCursor?: () => Cursor);
72
82
  initialize(block: VBlock<T>, native: T | undefined): void;
73
83
  finalize(block: VBlock<T>, isLeader: boolean): boolean;
74
84
  deploy(block: VBlock<T>, sequential: boolean): void;
75
- 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;
76
96
  render(block: VBlock<T>): void | Promise<void>;
77
97
  }
78
98
  export declare class StaticDriver<T> extends AbstractDriver<T> {
79
99
  readonly element: T;
80
- constructor(element: T, name: string, layout: LayoutKind, createAllocator?: () => Allocator);
100
+ constructor(element: T, name: string, layout: LayoutKind, createCursor?: () => Cursor);
81
101
  initialize(block: VBlock<T>, element: T | undefined): void;
82
102
  }
@@ -17,7 +17,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
17
17
  });
18
18
  };
19
19
  import { reactive, nonreactive, Transaction, options, Reentrance, Rx, Collection, ObservableObject, raw } from "reactronic";
20
- import { Allocator, To } from "./Allocator";
20
+ import { equalCellRanges } from "./CellRange";
21
+ import { Cursor, Align } from "./Cursor";
21
22
  export var Priority;
22
23
  (function (Priority) {
23
24
  Priority[Priority["SyncP0"] = 0] = "SyncP0";
@@ -39,9 +40,6 @@ export function use(type) {
39
40
  return VBlockImpl.use(type);
40
41
  }
41
42
  export class VBlock {
42
- render() {
43
- return invokeRenderFunction(this);
44
- }
45
43
  get isInitialRendering() {
46
44
  return this.stamp === 2;
47
45
  }
@@ -66,7 +64,7 @@ export class VBlock {
66
64
  let ex = undefined;
67
65
  driver !== null && driver !== void 0 ? driver : (driver = AbstractDriver.group);
68
66
  name || (name = `${++owner.numerator}`);
69
- if (driver.isPart) {
67
+ if (driver.isRow) {
70
68
  const last = children.lastClaimedItem();
71
69
  if (((_a = last === null || last === void 0 ? void 0 : last.instance) === null || _a === void 0 ? void 0 : _a.driver) === driver)
72
70
  ex = last;
@@ -109,74 +107,55 @@ export var LayoutKind;
109
107
  LayoutKind[LayoutKind["Group"] = 3] = "Group";
110
108
  LayoutKind[LayoutKind["Text"] = 4] = "Text";
111
109
  })(LayoutKind || (LayoutKind = {}));
112
- const createDefaultAllocator = () => new Allocator();
110
+ const createDefaultCursor = () => new Cursor();
113
111
  export class AbstractDriver {
114
- constructor(name, layout, createAllocator) {
112
+ constructor(name, layout, createCursor) {
115
113
  this.name = name;
116
114
  this.layout = layout;
117
- this.createAllocator = createAllocator !== null && createAllocator !== void 0 ? createAllocator : createDefaultAllocator;
115
+ this.createCursor = createCursor !== null && createCursor !== void 0 ? createCursor : createDefaultCursor;
118
116
  }
119
117
  get isSequential() { return (this.layout & 1) === 0; }
120
118
  get isAuxiliary() { return (this.layout & 2) === 2; }
121
119
  get isBlock() { return this.layout === LayoutKind.Block; }
122
120
  get isGrid() { return this.layout === LayoutKind.Grid; }
123
- get isPart() { return this.layout === LayoutKind.Row; }
121
+ get isRow() { return this.layout === LayoutKind.Row; }
124
122
  initialize(block, native) {
125
- var _a;
123
+ var _a, _b;
126
124
  const b = block;
127
125
  b.native = native;
128
- const initialize = (_a = block.args) === null || _a === void 0 ? void 0 : _a.initialize;
129
- if (initialize) {
130
- if (Array.isArray(initialize))
131
- for (const init of initialize)
132
- init(native, block, NOP);
133
- else
134
- initialize(native, block, NOP);
135
- }
126
+ (_b = (_a = block.args).initialize) === null || _b === void 0 ? void 0 : _b.call(_a, native, block, NOP);
136
127
  }
137
128
  finalize(block, isLeader) {
138
- var _a;
129
+ var _a, _b;
139
130
  const b = block;
140
- const finalize = (_a = block.args) === null || _a === void 0 ? void 0 : _a.finalize;
141
- if (finalize) {
142
- const native = block.native;
143
- if (Array.isArray(finalize))
144
- for (const fin of finalize)
145
- fin(native, block, NOP);
146
- else
147
- finalize(native, block, NOP);
148
- }
131
+ const native = block.native;
132
+ (_b = (_a = block.args).finalize) === null || _b === void 0 ? void 0 : _b.call(_a, native, block, NOP);
149
133
  b.native = undefined;
150
134
  return isLeader;
151
135
  }
152
136
  deploy(block, sequential) {
153
137
  }
154
- arrange(block, place, heightGrowth) {
155
- var _a, _b, _c;
156
- const b = block;
157
- if (heightGrowth === undefined) {
158
- b.place = place;
159
- const host = b.host;
160
- if (host.driver.isPart) {
161
- const growth = (_a = place === null || place === void 0 ? void 0 : place.heightGrowth) !== null && _a !== void 0 ? _a : 0;
162
- if (growth > 0 && ((_c = (_b = host.place) === null || _b === void 0 ? void 0 : _b.heightGrowth) !== null && _c !== void 0 ? _c : 0) < growth)
163
- host.driver.arrange(host, undefined, growth);
164
- }
165
- }
166
- else if (heightGrowth > 0) {
167
- if (b.place === undefined)
168
- b.place = {
169
- exact: undefined,
170
- widthMin: "", widthMax: "", widthGrowth: 0,
171
- heightMin: "", heightMax: "", heightGrowth,
172
- alignContent: To.Default,
173
- alignFrame: To.Default,
174
- wrapping: false,
175
- floating: false,
176
- };
177
- else
178
- b.place.heightGrowth = heightGrowth;
179
- }
138
+ applyCellRange(block, cellRange) {
139
+ }
140
+ applyWidthGrowth(block, widthGrowth) {
141
+ }
142
+ applyWidthMin(block, widthMin) {
143
+ }
144
+ applyWidthMax(block, widthMax) {
145
+ }
146
+ applyHeightGrowth(block, heightGrowth) {
147
+ }
148
+ applyHeightMin(block, heightMin) {
149
+ }
150
+ applyHeightMax(block, heightMax) {
151
+ }
152
+ applyAlignContent(block, alignContent) {
153
+ }
154
+ applyAlignFrame(block, alignFrame) {
155
+ }
156
+ applyWrapping(block, wrapping) {
157
+ }
158
+ applyDangling(block, dangling) {
180
159
  }
181
160
  render(block) {
182
161
  var _a;
@@ -196,8 +175,8 @@ function invokeRenderFunction(block) {
196
175
  return r(block.native, block, NOP);
197
176
  }
198
177
  export class StaticDriver extends AbstractDriver {
199
- constructor(element, name, layout, createAllocator) {
200
- super(name, layout, createAllocator);
178
+ constructor(element, name, layout, createCursor) {
179
+ super(name, layout, createCursor);
201
180
  this.element = element;
202
181
  }
203
182
  initialize(block, element) {
@@ -225,6 +204,18 @@ class VBlockImpl extends VBlock {
225
204
  this.driver = driver;
226
205
  this.args = args;
227
206
  this.model = undefined;
207
+ this.assignedCells = undefined;
208
+ this.appliedCellRange = Cursor.UndefinedCellRange;
209
+ this.appliedWidthGrowth = 0;
210
+ this.appliedWidthMin = "";
211
+ this.appliedWidthMax = "";
212
+ this.appliedHeightGrowth = 0;
213
+ this.appliedHeightMin = "";
214
+ this.appliedHeightMax = "";
215
+ this.appliedAlignContent = Align.Default;
216
+ this.appliedAlignFrame = Align.Default;
217
+ this.appliedWrapping = false;
218
+ this.appliedDangling = false;
228
219
  this.level = owner.level + 1;
229
220
  this.host = owner;
230
221
  this.children = new Collection(driver.isSequential, getBlockName);
@@ -232,14 +223,94 @@ class VBlockImpl extends VBlock {
232
223
  this.item = undefined;
233
224
  this.stamp = 0;
234
225
  this.native = undefined;
235
- this.place = undefined;
236
- this.allocator = driver.createAllocator();
226
+ this.cursor = driver.createCursor();
237
227
  this.senior = owner.context ? owner : owner.senior;
238
228
  this.context = undefined;
239
229
  }
240
230
  rerender(_triggers) {
241
231
  runRender(this.item);
242
232
  }
233
+ get cells() { return this.assignedCells; }
234
+ set cells(value) {
235
+ if (this.assignedCells !== undefined)
236
+ throw new Error("cells can be assigned only once during rendering");
237
+ const cellRange = this.host.cursor.onwards(value);
238
+ if (!equalCellRanges(cellRange, this.appliedCellRange)) {
239
+ this.driver.applyCellRange(this, cellRange);
240
+ this.appliedCellRange = cellRange;
241
+ }
242
+ this.assignedCells = value !== null && value !== void 0 ? value : {};
243
+ }
244
+ get widthGrowth() { return this.appliedWidthGrowth; }
245
+ set widthGrowth(value) {
246
+ if (value !== this.appliedWidthGrowth) {
247
+ this.driver.applyWidthGrowth(this, value);
248
+ this.appliedWidthGrowth = value;
249
+ }
250
+ }
251
+ get widthMin() { return this.appliedWidthMin; }
252
+ set widthMin(value) {
253
+ if (value !== this.appliedWidthMin) {
254
+ this.driver.applyWidthMin(this, value);
255
+ this.appliedWidthMin = value;
256
+ }
257
+ }
258
+ get widthMax() { return this.appliedWidthMax; }
259
+ set widthMax(value) {
260
+ if (value !== this.appliedWidthMax) {
261
+ this.driver.applyWidthMax(this, value);
262
+ this.appliedWidthMax = value;
263
+ }
264
+ }
265
+ get heightGrowth() { return this.appliedHeightGrowth; }
266
+ set heightGrowth(value) {
267
+ if (value !== this.appliedHeightGrowth) {
268
+ this.driver.applyHeightGrowth(this, value);
269
+ this.appliedHeightGrowth = value;
270
+ }
271
+ }
272
+ get heightMin() { return this.appliedHeightMin; }
273
+ set heightMin(value) {
274
+ if (value !== this.appliedWidthMin) {
275
+ this.driver.applyWidthMin(this, value);
276
+ this.appliedWidthMin = value;
277
+ }
278
+ }
279
+ get heightMax() { return this.appliedHeightMax; }
280
+ set heightMax(value) {
281
+ if (value !== this.appliedWidthMax) {
282
+ this.driver.applyWidthMax(this, value);
283
+ this.appliedWidthMax = value;
284
+ }
285
+ }
286
+ get alignContent() { return this.appliedAlignContent; }
287
+ set alignContent(value) {
288
+ if (value !== this.appliedAlignContent) {
289
+ this.driver.applyAlignContent(this, value);
290
+ this.appliedAlignContent = value;
291
+ }
292
+ }
293
+ get alignFrame() { return this.appliedAlignFrame; }
294
+ set alignFrame(value) {
295
+ if (value !== this.appliedAlignFrame) {
296
+ this.driver.applyAlignFrame(this, value);
297
+ this.appliedAlignFrame = value;
298
+ }
299
+ }
300
+ get wrapping() { return this.appliedWrapping; }
301
+ set wrapping(value) {
302
+ if (value !== this.appliedWrapping) {
303
+ this.driver.applyWrapping(this, value);
304
+ this.appliedWrapping = value;
305
+ }
306
+ }
307
+ get dangling() { return this.appliedDangling; }
308
+ set dangling(value) {
309
+ if (value !== this.appliedDangling) {
310
+ this.driver.applyDangling(this, value);
311
+ this.appliedDangling = value;
312
+ }
313
+ }
243
314
  static use(type) {
244
315
  var _a, _b;
245
316
  let b = gCurrent.instance;
@@ -302,25 +373,19 @@ function runRenderNestedTreesThenDo(error, action) {
302
373
  if (!error) {
303
374
  const ownerIsBlock = owner.driver.isBlock;
304
375
  const sequential = children.strict;
305
- const allocator = owner.allocator;
306
- allocator.reset();
376
+ const cursor = owner.cursor;
307
377
  let p1 = undefined;
308
378
  let p2 = undefined;
309
379
  let redeploy = false;
310
380
  let partHost = owner;
381
+ cursor.reset();
311
382
  for (const item of children.items()) {
312
383
  if (Transaction.isCanceled)
313
384
  break;
314
385
  const block = item.instance;
315
386
  const driver = block.driver;
316
387
  const opt = block.args;
317
- if (!driver.isPart) {
318
- const place = allocator.allocate(opt);
319
- driver.arrange(block, place, undefined);
320
- }
321
- else
322
- allocator.lineFeed();
323
- const host = driver.isPart ? owner : partHost;
388
+ const host = driver.isRow ? owner : partHost;
324
389
  redeploy = markToRedeployIfNecessary(redeploy, host, item, children, sequential);
325
390
  const priority = (_a = opt === null || opt === void 0 ? void 0 : opt.priority) !== null && _a !== void 0 ? _a : Priority.SyncP0;
326
391
  if (priority === Priority.SyncP0)
@@ -329,7 +394,7 @@ function runRenderNestedTreesThenDo(error, action) {
329
394
  p1 = push(item, p1);
330
395
  else
331
396
  p2 = push(item, p2);
332
- if (ownerIsBlock && driver.isPart)
397
+ if (ownerIsBlock && driver.isRow)
333
398
  partHost = block;
334
399
  }
335
400
  if (!Transaction.isCanceled && (p1 !== undefined || p2 !== undefined))
@@ -430,7 +495,6 @@ function prepareRender(item, redeploy, sequential) {
430
495
  }
431
496
  driver.initialize(block, undefined);
432
497
  driver.deploy(block, sequential);
433
- driver.arrange(block, block.place, undefined);
434
498
  });
435
499
  }
436
500
  else if (redeploy)
@@ -446,8 +510,13 @@ function runRender(item) {
446
510
  try {
447
511
  block.stamp++;
448
512
  block.numerator = 0;
513
+ block.assignedCells = undefined;
449
514
  block.children.beginMerge();
450
515
  result = block.driver.render(block);
516
+ if (block.driver.isRow)
517
+ block.host.cursor.lineFeed();
518
+ else if (block.assignedCells === undefined)
519
+ block.cells = undefined;
451
520
  if (result instanceof Promise)
452
521
  result.then(v => { runRenderNestedTreesThenDo(undefined, NOP); return v; }, e => { console.log(e); runRenderNestedTreesThenDo(e !== null && e !== void 0 ? e : new Error("unknown error"), NOP); });
453
522
  else
@@ -1,5 +1,5 @@
1
1
  export * from "./Utils";
2
2
  export * from "./CellRange";
3
- export * from "./Allocator";
3
+ export * from "./Cursor";
4
4
  export * from "./Restyler";
5
5
  export * from "./VBlock";
@@ -1,5 +1,5 @@
1
1
  export * from "./Utils";
2
2
  export * from "./CellRange";
3
- export * from "./Allocator";
3
+ export * from "./Cursor";
4
4
  export * from "./Restyler";
5
5
  export * from "./VBlock";
@@ -1,4 +1,4 @@
1
- import { VBlock, Place, BlockArgs } from "../core/api";
1
+ import { VBlock, BlockArgs, Align, CellRange } from "../core/api";
2
2
  import { HtmlDriver } from "./HtmlDriver";
3
3
  export declare function Block<M = unknown, R = void>(name: string, args: BlockArgs<HTMLElement, M, R>): VBlock<HTMLElement, M, R>;
4
4
  export declare function PlainText(content: string, name?: string, args?: BlockArgs<HTMLElement, void, void>): VBlock<HTMLElement, void, void>;
@@ -8,6 +8,16 @@ export declare function Line<T = void>(claim: (x: void) => T): VBlock<HTMLElemen
8
8
  export declare function lineFeed(args?: BlockArgs<HTMLElement, void, void>, noCoalescing?: boolean): VBlock<HTMLElement>;
9
9
  export declare function Group<M = unknown, R = void>(name: string, args: BlockArgs<HTMLElement, M, R>): VBlock<HTMLElement, M, R>;
10
10
  export declare class VerstakDriver<T extends HTMLElement> extends HtmlDriver<T> {
11
- arrange(block: VBlock<T>, place: Place | undefined, heightGrowth: number | undefined): void;
11
+ applyCellRange(block: VBlock<T>, cellRange: CellRange | undefined): void;
12
+ applyWidthGrowth(block: VBlock<T>, widthGrowth: number): void;
13
+ applyWidthMin(block: VBlock<T>, widthMin: string): void;
14
+ applyWidthMax(block: VBlock<T>, widthMax: string): void;
15
+ applyHeightGrowth(block: VBlock<T>, heightGrowth: number): void;
16
+ applyHeightMin(block: VBlock<T>, heightMin: string): void;
17
+ applyHeightMax(block: VBlock<T>, heightMax: string): void;
18
+ applyAlignContent(block: VBlock<T>, alignContent: Align): void;
19
+ applyAlignFrame(block: VBlock<T>, alignFrame: Align): void;
20
+ applyWrapping(block: VBlock<T>, wrapping: boolean): void;
21
+ applyDangling(block: VBlock<T>, dangling: boolean): void;
12
22
  render(block: VBlock<T>): void | Promise<void>;
13
23
  }
@@ -1,4 +1,4 @@
1
- import { VBlock, LayoutKind, To, GridBasedAllocator, asComponent } from "../core/api";
1
+ import { VBlock, LayoutKind, Align, GridCursor, asComponent } from "../core/api";
2
2
  import { HtmlDriver } from "./HtmlDriver";
3
3
  export function Block(name, args) {
4
4
  return VBlock.claim(name, VerstakTags.block, args);
@@ -33,102 +33,90 @@ export function Group(name, args) {
33
33
  return VBlock.claim(name, VerstakTags.group, args);
34
34
  }
35
35
  export class VerstakDriver extends HtmlDriver {
36
- arrange(block, place, heightGrowth) {
37
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
38
- const native = block.native;
39
- if (native) {
40
- if (heightGrowth === undefined) {
41
- const ex = block.stamp > 1 ? block.place : undefined;
42
- if (place !== ex) {
43
- const css = native.style;
44
- const exact = place === null || place === void 0 ? void 0 : place.exact;
45
- if (exact !== (ex === null || ex === void 0 ? void 0 : ex.exact)) {
46
- if (exact) {
47
- const x1 = exact.x1 || 1;
48
- const y1 = exact.y1 || 1;
49
- const x2 = exact.x2 || x1;
50
- const y2 = exact.y2 || y1;
51
- css.gridArea = `${y1} / ${x1} / span ${y2 - y1 + 1} / span ${x2 - x1 + 1}`;
52
- }
53
- else
54
- css.gridArea = "";
55
- }
56
- const widthGrowth = (_a = place === null || place === void 0 ? void 0 : place.widthGrowth) !== null && _a !== void 0 ? _a : 0;
57
- if (widthGrowth !== ((_b = ex === null || ex === void 0 ? void 0 : ex.widthGrowth) !== null && _b !== void 0 ? _b : 0)) {
58
- if (widthGrowth > 0) {
59
- css.flexGrow = `${widthGrowth}`;
60
- css.flexBasis = "0";
61
- }
62
- else {
63
- css.flexGrow = "";
64
- css.flexBasis = "";
65
- }
66
- }
67
- const widthMin = (_c = place === null || place === void 0 ? void 0 : place.widthMin) !== null && _c !== void 0 ? _c : "";
68
- if (widthMin !== ((_d = ex === null || ex === void 0 ? void 0 : ex.widthMin) !== null && _d !== void 0 ? _d : ""))
69
- css.minWidth = `${widthMin}`;
70
- const widthMax = (_e = place === null || place === void 0 ? void 0 : place.widthMax) !== null && _e !== void 0 ? _e : "";
71
- if (widthMax !== ((_f = ex === null || ex === void 0 ? void 0 : ex.widthMax) !== null && _f !== void 0 ? _f : ""))
72
- css.maxWidth = `${widthMax}`;
73
- const heightMin = (_g = place === null || place === void 0 ? void 0 : place.heightMin) !== null && _g !== void 0 ? _g : "";
74
- if (heightMin !== ((_h = ex === null || ex === void 0 ? void 0 : ex.heightMin) !== null && _h !== void 0 ? _h : ""))
75
- css.minHeight = `${heightMin}`;
76
- const heightMax = (_j = place === null || place === void 0 ? void 0 : place.heightMax) !== null && _j !== void 0 ? _j : "";
77
- if (heightMax !== ((_k = ex === null || ex === void 0 ? void 0 : ex.heightMax) !== null && _k !== void 0 ? _k : ""))
78
- css.maxHeight = `${heightMax}`;
79
- const alignContent = (_l = place === null || place === void 0 ? void 0 : place.alignContent) !== null && _l !== void 0 ? _l : To.Default;
80
- if (alignContent !== ((_m = ex === null || ex === void 0 ? void 0 : ex.alignContent) !== null && _m !== void 0 ? _m : To.Default)) {
81
- if ((alignContent & To.Default) === 0) {
82
- const v = AlignToCss[(alignContent >> 2) & 0b11];
83
- const h = AlignToCss[alignContent & 0b11];
84
- const t = TextAlignCss[alignContent & 0b11];
85
- css.justifyContent = v;
86
- css.alignItems = h;
87
- css.textAlign = t;
88
- }
89
- else
90
- css.justifyContent = css.alignContent = css.textAlign = "";
91
- }
92
- const heightGrowth = (_o = place === null || place === void 0 ? void 0 : place.heightGrowth) !== null && _o !== void 0 ? _o : 0;
93
- const alignFrame = (_p = place === null || place === void 0 ? void 0 : place.alignFrame) !== null && _p !== void 0 ? _p : To.Default;
94
- if (alignFrame !== ((_q = ex === null || ex === void 0 ? void 0 : ex.alignFrame) !== null && _q !== void 0 ? _q : To.Default) ||
95
- heightGrowth !== ((_r = ex === null || ex === void 0 ? void 0 : ex.heightGrowth) !== null && _r !== void 0 ? _r : 0)) {
96
- if ((alignFrame & To.Default) === 0) {
97
- const v = AlignToCss[(alignFrame >> 2) & 0b11];
98
- const h = AlignToCss[alignFrame & 0b11];
99
- css.alignSelf = v;
100
- css.justifySelf = h;
101
- }
102
- else if (heightGrowth > 0) {
103
- css.alignSelf = AlignToCss[To.Fit];
104
- }
105
- else
106
- css.alignSelf = css.justifySelf = "";
107
- }
108
- const wrapping = (_s = place === null || place === void 0 ? void 0 : place.wrapping) !== null && _s !== void 0 ? _s : false;
109
- if (wrapping !== ((_t = ex === null || ex === void 0 ? void 0 : ex.wrapping) !== null && _t !== void 0 ? _t : false)) {
110
- if (wrapping)
111
- native.setAttribute("wrapping", "true");
112
- else
113
- native.removeAttribute("wrapping");
114
- }
115
- const floating = (_u = place === null || place === void 0 ? void 0 : place.floating) !== null && _u !== void 0 ? _u : false;
116
- if (floating !== ((_v = ex === null || ex === void 0 ? void 0 : ex.floating) !== null && _v !== void 0 ? _v : false)) {
117
- if (floating)
118
- native.setAttribute("floating", "true");
119
- else
120
- native.removeAttribute("floating");
121
- }
122
- }
123
- }
124
- else {
125
- if (heightGrowth > 0)
126
- block.native.style.flexGrow = `${heightGrowth}`;
127
- else
128
- block.native.style.flexGrow = "";
129
- }
36
+ applyCellRange(block, cellRange) {
37
+ const css = block.native.style;
38
+ if (cellRange) {
39
+ const x1 = cellRange.x1 || 1;
40
+ const y1 = cellRange.y1 || 1;
41
+ const x2 = cellRange.x2 || x1;
42
+ const y2 = cellRange.y2 || y1;
43
+ css.gridArea = `${y1} / ${x1} / span ${y2 - y1 + 1} / span ${x2 - x1 + 1}`;
130
44
  }
131
- super.arrange(block, place, heightGrowth);
45
+ else
46
+ css.gridArea = "";
47
+ super.applyCellRange(block, cellRange);
48
+ }
49
+ applyWidthGrowth(block, widthGrowth) {
50
+ const css = block.native.style;
51
+ if (widthGrowth > 0) {
52
+ css.flexGrow = `${widthGrowth}`;
53
+ css.flexBasis = "0";
54
+ }
55
+ else {
56
+ css.flexGrow = "";
57
+ css.flexBasis = "";
58
+ }
59
+ }
60
+ applyWidthMin(block, widthMin) {
61
+ block.native.style.minWidth = `${widthMin}`;
62
+ }
63
+ applyWidthMax(block, widthMax) {
64
+ block.native.style.maxWidth = `${widthMax}`;
65
+ }
66
+ applyHeightGrowth(block, heightGrowth) {
67
+ if (block.driver.isRow) {
68
+ const css = block.native.style;
69
+ if (heightGrowth > 0)
70
+ css.flexGrow = `${heightGrowth}`;
71
+ else
72
+ css.flexGrow = "";
73
+ }
74
+ else if (block.host.driver.isRow) {
75
+ block.driver.applyAlignFrame(block, Align.Stretch);
76
+ block.host.driver.applyHeightGrowth(block.host, heightGrowth);
77
+ }
78
+ }
79
+ applyHeightMin(block, heightMin) {
80
+ block.native.style.minHeight = `${heightMin}`;
81
+ }
82
+ applyHeightMax(block, heightMax) {
83
+ block.native.style.maxHeight = `${heightMax}`;
84
+ }
85
+ applyAlignContent(block, alignContent) {
86
+ const css = block.native.style;
87
+ if ((alignContent & Align.Default) === 0) {
88
+ const v = AlignToCss[(alignContent >> 2) & 0b11];
89
+ const h = AlignToCss[alignContent & 0b11];
90
+ const t = TextAlignCss[alignContent & 0b11];
91
+ css.justifyContent = v;
92
+ css.alignItems = h;
93
+ css.textAlign = t;
94
+ }
95
+ else
96
+ css.justifyContent = css.alignContent = css.textAlign = "";
97
+ }
98
+ applyAlignFrame(block, alignFrame) {
99
+ const css = block.native.style;
100
+ if ((alignFrame & Align.Default) === 0) {
101
+ const v = AlignToCss[(alignFrame >> 2) & 0b11];
102
+ const h = AlignToCss[alignFrame & 0b11];
103
+ css.alignSelf = v;
104
+ css.justifySelf = h;
105
+ }
106
+ else
107
+ css.alignSelf = css.justifySelf = "";
108
+ }
109
+ applyWrapping(block, wrapping) {
110
+ if (wrapping)
111
+ block.native.setAttribute("wrapping", "true");
112
+ else
113
+ block.native.removeAttribute("wrapping");
114
+ }
115
+ applyDangling(block, dangling) {
116
+ if (dangling)
117
+ block.native.setAttribute("dangling", "true");
118
+ else
119
+ block.native.removeAttribute("dangling");
132
120
  }
133
121
  render(block) {
134
122
  if (block.driver.layout < LayoutKind.Row)
@@ -139,7 +127,7 @@ export class VerstakDriver extends HtmlDriver {
139
127
  const VerstakTags = {
140
128
  block: new VerstakDriver("v-block", LayoutKind.Block),
141
129
  text: new VerstakDriver("v-text", LayoutKind.Text),
142
- grid: new VerstakDriver("v-grid", LayoutKind.Grid, () => new GridBasedAllocator()),
130
+ grid: new VerstakDriver("v-grid", LayoutKind.Grid, () => new GridCursor()),
143
131
  row: new VerstakDriver("v-row", LayoutKind.Row),
144
132
  group: new VerstakDriver("v-group", LayoutKind.Group),
145
133
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "verstak",
3
- "version": "0.22.509",
3
+ "version": "0.22.510",
4
4
  "description": "Verstak - Front-End Library",
5
5
  "publisher": "Nezaboodka Software",
6
6
  "license": "Apache-2.0",
@@ -1,145 +0,0 @@
1
- import { parseCellRange } from "./CellRange";
2
- export var To;
3
- (function (To) {
4
- To[To["Fit"] = 0] = "Fit";
5
- To[To["Left"] = 1] = "Left";
6
- To[To["Center"] = 2] = "Center";
7
- To[To["Right"] = 3] = "Right";
8
- To[To["Top"] = 4] = "Top";
9
- To[To["CenterV"] = 8] = "CenterV";
10
- To[To["Bottom"] = 12] = "Bottom";
11
- To[To["Default"] = 16] = "Default";
12
- })(To || (To = {}));
13
- export class Allocator {
14
- reset() {
15
- }
16
- lineFeed() {
17
- }
18
- allocate(bounds) {
19
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
20
- return !bounds ? undefined : {
21
- exact: bounds.place ? parseCellRange(bounds.place, { x1: 0, y1: 0, x2: 0, y2: 0 }) : undefined,
22
- widthMin: (_a = bounds.widthMin) !== null && _a !== void 0 ? _a : "",
23
- widthMax: (_b = bounds.widthMax) !== null && _b !== void 0 ? _b : "",
24
- widthGrowth: (_c = bounds.widthGrowth) !== null && _c !== void 0 ? _c : 0,
25
- heightMin: (_d = bounds.heightMin) !== null && _d !== void 0 ? _d : "",
26
- heightMax: (_e = bounds.heightMax) !== null && _e !== void 0 ? _e : "",
27
- heightGrowth: (_f = bounds.heightGrowth) !== null && _f !== void 0 ? _f : 0,
28
- alignContent: (_g = bounds.alignContent) !== null && _g !== void 0 ? _g : To.Default,
29
- alignFrame: (_h = bounds.alignFrame) !== null && _h !== void 0 ? _h : To.Default,
30
- wrapping: (_j = bounds.wrapping) !== null && _j !== void 0 ? _j : false,
31
- floating: (_k = bounds.floating) !== null && _k !== void 0 ? _k : false,
32
- };
33
- }
34
- }
35
- export class GridBasedAllocator {
36
- constructor() {
37
- this.maxColumnCount = 0;
38
- this.maxRowCount = 0;
39
- this.actualColumnCount = 0;
40
- this.actualRowCount = 0;
41
- this.columnCursor = 0;
42
- this.rowCursor = 0;
43
- this.newRowCursor = 0;
44
- }
45
- reset() {
46
- this.maxColumnCount = 0;
47
- this.maxRowCount = 0;
48
- this.actualColumnCount = 0;
49
- this.actualRowCount = 0;
50
- this.columnCursor = 0;
51
- this.rowCursor = 0;
52
- this.newRowCursor = 0;
53
- }
54
- lineFeed() {
55
- this.columnCursor = 0;
56
- this.rowCursor = this.newRowCursor;
57
- }
58
- allocate(bounds) {
59
- var _a, _b, _c, _d, _e, _f;
60
- const result = {
61
- exact: undefined,
62
- widthMin: "", widthMax: "", widthGrowth: 0,
63
- heightMin: "", heightMax: "", heightGrowth: 0,
64
- alignContent: (_a = bounds === null || bounds === void 0 ? void 0 : bounds.alignContent) !== null && _a !== void 0 ? _a : To.Default,
65
- alignFrame: (_b = bounds === null || bounds === void 0 ? void 0 : bounds.alignFrame) !== null && _b !== void 0 ? _b : To.Default,
66
- wrapping: (_c = bounds === null || bounds === void 0 ? void 0 : bounds.wrapping) !== null && _c !== void 0 ? _c : false,
67
- floating: (_d = bounds === null || bounds === void 0 ? void 0 : bounds.floating) !== null && _d !== void 0 ? _d : false,
68
- };
69
- if (bounds === null || bounds === void 0 ? void 0 : bounds.place) {
70
- result.exact = parseCellRange(bounds.place, { x1: 0, y1: 0, x2: 0, y2: 0 });
71
- absolutizeCellRange(result.exact, this.columnCursor + 1, this.rowCursor + 1, this.maxColumnCount || Infinity, this.maxRowCount || Infinity, result.exact);
72
- }
73
- else {
74
- const totalColumnCount = this.maxColumnCount !== 0 ? this.maxColumnCount : this.actualColumnCount;
75
- const totalRowCount = this.maxRowCount !== 0 ? this.maxRowCount : this.actualRowCount;
76
- const cr = result.exact = { x1: 0, y1: 0, x2: 0, y2: 0 };
77
- let w = (_e = bounds === null || bounds === void 0 ? void 0 : bounds.widthSpan) !== null && _e !== void 0 ? _e : 1;
78
- if (w === 0)
79
- w = totalColumnCount || 1;
80
- if (w >= 0) {
81
- cr.x1 = this.columnCursor + 1;
82
- cr.x2 = absolutizePosition(cr.x1 + w - 1, 0, this.maxColumnCount || Infinity);
83
- if (!(bounds === null || bounds === void 0 ? void 0 : bounds.widthOverlap))
84
- this.columnCursor = cr.x2;
85
- }
86
- else {
87
- cr.x1 = Math.max(this.columnCursor + w, 1);
88
- cr.x2 = this.columnCursor;
89
- }
90
- let h = (_f = bounds === null || bounds === void 0 ? void 0 : bounds.heightSpan) !== null && _f !== void 0 ? _f : 1;
91
- if (h === 0)
92
- h = totalRowCount || 1;
93
- if (h >= 0) {
94
- cr.y1 = this.rowCursor + 1;
95
- cr.y2 = absolutizePosition(cr.y1 + h - 1, 0, this.maxRowCount || Infinity);
96
- if (!(bounds === null || bounds === void 0 ? void 0 : bounds.heightOverlap) && cr.y2 > this.newRowCursor)
97
- this.newRowCursor = cr.y2;
98
- }
99
- else {
100
- cr.y1 = Math.max(this.rowCursor + h, 1);
101
- cr.y2 = this.rowCursor;
102
- }
103
- }
104
- return result;
105
- }
106
- }
107
- function absolutizeCellRange(area, cursorX, cursorY, maxWidth, maxHeight, result) {
108
- const x1 = absolutizePosition(area.x1, cursorX, maxWidth);
109
- const x2 = absolutizePosition(area.x2, x1, maxWidth);
110
- if (x1 <= x2)
111
- result.x1 = x1, result.x2 = x2;
112
- else
113
- result.x1 = x2, result.x2 = x1;
114
- const y1 = absolutizePosition(area.y1, cursorY, maxHeight);
115
- const y2 = absolutizePosition(area.y2, y1, maxHeight);
116
- if (y1 <= y2)
117
- result.y1 = y1, result.y2 = y2;
118
- else
119
- result.y1 = y2, result.y2 = y1;
120
- return result;
121
- }
122
- function absolutizePosition(pos, cursor, max) {
123
- if (pos === 0)
124
- pos = cursor;
125
- else if (pos < 0)
126
- pos = Math.max(max + pos, 1);
127
- else
128
- pos = Math.min(pos, max);
129
- return pos;
130
- }
131
- export function equalPlaces(a, b) {
132
- let result;
133
- if (a) {
134
- if (b) {
135
- result = a.widthGrowth == b.widthGrowth;
136
- }
137
- else
138
- result = false;
139
- }
140
- else if (b)
141
- result = false;
142
- else
143
- result = true;
144
- return result;
145
- }