@colixsystems/widget-sdk 0.309.0 → 0.314.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 CHANGED
@@ -19,7 +19,7 @@ The data layer lives in **four separate domain-client packages**, each instantia
19
19
  | Group | Hook (signature) | Returns | Reads / scope |
20
20
  | ----- | ---------------- | ------- | ------------- |
21
21
  | **CORE** | `useTheme()` | `{ colors, elevation, interaction, spacing, spacingScale, radii, typography, components, widgetStyles }` | `ctx.workspace.theme` — no scope. `elevation` is the shared depth scale (`none / sm / md / lg / xl`) you spread into a style; `colors` includes the accent's quiet tiers (`primarySoft` / `onPrimarySoft` / `primaryStrong`) and `loader`, the spinner colour for your own loading state. `components` is HOST-OWNED (the theme's per-component style tokens); the host has already folded it into your `props.style`, so read `useWidgetStyle()` and ignore this slice. |
22
- | **CORE** | `useWorkspaceCurrency()` | `{ currency, formatMoney }` | `ctx.workspace.currency` — no scope. The currency this workspace charges its app users in, resolved at RENDER time. Render every price as `formatMoney(minorUnits)` and never write a currency symbol or code into a widget: the owner can change it after the widget ships, and a baked label then contradicts the charge. |
22
+ | **CORE** | `useWorkspaceCurrency()` | `{ currency, formatMoney }` | `ctx.workspace.currency` — no scope. The currency this workspace charges its app users in, resolved at RENDER time. Render every price as `formatMoney(minorUnits)` (a whole amount shows no decimals; `{ decimals: "always" }` keeps them) and never write a currency symbol or code into a widget: the owner can change it after the widget ships, and a baked label then contradicts the charge. |
23
23
  | **CORE** | `useWidgetStyle()` | `{ [styleField]: value }` | `ctx.props.style` — no scope. The author-set per-widget style values declared in `manifest.styleSchema`; apply each onto whatever element you choose. |
24
24
  | **CORE** | `useUser()` | `{ id, email, displayName, photoUrl, roles, groupIds }` | `ctx.user` (host-built context, **camelCase** — not a wire payload; `id` null when anonymous) — no scope. `photoUrl` is the user's own profile photo as an absolute URL, or `null`. |
25
25
  | **CORE** | `useUserPhoto()` | `{ url, canEdit, upload, remove, uploading, error }` | `ctx.user` + the optional `ctx.account` — no scope. Changes the signed-in user's OWN profile photo. `canEdit` is false when nobody is signed in or the host cannot change it; `upload` / `remove` then reject. |
@@ -90,7 +90,29 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
90
90
 
91
91
  ## Status
92
92
 
93
- `v0.309.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**.
93
+ `v0.314.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.314.0 (contract 1.254.0)
96
+
97
+ **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.
98
+
99
+ ### What's new in 0.313.0 (contract 1.254.0)
100
+
101
+ **`esbuild` and `sucrase` are no longer installed with the SDK.** They are optional peer dependencies now: build tooling peers, installed by first-party tooling, so installing the SDK brings no third-party code into your project or an app built from it. Linting, building and uploading a widget need neither. A project that depends on `esbuild` directly at a version outside `^0.28.0` gets `ERESOLVE` on install; move it to `^0.28.0`, or install with `--legacy-peer-deps`. The widget contract is unchanged.
102
+
103
+ ### What's new in 0.312.0 (contract 1.254.0)
104
+
105
+ **`formatMoney` writes a whole price without decimals.** `useWorkspaceCurrency().formatMoney(79500)` now renders `"795 kr"` instead of `"795,00 kr"`, the way shops, salons and menus write prices; an amount with a fractional part keeps the currency's decimals (`formatMoney(9950)` → `"99,50 kr"`). For a receipt or invoice total that should always read to the cent, pass `formatMoney(minorUnits, { decimals: "always" })` → `"795,00 kr"`. Zero-decimal currencies such as JPY are unchanged. Hosts get the same formatter as `formatMoneyIn(currency, minorUnits, options?)` from `@colixsystems/widget-sdk/host`; the paid-app sign-up price on both hosts now uses it, so it reads `"99 kr / month"` in the web Player and the exported app alike.
106
+
107
+ ### What's new in 0.311.0 (contract 1.253.0)
108
+
109
+ **New linter rule `empty-state-action-outside` (severity `warning`, non-blocking).** A `<Button>` or `<Pressable>` rendered straight after an `<EmptyState>`, or as the first child of the `View` that follows one, sits outside the empty-state panel. Pass it as the EmptyState's children instead: `<EmptyState title={…}><Button … /></EmptyState>` draws it inside the panel, under the message. An EmptyState and a button that are alternatives (`empty ? <EmptyState /> : <Button />`) or sit in separate expressions are not flagged.
110
+
111
+ **New linter rule `field-label-styles-mixed` (severity `warning`, non-blocking).** A widget that gives one form field the SDK `label` (`<TextField>`, `<Select>`, `<RadioGroup>`, `<PeoplePicker>`, `<FileUpload>`, `<FormField>`) and labels another with its own `<Text>` shows labels in two styles. A `<Text>` counts as a field's label only when it is the element just before a control with no `label` (one of those fields, a `<ChipGroup>`, a `<DateTimePicker>` or a `<TextInput>`), so a heading above a form does not count. Label every field one way: the `label` prop, or `<FormField label>` round a control that has none.
112
+
113
+ ### What's new in 0.310.0 (contract 1.253.0)
114
+
115
+ **A look can carry its own light surface colours.** A theme may state `surfaceMutedColor`, `surfaceBorderColor` and `mutedTextColor`. On a light page they become `useTheme().colors.surfaceMuted`, `border` and `onSurfaceMuted`, in the web Player and the exported app alike, so a warm page gets warm panels and muted text instead of the default slate. They are worked out only for a tinted page; a white, grey or slate-blue page keeps the slate defaults, which already match it. A dark page ignores them and keeps the colours derived from it. A theme without them renders exactly as before. Hosts read them through the new `themeSurfaceTokens(themeConfig)` in `@colixsystems/widget-sdk/host`; `deriveLightSurfaceColors(backgroundColor, inkColor)` works the three out from a light page, holding the muted text at 4.5:1 on the surface, the muted panel and the page. Nothing changes for a widget: it keeps reading `useTheme().colors`.
94
116
 
