主题参数 本节 SDK 涵盖与 主题参数 相关的主题。 解析要解析作为主题参数的值,软件包提供了 parseThemeParams 方法。 该 方法接受一个 JSON 字符串对象或 JavaScript 对象,返回 ThemeParams 接口。 如果提供的数据无效,则会出错。 Usage Example : - import { parseThemeParams } from '@telegram-apps/sdk';
2 ?% G+ A7 ? y! T0 b
% q! F4 S3 A% a% ^, _% \- parseThemeParams({- I, j# B' g7 E4 T) x
- accent_text_color: "#6ab2f2",
' {. V& I/ P1 ` - bg_color: "#17212b",
) c( \! v# P- l4 \: V: R% W! H - button_color: "#5288c1",3 P4 j6 k& s* M4 D: r
- button_text_color: "#ffffff", p1 m; F0 P5 h* Z1 h
- destructive_text_color: "#ec3942",3 A' u8 w5 \7 b( s, E% ]3 O/ C
- header_bg_color: "#17212b",
; R% J* l$ u0 j% V" L' ? - hint_color: "#708499",
& M' I; n* j$ m - link_color: "#6ab3f3",
# l- f: A- P# _# [8 I6 ^2 m; `+ d - secondary_bg_color: "#232e3c",
- u, T% J& ~1 K n - section_bg_color: "#17212b",% v! s a" [* W, s) Q) @
- section_header_text_color: "#6ab3f3",
1 q1 q; Q8 ^( ~' j3 C3 j - subtitle_text_color: "#708499",
d' Q& p2 d1 e - text_color: "#f5f5f5"
. y3 u3 V- S( x( i- | - });
复制代码Expected Result : - const result = {
4 Q/ u. \* T# T& u! m5 d. j - accentTextColor: "#6ab2f2",& [* {# v6 K/ Z. ^
- bgColor: "#17212b",2 v! ^) g) |+ j* k1 L% y: v) K" E
- buttonColor: "#5288c1",+ G7 x* V( O* U+ d# q* M) w
- buttonTextColor: "#ffffff",$ @5 u4 u% s9 a U6 x
- destructiveTextColor: "#ec3942",8 ~3 T; l8 A2 G7 A% g
- headerBgColor: "#17212b",3 ~8 V1 R5 [ f
- hintColor: "#708499",
5 C: g2 I" b0 Z! [! z: c - linkColor: "#6ab3f3",
% A' h0 K0 L# V: W$ A& Z! R8 ?& P - secondaryBgColor: "#232e3c",0 W" }. a7 }5 E7 ^5 x7 p
- sectionBgColor: "#17212b",2 c. o {! p# _2 {7 i
- sectionHeaderTextColor: "#6ab3f3",; D$ q; f0 ^2 Q! \
- subtitleTextColor: "#708499",( |5 H. c$ a" x. S7 t0 L$ W$ H
- textColor: "#f5f5f5"1 _* u. D+ a$ X, y6 L, p
- };
复制代码假设每个属性都使用蛇形大小写,它会将其转换为驼峰形大小写。
: a3 T+ ~$ ]7 j序列化要将主题参数对象表示转换为字符串,开发人员应使用 的 serializeThemeParams 函数: - import { serializeThemeParams } from '@telegram-apps/sdk';
1 ^( K; R+ V# H j* o2 u
6 v1 _1 ~. N' C. j0 B: B- serializeThemeParams({
4 z# y( g- `& q2 [& E3 M6 A' m0 t - accentTextColor: "#6ab2f2",6 I& K2 X) K/ D W7 K) o/ D6 p
- bgColor: "#17212b",
: [4 z5 m. ~' a - buttonColor: "#5288c1", A# l5 O- b+ b# }" l$ U& m% Q
- buttonTextColor: "#ffffff",
+ ~5 y( _* Y) I. N O1 I: g& X - destructiveTextColor: "#ec3942",
2 B6 O4 ?" R6 _, u! H# |( m6 P# ] - headerBgColor: "#17212b",* k: R/ t% \8 k. w* y
- hintColor: "#708499",5 t4 ]8 B0 L' @6 o K
- linkColor: "#6ab3f3",; F0 _/ E; q; e5 U3 a2 Q$ ?, s6 E$ y
- secondaryBgColor: "#232e3c",$ s; r$ w' X4 N
- sectionBgColor: "#17212b",
' \" l u8 m2 q2 q - sectionHeaderTextColor: "#6ab3f3",
9 \6 e9 i& E' N1 } - subtitleTextColor: "#708499",, s) G2 m+ _ X. n$ m$ E" ?# i0 ]
- textColor: "#f5f5f5"
% O2 W( u! i6 I" f0 M! K - });
& L( h8 u7 Q6 U2 l - $ r' V4 {1 p& t% Y; w8 Q! ]
- // Result:
U& P9 n& }* u$ v* F: D9 B4 q - // `{5 ]2 k$ t! Q% I: V! f, w/ C( |
- // "accent_text_color":"#6ab2f2",8 f' \7 g; j0 N
- // "bg_color":"#17212b",) [' G- z7 F9 ~" U
- // "button_color":"#5288c1",
' L n5 E7 z" q( U5 m - // "button_text_color":"#ffffff", B* o5 C+ ^' E1 V# H" V/ a
- // "destructive_text_color":"#ec3942",# f3 R/ \: p: p* b9 W0 J" p& a
- // "header_bg_color":"#17212b",
; ?3 Q+ P2 C/ a - // "hint_color":"#708499",: r% z( n/ o5 h0 f7 C
- // "link_color":"#6ab3f3",& I1 u$ I1 Q) Q S3 q
- // "secondary_bg_color":"#232e3c",
; ~; q# b% E5 r1 G0 u - // "section_bg_color":"#17212b"," R% O, N. w5 B F: J7 B0 h
- // "section_header_text_color":"#6ab3f3",# y; z$ j* L9 _5 V. l
- // "subtitle_text_color":"#708499",4 u% L- A/ |! z/ Z d
- // "text_color":"#f5f5f5"9 ^3 h5 X j: ^8 A
- // }`
复制代码 & `# @% g& d8 G5 J( S+ s# B8 _* {
0 \5 N* q' b7 h7 s' O4 A( h* f9 U
0 I% _% g1 i& r2 y1 ?2 H f5 } |