Files
sousa-gecko/devtools/server/actors/utils/css-grid-utils.js
T
Brad Werth 148c72ce9c Bug 1815140 Part 2: Make grid highlighter hasMoved directly compare the grid fragment objects. r=devtools-reviewers,jdescottes
The Grid objects will be regenerated whenever the grid is reflowed, which
is nearly the same to the old check of comparing the contents of the
grid structure. This approach is prone to false positives, which is
explained in a new comment.

Differential Revision: https://phabricator.services.mozilla.com/D169725
2023-02-23 01:07:34 +00:00

61 lines
1.6 KiB
JavaScript

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
/**
* Returns the grid fragment array with all the grid fragment data stringifiable.
*
* @param {Object} fragments
* Grid fragment object.
* @return {Array} representation with the grid fragment data stringifiable.
*/
function getStringifiableFragments(fragments = []) {
if (fragments[0] && Cu.isDeadWrapper(fragments[0])) {
return {};
}
return fragments.map(getStringifiableFragment);
}
function getStringifiableFragment(fragment) {
return {
areas: getStringifiableAreas(fragment.areas),
cols: getStringifiableDimension(fragment.cols),
rows: getStringifiableDimension(fragment.rows),
};
}
function getStringifiableAreas(areas) {
return [...areas].map(getStringifiableArea);
}
function getStringifiableDimension(dimension) {
return {
lines: [...dimension.lines].map(getStringifiableLine),
tracks: [...dimension.tracks].map(getStringifiableTrack),
};
}
function getStringifiableArea({
columnEnd,
columnStart,
name,
rowEnd,
rowStart,
type,
}) {
return { columnEnd, columnStart, name, rowEnd, rowStart, type };
}
function getStringifiableLine({ breadth, names, number, start, type }) {
return { breadth, names, number, start, type };
}
function getStringifiableTrack({ breadth, start, state, type }) {
return { breadth, start, state, type };
}
exports.getStringifiableFragments = getStringifiableFragments;