Skip to content

Commit bcd15a5

Browse files
caio-pizzolsuperdoc-oss-port[bot]
authored andcommitted
Merge pull request #81 from superdoc/feat/superdoc-fonts-package
feat(fonts): @superdoc/fonts package for bundled fonts (SD-3441) Ported-From-Source-Repo: superdoc/orbit Ported-From-Source-Commit: 45a456f29763f301ab5c336dd26c6f08124c5288 Ported-Public-Prefix: superdoc/public
1 parent a9a582a commit bcd15a5

40 files changed

Lines changed: 664 additions & 40 deletions

apps/docs/getting-started/fonts.mdx

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,66 @@ keywords: 'fonts, font loading, calibri, cambria, aptos, font fallback, custom f
66

77
SuperDoc keeps the font name from the Word document. When SuperDoc ships an approved fallback for that font, it renders with the fallback but keeps the original name for export. When no fallback is available, load the real font in your app.
88

9-
## Load fonts in your app
9+
## Bundled fallback fonts
1010

11-
Fonts are your host page's responsibility. `@font-face`, a hosted stylesheet, or a font CDN: anything the browser can resolve.
11+
A Word document asks for fonts like Calibri, Cambria, and Times New Roman. Most are proprietary, or not installed on every machine. SuperDoc renders them with reviewed open substitutes that match the metrics: Carlito for Calibri, Liberation Serif for Times New Roman, and more. The original name is kept for export.
12+
13+
These substitutes are real `.woff2` files. The browser fetches them from a URL. Installing SuperDoc from npm puts them in `node_modules`, which does not serve them to the browser. So you tell your app where they live. Pick one path.
14+
15+
### Recommended: the `@superdoc/fonts` package
16+
17+
Install the optional pack and pass it. Your bundler (Vite, Webpack, Next, Nuxt) emits the files and rewrites the URLs. No copy step. No path config.
18+
19+
```bash
20+
npm install @superdoc/fonts
21+
```
22+
23+
```js
24+
import { SuperDoc } from 'superdoc';
25+
import { superdocFonts } from '@superdoc/fonts';
26+
27+
new SuperDoc({
28+
selector: '#editor',
29+
document: 'contract.docx',
30+
fonts: superdocFonts,
31+
});
32+
```
33+
34+
### Alternative: host the files yourself
35+
36+
Serve the `.woff2` from your own path or a CDN, then point SuperDoc at them. The files ship in the package at `node_modules/superdoc/dist/fonts/`.
37+
38+
```js
39+
new SuperDoc({
40+
selector: '#editor',
41+
document: 'contract.docx',
42+
fonts: { assetBaseUrl: '/fonts/' },
43+
});
44+
```
45+
46+
Use `fonts.resolveAssetUrl` instead for signed or versioned URLs.
47+
48+
### CDN script build
49+
50+
The CDN build loads the fonts from a path relative to the script. Loading from a public CDN (jsDelivr or unpkg) needs no setup: the fonts resolve to `superdoc@<version>/dist/fonts/...` automatically. If you self-host `superdoc.min.js`, serve its `dist/fonts/` folder beside it.
51+
52+
### Skipping the pack
53+
54+
The pack is optional. Skip it if you load your own fonts for every family, or only need fonts the user's OS already has. When the bundled `.woff2` cannot be fetched, SuperDoc logs a one-time warning and falls back to the original font name. On a machine without that font, the text renders in a system fallback, so it can look unchanged.
55+
56+
## Load your own fonts
57+
58+
For a brand font, a licensed font, or any family SuperDoc does not ship a fallback for, load the real file yourself. Use `@font-face`, a hosted stylesheet, or a font CDN. Anything the browser can resolve.
1259

1360
```css
1461
@font-face {
15-
font-family: 'Calibri';
16-
src: url('/fonts/Carlito-Regular.woff2') format('woff2');
62+
font-family: 'Inter';
63+
src: url('/fonts/Inter-Regular.woff2') format('woff2');
1764
font-display: swap;
1865
}
1966
```
2067

21-
For custom or licensed fonts, load the real file yourself. SuperDoc's built-in fallbacks cover only the fonts it ships and verifies.
68+
SuperDoc's built-in fallbacks cover only the fonts it ships and verifies. For everything else, the real file is yours to provide. To register it through SuperDoc instead of CSS, pass it in `fonts.families` (which composes with `@superdoc/fonts`).
2269

2370
## Toolbar font list
2471

