@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.
- package/README.md +3 -0
- package/dist/docs/component-index.json +1 -1
- package/dist/docs/consumer-guide.md +96 -0
- package/dist/foundations/telegram/index.cjs +20 -0
- package/dist/foundations/telegram/index.cjs.map +7 -0
- package/dist/foundations/telegram/index.d.cts +3 -0
- package/dist/foundations/telegram/index.d.cts.map +1 -0
- package/dist/foundations/telegram/index.d.mts +3 -0
- package/dist/foundations/telegram/index.d.mts.map +1 -0
- package/dist/foundations/telegram/index.d.ts +3 -0
- package/dist/foundations/telegram/index.d.ts.map +1 -0
- package/dist/foundations/telegram/index.js +3 -0
- package/dist/foundations/telegram/index.js.map +7 -0
- package/dist/foundations/telegram/theme-params.cjs +160 -0
- package/dist/foundations/telegram/theme-params.cjs.map +7 -0
- package/dist/foundations/telegram/theme-params.d.cts +124 -0
- package/dist/foundations/telegram/theme-params.d.cts.map +1 -0
- package/dist/foundations/telegram/theme-params.d.mts +124 -0
- package/dist/foundations/telegram/theme-params.d.mts.map +1 -0
- package/dist/foundations/telegram/theme-params.d.ts +124 -0
- package/dist/foundations/telegram/theme-params.d.ts.map +1 -0
- package/dist/foundations/telegram/theme-params.js +140 -0
- package/dist/foundations/telegram/theme-params.js.map +7 -0
- package/dist/foundations/telegram/viewport.cjs +81 -0
- package/dist/foundations/telegram/viewport.cjs.map +7 -0
- package/dist/foundations/telegram/viewport.d.cts +57 -0
- package/dist/foundations/telegram/viewport.d.cts.map +1 -0
- package/dist/foundations/telegram/viewport.d.mts +57 -0
- package/dist/foundations/telegram/viewport.d.mts.map +1 -0
- package/dist/foundations/telegram/viewport.d.ts +57 -0
- package/dist/foundations/telegram/viewport.d.ts.map +1 -0
- package/dist/foundations/telegram/viewport.js +61 -0
- package/dist/foundations/telegram/viewport.js.map +7 -0
- package/dist/styles.css +2 -3
- package/dist/telegram.css +93 -0
- package/dist/tokens.cjs +968 -0
- package/dist/tokens.d.cts +964 -0
- package/dist/tokens.d.mts +964 -0
- package/dist/tokens.d.ts +964 -0
- package/dist/tokens.js +964 -0
- package/dist/tokens.json +964 -0
- package/dist/utilities.css +2 -3
- package/package.json +26 -2
package/README.md
CHANGED
|
@@ -91,6 +91,9 @@ Google Fonts.
|
|
|
91
91
|
- `@d4gger/design-system/components` — primitives and composite UI
|
|
92
92
|
- `@d4gger/design-system/icons` — named icon exports
|
|
93
93
|
- `@d4gger/design-system/motion` — thin `framer-motion` re-export
|
|
94
|
+
- `@d4gger/design-system/tokens` — typed token maps (`tokens` defaults +
|
|
95
|
+
`tokensLight` light overrides, keys mirror `tokens.css` var names);
|
|
96
|
+
raw JSON twin at `@d4gger/design-system/tokens.json`
|
|
94
97
|
- `@d4gger/design-system/article-nodes` — read-side article renderers
|
|
95
98
|
- `@d4gger/design-system/article-extensions` — Tiptap article extensions
|
|
96
99
|
- `@d4gger/design-system/sortable-list` — dnd-kit-backed reordering
|
|
@@ -58,6 +58,7 @@ Starfield density can be selected with `dsx-brand-starfield--sparse` or
|
|
|
58
58
|
| `components/*.css` | Single-component styles | Tree-shaking per component (see below). |
|
|
59
59
|
| `tailwind.css` | Tailwind v4 token adapter | Apps that run Tailwind for page composition and want DS-token utility mappings. |
|
|
60
60
|
| `brand-effects.css` | Optional ambient, starfield, shimmer wrappers | Pages that opt into product atmosphere. |
|
|
61
|
+
| `telegram.css` | Telegram Mini App viewport, safe-area, accent, and motion bindings | Mini App entries only, imported after `styles.css`. No-op in a plain browser. |
|
|
61
62
|
|
|
62
63
|
### Tree-shaking component CSS
|
|
63
64
|
|
|
@@ -114,6 +115,26 @@ The same rule applies to `calendar`, `chart`, `combobox`, `command`,
|
|
|
114
115
|
Install the peer dependencies for the subpaths the application actually uses.
|
|
115
116
|
Do not import internal source or `dist` files.
|
|
116
117
|
|
|
118
|
+
### Typed tokens
|
|
119
|
+
|
|
120
|
+
`@d4gger/design-system/tokens` exposes the token contract as typed JavaScript
|
|
121
|
+
for build tooling, lint rules, and sync scripts (Tailwind config, Penpot sync).
|
|
122
|
+
Keys are the full CSS var names, 1:1 with `tokens.css`:
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
import { tokens, tokensLight, type TokenName } from '@d4gger/design-system/tokens'
|
|
126
|
+
|
|
127
|
+
tokens['--dsx-space-md'] // default (dark) value
|
|
128
|
+
tokensLight['--dsx-color-background'] // light-theme override
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
`tokens` holds every default value; `tokensLight` holds only the light-theme
|
|
132
|
+
overrides. Variant-scoped values (density, radius, accent, gray) stay
|
|
133
|
+
CSS-only — resolve them through `var()` at runtime. The same two maps ship as
|
|
134
|
+
raw JSON at `@d4gger/design-system/tokens.json` for non-JS tooling. The
|
|
135
|
+
`qa:tokens-typed` package check fails the build if the maps drift from
|
|
136
|
+
`tokens.css`.
|
|
137
|
+
|
|
117
138
|
## Layout
|
|
118
139
|
|
|
119
140
|
The layout primitives compose app shells and product pages. Pick the
|
|
@@ -966,6 +987,81 @@ The four `--dsx-safe-area-inset-*` aliases prefer Telegram's
|
|
|
966
987
|
safe-area inset. Components do not add that padding automatically; the app shell
|
|
967
988
|
owns where safe-area spacing belongs.
|
|
968
989
|
|
|
990
|
+
### Dedicated Telegram adapter (`./telegram` + `telegram.css`)
|
|
991
|
+
|
|
992
|
+
A Mini App that wants the design system to follow the user's Telegram palette, or needs more than the core compliance layer,
|
|
993
|
+
imports the dedicated adapter. It is peer-light (no Telegram SDK dependency) and additive: nothing in the core bundle changes
|
|
994
|
+
when it is absent. A Mini App that keeps the design system's own dark and light look does not need it.
|
|
995
|
+
|
|
996
|
+
```tsx
|
|
997
|
+
// mini-app/entry.tsx
|
|
998
|
+
import '@d4gger/design-system/styles.css'
|
|
999
|
+
import '@d4gger/design-system/telegram.css'
|
|
1000
|
+
import {
|
|
1001
|
+
applyTelegramThemeParams,
|
|
1002
|
+
observeTelegramHost,
|
|
1003
|
+
} from '@d4gger/design-system/telegram'
|
|
1004
|
+
|
|
1005
|
+
const root = document.documentElement
|
|
1006
|
+
const syncFromHost = () =>
|
|
1007
|
+
applyTelegramThemeParams(root, window.Telegram?.WebApp.themeParams ?? {})
|
|
1008
|
+
|
|
1009
|
+
syncFromHost()
|
|
1010
|
+
const stopObserving = observeTelegramHost(syncFromHost)
|
|
1011
|
+
```
|
|
1012
|
+
|
|
1013
|
+
What the adapter does:
|
|
1014
|
+
|
|
1015
|
+
- **Viewport bindings** (`telegram.css`). `--dsx-tg-viewport-height` and `--dsx-tg-viewport-stable-height` (Telegram's
|
|
1016
|
+
values, `100vh` fallback) plus `--dsx-tg-content-safe-area-inset-*` for the region inside Telegram's own bottom chrome.
|
|
1017
|
+
Bind full-height panels to the stable alias, not to `--tg-viewport-height`, which shrinks while the keyboard is up.
|
|
1018
|
+
Telegram's script sets its `--tg-*` variables when it loads and keeps them current (`viewportChanged`,
|
|
1019
|
+
`safeAreaChanged`, `contentSafeAreaChanged`), so this CSS needs no JavaScript.
|
|
1020
|
+
- **`theme_params` → DS tokens** (`applyTelegramThemeParams`, the only path for colour; `telegram.css` has none).
|
|
1021
|
+
It writes the roles the components read:
|
|
1022
|
+
- `bg_color` → `--dsx-color-background`, `text_color` → `--dsx-color-on-background`, `hint_color` →
|
|
1023
|
+
`--dsx-color-on-surface-variant`, `secondary_bg_color` → `--dsx-color-surface`, `section_bg_color` →
|
|
1024
|
+
`--dsx-color-surface-raised`, `destructive_text_color` → `--dsx-color-error`.
|
|
1025
|
+
- `button_color` → `--dsx-color-accent-track` (the primary button, progress and slider fills) and the legacy
|
|
1026
|
+
`--dsx-color-primary`; `button_text_color` → `--dsx-color-accent-contrast` and `--dsx-color-on-primary`.
|
|
1027
|
+
- `link_color` and `accent_text_color` → `--dsx-color-accent-indicator` (links, active markers); when both are present
|
|
1028
|
+
`accent_text_color` wins.
|
|
1029
|
+
- Derived from `button_color`, because Telegram has no param for them: the button's hover step (`--dsx-color-accent-10`,
|
|
1030
|
+
12% darker) and the soft accent surface behind selected rows and soft badges (`--dsx-color-accent-surface`, 20% alpha).
|
|
1031
|
+
- Not bridged (no design-system role): `header_bg_color`, `bottom_bar_bg_color`, `section_header_text_color`,
|
|
1032
|
+
`section_separator_color`, `subtitle_text_color`. Read them through `TELEGRAM_THEME_CSS_VARS`.
|
|
1033
|
+
|
|
1034
|
+
Pass `document.documentElement`: the call writes on `<html>` and on `<body>`, because `ThemeProvider` mirrors its data
|
|
1035
|
+
attributes on both and the theme rules re-declare every token on `<body>`, so a value written only on `<html>` never
|
|
1036
|
+
reaches a component. Params Telegram omits (or older clients predate) and values that are not `#rgb` / `#rrggbb` are
|
|
1037
|
+
skipped; design-system defaults stand in. This is a palette bridge, not a full re-theme: the accent steps no component
|
|
1038
|
+
role reads (the rest of the 1–12 ramp) keep the design system's accent.
|
|
1039
|
+
- **Mode.** Mode ownership stays with `Theme` / `ThemeProvider`; the bridge never touches `data-dsx-theme`.
|
|
1040
|
+
- **Compact density.** `TELEGRAM_MINI_APP_DENSITY_DEFAULT` is `compact` (small WebView, thumb reach). The bridge sets it
|
|
1041
|
+
only when nothing set `data-dsx-density` yet, and `ThemeProvider` always sets one, so an app under it passes
|
|
1042
|
+
`density={TELEGRAM_MINI_APP_DENSITY_DEFAULT}` itself. The `density` / `markHost` options cover an app that manages its own root.
|
|
1043
|
+
- **60fps / low-end guidance.** `motion.css` already honors `prefers-reduced-motion` globally; `telegram.css` adds the
|
|
1044
|
+
app-set `data-tg-motion="reduced"` marker for low-end Android WebViews where the OS signal never fires (the app decides,
|
|
1045
|
+
e.g. via hardware-concurrency or device-memory heuristics), scoped to a root carrying `data-tg-mini-app` (the bridge sets
|
|
1046
|
+
it). Inside the WebView, skip `brand-effects.css` and keep per-frame work (orbit satellites, scan sweeps, starfields) off
|
|
1047
|
+
small screens. `qa:telegram-vars` fails the release gate if any `--tg-*` binding loses its standard-web fallback, or if a
|
|
1048
|
+
token the bridge writes is not declared or is read by no stylesheet.
|
|
1049
|
+
|
|
1050
|
+
## Stream pins
|
|
1051
|
+
|
|
1052
|
+
Each playground stream's `frontend.md` carries its normative pin in its
|
|
1053
|
+
header — the opening paragraphs before the first `##` section — as
|
|
1054
|
+
`` Producer pin `core@<sha>` `` or `` `bot@<sha>` `` with a `YYYY-MM-DD`
|
|
1055
|
+
date (`design@<sha>` is the target self-pin form; producer pins are interim
|
|
1056
|
+
source evidence). The generated convenience index at
|
|
1057
|
+
[`docs/intel/pin-table.md`](../intel/pin-table.md) aggregates every stream
|
|
1058
|
+
(`stream | design@sha | package version | date | playground route`, plus an
|
|
1059
|
+
interim producer-pin column); it is rebuilt at release via
|
|
1060
|
+
`node scripts/scrape-consumers/generate-pin-table.mjs` and never hand-edited.
|
|
1061
|
+
Skill handoffs and scrape tooling cite the `frontend.md` header pin as
|
|
1062
|
+
authority, never the table. Missing pins are literal `TODO` cells — SHAs are
|
|
1063
|
+
never invented.
|
|
1064
|
+
|
|
969
1065
|
## Next steps
|
|
970
1066
|
|
|
971
1067
|
- Theme system, ThemeProvider, useTheme, and the SSR guidance live in
|
|
@@ -0,0 +1,20 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var telegram_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(telegram_exports);
|
|
18
|
+
__reExport(telegram_exports, require("./theme-params"), module.exports);
|
|
19
|
+
__reExport(telegram_exports, require("./viewport"), module.exports);
|
|
20
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/foundations/telegram/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/foundations/telegram/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/foundations/telegram/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA"}
|
|
@@ -0,0 +1,160 @@
|
|
|
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 theme_params_exports = {};
|
|
20
|
+
__export(theme_params_exports, {
|
|
21
|
+
TELEGRAM_THEME_CSS_VARS: () => TELEGRAM_THEME_CSS_VARS,
|
|
22
|
+
TELEGRAM_THEME_PARAM_BRIDGE: () => TELEGRAM_THEME_PARAM_BRIDGE,
|
|
23
|
+
TELEGRAM_THEME_PARAM_DERIVED: () => TELEGRAM_THEME_PARAM_DERIVED,
|
|
24
|
+
TELEGRAM_THEME_PARAM_NAMES: () => TELEGRAM_THEME_PARAM_NAMES,
|
|
25
|
+
applyTelegramThemeParams: () => applyTelegramThemeParams,
|
|
26
|
+
clearTelegramThemeParams: () => clearTelegramThemeParams
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(theme_params_exports);
|
|
29
|
+
const TELEGRAM_THEME_PARAM_NAMES = [
|
|
30
|
+
"bg_color",
|
|
31
|
+
"text_color",
|
|
32
|
+
"hint_color",
|
|
33
|
+
"link_color",
|
|
34
|
+
"button_color",
|
|
35
|
+
"button_text_color",
|
|
36
|
+
"secondary_bg_color",
|
|
37
|
+
"header_bg_color",
|
|
38
|
+
"bottom_bar_bg_color",
|
|
39
|
+
"accent_text_color",
|
|
40
|
+
"section_bg_color",
|
|
41
|
+
"section_header_text_color",
|
|
42
|
+
"section_separator_color",
|
|
43
|
+
"subtitle_text_color",
|
|
44
|
+
"destructive_text_color"
|
|
45
|
+
];
|
|
46
|
+
const TELEGRAM_THEME_CSS_VARS = {
|
|
47
|
+
bg_color: "--tg-theme-bg-color",
|
|
48
|
+
text_color: "--tg-theme-text-color",
|
|
49
|
+
hint_color: "--tg-theme-hint-color",
|
|
50
|
+
link_color: "--tg-theme-link-color",
|
|
51
|
+
button_color: "--tg-theme-button-color",
|
|
52
|
+
button_text_color: "--tg-theme-button-text-color",
|
|
53
|
+
secondary_bg_color: "--tg-theme-secondary-bg-color",
|
|
54
|
+
header_bg_color: "--tg-theme-header-bg-color",
|
|
55
|
+
bottom_bar_bg_color: "--tg-theme-bottom-bar-bg-color",
|
|
56
|
+
accent_text_color: "--tg-theme-accent-text-color",
|
|
57
|
+
section_bg_color: "--tg-theme-section-bg-color",
|
|
58
|
+
section_header_text_color: "--tg-theme-section-header-text-color",
|
|
59
|
+
section_separator_color: "--tg-theme-section-separator-color",
|
|
60
|
+
subtitle_text_color: "--tg-theme-subtitle-text-color",
|
|
61
|
+
destructive_text_color: "--tg-theme-destructive-text-color"
|
|
62
|
+
};
|
|
63
|
+
const TELEGRAM_THEME_PARAM_BRIDGE = {
|
|
64
|
+
bg_color: ["--dsx-color-background"],
|
|
65
|
+
text_color: ["--dsx-color-on-background"],
|
|
66
|
+
hint_color: ["--dsx-color-on-surface-variant"],
|
|
67
|
+
link_color: ["--dsx-color-accent-indicator"],
|
|
68
|
+
accent_text_color: ["--dsx-color-accent-indicator"],
|
|
69
|
+
button_color: ["--dsx-color-primary", "--dsx-color-accent-track"],
|
|
70
|
+
button_text_color: ["--dsx-color-on-primary", "--dsx-color-accent-contrast"],
|
|
71
|
+
secondary_bg_color: ["--dsx-color-surface"],
|
|
72
|
+
section_bg_color: ["--dsx-color-surface-raised"],
|
|
73
|
+
destructive_text_color: ["--dsx-color-error"]
|
|
74
|
+
};
|
|
75
|
+
const TELEGRAM_THEME_PARAM_DERIVED = {
|
|
76
|
+
button_color: ["--dsx-color-accent-10", "--dsx-color-accent-surface"]
|
|
77
|
+
};
|
|
78
|
+
const HOVER_SHADE = 0.12;
|
|
79
|
+
const SURFACE_ALPHA = 0.2;
|
|
80
|
+
const TELEGRAM_BRIDGE_ORDER = [
|
|
81
|
+
"bg_color",
|
|
82
|
+
"text_color",
|
|
83
|
+
"hint_color",
|
|
84
|
+
"link_color",
|
|
85
|
+
"accent_text_color",
|
|
86
|
+
"button_color",
|
|
87
|
+
"button_text_color",
|
|
88
|
+
"secondary_bg_color",
|
|
89
|
+
"section_bg_color",
|
|
90
|
+
"destructive_text_color"
|
|
91
|
+
];
|
|
92
|
+
function isHexColor(value) {
|
|
93
|
+
return /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/.test(value);
|
|
94
|
+
}
|
|
95
|
+
function parseHex(value) {
|
|
96
|
+
const digits = value.slice(1);
|
|
97
|
+
const full = digits.length === 3 ? [...digits].map((digit) => digit + digit).join("") : digits;
|
|
98
|
+
return [0, 2, 4].map((offset) => parseInt(full.slice(offset, offset + 2), 16));
|
|
99
|
+
}
|
|
100
|
+
function toHex(channels) {
|
|
101
|
+
return `#${channels.map((channel) => channel.toString(16).padStart(2, "0")).join("")}`;
|
|
102
|
+
}
|
|
103
|
+
const DERIVE_FROM_BUTTON_COLOR = {
|
|
104
|
+
"--dsx-color-accent-10": (rgb) => toHex(rgb.map((channel) => Math.round(channel * (1 - HOVER_SHADE)))),
|
|
105
|
+
"--dsx-color-accent-surface": ([red, green, blue]) => `rgba(${red}, ${green}, ${blue}, ${SURFACE_ALPHA})`
|
|
106
|
+
};
|
|
107
|
+
function writesFor(name, value) {
|
|
108
|
+
const writes = TELEGRAM_THEME_PARAM_BRIDGE[name].map((token) => [token, value]);
|
|
109
|
+
if (name === "button_color") {
|
|
110
|
+
const rgb = parseHex(value);
|
|
111
|
+
for (const token of TELEGRAM_THEME_PARAM_DERIVED.button_color) {
|
|
112
|
+
writes.push([token, DERIVE_FROM_BUTTON_COLOR[token](rgb)]);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return writes;
|
|
116
|
+
}
|
|
117
|
+
function themeHosts(root) {
|
|
118
|
+
const { documentElement, body } = root.ownerDocument;
|
|
119
|
+
return root === documentElement && body ? [root, body] : [root];
|
|
120
|
+
}
|
|
121
|
+
const DEFAULT_APPLY_OPTIONS = {
|
|
122
|
+
density: "compact",
|
|
123
|
+
markHost: true
|
|
124
|
+
};
|
|
125
|
+
function applyTelegramThemeParams(root, params, options = {}) {
|
|
126
|
+
const { density, markHost } = { ...DEFAULT_APPLY_OPTIONS, ...options };
|
|
127
|
+
const hosts = themeHosts(root);
|
|
128
|
+
if (markHost && !root.hasAttribute("data-tg-mini-app")) {
|
|
129
|
+
root.setAttribute("data-tg-mini-app", "");
|
|
130
|
+
}
|
|
131
|
+
if (density !== false && !root.hasAttribute("data-dsx-density")) {
|
|
132
|
+
root.setAttribute("data-dsx-density", density);
|
|
133
|
+
}
|
|
134
|
+
for (const name of TELEGRAM_BRIDGE_ORDER) {
|
|
135
|
+
const value = params[name];
|
|
136
|
+
if (typeof value !== "string" || !isHexColor(value)) {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
for (const [token, tokenValue] of writesFor(name, value)) {
|
|
140
|
+
for (const host of hosts) {
|
|
141
|
+
host.style.setProperty(token, tokenValue);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function clearTelegramThemeParams(root) {
|
|
147
|
+
const targets = /* @__PURE__ */ new Set();
|
|
148
|
+
for (const names of [...Object.values(TELEGRAM_THEME_PARAM_BRIDGE), ...Object.values(TELEGRAM_THEME_PARAM_DERIVED)]) {
|
|
149
|
+
for (const target of names) {
|
|
150
|
+
targets.add(target);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
for (const host of themeHosts(root)) {
|
|
154
|
+
for (const target of targets) {
|
|
155
|
+
host.style.removeProperty(target);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
root.removeAttribute("data-tg-mini-app");
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=theme-params.cjs.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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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,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AG;AACnD;AAAA,IACF;AAEA,eAAW,CAAC,OAAO,UAAU,KAAK,UAAU,MAAM,KAAK,GAAG;AACxD,iBAAW,QAAQ,OAAO;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,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.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme-params.d.cts","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,MA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