@littlepress/renderer-web 0.0.0-stage → 1.0.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/LICENSE +202 -0
- package/NOTICE +20 -0
- package/README.md +229 -2
- package/dist/answer/answerComponents.d.ts +107 -0
- package/dist/answer/answerComponents.js +637 -0
- package/dist/answer/download.d.ts +63 -0
- package/dist/answer/download.js +109 -0
- package/dist/answer/downloadExport.d.ts +44 -0
- package/dist/answer/downloadExport.js +266 -0
- package/dist/answer/hostValues.d.ts +28 -0
- package/dist/answer/hostValues.js +379 -0
- package/dist/answer/mapComponent.d.ts +6 -0
- package/dist/answer/mapComponent.js +213 -0
- package/dist/answer/math.d.ts +57 -0
- package/dist/answer/math.js +168 -0
- package/dist/answer/surfaceStream.d.ts +51 -0
- package/dist/answer/surfaceStream.js +260 -0
- package/dist/answer/tableLayout.d.ts +42 -0
- package/dist/answer/tableLayout.js +89 -0
- package/dist/controls/ActionFeedback.d.ts +5 -0
- package/dist/controls/ActionFeedback.js +43 -0
- package/dist/controls/actionDispatch.d.ts +51 -0
- package/dist/controls/actionDispatch.js +211 -0
- package/dist/controls/actionOutcome.generated.d.ts +64 -0
- package/dist/controls/actionOutcome.generated.js +64 -0
- package/dist/controls/calculationPublisher.d.ts +14 -0
- package/dist/controls/calculationPublisher.js +6 -0
- package/dist/controls/calculations.d.ts +20 -0
- package/dist/controls/calculations.generated.d.ts +73 -0
- package/dist/controls/calculations.generated.js +85 -0
- package/dist/controls/calculations.js +208 -0
- package/dist/controls/controlState.d.ts +84 -0
- package/dist/controls/controlState.js +256 -0
- package/dist/controls/fieldMessages.d.ts +41 -0
- package/dist/controls/fieldMessages.js +81 -0
- package/dist/controls/fieldValidation.d.ts +19 -0
- package/dist/controls/fieldValidation.js +98 -0
- package/dist/controls/formComponents.d.ts +23 -0
- package/dist/controls/formComponents.js +738 -0
- package/dist/controls/formProgress.d.ts +63 -0
- package/dist/controls/formProgress.js +122 -0
- package/dist/controls/inputDrafts.d.ts +55 -0
- package/dist/controls/inputDrafts.js +183 -0
- package/dist/controls/inputValidation.d.ts +33 -0
- package/dist/controls/inputValidation.js +119 -0
- package/dist/controls/localWrites.d.ts +9 -0
- package/dist/controls/localWrites.js +29 -0
- package/dist/core/A2uiSurface.d.ts +13 -0
- package/dist/core/A2uiSurface.js +15 -0
- package/dist/core/AtlasIcon.d.ts +18 -0
- package/dist/core/AtlasIcon.js +22 -0
- package/dist/core/AtlasMedia.d.ts +22 -0
- package/dist/core/AtlasMedia.js +45 -0
- package/dist/core/Carousel.d.ts +61 -0
- package/dist/core/Carousel.js +183 -0
- package/dist/core/CoreMedia.d.ts +19 -0
- package/dist/core/CoreMedia.js +25 -0
- package/dist/core/FoundationA2uiSurface.d.ts +86 -0
- package/dist/core/FoundationA2uiSurface.js +440 -0
- package/dist/core/ImagePreview.d.ts +42 -0
- package/dist/core/ImagePreview.js +73 -0
- package/dist/core/LucideIcon.d.ts +19 -0
- package/dist/core/LucideIcon.js +42 -0
- package/dist/core/SurfaceLink.d.ts +35 -0
- package/dist/core/SurfaceLink.js +60 -0
- package/dist/core/appearance/aegis.d.ts +49 -0
- package/dist/core/appearance/aegis.js +34 -0
- package/dist/core/appearance/colour.d.ts +24 -0
- package/dist/core/appearance/colour.js +103 -0
- package/dist/core/appearance/css.d.ts +17 -0
- package/dist/core/appearance/css.js +153 -0
- package/dist/core/appearance/presets.generated.d.ts +4 -0
- package/dist/core/appearance/presets.generated.js +1184 -0
- package/dist/core/appearance/react.d.ts +29 -0
- package/dist/core/appearance/react.js +110 -0
- package/dist/core/appearance/resolve.d.ts +76 -0
- package/dist/core/appearance/resolve.js +127 -0
- package/dist/core/appearance/textScale.d.ts +11 -0
- package/dist/core/appearance/textScale.js +51 -0
- package/dist/core/appearance/theme.d.ts +138 -0
- package/dist/core/appearance/theme.js +274 -0
- package/dist/core/baseComponents.d.ts +53 -0
- package/dist/core/baseComponents.js +480 -0
- package/dist/core/binding.d.ts +46 -0
- package/dist/core/binding.js +118 -0
- package/dist/core/bundle.d.ts +23 -0
- package/dist/core/bundle.js +75 -0
- package/dist/core/catalog/catalog-index.generated.d.ts +44 -0
- package/dist/core/catalog/catalog-index.generated.js +79 -0
- package/dist/core/catalog/icons.generated.d.ts +6 -0
- package/dist/core/catalog/icons.generated.js +1788 -0
- package/dist/core/catalog.d.ts +6 -0
- package/dist/core/catalog.generated.d.ts +50 -0
- package/dist/core/catalog.generated.js +2174 -0
- package/dist/core/catalog.js +8 -0
- package/dist/core/chartRows.d.ts +7 -0
- package/dist/core/chartRows.js +38 -0
- package/dist/core/component-support.d.ts +39 -0
- package/dist/core/component-support.js +127 -0
- package/dist/core/components/actions.d.ts +4 -0
- package/dist/core/components/actions.js +21 -0
- package/dist/core/components/cards.d.ts +9 -0
- package/dist/core/components/cards.js +227 -0
- package/dist/core/components/charts.d.ts +18 -0
- package/dist/core/components/charts.js +412 -0
- package/dist/core/components/comparisonTable.d.ts +50 -0
- package/dist/core/components/comparisonTable.js +89 -0
- package/dist/core/components/content.d.ts +13 -0
- package/dist/core/components/content.js +108 -0
- package/dist/core/components/seriesCharts.d.ts +531 -0
- package/dist/core/components/seriesCharts.js +1053 -0
- package/dist/core/components/stepFlow.d.ts +7 -0
- package/dist/core/components/stepFlow.js +13 -0
- package/dist/core/components.full.d.ts +10 -0
- package/dist/core/components.full.js +41 -0
- package/dist/core/context.d.ts +207 -0
- package/dist/core/context.js +172 -0
- package/dist/core/coverage.d.ts +30 -0
- package/dist/core/coverage.js +93 -0
- package/dist/core/foundation.d.ts +21 -0
- package/dist/core/foundation.js +22 -0
- package/dist/core/fullTheme.d.ts +5 -0
- package/dist/core/fullTheme.js +9 -0
- package/dist/core/iconNodes.generated.d.ts +7 -0
- package/dist/core/iconNodes.generated.js +5 -0
- package/dist/core/lucideIcons.d.ts +5 -0
- package/dist/core/lucideIcons.js +7 -0
- package/dist/core/messages.d.ts +111 -0
- package/dist/core/messages.js +134 -0
- package/dist/core/pointer.d.ts +17 -0
- package/dist/core/pointer.js +104 -0
- package/dist/core/registry.d.ts +12 -0
- package/dist/core/registry.js +114 -0
- package/dist/core/runtime.d.ts +8 -0
- package/dist/core/runtime.js +6 -0
- package/dist/core/state.d.ts +73 -0
- package/dist/core/state.js +274 -0
- package/dist/core/surfaceMotion.d.ts +5 -0
- package/dist/core/surfaceMotion.js +46 -0
- package/dist/core/theme.d.ts +5 -0
- package/dist/core/theme.js +7 -0
- package/dist/core/useSurfaceImage.d.ts +20 -0
- package/dist/core/useSurfaceImage.js +65 -0
- package/dist/graph/RelationshipGraph.d.ts +14 -0
- package/dist/graph/RelationshipGraph.js +206 -0
- package/dist/graph/model.d.ts +20 -0
- package/dist/graph/model.js +36 -0
- package/dist/graph/program/assets.d.ts +3 -0
- package/dist/graph/program/assets.js +3 -0
- package/dist/graph/program/bridge.d.ts +6 -0
- package/dist/graph/program/bridge.generated.d.ts +136 -0
- package/dist/graph/program/bridge.generated.js +1 -0
- package/dist/graph/program/bridge.js +24 -0
- package/dist/graph/program/bridge.schema.json +717 -0
- package/dist/graph/program/bridgeValidator.cjs +2 -0
- package/dist/graph/program/bridgeValidator.d.cts +4 -0
- package/dist/graph/program/runner.d.ts +1 -0
- package/dist/graph/program/runner.html +2193 -0
- package/dist/graph/program/runner.js +157 -0
- package/dist/graph/program/runtime-manifest.json +1 -0
- package/dist/graph/program/view.d.ts +11 -0
- package/dist/graph/program/view.js +210 -0
- package/dist/graph/program/worker.d.ts +1 -0
- package/dist/graph/program/worker.js +2186 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +45 -0
- package/dist/internal/dsh.d.ts +4 -0
- package/dist/internal/dsh.js +3 -0
- package/dist/internal/relationship-graph.d.ts +4 -0
- package/dist/internal/relationship-graph.js +7202 -0
- package/dist/page/layoutComponents.d.ts +6 -0
- package/dist/page/layoutComponents.js +123 -0
- package/dist/page/layoutGeometry.d.ts +68 -0
- package/dist/page/layoutGeometry.js +174 -0
- package/dist/page/pageFormat.d.ts +34 -0
- package/dist/page/pageFormat.js +119 -0
- package/dist/page/printFit.d.ts +81 -0
- package/dist/page/printFit.js +338 -0
- package/dist/react/index.d.ts +5 -0
- package/dist/react/index.js +2 -0
- package/dist/report/locate.d.ts +42 -0
- package/dist/report/locate.js +34 -0
- package/dist/styles/renderer.css +4580 -0
- package/licenses/LUCIDE-LICENSE.txt +43 -0
- package/licenses/QUICKJS-EMSCRIPTEN-LICENSE.txt +21 -0
- package/licenses/QUICKJS-VARIANT-LICENSE.txt +47 -0
- package/package.json +68 -3
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type Appearance, type AppearanceResult, type ResolvedAppearance, type SystemAppearance } from "./resolve.ts";
|
|
3
|
+
import type { AppearanceProblem } from "./theme.ts";
|
|
4
|
+
/** Receives what was refused or clamped; the `appearance_rejected` diagnostic. */
|
|
5
|
+
export type AppearanceProblemHandler = (problems: readonly AppearanceProblem[]) => void;
|
|
6
|
+
export type LittlePressAppearanceProps = Appearance & {
|
|
7
|
+
children?: ReactNode;
|
|
8
|
+
/** Called with every refused or clamped value. Without it the problems are logged with `console.error`. */
|
|
9
|
+
onProblems?: AppearanceProblemHandler;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Sets how every LittlePress surface inside it looks. Nest it to change part of the page; an inner
|
|
13
|
+
* one only needs the settings it changes. Changing any setting redraws in place: drafts, selections
|
|
14
|
+
* and running programs are kept.
|
|
15
|
+
*/
|
|
16
|
+
export declare function LittlePressAppearance({ children, onProblems, ...appearance }: LittlePressAppearanceProps): import("react/jsx-runtime").JSX.Element;
|
|
17
|
+
/** The platform's colour scheme, contrast, motion and text size settings; follows changes. */
|
|
18
|
+
export declare function useSystemAppearance(): SystemAppearance;
|
|
19
|
+
/**
|
|
20
|
+
* Resolve the surrounding appearance with optional overrides. A refused theme keeps the last theme
|
|
21
|
+
* that passed, so switching to a broken theme never blanks the screen.
|
|
22
|
+
*/
|
|
23
|
+
export declare function useAppearanceResult(overrides?: Appearance): AppearanceResult;
|
|
24
|
+
export type LittlePressAppearanceValues = ResolvedAppearance & {
|
|
25
|
+
/** The same CSS custom properties a surface sets, for the Host's own elements (`style={cssVariables}`). */
|
|
26
|
+
cssVariables: Record<string, string>;
|
|
27
|
+
};
|
|
28
|
+
/** The resolved appearance for the Host's own screens: colours, text styles and sizes already computed. */
|
|
29
|
+
export declare function useLittlePressAppearance(): LittlePressAppearanceValues;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useEffect, useMemo, useRef, useSyncExternalStore } from "react";
|
|
3
|
+
import { appearanceCssVariables, systemFontStacks } from "./css.js";
|
|
4
|
+
import { resolveAppearance } from "./resolve.js";
|
|
5
|
+
const AppearanceContext = createContext({ appearance: {} });
|
|
6
|
+
function defined(appearance) {
|
|
7
|
+
return Object.fromEntries(Object.entries(appearance).filter(([, value]) => value !== undefined));
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Sets how every LittlePress surface inside it looks. Nest it to change part of the page; an inner
|
|
11
|
+
* one only needs the settings it changes. Changing any setting redraws in place: drafts, selections
|
|
12
|
+
* and running programs are kept.
|
|
13
|
+
*/
|
|
14
|
+
export function LittlePressAppearance({ children, onProblems, ...appearance }) {
|
|
15
|
+
const outer = useContext(AppearanceContext);
|
|
16
|
+
const { theme, colorMode, textScale, contrast, boldText, reducedMotion, minTouchTarget } = appearance;
|
|
17
|
+
const value = useMemo(() => ({
|
|
18
|
+
appearance: { ...outer.appearance, ...defined({ theme, colorMode, textScale, contrast, boldText, reducedMotion, minTouchTarget }) },
|
|
19
|
+
onProblems: onProblems ?? outer.onProblems,
|
|
20
|
+
}), [outer, onProblems, theme, colorMode, textScale, contrast, boldText, reducedMotion, minTouchTarget]);
|
|
21
|
+
return _jsx(AppearanceContext.Provider, { value: value, children: children });
|
|
22
|
+
}
|
|
23
|
+
const queries = {
|
|
24
|
+
dark: "(prefers-color-scheme: dark)",
|
|
25
|
+
highContrast: "(prefers-contrast: more)",
|
|
26
|
+
reducedMotion: "(prefers-reduced-motion: reduce)",
|
|
27
|
+
};
|
|
28
|
+
let fontProbe;
|
|
29
|
+
/**
|
|
30
|
+
* The browser's own text size, read from a hidden element sized `medium`. Unlike the root font
|
|
31
|
+
* size it ignores the page's `html { font-size }`, so a Host stylesheet with `62.5%` does not shrink
|
|
32
|
+
* the cards.
|
|
33
|
+
*/
|
|
34
|
+
function browserDefaultFontSize() {
|
|
35
|
+
const document = window.document;
|
|
36
|
+
if (!document.body)
|
|
37
|
+
return 0;
|
|
38
|
+
if (!fontProbe || !fontProbe.isConnected) {
|
|
39
|
+
fontProbe = document.createElement("span");
|
|
40
|
+
fontProbe.setAttribute("aria-hidden", "true");
|
|
41
|
+
fontProbe.style.cssText = "position:absolute;visibility:hidden;pointer-events:none;font-size:medium;";
|
|
42
|
+
document.body.appendChild(fontProbe);
|
|
43
|
+
}
|
|
44
|
+
const size = Number.parseFloat(window.getComputedStyle(fontProbe).fontSize);
|
|
45
|
+
return Number.isFinite(size) ? size : 0;
|
|
46
|
+
}
|
|
47
|
+
function readSystem() {
|
|
48
|
+
if (typeof window === "undefined" || typeof window.matchMedia !== "function")
|
|
49
|
+
return "{}";
|
|
50
|
+
const defaultSize = browserDefaultFontSize();
|
|
51
|
+
const system = {
|
|
52
|
+
dark: window.matchMedia(queries.dark).matches,
|
|
53
|
+
highContrast: window.matchMedia(queries.highContrast).matches,
|
|
54
|
+
reducedMotion: window.matchMedia(queries.reducedMotion).matches,
|
|
55
|
+
// The browser's text size setting; 16px is the default.
|
|
56
|
+
textScale: defaultSize > 0 ? defaultSize / 16 : 1,
|
|
57
|
+
};
|
|
58
|
+
return JSON.stringify(system);
|
|
59
|
+
}
|
|
60
|
+
function subscribeSystem(onChange) {
|
|
61
|
+
if (typeof window === "undefined" || typeof window.matchMedia !== "function")
|
|
62
|
+
return () => { };
|
|
63
|
+
const lists = Object.values(queries).map((query) => window.matchMedia(query));
|
|
64
|
+
for (const list of lists)
|
|
65
|
+
list.addEventListener("change", onChange);
|
|
66
|
+
window.addEventListener("resize", onChange);
|
|
67
|
+
return () => {
|
|
68
|
+
for (const list of lists)
|
|
69
|
+
list.removeEventListener("change", onChange);
|
|
70
|
+
window.removeEventListener("resize", onChange);
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
/** The platform's colour scheme, contrast, motion and text size settings; follows changes. */
|
|
74
|
+
export function useSystemAppearance() {
|
|
75
|
+
const snapshot = useSyncExternalStore(subscribeSystem, readSystem, () => "{}");
|
|
76
|
+
return useMemo(() => JSON.parse(snapshot), [snapshot]);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Resolve the surrounding appearance with optional overrides. A refused theme keeps the last theme
|
|
80
|
+
* that passed, so switching to a broken theme never blanks the screen.
|
|
81
|
+
*/
|
|
82
|
+
export function useAppearanceResult(overrides = {}) {
|
|
83
|
+
const { appearance, onProblems } = useContext(AppearanceContext);
|
|
84
|
+
const system = useSystemAppearance();
|
|
85
|
+
const lastTheme = useRef(undefined);
|
|
86
|
+
const merged = { ...appearance, ...defined(overrides) };
|
|
87
|
+
const result = useMemo(() => resolveAppearance(merged, { system, platform: "web", fallbackTheme: lastTheme.current }),
|
|
88
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
89
|
+
[system, merged.theme, merged.colorMode, merged.textScale, merged.contrast, merged.boldText, merged.reducedMotion, merged.minTouchTarget]);
|
|
90
|
+
lastTheme.current = result.theme;
|
|
91
|
+
const reported = useRef("");
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
const key = JSON.stringify(result.problems);
|
|
94
|
+
if (key === reported.current)
|
|
95
|
+
return;
|
|
96
|
+
reported.current = key;
|
|
97
|
+
if (result.problems.length === 0)
|
|
98
|
+
return;
|
|
99
|
+
if (onProblems)
|
|
100
|
+
onProblems(result.problems);
|
|
101
|
+
else
|
|
102
|
+
console.error("LittlePress appearance_rejected", result.problems);
|
|
103
|
+
}, [result.problems, onProblems]);
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
/** The resolved appearance for the Host's own screens: colours, text styles and sizes already computed. */
|
|
107
|
+
export function useLittlePressAppearance() {
|
|
108
|
+
const { resolved } = useAppearanceResult();
|
|
109
|
+
return useMemo(() => ({ ...resolved, cssVariables: { ...systemFontStacks, ...appearanceCssVariables(resolved) } }), [resolved]);
|
|
110
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve what a Host set and what the system reports into the values renderers, Aegis programs
|
|
3
|
+
* and the Host's own screens use. See docs/architecture/host-appearance.md §3, §5.
|
|
4
|
+
*/
|
|
5
|
+
import { type AppearanceProblem, type CompleteModeValues, type CompleteTheme, type Theme } from "./theme.ts";
|
|
6
|
+
/** What a Host sets. Every field is optional; an absent field follows the system. */
|
|
7
|
+
export interface Appearance {
|
|
8
|
+
theme?: Theme;
|
|
9
|
+
colorMode?: "light" | "dark" | "system";
|
|
10
|
+
/** Multiplied with the system text size; clamped to 0.85–3. */
|
|
11
|
+
textScale?: number;
|
|
12
|
+
contrast?: "standard" | "high" | "system";
|
|
13
|
+
boldText?: boolean;
|
|
14
|
+
/** `true` turns motion off. The Host cannot turn motion back on once the system has turned it off. */
|
|
15
|
+
reducedMotion?: boolean;
|
|
16
|
+
/** Smallest tappable size in dp, pt or CSS px; never below the platform floor. */
|
|
17
|
+
minTouchTarget?: number;
|
|
18
|
+
}
|
|
19
|
+
/** What the platform reports. Web reads media queries; Android and iOS read their accessibility settings. */
|
|
20
|
+
export interface SystemAppearance {
|
|
21
|
+
dark?: boolean;
|
|
22
|
+
/** System text size as a multiplier (Android `fontScale`, iOS content size, browser root size / 16). */
|
|
23
|
+
textScale?: number;
|
|
24
|
+
highContrast?: boolean;
|
|
25
|
+
boldText?: boolean;
|
|
26
|
+
reducedMotion?: boolean;
|
|
27
|
+
}
|
|
28
|
+
export type AppearancePlatform = "web" | "android" | "ios";
|
|
29
|
+
export declare const touchTargetFloor: Readonly<Record<AppearancePlatform, number>>;
|
|
30
|
+
export declare const textScaleRange: {
|
|
31
|
+
readonly min: 0.85;
|
|
32
|
+
readonly max: 3;
|
|
33
|
+
};
|
|
34
|
+
/** Added to every text weight when bold text is on, capped at `boldWeightCap`. */
|
|
35
|
+
export declare const boldWeightIncrease = 300;
|
|
36
|
+
export declare const boldWeightCap = 800;
|
|
37
|
+
/** Everything a renderer needs, with display settings already applied. */
|
|
38
|
+
export interface ResolvedAppearance {
|
|
39
|
+
themeId: string;
|
|
40
|
+
mode: "light" | "dark";
|
|
41
|
+
contrast: "standard" | "high";
|
|
42
|
+
/** Colours for the current mode, after high contrast. */
|
|
43
|
+
color: CompleteModeValues["color"];
|
|
44
|
+
controlColor: CompleteModeValues["controlColor"];
|
|
45
|
+
shadow: CompleteModeValues["shadow"];
|
|
46
|
+
font: CompleteTheme["font"];
|
|
47
|
+
/** Text styles at text scale 1 with bold text applied; renderers apply the text scale curve. */
|
|
48
|
+
type: CompleteTheme["type"];
|
|
49
|
+
tracking: CompleteTheme["tracking"];
|
|
50
|
+
space: CompleteTheme["space"];
|
|
51
|
+
size: CompleteTheme["size"];
|
|
52
|
+
radius: CompleteTheme["radius"];
|
|
53
|
+
controls: CompleteTheme["controls"];
|
|
54
|
+
/** Host multiplier × system text size. */
|
|
55
|
+
textScale: number;
|
|
56
|
+
boldText: boolean;
|
|
57
|
+
reducedMotion: boolean;
|
|
58
|
+
minTouchTarget: number;
|
|
59
|
+
}
|
|
60
|
+
export interface AppearanceResult {
|
|
61
|
+
resolved: ResolvedAppearance;
|
|
62
|
+
/** The theme in use: the Host's when it passed the check, otherwise `fallbackTheme`. */
|
|
63
|
+
theme: Theme;
|
|
64
|
+
/** Non-empty when something was refused or clamped; report as the `appearance_rejected` diagnostic. */
|
|
65
|
+
problems: AppearanceProblem[];
|
|
66
|
+
}
|
|
67
|
+
export interface ResolveAppearanceOptions {
|
|
68
|
+
system?: SystemAppearance;
|
|
69
|
+
platform?: AppearancePlatform;
|
|
70
|
+
/** Kept when the Host gives a theme that fails the check: the theme in use before. Without it, the neutral preset. Not used when no theme is given. */
|
|
71
|
+
fallbackTheme?: Theme;
|
|
72
|
+
}
|
|
73
|
+
/** High contrast (§5.3): secondary text takes the text colour, accent and button text reach 7:1, outlines 4.5:1. */
|
|
74
|
+
export declare function highContrastColours(values: CompleteModeValues, mode: "light" | "dark"): CompleteModeValues;
|
|
75
|
+
/** Combine the Host's appearance with the system settings. Never throws; refused values are reported in `problems`. */
|
|
76
|
+
export declare function resolveAppearance(appearance?: Appearance, options?: ResolveAppearanceOptions): AppearanceResult;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolve what a Host set and what the system reports into the values renderers, Aegis programs
|
|
3
|
+
* and the Host's own screens use. See docs/architecture/host-appearance.md §3, §5.
|
|
4
|
+
*/
|
|
5
|
+
import { adjustForContrast, contrastRatio, over } from "./colour.js";
|
|
6
|
+
import { themePresets } from "./presets.generated.js";
|
|
7
|
+
import { checkTheme, completeTheme, minimumContrast, minimumHighContrast, refusesTheme, solidColours, withoutUnknownFields, } from "./theme.js";
|
|
8
|
+
export const touchTargetFloor = { web: 44, android: 48, ios: 44 };
|
|
9
|
+
export const textScaleRange = { min: 0.85, max: 3 };
|
|
10
|
+
/** The Host's scale times the platform's, kept inside [textScaleRange]. */
|
|
11
|
+
function clampTextScale(scale) {
|
|
12
|
+
return Number.isFinite(scale) ? Math.min(textScaleRange.max, Math.max(textScaleRange.min, scale)) : 1;
|
|
13
|
+
}
|
|
14
|
+
/** Added to every text weight when bold text is on, capped at `boldWeightCap`. */
|
|
15
|
+
export const boldWeightIncrease = 300;
|
|
16
|
+
export const boldWeightCap = 800;
|
|
17
|
+
/** High contrast (§5.3): secondary text takes the text colour, accent and button text reach 7:1, outlines 4.5:1. */
|
|
18
|
+
export function highContrastColours(values, mode) {
|
|
19
|
+
const c = values.color;
|
|
20
|
+
const solid = solidColours(c);
|
|
21
|
+
const given = values.highContrastColor;
|
|
22
|
+
const direction = mode === "light" ? -1 : 1;
|
|
23
|
+
const textVariant = given.textVariant ?? c.text;
|
|
24
|
+
const accent = given.accent ?? adjustForContrast(solid.accent, [solid.surface, solid.surfaceVariant, solid.onAccent], minimumHighContrast, direction);
|
|
25
|
+
let onAccent = given.onAccent ?? c.onAccent;
|
|
26
|
+
if (given.onAccent === undefined && contrastRatio(over(onAccent, accent), accent) < minimumHighContrast) {
|
|
27
|
+
onAccent = contrastRatio("#FFFFFF", accent) >= contrastRatio("#000000", accent) ? "#FFFFFF" : "#000000";
|
|
28
|
+
}
|
|
29
|
+
const outline = given.outline ?? adjustForContrast(solid.outline, [solid.surface], minimumContrast, direction);
|
|
30
|
+
const control = values.controlColor;
|
|
31
|
+
return {
|
|
32
|
+
...values,
|
|
33
|
+
color: { ...c, textVariant, accent, onAccent, outline },
|
|
34
|
+
controlColor: {
|
|
35
|
+
...control,
|
|
36
|
+
stroke: textVariant,
|
|
37
|
+
tabText: textVariant,
|
|
38
|
+
active: accent,
|
|
39
|
+
onActive: onAccent,
|
|
40
|
+
thumbFill: control.thumbFill === control.active ? accent : control.thumbFill,
|
|
41
|
+
tabIndicator: control.tabIndicator === c.accent ? accent : control.tabIndicator,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function boldType(type) {
|
|
46
|
+
return Object.fromEntries(Object.entries(type).map(([role, value]) => [
|
|
47
|
+
role, { ...value, weight: Math.min(boldWeightCap, value.weight + boldWeightIncrease) },
|
|
48
|
+
]));
|
|
49
|
+
}
|
|
50
|
+
/** Combine the Host's appearance with the system settings. Never throws; refused values are reported in `problems`. */
|
|
51
|
+
export function resolveAppearance(appearance = {}, options = {}) {
|
|
52
|
+
const system = options.system ?? {};
|
|
53
|
+
const platform = options.platform ?? "web";
|
|
54
|
+
const problems = [];
|
|
55
|
+
// No theme given (never set, or taken away) means the default; the theme kept from before stands
|
|
56
|
+
// in only for a theme that was given and refused.
|
|
57
|
+
let theme = themePresets.neutral;
|
|
58
|
+
if (appearance.theme !== undefined) {
|
|
59
|
+
theme = options.fallbackTheme ?? theme;
|
|
60
|
+
const checked = checkTheme(appearance.theme);
|
|
61
|
+
const themeProblems = checked.map((problem) => ({
|
|
62
|
+
...problem,
|
|
63
|
+
path: problem.path ? `theme.${problem.path}` : "theme",
|
|
64
|
+
...(problem.against === undefined ? {} : { against: `theme.${problem.against}` }),
|
|
65
|
+
}));
|
|
66
|
+
// An unknown field (a token from a newer version) is ignored with a warning; anything else refuses the theme.
|
|
67
|
+
if (!checked.some(refusesTheme))
|
|
68
|
+
theme = withoutUnknownFields(appearance.theme, checked);
|
|
69
|
+
problems.push(...themeProblems);
|
|
70
|
+
}
|
|
71
|
+
const mode = appearance.colorMode === "light" || appearance.colorMode === "dark"
|
|
72
|
+
? appearance.colorMode
|
|
73
|
+
: system.dark ? "dark" : "light";
|
|
74
|
+
const contrast = appearance.contrast === "standard" || appearance.contrast === "high"
|
|
75
|
+
? appearance.contrast
|
|
76
|
+
: system.highContrast ? "high" : "standard";
|
|
77
|
+
let hostScale = 1;
|
|
78
|
+
if (appearance.textScale !== undefined) {
|
|
79
|
+
if (typeof appearance.textScale !== "number" || !Number.isFinite(appearance.textScale)) {
|
|
80
|
+
problems.push({ path: "textScale", code: "type" });
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
hostScale = Math.min(textScaleRange.max, Math.max(textScaleRange.min, appearance.textScale));
|
|
84
|
+
if (hostScale !== appearance.textScale)
|
|
85
|
+
problems.push({ path: "textScale", code: "range" });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
let hostTouch = 0;
|
|
89
|
+
if (appearance.minTouchTarget !== undefined) {
|
|
90
|
+
if (typeof appearance.minTouchTarget !== "number" || !Number.isFinite(appearance.minTouchTarget)) {
|
|
91
|
+
problems.push({ path: "minTouchTarget", code: "type" });
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
hostTouch = Math.min(160, Math.max(0, appearance.minTouchTarget));
|
|
95
|
+
if (hostTouch !== appearance.minTouchTarget)
|
|
96
|
+
problems.push({ path: "minTouchTarget", code: "range" });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const complete = completeTheme(theme);
|
|
100
|
+
const standard = complete[mode];
|
|
101
|
+
const values = contrast === "high" ? highContrastColours(standard, mode) : standard;
|
|
102
|
+
const boldText = appearance.boldText ?? system.boldText ?? false;
|
|
103
|
+
const minTouchTarget = Math.max(hostTouch, complete.size.minTouchTarget, touchTargetFloor[platform]);
|
|
104
|
+
return {
|
|
105
|
+
theme,
|
|
106
|
+
problems,
|
|
107
|
+
resolved: {
|
|
108
|
+
themeId: complete.id,
|
|
109
|
+
mode,
|
|
110
|
+
contrast,
|
|
111
|
+
color: values.color,
|
|
112
|
+
controlColor: values.controlColor,
|
|
113
|
+
shadow: values.shadow,
|
|
114
|
+
font: complete.font,
|
|
115
|
+
type: boldText ? boldType(complete.type) : complete.type,
|
|
116
|
+
tracking: complete.tracking,
|
|
117
|
+
space: complete.space,
|
|
118
|
+
size: { ...complete.size, minTouchTarget },
|
|
119
|
+
radius: complete.radius,
|
|
120
|
+
controls: complete.controls,
|
|
121
|
+
textScale: clampTextScale(hostScale * (system.textScale ?? 1)),
|
|
122
|
+
boldText,
|
|
123
|
+
reducedMotion: appearance.reducedMotion === true || system.reducedMotion === true,
|
|
124
|
+
minTouchTarget,
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Non-linear text scaling, the same on every platform (docs/architecture/host-appearance.md §5.2).
|
|
3
|
+
* Body text grows the most; large titles and figures grow less, so a card at text scale 2 stays
|
|
4
|
+
* readable instead of a few huge numbers pushing everything else out. The table follows the shape
|
|
5
|
+
* of Android 14's font scale tables: for each scale, the size a given base size becomes.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* The size `size` becomes at text scale `scale`. Below 1 every size shrinks in proportion.
|
|
9
|
+
* Above 2 the result at 2 grows in proportion to the extra scale.
|
|
10
|
+
*/
|
|
11
|
+
export declare function scaleTextSize(size: number, scale: number): number;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Non-linear text scaling, the same on every platform (docs/architecture/host-appearance.md §5.2).
|
|
3
|
+
* Body text grows the most; large titles and figures grow less, so a card at text scale 2 stays
|
|
4
|
+
* readable instead of a few huge numbers pushing everything else out. The table follows the shape
|
|
5
|
+
* of Android 14's font scale tables: for each scale, the size a given base size becomes.
|
|
6
|
+
*/
|
|
7
|
+
/** Base sizes the table is written for (px, dp or pt). Above the last one nothing grows. */
|
|
8
|
+
const baseSizes = [8, 10, 12, 14, 18, 20, 24, 30, 100];
|
|
9
|
+
/** Scale -> the size each base size becomes. Between two scales the result is interpolated. */
|
|
10
|
+
const curves = [
|
|
11
|
+
[1, [8, 10, 12, 14, 18, 20, 24, 30, 100]],
|
|
12
|
+
[1.15, [9.2, 11.5, 13.8, 16.4, 19.8, 21.8, 25.2, 30, 100]],
|
|
13
|
+
[1.3, [10.4, 13, 15.6, 18.8, 21.6, 23.6, 26.4, 30, 100]],
|
|
14
|
+
[1.5, [12, 15, 18, 22, 24, 26, 28, 30, 100]],
|
|
15
|
+
[1.8, [14.4, 18, 21.6, 24.4, 27.6, 30.8, 32.8, 34.8, 100]],
|
|
16
|
+
[2, [16, 20, 24, 26, 30, 34, 36, 38, 100]],
|
|
17
|
+
];
|
|
18
|
+
function along(table, size) {
|
|
19
|
+
if (size <= baseSizes[0])
|
|
20
|
+
return size * (table[0] / baseSizes[0]);
|
|
21
|
+
for (let i = 1; i < baseSizes.length; i += 1) {
|
|
22
|
+
const upper = baseSizes[i];
|
|
23
|
+
if (size <= upper) {
|
|
24
|
+
const lower = baseSizes[i - 1];
|
|
25
|
+
const t = (size - lower) / (upper - lower);
|
|
26
|
+
return table[i - 1] + (table[i] - table[i - 1]) * t;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return size;
|
|
30
|
+
}
|
|
31
|
+
const round = (value) => Math.round(value * 100) / 100;
|
|
32
|
+
/**
|
|
33
|
+
* The size `size` becomes at text scale `scale`. Below 1 every size shrinks in proportion.
|
|
34
|
+
* Above 2 the result at 2 grows in proportion to the extra scale.
|
|
35
|
+
*/
|
|
36
|
+
export function scaleTextSize(size, scale) {
|
|
37
|
+
if (scale <= 1)
|
|
38
|
+
return round(size * scale);
|
|
39
|
+
if (scale >= 2)
|
|
40
|
+
return round(along(curves[curves.length - 1][1], size) * (scale / 2));
|
|
41
|
+
for (let i = 1; i < curves.length; i += 1) {
|
|
42
|
+
const [upperScale, upperTable] = curves[i];
|
|
43
|
+
if (scale <= upperScale) {
|
|
44
|
+
const [lowerScale, lowerTable] = curves[i - 1];
|
|
45
|
+
const t = (scale - lowerScale) / (upperScale - lowerScale);
|
|
46
|
+
const low = along(lowerTable, size);
|
|
47
|
+
return round(low + (along(upperTable, size) - low) * t);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return round(size);
|
|
51
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The theme a Host gives the SDK: explicit values, no style-pack name. `checkTheme` applies the
|
|
3
|
+
* shape and contrast rules of ui-foundation/surface/contracts/schema/appearance.json; `completeTheme`
|
|
4
|
+
* fills every optional value so renderers never guess. See docs/architecture/host-appearance.md §4, §7.
|
|
5
|
+
*/
|
|
6
|
+
export declare const themeSchema = "littlepress.theme/1";
|
|
7
|
+
export declare const requiredColours: readonly ["background", "surface", "surfaceVariant", "text", "textVariant", "accent", "onAccent", "outline", "positive", "warning", "danger", "info", "series1", "series2", "series3", "series4"];
|
|
8
|
+
export declare const optionalColours: readonly ["highlight", "surfaceDisabled", "textDisabled", "onAccentVariant", "hover", "accentContainer"];
|
|
9
|
+
export declare const controlColours: readonly ["fill", "stroke", "active", "onActive", "tabSurface", "tabActiveSurface", "tabText", "tabActiveText", "tabIndicator", "thumbFill"];
|
|
10
|
+
export declare const typeRoles: readonly ["display", "headline", "titleLarge", "titleSmall", "bodyLarge", "bodyMedium", "bodySmall", "labelLarge", "labelSmall"];
|
|
11
|
+
export type RequiredColour = (typeof requiredColours)[number];
|
|
12
|
+
export type OptionalColour = (typeof optionalColours)[number];
|
|
13
|
+
export type ControlColour = (typeof controlColours)[number];
|
|
14
|
+
export type TypeRoleName = (typeof typeRoles)[number];
|
|
15
|
+
export type ThemeColours = Record<RequiredColour, string> & Partial<Record<OptionalColour, string>>;
|
|
16
|
+
export interface ShadowLayer {
|
|
17
|
+
x: number;
|
|
18
|
+
y: number;
|
|
19
|
+
blur: number;
|
|
20
|
+
spread: number;
|
|
21
|
+
color: string;
|
|
22
|
+
}
|
|
23
|
+
export interface TypeRole {
|
|
24
|
+
size: number;
|
|
25
|
+
lineHeight: number;
|
|
26
|
+
weight: number;
|
|
27
|
+
font?: "display" | "text";
|
|
28
|
+
}
|
|
29
|
+
export interface ThemeFont {
|
|
30
|
+
name?: string;
|
|
31
|
+
generic: "sans-serif" | "serif";
|
|
32
|
+
}
|
|
33
|
+
export interface ThemeModeValues {
|
|
34
|
+
color: ThemeColours;
|
|
35
|
+
highContrastColor?: Partial<Record<"textVariant" | "accent" | "onAccent" | "outline", string>>;
|
|
36
|
+
controlColor?: Partial<Record<ControlColour, string>>;
|
|
37
|
+
shadow?: {
|
|
38
|
+
card?: ShadowLayer[];
|
|
39
|
+
controlTab?: ShadowLayer[];
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export interface ThemeControls {
|
|
43
|
+
tabs?: "underline" | "segmented";
|
|
44
|
+
tabsFullWidth?: boolean;
|
|
45
|
+
fields?: "standard" | "filled";
|
|
46
|
+
markRadius?: number;
|
|
47
|
+
trackHeight?: number;
|
|
48
|
+
thumbWidth?: number;
|
|
49
|
+
thumbHeight?: number;
|
|
50
|
+
thumbRadius?: number;
|
|
51
|
+
tabRadius?: number;
|
|
52
|
+
tabTrackPadding?: number;
|
|
53
|
+
tabSegmentRadius?: number;
|
|
54
|
+
tabPaddingX?: number;
|
|
55
|
+
tabGap?: number;
|
|
56
|
+
tabWeight?: number;
|
|
57
|
+
tabActiveWeight?: number;
|
|
58
|
+
}
|
|
59
|
+
export interface Theme {
|
|
60
|
+
schema: typeof themeSchema;
|
|
61
|
+
id?: string;
|
|
62
|
+
light: ThemeModeValues;
|
|
63
|
+
dark: ThemeModeValues;
|
|
64
|
+
font?: {
|
|
65
|
+
display?: ThemeFont;
|
|
66
|
+
text?: ThemeFont;
|
|
67
|
+
};
|
|
68
|
+
type?: Partial<Record<TypeRoleName, TypeRole>>;
|
|
69
|
+
tracking?: {
|
|
70
|
+
overline?: number;
|
|
71
|
+
meta?: number;
|
|
72
|
+
};
|
|
73
|
+
space?: Partial<Record<"2xs" | "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "blockGap", number>>;
|
|
74
|
+
size?: Partial<Record<"control" | "row" | "avatar" | "icon" | "minTouchTarget", number>>;
|
|
75
|
+
radius?: Partial<Record<"control" | "surface" | "surfaceLarge" | "pill", number>>;
|
|
76
|
+
controls?: ThemeControls;
|
|
77
|
+
}
|
|
78
|
+
/** One reason a theme or display setting was refused, reported as the `appearance_rejected` diagnostic. */
|
|
79
|
+
export interface AppearanceProblem {
|
|
80
|
+
/** JSON path of the value, for example `light.color.accent`. */
|
|
81
|
+
path: string;
|
|
82
|
+
code: "missing" | "type" | "format" | "range" | "unknown" | "contrast";
|
|
83
|
+
/** For `contrast`: the colour the text sits on, the ratio reached and the ratio required. */
|
|
84
|
+
against?: string;
|
|
85
|
+
ratio?: number;
|
|
86
|
+
minimum?: number;
|
|
87
|
+
}
|
|
88
|
+
/** Text colour, the colour it sits on. Each pair must reach `minimumContrast` in both modes. */
|
|
89
|
+
export declare const contrastPairs: ReadonlyArray<readonly [RequiredColour, RequiredColour]>;
|
|
90
|
+
export declare const minimumContrast = 4.5;
|
|
91
|
+
export declare const minimumHighContrast = 7;
|
|
92
|
+
/**
|
|
93
|
+
* The required colours as the screen shows them: the surface over the page background, the variant
|
|
94
|
+
* surface over the surface, the accent over the surface, button text over the accent, and every other
|
|
95
|
+
* colour over the surface. Contrast and the derived colours are computed from these.
|
|
96
|
+
*/
|
|
97
|
+
export declare function solidColours(color: ThemeColours): Record<RequiredColour, string>;
|
|
98
|
+
/**
|
|
99
|
+
* Every problem with `value` as a theme; an empty list means it is clean. `unknown` (a field this
|
|
100
|
+
* version does not know, for example a token a newer version added) does not stop the theme from
|
|
101
|
+
* being used: Hosts ignore the field and report it as a warning. Every other code refuses the
|
|
102
|
+
* theme. Tools that write themes treat any problem, `unknown` included, as an error.
|
|
103
|
+
*/
|
|
104
|
+
export declare function checkTheme(value: unknown): AppearanceProblem[];
|
|
105
|
+
/** Whether a problem stops the theme from being used. Only `unknown` does not. */
|
|
106
|
+
export declare function refusesTheme(problem: AppearanceProblem): boolean;
|
|
107
|
+
/** `theme` without the fields `checkTheme` reported as `unknown`, so nothing unknown reaches drawing. */
|
|
108
|
+
export declare function withoutUnknownFields(theme: Theme, problems: readonly AppearanceProblem[]): Theme;
|
|
109
|
+
/** A theme with every optional value filled in. */
|
|
110
|
+
export interface CompleteTheme {
|
|
111
|
+
id: string;
|
|
112
|
+
light: CompleteModeValues;
|
|
113
|
+
dark: CompleteModeValues;
|
|
114
|
+
font: {
|
|
115
|
+
display: ThemeFont;
|
|
116
|
+
text: ThemeFont;
|
|
117
|
+
};
|
|
118
|
+
type: Record<TypeRoleName, Required<TypeRole>>;
|
|
119
|
+
tracking: {
|
|
120
|
+
overline: number;
|
|
121
|
+
meta: number;
|
|
122
|
+
};
|
|
123
|
+
space: Record<"2xs" | "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "blockGap", number>;
|
|
124
|
+
size: Record<"control" | "row" | "avatar" | "icon" | "minTouchTarget", number>;
|
|
125
|
+
radius: Record<"control" | "surface" | "surfaceLarge" | "pill", number>;
|
|
126
|
+
controls: Required<ThemeControls>;
|
|
127
|
+
}
|
|
128
|
+
export interface CompleteModeValues {
|
|
129
|
+
color: Record<RequiredColour | OptionalColour, string>;
|
|
130
|
+
highContrastColor: Partial<Record<"textVariant" | "accent" | "onAccent" | "outline", string>>;
|
|
131
|
+
controlColor: Record<ControlColour, string>;
|
|
132
|
+
shadow: {
|
|
133
|
+
card: ShadowLayer[];
|
|
134
|
+
controlTab: ShadowLayer[];
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/** Fill every optional value of a checked theme. Absent values come from the default theme or the formulas above. */
|
|
138
|
+
export declare function completeTheme(theme: Theme): CompleteTheme;
|