@@ -18,15 +18,33 @@ Vue.component('dynamic-text', {
1818 }
1919 } ,
2020 methods : {
21+ isValidFontSize ( size ) {
22+ if ( ! size ) return false ;
23+ return / ^ - ? \d * \. ? \d + ( p x | e m | r e m | % | p t | v h | v w | v m i n | v m a x | c h | e x ) $ / i. test ( size . trim ( ) ) ;
24+ } ,
25+ isValidFontWeight ( weight ) {
26+ if ( ! weight ) return false ;
27+ const normalized = weight . trim ( ) . toLowerCase ( ) ;
28+ if ( / ^ [ 1 - 9 ] 0 0 $ / . test ( normalized ) ) return true ;
29+ return [ 'normal' , 'bold' , 'bolder' , 'lighter' ] . includes ( normalized ) ;
30+ } ,
2131 parseText ( ) {
2232 const parts = [ ] ;
2333 let currentText = '' ;
2434 let currentColor = null ;
35+ let currentSize = null ;
36+ let currentWeight = null ;
2537 let i = 0 ;
2638
2739 const pushCurrentText = ( ) => {
2840 if ( currentText ) {
29- parts . push ( { type : 'text' , text : currentText , color : currentColor } ) ;
41+ parts . push ( {
42+ type : 'text' ,
43+ text : currentText ,
44+ color : currentColor ,
45+ size : currentSize ,
46+ weight : currentWeight
47+ } ) ;
3048 currentText = '' ;
3149 }
3250 } ;
@@ -54,6 +72,23 @@ Vue.component('dynamic-text', {
5472 } ) ;
5573 } else if ( code === 'e' ) {
5674 currentColor = null ;
75+ currentSize = null ;
76+ currentWeight = null ;
77+ } else if ( code . startsWith ( 'size:' ) ) {
78+ const sizeData = code . substring ( 5 ) ;
79+ const [ rawSize , rawWeight ] = sizeData . split ( '|' ) ;
80+ const nextSize = rawSize ? rawSize . trim ( ) : null ;
81+ const nextWeight = rawWeight ? rawWeight . trim ( ) : null ;
82+
83+ if ( nextSize && this . isValidFontSize ( nextSize ) ) {
84+ currentSize = nextSize ;
85+ }
86+
87+ if ( nextWeight && this . isValidFontWeight ( nextWeight ) ) {
88+ currentWeight = nextWeight ;
89+ } else {
90+ currentWeight = null ;
91+ }
5792 } else if ( code . startsWith ( '#' ) ) {
5893 currentColor = code ;
5994 } else if ( code . startsWith ( 'img:' ) ) {
@@ -136,7 +171,9 @@ Vue.component('dynamic-text', {
136171 return h ( 'span' , {
137172 key : index ,
138173 style : {
139- color : part . color
174+ color : part . color ,
175+ fontSize : part . size ,
176+ fontWeight : part . weight
140177 }
141178 } , part . text ) ;
142179 }
0 commit comments