feat(smart-app): implement complete mobile app MVP

- App.tsx: full navigation (Auth stack + Main tabs with 5 screens)
- Auth: LoginScreen, RegisterScreen, ForgotPasswordScreen
- HomeScreen: dashboard with IoT metrics, weather widget, alerts, quick actions, sensors
- MapScreen: interactive map with layer toggles (6 layers)
- MarketplaceScreen: categories (6), products (5), search
- ChatScreen: AI chat with quick prompts (4), bot responses
- ProfileScreen: user info, stats, menu (9 items), logout
- AlertsScreen: alert list with severity, acknowledge
- SensorsScreen: sensor list with type filters (6 types), search
- ZonesScreen: zone cards with stats
- SettingsScreen: language picker (FR/EN/ES/DE), privacy, about
- Stores: iotStore (sensors, zones, alerts), notificationStore, uiStore + i18n
- Hooks: useSensors, useAlerts, useNotifications, useLocation
- Components: Card, Button, LoadingSpinner, ErrorBoundary, Header
- Services: iotService, notificationService (with axios API client)
- Utils: formatters (temp, AQI, noise, dates), validators (email, password, IBAN)
- Theme: colors.ts with full design system (Blue Ocean palette)
- Ditto: fixed MongoDB connection, new JWT secrets, official gateway image
This commit is contained in:
Eric FELIXINE
2026-06-01 18:00:35 -04:00
parent 08ca495bde
commit e30ae8ed09
35578 changed files with 3703534 additions and 43 deletions

View File

@@ -0,0 +1,3 @@
declare const _default: any;
export default _default;
//# sourceMappingURL=ExpoFontLoader.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"ExpoFontLoader.d.ts","sourceRoot":"","sources":["../src/ExpoFontLoader.ts"],"names":[],"mappings":";AACA,wBAAqD"}

View File

@@ -0,0 +1,3 @@
import { requireNativeModule } from 'expo-modules-core';
export default requireNativeModule('ExpoFontLoader');
//# sourceMappingURL=ExpoFontLoader.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"ExpoFontLoader.js","sourceRoot":"","sources":["../src/ExpoFontLoader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,eAAe,mBAAmB,CAAC,gBAAgB,CAAC,CAAC","sourcesContent":["import { requireNativeModule } from 'expo-modules-core';\nexport default requireNativeModule('ExpoFontLoader');\n"]}

View File

@@ -0,0 +1,13 @@
import { UnloadFontOptions } from './Font';
import { FontResource } from './Font.types';
declare const _default: {
unloadAllAsync(): Promise<void>;
unloadAsync(fontFamilyName: string, options?: UnloadFontOptions): Promise<void>;
getServerResources(): string[];
resetServerContext(): void;
isLoaded(fontFamilyName: string, resource?: UnloadFontOptions): boolean;
loadAsync(fontFamilyName: string, resource: FontResource): Promise<void>;
};
export default _default;
export declare function _createWebFontTemplate(fontFamily: string, resource: FontResource): string;
//# sourceMappingURL=ExpoFontLoader.web.d.ts.map

View File

@@ -0,0 +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,QAAQ,IAAI,CAAC;gCASH,MAAM,YAAY,iBAAiB,GAAG,QAAQ,IAAI,CAAC;0BAS/D,MAAM,EAAE;;6BAqBL,MAAM,aAAY,iBAAiB,GAAQ,OAAO;8BAUjD,MAAM,YAAY,YAAY,GAAG,QAAQ,IAAI,CAAC;;AAlD1E,wBAmFE;AAeF,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,GAAG,MAAM,CAIzF"}

View File

