@react-x11/components 0.11.0 → 0.12.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 +26 -7
- package/dist/html/controls.d.ts.map +1 -1
- package/dist/html/controls.js +28 -3
- package/dist/html/controls.js.map +1 -1
- package/dist/html/css/cascade.d.ts.map +1 -1
- package/dist/html/css/cascade.js +19 -6
- 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 +11 -0
- package/dist/html/css/parse.d.ts.map +1 -1
- package/dist/html/css/parse.js +114 -4
- package/dist/html/css/parse.js.map +1 -1
- package/dist/html/css/style.d.ts +38 -1
- package/dist/html/css/style.d.ts.map +1 -1
- package/dist/html/css/style.js +326 -8
- package/dist/html/css/style.js.map +1 -1
- package/dist/html/css/ua.js +14 -0
- 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 +35 -2
- package/dist/html/dom.js.map +1 -1
- package/dist/html/index.d.ts.map +1 -1
- package/dist/html/index.js +38 -1
- 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 +181 -18
- package/dist/html/layout/block.js.map +1 -1
- package/dist/html/layout/boxes.d.ts +34 -6
- package/dist/html/layout/boxes.d.ts.map +1 -1
- package/dist/html/layout/boxes.js +35 -14
- 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/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 +1222 -115
- package/dist/html/layout/inline.js.map +1 -1
- package/dist/html/node.d.ts +33 -0
- package/dist/html/node.d.ts.map +1 -1
- package/dist/html/node.js +512 -51
- package/dist/html/node.js.map +1 -1
- package/dist/html/paint.d.ts +53 -1
- package/dist/html/paint.d.ts.map +1 -1
- package/dist/html/paint.js +546 -180
- 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/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 +5 -3
- package/src/flow/node.ts +80 -64
- package/src/html/controls.ts +50 -9
- package/src/html/css/cascade.ts +19 -6
- package/src/html/css/color.ts +87 -0
- package/src/html/css/parse.ts +107 -4
- package/src/html/css/style.ts +343 -8
- package/src/html/css/ua.ts +14 -0
- package/src/html/css/values.ts +31 -3
- package/src/html/css/vars.ts +2 -2
- package/src/html/dom.ts +38 -2
- package/src/html/index.ts +39 -1
- package/src/html/layout/block.ts +228 -16
- package/src/html/layout/boxes.ts +55 -21
- package/src/html/layout/cache.ts +8 -3
- package/src/html/layout/floats.ts +24 -0
- package/src/html/layout/inline.ts +1435 -108
- package/src/html/node.ts +535 -54
- package/src/html/paint.ts +650 -241
- package/src/html/surfaces.ts +21 -1
- package/src/internal/window.ts +36 -8
- package/src/richtext/node.ts +7 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../../../src/html/layout/block.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAEV,aAAa,EACb,WAAW,EAEZ,MAAM,iBAAiB,CAAC;AAUzB,OAAO,EAEL,GAAG,EAWJ,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EACV,OAAO,EACP,eAAe,EAMhB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../../../src/html/layout/block.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAEV,aAAa,EACb,WAAW,EAEZ,MAAM,iBAAiB,CAAC;AAUzB,OAAO,EAEL,GAAG,EAWJ,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EACV,OAAO,EACP,eAAe,EAMhB,MAAM,YAAY,CAAC;AAWpB,OAAO,KAAK,EAAE,SAAS,EAA+B,MAAM,aAAa,CAAC;AAe1E,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;IACxB,oEAAoE;IACpE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,oEAAoE;IACpE,eAAe,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;IACzC;uCACmC;IACnC,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;gCAC4B;IAC5B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB;yEACqE;IACrE,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;+EAE2E;IAC3E,UAA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AAI,CAO3D;AAED;4EAC4E;AAC5E,wBAAgB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,GAAG,IAAI,CAGtD;AA6BD;;iEAEiE;AACjE,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,eAAe,EAAE,MAAM,GAAG,IAAI,CAiDpE;AAyCD;+DAC+D;AAC/D,wBAAgB,cAAc,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CA8BhD;AAED;;;kEAGkE;AAClE,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,GAAG,EACR,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,MAAM,GACrB,IAAI,CA2BN;AAED;sEACsE;AACtE,wBAAgB,WAAW,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAEzD;AAeD;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,aAAa,GAAG,IAAI,CAM9D"}
|
|
@@ -15,11 +15,11 @@ import { CONTAIN_INLINE_SIZE, CONTAIN_LAYOUT, CONTAIN_PAINT, CONTAIN_SIZE, scrol
|
|
|
15
15
|
import { lineOf, spanToName } from './grid-lines.js';
|
|
16
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';
|
|
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
|
|
@@ -792,11 +828,21 @@ function layoutBesideFloats(box, ctx, floats, contentLeft, y, contentWidth) {
|
|
|
792
828
|
band = over;
|
|
793
829
|
continue;
|
|
794
830
|
}
|
|
831
|
+
// Where no float narrows the room on either side, the box is where
|
|
832
|
+
// it would be were there none, and one too wide for its containing
|
|
833
|
+
// block overflows it here: below the floats it would be the same box
|
|
834
|
+
// in the same room. Blink tests a fit only against a side a float is
|
|
835
|
+
// on (`can_expand_outside_opportunity`, BlockLayoutAlgorithm::
|
|
836
|
+
// LayoutNewFormattingContext). Design 209's 247px heading, which
|
|
837
|
+
// clips its overflow, in a 240px column beside a float that ends
|
|
838
|
+
// left of the column, went under the float, 555px down.
|
|
839
|
+
if (lo === -Infinity && hi === Infinity)
|
|
840
|
+
fits = true;
|
|
795
841
|
// What is too wide overflows at the end of the line, as far as a
|
|
796
842
|
// negative margin there takes it, but no further into a float or
|
|
797
843
|
// past the room; at the start it would run into the floats, and
|
|
798
844
|
// waits below them (the suite's floats-wrap-bfc-with-margin tests)
|
|
799
|
-
if (inRoom) {
|
|
845
|
+
else if (inRoom) {
|
|
800
846
|
fits = box.marginLeft + box.width + box.marginRight <= room + 0.5;
|
|
801
847
|
}
|
|
802
848
|
else if (rtl) {
|
|
@@ -1397,6 +1443,10 @@ function layoutBox(box, ctx, borderBoxWidth, x, y, outerFloats) {
|
|
|
1397
1443
|
MARKER_ROOM.set(box, room);
|
|
1398
1444
|
else
|
|
1399
1445
|
MARKER_ROOM.delete(box);
|
|
1446
|
+
if (box.style.listStylePosition === 'inside')
|
|
1447
|
+
MARKER_ASCENT.delete(box);
|
|
1448
|
+
else
|
|
1449
|
+
MARKER_ASCENT.set(box, markerAscent(box, box.marker, ctx.fonts));
|
|
1400
1450
|
}
|
|
1401
1451
|
const flow = layoutChildren(box, ctx, floats, box.contentY, contentWidth);
|
|
1402
1452
|
// A list item with a marker and no line holds one, the marker's, a line
|
|
@@ -1475,6 +1525,26 @@ function markerRoom(box, marker, fonts) {
|
|
|
1475
1525
|
? strutOf(fonts, marker.style)
|
|
1476
1526
|
: null;
|
|
1477
1527
|
}
|
|
1528
|
+
/**
|
|
1529
|
+
* How far an outside marker reaches above the baseline it sits on. The
|
|
1530
|
+
* marker is a line of its own face, the item's or a `::marker` rule's, so a
|
|
1531
|
+
* bullet or a number reaches its face's ascent on that line, and an image,
|
|
1532
|
+
* set on the line bottom on the baseline, the higher of that and its own
|
|
1533
|
+
* height. Where the item's first line is in a block inside it — a link set
|
|
1534
|
+
* `display: block`, a paragraph — and the block's first baseline is nearer
|
|
1535
|
+
* its top than that, the block goes lower by the difference, and its line
|
|
1536
|
+
* stays the height it was: CSS 2.1 (12.5.1) leaves this to the user agent,
|
|
1537
|
+
* and Blink aligns the marker's baseline with the block's and pushes the
|
|
1538
|
+
* block down (`UnpositionedListMarker::AddToBox`). Its first line grew
|
|
1539
|
+
* instead, and design 196's links, under 18px bullets, were 21px tall where
|
|
1540
|
+
* Chrome has them 14px, 7px lower. On the item's own line the two come to
|
|
1541
|
+
* the same: the line grows by what the push would have moved it.
|
|
1542
|
+
*/
|
|
1543
|
+
const MARKER_ASCENT = new WeakMap();
|
|
1544
|
+
function markerAscent(box, marker, fonts) {
|
|
1545
|
+
const ascent = strutOf(fonts, marker.style ?? box.style).ascent;
|
|
1546
|
+
return marker.image ? Math.max(marker.image.height, ascent) : ascent;
|
|
1547
|
+
}
|
|
1478
1548
|
/** The first line box anywhere under a box, in layout order. */
|
|
1479
1549
|
function firstLineIn(box) {
|
|
1480
1550
|
if (box.lines?.length)
|
|
@@ -2358,11 +2428,20 @@ function wordBound(box, fonts, measured) {
|
|
|
2358
2428
|
for (const line of box.lines) {
|
|
2359
2429
|
if (unbroken)
|
|
2360
2430
|
widest = Math.max(widest, line.width);
|
|
2431
|
+
// a word across inline boxes' edges is in two fragments of text, and
|
|
2432
|
+
// as wide as its parts in both and the edges between: bound by the
|
|
2433
|
+
// widest word of each, a float in a narrow room took a letter of a
|
|
2434
|
+
// word of letters in bordered spans for its least width, and was cut
|
|
2435
|
+
// to the room (`joinsBefore`)
|
|
2436
|
+
let chain = 0;
|
|
2361
2437
|
for (const text of line.texts) {
|
|
2362
|
-
|
|
2438
|
+
const joins = joinsBefore(text);
|
|
2439
|
+
if (joins === undefined && text.layout === last)
|
|
2363
2440
|
continue;
|
|
2364
2441
|
last = text.layout;
|
|
2365
|
-
|
|
2442
|
+
const own = widestWord(fonts, text.layout, measured);
|
|
2443
|
+
chain = joins === undefined ? own : chain + joins + own;
|
|
2444
|
+
widest = Math.max(widest, chain);
|
|
2366
2445
|
}
|
|
2367
2446
|
for (const placed of line.atomics) {
|
|
2368
2447
|
const b = placed.box;
|
|
@@ -3448,10 +3527,11 @@ export function establishesBFC(box) {
|
|
|
3448
3527
|
}
|
|
3449
3528
|
/** What a box's `position: relative` offset moves it by, applied after
|
|
3450
3529
|
* 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
|
-
|
|
3530
|
+
* whole of what makes it *relative* — and its translation with it, and
|
|
3531
|
+
* where `position: sticky` puts one at rest (`stickyOffset`). */
|
|
3532
|
+
export function applyRelativeOffsets(box, viewportWidth, viewportHeight) {
|
|
3453
3533
|
for (const child of box.children)
|
|
3454
|
-
applyRelativeOffsets(child);
|
|
3534
|
+
applyRelativeOffsets(child, viewportWidth, viewportHeight);
|
|
3455
3535
|
const style = box.style;
|
|
3456
3536
|
if (transformed(style) && box.kind !== 'inline') {
|
|
3457
3537
|
// a transform moves the box it is on, and an inline box is none
|
|
@@ -3463,7 +3543,9 @@ export function applyRelativeOffsets(box) {
|
|
|
3463
3543
|
}
|
|
3464
3544
|
if (style.position !== 'relative' && style.position !== 'sticky')
|
|
3465
3545
|
return;
|
|
3466
|
-
const [dx, dy] =
|
|
3546
|
+
const [dx, dy] = style.position === 'sticky'
|
|
3547
|
+
? stickyOffset(box, viewportWidth, viewportHeight)
|
|
3548
|
+
: relativeOffset(box);
|
|
3467
3549
|
if (!(dx || dy))
|
|
3468
3550
|
return;
|
|
3469
3551
|
translate(box, dx, dy);
|
|
@@ -3485,10 +3567,10 @@ export function transformed(style) {
|
|
|
3485
3567
|
}
|
|
3486
3568
|
/** How far `translate` and a `transform` move a box: a percentage is of
|
|
3487
3569
|
* its own border box (CSS Transforms 1, 7). */
|
|
3488
|
-
function translationOf(box) {
|
|
3570
|
+
function translationOf(box, style = box.style) {
|
|
3489
3571
|
let dx = 0;
|
|
3490
3572
|
let dy = 0;
|
|
3491
|
-
for (const moved of [
|
|
3573
|
+
for (const moved of [style.translate, style.transformTranslate]) {
|
|
3492
3574
|
if (!moved)
|
|
3493
3575
|
continue;
|
|
3494
3576
|
dx += resolve(moved[0], box.width, 0);
|
|
@@ -3496,6 +3578,21 @@ function translationOf(box) {
|
|
|
3496
3578
|
}
|
|
3497
3579
|
return [dx, dy];
|
|
3498
3580
|
}
|
|
3581
|
+
/**
|
|
3582
|
+
* Move a laid-out box, and everything in it, by how far its translation
|
|
3583
|
+
* changed when its style went from `was` to the one it has — what
|
|
3584
|
+
* `applyRelativeOffsets` moves it by now, less what it moved it by then.
|
|
3585
|
+
* For a style changed in place, where nothing else moves (a `transform` is
|
|
3586
|
+
* what makes that true). Not for an inline box, whose text is what moves.
|
|
3587
|
+
*/
|
|
3588
|
+
export function retranslate(box, was) {
|
|
3589
|
+
const [x0, y0] = translationOf(box, was);
|
|
3590
|
+
const [x1, y1] = translationOf(box);
|
|
3591
|
+
if (x1 === x0 && y1 === y0)
|
|
3592
|
+
return;
|
|
3593
|
+
translate(box, x1 - x0, y1 - y0);
|
|
3594
|
+
movedOffLine(box);
|
|
3595
|
+
}
|
|
3499
3596
|
/** How far `position: relative` moves a box. */
|
|
3500
3597
|
function relativeOffset(box) {
|
|
3501
3598
|
const style = box.style;
|
|
@@ -3513,6 +3610,72 @@ function relativeOffset(box) {
|
|
|
3513
3610
|
const dy = top ?? (bottom !== null ? -bottom : 0);
|
|
3514
3611
|
return [dx, dy];
|
|
3515
3612
|
}
|
|
3613
|
+
/**
|
|
3614
|
+
* Where `position: sticky` puts a box at rest (CSS Positioned Layout 3,
|
|
3615
|
+
* 3.4): moved only as far as keeps its border box inside the sticky view
|
|
3616
|
+
* rectangle — its nearest scroll container's scrollport, scrolled to its
|
|
3617
|
+
* start, less its insets — and no further than keeps its margin box in its
|
|
3618
|
+
* containing block, `top` winning over `bottom` and the start side over the
|
|
3619
|
+
* end. Nothing here scrolls a box the document holds, so for one of those
|
|
3620
|
+
* this is where the box stays. The viewport does scroll, and the document
|
|
3621
|
+
* with it, and a sticky box does not follow: against the viewport only its
|
|
3622
|
+
* `top` and its start side are kept, which at rest put a box as a browser
|
|
3623
|
+
* does, while a `bottom: 0` would pin a footer to the middle of the page
|
|
3624
|
+
* once it was scrolled. Taken as `relative`, a box stood its `top` below
|
|
3625
|
+
* where a browser starts it: Wikipedia's contents, 24px low.
|
|
3626
|
+
*/
|
|
3627
|
+
function stickyOffset(box, viewportWidth, viewportHeight) {
|
|
3628
|
+
const style = box.style;
|
|
3629
|
+
// the scroll container a sticky box keeps to: the nearest box that
|
|
3630
|
+
// scrolls, or the viewport, whose are the root's and the body's overflow
|
|
3631
|
+
let port = box.parent;
|
|
3632
|
+
while (port && !scrolls(port.style))
|
|
3633
|
+
port = port.parent;
|
|
3634
|
+
const tag = port?.el?.name;
|
|
3635
|
+
const inside = !!port && tag !== 'html' && tag !== 'body';
|
|
3636
|
+
let cb = box.parent;
|
|
3637
|
+
while (cb && cb.kind === 'inline')
|
|
3638
|
+
cb = cb.parent;
|
|
3639
|
+
if (!cb)
|
|
3640
|
+
return [0, 0];
|
|
3641
|
+
// the scrollport, at its start: a scroll container's padding box, or
|
|
3642
|
+
// the viewport, which the document's top is at
|
|
3643
|
+
const px = port && inside ? port.x + port.borderLeft : 0;
|
|
3644
|
+
const py = port && inside ? port.y + port.borderTop : 0;
|
|
3645
|
+
const pw = port && inside
|
|
3646
|
+
? port.width - port.borderLeft - port.borderRight
|
|
3647
|
+
: viewportWidth;
|
|
3648
|
+
const ph = port && inside
|
|
3649
|
+
? port.height - port.borderTop - port.borderBottom
|
|
3650
|
+
: viewportHeight;
|
|
3651
|
+
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,
|
|
3652
|
+
// `left` wins where both hold, or `right` in a right-to-left block
|
|
3653
|
+
cb.style.direction !== 'rtl');
|
|
3654
|
+
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);
|
|
3655
|
+
return [dx, dy];
|
|
3656
|
+
}
|
|
3657
|
+
/**
|
|
3658
|
+
* How far a sticky box moves along one axis: toward the end until its
|
|
3659
|
+
* start edge is `start` inside the scrollport's, or toward the start until
|
|
3660
|
+
* its end edge is `end` inside the scrollport's, each no further than its
|
|
3661
|
+
* margin box stays in its containing block — and where both would move
|
|
3662
|
+
* it, `startWins` says which does.
|
|
3663
|
+
*/
|
|
3664
|
+
function stuck(at, size, marginStart, marginEnd, cbAt, cbSize, portAt, portSize, start, end, startWins) {
|
|
3665
|
+
let byStart = 0;
|
|
3666
|
+
if (start !== null && Number.isFinite(start) && at < portAt + start) {
|
|
3667
|
+
const room = cbAt + cbSize - (at + size + marginEnd);
|
|
3668
|
+
byStart = Math.max(0, Math.min(portAt + start - at, room));
|
|
3669
|
+
}
|
|
3670
|
+
let byEnd = 0;
|
|
3671
|
+
if (end !== null && Number.isFinite(end)) {
|
|
3672
|
+
const over = at + size - (portAt + portSize - end);
|
|
3673
|
+
const room = at - marginStart - cbAt;
|
|
3674
|
+
if (over > 0)
|
|
3675
|
+
byEnd = -Math.max(0, Math.min(over, room));
|
|
3676
|
+
}
|
|
3677
|
+
return startWins ? byStart || byEnd : byEnd || byStart;
|
|
3678
|
+
}
|
|
3516
3679
|
/**
|
|
3517
3680
|
* Move an inline box's text where `position: relative` puts the box. Its
|
|
3518
3681
|
* text is on its block's lines, laid out apart from the text around it
|