@mintlify/common 1.0.1221 → 1.0.1222

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/mdx/getMDXOptions.d.ts +3 -1
  2. package/dist/mdx/getMDXOptions.js +7 -1
  3. package/dist/mdx/index.d.ts +1 -0
  4. package/dist/mdx/index.js +1 -0
  5. package/dist/mdx/islands/extractPackageIslands.d.ts +5 -0
  6. package/dist/mdx/islands/extractPackageIslands.js +147 -0
  7. package/dist/mdx/islands/index.d.ts +5 -0
  8. package/dist/mdx/islands/index.js +5 -0
  9. package/dist/mdx/islands/island-bindings.d.ts +40 -0
  10. package/dist/mdx/islands/island-bindings.js +149 -0
  11. package/dist/mdx/islands/island-module-builder.d.ts +37 -0
  12. package/dist/mdx/islands/island-module-builder.js +472 -0
  13. package/dist/mdx/islands/island-placement.d.ts +10 -0
  14. package/dist/mdx/islands/island-placement.js +229 -0
  15. package/dist/mdx/islands/packageImports.d.ts +28 -0
  16. package/dist/mdx/islands/packageImports.js +155 -0
  17. package/dist/mdx/islands/remarkPackageIslands.d.ts +23 -0
  18. package/dist/mdx/islands/remarkPackageIslands.js +177 -0
  19. package/dist/mdx/islands/sha256.d.ts +1 -0
  20. package/dist/mdx/islands/sha256.js +71 -0
  21. package/dist/mdx/islands/static-expressions.d.ts +24 -0
  22. package/dist/mdx/islands/static-expressions.js +169 -0
  23. package/dist/mdx/islands/types.d.ts +36 -0
  24. package/dist/mdx/islands/types.js +1 -0
  25. package/dist/mdx/plugins/remark/remarkMdxExpandExpressions.js +1 -1
  26. package/dist/mdx/plugins/remark/remarkMdxInjectSnippets.d.ts +4 -1
  27. package/dist/mdx/plugins/remark/remarkMdxInjectSnippets.js +68 -17
  28. package/dist/mdx/plugins/remark/remarkMdxRemoveJs.js +1 -1
  29. package/dist/mdx/plugins/remark/remarkResolveRelativeLinks.d.ts +1 -0
  30. package/dist/mdx/plugins/remark/remarkResolveRelativeLinks.js +6 -3
  31. package/dist/mdx/server-only/getMdx.d.ts +11 -1
  32. package/dist/mdx/server-only/getMdx.js +66 -31
  33. package/dist/mdx/server-only/index.d.ts +1 -1
  34. package/dist/mdx/server-only/index.js +1 -1
  35. package/dist/mdx/snippets/resolveAllImports.d.ts +3 -1
  36. package/dist/mdx/snippets/resolveAllImports.js +65 -1
  37. package/dist/mdx/static-object-keys.d.ts +1 -0
  38. package/dist/mdx/static-object-keys.js +1 -0
  39. package/dist/tsconfig.build.tsbuildinfo +1 -1
  40. package/dist/types/mdx/MdxExtracts.d.ts +6 -0
  41. package/package.json +2 -2