95
117
  ### What's new in 0.309.0 (contract 1.253.0)
96
118
 
@@ -3999,6 +4021,10 @@ Pass `--manifest` to enable `style-field-unread` and the three editability rules
3999
4021
 
4000
4022
  `text-symbol-icon` flags a JSX text child that is nothing but symbols or emoji (`<Text>✓</Text>`, `<Text>{open ? "▲" : "▼"}</Text>`, or `✓ {label}`), naming the lucide `<Icon>` to draw instead where one is obvious (✓ check, ★ star, → arrow-right, ☰ menu, ⌕ search). A symbol inside running text ("Steg 1 → 2", "© 2026"), bullets and dashes (• · – —), ×, currency signs and flag emoji pass. A warning for a human author, blocking for the AI widget agent and `/mcp/build`.
4001
4023
 
4024
+ `empty-state-action-outside` flags a `<Button>` or `<Pressable>` placed beside an `<EmptyState>` (next to it, or first in the `View` after it), outside the panel. Pass it as the EmptyState's children. A warning.
4025
+
4026
+ `field-label-styles-mixed` flags a widget that labels some fields with the SDK `label` and others with a `<Text>` just before the control, so the labels render in two styles. Label every field one way. A warning.
4027
+
4002
4028
  `comment-as-jsx-text` refuses a `//` or `/* */` comment written between JSX tags, where it is text the web Player shows and the native app refuses. Write it as `{/* … */}`. An error.
4003
4029
 
4004
4030
  `row-action-not-gated` flags a widget that calls `update` or `delete` from `useDatastoreMutation` without a per-row permission check: no `_capabilities` read and no `useCanWrite(tableId, { recordId })`. The table-level `useCanWrite(tableId)` only answers "may create", so a list gated on it shows Edit / Delete on rows the server will refuse. A warning.
@@ -4035,8 +4061,9 @@ published bundle hits) and hot-reloads onto the canvas on every save.
4035
4061
  `widget.native.jsx` with shared `./relative.jsx` helpers) need a real build
4036
4062
  step; the dev server reports relative imports rather than serving a module
4037
4063
  the browser can't resolve.
4038
- - `dev` lazily requires the optional `sucrase` dependency. In this monorepo it
4039
- is already present; in a standalone widget project run `npm i -D sucrase`.
4064
+ - `dev` lazily requires the optional peers `sucrase` and `esbuild`. In this
4065
+ monorepo they are already present; in a standalone widget project run
4066
+ `npm i -D sucrase esbuild`.
4040
4067
  - Lint findings print to the terminal on each change but never block serving.
4041
4068
 
4042
4069
  ## Why no TypeScript dependency?
package/dist/contract.cjs CHANGED
@@ -2514,7 +2514,7 @@ const HOOKS = [
2514
2514
  currency:
2515
2515
  "string // the ISO code this workspace charges its app users in, e.g. \"SEK\"",
2516
2516
  formatMoney:
2517
- "(minorUnits) => string // 45000 -> \"450,00 kr\"; renders identically on web and native. NEVER write a currency symbol or code yourself",
2517
+ "(minorUnits, { decimals: \"always\" }?) => string // 79500 -> \"795 kr\", 9950 -> \"99,50 kr\": a whole amount shows no decimals; pass { decimals: \"always\" } for a receipt or invoice total (\"795,00 kr\"). Renders identically on web and native. NEVER write a currency symbol or code yourself",
2518
2518
  },
