mol_plot_all 1.2.1550 → 1.2.1552

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
@@ -3088,12 +3088,41 @@ var $;
3088
3088
  "use strict";
3089
3089
  var $;
3090
3090
  (function ($) {
3091
- const TextEncoder = globalThis.TextEncoder ?? $node.util.TextEncoder;
3092
- const encoder = new TextEncoder();
3093
- function $mol_charset_encode(value) {
3094
- return encoder.encode(value);
3091
+ let buf = new Uint8Array(2 ** 12);
3092
+ function $mol_charset_encode(str) {
3093
+ const capacity = str.length * 3;
3094
+ if (buf.byteLength < capacity)
3095
+ buf = new Uint8Array(capacity);
3096
+ return buf.slice(0, $mol_charset_encode_to(str, buf));
3095
3097
  }
3096
3098
  $.$mol_charset_encode = $mol_charset_encode;
3099
+ function $mol_charset_encode_to(str, buf, from = 0) {
3100
+ let pos = from;
3101
+ for (let i = 0; i < str.length; i++) {
3102
+ let code = str.charCodeAt(i);
3103
+ if (code < 0x80) {
3104
+ buf[pos++] = code;
3105
+ }
3106
+ else if (code < 0x800) {
3107
+ buf[pos++] = 0xc0 | (code >> 6);
3108
+ buf[pos++] = 0x80 | (code & 0x3f);
3109
+ }
3110
+ else if (code < 0xd800 || code >= 0xe000) {
3111
+ buf[pos++] = 0xe0 | (code >> 12);
3112
+ buf[pos++] = 0x80 | ((code >> 6) & 0x3f);
3113
+ buf[pos++] = 0x80 | (code & 0x3f);
3114
+ }
3115
+ else {
3116
+ const point = ((code - 0xd800) << 10) + str.charCodeAt(++i) + 0x2400;
3117
+ buf[pos++] = 0xf0 | (point >> 18);
3118
+ buf[pos++] = 0x80 | ((point >> 12) & 0x3f);
3119
+ buf[pos++] = 0x80 | ((point >> 6) & 0x3f);
3120
+ buf[pos++] = 0x80 | (point & 0x3f);
3121
+ }
3122
+ }
3123
+ return pos - from;
3124
+ }
3125
+ $.$mol_charset_encode_to = $mol_charset_encode_to;
3097
3126
  })($ || ($ = {}));
3098
3127
 
3099
3128
  ;
package/node.test.js CHANGED
@@ -3079,12 +3079,41 @@ var $;
3079
3079
  "use strict";
3080
3080
  var $;
3081
3081
  (function ($) {
3082
- const TextEncoder = globalThis.TextEncoder ?? $node.util.TextEncoder;
3083
- const encoder = new TextEncoder();
3084
- function $mol_charset_encode(value) {
3085
- return encoder.encode(value);
3082
+ let buf = new Uint8Array(2 ** 12);
3083
+ function $mol_charset_encode(str) {
3084
+ const capacity = str.length * 3;
3085
+ if (buf.byteLength < capacity)
3086
+ buf = new Uint8Array(capacity);
3087
+ return buf.slice(0, $mol_charset_encode_to(str, buf));
3086
3088
  }
3087
3089
  $.$mol_charset_encode = $mol_charset_encode;
3090
+ function $mol_charset_encode_to(str, buf, from = 0) {
3091
+ let pos = from;
3092
+ for (let i = 0; i < str.length; i++) {
3093
+ let code = str.charCodeAt(i);
3094
+ if (code < 0x80) {
3095
+ buf[pos++] = code;
3096
+ }
3097
+ else if (code < 0x800) {
3098
+ buf[pos++] = 0xc0 | (code >> 6);
3099
+ buf[pos++] = 0x80 | (code & 0x3f);
3100
+ }
3101
+ else if (code < 0xd800 || code >= 0xe000) {
3102
+ buf[pos++] = 0xe0 | (code >> 12);
3103
+ buf[pos++] = 0x80 | ((code >> 6) & 0x3f);
3104
+ buf[pos++] = 0x80 | (code & 0x3f);
3105
+ }
3106
+ else {
3107
+ const point = ((code - 0xd800) << 10) + str.charCodeAt(++i) + 0x2400;
3108
+ buf[pos++] = 0xf0 | (point >> 18);
3109
+ buf[pos++] = 0x80 | ((point >> 12) & 0x3f);
3110
+ buf[pos++] = 0x80 | ((point >> 6) & 0x3f);
3111
+ buf[pos++] = 0x80 | (point & 0x3f);
3112
+ }
3113
+ }
3114
+ return pos - from;
3115
+ }
3116
+ $.$mol_charset_encode_to = $mol_charset_encode_to;
3088
3117
  })($ || ($ = {}));
3089
3118
 
3090
3119
  ;
@@ -10099,10 +10128,23 @@ var $;
10099
10128
  var $;
10100
10129
  (function ($) {
10101
10130
  $mol_test({
10102
- 'encode utf8 string'() {
10103
- const str = 'Hello, ΧΨΩЫ';
10104
- const encoded = new Uint8Array([72, 101, 108, 108, 111, 44, 32, 206, 167, 206, 168, 206, 169, 208, 171]);
10105
- $mol_assert_like($mol_charset_encode(str), encoded);
10131
+ 'encode empty'() {
10132
+ $mol_assert_equal($mol_charset_encode(''), new Uint8Array([]));
10133
+ },
10134
+ 'encode 1 octet'() {
10135
+ $mol_assert_equal($mol_charset_encode('F'), new Uint8Array([0x46]));
10136
+ },
10137
+ 'encode 2 octet'() {
10138
+ $mol_assert_equal($mol_charset_encode('Б'), new Uint8Array([0xd0, 0x91]));
10139
+ },
10140
+ 'encode 3 octet'() {
10141
+ $mol_assert_equal($mol_charset_encode('ह'), new Uint8Array([0xe0, 0xa4, 0xb9]));
10142
+ },
10143
+ 'encode 4 octet'() {
10144
+ $mol_assert_equal($mol_charset_encode('𐍈'), new Uint8Array([0xf0, 0x90, 0x8d, 0x88]));
10145
+ },
10146
+ 'encode surrogate pair'() {
10147
+ $mol_assert_equal($mol_charset_encode('😀'), new Uint8Array([0xf0, 0x9f, 0x98, 0x80]));
10106
10148
  },
10107
10149
  });
10108
10150
  })($ || ($ = {}));