Skip to content

Commit 5cec648

Browse files
committed
feat: add Inter and InterDisplay font families with various styles and weights; update font paths in CSS and config; enhance font face URL handling in stylesheets
1 parent 8c2b439 commit 5cec648

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+72
-49
lines changed

entrypoints/content/ui.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,51 @@
11
import { createPinia } from 'pinia'
22
import type { Component } from 'vue'
33
import { createApp } from 'vue'
4+
import { browser, PublicPath } from 'wxt/browser'
45
import { ContentScriptContext } from 'wxt/utils/content-script-context'
56
import { createShadowRootUi } from 'wxt/utils/content-script-ui/shadow-root'
67

78
import { initToast } from '@/composables/useToast'
89
import { CONTENT_UI_SHADOW_ROOT_NAME } from '@/utils/constants'
9-
import { extractFontFace, injectStyleSheetToDocument, loadContentScriptStyleSheet } from '@/utils/css'
10+
import {
11+
extractFontFace,
12+
injectStyleSheetToDocument,
13+
loadContentScriptStyleSheet,
14+
replaceFontFaceUrl,
15+
} from '@/utils/css'
1016
import { createI18nInstance } from '@/utils/i18n/index'
1117
import logger from '@/utils/logger'
1218

1319
async function loadStyleSheet(shadowRoot: ShadowRoot) {
14-
const styleSheet = await loadContentScriptStyleSheet(import.meta.env.ENTRYPOINT)
20+
const styleSheet = await loadContentScriptStyleSheet(
21+
import.meta.env.ENTRYPOINT,
22+
)
1523
injectStyleSheetToDocument(shadowRoot, styleSheet)
1624
// font-face can only be applied to the document, not the shadow root
1725
const fontFaceStyleSheet = extractFontFace(styleSheet)
26+
// Content script stylesheets are parsed via new CSSStyleSheet() + replaceSync(),
27+
// so @font-face URLs (e.g. /fonts/Inter.woff2) resolve against the page URL
28+
// instead of the extension URL. Convert to absolute extension URLs.
29+
replaceFontFaceUrl(fontFaceStyleSheet, (url) => {
30+
if (
31+
url.startsWith('data:')
32+
|| url.startsWith('moz-extension://')
33+
|| url.startsWith('chrome-extension://')
34+
|| url.startsWith('http://')
35+
|| url.startsWith('https://')
36+
|| url.startsWith('blob:')
37+
) {
38+
return url
39+
}
40+
return browser.runtime.getURL(url as PublicPath)
41+
})
1842
injectStyleSheetToDocument(document, fontFaceStyleSheet)
1943
}
2044

21-
export async function createShadowRootOverlay(ctx: ContentScriptContext, component: Component<{ rootElement: HTMLDivElement }>) {
45+
export async function createShadowRootOverlay(
46+
ctx: ContentScriptContext,
47+
component: Component<{ rootElement: HTMLDivElement }>,
48+
) {
2249
const existingUI = document.querySelector(CONTENT_UI_SHADOW_ROOT_NAME)
2350
if (existingUI) {
2451
try {

0 commit comments

Comments
 (0)