@pixagram/renderart 0.1.3 → 0.2.1

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/dist/index.js CHANGED
@@ -1,795 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __esm = (fn, res) => function __init() {
7
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
8
- };
9
- var __export = (target, all) => {
10
- for (var name in all)
11
- __defProp(target, name, { get: all[name], enumerable: true });
12
- };
13
-
14
- // pkg/renderart_wasm.js
15
- var renderart_wasm_exports = {};
16
- __export(renderart_wasm_exports, {
17
- CrtConfig: () => CrtConfig,
18
- HexConfig: () => HexConfig,
19
- HexOrientation: () => HexOrientation,
20
- UpscaleResult: () => UpscaleResult,
21
- XbrzConfig: () => XbrzConfig,
22
- crt_upscale: () => crt_upscale,
23
- crt_upscale_config: () => crt_upscale_config,
24
- default: () => renderart_wasm_default,
25
- get_memory: () => get_memory,
26
- hex_get_dimensions: () => hex_get_dimensions,
27
- hex_upscale: () => hex_upscale,
28
- hex_upscale_config: () => hex_upscale_config,
29
- init: () => init,
30
- initSync: () => initSync,
31
- xbrz_upscale: () => xbrz_upscale,
32
- xbrz_upscale_config: () => xbrz_upscale_config
33
- });
34
- function _assertClass(instance, klass) {
35
- if (!(instance instanceof klass)) {
36
- throw new Error(`expected instance of ${klass.name}`);
37
- }
38
- }
39
- function getArrayU32FromWasm0(ptr, len) {
40
- ptr = ptr >>> 0;
41
- return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
42
- }
43
- function getDataViewMemory0() {
44
- if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || cachedDataViewMemory0.buffer.detached === void 0 && cachedDataViewMemory0.buffer !== wasm.memory.buffer) {
45
- cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
46
- }
47
- return cachedDataViewMemory0;
48
- }
49
- function getStringFromWasm0(ptr, len) {
50
- ptr = ptr >>> 0;
51
- return decodeText(ptr, len);
52
- }
53
- function getUint32ArrayMemory0() {
54
- if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
55
- cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
56
- }
57
- return cachedUint32ArrayMemory0;
58
- }
59
- function getUint8ArrayMemory0() {
60
- if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
61
- cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
62
- }
63
- return cachedUint8ArrayMemory0;
64
- }
65
- function passArray8ToWasm0(arg, malloc) {
66
- const ptr = malloc(arg.length * 1, 1) >>> 0;
67
- getUint8ArrayMemory0().set(arg, ptr / 1);
68
- WASM_VECTOR_LEN = arg.length;
69
- return ptr;
70
- }
71
- function passStringToWasm0(arg, malloc, realloc) {
72
- if (realloc === void 0) {
73
- const buf = cachedTextEncoder.encode(arg);
74
- const ptr2 = malloc(buf.length, 1) >>> 0;
75
- getUint8ArrayMemory0().subarray(ptr2, ptr2 + buf.length).set(buf);
76
- WASM_VECTOR_LEN = buf.length;
77
- return ptr2;
78
- }
79
- let len = arg.length;
80
- let ptr = malloc(len, 1) >>> 0;
81
- const mem = getUint8ArrayMemory0();
82
- let offset = 0;
83
- for (; offset < len; offset++) {
84
- const code = arg.charCodeAt(offset);
85
- if (code > 127) break;
86
- mem[ptr + offset] = code;
87
- }
88
- if (offset !== len) {
89
- if (offset !== 0) {
90
- arg = arg.slice(offset);
91
- }
92
- ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
93
- const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
94
- const ret = cachedTextEncoder.encodeInto(arg, view);
95
- offset += ret.written;
96
- ptr = realloc(ptr, len, offset, 1) >>> 0;
97
- }
98
- WASM_VECTOR_LEN = offset;
99
- return ptr;
100
- }
101
- function takeFromExternrefTable0(idx) {
102
- const value = wasm.__wbindgen_externrefs.get(idx);
103
- wasm.__externref_table_dealloc(idx);
104
- return value;
105
- }
106
- function decodeText(ptr, len) {
107
- numBytesDecoded += len;
108
- if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
109
- cachedTextDecoder = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
110
- cachedTextDecoder.decode();
111
- numBytesDecoded = len;
112
- }
113
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
114
- }
115
- function crt_upscale(input, src_w, src_h, scale) {
116
- const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_malloc);
117
- const len0 = WASM_VECTOR_LEN;
118
- const ret = wasm.crt_upscale(ptr0, len0, src_w, src_h, scale);
119
- if (ret[2]) {
120
- throw takeFromExternrefTable0(ret[1]);
121
- }
122
- return UpscaleResult.__wrap(ret[0]);
123
- }
124
- function crt_upscale_config(input, src_w, src_h, scale, config) {
125
- const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_malloc);
126
- const len0 = WASM_VECTOR_LEN;
127
- _assertClass(config, CrtConfig);
128
- const ret = wasm.crt_upscale_config(ptr0, len0, src_w, src_h, scale, config.__wbg_ptr);
129
- if (ret[2]) {
130
- throw takeFromExternrefTable0(ret[1]);
131
- }
132
- return UpscaleResult.__wrap(ret[0]);
133
- }
134
- function get_memory() {
135
- const ret = wasm.get_memory();
136
- return ret;
137
- }
138
- function hex_get_dimensions(src_w, src_h, scale, orientation) {
139
- const ret = wasm.hex_get_dimensions(src_w, src_h, scale, orientation);
140
- var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
141
- wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
142
- return v1;
143
- }
144
- function hex_upscale(input, src_w, src_h, scale) {
145
- const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_malloc);
146
- const len0 = WASM_VECTOR_LEN;
147
- const ret = wasm.hex_upscale(ptr0, len0, src_w, src_h, scale);
148
- if (ret[2]) {
149
- throw takeFromExternrefTable0(ret[1]);
150
- }
151
- return UpscaleResult.__wrap(ret[0]);
152
- }
153
- function hex_upscale_config(input, src_w, src_h, scale, config) {
154
- const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_malloc);
155
- const len0 = WASM_VECTOR_LEN;
156
- _assertClass(config, HexConfig);
157
- const ret = wasm.hex_upscale_config(ptr0, len0, src_w, src_h, scale, config.__wbg_ptr);
158
- if (ret[2]) {
159
- throw takeFromExternrefTable0(ret[1]);
160
- }
161
- return UpscaleResult.__wrap(ret[0]);
162
- }
163
- function init() {
164
- wasm.init();
165
- }
166
- function xbrz_upscale(input, src_w, src_h, scale) {
167
- const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_malloc);
168
- const len0 = WASM_VECTOR_LEN;
169
- const ret = wasm.xbrz_upscale(ptr0, len0, src_w, src_h, scale);
170
- if (ret[2]) {
171
- throw takeFromExternrefTable0(ret[1]);
172
- }
173
- return UpscaleResult.__wrap(ret[0]);
174
- }
175
- function xbrz_upscale_config(input, src_w, src_h, scale, config) {
176
- const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_malloc);
177
- const len0 = WASM_VECTOR_LEN;
178
- _assertClass(config, XbrzConfig);
179
- const ret = wasm.xbrz_upscale_config(ptr0, len0, src_w, src_h, scale, config.__wbg_ptr);
180
- if (ret[2]) {
181
- throw takeFromExternrefTable0(ret[1]);
182
- }
183
- return UpscaleResult.__wrap(ret[0]);
184
- }
185
- async function __wbg_load(module, imports) {
186
- if (typeof Response === "function" && module instanceof Response) {
187
- if (typeof WebAssembly.instantiateStreaming === "function") {
188
- try {
189
- return await WebAssembly.instantiateStreaming(module, imports);
190
- } catch (e) {
191
- const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
192
- if (validResponse && module.headers.get("Content-Type") !== "application/wasm") {
193
- 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);
194
- } else {
195
- throw e;
196
- }
197
- }
198
- }
199
- const bytes = await module.arrayBuffer();
200
- return await WebAssembly.instantiate(bytes, imports);
201
- } else {
202
- const instance = await WebAssembly.instantiate(module, imports);
203
- if (instance instanceof WebAssembly.Instance) {
204
- return { instance, module };
205
- } else {
206
- return instance;
207
- }
208
- }
209
- }
210
- function __wbg_get_imports() {
211
- const imports = {};
212
- imports.wbg = {};
213
- imports.wbg.__wbg___wbindgen_memory_a342e963fbcabd68 = function() {
214
- const ret = wasm.memory;
215
- return ret;
216
- };
217
- imports.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e = function(arg0, arg1) {
218
- throw new Error(getStringFromWasm0(arg0, arg1));
219
- };
220
- imports.wbg.__wbg_error_7534b8e9a36f1ab4 = function(arg0, arg1) {
221
- let deferred0_0;
222
- let deferred0_1;
223
- try {
224
- deferred0_0 = arg0;
225
- deferred0_1 = arg1;
226
- console.error(getStringFromWasm0(arg0, arg1));
227
- } finally {
228
- wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
229
- }
230
- };
231
- imports.wbg.__wbg_new_8a6f238a6ece86ea = function() {
232
- const ret = new Error();
233
- return ret;
234
- };
235
- imports.wbg.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
236
- const ret = arg1.stack;
237
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
238
- const len1 = WASM_VECTOR_LEN;
239
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
240
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
241
- };
242
- imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
243
- const ret = getStringFromWasm0(arg0, arg1);
244
- return ret;
245
- };
246
- imports.wbg.__wbindgen_init_externref_table = function() {
247
- const table = wasm.__wbindgen_externrefs;
248
- const offset = table.grow(4);
249
- table.set(0, void 0);
250
- table.set(offset + 0, void 0);
251
- table.set(offset + 1, null);
252
- table.set(offset + 2, true);
253
- table.set(offset + 3, false);
254
- };
255
- return imports;
256
- }
257
- function __wbg_finalize_init(instance, module) {
258
- wasm = instance.exports;
259
- __wbg_init.__wbindgen_wasm_module = module;
260
- cachedDataViewMemory0 = null;
261
- cachedUint32ArrayMemory0 = null;
262
- cachedUint8ArrayMemory0 = null;
263
- wasm.__wbindgen_start();
264
- return wasm;
265
- }
266
- function initSync(module) {
267
- if (wasm !== void 0) return wasm;
268
- if (typeof module !== "undefined") {
269
- if (Object.getPrototypeOf(module) === Object.prototype) {
270
- ({ module } = module);
271
- } else {
272
- console.warn("using deprecated parameters for `initSync()`; pass a single object instead");
273
- }
274
- }
275
- const imports = __wbg_get_imports();
276
- if (!(module instanceof WebAssembly.Module)) {
277
- module = new WebAssembly.Module(module);
278
- }
279
- const instance = new WebAssembly.Instance(module, imports);
280
- return __wbg_finalize_init(instance, module);
281
- }
282
- async function __wbg_init(module_or_path) {
283
- if (wasm !== void 0) return wasm;
284
- if (typeof module_or_path !== "undefined") {
285
- if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
286
- ({ module_or_path } = module_or_path);
287
- } else {
288
- console.warn("using deprecated parameters for the initialization function; pass a single object instead");
289
- }
290
- }
291
- if (typeof module_or_path === "undefined") {
292
- module_or_path = new URL("renderart_wasm_bg.wasm", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)));
293
- }
294
- const imports = __wbg_get_imports();
295
- if (typeof module_or_path === "string" || typeof Request === "function" && module_or_path instanceof Request || typeof URL === "function" && module_or_path instanceof URL) {
296
- module_or_path = fetch(module_or_path);
297
- }
298
- const { instance, module } = await __wbg_load(await module_or_path, imports);
299
- return __wbg_finalize_init(instance, module);
300
- }
301
- var wasm, cachedDataViewMemory0, cachedUint32ArrayMemory0, cachedUint8ArrayMemory0, cachedTextDecoder, MAX_SAFARI_DECODE_BYTES, numBytesDecoded, cachedTextEncoder, WASM_VECTOR_LEN, CrtConfigFinalization, HexConfigFinalization, UpscaleResultFinalization, XbrzConfigFinalization, CrtConfig, HexConfig, HexOrientation, UpscaleResult, XbrzConfig, EXPECTED_RESPONSE_TYPES, renderart_wasm_default;
302
- var init_renderart_wasm = __esm({
303
- "pkg/renderart_wasm.js"() {
304
- cachedDataViewMemory0 = null;
305
- cachedUint32ArrayMemory0 = null;
306
- cachedUint8ArrayMemory0 = null;
307
- cachedTextDecoder = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
308
- cachedTextDecoder.decode();
309
- MAX_SAFARI_DECODE_BYTES = 2146435072;
310
- numBytesDecoded = 0;
311
- cachedTextEncoder = new TextEncoder();
312
- if (!("encodeInto" in cachedTextEncoder)) {
313
- cachedTextEncoder.encodeInto = function(arg, view) {
314
- const buf = cachedTextEncoder.encode(arg);
315
- view.set(buf);
316
- return {
317
- read: arg.length,
318
- written: buf.length
319
- };
320
- };
321
- }
322
- WASM_VECTOR_LEN = 0;
323
- CrtConfigFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
324
- }, unregister: () => {
325
- } } : new FinalizationRegistry((ptr) => wasm.__wbg_crtconfig_free(ptr >>> 0, 1));
326
- HexConfigFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
327
- }, unregister: () => {
328
- } } : new FinalizationRegistry((ptr) => wasm.__wbg_hexconfig_free(ptr >>> 0, 1));
329
- UpscaleResultFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
330
- }, unregister: () => {
331
- } } : new FinalizationRegistry((ptr) => wasm.__wbg_upscaleresult_free(ptr >>> 0, 1));
332
- XbrzConfigFinalization = typeof FinalizationRegistry === "undefined" ? { register: () => {
333
- }, unregister: () => {
334
- } } : new FinalizationRegistry((ptr) => wasm.__wbg_xbrzconfig_free(ptr >>> 0, 1));
335
- CrtConfig = class _CrtConfig {
336
- static __wrap(ptr) {
337
- ptr = ptr >>> 0;
338
- const obj = Object.create(_CrtConfig.prototype);
339
- obj.__wbg_ptr = ptr;
340
- CrtConfigFinalization.register(obj, obj.__wbg_ptr, obj);
341
- return obj;
342
- }
343
- __destroy_into_raw() {
344
- const ptr = this.__wbg_ptr;
345
- this.__wbg_ptr = 0;
346
- CrtConfigFinalization.unregister(this);
347
- return ptr;
348
- }
349
- free() {
350
- const ptr = this.__destroy_into_raw();
351
- wasm.__wbg_crtconfig_free(ptr, 0);
352
- }
353
- /**
354
- * Horizontal warp intensity (0.0 - 0.1)
355
- * @returns {number}
356
- */
357
- get warp_x() {
358
- const ret = wasm.__wbg_get_crtconfig_warp_x(this.__wbg_ptr);
359
- return ret;
360
- }
361
- /**
362
- * Horizontal warp intensity (0.0 - 0.1)
363
- * @param {number} arg0
364
- */
365
- set warp_x(arg0) {
366
- wasm.__wbg_set_crtconfig_warp_x(this.__wbg_ptr, arg0);
367
- }
368
- /**
369
- * Vertical warp intensity (0.0 - 0.1)
370
- * @returns {number}
371
- */
372
- get warp_y() {
373
- const ret = wasm.__wbg_get_crtconfig_warp_y(this.__wbg_ptr);
374
- return ret;
375
- }
376
- /**
377
- * Vertical warp intensity (0.0 - 0.1)
378
- * @param {number} arg0
379
- */
380
- set warp_y(arg0) {
381
- wasm.__wbg_set_crtconfig_warp_y(this.__wbg_ptr, arg0);
382
- }
383
- /**
384
- * Scanline hardness (-10.0 to 0.0, more negative = sharper)
385
- * @returns {number}
386
- */
387
- get scan_hardness() {
388
- const ret = wasm.__wbg_get_crtconfig_scan_hardness(this.__wbg_ptr);
389
- return ret;
390
- }
391
- /**
392
- * Scanline hardness (-10.0 to 0.0, more negative = sharper)
393
- * @param {number} arg0
394
- */
395
- set scan_hardness(arg0) {
396
- wasm.__wbg_set_crtconfig_scan_hardness(this.__wbg_ptr, arg0);
397
- }
398
- /**
399
- * Scanline opacity (0.0 - 1.0)
400
- * @returns {number}
401
- */
402
- get scan_opacity() {
403
- const ret = wasm.__wbg_get_crtconfig_scan_opacity(this.__wbg_ptr);
404
- return ret;
405
- }
406
- /**
407
- * Scanline opacity (0.0 - 1.0)
408
- * @param {number} arg0
409
- */
410
- set scan_opacity(arg0) {
411
- wasm.__wbg_set_crtconfig_scan_opacity(this.__wbg_ptr, arg0);
412
- }
413
- /**
414
- * Shadow mask opacity (0.0 - 1.0)
415
- * @returns {number}
416
- */
417
- get mask_opacity() {
418
- const ret = wasm.__wbg_get_crtconfig_mask_opacity(this.__wbg_ptr);
419
- return ret;
420
- }
421
- /**
422
- * Shadow mask opacity (0.0 - 1.0)
423
- * @param {number} arg0
424
- */
425
- set mask_opacity(arg0) {
426
- wasm.__wbg_set_crtconfig_mask_opacity(this.__wbg_ptr, arg0);
427
- }
428
- /**
429
- * Enable barrel distortion
430
- * @returns {boolean}
431
- */
432
- get enable_warp() {
433
- const ret = wasm.__wbg_get_crtconfig_enable_warp(this.__wbg_ptr);
434
- return ret !== 0;
435
- }
436
- /**
437
- * Enable barrel distortion
438
- * @param {boolean} arg0
439
- */
440
- set enable_warp(arg0) {
441
- wasm.__wbg_set_crtconfig_enable_warp(this.__wbg_ptr, arg0);
442
- }
443
- /**
444
- * Enable scanlines
445
- * @returns {boolean}
446
- */
447
- get enable_scanlines() {
448
- const ret = wasm.__wbg_get_crtconfig_enable_scanlines(this.__wbg_ptr);
449
- return ret !== 0;
450
- }
451
- /**
452
- * Enable scanlines
453
- * @param {boolean} arg0
454
- */
455
- set enable_scanlines(arg0) {
456
- wasm.__wbg_set_crtconfig_enable_scanlines(this.__wbg_ptr, arg0);
457
- }
458
- /**
459
- * Enable shadow mask
460
- * @returns {boolean}
461
- */
462
- get enable_mask() {
463
- const ret = wasm.__wbg_get_crtconfig_enable_mask(this.__wbg_ptr);
464
- return ret !== 0;
465
- }
466
- /**
467
- * Enable shadow mask
468
- * @param {boolean} arg0
469
- */
470
- set enable_mask(arg0) {
471
- wasm.__wbg_set_crtconfig_enable_mask(this.__wbg_ptr, arg0);
472
- }
473
- constructor() {
474
- const ret = wasm.crtconfig_new();
475
- this.__wbg_ptr = ret >>> 0;
476
- CrtConfigFinalization.register(this, this.__wbg_ptr, this);
477
- return this;
478
- }
479
- /**
480
- * Create preset: Authentic CRT look
481
- * @returns {CrtConfig}
482
- */
483
- static preset_authentic() {
484
- const ret = wasm.crtconfig_preset_authentic();
485
- return _CrtConfig.__wrap(ret);
486
- }
487
- /**
488
- * Create preset: Subtle modern look
489
- * @returns {CrtConfig}
490
- */
491
- static preset_subtle() {
492
- const ret = wasm.crtconfig_preset_subtle();
493
- return _CrtConfig.__wrap(ret);
494
- }
495
- /**
496
- * Create preset: Flat screen (no curvature)
497
- * @returns {CrtConfig}
498
- */
499
- static preset_flat() {
500
- const ret = wasm.crtconfig_preset_flat();
501
- return _CrtConfig.__wrap(ret);
502
- }
503
- };
504
- if (Symbol.dispose) CrtConfig.prototype[Symbol.dispose] = CrtConfig.prototype.free;
505
- HexConfig = class _HexConfig {
506
- static __wrap(ptr) {
507
- ptr = ptr >>> 0;
508
- const obj = Object.create(_HexConfig.prototype);
509
- obj.__wbg_ptr = ptr;
510
- HexConfigFinalization.register(obj, obj.__wbg_ptr, obj);
511
- return obj;
512
- }
513
- __destroy_into_raw() {
514
- const ptr = this.__wbg_ptr;
515
- this.__wbg_ptr = 0;
516
- HexConfigFinalization.unregister(this);
517
- return ptr;
518
- }
519
- free() {
520
- const ptr = this.__destroy_into_raw();
521
- wasm.__wbg_hexconfig_free(ptr, 0);
522
- }
523
- /**
524
- * Hexagon orientation
525
- * @returns {HexOrientation}
526
- */
527
- get orientation() {
528
- const ret = wasm.__wbg_get_hexconfig_orientation(this.__wbg_ptr);
529
- return ret;
530
- }
531
- /**
532
- * Hexagon orientation
533
- * @param {HexOrientation} arg0
534
- */
535
- set orientation(arg0) {
536
- wasm.__wbg_set_hexconfig_orientation(this.__wbg_ptr, arg0);
537
- }
538
- /**
539
- * Draw hexagon borders
540
- * @returns {boolean}
541
- */
542
- get draw_borders() {
543
- const ret = wasm.__wbg_get_hexconfig_draw_borders(this.__wbg_ptr);
544
- return ret !== 0;
545
- }
546
- /**
547
- * Draw hexagon borders
548
- * @param {boolean} arg0
549
- */
550
- set draw_borders(arg0) {
551
- wasm.__wbg_set_hexconfig_draw_borders(this.__wbg_ptr, arg0);
552
- }
553
- /**
554
- * Border color (RGBA packed as u32: 0xRRGGBBAA)
555
- * @returns {number}
556
- */
557
- get border_color() {
558
- const ret = wasm.__wbg_get_hexconfig_border_color(this.__wbg_ptr);
559
- return ret >>> 0;
560
- }
561
- /**
562
- * Border color (RGBA packed as u32: 0xRRGGBBAA)
563
- * @param {number} arg0
564
- */
565
- set border_color(arg0) {
566
- wasm.__wbg_set_hexconfig_border_color(this.__wbg_ptr, arg0);
567
- }
568
- /**
569
- * Border thickness in pixels
570
- * @returns {number}
571
- */
572
- get border_thickness() {
573
- const ret = wasm.__wbg_get_hexconfig_border_thickness(this.__wbg_ptr);
574
- return ret >>> 0;
575
- }
576
- /**
577
- * Border thickness in pixels
578
- * @param {number} arg0
579
- */
580
- set border_thickness(arg0) {
581
- wasm.__wbg_set_hexconfig_border_thickness(this.__wbg_ptr, arg0);
582
- }
583
- /**
584
- * Background color (RGBA packed as u32)
585
- * @returns {number}
586
- */
587
- get background_color() {
588
- const ret = wasm.__wbg_get_hexconfig_background_color(this.__wbg_ptr);
589
- return ret >>> 0;
590
- }
591
- /**
592
- * Background color (RGBA packed as u32)
593
- * @param {number} arg0
594
- */
595
- set background_color(arg0) {
596
- wasm.__wbg_set_hexconfig_background_color(this.__wbg_ptr, arg0);
597
- }
598
- constructor() {
599
- const ret = wasm.hexconfig_new();
600
- this.__wbg_ptr = ret >>> 0;
601
- HexConfigFinalization.register(this, this.__wbg_ptr, this);
602
- return this;
603
- }
604
- /**
605
- * Create preset with borders
606
- * @returns {HexConfig}
607
- */
608
- static preset_bordered() {
609
- const ret = wasm.hexconfig_preset_bordered();
610
- return _HexConfig.__wrap(ret);
611
- }
612
- /**
613
- * Create preset for pointy-top hexagons
614
- * @returns {HexConfig}
615
- */
616
- static preset_pointy() {
617
- const ret = wasm.hexconfig_preset_pointy();
618
- return _HexConfig.__wrap(ret);
619
- }
620
- };
621
- if (Symbol.dispose) HexConfig.prototype[Symbol.dispose] = HexConfig.prototype.free;
622
- HexOrientation = Object.freeze({
623
- /**
624
- * Flat edge at top, vertices on left/right
625
- */
626
- FlatTop: 0,
627
- "0": "FlatTop",
628
- /**
629
- * Vertex at top, flat edges on left/right
630
- */
631
- PointyTop: 1,
632
- "1": "PointyTop"
633
- });
634
- UpscaleResult = class _UpscaleResult {
635
- static __wrap(ptr) {
636
- ptr = ptr >>> 0;
637
- const obj = Object.create(_UpscaleResult.prototype);
638
- obj.__wbg_ptr = ptr;
639
- UpscaleResultFinalization.register(obj, obj.__wbg_ptr, obj);
640
- return obj;
641
- }
642
- __destroy_into_raw() {
643
- const ptr = this.__wbg_ptr;
644
- this.__wbg_ptr = 0;
645
- UpscaleResultFinalization.unregister(this);
646
- return ptr;
647
- }
648
- free() {
649
- const ptr = this.__destroy_into_raw();
650
- wasm.__wbg_upscaleresult_free(ptr, 0);
651
- }
652
- /**
653
- * Pointer to the output buffer in WASM memory
654
- * @returns {number}
655
- */
656
- get ptr() {
657
- const ret = wasm.upscaleresult_ptr(this.__wbg_ptr);
658
- return ret >>> 0;
659
- }
660
- /**
661
- * Length of the output buffer in bytes
662
- * @returns {number}
663
- */
664
- get len() {
665
- const ret = wasm.upscaleresult_len(this.__wbg_ptr);
666
- return ret >>> 0;
667
- }
668
- /**
669
- * Output image width
670
- * @returns {number}
671
- */
672
- get width() {
673
- const ret = wasm.upscaleresult_width(this.__wbg_ptr);
674
- return ret >>> 0;
675
- }
676
- /**
677
- * Output image height
678
- * @returns {number}
679
- */
680
- get height() {
681
- const ret = wasm.upscaleresult_height(this.__wbg_ptr);
682
- return ret >>> 0;
683
- }
684
- };
685
- if (Symbol.dispose) UpscaleResult.prototype[Symbol.dispose] = UpscaleResult.prototype.free;
686
- XbrzConfig = class _XbrzConfig {
687
- static __wrap(ptr) {
688
- ptr = ptr >>> 0;
689
- const obj = Object.create(_XbrzConfig.prototype);
690
- obj.__wbg_ptr = ptr;
691
- XbrzConfigFinalization.register(obj, obj.__wbg_ptr, obj);
692
- return obj;
693
- }
694
- __destroy_into_raw() {
695
- const ptr = this.__wbg_ptr;
696
- this.__wbg_ptr = 0;
697
- XbrzConfigFinalization.unregister(this);
698
- return ptr;
699
- }
700
- free() {
701
- const ptr = this.__destroy_into_raw();
702
- wasm.__wbg_xbrzconfig_free(ptr, 0);
703
- }
704
- /**
705
- * Luminance weight for edge detection (0.0 - 1.0)
706
- * @returns {number}
707
- */
708
- get luminance_weight() {
709
- const ret = wasm.__wbg_get_crtconfig_warp_x(this.__wbg_ptr);
710
- return ret;
711
- }
712
- /**
713
- * Luminance weight for edge detection (0.0 - 1.0)
714
- * @param {number} arg0
715
- */
716
- set luminance_weight(arg0) {
717
- wasm.__wbg_set_crtconfig_warp_x(this.__wbg_ptr, arg0);
718
- }
719
- /**
720
- * Equal color tolerance (0 - 50)
721
- * @returns {number}
722
- */
723
- get equal_color_tolerance() {
724
- const ret = wasm.__wbg_get_hexconfig_border_thickness(this.__wbg_ptr);
725
- return ret >>> 0;
726
- }
727
- /**
728
- * Equal color tolerance (0 - 50)
729
- * @param {number} arg0
730
- */
731
- set equal_color_tolerance(arg0) {
732
- wasm.__wbg_set_hexconfig_border_thickness(this.__wbg_ptr, arg0);
733
- }
734
- /**
735
- * Dominant direction threshold (3.5 - 6.0)
736
- * @returns {number}
737
- */
738
- get dominant_direction_threshold() {
739
- const ret = wasm.__wbg_get_crtconfig_scan_hardness(this.__wbg_ptr);
740
- return ret;
741
- }
742
- /**
743
- * Dominant direction threshold (3.5 - 6.0)
744
- * @param {number} arg0
745
- */
746
- set dominant_direction_threshold(arg0) {
747
- wasm.__wbg_set_crtconfig_scan_hardness(this.__wbg_ptr, arg0);
748
- }
749
- /**
750
- * Steep direction threshold (2.0 - 3.0)
751
- * @returns {number}
752
- */
753
- get steep_direction_threshold() {
754
- const ret = wasm.__wbg_get_crtconfig_scan_opacity(this.__wbg_ptr);
755
- return ret;
756
- }
757
- /**
758
- * Steep direction threshold (2.0 - 3.0)
759
- * @param {number} arg0
760
- */
761
- set steep_direction_threshold(arg0) {
762
- wasm.__wbg_set_crtconfig_scan_opacity(this.__wbg_ptr, arg0);
763
- }
764
- constructor() {
765
- const ret = wasm.xbrzconfig_new();
766
- this.__wbg_ptr = ret >>> 0;
767
- XbrzConfigFinalization.register(this, this.__wbg_ptr, this);
768
- return this;
769
- }
770
- /**
771
- * Preset for sharp edges
772
- * @returns {XbrzConfig}
773
- */
774
- static preset_sharp() {
775
- const ret = wasm.xbrzconfig_preset_sharp();
776
- return _XbrzConfig.__wrap(ret);
777
- }
778
- /**
779
- * Preset for smooth output
780
- * @returns {XbrzConfig}
781
- */
782
- static preset_smooth() {
783
- const ret = wasm.xbrzconfig_preset_smooth();
784
- return _XbrzConfig.__wrap(ret);
785
- }
786
- };
787
- if (Symbol.dispose) XbrzConfig.prototype[Symbol.dispose] = XbrzConfig.prototype.free;
788
- EXPECTED_RESPONSE_TYPES = /* @__PURE__ */ new Set(["basic", "cors", "default"]);
789
- renderart_wasm_default = __wbg_init;
790
- }
791
- });
792
-
793
3
  // src/crt-gpu.ts
