@swiftbrowser/web 0.26.2 → 0.26.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/app/index.html +9 -3
- package/node/dist/node/apps.d.ts +6 -0
- package/node/dist/node/apps.d.ts.map +1 -1
- package/node/dist/node/apps.js +3 -0
- package/node/dist/node/apps.js.map +1 -1
- package/node/dist/node/config.d.ts +2 -0
- package/node/dist/node/config.d.ts.map +1 -1
- package/node/dist/node/config.js +5 -0
- package/node/dist/node/config.js.map +1 -1
- package/node/dist/plugins/site-layout.d.ts +2 -0
- package/node/dist/plugins/site-layout.d.ts.map +1 -1
- package/node/dist/plugins/site-layout.js.map +1 -1
- package/package.json +1 -1
- package/plugins/site-layout.ts +2 -0
- package/src/deviceFrame.ts +38 -14
- package/src/layout/engine.ts +787 -175
- package/src/layout/types.ts +3 -0
- package/src/layout/typography.ts +27 -6
- package/src/layoutDom.ts +64 -3
- package/src/main.ts +13 -4
- package/src/protocol.ts +11 -0
- package/src/renderer.ts +22 -5
- package/src/styles.css +752 -0
- package/src/typography.ts +11 -10
- package/src/vite-env.d.ts +2 -0
package/src/layout/types.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import type { AssetCatalog } from '../assets';
|
|
8
|
+
import type { Platform } from '../protocol';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* A size proposal from a parent to a child. `null` means "whatever you want",
|
|
@@ -97,6 +98,8 @@ export interface LayoutEnvironment {
|
|
|
97
98
|
dynamicTypeSize: DynamicTypeSize;
|
|
98
99
|
devicePixelRatio: number;
|
|
99
100
|
colorScheme: 'light' | 'dark';
|
|
101
|
+
/** The platform whose idiom the engine lays out for (docs/notes/macos.md); iOS when absent. */
|
|
102
|
+
platform?: Platform;
|
|
100
103
|
/**
|
|
101
104
|
* Phase 5: the app's asset catalog manifest, for the intrinsic size of
|
|
102
105
|
* named images. Absent (or empty) when the app has no catalog; named
|
package/src/layout/typography.ts
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* leading (body 22): the distance between a paragraph's lines (`LEADINGS`).
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
+
import type { Platform } from '../protocol';
|
|
14
15
|
import type { DynamicTypeSize, FontFamily, LayoutEnvironment, ResolvedFont } from './types';
|
|
15
16
|
|
|
16
17
|
export type TextStyle =
|
|
@@ -63,6 +64,24 @@ export const TEXT_STYLE_SIZES: Record<TextStyle, readonly number[]> = {
|
|
|
63
64
|
caption2: [11, 11, 11, 11, 13, 15, 17, 20, 24, 29, 34, 40],
|
|
64
65
|
};
|
|
65
66
|
|
|
67
|
+
/**
|
|
68
|
+
* The macOS text styles (HIG "Typography" > "macOS built-in text styles"),
|
|
69
|
+
* one size each: the Mac has no Dynamic Type. Body is 13.
|
|
70
|
+
*/
|
|
71
|
+
export const MAC_TEXT_STYLE_SIZES: Readonly<Record<TextStyle, number>> = {
|
|
72
|
+
largeTitle: 26,
|
|
73
|
+
title: 22,
|
|
74
|
+
title2: 17,
|
|
75
|
+
title3: 15,
|
|
76
|
+
headline: 13,
|
|
77
|
+
body: 13,
|
|
78
|
+
callout: 12,
|
|
79
|
+
subheadline: 11,
|
|
80
|
+
footnote: 10,
|
|
81
|
+
caption: 10,
|
|
82
|
+
caption2: 10,
|
|
83
|
+
};
|
|
84
|
+
|
|
66
85
|
/**
|
|
67
86
|
* The HIG's leading for the standard (Large) point sizes: the distance
|
|
68
87
|
* between the baselines of a paragraph's lines, which SwiftUI keeps (a
|
|
@@ -122,8 +141,9 @@ export function sizeCategoryIndex(size: DynamicTypeSize): number {
|
|
|
122
141
|
return index < 0 ? LARGE_INDEX : index;
|
|
123
142
|
}
|
|
124
143
|
|
|
125
|
-
/** Point size of a text style at a Dynamic Type size category. */
|
|
126
|
-
export function textStyleSize(style: TextStyle, size: DynamicTypeSize): number {
|
|
144
|
+
/** Point size of a text style at a Dynamic Type size category (on the Mac, its one size). */
|
|
145
|
+
export function textStyleSize(style: TextStyle, size: DynamicTypeSize, platform: Platform = 'ios'): number {
|
|
146
|
+
if (platform === 'macos') return MAC_TEXT_STYLE_SIZES[style];
|
|
127
147
|
const row = TEXT_STYLE_SIZES[style];
|
|
128
148
|
return row[sizeCategoryIndex(size)] ?? row[LARGE_INDEX] ?? 17;
|
|
129
149
|
}
|
|
@@ -166,9 +186,9 @@ export function makeFont(
|
|
|
166
186
|
return font;
|
|
167
187
|
}
|
|
168
188
|
|
|
169
|
-
/** Body text for the current `dynamicTypeSize` (17/20.33 at Large). */
|
|
189
|
+
/** Body text for the current `dynamicTypeSize` (17/20.33 at Large; 13 on the Mac). */
|
|
170
190
|
export function defaultFont(env: LayoutEnvironment): ResolvedFont {
|
|
171
|
-
return makeFont('system', textStyleSize('body', env.dynamicTypeSize), 400);
|
|
191
|
+
return makeFont('system', textStyleSize('body', env.dynamicTypeSize, env.platform), 400);
|
|
172
192
|
}
|
|
173
193
|
|
|
174
194
|
/**
|
|
@@ -199,13 +219,14 @@ export function resolveFont(
|
|
|
199
219
|
let defaultWeight = 400;
|
|
200
220
|
let isNewFont = false;
|
|
201
221
|
if (isTextStyle(textStyle)) {
|
|
202
|
-
size = textStyleSize(textStyle, env.dynamicTypeSize);
|
|
222
|
+
size = textStyleSize(textStyle, env.dynamicTypeSize, env.platform);
|
|
203
223
|
if (textStyle === 'headline') defaultWeight = 600;
|
|
204
224
|
isNewFont = true;
|
|
205
225
|
} else if (typeof fixedSize === 'number' && Number.isFinite(fixedSize) && fixedSize > 0) {
|
|
206
226
|
size = fixedSize;
|
|
207
227
|
const relativeTo = font['relativeTo'];
|
|
208
|
-
|
|
228
|
+
// The Mac has no Dynamic Type: a fixed size stays as given.
|
|
229
|
+
if (isTextStyle(relativeTo) && env.platform !== 'macos') {
|
|
209
230
|
const base = TEXT_STYLE_SIZES[relativeTo][LARGE_INDEX] ?? 17;
|
|
210
231
|
size = fixedSize * (textStyleSize(relativeTo, env.dynamicTypeSize) / base);
|
|
211
232
|
}
|
package/src/layoutDom.ts
CHANGED
|
@@ -702,6 +702,8 @@ function applyChrome(
|
|
|
702
702
|
// Phase 8 controls: their chrome sits at the engine's rects inside the element's box.
|
|
703
703
|
case 'stepper':
|
|
704
704
|
placeChrome(el.querySelector<HTMLElement>(':scope > .sb-stepper-control'), chrome?.['control'], box);
|
|
705
|
+
// The Mac idiom: the arrows, up over down (styles.css).
|
|
706
|
+
setFlag(el, 'sbArrows', chrome?.['arrows'] ? '' : null);
|
|
705
707
|
return;
|
|
706
708
|
case 'slider': {
|
|
707
709
|
// The `label` child is hidden (iOS draws none) and names the slider, as VoiceOver reads it.
|
|
@@ -715,6 +717,8 @@ function applyChrome(
|
|
|
715
717
|
el.removeAttribute('aria-labelledby');
|
|
716
718
|
}
|
|
717
719
|
placeChrome(el.querySelector<HTMLElement>(':scope > .sb-slider-track'), chrome?.['track'], box);
|
|
720
|
+
// The Mac idiom: the round knob (styles.css).
|
|
721
|
+
setFlag(el, 'sbKnob', chrome?.['knob'] ? '' : null);
|
|
718
722
|
placeChrome(el.querySelector<HTMLElement>(':scope > .sb-slider-fill'), chrome?.['fill'], box);
|
|
719
723
|
placeChrome(el.querySelector<HTMLElement>(':scope > .sb-slider-thumb'), chrome?.['thumb'], box);
|
|
720
724
|
return;
|
|
@@ -722,6 +726,8 @@ function applyChrome(
|
|
|
722
726
|
case 'datepicker':
|
|
723
727
|
placeChrome(el.querySelector<HTMLElement>(':scope > .sb-datepicker-date'), chrome?.['date'], box);
|
|
724
728
|
placeChrome(el.querySelector<HTMLElement>(':scope > .sb-datepicker-time'), chrome?.['time'], box);
|
|
729
|
+
// The Mac idiom: the date and time as bordered fields (styles.css).
|
|
730
|
+
setFlag(el, 'sbFields', chrome?.['fields'] ? '' : null);
|
|
725
731
|
return;
|
|
726
732
|
case 'alert': {
|
|
727
733
|
// Phase 8: the card(s), the centered title / message lines and the
|
|
@@ -742,6 +748,8 @@ function applyChrome(
|
|
|
742
748
|
if (message && texts?.['message']) setTextLayout(message, texts['message']);
|
|
743
749
|
placeChrome(part('sb-alert-ok'), chrome?.['ok'], box);
|
|
744
750
|
el.toggleAttribute('data-sb-header', Boolean(chrome?.['title'] || chrome?.['message']));
|
|
751
|
+
// The Mac idiom: the alert as a panel (styles.css).
|
|
752
|
+
setFlag(el, 'sbPanel', chrome?.['panel'] ? '' : null);
|
|
745
753
|
const first = chrome?.['button0'];
|
|
746
754
|
const second = chrome?.['button1'];
|
|
747
755
|
el.dataset['sbLayout'] = first && second && first.y === second.y && !chrome?.['button2'] ? 'row' : 'stack';
|
|
@@ -750,7 +758,34 @@ function applyChrome(
|
|
|
750
758
|
}
|
|
751
759
|
return;
|
|
752
760
|
}
|
|
761
|
+
case 'menu':
|
|
762
|
+
// The Mac idiom: a pull-down button around the label (styles.css).
|
|
763
|
+
setFlag(el, 'sbPulldown', chrome?.['pulldown'] ? '' : null);
|
|
764
|
+
return;
|
|
765
|
+
case 'button': {
|
|
766
|
+
// The Mac idiom: an automatic button the engine bordered (styles.css);
|
|
767
|
+
// in a list row the button is drawn at its own frame on the row
|
|
768
|
+
// (`inset`, the frame in the row's coordinates).
|
|
769
|
+
// The rect the border is drawn at: the engine's (a bar item's slot) or
|
|
770
|
+
// the button's own frame; `inset` when it is not the element's box.
|
|
771
|
+
const bordered = chrome?.['bordered'];
|
|
772
|
+
const rect = bordered ?? frame;
|
|
773
|
+
const inset = bordered !== undefined && (box.x !== rect.x || box.y !== rect.y || box.width !== rect.width || box.height !== rect.height);
|
|
774
|
+
setFlag(el, 'sbBordered', bordered ? (inset ? 'inset' : '') : null);
|
|
775
|
+
const vars: [string, string][] = inset
|
|
776
|
+
? [['--sb-bordered-left', `${rect.x - box.x}px`], ['--sb-bordered-top', `${rect.y - box.y}px`], ['--sb-bordered-width', `${rect.width}px`], ['--sb-bordered-height', `${rect.height}px`]]
|
|
777
|
+
: [['--sb-bordered-left', ''], ['--sb-bordered-top', ''], ['--sb-bordered-width', ''], ['--sb-bordered-height', '']];
|
|
778
|
+
for (const [name, value] of vars) {
|
|
779
|
+
if (el.style.getPropertyValue(name) !== value) {
|
|
780
|
+
if (value) el.style.setProperty(name, value);
|
|
781
|
+
else el.style.removeProperty(name);
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
return;
|
|
785
|
+
}
|
|
753
786
|
case 'toggle': {
|
|
787
|
+
// The Mac idiom: a checkbox at the switch's rect (styles.css).
|
|
788
|
+
setFlag(el, 'sbCheckbox', chrome?.['checkbox'] ? '' : null);
|
|
754
789
|
const sw = el.querySelector<HTMLElement>(':scope > .sb-switch');
|
|
755
790
|
const rect = chrome?.['switch'] ?? {
|
|
756
791
|
x: frame.x + frame.width - SWITCH_SIZE.width,
|
|
@@ -761,10 +796,22 @@ function applyChrome(
|
|
|
761
796
|
return;
|
|
762
797
|
}
|
|
763
798
|
case 'disclosuregroup': {
|
|
764
|
-
// The chevron at the label's trailing edge, the toggle over the label (the first child's frame).
|
|
765
|
-
const label = node.children[0] ? result.frames.get(node.children[0].id) : undefined;
|
|
766
799
|
const chevron = el.querySelector<HTMLElement>(':scope > .sb-disclosure-chevron');
|
|
767
800
|
const toggle = el.querySelector<HTMLElement>(':scope > .sb-disclosure-toggle');
|
|
801
|
+
// In a list the group is an outline (engine.ts `outlineRows`): its label
|
|
802
|
+
// and content are rows (styles.css draws them as the card's), the toggle
|
|
803
|
+
// lies over the label's row and the chevron sits at that row's trailing
|
|
804
|
+
// edge, centred as a link's is.
|
|
805
|
+
const outline = chrome?.['toggle'];
|
|
806
|
+
setFlag(el, 'sbOutline', outline ? '' : null);
|
|
807
|
+
if (outline) {
|
|
808
|
+
placeChrome(toggle, outline, box);
|
|
809
|
+
const rect = chrome?.['chevron'];
|
|
810
|
+
placeChrome(chevron, rect ? { x: rect.x + (rect.width - CHEVRON_SIZE) / 2, y: rect.y + (rect.height - CHEVRON_SIZE) / 2, width: CHEVRON_SIZE, height: CHEVRON_SIZE } : undefined, box);
|
|
811
|
+
return;
|
|
812
|
+
}
|
|
813
|
+
// The chevron at the label's trailing edge, the toggle over the label (the first child's frame).
|
|
814
|
+
const label = node.children[0] ? result.frames.get(node.children[0].id) : undefined;
|
|
768
815
|
if (label) {
|
|
769
816
|
placeChrome(chevron, { x: frame.x + frame.width - CHEVRON_SIZE - 2, y: label.y + (label.height - CHEVRON_SIZE) / 2, width: CHEVRON_SIZE, height: CHEVRON_SIZE }, box);
|
|
770
817
|
placeChrome(toggle, { x: frame.x, y: label.y, width: frame.width, height: label.height }, box);
|
|
@@ -884,11 +931,17 @@ function applyChrome(
|
|
|
884
931
|
bar.style.paddingTop = `${top}px`;
|
|
885
932
|
bar.style.paddingBottom = `${bottom}px`;
|
|
886
933
|
}
|
|
934
|
+
// The Mac idiom: a unified title bar (styles.css lays its title out leading-aligned).
|
|
935
|
+
setFlag(el, 'sbUnified', chrome?.['unified'] ? '' : null);
|
|
936
|
+
// The Mac idiom: a sheet's title bar (the title leading, 13 bold).
|
|
937
|
+
setFlag(el, 'sbSheetBar', chrome?.['sheetBar'] ? '' : null);
|
|
887
938
|
syncBarGlass(result, node, el, chrome, frame, isNew, changes);
|
|
888
939
|
// The `keyboard` toolbars' bar above the keyboard while a text input of the screen is focused.
|
|
889
940
|
placeChrome(el.querySelector<HTMLElement>(':scope > .sb-navscreen-body > .sb-keyboard-bar'), chrome?.['keyboardBar'], frame);
|
|
890
941
|
// iOS 26 in a tab view: the search field under the title (styles.css).
|
|
891
942
|
setFlag(el, 'sbSearchTop', chrome?.['searchTop'] ? '' : null);
|
|
943
|
+
// The Mac idiom: the search field in the title bar (styles.css).
|
|
944
|
+
setFlag(el, 'sbSearchBar', chrome?.['searchBar'] ? '' : null);
|
|
892
945
|
const largeRect = chrome?.['largeTitle'];
|
|
893
946
|
if (largeTitle) {
|
|
894
947
|
if (largeRect) {
|
|
@@ -956,6 +1009,8 @@ function applyChrome(
|
|
|
956
1009
|
setFlag(el, 'sbFloating', chrome?.['floating'] ? '' : null);
|
|
957
1010
|
// iPadOS: in a regular width, a centered form sheet (styles.css).
|
|
958
1011
|
setFlag(el, 'sbForm', chrome?.['form'] ? '' : null);
|
|
1012
|
+
// The Mac idiom: a bottom bar with the sheet's actions (styles.css).
|
|
1013
|
+
setFlag(el, 'sbActions', chrome?.['actions'] ? '' : null);
|
|
959
1014
|
return;
|
|
960
1015
|
}
|
|
961
1016
|
case 'tabview': {
|
|
@@ -963,6 +1018,8 @@ function applyChrome(
|
|
|
963
1018
|
const barRect = chrome?.['bar'];
|
|
964
1019
|
if (!bar || !barRect) return;
|
|
965
1020
|
placeChrome(bar, barRect, box);
|
|
1021
|
+
// The Mac idiom: the bar is a segmented control at the top of the content (styles.css).
|
|
1022
|
+
setFlag(el, 'sbTabsTop', chrome?.['top'] ? '' : null);
|
|
966
1023
|
// Items are the 49px row at the top of the bar; the rest is the safe area.
|
|
967
1024
|
const items = Array.from(bar.children) as HTMLElement[];
|
|
968
1025
|
items.forEach((item, i) => placeChrome(item, chrome?.[`item${i}`], barRect));
|
|
@@ -1006,7 +1063,9 @@ function applyChrome(
|
|
|
1006
1063
|
if (node.props['style'] === 'segmented') {
|
|
1007
1064
|
// In a navigation bar item the control is the bar's glass capsule (engine `bar`).
|
|
1008
1065
|
el.toggleAttribute('data-sb-bar', chrome?.['bar'] !== undefined);
|
|
1009
|
-
|
|
1066
|
+
// The Mac idiom: the label before the control (engine `label`, `track`).
|
|
1067
|
+
placeChrome(el.querySelector<HTMLElement>(':scope > .sb-segment-track'), chrome?.['track'] ?? frame, box);
|
|
1068
|
+
placeChrome(el.querySelector<HTMLElement>(':scope > .sb-picker-label'), chrome?.['label'], box);
|
|
1010
1069
|
const segments = el.querySelectorAll<HTMLElement>(':scope > .sb-segment');
|
|
1011
1070
|
segments.forEach((segment, i) => placeChrome(segment, chrome?.[`segment${i}`], box));
|
|
1012
1071
|
} else if (node.props['style'] === 'inline') {
|
|
@@ -1017,6 +1076,8 @@ function applyChrome(
|
|
|
1017
1076
|
} else {
|
|
1018
1077
|
placeChrome(el.querySelector<HTMLElement>(':scope > .sb-picker-label'), chrome?.['label'], box);
|
|
1019
1078
|
placeChrome(el.querySelector<HTMLElement>(':scope > .sb-picker-value'), chrome?.['value'], box);
|
|
1079
|
+
// The Mac idiom: the value in a pop-up button (styles.css).
|
|
1080
|
+
setFlag(el, 'sbPopup', chrome?.['popup'] ? '' : null);
|
|
1020
1081
|
}
|
|
1021
1082
|
return;
|
|
1022
1083
|
}
|
package/src/main.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { easingFor, springEasing, timingFor } from './animation';
|
|
3
3
|
import type { BuildEndPayload, BuildErrorPayload, BuildStartPayload } from './devEvents';
|
|
4
4
|
import { ChromeColor } from './chromeColor';
|
|
5
|
-
import { installDeviceFrame } from './deviceFrame';
|
|
5
|
+
import { frameFor, installDeviceFrame } from './deviceFrame';
|
|
6
6
|
import { applyPageMode, decidePageMode, installViewportReadout, readViewportInsets, watchKeyboard, watchViewport, type PageMode } from './deviceMode';
|
|
7
7
|
import { EMPTY_CATALOG, catalogPath, isAssetCatalog, type AssetCatalog } from './assets';
|
|
8
8
|
import { createMockApp } from './mock';
|
|
@@ -202,7 +202,7 @@ function currentTypeSize(): DynamicTypeSize {
|
|
|
202
202
|
*/
|
|
203
203
|
function applyTypeSize(size: DynamicTypeSize, persist: boolean): void {
|
|
204
204
|
device.dataset['typeSize'] = size;
|
|
205
|
-
applyTypeSizeVariables(device, size);
|
|
205
|
+
applyTypeSizeVariables(device, size, renderer.platform);
|
|
206
206
|
// The layout engine resolves text styles for this size and re-lays out.
|
|
207
207
|
renderer.setEnvironment({ dynamicTypeSize: size });
|
|
208
208
|
if (typeSizeSelect.value !== size) typeSizeSelect.value = size;
|
|
@@ -237,6 +237,8 @@ function currentSizeClass(): HorizontalSizeClass {
|
|
|
237
237
|
}
|
|
238
238
|
/** The size class last sent in an `environment` event (null before the first). */
|
|
239
239
|
let sentSizeClass: HorizontalSizeClass | null = null;
|
|
240
|
+
/** The platform last sent in an `environment` event (null before the first). */
|
|
241
|
+
let sentPlatform: string | null = null;
|
|
240
242
|
|
|
241
243
|
if (deviceMode) {
|
|
242
244
|
// `#screen` fills the viewport (styles.css); the renderer re-reads its size
|
|
@@ -267,9 +269,12 @@ if (deviceMode) {
|
|
|
267
269
|
// app in an iPhone, an iPad or no device; the renderer re-reads the
|
|
268
270
|
// screen's size when it changes, and Swift hears a new size class.
|
|
269
271
|
const sizeClassMayHaveChanged = (): void => {
|
|
270
|
-
|
|
272
|
+
// The Mac's text styles are its own: the device's variables follow the platform.
|
|
273
|
+
applyTypeSizeVariables(device, currentTypeSize(), renderer.platform);
|
|
274
|
+
if (sentSizeClass !== null && (currentSizeClass() !== sentSizeClass || renderer.platform !== sentPlatform)) sendEnvironment();
|
|
271
275
|
};
|
|
272
|
-
|
|
276
|
+
// An app built for macOS (docs/notes/macos.md) starts in a Mac window.
|
|
277
|
+
installDeviceFrame(renderer, { onChange: sizeClassMayHaveChanged, preferred: frameFor(registeredApp()?.platform) });
|
|
273
278
|
watchViewport(sizeClassMayHaveChanged);
|
|
274
279
|
}
|
|
275
280
|
|
|
@@ -303,12 +308,16 @@ function sendEnvironment(): void {
|
|
|
303
308
|
// Phase 8: every environment event carries the scene phase.
|
|
304
309
|
const scenePhase = currentScenePhase();
|
|
305
310
|
sentScenePhase = scenePhase;
|
|
311
|
+
// The platform the renderer draws (docs/notes/macos.md).
|
|
312
|
+
const platform = renderer.platform;
|
|
313
|
+
sentPlatform = platform;
|
|
306
314
|
dispatch({
|
|
307
315
|
type: 'environment',
|
|
308
316
|
colorScheme: currentTheme(),
|
|
309
317
|
dynamicTypeSize: currentTypeSize(),
|
|
310
318
|
horizontalSizeClass,
|
|
311
319
|
scenePhase,
|
|
320
|
+
platform,
|
|
312
321
|
});
|
|
313
322
|
}
|
|
314
323
|
|
package/src/protocol.ts
CHANGED
|
@@ -1782,6 +1782,17 @@ export function horizontalSizeClassFor(width: number): HorizontalSizeClass {
|
|
|
1782
1782
|
return Number.isFinite(width) && width >= REGULAR_WIDTH_MIN ? 'regular' : 'compact';
|
|
1783
1783
|
}
|
|
1784
1784
|
|
|
1785
|
+
/**
|
|
1786
|
+
* The platform the app is drawn as (docs/notes/macos.md): `ios`, the
|
|
1787
|
+
* default, or `macos`. The renderer draws the platform's idiom and reports
|
|
1788
|
+
* it in the first `environment` event; it never changes in a session.
|
|
1789
|
+
*/
|
|
1790
|
+
export type Platform = 'ios' | 'macos';
|
|
1791
|
+
|
|
1792
|
+
export interface EnvironmentEvent {
|
|
1793
|
+
platform?: Platform;
|
|
1794
|
+
}
|
|
1795
|
+
|
|
1785
1796
|
// ---------------------------------------------------------------------------
|
|
1786
1797
|
// Phase 7: charts (docs/ops-protocol.md, "Phase 7"). Swift turns data into
|
|
1787
1798
|
// unit coordinates (0...1 of the plot rectangle, y top → bottom); the renderer
|
package/src/renderer.ts
CHANGED
|
@@ -148,6 +148,7 @@ import {
|
|
|
148
148
|
type CanvasProps,
|
|
149
149
|
type Color,
|
|
150
150
|
type LazySpacerProps,
|
|
151
|
+
type Platform,
|
|
151
152
|
} from './protocol';
|
|
152
153
|
import {
|
|
153
154
|
combineDateSeconds,
|
|
@@ -361,6 +362,8 @@ const DEFAULT_SAFE_AREA = { top: 59, leading: 0, bottom: 34, trailing: 0 };
|
|
|
361
362
|
export interface RendererEnvironment {
|
|
362
363
|
dynamicTypeSize: DynamicTypeSize;
|
|
363
364
|
colorScheme: ColorScheme;
|
|
365
|
+
/** The platform drawn (docs/notes/macos.md): iOS unless the page says macOS. */
|
|
366
|
+
platform: Platform;
|
|
364
367
|
}
|
|
365
368
|
|
|
366
369
|
export class Renderer {
|
|
@@ -473,7 +476,7 @@ export class Renderer {
|
|
|
473
476
|
*/
|
|
474
477
|
private engine: LayoutPass | null = null;
|
|
475
478
|
private engineEnvKey = '';
|
|
476
|
-
private environment: RendererEnvironment = { dynamicTypeSize: 'large', colorScheme: 'light' };
|
|
479
|
+
private environment: RendererEnvironment = { dynamicTypeSize: 'large', colorScheme: 'light', platform: 'ios' };
|
|
477
480
|
/** Phase 5: the app's asset catalog manifest (empty until `setAssetCatalog`). */
|
|
478
481
|
private assets: AssetCatalog = EMPTY_CATALOG;
|
|
479
482
|
/** The `<style>` holding the catalog colors as custom properties (see `setAssetCatalog`). */
|
|
@@ -1464,18 +1467,26 @@ export class Renderer {
|
|
|
1464
1467
|
// -------------------------------------------------------------------------
|
|
1465
1468
|
|
|
1466
1469
|
/**
|
|
1467
|
-
* Set the device environment (Dynamic Type size, color scheme)
|
|
1468
|
-
* the tree out. The page calls this on boot and whenever a
|
|
1470
|
+
* Set the device environment (Dynamic Type size, color scheme, platform)
|
|
1471
|
+
* and re-lay the tree out. The page calls this on boot and whenever a
|
|
1472
|
+
* control changes. The platform is also on the document
|
|
1473
|
+
* (`html[data-sb-platform]`), which the stylesheet themes by.
|
|
1469
1474
|
*/
|
|
1470
1475
|
setEnvironment(environment: Partial<RendererEnvironment>): void {
|
|
1471
1476
|
const next = { ...this.environment, ...environment };
|
|
1472
|
-
if (next.dynamicTypeSize === this.environment.dynamicTypeSize && next.colorScheme === this.environment.colorScheme) {
|
|
1477
|
+
if (next.dynamicTypeSize === this.environment.dynamicTypeSize && next.colorScheme === this.environment.colorScheme && next.platform === this.environment.platform) {
|
|
1473
1478
|
return;
|
|
1474
1479
|
}
|
|
1475
1480
|
this.environment = next;
|
|
1481
|
+
this.root.ownerDocument.documentElement.dataset['sbPlatform'] = next.platform;
|
|
1476
1482
|
if (this.commits > 0) this.layout();
|
|
1477
1483
|
}
|
|
1478
1484
|
|
|
1485
|
+
/** The platform drawn (`setEnvironment`). */
|
|
1486
|
+
get platform(): Platform {
|
|
1487
|
+
return this.environment.platform;
|
|
1488
|
+
}
|
|
1489
|
+
|
|
1479
1490
|
/**
|
|
1480
1491
|
* Phase 5: give the renderer the app's asset catalog manifest (src/assets.ts).
|
|
1481
1492
|
* Named images take their intrinsic size and `src` from it, and every
|
|
@@ -1589,6 +1600,7 @@ export class Renderer {
|
|
|
1589
1600
|
dynamicTypeSize: this.environment.dynamicTypeSize,
|
|
1590
1601
|
devicePixelRatio: typeof window !== 'undefined' ? window.devicePixelRatio || 1 : 1,
|
|
1591
1602
|
colorScheme: this.environment.colorScheme,
|
|
1603
|
+
platform: this.environment.platform,
|
|
1592
1604
|
assets: this.assets,
|
|
1593
1605
|
...(this.contentHeight ? { contentHeight: true } : {}),
|
|
1594
1606
|
...(this.keyboard > 0 ? { keyboard: this.keyboard } : {}),
|
|
@@ -4843,8 +4855,13 @@ function applyPicker(el: HTMLElement, props: PickerProps): void {
|
|
|
4843
4855
|
el.removeAttribute('aria-haspopup');
|
|
4844
4856
|
el.removeAttribute('aria-expanded');
|
|
4845
4857
|
// The gray track sits at the control's frame (which, in a list row, is
|
|
4846
|
-
// narrower than the row box the element occupies)
|
|
4858
|
+
// narrower than the row box the element occupies); the label shows only
|
|
4859
|
+
// where the engine places it (the Mac idiom).
|
|
4847
4860
|
el.append(div('sb-segment-track'));
|
|
4861
|
+
const segmentedLabel = span('sb-picker-label');
|
|
4862
|
+
segmentedLabel.textContent = label;
|
|
4863
|
+
segmentedLabel.hidden = true;
|
|
4864
|
+
el.append(segmentedLabel);
|
|
4848
4865
|
options.forEach((option, index) => {
|
|
4849
4866
|
const segment = document.createElement('button');
|
|
4850
4867
|
segment.type = 'button';
|