From 0fdcb59d75e80b5cf01a1576691b44040e47e6e5 Mon Sep 17 00:00:00 2001 From: Danny Rorabaugh Date: Thu, 25 Apr 2024 16:00:08 -0400 Subject: [PATCH] Update font scripts --- .../mui_language_picker_font_map.json | 19 -- .../font_lists/mui_language_picker_fonts.txt | 188 ------------------ maintenance/scripts/get_fonts.py | 81 ++++---- .../scripts/mui_language_picker_fonts.txt | 152 ++++++++++++++ package-lock.json | 75 +++---- package.json | 2 +- scripts/get_fonts_dev.py | 34 +++- 7 files changed, 244 insertions(+), 307 deletions(-) delete mode 100644 maintenance/scripts/font_lists/mui_language_picker_font_map.json delete mode 100644 maintenance/scripts/font_lists/mui_language_picker_fonts.txt create mode 100644 maintenance/scripts/mui_language_picker_fonts.txt diff --git a/maintenance/scripts/font_lists/mui_language_picker_font_map.json b/maintenance/scripts/font_lists/mui_language_picker_font_map.json deleted file mode 100644 index 257fc91086..0000000000 --- a/maintenance/scripts/font_lists/mui_language_picker_font_map.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "KNDABadami": "Badami", - "Galatia": "GalatiaSIL", - "Kyebogyi": "KyebogyiSIL", - "NamdhinggoSIL": "Namdhinggo", - "NotoSansCJKJP": "NotoSansJP", - "NotoSansCJKKR": "NotoSansKR", - "NotoSansCJKSC": "NotoSansSC", - "NotoSansCJKTC": "NotoSansTC", - "NotoSansLatin": "NotoSans", - "NotoSansTangut": "NotoSerifTangut", - "NotoSerifCJKJP": "NotoSerifJP", - "NotoSerifCJKKR": "NotoSerifKR", - "NotoSerifCJKSC": "NotoSerifSC", - "NotoSerifCJKTC": "NotoSerifTC", - "NotoSerifLatin": "NotoSerif", - "Scheherazade": "ScheherazadeNew", - "TAMLThiruValluvar": "ThiruValluvar" -} diff --git a/maintenance/scripts/font_lists/mui_language_picker_fonts.txt b/maintenance/scripts/font_lists/mui_language_picker_fonts.txt deleted file mode 100644 index 1a8e38ed63..0000000000 --- a/maintenance/scripts/font_lists/mui_language_picker_fonts.txt +++ /dev/null @@ -1,188 +0,0 @@ -Abyssinica SIL -Annapurna SIL -Awami Nastaliq -Charis SIL -Dai Banna SIL -DokChampa -Doulos SIL -Ebrima -Ezra SIL -Galatia -Gentium Plus -Harmattan -KNDA Badami -Kayahli -Khmer Mondulkiri -Kyebogyi -LisuTzimu -Mingzat -Namdhinggo SIL -Narnoor -Nokyung -Noto Sans CJK JP -Noto Sans CJK KR -Noto Sans CJK SC -Noto Sans CJK TC -Noto Serif CJK JP -Noto Serif CJK KR -Noto Serif CJK SC -Noto Serif CJK TC -NotoNastaliqUrdu -NotoSans -NotoSansAdlam -NotoSansAnatolianHieroglyphs -NotoSansArabic -NotoSansArmenian -NotoSansAvestan -NotoSansBalinese -NotoSansBamum -NotoSansBassaVah -NotoSansBatak -NotoSansBengali -NotoSansBhaiksuki -NotoSansBrahmi -NotoSansBuginese -NotoSansBuhid -NotoSansCanadianAboriginal -NotoSansCarian -NotoSansCaucasianAlbanian -NotoSansChakma -NotoSansCham -NotoSansCherokee -NotoSansCoptic -NotoSansCuneiform -NotoSansCypriot -NotoSansDeseret -NotoSansDevanagari -NotoSansDuployan -NotoSansEgyptianHieroglyphs -NotoSansElbasan -NotoSansEthiopic -NotoSansGeorgian -NotoSansGlagolitic -NotoSansGothic -NotoSansGrantha -NotoSansGujarati -NotoSansGurmukhi -NotoSansHanunoo -NotoSansHatran -NotoSansHebrew -NotoSansImperialAramaic -NotoSansInscriptionalPahlavi -NotoSansInscriptionalParthian -NotoSansJavanese -NotoSansKaithi -NotoSansKannada -NotoSansKayah Li -NotoSansKharoshthi -NotoSansKhmer -NotoSansKhojki -NotoSansKhudawadi -NotoSansLao -NotoSansLatin -NotoSansLeke -NotoSansLepcha -NotoSansLimbu -NotoSansLinearA -NotoSansLinearB -NotoSansLisu -NotoSansLycian -NotoSansLydian -NotoSansMahajani -NotoSansMalayalam -NotoSansMandaic -NotoSansManichaean -NotoSansMarchen -NotoSansMeeteiMayek -NotoSansMendeKikakui -NotoSansMeroitic -NotoSansMeroitic Cursive -NotoSansMiao -NotoSansModi -NotoSansMongolian -NotoSansMro -NotoSansMultani -NotoSansMyanmar -NotoSansNKo -NotoSansNabataean -NotoSansNandinagari -NotoSansNewTaiLue -NotoSansNewa -NotoSansOgham -NotoSansOl Chiki -NotoSansOld Permic -NotoSansOldHungarian -NotoSansOldItalic -NotoSansOldNorthArabian -NotoSansOldPersian -NotoSansOldSouthArabian -NotoSansOldTurkic -NotoSansOriya -NotoSansOsage -NotoSansOsmanya -NotoSansPahawhHmong -NotoSansPalmyrene -NotoSansPauCinHau -NotoSansPhagsPa -NotoSansPhoenician -NotoSansPsalterPahlavi -NotoSansRejang -NotoSansRunic -NotoSansSamaritan -NotoSansSaurashtra -NotoSansShuishu -NotoSansSiddham -NotoSansSinhala -NotoSansSora Sompeng -NotoSansSylotiNagri -NotoSansSyriac -NotoSansTagalog -NotoSansTagbanwa -NotoSansTaiLe -NotoSansTaiTham -NotoSansTaiViet -NotoSansTakri -NotoSansTamil -NotoSansTangut -NotoSansTelugu -NotoSansThaana -NotoSansThai -NotoSansTibetan -NotoSansTifinagh -NotoSansTirhuta -NotoSansUgaritic -NotoSansVai -NotoSansWarangCiti -NotoSansYi -NotoSerif -NotoSerifAhom -NotoSerifArmenian -NotoSerifBengali -NotoSerifDevanagari -NotoSerifEthiopic -NotoSerifGeorgian -NotoSerifGujarati -NotoSerifGurmukhi -NotoSerifHebrew -NotoSerifKannada -NotoSerifKhmer -NotoSerifLao -NotoSerifLatin -NotoSerifMalayalam -NotoSerifMyanmar -NotoSerifSinhala -NotoSerifTamil -NotoSerifTelugu -NotoSerifThai -NotoSerifTibetan -Nuosu SIL -Padauk -Saysettha MX -Scheherazade -ShiShan -Shimenkan -SimSun -Sophia Nubian -Surma -TAML ThiruValluvar -Tai Heritage Pro diff --git a/maintenance/scripts/get_fonts.py b/maintenance/scripts/get_fonts.py index f2f40056cd..cac191ed73 100755 --- a/maintenance/scripts/get_fonts.py +++ b/maintenance/scripts/get_fonts.py @@ -19,10 +19,8 @@ scripts_dir = Path(__file__).resolve().parent file_name_fallback = "fallback.json" -font_lists_dir = scripts_dir / "font_lists" -mlp_font_list = font_lists_dir / "mui_language_picker_fonts.txt" -mlp_font_map = font_lists_dir / "mui_language_picker_font_map.json" -mlp_fonts_known_unavailable = ["NotoSansLeke", "NotoSansShuishu", "SimSun"] +mlp_font_list = scripts_dir / "mui_language_picker_fonts.txt" +mlp_fonts_known_unavailable = [] url_font_families_info = "https://github.com/silnrsi/fonts/raw/main/families.json" url_lang_tags_list = "https://ldml.api.sil.org/en?query=langtags" url_script_font_table = ( @@ -48,6 +46,13 @@ def parse_args() -> argparse.Namespace: metavar="LANG", help="List of language tags for which fonts should be downloaded.", ) + parser.add_argument( + "--scripts", + "-s", + nargs="*", + metavar="SCRIPT", + help="List of script tags for which fonts should be downloaded.", + ) parser.add_argument( "--url", "-u", @@ -120,10 +125,10 @@ def extract_lang_subtags(langs: List[str]) -> List[str]: return lang_list -def fetch_scripts_for_langs(langs: List[str]) -> List[str]: +def fetch_scripts_for_langs(langs: List[str], scripts: List[str] = None) -> List[str]: """Given a list of langtags, look up and return all script tags used with the languages.""" langs = [lang.lower() for lang in langs] - scripts = [] + scripts = scripts if scripts else [] logging.debug(f"Downloading lang-tag list from {url_lang_tags_list}") req = requests.get(url_lang_tags_list) for line in req.iter_lines(): @@ -144,8 +149,8 @@ def fetch_fonts_for_scripts(scripts: List[str]) -> List[str]: """Given a list of script tags, look up the default fonts used with those scripts.""" scripts = [script.capitalize() for script in scripts] - # Always have the Mui-Language-Picker default/safe fonts (except proprietary "SimSun"). - fonts = ["AnnapurnaSIL", "CharisSIL", "DoulosSIL", "NotoSans", "ScheherazadeNew"] + # Always have the Mui-Language-Picker default/safe fonts. + fonts = ["Annapurna SIL", "Charis SIL", "Noto Sans TC", "Scheherazade New"] logging.debug(f"Downloading script font table from {url_script_font_table}") req = requests.get(url_script_font_table) @@ -174,7 +179,7 @@ def fetch_fonts_for_scripts(scripts: List[str]) -> List[str]: if len(row) == 0 or row[0] not in scripts: continue for i in font_indices: - font = row[i].replace(" ", "") + font = row[i] if font != "" and font not in fonts: fonts.append(font) @@ -200,19 +205,22 @@ def main() -> None: logging.error(f"Invalid output directory: '{args.output}'") exit(1) - with open(mlp_font_list, "r") as mlp_fonts_list: - # MLP use of spaces in fonts is inconsistent, so remove all spaces for simplicity. - fonts = [f.strip().replace(" ", "") for f in mlp_fonts_list.readlines()] + offline: bool = args.langs or args.scripts - if args.langs: - logging.info(f"Language tags: {', '.join(args.langs)}") + with open(mlp_font_list, "r") as mlp_fonts_list: + fonts = [f.strip() for f in mlp_fonts_list.readlines()] - scripts = fetch_scripts_for_langs(args.langs) - logging.info(f"Scripts used for specified language tags: {', '.join(scripts)}") + if offline: + if args.langs: + logging.info(f"Language tags: {', '.join(args.langs)}") + scripts = fetch_scripts_for_langs(args.langs, args.scripts) + else: + scripts = args.scripts + logging.info(f"Scripts: {', '.join(scripts)}") script_fonts = fetch_fonts_for_scripts(scripts) logging.info( - f"Default fonts and fonts used for specified language tags: {', '.join(script_fonts)}" + f"Fonts (default and those for specified languages/scripts): {', '.join(script_fonts)}" ) if args.clean: @@ -227,28 +235,19 @@ def main() -> None: families = fetch_font_families_info() - with open(mlp_font_map, "r") as mlp_map_file: - mlp_map: dict[str, str] = json.load(mlp_map_file) - # Assumes no two keys map to the same value. - mlp_map_rev = {val: key for key, val in mlp_map.items()} - # Fonts for which the frontend will get css files from Google's font API. google_fallback: dict[str, str] = {} for font in fonts: logging.debug(f"Font: {font}") - font_id: str = font.lower() - if font in mlp_map.keys(): - font_id = mlp_map[font].lower() + font_id: str = font.replace(" ", "").lower() # Get font family info from font families info, using fallback font if necessary. while font_id != "" and font_id in families.keys(): font_info = families[font_id] family: str = font_info["family"] from_google = ( - (not args.langs) - and "source" in font_info.keys() - and font_info["source"] == "Google" + (not offline) and "source" in font_info.keys() and font_info["source"] == "Google" ) if check_font_info(font_info) or from_google: # Font available. @@ -261,18 +260,18 @@ def main() -> None: font_id = "" # When downloading, only download fonts used for scripts of the specified languages. - if args.langs and family.replace(" ", "") not in script_fonts: - logging.debug(f"Skipping font {font} as irrelevant for specified languages.") + if offline and family not in script_fonts: + logging.debug(f'Skipping font "{font}" as irrelevant for specified languages/scripts.') continue # Check if font was determined available. if font_id == "" or font_id not in families.keys(): if font in mlp_fonts_known_unavailable: - logging.debug(f"Font {font} not available (but we knew that already)") - elif args.langs: - logging.warning(f"Font {font} not available for download") + logging.debug(f'Font "{font}" not available (but we knew that already)') + elif offline: + logging.warning(f'Font "{font}" not available for download') else: - logging.warning(f"Font {font} css info not available") + logging.warning(f'Font "{font}" css info not available') continue # When not downloading, prefer fetching css info from Google when available. @@ -305,7 +304,7 @@ def main() -> None: logging.warning(f"{file_name}: No 'flourl' or 'url' for this file") continue - if args.langs: + if offline: # With the https://fonts.languagetechnology.org "flourl" urls, # urllib.request.urlretrieve() is denied (403), but requests.get() works. req = requests.get(src) @@ -326,17 +325,7 @@ def main() -> None: with open(css_file_path, "w") as css_file: css_file.writelines(css_lines) - # If the font corresponds to a different MPL font name, - # create a css file for that font name too. - if font in mlp_map_rev.keys(): - font = mlp_map_rev[font] - css_lines[2] = f" font-family: '{font}';\n" - css_file_path = args.output / f"{font}.css" - logging.debug(f"Writing {css_file_path}") - with open(css_file_path, "w") as css_file: - css_file.writelines(css_lines) - - if not args.langs: + if not offline: fallback_lines = ['{\n "google": {\n'] for key, val in google_fallback.items(): fallback_lines.append(f' "{key}": "{val}",\n') diff --git a/maintenance/scripts/mui_language_picker_fonts.txt b/maintenance/scripts/mui_language_picker_fonts.txt new file mode 100644 index 0000000000..5b9eaeb3c6 --- /dev/null +++ b/maintenance/scripts/mui_language_picker_fonts.txt @@ -0,0 +1,152 @@ +Abyssinica SIL +Annapurna SIL +BJCree UNI +Badami +Charis SIL +Dai Banna SIL +Dukor +Ezra SIL +Gentium Plus +Kay Pho Du +Khmer Mondulkiri +Lisu Bosa +Mingzat +Namdhinggo +Narnoor +Noto Sans Anatolian Hieroglyphs +Noto Sans Avestan +Noto Sans Balinese +Noto Sans Bamum +Noto Sans Bassa Vah +Noto Sans Batak +Noto Sans Bengali +Noto Sans Bhaiksuki +Noto Sans Brahmi +Noto Sans Buginese +Noto Sans Buhid +Noto Sans Carian +Noto Sans Caucasian Albanian +Noto Sans Chakma +Noto Sans Cham +Noto Sans Cherokee +Noto Sans Chorasmian +Noto Sans Coptic +Noto Sans Cuneiform +Noto Sans Cypriot +Noto Sans Deseret +Noto Sans Duployan +Noto Sans Egyptian Hieroglyphs +Noto Sans Elbasan +Noto Sans Elymaic +Noto Sans Georgian +Noto Sans Glagolitic +Noto Sans Gothic +Noto Sans Grantha +Noto Sans Gujarati +Noto Sans Gurmukhi +Noto Sans Hanifi Rohingya +Noto Sans Hanunoo +Noto Sans Hatran +Noto Sans Imperial Aramaic +Noto Sans Inscriptional Pahlavi +Noto Sans Inscriptional Parthian +Noto Sans JP +Noto Sans Javanese +Noto Sans KR +Noto Sans Kaithi +Noto Sans Kharoshthi +Noto Sans Khojki +Noto Sans Khudawadi +Noto Sans Linear A +Noto Sans Linear B +Noto Sans Lycian +Noto Sans Lydian +Noto Sans Mahajani +Noto Sans Mandaic +Noto Sans Manichaean +Noto Sans Marchen +Noto Sans Medefaidrin +Noto Sans Meetei Mayek +Noto Sans Mende Kikakui +Noto Sans Meroitic +Noto Sans Modi +Noto Sans Mongolian +Noto Sans Mro +Noto Sans Multani +Noto Sans NKo +Noto Sans Nabataean +Noto Sans Nag Mundari +Noto Sans Nandinagari +Noto Sans Newa +Noto Sans Ogham +Noto Sans Ol Chiki +Noto Sans Old Hungarian +Noto Sans Old Italic +Noto Sans Old North Arabian +Noto Sans Old Permic +Noto Sans Old Persian +Noto Sans Old Sogdian +Noto Sans Old South Arabian +Noto Sans Old Turkic +Noto Sans Oriya +Noto Sans Osage +Noto Sans Osmanya +Noto Sans Pahawh Hmong +Noto Sans Palmyrene +Noto Sans Pau Cin Hau +Noto Sans Phags Pa +Noto Sans Phoenician +Noto Sans Psalter Pahlavi +Noto Sans Rejang +Noto Sans Runic +Noto Sans SC +Noto Sans Samaritan +Noto Sans Saurashtra +Noto Sans Sharada +Noto Sans Shavian +Noto Sans Siddham +Noto Sans SignWriting +Noto Sans Sinhala +Noto Sans Sogdian +Noto Sans Sora Sompeng +Noto Sans Soyombo +Noto Sans Sundanese +Noto Sans Syriac +Noto Sans TC +Noto Sans Tagalog +Noto Sans Tai Le +Noto Sans Tai Tham +Noto Sans Takri +Noto Sans Tamil +Noto Sans Tangsa +Noto Sans Thaana +Noto Sans Thai +Noto Sans Tifinagh +Noto Sans Tirhuta +Noto Sans Ugaritic +Noto Sans Vithkuqi +Noto Sans Wancho +Noto Sans Warang Citi +Noto Sans Zanabazar Square +Noto Serif Ahom +Noto Serif Armenian +Noto Serif Dogra +Noto Serif JP +Noto Serif KR +Noto Serif Khitan Small Script +Noto Serif Makasar +Noto Serif Malayalam +Noto Serif NP Hmong +Noto Serif SC +Noto Serif Tangut +Noto Serif Telugu +Noto Serif Tibetan +Noto Serif Toto +Noto Serif Yezidi +Nuosu SIL +Padauk +Sapushan +Saysettha +Scheherazade New +Surma +Tai Heritage Pro diff --git a/package-lock.json b/package-lock.json index 19e020a790..743b65c1ff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34,7 +34,7 @@ "make-dir": "^4.0.0", "material-react-table": "^2.9.2", "motion": "^10.16.2", - "mui-language-picker": "2.1", + "mui-language-picker": "^2.1.2", "notistack": "^3.0.1", "nspell": "^2.1.5", "punycode": "^2.3.0", @@ -8280,7 +8280,8 @@ "node_modules/@types/aria-query": { "version": "5.0.4", "resolved": "https://registry.npmjs.org/@types/aria-query/-/aria-query-5.0.4.tgz", - "integrity": "sha512-rfT93uj5s0PRL7EzccGMs3brplhcrghnDoV26NqKhCAS1hVo+WdNsPvE/yb6ilfr5hi2MEk6d5EWJTKdxg8jVw==" + "integrity": "sha512-rfT93uj5s0PRL7EzccGMs3brplhcrghnDoV26NqKhCAS1hVo+WdNsPvE/yb6ilfr5hi2MEk6d5EWJTKdxg8jVw==", + "dev": true }, "node_modules/@types/babel__core": { "version": "7.20.4", @@ -8644,6 +8645,7 @@ "version": "18.2.15", "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-18.2.15.tgz", "integrity": "sha512-HWMdW+7r7MR5+PZqJF6YFNSCtjz1T0dsvo/f1BV6HkV+6erD/nA7wd9NM00KVG83zf2nJ7uATPO9ttdIPvi3gg==", + "devOptional": true, "dependencies": { "@types/react": "*" } @@ -9722,6 +9724,7 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true, "engines": { "node": ">=8" } @@ -9730,6 +9733,7 @@ "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, "dependencies": { "color-convert": "^2.0.1" }, @@ -10731,6 +10735,7 @@ "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, "dependencies": { "ansi-styles": "^4.1.0", "supports-color": "^7.1.0" @@ -11020,6 +11025,7 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, "dependencies": { "color-name": "~1.1.4" }, @@ -11030,7 +11036,8 @@ "node_modules/color-name": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true }, "node_modules/colord": { "version": "2.9.3", @@ -12089,6 +12096,7 @@ "version": "2.0.3", "resolved": "https://registry.npmjs.org/dequal/-/dequal-2.0.3.tgz", "integrity": "sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==", + "dev": true, "engines": { "node": ">=6" } @@ -12446,7 +12454,8 @@ "node_modules/dom-accessibility-api": { "version": "0.5.16", "resolved": "https://registry.npmjs.org/dom-accessibility-api/-/dom-accessibility-api-0.5.16.tgz", - "integrity": "sha512-X7BJ2yElsnOJ30pZF4uIIDfBEVgF4XEBxL9Bxhy6dnrm5hkzqmsWHGTiHqRiITNhMyFLyAiWndIJP7Z1NTteDg==" + "integrity": "sha512-X7BJ2yElsnOJ30pZF4uIIDfBEVgF4XEBxL9Bxhy6dnrm5hkzqmsWHGTiHqRiITNhMyFLyAiWndIJP7Z1NTteDg==", + "dev": true }, "node_modules/dom-converter": { "version": "0.2.0", @@ -15037,6 +15046,7 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true, "engines": { "node": ">=8" } @@ -19421,6 +19431,7 @@ "version": "1.5.0", "resolved": "https://registry.npmjs.org/lz-string/-/lz-string-1.5.0.tgz", "integrity": "sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ==", + "dev": true, "bin": { "lz-string": "bin/bin.js" } @@ -19929,57 +19940,13 @@ "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" }, "node_modules/mui-language-picker": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/mui-language-picker/-/mui-language-picker-2.1.0.tgz", - "integrity": "sha512-kbU5Pu8okfPt/6KHXmqoWv/T8D/Led3pe9/GOg9LBBYLC+UIbtu6yXbxdndi03ksS5z4btJIXijMQNUgwnJT6Q==", + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/mui-language-picker/-/mui-language-picker-2.1.2.tgz", + "integrity": "sha512-unzOfIJs9iwKwbG1Xt4KcjwLP/rknDqDe5GoPIdZlWbPMOFVLqOOcqpmt/IoM6mjfbc3flKnymVRJegET9ABCg==", "dependencies": { - "@testing-library/react": "^15.0.4", "lodash": "^4.17.21" } }, - "node_modules/mui-language-picker/node_modules/@testing-library/dom": { - "version": "10.0.0", - "resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-10.0.0.tgz", - "integrity": "sha512-PmJPnogldqoVFf+EwbHvbBJ98MmqASV8kLrBYgsDNxQcFMeIS7JFL48sfyXvuMtgmWO/wMhh25odr+8VhDmn4g==", - "dependencies": { - "@babel/code-frame": "^7.10.4", - "@babel/runtime": "^7.12.5", - "@types/aria-query": "^5.0.1", - "aria-query": "5.3.0", - "chalk": "^4.1.0", - "dom-accessibility-api": "^0.5.9", - "lz-string": "^1.5.0", - "pretty-format": "^27.0.2" - }, - "engines": { - "node": ">=18" - } - }, - "node_modules/mui-language-picker/node_modules/@testing-library/react": { - "version": "15.0.4", - "resolved": "https://registry.npmjs.org/@testing-library/react/-/react-15.0.4.tgz", - "integrity": "sha512-Fw/LM1emOHKfCxv5R0tz+25TOtiMt0o5Np1zJmb4LbSacOagXQX4ooAaHiJfGUMe+OjUk504BX11W+9Z8CvyZA==", - "dependencies": { - "@babel/runtime": "^7.12.5", - "@testing-library/dom": "^10.0.0", - "@types/react-dom": "^18.0.0" - }, - "engines": { - "node": ">=18" - }, - "peerDependencies": { - "react": "^18.0.0", - "react-dom": "^18.0.0" - } - }, - "node_modules/mui-language-picker/node_modules/aria-query": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/aria-query/-/aria-query-5.3.0.tgz", - "integrity": "sha512-b0P0sZPKtyu8HkeRAfCq0IfURZK+SuwMjY1UXGBU27wpAiTwQAIlq56IbIO+ytk/JjS1fMR14ee5WBBfKi5J6A==", - "dependencies": { - "dequal": "^2.0.3" - } - }, "node_modules/multicast-dns": { "version": "7.2.5", "resolved": "https://registry.npmjs.org/multicast-dns/-/multicast-dns-7.2.5.tgz", @@ -22712,6 +22679,7 @@ "version": "27.5.1", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-27.5.1.tgz", "integrity": "sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ==", + "dev": true, "dependencies": { "ansi-regex": "^5.0.1", "ansi-styles": "^5.0.0", @@ -22725,6 +22693,7 @@ "version": "5.2.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-5.2.0.tgz", "integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==", + "dev": true, "engines": { "node": ">=10" }, @@ -22735,7 +22704,8 @@ "node_modules/pretty-format/node_modules/react-is": { "version": "17.0.2", "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", - "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==" + "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==", + "dev": true }, "node_modules/pretty-ms": { "version": "7.0.1", @@ -26473,6 +26443,7 @@ "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, "dependencies": { "has-flag": "^4.0.0" }, diff --git a/package.json b/package.json index 0f31eec2bd..1965804d9c 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "make-dir": "^4.0.0", "material-react-table": "^2.9.2", "motion": "^10.16.2", - "mui-language-picker": "2.1", + "mui-language-picker": "^2.1.2", "notistack": "^3.0.1", "nspell": "^2.1.5", "punycode": "^2.3.0", diff --git a/scripts/get_fonts_dev.py b/scripts/get_fonts_dev.py index 4ec7287248..f82d25f050 100755 --- a/scripts/get_fonts_dev.py +++ b/scripts/get_fonts_dev.py @@ -5,10 +5,16 @@ import argparse from pathlib import Path import platform +import re import subprocess project_dir = Path(__file__).resolve().parent.parent dev_output_dir = project_dir / "public" / "fonts" +maintenance_scripts_dir = project_dir / "maintenance" / "scripts" +mlp_font_list = maintenance_scripts_dir / "mui_language_picker_fonts.txt" +mlp_font_families = ( + project_dir / "node_modules" / "mui-language-picker" / "dist" / "data" / "scriptFontIndex.js" +) def parse_args() -> argparse.Namespace: @@ -26,6 +32,13 @@ def parse_args() -> argparse.Namespace: metavar="LANG", help="List of language tags for which fonts should be downloaded.", ) + parser.add_argument( + "--scripts", + "-s", + nargs="*", + metavar="SCRIPT", + help="List of script tags for which fonts should be downloaded.", + ) parser.add_argument( "--url", "-u", @@ -35,6 +48,12 @@ def parse_args() -> argparse.Namespace: parser.add_argument( "--output", "-o", default=dev_output_dir, help="Output directory for font data." ) + parser.add_argument( + "--update", + "-U", + action="store_true", + help="Updates the list of fonts from mui-language-picker. (Must have run `npm i`)", + ) parser.add_argument( "--verbose", "-v", @@ -49,11 +68,21 @@ def parse_args() -> argparse.Namespace: def main() -> None: args = parse_args() + if args.update: + family_pattern = re.compile(r'\\"family\\"\:\\"([^\\]+)\\"') # \:\\\\"(1)\\\\"') + with open(mlp_font_families, "r") as families_file: + matches = re.findall(family_pattern, families_file.read()) + matches = [match + "\n" for match in set(matches)] + print(len(matches)) + matches.sort() + with open(mlp_font_list, "w") as fonts_file: + fonts_file.writelines(matches) + args.output.mkdir(mode=0o755, parents=True, exist_ok=True) command = [ "python", - project_dir / "maintenance" / "scripts" / "get_fonts.py", + maintenance_scripts_dir / "get_fonts.py", "-o", args.output, ] @@ -65,6 +94,9 @@ def main() -> None: if args.langs: command.append("-l") command.extend(args.langs) + if args.scripts: + command.append("-s") + command.extend(args.scripts) if args.verbose: command.append("-v") subprocess.run(command, shell=(platform.system() == "Windows"), check=True, text=True)