apps/docs/getting-started/frameworks/angular.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ Requires Angular 17.2+. `viewChild()` and `input()` are stable from Angular 19;
1111
## Install
1212

1313
```bash
14-
npm install superdoc
14+
npm install superdoc @superdoc/fonts
1515
```
1616

1717
## Basic setup
1818

1919
```typescript
2020
import { Component, ElementRef, viewChild, AfterViewInit, inject, DestroyRef } from '@angular/core';
2121
import { SuperDoc } from 'superdoc';
22+
import { superdocFonts } from '@superdoc/fonts';
2223
import 'superdoc/style.css';
2324

2425
@Component({
@@ -38,6 +39,7 @@ export class EditorComponent implements AfterViewInit {
3839
selector: this.editorRef().nativeElement,
3940
document: 'contract.docx',
4041
documentMode: 'editing',
42+
fonts: superdocFonts,
4143
});
4244
}
4345
}

apps/docs/getting-started/frameworks/laravel.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ SuperDoc works with Laravel + Blade + Vite. Laravel serves the Blade template wi
1111
```bash
1212
composer install
1313
npm install
14+
npm install superdoc @superdoc/fonts
1415
```
1516

1617
## Vite config
@@ -55,9 +56,10 @@ Create a Blade view that loads the Vite-bundled script and mounts the editor:
5556

5657
```js resources/js/app.js
5758
import { SuperDoc } from 'superdoc';
59+
import { superdocFonts } from '@superdoc/fonts';
5860
import 'superdoc/style.css';
5961

60-
let superdoc = new SuperDoc({ selector: '#editor' });
62+
let superdoc = new SuperDoc({ selector: '#editor', fonts: superdocFonts });
6163