@@ -0,0 +1,174 @@
import { CodedError, Platform } from 'expo-modules-core';
import FontObserver from 'fontfaceobserver';
import { FontDisplay } from './Font.types';
function getFontFaceStyleSheet() {
if (!Platform.isDOMAvailable) {
return null;
}
const styleSheet = getStyleElement();
return styleSheet.sheet ? styleSheet.sheet : null;
}
function getFontFaceRules() {
const sheet = getFontFaceStyleSheet();
if (sheet) {
// @ts-ignore: rule iterator
const rules = [...sheet.cssRules];
const items = [];
for (let i = 0; i < rules.length; i++) {
const rule = rules[i];
if (rule instanceof CSSFontFaceRule) {
items.push({ rule, index: i });
}
}
return items;
}
return [];
}
function getFontFaceRulesMatchingResource(fontFamilyName, options) {
const rules = getFontFaceRules();
return rules.filter(({ rule }) => {
return (rule.style.fontFamily === fontFamilyName &&
(options && options.display ? options.display === rule.style.fontDisplay : true));
});
}
const serverContext = new Set();
function getHeadElements() {
const entries = [...serverContext.entries()];
if (!entries.length) {
return [];
}
const css = entries.map(([{ css }]) => css).join('\n');
const links = entries.map(([{ resourceId }]) => resourceId);
// TODO: Maybe return nothing if no fonts were loaded.
return [
{
$$type: 'style',
children: css,
id: ID,
type: 'text/css',
},
...links.map((resourceId) => ({
$$type: 'link',
rel: 'preload',
href: resourceId,
as: 'font',
crossorigin: '',
})),
];
}
export default {
async unloadAllAsync() {
if (!Platform.isDOMAvailable)
return;
const element = document.getElementById(ID);
if (element && element instanceof HTMLStyleElement) {
document.removeChild(element);
}
},
async unloadAsync(fontFamilyName, options) {
const sheet = getFontFaceStyleSheet();
if (!sheet)
return;
const items = getFontFaceRulesMatchingResource(fontFamilyName, options);
for (const item of items) {
sheet.deleteRule(item.index);
}
},
getServerResources() {
const elements = getHeadElements();
return elements
.map((element) => {
switch (element.$$type) {
case 'style':
return `<style id="${element.id}" type="${element.type}">${element.children}</style>`;
case 'link':
return `<link rel="${element.rel}" href="${element.href}" as="${element.as}" crossorigin="${element.crossorigin}" />`;
default:
return '';
}
})
.filter(Boolean);
},
resetServerContext() {
serverContext.clear();
},
isLoaded(fontFamilyName, resource = {}) {
if (typeof window === 'undefined') {
return !![...serverContext.values()].find((asset) => {
return asset.name === fontFamilyName;
});
}
return getFontFaceRulesMatchingResource(fontFamilyName, resource)?.length > 0;
},
// NOTE(EvanBacon): No async keyword! This cannot return a promise in Node environments.
loadAsync(fontFamilyName, resource) {
if (typeof window === 'undefined') {
serverContext.add({
name: fontFamilyName,
css: _createWebFontTemplate(fontFamilyName, resource),
// @ts-expect-error: typeof string
resourceId: resource.uri,
});
return Promise.resolve();
}
const canInjectStyle = document.head && typeof document.head.appendChild === 'function';
if (!canInjectStyle) {
throw new CodedError('ERR_WEB_ENVIRONMENT', `The browser's \`document.head\` element doesn't support injecting fonts.`);
}
const style = getStyleElement();
document.head.appendChild(style);
const res = getFontFaceRulesMatchingResource(fontFamilyName, resource);
if (!res.length) {
_createWebStyle(fontFamilyName, resource);
}
if (!isFontLoadingListenerSupported()) {
return Promise.resolve();
}
return new FontObserver(fontFamilyName, { display: resource.display }).load(null, 6000);
},
};
const ID = 'expo-generated-fonts';
function getStyleElement() {
const element = document.getElementById(ID);
if (element && element instanceof HTMLStyleElement) {
return element;
}
const styleElement = document.createElement('style');
styleElement.id = ID;
styleElement.type = 'text/css';
return styleElement;
}
export function _createWebFontTemplate(fontFamily, resource) {
return `@font-face{font-family:${fontFamily};src:url(${resource.uri});font-display:${resource.display || FontDisplay.AUTO}}`;
}
function _createWebStyle(fontFamily, resource) {
const fontStyle = _createWebFontTemplate(fontFamily, resource);
const styleElement = getStyleElement();
// @ts-ignore: TypeScript does not define HTMLStyleElement::styleSheet. This is just for IE and
// possibly can be removed if it's unnecessary on IE 11.
if (styleElement.styleSheet) {
const styleElementIE = styleElement;
styleElementIE.styleSheet.cssText = styleElementIE.styleSheet.cssText
? styleElementIE.styleSheet.cssText + fontStyle
: fontStyle;
}
else {
const textNode = document.createTextNode(fontStyle);
styleElement.appendChild(textNode);
}
return styleElement;
}
function isFontLoadingListenerSupported() {
const { userAgent } = window.navigator;
// WebKit is broken https://github.com/bramstein/fontfaceobserver/issues/95
const isIOS = !!userAgent.match(/iPad|iPhone/i);
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
// Edge is broken https://github.com/bramstein/fontfaceobserver/issues/109#issuecomment-333356795
const isEdge = userAgent.includes('Edge');
// Internet Explorer
const isIE = userAgent.includes('Trident');
// Firefox
const isFirefox = userAgent.includes('Firefox');
return !isSafari && !isIOS && !isEdge && !isIE && !isFirefox;
}
//# sourceMappingURL=ExpoFontLoader.web.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,52 @@
import { FontDisplay, FontSource, FontResource, UnloadFontOptions } from './Font.types';
/**
* Used to transform font family names to the scoped name. This does not need to
* be called in standalone or bare apps but it will return unscoped font family
* names if it is called in those contexts.
*
* @param fontFamily Name of font to process.
* @returns Returns a name processed for use with the [current workflow](https://docs.expo.dev/archive/managed-vs-bare/).
*/
export declare function processFontFamily(fontFamily: string | null): string | null;
/**
* Synchronously detect if the font for `fontFamily` has finished loading.
*
* @param fontFamily The name used to load the `FontResource`.
* @return Returns `true` if the font has fully loaded.
*/
export declare function isLoaded(fontFamily: string): boolean;
/**
* Synchronously detect if the font for `fontFamily` is still being loaded.
*
* @param fontFamily The name used to load the `FontResource`.
* @returns Returns `true` if the font is still loading.
*/
export declare function isLoading(fontFamily: string): boolean;
/**
* Highly efficient method for loading fonts from static or remote resources which can then be used
* with the platform's native text elements. In the browser this generates a `@font-face` block in
* a shared style sheet for fonts. No CSS is needed to use this method.
*
* @param fontFamilyOrFontMap string or map of values that can be used as the [`fontFamily`](https://reactnative.dev/docs/text#style)
* style prop with React Native Text elements.
* @param source the font asset that should be loaded into the `fontFamily` namespace.
*
* @return Returns a promise that fulfils when the font has loaded. Often you may want to wrap the
* method in a `try/catch/finally` to ensure the app continues if the font fails to load.
*/
export declare function loadAsync(fontFamilyOrFontMap: string | Record<string, FontSource>, source?: FontSource): Promise<void>;
/**
* Unloads all the custom fonts. This is used for testing.
*/
export declare function unloadAllAsync(): Promise<void>;
/**
* Unload custom fonts matching the `fontFamily`s and display values provided.
* Because fonts are automatically unloaded on every platform this is mostly used for testing.
*
* @param fontFamilyOrFontMap The name or names of the custom fonts that will be unloaded.
* @param options When `fontFamilyOrFontMap` is a string, this should be the font source used to load
* the custom font originally.
*/
export declare function unloadAsync(fontFamilyOrFontMap: string | Record<string, UnloadFontOptions>, options?: UnloadFontOptions): Promise<void>;
export { FontDisplay, FontSource, FontResource, UnloadFontOptions };
//# sourceMappingURL=Font.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"Font.d.ts","sourceRoot":"","sources":["../src/Font.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAYxF;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAoB1E;AAGD;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAKpD;AAGD;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAErD;AAGD;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CACvB,mBAAmB,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,EACxD,MAAM,CAAC,EAAE,UAAU,GAClB,OAAO,CAAC,IAAI,CAAC,CAkCf;AAwCD;;GAEG;AACH,wBAAsB,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CAiBpD;AAGD;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAC/B,mBAAmB,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,EAC/D,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,IAAI,CAAC,CAkBf;AA0BD,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,YAAY,EAAE,iBAAiB,EAAE,CAAC"}

