```worker_inline.stub.mjs
/* ──────────────────────────────────────────────────────────────
   INLINE WORKER – “file:// edition”
   (gzip → text) ES-MODULE – no DOM dependencies
   ----------------------------------------------------------------
   Added / kept
     • global URL REGISTRYistry   (all inline-generated blob: URLs)
     • single beforeunload gc/release for every stub
     • lazy-promise helpers (blob / url)
     • explicit dispose()
────────────────────────────────────────────────────────────────*/

const filePath = '$__WORKER_PATH__';          // ↖ used only if you want
                                              //   fetch-redirect support
let GZ_B64_SRC = `$__WORKER_B64_GZ__`;      // ← injected at build-time

/*─────────────────────────────────────────────────────────────────────
  ❶  Global REGISTRYistry & single beforeunload hook
─────────────────────────────────────────────────────────────────────*/
const REGISTRY = globalThis[
  Symbol.for('__INLINE_WORKER_URL_REGISTRYISTRY__')
] ||= new Map();                              // filePath? → blobURL

const BOOT = Symbol.for('__INLINE_WORKER_BOOTSTRAPPED__');
if (!globalThis[BOOT]) {
  globalThis[BOOT] = true;

  /* optional fetch-redirect (skip if not needed) */
  const origFetch = globalThis.fetch?.bind(globalThis);
  if (origFetch) {
    globalThis.fetch = (req, init) => {
      const url =
          typeof req === 'string' ? req
        : req instanceof Request   ? req.url
        : req instanceof URL       ? req.href
        : '';

      for (const [p, blobURL] of REGISTRY)
        if (url.endsWith(p)) return origFetch(blobURL, init);

      return origFetch(req, init);
    };
  }

  /* global release */
  addEventListener('beforeunload', () => {
    for (const u of REGISTRY.values()) URL.revokeObjectURL(u);
    REGISTRY.clear();
  });
}

/*─────────────────────────────────────────────────────────────────────
  ❷  Payload guards / helpers
─────────────────────────────────────────────────────────────────────*/
GZ_B64_SRC = GZ_B64_SRC?.trim();
if (!GZ_B64_SRC || GZ_B64_SRC[0] === '$') {
  throw new Error('Inline worker payload missing');
}

const b64ToU8 = b64 => {
  const bin = atob(b64);
  return Uint8Array.from({ length: bin.length }, (_, i) => bin.charCodeAt(i));
};

const asStream = u8 => new ReadableStream({
  start(c) { c.enqueue(u8); c.close(); }
});

/*─────────────────────────────────────────────────────────────────────
  ❸  Main promise – “workerReady”
─────────────────────────────────────────────────────────────────────*/
export const workerReady = (async () => {
  const compressed = b64ToU8(GZ_B64_SRC);

  const stream = 'DecompressionStream' in globalThis
    ? asStream(compressed).pipeThrough(new DecompressionStream('gzip'))
    : asStream(
        (await import(
          'https://cdn.jsdelivr.net/npm/fflate@0.8.0/esm/browser.js'
        )).gunzipSync(compressed)
      );

  const workerCode = await new Response(stream).text();

  /* GC-hints */
  GZ_B64_SRC = undefined;
  compressed.fill(0);

  /* ── lazy memoised helpers ─────────────────────────── */
  let blobP, urlP;

  const workerBlobPromise = () =>
    blobP ||= Promise.resolve(
      new Blob([workerCode], { type: 'application/javascript' })
    );

  const workerURLPromise = () =>
    urlP ||= (async () => {
      const url = URL.createObjectURL(await workerBlobPromise());
      if (filePath) REGISTRY.set(filePath, url);
      return url;
    })();

  /* quick one-shot helper: spawn() */
  const spawn = async (opts = {}) =>
    new Worker(await workerURLPromise(), opts);

  const disposeURL = () => {
    const url = REGISTRY.get(filePath);
    if (url) {
      URL.revokeObjectURL(url);
      REGISTRY.delete(filePath);
    }
  }

  return { workerCode, workerBlobPromise, workerURLPromise, spawn, disposeURL };
})();

export default workerReady;

```

