mol_view_tree2_lib 1.0.36 → 1.0.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/node.mjs CHANGED
@@ -199,7 +199,7 @@ var $;
199
199
  if (this[$mol_ambient_ref])
200
200
  return this[$mol_ambient_ref];
201
201
  const owner = $mol_owning_get(this);
202
- return this[$mol_ambient_ref] = owner?.$ || $mol_object2.$;
202
+ return this[$mol_ambient_ref] = owner?.$ || this.constructor.$ || $mol_object2.$;
203
203
  }
204
204
  set $(next) {
205
205
  if (this[$mol_ambient_ref])
@@ -4326,12 +4326,41 @@ var $;
4326
4326
  "use strict";
4327
4327
  var $;
4328
4328
  (function ($) {
4329
- const TextEncoder = globalThis.TextEncoder ?? $node.util.TextEncoder;
4330
- const encoder = new TextEncoder();
4331
- function $mol_charset_encode(value) {
4332
- return encoder.encode(value);
4329
+ let buf = new Uint8Array(2 ** 12);
4330
+ function $mol_charset_encode(str) {
4331
+ const capacity = str.length * 3;
4332
+ if (buf.byteLength < capacity)
4333
+ buf = new Uint8Array(capacity);
4334
+ return buf.slice(0, $mol_charset_encode_to(str, buf));
4333
4335
  }
4334
4336
  $.$mol_charset_encode = $mol_charset_encode;
4337
+ function $mol_charset_encode_to(str, buf, from = 0) {
4338
+ let pos = from;
4339
+ for (let i = 0; i < str.length; i++) {
4340
+ let code = str.charCodeAt(i);
4341
+ if (code < 0x80) {
4342
+ buf[pos++] = code;
4343
+ }
4344
+ else if (code < 0x800) {
4345
+ buf[pos++] = 0xc0 | (code >> 6);
4346
+ buf[pos++] = 0x80 | (code & 0x3f);
4347
+ }
4348
+ else if (code < 0xd800 || code >= 0xe000) {
4349
+ buf[pos++] = 0xe0 | (code >> 12);
4350
+ buf[pos++] = 0x80 | ((code >> 6) & 0x3f);
4351
+ buf[pos++] = 0x80 | (code & 0x3f);
4352
+ }
4353
+ else {
4354
+ const point = ((code - 0xd800) << 10) + str.charCodeAt(++i) + 0x2400;
4355
+ buf[pos++] = 0xf0 | (point >> 18);
4356
+ buf[pos++] = 0x80 | ((point >> 12) & 0x3f);
4357
+ buf[pos++] = 0x80 | ((point >> 6) & 0x3f);
4358
+ buf[pos++] = 0x80 | (point & 0x3f);
4359
+ }
4360
+ }
4361
+ return pos - from;
4362
+ }
4363
+ $.$mol_charset_encode_to = $mol_charset_encode_to;
4335
4364
  })($ || ($ = {}));
4336
4365
 
4337
4366
  ;
package/node.test.js CHANGED
@@ -190,7 +190,7 @@ var $;
190
190
  if (this[$mol_ambient_ref])
191
191
  return this[$mol_ambient_ref];
192
192
  const owner = $mol_owning_get(this);
193
- return this[$mol_ambient_ref] = owner?.$ || $mol_object2.$;
193
+ return this[$mol_ambient_ref] = owner?.$ || this.constructor.$ || $mol_object2.$;
194
194
  }
195
195
  set $(next) {
196
196
  if (this[$mol_ambient_ref])
@@ -4317,12 +4317,41 @@ var $;
4317
4317
  "use strict";
4318
4318
  var $;
4319
4319
  (function ($) {
4320
- const TextEncoder = globalThis.TextEncoder ?? $node.util.TextEncoder;
4321
- const encoder = new TextEncoder();
4322
- function $mol_charset_encode(value) {
4323
- return encoder.encode(value);
4320
+ let buf = new Uint8Array(2 ** 12);
4321
+ function $mol_charset_encode(str) {
4322
+ const capacity = str.length * 3;
4323
+ if (buf.byteLength < capacity)
4324
+ buf = new Uint8Array(capacity);
4325
+ return buf.slice(0, $mol_charset_encode_to(str, buf));
4324
4326
  }
4325
4327
  $.$mol_charset_encode = $mol_charset_encode;
4328
+ function $mol_charset_encode_to(str, buf, from = 0) {
4329
+ let pos = from;
4330
+ for (let i = 0; i < str.length; i++) {
4331
+ let code = str.charCodeAt(i);
4332
+ if (code < 0x80) {
4333
+ buf[pos++] = code;
4334
+ }
4335
+ else if (code < 0x800) {
4336
+ buf[pos++] = 0xc0 | (code >> 6);
4337
+ buf[pos++] = 0x80 | (code & 0x3f);
4338
+ }
4339
+ else if (code < 0xd800 || code >= 0xe000) {
4340
+ buf[pos++] = 0xe0 | (code >> 12);
4341
+ buf[pos++] = 0x80 | ((code >> 6) & 0x3f);
4342
+ buf[pos++] = 0x80 | (code & 0x3f);
4343
+ }
4344
+ else {
4345
+ const point = ((code - 0xd800) << 10) + str.charCodeAt(++i) + 0x2400;
4346
+ buf[pos++] = 0xf0 | (point >> 18);
4347
+ buf[pos++] = 0x80 | ((point >> 12) & 0x3f);
4348
+ buf[pos++] = 0x80 | ((point >> 6) & 0x3f);
4349
+ buf[pos++] = 0x80 | (point & 0x3f);
4350
+ }
4351
+ }
4352
+ return pos - from;
4353
+ }
4354
+ $.$mol_charset_encode_to = $mol_charset_encode_to;
4326
4355
  })($ || ($ = {}));
4327
4356
 
4328
4357
  ;
@@ -6432,7 +6461,7 @@ var $;
6432
6461
  ;
6433
6462
  "use strict";
6434
6463
  var $;
6435
- (function ($) {
6464
+ (function ($_1) {
6436
6465
  $mol_test({
6437
6466
  'init with overload'() {
6438
6467
  class X extends $mol_object {
@@ -6445,6 +6474,13 @@ var $;
6445
6474
  });
6446
6475
  $mol_assert_equal(x.foo(), 2);
6447
6476
  },
6477
+ 'Context in instance inherits from class'($) {
6478
+ const custom = $.$mol_ambient({});
6479
+ class X extends $.$mol_object {
6480
+ static $ = custom;
6481
+ }
6482
+ $mol_assert_equal(new X().$, custom);
6483
+ },
6448
6484
  });
6449
6485
  })($ || ($ = {}));
6450
6486
 
@@ -9157,10 +9193,23 @@ var $;
9157
9193
  var $;
9158
9194
  (function ($) {
9159
9195
  $mol_test({
9160
- 'encode utf8 string'() {
9161
- const str = 'Hello, ΧΨΩЫ';
9162
- const encoded = new Uint8Array([72, 101, 108, 108, 111, 44, 32, 206, 167, 206, 168, 206, 169, 208, 171]);
9163
- $mol_assert_like($mol_charset_encode(str), encoded);
9196
+ 'encode empty'() {
9197
+ $mol_assert_equal($mol_charset_encode(''), new Uint8Array([]));
9198
+ },
9199
+ 'encode 1 octet'() {
9200
+ $mol_assert_equal($mol_charset_encode('F'), new Uint8Array([0x46]));
9201
+ },
9202
+ 'encode 2 octet'() {
9203
+ $mol_assert_equal($mol_charset_encode('Б'), new Uint8Array([0xd0, 0x91]));
9204
+ },
9205
+ 'encode 3 octet'() {
9206
+ $mol_assert_equal($mol_charset_encode('ह'), new Uint8Array([0xe0, 0xa4, 0xb9]));
9207
+ },
9208
+ 'encode 4 octet'() {
9209
+ $mol_assert_equal($mol_charset_encode('𐍈'), new Uint8Array([0xf0, 0x90, 0x8d, 0x88]));
9210
+ },
9211
+ 'encode surrogate pair'() {
9212
+ $mol_assert_equal($mol_charset_encode('😀'), new Uint8Array([0xf0, 0x9f, 0x98, 0x80]));
9164
9213
  },
9165
9214
  });
9166
9215
  })($ || ($ = {}));