import { Document } from "../../Document" ; import { Helper } from "../../Helper" ; import { GlobalState } from "../Containers" ; import { DestinationBase } from "./DestinationBase" ; export class StylesheetDestinationSub extends DestinationBase { private _stylesheet : StylesheetDestination ; private index : number ; private name : string ; private handler : ( keyword : string , param : number ) => boolean ; private paragraph ? : null ; constructor ( stylesheet ) { super ( "stylesheet:sub" ) ; this . _stylesheet = stylesheet ; this . index = 0 ; this . name = null ; this . handler = this . _handleKeywordCommon ( "paragraph" ) ; } public handleKeyword ( keyword , param ) { switch ( keyword ) { case "s" : this . index = param ; return true ; case "cs" : delete this . paragraph ; this . handler = this . _handleKeywordCommon ( "character" ) ; this . index = param ; return true ; case "ds" : delete this . paragraph ; this . handler = this . _handleKeywordCommon ( "section" ) ; this . index = param ; return true ; case "ts" : delete this . paragraph ; this . handler = this . _handleKeywordCommon ( "table" ) ; this . index = param ; return true ; } return this . handler ( keyword , param ) ; } public appendText ( text ) { if ( this . name == null ) { this . name = text ; } else { this . name += text ; } } public apply ( ) { this . _stylesheet . addSub ( { index : this . index , name : this . name , } ) ; delete this . _stylesheet ; } private _handleKeywordCommon ( member ) { return ( keyword , param ) => { Helper . log ( "[stylesheet:sub]." + member + ": unhandled keyword: " + keyword + " param: " + param ) ; return false ; } ; } } export class StylesheetDestination extends DestinationBase { private _stylesheets : { index : number ; name : string ; } [ ] ; private inst : Document ; constructor ( parser , inst ) { super ( "stylesheet" ) ; this . _stylesheets = [ ] ; this . inst = inst ; } public sub ( ) { return new StylesheetDestinationSub ( this ) ; } public apply ( ) { Helper . log ( "[stylesheet] apply()" ) ; for ( const idx in this . _stylesheets ) { Helper . log ( "[stylesheet] [" + idx + "] name: " + this . _stylesheets [ idx ] . name ) ; } this . inst . _stylesheets = this . _stylesheets ; delete this . _stylesheets ; } public addSub ( sub ) { this . _stylesheets [ sub . index ] = sub ; } }