docusaurus-plugin-glossary 3.0.2 → 3.2.0

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 (50) hide show
  1. package/dist/chunk-4CUFUKUA.js +109 -0
  2. package/dist/chunk-4CUFUKUA.js.map +1 -0
  3. package/dist/chunk-PEB4Y6RI.js +311 -0
  4. package/dist/chunk-PEB4Y6RI.js.map +1 -0
  5. package/dist/chunk-SNP37IVL.js +212 -0
  6. package/dist/chunk-SNP37IVL.js.map +1 -0
  7. package/dist/client/index.cjs +55 -0
  8. package/dist/client/index.cjs.map +1 -0
  9. package/dist/client/index.js +10 -21
  10. package/dist/client/index.js.map +1 -0
  11. package/dist/components/GlossaryPage.cjs +130 -0
  12. package/dist/components/GlossaryPage.cjs.map +1 -0
  13. package/dist/components/GlossaryPage.js +74 -113
  14. package/dist/components/GlossaryPage.js.map +1 -0
  15. package/dist/index.cjs +659 -0
  16. package/dist/index.cjs.map +1 -0
  17. package/dist/index.d.cts +173 -0
  18. package/dist/index.d.ts +83 -11
  19. package/dist/index.js +23 -173
  20. package/dist/index.js.map +1 -0
  21. package/dist/preset.cjs +710 -0
  22. package/dist/preset.cjs.map +1 -0
  23. package/dist/preset.d.cts +98 -0
  24. package/dist/preset.d.ts +8 -7
  25. package/dist/preset.js +79 -143
  26. package/dist/preset.js.map +1 -0
  27. package/dist/remark/glossary-terms.cjs +345 -0
  28. package/dist/remark/glossary-terms.cjs.map +1 -0
  29. package/dist/remark/glossary-terms.js +9 -440
  30. package/dist/remark/glossary-terms.js.map +1 -0
  31. package/dist/theme/GlossaryTerm/index.cjs +138 -0
  32. package/dist/theme/GlossaryTerm/index.cjs.map +1 -0
  33. package/dist/theme/GlossaryTerm/index.js +56 -90
  34. package/dist/theme/GlossaryTerm/index.js.map +1 -0
  35. package/dist/validation.cjs +238 -0
  36. package/dist/validation.cjs.map +1 -0
  37. package/dist/validation.d.cts +2 -0
  38. package/dist/validation.d.ts +2 -44
  39. package/dist/validation.js +11 -246
  40. package/dist/validation.js.map +1 -0
  41. package/package.json +25 -30
  42. package/dist/components/GlossaryPage.test.js +0 -205
  43. package/dist/index.d.ts.map +0 -1
  44. package/dist/preset.d.ts.map +0 -1
  45. package/dist/remark/glossary-terms.d.ts +0 -28
  46. package/dist/remark/glossary-terms.d.ts.map +0 -1
  47. package/dist/theme/GlossaryTerm/index.test.js +0 -143
  48. package/dist/validation.d.ts.map +0 -1
  49. /package/dist/{components/GlossaryPage.module.css → GlossaryPage.module-M4DEUP4X.module.css} +0 -0
  50. /package/dist/{theme/GlossaryTerm/styles.module.css → styles.module-N7ME3MWS.module.css} +0 -0
