@@ -68,10 +68,67 @@ export default class Node {
6868 return cloned ;
6969 }
7070
71+ /**
72+ * Some non-standard syntax doesn't follow normal escaping rules for css.
73+ * This allows non standard syntax to be appended to an existing property
74+ * by specifying the escaped value. By specifying the escaped value,
75+ * illegal characters are allowed to be directly inserted into css output.
76+ * @param {string } name the property to set
77+ * @param {any } value the unescaped value of the property
78+ * @param {string } valueEscaped optional. the escaped value of the property.
79+ */
80+ appendToPropertyAndEscape ( name , value , valueEscaped ) {
81+ if ( ! this . raws ) {
82+ this . raws = { } ;
83+ }
84+ let originalValue = this [ name ] ;
85+ let originalEscaped = this . raws [ name ] ;
86+ this [ name ] = originalValue + value ; // this may trigger a setter that updates raws, so it has to be set first.
87+ if ( originalEscaped || valueEscaped !== value ) {
88+ this . raws [ name ] = ( originalEscaped || originalValue ) + valueEscaped ;
89+ } else {
90+ delete this . raws [ name ] ; // delete any escaped value that was created by the setter.
91+ }
92+ }
93+
94+ /**
95+ * Some non-standard syntax doesn't follow normal escaping rules for css.
96+ * This allows the escaped value to be specified directly, allowing illegal
97+ * characters to be directly inserted into css output.
98+ * @param {string } name the property to set
99+ * @param {any } value the unescaped value of the property
100+ * @param {string } valueEscaped optional. the escaped value of the property.
101+ */
102+ setPropertyAndEscape ( name , value , valueEscaped ) {
103+ if ( ! this . raws ) {
104+ this . raws = { } ;
105+ }
106+ this [ name ] = value ; // this may trigger a setter that updates raws, so it has to be set first.
107+ this . raws [ name ] = valueEscaped ;
108+ }
109+
110+ /**
111+ * When you want a value to passed through to CSS directly. This method
112+ * deletes the corresponding raw value causing the stringifier to fallback
113+ * to the unescaped value.
114+ * @param {string } name the property to set.
115+ * @param {any } value The value that is both escaped and unescaped.
116+ */
117+ setPropertyWithoutEscape ( name , value ) {
118+ this [ name ] = value ; // this may trigger a setter that updates raws, so it has to be set first.
119+ if ( this . raws ) {
120+ delete this . raws [ name ] ;
121+ }
122+ }
123+
124+ _valueFor ( name ) {
125+ return ( this . raws && this . raws [ name ] ) || this [ name ] ;
126+ }
127+
71128 toString ( ) {
72129 return [
73130 this . spaces . before ,
74- String ( this . value ) ,
131+ String ( this . _valueFor ( " value" ) ) ,
75132 this . spaces . after ,
76133 ] . join ( '' ) ;
77134 }
0 commit comments