"use strict";

var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
exports.__esModule = true;
exports.visit = exports.traverse = exports.transclude = exports.toYAML = exports.toValue = exports.toString = exports.toJSON = exports.some = exports.sexprs = exports.reject = exports.refractorPluginSemanticElementIdentity = exports.refractorPluginElementIdentity = exports.refract = exports.parents = exports.namespace = exports.mergeAllVisitors = exports.keyMap = exports.isStringElement = exports.isSourceMapElement = exports.isRefElement = exports.isPrimitiveElement = exports.isParseResultElement = exports.isObjectElement = exports.isNumberElement = exports.isNullElement = exports.isMemberElement = exports.isLinkElement = exports.isElement = exports.isBooleanElement = exports.isArrayElement = exports.isAnnotationElement = exports.includesSymbols = exports.includesClasses = exports.hasElementSourceMap = exports.getNodeType = exports.from = exports.findAtOffset = exports.find = exports.filter = exports.dispatchRefractorPlugins = exports.dereference = exports.dehydrate = exports.deepmerge = exports.createPredicate = exports.createNamespace = exports.Transcluder = exports.StringElement = exports.SourceMapElement = exports.RefElement = exports.ParseResultElement = exports.ObjectSlice = exports.ObjectElement = exports.NumberElement = exports.NullElement = exports.Namespace = exports.MemberElement = exports.MediaTypes = exports.LinkElement = exports.KeyValuePair = exports.Element = exports.CommentElement = exports.BooleanElement = exports.BREAK = exports.ArraySlice = exports.ArrayElement = exports.AnnotationElement = void 0;
var _ramda = require("ramda");
var _ramdaAdjunct = require("ramda-adjunct");
require("./refractor/registration.cjs");
var _namespace = _interopRequireWildcard(require("./namespace.cjs"));
exports.namespace = _namespace.default;
exports.Namespace = _namespace.Namespace;
exports.createNamespace = _namespace.createNamespace;
var _index = _interopRequireDefault(require("./serializers/value/index.cjs"));
var _json = _interopRequireDefault(require("./serializers/json.cjs"));
var _yaml = _interopRequireDefault(require("./serializers/yaml-1-2.cjs"));
var _index2 = require("./refractor/plugins/utils/index.cjs");
exports.dispatchRefractorPlugins = _index2.dispatchPlugins;
var _elementIdentity = _interopRequireDefault(require("./refractor/plugins/element-identity.cjs"));
exports.refractorPluginElementIdentity = _elementIdentity.default;
var _semanticElementIdentity = _interopRequireDefault(require("./refractor/plugins/semantic-element-identity.cjs"));
exports.refractorPluginSemanticElementIdentity = _semanticElementIdentity.default;
var _mediaTypes = _interopRequireDefault(require("./media-types.cjs"));
exports.MediaTypes = _mediaTypes.default;
var _minim = require("minim");
exports.Element = _minim.Element;
exports.ObjectElement = _minim.ObjectElement;
exports.MemberElement = _minim.MemberElement;
exports.ArrayElement = _minim.ArrayElement;
exports.BooleanElement = _minim.BooleanElement;
exports.StringElement = _minim.StringElement;
exports.NullElement = _minim.NullElement;
exports.NumberElement = _minim.NumberElement;
exports.RefElement = _minim.RefElement;
exports.LinkElement = _minim.LinkElement;
exports.KeyValuePair = _minim.KeyValuePair;
exports.ObjectSlice = _minim.ObjectSlice;
exports.ArraySlice = _minim.ArraySlice;
exports.refract = _minim.refract;
var _Annotation = _interopRequireDefault(require("./elements/Annotation.cjs"));
exports.AnnotationElement = _Annotation.default;
var _Comment = _interopRequireDefault(require("./elements/Comment.cjs"));
exports.CommentElement = _Comment.default;
var _ParseResult = _interopRequireDefault(require("./elements/ParseResult.cjs"));
exports.ParseResultElement = _ParseResult.default;
var _SourceMap = _interopRequireDefault(require("./elements/SourceMap.cjs"));
exports.SourceMapElement = _SourceMap.default;
var _index3 = require("./predicates/index.cjs");
exports.isElement = _index3.isElement;
exports.isStringElement = _index3.isStringElement;
exports.isNumberElement = _index3.isNumberElement;
exports.isNullElement = _index3.isNullElement;
exports.isBooleanElement = _index3.isBooleanElement;
exports.isArrayElement = _index3.isArrayElement;
exports.isObjectElement = _index3.isObjectElement;
exports.isMemberElement = _index3.isMemberElement;
exports.isLinkElement = _index3.isLinkElement;
exports.isRefElement = _index3.isRefElement;
exports.isAnnotationElement = _index3.isAnnotationElement;
exports.isParseResultElement = _index3.isParseResultElement;
exports.isSourceMapElement = _index3.isSourceMapElement;
exports.isPrimitiveElement = _index3.isPrimitiveElement;
exports.hasElementSourceMap = _index3.hasElementSourceMap;
exports.includesSymbols = _index3.includesSymbols;
exports.includesClasses = _index3.includesClasses;
var _helpers = _interopRequireDefault(require("./predicates/helpers.cjs"));
exports.createPredicate = _helpers.default;
var _index4 = require("./traversal/index.cjs");
exports.filter = _index4.filter;
exports.reject = _index4.reject;
exports.find = _index4.find;
exports.findAtOffset = _index4.findAtOffset;
exports.some = _index4.some;
exports.traverse = _index4.traverse;
exports.parents = _index4.parents;
var _visitor = require("./traversal/visitor.cjs");
exports.visit = _visitor.visit;
exports.BREAK = _visitor.BREAK;
exports.mergeAllVisitors = _visitor.mergeAllVisitors;
exports.getNodeType = _visitor.getNodeType;
exports.keyMap = _visitor.keyMapDefault;
var _index5 = _interopRequireWildcard(require("./transcluder/index.cjs"));
exports.transclude = _index5.transclude;
exports.Transcluder = _index5.default;
var _util = require("./util.cjs");
exports.dereference = _util.dereference;
var _sexprs = _interopRequireDefault(require("./sexprs.cjs"));
exports.sexprs = _sexprs.default;
var _deepmerge = _interopRequireDefault(require("./deepmerge.cjs"));
exports.deepmerge = _deepmerge.default;
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
/**
 * Transforms data to an Element from a particular namespace.
 */
