import childProcess from "child_process" ; import path from "path" ; import { ILoader } from "@fluidframework/container-definitions" ; import { ISharedMap , SharedMap } from "@fluidframework/map" ; import * as MergeTree from "@fluidframework/merge-tree" ; import { IFluidDataStoreRuntime } from "@fluidframework/datastore-definitions" ; import { ISharedString } from "@fluidframework/sequence" ; import * as author from "./author" ; function setParagraphs ( chunks , sharedString ) { let props ; chunks . forEach ( ( chunk , index ) => { props = { [ MergeTree . reservedMarkerIdKey ] : [ `p-${ index }` ] , [ MergeTree . reservedTileLabelsKey ] : [ "pg" ] } ; sharedString . insertMarker ( index , MergeTree . ReferenceType . Tile , props ) ; } ) ; props = { [ MergeTree . reservedMarkerIdKey ] : [ "p-final" ] , [ MergeTree . reservedTileLabelsKey ] : [ "pg" ] } ; sharedString . insertMarker ( chunks . length , MergeTree . ReferenceType . Tile , props ) ; } async function conductor ( loader , url , scribeMap , runtime , text , intervalTime , writers , processes , callback ) { const process = 0 ; const docId = "" ; const chunks = author . normalizeText ( text ) . split ( "\n" ) ; const sharedString = await author . requestSharedString ( loader , url ) ; const chunksMap = SharedMap . create ( runtime ) ; scribeMap . set ( "chunks" , chunksMap . handle ) ; setParagraphs ( chunks , sharedString ) ; chunks . forEach ( ( chunk , index ) => { const chunkKey = `p-${ index }` ; chunksMap . set ( chunkKey , chunk ) ; } ) ; if ( processes === 1 ) { return await author . typeFile ( loader , url , runtime , sharedString , chunksMap , text , intervalTime , writers , callback ) ; } const interval = setInterval ( ( ) => { const args = [ docId , intervalTime , chunks . length , process ] ; childProcess . fork ( `${ __dirname + path . sep }author.js` , args ) ; if ( process >= processes ) { clearInterval ( interval ) ; } } , 500 ) ; } export async function type ( loader , urlBase , scribeMap , runtime , intervalTime , text , writers , processes , callback , distributed = false ) { if ( distributed ) { console . log ( "distributed" ) ; } return conductor ( loader , urlBase , scribeMap , runtime , text , intervalTime , writers , processes , callback ) ; } /**
 * Toggle between play and pause.
 */ export function togglePlay ( ) { author . toggleAuthorPlay ( ) ; }