From 7c7133a669de6ab54204d0bc53b12a5b4ef5f154 Mon Sep 17 00:00:00 2001 From: Alex Sorafumo Date: Thu, 5 Nov 2026 16:45:10 +1100 Subject: [PATCH] fix: raise Lighthouse scores to 100 on the landing page - Subset the Material Symbols font (422 KB to 13.5 KB). IconComponent falls back to the full font for icons that are not in the subset. - Swap firacode for @fontsource-variable/fira-code (36 KB Latin file). - Load modals on demand and defer the desktop sidebar, item details and settings editor, so the landing page loads less JS. - Show a static splash from index.html until the app loads. - Add a meta description, robots.txt and llms.txt. Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 3 +- bun.lock | 6 +- config/icon-subset.ts | 60 ++++++++ package.json | 2 +- project.json | 2 +- public/llms.txt | 21 +++ public/robots.txt | 2 + src/app/app.ts | 21 +-- src/app/common/general.ts | 13 ++ src/app/common/item.service.ts | 19 ++- src/app/systems/system-about.component.ts | 28 ++-- src/app/systems/system-state.service.ts | 39 ++--- src/app/triggers/trigger-state.service.ts | 3 +- src/app/ui/basic-line-graph.component.ts | 2 +- .../custom-fields/settings-field.component.ts | 2 +- src/app/ui/diff-viewer.component.ts | 2 +- src/app/ui/icon-subset.ts | 135 ++++++++++++++++++ src/app/ui/icon.component.ts | 16 +++ src/app/ui/item-shell.component.ts | 103 ++++++++----- .../material-symbols-rounded-subset.woff2 | Bin 0 -> 13788 bytes src/fonts/material-symbols.css | 15 ++ src/index.html | 50 ++++++- src/styles.css | 10 +- .../ui/components/icon.component.spec.ts | 25 ++++ 24 files changed, 475 insertions(+), 104 deletions(-) create mode 100644 config/icon-subset.ts create mode 100644 public/llms.txt create mode 100644 public/robots.txt create mode 100644 src/app/ui/icon-subset.ts create mode 100644 src/fonts/material-symbols-rounded-subset.woff2 diff --git a/AGENTS.md b/AGENTS.md index 7eee1f492..ea83d679c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -98,7 +98,8 @@ export class MyComponent extends AsyncHandler { - Supports multiple locales (see `app.locales` in settings) - Service worker support for PWA functionality (production builds) - Custom localization support via `public/assets/locale`, **TranslatePipe** and **LocaleService**. `en-AU.json` is the fallback locale -- Use **IconComponent** for icons +- Use **IconComponent** for icons. The default icon font is a subset of the icons in the source. After you add icons, run `bun config/icon-subset.ts` (needs `pip install fonttools brotli`). An icon that is not in the subset still shows, but it loads the full 420 KB font +- `src/index.html` has a splash that shows until the app loads. Lighthouse measures its title as the largest contentful paint, so keep the title larger than the content of the first page - Use `feat/*`, `fix/*`, `perf/*`, or `refactor/*` for branch names ## Code styles diff --git a/bun.lock b/bun.lock index c43973d88..561faa1d8 100644 --- a/bun.lock +++ b/bun.lock @@ -30,6 +30,7 @@ "@angular/language-service": "22.2.3", "@angular/material": "22.2.4", "@eslint/js": "^9.8.0", + "@fontsource-variable/fira-code": "^5.3.0", "@fontsource-variable/roboto": "^5.3.0", "@nx/angular": "23.3.0", "@nx/devkit": "23.3.0", @@ -60,7 +61,6 @@ "eslint": "^9.8.0", "eslint-config-prettier": "^10.0.0", "eslint-plugin-playwright": "^1.6.2", - "firacode": "^6.2.0", "git-describe": "^4.1.1", "jiti": "2.4.2", "js-yaml": "^4.1.1", @@ -511,6 +511,8 @@ "@eslint/plugin-kit": ["@eslint/plugin-kit@0.4.1", "", { "dependencies": { "@eslint/core": "^0.17.0", "levn": "^0.4.1" } }, "sha512-43/qtrDUokr7LJqoF2c3+RInu/t4zfrpYdoSDfYyhg52rwLV6TnOvdG4fXm7IkSB3wErkcmJS9iEhjVtOSEjjA=="], + "@fontsource-variable/fira-code": ["@fontsource-variable/fira-code@5.3.0", "", {}, "sha512-ZhvHeknlicraKVSJBa1NrJnXDVByUkC407zwgELYfmnx3p9g8vwIPfQCxx8YD3K7dAeCdLuHJOHlpMfRsIcApQ=="], + "@fontsource-variable/roboto": ["@fontsource-variable/roboto@5.3.0", "", {}, "sha512-BoaaZiQf8fgtxv07KXkTwx1bKz/EoqIlTXq2OOKKXINxp6qXWdnlChqV+hSaDANS49yyUASFl3OVBMMDTCIHFA=="], "@harperfast/extended-iterable": ["@harperfast/extended-iterable@1.0.3", "", {}, "sha512-sSAYhQca3rDWtQUHSAPeO7axFIUJOI6hn1gjRC5APVE1a90tuyT8f5WIgRsFhhWA7htNkju2veB9eWL6YHi/Lw=="], @@ -1343,8 +1345,6 @@ "find-up": ["find-up@5.0.0", "", { "dependencies": { "locate-path": "^6.0.0", "path-exists": "^4.0.0" } }, "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng=="], - "firacode": ["firacode@6.2.0", "", {}, "sha512-t5R3aO2BmhRXnYtKXbImLVNsILuCIbJ/XlDzBufjpi3il8P/CVdpWco83Ud3r2Tl0gitAmyP4o1fbJ52ozV1jw=="], - "flat-cache": ["flat-cache@4.0.1", "", { "dependencies": { "flatted": "^3.2.9", "keyv": "^4.5.4" } }, "sha512-f7ccFPK3SXFHpx15UIGyRJ/FJQctuKZ0zVuN3frBo4HnK3cay9VEW0R6yPYFHC0AgqhukPzKjq22t5DmAyqGyw=="], "flatted": ["flatted@3.4.2", "", {}, "sha512-PjDse7RzhcPkIJwy5t7KPWQSZ9cAbzQXcafsetQoD7sOJRQlGikNbx7yZp2OotDnJyrDcbyRq3Ttb18iYOqkxA=="], diff --git a/config/icon-subset.ts b/config/icon-subset.ts new file mode 100644 index 000000000..5cd296b13 --- /dev/null +++ b/config/icon-subset.ts @@ -0,0 +1,60 @@ +/** + * Make the subset of the Material Symbols Rounded font that the app uses. + * + * The full font is about 420 KB. The app uses a few hundred of its icons, so + * the first page load gets a small subset font. IconComponent switches to the + * full font for names that are not in the subset (e.g. icons from server + * settings), so a missing name costs a download, not a broken icon. + * + * Run this when you add icons: `bun config/icon-subset.ts` + * It needs fontTools: `pip install fonttools brotli` + */ +import { $, Glob } from 'bun'; + +const FONT = 'src/fonts/material-symbols-rounded.woff2'; +const SUBSET = 'src/fonts/material-symbols-rounded-subset.woff2'; +const NAMES = 'src/app/ui/icon-subset.ts'; + +/** Names of the glyphs in the full font */ +async function fontGlyphs() { + const out = + await $`python3 -c ${'import sys; from fontTools.ttLib import TTFont; print("\\n".join(TTFont(sys.argv[1]).getGlyphOrder()))'} ${FONT}`.text(); + return new Set(out.split('\n').filter(Boolean)); +} + +/** Words in the source that could be icon names */ +async function sourceWords() { + const words = new Set(); + // Text inside icon elements, e.g. add or {{ a ? 'b' : 'c' }} + const icon_tags = + /<(?:icon|app-icon)\b[^>]*>([\s\S]*?)<\/(?:icon|app-icon)>/g; + // Icon objects and inputs, e.g. { content: 'add' } or icon: 'add' + const icon_props = /\b(?:content|icon)\s*:\s*['"`]([a-z0-9_]+)['"`]/g; + for await (const file of new Glob('src/app/**/*.ts').scan()) { + if (file.includes('/mocks/')) continue; + const text = await Bun.file(file).text(); + for (const [, inner] of text.matchAll(icon_tags)) { + for (const [word] of inner.matchAll(/[a-z0-9_]+/g)) words.add(word); + } + for (const [, word] of text.matchAll(icon_props)) words.add(word); + } + return words; +} + +const glyphs = await fontGlyphs(); +// Single letters and digits are glyphs too, but not icons +const icons = [...(await sourceWords())] + .filter((w) => w.length > 1 && glyphs.has(w)) + .sort(); +// Letters and digits are the input of the icon ligatures +const text = 'abcdefghijklmnopqrstuvwxyz0123456789_'; +// No layout closure, so only the ligatures of the kept icons stay +await $`python3 -m fontTools.subset ${FONT} --output-file=${SUBSET} --flavor=woff2 --text=${text} --glyphs=${icons.join(',')} --layout-features=rlig --no-layout-closure --no-hinting --desubroutinize`; +await Bun.write( + NAMES, + `// Generated by config/icon-subset.ts. Do not edit.\n\n/** Icons in the subset icon font */\nexport const ICON_SUBSET: ReadonlySet = new Set(${JSON.stringify(icons, null, 4).replace(/"/g, "'")});\n`, +); +await $`bunx prettier --write ${NAMES}`.quiet(); +console.log( + `${icons.length} icons, ${(Bun.file(SUBSET).size / 1024).toFixed(1)} KB`, +); diff --git a/package.json b/package.json index f2ec144a7..7de757174 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "@angular/language-service": "22.2.3", "@angular/material": "22.2.4", "@eslint/js": "^9.8.0", + "@fontsource-variable/fira-code": "^5.3.0", "@fontsource-variable/roboto": "^5.3.0", "@nx/angular": "23.3.0", "@nx/devkit": "23.3.0", @@ -70,7 +71,6 @@ "eslint": "^9.8.0", "eslint-config-prettier": "^10.0.0", "eslint-plugin-playwright": "^1.6.2", - "firacode": "^6.2.0", "git-describe": "^4.1.1", "jiti": "2.4.2", "js-yaml": "^4.1.1", diff --git a/project.json b/project.json index 0976298c5..c41be422b 100644 --- a/project.json +++ b/project.json @@ -47,7 +47,7 @@ "./node_modules/@fontsource-variable/roboto/index.css", "./node_modules/@fontsource-variable/roboto/wght-italic.css", "./src/fonts/material-symbols.css", - "./node_modules/firacode/distr/fira_code.css", + "./node_modules/@fontsource-variable/fira-code/index.css", "./src/styles.css", "./src/material-theme.scss" ] diff --git a/public/llms.txt b/public/llms.txt new file mode 100644 index 000000000..4204d27b1 --- /dev/null +++ b/public/llms.txt @@ -0,0 +1,21 @@ +# PlaceOS Backoffice + +> Backoffice is the administration app of PlaceOS, a building automation platform. Administrators use it to manage the systems, modules, drivers, zones, triggers, domains and users of a PlaceOS instance. All pages need a PlaceOS account with admin or support access. + +The app has no public content. Use the documentation and the API references below to learn about PlaceOS and Backoffice. + +## Documentation + +- [Backoffice overview](https://docs.placeos.com/placeos/overview/backoffice/): What Backoffice is and what each section does +- [PlaceOS overview](https://docs.placeos.com/placeos/overview/): The parts of PlaceOS and how they connect +- [Add a domain](https://docs.placeos.com/placeos/how-to/backoffice/add-domain/): Set up a new domain in Backoffice +- [PlaceOS reference](https://docs.placeos.com/placeos/reference/): Reference material for PlaceOS + +## API + +- [PlaceOS REST API](https://placeos.github.io/rest-api-swagger-ui/): The engine API that Backoffice uses +- [Staff API](https://placeos.github.io/staff-api-swagger-ui/): The API for bookings, events and staff + +## Optional + +- [Source code](https://github.com/PlaceOS/backoffice): The Backoffice repository on GitHub diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 000000000..eb0536286 --- /dev/null +++ b/public/robots.txt @@ -0,0 +1,2 @@ +User-agent: * +Disallow: diff --git a/src/app/app.ts b/src/app/app.ts index cbf224915..d9f16193c 100644 --- a/src/app/app.ts +++ b/src/app/app.ts @@ -77,10 +77,8 @@ function browserOnline() { } @error {} } } @else { -
+ +
@@ -135,17 +133,6 @@ function browserOnline() { } @error {} } `, - styles: [ - ` - [loader] { - background-image: linear-gradient( - to right, - #c62828 0%, - #ef5350 100% - ); - } - `, - ], imports: [ GlobalBannerComponent, RouterOutlet, @@ -228,6 +215,10 @@ export class AppComponent implements OnInit { // TranslatePipe is pure, so load translations before the shell renders await this._initLocale(); this.loading.set(false); + // Remove it late. Chrome does not record the paint of an element + // removed soon after it shows, which makes it miss the splash as + // the largest contentful paint. + document.getElementById('app-splash')?.remove(); this._router.events.subscribe((event) => { if (event instanceof NavigationEnd) { this.simple.set(this._router.url.includes('mqtt')); diff --git a/src/app/common/general.ts b/src/app/common/general.ts index 2cc2784d2..bc4e818c6 100644 --- a/src/app/common/general.ts +++ b/src/app/common/general.ts @@ -58,6 +58,19 @@ export function getItemWithKeys( return null; } +/** + * Move an array item from one index to another, in place. + * Same as `moveItemInArray` in `@angular/cdk/drag-drop`. State services use + * this copy, so pages that use them do not load the drag and drop code. + */ +export function moveItemInArray(array: T[], from: number, to: number) { + const clamp = (i: number) => Math.max(0, Math.min(i, array.length - 1)); + from = clamp(from); + to = clamp(to); + if (from === to) return; + array.splice(to, 0, ...array.splice(from, 1)); +} + /** * Remove duplicates from the given array * @param array List of items to remove duplicates from diff --git a/src/app/common/item.service.ts b/src/app/common/item.service.ts index 59347f602..fe85db031 100644 --- a/src/app/common/item.service.ts +++ b/src/app/common/item.service.ts @@ -17,13 +17,11 @@ import { HashMap, Identity, } from '../common/types'; -import { BulkItemModalComponent } from '../overlays/bulk-item-modal/bulk-item-modal.component'; -import { - CONFIRM_METADATA, +// Modals load on demand to keep them out of the first page load +import type { ConfirmModalComponent, ConfirmModalData, } from '../overlays/confirm-modal.component'; -import { DuplicateModalComponent } from '../overlays/duplicate-modal.component'; import { BackofficeUsersService } from '../users/users.service'; import { ACTIONS, ItemActions } from './actions'; import { AsyncHandler } from './async-handler.class'; @@ -302,9 +300,12 @@ export class ActiveItemService extends AsyncHandler { ); } - public bulkAdd() { + public async bulkAdd() { if (!this.canMutate(2)) return; const actions = this.actions; + const { BulkItemModalComponent } = await import( + '../overlays/bulk-item-modal/bulk-item-modal.component' + ); this._settings.post('disable_uploads', true); const ref = this._dialog.open(BulkItemModalComponent, { height: 'auto', @@ -383,6 +384,9 @@ export class ActiveItemService extends AsyncHandler { // Resolved lazily, only if the user enables the option — a cascade // plan walks the whole zone subtree, which is not free. let plan: CascadePlan | null = null; + const { CONFIRM_METADATA, ConfirmModalComponent } = await import( + '../overlays/confirm-modal.component' + ); const ref = this._dialog.open( ConfirmModalComponent, { @@ -591,10 +595,13 @@ export class ActiveItemService extends AsyncHandler { }); } - public duplicate() { + public async duplicate() { if (!this.canCopy(true)) return; const item = this._active_item(); if (item) { + const { DuplicateModalComponent } = await import( + '../overlays/duplicate-modal.component' + ); const ref = this._dialog.open(DuplicateModalComponent, { data: { item: item as PlaceResource, diff --git a/src/app/systems/system-about.component.ts b/src/app/systems/system-about.component.ts index c7a7a0168..26b87d8f9 100644 --- a/src/app/systems/system-about.component.ts +++ b/src/app/systems/system-about.component.ts @@ -176,16 +176,24 @@ import { SystemStateService } from './system-state.service'; }
@let other_settings_value = other_settings(); - @if (item()?.settings && other_settings_value) { -
- -
- } @else { + + @defer (on immediate) { + @if (item()?.settings && other_settings_value) { +
+ +
+ } @else { +
+ +

{{ 'SYSTEMS.LOADING_SETTINGS' | translate }}

+
+ } + } @placeholder {

{{ 'SYSTEMS.LOADING_SETTINGS' | translate }}

diff --git a/src/app/systems/system-state.service.ts b/src/app/systems/system-state.service.ts index acd63f07d..c4eac6323 100644 --- a/src/app/systems/system-state.service.ts +++ b/src/app/systems/system-state.service.ts @@ -1,4 +1,3 @@ -import { moveItemInArray } from '@angular/cdk/drag-drop'; import { computed, inject, resource, Service, signal } from '@angular/core'; import { MatDialog } from '@angular/material/dialog'; import { @@ -30,7 +29,7 @@ import { import { calculateModuleIndex } from '../common/api'; import { AsyncHandler } from '../common/async-handler.class'; import { PlaceDebugService } from '../common/debug.service'; -import { escapeHtml, unique } from '../common/general'; +import { escapeHtml, moveItemInArray, unique } from '../common/general'; import { openedTabs } from '../common/opened-tabs'; import { isSubsystemUser, @@ -43,16 +42,18 @@ import { reportLoadError } from '../common/load-error'; import { notifyError, notifySuccess } from '../common/notifications'; import { waitForDialog } from '../common/signals'; import { HashMap, Identity } from '../common/types'; -import { - ConfirmModalData, - openConfirmModal, -} from '../overlays/confirm-modal.component'; -import { +// Modals load on demand to keep them out of the first page load +import type { ConfirmModalData } from '../overlays/confirm-modal.component'; +import type { SelectItemModalComponent, SelectItemModalData, } from '../overlays/select-item-modal.component'; -import { ViewResponseModalComponent } from '../overlays/view-response-modal.component'; -import { SystemTriggerFormComponent } from './system-trigger-form.component'; + +/** Load the item picker modal */ +async function selectItemModal() { + const m = await import('../overlays/select-item-modal.component'); + return m.SelectItemModalComponent; +} @Service() export class SystemStateService extends AsyncHandler { @@ -394,7 +395,7 @@ export class SystemStateService extends AsyncHandler { const ref = this._dialog.open< SelectItemModalComponent, SelectItemModalData - >(SelectItemModalComponent, { + >(await selectItemModal(), { data: { service_name: 'module to system', query_fn: (_) => @@ -431,7 +432,7 @@ export class SystemStateService extends AsyncHandler { const ref = this._dialog.open< SelectItemModalComponent, SelectItemModalData - >(SelectItemModalComponent, { + >(await selectItemModal(), { data: { service_name: 'Triggers', query_fn: (_) => @@ -466,6 +467,9 @@ export class SystemStateService extends AsyncHandler { public async editTrigger(trigger: PlaceTrigger) { if (this.item() && trigger) { + const { SystemTriggerFormComponent } = await import( + './system-trigger-form.component' + ); const ref = this._dialog.open(SystemTriggerFormComponent, { data: { item: trigger, @@ -776,16 +780,17 @@ export class SystemStateService extends AsyncHandler { } /** View Results of the execute */ - private viewDetails(content: unknown) { - this._dialog.open( - ViewResponseModalComponent, - { - data: { content }, - }, + private async viewDetails(content: unknown) { + const { ViewResponseModalComponent } = await import( + '../overlays/view-response-modal.component' ); + this._dialog.open(ViewResponseModalComponent, { data: { content } }); } private async confirm(data: ConfirmModalData) { + const { openConfirmModal } = await import( + '../overlays/confirm-modal.component' + ); return openConfirmModal(data, this._dialog); } diff --git a/src/app/triggers/trigger-state.service.ts b/src/app/triggers/trigger-state.service.ts index 52fcadd7b..2ca229fbd 100644 --- a/src/app/triggers/trigger-state.service.ts +++ b/src/app/triggers/trigger-state.service.ts @@ -1,4 +1,3 @@ -import { moveItemInArray } from '@angular/cdk/drag-drop'; import { Service, computed, inject, resource, signal } from '@angular/core'; import { MatDialog } from '@angular/material/dialog'; import { @@ -16,7 +15,7 @@ import { } from '@placeos/ts-client'; import { describeError } from '../common/errors'; -import { escapeHtml } from '../common/general'; +import { escapeHtml, moveItemInArray } from '../common/general'; import { ActiveItemService } from '../common/item.service'; import { reportLoadError } from '../common/load-error'; import { i18n } from '../common/locale.service'; diff --git a/src/app/ui/basic-line-graph.component.ts b/src/app/ui/basic-line-graph.component.ts index a031d99eb..70dcf8776 100644 --- a/src/app/ui/basic-line-graph.component.ts +++ b/src/app/ui/basic-line-graph.component.ts @@ -98,7 +98,7 @@ export class BasicLineGraphComponent { } ctx.setLineDash([]); // Draw Y-Axis Labels - ctx.font = '20px Fira Code'; + ctx.font = '20px "Fira Code Variable"'; ctx.fillStyle = color; ctx.fillText('50%', -4, (height - axis_start.y) / 2 + 8); ctx.fillText('100%', -12, 8); diff --git a/src/app/ui/custom-fields/settings-field.component.ts b/src/app/ui/custom-fields/settings-field.component.ts index 2c7abf635..1e5d079e1 100644 --- a/src/app/ui/custom-fields/settings-field.component.ts +++ b/src/app/ui/custom-fields/settings-field.component.ts @@ -237,7 +237,7 @@ export class SettingsFieldComponent this.editor = monaco.editor.create(element.nativeElement, { value: this.settings_string || '', language: this.lang() || 'yaml', - fontFamily: `"Fira Code", monospace`, + fontFamily: `"Fira Code Variable", monospace`, lineNumbers: 'on', roundedSelection: false, scrollBeyondLastLine: false, diff --git a/src/app/ui/diff-viewer.component.ts b/src/app/ui/diff-viewer.component.ts index 112798e89..7f92e3dad 100644 --- a/src/app/ui/diff-viewer.component.ts +++ b/src/app/ui/diff-viewer.component.ts @@ -88,7 +88,7 @@ export class DiffViewerComponent this._editor = monaco.editor.createDiffEditor( this._editor_el().nativeElement, { - fontFamily: `"Fira Code", monospace`, + fontFamily: `"Fira Code Variable", monospace`, theme: !this._users.dark_mode ? 'vs' : 'vs-dark', readOnly: true, // Monaco watches the container size, so resizes need no rebuild diff --git a/src/app/ui/icon-subset.ts b/src/app/ui/icon-subset.ts new file mode 100644 index 000000000..388fc2426 --- /dev/null +++ b/src/app/ui/icon-subset.ts @@ -0,0 +1,135 @@ +// Generated by config/icon-subset.ts. Do not edit. + +/** Icons in the subset icon font */ +export const ICON_SUBSET: ReadonlySet = new Set([ + 'account_tree', + 'add', + 'api', + 'app_registration', + 'apps', + 'arrow_back', + 'arrow_downward', + 'arrow_drop_down', + 'arrow_upward', + 'auto_awesome', + 'block', + 'bolt', + 'border_bottom', + 'border_right', + 'brightness_alert', + 'bug_report', + 'build', + 'business_messages', + 'call_split', + 'cancel', + 'cancel_presentation', + 'check', + 'chevron_left', + 'chevron_right', + 'clear_all', + 'close', + 'cloud_download', + 'cloud_off', + 'cloud_upload', + 'code_blocks', + 'colors', + 'comments_disabled', + 'construction', + 'content_copy', + 'dark_mode', + 'database', + 'delete', + 'delete_forever', + 'delete_sweep', + 'description', + 'display_settings', + 'dns', + 'docs', + 'domain', + 'done', + 'download', + 'edit', + 'edit_off', + 'error', + 'event', + 'expand_more', + 'extension', + 'filter_list', + 'group', + 'groups', + 'hearing_disabled', + 'history', + 'hub', + 'info', + 'input', + 'integration_instructions', + 'inventory_2', + 'key', + 'keyboard_arrow_down', + 'label', + 'language', + 'laps', + 'layers', + 'link', + 'list', + 'lock', + 'lock_open', + 'login', + 'logout', + 'meeting_room', + 'menu', + 'monitoring', + 'more_horiz', + 'more_time', + 'more_vert', + 'network_node', + 'notes', + 'notifications_active', + 'opacity', + 'open_in_browser', + 'outlet', + 'pending', + 'person', + 'photo_album', + 'play_arrow', + 'play_circle', + 'playlist_add', + 'playlist_remove', + 'power', + 'public', + 'publish', + 'refresh', + 'remove', + 'reorder', + 'restore_from_trash', + 'route', + 'router', + 'save', + 'schedule', + 'sdk', + 'search', + 'send', + 'sensors', + 'settings', + 'settings_alert', + 'shadow', + 'sort', + 'space', + 'start', + 'stop', + 'switch', + 'sync_problem', + 'table', + 'tablet', + 'timer', + 'today', + 'translate', + 'travel_explore', + 'unfold_more', + 'update', + 'upload', + 'visibility', + 'warning', + 'web', + 'webhook', +]); diff --git a/src/app/ui/icon.component.ts b/src/app/ui/icon.component.ts index 9404199f7..78f6c0106 100644 --- a/src/app/ui/icon.component.ts +++ b/src/app/ui/icon.component.ts @@ -10,6 +10,7 @@ import { } from '@angular/core'; import { MatTooltip } from '@angular/material/tooltip'; import { ApplicationIcon } from '../common/types'; +import { ICON_SUBSET } from './icon-subset'; import { SafePipe } from './pipes/safe.pipe'; /** Text of an element, leaving out the names of any icons inside it */ @@ -59,6 +60,21 @@ export class IconComponent { constructor() { afterNextRender(() => this._labelControl()); + afterEveryRender(() => this._useFullFont()); + } + + /** + * The default icon font is a subset. Projected names are only known + * after render, so check the rendered name and use the full font for + * names that are not in the subset. + */ + private _useFullFont() { + const glyph = this._element.nativeElement.querySelector('i'); + if (!glyph?.classList.contains('material-symbols-rounded')) return; + const full = !ICON_SUBSET.has(glyph.textContent.trim()); + if (glyph.hasAttribute('data-full') !== full) { + glyph.toggleAttribute('data-full', full); + } } /** diff --git a/src/app/ui/item-shell.component.ts b/src/app/ui/item-shell.component.ts index 006048bdc..f671ad3b0 100644 --- a/src/app/ui/item-shell.component.ts +++ b/src/app/ui/item-shell.component.ts @@ -2,6 +2,7 @@ import { booleanAttribute, Component, computed, + DestroyRef, inject, input, signal, @@ -15,17 +16,31 @@ import { ActiveItemService } from '../common/item.service'; import { DebugOutputComponent } from './debug-output.component'; import { IconComponent } from './icon.component'; import { ItemDetailsSkeletonComponent } from './item-details-skeleton.component'; -import { - DisplayItem, - ItemAction, - ItemDetailsComponent, -} from './item-details.component'; +import type { DisplayItem, ItemAction } from './item-details.component'; +import { ItemDetailsComponent } from './item-details.component'; import { ItemSelectionComponent } from './item-selection.component'; import { ItemSidebarComponent } from './item-sidebar.component'; -import { ItemTab, ItemTablistComponent } from './item-tablist.component'; +import type { ItemTab } from './item-tablist.component'; +import { ItemTablistComponent } from './item-tablist.component'; import { SidebarMenuComponent } from './sidebar-menu.component'; import { TranslatePipe } from './translate.pipe'; +/** Tailwind `lg` breakpoint, where the item list moves to the sidebar */ +const LARGE_SCREEN = '(min-width: 64rem)'; + +/** Signal of whether a CSS media query matches. Call in an injection context. */ +function mediaQuery(query: string) { + // jsdom has no matchMedia + const media = window.matchMedia?.(query); + const matches = signal(!!media?.matches); + const update = () => matches.set(!!media?.matches); + media?.addEventListener('change', update); + inject(DestroyRef).onDestroy(() => + media?.removeEventListener('change', update), + ); + return matches.asReadonly(); +} + /** * Page layout for an item feature: main menu, item list, details header, * tabs and the active tab. Projected content shows next to the add button. @@ -39,12 +54,20 @@ import { TranslatePipe } from './translate.pipe';
-