@@ -0,0 +1,472 @@
1
+ import { jsx as jsxHandlers, toJs } from 'estree-util-to-js';
2
+ import { parseInlineStyle } from '../../parse-inline-style.js';
3
+ import { resolveRelativeUrl } from '../plugins/remark/remarkResolveRelativeLinks.js';
4
+ import { allowedComponents } from '../utils.js';
5
+ import { bindingHead, lineOf } from './island-bindings.js';
6
+ import { isIntrinsic, isListLoose } from './island-placement.js';
7
+ import { UNSAFE_KEYS, identifier, literal, toStaticExpression, valueToExpression, } from './static-expressions.js';
8
+ const BLOCKED_ELEMENTS = new Set([
9
+ 'script',
10
+ 'style',
11
+ 'iframe',
12
+ 'object',
13
+ 'embed',
14
+ 'form',
15
+ 'base',
16
+ 'meta',
17
+ 'link',
18
+ 'foreignobject',
19
+ ]);
20
+ export const MOVE_TO_SNIPPET = 'Move this into a snippet.';
21
+ const MINTLIFY_COMPONENTS = new Set(allowedComponents);
22
+ const URL_ATTRIBUTES = new Map([
23
+ ['a', 'href'],
24
+ ['img', 'src'],
25
+ ['source', 'src'],
26
+ ]);
27
+ const container = (expression) => ({
28
+ type: 'JSXExpressionContainer',
29
+ expression,
30
+ });
31
+ const jsxName = (name) => {
32
+ if (name.includes(':')) {
33
+ const [namespace = '', local = ''] = name.split(':');
34
+ return {
35
+ type: 'JSXNamespacedName',
36
+ namespace: { type: 'JSXIdentifier', name: namespace },
37
+ name: { type: 'JSXIdentifier', name: local },
38
+ };
39
+ }
40
+ const [first = '', ...rest] = name.split('.');
41
+ let result = { type: 'JSXIdentifier', name: first };
42
+ for (const part of rest) {
43
+ result = {
44
+ type: 'JSXMemberExpression',
45
+ object: result,
46
+ property: { type: 'JSXIdentifier', name: part },
47
+ };
48
+ }
49
+ return result;
50
+ };
51
+ const jsxElement = (name, attributes, children) => {
52
+ const elementName = jsxName(name);
53
+ const selfClosing = children.length === 0;
54
+ return {
55
+ type: 'JSXElement',
56
+ openingElement: { type: 'JSXOpeningElement', name: elementName, attributes, selfClosing },
57
+ closingElement: selfClosing ? null : { type: 'JSXClosingElement', name: jsxName(name) },
58
+ children,
59
+ };
60
+ };
61
+ const jsxAttribute = (name, value) => {
62
+ const attributeName = jsxName(name);
63
+ return {
64
+ type: 'JSXAttribute',
65
+ name: attributeName.type === 'JSXMemberExpression'
66
+ ? { type: 'JSXIdentifier', name }
67
+ : attributeName,
68
+ value: value ? container(value) : null,
69
+ };
70
+ };
71
+ const newline = () => container(literal('\n'));
72
+ const wrap = (units) => [
73
+ newline(),
74
+ ...units.flatMap((unit, index) => (index > 0 ? [newline(), ...unit] : unit)),
75
+ ...(units.length > 0 ? [newline()] : []),
76
+ ];
77
+ const trimLines = (value) => value.replace(/[\t ]*(\r?\n|\r)[\t ]*/g, '$1');
78
+ const trimStart = (value) => value.replace(/^[\t ]+/, '');
79
+ const codeText = (value) => value.replace(/\r?\n|\r/g, ' ');
80
+ const trimAfterBreak = (node) => {
81
+ switch (node.type) {
82
+ case 'text':
83
+ return Object.assign(Object.assign({}, node), { value: trimStart(node.value) });
84
+ case 'inlineCode':
85
+ return Object.assign(Object.assign({}, node), { value: trimStart(codeText(node.value)) });
86
+ case 'strong':
87
+ case 'emphasis':
88
+ case 'delete':
89
+ case 'link': {
90
+ const [head, ...rest] = node.children;
91
+ return (head === null || head === void 0 ? void 0 : head.type) === 'text'
92
+ ? Object.assign(Object.assign({}, node), { children: [Object.assign(Object.assign({}, head), { value: trimStart(head.value) }), ...rest] }) : node;
93
+ }
94
+ default:
95
+ return node;
96
+ }
97
+ };
98
+ const isJsxPhrasing = (node) => node.type === 'mdxJsxTextElement' || node.type === 'mdxTextExpression';
99
+ const unravel = (nodes) => nodes.flatMap((node) => node.type === 'paragraph' &&
100
+ node.children.some(isJsxPhrasing) &&
101
+ node.children.every((child) => isJsxPhrasing(child) || (child.type === 'text' && /^[\t\n\v\f\r ]*$/.test(child.value)))
102
+ ? node.children.filter((child) => child.type !== 'text' || !/^[\t\r\n ]+$/.test(child.value))
103
+ : [node]);
104
+ const truncate = (value, max = 40) => value.length > max ? `${value.slice(0, max - 1)}…` : value;
105
+ export class IslandModuleBuilder {
106
+ constructor(rootName, pagePath, bindings, undeclared, consts, sideEffects, order) {
107
+ this.rootName = rootName;
108
+ this.pagePath = pagePath;
109
+ this.bindings = bindings;
110
+ this.undeclared = undeclared;
111
+ this.consts = consts;
112
+ this.sideEffects = sideEffects;
113
+ this.order = order;
114
+ this.usedBindings = new Map();
115
+ this.usedConsts = new Set();
116
+ this.errors = [];
117
+ }
118
+ url(value, isPageLink) {
119
+ return literal(resolveRelativeUrl(this.pagePath, value, isPageLink));
120
+ }
121
+ fail(node, message) {
122
+ this.errors.push({ line: lineOf(node), message });
123
+ }
124
+ insideRoot() {
125
+ return `the package component <${this.rootName}>`;
126
+ }
127
+ element(node) {
128
+ if (!node.name) {
129
+ const children = this.children(node.children);
130
+ return {
131
+ type: 'JSXFragment',
132
+ openingFragment: { type: 'JSXOpeningFragment' },
133
+ closingFragment: { type: 'JSXClosingFragment' },
134
+ children,
135
+ };
136
+ }
137
+ const name = node.name;
138
+ const head = bindingHead(name);
139
+ const binding = head === undefined ? undefined : this.bindings.get(head);
140
+ if (binding === null || binding === void 0 ? void 0 : binding.invalidName) {
141
+ this.fail(node, `<${name}> is imported from "${binding.source}" by the string name ${JSON.stringify(binding.imported)}, which isn't a valid identifier. Import it by an identifier name, or move this into a snippet.`);
142
+ return undefined;
143
+ }
144
+ else if (binding && head !== undefined) {
145
+ this.usedBindings.set(head, binding);
146
+ }
147
+ else if (isIntrinsic(name)) {
148
+ if (BLOCKED_ELEMENTS.has(name.toLowerCase())) {
149
+ this.fail(node, `<${name}> isn't allowed inside ${this.insideRoot()}.`);
150
+ return undefined;
151
+ }
152
+ }
153
+ else if (head !== undefined && this.undeclared.has(head)) {
154
+ this.fail(node, `<${name}> is imported from "${this.undeclared.get(head)}", which isn't listed in package.json dependencies.`);
155
+ return undefined;
156
+ }
157
+ else if (MINTLIFY_COMPONENTS.has(name)) {
158
+ this.fail(node, `<${name}> is a Mintlify component and can't render inside ${this.insideRoot()}. Move <${name}> outside <${this.rootName}>.`);
159
+ return undefined;
160
+ }
161
+ else {
162
+ this.fail(node, `<${name}> isn't imported from a package or a package snippet, so it can't render inside ${this.insideRoot()}. ${MOVE_TO_SNIPPET}`);
163
+ return undefined;
164
+ }
165
+ const attributes = [];
166
+ for (const attribute of node.attributes) {
167
+ const converted = this.attribute(node, name, attribute);
168
+ if (converted)
169
+ attributes.push(converted);
170
+ }
171
+ return jsxElement(name, attributes, this.children(node.children));
172
+ }
173
+ attribute(node, elementName, attribute) {
174
+ var _a;
175
+ const at = attribute.position ? attribute : node;
176
+ if (attribute.type === 'mdxJsxExpressionAttribute') {
177
+ this.fail(at, `<${elementName}> spreads props ({...}), which can't be evaluated at build time. ${MOVE_TO_SNIPPET}`);
178
+ return undefined;
179
+ }
180
+ const prop = `Prop "${attribute.name}" on <${elementName}>`;
181
+ if (/^on[A-Z]/.test(attribute.name) ||
182
+ (isIntrinsic(elementName) && /^on/i.test(attribute.name))) {
183
+ this.fail(at, `${prop} is an event handler, and package components in MDX only take static props. ${MOVE_TO_SNIPPET}`);
184
+ return undefined;
185
+ }
186
+ if (attribute.name === 'dangerouslySetInnerHTML' || attribute.name === 'ref') {
187
+ this.fail(at, `${prop} isn't allowed inside ${this.insideRoot()}.`);
188
+ return undefined;
189
+ }
190
+ if (attribute.value === null || attribute.value === undefined) {
191
+ return jsxAttribute(attribute.name, null);
192
+ }
193
+ if (typeof attribute.value === 'string') {
194
+ if (attribute.name === 'style' && isIntrinsic(elementName)) {
195
+ const style = parseInlineStyle(attribute.value);
196
+ const expression = valueToExpression(style);
197
+ if (expression)
198
+ return jsxAttribute('style', expression);
199
+ const key = Object.keys(style).find((name) => UNSAFE_KEYS.has(name));
200
+ this.fail(at, this.propFailure(prop, { reason: 'key', name: key }));
201
+ return undefined;
202
+ }
203
+ return jsxAttribute(attribute.name, URL_ATTRIBUTES.get(elementName) === attribute.name
204
+ ? this.url(attribute.value, attribute.name === 'href')
205
+ : literal(attribute.value));
206
+ }
207
+ const program = (_a = attribute.value.data) === null || _a === void 0 ? void 0 : _a.estree;
208
+ const statement = program === null || program === void 0 ? void 0 : program.body[0];
209
+ if (!program || program.body.length !== 1 || (statement === null || statement === void 0 ? void 0 : statement.type) !== 'ExpressionStatement') {
210
+ this.fail(at, `${prop} is an expression that can't be evaluated at build time. ${MOVE_TO_SNIPPET}`);
211
+ return undefined;
212
+ }
213
+ const converted = toStaticExpression(statement.expression, this.consts, this.usedConsts);
214
+ if (converted.ok)
215
+ return jsxAttribute(attribute.name, converted.expression);
216
+ this.fail(at, this.propFailure(prop, converted));
217
+ return undefined;
218
+ }
219
+ propFailure(prop, failure) {
220
+ switch (failure.reason) {
221
+ case 'function':
222
+ return `${prop} is a function, and package components in MDX only take static props. ${MOVE_TO_SNIPPET}`;
223
+ case 'jsx':
224
+ return `${prop} is JSX, and package components in MDX only take static props. ${MOVE_TO_SNIPPET}`;
225
+ case 'identifier':
226
+ return `${prop} uses "${failure.name}", which isn't a literal \`export const\` in this page. ${MOVE_TO_SNIPPET}`;
227
+ case 'const':
228
+ return `${prop} uses \`export const ${failure.name}\`, whose value isn't a literal (strings, numbers, booleans, arrays and objects only). ${MOVE_TO_SNIPPET}`;
229
+ case 'key':
230
+ return `${prop} uses the object key "${failure.name}", which isn't allowed.`;
231
+ case 'expression':
232
+ return `${prop} is an expression that can't be evaluated at build time. ${MOVE_TO_SNIPPET}`;
233
+ }
234
+ }
235
+ intrinsic(name, children, attributes = []) {
236
+ return jsxElement(name, attributes, this.children(children));
237
+ }
238
+ children(nodes) {
239
+ const result = [];
240
+ let afterBreak = false;
241
+ for (const node of unravel(nodes)) {
242
+ const converted = this.child(afterBreak ? trimAfterBreak(node) : node);
243
+ afterBreak = node.type === 'break';
244
+ if (converted)
245
+ result.push(...converted);
246
+ }
247
+ return result;
248
+ }
249
+ child(node) {
250
+ var _a, _b;
251
+ switch (node.type) {
252
+ case 'mdxJsxFlowElement':
253
+ case 'mdxJsxTextElement': {
254
+ const element = this.element(node);
255
+ return element ? [element] : undefined;
256
+ }
257
+ case 'text': {
258
+ const value = trimLines(node.value);
259
+ return value === '' ? [] : [container(literal(value))];
260
+ }
261
+ case 'paragraph':
262
+ return [this.intrinsic('p', node.children)];
263
+ case 'strong':
264
+ return [this.intrinsic('strong', node.children)];
265
+ case 'emphasis':
266
+ return [this.intrinsic('em', node.children)];
267
+ case 'delete':
268
+ return [this.intrinsic('del', node.children)];
269
+ case 'inlineCode':
270
+ return [jsxElement('code', [], [container(literal(codeText(node.value)))])];
271
+ case 'break':
272
+ return [jsxElement('br', [], []), newline()];
273
+ case 'thematicBreak':
274
+ return [jsxElement('hr', [], [])];
275
+ case 'blockquote':
276
+ return [
277
+ jsxElement('blockquote', [], wrap(unravel(node.children).map((child) => { var _a; return (_a = this.child(child)) !== null && _a !== void 0 ? _a : []; }))),
278
+ ];
279
+ case 'heading':
280
+ return [this.intrinsic(`h${node.depth}`, node.children)];
281
+ case 'link': {
282
+ const attributes = [jsxAttribute('href', this.url(node.url, true))];
283
+ if (node.title)
284
+ attributes.push(jsxAttribute('title', literal(node.title)));
285
+ return [this.intrinsic('a', node.children, attributes)];
286
+ }
287
+ case 'image': {
288
+ const attributes = [
289
+ jsxAttribute('src', this.url(node.url, false)),
290
+ jsxAttribute('alt', literal((_a = node.alt) !== null && _a !== void 0 ? _a : '')),
291
+ ];
292
+ if (node.title)
293
+ attributes.push(jsxAttribute('title', literal(node.title)));
294
+ return [jsxElement('img', attributes, [])];
295
+ }
296
+ case 'code': {
297
+ const attributes = node.lang
298
+ ? [jsxAttribute('className', literal(`language-${node.lang}`))]
299
+ : [];
300
+ return [
301
+ jsxElement('pre', [], [jsxElement('code', attributes, [container(literal(node.value))])]),
302
+ ];
303
+ }
304
+ case 'list': {
305
+ const loose = isListLoose(node);
306
+ const attributes = node.ordered && typeof node.start === 'number' && node.start !== 1
307
+ ? [jsxAttribute('start', literal(node.start))]
308
+ : [];
309
+ if (node.children.some((item) => typeof item.checked === 'boolean')) {
310
+ attributes.push(jsxAttribute('className', literal('contains-task-list')));
311
+ }
312
+ return [
313
+ jsxElement(node.ordered ? 'ol' : 'ul', attributes, wrap(node.children.map((item) => [this.listItem(item, loose)]))),
314
+ ];
315
+ }
316
+ case 'table': {
317
+ const [head, ...body] = node.children;
318
+ const row = (cells, cell) => jsxElement('tr', [], cells.map((entry) => this.intrinsic(cell, 'children' in entry ? entry.children : [])));
319
+ const sections = [];
320
+ if (head)
321
+ sections.push(jsxElement('thead', [], [row(head.children, 'th')]));
322
+ if (body.length > 0) {
323
+ sections.push(jsxElement('tbody', [], body.map((entry) => row(entry.children, 'td'))));
324
+ }
325
+ return [jsxElement('table', [], sections)];
326
+ }
327
+ case 'mdxFlowExpression':
328
+ case 'mdxTextExpression': {
329
+ const program = (_b = node.data) === null || _b === void 0 ? void 0 : _b.estree;
330
+ if (program && program.body.length === 0)
331
+ return [];
332
+ const statement = program === null || program === void 0 ? void 0 : program.body[0];
333
+ if ((program === null || program === void 0 ? void 0 : program.body.length) === 1 && (statement === null || statement === void 0 ? void 0 : statement.type) === 'ExpressionStatement') {
334
+ const converted = toStaticExpression(statement.expression, this.consts, this.usedConsts);
335
+ if (converted.ok && this.isRenderableText(converted.expression)) {
336
+ return [container(converted.expression)];
337
+ }
338
+ }
339
+ this.fail(node, `{${truncate(node.value.trim())}} inside ${this.insideRoot()} can't be evaluated at build time. ${MOVE_TO_SNIPPET}`);
340
+ return undefined;
341
+ }
342
+ default:
343
+ this.fail(node, `Markdown ${node.type} content isn't supported inside ${this.insideRoot()}. ${MOVE_TO_SNIPPET}`);
344
+ return undefined;
345
+ }
346
+ }
347
+ listItem(item, loose) {
348
+ const results = unravel(item.children).map((child) => {
349
+ var _a;
350
+ return child.type === 'paragraph'
351
+ ? { p: true, empty: child.children.length === 0, children: this.children(child.children) }
352
+ : { p: false, empty: false, children: (_a = this.child(child)) !== null && _a !== void 0 ? _a : [] };
353
+ });
354
+ const attributes = [];
355
+ if (typeof item.checked === 'boolean') {
356
+ const checkbox = jsxElement('input', [
357
+ jsxAttribute('type', literal('checkbox')),
358
+ jsxAttribute('checked', literal(item.checked)),
359
+ jsxAttribute('disabled', null),
360
+ ], []);
361
+ const [head] = results;
362
+ if (head === null || head === void 0 ? void 0 : head.p)
363
+ head.children.unshift(checkbox, ...(head.empty ? [] : [container(literal(' '))]));
364
+ else
365
+ results.unshift({ p: true, empty: true, children: [checkbox] });
366
+ attributes.push(jsxAttribute('className', literal('task-list-item')));
367
+ }
368
+ const children = results.flatMap(({ p, children: content }, index) => [
369
+ ...(loose || index > 0 || !p ? [newline()] : []),
370
+ ...(p && loose ? [jsxElement('p', [], content)] : content),
371
+ ]);
372
+ const tail = results.at(-1);
373
+ if (tail && (loose || !tail.p))
374
+ children.push(newline());
375
+ return jsxElement('li', attributes, children);
376
+ }
377
+ isRenderableText(expression) {
378
+ var _a;
379
+ if (expression.type === 'Literal') {
380
+ return typeof expression.value === 'string' || typeof expression.value === 'number';
381
+ }
382
+ if (expression.type === 'UnaryExpression')
383
+ return true;
384
+ if (expression.type !== 'Identifier' || expression.name === 'undefined')
385
+ return false;
386
+ const value = (_a = this.consts.get(expression.name)) === null || _a === void 0 ? void 0 : _a.expression;
387
+ return value !== undefined && this.isRenderableText(value) && value.type !== 'Identifier';
388
+ }
389
+ module(root) {
390
+ var _a, _b, _c;
391
+ const body = [];
392
+ const bySource = new Map();
393
+ for (const binding of [...this.usedBindings.values()].sort((a, b) => compare(a.local, b.local))) {
394
+ bySource.set(binding.source, [...((_a = bySource.get(binding.source)) !== null && _a !== void 0 ? _a : []), binding]);
395
+ }
396
+ const sources = this.sideEffects.size === 0
397
+ ? [...bySource.keys()].sort(compare)
398
+ : this.order.filter((source) => bySource.has(source) || this.sideEffects.has(source));
399
+ for (const source of sources) {
400
+ const bindings = (_b = bySource.get(source)) !== null && _b !== void 0 ? _b : [];
401
+ const declaration = (specifiers) => ({
402
+ type: 'ImportDeclaration',
403
+ specifiers,
404
+ source: { type: 'Literal', value: source },
405
+ });
406
+ const [firstDefault, ...otherDefaults] = bindings.filter((binding) => binding.imported === 'default');
407
+ const named = bindings.filter((binding) => binding.imported !== 'default' && binding.imported !== '*');
408
+ const mainSpecifiers = [];
409
+ if (firstDefault) {
410
+ mainSpecifiers.push({
411
+ type: 'ImportDefaultSpecifier',
412
+ local: identifier(firstDefault.local),
413
+ });
414
+ }
415
+ for (const binding of named) {
416
+ mainSpecifiers.push({
417
+ type: 'ImportSpecifier',
418
+ imported: identifier(binding.imported),
419
+ local: identifier(binding.local),
420
+ });
421
+ }
422
+ if (mainSpecifiers.length > 0 || bindings.length === 0) {
423
+ body.push(declaration(mainSpecifiers));
424
+ }
425
+ for (const binding of otherDefaults) {
426
+ body.push(declaration([{ type: 'ImportDefaultSpecifier', local: identifier(binding.local) }]));
427
+ }
428
+ for (const binding of bindings.filter((entry) => entry.imported === '*')) {
429
+ body.push(declaration([{ type: 'ImportNamespaceSpecifier', local: identifier(binding.local) }]));
430
+ }
431
+ }
432
+ for (const name of [...this.usedConsts].sort(compare)) {
433
+ const expression = (_c = this.consts.get(name)) === null || _c === void 0 ? void 0 : _c.expression;
434
+ if (!expression)
435
+ continue;
436
+ body.push({
437
+ type: 'VariableDeclaration',
438
+ kind: 'const',
439
+ declarations: [{ type: 'VariableDeclarator', id: identifier(name), init: expression }],
440
+ });
441
+ }
442
+ const taken = new Set([...this.usedBindings.keys(), ...this.usedConsts]);
443
+ let functionName = 'Island';
444
+ while (taken.has(functionName))
445
+ functionName = `${functionName}_`;
446
+ body.push({
447
+ type: 'ExportDefaultDeclaration',
448
+ declaration: {
449
+ type: 'FunctionDeclaration',
450
+ id: identifier(functionName),
451
+ params: [],
452
+ generator: false,
453
+ async: false,
454
+ body: { type: 'BlockStatement', body: [{ type: 'ReturnStatement', argument: root }] },
455
+ },
456
+ });
457
+ const program = { type: 'Program', sourceType: 'module', body };
458
+ return toJs(program, { handlers: jsxHandlers }).value;
459
+ }
460
+ imports() {
461
+ return [...this.usedBindings.values()]
462
+ .map(({ local, source, imported }) => ({ local, pkg: source, imported }))
463
+ .sort((a, b) => compare(a.local, b.local));
464
+ }
465
+ }
466
+ const compare = (a, b) => {
467
+ if (a < b)
468
+ return -1;
469
+ if (a > b)
470
+ return 1;
471
+ return 0;
472
+ };
@@ -0,0 +1,10 @@
1
+ import type { List, ListItem } from 'mdast';
2
+ import type { LocatedStatement } from './island-bindings.js';
3
+ export type Blocker = string | false;
4
+ type ChildrenPlacements = Map<string, (string | null)[][]>;
5
+ export declare const isItemLoose: (item: ListItem) => boolean;
6
+ export declare const isListLoose: (list: List) => boolean;
7
+ export declare const isIntrinsic: (name: string) => boolean;
8
+ export declare const childrenPlacements: (statements: LocatedStatement[]) => ChildrenPlacements;
9
+ export declare const blockerWithin: (name: string | null, blocker: Blocker, placements: ChildrenPlacements, seen?: ReadonlySet<string>) => Blocker;
10
+ export {};