'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var crossFetch = require('cross-fetch');
var fs = require('fs');
var createGLContext = require('gl');
var core = require('pixijs/core');
var NodeCanvasElement = require('./NodeCanvasElement.js');
var xmldom = require('@xmldom/xmldom');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

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

Object.defineProperty(exports, 'settings', {
    enumerable: true,
    get: function () { return core.settings; }
});
exports.NodeAdapter = NodeAdapter;
//# sourceMappingURL=adapter.js.map
