Skip to content

Build your personal knowledge base with Trilium Notes

client/icon pack/preview: limit the count glyphs rendered in non-interactive mode

Adorian Doran82eb34eafb40
diff --git a/apps/client/src/widgets/type_widgets/icon_pack/IconPackPreview.tsx b/apps/client/src/widgets/type_widgets/icon_pack/IconPackPreview.tsx
index 56cb3a2baa..6838f1abb5 100644
--- a/apps/client/src/widgets/type_widgets/icon_pack/IconPackPreview.tsx
+++ b/apps/client/src/widgets/type_widgets/icon_pack/IconPackPreview.tsx
@@ -13,6 +13,10 @@ import previewStylesheet from "./icon_pack_preview.css?raw";
/** How long to wait after the last edit before re-parsing and re-rendering the (potentially large) preview. */
const PREVIEW_DEBOUNCE_MS = 1500;
+/** In non-interactive previews (collection tiles) only this many glyphs are rendered to stay lightweight;
+ * the count line still reports the true total. */
+const NON_INTERACTIVE_ICON_LIMIT = 250;
+
/** Theme variables forwarded into the isolated preview frame so it matches the app's colours. */
const PREVIEW_CSS_VARS = [
"--main-text-color",
@@ -57,10 +61,13 @@ export function IconPackPreview({ note, content, interactive = true }: IconPackP
return <div className="icon-pack-preview"><NoItems icon="bx bx-images" text={t("icon_pack.no_icons")} /></div>;
}
+ // Keep read-only tiles cheap by rendering only a capped sample; the count line still shows the true total.
+ const visibleIcons = interactive ? parsed.icons : parsed.icons.slice(0, NON_INTERACTIVE_ICON_LIMIT);
+
return (
<IsolatedFrame className="icon-pack-frame" title={t("icon_pack.preview_title")} css={css} cssVars={PREVIEW_CSS_VARS}>
<div className={interactive ? "ip-grid interactive" : "ip-grid"}>
- {parsed.icons.map((icon) => (
+ {visibleIcons.map((icon) => (
<div className="ip-cell" key={icon.id} title={interactive ? iconTooltip(prefix, icon) : undefined}>
<span className="ip-glyph">{icon.glyph}</span>
</div>
diff --git a/apps/client/src/widgets/type_widgets/icon_pack/icon_pack_preview.css b/apps/client/src/widgets/type_widgets/icon_pack/icon_pack_preview.css
index 6ef9d8bc76..dd1e6deaa9 100644
--- a/apps/client/src/widgets/type_widgets/icon_pack/icon_pack_preview.css
+++ b/apps/client/src/widgets/type_widgets/icon_pack/icon_pack_preview.css
@@ -12,26 +12,42 @@ body {
margin: 0;
height: 100%;
user-select: none;
+ overflow: hidden;
}
+html:has(.ip-grid.interactive),
+body:has(.ip-grid.interactive) {
+ overflow: auto;
+}
+
+
body {
color: var(--main-text-color, #000);
background: var(--main-background-color, #fff);
padding: 8px;
box-sizing: border-box;
- overflow: auto;
+ /* Read-only previews (collection tiles) are clipped, not scrollable — see the interactive override below. */
}
+
.ip-grid {
+ --icon-size: 24px;
+ --icon-size-ratio: .85;
+
display: grid;
- grid-template-columns: repeat(auto-fill, 48px);
+ grid-template-columns: repeat(auto-fill, var(--icon-size));
gap: 8px;
justify-content: start;
}
+.ip-grid.ip-grid.interactive {
+ --icon-size-ratio: .75;
+ --icon-size: 48px;
+}
+
.ip-cell {
- width: 48px;
- height: 48px;
+ width: var(--icon-size);
+ height: var(--icon-size);
display: flex;
align-items: center;
justify-content: center;
@@ -39,7 +55,7 @@ body {
cursor: default;
/* Skip layout/paint for off-screen cells so large packs stay responsive. */
content-visibility: auto;
- contain-intrinsic-size: 48px 48px;
+ contain-intrinsic-size: var(--icon-size) var(--icon-size);
}
/* Hover highlight only in interactive mode (off for read-only content-renderer previews). */
@@ -53,7 +69,7 @@ body {
.ip-glyph {
font-family: "tn-icon-pack-preview";
- font-size: 32px;
+ font-size: calc(var(--icon-size) * var(--icon-size-ratio));
line-height: 1;
}