@storm-stack/core
Version:
A build toolkit and runtime used by Storm Software in TypeScript applications
204 lines (197 loc) • 6.01 kB
JavaScript
import { __name } from './chunk-43IZMM3W.js';
import { ReflectionKind } from 'typedoc';
import { MarkdownTheme } from 'typedoc-plugin-markdown/dist/theme';
import * as Handlebars from 'handlebars';
function registerCommentHelper() {
Handlebars.registerHelper("comment", (parts) => {
const result = [];
for (const part of parts) {
switch (part.kind) {
case "text":
case "code":
result.push(part.text);
break;
case "inline-tag":
switch (part.tag) {
case "@label":
case "@inheritdoc":
break;
case "@link":
case "@linkcode":
case "@linkplain": {
if (part.target) {
const url = typeof part.target === "string" ? part.target : Handlebars.helpers.relativeURL ? Handlebars.helpers.relativeURL(part.target.url) : "";
const wrap = part.tag === "@linkcode" ? "`" : "";
result.push(url ? `[${wrap}${part.text}${wrap}](${url})` : part.text);
} else {
result.push(part.text);
}
break;
}
default:
result.push(`{${part.tag} ${part.text}}`);
break;
}
break;
default:
result.push("");
}
}
return result.join("").split("\n").filter((line) => !line.startsWith("@note")).join("\n");
});
}
__name(registerCommentHelper, "registerCommentHelper");
var comment_default = registerCommentHelper;
function escapeChars(str) {
return str.replace(/>/g, "\\>").replace(/_/g, "\\_").replace(/`/g, "\\`").replace(/\|/g, "\\|");
}
__name(escapeChars, "escapeChars");
function registerTOCHelper(theme) {
function innerRegisterTOCHelper() {
const md = [];
const { hideInPageTOC } = theme;
const isVisible = this.groups?.some((group) => group.allChildrenHaveOwnDocument());
function pushGroup(group, md2) {
const children = group.children.map((child) => {
const propertyType = [
ReflectionKind.Property,
ReflectionKind.Variable
].includes(child.kind) ? `: ${getPropertyType(child)}` : "";
return `- [${escapeChars(child.name)}](${Handlebars.helpers.relativeURL ? Handlebars.helpers.relativeURL(child.url) : child.url})${propertyType}`;
});
md2.push(children.join("\n"));
}
__name(pushGroup, "pushGroup");
if (!hideInPageTOC && this.groups || isVisible && this.groups) {
if (!hideInPageTOC) {
md.push(`## Table of contents
`);
}
const headingLevel = hideInPageTOC ? `##` : `###`;
this.groups?.forEach((group) => {
const groupTitle = group.title;
if (group.categories) {
group.categories.forEach((category) => {
md.push(`${headingLevel} ${category.title} ${groupTitle}
`);
pushGroup(category, md);
md.push("\n");
});
} else if (!hideInPageTOC || group.allChildrenHaveOwnDocument()) {
md.push(`${headingLevel} ${groupTitle}
`);
pushGroup(group, md);
md.push("\n");
}
});
}
return md.length > 0 ? md.join("\n") : null;
}
__name(innerRegisterTOCHelper, "innerRegisterTOCHelper");
Handlebars.registerHelper("toc", innerRegisterTOCHelper);
}
__name(registerTOCHelper, "registerTOCHelper");
function getPropertyType(property) {
if (property.getSignature) {
return property.getSignature.type;
}
if (property.setSignature) {
return property.setSignature.type;
}
return property.type ? property.type : property;
}
__name(getPropertyType, "getPropertyType");
var toc_default = registerTOCHelper;
// src/lib/typedoc/helpers/theme.ts
var StormStackMarkdownTheme = class extends MarkdownTheme {
static {
__name(this, "StormStackMarkdownTheme");
}
constructor(renderer) {
super(renderer);
toc_default(this);
comment_default();
}
render(page, template) {
return super.render(page, template).replace(/\.md/gi, "").replace(/\/devkit\//gi, "/devkit/documents/");
}
get mappings() {
return [
{
kind: [
ReflectionKind.Module
],
isLeaf: true,
directory: ".",
template: this.getReflectionTemplate()
},
{
kind: [
ReflectionKind.Enum
],
isLeaf: false,
directory: ".",
template: this.getReflectionTemplate()
},
{
kind: [
ReflectionKind.Class
],
isLeaf: false,
directory: ".",
template: this.getReflectionTemplate()
},
{
kind: [
ReflectionKind.Interface
],
isLeaf: false,
directory: ".",
template: this.getReflectionTemplate()
},
...this.allReflectionsHaveOwnDocument ? [
{
kind: [
ReflectionKind.TypeAlias
],
isLeaf: true,
directory: ".",
template: this.getReflectionMemberTemplate()
},
{
kind: [
ReflectionKind.Variable
],
isLeaf: true,
directory: ".",
template: this.getReflectionMemberTemplate()
},
{
kind: [
ReflectionKind.Function
],
isLeaf: true,
directory: ".",
template: this.getReflectionMemberTemplate()
}
] : []
];
}
/**
* Returns the full url of a given mapping and reflection
*
* @param mapping - The mapping object
* @param reflection - The reflection object
*/
toUrl(mapping, reflection) {
return `${(mapping.directory === "." ? "" : `${mapping.directory}/`) + this.getUrl(reflection)}.md`;
}
};
// src/lib/typedoc/index.ts
function load(app) {
app.renderer.defineTheme("storm-stack", StormStackMarkdownTheme);
}
__name(load, "load");
export { load };
//# sourceMappingURL=chunk-RU3ACI7K.js.map
//# sourceMappingURL=chunk-RU3ACI7K.js.map