View File

@@ -0,0 +1,176 @@
import { CodedError, Platform, UnavailabilityError } from 'expo-modules-core';
import ExpoFontLoader from './ExpoFontLoader';
import { FontDisplay } from './Font.types';
import { getAssetForSource, loadSingleFontAsync, fontFamilyNeedsScoping, getNativeFontName, } from './FontLoader';
import { loaded, loadPromises } from './memory';
import { registerStaticFont } from './server';
// @needsAudit
// note(brentvatne): at some point we may want to warn if this is called outside of a managed app.
/**
* Used to transform font family names to the scoped name. This does not need to
* be called in standalone or bare apps but it will return unscoped font family
* names if it is called in those contexts.
*
* @param fontFamily Name of font to process.
* @returns Returns a name processed for use with the [current workflow](https://docs.expo.dev/archive/managed-vs-bare/).
*/
export function processFontFamily(fontFamily) {
if (!fontFamily || !fontFamilyNeedsScoping(fontFamily)) {
return fontFamily;
}
if (!isLoaded(fontFamily)) {
if (__DEV__) {
if (isLoading(fontFamily)) {
console.warn(`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.`);
}
else {
console.warn(`fontFamily "${fontFamily}" is not a system font and has not been loaded through expo-font.`);
}
}
}
return `ExpoFont-${getNativeFontName(fontFamily)}`;
}
// @needsAudit
/**
* Synchronously detect if the font for `fontFamily` has finished loading.
*
* @param fontFamily The name used to load the `FontResource`.
* @return Returns `true` if the font has fully loaded.
*/
export function isLoaded(fontFamily) {
if (Platform.OS === 'web') {
return fontFamily in loaded || !!ExpoFontLoader.isLoaded(fontFamily);
}
return fontFamily in loaded || ExpoFontLoader.customNativeFonts?.includes(fontFamily);
}
// @needsAudit
/**
* Synchronously detect if the font for `fontFamily` is still being loaded.
*
* @param fontFamily The name used to load the `FontResource`.
* @returns Returns `true` if the font is still loading.
*/
export function isLoading(fontFamily) {
return fontFamily in loadPromises;
}
// @needsAudit
/**
* Highly efficient method for loading fonts from static or remote resources which can then be used
* with the platform's native text elements. In the browser this generates a `@font-face` block in
* a shared style sheet for fonts. No CSS is needed to use this method.
*
* @param fontFamilyOrFontMap string or map of values that can be used as the [`fontFamily`](https://reactnative.dev/docs/text#style)
* style prop with React Native Text elements.
* @param source the font asset that should be loaded into the `fontFamily` namespace.
*
* @return Returns a promise that fulfils when the font has loaded. Often you may want to wrap the
* method in a `try/catch/finally` to ensure the app continues if the font fails to load.
*/
export function loadAsync(fontFamilyOrFontMap, source) {
// NOTE(EvanBacon): Static render pass on web must be synchronous to collect all fonts.
// Because of this, `loadAsync` doesn't use the `async` keyword and deviates from the
// standard Expo SDK style guide.
const isServer = Platform.OS === 'web' && typeof window === 'undefined';
if (typeof fontFamilyOrFontMap === 'object') {
if (source) {
return Promise.reject(new CodedError(`ERR_FONT_API`, `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.`));
}
const fontMap = fontFamilyOrFontMap;
const names = Object.keys(fontMap);
if (isServer) {
names.map((name) => registerStaticFont(name, fontMap[name]));
return Promise.resolve();
}
return Promise.all(names.map((name) => loadFontInNamespaceAsync(name, fontMap[name]))).then(() => { });
}
if (isServer) {
registerStaticFont(fontFamilyOrFontMap, source);
return Promise.resolve();
}
return loadFontInNamespaceAsync(fontFamilyOrFontMap, source);
}
async function loadFontInNamespaceAsync(fontFamily, source) {
if (!source) {
throw new CodedError(`ERR_FONT_SOURCE`, `Cannot load null or undefined font source: { "${fontFamily}": ${source} }. Expected asset of type \`FontSource\` for fontFamily of name: "${fontFamily}"`);
}
if (loaded[fontFamily]) {
return;
}
if (loadPromises.hasOwnProperty(fontFamily)) {
return loadPromises[fontFamily];
}
// Important: we want all callers that concurrently try to load the same font to await the same
// promise. If we're here, we haven't created the promise yet. To ensure we create only one
// promise in the program, we need to create the promise synchronously without yielding the event
// loop from this point.
const asset = getAssetForSource(source);
loadPromises[fontFamily] = (async () => {
try {
await loadSingleFontAsync(fontFamily, asset);
loaded[fontFamily] = true;
}
finally {
delete loadPromises[fontFamily];
}
})();
await loadPromises[fontFamily];
}
// @needsAudit
/**
* Unloads all the custom fonts. This is used for testing.
*/
export async function unloadAllAsync() {
if (!ExpoFontLoader.unloadAllAsync) {
throw new UnavailabilityError('expo-font', 'unloadAllAsync');
}
if (Object.keys(loadPromises).length) {
throw new CodedError(`ERR_UNLOAD`, `Cannot unload fonts while they're still loading: ${Object.keys(loadPromises).join(', ')}`);
}
for (const fontFamily of Object.keys(loaded)) {
delete loaded[fontFamily];
}
await ExpoFontLoader.unloadAllAsync();
}
// @needsAudit
/**
* Unload custom fonts matching the `fontFamily`s and display values provided.
* Because fonts are automatically unloaded on every platform this is mostly used for testing.
*
* @param fontFamilyOrFontMap The name or names of the custom fonts that will be unloaded.
* @param options When `fontFamilyOrFontMap` is a string, this should be the font source used to load
* the custom font originally.
*/
export async function unloadAsync(fontFamilyOrFontMap, options) {
if (!ExpoFontLoader.unloadAsync) {
throw new UnavailabilityError('expo-font', 'unloadAsync');
}
if (typeof fontFamilyOrFontMap === 'object') {
if (options) {
throw new CodedError(`ERR_FONT_API`, `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.`);
}
const fontMap = fontFamilyOrFontMap;
const names = Object.keys(fontMap);
await Promise.all(names.map((name) => unloadFontInNamespaceAsync(name, fontMap[name])));
return;
}
return await unloadFontInNamespaceAsync(fontFamilyOrFontMap, options);
}
async function unloadFontInNamespaceAsync(fontFamily, options) {
if (!loaded[fontFamily]) {
return;
}
else {
delete loaded[fontFamily];
}
// Important: we want all callers that concurrently try to load the same font to await the same
// promise. If we're here, we haven't created the promise yet. To ensure we create only one
// promise in the program, we need to create the promise synchronously without yielding the event
// loop from this point.
const nativeFontName = getNativeFontName(fontFamily);
if (!nativeFontName) {
throw new CodedError(`ERR_FONT_FAMILY`, `Cannot unload an empty name`);
}
await ExpoFontLoader.unloadAsync(nativeFontName, options);
}
export { FontDisplay };
//# sourceMappingURL=Font.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,65 @@
import { Asset } from 'expo-asset';
/**
* The different types of assets you can provide to the [`loadAsync()`](#loadasyncfontfamilyorfontmap-source) function.
* A font source can be a URI, a module ID, or an Expo Asset.
*/
export type FontSource = string | number | Asset | FontResource;
/**
* An object used to dictate the resource that is loaded into the provided font namespace when used
* with [`loadAsync`](#loadasyncfontfamilyorfontmap-source).
*/
export type FontResource = {
uri?: string | number;
/**
* Sets the [`font-display`](#fontdisplay) property for a given typeface in the browser.
* @platform web
*/
display?: FontDisplay;
default?: string;
};
/**
* Sets the [font-display](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-display)
* for a given typeface. The default font value on web is `FontDisplay.AUTO`.
* Even though setting the `fontDisplay` does nothing on native platforms, the default behavior
* emulates `FontDisplay.SWAP` on flagship devices like iOS, Samsung, Pixel, etc. Default
* functionality varies on One Plus devices. In the browser this value is set in the generated
* `@font-face` CSS block and not as a style property meaning you cannot dynamically change this
* value based on the element it's used in.
* @platform web
*/
export declare enum FontDisplay {
/**
* __(Default)__ The font display strategy is defined by the user agent or platform.
* This generally defaults to the text being invisible until the font is loaded.
* Good for buttons or banners that require a specific treatment.
*/
AUTO = "auto",
/**
* Fallback text is rendered immediately with a default font while the desired font is loaded.
* This is good for making the content appear to load instantly and is usually preferred.
*/
SWAP = "swap",
/**
* The text will be invisible until the font has loaded. If the font fails to load then nothing
* will appear - it's best to turn this off when debugging missing text.
*/
BLOCK = "block",
/**
* Splits the behavior between `SWAP` and `BLOCK`.
* There will be a [100ms timeout](https://developers.google.com/web/updates/2016/02/font-display?hl=en)
* where the text with a custom font is invisible, after that the text will either swap to the
* styled text or it'll show the unstyled text and continue to load the custom font. This is good
* for buttons that need a custom font but should also be quickly available to screen-readers.
*/
FALLBACK = "fallback",
/**
* This works almost identically to `FALLBACK`, the only difference is that the browser will
* decide to load the font based on slow connection speed or critical resource demand.
*/
OPTIONAL = "optional"
}
/**
* Object used to query fonts for unloading.
*/
export type UnloadFontOptions = Pick<FontResource, 'display'>;
//# sourceMappingURL=Font.types.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"Font.types.d.ts","sourceRoot":"","sources":["../src/Font.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGnC;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,YAAY,CAAC;AAGhE;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACtB;;;OAGG;IACH,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAGF;;;;;;;;;GASG;AACH,oBAAY,WAAW;IACrB;;;;OAIG;IACH,IAAI,SAAS;IACb;;;OAGG;IACH,IAAI,SAAS;IACb;;;OAGG;IACH,KAAK,UAAU;IACf;;;;;;OAMG;IACH,QAAQ,aAAa;IACrB;;;OAGG;IACH,QAAQ,aAAa;CACtB;AAGD;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC"}

