preprocessSource static method

String preprocessSource(
  1. String src, {
  2. Set<EmbeddedJsContent> jsContent = const {},
  3. bool forWeb = false,
  4. bool encodeHtml = false,
  5. String? windowDisambiguator,
})

This is where the magic happens.

Depending on the params passed to it, this function embeds ("burns") javascript functions inside the HTML source, wraps it and/or URI-encodes it.

Implementation

static String preprocessSource(
  String src, {
  Set<EmbeddedJsContent> jsContent = const {},
  bool forWeb = false,
  bool encodeHtml = false,
  String? windowDisambiguator,
}) {
  var _src = src;

  if (!isFullHtmlPage(_src)) {
    _src = wrapHtml(_src, windowDisambiguator);
  }

  if (forWeb) {
    _src = embedWebIframeJsConnector(_src, windowDisambiguator!);
  }

  if (jsContent.isNotEmpty) {
    final jsContentStrings = <String>{};
    for (final jsToEmbed in jsContent) {
      if (jsToEmbed.js != null) {
        jsContentStrings.add(jsToEmbed.js!);
      } else {
        if (forWeb && jsToEmbed.webJs != null) {
          jsContentStrings.add(jsToEmbed.webJs!);
        } else {
          jsContentStrings.add(jsToEmbed.mobileJs!);
        }
      }
    }
    _src = embedJsInHtmlSource(_src, jsContentStrings);
  }

  if (encodeHtml) {
    _src = encodeHtmlToURI(_src);
  }

  return _src;
}