flexysnap 0.2.1-alpha.1 → 0.2.2-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.js +1 -6
- package/src/wireframeComparison.js +32 -21
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -14,12 +14,7 @@ export {
|
|
|
14
14
|
} from './testUtils.js';
|
|
15
15
|
|
|
16
16
|
export {
|
|
17
|
-
compareWireframes
|
|
18
|
-
compareElements,
|
|
19
|
-
compareTexts,
|
|
20
|
-
compareBoundingBoxes,
|
|
21
|
-
createPairings,
|
|
22
|
-
histogramDiff
|
|
17
|
+
compareWireframes
|
|
23
18
|
} from './wireframeComparison.js';
|
|
24
19
|
|
|
25
20
|
export { areWireframesStable } from './wireframeStability.js';
|
|
@@ -64,13 +64,12 @@ function createPairings(currentElements, baselineElements) {
|
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
function compareBoundingBoxes(baselineRect, currentRect,
|
|
67
|
+
function compareBoundingBoxes(baselineRect, currentRect, strictPosition = true, strictSize = true) {
|
|
68
68
|
const differences = [];
|
|
69
69
|
|
|
70
70
|
if (strictPosition) {
|
|
71
71
|
const boundingBoxDifference = calculateBoundingBoxDistance(baselineRect, currentRect)
|
|
72
|
-
|
|
73
|
-
if (boundingBoxDifference > tolerance) {
|
|
72
|
+
if (boundingBoxDifference > 10) {
|
|
74
73
|
differences.push({
|
|
75
74
|
type: "layout_shift",
|
|
76
75
|
difference: boundingBoxDifference
|
|
@@ -81,15 +80,26 @@ function compareBoundingBoxes(baselineRect, currentRect, tolerance = 10, strictP
|
|
|
81
80
|
const baselineHeight = baselineRect.bottom - baselineRect.top;
|
|
82
81
|
const currentWidth = currentRect.right - currentRect.left;
|
|
83
82
|
const currentHeight = currentRect.bottom - currentRect.top;
|
|
84
|
-
|
|
85
|
-
Math.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
83
|
+
if (strictSize) {
|
|
84
|
+
const sizeDiff = Math.max(
|
|
85
|
+
Math.abs(baselineWidth - currentWidth),
|
|
86
|
+
Math.abs(baselineHeight - currentHeight)
|
|
87
|
+
);
|
|
88
|
+
if (sizeDiff > 10) {
|
|
89
|
+
differences.push({
|
|
90
|
+
type: "size_mismatch",
|
|
91
|
+
difference: sizeDiff
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
} else {
|
|
95
|
+
const diffRatio = (baselineWidth * baselineHeight) / (currentWidth * currentHeight)
|
|
96
|
+
if (diffRatio > 1.1 || diffRatio < 0.9) {
|
|
97
|
+
differences.push({
|
|
98
|
+
type: "size_mismatch",
|
|
99
|
+
difference: diffRatio
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
93
103
|
}
|
|
94
104
|
}
|
|
95
105
|
|
|
@@ -100,7 +110,7 @@ function replaceDigitsWithPlaceholder(text) {
|
|
|
100
110
|
return text.replace(/\d+/g, '[digits]');
|
|
101
111
|
}
|
|
102
112
|
|
|
103
|
-
function compareTexts(baselineTexts, currentTexts, strictPosition = true, maskDigits = false) {
|
|
113
|
+
function compareTexts(baselineTexts, currentTexts, strictPosition = true, strictSize = true, maskDigits = false) {
|
|
104
114
|
const { matchedPairs, unmatchedCurrent, unmatchedBaseline } = createPairings(currentTexts, baselineTexts);
|
|
105
115
|
|
|
106
116
|
for (const pairing of matchedPairs) {
|
|
@@ -127,8 +137,8 @@ function compareTexts(baselineTexts, currentTexts, strictPosition = true, maskDi
|
|
|
127
137
|
const boundingBoxDifferences = compareBoundingBoxes(
|
|
128
138
|
baselineText.boundingRect,
|
|
129
139
|
currentText.boundingRect,
|
|
130
|
-
|
|
131
|
-
|
|
140
|
+
strictPosition,
|
|
141
|
+
strictSize
|
|
132
142
|
);
|
|
133
143
|
currentText.differences = currentText.differences.concat(boundingBoxDifferences);
|
|
134
144
|
}
|
|
@@ -156,12 +166,12 @@ function compareTexts(baselineTexts, currentTexts, strictPosition = true, maskDi
|
|
|
156
166
|
}
|
|
157
167
|
}
|
|
158
168
|
|
|
159
|
-
function compareElements(baselineElement, currentElement, strictPosition = true, maskDigits = false) {
|
|
169
|
+
function compareElements(baselineElement, currentElement, strictPosition = true, strictSize = true, maskDigits = false) {
|
|
160
170
|
currentElement.differences = compareBoundingBoxes(
|
|
161
171
|
baselineElement.boundingRect,
|
|
162
172
|
currentElement.boundingRect,
|
|
163
|
-
|
|
164
|
-
|
|
173
|
+
strictPosition,
|
|
174
|
+
strictSize
|
|
165
175
|
);
|
|
166
176
|
|
|
167
177
|
if (baselineElement.histogram && currentElement.histogram) {
|
|
@@ -175,7 +185,7 @@ function compareElements(baselineElement, currentElement, strictPosition = true,
|
|
|
175
185
|
}
|
|
176
186
|
|
|
177
187
|
if (baselineElement.texts.length > 0 || currentElement.texts.length > 0) {
|
|
178
|
-
compareTexts(baselineElement.texts, currentElement.texts, strictPosition, maskDigits);
|
|
188
|
+
compareTexts(baselineElement.texts, currentElement.texts, strictPosition, strictSize, maskDigits);
|
|
179
189
|
}
|
|
180
190
|
}
|
|
181
191
|
|
|
@@ -193,6 +203,7 @@ function compareWireframes(baselineWireframe, currentWireframe) {
|
|
|
193
203
|
expect(baselineElementGroup.selector).toEqual(currentElementGroup.selector);
|
|
194
204
|
|
|
195
205
|
const strictPosition = currentElementGroup.strictPosition !== false;
|
|
206
|
+
const strictSize = currentElementGroup.strictSize !== false;
|
|
196
207
|
const maskDigits = currentElementGroup.maskDigits === true;
|
|
197
208
|
|
|
198
209
|
//TODO: REMOVE later
|
|
@@ -208,7 +219,7 @@ function compareWireframes(baselineWireframe, currentWireframe) {
|
|
|
208
219
|
for (const pairing of matchedPairs) {
|
|
209
220
|
const baselineElement = baselineElementGroup.elements[pairing.baselineIndex];
|
|
210
221
|
const currentElement = currentElementGroup.elements[pairing.currentIndex];
|
|
211
|
-
compareElements(baselineElement, currentElement, strictPosition, maskDigits);
|
|
222
|
+
compareElements(baselineElement, currentElement, strictPosition, strictSize, maskDigits);
|
|
212
223
|
if (currentElement.differences?.length === 0) {
|
|
213
224
|
currentElement.differences = undefined
|
|
214
225
|
}
|
|
@@ -233,4 +244,4 @@ function compareWireframes(baselineWireframe, currentWireframe) {
|
|
|
233
244
|
return currentWireframe;
|
|
234
245
|
}
|
|
235
246
|
|
|
236
|
-
export { compareWireframes
|
|
247
|
+
export { compareWireframes };
|