@mintlify/common 1.0.1182 → 1.0.1184

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.
@@ -6,7 +6,6 @@ export * from './rehypeParamFieldIds.js';
6
6
  export * from './rehypeRawComponents.js';
7
7
  export * from './rehypeTable.js';
8
8
  export * from './rehypeZoomImages.js';
9
- export * from './rehypeOptimizedVideo.js';
10
9
  export * from './rehypeUnicodeIds.js';
11
10
  export * from './rehypeDynamicTailwindCss.js';
12
11
  export * from './rehypeKeyboardSymbols.js';
@@ -6,7 +6,6 @@ export * from './rehypeParamFieldIds.js';
6
6
  export * from './rehypeRawComponents.js';
7
7
  export * from './rehypeTable.js';
8
8
  export * from './rehypeZoomImages.js';
9
- export * from './rehypeOptimizedVideo.js';
10
9
  export * from './rehypeUnicodeIds.js';
11
10
  export * from './rehypeDynamicTailwindCss.js';
12
11
  export * from './rehypeKeyboardSymbols.js';
@@ -1,8 +1,8 @@
1
- import slugify from '@sindresorhus/slugify';
2
1
  import { visit } from 'unist-util-visit';
2
+ import { cachedSlugify } from '../../../slugify.js';
3
3
  export function generateParamFieldId(name, count) {
4
4
  const suffix = count > 0 ? `_${count}` : '';
5
- return slugify(`param-${name}${suffix}`, { decamelize: true, separator: '-' });
5
+ return cachedSlugify(`param-${name}${suffix}`, { decamelize: true, separator: '-' });
6
6
  }
7
7
  const PARAM_FIELD_COMPONENTS = ['ParamField', 'Param', 'ResponseField'];
8
8
  const PARAM_NAME_PRECEDENCE = ['query', 'path', 'body', 'header'];
@@ -1,9 +1,8 @@
1
- import defaultSlugify, { slugifyWithCounter } from '@sindresorhus/slugify';
2
1
  import { visit } from 'unist-util-visit';
3
- import { slugify } from '../../../slugify.js';
2
+ import { cachedSlugify, cachedSlugifyWithCounter, slugify } from '../../../slugify.js';
4
3
  import { createMdxJsxAttribute, getTableOfContentsTitle, getTitleMarkdownText, } from '../../lib/remark-utils.js';
5
4
  export function generateComponentId(title, count) {
6
- const base = defaultSlugify(title.replace(':', '-'), { decamelize: false });
5
+ const base = cachedSlugify(title.replace(':', '-'), { decamelize: false });
7
6
  return count != null && count > 0 ? `${base}-${count}` : base;
8
7
  }
9
8
  export const HEADING_LEVELS = [1, 2, 3, 4];
@@ -12,8 +11,8 @@ export const CHILD_TAB_IDS_ATTRIBUTE = 'data-child-tab-ids';
12
11
  export const CHILD_HEADING_IDS_ATTRIBUTE = 'data-child-heading-ids';
13
12
  export const remarkComponentIds = (pageMetadata) => (tree) => {
14
13
  var _a;
15
- const slugifyFn = slugifyWithCounter();
16
- const tabSlugifyFn = slugifyWithCounter();
14
+ const slugifyFn = cachedSlugifyWithCounter();
15
+ const tabSlugifyFn = cachedSlugifyWithCounter();
17
16
  const isAvoidedPageMode = AVOIDED_PAGE_MODES.includes((_a = pageMetadata === null || pageMetadata === void 0 ? void 0 : pageMetadata.mode) !== null && _a !== void 0 ? _a : '');
18
17
  visit(tree, 'heading', (node) => {
19
18
  if (isAvoidedPageMode)
@@ -65,12 +65,31 @@ export function createSnippetTreeMap(snippets) {
65
65
  return treeMap;
66
66
  });
67
67
  }
68
+ const MAX_CACHED_SNIPPET_CHARS = 4 * 1024 * 1024;
69
+ const snippetTreeCache = new Map();
70
+ let snippetTreeCacheChars = 0;
71
+ // safe to share: remarkMdxInjectSnippets structuredClones a tree before using it
72
+ function parseSnippetTree(content) {
73
+ const cached = snippetTreeCache.get(content);
74
+ if (cached)
75
+ return cached;
76
+ const tree = fromMarkdown(content, {
77
+ extensions: [gfm(), mdxjs()],
78
+ mdastExtensions: [gfmFromMarkdown(), mdxFromMarkdown()],
79
+ });
80
+ if (content.length > MAX_CACHED_SNIPPET_CHARS)
81
+ return tree;
82
+ if (snippetTreeCacheChars + content.length > MAX_CACHED_SNIPPET_CHARS) {
83
+ snippetTreeCache.clear();
84
+ snippetTreeCacheChars = 0;
85
+ }
86
+ snippetTreeCache.set(content, tree);
87
+ snippetTreeCacheChars += content.length;
88
+ return tree;
89
+ }
68
90
  function parseSnippetContentToMap(snippet, map) {
69
91
  try {
70
- const tree = fromMarkdown(snippet.content, {
71
- extensions: [gfm(), mdxjs()],
72
- mdastExtensions: [gfmFromMarkdown(), mdxFromMarkdown()],
73
- });
92
+ const tree = parseSnippetTree(snippet.content);
74
93
  // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- TODO: Please fix this violation when you can!
75
94
  map = Object.assign(Object.assign({}, map), { [snippet.snippetFileLocation]: tree });
76
95
  }
package/dist/slugify.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- import { CountableSlugify } from '@sindresorhus/slugify';
1
+ import { CountableSlugify, type Options } from '@sindresorhus/slugify';
2
2
  export declare const cleanHeadingId: (id: string) => string;
3
3
  export declare const safeCleanHeadingId: (id: string) => string;
4
+ export declare function cachedSlugify(string: string, options?: Options): string;
5
+ export declare function cachedSlugifyWithCounter(): CountableSlugify;
4
6
  export declare function slugify(string: string, slugify?: CountableSlugify): string;
package/dist/slugify.js CHANGED
@@ -1,4 +1,4 @@
1
- import { slugifyWithCounter } from '@sindresorhus/slugify';
1
+ import librarySlugify from '@sindresorhus/slugify';
2
2
  import { getUnicodeId } from './mdx/lib/remark-utils.js';
3
3
  // decodes percent-encoded slugs and strips punctuation + emoji so the
4
4
  // resulting ID matches what the client renders in the DOM
@@ -18,7 +18,44 @@ export const safeCleanHeadingId = (id) => {
18
18
  return id;
19
19
  }
20
20
  };
21
- export function slugify(string, slugify = slugifyWithCounter()) {
21
+ const MAX_CACHED_SLUGS = 20000;
22
+ const slugCache = new Map();
23
+ // the library rebuilds ~2000 transliteration regexes per call
24
+ export function cachedSlugify(string, options) {
25
+ const key = `${JSON.stringify(options !== null && options !== void 0 ? options : null)}\u0000${string}`;
26
+ const cached = slugCache.get(key);
27
+ if (cached !== undefined)
28
+ return cached;
29
+ const result = librarySlugify(string, options);
30
+ if (slugCache.size >= MAX_CACHED_SLUGS)
31
+ slugCache.clear();
32
+ slugCache.set(key, result);
33
+ return result;
34
+ }
35
+ // `slugifyWithCounter` from `@sindresorhus/slugify` 2.2.0, on top of cachedSlugify
36
+ export function cachedSlugifyWithCounter() {
37
+ const occurrences = new Map();
38
+ const countable = (string, options) => {
39
+ string = cachedSlugify(string, options);
40
+ if (!string) {
41
+ return '';
42
+ }
43
+ const stringLower = string.toLowerCase();
44
+ const numberless = occurrences.get(stringLower.replace(/(?:-\d+?)+?$/, '')) || 0;
45
+ const counter = occurrences.get(stringLower);
46
+ occurrences.set(stringLower, typeof counter === 'number' ? counter + 1 : 1);
47
+ const newCounter = occurrences.get(stringLower) || 2;
48
+ if (newCounter >= 2 || numberless > 2) {
49
+ string = `${string}-${newCounter}`;
50
+ }
51
+ return string;
52
+ };
53
+ countable.reset = () => {
54
+ occurrences.clear();
55
+ };
56
+ return countable;
57
+ }
58
+ export function slugify(string, slugify = cachedSlugifyWithCounter()) {
22
59
  const encodedString = getUnicodeId(string);
23
60
  // if encoded title is already percent-encoded, return it as is
24
61
  // slugify doesn't support percent-encoded characters, like Chinese, Korean, etc.