/// <summary> /// Creates a style sheet for the given response asynchronously. /// </summary> /// <param name="response"> /// The response with the stream representing the source of the /// stylesheet. /// </param> /// <param name="options"> /// The options with the parameters for evaluating the style. /// </param> /// <param name="cancel">The cancellation token.</param> /// <returns>The task resulting in the style sheet.</returns> public async Task<IStyleSheet> ParseStylesheetAsync(IResponse response, StyleOptions options, CancellationToken cancel) { var context = options.Context; var configuration = context.Configuration; var parser = new CssParser(_options, configuration); var url = response.Address?.Href; var sheet = new CssStyleSheet(parser, url, options.Element) { IsDisabled = options.IsDisabled }; var source = new TextSource(response.Content); var tokenizer = new CssTokenizer(source); tokenizer.Error += (_, ev) => context.Fire(ev); var builder = new CssBuilder(tokenizer, parser); context.Fire(new CssParseEvent(sheet, completed: false)); await parser.ParseStylesheetAsync(sheet, source).ConfigureAwait(false); context.Fire(new CssParseEvent(sheet, completed: true)); return sheet; }