verstak 0.23.125 → 0.24.107

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.
@@ -1,887 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
8
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
- };
10
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
11
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
12
- return new (P || (P = Promise))(function (resolve, reject) {
13
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
14
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
15
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
16
- step((generator = generator.apply(thisArg, _arguments || [])).next());
17
- });
18
- };
19
- import { reactive, unobs, Transaction, options, Reentrance, Rx, MergeList, ObservableObject, raw } from "reactronic";
20
- import { ElKind, Priority, Mode, Align } from "./Interfaces.js";
21
- import { emitLetters, equalElCoords, parseElCoords, getCallerInfo } from "./Utils.js";
22
- export class Verstak {
23
- static specify(driver, spec, base) {
24
- var _a;
25
- let result;
26
- if (spec)
27
- spec.base = base;
28
- else
29
- spec = base !== null && base !== void 0 ? base : {};
30
- let key = spec.key;
31
- const owner = gCurrent === null || gCurrent === void 0 ? void 0 : gCurrent.instance;
32
- if (owner) {
33
- let ex = undefined;
34
- const children = owner.node.children;
35
- if (driver.isSeparator) {
36
- const last = children.lastMergedItem();
37
- if (((_a = last === null || last === void 0 ? void 0 : last.instance) === null || _a === void 0 ? void 0 : _a.node.driver) === driver)
38
- ex = last;
39
- }
40
- ex !== null && ex !== void 0 ? ex : (ex = children.tryMergeAsExisting(key = key || generateKey(owner), undefined, "nested elements can be declared inside update function only"));
41
- if (ex) {
42
- result = ex.instance;
43
- const node = result.node;
44
- if (node.driver !== driver && driver !== undefined)
45
- throw new Error(`changing element driver is not yet supported: "${result.node.driver.name}" -> "${driver === null || driver === void 0 ? void 0 : driver.name}"`);
46
- const exTriggers = node.spec.triggers;
47
- if (triggersAreEqual(spec.triggers, exTriggers))
48
- spec.triggers = exTriggers;
49
- node.spec = spec;
50
- }
51
- else {
52
- result = new ElImpl(key || generateKey(owner), driver, owner, spec);
53
- result.node.slot = children.mergeAsAdded(result);
54
- }
55
- }
56
- else {
57
- result = new ElImpl(key || "", driver, owner, spec);
58
- result.node.slot = MergeList.createItem(result);
59
- triggerUpdate(result.node.slot);
60
- }
61
- return result;
62
- }
63
- static get element() {
64
- if (gCurrent === undefined)
65
- throw new Error("current element is undefined");
66
- return gCurrent.instance;
67
- }
68
- static triggerUpdate(element, triggers) {
69
- const el = element;
70
- const spec = el.node.spec;
71
- if (!triggersAreEqual(triggers, spec.triggers)) {
72
- spec.triggers = triggers;
73
- triggerUpdate(el.node.slot);
74
- }
75
- }
76
- static updateNestedTreesThenDo(action) {
77
- runUpdateNestedTreesThenDo(undefined, action);
78
- }
79
- static getDefaultLoggingOptions() {
80
- return ElImpl.logging;
81
- }
82
- static setDefaultLoggingOptions(logging) {
83
- ElImpl.logging = logging;
84
- }
85
- }
86
- Verstak.shortFrameDuration = 16;
87
- Verstak.longFrameDuration = 300;
88
- Verstak.currentUpdatePriority = Priority.Realtime;
89
- Verstak.frameDuration = Verstak.longFrameDuration;
90
- export class BaseDriver {
91
- constructor(name, isSeparator, preset) {
92
- this.name = name;
93
- this.isSeparator = isSeparator;
94
- this.preset = preset;
95
- }
96
- specify(element) {
97
- chainedSpecify(element, element.node.spec);
98
- }
99
- create(element) {
100
- chainedCreate(element, element.node.spec);
101
- }
102
- initialize(element) {
103
- var _a;
104
- (_a = this.preset) === null || _a === void 0 ? void 0 : _a.call(this, element);
105
- chainedInitialize(element, element.node.spec);
106
- }
107
- mount(element) {
108
- }
109
- update(element) {
110
- chainedUpdated(element, element.node.spec);
111
- }
112
- finalize(element, isLeader) {
113
- chainedFinalize(element, element.node.spec);
114
- return isLeader;
115
- }
116
- applyKind(element, value) { }
117
- applyCoords(element, value) { }
118
- applyWidthGrowth(element, value) { }
119
- applyMinWidth(element, value) { }
120
- applyMaxWidth(element, value) { }
121
- applyHeightGrowth(element, value) { }
122
- applyMinHeight(element, value) { }
123
- applyMaxHeight(element, value) { }
124
- applyContentAlignment(element, value) { }
125
- applyElementAlignment(element, value) { }
126
- applyContentWrapping(element, value) { }
127
- applyOverlayVisible(element, value) { }
128
- applyStyle(element, secondary, styleName, enabled) { }
129
- }
130
- BaseDriver.fragment = new BaseDriver("fragment", false, el => el.kind = ElKind.Group);
131
- function generateKey(owner) {
132
- const n = owner.node.numerator++;
133
- const lettered = emitLetters(n);
134
- let result;
135
- if (Rx.isLogging)
136
- result = `·${getCallerInfo(lettered)}`;
137
- else
138
- result = `·${lettered}`;
139
- return result;
140
- }
141
- function chainedMode(bb) {
142
- var _a;
143
- return (_a = bb === null || bb === void 0 ? void 0 : bb.mode) !== null && _a !== void 0 ? _a : ((bb === null || bb === void 0 ? void 0 : bb.base) ? chainedMode(bb === null || bb === void 0 ? void 0 : bb.base) : Mode.Default);
144
- }
145
- function chainedSpecify(element, elb) {
146
- const specify = elb.specify;
147
- const base = elb.base;
148
- if (specify)
149
- specify(element, base ? () => chainedSpecify(element, base) : NOP);
150
- else if (base)
151
- chainedSpecify(element, base);
152
- }
153
- function chainedCreate(element, elb) {
154
- const create = elb.create;
155
- const base = elb.base;
156
- if (create)
157
- create(element, base ? () => chainedCreate(element, base) : NOP);
158
- else if (base)
159
- chainedCreate(element, base);
160
- }
161
- function chainedInitialize(element, elb) {
162
- const initialize = elb.initialize;
163
- const base = elb.base;
164
- if (initialize)
165
- initialize(element, base ? () => chainedInitialize(element, base) : NOP);
166
- else if (base)
167
- chainedInitialize(element, base);
168
- }
169
- function chainedUpdated(element, elb) {
170
- const update = elb.update;
171
- const base = elb.base;
172
- if (update)
173
- update(element, base ? () => chainedUpdated(element, base) : NOP);
174
- else if (base)
175
- chainedUpdated(element, base);
176
- }
177
- function chainedFinalize(element, elb) {
178
- const finalize = elb.finalize;
179
- const base = elb.base;
180
- if (finalize)
181
- finalize(element, base ? () => chainedFinalize(element, base) : NOP);
182
- else if (base)
183
- chainedFinalize(element, base);
184
- }
185
- export class StaticDriver extends BaseDriver {
186
- constructor(native, name, isRow, preset) {
187
- super(name, isRow, preset);
188
- this.native = native;
189
- }
190
- create(element) {
191
- element.native = this.native;
192
- }
193
- }
194
- export class CursorCommand {
195
- }
196
- export class CursorCommandDriver extends BaseDriver {
197
- constructor() {
198
- super("cursor", false, el => el.kind = ElKind.Cursor);
199
- }
200
- create(element) {
201
- element.native = new CursorCommand();
202
- super.create(element);
203
- }
204
- }
205
- export class SubTreeVariable {
206
- constructor(defaultValue) {
207
- this.defaultValue = defaultValue;
208
- }
209
- set value(value) {
210
- ElImpl.setSubTreeVariableValue(this, value);
211
- }
212
- get value() {
213
- return ElImpl.useSubTreeVariableValue(this);
214
- }
215
- get valueOrUndefined() {
216
- return ElImpl.tryUseSubTreeVariable(this);
217
- }
218
- }
219
- class CursorPosition {
220
- constructor(prev) {
221
- this.x = prev.x;
222
- this.y = prev.y;
223
- this.runningMaxX = prev.runningMaxX;
224
- this.runningMaxY = prev.runningMaxY;
225
- this.flags = prev.flags & ~CursorFlags.OwnCursorPosition;
226
- }
227
- }
228
- var CursorFlags;
229
- (function (CursorFlags) {
230
- CursorFlags[CursorFlags["None"] = 0] = "None";
231
- CursorFlags[CursorFlags["OwnCursorPosition"] = 1] = "OwnCursorPosition";
232
- CursorFlags[CursorFlags["UsesRunningColumnCount"] = 2] = "UsesRunningColumnCount";
233
- CursorFlags[CursorFlags["UsesRunningRowCount"] = 4] = "UsesRunningRowCount";
234
- })(CursorFlags || (CursorFlags = {}));
235
- const UndefinedElCoords = Object.freeze({ x1: 0, y1: 0, x2: 0, y2: 0 });
236
- const InitialCursorPosition = Object.freeze(new CursorPosition({ x: 1, y: 1, runningMaxX: 0, runningMaxY: 0, flags: CursorFlags.None }));
237
- class RxNodeCtxImpl extends ObservableObject {
238
- constructor(variable, value) {
239
- super();
240
- this.next = undefined;
241
- this.variable = variable;
242
- this.value = value;
243
- }
244
- }
245
- __decorate([
246
- raw,
247
- __metadata("design:type", Object)
248
- ], RxNodeCtxImpl.prototype, "next", void 0);
249
- __decorate([
250
- raw,
251
- __metadata("design:type", SubTreeVariable)
252
- ], RxNodeCtxImpl.prototype, "variable", void 0);
253
- class RxNodeImpl {
254
- constructor(key, driver, spec, element, owner) {
255
- this.key = key;
256
- this.driver = driver;
257
- this.spec = spec;
258
- if (owner) {
259
- const node = owner;
260
- this.level = node.level + 1;
261
- this.owner = owner;
262
- this.outer = node.context ? owner : node.outer;
263
- }
264
- else {
265
- this.level = 1;
266
- this.owner = owner = this;
267
- this.outer = this;
268
- }
269
- this.host = this;
270
- this.children = new MergeList(getNodeKey, true);
271
- this.slot = undefined;
272
- this.stamp = Number.MAX_SAFE_INTEGER;
273
- this.context = undefined;
274
- this.numerator = 0;
275
- this.priority = Priority.Realtime;
276
- this.childrenShuffling = false;
277
- RxNodeImpl.grandNodeCount++;
278
- if (this.has(Mode.PinpointUpdate))
279
- RxNodeImpl.disposableNodeCount++;
280
- }
281
- get isInitialUpdate() { return this.stamp === 1; }
282
- get strictOrder() { return this.children.isStrict; }
283
- set strictOrder(value) { this.children.isStrict = value; }
284
- get isMoved() { return this.owner.children.isMoved(this.slot); }
285
- has(mode) {
286
- return (chainedMode(this.spec) & mode) === mode;
287
- }
288
- update(_triggers) {
289
- updateNow(this.slot);
290
- }
291
- }
292
- RxNodeImpl.grandNodeCount = 0;
293
- RxNodeImpl.disposableNodeCount = 0;
294
- __decorate([
295
- reactive,
296
- options({
297
- reentrance: Reentrance.CancelPrevious,
298
- triggeringArgs: true,
299
- noSideEffects: false,
300
- }),
301
- __metadata("design:type", Function),
302
- __metadata("design:paramtypes", [Object]),
303
- __metadata("design:returntype", void 0)
304
- ], RxNodeImpl.prototype, "update", null);
305
- class ElImpl {
306
- constructor(key, driver, owner, spec) {
307
- this.node = new RxNodeImpl(key, driver, spec, this, owner === null || owner === void 0 ? void 0 : owner.node);
308
- this.maxColumnCount = 0;
309
- this.maxRowCount = 0;
310
- this.cursorPosition = undefined;
311
- this.native = undefined;
312
- this.model = undefined;
313
- this.controller = undefined;
314
- this._kind = ElKind.Row;
315
- this._area = undefined;
316
- this._coords = UndefinedElCoords;
317
- this._widthGrowth = 0;
318
- this._minWidth = "";
319
- this._maxWidth = "";
320
- this._heightGrowth = 0;
321
- this._minHeight = "";
322
- this._maxHeight = "";
323
- this._contentAlignment = Align.Default;
324
- this._elementAlignment = Align.Default;
325
- this._contentWrapping = true;
326
- this._overlayVisible = undefined;
327
- this._hasStyles = false;
328
- }
329
- prepareForUpdate() {
330
- this._area = undefined;
331
- this._hasStyles = false;
332
- }
333
- get isAuxiliary() { return this.kind > ElKind.Note; }
334
- get isSection() { return this.kind === ElKind.Section; }
335
- get isTable() { return this.kind === ElKind.Table; }
336
- get kind() { return this._kind; }
337
- set kind(value) {
338
- if (value !== this._kind || this.node.stamp >= Number.MAX_SAFE_INTEGER - 1) {
339
- this.node.driver.applyKind(this, value);
340
- this._kind = value;
341
- }
342
- }
343
- get area() { return this._area; }
344
- set area(value) {
345
- var _a, _b;
346
- const node = this.node;
347
- const driver = node.driver;
348
- if (!driver.isSeparator) {
349
- const owner = node.owner;
350
- const ownerEl = owner.slot.instance;
351
- const cursorPosition = (_b = (_a = node.slot.prev) === null || _a === void 0 ? void 0 : _a.instance.cursorPosition) !== null && _b !== void 0 ? _b : InitialCursorPosition;
352
- const newCursorPosition = this.cursorPosition = owner.children.isStrict ? new CursorPosition(cursorPosition) : undefined;
353
- const isCursorElement = driver instanceof CursorCommandDriver;
354
- const coords = getEffectiveElCoords(!isCursorElement, value, ownerEl.maxColumnCount, ownerEl.maxRowCount, cursorPosition, newCursorPosition);
355
- if (!equalElCoords(coords, this._coords)) {
356
- driver.applyCoords(this, coords);
357
- this._coords = coords;
358
- }
359
- this._area = value !== null && value !== void 0 ? value : {};
360
- }
361
- else
362
- this.rowBreak();
363
- }
364
- get widthGrowth() { return this._widthGrowth; }
365
- set widthGrowth(value) {
366
- if (value !== this._widthGrowth) {
367
- this.node.driver.applyWidthGrowth(this, value);
368
- this._widthGrowth = value;
369
- }
370
- }
371
- get minWidth() { return this._minWidth; }
372
- set minWidth(value) {
373
- if (value !== this._minWidth) {
374
- this.node.driver.applyMinWidth(this, value);
375
- this._minWidth = value;
376
- }
377
- }
378
- get maxWidth() { return this._maxWidth; }
379
- set maxWidth(value) {
380
- if (value !== this._maxWidth) {
381
- this.node.driver.applyMaxWidth(this, value);
382
- this._maxWidth = value;
383
- }
384
- }
385
- get heightGrowth() { return this._heightGrowth; }
386
- set heightGrowth(value) {
387
- if (value !== this._heightGrowth) {
388
- this.node.driver.applyHeightGrowth(this, value);
389
- this._heightGrowth = value;
390
- }
391
- }
392
- get minHeight() { return this._minHeight; }
393
- set minHeight(value) {
394
- if (value !== this._minHeight) {
395
- this.node.driver.applyMinHeight(this, value);
396
- this._minHeight = value;
397
- }
398
- }
399
- get maxHeight() { return this._maxHeight; }
400
- set maxHeight(value) {
401
- if (value !== this._maxHeight) {
402
- this.node.driver.applyMaxHeight(this, value);
403
- this._maxHeight = value;
404
- }
405
- }
406
- get contentAlignment() { return this._contentAlignment; }
407
- set contentAlignment(value) {
408
- if (value !== this._contentAlignment) {
409
- this.node.driver.applyContentAlignment(this, value);
410
- this._contentAlignment = value;
411
- }
412
- }
413
- get elementAlignment() { return this._elementAlignment; }
414
- set elementAlignment(value) {
415
- if (value !== this._elementAlignment) {
416
- this.node.driver.applyElementAlignment(this, value);
417
- this._elementAlignment = value;
418
- }
419
- }
420
- get contentWrapping() { return this._contentWrapping; }
421
- set contentWrapping(value) {
422
- if (value !== this._contentWrapping) {
423
- this.node.driver.applyContentWrapping(this, value);
424
- this._contentWrapping = value;
425
- }
426
- }
427
- get overlayVisible() { return this._overlayVisible; }
428
- set overlayVisible(value) {
429
- if (value !== this._overlayVisible) {
430
- this.node.driver.applyOverlayVisible(this, value);
431
- this._overlayVisible = value;
432
- }
433
- }
434
- useStyle(styleName, enabled) {
435
- this.node.driver.applyStyle(this, this._hasStyles, styleName, enabled);
436
- this._hasStyles = true;
437
- }
438
- configureReactronic(options) {
439
- const node = this.node;
440
- if (node.stamp < Number.MAX_SAFE_INTEGER - 1 || !node.has(Mode.PinpointUpdate))
441
- throw new Error("reactronic can be configured only for elements with pinpoint update mode and only inside initialize");
442
- return Rx.getReaction(node.update).configure(options);
443
- }
444
- static get curr() {
445
- if (!gCurrent)
446
- throw new Error("current element is undefined");
447
- return gCurrent;
448
- }
449
- static tryUseSubTreeVariable(variable) {
450
- var _a, _b;
451
- let el = ElImpl.curr.instance;
452
- while (((_a = el.node.context) === null || _a === void 0 ? void 0 : _a.variable) !== variable && el.node.owner !== el.node)
453
- el = el.node.outer.slot.instance;
454
- return (_b = el.node.context) === null || _b === void 0 ? void 0 : _b.value;
455
- }
456
- static useSubTreeVariableValue(variable) {
457
- var _a;
458
- const result = (_a = ElImpl.tryUseSubTreeVariable(variable)) !== null && _a !== void 0 ? _a : variable.defaultValue;
459
- if (!result)
460
- throw new Error("context doesn't exist");
461
- return result;
462
- }
463
- static setSubTreeVariableValue(variable, value) {
464
- const el = ElImpl.curr.instance;
465
- const node = el.node;
466
- const owner = node.owner;
467
- const hostCtx = unobs(() => { var _a; return (_a = owner.context) === null || _a === void 0 ? void 0 : _a.value; });
468
- if (value && value !== hostCtx) {
469
- if (hostCtx)
470
- node.outer = owner;
471
- else
472
- node.outer = owner.outer;
473
- Transaction.run({ separation: true }, () => {
474
- const ctx = node.context;
475
- if (ctx) {
476
- ctx.variable = variable;
477
- ctx.value = value;
478
- }
479
- else
480
- node.context = new RxNodeCtxImpl(variable, value);
481
- });
482
- }
483
- else if (hostCtx)
484
- node.outer = owner;
485
- else
486
- node.outer = owner.outer;
487
- }
488
- rowBreak() {
489
- var _a, _b;
490
- const node = this.node;
491
- const cursorPosition = (_b = (_a = node.slot.prev) === null || _a === void 0 ? void 0 : _a.instance.cursorPosition) !== null && _b !== void 0 ? _b : InitialCursorPosition;
492
- const newCursorPosition = this.cursorPosition = new CursorPosition(cursorPosition);
493
- newCursorPosition.x = 1;
494
- newCursorPosition.y = newCursorPosition.runningMaxY + 1;
495
- }
496
- }
497
- ElImpl.logging = undefined;
498
- function getNodeKey(element) {
499
- const node = element.node;
500
- return node.stamp >= 0 ? node.key : undefined;
501
- }
502
- function getEffectiveElCoords(isRegularElement, area, maxX, maxY, cursorPosition, newCursorPosition) {
503
- var _a, _b;
504
- let result;
505
- if (typeof (area) === "string") {
506
- result = parseElCoords(area, { x1: 0, y1: 0, x2: 0, y2: 0 });
507
- absolutizeElCoords(result, cursorPosition.x, cursorPosition.y, maxX || Infinity, maxY || Infinity, result);
508
- if (newCursorPosition) {
509
- newCursorPosition.x = isRegularElement ? result.x2 + 1 : result.x1;
510
- newCursorPosition.y = result.y1;
511
- newCursorPosition.flags = CursorFlags.OwnCursorPosition;
512
- }
513
- }
514
- else if (newCursorPosition) {
515
- let dx;
516
- let dy;
517
- if (area) {
518
- dx = (_a = area.cellsOverWidth) !== null && _a !== void 0 ? _a : 1;
519
- dy = (_b = area.cellsOverHeight) !== null && _b !== void 0 ? _b : 1;
520
- }
521
- else
522
- dx = dy = 1;
523
- const runningX = maxX !== 0 ? maxX : cursorPosition.runningMaxX;
524
- const runningY = maxY !== 0 ? maxY : cursorPosition.runningMaxY;
525
- result = { x1: 0, y1: 0, x2: 0, y2: 0 };
526
- if (dx === 0 && isRegularElement) {
527
- dx = runningX || 1;
528
- newCursorPosition.flags = CursorFlags.UsesRunningColumnCount;
529
- }
530
- if (dx >= 0) {
531
- if (isRegularElement) {
532
- result.x1 = cursorPosition.x;
533
- result.x2 = absolutizePosition(result.x1 + dx - 1, 0, maxX || Infinity);
534
- newCursorPosition.x = result.x2 + 1;
535
- }
536
- else {
537
- result.x1 = result.x2 = cursorPosition.x + dx;
538
- newCursorPosition.x = result.x2;
539
- }
540
- }
541
- else {
542
- if (isRegularElement) {
543
- result.x1 = Math.max(cursorPosition.x + dx, 1);
544
- result.x2 = cursorPosition.x;
545
- newCursorPosition.x = result.x2 + 1;
546
- }
547
- else {
548
- result.x1 = result.x2 = cursorPosition.x + dx;
549
- newCursorPosition.x = result.x2;
550
- }
551
- }
552
- if (dy === 0 && isRegularElement) {
553
- dy = runningY || 1;
554
- newCursorPosition.flags |= CursorFlags.UsesRunningRowCount;
555
- }
556
- if (dy >= 0) {
557
- if (isRegularElement) {
558
- result.y1 = cursorPosition.y;
559
- result.y2 = absolutizePosition(result.y1 + dy - 1, 0, maxY || Infinity);
560
- if (result.y2 > newCursorPosition.runningMaxY)
561
- newCursorPosition.runningMaxY = result.y2;
562
- }
563
- else
564
- result.y1 = result.y2 = cursorPosition.y + dy;
565
- }
566
- else {
567
- if (isRegularElement) {
568
- result.y1 = Math.max(cursorPosition.y + dy, 1);
569
- result.y2 = cursorPosition.y;
570
- }
571
- else
572
- result.y1 = result.y2 = cursorPosition.y + dy;
573
- }
574
- }
575
- else
576
- throw new Error("relative layout requires sequential children");
577
- return result;
578
- }
579
- function runUpdateNestedTreesThenDo(error, action) {
580
- var _a;
581
- const curr = ElImpl.curr;
582
- const owner = curr.instance;
583
- const children = owner.node.children;
584
- if (children.isMergeInProgress) {
585
- let promised = undefined;
586
- try {
587
- children.endMerge(error);
588
- for (const slot of children.removedItems(true))
589
- triggerFinalization(slot, true, true);
590
- if (!error) {
591
- const ownerIsSection = owner.isSection;
592
- const sequential = children.isStrict;
593
- let p1 = undefined;
594
- let p2 = undefined;
595
- let mounting = false;
596
- let hostingRow = owner;
597
- for (const slot of children.items()) {
598
- if (Transaction.isCanceled)
599
- break;
600
- const el = slot.instance;
601
- const isSeparator = el.node.driver.isSeparator;
602
- const host = isSeparator ? owner : hostingRow;
603
- const p = (_a = el.node.priority) !== null && _a !== void 0 ? _a : Priority.Realtime;
604
- mounting = markToMountIfNecessary(mounting, host, slot, children, sequential);
605
- if (p === Priority.Realtime)
606
- triggerUpdate(slot);
607
- else if (p === Priority.Normal)
608
- p1 = push(slot, p1);
609
- else
610
- p2 = push(slot, p2);
611
- if (ownerIsSection && isSeparator)
612
- hostingRow = el;
613
- }
614
- if (!Transaction.isCanceled && (p1 !== undefined || p2 !== undefined))
615
- promised = startIncrementalUpdate(curr, children, p1, p2).then(() => action(error), e => action(e));
616
- }
617
- }
618
- finally {
619
- if (!promised)
620
- action(error);
621
- }
622
- }
623
- }
624
- function markToMountIfNecessary(mounting, host, slot, children, sequential) {
625
- const el = slot.instance;
626
- const node = el.node;
627
- if (el.native && !node.has(Mode.ManualMount)) {
628
- if (mounting || node.host !== host.node) {
629
- children.markAsMoved(slot);
630
- mounting = false;
631
- }
632
- }
633
- else if (sequential && children.isMoved(slot))
634
- mounting = true;
635
- node.host = host.node;
636
- return mounting;
637
- }
638
- function startIncrementalUpdate(owner, allChildren, priority1, priority2) {
639
- return __awaiter(this, void 0, void 0, function* () {
640
- const stamp = owner.instance.node.stamp;
641
- if (priority1)
642
- yield updateIncrementally(owner, stamp, allChildren, priority1, Priority.Normal);
643
- if (priority2)
644
- yield updateIncrementally(owner, stamp, allChildren, priority2, Priority.Background);
645
- });
646
- }
647
- function updateIncrementally(owner, stamp, allChildren, items, priority) {
648
- return __awaiter(this, void 0, void 0, function* () {
649
- yield Transaction.requestNextFrame();
650
- const el = owner.instance;
651
- if (!Transaction.isCanceled || !Transaction.isFrameOver(1, Verstak.shortFrameDuration / 3)) {
652
- let outerPriority = Verstak.currentUpdatePriority;
653
- Verstak.currentUpdatePriority = priority;
654
- try {
655
- if (el.node.childrenShuffling)
656
- shuffle(items);
657
- const frameDurationLimit = priority === Priority.Background ? Verstak.shortFrameDuration : Infinity;
658
- let frameDuration = Math.min(frameDurationLimit, Math.max(Verstak.frameDuration / 4, Verstak.shortFrameDuration));
659
- for (const child of items) {
660
- triggerUpdate(child);
661
- if (Transaction.isFrameOver(1, frameDuration)) {
662
- Verstak.currentUpdatePriority = outerPriority;
663
- yield Transaction.requestNextFrame(0);
664
- outerPriority = Verstak.currentUpdatePriority;
665
- Verstak.currentUpdatePriority = priority;
666
- frameDuration = Math.min(4 * frameDuration, Math.min(frameDurationLimit, Verstak.frameDuration));
667
- }
668
- if (Transaction.isCanceled && Transaction.isFrameOver(1, Verstak.shortFrameDuration / 3))
669
- break;
670
- }
671
- }
672
- finally {
673
- Verstak.currentUpdatePriority = outerPriority;
674
- }
675
- }
676
- });
677
- }
678
- function triggerUpdate(slot) {
679
- const el = slot.instance;
680
- const node = el.node;
681
- if (node.stamp >= 0) {
682
- if (node.has(Mode.PinpointUpdate)) {
683
- if (node.stamp === Number.MAX_SAFE_INTEGER) {
684
- Transaction.outside(() => {
685
- if (Rx.isLogging)
686
- Rx.setLoggingHint(el, node.key);
687
- Rx.getReaction(node.update).configure({
688
- order: node.level,
689
- });
690
- });
691
- }
692
- unobs(node.update, node.spec.triggers);
693
- }
694
- else
695
- updateNow(slot);
696
- }
697
- }
698
- function mountOrRemountIfNecessary(element) {
699
- const node = element.node;
700
- const driver = node.driver;
701
- if (node.stamp === Number.MAX_SAFE_INTEGER) {
702
- node.stamp = Number.MAX_SAFE_INTEGER - 1;
703
- unobs(() => {
704
- driver.create(element);
705
- driver.initialize(element);
706
- if (!node.has(Mode.ManualMount)) {
707
- node.stamp = 0;
708
- if (element.node.host !== element.node)
709
- driver.mount(element);
710
- }
711
- node.stamp = 0;
712
- });
713
- }
714
- else if (node.isMoved && !node.has(Mode.ManualMount) && element.node.host !== element.node)
715
- unobs(() => driver.mount(element));
716
- }
717
- function updateNow(slot) {
718
- const el = slot.instance;
719
- const node = el.node;
720
- if (node.stamp >= 0) {
721
- let result = undefined;
722
- runInside(slot, () => {
723
- mountOrRemountIfNecessary(el);
724
- if (node.stamp < Number.MAX_SAFE_INTEGER - 1) {
725
- try {
726
- node.stamp++;
727
- node.numerator = 0;
728
- el.prepareForUpdate();
729
- node.children.beginMerge();
730
- const driver = node.driver;
731
- result = driver.update(el);
732
- if (el.area === undefined && node.owner.slot.instance.isTable)
733
- el.area = undefined;
734
- if (result instanceof Promise)
735
- result.then(v => { runUpdateNestedTreesThenDo(undefined, NOP); return v; }, e => { console.log(e); runUpdateNestedTreesThenDo(e !== null && e !== void 0 ? e : new Error("unknown error"), NOP); });
736
- else
737
- runUpdateNestedTreesThenDo(undefined, NOP);
738
- }
739
- catch (e) {
740
- runUpdateNestedTreesThenDo(e, NOP);
741
- console.log(`Update failed: ${node.key}`);
742
- console.log(`${e}`);
743
- }
744
- }
745
- });
746
- }
747
- }
748
- function triggerFinalization(slot, isLeader, individual) {
749
- const el = slot.instance;
750
- const node = el.node;
751
- if (node.stamp >= 0) {
752
- const driver = node.driver;
753
- if (individual && node.key !== node.spec.key && !driver.isSeparator)
754
- console.log(`WARNING: it is recommended to assign explicit key for conditional element in order to avoid unexpected side effects: ${node.key}`);
755
- node.stamp = ~node.stamp;
756
- const childrenAreLeaders = unobs(() => driver.finalize(el, isLeader));
757
- el.native = null;
758
- el.controller = null;
759
- if (node.has(Mode.PinpointUpdate)) {
760
- slot.aux = undefined;
761
- const last = gLastToDispose;
762
- if (last)
763
- gLastToDispose = last.aux = slot;
764
- else
765
- gFirstToDispose = gLastToDispose = slot;
766
- if (gFirstToDispose === slot)
767
- Transaction.run({ separation: "disposal", hint: `runDisposalLoop(initiator=${slot.instance.node.key})` }, () => {
768
- void runDisposalLoop().then(NOP, error => console.log(error));
769
- });
770
- }
771
- for (const slot of node.children.items())
772
- triggerFinalization(slot, childrenAreLeaders, false);
773
- RxNodeImpl.grandNodeCount--;
774
- }
775
- }
776
- function runDisposalLoop() {
777
- return __awaiter(this, void 0, void 0, function* () {
778
- yield Transaction.requestNextFrame();
779
- let slot = gFirstToDispose;
780
- while (slot !== undefined) {
781
- if (Transaction.isFrameOver(500, 5))
782
- yield Transaction.requestNextFrame();
783
- Rx.dispose(slot.instance);
784
- slot = slot.aux;
785
- RxNodeImpl.disposableNodeCount--;
786
- }
787
- gFirstToDispose = gLastToDispose = undefined;
788
- });
789
- }
790
- function wrapToRunInside(func) {
791
- let wrappedToRunInside;
792
- const current = gCurrent;
793
- if (current)
794
- wrappedToRunInside = (...args) => {
795
- return runInside(current, func, ...args);
796
- };
797
- else
798
- wrappedToRunInside = func;
799
- return wrappedToRunInside;
800
- }
801
- function runInside(slot, func, ...args) {
802
- const outer = gCurrent;
803
- try {
804
- gCurrent = slot;
805
- return func(...args);
806
- }
807
- finally {
808
- gCurrent = outer;
809
- }
810
- }
811
- function triggersAreEqual(a1, a2) {
812
- let result = a1 === a2;
813
- if (!result) {
814
- if (Array.isArray(a1)) {
815
- result = Array.isArray(a2) &&
816
- a1.length === a2.length &&
817
- a1.every((t, i) => t === a2[i]);
818
- }
819
- else if (a1 === Object(a1) && a2 === Object(a2)) {
820
- for (const p in a1) {
821
- result = a1[p] === a2[p];
822
- if (!result)
823
- break;
824
- }
825
- }
826
- }
827
- return result;
828
- }
829
- function absolutizeElCoords(area, cursorX, cursorY, maxWidth, maxHeight, result) {
830
- const x1 = absolutizePosition(area.x1, cursorX, maxWidth);
831
- const x2 = absolutizePosition(area.x2, x1, maxWidth);
832
- if (x1 <= x2)
833
- result.x1 = x1, result.x2 = x2;
834
- else
835
- result.x1 = x2, result.x2 = x1;
836
- const y1 = absolutizePosition(area.y1, cursorY, maxHeight);
837
- const y2 = absolutizePosition(area.y2, y1, maxHeight);
838
- if (y1 <= y2)
839
- result.y1 = y1, result.y2 = y2;
840
- else
841
- result.y1 = y2, result.y2 = y1;
842
- return result;
843
- }
844
- function absolutizePosition(pos, cursor, max) {
845
- if (pos === 0)
846
- pos = cursor;
847
- else if (pos < 0)
848
- pos = Math.max(max + pos, 1);
849
- else
850
- pos = Math.min(pos, max);
851
- return pos;
852
- }
853
- function push(item, array) {
854
- if (array == undefined)
855
- array = new Array();
856
- array.push(item);
857
- return array;
858
- }
859
- function shuffle(array) {
860
- const n = array.length - 1;
861
- let i = n;
862
- while (i >= 0) {
863
- const j = Math.floor(Math.random() * n);
864
- const t = array[i];
865
- array[i] = array[j];
866
- array[j] = t;
867
- i--;
868
- }
869
- return array;
870
- }
871
- const ORIGINAL_PROMISE_THEN = Promise.prototype.then;
872
- function reactronicDomHookedThen(resolve, reject) {
873
- resolve = resolve ? wrapToRunInside(resolve) : defaultResolve;
874
- reject = reject ? wrapToRunInside(reject) : defaultReject;
875
- return ORIGINAL_PROMISE_THEN.call(this, resolve, reject);
876
- }
877
- function defaultResolve(value) {
878
- return value;
879
- }
880
- function defaultReject(error) {
881
- throw error;
882
- }
883
- Promise.prototype.then = reactronicDomHookedThen;
884
- const NOP = (...args) => { };
885
- let gCurrent = undefined;
886
- let gFirstToDispose = undefined;
887
- let gLastToDispose = undefined;