2023-10-22 19:42:03 +00:00
|
|
|
|
/*
|
|
|
|
|
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
|
|
|
|
|
*/
|
|
|
|
|
|
2023-03-12 13:40:56 +00:00
|
|
|
|
// helps with some corner cases where <wbr> starts working already,
|
|
|
|
|
// but the signature is not yet long enough to be wrapped
|
2023-10-22 19:42:03 +00:00
|
|
|
|
(function() {
|
|
|
|
|
const leftPaddingPx = 60;
|
2023-03-12 13:40:56 +00:00
|
|
|
|
|
2023-10-22 19:42:03 +00:00
|
|
|
|
function createNbspIndent() {
|
|
|
|
|
let indent = document.createElement("span");
|
|
|
|
|
indent.append(document.createTextNode("\u00A0\u00A0\u00A0\u00A0"));
|
|
|
|
|
indent.classList.add("nbsp-indent");
|
|
|
|
|
return indent;
|
2023-03-12 13:40:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-22 19:42:03 +00:00
|
|
|
|
function wrapSymbolParameters(entry) {
|
|
|
|
|
const symbol = entry.target;
|
|
|
|
|
const symbolBlockWidth = entry.borderBoxSize && entry.borderBoxSize[0] && entry.borderBoxSize[0].inlineSize;
|
2023-03-12 13:40:56 +00:00
|
|
|
|
|
2023-10-22 19:42:03 +00:00
|
|
|
|
// Even though the script is marked as `defer` and we wait for `DOMContentLoaded` event,
|
|
|
|
|
// or if this block is a part of hidden tab, it can happen that `symbolBlockWidth` is 0,
|
|
|
|
|
// indicating that something hasn't been loaded.
|
|
|
|
|
// In this case, observer will be triggered onсe again when it will be ready.
|
|
|
|
|
if (symbolBlockWidth > 0) {
|
|
|
|
|
const node = symbol.querySelector(".parameters");
|
2023-03-12 13:40:56 +00:00
|
|
|
|
|
2023-10-22 19:42:03 +00:00
|
|
|
|
if (node) {
|
|
|
|
|
// if window resize happened and observer was triggered, reset previously wrapped
|
|
|
|
|
// parameters as they might not need wrapping anymore, and check again
|
|
|
|
|
node.classList.remove("wrapped");
|
|
|
|
|
node.querySelectorAll(".parameter .nbsp-indent")
|
|
|
|
|
.forEach(indent => indent.remove());
|
2023-03-12 13:40:56 +00:00
|
|
|
|
|
2023-10-22 19:42:03 +00:00
|
|
|
|
const innerTextWidth = Array.from(symbol.children)
|
|
|
|
|
.filter(it => !it.classList.contains("block")) // blocks are usually on their own (like annotations), so ignore it
|
|
|
|
|
.map(it => it.getBoundingClientRect().width)
|
|
|
|
|
.reduce((a, b) => a + b, 0);
|
2023-03-12 13:40:56 +00:00
|
|
|
|
|
2023-10-22 19:42:03 +00:00
|
|
|
|
// if signature text takes up more than a single line, wrap params for readability
|
|
|
|
|
if (innerTextWidth > (symbolBlockWidth - leftPaddingPx)) {
|
|
|
|
|
node.classList.add("wrapped");
|
|
|
|
|
node.querySelectorAll(".parameter").forEach(param => {
|
|
|
|
|
// has to be a physical indent so that it can be copied. styles like
|
|
|
|
|
// paddings and `::before { content: " " }` do not work for that
|
|
|
|
|
param.prepend(createNbspIndent());
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-12 13:40:56 +00:00
|
|
|
|
|
2023-10-22 19:42:03 +00:00
|
|
|
|
const symbolsObserver = new ResizeObserver(entries => entries.forEach(wrapSymbolParameters));
|
2023-03-12 13:40:56 +00:00
|
|
|
|
|
2023-10-22 19:42:03 +00:00
|
|
|
|
function initHandlers() {
|
|
|
|
|
document.querySelectorAll("div.symbol").forEach(symbol => symbolsObserver.observe(symbol));
|
2023-03-12 13:40:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-22 19:42:03 +00:00
|
|
|
|
if (document.readyState === 'loading') window.addEventListener('DOMContentLoaded', initHandlers);
|
|
|
|
|
else initHandlers();
|
2023-03-12 13:40:56 +00:00
|
|
|
|
|
2023-10-22 19:42:03 +00:00
|
|
|
|
// ToDo: Add `unobserve` if dokka will be SPA-like:
|
|
|
|
|
// https://github.com/w3c/csswg-drafts/issues/5155
|
|
|
|
|
})();
|