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 | import datetime
|
31 | import json
|
32 | import os
|
33 | import sys
|
34 | from os import path
|
35 |
|
36 | PYJSON5_DIR = os.path.join(os.path.dirname(__file__), '..', '..', 'third_party', 'pyjson5', 'src')
|
37 | sys.path.append(PYJSON5_DIR)
|
38 |
|
39 | import json5
|
40 |
|
41 | ROOT_DIRECTORY = path.join(path.dirname(__file__), '..', '..')
|
42 | GENERATED_LOCATION = path.join(ROOT_DIRECTORY, 'front_end', 'generated', 'SupportedCSSProperties.js')
|
43 | READ_LOCATION = path.join(ROOT_DIRECTORY, 'third_party', 'blink', 'renderer', 'core', 'css', 'css_properties.json5')
|
44 |
|
45 |
|
46 | def _keep_only_required_keys(entry):
|
47 | for key in entry.keys():
|
48 | if key not in ("name", "longhands", "svg", "inherited", "keywords"):
|
49 | del entry[key]
|
50 | return entry
|
51 |
|
52 |
|
53 | def properties_from_file(file_name):
|
54 | with open(file_name) as json5_file:
|
55 | doc = json5.loads(json5_file.read())
|
56 |
|
57 | properties = []
|
58 | property_names = {}
|
59 | property_values = {}
|
60 | aliases_for = []
|
61 | for entry in doc["data"]:
|
62 | if type(entry) is str:
|
63 | entry = {"name": entry}
|
64 | if "alias_for" in entry:
|
65 | aliases_for.append([entry["name"], entry["alias_for"]])
|
66 | continue
|
67 |
|
68 | if entry["name"].startswith("-internal-"):
|
69 | continue
|
70 | properties.append(_keep_only_required_keys(entry))
|
71 | property_names[entry["name"]] = entry
|
72 | if "keywords" in entry:
|
73 | keywords = list(
|
74 | filter(lambda keyword: not keyword.startswith("-internal-"),
|
75 | entry["keywords"]))
|
76 | property_values[entry["name"]] = {"values": keywords}
|
77 |
|
78 | properties.sort(key=lambda entry: entry["name"])
|
79 | aliases_for.sort(key=lambda entry: entry[0])
|
80 |
|
81 |
|
82 | for property in properties:
|
83 | longhands = property.get("longhands")
|
84 | if not longhands:
|
85 | continue
|
86 | if type(longhands) is str:
|
87 | longhands = longhands.split(";")
|
88 | longhands = [longhand for longhand in longhands if longhand in property_names]
|
89 | if not longhands:
|
90 | del property["longhands"]
|
91 | else:
|
92 | property["longhands"] = longhands
|
93 | all_inherited = True
|
94 | for longhand in longhands:
|
95 | longhand_property = property_names[longhand]
|
96 | all_inherited = all_inherited and ("inherited" in longhand_property) and longhand_property["inherited"]
|
97 | if all_inherited:
|
98 | property["inherited"] = True
|
99 |
|
100 | return properties, property_values, aliases_for
|
101 |
|
102 |
|
103 | properties, property_values, aliases_for = properties_from_file(READ_LOCATION)
|
104 | now = datetime.datetime.now()
|
105 | with open(GENERATED_LOCATION, "w+") as f:
|
106 | f.write('// Copyright %d The Chromium Authors. All rights reserved.\n' % now.year)
|
107 | f.write('// Use of this source code is governed by a BSD-style license that can be\n')
|
108 | f.write('// found in the LICENSE file.\n')
|
109 | f.write('\n')
|
110 | f.write("export const generatedProperties = %s;\n" % json.dumps(properties))
|
111 |
|
112 | f.write("export const generatedPropertyValues = %s;\n" % json.dumps(property_values, sort_keys=True))
|
113 | f.write("export const generatedAliasesFor = new Map(%s);\n" % json.dumps(aliases_for))
|