@vxrn/mdx 1.2.54 → 1.2.56
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.js +63 -33
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +63 -33
- package/package.json +6 -2
- package/src/getMDX.ts +29 -3
- package/src/index.ts +2 -2
- package/src/processImageMeta.ts +55 -0
- package/src/types.ts +8 -0
- package/types/getMDX.d.ts +6 -1
- package/types/getMDX.d.ts.map +1 -1
- package/types/index.d.ts +2 -2
- package/types/index.d.ts.map +1 -1
- package/types/processImageMeta.d.ts +9 -0
- package/types/processImageMeta.d.ts.map +1 -0
- package/types/types.d.ts +7 -0
- package/types/types.d.ts.map +1 -1
package/dist/index.js
CHANGED
|
@@ -2794,38 +2794,38 @@ var require_queue = __commonJS({
|
|
|
2794
2794
|
var queue = fastqueue(context, asyncWrapper, _concurrency), pushCb = queue.push, unshiftCb = queue.unshift;
|
|
2795
2795
|
return queue.push = push, queue.unshift = unshift, queue.drained = drained, queue;
|
|
2796
2796
|
function push(value) {
|
|
2797
|
-
var p2 = new Promise(function(
|
|
2797
|
+
var p2 = new Promise(function(resolve2, reject) {
|
|
2798
2798
|
pushCb(value, function(err, result) {
|
|
2799
2799
|
if (err) {
|
|
2800
2800
|
reject(err);
|
|
2801
2801
|
return;
|
|
2802
2802
|
}
|
|
2803
|
-
|
|
2803
|
+
resolve2(result);
|
|
2804
2804
|
});
|
|
2805
2805
|
});
|
|
2806
2806
|
return p2.catch(noop), p2;
|
|
2807
2807
|
}
|
|
2808
2808
|
function unshift(value) {
|
|
2809
|
-
var p2 = new Promise(function(
|
|
2809
|
+
var p2 = new Promise(function(resolve2, reject) {
|
|
2810
2810
|
unshiftCb(value, function(err, result) {
|
|
2811
2811
|
if (err) {
|
|
2812
2812
|
reject(err);
|
|
2813
2813
|
return;
|
|
2814
2814
|
}
|
|
2815
|
-
|
|
2815
|
+
resolve2(result);
|
|
2816
2816
|
});
|
|
2817
2817
|
});
|
|
2818
2818
|
return p2.catch(noop), p2;
|
|
2819
2819
|
}
|
|
2820
2820
|
function drained() {
|
|
2821
|
-
var p2 = new Promise(function(
|
|
2821
|
+
var p2 = new Promise(function(resolve2) {
|
|
2822
2822
|
process.nextTick(function() {
|
|
2823
2823
|
if (queue.idle())
|
|
2824
|
-
|
|
2824
|
+
resolve2();
|
|
2825
2825
|
else {
|
|
2826
2826
|
var previousDrain = queue.drain;
|
|
2827
2827
|
queue.drain = function() {
|
|
2828
|
-
typeof previousDrain == "function" && previousDrain(),
|
|
2828
|
+
typeof previousDrain == "function" && previousDrain(), resolve2(), queue.drain = previousDrain;
|
|
2829
2829
|
};
|
|
2830
2830
|
}
|
|
2831
2831
|
});
|
|
@@ -3180,8 +3180,8 @@ var require_stream3 = __commonJS({
|
|
|
3180
3180
|
});
|
|
3181
3181
|
}
|
|
3182
3182
|
_getStat(filepath) {
|
|
3183
|
-
return new Promise((
|
|
3184
|
-
this._stat(filepath, this._fsStatSettings, (error, stats) => error === null ?
|
|
3183
|
+
return new Promise((resolve2, reject) => {
|
|
3184
|
+
this._stat(filepath, this._fsStatSettings, (error, stats) => error === null ? resolve2(stats) : reject(error));
|
|
3185
3185
|
});
|
|
3186
3186
|
}
|
|
3187
3187
|
};
|
|
@@ -3199,16 +3199,16 @@ var require_async5 = __commonJS({
|
|
|
3199
3199
|
super(...arguments), this._walkAsync = fsWalk.walk, this._readerStream = new stream_1.default(this._settings);
|
|
3200
3200
|
}
|
|
3201
3201
|
dynamic(root3, options2) {
|
|
3202
|
-
return new Promise((
|
|
3202
|
+
return new Promise((resolve2, reject) => {
|
|
3203
3203
|
this._walkAsync(root3, options2, (error, entries) => {
|
|
3204
|
-
error === null ?
|
|
3204
|
+
error === null ? resolve2(entries) : reject(error);
|
|
3205
3205
|
});
|
|
3206
3206
|
});
|
|
3207
3207
|
}
|
|
3208
3208
|
async static(patterns, options2) {
|
|
3209
3209
|
let entries = [], stream = this._readerStream.static(patterns, options2);
|
|
3210
|
-
return new Promise((
|
|
3211
|
-
stream.once("error", reject), stream.on("data", (entry) => entries.push(entry)), stream.once("end", () =>
|
|
3210
|
+
return new Promise((resolve2, reject) => {
|
|
3211
|
+
stream.once("error", reject), stream.on("data", (entry) => entries.push(entry)), stream.once("end", () => resolve2(entries));
|
|
3212
3212
|
});
|
|
3213
3213
|
}
|
|
3214
3214
|
};
|
|
@@ -14084,8 +14084,8 @@ function previousUnbalanced(events) {
|
|
|
14084
14084
|
function resolveAll(constructs2, events, context) {
|
|
14085
14085
|
let called = [], index2 = -1;
|
|
14086
14086
|
for (; ++index2 < constructs2.length; ) {
|
|
14087
|
-
let
|
|
14088
|
-
|
|
14087
|
+
let resolve2 = constructs2[index2].resolveAll;
|
|
14088
|
+
resolve2 && !called.includes(resolve2) && (events = resolve2(events, context), called.push(resolve2));
|
|
14089
14089
|
}
|
|
14090
14090
|
return events;
|
|
14091
14091
|
}
|
|
@@ -14651,6 +14651,31 @@ function remarkGfm(options2) {
|
|
|
14651
14651
|
micromarkExtensions.push(gfm(settings)), fromMarkdownExtensions.push(gfmFromMarkdown()), toMarkdownExtensions.push(gfmToMarkdown(settings));
|
|
14652
14652
|
}
|
|
14653
14653
|
|
|
14654
|
+
// src/processImageMeta.ts
|
|
14655
|
+
var import_node_fs2 = require("node:fs"), import_node_path2 = require("node:path");
|
|
14656
|
+
async function getSharp() {
|
|
14657
|
+
try {
|
|
14658
|
+
let sharpModule = await import("sharp");
|
|
14659
|
+
return sharpModule.default || sharpModule;
|
|
14660
|
+
} catch {
|
|
14661
|
+
return null;
|
|
14662
|
+
}
|
|
14663
|
+
}
|
|
14664
|
+
async function processImageMeta(imagePath, opts) {
|
|
14665
|
+
let publicDir = opts?.publicDir ?? "./public", filePath;
|
|
14666
|
+
if (imagePath.startsWith("/") ? filePath = (0, import_node_path2.resolve)(publicDir, imagePath.slice(1)) : filePath = (0, import_node_path2.resolve)(imagePath), !(0, import_node_fs2.existsSync)(filePath))
|
|
14667
|
+
return null;
|
|
14668
|
+
let sharp = await getSharp();
|
|
14669
|
+
if (!sharp)
|
|
14670
|
+
return null;
|
|
14671
|
+
try {
|
|
14672
|
+
let image2 = sharp(filePath), metadata = await image2.metadata(), { width = 0, height = 0 } = metadata, blurDataURL = `data:image/jpeg;base64,${(await image2.resize(10).blur().jpeg({ quality: 40 }).toBuffer()).toString("base64")}`;
|
|
14673
|
+
return { width, height, blurDataURL };
|
|
14674
|
+
} catch {
|
|
14675
|
+
return null;
|
|
14676
|
+
}
|
|
14677
|
+
}
|
|
14678
|
+
|
|
14654
14679
|
// src/rehypeHighlightCode.tsx
|
|
14655
14680
|
var import_parse_numeric_range = __toESM(require_parse_numeric_range());
|
|
14656
14681
|
|
|
@@ -22172,10 +22197,10 @@ function base2() {
|
|
|
22172
22197
|
if (assertNode(node2), processor.freeze(), !callback && typeof doc == "function" && (callback = doc, doc = void 0), !callback)
|
|
22173
22198
|
return new Promise(executor);
|
|
22174
22199
|
executor(null, callback);
|
|
22175
|
-
function executor(
|
|
22200
|
+
function executor(resolve2, reject) {
|
|
22176
22201
|
transformers.run(node2, vfile(doc), done);
|
|
22177
22202
|
function done(error, tree, file) {
|
|
22178
|
-
tree = tree || node2, error ? reject(error) :
|
|
22203
|
+
tree = tree || node2, error ? reject(error) : resolve2 ? resolve2(tree) : callback(null, tree, file);
|
|
22179
22204
|
}
|
|
22180
22205
|
}
|
|
22181
22206
|
}
|
|
@@ -22190,7 +22215,7 @@ function base2() {
|
|
|
22190
22215
|
if (processor.freeze(), assertParser("process", processor.Parser), assertCompiler("process", processor.Compiler), !callback)
|
|
22191
22216
|
return new Promise(executor);
|
|
22192
22217
|
executor(null, callback);
|
|
22193
|
-
function executor(
|
|
22218
|
+
function executor(resolve2, reject) {
|
|
22194
22219
|
let file = vfile(doc);
|
|
22195
22220
|
processor.run(processor.parse(file), file, (error, tree, file2) => {
|
|
22196
22221
|
if (error || !tree || !file2)
|
|
@@ -22201,7 +22226,7 @@ function base2() {
|
|
|
22201
22226
|
}
|
|
22202
22227
|
});
|
|
22203
22228
|
function done(error, file2) {
|
|
22204
|
-
error || !file2 ? reject(error) :
|
|
22229
|
+
error || !file2 ? reject(error) : resolve2 ? resolve2(file2) : callback(null, file2);
|
|
22205
22230
|
}
|
|
22206
22231
|
}
|
|
22207
22232
|
}
|
|
@@ -22374,13 +22399,13 @@ var import_unist_util_visit5 = __toESM(require_unist_util_visit()), re = /\b([-\
|
|
|
22374
22399
|
};
|
|
22375
22400
|
|
|
22376
22401
|
// src/getMDX.ts
|
|
22377
|
-
async function getMDX(source,
|
|
22378
|
-
let { frontmatter, code: code3 } = await (0, import_mdx_bundler.bundleMDX)({
|
|
22402
|
+
async function getMDX(source, extraPluginsOrOptions) {
|
|
22403
|
+
let opts = Array.isArray(extraPluginsOrOptions) ? { extraPlugins: extraPluginsOrOptions } : extraPluginsOrOptions ?? {}, { frontmatter, code: code3 } = await (0, import_mdx_bundler.bundleMDX)({
|
|
22379
22404
|
source,
|
|
22380
22405
|
mdxOptions(options2) {
|
|
22381
22406
|
options2.remarkPlugins = [...options2.remarkPlugins ?? [], remarkGfm];
|
|
22382
22407
|
let plugins = [
|
|
22383
|
-
...extraPlugins || [],
|
|
22408
|
+
...opts.extraPlugins || [],
|
|
22384
22409
|
...options2.rehypePlugins ?? [],
|
|
22385
22410
|
rehypeMetaAttribute_default,
|
|
22386
22411
|
rehypeHighlightCode,
|
|
@@ -22389,32 +22414,37 @@ async function getMDX(source, extraPlugins) {
|
|
|
22389
22414
|
];
|
|
22390
22415
|
return options2.rehypePlugins = plugins, options2;
|
|
22391
22416
|
}
|
|
22392
|
-
});
|
|
22417
|
+
}), imageMeta;
|
|
22418
|
+
if (frontmatter.image && typeof frontmatter.image == "string") {
|
|
22419
|
+
let meta = await processImageMeta(frontmatter.image, { publicDir: opts.publicDir });
|
|
22420
|
+
meta && (imageMeta = meta);
|
|
22421
|
+
}
|
|
22393
22422
|
return {
|
|
22394
22423
|
frontmatter: {
|
|
22395
22424
|
...frontmatter,
|
|
22396
22425
|
headings: getHeadings(source),
|
|
22397
|
-
readingTime: (0, import_reading_time2.default)(code3)
|
|
22426
|
+
readingTime: (0, import_reading_time2.default)(code3),
|
|
22427
|
+
imageMeta
|
|
22398
22428
|
},
|
|
22399
22429
|
code: code3
|
|
22400
22430
|
};
|
|
22401
22431
|
}
|
|
22402
22432
|
|
|
22403
22433
|
// src/getMDXBySlug.tsx
|
|
22404
|
-
var
|
|
22434
|
+
var import_node_fs3 = __toESM(require("node:fs")), import_node_path3 = __toESM(require("node:path")), import_compare_versions = __toESM(require_compare_versions());
|
|
22405
22435
|
var getMDXBySlug = async (basePath, slug2, extraPlugins) => {
|
|
22406
22436
|
let mdxPath = slug2;
|
|
22407
22437
|
if (!slug2.includes(".") && basePath.includes("components")) {
|
|
22408
|
-
let versions = getAllVersionsFromPath(
|
|
22438
|
+
let versions = getAllVersionsFromPath(import_node_path3.default.join(basePath, slug2));
|
|
22409
22439
|
mdxPath += `/${versions[0]}`;
|
|
22410
22440
|
}
|
|
22411
|
-
let filePath =
|
|
22441
|
+
let filePath = import_node_path3.default.join(basePath, `${mdxPath}.mdx`);
|
|
22412
22442
|
notifyFileRead(filePath);
|
|
22413
|
-
let source =
|
|
22443
|
+
let source = import_node_fs3.default.readFileSync(filePath, "utf8");
|
|
22414
22444
|
return await getMDX(source, extraPlugins);
|
|
22415
22445
|
};
|
|
22416
22446
|
function getAllVersionsFromPath(fromPath) {
|
|
22417
|
-
return
|
|
22447
|
+
return import_node_fs3.default.existsSync(fromPath) ? import_node_fs3.default.readdirSync(fromPath).map((fileName) => fileName.replace(".mdx", "")).sort(import_compare_versions.default).reverse() : [];
|
|
22418
22448
|
}
|
|
22419
22449
|
|
|
22420
22450
|
// src/highlightCode.tsx
|
|
@@ -22428,13 +22458,13 @@ function createCodeHighlighter() {
|
|
|
22428
22458
|
}
|
|
22429
22459
|
|
|
22430
22460
|
// src/rehypeHeroTemplate.ts
|
|
22431
|
-
var import_node_module = require("node:module"),
|
|
22461
|
+
var import_node_module = require("node:module"), import_node_fs4 = __toESM(require("node:fs")), import_node_path4 = __toESM(require("node:path")), import_unist_util_visit6 = __toESM(require_unist_util_visit()), import_meta = {}, rehypeHeroTemplate = (options2 = {}) => {
|
|
22432
22462
|
let demosRoot;
|
|
22433
22463
|
if (options2.demosPath)
|
|
22434
22464
|
demosRoot = options2.demosPath;
|
|
22435
22465
|
else if (options2.demosPackage) {
|
|
22436
22466
|
let resolved = (typeof require > "u" ? (0, import_node_module.createRequire)(import_meta.url) : require).resolve(options2.demosPackage);
|
|
22437
|
-
demosRoot =
|
|
22467
|
+
demosRoot = import_node_path4.default.join(resolved, "..", "..", "..");
|
|
22438
22468
|
} else
|
|
22439
22469
|
throw new Error("rehypeHeroTemplate requires either demosPackage or demosPath option");
|
|
22440
22470
|
return (tree) => {
|
|
@@ -22442,9 +22472,9 @@ var import_node_module = require("node:module"), import_node_fs3 = __toESM(requi
|
|
|
22442
22472
|
if (node2.tagName !== "code" || !node2.properties.template) return;
|
|
22443
22473
|
let templateName = node2.properties.template;
|
|
22444
22474
|
if (!templateName) return;
|
|
22445
|
-
let templatePath =
|
|
22475
|
+
let templatePath = import_node_path4.default.join(demosRoot, "src", `${templateName}Demo.tsx`);
|
|
22446
22476
|
try {
|
|
22447
|
-
let source =
|
|
22477
|
+
let source = import_node_fs4.default.readFileSync(templatePath, "utf8");
|
|
22448
22478
|
node2.children[0].value = source;
|
|
22449
22479
|
} catch (err) {
|
|
22450
22480
|
console.warn("Error setting template", err.message);
|