@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,71 @@
1
+ const K = new Uint32Array([
2
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
3
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
4
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
5
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
6
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
7
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
8
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
9
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
10
+ ]);
11
+ const rotr = (x, n) => (x >>> n) | (x << (32 - n));
12
+ const at = (words, index) => { var _a; return (_a = words[index]) !== null && _a !== void 0 ? _a : 0; };
13
+ export const sha256Hex = (input) => {
14
+ const bytes = new TextEncoder().encode(input);
15
+ const bitLength = bytes.length * 8;
16
+ const paddedLength = Math.ceil((bytes.length + 9) / 64) * 64;
17
+ const data = new Uint8Array(paddedLength);
18
+ data.set(bytes);
19
+ data[bytes.length] = 0x80;
20
+ const view = new DataView(data.buffer);
21
+ view.setUint32(paddedLength - 8, Math.floor(bitLength / 0x100000000));
22
+ view.setUint32(paddedLength - 4, bitLength >>> 0);
23
+ const h = new Uint32Array([
24
+ 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
25
+ ]);
26
+ const w = new Uint32Array(64);
27
+ for (let offset = 0; offset < paddedLength; offset += 64) {
28
+ for (let i = 0; i < 16; i++)
29
+ w[i] = view.getUint32(offset + i * 4);
30
+ for (let i = 16; i < 64; i++) {
31
+ const w15 = at(w, i - 15);
32
+ const w2 = at(w, i - 2);
33
+ const s0 = rotr(w15, 7) ^ rotr(w15, 18) ^ (w15 >>> 3);
34
+ const s1 = rotr(w2, 17) ^ rotr(w2, 19) ^ (w2 >>> 10);
35
+ w[i] = (at(w, i - 16) + s0 + at(w, i - 7) + s1) >>> 0;
36
+ }
37
+ let a = at(h, 0);
38
+ let b = at(h, 1);
39
+ let c = at(h, 2);
40
+ let d = at(h, 3);
41
+ let e = at(h, 4);
42
+ let f = at(h, 5);
43
+ let g = at(h, 6);
44
+ let hh = at(h, 7);
45
+ for (let i = 0; i < 64; i++) {
46
+ const s1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
47
+ const ch = (e & f) ^ (~e & g);
48
+ const t1 = (hh + s1 + ch + at(K, i) + at(w, i)) >>> 0;
49
+ const s0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
50
+ const maj = (a & b) ^ (a & c) ^ (b & c);
51
+ const t2 = (s0 + maj) >>> 0;
52
+ hh = g;
53
+ g = f;
54
+ f = e;
55
+ e = (d + t1) >>> 0;
56
+ d = c;
57
+ c = b;
58
+ b = a;
59
+ a = (t1 + t2) >>> 0;
60
+ }
61
+ h[0] = (at(h, 0) + a) >>> 0;
62
+ h[1] = (at(h, 1) + b) >>> 0;
63
+ h[2] = (at(h, 2) + c) >>> 0;
64
+ h[3] = (at(h, 3) + d) >>> 0;
65
+ h[4] = (at(h, 4) + e) >>> 0;
66
+ h[5] = (at(h, 5) + f) >>> 0;
67
+ h[6] = (at(h, 6) + g) >>> 0;
68
+ h[7] = (at(h, 7) + hh) >>> 0;
69
+ }
70
+ return Array.from(h, (word) => word.toString(16).padStart(8, '0')).join('');
71
+ };
@@ -0,0 +1,24 @@
1
+ import type { Expression, Identifier, Node as EstreeNode } from 'estree-jsx';
2
+ export { UNSAFE_OBJECT_KEYS as UNSAFE_KEYS } from '../static-object-keys.js';
3
+ export type ConstEntry = {
4
+ expression: Expression | undefined;
5
+ };
6
+ type ParenthesizedExpression = {
7
+ type: 'ParenthesizedExpression';
8
+ expression: Expression;
9
+ };
10
+ export type Failure = {
11
+ reason: 'function' | 'jsx' | 'identifier' | 'const' | 'key' | 'expression';
12
+ name?: string;
13
+ };
14
+ type Converted = {
15
+ ok: true;
16
+ expression: Expression;
17
+ } | ({
18
+ ok: false;
19
+ } & Failure);
20
+ export declare const IDENTIFIER_NAME: RegExp;
21
+ export declare const literal: (value: string | number | boolean | null) => Expression;
22
+ export declare const identifier: (name: string) => Identifier;
23
+ export declare const toStaticExpression: (node: EstreeNode | ParenthesizedExpression | null | undefined, consts: Map<string, ConstEntry> | undefined, usedConsts: Set<string>) => Converted;
24
+ export declare const valueToExpression: (value: unknown, depth?: number) => Expression | undefined;
@@ -0,0 +1,169 @@
1
+ import { UNSAFE_OBJECT_KEYS as UNSAFE_KEYS } from '../static-object-keys.js';
2
+ export { UNSAFE_OBJECT_KEYS as UNSAFE_KEYS } from '../static-object-keys.js';
3
+ export const IDENTIFIER_NAME = /^[A-Za-z_$][\w$]*$/;
4
+ export const literal = (value) => ({
5
+ type: 'Literal',
6
+ value,
7
+ });
8
+ export const identifier = (name) => ({ type: 'Identifier', name });
9
+ const unwrapParentheses = (node) => node.type === 'ParenthesizedExpression' ? unwrapParentheses(node.expression) : node;
10
+ export const toStaticExpression = (node, consts, usedConsts) => {
11
+ if (!node)
12
+ return { ok: false, reason: 'expression' };
13
+ switch (node.type) {
14
+ case 'ParenthesizedExpression':
15
+ return toStaticExpression(node.expression, consts, usedConsts);
16
+ case 'Literal': {
17
+ if ('regex' in node || 'bigint' in node)
18
+ return { ok: false, reason: 'expression' };
19
+ const { value } = node;
20
+ if (value === null ||
21
+ typeof value === 'string' ||
22
+ typeof value === 'boolean' ||
23
+ (typeof value === 'number' && Number.isFinite(value))) {
24
+ return { ok: true, expression: literal(value) };
25
+ }
26
+ return { ok: false, reason: 'expression' };
27
+ }
28
+ case 'TemplateLiteral': {
29
+ if (node.expressions.length > 0)
30
+ return { ok: false, reason: 'expression' };
31
+ return {
32
+ ok: true,
33
+ expression: literal(node.quasis.map((quasi) => { var _a; return (_a = quasi.value.cooked) !== null && _a !== void 0 ? _a : quasi.value.raw; }).join('')),
34
+ };
35
+ }
36
+ case 'UnaryExpression': {
37
+ const argument = unwrapParentheses(node.argument);
38
+ if (node.operator === '-' &&
39
+ argument.type === 'Literal' &&
40
+ typeof argument.value === 'number' &&
41
+ Number.isFinite(argument.value)) {
42
+ return {
43
+ ok: true,
44
+ expression: {
45
+ type: 'UnaryExpression',
46
+ operator: '-',
47
+ prefix: true,
48
+ argument: literal(argument.value),
49
+ },
50
+ };
51
+ }
52
+ return { ok: false, reason: 'expression' };
53
+ }
54
+ case 'ArrayExpression': {
55
+ const elements = [];
56
+ for (const element of node.elements) {
57
+ if (!element || element.type === 'SpreadElement')
58
+ return { ok: false, reason: 'expression' };
59
+ const converted = toStaticExpression(element, consts, usedConsts);
60
+ if (!converted.ok)
61
+ return converted;
62
+ elements.push(converted.expression);
63
+ }
64
+ return { ok: true, expression: { type: 'ArrayExpression', elements } };
65
+ }
66
+ case 'ObjectExpression': {
67
+ const properties = [];
68
+ for (const property of node.properties) {
69
+ if (property.type === 'SpreadElement' || property.computed) {
70
+ return { ok: false, reason: 'expression' };
71
+ }
72
+ if (property.kind !== 'init' || property.method)
73
+ return { ok: false, reason: 'function' };
74
+ let key;
75
+ if (property.key.type === 'Identifier') {
76
+ key = property.key.name;
77
+ }
78
+ else if (property.key.type === 'Literal' &&
79
+ (typeof property.key.value === 'string' || typeof property.key.value === 'number')) {
80
+ key = String(property.key.value);
81
+ }
82
+ if (key === undefined)
83
+ return { ok: false, reason: 'expression' };
84
+ if (UNSAFE_KEYS.has(key))
85
+ return { ok: false, reason: 'key', name: key };
86
+ const converted = toStaticExpression(property.value, consts, usedConsts);
87
+ if (!converted.ok)
88
+ return converted;
89
+ const staticProperty = {
90
+ type: 'Property',
91
+ key: IDENTIFIER_NAME.test(key) ? identifier(key) : literal(key),
92
+ value: converted.expression,
93
+ kind: 'init',
94
+ method: false,
95
+ shorthand: false,
96
+ computed: false,
97
+ };
98
+ properties.push(staticProperty);
99
+ }
100
+ return { ok: true, expression: { type: 'ObjectExpression', properties } };
101
+ }
102
+ case 'Identifier': {
103
+ if (node.name === 'undefined')
104
+ return { ok: true, expression: identifier('undefined') };
105
+ const entry = consts === null || consts === void 0 ? void 0 : consts.get(node.name);
106
+ if (!entry)
107
+ return { ok: false, reason: 'identifier', name: node.name };
108
+ if (!entry.expression)
109
+ return { ok: false, reason: 'const', name: node.name };
110
+ usedConsts.add(node.name);
111
+ return { ok: true, expression: identifier(node.name) };
112
+ }
113
+ case 'ArrowFunctionExpression':
114
+ case 'FunctionExpression':
115
+ return { ok: false, reason: 'function' };
116
+ case 'JSXElement':
117
+ case 'JSXFragment':
118
+ return { ok: false, reason: 'jsx' };
119
+ default:
120
+ return { ok: false, reason: 'expression' };
121
+ }
122
+ };
123
+ export const valueToExpression = (value, depth = 0) => {
124
+ if (depth > 32)
125
+ return undefined;
126
+ if (value === undefined)
127
+ return identifier('undefined');
128
+ if (value === null || typeof value === 'string' || typeof value === 'boolean') {
129
+ return literal(value);
130
+ }
131
+ if (typeof value === 'number') {
132
+ if (!Number.isFinite(value))
133
+ return undefined;
134
+ return value < 0 || Object.is(value, -0)
135
+ ? { type: 'UnaryExpression', operator: '-', prefix: true, argument: literal(-value) }
136
+ : literal(value);
137
+ }
138
+ if (Array.isArray(value)) {
139
+ const elements = [];
140
+ for (const element of value) {
141
+ const converted = valueToExpression(element, depth + 1);
142
+ if (!converted)
143
+ return undefined;
144
+ elements.push(converted);
145
+ }
146
+ return { type: 'ArrayExpression', elements };
147
+ }
148
+ if (typeof value === 'object' && Object.getPrototypeOf(value) === Object.prototype) {
149
+ const properties = [];
150
+ for (const [key, entry] of Object.entries(value)) {
151
+ if (UNSAFE_KEYS.has(key))
152
+ return undefined;
153
+ const converted = valueToExpression(entry, depth + 1);
154
+ if (!converted)
155
+ return undefined;
156
+ properties.push({
157
+ type: 'Property',
158
+ key: IDENTIFIER_NAME.test(key) ? identifier(key) : literal(key),
159
+ value: converted,
160
+ kind: 'init',
161
+ method: false,
162
+ shorthand: false,
163
+ computed: false,
164
+ });
165
+ }
166
+ return { type: 'ObjectExpression', properties };
167
+ }
168
+ return undefined;
169
+ };
@@ -0,0 +1,36 @@
1
+ import type { Parent } from 'mdast';
2
+ import type { MdxJsxFlowElement, MdxJsxTextElement } from 'mdast-util-mdx-jsx';
3
+ export type IslandImport = {
4
+ local: string;
5
+ pkg: string;
6
+ imported: string;
7
+ };
8
+ export type IslandSpec = {
9
+ id: string;
10
+ pagePath: string;
11
+ kind: 'inline' | 'snippet';
12
+ imports: IslandImport[];
13
+ module: string;
14
+ };
15
+ export type IslandError = {
16
+ line?: number;
17
+ code?: 'side-effect-import-without-island';
18
+ message: string;
19
+ };
20
+ export type ExtractPackageIslandsOptions = {
21
+ packageNames: ReadonlySet<string>;
22
+ pagePath: string;
23
+ exportedConsts?: Record<string, unknown>;
24
+ packageSnippets?: ReadonlySet<string>;
25
+ };
26
+ export type IslandRoot = {
27
+ id: string;
28
+ name: string;
29
+ node: MdxJsxFlowElement | MdxJsxTextElement;
30
+ parent: Parent;
31
+ };
32
+ export type ExtractPackageIslandsResult = {
33
+ islands: IslandSpec[];
34
+ errors: IslandError[];
35
+ roots: IslandRoot[];
36
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -17,6 +17,7 @@ import { visitParents } from 'unist-util-visit-parents';
17
17
  import { JSXParser } from '../../lib/jsxParser.js';
18
18
  import { decodeMdxFragmentCode } from '../../preprocessMdxFragmentCode.js';
19
19
  import { getAST } from '../../remark.js';
20
+ import { UNSAFE_OBJECT_KEYS as UNSAFE_KEYS } from '../../static-object-keys.js';
20
21
  import { getExportedFunctionNames } from './remarkMdxClientComponentBoundaries.js';
21
22
  const REMARK_REHYPE_OPTIONS = {
22
23
  allowDangerousHtml: true,
@@ -45,7 +46,6 @@ const UNKNOWN = Symbol('unknown');
45
46
  */
46
47
  const MAX_ANALYSIS_NODES = 50000;
47
48
  const MAX_ANALYSIS_DEPTH = 1000;
48
- const UNSAFE_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
49
49
  /**
50
50
  * Compile-time expansion of `<MDX>` inside `{…}` expressions.
51
51
  *
@@ -1,4 +1,7 @@
1
1
  import type { Root } from 'mdast';
2
- import { Parent } from 'unist';
2
+ import type { MdxjsEsm } from 'mdast-util-mdx';
3
+ import { Node, Parent } from 'unist';
3
4
  import { VFile } from 'vfile';
5
+ export declare const injectedSnippetFile: (node: MdxjsEsm) => string | undefined;
6
+ export declare const findSnippetCycle: (tree: Node, snippetTreeMap: Record<string, Root>) => string[] | undefined;
4
7
  export declare const remarkMdxInjectSnippets: (snippetTreeMap: Record<string, Root>) => (tree: Parent, file: VFile) => void;
@@ -1,25 +1,76 @@
1
1
  import { removePosition } from 'unist-util-remove-position';
2
2
  import { visit, SKIP } from 'unist-util-visit';
3
+ export const injectedSnippetFile = (node) => {
4
+ const data = node.data;
5
+ return data && 'snippetFile' in data && typeof data.snippetFile === 'string'
6
+ ? data.snippetFile
7
+ : undefined;
8
+ };
9
+ const snippetFileOf = (node) => {
10
+ if (node.type !== 'mdxJsxFlowElement')
11
+ return undefined;
12
+ const mdxJsxFlowElement = node;
13
+ if (mdxJsxFlowElement.name !== 'Snippet')
14
+ return undefined;
15
+ const fileAttr = mdxJsxFlowElement.attributes.find((attr) => attr.type === 'mdxJsxAttribute' && attr.name === 'file');
16
+ return typeof (fileAttr === null || fileAttr === void 0 ? void 0 : fileAttr.value) === 'string' ? fileAttr.value : undefined;
17
+ };
18
+ export const findSnippetCycle = (tree, snippetTreeMap) => {
19
+ const acyclic = new Set();
20
+ const references = (node) => {
21
+ const names = [];
22
+ visit(node, (child) => {
23
+ const name = snippetFileOf(child);
24
+ if (name === undefined || !snippetTreeMap[name])
25
+ return;
26
+ names.push(name);
27
+ return SKIP;
28
+ });
29
+ return names;
30
+ };
31
+ const walk = (name, chain) => {
32
+ if (chain.includes(name))
33
+ return [...chain.slice(chain.indexOf(name)), name];
34
+ const snippet = snippetTreeMap[name];
35
+ if (acyclic.has(name) || !snippet)
36
+ return undefined;
37
+ for (const next of references(snippet)) {
38
+ const cycle = walk(next, [...chain, name]);
39
+ if (cycle)
40
+ return cycle;
41
+ }
42
+ acyclic.add(name);
43
+ return undefined;
44
+ };
45
+ for (const name of references(tree)) {
46
+ const cycle = walk(name, []);
47
+ if (cycle)
48
+ return cycle;
49
+ }
50
+ return undefined;
51
+ };
3
52
  export const remarkMdxInjectSnippets = (snippetTreeMap) => (tree, file) => {
4
53
  visit(tree, (node, index, parent) => {
5
- if (parent && index != null && node.type === 'mdxJsxFlowElement') {
6
- const mdxJsxFlowElement = node;
7
- if (mdxJsxFlowElement.name === 'Snippet') {
8
- const fileAttr = mdxJsxFlowElement.attributes.find((attr) => attr.type === 'mdxJsxAttribute' && attr.name === 'file');
9
- const name = fileAttr === null || fileAttr === void 0 ? void 0 : fileAttr.value;
10
- if (typeof name === 'string') {
11
- const snippet = snippetTreeMap[name];
12
- if (snippet) {
13
- const fragment = structuredClone(snippet);
14
- removePosition(fragment);
15
- parent.children.splice(index, 1, ...fragment.children);
16
- return [SKIP, index];
17
- }
18
- else {
19
- file.message('Cannot expand missing snippet `' + name + '`', node, 'remark-mdx-inject-snippets');
20
- }
21
- }
54
+ if (!parent || index == null)
55
+ return;
56
+ const name = snippetFileOf(node);
57
+ if (name === undefined)
58
+ return;
59
+ const snippet = snippetTreeMap[name];
60
+ if (snippet) {
61
+ const fragment = structuredClone(snippet);
62
+ removePosition(fragment);
63
+ for (const child of fragment.children) {
64
+ if (child.type !== 'mdxjsEsm')
65
+ continue;
66
+ const data = Object.assign(Object.assign({}, child.data), { snippetFile: name });
67
+ child.data = data;
22
68
  }
69
+ parent.children.splice(index, 1, ...fragment.children);
70
+ return [SKIP, index];
71
+ }
72
+ else {
73
+ file.message('Cannot expand missing snippet `' + name + '`', node, 'remark-mdx-inject-snippets');
23
74
  }
24
75
  });
25
76
  };
@@ -1,5 +1,6 @@
1
1
  import { remove } from 'unist-util-remove';
2
2
  import { CONTINUE, visit } from 'unist-util-visit';
3
+ import { UNSAFE_OBJECT_KEYS } from '../../static-object-keys.js';
3
4
  import { isMdxJsEsm } from '../../utils.js';
4
5
  const objectEstree = {
5
6
  type: 'Program',
@@ -214,7 +215,6 @@ export function rebuildStyleValue(properties) {
214
215
  function isJsxLikeNode(value) {
215
216
  return (typeof value === 'object' && value !== null && 'type' in value && typeof value.type === 'string');
216
217
  }
217
- const UNSAFE_OBJECT_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
218
218
  export const MAX_PURE_DATA_DEPTH = 32;
219
219
  function isPureDataLiteral(node) {
220
220
  if (node.type !== 'Literal' || 'regex' in node || 'bigint' in node)
@@ -2,5 +2,6 @@ import type { Root } from 'mdast';
2
2
  type Options = {
3
3
  path?: string;
4
4
  };
5
+ export declare const resolveRelativeUrl: (path: string, url: string, isPageLink: boolean) => string;
5
6
  export declare const remarkResolveRelativeLinks: (options?: Options) => (tree: Root) => void;
6
7
  export {};
@@ -23,14 +23,17 @@ const ATTR_BY_TAG = {
23
23
  img: 'src',
24
24
  source: 'src',
25
25
  };
26
+ const baseDirOf = (path) => {
27
+ const dir = posix.dirname(path.replace(/^\/+/, '').replace(/\.mdx?$/i, ''));
28
+ return dir === '.' || dir === '' ? '/' : `/${dir}`;
29
+ };
30
+ export const resolveRelativeUrl = (path, url, isPageLink) => isRelative(url) ? resolveRelative(baseDirOf(path), url, isPageLink) : url;
26
31
  export const remarkResolveRelativeLinks = (options = {}) => {
27
32
  return (tree) => {
28
33
  const { path } = options;
29
34
  if (!path)
30
35
  return;
31
- const stripped = path.replace(/^\/+/, '').replace(/\.mdx?$/i, '');
32
- const dir = posix.dirname(stripped);
33
- const baseDir = dir === '.' || dir === '' ? '/' : `/${dir}`;
36
+ const baseDir = baseDirOf(path);
34
37
  visit(tree, (node) => {
35
38
  if (node.type === 'link' || node.type === 'image') {
36
39
  const linkOrImg = node;
@@ -5,6 +5,15 @@ import type { PluggableList } from 'unified';
5
5
  import { MdxExtracts } from '../../index.js';
6
6
  import { createSnippetTreeMap, type Snippet } from './getMdx/snippets.js';
7
7
  type RunWithTracingFn = <T>(spanName: string, fn: () => Promise<T>) => Promise<T>;
8
+ export type PackageBuildInput = {
9
+ baseUrl: string;
10
+ islands: Record<string, {
11
+ html?: string;
12
+ prefix: string;
13
+ }>;
14
+ packageNames: string[];
15
+ packageSnippets?: string[];
16
+ };
8
17
  export type GetMdxType = {
9
18
  mdxSource: SerializeSuccess;
10
19
  mdxSourceWithNoJs: SerializeSuccess;
@@ -13,7 +22,7 @@ export type GetMdxType = {
13
22
  panelMdxSourceWithNoJs?: SerializeSuccess;
14
23
  parseFailed?: boolean;
15
24
  };
16
- export declare function getMdx({ path, content, metadata, snippets, subdomain, codeStyling, config, tailwindSelectors, pageType, trace, customLanguages, variables, rehypePlugins, remarkPlugins, earlyRemarkPlugins, allowedComponents, singlePass, }: {
25
+ export declare function getMdx({ path, content, metadata, snippets, subdomain, codeStyling, config, tailwindSelectors, pageType, trace, customLanguages, variables, rehypePlugins, remarkPlugins, earlyRemarkPlugins, allowedComponents, packageBuild, singlePass, }: {
17
26
  path: string;
18
27
  content: string;
19
28
  metadata: PageMetaTags;
@@ -30,6 +39,7 @@ export declare function getMdx({ path, content, metadata, snippets, subdomain, c
30
39
  remarkPlugins?: PluggableList;
31
40
  earlyRemarkPlugins?: PluggableList;
32
41
  allowedComponents?: string[];
42
+ packageBuild?: PackageBuildInput;
33
43
  singlePass?: boolean;
34
44
  }): Promise<GetMdxType>;
35
45
  export { createSnippetTreeMap, type Snippet };