View File

@@ -0,0 +1,44 @@
// @needsAudit
/**
* Sets the [font-display](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/font-display)
* for a given typeface. The default font value on web is `FontDisplay.AUTO`.
* Even though setting the `fontDisplay` does nothing on native platforms, the default behavior
* emulates `FontDisplay.SWAP` on flagship devices like iOS, Samsung, Pixel, etc. Default
* functionality varies on One Plus devices. In the browser this value is set in the generated
* `@font-face` CSS block and not as a style property meaning you cannot dynamically change this
* value based on the element it's used in.
* @platform web
*/
export var FontDisplay;
(function (FontDisplay) {
/**
* __(Default)__ The font display strategy is defined by the user agent or platform.
* This generally defaults to the text being invisible until the font is loaded.
* Good for buttons or banners that require a specific treatment.
*/
FontDisplay["AUTO"] = "auto";
/**
* Fallback text is rendered immediately with a default font while the desired font is loaded.
* This is good for making the content appear to load instantly and is usually preferred.
*/
FontDisplay["SWAP"] = "swap";
/**
* The text will be invisible until the font has loaded. If the font fails to load then nothing
* will appear - it's best to turn this off when debugging missing text.
*/
FontDisplay["BLOCK"] = "block";
/**
* Splits the behavior between `SWAP` and `BLOCK`.
* There will be a [100ms timeout](https://developers.google.com/web/updates/2016/02/font-display?hl=en)
* where the text with a custom font is invisible, after that the text will either swap to the
* styled text or it'll show the unstyled text and continue to load the custom font. This is good
* for buttons that need a custom font but should also be quickly available to screen-readers.
*/
FontDisplay["FALLBACK"] = "fallback";
/**
* This works almost identically to `FALLBACK`, the only difference is that the browser will
* decide to load the font based on slow connection speed or critical resource demand.
*/
FontDisplay["OPTIONAL"] = "optional";
})(FontDisplay || (FontDisplay = {}));
//# sourceMappingURL=Font.types.js.map

