mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
979d9a412d
* fix: Upgrade mermaid to 11.13.0 Includes a fix for incorrect viewBox casing in Radar and Packet diagram renderers (mermaid-js/mermaid#7076) and other improvements. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: Use visibility:hidden for mermaid rendering element Instead of positioning the temporary render element offscreen at -9999px, use visibility:hidden with position:fixed so the browser computes correct bounding boxes for SVG elements. Offscreen elements can produce incorrect getBBox() results, leading to wrong viewBox dimensions and diagrams rendering too big or too small. Fixes #11782 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Add session storage for generated diagrams to reduce relayout * fix: Use LRU eviction for mermaid sessionStorage cache Track access order via a dedicated LRU index key so the cache evicts least-recently-used entries rather than arbitrary ones. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
80 lines
1.9 KiB
TypeScript
80 lines
1.9 KiB
TypeScript
/**
|
|
* Simple string hash using the djb2 algorithm, returns a hex string.
|
|
*
|
|
* @param str the string to hash.
|
|
* @returns a hex-encoded 32-bit hash.
|
|
*/
|
|
export function hashString(str: string): string {
|
|
let hash = 5381;
|
|
for (let i = 0; i < str.length; i++) {
|
|
hash = ((hash << 5) + hash + str.charCodeAt(i)) | 0;
|
|
}
|
|
return (hash >>> 0).toString(16);
|
|
}
|
|
|
|
/**
|
|
* Returns the index of the first occurrence of a substring in a string that matches a regular expression.
|
|
*
|
|
* @param text The string to search in.
|
|
* @param re The regular expression to search for.
|
|
* @param startPos The position in the string at which to begin the search. Defaults to 0.
|
|
*/
|
|
export const regexIndexOf = function (
|
|
text: string,
|
|
re: RegExp,
|
|
startPos?: number
|
|
) {
|
|
startPos = startPos || 0;
|
|
|
|
if (!re.global) {
|
|
const flags = "g" + (re.multiline ? "m" : "") + (re.ignoreCase ? "i" : "");
|
|
re = new RegExp(re.source, flags);
|
|
}
|
|
|
|
re.lastIndex = startPos;
|
|
const match = re.exec(text);
|
|
|
|
if (match) {
|
|
return match.index;
|
|
} else {
|
|
return -1;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Returns the index of the last occurrence of a substring in a string that matches a regular expression.
|
|
*
|
|
* @param text The string to search in.
|
|
* @param re The regular expression to search for.
|
|
* @param startPos The position in the string at which to begin the search. Defaults to the end of the string.
|
|
*/
|
|
export const regexLastIndexOf = function (
|
|
text: string,
|
|
re: RegExp,
|
|
startPos?: number
|
|
) {
|
|
startPos = startPos === undefined ? text.length : startPos;
|
|
|
|
if (!re.global) {
|
|
const flags = "g" + (re.multiline ? "m" : "") + (re.ignoreCase ? "i" : "");
|
|
re = new RegExp(re.source, flags);
|
|
}
|
|
|
|
let lastSuccess = -1;
|
|
for (let pos = 0; pos <= startPos; pos++) {
|
|
re.lastIndex = pos;
|
|
|
|
const match = re.exec(text);
|
|
if (!match) {
|
|
break;
|
|
}
|
|
|
|
pos = match.index;
|
|
if (pos <= startPos) {
|
|
lastSuccess = pos;
|
|
}
|
|
}
|
|
|
|
return lastSuccess;
|
|
};
|