794
4
  var VERTEX_SHADER = `#version 300 es
795
5
  layout(location = 0) in vec2 position;
@@ -1410,31 +620,85 @@ var HEX_PRESETS = {
1410
620
  };
1411
621
 
1412
622
  // src/wasm-loader.ts
1413
- var wasmModule = null;
623
+ var wasm = null;
1414
624
  var wasmMemory = null;
1415
- var loadPromise = null;
1416
- async function loadWasm() {
1417
- if (wasmModule) return wasmModule;
1418
- if (loadPromise) return loadPromise;
1419
- loadPromise = (async () => {
625
+ var initPromise = null;
626
+ var wasmUrl = "";
627
+ var cachedUint8Memory = null;
628
+ var WASM_VECTOR_LEN = 0;
629
+ function getUint8Memory() {
630
+ if (cachedUint8Memory === null || cachedUint8Memory.byteLength === 0) {
631
+ cachedUint8Memory = new Uint8Array(wasmMemory.buffer);
632
+ }
633
+ return cachedUint8Memory;
634
+ }
635
+ function passArray8ToWasm(arg) {
636
+ const ptr = wasm.__wbindgen_malloc(arg.length);
637
+ getUint8Memory().set(arg, ptr);
638
+ WASM_VECTOR_LEN = arg.length;
639
+ return ptr;
640
+ }
641
+ function setWasmUrl(url) {
642
+ wasmUrl = url;
643
+ }
644
+ function getDefaultWasmUrl() {
645
+ if (wasmUrl) return wasmUrl;
646
+ const paths = [
647
+ "/renderart_wasm_bg.wasm",
648
+ "/wasm/renderart_wasm_bg.wasm",
649
+ "/static/wasm/renderart_wasm_bg.wasm",
650
+ "/assets/wasm/renderart_wasm_bg.wasm"
651
+ ];
652
+ return paths[0];
653
+ }
654
+ async function initWasm(customUrl) {
655
+ if (wasm) return;
656
+ if (initPromise) return initPromise;
657
+ const url = customUrl || getDefaultWasmUrl();
658
+ initPromise = (async () => {
1420
659
  try {
1421
- const wasm2 = await Promise.resolve().then(() => (init_renderart_wasm(), renderart_wasm_exports));
1422
- await wasm2.default();
1423
- wasmModule = wasm2;
1424
- wasmMemory = wasmModule.get_memory();
1425
- return wasmModule;
660
+ const response = await fetch(url);
661
+ if (!response.ok) {
662
+ throw new Error(`Failed to fetch WASM: ${response.status} ${response.statusText}`);
663
+ }
664
+ const bytes = await response.arrayBuffer();
665
+ const imports = {
666
+ __wbindgen_placeholder__: {
667
+ __wbindgen_throw: (ptr, len) => {
668
+ const msg = new TextDecoder().decode(getUint8Memory().subarray(ptr, ptr + len));
669
+ throw new Error(msg);
670
+ }
671
+ },
672
+ wbg: {
673
+ __wbindgen_throw: (ptr, len) => {
674
+ const msg = new TextDecoder().decode(getUint8Memory().subarray(ptr, ptr + len));
675
+ throw new Error(msg);
676
+ }
677
+ }
678
+ };
679
+ const { instance } = await WebAssembly.instantiate(bytes, imports);
680
+ wasm = instance.exports;
681
+ wasmMemory = wasm.memory;
682
+ if (wasm.__wbindgen_start) {
683
+ wasm.__wbindgen_start();
684
+ }
1426
685
  } catch (e) {
1427
- throw new Error(`Failed to load WASM module: ${e}`);
686
+ initPromise = null;
687
+ throw new Error(`Failed to initialize WASM: ${e}. Make sure the .wasm file is served at: ${url}`);
1428
688
  }
1429
689
  })();
1430
- return loadPromise;
690
+ return initPromise;
1431
691
  }
1432
692
  function isWasmLoaded() {
1433
- return wasmModule !== null;
693
+ return wasm !== null;
694
+ }
695
+ async function ensureWasm() {
696
+ if (!wasm) {
697
+ await initWasm();
698
+ }
1434
699
  }
1435
- function getOutputData(result) {
1436
- if (!wasmMemory) throw new Error("WASM memory not available");
1437
- const buffer = new Uint8Array(wasmMemory.buffer, result.ptr, result.len);
700
+ function getOutputData(ptr, len) {
701
+ const buffer = getUint8Memory().subarray(ptr, ptr + len);
1438
702
  return new Uint8ClampedArray(buffer.slice());
1439
703
  }
1440
704
  function toUint8Array(input) {
@@ -1460,46 +724,49 @@ var CrtCpuRenderer = class _CrtCpuRenderer {
1460
724
  constructor() {
1461
725
  this.ready = false;
1462
726
  }
1463
- /** Create and initialize renderer */
727
+ /** Create and initialize renderer (auto-loads WASM) */
1464
728
  static async create() {
729
+ await ensureWasm();
1465
730
  const renderer = new _CrtCpuRenderer();
1466
- await renderer.init();
731
+ renderer.ready = true;
1467
732
  return renderer;
1468
733
  }
1469
- async init() {
1470
- await loadWasm();
1471
- this.ready = true;
1472
- }
1473
- /** Check if renderer is ready */
1474
734
  isReady() {
1475
- return this.ready;
735
+ return this.ready && isWasmLoaded();
1476
736
  }
1477
- /** Render CRT effect */
1478
737
  render(input, options = {}) {
1479
- if (!this.ready || !wasmModule) {
738
+ if (!this.ready || !wasm) {
1480
739
  throw new Error("Renderer not initialized");
1481
740
  }
1482
741
  const data = toUint8Array(input);
1483
742
  const width = input.width;
1484
743
  const height = input.height;
1485
744
  const scale = Math.min(32, Math.max(2, options.scale ?? 3));
1486
- const config = new wasmModule.CrtConfig();
1487
- config.warp_x = options.warpX ?? 0.015;
1488
- config.warp_y = options.warpY ?? 0.02;
1489
- config.scan_hardness = options.scanHardness ?? -4;
1490
- config.scan_opacity = options.scanOpacity ?? 0.5;
1491
- config.mask_opacity = options.maskOpacity ?? 0.3;
1492
- config.enable_warp = options.enableWarp !== false;
1493
- config.enable_scanlines = options.enableScanlines !== false;
1494
- config.enable_mask = options.enableMask !== false;
1495
- const result = wasmModule.crt_upscale_config(data, width, height, scale, config);
745
+ const ptr = passArray8ToWasm(data);
746
+ const resultPtr = wasm.crt_upscale_raw(
747
+ ptr,
748
+ WASM_VECTOR_LEN,
749
+ width,
750
+ height,
751
+ scale,
752
+ options.warpX ?? 0.015,
753
+ options.warpY ?? 0.02,
754
+ options.scanHardness ?? -4,
755
+ options.scanOpacity ?? 0.5,
756
+ options.maskOpacity ?? 0.3,
757
+ options.enableWarp !== false ? 1 : 0,
758
+ options.enableScanlines !== false ? 1 : 0,
759
+ options.enableMask !== false ? 1 : 0
760
+ );
761
+ const outWidth = width * scale;
762
+ const outHeight = height * scale;
763
+ const outLen = outWidth * outHeight * 4;
1496
764
  return {
1497
- data: getOutputData(result),
1498
- width: result.width,
1499
- height: result.height
765
+ data: getOutputData(resultPtr, outLen),
766
+ width: outWidth,
767
+ height: outHeight
1500
768
  };
1501
769
  }
1502
- /** Dispose resources */
1503
770
  dispose() {
1504
771
  this.ready = false;
1505
772
  }
@@ -1508,51 +775,68 @@ var HexCpuRenderer = class _HexCpuRenderer {
1508
775
  constructor() {
1509
776
  this.ready = false;
1510
777
  }
1511
- /** Create and initialize renderer */
1512
778
  static async create() {
779
+ await ensureWasm();
1513
780
  const renderer = new _HexCpuRenderer();
1514
- await renderer.init();
781
+ renderer.ready = true;
1515
782
  return renderer;
1516
783
  }
1517
- async init() {
1518
- await loadWasm();
1519
- this.ready = true;
1520
- }
1521
- /** Check if renderer is ready */
1522
784
  isReady() {
1523
- return this.ready;
785
+ return this.ready && isWasmLoaded();
1524
786
  }
1525
- /** Render hexagonal effect */
1526
787
  render(input, options = {}) {
1527
- if (!this.ready || !wasmModule) {
788
+ if (!this.ready || !wasm) {
1528
789
  throw new Error("Renderer not initialized");
1529
790
  }
1530
791
  const data = toUint8Array(input);
1531
792
  const width = input.width;
1532
793
  const height = input.height;
1533
794
  const scale = Math.min(32, Math.max(2, options.scale ?? 16));
1534
- const config = new wasmModule.HexConfig();
1535
- config.orientation = options.orientation === "pointy-top" ? 1 : 0;
1536
- config.draw_borders = options.drawBorders ?? false;
1537
- config.border_color = parseColorToU32(options.borderColor, 673720575);
1538
- config.border_thickness = options.borderThickness ?? 1;
1539
- config.background_color = parseColorToU32(options.backgroundColor, 0);
1540
- const result = wasmModule.hex_upscale_config(data, width, height, scale, config);
795
+ const orientation = options.orientation === "pointy-top" ? 1 : 0;
796
+ const ptr = passArray8ToWasm(data);
797
+ const resultPtr = wasm.hex_upscale_raw(
798
+ ptr,
799
+ WASM_VECTOR_LEN,
800
+ width,
801
+ height,
802
+ scale,
803
+ orientation,
804
+ options.drawBorders ? 1 : 0,
805
+ parseColorToU32(options.borderColor, 673720575),
806
+ options.borderThickness ?? 1,
807
+ parseColorToU32(options.backgroundColor, 0)
808
+ );
809
+ const dims = this.getDimensions(width, height, scale, options.orientation);
810
+ const outLen = dims.width * dims.height * 4;
1541
811
  return {
1542
- data: getOutputData(result),
1543
- width: result.width,
1544
- height: result.height
812
+ data: getOutputData(resultPtr, outLen),
813
+ width: dims.width,
814
+ height: dims.height
1545
815
  };
1546
816
  }
1547
- /** Get output dimensions */
1548
817
  getDimensions(srcWidth, srcHeight, scale, orientation = "flat-top") {
1549
- if (!this.ready || !wasmModule) {
1550
- throw new Error("Renderer not initialized");
818
+ const SQRT3 = 1.732050808;
819
+ scale = Math.min(32, Math.max(2, scale));
820
+ if (orientation === "flat-top") {
821
+ const hSpacing = scale * 1.5;
822
+ const vSpacing = scale * SQRT3;
823
+ const cellWidth = scale * 2;
824
+ const cellHeight = scale * SQRT3;
825
+ return {
826
+ width: Math.ceil(srcWidth * hSpacing + cellWidth),
827
+ height: Math.ceil(srcHeight * vSpacing + cellHeight)
828
+ };
829
+ } else {
830
+ const hSpacing = scale * SQRT3;
831
+ const vSpacing = scale * 1.5;
832
+ const cellWidth = scale * SQRT3;
833
+ const cellHeight = scale * 2;
834
+ return {
835
+ width: Math.ceil(srcWidth * hSpacing + cellWidth),
836
+ height: Math.ceil(srcHeight * vSpacing + cellHeight)
837
+ };
1551
838
  }
1552
- const dims = wasmModule.hex_get_dimensions(srcWidth, srcHeight, scale, orientation === "pointy-top" ? 1 : 0);
1553
- return { width: dims[0], height: dims[1] };
1554
839
  }
1555
- /** Dispose resources */
1556
840
  dispose() {
1557
841
  this.ready = false;
1558
842
  }
@@ -1561,42 +845,44 @@ var XbrzCpuRenderer = class _XbrzCpuRenderer {
1561
845
  constructor() {
1562
846
  this.ready = false;
1563
847
  }
1564
- /** Create and initialize renderer */
1565
848
  static async create() {
849
+ await ensureWasm();
1566
850
  const renderer = new _XbrzCpuRenderer();
1567
- await renderer.init();
851
+ renderer.ready = true;
1568
852
  return renderer;
1569
853
  }
1570
- async init() {
1571
- await loadWasm();
1572
- this.ready = true;
1573
- }
1574
- /** Check if renderer is ready */
1575
854
  isReady() {
1576
- return this.ready;
855
+ return this.ready && isWasmLoaded();
1577
856
  }
1578
- /** Render xBRZ scaling */
1579
857
  render(input, options = {}) {
1580
- if (!this.ready || !wasmModule) {
858
+ if (!this.ready || !wasm) {
1581
859
  throw new Error("Renderer not initialized");
1582
860
  }
1583
861
  const data = toUint8Array(input);
1584
862
  const width = input.width;
1585
863
  const height = input.height;
1586
864
  const scale = Math.min(6, Math.max(2, options.scale ?? 2));
1587
- const config = new wasmModule.XbrzConfig();
1588
- config.luminance_weight = options.luminanceWeight ?? 1;
1589
- config.equal_color_tolerance = options.equalColorTolerance ?? 30;
1590
- config.dominant_direction_threshold = options.dominantDirectionThreshold ?? 4.4;
1591
- config.steep_direction_threshold = options.steepDirectionThreshold ?? 2.2;
1592
- const result = wasmModule.xbrz_upscale_config(data, width, height, scale, config);
865
+ const ptr = passArray8ToWasm(data);
866
+ const resultPtr = wasm.xbrz_upscale_raw(
867
+ ptr,
868
+ WASM_VECTOR_LEN,
869
+ width,
870
+ height,
871
+ scale,
872
+ options.luminanceWeight ?? 1,
873
+ options.equalColorTolerance ?? 30,
874
+ options.dominantDirectionThreshold ?? 4.4,
875
+ options.steepDirectionThreshold ?? 2.2
876
+ );
877
+ const outWidth = width * scale;
878
+ const outHeight = height * scale;
879
+ const outLen = outWidth * outHeight * 4;
1593
880
  return {
1594
- data: getOutputData(result),
1595
- width: result.width,
1596
- height: result.height
881
+ data: getOutputData(resultPtr, outLen),
882
+ width: outWidth,
883
+ height: outHeight
1597
884
  };
1598
885
  }
1599
- /** Dispose resources */
1600
886
  dispose() {
1601
887
  this.ready = false;
1602
888
  }
@@ -1638,13 +924,11 @@ function getMaxTextureSize() {
1638
924
  }
1639
925
  }
1640
926
  var CrtEngine = class {
1641
- constructor(gpuAvailable, cpuAvailable) {
927
+ constructor(gpuAvailable) {
1642
928
  this.gpuRenderer = null;
1643
929
  this.cpuRenderer = null;
1644
930
  this.gpuAvailable = gpuAvailable;
1645
- this.cpuAvailable = cpuAvailable;
1646
931
  }
1647
- /** Initialize GPU renderer */
1648
932
  ensureGpu() {
1649
933
  if (!this.gpuRenderer && this.gpuAvailable) {
1650
934
  this.gpuRenderer = CrtGpuRenderer.create();
@@ -1652,12 +936,10 @@ var CrtEngine = class {
1652
936
  if (!this.gpuRenderer) throw new Error("GPU renderer not available");
1653
937
  return this.gpuRenderer;
1654
938
  }
1655
- /** Initialize CPU renderer */
1656
939
  async ensureCpu() {
1657
- if (!this.cpuRenderer && this.cpuAvailable) {
940
+ if (!this.cpuRenderer) {
1658
941
  this.cpuRenderer = await CrtCpuRenderer.create();
1659
942
  }
1660
- if (!this.cpuRenderer) throw new Error("CPU renderer not available");
1661
943
  return this.cpuRenderer;
1662
944
  }
1663
945
  async render(input, optionsOrPreset, overrides) {
@@ -1682,7 +964,6 @@ var CrtEngine = class {
1682
964
  renderSync(input, options) {
1683
965
  return this.ensureGpu().render(input, options ?? {});
1684
966
  }
1685
- /** Dispose resources */
1686
967
  dispose() {
1687
968
  this.gpuRenderer?.dispose();
1688
969
  this.cpuRenderer?.dispose();
@@ -1691,11 +972,10 @@ var CrtEngine = class {
1691
972
  }
1692
973
  };
1693
974
  var HexEngine = class {
1694
- constructor(gpuAvailable, cpuAvailable) {
975
+ constructor(gpuAvailable) {
1695
976
  this.gpuRenderer = null;
1696
977
  this.cpuRenderer = null;
1697
978
  this.gpuAvailable = gpuAvailable;
1698
- this.cpuAvailable = cpuAvailable;
1699
979
  }
1700
980
  ensureGpu() {
1701
981
  if (!this.gpuRenderer && this.gpuAvailable) {
@@ -1705,10 +985,9 @@ var HexEngine = class {
1705
985
  return this.gpuRenderer;
1706
986
  }
1707
987
  async ensureCpu() {
1708
- if (!this.cpuRenderer && this.cpuAvailable) {
988
+ if (!this.cpuRenderer) {
1709
989
  this.cpuRenderer = await HexCpuRenderer.create();
1710
990
  }
1711
- if (!this.cpuRenderer) throw new Error("CPU renderer not available");
1712
991
  return this.cpuRenderer;
1713
992
  }
1714
993
  async render(input, optionsOrPreset, overrides) {
@@ -1729,11 +1008,9 @@ var HexEngine = class {
1729
1008
  const cpu = await this.ensureCpu();
1730
1009
  return cpu.render(input, options);
1731
1010
  }
1732
- /** Render synchronously (GPU only) */
1733
1011
  renderSync(input, options) {
1734
1012
  return this.ensureGpu().render(input, options ?? {});
1735
1013
  }
1736
- /** Get output dimensions */
1737
1014
  getDimensions(srcWidth, srcHeight, options) {
1738
1015
  const scale = options?.scale ?? 16;
1739
1016
  const orientation = options?.orientation ?? "flat-top";
@@ -1747,15 +1024,13 @@ var HexEngine = class {
1747
1024
  }
1748
1025
  };
1749
1026
  var XbrzEngine = class {
1750
- constructor(cpuAvailable) {
1027
+ constructor() {
1751
1028
  this.cpuRenderer = null;
1752
- this.cpuAvailable = cpuAvailable;
1753
1029
  }
1754
1030
  async ensureCpu() {
1755
- if (!this.cpuRenderer && this.cpuAvailable) {
1031
+ if (!this.cpuRenderer) {
1756
1032
  this.cpuRenderer = await XbrzCpuRenderer.create();
1757
1033
  }
1758
- if (!this.cpuRenderer) throw new Error("CPU renderer not available");
1759
1034
  return this.cpuRenderer;
1760
1035
  }
1761
1036
  async render(input, optionsOrPreset, overrides) {
@@ -1768,7 +1043,6 @@ var XbrzEngine = class {
1768
1043
  const cpu = await this.ensureCpu();
1769
1044
  return cpu.render(input, options);
1770
1045
  }
1771
- /** Get output dimensions */
1772
1046
  getDimensions(srcWidth, srcHeight, scale = 2) {
1773
1047
  const s = Math.min(6, Math.max(2, scale));
1774
1048
  return { width: srcWidth * s, height: srcHeight * s };
@@ -1779,37 +1053,38 @@ var XbrzEngine = class {
1779
1053
  }
1780
1054
  };
1781
1055
  var RenderArt = class _RenderArt {
1782
- constructor(gpuAvailable, cpuAvailable) {
1783
- this.crt = new CrtEngine(gpuAvailable, cpuAvailable);
1784
- this.hex = new HexEngine(gpuAvailable, cpuAvailable);
1785
- this.xbrz = new XbrzEngine(cpuAvailable);
1056
+ constructor(gpuAvailable) {
1057
+ this.crt = new CrtEngine(gpuAvailable);
1058
+ this.hex = new HexEngine(gpuAvailable);
1059
+ this.xbrz = new XbrzEngine();
1786
1060
  const maxTextureSize = gpuAvailable ? getMaxTextureSize() : 0;
1787
1061
  this._capabilities = {
1788
1062
  gpu: gpuAvailable,
1789
- cpu: cpuAvailable,
1063
+ cpu: true,
1064
+ // Always potentially available via async init
1790
1065
  maxTextureSize,
1791
- recommendedBackend: gpuAvailable ? "gpu" : cpuAvailable ? "cpu" : "auto"
1066
+ recommendedBackend: gpuAvailable ? "gpu" : "cpu"
1792
1067
  };
1793
1068
  }
1794
- /** Create and initialize RenderArt instance */
1795
- static async create() {
1069
+ /** Create RenderArt instance */
1070
+ static create() {
1796
1071
  const gpuAvailable = checkWebGL2();
1797
- let cpuAvailable = false;
1798
- try {
1799
- await loadWasm();
1800
- cpuAvailable = isWasmLoaded();
1801
- } catch {
1802
- }
1803
- if (!gpuAvailable && !cpuAvailable) {
1804
- throw new Error("No rendering backend available. WebGL2 or WASM required.");
1072
+ return new _RenderArt(gpuAvailable);
1073
+ }
1074
+ /** Create GPU-only instance */
1075
+ static createGpuOnly() {
1076
+ if (!checkWebGL2()) {
1077
+ throw new Error("WebGL2 not supported");
1805
1078
  }
1806
- return new _RenderArt(gpuAvailable, cpuAvailable);
1079
+ return new _RenderArt(true);
1080
+ }
1081
+ /** Pre-initialize WASM for faster first CPU render */
1082
+ async preloadWasm(wasmUrl2) {
1083
+ await initWasm(wasmUrl2);
1807
1084
  }
1808
- /** Get renderer capabilities */
1809
1085
  get capabilities() {
1810
1086
  return { ...this._capabilities };
1811
1087
  }
1812
- /** Dispose all resources */
1813
1088
  dispose() {
1814
1089
  this.crt.dispose();
1815
1090
  this.hex.dispose();
@@ -1819,15 +1094,19 @@ var RenderArt = class _RenderArt {
1819
1094
 
1820
1095
  exports.CRT_PRESETS = CRT_PRESETS;
1821
1096
  exports.CrtCpuRenderer = CrtCpuRenderer;
1097
+ exports.CrtEngine = CrtEngine;
1822
1098
  exports.CrtGpuRenderer = CrtGpuRenderer;
1823
1099
  exports.HEX_PRESETS = HEX_PRESETS;
1824
1100
  exports.HexCpuRenderer = HexCpuRenderer;
1101
+ exports.HexEngine = HexEngine;
1825
1102
  exports.HexGpuRenderer = HexGpuRenderer;
1826
1103
  exports.RenderArt = RenderArt;
1827
1104
  exports.XBRZ_PRESETS = XBRZ_PRESETS;
1828
1105
  exports.XbrzCpuRenderer = XbrzCpuRenderer;
1106
+ exports.XbrzEngine = XbrzEngine;
1829
1107
  exports.hexGetDimensions = hexGetDimensions;
1108
+ exports.initWasm = initWasm;
1830
1109
  exports.isWasmLoaded = isWasmLoaded;
1831
- exports.loadWasm = loadWasm;
1110
+ exports.setWasmUrl = setWasmUrl;
1832
1111
  //# sourceMappingURL=index.js.map
1833
1112
  //# sourceMappingURL=index.js.map