mol_dump_lib 0.0.179 → 0.0.181

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.test.js CHANGED
@@ -1068,894 +1068,904 @@ var $;
1068
1068
  "use strict";
1069
1069
  var $;
1070
1070
  (function ($) {
1071
- class $mol_wire_task extends $mol_wire_fiber {
1072
- static getter(task) {
1073
- return function $mol_wire_task_get(host, args) {
1074
- const sub = $mol_wire_auto();
1075
- const existen = sub?.track_next();
1076
- reuse: if (existen) {
1077
- if (!existen.temp)
1078
- break reuse;
1079
- if (existen.host !== host)
1080
- break reuse;
1081
- if (existen.task !== task)
1082
- break reuse;
1083
- if (!$mol_compare_deep(existen.args, args))
1084
- break reuse;
1085
- return existen;
1086
- }
1087
- return new $mol_wire_task(`${host?.[Symbol.toStringTag] ?? host}.${task.name}(#)`, task, host, args);
1088
- };
1089
- }
1090
- get temp() {
1091
- return true;
1092
- }
1093
- complete() {
1094
- if ($mol_promise_like(this.cache))
1095
- return;
1096
- this.destructor();
1097
- }
1098
- put(next) {
1099
- const prev = this.cache;
1100
- this.cache = next;
1101
- if ($mol_promise_like(next)) {
1102
- this.cursor = $mol_wire_cursor.fresh;
1103
- if (next !== prev)
1104
- this.emit();
1105
- return next;
1106
- }
1107
- this.cursor = $mol_wire_cursor.final;
1108
- if (this.sub_empty)
1109
- this.destructor();
1110
- else if (next !== prev)
1111
- this.emit();
1112
- return next;
1113
- }
1114
- }
1115
- $.$mol_wire_task = $mol_wire_task;
1116
- })($ || ($ = {}));
1117
- //mol/wire/task/task.ts
1118
- ;
1119
- "use strict";
1120
- var $;
1121
- (function ($) {
1122
- function $mol_wire_method(host, field, descr) {
1123
- if (!descr)
1124
- descr = Reflect.getOwnPropertyDescriptor(host, field);
1125
- const orig = descr?.value ?? host[field];
1126
- const sup = Reflect.getPrototypeOf(host);
1127
- if (typeof sup[field] === 'function') {
1128
- Object.defineProperty(orig, 'name', { value: sup[field].name });
1129
- }
1130
- const temp = $mol_wire_task.getter(orig);
1131
- const value = function (...args) {
1132
- const fiber = temp(this ?? null, args);
1133
- return fiber.sync();
1071
+ function $mol_log3_area_lazy(event) {
1072
+ const self = this;
1073
+ const stack = self.$mol_log3_stack;
1074
+ const deep = stack.length;
1075
+ let logged = false;
1076
+ stack.push(() => {
1077
+ logged = true;
1078
+ self.$mol_log3_area.call(self, event);
1079
+ });
1080
+ return () => {
1081
+ if (logged)
1082
+ self.console.groupEnd();
1083
+ if (stack.length > deep)
1084
+ stack.length = deep;
1134
1085
  };
1135
- Object.defineProperty(value, 'name', { value: orig.name + ' ' });
1136
- Object.assign(value, { orig });
1137
- const descr2 = { ...descr, value };
1138
- Reflect.defineProperty(host, field, descr2);
1139
- return descr2;
1140
1086
  }
1141
- $.$mol_wire_method = $mol_wire_method;
1087
+ $.$mol_log3_area_lazy = $mol_log3_area_lazy;
1088
+ $.$mol_log3_stack = [];
1142
1089
  })($ || ($ = {}));
1143
- //mol/wire/method/method.ts
1144
- ;
1145
- "use strict";
1146
- //mol/type/tail/tail.ts
1147
- ;
1148
- "use strict";
1149
- //mol/type/foot/foot.ts
1090
+ //mol/log3/log3.ts
1150
1091
  ;
1151
1092
  "use strict";
1152
1093
  var $;
1153
1094
  (function ($) {
1154
- const catched = new WeakMap();
1155
- function $mol_fail_catch(error) {
1156
- if (typeof error !== 'object')
1157
- return false;
1158
- if ($mol_promise_like(error))
1159
- $mol_fail_hidden(error);
1160
- if (catched.get(error))
1161
- return false;
1162
- catched.set(error, true);
1163
- return true;
1095
+ class $mol_span extends $mol_object2 {
1096
+ uri;
1097
+ source;
1098
+ row;
1099
+ col;
1100
+ length;
1101
+ constructor(uri, source, row, col, length) {
1102
+ super();
1103
+ this.uri = uri;
1104
+ this.source = source;
1105
+ this.row = row;
1106
+ this.col = col;
1107
+ this.length = length;
1108
+ this[Symbol.toStringTag] = `${this.uri}#${this.row}:${this.col}/${this.length}`;
1109
+ }
1110
+ static unknown = $mol_span.begin('?');
1111
+ static begin(uri, source = '') {
1112
+ return new $mol_span(uri, source, 1, 1, 0);
1113
+ }
1114
+ static end(uri, source) {
1115
+ return new $mol_span(uri, source, 1, source.length + 1, 0);
1116
+ }
1117
+ static entire(uri, source) {
1118
+ return new $mol_span(uri, source, 1, 1, source.length);
1119
+ }
1120
+ toString() {
1121
+ return this[Symbol.toStringTag];
1122
+ }
1123
+ toJSON() {
1124
+ return {
1125
+ uri: this.uri,
1126
+ row: this.row,
1127
+ col: this.col,
1128
+ length: this.length
1129
+ };
1130
+ }
1131
+ error(message, Class = Error) {
1132
+ return new Class(`${message} (${this})`);
1133
+ }
1134
+ span(row, col, length) {
1135
+ return new $mol_span(this.uri, this.source, row, col, length);
1136
+ }
1137
+ after(length = 0) {
1138
+ return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
1139
+ }
1140
+ slice(begin, end = -1) {
1141
+ let len = this.length;
1142
+ if (begin < 0)
1143
+ begin += len;
1144
+ if (end < 0)
1145
+ end += len;
1146
+ if (begin < 0 || begin > len)
1147
+ this.$.$mol_fail(this.error(`Begin value '${begin}' out of range`, RangeError));
1148
+ if (end < 0 || end > len)
1149
+ this.$.$mol_fail(this.error(`End value '${end}' out of range`, RangeError));
1150
+ if (end < begin)
1151
+ this.$.$mol_fail(this.error(`End value '${end}' can't be less than begin value`, RangeError));
1152
+ return this.span(this.row, this.col + begin, end - begin);
1153
+ }
1164
1154
  }
1165
- $.$mol_fail_catch = $mol_fail_catch;
1155
+ $.$mol_span = $mol_span;
1166
1156
  })($ || ($ = {}));
1167
- //mol/fail/catch/catch.ts
1157
+ //mol/span/span.ts
1168
1158
  ;
1169
1159
  "use strict";
1170
1160
  var $;
1171
1161
  (function ($) {
1172
- function $mol_fail_log(error) {
1173
- if ($mol_promise_like(error))
1174
- return false;
1175
- if (!$mol_fail_catch(error))
1176
- return false;
1177
- console.error(error);
1178
- return true;
1162
+ function $mol_tree2_to_string(tree) {
1163
+ let output = [];
1164
+ function dump(tree, prefix = '') {
1165
+ if (tree.type.length) {
1166
+ if (!prefix.length) {
1167
+ prefix = "\t";
1168
+ }
1169
+ output.push(tree.type);
1170
+ if (tree.kids.length == 1) {
1171
+ output.push(' ');
1172
+ dump(tree.kids[0], prefix);
1173
+ return;
1174
+ }
1175
+ output.push("\n");
1176
+ }
1177
+ else if (tree.value.length || prefix.length) {
1178
+ output.push("\\" + tree.value + "\n");
1179
+ }
1180
+ for (const kid of tree.kids) {
1181
+ output.push(prefix);
1182
+ dump(kid, prefix + "\t");
1183
+ }
1184
+ }
1185
+ dump(tree);
1186
+ return output.join('');
1179
1187
  }
1180
- $.$mol_fail_log = $mol_fail_log;
1188
+ $.$mol_tree2_to_string = $mol_tree2_to_string;
1181
1189
  })($ || ($ = {}));
1182
- //mol/fail/log/log.ts
1190
+ //mol/tree2/to/string/string.ts
1183
1191
  ;
1184
1192
  "use strict";
1185
1193
  var $;
1186
1194
  (function ($) {
1187
- class $mol_wire_atom extends $mol_wire_fiber {
1188
- static solo(host, task) {
1189
- const field = task.name + '()';
1190
- const existen = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
1191
- if (existen)
1192
- return existen;
1193
- const prefix = host?.[Symbol.toStringTag] ?? (host instanceof Function ? $$.$mol_func_name(host) : host);
1194
- const key = `${prefix}.${field}`;
1195
- const fiber = new $mol_wire_atom(key, task, host, []);
1196
- (host ?? task)[field] = fiber;
1197
- return fiber;
1195
+ class $mol_tree2 extends Object {
1196
+ type;
1197
+ value;
1198
+ kids;
1199
+ span;
1200
+ constructor(type, value, kids, span) {
1201
+ super();
1202
+ this.type = type;
1203
+ this.value = value;
1204
+ this.kids = kids;
1205
+ this.span = span;
1206
+ this[Symbol.toStringTag] = type || '\\' + value;
1198
1207
  }
1199
- static plex(host, task, key) {
1200
- const field = task.name + '()';
1201
- let dict = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
1202
- const prefix = host?.[Symbol.toStringTag] ?? (host instanceof Function ? $$.$mol_func_name(host) : host);
1203
- const id = `${prefix}.${task.name}(${$mol_key(key).replace(/^"|"$/g, "'")})`;
1204
- if (dict) {
1205
- const existen = dict.get(id);
1206
- if (existen)
1207
- return existen;
1208
- }
1209
- else {
1210
- dict = (host ?? task)[field] = new Map();
1208
+ static list(kids, span = $mol_span.unknown) {
1209
+ return new $mol_tree2('', '', kids, span);
1210
+ }
1211
+ list(kids) {
1212
+ return $mol_tree2.list(kids, this.span);
1213
+ }
1214
+ static data(value, kids = [], span = $mol_span.unknown) {
1215
+ const chunks = value.split('\n');
1216
+ if (chunks.length > 1) {
1217
+ let kid_span = span.span(span.row, span.col, 0);
1218
+ const data = chunks.map(chunk => {
1219
+ kid_span = kid_span.after(chunk.length);
1220
+ return new $mol_tree2('', chunk, [], kid_span);
1221
+ });
1222
+ kids = [...data, ...kids];
1223
+ value = '';
1211
1224
  }
1212
- const fiber = new $mol_wire_atom(id, task, host, [key]);
1213
- dict.set(id, fiber);
1214
- return fiber;
1225
+ return new $mol_tree2('', value, kids, span);
1215
1226
  }
1216
- static watching = new Set();
1217
- static watcher = null;
1218
- static watch() {
1219
- $mol_wire_atom.watcher = new $mol_after_frame($mol_wire_atom.watch);
1220
- for (const atom of $mol_wire_atom.watching) {
1221
- if (atom.cursor === $mol_wire_cursor.final) {
1222
- $mol_wire_atom.watching.delete(atom);
1223
- }
1224
- else {
1225
- atom.cursor = $mol_wire_cursor.stale;
1226
- atom.fresh();
1227
- }
1227
+ data(value, kids = []) {
1228
+ return $mol_tree2.data(value, kids, this.span);
1229
+ }
1230
+ static struct(type, kids = [], span = $mol_span.unknown) {
1231
+ if (/[ \n\t\\]/.test(type)) {
1232
+ $$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
1228
1233
  }
1234
+ return new $mol_tree2(type, '', kids, span);
1229
1235
  }
1230
- watch() {
1231
- if (!$mol_wire_atom.watcher) {
1232
- $mol_wire_atom.watcher = new $mol_after_frame($mol_wire_atom.watch);
1236
+ struct(type, kids = []) {
1237
+ return $mol_tree2.struct(type, kids, this.span);
1238
+ }
1239
+ clone(kids, span = this.span) {
1240
+ return new $mol_tree2(this.type, this.value, kids, span);
1241
+ }
1242
+ text() {
1243
+ var values = [];
1244
+ for (var kid of this.kids) {
1245
+ if (kid.type)
1246
+ continue;
1247
+ values.push(kid.value);
1233
1248
  }
1234
- $mol_wire_atom.watching.add(this);
1249
+ return this.value + values.join('\n');
1235
1250
  }
1236
- resync(args) {
1237
- return this.put(this.task.call(this.host, ...args));
1251
+ static fromString(str, uri = 'unknown') {
1252
+ return $$.$mol_tree2_from_string(str, uri);
1238
1253
  }
1239
- once() {
1240
- return this.sync();
1254
+ toString() {
1255
+ return $$.$mol_tree2_to_string(this);
1241
1256
  }
1242
- channel() {
1243
- return Object.assign((next) => {
1244
- if (next !== undefined)
1245
- return this.resync([...this.args, next]);
1246
- if (!$mol_wire_fiber.warm)
1247
- return this.result();
1248
- if ($mol_wire_auto()?.temp) {
1249
- return this.once();
1257
+ insert(value, ...path) {
1258
+ if (path.length === 0)
1259
+ return value;
1260
+ const type = path[0];
1261
+ if (typeof type === 'string') {
1262
+ let replaced = false;
1263
+ const sub = this.kids.map((item, index) => {
1264
+ if (item.type !== type)
1265
+ return item;
1266
+ replaced = true;
1267
+ return item.insert(value, ...path.slice(1));
1268
+ }).filter(Boolean);
1269
+ if (!replaced && value) {
1270
+ sub.push(this.struct(type, []).insert(value, ...path.slice(1)));
1271
+ }
1272
+ return this.clone(sub);
1273
+ }
1274
+ else if (typeof type === 'number') {
1275
+ const sub = this.kids.slice();
1276
+ sub[type] = (sub[type] || this.list([]))
1277
+ .insert(value, ...path.slice(1));
1278
+ return this.clone(sub.filter(Boolean));
1279
+ }
1280
+ else {
1281
+ const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
1282
+ .map(item => item.insert(value, ...path.slice(1)))
1283
+ .filter(Boolean);
1284
+ return this.clone(kids);
1285
+ }
1286
+ }
1287
+ select(...path) {
1288
+ let next = [this];
1289
+ for (const type of path) {
1290
+ if (!next.length)
1291
+ break;
1292
+ const prev = next;
1293
+ next = [];
1294
+ for (var item of prev) {
1295
+ switch (typeof (type)) {
1296
+ case 'string':
1297
+ for (var child of item.kids) {
1298
+ if (child.type == type) {
1299
+ next.push(child);
1300
+ }
1301
+ }
1302
+ break;
1303
+ case 'number':
1304
+ if (type < item.kids.length)
1305
+ next.push(item.kids[type]);
1306
+ break;
1307
+ default: next.push(...item.kids);
1308
+ }
1309
+ }
1310
+ }
1311
+ return this.list(next);
1312
+ }
1313
+ filter(path, value) {
1314
+ const sub = this.kids.filter(item => {
1315
+ var found = item.select(...path);
1316
+ if (value === undefined) {
1317
+ return Boolean(found.kids.length);
1250
1318
  }
1251
1319
  else {
1252
- return this.sync();
1320
+ return found.kids.some(child => child.value == value);
1253
1321
  }
1254
- }, { atom: this });
1255
- }
1256
- destructor() {
1257
- super.destructor();
1258
- const prev = this.cache;
1259
- if ($mol_owning_check(this, prev)) {
1260
- prev.destructor();
1261
- }
1262
- if (this.pub_from === 0) {
1263
- ;
1264
- (this.host ?? this.task)[this.field()] = null;
1265
- }
1266
- else {
1267
- ;
1268
- (this.host ?? this.task)[this.field()].delete(this[Symbol.toStringTag]);
1269
- }
1322
+ });
1323
+ return this.clone(sub);
1270
1324
  }
1271
- put(next) {
1272
- const prev = this.cache;
1273
- update: if (next !== prev) {
1325
+ hack(belt, context = {}) {
1326
+ return [].concat(...this.kids.map(child => {
1327
+ let handle = belt[child.type] || belt[''];
1328
+ if (!handle || handle === Object.prototype[child.type]) {
1329
+ handle = (input, belt, context) => [
1330
+ input.clone(input.hack(belt, context), context.span)
1331
+ ];
1332
+ }
1274
1333
  try {
1275
- if ($mol_compare_deep(prev, next))
1276
- break update;
1334
+ return handle(child, belt, context);
1277
1335
  }
1278
1336
  catch (error) {
1279
- $mol_fail_log(error);
1280
- }
1281
- if ($mol_owning_check(this, prev)) {
1282
- prev.destructor();
1283
- }
1284
- if ($mol_owning_catch(this, next)) {
1285
- try {
1286
- next[Symbol.toStringTag] = this[Symbol.toStringTag];
1287
- }
1288
- catch {
1289
- Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
1290
- }
1337
+ error.message += `\n${child.clone([])}${child.span}`;
1338
+ $mol_fail_hidden(error);
1291
1339
  }
1292
- if (!this.sub_empty)
1293
- this.emit();
1294
- }
1295
- this.cache = next;
1296
- this.cursor = $mol_wire_cursor.fresh;
1297
- if ($mol_promise_like(next))
1298
- return next;
1299
- this.complete_pubs();
1300
- return next;
1340
+ }));
1341
+ }
1342
+ error(message, Class = Error) {
1343
+ return this.span.error(`${message}\n${this.clone([])}`, Class);
1301
1344
  }
1302
1345
  }
1303
- __decorate([
1304
- $mol_wire_method
1305
- ], $mol_wire_atom.prototype, "resync", null);
1306
- __decorate([
1307
- $mol_wire_method
1308
- ], $mol_wire_atom.prototype, "once", null);
1309
- $.$mol_wire_atom = $mol_wire_atom;
1346
+ $.$mol_tree2 = $mol_tree2;
1347
+ class $mol_tree2_empty extends $mol_tree2 {
1348
+ constructor() {
1349
+ super('', '', [], $mol_span.unknown);
1350
+ }
1351
+ }
1352
+ $.$mol_tree2_empty = $mol_tree2_empty;
1310
1353
  })($ || ($ = {}));
1311
- //mol/wire/atom/atom.ts
1354
+ //mol/tree2/tree2.ts
1312
1355
  ;
1313
1356
  "use strict";
1314
1357
  var $;
1315
1358
  (function ($) {
1316
- function $mol_wire_solo(host, field, descr) {
1317
- if (!descr)
1318
- descr = Reflect.getOwnPropertyDescriptor(host, field);
1319
- const orig = descr?.value ?? host[field];
1320
- const sup = Reflect.getPrototypeOf(host);
1321
- if (typeof sup[field] === 'function') {
1322
- Object.defineProperty(orig, 'name', { value: sup[field].name });
1359
+ class $mol_error_syntax extends SyntaxError {
1360
+ reason;
1361
+ line;
1362
+ span;
1363
+ constructor(reason, line, span) {
1364
+ super(`${reason}\n${span}\n${line.substring(0, span.col - 1).replace(/\S/g, ' ')}${''.padEnd(span.length, '!')}\n${line}`);
1365
+ this.reason = reason;
1366
+ this.line = line;
1367
+ this.span = span;
1323
1368
  }
1324
- const descr2 = {
1325
- ...descr,
1326
- value: function (...args) {
1327
- let atom = $mol_wire_atom.solo(this, orig);
1328
- if ((args.length === 0) || (args[0] === undefined)) {
1329
- if (!$mol_wire_fiber.warm)
1330
- return atom.result();
1331
- if ($mol_wire_auto()?.temp) {
1332
- return atom.once();
1333
- }
1334
- else {
1335
- return atom.sync();
1369
+ }
1370
+ $.$mol_error_syntax = $mol_error_syntax;
1371
+ })($ || ($ = {}));
1372
+ //mol/error/syntax/syntax.ts
1373
+ ;
1374
+ "use strict";
1375
+ var $;
1376
+ (function ($) {
1377
+ function $mol_tree2_from_string(str, uri = '?') {
1378
+ const span = $mol_span.entire(uri, str);
1379
+ var root = $mol_tree2.list([], span);
1380
+ var stack = [root];
1381
+ var pos = 0, row = 0, min_indent = 0;
1382
+ while (str.length > pos) {
1383
+ var indent = 0;
1384
+ var line_start = pos;
1385
+ row++;
1386
+ while (str.length > pos && str[pos] == '\t') {
1387
+ indent++;
1388
+ pos++;
1389
+ }
1390
+ if (!root.kids.length) {
1391
+ min_indent = indent;
1392
+ }
1393
+ indent -= min_indent;
1394
+ if (indent < 0 || indent >= stack.length) {
1395
+ const sp = span.span(row, 1, pos - line_start);
1396
+ while (str.length > pos && str[pos] != '\n') {
1397
+ pos++;
1398
+ }
1399
+ if (indent < 0) {
1400
+ if (str.length > pos) {
1401
+ this.$mol_fail(new this.$mol_error_syntax(`Too few tabs`, str.substring(line_start, pos), sp));
1336
1402
  }
1337
1403
  }
1338
- return atom.resync(args);
1404
+ else {
1405
+ this.$mol_fail(new this.$mol_error_syntax(`Too many tabs`, str.substring(line_start, pos), sp));
1406
+ }
1339
1407
  }
1340
- };
1341
- Reflect.defineProperty(descr2.value, 'name', { value: orig.name + ' ' });
1342
- Reflect.defineProperty(descr2.value, 'length', { value: orig.length });
1343
- Object.assign(descr2.value, { orig });
1344
- Reflect.defineProperty(host, field, descr2);
1345
- return descr2;
1408
+ stack.length = indent + 1;
1409
+ var parent = stack[indent];
1410
+ while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
1411
+ var error_start = pos;
1412
+ while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
1413
+ pos++;
1414
+ }
1415
+ if (pos > error_start) {
1416
+ let line_end = str.indexOf('\n', pos);
1417
+ if (line_end === -1)
1418
+ line_end = str.length;
1419
+ const sp = span.span(row, error_start - line_start + 1, pos - error_start);
1420
+ this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
1421
+ }
1422
+ var type_start = pos;
1423
+ while (str.length > pos &&
1424
+ str[pos] != '\\' &&
1425
+ str[pos] != ' ' &&
1426
+ str[pos] != '\t' &&
1427
+ str[pos] != '\n') {
1428
+ pos++;
1429
+ }
1430
+ if (pos > type_start) {
1431
+ let next = new $mol_tree2(str.slice(type_start, pos), '', [], span.span(row, type_start - line_start + 1, pos - type_start));
1432
+ const parent_kids = parent.kids;
1433
+ parent_kids.push(next);
1434
+ parent = next;
1435
+ }
1436
+ if (str.length > pos && str[pos] == ' ') {
1437
+ pos++;
1438
+ }
1439
+ }
1440
+ if (str.length > pos && str[pos] == '\\') {
1441
+ var data_start = pos;
1442
+ while (str.length > pos && str[pos] != '\n') {
1443
+ pos++;
1444
+ }
1445
+ let next = new $mol_tree2('', str.slice(data_start + 1, pos), [], span.span(row, data_start - line_start + 2, pos - data_start - 1));
1446
+ const parent_kids = parent.kids;
1447
+ parent_kids.push(next);
1448
+ parent = next;
1449
+ }
1450
+ if (str.length === pos && stack.length > 0) {
1451
+ const sp = span.span(row, pos - line_start + 1, 1);
1452
+ this.$mol_fail(new this.$mol_error_syntax(`Unexpected EOF, LF required`, str.substring(line_start, str.length), sp));
1453
+ }
1454
+ stack.push(parent);
1455
+ pos++;
1456
+ }
1457
+ return root;
1346
1458
  }
1347
- $.$mol_wire_solo = $mol_wire_solo;
1459
+ $.$mol_tree2_from_string = $mol_tree2_from_string;
1348
1460
  })($ || ($ = {}));
1349
- //mol/wire/solo/solo.ts
1461
+ //mol/tree2/from/string/string.ts
1350
1462
  ;
1351
1463
  "use strict";
1352
1464
  var $;
1353
1465
  (function ($) {
1354
- function $mol_wire_plex(host, field, descr) {
1355
- if (!descr)
1356
- descr = Reflect.getOwnPropertyDescriptor(host, field);
1357
- const orig = descr?.value ?? host[field];
1358
- const sup = Reflect.getPrototypeOf(host);
1359
- if (typeof sup[field] === 'function') {
1360
- Object.defineProperty(orig, 'name', { value: sup[field].name });
1466
+ function $mol_tree2_from_json(json, span = $mol_span.unknown) {
1467
+ if (typeof json === 'boolean' || typeof json === 'number' || json === null) {
1468
+ return new $mol_tree2(String(json), '', [], span);
1361
1469
  }
1362
- const descr2 = {
1363
- ...descr,
1364
- value: function (...args) {
1365
- let atom = $mol_wire_atom.plex(this, orig, args[0]);
1366
- if ((args.length === 1) || (args[1] === undefined)) {
1367
- if (!$mol_wire_fiber.warm)
1368
- return atom.result();
1369
- if ($mol_wire_auto()?.temp) {
1370
- return atom.once();
1371
- }
1372
- else {
1373
- return atom.sync();
1374
- }
1375
- }
1376
- return atom.resync(args);
1470
+ if (typeof json === 'string') {
1471
+ return $mol_tree2.data(json, [], span);
1472
+ }
1473
+ if (Array.isArray(json)) {
1474
+ const sub = json.map(json => $mol_tree2_from_json(json, span));
1475
+ return new $mol_tree2('/', '', sub, span);
1476
+ }
1477
+ if (ArrayBuffer.isView(json)) {
1478
+ const buf = new Uint8Array(json.buffer, json.byteOffset, json.byteLength);
1479
+ return $mol_tree2.data(String.fromCharCode(...buf), [], span);
1480
+ }
1481
+ if (json instanceof Date) {
1482
+ return new $mol_tree2('', json.toISOString(), [], span);
1483
+ }
1484
+ if (typeof json.toJSON === 'function') {
1485
+ return $mol_tree2_from_json(json.toJSON());
1486
+ }
1487
+ if (json instanceof Error) {
1488
+ const { name, message, stack } = json;
1489
+ json = { ...json, name, message, stack };
1490
+ }
1491
+ const sub = [];
1492
+ for (var key in json) {
1493
+ const val = json[key];
1494
+ if (val === undefined)
1495
+ continue;
1496
+ const subsub = $mol_tree2_from_json(val, span);
1497
+ if (/^[^\n\t\\ ]+$/.test(key)) {
1498
+ sub.push(new $mol_tree2(key, '', [subsub], span));
1377
1499
  }
1378
- };
1379
- Reflect.defineProperty(descr2.value, 'name', { value: orig.name + ' ' });
1380
- Reflect.defineProperty(descr2.value, 'length', { value: orig.length });
1381
- Object.assign(descr2.value, { orig });
1382
- Reflect.defineProperty(host, field, descr2);
1383
- return descr2;
1500
+ else {
1501
+ sub.push($mol_tree2.data(key, [subsub], span));
1502
+ }
1503
+ }
1504
+ return new $mol_tree2('*', '', sub, span);
1384
1505
  }
1385
- $.$mol_wire_plex = $mol_wire_plex;
1386
- })($ || ($ = {}));
1387
- //mol/wire/plex/plex.ts
1388
- ;
1389
- "use strict";
1390
- var $;
1391
- (function ($) {
1392
- $.$mol_mem = $mol_wire_solo;
1393
- $.$mol_mem_key = $mol_wire_plex;
1506
+ $.$mol_tree2_from_json = $mol_tree2_from_json;
1394
1507
  })($ || ($ = {}));
1395
- //mol/mem/mem.ts
1508
+ //mol/tree2/from/json/json.ts
1396
1509
  ;
1397
1510
  "use strict";
1398
1511
  var $;
1399
1512
  (function ($) {
1400
- })($ || ($ = {}));
1401
- //mol/dom/context/context.ts
1402
- ;
1403
- "use strict";
1404
- //node/node.ts
1405
- ;
1406
- "use strict";
1407
- var $node = new Proxy({ require }, {
1408
- get(target, name, wrapper) {
1409
- if (target[name])
1410
- return target[name];
1411
- const mod = target.require('module');
1412
- if (mod.builtinModules.indexOf(name) >= 0)
1413
- return target.require(name);
1414
- if (name[0] === '.')
1415
- return target.require(name);
1416
- const path = target.require('path');
1417
- const fs = target.require('fs');
1418
- let dir = path.resolve('.');
1419
- const suffix = `./node_modules/${name}`;
1420
- const $$ = $;
1421
- while (!fs.existsSync(path.join(dir, suffix))) {
1422
- const parent = path.resolve(dir, '..');
1423
- if (parent === dir) {
1424
- $$.$mol_exec('.', 'npm', 'install', '--omit=dev', name);
1425
- try {
1426
- $$.$mol_exec('.', 'npm', 'install', '--omit=dev', '@types/' + name);
1427
- }
1428
- catch { }
1429
- break;
1430
- }
1431
- else {
1432
- dir = parent;
1433
- }
1513
+ class $mol_term_color {
1514
+ static reset = this.ansi(0, 0);
1515
+ static bold = this.ansi(1, 22);
1516
+ static italic = this.ansi(3, 23);
1517
+ static underline = this.ansi(4, 24);
1518
+ static inverse = this.ansi(7, 27);
1519
+ static hidden = this.ansi(8, 28);
1520
+ static strike = this.ansi(9, 29);
1521
+ static gray = this.ansi(90, 39);
1522
+ static red = this.ansi(91, 39);
1523
+ static green = this.ansi(92, 39);
1524
+ static yellow = this.ansi(93, 39);
1525
+ static blue = this.ansi(94, 39);
1526
+ static magenta = this.ansi(95, 39);
1527
+ static cyan = this.ansi(96, 39);
1528
+ static Gray = (str) => this.inverse(this.gray(str));
1529
+ static Red = (str) => this.inverse(this.red(str));
1530
+ static Green = (str) => this.inverse(this.green(str));
1531
+ static Yellow = (str) => this.inverse(this.yellow(str));
1532
+ static Blue = (str) => this.inverse(this.blue(str));
1533
+ static Magenta = (str) => this.inverse(this.magenta(str));
1534
+ static Cyan = (str) => this.inverse(this.cyan(str));
1535
+ static ansi(open, close) {
1536
+ if (typeof process === 'undefined')
1537
+ return String;
1538
+ if (!process.stdout.isTTY)
1539
+ return String;
1540
+ const prefix = `\x1b[${open}m`;
1541
+ const postfix = `\x1b[${close}m`;
1542
+ const suffix_regexp = new RegExp(postfix.replace('[', '\\['), 'g');
1543
+ return function colorer(str) {
1544
+ str = String(str);
1545
+ if (str === '')
1546
+ return str;
1547
+ const suffix = str.replace(suffix_regexp, prefix);
1548
+ return prefix + suffix + postfix;
1549
+ };
1434
1550
  }
1435
- return target.require(name);
1436
- },
1437
- set(target, name, value) {
1438
- target[name] = value;
1439
- return true;
1440
- },
1441
- });
1442
- require = (req => Object.assign(function require(name) {
1443
- return $node[name];
1444
- }, req))(require);
1445
- //node/node.node.ts
1551
+ }
1552
+ $.$mol_term_color = $mol_term_color;
1553
+ })($ || ($ = {}));
1554
+ //mol/term/color/color.ts
1446
1555
  ;
1447
1556
  "use strict";
1448
1557
  var $;
1449
1558
  (function ($) {
1450
- function $mol_log3_area_lazy(event) {
1451
- const self = this;
1452
- const stack = self.$mol_log3_stack;
1453
- const deep = stack.length;
1454
- let logged = false;
1455
- stack.push(() => {
1456
- logged = true;
1457
- self.$mol_log3_area.call(self, event);
1458
- });
1459
- return () => {
1460
- if (logged)
1461
- self.console.groupEnd();
1462
- if (stack.length > deep)
1463
- stack.length = deep;
1559
+ function $mol_log3_node_make(level, output, type, color) {
1560
+ return function $mol_log3_logger(event) {
1561
+ if (!event.time)
1562
+ event = { time: new Date().toISOString(), ...event };
1563
+ let tree = this.$mol_tree2_from_json(event);
1564
+ tree = tree.struct(type, tree.kids);
1565
+ let str = color(tree.toString());
1566
+ this.console[level](str);
1567
+ const self = this;
1568
+ return () => self.console.groupEnd();
1464
1569
  };
1465
1570
  }
1466
- $.$mol_log3_area_lazy = $mol_log3_area_lazy;
1467
- $.$mol_log3_stack = [];
1571
+ $.$mol_log3_node_make = $mol_log3_node_make;
1572
+ $.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', $mol_term_color.blue);
1573
+ $.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', $mol_term_color.green);
1574
+ $.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', $mol_term_color.red);
1575
+ $.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', $mol_term_color.yellow);
1576
+ $.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', $mol_term_color.magenta);
1577
+ $.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', $mol_term_color.cyan);
1468
1578
  })($ || ($ = {}));
1469
- //mol/log3/log3.ts
1579
+ //mol/log3/log3.node.ts
1470
1580
  ;
1471
1581
  "use strict";
1472
1582
  var $;
1473
1583
  (function ($) {
1474
- class $mol_span extends $mol_object2 {
1475
- uri;
1476
- source;
1477
- row;
1478
- col;
1479
- length;
1480
- constructor(uri, source, row, col, length) {
1481
- super();
1482
- this.uri = uri;
1483
- this.source = source;
1484
- this.row = row;
1485
- this.col = col;
1486
- this.length = length;
1487
- this[Symbol.toStringTag] = `${this.uri}#${this.row}:${this.col}/${this.length}`;
1488
- }
1489
- static unknown = $mol_span.begin('?');
1490
- static begin(uri, source = '') {
1491
- return new $mol_span(uri, source, 1, 1, 0);
1492
- }
1493
- static end(uri, source) {
1494
- return new $mol_span(uri, source, 1, source.length + 1, 0);
1495
- }
1496
- static entire(uri, source) {
1497
- return new $mol_span(uri, source, 1, 1, source.length);
1498
- }
1499
- toString() {
1500
- return this[Symbol.toStringTag];
1501
- }
1502
- toJSON() {
1503
- return {
1504
- uri: this.uri,
1505
- row: this.row,
1506
- col: this.col,
1507
- length: this.length
1584
+ class $mol_wire_task extends $mol_wire_fiber {
1585
+ static getter(task) {
1586
+ return function $mol_wire_task_get(host, args) {
1587
+ const sub = $mol_wire_auto();
1588
+ const existen = sub?.track_next();
1589
+ reuse: if (existen) {
1590
+ if (!existen.temp)
1591
+ break reuse;
1592
+ if (existen.host !== host)
1593
+ break reuse;
1594
+ if (existen.task !== task)
1595
+ break reuse;
1596
+ if (!$mol_compare_deep(existen.args, args))
1597
+ break reuse;
1598
+ return existen;
1599
+ }
1600
+ const next = new $mol_wire_task(`${host?.[Symbol.toStringTag] ?? host}.${task.name}(#)`, task, host, args);
1601
+ if (existen?.temp) {
1602
+ $$.$mol_log3_warn({
1603
+ place: '$mol_wire_task',
1604
+ message: `Non idempotency`,
1605
+ existen,
1606
+ next,
1607
+ hint: 'Ignore it',
1608
+ });
1609
+ }
1610
+ return next;
1508
1611
  };
1509
1612
  }
1510
- error(message, Class = Error) {
1511
- return new Class(`${message}${this}`);
1613
+ get temp() {
1614
+ return true;
1512
1615
  }
1513
- span(row, col, length) {
1514
- return new $mol_span(this.uri, this.source, row, col, length);
1616
+ complete() {
1617
+ if ($mol_promise_like(this.cache))
1618
+ return;
1619
+ this.destructor();
1515
1620
  }
1516
- after(length = 0) {
1517
- return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
1621
+ put(next) {
1622
+ const prev = this.cache;
1623
+ this.cache = next;
1624
+ if ($mol_promise_like(next)) {
1625
+ this.cursor = $mol_wire_cursor.fresh;
1626
+ if (next !== prev)
1627
+ this.emit();
1628
+ return next;
1629
+ }
1630
+ this.cursor = $mol_wire_cursor.final;
1631
+ if (this.sub_empty)
1632
+ this.destructor();
1633
+ else if (next !== prev)
1634
+ this.emit();
1635
+ return next;
1518
1636
  }
1519
- slice(begin, end = -1) {
1520
- let len = this.length;
1521
- if (begin < 0)
1522
- begin += len;
1523
- if (end < 0)
1524
- end += len;
1525
- if (begin < 0 || begin > len)
1526
- this.$.$mol_fail(`Begin value '${begin}' out of range ${this}`);
1527
- if (end < 0 || end > len)
1528
- this.$.$mol_fail(`End value '${end}' out of range ${this}`);
1529
- if (end < begin)
1530
- this.$.$mol_fail(`End value '${end}' can't be less than begin value ${this}`);
1531
- return this.span(this.row, this.col + begin, end - begin);
1637
+ }
1638
+ $.$mol_wire_task = $mol_wire_task;
1639
+ })($ || ($ = {}));
1640
+ //mol/wire/task/task.ts
1641
+ ;
1642
+ "use strict";
1643
+ var $;
1644
+ (function ($) {
1645
+ function $mol_wire_method(host, field, descr) {
1646
+ if (!descr)
1647
+ descr = Reflect.getOwnPropertyDescriptor(host, field);
1648
+ const orig = descr?.value ?? host[field];
1649
+ const sup = Reflect.getPrototypeOf(host);
1650
+ if (typeof sup[field] === 'function') {
1651
+ Object.defineProperty(orig, 'name', { value: sup[field].name });
1532
1652
  }
1653
+ const temp = $mol_wire_task.getter(orig);
1654
+ const value = function (...args) {
1655
+ const fiber = temp(this ?? null, args);
1656
+ return fiber.sync();
1657
+ };
1658
+ Object.defineProperty(value, 'name', { value: orig.name + ' ' });
1659
+ Object.assign(value, { orig });
1660
+ const descr2 = { ...descr, value };
1661
+ Reflect.defineProperty(host, field, descr2);
1662
+ return descr2;
1533
1663
  }
1534
- $.$mol_span = $mol_span;
1664
+ $.$mol_wire_method = $mol_wire_method;
1535
1665
  })($ || ($ = {}));
1536
- //mol/span/span.ts
1666
+ //mol/wire/method/method.ts
1667
+ ;
1668
+ "use strict";
1669
+ //mol/type/tail/tail.ts
1670
+ ;
1671
+ "use strict";
1672
+ //mol/type/foot/foot.ts
1537
1673
  ;
1538
1674
  "use strict";
1539
1675
  var $;
1540
1676
  (function ($) {
1541
- function $mol_tree2_to_string(tree) {
1542
- let output = [];
1543
- function dump(tree, prefix = '') {
1544
- if (tree.type.length) {
1545
- if (!prefix.length) {
1546
- prefix = "\t";
1547
- }
1548
- output.push(tree.type);
1549
- if (tree.kids.length == 1) {
1550
- output.push(' ');
1551
- dump(tree.kids[0], prefix);
1552
- return;
1553
- }
1554
- output.push("\n");
1555
- }
1556
- else if (tree.value.length || prefix.length) {
1557
- output.push("\\" + tree.value + "\n");
1558
- }
1559
- for (const kid of tree.kids) {
1560
- output.push(prefix);
1561
- dump(kid, prefix + "\t");
1562
- }
1563
- }
1564
- dump(tree);
1565
- return output.join('');
1677
+ const catched = new WeakMap();
1678
+ function $mol_fail_catch(error) {
1679
+ if (typeof error !== 'object')
1680
+ return false;
1681
+ if ($mol_promise_like(error))
1682
+ $mol_fail_hidden(error);
1683
+ if (catched.get(error))
1684
+ return false;
1685
+ catched.set(error, true);
1686
+ return true;
1566
1687
  }
1567
- $.$mol_tree2_to_string = $mol_tree2_to_string;
1688
+ $.$mol_fail_catch = $mol_fail_catch;
1568
1689
  })($ || ($ = {}));
1569
- //mol/tree2/to/string/string.ts
1690
+ //mol/fail/catch/catch.ts
1570
1691
  ;
1571
1692
  "use strict";
1572
1693
  var $;
1573
1694
  (function ($) {
1574
- class $mol_tree2 extends Object {
1575
- type;
1576
- value;
1577
- kids;
1578
- span;
1579
- constructor(type, value, kids, span) {
1580
- super();
1581
- this.type = type;
1582
- this.value = value;
1583
- this.kids = kids;
1584
- this.span = span;
1585
- this[Symbol.toStringTag] = type || '\\' + value;
1586
- }
1587
- static list(kids, span = $mol_span.unknown) {
1588
- return new $mol_tree2('', '', kids, span);
1589
- }
1590
- list(kids) {
1591
- return $mol_tree2.list(kids, this.span);
1592
- }
1593
- static data(value, kids = [], span = $mol_span.unknown) {
1594
- const chunks = value.split('\n');
1595
- if (chunks.length > 1) {
1596
- let kid_span = span.span(span.row, span.col, 0);
1597
- const data = chunks.map(chunk => {
1598
- kid_span = kid_span.after(chunk.length);
1599
- return new $mol_tree2('', chunk, [], kid_span);
1600
- });
1601
- kids = [...data, ...kids];
1602
- value = '';
1603
- }
1604
- return new $mol_tree2('', value, kids, span);
1605
- }
1606
- data(value, kids = []) {
1607
- return $mol_tree2.data(value, kids, this.span);
1695
+ function $mol_fail_log(error) {
1696
+ if ($mol_promise_like(error))
1697
+ return false;
1698
+ if (!$mol_fail_catch(error))
1699
+ return false;
1700
+ console.error(error);
1701
+ return true;
1702
+ }
1703
+ $.$mol_fail_log = $mol_fail_log;
1704
+ })($ || ($ = {}));
1705
+ //mol/fail/log/log.ts
1706
+ ;
1707
+ "use strict";
1708
+ var $;
1709
+ (function ($) {
1710
+ class $mol_wire_atom extends $mol_wire_fiber {
1711
+ static solo(host, task) {
1712
+ const field = task.name + '()';
1713
+ const existen = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
1714
+ if (existen)
1715
+ return existen;
1716
+ const prefix = host?.[Symbol.toStringTag] ?? (host instanceof Function ? $$.$mol_func_name(host) : host);
1717
+ const key = `${prefix}.${field}`;
1718
+ const fiber = new $mol_wire_atom(key, task, host, []);
1719
+ (host ?? task)[field] = fiber;
1720
+ return fiber;
1608
1721
  }
1609
- static struct(type, kids = [], span = $mol_span.unknown) {
1610
- if (/[ \n\t\\]/.test(type)) {
1611
- $$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
1722
+ static plex(host, task, key) {
1723
+ const field = task.name + '()';
1724
+ let dict = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
1725
+ const prefix = host?.[Symbol.toStringTag] ?? (host instanceof Function ? $$.$mol_func_name(host) : host);
1726
+ const id = `${prefix}.${task.name}(${$mol_key(key).replace(/^"|"$/g, "'")})`;
1727
+ if (dict) {
1728
+ const existen = dict.get(id);
1729
+ if (existen)
1730
+ return existen;
1612
1731
  }
1613
- return new $mol_tree2(type, '', kids, span);
1614
- }
1615
- struct(type, kids = []) {
1616
- return $mol_tree2.struct(type, kids, this.span);
1617
- }
1618
- clone(kids, span = this.span) {
1619
- return new $mol_tree2(this.type, this.value, kids, span);
1620
- }
1621
- text() {
1622
- var values = [];
1623
- for (var kid of this.kids) {
1624
- if (kid.type)
1625
- continue;
1626
- values.push(kid.value);
1732
+ else {
1733
+ dict = (host ?? task)[field] = new Map();
1627
1734
  }
1628
- return this.value + values.join('\n');
1629
- }
1630
- static fromString(str, uri = 'unknown') {
1631
- return $$.$mol_tree2_from_string(str, uri);
1632
- }
1633
- toString() {
1634
- return $$.$mol_tree2_to_string(this);
1735
+ const fiber = new $mol_wire_atom(id, task, host, [key]);
1736
+ dict.set(id, fiber);
1737
+ return fiber;
1635
1738
  }
1636
- insert(value, ...path) {
1637
- if (path.length === 0)
1638
- return value;
1639
- const type = path[0];
1640
- if (typeof type === 'string') {
1641
- let replaced = false;
1642
- const sub = this.kids.map((item, index) => {
1643
- if (item.type !== type)
1644
- return item;
1645
- replaced = true;
1646
- return item.insert(value, ...path.slice(1));
1647
- }).filter(Boolean);
1648
- if (!replaced && value) {
1649
- sub.push(this.struct(type, []).insert(value, ...path.slice(1)));
1739
+ static watching = new Set();
1740
+ static watcher = null;
1741
+ static watch() {
1742
+ $mol_wire_atom.watcher = new $mol_after_frame($mol_wire_atom.watch);
1743
+ for (const atom of $mol_wire_atom.watching) {
1744
+ if (atom.cursor === $mol_wire_cursor.final) {
1745
+ $mol_wire_atom.watching.delete(atom);
1746
+ }
1747
+ else {
1748
+ atom.cursor = $mol_wire_cursor.stale;
1749
+ atom.fresh();
1650
1750
  }
1651
- return this.clone(sub);
1652
- }
1653
- else if (typeof type === 'number') {
1654
- const sub = this.kids.slice();
1655
- sub[type] = (sub[type] || this.list([]))
1656
- .insert(value, ...path.slice(1));
1657
- return this.clone(sub.filter(Boolean));
1658
- }
1659
- else {
1660
- const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
1661
- .map(item => item.insert(value, ...path.slice(1)))
1662
- .filter(Boolean);
1663
- return this.clone(kids);
1664
1751
  }
1665
1752
  }
1666
- select(...path) {
1667
- let next = [this];
1668
- for (const type of path) {
1669
- if (!next.length)
1670
- break;
1671
- const prev = next;
1672
- next = [];
1673
- for (var item of prev) {
1674
- switch (typeof (type)) {
1675
- case 'string':
1676
- for (var child of item.kids) {
1677
- if (child.type == type) {
1678
- next.push(child);
1679
- }
1680
- }
1681
- break;
1682
- case 'number':
1683
- if (type < item.kids.length)
1684
- next.push(item.kids[type]);
1685
- break;
1686
- default: next.push(...item.kids);
1687
- }
1688
- }
1753
+ watch() {
1754
+ if (!$mol_wire_atom.watcher) {
1755
+ $mol_wire_atom.watcher = new $mol_after_frame($mol_wire_atom.watch);
1689
1756
  }
1690
- return this.list(next);
1757
+ $mol_wire_atom.watching.add(this);
1691
1758
  }
1692
- filter(path, value) {
1693
- const sub = this.kids.filter(item => {
1694
- var found = item.select(...path);
1695
- if (value === undefined) {
1696
- return Boolean(found.kids.length);
1759
+ resync(args) {
1760
+ return this.put(this.task.call(this.host, ...args));
1761
+ }
1762
+ once() {
1763
+ return this.sync();
1764
+ }
1765
+ channel() {
1766
+ return Object.assign((next) => {
1767
+ if (next !== undefined)
1768
+ return this.resync([...this.args, next]);
1769
+ if (!$mol_wire_fiber.warm)
1770
+ return this.result();
1771
+ if ($mol_wire_auto()?.temp) {
1772
+ return this.once();
1697
1773
  }
1698
1774
  else {
1699
- return found.kids.some(child => child.value == value);
1700
- }
1701
- });
1702
- return this.clone(sub);
1703
- }
1704
- hack(belt, context = {}) {
1705
- return [].concat(...this.kids.map(child => {
1706
- let handle = belt[child.type] || belt[''];
1707
- if (!handle || handle === Object.prototype[child.type]) {
1708
- handle = (input, belt, context) => [
1709
- input.clone(input.hack(belt, context), context.span)
1710
- ];
1775
+ return this.sync();
1711
1776
  }
1777
+ }, { atom: this });
1778
+ }
1779
+ destructor() {
1780
+ super.destructor();
1781
+ const prev = this.cache;
1782
+ if ($mol_owning_check(this, prev)) {
1783
+ prev.destructor();
1784
+ }
1785
+ if (this.pub_from === 0) {
1786
+ ;
1787
+ (this.host ?? this.task)[this.field()] = null;
1788
+ }
1789
+ else {
1790
+ ;
1791
+ (this.host ?? this.task)[this.field()].delete(this[Symbol.toStringTag]);
1792
+ }
1793
+ }
1794
+ put(next) {
1795
+ const prev = this.cache;
1796
+ update: if (next !== prev) {
1712
1797
  try {
1713
- return handle(child, belt, context);
1798
+ if ($mol_compare_deep(prev, next))
1799
+ break update;
1714
1800
  }
1715
1801
  catch (error) {
1716
- error.message += `\n${child.clone([])}${child.span}`;
1717
- $mol_fail_hidden(error);
1802
+ $mol_fail_log(error);
1718
1803
  }
1719
- }));
1720
- }
1721
- error(message, Class = Error) {
1722
- return this.span.error(`${message}\n${this.clone([])}`, Class);
1723
- }
1724
- }
1725
- $.$mol_tree2 = $mol_tree2;
1726
- class $mol_tree2_empty extends $mol_tree2 {
1727
- constructor() {
1728
- super('', '', [], $mol_span.unknown);
1804
+ if ($mol_owning_check(this, prev)) {
1805
+ prev.destructor();
1806
+ }
1807
+ if ($mol_owning_catch(this, next)) {
1808
+ try {
1809
+ next[Symbol.toStringTag] = this[Symbol.toStringTag];
1810
+ }
1811
+ catch {
1812
+ Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
1813
+ }
1814
+ }
1815
+ if (!this.sub_empty)
1816
+ this.emit();
1817
+ }
1818
+ this.cache = next;
1819
+ this.cursor = $mol_wire_cursor.fresh;
1820
+ if ($mol_promise_like(next))
1821
+ return next;
1822
+ this.complete_pubs();
1823
+ return next;
1729
1824
  }
1730
1825
  }
1731
- $.$mol_tree2_empty = $mol_tree2_empty;
1826
+ __decorate([
1827
+ $mol_wire_method
1828
+ ], $mol_wire_atom.prototype, "resync", null);
1829
+ __decorate([
1830
+ $mol_wire_method
1831
+ ], $mol_wire_atom.prototype, "once", null);
1832
+ $.$mol_wire_atom = $mol_wire_atom;
1732
1833
  })($ || ($ = {}));
1733
- //mol/tree2/tree2.ts
1834
+ //mol/wire/atom/atom.ts
1734
1835
  ;
1735
1836
  "use strict";
1736
1837
  var $;
1737
1838
  (function ($) {
1738
- class $mol_error_syntax extends SyntaxError {
1739
- reason;
1740
- line;
1741
- span;
1742
- constructor(reason, line, span) {
1743
- super(`${reason}\n${span}\n${line.substring(0, span.col - 1).replace(/\S/g, ' ')}${''.padEnd(span.length, '!')}\n${line}`);
1744
- this.reason = reason;
1745
- this.line = line;
1746
- this.span = span;
1839
+ function $mol_wire_solo(host, field, descr) {
1840
+ if (!descr)
1841
+ descr = Reflect.getOwnPropertyDescriptor(host, field);
1842
+ const orig = descr?.value ?? host[field];
1843
+ const sup = Reflect.getPrototypeOf(host);
1844
+ if (typeof sup[field] === 'function') {
1845
+ Object.defineProperty(orig, 'name', { value: sup[field].name });
1747
1846
  }
1748
- }
1749
- $.$mol_error_syntax = $mol_error_syntax;
1750
- })($ || ($ = {}));
1751
- //mol/error/syntax/syntax.ts
1752
- ;
1753
- "use strict";
1754
- var $;
1755
- (function ($) {
1756
- function $mol_tree2_from_string(str, uri = '?') {
1757
- const span = $mol_span.entire(uri, str);
1758
- var root = $mol_tree2.list([], span);
1759
- var stack = [root];
1760
- var pos = 0, row = 0, min_indent = 0;
1761
- while (str.length > pos) {
1762
- var indent = 0;
1763
- var line_start = pos;
1764
- row++;
1765
- while (str.length > pos && str[pos] == '\t') {
1766
- indent++;
1767
- pos++;
1768
- }
1769
- if (!root.kids.length) {
1770
- min_indent = indent;
1771
- }
1772
- indent -= min_indent;
1773
- if (indent < 0 || indent >= stack.length) {
1774
- const sp = span.span(row, 1, pos - line_start);
1775
- while (str.length > pos && str[pos] != '\n') {
1776
- pos++;
1777
- }
1778
- if (indent < 0) {
1779
- if (str.length > pos) {
1780
- this.$mol_fail(new this.$mol_error_syntax(`Too few tabs`, str.substring(line_start, pos), sp));
1847
+ const descr2 = {
1848
+ ...descr,
1849
+ value: function (...args) {
1850
+ let atom = $mol_wire_atom.solo(this, orig);
1851
+ if ((args.length === 0) || (args[0] === undefined)) {
1852
+ if (!$mol_wire_fiber.warm)
1853
+ return atom.result();
1854
+ if ($mol_wire_auto()?.temp) {
1855
+ return atom.once();
1856
+ }
1857
+ else {
1858
+ return atom.sync();
1781
1859
  }
1782
1860
  }
1783
- else {
1784
- this.$mol_fail(new this.$mol_error_syntax(`Too many tabs`, str.substring(line_start, pos), sp));
1785
- }
1786
- }
1787
- stack.length = indent + 1;
1788
- var parent = stack[indent];
1789
- while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
1790
- var error_start = pos;
1791
- while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
1792
- pos++;
1793
- }
1794
- if (pos > error_start) {
1795
- let line_end = str.indexOf('\n', pos);
1796
- if (line_end === -1)
1797
- line_end = str.length;
1798
- const sp = span.span(row, error_start - line_start + 1, pos - error_start);
1799
- this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
1800
- }
1801
- var type_start = pos;
1802
- while (str.length > pos &&
1803
- str[pos] != '\\' &&
1804
- str[pos] != ' ' &&
1805
- str[pos] != '\t' &&
1806
- str[pos] != '\n') {
1807
- pos++;
1808
- }
1809
- if (pos > type_start) {
1810
- let next = new $mol_tree2(str.slice(type_start, pos), '', [], span.span(row, type_start - line_start + 1, pos - type_start));
1811
- const parent_kids = parent.kids;
1812
- parent_kids.push(next);
1813
- parent = next;
1814
- }
1815
- if (str.length > pos && str[pos] == ' ') {
1816
- pos++;
1817
- }
1818
- }
1819
- if (str.length > pos && str[pos] == '\\') {
1820
- var data_start = pos;
1821
- while (str.length > pos && str[pos] != '\n') {
1822
- pos++;
1823
- }
1824
- let next = new $mol_tree2('', str.slice(data_start + 1, pos), [], span.span(row, data_start - line_start + 2, pos - data_start - 1));
1825
- const parent_kids = parent.kids;
1826
- parent_kids.push(next);
1827
- parent = next;
1828
- }
1829
- if (str.length === pos && stack.length > 0) {
1830
- const sp = span.span(row, pos - line_start + 1, 1);
1831
- this.$mol_fail(new this.$mol_error_syntax(`Unexpected EOF, LF required`, str.substring(line_start, str.length), sp));
1861
+ return atom.resync(args);
1832
1862
  }
1833
- stack.push(parent);
1834
- pos++;
1835
- }
1836
- return root;
1863
+ };
1864
+ Reflect.defineProperty(descr2.value, 'name', { value: orig.name + ' ' });
1865
+ Reflect.defineProperty(descr2.value, 'length', { value: orig.length });
1866
+ Object.assign(descr2.value, { orig });
1867
+ Reflect.defineProperty(host, field, descr2);
1868
+ return descr2;
1837
1869
  }
1838
- $.$mol_tree2_from_string = $mol_tree2_from_string;
1870
+ $.$mol_wire_solo = $mol_wire_solo;
1839
1871
  })($ || ($ = {}));
1840
- //mol/tree2/from/string/string.ts
1872
+ //mol/wire/solo/solo.ts
1841
1873
  ;
1842
1874
  "use strict";
1843
1875
  var $;
1844
1876
  (function ($) {
1845
- function $mol_tree2_from_json(json, span = $mol_span.unknown) {
1846
- if (typeof json === 'boolean' || typeof json === 'number' || json === null) {
1847
- return new $mol_tree2(String(json), '', [], span);
1848
- }
1849
- if (typeof json === 'string') {
1850
- return $mol_tree2.data(json, [], span);
1851
- }
1852
- if (Array.isArray(json)) {
1853
- const sub = json.map(json => $mol_tree2_from_json(json, span));
1854
- return new $mol_tree2('/', '', sub, span);
1855
- }
1856
- if (ArrayBuffer.isView(json)) {
1857
- const buf = new Uint8Array(json.buffer, json.byteOffset, json.byteLength);
1858
- return $mol_tree2.data(String.fromCharCode(...buf), [], span);
1859
- }
1860
- if (json instanceof Date) {
1861
- return new $mol_tree2('', json.toISOString(), [], span);
1862
- }
1863
- if (typeof json.toJSON === 'function') {
1864
- return $mol_tree2_from_json(json.toJSON());
1865
- }
1866
- if (json instanceof Error) {
1867
- const { name, message, stack } = json;
1868
- json = { ...json, name, message, stack };
1877
+ function $mol_wire_plex(host, field, descr) {
1878
+ if (!descr)
1879
+ descr = Reflect.getOwnPropertyDescriptor(host, field);
1880
+ const orig = descr?.value ?? host[field];
1881
+ const sup = Reflect.getPrototypeOf(host);
1882
+ if (typeof sup[field] === 'function') {
1883
+ Object.defineProperty(orig, 'name', { value: sup[field].name });
1869
1884
  }
1870
- const sub = [];
1871
- for (var key in json) {
1872
- const val = json[key];
1873
- if (val === undefined)
1874
- continue;
1875
- const subsub = $mol_tree2_from_json(val, span);
1876
- if (/^[^\n\t\\ ]+$/.test(key)) {
1877
- sub.push(new $mol_tree2(key, '', [subsub], span));
1878
- }
1879
- else {
1880
- sub.push($mol_tree2.data(key, [subsub], span));
1885
+ const descr2 = {
1886
+ ...descr,
1887
+ value: function (...args) {
1888
+ let atom = $mol_wire_atom.plex(this, orig, args[0]);
1889
+ if ((args.length === 1) || (args[1] === undefined)) {
1890
+ if (!$mol_wire_fiber.warm)
1891
+ return atom.result();
1892
+ if ($mol_wire_auto()?.temp) {
1893
+ return atom.once();
1894
+ }
1895
+ else {
1896
+ return atom.sync();
1897
+ }
1898
+ }
1899
+ return atom.resync(args);
1881
1900
  }
1882
- }
1883
- return new $mol_tree2('*', '', sub, span);
1901
+ };
1902
+ Reflect.defineProperty(descr2.value, 'name', { value: orig.name + ' ' });
1903
+ Reflect.defineProperty(descr2.value, 'length', { value: orig.length });
1904
+ Object.assign(descr2.value, { orig });
1905
+ Reflect.defineProperty(host, field, descr2);
1906
+ return descr2;
1884
1907
  }
1885
- $.$mol_tree2_from_json = $mol_tree2_from_json;
1908
+ $.$mol_wire_plex = $mol_wire_plex;
1886
1909
  })($ || ($ = {}));
1887
- //mol/tree2/from/json/json.ts
1910
+ //mol/wire/plex/plex.ts
1888
1911
  ;
1889
1912
  "use strict";
1890
1913
  var $;
1891
1914
  (function ($) {
1892
- class $mol_term_color {
1893
- static reset = this.ansi(0, 0);
1894
- static bold = this.ansi(1, 22);
1895
- static italic = this.ansi(3, 23);
1896
- static underline = this.ansi(4, 24);
1897
- static inverse = this.ansi(7, 27);
1898
- static hidden = this.ansi(8, 28);
1899
- static strike = this.ansi(9, 29);
1900
- static gray = this.ansi(90, 39);
1901
- static red = this.ansi(91, 39);
1902
- static green = this.ansi(92, 39);
1903
- static yellow = this.ansi(93, 39);
1904
- static blue = this.ansi(94, 39);
1905
- static magenta = this.ansi(95, 39);
1906
- static cyan = this.ansi(96, 39);
1907
- static Gray = (str) => this.inverse(this.gray(str));
1908
- static Red = (str) => this.inverse(this.red(str));
1909
- static Green = (str) => this.inverse(this.green(str));
1910
- static Yellow = (str) => this.inverse(this.yellow(str));
1911
- static Blue = (str) => this.inverse(this.blue(str));
1912
- static Magenta = (str) => this.inverse(this.magenta(str));
1913
- static Cyan = (str) => this.inverse(this.cyan(str));
1914
- static ansi(open, close) {
1915
- if (typeof process === 'undefined')
1916
- return String;
1917
- if (!process.stdout.isTTY)
1918
- return String;
1919
- const prefix = `\x1b[${open}m`;
1920
- const postfix = `\x1b[${close}m`;
1921
- const suffix_regexp = new RegExp(postfix.replace('[', '\\['), 'g');
1922
- return function colorer(str) {
1923
- str = String(str);
1924
- if (str === '')
1925
- return str;
1926
- const suffix = str.replace(suffix_regexp, prefix);
1927
- return prefix + suffix + postfix;
1928
- };
1929
- }
1930
- }
1931
- $.$mol_term_color = $mol_term_color;
1915
+ $.$mol_mem = $mol_wire_solo;
1916
+ $.$mol_mem_key = $mol_wire_plex;
1932
1917
  })($ || ($ = {}));
1933
- //mol/term/color/color.ts
1918
+ //mol/mem/mem.ts
1934
1919
  ;
1935
1920
  "use strict";
1936
1921
  var $;
1937
1922
  (function ($) {
1938
- function $mol_log3_node_make(level, output, type, color) {
1939
- return function $mol_log3_logger(event) {
1940
- if (!event.time)
1941
- event = { time: new Date().toISOString(), ...event };
1942
- let tree = this.$mol_tree2_from_json(event);
1943
- tree = tree.struct(type, tree.kids);
1944
- let str = color(tree.toString());
1945
- this.console[level](str);
1946
- const self = this;
1947
- return () => self.console.groupEnd();
1948
- };
1949
- }
1950
- $.$mol_log3_node_make = $mol_log3_node_make;
1951
- $.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', $mol_term_color.blue);
1952
- $.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', $mol_term_color.green);
1953
- $.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', $mol_term_color.red);
1954
- $.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', $mol_term_color.yellow);
1955
- $.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', $mol_term_color.magenta);
1956
- $.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', $mol_term_color.cyan);
1957
1923
  })($ || ($ = {}));
1958
- //mol/log3/log3.node.ts
1924
+ //mol/dom/context/context.ts
1925
+ ;
1926
+ "use strict";
1927
+ //node/node.ts
1928
+ ;
1929
+ "use strict";
1930
+ var $node = new Proxy({ require }, {
1931
+ get(target, name, wrapper) {
1932
+ if (target[name])
1933
+ return target[name];
1934
+ const mod = target.require('module');
1935
+ if (mod.builtinModules.indexOf(name) >= 0)
1936
+ return target.require(name);
1937
+ if (name[0] === '.')
1938
+ return target.require(name);
1939
+ const path = target.require('path');
1940
+ const fs = target.require('fs');
1941
+ let dir = path.resolve('.');
1942
+ const suffix = `./node_modules/${name}`;
1943
+ const $$ = $;
1944
+ while (!fs.existsSync(path.join(dir, suffix))) {
1945
+ const parent = path.resolve(dir, '..');
1946
+ if (parent === dir) {
1947
+ $$.$mol_exec('.', 'npm', 'install', '--omit=dev', name);
1948
+ try {
1949
+ $$.$mol_exec('.', 'npm', 'install', '--omit=dev', '@types/' + name);
1950
+ }
1951
+ catch { }
1952
+ break;
1953
+ }
1954
+ else {
1955
+ dir = parent;
1956
+ }
1957
+ }
1958
+ return target.require(name);
1959
+ },
1960
+ set(target, name, value) {
1961
+ target[name] = value;
1962
+ return true;
1963
+ },
1964
+ });
1965
+ require = (req => Object.assign(function require(name) {
1966
+ return $node[name];
1967
+ }, req))(require);
1968
+ //node/node.node.ts
1959
1969
  ;
1960
1970
  "use strict";
1961
1971
  var $;
@@ -5591,279 +5601,6 @@ var $;
5591
5601
  //mol/file/file.node.ts
5592
5602
  ;
5593
5603
  "use strict";
5594
- //hyoo/hyoo.ts
5595
- ;
5596
- "use strict";
5597
- var $;
5598
- (function ($) {
5599
- $.$mol_action = $mol_wire_method;
5600
- })($ || ($ = {}));
5601
- //mol/action/action.ts
5602
- ;
5603
- "use strict";
5604
- var $;
5605
- (function ($) {
5606
- function $mol_dom_parse(text, type = 'application/xhtml+xml') {
5607
- const parser = new $mol_dom_context.DOMParser();
5608
- const doc = parser.parseFromString(text, type);
5609
- const error = doc.getElementsByTagName('parsererror');
5610
- if (error.length)
5611
- throw new Error(error[0].textContent);
5612
- return doc;
5613
- }
5614
- $.$mol_dom_parse = $mol_dom_parse;
5615
- })($ || ($ = {}));
5616
- //mol/dom/parse/parse.ts
5617
- ;
5618
- "use strict";
5619
- var $;
5620
- (function ($) {
5621
- class $mol_fetch_response extends $mol_object2 {
5622
- native;
5623
- constructor(native) {
5624
- super();
5625
- this.native = native;
5626
- }
5627
- status() {
5628
- const types = ['unknown', 'inform', 'success', 'redirect', 'wrong', 'failed'];
5629
- return types[Math.floor(this.native.status / 100)];
5630
- }
5631
- code() {
5632
- return this.native.status;
5633
- }
5634
- message() {
5635
- return this.native.statusText || `HTTP Error ${this.code()}`;
5636
- }
5637
- headers() {
5638
- return this.native.headers;
5639
- }
5640
- mime() {
5641
- return this.headers().get('content-type');
5642
- }
5643
- stream() {
5644
- return this.native.body;
5645
- }
5646
- text() {
5647
- const buffer = this.buffer();
5648
- const native = this.native;
5649
- const mime = native.headers.get('content-type') || '';
5650
- const [, charset] = /charset=(.*)/.exec(mime) || [, 'utf-8'];
5651
- const decoder = new TextDecoder(charset);
5652
- return decoder.decode(buffer);
5653
- }
5654
- json() {
5655
- return $mol_wire_sync(this.native).json();
5656
- }
5657
- buffer() {
5658
- return $mol_wire_sync(this.native).arrayBuffer();
5659
- }
5660
- xml() {
5661
- return $mol_dom_parse(this.text(), 'application/xml');
5662
- }
5663
- xhtml() {
5664
- return $mol_dom_parse(this.text(), 'application/xhtml+xml');
5665
- }
5666
- html() {
5667
- return $mol_dom_parse(this.text(), 'text/html');
5668
- }
5669
- }
5670
- __decorate([
5671
- $mol_action
5672
- ], $mol_fetch_response.prototype, "stream", null);
5673
- __decorate([
5674
- $mol_action
5675
- ], $mol_fetch_response.prototype, "text", null);
5676
- __decorate([
5677
- $mol_action
5678
- ], $mol_fetch_response.prototype, "buffer", null);
5679
- __decorate([
5680
- $mol_action
5681
- ], $mol_fetch_response.prototype, "xml", null);
5682
- __decorate([
5683
- $mol_action
5684
- ], $mol_fetch_response.prototype, "xhtml", null);
5685
- __decorate([
5686
- $mol_action
5687
- ], $mol_fetch_response.prototype, "html", null);
5688
- $.$mol_fetch_response = $mol_fetch_response;
5689
- class $mol_fetch extends $mol_object2 {
5690
- static request(input, init = {}) {
5691
- const native = globalThis.fetch ?? $node['undici'].fetch;
5692
- const controller = new AbortController();
5693
- let done = false;
5694
- const promise = native(input, {
5695
- ...init,
5696
- signal: controller.signal,
5697
- }).finally(() => {
5698
- done = true;
5699
- });
5700
- return Object.assign(promise, {
5701
- destructor: () => {
5702
- if (!done && !controller.signal.aborted)
5703
- controller.abort();
5704
- },
5705
- });
5706
- }
5707
- static response(input, init) {
5708
- return new $mol_fetch_response($mol_wire_sync(this).request(input, init));
5709
- }
5710
- static success(input, init) {
5711
- const response = this.response(input, init);
5712
- if (response.status() === 'success')
5713
- return response;
5714
- throw new Error(response.message());
5715
- }
5716
- static stream(input, init) {
5717
- return this.success(input, init).stream();
5718
- }
5719
- static text(input, init) {
5720
- return this.success(input, init).text();
5721
- }
5722
- static json(input, init) {
5723
- return this.success(input, init).json();
5724
- }
5725
- static buffer(input, init) {
5726
- return this.success(input, init).buffer();
5727
- }
5728
- static xml(input, init) {
5729
- return this.success(input, init).xml();
5730
- }
5731
- static xhtml(input, init) {
5732
- return this.success(input, init).xhtml();
5733
- }
5734
- static html(input, init) {
5735
- return this.success(input, init).html();
5736
- }
5737
- }
5738
- __decorate([
5739
- $mol_action
5740
- ], $mol_fetch, "response", null);
5741
- __decorate([
5742
- $mol_action
5743
- ], $mol_fetch, "success", null);
5744
- __decorate([
5745
- $mol_action
5746
- ], $mol_fetch, "stream", null);
5747
- __decorate([
5748
- $mol_action
5749
- ], $mol_fetch, "text", null);
5750
- __decorate([
5751
- $mol_action
5752
- ], $mol_fetch, "json", null);
5753
- __decorate([
5754
- $mol_action
5755
- ], $mol_fetch, "buffer", null);
5756
- __decorate([
5757
- $mol_action
5758
- ], $mol_fetch, "xml", null);
5759
- __decorate([
5760
- $mol_action
5761
- ], $mol_fetch, "xhtml", null);
5762
- __decorate([
5763
- $mol_action
5764
- ], $mol_fetch, "html", null);
5765
- $.$mol_fetch = $mol_fetch;
5766
- })($ || ($ = {}));
5767
- //mol/fetch/fetch.ts
5768
- ;
5769
- "use strict";
5770
- var $;
5771
- (function ($) {
5772
- function $mol_huggingface_run(space, method, ...data) {
5773
- while (true) {
5774
- try {
5775
- if (typeof method === 'number') {
5776
- return $mol_wire_sync(this).$mol_huggingface_ws(space, method, ...data);
5777
- }
5778
- else {
5779
- return this.$mol_huggingface_rest(space, method, ...data);
5780
- }
5781
- }
5782
- catch (error) {
5783
- if ($mol_promise_like(error))
5784
- $mol_fail_hidden(error);
5785
- if (error instanceof Error && error.message === `Queue full`) {
5786
- $mol_fail_log(error);
5787
- continue;
5788
- }
5789
- $mol_fail_hidden(error);
5790
- }
5791
- }
5792
- }
5793
- $.$mol_huggingface_run = $mol_huggingface_run;
5794
- function $mol_huggingface_rest(space, method, ...data) {
5795
- const uri = `https://${space}.hf.space/run/${method}`;
5796
- const response = $mol_fetch.json(uri, {
5797
- method: 'post',
5798
- headers: { "Content-Type": "application/json" },
5799
- body: JSON.stringify({ data }),
5800
- });
5801
- if ('error' in response) {
5802
- $mol_fail(new Error(response.error ?? 'Unknown API error'));
5803
- }
5804
- return response.data;
5805
- }
5806
- $.$mol_huggingface_rest = $mol_huggingface_rest;
5807
- function $mol_huggingface_ws(space, fn_index, ...data) {
5808
- const session_hash = $mol_guid();
5809
- const socket = new WebSocket(`wss://${space}.hf.space/queue/join`);
5810
- const promise = new Promise((done, fail) => {
5811
- socket.onclose = event => {
5812
- if (event.reason)
5813
- fail(new Error(event.reason));
5814
- };
5815
- socket.onerror = event => {
5816
- fail(new Error(`Socket error`));
5817
- };
5818
- socket.onmessage = event => {
5819
- const message = JSON.parse(event.data);
5820
- switch (message.msg) {
5821
- case 'send_hash':
5822
- return socket.send(JSON.stringify({ session_hash, fn_index }));
5823
- case 'estimation': return;
5824
- case 'queue_full':
5825
- fail(new Error(`Queue full`));
5826
- case 'send_data':
5827
- return socket.send(JSON.stringify({ session_hash, fn_index, data }));
5828
- case 'process_starts': return;
5829
- case 'process_completed':
5830
- if (message.success) {
5831
- return done(message.output.data);
5832
- }
5833
- else {
5834
- return fail(new Error(message.output.error ?? `Unknown API error`));
5835
- }
5836
- default:
5837
- return fail(new Error(`Unknown message type: ${message.msg}`));
5838
- }
5839
- };
5840
- });
5841
- return Object.assign(promise, {
5842
- destructor: () => socket.close()
5843
- });
5844
- }
5845
- $.$mol_huggingface_ws = $mol_huggingface_ws;
5846
- })($ || ($ = {}));
5847
- //mol/huggingface/huggingface.ts
5848
- ;
5849
- "use strict";
5850
- var $;
5851
- (function ($) {
5852
- function $hyoo_lingua_translate(lang, text) {
5853
- if (!text.trim())
5854
- return '';
5855
- const cache_key = `$hyoo_lingua_translate(${JSON.stringify(lang)},${JSON.stringify(text)})`;
5856
- const cached = this.$mol_state_local.value(cache_key);
5857
- if (cached)
5858
- return String(cached);
5859
- const translated = this.$mol_huggingface_run('hyoo-translate', 0, lang, text)[0];
5860
- return this.$mol_state_local.value(cache_key, translated);
5861
- }
5862
- $.$hyoo_lingua_translate = $hyoo_lingua_translate;
5863
- })($ || ($ = {}));
5864
- //hyoo/lingua/translate/translate.ts
5865
- ;
5866
- "use strict";
5867
5604
  var $;
5868
5605
  (function ($) {
5869
5606
  class $mol_locale extends $mol_object {
@@ -5900,12 +5637,6 @@ var $;
5900
5637
  const en = this.texts('en')[key];
5901
5638
  if (!en)
5902
5639
  return key;
5903
- try {
5904
- return $mol_wire_sync($hyoo_lingua_translate).call(this.$, lang, en);
5905
- }
5906
- catch (error) {
5907
- $mol_fail_log(error);
5908
- }
5909
5640
  return en;
5910
5641
  }
5911
5642
  static warn(key) {
@@ -7565,17 +7296,6 @@ var $;
7565
7296
  ;
7566
7297
  "use strict";
7567
7298
  var $;
7568
- (function ($) {
7569
- function $mol_dom_serialize(node) {
7570
- const serializer = new $mol_dom_context.XMLSerializer;
7571
- return serializer.serializeToString(node);
7572
- }
7573
- $.$mol_dom_serialize = $mol_dom_serialize;
7574
- })($ || ($ = {}));
7575
- //mol/dom/serialize/serialize.ts
7576
- ;
7577
- "use strict";
7578
- var $;
7579
7299
  (function ($) {
7580
7300
  function $mol_assert_ok(value) {
7581
7301
  if (value)
@@ -7596,14 +7316,12 @@ var $;
7596
7316
  handler();
7597
7317
  }
7598
7318
  catch (error) {
7599
- if (!ErrorRight)
7600
- return error;
7601
7319
  $.$mol_fail = fail;
7602
7320
  if (typeof ErrorRight === 'string') {
7603
7321
  $mol_assert_equal(error.message, ErrorRight);
7604
7322
  }
7605
7323
  else {
7606
- $mol_assert_ok(error instanceof ErrorRight);
7324
+ $mol_assert_equal(error instanceof ErrorRight, true);
7607
7325
  }
7608
7326
  return error;
7609
7327
  }
@@ -7613,58 +7331,47 @@ var $;
7613
7331
  $mol_fail(new Error('Not failed'));
7614
7332
  }
7615
7333
  $.$mol_assert_fail = $mol_assert_fail;
7616
- function $mol_assert_equal(...args) {
7617
- for (let i = 0; i < args.length; ++i) {
7618
- for (let j = 0; j < args.length; ++j) {
7619
- if (i === j)
7620
- continue;
7621
- if (Number.isNaN(args[i]) && Number.isNaN(args[j]))
7622
- continue;
7623
- if (args[i] !== args[j])
7624
- $mol_fail(new Error(`Not equal (${i + 1}:${j + 1})\n${args[i]}\n${args[j]}`));
7625
- }
7626
- }
7334
+ function $mol_assert_like(...args) {
7335
+ $mol_assert_equal(...args);
7627
7336
  }
7628
- $.$mol_assert_equal = $mol_assert_equal;
7337
+ $.$mol_assert_like = $mol_assert_like;
7629
7338
  function $mol_assert_unique(...args) {
7630
7339
  for (let i = 0; i < args.length; ++i) {
7631
7340
  for (let j = 0; j < args.length; ++j) {
7632
7341
  if (i === j)
7633
7342
  continue;
7634
- if (args[i] === args[j] || (Number.isNaN(args[i]) && Number.isNaN(args[j]))) {
7635
- $mol_fail(new Error(`args[${i}] = args[${j}] = ${args[i]}`));
7636
- }
7343
+ if (!$mol_compare_deep(args[i], args[j]))
7344
+ continue;
7345
+ $mol_fail(new Error(`args[${i}] = args[${j}] = ${args[i]}`));
7637
7346
  }
7638
7347
  }
7639
7348
  }
7640
7349
  $.$mol_assert_unique = $mol_assert_unique;
7641
- function $mol_assert_like(head, ...tail) {
7642
- for (let [index, value] of Object.entries(tail)) {
7643
- if (!$mol_compare_deep(value, head)) {
7644
- const print = (val) => {
7645
- if (!val)
7646
- return val;
7647
- if (typeof val !== 'object')
7648
- return val;
7649
- if ('outerHTML' in val)
7650
- return val.outerHTML;
7651
- try {
7652
- return JSON.stringify(val, (k, v) => typeof v === 'bigint' ? String(v) : v, '\t');
7653
- }
7654
- catch (error) {
7655
- console.error(error);
7656
- return val;
7657
- }
7658
- };
7659
- return $mol_fail(new Error(`Not like (1:${+index + 2})\n${print(head)}\n---\n${print(value)}`));
7660
- }
7350
+ function $mol_assert_equal(...args) {
7351
+ for (let i = 1; i < args.length; ++i) {
7352
+ if ($mol_compare_deep(args[0], args[i]))
7353
+ continue;
7354
+ if (args[0] instanceof Element && args[i] instanceof Element && args[0].outerHTML === args[i].outerHTML)
7355
+ continue;
7356
+ return $mol_fail(new Error(`args[0] args[${i}]\n${print(args[0])}\n---\n${print(args[i])}`));
7661
7357
  }
7662
7358
  }
7663
- $.$mol_assert_like = $mol_assert_like;
7664
- function $mol_assert_dom(left, right) {
7665
- $mol_assert_equal($mol_dom_serialize(left), $mol_dom_serialize(right));
7666
- }
7667
- $.$mol_assert_dom = $mol_assert_dom;
7359
+ $.$mol_assert_equal = $mol_assert_equal;
7360
+ const print = (val) => {
7361
+ if (!val)
7362
+ return val;
7363
+ if (typeof val !== 'object')
7364
+ return val;
7365
+ if ('outerHTML' in val)
7366
+ return val.outerHTML;
7367
+ try {
7368
+ return JSON.stringify(val, (k, v) => typeof v === 'bigint' ? String(v) : v, '\t');
7369
+ }
7370
+ catch (error) {
7371
+ console.error(error);
7372
+ return val;
7373
+ }
7374
+ };
7668
7375
  })($ || ($ = {}));
7669
7376
  //mol/assert/assert.ts
7670
7377
  ;
@@ -7685,10 +7392,10 @@ var $;
7685
7392
  $mol_assert_equal(2, 2, 2);
7686
7393
  },
7687
7394
  'two must be unique'() {
7688
- $mol_assert_unique([3], [3]);
7395
+ $mol_assert_unique([2], [3]);
7689
7396
  },
7690
7397
  'three must be unique'() {
7691
- $mol_assert_unique([3], [3], [3]);
7398
+ $mol_assert_unique([1], [2], [3]);
7692
7399
  },
7693
7400
  'two must be alike'() {
7694
7401
  $mol_assert_like([3], [3]);
@@ -8435,7 +8142,7 @@ var $;
8435
8142
  ], App, "result", null);
8436
8143
  $mol_assert_equal(App.result(), 1);
8437
8144
  App.condition(true);
8438
- $mol_assert_fail(() => App.result());
8145
+ $mol_assert_fail(() => App.result(), 'test error');
8439
8146
  App.condition(false);
8440
8147
  $mol_assert_equal(App.result(), 1);
8441
8148
  },
@@ -9374,14 +9081,14 @@ var $;
9374
9081
  },
9375
9082
  'slice span - out of range'($) {
9376
9083
  const span = new $mol_span('test.ts', '', 1, 3, 5);
9377
- $mol_assert_fail(() => span.slice(-1, 3));
9378
- $mol_assert_fail(() => span.slice(1, 6));
9379
- $mol_assert_fail(() => span.slice(1, 10));
9084
+ $mol_assert_fail(() => span.slice(-1, 3), `End value '3' can't be less than begin value (test.ts#1:3/5)`);
9085
+ $mol_assert_fail(() => span.slice(1, 6), `End value '6' out of range (test.ts#1:3/5)`);
9086
+ $mol_assert_fail(() => span.slice(1, 10), `End value '10' out of range (test.ts#1:3/5)`);
9380
9087
  },
9381
9088
  'error handling'($) {
9382
9089
  const span = new $mol_span('test.ts', '', 1, 3, 4);
9383
- const error = span.error('Some error\n');
9384
- $mol_assert_equal(error.message, 'Some error\ntest.ts#1:3/4');
9090
+ const error = span.error('Some error');
9091
+ $mol_assert_equal(error.message, 'Some error (test.ts#1:3/4)');
9385
9092
  }
9386
9093
  });
9387
9094
  })($ || ($ = {}));