odiff icon indicating copy to clipboard operation
odiff copied to clipboard

feat: add captureCoords option to retrieve x,y diff information

Open tgriesser opened this issue 8 months ago • 2 comments

Hey @dmtrKovalenko!

Was playing around with this library a bit and wanted to capture the locations of the highlighted diffs beyond just the diffLines

So I tried to implement a captureCoords option which outputs a diffCoords formatted as:

Array<[yAxis: number, ...xAxisRanges: Array<[number, number]>]>

so:

[
  [1169, [886, 888], [890, 892]],
  [1170, [885, 894], [896, 896]],
  [1171, [882, 899]],
  [1172, [878, 901]],
  [1173, [878, 902], [904, 904]],
  // ...
]

See the test/coords-fixture.json for an example.

Haven't written much ocaml, so possible it could be done simpler, but let me know what you think.

tgriesser avatar Apr 17 '25 20:04 tgriesser

Hey @tgriesser long time no see. Thanks for the proposal I'll take my time to review it but I just wonder on the motivation. What are you exactly trying to perform? Why diff output / diff mask is not enough? How would you use the information for each individual pixel?

dmtrKovalenko avatar Apr 17 '25 21:04 dmtrKovalenko

Don't need every individual pixel, just the x-axis ranges of pixels for the given lines where there are diffs.

The idea is that if you have that info, you'd be able to draw a rough bounding boxes for the DOM around the various major elements that were affected when there's a diff and be able to use that information to find the actual elements where side-effects took place via elementFromPoint or something

Mostly just experimenting at this point, but figured it could also be useful if you wanted to do something like crop the image to the areas where there are changes or something

tgriesser avatar Apr 17 '25 21:04 tgriesser