UNPKG

typedoc

Version:

Create api documentation for TypeScript projects.

1,458 lines (1,446 loc) 117 kB
var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : /* @__PURE__ */ Symbol.for("Symbol." + name); var __typeError = (msg) => { throw TypeError(msg); }; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); var __decoratorStart = (base) => [, , , __create(base?.[__knownSymbol("metadata")] ?? null)]; var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"]; var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn; var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) }); var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]); var __runInitializers = (array, flags, self, value) => { for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value); return value; }; var __decorateElement = (array, flags, name, decorators, target, extra) => { var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16); var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5]; var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []); var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() { return __privateGet(this, extra); }, set [name](x) { return __privateSet(this, extra, x); } }, name)); k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name); for (var i = decorators.length - 1; i >= 0; i--) { ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers); if (k) { ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x }; if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name]; if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y; } it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1; if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it); else if (typeof it !== "object" || it === null) __typeError("Object expected"); else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn); } return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target; }; var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg); var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj); var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)); var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value); var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method); // src/lib/models/Comment.ts import { assertNever, i18n, NonEnumerable, removeIf } from "#utils"; // src/lib/models/ReflectionSymbolId.ts import "#utils"; // src/lib/models/utils.ts function splitUnquotedString(input, delimiter) { if (input.startsWith(delimiter)) { return splitUnquotedString( input.substring(delimiter.length), delimiter ); } if (input.startsWith('"')) { const closingQuoteIndex = input.indexOf('"', 1); if (closingQuoteIndex === -1) { return input.split(delimiter); } if (closingQuoteIndex === input.length - 1) { return [input]; } else { const remainder = input.substring(closingQuoteIndex + 1); return [ input.substring(0, closingQuoteIndex + 1), ...splitUnquotedString(remainder, delimiter) ]; } } else { return input.split(delimiter); } } // src/lib/models/ReflectionSymbolId.ts var ReflectionSymbolId = class { /** * This will only be used if we somehow cannot find a package.json file for * source code. This is very unlikely, but if it occurs then the {@link packageName} * will be set to this string, and {@link packagePath} will have the absolute path * to the source file. */ static UNKNOWN_PACKAGE = "<unknown>"; /** * The name of the package which this symbol ID resides within. */ packageName; /** * Path to the source file containing this symbol. * Note that this is NOT an absolute path, but a package-relative path according * to the directory containing package.json for the package name. */ packagePath; /** * Qualified name of this symbol within the source file. */ qualifiedName; /** * Note: This is **not** serialized. It exists for sorting by declaration order, but * should not be needed when deserializing from JSON. * Will be set to `Infinity` if the ID was deserialized from JSON. */ pos; /** * Note: This is **not** serialized. It exists to support detection of the differences between * symbols which share declarations, but are instantiated with different type parameters. * This will be `NaN` if the symbol reference is not transient. * Note: This can only be non-NaN if {@link pos} is finite. */ transientId; /** * Note: This is **not** serialized, only {@link packageName} and {@link packagePath} path * information is preserved when serializing. This is set so that it is available to plugins * when initially converting a project. * * @privateRemarks * This is used by typedoc-plugin-dt-links to determine the path to read to get the source * code of a definitely typed package. */ fileName; constructor(json, pos, transientId, fileName) { this.packageName = json.packageName; this.packagePath = json.packagePath; this.qualifiedName = json.qualifiedName; this.pos = pos ?? Infinity; this.transientId = transientId ?? NaN; this.fileName = fileName; } getStableKey() { if (Number.isFinite(this.pos)) { return `${this.packageName}\0${this.packagePath}\0${this.qualifiedName}\0${this.pos}\0${this.transientId}`; } else { return `${this.packageName}\0${this.packagePath}\0${this.qualifiedName}`; } } toDeclarationReference() { return { resolutionStart: "global", moduleSource: this.packageName, symbolReference: { path: splitUnquotedString(this.qualifiedName, ".").map( (path) => ({ navigation: ".", path }) ) } }; } toObject() { return { packageName: this.packageName, packagePath: this.packagePath, qualifiedName: this.qualifiedName }; } }; // src/lib/models/Comment.ts var CommentTag = class _CommentTag { /** * The name of this tag, e.g. `@returns`, `@example` */ tag; /** * Some tags, (`@typedef`, `@param`, `@property`, etc.) may have a user defined identifier associated with them. * If this tag is one of those, it will be parsed out and included here. */ name; /** * Optional type annotation associated with this tag. TypeDoc will remove type annotations unless explicitly * requested by the user with the `preservedTypeAnnotationTags` option. */ typeAnnotation; /** * The actual body text of this tag. */ content; /** * A flag which may be set by plugins to prevent TypeDoc from rendering this tag, if the plugin provides * custom rendering. Note: This flag is **not** serialized, it is expected to be set just before the comment * is rendered. */ skipRendering = false; /** * Create a new CommentTag instance. */ constructor(tag, text) { this.tag = tag; this.content = text; } /** * Checks if this block tag is roughly equal to the other tag. * This isn't exactly equal, but just "roughly equal" by the tag * text. */ similarTo(other) { return this.tag === other.tag && this.name === other.name && Comment.combineDisplayParts(this.content) === Comment.combineDisplayParts(other.content); } clone() { const tag = new _CommentTag( this.tag, Comment.cloneDisplayParts(this.content) ); if (this.name) { tag.name = this.name; } if (this.typeAnnotation) { tag.typeAnnotation = this.typeAnnotation; } return tag; } toObject() { return { tag: this.tag, name: this.name, content: Comment.serializeDisplayParts(this.content), typeAnnotation: this.typeAnnotation }; } fromObject(de, obj) { this.name = obj.name; this.typeAnnotation = obj.typeAnnotation; this.content = Comment.deserializeDisplayParts(de, obj.content); } }; var _inheritedFromParentDeclaration_dec, _discoveryId_dec, _sourcePath_dec, _init; _sourcePath_dec = [NonEnumerable], _discoveryId_dec = [NonEnumerable], _inheritedFromParentDeclaration_dec = [NonEnumerable]; var _Comment = class _Comment { /** * Creates a new Comment instance. */ constructor(summary = [], blockTags = [], modifierTags = /* @__PURE__ */ new Set()) { /** * The content of the comment which is not associated with a block tag. */ __publicField(this, "summary"); /** * All associated block level tags. */ __publicField(this, "blockTags", []); /** * All modifier tags present on the comment, e.g. `@alpha`, `@beta`. */ __publicField(this, "modifierTags", /* @__PURE__ */ new Set()); /** * Label associated with this reflection, if any (https://tsdoc.org/pages/tags/label/) */ __publicField(this, "label"); __publicField(this, "sourcePath", __runInitializers(_init, 8, this)), __runInitializers(_init, 11, this); __publicField(this, "discoveryId", __runInitializers(_init, 12, this)), __runInitializers(_init, 15, this); __publicField(this, "inheritedFromParentDeclaration", __runInitializers(_init, 16, this)), __runInitializers(_init, 19, this); this.summary = summary; this.blockTags = blockTags; this.modifierTags = modifierTags; extractLabelTag(this); } /** * Debugging utility for combining parts into a simple string. Not suitable for * rendering, but can be useful in tests. */ static combineDisplayParts(parts) { let result = ""; for (const item of parts || []) { switch (item.kind) { case "text": case "code": case "relative-link": result += item.text; break; case "inline-tag": result += `{${item.tag} ${item.text}}`; break; default: assertNever(item); } } return result; } /** * Helper utility to clone {@link Comment#summary} or {@link CommentTag#content} */ static cloneDisplayParts(parts) { return parts.map((p) => ({ ...p })); } static serializeDisplayParts(parts) { return parts?.map((part) => { switch (part.kind) { case "text": case "code": return { ...part }; case "inline-tag": { let target; if (typeof part.target === "string") { target = part.target; } else if (part.target) { if ("id" in part.target) { target = part.target.id; } else { target = part.target.toObject(); } } return { ...part, target }; } case "relative-link": { return { ...part }; } } }); } // Since display parts are plain objects, this lives here static deserializeDisplayParts(de, parts) { const links = []; const files = []; const result = parts.map((part) => { switch (part.kind) { case "text": case "code": return { ...part }; case "inline-tag": { if (typeof part.target === "number") { const part2 = { kind: part.kind, tag: part.tag, text: part.text, target: void 0, tsLinkText: part.tsLinkText }; links.push([part.target, part2]); return part2; } else if (typeof part.target === "string" || part.target === void 0) { return { kind: "inline-tag", tag: part.tag, text: part.text, target: part.target, tsLinkText: part.tsLinkText }; } else if (typeof part.target === "object") { return { kind: "inline-tag", tag: part.tag, text: part.text, target: new ReflectionSymbolId(part.target), tsLinkText: part.tsLinkText }; } else { assertNever(part.target); } break; } case "relative-link": { if (part.target) { const part2 = { kind: "relative-link", text: part.text, target: null, targetAnchor: part.targetAnchor }; files.push([part.target, part2]); return part2; } return { ...part, target: void 0, targetAnchor: part.targetAnchor }; } } }); if (links.length || files.length) { de.defer((project) => { for (const [oldFileId, part] of files) { part.target = de.oldFileIdToNewFileId[oldFileId]; } for (const [oldId, part] of links) { part.target = project.getReflectionById( de.oldIdToNewId[oldId] ?? -1 ); if (!part.target) { de.logger.warn( i18n.serialized_project_referenced_0_not_part_of_project( oldId.toString() ) ); } } }); } return result; } /** * Splits the provided parts into a header (first line, as a string) * and body (remaining lines). If the header line contains inline tags * they will be serialized to a string. */ static splitPartsToHeaderAndBody(parts) { let index = parts.findIndex((part) => { switch (part.kind) { case "text": case "code": return part.text.includes("\n"); case "inline-tag": case "relative-link": return false; } }); if (index === -1) { return { header: _Comment.combineDisplayParts(parts), body: [] }; } if (parts[index].kind === "code") { --index; } if (index === -1) { return { header: "", body: _Comment.cloneDisplayParts(parts) }; } let header = _Comment.combineDisplayParts(parts.slice(0, index)); const split = parts[index].text.indexOf("\n"); let body; if (split === -1) { header += parts[index].text; body = _Comment.cloneDisplayParts(parts.slice(index + 1)); } else { header += parts[index].text.substring(0, split); body = _Comment.cloneDisplayParts(parts.slice(index)); body[0].text = body[0].text.substring(split + 1); } if (!body[0].text) { body.shift(); } return { header: header.trim(), body }; } /** * Gets either the `@summary` tag, or a short version of the comment summary * section for rendering in module/namespace pages. */ getShortSummary(useFirstParagraph) { const tag = this.getTag("@summary"); if (tag) return tag.content; if (!useFirstParagraph) return []; let partsEnd = this.summary.findIndex((part) => { switch (part.kind) { case "text": return /\r?\n\r?\n/.test(part.text); case "code": return part.text.includes("\n"); case "inline-tag": case "relative-link": return false; default: assertNever(part); } }); const foundEnd = partsEnd !== -1; if (partsEnd === -1) { partsEnd = this.summary.length - 1; } const summaryParts = this.summary.slice(0, partsEnd); if (partsEnd !== -1) { const text = this.summary[partsEnd].text; const paragraphEnd = text.match(/\r?\n\r?\n/); if (paragraphEnd) { summaryParts.push({ ...this.summary[partsEnd], text: text.slice(0, paragraphEnd.index) }); } else if (!foundEnd) { summaryParts.push(this.summary[partsEnd]); } } return summaryParts; } /** * Checks if this comment is roughly equal to the other comment. * This isn't exactly equal, but just "roughly equal" by the comment * text. */ similarTo(other) { if (_Comment.combineDisplayParts(this.summary) !== _Comment.combineDisplayParts(other.summary)) { return false; } if (this.blockTags.length !== other.blockTags.length) { return false; } for (let i = 0; i < this.blockTags.length; ++i) { if (!this.blockTags[i].similarTo(other.blockTags[i])) { return false; } } return true; } /** * Create a deep clone of this comment. */ clone() { const comment = new _Comment( _Comment.cloneDisplayParts(this.summary), this.blockTags.map((tag) => tag.clone()), new Set(this.modifierTags) ); comment.discoveryId = this.discoveryId; comment.sourcePath = this.sourcePath; comment.inheritedFromParentDeclaration = this.inheritedFromParentDeclaration; return comment; } /** * Returns true if this comment is completely empty. * @internal */ isEmpty() { return !this.hasVisibleComponent() && this.modifierTags.size === 0; } /** * Checks if this comment contains any visible text. * * @returns TRUE when this reflection has a visible comment. */ hasVisibleComponent(notRenderedTags) { if (this.summary.some((x) => x.kind !== "text" || x.text !== "")) { return true; } if (notRenderedTags) { return this.blockTags.some((tag) => !notRenderedTags.includes(tag.tag)); } else { return this.blockTags.length > 0; } } /** * Test whether this comment contains a tag with the given name. * * @param tagName The name of the tag to look for. * @returns TRUE when this comment contains a tag with the given name, otherwise FALSE. */ hasModifier(tagName) { return this.modifierTags.has(tagName); } removeModifier(tagName) { this.modifierTags.delete(tagName); } /** * Return the first tag with the given name. * * @param tagName The name of the tag to look for. * @returns The found tag or undefined. */ getTag(tagName) { return this.blockTags.find((tag) => tag.tag === tagName); } /** * Get all tags with the given tag name. */ getTags(tagName) { return this.blockTags.filter((tag) => tag.tag === tagName); } getIdentifiedTag(identifier, tagName) { return this.blockTags.find( (tag) => tag.tag === tagName && tag.name === identifier ); } /** * Removes all block tags with the given tag name from the comment. * @param tagName */ removeTags(tagName) { removeIf(this.blockTags, (tag) => tag.tag === tagName); } toObject(serializer) { return { summary: _Comment.serializeDisplayParts(this.summary), blockTags: serializer.toObjectsOptional(this.blockTags), modifierTags: this.modifierTags.size > 0 ? Array.from(this.modifierTags) : void 0, label: this.label }; } fromObject(de, obj) { this.summary = _Comment.deserializeDisplayParts(de, obj.summary); this.blockTags = obj.blockTags?.map((tagObj) => { const tag = new CommentTag(tagObj.tag, []); de.fromObject(tag, tagObj); return tag; }) || []; this.modifierTags = new Set(obj.modifierTags); this.label = obj.label; } }; _init = __decoratorStart(null); __decorateElement(_init, 5, "sourcePath", _sourcePath_dec, _Comment); __decorateElement(_init, 5, "discoveryId", _discoveryId_dec, _Comment); __decorateElement(_init, 5, "inheritedFromParentDeclaration", _inheritedFromParentDeclaration_dec, _Comment); __decoratorMetadata(_init, _Comment); var Comment = _Comment; function extractLabelTag(comment) { const index = comment.summary.findIndex( (part) => part.kind === "inline-tag" && part.tag === "@label" ); if (index !== -1) { comment.label = comment.summary.splice(index, 1)[0].text; } } // src/lib/models/Reflection.ts import { i18n as i18n3, NonEnumerable as NonEnumerable2 } from "#utils"; // src/lib/models/kind.ts import { i18n as i18n2 } from "#utils"; var ReflectionKind = /* @__PURE__ */ ((ReflectionKind2) => { ReflectionKind2[ReflectionKind2["Project"] = 1] = "Project"; ReflectionKind2[ReflectionKind2["Module"] = 2] = "Module"; ReflectionKind2[ReflectionKind2["Namespace"] = 4] = "Namespace"; ReflectionKind2[ReflectionKind2["Enum"] = 8] = "Enum"; ReflectionKind2[ReflectionKind2["EnumMember"] = 16] = "EnumMember"; ReflectionKind2[ReflectionKind2["Variable"] = 32] = "Variable"; ReflectionKind2[ReflectionKind2["Function"] = 64] = "Function"; ReflectionKind2[ReflectionKind2["Class"] = 128] = "Class"; ReflectionKind2[ReflectionKind2["Interface"] = 256] = "Interface"; ReflectionKind2[ReflectionKind2["Constructor"] = 512] = "Constructor"; ReflectionKind2[ReflectionKind2["Property"] = 1024] = "Property"; ReflectionKind2[ReflectionKind2["Method"] = 2048] = "Method"; ReflectionKind2[ReflectionKind2["CallSignature"] = 4096] = "CallSignature"; ReflectionKind2[ReflectionKind2["IndexSignature"] = 8192] = "IndexSignature"; ReflectionKind2[ReflectionKind2["ConstructorSignature"] = 16384] = "ConstructorSignature"; ReflectionKind2[ReflectionKind2["Parameter"] = 32768] = "Parameter"; ReflectionKind2[ReflectionKind2["TypeLiteral"] = 65536] = "TypeLiteral"; ReflectionKind2[ReflectionKind2["TypeParameter"] = 131072] = "TypeParameter"; ReflectionKind2[ReflectionKind2["Accessor"] = 262144] = "Accessor"; ReflectionKind2[ReflectionKind2["GetSignature"] = 524288] = "GetSignature"; ReflectionKind2[ReflectionKind2["SetSignature"] = 1048576] = "SetSignature"; ReflectionKind2[ReflectionKind2["TypeAlias"] = 2097152] = "TypeAlias"; ReflectionKind2[ReflectionKind2["Reference"] = 4194304] = "Reference"; ReflectionKind2[ReflectionKind2["Document"] = 8388608] = "Document"; return ReflectionKind2; })(ReflectionKind || {}); ((ReflectionKind2) => { ReflectionKind2.All = 4194304 /* Reference */ * 2 - 1; ReflectionKind2.ClassOrInterface = 128 /* Class */ | 256 /* Interface */; ReflectionKind2.VariableOrProperty = 32 /* Variable */ | 1024 /* Property */; ReflectionKind2.FunctionOrMethod = 64 /* Function */ | 2048 /* Method */; ReflectionKind2.ClassMember = 262144 /* Accessor */ | 512 /* Constructor */ | 2048 /* Method */ | 1024 /* Property */; ReflectionKind2.SomeSignature = 4096 /* CallSignature */ | 8192 /* IndexSignature */ | 16384 /* ConstructorSignature */ | 524288 /* GetSignature */ | 1048576 /* SetSignature */; ReflectionKind2.SomeModule = 4 /* Namespace */ | 2 /* Module */; ReflectionKind2.SomeType = 256 /* Interface */ | 65536 /* TypeLiteral */ | 131072 /* TypeParameter */ | 2097152 /* TypeAlias */; ReflectionKind2.SomeValue = 32 /* Variable */ | 64 /* Function */; ReflectionKind2.SomeMember = 16 /* EnumMember */ | 1024 /* Property */ | 2048 /* Method */ | 262144 /* Accessor */; ReflectionKind2.SomeExport = 2 /* Module */ | 4 /* Namespace */ | 8 /* Enum */ | 32 /* Variable */ | 64 /* Function */ | 128 /* Class */ | 256 /* Interface */ | 2097152 /* TypeAlias */ | 4194304 /* Reference */; ReflectionKind2.MayContainDocuments = ReflectionKind2.SomeExport | 1 /* Project */ | 8388608 /* Document */; ReflectionKind2.ExportContainer = ReflectionKind2.SomeModule | 1 /* Project */; ReflectionKind2.Inheritable = 262144 /* Accessor */ | 8192 /* IndexSignature */ | 1024 /* Property */ | 2048 /* Method */ | 512 /* Constructor */; ReflectionKind2.ContainsCallSignatures = 512 /* Constructor */ | 64 /* Function */ | 2048 /* Method */; ReflectionKind2.TypeReferenceTarget = 256 /* Interface */ | 2097152 /* TypeAlias */ | 128 /* Class */ | 8 /* Enum */; ReflectionKind2.ValueReferenceTarget = 2 /* Module */ | 4 /* Namespace */ | 32 /* Variable */ | 64 /* Function */; ReflectionKind2.SignatureContainer = ReflectionKind2.ContainsCallSignatures | 262144 /* Accessor */; ReflectionKind2.VariableContainer = ReflectionKind2.SomeModule | 1 /* Project */; ReflectionKind2.MethodContainer = ReflectionKind2.ClassOrInterface | ReflectionKind2.VariableOrProperty | ReflectionKind2.FunctionOrMethod | 65536 /* TypeLiteral */; function singularString(kind) { switch (kind) { case 1 /* Project */: return i18n2.kind_project(); case 2 /* Module */: return i18n2.kind_module(); case 4 /* Namespace */: return i18n2.kind_namespace(); case 8 /* Enum */: return i18n2.kind_enum(); case 16 /* EnumMember */: return i18n2.kind_enum_member(); case 32 /* Variable */: return i18n2.kind_variable(); case 64 /* Function */: return i18n2.kind_function(); case 128 /* Class */: return i18n2.kind_class(); case 256 /* Interface */: return i18n2.kind_interface(); case 512 /* Constructor */: return i18n2.kind_constructor(); case 1024 /* Property */: return i18n2.kind_property(); case 2048 /* Method */: return i18n2.kind_method(); case 4096 /* CallSignature */: return i18n2.kind_call_signature(); case 8192 /* IndexSignature */: return i18n2.kind_index_signature(); case 16384 /* ConstructorSignature */: return i18n2.kind_constructor_signature(); case 32768 /* Parameter */: return i18n2.kind_parameter(); case 65536 /* TypeLiteral */: return i18n2.kind_type_literal(); case 131072 /* TypeParameter */: return i18n2.kind_type_parameter(); case 262144 /* Accessor */: return i18n2.kind_accessor(); case 524288 /* GetSignature */: return i18n2.kind_get_signature(); case 1048576 /* SetSignature */: return i18n2.kind_set_signature(); case 2097152 /* TypeAlias */: return i18n2.kind_type_alias(); case 4194304 /* Reference */: return i18n2.kind_reference(); case 8388608 /* Document */: return i18n2.kind_document(); } } ReflectionKind2.singularString = singularString; function pluralString(kind) { switch (kind) { case 1 /* Project */: return i18n2.kind_plural_project(); case 2 /* Module */: return i18n2.kind_plural_module(); case 4 /* Namespace */: return i18n2.kind_plural_namespace(); case 8 /* Enum */: return i18n2.kind_plural_enum(); case 16 /* EnumMember */: return i18n2.kind_plural_enum_member(); case 32 /* Variable */: return i18n2.kind_plural_variable(); case 64 /* Function */: return i18n2.kind_plural_function(); case 128 /* Class */: return i18n2.kind_plural_class(); case 256 /* Interface */: return i18n2.kind_plural_interface(); case 512 /* Constructor */: return i18n2.kind_plural_constructor(); case 1024 /* Property */: return i18n2.kind_plural_property(); case 2048 /* Method */: return i18n2.kind_plural_method(); case 4096 /* CallSignature */: return i18n2.kind_plural_call_signature(); case 8192 /* IndexSignature */: return i18n2.kind_plural_index_signature(); case 16384 /* ConstructorSignature */: return i18n2.kind_plural_constructor_signature(); case 32768 /* Parameter */: return i18n2.kind_plural_parameter(); case 65536 /* TypeLiteral */: return i18n2.kind_plural_type_literal(); case 131072 /* TypeParameter */: return i18n2.kind_plural_type_parameter(); case 262144 /* Accessor */: return i18n2.kind_plural_accessor(); case 524288 /* GetSignature */: return i18n2.kind_plural_get_signature(); case 1048576 /* SetSignature */: return i18n2.kind_plural_set_signature(); case 2097152 /* TypeAlias */: return i18n2.kind_plural_type_alias(); case 4194304 /* Reference */: return i18n2.kind_plural_reference(); case 8388608 /* Document */: return i18n2.kind_plural_document(); } } ReflectionKind2.pluralString = pluralString; function classString(kind) { return `tsd-kind-${ReflectionKind2[kind].replace(/(.)([A-Z])/g, (_m, a, b) => `${a}-${b}`).toLowerCase()}`; } ReflectionKind2.classString = classString; })(ReflectionKind || (ReflectionKind = {})); // src/lib/models/Reflection.ts var REFLECTION_ID = 0; function resetReflectionID() { REFLECTION_ID = 0; } var ReflectionFlag = /* @__PURE__ */ ((ReflectionFlag2) => { ReflectionFlag2[ReflectionFlag2["None"] = 0] = "None"; ReflectionFlag2[ReflectionFlag2["Private"] = 1] = "Private"; ReflectionFlag2[ReflectionFlag2["Protected"] = 2] = "Protected"; ReflectionFlag2[ReflectionFlag2["Public"] = 4] = "Public"; ReflectionFlag2[ReflectionFlag2["Static"] = 8] = "Static"; ReflectionFlag2[ReflectionFlag2["External"] = 16] = "External"; ReflectionFlag2[ReflectionFlag2["Optional"] = 32] = "Optional"; ReflectionFlag2[ReflectionFlag2["Rest"] = 64] = "Rest"; ReflectionFlag2[ReflectionFlag2["Abstract"] = 128] = "Abstract"; ReflectionFlag2[ReflectionFlag2["Const"] = 256] = "Const"; ReflectionFlag2[ReflectionFlag2["Readonly"] = 512] = "Readonly"; ReflectionFlag2[ReflectionFlag2["Inherited"] = 1024] = "Inherited"; return ReflectionFlag2; })(ReflectionFlag || {}); var relevantFlags = [ 1 /* Private */, 2 /* Protected */, 8 /* Static */, 32 /* Optional */, 128 /* Abstract */, 256 /* Const */, 512 /* Readonly */ ]; var ReflectionFlags = class _ReflectionFlags { flags = 0 /* None */; hasFlag(flag) { return (flag & this.flags) !== 0; } /** * Is this a private member? */ get isPrivate() { return this.hasFlag(1 /* Private */); } /** * Is this a protected member? */ get isProtected() { return this.hasFlag(2 /* Protected */); } /** * Is this a public member? */ get isPublic() { return this.hasFlag(4 /* Public */); } /** * Is this a static member? */ get isStatic() { return this.hasFlag(8 /* Static */); } /** * Is this a declaration from an external document? */ get isExternal() { return this.hasFlag(16 /* External */); } /** * Whether this reflection is an optional component or not. * * Applies to function parameters and object members. */ get isOptional() { return this.hasFlag(32 /* Optional */); } /** * Whether it's a rest parameter, like `foo(...params);`. */ get isRest() { return this.hasFlag(64 /* Rest */); } get isAbstract() { return this.hasFlag(128 /* Abstract */); } get isConst() { return this.hasFlag(256 /* Const */); } get isReadonly() { return this.hasFlag(512 /* Readonly */); } get isInherited() { return this.hasFlag(1024 /* Inherited */); } setFlag(flag, set) { switch (flag) { case 1 /* Private */: this.setSingleFlag(1 /* Private */, set); if (set) { this.setFlag(2 /* Protected */, false); this.setFlag(4 /* Public */, false); } break; case 2 /* Protected */: this.setSingleFlag(2 /* Protected */, set); if (set) { this.setFlag(1 /* Private */, false); this.setFlag(4 /* Public */, false); } break; case 4 /* Public */: this.setSingleFlag(4 /* Public */, set); if (set) { this.setFlag(1 /* Private */, false); this.setFlag(2 /* Protected */, false); } break; default: this.setSingleFlag(flag, set); } } static flagString(flag) { switch (flag) { case 0 /* None */: throw new Error("Should be unreachable"); case 1 /* Private */: return i18n3.flag_private(); case 2 /* Protected */: return i18n3.flag_protected(); case 4 /* Public */: return i18n3.flag_public(); case 8 /* Static */: return i18n3.flag_static(); case 16 /* External */: return i18n3.flag_external(); case 32 /* Optional */: return i18n3.flag_optional(); case 64 /* Rest */: return i18n3.flag_rest(); case 128 /* Abstract */: return i18n3.flag_abstract(); case 256 /* Const */: return i18n3.flag_const(); case 512 /* Readonly */: return i18n3.flag_readonly(); case 1024 /* Inherited */: return i18n3.flag_inherited(); } } getFlagStrings() { const strings = []; for (const flag of relevantFlags) { if (this.hasFlag(flag)) { strings.push(_ReflectionFlags.flagString(flag)); } } return strings; } setSingleFlag(flag, set) { if (!set && this.hasFlag(flag)) { this.flags ^= flag; } else if (set && !this.hasFlag(flag)) { this.flags |= flag; } } static serializedFlags = [ "isPrivate", "isProtected", "isPublic", "isStatic", "isExternal", "isOptional", "isRest", "isAbstract", "isConst", "isReadonly", "isInherited" ]; toObject() { return Object.fromEntries( _ReflectionFlags.serializedFlags.filter((flag) => this[flag]).map((flag) => [flag, true]) ); } fromObject(obj) { for (const key of Object.keys(obj)) { const flagName = key.substring(2); if (flagName in ReflectionFlag) { this.setFlag( ReflectionFlag[flagName], true ); } } } }; var TraverseProperty = /* @__PURE__ */ ((TraverseProperty2) => { TraverseProperty2[TraverseProperty2["Children"] = 0] = "Children"; TraverseProperty2[TraverseProperty2["Documents"] = 1] = "Documents"; TraverseProperty2[TraverseProperty2["Parameters"] = 2] = "Parameters"; TraverseProperty2[TraverseProperty2["TypeLiteral"] = 3] = "TypeLiteral"; TraverseProperty2[TraverseProperty2["TypeParameter"] = 4] = "TypeParameter"; TraverseProperty2[TraverseProperty2["Signatures"] = 5] = "Signatures"; TraverseProperty2[TraverseProperty2["IndexSignature"] = 6] = "IndexSignature"; TraverseProperty2[TraverseProperty2["GetSignature"] = 7] = "GetSignature"; TraverseProperty2[TraverseProperty2["SetSignature"] = 8] = "SetSignature"; return TraverseProperty2; })(TraverseProperty || {}); var _project_dec, _parent_dec, _init2; _parent_dec = [NonEnumerable2], _project_dec = [NonEnumerable2]; var Reflection = class { constructor(name, kind, parent) { /** * Unique id of this reflection. */ __publicField(this, "id"); /** * The symbol name of this reflection. */ __publicField(this, "name"); /** * The kind of this reflection. */ __publicField(this, "kind"); __publicField(this, "flags", new ReflectionFlags()); // So that it doesn't show up in console.log __publicField(this, "parent", __runInitializers(_init2, 8, this)), __runInitializers(_init2, 11, this); __publicField(this, "project", __runInitializers(_init2, 12, this)), __runInitializers(_init2, 15, this); /** * The parsed documentation comment attached to this reflection. */ __publicField(this, "comment"); this.id = REFLECTION_ID++; this.parent = parent; this.project = parent?.project || this; this.name = name; this.kind = kind; if (parent?.flags.isExternal) { this.setFlag(16 /* External */); } } /** * Test whether this reflection is of the given kind. */ kindOf(kind) { const kindFlags = Array.isArray(kind) ? kind.reduce((a, b) => a | b, 0) : kind; return (this.kind & kindFlags) !== 0; } /** * Return the full name of this reflection. Intended for use in debugging. For log messages * intended to be displayed to the user for them to fix, prefer {@link getFriendlyFullName} instead. * * The full name contains the name of this reflection and the names of all parent reflections. * * @param separator Separator used to join the names of the reflections. * @returns The full name of this reflection. */ getFullName(separator = ".") { if (this.parent && !this.parent.isProject()) { return this.parent.getFullName(separator) + separator + this.name; } else { return this.name; } } /** * Return the full name of this reflection, with signature names dropped if possible without * introducing ambiguity in the name. */ getFriendlyFullName() { if (this.parent && !this.parent.isProject()) { if (this.kindOf( 16384 /* ConstructorSignature */ | 4096 /* CallSignature */ | 524288 /* GetSignature */ | 1048576 /* SetSignature */ )) { return this.parent.getFriendlyFullName(); } return this.parent.getFriendlyFullName() + "." + this.name; } else { return this.name; } } /** * Set a flag on this reflection. */ setFlag(flag, value = true) { this.flags.setFlag(flag, value); } /** * Checks if this reflection has a comment which contains any visible text. * * @returns TRUE when this reflection has a visible comment. */ hasComment(notRenderedTags) { return this.comment ? this.comment.hasVisibleComponent(notRenderedTags) : false; } hasGetterOrSetter() { return false; } /** * Return a child by its name. * * @param arg The name hierarchy of the child to look for. * @returns The found child or undefined. */ getChildByName(arg) { const names = Array.isArray(arg) ? arg : splitUnquotedString(arg, "."); const name = names[0]; let result; this.traverse((child) => { if (child.name === name) { if (names.length <= 1) { result = child; } else { result = child.getChildByName(names.slice(1)); } return false; } return true; }); return result; } /** * Return whether this reflection is the root / project reflection. */ isProject() { return false; } isDeclaration() { return false; } isSignature() { return false; } isTypeParameter() { return false; } isParameter() { return false; } isDocument() { return false; } isReference() { return this.variant === "reference"; } isContainer() { return false; } /** * Check if this reflection or any of its parents have been marked with the `@deprecated` tag. */ isDeprecated() { let signaturesDeprecated = false; this.visit({ declaration(decl) { if (decl.signatures?.length && decl.signatures.every((sig) => sig.comment?.getTag("@deprecated"))) { signaturesDeprecated = true; } } }); if (signaturesDeprecated || this.comment?.getTag("@deprecated")) { return true; } return this.parent?.isDeprecated() ?? false; } visit(visitor) { visitor[this.variant]?.(this); } /** * Return a string representation of this reflection. */ toString() { return ReflectionKind[this.kind] + " " + this.name; } /** * Return a string representation of this reflection and all of its children. * * Note: This is intended as a debug tool only, output may change between patch versions. * * @param indent Used internally to indent child reflections. */ toStringHierarchy(indent = "") { const lines = [indent + this.toString()]; indent += " "; this.traverse((child) => { lines.push(child.toStringHierarchy(indent)); return true; }); return lines.join("\n"); } toObject(serializer) { return { id: this.id, name: this.name, variant: this.variant, kind: this.kind, flags: this.flags.toObject(), comment: this.comment && !this.comment.isEmpty() ? serializer.toObject(this.comment) : void 0 }; } fromObject(de, obj) { this.name = obj.name; this.kind = obj.kind; this.flags.fromObject(obj.flags); this.comment = de.revive(obj.comment, () => new Comment()); } }; _init2 = __decoratorStart(null); __decorateElement(_init2, 5, "parent", _parent_dec, Reflection); __decorateElement(_init2, 5, "project", _project_dec, Reflection); __decoratorMetadata(_init2, Reflection); // src/lib/models/ReflectionCategory.ts var ReflectionCategory = class { /** * The title, a string representation of this category. */ title; /** * The user specified description, if any, set with `@categoryDescription` */ description; /** * All reflections of this category. */ children = []; /** * Create a new ReflectionCategory instance. * * @param title The title of this category. */ constructor(title) { this.title = title; } toObject() { return { title: this.title, description: this.description ? Comment.serializeDisplayParts(this.description) : void 0, children: this.children.length > 0 ? this.children.map((child) => child.id) : void 0 }; } fromObject(de, obj) { if (obj.description) { this.description = Comment.deserializeDisplayParts( de, obj.description ); } if (obj.children) { de.defer((project) => { for (const childId of obj.children || []) { const child = project.getReflectionById( de.oldIdToNewId[childId] ?? -1 ); if (child?.isDeclaration() || child?.isDocument()) { this.children.push(child); } } }); } } }; // src/lib/models/ReflectionGroup.ts var ReflectionGroup = class { /** * Create a new ReflectionGroup instance. * * @param title The title of this group. * @param owningReflection The reflection containing this group, useful for changing rendering based on a comment on a reflection. */ constructor(title, owningReflection) { this.owningReflection = owningReflection; this.title = title; } owningReflection; /** * The title, a string representation of the typescript kind, of this group. */ title; /** * User specified description via `@groupDescription`, if specified. */ description; /** * All reflections of this group. */ children = []; /** * Categories contained within this group. */ categories; toObject(serializer) { return { title: this.title, description: this.description ? Comment.serializeDisplayParts(this.description) : void 0, children: this.children.length > 0 ? this.children.map((child) => child.id) : void 0, categories: serializer.toObjectsOptional(this.categories) }; } fromObject(de, obj) { if (obj.description) { this.description = Comment.deserializeDisplayParts( de, obj.description ); } if (obj.categories) { this.categories = obj.categories.map((catObj) => { const cat = new ReflectionCategory(catObj.title); de.fromObject(cat, catObj); return cat; }); } if (obj.children) { de.defer((project) => { for (const childId of obj.children || []) { const child = project.getReflectionById( de.oldIdToNewId[childId] ?? -1 ); if (child?.isDeclaration() || child?.isDocument()) { this.children.push(child); } } }); } } }; // src/lib/models/ContainerReflection.ts import { assertNever as assertNever2, removeIfPresent } from "#utils"; var ContainerReflection = class extends Reflection { /** * The children of this reflection. Do not add reflections to this array * manually. Instead call {@link addChild}. */ children; /** * Documents associated with this reflection. * * These are not children as including them as children requires code handle both * types, despite being mostly unrelated and handled separately. * * Including them here in a separate array neatly handles that problem, but also * introduces another one for rendering. When rendering, documents should really * actually be considered part of the "children" of a reflection. For this reason, * we also maintain a list of child declarations with child documents which is used * when rendering. */ documents; /** * Union of the {@link children} and {@link documents} arrays which dictates the * sort order for rendering. */ childrenIncludingDocuments; /** * All children grouped by their kind. */ groups; /** * All children grouped by their category. */ categories; /** * Return a list of all children of a certain kind. * * @param kind The desired kind of children. * @returns An array containing all children with the desired kind. */ getChildrenByKind(kind) { return (this.children || []).filter((child) => child.kindOf(kind)); } addChild(child) { if (child.isDeclaration()) { this.children ||= []; this.children.push(child); this.childrenIncludingDocuments ||= []; this.childrenIncludingDocuments.push(child); } else if (child.isDocument()) { this.documents ||= []; this.documents.push(child); this.childrenIncludingDocuments ||= []; this.childrenIncludingDocuments.push(child); } else if (this.isDeclaration() && child.isSignature()) { switch (child.kind) { case 4096 /* CallSignature */: case 16384 /* ConstructorSignature */: this.signatures ||= []; this.signatures.push(child); break; case 8192 /* IndexSignature */: this.indexSignatures ||= []; this.indexSignatures.push(child); break; case 524288 /* GetSignature */: case 1048576 /* SetSignature */: throw new Error("Unsupported child type: " + ReflectionKind[child.kind]); default: assertNever2(child.kind); } } else { throw new Error("Unsupported child type: " + ReflectionKind[child.kind]); } } removeChild(child) { if (child.isDeclaration()) { removeIfPresent(this.children, child); if (this.children?.length === 0) { delete this.children; } } else { removeIfPresent(this.documents, child); if (this.documents?.length === 0) { delete this.documents; } } removeIfPresent(this.childrenIncludingDocuments, child); if (this.childrenIncludingDocuments?.length === 0) { delete this.childrenIncludingDocuments; } } isContainer() { return true; } traverse(callback) { for (const child of this.children?.slice() || []) { if (callback(child, 0 /* Children */) === false) { return; } } for (const child of this.documents?.slice() || []) { if (callback(child, 1 /* Documents */) === false) { return; } } } toObject(serializer) { return { ...super.toObject(serializer), children: serializer.toObjectsOptional(this.children), documents: serializer.toObjectsOptional(this.documents), // If we only have one type of child, don't bother writing the duplicate info about // ordering with documents to the serialized file. childrenIncludingDocuments: this.children?.length && this.documents?.length ? this.childrenIncludingDocuments?.map((refl) => refl.id) : void 0, groups: serializer.toObjectsOptional(this.groups), categories: serializer.toObjectsOptional(this.categories) }; } fromObject(de, obj) { super.fromObject(de, obj); this.children = de.reviveMany(obj.children, (child) => de.constructReflection(child)); this.documents = de.reviveMany(obj.documents, (child) => de.constructReflection(child)); const byId = /* @__PURE__ */ new Map(); for (const child of this.children || []) { byId.set(child.id, child); } for (const child of this.documents || []) { byId.set(child.id, child); } for (const id of obj.childrenIncludingDocuments || []) { const child = byId.get(de.oldIdToNewId[id] ?? -1); if (child) { this.childrenIncludingDocuments ||= []; this.childrenIncludingDocuments.push(child); byId.delete(de.oldIdToNewId[id] ?? -1); } } if (byId.size) { this.childrenIncludingDocuments ||= []; this.childrenIncludingDocuments.push(...byId.values()); } this.groups = de.reviveMany( obj.groups, (group) => new ReflectionGroup(group.title, this) ); this.categories = de.reviveMany( obj.categories, (cat) => new ReflectionCategory(cat.title) ); } }; // src/lib/models/