diff --git a/.eslintignore b/.eslintignore index 8ab4750abd1685..bc0bd623b50c06 100644 --- a/.eslintignore +++ b/.eslintignore @@ -6,5 +6,4 @@ test/message/esm_display_syntax_error.mjs tools/icu tools/lint-md/lint-md.mjs benchmark/tmp -doc/**/*.js !.eslintrc.js diff --git a/doc/api_assets/script.js b/doc/api_assets/script.js new file mode 100644 index 00000000000000..ae3078437e0670 --- /dev/null +++ b/doc/api_assets/script.js @@ -0,0 +1,61 @@ +'use strict'; + +{ + const eqIsh = (a, b, fuzz = 2) => { + return (Math.abs(a - b) <= fuzz); + }; + + const rectNotEQ = (a, b) => { + return (!eqIsh(a.width, b.width) || + !eqIsh(a.height, b.height)); + }; + + const spaced = new WeakMap(); + + const reserveSpace = (el, rect = el.getClientBoundingRect()) => { + const old = spaced.get(el); + if (!old || rectNotEQ(old, rect)) { + spaced.set(el, rect); + el.attributeStyleMap.set( + 'contain-intrinsic-size', + `${rect.width}px ${rect.height}px` + ); + } + }; + + const iObs = new IntersectionObserver( + (entries, o) => { + entries.forEach((entry) => { + + reserveSpace(entry.target, + entry.boundingClientRect); + }); + }, + { rootMargin: '500px 0px 500px 0px' } + ); + + const rObs = new ResizeObserver( + (entries, o) => { + entries.forEach((entry) => { + reserveSpace(entry.target, entry.contentRect); + }); + } + ); + + const articles = + document.querySelectorAll('#apicontent>section'); + + articles.forEach((el) => { + iObs.observe(el); + rObs.observe(el); + }); + + requestAnimationFrame(() => { + requestAnimationFrame(() => { + articles[0].attributeStyleMap.set( + 'content-visibility', + 'auto' + ); + }); + }); +} diff --git a/doc/template.html b/doc/template.html index 5e70b6054e080b..9f6c9dcf3730da 100644 --- a/doc/template.html +++ b/doc/template.html @@ -9,6 +9,7 @@ +