View File

@@ -0,0 +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"]}

View File

@@ -0,0 +1,20 @@
import { FontSource } from './Font.types';
/**
* ```ts
* const [loaded, error] = useFonts({ ... });
* ```
* Load a map of fonts with [`loadAsync`](#loadasyncfontfamilyorfontmap-source). This returns a `boolean` if the fonts are
* loaded and ready to use. It also returns an error if something went wrong, to use in development.
*
* > Note, the fonts are not "reloaded" when you dynamically change the font map.
*
* @param map A map of `fontFamily`s to [`FontSource`](#fontsource)s. After loading the font you can
* use the key in the `fontFamily` style prop of a `Text` element.
*
* @return
* - __loaded__ (`boolean`) - A boolean to detect if the font for `fontFamily` has finished
* loading.
* - __error__ (`Error | null`) - An error encountered when loading the fonts.
*/
export declare const useFonts: (map: string | Record<string, FontSource>) => [boolean, Error | null];
//# sourceMappingURL=FontHooks.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"FontHooks.d.ts","sourceRoot":"","sources":["../src/FontHooks.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAiC1C;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,GAAG,IAAI,CACzB,CAAC"}

View File

@@ -0,0 +1,47 @@
import { useEffect, useState } from 'react';
import { loadAsync, isLoaded } from './Font';
function isMapLoaded(map) {
if (typeof map === 'string') {
return isLoaded(map);
}
else {
return Object.keys(map).every((fontFamily) => isLoaded(fontFamily));
}
}
function useRuntimeFonts(map) {
const [loaded, setLoaded] = useState(
// For web rehydration, we need to check if the fonts are already loaded during the static render.
// Native will also benefit from this optimization.
isMapLoaded(map));
const [error, setError] = useState(null);
useEffect(() => {
loadAsync(map)
.then(() => setLoaded(true))
.catch(setError);
}, []);
return [loaded, error];
}
function useStaticFonts(map) {
loadAsync(map);
return [true, null];
}
// @needsAudit
/**
* ```ts
* const [loaded, error] = useFonts({ ... });
* ```
* Load a map of fonts with [`loadAsync`](#loadasyncfontfamilyorfontmap-source). This returns a `boolean` if the fonts are
* loaded and ready to use. It also returns an error if something went wrong, to use in development.
*
* > Note, the fonts are not "reloaded" when you dynamically change the font map.
*
* @param map A map of `fontFamily`s to [`FontSource`](#fontsource)s. After loading the font you can
* use the key in the `fontFamily` style prop of a `Text` element.
*
* @return
* - __loaded__ (`boolean`) - A boolean to detect if the font for `fontFamily` has finished
* loading.
* - __error__ (`Error | null`) - An error encountered when loading the fonts.
*/
export const useFonts = typeof window === 'undefined' ? useStaticFonts : useRuntimeFonts;
//# sourceMappingURL=FontHooks.js.map

