UNPKG

fumadocs-core

Version:

The React.js library for building a documentation website

1,022 lines (1,021 loc) • 29.1 kB
import { r as __toESM, t as __commonJSMin } from "./chunk-B-1-B7_t.js"; //#region ../../node_modules/.pnpm/negotiator@1.0.0/node_modules/negotiator/lib/charset.js /** * negotiator * Copyright(c) 2012 Isaac Z. Schlueter * Copyright(c) 2014 Federico Romero * Copyright(c) 2014-2015 Douglas Christopher Wilson * MIT Licensed */ var require_charset = /* @__PURE__ */ __commonJSMin(((exports, module) => { /** * Module exports. * @public */ module.exports = preferredCharsets; module.exports.preferredCharsets = preferredCharsets; /** * Module variables. * @private */ var simpleCharsetRegExp = /^\s*([^\s;]+)\s*(?:;(.*))?$/; /** * Parse the Accept-Charset header. * @private */ function parseAcceptCharset(accept) { var accepts = accept.split(","); for (var i = 0, j = 0; i < accepts.length; i++) { var charset = parseCharset(accepts[i].trim(), i); if (charset) accepts[j++] = charset; } accepts.length = j; return accepts; } /** * Parse a charset from the Accept-Charset header. * @private */ function parseCharset(str, i) { var match = simpleCharsetRegExp.exec(str); if (!match) return null; var charset = match[1]; var q = 1; if (match[2]) { var params = match[2].split(";"); for (var j = 0; j < params.length; j++) { var p = params[j].trim().split("="); if (p[0] === "q") { q = parseFloat(p[1]); break; } } } return { charset, q, i }; } /** * Get the priority of a charset. * @private */ function getCharsetPriority(charset, accepted, index) { var priority = { o: -1, q: 0, s: 0 }; for (var i = 0; i < accepted.length; i++) { var spec = specify(charset, accepted[i], index); if (spec && (priority.s - spec.s || priority.q - spec.q || priority.o - spec.o) < 0) priority = spec; } return priority; } /** * Get the specificity of the charset. * @private */ function specify(charset, spec, index) { var s = 0; if (spec.charset.toLowerCase() === charset.toLowerCase()) s |= 1; else if (spec.charset !== "*") return null; return { i: index, o: spec.i, q: spec.q, s }; } /** * Get the preferred charsets from an Accept-Charset header. * @public */ function preferredCharsets(accept, provided) { var accepts = parseAcceptCharset(accept === void 0 ? "*" : accept || ""); if (!provided) return accepts.filter(isQuality).sort(compareSpecs).map(getFullCharset); var priorities = provided.map(function getPriority(type, index) { return getCharsetPriority(type, accepts, index); }); return priorities.filter(isQuality).sort(compareSpecs).map(function getCharset(priority) { return provided[priorities.indexOf(priority)]; }); } /** * Compare two specs. * @private */ function compareSpecs(a, b) { return b.q - a.q || b.s - a.s || a.o - b.o || a.i - b.i || 0; } /** * Get full charset string. * @private */ function getFullCharset(spec) { return spec.charset; } /** * Check if a spec has any quality. * @private */ function isQuality(spec) { return spec.q > 0; } })); //#endregion //#region ../../node_modules/.pnpm/negotiator@1.0.0/node_modules/negotiator/lib/encoding.js /** * negotiator * Copyright(c) 2012 Isaac Z. Schlueter * Copyright(c) 2014 Federico Romero * Copyright(c) 2014-2015 Douglas Christopher Wilson * MIT Licensed */ var require_encoding = /* @__PURE__ */ __commonJSMin(((exports, module) => { /** * Module exports. * @public */ module.exports = preferredEncodings; module.exports.preferredEncodings = preferredEncodings; /** * Module variables. * @private */ var simpleEncodingRegExp = /^\s*([^\s;]+)\s*(?:;(.*))?$/; /** * Parse the Accept-Encoding header. * @private */ function parseAcceptEncoding(accept) { var accepts = accept.split(","); var hasIdentity = false; var minQuality = 1; for (var i = 0, j = 0; i < accepts.length; i++) { var encoding = parseEncoding(accepts[i].trim(), i); if (encoding) { accepts[j++] = encoding; hasIdentity = hasIdentity || specify("identity", encoding); minQuality = Math.min(minQuality, encoding.q || 1); } } if (!hasIdentity) accepts[j++] = { encoding: "identity", q: minQuality, i }; accepts.length = j; return accepts; } /** * Parse an encoding from the Accept-Encoding header. * @private */ function parseEncoding(str, i) { var match = simpleEncodingRegExp.exec(str); if (!match) return null; var encoding = match[1]; var q = 1; if (match[2]) { var params = match[2].split(";"); for (var j = 0; j < params.length; j++) { var p = params[j].trim().split("="); if (p[0] === "q") { q = parseFloat(p[1]); break; } } } return { encoding, q, i }; } /** * Get the priority of an encoding. * @private */ function getEncodingPriority(encoding, accepted, index) { var priority = { encoding, o: -1, q: 0, s: 0 }; for (var i = 0; i < accepted.length; i++) { var spec = specify(encoding, accepted[i], index); if (spec && (priority.s - spec.s || priority.q - spec.q || priority.o - spec.o) < 0) priority = spec; } return priority; } /** * Get the specificity of the encoding. * @private */ function specify(encoding, spec, index) { var s = 0; if (spec.encoding.toLowerCase() === encoding.toLowerCase()) s |= 1; else if (spec.encoding !== "*") return null; return { encoding, i: index, o: spec.i, q: spec.q, s }; } /** * Get the preferred encodings from an Accept-Encoding header. * @public */ function preferredEncodings(accept, provided, preferred) { var accepts = parseAcceptEncoding(accept || ""); var comparator = preferred ? function comparator(a, b) { if (a.q !== b.q) return b.q - a.q; var aPreferred = preferred.indexOf(a.encoding); var bPreferred = preferred.indexOf(b.encoding); if (aPreferred === -1 && bPreferred === -1) return b.s - a.s || a.o - b.o || a.i - b.i; if (aPreferred !== -1 && bPreferred !== -1) return aPreferred - bPreferred; return aPreferred === -1 ? 1 : -1; } : compareSpecs; if (!provided) return accepts.filter(isQuality).sort(comparator).map(getFullEncoding); var priorities = provided.map(function getPriority(type, index) { return getEncodingPriority(type, accepts, index); }); return priorities.filter(isQuality).sort(comparator).map(function getEncoding(priority) { return provided[priorities.indexOf(priority)]; }); } /** * Compare two specs. * @private */ function compareSpecs(a, b) { return b.q - a.q || b.s - a.s || a.o - b.o || a.i - b.i; } /** * Get full encoding string. * @private */ function getFullEncoding(spec) { return spec.encoding; } /** * Check if a spec has any quality. * @private */ function isQuality(spec) { return spec.q > 0; } })); //#endregion //#region ../../node_modules/.pnpm/negotiator@1.0.0/node_modules/negotiator/lib/language.js /** * negotiator * Copyright(c) 2012 Isaac Z. Schlueter * Copyright(c) 2014 Federico Romero * Copyright(c) 2014-2015 Douglas Christopher Wilson * MIT Licensed */ var require_language = /* @__PURE__ */ __commonJSMin(((exports, module) => { /** * Module exports. * @public */ module.exports = preferredLanguages; module.exports.preferredLanguages = preferredLanguages; /** * Module variables. * @private */ var simpleLanguageRegExp = /^\s*([^\s\-;]+)(?:-([^\s;]+))?\s*(?:;(.*))?$/; /** * Parse the Accept-Language header. * @private */ function parseAcceptLanguage(accept) { var accepts = accept.split(","); for (var i = 0, j = 0; i < accepts.length; i++) { var language = parseLanguage(accepts[i].trim(), i); if (language) accepts[j++] = language; } accepts.length = j; return accepts; } /** * Parse a language from the Accept-Language header. * @private */ function parseLanguage(str, i) { var match = simpleLanguageRegExp.exec(str); if (!match) return null; var prefix = match[1]; var suffix = match[2]; var full = prefix; if (suffix) full += "-" + suffix; var q = 1; if (match[3]) { var params = match[3].split(";"); for (var j = 0; j < params.length; j++) { var p = params[j].split("="); if (p[0] === "q") q = parseFloat(p[1]); } } return { prefix, suffix, q, i, full }; } /** * Get the priority of a language. * @private */ function getLanguagePriority(language, accepted, index) { var priority = { o: -1, q: 0, s: 0 }; for (var i = 0; i < accepted.length; i++) { var spec = specify(language, accepted[i], index); if (spec && (priority.s - spec.s || priority.q - spec.q || priority.o - spec.o) < 0) priority = spec; } return priority; } /** * Get the specificity of the language. * @private */ function specify(language, spec, index) { var p = parseLanguage(language); if (!p) return null; var s = 0; if (spec.full.toLowerCase() === p.full.toLowerCase()) s |= 4; else if (spec.prefix.toLowerCase() === p.full.toLowerCase()) s |= 2; else if (spec.full.toLowerCase() === p.prefix.toLowerCase()) s |= 1; else if (spec.full !== "*") return null; return { i: index, o: spec.i, q: spec.q, s }; } /** * Get the preferred languages from an Accept-Language header. * @public */ function preferredLanguages(accept, provided) { var accepts = parseAcceptLanguage(accept === void 0 ? "*" : accept || ""); if (!provided) return accepts.filter(isQuality).sort(compareSpecs).map(getFullLanguage); var priorities = provided.map(function getPriority(type, index) { return getLanguagePriority(type, accepts, index); }); return priorities.filter(isQuality).sort(compareSpecs).map(function getLanguage(priority) { return provided[priorities.indexOf(priority)]; }); } /** * Compare two specs. * @private */ function compareSpecs(a, b) { return b.q - a.q || b.s - a.s || a.o - b.o || a.i - b.i || 0; } /** * Get full language string. * @private */ function getFullLanguage(spec) { return spec.full; } /** * Check if a spec has any quality. * @private */ function isQuality(spec) { return spec.q > 0; } })); //#endregion //#region ../../node_modules/.pnpm/negotiator@1.0.0/node_modules/negotiator/lib/mediaType.js /** * negotiator * Copyright(c) 2012 Isaac Z. Schlueter * Copyright(c) 2014 Federico Romero * Copyright(c) 2014-2015 Douglas Christopher Wilson * MIT Licensed */ var require_mediaType = /* @__PURE__ */ __commonJSMin(((exports, module) => { /** * Module exports. * @public */ module.exports = preferredMediaTypes; module.exports.preferredMediaTypes = preferredMediaTypes; /** * Module variables. * @private */ var simpleMediaTypeRegExp = /^\s*([^\s\/;]+)\/([^;\s]+)\s*(?:;(.*))?$/; /** * Parse the Accept header. * @private */ function parseAccept(accept) { var accepts = splitMediaTypes(accept); for (var i = 0, j = 0; i < accepts.length; i++) { var mediaType = parseMediaType(accepts[i].trim(), i); if (mediaType) accepts[j++] = mediaType; } accepts.length = j; return accepts; } /** * Parse a media type from the Accept header. * @private */ function parseMediaType(str, i) { var match = simpleMediaTypeRegExp.exec(str); if (!match) return null; var params = Object.create(null); var q = 1; var subtype = match[2]; var type = match[1]; if (match[3]) { var kvps = splitParameters(match[3]).map(splitKeyValuePair); for (var j = 0; j < kvps.length; j++) { var pair = kvps[j]; var key = pair[0].toLowerCase(); var val = pair[1]; var value = val && val[0] === "\"" && val[val.length - 1] === "\"" ? val.slice(1, -1) : val; if (key === "q") { q = parseFloat(value); break; } params[key] = value; } } return { type, subtype, params, q, i }; } /** * Get the priority of a media type. * @private */ function getMediaTypePriority(type, accepted, index) { var priority = { o: -1, q: 0, s: 0 }; for (var i = 0; i < accepted.length; i++) { var spec = specify(type, accepted[i], index); if (spec && (priority.s - spec.s || priority.q - spec.q || priority.o - spec.o) < 0) priority = spec; } return priority; } /** * Get the specificity of the media type. * @private */ function specify(type, spec, index) { var p = parseMediaType(type); var s = 0; if (!p) return null; if (spec.type.toLowerCase() == p.type.toLowerCase()) s |= 4; else if (spec.type != "*") return null; if (spec.subtype.toLowerCase() == p.subtype.toLowerCase()) s |= 2; else if (spec.subtype != "*") return null; var keys = Object.keys(spec.params); if (keys.length > 0) if (keys.every(function(k) { return spec.params[k] == "*" || (spec.params[k] || "").toLowerCase() == (p.params[k] || "").toLowerCase(); })) s |= 1; else return null; return { i: index, o: spec.i, q: spec.q, s }; } /** * Get the preferred media types from an Accept header. * @public */ function preferredMediaTypes(accept, provided) { var accepts = parseAccept(accept === void 0 ? "*/*" : accept || ""); if (!provided) return accepts.filter(isQuality).sort(compareSpecs).map(getFullType); var priorities = provided.map(function getPriority(type, index) { return getMediaTypePriority(type, accepts, index); }); return priorities.filter(isQuality).sort(compareSpecs).map(function getType(priority) { return provided[priorities.indexOf(priority)]; }); } /** * Compare two specs. * @private */ function compareSpecs(a, b) { return b.q - a.q || b.s - a.s || a.o - b.o || a.i - b.i || 0; } /** * Get full type string. * @private */ function getFullType(spec) { return spec.type + "/" + spec.subtype; } /** * Check if a spec has any quality. * @private */ function isQuality(spec) { return spec.q > 0; } /** * Count the number of quotes in a string. * @private */ function quoteCount(string) { var count = 0; var index = 0; while ((index = string.indexOf("\"", index)) !== -1) { count++; index++; } return count; } /** * Split a key value pair. * @private */ function splitKeyValuePair(str) { var index = str.indexOf("="); var key; var val; if (index === -1) key = str; else { key = str.slice(0, index); val = str.slice(index + 1); } return [key, val]; } /** * Split an Accept header into media types. * @private */ function splitMediaTypes(accept) { var accepts = accept.split(","); for (var i = 1, j = 0; i < accepts.length; i++) if (quoteCount(accepts[j]) % 2 == 0) accepts[++j] = accepts[i]; else accepts[j] += "," + accepts[i]; accepts.length = j + 1; return accepts; } /** * Split a string of parameters. * @private */ function splitParameters(str) { var parameters = str.split(";"); for (var i = 1, j = 0; i < parameters.length; i++) if (quoteCount(parameters[j]) % 2 == 0) parameters[++j] = parameters[i]; else parameters[j] += ";" + parameters[i]; parameters.length = j + 1; for (var i = 0; i < parameters.length; i++) parameters[i] = parameters[i].trim(); return parameters; } })); //#endregion //#region ../../node_modules/.pnpm/negotiator@1.0.0/node_modules/negotiator/index.js /*! * negotiator * Copyright(c) 2012 Federico Romero * Copyright(c) 2012-2014 Isaac Z. Schlueter * Copyright(c) 2015 Douglas Christopher Wilson * MIT Licensed */ var require_negotiator = /* @__PURE__ */ __commonJSMin(((exports, module) => { var preferredCharsets = require_charset(); var preferredEncodings = require_encoding(); var preferredLanguages = require_language(); var preferredMediaTypes = require_mediaType(); /** * Module exports. * @public */ module.exports = Negotiator; module.exports.Negotiator = Negotiator; /** * Create a Negotiator instance from a request. * @param {object} request * @public */ function Negotiator(request) { if (!(this instanceof Negotiator)) return new Negotiator(request); this.request = request; } Negotiator.prototype.charset = function charset(available) { var set = this.charsets(available); return set && set[0]; }; Negotiator.prototype.charsets = function charsets(available) { return preferredCharsets(this.request.headers["accept-charset"], available); }; Negotiator.prototype.encoding = function encoding(available, opts) { var set = this.encodings(available, opts); return set && set[0]; }; Negotiator.prototype.encodings = function encodings(available, options) { var opts = options || {}; return preferredEncodings(this.request.headers["accept-encoding"], available, opts.preferred); }; Negotiator.prototype.language = function language(available) { var set = this.languages(available); return set && set[0]; }; Negotiator.prototype.languages = function languages(available) { return preferredLanguages(this.request.headers["accept-language"], available); }; Negotiator.prototype.mediaType = function mediaType(available) { var set = this.mediaTypes(available); return set && set[0]; }; Negotiator.prototype.mediaTypes = function mediaTypes(available) { return preferredMediaTypes(this.request.headers.accept, available); }; Negotiator.prototype.preferredCharset = Negotiator.prototype.charset; Negotiator.prototype.preferredCharsets = Negotiator.prototype.charsets; Negotiator.prototype.preferredEncoding = Negotiator.prototype.encoding; Negotiator.prototype.preferredEncodings = Negotiator.prototype.encodings; Negotiator.prototype.preferredLanguage = Negotiator.prototype.language; Negotiator.prototype.preferredLanguages = Negotiator.prototype.languages; Negotiator.prototype.preferredMediaType = Negotiator.prototype.mediaType; Negotiator.prototype.preferredMediaTypes = Negotiator.prototype.mediaTypes; })); //#endregion //#region ../../node_modules/.pnpm/path-to-regexp@8.4.2/node_modules/path-to-regexp/dist/index.js var require_dist = /* @__PURE__ */ __commonJSMin(((exports) => { Object.defineProperty(exports, "__esModule", { value: true }); exports.PathError = exports.TokenData = void 0; exports.compile = compile; exports.match = match; const DEFAULT_DELIMITER = "/"; const NOOP_VALUE = (value) => value; const ID_START = /^[$_\p{ID_Start}]$/u; const ID_CONTINUE = /^[$\u200c\u200d\p{ID_Continue}]$/u; /** * Escape a regular expression string. */ function escape(str) { return str.replace(/[.+*?^${}()[\]|/\\]/g, "\\$&"); } /** * Tokenized path instance. */ var TokenData = class { constructor(tokens, originalPath) { this.tokens = tokens; this.originalPath = originalPath; } }; exports.TokenData = TokenData; /** * ParseError is thrown when there is an error processing the path. */ var PathError = class extends TypeError { constructor(message, originalPath) { let text = message; if (originalPath) text += `: ${originalPath}`; text += `; visit https://git.new/pathToRegexpError for info`; super(text); this.originalPath = originalPath; } }; exports.PathError = PathError; /** * Parse a string for the raw tokens. */ function parse(str, options = {}) { const { encodePath = NOOP_VALUE } = options; const chars = [...str]; let index = 0; function consumeUntil(end) { const output = []; let path = ""; function writePath() { if (!path) return; output.push({ type: "text", value: encodePath(path) }); path = ""; } while (index < chars.length) { const value = chars[index++]; if (value === end) { writePath(); return output; } if (value === "\\") { if (index === chars.length) throw new PathError(`Unexpected end after \\ at index ${index}`, str); path += chars[index++]; continue; } if (value === ":" || value === "*") { const type = value === ":" ? "param" : "wildcard"; let name = ""; if (ID_START.test(chars[index])) do name += chars[index++]; while (ID_CONTINUE.test(chars[index])); else if (chars[index] === "\"") { let quoteStart = index; while (index < chars.length) { if (chars[++index] === "\"") { index++; quoteStart = 0; break; } if (chars[index] === "\\") index++; name += chars[index]; } if (quoteStart) throw new PathError(`Unterminated quote at index ${quoteStart}`, str); } if (!name) throw new PathError(`Missing parameter name at index ${index}`, str); writePath(); output.push({ type, name }); continue; } if (value === "{") { writePath(); output.push({ type: "group", tokens: consumeUntil("}") }); continue; } if (value === "}" || value === "(" || value === ")" || value === "[" || value === "]" || value === "+" || value === "?" || value === "!") throw new PathError(`Unexpected ${value} at index ${index - 1}`, str); path += value; } if (end) throw new PathError(`Unexpected end at index ${index}, expected ${end}`, str); writePath(); return output; } return new TokenData(consumeUntil(""), str); } /** * Compile a string to a template function for the path. */ function compile(path, options = {}) { const { encode = encodeURIComponent, delimiter = DEFAULT_DELIMITER } = options; const fn = tokensToFunction((typeof path === "object" ? path : parse(path, options)).tokens, delimiter, encode); return function path(params = {}) { const missing = []; const path = fn(params, missing); if (missing.length) throw new TypeError(`Missing parameters: ${missing.join(", ")}`); return path; }; } function tokensToFunction(tokens, delimiter, encode) { const encoders = tokens.map((token) => tokenToFunction(token, delimiter, encode)); return (data, missing) => { let result = ""; for (const encoder of encoders) result += encoder(data, missing); return result; }; } /** * Convert a single token into a path building function. */ function tokenToFunction(token, delimiter, encode) { if (token.type === "text") return () => token.value; if (token.type === "group") { const fn = tokensToFunction(token.tokens, delimiter, encode); return (data, missing) => { const len = missing.length; const value = fn(data, missing); if (missing.length === len) return value; missing.length = len; return ""; }; } const encodeValue = encode || NOOP_VALUE; if (token.type === "wildcard" && encode !== false) return (data, missing) => { const value = data[token.name]; if (value == null) { missing.push(token.name); return ""; } if (!Array.isArray(value) || value.length === 0) throw new TypeError(`Expected "${token.name}" to be a non-empty array`); let result = ""; for (let i = 0; i < value.length; i++) { if (typeof value[i] !== "string") throw new TypeError(`Expected "${token.name}/${i}" to be a string`); if (i > 0) result += delimiter; result += encodeValue(value[i]); } return result; }; return (data, missing) => { const value = data[token.name]; if (value == null) { missing.push(token.name); return ""; } if (typeof value !== "string") throw new TypeError(`Expected "${token.name}" to be a string`); return encodeValue(value); }; } /** * Transform a path into a match function. */ function match(path, options = {}) { const { decode = decodeURIComponent, delimiter = DEFAULT_DELIMITER } = options; const { regexp, keys } = pathToRegexp(path, options); const decoders = keys.map((key) => { if (decode === false) return NOOP_VALUE; if (key.type === "param") return decode; return (value) => value.split(delimiter).map(decode); }); return function match(input) { const m = regexp.exec(input); if (!m) return false; const path = m[0]; const params = Object.create(null); for (let i = 1; i < m.length; i++) { if (m[i] === void 0) continue; const key = keys[i - 1]; const decoder = decoders[i - 1]; params[key.name] = decoder(m[i]); } return { path, params }; }; } /** * Transform a path into a regular expression and capture keys. */ function pathToRegexp(path, options = {}) { const { delimiter = DEFAULT_DELIMITER, end = true, sensitive = false, trailing = true } = options; const keys = []; let source = ""; let combinations = 0; function process(path) { if (Array.isArray(path)) { for (const p of path) process(p); return; } const data = typeof path === "object" ? path : parse(path, options); flatten(data.tokens, 0, [], (tokens) => { if (combinations >= 256) throw new PathError("Too many path combinations", data.originalPath); if (combinations > 0) source += "|"; source += toRegExpSource(tokens, delimiter, keys, data.originalPath); combinations++; }); } process(path); let pattern = `^(?:${source})`; if (trailing) pattern += "(?:" + escape(delimiter) + "$)?"; pattern += end ? "$" : "(?=" + escape(delimiter) + "|$)"; return { regexp: new RegExp(pattern, sensitive ? "" : "i"), keys }; } /** * Generate a flat list of sequence tokens from the given tokens. */ function flatten(tokens, index, result, callback) { while (index < tokens.length) { const token = tokens[index++]; if (token.type === "group") { const len = result.length; flatten(token.tokens, 0, result, (seq) => flatten(tokens, index, seq, callback)); result.length = len; continue; } result.push(token); } callback(result); } /** * Transform a flat sequence of tokens into a regular expression. */ function toRegExpSource(tokens, delimiter, keys, originalPath) { let result = ""; let backtrack = ""; let wildcardBacktrack = ""; let prevCaptureType = 0; let hasSegmentCapture = 0; let index = 0; function hasInSegment(index, type) { while (index < tokens.length) { const token = tokens[index++]; if (token.type === type) return true; if (token.type === "text") { if (token.value.includes(delimiter)) break; } } return false; } function peekText(index) { let result = ""; while (index < tokens.length) { const token = tokens[index++]; if (token.type !== "text") break; result += token.value; } return result; } while (index < tokens.length) { const token = tokens[index++]; if (token.type === "text") { result += escape(token.value); backtrack += token.value; if (prevCaptureType === 2) wildcardBacktrack += token.value; if (token.value.includes(delimiter)) hasSegmentCapture = 0; continue; } if (token.type === "param" || token.type === "wildcard") { if (prevCaptureType && !backtrack) throw new PathError(`Missing text before "${token.name}" ${token.type}`, originalPath); if (token.type === "param") { result += hasSegmentCapture & 2 ? `(${negate(delimiter, backtrack)}+)` : hasInSegment(index, "wildcard") ? `(${negate(delimiter, peekText(index))}+)` : hasSegmentCapture & 1 ? `(${negate(delimiter, backtrack)}+|${escape(backtrack)})` : `(${negate(delimiter, "")}+)`; hasSegmentCapture |= prevCaptureType = 1; } else { result += hasSegmentCapture & 2 ? `(${negate(backtrack, "")}+)` : wildcardBacktrack ? `(${negate(wildcardBacktrack, "")}+|${negate(delimiter, "")}+)` : `([^]+)`; wildcardBacktrack = ""; hasSegmentCapture |= prevCaptureType = 2; } keys.push(token); backtrack = ""; continue; } throw new TypeError(`Unknown token type: ${token.type}`); } return result; } /** * Block backtracking on previous text/delimiter. */ function negate(a, b) { if (b.length > a.length) return negate(b, a); if (a === b) b = ""; if (b.length > 1) return `(?:(?!${escape(a)}|${escape(b)})[^])`; if (a.length > 1) return `(?:(?!${escape(a)})[^${escape(b)}])`; return `[^${escape(a + b)}]`; } })); //#endregion //#region src/negotiation/index.ts var import_negotiator = /* @__PURE__ */ __toESM(require_negotiator(), 1); var import_dist = require_dist(); function getNegotiator(request) { const headers = {}; request.headers.forEach((value, key) => { headers[key] = value; }); return new import_negotiator.default({ headers }); } /** * Rewrite incoming path matching the `source` pattern into the `destination` pattern. * * See [`path-to-regexp`](https://github.com/pillarjs/path-to-regexp) for accepted pattern formats. * * @param source - the original pattern of incoming paths * @param destination - the target pattern to convert into */ function rewritePath(source, destination) { const matcher = (0, import_dist.match)(source, { decode: false }); const compiler = (0, import_dist.compile)(destination, { encode: false }); return { rewrite(pathname) { const result = matcher(pathname); if (!result) return false; return compiler(result.params); } }; } function isMarkdownPreferred(request, options) { const { markdownMediaTypes = [ "text/plain", "text/markdown", "text/x-markdown" ] } = options ?? {}; const mediaTypes = getNegotiator(request).mediaTypes(); return markdownMediaTypes.some((type) => mediaTypes.includes(type)); } //#endregion export { isMarkdownPreferred as n, rewritePath as r, getNegotiator as t };