```wasm_inline.stub.mjs
/* ──────────────────────────────────────────────────────────────
   INLINE WASM  –  “file:// edition”
   (gzip → bytes)  ES-MODULE  –  no DOM dependencies
   ----------------------------------------------------------------
   Added / kept
     • global fetch-redirect registry
     • compile-streaming + fallback
     • isWasmReady flag, sync/async helpers, releaseWasm()
────────────────────────────────────────────────────────────────*/

const filePath = '$__WASM_PATH__';          // injected at build-time
let GZ_B64_SRC = `$__WASM_B64_GZ__`;      // ← injected at build-time

// global registry shared by all inline stubs
const REGISTRY = globalThis[
  Symbol.for('__INLINE_WASM_FETCH_REGISTRY__')
] ||= new Map();                               // filePath → blob:

// ONE flag → has bootstrap run?
const BOOT = Symbol.for('__INLINE_WASM_BOOTSTRAPPED__');

if (!globalThis[BOOT]) {
  globalThis[BOOT] = true;

  /* fetch redirect --------------------------------------------------- */
  const origFetch = globalThis.fetch.bind(globalThis);
  globalThis.fetch = (req, init) => {
    const url =
      typeof req === 'string' ? req
    : req instanceof Request    ? req.url
    : req instanceof URL        ? req.href
    : '';

    for (const [path, blobURL] of REGISTRY)
      if (url.endsWith(path)) return origFetch(blobURL, init);

    return origFetch(req, init);
  };

  /* beforeunload cleanup --------------------------------------------- */
  addEventListener('beforeunload', () => {
    for (const u of REGISTRY.values()) URL.revokeObjectURL(u);
    REGISTRY.clear();
  });
}

/*─────────────────────────────────────────────────────────────────────
  gzip-base64 payload
─────────────────────────────────────────────────────────────────────*/
GZ_B64_SRC = GZ_B64_SRC?.trim();
if (!GZ_B64_SRC || GZ_B64_SRC[0] === '$') {
  throw new Error('Inline WASM payload missing');
}

/* helpers */
const b64ToU8 = b64 => {
  const bin = atob(b64);
  return Uint8Array.from({ length: bin.length }, (_, i) => bin.charCodeAt(i));
};
const asStream = u8 => new ReadableStream({
  start(c) { c.enqueue(u8); c.close(); }
});

/* main promise */
export const wasmReady = (async () => {
  const compressed = b64ToU8(GZ_B64_SRC);

  const stream = 'DecompressionStream' in globalThis
    ? asStream(compressed).pipeThrough(new DecompressionStream('gzip'))
    : asStream(
        (await import(
          'https://cdn.jsdelivr.net/npm/fflate@0.8.0/esm/browser.js'
        )).gunzipSync(compressed)
      );

  const wasmBuffer = await new Response(stream).arrayBuffer();

  // GC-hints
  GZ_B64_SRC = undefined;
  compressed.fill(0);

  /* lazy helpers (memoised) */
  let blobP, urlP, modP;

  const wasmBlobPromise = () =>
    blobP ||= Promise.resolve(new Blob([wasmBuffer], { type: 'application/wasm' }));

  const wasmURLPromise = () =>
    urlP ||= (async () => {
      const url = URL.createObjectURL(await wasmBlobPromise());
      if (filePath) REGISTRY.set(filePath, url);
      return url;
    })();

  const modulePromise = () => modP ||= WebAssembly.compile(wasmBuffer);

  const instantiate = async (imports = {}) => {
    const module = await modulePromise();
    return { module, instance: new WebAssembly.Instance(module, imports) };
  };

  const disposeURL = () => {
    const url = REGISTRY.get(filePath);
    if (url) {
      URL.revokeObjectURL(url);
      REGISTRY.delete(filePath);
    }
  }

  return { wasmBuffer, wasmBlobPromise, wasmURLPromise, modulePromise, instantiate, disposeURL };
})();

export default wasmReady;
```

the two stub dup many code. help refactor the common things out into another importable module usable by both. goal is to DRY.