Skip to content

Commit

Permalink
More progress
Browse files Browse the repository at this point in the history
  • Loading branch information
kblok committed Dec 12, 2023
1 parent 2b76a81 commit 9fafe25
Show file tree
Hide file tree
Showing 11 changed files with 236 additions and 130 deletions.
32 changes: 14 additions & 18 deletions lib/PuppeteerSharp.DevicesFetcher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,26 @@
using Newtonsoft.Json;
namespace PuppeteerSharp.DevicesFetcher
{
class Program
static class Program
{
const string DEVICES_URL = "https://raw.githubusercontent.com/puppeteer/puppeteer/master/src/common/DeviceDescriptors.ts";

static readonly string deviceDescriptorsOutput = "../../../../PuppeteerSharp/Mobile/DeviceDescriptors.cs";
static readonly string deviceDescriptorNameOutput = "../../../../PuppeteerSharp/Mobile/DeviceDescriptorName.cs";
private const string DevicesURL = "https://raw.githubusercontent.com/puppeteer/puppeteer/master/src/common/DeviceDescriptors.ts";
private const string DeviceDescriptorsOutput = "../../../../PuppeteerSharp/Mobile/DeviceDescriptors.cs";
private const string DeviceDescriptorNameOutput = "../../../../PuppeteerSharp/Mobile/DeviceDescriptorName.cs";

static async Task Main(string[] args)
{
var url = DEVICES_URL;
var url = DevicesURL;
if (args.Length > 0)
{
url = args[0];
}

Console.WriteLine($"GET {url}");
var text = await HttpGET(url).ConfigureAwait(false);
var text = await HttpGet(url).ConfigureAwait(false);

const string DeviceArray = "Device[] = [";
var startIndex = text.IndexOf(DeviceArray) + DeviceArray.Length;
var endIndex = text.IndexOf("];", startIndex);
const string deviceArray = "Device[] = [";
var startIndex = text.IndexOf(deviceArray, StringComparison.Ordinal) + deviceArray.Length;
var endIndex = text.IndexOf("];", startIndex, StringComparison.Ordinal);
var length = endIndex - startIndex;
text = "[" + text.Substring(startIndex, length) + "]";

Expand Down Expand Up @@ -86,7 +85,7 @@ public static class DeviceDescriptors
builder.AppendJoin(",\n", devices.Select(GenerateCsharpFromDevice));
builder.Append(end);

File.WriteAllText(deviceDescriptorsOutput, builder.ToString());
File.WriteAllText(DeviceDescriptorsOutput, builder.ToString());
}

static void WriteDeviceDescriptorName(IEnumerable<Device> devices)
Expand All @@ -104,17 +103,14 @@ public enum DeviceDescriptorName
}";

builder.Append(begin);
builder.AppendJoin(",", devices.Select(device =>
{
return $@"
builder.AppendJoin(",", devices.Select(device => $@"
/// <summary>
/// {device.Name}
/// </summary>
{DeviceNameToEnumValue(device)}";
}));
{DeviceNameToEnumValue(device)}"));
builder.Append(end);

File.WriteAllText(deviceDescriptorNameOutput, builder.ToString());
File.WriteAllText(DeviceDescriptorNameOutput, builder.ToString());
}

static string GenerateCsharpFromDevice(Device device)
Expand Down Expand Up @@ -156,7 +152,7 @@ static string DeviceNameToEnumValue(Device device)
return output.ToString();
}

static async Task<string> HttpGET(string url)
private static async Task<string> HttpGet(string url)
{
using var httpClient = new HttpClient();
return await httpClient.GetStringAsync(url).ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ namespace PuppeteerSharp.Tests.QuerySelectorTests
{
public class ElementHandleQuerySelectorAllEvalTests : PuppeteerPageBaseTest
{
public ElementHandleQuerySelectorAllEvalTests(): base()
{
}

[PuppeteerTest("queryselector.spec.ts", "ElementHandle.$$eval", "should work")]
[PuppeteerTimeout]
public async Task ShouldWork()
Expand Down
90 changes: 89 additions & 1 deletion lib/PuppeteerSharp/BoundingBox.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,100 @@
using System;
using Newtonsoft.Json;
using PuppeteerSharp.Media;

namespace PuppeteerSharp
{
/// <summary>
/// Bounding box data returned by <see cref="IElementHandle.BoundingBoxAsync"/>.
/// </summary>
public record BoundingBox(decimal X, decimal Y, decimal Width, decimal Height) : Point(X, Y)
public class BoundingBox : IEquatable<BoundingBox>
{
/// <summary>
/// Initializes a new instance of the <see cref="BoundingBox"/> class.
/// </summary>
public BoundingBox()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="BoundingBox"/> class.
/// </summary>
/// <param name="x">The x coordinate.</param>
/// <param name="y">The y coordinate.</param>
/// <param name="width">Width.</param>
/// <param name="height">Height.</param>
public BoundingBox(decimal x, decimal y, decimal width, decimal height)
{
X = x;
Y = y;
Width = width;
Height = height;
}

/// <summary>
/// The x coordinate of the element in pixels.
/// </summary>
/// <value>The x.</value>
public decimal X { get; set; }

/// <summary>
/// The y coordinate of the element in pixels.
/// </summary>
/// <value>The y.</value>
public decimal Y { get; set; }

/// <summary>
/// The width of the element in pixels.
/// </summary>
/// <value>The width.</value>
public decimal Width { get; set; }

/// <summary>
/// The height of the element in pixels.
/// </summary>
/// <value>The height.</value>
public decimal Height { get; set; }

/// <inheritdoc/>
public override bool Equals(object obj)
{
if (obj == null || GetType() != obj.GetType())
{
return false;
}

return Equals((BoundingBox)obj);
}

/// <summary>
/// Determines whether the specified <see cref="PuppeteerSharp.BoundingBox"/> is equal to the current <see cref="T:PuppeteerSharp.BoundingBox"/>.
/// </summary>
/// <param name="obj">The <see cref="PuppeteerSharp.BoundingBox"/> to compare with the current <see cref="T:PuppeteerSharp.BoundingBox"/>.</param>
/// <returns><c>true</c> if the specified <see cref="PuppeteerSharp.BoundingBox"/> is equal to the current
/// <see cref="T:PuppeteerSharp.BoundingBox"/>; otherwise, <c>false</c>.</returns>
public bool Equals(BoundingBox obj)
=> obj != null &&
obj.X == X &&
obj.Y == Y &&
obj.Height == Height &&
obj.Width == Width;

/// <inheritdoc/>
public override int GetHashCode()
=> X.GetHashCode() * 397
^ Y.GetHashCode() * 397
^ Width.GetHashCode() * 397
^ Height.GetHashCode() * 397;

internal Clip ToClip()
{
return new Clip
{
X = X,
Y = Y,
Width = Width,
Height = Height,
};
}
}
}
Loading

0 comments on commit 9fafe25

Please sign in to comment.