@c1m-public/channel-client 6.0.0 → 6.1.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,8 @@ transport core.
19
19
  split; see [The `/next` kits](#the-next-kits).
20
20
  - `@c1m-public/channel-client/site` — what a public site serves, decided from
21
21
  the `signals` block every bootstrap carries, plus the site-mode settings
22
- helpers owner and operator screens share; see [`./site`](#site). Pure, no
22
+ helpers owner and operator screens share, and the brand-colour theme
23
+ helpers; see [`./site`](#site). Pure, no
23
24
  transport, safe in a proxy or a client component.
24
25
  - `@c1m-public/channel-client/moving-lead-model` — the moving-quote domain
25
26
  model shared by dash sites and SaaSDash; no transport, optional `zod` peer.
@@ -364,6 +365,33 @@ itself when the site is available.
364
365
  `describeLiveGate`, `toDateTimeLocal` and `fromDateTimeLocal` are the shared
365
366
  pieces of a site-mode settings form.
366
367
 
368
+ ### Site theme
369
+
370
+ `createSiteTheme(primaryColor, options?)` turns the owner's brand colour
371
+ (`content.theme.get()` or `dash.init().branding`) into the accent tokens, and
372
+ `themeStyle(theme)` returns them as CSS custom properties for the root
373
+ element's `style`:
374
+
375
+ ```tsx
376
+ import type { CSSProperties } from "react";
377
+ import { createSiteTheme, themeStyle } from "@c1m-public/channel-client/site";
378
+
379
+ const theme = createSiteTheme(brand.primary_color);
380
+ <body style={themeStyle(theme) as CSSProperties}>…</body>
381
+ ```
382
+
383
+ | Token | Meaning |
384
+ | --- | --- |
385
+ | `--accent` | The brand colour, or `options.fallbackAccent` (default `#262626`) when missing or not a six-digit hex |
386
+ | `--accent-foreground` | White or `options.darkText` (default `#171717`), whichever contrasts more with the accent |
387
+ | `--accent-text` | The accent darkened until it reads as text on white (contrast 5:1) |
388
+ | `--accent-strong` | Hover and pressed shade: 14% toward black, or 18% toward white for a near-black accent |
389
+ | `--accent-soft` | Tint for selected surfaces: 90% toward white |
390
+
391
+ The full site token contract, with a copy-paste `globals.css`, is in the
392
+ `@c1m-public/dash-site-kit` README under "Styling contract"; workspace sites
393
+ use the same token names.
394
+
367
395
  ## `./moving-lead-model`
368
396
 
369
397
  A subpath carrying the moving-quote domain model: lead payload schemas, the
package/dist/site.d.ts CHANGED
@@ -1,11 +1,59 @@
1
1
  import { cf as SiteRef, ca as PublicGate, cc as PublicSiteSignals } from './types-BedZ9_Y2.js';
2
2
 
3
+ /**
4
+ * Site theme: the accent tokens a public site derives from the owner's brand
5
+ * colour. Pure and framework-free, so a Next layout, a plain server and a
6
+ * settings preview share one reading of the colour.
7
+ */
8
+ interface SiteThemeOptions {
9
+ /** Accent used when the primary colour is missing or not a six-digit hex. Default `#262626`. */
10
+ fallbackAccent?: string;
11
+ /** Text colour used on a light accent. Default `#171717`. */
12
+ darkText?: string;
13
+ }
14
+ /** The accent tokens of a site, as `#RRGGBB` strings. */
15
+ interface SiteTheme {
16
+ /** The normalised brand colour, or the fallback accent. */
17
+ accent: string;
18
+ /** White or the configured dark text, whichever contrasts more with the accent. */
19
+ accentForeground: string;
20
+ /** The accent darkened until it reads as text on white. */
21
+ accentText: string;
22
+ /**
23
+ * The hover and pressed accent: 14% darker, or 18% lighter for a
24
+ * near-black accent. Matches the `color-mix` the sites used in CSS.
25
+ */
26
+ accentStrong: string;
27
+ /** A tint for selected and highlighted surfaces: the accent mixed with 90% white. */
28
+ accentSoft: string;
29
+ }
30
+ /**
31
+ * What `themeStyle` reads. `accentStrong` and `accentSoft` are optional so a
32
+ * theme built by hand before they existed still renders; they are derived
33
+ * from `accent` when absent.
34
+ */
35
+ type SiteThemeTokens = Pick<SiteTheme, "accent" | "accentForeground" | "accentText"> & Partial<Pick<SiteTheme, "accentStrong" | "accentSoft">>;
36
+ /**
37
+ * The site's accent from the platform's brand colour, with text colours that
38
+ * stay readable on it and on a white page, plus its hover and tint shades. A
39
+ * missing or malformed colour falls back to `options.fallbackAccent`.
40
+ */
41
+ declare function createSiteTheme(primaryColor: string | undefined, options?: SiteThemeOptions): SiteTheme;
42
+ /**
43
+ * The theme as the CSS custom properties a site's `globals.css` reads:
44
+ * `--accent`, `--accent-foreground`, `--accent-text`, `--accent-strong` and
45
+ * `--accent-soft`. A plain record so the entry needs no React types; cast it
46
+ * to `CSSProperties` to pass it as a `style` prop.
47
+ */
48
+ declare function themeStyle(theme: SiteThemeTokens): Record<string, string>;
49
+
3
50
  /**
4
51
  * Site signals: what a public site serves, decided from the `signals` block
5
52
  * every bootstrap carries (dash init, workspace init and light init). Pure and
6
53
  * framework-free, so a proxy, a layout and an admin screen share one reading.
7
54
  * The server decides whether a gate applies; this only maps the decision to a
8
- * request.
55
+ * request. The entry also carries the site theme helpers (`createSiteTheme`,
56
+ * `themeStyle`), which derive the accent tokens from the brand colour.
9
57
  */
10
58
 
11
59
  type SiteGateKind = "waitlist" | "maintenance" | "private";
@@ -125,4 +173,4 @@ declare function toDateTimeLocal(value?: string): string;
125
173
  /** A datetime-local value back to RFC 3339; undefined when empty or invalid. */
126
174
  declare function fromDateTimeLocal(value: string): string | undefined;
127
175
 
128
- export { GATE_EXEMPT_PATHS, PRIVATE_PATH, PublicGate, PublicSiteSignals, SITE_MODE_CHOICES, type SiteDecision, type SiteGate, type SiteGateKind, type SiteModeChoice, type SiteModeFields, SiteRef, type SiteResponse, type SiteSignals, UNAVAILABLE_PATH, describeLiveGate, fromDateTimeLocal, normalizeGate, normalizeSignals, siteDecision, siteModeChoice, siteResponse, toDateTimeLocal, withSiteModeChoice };
176
+ export { GATE_EXEMPT_PATHS, PRIVATE_PATH, PublicGate, PublicSiteSignals, SITE_MODE_CHOICES, type SiteDecision, type SiteGate, type SiteGateKind, type SiteModeChoice, type SiteModeFields, SiteRef, type SiteResponse, type SiteSignals, type SiteTheme, type SiteThemeOptions, type SiteThemeTokens, UNAVAILABLE_PATH, createSiteTheme, describeLiveGate, fromDateTimeLocal, normalizeGate, normalizeSignals, siteDecision, siteModeChoice, siteResponse, themeStyle, toDateTimeLocal, withSiteModeChoice };
package/dist/site.js CHANGED
@@ -1,3 +1,73 @@
1
+ // src/site-theme.ts
2
+ var DEFAULT_FALLBACK_ACCENT = "#262626";
3
+ var DEFAULT_DARK_TEXT = "#171717";
4
+ var WHITE = "#FFFFFF";
5
+ var HEX_COLOR = /^#?([0-9a-f]{6})$/i;
6
+ var NEAR_BLACK_LUMINANCE = 0.02;
7
+ function rgbOf(value) {
8
+ return [1, 3, 5].map((offset) => Number.parseInt(value.slice(offset, offset + 2), 16));
9
+ }
10
+ function hexOf(rgb) {
11
+ return `#${rgb.map((value) => Math.round(value).toString(16).padStart(2, "0")).join("").toUpperCase()}`;
12
+ }
13
+ function linearize(value) {
14
+ return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
15
+ }
16
+ function relativeLuminance(value) {
17
+ const [r, g, b] = rgbOf(value).map((channel) => linearize(channel / 255));
18
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b;
19
+ }
20
+ function contrast(lighter, darker) {
21
+ return (lighter + 0.05) / (darker + 0.05);
22
+ }
23
+ function mix(accent, target, weight) {
24
+ return hexOf(rgbOf(accent).map((value) => value * (1 - weight) + target * weight));
25
+ }
26
+ function readableAccentText(accent) {
27
+ let rgb = rgbOf(accent);
28
+ let candidate = accent;
29
+ while (contrast(1, relativeLuminance(candidate)) < 5) {
30
+ rgb = rgb.map((value) => Math.floor(value * 0.82));
31
+ candidate = hexOf(rgb);
32
+ }
33
+ return candidate;
34
+ }
35
+ function strongAccent(accent) {
36
+ return relativeLuminance(accent) < NEAR_BLACK_LUMINANCE ? mix(accent, 255, 0.18) : mix(accent, 0, 0.14);
37
+ }
38
+ function softAccent(accent) {
39
+ return mix(accent, 255, 0.9);
40
+ }
41
+ function normalizeHex(value) {
42
+ const match = value.trim().match(HEX_COLOR);
43
+ return match ? `#${match[1].toUpperCase()}` : void 0;
44
+ }
45
+ function createSiteTheme(primaryColor, options = {}) {
46
+ const fallback = options.fallbackAccent ?? DEFAULT_FALLBACK_ACCENT;
47
+ const darkText = options.darkText ?? DEFAULT_DARK_TEXT;
48
+ const accent = (primaryColor === void 0 ? void 0 : normalizeHex(primaryColor)) ?? fallback;
49
+ const luminance = relativeLuminance(accent);
50
+ const whiteContrast = contrast(1, luminance);
51
+ const darkContrast = contrast(luminance, relativeLuminance(darkText));
52
+ return {
53
+ accent,
54
+ accentForeground: whiteContrast >= darkContrast ? WHITE : darkText,
55
+ accentText: readableAccentText(accent),
56
+ accentStrong: strongAccent(accent),
57
+ accentSoft: softAccent(accent)
58
+ };
59
+ }
60
+ function themeStyle(theme) {
61
+ const accent = normalizeHex(theme.accent);
62
+ return {
63
+ "--accent": theme.accent,
64
+ "--accent-foreground": theme.accentForeground,
65
+ "--accent-text": theme.accentText,
66
+ "--accent-strong": theme.accentStrong ?? (accent ? strongAccent(accent) : theme.accent),
67
+ "--accent-soft": theme.accentSoft ?? (accent ? softAccent(accent) : theme.accent)
68
+ };
69
+ }
70
+
1
71
  // src/site.ts
2
72
  var GATE_EXEMPT_PATHS = [
3
73
  "/api",
@@ -125,4 +195,4 @@ function fromDateTimeLocal(value) {
125
195
  return Number.isNaN(date.getTime()) ? void 0 : date.toISOString();
126
196
  }
127
197
 
128
- export { GATE_EXEMPT_PATHS, PRIVATE_PATH, SITE_MODE_CHOICES, UNAVAILABLE_PATH, describeLiveGate, fromDateTimeLocal, normalizeGate, normalizeSignals, siteDecision, siteModeChoice, siteResponse, toDateTimeLocal, withSiteModeChoice };
198
+ export { GATE_EXEMPT_PATHS, PRIVATE_PATH, SITE_MODE_CHOICES, UNAVAILABLE_PATH, createSiteTheme, describeLiveGate, fromDateTimeLocal, normalizeGate, normalizeSignals, siteDecision, siteModeChoice, siteResponse, themeStyle, toDateTimeLocal, withSiteModeChoice };
package/package.json CHANGED
@@ -1,17 +1,16 @@
1
1
  {
2
2
  "name": "@c1m-public/channel-client",
3
- "version": "6.0.0",
3
+ "version": "6.1.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Typed server-side client for the MML headless Channel API",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "https://github.com/cloud1mediaLtd/mml-js.git",
10
- "directory": "packages/channel-client"
9
+ "url": "https://github.com/cloud1mediaLtd/workspace-site-starter.git"
11
10
  },
12
- "homepage": "https://github.com/cloud1mediaLtd/mml-js/tree/main/packages/channel-client",
11
+ "homepage": "https://github.com/cloud1mediaLtd/workspace-site-starter#readme",
13
12
  "bugs": {
14
- "url": "https://github.com/cloud1mediaLtd/mml-js/issues"
13
+ "url": "https://github.com/cloud1mediaLtd/workspace-site-starter/issues"
15
14
  },
16
15
  "main": "./dist/index.js",
17
16
  "types": "./dist/index.d.ts",