@hexze/mctext 1.1.1 → 1.1.3

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/README.md CHANGED
@@ -46,7 +46,7 @@ mctext = { version = "1.0", features = ["legacy-fonts"] }
46
46
  use mctext::{MCText, NamedColor};
47
47
 
48
48
  let text = MCText::new()
49
- .add("Red ").color(NamedColor::Red)
49
+ .span("Red ").color(NamedColor::Red)
50
50
  .then("Bold").color(NamedColor::Red).bold()
51
51
  .build();
52
52
 
@@ -64,7 +64,7 @@ pip install mctext
64
64
  ```python
65
65
  import mctext
66
66
 
67
- text = mctext.MCText().add("Red ").color("red").then("Bold").color("red").bold().build()
67
+ text = mctext.MCText().span("Red ").color("red").then("Bold").color("red").bold().build()
68
68
 
69
69
  for span in text.spans():
70
70
  print(f"{span.text}: {span.color}")
@@ -77,11 +77,9 @@ npm install @hexze/mctext
77
77
  ```
78
78
 
79
79
  ```javascript
80
- import init, { MCText } from '@hexze/mctext';
80
+ const { MCText } = require('@hexze/mctext');
81
81
 
82
- await init();
83
-
84
- let text = new MCText().add("Red ").color("red").then("Bold").color("red").bold().build();
82
+ let text = new MCText().span("Red ").color("red").then("Bold").color("red").bold().build();
85
83
 
86
84
  for (const span of text.spans()) {
87
85
  console.log(`${span.text}: ${span.color}`);
package/mctext_wasm.d.ts CHANGED
@@ -22,8 +22,8 @@ export class MCText {
22
22
  [Symbol.dispose](): void;
23
23
  static parseJson(json: string): MCText;
24
24
  plainText(): string;
25
- add(text: string): SpanBuilder;
26
25
  constructor();
26
+ span(text: string): SpanBuilder;
27
27
  static parse(text: string): MCText;
28
28
  spans(): any;
29
29
  toJson(): string;
@@ -60,72 +60,3 @@ export function namedColors(): any;
60
60
  export function render(font_system: FontSystem, text: MCText, width: number, height: number, options: LayoutOptions): RenderResult;
61
61
 
62
62
  export function stripCodes(text: string): string;
63
-
64
- export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
65
-
66
- export interface InitOutput {
67
- readonly memory: WebAssembly.Memory;
68
- readonly __wbg_mctext_free: (a: number, b: number) => void;
69
- readonly __wbg_spanbuilder_free: (a: number, b: number) => void;
70
- readonly countVisibleChars: (a: number, b: number) => number;
71
- readonly mctext_add: (a: number, b: number, c: number) => number;
72
- readonly mctext_new: () => number;
73
- readonly mctext_parse: (a: number, b: number) => number;
74
- readonly mctext_parseJson: (a: number, b: number) => [number, number, number];
75
- readonly mctext_plainText: (a: number) => [number, number];
76
- readonly mctext_spans: (a: number) => any;
77
- readonly mctext_toJson: (a: number) => [number, number];
78
- readonly mctext_toLegacy: (a: number) => [number, number];
79
- readonly namedColors: () => any;
80
- readonly spanbuilder_bold: (a: number) => number;
81
- readonly spanbuilder_build: (a: number) => number;
82
- readonly spanbuilder_color: (a: number, b: number, c: number) => number;
83
- readonly spanbuilder_italic: (a: number) => number;
84
- readonly spanbuilder_obfuscated: (a: number) => number;
85
- readonly spanbuilder_strikethrough: (a: number) => number;
86
- readonly spanbuilder_then: (a: number, b: number, c: number) => number;
87
- readonly spanbuilder_underlined: (a: number) => number;
88
- readonly stripCodes: (a: number, b: number) => [number, number];
89
- readonly __wbg_fontsystem_free: (a: number, b: number) => void;
90
- readonly __wbg_layoutoptions_free: (a: number, b: number) => void;
91
- readonly __wbg_renderresult_free: (a: number, b: number) => void;
92
- readonly fontsystem_measure: (a: number, b: number, c: number, d: number) => number;
93
- readonly fontsystem_modern: () => number;
94
- readonly layoutoptions_new: (a: number) => number;
95
- readonly layoutoptions_withMaxWidth: (a: number, b: number) => number;
96
- readonly layoutoptions_withShadow: (a: number, b: number) => number;
97
- readonly render: (a: number, b: number, c: number, d: number, e: number) => number;
98
- readonly renderresult_data: (a: number) => [number, number];
99
- readonly renderresult_height: (a: number) => number;
100
- readonly renderresult_width: (a: number) => number;
101
- readonly __wbindgen_exn_store: (a: number) => void;
102
- readonly __externref_table_alloc: () => number;
103
- readonly __wbindgen_externrefs: WebAssembly.Table;
104
- readonly __wbindgen_malloc: (a: number, b: number) => number;
105
- readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
106
- readonly __wbindgen_free: (a: number, b: number, c: number) => void;
107
- readonly __externref_table_dealloc: (a: number) => void;
108
- readonly __wbindgen_start: () => void;
109
- }
110
-
111
- export type SyncInitInput = BufferSource | WebAssembly.Module;
112
-
113
- /**
114
- * Instantiates the given `module`, which can either be bytes or
115
- * a precompiled `WebAssembly.Module`.
116
- *
117
- * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
118
- *
119
- * @returns {InitOutput}
120
- */
121
- export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
122
-
123
- /**
124
- * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
125
- * for everything else, calls `WebAssembly.instantiate` directly.
126
- *
127
- * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
128
- *
129
- * @returns {Promise<InitOutput>}
130
- */
131
- export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
package/mctext_wasm.js CHANGED
@@ -1,4 +1,6 @@
1
- let wasm;
1
+
2
+ let imports = {};
3
+ imports['__wbindgen_placeholder__'] = module.exports;
2
4
 
3
5
  function addToExternrefTable0(obj) {
4
6
  const idx = wasm.__externref_table_alloc();
@@ -84,15 +86,7 @@ function takeFromExternrefTable0(idx) {
84
86
 
85
87
  let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
86
88
  cachedTextDecoder.decode();
87
- const MAX_SAFARI_DECODE_BYTES = 2146435072;
88
- let numBytesDecoded = 0;
89
89
  function decodeText(ptr, len) {
90
- numBytesDecoded += len;
91
- if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
92
- cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
93
- cachedTextDecoder.decode();
94
- numBytesDecoded = len;
95
- }
96
90
  return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
97
91
  }
98
92
 
@@ -131,7 +125,7 @@ const SpanBuilderFinalization = (typeof FinalizationRegistry === 'undefined')
131
125
  ? { register: () => {}, unregister: () => {} }
132
126
  : new FinalizationRegistry(ptr => wasm.__wbg_spanbuilder_free(ptr >>> 0, 1));
133
127
 
134
- export class FontSystem {
128
+ class FontSystem {
135
129
  static __wrap(ptr) {
136
130
  ptr = ptr >>> 0;
137
131
  const obj = Object.create(FontSystem.prototype);
@@ -169,8 +163,9 @@ export class FontSystem {
169
163
  }
170
164
  }
171
165
  if (Symbol.dispose) FontSystem.prototype[Symbol.dispose] = FontSystem.prototype.free;
166
+ exports.FontSystem = FontSystem;
172
167
 
173
- export class LayoutOptions {
168
+ class LayoutOptions {
174
169
  static __wrap(ptr) {
175
170
  ptr = ptr >>> 0;
176
171
  const obj = Object.create(LayoutOptions.prototype);
@@ -217,8 +212,9 @@ export class LayoutOptions {
217
212
  }
218
213
  }
219
214
  if (Symbol.dispose) LayoutOptions.prototype[Symbol.dispose] = LayoutOptions.prototype.free;
215
+ exports.LayoutOptions = LayoutOptions;
220
216
 
221
- export class MCText {
217
+ class MCText {
222
218
  static __wrap(ptr) {
223
219
  ptr = ptr >>> 0;
224
220
  const obj = Object.create(MCText.prototype);
@@ -264,23 +260,23 @@ export class MCText {
264
260
  wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
265
261
  }
266
262
  }
263
+ constructor() {
264
+ const ret = wasm.mctext_new();
265
+ this.__wbg_ptr = ret >>> 0;
266
+ MCTextFinalization.register(this, this.__wbg_ptr, this);
267
+ return this;
268
+ }
267
269
  /**
268
270
  * @param {string} text
269
271
  * @returns {SpanBuilder}
270
272
  */
271
- add(text) {
273
+ span(text) {
272
274
  const ptr = this.__destroy_into_raw();
273
275
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
274
276
  const len0 = WASM_VECTOR_LEN;
275
- const ret = wasm.mctext_add(ptr, ptr0, len0);
277
+ const ret = wasm.mctext_span(ptr, ptr0, len0);
276
278
  return SpanBuilder.__wrap(ret);
277
279
  }
278
- constructor() {
279
- const ret = wasm.mctext_new();
280
- this.__wbg_ptr = ret >>> 0;
281
- MCTextFinalization.register(this, this.__wbg_ptr, this);
282
- return this;
283
- }
284
280
  /**
285
281
  * @param {string} text
286
282
  * @returns {MCText}
@@ -330,8 +326,9 @@ export class MCText {
330
326
  }
331
327
  }
332
328
  if (Symbol.dispose) MCText.prototype[Symbol.dispose] = MCText.prototype.free;
329
+ exports.MCText = MCText;
333
330
 
334
- export class RenderResult {
331
+ class RenderResult {
335
332
  static __wrap(ptr) {
336
333
  ptr = ptr >>> 0;
337
334
  const obj = Object.create(RenderResult.prototype);
@@ -374,8 +371,9 @@ export class RenderResult {
374
371
  }
375
372
  }
376
373
  if (Symbol.dispose) RenderResult.prototype[Symbol.dispose] = RenderResult.prototype.free;
374
+ exports.RenderResult = RenderResult;
377
375
 
378
- export class SpanBuilder {
376
+ class SpanBuilder {
379
377
  static __wrap(ptr) {
380
378
  ptr = ptr >>> 0;
381
379
  const obj = Object.create(SpanBuilder.prototype);
@@ -465,25 +463,28 @@ export class SpanBuilder {
465
463
  }
466
464
  }
467
465
  if (Symbol.dispose) SpanBuilder.prototype[Symbol.dispose] = SpanBuilder.prototype.free;
466
+ exports.SpanBuilder = SpanBuilder;
468
467
 
469
468
  /**
470
469
  * @param {string} text
471
470
  * @returns {number}
472
471
  */
473
- export function countVisibleChars(text) {
472
+ function countVisibleChars(text) {
474
473
  const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
475
474
  const len0 = WASM_VECTOR_LEN;
476
475
  const ret = wasm.countVisibleChars(ptr0, len0);
477
476
  return ret >>> 0;
478
477
  }
478
+ exports.countVisibleChars = countVisibleChars;
479
479
 
480
480
  /**
481
481
  * @returns {any}
482
482
  */
483
- export function namedColors() {
483
+ function namedColors() {
484
484
  const ret = wasm.namedColors();
485
485
  return ret;
486
486
  }
487
+ exports.namedColors = namedColors;
487
488
 
488
489
  /**
489
490
  * @param {FontSystem} font_system
@@ -493,19 +494,20 @@ export function namedColors() {
493
494
  * @param {LayoutOptions} options
494
495
  * @returns {RenderResult}
495
496
  */
496
- export function render(font_system, text, width, height, options) {
497
+ function render(font_system, text, width, height, options) {
497
498
  _assertClass(font_system, FontSystem);
498
499
  _assertClass(text, MCText);
499
500
  _assertClass(options, LayoutOptions);
500
501
  const ret = wasm.render(font_system.__wbg_ptr, text.__wbg_ptr, width, height, options.__wbg_ptr);
501
502
  return RenderResult.__wrap(ret);
502
503
  }
504
+ exports.render = render;
503
505
 
504
506
  /**
505
507
  * @param {string} text
506
508
  * @returns {string}
507
509
  */
508
- export function stripCodes(text) {
510
+ function stripCodes(text) {
509
511
  let deferred2_0;
510
512
  let deferred2_1;
511
513
  try {
@@ -519,167 +521,92 @@ export function stripCodes(text) {
519
521
  wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
520
522
  }
521
523
  }
524
+ exports.stripCodes = stripCodes;
522
525
 
523
- const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
524
-
525
- async function __wbg_load(module, imports) {
526
- if (typeof Response === 'function' && module instanceof Response) {
527
- if (typeof WebAssembly.instantiateStreaming === 'function') {
528
- try {
529
- return await WebAssembly.instantiateStreaming(module, imports);
530
- } catch (e) {
531
- const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
532
-
533
- if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
534
- console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
535
-
536
- } else {
537
- throw e;
538
- }
539
- }
540
- }
541
-
542
- const bytes = await module.arrayBuffer();
543
- return await WebAssembly.instantiate(bytes, imports);
544
- } else {
545
- const instance = await WebAssembly.instantiate(module, imports);
546
-
547
- if (instance instanceof WebAssembly.Instance) {
548
- return { instance, module };
549
- } else {
550
- return instance;
551
- }
552
- }
553
- }
554
-
555
- function __wbg_get_imports() {
556
- const imports = {};
557
- imports.wbg = {};
558
- imports.wbg.__wbg_Error_52673b7de5a0ca89 = function(arg0, arg1) {
559
- const ret = Error(getStringFromWasm0(arg0, arg1));
560
- return ret;
561
- };
562
- imports.wbg.__wbg___wbindgen_is_string_704ef9c8fc131030 = function(arg0) {
563
- const ret = typeof(arg0) === 'string';
564
- return ret;
565
- };
566
- imports.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e = function(arg0, arg1) {
567
- throw new Error(getStringFromWasm0(arg0, arg1));
568
- };
569
- imports.wbg.__wbg_fromCodePoint_50facac709b76f67 = function() { return handleError(function (arg0) {
570
- const ret = String.fromCodePoint(arg0 >>> 0);
571
- return ret;
572
- }, arguments) };
573
- imports.wbg.__wbg_new_1ba21ce319a06297 = function() {
574
- const ret = new Object();
575
- return ret;
576
- };
577
- imports.wbg.__wbg_new_25f239778d6112b9 = function() {
578
- const ret = new Array();
579
- return ret;
580
- };
581
- imports.wbg.__wbg_new_b546ae120718850e = function() {
582
- const ret = new Map();
583
- return ret;
584
- };
585
- imports.wbg.__wbg_set_3f1d0b984ed272ed = function(arg0, arg1, arg2) {
586
- arg0[arg1] = arg2;
587
- };
588
- imports.wbg.__wbg_set_7df433eea03a5c14 = function(arg0, arg1, arg2) {
589
- arg0[arg1 >>> 0] = arg2;
590
- };
591
- imports.wbg.__wbg_set_efaaf145b9377369 = function(arg0, arg1, arg2) {
592
- const ret = arg0.set(arg1, arg2);
593
- return ret;
594
- };
595
- imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
596
- // Cast intrinsic for `Ref(String) -> Externref`.
597
- const ret = getStringFromWasm0(arg0, arg1);
598
- return ret;
599
- };
600
- imports.wbg.__wbindgen_cast_4625c577ab2ec9ee = function(arg0) {
601
- // Cast intrinsic for `U64 -> Externref`.
602
- const ret = BigInt.asUintN(64, arg0);
603
- return ret;
604
- };
605
- imports.wbg.__wbindgen_cast_9ae0607507abb057 = function(arg0) {
606
- // Cast intrinsic for `I64 -> Externref`.
607
- const ret = arg0;
608
- return ret;
609
- };
610
- imports.wbg.__wbindgen_cast_d6cd19b81560fd6e = function(arg0) {
611
- // Cast intrinsic for `F64 -> Externref`.
612
- const ret = arg0;
613
- return ret;
614
- };
615
- imports.wbg.__wbindgen_init_externref_table = function() {
616
- const table = wasm.__wbindgen_externrefs;
617
- const offset = table.grow(4);
618
- table.set(0, undefined);
619
- table.set(offset + 0, undefined);
620
- table.set(offset + 1, null);
621
- table.set(offset + 2, true);
622
- table.set(offset + 3, false);
623
- };
624
-
625
- return imports;
626
- }
627
-
628
- function __wbg_finalize_init(instance, module) {
629
- wasm = instance.exports;
630
- __wbg_init.__wbindgen_wasm_module = module;
631
- cachedUint8ArrayMemory0 = null;
632
-
526
+ exports.__wbg_Error_52673b7de5a0ca89 = function(arg0, arg1) {
527
+ const ret = Error(getStringFromWasm0(arg0, arg1));
528
+ return ret;
529
+ };
633
530
 
634
- wasm.__wbindgen_start();
635
- return wasm;
636
- }
531
+ exports.__wbg___wbindgen_is_string_704ef9c8fc131030 = function(arg0) {
532
+ const ret = typeof(arg0) === 'string';
533
+ return ret;
534
+ };
637
535
 
638
- function initSync(module) {
639
- if (wasm !== undefined) return wasm;
536
+ exports.__wbg___wbindgen_throw_dd24417ed36fc46e = function(arg0, arg1) {
537
+ throw new Error(getStringFromWasm0(arg0, arg1));
538
+ };
640
539
 
540
+ exports.__wbg_fromCodePoint_50facac709b76f67 = function() { return handleError(function (arg0) {
541
+ const ret = String.fromCodePoint(arg0 >>> 0);
542
+ return ret;
543
+ }, arguments) };
641
544
 
642
- if (typeof module !== 'undefined') {
643
- if (Object.getPrototypeOf(module) === Object.prototype) {
644
- ({module} = module)
645
- } else {
646
- console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
647
- }
648
- }
545
+ exports.__wbg_new_1ba21ce319a06297 = function() {
546
+ const ret = new Object();
547
+ return ret;
548
+ };
649
549
 
650
- const imports = __wbg_get_imports();
651
- if (!(module instanceof WebAssembly.Module)) {
652
- module = new WebAssembly.Module(module);
653
- }
654
- const instance = new WebAssembly.Instance(module, imports);
655
- return __wbg_finalize_init(instance, module);
656
- }
550
+ exports.__wbg_new_25f239778d6112b9 = function() {
551
+ const ret = new Array();
552
+ return ret;
553
+ };
657
554
 
658
- async function __wbg_init(module_or_path) {
659
- if (wasm !== undefined) return wasm;
555
+ exports.__wbg_new_b546ae120718850e = function() {
556
+ const ret = new Map();
557
+ return ret;
558
+ };
660
559
 
560
+ exports.__wbg_set_3f1d0b984ed272ed = function(arg0, arg1, arg2) {
561
+ arg0[arg1] = arg2;
562
+ };
661
563
 
662
- if (typeof module_or_path !== 'undefined') {
663
- if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
664
- ({module_or_path} = module_or_path)
665
- } else {
666
- console.warn('using deprecated parameters for the initialization function; pass a single object instead')
667
- }
668
- }
564
+ exports.__wbg_set_7df433eea03a5c14 = function(arg0, arg1, arg2) {
565
+ arg0[arg1 >>> 0] = arg2;
566
+ };
669
567
 
670
- if (typeof module_or_path === 'undefined') {
671
- module_or_path = new URL('mctext_wasm_bg.wasm', import.meta.url);
672
- }
673
- const imports = __wbg_get_imports();
568
+ exports.__wbg_set_efaaf145b9377369 = function(arg0, arg1, arg2) {
569
+ const ret = arg0.set(arg1, arg2);
570
+ return ret;
571
+ };
674
572
 
675
- if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
676
- module_or_path = fetch(module_or_path);
677
- }
573
+ exports.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
574
+ // Cast intrinsic for `Ref(String) -> Externref`.
575
+ const ret = getStringFromWasm0(arg0, arg1);
576
+ return ret;
577
+ };
678
578
 
679
- const { instance, module } = await __wbg_load(await module_or_path, imports);
579
+ exports.__wbindgen_cast_4625c577ab2ec9ee = function(arg0) {
580
+ // Cast intrinsic for `U64 -> Externref`.
581
+ const ret = BigInt.asUintN(64, arg0);
582
+ return ret;
583
+ };
680
584
 
681
- return __wbg_finalize_init(instance, module);
682
- }
585
+ exports.__wbindgen_cast_9ae0607507abb057 = function(arg0) {
586
+ // Cast intrinsic for `I64 -> Externref`.
587
+ const ret = arg0;
588
+ return ret;
589
+ };
683
590
 
684
- export { initSync };
685
- export default __wbg_init;
591
+ exports.__wbindgen_cast_d6cd19b81560fd6e = function(arg0) {
592
+ // Cast intrinsic for `F64 -> Externref`.
593
+ const ret = arg0;
594
+ return ret;
595
+ };
596
+
597
+ exports.__wbindgen_init_externref_table = function() {
598
+ const table = wasm.__wbindgen_externrefs;
599
+ const offset = table.grow(4);
600
+ table.set(0, undefined);
601
+ table.set(offset + 0, undefined);
602
+ table.set(offset + 1, null);
603
+ table.set(offset + 2, true);
604
+ table.set(offset + 3, false);
605
+ };
606
+
607
+ const wasmPath = `${__dirname}/mctext_wasm_bg.wasm`;
608
+ const wasmBytes = require('fs').readFileSync(wasmPath);
609
+ const wasmModule = new WebAssembly.Module(wasmBytes);
610
+ const wasm = exports.__wasm = new WebAssembly.Instance(wasmModule, imports).exports;
611
+
612
+ wasm.__wbindgen_start();
Binary file
package/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "@hexze/mctext",
3
- "type": "module",
4
3
  "description": "Minecraft text formatting for JavaScript/WASM",
5
- "version": "1.1.1",
4
+ "version": "1.1.3",
6
5
  "license": "MIT",
7
6
  "repository": {
8
7
  "type": "git",
@@ -14,8 +13,5 @@
14
13
  "mctext_wasm.d.ts"
15
14
  ],
16
15
  "main": "mctext_wasm.js",
17
- "types": "mctext_wasm.d.ts",
18
- "sideEffects": [
19
- "./snippets/*"
20
- ]
16
+ "types": "mctext_wasm.d.ts"
21
17
  }