hyoo_sync_client 0.0.18 → 0.0.19

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/web.js CHANGED
@@ -32,7 +32,7 @@ $.$$ = $
32
32
  //hyoo/hyoo.ts
33
33
  ;
34
34
  "use strict";
35
- let $hyoo_sync_revision = "8b9fe5e";
35
+ let $hyoo_sync_revision = "fac6330";
36
36
  //hyoo/sync/-meta.tree/revision.meta.tree.ts
37
37
  ;
38
38
  "use strict";
@@ -207,2101 +207,2101 @@ var $;
207
207
  //mol/object2/object2.ts
208
208
  ;
209
209
  "use strict";
210
+ //node/node.ts
211
+ ;
212
+ "use strict";
213
+ var $node = $node || {};
214
+ //node/node.web.ts
215
+ ;
216
+ "use strict";
210
217
  var $;
211
218
  (function ($) {
212
- let $mol_wire_cursor;
213
- (function ($mol_wire_cursor) {
214
- $mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
215
- $mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
216
- $mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
217
- $mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
218
- })($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
219
+ const TextEncoder = globalThis.TextEncoder ?? $node.util.TextEncoder;
220
+ const encoder = new TextEncoder();
221
+ function $mol_charset_encode(value) {
222
+ return encoder.encode(value);
223
+ }
224
+ $.$mol_charset_encode = $mol_charset_encode;
219
225
  })($ || ($ = {}));
220
- //mol/wire/cursor/cursor.ts
226
+ //mol/charset/encode/encode.ts
221
227
  ;
222
228
  "use strict";
223
229
  var $;
224
230
  (function ($) {
225
- class $mol_wire_pub extends Object {
226
- data = [];
227
- static get [Symbol.species]() {
228
- return Array;
229
- }
230
- sub_from = 0;
231
- get sub_list() {
232
- const res = [];
233
- for (let i = this.sub_from; i < this.data.length; i += 2) {
234
- res.push(this.data[i]);
235
- }
236
- return res;
237
- }
238
- get sub_empty() {
239
- return this.sub_from === this.data.length;
240
- }
241
- sub_on(sub, pub_pos) {
242
- const pos = this.data.length;
243
- this.data.push(sub, pub_pos);
244
- return pos;
245
- }
246
- sub_off(sub_pos) {
247
- if (!(sub_pos < this.data.length)) {
248
- $mol_fail(new Error(`Wrong pos ${sub_pos}`));
249
- }
250
- const end = this.data.length - 2;
251
- if (sub_pos !== end) {
252
- this.peer_move(end, sub_pos);
253
- }
254
- this.data.pop();
255
- this.data.pop();
256
- if (this.data.length === this.sub_from)
257
- this.reap();
258
- }
259
- reap() { }
260
- promote() {
261
- $mol_wire_auto()?.track_next(this);
231
+ function $mol_int62_string_ensure(str) {
232
+ if (typeof str !== 'string')
233
+ return null;
234
+ return $mol_int62_from_string(str) && str;
235
+ }
236
+ $.$mol_int62_string_ensure = $mol_int62_string_ensure;
237
+ $.$mol_int62_max = (2 ** 30) - 1;
238
+ $.$mol_int62_min = -(2 ** 30);
239
+ $.$mol_int62_range = $.$mol_int62_max - $.$mol_int62_min + 1;
240
+ function $mol_int62_to_string({ lo, hi }) {
241
+ lo = (lo + $.$mol_int62_range) % $.$mol_int62_range;
242
+ hi = (hi + $.$mol_int62_range) % $.$mol_int62_range;
243
+ return lo.toString(36) + '_' + hi.toString(36);
244
+ }
245
+ $.$mol_int62_to_string = $mol_int62_to_string;
246
+ function $mol_int62_from_string(str) {
247
+ const [str_lo, str_hi] = str.split('_');
248
+ const int_lo = parseInt(str_lo, 36);
249
+ const int_hi = parseInt(str_hi, 36);
250
+ if (int_lo.toString(36) !== str_lo || int_hi.toString(36) !== str_hi) {
251
+ return null;
262
252
  }
263
- fresh() { }
264
- complete() { }
265
- emit(quant = $mol_wire_cursor.stale) {
266
- for (let i = this.sub_from; i < this.data.length; i += 2) {
267
- ;
268
- this.data[i].absorb(quant);
269
- }
253
+ return {
254
+ lo: (int_lo - $.$mol_int62_min) % $.$mol_int62_range + $.$mol_int62_min,
255
+ hi: (int_hi - $.$mol_int62_min) % $.$mol_int62_range + $.$mol_int62_min,
256
+ };
257
+ }
258
+ $.$mol_int62_from_string = $mol_int62_from_string;
259
+ function $mol_int62_compare(left_lo, left_hi, right_lo, right_hi) {
260
+ return (right_hi - left_hi) || (right_lo - left_lo);
261
+ }
262
+ $.$mol_int62_compare = $mol_int62_compare;
263
+ function $mol_int62_inc(lo, hi, max = $.$mol_int62_max) {
264
+ if (lo === max) {
265
+ return { lo: -max, hi: hi + 1 };
270
266
  }
271
- peer_move(from_pos, to_pos) {
272
- const peer = this.data[from_pos];
273
- const self_pos = this.data[from_pos + 1];
274
- this.data[to_pos] = peer;
275
- this.data[to_pos + 1] = self_pos;
276
- peer.peer_repos(self_pos, to_pos);
267
+ else {
268
+ return { lo: lo + 1, hi };
277
269
  }
278
- peer_repos(peer_pos, self_pos) {
279
- this.data[peer_pos + 1] = self_pos;
270
+ }
271
+ $.$mol_int62_inc = $mol_int62_inc;
272
+ function $mol_int62_random() {
273
+ return {
274
+ lo: Math.floor(Math.random() * $.$mol_int62_range + $.$mol_int62_min),
275
+ hi: Math.floor(Math.random() * $.$mol_int62_range + $.$mol_int62_min),
276
+ };
277
+ }
278
+ $.$mol_int62_random = $mol_int62_random;
279
+ function $mol_int62_hash_string(str) {
280
+ return $mol_int62_to_string($mol_int62_hash_buffer($mol_charset_encode(str)));
281
+ }
282
+ $.$mol_int62_hash_string = $mol_int62_hash_string;
283
+ function $mol_int62_hash_buffer(buf, seed = { lo: 0, hi: 0 }) {
284
+ let h1 = 0xdeadbeef ^ seed.lo;
285
+ let h2 = 0x41c6ce57 ^ seed.hi;
286
+ for (const byte of buf) {
287
+ h1 = Math.imul(h1 ^ byte, 2654435761);
288
+ h2 = Math.imul(h2 ^ byte, 1597334677);
280
289
  }
290
+ h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
291
+ h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
292
+ return { lo: h1 << 1 >> 1, hi: h2 << 1 >> 1 };
281
293
  }
282
- $.$mol_wire_pub = $mol_wire_pub;
294
+ $.$mol_int62_hash_buffer = $mol_int62_hash_buffer;
283
295
  })($ || ($ = {}));
284
- //mol/wire/pub/pub.ts
296
+ //mol/int62/int62.ts
285
297
  ;
286
298
  "use strict";
287
- //mol/wire/sub/sub.ts
299
+ //mol/data/value/value.ts
288
300
  ;
289
301
  "use strict";
290
302
  var $;
291
303
  (function ($) {
292
- $.$mol_wire_auto_sub = null;
293
- function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
294
- return $.$mol_wire_auto_sub = next;
304
+ function $mol_data_setup(value, config) {
305
+ return Object.assign(value, {
306
+ config,
307
+ Value: null
308
+ });
295
309
  }
296
- $.$mol_wire_auto = $mol_wire_auto;
297
- $.$mol_wire_affected = [];
310
+ $.$mol_data_setup = $mol_data_setup;
298
311
  })($ || ($ = {}));
299
- //mol/wire/wire.ts
312
+ //mol/data/setup/setup.ts
300
313
  ;
301
314
  "use strict";
302
315
  var $;
303
316
  (function ($) {
304
- $['devtoolsFormatters'] ||= [];
305
- function $mol_dev_format_register(config) {
306
- $['devtoolsFormatters'].push(config);
307
- }
308
- $.$mol_dev_format_register = $mol_dev_format_register;
309
- $.$mol_dev_format_head = Symbol('$mol_dev_format_head');
310
- $.$mol_dev_format_body = Symbol('$mol_dev_format_body');
311
- $mol_dev_format_register({
312
- header: (val, config = false) => {
313
- if (config)
314
- return null;
315
- if (!val)
316
- return null;
317
- if ($.$mol_dev_format_head in val) {
318
- return val[$.$mol_dev_format_head]();
319
- }
320
- if (typeof val === 'function') {
321
- return $mol_dev_format_native(val);
317
+ function $mol_diff_path(...paths) {
318
+ const limit = Math.min(...paths.map(path => path.length));
319
+ lookup: for (var i = 0; i < limit; ++i) {
320
+ const first = paths[0][i];
321
+ for (let j = 1; j < paths.length; ++j) {
322
+ if (paths[j][i] !== first)
323
+ break lookup;
322
324
  }
323
- return null;
324
- },
325
- hasBody: val => val[$.$mol_dev_format_body],
326
- body: val => val[$.$mol_dev_format_body](),
327
- });
328
- function $mol_dev_format_native(obj) {
329
- if (typeof obj === 'undefined')
330
- return $.$mol_dev_format_shade('undefined');
331
- if (typeof obj !== 'object' && typeof obj !== 'function')
332
- return obj;
333
- return [
334
- 'object',
335
- {
336
- object: obj,
337
- config: true,
338
- },
339
- ];
340
- }
341
- $.$mol_dev_format_native = $mol_dev_format_native;
342
- function $mol_dev_format_auto(obj) {
343
- if (obj == null)
344
- return $.$mol_dev_format_shade(String(obj));
345
- if (typeof obj === 'object' && $.$mol_dev_format_head in obj) {
346
- return obj[$.$mol_dev_format_head]();
347
325
  }
348
- return [
349
- 'object',
350
- {
351
- object: obj,
352
- config: false,
353
- },
354
- ];
355
- }
356
- $.$mol_dev_format_auto = $mol_dev_format_auto;
357
- function $mol_dev_format_element(element, style, ...content) {
358
- const styles = [];
359
- for (let key in style)
360
- styles.push(`${key} : ${style[key]}`);
361
- return [
362
- element,
363
- {
364
- style: styles.join(' ; '),
365
- },
366
- ...content,
367
- ];
368
- }
369
- $.$mol_dev_format_element = $mol_dev_format_element;
370
- function $mol_dev_format_span(style, ...content) {
371
- return $mol_dev_format_element('span', {
372
- 'vertical-align': '8%',
373
- ...style,
374
- }, ...content);
326
+ return {
327
+ prefix: paths[0].slice(0, i),
328
+ suffix: paths.map(path => path.slice(i)),
329
+ };
375
330
  }
376
- $.$mol_dev_format_span = $mol_dev_format_span;
377
- $.$mol_dev_format_div = $mol_dev_format_element.bind(null, 'div');
378
- $.$mol_dev_format_ol = $mol_dev_format_element.bind(null, 'ol');
379
- $.$mol_dev_format_li = $mol_dev_format_element.bind(null, 'li');
380
- $.$mol_dev_format_table = $mol_dev_format_element.bind(null, 'table');
381
- $.$mol_dev_format_tr = $mol_dev_format_element.bind(null, 'tr');
382
- $.$mol_dev_format_td = $mol_dev_format_element.bind(null, 'td');
383
- $.$mol_dev_format_accent = $mol_dev_format_span.bind(null, {
384
- 'color': 'magenta',
385
- });
386
- $.$mol_dev_format_strong = $mol_dev_format_span.bind(null, {
387
- 'font-weight': 'bold',
388
- });
389
- $.$mol_dev_format_string = $mol_dev_format_span.bind(null, {
390
- 'color': 'green',
391
- });
392
- $.$mol_dev_format_shade = $mol_dev_format_span.bind(null, {
393
- 'color': 'gray',
394
- });
395
- $.$mol_dev_format_indent = $.$mol_dev_format_div.bind(null, {
396
- 'margin-left': '13px'
397
- });
331
+ $.$mol_diff_path = $mol_diff_path;
398
332
  })($ || ($ = {}));
399
- //mol/dev/format/format.ts
333
+ //mol/diff/path/path.ts
400
334
  ;
401
335
  "use strict";
402
336
  var $;
403
337
  (function ($) {
404
- class $mol_wire_pub_sub extends $mol_wire_pub {
405
- pub_from = 0;
406
- cursor = $mol_wire_cursor.stale;
407
- get temp() {
408
- return false;
409
- }
410
- get pub_list() {
411
- const res = [];
412
- const max = this.cursor >= 0 ? this.cursor : this.sub_from;
413
- for (let i = this.pub_from; i < max; i += 2) {
414
- if (this.data[i])
415
- res.push(this.data[i]);
416
- }
417
- return res;
418
- }
419
- track_on() {
420
- this.cursor = this.pub_from;
421
- const sub = $mol_wire_auto();
422
- $mol_wire_auto(this);
423
- return sub;
424
- }
425
- promote() {
426
- if (this.cursor >= this.pub_from) {
427
- $mol_fail(new Error('Circular subscription'));
428
- }
429
- super.promote();
430
- }
431
- track_next(pub) {
432
- if (this.cursor < 0)
433
- $mol_fail(new Error('Promo to non begun sub'));
434
- if (this.cursor < this.sub_from) {
435
- const next = this.data[this.cursor];
436
- if (pub === undefined)
437
- return next ?? null;
438
- if (next === pub) {
439
- this.cursor += 2;
440
- return next;
441
- }
442
- if (next) {
443
- if (this.sub_from < this.data.length) {
444
- this.peer_move(this.sub_from, this.data.length);
445
- }
446
- this.peer_move(this.cursor, this.sub_from);
447
- this.sub_from += 2;
448
- }
449
- }
450
- else {
451
- if (pub === undefined)
452
- return null;
453
- if (this.sub_from < this.data.length) {
454
- this.peer_move(this.sub_from, this.data.length);
455
- }
456
- this.sub_from += 2;
457
- }
458
- this.data[this.cursor] = pub;
459
- this.data[this.cursor + 1] = pub.sub_on(this, this.cursor);
460
- this.cursor += 2;
461
- return pub;
462
- }
463
- track_off(sub) {
464
- $mol_wire_auto(sub);
465
- if (this.cursor < 0) {
466
- $mol_fail(new Error('End of non begun sub'));
467
- }
468
- for (let cursor = this.pub_from; cursor < this.cursor; cursor += 2) {
469
- const pub = this.data[cursor];
470
- pub.fresh();
471
- }
472
- this.cursor = $mol_wire_cursor.fresh;
473
- }
474
- pub_off(sub_pos) {
475
- this.data[sub_pos] = undefined;
476
- this.data[sub_pos + 1] = undefined;
477
- }
478
- destructor() {
479
- for (let cursor = this.data.length - 2; cursor >= this.sub_from; cursor -= 2) {
480
- const sub = this.data[cursor];
481
- const pos = this.data[cursor + 1];
482
- sub.pub_off(pos);
483
- this.data.pop();
484
- this.data.pop();
485
- }
486
- this.cursor = this.pub_from;
487
- this.track_cut();
488
- this.cursor = $mol_wire_cursor.final;
489
- }
490
- track_cut() {
491
- if (this.cursor < this.pub_from) {
492
- $mol_fail(new Error('Cut of non begun sub'));
493
- }
494
- let tail = 0;
495
- for (let cursor = this.cursor; cursor < this.sub_from; cursor += 2) {
496
- const pub = this.data[cursor];
497
- pub?.sub_off(this.data[cursor + 1]);
498
- if (this.sub_from < this.data.length) {
499
- this.peer_move(this.data.length - 2, cursor);
500
- this.data.pop();
501
- this.data.pop();
502
- }
503
- else {
504
- ++tail;
505
- }
506
- }
507
- for (; tail; --tail) {
508
- this.data.pop();
509
- this.data.pop();
510
- }
511
- this.sub_from = this.cursor;
512
- }
513
- complete() { }
514
- complete_pubs() {
515
- const limit = this.cursor < 0 ? this.sub_from : this.cursor;
516
- for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
517
- const pub = this.data[cursor];
518
- pub?.complete();
338
+ class $mol_error_mix extends Error {
339
+ errors;
340
+ constructor(message, ...errors) {
341
+ super(message);
342
+ this.errors = errors;
343
+ if (errors.length) {
344
+ const stacks = [...errors.map(error => error.stack), this.stack];
345
+ const diff = $mol_diff_path(...stacks.map(stack => {
346
+ if (!stack)
347
+ return [];
348
+ return stack.split('\n').reverse();
349
+ }));
350
+ const head = diff.prefix.reverse().join('\n');
351
+ const tails = diff.suffix.map(path => path.reverse().map(line => line.replace(/^(?!\s+at)/, '\tat (.) ')).join('\n')).join('\n\tat (.) -----\n');
352
+ this.stack = `Error: ${this.constructor.name}\n\tat (.) /"""\\\n${tails}\n\tat (.) \\___/\n${head}`;
353
+ this.message += errors.map(error => '\n' + error.message).join('');
519
354
  }
520
355
  }
521
- absorb(quant = $mol_wire_cursor.stale) {
522
- if (this.cursor === $mol_wire_cursor.final)
523
- return;
524
- if (this.cursor >= quant)
525
- return;
526
- this.cursor = quant;
527
- this.emit($mol_wire_cursor.doubt);
528
- }
529
- [$mol_dev_format_head]() {
530
- return $mol_dev_format_native(this);
531
- }
532
- get pub_empty() {
533
- return this.sub_from === this.pub_from;
356
+ toJSON() {
357
+ return this.message;
534
358
  }
535
359
  }
536
- $.$mol_wire_pub_sub = $mol_wire_pub_sub;
360
+ $.$mol_error_mix = $mol_error_mix;
537
361
  })($ || ($ = {}));
538
- //mol/wire/pub/sub/sub.ts
362
+ //mol/error/mix/mix.ts
539
363
  ;
540
364
  "use strict";
541
365
  var $;
542
366
  (function ($) {
543
- class $mol_after_frame extends $mol_object2 {
544
- task;
545
- static _promise = null;
546
- static get promise() {
547
- if (this._promise)
548
- return this._promise;
549
- return this._promise = new Promise(done => {
550
- const complete = () => {
551
- this._promise = null;
552
- done();
553
- };
554
- if (typeof requestAnimationFrame === 'function') {
555
- requestAnimationFrame(complete);
556
- }
557
- else {
558
- setTimeout(complete, 16);
559
- }
560
- });
561
- }
562
- cancelled = false;
563
- promise;
564
- constructor(task) {
565
- super();
566
- this.task = task;
567
- this.promise = $mol_after_frame.promise.then(() => {
568
- if (this.cancelled)
569
- return;
570
- task();
571
- });
572
- }
573
- destructor() {
574
- this.cancelled = true;
575
- }
367
+ class $mol_data_error extends $mol_error_mix {
576
368
  }
577
- $.$mol_after_frame = $mol_after_frame;
369
+ $.$mol_data_error = $mol_data_error;
578
370
  })($ || ($ = {}));
579
- //mol/after/frame/frame.web.ts
371
+ //mol/data/error/error.ts
580
372
  ;
581
373
  "use strict";
582
374
  var $;
583
375
  (function ($) {
584
- function $mol_promise_like(val) {
585
- return val && typeof val.then === 'function';
376
+ function $mol_data_enum(name, dict) {
377
+ const index = {};
378
+ for (let key in dict) {
379
+ if (Number.isNaN(Number(key))) {
380
+ index[dict[key]] = key;
381
+ }
382
+ }
383
+ return $mol_data_setup((value) => {
384
+ if (typeof index[value] !== 'string') {
385
+ return $mol_fail(new $mol_data_error(`${value} is not value of ${name} enum`));
386
+ }
387
+ return value;
388
+ }, { name, dict });
586
389
  }
587
- $.$mol_promise_like = $mol_promise_like;
390
+ $.$mol_data_enum = $mol_data_enum;
588
391
  })($ || ($ = {}));
589
- //mol/promise/like/like.ts
392
+ //mol/data/enum/enum.ts
590
393
  ;
591
394
  "use strict";
592
395
  var $;
593
396
  (function ($) {
594
- const handled = new WeakSet();
595
- class $mol_wire_fiber extends $mol_wire_pub_sub {
596
- task;
597
- host;
598
- static warm = true;
599
- static planning = new Set();
600
- static reaping = new Set();
601
- static plan_task = null;
602
- static plan() {
603
- if (this.plan_task)
604
- return;
605
- this.plan_task = new $mol_after_frame(() => {
606
- try {
607
- this.sync();
608
- }
609
- finally {
610
- $mol_wire_fiber.plan_task = null;
611
- }
612
- });
397
+ $.$mol_crypto_native = crypto;
398
+ })($ || ($ = {}));
399
+ //mol/crypto/native/native.web.ts
400
+ ;
401
+ "use strict";
402
+ var $;
403
+ (function ($) {
404
+ const algorithm = {
405
+ name: 'ECDSA',
406
+ hash: 'SHA-256',
407
+ namedCurve: "P-256",
408
+ };
409
+ async function $mol_crypto_auditor_pair() {
410
+ const pair = await $mol_crypto_native.subtle.generateKey(algorithm, true, ['sign', 'verify']);
411
+ return {
412
+ public: new $mol_crypto_auditor_public(pair.publicKey),
413
+ private: new $mol_crypto_auditor_private(pair.privateKey),
414
+ };
415
+ }
416
+ $.$mol_crypto_auditor_pair = $mol_crypto_auditor_pair;
417
+ class $mol_crypto_auditor_public extends Object {
418
+ native;
419
+ static size = 86;
420
+ constructor(native) {
421
+ super();
422
+ this.native = native;
613
423
  }
614
- static sync() {
615
- while (this.planning.size) {
616
- for (const fiber of this.planning) {
617
- this.planning.delete(fiber);
618
- if (fiber.cursor >= 0)
619
- continue;
620
- if (fiber.cursor === $mol_wire_cursor.final)
621
- continue;
622
- fiber.fresh();
623
- }
624
- }
625
- while (this.reaping.size) {
626
- const fibers = this.reaping;
627
- this.reaping = new Set;
628
- for (const fiber of fibers) {
629
- if (!fiber.sub_empty)
630
- continue;
631
- fiber.destructor();
632
- }
633
- }
634
- }
635
- [Symbol.toStringTag];
636
- cache = undefined;
637
- get args() {
638
- return this.data.slice(0, this.pub_from);
424
+ static async from(serial) {
425
+ return new this(await $mol_crypto_native.subtle.importKey('jwk', {
426
+ crv: "P-256",
427
+ ext: true,
428
+ key_ops: ['verify'],
429
+ kty: "EC",
430
+ x: serial.slice(0, 43),
431
+ y: serial.slice(43, 86),
432
+ }, algorithm, true, ['verify']));
639
433
  }
640
- result() {
641
- if ($mol_promise_like(this.cache))
642
- return;
643
- if (this.cache instanceof Error)
644
- return;
645
- return this.cache;
434
+ async serial() {
435
+ const { x, y } = await $mol_crypto_native.subtle.exportKey('jwk', this.native);
436
+ return x + y;
646
437
  }
647
- field() {
648
- return this.task.name + '()';
438
+ async verify(data, sign) {
439
+ return await $mol_crypto_native.subtle.verify(algorithm, this.native, sign, data);
649
440
  }
650
- constructor(id, task, host, args) {
441
+ }
442
+ $.$mol_crypto_auditor_public = $mol_crypto_auditor_public;
443
+ class $mol_crypto_auditor_private extends Object {
444
+ native;
445
+ static size = 129;
446
+ constructor(native) {
651
447
  super();
652
- this.task = task;
653
- this.host = host;
654
- if (args)
655
- this.data.push(...args);
656
- this.pub_from = this.sub_from = args?.length ?? 0;
657
- this[Symbol.toStringTag] = id;
658
- }
659
- plan() {
660
- $mol_wire_fiber.planning.add(this);
661
- $mol_wire_fiber.plan();
662
- }
663
- reap() {
664
- $mol_wire_fiber.reaping.add(this);
665
- $mol_wire_fiber.plan();
666
- }
667
- toString() {
668
- return this[Symbol.toStringTag];
669
- }
670
- toJSON() {
671
- return this[Symbol.toStringTag];
448
+ this.native = native;
672
449
  }
673
- [$mol_dev_format_head]() {
674
- const cursor = {
675
- [$mol_wire_cursor.stale]: '🔴',
676
- [$mol_wire_cursor.doubt]: '🟡',
677
- [$mol_wire_cursor.fresh]: '🟢',
678
- [$mol_wire_cursor.final]: '🔵',
679
- }[this.cursor] ?? this.cursor.toString();
680
- return $mol_dev_format_div({}, $mol_dev_format_native(this), $mol_dev_format_shade(cursor + ' '), $mol_dev_format_auto(this.cache));
450
+ static async from(serial) {
451
+ return new this(await $mol_crypto_native.subtle.importKey('jwk', {
452
+ crv: "P-256",
453
+ ext: true,
454
+ key_ops: ['sign'],
455
+ kty: "EC",
456
+ x: serial.slice(0, 43),
457
+ y: serial.slice(43, 86),
458
+ d: serial.slice(86, 129),
459
+ }, algorithm, true, ['sign']));
681
460
  }
682
- get $() {
683
- return (this.host ?? this.task)['$'];
461
+ async serial() {
462
+ const { x, y, d } = await $mol_crypto_native.subtle.exportKey('jwk', this.native);
463
+ return x + y + d;
684
464
  }
685
- emit(quant = $mol_wire_cursor.stale) {
686
- if (this.sub_empty)
687
- this.plan();
688
- else
689
- super.emit(quant);
465
+ async sign(data) {
466
+ return await $mol_crypto_native.subtle.sign(algorithm, this.native, data);
690
467
  }
691
- fresh() {
692
- if (this.cursor === $mol_wire_cursor.fresh)
693
- return;
694
- if (this.cursor === $mol_wire_cursor.final)
695
- return;
696
- check: if (this.cursor === $mol_wire_cursor.doubt) {
697
- for (let i = this.pub_from; i < this.sub_from; i += 2) {
698
- ;
699
- this.data[i]?.fresh();
700
- if (this.cursor !== $mol_wire_cursor.doubt)
701
- break check;
702
- }
703
- this.cursor = $mol_wire_cursor.fresh;
704
- return;
705
- }
706
- const bu = this.track_on();
707
- let result;
708
- try {
709
- switch (this.pub_from) {
710
- case 0:
711
- result = this.task.call(this.host);
712
- break;
713
- case 1:
714
- result = this.task.call(this.host, this.data[0]);
715
- break;
716
- default:
717
- result = this.task.call(this.host, ...this.args);
718
- break;
719
- }
720
- if ($mol_promise_like(result)) {
721
- const put = (res) => {
722
- if (this.cache === result)
723
- this.put(res);
724
- return res;
725
- };
726
- result = Object.assign(result.then(put, put), {
727
- destructor: result['destructor'] ?? (() => { })
728
- });
729
- handled.add(result);
730
- }
731
- }
732
- catch (error) {
733
- if (error instanceof Error || $mol_promise_like(error)) {
734
- result = error;
735
- }
736
- else {
737
- result = new Error(String(error), { cause: error });
738
- }
739
- if ($mol_promise_like(result) && !handled.has(result)) {
740
- result = Object.assign(result.finally(() => {
741
- if (this.cache === result)
742
- this.absorb();
743
- }), {
744
- destructor: result['destructor'] ?? (() => { })
745
- });
746
- handled.add(result);
747
- }
748
- }
749
- if (!$mol_promise_like(result)) {
750
- this.track_cut();
751
- }
752
- this.track_off(bu);
753
- this.put(result);
468
+ async public() {
469
+ return await $mol_crypto_auditor_public.from($mol_crypto_auditor_private_to_public(await this.serial()));
754
470
  }
755
- refresh() {
756
- this.cursor = $mol_wire_cursor.stale;
757
- this.fresh();
471
+ }
472
+ $.$mol_crypto_auditor_private = $mol_crypto_auditor_private;
473
+ $.$mol_crypto_auditor_sign_size = 64;
474
+ function $mol_crypto_auditor_private_to_public(serial) {
475
+ return serial.slice(0, 86);
476
+ }
477
+ $.$mol_crypto_auditor_private_to_public = $mol_crypto_auditor_private_to_public;
478
+ })($ || ($ = {}));
479
+ //mol/crypto/auditor/auditor.ts
480
+ ;
481
+ "use strict";
482
+ var $;
483
+ (function ($) {
484
+ let $hyoo_crowd_peer_level;
485
+ (function ($hyoo_crowd_peer_level) {
486
+ $hyoo_crowd_peer_level[$hyoo_crowd_peer_level["get"] = 0] = "get";
487
+ $hyoo_crowd_peer_level[$hyoo_crowd_peer_level["add"] = 1] = "add";
488
+ $hyoo_crowd_peer_level[$hyoo_crowd_peer_level["mod"] = 2] = "mod";
489
+ $hyoo_crowd_peer_level[$hyoo_crowd_peer_level["law"] = 3] = "law";
490
+ })($hyoo_crowd_peer_level = $.$hyoo_crowd_peer_level || ($.$hyoo_crowd_peer_level = {}));
491
+ class $hyoo_crowd_peer extends Object {
492
+ key_public;
493
+ key_public_serial;
494
+ key_private;
495
+ key_private_serial;
496
+ id;
497
+ constructor(key_public, key_public_serial, key_private, key_private_serial) {
498
+ super();
499
+ this.key_public = key_public;
500
+ this.key_public_serial = key_public_serial;
501
+ this.key_private = key_private;
502
+ this.key_private_serial = key_private_serial;
503
+ this.id = $mol_int62_hash_string(this.key_public_serial);
758
504
  }
759
- sync() {
760
- if (!$mol_wire_fiber.warm) {
761
- return this.result();
762
- }
763
- this.promote();
764
- this.fresh();
765
- if (this.cache instanceof Error) {
766
- return $mol_fail_hidden(this.cache);
767
- }
768
- if ($mol_promise_like(this.cache)) {
769
- return $mol_fail_hidden(this.cache);
770
- }
771
- return this.cache;
505
+ static async generate() {
506
+ const pair = await $$.$mol_crypto_auditor_pair();
507
+ const serial = await pair.private.serial();
508
+ return new this(pair.public, $mol_crypto_auditor_private_to_public(serial), pair.private, serial);
772
509
  }
773
- async async() {
774
- while (true) {
775
- this.fresh();
776
- if (this.cache instanceof Error) {
777
- $mol_fail_hidden(this.cache);
778
- }
779
- if (!$mol_promise_like(this.cache))
780
- return this.cache;
781
- await this.cache;
782
- if (this.cursor === $mol_wire_cursor.final) {
783
- await new Promise(() => { });
784
- }
785
- }
510
+ static async restore(serial) {
511
+ return new this(await $$.$mol_crypto_auditor_public.from(serial), $mol_crypto_auditor_private_to_public(serial), await $$.$mol_crypto_auditor_private.from(serial), serial);
786
512
  }
787
513
  }
788
- $.$mol_wire_fiber = $mol_wire_fiber;
514
+ $.$hyoo_crowd_peer = $hyoo_crowd_peer;
789
515
  })($ || ($ = {}));
790
- //mol/wire/fiber/fiber.ts
516
+ //hyoo/crowd/peer/peer.ts
791
517
  ;
792
518
  "use strict";
793
519
  var $;
794
520
  (function ($) {
795
- const named = new WeakSet();
796
- function $mol_func_name(func) {
797
- let name = func.name;
798
- if (name?.length > 1)
799
- return name;
800
- if (named.has(func))
801
- return name;
802
- for (let key in this) {
803
- try {
804
- if (this[key] !== func)
805
- continue;
806
- name = key;
807
- Object.defineProperty(func, 'name', { value: name });
808
- break;
809
- }
810
- catch { }
811
- }
812
- named.add(func);
813
- return name;
521
+ $['devtoolsFormatters'] ||= [];
522
+ function $mol_dev_format_register(config) {
523
+ $['devtoolsFormatters'].push(config);
814
524
  }
815
- $.$mol_func_name = $mol_func_name;
816
- function $mol_func_name_from(target, source) {
817
- Object.defineProperty(target, 'name', { value: source.name });
818
- return target;
525
+ $.$mol_dev_format_register = $mol_dev_format_register;
526
+ $.$mol_dev_format_head = Symbol('$mol_dev_format_head');
527
+ $.$mol_dev_format_body = Symbol('$mol_dev_format_body');
528
+ $mol_dev_format_register({
529
+ header: (val, config = false) => {
530
+ if (config)
531
+ return null;
532
+ if (!val)
533
+ return null;
534
+ if ($.$mol_dev_format_head in val) {
535
+ return val[$.$mol_dev_format_head]();
536
+ }
537
+ if (typeof val === 'function') {
538
+ return $mol_dev_format_native(val);
539
+ }
540
+ return null;
541
+ },
542
+ hasBody: val => val[$.$mol_dev_format_body],
543
+ body: val => val[$.$mol_dev_format_body](),
544
+ });
545
+ function $mol_dev_format_native(obj) {
546
+ if (typeof obj === 'undefined')
547
+ return $.$mol_dev_format_shade('undefined');
548
+ if (typeof obj !== 'object' && typeof obj !== 'function')
549
+ return obj;
550
+ return [
551
+ 'object',
552
+ {
553
+ object: obj,
554
+ config: true,
555
+ },
556
+ ];
819
557
  }
820
- $.$mol_func_name_from = $mol_func_name_from;
821
- })($ || ($ = {}));
822
- //mol/func/name/name.ts
823
- ;
824
- "use strict";
825
- var $;
826
- (function ($) {
827
- function $mol_guid(length = 8, exists = () => false) {
828
- for (;;) {
829
- let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
830
- if (exists(id))
831
- continue;
832
- return id;
558
+ $.$mol_dev_format_native = $mol_dev_format_native;
559
+ function $mol_dev_format_auto(obj) {
560
+ if (obj == null)
561
+ return $.$mol_dev_format_shade(String(obj));
562
+ if (typeof obj === 'object' && $.$mol_dev_format_head in obj) {
563
+ return obj[$.$mol_dev_format_head]();
833
564
  }
565
+ return [
566
+ 'object',
567
+ {
568
+ object: obj,
569
+ config: false,
570
+ },
571
+ ];
834
572
  }
835
- $.$mol_guid = $mol_guid;
573
+ $.$mol_dev_format_auto = $mol_dev_format_auto;
574
+ function $mol_dev_format_element(element, style, ...content) {
575
+ const styles = [];
576
+ for (let key in style)
577
+ styles.push(`${key} : ${style[key]}`);
578
+ return [
579
+ element,
580
+ {
581
+ style: styles.join(' ; '),
582
+ },
583
+ ...content,
584
+ ];
585
+ }
586
+ $.$mol_dev_format_element = $mol_dev_format_element;
587
+ function $mol_dev_format_span(style, ...content) {
588
+ return $mol_dev_format_element('span', {
589
+ 'vertical-align': '8%',
590
+ ...style,
591
+ }, ...content);
592
+ }
593
+ $.$mol_dev_format_span = $mol_dev_format_span;
594
+ $.$mol_dev_format_div = $mol_dev_format_element.bind(null, 'div');
595
+ $.$mol_dev_format_ol = $mol_dev_format_element.bind(null, 'ol');
596
+ $.$mol_dev_format_li = $mol_dev_format_element.bind(null, 'li');
597
+ $.$mol_dev_format_table = $mol_dev_format_element.bind(null, 'table');
598
+ $.$mol_dev_format_tr = $mol_dev_format_element.bind(null, 'tr');
599
+ $.$mol_dev_format_td = $mol_dev_format_element.bind(null, 'td');
600
+ $.$mol_dev_format_accent = $mol_dev_format_span.bind(null, {
601
+ 'color': 'magenta',
602
+ });
603
+ $.$mol_dev_format_strong = $mol_dev_format_span.bind(null, {
604
+ 'font-weight': 'bold',
605
+ });
606
+ $.$mol_dev_format_string = $mol_dev_format_span.bind(null, {
607
+ 'color': 'green',
608
+ });
609
+ $.$mol_dev_format_shade = $mol_dev_format_span.bind(null, {
610
+ 'color': 'gray',
611
+ });
612
+ $.$mol_dev_format_indent = $.$mol_dev_format_div.bind(null, {
613
+ 'margin-left': '13px'
614
+ });
836
615
  })($ || ($ = {}));
837
- //mol/guid/guid.ts
616
+ //mol/dev/format/format.ts
617
+ ;
618
+ "use strict";
619
+ //mol/charset/encoding/encoding.ts
838
620
  ;
839
621
  "use strict";
840
622
  var $;
841
623
  (function ($) {
842
- $.$mol_key_store = new WeakMap();
843
- function $mol_key(value) {
844
- if (!value)
845
- return JSON.stringify(value);
846
- if (typeof value !== 'object' && typeof value !== 'function')
847
- return JSON.stringify(value);
848
- return JSON.stringify(value, (field, value) => {
849
- if (!value)
850
- return value;
851
- if (typeof value !== 'object' && typeof value !== 'function')
852
- return value;
853
- if (Array.isArray(value))
854
- return value;
855
- const proto = Reflect.getPrototypeOf(value);
856
- if (!proto)
857
- return value;
858
- if (Reflect.getPrototypeOf(proto) === null)
859
- return value;
860
- if ('toJSON' in value)
861
- return value;
862
- if (value instanceof RegExp)
863
- return value.toString();
864
- let key = $.$mol_key_store.get(value);
865
- if (key)
866
- return key;
867
- key = $mol_guid();
868
- $.$mol_key_store.set(value, key);
869
- return key;
870
- });
624
+ const decoders = {};
625
+ function $mol_charset_decode(buffer, encoding = 'utf8') {
626
+ let decoder = decoders[encoding];
627
+ if (!decoder)
628
+ decoder = decoders[encoding] = new TextDecoder(encoding);
629
+ return decoder.decode(buffer);
871
630
  }
872
- $.$mol_key = $mol_key;
631
+ $.$mol_charset_decode = $mol_charset_decode;
873
632
  })($ || ($ = {}));
874
- //mol/key/key.ts
633
+ //mol/charset/decode/decode.ts
875
634
  ;
876
635
  "use strict";
877
636
  var $;
878
637
  (function ($) {
879
- $.$mol_compare_deep_cache = new WeakMap();
880
- function $mol_compare_deep(left, right) {
881
- if (Object.is(left, right))
882
- return true;
883
- if (left === null)
884
- return false;
885
- if (right === null)
886
- return false;
887
- if (typeof left !== 'object')
888
- return false;
889
- if (typeof right !== 'object')
890
- return false;
891
- const left_proto = Reflect.getPrototypeOf(left);
892
- const right_proto = Reflect.getPrototypeOf(right);
893
- if (left_proto !== right_proto)
894
- return false;
895
- if (left instanceof Boolean)
896
- return Object.is(left.valueOf(), right['valueOf']());
897
- if (left instanceof Number)
898
- return Object.is(left.valueOf(), right['valueOf']());
899
- if (left instanceof String)
900
- return Object.is(left.valueOf(), right['valueOf']());
901
- if (left instanceof Date)
902
- return Object.is(left.valueOf(), right['valueOf']());
903
- if (left instanceof RegExp)
904
- return left.source === right.source && left.flags === right.flags;
905
- if (left instanceof Error)
906
- return left.message === right.message && left.stack === right.stack;
907
- let left_cache = $.$mol_compare_deep_cache.get(left);
908
- if (left_cache) {
909
- const right_cache = left_cache.get(right);
910
- if (typeof right_cache === 'boolean')
911
- return right_cache;
912
- }
913
- else {
914
- left_cache = new WeakMap([[right, true]]);
915
- $.$mol_compare_deep_cache.set(left, left_cache);
638
+ const level = $mol_data_enum('level', $hyoo_crowd_peer_level);
639
+ let $hyoo_crowd_unit_kind;
640
+ (function ($hyoo_crowd_unit_kind) {
641
+ $hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["grab"] = 0] = "grab";
642
+ $hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["join"] = 1] = "join";
643
+ $hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["give"] = 2] = "give";
644
+ $hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["data"] = 3] = "data";
645
+ })($hyoo_crowd_unit_kind = $.$hyoo_crowd_unit_kind || ($.$hyoo_crowd_unit_kind = {}));
646
+ let $hyoo_crowd_unit_group;
647
+ (function ($hyoo_crowd_unit_group) {
648
+ $hyoo_crowd_unit_group[$hyoo_crowd_unit_group["auth"] = 0] = "auth";
649
+ $hyoo_crowd_unit_group[$hyoo_crowd_unit_group["data"] = 1] = "data";
650
+ })($hyoo_crowd_unit_group = $.$hyoo_crowd_unit_group || ($.$hyoo_crowd_unit_group = {}));
651
+ class $hyoo_crowd_unit extends Object {
652
+ land;
653
+ auth;
654
+ head;
655
+ self;
656
+ next;
657
+ prev;
658
+ time;
659
+ data;
660
+ bin;
661
+ constructor(land, auth, head, self, next, prev, time, data, bin) {
662
+ super();
663
+ this.land = land;
664
+ this.auth = auth;
665
+ this.head = head;
666
+ this.self = self;
667
+ this.next = next;
668
+ this.prev = prev;
669
+ this.time = time;
670
+ this.data = data;
671
+ this.bin = bin;
916
672
  }
917
- let result;
918
- try {
919
- if (!left_proto)
920
- result = compare_pojo(left, right);
921
- else if (!Reflect.getPrototypeOf(left_proto))
922
- result = compare_pojo(left, right);
923
- else if (Array.isArray(left))
924
- result = compare_array(left, right);
925
- else if (left instanceof Set)
926
- result = compare_set(left, right);
927
- else if (left instanceof Map)
928
- result = compare_map(left, right);
929
- else if (ArrayBuffer.isView(left))
930
- result = compare_buffer(left, right);
931
- else if (Symbol.toPrimitive in left)
932
- result = compare_primitive(left, right);
933
- else
934
- result = false;
673
+ kind() {
674
+ if (this.head === this.self && this.auth === this.self) {
675
+ if (this.head === this.land) {
676
+ return $hyoo_crowd_unit_kind.grab;
677
+ }
678
+ else {
679
+ return $hyoo_crowd_unit_kind.join;
680
+ }
681
+ }
682
+ if (this.head === this.land) {
683
+ return $hyoo_crowd_unit_kind.give;
684
+ }
685
+ return $hyoo_crowd_unit_kind.data;
935
686
  }
936
- finally {
937
- left_cache.set(right, result);
687
+ group() {
688
+ return this.kind() === $hyoo_crowd_unit_kind.data
689
+ ? $hyoo_crowd_unit_group.data
690
+ : $hyoo_crowd_unit_group.auth;
938
691
  }
939
- return result;
940
- }
941
- $.$mol_compare_deep = $mol_compare_deep;
942
- function compare_array(left, right) {
943
- const len = left.length;
944
- if (len !== right.length)
945
- return false;
946
- for (let i = 0; i < len; ++i) {
947
- if (!$mol_compare_deep(left[i], right[i]))
948
- return false;
692
+ level() {
693
+ switch (this.kind()) {
694
+ case $hyoo_crowd_unit_kind.grab: return $hyoo_crowd_peer_level.law;
695
+ case $hyoo_crowd_unit_kind.give: return level(this.data);
696
+ default: $mol_fail(new Error(`Wrong unit kind for getting level: ${this.kind()}`));
697
+ }
949
698
  }
950
- return true;
951
- }
952
- function compare_buffer(left, right) {
953
- const len = left.byteLength;
954
- if (len !== right.byteLength)
955
- return false;
956
- for (let i = 0; i < len; ++i) {
957
- if (left[i] !== right[i])
958
- return false;
699
+ [Symbol.toPrimitive]() {
700
+ return JSON.stringify(this);
959
701
  }
960
- return true;
961
- }
962
- function compare_iterator(left, right) {
963
- while (true) {
964
- const left_next = left.next();
965
- const right_next = right.next();
966
- if (left_next.done !== right_next.done)
967
- return false;
968
- if (left_next.done)
969
- break;
970
- if (!$mol_compare_deep(left_next.value, right_next.value))
971
- return false;
702
+ [$mol_dev_format_head]() {
703
+ switch (this.kind()) {
704
+ case $hyoo_crowd_unit_kind.grab:
705
+ return $mol_dev_format_div({}, $mol_dev_format_native(this), ' 👑');
706
+ case $hyoo_crowd_unit_kind.join:
707
+ return $mol_dev_format_div({}, $mol_dev_format_native(this), $mol_dev_format_shade(' 🔑 ', this.self));
708
+ case $hyoo_crowd_unit_kind.give:
709
+ return $mol_dev_format_div({}, $mol_dev_format_native(this), $mol_dev_format_shade(' 🏅 ', this.self, ' '), $mol_dev_format_native($hyoo_crowd_peer_level[this.data] ?? this.data));
710
+ case $hyoo_crowd_unit_kind.data:
711
+ return $mol_dev_format_div({}, $mol_dev_format_native(this), $mol_dev_format_shade(' 📦 ', this.head, '!', this.self, ' '), $mol_dev_format_native(this.data));
712
+ }
972
713
  }
973
- return true;
974
- }
975
- function compare_set(left, right) {
976
- if (left.size !== right.size)
977
- return false;
978
- return compare_iterator(left.values(), right.values());
979
- }
980
- function compare_map(left, right) {
981
- if (left.size !== right.size)
982
- return false;
983
- return compare_iterator(left.keys(), right.keys())
984
- && compare_iterator(left.values(), right.values());
985
714
  }
986
- function compare_pojo(left, right) {
987
- const left_keys = Object.getOwnPropertyNames(left);
988
- const right_keys = Object.getOwnPropertyNames(right);
989
- if (!compare_array(left_keys, right_keys))
990
- return false;
991
- for (let key of left_keys) {
992
- if (!$mol_compare_deep(left[key], right[key]))
993
- return false;
715
+ $.$hyoo_crowd_unit = $hyoo_crowd_unit;
716
+ const offset = {
717
+ land_lo: 0,
718
+ land_hi: 4,
719
+ auth_lo: 8,
720
+ auth_hi: 12,
721
+ head_lo: 16,
722
+ head_hi: 20,
723
+ self_lo: 24,
724
+ self_hi: 28,
725
+ next_lo: 32,
726
+ next_hi: 36,
727
+ prev_lo: 40,
728
+ prev_hi: 44,
729
+ time: 48,
730
+ size: 54,
731
+ data: 56,
732
+ };
733
+ class $hyoo_crowd_unit_bin extends DataView {
734
+ static from_buffer(buffer) {
735
+ const size = Math.ceil(Math.abs(buffer[offset.size / 2]) / 8) * 8 + offset.data + $mol_crypto_auditor_sign_size;
736
+ return new this(buffer.slice(0, size / 2).buffer);
994
737
  }
995
- const left_syms = Object.getOwnPropertySymbols(left);
996
- const right_syms = Object.getOwnPropertySymbols(right);
997
- if (!compare_array(left_syms, right_syms))
998
- return false;
999
- for (let key of left_syms) {
1000
- if (!$mol_compare_deep(left[key], right[key]))
1001
- return false;
738
+ static from_unit(unit) {
739
+ if (unit.bin)
740
+ return unit.bin;
741
+ const type = unit.data === null
742
+ ? 0
743
+ : unit.data instanceof Uint8Array
744
+ ? -1
745
+ : 1;
746
+ const buff = type === 0 ? null
747
+ : type > 0 ? $mol_charset_encode(JSON.stringify(unit.data))
748
+ : unit.data;
749
+ const size = buff?.byteLength ?? 0;
750
+ if (type > 0 && size > 2 ** 15 - 1)
751
+ throw new Error(`Too large json data: ${size} > ${2 ** 15 - 1}`);
752
+ if (type < 0 && size > 2 ** 15)
753
+ throw new Error(`Too large binary data: ${size} > ${2 ** 15}`);
754
+ const total = offset.data + Math.ceil(size / 8) * 8 + $mol_crypto_auditor_sign_size;
755
+ const mem = new Uint8Array(total);
756
+ const bin = new $hyoo_crowd_unit_bin(mem.buffer);
757
+ const land = $mol_int62_from_string(unit.land);
758
+ bin.setInt32(offset.land_lo, land.lo, true);
759
+ bin.setInt32(offset.land_hi, land.hi, true);
760
+ const auth = $mol_int62_from_string(unit.auth);
761
+ bin.setInt32(offset.auth_lo, auth.lo, true);
762
+ bin.setInt32(offset.auth_hi, auth.hi, true);
763
+ const head = $mol_int62_from_string(unit.head);
764
+ bin.setInt32(offset.head_lo, head.lo, true);
765
+ bin.setInt32(offset.head_hi, head.hi, true);
766
+ const self = $mol_int62_from_string(unit.self);
767
+ bin.setInt32(offset.self_lo, self.lo, true);
768
+ bin.setInt32(offset.self_hi, self.hi, true);
769
+ const next = $mol_int62_from_string(unit.next);
770
+ bin.setInt32(offset.next_lo, next.lo, true);
771
+ bin.setInt32(offset.next_hi, next.hi, true);
772
+ const prev = $mol_int62_from_string(unit.prev);
773
+ bin.setInt32(offset.prev_lo, prev.lo, true);
774
+ bin.setInt32(offset.prev_hi, prev.hi, true);
775
+ bin.setInt32(offset.time, unit.time, true);
776
+ bin.setInt16(offset.size, type * size, true);
777
+ if (buff)
778
+ mem.set(buff, offset.data);
779
+ return bin;
1002
780
  }
1003
- return true;
1004
- }
1005
- function compare_primitive(left, right) {
1006
- return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
1007
- }
1008
- })($ || ($ = {}));
1009
- //mol/compare/deep/deep.ts
1010
- ;
1011
- "use strict";
1012
- var $;
1013
- (function ($) {
1014
- class $mol_wire_task extends $mol_wire_fiber {
1015
- static getter(task) {
1016
- return function $mol_wire_task_get(host, args) {
1017
- const sub = $mol_wire_auto();
1018
- const existen = sub?.track_next();
1019
- reuse: if (existen) {
1020
- if (!existen.temp)
1021
- break reuse;
1022
- if (existen.host !== host)
1023
- break reuse;
1024
- if (existen.task !== task)
1025
- break reuse;
1026
- if (!$mol_compare_deep(existen.args, args))
1027
- break reuse;
1028
- return existen;
1029
- }
1030
- return new $mol_wire_task(`${host?.[Symbol.toStringTag] ?? host}.${task.name}(#)`, task, host, args);
1031
- };
781
+ sign(next) {
782
+ const sign_offset = this.byteOffset + this.byteLength - $mol_crypto_auditor_sign_size;
783
+ const buff = new Uint8Array(this.buffer, sign_offset, $mol_crypto_auditor_sign_size);
784
+ if (!next)
785
+ return buff;
786
+ buff.set(next);
787
+ return buff;
1032
788
  }
1033
- get temp() {
1034
- return true;
789
+ size() {
790
+ return Math.ceil(Math.abs(this.getInt16(offset.size, true)) / 8) * 8 + offset.data + $mol_crypto_auditor_sign_size;
1035
791
  }
1036
- complete() {
1037
- if ($mol_promise_like(this.cache))
1038
- return;
1039
- this.destructor();
792
+ sens() {
793
+ return new Uint8Array(this.buffer, this.byteOffset, this.size() - $mol_crypto_auditor_sign_size);
1040
794
  }
1041
- put(next) {
1042
- const prev = this.cache;
1043
- this.cache = next;
1044
- if ($mol_promise_like(next)) {
1045
- this.cursor = $mol_wire_cursor.fresh;
1046
- if (next !== prev)
1047
- this.emit();
1048
- return next;
795
+ unit() {
796
+ const land = $mol_int62_to_string({
797
+ lo: this.getInt32(offset.land_lo, true) << 1 >> 1,
798
+ hi: this.getInt32(offset.land_hi, true) << 1 >> 1,
799
+ });
800
+ const auth = $mol_int62_to_string({
801
+ lo: this.getInt32(offset.auth_lo, true) << 1 >> 1,
802
+ hi: this.getInt32(offset.auth_hi, true) << 1 >> 1,
803
+ });
804
+ const head = $mol_int62_to_string({
805
+ lo: this.getInt32(offset.head_lo, true) << 1 >> 1,
806
+ hi: this.getInt32(offset.head_hi, true) << 1 >> 1,
807
+ });
808
+ const self = $mol_int62_to_string({
809
+ lo: this.getInt32(offset.self_lo, true) << 1 >> 1,
810
+ hi: this.getInt32(offset.self_hi, true) << 1 >> 1,
811
+ });
812
+ const next = $mol_int62_to_string({
813
+ lo: this.getInt32(offset.next_lo, true) << 1 >> 1,
814
+ hi: this.getInt32(offset.next_hi, true) << 1 >> 1,
815
+ });
816
+ const prev = $mol_int62_to_string({
817
+ lo: this.getInt32(offset.prev_lo, true) << 1 >> 1,
818
+ hi: this.getInt32(offset.prev_hi, true) << 1 >> 1,
819
+ });
820
+ const time = this.getInt32(offset.time, true) << 1 >> 1;
821
+ const type_size = this.getInt16(offset.size, true);
822
+ let data = null;
823
+ if (type_size) {
824
+ try {
825
+ var buff = new Uint8Array(this.buffer, this.byteOffset + offset.data, Math.abs(type_size));
826
+ }
827
+ catch (error) {
828
+ error['message'] += `\nhead=${head};self=${self}`;
829
+ $mol_fail_hidden(error);
830
+ }
831
+ if (type_size < 0)
832
+ data = buff;
833
+ else
834
+ data = JSON.parse($mol_charset_decode(buff));
1049
835
  }
1050
- this.cursor = $mol_wire_cursor.final;
1051
- if (this.sub_empty)
1052
- this.destructor();
1053
- else if (next !== prev)
1054
- this.emit();
1055
- return next;
836
+ return new $hyoo_crowd_unit(land, auth, head, self, next, prev, time, data, this);
1056
837
  }
1057
838
  }
1058
- $.$mol_wire_task = $mol_wire_task;
1059
- })($ || ($ = {}));
1060
- //mol/wire/task/task.ts
1061
- ;
1062
- "use strict";
1063
- var $;
1064
- (function ($) {
1065
- function $mol_wire_method(host, field, descr) {
1066
- if (!descr)
1067
- descr = Reflect.getOwnPropertyDescriptor(host, field);
1068
- const orig = descr?.value ?? host[field];
1069
- const sup = Reflect.getPrototypeOf(host);
1070
- if (typeof sup[field] === 'function') {
1071
- Object.defineProperty(orig, 'name', { value: sup[field].name });
1072
- }
1073
- const temp = $mol_wire_task.getter(orig);
1074
- const value = function (...args) {
1075
- const fiber = temp(this ?? null, args);
1076
- return fiber.sync();
1077
- };
1078
- Object.defineProperty(value, 'name', { value: orig.name + ' ' });
1079
- Object.assign(value, { orig });
1080
- const descr2 = { ...descr, value };
1081
- Reflect.defineProperty(host, field, descr2);
1082
- return descr2;
1083
- }
1084
- $.$mol_wire_method = $mol_wire_method;
1085
- })($ || ($ = {}));
1086
- //mol/wire/method/method.ts
1087
- ;
1088
- "use strict";
1089
- //mol/type/tail/tail.ts
1090
- ;
1091
- "use strict";
1092
- //mol/type/foot/foot.ts
1093
- ;
1094
- "use strict";
1095
- var $;
1096
- (function ($) {
1097
- const catched = new WeakMap();
1098
- function $mol_fail_catch(error) {
1099
- if (typeof error !== 'object')
1100
- return false;
1101
- if ($mol_promise_like(error))
1102
- $mol_fail_hidden(error);
1103
- if (catched.get(error))
1104
- return false;
1105
- catched.set(error, true);
1106
- return true;
1107
- }
1108
- $.$mol_fail_catch = $mol_fail_catch;
1109
- })($ || ($ = {}));
1110
- //mol/fail/catch/catch.ts
1111
- ;
1112
- "use strict";
1113
- var $;
1114
- (function ($) {
1115
- function $mol_fail_log(error) {
1116
- if ($mol_promise_like(error))
1117
- return false;
1118
- if (!$mol_fail_catch(error))
1119
- return false;
1120
- console.error(error);
1121
- return true;
1122
- }
1123
- $.$mol_fail_log = $mol_fail_log;
1124
- })($ || ($ = {}));
1125
- //mol/fail/log/log.ts
1126
- ;
1127
- "use strict";
1128
- var $;
1129
- (function ($) {
1130
- class $mol_wire_atom extends $mol_wire_fiber {
1131
- static solo(host, task) {
1132
- const field = task.name + '()';
1133
- const existen = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
1134
- if (existen)
1135
- return existen;
1136
- const prefix = host?.[Symbol.toStringTag] ?? (host instanceof Function ? $$.$mol_func_name(host) : host);
1137
- const key = `${prefix}.${field}`;
1138
- const fiber = new $mol_wire_atom(key, task, host, []);
1139
- (host ?? task)[field] = fiber;
1140
- return fiber;
1141
- }
1142
- static plex(host, task, key) {
1143
- const field = task.name + '()';
1144
- let dict = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
1145
- const prefix = host?.[Symbol.toStringTag] ?? (host instanceof Function ? $$.$mol_func_name(host) : host);
1146
- const id = `${prefix}.${task.name}(${$mol_key(key)})`;
1147
- if (dict) {
1148
- const existen = dict.get(id);
1149
- if (existen)
1150
- return existen;
1151
- }
1152
- else {
1153
- dict = (host ?? task)[field] = new Map();
1154
- }
1155
- const fiber = new $mol_wire_atom(id, task, host, [key]);
1156
- dict.set(id, fiber);
1157
- return fiber;
1158
- }
1159
- static watching = new Set();
1160
- static watcher = null;
1161
- static watch() {
1162
- $mol_wire_atom.watcher = new $mol_after_frame($mol_wire_atom.watch);
1163
- for (const atom of $mol_wire_atom.watching) {
1164
- if (atom.cursor === $mol_wire_cursor.final) {
1165
- $mol_wire_atom.watching.delete(atom);
1166
- }
1167
- else {
1168
- atom.cursor = $mol_wire_cursor.stale;
1169
- atom.fresh();
1170
- }
1171
- }
1172
- }
1173
- watch() {
1174
- if (!$mol_wire_atom.watcher) {
1175
- $mol_wire_atom.watcher = new $mol_after_frame($mol_wire_atom.watch);
1176
- }
1177
- $mol_wire_atom.watching.add(this);
1178
- }
1179
- resync(args) {
1180
- return this.put(this.task.call(this.host, ...args));
1181
- }
1182
- once() {
1183
- return this.sync();
1184
- }
1185
- channel() {
1186
- return Object.assign((next) => {
1187
- if (next !== undefined)
1188
- return this.resync([...this.args, next]);
1189
- if (!$mol_wire_fiber.warm)
1190
- return this.result();
1191
- if ($mol_wire_auto()?.temp) {
1192
- return this.once();
1193
- }
1194
- else {
1195
- return this.sync();
1196
- }
1197
- }, { atom: this });
1198
- }
1199
- destructor() {
1200
- super.destructor();
1201
- const prev = this.cache;
1202
- if ($mol_owning_check(this, prev)) {
1203
- prev.destructor();
1204
- }
1205
- if (this.pub_from === 0) {
1206
- ;
1207
- (this.host ?? this.task)[this.field()] = null;
1208
- }
1209
- else {
1210
- ;
1211
- (this.host ?? this.task)[this.field()].delete(this[Symbol.toStringTag]);
1212
- }
1213
- }
1214
- put(next) {
1215
- const prev = this.cache;
1216
- update: if (next !== prev) {
1217
- try {
1218
- if ($mol_compare_deep(prev, next))
1219
- break update;
1220
- }
1221
- catch (error) {
1222
- $mol_fail_log(error);
1223
- }
1224
- if ($mol_owning_check(this, prev)) {
1225
- prev.destructor();
1226
- }
1227
- if ($mol_owning_catch(this, next)) {
1228
- try {
1229
- next[Symbol.toStringTag] = this[Symbol.toStringTag];
1230
- }
1231
- catch {
1232
- Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
1233
- }
1234
- }
1235
- if (!this.sub_empty)
1236
- this.emit();
1237
- }
1238
- this.cache = next;
1239
- this.cursor = $mol_wire_cursor.fresh;
1240
- if ($mol_promise_like(next))
1241
- return next;
1242
- this.complete_pubs();
1243
- return next;
1244
- }
1245
- }
1246
- __decorate([
1247
- $mol_wire_method
1248
- ], $mol_wire_atom.prototype, "resync", null);
1249
- __decorate([
1250
- $mol_wire_method
1251
- ], $mol_wire_atom.prototype, "once", null);
1252
- $.$mol_wire_atom = $mol_wire_atom;
1253
- })($ || ($ = {}));
1254
- //mol/wire/atom/atom.ts
1255
- ;
1256
- "use strict";
1257
- var $;
1258
- (function ($) {
1259
- function $mol_wire_solo(host, field, descr) {
1260
- if (!descr)
1261
- descr = Reflect.getOwnPropertyDescriptor(host, field);
1262
- const orig = descr?.value ?? host[field];
1263
- const sup = Reflect.getPrototypeOf(host);
1264
- if (typeof sup[field] === 'function') {
1265
- Object.defineProperty(orig, 'name', { value: sup[field].name });
1266
- }
1267
- const descr2 = {
1268
- ...descr,
1269
- value: function (...args) {
1270
- let atom = $mol_wire_atom.solo(this, orig);
1271
- if ((args.length === 0) || (args[0] === undefined)) {
1272
- if (!$mol_wire_fiber.warm)
1273
- return atom.result();
1274
- if ($mol_wire_auto()?.temp) {
1275
- return atom.once();
1276
- }
1277
- else {
1278
- return atom.sync();
1279
- }
1280
- }
1281
- return atom.resync(args);
1282
- }
1283
- };
1284
- Reflect.defineProperty(descr2.value, 'name', { value: orig.name + ' ' });
1285
- Object.assign(descr2.value, { orig });
1286
- Reflect.defineProperty(host, field, descr2);
1287
- return descr2;
1288
- }
1289
- $.$mol_wire_solo = $mol_wire_solo;
1290
- })($ || ($ = {}));
1291
- //mol/wire/solo/solo.ts
1292
- ;
1293
- "use strict";
1294
- var $;
1295
- (function ($) {
1296
- function $mol_wire_plex(host, field, descr) {
1297
- if (!descr)
1298
- descr = Reflect.getOwnPropertyDescriptor(host, field);
1299
- const orig = descr?.value ?? host[field];
1300
- const sup = Reflect.getPrototypeOf(host);
1301
- if (typeof sup[field] === 'function') {
1302
- Object.defineProperty(orig, 'name', { value: sup[field].name });
1303
- }
1304
- const descr2 = {
1305
- ...descr,
1306
- value: function (...args) {
1307
- let atom = $mol_wire_atom.plex(this, orig, args[0]);
1308
- if ((args.length === 1) || (args[1] === undefined)) {
1309
- if (!$mol_wire_fiber.warm)
1310
- return atom.result();
1311
- if ($mol_wire_auto()?.temp) {
1312
- return atom.once();
1313
- }
1314
- else {
1315
- return atom.sync();
1316
- }
1317
- }
1318
- return atom.resync(args);
1319
- }
1320
- };
1321
- Reflect.defineProperty(descr2.value, 'name', { value: orig.name + ' ' });
1322
- Object.assign(descr2.value, { orig });
1323
- Reflect.defineProperty(host, field, descr2);
1324
- return descr2;
1325
- }
1326
- $.$mol_wire_plex = $mol_wire_plex;
1327
- })($ || ($ = {}));
1328
- //mol/wire/plex/plex.ts
1329
- ;
1330
- "use strict";
1331
- var $;
1332
- (function ($) {
1333
- $.$mol_mem = $mol_wire_solo;
1334
- $.$mol_mem_key = $mol_wire_plex;
1335
- })($ || ($ = {}));
1336
- //mol/mem/mem.ts
1337
- ;
1338
- "use strict";
1339
- var $;
1340
- (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
- });
839
+ $.$hyoo_crowd_unit_bin = $hyoo_crowd_unit_bin;
840
+ function $hyoo_crowd_unit_compare(left, right) {
841
+ return (left.group() - right.group())
842
+ || (left.time - right.time)
843
+ || ((left.auth > right.auth) ? 1 : (left.auth < right.auth) ? -1 : 0)
844
+ || ((left.self > right.self) ? 1 : (left.self < right.self) ? -1 : 0)
845
+ || ((left.head > right.head) ? 1 : (left.head < right.head) ? -1 : 0)
846
+ || ((left.prev > right.prev) ? 1 : (left.prev < right.prev) ? -1 : 0)
847
+ || ((left.next > right.next) ? 1 : (left.next < right.next) ? -1 : 0)
848
+ || ((left.land > right.land) ? 1 : (left.land < right.land) ? -1 : 0);
1359
849
  }
1360
- $.$mol_wire_sync = $mol_wire_sync;
850
+ $.$hyoo_crowd_unit_compare = $hyoo_crowd_unit_compare;
1361
851
  })($ || ($ = {}));
1362
- //mol/wire/sync/sync.ts
852
+ //hyoo/crowd/unit/unit.ts
1363
853
  ;
1364
854
  "use strict";
1365
855
  var $;
1366
856
  (function ($) {
857
+ let $mol_wire_cursor;
858
+ (function ($mol_wire_cursor) {
859
+ $mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
860
+ $mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
861
+ $mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
862
+ $mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
863
+ })($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
1367
864
  })($ || ($ = {}));
1368
- //mol/dom/context/context.ts
865
+ //mol/wire/cursor/cursor.ts
1369
866
  ;
1370
867
  "use strict";
1371
868
  var $;
1372
869
  (function ($) {
1373
- $.$mol_dom_context = self;
870
+ class $mol_wire_pub extends Object {
871
+ data = [];
872
+ static get [Symbol.species]() {
873
+ return Array;
874
+ }
875
+ sub_from = 0;
876
+ get sub_list() {
877
+ const res = [];
878
+ for (let i = this.sub_from; i < this.data.length; i += 2) {
879
+ res.push(this.data[i]);
880
+ }
881
+ return res;
882
+ }
883
+ get sub_empty() {
884
+ return this.sub_from === this.data.length;
885
+ }
886
+ sub_on(sub, pub_pos) {
887
+ const pos = this.data.length;
888
+ this.data.push(sub, pub_pos);
889
+ return pos;
890
+ }
891
+ sub_off(sub_pos) {
892
+ if (!(sub_pos < this.data.length)) {
893
+ $mol_fail(new Error(`Wrong pos ${sub_pos}`));
894
+ }
895
+ const end = this.data.length - 2;
896
+ if (sub_pos !== end) {
897
+ this.peer_move(end, sub_pos);
898
+ }
899
+ this.data.pop();
900
+ this.data.pop();
901
+ if (this.data.length === this.sub_from)
902
+ this.reap();
903
+ }
904
+ reap() { }
905
+ promote() {
906
+ $mol_wire_auto()?.track_next(this);
907
+ }
908
+ fresh() { }
909
+ complete() { }
910
+ emit(quant = $mol_wire_cursor.stale) {
911
+ for (let i = this.sub_from; i < this.data.length; i += 2) {
912
+ ;
913
+ this.data[i].absorb(quant);
914
+ }
915
+ }
916
+ peer_move(from_pos, to_pos) {
917
+ const peer = this.data[from_pos];
918
+ const self_pos = this.data[from_pos + 1];
919
+ this.data[to_pos] = peer;
920
+ this.data[to_pos + 1] = self_pos;
921
+ peer.peer_repos(self_pos, to_pos);
922
+ }
923
+ peer_repos(peer_pos, self_pos) {
924
+ this.data[peer_pos + 1] = self_pos;
925
+ }
926
+ }
927
+ $.$mol_wire_pub = $mol_wire_pub;
1374
928
  })($ || ($ = {}));
1375
- //mol/dom/context/context.web.ts
929
+ //mol/wire/pub/pub.ts
930
+ ;
931
+ "use strict";
932
+ //mol/wire/sub/sub.ts
1376
933
  ;
1377
934
  "use strict";
1378
935
  var $;
1379
936
  (function ($) {
1380
- function $mol_dom_render_children(el, childNodes) {
1381
- const node_set = new Set(childNodes);
1382
- let nextNode = el.firstChild;
1383
- for (let view of childNodes) {
1384
- if (view == null)
1385
- continue;
1386
- if (view instanceof $mol_dom_context.Node) {
1387
- while (true) {
1388
- if (!nextNode) {
1389
- el.appendChild(view);
1390
- break;
1391
- }
1392
- if (nextNode == view) {
1393
- nextNode = nextNode.nextSibling;
1394
- break;
1395
- }
1396
- else {
1397
- if (node_set.has(nextNode)) {
1398
- el.insertBefore(view, nextNode);
1399
- break;
1400
- }
1401
- else {
1402
- const nn = nextNode.nextSibling;
1403
- el.removeChild(nextNode);
1404
- nextNode = nn;
1405
- }
937
+ $.$mol_wire_auto_sub = null;
938
+ function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
939
+ return $.$mol_wire_auto_sub = next;
940
+ }
941
+ $.$mol_wire_auto = $mol_wire_auto;
942
+ $.$mol_wire_affected = [];
943
+ })($ || ($ = {}));
944
+ //mol/wire/wire.ts
945
+ ;
946
+ "use strict";
947
+ var $;
948
+ (function ($) {
949
+ class $mol_wire_pub_sub extends $mol_wire_pub {
950
+ pub_from = 0;
951
+ cursor = $mol_wire_cursor.stale;
952
+ get temp() {
953
+ return false;
954
+ }
955
+ get pub_list() {
956
+ const res = [];
957
+ const max = this.cursor >= 0 ? this.cursor : this.sub_from;
958
+ for (let i = this.pub_from; i < max; i += 2) {
959
+ if (this.data[i])
960
+ res.push(this.data[i]);
961
+ }
962
+ return res;
963
+ }
964
+ track_on() {
965
+ this.cursor = this.pub_from;
966
+ const sub = $mol_wire_auto();
967
+ $mol_wire_auto(this);
968
+ return sub;
969
+ }
970
+ promote() {
971
+ if (this.cursor >= this.pub_from) {
972
+ $mol_fail(new Error('Circular subscription'));
973
+ }
974
+ super.promote();
975
+ }
976
+ track_next(pub) {
977
+ if (this.cursor < 0)
978
+ $mol_fail(new Error('Promo to non begun sub'));
979
+ if (this.cursor < this.sub_from) {
980
+ const next = this.data[this.cursor];
981
+ if (pub === undefined)
982
+ return next ?? null;
983
+ if (next === pub) {
984
+ this.cursor += 2;
985
+ return next;
986
+ }
987
+ if (next) {
988
+ if (this.sub_from < this.data.length) {
989
+ this.peer_move(this.sub_from, this.data.length);
1406
990
  }
991
+ this.peer_move(this.cursor, this.sub_from);
992
+ this.sub_from += 2;
1407
993
  }
1408
994
  }
1409
995
  else {
1410
- if (nextNode && nextNode.nodeName === '#text') {
1411
- const str = String(view);
1412
- if (nextNode.nodeValue !== str)
1413
- nextNode.nodeValue = str;
1414
- nextNode = nextNode.nextSibling;
996
+ if (pub === undefined)
997
+ return null;
998
+ if (this.sub_from < this.data.length) {
999
+ this.peer_move(this.sub_from, this.data.length);
1000
+ }
1001
+ this.sub_from += 2;
1002
+ }
1003
+ this.data[this.cursor] = pub;
1004
+ this.data[this.cursor + 1] = pub.sub_on(this, this.cursor);
1005
+ this.cursor += 2;
1006
+ return pub;
1007
+ }
1008
+ track_off(sub) {
1009
+ $mol_wire_auto(sub);
1010
+ if (this.cursor < 0) {
1011
+ $mol_fail(new Error('End of non begun sub'));
1012
+ }
1013
+ for (let cursor = this.pub_from; cursor < this.cursor; cursor += 2) {
1014
+ const pub = this.data[cursor];
1015
+ pub.fresh();
1016
+ }
1017
+ this.cursor = $mol_wire_cursor.fresh;
1018
+ }
1019
+ pub_off(sub_pos) {
1020
+ this.data[sub_pos] = undefined;
1021
+ this.data[sub_pos + 1] = undefined;
1022
+ }
1023
+ destructor() {
1024
+ for (let cursor = this.data.length - 2; cursor >= this.sub_from; cursor -= 2) {
1025
+ const sub = this.data[cursor];
1026
+ const pos = this.data[cursor + 1];
1027
+ sub.pub_off(pos);
1028
+ this.data.pop();
1029
+ this.data.pop();
1030
+ }
1031
+ this.cursor = this.pub_from;
1032
+ this.track_cut();
1033
+ this.cursor = $mol_wire_cursor.final;
1034
+ }
1035
+ track_cut() {
1036
+ if (this.cursor < this.pub_from) {
1037
+ $mol_fail(new Error('Cut of non begun sub'));
1038
+ }
1039
+ let tail = 0;
1040
+ for (let cursor = this.cursor; cursor < this.sub_from; cursor += 2) {
1041
+ const pub = this.data[cursor];
1042
+ pub?.sub_off(this.data[cursor + 1]);
1043
+ if (this.sub_from < this.data.length) {
1044
+ this.peer_move(this.data.length - 2, cursor);
1045
+ this.data.pop();
1046
+ this.data.pop();
1047
+ }
1048
+ else {
1049
+ ++tail;
1050
+ }
1051
+ }
1052
+ for (; tail; --tail) {
1053
+ this.data.pop();
1054
+ this.data.pop();
1055
+ }
1056
+ this.sub_from = this.cursor;
1057
+ }
1058
+ complete() { }
1059
+ complete_pubs() {
1060
+ const limit = this.cursor < 0 ? this.sub_from : this.cursor;
1061
+ for (let cursor = this.pub_from; cursor < limit; cursor += 2) {
1062
+ const pub = this.data[cursor];
1063
+ pub?.complete();
1064
+ }
1065
+ }
1066
+ absorb(quant = $mol_wire_cursor.stale) {
1067
+ if (this.cursor === $mol_wire_cursor.final)
1068
+ return;
1069
+ if (this.cursor >= quant)
1070
+ return;
1071
+ this.cursor = quant;
1072
+ this.emit($mol_wire_cursor.doubt);
1073
+ }
1074
+ [$mol_dev_format_head]() {
1075
+ return $mol_dev_format_native(this);
1076
+ }
1077
+ get pub_empty() {
1078
+ return this.sub_from === this.pub_from;
1079
+ }
1080
+ }
1081
+ $.$mol_wire_pub_sub = $mol_wire_pub_sub;
1082
+ })($ || ($ = {}));
1083
+ //mol/wire/pub/sub/sub.ts
1084
+ ;
1085
+ "use strict";
1086
+ var $;
1087
+ (function ($) {
1088
+ class $mol_after_frame extends $mol_object2 {
1089
+ task;
1090
+ static _promise = null;
1091
+ static get promise() {
1092
+ if (this._promise)
1093
+ return this._promise;
1094
+ return this._promise = new Promise(done => {
1095
+ const complete = () => {
1096
+ this._promise = null;
1097
+ done();
1098
+ };
1099
+ if (typeof requestAnimationFrame === 'function') {
1100
+ requestAnimationFrame(complete);
1415
1101
  }
1416
1102
  else {
1417
- const textNode = $mol_dom_context.document.createTextNode(String(view));
1418
- el.insertBefore(textNode, nextNode);
1103
+ setTimeout(complete, 16);
1419
1104
  }
1420
- }
1105
+ });
1421
1106
  }
1422
- while (nextNode) {
1423
- const currNode = nextNode;
1424
- nextNode = currNode.nextSibling;
1425
- el.removeChild(currNode);
1107
+ cancelled = false;
1108
+ promise;
1109
+ constructor(task) {
1110
+ super();
1111
+ this.task = task;
1112
+ this.promise = $mol_after_frame.promise.then(() => {
1113
+ if (this.cancelled)
1114
+ return;
1115
+ task();
1116
+ });
1117
+ }
1118
+ destructor() {
1119
+ this.cancelled = true;
1426
1120
  }
1427
1121
  }
1428
- $.$mol_dom_render_children = $mol_dom_render_children;
1122
+ $.$mol_after_frame = $mol_after_frame;
1429
1123
  })($ || ($ = {}));
1430
- //mol/dom/render/children/children.ts
1124
+ //mol/after/frame/frame.web.ts
1431
1125
  ;
1432
1126
  "use strict";
1433
- //mol/type/partial/deep/deep.ts
1127
+ var $;
1128
+ (function ($) {
1129
+ function $mol_promise_like(val) {
1130
+ return val && typeof val.then === 'function';
1131
+ }
1132
+ $.$mol_promise_like = $mol_promise_like;
1133
+ })($ || ($ = {}));
1134
+ //mol/promise/like/like.ts
1434
1135
  ;
1435
1136
  "use strict";
1436
1137
  var $;
1437
1138
  (function ($) {
1438
- $.$mol_jsx_prefix = '';
1439
- $.$mol_jsx_crumbs = '';
1440
- $.$mol_jsx_booked = null;
1441
- $.$mol_jsx_document = {
1442
- getElementById: () => null,
1443
- createElementNS: (space, name) => $mol_dom_context.document.createElementNS(space, name),
1444
- createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
1445
- };
1446
- $.$mol_jsx_frag = '';
1447
- function $mol_jsx(Elem, props, ...childNodes) {
1448
- const id = props && props.id || '';
1449
- const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
1450
- const crumbs_self = id ? $.$mol_jsx_crumbs.replace(/(\S+)/g, `$1_${id.replace(/\/.*/i, '')}`) : $.$mol_jsx_crumbs;
1451
- if (Elem && $.$mol_jsx_booked) {
1452
- if ($.$mol_jsx_booked.has(id)) {
1453
- $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
1139
+ const handled = new WeakSet();
1140
+ class $mol_wire_fiber extends $mol_wire_pub_sub {
1141
+ task;
1142
+ host;
1143
+ static warm = true;
1144
+ static planning = new Set();
1145
+ static reaping = new Set();
1146
+ static plan_task = null;
1147
+ static plan() {
1148
+ if (this.plan_task)
1149
+ return;
1150
+ this.plan_task = new $mol_after_frame(() => {
1151
+ try {
1152
+ this.sync();
1153
+ }
1154
+ finally {
1155
+ $mol_wire_fiber.plan_task = null;
1156
+ }
1157
+ });
1158
+ }
1159
+ static sync() {
1160
+ while (this.planning.size) {
1161
+ for (const fiber of this.planning) {
1162
+ this.planning.delete(fiber);
1163
+ if (fiber.cursor >= 0)
1164
+ continue;
1165
+ if (fiber.cursor === $mol_wire_cursor.final)
1166
+ continue;
1167
+ fiber.fresh();
1168
+ }
1454
1169
  }
1455
- else {
1456
- $.$mol_jsx_booked.add(id);
1170
+ while (this.reaping.size) {
1171
+ const fibers = this.reaping;
1172
+ this.reaping = new Set;
1173
+ for (const fiber of fibers) {
1174
+ if (!fiber.sub_empty)
1175
+ continue;
1176
+ fiber.destructor();
1177
+ }
1457
1178
  }
1458
1179
  }
1459
- let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
1460
- if ($.$mol_jsx_prefix) {
1461
- const prefix_ext = $.$mol_jsx_prefix;
1462
- const booked_ext = $.$mol_jsx_booked;
1463
- const crumbs_ext = $.$mol_jsx_crumbs;
1464
- for (const field in props) {
1465
- const func = props[field];
1466
- if (typeof func !== 'function')
1467
- continue;
1468
- const wrapper = function (...args) {
1469
- const prefix = $.$mol_jsx_prefix;
1470
- const booked = $.$mol_jsx_booked;
1471
- const crumbs = $.$mol_jsx_crumbs;
1472
- try {
1473
- $.$mol_jsx_prefix = prefix_ext;
1474
- $.$mol_jsx_booked = booked_ext;
1475
- $.$mol_jsx_crumbs = crumbs_ext;
1476
- return func.call(this, ...args);
1477
- }
1478
- finally {
1479
- $.$mol_jsx_prefix = prefix;
1480
- $.$mol_jsx_booked = booked;
1481
- $.$mol_jsx_crumbs = crumbs;
1482
- }
1483
- };
1484
- $mol_func_name_from(wrapper, func);
1485
- props[field] = wrapper;
1486
- }
1180
+ [Symbol.toStringTag];
1181
+ cache = undefined;
1182
+ get args() {
1183
+ return this.data.slice(0, this.pub_from);
1487
1184
  }
1488
- if (typeof Elem !== 'string') {
1489
- if ('prototype' in Elem) {
1490
- const view = node && node[String(Elem)] || new Elem;
1491
- Object.assign(view, props);
1492
- view[Symbol.toStringTag] = guid;
1493
- view.childNodes = childNodes;
1494
- if (!view.ownerDocument)
1495
- view.ownerDocument = $.$mol_jsx_document;
1496
- view.className = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
1497
- node = view.valueOf();
1498
- node[String(Elem)] = view;
1499
- return node;
1185
+ result() {
1186
+ if ($mol_promise_like(this.cache))
1187
+ return;
1188
+ if (this.cache instanceof Error)
1189
+ return;
1190
+ return this.cache;
1191
+ }
1192
+ field() {
1193
+ return this.task.name + '()';
1194
+ }
1195
+ constructor(id, task, host, args) {
1196
+ super();
1197
+ this.task = task;
1198
+ this.host = host;
1199
+ if (args)
1200
+ this.data.push(...args);
1201
+ this.pub_from = this.sub_from = args?.length ?? 0;
1202
+ this[Symbol.toStringTag] = id;
1203
+ }
1204
+ plan() {
1205
+ $mol_wire_fiber.planning.add(this);
1206
+ $mol_wire_fiber.plan();
1207
+ }
1208
+ reap() {
1209
+ $mol_wire_fiber.reaping.add(this);
1210
+ $mol_wire_fiber.plan();
1211
+ }
1212
+ toString() {
1213
+ return this[Symbol.toStringTag];
1214
+ }
1215
+ toJSON() {
1216
+ return this[Symbol.toStringTag];
1217
+ }
1218
+ [$mol_dev_format_head]() {
1219
+ const cursor = {
1220
+ [$mol_wire_cursor.stale]: '🔴',
1221
+ [$mol_wire_cursor.doubt]: '🟡',
1222
+ [$mol_wire_cursor.fresh]: '🟢',
1223
+ [$mol_wire_cursor.final]: '🔵',
1224
+ }[this.cursor] ?? this.cursor.toString();
1225
+ return $mol_dev_format_div({}, $mol_dev_format_native(this), $mol_dev_format_shade(cursor + ' '), $mol_dev_format_auto(this.cache));
1226
+ }
1227
+ get $() {
1228
+ return (this.host ?? this.task)['$'];
1229
+ }
1230
+ emit(quant = $mol_wire_cursor.stale) {
1231
+ if (this.sub_empty)
1232
+ this.plan();
1233
+ else
1234
+ super.emit(quant);
1235
+ }
1236
+ fresh() {
1237
+ if (this.cursor === $mol_wire_cursor.fresh)
1238
+ return;
1239
+ if (this.cursor === $mol_wire_cursor.final)
1240
+ return;
1241
+ check: if (this.cursor === $mol_wire_cursor.doubt) {
1242
+ for (let i = this.pub_from; i < this.sub_from; i += 2) {
1243
+ ;
1244
+ this.data[i]?.fresh();
1245
+ if (this.cursor !== $mol_wire_cursor.doubt)
1246
+ break check;
1247
+ }
1248
+ this.cursor = $mol_wire_cursor.fresh;
1249
+ return;
1500
1250
  }
1501
- else {
1502
- const prefix = $.$mol_jsx_prefix;
1503
- const booked = $.$mol_jsx_booked;
1504
- const crumbs = $.$mol_jsx_crumbs;
1505
- try {
1506
- $.$mol_jsx_prefix = guid;
1507
- $.$mol_jsx_booked = new Set;
1508
- $.$mol_jsx_crumbs = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
1509
- return Elem(props, ...childNodes);
1251
+ const bu = this.track_on();
1252
+ let result;
1253
+ try {
1254
+ switch (this.pub_from) {
1255
+ case 0:
1256
+ result = this.task.call(this.host);
1257
+ break;
1258
+ case 1:
1259
+ result = this.task.call(this.host, this.data[0]);
1260
+ break;
1261
+ default:
1262
+ result = this.task.call(this.host, ...this.args);
1263
+ break;
1510
1264
  }
1511
- finally {
1512
- $.$mol_jsx_prefix = prefix;
1513
- $.$mol_jsx_booked = booked;
1514
- $.$mol_jsx_crumbs = crumbs;
1265
+ if ($mol_promise_like(result)) {
1266
+ const put = (res) => {
1267
+ if (this.cache === result)
1268
+ this.put(res);
1269
+ return res;
1270
+ };
1271
+ result = Object.assign(result.then(put, put), {
1272
+ destructor: result['destructor'] ?? (() => { })
1273
+ });
1274
+ handled.add(result);
1275
+ }
1276
+ }
1277
+ catch (error) {
1278
+ if (error instanceof Error || $mol_promise_like(error)) {
1279
+ result = error;
1280
+ }
1281
+ else {
1282
+ result = new Error(String(error), { cause: error });
1283
+ }
1284
+ if ($mol_promise_like(result) && !handled.has(result)) {
1285
+ result = Object.assign(result.finally(() => {
1286
+ if (this.cache === result)
1287
+ this.absorb();
1288
+ }), {
1289
+ destructor: result['destructor'] ?? (() => { })
1290
+ });
1291
+ handled.add(result);
1515
1292
  }
1516
1293
  }
1294
+ if (!$mol_promise_like(result)) {
1295
+ this.track_cut();
1296
+ }
1297
+ this.track_off(bu);
1298
+ this.put(result);
1517
1299
  }
1518
- if (!node) {
1519
- node = Elem
1520
- ? $.$mol_jsx_document.createElementNS(props?.xmlns ?? 'http://www.w3.org/1999/xhtml', Elem)
1521
- : $.$mol_jsx_document.createDocumentFragment();
1300
+ refresh() {
1301
+ this.cursor = $mol_wire_cursor.stale;
1302
+ this.fresh();
1522
1303
  }
1523
- $mol_dom_render_children(node, [].concat(...childNodes));
1524
- if (!Elem)
1525
- return node;
1526
- if (guid)
1527
- node.id = guid;
1528
- for (const key in props) {
1529
- if (key === 'id')
1530
- continue;
1531
- if (typeof props[key] === 'string') {
1532
- if (typeof node[key] === 'string')
1533
- node[key] = props[key];
1534
- node.setAttribute(key, props[key]);
1304
+ sync() {
1305
+ if (!$mol_wire_fiber.warm) {
1306
+ return this.result();
1535
1307
  }
1536
- else if (props[key] &&
1537
- typeof props[key] === 'object' &&
1538
- Reflect.getPrototypeOf(props[key]) === Reflect.getPrototypeOf({})) {
1539
- if (typeof node[key] === 'object') {
1540
- Object.assign(node[key], props[key]);
1541
- continue;
1542
- }
1308
+ this.promote();
1309
+ this.fresh();
1310
+ if (this.cache instanceof Error) {
1311
+ return $mol_fail_hidden(this.cache);
1543
1312
  }
1544
- else {
1545
- node[key] = props[key];
1313
+ if ($mol_promise_like(this.cache)) {
1314
+ return $mol_fail_hidden(this.cache);
1546
1315
  }
1316
+ return this.cache;
1547
1317
  }
1548
- if ($.$mol_jsx_crumbs)
1549
- node.className = (props?.['class'] ? props['class'] + ' ' : '') + crumbs_self;
1550
- return node;
1551
- }
1552
- $.$mol_jsx = $mol_jsx;
1553
- })($ || ($ = {}));
1554
- //mol/jsx/jsx.ts
1555
- ;
1556
- "use strict";
1557
- var $;
1558
- (function ($_1) {
1559
- let $$;
1560
- (function ($$) {
1561
- let $;
1562
- })($$ = $_1.$$ || ($_1.$$ = {}));
1563
- $_1.$mol_object_field = Symbol('$mol_object_field');
1564
- class $mol_object extends $mol_object2 {
1565
- static make(config) {
1566
- return super.create(obj => {
1567
- for (let key in config)
1568
- obj[key] = config[key];
1569
- });
1318
+ async async() {
1319
+ while (true) {
1320
+ this.fresh();
1321
+ if (this.cache instanceof Error) {
1322
+ $mol_fail_hidden(this.cache);
1323
+ }
1324
+ if (!$mol_promise_like(this.cache))
1325
+ return this.cache;
1326
+ await this.cache;
1327
+ if (this.cursor === $mol_wire_cursor.final) {
1328
+ await new Promise(() => { });
1329
+ }
1330
+ }
1570
1331
  }
1571
1332
  }
1572
- $_1.$mol_object = $mol_object;
1333
+ $.$mol_wire_fiber = $mol_wire_fiber;
1573
1334
  })($ || ($ = {}));
1574
- //mol/object/object.ts
1335
+ //mol/wire/fiber/fiber.ts
1575
1336
  ;
1576
1337
  "use strict";
1577
1338
  var $;
1578
1339
  (function ($) {
1579
- class $mol_state_local extends $mol_object {
1580
- static 'native()';
1581
- static native() {
1582
- if (this['native()'])
1583
- return this['native()'];
1584
- check: try {
1585
- const native = $mol_dom_context.localStorage;
1586
- if (!native)
1587
- break check;
1588
- native.setItem('', '');
1589
- native.removeItem('');
1590
- return this['native()'] = native;
1591
- }
1592
- catch (error) {
1593
- console.warn(error);
1340
+ const named = new WeakSet();
1341
+ function $mol_func_name(func) {
1342
+ let name = func.name;
1343
+ if (name?.length > 1)
1344
+ return name;
1345
+ if (named.has(func))
1346
+ return name;
1347
+ for (let key in this) {
1348
+ try {
1349
+ if (this[key] !== func)
1350
+ continue;
1351
+ name = key;
1352
+ Object.defineProperty(func, 'name', { value: name });
1353
+ break;
1594
1354
  }
1595
- return this['native()'] = {
1596
- getItem(key) {
1597
- return this[':' + key];
1598
- },
1599
- setItem(key, value) {
1600
- this[':' + key] = value;
1601
- },
1602
- removeItem(key) {
1603
- this[':' + key] = void 0;
1604
- }
1605
- };
1606
- }
1607
- static changes(next) { return next; }
1608
- static value(key, next) {
1609
- this.changes();
1610
- if (next === void 0)
1611
- return JSON.parse(this.native().getItem(key) || 'null');
1612
- if (next === null)
1613
- this.native().removeItem(key);
1614
- else
1615
- this.native().setItem(key, JSON.stringify(next));
1616
- return next;
1617
- }
1618
- prefix() { return ''; }
1619
- value(key, next) {
1620
- return $mol_state_local.value(this.prefix() + '.' + key, next);
1355
+ catch { }
1621
1356
  }
1357
+ named.add(func);
1358
+ return name;
1622
1359
  }
1623
- __decorate([
1624
- $mol_mem
1625
- ], $mol_state_local, "changes", null);
1626
- __decorate([
1627
- $mol_mem_key
1628
- ], $mol_state_local, "value", null);
1629
- $.$mol_state_local = $mol_state_local;
1360
+ $.$mol_func_name = $mol_func_name;
1361
+ function $mol_func_name_from(target, source) {
1362
+ Object.defineProperty(target, 'name', { value: source.name });
1363
+ return target;
1364
+ }
1365
+ $.$mol_func_name_from = $mol_func_name_from;
1630
1366
  })($ || ($ = {}));
1631
- //mol/state/local/local.ts
1367
+ //mol/func/name/name.ts
1632
1368
  ;
1633
1369
  "use strict";
1634
1370
  var $;
1635
1371
  (function ($) {
1636
- self.addEventListener('storage', event => $.$mol_state_local.changes(event));
1372
+ function $mol_guid(length = 8, exists = () => false) {
1373
+ for (;;) {
1374
+ let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
1375
+ if (exists(id))
1376
+ continue;
1377
+ return id;
1378
+ }
1379
+ }
1380
+ $.$mol_guid = $mol_guid;
1637
1381
  })($ || ($ = {}));
1638
- //mol/state/local/local.web.ts
1639
- ;
1640
- "use strict";
1641
- //node/node.ts
1642
- ;
1643
- "use strict";
1644
- var $node = $node || {};
1645
- //node/node.web.ts
1382
+ //mol/guid/guid.ts
1646
1383
  ;
1647
1384
  "use strict";
1648
1385
  var $;
1649
1386
  (function ($) {
1650
- const TextEncoder = globalThis.TextEncoder ?? $node.util.TextEncoder;
1651
- const encoder = new TextEncoder();
1652
- function $mol_charset_encode(value) {
1653
- return encoder.encode(value);
1387
+ $.$mol_key_store = new WeakMap();
1388
+ function $mol_key(value) {
1389
+ if (!value)
1390
+ return JSON.stringify(value);
1391
+ if (typeof value !== 'object' && typeof value !== 'function')
1392
+ return JSON.stringify(value);
1393
+ return JSON.stringify(value, (field, value) => {
1394
+ if (!value)
1395
+ return value;
1396
+ if (typeof value !== 'object' && typeof value !== 'function')
1397
+ return value;
1398
+ if (Array.isArray(value))
1399
+ return value;
1400
+ const proto = Reflect.getPrototypeOf(value);
1401
+ if (!proto)
1402
+ return value;
1403
+ if (Reflect.getPrototypeOf(proto) === null)
1404
+ return value;
1405
+ if ('toJSON' in value)
1406
+ return value;
1407
+ if (value instanceof RegExp)
1408
+ return value.toString();
1409
+ let key = $.$mol_key_store.get(value);
1410
+ if (key)
1411
+ return key;
1412
+ key = $mol_guid();
1413
+ $.$mol_key_store.set(value, key);
1414
+ return key;
1415
+ });
1654
1416
  }
1655
- $.$mol_charset_encode = $mol_charset_encode;
1417
+ $.$mol_key = $mol_key;
1656
1418
  })($ || ($ = {}));
1657
- //mol/charset/encode/encode.ts
1419
+ //mol/key/key.ts
1658
1420
  ;
1659
1421
  "use strict";
1660
1422
  var $;
1661
1423
  (function ($) {
1662
- function $mol_int62_string_ensure(str) {
1663
- if (typeof str !== 'string')
1664
- return null;
1665
- return $mol_int62_from_string(str) && str;
1666
- }
1667
- $.$mol_int62_string_ensure = $mol_int62_string_ensure;
1668
- $.$mol_int62_max = (2 ** 30) - 1;
1669
- $.$mol_int62_min = -(2 ** 30);
1670
- $.$mol_int62_range = $.$mol_int62_max - $.$mol_int62_min + 1;
1671
- function $mol_int62_to_string({ lo, hi }) {
1672
- lo = (lo + $.$mol_int62_range) % $.$mol_int62_range;
1673
- hi = (hi + $.$mol_int62_range) % $.$mol_int62_range;
1674
- return lo.toString(36) + '_' + hi.toString(36);
1675
- }
1676
- $.$mol_int62_to_string = $mol_int62_to_string;
1677
- function $mol_int62_from_string(str) {
1678
- const [str_lo, str_hi] = str.split('_');
1679
- const int_lo = parseInt(str_lo, 36);
1680
- const int_hi = parseInt(str_hi, 36);
1681
- if (int_lo.toString(36) !== str_lo || int_hi.toString(36) !== str_hi) {
1682
- return null;
1424
+ $.$mol_compare_deep_cache = new WeakMap();
1425
+ function $mol_compare_deep(left, right) {
1426
+ if (Object.is(left, right))
1427
+ return true;
1428
+ if (left === null)
1429
+ return false;
1430
+ if (right === null)
1431
+ return false;
1432
+ if (typeof left !== 'object')
1433
+ return false;
1434
+ if (typeof right !== 'object')
1435
+ return false;
1436
+ const left_proto = Reflect.getPrototypeOf(left);
1437
+ const right_proto = Reflect.getPrototypeOf(right);
1438
+ if (left_proto !== right_proto)
1439
+ return false;
1440
+ if (left instanceof Boolean)
1441
+ return Object.is(left.valueOf(), right['valueOf']());
1442
+ if (left instanceof Number)
1443
+ return Object.is(left.valueOf(), right['valueOf']());
1444
+ if (left instanceof String)
1445
+ return Object.is(left.valueOf(), right['valueOf']());
1446
+ if (left instanceof Date)
1447
+ return Object.is(left.valueOf(), right['valueOf']());
1448
+ if (left instanceof RegExp)
1449
+ return left.source === right.source && left.flags === right.flags;
1450
+ if (left instanceof Error)
1451
+ return left.message === right.message && left.stack === right.stack;
1452
+ let left_cache = $.$mol_compare_deep_cache.get(left);
1453
+ if (left_cache) {
1454
+ const right_cache = left_cache.get(right);
1455
+ if (typeof right_cache === 'boolean')
1456
+ return right_cache;
1683
1457
  }
1684
- return {
1685
- lo: (int_lo - $.$mol_int62_min) % $.$mol_int62_range + $.$mol_int62_min,
1686
- hi: (int_hi - $.$mol_int62_min) % $.$mol_int62_range + $.$mol_int62_min,
1687
- };
1458
+ else {
1459
+ left_cache = new WeakMap([[right, true]]);
1460
+ $.$mol_compare_deep_cache.set(left, left_cache);
1461
+ }
1462
+ let result;
1463
+ try {
1464
+ if (!left_proto)
1465
+ result = compare_pojo(left, right);
1466
+ else if (!Reflect.getPrototypeOf(left_proto))
1467
+ result = compare_pojo(left, right);
1468
+ else if (Array.isArray(left))
1469
+ result = compare_array(left, right);
1470
+ else if (left instanceof Set)
1471
+ result = compare_set(left, right);
1472
+ else if (left instanceof Map)
1473
+ result = compare_map(left, right);
1474
+ else if (ArrayBuffer.isView(left))
1475
+ result = compare_buffer(left, right);
1476
+ else if (Symbol.toPrimitive in left)
1477
+ result = compare_primitive(left, right);
1478
+ else
1479
+ result = false;
1480
+ }
1481
+ finally {
1482
+ left_cache.set(right, result);
1483
+ }
1484
+ return result;
1688
1485
  }
1689
- $.$mol_int62_from_string = $mol_int62_from_string;
1690
- function $mol_int62_compare(left_lo, left_hi, right_lo, right_hi) {
1691
- return (right_hi - left_hi) || (right_lo - left_lo);
1486
+ $.$mol_compare_deep = $mol_compare_deep;
1487
+ function compare_array(left, right) {
1488
+ const len = left.length;
1489
+ if (len !== right.length)
1490
+ return false;
1491
+ for (let i = 0; i < len; ++i) {
1492
+ if (!$mol_compare_deep(left[i], right[i]))
1493
+ return false;
1494
+ }
1495
+ return true;
1692
1496
  }
1693
- $.$mol_int62_compare = $mol_int62_compare;
1694
- function $mol_int62_inc(lo, hi, max = $.$mol_int62_max) {
1695
- if (lo === max) {
1696
- return { lo: -max, hi: hi + 1 };
1497
+ function compare_buffer(left, right) {
1498
+ const len = left.byteLength;
1499
+ if (len !== right.byteLength)
1500
+ return false;
1501
+ for (let i = 0; i < len; ++i) {
1502
+ if (left[i] !== right[i])
1503
+ return false;
1697
1504
  }
1698
- else {
1699
- return { lo: lo + 1, hi };
1505
+ return true;
1506
+ }
1507
+ function compare_iterator(left, right) {
1508
+ while (true) {
1509
+ const left_next = left.next();
1510
+ const right_next = right.next();
1511
+ if (left_next.done !== right_next.done)
1512
+ return false;
1513
+ if (left_next.done)
1514
+ break;
1515
+ if (!$mol_compare_deep(left_next.value, right_next.value))
1516
+ return false;
1700
1517
  }
1518
+ return true;
1701
1519
  }
1702
- $.$mol_int62_inc = $mol_int62_inc;
1703
- function $mol_int62_random() {
1704
- return {
1705
- lo: Math.floor(Math.random() * $.$mol_int62_range + $.$mol_int62_min),
1706
- hi: Math.floor(Math.random() * $.$mol_int62_range + $.$mol_int62_min),
1707
- };
1520
+ function compare_set(left, right) {
1521
+ if (left.size !== right.size)
1522
+ return false;
1523
+ return compare_iterator(left.values(), right.values());
1708
1524
  }
1709
- $.$mol_int62_random = $mol_int62_random;
1710
- function $mol_int62_hash_string(str) {
1711
- return $mol_int62_to_string($mol_int62_hash_buffer($mol_charset_encode(str)));
1525
+ function compare_map(left, right) {
1526
+ if (left.size !== right.size)
1527
+ return false;
1528
+ return compare_iterator(left.keys(), right.keys())
1529
+ && compare_iterator(left.values(), right.values());
1712
1530
  }
1713
- $.$mol_int62_hash_string = $mol_int62_hash_string;
1714
- function $mol_int62_hash_buffer(buf, seed = { lo: 0, hi: 0 }) {
1715
- let h1 = 0xdeadbeef ^ seed.lo;
1716
- let h2 = 0x41c6ce57 ^ seed.hi;
1717
- for (const byte of buf) {
1718
- h1 = Math.imul(h1 ^ byte, 2654435761);
1719
- h2 = Math.imul(h2 ^ byte, 1597334677);
1531
+ function compare_pojo(left, right) {
1532
+ const left_keys = Object.getOwnPropertyNames(left);
1533
+ const right_keys = Object.getOwnPropertyNames(right);
1534
+ if (!compare_array(left_keys, right_keys))
1535
+ return false;
1536
+ for (let key of left_keys) {
1537
+ if (!$mol_compare_deep(left[key], right[key]))
1538
+ return false;
1720
1539
  }
1721
- h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
1722
- h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
1723
- return { lo: h1 << 1 >> 1, hi: h2 << 1 >> 1 };
1540
+ const left_syms = Object.getOwnPropertySymbols(left);
1541
+ const right_syms = Object.getOwnPropertySymbols(right);
1542
+ if (!compare_array(left_syms, right_syms))
1543
+ return false;
1544
+ for (let key of left_syms) {
1545
+ if (!$mol_compare_deep(left[key], right[key]))
1546
+ return false;
1547
+ }
1548
+ return true;
1549
+ }
1550
+ function compare_primitive(left, right) {
1551
+ return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
1724
1552
  }
1725
- $.$mol_int62_hash_buffer = $mol_int62_hash_buffer;
1726
- })($ || ($ = {}));
1727
- //mol/int62/int62.ts
1728
- ;
1729
- "use strict";
1730
- var $;
1731
- (function ($) {
1732
- $.$mol_crypto_native = crypto;
1733
1553
  })($ || ($ = {}));
1734
- //mol/crypto/native/native.web.ts
1554
+ //mol/compare/deep/deep.ts
1735
1555
  ;
1736
1556
  "use strict";
1737
1557
  var $;
1738
1558
  (function ($) {
1739
- const algorithm = {
1740
- name: 'ECDSA',
1741
- hash: 'SHA-256',
1742
- namedCurve: "P-256",
1743
- };
1744
- async function $mol_crypto_auditor_pair() {
1745
- const pair = await $mol_crypto_native.subtle.generateKey(algorithm, true, ['sign', 'verify']);
1746
- return {
1747
- public: new $mol_crypto_auditor_public(pair.publicKey),
1748
- private: new $mol_crypto_auditor_private(pair.privateKey),
1749
- };
1750
- }
1751
- $.$mol_crypto_auditor_pair = $mol_crypto_auditor_pair;
1752
- class $mol_crypto_auditor_public extends Object {
1753
- native;
1754
- static size = 86;
1755
- constructor(native) {
1756
- super();
1757
- this.native = native;
1559
+ class $mol_wire_task extends $mol_wire_fiber {
1560
+ static getter(task) {
1561
+ return function $mol_wire_task_get(host, args) {
1562
+ const sub = $mol_wire_auto();
1563
+ const existen = sub?.track_next();
1564
+ reuse: if (existen) {
1565
+ if (!existen.temp)
1566
+ break reuse;
1567
+ if (existen.host !== host)
1568
+ break reuse;
1569
+ if (existen.task !== task)
1570
+ break reuse;
1571
+ if (!$mol_compare_deep(existen.args, args))
1572
+ break reuse;
1573
+ return existen;
1574
+ }
1575
+ return new $mol_wire_task(`${host?.[Symbol.toStringTag] ?? host}.${task.name}(#)`, task, host, args);
1576
+ };
1758
1577
  }
1759
- static async from(serial) {
1760
- return new this(await $mol_crypto_native.subtle.importKey('jwk', {
1761
- crv: "P-256",
1762
- ext: true,
1763
- key_ops: ['verify'],
1764
- kty: "EC",
1765
- x: serial.slice(0, 43),
1766
- y: serial.slice(43, 86),
1767
- }, algorithm, true, ['verify']));
1578
+ get temp() {
1579
+ return true;
1768
1580
  }
1769
- async serial() {
1770
- const { x, y } = await $mol_crypto_native.subtle.exportKey('jwk', this.native);
1771
- return x + y;
1581
+ complete() {
1582
+ if ($mol_promise_like(this.cache))
1583
+ return;
1584
+ this.destructor();
1772
1585
  }
1773
- async verify(data, sign) {
1774
- return await $mol_crypto_native.subtle.verify(algorithm, this.native, sign, data);
1586
+ put(next) {
1587
+ const prev = this.cache;
1588
+ this.cache = next;
1589
+ if ($mol_promise_like(next)) {
1590
+ this.cursor = $mol_wire_cursor.fresh;
1591
+ if (next !== prev)
1592
+ this.emit();
1593
+ return next;
1594
+ }
1595
+ this.cursor = $mol_wire_cursor.final;
1596
+ if (this.sub_empty)
1597
+ this.destructor();
1598
+ else if (next !== prev)
1599
+ this.emit();
1600
+ return next;
1775
1601
  }
1776
1602
  }
1777
- $.$mol_crypto_auditor_public = $mol_crypto_auditor_public;
1778
- class $mol_crypto_auditor_private extends Object {
1779
- native;
1780
- static size = 129;
1781
- constructor(native) {
1782
- super();
1783
- this.native = native;
1784
- }
1785
- static async from(serial) {
1786
- return new this(await $mol_crypto_native.subtle.importKey('jwk', {
1787
- crv: "P-256",
1788
- ext: true,
1789
- key_ops: ['sign'],
1790
- kty: "EC",
1791
- x: serial.slice(0, 43),
1792
- y: serial.slice(43, 86),
1793
- d: serial.slice(86, 129),
1794
- }, algorithm, true, ['sign']));
1795
- }
1796
- async serial() {
1797
- const { x, y, d } = await $mol_crypto_native.subtle.exportKey('jwk', this.native);
1798
- return x + y + d;
1799
- }
1800
- async sign(data) {
1801
- return await $mol_crypto_native.subtle.sign(algorithm, this.native, data);
1802
- }
1803
- async public() {
1804
- return await $mol_crypto_auditor_public.from($mol_crypto_auditor_private_to_public(await this.serial()));
1603
+ $.$mol_wire_task = $mol_wire_task;
1604
+ })($ || ($ = {}));
1605
+ //mol/wire/task/task.ts
1606
+ ;
1607
+ "use strict";
1608
+ var $;
1609
+ (function ($) {
1610
+ function $mol_wire_method(host, field, descr) {
1611
+ if (!descr)
1612
+ descr = Reflect.getOwnPropertyDescriptor(host, field);
1613
+ const orig = descr?.value ?? host[field];
1614
+ const sup = Reflect.getPrototypeOf(host);
1615
+ if (typeof sup[field] === 'function') {
1616
+ Object.defineProperty(orig, 'name', { value: sup[field].name });
1805
1617
  }
1618
+ const temp = $mol_wire_task.getter(orig);
1619
+ const value = function (...args) {
1620
+ const fiber = temp(this ?? null, args);
1621
+ return fiber.sync();
1622
+ };
1623
+ Object.defineProperty(value, 'name', { value: orig.name + ' ' });
1624
+ Object.assign(value, { orig });
1625
+ const descr2 = { ...descr, value };
1626
+ Reflect.defineProperty(host, field, descr2);
1627
+ return descr2;
1806
1628
  }
1807
- $.$mol_crypto_auditor_private = $mol_crypto_auditor_private;
1808
- $.$mol_crypto_auditor_sign_size = 64;
1809
- function $mol_crypto_auditor_private_to_public(serial) {
1810
- return serial.slice(0, 86);
1629
+ $.$mol_wire_method = $mol_wire_method;
1630
+ })($ || ($ = {}));
1631
+ //mol/wire/method/method.ts
1632
+ ;
1633
+ "use strict";
1634
+ //mol/type/tail/tail.ts
1635
+ ;
1636
+ "use strict";
1637
+ //mol/type/foot/foot.ts
1638
+ ;
1639
+ "use strict";
1640
+ var $;
1641
+ (function ($) {
1642
+ const catched = new WeakMap();
1643
+ function $mol_fail_catch(error) {
1644
+ if (typeof error !== 'object')
1645
+ return false;
1646
+ if ($mol_promise_like(error))
1647
+ $mol_fail_hidden(error);
1648
+ if (catched.get(error))
1649
+ return false;
1650
+ catched.set(error, true);
1651
+ return true;
1811
1652
  }
1812
- $.$mol_crypto_auditor_private_to_public = $mol_crypto_auditor_private_to_public;
1653
+ $.$mol_fail_catch = $mol_fail_catch;
1813
1654
  })($ || ($ = {}));
1814
- //mol/crypto/auditor/auditor.ts
1655
+ //mol/fail/catch/catch.ts
1815
1656
  ;
1816
1657
  "use strict";
1817
1658
  var $;
1818
1659
  (function ($) {
1819
- let $hyoo_crowd_peer_level;
1820
- (function ($hyoo_crowd_peer_level) {
1821
- $hyoo_crowd_peer_level[$hyoo_crowd_peer_level["get"] = 0] = "get";
1822
- $hyoo_crowd_peer_level[$hyoo_crowd_peer_level["add"] = 1] = "add";
1823
- $hyoo_crowd_peer_level[$hyoo_crowd_peer_level["mod"] = 2] = "mod";
1824
- $hyoo_crowd_peer_level[$hyoo_crowd_peer_level["law"] = 3] = "law";
1825
- })($hyoo_crowd_peer_level = $.$hyoo_crowd_peer_level || ($.$hyoo_crowd_peer_level = {}));
1826
- class $hyoo_crowd_peer extends Object {
1827
- key_public;
1828
- key_public_serial;
1829
- key_private;
1830
- key_private_serial;
1831
- id;
1832
- constructor(key_public, key_public_serial, key_private, key_private_serial) {
1833
- super();
1834
- this.key_public = key_public;
1835
- this.key_public_serial = key_public_serial;
1836
- this.key_private = key_private;
1837
- this.key_private_serial = key_private_serial;
1838
- this.id = $mol_int62_hash_string(this.key_public_serial);
1839
- }
1840
- static async generate() {
1841
- const pair = await $$.$mol_crypto_auditor_pair();
1842
- const serial = await pair.private.serial();
1843
- return new this(pair.public, $mol_crypto_auditor_private_to_public(serial), pair.private, serial);
1844
- }
1845
- static async restore(serial) {
1846
- return new this(await $$.$mol_crypto_auditor_public.from(serial), $mol_crypto_auditor_private_to_public(serial), await $$.$mol_crypto_auditor_private.from(serial), serial);
1847
- }
1660
+ function $mol_fail_log(error) {
1661
+ if ($mol_promise_like(error))
1662
+ return false;
1663
+ if (!$mol_fail_catch(error))
1664
+ return false;
1665
+ console.error(error);
1666
+ return true;
1848
1667
  }
1849
- $.$hyoo_crowd_peer = $hyoo_crowd_peer;
1668
+ $.$mol_fail_log = $mol_fail_log;
1850
1669
  })($ || ($ = {}));
1851
- //hyoo/crowd/peer/peer.ts
1670
+ //mol/fail/log/log.ts
1852
1671
  ;
1853
1672
  "use strict";
1854
1673
  var $;
1855
1674
  (function ($) {
1856
- async function $hyoo_sync_peer(path) {
1857
- let serial = $mol_state_local.value('$hyoo_sync_peer');
1858
- if (typeof serial === 'string') {
1859
- return await $hyoo_crowd_peer.restore(serial);
1675
+ class $mol_wire_atom extends $mol_wire_fiber {
1676
+ static solo(host, task) {
1677
+ const field = task.name + '()';
1678
+ const existen = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
1679
+ if (existen)
1680
+ return existen;
1681
+ const prefix = host?.[Symbol.toStringTag] ?? (host instanceof Function ? $$.$mol_func_name(host) : host);
1682
+ const key = `${prefix}.${field}`;
1683
+ const fiber = new $mol_wire_atom(key, task, host, []);
1684
+ (host ?? task)[field] = fiber;
1685
+ return fiber;
1860
1686
  }
1861
- else {
1862
- serial = $mol_state_local.value(path);
1863
- if (typeof serial === 'string') {
1864
- $mol_state_local.value('$hyoo_sync_peer', serial);
1865
- $mol_state_local.value(path, null);
1687
+ static plex(host, task, key) {
1688
+ const field = task.name + '()';
1689
+ let dict = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
1690
+ const prefix = host?.[Symbol.toStringTag] ?? (host instanceof Function ? $$.$mol_func_name(host) : host);
1691
+ const id = `${prefix}.${task.name}(${$mol_key(key)})`;
1692
+ if (dict) {
1693
+ const existen = dict.get(id);
1694
+ if (existen)
1695
+ return existen;
1866
1696
  }
1697
+ else {
1698
+ dict = (host ?? task)[field] = new Map();
1699
+ }
1700
+ const fiber = new $mol_wire_atom(id, task, host, [key]);
1701
+ dict.set(id, fiber);
1702
+ return fiber;
1867
1703
  }
1868
- const frame = $mol_jsx("iframe", { src: "https://sync.hyoo.ru/auth/" });
1869
- frame.style.display = 'none';
1870
- await new Promise((done, fail) => {
1871
- frame.onload = done;
1872
- frame.onerror = fail;
1873
- frame.onabort = fail;
1874
- document.body.appendChild(frame);
1875
- });
1876
- const serial_ext = await new Promise((done, fail) => {
1877
- window.addEventListener('message', event => {
1878
- if (!Array.isArray(event.data))
1879
- return;
1880
- if (event.data[0] !== '$hyoo_sync_peer')
1881
- return;
1882
- done(event.data[1]);
1883
- });
1884
- frame.contentWindow.postMessage(['$hyoo_sync_peer', serial], '*');
1885
- setTimeout(() => done(serial), 5000);
1886
- });
1887
- document.body.removeChild(frame);
1888
- if (typeof serial_ext === 'string') {
1889
- if (!serial)
1890
- $mol_state_local.value('$hyoo_sync_peer', serial_ext);
1891
- return await $hyoo_crowd_peer.restore(serial_ext);
1704
+ static watching = new Set();
1705
+ static watcher = null;
1706
+ static watch() {
1707
+ $mol_wire_atom.watcher = new $mol_after_frame($mol_wire_atom.watch);
1708
+ for (const atom of $mol_wire_atom.watching) {
1709
+ if (atom.cursor === $mol_wire_cursor.final) {
1710
+ $mol_wire_atom.watching.delete(atom);
1711
+ }
1712
+ else {
1713
+ atom.cursor = $mol_wire_cursor.stale;
1714
+ atom.fresh();
1715
+ }
1716
+ }
1892
1717
  }
1893
- const peer = await $hyoo_crowd_peer.generate();
1894
- $mol_state_local.value('$hyoo_sync_peer', peer.key_private_serial);
1895
- return peer;
1718
+ watch() {
1719
+ if (!$mol_wire_atom.watcher) {
1720
+ $mol_wire_atom.watcher = new $mol_after_frame($mol_wire_atom.watch);
1721
+ }
1722
+ $mol_wire_atom.watching.add(this);
1723
+ }
1724
+ resync(args) {
1725
+ return this.put(this.task.call(this.host, ...args));
1726
+ }
1727
+ once() {
1728
+ return this.sync();
1729
+ }
1730
+ channel() {
1731
+ return Object.assign((next) => {
1732
+ if (next !== undefined)
1733
+ return this.resync([...this.args, next]);
1734
+ if (!$mol_wire_fiber.warm)
1735
+ return this.result();
1736
+ if ($mol_wire_auto()?.temp) {
1737
+ return this.once();
1738
+ }
1739
+ else {
1740
+ return this.sync();
1741
+ }
1742
+ }, { atom: this });
1743
+ }
1744
+ destructor() {
1745
+ super.destructor();
1746
+ const prev = this.cache;
1747
+ if ($mol_owning_check(this, prev)) {
1748
+ prev.destructor();
1749
+ }
1750
+ if (this.pub_from === 0) {
1751
+ ;
1752
+ (this.host ?? this.task)[this.field()] = null;
1753
+ }
1754
+ else {
1755
+ ;
1756
+ (this.host ?? this.task)[this.field()].delete(this[Symbol.toStringTag]);
1757
+ }
1758
+ }
1759
+ put(next) {
1760
+ const prev = this.cache;
1761
+ update: if (next !== prev) {
1762
+ try {
1763
+ if ($mol_compare_deep(prev, next))
1764
+ break update;
1765
+ }
1766
+ catch (error) {
1767
+ $mol_fail_log(error);
1768
+ }
1769
+ if ($mol_owning_check(this, prev)) {
1770
+ prev.destructor();
1771
+ }
1772
+ if ($mol_owning_catch(this, next)) {
1773
+ try {
1774
+ next[Symbol.toStringTag] = this[Symbol.toStringTag];
1775
+ }
1776
+ catch {
1777
+ Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
1778
+ }
1779
+ }
1780
+ if (!this.sub_empty)
1781
+ this.emit();
1782
+ }
1783
+ this.cache = next;
1784
+ this.cursor = $mol_wire_cursor.fresh;
1785
+ if ($mol_promise_like(next))
1786
+ return next;
1787
+ this.complete_pubs();
1788
+ return next;
1789
+ }
1790
+ }
1791
+ __decorate([
1792
+ $mol_wire_method
1793
+ ], $mol_wire_atom.prototype, "resync", null);
1794
+ __decorate([
1795
+ $mol_wire_method
1796
+ ], $mol_wire_atom.prototype, "once", null);
1797
+ $.$mol_wire_atom = $mol_wire_atom;
1798
+ })($ || ($ = {}));
1799
+ //mol/wire/atom/atom.ts
1800
+ ;
1801
+ "use strict";
1802
+ var $;
1803
+ (function ($) {
1804
+ function $mol_wire_solo(host, field, descr) {
1805
+ if (!descr)
1806
+ descr = Reflect.getOwnPropertyDescriptor(host, field);
1807
+ const orig = descr?.value ?? host[field];
1808
+ const sup = Reflect.getPrototypeOf(host);
1809
+ if (typeof sup[field] === 'function') {
1810
+ Object.defineProperty(orig, 'name', { value: sup[field].name });
1811
+ }
1812
+ const descr2 = {
1813
+ ...descr,
1814
+ value: function (...args) {
1815
+ let atom = $mol_wire_atom.solo(this, orig);
1816
+ if ((args.length === 0) || (args[0] === undefined)) {
1817
+ if (!$mol_wire_fiber.warm)
1818
+ return atom.result();
1819
+ if ($mol_wire_auto()?.temp) {
1820
+ return atom.once();
1821
+ }
1822
+ else {
1823
+ return atom.sync();
1824
+ }
1825
+ }
1826
+ return atom.resync(args);
1827
+ }
1828
+ };
1829
+ Reflect.defineProperty(descr2.value, 'name', { value: orig.name + ' ' });
1830
+ Object.assign(descr2.value, { orig });
1831
+ Reflect.defineProperty(host, field, descr2);
1832
+ return descr2;
1896
1833
  }
1897
- $.$hyoo_sync_peer = $hyoo_sync_peer;
1834
+ $.$mol_wire_solo = $mol_wire_solo;
1898
1835
  })($ || ($ = {}));
1899
- //hyoo/sync/peer/peer.web.tsx
1836
+ //mol/wire/solo/solo.ts
1900
1837
  ;
1901
1838
  "use strict";
1902
1839
  var $;
1903
1840
  (function ($) {
1904
- function $mol_wire_solid() {
1905
- const current = $mol_wire_auto();
1906
- if (current.reap !== nothing) {
1907
- current?.sub_on(sub, sub.data.length);
1841
+ function $mol_wire_plex(host, field, descr) {
1842
+ if (!descr)
1843
+ descr = Reflect.getOwnPropertyDescriptor(host, field);
1844
+ const orig = descr?.value ?? host[field];
1845
+ const sup = Reflect.getPrototypeOf(host);
1846
+ if (typeof sup[field] === 'function') {
1847
+ Object.defineProperty(orig, 'name', { value: sup[field].name });
1908
1848
  }
1909
- current.reap = nothing;
1849
+ const descr2 = {
1850
+ ...descr,
1851
+ value: function (...args) {
1852
+ let atom = $mol_wire_atom.plex(this, orig, args[0]);
1853
+ if ((args.length === 1) || (args[1] === undefined)) {
1854
+ if (!$mol_wire_fiber.warm)
1855
+ return atom.result();
1856
+ if ($mol_wire_auto()?.temp) {
1857
+ return atom.once();
1858
+ }
1859
+ else {
1860
+ return atom.sync();
1861
+ }
1862
+ }
1863
+ return atom.resync(args);
1864
+ }
1865
+ };
1866
+ Reflect.defineProperty(descr2.value, 'name', { value: orig.name + ' ' });
1867
+ Object.assign(descr2.value, { orig });
1868
+ Reflect.defineProperty(host, field, descr2);
1869
+ return descr2;
1910
1870
  }
1911
- $.$mol_wire_solid = $mol_wire_solid;
1912
- const nothing = () => { };
1913
- const sub = new $mol_wire_pub_sub;
1871
+ $.$mol_wire_plex = $mol_wire_plex;
1914
1872
  })($ || ($ = {}));
1915
- //mol/wire/solid/solid.ts
1873
+ //mol/wire/plex/plex.ts
1916
1874
  ;
1917
1875
  "use strict";
1918
1876
  var $;
1919
1877
  (function ($) {
1920
- class $mol_wrapper extends $mol_object2 {
1921
- static wrap;
1922
- static run(task) {
1923
- return this.func(task)();
1924
- }
1925
- static func(func) {
1926
- return this.wrap(func);
1927
- }
1928
- static get class() {
1929
- return (Class) => {
1930
- const construct = (target, args) => new Class(...args);
1931
- const handler = {
1932
- construct: this.func(construct)
1878
+ $.$mol_mem = $mol_wire_solo;
1879
+ $.$mol_mem_key = $mol_wire_plex;
1880
+ })($ || ($ = {}));
1881
+ //mol/mem/mem.ts
1882
+ ;
1883
+ "use strict";
1884
+ var $;
1885
+ (function ($) {
1886
+ function $mol_wire_sync(obj) {
1887
+ return new Proxy(obj, {
1888
+ get(obj, field) {
1889
+ const val = obj[field];
1890
+ if (typeof val !== 'function')
1891
+ return val;
1892
+ const temp = $mol_wire_task.getter(val);
1893
+ return function $mol_wire_sync(...args) {
1894
+ const fiber = temp(obj, args);
1895
+ return fiber.sync();
1933
1896
  };
1934
- handler[Symbol.toStringTag] = Class.name + '#';
1935
- return new Proxy(Class, handler);
1936
- };
1937
- }
1938
- static get method() {
1939
- return (obj, name, descr) => {
1940
- descr.value = this.func(descr.value);
1941
- return descr;
1942
- };
1943
- }
1944
- static get field() {
1945
- return (obj, name, descr) => {
1946
- descr.get = descr.set = this.func(descr.get);
1947
- return descr;
1948
- };
1949
- }
1897
+ },
1898
+ apply(obj, self, args) {
1899
+ const temp = $mol_wire_task.getter(obj);
1900
+ const fiber = temp(self, args);
1901
+ return fiber.sync();
1902
+ },
1903
+ });
1950
1904
  }
1951
- $.$mol_wrapper = $mol_wrapper;
1905
+ $.$mol_wire_sync = $mol_wire_sync;
1952
1906
  })($ || ($ = {}));
1953
- //mol/wrapper/wrapper.ts
1907
+ //mol/wire/sync/sync.ts
1954
1908
  ;
1955
1909
  "use strict";
1956
1910
  var $;
1957
1911
  (function ($) {
1958
- class $mol_memo extends $mol_wrapper {
1959
- static wrap(task) {
1960
- const store = new WeakMap();
1961
- return function (next) {
1962
- if (next === undefined && store.has(this))
1963
- return store.get(this);
1964
- const val = task.call(this, next) ?? next;
1965
- store.set(this, val);
1966
- return val;
1967
- };
1968
- }
1969
- }
1970
- $.$mol_memo = $mol_memo;
1971
1912
  })($ || ($ = {}));
1972
- //mol/memo/memo.ts
1913
+ //mol/dom/context/context.ts
1973
1914
  ;
1974
1915
  "use strict";
1975
- //mol/data/value/value.ts
1916
+ var $;
1917
+ (function ($) {
1918
+ $.$mol_dom_context = self;
1919
+ })($ || ($ = {}));
1920
+ //mol/dom/context/context.web.ts
1976
1921
  ;
1977
1922
  "use strict";
1978
1923
  var $;
1979
1924
  (function ($) {
1980
- function $mol_data_setup(value, config) {
1981
- return Object.assign(value, {
1982
- config,
1983
- Value: null
1984
- });
1925
+ function $mol_dom_render_children(el, childNodes) {
1926
+ const node_set = new Set(childNodes);
1927
+ let nextNode = el.firstChild;
1928
+ for (let view of childNodes) {
1929
+ if (view == null)
1930
+ continue;
1931
+ if (view instanceof $mol_dom_context.Node) {
1932
+ while (true) {
1933
+ if (!nextNode) {
1934
+ el.appendChild(view);
1935
+ break;
1936
+ }
1937
+ if (nextNode == view) {
1938
+ nextNode = nextNode.nextSibling;
1939
+ break;
1940
+ }
1941
+ else {
1942
+ if (node_set.has(nextNode)) {
1943
+ el.insertBefore(view, nextNode);
1944
+ break;
1945
+ }
1946
+ else {
1947
+ const nn = nextNode.nextSibling;
1948
+ el.removeChild(nextNode);
1949
+ nextNode = nn;
1950
+ }
1951
+ }
1952
+ }
1953
+ }
1954
+ else {
1955
+ if (nextNode && nextNode.nodeName === '#text') {
1956
+ const str = String(view);
1957
+ if (nextNode.nodeValue !== str)
1958
+ nextNode.nodeValue = str;
1959
+ nextNode = nextNode.nextSibling;
1960
+ }
1961
+ else {
1962
+ const textNode = $mol_dom_context.document.createTextNode(String(view));
1963
+ el.insertBefore(textNode, nextNode);
1964
+ }
1965
+ }
1966
+ }
1967
+ while (nextNode) {
1968
+ const currNode = nextNode;
1969
+ nextNode = currNode.nextSibling;
1970
+ el.removeChild(currNode);
1971
+ }
1985
1972
  }
1986
- $.$mol_data_setup = $mol_data_setup;
1973
+ $.$mol_dom_render_children = $mol_dom_render_children;
1987
1974
  })($ || ($ = {}));
1988
- //mol/data/setup/setup.ts
1975
+ //mol/dom/render/children/children.ts
1976
+ ;
1977
+ "use strict";
1978
+ //mol/type/partial/deep/deep.ts
1989
1979
  ;
1990
1980
  "use strict";
1991
1981
  var $;
1992
1982
  (function ($) {
1993
- function $mol_diff_path(...paths) {
1994
- const limit = Math.min(...paths.map(path => path.length));
1995
- lookup: for (var i = 0; i < limit; ++i) {
1996
- const first = paths[0][i];
1997
- for (let j = 1; j < paths.length; ++j) {
1998
- if (paths[j][i] !== first)
1999
- break lookup;
1983
+ $.$mol_jsx_prefix = '';
1984
+ $.$mol_jsx_crumbs = '';
1985
+ $.$mol_jsx_booked = null;
1986
+ $.$mol_jsx_document = {
1987
+ getElementById: () => null,
1988
+ createElementNS: (space, name) => $mol_dom_context.document.createElementNS(space, name),
1989
+ createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
1990
+ };
1991
+ $.$mol_jsx_frag = '';
1992
+ function $mol_jsx(Elem, props, ...childNodes) {
1993
+ const id = props && props.id || '';
1994
+ const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
1995
+ const crumbs_self = id ? $.$mol_jsx_crumbs.replace(/(\S+)/g, `$1_${id.replace(/\/.*/i, '')}`) : $.$mol_jsx_crumbs;
1996
+ if (Elem && $.$mol_jsx_booked) {
1997
+ if ($.$mol_jsx_booked.has(id)) {
1998
+ $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
1999
+ }
2000
+ else {
2001
+ $.$mol_jsx_booked.add(id);
2002
+ }
2003
+ }
2004
+ let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
2005
+ if ($.$mol_jsx_prefix) {
2006
+ const prefix_ext = $.$mol_jsx_prefix;
2007
+ const booked_ext = $.$mol_jsx_booked;
2008
+ const crumbs_ext = $.$mol_jsx_crumbs;
2009
+ for (const field in props) {
2010
+ const func = props[field];
2011
+ if (typeof func !== 'function')
2012
+ continue;
2013
+ const wrapper = function (...args) {
2014
+ const prefix = $.$mol_jsx_prefix;
2015
+ const booked = $.$mol_jsx_booked;
2016
+ const crumbs = $.$mol_jsx_crumbs;
2017
+ try {
2018
+ $.$mol_jsx_prefix = prefix_ext;
2019
+ $.$mol_jsx_booked = booked_ext;
2020
+ $.$mol_jsx_crumbs = crumbs_ext;
2021
+ return func.call(this, ...args);
2022
+ }
2023
+ finally {
2024
+ $.$mol_jsx_prefix = prefix;
2025
+ $.$mol_jsx_booked = booked;
2026
+ $.$mol_jsx_crumbs = crumbs;
2027
+ }
2028
+ };
2029
+ $mol_func_name_from(wrapper, func);
2030
+ props[field] = wrapper;
2000
2031
  }
2001
2032
  }
2002
- return {
2003
- prefix: paths[0].slice(0, i),
2004
- suffix: paths.map(path => path.slice(i)),
2005
- };
2006
- }
2007
- $.$mol_diff_path = $mol_diff_path;
2008
- })($ || ($ = {}));
2009
- //mol/diff/path/path.ts
2010
- ;
2011
- "use strict";
2012
- var $;
2013
- (function ($) {
2014
- class $mol_error_mix extends Error {
2015
- errors;
2016
- constructor(message, ...errors) {
2017
- super(message);
2018
- this.errors = errors;
2019
- if (errors.length) {
2020
- const stacks = [...errors.map(error => error.stack), this.stack];
2021
- const diff = $mol_diff_path(...stacks.map(stack => {
2022
- if (!stack)
2023
- return [];
2024
- return stack.split('\n').reverse();
2025
- }));
2026
- const head = diff.prefix.reverse().join('\n');
2027
- const tails = diff.suffix.map(path => path.reverse().map(line => line.replace(/^(?!\s+at)/, '\tat (.) ')).join('\n')).join('\n\tat (.) -----\n');
2028
- this.stack = `Error: ${this.constructor.name}\n\tat (.) /"""\\\n${tails}\n\tat (.) \\___/\n${head}`;
2029
- this.message += errors.map(error => '\n' + error.message).join('');
2033
+ if (typeof Elem !== 'string') {
2034
+ if ('prototype' in Elem) {
2035
+ const view = node && node[String(Elem)] || new Elem;
2036
+ Object.assign(view, props);
2037
+ view[Symbol.toStringTag] = guid;
2038
+ view.childNodes = childNodes;
2039
+ if (!view.ownerDocument)
2040
+ view.ownerDocument = $.$mol_jsx_document;
2041
+ view.className = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
2042
+ node = view.valueOf();
2043
+ node[String(Elem)] = view;
2044
+ return node;
2045
+ }
2046
+ else {
2047
+ const prefix = $.$mol_jsx_prefix;
2048
+ const booked = $.$mol_jsx_booked;
2049
+ const crumbs = $.$mol_jsx_crumbs;
2050
+ try {
2051
+ $.$mol_jsx_prefix = guid;
2052
+ $.$mol_jsx_booked = new Set;
2053
+ $.$mol_jsx_crumbs = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
2054
+ return Elem(props, ...childNodes);
2055
+ }
2056
+ finally {
2057
+ $.$mol_jsx_prefix = prefix;
2058
+ $.$mol_jsx_booked = booked;
2059
+ $.$mol_jsx_crumbs = crumbs;
2060
+ }
2030
2061
  }
2031
2062
  }
2032
- toJSON() {
2033
- return this.message;
2063
+ if (!node) {
2064
+ node = Elem
2065
+ ? $.$mol_jsx_document.createElementNS(props?.xmlns ?? 'http://www.w3.org/1999/xhtml', Elem)
2066
+ : $.$mol_jsx_document.createDocumentFragment();
2067
+ }
2068
+ $mol_dom_render_children(node, [].concat(...childNodes));
2069
+ if (!Elem)
2070
+ return node;
2071
+ if (guid)
2072
+ node.id = guid;
2073
+ for (const key in props) {
2074
+ if (key === 'id')
2075
+ continue;
2076
+ if (typeof props[key] === 'string') {
2077
+ if (typeof node[key] === 'string')
2078
+ node[key] = props[key];
2079
+ node.setAttribute(key, props[key]);
2080
+ }
2081
+ else if (props[key] &&
2082
+ typeof props[key] === 'object' &&
2083
+ Reflect.getPrototypeOf(props[key]) === Reflect.getPrototypeOf({})) {
2084
+ if (typeof node[key] === 'object') {
2085
+ Object.assign(node[key], props[key]);
2086
+ continue;
2087
+ }
2088
+ }
2089
+ else {
2090
+ node[key] = props[key];
2091
+ }
2034
2092
  }
2093
+ if ($.$mol_jsx_crumbs)
2094
+ node.className = (props?.['class'] ? props['class'] + ' ' : '') + crumbs_self;
2095
+ return node;
2035
2096
  }
2036
- $.$mol_error_mix = $mol_error_mix;
2097
+ $.$mol_jsx = $mol_jsx;
2037
2098
  })($ || ($ = {}));
2038
- //mol/error/mix/mix.ts
2099
+ //mol/jsx/jsx.ts
2039
2100
  ;
2040
2101
  "use strict";
2041
2102
  var $;
2042
- (function ($) {
2043
- class $mol_data_error extends $mol_error_mix {
2103
+ (function ($_1) {
2104
+ let $$;
2105
+ (function ($$) {
2106
+ let $;
2107
+ })($$ = $_1.$$ || ($_1.$$ = {}));
2108
+ $_1.$mol_object_field = Symbol('$mol_object_field');
2109
+ class $mol_object extends $mol_object2 {
2110
+ static make(config) {
2111
+ return super.create(obj => {
2112
+ for (let key in config)
2113
+ obj[key] = config[key];
2114
+ });
2115
+ }
2044
2116
  }
2045
- $.$mol_data_error = $mol_data_error;
2117
+ $_1.$mol_object = $mol_object;
2046
2118
  })($ || ($ = {}));
2047
- //mol/data/error/error.ts
2119
+ //mol/object/object.ts
2048
2120
  ;
2049
2121
  "use strict";
2050
2122
  var $;
2051
2123
  (function ($) {
2052
- function $mol_data_enum(name, dict) {
2053
- const index = {};
2054
- for (let key in dict) {
2055
- if (Number.isNaN(Number(key))) {
2056
- index[dict[key]] = key;
2124
+ class $mol_state_local extends $mol_object {
2125
+ static 'native()';
2126
+ static native() {
2127
+ if (this['native()'])
2128
+ return this['native()'];
2129
+ check: try {
2130
+ const native = $mol_dom_context.localStorage;
2131
+ if (!native)
2132
+ break check;
2133
+ native.setItem('', '');
2134
+ native.removeItem('');
2135
+ return this['native()'] = native;
2057
2136
  }
2058
- }
2059
- return $mol_data_setup((value) => {
2060
- if (typeof index[value] !== 'string') {
2061
- return $mol_fail(new $mol_data_error(`${value} is not value of ${name} enum`));
2137
+ catch (error) {
2138
+ console.warn(error);
2062
2139
  }
2063
- return value;
2064
- }, { name, dict });
2140
+ return this['native()'] = {
2141
+ getItem(key) {
2142
+ return this[':' + key];
2143
+ },
2144
+ setItem(key, value) {
2145
+ this[':' + key] = value;
2146
+ },
2147
+ removeItem(key) {
2148
+ this[':' + key] = void 0;
2149
+ }
2150
+ };
2151
+ }
2152
+ static changes(next) { return next; }
2153
+ static value(key, next) {
2154
+ this.changes();
2155
+ if (next === void 0)
2156
+ return JSON.parse(this.native().getItem(key) || 'null');
2157
+ if (next === null)
2158
+ this.native().removeItem(key);
2159
+ else
2160
+ this.native().setItem(key, JSON.stringify(next));
2161
+ return next;
2162
+ }
2163
+ prefix() { return ''; }
2164
+ value(key, next) {
2165
+ return $mol_state_local.value(this.prefix() + '.' + key, next);
2166
+ }
2065
2167
  }
2066
- $.$mol_data_enum = $mol_data_enum;
2168
+ __decorate([
2169
+ $mol_mem
2170
+ ], $mol_state_local, "changes", null);
2171
+ __decorate([
2172
+ $mol_mem_key
2173
+ ], $mol_state_local, "value", null);
2174
+ $.$mol_state_local = $mol_state_local;
2067
2175
  })($ || ($ = {}));
2068
- //mol/data/enum/enum.ts
2069
- ;
2070
- "use strict";
2071
- //mol/charset/encoding/encoding.ts
2176
+ //mol/state/local/local.ts
2072
2177
  ;
2073
2178
  "use strict";
2074
2179
  var $;
2075
2180
  (function ($) {
2076
- const decoders = {};
2077
- function $mol_charset_decode(buffer, encoding = 'utf8') {
2078
- let decoder = decoders[encoding];
2079
- if (!decoder)
2080
- decoder = decoders[encoding] = new TextDecoder(encoding);
2081
- return decoder.decode(buffer);
2082
- }
2083
- $.$mol_charset_decode = $mol_charset_decode;
2181
+ self.addEventListener('storage', event => $.$mol_state_local.changes(event));
2084
2182
  })($ || ($ = {}));
2085
- //mol/charset/decode/decode.ts
2183
+ //mol/state/local/local.web.ts
2086
2184
  ;
2087
- "use strict";
2088
- var $;
2089
- (function ($) {
2090
- const level = $mol_data_enum('level', $hyoo_crowd_peer_level);
2091
- let $hyoo_crowd_unit_kind;
2092
- (function ($hyoo_crowd_unit_kind) {
2093
- $hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["grab"] = 0] = "grab";
2094
- $hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["join"] = 1] = "join";
2095
- $hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["give"] = 2] = "give";
2096
- $hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["data"] = 3] = "data";
2097
- })($hyoo_crowd_unit_kind = $.$hyoo_crowd_unit_kind || ($.$hyoo_crowd_unit_kind = {}));
2098
- let $hyoo_crowd_unit_group;
2099
- (function ($hyoo_crowd_unit_group) {
2100
- $hyoo_crowd_unit_group[$hyoo_crowd_unit_group["auth"] = 0] = "auth";
2101
- $hyoo_crowd_unit_group[$hyoo_crowd_unit_group["data"] = 1] = "data";
2102
- })($hyoo_crowd_unit_group = $.$hyoo_crowd_unit_group || ($.$hyoo_crowd_unit_group = {}));
2103
- class $hyoo_crowd_unit extends Object {
2104
- land;
2105
- auth;
2106
- head;
2107
- self;
2108
- next;
2109
- prev;
2110
- time;
2111
- data;
2112
- bin;
2113
- constructor(land, auth, head, self, next, prev, time, data, bin) {
2114
- super();
2115
- this.land = land;
2116
- this.auth = auth;
2117
- this.head = head;
2118
- this.self = self;
2119
- this.next = next;
2120
- this.prev = prev;
2121
- this.time = time;
2122
- this.data = data;
2123
- this.bin = bin;
2124
- }
2125
- kind() {
2126
- if (this.head === this.self && this.auth === this.self) {
2127
- if (this.head === this.land) {
2128
- return $hyoo_crowd_unit_kind.grab;
2129
- }
2130
- else {
2131
- return $hyoo_crowd_unit_kind.join;
2132
- }
2133
- }
2134
- if (this.head === this.land) {
2135
- return $hyoo_crowd_unit_kind.give;
2136
- }
2137
- return $hyoo_crowd_unit_kind.data;
2138
- }
2139
- group() {
2140
- return this.kind() === $hyoo_crowd_unit_kind.data
2141
- ? $hyoo_crowd_unit_group.data
2142
- : $hyoo_crowd_unit_group.auth;
2143
- }
2144
- level() {
2145
- switch (this.kind()) {
2146
- case $hyoo_crowd_unit_kind.grab: return $hyoo_crowd_peer_level.law;
2147
- case $hyoo_crowd_unit_kind.give: return level(this.data);
2148
- default: $mol_fail(new Error(`Wrong unit kind for getting level: ${this.kind()}`));
2149
- }
2150
- }
2151
- [Symbol.toPrimitive]() {
2152
- return JSON.stringify(this);
2185
+ "use strict";
2186
+ var $;
2187
+ (function ($) {
2188
+ async function $hyoo_sync_peer(path) {
2189
+ let serial = $mol_state_local.value('$hyoo_sync_peer');
2190
+ if (typeof serial === 'string') {
2191
+ return await $hyoo_crowd_peer.restore(serial);
2153
2192
  }
2154
- [$mol_dev_format_head]() {
2155
- switch (this.kind()) {
2156
- case $hyoo_crowd_unit_kind.grab:
2157
- return $mol_dev_format_div({}, $mol_dev_format_native(this), ' 👑');
2158
- case $hyoo_crowd_unit_kind.join:
2159
- return $mol_dev_format_div({}, $mol_dev_format_native(this), $mol_dev_format_shade(' 🔑 ', this.self));
2160
- case $hyoo_crowd_unit_kind.give:
2161
- return $mol_dev_format_div({}, $mol_dev_format_native(this), $mol_dev_format_shade(' 🏅 ', this.self, ' '), $mol_dev_format_native($hyoo_crowd_peer_level[this.data] ?? this.data));
2162
- case $hyoo_crowd_unit_kind.data:
2163
- return $mol_dev_format_div({}, $mol_dev_format_native(this), $mol_dev_format_shade(' 📦 ', this.head, '!', this.self, ' '), $mol_dev_format_native(this.data));
2193
+ else {
2194
+ serial = $mol_state_local.value(path);
2195
+ if (typeof serial === 'string') {
2196
+ $mol_state_local.value('$hyoo_sync_peer', serial);
2197
+ $mol_state_local.value(path, null);
2164
2198
  }
2165
2199
  }
2200
+ const frame = $mol_jsx("iframe", { src: "https://sync.hyoo.ru/auth/" });
2201
+ frame.style.display = 'none';
2202
+ await new Promise((done, fail) => {
2203
+ frame.onload = done;
2204
+ frame.onerror = fail;
2205
+ frame.onabort = fail;
2206
+ document.body.appendChild(frame);
2207
+ });
2208
+ const serial_ext = await new Promise((done, fail) => {
2209
+ window.addEventListener('message', event => {
2210
+ if (!Array.isArray(event.data))
2211
+ return;
2212
+ if (event.data[0] !== '$hyoo_sync_peer')
2213
+ return;
2214
+ done(event.data[1]);
2215
+ });
2216
+ frame.contentWindow.postMessage(['$hyoo_sync_peer', serial], '*');
2217
+ setTimeout(() => done(serial), 5000);
2218
+ });
2219
+ document.body.removeChild(frame);
2220
+ if (typeof serial_ext === 'string') {
2221
+ if (!serial)
2222
+ $mol_state_local.value('$hyoo_sync_peer', serial_ext);
2223
+ return await $hyoo_crowd_peer.restore(serial_ext);
2224
+ }
2225
+ const peer = await $hyoo_crowd_peer.generate();
2226
+ $mol_state_local.value('$hyoo_sync_peer', peer.key_private_serial);
2227
+ return peer;
2166
2228
  }
2167
- $.$hyoo_crowd_unit = $hyoo_crowd_unit;
2168
- const offset = {
2169
- land_lo: 0,
2170
- land_hi: 4,
2171
- auth_lo: 8,
2172
- auth_hi: 12,
2173
- head_lo: 16,
2174
- head_hi: 20,
2175
- self_lo: 24,
2176
- self_hi: 28,
2177
- next_lo: 32,
2178
- next_hi: 36,
2179
- prev_lo: 40,
2180
- prev_hi: 44,
2181
- time: 48,
2182
- size: 54,
2183
- data: 56,
2184
- };
2185
- class $hyoo_crowd_unit_bin extends DataView {
2186
- static from_buffer(buffer) {
2187
- const size = Math.ceil(Math.abs(buffer[offset.size / 2]) / 8) * 8 + offset.data + $mol_crypto_auditor_sign_size;
2188
- return new this(buffer.slice(0, size / 2).buffer);
2229
+ $.$hyoo_sync_peer = $hyoo_sync_peer;
2230
+ })($ || ($ = {}));
2231
+ //hyoo/sync/peer/peer.web.tsx
2232
+ ;
2233
+ "use strict";
2234
+ var $;
2235
+ (function ($) {
2236
+ function $mol_wire_solid() {
2237
+ const current = $mol_wire_auto();
2238
+ if (current.reap !== nothing) {
2239
+ current?.sub_on(sub, sub.data.length);
2189
2240
  }
2190
- static from_unit(unit) {
2191
- if (unit.bin)
2192
- return unit.bin;
2193
- const type = unit.data === null
2194
- ? 0
2195
- : unit.data instanceof Uint8Array
2196
- ? -1
2197
- : 1;
2198
- const buff = type === 0 ? null
2199
- : type > 0 ? $mol_charset_encode(JSON.stringify(unit.data))
2200
- : unit.data;
2201
- const size = buff?.byteLength ?? 0;
2202
- if (type > 0 && size > 2 ** 15 - 1)
2203
- throw new Error(`Too large json data: ${size} > ${2 ** 15 - 1}`);
2204
- if (type < 0 && size > 2 ** 15)
2205
- throw new Error(`Too large binary data: ${size} > ${2 ** 15}`);
2206
- const total = offset.data + Math.ceil(size / 8) * 8 + $mol_crypto_auditor_sign_size;
2207
- const mem = new Uint8Array(total);
2208
- const bin = new $hyoo_crowd_unit_bin(mem.buffer);
2209
- const land = $mol_int62_from_string(unit.land);
2210
- bin.setInt32(offset.land_lo, land.lo, true);
2211
- bin.setInt32(offset.land_hi, land.hi, true);
2212
- const auth = $mol_int62_from_string(unit.auth);
2213
- bin.setInt32(offset.auth_lo, auth.lo, true);
2214
- bin.setInt32(offset.auth_hi, auth.hi, true);
2215
- const head = $mol_int62_from_string(unit.head);
2216
- bin.setInt32(offset.head_lo, head.lo, true);
2217
- bin.setInt32(offset.head_hi, head.hi, true);
2218
- const self = $mol_int62_from_string(unit.self);
2219
- bin.setInt32(offset.self_lo, self.lo, true);
2220
- bin.setInt32(offset.self_hi, self.hi, true);
2221
- const next = $mol_int62_from_string(unit.next);
2222
- bin.setInt32(offset.next_lo, next.lo, true);
2223
- bin.setInt32(offset.next_hi, next.hi, true);
2224
- const prev = $mol_int62_from_string(unit.prev);
2225
- bin.setInt32(offset.prev_lo, prev.lo, true);
2226
- bin.setInt32(offset.prev_hi, prev.hi, true);
2227
- bin.setInt32(offset.time, unit.time, true);
2228
- bin.setInt16(offset.size, type * size, true);
2229
- if (buff)
2230
- mem.set(buff, offset.data);
2231
- return bin;
2241
+ current.reap = nothing;
2242
+ }
2243
+ $.$mol_wire_solid = $mol_wire_solid;
2244
+ const nothing = () => { };
2245
+ const sub = new $mol_wire_pub_sub;
2246
+ })($ || ($ = {}));
2247
+ //mol/wire/solid/solid.ts
2248
+ ;
2249
+ "use strict";
2250
+ var $;
2251
+ (function ($) {
2252
+ class $mol_wrapper extends $mol_object2 {
2253
+ static wrap;
2254
+ static run(task) {
2255
+ return this.func(task)();
2232
2256
  }
2233
- sign(next) {
2234
- const sign_offset = this.byteOffset + this.byteLength - $mol_crypto_auditor_sign_size;
2235
- const buff = new Uint8Array(this.buffer, sign_offset, $mol_crypto_auditor_sign_size);
2236
- if (!next)
2237
- return buff;
2238
- buff.set(next);
2239
- return buff;
2257
+ static func(func) {
2258
+ return this.wrap(func);
2240
2259
  }
2241
- size() {
2242
- return Math.ceil(Math.abs(this.getInt16(offset.size, true)) / 8) * 8 + offset.data + $mol_crypto_auditor_sign_size;
2260
+ static get class() {
2261
+ return (Class) => {
2262
+ const construct = (target, args) => new Class(...args);
2263
+ const handler = {
2264
+ construct: this.func(construct)
2265
+ };
2266
+ handler[Symbol.toStringTag] = Class.name + '#';
2267
+ return new Proxy(Class, handler);
2268
+ };
2243
2269
  }
2244
- sens() {
2245
- return new Uint8Array(this.buffer, this.byteOffset, this.size() - $mol_crypto_auditor_sign_size);
2270
+ static get method() {
2271
+ return (obj, name, descr) => {
2272
+ descr.value = this.func(descr.value);
2273
+ return descr;
2274
+ };
2246
2275
  }
2247
- unit() {
2248
- const land = $mol_int62_to_string({
2249
- lo: this.getInt32(offset.land_lo, true) << 1 >> 1,
2250
- hi: this.getInt32(offset.land_hi, true) << 1 >> 1,
2251
- });
2252
- const auth = $mol_int62_to_string({
2253
- lo: this.getInt32(offset.auth_lo, true) << 1 >> 1,
2254
- hi: this.getInt32(offset.auth_hi, true) << 1 >> 1,
2255
- });
2256
- const head = $mol_int62_to_string({
2257
- lo: this.getInt32(offset.head_lo, true) << 1 >> 1,
2258
- hi: this.getInt32(offset.head_hi, true) << 1 >> 1,
2259
- });
2260
- const self = $mol_int62_to_string({
2261
- lo: this.getInt32(offset.self_lo, true) << 1 >> 1,
2262
- hi: this.getInt32(offset.self_hi, true) << 1 >> 1,
2263
- });
2264
- const next = $mol_int62_to_string({
2265
- lo: this.getInt32(offset.next_lo, true) << 1 >> 1,
2266
- hi: this.getInt32(offset.next_hi, true) << 1 >> 1,
2267
- });
2268
- const prev = $mol_int62_to_string({
2269
- lo: this.getInt32(offset.prev_lo, true) << 1 >> 1,
2270
- hi: this.getInt32(offset.prev_hi, true) << 1 >> 1,
2271
- });
2272
- const time = this.getInt32(offset.time, true) << 1 >> 1;
2273
- const type_size = this.getInt16(offset.size, true);
2274
- let data = null;
2275
- if (type_size) {
2276
- try {
2277
- var buff = new Uint8Array(this.buffer, this.byteOffset + offset.data, Math.abs(type_size));
2278
- }
2279
- catch (error) {
2280
- error['message'] += `\nhead=${head};self=${self}`;
2281
- $mol_fail_hidden(error);
2282
- }
2283
- if (type_size < 0)
2284
- data = buff;
2285
- else
2286
- data = JSON.parse($mol_charset_decode(buff));
2287
- }
2288
- return new $hyoo_crowd_unit(land, auth, head, self, next, prev, time, data, this);
2276
+ static get field() {
2277
+ return (obj, name, descr) => {
2278
+ descr.get = descr.set = this.func(descr.get);
2279
+ return descr;
2280
+ };
2289
2281
  }
2290
2282
  }
2291
- $.$hyoo_crowd_unit_bin = $hyoo_crowd_unit_bin;
2292
- function $hyoo_crowd_unit_compare(left, right) {
2293
- return (left.group() - right.group())
2294
- || (left.time - right.time)
2295
- || ((left.auth > right.auth) ? 1 : (left.auth < right.auth) ? -1 : 0)
2296
- || ((left.self > right.self) ? 1 : (left.self < right.self) ? -1 : 0)
2297
- || ((left.head > right.head) ? 1 : (left.head < right.head) ? -1 : 0)
2298
- || ((left.prev > right.prev) ? 1 : (left.prev < right.prev) ? -1 : 0)
2299
- || ((left.next > right.next) ? 1 : (left.next < right.next) ? -1 : 0)
2300
- || ((left.land > right.land) ? 1 : (left.land < right.land) ? -1 : 0);
2283
+ $.$mol_wrapper = $mol_wrapper;
2284
+ })($ || ($ = {}));
2285
+ //mol/wrapper/wrapper.ts
2286
+ ;
2287
+ "use strict";
2288
+ var $;
2289
+ (function ($) {
2290
+ class $mol_memo extends $mol_wrapper {
2291
+ static wrap(task) {
2292
+ const store = new WeakMap();
2293
+ return function (next) {
2294
+ if (next === undefined && store.has(this))
2295
+ return store.get(this);
2296
+ const val = task.call(this, next) ?? next;
2297
+ store.set(this, val);
2298
+ return val;
2299
+ };
2300
+ }
2301
2301
  }
2302
- $.$hyoo_crowd_unit_compare = $hyoo_crowd_unit_compare;
2302
+ $.$mol_memo = $mol_memo;
2303
2303
  })($ || ($ = {}));
2304
- //hyoo/crowd/unit/unit.ts
2304
+ //mol/memo/memo.ts
2305
2305
  ;
2306
2306
  "use strict";
2307
2307
  var $;
@@ -2390,16 +2390,18 @@ var $;
2390
2390
  const offset = {
2391
2391
  land_lo: 0,
2392
2392
  land_hi: 4,
2393
- clocks: 8,
2393
+ count: 8,
2394
+ clocks: 16,
2394
2395
  };
2395
2396
  class $hyoo_crowd_clock_bin extends DataView {
2396
- static from(land_id, clocks) {
2397
+ static from(land_id, clocks, count) {
2397
2398
  const size = offset.clocks + clocks[0].size * 16;
2398
2399
  const mem = new Uint8Array(size);
2399
2400
  const bin = new $hyoo_crowd_clock_bin(mem.buffer);
2400
2401
  const land = $mol_int62_from_string(land_id);
2401
2402
  bin.setInt32(offset.land_lo, land.lo ^ (1 << 31), true);
2402
2403
  bin.setInt32(offset.land_hi, land.hi, true);
2404
+ bin.setInt32(offset.count, count, true);
2403
2405
  let cursor = offset.clocks;
2404
2406
  for (const [peer_id, time] of clocks[0]) {
2405
2407
  const peer = $mol_int62_from_string(peer_id);
@@ -2417,6 +2419,9 @@ var $;
2417
2419
  hi: this.getInt32(offset.land_hi, true) << 1 >> 1,
2418
2420
  });
2419
2421
  }
2422
+ count() {
2423
+ return this.getInt32(offset.count, true);
2424
+ }
2420
2425
  }
2421
2426
  $.$hyoo_crowd_clock_bin = $hyoo_crowd_clock_bin;
2422
2427
  })($ || ($ = {}));
@@ -2482,7 +2487,7 @@ var $;
2482
2487
  (function ($) {
2483
2488
  class $hyoo_crowd_reg extends $hyoo_crowd_node {
2484
2489
  value(next) {
2485
- const unit = this.units()[0];
2490
+ const unit = this.units().at(-1);
2486
2491
  if (next === undefined)
2487
2492
  return unit?.data ?? null;
2488
2493
  if ($mol_compare_deep(unit?.data, next))
@@ -2578,7 +2583,7 @@ var $;
2578
2583
  return this._clocks;
2579
2584
  }
2580
2585
  get clocks_bin() {
2581
- return new Uint8Array($hyoo_crowd_clock_bin.from(this.id(), this._clocks).buffer);
2586
+ return new Uint8Array($hyoo_crowd_clock_bin.from(this.id(), this._clocks, this._unit_all.size).buffer);
2582
2587
  }
2583
2588
  pub = new $mol_wire_pub;
2584
2589
  _clocks = [new $hyoo_crowd_clock, new $hyoo_crowd_clock];
@@ -3404,6 +3409,7 @@ var $;
3404
3409
  var $;
3405
3410
  (function ($) {
3406
3411
  class $hyoo_sync_yard extends $mol_object2 {
3412
+ db_unit_persisted = new WeakSet();
3407
3413
  log_pack(data) {
3408
3414
  return data;
3409
3415
  }
@@ -3502,16 +3508,19 @@ var $;
3502
3508
  }
3503
3509
  db_land_sync(land) {
3504
3510
  this.db_land_init(land);
3505
- const db_clocks = this.db_land_clocks(land.id());
3506
3511
  land.clocks;
3507
- const units = land.delta(db_clocks);
3512
+ const units = [];
3513
+ for (const unit of land._unit_all.values()) {
3514
+ if (this.db_unit_persisted.has(unit))
3515
+ continue;
3516
+ units.push(unit);
3517
+ }
3508
3518
  if (!units.length)
3509
3519
  return;
3510
3520
  $mol_wire_sync(this.world()).sign_units(units);
3511
3521
  $mol_wire_sync(this).db_land_save(land, units);
3512
- for (const unit of units) {
3513
- db_clocks[unit.group()].see_peer(unit.auth, unit.time);
3514
- }
3522
+ for (const unit of units)
3523
+ this.db_unit_persisted.add(unit);
3515
3524
  }
3516
3525
  db_land_init(land) {
3517
3526
  try {
@@ -3527,13 +3536,10 @@ var $;
3527
3536
  });
3528
3537
  units = [];
3529
3538
  }
3539
+ for (const unit of units)
3540
+ this.db_unit_persisted.add(unit);
3530
3541
  units.sort($hyoo_crowd_unit_compare);
3531
- const clocks = [new $hyoo_crowd_clock, new $hyoo_crowd_clock];
3532
- this.db_land_clocks(land.id(), clocks);
3533
3542
  land.apply(units);
3534
- for (const unit of units) {
3535
- clocks[unit.group()].see_peer(unit.auth, unit.time);
3536
- }
3537
3543
  }
3538
3544
  async db_land_load(land) {
3539
3545
  return [];
@@ -3619,6 +3625,9 @@ var $;
3619
3625
  for (let group = 0; group < clocks.length; ++group) {
3620
3626
  clocks[group].see_bin(bin, group);
3621
3627
  }
3628
+ if (bin.count() + land.delta(clocks).length < land._unit_all.size) {
3629
+ this.line_land_clocks({ line, land }, clocks = [new $hyoo_crowd_clock, new $hyoo_crowd_clock]);
3630
+ }
3622
3631
  const lands = this.line_lands(line);
3623
3632
  if (lands.includes(land)) {
3624
3633
  this.$.$mol_log3_warn({
@@ -4030,7 +4039,7 @@ var $;
4030
4039
  master() {
4031
4040
  this.reconnects();
4032
4041
  const link = this.master_link();
4033
- const line = new $mol_dom_context.WebSocket(link, ['$hyoo_sync']);
4042
+ const line = new $mol_dom_context.WebSocket(link, ['$hyoo_sync_protocol_1']);
4034
4043
  line.binaryType = 'arraybuffer';
4035
4044
  line.onmessage = async (event) => {
4036
4045
  if (event.data instanceof ArrayBuffer) {