Skip to content

Commit

Permalink
feat(wc): copy fontface definitions to document on init
Browse files Browse the repository at this point in the history
this will make icons and fonts appear in web components
  • Loading branch information
jahow committed Oct 21, 2023
1 parent c3d7cec commit ba50d70
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions apps/webcomponents/src/app/components/base.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,35 @@ export class BaseComponent implements OnChanges, OnInit {
this.titleFont
)
this.facade.init(this.searchId)
this.copyFontFacesToDocument()
this.isInitialized = true
}

changes() {
// to override
}

private copyFontFacesToDocument() {
// get the list of font face definitions in the Shadow DOM
const root = this.injector.get(ElementRef).nativeElement as HTMLElement
const styles = root.shadowRoot.styleSheets
const fontFaces = Array.from(styles).reduce(
(prev, curr) => [
...prev,
...Array.from(curr.cssRules)
.filter((rule) => rule.cssText.startsWith('@font-face'))
.map((rule) => rule.cssText),
],
[]
)

// all font faces are then copied to the document
const style = document.createElement('style')
const cssText = fontFaces.join('\n')
style.appendChild(document.createTextNode(cssText))
document.head.appendChild(style)
}

async getRecordLink(
uuid: string,
usages: LinkUsage[]
Expand Down

0 comments on commit ba50d70

Please sign in to comment.