Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

diverged

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

diverged - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

docs/diverged images/changeGraphDiff.png

2

package.json
{
"name": "diverged",
"version": "0.1.2",
"version": "0.1.3",
"description": "Compare UI screenshots with document flow detection.",

@@ -5,0 +5,0 @@ "main": "src/diverged.js",

'use strict';
let MEYERS_DIFF_ARRAY_METHOD = undefined;
const noop = function (){};
let LCS_DIFF_ARRAY_METHOD = undefined;
// debugger
if (typeof require !== 'undefined') {
MEYERS_DIFF_ARRAY_METHOD = require('diff').diffArrays;
LCS_DIFF_ARRAY_METHOD = require('diff').diffArrays;
} else {
MEYERS_DIFF_ARRAY_METHOD = JsDiff.diffArrays;
try {
LCS_DIFF_ARRAY_METHOD = JsDiff.diffArrays;
} catch(err) {
console.error(err);
}
}
const rowSpread = 1;
const spread = 50; // range of adjacent pixels to aggregate when calculating diff

@@ -16,6 +22,6 @@ const IS_ADDED_WORD = '0_255_0_255';

const IS_SAME_WORD = '';
const OPACITY = '30'; // 0-255 range
const OPACITY = '40'; // 0-255 range
/**
* Applies meyers-diff algorithm to imageData formatted arrays
* Applies Longest-Common-Subsequence-Diff algorithm to imageData formatted arrays
*

@@ -64,3 +70,3 @@ * @param {Uint8ClampedArray} [reference] baseline image

console.time("unGroupAdjacent");
const expandedColumns = ungroupAdjacent(reducedColumnDiff, spread, cols_rows_ref.columns, h, w);
const expandedColumns = ungroupAdjacent(reducedColumnDiff, spread, cols_rows_test.columns, h, w);
console.timeEnd("unGroupAdjacent");

@@ -123,2 +129,3 @@

// Categorize the current segment
if (columnDiff[depthIndex].removed) {

@@ -139,3 +146,2 @@ segmentLength = columnDiff[depthIndex].count;

segmentLength = columnDiff[depthIndex].count;

@@ -154,2 +160,3 @@

// Limit segmentLength to total length of column
if (!segmentLength) {

@@ -161,4 +168,4 @@ continue;

if (debug || resultClass !== IS_SAME_WORD){
const printSampleMap = false;
if (!printSampleMap || resultClass !== IS_SAME_WORD){
segment = new Array(segmentLength).fill(resultClass);

@@ -192,3 +199,3 @@ } else {

for (let i = 0; i < refArr.length; i++) {
rawResultArr.push(MEYERS_DIFF_ARRAY_METHOD(refArr[i], testArr[i]));
rawResultArr.push(LCS_DIFF_ARRAY_METHOD(refArr[i], testArr[i]));
}

@@ -226,4 +233,4 @@ return rawResultArr;

function getCompositeColumnDepthValues(columns, range, depth) {
return range.reduce((acc, column) => {
function getCompositeColumnDepthValues(columns, sequence, depth) {
return sequence.reduce((acc, column) => {
return acc.concat(columns[column][depth]);

@@ -233,16 +240,37 @@ }, [])

const interpolatedColumnsValues = new Array();
let i = 0;
while (i < w) {
const adjacentBounds = getAdjacentArrayBounds(i, spread, w);
const interpolatedColumns = getInterpolatedSequence(...adjacentBounds);
function getCompositeRowIndexValues(groupedColumns, sequence, column) {
return sequence.reduce((acc, depth) => {
return acc.concat(groupedColumns[column][depth]);
}, [])
}
const groupedColumns = new Array();
let columnPointer = 0;
while (columnPointer < w) {
const adjacentColumnBounds = getAdjacentArrayBounds(columnPointer, spread, w);
const interpolatedColumns = getInterpolatedSequence(...adjacentColumnBounds);
const columnComposite = new Array(h);
const columnComposite = new Array();
for (var depth = 0; depth < h; depth++) {
columnComposite[depth] = getCompositeColumnDepthValues(columns, interpolatedColumns, depth).join('|');
}
interpolatedColumnsValues.push(columnComposite);
i += spread;
groupedColumns.push(columnComposite);
columnPointer += spread;
}
return interpolatedColumnsValues;
const groupedRows = new Array();
if (rowSpread > 1) {
for (var index = 0; index < groupedColumns.length; index++) {
const rowComposite = new Array();
let depthPointer = 0;
while (depthPointer < h) {
const adjacentRowBounds = getAdjacentArrayBounds(depthPointer, rowSpread, h);
const interpolatedRows = getInterpolatedSequence(...adjacentRowBounds);
rowComposite.push(getCompositeRowIndexValues(groupedColumns, interpolatedRows, index).join(','));
depthPointer += rowSpread;
}
groupedRows[index] = rowComposite;
}
}
return groupedRows.length ? groupedRows : groupedColumns ;
}

@@ -259,12 +287,14 @@

// expand columns
const ungrouped = new Array(w);
for (let i = 0; i < w; i++) {
if (!ungrouped[i]) {
ungrouped[i] = new Array(h);
for (let index = 0; index < w; index++) {
if (!ungrouped[index]) {
ungrouped[index] = new Array(h);
}
const groupedIndex = mapUngroupedColumnIndexToGroupedIndex(i, spread);
for (let j = 0; j < h; j++) {
const value = grouped[groupedIndex][j].split('|')[0];
ungrouped[i][j] = value ? value : columnUnderlay[i][j].replace(/\d+$/, OPACITY);
const groupedIndexMap = mapUngroupedColumnIndexToGroupedIndex(index, spread);
for (let depth = 0; depth < h; depth++) {
const groupedDepthMap = rowSpread > 1 ? mapUngroupedColumnIndexToGroupedIndex(depth, rowSpread) : depth;
const value = grouped[groupedIndexMap][groupedDepthMap].split('|')[0];
ungrouped[index][depth] = value ? value : columnUnderlay[index][depth].replace(/\d+$/, OPACITY);
}

@@ -271,0 +301,0 @@ }

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc