mol_wire_lib 1.0.836 → 1.0.838

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/node.mjs CHANGED
@@ -983,480 +983,639 @@ var $;
983
983
  "use strict";
984
984
  var $;
985
985
  (function ($) {
986
- class $mol_wire_task extends $mol_wire_fiber {
987
- static getter(task) {
988
- return function $mol_wire_task_get(host, args) {
989
- const sub = $mol_wire_auto();
990
- const existen = sub?.track_next();
991
- reuse: if (existen) {
992
- if (!existen.temp)
993
- break reuse;
994
- if (existen.host !== host)
995
- break reuse;
996
- if (existen.task !== task)
997
- break reuse;
998
- if (!$mol_compare_deep(existen.args, args))
999
- break reuse;
1000
- return existen;
1001
- }
1002
- return new $mol_wire_task(`${host?.[Symbol.toStringTag] ?? host}.${task.name}(#)`, task, host, args);
1003
- };
1004
- }
1005
- get temp() {
1006
- return true;
1007
- }
1008
- complete() {
1009
- if ($mol_promise_like(this.cache))
1010
- return;
1011
- this.destructor();
1012
- }
1013
- put(next) {
1014
- const prev = this.cache;
1015
- this.cache = next;
1016
- if ($mol_promise_like(next)) {
1017
- this.cursor = $mol_wire_cursor.fresh;
1018
- if (next !== prev)
1019
- this.emit();
1020
- return next;
1021
- }
1022
- this.cursor = $mol_wire_cursor.final;
1023
- if (this.sub_empty)
1024
- this.destructor();
1025
- else if (next !== prev)
1026
- this.emit();
1027
- return next;
1028
- }
1029
- }
1030
- $.$mol_wire_task = $mol_wire_task;
1031
- })($ || ($ = {}));
1032
- //mol/wire/task/task.ts
1033
- ;
1034
- "use strict";
1035
- var $;
1036
- (function ($) {
1037
- function $mol_guid(length = 8, exists = () => false) {
1038
- for (;;) {
1039
- let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
1040
- if (exists(id))
1041
- continue;
1042
- return id;
1043
- }
1044
- }
1045
- $.$mol_guid = $mol_guid;
1046
- })($ || ($ = {}));
1047
- //mol/guid/guid.ts
1048
- ;
1049
- "use strict";
1050
- var $;
1051
- (function ($) {
1052
- $.$mol_key_store = new WeakMap();
1053
- function $mol_key(value) {
1054
- if (typeof value === 'bigint')
1055
- return value.toString() + 'n';
1056
- if (!value)
1057
- return JSON.stringify(value);
1058
- if (typeof value !== 'object' && typeof value !== 'function')
1059
- return JSON.stringify(value);
1060
- return JSON.stringify(value, (field, value) => {
1061
- if (typeof value === 'bigint')
1062
- return value.toString() + 'n';
1063
- if (!value)
1064
- return value;
1065
- if (typeof value !== 'object' && typeof value !== 'function')
1066
- return value;
1067
- if (Array.isArray(value))
1068
- return value;
1069
- const proto = Reflect.getPrototypeOf(value);
1070
- if (!proto)
1071
- return value;
1072
- if (Reflect.getPrototypeOf(proto) === null)
1073
- return value;
1074
- if ('toJSON' in value)
1075
- return value;
1076
- if (value instanceof RegExp)
1077
- return value.toString();
1078
- if (value instanceof Uint8Array)
1079
- return [...value];
1080
- let key = $.$mol_key_store.get(value);
1081
- if (key)
1082
- return key;
1083
- key = $mol_guid();
1084
- $.$mol_key_store.set(value, key);
1085
- return key;
986
+ function $mol_log3_area_lazy(event) {
987
+ const self = this;
988
+ const stack = self.$mol_log3_stack;
989
+ const deep = stack.length;
990
+ let logged = false;
991
+ stack.push(() => {
992
+ logged = true;
993
+ self.$mol_log3_area.call(self, event);
1086
994
  });
995
+ return () => {
996
+ if (logged)
997
+ self.console.groupEnd();
998
+ if (stack.length > deep)
999
+ stack.length = deep;
1000
+ };
1087
1001
  }
1088
- $.$mol_key = $mol_key;
1002
+ $.$mol_log3_area_lazy = $mol_log3_area_lazy;
1003
+ $.$mol_log3_stack = [];
1089
1004
  })($ || ($ = {}));
1090
- //mol/key/key.ts
1005
+ //mol/log3/log3.ts
1091
1006
  ;
1092
1007
  "use strict";
1093
1008
  var $;
1094
1009
  (function ($) {
1095
- function $mol_wire_method(host, field, descr) {
1096
- if (!descr)
1097
- descr = Reflect.getOwnPropertyDescriptor(host, field);
1098
- const orig = descr?.value ?? host[field];
1099
- const sup = Reflect.getPrototypeOf(host);
1100
- if (typeof sup[field] === 'function') {
1101
- Object.defineProperty(orig, 'name', { value: sup[field].name });
1010
+ class $mol_span extends $mol_object2 {
1011
+ uri;
1012
+ source;
1013
+ row;
1014
+ col;
1015
+ length;
1016
+ constructor(uri, source, row, col, length) {
1017
+ super();
1018
+ this.uri = uri;
1019
+ this.source = source;
1020
+ this.row = row;
1021
+ this.col = col;
1022
+ this.length = length;
1023
+ this[Symbol.toStringTag] = `${this.uri}#${this.row}:${this.col}/${this.length}`;
1024
+ }
1025
+ static unknown = $mol_span.begin('?');
1026
+ static begin(uri, source = '') {
1027
+ return new $mol_span(uri, source, 1, 1, 0);
1028
+ }
1029
+ static end(uri, source) {
1030
+ return new $mol_span(uri, source, 1, source.length + 1, 0);
1031
+ }
1032
+ static entire(uri, source) {
1033
+ return new $mol_span(uri, source, 1, 1, source.length);
1034
+ }
1035
+ toString() {
1036
+ return this[Symbol.toStringTag];
1037
+ }
1038
+ toJSON() {
1039
+ return {
1040
+ uri: this.uri,
1041
+ row: this.row,
1042
+ col: this.col,
1043
+ length: this.length
1044
+ };
1045
+ }
1046
+ error(message, Class = Error) {
1047
+ return new Class(`${message}${this}`);
1048
+ }
1049
+ span(row, col, length) {
1050
+ return new $mol_span(this.uri, this.source, row, col, length);
1051
+ }
1052
+ after(length = 0) {
1053
+ return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
1054
+ }
1055
+ slice(begin, end = -1) {
1056
+ let len = this.length;
1057
+ if (begin < 0)
1058
+ begin += len;
1059
+ if (end < 0)
1060
+ end += len;
1061
+ if (begin < 0 || begin > len)
1062
+ this.$.$mol_fail(`Begin value '${begin}' out of range ${this}`);
1063
+ if (end < 0 || end > len)
1064
+ this.$.$mol_fail(`End value '${end}' out of range ${this}`);
1065
+ if (end < begin)
1066
+ this.$.$mol_fail(`End value '${end}' can't be less than begin value ${this}`);
1067
+ return this.span(this.row, this.col + begin, end - begin);
1102
1068
  }
1103
- const temp = $mol_wire_task.getter(orig);
1104
- const value = function (...args) {
1105
- const fiber = temp(this ?? null, args);
1106
- return fiber.sync();
1107
- };
1108
- Object.defineProperty(value, 'name', { value: orig.name + ' ' });
1109
- Object.assign(value, { orig });
1110
- const descr2 = { ...descr, value };
1111
- Reflect.defineProperty(host, field, descr2);
1112
- return descr2;
1113
1069
  }
1114
- $.$mol_wire_method = $mol_wire_method;
1070
+ $.$mol_span = $mol_span;
1115
1071
  })($ || ($ = {}));
1116
- //mol/wire/method/method.ts
1117
- ;
1118
- "use strict";
1119
- //mol/type/tail/tail.ts
1120
- ;
1121
- "use strict";
1122
- //mol/type/foot/foot.ts
1072
+ //mol/span/span.ts
1123
1073
  ;
1124
1074
  "use strict";
1125
1075
  var $;
1126
1076
  (function ($) {
1127
- const catched = new WeakMap();
1128
- function $mol_fail_catch(error) {
1129
- if (typeof error !== 'object')
1130
- return false;
1131
- if ($mol_promise_like(error))
1132
- $mol_fail_hidden(error);
1133
- if (catched.get(error))
1134
- return false;
1135
- catched.set(error, true);
1136
- return true;
1077
+ function $mol_tree2_to_string(tree) {
1078
+ let output = [];
1079
+ function dump(tree, prefix = '') {
1080
+ if (tree.type.length) {
1081
+ if (!prefix.length) {
1082
+ prefix = "\t";
1083
+ }
1084
+ output.push(tree.type);
1085
+ if (tree.kids.length == 1) {
1086
+ output.push(' ');
1087
+ dump(tree.kids[0], prefix);
1088
+ return;
1089
+ }
1090
+ output.push("\n");
1091
+ }
1092
+ else if (tree.value.length || prefix.length) {
1093
+ output.push("\\" + tree.value + "\n");
1094
+ }
1095
+ for (const kid of tree.kids) {
1096
+ output.push(prefix);
1097
+ dump(kid, prefix + "\t");
1098
+ }
1099
+ }
1100
+ dump(tree);
1101
+ return output.join('');
1137
1102
  }
1138
- $.$mol_fail_catch = $mol_fail_catch;
1103
+ $.$mol_tree2_to_string = $mol_tree2_to_string;
1139
1104
  })($ || ($ = {}));
1140
- //mol/fail/catch/catch.ts
1105
+ //mol/tree2/to/string/string.ts
1141
1106
  ;
1142
1107
  "use strict";
1143
1108
  var $;
1144
1109
  (function ($) {
1145
- function $mol_fail_log(error) {
1146
- if ($mol_promise_like(error))
1147
- return false;
1148
- if (!$mol_fail_catch(error))
1149
- return false;
1150
- console.error(error);
1151
- return true;
1152
- }
1153
- $.$mol_fail_log = $mol_fail_log;
1154
- })($ || ($ = {}));
1155
- //mol/fail/log/log.ts
1156
- ;
1157
- "use strict";
1158
- var $;
1159
- (function ($) {
1160
- class $mol_wire_atom extends $mol_wire_fiber {
1161
- static solo(host, task) {
1162
- const field = task.name + '()';
1163
- const existen = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
1164
- if (existen)
1165
- return existen;
1166
- const prefix = host?.[Symbol.toStringTag] ?? (host instanceof Function ? $$.$mol_func_name(host) : host);
1167
- const key = `${prefix}.${field}`;
1168
- const fiber = new $mol_wire_atom(key, task, host, []);
1169
- (host ?? task)[field] = fiber;
1170
- return fiber;
1110
+ class $mol_tree2 extends Object {
1111
+ type;
1112
+ value;
1113
+ kids;
1114
+ span;
1115
+ constructor(type, value, kids, span) {
1116
+ super();
1117
+ this.type = type;
1118
+ this.value = value;
1119
+ this.kids = kids;
1120
+ this.span = span;
1121
+ this[Symbol.toStringTag] = type || '\\' + value;
1171
1122
  }
1172
- static plex(host, task, key) {
1173
- const field = task.name + '()';
1174
- let dict = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
1175
- const prefix = host?.[Symbol.toStringTag] ?? (host instanceof Function ? $$.$mol_func_name(host) : host);
1176
- const id = `${prefix}.${task.name}(${$mol_key(key).replace(/^"|"$/g, "'")})`;
1177
- if (dict) {
1178
- const existen = dict.get(id);
1179
- if (existen)
1180
- return existen;
1181
- }
1182
- else {
1183
- dict = (host ?? task)[field] = new Map();
1123
+ static list(kids, span = $mol_span.unknown) {
1124
+ return new $mol_tree2('', '', kids, span);
1125
+ }
1126
+ list(kids) {
1127
+ return $mol_tree2.list(kids, this.span);
1128
+ }
1129
+ static data(value, kids = [], span = $mol_span.unknown) {
1130
+ const chunks = value.split('\n');
1131
+ if (chunks.length > 1) {
1132
+ let kid_span = span.span(span.row, span.col, 0);
1133
+ const data = chunks.map(chunk => {
1134
+ kid_span = kid_span.after(chunk.length);
1135
+ return new $mol_tree2('', chunk, [], kid_span);
1136
+ });
1137
+ kids = [...data, ...kids];
1138
+ value = '';
1184
1139
  }
1185
- const fiber = new $mol_wire_atom(id, task, host, [key]);
1186
- dict.set(id, fiber);
1187
- return fiber;
1140
+ return new $mol_tree2('', value, kids, span);
1188
1141
  }
1189
- static watching = new Set();
1190
- static watcher = null;
1191
- static watch() {
1192
- $mol_wire_atom.watcher = new $mol_after_frame($mol_wire_atom.watch);
1193
- for (const atom of $mol_wire_atom.watching) {
1194
- if (atom.cursor === $mol_wire_cursor.final) {
1195
- $mol_wire_atom.watching.delete(atom);
1196
- }
1197
- else {
1198
- atom.cursor = $mol_wire_cursor.stale;
1199
- atom.fresh();
1200
- }
1142
+ data(value, kids = []) {
1143
+ return $mol_tree2.data(value, kids, this.span);
1144
+ }
1145
+ static struct(type, kids = [], span = $mol_span.unknown) {
1146
+ if (/[ \n\t\\]/.test(type)) {
1147
+ $$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
1201
1148
  }
1149
+ return new $mol_tree2(type, '', kids, span);
1202
1150
  }
1203
- watch() {
1204
- if (!$mol_wire_atom.watcher) {
1205
- $mol_wire_atom.watcher = new $mol_after_frame($mol_wire_atom.watch);
1151
+ struct(type, kids = []) {
1152
+ return $mol_tree2.struct(type, kids, this.span);
1153
+ }
1154
+ clone(kids, span = this.span) {
1155
+ return new $mol_tree2(this.type, this.value, kids, span);
1156
+ }
1157
+ text() {
1158
+ var values = [];
1159
+ for (var kid of this.kids) {
1160
+ if (kid.type)
1161
+ continue;
1162
+ values.push(kid.value);
1206
1163
  }
1207
- $mol_wire_atom.watching.add(this);
1164
+ return this.value + values.join('\n');
1208
1165
  }
1209
- resync(args) {
1210
- return this.put(this.task.call(this.host, ...args));
1166
+ static fromString(str, uri = 'unknown') {
1167
+ return $$.$mol_tree2_from_string(str, uri);
1211
1168
  }
1212
- once() {
1213
- return this.sync();
1169
+ toString() {
1170
+ return $$.$mol_tree2_to_string(this);
1214
1171
  }
1215
- channel() {
1216
- return Object.assign((next) => {
1217
- if (next !== undefined)
1218
- return this.resync([...this.args, next]);
1219
- if (!$mol_wire_fiber.warm)
1220
- return this.result();
1221
- if ($mol_wire_auto()?.temp) {
1222
- return this.once();
1223
- }
1224
- else {
1225
- return this.sync();
1172
+ insert(value, ...path) {
1173
+ if (path.length === 0)
1174
+ return value;
1175
+ const type = path[0];
1176
+ if (typeof type === 'string') {
1177
+ let replaced = false;
1178
+ const sub = this.kids.map((item, index) => {
1179
+ if (item.type !== type)
1180
+ return item;
1181
+ replaced = true;
1182
+ return item.insert(value, ...path.slice(1));
1183
+ }).filter(Boolean);
1184
+ if (!replaced && value) {
1185
+ sub.push(this.struct(type, []).insert(value, ...path.slice(1)));
1226
1186
  }
1227
- }, { atom: this });
1228
- }
1229
- destructor() {
1230
- super.destructor();
1231
- const prev = this.cache;
1232
- if ($mol_owning_check(this, prev)) {
1233
- prev.destructor();
1187
+ return this.clone(sub);
1234
1188
  }
1235
- if (this.pub_from === 0) {
1236
- ;
1237
- (this.host ?? this.task)[this.field()] = null;
1189
+ else if (typeof type === 'number') {
1190
+ const sub = this.kids.slice();
1191
+ sub[type] = (sub[type] || this.list([]))
1192
+ .insert(value, ...path.slice(1));
1193
+ return this.clone(sub.filter(Boolean));
1238
1194
  }
1239
1195
  else {
1240
- ;
1241
- (this.host ?? this.task)[this.field()].delete(this[Symbol.toStringTag]);
1196
+ const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
1197
+ .map(item => item.insert(value, ...path.slice(1)))
1198
+ .filter(Boolean);
1199
+ return this.clone(kids);
1242
1200
  }
1243
1201
  }
1244
- put(next) {
1245
- const prev = this.cache;
1246
- update: if (next !== prev) {
1247
- try {
1248
- if ($mol_compare_deep(prev, next))
1249
- break update;
1202
+ select(...path) {
1203
+ let next = [this];
1204
+ for (const type of path) {
1205
+ if (!next.length)
1206
+ break;
1207
+ const prev = next;
1208
+ next = [];
1209
+ for (var item of prev) {
1210
+ switch (typeof (type)) {
1211
+ case 'string':
1212
+ for (var child of item.kids) {
1213
+ if (child.type == type) {
1214
+ next.push(child);
1215
+ }
1216
+ }
1217
+ break;
1218
+ case 'number':
1219
+ if (type < item.kids.length)
1220
+ next.push(item.kids[type]);
1221
+ break;
1222
+ default: next.push(...item.kids);
1223
+ }
1250
1224
  }
1251
- catch (error) {
1252
- $mol_fail_log(error);
1225
+ }
1226
+ return this.list(next);
1227
+ }
1228
+ filter(path, value) {
1229
+ const sub = this.kids.filter(item => {
1230
+ var found = item.select(...path);
1231
+ if (value === undefined) {
1232
+ return Boolean(found.kids.length);
1253
1233
  }
1254
- if ($mol_owning_check(this, prev)) {
1255
- prev.destructor();
1234
+ else {
1235
+ return found.kids.some(child => child.value == value);
1256
1236
  }
1257
- if ($mol_owning_catch(this, next)) {
1258
- try {
1259
- next[Symbol.toStringTag] = this[Symbol.toStringTag];
1260
- }
1261
- catch {
1262
- Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
1263
- }
1237
+ });
1238
+ return this.clone(sub);
1239
+ }
1240
+ hack(belt, context = {}) {
1241
+ return [].concat(...this.kids.map(child => {
1242
+ let handle = belt[child.type] || belt[''];
1243
+ if (!handle || handle === Object.prototype[child.type]) {
1244
+ handle = (input, belt, context) => [
1245
+ input.clone(input.hack(belt, context), context.span)
1246
+ ];
1264
1247
  }
1265
- if (!this.sub_empty)
1266
- this.emit();
1267
- }
1268
- this.cache = next;
1269
- this.cursor = $mol_wire_cursor.fresh;
1270
- if ($mol_promise_like(next))
1271
- return next;
1272
- this.complete_pubs();
1273
- return next;
1248
+ try {
1249
+ return handle(child, belt, context);
1250
+ }
1251
+ catch (error) {
1252
+ error.message += `\n${child.clone([])}${child.span}`;
1253
+ $mol_fail_hidden(error);
1254
+ }
1255
+ }));
1256
+ }
1257
+ error(message, Class = Error) {
1258
+ return this.span.error(`${message}\n${this.clone([])}`, Class);
1274
1259
  }
1275
1260
  }
1276
- __decorate([
1277
- $mol_wire_method
1278
- ], $mol_wire_atom.prototype, "resync", null);
1279
- __decorate([
1280
- $mol_wire_method
1281
- ], $mol_wire_atom.prototype, "once", null);
1282
- $.$mol_wire_atom = $mol_wire_atom;
1261
+ $.$mol_tree2 = $mol_tree2;
1262
+ class $mol_tree2_empty extends $mol_tree2 {
1263
+ constructor() {
1264
+ super('', '', [], $mol_span.unknown);
1265
+ }
1266
+ }
1267
+ $.$mol_tree2_empty = $mol_tree2_empty;
1283
1268
  })($ || ($ = {}));
1284
- //mol/wire/atom/atom.ts
1269
+ //mol/tree2/tree2.ts
1285
1270
  ;
1286
1271
  "use strict";
1287
1272
  var $;
1288
1273
  (function ($) {
1289
- function $mol_wire_probe(task, def) {
1290
- const warm = $mol_wire_fiber.warm;
1291
- try {
1292
- $mol_wire_fiber.warm = false;
1293
- const res = task();
1294
- if (res === undefined)
1295
- return def;
1296
- return res;
1297
- }
1298
- finally {
1299
- $mol_wire_fiber.warm = warm;
1300
- }
1301
- }
1302
- $.$mol_wire_probe = $mol_wire_probe;
1274
+ class $mol_error_syntax extends SyntaxError {
1275
+ reason;
1276
+ line;
1277
+ span;
1278
+ constructor(reason, line, span) {
1279
+ super(`${reason}\n${span}\n${line.substring(0, span.col - 1).replace(/\S/g, ' ')}${''.padEnd(span.length, '!')}\n${line}`);
1280
+ this.reason = reason;
1281
+ this.line = line;
1282
+ this.span = span;
1283
+ }
1284
+ }
1285
+ $.$mol_error_syntax = $mol_error_syntax;
1303
1286
  })($ || ($ = {}));
1304
- //mol/wire/probe/probe.ts
1287
+ //mol/error/syntax/syntax.ts
1305
1288
  ;
1306
1289
  "use strict";
1307
1290
  var $;
1308
1291
  (function ($) {
1309
- function $mol_wire_solid() {
1310
- const current = $mol_wire_auto();
1311
- if (current.reap !== nothing) {
1312
- current?.sub_on(sub, sub.data.length);
1292
+ function $mol_tree2_from_string(str, uri = '?') {
1293
+ const span = $mol_span.entire(uri, str);
1294
+ var root = $mol_tree2.list([], span);
1295
+ var stack = [root];
1296
+ var pos = 0, row = 0, min_indent = 0;
1297
+ while (str.length > pos) {
1298
+ var indent = 0;
1299
+ var line_start = pos;
1300
+ row++;
1301
+ while (str.length > pos && str[pos] == '\t') {
1302
+ indent++;
1303
+ pos++;
1304
+ }
1305
+ if (!root.kids.length) {
1306
+ min_indent = indent;
1307
+ }
1308
+ indent -= min_indent;
1309
+ if (indent < 0 || indent >= stack.length) {
1310
+ const sp = span.span(row, 1, pos - line_start);
1311
+ while (str.length > pos && str[pos] != '\n') {
1312
+ pos++;
1313
+ }
1314
+ if (indent < 0) {
1315
+ if (str.length > pos) {
1316
+ this.$mol_fail(new this.$mol_error_syntax(`Too few tabs`, str.substring(line_start, pos), sp));
1317
+ }
1318
+ }
1319
+ else {
1320
+ this.$mol_fail(new this.$mol_error_syntax(`Too many tabs`, str.substring(line_start, pos), sp));
1321
+ }
1322
+ }
1323
+ stack.length = indent + 1;
1324
+ var parent = stack[indent];
1325
+ while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
1326
+ var error_start = pos;
1327
+ while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
1328
+ pos++;
1329
+ }
1330
+ if (pos > error_start) {
1331
+ let line_end = str.indexOf('\n', pos);
1332
+ if (line_end === -1)
1333
+ line_end = str.length;
1334
+ const sp = span.span(row, error_start - line_start + 1, pos - error_start);
1335
+ this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
1336
+ }
1337
+ var type_start = pos;
1338
+ while (str.length > pos &&
1339
+ str[pos] != '\\' &&
1340
+ str[pos] != ' ' &&
1341
+ str[pos] != '\t' &&
1342
+ str[pos] != '\n') {
1343
+ pos++;
1344
+ }
1345
+ if (pos > type_start) {
1346
+ let next = new $mol_tree2(str.slice(type_start, pos), '', [], span.span(row, type_start - line_start + 1, pos - type_start));
1347
+ const parent_kids = parent.kids;
1348
+ parent_kids.push(next);
1349
+ parent = next;
1350
+ }
1351
+ if (str.length > pos && str[pos] == ' ') {
1352
+ pos++;
1353
+ }
1354
+ }
1355
+ if (str.length > pos && str[pos] == '\\') {
1356
+ var data_start = pos;
1357
+ while (str.length > pos && str[pos] != '\n') {
1358
+ pos++;
1359
+ }
1360
+ let next = new $mol_tree2('', str.slice(data_start + 1, pos), [], span.span(row, data_start - line_start + 2, pos - data_start - 1));
1361
+ const parent_kids = parent.kids;
1362
+ parent_kids.push(next);
1363
+ parent = next;
1364
+ }
1365
+ if (str.length === pos && stack.length > 0) {
1366
+ const sp = span.span(row, pos - line_start + 1, 1);
1367
+ this.$mol_fail(new this.$mol_error_syntax(`Unexpected EOF, LF required`, str.substring(line_start, str.length), sp));
1368
+ }
1369
+ stack.push(parent);
1370
+ pos++;
1313
1371
  }
1314
- current.reap = nothing;
1372
+ return root;
1315
1373
  }
1316
- $.$mol_wire_solid = $mol_wire_solid;
1317
- const nothing = () => { };
1318
- const sub = new $mol_wire_pub_sub;
1374
+ $.$mol_tree2_from_string = $mol_tree2_from_string;
1319
1375
  })($ || ($ = {}));
1320
- //mol/wire/solid/solid.ts
1376
+ //mol/tree2/from/string/string.ts
1321
1377
  ;
1322
1378
  "use strict";
1323
1379
  var $;
1324
1380
  (function ($) {
1325
- function $mol_wire_watch() {
1326
- const atom = $mol_wire_auto();
1327
- if (atom instanceof $mol_wire_atom) {
1328
- atom.watch();
1381
+ function $mol_tree2_from_json(json, span = $mol_span.unknown) {
1382
+ if (typeof json === 'boolean' || typeof json === 'number' || json === null) {
1383
+ return new $mol_tree2(String(json), '', [], span);
1329
1384
  }
1330
- else {
1331
- $mol_fail(new Error('Atom is required for watching'));
1385
+ if (typeof json === 'string') {
1386
+ return $mol_tree2.data(json, [], span);
1387
+ }
1388
+ if (Array.isArray(json)) {
1389
+ const sub = json.map(json => $mol_tree2_from_json(json, span));
1390
+ return new $mol_tree2('/', '', sub, span);
1391
+ }
1392
+ if (ArrayBuffer.isView(json)) {
1393
+ const buf = new Uint8Array(json.buffer, json.byteOffset, json.byteLength);
1394
+ return $mol_tree2.data(String.fromCharCode(...buf), [], span);
1395
+ }
1396
+ if (json instanceof Date) {
1397
+ return new $mol_tree2('', json.toISOString(), [], span);
1398
+ }
1399
+ if (typeof json.toJSON === 'function') {
1400
+ return $mol_tree2_from_json(json.toJSON());
1401
+ }
1402
+ if (json instanceof Error) {
1403
+ const { name, message, stack } = json;
1404
+ json = { ...json, name, message, stack };
1405
+ }
1406
+ const sub = [];
1407
+ for (var key in json) {
1408
+ const val = json[key];
1409
+ if (val === undefined)
1410
+ continue;
1411
+ const subsub = $mol_tree2_from_json(val, span);
1412
+ if (/^[^\n\t\\ ]+$/.test(key)) {
1413
+ sub.push(new $mol_tree2(key, '', [subsub], span));
1414
+ }
1415
+ else {
1416
+ sub.push($mol_tree2.data(key, [subsub], span));
1417
+ }
1332
1418
  }
1419
+ return new $mol_tree2('*', '', sub, span);
1333
1420
  }
1334
- $.$mol_wire_watch = $mol_wire_watch;
1421
+ $.$mol_tree2_from_json = $mol_tree2_from_json;
1335
1422
  })($ || ($ = {}));
1336
- //mol/wire/watch/watch.ts
1423
+ //mol/tree2/from/json/json.ts
1337
1424
  ;
1338
1425
  "use strict";
1339
1426
  var $;
1340
1427
  (function ($) {
1341
- function $mol_wire_sync(obj) {
1342
- return new Proxy(obj, {
1343
- get(obj, field) {
1344
- const val = obj[field];
1345
- if (typeof val !== 'function')
1346
- return val;
1347
- const temp = $mol_wire_task.getter(val);
1348
- return function $mol_wire_sync(...args) {
1349
- const fiber = temp(obj, args);
1350
- return fiber.sync();
1351
- };
1352
- },
1353
- apply(obj, self, args) {
1354
- const temp = $mol_wire_task.getter(obj);
1355
- const fiber = temp(self, args);
1356
- return fiber.sync();
1357
- },
1358
- });
1428
+ class $mol_term_color {
1429
+ static reset = this.ansi(0, 0);
1430
+ static bold = this.ansi(1, 22);
1431
+ static italic = this.ansi(3, 23);
1432
+ static underline = this.ansi(4, 24);
1433
+ static inverse = this.ansi(7, 27);
1434
+ static hidden = this.ansi(8, 28);
1435
+ static strike = this.ansi(9, 29);
1436
+ static gray = this.ansi(90, 39);
1437
+ static red = this.ansi(91, 39);
1438
+ static green = this.ansi(92, 39);
1439
+ static yellow = this.ansi(93, 39);
1440
+ static blue = this.ansi(94, 39);
1441
+ static magenta = this.ansi(95, 39);
1442
+ static cyan = this.ansi(96, 39);
1443
+ static Gray = (str) => this.inverse(this.gray(str));
1444
+ static Red = (str) => this.inverse(this.red(str));
1445
+ static Green = (str) => this.inverse(this.green(str));
1446
+ static Yellow = (str) => this.inverse(this.yellow(str));
1447
+ static Blue = (str) => this.inverse(this.blue(str));
1448
+ static Magenta = (str) => this.inverse(this.magenta(str));
1449
+ static Cyan = (str) => this.inverse(this.cyan(str));
1450
+ static ansi(open, close) {
1451
+ if (typeof process === 'undefined')
1452
+ return String;
1453
+ if (!process.stdout.isTTY)
1454
+ return String;
1455
+ const prefix = `\x1b[${open}m`;
1456
+ const postfix = `\x1b[${close}m`;
1457
+ const suffix_regexp = new RegExp(postfix.replace('[', '\\['), 'g');
1458
+ return function colorer(str) {
1459
+ str = String(str);
1460
+ if (str === '')
1461
+ return str;
1462
+ const suffix = str.replace(suffix_regexp, prefix);
1463
+ return prefix + suffix + postfix;
1464
+ };
1465
+ }
1359
1466
  }
1360
- $.$mol_wire_sync = $mol_wire_sync;
1467
+ $.$mol_term_color = $mol_term_color;
1361
1468
  })($ || ($ = {}));
1362
- //mol/wire/sync/sync.ts
1469
+ //mol/term/color/color.ts
1363
1470
  ;
1364
1471
  "use strict";
1365
1472
  var $;
1366
1473
  (function ($) {
1367
- function $mol_wire_async(obj) {
1368
- let fiber;
1369
- const temp = $mol_wire_task.getter(obj);
1370
- return new Proxy(obj, {
1371
- get(obj, field) {
1372
- const val = obj[field];
1373
- if (typeof val !== 'function')
1374
- return val;
1375
- let fiber;
1376
- const temp = $mol_wire_task.getter(val);
1377
- return function $mol_wire_async(...args) {
1378
- fiber?.destructor();
1379
- fiber = temp(obj, args);
1380
- return fiber.async();
1381
- };
1382
- },
1383
- apply(obj, self, args) {
1384
- fiber?.destructor();
1385
- fiber = temp(self, args);
1386
- return fiber.async();
1387
- },
1388
- });
1474
+ function $mol_log3_node_make(level, output, type, color) {
1475
+ return function $mol_log3_logger(event) {
1476
+ if (!event.time)
1477
+ event = { time: new Date().toISOString(), ...event };
1478
+ let tree = this.$mol_tree2_from_json(event);
1479
+ tree = tree.struct(type, tree.kids);
1480
+ let str = color(tree.toString());
1481
+ this.console[level](str);
1482
+ const self = this;
1483
+ return () => self.console.groupEnd();
1484
+ };
1389
1485
  }
1390
- $.$mol_wire_async = $mol_wire_async;
1486
+ $.$mol_log3_node_make = $mol_log3_node_make;
1487
+ $.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', $mol_term_color.blue);
1488
+ $.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', $mol_term_color.green);
1489
+ $.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', $mol_term_color.red);
1490
+ $.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', $mol_term_color.yellow);
1491
+ $.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', $mol_term_color.magenta);
1492
+ $.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', $mol_term_color.cyan);
1391
1493
  })($ || ($ = {}));
1392
- //mol/wire/async/async.ts
1494
+ //mol/log3/log3.node.ts
1393
1495
  ;
1394
1496
  "use strict";
1395
1497
  var $;
1396
1498
  (function ($) {
1397
- function $mol_wire_race(...tasks) {
1398
- const results = tasks.map(task => {
1399
- try {
1400
- return task();
1401
- }
1402
- catch (error) {
1403
- return error;
1499
+ class $mol_wire_task extends $mol_wire_fiber {
1500
+ static getter(task) {
1501
+ return function $mol_wire_task_get(host, args) {
1502
+ const sub = $mol_wire_auto();
1503
+ const existen = sub?.track_next();
1504
+ reuse: if (existen) {
1505
+ if (!existen.temp)
1506
+ break reuse;
1507
+ if (existen.host !== host)
1508
+ break reuse;
1509
+ if (existen.task !== task)
1510
+ break reuse;
1511
+ if (!$mol_compare_deep(existen.args, args))
1512
+ break reuse;
1513
+ return existen;
1514
+ }
1515
+ const next = new $mol_wire_task(`${host?.[Symbol.toStringTag] ?? host}.${task.name}(#)`, task, host, args);
1516
+ if (existen?.temp) {
1517
+ $$.$mol_log3_warn({
1518
+ place: '$mol_wire_task',
1519
+ message: `Non idempotency`,
1520
+ existen,
1521
+ next,
1522
+ hint: 'Ignore it',
1523
+ });
1524
+ }
1525
+ return next;
1526
+ };
1527
+ }
1528
+ get temp() {
1529
+ return true;
1530
+ }
1531
+ complete() {
1532
+ if ($mol_promise_like(this.cache))
1533
+ return;
1534
+ this.destructor();
1535
+ }
1536
+ put(next) {
1537
+ const prev = this.cache;
1538
+ this.cache = next;
1539
+ if ($mol_promise_like(next)) {
1540
+ this.cursor = $mol_wire_cursor.fresh;
1541
+ if (next !== prev)
1542
+ this.emit();
1543
+ return next;
1404
1544
  }
1405
- });
1406
- const promises = results.filter(res => $mol_promise_like(res));
1407
- if (promises.length)
1408
- $mol_fail(Promise.race(promises));
1409
- const error = results.find(res => res instanceof Error);
1410
- if (error)
1411
- $mol_fail(error);
1412
- return results;
1545
+ this.cursor = $mol_wire_cursor.final;
1546
+ if (this.sub_empty)
1547
+ this.destructor();
1548
+ else if (next !== prev)
1549
+ this.emit();
1550
+ return next;
1551
+ }
1413
1552
  }
1414
- $.$mol_wire_race = $mol_wire_race;
1553
+ $.$mol_wire_task = $mol_wire_task;
1415
1554
  })($ || ($ = {}));
1416
- //mol/wire/race/race.ts
1555
+ //mol/wire/task/task.ts
1417
1556
  ;
1418
1557
  "use strict";
1419
1558
  var $;
1420
1559
  (function ($) {
1421
- function $mol_wire_solo(host, field, descr) {
1422
- if (!descr)
1423
- descr = Reflect.getOwnPropertyDescriptor(host, field);
1424
- const orig = descr?.value ?? host[field];
1425
- const sup = Reflect.getPrototypeOf(host);
1426
- if (typeof sup[field] === 'function') {
1427
- Object.defineProperty(orig, 'name', { value: sup[field].name });
1560
+ function $mol_guid(length = 8, exists = () => false) {
1561
+ for (;;) {
1562
+ let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
1563
+ if (exists(id))
1564
+ continue;
1565
+ return id;
1428
1566
  }
1429
- const descr2 = {
1430
- ...descr,
1431
- value: function (...args) {
1432
- let atom = $mol_wire_atom.solo(this, orig);
1433
- if ((args.length === 0) || (args[0] === undefined)) {
1434
- if (!$mol_wire_fiber.warm)
1435
- return atom.result();
1436
- if ($mol_wire_auto()?.temp) {
1437
- return atom.once();
1438
- }
1439
- else {
1440
- return atom.sync();
1441
- }
1442
- }
1443
- return atom.resync(args);
1444
- }
1445
- };
1446
- Reflect.defineProperty(descr2.value, 'name', { value: orig.name + ' ' });
1447
- Reflect.defineProperty(descr2.value, 'length', { value: orig.length });
1448
- Object.assign(descr2.value, { orig });
1449
- Reflect.defineProperty(host, field, descr2);
1450
- return descr2;
1451
1567
  }
1452
- $.$mol_wire_solo = $mol_wire_solo;
1568
+ $.$mol_guid = $mol_guid;
1453
1569
  })($ || ($ = {}));
1454
- //mol/wire/solo/solo.ts
1570
+ //mol/guid/guid.ts
1455
1571
  ;
1456
1572
  "use strict";
1457
1573
  var $;
1458
1574
  (function ($) {
1459
- function $mol_wire_plex(host, field, descr) {
1575
+ $.$mol_key_store = new WeakMap();
1576
+ function $mol_key(value) {
1577
+ if (typeof value === 'bigint')
1578
+ return value.toString() + 'n';
1579
+ if (!value)
1580
+ return JSON.stringify(value);
1581
+ if (typeof value !== 'object' && typeof value !== 'function')
1582
+ return JSON.stringify(value);
1583
+ return JSON.stringify(value, (field, value) => {
1584
+ if (typeof value === 'bigint')
1585
+ return value.toString() + 'n';
1586
+ if (!value)
1587
+ return value;
1588
+ if (typeof value !== 'object' && typeof value !== 'function')
1589
+ return value;
1590
+ if (Array.isArray(value))
1591
+ return value;
1592
+ const proto = Reflect.getPrototypeOf(value);
1593
+ if (!proto)
1594
+ return value;
1595
+ if (Reflect.getPrototypeOf(proto) === null)
1596
+ return value;
1597
+ if ('toJSON' in value)
1598
+ return value;
1599
+ if (value instanceof RegExp)
1600
+ return value.toString();
1601
+ if (value instanceof Uint8Array)
1602
+ return [...value];
1603
+ let key = $.$mol_key_store.get(value);
1604
+ if (key)
1605
+ return key;
1606
+ key = $mol_guid();
1607
+ $.$mol_key_store.set(value, key);
1608
+ return key;
1609
+ });
1610
+ }
1611
+ $.$mol_key = $mol_key;
1612
+ })($ || ($ = {}));
1613
+ //mol/key/key.ts
1614
+ ;
1615
+ "use strict";
1616
+ var $;
1617
+ (function ($) {
1618
+ function $mol_wire_method(host, field, descr) {
1460
1619
  if (!descr)
1461
1620
  descr = Reflect.getOwnPropertyDescriptor(host, field);
1462
1621
  const orig = descr?.value ?? host[field];
@@ -1464,889 +1623,740 @@ var $;
1464
1623
  if (typeof sup[field] === 'function') {
1465
1624
  Object.defineProperty(orig, 'name', { value: sup[field].name });
1466
1625
  }
1467
- const descr2 = {
1468
- ...descr,
1469
- value: function (...args) {
1470
- let atom = $mol_wire_atom.plex(this, orig, args[0]);
1471
- if ((args.length === 1) || (args[1] === undefined)) {
1472
- if (!$mol_wire_fiber.warm)
1473
- return atom.result();
1474
- if ($mol_wire_auto()?.temp) {
1475
- return atom.once();
1476
- }
1477
- else {
1478
- return atom.sync();
1479
- }
1480
- }
1481
- return atom.resync(args);
1482
- }
1626
+ const temp = $mol_wire_task.getter(orig);
1627
+ const value = function (...args) {
1628
+ const fiber = temp(this ?? null, args);
1629
+ return fiber.sync();
1483
1630
  };
1484
- Reflect.defineProperty(descr2.value, 'name', { value: orig.name + ' ' });
1485
- Reflect.defineProperty(descr2.value, 'length', { value: orig.length });
1486
- Object.assign(descr2.value, { orig });
1631
+ Object.defineProperty(value, 'name', { value: orig.name + ' ' });
1632
+ Object.assign(value, { orig });
1633
+ const descr2 = { ...descr, value };
1487
1634
  Reflect.defineProperty(host, field, descr2);
1488
1635
  return descr2;
1489
1636
  }
1490
- $.$mol_wire_plex = $mol_wire_plex;
1637
+ $.$mol_wire_method = $mol_wire_method;
1491
1638
  })($ || ($ = {}));
1492
- //mol/wire/plex/plex.ts
1639
+ //mol/wire/method/method.ts
1493
1640
  ;
1494
1641
  "use strict";
1495
- var $;
1496
- (function ($) {
1497
- function $mol_const(value) {
1498
- const getter = (() => value);
1499
- getter['()'] = value;
1500
- getter[Symbol.toStringTag] = value;
1501
- getter[$mol_dev_format_head] = () => $mol_dev_format_span({}, '()=> ', $mol_dev_format_auto(value));
1502
- return getter;
1503
- }
1504
- $.$mol_const = $mol_const;
1505
- })($ || ($ = {}));
1506
- //mol/const/const.ts
1642
+ //mol/type/tail/tail.ts
1643
+ ;
1644
+ "use strict";
1645
+ //mol/type/foot/foot.ts
1507
1646
  ;
1508
1647
  "use strict";
1509
1648
  var $;
1510
1649
  (function ($) {
1511
- function $mol_wire_field(host, field, descr) {
1512
- if (!descr)
1513
- descr = Reflect.getOwnPropertyDescriptor(host, field);
1514
- const _get = descr?.get || $mol_const(descr?.value);
1515
- const _set = descr?.set || function (next) {
1516
- $mol_wire_atom.solo(this, _get).put(next);
1517
- };
1518
- const sup = Reflect.getPrototypeOf(host);
1519
- const sup_descr = Reflect.getOwnPropertyDescriptor(sup, field);
1520
- Object.defineProperty(_get, 'name', { value: sup_descr?.get?.name ?? field });
1521
- Object.defineProperty(_set, 'name', { value: sup_descr?.set?.name ?? field });
1522
- function get() {
1523
- return $mol_wire_atom.solo(this, _get).sync();
1524
- }
1525
- const temp = $mol_wire_task.getter(_set);
1526
- function set(next) {
1527
- temp(this, [next]).sync();
1528
- }
1529
- Object.defineProperty(get, 'name', { value: _get.name + '$' });
1530
- Object.defineProperty(set, 'name', { value: _set.name + '@' });
1531
- Object.assign(get, { orig: _get });
1532
- Object.assign(set, { orig: _set });
1533
- const { value, writable, ...descr2 } = { ...descr, get, set };
1534
- Reflect.defineProperty(host, field, descr2);
1535
- return descr2;
1650
+ const catched = new WeakMap();
1651
+ function $mol_fail_catch(error) {
1652
+ if (typeof error !== 'object')
1653
+ return false;
1654
+ if ($mol_promise_like(error))
1655
+ $mol_fail_hidden(error);
1656
+ if (catched.get(error))
1657
+ return false;
1658
+ catched.set(error, true);
1659
+ return true;
1536
1660
  }
1537
- $.$mol_wire_field = $mol_wire_field;
1661
+ $.$mol_fail_catch = $mol_fail_catch;
1538
1662
  })($ || ($ = {}));
1539
- //mol/wire/field/field.ts
1663
+ //mol/fail/catch/catch.ts
1540
1664
  ;
1541
1665
  "use strict";
1542
1666
  var $;
1543
- (function ($_1) {
1544
- let $$;
1545
- (function ($$) {
1546
- let $;
1547
- })($$ = $_1.$$ || ($_1.$$ = {}));
1548
- $_1.$mol_object_field = Symbol('$mol_object_field');
1549
- class $mol_object extends $mol_object2 {
1550
- static make(config) {
1551
- return super.create(obj => {
1552
- for (let key in config)
1553
- obj[key] = config[key];
1554
- });
1555
- }
1667
+ (function ($) {
1668
+ function $mol_fail_log(error) {
1669
+ if ($mol_promise_like(error))
1670
+ return false;
1671
+ if (!$mol_fail_catch(error))
1672
+ return false;
1673
+ console.error(error);
1674
+ return true;
1556
1675
  }
1557
- $_1.$mol_object = $mol_object;
1676
+ $.$mol_fail_log = $mol_fail_log;
1558
1677
  })($ || ($ = {}));
1559
- //mol/object/object.ts
1678
+ //mol/fail/log/log.ts
1560
1679
  ;
1561
1680
  "use strict";
1562
1681
  var $;
1563
1682
  (function ($) {
1564
- $.$mol_mem = $mol_wire_solo;
1565
- $.$mol_mem_key = $mol_wire_plex;
1566
- })($ || ($ = {}));
1567
- //mol/mem/mem.ts
1568
- ;
1569
- "use strict";
1570
- var $;
1571
- (function ($) {
1572
- class $mol_state_time extends $mol_object {
1573
- static task(precision, reset) {
1574
- if (precision) {
1575
- return new $mol_after_timeout(precision, () => this.task(precision, null));
1683
+ class $mol_wire_atom extends $mol_wire_fiber {
1684
+ static solo(host, task) {
1685
+ const field = task.name + '()';
1686
+ const existen = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
1687
+ if (existen)
1688
+ return existen;
1689
+ const prefix = host?.[Symbol.toStringTag] ?? (host instanceof Function ? $$.$mol_func_name(host) : host);
1690
+ const key = `${prefix}.${field}`;
1691
+ const fiber = new $mol_wire_atom(key, task, host, []);
1692
+ (host ?? task)[field] = fiber;
1693
+ return fiber;
1694
+ }
1695
+ static plex(host, task, key) {
1696
+ const field = task.name + '()';
1697
+ let dict = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
1698
+ const prefix = host?.[Symbol.toStringTag] ?? (host instanceof Function ? $$.$mol_func_name(host) : host);
1699
+ const id = `${prefix}.${task.name}(${$mol_key(key).replace(/^"|"$/g, "'")})`;
1700
+ if (dict) {
1701
+ const existen = dict.get(id);
1702
+ if (existen)
1703
+ return existen;
1576
1704
  }
1577
1705
  else {
1578
- return new $mol_after_frame(() => this.task(precision, null));
1706
+ dict = (host ?? task)[field] = new Map();
1579
1707
  }
1708
+ const fiber = new $mol_wire_atom(id, task, host, [key]);
1709
+ dict.set(id, fiber);
1710
+ return fiber;
1580
1711
  }
1581
- static now(precision) {
1582
- this.task(precision);
1583
- return Date.now();
1712
+ static watching = new Set();
1713
+ static watcher = null;
1714
+ static watch() {
1715
+ $mol_wire_atom.watcher = new $mol_after_frame($mol_wire_atom.watch);
1716
+ for (const atom of $mol_wire_atom.watching) {
1717
+ if (atom.cursor === $mol_wire_cursor.final) {
1718
+ $mol_wire_atom.watching.delete(atom);
1719
+ }
1720
+ else {
1721
+ atom.cursor = $mol_wire_cursor.stale;
1722
+ atom.fresh();
1723
+ }
1724
+ }
1725
+ }
1726
+ watch() {
1727
+ if (!$mol_wire_atom.watcher) {
1728
+ $mol_wire_atom.watcher = new $mol_after_frame($mol_wire_atom.watch);
1729
+ }
1730
+ $mol_wire_atom.watching.add(this);
1731
+ }
1732
+ resync(args) {
1733
+ return this.put(this.task.call(this.host, ...args));
1734
+ }
1735
+ once() {
1736
+ return this.sync();
1737
+ }
1738
+ channel() {
1739
+ return Object.assign((next) => {
1740
+ if (next !== undefined)
1741
+ return this.resync([...this.args, next]);
1742
+ if (!$mol_wire_fiber.warm)
1743
+ return this.result();
1744
+ if ($mol_wire_auto()?.temp) {
1745
+ return this.once();
1746
+ }
1747
+ else {
1748
+ return this.sync();
1749
+ }
1750
+ }, { atom: this });
1751
+ }
1752
+ destructor() {
1753
+ super.destructor();
1754
+ const prev = this.cache;
1755
+ if ($mol_owning_check(this, prev)) {
1756
+ prev.destructor();
1757
+ }
1758
+ if (this.pub_from === 0) {
1759
+ ;
1760
+ (this.host ?? this.task)[this.field()] = null;
1761
+ }
1762
+ else {
1763
+ ;
1764
+ (this.host ?? this.task)[this.field()].delete(this[Symbol.toStringTag]);
1765
+ }
1766
+ }
1767
+ put(next) {
1768
+ const prev = this.cache;
1769
+ update: if (next !== prev) {
1770
+ try {
1771
+ if ($mol_compare_deep(prev, next))
1772
+ break update;
1773
+ }
1774
+ catch (error) {
1775
+ $mol_fail_log(error);
1776
+ }
1777
+ if ($mol_owning_check(this, prev)) {
1778
+ prev.destructor();
1779
+ }
1780
+ if ($mol_owning_catch(this, next)) {
1781
+ try {
1782
+ next[Symbol.toStringTag] = this[Symbol.toStringTag];
1783
+ }
1784
+ catch {
1785
+ Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
1786
+ }
1787
+ }
1788
+ if (!this.sub_empty)
1789
+ this.emit();
1790
+ }
1791
+ this.cache = next;
1792
+ this.cursor = $mol_wire_cursor.fresh;
1793
+ if ($mol_promise_like(next))
1794
+ return next;
1795
+ this.complete_pubs();
1796
+ return next;
1584
1797
  }
1585
1798
  }
1586
1799
  __decorate([
1587
- $mol_mem_key
1588
- ], $mol_state_time, "task", null);
1800
+ $mol_wire_method
1801
+ ], $mol_wire_atom.prototype, "resync", null);
1589
1802
  __decorate([
1590
- $mol_mem_key
1591
- ], $mol_state_time, "now", null);
1592
- $.$mol_state_time = $mol_state_time;
1803
+ $mol_wire_method
1804
+ ], $mol_wire_atom.prototype, "once", null);
1805
+ $.$mol_wire_atom = $mol_wire_atom;
1593
1806
  })($ || ($ = {}));
1594
- //mol/state/time/time.ts
1807
+ //mol/wire/atom/atom.ts
1595
1808
  ;
1596
1809
  "use strict";
1597
1810
  var $;
1598
1811
  (function ($) {
1599
- function $mol_wire_easing(next) {
1600
- const atom = $mol_wire_auto();
1601
- if (!(atom instanceof $mol_wire_atom))
1602
- $mol_fail(new Error('Allowed only inside atom'));
1603
- const prev = atom.result() ?? next;
1604
- if (typeof prev !== 'number')
1605
- return next;
1606
- const current = (prev * 2 + next) / 3;
1607
- const diff = Math.abs(current - next);
1608
- if (diff < 1)
1609
- return next;
1610
- $mol_state_time.now(0);
1611
- return current;
1812
+ function $mol_wire_probe(task, def) {
1813
+ const warm = $mol_wire_fiber.warm;
1814
+ try {
1815
+ $mol_wire_fiber.warm = false;
1816
+ const res = task();
1817
+ if (res === undefined)
1818
+ return def;
1819
+ return res;
1820
+ }
1821
+ finally {
1822
+ $mol_wire_fiber.warm = warm;
1823
+ }
1612
1824
  }
1613
- $.$mol_wire_easing = $mol_wire_easing;
1825
+ $.$mol_wire_probe = $mol_wire_probe;
1614
1826
  })($ || ($ = {}));
1615
- //mol/wire/easing/easing.ts
1827
+ //mol/wire/probe/probe.ts
1616
1828
  ;
1617
1829
  "use strict";
1618
1830
  var $;
1619
1831
  (function ($) {
1620
- function $mol_wire_patch(obj) {
1621
- for (const field of Reflect.ownKeys(obj)) {
1622
- const descr = Reflect.getOwnPropertyDescriptor(obj, field);
1623
- if (!descr.configurable)
1624
- continue;
1625
- if (!descr.get)
1626
- continue;
1627
- const get = descr.get ?? (() => descr.value);
1628
- const set = descr.set ?? (next => descr.value = next);
1629
- Reflect.defineProperty(obj, field, {
1630
- configurable: true,
1631
- enumerable: descr.enumerable,
1632
- get() {
1633
- const atom = $mol_wire_atom.solo(obj, get);
1634
- atom.watch();
1635
- return atom.sync();
1636
- },
1637
- set(next) {
1638
- const atom = $mol_wire_atom.solo(obj, get);
1639
- set.call(this, next);
1640
- atom.refresh();
1641
- },
1642
- });
1832
+ function $mol_wire_solid() {
1833
+ const current = $mol_wire_auto();
1834
+ if (current.reap !== nothing) {
1835
+ current?.sub_on(sub, sub.data.length);
1643
1836
  }
1837
+ current.reap = nothing;
1644
1838
  }
1645
- $.$mol_wire_patch = $mol_wire_patch;
1839
+ $.$mol_wire_solid = $mol_wire_solid;
1840
+ const nothing = () => { };
1841
+ const sub = new $mol_wire_pub_sub;
1646
1842
  })($ || ($ = {}));
1647
- //mol/wire/patch/patch.ts
1843
+ //mol/wire/solid/solid.ts
1648
1844
  ;
1649
1845
  "use strict";
1650
- //mol/type/result/result.ts
1846
+ var $;
1847
+ (function ($) {
1848
+ function $mol_wire_watch() {
1849
+ const atom = $mol_wire_auto();
1850
+ if (atom instanceof $mol_wire_atom) {
1851
+ atom.watch();
1852
+ }
1853
+ else {
1854
+ $mol_fail(new Error('Atom is required for watching'));
1855
+ }
1856
+ }
1857
+ $.$mol_wire_watch = $mol_wire_watch;
1858
+ })($ || ($ = {}));
1859
+ //mol/wire/watch/watch.ts
1651
1860
  ;
1652
1861
  "use strict";
1653
1862
  var $;
1654
1863
  (function ($) {
1655
- function $mol_wire_let(host) {
1656
- for (const field of Object.keys(host)) {
1657
- host[field] = new $mol_wire_atom(field, host[field], host).channel();
1658
- }
1659
- return host;
1864
+ function $mol_wire_sync(obj) {
1865
+ return new Proxy(obj, {
1866
+ get(obj, field) {
1867
+ const val = obj[field];
1868
+ if (typeof val !== 'function')
1869
+ return val;
1870
+ const temp = $mol_wire_task.getter(val);
1871
+ return function $mol_wire_sync(...args) {
1872
+ const fiber = temp(obj, args);
1873
+ return fiber.sync();
1874
+ };
1875
+ },
1876
+ apply(obj, self, args) {
1877
+ const temp = $mol_wire_task.getter(obj);
1878
+ const fiber = temp(self, args);
1879
+ return fiber.sync();
1880
+ },
1881
+ });
1660
1882
  }
1661
- $.$mol_wire_let = $mol_wire_let;
1883
+ $.$mol_wire_sync = $mol_wire_sync;
1662
1884
  })($ || ($ = {}));
1663
- //mol/wire/let/let.ts
1885
+ //mol/wire/sync/sync.ts
1664
1886
  ;
1665
1887
  "use strict";
1666
1888
  var $;
1667
1889
  (function ($) {
1668
- class $mol_wire_set extends Set {
1669
- pub = new $mol_wire_pub;
1670
- has(value) {
1671
- this.pub.promote();
1672
- return super.has(value);
1673
- }
1674
- entries() {
1675
- this.pub.promote();
1676
- return super.entries();
1677
- }
1678
- keys() {
1679
- this.pub.promote();
1680
- return super.keys();
1681
- }
1682
- values() {
1683
- this.pub.promote();
1684
- return super.values();
1685
- }
1686
- forEach(task, self) {
1687
- this.pub.promote();
1688
- super.forEach(task, self);
1689
- }
1690
- [Symbol.iterator]() {
1691
- this.pub.promote();
1692
- return super[Symbol.iterator]();
1693
- }
1694
- get size() {
1695
- this.pub.promote();
1696
- return super.size;
1697
- }
1698
- add(value) {
1699
- if (super.has(value))
1700
- return this;
1701
- super.add(value);
1702
- this.pub.emit();
1703
- return this;
1704
- }
1705
- delete(value) {
1706
- const res = super.delete(value);
1707
- if (res)
1708
- this.pub.emit();
1709
- return res;
1710
- }
1711
- clear() {
1712
- if (!super.size)
1713
- return;
1714
- super.clear();
1715
- this.pub.emit();
1716
- }
1717
- item(val, next) {
1718
- if (next === undefined)
1719
- return this.has(val);
1720
- if (next)
1721
- this.add(val);
1722
- else
1723
- this.delete(val);
1724
- return next;
1725
- }
1890
+ function $mol_wire_async(obj) {
1891
+ let fiber;
1892
+ const temp = $mol_wire_task.getter(obj);
1893
+ return new Proxy(obj, {
1894
+ get(obj, field) {
1895
+ const val = obj[field];
1896
+ if (typeof val !== 'function')
1897
+ return val;
1898
+ let fiber;
1899
+ const temp = $mol_wire_task.getter(val);
1900
+ return function $mol_wire_async(...args) {
1901
+ fiber?.destructor();
1902
+ fiber = temp(obj, args);
1903
+ return fiber.async();
1904
+ };
1905
+ },
1906
+ apply(obj, self, args) {
1907
+ fiber?.destructor();
1908
+ fiber = temp(self, args);
1909
+ return fiber.async();
1910
+ },
1911
+ });
1726
1912
  }
1727
- $.$mol_wire_set = $mol_wire_set;
1913
+ $.$mol_wire_async = $mol_wire_async;
1728
1914
  })($ || ($ = {}));
1729
- //mol/wire/set/set.ts
1915
+ //mol/wire/async/async.ts
1730
1916
  ;
1731
1917
  "use strict";
1732
1918
  var $;
1733
1919
  (function ($) {
1734
- class $mol_wire_dict extends Map {
1735
- pub = new $mol_wire_pub;
1736
- has(key) {
1737
- this.pub.promote();
1738
- return super.has(key);
1739
- }
1740
- get(key) {
1741
- this.pub.promote();
1742
- return super.get(key);
1743
- }
1744
- entries() {
1745
- this.pub.promote();
1746
- return super.entries();
1747
- }
1748
- keys() {
1749
- this.pub.promote();
1750
- return super.keys();
1751
- }
1752
- values() {
1753
- this.pub.promote();
1754
- return super.values();
1755
- }
1756
- forEach(task, self) {
1757
- this.pub.promote();
1758
- super.forEach(task, self);
1759
- }
1760
- [Symbol.iterator]() {
1761
- this.pub.promote();
1762
- return super[Symbol.iterator]();
1763
- }
1764
- get size() {
1765
- this.pub.promote();
1766
- return super.size;
1767
- }
1768
- set(key, value) {
1769
- if (super.get(key) === value)
1770
- return this;
1771
- super.set(key, value);
1772
- this.pub?.emit();
1773
- return this;
1774
- }
1775
- delete(key) {
1776
- const res = super.delete(key);
1777
- if (res)
1778
- this.pub.emit();
1779
- return res;
1780
- }
1781
- clear() {
1782
- if (!super.size)
1783
- return;
1784
- super.clear();
1785
- this.pub.emit();
1786
- }
1787
- item(key, next) {
1788
- if (next === undefined)
1789
- return this.get(key) ?? null;
1790
- if (next === null)
1791
- this.delete(key);
1792
- else
1793
- this.set(key, next);
1794
- return next;
1795
- }
1920
+ function $mol_wire_race(...tasks) {
1921
+ const results = tasks.map(task => {
1922
+ try {
1923
+ return task();
1924
+ }
1925
+ catch (error) {
1926
+ return error;
1927
+ }
1928
+ });
1929
+ const promises = results.filter(res => $mol_promise_like(res));
1930
+ if (promises.length)
1931
+ $mol_fail(Promise.race(promises));
1932
+ const error = results.find(res => res instanceof Error);
1933
+ if (error)
1934
+ $mol_fail(error);
1935
+ return results;
1796
1936
  }
1797
- $.$mol_wire_dict = $mol_wire_dict;
1937
+ $.$mol_wire_race = $mol_wire_race;
1798
1938
  })($ || ($ = {}));
1799
- //mol/wire/dict/dict.ts
1939
+ //mol/wire/race/race.ts
1800
1940
  ;
1801
1941
  "use strict";
1802
1942
  var $;
1803
1943
  (function ($) {
1804
- function $mol_promise() {
1805
- let done;
1806
- let fail;
1807
- const promise = new Promise((d, f) => {
1808
- done = d;
1809
- fail = f;
1810
- });
1811
- return Object.assign(promise, {
1812
- done,
1813
- fail,
1814
- });
1944
+ function $mol_wire_solo(host, field, descr) {
1945
+ if (!descr)
1946
+ descr = Reflect.getOwnPropertyDescriptor(host, field);
1947
+ const orig = descr?.value ?? host[field];
1948
+ const sup = Reflect.getPrototypeOf(host);
1949
+ if (typeof sup[field] === 'function') {
1950
+ Object.defineProperty(orig, 'name', { value: sup[field].name });
1951
+ }
1952
+ const descr2 = {
1953
+ ...descr,
1954
+ value: function (...args) {
1955
+ let atom = $mol_wire_atom.solo(this, orig);
1956
+ if ((args.length === 0) || (args[0] === undefined)) {
1957
+ if (!$mol_wire_fiber.warm)
1958
+ return atom.result();
1959
+ if ($mol_wire_auto()?.temp) {
1960
+ return atom.once();
1961
+ }
1962
+ else {
1963
+ return atom.sync();
1964
+ }
1965
+ }
1966
+ return atom.resync(args);
1967
+ }
1968
+ };
1969
+ Reflect.defineProperty(descr2.value, 'name', { value: orig.name + ' ' });
1970
+ Reflect.defineProperty(descr2.value, 'length', { value: orig.length });
1971
+ Object.assign(descr2.value, { orig });
1972
+ Reflect.defineProperty(host, field, descr2);
1973
+ return descr2;
1815
1974
  }
1816
- $.$mol_promise = $mol_promise;
1975
+ $.$mol_wire_solo = $mol_wire_solo;
1817
1976
  })($ || ($ = {}));
1818
- //mol/promise/promise/promise.ts
1977
+ //mol/wire/solo/solo.ts
1819
1978
  ;
1820
1979
  "use strict";
1821
1980
  var $;
1822
1981
  (function ($) {
1823
- function $mol_wait_timeout_async(timeout) {
1824
- const promise = $mol_promise();
1825
- const task = new this.$mol_after_timeout(timeout, () => promise.done());
1826
- return Object.assign(promise, {
1827
- destructor: () => task.destructor()
1828
- });
1982
+ function $mol_wire_plex(host, field, descr) {
1983
+ if (!descr)
1984
+ descr = Reflect.getOwnPropertyDescriptor(host, field);
1985
+ const orig = descr?.value ?? host[field];
1986
+ const sup = Reflect.getPrototypeOf(host);
1987
+ if (typeof sup[field] === 'function') {
1988
+ Object.defineProperty(orig, 'name', { value: sup[field].name });
1989
+ }
1990
+ const descr2 = {
1991
+ ...descr,
1992
+ value: function (...args) {
1993
+ let atom = $mol_wire_atom.plex(this, orig, args[0]);
1994
+ if ((args.length === 1) || (args[1] === undefined)) {
1995
+ if (!$mol_wire_fiber.warm)
1996
+ return atom.result();
1997
+ if ($mol_wire_auto()?.temp) {
1998
+ return atom.once();
1999
+ }
2000
+ else {
2001
+ return atom.sync();
2002
+ }
2003
+ }
2004
+ return atom.resync(args);
2005
+ }
2006
+ };
2007
+ Reflect.defineProperty(descr2.value, 'name', { value: orig.name + ' ' });
2008
+ Reflect.defineProperty(descr2.value, 'length', { value: orig.length });
2009
+ Object.assign(descr2.value, { orig });
2010
+ Reflect.defineProperty(host, field, descr2);
2011
+ return descr2;
1829
2012
  }
1830
- $.$mol_wait_timeout_async = $mol_wait_timeout_async;
1831
- function $mol_wait_timeout(timeout) {
1832
- return this.$mol_wire_sync(this).$mol_wait_timeout_async(timeout);
2013
+ $.$mol_wire_plex = $mol_wire_plex;
2014
+ })($ || ($ = {}));
2015
+ //mol/wire/plex/plex.ts
2016
+ ;
2017
+ "use strict";
2018
+ var $;
2019
+ (function ($) {
2020
+ function $mol_const(value) {
2021
+ const getter = (() => value);
2022
+ getter['()'] = value;
2023
+ getter[Symbol.toStringTag] = value;
2024
+ getter[$mol_dev_format_head] = () => $mol_dev_format_span({}, '()=> ', $mol_dev_format_auto(value));
2025
+ return getter;
1833
2026
  }
1834
- $.$mol_wait_timeout = $mol_wait_timeout;
2027
+ $.$mol_const = $mol_const;
1835
2028
  })($ || ($ = {}));
1836
- //mol/wait/timeout/timeout.ts
2029
+ //mol/const/const.ts
1837
2030
  ;
1838
2031
  "use strict";
1839
2032
  var $;
1840
2033
  (function ($) {
1841
- function $mol_log3_area_lazy(event) {
1842
- const self = this;
1843
- const stack = self.$mol_log3_stack;
1844
- const deep = stack.length;
1845
- let logged = false;
1846
- stack.push(() => {
1847
- logged = true;
1848
- self.$mol_log3_area.call(self, event);
1849
- });
1850
- return () => {
1851
- if (logged)
1852
- self.console.groupEnd();
1853
- if (stack.length > deep)
1854
- stack.length = deep;
2034
+ function $mol_wire_field(host, field, descr) {
2035
+ if (!descr)
2036
+ descr = Reflect.getOwnPropertyDescriptor(host, field);
2037
+ const _get = descr?.get || $mol_const(descr?.value);
2038
+ const _set = descr?.set || function (next) {
2039
+ $mol_wire_atom.solo(this, _get).put(next);
1855
2040
  };
2041
+ const sup = Reflect.getPrototypeOf(host);
2042
+ const sup_descr = Reflect.getOwnPropertyDescriptor(sup, field);
2043
+ Object.defineProperty(_get, 'name', { value: sup_descr?.get?.name ?? field });
2044
+ Object.defineProperty(_set, 'name', { value: sup_descr?.set?.name ?? field });
2045
+ function get() {
2046
+ return $mol_wire_atom.solo(this, _get).sync();
2047
+ }
2048
+ const temp = $mol_wire_task.getter(_set);
2049
+ function set(next) {
2050
+ temp(this, [next]).sync();
2051
+ }
2052
+ Object.defineProperty(get, 'name', { value: _get.name + '$' });
2053
+ Object.defineProperty(set, 'name', { value: _set.name + '@' });
2054
+ Object.assign(get, { orig: _get });
2055
+ Object.assign(set, { orig: _set });
2056
+ const { value, writable, ...descr2 } = { ...descr, get, set };
2057
+ Reflect.defineProperty(host, field, descr2);
2058
+ return descr2;
1856
2059
  }
1857
- $.$mol_log3_area_lazy = $mol_log3_area_lazy;
1858
- $.$mol_log3_stack = [];
2060
+ $.$mol_wire_field = $mol_wire_field;
1859
2061
  })($ || ($ = {}));
1860
- //mol/log3/log3.ts
2062
+ //mol/wire/field/field.ts
1861
2063
  ;
1862
2064
  "use strict";
1863
2065
  var $;
1864
- (function ($) {
1865
- class $mol_span extends $mol_object2 {
1866
- uri;
1867
- source;
1868
- row;
1869
- col;
1870
- length;
1871
- constructor(uri, source, row, col, length) {
1872
- super();
1873
- this.uri = uri;
1874
- this.source = source;
1875
- this.row = row;
1876
- this.col = col;
1877
- this.length = length;
1878
- this[Symbol.toStringTag] = `${this.uri}#${this.row}:${this.col}/${this.length}`;
1879
- }
1880
- static unknown = $mol_span.begin('?');
1881
- static begin(uri, source = '') {
1882
- return new $mol_span(uri, source, 1, 1, 0);
1883
- }
1884
- static end(uri, source) {
1885
- return new $mol_span(uri, source, 1, source.length + 1, 0);
1886
- }
1887
- static entire(uri, source) {
1888
- return new $mol_span(uri, source, 1, 1, source.length);
1889
- }
1890
- toString() {
1891
- return this[Symbol.toStringTag];
1892
- }
1893
- toJSON() {
1894
- return {
1895
- uri: this.uri,
1896
- row: this.row,
1897
- col: this.col,
1898
- length: this.length
1899
- };
1900
- }
1901
- error(message, Class = Error) {
1902
- return new Class(`${message}${this}`);
1903
- }
1904
- span(row, col, length) {
1905
- return new $mol_span(this.uri, this.source, row, col, length);
1906
- }
1907
- after(length = 0) {
1908
- return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
1909
- }
1910
- slice(begin, end = -1) {
1911
- let len = this.length;
1912
- if (begin < 0)
1913
- begin += len;
1914
- if (end < 0)
1915
- end += len;
1916
- if (begin < 0 || begin > len)
1917
- this.$.$mol_fail(`Begin value '${begin}' out of range ${this}`);
1918
- if (end < 0 || end > len)
1919
- this.$.$mol_fail(`End value '${end}' out of range ${this}`);
1920
- if (end < begin)
1921
- this.$.$mol_fail(`End value '${end}' can't be less than begin value ${this}`);
1922
- return this.span(this.row, this.col + begin, end - begin);
2066
+ (function ($_1) {
2067
+ let $$;
2068
+ (function ($$) {
2069
+ let $;
2070
+ })($$ = $_1.$$ || ($_1.$$ = {}));
2071
+ $_1.$mol_object_field = Symbol('$mol_object_field');
2072
+ class $mol_object extends $mol_object2 {
2073
+ static make(config) {
2074
+ return super.create(obj => {
2075
+ for (let key in config)
2076
+ obj[key] = config[key];
2077
+ });
1923
2078
  }
1924
2079
  }
1925
- $.$mol_span = $mol_span;
2080
+ $_1.$mol_object = $mol_object;
1926
2081
  })($ || ($ = {}));
1927
- //mol/span/span.ts
2082
+ //mol/object/object.ts
1928
2083
  ;
1929
2084
  "use strict";
1930
2085
  var $;
1931
2086
  (function ($) {
1932
- function $mol_tree2_to_string(tree) {
1933
- let output = [];
1934
- function dump(tree, prefix = '') {
1935
- if (tree.type.length) {
1936
- if (!prefix.length) {
1937
- prefix = "\t";
1938
- }
1939
- output.push(tree.type);
1940
- if (tree.kids.length == 1) {
1941
- output.push(' ');
1942
- dump(tree.kids[0], prefix);
1943
- return;
1944
- }
1945
- output.push("\n");
1946
- }
1947
- else if (tree.value.length || prefix.length) {
1948
- output.push("\\" + tree.value + "\n");
1949
- }
1950
- for (const kid of tree.kids) {
1951
- output.push(prefix);
1952
- dump(kid, prefix + "\t");
1953
- }
1954
- }
1955
- dump(tree);
1956
- return output.join('');
1957
- }
1958
- $.$mol_tree2_to_string = $mol_tree2_to_string;
2087
+ $.$mol_mem = $mol_wire_solo;
2088
+ $.$mol_mem_key = $mol_wire_plex;
1959
2089
  })($ || ($ = {}));
1960
- //mol/tree2/to/string/string.ts
2090
+ //mol/mem/mem.ts
1961
2091
  ;
1962
2092
  "use strict";
1963
2093
  var $;
1964
2094
  (function ($) {
1965
- class $mol_tree2 extends Object {
1966
- type;
1967
- value;
1968
- kids;
1969
- span;
1970
- constructor(type, value, kids, span) {
1971
- super();
1972
- this.type = type;
1973
- this.value = value;
1974
- this.kids = kids;
1975
- this.span = span;
1976
- this[Symbol.toStringTag] = type || '\\' + value;
1977
- }
1978
- static list(kids, span = $mol_span.unknown) {
1979
- return new $mol_tree2('', '', kids, span);
1980
- }
1981
- list(kids) {
1982
- return $mol_tree2.list(kids, this.span);
1983
- }
1984
- static data(value, kids = [], span = $mol_span.unknown) {
1985
- const chunks = value.split('\n');
1986
- if (chunks.length > 1) {
1987
- let kid_span = span.span(span.row, span.col, 0);
1988
- const data = chunks.map(chunk => {
1989
- kid_span = kid_span.after(chunk.length);
1990
- return new $mol_tree2('', chunk, [], kid_span);
1991
- });
1992
- kids = [...data, ...kids];
1993
- value = '';
1994
- }
1995
- return new $mol_tree2('', value, kids, span);
1996
- }
1997
- data(value, kids = []) {
1998
- return $mol_tree2.data(value, kids, this.span);
1999
- }
2000
- static struct(type, kids = [], span = $mol_span.unknown) {
2001
- if (/[ \n\t\\]/.test(type)) {
2002
- $$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
2003
- }
2004
- return new $mol_tree2(type, '', kids, span);
2005
- }
2006
- struct(type, kids = []) {
2007
- return $mol_tree2.struct(type, kids, this.span);
2008
- }
2009
- clone(kids, span = this.span) {
2010
- return new $mol_tree2(this.type, this.value, kids, span);
2011
- }
2012
- text() {
2013
- var values = [];
2014
- for (var kid of this.kids) {
2015
- if (kid.type)
2016
- continue;
2017
- values.push(kid.value);
2018
- }
2019
- return this.value + values.join('\n');
2020
- }
2021
- static fromString(str, uri = 'unknown') {
2022
- return $$.$mol_tree2_from_string(str, uri);
2023
- }
2024
- toString() {
2025
- return $$.$mol_tree2_to_string(this);
2026
- }
2027
- insert(value, ...path) {
2028
- if (path.length === 0)
2029
- return value;
2030
- const type = path[0];
2031
- if (typeof type === 'string') {
2032
- let replaced = false;
2033
- const sub = this.kids.map((item, index) => {
2034
- if (item.type !== type)
2035
- return item;
2036
- replaced = true;
2037
- return item.insert(value, ...path.slice(1));
2038
- }).filter(Boolean);
2039
- if (!replaced && value) {
2040
- sub.push(this.struct(type, []).insert(value, ...path.slice(1)));
2041
- }
2042
- return this.clone(sub);
2043
- }
2044
- else if (typeof type === 'number') {
2045
- const sub = this.kids.slice();
2046
- sub[type] = (sub[type] || this.list([]))
2047
- .insert(value, ...path.slice(1));
2048
- return this.clone(sub.filter(Boolean));
2095
+ class $mol_state_time extends $mol_object {
2096
+ static task(precision, reset) {
2097
+ if (precision) {
2098
+ return new $mol_after_timeout(precision, () => this.task(precision, null));
2049
2099
  }
2050
2100
  else {
2051
- const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
2052
- .map(item => item.insert(value, ...path.slice(1)))
2053
- .filter(Boolean);
2054
- return this.clone(kids);
2055
- }
2056
- }
2057
- select(...path) {
2058
- let next = [this];
2059
- for (const type of path) {
2060
- if (!next.length)
2061
- break;
2062
- const prev = next;
2063
- next = [];
2064
- for (var item of prev) {
2065
- switch (typeof (type)) {
2066
- case 'string':
2067
- for (var child of item.kids) {
2068
- if (child.type == type) {
2069
- next.push(child);
2070
- }
2071
- }
2072
- break;
2073
- case 'number':
2074
- if (type < item.kids.length)
2075
- next.push(item.kids[type]);
2076
- break;
2077
- default: next.push(...item.kids);
2078
- }
2079
- }
2101
+ return new $mol_after_frame(() => this.task(precision, null));
2080
2102
  }
2081
- return this.list(next);
2082
- }
2083
- filter(path, value) {
2084
- const sub = this.kids.filter(item => {
2085
- var found = item.select(...path);
2086
- if (value === undefined) {
2087
- return Boolean(found.kids.length);
2088
- }
2089
- else {
2090
- return found.kids.some(child => child.value == value);
2091
- }
2092
- });
2093
- return this.clone(sub);
2094
- }
2095
- hack(belt, context = {}) {
2096
- return [].concat(...this.kids.map(child => {
2097
- let handle = belt[child.type] || belt[''];
2098
- if (!handle || handle === Object.prototype[child.type]) {
2099
- handle = (input, belt, context) => [
2100
- input.clone(input.hack(belt, context), context.span)
2101
- ];
2102
- }
2103
- try {
2104
- return handle(child, belt, context);
2105
- }
2106
- catch (error) {
2107
- error.message += `\n${child.clone([])}${child.span}`;
2108
- $mol_fail_hidden(error);
2109
- }
2110
- }));
2111
- }
2112
- error(message, Class = Error) {
2113
- return this.span.error(`${message}\n${this.clone([])}`, Class);
2114
2103
  }
2115
- }
2116
- $.$mol_tree2 = $mol_tree2;
2117
- class $mol_tree2_empty extends $mol_tree2 {
2118
- constructor() {
2119
- super('', '', [], $mol_span.unknown);
2104
+ static now(precision) {
2105
+ this.task(precision);
2106
+ return Date.now();
2120
2107
  }
2121
2108
  }
2122
- $.$mol_tree2_empty = $mol_tree2_empty;
2109
+ __decorate([
2110
+ $mol_mem_key
2111
+ ], $mol_state_time, "task", null);
2112
+ __decorate([
2113
+ $mol_mem_key
2114
+ ], $mol_state_time, "now", null);
2115
+ $.$mol_state_time = $mol_state_time;
2123
2116
  })($ || ($ = {}));
2124
- //mol/tree2/tree2.ts
2117
+ //mol/state/time/time.ts
2125
2118
  ;
2126
2119
  "use strict";
2127
2120
  var $;
2128
2121
  (function ($) {
2129
- class $mol_error_syntax extends SyntaxError {
2130
- reason;
2131
- line;
2132
- span;
2133
- constructor(reason, line, span) {
2134
- super(`${reason}\n${span}\n${line.substring(0, span.col - 1).replace(/\S/g, ' ')}${''.padEnd(span.length, '!')}\n${line}`);
2135
- this.reason = reason;
2136
- this.line = line;
2137
- this.span = span;
2138
- }
2122
+ function $mol_wire_easing(next) {
2123
+ const atom = $mol_wire_auto();
2124
+ if (!(atom instanceof $mol_wire_atom))
2125
+ $mol_fail(new Error('Allowed only inside atom'));
2126
+ const prev = atom.result() ?? next;
2127
+ if (typeof prev !== 'number')
2128
+ return next;
2129
+ const current = (prev * 2 + next) / 3;
2130
+ const diff = Math.abs(current - next);
2131
+ if (diff < 1)
2132
+ return next;
2133
+ $mol_state_time.now(0);
2134
+ return current;
2139
2135
  }
2140
- $.$mol_error_syntax = $mol_error_syntax;
2136
+ $.$mol_wire_easing = $mol_wire_easing;
2141
2137
  })($ || ($ = {}));
2142
- //mol/error/syntax/syntax.ts
2138
+ //mol/wire/easing/easing.ts
2143
2139
  ;
2144
2140
  "use strict";
2145
2141
  var $;
2146
2142
  (function ($) {
2147
- function $mol_tree2_from_string(str, uri = '?') {
2148
- const span = $mol_span.entire(uri, str);
2149
- var root = $mol_tree2.list([], span);
2150
- var stack = [root];
2151
- var pos = 0, row = 0, min_indent = 0;
2152
- while (str.length > pos) {
2153
- var indent = 0;
2154
- var line_start = pos;
2155
- row++;
2156
- while (str.length > pos && str[pos] == '\t') {
2157
- indent++;
2158
- pos++;
2159
- }
2160
- if (!root.kids.length) {
2161
- min_indent = indent;
2162
- }
2163
- indent -= min_indent;
2164
- if (indent < 0 || indent >= stack.length) {
2165
- const sp = span.span(row, 1, pos - line_start);
2166
- while (str.length > pos && str[pos] != '\n') {
2167
- pos++;
2168
- }
2169
- if (indent < 0) {
2170
- if (str.length > pos) {
2171
- this.$mol_fail(new this.$mol_error_syntax(`Too few tabs`, str.substring(line_start, pos), sp));
2172
- }
2173
- }
2174
- else {
2175
- this.$mol_fail(new this.$mol_error_syntax(`Too many tabs`, str.substring(line_start, pos), sp));
2176
- }
2177
- }
2178
- stack.length = indent + 1;
2179
- var parent = stack[indent];
2180
- while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
2181
- var error_start = pos;
2182
- while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
2183
- pos++;
2184
- }
2185
- if (pos > error_start) {
2186
- let line_end = str.indexOf('\n', pos);
2187
- if (line_end === -1)
2188
- line_end = str.length;
2189
- const sp = span.span(row, error_start - line_start + 1, pos - error_start);
2190
- this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
2191
- }
2192
- var type_start = pos;
2193
- while (str.length > pos &&
2194
- str[pos] != '\\' &&
2195
- str[pos] != ' ' &&
2196
- str[pos] != '\t' &&
2197
- str[pos] != '\n') {
2198
- pos++;
2199
- }
2200
- if (pos > type_start) {
2201
- let next = new $mol_tree2(str.slice(type_start, pos), '', [], span.span(row, type_start - line_start + 1, pos - type_start));
2202
- const parent_kids = parent.kids;
2203
- parent_kids.push(next);
2204
- parent = next;
2205
- }
2206
- if (str.length > pos && str[pos] == ' ') {
2207
- pos++;
2208
- }
2209
- }
2210
- if (str.length > pos && str[pos] == '\\') {
2211
- var data_start = pos;
2212
- while (str.length > pos && str[pos] != '\n') {
2213
- pos++;
2214
- }
2215
- let next = new $mol_tree2('', str.slice(data_start + 1, pos), [], span.span(row, data_start - line_start + 2, pos - data_start - 1));
2216
- const parent_kids = parent.kids;
2217
- parent_kids.push(next);
2218
- parent = next;
2219
- }
2220
- if (str.length === pos && stack.length > 0) {
2221
- const sp = span.span(row, pos - line_start + 1, 1);
2222
- this.$mol_fail(new this.$mol_error_syntax(`Unexpected EOF, LF required`, str.substring(line_start, str.length), sp));
2223
- }
2224
- stack.push(parent);
2225
- pos++;
2143
+ function $mol_wire_patch(obj) {
2144
+ for (const field of Reflect.ownKeys(obj)) {
2145
+ const descr = Reflect.getOwnPropertyDescriptor(obj, field);
2146
+ if (!descr.configurable)
2147
+ continue;
2148
+ if (!descr.get)
2149
+ continue;
2150
+ const get = descr.get ?? (() => descr.value);
2151
+ const set = descr.set ?? (next => descr.value = next);
2152
+ Reflect.defineProperty(obj, field, {
2153
+ configurable: true,
2154
+ enumerable: descr.enumerable,
2155
+ get() {
2156
+ const atom = $mol_wire_atom.solo(obj, get);
2157
+ atom.watch();
2158
+ return atom.sync();
2159
+ },
2160
+ set(next) {
2161
+ const atom = $mol_wire_atom.solo(obj, get);
2162
+ set.call(this, next);
2163
+ atom.refresh();
2164
+ },
2165
+ });
2166
+ }
2167
+ }
2168
+ $.$mol_wire_patch = $mol_wire_patch;
2169
+ })($ || ($ = {}));
2170
+ //mol/wire/patch/patch.ts
2171
+ ;
2172
+ "use strict";
2173
+ //mol/type/result/result.ts
2174
+ ;
2175
+ "use strict";
2176
+ var $;
2177
+ (function ($) {
2178
+ function $mol_wire_let(host) {
2179
+ for (const field of Object.keys(host)) {
2180
+ host[field] = new $mol_wire_atom(field, host[field], host).channel();
2226
2181
  }
2227
- return root;
2182
+ return host;
2228
2183
  }
2229
- $.$mol_tree2_from_string = $mol_tree2_from_string;
2184
+ $.$mol_wire_let = $mol_wire_let;
2230
2185
  })($ || ($ = {}));
2231
- //mol/tree2/from/string/string.ts
2186
+ //mol/wire/let/let.ts
2232
2187
  ;
2233
2188
  "use strict";
2234
2189
  var $;
2235
2190
  (function ($) {
2236
- function $mol_tree2_from_json(json, span = $mol_span.unknown) {
2237
- if (typeof json === 'boolean' || typeof json === 'number' || json === null) {
2238
- return new $mol_tree2(String(json), '', [], span);
2191
+ class $mol_wire_set extends Set {
2192
+ pub = new $mol_wire_pub;
2193
+ has(value) {
2194
+ this.pub.promote();
2195
+ return super.has(value);
2239
2196
  }
2240
- if (typeof json === 'string') {
2241
- return $mol_tree2.data(json, [], span);
2197
+ entries() {
2198
+ this.pub.promote();
2199
+ return super.entries();
2242
2200
  }
2243
- if (Array.isArray(json)) {
2244
- const sub = json.map(json => $mol_tree2_from_json(json, span));
2245
- return new $mol_tree2('/', '', sub, span);
2201
+ keys() {
2202
+ this.pub.promote();
2203
+ return super.keys();
2246
2204
  }
2247
- if (ArrayBuffer.isView(json)) {
2248
- const buf = new Uint8Array(json.buffer, json.byteOffset, json.byteLength);
2249
- return $mol_tree2.data(String.fromCharCode(...buf), [], span);
2205
+ values() {
2206
+ this.pub.promote();
2207
+ return super.values();
2250
2208
  }
2251
- if (json instanceof Date) {
2252
- return new $mol_tree2('', json.toISOString(), [], span);
2209
+ forEach(task, self) {
2210
+ this.pub.promote();
2211
+ super.forEach(task, self);
2253
2212
  }
2254
- if (typeof json.toJSON === 'function') {
2255
- return $mol_tree2_from_json(json.toJSON());
2213
+ [Symbol.iterator]() {
2214
+ this.pub.promote();
2215
+ return super[Symbol.iterator]();
2256
2216
  }
2257
- if (json instanceof Error) {
2258
- const { name, message, stack } = json;
2259
- json = { ...json, name, message, stack };
2217
+ get size() {
2218
+ this.pub.promote();
2219
+ return super.size;
2260
2220
  }
2261
- const sub = [];
2262
- for (var key in json) {
2263
- const val = json[key];
2264
- if (val === undefined)
2265
- continue;
2266
- const subsub = $mol_tree2_from_json(val, span);
2267
- if (/^[^\n\t\\ ]+$/.test(key)) {
2268
- sub.push(new $mol_tree2(key, '', [subsub], span));
2269
- }
2270
- else {
2271
- sub.push($mol_tree2.data(key, [subsub], span));
2272
- }
2221
+ add(value) {
2222
+ if (super.has(value))
2223
+ return this;
2224
+ super.add(value);
2225
+ this.pub.emit();
2226
+ return this;
2227
+ }
2228
+ delete(value) {
2229
+ const res = super.delete(value);
2230
+ if (res)
2231
+ this.pub.emit();
2232
+ return res;
2233
+ }
2234
+ clear() {
2235
+ if (!super.size)
2236
+ return;
2237
+ super.clear();
2238
+ this.pub.emit();
2239
+ }
2240
+ item(val, next) {
2241
+ if (next === undefined)
2242
+ return this.has(val);
2243
+ if (next)
2244
+ this.add(val);
2245
+ else
2246
+ this.delete(val);
2247
+ return next;
2273
2248
  }
2274
- return new $mol_tree2('*', '', sub, span);
2275
2249
  }
2276
- $.$mol_tree2_from_json = $mol_tree2_from_json;
2250
+ $.$mol_wire_set = $mol_wire_set;
2277
2251
  })($ || ($ = {}));
2278
- //mol/tree2/from/json/json.ts
2252
+ //mol/wire/set/set.ts
2279
2253
  ;
2280
2254
  "use strict";
2281
2255
  var $;
2282
2256
  (function ($) {
2283
- class $mol_term_color {
2284
- static reset = this.ansi(0, 0);
2285
- static bold = this.ansi(1, 22);
2286
- static italic = this.ansi(3, 23);
2287
- static underline = this.ansi(4, 24);
2288
- static inverse = this.ansi(7, 27);
2289
- static hidden = this.ansi(8, 28);
2290
- static strike = this.ansi(9, 29);
2291
- static gray = this.ansi(90, 39);
2292
- static red = this.ansi(91, 39);
2293
- static green = this.ansi(92, 39);
2294
- static yellow = this.ansi(93, 39);
2295
- static blue = this.ansi(94, 39);
2296
- static magenta = this.ansi(95, 39);
2297
- static cyan = this.ansi(96, 39);
2298
- static Gray = (str) => this.inverse(this.gray(str));
2299
- static Red = (str) => this.inverse(this.red(str));
2300
- static Green = (str) => this.inverse(this.green(str));
2301
- static Yellow = (str) => this.inverse(this.yellow(str));
2302
- static Blue = (str) => this.inverse(this.blue(str));
2303
- static Magenta = (str) => this.inverse(this.magenta(str));
2304
- static Cyan = (str) => this.inverse(this.cyan(str));
2305
- static ansi(open, close) {
2306
- if (typeof process === 'undefined')
2307
- return String;
2308
- if (!process.stdout.isTTY)
2309
- return String;
2310
- const prefix = `\x1b[${open}m`;
2311
- const postfix = `\x1b[${close}m`;
2312
- const suffix_regexp = new RegExp(postfix.replace('[', '\\['), 'g');
2313
- return function colorer(str) {
2314
- str = String(str);
2315
- if (str === '')
2316
- return str;
2317
- const suffix = str.replace(suffix_regexp, prefix);
2318
- return prefix + suffix + postfix;
2319
- };
2257
+ class $mol_wire_dict extends Map {
2258
+ pub = new $mol_wire_pub;
2259
+ has(key) {
2260
+ this.pub.promote();
2261
+ return super.has(key);
2262
+ }
2263
+ get(key) {
2264
+ this.pub.promote();
2265
+ return super.get(key);
2266
+ }
2267
+ entries() {
2268
+ this.pub.promote();
2269
+ return super.entries();
2270
+ }
2271
+ keys() {
2272
+ this.pub.promote();
2273
+ return super.keys();
2274
+ }
2275
+ values() {
2276
+ this.pub.promote();
2277
+ return super.values();
2278
+ }
2279
+ forEach(task, self) {
2280
+ this.pub.promote();
2281
+ super.forEach(task, self);
2282
+ }
2283
+ [Symbol.iterator]() {
2284
+ this.pub.promote();
2285
+ return super[Symbol.iterator]();
2286
+ }
2287
+ get size() {
2288
+ this.pub.promote();
2289
+ return super.size;
2290
+ }
2291
+ set(key, value) {
2292
+ if (super.get(key) === value)
2293
+ return this;
2294
+ super.set(key, value);
2295
+ this.pub?.emit();
2296
+ return this;
2297
+ }
2298
+ delete(key) {
2299
+ const res = super.delete(key);
2300
+ if (res)
2301
+ this.pub.emit();
2302
+ return res;
2303
+ }
2304
+ clear() {
2305
+ if (!super.size)
2306
+ return;
2307
+ super.clear();
2308
+ this.pub.emit();
2309
+ }
2310
+ item(key, next) {
2311
+ if (next === undefined)
2312
+ return this.get(key) ?? null;
2313
+ if (next === null)
2314
+ this.delete(key);
2315
+ else
2316
+ this.set(key, next);
2317
+ return next;
2320
2318
  }
2321
2319
  }
2322
- $.$mol_term_color = $mol_term_color;
2320
+ $.$mol_wire_dict = $mol_wire_dict;
2323
2321
  })($ || ($ = {}));
2324
- //mol/term/color/color.ts
2322
+ //mol/wire/dict/dict.ts
2325
2323
  ;
2326
2324
  "use strict";
2327
2325
  var $;
2328
2326
  (function ($) {
2329
- function $mol_log3_node_make(level, output, type, color) {
2330
- return function $mol_log3_logger(event) {
2331
- if (!event.time)
2332
- event = { time: new Date().toISOString(), ...event };
2333
- let tree = this.$mol_tree2_from_json(event);
2334
- tree = tree.struct(type, tree.kids);
2335
- let str = color(tree.toString());
2336
- this.console[level](str);
2337
- const self = this;
2338
- return () => self.console.groupEnd();
2339
- };
2327
+ function $mol_promise() {
2328
+ let done;
2329
+ let fail;
2330
+ const promise = new Promise((d, f) => {
2331
+ done = d;
2332
+ fail = f;
2333
+ });
2334
+ return Object.assign(promise, {
2335
+ done,
2336
+ fail,
2337
+ });
2340
2338
  }
2341
- $.$mol_log3_node_make = $mol_log3_node_make;
2342
- $.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', $mol_term_color.blue);
2343
- $.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', $mol_term_color.green);
2344
- $.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', $mol_term_color.red);
2345
- $.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', $mol_term_color.yellow);
2346
- $.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', $mol_term_color.magenta);
2347
- $.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', $mol_term_color.cyan);
2339
+ $.$mol_promise = $mol_promise;
2348
2340
  })($ || ($ = {}));
2349
- //mol/log3/log3.node.ts
2341
+ //mol/promise/promise/promise.ts
2342
+ ;
2343
+ "use strict";
2344
+ var $;
2345
+ (function ($) {
2346
+ function $mol_wait_timeout_async(timeout) {
2347
+ const promise = $mol_promise();
2348
+ const task = new this.$mol_after_timeout(timeout, () => promise.done());
2349
+ return Object.assign(promise, {
2350
+ destructor: () => task.destructor()
2351
+ });
2352
+ }
2353
+ $.$mol_wait_timeout_async = $mol_wait_timeout_async;
2354
+ function $mol_wait_timeout(timeout) {
2355
+ return this.$mol_wire_sync(this).$mol_wait_timeout_async(timeout);
2356
+ }
2357
+ $.$mol_wait_timeout = $mol_wait_timeout;
2358
+ })($ || ($ = {}));
2359
+ //mol/wait/timeout/timeout.ts
2350
2360
  ;
2351
2361
  "use strict";
2352
2362
  var $;