@@ -270,9 +270,22 @@ The layout algorithm performs a block-like layout (positioning fragments sequent
270
270
direction), while centering its children in the inline direction.
271
271
272
272
<pre class="lang-javascript">
273
- registerLayout('block-like' , class extends Layout {
274
- static blockifyChildren = true;
275
- static inputProperties = super.inputProperties;
273
+ registerLayout('block-like' , class {
274
+ *intrinsicSizes(styleMap, children) {
275
+ const childrenSizes = yield children.map((child) => {
276
+ return child.intrinsicSizes();
277
+ });
278
+
279
+ const maxContentSize = childrenSizes.reduce((max, childSizes) => {
280
+ return Math.max(max, childSizes.maxContentContribution);
281
+ }, 0);
282
+
283
+ const minContentSize = childrenSizes.reduce((max, childSizes) => {
284
+ return Math.max(max, childSizes.minContentContribution);
285
+ }, 0);
286
+
287
+ return {maxContentSize, minContentSize};
288
+ }
276
289
277
290
*layout(space, children, styleMap, edges) {
278
291
const inlineSize = resolveInlineSize(space, styleMap);
@@ -286,21 +299,20 @@ registerLayout('block-like', class extends Layout {
286
299
blockSize: availableBlockSize,
287
300
});
288
301
289
- let maxChildInlineSize = 0;
290
302
let blockOffset = edges.all.blockStart;
291
303
292
- for (let child of children) {
293
- const fragment = yield child.layoutNextFragment(childConstraintSpace);
304
+ const childFragments = yeild children.map((child) => {
305
+ return child.layoutNextFragment(childConstraintSpace);
306
+ });
294
307
308
+ for (let fragment of childFragments) {
295
309
// Position the fragment in a block like manner, centering it in the
296
310
// inline direction.
297
311
fragment.blockOffset = blockOffset;
298
312
fragment.inlineOffset = Math.max(
299
313
edges.all.inlineStart,
300
314
(availableInlineSize - fragment.inlineSize) / 2);
301
315
302
- maxChildInlineSize =
303
- Math.max(maxChildInlineSize, childFragments.inlineSize);
304
316
blockOffset += fragment.blockSize;
305
317
}
306
318
@@ -389,46 +401,65 @@ creates child constraint spaces which specify that a child should be a fixed inl
389
401
390
402
<pre class="lang-javascript">
391
403
registerLayout('flex-distribution-like' , class {
404
+ *intrinsicSizes(styleMap, children) {
405
+ const childrenSizes = yield children.map((child) => {
406
+ return child.intrinsicSizes();
407
+ });
408
+
409
+ const maxContentSize = childrenSizes.reduce((sum, childSizes) => {
410
+ return sum + childSizes.maxContentContribution;
411
+ }, 0);
412
+
413
+ const minContentSize = childrenSizes.reduce((max, childSizes) => {
414
+ return sum + childSizes.minContentContribution;
415
+ }, 0);
416
+
417
+ return {maxContentSize, minContentSize};
418
+ }
419
+
392
420
*layout(space, children, styleMap, edges, breakToken) {
393
421
const inlineSize = resolveInlineSize(space, styleMap);
394
422
395
423
const availableInlineSize = inlineSize - edges.all.inline;
396
424
const availableBlockSize =
397
425
resolveBlockSize(space, styleMap) - edges.all.block;
398
426
399
- const unconstrainedSizes = [];
400
427
const childConstraintSpace = new ConstraintSpace({
401
428
inlineSize: availableInlineSize,
402
429
blockSize: availableBlockSize,
403
430
});
404
- let totalSize = 0;
405
431
406
- // Calculate the unconstrained size for each child.
407
- for (let child of children) {
408
- const fragment = yield child.layoutNextFragment(childConstraintSpace);
409
- unconstrainedSizes.push(fragment.inlineSize);
410
- totalSize += fragment.inlineSize;
411
- }
432
+ const unconstrainedChildFragments = yield children.map((child) => {
433
+ return child.layoutNextFragment(childConstraintSpace);
434
+ });
435
+
436
+ const unconstrainedSizes = [];
437
+ const totalSize = unconstrainedChildFragments.reduce((sum, fragment, i) => {
438
+ unconstrainedSizes[i] = fragment.inlineSize;
439
+ return sum + fragment.inlineSize;
440
+ }, 0);
412
441
413
442
// Distribute spare space between children.
414
443
const remainingSpace = Math.max(0, inlineSize - totalSize);
415
444
const extraSpace = remainingSpace / children.length;
416
- const childFragments = [];
417
- let inlineOffset = 0;
418
- let maxChildBlockSize = 0;
419
- for (let i = 0; i < children.length; i++) {
420
- let fragment = yield child.layoutNextFragment(new ConstraintSpace({
445
+
446
+ const childFragments = yield children.map((child, i) => {
447
+ return child.layoutNextFragment(new ConstraintSpace({
421
448
inlineSize: unconstrainedSizes[i] + extraSpace,
422
449
inlineSizeFixed: true,
423
450
blockSize: availableBlockSize
424
451
}));
452
+ });
425
453
454
+ // Position the fragments.
455
+ let inlineOffset = 0;
456
+ let maxChildBlockSize = 0;
457
+ for (let fragment of childFragments) {
426
458
fragment.inlineOffset = inlineOffset;
427
- inlineOffset += fragment.inlineSize ;
459
+ fragment.blockOffset = edges.all.blockStart ;
428
460
461
+ inlineOffset += fragment.inlineSize;
429
462
maxChildBlockSize = Math.max(maxChildBlockSize, fragment.blockSize);
430
-
431
- childFragments.push(fragment);
432
463
}
433
464
434
465
// Resolve our block size.
@@ -505,8 +536,8 @@ It returns a {{FragmentResultOptions}} with a {{FragmentResultOptions/breakToken
505
536
resume the layout.
506
537
507
538
<pre class="lang-javascript">
508
- registerLayout('basic-inline' , class extends Layout {
509
- static inputProperties = super.inputProperties ;
539
+ registerLayout('basic-inline' , class {
540
+ static displayType = 'normal' ;
510
541
511
542
*layout(space, children, styleMap, edges, breakToken) {
512
543
// Resolve our inline size.
@@ -694,7 +725,7 @@ This example shows an node styled by CSS, and what its respective {{LayoutEdges}
694
725
</pre>
695
726
696
727
<pre class="lang-javascript">
697
- registerLayout('box-edges' , class extends Layout {
728
+ registerLayout('box-edges' , class {
698
729
*layout(space, children, styleMap, edges, breakToken) {
699
730
edges.padding.inlineStart; // 5 (as 10% * 50px = 5px).
700
731
edges.border.blockEnd; // 2
@@ -933,13 +964,13 @@ is called, the user agent <em>must</em> run the following steps:
933
964
18. If |layout|'s <code> \[[FunctionKind]] </code> internal slot is not <code> "generator"</code> ,
934
965
<a>throw</a> a <a>TypeError</a> and abort all these steps.
935
966
936
- 19. Let |intrinsizeSizes | be the result of <a>Get</a> (|prototype|,
967
+ 19. Let |intrinsicSizes | be the result of <a>Get</a> (|prototype|,
937
968
<code> "intrinsicSizes"</code> ).
938
969
939
- 20. If the result of <a>IsCallable</a> (|intrinsizeSizes |) is false, <a>throw</a> a
970
+ 20. If the result of <a>IsCallable</a> (|intrinsicSizes |) is false, <a>throw</a> a
940
971
<a>TypeError</a> and abort all these steps.
941
972
942
- 21. If |intrinsizeSizes |'s <code> \[[FunctionKind]] </code> internal slot is not
973
+ 21. If |intrinsicSizes |'s <code> \[[FunctionKind]] </code> internal slot is not
943
974
<code> "generator"</code> , <a>throw</a> a <a>TypeError</a> and abort all these steps.
944
975
945
976
22. Let |definition| be a new <a>layout definition</a> with:
@@ -948,7 +979,7 @@ is called, the user agent <em>must</em> run the following steps:
948
979
949
980
- <a>layout generator function</a> being |layout|.
950
981
951
- - <a>intrinsic sizes generator function</a> being |intrinsizeSizes |.
982
+ - <a>intrinsic sizes generator function</a> being |intrinsicSizes |.
952
983
953
984
- <a>constructor valid flag</a> being <b> true</b> .
954
985
0 commit comments