View File

@@ -0,0 +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;QAC3B,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;KACtB;SAAM;QACL,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC;KACrE;AACH,CAAC;AAED,SAAS,eAAe,CAAC,GAAwC;IAC/D,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ;IAClC,kGAAkG;IAClG,mDAAmD;IACnD,WAAW,CAAC,GAAG,CAAC,CACjB,CAAC;IACF,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAe,IAAI,CAAC,CAAC;IAEvD,SAAS,CAAC,GAAG,EAAE;QACb,SAAS,CAAC,GAAG,CAAC;aACX,IAAI,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;aAC3B,KAAK,CAAC,QAAQ,CAAC,CAAC;IACrB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AACzB,CAAC;AAED,SAAS,cAAc,CAAC,GAAwC;IAC9D,SAAS,CAAC,GAAG,CAAC,CAAC;IACf,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACtB,CAAC;AAED,cAAc;AACd;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,QAAQ,GACnB,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,eAAe,CAAC","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"]}

View File

@@ -0,0 +1,7 @@
import { Asset } from 'expo-asset';
import { FontResource, FontSource } from './Font.types';
export declare function fontFamilyNeedsScoping(name: string): boolean;
export declare function getAssetForSource(source: FontSource): Asset | FontResource;
export declare function loadSingleFontAsync(name: string, input: Asset | FontResource): Promise<void>;
export declare function getNativeFontName(name: string): string;
//# sourceMappingURL=FontLoader.d.ts.map

View File

@@ -0,0 +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,CAQ5D;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"}

View File

@@ -0,0 +1,50 @@
import { Asset } from 'expo-asset';
import Constants from 'expo-constants';
import { CodedError, Platform } from 'expo-modules-core';
import ExpoFontLoader from './ExpoFontLoader';
const isInExpoGo = Constants.appOwnership === 'expo';
export function fontFamilyNeedsScoping(name) {
return (isInExpoGo &&
Platform.OS !== 'ios' &&
!Constants.systemFonts.includes(name) &&
name !== 'System' &&
!name.includes(Constants.sessionId));
}
export function getAssetForSource(source) {
if (source instanceof Asset) {
return source;
}
if (typeof source === 'string') {
return Asset.fromURI(source);
}
else if (typeof source === 'number') {
return Asset.fromModule(source);
}
else if (typeof source === 'object' && typeof source.uri !== 'undefined') {
return getAssetForSource(source.uri);
}
// @ts-ignore Error: Type 'string' is not assignable to type 'Asset'
// We can't have a string here, we would have thrown an error if !isWeb
// or returned Asset.fromModule if isWeb.
return source;
}
export async function loadSingleFontAsync(name, input) {
const asset = input;
if (!asset.downloadAsync) {
throw new CodedError(`ERR_FONT_SOURCE`, '`loadSingleFontAsync` expected resource of type `Asset` from expo-asset on native');
}
await asset.downloadAsync();
if (!asset.downloaded) {
throw new CodedError(`ERR_DOWNLOAD`, `Failed to download asset for font "${name}"`);
}
await ExpoFontLoader.loadAsync(getNativeFontName(name), asset.localUri);
}
export function getNativeFontName(name) {
if (fontFamilyNeedsScoping(name)) {
return `${Constants.sessionId}-${name}`;
}
else {
return name;
}
}
//# sourceMappingURL=FontLoader.js.map

