-
-
Notifications
You must be signed in to change notification settings - Fork 673
/
properties.py
260 lines (232 loc) · 7.1 KB
/
properties.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# coding: utf8
"""
weasyprint.css.properties
-------------------------
Various data about known properties.
:copyright: Copyright 2011-2012 Simon Sapin and contributors, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
from __future__ import division, unicode_literals
import collections
from tinycss.color3 import COLOR_KEYWORDS
Dimension = collections.namedtuple('Dimension', ['value', 'unit'])
# See http://www.w3.org/TR/CSS21/propidx.html
INITIAL_VALUES = {
'background_attachment': 'scroll',
'background_color': COLOR_KEYWORDS['transparent'],
'background_image': 'none',
'background_position': (Dimension(0, '%'), Dimension(0, '%')),
'background_repeat': 'repeat',
'background_clip': 'border-box', # CSS3
'background_origin': 'padding-box', # CSS3
'background_size': ('auto', 'auto'), # CSS3
'border_collapse': 'separate',
# http://www.w3.org/TR/css3-color/#currentcolor
'border_top_color': 'currentColor',
'border_right_color': 'currentColor',
'border_bottom_color': 'currentColor',
'border_left_color': 'currentColor',
'border_spacing': (0, 0),
'border_top_style': 'none',
'border_right_style': 'none',
'border_bottom_style': 'none',
'border_left_style': 'none',
'border_top_width': 3, # Computed value for 'medium'
'border_right_width': 3,
'border_bottom_width': 3,
'border_left_width': 3,
'bottom': 'auto',
'caption_side': 'top',
'clear': 'none',
'clip': (), # empty collection, computed value for 'auto'
'color': COLOR_KEYWORDS['black'], # chosen by the user agent
'content': 'normal',
# Means 'none', but allow `display: list-item` to increment the
# list-item counter. If we ever have a way for authors to query
# computed values (JavaScript?), this value should serialize to 'none'.
'counter_increment': 'auto',
'counter_reset': [], # parsed value for 'none'
# 'counter_set': [], # parsed value for 'none'
'direction': 'ltr',
'display': 'inline',
'empty_cells': 'show',
'float': 'none',
'font_family': ['serif'], # depends on user agent
'font_size': 16, # Actually medium, but we define medium from this.
'font_stretch': 'normal', # css3-fonts
'font_style': 'normal',
'font_variant': 'normal',
'font_weight': 400,
'height': 'auto',
'left': 'auto',
'letter_spacing': 'normal',
'line_height': 'normal',
'list_style_image': 'none',
'list_style_position': 'outside',
'list_style_type': 'disc',
'margin_top': Dimension(0, 'px'),
'margin_right': Dimension(0, 'px'),
'margin_bottom': Dimension(0, 'px'),
'margin_left': Dimension(0, 'px'),
'max_height': Dimension(float('inf'), 'px'), # Parsed value for 'none'
'max_width': Dimension(float('inf'), 'px'),
'min_height': Dimension(0, 'px'),
'min_width': Dimension(0, 'px'),
'orphans': 2,
'outline_color': 'currentColor', # invert is not supported
'outline_style': 'none',
'outline_width': 3, # Computed value for 'medium'
'overflow': 'visible',
'padding_top': Dimension(0, 'px'),
'padding_right': Dimension(0, 'px'),
'padding_bottom': Dimension(0, 'px'),
'padding_left': Dimension(0, 'px'),
'page_break_after': 'auto',
'page_break_before': 'auto',
'page_break_inside': 'auto',
'quotes': list('“”‘’'), # depends on user agent
'position': 'static',
'right': 'auto',
'table_layout': 'auto',
'text_align': '-weasy-start', # Taken from CSS3 Text.
# The only other supported value form CSS3 is -weasy-end.
'text_decoration': 'none',
'text_indent': Dimension(0, 'px'),
'text_transform': 'none',
'top': 'auto',
'unicode_bidi': 'normal',
'vertical_align': 'baseline',
'visibility': 'visible',
'white_space': 'normal',
'widows': 2,
'width': 'auto',
'word_spacing': 0, # computed value for 'normal'
'z_index': 'auto',
# CSS3 Paged Media: http://www.w3.org/TR/css3-page/#page-size
'size': None, # XXX set to A4 in computed_values
# CSS3 User Interface: http://www.w3.org/TR/css3-ui/#box-sizing
'box_sizing': 'content-box',
# CSS3 Color: http://www.w3.org/TR/css3-color/#transparency
'opacity': 1,
# CSS3 2D Transforms: http://www.w3.org/TR/css3-2d-transforms
'transform_origin': (Dimension(50, '%'), Dimension(50, '%')),
'transform': (), # empty sequence: computed value for 'none'
# Taken from SVG:
# http://www.w3.org/TR/SVG/painting.html#ImageRenderingProperty
'image_rendering': 'auto',
# Proprietary
'anchor': None, # computed value of 'none'
'link': None, # computed value of 'none'
# CSS3 Generated Content for Paged Media
# http://dev.w3.org/csswg/css3-gcpm/
'bookmark_label': ('keyword', 'none'), # computed value of 'none'
'bookmark_level': 'none',
# Internal, to implement the "static position" for absolute boxes.
'_weasy_specified_display': 'inline',
}
KNOWN_PROPERTIES = set(name.replace('_', '-') for name in INITIAL_VALUES)
# Not applicable to the print media
NOT_PRINT_MEDIA = set([
# Aural media:
'azimuth',
'cue',
'cue-after',
'cue-before',
'cursor',
'elevation',
'pause',
'pause-after',
'pause-before',
'pitch-range',
'pitch',
'play-during',
'richness',
'speak-header',
'speak-numeral',
'speak-punctuation',
'speak',
'speech-rate',
'stress',
'voice-family',
'volume',
# outlines are not just for interactive but any visual media in css3-ui
])
# Do not list shorthand properties here as we handle them before inheritance.
#
# text_decoration is not a really inherited, see
# http://www.w3.org/TR/CSS2/text.html#propdef-text-decoration
#
# link: click events normally bubble up to link ancestors
# See http://lists.w3.org/Archives/Public/www-style/2012Jun/0315.html
INHERITED = set("""
border_collapse
border_spacing
caption_side
color
direction
empty_cells
font_family
font_size
font_style
font_stretch
font_variant
font_weight
letter_spacing
line_height
list_style_image
list_style_position
list_style_type
orphans
quotes
text_align
text_decoration
text_indent
text_transform
visibility
white_space
widows
word_spacing
image_rendering
link
""".split())
# Inherited but not applicable to print:
# azimuth
# cursor
# elevation
# pitch_range
# pitch
# richness
# speak_header
# speak_numeral
# speak_punctuation
# speak
# speech_rate
# stress
# voice_family
# volume
# http://www.w3.org/TR/CSS21/tables.html#model
# See also http://lists.w3.org/Archives/Public/www-style/2012Jun/0066.html
# Only non-inherited properties need to be included here.
TABLE_WRAPPER_BOX_PROPERTIES = set('''
position
float
margin_top
margin_bottom
margin_left
margin_right
top
bottom
left
right
clear
counter_increment
counter_reset
opacity
page_break_before
page_break_after
page_break_inside
transform
transform_origin
vertical_align
z_index
'''.split())