using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
using HtmlAgilityPack;
namespace AIStudio.Assistants.VisualBriefing;
public sealed partial class VisualBriefingArtifactService
{
///
/// Matches the version-independent artifact header at the start of standalone HTML.
///
private static readonly Regex HEADER_REGEX = HeaderRegex();
///
/// Matches the version-independent artifact header at the start of standalone HTML.
///
[GeneratedRegex(@"\A\n\n", RegexOptions.CultureInvariant)]
private static partial Regex HeaderRegex();
///
/// Matches the generated presentation stylesheet.
///
private static readonly Regex STYLE_REGEX = StyleRegex();
///
/// Matches the generated presentation stylesheet.
///
[GeneratedRegex("""""", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)]
private static partial Regex StyleRegex();
///
/// Matches the embedded declarative runtime.
///
private static readonly Regex RUNTIME_REGEX = RuntimeRegex();
///
/// Matches the embedded declarative runtime.
///
[GeneratedRegex("""""", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)]
private static partial Regex RuntimeRegex();
///
/// Matches the optional embedded chart runtime.
///
private static readonly Regex ECHARTS_REGEX = EChartsRegex();
///
/// Matches the optional embedded chart runtime.
///
[GeneratedRegex("""""", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)]
private static partial Regex EChartsRegex();
///
/// Reads an intact standalone artifact without applying current compiler or runtime rules.
///
public static bool TryParse(string html, out VisualBriefingArtifactParts parts, out string issue)
{
parts = null!;
issue = string.Empty;
if (string.IsNullOrWhiteSpace(html))
{
issue = "The briefing file is empty.";
return false;
}
if (!html.EndsWith("