2519
2519
  requiredContextSlice: ["workspace.currency"],
2520
2520
  scopes: null,
@@ -4978,8 +4978,8 @@ const VETTED_IMPORTS = [
4978
4978
  description:
4979
4979
  "RevenueCat in-app purchase (StoreKit / Play Billing). PREFER usePurchases() from the SDK, which already runs on the " +
4980
4980
  "app's configured, signed-in customer. Import this directly only for what the hook does not cover, and NEVER call " +
4981
- "Purchases.configure, logIn or logOut — the app owns them, and it configures Purchases only when the workspace " +
4982
- "connected RevenueCat. Native-only because no browser offers store billing: author it in widget.native.jsx and give " +
4981
+ "Purchases.configure, logIn or logOut — the app owns them. The package is in the app only when the workspace " +
4982
+ "connected RevenueCat: a store build of a workspace that has not is refused while a widget imports it. Native-only because no browser offers store billing: author it in widget.native.jsx and give " +
4983
4983
  "widget.web.jsx a visible 'available in the app' state.",
4984
4984
  },
4985
4985
  {
@@ -5341,18 +5341,6 @@ function normaliseCurrencyCode(value) {
5341
5341
  return code || CHARGE_CURRENCY;
5342
5342
  }
5343
5343
 
5344
- /**
5345
- * `formatMoneyIn("SEK", 45000)` → `"450,00 kr"`.
5346
- *
5347
- * Takes MINOR units — the same unit `requestPayment` charges in — so there is no
5348
- * conversion step for a widget to get wrong. Renders from `CURRENCY_FORMATS`
5349
- * rather than `Intl.NumberFormat`, which does not produce identical output in
5350
- * the exported Expo app and react-native-web; this string sits beside the amount
5351
- * the buyer is actually charged, so the two hosts must agree exactly.
5352
- *
5353
- * A non-finite amount renders as zero rather than "NaN": a price whose data has
5354
- * not loaded should read as an amount, never as a broken string in a checkout.
5355
- */
5356
5344
  /**
5357
5345
  * sc-5717 — value equality for a stored widget-route value: is this key still
5358
5346
  * at the default its widget declared?
@@ -5368,7 +5356,22 @@ function sameWidgetRouteValue(a, b) {
5368
5356
  }
5369
5357
  return Object.is(a, b);
5370
5358
  }
5371
- function formatMoneyIn(currency, minorUnits) {
5359
+ /**
5360
+ * `formatMoneyIn("SEK", 79500)` → `"795 kr"`; `formatMoneyIn("SEK", 9950)` → `"99,50 kr"`.
5361
+ *
5362
+ * Takes MINOR units — the same unit `requestPayment` charges in — so there is no
5363
+ * conversion step for a widget to get wrong. Renders from `CURRENCY_FORMATS`
5364
+ * rather than `Intl.NumberFormat`, which does not produce identical output in
5365
+ * the exported Expo app and react-native-web; this string sits beside the amount
5366
+ * the buyer is actually charged, so the two hosts must agree exactly.
5367
+ *
5368
+ * A whole amount drops its decimals, as shops and menus write prices.
5369
+ * `{ decimals: "always" }` keeps them, for a receipt or invoice total.
5370
+ *
5371
+ * A non-finite amount renders as zero rather than "NaN": a price whose data has
5372
+ * not loaded should read as an amount, never as a broken string in a checkout.
5373
+ */
5374
+ function formatMoneyIn(currency, minorUnits, options) {
5372
5375
  const code = normaliseCurrencyCode(currency);
5373
5376
  const fmt = CURRENCY_FORMATS[code] || {
5374
5377
  ...CURRENCY_FORMAT_FALLBACK,
@@ -5381,7 +5384,9 @@ function formatMoneyIn(currency, minorUnits) {
5381
5384
  const whole = fmt.decimals > 0 ? digits.slice(0, -fmt.decimals) : digits;
5382
5385
  const cents = fmt.decimals > 0 ? digits.slice(-fmt.decimals) : "";
5383
5386
  const grouped = whole.replace(/\B(?=(\d{3})+(?!\d))/g, fmt.groupSeparator);
5384
- const body = cents ? `${grouped}${fmt.decimalSeparator}${cents}` : grouped;
5387
+ const alwaysDecimals = Boolean(options && options.decimals === "always");
5388
+ const showCents = cents !== "" && (alwaysDecimals || /[1-9]/.test(cents));
5389
+ const body = showCents ? `${grouped}${fmt.decimalSeparator}${cents}` : grouped;
5385
5390
  const gap = fmt.space ? " " : "";
5386
5391
  const withSymbol =
5387
5392
  fmt.position === "before"
@@ -6950,7 +6955,9 @@ const CONTRACT = deepFreeze({
6950
6955
  // holding any of the values. At most 100; no `valueMode` applies.
6951
6956
  // 1.253.0: fix (sc-16577) — `react-native-safe-area-context` is host-resolved,
6952
6957
  // so `useSafeAreaInsets()` returns zeros on web as documented instead of throwing.
6953
- version: "1.253.0",
6958
+ // 1.254.0: `formatMoney` shows a whole amount without decimals ("795 kr");
6959
+ // `formatMoney(minor, { decimals: "always" })` keeps them ("795,00 kr").
6960
+ version: "1.254.0",
6954
6961
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
6955
6962
  hooks: HOOKS,
6956
6963
  primitives: PRIMITIVES,
@@ -7302,6 +7309,82 @@ function deriveSurfaceTokens(backgroundColor) {
7302
7309
  };
7303
7310
  }
7304
7311
 
7312
+ // The theme_config keys that state a light page's own surface set, by token.
7313
+ const THEME_SURFACE_COLOR_KEYS = Object.freeze({
7314
+ surfaceMuted: "surfaceMutedColor",
7315
+ border: "surfaceBorderColor",
7316
+ onSurfaceMuted: "mutedTextColor",
7317
+ });
7318
+ // How far a look's muted panel and border step from its page toward its ink.
7319
+ const LIGHT_SURFACE_MIX = Object.freeze({ surfaceMuted: 0.04, border: 0.12 });
7320
+ // Slate's own saturation, so a tinted set is as quiet as the default one.
7321
+ const LIGHT_SURFACE_MAX_SATURATION = 0.2;
7322
+ const LIGHT_SURFACE_TEXT_STEP = 0.01;
7323
+
7324
+ function isLightBackground(backgroundColor) {
7325
+ return readableTextColor(backgroundColor, "dark", "light") === "dark";
7326
+ }
7327
+
7328
+ /**
7329
+ * The page's surface set for a stored theme: `deriveSurfaceTokens` of its
7330
+ * background, with the theme's own `THEME_SURFACE_COLOR_KEYS` over it while
7331
+ * that background is light. A dark page keeps the derivation, so a light set
7332
+ * left on the theme never paints it. `null` when the background is unusable.
7333
+ */
7334
+ function themeSurfaceTokens(themeConfig) {
7335
+ const cfg = themeConfig && typeof themeConfig === "object" ? themeConfig : {};
7336
+ const derived = deriveSurfaceTokens(cfg.backgroundColor);
7337
+ if (!derived || !isLightBackground(cfg.backgroundColor)) return derived;
7338
+ const out = { ...derived };
7339
+ for (const [token, key] of Object.entries(THEME_SURFACE_COLOR_KEYS)) {
7340
+ if (isHexColor(cfg[key])) out[token] = cfg[key];
7341
+ }
7342
+ return out;
7343
+ }
7344
+
7345
+ /**
7346
+ * The surface set a look's LIGHT background wants, as theme_config keys: the
7347
+ * muted panel and border step toward the ink in the background's own hue, and
7348
+ * the muted text keeps the default's weight in that hue, darkened until it
7349
+ * reads at WCAG AA on the surface, the muted panel and the page. `null` for a
7350
+ * dark or unusable background, which `deriveSurfaceTokens` already covers.
7351
+ */
7352
+ /** The hues of the contract's own slate: a page tinted within them already matches it. */
7353
+ const SLATE_HUES = Object.freeze({ from: 195, to: 225 });
7354
+
7355
+ /** Whether a page has a hue of its own; white, grey and slate-blue keep the contract's colours. */
7356
+ function hasOwnTint(backgroundColor) {
7357
+ const channels = hexChannels(backgroundColor);
7358
+ if (Math.max(...channels) - Math.min(...channels) <= 2) return false;
7359
+ const [hue] = hexToHsl(backgroundColor);
7360
+ return hue < SLATE_HUES.from || hue > SLATE_HUES.to;
7361
+ }
7362
+
7363
+ function deriveLightSurfaceColors(backgroundColor, inkColor) {
7364
+ if (!isHexColor(backgroundColor) || !isLightBackground(backgroundColor) || !hasOwnTint(backgroundColor)) return null;
7365
+ const base = DEFAULT_THEME_TOKENS.colors;
7366
+ const [hue, saturation] = hexToHsl(backgroundColor);
7367
+ const tint = Math.min(saturation, LIGHT_SURFACE_MAX_SATURATION);
7368
+ const ink = isHexColor(inkColor) ? inkColor : base.onSurface;
7369
+ const tone = hslToHex(hue, tint, hexToHsl(ink)[2]);
7370
+ const surfaceMuted = mixHex(backgroundColor, tone, LIGHT_SURFACE_MIX.surfaceMuted);
7371
+ const backdrops = [base.surface, surfaceMuted, backgroundColor];
7372
+ let lightness = hexToHsl(base.onSurfaceMuted)[2];
7373
+ let text = hslToHex(hue, tint, lightness);
7374
+ while (
7375
+ lightness > 0 &&
7376
+ backdrops.some((backdrop) => contrastRatio(text, backdrop) < ACCENT_TEXT_MIN_CONTRAST)
7377
+ ) {
7378
+ lightness = Math.max(0, lightness - LIGHT_SURFACE_TEXT_STEP);
7379
+ text = hslToHex(hue, tint, lightness);
7380
+ }
7381
+ return {
7382
+ [THEME_SURFACE_COLOR_KEYS.surfaceMuted]: surfaceMuted,
7383
+ [THEME_SURFACE_COLOR_KEYS.border]: mixHex(backgroundColor, tone, LIGHT_SURFACE_MIX.border),
7384
+ [THEME_SURFACE_COLOR_KEYS.onSurfaceMuted]: text,
7385
+ };
7386
+ }
7387
+
7305
7388
  // sc-8370: WCAG 1.4.3 for text, 1.4.11 for a control's boundary.
7306
7389
  const INK_CONTRAST = Object.freeze({ text: 4.5, boundary: 3 });
7307
7390
 
@@ -7455,6 +7538,9 @@ module.exports = {
7455
7538
  deriveAccentTints,
7456
7539
  deriveStatusColors,
7457
7540
  deriveSurfaceTokens,
7541
+ themeSurfaceTokens,
7542
+ deriveLightSurfaceColors,
7543
+ THEME_SURFACE_COLOR_KEYS,
7458
7544
  inkForBackdrop,
7459
7545
  INK_CONTRAST,
7460
7546
  gradientAngleToVector,
package/dist/contract.js CHANGED
@@ -2509,7 +2509,7 @@ const HOOKS = [
2509
2509
  currency:
2510
2510
  "string // the ISO code this workspace charges its app users in, e.g. \"SEK\"",
2511
2511
  formatMoney:
2512
- "(minorUnits) => string // 45000 -> \"450,00 kr\"; renders identically on web and native. NEVER write a currency symbol or code yourself",
2512
+ "(minorUnits, { decimals: \"always\" }?) => string // 79500 -> \"795 kr\", 9950 -> \"99,50 kr\": a whole amount shows no decimals; pass { decimals: \"always\" } for a receipt or invoice total (\"795,00 kr\"). Renders identically on web and native. NEVER write a currency symbol or code yourself",
2513
2513
  },
2514
2514
  requiredContextSlice: ["workspace.currency"],
2515
2515
  scopes: null,
@@ -4973,8 +4973,8 @@ const VETTED_IMPORTS = [
4973
4973
  description:
4974
4974
  "RevenueCat in-app purchase (StoreKit / Play Billing). PREFER usePurchases() from the SDK, which already runs on the " +
4975
4975
  "app's configured, signed-in customer. Import this directly only for what the hook does not cover, and NEVER call " +
4976
- "Purchases.configure, logIn or logOut — the app owns them, and it configures Purchases only when the workspace " +
4977
- "connected RevenueCat. Native-only because no browser offers store billing: author it in widget.native.jsx and give " +
4976
+ "Purchases.configure, logIn or logOut — the app owns them. The package is in the app only when the workspace " +
4977
+ "connected RevenueCat: a store build of a workspace that has not is refused while a widget imports it. Native-only because no browser offers store billing: author it in widget.native.jsx and give " +
4978
4978
  "widget.web.jsx a visible 'available in the app' state.",
4979
4979
  },
4980
4980
  {
@@ -5336,18 +5336,6 @@ function normaliseCurrencyCode(value) {
5336
5336
  return code || CHARGE_CURRENCY;
5337
5337
  }
5338
5338
 
5339
- /**
5340
- * `formatMoneyIn("SEK", 45000)` → `"450,00 kr"`.
5341
- *
5342
- * Takes MINOR units — the same unit `requestPayment` charges in — so there is no
5343
- * conversion step for a widget to get wrong. Renders from `CURRENCY_FORMATS`
5344
- * rather than `Intl.NumberFormat`, which does not produce identical output in
5345
- * the exported Expo app and react-native-web; this string sits beside the amount
5346
- * the buyer is actually charged, so the two hosts must agree exactly.
5347
- *
5348
- * A non-finite amount renders as zero rather than "NaN": a price whose data has
5349
- * not loaded should read as an amount, never as a broken string in a checkout.
5350
- */
5351
5339
  /**
5352
5340
  * sc-5717 — value equality for a stored widget-route value: is this key still
5353
5341
  * at the default its widget declared?
@@ -5363,7 +5351,22 @@ function sameWidgetRouteValue(a, b) {
5363
5351
  }
5364
5352
  return Object.is(a, b);
5365
5353
  }
5366
- function formatMoneyIn(currency, minorUnits) {
5354
+ /**
5355
+ * `formatMoneyIn("SEK", 79500)` → `"795 kr"`; `formatMoneyIn("SEK", 9950)` → `"99,50 kr"`.
5356
+ *
5357
+ * Takes MINOR units — the same unit `requestPayment` charges in — so there is no
5358
+ * conversion step for a widget to get wrong. Renders from `CURRENCY_FORMATS`
5359
+ * rather than `Intl.NumberFormat`, which does not produce identical output in
5360
+ * the exported Expo app and react-native-web; this string sits beside the amount
5361
+ * the buyer is actually charged, so the two hosts must agree exactly.
5362
+ *
5363
+ * A whole amount drops its decimals, as shops and menus write prices.
5364
+ * `{ decimals: "always" }` keeps them, for a receipt or invoice total.
5365
+ *
5366
+ * A non-finite amount renders as zero rather than "NaN": a price whose data has
5367
+ * not loaded should read as an amount, never as a broken string in a checkout.
5368
+ */
5369
+ function formatMoneyIn(currency, minorUnits, options) {
5367
5370
  const code = normaliseCurrencyCode(currency);
5368
5371
  const fmt = CURRENCY_FORMATS[code] || {
5369
5372
  ...CURRENCY_FORMAT_FALLBACK,
@@ -5376,7 +5379,9 @@ function formatMoneyIn(currency, minorUnits) {
5376
5379
  const whole = fmt.decimals > 0 ? digits.slice(0, -fmt.decimals) : digits;
5377
5380
  const cents = fmt.decimals > 0 ? digits.slice(-fmt.decimals) : "";
5378
5381
  const grouped = whole.replace(/\B(?=(\d{3})+(?!\d))/g, fmt.groupSeparator);
5379
- const body = cents ? `${grouped}${fmt.decimalSeparator}${cents}` : grouped;
5382
+ const alwaysDecimals = Boolean(options && options.decimals === "always");
5383
+ const showCents = cents !== "" && (alwaysDecimals || /[1-9]/.test(cents));
5384
+ const body = showCents ? `${grouped}${fmt.decimalSeparator}${cents}` : grouped;
5380
5385
  const gap = fmt.space ? " " : "";
5381
5386
  const withSymbol =
5382
5387
  fmt.position === "before"
@@ -6945,7 +6950,9 @@ const CONTRACT = deepFreeze({
6945
6950
  // holding any of the values. At most 100; no `valueMode` applies.
6946
6951
  // 1.253.0: fix (sc-16577) — `react-native-safe-area-context` is host-resolved,
6947
6952
  // so `useSafeAreaInsets()` returns zeros on web as documented instead of throwing.
6948
- version: "1.253.0",
6953
+ // 1.254.0: `formatMoney` shows a whole amount without decimals ("795 kr");
6954
+ // `formatMoney(minor, { decimals: "always" })` keeps them ("795,00 kr").
6955
+ version: "1.254.0",
6949
6956
  sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
6950
6957
  hooks: HOOKS,
6951
6958
  primitives: PRIMITIVES,
@@ -7297,6 +7304,82 @@ function deriveSurfaceTokens(backgroundColor) {
7297
7304
  };
7298
7305
  }
7299
7306
 
7307
+ // The theme_config keys that state a light page's own surface set, by token.
7308
+ const THEME_SURFACE_COLOR_KEYS = Object.freeze({
7309
+ surfaceMuted: "surfaceMutedColor",
7310
+ border: "surfaceBorderColor",
7311
+ onSurfaceMuted: "mutedTextColor",
7312
+ });
7313
+ // How far a look's muted panel and border step from its page toward its ink.
7314
+ const LIGHT_SURFACE_MIX = Object.freeze({ surfaceMuted: 0.04, border: 0.12 });
7315
+ // Slate's own saturation, so a tinted set is as quiet as the default one.
7316
+ const LIGHT_SURFACE_MAX_SATURATION = 0.2;
7317
+ const LIGHT_SURFACE_TEXT_STEP = 0.01;
7318
+
7319
+ function isLightBackground(backgroundColor) {
7320
+ return readableTextColor(backgroundColor, "dark", "light") === "dark";
7321
+ }
7322
+
7323
+ /**
7324
+ * The page's surface set for a stored theme: `deriveSurfaceTokens` of its
7325
+ * background, with the theme's own `THEME_SURFACE_COLOR_KEYS` over it while
7326
+ * that background is light. A dark page keeps the derivation, so a light set
7327
+ * left on the theme never paints it. `null` when the background is unusable.
7328
+ */
7329
+ function themeSurfaceTokens(themeConfig) {
7330
+ const cfg = themeConfig && typeof themeConfig === "object" ? themeConfig : {};
7331
+ const derived = deriveSurfaceTokens(cfg.backgroundColor);
7332
+ if (!derived || !isLightBackground(cfg.backgroundColor)) return derived;
7333
+ const out = { ...derived };
7334
+ for (const [token, key] of Object.entries(THEME_SURFACE_COLOR_KEYS)) {
7335
+ if (isHexColor(cfg[key])) out[token] = cfg[key];
7336
+ }
7337
+ return out;
7338
+ }
7339
+
7340
+ /**
7341
+ * The surface set a look's LIGHT background wants, as theme_config keys: the
7342
+ * muted panel and border step toward the ink in the background's own hue, and
7343
+ * the muted text keeps the default's weight in that hue, darkened until it
7344
+ * reads at WCAG AA on the surface, the muted panel and the page. `null` for a
7345
+ * dark or unusable background, which `deriveSurfaceTokens` already covers.
7346
+ */
7347
+ /** The hues of the contract's own slate: a page tinted within them already matches it. */
7348
+ const SLATE_HUES = Object.freeze({ from: 195, to: 225 });
7349
+
7350
+ /** Whether a page has a hue of its own; white, grey and slate-blue keep the contract's colours. */
7351
+ function hasOwnTint(backgroundColor) {
7352
+ const channels = hexChannels(backgroundColor);
7353
+ if (Math.max(...channels) - Math.min(...channels) <= 2) return false;
7354
+ const [hue] = hexToHsl(backgroundColor);
7355
+ return hue < SLATE_HUES.from || hue > SLATE_HUES.to;
7356
+ }
7357
+
7358
+ function deriveLightSurfaceColors(backgroundColor, inkColor) {
7359
+ if (!isHexColor(backgroundColor) || !isLightBackground(backgroundColor) || !hasOwnTint(backgroundColor)) return null;
7360
+ const base = DEFAULT_THEME_TOKENS.colors;
7361
+ const [hue, saturation] = hexToHsl(backgroundColor);
7362
+ const tint = Math.min(saturation, LIGHT_SURFACE_MAX_SATURATION);
7363
+ const ink = isHexColor(inkColor) ? inkColor : base.onSurface;
7364
+ const tone = hslToHex(hue, tint, hexToHsl(ink)[2]);
7365
+ const surfaceMuted = mixHex(backgroundColor, tone, LIGHT_SURFACE_MIX.surfaceMuted);
7366
+ const backdrops = [base.surface, surfaceMuted, backgroundColor];
7367
+ let lightness = hexToHsl(base.onSurfaceMuted)[2];
7368
+ let text = hslToHex(hue, tint, lightness);
7369
+ while (
7370
+ lightness > 0 &&
7371
+ backdrops.some((backdrop) => contrastRatio(text, backdrop) < ACCENT_TEXT_MIN_CONTRAST)
7372
+ ) {
7373
+ lightness = Math.max(0, lightness - LIGHT_SURFACE_TEXT_STEP);
7374
+ text = hslToHex(hue, tint, lightness);
7375
+ }
7376
+ return {
7377
+ [THEME_SURFACE_COLOR_KEYS.surfaceMuted]: surfaceMuted,
7378
+ [THEME_SURFACE_COLOR_KEYS.border]: mixHex(backgroundColor, tone, LIGHT_SURFACE_MIX.border),
7379
+ [THEME_SURFACE_COLOR_KEYS.onSurfaceMuted]: text,
7380
+ };
7381
+ }
7382
+
7300
7383
  // sc-8370: WCAG 1.4.3 for text, 1.4.11 for a control's boundary.
7301
7384
  const INK_CONTRAST = Object.freeze({ text: 4.5, boundary: 3 });
7302
7385
 
@@ -7450,6 +7533,9 @@ export {
7450
7533
  deriveAccentTints,
7451
7534
  deriveStatusColors,
7452
7535
  deriveSurfaceTokens,
7536
+ themeSurfaceTokens,
7537
+ deriveLightSurfaceColors,
7538
+ THEME_SURFACE_COLOR_KEYS,
7453
7539
  inkForBackdrop,
7454
7540
  INK_CONTRAST,
7455
7541
  gradientAngleToVector,
package/dist/devserver.js CHANGED
@@ -129,7 +129,7 @@ export async function loadTransform() {
129
129
  return mod.transform;
130
130
  } catch {
131
131
  throw new Error(
132
- "`appstudio-widget dev` needs the optional `sucrase` dependency.\n" +
132
+ "`appstudio-widget dev` needs `sucrase`, an optional peer of the SDK.\n" +
133
133
  "Install it in your widget project:\n" +
134
134
  " npm install --save-dev sucrase",
135
135
  );
package/dist/hooks.js CHANGED
@@ -198,8 +198,9 @@ function readInput(inputs, inputName) {
198
198
  * resolve the other two pieces of workspace configuration at render time.
199
199
  *
200
200
  * `formatMoney` takes MINOR units, the same unit `requestPayment` charges in.
201
+ * A whole amount shows no decimals; `{ decimals: "always" }` keeps them.
201
202
  *
202
- * @returns {{ currency: string, formatMoney: (minorUnits: number) => string }}
203
+ * @returns {{ currency: string, formatMoney: (minorUnits: number, options?: { decimals?: "always" }) => string }}
203
204
  */
204
205
  export function useWorkspaceCurrency() {
205
206
  const ctx = useWidgetContextOrThrow("useWorkspaceCurrency");
@@ -208,7 +209,7 @@ export function useWorkspaceCurrency() {
208
209
  return React.useMemo(
209
210
  () => ({
210
211
  currency: normaliseCurrencyCode(currency),
211
- formatMoney: (minorUnits) => formatMoneyIn(currency, minorUnits),
212
+ formatMoney: (minorUnits, options) => formatMoneyIn(currency, minorUnits, options),
212
213
  }),
213
214
  [currency],
214
215
  );
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
@@ -73,6 +73,16 @@ export function surfaceAwareTheme<T>(theme: T, backgroundColor: unknown): T;
73
73
  /** Minimum contrast: `text` for labels (WCAG 1.4.3), `boundary` for edges (1.4.11). */
74
74
  export const INK_CONTRAST: Readonly<{ text: number; boundary: number }>;
75
75
 
76
+ /**
77
+ * Minor units in a currency to its display string, as `useWorkspaceCurrency().formatMoney`
78
+ * writes it: `formatMoneyIn("SEK", 79500)` -> "795 kr", 9950 -> "99,50 kr".
79
+ */
80
+ export function formatMoneyIn(
81
+ currency: string | null | undefined,
82
+ minorUnits: number,
83
+ options?: { decimals?: "always" },
84
+ ): string;
85
+
76
86
  /**
77
87
  * The measured re-ink rule a painted section applies to its text and buttons:
78
88
  * `current` while it reaches `minimum` against `backdrop`, else `candidate`
@@ -124,6 +134,18 @@ export function applyThemeComponentStyle<T = Record<string, unknown>>(
124
134
  styleSchema?: Record<string, unknown> | null,
125
135
  ): T;
126
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
+
127
149
  // sc-4939 — the host half of `useToast()`. A widget only ever calls the hook;
128
150
  // these are what a platform host puts behind `WidgetContext.toast`.
129
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,
@@ -42,6 +45,10 @@ export {
42
45
  // Host plumbing, deliberately off the author entry point: a widget reads the
43
46
  // already-correct `useTheme().colors`, it never derives them itself.
44
47
  export { deriveSurfaceTokens, inkForBackdrop, INK_CONTRAST } from "./contract.js";
48
+ // A stored theme's page surface set, honouring its own light-surface colours.
49
+ export { themeSurfaceTokens } from "./contract.js";
50
+ // The host's own price labels, written exactly as a widget's `formatMoney`.
51
+ export { formatMoneyIn } from "./contract.js";
45
52
  export { surfaceAwareTheme } from "./surface-theme.js";
46
53
 
47
54
  // REQ-WSDK-PLATFORM §6: the host half of `useToast()` — the queue, the
package/dist/index.d.ts CHANGED
@@ -1843,8 +1843,11 @@ export function useRecordMutes(
1843
1843
  export interface WorkspaceCurrency {
1844
1844
  /** The ISO code this workspace charges its app users in. */
1845
1845
  currency: string;
1846
- /** MINOR units in, a display string out: 45000 -> "450,00 kr". */
1847
- formatMoney: (minorUnits: number) => string;
1846
+ /**
1847
+ * MINOR units in, a display string out: 79500 -> "795 kr", 9950 -> "99,50 kr".
1848
+ * `{ decimals: "always" }` keeps the decimals of a whole amount: "795,00 kr".
1849
+ */
1850
+ formatMoney: (minorUnits: number, options?: { decimals?: "always" }) => string;
1848
1851
  }
1849
1852
  /**
1850
1853
  * sc-4686 — the workspace charge currency + the only sanctioned way to render