expo-font 11.10.2 → 12.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -2
- package/android/build.gradle +7 -95
- package/build/ExpoFontLoader.web.d.ts +0 -1
- package/build/ExpoFontLoader.web.d.ts.map +1 -1
- package/build/ExpoFontLoader.web.js +0 -3
- package/build/ExpoFontLoader.web.js.map +1 -1
- package/build/Font.js.map +1 -1
- package/build/Font.types.d.ts +2 -2
- package/build/Font.types.js.map +1 -1
- package/build/FontHooks.d.ts +1 -1
- package/build/FontHooks.js +1 -1
- package/build/FontHooks.js.map +1 -1
- package/build/FontLoader.d.ts.map +1 -1
- package/build/FontLoader.js +2 -4
- package/build/FontLoader.js.map +1 -1
- package/build/FontLoader.web.js.map +1 -1
- package/build/server.js.map +1 -1
- package/expo-module.config.json +3 -0
- package/ios/{EXFont.podspec → ExpoFont.podspec} +8 -7
- package/ios/FontExceptions.swift +19 -0
- package/ios/FontFamilyAliasManager.swift +59 -0
- package/ios/FontLoaderModule.swift +31 -0
- package/ios/FontUtils.swift +75 -0
- package/ios/UIFont+FontFamilyAlias.swift +18 -0
- package/package.json +2 -2
- package/plugin/build/utils.js +4 -3
- package/plugin/build/withFontsAndroid.js +3 -1
- package/plugin/src/utils.ts +3 -1
- package/plugin/src/withFontsAndroid.ts +3 -1
- package/src/ExpoFontLoader.web.ts +0 -4
- package/src/Font.types.ts +2 -2
- package/src/FontHooks.ts +1 -1
- package/src/FontLoader.ts +2 -4
- package/ios/EXFont/EXFont.h +0 -13
- package/ios/EXFont/EXFont.m +0 -43
- package/ios/EXFont/EXFontLoader.h +0 -10
- package/ios/EXFont/EXFontLoader.m +0 -148
- package/ios/EXFont/EXFontLoaderProcessor.h +0 -14
- package/ios/EXFont/EXFontLoaderProcessor.m +0 -69
- package/ios/EXFont/EXFontManager.h +0 -12
- package/ios/EXFont/EXFontManager.m +0 -31
- package/ios/EXFont/EXFontScaler.h +0 -8
- package/ios/EXFont/EXFontScaler.m +0 -16
- package/ios/EXFont/Singletons/EXFontScalersManager.h +0 -8
- package/ios/EXFont/Singletons/EXFontScalersManager.m +0 -61
package/CHANGELOG.md
CHANGED
|
@@ -10,11 +10,29 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## 12.0.0 — 2024-04-18
|
|
14
|
+
|
|
15
|
+
### 🎉 New features
|
|
16
|
+
|
|
17
|
+
- [iOS] The native module has been simplified and rewritten to Swift. ([#26380](https://github.com/expo/expo/pull/26380) by [@tsapeta](https://github.com/tsapeta))
|
|
18
|
+
|
|
19
|
+
### 💡 Others
|
|
20
|
+
|
|
21
|
+
- drop unused web `name` property. ([#27437](https://github.com/expo/expo/pull/27437) by [@EvanBacon](https://github.com/EvanBacon))
|
|
22
|
+
- Remove most of Constants.appOwnership. ([#26313](https://github.com/expo/expo/pull/26313) by [@wschurman](https://github.com/wschurman))
|
|
23
|
+
- Removed deprecated backward compatible Gradle settings. ([#28083](https://github.com/expo/expo/pull/28083) by [@kudo](https://github.com/kudo))
|
|
24
|
+
|
|
25
|
+
## 11.10.3 - 2024-02-16
|
|
26
|
+
|
|
27
|
+
### 🐛 Bug fixes
|
|
28
|
+
|
|
29
|
+
- Only include supported font files when using the plugin. ([#27002](https://github.com/expo/expo/pull/27002) by [@alanjhughes](https://github.com/alanjhughes))
|
|
30
|
+
|
|
31
|
+
## 11.10.2 - 2024-01-18
|
|
14
32
|
|
|
15
33
|
_This version does not introduce any user-facing changes._
|
|
16
34
|
|
|
17
|
-
## 11.10.1
|
|
35
|
+
## 11.10.1 - 2024-01-10
|
|
18
36
|
|
|
19
37
|
### 🎉 New features
|
|
20
38
|
|
package/android/build.gradle
CHANGED
|
@@ -1,107 +1,19 @@
|
|
|
1
1
|
apply plugin: 'com.android.library'
|
|
2
|
-
apply plugin: 'kotlin-android'
|
|
3
|
-
apply plugin: 'maven-publish'
|
|
4
2
|
|
|
5
3
|
group = 'host.exp.exponent'
|
|
6
|
-
version = '
|
|
4
|
+
version = '12.0.0'
|
|
7
5
|
|
|
8
6
|
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
useExpoPublishing()
|
|
15
|
-
useCoreDependencies()
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
buildscript {
|
|
20
|
-
// Simple helper that allows the root project to override versions declared by this library.
|
|
21
|
-
ext.safeExtGet = { prop, fallback ->
|
|
22
|
-
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Ensures backward compatibility
|
|
26
|
-
ext.getKotlinVersion = {
|
|
27
|
-
if (ext.has("kotlinVersion")) {
|
|
28
|
-
ext.kotlinVersion()
|
|
29
|
-
} else {
|
|
30
|
-
ext.safeExtGet("kotlinVersion", "1.8.10")
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
repositories {
|
|
35
|
-
mavenCentral()
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
dependencies {
|
|
39
|
-
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${getKotlinVersion()}")
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Remove this if and it's contents, when support for SDK49 is dropped
|
|
44
|
-
if (!safeExtGet("expoProvidesDefaultConfig", false)) {
|
|
45
|
-
afterEvaluate {
|
|
46
|
-
publishing {
|
|
47
|
-
publications {
|
|
48
|
-
release(MavenPublication) {
|
|
49
|
-
from components.release
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
repositories {
|
|
53
|
-
maven {
|
|
54
|
-
url = mavenLocal().url
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
7
|
+
apply from: expoModulesCorePlugin
|
|
8
|
+
applyKotlinExpoModulesCorePlugin()
|
|
9
|
+
useCoreDependencies()
|
|
10
|
+
useDefaultAndroidSdkVersions()
|
|
11
|
+
useExpoPublishing()
|
|
60
12
|
|
|
61
13
|
android {
|
|
62
|
-
// Remove this if and it's contents, when support for SDK49 is dropped
|
|
63
|
-
if (!safeExtGet("expoProvidesDefaultConfig", false)) {
|
|
64
|
-
compileSdkVersion safeExtGet("compileSdkVersion", 34)
|
|
65
|
-
|
|
66
|
-
defaultConfig {
|
|
67
|
-
minSdkVersion safeExtGet("minSdkVersion", 23)
|
|
68
|
-
targetSdkVersion safeExtGet("targetSdkVersion", 34)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
publishing {
|
|
72
|
-
singleVariant("release") {
|
|
73
|
-
withSourcesJar()
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
lintOptions {
|
|
78
|
-
abortOnError false
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
|
|
83
|
-
if (agpVersion.tokenize('.')[0].toInteger() < 8) {
|
|
84
|
-
compileOptions {
|
|
85
|
-
sourceCompatibility JavaVersion.VERSION_11
|
|
86
|
-
targetCompatibility JavaVersion.VERSION_11
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
kotlinOptions {
|
|
90
|
-
jvmTarget = JavaVersion.VERSION_11.majorVersion
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
14
|
namespace "expo.modules.font"
|
|
95
15
|
defaultConfig {
|
|
96
16
|
versionCode 29
|
|
97
|
-
versionName "
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
dependencies {
|
|
102
|
-
// Remove this if and it's contents, when support for SDK49 is dropped
|
|
103
|
-
if (!safeExtGet("expoProvidesDefaultConfig", false)) {
|
|
104
|
-
implementation project(':expo-modules-core')
|
|
105
|
-
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${getKotlinVersion()}"
|
|
17
|
+
versionName "12.0.0"
|
|
106
18
|
}
|
|
107
19
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { UnloadFontOptions } from './Font';
|
|
2
2
|
import { FontResource } from './Font.types';
|
|
3
3
|
declare const _default: {
|
|
4
|
-
readonly name: string;
|
|
5
4
|
unloadAllAsync(): Promise<void>;
|
|
6
5
|
unloadAsync(fontFamilyName: string, options?: UnloadFontOptions): Promise<void>;
|
|
7
6
|
getServerResources(): string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoFontLoader.web.d.ts","sourceRoot":"","sources":["../src/ExpoFontLoader.web.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAAe,YAAY,EAAE,MAAM,cAAc,CAAC
|
|
1
|
+
{"version":3,"file":"ExpoFontLoader.web.d.ts","sourceRoot":"","sources":["../src/ExpoFontLoader.web.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAAe,YAAY,EAAE,MAAM,cAAc,CAAC;;sBAiF/B,OAAO,CAAC,IAAI,CAAC;gCASH,MAAM,YAAY,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;0BAS/D,MAAM,EAAE;;6BAqBL,MAAM,aAAY,iBAAiB,GAAQ,OAAO;8BAUjD,MAAM,YAAY,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;;AAlD1E,wBAmFE;AAeF,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,GAAG,MAAM,CAIzF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoFontLoader.web.js","sourceRoot":"","sources":["../src/ExpoFont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,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IAChD,MAAM,QAAQ,GAAG,gCAAgC,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IAC5E,iGAAiG;IACjG,MAAM,MAAM,GAAG,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC1C,oBAAoB;IACpB,MAAM,IAAI,GAAG,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC3C,UAAU;IACV,MAAM,SAAS,GAAG,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IAChD,OAAO,CAAC,QAAQ,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC;AAC/D,CAAC","sourcesContent":["import { CodedError, Platform } from 'expo-modules-core';\nimport FontObserver from 'fontfaceobserver';\n\nimport { UnloadFontOptions } from './Font';\nimport { FontDisplay, FontResource } from './Font.types';\n\nfunction getFontFaceStyleSheet(): CSSStyleSheet | null {\n if (!Platform.isDOMAvailable) {\n return null;\n }\n const styleSheet = getStyleElement();\n return styleSheet.sheet ? (styleSheet.sheet as CSSStyleSheet) : null;\n}\n\ntype RuleItem = { rule: CSSFontFaceRule; index: number };\n\nfunction getFontFaceRules(): RuleItem[] {\n const sheet = getFontFaceStyleSheet();\n if (sheet) {\n // @ts-ignore: rule iterator\n const rules = [...sheet.cssRules];\n\n const items: RuleItem[] = [];\n\n for (let i = 0; i < rules.length; i++) {\n const rule = rules[i];\n if (rule instanceof CSSFontFaceRule) {\n items.push({ rule, index: i });\n }\n }\n return items;\n }\n return [];\n}\n\nfunction getFontFaceRulesMatchingResource(\n fontFamilyName: string,\n options?: UnloadFontOptions\n): RuleItem[] {\n const rules = getFontFaceRules();\n return rules.filter(({ rule }) => {\n return (\n rule.style.fontFamily === fontFamilyName &&\n (options && options.display ? options.display === (rule.style as any).fontDisplay : true)\n );\n });\n}\n\nconst serverContext: Set<{ name: string; css: string; resourceId: string }> = new Set();\n\nfunction getHeadElements(): {\n $$type: string;\n rel?: string;\n href?: string;\n as?: string;\n crossorigin?: string;\n children?: string;\n id?: string;\n type?: string;\n}[] {\n const entries = [...serverContext.entries()];\n if (!entries.length) {\n return [];\n }\n const css = entries.map(([{ css }]) => css).join('\\n');\n const links = entries.map(([{ resourceId }]) => resourceId);\n // TODO: Maybe return nothing if no fonts were loaded.\n return [\n {\n $$type: 'style',\n children: css,\n id: ID,\n type: 'text/css',\n },\n ...links.map((resourceId) => ({\n $$type: 'link',\n rel: 'preload',\n href: resourceId,\n as: 'font',\n crossorigin: '',\n })),\n ];\n}\n\nexport default {\n get name(): string {\n return 'ExpoFontLoader';\n },\n\n async unloadAllAsync(): Promise<void> {\n if (!Platform.isDOMAvailable) return;\n\n const element = document.getElementById(ID);\n if (element && element instanceof HTMLStyleElement) {\n document.removeChild(element);\n }\n },\n\n async unloadAsync(fontFamilyName: string, options?: UnloadFontOptions): Promise<void> {\n const sheet = getFontFaceStyleSheet();\n if (!sheet) return;\n const items = getFontFaceRulesMatchingResource(fontFamilyName, options);\n for (const item of items) {\n sheet.deleteRule(item.index);\n }\n },\n\n getServerResources(): string[] {\n const elements = getHeadElements();\n\n return elements\n .map((element) => {\n switch (element.$$type) {\n case 'style':\n return `<style id=\"${element.id}\" type=\"${element.type}\">${element.children}</style>`;\n case 'link':\n return `<link rel=\"${element.rel}\" href=\"${element.href}\" as=\"${element.as}\" crossorigin=\"${element.crossorigin}\" />`;\n default:\n return '';\n }\n })\n .filter(Boolean);\n },\n\n resetServerContext() {\n serverContext.clear();\n },\n\n isLoaded(fontFamilyName: string, resource: UnloadFontOptions = {}): boolean {\n if (typeof window === 'undefined') {\n return !![...serverContext.values()].find((asset) => {\n return asset.name === fontFamilyName;\n });\n }\n return getFontFaceRulesMatchingResource(fontFamilyName, resource)?.length > 0;\n },\n\n // NOTE(EvanBacon): No async keyword! This cannot return a promise in Node environments.\n loadAsync(fontFamilyName: string, resource: FontResource): Promise<void> {\n if (typeof window === 'undefined') {\n serverContext.add({\n name: fontFamilyName,\n css: _createWebFontTemplate(fontFamilyName, resource),\n // @ts-expect-error: typeof string\n resourceId: resource.uri!,\n });\n return Promise.resolve();\n }\n\n const canInjectStyle = document.head && typeof document.head.appendChild === 'function';\n if (!canInjectStyle) {\n throw new CodedError(\n 'ERR_WEB_ENVIRONMENT',\n `The browser's \\`document.head\\` element doesn't support injecting fonts.`\n );\n }\n\n const style = getStyleElement();\n document.head!.appendChild(style);\n\n const res = getFontFaceRulesMatchingResource(fontFamilyName, resource);\n if (!res.length) {\n _createWebStyle(fontFamilyName, resource);\n }\n\n if (!isFontLoadingListenerSupported()) {\n return Promise.resolve();\n }\n\n return new FontObserver(fontFamilyName, { display: resource.display }).load(null, 6000);\n },\n};\n\nconst ID = 'expo-generated-fonts';\n\nfunction getStyleElement(): HTMLStyleElement {\n const element = document.getElementById(ID);\n if (element && element instanceof HTMLStyleElement) {\n return element;\n }\n const styleElement = document.createElement('style');\n styleElement.id = ID;\n styleElement.type = 'text/css';\n return styleElement;\n}\n\nexport function _createWebFontTemplate(fontFamily: string, resource: FontResource): string {\n return `@font-face{font-family:${fontFamily};src:url(${resource.uri});font-display:${\n resource.display || FontDisplay.AUTO\n }}`;\n}\n\nfunction _createWebStyle(fontFamily: string, resource: FontResource): HTMLStyleElement {\n const fontStyle = _createWebFontTemplate(fontFamily, resource);\n\n const styleElement = getStyleElement();\n // @ts-ignore: TypeScript does not define HTMLStyleElement::styleSheet. This is just for IE and\n // possibly can be removed if it's unnecessary on IE 11.\n if (styleElement.styleSheet) {\n const styleElementIE = styleElement as any;\n styleElementIE.styleSheet.cssText = styleElementIE.styleSheet.cssText\n ? styleElementIE.styleSheet.cssText + fontStyle\n : fontStyle;\n } else {\n const textNode = document.createTextNode(fontStyle);\n styleElement.appendChild(textNode);\n }\n return styleElement;\n}\n\nfunction isFontLoadingListenerSupported(): boolean {\n const { userAgent } = window.navigator;\n // WebKit is broken https://github.com/bramstein/fontfaceobserver/issues/95\n const isIOS = !!userAgent.match(/iPad|iPhone/i);\n const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);\n // Edge is broken https://github.com/bramstein/fontfaceobserver/issues/109#issuecomment-333356795\n const isEdge = userAgent.includes('Edge');\n // Internet Explorer\n const isIE = userAgent.includes('Trident');\n // Firefox\n const isFirefox = userAgent.includes('Firefox');\n return !isSafari && !isIOS && !isEdge && !isIE && !isFirefox;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ExpoFontLoader.web.js","sourceRoot":"","sources":["../src/ExpoFontLoader.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,YAAY,MAAM,kBAAkB,CAAC;AAG5C,OAAO,EAAE,WAAW,EAAgB,MAAM,cAAc,CAAC;AAEzD,SAAS,qBAAqB;IAC5B,IAAI,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,UAAU,GAAG,eAAe,EAAE,CAAC;IACrC,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC,CAAE,UAAU,CAAC,KAAuB,CAAC,CAAC,CAAC,IAAI,CAAC;AACvE,CAAC;AAID,SAAS,gBAAgB;IACvB,MAAM,KAAK,GAAG,qBAAqB,EAAE,CAAC;IACtC,IAAI,KAAK,EAAE,CAAC;QACV,4BAA4B;QAC5B,MAAM,KAAK,GAAG,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;QAElC,MAAM,KAAK,GAAe,EAAE,CAAC;QAE7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACtC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;YACtB,IAAI,IAAI,YAAY,eAAe,EAAE,CAAC;gBACpC,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,CAAC;QAC5B,MAAM,cAAc,GAAG,YAAmB,CAAC;QAC3C,cAAc,CAAC,UAAU,CAAC,OAAO,GAAG,cAAc,CAAC,UAAU,CAAC,OAAO;YACnE,CAAC,CAAC,cAAc,CAAC,UAAU,CAAC,OAAO,GAAG,SAAS;YAC/C,CAAC,CAAC,SAAS,CAAC;IAChB,CAAC;SAAM,CAAC;QACN,MAAM,QAAQ,GAAG,QAAQ,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;QACpD,YAAY,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,SAAS,8BAA8B;IACrC,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC,SAAS,CAAC;IACvC,2EAA2E;IAC3E,MAAM,KAAK,GAAG,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IAChD,MAAM,QAAQ,GAAG,gCAAgC,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IAC5E,iGAAiG;IACjG,MAAM,MAAM,GAAG,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC1C,oBAAoB;IACpB,MAAM,IAAI,GAAG,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC3C,UAAU;IACV,MAAM,SAAS,GAAG,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IAChD,OAAO,CAAC,QAAQ,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC;AAC/D,CAAC","sourcesContent":["import { CodedError, Platform } from 'expo-modules-core';\nimport FontObserver from 'fontfaceobserver';\n\nimport { UnloadFontOptions } from './Font';\nimport { FontDisplay, FontResource } from './Font.types';\n\nfunction getFontFaceStyleSheet(): CSSStyleSheet | null {\n if (!Platform.isDOMAvailable) {\n return null;\n }\n const styleSheet = getStyleElement();\n return styleSheet.sheet ? (styleSheet.sheet as CSSStyleSheet) : null;\n}\n\ntype RuleItem = { rule: CSSFontFaceRule; index: number };\n\nfunction getFontFaceRules(): RuleItem[] {\n const sheet = getFontFaceStyleSheet();\n if (sheet) {\n // @ts-ignore: rule iterator\n const rules = [...sheet.cssRules];\n\n const items: RuleItem[] = [];\n\n for (let i = 0; i < rules.length; i++) {\n const rule = rules[i];\n if (rule instanceof CSSFontFaceRule) {\n items.push({ rule, index: i });\n }\n }\n return items;\n }\n return [];\n}\n\nfunction getFontFaceRulesMatchingResource(\n fontFamilyName: string,\n options?: UnloadFontOptions\n): RuleItem[] {\n const rules = getFontFaceRules();\n return rules.filter(({ rule }) => {\n return (\n rule.style.fontFamily === fontFamilyName &&\n (options && options.display ? options.display === (rule.style as any).fontDisplay : true)\n );\n });\n}\n\nconst serverContext: Set<{ name: string; css: string; resourceId: string }> = new Set();\n\nfunction getHeadElements(): {\n $$type: string;\n rel?: string;\n href?: string;\n as?: string;\n crossorigin?: string;\n children?: string;\n id?: string;\n type?: string;\n}[] {\n const entries = [...serverContext.entries()];\n if (!entries.length) {\n return [];\n }\n const css = entries.map(([{ css }]) => css).join('\\n');\n const links = entries.map(([{ resourceId }]) => resourceId);\n // TODO: Maybe return nothing if no fonts were loaded.\n return [\n {\n $$type: 'style',\n children: css,\n id: ID,\n type: 'text/css',\n },\n ...links.map((resourceId) => ({\n $$type: 'link',\n rel: 'preload',\n href: resourceId,\n as: 'font',\n crossorigin: '',\n })),\n ];\n}\n\nexport default {\n async unloadAllAsync(): Promise<void> {\n if (!Platform.isDOMAvailable) return;\n\n const element = document.getElementById(ID);\n if (element && element instanceof HTMLStyleElement) {\n document.removeChild(element);\n }\n },\n\n async unloadAsync(fontFamilyName: string, options?: UnloadFontOptions): Promise<void> {\n const sheet = getFontFaceStyleSheet();\n if (!sheet) return;\n const items = getFontFaceRulesMatchingResource(fontFamilyName, options);\n for (const item of items) {\n sheet.deleteRule(item.index);\n }\n },\n\n getServerResources(): string[] {\n const elements = getHeadElements();\n\n return elements\n .map((element) => {\n switch (element.$$type) {\n case 'style':\n return `<style id=\"${element.id}\" type=\"${element.type}\">${element.children}</style>`;\n case 'link':\n return `<link rel=\"${element.rel}\" href=\"${element.href}\" as=\"${element.as}\" crossorigin=\"${element.crossorigin}\" />`;\n default:\n return '';\n }\n })\n .filter(Boolean);\n },\n\n resetServerContext() {\n serverContext.clear();\n },\n\n isLoaded(fontFamilyName: string, resource: UnloadFontOptions = {}): boolean {\n if (typeof window === 'undefined') {\n return !![...serverContext.values()].find((asset) => {\n return asset.name === fontFamilyName;\n });\n }\n return getFontFaceRulesMatchingResource(fontFamilyName, resource)?.length > 0;\n },\n\n // NOTE(EvanBacon): No async keyword! This cannot return a promise in Node environments.\n loadAsync(fontFamilyName: string, resource: FontResource): Promise<void> {\n if (typeof window === 'undefined') {\n serverContext.add({\n name: fontFamilyName,\n css: _createWebFontTemplate(fontFamilyName, resource),\n // @ts-expect-error: typeof string\n resourceId: resource.uri!,\n });\n return Promise.resolve();\n }\n\n const canInjectStyle = document.head && typeof document.head.appendChild === 'function';\n if (!canInjectStyle) {\n throw new CodedError(\n 'ERR_WEB_ENVIRONMENT',\n `The browser's \\`document.head\\` element doesn't support injecting fonts.`\n );\n }\n\n const style = getStyleElement();\n document.head!.appendChild(style);\n\n const res = getFontFaceRulesMatchingResource(fontFamilyName, resource);\n if (!res.length) {\n _createWebStyle(fontFamilyName, resource);\n }\n\n if (!isFontLoadingListenerSupported()) {\n return Promise.resolve();\n }\n\n return new FontObserver(fontFamilyName, { display: resource.display }).load(null, 6000);\n },\n};\n\nconst ID = 'expo-generated-fonts';\n\nfunction getStyleElement(): HTMLStyleElement {\n const element = document.getElementById(ID);\n if (element && element instanceof HTMLStyleElement) {\n return element;\n }\n const styleElement = document.createElement('style');\n styleElement.id = ID;\n styleElement.type = 'text/css';\n return styleElement;\n}\n\nexport function _createWebFontTemplate(fontFamily: string, resource: FontResource): string {\n return `@font-face{font-family:${fontFamily};src:url(${resource.uri});font-display:${\n resource.display || FontDisplay.AUTO\n }}`;\n}\n\nfunction _createWebStyle(fontFamily: string, resource: FontResource): HTMLStyleElement {\n const fontStyle = _createWebFontTemplate(fontFamily, resource);\n\n const styleElement = getStyleElement();\n // @ts-ignore: TypeScript does not define HTMLStyleElement::styleSheet. This is just for IE and\n // possibly can be removed if it's unnecessary on IE 11.\n if (styleElement.styleSheet) {\n const styleElementIE = styleElement as any;\n styleElementIE.styleSheet.cssText = styleElementIE.styleSheet.cssText\n ? styleElementIE.styleSheet.cssText + fontStyle\n : fontStyle;\n } else {\n const textNode = document.createTextNode(fontStyle);\n styleElement.appendChild(textNode);\n }\n return styleElement;\n}\n\nfunction isFontLoadingListenerSupported(): boolean {\n const { userAgent } = window.navigator;\n // WebKit is broken https://github.com/bramstein/fontfaceobserver/issues/95\n const isIOS = !!userAgent.match(/iPad|iPhone/i);\n const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);\n // Edge is broken https://github.com/bramstein/fontfaceobserver/issues/109#issuecomment-333356795\n const isEdge = userAgent.includes('Edge');\n // Internet Explorer\n const isIE = userAgent.includes('Trident');\n // Firefox\n const isFirefox = userAgent.includes('Firefox');\n return !isSafari && !isIOS && !isEdge && !isIE && !isFirefox;\n}\n"]}
|
package/build/Font.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Font.js","sourceRoot":"","sources":["../src/Font.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAE9E,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAA+C,MAAM,cAAc,CAAC;AACxF,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAChD,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Q,EAAE;QAC3C,IAAI,OAAO,EAAE;YACX,MAAM,IAAI,UAAU,CAClB,cAAc,EACd,uDAAuD,OAAO,4GAA4G,CAC3K,CAAC;SACH;QACD,MAAM,OAAO,GAAG,mBAAmB,CAAC;QACpC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACnC,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,0BAA0B,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QACxF,OAAO;KACR;IAED,OAAO,MAAM,0BAA0B,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAC;AACxE,CAAC;AAED,KAAK,UAAU,0BAA0B,CACvC,UAAkB,EAClB,OAAkC;IAElC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE;QACvB,OAAO;KACR;SAAM;QACL,OAAO,MAAM,CAAC,UAAU,CAAC,CAAC;KAC3B;IAED,+FAA+F;IAC/F,2FAA2F;IAC3F,iGAAiG;IACjG,wBAAwB;IAExB,MAAM,cAAc,GAAG,iBAAiB,CAAC,UAAU,CAAC,CAAC;IAErD,IAAI,CAAC,cAAc,EAAE;QACnB,MAAM,IAAI,UAAU,CAAC,iBAAiB,EAAE,6BAA6B,CAAC,CAAC;KACxE;IAED,MAAM,cAAc,CAAC,WAAW,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;AAC5D,CAAC;AAED,OAAO,EAAE,WAAW,EAA+C,CAAC","sourcesContent":["import { CodedError, Platform, UnavailabilityError } from 'expo-modules-core';\n\nimport ExpoFontLoader from './ExpoFontLoader';\nimport { FontDisplay, FontSource, FontResource, UnloadFontOptions } from './Font.types';\nimport {\n getAssetForSource,\n loadSingleFontAsync,\n fontFamilyNeedsScoping,\n getNativeFontName,\n} from './FontLoader';\nimport { loaded, loadPromises } from './memory';\nimport { registerStaticFont } from './server';\n\n// @needsAudit\n// note(brentvatne): at some point we may want to warn if this is called outside of a managed app.\n/**\n * Used to transform font family names to the scoped name. This does not need to\n * be called in standalone or bare apps but it will return unscoped font family\n * names if it is called in those contexts.\n *\n * @param fontFamily Name of font to process.\n * @returns Returns a name processed for use with the [current workflow](https://docs.expo.dev/archive/managed-vs-bare/).\n */\nexport function processFontFamily(fontFamily: string | null): string | null {\n if (!fontFamily || !fontFamilyNeedsScoping(fontFamily)) {\n return fontFamily;\n }\n\n if (!isLoaded(fontFamily)) {\n if (__DEV__) {\n if (isLoading(fontFamily)) {\n console.warn(\n `You started loading the font \"${fontFamily}\", but used it before it finished loading. You need to wait for Font.loadAsync to complete before using the font.`\n );\n } else {\n console.warn(\n `fontFamily \"${fontFamily}\" is not a system font and has not been loaded through expo-font.`\n );\n }\n }\n }\n\n return `ExpoFont-${getNativeFontName(fontFamily)}`;\n}\n\n// @needsAudit\n/**\n * Synchronously detect if the font for `fontFamily` has finished loading.\n *\n * @param fontFamily The name used to load the `FontResource`.\n * @return Returns `true` if the font has fully loaded.\n */\nexport function isLoaded(fontFamily: string): boolean {\n if (Platform.OS === 'web') {\n return fontFamily in loaded || !!ExpoFontLoader.isLoaded(fontFamily);\n }\n return fontFamily in loaded || ExpoFontLoader.customNativeFonts?.includes(fontFamily);\n}\n\n// @needsAudit\n/**\n * Synchronously detect if the font for `fontFamily` is still being loaded.\n *\n * @param fontFamily The name used to load the `FontResource`.\n * @returns Returns `true` if the font is still loading.\n */\nexport function isLoading(fontFamily: string): boolean {\n return fontFamily in loadPromises;\n}\n\n// @needsAudit\n/**\n * Highly efficient method for loading fonts from static or remote resources which can then be used\n * with the platform's native text elements. In the browser this generates a `@font-face` block in\n * a shared style sheet for fonts. No CSS is needed to use this method.\n *\n * @param fontFamilyOrFontMap string or map of values that can be used as the [`fontFamily`](https://reactnative.dev/docs/text#style)\n * style prop with React Native Text elements.\n * @param source the font asset that should be loaded into the `fontFamily` namespace.\n *\n * @return Returns a promise that fulfils when the font has loaded. Often you may want to wrap the\n * method in a `try/catch/finally` to ensure the app continues if the font fails to load.\n */\nexport function loadAsync(\n fontFamilyOrFontMap: string | Record<string, FontSource>,\n source?: FontSource\n): Promise<void> {\n // NOTE(EvanBacon): Static render pass on web must be synchronous to collect all fonts.\n // Because of this, `loadAsync` doesn't use the `async` keyword and deviates from the\n // standard Expo SDK style guide.\n const isServer = Platform.OS === 'web' && typeof window === 'undefined';\n\n if (typeof fontFamilyOrFontMap === 'object') {\n if (source) {\n return Promise.reject(\n new CodedError(\n `ERR_FONT_API`,\n `No fontFamily can be used for the provided source: ${source}. The second argument of \\`loadAsync()\\` can only be used with a \\`string\\` value as the first argument.`\n )\n );\n }\n const fontMap = fontFamilyOrFontMap;\n const names = Object.keys(fontMap);\n\n if (isServer) {\n names.map((name) => registerStaticFont(name, fontMap[name]));\n return Promise.resolve();\n }\n\n return Promise.all(names.map((name) => loadFontInNamespaceAsync(name, fontMap[name]))).then(\n () => {}\n );\n }\n\n if (isServer) {\n registerStaticFont(fontFamilyOrFontMap, source);\n return Promise.resolve();\n }\n\n return loadFontInNamespaceAsync(fontFamilyOrFontMap, source);\n}\n\nasync function loadFontInNamespaceAsync(\n fontFamily: string,\n source?: FontSource | null\n): Promise<void> {\n if (!source) {\n throw new CodedError(\n `ERR_FONT_SOURCE`,\n `Cannot load null or undefined font source: { \"${fontFamily}\": ${source} }. Expected asset of type \\`FontSource\\` for fontFamily of name: \"${fontFamily}\"`\n );\n }\n\n if (loaded[fontFamily]) {\n return;\n }\n\n if (loadPromises.hasOwnProperty(fontFamily)) {\n return loadPromises[fontFamily];\n }\n\n // Important: we want all callers that concurrently try to load the same font to await the same\n // promise. If we're here, we haven't created the promise yet. To ensure we create only one\n // promise in the program, we need to create the promise synchronously without yielding the event\n // loop from this point.\n\n const asset = getAssetForSource(source);\n loadPromises[fontFamily] = (async () => {\n try {\n await loadSingleFontAsync(fontFamily, asset);\n loaded[fontFamily] = true;\n } finally {\n delete loadPromises[fontFamily];\n }\n })();\n\n await loadPromises[fontFamily];\n}\n\n// @needsAudit\n/**\n * Unloads all the custom fonts. This is used for testing.\n */\nexport async function unloadAllAsync(): Promise<void> {\n if (!ExpoFontLoader.unloadAllAsync) {\n throw new UnavailabilityError('expo-font', 'unloadAllAsync');\n }\n\n if (Object.keys(loadPromises).length) {\n throw new CodedError(\n `ERR_UNLOAD`,\n `Cannot unload fonts while they're still loading: ${Object.keys(loadPromises).join(', ')}`\n );\n }\n\n for (const fontFamily of Object.keys(loaded)) {\n delete loaded[fontFamily];\n }\n\n await ExpoFontLoader.unloadAllAsync();\n}\n\n// @needsAudit\n/**\n * Unload custom fonts matching the `fontFamily`s and display values provided.\n * Because fonts are automatically unloaded on every platform this is mostly used for testing.\n *\n * @param fontFamilyOrFontMap The name or names of the custom fonts that will be unloaded.\n * @param options When `fontFamilyOrFontMap` is a string, this should be the font source used to load\n * the custom font originally.\n */\nexport async function unloadAsync(\n fontFamilyOrFontMap: string | Record<string, UnloadFontOptions>,\n options?: UnloadFontOptions\n): Promise<void> {\n if (!ExpoFontLoader.unloadAsync) {\n throw new UnavailabilityError('expo-font', 'unloadAsync');\n }\n if (typeof fontFamilyOrFontMap === 'object') {\n if (options) {\n throw new CodedError(\n `ERR_FONT_API`,\n `No fontFamily can be used for the provided options: ${options}. The second argument of \\`unloadAsync()\\` can only be used with a \\`string\\` value as the first argument.`\n );\n }\n const fontMap = fontFamilyOrFontMap;\n const names = Object.keys(fontMap);\n await Promise.all(names.map((name) => unloadFontInNamespaceAsync(name, fontMap[name])));\n return;\n }\n\n return await unloadFontInNamespaceAsync(fontFamilyOrFontMap, options);\n}\n\nasync function unloadFontInNamespaceAsync(\n fontFamily: string,\n options?: UnloadFontOptions | null\n): Promise<void> {\n if (!loaded[fontFamily]) {\n return;\n } else {\n delete loaded[fontFamily];\n }\n\n // Important: we want all callers that concurrently try to load the same font to await the same\n // promise. If we're here, we haven't created the promise yet. To ensure we create only one\n // promise in the program, we need to create the promise synchronously without yielding the event\n // loop from this point.\n\n const nativeFontName = getNativeFontName(fontFamily);\n\n if (!nativeFontName) {\n throw new CodedError(`ERR_FONT_FAMILY`, `Cannot unload an empty name`);\n }\n\n await ExpoFontLoader.unloadAsync(nativeFontName, options);\n}\n\nexport { FontDisplay, FontSource, FontResource, UnloadFontOptions };\n"]}
|
|
1
|
+
{"version":3,"file":"Font.js","sourceRoot":"","sources":["../src/Font.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAE9E,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAA+C,MAAM,cAAc,CAAC;AACxF,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,sBAAsB,EACtB,iBAAiB,GAClB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAE9C,cAAc;AACd,kGAAkG;AAClG;;;;;;;GAOG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAAyB;IACzD,IAAI,CAAC,UAAU,IAAI,CAAC,sBAAsB,CAAC,UAAU,CAAC,EAAE,CAAC;QACvD,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;QAC1B,IAAI,OAAO,EAAE,CAAC;YACZ,IAAI,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC;gBAC1B,OAAO,CAAC,IAAI,CACV,iCAAiC,UAAU,mHAAmH,CAC/J,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,IAAI,CACV,eAAe,UAAU,mEAAmE,CAC7F,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,YAAY,iBAAiB,CAAC,UAAU,CAAC,EAAE,CAAC;AACrD,CAAC;AAED,c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,CAAC;QACxF,OAAO;IACT,CAAC;IAED,OAAO,MAAM,0BAA0B,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAC;AACxE,CAAC;AAED,KAAK,UAAU,0BAA0B,CACvC,UAAkB,EAClB,OAAkC;IAElC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;QACxB,OAAO;IACT,CAAC;SAAM,CAAC;QACN,OAAO,MAAM,CAAC,UAAU,CAAC,CAAC;IAC5B,CAAC;IAED,+FAA+F;IAC/F,2FAA2F;IAC3F,iGAAiG;IACjG,wBAAwB;IAExB,MAAM,cAAc,GAAG,iBAAiB,CAAC,UAAU,CAAC,CAAC;IAErD,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,MAAM,IAAI,UAAU,CAAC,iBAAiB,EAAE,6BAA6B,CAAC,CAAC;IACzE,CAAC;IAED,MAAM,cAAc,CAAC,WAAW,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;AAC5D,CAAC;AAED,OAAO,EAAE,WAAW,EAA+C,CAAC","sourcesContent":["import { CodedError, Platform, UnavailabilityError } from 'expo-modules-core';\n\nimport ExpoFontLoader from './ExpoFontLoader';\nimport { FontDisplay, FontSource, FontResource, UnloadFontOptions } from './Font.types';\nimport {\n getAssetForSource,\n loadSingleFontAsync,\n fontFamilyNeedsScoping,\n getNativeFontName,\n} from './FontLoader';\nimport { loaded, loadPromises } from './memory';\nimport { registerStaticFont } from './server';\n\n// @needsAudit\n// note(brentvatne): at some point we may want to warn if this is called outside of a managed app.\n/**\n * Used to transform font family names to the scoped name. This does not need to\n * be called in standalone or bare apps but it will return unscoped font family\n * names if it is called in those contexts.\n *\n * @param fontFamily Name of font to process.\n * @returns Returns a name processed for use with the [current workflow](https://docs.expo.dev/archive/managed-vs-bare/).\n */\nexport function processFontFamily(fontFamily: string | null): string | null {\n if (!fontFamily || !fontFamilyNeedsScoping(fontFamily)) {\n return fontFamily;\n }\n\n if (!isLoaded(fontFamily)) {\n if (__DEV__) {\n if (isLoading(fontFamily)) {\n console.warn(\n `You started loading the font \"${fontFamily}\", but used it before it finished loading. You need to wait for Font.loadAsync to complete before using the font.`\n );\n } else {\n console.warn(\n `fontFamily \"${fontFamily}\" is not a system font and has not been loaded through expo-font.`\n );\n }\n }\n }\n\n return `ExpoFont-${getNativeFontName(fontFamily)}`;\n}\n\n// @needsAudit\n/**\n * Synchronously detect if the font for `fontFamily` has finished loading.\n *\n * @param fontFamily The name used to load the `FontResource`.\n * @return Returns `true` if the font has fully loaded.\n */\nexport function isLoaded(fontFamily: string): boolean {\n if (Platform.OS === 'web') {\n return fontFamily in loaded || !!ExpoFontLoader.isLoaded(fontFamily);\n }\n return fontFamily in loaded || ExpoFontLoader.customNativeFonts?.includes(fontFamily);\n}\n\n// @needsAudit\n/**\n * Synchronously detect if the font for `fontFamily` is still being loaded.\n *\n * @param fontFamily The name used to load the `FontResource`.\n * @returns Returns `true` if the font is still loading.\n */\nexport function isLoading(fontFamily: string): boolean {\n return fontFamily in loadPromises;\n}\n\n// @needsAudit\n/**\n * Highly efficient method for loading fonts from static or remote resources which can then be used\n * with the platform's native text elements. In the browser this generates a `@font-face` block in\n * a shared style sheet for fonts. No CSS is needed to use this method.\n *\n * @param fontFamilyOrFontMap string or map of values that can be used as the [`fontFamily`](https://reactnative.dev/docs/text#style)\n * style prop with React Native Text elements.\n * @param source the font asset that should be loaded into the `fontFamily` namespace.\n *\n * @return Returns a promise that fulfils when the font has loaded. Often you may want to wrap the\n * method in a `try/catch/finally` to ensure the app continues if the font fails to load.\n */\nexport function loadAsync(\n fontFamilyOrFontMap: string | Record<string, FontSource>,\n source?: FontSource\n): Promise<void> {\n // NOTE(EvanBacon): Static render pass on web must be synchronous to collect all fonts.\n // Because of this, `loadAsync` doesn't use the `async` keyword and deviates from the\n // standard Expo SDK style guide.\n const isServer = Platform.OS === 'web' && typeof window === 'undefined';\n\n if (typeof fontFamilyOrFontMap === 'object') {\n if (source) {\n return Promise.reject(\n new CodedError(\n `ERR_FONT_API`,\n `No fontFamily can be used for the provided source: ${source}. The second argument of \\`loadAsync()\\` can only be used with a \\`string\\` value as the first argument.`\n )\n );\n }\n const fontMap = fontFamilyOrFontMap;\n const names = Object.keys(fontMap);\n\n if (isServer) {\n names.map((name) => registerStaticFont(name, fontMap[name]));\n return Promise.resolve();\n }\n\n return Promise.all(names.map((name) => loadFontInNamespaceAsync(name, fontMap[name]))).then(\n () => {}\n );\n }\n\n if (isServer) {\n registerStaticFont(fontFamilyOrFontMap, source);\n return Promise.resolve();\n }\n\n return loadFontInNamespaceAsync(fontFamilyOrFontMap, source);\n}\n\nasync function loadFontInNamespaceAsync(\n fontFamily: string,\n source?: FontSource | null\n): Promise<void> {\n if (!source) {\n throw new CodedError(\n `ERR_FONT_SOURCE`,\n `Cannot load null or undefined font source: { \"${fontFamily}\": ${source} }. Expected asset of type \\`FontSource\\` for fontFamily of name: \"${fontFamily}\"`\n );\n }\n\n if (loaded[fontFamily]) {\n return;\n }\n\n if (loadPromises.hasOwnProperty(fontFamily)) {\n return loadPromises[fontFamily];\n }\n\n // Important: we want all callers that concurrently try to load the same font to await the same\n // promise. If we're here, we haven't created the promise yet. To ensure we create only one\n // promise in the program, we need to create the promise synchronously without yielding the event\n // loop from this point.\n\n const asset = getAssetForSource(source);\n loadPromises[fontFamily] = (async () => {\n try {\n await loadSingleFontAsync(fontFamily, asset);\n loaded[fontFamily] = true;\n } finally {\n delete loadPromises[fontFamily];\n }\n })();\n\n await loadPromises[fontFamily];\n}\n\n// @needsAudit\n/**\n * Unloads all the custom fonts. This is used for testing.\n */\nexport async function unloadAllAsync(): Promise<void> {\n if (!ExpoFontLoader.unloadAllAsync) {\n throw new UnavailabilityError('expo-font', 'unloadAllAsync');\n }\n\n if (Object.keys(loadPromises).length) {\n throw new CodedError(\n `ERR_UNLOAD`,\n `Cannot unload fonts while they're still loading: ${Object.keys(loadPromises).join(', ')}`\n );\n }\n\n for (const fontFamily of Object.keys(loaded)) {\n delete loaded[fontFamily];\n }\n\n await ExpoFontLoader.unloadAllAsync();\n}\n\n// @needsAudit\n/**\n * Unload custom fonts matching the `fontFamily`s and display values provided.\n * Because fonts are automatically unloaded on every platform this is mostly used for testing.\n *\n * @param fontFamilyOrFontMap The name or names of the custom fonts that will be unloaded.\n * @param options When `fontFamilyOrFontMap` is a string, this should be the font source used to load\n * the custom font originally.\n */\nexport async function unloadAsync(\n fontFamilyOrFontMap: string | Record<string, UnloadFontOptions>,\n options?: UnloadFontOptions\n): Promise<void> {\n if (!ExpoFontLoader.unloadAsync) {\n throw new UnavailabilityError('expo-font', 'unloadAsync');\n }\n if (typeof fontFamilyOrFontMap === 'object') {\n if (options) {\n throw new CodedError(\n `ERR_FONT_API`,\n `No fontFamily can be used for the provided options: ${options}. The second argument of \\`unloadAsync()\\` can only be used with a \\`string\\` value as the first argument.`\n );\n }\n const fontMap = fontFamilyOrFontMap;\n const names = Object.keys(fontMap);\n await Promise.all(names.map((name) => unloadFontInNamespaceAsync(name, fontMap[name])));\n return;\n }\n\n return await unloadFontInNamespaceAsync(fontFamilyOrFontMap, options);\n}\n\nasync function unloadFontInNamespaceAsync(\n fontFamily: string,\n options?: UnloadFontOptions | null\n): Promise<void> {\n if (!loaded[fontFamily]) {\n return;\n } else {\n delete loaded[fontFamily];\n }\n\n // Important: we want all callers that concurrently try to load the same font to await the same\n // promise. If we're here, we haven't created the promise yet. To ensure we create only one\n // promise in the program, we need to create the promise synchronously without yielding the event\n // loop from this point.\n\n const nativeFontName = getNativeFontName(fontFamily);\n\n if (!nativeFontName) {\n throw new CodedError(`ERR_FONT_FAMILY`, `Cannot unload an empty name`);\n }\n\n await ExpoFontLoader.unloadAsync(nativeFontName, options);\n}\n\nexport { FontDisplay, FontSource, FontResource, UnloadFontOptions };\n"]}
|
package/build/Font.types.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Asset } from 'expo-asset';
|
|
2
2
|
/**
|
|
3
|
-
* The different types of assets you can provide to the [`loadAsync()`](#
|
|
3
|
+
* The different types of assets you can provide to the [`loadAsync()`](#loadasyncfontfamilyorfontmap-source) function.
|
|
4
4
|
* A font source can be a URI, a module ID, or an Expo Asset.
|
|
5
5
|
*/
|
|
6
6
|
export type FontSource = string | number | Asset | FontResource;
|
|
7
7
|
/**
|
|
8
8
|
* An object used to dictate the resource that is loaded into the provided font namespace when used
|
|
9
|
-
* with [`loadAsync`](#
|
|
9
|
+
* with [`loadAsync`](#loadasyncfontfamilyorfontmap-source).
|
|
10
10
|
*/
|
|
11
11
|
export type FontResource = {
|
|
12
12
|
uri?: string | number;
|
package/build/Font.types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Font.types.js","sourceRoot":"","sources":["../src/Font.types.ts"],"names":[],"mappings":"AAwBA,cAAc;AACd;;;;;;;;;GASG;AACH,MAAM,CAAN,IAAY,WA8BX;AA9BD,WAAY,WAAW;IACrB;;;;OAIG;IACH,4BAAa,CAAA;IACb;;;OAGG;IACH,4BAAa,CAAA;IACb;;;OAGG;IACH,8BAAe,CAAA;IACf;;;;;;OAMG;IACH,oCAAqB,CAAA;IACrB;;;OAGG;IACH,oCAAqB,CAAA;AACvB,CAAC,EA9BW,WAAW,KAAX,WAAW,QA8BtB","sourcesContent":["import { Asset } from 'expo-asset';\n\n// @needsAudit\n/**\n * The different types of assets you can provide to the [`loadAsync()`](#
|
|
1
|
+
{"version":3,"file":"Font.types.js","sourceRoot":"","sources":["../src/Font.types.ts"],"names":[],"mappings":"AAwBA,cAAc;AACd;;;;;;;;;GASG;AACH,MAAM,CAAN,IAAY,WA8BX;AA9BD,WAAY,WAAW;IACrB;;;;OAIG;IACH,4BAAa,CAAA;IACb;;;OAGG;IACH,4BAAa,CAAA;IACb;;;OAGG;IACH,8BAAe,CAAA;IACf;;;;;;OAMG;IACH,oCAAqB,CAAA;IACrB;;;OAGG;IACH,oCAAqB,CAAA;AACvB,CAAC,EA9BW,WAAW,KAAX,WAAW,QA8BtB","sourcesContent":["import { Asset } from 'expo-asset';\n\n// @needsAudit\n/**\n * The different types of assets you can provide to the [`loadAsync()`](#loadasyncfontfamilyorfontmap-source) function.\n * A font source can be a URI, a module ID, or an Expo Asset.\n */\nexport type FontSource = string | number | Asset | FontResource;\n\n// @needsAudit\n/**\n * An object used to dictate the resource that is loaded into the provided font namespace when used\n * with [`loadAsync`](#loadasyncfontfamilyorfontmap-source).\n */\nexport type FontResource = {\n uri?: string | number;\n /**\n * Sets the [`font-display`](#fontdisplay) property for a given typeface in the browser.\n * @platform web\n */\n display?: FontDisplay;\n default?: string;\n};\n\n// @needsAudit\n/**\n * Sets the [font-display](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-display)\n * for a given typeface. The default font value on web is `FontDisplay.AUTO`.\n * Even though setting the `fontDisplay` does nothing on native platforms, the default behavior\n * emulates `FontDisplay.SWAP` on flagship devices like iOS, Samsung, Pixel, etc. Default\n * functionality varies on One Plus devices. In the browser this value is set in the generated\n * `@font-face` CSS block and not as a style property meaning you cannot dynamically change this\n * value based on the element it's used in.\n * @platform web\n */\nexport enum FontDisplay {\n /**\n * __(Default)__ The font display strategy is defined by the user agent or platform.\n * This generally defaults to the text being invisible until the font is loaded.\n * Good for buttons or banners that require a specific treatment.\n */\n AUTO = 'auto',\n /**\n * Fallback text is rendered immediately with a default font while the desired font is loaded.\n * This is good for making the content appear to load instantly and is usually preferred.\n */\n SWAP = 'swap',\n /**\n * The text will be invisible until the font has loaded. If the font fails to load then nothing\n * will appear - it's best to turn this off when debugging missing text.\n */\n BLOCK = 'block',\n /**\n * Splits the behavior between `SWAP` and `BLOCK`.\n * There will be a [100ms timeout](https://developers.google.com/web/updates/2016/02/font-display?hl=en)\n * where the text with a custom font is invisible, after that the text will either swap to the\n * styled text or it'll show the unstyled text and continue to load the custom font. This is good\n * for buttons that need a custom font but should also be quickly available to screen-readers.\n */\n FALLBACK = 'fallback',\n /**\n * This works almost identically to `FALLBACK`, the only difference is that the browser will\n * decide to load the font based on slow connection speed or critical resource demand.\n */\n OPTIONAL = 'optional',\n}\n\n// @needsAudit\n/**\n * Object used to query fonts for unloading.\n */\nexport type UnloadFontOptions = Pick<FontResource, 'display'>;\n"]}
|
package/build/FontHooks.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { FontSource } from './Font.types';
|
|
|
3
3
|
* ```ts
|
|
4
4
|
* const [loaded, error] = useFonts({ ... });
|
|
5
5
|
* ```
|
|
6
|
-
* Load a map of fonts with [`loadAsync`](#
|
|
6
|
+
* Load a map of fonts with [`loadAsync`](#loadasyncfontfamilyorfontmap-source). This returns a `boolean` if the fonts are
|
|
7
7
|
* loaded and ready to use. It also returns an error if something went wrong, to use in development.
|
|
8
8
|
*
|
|
9
9
|
* > Note, the fonts are not "reloaded" when you dynamically change the font map.
|
package/build/FontHooks.js
CHANGED
|
@@ -30,7 +30,7 @@ function useStaticFonts(map) {
|
|
|
30
30
|
* ```ts
|
|
31
31
|
* const [loaded, error] = useFonts({ ... });
|
|
32
32
|
* ```
|
|
33
|
-
* Load a map of fonts with [`loadAsync`](#
|
|
33
|
+
* Load a map of fonts with [`loadAsync`](#loadasyncfontfamilyorfontmap-source). This returns a `boolean` if the fonts are
|
|
34
34
|
* loaded and ready to use. It also returns an error if something went wrong, to use in development.
|
|
35
35
|
*
|
|
36
36
|
* > Note, the fonts are not "reloaded" when you dynamically change the font map.
|
package/build/FontHooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FontHooks.js","sourceRoot":"","sources":["../src/FontHooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAG7C,SAAS,WAAW,CAAC,GAAwC;IAC3D,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;
|
|
1
|
+
{"version":3,"file":"FontHooks.js","sourceRoot":"","sources":["../src/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AC","sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { loadAsync, isLoaded } from './Font';\nimport { FontSource } from './Font.types';\n\nfunction isMapLoaded(map: string | Record<string, FontSource>) {\n if (typeof map === 'string') {\n return isLoaded(map);\n } else {\n return Object.keys(map).every((fontFamily) => isLoaded(fontFamily));\n }\n}\n\nfunction useRuntimeFonts(map: string | Record<string, FontSource>): [boolean, Error | null] {\n const [loaded, setLoaded] = useState(\n // For web rehydration, we need to check if the fonts are already loaded during the static render.\n // Native will also benefit from this optimization.\n isMapLoaded(map)\n );\n const [error, setError] = useState<Error | null>(null);\n\n useEffect(() => {\n loadAsync(map)\n .then(() => setLoaded(true))\n .catch(setError);\n }, []);\n\n return [loaded, error];\n}\n\nfunction useStaticFonts(map: string | Record<string, FontSource>): [boolean, Error | null] {\n loadAsync(map);\n return [true, null];\n}\n\n// @needsAudit\n/**\n * ```ts\n * const [loaded, error] = useFonts({ ... });\n * ```\n * Load a map of fonts with [`loadAsync`](#loadasyncfontfamilyorfontmap-source). This returns a `boolean` if the fonts are\n * loaded and ready to use. It also returns an error if something went wrong, to use in development.\n *\n * > Note, the fonts are not \"reloaded\" when you dynamically change the font map.\n *\n * @param map A map of `fontFamily`s to [`FontSource`](#fontsource)s. After loading the font you can\n * use the key in the `fontFamily` style prop of a `Text` element.\n *\n * @return\n * - __loaded__ (`boolean`) - A boolean to detect if the font for `fontFamily` has finished\n * loading.\n * - __error__ (`Error | null`) - An error encountered when loading the fonts.\n */\nexport const useFonts: (map: string | Record<string, FontSource>) => [boolean, Error | null] =\n typeof window === 'undefined' ? useStaticFonts : useRuntimeFonts;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FontLoader.d.ts","sourceRoot":"","sources":["../src/FontLoader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"FontLoader.d.ts","sourceRoot":"","sources":["../src/FontLoader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAKnC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAIxD,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAO5D;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,UAAU,GAAG,KAAK,GAAG,YAAY,CAiB1E;AAED,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,KAAK,GAAG,YAAY,GAC1B,OAAO,CAAC,IAAI,CAAC,CAcf;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAMtD"}
|
package/build/FontLoader.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { Asset } from 'expo-asset';
|
|
2
2
|
import Constants from 'expo-constants';
|
|
3
3
|
import { CodedError } from 'expo-modules-core';
|
|
4
|
-
import { Platform } from 'react-native';
|
|
5
4
|
import ExpoFontLoader from './ExpoFontLoader';
|
|
6
|
-
const
|
|
7
|
-
const isInIOSStandalone = Constants.appOwnership === 'standalone' && Platform.OS === 'ios';
|
|
5
|
+
const isInExpoGo = Constants.appOwnership === 'expo';
|
|
8
6
|
export function fontFamilyNeedsScoping(name) {
|
|
9
|
-
return (
|
|
7
|
+
return (isInExpoGo &&
|
|
10
8
|
!Constants.systemFonts.includes(name) &&
|
|
11
9
|
name !== 'System' &&
|
|
12
10
|
!name.includes(Constants.sessionId));
|
package/build/FontLoader.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FontLoader.js","sourceRoot":"","sources":["../src/FontLoader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,SAAS,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3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,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC;QACzB,MAAM,IAAI,UAAU,CAClB,iBAAiB,EACjB,mFAAmF,CACpF,CAAC;IACJ,CAAC;IAED,MAAM,KAAK,CAAC,aAAa,EAAE,CAAC;IAC5B,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;QACtB,MAAM,IAAI,UAAU,CAAC,cAAc,EAAE,sCAAsC,IAAI,GAAG,CAAC,CAAC;IACtF,CAAC;IACD,MAAM,cAAc,CAAC,SAAS,CAAC,iBAAiB,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;AAC1E,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,IAAI,sBAAsB,CAAC,IAAI,CAAC,EAAE,CAAC;QACjC,OAAO,GAAG,SAAS,CAAC,SAAS,IAAI,IAAI,EAAE,CAAC;IAC1C,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import { Asset } from 'expo-asset';\nimport Constants from 'expo-constants';\nimport { CodedError } from 'expo-modules-core';\n\nimport ExpoFontLoader from './ExpoFontLoader';\nimport { FontResource, FontSource } from './Font.types';\n\nconst isInExpoGo = Constants.appOwnership === 'expo';\n\nexport function fontFamilyNeedsScoping(name: string): boolean {\n return (\n isInExpoGo &&\n !Constants.systemFonts.includes(name) &&\n name !== 'System' &&\n !name.includes(Constants.sessionId)\n );\n}\n\nexport function getAssetForSource(source: FontSource): Asset | FontResource {\n if (source instanceof Asset) {\n return source;\n }\n\n if (typeof source === 'string') {\n return Asset.fromURI(source);\n } else if (typeof source === 'number') {\n return Asset.fromModule(source);\n } else if (typeof source === 'object' && typeof source.uri !== 'undefined') {\n return getAssetForSource(source.uri);\n }\n\n // @ts-ignore Error: Type 'string' is not assignable to type 'Asset'\n // We can't have a string here, we would have thrown an error if !isWeb\n // or returned Asset.fromModule if isWeb.\n return source;\n}\n\nexport async function loadSingleFontAsync(\n name: string,\n input: Asset | FontResource\n): Promise<void> {\n const asset = input as Asset;\n if (!asset.downloadAsync) {\n throw new CodedError(\n `ERR_FONT_SOURCE`,\n '`loadSingleFontAsync` expected resource of type `Asset` from expo-asset on native'\n );\n }\n\n await asset.downloadAsync();\n if (!asset.downloaded) {\n throw new CodedError(`ERR_DOWNLOAD`, `Failed to download asset for font \"${name}\"`);\n }\n await ExpoFontLoader.loadAsync(getNativeFontName(name), asset.localUri);\n}\n\nexport function getNativeFontName(name: string): string {\n if (fontFamilyNeedsScoping(name)) {\n return `${Constants.sessionId}-${name}`;\n } else {\n return name;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FontLoader.web.js","sourceRoot":"","sources":["../src/FontLoader.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAA4B,WAAW,EAAE,MAAM,cAAc,CAAC;AAErE,SAAS,iBAAiB,CAAC,KAAU;IACnC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;
|
|
1
|
+
{"version":3,"file":"FontLoader.web.js","sourceRoot":"","sources":["../src/FontLoader.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAA4B,WAAW,EAAE,MAAM,cAAc,CAAC;AAErE,SAAS,iBAAiB,CAAC,KAAU;IACnC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,IAAI,IAAI,CAAC;IACvB,CAAC;SAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACrC,OAAO,KAAK,C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E,CAAC;QAC/F,uBAAuB,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;IAED,IAAI,CAAC;QACH,OAAO,cAAc,CAAC,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC/C,CAAC;IAAC,MAAM,CAAC;QACP,SAAS;IACX,CAAC;IAED,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;AAC3B,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import { Asset } from 'expo-asset';\nimport { CodedError } from 'expo-modules-core';\n\nimport ExpoFontLoader from './ExpoFontLoader';\nimport { FontResource, FontSource, FontDisplay } from './Font.types';\n\nfunction uriFromFontSource(asset: any): string | null {\n if (typeof asset === 'string') {\n return asset || null;\n } else if (typeof asset === 'object') {\n return asset.uri || asset.localUri || asset.default || null;\n } else if (typeof asset === 'number') {\n return uriFromFontSource(Asset.fromModule(asset));\n }\n return null;\n}\n\nfunction displayFromFontSource(asset: any): FontDisplay | undefined {\n return asset.display || FontDisplay.AUTO;\n}\n\nexport function fontFamilyNeedsScoping(name: string): boolean {\n return false;\n}\n\nexport function getAssetForSource(source: FontSource): Asset | FontResource {\n const uri = uriFromFontSource(source);\n const display = displayFromFontSource(source);\n\n if (!uri || typeof uri !== 'string') {\n throwInvalidSourceError(uri);\n }\n\n return {\n uri: uri!,\n display,\n };\n}\n\nfunction throwInvalidSourceError(source: any): never {\n let type: string = typeof source;\n if (type === 'object') type = JSON.stringify(source, null, 2);\n throw new CodedError(\n `ERR_FONT_SOURCE`,\n `Expected font asset of type \\`string | FontResource | Asset\\` instead got: ${type}`\n );\n}\n\n// NOTE(EvanBacon): No async keyword!\nexport function loadSingleFontAsync(name: string, input: Asset | FontResource): Promise<void> {\n if (typeof input !== 'object' || typeof input.uri !== 'string' || (input as any).downloadAsync) {\n throwInvalidSourceError(input);\n }\n\n try {\n return ExpoFontLoader.loadAsync(name, input);\n } catch {\n // No-op.\n }\n\n return Promise.resolve();\n}\n\nexport function getNativeFontName(name: string): string {\n return name;\n}\n"]}
|
package/build/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEtE;;;GAGG;AACH,MAAM,UAAU,kBAAkB;IAChC,OAAO,cAAc,CAAC,kBAAkB,EAAE,CAAC;AAC7C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB;IAChC,OAAO,cAAc,CAAC,kBAAkB,EAAE,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,UAAkB,EAAE,MAA0B;IAC/E,2BAA2B;IAC3B,IAAI,CAAC,MAAM,EAAE;
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEtE;;;GAGG;AACH,MAAM,UAAU,kBAAkB;IAChC,OAAO,cAAc,CAAC,kBAAkB,EAAE,CAAC;AAC7C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB;IAChC,OAAO,cAAc,CAAC,kBAAkB,EAAE,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,UAAkB,EAAE,MAA0B;IAC/E,2BAA2B;IAC3B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,UAAU,CAClB,iBAAiB,EACjB,iDAAiD,UAAU,MAAM,MAAM,sEAAsE,UAAU,GAAG,CAC3J,CAAC;IACJ,CAAC;IACD,MAAM,KAAK,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAExC,mBAAmB,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;AACzC,CAAC","sourcesContent":["import { CodedError } from 'expo-modules-core';\n\nimport ExpoFontLoader from './ExpoFontLoader';\nimport { FontSource } from './Font.types';\nimport { getAssetForSource, loadSingleFontAsync } from './FontLoader';\n\n/**\n * @returns the server resources that should be statically extracted.\n * @private\n */\nexport function getServerResources(): string[] {\n return ExpoFontLoader.getServerResources();\n}\n\n/**\n * @returns clear the server resources from the global scope.\n * @private\n */\nexport function resetServerContext() {\n return ExpoFontLoader.resetServerContext();\n}\n\nexport function registerStaticFont(fontFamily: string, source?: FontSource | null) {\n // MUST BE A SYNC FUNCTION!\n if (!source) {\n throw new CodedError(\n `ERR_FONT_SOURCE`,\n `Cannot load null or undefined font source: { \"${fontFamily}\": ${source} }. Expected asset of type \\`FontSource\\` for fontFamily of name: \"${fontFamily}\"`\n );\n }\n const asset = getAssetForSource(source);\n\n loadSingleFontAsync(fontFamily, asset);\n}\n"]}
|
package/expo-module.config.json
CHANGED
|
@@ -3,7 +3,7 @@ require 'json'
|
|
|
3
3
|
package = JSON.parse(File.read(File.join(__dir__, '..', 'package.json')))
|
|
4
4
|
|
|
5
5
|
Pod::Spec.new do |s|
|
|
6
|
-
s.name = '
|
|
6
|
+
s.name = 'ExpoFont'
|
|
7
7
|
s.version = package['version']
|
|
8
8
|
s.summary = package['description']
|
|
9
9
|
s.description = package['description']
|
|
@@ -15,15 +15,16 @@ Pod::Spec.new do |s|
|
|
|
15
15
|
:osx => '10.15',
|
|
16
16
|
:tvos => '13.4'
|
|
17
17
|
}
|
|
18
|
+
s.swift_version = '5.4'
|
|
18
19
|
s.source = { git: 'https://github.com/expo/expo.git' }
|
|
19
20
|
s.static_framework = true
|
|
20
21
|
|
|
21
22
|
s.dependency 'ExpoModulesCore'
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
# Swift/Objective-C compatibility
|
|
25
|
+
s.pod_target_xcconfig = {
|
|
26
|
+
'DEFINES_MODULE' => 'YES'
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
s.source_files = "**/*.{h,m,swift}"
|
|
29
30
|
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import ExpoModulesCore
|
|
2
|
+
|
|
3
|
+
internal final class FontFileNotFoundException: GenericException<String> {
|
|
4
|
+
override var reason: String {
|
|
5
|
+
"Font file '\(param)' doesn't exist"
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
internal final class FontCreationFailedException: GenericException<String> {
|
|
10
|
+
override var reason: String {
|
|
11
|
+
"Could not create font from loaded data for '\(param)'"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
internal final class FontRegistrationFailedException: GenericException<CFError> {
|
|
16
|
+
override var reason: String {
|
|
17
|
+
"Registering '\(param)' font failed with message: '\(param.localizedDescription)'"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import ExpoModulesCore
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
A registry of font family aliases mapped to their real font family names.
|
|
5
|
+
*/
|
|
6
|
+
private var fontFamilyAliases = [String: String]()
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
A flag that is set to `true` when the ``UIFont.fontNames(forFamilyName:)`` is already swizzled.
|
|
10
|
+
*/
|
|
11
|
+
private var hasSwizzled = false
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
Manages the font family aliases and swizzles the `UIFont` class.
|
|
15
|
+
*/
|
|
16
|
+
internal struct FontFamilyAliasManager {
|
|
17
|
+
/**
|
|
18
|
+
Whether the given alias has already been set.
|
|
19
|
+
*/
|
|
20
|
+
internal static func hasAlias(_ familyNameAlias: String) -> Bool {
|
|
21
|
+
return fontFamilyAliases[familyNameAlias] != nil
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
Sets the alias for the given family name.
|
|
26
|
+
If the alias has already been set, its family name will be overriden.
|
|
27
|
+
*/
|
|
28
|
+
internal static func setAlias(_ familyNameAlias: String, forFamilyName familyName: String) {
|
|
29
|
+
maybeSwizzleUIFont()
|
|
30
|
+
fontFamilyAliases[familyNameAlias] = familyName
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
Returns the family name for the given alias or `nil` when it's not set yet.
|
|
35
|
+
*/
|
|
36
|
+
internal static func familyName(forAlias familyNameAlias: String) -> String? {
|
|
37
|
+
return fontFamilyAliases[familyNameAlias]
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
Swizzles ``UIFont.fontNames(forFamilyName:)`` to support font family aliases.
|
|
43
|
+
This is necessary because the user provides a custom family name that is then used in stylesheets,
|
|
44
|
+
however the font usually has a different name encoded in the binary, thus the system may use a different name.
|
|
45
|
+
*/
|
|
46
|
+
private func maybeSwizzleUIFont() {
|
|
47
|
+
if hasSwizzled {
|
|
48
|
+
return
|
|
49
|
+
}
|
|
50
|
+
let originalMethod = class_getClassMethod(UIFont.self, #selector(UIFont.fontNames(forFamilyName:)))
|
|
51
|
+
let newMethod = class_getClassMethod(UIFont.self, #selector(UIFont._expo_fontNames(forFamilyName:)))
|
|
52
|
+
|
|
53
|
+
if let originalMethod, let newMethod {
|
|
54
|
+
method_exchangeImplementations(originalMethod, newMethod)
|
|
55
|
+
} else {
|
|
56
|
+
log.error("expo-font is unable to swizzle `UIFont.fontNames(forFamilyName:)`")
|
|
57
|
+
}
|
|
58
|
+
hasSwizzled = true
|
|
59
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import ExpoModulesCore
|
|
2
|
+
|
|
3
|
+
public final class FontLoaderModule: Module {
|
|
4
|
+
public func definition() -> ModuleDefinition {
|
|
5
|
+
Name("ExpoFontLoader")
|
|
6
|
+
|
|
7
|
+
Property("customNativeFonts") {
|
|
8
|
+
return queryCustomNativeFonts()
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
AsyncFunction("loadAsync") { (fontFamilyAlias: String, localUri: URL) in
|
|
12
|
+
// If the font was already registered, unregister it first. Otherwise CTFontManagerRegisterGraphicsFont
|
|
13
|
+
// would fail because of a duplicated font name when the app reloads or someone wants to override a font.
|
|
14
|
+
if let familyName = FontFamilyAliasManager.familyName(forAlias: fontFamilyAlias) {
|
|
15
|
+
try unregisterFont(named: familyName)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Create a font object from the given file
|
|
19
|
+
let font = try loadFont(fromPath: localUri.path, alias: fontFamilyAlias)
|
|
20
|
+
|
|
21
|
+
// Register the font
|
|
22
|
+
try registerFont(font)
|
|
23
|
+
|
|
24
|
+
// The real font name might be different than it's been requested by the user,
|
|
25
|
+
// so we save the provided name as an alias.
|
|
26
|
+
if let fullName = font.fullName as? String {
|
|
27
|
+
FontFamilyAliasManager.setAlias(fontFamilyAlias, forFamilyName: fullName)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|