UNPKG

mdx-scoped-runtime

Version:
82 lines (55 loc) 5.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireDefault(require("react")); var _buble = require("buble"); var _mdx = _interopRequireDefault(require("@mdx-js/mdx")); var _tag = require("@mdx-js/tag"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); } function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? Object(arguments[i]) : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } var _default = function _default(_ref) { var _ref$scope = _ref.scope, scope = _ref$scope === void 0 ? {} : _ref$scope, _ref$components = _ref.components, components = _ref$components === void 0 ? {} : _ref$components, _ref$mdPlugins = _ref.mdPlugins, mdPlugins = _ref$mdPlugins === void 0 ? [] : _ref$mdPlugins, _ref$hastPlugins = _ref.hastPlugins, hastPlugins = _ref$hastPlugins === void 0 ? [] : _ref$hastPlugins, children = _ref.children, props = _objectWithoutProperties(_ref, ["scope", "components", "mdPlugins", "hastPlugins", "children"]); var fullScope = _objectSpread({ MDXTag: _tag.MDXTag, components: components, props: props }, scope); var jsx = _mdx.default.sync(children, { mdPlugins: mdPlugins, hastPlugins: hastPlugins, skipExport: true }).trim(); var _transform = (0, _buble.transform)(jsx, { objectAssign: 'Object.assign' }), code = _transform.code; var keys = Object.keys(fullScope); var values = Object.values(fullScope); // eslint-disable-next-line no-new-func var fn = _construct(Function, ['_fn', 'React'].concat(_toConsumableArray(keys), ["".concat(code, "\n\n return React.createElement(MDXContent, { components, ...props });")])); return fn.apply(void 0, [{}, _react.default].concat(_toConsumableArray(values))); }; exports.default = _default; //# sourceMappingURL=MDX.js.map