6264
document.getElementById('file-input').addEventListener('change', (e) => {
6365
const file = e.target.files[0];

apps/docs/getting-started/frameworks/nextjs.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ SuperDoc works seamlessly with Next.js. The recommended approach is using `@supe
1010
The React wrapper is the simplest way to integrate SuperDoc with Next.js:
1111

1212
```bash
13-
npm install @superdoc-dev/react
13+
npm install @superdoc-dev/react @superdoc/fonts
1414
```
1515

1616
### App Router (Next.js 13+)
@@ -20,12 +20,14 @@ npm install @superdoc-dev/react
2020
'use client';
2121

2222
import { SuperDocEditor } from '@superdoc-dev/react';
23+
import { superdocFonts } from '@superdoc/fonts';
2324
import '@superdoc-dev/react/style.css';
2425

2526
export default function EditorPage() {
2627
return (
2728
<SuperDocEditor
2829
document="/sample.docx"
30+
fonts={superdocFonts}
2931
documentMode="editing"
3032
onReady={() => console.log('Editor ready!')}
3133
style={{ height: '100vh' }}

apps/docs/getting-started/frameworks/nuxt.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ SuperDoc works with Nuxt 4+ as a client-side Vue component. Set `ssr: false` in
99
## Install
1010

1111
```bash
12-
npm install superdoc
12+
npm install superdoc @superdoc/fonts
1313
```
1414

1515
## Configure Nuxt
@@ -33,6 +33,7 @@ Nuxt auto-imports Vue's `ref`, `watch`, and lifecycle hooks: no manual imports n
3333
```vue app/pages/index.vue
3434
<script setup lang="ts">
3535
import { SuperDoc } from 'superdoc';
36+
import { superdocFonts } from '@superdoc/fonts';
3637
3738
const container = ref<HTMLDivElement | null>(null);
3839
const file = ref<File | null>(null);
@@ -50,6 +51,7 @@ const initEditor = () => {
5051
superdoc = new SuperDoc({
5152
selector: container.value,
5253
document: file.value,
54+
fonts: superdocFonts,
5355
});
5456
};
5557

apps/docs/getting-started/frameworks/react.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ SuperDoc provides `@superdoc-dev/react`: a first-party wrapper with lifecycle ma
99
## Install
1010

1111
```bash
12-
npm install @superdoc-dev/react
12+
npm install @superdoc-dev/react @superdoc/fonts
1313
```
1414

1515
<Note>
@@ -20,12 +20,14 @@ npm install @superdoc-dev/react
2020

2121
```jsx
2222
import { SuperDocEditor } from '@superdoc-dev/react';
23+
import { superdocFonts } from '@superdoc/fonts';
2324
import '@superdoc-dev/react/style.css';
2425

2526
function App() {
2627
return (
2728
<SuperDocEditor
2829
document={file}
30+
fonts={superdocFonts}
2931
documentMode="editing"
3032
onReady={() => console.log('Editor ready!')}
3133
/>

apps/docs/getting-started/frameworks/solid.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ SuperDoc does not ship a first-party Solid wrapper. Use the core `superdoc` pack
1313
## Install
1414

1515
```bash
16-
npm install superdoc
16+
npm install superdoc @superdoc/fonts
1717
```
1818

1919
## Quick start
2020

2121
```tsx
2222
import { onCleanup, onMount } from 'solid-js';
2323
import { SuperDoc } from 'superdoc';
24+
import { superdocFonts } from '@superdoc/fonts';
2425
import 'superdoc/style.css';
2526

2627
export default function App() {
@@ -30,6 +31,7 @@ export default function App() {
3031
onMount(() => {
3132
superdoc = new SuperDoc({
3233
selector: `#${editorId}`,
34+
fonts: superdocFonts,
3335
});
3436
});
3537

apps/docs/getting-started/frameworks/vanilla-js.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ SuperDoc works with plain JavaScript. No framework required.
3434

3535
```javascript NPM/Bundler
3636
import { SuperDoc } from 'superdoc';
37+
import { superdocFonts } from '@superdoc/fonts';
3738
import 'superdoc/style.css';
3839

3940
const superdoc = new SuperDoc({
4041
selector: '#editor',
41-
document: 'contract.docx'
42+
document: 'contract.docx',
43+
fonts: superdocFonts,
4244
});
4345
```
4446

apps/docs/getting-started/frameworks/vue.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ SuperDoc works with Vue 3.0+ using Composition API, Options API, or `<script set
88
## Install
99

1010
```bash
11-
npm install superdoc
11+
npm install superdoc @superdoc/fonts
1212
```
1313

1414
## Basic setup
@@ -23,6 +23,7 @@ npm install superdoc
2323
<script setup>
2424
import { ref, onMounted, onBeforeUnmount } from 'vue';
2525
import { SuperDoc } from 'superdoc';
26+
import { superdocFonts } from '@superdoc/fonts';
2627
import 'superdoc/style.css';
2728
2829
const container = ref(null);
@@ -31,7 +32,8 @@ let superdoc = null;
3132
onMounted(() => {
3233
superdoc = new SuperDoc({
3334
selector: container.value,
34-
document: 'contract.docx'
35+
document: 'contract.docx',
36+
fonts: superdocFonts,
3537
});
3638
});
3739

apps/docs/getting-started/quickstart.mdx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ By the end of this page you'll have a working DOCX editor in your app: load a Wo
1414
<Tabs>
1515
<Tab title="npm">
1616
```bash
17-
npm install superdoc
17+
npm install superdoc @superdoc/fonts
1818
```
1919
</Tab>
2020
<Tab title="React">
2121
```bash
22-
npm install @superdoc-dev/react
22+
npm install @superdoc-dev/react @superdoc/fonts
2323
```
2424
</Tab>
2525
<Tab title="CDN">
@@ -31,6 +31,10 @@ By the end of this page you'll have a working DOCX editor in your app: load a Wo
3131
</Tab>
3232
</Tabs>
3333

34+
<Info>
35+
`@superdoc/fonts` serves SuperDoc's bundled fallback fonts so Word fonts render without copying assets. It's optional. See [Font support](/getting-started/fonts).
36+
</Info>
37+
3438
## 2. Render the editor
3539

3640
<Tabs>
@@ -40,21 +44,24 @@ By the end of this page you'll have a working DOCX editor in your app: load a Wo
4044

4145
<script type="module">
4246
import { SuperDoc } from 'superdoc';
47+
import { superdocFonts } from '@superdoc/fonts';
4348
import 'superdoc/style.css';
4449
4550
const superdoc = new SuperDoc({
4651
selector: '#editor',
52+
fonts: superdocFonts,
4753
});
4854
</script>
4955
```
5056
</Tab>
5157
<Tab title="React">
5258
```jsx
5359
import { SuperDocEditor } from '@superdoc-dev/react';
60+
import { superdocFonts } from '@superdoc/fonts';
5461
import '@superdoc-dev/react/style.css';
5562

5663
export default function App() {
57-
return <SuperDocEditor />;
64+
return <SuperDocEditor fonts={superdocFonts} />;
5865
}
5966
```
6067
</Tab>

0 commit comments

Comments
 (0)