@fileverse-dev/ddoc 3.5.6 → 4.0.0-font-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -98,6 +98,7 @@ The `DdocProps` interface is a TypeScript interface that defines the properties
98
98
  | `setIsPresentationMode` | `React.Dispatch<SetStateAction<boolean>>` | Function to toggle presentation mode |
99
99
  | `sharedSlidesLink` | `string` | Link for shared presentation slides |
100
100
  | `documentStyling` | `DocumentStyling` | Custom styling for document appearance |
101
+ | `fonts` | `FontDescriptor[]` | Consumer-provided font catalog (see Custom Fonts) |
101
102
 
102
103
  ## Document Styling
103
104
 
@@ -157,6 +158,57 @@ interface DocumentStyling {
157
158
 
158
159
  **Note:** Document styling works in both regular editor mode and presentation mode. In presentation mode, only `canvasBackground`, `textColor`, and `fontFamily` are applied to maintain clean slide appearance.
159
160
 
161
+ ## Custom Fonts
162
+
163
+ The editor ships with a **system-font baseline only** (Arial, Calibri, Georgia, Times New Roman, etc.) and makes **no third-party font requests** — there is no Google Fonts `@import`. To offer additional fonts, pass a `fonts` catalog. Each font is self-hosted by your app and loaded **on demand** via the CSS Font Loading API: a font's `woff2` is fetched only when it's selected in the picker or when a document (including a remote collaborator's change) actually renders text in it.
164
+
165
+ ```typescript
166
+ type FontDescriptor = {
167
+ /** Display name shown in the picker, e.g. "Poppins". */
168
+ name: string;
169
+ /** CSS font-family stack stored in the content, e.g. "Poppins, sans-serif". */
170
+ family: string;
171
+ /**
172
+ * woff2 source(s). Omit for a pure system font (no loading).
173
+ * - string: a single file covering all weights (e.g. a variable font).
174
+ * - Record<number, string>: a per-weight map, e.g. { 400: url400, 700: url700 }.
175
+ */
176
+ url?: string | Record<number, string>;
177
+ /**
178
+ * Optional SVG preview rendered in the picker. Any React node that renders an
179
+ * <svg>. Falls back to the font name in the default font when absent.
180
+ */
181
+ preview?: React.ReactNode;
182
+ };
183
+ ```
184
+
185
+ ### Usage Example
186
+
187
+ ```tsx
188
+ import { DdocEditor, FontDescriptor } from '@fileverse-dev/ddoc';
189
+ // Self-host the woff2 files however your bundler prefers (e.g. @fontsource/*).
190
+ import poppins400 from '@fontsource/poppins/files/poppins-latin-400-normal.woff2';
191
+ import poppins700 from '@fontsource/poppins/files/poppins-latin-700-normal.woff2';
192
+
193
+ const fonts: FontDescriptor[] = [
194
+ {
195
+ name: 'Poppins',
196
+ family: 'Poppins, sans-serif',
197
+ url: { 400: poppins400, 700: poppins700 },
198
+ preview: <PoppinsPreview />, // optional SVG
199
+ },
200
+ ];
201
+
202
+ <DdocEditor fonts={fonts} /* ...other props */ />;
203
+ ```
204
+
205
+ **Notes:**
206
+
207
+ - The picker lists the system baseline and your catalog **together, sorted A–Z** (with **Default** pinned to the top).
208
+ - The CSS face name is derived from the first token of `family`, so `name` is purely cosmetic and can differ (e.g. `name: 'Poppins (Brand)'`, `family: 'Poppins, sans-serif'`).
209
+ - The catalog also drives PDF/print export, which emits `@font-face` rules for the registered fonts.
210
+ - Host your `woff2` files **same-origin** so they resolve in both the editor and the print iframe.
211
+
160
212
  ## Comments & Collaboration Props
161
213
 
162
214
  | Property | Type | Description |