View File

@@ -0,0 +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,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAEzD,OAAO,cAAc,MAAM,kBAAkB,CAAC;AAG9C,MAAM,UAAU,GAAG,SAAS,CAAC,YAAY,KAAK,MAAM,CAAC;AAErD,MAAM,UAAU,sBAAsB,CAAC,IAAY;IACjD,OAAO,CACL,UAAU;QACV,QAAQ,CAAC,EAAE,KAAK,KAAK;QACrB,CAAC,SAAS,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC;QACrC,IAAI,KAAK,QAAQ;QACjB,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,SAAS,CAAC,CACpC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,MAAkB;IAClD,IAAI,MAAM,YAAY,KAAK,EAAE;QAC3B,OAAO,MAAM,CAAC;KACf;IAED,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;QAC9B,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;KAC9B;SAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;QACrC,OAAO,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;KACjC;SAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,OAAO,MAAM,CAAC,GAAG,KAAK,WAAW,EAAE;QAC1E,OAAO,iBAAiB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;KACtC;IAED,oEAAoE;IACpE,uEAAuE;IACvE,yCAAyC;IACzC,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,IAAY,EACZ,KAA2B;IAE3B,MAAM,KAAK,GAAG,KAAc,CAAC;IAC7B,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE;QACxB,MAAM,IAAI,UAAU,CAClB,iBAAiB,EACjB,mFAAmF,CACpF,CAAC;KACH;IAED,MAAM,KAAK,CAAC,aAAa,EAAE,CAAC;IAC5B,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE;QACrB,MAAM,IAAI,UAAU,CAAC,cAAc,EAAE,sCAAsC,IAAI,GAAG,CAAC,CAAC;KACrF;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;QAChC,OAAO,GAAG,SAAS,CAAC,SAAS,IAAI,IAAI,EAAE,CAAC;KACzC;SAAM;QACL,OAAO,IAAI,CAAC;KACb;AACH,CAAC","sourcesContent":["import { Asset } from 'expo-asset';\nimport Constants from 'expo-constants';\nimport { CodedError, Platform } 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 Platform.OS !== 'ios' &&\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"]}

View File

@@ -0,0 +1,7 @@
import { Asset } from 'expo-asset';
import { FontResource, FontSource } from './Font.types';
export declare function fontFamilyNeedsScoping(name: string): boolean;
export declare function getAssetForSource(source: FontSource): Asset | FontResource;
export declare function loadSingleFontAsync(name: string, input: Asset | FontResource): Promise<void>;
export declare function getNativeFontName(name: string): string;
//# sourceMappingURL=FontLoader.web.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"FontLoader.web.d.ts","sourceRoot":"","sources":["../src/FontLoader.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAInC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAe,MAAM,cAAc,CAAC;AAiBrE,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAE5D;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,UAAU,GAAG,KAAK,GAAG,YAAY,CAY1E;AAYD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAY5F;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEtD"}

View File

@@ -0,0 +1,56 @@
import { Asset } from 'expo-asset';
import { CodedError } from 'expo-modules-core';
import ExpoFontLoader from './ExpoFontLoader';
import { FontDisplay } from './Font.types';
function uriFromFontSource(asset) {
if (typeof asset === 'string') {
return asset || null;
}
else if (typeof asset === 'object') {
return asset.uri || asset.localUri || asset.default || null;
}
else if (typeof asset === 'number') {
return uriFromFontSource(Asset.fromModule(asset));
}
return null;
}
function displayFromFontSource(asset) {
return asset.display || FontDisplay.AUTO;
}
export function fontFamilyNeedsScoping(name) {
return false;
}
export function getAssetForSource(source) {
const uri = uriFromFontSource(source);
const display = displayFromFontSource(source);
if (!uri || typeof uri !== 'string') {
throwInvalidSourceError(uri);
}
return {
uri: uri,
display,
};
}
function throwInvalidSourceError(source) {
let type = typeof source;
if (type === 'object')
type = JSON.stringify(source, null, 2);
throw new CodedError(`ERR_FONT_SOURCE`, `Expected font asset of type \`string | FontResource | Asset\` instead got: ${type}`);
}
// NOTE(EvanBacon): No async keyword!
export function loadSingleFontAsync(name, input) {
if (typeof input !== 'object' || typeof input.uri !== 'string' || input.downloadAsync) {
throwInvalidSourceError(input);
}
try {
return ExpoFontLoader.loadAsync(name, input);
}
catch {
// No-op.
}
return Promise.resolve();
}
export function getNativeFontName(name) {
return name;
}
//# sourceMappingURL=FontLoader.web.js.map

