1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
import {areArraysEqual} from '/common/arrays.js';
function parseNumber(value) {
const num = parseInt(value.toString());
if (isNaN(num)) return undefined;
return num;
}
registerLayout('test', class {
static get childInputProperties() {
return [
'--available-inline-size',
'--available-block-size',
'--fixed-inline-size',
'--fixed-block-size',
'--percentage-inline-size',
'--percentage-block-size',
'--inline-size-expected',
'--block-size-expected'
];
}
async intrinsicSizes() {}
async layout(children, edges, constraints, styleMap) {
const childFragments = await Promise.all(children.map((child) => {
const childConstraints = {};
const availableInlineSize = parseNumber(child.styleMap.get('--available-inline-size'));
const availableBlockSize = parseNumber(child.styleMap.get('--available-block-size'));
const fixedInlineSize = parseNumber(child.styleMap.get('--fixed-inline-size'));
const fixedBlockSize = parseNumber(child.styleMap.get('--fixed-block-size'));
const percentageInlineSize = parseNumber(child.styleMap.get('--percentage-inline-size'));
const percentageBlockSize = parseNumber(child.styleMap.get('--percentage-block-size'));
return child.layoutNextFragment({
availableInlineSize,
availableBlockSize,
fixedInlineSize,
fixedBlockSize,
percentageInlineSize,
percentageBlockSize,
});
}));
const actual = childFragments.map((childFragment) => {
return {
inlineSize: childFragment.inlineSize,
blockSize: childFragment.blockSize,
};
});
const expected = children.map((child) => {
return {
inlineSize: parseInt(child.styleMap.get('--inline-size-expected').toString()),
blockSize: parseInt(child.styleMap.get('--block-size-expected').toString()),
};
});
const equalityFunc = (a, b) => {
return a.inlineSize == b.inlineSize && a.blockSize == b.blockSize;
};
if (!areArraysEqual(expected, actual, equalityFunc)) {
return {autoBlockSize: 0, childFragments};
}
return {autoBlockSize: 100, childFragments};
}
});
|