-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathcss.py
More file actions
2704 lines (2227 loc) · 92.4 KB
/
css.py
File metadata and controls
2704 lines (2227 loc) · 92.4 KB
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# DO NOT EDIT THIS FILE!
#
# This file is generated from the CDP specification. If you need to make
# changes, edit the generator and regenerate all of the modules.
#
# CDP domain: CSS (experimental)
from __future__ import annotations
from cdp.util import event_class, T_JSON_DICT
from dataclasses import dataclass
import enum
import typing
from . import dom
from . import page
class StyleSheetOrigin(enum.Enum):
r'''
Stylesheet type: "injected" for stylesheets injected via extension, "user-agent" for user-agent
stylesheets, "inspector" for stylesheets created by the inspector (i.e. those holding the "via
inspector" rules), "regular" for regular stylesheets.
'''
INJECTED = "injected"
USER_AGENT = "user-agent"
INSPECTOR = "inspector"
REGULAR = "regular"
def to_json(self) -> str:
return self.value
@classmethod
def from_json(cls, json: str) -> StyleSheetOrigin:
return cls(json)
@dataclass
class PseudoElementMatches:
r'''
CSS rule collection for a single pseudo style.
'''
#: Pseudo element type.
pseudo_type: dom.PseudoType
#: Matches of CSS rules applicable to the pseudo style.
matches: typing.List[RuleMatch]
#: Pseudo element custom ident.
pseudo_identifier: typing.Optional[str] = None
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['pseudoType'] = self.pseudo_type.to_json()
json['matches'] = [i.to_json() for i in self.matches]
if self.pseudo_identifier is not None:
json['pseudoIdentifier'] = self.pseudo_identifier
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> PseudoElementMatches:
return cls(
pseudo_type=dom.PseudoType.from_json(json['pseudoType']),
matches=[RuleMatch.from_json(i) for i in json['matches']],
pseudo_identifier=str(json['pseudoIdentifier']) if 'pseudoIdentifier' in json else None,
)
@dataclass
class CSSAnimationStyle:
r'''
CSS style coming from animations with the name of the animation.
'''
#: The style coming from the animation.
style: CSSStyle
#: The name of the animation.
name: typing.Optional[str] = None
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['style'] = self.style.to_json()
if self.name is not None:
json['name'] = self.name
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> CSSAnimationStyle:
return cls(
style=CSSStyle.from_json(json['style']),
name=str(json['name']) if 'name' in json else None,
)
@dataclass
class InheritedStyleEntry:
r'''
Inherited CSS rule collection from ancestor node.
'''
#: Matches of CSS rules matching the ancestor node in the style inheritance chain.
matched_css_rules: typing.List[RuleMatch]
#: The ancestor node's inline style, if any, in the style inheritance chain.
inline_style: typing.Optional[CSSStyle] = None
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['matchedCSSRules'] = [i.to_json() for i in self.matched_css_rules]
if self.inline_style is not None:
json['inlineStyle'] = self.inline_style.to_json()
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> InheritedStyleEntry:
return cls(
matched_css_rules=[RuleMatch.from_json(i) for i in json['matchedCSSRules']],
inline_style=CSSStyle.from_json(json['inlineStyle']) if 'inlineStyle' in json else None,
)
@dataclass
class InheritedAnimatedStyleEntry:
r'''
Inherited CSS style collection for animated styles from ancestor node.
'''
#: Styles coming from the animations of the ancestor, if any, in the style inheritance chain.
animation_styles: typing.Optional[typing.List[CSSAnimationStyle]] = None
#: The style coming from the transitions of the ancestor, if any, in the style inheritance chain.
transitions_style: typing.Optional[CSSStyle] = None
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
if self.animation_styles is not None:
json['animationStyles'] = [i.to_json() for i in self.animation_styles]
if self.transitions_style is not None:
json['transitionsStyle'] = self.transitions_style.to_json()
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> InheritedAnimatedStyleEntry:
return cls(
animation_styles=[CSSAnimationStyle.from_json(i) for i in json['animationStyles']] if 'animationStyles' in json else None,
transitions_style=CSSStyle.from_json(json['transitionsStyle']) if 'transitionsStyle' in json else None,
)
@dataclass
class InheritedPseudoElementMatches:
r'''
Inherited pseudo element matches from pseudos of an ancestor node.
'''
#: Matches of pseudo styles from the pseudos of an ancestor node.
pseudo_elements: typing.List[PseudoElementMatches]
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['pseudoElements'] = [i.to_json() for i in self.pseudo_elements]
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> InheritedPseudoElementMatches:
return cls(
pseudo_elements=[PseudoElementMatches.from_json(i) for i in json['pseudoElements']],
)
@dataclass
class RuleMatch:
r'''
Match data for a CSS rule.
'''
#: CSS rule in the match.
rule: CSSRule
#: Matching selector indices in the rule's selectorList selectors (0-based).
matching_selectors: typing.List[int]
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['rule'] = self.rule.to_json()
json['matchingSelectors'] = [i for i in self.matching_selectors]
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> RuleMatch:
return cls(
rule=CSSRule.from_json(json['rule']),
matching_selectors=[int(i) for i in json['matchingSelectors']],
)
@dataclass
class Value:
r'''
Data for a simple selector (these are delimited by commas in a selector list).
'''
#: Value text.
text: str
#: Value range in the underlying resource (if available).
range_: typing.Optional[SourceRange] = None
#: Specificity of the selector.
specificity: typing.Optional[Specificity] = None
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['text'] = self.text
if self.range_ is not None:
json['range'] = self.range_.to_json()
if self.specificity is not None:
json['specificity'] = self.specificity.to_json()
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> Value:
return cls(
text=str(json['text']),
range_=SourceRange.from_json(json['range']) if 'range' in json else None,
specificity=Specificity.from_json(json['specificity']) if 'specificity' in json else None,
)
@dataclass
class Specificity:
r'''
Specificity:
https://drafts.csswg.org/selectors/#specificity-rules
'''
#: The a component, which represents the number of ID selectors.
a: int
#: The b component, which represents the number of class selectors, attributes selectors, and
#: pseudo-classes.
b: int
#: The c component, which represents the number of type selectors and pseudo-elements.
c: int
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['a'] = self.a
json['b'] = self.b
json['c'] = self.c
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> Specificity:
return cls(
a=int(json['a']),
b=int(json['b']),
c=int(json['c']),
)
@dataclass
class SelectorList:
r'''
Selector list data.
'''
#: Selectors in the list.
selectors: typing.List[Value]
#: Rule selector text.
text: str
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['selectors'] = [i.to_json() for i in self.selectors]
json['text'] = self.text
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> SelectorList:
return cls(
selectors=[Value.from_json(i) for i in json['selectors']],
text=str(json['text']),
)
@dataclass
class CSSStyleSheetHeader:
r'''
CSS stylesheet metainformation.
'''
#: The stylesheet identifier.
style_sheet_id: dom.StyleSheetId
#: Owner frame identifier.
frame_id: page.FrameId
#: Stylesheet resource URL. Empty if this is a constructed stylesheet created using
#: new CSSStyleSheet() (but non-empty if this is a constructed stylesheet imported
#: as a CSS module script).
source_url: str
#: Stylesheet origin.
origin: StyleSheetOrigin
#: Stylesheet title.
title: str
#: Denotes whether the stylesheet is disabled.
disabled: bool
#: Whether this stylesheet is created for STYLE tag by parser. This flag is not set for
#: document.written STYLE tags.
is_inline: bool
#: Whether this stylesheet is mutable. Inline stylesheets become mutable
#: after they have been modified via CSSOM API.
#: ``<link>`` element's stylesheets become mutable only if DevTools modifies them.
#: Constructed stylesheets (new CSSStyleSheet()) are mutable immediately after creation.
is_mutable: bool
#: True if this stylesheet is created through new CSSStyleSheet() or imported as a
#: CSS module script.
is_constructed: bool
#: Line offset of the stylesheet within the resource (zero based).
start_line: float
#: Column offset of the stylesheet within the resource (zero based).
start_column: float
#: Size of the content (in characters).
length: float
#: Line offset of the end of the stylesheet within the resource (zero based).
end_line: float
#: Column offset of the end of the stylesheet within the resource (zero based).
end_column: float
#: URL of source map associated with the stylesheet (if any).
source_map_url: typing.Optional[str] = None
#: The backend id for the owner node of the stylesheet.
owner_node: typing.Optional[dom.BackendNodeId] = None
#: Whether the sourceURL field value comes from the sourceURL comment.
has_source_url: typing.Optional[bool] = None
#: If the style sheet was loaded from a network resource, this indicates when the resource failed to load
loading_failed: typing.Optional[bool] = None
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['styleSheetId'] = self.style_sheet_id.to_json()
json['frameId'] = self.frame_id.to_json()
json['sourceURL'] = self.source_url
json['origin'] = self.origin.to_json()
json['title'] = self.title
json['disabled'] = self.disabled
json['isInline'] = self.is_inline
json['isMutable'] = self.is_mutable
json['isConstructed'] = self.is_constructed
json['startLine'] = self.start_line
json['startColumn'] = self.start_column
json['length'] = self.length
json['endLine'] = self.end_line
json['endColumn'] = self.end_column
if self.source_map_url is not None:
json['sourceMapURL'] = self.source_map_url
if self.owner_node is not None:
json['ownerNode'] = self.owner_node.to_json()
if self.has_source_url is not None:
json['hasSourceURL'] = self.has_source_url
if self.loading_failed is not None:
json['loadingFailed'] = self.loading_failed
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> CSSStyleSheetHeader:
return cls(
style_sheet_id=dom.StyleSheetId.from_json(json['styleSheetId']),
frame_id=page.FrameId.from_json(json['frameId']),
source_url=str(json['sourceURL']),
origin=StyleSheetOrigin.from_json(json['origin']),
title=str(json['title']),
disabled=bool(json['disabled']),
is_inline=bool(json['isInline']),
is_mutable=bool(json['isMutable']),
is_constructed=bool(json['isConstructed']),
start_line=float(json['startLine']),
start_column=float(json['startColumn']),
length=float(json['length']),
end_line=float(json['endLine']),
end_column=float(json['endColumn']),
source_map_url=str(json['sourceMapURL']) if 'sourceMapURL' in json else None,
owner_node=dom.BackendNodeId.from_json(json['ownerNode']) if 'ownerNode' in json else None,
has_source_url=bool(json['hasSourceURL']) if 'hasSourceURL' in json else None,
loading_failed=bool(json['loadingFailed']) if 'loadingFailed' in json else None,
)
@dataclass
class CSSRule:
r'''
CSS rule representation.
'''
#: Rule selector data.
selector_list: SelectorList
#: Parent stylesheet's origin.
origin: StyleSheetOrigin
#: Associated style declaration.
style: CSSStyle
#: The css style sheet identifier (absent for user agent stylesheet and user-specified
#: stylesheet rules) this rule came from.
style_sheet_id: typing.Optional[dom.StyleSheetId] = None
#: Array of selectors from ancestor style rules, sorted by distance from the current rule.
nesting_selectors: typing.Optional[typing.List[str]] = None
#: The BackendNodeId of the DOM node that constitutes the origin tree scope of this rule.
origin_tree_scope_node_id: typing.Optional[dom.BackendNodeId] = None
#: Media list array (for rules involving media queries). The array enumerates media queries
#: starting with the innermost one, going outwards.
media: typing.Optional[typing.List[CSSMedia]] = None
#: Container query list array (for rules involving container queries).
#: The array enumerates container queries starting with the innermost one, going outwards.
container_queries: typing.Optional[typing.List[CSSContainerQuery]] = None
#: @supports CSS at-rule array.
#: The array enumerates @supports at-rules starting with the innermost one, going outwards.
supports: typing.Optional[typing.List[CSSSupports]] = None
#: Cascade layer array. Contains the layer hierarchy that this rule belongs to starting
#: with the innermost layer and going outwards.
layers: typing.Optional[typing.List[CSSLayer]] = None
#: @scope CSS at-rule array.
#: The array enumerates @scope at-rules starting with the innermost one, going outwards.
scopes: typing.Optional[typing.List[CSSScope]] = None
#: The array keeps the types of ancestor CSSRules from the innermost going outwards.
rule_types: typing.Optional[typing.List[CSSRuleType]] = None
#: @starting-style CSS at-rule array.
#: The array enumerates @starting-style at-rules starting with the innermost one, going outwards.
starting_styles: typing.Optional[typing.List[CSSStartingStyle]] = None
#: @navigation CSS at-rule array.
#: The array enumerates @navigation at-rules starting with the innermost one, going outwards.
navigations: typing.Optional[typing.List[CSSNavigation]] = None
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['selectorList'] = self.selector_list.to_json()
json['origin'] = self.origin.to_json()
json['style'] = self.style.to_json()
if self.style_sheet_id is not None:
json['styleSheetId'] = self.style_sheet_id.to_json()
if self.nesting_selectors is not None:
json['nestingSelectors'] = [i for i in self.nesting_selectors]
if self.origin_tree_scope_node_id is not None:
json['originTreeScopeNodeId'] = self.origin_tree_scope_node_id.to_json()
if self.media is not None:
json['media'] = [i.to_json() for i in self.media]
if self.container_queries is not None:
json['containerQueries'] = [i.to_json() for i in self.container_queries]
if self.supports is not None:
json['supports'] = [i.to_json() for i in self.supports]
if self.layers is not None:
json['layers'] = [i.to_json() for i in self.layers]
if self.scopes is not None:
json['scopes'] = [i.to_json() for i in self.scopes]
if self.rule_types is not None:
json['ruleTypes'] = [i.to_json() for i in self.rule_types]
if self.starting_styles is not None:
json['startingStyles'] = [i.to_json() for i in self.starting_styles]
if self.navigations is not None:
json['navigations'] = [i.to_json() for i in self.navigations]
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> CSSRule:
return cls(
selector_list=SelectorList.from_json(json['selectorList']),
origin=StyleSheetOrigin.from_json(json['origin']),
style=CSSStyle.from_json(json['style']),
style_sheet_id=dom.StyleSheetId.from_json(json['styleSheetId']) if 'styleSheetId' in json else None,
nesting_selectors=[str(i) for i in json['nestingSelectors']] if 'nestingSelectors' in json else None,
origin_tree_scope_node_id=dom.BackendNodeId.from_json(json['originTreeScopeNodeId']) if 'originTreeScopeNodeId' in json else None,
media=[CSSMedia.from_json(i) for i in json['media']] if 'media' in json else None,
container_queries=[CSSContainerQuery.from_json(i) for i in json['containerQueries']] if 'containerQueries' in json else None,
supports=[CSSSupports.from_json(i) for i in json['supports']] if 'supports' in json else None,
layers=[CSSLayer.from_json(i) for i in json['layers']] if 'layers' in json else None,
scopes=[CSSScope.from_json(i) for i in json['scopes']] if 'scopes' in json else None,
rule_types=[CSSRuleType.from_json(i) for i in json['ruleTypes']] if 'ruleTypes' in json else None,
starting_styles=[CSSStartingStyle.from_json(i) for i in json['startingStyles']] if 'startingStyles' in json else None,
navigations=[CSSNavigation.from_json(i) for i in json['navigations']] if 'navigations' in json else None,
)
class CSSRuleType(enum.Enum):
r'''
Enum indicating the type of a CSS rule, used to represent the order of a style rule's ancestors.
This list only contains rule types that are collected during the ancestor rule collection.
'''
MEDIA_RULE = "MediaRule"
SUPPORTS_RULE = "SupportsRule"
CONTAINER_RULE = "ContainerRule"
LAYER_RULE = "LayerRule"
SCOPE_RULE = "ScopeRule"
STYLE_RULE = "StyleRule"
STARTING_STYLE_RULE = "StartingStyleRule"
NAVIGATION_RULE = "NavigationRule"
def to_json(self) -> str:
return self.value
@classmethod
def from_json(cls, json: str) -> CSSRuleType:
return cls(json)
@dataclass
class RuleUsage:
r'''
CSS coverage information.
'''
#: The css style sheet identifier (absent for user agent stylesheet and user-specified
#: stylesheet rules) this rule came from.
style_sheet_id: dom.StyleSheetId
#: Offset of the start of the rule (including selector) from the beginning of the stylesheet.
start_offset: float
#: Offset of the end of the rule body from the beginning of the stylesheet.
end_offset: float
#: Indicates whether the rule was actually used by some element in the page.
used: bool
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['styleSheetId'] = self.style_sheet_id.to_json()
json['startOffset'] = self.start_offset
json['endOffset'] = self.end_offset
json['used'] = self.used
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> RuleUsage:
return cls(
style_sheet_id=dom.StyleSheetId.from_json(json['styleSheetId']),
start_offset=float(json['startOffset']),
end_offset=float(json['endOffset']),
used=bool(json['used']),
)
@dataclass
class SourceRange:
r'''
Text range within a resource. All numbers are zero-based.
'''
#: Start line of range.
start_line: int
#: Start column of range (inclusive).
start_column: int
#: End line of range
end_line: int
#: End column of range (exclusive).
end_column: int
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['startLine'] = self.start_line
json['startColumn'] = self.start_column
json['endLine'] = self.end_line
json['endColumn'] = self.end_column
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> SourceRange:
return cls(
start_line=int(json['startLine']),
start_column=int(json['startColumn']),
end_line=int(json['endLine']),
end_column=int(json['endColumn']),
)
@dataclass
class ShorthandEntry:
#: Shorthand name.
name: str
#: Shorthand value.
value: str
#: Whether the property has "!important" annotation (implies ``false`` if absent).
important: typing.Optional[bool] = None
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['name'] = self.name
json['value'] = self.value
if self.important is not None:
json['important'] = self.important
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> ShorthandEntry:
return cls(
name=str(json['name']),
value=str(json['value']),
important=bool(json['important']) if 'important' in json else None,
)
@dataclass
class CSSComputedStyleProperty:
#: Computed style property name.
name: str
#: Computed style property value.
value: str
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['name'] = self.name
json['value'] = self.value
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> CSSComputedStyleProperty:
return cls(
name=str(json['name']),
value=str(json['value']),
)
@dataclass
class ComputedStyleExtraFields:
#: Returns whether or not this node is being rendered with base appearance,
#: which happens when it has its appearance property set to base/base-select
#: or it is in the subtree of an element being rendered with base appearance.
is_appearance_base: bool
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['isAppearanceBase'] = self.is_appearance_base
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> ComputedStyleExtraFields:
return cls(
is_appearance_base=bool(json['isAppearanceBase']),
)
@dataclass
class CSSStyle:
r'''
CSS style representation.
'''
#: CSS properties in the style.
css_properties: typing.List[CSSProperty]
#: Computed values for all shorthands found in the style.
shorthand_entries: typing.List[ShorthandEntry]
#: The css style sheet identifier (absent for user agent stylesheet and user-specified
#: stylesheet rules) this rule came from.
style_sheet_id: typing.Optional[dom.StyleSheetId] = None
#: Style declaration text (if available).
css_text: typing.Optional[str] = None
#: Style declaration range in the enclosing stylesheet (if available).
range_: typing.Optional[SourceRange] = None
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['cssProperties'] = [i.to_json() for i in self.css_properties]
json['shorthandEntries'] = [i.to_json() for i in self.shorthand_entries]
if self.style_sheet_id is not None:
json['styleSheetId'] = self.style_sheet_id.to_json()
if self.css_text is not None:
json['cssText'] = self.css_text
if self.range_ is not None:
json['range'] = self.range_.to_json()
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> CSSStyle:
return cls(
css_properties=[CSSProperty.from_json(i) for i in json['cssProperties']],
shorthand_entries=[ShorthandEntry.from_json(i) for i in json['shorthandEntries']],
style_sheet_id=dom.StyleSheetId.from_json(json['styleSheetId']) if 'styleSheetId' in json else None,
css_text=str(json['cssText']) if 'cssText' in json else None,
range_=SourceRange.from_json(json['range']) if 'range' in json else None,
)
@dataclass
class CSSProperty:
r'''
CSS property declaration data.
'''
#: The property name.
name: str
#: The property value.
value: str
#: Whether the property has "!important" annotation (implies ``false`` if absent).
important: typing.Optional[bool] = None
#: Whether the property is implicit (implies ``false`` if absent).
implicit: typing.Optional[bool] = None
#: The full property text as specified in the style.
text: typing.Optional[str] = None
#: Whether the property is understood by the browser (implies ``true`` if absent).
parsed_ok: typing.Optional[bool] = None
#: Whether the property is disabled by the user (present for source-based properties only).
disabled: typing.Optional[bool] = None
#: The entire property range in the enclosing style declaration (if available).
range_: typing.Optional[SourceRange] = None
#: Parsed longhand components of this property if it is a shorthand.
#: This field will be empty if the given property is not a shorthand.
longhand_properties: typing.Optional[typing.List[CSSProperty]] = None
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['name'] = self.name
json['value'] = self.value
if self.important is not None:
json['important'] = self.important
if self.implicit is not None:
json['implicit'] = self.implicit
if self.text is not None:
json['text'] = self.text
if self.parsed_ok is not None:
json['parsedOk'] = self.parsed_ok
if self.disabled is not None:
json['disabled'] = self.disabled
if self.range_ is not None:
json['range'] = self.range_.to_json()
if self.longhand_properties is not None:
json['longhandProperties'] = [i.to_json() for i in self.longhand_properties]
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> CSSProperty:
return cls(
name=str(json['name']),
value=str(json['value']),
important=bool(json['important']) if 'important' in json else None,
implicit=bool(json['implicit']) if 'implicit' in json else None,
text=str(json['text']) if 'text' in json else None,
parsed_ok=bool(json['parsedOk']) if 'parsedOk' in json else None,
disabled=bool(json['disabled']) if 'disabled' in json else None,
range_=SourceRange.from_json(json['range']) if 'range' in json else None,
longhand_properties=[CSSProperty.from_json(i) for i in json['longhandProperties']] if 'longhandProperties' in json else None,
)
@dataclass
class CSSMedia:
r'''
CSS media rule descriptor.
'''
#: Media query text.
text: str
#: Source of the media query: "mediaRule" if specified by a @media rule, "importRule" if
#: specified by an @import rule, "linkedSheet" if specified by a "media" attribute in a linked
#: stylesheet's LINK tag, "inlineSheet" if specified by a "media" attribute in an inline
#: stylesheet's STYLE tag.
source: str
#: URL of the document containing the media query description.
source_url: typing.Optional[str] = None
#: The associated rule (@media or @import) header range in the enclosing stylesheet (if
#: available).
range_: typing.Optional[SourceRange] = None
#: Identifier of the stylesheet containing this object (if exists).
style_sheet_id: typing.Optional[dom.StyleSheetId] = None
#: Array of media queries.
media_list: typing.Optional[typing.List[MediaQuery]] = None
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['text'] = self.text
json['source'] = self.source
if self.source_url is not None:
json['sourceURL'] = self.source_url
if self.range_ is not None:
json['range'] = self.range_.to_json()
if self.style_sheet_id is not None:
json['styleSheetId'] = self.style_sheet_id.to_json()
if self.media_list is not None:
json['mediaList'] = [i.to_json() for i in self.media_list]
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> CSSMedia:
return cls(
text=str(json['text']),
source=str(json['source']),
source_url=str(json['sourceURL']) if 'sourceURL' in json else None,
range_=SourceRange.from_json(json['range']) if 'range' in json else None,
style_sheet_id=dom.StyleSheetId.from_json(json['styleSheetId']) if 'styleSheetId' in json else None,
media_list=[MediaQuery.from_json(i) for i in json['mediaList']] if 'mediaList' in json else None,
)
@dataclass
class MediaQuery:
r'''
Media query descriptor.
'''
#: Array of media query expressions.
expressions: typing.List[MediaQueryExpression]
#: Whether the media query condition is satisfied.
active: bool
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['expressions'] = [i.to_json() for i in self.expressions]
json['active'] = self.active
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> MediaQuery:
return cls(
expressions=[MediaQueryExpression.from_json(i) for i in json['expressions']],
active=bool(json['active']),
)
@dataclass
class MediaQueryExpression:
r'''
Media query expression descriptor.
'''
#: Media query expression value.
value: float
#: Media query expression units.
unit: str
#: Media query expression feature.
feature: str
#: The associated range of the value text in the enclosing stylesheet (if available).
value_range: typing.Optional[SourceRange] = None
#: Computed length of media query expression (if applicable).
computed_length: typing.Optional[float] = None
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['value'] = self.value
json['unit'] = self.unit
json['feature'] = self.feature
if self.value_range is not None:
json['valueRange'] = self.value_range.to_json()
if self.computed_length is not None:
json['computedLength'] = self.computed_length
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> MediaQueryExpression:
return cls(
value=float(json['value']),
unit=str(json['unit']),
feature=str(json['feature']),
value_range=SourceRange.from_json(json['valueRange']) if 'valueRange' in json else None,
computed_length=float(json['computedLength']) if 'computedLength' in json else None,
)
@dataclass
class CSSContainerQuery:
r'''
CSS container query rule descriptor.
'''
#: Container query text.
text: str
#: The associated rule header range in the enclosing stylesheet (if
#: available).
range_: typing.Optional[SourceRange] = None
#: Identifier of the stylesheet containing this object (if exists).
style_sheet_id: typing.Optional[dom.StyleSheetId] = None
#: Optional name for the container.
name: typing.Optional[str] = None
#: Optional physical axes queried for the container.
physical_axes: typing.Optional[dom.PhysicalAxes] = None
#: Optional logical axes queried for the container.
logical_axes: typing.Optional[dom.LogicalAxes] = None
#: true if the query contains scroll-state() queries.
queries_scroll_state: typing.Optional[bool] = None
#: true if the query contains anchored() queries.
queries_anchored: typing.Optional[bool] = None
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['text'] = self.text
if self.range_ is not None:
json['range'] = self.range_.to_json()
if self.style_sheet_id is not None:
json['styleSheetId'] = self.style_sheet_id.to_json()
if self.name is not None:
json['name'] = self.name
if self.physical_axes is not None:
json['physicalAxes'] = self.physical_axes.to_json()
if self.logical_axes is not None:
json['logicalAxes'] = self.logical_axes.to_json()
if self.queries_scroll_state is not None:
json['queriesScrollState'] = self.queries_scroll_state
if self.queries_anchored is not None:
json['queriesAnchored'] = self.queries_anchored
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> CSSContainerQuery:
return cls(
text=str(json['text']),
range_=SourceRange.from_json(json['range']) if 'range' in json else None,
style_sheet_id=dom.StyleSheetId.from_json(json['styleSheetId']) if 'styleSheetId' in json else None,
name=str(json['name']) if 'name' in json else None,
physical_axes=dom.PhysicalAxes.from_json(json['physicalAxes']) if 'physicalAxes' in json else None,
logical_axes=dom.LogicalAxes.from_json(json['logicalAxes']) if 'logicalAxes' in json else None,
queries_scroll_state=bool(json['queriesScrollState']) if 'queriesScrollState' in json else None,
queries_anchored=bool(json['queriesAnchored']) if 'queriesAnchored' in json else None,
)
@dataclass
class CSSSupports:
r'''
CSS Supports at-rule descriptor.
'''
#: Supports rule text.
text: str
#: Whether the supports condition is satisfied.
active: bool
#: The associated rule header range in the enclosing stylesheet (if
#: available).
range_: typing.Optional[SourceRange] = None
#: Identifier of the stylesheet containing this object (if exists).
style_sheet_id: typing.Optional[dom.StyleSheetId] = None
def to_json(self) -> T_JSON_DICT:
json: T_JSON_DICT = dict()
json['text'] = self.text
json['active'] = self.active
if self.range_ is not None:
json['range'] = self.range_.to_json()
if self.style_sheet_id is not None:
json['styleSheetId'] = self.style_sheet_id.to_json()
return json
@classmethod
def from_json(cls, json: T_JSON_DICT) -> CSSSupports:
return cls(
text=str(json['text']),
active=bool(json['active']),
range_=SourceRange.from_json(json['range']) if 'range' in json else None,
style_sheet_id=dom.StyleSheetId.from_json(json['styleSheetId']) if 'styleSheetId' in json else None,
)
@dataclass
class CSSNavigation:
r'''
CSS Navigation at-rule descriptor.
'''