(function (g) {
'use strict';
(function () {
var host = (typeof __hostConsole !== 'undefined') ? __hostConsole : null;
function isError(a) {
if (!a || typeof a !== 'object') return false;
if (a instanceof Error) return true;
var tag = Object.prototype.toString.call(a);
return tag === '[object Error]' || tag === '[object DOMException]';
}
function errorHead(a) {
return (a.name || 'Error') + (a.message ? ': ' + a.message : '');
}
function show(a) {
if (typeof a === 'string') return a;
if (isError(a)) {
var head = errorHead(a);
return a.stack ? head + '\n' + a.stack : head;
}
try {
var s = JSON.stringify(a, function (_k, x) {
if (typeof x === 'bigint') return x + 'n';
return isError(x) ? errorHead(x) : x;
});
return s === undefined ? String(a) : s;
} catch (e) { return String(a); }
}
var SPEC = /%([sdifoOjc%])/g;
function fmt(args) {
if (typeof args[0] !== 'string' || args.length < 2 || !/%[sdifoOjc%]/.test(args[0])) {
return args.map(show).join(' ');
}
var next = 1;
var out = args[0].replace(SPEC, function (whole, kind) {
if (kind === '%') return '%';
if (next >= args.length) return whole;
var a = args[next++];
switch (kind) {
case 'c': return '';
case 'd':
case 'i': return typeof a === 'symbol' || typeof a === 'bigint' ? String(a) : String(parseInt(a, 10));
case 'f': return typeof a === 'symbol' ? String(a) : String(parseFloat(a));
case 's': return typeof a === 'string' ? a : show(a);
default: return show(a);
}
});
for (; next < args.length; next++) out += ' ' + show(args[next]);
return out;
}
var forward = host
? function (name) { return function (...args) { try { host[name](...args); } catch (e) {} }; }
: function (name) {
var level = name === 'error' ? 3 : name === 'warn' ? 2 : 1;
return function (...args) { try { __rjs_print(level, fmt(args)); } catch (e) {} };
};
var noop = function () {};
g.console = {
log: forward('log'), info: forward('info'), warn: forward('warn'),
error: forward('error'), debug: forward('debug'), trace: forward('trace'),
clear: forward('clear'),
assert: function (cond, ...args) { if (!cond) g.console.error('Assertion failed:', ...args); },
dir: forward('log'), table: forward('log'),
group: forward('log'), groupCollapsed: forward('log'), groupEnd: noop,
count: noop, countReset: noop, time: noop, timeEnd: noop, timeLog: noop,
};
})();
if (typeof g.Request !== 'function') {
g.Request = class Request {
constructor(input, init) { init = init || {}; this.url = String((input && input.url) || input || ''); this.method = init.method || 'GET'; this.headers = new g.Headers(); }
};
}
(function () {
var fn = function () {};
Object.defineProperty(fn, Symbol.hasInstance, {
value: function (obj) {
if (obj == null) return false;
try { return obj.__brand === 'HTMLCanvasElement'; } catch (e) { return false; }
},
});
Object.defineProperty(fn.prototype, Symbol.toStringTag, { value: 'HTMLCanvasElement', configurable: true });
g.HTMLCanvasElement = fn;
})();
if (typeof g.HTMLVideoElement !== 'function') {
g.HTMLVideoElement = class HTMLVideoElement {};
Object.defineProperty(g.HTMLVideoElement.prototype, Symbol.toStringTag, { value: 'HTMLVideoElement', configurable: true });
}
if (typeof g.location === 'undefined') {
g.location = { href: 'app://redjs/', origin: 'app://redjs', protocol: 'app:', host: 'redjs', pathname: '/', search: '', hash: '', reload: function () {} };
}
if (typeof g.OffscreenCanvas !== 'function') {
class Ctx2D {
constructor(w, h) {
this.canvas = null; this.__w = w | 0; this.__h = h | 0;
this.__px = new Uint8ClampedArray(Math.max(0, this.__w * this.__h * 4));
this.fillStyle = '#000'; this.strokeStyle = '#000'; this.globalAlpha = 1; this.imageSmoothingEnabled = true;
}
drawImage(src, dx, dy) {
dx = (dx || 0) | 0; dy = (dy || 0) | 0;
var u = __rjs_sourcePixels(src); if (!u) return;
var sw = src.width | 0, sh = src.height | 0, W = this.__w, H = this.__h, px = this.__px;
for (var y = 0; y < sh; y++) {
var ty = dy + y; if (ty < 0 || ty >= H) continue;
for (var x = 0; x < sw; x++) {
var tx = dx + x; if (tx < 0 || tx >= W) continue;
var si = (y * sw + x) * 4, ti = (ty * W + tx) * 4;
px[ti] = u[si]; px[ti + 1] = u[si + 1]; px[ti + 2] = u[si + 2]; px[ti + 3] = u[si + 3];
}
}
}
getImageData(sx, sy, sw, sh) {
sx = sx | 0; sy = sy | 0; sw = sw | 0; sh = sh | 0;
var out = new Uint8ClampedArray(sw * sh * 4), W = this.__w, H = this.__h, px = this.__px;
for (var y = 0; y < sh; y++) {
var ry = sy + y; if (ry < 0 || ry >= H) continue;
for (var x = 0; x < sw; x++) {
var rx = sx + x; if (rx < 0 || rx >= W) continue;
var si = (ry * W + rx) * 4, di = (y * sw + x) * 4;
out[di] = px[si]; out[di + 1] = px[si + 1]; out[di + 2] = px[si + 2]; out[di + 3] = px[si + 3];
}
}
return new g.ImageData(out, sw, sh);
}
createImageData(w, h) { return new g.ImageData(w | 0, h | 0); }
putImageData() {} clearRect() {} fillRect() {} strokeRect() {} save() {} restore() {}
translate() {} scale() {} rotate() {} setTransform() {} resetTransform() {}
beginPath() {} closePath() {} moveTo() {} lineTo() {} arc() {} rect() {} fill() {} stroke() {} clip() {}
}
g.OffscreenCanvasRenderingContext2D = Ctx2D;
g.OffscreenCanvas = class OffscreenCanvas {
constructor(w, h) { this.width = w | 0; this.height = h | 0; }
getContext(type) { return (type === '2d') ? new Ctx2D(this.width, this.height) : null; }
transferToImageBitmap() { return null; }
};
Object.defineProperty(Ctx2D.prototype, Symbol.toStringTag, { value: 'OffscreenCanvasRenderingContext2D', configurable: true });
Object.defineProperty(g.OffscreenCanvas.prototype, Symbol.toStringTag, { value: 'OffscreenCanvas', configurable: true });
}
})(globalThis);