@react-x11/components 0.11.0 → 0.13.0
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/dist/flow/node.d.ts +14 -6
- package/dist/flow/node.d.ts.map +1 -1
- package/dist/flow/node.js +82 -64
- package/dist/flow/node.js.map +1 -1
- package/dist/html/controls.d.ts +38 -10
- package/dist/html/controls.d.ts.map +1 -1
- package/dist/html/controls.js +43 -58
- package/dist/html/controls.js.map +1 -1
- package/dist/html/css/cascade.d.ts +134 -20
- package/dist/html/css/cascade.d.ts.map +1 -1
- package/dist/html/css/cascade.js +538 -128
- package/dist/html/css/cascade.js.map +1 -1
- package/dist/html/css/color.d.ts +19 -0
- package/dist/html/css/color.d.ts.map +1 -1
- package/dist/html/css/color.js +86 -0
- package/dist/html/css/color.js.map +1 -1
- package/dist/html/css/parse.d.ts +40 -2
- package/dist/html/css/parse.d.ts.map +1 -1
- package/dist/html/css/parse.js +391 -13
- package/dist/html/css/parse.js.map +1 -1
- package/dist/html/css/style.d.ts +52 -1
- package/dist/html/css/style.d.ts.map +1 -1
- package/dist/html/css/style.js +328 -11
- package/dist/html/css/style.js.map +1 -1
- package/dist/html/css/ua.d.ts +11 -1
- package/dist/html/css/ua.d.ts.map +1 -1
- package/dist/html/css/ua.js +73 -7
- package/dist/html/css/ua.js.map +1 -1
- package/dist/html/css/values.d.ts +10 -1
- package/dist/html/css/values.d.ts.map +1 -1
- package/dist/html/css/values.js +27 -2
- package/dist/html/css/values.js.map +1 -1
- package/dist/html/css/vars.d.ts +5 -0
- package/dist/html/css/vars.d.ts.map +1 -1
- package/dist/html/css/vars.js +2 -2
- package/dist/html/css/vars.js.map +1 -1
- package/dist/html/dom.d.ts.map +1 -1
- package/dist/html/dom.js +38 -3
- package/dist/html/dom.js.map +1 -1
- package/dist/html/fonts.d.ts +25 -1
- package/dist/html/fonts.d.ts.map +1 -1
- package/dist/html/fonts.js +99 -6
- package/dist/html/fonts.js.map +1 -1
- package/dist/html/form.d.ts +200 -0
- package/dist/html/form.d.ts.map +1 -0
- package/dist/html/form.js +801 -0
- package/dist/html/form.js.map +1 -0
- package/dist/html/index.d.ts +12 -0
- package/dist/html/index.d.ts.map +1 -1
- package/dist/html/index.js +30 -264
- package/dist/html/index.js.map +1 -1
- package/dist/html/layout/block.d.ts +11 -2
- package/dist/html/layout/block.d.ts.map +1 -1
- package/dist/html/layout/block.js +186 -19
- package/dist/html/layout/block.js.map +1 -1
- package/dist/html/layout/boxes.d.ts +65 -7
- package/dist/html/layout/boxes.d.ts.map +1 -1
- package/dist/html/layout/boxes.js +87 -22
- package/dist/html/layout/boxes.js.map +1 -1
- package/dist/html/layout/cache.d.ts +2 -2
- package/dist/html/layout/cache.d.ts.map +1 -1
- package/dist/html/layout/cache.js +8 -3
- package/dist/html/layout/cache.js.map +1 -1
- package/dist/html/layout/flex.js +4 -1
- package/dist/html/layout/flex.js.map +1 -1
- package/dist/html/layout/floats.d.ts +4 -0
- package/dist/html/layout/floats.d.ts.map +1 -1
- package/dist/html/layout/floats.js +26 -0
- package/dist/html/layout/floats.js.map +1 -1
- package/dist/html/layout/inline.d.ts +26 -2
- package/dist/html/layout/inline.d.ts.map +1 -1
- package/dist/html/layout/inline.js +1232 -115
- package/dist/html/layout/inline.js.map +1 -1
- package/dist/html/node.d.ts +120 -15
- package/dist/html/node.d.ts.map +1 -1
- package/dist/html/node.js +993 -174
- package/dist/html/node.js.map +1 -1
- package/dist/html/paint.d.ts +75 -2
- package/dist/html/paint.d.ts.map +1 -1
- package/dist/html/paint.js +836 -200
- package/dist/html/paint.js.map +1 -1
- package/dist/html/surfaces.d.ts +7 -2
- package/dist/html/surfaces.d.ts.map +1 -1
- package/dist/html/surfaces.js +16 -0
- package/dist/html/surfaces.js.map +1 -1
- package/dist/html/widgets.d.ts +29 -0
- package/dist/html/widgets.d.ts.map +1 -0
- package/dist/html/widgets.js +620 -0
- package/dist/html/widgets.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/window.d.ts +22 -0
- package/dist/internal/window.d.ts.map +1 -1
- package/dist/internal/window.js +35 -8
- package/dist/internal/window.js.map +1 -1
- package/dist/richtext/node.d.ts +7 -0
- package/dist/richtext/node.d.ts.map +1 -1
- package/dist/richtext/node.js.map +1 -1
- package/package.json +6 -4
- package/src/flow/node.ts +80 -64
- package/src/html/controls.ts +79 -58
- package/src/html/css/cascade.ts +610 -146
- package/src/html/css/color.ts +87 -0
- package/src/html/css/parse.ts +431 -13
- package/src/html/css/style.ts +367 -11
- package/src/html/css/ua.ts +76 -8
- package/src/html/css/values.ts +31 -3
- package/src/html/css/vars.ts +2 -2
- package/src/html/dom.ts +41 -3
- package/src/html/fonts.ts +116 -6
- package/src/html/form.ts +962 -0
- package/src/html/index.ts +49 -300
- package/src/html/layout/block.ts +231 -16
- package/src/html/layout/boxes.ts +133 -32
- package/src/html/layout/cache.ts +8 -3
- package/src/html/layout/flex.ts +4 -1
- package/src/html/layout/floats.ts +24 -0
- package/src/html/layout/inline.ts +1445 -108
- package/src/html/node.ts +1010 -166
- package/src/html/paint.ts +980 -270
- package/src/html/surfaces.ts +21 -1
- package/src/html/widgets.ts +735 -0
- package/src/index.ts +1 -0
- package/src/internal/window.ts +36 -8
- package/src/richtext/node.ts +7 -0
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
import { AUTO, gapOf, isPct, isTransparent, resolve, resolveOrNull, } from '../css/values.js';
|
|
14
14
|
import { CONTAIN_INLINE_SIZE, CONTAIN_LAYOUT, CONTAIN_PAINT, CONTAIN_SIZE, scrolls, } from '../css/style.js';
|
|
15
15
|
import { lineOf, spanToName } from './grid-lines.js';
|
|
16
|
-
import { BOX_RAISES, Box, CLAMPED, CUT_BLOCKS, GRID_TRACKS, FIRST_LINE, INLINE_OFFSETS, MOVED_OFF_LINES, LINE_BOX_RAISES, SHIFTED_LINES, TEXT_SHIFTS, isBlank, } from './boxes.js';
|
|
16
|
+
import { BOX_RAISES, Box, CLAMPED, CLEARED_FROM, CUT_BLOCKS, GRID_TRACKS, FIRST_LINE, INLINE_OFFSETS, MOVED_OFF_LINES, LINE_BOX_RAISES, SHIFTED_LINES, TEXT_SHIFTS, isBlank, } from './boxes.js';
|
|
17
17
|
import { FloatContext } from './floats.js';
|
|
18
|
-
import { faceExtentOf, layoutInline, lineHeightMultiplier, spaceBreaksOnly, strutOf, widestWord, } from './inline.js';
|
|
18
|
+
import { faceExtentOf, joinsBefore, layoutInline, lineHeightMultiplier, spaceBreaksOnly, strutOf, widestWord, } from './inline.js';
|
|
19
19
|
import { layoutFlex } from './flex.js';
|
|
20
20
|
import { finishCaptions, layoutTable } from './table.js';
|
|
21
21
|
import { collapseEdges } from './collapse.js';
|
|
22
|
-
import { computePaintBounds, hoistNegative, stackLayers } from '../paint.js';
|
|
22
|
+
import { clipsFor, computePaintBounds, FIXED_BOXES, fixedToViewport, hoistNegative, OUT_OF_FLOW_REACH, stackLayers, } from '../paint.js';
|
|
23
23
|
/** Lay the whole document out at a width. */
|
|
24
24
|
export function layoutDocument(tree, fonts, viewportWidth, viewportHeight) {
|
|
25
25
|
const ctx = {
|
|
@@ -93,19 +93,39 @@ export function layoutDocument(tree, fonts, viewportWidth, viewportHeight) {
|
|
|
93
93
|
// and the ink bounds are computed after that, so culling sees where boxes
|
|
94
94
|
// ended up rather than where they were laid out.
|
|
95
95
|
if (tree.relative)
|
|
96
|
-
applyRelativeOffsets(root);
|
|
96
|
+
applyRelativeOffsets(root, viewportWidth, viewportHeight);
|
|
97
97
|
const reach = computePaintBounds(root, tree.movedInline);
|
|
98
98
|
if (tree.negative)
|
|
99
99
|
hoistNegative(root);
|
|
100
100
|
stackLayers(root);
|
|
101
101
|
// The document is as tall as what overflows the root, not the root: an
|
|
102
102
|
// `html, body { height: 100% }` a window tall holds a message longer than
|
|
103
|
-
// the window, and the element sizes to all of it.
|
|
103
|
+
// the window, and the element sizes to all of it. Not what a box that
|
|
104
|
+
// clips its overflow holds: that is its own to scroll, and the root's
|
|
105
|
+
// scrollable overflow takes in a positioned box only where no box on the
|
|
106
|
+
// way to it clips it (CSS Overflow 3, 2.2): an absolute box 900px down
|
|
107
|
+
// an `overflow: hidden` card made a page a browser shows 400px tall run
|
|
108
|
+
// on to 980, blank
|
|
104
109
|
let bottom = Math.max(root.height, reach);
|
|
110
|
+
let fixed = null;
|
|
105
111
|
for (const { box } of ctx.positioned) {
|
|
106
|
-
if (box.style.position
|
|
107
|
-
|
|
108
|
-
|
|
112
|
+
if (box.style.position === 'fixed') {
|
|
113
|
+
if (fixedToViewport(box))
|
|
114
|
+
(fixed ??= []).push(box);
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (clipsFor(box, root).length)
|
|
118
|
+
continue;
|
|
119
|
+
// and what it holds, where it does not clip it: a page set in an
|
|
120
|
+
// absolute wrapper 497px tall runs on below it, and the document with
|
|
121
|
+
// it — design 094 was a window tall and no taller, its text past the
|
|
122
|
+
// end of the scroll
|
|
123
|
+
bottom = Math.max(bottom, OUT_OF_FLOW_REACH.get(box) ?? box.y + box.height);
|
|
124
|
+
}
|
|
125
|
+
if (fixed)
|
|
126
|
+
FIXED_BOXES.set(tree, fixed);
|
|
127
|
+
else
|
|
128
|
+
FIXED_BOXES.delete(tree);
|
|
109
129
|
return {
|
|
110
130
|
width: viewportWidth,
|
|
111
131
|
height: bottom,
|
|
@@ -570,8 +590,12 @@ function layoutChildren(box, ctx, floats, contentTop, contentWidth, leading = 0)
|
|
|
570
590
|
// this box's first formatted line is its first child's in flow (CSS 2.1
|
|
571
591
|
// 5.12.1), which its `::first-line` is handed to
|
|
572
592
|
let firstLine = ctx.firstLine ? firstLineOf(box) : null;
|
|
573
|
-
// and the room a list item's marker takes on it (`MARKER_ROOM`)
|
|
574
|
-
|
|
593
|
+
// and the room a list item's marker takes on it (`MARKER_ROOM`): an
|
|
594
|
+
// inside marker's is handed down to the line it is on, and an outside
|
|
595
|
+
// one's is room above the baseline of the first child that has a line,
|
|
596
|
+
// which goes lower where the marker reaches higher (`MARKER_ASCENT`)
|
|
597
|
+
let pushed = MARKER_ASCENT.get(box) ?? null;
|
|
598
|
+
let marked = pushed === null ? (MARKER_ROOM.get(box) ?? null) : null;
|
|
575
599
|
const clamp = ctx.clamp ?? null;
|
|
576
600
|
for (const child of box.children) {
|
|
577
601
|
if (child.kind === 'text' && isBlank(child.text))
|
|
@@ -652,6 +676,7 @@ function layoutChildren(box, ctx, floats, contentTop, contentWidth, leading = 0)
|
|
|
652
676
|
childY = clearance;
|
|
653
677
|
}
|
|
654
678
|
const counted = clamp?.fit?.lines ?? 0;
|
|
679
|
+
const floatMark = floats.count;
|
|
655
680
|
if (!floats.isEmpty &&
|
|
656
681
|
(child.kind === 'replaced' || establishesBFC(child))) {
|
|
657
682
|
layoutBesideFloats(child, ctx, floats, contentLeft, childY, contentWidth);
|
|
@@ -659,6 +684,17 @@ function layoutChildren(box, ctx, floats, contentTop, contentWidth, leading = 0)
|
|
|
659
684
|
else {
|
|
660
685
|
layoutBlockLevel(child, ctx, floats, contentLeft, childY, contentWidth);
|
|
661
686
|
}
|
|
687
|
+
if (pushed !== null) {
|
|
688
|
+
const line = firstLineIn(child);
|
|
689
|
+
if (line) {
|
|
690
|
+
const push = pushed - (line.y + line.baseline - child.y);
|
|
691
|
+
if (push > 0) {
|
|
692
|
+
translate(child, 0, push);
|
|
693
|
+
floats.moveSince(floatMark, push);
|
|
694
|
+
}
|
|
695
|
+
pushed = null;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
662
698
|
// a block with none of the flow's lines in it — an image, a box of a
|
|
663
699
|
// formatting context of its own — puts the clamp point of an `auto`
|
|
664
700
|
// clamp before it where it ends below the room
|
|
@@ -674,6 +710,10 @@ function layoutChildren(box, ctx, floats, contentTop, contentWidth, leading = 0)
|
|
|
674
710
|
}
|
|
675
711
|
first = false;
|
|
676
712
|
const moved = childY !== at;
|
|
713
|
+
if (moved)
|
|
714
|
+
CLEARED_FROM.set(child, at);
|
|
715
|
+
else
|
|
716
|
+
CLEARED_FROM.delete(child);
|
|
677
717
|
if (!moved && collapsesThrough(child)) {
|
|
678
718
|
// nothing in it parts its margins: they and the ones either side of
|
|
679
719
|
// it are one (CSS 2.1 8.3.1), still hanging for what comes next —
|
|
@@ -792,11 +832,21 @@ function layoutBesideFloats(box, ctx, floats, contentLeft, y, contentWidth) {
|
|
|
792
832
|
band = over;
|
|
793
833
|
continue;
|
|
794
834
|
}
|
|
835
|
+
// Where no float narrows the room on either side, the box is where
|
|
836
|
+
// it would be were there none, and one too wide for its containing
|
|
837
|
+
// block overflows it here: below the floats it would be the same box
|
|
838
|
+
// in the same room. Blink tests a fit only against a side a float is
|
|
839
|
+
// on (`can_expand_outside_opportunity`, BlockLayoutAlgorithm::
|
|
840
|
+
// LayoutNewFormattingContext). Design 209's 247px heading, which
|
|
841
|
+
// clips its overflow, in a 240px column beside a float that ends
|
|
842
|
+
// left of the column, went under the float, 555px down.
|
|
843
|
+
if (lo === -Infinity && hi === Infinity)
|
|
844
|
+
fits = true;
|
|
795
845
|
// What is too wide overflows at the end of the line, as far as a
|
|
796
846
|
// negative margin there takes it, but no further into a float or
|
|
797
847
|
// past the room; at the start it would run into the floats, and
|
|
798
848
|
// waits below them (the suite's floats-wrap-bfc-with-margin tests)
|
|
799
|
-
if (inRoom) {
|
|
849
|
+
else if (inRoom) {
|
|
800
850
|
fits = box.marginLeft + box.width + box.marginRight <= room + 0.5;
|
|
801
851
|
}
|
|
802
852
|
else if (rtl) {
|
|
@@ -1397,6 +1447,10 @@ function layoutBox(box, ctx, borderBoxWidth, x, y, outerFloats) {
|
|
|
1397
1447
|
MARKER_ROOM.set(box, room);
|
|
1398
1448
|
else
|
|
1399
1449
|
MARKER_ROOM.delete(box);
|
|
1450
|
+
if (box.style.listStylePosition === 'inside')
|
|
1451
|
+
MARKER_ASCENT.delete(box);
|
|
1452
|
+
else
|
|
1453
|
+
MARKER_ASCENT.set(box, markerAscent(box, box.marker, ctx.fonts));
|
|
1400
1454
|
}
|
|
1401
1455
|
const flow = layoutChildren(box, ctx, floats, box.contentY, contentWidth);
|
|
1402
1456
|
// A list item with a marker and no line holds one, the marker's, a line
|
|
@@ -1475,6 +1529,26 @@ function markerRoom(box, marker, fonts) {
|
|
|
1475
1529
|
? strutOf(fonts, marker.style)
|
|
1476
1530
|
: null;
|
|
1477
1531
|
}
|
|
1532
|
+
/**
|
|
1533
|
+
* How far an outside marker reaches above the baseline it sits on. The
|
|
1534
|
+
* marker is a line of its own face, the item's or a `::marker` rule's, so a
|
|
1535
|
+
* bullet or a number reaches its face's ascent on that line, and an image,
|
|
1536
|
+
* set on the line bottom on the baseline, the higher of that and its own
|
|
1537
|
+
* height. Where the item's first line is in a block inside it — a link set
|
|
1538
|
+
* `display: block`, a paragraph — and the block's first baseline is nearer
|
|
1539
|
+
* its top than that, the block goes lower by the difference, and its line
|
|
1540
|
+
* stays the height it was: CSS 2.1 (12.5.1) leaves this to the user agent,
|
|
1541
|
+
* and Blink aligns the marker's baseline with the block's and pushes the
|
|
1542
|
+
* block down (`UnpositionedListMarker::AddToBox`). Its first line grew
|
|
1543
|
+
* instead, and design 196's links, under 18px bullets, were 21px tall where
|
|
1544
|
+
* Chrome has them 14px, 7px lower. On the item's own line the two come to
|
|
1545
|
+
* the same: the line grows by what the push would have moved it.
|
|
1546
|
+
*/
|
|
1547
|
+
const MARKER_ASCENT = new WeakMap();
|
|
1548
|
+
function markerAscent(box, marker, fonts) {
|
|
1549
|
+
const ascent = strutOf(fonts, marker.style ?? box.style).ascent;
|
|
1550
|
+
return marker.image ? Math.max(marker.image.height, ascent) : ascent;
|
|
1551
|
+
}
|
|
1478
1552
|
/** The first line box anywhere under a box, in layout order. */
|
|
1479
1553
|
function firstLineIn(box) {
|
|
1480
1554
|
if (box.lines?.length)
|
|
@@ -2358,11 +2432,20 @@ function wordBound(box, fonts, measured) {
|
|
|
2358
2432
|
for (const line of box.lines) {
|
|
2359
2433
|
if (unbroken)
|
|
2360
2434
|
widest = Math.max(widest, line.width);
|
|
2435
|
+
// a word across inline boxes' edges is in two fragments of text, and
|
|
2436
|
+
// as wide as its parts in both and the edges between: bound by the
|
|
2437
|
+
// widest word of each, a float in a narrow room took a letter of a
|
|
2438
|
+
// word of letters in bordered spans for its least width, and was cut
|
|
2439
|
+
// to the room (`joinsBefore`)
|
|
2440
|
+
let chain = 0;
|
|
2361
2441
|
for (const text of line.texts) {
|
|
2362
|
-
|
|
2442
|
+
const joins = joinsBefore(text);
|
|
2443
|
+
if (joins === undefined && text.layout === last)
|
|
2363
2444
|
continue;
|
|
2364
2445
|
last = text.layout;
|
|
2365
|
-
|
|
2446
|
+
const own = widestWord(fonts, text.layout, measured);
|
|
2447
|
+
chain = joins === undefined ? own : chain + joins + own;
|
|
2448
|
+
widest = Math.max(widest, chain);
|
|
2366
2449
|
}
|
|
2367
2450
|
for (const placed of line.atomics) {
|
|
2368
2451
|
const b = placed.box;
|
|
@@ -3448,10 +3531,11 @@ export function establishesBFC(box) {
|
|
|
3448
3531
|
}
|
|
3449
3532
|
/** What a box's `position: relative` offset moves it by, applied after
|
|
3450
3533
|
* layout so it does not affect anything else's position — which is the
|
|
3451
|
-
* whole of what makes it *relative* — and its translation with it
|
|
3452
|
-
|
|
3534
|
+
* whole of what makes it *relative* — and its translation with it, and
|
|
3535
|
+
* where `position: sticky` puts one at rest (`stickyOffset`). */
|
|
3536
|
+
export function applyRelativeOffsets(box, viewportWidth, viewportHeight) {
|
|
3453
3537
|
for (const child of box.children)
|
|
3454
|
-
applyRelativeOffsets(child);
|
|
3538
|
+
applyRelativeOffsets(child, viewportWidth, viewportHeight);
|
|
3455
3539
|
const style = box.style;
|
|
3456
3540
|
if (transformed(style) && box.kind !== 'inline') {
|
|
3457
3541
|
// a transform moves the box it is on, and an inline box is none
|
|
@@ -3463,7 +3547,9 @@ export function applyRelativeOffsets(box) {
|
|
|
3463
3547
|
}
|
|
3464
3548
|
if (style.position !== 'relative' && style.position !== 'sticky')
|
|
3465
3549
|
return;
|
|
3466
|
-
const [dx, dy] =
|
|
3550
|
+
const [dx, dy] = style.position === 'sticky'
|
|
3551
|
+
? stickyOffset(box, viewportWidth, viewportHeight)
|
|
3552
|
+
: relativeOffset(box);
|
|
3467
3553
|
if (!(dx || dy))
|
|
3468
3554
|
return;
|
|
3469
3555
|
translate(box, dx, dy);
|
|
@@ -3485,10 +3571,10 @@ export function transformed(style) {
|
|
|
3485
3571
|
}
|
|
3486
3572
|
/** How far `translate` and a `transform` move a box: a percentage is of
|
|
3487
3573
|
* its own border box (CSS Transforms 1, 7). */
|
|
3488
|
-
function translationOf(box) {
|
|
3574
|
+
function translationOf(box, style = box.style) {
|
|
3489
3575
|
let dx = 0;
|
|
3490
3576
|
let dy = 0;
|
|
3491
|
-
for (const moved of [
|
|
3577
|
+
for (const moved of [style.translate, style.transformTranslate]) {
|
|
3492
3578
|
if (!moved)
|
|
3493
3579
|
continue;
|
|
3494
3580
|
dx += resolve(moved[0], box.width, 0);
|
|
@@ -3496,6 +3582,21 @@ function translationOf(box) {
|
|
|
3496
3582
|
}
|
|
3497
3583
|
return [dx, dy];
|
|
3498
3584
|
}
|
|
3585
|
+
/**
|
|
3586
|
+
* Move a laid-out box, and everything in it, by how far its translation
|
|
3587
|
+
* changed when its style went from `was` to the one it has — what
|
|
3588
|
+
* `applyRelativeOffsets` moves it by now, less what it moved it by then.
|
|
3589
|
+
* For a style changed in place, where nothing else moves (a `transform` is
|
|
3590
|
+
* what makes that true). Not for an inline box, whose text is what moves.
|
|
3591
|
+
*/
|
|
3592
|
+
export function retranslate(box, was) {
|
|
3593
|
+
const [x0, y0] = translationOf(box, was);
|
|
3594
|
+
const [x1, y1] = translationOf(box);
|
|
3595
|
+
if (x1 === x0 && y1 === y0)
|
|
3596
|
+
return;
|
|
3597
|
+
translate(box, x1 - x0, y1 - y0);
|
|
3598
|
+
movedOffLine(box);
|
|
3599
|
+
}
|
|
3499
3600
|
/** How far `position: relative` moves a box. */
|
|
3500
3601
|
function relativeOffset(box) {
|
|
3501
3602
|
const style = box.style;
|
|
@@ -3513,6 +3614,72 @@ function relativeOffset(box) {
|
|
|
3513
3614
|
const dy = top ?? (bottom !== null ? -bottom : 0);
|
|
3514
3615
|
return [dx, dy];
|
|
3515
3616
|
}
|
|
3617
|
+
/**
|
|
3618
|
+
* Where `position: sticky` puts a box at rest (CSS Positioned Layout 3,
|
|
3619
|
+
* 3.4): moved only as far as keeps its border box inside the sticky view
|
|
3620
|
+
* rectangle — its nearest scroll container's scrollport, scrolled to its
|
|
3621
|
+
* start, less its insets — and no further than keeps its margin box in its
|
|
3622
|
+
* containing block, `top` winning over `bottom` and the start side over the
|
|
3623
|
+
* end. Nothing here scrolls a box the document holds, so for one of those
|
|
3624
|
+
* this is where the box stays. The viewport does scroll, and the document
|
|
3625
|
+
* with it, and a sticky box does not follow: against the viewport only its
|
|
3626
|
+
* `top` and its start side are kept, which at rest put a box as a browser
|
|
3627
|
+
* does, while a `bottom: 0` would pin a footer to the middle of the page
|
|
3628
|
+
* once it was scrolled. Taken as `relative`, a box stood its `top` below
|
|
3629
|
+
* where a browser starts it: Wikipedia's contents, 24px low.
|
|
3630
|
+
*/
|
|
3631
|
+
function stickyOffset(box, viewportWidth, viewportHeight) {
|
|
3632
|
+
const style = box.style;
|
|
3633
|
+
// the scroll container a sticky box keeps to: the nearest box that
|
|
3634
|
+
// scrolls, or the viewport, whose are the root's and the body's overflow
|
|
3635
|
+
let port = box.parent;
|
|
3636
|
+
while (port && !scrolls(port.style))
|
|
3637
|
+
port = port.parent;
|
|
3638
|
+
const tag = port?.el?.name;
|
|
3639
|
+
const inside = !!port && tag !== 'html' && tag !== 'body';
|
|
3640
|
+
let cb = box.parent;
|
|
3641
|
+
while (cb && cb.kind === 'inline')
|
|
3642
|
+
cb = cb.parent;
|
|
3643
|
+
if (!cb)
|
|
3644
|
+
return [0, 0];
|
|
3645
|
+
// the scrollport, at its start: a scroll container's padding box, or
|
|
3646
|
+
// the viewport, which the document's top is at
|
|
3647
|
+
const px = port && inside ? port.x + port.borderLeft : 0;
|
|
3648
|
+
const py = port && inside ? port.y + port.borderTop : 0;
|
|
3649
|
+
const pw = port && inside
|
|
3650
|
+
? port.width - port.borderLeft - port.borderRight
|
|
3651
|
+
: viewportWidth;
|
|
3652
|
+
const ph = port && inside
|
|
3653
|
+
? port.height - port.borderTop - port.borderBottom
|
|
3654
|
+
: viewportHeight;
|
|
3655
|
+
const dx = stuck(box.x, box.width, box.marginLeft, box.marginRight, cb.contentX, cb.contentWidth, px, pw, resolveOrNull(style.left, pw), inside ? resolveOrNull(style.right, pw) : null,
|
|
3656
|
+
// `left` wins where both hold, or `right` in a right-to-left block
|
|
3657
|
+
cb.style.direction !== 'rtl');
|
|
3658
|
+
const dy = stuck(box.y, box.height, box.marginTop, box.marginBottom, cb.contentY, cb.contentHeight, py, ph, resolveOrNull(style.top, ph), inside ? resolveOrNull(style.bottom, ph) : null, true);
|
|
3659
|
+
return [dx, dy];
|
|
3660
|
+
}
|
|
3661
|
+
/**
|
|
3662
|
+
* How far a sticky box moves along one axis: toward the end until its
|
|
3663
|
+
* start edge is `start` inside the scrollport's, or toward the start until
|
|
3664
|
+
* its end edge is `end` inside the scrollport's, each no further than its
|
|
3665
|
+
* margin box stays in its containing block — and where both would move
|
|
3666
|
+
* it, `startWins` says which does.
|
|
3667
|
+
*/
|
|
3668
|
+
function stuck(at, size, marginStart, marginEnd, cbAt, cbSize, portAt, portSize, start, end, startWins) {
|
|
3669
|
+
let byStart = 0;
|
|
3670
|
+
if (start !== null && Number.isFinite(start) && at < portAt + start) {
|
|
3671
|
+
const room = cbAt + cbSize - (at + size + marginEnd);
|
|
3672
|
+
byStart = Math.max(0, Math.min(portAt + start - at, room));
|
|
3673
|
+
}
|
|
3674
|
+
let byEnd = 0;
|
|
3675
|
+
if (end !== null && Number.isFinite(end)) {
|
|
3676
|
+
const over = at + size - (portAt + portSize - end);
|
|
3677
|
+
const room = at - marginStart - cbAt;
|
|
3678
|
+
if (over > 0)
|
|
3679
|
+
byEnd = -Math.max(0, Math.min(over, room));
|
|
3680
|
+
}
|
|
3681
|
+
return startWins ? byStart || byEnd : byEnd || byStart;
|
|
3682
|
+
}
|
|
3516
3683
|
/**
|
|
3517
3684
|
* Move an inline box's text where `position: relative` puts the box. Its
|
|
3518
3685
|
* text is on its block's lines, laid out apart from the text around it
|