@colixsystems/widget-sdk 0.313.0 → 0.315.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/README.md +9 -1
- package/dist/contract.cjs +13 -4
- package/dist/contract.js +13 -4
- package/dist/host.d.ts +13 -1
- package/dist/host.js +3 -0
- package/dist/index.d.ts +2 -0
- package/dist/linter.cjs +4 -3
- package/dist/linter.js +4 -3
- package/dist/theme-components.cjs +9 -5
- package/dist/theme-components.js +8 -5
- package/dist/theme-text-roles.cjs +64 -0
- package/dist/theme-text-roles.js +55 -0
- package/package.json +1 -1
- package/src/contract.js +13 -4
package/README.md
CHANGED
|
@@ -90,7 +90,15 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
|
|
|
90
90
|
|
|
91
91
|
## Status
|
|
92
92
|
|
|
93
|
-
`v0.
|
|
93
|
+
`v0.315.0` — pre-publish. The package surface (types, function names, export paths) is the v1 contract; runtime behaviour for some hooks is stubbed (each hook documents what's wired and what isn't). It is **not yet published to npm**.
|
|
94
|
+
|
|
95
|
+
### What's new in 0.315.0 (contract 1.255.0)
|
|
96
|
+
|
|
97
|
+
**The theme's type scale never goes below 12 px.** `CONTRACT.minFontPx` (12) is the smallest page text the render check accepts, and the lower bound of the theme's font sizes: the six text tiers in `theme.typography.roles` and the Buttons and Text component sizes. A smaller value now clamps up to it instead of to 8, in the web Player, in the exported app and when the theme is saved, so a size taken from `useTheme()` always passes the app's render check. Text you size yourself should stay at or above it too. A theme already at 12 or more renders exactly as before.
|
|
98
|
+
|
|
99
|
+
### What's new in 0.314.0 (contract 1.254.0)
|
|
100
|
+
|
|
101
|
+
**Hosts validate typography roles through one function.** `@colixsystems/widget-sdk/host` exports `normaliseTypographyRoles(raw)` and `resolveTypographyRoles(raw)`, the single validator the web Player, the exported app and AppStudio's backend now share for a theme's `typographyRoles`. A role colour is trimmed before it is checked, like every other theme colour, so a padded hex in a hand-edited theme now renders on both hosts instead of being dropped. The widget contract is unchanged.
|
|
94
102
|
|
|
95
103
|
### What's new in 0.313.0 (contract 1.254.0)
|
|
96
104
|
|
package/dist/contract.cjs
CHANGED
|
@@ -313,6 +313,11 @@ const THEME_TEXT_ROLE_FONT_WEIGHTS = Object.freeze([
|
|
|
313
313
|
|
|
314
314
|
const THEME_TEXT_ROLE_FONT_STYLES = Object.freeze(["normal", "italic"]);
|
|
315
315
|
|
|
316
|
+
// sc-16654 — the smallest page text the render check accepts (TEXT_TOO_SMALL
|
|
317
|
+
// reads this value). The type scale and component font sizes clamp up to it on
|
|
318
|
+
// both hosts and at save; a per-widget size is the author's own choice.
|
|
319
|
+
const MIN_FONT_PX = 12;
|
|
320
|
+
|
|
316
321
|
// The per-role token vocabulary, declared like a `themeComponents` scope's
|
|
317
322
|
// `tokens`: each field's value type and bounds stated ONCE, so the Studio
|
|
318
323
|
// control, the set_theme coercion and the host validator cannot disagree.
|
|
@@ -320,7 +325,7 @@ const THEME_TEXT_ROLE_FONT_STYLES = Object.freeze(["normal", "italic"]);
|
|
|
320
325
|
// value is right at every size; `color` overrides the role's surface-aware
|
|
321
326
|
// `colorToken`, which is why no role seeds a literal colour.
|
|
322
327
|
const THEME_TEXT_ROLE_FIELDS = Object.freeze({
|
|
323
|
-
fontSize: Object.freeze({ type: "size", min:
|
|
328
|
+
fontSize: Object.freeze({ type: "size", min: MIN_FONT_PX, max: 96 }),
|
|
324
329
|
fontWeight: Object.freeze({ type: "enum", values: THEME_TEXT_ROLE_FONT_WEIGHTS }),
|
|
325
330
|
fontStyle: Object.freeze({ type: "enum", values: THEME_TEXT_ROLE_FONT_STYLES }),
|
|
326
331
|
lineHeight: Object.freeze({ type: "decimal", min: 0.8, max: 3, step: 0.05 }),
|
|
@@ -561,7 +566,7 @@ const THEME_COMPONENTS = Object.freeze({
|
|
|
561
566
|
textColor: Object.freeze({ type: "color", uiDefault: "colors.onPrimary" }),
|
|
562
567
|
borderColor: Object.freeze({ type: "color", uiDefault: "colors.border" }),
|
|
563
568
|
radius: Object.freeze({ type: "size", min: 0, max: 48, uiDefault: "radii.sm" }),
|
|
564
|
-
fontSize: Object.freeze({ type: "size", min:
|
|
569
|
+
fontSize: Object.freeze({ type: "size", min: MIN_FONT_PX, max: 96, uiDefault: "typography.sizes.sm" }),
|
|
565
570
|
shadow: Object.freeze({ type: "shadow" }),
|
|
566
571
|
gradient: Object.freeze({ type: "gradient" }),
|
|
567
572
|
}),
|
|
@@ -615,7 +620,7 @@ const THEME_COMPONENTS = Object.freeze({
|
|
|
615
620
|
label: "Text",
|
|
616
621
|
tokens: Object.freeze({
|
|
617
622
|
color: Object.freeze({ type: "color", uiDefault: "colors.onSurface" }),
|
|
618
|
-
fontSize: Object.freeze({ type: "size", min:
|
|
623
|
+
fontSize: Object.freeze({ type: "size", min: MIN_FONT_PX, max: 96, uiDefault: "typography.sizes.md" }),
|
|
619
624
|
// sc-3857 — leading as a MULTIPLE of the font size, so one app-wide value
|
|
620
625
|
// is right at every size; `size` cannot carry it because it rounds.
|
|
621
626
|
lineHeight: Object.freeze({ type: "decimal", min: 0.8, max: 3, step: 0.05 }),
|
|
@@ -6957,7 +6962,10 @@ const CONTRACT = deepFreeze({
|
|
|
6957
6962
|
// so `useSafeAreaInsets()` returns zeros on web as documented instead of throwing.
|
|
6958
6963
|
// 1.254.0: `formatMoney` shows a whole amount without decimals ("795 kr");
|
|
6959
6964
|
// `formatMoney(minor, { decimals: "always" })` keeps them ("795,00 kr").
|
|
6960
|
-
|
|
6965
|
+
// 1.255.0: fix (sc-16654) — `minFontPx` (12) publishes the smallest page text
|
|
6966
|
+
// the render check accepts. The theme's six text tiers and its Buttons and
|
|
6967
|
+
// Text component sizes now clamp up to it instead of to 8.
|
|
6968
|
+
version: "1.255.0",
|
|
6961
6969
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
6962
6970
|
hooks: HOOKS,
|
|
6963
6971
|
primitives: PRIMITIVES,
|
|
@@ -6979,6 +6987,7 @@ const CONTRACT = deepFreeze({
|
|
|
6979
6987
|
themeComponentGradient: THEME_COMPONENT_GRADIENT,
|
|
6980
6988
|
themeTextRoles: THEME_TEXT_ROLES,
|
|
6981
6989
|
themeTextRoleFields: THEME_TEXT_ROLE_FIELDS,
|
|
6990
|
+
minFontPx: MIN_FONT_PX,
|
|
6982
6991
|
themeSpacingScale: THEME_SPACING_SCALE,
|
|
6983
6992
|
themeMenuTypes: THEME_MENU_TYPES,
|
|
6984
6993
|
themeWidgetStyles: THEME_WIDGET_STYLES,
|
package/dist/contract.js
CHANGED
|
@@ -308,6 +308,11 @@ const THEME_TEXT_ROLE_FONT_WEIGHTS = Object.freeze([
|
|
|
308
308
|
|
|
309
309
|
const THEME_TEXT_ROLE_FONT_STYLES = Object.freeze(["normal", "italic"]);
|
|
310
310
|
|
|
311
|
+
// sc-16654 — the smallest page text the render check accepts (TEXT_TOO_SMALL
|
|
312
|
+
// reads this value). The type scale and component font sizes clamp up to it on
|
|
313
|
+
// both hosts and at save; a per-widget size is the author's own choice.
|
|
314
|
+
const MIN_FONT_PX = 12;
|
|
315
|
+
|
|
311
316
|
// The per-role token vocabulary, declared like a `themeComponents` scope's
|
|
312
317
|
// `tokens`: each field's value type and bounds stated ONCE, so the Studio
|
|
313
318
|
// control, the set_theme coercion and the host validator cannot disagree.
|
|
@@ -315,7 +320,7 @@ const THEME_TEXT_ROLE_FONT_STYLES = Object.freeze(["normal", "italic"]);
|
|
|
315
320
|
// value is right at every size; `color` overrides the role's surface-aware
|
|
316
321
|
// `colorToken`, which is why no role seeds a literal colour.
|
|
317
322
|
const THEME_TEXT_ROLE_FIELDS = Object.freeze({
|
|
318
|
-
fontSize: Object.freeze({ type: "size", min:
|
|
323
|
+
fontSize: Object.freeze({ type: "size", min: MIN_FONT_PX, max: 96 }),
|
|
319
324
|
fontWeight: Object.freeze({ type: "enum", values: THEME_TEXT_ROLE_FONT_WEIGHTS }),
|
|
320
325
|
fontStyle: Object.freeze({ type: "enum", values: THEME_TEXT_ROLE_FONT_STYLES }),
|
|
321
326
|
lineHeight: Object.freeze({ type: "decimal", min: 0.8, max: 3, step: 0.05 }),
|
|
@@ -556,7 +561,7 @@ const THEME_COMPONENTS = Object.freeze({
|
|
|
556
561
|
textColor: Object.freeze({ type: "color", uiDefault: "colors.onPrimary" }),
|
|
557
562
|
borderColor: Object.freeze({ type: "color", uiDefault: "colors.border" }),
|
|
558
563
|
radius: Object.freeze({ type: "size", min: 0, max: 48, uiDefault: "radii.sm" }),
|
|
559
|
-
fontSize: Object.freeze({ type: "size", min:
|
|
564
|
+
fontSize: Object.freeze({ type: "size", min: MIN_FONT_PX, max: 96, uiDefault: "typography.sizes.sm" }),
|
|
560
565
|
shadow: Object.freeze({ type: "shadow" }),
|
|
561
566
|
gradient: Object.freeze({ type: "gradient" }),
|
|
562
567
|
}),
|
|
@@ -610,7 +615,7 @@ const THEME_COMPONENTS = Object.freeze({
|
|
|
610
615
|
label: "Text",
|
|
611
616
|
tokens: Object.freeze({
|
|
612
617
|
color: Object.freeze({ type: "color", uiDefault: "colors.onSurface" }),
|
|
613
|
-
fontSize: Object.freeze({ type: "size", min:
|
|
618
|
+
fontSize: Object.freeze({ type: "size", min: MIN_FONT_PX, max: 96, uiDefault: "typography.sizes.md" }),
|
|
614
619
|
// sc-3857 — leading as a MULTIPLE of the font size, so one app-wide value
|
|
615
620
|
// is right at every size; `size` cannot carry it because it rounds.
|
|
616
621
|
lineHeight: Object.freeze({ type: "decimal", min: 0.8, max: 3, step: 0.05 }),
|
|
@@ -6952,7 +6957,10 @@ const CONTRACT = deepFreeze({
|
|
|
6952
6957
|
// so `useSafeAreaInsets()` returns zeros on web as documented instead of throwing.
|
|
6953
6958
|
// 1.254.0: `formatMoney` shows a whole amount without decimals ("795 kr");
|
|
6954
6959
|
// `formatMoney(minor, { decimals: "always" })` keeps them ("795,00 kr").
|
|
6955
|
-
|
|
6960
|
+
// 1.255.0: fix (sc-16654) — `minFontPx` (12) publishes the smallest page text
|
|
6961
|
+
// the render check accepts. The theme's six text tiers and its Buttons and
|
|
6962
|
+
// Text component sizes now clamp up to it instead of to 8.
|
|
6963
|
+
version: "1.255.0",
|
|
6956
6964
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
6957
6965
|
hooks: HOOKS,
|
|
6958
6966
|
primitives: PRIMITIVES,
|
|
@@ -6974,6 +6982,7 @@ const CONTRACT = deepFreeze({
|
|
|
6974
6982
|
themeComponentGradient: THEME_COMPONENT_GRADIENT,
|
|
6975
6983
|
themeTextRoles: THEME_TEXT_ROLES,
|
|
6976
6984
|
themeTextRoleFields: THEME_TEXT_ROLE_FIELDS,
|
|
6985
|
+
minFontPx: MIN_FONT_PX,
|
|
6977
6986
|
themeSpacingScale: THEME_SPACING_SCALE,
|
|
6978
6987
|
themeMenuTypes: THEME_MENU_TYPES,
|
|
6979
6988
|
themeWidgetStyles: THEME_WIDGET_STYLES,
|
package/dist/host.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Host-integration surface — not the author-facing widget API. See host.js.
|
|
2
|
-
import type { WidgetPropertySchema } from "./index";
|
|
2
|
+
import type { TextRole, WidgetPropertySchema } from "./index";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Host render-boundary helper: fills a widget's propertySchema `default`s onto
|
|
@@ -134,6 +134,18 @@ export function applyThemeComponentStyle<T = Record<string, unknown>>(
|
|
|
134
134
|
styleSchema?: Record<string, unknown> | null,
|
|
135
135
|
): T;
|
|
136
136
|
|
|
137
|
+
/** One text role's validated fields (REQ-THEME-ROLE). */
|
|
138
|
+
export type TypographyRole = Record<string, string | number>;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* A raw `typographyRoles` blob cut down to the contract's roles and fields;
|
|
142
|
+
* unknown or out-of-bounds values are dropped and an emptied role is omitted.
|
|
143
|
+
*/
|
|
144
|
+
export function normaliseTypographyRoles(raw: unknown): Partial<Record<TextRole, TypographyRole>>;
|
|
145
|
+
|
|
146
|
+
/** Every declared role, each merged per field over the contract's default. */
|
|
147
|
+
export function resolveTypographyRoles(raw: unknown): Record<TextRole, TypographyRole>;
|
|
148
|
+
|
|
137
149
|
// sc-4939 — the host half of `useToast()`. A widget only ever calls the hook;
|
|
138
150
|
// these are what a platform host puts behind `WidgetContext.toast`.
|
|
139
151
|
|
package/dist/host.js
CHANGED
|
@@ -23,6 +23,9 @@ export {
|
|
|
23
23
|
applyThemeComponentStyle,
|
|
24
24
|
} from "./theme-components.js";
|
|
25
25
|
|
|
26
|
+
// REQ-THEME-ROLE: the one typography-role validator, for both hosts and the backend.
|
|
27
|
+
export { normaliseTypographyRoles, resolveTypographyRoles } from "./theme-text-roles.js";
|
|
28
|
+
|
|
26
29
|
// sc-7800: the theme-token colour bindings. `resolveThemeTokenRefs` replaces a
|
|
27
30
|
// bound `type: "color"` field with the colour its token currently resolves to,
|
|
28
31
|
// at the SAME render boundary on both hosts — so a rebrand repaints the Player,
|
package/dist/index.d.ts
CHANGED
|
@@ -6454,6 +6454,8 @@ export interface AiWidgetContract {
|
|
|
6454
6454
|
readonly badgeCounterExport: "useBadgeCount";
|
|
6455
6455
|
/** The most native Text / TextInput grow with the device font-scale setting. */
|
|
6456
6456
|
readonly maxFontSizeMultiplier: number;
|
|
6457
|
+
/** The smallest page text in px the render check accepts; the theme's type scale clamps up to it. */
|
|
6458
|
+
readonly minFontPx: number;
|
|
6457
6459
|
readonly bannedApis: ReadonlyArray<ContractBannedApi>;
|
|
6458
6460
|
readonly allowedBareImports: ReadonlyArray<string>;
|
|
6459
6461
|
/** Bare specifiers the web host provides by exact name; a widget bundle never inlines them. */
|
package/dist/linter.cjs
CHANGED
|
@@ -2863,9 +2863,10 @@ function _hardcodedDesignRules(source) {
|
|
|
2863
2863
|
`useTheme() (theme.colors.* / theme.typography.* / theme.radii.*), ` +
|
|
2864
2864
|
`use the SDK's <Card> / <Button> / <ListRow>, or declare a ` +
|
|
2865
2865
|
`styleSchema field and apply props.style.<field>. License a value ` +
|
|
2866
|
-
`that truly cannot be a token — a
|
|
2867
|
-
`
|
|
2868
|
-
`"// appstudio-design-ok: <reason>"
|
|
2866
|
+
`that truly cannot be a token — a video letterbox, a QR plate — ` +
|
|
2867
|
+
`with a preceding ` +
|
|
2868
|
+
`"// appstudio-design-ok: <reason>". A colour per category comes ` +
|
|
2869
|
+
`from chartColors(theme).series(i).`,
|
|
2869
2870
|
line: i + 1,
|
|
2870
2871
|
snippet: (sourceLines[i] || "").trim().slice(0, 200),
|
|
2871
2872
|
});
|
package/dist/linter.js
CHANGED
|
@@ -2858,9 +2858,10 @@ function _hardcodedDesignRules(source) {
|
|
|
2858
2858
|
`useTheme() (theme.colors.* / theme.typography.* / theme.radii.*), ` +
|
|
2859
2859
|
`use the SDK's <Card> / <Button> / <ListRow>, or declare a ` +
|
|
2860
2860
|
`styleSchema field and apply props.style.<field>. License a value ` +
|
|
2861
|
-
`that truly cannot be a token — a
|
|
2862
|
-
`
|
|
2863
|
-
`"// appstudio-design-ok: <reason>"
|
|
2861
|
+
`that truly cannot be a token — a video letterbox, a QR plate — ` +
|
|
2862
|
+
`with a preceding ` +
|
|
2863
|
+
`"// appstudio-design-ok: <reason>". A colour per category comes ` +
|
|
2864
|
+
`from chartColors(theme).series(i).`,
|
|
2864
2865
|
line: i + 1,
|
|
2865
2866
|
snippet: (sourceLines[i] || "").trim().slice(0, 200),
|
|
2866
2867
|
});
|
|
@@ -27,12 +27,15 @@ const { isPlainObject } = require("./plain-object.cjs");
|
|
|
27
27
|
// must never drop a colour the runner already accepted.
|
|
28
28
|
const HEX_COLOR = /^#(?:[0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
|
|
29
29
|
|
|
30
|
+
// Trimmed first, so a padded hex in a hand-edited theme survives.
|
|
31
|
+
function coerceThemeColor(value) {
|
|
32
|
+
if (typeof value !== "string") return undefined;
|
|
33
|
+
const trimmed = value.trim();
|
|
34
|
+
return HEX_COLOR.test(trimmed) ? trimmed : undefined;
|
|
35
|
+
}
|
|
36
|
+
|
|
30
37
|
function coerceToken(def, value) {
|
|
31
|
-
if (def.type === "color")
|
|
32
|
-
if (typeof value !== "string") return undefined;
|
|
33
|
-
const trimmed = value.trim();
|
|
34
|
-
return HEX_COLOR.test(trimmed) ? trimmed : undefined;
|
|
35
|
-
}
|
|
38
|
+
if (def.type === "color") return coerceThemeColor(value);
|
|
36
39
|
if (def.type === "size") {
|
|
37
40
|
const n = typeof value === "number" ? value : Number(value);
|
|
38
41
|
if (!Number.isFinite(n)) return undefined;
|
|
@@ -397,6 +400,7 @@ function applyThemeComponentStyle(manifestId, theme, props, styleSchema) {
|
|
|
397
400
|
return { ...base, style: { ...themed, ...authored } };
|
|
398
401
|
}
|
|
399
402
|
module.exports = {
|
|
403
|
+
coerceThemeColor,
|
|
400
404
|
normaliseThemeComponents,
|
|
401
405
|
MAX_STYLE_STRING_LENGTH,
|
|
402
406
|
styleValueBytes,
|
package/dist/theme-components.js
CHANGED
|
@@ -22,12 +22,15 @@ import { isPlainObject } from "./plain-object.js";
|
|
|
22
22
|
// must never drop a colour the runner already accepted.
|
|
23
23
|
const HEX_COLOR = /^#(?:[0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
|
|
24
24
|
|
|
25
|
+
// Trimmed first, so a padded hex in a hand-edited theme survives.
|
|
26
|
+
export function coerceThemeColor(value) {
|
|
27
|
+
if (typeof value !== "string") return undefined;
|
|
28
|
+
const trimmed = value.trim();
|
|
29
|
+
return HEX_COLOR.test(trimmed) ? trimmed : undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
25
32
|
function coerceToken(def, value) {
|
|
26
|
-
if (def.type === "color")
|
|
27
|
-
if (typeof value !== "string") return undefined;
|
|
28
|
-
const trimmed = value.trim();
|
|
29
|
-
return HEX_COLOR.test(trimmed) ? trimmed : undefined;
|
|
30
|
-
}
|
|
33
|
+
if (def.type === "color") return coerceThemeColor(value);
|
|
31
34
|
if (def.type === "size") {
|
|
32
35
|
const n = typeof value === "number" ? value : Number(value);
|
|
33
36
|
if (!Number.isFinite(n)) return undefined;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// GENERATED from theme-text-roles.js by scripts/generate-cjs.js — DO NOT EDIT.
|
|
2
|
+
// Change theme-text-roles.js, then run `npm run generate:cjs` in packages/widget-sdk.
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const { CONTRACT } = require("./contract.cjs");
|
|
6
|
+
const { coerceThemeColor } = require("./theme-components.cjs");
|
|
7
|
+
|
|
8
|
+
// REQ-THEME-ROLE: the one typography-role validator for both hosts and the backend.
|
|
9
|
+
|
|
10
|
+
// One stored role value, checked against its declared type and bounds.
|
|
11
|
+
function coerceRoleField(def, value) {
|
|
12
|
+
if (def.type === "color") return coerceThemeColor(value);
|
|
13
|
+
if (def.type === "enum") {
|
|
14
|
+
// A weight may arrive as a number; both hosts' `fontWeight` takes the string.
|
|
15
|
+
if (typeof value !== "string" && typeof value !== "number") return undefined;
|
|
16
|
+
const candidate = String(value);
|
|
17
|
+
return def.values.includes(candidate) ? candidate : undefined;
|
|
18
|
+
}
|
|
19
|
+
if (def.type === "textTransform") {
|
|
20
|
+
return CONTRACT.themeComponentTextTransforms.includes(value) ? value : undefined;
|
|
21
|
+
}
|
|
22
|
+
// `Number(true)` is 1 and `Number(["12"])` is 12: a trust boundary drops a
|
|
23
|
+
// wrong-typed value rather than inventing an in-range one from it.
|
|
24
|
+
if (typeof value !== "number" && typeof value !== "string") return undefined;
|
|
25
|
+
const n = typeof value === "number" ? value : Number(value);
|
|
26
|
+
if (!Number.isFinite(n)) return undefined;
|
|
27
|
+
const clamped = Math.min(def.max, Math.max(def.min, n));
|
|
28
|
+
if (def.type === "size") return Math.round(clamped);
|
|
29
|
+
// Leading and tracking must keep the decimals `size` rounds away.
|
|
30
|
+
if (def.type === "decimal") return Math.round(clamped * 100) / 100;
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** A raw blob cut down to the contract; an emptied role is omitted. */
|
|
35
|
+
function normaliseTypographyRoles(raw) {
|
|
36
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return {};
|
|
37
|
+
const out = {};
|
|
38
|
+
for (const role of CONTRACT.themeTextRoles) {
|
|
39
|
+
const requested = raw[role];
|
|
40
|
+
if (!requested || typeof requested !== "object" || Array.isArray(requested)) continue;
|
|
41
|
+
const fields = {};
|
|
42
|
+
for (const [field, def] of Object.entries(CONTRACT.themeTextRoleFields)) {
|
|
43
|
+
if (requested[field] === undefined) continue;
|
|
44
|
+
const coerced = coerceRoleField(def, requested[field]);
|
|
45
|
+
if (coerced !== undefined) fields[field] = coerced;
|
|
46
|
+
}
|
|
47
|
+
if (Object.keys(fields).length) out[role] = fields;
|
|
48
|
+
}
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Every declared role, merged per field over its default; re-validates. */
|
|
53
|
+
function resolveTypographyRoles(raw) {
|
|
54
|
+
const overrides = normaliseTypographyRoles(raw);
|
|
55
|
+
const merged = {};
|
|
56
|
+
for (const [role, defaults] of Object.entries(CONTRACT.themeTokens.typography.roles)) {
|
|
57
|
+
merged[role] = overrides[role] ? { ...defaults, ...overrides[role] } : { ...defaults };
|
|
58
|
+
}
|
|
59
|
+
return merged;
|
|
60
|
+
}
|
|
61
|
+
module.exports = {
|
|
62
|
+
normaliseTypographyRoles,
|
|
63
|
+
resolveTypographyRoles,
|
|
64
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// REQ-THEME-ROLE: the one typography-role validator for both hosts and the backend.
|
|
2
|
+
import { CONTRACT } from "./contract.js";
|
|
3
|
+
import { coerceThemeColor } from "./theme-components.js";
|
|
4
|
+
|
|
5
|
+
// One stored role value, checked against its declared type and bounds.
|
|
6
|
+
function coerceRoleField(def, value) {
|
|
7
|
+
if (def.type === "color") return coerceThemeColor(value);
|
|
8
|
+
if (def.type === "enum") {
|
|
9
|
+
// A weight may arrive as a number; both hosts' `fontWeight` takes the string.
|
|
10
|
+
if (typeof value !== "string" && typeof value !== "number") return undefined;
|
|
11
|
+
const candidate = String(value);
|
|
12
|
+
return def.values.includes(candidate) ? candidate : undefined;
|
|
13
|
+
}
|
|
14
|
+
if (def.type === "textTransform") {
|
|
15
|
+
return CONTRACT.themeComponentTextTransforms.includes(value) ? value : undefined;
|
|
16
|
+
}
|
|
17
|
+
// `Number(true)` is 1 and `Number(["12"])` is 12: a trust boundary drops a
|
|
18
|
+
// wrong-typed value rather than inventing an in-range one from it.
|
|
19
|
+
if (typeof value !== "number" && typeof value !== "string") return undefined;
|
|
20
|
+
const n = typeof value === "number" ? value : Number(value);
|
|
21
|
+
if (!Number.isFinite(n)) return undefined;
|
|
22
|
+
const clamped = Math.min(def.max, Math.max(def.min, n));
|
|
23
|
+
if (def.type === "size") return Math.round(clamped);
|
|
24
|
+
// Leading and tracking must keep the decimals `size` rounds away.
|
|
25
|
+
if (def.type === "decimal") return Math.round(clamped * 100) / 100;
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** A raw blob cut down to the contract; an emptied role is omitted. */
|
|
30
|
+
export function normaliseTypographyRoles(raw) {
|
|
31
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return {};
|
|
32
|
+
const out = {};
|
|
33
|
+
for (const role of CONTRACT.themeTextRoles) {
|
|
34
|
+
const requested = raw[role];
|
|
35
|
+
if (!requested || typeof requested !== "object" || Array.isArray(requested)) continue;
|
|
36
|
+
const fields = {};
|
|
37
|
+
for (const [field, def] of Object.entries(CONTRACT.themeTextRoleFields)) {
|
|
38
|
+
if (requested[field] === undefined) continue;
|
|
39
|
+
const coerced = coerceRoleField(def, requested[field]);
|
|
40
|
+
if (coerced !== undefined) fields[field] = coerced;
|
|
41
|
+
}
|
|
42
|
+
if (Object.keys(fields).length) out[role] = fields;
|
|
43
|
+
}
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Every declared role, merged per field over its default; re-validates. */
|
|
48
|
+
export function resolveTypographyRoles(raw) {
|
|
49
|
+
const overrides = normaliseTypographyRoles(raw);
|
|
50
|
+
const merged = {};
|
|
51
|
+
for (const [role, defaults] of Object.entries(CONTRACT.themeTokens.typography.roles)) {
|
|
52
|
+
merged[role] = overrides[role] ? { ...defaults, ...overrides[role] } : { ...defaults };
|
|
53
|
+
}
|
|
54
|
+
return merged;
|
|
55
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@colixsystems/widget-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.315.0",
|
|
4
4
|
"description": "Common widget interface for AppStudio. Implements WidgetManifest, WidgetContext, property schema, and helper hooks.",
|
|
5
5
|
"homepage": "https://github.com/Colix-AB/AppStudio",
|
|
6
6
|
"type": "module",
|
package/src/contract.js
CHANGED
|
@@ -308,6 +308,11 @@ const THEME_TEXT_ROLE_FONT_WEIGHTS = Object.freeze([
|
|
|
308
308
|
|
|
309
309
|
const THEME_TEXT_ROLE_FONT_STYLES = Object.freeze(["normal", "italic"]);
|
|
310
310
|
|
|
311
|
+
// sc-16654 — the smallest page text the render check accepts (TEXT_TOO_SMALL
|
|
312
|
+
// reads this value). The type scale and component font sizes clamp up to it on
|
|
313
|
+
// both hosts and at save; a per-widget size is the author's own choice.
|
|
314
|
+
const MIN_FONT_PX = 12;
|
|
315
|
+
|
|
311
316
|
// The per-role token vocabulary, declared like a `themeComponents` scope's
|
|
312
317
|
// `tokens`: each field's value type and bounds stated ONCE, so the Studio
|
|
313
318
|
// control, the set_theme coercion and the host validator cannot disagree.
|
|
@@ -315,7 +320,7 @@ const THEME_TEXT_ROLE_FONT_STYLES = Object.freeze(["normal", "italic"]);
|
|
|
315
320
|
// value is right at every size; `color` overrides the role's surface-aware
|
|
316
321
|
// `colorToken`, which is why no role seeds a literal colour.
|
|
317
322
|
const THEME_TEXT_ROLE_FIELDS = Object.freeze({
|
|
318
|
-
fontSize: Object.freeze({ type: "size", min:
|
|
323
|
+
fontSize: Object.freeze({ type: "size", min: MIN_FONT_PX, max: 96 }),
|
|
319
324
|
fontWeight: Object.freeze({ type: "enum", values: THEME_TEXT_ROLE_FONT_WEIGHTS }),
|
|
320
325
|
fontStyle: Object.freeze({ type: "enum", values: THEME_TEXT_ROLE_FONT_STYLES }),
|
|
321
326
|
lineHeight: Object.freeze({ type: "decimal", min: 0.8, max: 3, step: 0.05 }),
|
|
@@ -556,7 +561,7 @@ const THEME_COMPONENTS = Object.freeze({
|
|
|
556
561
|
textColor: Object.freeze({ type: "color", uiDefault: "colors.onPrimary" }),
|
|
557
562
|
borderColor: Object.freeze({ type: "color", uiDefault: "colors.border" }),
|
|
558
563
|
radius: Object.freeze({ type: "size", min: 0, max: 48, uiDefault: "radii.sm" }),
|
|
559
|
-
fontSize: Object.freeze({ type: "size", min:
|
|
564
|
+
fontSize: Object.freeze({ type: "size", min: MIN_FONT_PX, max: 96, uiDefault: "typography.sizes.sm" }),
|
|
560
565
|
shadow: Object.freeze({ type: "shadow" }),
|
|
561
566
|
gradient: Object.freeze({ type: "gradient" }),
|
|
562
567
|
}),
|
|
@@ -610,7 +615,7 @@ const THEME_COMPONENTS = Object.freeze({
|
|
|
610
615
|
label: "Text",
|
|
611
616
|
tokens: Object.freeze({
|
|
612
617
|
color: Object.freeze({ type: "color", uiDefault: "colors.onSurface" }),
|
|
613
|
-
fontSize: Object.freeze({ type: "size", min:
|
|
618
|
+
fontSize: Object.freeze({ type: "size", min: MIN_FONT_PX, max: 96, uiDefault: "typography.sizes.md" }),
|
|
614
619
|
// sc-3857 — leading as a MULTIPLE of the font size, so one app-wide value
|
|
615
620
|
// is right at every size; `size` cannot carry it because it rounds.
|
|
616
621
|
lineHeight: Object.freeze({ type: "decimal", min: 0.8, max: 3, step: 0.05 }),
|
|
@@ -6952,7 +6957,10 @@ const CONTRACT = deepFreeze({
|
|
|
6952
6957
|
// so `useSafeAreaInsets()` returns zeros on web as documented instead of throwing.
|
|
6953
6958
|
// 1.254.0: `formatMoney` shows a whole amount without decimals ("795 kr");
|
|
6954
6959
|
// `formatMoney(minor, { decimals: "always" })` keeps them ("795,00 kr").
|
|
6955
|
-
|
|
6960
|
+
// 1.255.0: fix (sc-16654) — `minFontPx` (12) publishes the smallest page text
|
|
6961
|
+
// the render check accepts. The theme's six text tiers and its Buttons and
|
|
6962
|
+
// Text component sizes now clamp up to it instead of to 8.
|
|
6963
|
+
version: "1.255.0",
|
|
6956
6964
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
6957
6965
|
hooks: HOOKS,
|
|
6958
6966
|
primitives: PRIMITIVES,
|
|
@@ -6974,6 +6982,7 @@ const CONTRACT = deepFreeze({
|
|
|
6974
6982
|
themeComponentGradient: THEME_COMPONENT_GRADIENT,
|
|
6975
6983
|
themeTextRoles: THEME_TEXT_ROLES,
|
|
6976
6984
|
themeTextRoleFields: THEME_TEXT_ROLE_FIELDS,
|
|
6985
|
+
minFontPx: MIN_FONT_PX,
|
|
6977
6986
|
themeSpacingScale: THEME_SPACING_SCALE,
|
|
6978
6987
|
themeMenuTypes: THEME_MENU_TYPES,
|
|
6979
6988
|
themeWidgetStyles: THEME_WIDGET_STYLES,
|