@swiftbrowser/web 0.9.2 → 0.9.3
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/layout/engine.ts +3 -0
- package/src/layoutDom.ts +25 -0
- package/src/renderer.ts +75 -10
- package/src/styles.css +30 -8
- package/src/symbols.ts +15 -1
package/package.json
CHANGED
package/src/layout/engine.ts
CHANGED
|
@@ -3130,6 +3130,9 @@ export class LayoutPass {
|
|
|
3130
3130
|
this.placeDatePicker(node, ctx, p, x, y, size);
|
|
3131
3131
|
return;
|
|
3132
3132
|
case 'texteditor':
|
|
3133
|
+
// It draws in the context font, as a field does (the page's own
|
|
3134
|
+
// font otherwise: a serif where the page sets none).
|
|
3135
|
+
if (node.id >= 0) this.fonts.set(node.id, ctx.font);
|
|
3133
3136
|
return;
|
|
3134
3137
|
case 'swipeactions':
|
|
3135
3138
|
case 'contextmenu': {
|
package/src/layoutDom.ts
CHANGED
|
@@ -492,6 +492,30 @@ function padIntoFrame(el: HTMLElement, box: Rect, frame: Rect, shift = 0): void
|
|
|
492
492
|
if (s.paddingBottom !== paddingBottom) s.paddingBottom = paddingBottom;
|
|
493
493
|
}
|
|
494
494
|
|
|
495
|
+
/**
|
|
496
|
+
* A vertical field's textarea draws every line a leading apart, where the
|
|
497
|
+
* engine sized it as a Text: its first line a line height tall, the rest a
|
|
498
|
+
* leading apart. The textarea's lines need the difference more (2 px for
|
|
499
|
+
* the body style); without it they overflow by that much, and the textarea
|
|
500
|
+
* scrolls its text up while it is edited. The difference comes out of the
|
|
501
|
+
* padding below the lines (a list row's, a rounded border's), else the box
|
|
502
|
+
* reaches that much further down (into the space below it, which its lines
|
|
503
|
+
* leave empty).
|
|
504
|
+
*/
|
|
505
|
+
function fitFieldLines(el: HTMLTextAreaElement, font: ResolvedFont, box: Rect, frame: Rect): void {
|
|
506
|
+
const extra = Math.ceil(font.leading - font.lineHeight - 0.01);
|
|
507
|
+
if (extra <= 0) return;
|
|
508
|
+
const s = el.style;
|
|
509
|
+
const below = box.y + box.height - (frame.y + frame.height);
|
|
510
|
+
const padding = below > 0 ? below : el.dataset['sbStyle'] === 'roundedBorder' ? ROUNDED_FIELD_INSET : 0;
|
|
511
|
+
s.paddingBottom = `${Math.max(0, padding - extra)}px`;
|
|
512
|
+
const height = `${box.height + Math.max(0, extra - padding)}px`;
|
|
513
|
+
if (s.height !== height) s.height = height;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/** A rounded border field's padding above and below its lines (styles.css: the engine's inset of 6, less the 1 px border). */
|
|
517
|
+
const ROUNDED_FIELD_INSET = 5;
|
|
518
|
+
|
|
495
519
|
const fieldCapShifts = new Map<string, number>();
|
|
496
520
|
|
|
497
521
|
/**
|
|
@@ -597,6 +621,7 @@ function applyChrome(
|
|
|
597
621
|
? fieldCapShift(font) + (line ? line.y - frame.y - (frame.height - font.lineHeight) / 2 : 0)
|
|
598
622
|
: 0;
|
|
599
623
|
padIntoFrame(el, box, frame, shift);
|
|
624
|
+
if (el instanceof HTMLTextAreaElement && node.kind === 'textfield' && font) fitFieldLines(el, font, box, frame);
|
|
600
625
|
return;
|
|
601
626
|
}
|
|
602
627
|
// Phase 8 controls: their chrome sits at the engine's rects inside the element's box.
|
package/src/renderer.ts
CHANGED
|
@@ -433,10 +433,35 @@ export class Renderer {
|
|
|
433
433
|
/** The highest `scrollTo` serial seen: a command keeps its serial until the reader re-runs, and runs once. */
|
|
434
434
|
private scrollSerial = 0;
|
|
435
435
|
|
|
436
|
+
/**
|
|
437
|
+
* A row that taps its button (`rowAction`) highlights while pressed, as a
|
|
438
|
+
* row that is a button does (`:active`, styles.css): until the pointer is
|
|
439
|
+
* released or the press turns into a scroll.
|
|
440
|
+
*/
|
|
441
|
+
private readonly onRowPress = (event: PointerEvent): void => {
|
|
442
|
+
const hit = event.target as HTMLElement | null;
|
|
443
|
+
if (!hit || !event.isPrimary || hit.closest('.sb-button, .sb-navlink')) return;
|
|
444
|
+
const button = rowAction(hit, this.root);
|
|
445
|
+
const row = button ? listRowOf(button, this.root) : null;
|
|
446
|
+
if (!row) return;
|
|
447
|
+
row.dataset['sbRowPressed'] = '';
|
|
448
|
+
const release = (): void => {
|
|
449
|
+
delete row.dataset['sbRowPressed'];
|
|
450
|
+
window.removeEventListener('pointerup', release, true);
|
|
451
|
+
window.removeEventListener('pointercancel', release, true);
|
|
452
|
+
this.root.removeEventListener('scroll', release, true);
|
|
453
|
+
};
|
|
454
|
+
window.addEventListener('pointerup', release, true);
|
|
455
|
+
window.addEventListener('pointercancel', release, true);
|
|
456
|
+
this.root.addEventListener('scroll', release, true);
|
|
457
|
+
};
|
|
458
|
+
|
|
436
459
|
private readonly onClick = (event: MouseEvent): void => {
|
|
437
460
|
// `closest` picks the innermost control, so a button inside a
|
|
438
|
-
// `tapgesture` (or a menu label) handles the click alone.
|
|
439
|
-
|
|
461
|
+
// `tapgesture` (or a menu label) handles the click alone. Elsewhere in
|
|
462
|
+
// a list row, the row's one button (`rowAction`).
|
|
463
|
+
const hit = event.target as HTMLElement | null;
|
|
464
|
+
const target = hit?.closest<HTMLElement>(
|
|
440
465
|
'.sb-button, .sb-navlink, .sb-navbar-back, .sb-navbar-more, .sb-navsplit-toggle, .sb-switch, .sb-sheet-scrim, ' +
|
|
441
466
|
'.sb-tabbar-item, .sb-segment, .sb-picker-option, .sb-picker-menu-item, .sb-picker[data-sb-style="menu"], ' +
|
|
442
467
|
'.sb-menu, .sb-tapgesture, .sb-stepper-button, .sb-alert-scrim, .sb-alert-ok, ' +
|
|
@@ -444,7 +469,7 @@ export class Renderer {
|
|
|
444
469
|
'.sb-swipe-action, .sb-listrow-control, .sb-listrow[data-sb-selectable], ' +
|
|
445
470
|
// A link in a rich text: innermost, so it wins over a tappable row around the text
|
|
446
471
|
'.sb-link',
|
|
447
|
-
);
|
|
472
|
+
) ?? (hit ? rowAction(hit, this.root) : null);
|
|
448
473
|
if (!target || !this.root.contains(target)) return;
|
|
449
474
|
if (target.classList.contains('sb-link')) {
|
|
450
475
|
const text = target.closest<HTMLElement>('.sb-text');
|
|
@@ -820,6 +845,7 @@ export class Renderer {
|
|
|
820
845
|
// Delegated listeners instead of one per control: elements can be
|
|
821
846
|
// created detached and moved around freely.
|
|
822
847
|
root.addEventListener('click', this.onClick);
|
|
848
|
+
root.addEventListener('pointerdown', this.onRowPress);
|
|
823
849
|
root.addEventListener('keydown', this.onKeyDown);
|
|
824
850
|
root.addEventListener('input', this.onInput);
|
|
825
851
|
root.addEventListener('focusin', this.onFocusChange);
|
|
@@ -1502,6 +1528,7 @@ export class Renderer {
|
|
|
1502
1528
|
dispose(): void {
|
|
1503
1529
|
this.closeMenu();
|
|
1504
1530
|
this.root.removeEventListener('click', this.onClick);
|
|
1531
|
+
this.root.removeEventListener('pointerdown', this.onRowPress);
|
|
1505
1532
|
this.root.removeEventListener('keydown', this.onKeyDown);
|
|
1506
1533
|
this.root.removeEventListener('input', this.onInput);
|
|
1507
1534
|
this.root.removeEventListener('focusin', this.onFocusChange);
|
|
@@ -1688,12 +1715,17 @@ export class Renderer {
|
|
|
1688
1715
|
// props produced before applying the new ones. The layout box is kept:
|
|
1689
1716
|
// the engine re-lays out at `commit`, and removals recorded later in the
|
|
1690
1717
|
// pass measure their old position against intact ancestors.
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
if (
|
|
1695
|
-
|
|
1696
|
-
|
|
1718
|
+
// A text input's props produce no inline style (layout sets its box,
|
|
1719
|
+
// font and padding), and it is updated on every keystroke while it is
|
|
1720
|
+
// being edited: its style stays as it is.
|
|
1721
|
+
if (kind !== 'textfield' && kind !== 'texteditor') {
|
|
1722
|
+
const { left, top, width, height } = el.style;
|
|
1723
|
+
el.removeAttribute('style');
|
|
1724
|
+
if (left) el.style.left = left;
|
|
1725
|
+
if (top) el.style.top = top;
|
|
1726
|
+
if (width) el.style.width = width;
|
|
1727
|
+
if (height) el.style.height = height;
|
|
1728
|
+
}
|
|
1697
1729
|
for (const key of Object.keys(el.dataset)) {
|
|
1698
1730
|
if (key !== ID_ATTR && key !== KIND_ATTR) delete el.dataset[key];
|
|
1699
1731
|
}
|
|
@@ -2510,6 +2542,38 @@ function createShell(kind: ElementKind): HTMLElement {
|
|
|
2510
2542
|
}
|
|
2511
2543
|
}
|
|
2512
2544
|
|
|
2545
|
+
/** The list row `el` is in (a direct child of a section's rows or a list's content), or null. */
|
|
2546
|
+
function listRowOf(el: HTMLElement, root: HTMLElement): HTMLElement | null {
|
|
2547
|
+
for (let node: HTMLElement | null = el; node && node !== root; node = node.parentElement) {
|
|
2548
|
+
const parent = node.parentElement;
|
|
2549
|
+
if (parent?.classList.contains('sb-section-rows') || parent?.classList.contains('sb-list-content')) return node;
|
|
2550
|
+
}
|
|
2551
|
+
return null;
|
|
2552
|
+
}
|
|
2553
|
+
|
|
2554
|
+
/** Controls a row may hold besides its button for the row to stay the button's: none. */
|
|
2555
|
+
const ROW_CONTROLS =
|
|
2556
|
+
'input, textarea, .sb-navlink, .sb-switch, .sb-picker, .sb-stepper, .sb-slider, .sb-menu, .sb-tapgesture, .sb-link, .sb-datepicker';
|
|
2557
|
+
|
|
2558
|
+
/**
|
|
2559
|
+
* A list row holding one button (with other views beside it, or under a
|
|
2560
|
+
* modifier) taps the button wherever it is tapped, as a UITableView cell
|
|
2561
|
+
* does on iOS; a row that is the button itself is that already. Not a
|
|
2562
|
+
* `.plain` or `.borderless` button (both arrive as `plain`), which SwiftUI
|
|
2563
|
+
* keeps to its own label in a row, a disabled one, or a row with other
|
|
2564
|
+
* controls.
|
|
2565
|
+
*/
|
|
2566
|
+
function rowAction(el: HTMLElement, root: HTMLElement): HTMLElement | null {
|
|
2567
|
+
const row = listRowOf(el, root);
|
|
2568
|
+
if (!row || row.matches('.sb-button, .sb-navlink, .sb-listrow[data-sb-selectable]')) return null;
|
|
2569
|
+
const buttons = row.querySelectorAll<HTMLElement>('.sb-button');
|
|
2570
|
+
if (buttons.length !== 1) return null;
|
|
2571
|
+
const button = buttons[0]!;
|
|
2572
|
+
if (button.dataset['sbStyle'] === 'plain' || button.closest('[data-sb-disabled]')) return null;
|
|
2573
|
+
if (row.querySelector(ROW_CONTROLS)) return null;
|
|
2574
|
+
return button;
|
|
2575
|
+
}
|
|
2576
|
+
|
|
2513
2577
|
/** A vertical `textfield`: a `<textarea>` the layout sizes to its lines. */
|
|
2514
2578
|
function createMultilineField(): HTMLTextAreaElement {
|
|
2515
2579
|
const el = document.createElement('textarea');
|
|
@@ -3565,7 +3629,8 @@ function applyTextField(input: HTMLInputElement | HTMLTextAreaElement, props: Te
|
|
|
3565
3629
|
// A vertical field is a `<textarea>`, which has no type.
|
|
3566
3630
|
if (input instanceof HTMLInputElement) input.type = props.secure ? 'password' : 'text';
|
|
3567
3631
|
else input.dataset['sbAxis'] = 'vertical';
|
|
3568
|
-
|
|
3632
|
+
const placeholder = props.placeholder ?? '';
|
|
3633
|
+
if (input.placeholder !== placeholder) input.placeholder = placeholder;
|
|
3569
3634
|
input.dataset['sbStyle'] = props.style ?? 'plain';
|
|
3570
3635
|
const text = props.text ?? '';
|
|
3571
3636
|
// Leave the caret alone when Swift echoes the value the field already shows.
|
package/src/styles.css
CHANGED
|
@@ -196,6 +196,14 @@
|
|
|
196
196
|
|
|
197
197
|
.device {
|
|
198
198
|
position: relative;
|
|
199
|
+
/* iOS Safari inflates the text of wide multi-line blocks it judges hard to
|
|
200
|
+
read ("text autosizing"): a wrapped section footer or paragraph would draw
|
|
201
|
+
a size up from the one the engine measured it at and run into what
|
|
202
|
+
follows. page.css pins this on the document in device mode; an island
|
|
203
|
+
(@swiftbrowser/react) lives in a page that may not, so pin it here too.
|
|
204
|
+
Inherited, so it covers everything the frame draws. */
|
|
205
|
+
-webkit-text-size-adjust: 100%;
|
|
206
|
+
text-size-adjust: 100%;
|
|
199
207
|
}
|
|
200
208
|
|
|
201
209
|
/* The iPhone's size and bezel: the frame's only. An island (`.sb-island`,
|
|
@@ -759,6 +767,8 @@ svg[data-sb-symbol="progress.indicator"] > line:nth-child(8) { animation-delay:
|
|
|
759
767
|
color: var(--sb-color-placeholder);
|
|
760
768
|
}
|
|
761
769
|
|
|
770
|
+
/* A UITextField's rounded rect: the same with the focus as without (iOS
|
|
771
|
+
draws no focus ring or tinted border on it). */
|
|
762
772
|
.sb-textfield[data-sb-style="roundedBorder"] {
|
|
763
773
|
padding: 0 7px;
|
|
764
774
|
border: 1px solid var(--sb-color-field-border);
|
|
@@ -766,11 +776,6 @@ svg[data-sb-symbol="progress.indicator"] > line:nth-child(8) { animation-delay:
|
|
|
766
776
|
background: var(--sb-color-field-background);
|
|
767
777
|
}
|
|
768
778
|
|
|
769
|
-
.sb-textfield[data-sb-style="roundedBorder"]:focus-visible {
|
|
770
|
-
border-color: var(--sb-color-accent);
|
|
771
|
-
box-shadow: 0 0 0 2px color-mix(in srgb, var(--sb-color-accent) 30%, transparent);
|
|
772
|
-
}
|
|
773
|
-
|
|
774
779
|
/* Toggle: the label children are positioned by their frames; the switch sits
|
|
775
780
|
at the engine's `switch` rect (51×31 at the trailing edge). */
|
|
776
781
|
.sb-switch {
|
|
@@ -969,6 +974,12 @@ svg[data-sb-symbol="progress.indicator"] > line:nth-child(8) { animation-delay:
|
|
|
969
974
|
background: var(--sb-color-fill);
|
|
970
975
|
}
|
|
971
976
|
|
|
977
|
+
/* A row whose one button it taps (renderer.ts `rowAction`), while pressed. */
|
|
978
|
+
.sb-section-rows > [data-sb-row-pressed],
|
|
979
|
+
.sb-list-content > [data-sb-row-pressed] {
|
|
980
|
+
background: var(--sb-color-fill);
|
|
981
|
+
}
|
|
982
|
+
|
|
972
983
|
/* ---------------------------------------------------------------------------
|
|
973
984
|
Phase 2: navigation
|
|
974
985
|
------------------------------------------------------------------------- */
|
|
@@ -2901,6 +2912,14 @@ svg[data-sb-symbol="progress.indicator"] > line:nth-child(8) { animation-delay:
|
|
|
2901
2912
|
pointer-events: auto;
|
|
2902
2913
|
}
|
|
2903
2914
|
|
|
2915
|
+
/* A list row is content however it is made (a stack, a modifier box): its
|
|
2916
|
+
empty space is the cell's, and a tap there taps the row's one button
|
|
2917
|
+
(renderer.ts `rowAction`), as on iOS. */
|
|
2918
|
+
.sb-section-rows > [data-sb-kind],
|
|
2919
|
+
.sb-list-content > [data-sb-kind] {
|
|
2920
|
+
pointer-events: auto;
|
|
2921
|
+
}
|
|
2922
|
+
|
|
2904
2923
|
.sb-styled[data-sb-background] {
|
|
2905
2924
|
pointer-events: auto;
|
|
2906
2925
|
}
|
|
@@ -3749,14 +3768,17 @@ svg[data-sb-symbol="progress.indicator"] > line:nth-child(8) { animation-delay:
|
|
|
3749
3768
|
}
|
|
3750
3769
|
|
|
3751
3770
|
/* ---------------------------------------------------------------------------
|
|
3752
|
-
Text editor: a borderless textarea filling its frame in
|
|
3753
|
-
parent provides any frame or background).
|
|
3771
|
+
Text editor: a borderless textarea filling its frame in its context's font
|
|
3772
|
+
(layoutDom.ts; its parent provides any frame or background). Its text is
|
|
3773
|
+
inset as a UITextView's is: 8 above and below (`textContainerInset`), 5 at
|
|
3774
|
+
the sides (`lineFragmentPadding`).
|
|
3754
3775
|
------------------------------------------------------------------------- */
|
|
3755
3776
|
.sb-texteditor {
|
|
3756
3777
|
appearance: none;
|
|
3757
3778
|
display: block;
|
|
3779
|
+
box-sizing: border-box;
|
|
3758
3780
|
margin: 0;
|
|
3759
|
-
padding:
|
|
3781
|
+
padding: 8px 5px;
|
|
3760
3782
|
border: 0;
|
|
3761
3783
|
outline: none;
|
|
3762
3784
|
resize: none;
|
package/src/symbols.ts
CHANGED
|
@@ -577,6 +577,20 @@ const QUESTIONMARK: IconNode = [
|
|
|
577
577
|
['path', { d: 'M12 20.5h.01' }],
|
|
578
578
|
];
|
|
579
579
|
|
|
580
|
+
/**
|
|
581
|
+
* `tray.fill`: the tray's silhouette (lucide's `Inbox`) filled, split along
|
|
582
|
+
* its opening's edge, the line with the notch, by a gap: the well above,
|
|
583
|
+
* the front below. A real gap, not a stroke in the background color, so
|
|
584
|
+
* whatever is behind the glyph (a selected tab's capsule) shows through.
|
|
585
|
+
* The pieces' edges along it sit 1.75 from that line, so with their 2 wide
|
|
586
|
+
* stroke they leave 1.5 between them, the notch's slants offset square to
|
|
587
|
+
* their direction.
|
|
588
|
+
*/
|
|
589
|
+
const TRAY_FILL: IconNode = [
|
|
590
|
+
['path', { d: 'M2.88 10.25 5.45 5.11A2 2 0 0 1 7.24 4h9.52a2 2 0 0 1 1.79 1.11l2.57 5.14h-6.06l-2 3h-2.12l-2-3z' }],
|
|
591
|
+
['path', { d: 'M2 13.75h5.06l2 3h5.88l2-3H22V18a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2z' }],
|
|
592
|
+
];
|
|
593
|
+
|
|
580
594
|
const outline = (icon: IconNode): SymbolGlyph => ({ icon, fill: 'outline' });
|
|
581
595
|
const knockout = (icon: IconNode): SymbolGlyph => ({ icon, fill: 'knockout' });
|
|
582
596
|
const solid = (icon: IconNode): SymbolGlyph => ({ icon, fill: 'solid' });
|
|
@@ -1083,7 +1097,7 @@ export const SF_SYMBOLS: Readonly<Record<string, SymbolGlyph>> = {
|
|
|
1083
1097
|
'envelope.badge': outline(MailWarning),
|
|
1084
1098
|
'envelope.open.fill': outline(MailOpen),
|
|
1085
1099
|
'tray.full': outline(Inbox),
|
|
1086
|
-
'tray.fill': solid(
|
|
1100
|
+
'tray.fill': solid(TRAY_FILL),
|
|
1087
1101
|
'tray.and.arrow.down': outline(Inbox),
|
|
1088
1102
|
'tray.and.arrow.up': outline(Inbox),
|
|
1089
1103
|
'phone.arrow.up.right': outline(PhoneOutgoing),
|