@mintlify/common 1.0.1224 → 1.0.1225

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.
@@ -0,0 +1,11 @@
1
+ export declare function packagePageBaseUrl(baseUrl: string, pagePath: string): string;
2
+ export declare function packagePageStylesheets(baseUrl: string, pagePath: string, islandIds: readonly string[], manifest: {
3
+ css: readonly {
4
+ path: string;
5
+ }[];
6
+ islands: Readonly<Record<string, {
7
+ css?: readonly {
8
+ path: string;
9
+ }[];
10
+ }>>;
11
+ }): string[];
@@ -0,0 +1,34 @@
1
+ const PRODUCTION_PACKAGE_BASE_URL = /^\/_mintlify\/pkg\/[a-f0-9]{16,64}$/;
2
+ const ROUTE_CANONICAL_BASE = 'https://pkg-access.invalid';
3
+ const MAX_ACCESS_ROUTE_LENGTH = 1024;
4
+ export function packagePageBaseUrl(baseUrl, pagePath) {
5
+ if (!PRODUCTION_PACKAGE_BASE_URL.test(baseUrl))
6
+ return baseUrl;
7
+ const route = pagePath.startsWith('/') ? pagePath : `/${pagePath}`;
8
+ if (route.length > MAX_ACCESS_ROUTE_LENGTH ||
9
+ route.startsWith('//') ||
10
+ /[?#\\\u0000-\u001f\u007f]/.test(route) ||
11
+ !URL.canParse(route, ROUTE_CANONICAL_BASE)) {
12
+ throw new Error('Invalid package page path');
13
+ }
14
+ const canonicalRoute = new URL(route, ROUTE_CANONICAL_BASE).pathname.replace(/\/+$/, '') || '/';
15
+ if (canonicalRoute.length > MAX_ACCESS_ROUTE_LENGTH * 9) {
16
+ throw new Error('Invalid package page path');
17
+ }
18
+ const bytes = new TextEncoder().encode(canonicalRoute);
19
+ const token = btoa(String.fromCharCode(...bytes))
20
+ .replace(/\+/g, '-')
21
+ .replace(/\//g, '_')
22
+ .replace(/=+$/, '');
23
+ return `${baseUrl}/pages/${token}`;
24
+ }
25
+ export function packagePageStylesheets(baseUrl, pagePath, islandIds, manifest) {
26
+ var _a, _b;
27
+ const pageBaseUrl = packagePageBaseUrl(baseUrl, pagePath);
28
+ const paths = new Set(manifest.css.map((css) => css.path));
29
+ for (const id of [...islandIds].sort()) {
30
+ for (const css of (_b = (_a = manifest.islands[id]) === null || _a === void 0 ? void 0 : _a.css) !== null && _b !== void 0 ? _b : [])
31
+ paths.add(css.path);
32
+ }
33
+ return [...paths].map((path) => `${pageBaseUrl}/${path}`);
34
+ }
@@ -10,7 +10,13 @@ export type PackageBuildInput = {
10
10
  islands: Record<string, {
11
11
  html?: string;
12
12
  prefix: string;
13
+ css?: {
14
+ path: string;
15
+ }[];
13
16
  }>;
17
+ css?: {
18
+ path: string;
19
+ }[];
14
20
  packageNames: string[];
15
21
  packageSnippets?: string[];
16
22
  };
@@ -11,6 +11,7 @@ import { serialize } from '@mintlify/mdx/server';
11
11
  import { getTailwindSelectors } from '../../css/tailwind.js';
12
12
  import { getMDXOptions, remarkMdxRemoveJs, remarkExpandContent, remarkSplitCodeGroup, remarkSplitTabs, remarkWrapCodeBlocks, remarkValidateAccordions, remarkValidateSteps, remarkValidateVisibility, remarkValidateTabs, remarkValidateApiExamples, } from '../../index.js';
13
13
  import { codeStylingToThemeOrThemes } from '../getCodeStyling.js';
14
+ import { packagePageBaseUrl, packagePageStylesheets } from '../islands/package-page-url.js';
14
15
  import { MINT_ISLAND_COMPONENT } from '../islands/packageImports.js';
15
16
  import { PackageIslandsError, parsePackageIslands, preprocessPageContent, } from '../islands/remarkPackageIslands.js';
16
17
  import { preprocessCustomHeadingIds } from '../preprocessCustomHeadingIds.js';
@@ -33,11 +34,22 @@ const getPackageIslandOptions = (packageBuild, pagePath, processedContent, snipp
33
34
  catch (_a) {
34
35
  plan = undefined;
35
36
  }
36
- return Object.assign(Object.assign({}, options), { plan, islandHtml: packageBuild.islands, baseUrl: packageBuild.baseUrl });
37
+ const baseUrl = packagePageBaseUrl(packageBuild.baseUrl, pagePath);
38
+ const islandHtml = Object.fromEntries(Object.entries(packageBuild.islands).map(([id, island]) => {
39
+ if (typeof island.html !== 'string')
40
+ return [id, island];
41
+ return [
42
+ id,
43
+ Object.assign(Object.assign({}, island), { html: island.html.replaceAll('/_mintlify/pkg-asset/', `${baseUrl}/client/`) }),
44
+ ];
45
+ }));
46
+ return Object.assign(Object.assign({}, options), { plan,
47
+ islandHtml,
48
+ baseUrl });
37
49
  };
38
50
  export function getMdx(_a) {
39
51
  return __awaiter(this, arguments, void 0, function* ({ path, content, metadata, snippets, subdomain, codeStyling, config, tailwindSelectors = undefined, pageType = 'default', trace = undefined, customLanguages = [], variables = undefined, rehypePlugins = [], remarkPlugins = [], earlyRemarkPlugins = [], allowedComponents = [], packageBuild = undefined, singlePass = true, }) {
40
- var _b, _c;
52
+ var _b, _c, _d, _e;
41
53
  const traceFn = trace !== null && trace !== void 0 ? trace : ((_name, fn) => fn());
42
54
  const processedContent = preprocessPageContent(content, variables);
43
55
  const processedSnippets = snippets.map((snippet) => (Object.assign(Object.assign({}, snippet), { content: preprocessCustomHeadingIds(preprocessMdxFragmentCode(replaceVariables(snippet.content, variables))) })));
@@ -149,6 +161,11 @@ export function getMdx(_a) {
149
161
  if (mdxExtracts.multiViewItems) {
150
162
  mdxExtracts.multiViewItems = mdxExtracts.multiViewItems.map((item, index) => (Object.assign(Object.assign({}, item), { active: index === 0 })));
151
163
  }
164
+ if (packageBuild) {
165
+ const packageCssFiles = packagePageStylesheets(packageBuild.baseUrl, path, Object.keys((_d = mdxExtracts.islands) !== null && _d !== void 0 ? _d : {}), { css: (_e = packageBuild.css) !== null && _e !== void 0 ? _e : [], islands: packageBuild.islands });
166
+ if (packageCssFiles.length > 0)
167
+ mdxExtracts.packageCssFiles = packageCssFiles;
168
+ }
152
169
  return Object.assign({ mdxExtracts,
153
170
  mdxSource,
154
171
  mdxSourceWithNoJs,
@@ -1,2 +1,3 @@
1
1
  export { createSnippetTreeMap, getMdx, type GetMdxType, type PackageBuildInput, type Snippet, } from './getMdx.js';
2
2
  export { getSerializeExtras } from './getSerializeExtras.js';
3
+ export { packagePageBaseUrl, packagePageStylesheets } from '../islands/package-page-url.js';
@@ -1,2 +1,3 @@
1
1
  export { createSnippetTreeMap, getMdx, } from './getMdx.js';
2
2
  export { getSerializeExtras } from './getSerializeExtras.js';
3
+ export { packagePageBaseUrl, packagePageStylesheets } from '../islands/package-page-url.js';