Skip to content

Commit fada493

Browse files
Merge pull request #11 from com-pas/feature/self-host-icons
feat: add self-hosted Material Symbols Outlined font support
2 parents 331e4d8 + 8ba942b commit fada493

4 files changed

Lines changed: 46 additions & 0 deletions

File tree

foundation/icons/icon-font.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Self-hosts the Material Symbols Outlined font used by `md-icon`.
2+
3+
const fontUrl = new URL('./material-symbols-outlined.woff2', import.meta.url)
4+
.href;
5+
6+
const styleElementId = 'oscd-publisher-icon-font';
7+
8+
export const publisherIconFontFamily = 'OSCD Publisher Icons';
9+
10+
export function loadPublisherIconFont(): void {
11+
if (document.getElementById(styleElementId)) return;
12+
13+
const style = document.createElement('style');
14+
style.id = styleElementId;
15+
style.textContent = `
16+
@font-face {
17+
font-family: '${publisherIconFontFamily}';
18+
font-style: normal;
19+
font-weight: 400;
20+
font-display: block;
21+
src: url('${fontUrl}') format('woff2');
22+
}
23+
`;
24+
document.head.appendChild(style);
25+
}
26+
27+
// Scopes `--md-icon-font` to a single element instead of `:root`, so it
28+
// can't clash with other plugins or the host.
29+
export function applyPublisherIconFont(host: HTMLElement): void {
30+
host.style.setProperty(
31+
'--md-icon-font',
32+
`'${publisherIconFontFamily}', 'Material Symbols Outlined'`
33+
);
34+
}
313 KB
Binary file not shown.

oscd-publisher.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ import { DataSetEditor } from './editors/dataset/data-set-editor.js';
1010
import { GseControlEditor } from './editors/gsecontrol/gse-control-editor.js';
1111
import { ReportControlEditor } from './editors/report/report-control-editor.js';
1212
import { SampledValueControlEditor } from './editors/sampledvalue/sampled-value-control-editor.js';
13+
import {
14+
applyPublisherIconFont,
15+
loadPublisherIconFont,
16+
} from './foundation/icons/icon-font.js';
17+
18+
loadPublisherIconFont();
1319

1420
const EditorSelector = {
1521
Report: 'report-control-editor',
@@ -43,6 +49,11 @@ export default class PublisherPlugin extends ScopedElementsMixin(LitElement) {
4349
@state()
4450
private publisherType: PublisherType = 'GOOSE';
4551

52+
connectedCallback(): void {
53+
super.connectedCallback();
54+
applyPublisherIconFont(this);
55+
}
56+
4657
private filterValues: Record<PublisherType, string> = {
4758
Report: '',
4859
GOOSE: '',

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"analyze": "cem analyze --litelement",
1414
"start": "tsc && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"wds\"",
1515
"build": "rimraf dist && rollup -c rollup.config.js",
16+
"preview": "npm run build && npx serve dist -l 5000 --cors",
1617
"deploy": "npm run build && gh-pages --dist 'dist' --branch 'deploy'",
1718
"prepublish": "tsc && npm run analyze -- --exclude dist",
1819
"lint": "eslint --ext .ts,.html . --ignore-path .gitignore && prettier \"**/*.ts\" --check --ignore-path .gitignore",

0 commit comments

Comments
 (0)