const from = (data, namespace = _namespace.default) => {
  if ((0, _ramdaAdjunct.isString)(data)) {
    // JSON serialized refract
    try {
      return namespace.fromRefract(JSON.parse(data));
    } catch {
      // noop
    }
  }
  if ((0, _ramdaAdjunct.isPlainObject)(data) && (0, _ramda.has)('element', data)) {
    // refract javascript structure
    return namespace.fromRefract(data);
  }
  return namespace.toElement(data);
};

/**
 * Transforms the ApiDOM into JavaScript POJO.
 * This POJO would be the result of interpreting the ApiDOM
 * into JavaScript structure.
 */
exports.from = from;
const toValue = _index.default;

/**
 * Transforms the ApiDOM into JSON string.
 */
exports.toValue = toValue;
const toJSON = _json.default;

/**
 * Transforms the ApiDOM into YAML string.
 */
exports.toJSON = toJSON;
const toYAML = _yaml.default;

/**
 * Creates a refract representation of an Element.
 * https://github.com/refractproject/refract-spec
 */
exports.toYAML = toYAML;
const dehydrate = (element, namespace = _namespace.default) => {
  return namespace.toRefract(element);
};

/**
 * Create a refracted string representation of an Element.
 */
exports.dehydrate = dehydrate;
const toString = (element, namespace = _namespace.default) => {
  const refractStructure = dehydrate(element, namespace);
  return JSON.stringify(refractStructure);
};
exports.toString = toString;