@lithent/lithent-mdx 0.2.6 → 0.2.7

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.
package/dist/index.cjs ADDED
@@ -0,0 +1,14 @@
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const b=require("@mdx-js/rollup"),g=n=>n&&n.__esModule?n:{default:n},$=g(b),a="/* __lithentMdxWrapped */",p=n=>{const r=w(n),e=r!==n;if(r.includes(a))return{code:r,modified:e};const t=k(r);if(t<0)return{code:r,modified:e};const o="MDXContent",i=t,c=i+34;let s=`${r.slice(0,i)}function ${o}${r.slice(c)}`;_(s,"lithent","mount")||(s=M(s,`import { mount } from 'lithent';
2
+ `));const f=`__LithentMdxComponent_${o}`,h=`
3
+ ${a}
4
+ const ${f} = mount((_renew, props) => {
5
+ return () => ${o}(props ?? {});
6
+ });
7
+ export default ${f};
8
+ `;return s=`${s}${h}`,{code:s,modified:!0}},k=n=>{const r="export default function MDXContent",e=n.length;let t=0,o="code",i=0;for(;t<e;){const c=n[t],s=n[t+1];switch(o){case"code":if(c==="/"){if(s==="/"){o="lineComment",t+=2;continue}if(s==="*"){o="blockComment",t+=2;continue}}if(c==="'"){o="single",t++;continue}if(c==='"'){o="double",t++;continue}if(c==="`"){o="template",i=0,t++;continue}if(n.startsWith(r,t))return t;t++;break;case"single":if(c==="\\"){t+=2;continue}c==="'"&&(o="code"),t++;break;case"double":if(c==="\\"){t+=2;continue}c==='"'&&(o="code"),t++;break;case"template":if(c==="\\"){t+=2;continue}if(c==="`"){if(i===0){o="code",t++;break}i--,t++;break}if(c==="$"&&s==="{"){i++,t+=2;break}if(c==="}"){i>0&&i--,t++;break}t++;break;case"lineComment":c===`
9
+ `&&(o="code"),t++;break;case"blockComment":if(c==="*"&&s==="/"){o="code",t+=2;break}t++;break}}return-1},w=n=>{const r=(i,c)=>i.replace(new RegExp(`^(\\s*)(?:export\\s+)?function\\s+${c}`,"gm"),(s,l)=>s.trimStart().startsWith("export ")?s:`${l}export function ${c}`),e=(i,c)=>i.replace(new RegExp(`^(\\s*)(?:export\\s+)?function\\s+${c}`,"gm"),(s,l)=>s.trimStart().startsWith("export default")?s:`${l}export default function ${c}`),t=r(n,"_createMdxContent");return e(t,"MDXContent")},M=(n,r)=>{const e=C(n);if(e>=0){const o=e>0&&n[e-1]!==`
10
+ `?`
11
+ ${r}`:r;return`${n.slice(0,e)}${o}${n.slice(e)}`}return`${r}${n}`},m=n=>{const r=[];let e=0,t="code",o=0;for(;e<n.length;){const i=n[e],c=n[e+1];switch(t){case"code":{if(i==="/"&&c==="/"){t="lineComment",e+=2;continue}if(i==="/"&&c==="*"){t="blockComment",e+=2;continue}if(i==="'"){t="single",e++;continue}if(i==='"'){t="double",e++;continue}if(i==="`"){t="template",o=0,e++;continue}if(e===0&&i==="#"&&c==="!"){t="lineComment",e+=2;continue}if(i==="i"&&I(n,e)&&!E(n,e)){const s=D(n,e);r.push({start:e,end:s,code:n.slice(e,s)}),e=s;continue}e++;break}case"single":if(i==="\\"){e+=2;continue}i==="'"&&(t="code"),e++;break;case"double":if(i==="\\"){e+=2;continue}i==='"'&&(t="code"),e++;break;case"template":if(i==="\\"){e+=2;continue}if(i==="`"){if(o===0){t="code",e++;continue}o--,e++;continue}if(i==="$"&&c==="{"){o++,e+=2;continue}i==="}"&&o>0&&o--,e++;break;case"lineComment":i===`
12
+ `&&(t="code"),e++;break;case"blockComment":if(i==="*"&&c==="/"){t="code",e+=2;continue}e++;break}}return r},C=n=>{const r=m(n);return r.length?r[r.length-1].end:-1},_=(n,r,e)=>{const t=m(n),o=new RegExp(`from\\s+['"]${u(r)}['"]`),i=new RegExp(`\\b${u(e)}\\b`);return t.some(c=>{if(!o.test(c.code))return!1;const[s]=c.code.split(/from\s+/i);return i.test(s)})},u=n=>n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),I=(n,r)=>{if(!n.startsWith("import",r))return!1;const e=n[r-1];if(e&&d(e))return!1;const t=n[r+6];return!(t&&d(t))},d=n=>/[A-Za-z0-9_$]/.test(n),E=(n,r)=>{const e=n[r+6];return!e||e==="("||e==="."},D=(n,r)=>{let e=r,t="code";for(;e<n.length;){const o=n[e],i=n[e+1];switch(t){case"code":if(o===";")return e+1;if(o==="/"&&i==="/"){t="lineComment",e+=2;continue}if(o==="/"&&i==="*"){t="blockComment",e+=2;continue}if(o==="'"){t="single",e++;continue}if(o==='"'){t="double",e++;continue}if(o==="`"){t="template",e++;continue}e++;break;case"single":if(o==="\\"){e+=2;continue}o==="'"&&(t="code"),e++;break;case"double":if(o==="\\"){e+=2;continue}o==='"'&&(t="code"),e++;break;case"template":if(o==="\\"){e+=2;continue}o==="`"&&(t="code"),e++;break;case"lineComment":o===`
13
+ `&&(t="code"),e++;break;case"blockComment":if(o==="*"&&i==="/"){t="code",e+=2;continue}e++;break}}return n.length},x=(n={})=>{const r=n.jsxImportSource??"lithent";return[$.default({jsxImportSource:r,...n.mdxOptions}),{name:"lithent:mdx-wrapper",enforce:void 0,transform(o,i){const[c]=i.split("?",1);if(!/\.mdx$/i.test(c))return null;const s=p(o);return s.modified?{code:s.code,map:null}:null}}]};exports.MDX_WRAP_SENTINEL=a;exports.default=x;exports.lithentMdx=x;exports.wrapMdxModule=p;
14
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../src/transform.ts","../src/plugin.ts"],"sourcesContent":["export interface MdxWrapResult {\n code: string;\n modified: boolean;\n}\n\nexport const MDX_WRAP_SENTINEL = '/* __lithentMdxWrapped */';\n\nexport const wrapMdxModule = (code: string): MdxWrapResult => {\n const fixedExports = wrapMdxExports(code);\n const exportsModified = fixedExports !== code;\n\n if (fixedExports.includes(MDX_WRAP_SENTINEL)) {\n return { code: fixedExports, modified: exportsModified };\n }\n\n const defaultExportIndex = findDefaultMdxExportIndex(fixedExports);\n\n if (defaultExportIndex < 0) {\n return { code: fixedExports, modified: exportsModified };\n }\n\n const fnName = 'MDXContent';\n\n const start = defaultExportIndex;\n const end = start + 'export default function MDXContent'.length;\n let updated = `${fixedExports.slice(0, start)}function ${fnName}${fixedExports.slice(end)}`;\n\n // Ensure mount import exists\n const hasMountImport = hasNamedImportFrom(updated, 'lithent', 'mount');\n\n if (!hasMountImport) {\n updated = insertImportString(updated, `import { mount } from 'lithent';\\n`);\n }\n\n const wrapperVar = `__LithentMdxComponent_${fnName}`;\n const wrapperSnippet = `\n${MDX_WRAP_SENTINEL}\nconst ${wrapperVar} = mount((_renew, props) => {\n return () => ${fnName}(props ?? {});\n});\nexport default ${wrapperVar};\n`;\n\n updated = `${updated}${wrapperSnippet}`;\n\n return { code: updated, modified: true };\n};\n\nconst findDefaultMdxExportIndex = (source: string): number => {\n const target = 'export default function MDXContent';\n const length = source.length;\n let i = 0;\n let state:\n | 'code'\n | 'single'\n | 'double'\n | 'template'\n | 'lineComment'\n | 'blockComment' = 'code';\n let templateDepth = 0;\n\n while (i < length) {\n const ch = source[i];\n const next = source[i + 1];\n\n switch (state) {\n case 'code':\n if (ch === '/') {\n if (next === '/') {\n state = 'lineComment';\n i += 2;\n continue;\n }\n if (next === '*') {\n state = 'blockComment';\n i += 2;\n continue;\n }\n }\n if (ch === \"'\") {\n state = 'single';\n i++;\n continue;\n }\n if (ch === '\"') {\n state = 'double';\n i++;\n continue;\n }\n if (ch === '`') {\n state = 'template';\n templateDepth = 0;\n i++;\n continue;\n }\n if (source.startsWith(target, i)) {\n return i;\n }\n i++;\n break;\n\n case 'single':\n if (ch === '\\\\') {\n i += 2;\n continue;\n }\n if (ch === \"'\") {\n state = 'code';\n }\n i++;\n break;\n\n case 'double':\n if (ch === '\\\\') {\n i += 2;\n continue;\n }\n if (ch === '\"') {\n state = 'code';\n }\n i++;\n break;\n\n case 'template':\n if (ch === '\\\\') {\n i += 2;\n continue;\n }\n if (ch === '`') {\n if (templateDepth === 0) {\n state = 'code';\n i++;\n break;\n }\n templateDepth--;\n i++;\n break;\n }\n if (ch === '$' && next === '{') {\n templateDepth++;\n i += 2;\n break;\n }\n if (ch === '}') {\n if (templateDepth > 0) {\n templateDepth--;\n }\n i++;\n break;\n }\n i++;\n break;\n\n case 'lineComment':\n if (ch === '\\n') {\n state = 'code';\n }\n i++;\n break;\n\n case 'blockComment':\n if (ch === '*' && next === '/') {\n state = 'code';\n i += 2;\n break;\n }\n i++;\n break;\n }\n }\n\n return -1;\n};\n\nconst wrapMdxExports = (code: string): string => {\n const ensureNamedExport = (source: string, fnName: string): string =>\n source.replace(\n new RegExp(`^(\\\\s*)(?:export\\\\s+)?function\\\\s+${fnName}`, 'gm'),\n (match, leading) => {\n if (match.trimStart().startsWith('export ')) {\n return match;\n }\n return `${leading}export function ${fnName}`;\n }\n );\n\n const ensureDefaultExport = (source: string, fnName: string): string =>\n source.replace(\n new RegExp(`^(\\\\s*)(?:export\\\\s+)?function\\\\s+${fnName}`, 'gm'),\n (match, leading) => {\n if (match.trimStart().startsWith('export default')) {\n return match;\n }\n return `${leading}export default function ${fnName}`;\n }\n );\n\n const withNamed = ensureNamedExport(code, '_createMdxContent');\n const withDefault = ensureDefaultExport(withNamed, 'MDXContent');\n return withDefault;\n};\n\nconst insertImportString = (source: string, statement: string): string => {\n const insertPos = findImportInsertionIndex(source);\n\n if (insertPos >= 0) {\n const needsLeadingNewline =\n insertPos > 0 && source[insertPos - 1] !== '\\n';\n const snippet = needsLeadingNewline ? `\\n${statement}` : statement;\n return `${source.slice(0, insertPos)}${snippet}${source.slice(insertPos)}`;\n }\n\n return `${statement}${source}`;\n};\n\ntype ScannerState =\n | 'code'\n | 'single'\n | 'double'\n | 'template'\n | 'lineComment'\n | 'blockComment';\n\ninterface ImportStatement {\n start: number;\n end: number;\n code: string;\n}\n\nconst getImportStatements = (source: string): ImportStatement[] => {\n const statements: ImportStatement[] = [];\n let i = 0;\n let state: ScannerState = 'code';\n let templateDepth = 0;\n\n while (i < source.length) {\n const ch = source[i];\n const next = source[i + 1];\n\n switch (state) {\n case 'code': {\n if (ch === '/' && next === '/') {\n state = 'lineComment';\n i += 2;\n continue;\n }\n if (ch === '/' && next === '*') {\n state = 'blockComment';\n i += 2;\n continue;\n }\n if (ch === \"'\") {\n state = 'single';\n i++;\n continue;\n }\n if (ch === '\"') {\n state = 'double';\n i++;\n continue;\n }\n if (ch === '`') {\n state = 'template';\n templateDepth = 0;\n i++;\n continue;\n }\n if (i === 0 && ch === '#' && next === '!') {\n state = 'lineComment';\n i += 2;\n continue;\n }\n if (\n ch === 'i' &&\n isImportKeyword(source, i) &&\n !isDynamicImport(source, i)\n ) {\n const end = findImportStatementEnd(source, i);\n statements.push({\n start: i,\n end,\n code: source.slice(i, end),\n });\n i = end;\n continue;\n }\n i++;\n break;\n }\n\n case 'single':\n if (ch === '\\\\') {\n i += 2;\n continue;\n }\n if (ch === \"'\") {\n state = 'code';\n }\n i++;\n break;\n\n case 'double':\n if (ch === '\\\\') {\n i += 2;\n continue;\n }\n if (ch === '\"') {\n state = 'code';\n }\n i++;\n break;\n\n case 'template':\n if (ch === '\\\\') {\n i += 2;\n continue;\n }\n if (ch === '`') {\n if (templateDepth === 0) {\n state = 'code';\n i++;\n continue;\n }\n templateDepth--;\n i++;\n continue;\n }\n if (ch === '$' && next === '{') {\n templateDepth++;\n i += 2;\n continue;\n }\n if (ch === '}' && templateDepth > 0) {\n templateDepth--;\n }\n i++;\n break;\n\n case 'lineComment':\n if (ch === '\\n') {\n state = 'code';\n }\n i++;\n break;\n\n case 'blockComment':\n if (ch === '*' && next === '/') {\n state = 'code';\n i += 2;\n continue;\n }\n i++;\n break;\n }\n }\n\n return statements;\n};\n\nconst findImportInsertionIndex = (source: string): number => {\n const statements = getImportStatements(source);\n\n if (!statements.length) {\n return -1;\n }\n\n return statements[statements.length - 1].end;\n};\n\nconst hasNamedImportFrom = (\n source: string,\n specifier: string,\n name: string\n): boolean => {\n const statements = getImportStatements(source);\n const fromPattern = new RegExp(\n `from\\\\s+['\"]${escapeRegExp(specifier)}['\"]`\n );\n const namePattern = new RegExp(`\\\\b${escapeRegExp(name)}\\\\b`);\n\n return statements.some(statement => {\n if (!fromPattern.test(statement.code)) {\n return false;\n }\n\n const [clause] = statement.code.split(/from\\s+/i);\n return namePattern.test(clause);\n });\n};\n\nconst escapeRegExp = (value: string): string =>\n value.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\n\nconst isImportKeyword = (source: string, index: number): boolean => {\n if (!source.startsWith('import', index)) {\n return false;\n }\n\n const prev = source[index - 1];\n if (prev && isIdentifierChar(prev)) {\n return false;\n }\n\n const next = source[index + 'import'.length];\n if (next && isIdentifierChar(next)) {\n return false;\n }\n\n return true;\n};\n\nconst isIdentifierChar = (ch: string): boolean => /[A-Za-z0-9_$]/.test(ch);\n\nconst isDynamicImport = (source: string, index: number): boolean => {\n const nextChar = source[index + 'import'.length];\n if (!nextChar) {\n return true;\n }\n if (nextChar === '(' || nextChar === '.') {\n return true;\n }\n return false;\n};\n\nconst findImportStatementEnd = (source: string, start: number): number => {\n let i = start;\n let state: ScannerState = 'code';\n\n while (i < source.length) {\n const ch = source[i];\n const next = source[i + 1];\n\n switch (state) {\n case 'code':\n if (ch === ';') {\n return i + 1;\n }\n if (ch === '/' && next === '/') {\n state = 'lineComment';\n i += 2;\n continue;\n }\n if (ch === '/' && next === '*') {\n state = 'blockComment';\n i += 2;\n continue;\n }\n if (ch === \"'\") {\n state = 'single';\n i++;\n continue;\n }\n if (ch === '\"') {\n state = 'double';\n i++;\n continue;\n }\n if (ch === '`') {\n state = 'template';\n i++;\n continue;\n }\n i++;\n break;\n\n case 'single':\n if (ch === '\\\\') {\n i += 2;\n continue;\n }\n if (ch === \"'\") {\n state = 'code';\n }\n i++;\n break;\n\n case 'double':\n if (ch === '\\\\') {\n i += 2;\n continue;\n }\n if (ch === '\"') {\n state = 'code';\n }\n i++;\n break;\n\n case 'template':\n if (ch === '\\\\') {\n i += 2;\n continue;\n }\n if (ch === '`') {\n state = 'code';\n }\n i++;\n break;\n\n case 'lineComment':\n if (ch === '\\n') {\n state = 'code';\n }\n i++;\n break;\n\n case 'blockComment':\n if (ch === '*' && next === '/') {\n state = 'code';\n i += 2;\n continue;\n }\n i++;\n break;\n }\n }\n\n return source.length;\n};\n","import type { Plugin, PluginOption } from 'vite';\nimport mdxRollup from '@mdx-js/rollup';\nimport { wrapMdxModule } from './transform';\n\nexport interface LithentMdxPluginOptions {\n /**\n * MDX plugin options to pass to @mdx-js/rollup\n */\n mdxOptions?: Record<string, unknown>;\n\n /**\n * JSX import source for MDX files\n * @default 'lithent'\n */\n jsxImportSource?: string;\n}\n\nexport const lithentMdx = (\n options: LithentMdxPluginOptions = {}\n): PluginOption => {\n const jsxImportSource = options.jsxImportSource ?? 'lithent';\n\n // Create the MDX rollup plugin with Lithent-specific JSX settings\n const mdxPlugin = mdxRollup({\n jsxImportSource,\n ...options.mdxOptions,\n });\n\n // Create the wrapper plugin that adds mount() wrapping\n const wrapperPlugin: Plugin = {\n name: 'lithent:mdx-wrapper',\n enforce: undefined, // normal - runs after mdxPlugin in array order\n\n transform(code, id) {\n const [filepath] = id.split('?', 1);\n\n // Only process .mdx files\n if (!/\\.mdx$/i.test(filepath)) {\n return null;\n }\n\n // Wrap MDXContent with mount() and add export default\n const result = wrapMdxModule(code);\n\n if (!result.modified) {\n return null;\n }\n\n return {\n code: result.code,\n map: null,\n };\n },\n };\n\n // Return both plugins as an array\n // Order matters: mdxPlugin first (MDX → JSX), then wrapperPlugin (add mount())\n return [mdxPlugin, wrapperPlugin];\n};\n\nexport default lithentMdx;\n"],"names":["MDX_WRAP_SENTINEL","wrapMdxModule","code","fixedExports","wrapMdxExports","exportsModified","defaultExportIndex","findDefaultMdxExportIndex","fnName","start","end","updated","hasNamedImportFrom","insertImportString","wrapperVar","wrapperSnippet","source","target","length","i","state","templateDepth","ch","next","ensureNamedExport","match","leading","ensureDefaultExport","withNamed","statement","insertPos","findImportInsertionIndex","snippet","getImportStatements","statements","isImportKeyword","isDynamicImport","findImportStatementEnd","specifier","name","fromPattern","escapeRegExp","namePattern","clause","value","index","prev","isIdentifierChar","nextChar","lithentMdx","options","jsxImportSource","mdxRollup","id","filepath","result"],"mappings":"wLAKaA,EAAoB,4BAEpBC,EAAiBC,GAAgC,CACtD,MAAAC,EAAeC,EAAeF,CAAI,EAClCG,EAAkBF,IAAiBD,EAErC,GAAAC,EAAa,SAASH,CAAiB,EACzC,MAAO,CAAE,KAAMG,EAAc,SAAUE,CAAgB,EAGnD,MAAAC,EAAqBC,EAA0BJ,CAAY,EAEjE,GAAIG,EAAqB,EACvB,MAAO,CAAE,KAAMH,EAAc,SAAUE,CAAgB,EAGzD,MAAMG,EAAS,aAETC,EAAQH,EACRI,EAAMD,EAAQ,GACpB,IAAIE,EAAU,GAAGR,EAAa,MAAM,EAAGM,CAAK,CAAC,YAAYD,CAAM,GAAGL,EAAa,MAAMO,CAAG,CAAC,GAGlEE,EAAmBD,EAAS,UAAW,OAAO,IAGnEA,EAAUE,EAAmBF,EAAS;AAAA,CAAoC,GAGtE,MAAAG,EAAa,yBAAyBN,CAAM,GAC5CO,EAAiB;AAAA,EACvBf,CAAiB;AAAA,QACXc,CAAU;AAAA,iBACDN,CAAM;AAAA;AAAA,iBAENM,CAAU;AAAA,EAGf,OAAAH,EAAA,GAAGA,CAAO,GAAGI,CAAc,GAE9B,CAAE,KAAMJ,EAAS,SAAU,EAAK,CACzC,EAEMJ,EAA6BS,GAA2B,CAC5D,MAAMC,EAAS,qCACTC,EAASF,EAAO,OACtB,IAAIG,EAAI,EACJC,EAMiB,OACjBC,EAAgB,EAEpB,KAAOF,EAAID,GAAQ,CACX,MAAAI,EAAKN,EAAOG,CAAC,EACbI,EAAOP,EAAOG,EAAI,CAAC,EAEzB,OAAQC,EAAO,CACb,IAAK,OACH,GAAIE,IAAO,IAAK,CACd,GAAIC,IAAS,IAAK,CACRH,EAAA,cACHD,GAAA,EACL,QACF,CACA,GAAII,IAAS,IAAK,CACRH,EAAA,eACHD,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M,CACVH,GAAA,EACL,QACF,CACIG,IAAO,MACDF,EAAA,QAEVD,IACA,MAEF,IAAK,SACH,GAAIG,IAAO,KAAM,CACVH,GAAA,EACL,QACF,CACIG,IAAO,MACDF,EAAA,QAEVD,IACA,MAEF,IAAK,WACH,GAAIG,IAAO,KAAM,CACVH,GAAA,EACL,QACF,CACIG,IAAO,MACDF,EAAA,QAEVD,IACA,MAEF,IAAK,cACCG,IAAO;AAAA,IACDF,EAAA,QAEVD,IACA,MAEF,IAAK,eACC,GAAAG,IAAO,KAAOC,IAAS,IAAK,CACtBH,EAAA,OACHD,GAAA,EACL,QACF,CACAA,IACA,KACJ,CACF,CAEA,OAAOH,EAAO,MAChB,ECrfaiC,EAAa,CACxBC,EAAmC,KAClB,CACX,MAAAC,EAAkBD,EAAQ,iBAAmB,UAqC5C,MAAA,CAlCWE,EAAAA,QAAU,CAC1B,gBAAAD,EACA,GAAGD,EAAQ,UAAA,CACZ,EAG6B,CAC5B,KAAM,sBACN,QAAS,OAET,UAAUhD,EAAMmD,EAAI,CAClB,KAAM,CAACC,CAAQ,EAAID,EAAG,MAAM,IAAK,CAAC,EAGlC,GAAI,CAAC,UAAU,KAAKC,CAAQ,EACnB,OAAA,KAIH,MAAAC,EAAStD,EAAcC,CAAI,EAE7B,OAACqD,EAAO,SAIL,CACL,KAAMA,EAAO,KACb,IAAK,IAAA,EALE,IAOX,CAAA,CAK8B,CAClC"}
@@ -0,0 +1,4 @@
1
+ export { lithentMdx, default } from './plugin.cjs';
2
+ export type { LithentMdxPluginOptions } from './plugin.cjs';
3
+ export { wrapMdxModule, MDX_WRAP_SENTINEL } from './transform.cjs';
4
+ export type { MdxWrapResult } from './transform.cjs';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { lithentMdx, default } from './plugin';
2
- export type { LithentMdxPluginOptions } from './plugin';
3
- export { wrapMdxModule, MDX_WRAP_SENTINEL } from './transform';
4
- export type { MdxWrapResult } from './transform';
1
+ export { lithentMdx, default } from './plugin.js';
2
+ export type { LithentMdxPluginOptions } from './plugin.js';
3
+ export { wrapMdxModule, MDX_WRAP_SENTINEL } from './transform.js';
4
+ export type { MdxWrapResult } from './transform.js';
package/dist/index.umd.js CHANGED
@@ -1,14 +1,14 @@
1
- (function(l,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("@mdx-js/rollup")):typeof define=="function"&&define.amd?define(["exports","@mdx-js/rollup"],f):(l=typeof globalThis<"u"?globalThis:l||self,f(l.lithentMdx={},l.mdxRollup))})(this,function(l,f){"use strict";const u="/* __lithentMdxWrapped */",d=n=>{const r=$(n),e=r!==n;if(r.includes(u))return{code:r,modified:e};const t=g(r);if(t<0)return{code:r,modified:e};const i="MDXContent",o=t,c=o+34;let s=`${r.slice(0,o)}function ${i}${r.slice(c)}`;M(s,"lithent","mount")||(s=k(s,`import { mount } from 'lithent';
2
- `));const b=`__LithentMdxComponent_${i}`,_=`
3
- ${u}
1
+ (function(l,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("@mdx-js/rollup")):typeof define=="function"&&define.amd?define(["exports","@mdx-js/rollup"],f):(l=typeof globalThis<"u"?globalThis:l||self,f(l.lithentMdx={},l.mdxRollup))})(this,function(l,f){"use strict";const g=(n=>n&&n.__esModule?n:{default:n})(f),a="/* __lithentMdxWrapped */",d=n=>{const r=k(n),e=r!==n;if(r.includes(a))return{code:r,modified:e};const t=$(r);if(t<0)return{code:r,modified:e};const i="MDXContent",o=t,c=o+34;let s=`${r.slice(0,o)}function ${i}${r.slice(c)}`;C(s,"lithent","mount")||(s=w(s,`import { mount } from 'lithent';
2
+ `));const b=`__LithentMdxComponent_${i}`,D=`
3
+ ${a}
4
4
  const ${b} = mount((_renew, props) => {
5
5
  return () => ${i}(props ?? {});
6
6
  });
7
7
  export default ${b};
8
- `;return s=`${s}${_}`,{code:s,modified:!0}},g=n=>{const r="export default function MDXContent",e=n.length;let t=0,i="code",o=0;for(;t<e;){const c=n[t],s=n[t+1];switch(i){case"code":if(c==="/"){if(s==="/"){i="lineComment",t+=2;continue}if(s==="*"){i="blockComment",t+=2;continue}}if(c==="'"){i="single",t++;continue}if(c==='"'){i="double",t++;continue}if(c==="`"){i="template",o=0,t++;continue}if(n.startsWith(r,t))return t;t++;break;case"single":if(c==="\\"){t+=2;continue}c==="'"&&(i="code"),t++;break;case"double":if(c==="\\"){t+=2;continue}c==='"'&&(i="code"),t++;break;case"template":if(c==="\\"){t+=2;continue}if(c==="`"){if(o===0){i="code",t++;break}o--,t++;break}if(c==="$"&&s==="{"){o++,t+=2;break}if(c==="}"){o>0&&o--,t++;break}t++;break;case"lineComment":c===`
9
- `&&(i="code"),t++;break;case"blockComment":if(c==="*"&&s==="/"){i="code",t+=2;break}t++;break}}return-1},$=n=>{const r=(o,c)=>o.replace(new RegExp(`^(\\s*)(?:export\\s+)?function\\s+${c}`,"gm"),(s,a)=>s.trimStart().startsWith("export ")?s:`${a}export function ${c}`),e=(o,c)=>o.replace(new RegExp(`^(\\s*)(?:export\\s+)?function\\s+${c}`,"gm"),(s,a)=>s.trimStart().startsWith("export default")?s:`${a}export default function ${c}`),t=r(n,"_createMdxContent");return e(t,"MDXContent")},k=(n,r)=>{const e=w(n);if(e>=0){const i=e>0&&n[e-1]!==`
8
+ `;return s=`${s}${D}`,{code:s,modified:!0}},$=n=>{const r="export default function MDXContent",e=n.length;let t=0,i="code",o=0;for(;t<e;){const c=n[t],s=n[t+1];switch(i){case"code":if(c==="/"){if(s==="/"){i="lineComment",t+=2;continue}if(s==="*"){i="blockComment",t+=2;continue}}if(c==="'"){i="single",t++;continue}if(c==='"'){i="double",t++;continue}if(c==="`"){i="template",o=0,t++;continue}if(n.startsWith(r,t))return t;t++;break;case"single":if(c==="\\"){t+=2;continue}c==="'"&&(i="code"),t++;break;case"double":if(c==="\\"){t+=2;continue}c==='"'&&(i="code"),t++;break;case"template":if(c==="\\"){t+=2;continue}if(c==="`"){if(o===0){i="code",t++;break}o--,t++;break}if(c==="$"&&s==="{"){o++,t+=2;break}if(c==="}"){o>0&&o--,t++;break}t++;break;case"lineComment":c===`
9
+ `&&(i="code"),t++;break;case"blockComment":if(c==="*"&&s==="/"){i="code",t+=2;break}t++;break}}return-1},k=n=>{const r=(o,c)=>o.replace(new RegExp(`^(\\s*)(?:export\\s+)?function\\s+${c}`,"gm"),(s,u)=>s.trimStart().startsWith("export ")?s:`${u}export function ${c}`),e=(o,c)=>o.replace(new RegExp(`^(\\s*)(?:export\\s+)?function\\s+${c}`,"gm"),(s,u)=>s.trimStart().startsWith("export default")?s:`${u}export default function ${c}`),t=r(n,"_createMdxContent");return e(t,"MDXContent")},w=(n,r)=>{const e=M(n);if(e>=0){const i=e>0&&n[e-1]!==`
10
10
  `?`
11
- ${r}`:r;return`${n.slice(0,e)}${i}${n.slice(e)}`}return`${r}${n}`},p=n=>{const r=[];let e=0,t="code",i=0;for(;e<n.length;){const o=n[e],c=n[e+1];switch(t){case"code":{if(o==="/"&&c==="/"){t="lineComment",e+=2;continue}if(o==="/"&&c==="*"){t="blockComment",e+=2;continue}if(o==="'"){t="single",e++;continue}if(o==='"'){t="double",e++;continue}if(o==="`"){t="template",i=0,e++;continue}if(e===0&&o==="#"&&c==="!"){t="lineComment",e+=2;continue}if(o==="i"&&C(n,e)&&!I(n,e)){const s=E(n,e);r.push({start:e,end:s,code:n.slice(e,s)}),e=s;continue}e++;break}case"single":if(o==="\\"){e+=2;continue}o==="'"&&(t="code"),e++;break;case"double":if(o==="\\"){e+=2;continue}o==='"'&&(t="code"),e++;break;case"template":if(o==="\\"){e+=2;continue}if(o==="`"){if(i===0){t="code",e++;continue}i--,e++;continue}if(o==="$"&&c==="{"){i++,e+=2;continue}o==="}"&&i>0&&i--,e++;break;case"lineComment":o===`
12
- `&&(t="code"),e++;break;case"blockComment":if(o==="*"&&c==="/"){t="code",e+=2;continue}e++;break}}return r},w=n=>{const r=p(n);return r.length?r[r.length-1].end:-1},M=(n,r,e)=>{const t=p(n),i=new RegExp(`from\\s+['"]${m(r)}['"]`),o=new RegExp(`\\b${m(e)}\\b`);return t.some(c=>{if(!i.test(c.code))return!1;const[s]=c.code.split(/from\s+/i);return o.test(s)})},m=n=>n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),C=(n,r)=>{if(!n.startsWith("import",r))return!1;const e=n[r-1];if(e&&x(e))return!1;const t=n[r+6];return!(t&&x(t))},x=n=>/[A-Za-z0-9_$]/.test(n),I=(n,r)=>{const e=n[r+6];return!e||e==="("||e==="."},E=(n,r)=>{let e=r,t="code";for(;e<n.length;){const i=n[e],o=n[e+1];switch(t){case"code":if(i===";")return e+1;if(i==="/"&&o==="/"){t="lineComment",e+=2;continue}if(i==="/"&&o==="*"){t="blockComment",e+=2;continue}if(i==="'"){t="single",e++;continue}if(i==='"'){t="double",e++;continue}if(i==="`"){t="template",e++;continue}e++;break;case"single":if(i==="\\"){e+=2;continue}i==="'"&&(t="code"),e++;break;case"double":if(i==="\\"){e+=2;continue}i==='"'&&(t="code"),e++;break;case"template":if(i==="\\"){e+=2;continue}i==="`"&&(t="code"),e++;break;case"lineComment":i===`
13
- `&&(t="code"),e++;break;case"blockComment":if(i==="*"&&o==="/"){t="code",e+=2;continue}e++;break}}return n.length},h=(n={})=>{const r=n.jsxImportSource??"lithent";return[f({jsxImportSource:r,...n.mdxOptions}),{name:"lithent:mdx-wrapper",enforce:void 0,transform(i,o){const[c]=o.split("?",1);if(!/\.mdx$/i.test(c))return null;const s=d(i);return s.modified?{code:s.code,map:null}:null}}]};l.MDX_WRAP_SENTINEL=u,l.default=h,l.lithentMdx=h,l.wrapMdxModule=d,Object.defineProperties(l,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
11
+ ${r}`:r;return`${n.slice(0,e)}${i}${n.slice(e)}`}return`${r}${n}`},p=n=>{const r=[];let e=0,t="code",i=0;for(;e<n.length;){const o=n[e],c=n[e+1];switch(t){case"code":{if(o==="/"&&c==="/"){t="lineComment",e+=2;continue}if(o==="/"&&c==="*"){t="blockComment",e+=2;continue}if(o==="'"){t="single",e++;continue}if(o==='"'){t="double",e++;continue}if(o==="`"){t="template",i=0,e++;continue}if(e===0&&o==="#"&&c==="!"){t="lineComment",e+=2;continue}if(o==="i"&&_(n,e)&&!I(n,e)){const s=E(n,e);r.push({start:e,end:s,code:n.slice(e,s)}),e=s;continue}e++;break}case"single":if(o==="\\"){e+=2;continue}o==="'"&&(t="code"),e++;break;case"double":if(o==="\\"){e+=2;continue}o==='"'&&(t="code"),e++;break;case"template":if(o==="\\"){e+=2;continue}if(o==="`"){if(i===0){t="code",e++;continue}i--,e++;continue}if(o==="$"&&c==="{"){i++,e+=2;continue}o==="}"&&i>0&&i--,e++;break;case"lineComment":o===`
12
+ `&&(t="code"),e++;break;case"blockComment":if(o==="*"&&c==="/"){t="code",e+=2;continue}e++;break}}return r},M=n=>{const r=p(n);return r.length?r[r.length-1].end:-1},C=(n,r,e)=>{const t=p(n),i=new RegExp(`from\\s+['"]${m(r)}['"]`),o=new RegExp(`\\b${m(e)}\\b`);return t.some(c=>{if(!i.test(c.code))return!1;const[s]=c.code.split(/from\s+/i);return o.test(s)})},m=n=>n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),_=(n,r)=>{if(!n.startsWith("import",r))return!1;const e=n[r-1];if(e&&x(e))return!1;const t=n[r+6];return!(t&&x(t))},x=n=>/[A-Za-z0-9_$]/.test(n),I=(n,r)=>{const e=n[r+6];return!e||e==="("||e==="."},E=(n,r)=>{let e=r,t="code";for(;e<n.length;){const i=n[e],o=n[e+1];switch(t){case"code":if(i===";")return e+1;if(i==="/"&&o==="/"){t="lineComment",e+=2;continue}if(i==="/"&&o==="*"){t="blockComment",e+=2;continue}if(i==="'"){t="single",e++;continue}if(i==='"'){t="double",e++;continue}if(i==="`"){t="template",e++;continue}e++;break;case"single":if(i==="\\"){e+=2;continue}i==="'"&&(t="code"),e++;break;case"double":if(i==="\\"){e+=2;continue}i==='"'&&(t="code"),e++;break;case"template":if(i==="\\"){e+=2;continue}i==="`"&&(t="code"),e++;break;case"lineComment":i===`
13
+ `&&(t="code"),e++;break;case"blockComment":if(i==="*"&&o==="/"){t="code",e+=2;continue}e++;break}}return n.length},h=(n={})=>{const r=n.jsxImportSource??"lithent";return[g.default({jsxImportSource:r,...n.mdxOptions}),{name:"lithent:mdx-wrapper",enforce:void 0,transform(i,o){const[c]=o.split("?",1);if(!/\.mdx$/i.test(c))return null;const s=d(i);return s.modified?{code:s.code,map:null}:null}}]};l.MDX_WRAP_SENTINEL=a,l.default=h,l.lithentMdx=h,l.wrapMdxModule=d,Object.defineProperties(l,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
14
14
  //# sourceMappingURL=index.umd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.umd.js","sources":["../src/transform.ts","../src/plugin.ts"],"sourcesContent":["export interface MdxWrapResult {\n code: string;\n modified: boolean;\n}\n\nexport const MDX_WRAP_SENTINEL = '/* __lithentMdxWrapped */';\n\nexport const wrapMdxModule = (code: string): MdxWrapResult => {\n const fixedExports = wrapMdxExports(code);\n const exportsModified = fixedExports !== code;\n\n if (fixedExports.includes(MDX_WRAP_SENTINEL)) {\n return { code: fixedExports, modified: exportsModified };\n }\n\n const defaultExportIndex = findDefaultMdxExportIndex(fixedExports);\n\n if (defaultExportIndex < 0) {\n return { code: fixedExports, modified: exportsModified };\n }\n\n const fnName = 'MDXContent';\n\n const start = defaultExportIndex;\n const end = start + 'export default function MDXContent'.length;\n let updated = `${fixedExports.slice(0, start)}function ${fnName}${fixedExports.slice(end)}`;\n\n // Ensure mount import exists\n const hasMountImport = hasNamedImportFrom(updated, 'lithent', 'mount');\n\n if (!hasMountImport) {\n updated = insertImportString(updated, `import { mount } from 'lithent';\\n`);\n }\n\n const wrapperVar = `__LithentMdxComponent_${fnName}`;\n const wrapperSnippet = `\n${MDX_WRAP_SENTINEL}\nconst ${wrapperVar} = mount((_renew, props) => {\n return () => ${fnName}(props ?? {});\n});\nexport default ${wrapperVar};\n`;\n\n updated = `${updated}${wrapperSnippet}`;\n\n return { code: updated, modified: true };\n};\n\nconst findDefaultMdxExportIndex = (source: string): number => {\n const target = 'export default function MDXContent';\n const length = source.length;\n let i = 0;\n let state:\n | 'code'\n | 'single'\n | 'double'\n | 'template'\n | 'lineComment'\n | 'blockComment' = 'code';\n let templateDepth = 0;\n\n while (i < length) {\n const ch = source[i];\n const next = source[i + 1];\n\n switch (state) {\n case 'code':\n if (ch === '/') {\n if (next === '/') {\n state = 'lineComment';\n i += 2;\n continue;\n }\n if (next === '*') {\n state = 'blockComment';\n i += 2;\n continue;\n }\n }\n if (ch === \"'\") {\n state = 'single';\n i++;\n continue;\n }\n if (ch === '\"') {\n state = 'double';\n i++;\n continue;\n }\n if (ch === '`') {\n state = 'template';\n templateDepth = 0;\n i++;\n continue;\n }\n if (source.startsWith(target, i)) {\n return i;\n }\n i++;\n break;\n\n case 'single':\n if (ch === '\\\\') {\n i += 2;\n continue;\n }\n if (ch === \"'\") {\n state = 'code';\n }\n i++;\n break;\n\n case 'double':\n if (ch === '\\\\') {\n i += 2;\n continue;\n }\n if (ch === '\"') {\n state = 'code';\n }\n i++;\n break;\n\n case 'template':\n if (ch === '\\\\') {\n i += 2;\n continue;\n }\n if (ch === '`') {\n if (templateDepth === 0) {\n state = 'code';\n i++;\n break;\n }\n templateDepth--;\n i++;\n break;\n }\n if (ch === '$' && next === '{') {\n templateDepth++;\n i += 2;\n break;\n }\n if (ch === '}') {\n if (templateDepth > 0) {\n templateDepth--;\n }\n i++;\n break;\n }\n i++;\n break;\n\n case 'lineComment':\n if (ch === '\\n') {\n state = 'code';\n }\n i++;\n break;\n\n case 'blockComment':\n if (ch === '*' && next === '/') {\n state = 'code';\n i += 2;\n break;\n }\n i++;\n break;\n }\n }\n\n return -1;\n};\n\nconst wrapMdxExports = (code: string): string => {\n const ensureNamedExport = (source: string, fnName: string): string =>\n source.replace(\n new RegExp(`^(\\\\s*)(?:export\\\\s+)?function\\\\s+${fnName}`, 'gm'),\n (match, leading) => {\n if (match.trimStart().startsWith('export ')) {\n return match;\n }\n return `${leading}export function ${fnName}`;\n }\n );\n\n const ensureDefaultExport = (source: string, fnName: string): string =>\n source.replace(\n new RegExp(`^(\\\\s*)(?:export\\\\s+)?function\\\\s+${fnName}`, 'gm'),\n (match, leading) => {\n if (match.trimStart().startsWith('export default')) {\n return match;\n }\n return `${leading}export default function ${fnName}`;\n }\n );\n\n const withNamed = ensureNamedExport(code, '_createMdxContent');\n const withDefault = ensureDefaultExport(withNamed, 'MDXContent');\n return withDefault;\n};\n\nconst insertImportString = (source: string, statement: string): string => {\n const insertPos = findImportInsertionIndex(source);\n\n if (insertPos >= 0) {\n const needsLeadingNewline =\n insertPos > 0 && source[insertPos - 1] !== '\\n';\n const snippet = needsLeadingNewline ? `\\n${statement}` : statement;\n return `${source.slice(0, insertPos)}${snippet}${source.slice(insertPos)}`;\n }\n\n return `${statement}${source}`;\n};\n\ntype ScannerState =\n | 'code'\n | 'single'\n | 'double'\n | 'template'\n | 'lineComment'\n | 'blockComment';\n\ninterface ImportStatement {\n start: number;\n end: number;\n code: string;\n}\n\nconst getImportStatements = (source: string): ImportStatement[] => {\n const statements: ImportStatement[] = [];\n let i = 0;\n let state: ScannerState = 'code';\n let templateDepth = 0;\n\n while (i < source.length) {\n const ch = source[i];\n const next = source[i + 1];\n\n switch (state) {\n case 'code': {\n if (ch === '/' && next === '/') {\n state = 'lineComment';\n i += 2;\n continue;\n }\n if (ch === '/' && next === '*') {\n state = 'blockComment';\n i += 2;\n continue;\n }\n if (ch === \"'\") {\n state = 'single';\n i++;\n continue;\n }\n if (ch === '\"') {\n state = 'double';\n i++;\n continue;\n }\n if (ch === '`') {\n state = 'template';\n templateDepth = 0;\n i++;\n continue;\n }\n if (i === 0 && ch === '#' && next === '!') {\n state = 'lineComment';\n i += 2;\n continue;\n }\n if (\n ch === 'i' &&\n isImportKeyword(source, i) &&\n !isDynamicImport(source, i)\n ) {\n const end = findImportStatementEnd(source, i);\n statements.push({\n start: i,\n end,\n code: source.slice(i, end),\n });\n i = end;\n continue;\n }\n i++;\n break;\n }\n\n case 'single':\n if (ch === '\\\\') {\n i += 2;\n continue;\n }\n if (ch === \"'\") {\n state = 'code';\n }\n i++;\n break;\n\n case 'double':\n if (ch === '\\\\') {\n i += 2;\n continue;\n }\n if (ch === '\"') {\n state = 'code';\n }\n i++;\n break;\n\n case 'template':\n if (ch === '\\\\') {\n i += 2;\n continue;\n }\n if (ch === '`') {\n if (templateDepth === 0) {\n state = 'code';\n i++;\n continue;\n }\n templateDepth--;\n i++;\n continue;\n }\n if (ch === '$' && next === '{') {\n templateDepth++;\n i += 2;\n continue;\n }\n if (ch === '}' && templateDepth > 0) {\n templateDepth--;\n }\n i++;\n break;\n\n case 'lineComment':\n if (ch === '\\n') {\n state = 'code';\n }\n i++;\n break;\n\n case 'blockComment':\n if (ch === '*' && next === '/') {\n state = 'code';\n i += 2;\n continue;\n }\n i++;\n break;\n }\n }\n\n return statements;\n};\n\nconst findImportInsertionIndex = (source: string): number => {\n const statements = getImportStatements(source);\n\n if (!statements.length) {\n return -1;\n }\n\n return statements[statements.length - 1].end;\n};\n\nconst hasNamedImportFrom = (\n source: string,\n specifier: string,\n name: string\n): boolean => {\n const statements = getImportStatements(source);\n const fromPattern = new RegExp(\n `from\\\\s+['\"]${escapeRegExp(specifier)}['\"]`\n );\n const namePattern = new RegExp(`\\\\b${escapeRegExp(name)}\\\\b`);\n\n return statements.some(statement => {\n if (!fromPattern.test(statement.code)) {\n return false;\n }\n\n const [clause] = statement.code.split(/from\\s+/i);\n return namePattern.test(clause);\n });\n};\n\nconst escapeRegExp = (value: string): string =>\n value.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\n\nconst isImportKeyword = (source: string, index: number): boolean => {\n if (!source.startsWith('import', index)) {\n return false;\n }\n\n const prev = source[index - 1];\n if (prev && isIdentifierChar(prev)) {\n return false;\n }\n\n const next = source[index + 'import'.length];\n if (next && isIdentifierChar(next)) {\n return false;\n }\n\n return true;\n};\n\nconst isIdentifierChar = (ch: string): boolean => /[A-Za-z0-9_$]/.test(ch);\n\nconst isDynamicImport = (source: string, index: number): boolean => {\n const nextChar = source[index + 'import'.length];\n if (!nextChar) {\n return true;\n }\n if (nextChar === '(' || nextChar === '.') {\n return true;\n }\n return false;\n};\n\nconst findImportStatementEnd = (source: string, start: number): number => {\n let i = start;\n let state: ScannerState = 'code';\n\n while (i < source.length) {\n const ch = source[i];\n const next = source[i + 1];\n\n switch (state) {\n case 'code':\n if (ch === ';') {\n return i + 1;\n }\n if (ch === '/' && next === '/') {\n state = 'lineComment';\n i += 2;\n continue;\n }\n if (ch === '/' && next === '*') {\n state = 'blockComment';\n i += 2;\n continue;\n }\n if (ch === \"'\") {\n state = 'single';\n i++;\n continue;\n }\n if (ch === '\"') {\n state = 'double';\n i++;\n continue;\n }\n if (ch === '`') {\n state = 'template';\n i++;\n continue;\n }\n i++;\n break;\n\n case 'single':\n if (ch === '\\\\') {\n i += 2;\n continue;\n }\n if (ch === \"'\") {\n state = 'code';\n }\n i++;\n break;\n\n case 'double':\n if (ch === '\\\\') {\n i += 2;\n continue;\n }\n if (ch === '\"') {\n state = 'code';\n }\n i++;\n break;\n\n case 'template':\n if (ch === '\\\\') {\n i += 2;\n continue;\n }\n if (ch === '`') {\n state = 'code';\n }\n i++;\n break;\n\n case 'lineComment':\n if (ch === '\\n') {\n state = 'code';\n }\n i++;\n break;\n\n case 'blockComment':\n if (ch === '*' && next === '/') {\n state = 'code';\n i += 2;\n continue;\n }\n i++;\n break;\n }\n }\n\n return source.length;\n};\n","import type { Plugin, PluginOption } from 'vite';\nimport mdxRollup from '@mdx-js/rollup';\nimport { wrapMdxModule } from './transform';\n\nexport interface LithentMdxPluginOptions {\n /**\n * MDX plugin options to pass to @mdx-js/rollup\n */\n mdxOptions?: Record<string, unknown>;\n\n /**\n * JSX import source for MDX files\n * @default 'lithent'\n */\n jsxImportSource?: string;\n}\n\nexport const lithentMdx = (\n options: LithentMdxPluginOptions = {}\n): PluginOption => {\n const jsxImportSource = options.jsxImportSource ?? 'lithent';\n\n // Create the MDX rollup plugin with Lithent-specific JSX settings\n const mdxPlugin = mdxRollup({\n jsxImportSource,\n ...options.mdxOptions,\n });\n\n // Create the wrapper plugin that adds mount() wrapping\n const wrapperPlugin: Plugin = {\n name: 'lithent:mdx-wrapper',\n enforce: undefined, // normal - runs after mdxPlugin in array order\n\n transform(code, id) {\n const [filepath] = id.split('?', 1);\n\n // Only process .mdx files\n if (!/\\.mdx$/i.test(filepath)) {\n return null;\n }\n\n // Wrap MDXContent with mount() and add export default\n const result = wrapMdxModule(code);\n\n if (!result.modified) {\n return null;\n }\n\n return {\n code: result.code,\n map: null,\n };\n },\n };\n\n // Return both plugins as an array\n // Order matters: mdxPlugin first (MDX → JSX), then wrapperPlugin (add mount())\n return [mdxPlugin, wrapperPlugin];\n};\n\nexport default lithentMdx;\n"],"names":["MDX_WRAP_SENTINEL","wrapMdxModule","code","fixedExports","wrapMdxExports","exportsModified","defaultExportIndex","findDefaultMdxExportIndex","fnName","start","end","updated","hasNamedImportFrom","insertImportString","wrapperVar","wrapperSnippet","source","target","length","i","state","templateDepth","ch","next","ensureNamedExport","match","leading","ensureDefaultExport","withNamed","statement","insertPos","findImportInsertionIndex","snippet","getImportStatements","statements","isImportKeyword","isDynamicImport","findImportStatementEnd","specifier","name","fromPattern","escapeRegExp","namePattern","clause","value","index","prev","isIdentifierChar","nextChar","lithentMdx","options","jsxImportSource","mdxRollup","id","filepath","result"],"mappings":"2RAKa,MAAAA,EAAoB,4BAEpBC,EAAiBC,GAAgC,CACtD,MAAAC,EAAeC,EAAeF,CAAI,EAClCG,EAAkBF,IAAiBD,EAErC,GAAAC,EAAa,SAASH,CAAiB,EACzC,MAAO,CAAE,KAAMG,EAAc,SAAUE,CAAgB,EAGnD,MAAAC,EAAqBC,EAA0BJ,CAAY,EAEjE,GAAIG,EAAqB,EACvB,MAAO,CAAE,KAAMH,EAAc,SAAUE,CAA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CACF,CAEA,OAAOH,EAAO,MAChB,ECrfaiC,EAAa,CACxBC,EAAmC,KAClB,CACX,MAAAC,EAAkBD,EAAQ,iBAAmB,UAqC5C,MAAA,CAlCWE,EAAU,CAC1B,gBAAAD,EACA,GAAGD,EAAQ,UAAA,CACZ,EAG6B,CAC5B,KAAM,sBACN,QAAS,OAET,UAAUhD,EAAMmD,EAAI,CAClB,KAAM,CAACC,CAAQ,EAAID,EAAG,MAAM,IAAK,CAAC,EAGlC,GAAI,CAAC,UAAU,KAAKC,CAAQ,EACnB,OAAA,KAIH,MAAAC,EAAStD,EAAcC,CAAI,EAE7B,OAACqD,EAAO,SAIL,CACL,KAAMA,EAAO,KACb,IAAK,IAAA,EALE,IAOX,CAAA,CAK8B,CAClC"}
1
+ {"version":3,"file":"index.umd.js","sources":["../src/transform.ts","../src/plugin.ts"],"sourcesContent":["export interface MdxWrapResult {\n code: string;\n modified: boolean;\n}\n\nexport const MDX_WRAP_SENTINEL = '/* __lithentMdxWrapped */';\n\nexport const wrapMdxModule = (code: string): MdxWrapResult => {\n const fixedExports = wrapMdxExports(code);\n const exportsModified = fixedExports !== code;\n\n if (fixedExports.includes(MDX_WRAP_SENTINEL)) {\n return { code: fixedExports, modified: exportsModified };\n }\n\n const defaultExportIndex = findDefaultMdxExportIndex(fixedExports);\n\n if (defaultExportIndex < 0) {\n return { code: fixedExports, modified: exportsModified };\n }\n\n const fnName = 'MDXContent';\n\n const start = defaultExportIndex;\n const end = start + 'export default function MDXContent'.length;\n let updated = `${fixedExports.slice(0, start)}function ${fnName}${fixedExports.slice(end)}`;\n\n // Ensure mount import exists\n const hasMountImport = hasNamedImportFrom(updated, 'lithent', 'mount');\n\n if (!hasMountImport) {\n updated = insertImportString(updated, `import { mount } from 'lithent';\\n`);\n }\n\n const wrapperVar = `__LithentMdxComponent_${fnName}`;\n const wrapperSnippet = `\n${MDX_WRAP_SENTINEL}\nconst ${wrapperVar} = mount((_renew, props) => {\n return () => ${fnName}(props ?? {});\n});\nexport default ${wrapperVar};\n`;\n\n updated = `${updated}${wrapperSnippet}`;\n\n return { code: updated, modified: true };\n};\n\nconst findDefaultMdxExportIndex = (source: string): number => {\n const target = 'export default function MDXContent';\n const length = source.length;\n let i = 0;\n let state:\n | 'code'\n | 'single'\n | 'double'\n | 'template'\n | 'lineComment'\n | 'blockComment' = 'code';\n let templateDepth = 0;\n\n while (i < length) {\n const ch = source[i];\n const next = source[i + 1];\n\n switch (state) {\n case 'code':\n if (ch === '/') {\n if (next === '/') {\n state = 'lineComment';\n i += 2;\n continue;\n }\n if (next === '*') {\n state = 'blockComment';\n i += 2;\n continue;\n }\n }\n if (ch === \"'\") {\n state = 'single';\n i++;\n continue;\n }\n if (ch === '\"') {\n state = 'double';\n i++;\n continue;\n }\n if (ch === '`') {\n state = 'template';\n templateDepth = 0;\n i++;\n continue;\n }\n if (source.startsWith(target, i)) {\n return i;\n }\n i++;\n break;\n\n case 'single':\n if (ch === '\\\\') {\n i += 2;\n continue;\n }\n if (ch === \"'\") {\n state = 'code';\n }\n i++;\n break;\n\n case 'double':\n if (ch === '\\\\') {\n i += 2;\n continue;\n }\n if (ch === '\"') {\n state = 'code';\n }\n i++;\n break;\n\n case 'template':\n if (ch === '\\\\') {\n i += 2;\n continue;\n }\n if (ch === '`') {\n if (templateDepth === 0) {\n state = 'code';\n i++;\n break;\n }\n templateDepth--;\n i++;\n break;\n }\n if (ch === '$' && next === '{') {\n templateDepth++;\n i += 2;\n break;\n }\n if (ch === '}') {\n if (templateDepth > 0) {\n templateDepth--;\n }\n i++;\n break;\n }\n i++;\n break;\n\n case 'lineComment':\n if (ch === '\\n') {\n state = 'code';\n }\n i++;\n break;\n\n case 'blockComment':\n if (ch === '*' && next === '/') {\n state = 'code';\n i += 2;\n break;\n }\n i++;\n break;\n }\n }\n\n return -1;\n};\n\nconst wrapMdxExports = (code: string): string => {\n const ensureNamedExport = (source: string, fnName: string): string =>\n source.replace(\n new RegExp(`^(\\\\s*)(?:export\\\\s+)?function\\\\s+${fnName}`, 'gm'),\n (match, leading) => {\n if (match.trimStart().startsWith('export ')) {\n return match;\n }\n return `${leading}export function ${fnName}`;\n }\n );\n\n const ensureDefaultExport = (source: string, fnName: string): string =>\n source.replace(\n new RegExp(`^(\\\\s*)(?:export\\\\s+)?function\\\\s+${fnName}`, 'gm'),\n (match, leading) => {\n if (match.trimStart().startsWith('export default')) {\n return match;\n }\n return `${leading}export default function ${fnName}`;\n }\n );\n\n const withNamed = ensureNamedExport(code, '_createMdxContent');\n const withDefault = ensureDefaultExport(withNamed, 'MDXContent');\n return withDefault;\n};\n\nconst insertImportString = (source: string, statement: string): string => {\n const insertPos = findImportInsertionIndex(source);\n\n if (insertPos >= 0) {\n const needsLeadingNewline =\n insertPos > 0 && source[insertPos - 1] !== '\\n';\n const snippet = needsLeadingNewline ? `\\n${statement}` : statement;\n return `${source.slice(0, insertPos)}${snippet}${source.slice(insertPos)}`;\n }\n\n return `${statement}${source}`;\n};\n\ntype ScannerState =\n | 'code'\n | 'single'\n | 'double'\n | 'template'\n | 'lineComment'\n | 'blockComment';\n\ninterface ImportStatement {\n start: number;\n end: number;\n code: string;\n}\n\nconst getImportStatements = (source: string): ImportStatement[] => {\n const statements: ImportStatement[] = [];\n let i = 0;\n let state: ScannerState = 'code';\n let templateDepth = 0;\n\n while (i < source.length) {\n const ch = source[i];\n const next = source[i + 1];\n\n switch (state) {\n case 'code': {\n if (ch === '/' && next === '/') {\n state = 'lineComment';\n i += 2;\n continue;\n }\n if (ch === '/' && next === '*') {\n state = 'blockComment';\n i += 2;\n continue;\n }\n if (ch === \"'\") {\n state = 'single';\n i++;\n continue;\n }\n if (ch === '\"') {\n state = 'double';\n i++;\n continue;\n }\n if (ch === '`') {\n state = 'template';\n templateDepth = 0;\n i++;\n continue;\n }\n if (i === 0 && ch === '#' && next === '!') {\n state = 'lineComment';\n i += 2;\n continue;\n }\n if (\n ch === 'i' &&\n isImportKeyword(source, i) &&\n !isDynamicImport(source, i)\n ) {\n const end = findImportStatementEnd(source, i);\n statements.push({\n start: i,\n end,\n code: source.slice(i, end),\n });\n i = end;\n continue;\n }\n i++;\n break;\n }\n\n case 'single':\n if (ch === '\\\\') {\n i += 2;\n continue;\n }\n if (ch === \"'\") {\n state = 'code';\n }\n i++;\n break;\n\n case 'double':\n if (ch === '\\\\') {\n i += 2;\n continue;\n }\n if (ch === '\"') {\n state = 'code';\n }\n i++;\n break;\n\n case 'template':\n if (ch === '\\\\') {\n i += 2;\n continue;\n }\n if (ch === '`') {\n if (templateDepth === 0) {\n state = 'code';\n i++;\n continue;\n }\n templateDepth--;\n i++;\n continue;\n }\n if (ch === '$' && next === '{') {\n templateDepth++;\n i += 2;\n continue;\n }\n if (ch === '}' && templateDepth > 0) {\n templateDepth--;\n }\n i++;\n break;\n\n case 'lineComment':\n if (ch === '\\n') {\n state = 'code';\n }\n i++;\n break;\n\n case 'blockComment':\n if (ch === '*' && next === '/') {\n state = 'code';\n i += 2;\n continue;\n }\n i++;\n break;\n }\n }\n\n return statements;\n};\n\nconst findImportInsertionIndex = (source: string): number => {\n const statements = getImportStatements(source);\n\n if (!statements.length) {\n return -1;\n }\n\n return statements[statements.length - 1].end;\n};\n\nconst hasNamedImportFrom = (\n source: string,\n specifier: string,\n name: string\n): boolean => {\n const statements = getImportStatements(source);\n const fromPattern = new RegExp(\n `from\\\\s+['\"]${escapeRegExp(specifier)}['\"]`\n );\n const namePattern = new RegExp(`\\\\b${escapeRegExp(name)}\\\\b`);\n\n return statements.some(statement => {\n if (!fromPattern.test(statement.code)) {\n return false;\n }\n\n const [clause] = statement.code.split(/from\\s+/i);\n return namePattern.test(clause);\n });\n};\n\nconst escapeRegExp = (value: string): string =>\n value.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\n\n\nconst isImportKeyword = (source: string, index: number): boolean => {\n if (!source.startsWith('import', index)) {\n return false;\n }\n\n const prev = source[index - 1];\n if (prev && isIdentifierChar(prev)) {\n return false;\n }\n\n const next = source[index + 'import'.length];\n if (next && isIdentifierChar(next)) {\n return false;\n }\n\n return true;\n};\n\nconst isIdentifierChar = (ch: string): boolean => /[A-Za-z0-9_$]/.test(ch);\n\nconst isDynamicImport = (source: string, index: number): boolean => {\n const nextChar = source[index + 'import'.length];\n if (!nextChar) {\n return true;\n }\n if (nextChar === '(' || nextChar === '.') {\n return true;\n }\n return false;\n};\n\nconst findImportStatementEnd = (source: string, start: number): number => {\n let i = start;\n let state: ScannerState = 'code';\n\n while (i < source.length) {\n const ch = source[i];\n const next = source[i + 1];\n\n switch (state) {\n case 'code':\n if (ch === ';') {\n return i + 1;\n }\n if (ch === '/' && next === '/') {\n state = 'lineComment';\n i += 2;\n continue;\n }\n if (ch === '/' && next === '*') {\n state = 'blockComment';\n i += 2;\n continue;\n }\n if (ch === \"'\") {\n state = 'single';\n i++;\n continue;\n }\n if (ch === '\"') {\n state = 'double';\n i++;\n continue;\n }\n if (ch === '`') {\n state = 'template';\n i++;\n continue;\n }\n i++;\n break;\n\n case 'single':\n if (ch === '\\\\') {\n i += 2;\n continue;\n }\n if (ch === \"'\") {\n state = 'code';\n }\n i++;\n break;\n\n case 'double':\n if (ch === '\\\\') {\n i += 2;\n continue;\n }\n if (ch === '\"') {\n state = 'code';\n }\n i++;\n break;\n\n case 'template':\n if (ch === '\\\\') {\n i += 2;\n continue;\n }\n if (ch === '`') {\n state = 'code';\n }\n i++;\n break;\n\n case 'lineComment':\n if (ch === '\\n') {\n state = 'code';\n }\n i++;\n break;\n\n case 'blockComment':\n if (ch === '*' && next === '/') {\n state = 'code';\n i += 2;\n continue;\n }\n i++;\n break;\n }\n }\n\n return source.length;\n};\n","import type { Plugin, PluginOption } from 'vite';\nimport mdxRollup from '@mdx-js/rollup';\nimport { wrapMdxModule } from './transform';\n\nexport interface LithentMdxPluginOptions {\n /**\n * MDX plugin options to pass to @mdx-js/rollup\n */\n mdxOptions?: Record<string, unknown>;\n\n /**\n * JSX import source for MDX files\n * @default 'lithent'\n */\n jsxImportSource?: string;\n}\n\nexport const lithentMdx = (\n options: LithentMdxPluginOptions = {}\n): PluginOption => {\n const jsxImportSource = options.jsxImportSource ?? 'lithent';\n\n // Create the MDX rollup plugin with Lithent-specific JSX settings\n const mdxPlugin = mdxRollup({\n jsxImportSource,\n ...options.mdxOptions,\n });\n\n // Create the wrapper plugin that adds mount() wrapping\n const wrapperPlugin: Plugin = {\n name: 'lithent:mdx-wrapper',\n enforce: undefined, // normal - runs after mdxPlugin in array order\n\n transform(code, id) {\n const [filepath] = id.split('?', 1);\n\n // Only process .mdx files\n if (!/\\.mdx$/i.test(filepath)) {\n return null;\n }\n\n // Wrap MDXContent with mount() and add export default\n const result = wrapMdxModule(code);\n\n if (!result.modified) {\n return null;\n }\n\n return {\n code: result.code,\n map: null,\n };\n },\n };\n\n // Return both plugins as an array\n // Order matters: mdxPlugin first (MDX → JSX), then wrapperPlugin (add mount())\n return [mdxPlugin, wrapperPlugin];\n};\n\nexport default lithentMdx;\n"],"names":["MDX_WRAP_SENTINEL","wrapMdxModule","code","fixedExports","wrapMdxExports","exportsModified","defaultExportIndex","findDefaultMdxExportIndex","fnName","start","end","updated","hasNamedImportFrom","insertImportString","wrapperVar","wrapperSnippet","source","target","length","i","state","templateDepth","ch","next","ensureNamedExport","match","leading","ensureDefaultExport","withNamed","statement","insertPos","findImportInsertionIndex","snippet","getImportStatements","statements","isImportKeyword","isDynamicImport","findImportStatementEnd","specifier","name","fromPattern","escapeRegExp","namePattern","clause","value","index","prev","isIdentifierChar","nextChar","lithentMdx","options","jsxImportSource","mdxRollup","id","filepath","result"],"mappings":"yUAKaA,EAAoB,4BAEpBC,EAAiBC,GAAgC,CACtD,MAAAC,EAAeC,EAAeF,CAAI,EAClCG,EAAkBF,IAAiBD,EAErC,GAAAC,EAAa,SAASH,CAAiB,EACzC,MAAO,CAAE,KAAMG,EAAc,SAAUE,CAAgB,EAGnD,MAAAC,EAAqBC,EAA0BJ,CAAY,EAEjE,GAAIG,EAAqB,EACvB,MAAO,CAAE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ACL,QACF,CACAA,IACA,KACJ,CACF,CAEA,OAAOH,EAAO,MAChB,ECrfaiC,EAAa,CACxBC,EAAmC,KAClB,CACX,MAAAC,EAAkBD,EAAQ,iBAAmB,UAqC5C,MAAA,CAlCWE,EAAAA,QAAU,CAC1B,gBAAAD,EACA,GAAGD,EAAQ,UAAA,CACZ,EAG6B,CAC5B,KAAM,sBACN,QAAS,OAET,UAAUhD,EAAMmD,EAAI,CAClB,KAAM,CAACC,CAAQ,EAAID,EAAG,MAAM,IAAK,CAAC,EAGlC,GAAI,CAAC,UAAU,KAAKC,CAAQ,EACnB,OAAA,KAIH,MAAAC,EAAStD,EAAcC,CAAI,EAE7B,OAACqD,EAAO,SAIL,CACL,KAAMA,EAAO,KACb,IAAK,IAAA,EALE,IAOX,CAAA,CAK8B,CAClC"}
@@ -0,0 +1,14 @@
1
+ import type { PluginOption } from 'vite' with { "resolution-mode": "import" };
2
+ export interface LithentMdxPluginOptions {
3
+ /**
4
+ * MDX plugin options to pass to @mdx-js/rollup
5
+ */
6
+ mdxOptions?: Record<string, unknown>;
7
+ /**
8
+ * JSX import source for MDX files
9
+ * @default 'lithent'
10
+ */
11
+ jsxImportSource?: string;
12
+ }
13
+ export declare const lithentMdx: (options?: LithentMdxPluginOptions) => PluginOption;
14
+ export default lithentMdx;
@@ -0,0 +1,6 @@
1
+ export interface MdxWrapResult {
2
+ code: string;
3
+ modified: boolean;
4
+ }
5
+ export declare const MDX_WRAP_SENTINEL = "/* __lithentMdxWrapped */";
6
+ export declare const wrapMdxModule: (code: string) => MdxWrapResult;
package/package.json CHANGED
@@ -1,25 +1,30 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@lithent/lithent-mdx",
4
- "version": "0.2.6",
4
+ "version": "0.2.7",
5
5
  "description": "Vite plugin for MDX support in Lithent applications",
6
- "main": "./dist/index.mjs",
6
+ "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.mjs",
8
8
  "types": "./dist/index.d.ts",
9
9
  "exports": {
10
10
  ".": {
11
- "types": "./dist/index.d.ts",
12
- "import": "./dist/index.mjs",
13
- "require": "./dist/index.umd.js"
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.mjs"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
14
19
  }
15
20
  },
16
21
  "dependencies": {
17
22
  "@mdx-js/rollup": "^3.1.0"
18
23
  },
19
24
  "devDependencies": {
20
- "vite": "^5.4.8",
21
- "@lithent/hmr-parser": "0.2.2",
22
- "lithent": "1.21.0"
25
+ "@lithent/hmr-parser": "0.2.4",
26
+ "lithent": "1.25.6",
27
+ "vite": "^5.4.8"
23
28
  },
24
29
  "keywords": [
25
30
  "lithent",
@@ -34,16 +39,13 @@
34
39
  "url": "https://github.com/superlucky84/lithent.git"
35
40
  },
36
41
  "peerDependencies": {
37
- "lithent": "^1.21.0",
42
+ "lithent": "^1.21.3",
38
43
  "vite": "^5.0.0"
39
44
  },
40
45
  "files": [
41
46
  "dist",
42
47
  "src"
43
48
  ],
44
- "volta": {
45
- "node": "20.3.0"
46
- },
47
49
  "scripts": {
48
50
  "dev": "vite --config vite.config.dev.ts",
49
51
  "build": "vite build",