haven 0.1.4

Actix + React + Vite integration for server-rendered applications
Documentation
class RuntimePort {
  constructor() {
    this.peer = null;
    this.onmessage = null;
  }

  postMessage(value) {
    const peer = this.peer;
    Promise.resolve().then(() => {
      if (peer?.onmessage) {
        peer.onmessage({ data: value });
      }
    });
  }
}

if (!globalThis.MessageChannel) {
  globalThis.MessageChannel = class MessageChannel {
    constructor() {
      this.port1 = new RuntimePort();
      this.port2 = new RuntimePort();
      this.port1.peer = this.port2;
      this.port2.peer = this.port1;
    }
  };
}

if (!globalThis.TextEncoder) {
  globalThis.TextEncoder = class TextEncoder {
    encode(input = "") {
      const encoded = unescape(encodeURIComponent(String(input)));
      const bytes = new Uint8Array(encoded.length);
      for (let i = 0; i < encoded.length; i += 1) {
        bytes[i] = encoded.charCodeAt(i);
      }
      return bytes;
    }
  };
}

if (!globalThis.TextDecoder) {
  globalThis.TextDecoder = class TextDecoder {
    decode(input = new Uint8Array()) {
      const bytes = input instanceof Uint8Array ? input : new Uint8Array(input);
      let value = "";
      for (let i = 0; i < bytes.length; i += 1) {
        value += String.fromCharCode(bytes[i]);
      }
      return decodeURIComponent(escape(value));
    }
  };
}

if (!globalThis.process) {
  globalThis.process = {
    env: {
      NODE_ENV: "production",
    },
  };
}

if (!globalThis.global) {
  globalThis.global = globalThis;
}

globalThis.__RUNTIME__ = {
  now() {
    return Deno.core.ops.op_now();
  },
  sleep(ms) {
    return Deno.core.ops.op_sleep(Number(ms));
  },
  log(level, message) {
    return Deno.core.ops.op_log(level, String(message));
  },
};

globalThis.__RUNTIME_I18N__ = {
  t(key, params = {}, locale) {
    const activeLocale =
      locale ??
      globalThis.__RUNTIME_PAGE__?.page?.locale ??
      globalThis.__RUNTIME_CONFIG__?.locale ??
      "en";
    return Deno.core.ops.op_translate(
      String(activeLocale),
      String(key),
      JSON.stringify(params ?? {}),
    );
  },
};

globalThis.__RUNTIME_STREAM__ = {
  write(chunk) {
    Deno.core.ops.op_stream_chunk(String(chunk));
  },
};

globalThis.console = {
  log(...args) {
    globalThis.__RUNTIME__.log("info", args.join(" "));
  },
  warn(...args) {
    globalThis.__RUNTIME__.log("warn", args.join(" "));
  },
  error(...args) {
    globalThis.__RUNTIME__.log("error", args.join(" "));
  },
};