Merged features tied to Scotch Bonnet funding goal

This commit is contained in:
squidfunk
2022-09-13 12:35:14 +02:00
parent 6b001c8fa2
commit 419740831d
66 changed files with 1619 additions and 363 deletions

View File

@@ -34,8 +34,6 @@ import {
mergeWith,
switchMap,
take,
takeLast,
takeUntil,
tap
} from "rxjs"
@@ -72,6 +70,7 @@ export interface CodeBlock {
* Mount options
*/
interface MountOptions {
target$: Observable<HTMLElement> /* Location target observable */
print$: Observable<boolean> /* Media print observable */
}
@@ -80,7 +79,7 @@ interface MountOptions {
* ------------------------------------------------------------------------- */
/**
* Global sequence number for Clipboard.js integration
* Global sequence number for code blocks
*/
let sequence = 0
@@ -147,6 +146,11 @@ export function watchCodeBlock(
* Furthermore, if code annotations are enabled, they are mounted if and only
* if the code block is currently visible, e.g., not in a hidden content tab.
*
* Note that code blocks may be mounted eagerly or lazily. If they're mounted
* lazily (on first visibility), code annotation anchor links will not work,
* as they are evaluated on initial page load, and code annotations in general
* might feel a little bumpier.
*
* @param el - Code block element
* @param options - Options
*
@@ -198,7 +202,6 @@ export function mountCodeBlock(
mergeWith(
watchElementSize(container)
.pipe(
takeUntil(push$.pipe(takeLast(1))),
map(({ width, height }) => width && height),
distinctUntilChanged(),
switchMap(active => active ? annotations$ : EMPTY)
@@ -217,11 +220,15 @@ export function mountCodeBlock(
)
})
/* Mount code block on first sight */
return watchElementVisibility(el)
.pipe(
filter(visible => visible),
take(1),
switchMap(() => factory$)
)
/* Mount code block lazily */
if (feature("content.lazy"))
return watchElementVisibility(el)
.pipe(
filter(visible => visible),
take(1),
switchMap(() => factory$)
)
/* Mount code block */
return factory$
}