View File

@@ -0,0 +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;QAC7B,OAAO,KAAK,IAAI,IAAI,CAAC;KACtB;SAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QACpC,OAAO,KAAK,CAAC,GAAG,IAAI,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,OAAO,IAAI,IAAI,CAAC;KAC7D;SAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QACpC,OAAO,iBAAiB,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;KACnD;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,qBAAqB,CAAC,KAAU;IACvC,OAAO,KAAK,CAAC,OAAO,IAAI,WAAW,CAAC,IAAI,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,IAAY;IACjD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,MAAkB;IAClD,MAAM,GAAG,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC;IACtC,MAAM,OAAO,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;IAE9C,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;QACnC,uBAAuB,CAAC,GAAG,CAAC,CAAC;KAC9B;IAED,OAAO;QACL,GAAG,EAAE,GAAI;QACT,OAAO;KACR,CAAC;AACJ,CAAC;AAED,SAAS,uBAAuB,CAAC,MAAW;IAC1C,IAAI,IAAI,GAAW,OAAO,MAAM,CAAC;IACjC,IAAI,IAAI,KAAK,QAAQ;QAAE,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAC9D,MAAM,IAAI,UAAU,CAClB,iBAAiB,EACjB,8EAA8E,IAAI,EAAE,CACrF,CAAC;AACJ,CAAC;AAED,qCAAqC;AACrC,MAAM,UAAU,mBAAmB,CAAC,IAAY,EAAE,KAA2B;IAC3E,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,CAAC,GAAG,KAAK,QAAQ,IAAK,KAAa,CAAC,aAAa,EAAE;QAC9F,uBAAuB,CAAC,KAAK,CAAC,CAAC;KAChC;IAED,IAAI;QACF,OAAO,cAAc,CAAC,SAAS,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;KAC9C;IAAC,MAAM;QACN,SAAS;KACV;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"]}

View File

@@ -0,0 +1,3 @@
export * from './Font';
export { useFonts } from './FontHooks';
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC"}

View File

@@ -0,0 +1,3 @@
export * from './Font';
export { useFonts } from './FontHooks';
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC","sourcesContent":["export * from './Font';\nexport { useFonts } from './FontHooks';\n"]}

View File

@@ -0,0 +1,7 @@
export declare const loaded: {
[name: string]: boolean;
};
export declare const loadPromises: {
[name: string]: Promise<void>;
};
//# sourceMappingURL=memory.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM,EAAE;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAA;CAAO,CAAC;AACtD,eAAO,MAAM,YAAY,EAAE;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAAO,CAAC"}

View File

@@ -0,0 +1,3 @@
export const loaded = {};
export const loadPromises = {};
//# sourceMappingURL=memory.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,MAAM,GAAgC,EAAE,CAAC;AACtD,MAAM,CAAC,MAAM,YAAY,GAAsC,EAAE,CAAC","sourcesContent":["export const loaded: { [name: string]: boolean } = {};\nexport const loadPromises: { [name: string]: Promise<void> } = {};\n"]}

View File

@@ -0,0 +1,13 @@
import { FontSource } from './Font.types';
/**
* @returns the server resources that should be statically extracted.
* @private
*/
export declare function getServerResources(): string[];
/**
* @returns clear the server resources from the global scope.
* @private
*/
export declare function resetServerContext(): any;
export declare function registerStaticFont(fontFamily: string, source?: FontSource | null): void;
//# sourceMappingURL=server.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,EAAE,CAE7C;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,QAEjC;AAED,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,UAAU,GAAG,IAAI,QAWhF"}

View File

@@ -0,0 +1,26 @@
import { CodedError } from 'expo-modules-core';
import ExpoFontLoader from './ExpoFontLoader';
import { getAssetForSource, loadSingleFontAsync } from './FontLoader';
/**
* @returns the server resources that should be statically extracted.
* @private
*/
export function getServerResources() {
return ExpoFontLoader.getServerResources();
}
/**
* @returns clear the server resources from the global scope.
* @private
*/
export function resetServerContext() {
return ExpoFontLoader.resetServerContext();
}
export function registerStaticFont(fontFamily, source) {
// MUST BE A SYNC FUNCTION!
if (!source) {
throw new CodedError(`ERR_FONT_SOURCE`, `Cannot load null or undefined font source: { "${fontFamily}": ${source} }. Expected asset of type \`FontSource\` for fontFamily of name: "${fontFamily}"`);
}
const asset = getAssetForSource(source);
loadSingleFontAsync(fontFamily, asset);
}
//# sourceMappingURL=server.js.map

View File

@@ -0,0 +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;QACX,MAAM,IAAI,UAAU,CAClB,iBAAiB,EACjB,iDAAiD,UAAU,MAAM,MAAM,sEAAsE,UAAU,GAAG,CAC3J,CAAC;KACH;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"]}