react-native-nano-icons 1.0.1 → 1.1.0-beta.2
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/README.md +139 -21
- package/android/src/main/java/com/nanoicons/NanoIconFonts.kt +15 -0
- package/android/src/main/java/com/nanoicons/NanoIconView.kt +27 -4
- package/android/src/main/java/com/nanoicons/NanoIconViewManager.kt +7 -0
- package/android/src/main/java/com/nanoicons/NanoIconsFontLoaderModule.kt +3 -0
- package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconProps.cpp +6 -1
- package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconProps.h +4 -2
- package/ios/NanoIconView.mm +34 -44
- package/ios/NanoIconsFontLoader.mm +5 -0
- package/lib/commonjs/cli/build.d.ts +26 -0
- package/lib/commonjs/cli/build.js +174 -64
- package/lib/commonjs/cli/buildSymbols.d.ts +30 -1
- package/lib/commonjs/cli/buildSymbols.js +120 -42
- package/lib/commonjs/cli/expoConfig.d.ts +11 -0
- package/lib/commonjs/cli/expoConfig.js +28 -9
- package/lib/commonjs/cli/fingerprint.d.ts +15 -0
- package/lib/commonjs/cli/fingerprint.js +42 -0
- package/lib/commonjs/cli/index.d.ts +2 -2
- package/lib/commonjs/cli/index.js +3 -1
- package/lib/commonjs/cli/link.d.ts +4 -0
- package/lib/commonjs/cli/link.js +38 -1
- package/lib/commonjs/cli/sameOutputs.d.ts +5 -0
- package/lib/commonjs/cli/sameOutputs.js +45 -0
- package/lib/commonjs/index.node.js +1 -1
- package/lib/commonjs/plugin/src/buildFonts.d.ts +3 -2
- package/lib/commonjs/plugin/src/buildFonts.js +11 -3
- package/lib/commonjs/plugin/src/buildSymbols.d.ts +2 -2
- package/lib/commonjs/plugin/src/buildSymbols.js +10 -3
- package/lib/commonjs/plugin/src/frozen.d.ts +3 -0
- package/lib/commonjs/plugin/src/frozen.js +18 -0
- package/lib/commonjs/plugin/src/index.js +3 -3
- package/lib/commonjs/plugin/src/types.d.ts +22 -1
- package/lib/commonjs/plugin/src/withNanoIconsDrawableLinking.d.ts +1 -1
- package/lib/commonjs/plugin/src/withNanoIconsDrawableLinking.js +2 -2
- package/lib/commonjs/plugin/src/withNanoIconsFontLinking.d.ts +3 -3
- package/lib/commonjs/plugin/src/withNanoIconsFontLinking.js +8 -8
- package/lib/commonjs/plugin/src/withNanoIconsSymbolLinking.d.ts +1 -1
- package/lib/commonjs/plugin/src/withNanoIconsSymbolLinking.js +2 -2
- package/lib/commonjs/scripts/cli.js +31 -2
- package/lib/commonjs/src/core/flatten/dom.js +40 -5
- package/lib/commonjs/src/core/flatten/element.js +2 -1
- package/lib/commonjs/src/core/flatten/stages/collapse.js +12 -0
- package/lib/commonjs/src/core/font/compile.d.ts +0 -1
- package/lib/commonjs/src/core/font/compile.js +2 -8
- package/lib/commonjs/src/core/glyph/merge.d.ts +2 -1
- package/lib/commonjs/src/core/glyph/merge.js +27 -36
- package/lib/commonjs/src/core/glyph/parse.d.ts +1 -2
- package/lib/commonjs/src/core/glyph/parse.js +31 -18
- package/lib/commonjs/src/core/glyph/placement.d.ts +1 -0
- package/lib/commonjs/src/core/glyph/placement.js +9 -3
- package/lib/commonjs/src/core/pathkit/types.d.ts +1 -0
- package/lib/commonjs/src/core/pathkit/winding.d.ts +14 -3
- package/lib/commonjs/src/core/pathkit/winding.js +434 -7
- package/lib/commonjs/src/core/pipeline/config.d.ts +1 -0
- package/lib/commonjs/src/core/pipeline/prepare.d.ts +1 -1
- package/lib/commonjs/src/core/pipeline/prepare.js +4 -16
- package/lib/commonjs/src/core/pipeline/prepareIcon.d.ts +1 -0
- package/lib/commonjs/src/core/pipeline/prepareIcon.js +3 -1
- package/lib/commonjs/src/core/pipeline/prepareSymbol.d.ts +2 -0
- package/lib/commonjs/src/core/pipeline/prepareSymbol.js +15 -3
- package/lib/commonjs/src/core/pipeline/preparedSvgCache.js +2 -2
- package/lib/commonjs/src/core/pipeline/runFontPipeline.js +20 -12
- package/lib/commonjs/src/core/pipeline/runSymbolPipeline.d.ts +2 -0
- package/lib/commonjs/src/core/pipeline/runSymbolPipeline.js +2 -0
- package/lib/commonjs/src/core/symbols/contents.d.ts +1 -1
- package/lib/commonjs/src/core/symbols/contents.js +6 -2
- package/lib/commonjs/src/core/symbols/knockout.js +4 -3
- package/lib/commonjs/src/core/symbols/layers.d.ts +1 -0
- package/lib/commonjs/src/core/symbols/layers.js +133 -92
- package/lib/commonjs/src/core/symbols/template.d.ts +8 -3
- package/lib/commonjs/src/core/symbols/template.js +23 -8
- package/lib/commonjs/src/core/symbols/vectorDrawable.d.ts +8 -0
- package/lib/commonjs/src/core/symbols/vectorDrawable.js +28 -2
- package/lib/commonjs/src/utils/fingerPrint.d.ts +3 -0
- package/lib/commonjs/src/utils/fingerPrint.js +5 -1
- package/lib/commonjs/src/utils/fontIdentity.d.ts +1 -1
- package/lib/commonjs/src/utils/fontIdentity.js +2 -2
- package/lib/module/createNanoIconsSet.js +0 -1
- package/lib/module/createNanoIconsSet.native.js +22 -18
- package/lib/module/createNanoIconsSet.shared.js +32 -18
- package/lib/module/createNanoIconsSet.web.js +103 -61
- package/lib/module/devServerFont.js +1 -1
- package/lib/module/devServerFont.web.js +3 -5
- package/lib/module/fontIntegrity.js +20 -38
- package/lib/module/fontIntegrity.web.js +48 -0
- package/lib/module/fontIntegrityStore.js +65 -0
- package/lib/module/index.js +1 -1
- package/lib/module/index.node.js +1 -1
- package/lib/module/index.web.js +4 -0
- package/lib/module/loadDynamicFont.js +3 -15
- package/lib/module/specs/NanoIconViewNativeComponent.ts +2 -1
- package/lib/module/utils/fingerPrint.js +4 -3
- package/lib/module/utils/fontIdentity.js +2 -2
- package/lib/module/utils/fontScale.js +10 -2
- package/lib/module/utils/glyphRuntime.js +13 -0
- package/lib/module/utils/iconAccessibility.js +26 -0
- package/lib/module/utils/iconPropsEqual.js +27 -0
- package/lib/module/utils/webCss.js +26 -0
- package/lib/module/utils/webStyle.js +86 -0
- package/lib/module/webFont.js +33 -0
- package/lib/typescript/src/const/codegenPrimitives.d.ts +1 -0
- package/lib/typescript/src/core/glyph/merge.d.ts +2 -1
- package/lib/typescript/src/core/glyph/parse.d.ts +1 -2
- package/lib/typescript/src/core/glyph/placement.d.ts +1 -0
- package/lib/typescript/src/core/pathkit/types.d.ts +1 -0
- package/lib/typescript/src/core/pathkit/winding.d.ts +14 -3
- package/lib/typescript/src/core/symbols/contents.d.ts +1 -1
- package/lib/typescript/src/core/symbols/layers.d.ts +1 -0
- package/lib/typescript/src/core/symbols/template.d.ts +8 -3
- package/lib/typescript/src/core/symbols/vectorDrawable.d.ts +8 -0
- package/lib/typescript/src/createNanoIconsSet.d.ts +0 -1
- package/lib/typescript/src/createNanoIconsSet.native.d.ts +0 -2
- package/lib/typescript/src/createNanoIconsSet.shared.d.ts +1 -3
- package/lib/typescript/src/createNanoIconsSet.web.d.ts +1 -2
- package/lib/typescript/src/fontIntegrity.d.ts +2 -14
- package/lib/typescript/src/fontIntegrity.web.d.ts +7 -0
- package/lib/typescript/src/fontIntegrityStore.d.ts +19 -0
- package/lib/typescript/src/index.d.ts +2 -1
- package/lib/typescript/src/index.web.d.ts +5 -0
- package/lib/typescript/src/loadDynamicFont.d.ts +0 -1
- package/lib/typescript/src/specs/NanoIconViewNativeComponent.d.ts +2 -1
- package/lib/typescript/src/specs/NativeNanoIconsFontLoader.d.ts +1 -0
- package/lib/typescript/src/types.d.ts +37 -9
- package/lib/typescript/src/utils/fingerPrint.d.ts +3 -0
- package/lib/typescript/src/utils/fontIdentity.d.ts +1 -1
- package/lib/typescript/src/utils/glyphRuntime.d.ts +8 -0
- package/lib/typescript/src/utils/iconAccessibility.d.ts +4 -0
- package/lib/typescript/src/utils/iconPropsEqual.d.ts +4 -0
- package/lib/typescript/src/utils/webCss.d.ts +9 -0
- package/lib/typescript/src/utils/webStyle.d.ts +3 -0
- package/lib/typescript/src/webFont.d.ts +6 -0
- package/package.json +19 -3
- package/src/const/codegenPrimitives.ts +3 -3
- package/src/specs/NanoIconViewNativeComponent.ts +2 -1
- package/src/specs/NativeNanoIconsFontLoader.ts +1 -0
- package/lib/commonjs/src/core/pathkit/evenodd.d.ts +0 -12
- package/lib/commonjs/src/core/pathkit/evenodd.js +0 -37
- package/lib/typescript/src/core/pathkit/evenodd.d.ts +0 -13
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare function buildFontFamily(fontFamily: string,
|
|
1
|
+
export declare function buildFontFamily(fontFamily: string, contentHash: string): string;
|
|
2
2
|
export declare function configuredFontFamily(family: string): string;
|
|
3
3
|
export declare function isFontFileOf(fontFamily: string, fileName: string): boolean;
|
|
4
4
|
export declare function isBuildFontFile(fileName: string): boolean;
|
|
@@ -9,8 +9,8 @@ const BUILD_HASH = `[0-9a-f]{${BUILD_HASH_LENGTH}}`;
|
|
|
9
9
|
const BUILD_SUFFIX = new RegExp(`-${BUILD_HASH}$`);
|
|
10
10
|
const BUILD_FONT_FILE = new RegExp(`-${BUILD_HASH}\\.ttf$`);
|
|
11
11
|
const REGEX_SPECIALS = /[.*+?^${}()|[\]\\]/g;
|
|
12
|
-
function buildFontFamily(fontFamily,
|
|
13
|
-
return `${fontFamily}-${
|
|
12
|
+
function buildFontFamily(fontFamily, contentHash) {
|
|
13
|
+
return `${fontFamily}-${contentHash.slice(0, BUILD_HASH_LENGTH)}`;
|
|
14
14
|
}
|
|
15
15
|
function configuredFontFamily(family) {
|
|
16
16
|
return family.replace(BUILD_SUFFIX, '');
|
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
import { memo, useMemo } from 'react';
|
|
4
4
|
import { UIManager, View } from 'react-native';
|
|
5
|
-
import {
|
|
5
|
+
import { areIconPropsEqual } from "./utils/iconPropsEqual.js";
|
|
6
|
+
import { iconAccessibilityProps } from "./utils/iconAccessibility.js";
|
|
6
7
|
import { useFontScale } from "./utils/fontScale.js";
|
|
7
8
|
import { validateLayerColor } from "./utils/validateLayerColor.js";
|
|
8
|
-
import { DEFAULT_ICON_SIZE, resolveGlyphEntry, createLayerColorResolver, tintableLayers } from "./utils/glyphRuntime.js";
|
|
9
|
+
import { DEFAULT_ICON_SIZE, resolveGlyphEntry, createLayerColorResolver, squareGlyphBox, tintableLayers } from "./utils/glyphRuntime.js";
|
|
9
10
|
import NanoIconViewNative from './specs/NanoIconViewNativeComponent';
|
|
10
11
|
import { createJSIconSet, warnIfLinkingMismatch } from "./createNanoIconsSet.shared.js";
|
|
11
12
|
import { loadDynamicFont, useDynamicFontPending } from "./loadDynamicFont.js";
|
|
12
|
-
import { checkFontIntegrity, isFontMismatch, reportDynamicFontLoadFailure, reportFontMismatch } from
|
|
13
|
+
import { checkFontIntegrity, checkStaticFontNow, isFontMismatch, reportDynamicFontLoadFailure, reportFontMismatch } from './fontIntegrity';
|
|
13
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
-
export { shallowEqualColor };
|
|
15
15
|
const HAS_NATIVE_IMPL = UIManager.hasViewManagerConfig('NanoIconView');
|
|
16
16
|
async function loadFontFromDevServer(family) {
|
|
17
17
|
if (__DEV__) {
|
|
@@ -30,6 +30,7 @@ export function createIconSet(glyphMap, font) {
|
|
|
30
30
|
}
|
|
31
31
|
const fontFamilyBasename = glyphMap.m.f;
|
|
32
32
|
const unitsPerEm = glyphMap.m.u;
|
|
33
|
+
const safeZone = glyphMap.m.z;
|
|
33
34
|
warnIfLinkingMismatch(fontFamilyBasename, glyphMap.m.l, font);
|
|
34
35
|
|
|
35
36
|
// dynamically linked font - register and hide icons until ready
|
|
@@ -44,7 +45,7 @@ export function createIconSet(glyphMap, font) {
|
|
|
44
45
|
void reportDynamicFontLoadFailure(fontFamilyBasename, err);
|
|
45
46
|
}
|
|
46
47
|
});
|
|
47
|
-
} else if (linking === 'static') {
|
|
48
|
+
} else if (linking === 'static' && !checkStaticFontNow(fontFamilyBasename)) {
|
|
48
49
|
void ensureStaticFont(fontFamilyBasename);
|
|
49
50
|
}
|
|
50
51
|
|
|
@@ -76,9 +77,10 @@ export function createIconSet(glyphMap, font) {
|
|
|
76
77
|
tintMode,
|
|
77
78
|
style,
|
|
78
79
|
allowFontScaling = true,
|
|
80
|
+
frame,
|
|
79
81
|
accessible,
|
|
80
82
|
accessibilityLabel,
|
|
81
|
-
accessibilityRole
|
|
83
|
+
accessibilityRole,
|
|
82
84
|
accessibilityElementsHidden,
|
|
83
85
|
importantForAccessibility,
|
|
84
86
|
testID,
|
|
@@ -87,7 +89,9 @@ export function createIconSet(glyphMap, font) {
|
|
|
87
89
|
const fontScale = useFontScale(allowFontScaling);
|
|
88
90
|
const [adv, layers] = resolveGlyphEntry(glyphMap, name);
|
|
89
91
|
const scaledSize = size * fontScale;
|
|
90
|
-
const
|
|
92
|
+
const square = frame === 'square';
|
|
93
|
+
const width = square ? scaledSize : adv / unitsPerEm * scaledSize;
|
|
94
|
+
const squareGlyphScale = square ? squareGlyphBox(adv, unitsPerEm, safeZone).scale : undefined;
|
|
91
95
|
const pending = useDynamicFontPending(managed, fontFamilyBasename);
|
|
92
96
|
const nameStr = name;
|
|
93
97
|
const codepoints = getCodepoints(nameStr, layers);
|
|
@@ -99,6 +103,13 @@ export function createIconSet(glyphMap, font) {
|
|
|
99
103
|
const resolveColor = createLayerColorResolver(color, tintMode, layers);
|
|
100
104
|
return layers.map(([, srcColor], i) => validateLayerColor(resolveColor(i, srcColor), nameStr, i));
|
|
101
105
|
}, [nameStr, color, tintMode]);
|
|
106
|
+
const accessibility = iconAccessibilityProps({
|
|
107
|
+
accessible,
|
|
108
|
+
accessibilityLabel,
|
|
109
|
+
accessibilityRole,
|
|
110
|
+
accessibilityElementsHidden,
|
|
111
|
+
importantForAccessibility
|
|
112
|
+
});
|
|
102
113
|
const nativeStyle = useMemo(() => [{
|
|
103
114
|
width,
|
|
104
115
|
height: scaledSize
|
|
@@ -110,11 +121,7 @@ export function createIconSet(glyphMap, font) {
|
|
|
110
121
|
return /*#__PURE__*/_jsx(View, {
|
|
111
122
|
ref: ref,
|
|
112
123
|
style: nativeStyle,
|
|
113
|
-
|
|
114
|
-
accessibilityRole: accessibilityRole,
|
|
115
|
-
accessibilityLabel: accessibilityLabel ?? name,
|
|
116
|
-
accessibilityElementsHidden: accessibilityElementsHidden,
|
|
117
|
-
importantForAccessibility: importantForAccessibility,
|
|
124
|
+
...accessibility,
|
|
118
125
|
testID: testID
|
|
119
126
|
});
|
|
120
127
|
}
|
|
@@ -128,15 +135,12 @@ export function createIconSet(glyphMap, font) {
|
|
|
128
135
|
fontScale: fontScale,
|
|
129
136
|
advanceWidth: adv,
|
|
130
137
|
unitsPerEm: unitsPerEm,
|
|
138
|
+
squareGlyphScale: squareGlyphScale,
|
|
131
139
|
style: style,
|
|
132
|
-
|
|
133
|
-
accessibilityRole: accessibilityRole,
|
|
134
|
-
accessibilityLabel: accessibilityLabel ?? name,
|
|
135
|
-
accessibilityElementsHidden: accessibilityElementsHidden,
|
|
136
|
-
importantForAccessibility: importantForAccessibility,
|
|
140
|
+
...accessibility,
|
|
137
141
|
testID: testID
|
|
138
142
|
});
|
|
139
|
-
},
|
|
143
|
+
}, areIconPropsEqual);
|
|
140
144
|
Icon.displayName = `NanoIcon(${fontFamilyBasename})`;
|
|
141
145
|
const IconComp = Icon;
|
|
142
146
|
IconComp.loadFont = override => glyphMap.m.l === 'd' ? loadDynamicFont(fontFamilyBasename, override ?? font, {
|
|
@@ -2,15 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
import { memo, useMemo } from 'react';
|
|
4
4
|
import { PixelRatio, Platform, Text, View } from 'react-native';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { areIconPropsEqual } from "./utils/iconPropsEqual.js";
|
|
6
|
+
import { iconAccessibilityProps } from "./utils/iconAccessibility.js";
|
|
7
|
+
import { DEFAULT_ICON_SIZE, resolveGlyphEntry, createCharCache, createLayerColorResolver, squareGlyphBox } from "./utils/glyphRuntime.js";
|
|
7
8
|
import { loadDynamicFont, useDynamicFontPending } from "./loadDynamicFont.js";
|
|
8
9
|
import { warnRuntime } from "./utils/runtimeLog.js";
|
|
9
|
-
import { isFontMismatch, reportDynamicFontLoadFailure, reportFontMismatch, reportMissingDynamicFont } from
|
|
10
|
+
import { isFontMismatch, reportDynamicFontLoadFailure, reportFontMismatch, reportMissingDynamicFont } from './fontIntegrity';
|
|
10
11
|
import { configuredFontFamily } from "./utils/fontIdentity.js";
|
|
11
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
-
export { shallowEqualColor };
|
|
13
|
-
|
|
14
13
|
/**
|
|
15
14
|
* Warn when the `font` argument and the glyphmap's linking mode are inconsistent.
|
|
16
15
|
*
|
|
@@ -33,7 +32,7 @@ export function warnIfLinkingMismatch(fontFamily, linking, font) {
|
|
|
33
32
|
|
|
34
33
|
/**
|
|
35
34
|
* JS implementation using <View> + <Text> layers.
|
|
36
|
-
* Used
|
|
35
|
+
* Used as a fallback when native component is unavailable (e.g. Expo Go).
|
|
37
36
|
*/
|
|
38
37
|
|
|
39
38
|
export function createJSIconSet(glyphMap, font) {
|
|
@@ -64,6 +63,7 @@ export function createJSIconSet(glyphMap, font) {
|
|
|
64
63
|
bottom: 0
|
|
65
64
|
};
|
|
66
65
|
const unitsPerEm = glyphMap.m.u;
|
|
66
|
+
const safeZone = glyphMap.m.z;
|
|
67
67
|
const getChar = createCharCache();
|
|
68
68
|
const Icon = /*#__PURE__*/memo(({
|
|
69
69
|
name,
|
|
@@ -72,9 +72,10 @@ export function createJSIconSet(glyphMap, font) {
|
|
|
72
72
|
tintMode,
|
|
73
73
|
style,
|
|
74
74
|
allowFontScaling = true,
|
|
75
|
+
frame,
|
|
75
76
|
accessible,
|
|
76
77
|
accessibilityLabel,
|
|
77
|
-
accessibilityRole
|
|
78
|
+
accessibilityRole,
|
|
78
79
|
accessibilityElementsHidden,
|
|
79
80
|
importantForAccessibility,
|
|
80
81
|
testID,
|
|
@@ -83,7 +84,8 @@ export function createJSIconSet(glyphMap, font) {
|
|
|
83
84
|
const fontScale = allowFontScaling ? PixelRatio.getFontScale() : 1;
|
|
84
85
|
const [adv, layers] = resolveGlyphEntry(glyphMap, name);
|
|
85
86
|
const scaledSize = size * fontScale;
|
|
86
|
-
const
|
|
87
|
+
const square = frame === 'square';
|
|
88
|
+
const width = square ? scaledSize : adv / unitsPerEm * scaledSize;
|
|
87
89
|
const pending = useDynamicFontPending(managed, fontBasename);
|
|
88
90
|
const resolveColor = createLayerColorResolver(color, tintMode, layers);
|
|
89
91
|
const containerStyle = useMemo(() => [{
|
|
@@ -91,17 +93,29 @@ export function createJSIconSet(glyphMap, font) {
|
|
|
91
93
|
width,
|
|
92
94
|
bottom: 0
|
|
93
95
|
}, style], [scaledSize, width, style]);
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
96
|
+
const glyphStyle = useMemo(() => {
|
|
97
|
+
if (!square) return {
|
|
98
|
+
fontSize: size
|
|
99
|
+
};
|
|
100
|
+
const box = squareGlyphBox(adv, unitsPerEm, safeZone);
|
|
101
|
+
return {
|
|
102
|
+
fontSize: size * box.scale,
|
|
103
|
+
left: '50%',
|
|
104
|
+
bottom: '50%',
|
|
105
|
+
marginLeft: -box.width * scaledSize / 2,
|
|
106
|
+
marginBottom: -box.scale * scaledSize / 2
|
|
107
|
+
};
|
|
108
|
+
}, [size, scaledSize, square, adv]);
|
|
97
109
|
return /*#__PURE__*/_jsx(View, {
|
|
98
110
|
ref: ref,
|
|
99
111
|
style: containerStyle,
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
112
|
+
...iconAccessibilityProps({
|
|
113
|
+
accessible,
|
|
114
|
+
accessibilityLabel,
|
|
115
|
+
accessibilityRole,
|
|
116
|
+
accessibilityElementsHidden,
|
|
117
|
+
importantForAccessibility
|
|
118
|
+
}),
|
|
105
119
|
testID: testID,
|
|
106
120
|
children: pending ? null : layers.map(([codepoint, srcColor], i) => {
|
|
107
121
|
const layerColor = resolveColor(i, srcColor);
|
|
@@ -109,14 +123,14 @@ export function createJSIconSet(glyphMap, font) {
|
|
|
109
123
|
selectable: false,
|
|
110
124
|
accessible: false,
|
|
111
125
|
allowFontScaling: allowFontScaling,
|
|
112
|
-
style: [styleOverrides,
|
|
126
|
+
style: [styleOverrides, glyphStyle, {
|
|
113
127
|
color: layerColor
|
|
114
128
|
}],
|
|
115
129
|
children: getChar(codepoint)
|
|
116
130
|
}, i);
|
|
117
131
|
})
|
|
118
132
|
});
|
|
119
|
-
},
|
|
133
|
+
}, areIconPropsEqual);
|
|
120
134
|
Icon.displayName = `NanoIcon(${fontBasename})`;
|
|
121
135
|
const IconComp = Icon;
|
|
122
136
|
IconComp.loadFont = override => glyphMap.m.l === 'd' ? loadDynamicFont(fontBasename, override ?? font, {
|
|
@@ -1,92 +1,134 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import { memo
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
3
|
+
import { memo } from 'react';
|
|
4
|
+
import * as ReactDOM from 'react-dom';
|
|
5
|
+
import { areIconPropsEqual } from "./utils/iconPropsEqual.js";
|
|
6
|
+
import { iconAccessibilityProps } from "./utils/iconAccessibility.js";
|
|
7
|
+
import { resolveGlyphEntry, createCharCache, createLayerColorResolver, squareGlyphBox } from "./utils/glyphRuntime.js";
|
|
6
8
|
import { configuredFontFamily } from "./utils/fontIdentity.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const dev = require('./devServerFont');
|
|
13
|
-
return dev.loadFontFromDevServer(family);
|
|
14
|
-
}
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
9
|
+
import { loadFontFromDevServer } from "./devServerFont.web.js";
|
|
10
|
+
import { reportFontLoadFailure, resolveFontIssue, watchFontLoadFailures } from "./fontIntegrity.web.js";
|
|
11
|
+
import { resolveWebStyle } from "./utils/webStyle.js";
|
|
12
|
+
import { BASE_CSS, BASE_HREF, ICON_CLASS, STYLE_HREF, STYLE_PRECEDENCE, followsTextColor, shortHash } from "./utils/webCss.js";
|
|
13
|
+
import { registerWebFont, warnFontNotLoaded, webFontUrl } from "./webFont.js";
|
|
17
14
|
|
|
18
15
|
// Web renderer: uses inline <span> elements so icons flow out of the box (display: inline-block keeps width/height)
|
|
19
|
-
|
|
16
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
17
|
+
export function createIconSet(glyphMap, font) {
|
|
20
18
|
const family = glyphMap.m.f;
|
|
21
19
|
const fontBasename = configuredFontFamily(family);
|
|
20
|
+
const linking = glyphMap.m.l === 'd' ? 'dynamic' : 'static';
|
|
21
|
+
const fontFamily = family === fontBasename ? JSON.stringify(fontBasename) : `${JSON.stringify(family)}, ${JSON.stringify(fontBasename)}`;
|
|
22
22
|
const unitsPerEm = glyphMap.m.u;
|
|
23
|
+
const safeZone = glyphMap.m.z;
|
|
23
24
|
const getChar = createCharCache();
|
|
24
|
-
|
|
25
|
+
const fontUrl = webFontUrl(font);
|
|
26
|
+
const fontFace = fontUrl && {
|
|
27
|
+
href: `${STYLE_HREF}:${shortHash(`${fontBasename}:${fontUrl}`)}`,
|
|
28
|
+
css: `@font-face{font-family:${JSON.stringify(fontBasename)};src:url(${JSON.stringify(fontUrl)});font-display:block}`
|
|
29
|
+
};
|
|
30
|
+
if (typeof __DEV__ !== 'undefined' && __DEV__) {
|
|
31
|
+
if (font != null && fontUrl === undefined) {
|
|
32
|
+
warnFontNotLoaded(fontBasename);
|
|
33
|
+
}
|
|
34
|
+
if (globalThis.document !== undefined) {
|
|
35
|
+
void loadFontFromDevServer(family).then(() => watchFontLoadFailures(family, linking));
|
|
36
|
+
}
|
|
37
|
+
} else {
|
|
38
|
+
watchFontLoadFailures(family, linking);
|
|
39
|
+
}
|
|
25
40
|
const Icon = /*#__PURE__*/memo(({
|
|
26
41
|
name,
|
|
27
|
-
size
|
|
42
|
+
size,
|
|
28
43
|
color,
|
|
29
44
|
tintMode,
|
|
45
|
+
frame,
|
|
30
46
|
style,
|
|
31
47
|
accessible,
|
|
32
48
|
accessibilityLabel,
|
|
33
|
-
accessibilityRole
|
|
49
|
+
accessibilityRole,
|
|
34
50
|
accessibilityElementsHidden,
|
|
51
|
+
importantForAccessibility,
|
|
35
52
|
testID,
|
|
36
53
|
className,
|
|
37
54
|
ref
|
|
38
55
|
}) => {
|
|
39
56
|
const [adv, layers] = resolveGlyphEntry(glyphMap, name);
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
verticalAlign: 'middle',
|
|
50
|
-
...style
|
|
51
|
-
}), [size, width, style]);
|
|
52
|
-
const layerBaseStyle = useMemo(() => ({
|
|
53
|
-
position: 'absolute',
|
|
54
|
-
left: 0,
|
|
55
|
-
bottom: 0,
|
|
57
|
+
const square = frame === 'square';
|
|
58
|
+
if (fontUrl && !fontUrl.startsWith('data:')) {
|
|
59
|
+
ReactDOM.preload?.(fontUrl, {
|
|
60
|
+
as: 'font',
|
|
61
|
+
crossOrigin: 'anonymous'
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
const containerStyle = {
|
|
65
|
+
'--nano-icon-ratio': square ? 1 : adv / unitsPerEm,
|
|
56
66
|
fontFamily,
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
67
|
+
...(size === undefined ? null : {
|
|
68
|
+
fontSize: size
|
|
69
|
+
}),
|
|
70
|
+
...resolveWebStyle(style)
|
|
71
|
+
};
|
|
72
|
+
const inheritColor = color == null && followsTextColor(layers);
|
|
73
|
+
const resolveColor = createLayerColorResolver(color, tintMode, layers);
|
|
74
|
+
const box = square ? squareGlyphBox(adv, unitsPerEm, safeZone) : null;
|
|
75
|
+
const layerBoxStyle = box ? {
|
|
76
|
+
fontSize: `${box.scale}em`,
|
|
77
|
+
left: `calc(50% - ${adv / unitsPerEm / 2}em)`,
|
|
78
|
+
bottom: 'calc(50% - 0.5em)'
|
|
79
|
+
} : undefined;
|
|
80
|
+
const accessibility = iconAccessibilityProps({
|
|
81
|
+
accessible,
|
|
82
|
+
accessibilityLabel,
|
|
83
|
+
accessibilityRole,
|
|
84
|
+
accessibilityElementsHidden,
|
|
85
|
+
importantForAccessibility
|
|
86
|
+
});
|
|
87
|
+
const isHidden = accessibility.accessible === false || accessibility.accessibilityElementsHidden === true;
|
|
88
|
+
const role = accessibility.accessibilityRole === 'image' ? 'img' : accessibility.accessibilityRole;
|
|
89
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
90
|
+
children: [/*#__PURE__*/_jsx("style", {
|
|
91
|
+
href: BASE_HREF,
|
|
92
|
+
precedence: STYLE_PRECEDENCE,
|
|
93
|
+
children: BASE_CSS
|
|
94
|
+
}), fontFace ? /*#__PURE__*/_jsx("style", {
|
|
95
|
+
href: fontFace.href,
|
|
96
|
+
precedence: STYLE_PRECEDENCE,
|
|
97
|
+
children: fontFace.css
|
|
98
|
+
}) : null, /*#__PURE__*/_jsx("span", {
|
|
99
|
+
ref: ref,
|
|
100
|
+
className: className ? `${ICON_CLASS} ${className}` : ICON_CLASS,
|
|
101
|
+
style: containerStyle,
|
|
102
|
+
role: isHidden ? undefined : role,
|
|
103
|
+
"aria-label": isHidden ? undefined : accessibilityLabel || name,
|
|
104
|
+
"aria-hidden": isHidden || undefined,
|
|
105
|
+
"data-testid": testID,
|
|
106
|
+
children: layers.map(([codepoint, srcColor], i) => /*#__PURE__*/_jsx("span", {
|
|
76
107
|
"aria-hidden": true,
|
|
77
|
-
style: {
|
|
78
|
-
...
|
|
79
|
-
color:
|
|
108
|
+
style: inheritColor ? layerBoxStyle : {
|
|
109
|
+
...layerBoxStyle,
|
|
110
|
+
color: resolveColor(i, srcColor)
|
|
80
111
|
},
|
|
81
112
|
children: getChar(codepoint)
|
|
82
|
-
}, i)
|
|
83
|
-
})
|
|
113
|
+
}, i))
|
|
114
|
+
})]
|
|
84
115
|
});
|
|
85
|
-
},
|
|
116
|
+
}, areIconPropsEqual);
|
|
86
117
|
Icon.displayName = `NanoIcon(${fontBasename})`;
|
|
87
|
-
|
|
88
|
-
// No-op on web: the host app links the font under the configured family name, nothing to load at runtime.
|
|
89
118
|
const IconComp = Icon;
|
|
90
|
-
IconComp.loadFont =
|
|
119
|
+
IconComp.loadFont = override => {
|
|
120
|
+
const source = override ?? font;
|
|
121
|
+
const url = webFontUrl(source);
|
|
122
|
+
if (url) {
|
|
123
|
+
return registerWebFont(fontBasename, url).then(() => resolveFontIssue(family), cause => {
|
|
124
|
+
reportFontLoadFailure(family, linking, cause);
|
|
125
|
+
throw cause;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
if (source != null && typeof __DEV__ !== 'undefined' && __DEV__) {
|
|
129
|
+
warnFontNotLoaded(fontBasename);
|
|
130
|
+
}
|
|
131
|
+
return Promise.resolve();
|
|
132
|
+
};
|
|
91
133
|
return IconComp;
|
|
92
134
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import { TurboModuleRegistry } from 'react-native';
|
|
4
|
-
import { isFontRegistered } from
|
|
4
|
+
import { isFontRegistered } from './fontIntegrity';
|
|
5
5
|
import { loadDynamicFont } from "./loadDynamicFont.js";
|
|
6
6
|
import NanoIconsFontLoader from './nativeFontLoader';
|
|
7
7
|
export const DEV_SERVER_FONT_ROUTE = '/__nanoicons/';
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { isWebFontRegistered, registerWebFont } from "./webFont.js";
|
|
4
4
|
export const DEV_SERVER_FONT_ROUTE = '/__nanoicons/';
|
|
5
5
|
export function devServerFontUri(family) {
|
|
6
6
|
const origin = globalThis.location?.origin;
|
|
7
7
|
return origin ? `${origin}${DEV_SERVER_FONT_ROUTE}${encodeURIComponent(family)}.ttf` : undefined;
|
|
8
8
|
}
|
|
9
9
|
export async function loadFontFromDevServer(family) {
|
|
10
|
-
if (
|
|
10
|
+
if (isWebFontRegistered(family)) return true;
|
|
11
11
|
const uri = devServerFontUri(family);
|
|
12
12
|
if (!uri) return false;
|
|
13
13
|
try {
|
|
@@ -15,9 +15,7 @@ export async function loadFontFromDevServer(family) {
|
|
|
15
15
|
method: 'HEAD'
|
|
16
16
|
});
|
|
17
17
|
if (!head.ok) return false;
|
|
18
|
-
await
|
|
19
|
-
uri
|
|
20
|
-
});
|
|
18
|
+
await registerWebFont(family, uri);
|
|
21
19
|
return true;
|
|
22
20
|
} catch {
|
|
23
21
|
return false;
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import NanoIconsFontLoader from './nativeFontLoader';
|
|
4
|
+
import { __resetFontIssuesForTests, causeDetail, recordIssue } from "./fontIntegrityStore.js";
|
|
4
5
|
import { configuredFontFamily } from "./utils/fontIdentity.js";
|
|
5
6
|
import { errorRuntime, LOG_PREFIX, warnRuntime } from "./utils/runtimeLog.js";
|
|
7
|
+
export { addFontIntegrityListener, getFontIntegrityIssues, resolveFontIssue, useFontIntegrityIssue } from "./fontIntegrityStore.js";
|
|
6
8
|
const checked = new Set();
|
|
7
|
-
const issues = new Map();
|
|
8
|
-
const listeners = new Set();
|
|
9
9
|
let staleBinaryReported = false;
|
|
10
10
|
function hasNativeCheck() {
|
|
11
11
|
return typeof NanoIconsFontLoader?.isFontRegistered === 'function';
|
|
12
12
|
}
|
|
13
|
+
function hasSyncCheck() {
|
|
14
|
+
return typeof NanoIconsFontLoader?.isFontAvailable === 'function';
|
|
15
|
+
}
|
|
13
16
|
export function isFontRegistered(family) {
|
|
14
17
|
if (!NanoIconsFontLoader || !hasNativeCheck()) return Promise.resolve(false);
|
|
15
18
|
return NanoIconsFontLoader.isFontRegistered(family);
|
|
@@ -25,7 +28,20 @@ export async function checkFontIntegrity(family, linking) {
|
|
|
25
28
|
return;
|
|
26
29
|
}
|
|
27
30
|
if (await isFontRegistered(family)) return;
|
|
28
|
-
recordIssue(family, linking,
|
|
31
|
+
recordIssue(family, linking, missingFontMessage(family));
|
|
32
|
+
}
|
|
33
|
+
export function checkStaticFontNow(family) {
|
|
34
|
+
if (!NanoIconsFontLoader || !hasSyncCheck()) return false;
|
|
35
|
+
if (NanoIconsFontLoader.isFontAvailable(family)) return true;
|
|
36
|
+
if (__DEV__) return false;
|
|
37
|
+
if (!checked.has(family)) {
|
|
38
|
+
checked.add(family);
|
|
39
|
+
recordIssue(family, 'static', missingFontMessage(family), undefined, true);
|
|
40
|
+
}
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
function missingFontMessage(family) {
|
|
44
|
+
return `Icon font "${configuredFontFamily(family)}" is missing or out of date, so its icons will render blank. ` + 'Regenerate the icon fonts with the react-native-nano-icons CLI.';
|
|
29
45
|
}
|
|
30
46
|
export const FONT_MISMATCH_CODE = 'E_NANOICONS_FONT_MISMATCH';
|
|
31
47
|
export function isFontMismatch(err) {
|
|
@@ -58,42 +74,8 @@ async function reportDynamicFontIssue(family, message, cause) {
|
|
|
58
74
|
warnRuntime(message, ...causeDetail(cause));
|
|
59
75
|
}
|
|
60
76
|
}
|
|
61
|
-
function causeDetail(cause) {
|
|
62
|
-
return cause === undefined ? [] : [cause];
|
|
63
|
-
}
|
|
64
|
-
function recordIssue(family, linking, message, cause) {
|
|
65
|
-
const issue = {
|
|
66
|
-
fontFamily: configuredFontFamily(family),
|
|
67
|
-
family,
|
|
68
|
-
linking,
|
|
69
|
-
message,
|
|
70
|
-
...(cause === undefined ? {} : {
|
|
71
|
-
cause
|
|
72
|
-
})
|
|
73
|
-
};
|
|
74
|
-
issues.set(family, issue);
|
|
75
|
-
if (__DEV__) warnRuntime(message, ...causeDetail(cause));
|
|
76
|
-
for (const listener of listeners) listener(issue, 'found');
|
|
77
|
-
}
|
|
78
|
-
export function resolveFontIssue(family) {
|
|
79
|
-
const issue = issues.get(family);
|
|
80
|
-
if (!issue) return;
|
|
81
|
-
issues.delete(family);
|
|
82
|
-
for (const listener of listeners) listener(issue, 'resolved');
|
|
83
|
-
}
|
|
84
|
-
export function addFontIntegrityListener(listener) {
|
|
85
|
-
listeners.add(listener);
|
|
86
|
-
for (const issue of issues.values()) listener(issue, 'found');
|
|
87
|
-
return () => {
|
|
88
|
-
listeners.delete(listener);
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
export function getFontIntegrityIssues() {
|
|
92
|
-
return [...issues.values()];
|
|
93
|
-
}
|
|
94
77
|
export function __resetFontIntegrityForTests() {
|
|
95
78
|
staleBinaryReported = false;
|
|
96
79
|
checked.clear();
|
|
97
|
-
|
|
98
|
-
listeners.clear();
|
|
80
|
+
__resetFontIssuesForTests();
|
|
99
81
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { __resetFontIssuesForTests, getFontIntegrityIssues, recordIssue } from "./fontIntegrityStore.js";
|
|
4
|
+
import { configuredFontFamily } from "./utils/fontIdentity.js";
|
|
5
|
+
export { addFontIntegrityListener, getFontIntegrityIssues, resolveFontIssue, useFontIntegrityIssue } from "./fontIntegrityStore.js";
|
|
6
|
+
const watched = new Map();
|
|
7
|
+
let listeningTo;
|
|
8
|
+
function documentFonts() {
|
|
9
|
+
return globalThis.document?.fonts;
|
|
10
|
+
}
|
|
11
|
+
function facesOf(fonts, family) {
|
|
12
|
+
const names = [family, configuredFontFamily(family)];
|
|
13
|
+
const faces = [];
|
|
14
|
+
fonts.forEach(face => {
|
|
15
|
+
if (names.includes(face.family.replace(/^["']|["']$/g, ''))) {
|
|
16
|
+
faces.push(face);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
return faces;
|
|
20
|
+
}
|
|
21
|
+
export function reportFontLoadFailure(family, linking, cause) {
|
|
22
|
+
const fonts = documentFonts();
|
|
23
|
+
if (!fonts || getFontIntegrityIssues().some(issue => issue.family === family) || facesOf(fonts, family).some(face => face.status === 'loaded' || face.status === 'loading')) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
recordIssue(family, linking, `Icon font "${configuredFontFamily(family)}" could not be loaded, so its icons will render blank. ` + 'Check that its font url serves a valid font file.', cause);
|
|
27
|
+
}
|
|
28
|
+
function reportFailedFaces(fonts) {
|
|
29
|
+
for (const [family, linking] of watched) {
|
|
30
|
+
const failed = facesOf(fonts, family).find(face => face.status === 'error');
|
|
31
|
+
failed?.loaded.catch(cause => reportFontLoadFailure(family, linking, cause));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export function watchFontLoadFailures(family, linking) {
|
|
35
|
+
const fonts = documentFonts();
|
|
36
|
+
if (!fonts) return;
|
|
37
|
+
watched.set(family, linking);
|
|
38
|
+
if (listeningTo !== fonts) {
|
|
39
|
+
listeningTo = fonts;
|
|
40
|
+
fonts.addEventListener('loadingerror', () => reportFailedFaces(fonts));
|
|
41
|
+
}
|
|
42
|
+
reportFailedFaces(fonts);
|
|
43
|
+
}
|
|
44
|
+
export function __resetFontIntegrityForTests() {
|
|
45
|
+
watched.clear();
|
|
46
|
+
listeningTo = undefined;
|
|
47
|
+
__resetFontIssuesForTests();
|
|
48
|
+
}
|