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