@ox-content/vite-plugin 3.0.0-alpha.11 → 3.0.0-alpha.12
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 +99 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +55 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +55 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +99 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1438,6 +1438,37 @@ async function transformYouTube(html, options) {
|
|
|
1438
1438
|
return (await require_vitepress.importNapiModule()).transformYoutubeEmbeds(html, options);
|
|
1439
1439
|
}
|
|
1440
1440
|
//#endregion
|
|
1441
|
+
//#region src/plugins/media-marker.ts
|
|
1442
|
+
/**
|
|
1443
|
+
* True when the document contains any tag the transform could rewrite.
|
|
1444
|
+
*
|
|
1445
|
+
* The list comes from the Rust registry rather than a copy kept here. The copy
|
|
1446
|
+
* had already drifted: `codesandbox` was missing, so a page whose only embed
|
|
1447
|
+
* was a `<CodeSandbox>` skipped the transform entirely and shipped the raw tag.
|
|
1448
|
+
*/
|
|
1449
|
+
async function hasMediaMarker(html) {
|
|
1450
|
+
return (await markerPattern()).test(html);
|
|
1451
|
+
}
|
|
1452
|
+
/**
|
|
1453
|
+
* Providers that live in this package rather than the Rust registry, so the
|
|
1454
|
+
* registry cannot name them. Reddit is fetched here, not rendered there.
|
|
1455
|
+
*/
|
|
1456
|
+
const TYPESCRIPT_ONLY_TAGS = ["reddit"];
|
|
1457
|
+
let cachedPattern;
|
|
1458
|
+
async function markerPattern() {
|
|
1459
|
+
if (cachedPattern) return cachedPattern;
|
|
1460
|
+
const tags = (await require_vitepress.importNapiModule()).mediaEmbedTags();
|
|
1461
|
+
const anyCase = [...tags.filter((tag) => !tag.pascalOnly).map((tag) => tag.name), ...TYPESCRIPT_ONLY_TAGS];
|
|
1462
|
+
const pascalOnly = tags.filter((tag) => tag.pascalOnly).map((tag) => tag.name);
|
|
1463
|
+
const parts = [`(?:<(?:${anyCase.join("|")})[\\s/>])`];
|
|
1464
|
+
if (pascalOnly.length > 0) parts.push(`(?:<(?:${pascalOnly.map(capitalize).join("|")})[\\s/>])`);
|
|
1465
|
+
cachedPattern = new RegExp(parts.join("|"), "i");
|
|
1466
|
+
return cachedPattern;
|
|
1467
|
+
}
|
|
1468
|
+
function capitalize(value) {
|
|
1469
|
+
return value.charAt(0).toUpperCase() + value.slice(1);
|
|
1470
|
+
}
|
|
1471
|
+
//#endregion
|
|
1441
1472
|
//#region src/plugins/provider-failure.ts
|
|
1442
1473
|
/** Node's fetch reports a missing network through `cause.code`. */
|
|
1443
1474
|
const OFFLINE_CODES = /* @__PURE__ */ new Set([
|
|
@@ -4015,7 +4046,7 @@ async function transformFetchedTweets(html, options) {
|
|
|
4015
4046
|
//#endregion
|
|
4016
4047
|
//#region src/plugins/media.ts
|
|
4017
4048
|
async function transformMediaEmbeds(html, options) {
|
|
4018
|
-
if (!hasEnabledMediaEmbed(options) || !hasMediaMarker(html)) return html;
|
|
4049
|
+
if (!hasEnabledMediaEmbed(options) || !await hasMediaMarker(html)) return html;
|
|
4019
4050
|
let result = html;
|
|
4020
4051
|
if (typeof options.twitter === "object") result = await transformFetchedTweets(result, options.twitter);
|
|
4021
4052
|
if (options.reddit) result = await transformRedditEmbeds(result, typeof options.reddit === "object" ? options.reddit : {});
|
|
@@ -4052,16 +4083,18 @@ async function transformMediaEmbeds(html, options) {
|
|
|
4052
4083
|
facebook: options.facebook,
|
|
4053
4084
|
threads: options.threads,
|
|
4054
4085
|
instagram: options.instagram,
|
|
4055
|
-
webContainer: options.webContainer
|
|
4086
|
+
webContainer: options.webContainer,
|
|
4087
|
+
loom: options.loom,
|
|
4088
|
+
asciinema: options.asciinema,
|
|
4089
|
+
figma: options.figma,
|
|
4090
|
+
note: options.note,
|
|
4091
|
+
googleSlides: options.googleSlides
|
|
4056
4092
|
});
|
|
4057
4093
|
reportRefusedEmbeds(transformed.diagnostics);
|
|
4058
4094
|
return transformed.html;
|
|
4059
4095
|
}
|
|
4060
4096
|
function hasEnabledMediaEmbed(options) {
|
|
4061
|
-
return Boolean(options.spotify || options.appleMusic || options.speakerDeck || options.audio || options.video || options.stackBlitz || options.twitter || options.reddit || options.bluesky || options.googleMaps || options.qiita || options.zenn || options.packageRegistry || options.playgrounds || options.vimeo || options.twitch || options.discord || options.fediverse || options.facebook || options.threads || options.instagram || options.webContainer);
|
|
4062
|
-
}
|
|
4063
|
-
function hasMediaMarker(html) {
|
|
4064
|
-
return /<(spotify|applemusic|speakerdeck|stackblitz|tweet|xpost|reddit|bluesky|googlemaps|qiita|zenn|npmpackage|cratesio|pypi|dockerhub|codepen|jsfiddle|observable|vimeo|twitch|discord|fediverse|mastodon|misskey|mixi2|facebook|threads|instagram|webcontainer)[\s/>]/i.test(html) || /<(Audio|Video)[\s/>]/.test(html);
|
|
4097
|
+
return Boolean(options.spotify || options.appleMusic || options.speakerDeck || options.audio || options.video || options.stackBlitz || options.twitter || options.reddit || options.bluesky || options.googleMaps || options.qiita || options.zenn || options.packageRegistry || options.playgrounds || options.vimeo || options.twitch || options.discord || options.fediverse || options.facebook || options.threads || options.instagram || options.webContainer || options.loom || options.asciinema || options.figma || options.note || options.googleSlides);
|
|
4065
4098
|
}
|
|
4066
4099
|
/**
|
|
4067
4100
|
* Warns about tags an enabled provider refused.
|
|
@@ -5989,7 +6022,20 @@ function decodeHtmlAttr$2(value) {
|
|
|
5989
6022
|
* All plugins are designed with No-JavaScript-First principle.
|
|
5990
6023
|
* They generate static HTML at build time and require no client-side JS.
|
|
5991
6024
|
*/
|
|
5992
|
-
|
|
6025
|
+
/**
|
|
6026
|
+
* Embed tags this package owns, which the Rust provider registry cannot name.
|
|
6027
|
+
*
|
|
6028
|
+
* Everything else in the pattern comes from the registry, because a
|
|
6029
|
+
* hand-maintained copy drifts — and the drift is not cosmetic here.
|
|
6030
|
+
*/
|
|
6031
|
+
const TYPESCRIPT_ONLY_EMBED_TAGS = [
|
|
6032
|
+
"GitHub",
|
|
6033
|
+
"OgCard",
|
|
6034
|
+
"Reddit",
|
|
6035
|
+
"YouTube",
|
|
6036
|
+
"NotByAI"
|
|
6037
|
+
];
|
|
6038
|
+
let selfClosingPattern;
|
|
5993
6039
|
/**
|
|
5994
6040
|
* Custom embed tags are not HTML void elements, so a self-closing authoring
|
|
5995
6041
|
* form like `<GitHub ... />` reaches the HTML re-parsers (syntax highlighting,
|
|
@@ -5997,12 +6043,23 @@ const SELF_CLOSING_EMBED_TAG = /<(GitHub|OgCard|Tweet|XPost|Reddit|Bluesky|Googl
|
|
|
5997
6043
|
* document. Normalize to an explicit open/close pair before any rehype pass
|
|
5998
6044
|
* runs. A leftover `</Tweet>` after `/>` (CommonMark HTML + self-close) is
|
|
5999
6045
|
* consumed so the closer cannot survive the embed rewrite.
|
|
6046
|
+
*
|
|
6047
|
+
* The tag list is built from the provider registry rather than written out
|
|
6048
|
+
* here. It had drifted: `<CodeSandbox … />` was absent, so a page using the
|
|
6049
|
+
* self-closing form lost every element after it.
|
|
6000
6050
|
*/
|
|
6001
6051
|
function normalizeSelfClosingEmbeds(html) {
|
|
6002
|
-
return html.replace(
|
|
6052
|
+
return html.replace(selfClosingEmbedPattern(), (_match, tag, attrs) => {
|
|
6003
6053
|
return `<${tag}${attrs}></${tag}>`;
|
|
6004
6054
|
});
|
|
6005
6055
|
}
|
|
6056
|
+
function selfClosingEmbedPattern() {
|
|
6057
|
+
if (selfClosingPattern) return selfClosingPattern;
|
|
6058
|
+
const registryTags = require_vitepress.importNapiModuleSync().mediaEmbedTags().map((tag) => tag.name);
|
|
6059
|
+
const names = [.../* @__PURE__ */ new Set([...TYPESCRIPT_ONLY_EMBED_TAGS, ...registryTags])];
|
|
6060
|
+
selfClosingPattern = new RegExp(`<(${names.join("|")})((?:[^>"']|"[^"]*"|'[^']*')*?)\\s*\\/>(?:\\s*<\\/\\1\\s*>)?`, "gi");
|
|
6061
|
+
return selfClosingPattern;
|
|
6062
|
+
}
|
|
6006
6063
|
/**
|
|
6007
6064
|
* Transform all enabled plugins in HTML content.
|
|
6008
6065
|
*/
|
|
@@ -6081,7 +6138,12 @@ async function transformBuiltinEmbeds(html, options) {
|
|
|
6081
6138
|
facebook: options.facebook,
|
|
6082
6139
|
threads: options.threads,
|
|
6083
6140
|
instagram: options.instagram,
|
|
6084
|
-
webContainer: options.webContainer
|
|
6141
|
+
webContainer: options.webContainer,
|
|
6142
|
+
loom: options.loom,
|
|
6143
|
+
asciinema: options.asciinema,
|
|
6144
|
+
figma: options.figma,
|
|
6145
|
+
note: options.note,
|
|
6146
|
+
googleSlides: options.googleSlides
|
|
6085
6147
|
};
|
|
6086
6148
|
if (Object.values(mediaOptions).some(Boolean)) result = await transformMediaEmbeds(result, mediaOptions);
|
|
6087
6149
|
return normalizeBlockEmbedParagraphs(result);
|
|
@@ -16988,6 +17050,11 @@ async function transformSsgHtml(html, options) {
|
|
|
16988
17050
|
threads: options.embeds.threads,
|
|
16989
17051
|
instagram: options.embeds.instagram,
|
|
16990
17052
|
webContainer: options.embeds.webContainer,
|
|
17053
|
+
loom: options.embeds.loom,
|
|
17054
|
+
asciinema: options.embeds.asciinema,
|
|
17055
|
+
figma: options.embeds.figma,
|
|
17056
|
+
note: options.embeds.note,
|
|
17057
|
+
googleSlides: options.embeds.googleSlides,
|
|
16991
17058
|
mermaid: true,
|
|
16992
17059
|
githubToken: process.env.GITHUB_TOKEN
|
|
16993
17060
|
});
|
|
@@ -17600,6 +17667,11 @@ async function renderPage$1(filePath, options, navGroups, siteName, base, root,
|
|
|
17600
17667
|
threads: options.embeds.threads,
|
|
17601
17668
|
instagram: options.embeds.instagram,
|
|
17602
17669
|
webContainer: options.embeds.webContainer,
|
|
17670
|
+
loom: options.embeds.loom,
|
|
17671
|
+
asciinema: options.embeds.asciinema,
|
|
17672
|
+
figma: options.embeds.figma,
|
|
17673
|
+
note: options.embeds.note,
|
|
17674
|
+
googleSlides: options.embeds.googleSlides,
|
|
17603
17675
|
mermaid: true,
|
|
17604
17676
|
githubToken: process.env.GITHUB_TOKEN
|
|
17605
17677
|
});
|
|
@@ -18224,7 +18296,12 @@ function resolveBuiltinEmbedOptions(options) {
|
|
|
18224
18296
|
facebook: false,
|
|
18225
18297
|
threads: false,
|
|
18226
18298
|
instagram: false,
|
|
18227
|
-
webContainer: false
|
|
18299
|
+
webContainer: false,
|
|
18300
|
+
loom: false,
|
|
18301
|
+
asciinema: false,
|
|
18302
|
+
figma: false,
|
|
18303
|
+
note: false,
|
|
18304
|
+
googleSlides: false
|
|
18228
18305
|
};
|
|
18229
18306
|
return {
|
|
18230
18307
|
github: resolveSingleEmbedOptions(options?.github),
|
|
@@ -18251,7 +18328,12 @@ function resolveBuiltinEmbedOptions(options) {
|
|
|
18251
18328
|
facebook: options?.facebook === true,
|
|
18252
18329
|
threads: options?.threads === true,
|
|
18253
18330
|
instagram: options?.instagram === true,
|
|
18254
|
-
webContainer: options?.webContainer === true
|
|
18331
|
+
webContainer: options?.webContainer === true,
|
|
18332
|
+
loom: options?.loom === true,
|
|
18333
|
+
asciinema: options?.asciinema === true,
|
|
18334
|
+
figma: options?.figma === true,
|
|
18335
|
+
note: options?.note === true,
|
|
18336
|
+
googleSlides: options?.googleSlides === true
|
|
18255
18337
|
};
|
|
18256
18338
|
}
|
|
18257
18339
|
function resolveSingleEmbedOptions(options) {
|
|
@@ -19288,7 +19370,12 @@ function createFrameworkMarkdownOptions(options) {
|
|
|
19288
19370
|
twitter: false,
|
|
19289
19371
|
reddit: false,
|
|
19290
19372
|
bluesky: false,
|
|
19291
|
-
webContainer: false
|
|
19373
|
+
webContainer: false,
|
|
19374
|
+
loom: false,
|
|
19375
|
+
asciinema: false,
|
|
19376
|
+
figma: false,
|
|
19377
|
+
note: false,
|
|
19378
|
+
googleSlides: false
|
|
19292
19379
|
},
|
|
19293
19380
|
i18n: false,
|
|
19294
19381
|
wikiLinks: {
|