@@ -192,6 +192,7 @@ import type {
192192 SectionMetadata ,
193193 TrackedChangesMode ,
194194 Fragment ,
195+ DocumentBackground ,
195196} from '@superdoc/contracts' ;
196197import { extractHeaderFooterSpace as _extractHeaderFooterSpace } from '@superdoc/contracts' ;
197198// TrackChangesBasePluginKey is used by #syncTrackedChangesPreferences and getTrackChangesPluginState.
@@ -502,6 +503,7 @@ export class PresentationEditor extends EventEmitter {
502503 /** Scroll-isolating wrapper around #hiddenHost. Append/remove this from the DOM. */
503504 #hiddenHostWrapper: HTMLElement ;
504505 #layoutOptions: LayoutEngineOptions ;
506+ #configuredDocumentBackground: DocumentBackground | undefined ;
505507 #layoutState: LayoutState = { blocks : [ ] , measures : [ ] , layout : null , bookmarks : new Map ( ) } ;
506508 #layoutLookupBlocks: FlowBlock [ ] = [ ] ;
507509 #layoutLookupMeasures: Measure [ ] = [ ] ;
@@ -702,6 +704,9 @@ export class PresentationEditor extends EventEmitter {
702704
703705 const requestedFlowMode = options . layoutEngineOptions ?. flowMode === 'semantic' ? 'semantic' : 'paginated' ;
704706 const requestedLayoutMode = options . layoutEngineOptions ?. layoutMode ?? 'vertical' ;
707+ this . #configuredDocumentBackground = this . #coerceDocumentBackground(
708+ options . layoutEngineOptions ?. documentBackground ,
709+ ) ;
705710 this . #layoutOptions = {
706711 pageSize : options . layoutEngineOptions ?. pageSize ?? DEFAULT_PAGE_SIZE ,
707712 margins : options . layoutEngineOptions ?. margins ?? DEFAULT_MARGINS ,
@@ -713,6 +718,7 @@ export class PresentationEditor extends EventEmitter {
713718 }
714719 : options . layoutEngineOptions ?. virtualization ,
715720 zoom : options . layoutEngineOptions ?. zoom ?? 1 ,
721+ ...( this . #configuredDocumentBackground ? { documentBackground : this . #configuredDocumentBackground } : { } ) ,
716722 pageStyles : options . layoutEngineOptions ?. pageStyles ,
717723 debugLabel : options . layoutEngineOptions ?. debugLabel ,
718724 layoutMode : requestedFlowMode === 'semantic' ? 'vertical' : requestedLayoutMode ,
@@ -7861,6 +7867,12 @@ export class PresentationEditor extends EventEmitter {
78617867 this . #layoutOptions. pageSize = pageSize ;
78627868 this . #layoutOptions. margins = margins ;
78637869 const flowMode = this . #layoutOptions. flowMode ?? 'paginated' ;
7870+ const documentBackground = this . #resolveDocumentBackground( ) ;
7871+ if ( documentBackground ) {
7872+ this . #layoutOptions. documentBackground = documentBackground ;
7873+ } else {
7874+ delete this . #layoutOptions. documentBackground ;
7875+ }
78647876
78657877 const resolvedMargins = {
78667878 top : margins . top ! ,
@@ -7900,17 +7912,18 @@ export class PresentationEditor extends EventEmitter {
79007912 marginBottom : semanticMargins . bottom ,
79017913 } ,
79027914 sectionMetadata,
7915+ ...( documentBackground ? { documentBackground } : { } ) ,
79037916 } ;
79047917 }
79057918
79067919 this . #hiddenHost. style . width = `${ pageSize . w } px` ;
79077920
79087921 const alternateHeaders = this . #resolveAlternateHeadersFlag( ) ;
7909-
79107922 return {
79117923 flowMode : 'paginated' ,
79127924 pageSize,
79137925 margins : resolvedMargins ,
7926+ ...( documentBackground ? { documentBackground } : { } ) ,
79147927 ...( columns ? { columns } : { } ) ,
79157928 sectionMetadata,
79167929 alternateHeaders,
@@ -7938,6 +7951,19 @@ export class PresentationEditor extends EventEmitter {
79387951 return out ;
79397952 }
79407953
7954+ #coerceDocumentBackground( candidate : unknown ) : DocumentBackground | undefined {
7955+ if ( ! candidate || typeof candidate !== 'object' ) return undefined ;
7956+ const color = ( candidate as { color ?: unknown } ) . color ;
7957+ return typeof color === 'string' && color . length > 0 ? { color } : undefined ;
7958+ }
7959+
7960+ #resolveDocumentBackground( ) : DocumentBackground | undefined {
7961+ return (
7962+ this . #coerceDocumentBackground( this . #editor?. state ?. doc ?. attrs ?. documentBackground ) ??
7963+ ( this . #configuredDocumentBackground ? { ...this . #configuredDocumentBackground } : undefined )
7964+ ) ;
7965+ }
7966+
79417967 #buildHeaderFooterInput( ) {
79427968 if ( this . #isSemanticFlowMode( ) ) {
79437969 return null ;
0 commit comments