@@ -0,0 +1,345 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/remark/glossary-terms.js
31
+ var glossary_terms_exports = {};
32
+ __export(glossary_terms_exports, {
33
+ clearGlossaryCache: () => clearGlossaryCache,
34
+ default: () => remarkGlossaryTerms
35
+ });
36
+ module.exports = __toCommonJS(glossary_terms_exports);
37
+ var import_unist_util_visit = require("unist-util-visit");
38
+ var import_path = __toESM(require("path"), 1);
39
+ var import_fs = __toESM(require("fs"), 1);
40
+ function validateGlossaryTerms(data, _filePath) {
41
+ const errors = [];
42
+ const validTerms = [];
43
+ if (data === null || data === void 0) {
44
+ errors.push(`Glossary data is null or undefined`);
45
+ return { terms: [], errors };
46
+ }
47
+ if (typeof data !== "object") {
48
+ errors.push(`Glossary data must be an object, got ${typeof data}`);
49
+ return { terms: [], errors };
50
+ }
51
+ if (!("terms" in data)) {
52
+ errors.push(`Glossary data must contain a "terms" array`);
53
+ return { terms: [], errors };
54
+ }
55
+ if (!Array.isArray(data.terms)) {
56
+ errors.push(`Field "terms" must be an array, got ${typeof data.terms}`);
57
+ return { terms: [], errors };
58
+ }
59
+ data.terms.forEach((term, index) => {
60
+ if (term === null || term === void 0 || typeof term !== "object") {
61
+ errors.push(`terms[${index}]: Term must be an object`);
62
+ return;
63
+ }
64
+ if (typeof term.term !== "string" || term.term.trim() === "") {
65
+ errors.push(`terms[${index}]: Missing or invalid "term" field`);
66
+ return;
67
+ }
68
+ if (typeof term.definition !== "string") {
69
+ errors.push(`terms[${index}]: Missing or invalid "definition" field`);
70
+ return;
71
+ }
72
+ validTerms.push(term);
73
+ });
74
+ return { terms: validTerms, errors };
75
+ }
76
+ var glossaryCache = /* @__PURE__ */ new Map();
77
+ var CACHE_TTL = 5e3;
78
+ function remarkGlossaryTerms({
79
+ terms = [],
80
+ glossaryPath = null,
81
+ routePath = "/glossary",
82
+ siteDir = null
83
+ } = {}) {
84
+ let glossaryTerms = terms;
85
+ if (!glossaryTerms.length && glossaryPath && siteDir) {
86
+ try {
87
+ const glossaryFilePath = import_path.default.resolve(siteDir, glossaryPath);
88
+ const now = Date.now();
89
+ const cached = glossaryCache.get(glossaryFilePath);
90
+ if (cached && now - cached.loadedAt < CACHE_TTL) {
91
+ glossaryTerms = cached.terms;
92
+ } else {
93
+ if (import_fs.default.existsSync(glossaryFilePath)) {
94
+ const fileContent = import_fs.default.readFileSync(glossaryFilePath, "utf8");
95
+ let glossaryData;
96
+ try {
97
+ glossaryData = JSON.parse(fileContent);
98
+ } catch (parseError) {
99
+ console.error(
100
+ `[glossary-plugin] Failed to parse glossary JSON at ${glossaryPath}:`,
101
+ parseError.message
102
+ );
103
+ glossaryCache.set(glossaryFilePath, {
104
+ terms: [],
105
+ loadedAt: now
106
+ });
107
+ return (tree) => tree;
108
+ }
109
+ const { terms: validTerms, errors } = validateGlossaryTerms(glossaryData, glossaryPath);
110
+ if (errors.length > 0) {
111
+ console.warn(`[glossary-plugin] Glossary validation errors in ${glossaryPath}:`);
112
+ errors.forEach((err) => console.warn(` - ${err}`));
113
+ if (validTerms.length > 0) {
114
+ console.warn(`[glossary-plugin] Proceeding with ${validTerms.length} valid term(s).`);
115
+ }
116
+ }
117
+ glossaryTerms = validTerms;
118
+ glossaryCache.set(glossaryFilePath, {
119
+ terms: glossaryTerms,
120
+ loadedAt: now
121
+ });
122
+ if (!cached && process.env.NODE_ENV !== "production") {
123
+ console.log(
124
+ `[glossary-plugin] Loaded ${glossaryTerms.length} terms from ${glossaryPath}`
125
+ );
126
+ }
127
+ } else {
128
+ glossaryCache.set(glossaryFilePath, {
129
+ terms: [],
130
+ loadedAt: now
131
+ });
132
+ if (process.env.NODE_ENV !== "production") {
133
+ console.warn(`[glossary-plugin] Glossary file not found: ${glossaryPath}`);
134
+ }
135
+ }
136
+ }
137
+ } catch (error) {
138
+ console.warn(
139
+ `[glossary-plugin] Failed to load glossary from ${glossaryPath}:`,
140
+ error.message
141
+ );
142
+ if (glossaryPath && siteDir) {
143
+ const glossaryFilePath = import_path.default.resolve(siteDir, glossaryPath);
144
+ glossaryCache.set(glossaryFilePath, {
145
+ terms: [],
146
+ loadedAt: Date.now()
147
+ });
148
+ }
149
+ }
150
+ }
151
+ const termMap = /* @__PURE__ */ new Map();
152
+ glossaryTerms.forEach((termObj) => {
153
+ if (termObj.term && termObj.autoLink !== false) {
154
+ termMap.set(termObj.term.toLowerCase(), termObj);
155
+ }
156
+ });
157
+ const sortedTerms = Array.from(termMap.entries()).sort((a, b) => b[0].length - a[0].length);
158
+ if (sortedTerms.length === 0) {
159
+ return (tree) => tree;
160
+ }
161
+ function replaceTermsInText(text) {
162
+ if (!text || !sortedTerms.length) {
163
+ return [{ type: "text", value: text }];
164
+ }
165
+ const result = [];
166
+ let lastIndex = 0;
167
+ const textLower = text.toLowerCase();
168
+ const matches = [];
169
+ for (const [lowerTerm, termObj] of sortedTerms) {
170
+ const term = termObj.term;
171
+ let searchIndex = 0;
172
+ while (searchIndex < textLower.length) {
173
+ const index = textLower.indexOf(lowerTerm, searchIndex);
174
+ if (index === -1) break;
175
+ const beforeChar = index > 0 ? textLower[index - 1] : " ";
176
+ const afterIndex = index + lowerTerm.length;
177
+ const afterChar = afterIndex < textLower.length ? textLower[afterIndex] : " ";
178
+ let matchLength = term.length;
179
+ let isWordBoundary = !/\w/.test(beforeChar) && !/\w/.test(afterChar);
180
+ if (!isWordBoundary && afterChar === "s") {
181
+ const nextChar = afterIndex + 1 < textLower.length ? textLower[afterIndex + 1] : " ";
182
+ if (!/\w/.test(nextChar)) {
183
+ isWordBoundary = true;
184
+ matchLength = term.length + 1;
185
+ }
186
+ }
187
+ if (!isWordBoundary && afterChar === "e" && afterIndex + 1 < textLower.length && textLower[afterIndex + 1] === "s") {
188
+ const nextChar = afterIndex + 2 < textLower.length ? textLower[afterIndex + 2] : " ";
189
+ if (!/\w/.test(nextChar)) {
190
+ isWordBoundary = true;
191
+ matchLength = term.length + 2;
192
+ }
193
+ }
194
+ if (isWordBoundary) {
195
+ matches.push({
196
+ index,
197
+ length: matchLength,
198
+ term,
199
+ termObj,
200
+ // Store original case from the text
201
+ originalText: text.substring(index, index + matchLength)
202
+ });
203
+ }
204
+ searchIndex = index + 1;
205
+ }
206
+ }
207
+ matches.sort((a, b) => a.index - b.index);
208
+ const nonOverlappingMatches = [];
209
+ let lastMatchEnd = 0;
210
+ for (const match of matches) {
211
+ if (match.index >= lastMatchEnd) {
212
+ nonOverlappingMatches.push(match);
213
+ lastMatchEnd = match.index + match.length;
214
+ }
215
+ }
216
+ for (const match of nonOverlappingMatches) {
217
+ if (match.index > lastIndex) {
218
+ result.push({
219
+ type: "text",
220
+ value: text.substring(lastIndex, match.index)
221
+ });
222
+ }
223
+ result.push({
224
+ type: "mdxJsxFlowElement",
225
+ name: "GlossaryTerm",
226
+ attributes: [
227
+ {
228
+ type: "mdxJsxAttribute",
229
+ name: "term",
230
+ value: match.termObj.term
231
+ },
232
+ {
233
+ type: "mdxJsxAttribute",
234
+ name: "definition",
235
+ value: match.termObj.definition || ""
236
+ },
237
+ {
238
+ type: "mdxJsxAttribute",
239
+ name: "routePath",
240
+ value: routePath
241
+ }
242
+ ],
243
+ children: [
244
+ {
245
+ type: "text",
246
+ value: match.originalText
247
+ }
248
+ ]
249
+ });
250
+ lastIndex = match.index + match.length;
251
+ }
252
+ if (lastIndex < text.length) {
253
+ result.push({
254
+ type: "text",
255
+ value: text.substring(lastIndex)
256
+ });
257
+ }
258
+ return result.length > 0 ? result : [{ type: "text", value: text }];
259
+ }
260
+ const transformer = (tree) => {
261
+ let usedGlossaryTerm = false;
262
+ (0, import_unist_util_visit.visit)(tree, "text", (node, index, parent) => {
263
+ if (parent.type === "code" || parent.type === "inlineCode" || parent.type === "link" || parent.type === "mdxJsxFlowElement" || parent.type === "mdxJsxTextElement") {
264
+ return;
265
+ }
266
+ const replacements = replaceTermsInText(node.value);
267
+ if (replacements.length > 1 || replacements.length === 1 && replacements[0].type !== "text") {
268
+ const newNodes = replacements.map((replacement) => {
269
+ if (replacement.type === "mdxJsxFlowElement") {
270
+ if (parent.type === "paragraph") {
271
+ usedGlossaryTerm = true;
272
+ return {
273
+ type: "mdxJsxTextElement",
274
+ name: replacement.name,
275
+ attributes: replacement.attributes,
276
+ children: replacement.children
277
+ };
278
+ }
279
+ usedGlossaryTerm = true;
280
+ }
281
+ return replacement;
282
+ });
283
+ parent.children.splice(index, 1, ...newNodes);
284
+ return index + newNodes.length - 1;
285
+ }
286
+ });
287
+ if (usedGlossaryTerm) {
288
+ const importNode = {
289
+ type: "mdxjsEsm",
290
+ value: 'import GlossaryTerm from "@theme/GlossaryTerm";',
291
+ data: {
292
+ estree: {
293
+ type: "Program",
294
+ sourceType: "module",
295
+ body: [
296
+ {
297
+ type: "ImportDeclaration",
298
+ specifiers: [
299
+ {
300
+ type: "ImportDefaultSpecifier",
301
+ local: { type: "Identifier", name: "GlossaryTerm" }
302
+ }
303
+ ],
304
+ source: {
305
+ type: "Literal",
306
+ value: "@theme/GlossaryTerm",
307
+ raw: '"@theme/GlossaryTerm"'
308
+ }
309
+ }
310
+ ]
311
+ }
312
+ }
313
+ };
314
+ const hasImport = Array.isArray(tree.children) && tree.children.some(
315
+ (n) => n.type === "mdxjsEsm" && (n.value?.includes("@theme/GlossaryTerm") || n.data?.estree?.body?.some((s) => s.source?.value === "@theme/GlossaryTerm"))
316
+ );
317
+ if (!hasImport) {
318
+ if (!Array.isArray(tree.children)) tree.children = [];
319
+ let insertIndex = 0;
320
+ for (let i = 0; i < tree.children.length; i++) {
321
+ const node = tree.children[i];
322
+ if (node.type === "yaml" || node.type === "toml") {
323
+ insertIndex = i + 1;
324
+ } else {
325
+ break;
326
+ }
327
+ }
328
+ tree.children.splice(insertIndex, 0, importNode);
329
+ }
330
+ }
331
+ };
332
+ return transformer;
333
+ }
334
+ function clearGlossaryCache(filePath) {
335
+ if (filePath) {
336
+ glossaryCache.delete(filePath);
337
+ } else {
338
+ glossaryCache.clear();
339
+ }
340
+ }
341
+ // Annotate the CommonJS export names for ESM import in node:
342
+ 0 && (module.exports = {
343
+ clearGlossaryCache
344
+ });
345
+ //# sourceMappingURL=glossary-terms.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/remark/glossary-terms.js"],"sourcesContent":["import { visit } from 'unist-util-visit';\nimport path from 'path';\nimport fs from 'fs';\n\n/**\n * Simple validation for glossary terms loaded from file\n * Returns only valid terms with required fields\n *\n * @param {unknown} data - The parsed JSON data\n * @param {string} filePath - Path to the file (for error messages)\n * @returns {{ terms: Array<{term: string, definition: string}>, errors: string[] }}\n */\nfunction validateGlossaryTerms(data, _filePath) {\n const errors = [];\n const validTerms = [];\n\n if (data === null || data === undefined) {\n errors.push(`Glossary data is null or undefined`);\n return { terms: [], errors };\n }\n\n if (typeof data !== 'object') {\n errors.push(`Glossary data must be an object, got ${typeof data}`);\n return { terms: [], errors };\n }\n\n if (!('terms' in data)) {\n errors.push(`Glossary data must contain a \"terms\" array`);\n return { terms: [], errors };\n }\n\n if (!Array.isArray(data.terms)) {\n errors.push(`Field \"terms\" must be an array, got ${typeof data.terms}`);\n return { terms: [], errors };\n }\n\n data.terms.forEach((term, index) => {\n if (term === null || term === undefined || typeof term !== 'object') {\n errors.push(`terms[${index}]: Term must be an object`);\n return;\n }\n\n if (typeof term.term !== 'string' || term.term.trim() === '') {\n errors.push(`terms[${index}]: Missing or invalid \"term\" field`);\n return;\n }\n\n if (typeof term.definition !== 'string') {\n errors.push(`terms[${index}]: Missing or invalid \"definition\" field`);\n return;\n }\n\n validTerms.push(term);\n });\n\n return { terms: validTerms, errors };\n}\n\n// Cache for glossary data to avoid repeated synchronous file reads\n// Key: absolute file path, Value: { terms, loadedAt }\nconst glossaryCache = new Map();\nconst CACHE_TTL = 5000; // 5 seconds TTL to allow for file changes during dev\n\n/**\n * Creates a remark plugin that automatically detects and replaces glossary terms in markdown\n *\n * This plugin transforms plain text terms into <GlossaryTerm> JSX elements.\n * The GlossaryTerm component is globally available via the MDXComponents theme wrapper,\n * so no import injection is needed - MDX files can use it without explicit imports.\n *\n * @param {object} options - Plugin options\n * @param {Array} options.terms - Array of glossary term objects with {term, definition}\n * @param {string} options.glossaryPath - Path to glossary JSON file (optional, if terms not provided)\n * @param {string} options.routePath - Route path to glossary page (default: '/glossary')\n * @param {string} options.siteDir - Docusaurus site directory (required if using glossaryPath)\n * @returns {function} Remark plugin function\n */\nexport default function remarkGlossaryTerms({\n terms = [],\n glossaryPath = null,\n routePath = '/glossary',\n siteDir = null,\n} = {}) {\n let glossaryTerms = terms;\n\n // If terms not provided, try to load from glossaryPath with caching\n if (!glossaryTerms.length && glossaryPath && siteDir) {\n try {\n const glossaryFilePath = path.resolve(siteDir, glossaryPath);\n const now = Date.now();\n\n // Check cache first to avoid repeated file reads\n const cached = glossaryCache.get(glossaryFilePath);\n if (cached && now - cached.loadedAt < CACHE_TTL) {\n glossaryTerms = cached.terms;\n } else {\n // Cache miss or expired - load from file synchronously\n // Note: This is synchronous I/O which can block the build process\n // Consider passing terms directly to avoid this\n if (fs.existsSync(glossaryFilePath)) {\n const fileContent = fs.readFileSync(glossaryFilePath, 'utf8');\n let glossaryData;\n try {\n glossaryData = JSON.parse(fileContent);\n } catch (parseError) {\n console.error(\n `[glossary-plugin] Failed to parse glossary JSON at ${glossaryPath}:`,\n parseError.message\n );\n glossaryCache.set(glossaryFilePath, {\n terms: [],\n loadedAt: now,\n });\n return tree => tree;\n }\n\n // Validate glossary data\n const { terms: validTerms, errors } = validateGlossaryTerms(glossaryData, glossaryPath);\n\n if (errors.length > 0) {\n console.warn(`[glossary-plugin] Glossary validation errors in ${glossaryPath}:`);\n errors.forEach(err => console.warn(` - ${err}`));\n if (validTerms.length > 0) {\n console.warn(`[glossary-plugin] Proceeding with ${validTerms.length} valid term(s).`);\n }\n }\n\n glossaryTerms = validTerms;\n\n // Update cache\n glossaryCache.set(glossaryFilePath, {\n terms: glossaryTerms,\n loadedAt: now,\n });\n\n // Log only once per file (when cache is first populated)\n if (!cached && process.env.NODE_ENV !== 'production') {\n console.log(\n `[glossary-plugin] Loaded ${glossaryTerms.length} terms from ${glossaryPath}`\n );\n }\n } else {\n // File doesn't exist - cache empty result to avoid repeated checks\n glossaryCache.set(glossaryFilePath, {\n terms: [],\n loadedAt: now,\n });\n if (process.env.NODE_ENV !== 'production') {\n console.warn(`[glossary-plugin] Glossary file not found: ${glossaryPath}`);\n }\n }\n }\n } catch (error) {\n console.warn(\n `[glossary-plugin] Failed to load glossary from ${glossaryPath}:`,\n error.message\n );\n // Cache the error to avoid repeated attempts\n if (glossaryPath && siteDir) {\n const glossaryFilePath = path.resolve(siteDir, glossaryPath);\n glossaryCache.set(glossaryFilePath, {\n terms: [],\n loadedAt: Date.now(),\n });\n }\n }\n }\n\n // Build a map of terms for efficient lookup, skipping terms with autoLink: false\n // Key: lowercase term, Value: term object with original case\n const termMap = new Map();\n glossaryTerms.forEach(termObj => {\n if (termObj.term && termObj.autoLink !== false) {\n termMap.set(termObj.term.toLowerCase(), termObj);\n }\n });\n\n // Sort terms by length (longest first) to avoid partial matches\n // e.g., \"Application Programming Interface\" should match before \"API\"\n const sortedTerms = Array.from(termMap.entries()).sort((a, b) => b[0].length - a[0].length);\n\n // If no terms, return a no-op transformer\n if (sortedTerms.length === 0) {\n return tree => tree;\n }\n\n /**\n * Recursively replace glossary terms in text\n * Returns an array of text nodes and MDX components\n */\n function replaceTermsInText(text) {\n if (!text || !sortedTerms.length) {\n return [{ type: 'text', value: text }];\n }\n\n const result = [];\n let lastIndex = 0;\n const textLower = text.toLowerCase();\n\n // Find all matches\n const matches = [];\n for (const [lowerTerm, termObj] of sortedTerms) {\n const term = termObj.term;\n let searchIndex = 0;\n\n while (searchIndex < textLower.length) {\n const index = textLower.indexOf(lowerTerm, searchIndex);\n if (index === -1) break;\n\n // Check if it's a whole word match, with simple plural tolerance ('s' or 'es')\n const beforeChar = index > 0 ? textLower[index - 1] : ' ';\n const afterIndex = index + lowerTerm.length;\n const afterChar = afterIndex < textLower.length ? textLower[afterIndex] : ' ';\n\n let matchLength = term.length;\n let isWordBoundary = !/\\w/.test(beforeChar) && !/\\w/.test(afterChar);\n\n // Allow trailing 's' plural (e.g., webhook -> webhooks)\n if (!isWordBoundary && afterChar === 's') {\n const nextChar = afterIndex + 1 < textLower.length ? textLower[afterIndex + 1] : ' ';\n if (!/\\w/.test(nextChar)) {\n isWordBoundary = true;\n matchLength = term.length + 1;\n }\n }\n\n // Allow trailing 'es' plural (e.g., API -> APIs, box -> boxes)\n if (\n !isWordBoundary &&\n afterChar === 'e' &&\n afterIndex + 1 < textLower.length &&\n textLower[afterIndex + 1] === 's'\n ) {\n const nextChar = afterIndex + 2 < textLower.length ? textLower[afterIndex + 2] : ' ';\n if (!/\\w/.test(nextChar)) {\n isWordBoundary = true;\n matchLength = term.length + 2;\n }\n }\n\n if (isWordBoundary) {\n matches.push({\n index,\n length: matchLength,\n term: term,\n termObj: termObj,\n // Store original case from the text\n originalText: text.substring(index, index + matchLength),\n });\n }\n\n searchIndex = index + 1;\n }\n }\n\n // Sort matches by index\n matches.sort((a, b) => a.index - b.index);\n\n // Remove overlapping matches (keep the first one)\n const nonOverlappingMatches = [];\n let lastMatchEnd = 0;\n for (const match of matches) {\n if (match.index >= lastMatchEnd) {\n nonOverlappingMatches.push(match);\n lastMatchEnd = match.index + match.length;\n }\n }\n\n // Build result array\n for (const match of nonOverlappingMatches) {\n // Add text before match\n if (match.index > lastIndex) {\n result.push({\n type: 'text',\n value: text.substring(lastIndex, match.index),\n });\n }\n\n // Add MDX component for glossary term\n result.push({\n type: 'mdxJsxFlowElement',\n name: 'GlossaryTerm',\n attributes: [\n {\n type: 'mdxJsxAttribute',\n name: 'term',\n value: match.termObj.term,\n },\n {\n type: 'mdxJsxAttribute',\n name: 'definition',\n value: match.termObj.definition || '',\n },\n {\n type: 'mdxJsxAttribute',\n name: 'routePath',\n value: routePath,\n },\n ],\n children: [\n {\n type: 'text',\n value: match.originalText,\n },\n ],\n });\n\n lastIndex = match.index + match.length;\n }\n\n // Add remaining text\n if (lastIndex < text.length) {\n result.push({\n type: 'text',\n value: text.substring(lastIndex),\n });\n }\n\n return result.length > 0 ? result : [{ type: 'text', value: text }];\n }\n\n // Return the transformer function\n const transformer = tree => {\n let usedGlossaryTerm = false;\n visit(tree, 'text', (node, index, parent) => {\n // Skip text nodes inside code blocks, links, or existing MDX components\n if (\n parent.type === 'code' ||\n parent.type === 'inlineCode' ||\n parent.type === 'link' ||\n parent.type === 'mdxJsxFlowElement' ||\n parent.type === 'mdxJsxTextElement'\n ) {\n return;\n }\n\n // Replace terms in text node\n const replacements = replaceTermsInText(node.value);\n\n // If we have replacements, replace the single text node with multiple nodes\n if (\n replacements.length > 1 ||\n (replacements.length === 1 && replacements[0].type !== 'text')\n ) {\n // Convert to text elements for paragraph context if needed\n const newNodes = replacements.map(replacement => {\n if (replacement.type === 'mdxJsxFlowElement') {\n // In paragraph context, we need mdxJsxTextElement instead\n if (parent.type === 'paragraph') {\n usedGlossaryTerm = true;\n return {\n type: 'mdxJsxTextElement',\n name: replacement.name,\n attributes: replacement.attributes,\n children: replacement.children,\n };\n }\n usedGlossaryTerm = true;\n }\n return replacement;\n });\n\n // Replace the single node with multiple nodes\n parent.children.splice(index, 1, ...newNodes);\n return index + newNodes.length - 1; // Return new index to continue\n }\n });\n\n // Inject MDX import for GlossaryTerm if we used it\n // The component is available via theme path, so we just need to import it\n if (usedGlossaryTerm) {\n const importNode = {\n type: 'mdxjsEsm',\n value: 'import GlossaryTerm from \"@theme/GlossaryTerm\";',\n data: {\n estree: {\n type: 'Program',\n sourceType: 'module',\n body: [\n {\n type: 'ImportDeclaration',\n specifiers: [\n {\n type: 'ImportDefaultSpecifier',\n local: { type: 'Identifier', name: 'GlossaryTerm' },\n },\n ],\n source: {\n type: 'Literal',\n value: '@theme/GlossaryTerm',\n raw: '\"@theme/GlossaryTerm\"',\n },\n },\n ],\n },\n },\n };\n\n // Check for existing import\n const hasImport =\n Array.isArray(tree.children) &&\n tree.children.some(\n n =>\n n.type === 'mdxjsEsm' &&\n (n.value?.includes('@theme/GlossaryTerm') ||\n n.data?.estree?.body?.some(s => s.source?.value === '@theme/GlossaryTerm'))\n );\n\n if (!hasImport) {\n if (!Array.isArray(tree.children)) tree.children = [];\n let insertIndex = 0;\n for (let i = 0; i < tree.children.length; i++) {\n const node = tree.children[i];\n if (node.type === 'yaml' || node.type === 'toml') {\n insertIndex = i + 1;\n } else {\n break;\n }\n }\n tree.children.splice(insertIndex, 0, importNode);\n }\n }\n };\n\n return transformer;\n}\n\n/**\n * Clears the glossary cache\n * Useful for testing or when you want to force a reload of glossary data\n *\n * @param {string} [filePath] - Optional specific file path to clear. If not provided, clears entire cache.\n */\nexport function clearGlossaryCache(filePath) {\n if (filePath) {\n glossaryCache.delete(filePath);\n } else {\n glossaryCache.clear();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAAsB;AACtB,kBAAiB;AACjB,gBAAe;AAUf,SAAS,sBAAsB,MAAM,WAAW;AAC9C,QAAM,SAAS,CAAC;AAChB,QAAM,aAAa,CAAC;AAEpB,MAAI,SAAS,QAAQ,SAAS,QAAW;AACvC,WAAO,KAAK,oCAAoC;AAChD,WAAO,EAAE,OAAO,CAAC,GAAG,OAAO;AAAA,EAC7B;AAEA,MAAI,OAAO,SAAS,UAAU;AAC5B,WAAO,KAAK,wCAAwC,OAAO,IAAI,EAAE;AACjE,WAAO,EAAE,OAAO,CAAC,GAAG,OAAO;AAAA,EAC7B;AAEA,MAAI,EAAE,WAAW,OAAO;AACtB,WAAO,KAAK,4CAA4C;AACxD,WAAO,EAAE,OAAO,CAAC,GAAG,OAAO;AAAA,EAC7B;AAEA,MAAI,CAAC,MAAM,QAAQ,KAAK,KAAK,GAAG;AAC9B,WAAO,KAAK,uCAAuC,OAAO,KAAK,KAAK,EAAE;AACtE,WAAO,EAAE,OAAO,CAAC,GAAG,OAAO;AAAA,EAC7B;AAEA,OAAK,MAAM,QAAQ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