@swiftbrowser/web 0.9.5 → 0.9.6
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/package.json +1 -1
- package/src/hostInset.ts +26 -0
- package/src/layoutDom.ts +24 -0
package/package.json
CHANGED
package/src/hostInset.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `host` that is a list row is drawn in the row's box (the card's width,
|
|
3
|
+
* the row's height with its padding), as every row is, while the engine
|
|
4
|
+
* measured and placed its content in the row's content frame inside it.
|
|
5
|
+
* The content element goes back into that frame, as a text row's text is
|
|
6
|
+
* padded into its own (layoutDom.ts), so DOM content that fills its box
|
|
7
|
+
* (`sizing: "fill"`, `height: 100%`) fills what it was measured for and
|
|
8
|
+
* not the row's padding too.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { Rect } from './layout';
|
|
12
|
+
|
|
13
|
+
export interface HostContentInset {
|
|
14
|
+
left: number;
|
|
15
|
+
top: number;
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Where the content sits inside the element's box; null when the box is the frame (nothing to set). */
|
|
21
|
+
export function hostContentInset(box: Rect, frame: Rect): HostContentInset | null {
|
|
22
|
+
const left = frame.x - box.x;
|
|
23
|
+
const top = frame.y - box.y;
|
|
24
|
+
if (left === 0 && top === 0 && frame.width === box.width && frame.height === box.height) return null;
|
|
25
|
+
return { left, top, width: frame.width, height: frame.height };
|
|
26
|
+
}
|
package/src/layoutDom.ts
CHANGED
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
*/
|
|
35
35
|
|
|
36
36
|
import type { LayoutEnvironment, LayoutNode, LayoutResult, Rect, ResolvedFont, TextLayout } from './layout';
|
|
37
|
+
import { hostContentInset } from './hostInset';
|
|
37
38
|
import { listRowBackgroundOf } from './layout';
|
|
38
39
|
import { styleToCSS } from './styles';
|
|
39
40
|
import type { ShapeStyle } from './protocol';
|
|
@@ -488,6 +489,26 @@ function setFlag(el: HTMLElement, key: string, value: string | null): void {
|
|
|
488
489
|
}
|
|
489
490
|
}
|
|
490
491
|
|
|
492
|
+
/**
|
|
493
|
+
* A host's content element goes back into the engine's frame when the host
|
|
494
|
+
* is drawn in a bigger box (a list row's): src/hostInset.ts. In its own
|
|
495
|
+
* frame the stylesheet's `width: 100%` (and `height: 100%` for `fill`) hold.
|
|
496
|
+
*/
|
|
497
|
+
function positionHostContent(el: HTMLElement, box: Rect, frame: Rect): void {
|
|
498
|
+
const content = el.querySelector<HTMLElement>(':scope > .sb-host-content');
|
|
499
|
+
if (!content) return;
|
|
500
|
+
const inset = hostContentInset(box, frame);
|
|
501
|
+
const s = content.style;
|
|
502
|
+
const left = inset ? `${inset.left}px` : '';
|
|
503
|
+
const top = inset ? `${inset.top}px` : '';
|
|
504
|
+
const width = inset ? `${inset.width}px` : '';
|
|
505
|
+
const height = inset ? `${inset.height}px` : '';
|
|
506
|
+
if (s.left !== left) s.left = left;
|
|
507
|
+
if (s.top !== top) s.top = top;
|
|
508
|
+
if (s.width !== width) s.width = width;
|
|
509
|
+
if (s.height !== height) s.height = height;
|
|
510
|
+
}
|
|
511
|
+
|
|
491
512
|
/**
|
|
492
513
|
* For leaf rows: pad the content frame back into place inside the row box.
|
|
493
514
|
* `shift` moves vertically centered content (a one-line field's text) down
|
|
@@ -617,6 +638,9 @@ function applyChrome(
|
|
|
617
638
|
padIntoFrame(el, box, frame);
|
|
618
639
|
return;
|
|
619
640
|
}
|
|
641
|
+
case 'host':
|
|
642
|
+
positionHostContent(el, box, frame);
|
|
643
|
+
return;
|
|
620
644
|
case 'image': {
|
|
621
645
|
const font = result.fonts.get(node.id);
|
|
622
646
|
if (font) {
|