import { Request, fetch, Response } from 'cross-fetch';
import fs from 'fs';
import { WebGLRenderingContext } from 'gl';
import { utils, settings } from 'pixijs/core';
export { settings } from 'pixijs/core';
import { NodeCanvasElement } from './NodeCanvasElement.mjs';
import { DOMParser } from '@xmldom/xmldom';

const NodeAdapter = {
  createCanvas: (width, height) => new NodeCanvasElement(width, height),
  getWebGLRenderingContext: () => WebGLRenderingContext,
  getNavigator: () => ({ userAgent: "node" }),
  getBaseUrl: () => process.cwd(),
  getFontFaceSet: () => null,
  fetch: (url, options) => {
    const request = new Request(url, options);
    if (utils.path.isUrl(request.url)) {
      return fetch(url, request);
    }
    return new Promise((resolve, reject) => {
      const filePath = utils.path.normalize(request.url);
      if (!fs.existsSync(filePath)) {
        reject(`File not found: ${filePath}`);
      }
      const readStream = fs.createReadStream(filePath);
      readStream.on("open", function() {
        resolve(new Response(readStream, {
          url: request.url,
          status: 200,
          statusText: "OK",
          size: fs.statSync(filePath).size,
          timeout: request.timeout
        }));
      });
    });
  },
  parseXML: (xml) => {
    const parser = new DOMParser();
    return parser.parseFromString(xml, "text/xml");
  }
};
settings.ADAPTER = NodeAdapter;

export { NodeAdapter };
//# sourceMappingURL=adapter.mjs.map
