UNPKG

6.01 kBJavaScriptView Raw
1import React from 'react';
2import { transform } from 'buble-jsx-only';
3import mdx from '@mdx-js/mdx';
4import { mdx as mdx$1, MDXProvider } from '@mdx-js/react';
5
6function _defineProperty(obj, key, value) {
7 if (key in obj) {
8 Object.defineProperty(obj, key, {
9 value: value,
10 enumerable: true,
11 configurable: true,
12 writable: true
13 });
14 } else {
15 obj[key] = value;
16 }
17
18 return obj;
19}
20
21function ownKeys(object, enumerableOnly) {
22 var keys = Object.keys(object);
23
24 if (Object.getOwnPropertySymbols) {
25 var symbols = Object.getOwnPropertySymbols(object);
26 if (enumerableOnly) symbols = symbols.filter(function (sym) {
27 return Object.getOwnPropertyDescriptor(object, sym).enumerable;
28 });
29 keys.push.apply(keys, symbols);
30 }
31
32 return keys;
33}
34
35function _objectSpread2(target) {
36 for (var i = 1; i < arguments.length; i++) {
37 var source = arguments[i] != null ? arguments[i] : {};
38
39 if (i % 2) {
40 ownKeys(Object(source), true).forEach(function (key) {
41 _defineProperty(target, key, source[key]);
42 });
43 } else if (Object.getOwnPropertyDescriptors) {
44 Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
45 } else {
46 ownKeys(Object(source)).forEach(function (key) {
47 Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
48 });
49 }
50 }
51
52 return target;
53}
54
55function _setPrototypeOf(o, p) {
56 _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
57 o.__proto__ = p;
58 return o;
59 };
60
61 return _setPrototypeOf(o, p);
62}
63
64function _isNativeReflectConstruct() {
65 if (typeof Reflect === "undefined" || !Reflect.construct) return false;
66 if (Reflect.construct.sham) return false;
67 if (typeof Proxy === "function") return true;
68
69 try {
70 Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
71 return true;
72 } catch (e) {
73 return false;
74 }
75}
76
77function _construct(Parent, args, Class) {
78 if (_isNativeReflectConstruct()) {
79 _construct = Reflect.construct;
80 } else {
81 _construct = function _construct(Parent, args, Class) {
82 var a = [null];
83 a.push.apply(a, args);
84 var Constructor = Function.bind.apply(Parent, a);
85 var instance = new Constructor();
86 if (Class) _setPrototypeOf(instance, Class.prototype);
87 return instance;
88 };
89 }
90
91 return _construct.apply(null, arguments);
92}
93
94function _objectWithoutPropertiesLoose(source, excluded) {
95 if (source == null) return {};
96 var target = {};
97 var sourceKeys = Object.keys(source);
98 var key, i;
99
100 for (i = 0; i < sourceKeys.length; i++) {
101 key = sourceKeys[i];
102 if (excluded.indexOf(key) >= 0) continue;
103 target[key] = source[key];
104 }
105
106 return target;
107}
108
109function _objectWithoutProperties(source, excluded) {
110 if (source == null) return {};
111
112 var target = _objectWithoutPropertiesLoose(source, excluded);
113
114 var key, i;
115
116 if (Object.getOwnPropertySymbols) {
117 var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
118
119 for (i = 0; i < sourceSymbolKeys.length; i++) {
120 key = sourceSymbolKeys[i];
121 if (excluded.indexOf(key) >= 0) continue;
122 if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
123 target[key] = source[key];
124 }
125 }
126
127 return target;
128}
129
130function _toConsumableArray(arr) {
131 return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
132}
133
134function _arrayWithoutHoles(arr) {
135 if (Array.isArray(arr)) return _arrayLikeToArray(arr);
136}
137
138function _iterableToArray(iter) {
139 if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
140}
141
142function _unsupportedIterableToArray(o, minLen) {
143 if (!o) return;
144 if (typeof o === "string") return _arrayLikeToArray(o, minLen);
145 var n = Object.prototype.toString.call(o).slice(8, -1);
146 if (n === "Object" && o.constructor) n = o.constructor.name;
147 if (n === "Map" || n === "Set") return Array.from(n);
148 if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
149}
150
151function _arrayLikeToArray(arr, len) {
152 if (len == null || len > arr.length) len = arr.length;
153
154 for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
155
156 return arr2;
157}
158
159function _nonIterableSpread() {
160 throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
161}
162
163var index = (function (_ref) {
164 var _ref$scope = _ref.scope,
165 scope = _ref$scope === void 0 ? {} : _ref$scope,
166 _ref$components = _ref.components,
167 components = _ref$components === void 0 ? {} : _ref$components,
168 _ref$remarkPlugins = _ref.remarkPlugins,
169 remarkPlugins = _ref$remarkPlugins === void 0 ? [] : _ref$remarkPlugins,
170 _ref$rehypePlugins = _ref.rehypePlugins,
171 rehypePlugins = _ref$rehypePlugins === void 0 ? [] : _ref$rehypePlugins,
172 children = _ref.children,
173 props = _objectWithoutProperties(_ref, ["scope", "components", "remarkPlugins", "rehypePlugins", "children"]);
174
175 var fullScope = _objectSpread2({
176 mdx: mdx$1,
177 MDXProvider: MDXProvider,
178 components: components,
179 props: props
180 }, scope);
181
182 var jsx = mdx.sync(children, {
183 remarkPlugins: remarkPlugins,
184 rehypePlugins: rehypePlugins,
185 skipExport: true
186 }).trim();
187 var code;
188
189 try {
190 code = transform(jsx, {
191 objectAssign: 'Object.assign'
192 }).code;
193 } catch (err) {
194 console.error(err);
195 throw err;
196 }
197
198 var keys = Object.keys(fullScope);
199 var values = Object.values(fullScope); // eslint-disable-next-line no-new-func
200
201 var fn = _construct(Function, ['_fn', 'React'].concat(_toConsumableArray(keys), ["".concat(code, "\n\n return React.createElement(MDXProvider, { components },\n React.createElement(MDXContent, props)\n );")]));
202
203 return fn.apply(void 0, [{}, React].concat(_toConsumableArray(values)));
204});
205
206export default index;