mirror of
https://github.com/Kornstalx/5etools-mirror-2.github.io.git
synced 2025-10-28 20:45:35 -05:00
v1.203.0
This commit is contained in:
61
js/render.js
61
js/render.js
@@ -260,7 +260,6 @@ globalThis.Renderer = function () {
|
||||
|
||||
this._getPlugins = function (pluginType) { return this._plugins[pluginType] ||= []; };
|
||||
|
||||
// TODO(Future) refactor to use this
|
||||
this._applyPlugins_useFirst = function (pluginType, commonArgs, pluginArgs) {
|
||||
for (const plugin of this._getPlugins(pluginType)) {
|
||||
const out = plugin(commonArgs, pluginArgs);
|
||||
@@ -279,6 +278,15 @@ globalThis.Renderer = function () {
|
||||
return input;
|
||||
};
|
||||
|
||||
this._applyPlugins_getAll = function (pluginType, commonArgs, pluginArgs) {
|
||||
const plugins = this._getPlugins(pluginType);
|
||||
if (!plugins?.length) return [];
|
||||
|
||||
return plugins
|
||||
.map(plugin => plugin(commonArgs, pluginArgs))
|
||||
.filter(Boolean);
|
||||
};
|
||||
|
||||
/** Run a function with the given plugin active. */
|
||||
this.withPlugin = function ({pluginTypes, fnPlugin, fn}) {
|
||||
for (const pt of pluginTypes) this.addPlugin(pt, fnPlugin);
|
||||
@@ -504,7 +512,7 @@ globalThis.Renderer = function () {
|
||||
: null;
|
||||
const ptTitleCreditTooltip = this._renderImage_getTitleCreditTooltipText(entry);
|
||||
const ptTitle = ptTitleCreditTooltip ? `title="${ptTitleCreditTooltip}"` : "";
|
||||
const pluginDataIsNoLink = this._getPlugins("image_isNoLink").map(plugin => plugin(entry, textStack, meta, options)).some(Boolean);
|
||||
const pluginDataIsNoLink = this._applyPlugins_useFirst("image_isNoLink", {textStack, meta, options}, {input: entry});
|
||||
|
||||
textStack[0] += `<div class="${this._renderImage_getWrapperClasses(entry, meta)}" ${entry.title && this._isHeaderIndexIncludeImageTitles ? `data-title-index="${this._headerIndex++}"` : ""}>
|
||||
${pluginDataIsNoLink ? "" : `<a href="${href}" target="_blank" rel="noopener noreferrer" ${ptTitle}>`}
|
||||
@@ -604,17 +612,13 @@ globalThis.Renderer = function () {
|
||||
|
||||
this._renderImage_getUrl = function (entry) {
|
||||
let url = Renderer.utils.getEntryMediaUrl(entry, "href", "img");
|
||||
for (const plugin of this._getPlugins(`image_urlPostProcess`)) {
|
||||
url = plugin(entry, url) || url;
|
||||
}
|
||||
url = this._applyPlugins_useAll("image_urlPostProcess", null, {input: url}) ?? url;
|
||||
return url;
|
||||
};
|
||||
|
||||
this._renderImage_getUrlThumbnail = function (entry) {
|
||||
let url = Renderer.utils.getEntryMediaUrl(entry, "hrefThumbnail", "img");
|
||||
for (const plugin of this._getPlugins(`image_urlThumbnailPostProcess`)) {
|
||||
url = plugin(entry, url) || url;
|
||||
}
|
||||
url = this._applyPlugins_useAll("image_urlThumbnailPostProcess", null, {input: url}) ?? url;
|
||||
return url;
|
||||
};
|
||||
|
||||
@@ -824,7 +828,7 @@ globalThis.Renderer = function () {
|
||||
const cachedLastDepthTrackerProps = MiscUtil.copyFast(this._lastDepthTrackerInheritedProps);
|
||||
this._handleTrackDepth(entry, meta.depth);
|
||||
|
||||
const pluginDataNamePrefix = this._getPlugins(`${type}_namePrefix`).map(plugin => plugin(entry, textStack, meta, options)).filter(Boolean);
|
||||
const pluginDataNamePrefix = this._applyPlugins_getAll(`${type}_namePrefix`, {textStack, meta, options}, {input: entry});
|
||||
|
||||
const headerSpan = entry.name ? `<${headerTag} class="rd__h ${headerClass}" data-title-index="${this._headerIndex++}" ${this._getEnumeratedTitleRel(entry.name)}> <span class="entry-title-inner${!pagePart && entry.source ? ` help-subtle` : ""}"${!pagePart && entry.source ? ` title="Source: ${Parser.sourceJsonToFull(entry.source)}${entry.page ? `, p${entry.page}` : ""}"` : ""}>${pluginDataNamePrefix.join("")}${this.render({type: "inline", entries: [entry.name]})}${isAddPeriod ? "." : ""}</span>${partPageExpandCollapse}</${headerTag}> ` : "";
|
||||
|
||||
@@ -1245,7 +1249,7 @@ globalThis.Renderer = function () {
|
||||
};
|
||||
|
||||
this._renderDice = function (entry, textStack, meta, options) {
|
||||
const pluginResults = this._getPlugins("dice").map(plugin => plugin(entry, textStack, meta, options)).filter(Boolean);
|
||||
const pluginResults = this._applyPlugins_getAll("dice", {textStack, meta, options}, {input: entry});
|
||||
|
||||
textStack[0] += Renderer.getEntryDice(entry, entry.name, {isAddHandlers: this._isAddHandlers, pluginResults});
|
||||
};
|
||||
@@ -1545,8 +1549,7 @@ globalThis.Renderer = function () {
|
||||
this._getStyleClass = function (entryType, entry) {
|
||||
const outList = [];
|
||||
|
||||
const pluginResults = this._getPlugins(`${entryType}_styleClass_fromSource`)
|
||||
.map(plugin => plugin(entryType, entry)).filter(Boolean);
|
||||
const pluginResults = this._applyPlugins_getAll(`${entryType}_styleClass_fromSource`, null, {input: {entryType, entry}});
|
||||
|
||||
if (!pluginResults.some(it => it.isSkip)) {
|
||||
if (
|
||||
@@ -1585,29 +1588,21 @@ globalThis.Renderer = function () {
|
||||
};
|
||||
|
||||
this._renderString_renderBasic = function (textStack, meta, options, str) {
|
||||
// region Plugins
|
||||
for (const plugin of this._getPlugins("string_basic")) {
|
||||
const out = plugin(str, textStack, meta, options);
|
||||
if (out) return void (textStack[0] += out);
|
||||
}
|
||||
// endregion
|
||||
const fromPlugins = this._applyPlugins_useFirst("string_basic", {textStack, meta, options}, {input: str});
|
||||
if (fromPlugins) return void (textStack[0] += fromPlugins);
|
||||
|
||||
textStack[0] += str;
|
||||
};
|
||||
|
||||
this._renderString_renderTag = function (textStack, meta, options, tag, text) {
|
||||
// region Plugins
|
||||
// Generic
|
||||
for (const plugin of this._getPlugins("string_tag")) {
|
||||
const out = plugin(tag, text, textStack, meta, options);
|
||||
if (out) return void (textStack[0] += out);
|
||||
}
|
||||
|
||||
// Tag-specific
|
||||
for (const plugin of this._getPlugins(`string_${tag}`)) {
|
||||
const out = plugin(tag, text, textStack, meta, options);
|
||||
if (out) return void (textStack[0] += out);
|
||||
}
|
||||
const fromPluginsSpecific = this._applyPlugins_useFirst(`string_${tag}`, {textStack, meta, options}, {input: {tag, text}});
|
||||
if (fromPluginsSpecific) return void (textStack[0] += fromPluginsSpecific);
|
||||
|
||||
// Generic
|
||||
const fromPluginsGeneric = this._applyPlugins_useFirst("string_tag", {textStack, meta, options}, {input: {tag, text}});
|
||||
if (fromPluginsGeneric) return void (textStack[0] += fromPluginsGeneric);
|
||||
// endregion
|
||||
|
||||
switch (tag) {
|
||||
@@ -2035,7 +2030,7 @@ globalThis.Renderer = function () {
|
||||
}
|
||||
}
|
||||
|
||||
const pluginData = this._getPlugins("link").map(plugin => plugin(entry, textStack, meta, options)).filter(Boolean);
|
||||
const pluginData = this._applyPlugins_getAll("link", {textStack, meta, options}, {input: entry});
|
||||
const isDisableEvents = pluginData.some(it => it.isDisableEvents);
|
||||
const additionalAttributes = pluginData.map(it => it.attributes).filter(Boolean);
|
||||
|
||||
@@ -2084,9 +2079,7 @@ globalThis.Renderer = function () {
|
||||
procHash += Renderer.utils.getLinkSubhashString(entry.href.hover.subhashes);
|
||||
}
|
||||
|
||||
const pluginData = this._getPlugins("link_attributesHover")
|
||||
.map(plugin => plugin(entry, procHash))
|
||||
.filter(Boolean);
|
||||
const pluginData = this._applyPlugins_getAll("link_attributesHover", null, {input: {entry, procHash}});
|
||||
const replacementAttributes = pluginData.map(it => it.attributesHoverReplace).filter(Boolean);
|
||||
if (replacementAttributes.length) return replacementAttributes.join(" ");
|
||||
|
||||
@@ -11046,10 +11039,10 @@ Renderer.generic = class {
|
||||
|
||||
static getTokenUrl (ent, mediaDir, {isIgnoreImplicit = false} = {}) {
|
||||
if (ent.tokenUrl) return ent.tokenUrl; // TODO(Future) legacy; remove
|
||||
if (ent.token) return Renderer.get().getMediaUrl("img", `${mediaDir}/${Parser.sourceJsonToAbv(ent.token.source)}/${Parser.nameToTokenName(ent.token.name)}.webp`);
|
||||
if (ent.token) return Renderer.get().getMediaUrl("img", `${mediaDir}/${ent.token.source}/${Parser.nameToTokenName(ent.token.name)}.webp`);
|
||||
if (ent.tokenHref) return Renderer.utils.getEntryMediaUrl(ent, "tokenHref", "img");
|
||||
if (isIgnoreImplicit) return null;
|
||||
return Renderer.get().getMediaUrl("img", `${mediaDir}/${Parser.sourceJsonToAbv(ent.source)}/${Parser.nameToTokenName(ent.name)}.webp`);
|
||||
return Renderer.get().getMediaUrl("img", `${mediaDir}/${ent.source}/${Parser.nameToTokenName(ent.name)}.webp`);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user