react-native-nano-icons 1.0.0 → 1.1.0-beta.1
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 +137 -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 +9 -2
- package/android/src/main/java/com/nanoicons/NanoIconsFontLoaderModule.kt +3 -0
- package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconProps.cpp +122 -0
- package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconProps.h +60 -0
- package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconViewShadowNode.cpp +0 -39
- package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconViewShadowNode.h +2 -16
- package/ios/NanoIconView.mm +17 -5
- 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 +17 -0
- package/lib/commonjs/cli/buildSymbols.js +103 -42
- package/lib/commonjs/cli/expoConfig.d.ts +10 -0
- package/lib/commonjs/cli/expoConfig.js +22 -7
- package/lib/commonjs/cli/fingerprint.d.ts +15 -0
- package/lib/commonjs/cli/fingerprint.js +36 -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 +25 -0
- 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 +10 -0
- 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/pathkit/winding.d.ts +7 -1
- package/lib/commonjs/src/core/pathkit/winding.js +172 -0
- 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 +3 -16
- package/lib/commonjs/src/core/pipeline/prepareIcon.d.ts +1 -0
- package/lib/commonjs/src/core/pipeline/prepareIcon.js +1 -1
- package/lib/commonjs/src/core/pipeline/preparedSvgCache.js +1 -1
- package/lib/commonjs/src/core/pipeline/runFontPipeline.js +20 -12
- package/lib/commonjs/src/core/symbols/knockout.js +4 -3
- package/lib/commonjs/src/utils/fingerPrint.d.ts +1 -0
- package/lib/commonjs/src/utils/fingerPrint.js +3 -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 +26 -21
- 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 +3 -2
- package/lib/module/utils/fingerPrint.js +3 -2
- package/lib/module/utils/fontIdentity.js +2 -2
- package/lib/module/utils/fontScale.js +23 -0
- 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/pathkit/winding.d.ts +7 -1
- 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 +3 -2
- 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 +1 -0
- package/lib/typescript/src/utils/fontIdentity.d.ts +1 -1
- package/lib/typescript/src/utils/fontScale.d.ts +2 -0
- 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 +3 -2
- 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,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
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { configuredFontFamily } from "./utils/fontIdentity.js";
|
|
5
|
+
import { warnRuntime } from "./utils/runtimeLog.js";
|
|
6
|
+
const issues = new Map();
|
|
7
|
+
const listeners = new Set();
|
|
8
|
+
export function causeDetail(cause) {
|
|
9
|
+
return cause === undefined ? [] : [cause];
|
|
10
|
+
}
|
|
11
|
+
export function recordIssue(family, linking, message, cause, notifyLater = false) {
|
|
12
|
+
const issue = {
|
|
13
|
+
fontFamily: configuredFontFamily(family),
|
|
14
|
+
family,
|
|
15
|
+
linking,
|
|
16
|
+
message,
|
|
17
|
+
...(cause === undefined ? {} : {
|
|
18
|
+
cause
|
|
19
|
+
})
|
|
20
|
+
};
|
|
21
|
+
issues.set(family, issue);
|
|
22
|
+
if (typeof __DEV__ !== 'undefined' && __DEV__) {
|
|
23
|
+
warnRuntime(message, ...causeDetail(cause));
|
|
24
|
+
}
|
|
25
|
+
if (!notifyLater) {
|
|
26
|
+
for (const listener of listeners) listener(issue, 'found');
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const subscribed = [...listeners];
|
|
30
|
+
void Promise.resolve().then(() => {
|
|
31
|
+
for (const listener of subscribed) {
|
|
32
|
+
if (listeners.has(listener)) listener(issue, 'found');
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
export function resolveFontIssue(family) {
|
|
37
|
+
const issue = issues.get(family);
|
|
38
|
+
if (!issue) return;
|
|
39
|
+
issues.delete(family);
|
|
40
|
+
for (const listener of listeners) listener(issue, 'resolved');
|
|
41
|
+
}
|
|
42
|
+
export function addFontIntegrityListener(listener) {
|
|
43
|
+
listeners.add(listener);
|
|
44
|
+
for (const issue of issues.values()) listener(issue, 'found');
|
|
45
|
+
return () => {
|
|
46
|
+
listeners.delete(listener);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export function getFontIntegrityIssues() {
|
|
50
|
+
return [...issues.values()];
|
|
51
|
+
}
|
|
52
|
+
function subscribe(onChange) {
|
|
53
|
+
const listener = () => onChange();
|
|
54
|
+
listeners.add(listener);
|
|
55
|
+
return () => {
|
|
56
|
+
listeners.delete(listener);
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export function useFontIntegrityIssue(family) {
|
|
60
|
+
return React.useSyncExternalStore(subscribe, () => issues.get(family), () => undefined);
|
|
61
|
+
}
|
|
62
|
+
export function __resetFontIssuesForTests() {
|
|
63
|
+
issues.clear();
|
|
64
|
+
listeners.clear();
|
|
65
|
+
}
|
package/lib/module/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
export { createIconSet as createNanoIconSet } from './createNanoIconsSet';
|
|
4
|
-
export { addFontIntegrityListener, getFontIntegrityIssues } from
|
|
4
|
+
export { addFontIntegrityListener, getFontIntegrityIssues, useFontIntegrityIssue } from './fontIntegrity';
|
package/lib/module/index.node.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import { useSyncExternalStore } from 'react';
|
|
4
|
-
import { Image
|
|
5
|
-
import { FONT_SOURCE_CODE, resolveFontIssue } from
|
|
4
|
+
import { Image } from 'react-native';
|
|
5
|
+
import { FONT_SOURCE_CODE, resolveFontIssue } from './fontIntegrity';
|
|
6
6
|
import NanoIconsFontLoader from './nativeFontLoader';
|
|
7
7
|
import { runtimeError } from "./utils/runtimeLog.js";
|
|
8
8
|
|
|
@@ -46,18 +46,6 @@ export function resolveFontUri(font) {
|
|
|
46
46
|
throw fontSourceError('Unsupported font source. Pass require("Foo.ttf"), { uri }, or a path string.');
|
|
47
47
|
}
|
|
48
48
|
async function register(family, uri) {
|
|
49
|
-
if (Platform.OS === 'web') {
|
|
50
|
-
// Browser FontFace API. Typed loosely so this compiles under both the RN-only
|
|
51
|
-
// lib config and a DOM-aware app config without depending on the DOM lib.
|
|
52
|
-
const g = globalThis;
|
|
53
|
-
if (!g.FontFace || !g.document?.fonts) {
|
|
54
|
-
throw runtimeError('FontFace API unavailable; cannot load dynamic font on this platform.');
|
|
55
|
-
}
|
|
56
|
-
const face = new g.FontFace(family, `url(${uri})`);
|
|
57
|
-
await face.load();
|
|
58
|
-
g.document.fonts.add(face);
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
49
|
if (!NanoIconsFontLoader) {
|
|
62
50
|
throw runtimeError('Native font loader is unavailable (Expo Go or module not built). ' + 'Load the font yourself, or use a development/production build.');
|
|
63
51
|
}
|
|
@@ -113,7 +101,7 @@ export function useDynamicFontPending(managed, family) {
|
|
|
113
101
|
const status = useDynamicFontStatus(family);
|
|
114
102
|
return managed && status === 'loading';
|
|
115
103
|
}
|
|
116
|
-
|
|
104
|
+
function useDynamicFontStatus(family) {
|
|
117
105
|
return useSyncExternalStore(cb => {
|
|
118
106
|
listeners.add(cb);
|
|
119
107
|
return () => listeners.delete(cb);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { codegenNativeComponent } from 'react-native';
|
|
2
2
|
import type { ColorValue, ViewProps } from 'react-native';
|
|
3
|
-
import type { Float, Int32 } from '../const/codegenPrimitives';
|
|
3
|
+
import type { Float, Int32, WithDefault } from '../const/codegenPrimitives';
|
|
4
4
|
|
|
5
5
|
export interface NativeProps extends ViewProps {
|
|
6
6
|
fontFamily: string;
|
|
@@ -9,9 +9,10 @@ export interface NativeProps extends ViewProps {
|
|
|
9
9
|
color?: ColorValue;
|
|
10
10
|
tintLayers: ReadonlyArray<Int32>;
|
|
11
11
|
size: Float;
|
|
12
|
-
|
|
12
|
+
fontScale: Float;
|
|
13
13
|
advanceWidth: Int32;
|
|
14
14
|
unitsPerEm: Int32;
|
|
15
|
+
squareGlyphScale?: WithDefault<Float, 0>;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
export default codegenNativeComponent<NativeProps>('NanoIconView', {
|
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
const crypto = require('crypto');
|
|
4
4
|
const fs = require('fs');
|
|
5
5
|
const path = require('path');
|
|
6
|
+
const CRLF = /\r\n/g;
|
|
6
7
|
export function getFingerprintSync(dir, inputs) {
|
|
7
8
|
return fingerprintSvgDirSync(dir, inputs).hash;
|
|
8
9
|
}
|
|
9
10
|
export function fingerprintSvgDirSync(dir, inputs) {
|
|
10
|
-
return hashSvgDir(dir, [inputs.upm, inputs.safeZone, inputs.startUnicode, inputs.version, inputs.toolchain]);
|
|
11
|
+
return hashSvgDir(dir, [inputs.upm, inputs.safeZone, inputs.curveTolerance, inputs.startUnicode, inputs.version, inputs.toolchain]);
|
|
11
12
|
}
|
|
12
13
|
export function fingerprintSymbolDirSync(dir, inputs) {
|
|
13
14
|
return hashSvgDir(dir, ['symbol', inputs.prefix, inputs.version, inputs.toolchain]);
|
|
@@ -18,7 +19,7 @@ function hashSvgDir(dir, settings) {
|
|
|
18
19
|
const svgHashByFile = new Map();
|
|
19
20
|
for (const file of files) {
|
|
20
21
|
const filePath = path.join(dir, file);
|
|
21
|
-
const content = fs.readFileSync(filePath);
|
|
22
|
+
const content = fs.readFileSync(filePath, 'utf8').replace(CRLF, '\n');
|
|
22
23
|
// Hash both path and content
|
|
23
24
|
hash.update(file);
|
|
24
25
|
hash.update(content);
|
|
@@ -5,8 +5,8 @@ const BUILD_HASH = `[0-9a-f]{${BUILD_HASH_LENGTH}}`;
|
|
|
5
5
|
const BUILD_SUFFIX = new RegExp(`-${BUILD_HASH}$`);
|
|
6
6
|
const BUILD_FONT_FILE = new RegExp(`-${BUILD_HASH}\\.ttf$`);
|
|
7
7
|
const REGEX_SPECIALS = /[.*+?^${}()|[\]\\]/g;
|
|
8
|
-
export function buildFontFamily(fontFamily,
|
|
9
|
-
return `${fontFamily}-${
|
|
8
|
+
export function buildFontFamily(fontFamily, contentHash) {
|
|
9
|
+
return `${fontFamily}-${contentHash.slice(0, BUILD_HASH_LENGTH)}`;
|
|
10
10
|
}
|
|
11
11
|
export function configuredFontFamily(family) {
|
|
12
12
|
return family.replace(BUILD_SUFFIX, '');
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { useSyncExternalStore } from 'react';
|
|
4
|
+
import { Dimensions, PixelRatio } from 'react-native';
|
|
5
|
+
function subscribe(onChange) {
|
|
6
|
+
const subscription = Dimensions.addEventListener('change', onChange);
|
|
7
|
+
return () => subscription.remove();
|
|
8
|
+
}
|
|
9
|
+
function getFontScale() {
|
|
10
|
+
return PixelRatio.getFontScale();
|
|
11
|
+
}
|
|
12
|
+
function subscribeNever() {
|
|
13
|
+
return () => {};
|
|
14
|
+
}
|
|
15
|
+
function noScale() {
|
|
16
|
+
return 1;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Icons with font scaling disabled don't subscribe, so they don't add a
|
|
20
|
+
// Dimensions listener or re-render on window changes.
|
|
21
|
+
export function useFontScale(enabled) {
|
|
22
|
+
return useSyncExternalStore(enabled ? subscribe : subscribeNever, enabled ? getFontScale : noScale);
|
|
23
|
+
}
|
|
@@ -11,6 +11,19 @@ export function resolveGlyphEntry(glyphMap, name) {
|
|
|
11
11
|
return glyphMap.i[name] ?? [glyphMap.m.u, [[63, 'black']]];
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Size of a glyph in a square box, as fractions of the box side: the glyph's
|
|
16
|
+
* longer side fits the safe zone.
|
|
17
|
+
*/
|
|
18
|
+
export function squareGlyphBox(advanceWidth, unitsPerEm, safeZone) {
|
|
19
|
+
const contentWidth = advanceWidth - (unitsPerEm - safeZone);
|
|
20
|
+
const scale = contentWidth > safeZone ? safeZone / contentWidth : 1;
|
|
21
|
+
return {
|
|
22
|
+
scale,
|
|
23
|
+
width: advanceWidth / unitsPerEm * scale
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
14
27
|
/** A memoized codepoint -> string converter, scoped per icon set. */
|
|
15
28
|
export function createCharCache() {
|
|
16
29
|
const cache = new Map();
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
export function iconAccessibilityProps({
|
|
4
|
+
accessible,
|
|
5
|
+
accessibilityLabel,
|
|
6
|
+
accessibilityRole,
|
|
7
|
+
accessibilityElementsHidden,
|
|
8
|
+
importantForAccessibility
|
|
9
|
+
}) {
|
|
10
|
+
if (accessibilityLabel || accessible === true || accessibilityElementsHidden === false || importantForAccessibility === 'yes' || accessibilityRole !== undefined && accessibilityRole !== 'none') {
|
|
11
|
+
return {
|
|
12
|
+
accessible,
|
|
13
|
+
accessibilityLabel,
|
|
14
|
+
accessibilityRole: accessibilityRole ?? 'image',
|
|
15
|
+
accessibilityElementsHidden,
|
|
16
|
+
importantForAccessibility
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
accessible: accessible ?? false,
|
|
21
|
+
accessibilityLabel,
|
|
22
|
+
accessibilityRole,
|
|
23
|
+
accessibilityElementsHidden: accessibilityElementsHidden ?? true,
|
|
24
|
+
importantForAccessibility: importantForAccessibility ?? 'no-hide-descendants'
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { shallowEqualColor } from "./shallowEqualColor.js";
|
|
4
|
+
const hasOwn = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
|
|
5
|
+
export function shallowEqualStyle(a, b) {
|
|
6
|
+
if (a === b) return true;
|
|
7
|
+
if (Array.isArray(a) || Array.isArray(b)) {
|
|
8
|
+
return Array.isArray(a) && Array.isArray(b) && a.length === b.length && a.every((item, i) => shallowEqualStyle(item, b[i]));
|
|
9
|
+
}
|
|
10
|
+
if (a === null || b === null || typeof a !== 'object' || typeof b !== 'object') {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
const aStyle = a;
|
|
14
|
+
const bStyle = b;
|
|
15
|
+
const keys = Object.keys(aStyle);
|
|
16
|
+
return keys.length === Object.keys(bStyle).length && keys.every(key => hasOwn(bStyle, key) && Object.is(aStyle[key], bStyle[key]));
|
|
17
|
+
}
|
|
18
|
+
export function areIconPropsEqual(prev, next) {
|
|
19
|
+
const keys = Object.keys(prev);
|
|
20
|
+
if (keys.length !== Object.keys(next).length) return false;
|
|
21
|
+
return keys.every(key => {
|
|
22
|
+
if (!hasOwn(next, key)) return false;
|
|
23
|
+
if (key === 'style') return shallowEqualStyle(prev.style, next.style);
|
|
24
|
+
if (key === 'color') return shallowEqualColor(prev.color, next.color);
|
|
25
|
+
return Object.is(prev[key], next[key]);
|
|
26
|
+
});
|
|
27
|
+
}
|