@d4gger/design-system 4.0.2 → 4.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.
Files changed (43) hide show
  1. package/README.md +3 -0
  2. package/dist/docs/component-index.json +1 -1
  3. package/dist/docs/consumer-guide.md +96 -0
  4. package/dist/foundations/telegram/index.cjs +20 -0
  5. package/dist/foundations/telegram/index.cjs.map +7 -0
  6. package/dist/foundations/telegram/index.d.cts +3 -0
  7. package/dist/foundations/telegram/index.d.cts.map +1 -0
  8. package/dist/foundations/telegram/index.d.mts +3 -0
  9. package/dist/foundations/telegram/index.d.mts.map +1 -0
  10. package/dist/foundations/telegram/index.d.ts +3 -0
  11. package/dist/foundations/telegram/index.d.ts.map +1 -0
  12. package/dist/foundations/telegram/index.js +3 -0
  13. package/dist/foundations/telegram/index.js.map +7 -0
  14. package/dist/foundations/telegram/theme-params.cjs +160 -0
  15. package/dist/foundations/telegram/theme-params.cjs.map +7 -0
  16. package/dist/foundations/telegram/theme-params.d.cts +124 -0
  17. package/dist/foundations/telegram/theme-params.d.cts.map +1 -0
  18. package/dist/foundations/telegram/theme-params.d.mts +124 -0
  19. package/dist/foundations/telegram/theme-params.d.mts.map +1 -0
  20. package/dist/foundations/telegram/theme-params.d.ts +124 -0
  21. package/dist/foundations/telegram/theme-params.d.ts.map +1 -0
  22. package/dist/foundations/telegram/theme-params.js +140 -0
  23. package/dist/foundations/telegram/theme-params.js.map +7 -0
  24. package/dist/foundations/telegram/viewport.cjs +81 -0
  25. package/dist/foundations/telegram/viewport.cjs.map +7 -0
  26. package/dist/foundations/telegram/viewport.d.cts +57 -0
  27. package/dist/foundations/telegram/viewport.d.cts.map +1 -0
  28. package/dist/foundations/telegram/viewport.d.mts +57 -0
  29. package/dist/foundations/telegram/viewport.d.mts.map +1 -0
  30. package/dist/foundations/telegram/viewport.d.ts +57 -0
  31. package/dist/foundations/telegram/viewport.d.ts.map +1 -0
  32. package/dist/foundations/telegram/viewport.js +61 -0
  33. package/dist/foundations/telegram/viewport.js.map +7 -0
  34. package/dist/styles.css +2 -3
  35. package/dist/telegram.css +93 -0
  36. package/dist/tokens.cjs +968 -0
  37. package/dist/tokens.d.cts +964 -0
  38. package/dist/tokens.d.mts +964 -0
  39. package/dist/tokens.d.ts +964 -0
  40. package/dist/tokens.js +964 -0
  41. package/dist/tokens.json +964 -0
  42. package/dist/utilities.css +2 -3
  43. package/package.json +26 -2
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Telegram Mini App `theme_params` contract and its bridge into DS tokens.
3
+ *
4
+ * Telegram publishes the client's palette two ways: as a `themeParams`
5
+ * object on `Telegram.WebApp` (snake_case hex colors, e.g. `bg_color`) and
6
+ * as CSS custom properties on `:root` (`--tg-theme-bg-color`, …). This
7
+ * module types the params object, names the CSS variables, and maps each
8
+ * param onto the DS token it feeds — without taking a Telegram SDK
9
+ * dependency (same stance as `ThemeProvider`'s system-mode handling).
10
+ *
11
+ * Mode ownership stays with `Theme` / `ThemeProvider`: this bridge only
12
+ * writes paint tokens on the Mini App root. `colorScheme` sync (including
13
+ * the `themeChanged` subscription) already lives in `ThemeProvider`.
14
+ *
15
+ * The bridge is the one path from Telegram's palette to DS tokens (G-35:
16
+ * `telegram.css` carries no colour rules). It writes the accent *roles* the
17
+ * components read (`track`, `contrast`, `indicator`, `surface`, ADR 003) next
18
+ * to the legacy `primary` pair, and it writes on both `<html>` and `<body>`
19
+ * because `Theme` mirrors its data attributes on both and the theme rules
20
+ * re-declare every token on `<body>` (G-33, G-34).
21
+ */
22
+ export type TelegramColorScheme = 'light' | 'dark';
23
+ /**
24
+ * Subset of `Telegram.WebApp.themeParams` the bridge consumes. Every field
25
+ * is optional — Telegram omits keys it has no value for, and older clients
26
+ * predate newer keys (`bottom_bar_bg_color`). Values are `#rrggbb` hex.
27
+ */
28
+ export type TelegramThemeParams = {
29
+ bg_color?: string;
30
+ text_color?: string;
31
+ hint_color?: string;
32
+ link_color?: string;
33
+ button_color?: string;
34
+ button_text_color?: string;
35
+ secondary_bg_color?: string;
36
+ header_bg_color?: string;
37
+ bottom_bar_bg_color?: string;
38
+ accent_text_color?: string;
39
+ section_bg_color?: string;
40
+ section_header_text_color?: string;
41
+ section_separator_color?: string;
42
+ subtitle_text_color?: string;
43
+ destructive_text_color?: string;
44
+ };
45
+ export type TelegramThemeParamName = keyof TelegramThemeParams;
46
+ /** Every `themeParams` key, in Telegram's documented order. */
47
+ export declare const TELEGRAM_THEME_PARAM_NAMES: readonly ["bg_color", "text_color", "hint_color", "link_color", "button_color", "button_text_color", "secondary_bg_color", "header_bg_color", "bottom_bar_bg_color", "accent_text_color", "section_bg_color", "section_header_text_color", "section_separator_color", "subtitle_text_color", "destructive_text_color"];
48
+ /** `themeParams` key → the `--tg-theme-*` CSS variable Telegram sets for it. */
49
+ export declare const TELEGRAM_THEME_CSS_VARS: {
50
+ readonly bg_color: "--tg-theme-bg-color";
51
+ readonly text_color: "--tg-theme-text-color";
52
+ readonly hint_color: "--tg-theme-hint-color";
53
+ readonly link_color: "--tg-theme-link-color";
54
+ readonly button_color: "--tg-theme-button-color";
55
+ readonly button_text_color: "--tg-theme-button-text-color";
56
+ readonly secondary_bg_color: "--tg-theme-secondary-bg-color";
57
+ readonly header_bg_color: "--tg-theme-header-bg-color";
58
+ readonly bottom_bar_bg_color: "--tg-theme-bottom-bar-bg-color";
59
+ readonly accent_text_color: "--tg-theme-accent-text-color";
60
+ readonly section_bg_color: "--tg-theme-section-bg-color";
61
+ readonly section_header_text_color: "--tg-theme-section-header-text-color";
62
+ readonly section_separator_color: "--tg-theme-section-separator-color";
63
+ readonly subtitle_text_color: "--tg-theme-subtitle-text-color";
64
+ readonly destructive_text_color: "--tg-theme-destructive-text-color";
65
+ };
66
+ /**
67
+ * `themeParams` key → DS paint token(s) `applyTelegramThemeParams` writes
68
+ * verbatim. Only pairs with a clear semantic fit are bridged; the rest stay
69
+ * readable through `TELEGRAM_THEME_CSS_VARS` for app-owned mapping.
70
+ *
71
+ * - `button_color` feeds the solid-fill role (`accent-track`: the primary
72
+ * button, progress and slider fills) and the legacy `primary` alias.
73
+ * - `button_text_color` feeds `accent-contrast` (text on that fill) and `on-primary`.
74
+ * - `link_color` and `accent_text_color` feed `accent-indicator` (links, active
75
+ * markers, accent foreground). Precedence: `accent_text_color` is applied
76
+ * after `link_color`, so the more specific param wins when both are present.
77
+ */
78
+ export declare const TELEGRAM_THEME_PARAM_BRIDGE: {
79
+ readonly bg_color: readonly ["--dsx-color-background"];
80
+ readonly text_color: readonly ["--dsx-color-on-background"];
81
+ readonly hint_color: readonly ["--dsx-color-on-surface-variant"];
82
+ readonly link_color: readonly ["--dsx-color-accent-indicator"];
83
+ readonly accent_text_color: readonly ["--dsx-color-accent-indicator"];
84
+ readonly button_color: readonly ["--dsx-color-primary", "--dsx-color-accent-track"];
85
+ readonly button_text_color: readonly ["--dsx-color-on-primary", "--dsx-color-accent-contrast"];
86
+ readonly secondary_bg_color: readonly ["--dsx-color-surface"];
87
+ readonly section_bg_color: readonly ["--dsx-color-surface-raised"];
88
+ readonly destructive_text_color: readonly ["--dsx-color-error"];
89
+ };
90
+ /**
91
+ * Tokens the bridge derives from a param instead of copying it. Telegram has
92
+ * no param for them, and leaving them would show the DS accent next to the
93
+ * Telegram one: the primary button's hover step (`accent-10`, 12% darker than
94
+ * `button_color`) and the soft accent surface behind selected rows and soft
95
+ * badges (`accent-surface`, `button_color` at 20% alpha, as the shipped accents do).
96
+ */
97
+ export declare const TELEGRAM_THEME_PARAM_DERIVED: {
98
+ readonly button_color: readonly ["--dsx-color-accent-10", "--dsx-color-accent-surface"];
99
+ };
100
+ export type ApplyTelegramThemeParamsOptions = {
101
+ /**
102
+ * DS density for the Mini App root. Mini Apps default to `compact`
103
+ * (small WebView, thumb reach); pass an explicit mode to override, or
104
+ * `false` to leave the attribute untouched. A `data-dsx-density` the app
105
+ * already set always wins over this default — `ThemeProvider` always sets
106
+ * one, so an app under it passes `density={TELEGRAM_MINI_APP_DENSITY_DEFAULT}` itself.
107
+ */
108
+ density?: 'comfortable' | 'compact' | false;
109
+ /**
110
+ * Write `data-tg-mini-app=""` on the root so `telegram.css` can scope its
111
+ * motion rules. Disable when the app manages its own marker.
112
+ */
113
+ markHost?: boolean;
114
+ };
115
+ /**
116
+ * Bridge Telegram `theme_params` into DS paint tokens on `root` (usually
117
+ * `document.documentElement`; `<body>` is covered with it). Writes are inline
118
+ * custom properties, so they beat stylesheet defaults without `!important`
119
+ * and vanish with the element. Unknown or non-hex values are skipped, never written.
120
+ */
121
+ export declare function applyTelegramThemeParams(root: HTMLElement, params: TelegramThemeParams, options?: ApplyTelegramThemeParamsOptions): void;
122
+ /** Remove everything `applyTelegramThemeParams` wrote (tokens, on every host, and the marker it set). */
123
+ export declare function clearTelegramThemeParams(root: HTMLElement): void;
124
+ //# sourceMappingURL=theme-params.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme-params.d.mts","sourceRoot":"","sources":["../../../src/foundations/telegram/theme-params.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,MAAM,MAAM,mBAAmB,GAAG,OAAO,GAAG,MAAM,CAAA;AAElD;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAC5B,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,yBAAyB,CAAC,EAAE,MAAM,CAAA;IAClC,uBAAuB,CAAC,EAAE,MAAM,CAAA;IAChC,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAC5B,sBAAsB,CAAC,EAAE,MAAM,CAAA;CAChC,CAAA;AAED,MAAM,MAAM,sBAAsB,GAAG,MAAM,mBAAmB,CAAA;AAE9D,+DAA+D;AAC/D,eAAO,MAAM,0BAA0B,wTAgBe,CAAA;AAEtD,gFAAgF;AAChF,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;CAgBuC,CAAA;AAE3E;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,2BAA2B;;;;;;;;;;;CAWuC,CAAA;AAE/E;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B;;CAEsC,CAAA;AAkE/E,MAAM,MAAM,+BAA+B,GAAG;IAC5C;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,aAAa,GAAG,SAAS,GAAG,KAAK,CAAA;IAC3C;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAOD;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,WAAW,EACjB,MAAM,EAAE,mBAAmB,EAC3B,OAAO,GAAE,+BAAoC,GAC5C,IAAI,CAwBN;AAED,yGAAyG;AACzG,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,CAehE"}
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Telegram Mini App `theme_params` contract and its bridge into DS tokens.
3
+ *
4
+ * Telegram publishes the client's palette two ways: as a `themeParams`
5
+ * object on `Telegram.WebApp` (snake_case hex colors, e.g. `bg_color`) and
6
+ * as CSS custom properties on `:root` (`--tg-theme-bg-color`, …). This
7
+ * module types the params object, names the CSS variables, and maps each
8
+ * param onto the DS token it feeds — without taking a Telegram SDK
9
+ * dependency (same stance as `ThemeProvider`'s system-mode handling).
10
+ *
11
+ * Mode ownership stays with `Theme` / `ThemeProvider`: this bridge only
12
+ * writes paint tokens on the Mini App root. `colorScheme` sync (including
13
+ * the `themeChanged` subscription) already lives in `ThemeProvider`.
14
+ *
15
+ * The bridge is the one path from Telegram's palette to DS tokens (G-35:
16
+ * `telegram.css` carries no colour rules). It writes the accent *roles* the
17
+ * components read (`track`, `contrast`, `indicator`, `surface`, ADR 003) next
18
+ * to the legacy `primary` pair, and it writes on both `<html>` and `<body>`
19
+ * because `Theme` mirrors its data attributes on both and the theme rules
20
+ * re-declare every token on `<body>` (G-33, G-34).
21
+ */
22
+ export type TelegramColorScheme = 'light' | 'dark';
23
+ /**
24
+ * Subset of `Telegram.WebApp.themeParams` the bridge consumes. Every field
25
+ * is optional — Telegram omits keys it has no value for, and older clients
26
+ * predate newer keys (`bottom_bar_bg_color`). Values are `#rrggbb` hex.
27
+ */
28
+ export type TelegramThemeParams = {
29
+ bg_color?: string;
30
+ text_color?: string;
31
+ hint_color?: string;
32
+ link_color?: string;
33
+ button_color?: string;
34
+ button_text_color?: string;
35
+ secondary_bg_color?: string;
36
+ header_bg_color?: string;
37
+ bottom_bar_bg_color?: string;
38
+ accent_text_color?: string;
39
+ section_bg_color?: string;
40
+ section_header_text_color?: string;
41
+ section_separator_color?: string;
42
+ subtitle_text_color?: string;
43
+ destructive_text_color?: string;
44
+ };
45
+ export type TelegramThemeParamName = keyof TelegramThemeParams;
46
+ /** Every `themeParams` key, in Telegram's documented order. */
47
+ export declare const TELEGRAM_THEME_PARAM_NAMES: readonly ["bg_color", "text_color", "hint_color", "link_color", "button_color", "button_text_color", "secondary_bg_color", "header_bg_color", "bottom_bar_bg_color", "accent_text_color", "section_bg_color", "section_header_text_color", "section_separator_color", "subtitle_text_color", "destructive_text_color"];
48
+ /** `themeParams` key → the `--tg-theme-*` CSS variable Telegram sets for it. */
49
+ export declare const TELEGRAM_THEME_CSS_VARS: {
50
+ readonly bg_color: "--tg-theme-bg-color";
51
+ readonly text_color: "--tg-theme-text-color";
52
+ readonly hint_color: "--tg-theme-hint-color";
53
+ readonly link_color: "--tg-theme-link-color";
54
+ readonly button_color: "--tg-theme-button-color";
55
+ readonly button_text_color: "--tg-theme-button-text-color";
56
+ readonly secondary_bg_color: "--tg-theme-secondary-bg-color";
57
+ readonly header_bg_color: "--tg-theme-header-bg-color";
58
+ readonly bottom_bar_bg_color: "--tg-theme-bottom-bar-bg-color";
59
+ readonly accent_text_color: "--tg-theme-accent-text-color";
60
+ readonly section_bg_color: "--tg-theme-section-bg-color";
61
+ readonly section_header_text_color: "--tg-theme-section-header-text-color";
62
+ readonly section_separator_color: "--tg-theme-section-separator-color";
63
+ readonly subtitle_text_color: "--tg-theme-subtitle-text-color";
64
+ readonly destructive_text_color: "--tg-theme-destructive-text-color";
65
+ };
66
+ /**
67
+ * `themeParams` key → DS paint token(s) `applyTelegramThemeParams` writes
68
+ * verbatim. Only pairs with a clear semantic fit are bridged; the rest stay
69
+ * readable through `TELEGRAM_THEME_CSS_VARS` for app-owned mapping.
70
+ *
71
+ * - `button_color` feeds the solid-fill role (`accent-track`: the primary
72
+ * button, progress and slider fills) and the legacy `primary` alias.
73
+ * - `button_text_color` feeds `accent-contrast` (text on that fill) and `on-primary`.
74
+ * - `link_color` and `accent_text_color` feed `accent-indicator` (links, active
75
+ * markers, accent foreground). Precedence: `accent_text_color` is applied
76
+ * after `link_color`, so the more specific param wins when both are present.
77
+ */
78
+ export declare const TELEGRAM_THEME_PARAM_BRIDGE: {
79
+ readonly bg_color: readonly ["--dsx-color-background"];
80
+ readonly text_color: readonly ["--dsx-color-on-background"];
81
+ readonly hint_color: readonly ["--dsx-color-on-surface-variant"];
82
+ readonly link_color: readonly ["--dsx-color-accent-indicator"];
83
+ readonly accent_text_color: readonly ["--dsx-color-accent-indicator"];
84
+ readonly button_color: readonly ["--dsx-color-primary", "--dsx-color-accent-track"];
85
+ readonly button_text_color: readonly ["--dsx-color-on-primary", "--dsx-color-accent-contrast"];
86
+ readonly secondary_bg_color: readonly ["--dsx-color-surface"];
87
+ readonly section_bg_color: readonly ["--dsx-color-surface-raised"];
88
+ readonly destructive_text_color: readonly ["--dsx-color-error"];
89
+ };
90
+ /**
91
+ * Tokens the bridge derives from a param instead of copying it. Telegram has
92
+ * no param for them, and leaving them would show the DS accent next to the
93
+ * Telegram one: the primary button's hover step (`accent-10`, 12% darker than
94
+ * `button_color`) and the soft accent surface behind selected rows and soft
95
+ * badges (`accent-surface`, `button_color` at 20% alpha, as the shipped accents do).
96
+ */
97
+ export declare const TELEGRAM_THEME_PARAM_DERIVED: {
98
+ readonly button_color: readonly ["--dsx-color-accent-10", "--dsx-color-accent-surface"];
99
+ };
100
+ export type ApplyTelegramThemeParamsOptions = {
101
+ /**
102
+ * DS density for the Mini App root. Mini Apps default to `compact`
103
+ * (small WebView, thumb reach); pass an explicit mode to override, or
104
+ * `false` to leave the attribute untouched. A `data-dsx-density` the app
105
+ * already set always wins over this default — `ThemeProvider` always sets
106
+ * one, so an app under it passes `density={TELEGRAM_MINI_APP_DENSITY_DEFAULT}` itself.
107
+ */
108
+ density?: 'comfortable' | 'compact' | false;
109
+ /**
110
+ * Write `data-tg-mini-app=""` on the root so `telegram.css` can scope its
111
+ * motion rules. Disable when the app manages its own marker.
112
+ */
113
+ markHost?: boolean;
114
+ };
115
+ /**
116
+ * Bridge Telegram `theme_params` into DS paint tokens on `root` (usually
117
+ * `document.documentElement`; `<body>` is covered with it). Writes are inline
118
+ * custom properties, so they beat stylesheet defaults without `!important`
119
+ * and vanish with the element. Unknown or non-hex values are skipped, never written.
120
+ */
121
+ export declare function applyTelegramThemeParams(root: HTMLElement, params: TelegramThemeParams, options?: ApplyTelegramThemeParamsOptions): void;
122
+ /** Remove everything `applyTelegramThemeParams` wrote (tokens, on every host, and the marker it set). */
123
+ export declare function clearTelegramThemeParams(root: HTMLElement): void;
124
+ //# sourceMappingURL=theme-params.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme-params.d.ts","sourceRoot":"","sources":["../../../src/foundations/telegram/theme-params.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;G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IAAI,EAAE,WAAW,EACjB,MAAM,EAAE,mBAAmB,EAC3B,OAAO,GAAE,+BAAoC,GAC5C,IAAI,CAwBN;AAED,yGAAyG;AACzG,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,CAehE"}
@@ -0,0 +1,140 @@
1
+ const TELEGRAM_THEME_PARAM_NAMES = [
2
+ "bg_color",
3
+ "text_color",
4
+ "hint_color",
5
+ "link_color",
6
+ "button_color",
7
+ "button_text_color",
8
+ "secondary_bg_color",
9
+ "header_bg_color",
10
+ "bottom_bar_bg_color",
11
+ "accent_text_color",
12
+ "section_bg_color",
13
+ "section_header_text_color",
14
+ "section_separator_color",
15
+ "subtitle_text_color",
16
+ "destructive_text_color"
17
+ ];
18
+ const TELEGRAM_THEME_CSS_VARS = {
19
+ bg_color: "--tg-theme-bg-color",
20
+ text_color: "--tg-theme-text-color",
21
+ hint_color: "--tg-theme-hint-color",
22
+ link_color: "--tg-theme-link-color",
23
+ button_color: "--tg-theme-button-color",
24
+ button_text_color: "--tg-theme-button-text-color",
25
+ secondary_bg_color: "--tg-theme-secondary-bg-color",
26
+ header_bg_color: "--tg-theme-header-bg-color",
27
+ bottom_bar_bg_color: "--tg-theme-bottom-bar-bg-color",
28
+ accent_text_color: "--tg-theme-accent-text-color",
29
+ section_bg_color: "--tg-theme-section-bg-color",
30
+ section_header_text_color: "--tg-theme-section-header-text-color",
31
+ section_separator_color: "--tg-theme-section-separator-color",
32
+ subtitle_text_color: "--tg-theme-subtitle-text-color",
33
+ destructive_text_color: "--tg-theme-destructive-text-color"
34
+ };
35
+ const TELEGRAM_THEME_PARAM_BRIDGE = {
36
+ bg_color: ["--dsx-color-background"],
37
+ text_color: ["--dsx-color-on-background"],
38
+ hint_color: ["--dsx-color-on-surface-variant"],
39
+ link_color: ["--dsx-color-accent-indicator"],
40
+ accent_text_color: ["--dsx-color-accent-indicator"],
41
+ button_color: ["--dsx-color-primary", "--dsx-color-accent-track"],
42
+ button_text_color: ["--dsx-color-on-primary", "--dsx-color-accent-contrast"],
43
+ secondary_bg_color: ["--dsx-color-surface"],
44
+ section_bg_color: ["--dsx-color-surface-raised"],
45
+ destructive_text_color: ["--dsx-color-error"]
46
+ };
47
+ const TELEGRAM_THEME_PARAM_DERIVED = {
48
+ button_color: ["--dsx-color-accent-10", "--dsx-color-accent-surface"]
49
+ };
50
+ const HOVER_SHADE = 0.12;
51
+ const SURFACE_ALPHA = 0.2;
52
+ const TELEGRAM_BRIDGE_ORDER = [
53
+ "bg_color",
54
+ "text_color",
55
+ "hint_color",
56
+ "link_color",
57
+ "accent_text_color",
58
+ "button_color",
59
+ "button_text_color",
60
+ "secondary_bg_color",
61
+ "section_bg_color",
62
+ "destructive_text_color"
63
+ ];
64
+ function isHexColor(value) {
65
+ return /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(value);
66
+ }
67
+ function parseHex(value) {
68
+ const digits = value.slice(1);
69
+ const full = digits.length === 3 ? [...digits].map((digit) => digit + digit).join("") : digits;
70
+ return [0, 2, 4].map((offset) => parseInt(full.slice(offset, offset + 2), 16));
71
+ }
72
+ function toHex(channels) {
73
+ return `#${channels.map((channel) => channel.toString(16).padStart(2, "0")).join("")}`;
74
+ }
75
+ const DERIVE_FROM_BUTTON_COLOR = {
76
+ "--dsx-color-accent-10": (rgb) => toHex(rgb.map((channel) => Math.round(channel * (1 - HOVER_SHADE)))),
77
+ "--dsx-color-accent-surface": ([red, green, blue]) => `rgba(${red}, ${green}, ${blue}, ${SURFACE_ALPHA})`
78
+ };
79
+ function writesFor(name, value) {
80
+ const writes = TELEGRAM_THEME_PARAM_BRIDGE[name].map((token) => [token, value]);
81
+ if (name === "button_color") {
82
+ const rgb = parseHex(value);
83
+ for (const token of TELEGRAM_THEME_PARAM_DERIVED.button_color) {
84
+ writes.push([token, DERIVE_FROM_BUTTON_COLOR[token](rgb)]);
85
+ }
86
+ }
87
+ return writes;
88
+ }
89
+ function themeHosts(root) {
90
+ const { documentElement, body } = root.ownerDocument;
91
+ return root === documentElement && body ? [root, body] : [root];
92
+ }
93
+ const DEFAULT_APPLY_OPTIONS = {
94
+ density: "compact",
95
+ markHost: true
96
+ };
97
+ function applyTelegramThemeParams(root, params, options = {}) {
98
+ const { density, markHost } = { ...DEFAULT_APPLY_OPTIONS, ...options };
99
+ const hosts = themeHosts(root);
100
+ if (markHost && !root.hasAttribute("data-tg-mini-app")) {
101
+ root.setAttribute("data-tg-mini-app", "");
102
+ }
103
+ if (density !== false && !root.hasAttribute("data-dsx-density")) {
104
+ root.setAttribute("data-dsx-density", density);
105
+ }
106
+ for (const name of TELEGRAM_BRIDGE_ORDER) {
107
+ const value = params[name];
108
+ if (typeof value !== "string" || !isHexColor(value)) {
109
+ continue;
110
+ }
111
+ for (const [token, tokenValue] of writesFor(name, value)) {
112
+ for (const host of hosts) {
113
+ host.style.setProperty(token, tokenValue);
114
+ }
115
+ }
116
+ }
117
+ }
118
+ function clearTelegramThemeParams(root) {
119
+ const targets = /* @__PURE__ */ new Set();
120
+ for (const names of [...Object.values(TELEGRAM_THEME_PARAM_BRIDGE), ...Object.values(TELEGRAM_THEME_PARAM_DERIVED)]) {
121
+ for (const target of names) {
122
+ targets.add(target);
123
+ }
124
+ }
125
+ for (const host of themeHosts(root)) {
126
+ for (const target of targets) {
127
+ host.style.removeProperty(target);
128
+ }
129
+ }
130
+ root.removeAttribute("data-tg-mini-app");
131
+ }
132
+ export {
133
+ TELEGRAM_THEME_CSS_VARS,
134
+ TELEGRAM_THEME_PARAM_BRIDGE,
135
+ TELEGRAM_THEME_PARAM_DERIVED,
136
+ TELEGRAM_THEME_PARAM_NAMES,
137
+ applyTelegramThemeParams,
138
+ clearTelegramThemeParams
139
+ };
140
+ //# sourceMappingURL=theme-params.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/foundations/telegram/theme-params.ts"],
4
+ "sourcesContent": ["/**\n * Telegram Mini App `theme_params` contract and its bridge into DS tokens.\n *\n * Telegram publishes the client's palette two ways: as a `themeParams`\n * object on `Telegram.WebApp` (snake_case hex colors, e.g. `bg_color`) and\n * as CSS custom properties on `:root` (`--tg-theme-bg-color`, \u2026). This\n * module types the params object, names the CSS variables, and maps each\n * param onto the DS token it feeds \u2014 without taking a Telegram SDK\n * dependency (same stance as `ThemeProvider`'s system-mode handling).\n *\n * Mode ownership stays with `Theme` / `ThemeProvider`: this bridge only\n * writes paint tokens on the Mini App root. `colorScheme` sync (including\n * the `themeChanged` subscription) already lives in `ThemeProvider`.\n *\n * The bridge is the one path from Telegram's palette to DS tokens (G-35:\n * `telegram.css` carries no colour rules). It writes the accent *roles* the\n * components read (`track`, `contrast`, `indicator`, `surface`, ADR 003) next\n * to the legacy `primary` pair, and it writes on both `<html>` and `<body>`\n * because `Theme` mirrors its data attributes on both and the theme rules\n * re-declare every token on `<body>` (G-33, G-34).\n */\n\nexport type TelegramColorScheme = 'light' | 'dark'\n\n/**\n * Subset of `Telegram.WebApp.themeParams` the bridge consumes. Every field\n * is optional \u2014 Telegram omits keys it has no value for, and older clients\n * predate newer keys (`bottom_bar_bg_color`). Values are `#rrggbb` hex.\n */\nexport type TelegramThemeParams = {\n bg_color?: string\n text_color?: string\n hint_color?: string\n link_color?: string\n button_color?: string\n button_text_color?: string\n secondary_bg_color?: string\n header_bg_color?: string\n bottom_bar_bg_color?: string\n accent_text_color?: string\n section_bg_color?: string\n section_header_text_color?: string\n section_separator_color?: string\n subtitle_text_color?: string\n destructive_text_color?: string\n}\n\nexport type TelegramThemeParamName = keyof TelegramThemeParams\n\n/** Every `themeParams` key, in Telegram's documented order. */\nexport const TELEGRAM_THEME_PARAM_NAMES = [\n 'bg_color',\n 'text_color',\n 'hint_color',\n 'link_color',\n 'button_color',\n 'button_text_color',\n 'secondary_bg_color',\n 'header_bg_color',\n 'bottom_bar_bg_color',\n 'accent_text_color',\n 'section_bg_color',\n 'section_header_text_color',\n 'section_separator_color',\n 'subtitle_text_color',\n 'destructive_text_color',\n] as const satisfies readonly TelegramThemeParamName[]\n\n/** `themeParams` key \u2192 the `--tg-theme-*` CSS variable Telegram sets for it. */\nexport const TELEGRAM_THEME_CSS_VARS = {\n bg_color: '--tg-theme-bg-color',\n text_color: '--tg-theme-text-color',\n hint_color: '--tg-theme-hint-color',\n link_color: '--tg-theme-link-color',\n button_color: '--tg-theme-button-color',\n button_text_color: '--tg-theme-button-text-color',\n secondary_bg_color: '--tg-theme-secondary-bg-color',\n header_bg_color: '--tg-theme-header-bg-color',\n bottom_bar_bg_color: '--tg-theme-bottom-bar-bg-color',\n accent_text_color: '--tg-theme-accent-text-color',\n section_bg_color: '--tg-theme-section-bg-color',\n section_header_text_color: '--tg-theme-section-header-text-color',\n section_separator_color: '--tg-theme-section-separator-color',\n subtitle_text_color: '--tg-theme-subtitle-text-color',\n destructive_text_color: '--tg-theme-destructive-text-color',\n} as const satisfies Record<TelegramThemeParamName, `--tg-theme-${string}`>\n\n/**\n * `themeParams` key \u2192 DS paint token(s) `applyTelegramThemeParams` writes\n * verbatim. Only pairs with a clear semantic fit are bridged; the rest stay\n * readable through `TELEGRAM_THEME_CSS_VARS` for app-owned mapping.\n *\n * - `button_color` feeds the solid-fill role (`accent-track`: the primary\n * button, progress and slider fills) and the legacy `primary` alias.\n * - `button_text_color` feeds `accent-contrast` (text on that fill) and `on-primary`.\n * - `link_color` and `accent_text_color` feed `accent-indicator` (links, active\n * markers, accent foreground). Precedence: `accent_text_color` is applied\n * after `link_color`, so the more specific param wins when both are present.\n */\nexport const TELEGRAM_THEME_PARAM_BRIDGE = {\n bg_color: ['--dsx-color-background'],\n text_color: ['--dsx-color-on-background'],\n hint_color: ['--dsx-color-on-surface-variant'],\n link_color: ['--dsx-color-accent-indicator'],\n accent_text_color: ['--dsx-color-accent-indicator'],\n button_color: ['--dsx-color-primary', '--dsx-color-accent-track'],\n button_text_color: ['--dsx-color-on-primary', '--dsx-color-accent-contrast'],\n secondary_bg_color: ['--dsx-color-surface'],\n section_bg_color: ['--dsx-color-surface-raised'],\n destructive_text_color: ['--dsx-color-error'],\n} as const satisfies Partial<Record<TelegramThemeParamName, readonly string[]>>\n\n/**\n * Tokens the bridge derives from a param instead of copying it. Telegram has\n * no param for them, and leaving them would show the DS accent next to the\n * Telegram one: the primary button's hover step (`accent-10`, 12% darker than\n * `button_color`) and the soft accent surface behind selected rows and soft\n * badges (`accent-surface`, `button_color` at 20% alpha, as the shipped accents do).\n */\nexport const TELEGRAM_THEME_PARAM_DERIVED = {\n button_color: ['--dsx-color-accent-10', '--dsx-color-accent-surface'],\n} as const satisfies Partial<Record<TelegramThemeParamName, readonly string[]>>\n\nconst HOVER_SHADE = 0.12\nconst SURFACE_ALPHA = 0.2\n\ntype Rgb = readonly [number, number, number]\n\n/** Application order for the bridge: `accent_text_color` after `link_color` (the precedence note above). */\nconst TELEGRAM_BRIDGE_ORDER: Array<keyof typeof TELEGRAM_THEME_PARAM_BRIDGE> = [\n 'bg_color',\n 'text_color',\n 'hint_color',\n 'link_color',\n 'accent_text_color',\n 'button_color',\n 'button_text_color',\n 'secondary_bg_color',\n 'section_bg_color',\n 'destructive_text_color',\n]\n\nfunction isHexColor(value: string): boolean {\n return /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(value)\n}\n\nfunction parseHex(value: string): Rgb {\n const digits = value.slice(1)\n const full = digits.length === 3 ? [...digits].map((digit) => digit + digit).join('') : digits\n return [0, 2, 4].map((offset) => parseInt(full.slice(offset, offset + 2), 16)) as unknown as Rgb\n}\n\nfunction toHex(channels: Rgb): string {\n return `#${channels.map((channel) => channel.toString(16).padStart(2, '0')).join('')}`\n}\n\nconst DERIVE_FROM_BUTTON_COLOR: Record<(typeof TELEGRAM_THEME_PARAM_DERIVED.button_color)[number], (rgb: Rgb) => string> = {\n '--dsx-color-accent-10': (rgb) =>\n toHex(rgb.map((channel) => Math.round(channel * (1 - HOVER_SHADE))) as unknown as Rgb),\n '--dsx-color-accent-surface': ([red, green, blue]) => `rgba(${red}, ${green}, ${blue}, ${SURFACE_ALPHA})`,\n}\n\n/** Every `[token, value]` pair one valid param writes. */\nfunction writesFor(name: keyof typeof TELEGRAM_THEME_PARAM_BRIDGE, value: string): Array<[string, string]> {\n const writes: Array<[string, string]> = TELEGRAM_THEME_PARAM_BRIDGE[name].map((token) => [token, value])\n\n if (name === 'button_color') {\n const rgb = parseHex(value)\n for (const token of TELEGRAM_THEME_PARAM_DERIVED.button_color) {\n writes.push([token, DERIVE_FROM_BUTTON_COLOR[token](rgb)])\n }\n }\n\n return writes\n}\n\n/**\n * The elements that carry the DS theme attributes. `Theme` mirrors them on\n * `<html>` and `<body>`, and the theme rules re-declare every token on each\n * element that has them, so a value written only on `<html>` never reaches a\n * component under `<body>`. Given `<html>`, write on both; given anything else, on it alone.\n */\nfunction themeHosts(root: HTMLElement): HTMLElement[] {\n const { documentElement, body } = root.ownerDocument\n return root === documentElement && body ? [root, body] : [root]\n}\n\nexport type ApplyTelegramThemeParamsOptions = {\n /**\n * DS density for the Mini App root. Mini Apps default to `compact`\n * (small WebView, thumb reach); pass an explicit mode to override, or\n * `false` to leave the attribute untouched. A `data-dsx-density` the app\n * already set always wins over this default \u2014 `ThemeProvider` always sets\n * one, so an app under it passes `density={TELEGRAM_MINI_APP_DENSITY_DEFAULT}` itself.\n */\n density?: 'comfortable' | 'compact' | false\n /**\n * Write `data-tg-mini-app=\"\"` on the root so `telegram.css` can scope its\n * motion rules. Disable when the app manages its own marker.\n */\n markHost?: boolean\n}\n\nconst DEFAULT_APPLY_OPTIONS = {\n density: 'compact',\n markHost: true,\n} as const satisfies Required<ApplyTelegramThemeParamsOptions>\n\n/**\n * Bridge Telegram `theme_params` into DS paint tokens on `root` (usually\n * `document.documentElement`; `<body>` is covered with it). Writes are inline\n * custom properties, so they beat stylesheet defaults without `!important`\n * and vanish with the element. Unknown or non-hex values are skipped, never written.\n */\nexport function applyTelegramThemeParams(\n root: HTMLElement,\n params: TelegramThemeParams,\n options: ApplyTelegramThemeParamsOptions = {},\n): void {\n const { density, markHost } = { ...DEFAULT_APPLY_OPTIONS, ...options }\n const hosts = themeHosts(root)\n\n if (markHost && !root.hasAttribute('data-tg-mini-app')) {\n root.setAttribute('data-tg-mini-app', '')\n }\n\n if (density !== false && !root.hasAttribute('data-dsx-density')) {\n root.setAttribute('data-dsx-density', density)\n }\n\n for (const name of TELEGRAM_BRIDGE_ORDER) {\n const value = params[name]\n if (typeof value !== 'string' || !isHexColor(value)) {\n continue\n }\n\n for (const [token, tokenValue] of writesFor(name, value)) {\n for (const host of hosts) {\n host.style.setProperty(token, tokenValue)\n }\n }\n }\n}\n\n/** Remove everything `applyTelegramThemeParams` wrote (tokens, on every host, and the marker it set). */\nexport function clearTelegramThemeParams(root: HTMLElement): void {\n const targets = new Set<string>()\n for (const names of [...Object.values(TELEGRAM_THEME_PARAM_BRIDGE), ...Object.values(TELEGRAM_THEME_PARAM_DERIVED)]) {\n for (const target of names) {\n targets.add(target)\n }\n }\n\n for (const host of themeHosts(root)) {\n for (const target of targets) {\n host.style.removeProperty(target)\n }\n }\n\n root.removeAttribute('data-tg-mini-app')\n}\n"],
5
+ "mappings": "AAkDO,MAAM,6BAA6B;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAGO,MAAM,0BAA0B;AAAA,EACrC,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,cAAc;AAAA,EACd,mBAAmB;AAAA,EACnB,oBAAoB;AAAA,EACpB,iBAAiB;AAAA,EACjB,qBAAqB;AAAA,EACrB,mBAAmB;AAAA,EACnB,kBAAkB;AAAA,EAClB,2BAA2B;AAAA,EAC3B,yBAAyB;AAAA,EACzB,qBAAqB;AAAA,EACrB,wBAAwB;AAC1B;AAcO,M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;AACxB,aAAK,MAAM,YAAY,OAAO,UAAU;AAAA,MAC1C;AAAA,IACF;AAAA,EACF;AACF;AAGO,SAAS,yBAAyB,MAAyB;AAChE,QAAM,UAAU,oBAAI,IAAY;AAChC,aAAW,SAAS,CAAC,GAAG,OAAO,OAAO,2BAA2B,GAAG,GAAG,OAAO,OAAO,4BAA4B,CAAC,GAAG;AACnH,eAAW,UAAU,OAAO;AAC1B,cAAQ,IAAI,MAAM;AAAA,IACpB;AAAA,EACF;AAEA,aAAW,QAAQ,WAAW,IAAI,GAAG;AACnC,eAAW,UAAU,SAAS;AAC5B,WAAK,MAAM,eAAe,MAAM;AAAA,IAClC;AAAA,EACF;AAEA,OAAK,gBAAgB,kBAAkB;AACzC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var viewport_exports = {};
20
+ __export(viewport_exports, {
21
+ TELEGRAM_COLOR_SCHEME_VAR: () => TELEGRAM_COLOR_SCHEME_VAR,
22
+ TELEGRAM_CONTENT_SAFE_AREA_VARS: () => TELEGRAM_CONTENT_SAFE_AREA_VARS,
23
+ TELEGRAM_MINI_APP_ATTRIBUTE: () => TELEGRAM_MINI_APP_ATTRIBUTE,
24
+ TELEGRAM_MINI_APP_DENSITY_DEFAULT: () => TELEGRAM_MINI_APP_DENSITY_DEFAULT,
25
+ TELEGRAM_SAFE_AREA_VARS: () => TELEGRAM_SAFE_AREA_VARS,
26
+ TELEGRAM_VIEWPORT_HEIGHT_VAR: () => TELEGRAM_VIEWPORT_HEIGHT_VAR,
27
+ TELEGRAM_VIEWPORT_STABLE_HEIGHT_VAR: () => TELEGRAM_VIEWPORT_STABLE_HEIGHT_VAR,
28
+ isTelegramWebView: () => isTelegramWebView,
29
+ observeTelegramHost: () => observeTelegramHost
30
+ });
31
+ module.exports = __toCommonJS(viewport_exports);
32
+ const TELEGRAM_VIEWPORT_HEIGHT_VAR = "--tg-viewport-height";
33
+ const TELEGRAM_VIEWPORT_STABLE_HEIGHT_VAR = "--tg-viewport-stable-height";
34
+ const TELEGRAM_COLOR_SCHEME_VAR = "--tg-color-scheme";
35
+ const TELEGRAM_SAFE_AREA_VARS = {
36
+ top: "--tg-safe-area-inset-top",
37
+ right: "--tg-safe-area-inset-right",
38
+ bottom: "--tg-safe-area-inset-bottom",
39
+ left: "--tg-safe-area-inset-left"
40
+ };
41
+ const TELEGRAM_CONTENT_SAFE_AREA_VARS = {
42
+ top: "--tg-content-safe-area-inset-top",
43
+ right: "--tg-content-safe-area-inset-right",
44
+ bottom: "--tg-content-safe-area-inset-bottom",
45
+ left: "--tg-content-safe-area-inset-left"
46
+ };
47
+ const TELEGRAM_MINI_APP_DENSITY_DEFAULT = "compact";
48
+ const TELEGRAM_MINI_APP_ATTRIBUTE = "data-tg-mini-app";
49
+ function getTelegramWebApp() {
50
+ if (typeof window === "undefined") {
51
+ return void 0;
52
+ }
53
+ return window.Telegram?.WebApp;
54
+ }
55
+ function isTelegramWebView() {
56
+ return getTelegramWebApp() !== void 0;
57
+ }
58
+ function observeTelegramHost(apply, options = {}) {
59
+ const { themeChanged = true, viewportChanged = true } = options;
60
+ const webApp = getTelegramWebApp();
61
+ if (!webApp?.onEvent) {
62
+ return () => {
63
+ };
64
+ }
65
+ const subscriptions = [];
66
+ if (themeChanged) {
67
+ subscriptions.push(["themeChanged", apply]);
68
+ }
69
+ if (viewportChanged) {
70
+ subscriptions.push(["viewportChanged", apply]);
71
+ }
72
+ for (const [type, listener] of subscriptions) {
73
+ webApp.onEvent(type, listener);
74
+ }
75
+ return () => {
76
+ for (const [type, listener] of subscriptions) {
77
+ webApp.offEvent?.(type, listener);
78
+ }
79
+ };
80
+ }
81
+ //# sourceMappingURL=viewport.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/foundations/telegram/viewport.ts"],
4
+ "sourcesContent": ["/**\n * Telegram Mini App viewport contract: the CSS variables Telegram's script\n * sets on `:root` as soon as it loads (no `ready()` call is needed, and\n * Telegram keeps them current on `viewportChanged` / `safeAreaChanged` /\n * `contentSafeAreaChanged`), plus the DS-side defaults for hosted\n * (non-Telegram) rendering. CSS that reads them needs no JS subscription;\n * `observeTelegramHost` only re-runs the colour bridge.\n *\n * - `--tg-viewport-height` tracks the full WebView height, including areas\n * temporarily covered (e.g. by the on-screen keyboard).\n * - `--tg-viewport-stable-height` excludes transient shrinking \u2014 the value\n * full-height panels should bind to (already the default for `body` and\n * full Drawers via the `globals.css` compliance layer).\n * - `--tg-safe-area-inset-*` / `--tg-content-safe-area-inset-*` carry the\n * notch / status-bar / home-indicator regions; the content variant is the\n * inset inside Telegram's own bottom chrome.\n *\n * Every `var(--tg-\u2026)` reference in `telegram.css` carries a standard-web\n * fallback, so the stylesheet is a no-op outside a Telegram WebView. The\n * `qa:telegram-vars` package check enforces that invariant.\n */\n\nimport type { DensityMode } from '../../layout/responsive.props'\n\nexport const TELEGRAM_VIEWPORT_HEIGHT_VAR = '--tg-viewport-height' as const\nexport const TELEGRAM_VIEWPORT_STABLE_HEIGHT_VAR = '--tg-viewport-stable-height' as const\nexport const TELEGRAM_COLOR_SCHEME_VAR = '--tg-color-scheme' as const\n\nexport const TELEGRAM_SAFE_AREA_VARS = {\n top: '--tg-safe-area-inset-top',\n right: '--tg-safe-area-inset-right',\n bottom: '--tg-safe-area-inset-bottom',\n left: '--tg-safe-area-inset-left',\n} as const\n\nexport const TELEGRAM_CONTENT_SAFE_AREA_VARS = {\n top: '--tg-content-safe-area-inset-top',\n right: '--tg-content-safe-area-inset-right',\n bottom: '--tg-content-safe-area-inset-bottom',\n left: '--tg-content-safe-area-inset-left',\n} as const\n\n/** DS density a Mini App root defaults to \u2014 small WebView, thumb reach. */\nexport const TELEGRAM_MINI_APP_DENSITY_DEFAULT: DensityMode = 'compact'\n\n/** Host marker attribute the bridge sets and `telegram.css` scopes to. */\nexport const TELEGRAM_MINI_APP_ATTRIBUTE = 'data-tg-mini-app' as const\n\ntype MinimalTelegramWebApp = {\n colorScheme?: 'light' | 'dark'\n viewportHeight?: number\n viewportStableHeight?: number\n isExpanded?: boolean\n onEvent?: (type: string, listener: () => void) => void\n offEvent?: (type: string, listener: () => void) => void\n}\n\nfunction getTelegramWebApp(): MinimalTelegramWebApp | undefined {\n if (typeof window === 'undefined') {\n return undefined\n }\n\n return (window as typeof window & { Telegram?: { WebApp?: MinimalTelegramWebApp } }).Telegram?.WebApp\n}\n\n/** True inside a Telegram Mini App WebView (real or stubbed in tests). */\nexport function isTelegramWebView(): boolean {\n return getTelegramWebApp() !== undefined\n}\n\nexport type ObserveTelegramHostOptions = {\n /** Re-run the bridge when Telegram fires `themeChanged`. Default true. */\n themeChanged?: boolean\n /** Re-run the bridge when Telegram fires `viewportChanged`. Default true. */\n viewportChanged?: boolean\n}\n\n/**\n * Keep the bridge output fresh across a Mini App session: re-runs `apply`\n * on Telegram's `themeChanged` / `viewportChanged` events. Returns a\n * cleanup that detaches both listeners. No-op (returns a no-op cleanup)\n * outside a Telegram WebView or when the host exposes no event API.\n */\nexport function observeTelegramHost(\n apply: () => void,\n options: ObserveTelegramHostOptions = {},\n): () => void {\n const { themeChanged = true, viewportChanged = true } = options\n const webApp = getTelegramWebApp()\n if (!webApp?.onEvent) {\n return () => {}\n }\n\n const subscriptions: Array<[string, () => void]> = []\n if (themeChanged) {\n subscriptions.push(['themeChanged', apply])\n }\n if (viewportChanged) {\n subscriptions.push(['viewportChanged', apply])\n }\n\n for (const [type, listener] of subscriptions) {\n webApp.onEvent(type, listener)\n }\n\n return () => {\n for (const [type, listener] of subscriptions) {\n webApp.offEvent?.(type, listener)\n }\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwBO,MAAM,+BAA+B;AACrC,MAAM,sCAAsC;AAC5C,MAAM,4BAA4B;AAElC,MAAM,0BAA0B;AAAA,EACrC,KAAK;AAAA,EACL,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,MAAM;AACR;AAEO,MAAM,kCAAkC;AAAA,EAC7C,KAAK;AAAA,EACL,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,MAAM;AACR;AAGO,MAAM,oCAAiD;AAGvD,MAAM,8BAA8B;AAW3C,SAAS,oBAAuD;AAC9D,MAAI,OAAO,WAAW,aAAa;AACjC,WAAO;AAAA,EACT;AAEA,SAAQ,OAA6E,UAAU;AACjG;AAGO,SAAS,oBAA6B;AAC3C,SAAO,kBAAkB,MAAM;AACjC;AAeO,SAAS,oBACd,OACA,UAAsC,CAAC,GAC3B;AACZ,QAAM,EAAE,eAAe,MAAM,kBAAkB,KAAK,IAAI;AACxD,QAAM,SAAS,kBAAkB;AACjC,MAAI,CAAC,QAAQ,SAAS;AACpB,WAAO,MAAM;AAAA,IAAC;AAAA,EAChB;AAEA,QAAM,gBAA6C,CAAC;AACpD,MAAI,cAAc;AAChB,kBAAc,KAAK,CAAC,gBAAgB,KAAK,CAAC;AAAA,EAC5C;AACA,MAAI,iBAAiB;AACnB,kBAAc,KAAK,CAAC,mBAAmB,KAAK,CAAC;AAAA,EAC/C;AAEA,aAAW,CAAC,MAAM,QAAQ,KAAK,eAAe;AAC5C,WAAO,QAAQ,MAAM,QAAQ;AAAA,EAC/B;AAEA,SAAO,MAAM;AACX,eAAW,CAAC,MAAM,QAAQ,KAAK,eAAe;AAC5C,aAAO,WAAW,MAAM,QAAQ;AAAA,IAClC;AAAA,EACF;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Telegram Mini App viewport contract: the CSS variables Telegram's script
3
+ * sets on `:root` as soon as it loads (no `ready()` call is needed, and
4
+ * Telegram keeps them current on `viewportChanged` / `safeAreaChanged` /
5
+ * `contentSafeAreaChanged`), plus the DS-side defaults for hosted
6
+ * (non-Telegram) rendering. CSS that reads them needs no JS subscription;
7
+ * `observeTelegramHost` only re-runs the colour bridge.
8
+ *
9
+ * - `--tg-viewport-height` tracks the full WebView height, including areas
10
+ * temporarily covered (e.g. by the on-screen keyboard).
11
+ * - `--tg-viewport-stable-height` excludes transient shrinking — the value
12
+ * full-height panels should bind to (already the default for `body` and
13
+ * full Drawers via the `globals.css` compliance layer).
14
+ * - `--tg-safe-area-inset-*` / `--tg-content-safe-area-inset-*` carry the
15
+ * notch / status-bar / home-indicator regions; the content variant is the
16
+ * inset inside Telegram's own bottom chrome.
17
+ *
18
+ * Every `var(--tg-…)` reference in `telegram.css` carries a standard-web
19
+ * fallback, so the stylesheet is a no-op outside a Telegram WebView. The
20
+ * `qa:telegram-vars` package check enforces that invariant.
21
+ */
22
+ import type { DensityMode } from '../../layout/responsive.props.cjs';
23
+ export declare const TELEGRAM_VIEWPORT_HEIGHT_VAR: "--tg-viewport-height";
24
+ export declare const TELEGRAM_VIEWPORT_STABLE_HEIGHT_VAR: "--tg-viewport-stable-height";
25
+ export declare const TELEGRAM_COLOR_SCHEME_VAR: "--tg-color-scheme";
26
+ export declare const TELEGRAM_SAFE_AREA_VARS: {
27
+ readonly top: "--tg-safe-area-inset-top";
28
+ readonly right: "--tg-safe-area-inset-right";
29
+ readonly bottom: "--tg-safe-area-inset-bottom";
30
+ readonly left: "--tg-safe-area-inset-left";
31
+ };
32
+ export declare const TELEGRAM_CONTENT_SAFE_AREA_VARS: {
33
+ readonly top: "--tg-content-safe-area-inset-top";
34
+ readonly right: "--tg-content-safe-area-inset-right";
35
+ readonly bottom: "--tg-content-safe-area-inset-bottom";
36
+ readonly left: "--tg-content-safe-area-inset-left";
37
+ };
38
+ /** DS density a Mini App root defaults to — small WebView, thumb reach. */
39
+ export declare const TELEGRAM_MINI_APP_DENSITY_DEFAULT: DensityMode;
40
+ /** Host marker attribute the bridge sets and `telegram.css` scopes to. */
41
+ export declare const TELEGRAM_MINI_APP_ATTRIBUTE: "data-tg-mini-app";
42
+ /** True inside a Telegram Mini App WebView (real or stubbed in tests). */
43
+ export declare function isTelegramWebView(): boolean;
44
+ export type ObserveTelegramHostOptions = {
45
+ /** Re-run the bridge when Telegram fires `themeChanged`. Default true. */
46
+ themeChanged?: boolean;
47
+ /** Re-run the bridge when Telegram fires `viewportChanged`. Default true. */
48
+ viewportChanged?: boolean;
49
+ };
50
+ /**
51
+ * Keep the bridge output fresh across a Mini App session: re-runs `apply`
52
+ * on Telegram's `themeChanged` / `viewportChanged` events. Returns a
53
+ * cleanup that detaches both listeners. No-op (returns a no-op cleanup)
54
+ * outside a Telegram WebView or when the host exposes no event API.
55
+ */
56
+ export declare function observeTelegramHost(apply: () => void, options?: ObserveTelegramHostOptions): () => void;
57
+ //# sourceMappingURL=viewport.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"viewport.d.cts","sourceRoot":"","sources":["../../../src/foundations/telegram/viewport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAA;AAEhE,eAAO,MAAM,4BAA4B,EAAG,sBAA+B,CAAA;AAC3E,eAAO,MAAM,mCAAmC,EAAG,6BAAsC,CAAA;AACzF,eAAO,MAAM,yBAAyB,EAAG,mBAA4B,CAAA;AAErE,eAAO,MAAM,uBAAuB;;;;;CAK1B,CAAA;AAEV,eAAO,MAAM,+BAA+B;;;;;CAKlC,CAAA;AAEV,2EAA2E;AAC3E,eAAO,MAAM,iCAAiC,EAAE,WAAuB,CAAA;AAEvE,0EAA0E;AAC1E,eAAO,MAAM,2BAA2B,EAAG,kBAA2B,CAAA;AAmBtE,0EAA0E;AAC1E,wBAAgB,iBAAiB,IAAI,OAAO,CAE3C;AAED,MAAM,MAAM,0BAA0B,GAAG;IACvC,0EAA0E;IAC1E,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,6EAA6E;IAC7E,eAAe,CAAC,EAAE,OAAO,CAAA;CAC1B,CAAA;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,IAAI,EACjB,OAAO,GAAE,0BAA+B,GACvC,MAAM,IAAI,CAwBZ"}