react-native-nano-icons 1.0.1 → 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.
Files changed (117) hide show
  1. package/README.md +137 -21
  2. package/android/src/main/java/com/nanoicons/NanoIconFonts.kt +15 -0
  3. package/android/src/main/java/com/nanoicons/NanoIconView.kt +27 -4
  4. package/android/src/main/java/com/nanoicons/NanoIconViewManager.kt +7 -0
  5. package/android/src/main/java/com/nanoicons/NanoIconsFontLoaderModule.kt +3 -0
  6. package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconProps.cpp +6 -1
  7. package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconProps.h +4 -2
  8. package/ios/NanoIconView.mm +12 -0
  9. package/ios/NanoIconsFontLoader.mm +5 -0
  10. package/lib/commonjs/cli/build.d.ts +26 -0
  11. package/lib/commonjs/cli/build.js +174 -64
  12. package/lib/commonjs/cli/buildSymbols.d.ts +17 -0
  13. package/lib/commonjs/cli/buildSymbols.js +103 -42
  14. package/lib/commonjs/cli/expoConfig.d.ts +10 -0
  15. package/lib/commonjs/cli/expoConfig.js +22 -7
  16. package/lib/commonjs/cli/fingerprint.d.ts +15 -0
  17. package/lib/commonjs/cli/fingerprint.js +36 -0
  18. package/lib/commonjs/cli/index.d.ts +2 -2
  19. package/lib/commonjs/cli/index.js +3 -1
  20. package/lib/commonjs/cli/link.d.ts +4 -0
  21. package/lib/commonjs/cli/link.js +25 -0
  22. package/lib/commonjs/cli/sameOutputs.d.ts +5 -0
  23. package/lib/commonjs/cli/sameOutputs.js +45 -0
  24. package/lib/commonjs/index.node.js +1 -1
  25. package/lib/commonjs/plugin/src/buildFonts.d.ts +3 -2
  26. package/lib/commonjs/plugin/src/buildFonts.js +11 -3
  27. package/lib/commonjs/plugin/src/buildSymbols.d.ts +2 -2
  28. package/lib/commonjs/plugin/src/buildSymbols.js +10 -3
  29. package/lib/commonjs/plugin/src/frozen.d.ts +3 -0
  30. package/lib/commonjs/plugin/src/frozen.js +18 -0
  31. package/lib/commonjs/plugin/src/index.js +3 -3
  32. package/lib/commonjs/plugin/src/types.d.ts +10 -0
  33. package/lib/commonjs/plugin/src/withNanoIconsDrawableLinking.d.ts +1 -1
  34. package/lib/commonjs/plugin/src/withNanoIconsDrawableLinking.js +2 -2
  35. package/lib/commonjs/plugin/src/withNanoIconsFontLinking.d.ts +3 -3
  36. package/lib/commonjs/plugin/src/withNanoIconsFontLinking.js +8 -8
  37. package/lib/commonjs/plugin/src/withNanoIconsSymbolLinking.d.ts +1 -1
  38. package/lib/commonjs/plugin/src/withNanoIconsSymbolLinking.js +2 -2
  39. package/lib/commonjs/scripts/cli.js +31 -2
  40. package/lib/commonjs/src/core/flatten/dom.js +40 -5
  41. package/lib/commonjs/src/core/flatten/element.js +2 -1
  42. package/lib/commonjs/src/core/flatten/stages/collapse.js +12 -0
  43. package/lib/commonjs/src/core/font/compile.d.ts +0 -1
  44. package/lib/commonjs/src/core/font/compile.js +2 -8
  45. package/lib/commonjs/src/core/glyph/merge.d.ts +2 -1
  46. package/lib/commonjs/src/core/glyph/merge.js +27 -36
  47. package/lib/commonjs/src/core/glyph/parse.d.ts +1 -2
  48. package/lib/commonjs/src/core/glyph/parse.js +31 -18
  49. package/lib/commonjs/src/core/pathkit/winding.d.ts +7 -1
  50. package/lib/commonjs/src/core/pathkit/winding.js +172 -0
  51. package/lib/commonjs/src/core/pipeline/config.d.ts +1 -0
  52. package/lib/commonjs/src/core/pipeline/prepare.d.ts +1 -1
  53. package/lib/commonjs/src/core/pipeline/prepare.js +3 -16
  54. package/lib/commonjs/src/core/pipeline/prepareIcon.d.ts +1 -0
  55. package/lib/commonjs/src/core/pipeline/prepareIcon.js +1 -1
  56. package/lib/commonjs/src/core/pipeline/preparedSvgCache.js +1 -1
  57. package/lib/commonjs/src/core/pipeline/runFontPipeline.js +20 -12
  58. package/lib/commonjs/src/core/symbols/knockout.js +4 -3
  59. package/lib/commonjs/src/utils/fingerPrint.d.ts +1 -0
  60. package/lib/commonjs/src/utils/fingerPrint.js +3 -1
  61. package/lib/commonjs/src/utils/fontIdentity.d.ts +1 -1
  62. package/lib/commonjs/src/utils/fontIdentity.js +2 -2
  63. package/lib/module/createNanoIconsSet.js +0 -1
  64. package/lib/module/createNanoIconsSet.native.js +22 -18
  65. package/lib/module/createNanoIconsSet.shared.js +32 -18
  66. package/lib/module/createNanoIconsSet.web.js +103 -61
  67. package/lib/module/devServerFont.js +1 -1
  68. package/lib/module/devServerFont.web.js +3 -5
  69. package/lib/module/fontIntegrity.js +20 -38
  70. package/lib/module/fontIntegrity.web.js +48 -0
  71. package/lib/module/fontIntegrityStore.js +65 -0
  72. package/lib/module/index.js +1 -1
  73. package/lib/module/index.node.js +1 -1
  74. package/lib/module/index.web.js +4 -0
  75. package/lib/module/loadDynamicFont.js +3 -15
  76. package/lib/module/specs/NanoIconViewNativeComponent.ts +2 -1
  77. package/lib/module/utils/fingerPrint.js +3 -2
  78. package/lib/module/utils/fontIdentity.js +2 -2
  79. package/lib/module/utils/fontScale.js +10 -2
  80. package/lib/module/utils/glyphRuntime.js +13 -0
  81. package/lib/module/utils/iconAccessibility.js +26 -0
  82. package/lib/module/utils/iconPropsEqual.js +27 -0
  83. package/lib/module/utils/webCss.js +26 -0
  84. package/lib/module/utils/webStyle.js +86 -0
  85. package/lib/module/webFont.js +33 -0
  86. package/lib/typescript/src/const/codegenPrimitives.d.ts +1 -0
  87. package/lib/typescript/src/core/glyph/merge.d.ts +2 -1
  88. package/lib/typescript/src/core/glyph/parse.d.ts +1 -2
  89. package/lib/typescript/src/core/pathkit/winding.d.ts +7 -1
  90. package/lib/typescript/src/createNanoIconsSet.d.ts +0 -1
  91. package/lib/typescript/src/createNanoIconsSet.native.d.ts +0 -2
  92. package/lib/typescript/src/createNanoIconsSet.shared.d.ts +1 -3
  93. package/lib/typescript/src/createNanoIconsSet.web.d.ts +1 -2
  94. package/lib/typescript/src/fontIntegrity.d.ts +2 -14
  95. package/lib/typescript/src/fontIntegrity.web.d.ts +7 -0
  96. package/lib/typescript/src/fontIntegrityStore.d.ts +19 -0
  97. package/lib/typescript/src/index.d.ts +2 -1
  98. package/lib/typescript/src/index.web.d.ts +5 -0
  99. package/lib/typescript/src/loadDynamicFont.d.ts +0 -1
  100. package/lib/typescript/src/specs/NanoIconViewNativeComponent.d.ts +2 -1
  101. package/lib/typescript/src/specs/NativeNanoIconsFontLoader.d.ts +1 -0
  102. package/lib/typescript/src/types.d.ts +37 -9
  103. package/lib/typescript/src/utils/fingerPrint.d.ts +1 -0
  104. package/lib/typescript/src/utils/fontIdentity.d.ts +1 -1
  105. package/lib/typescript/src/utils/glyphRuntime.d.ts +8 -0
  106. package/lib/typescript/src/utils/iconAccessibility.d.ts +4 -0
  107. package/lib/typescript/src/utils/iconPropsEqual.d.ts +4 -0
  108. package/lib/typescript/src/utils/webCss.d.ts +9 -0
  109. package/lib/typescript/src/utils/webStyle.d.ts +3 -0
  110. package/lib/typescript/src/webFont.d.ts +6 -0
  111. package/package.json +19 -3
  112. package/src/const/codegenPrimitives.ts +3 -3
  113. package/src/specs/NanoIconViewNativeComponent.ts +2 -1
  114. package/src/specs/NativeNanoIconsFontLoader.ts +1 -0
  115. package/lib/commonjs/src/core/pathkit/evenodd.d.ts +0 -12
  116. package/lib/commonjs/src/core/pathkit/evenodd.js +0 -37
  117. package/lib/typescript/src/core/pathkit/evenodd.d.ts +0 -13
@@ -2,16 +2,16 @@
2
2
 
3
3
  import { memo, useMemo } from 'react';
4
4
  import { UIManager, View } from 'react-native';
5
- import { shallowEqualColor } from "./utils/shallowEqualColor.js";
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 "./fontIntegrity.js";
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 = 'image',
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 width = adv / unitsPerEm * scaledSize;
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
- accessible: accessible,
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
- accessible: accessible,
133
- accessibilityRole: accessibilityRole,
134
- accessibilityLabel: accessibilityLabel ?? name,
135
- accessibilityElementsHidden: accessibilityElementsHidden,
136
- importantForAccessibility: importantForAccessibility,
140
+ ...accessibility,
137
141
  testID: testID
138
142
  });
139
- }, (prev, next) => prev.name === next.name && prev.size === next.size && prev.allowFontScaling === next.allowFontScaling && prev.style === next.style && prev.tintMode === next.tintMode && shallowEqualColor(prev.color, next.color));
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 { shallowEqualColor } from "./utils/shallowEqualColor.js";
6
- import { DEFAULT_ICON_SIZE, resolveGlyphEntry, createCharCache, createLayerColorResolver } from "./utils/glyphRuntime.js";
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 "./fontIntegrity.js";
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 on web and as a fallback when native component is unavailable (e.g. Expo Go).
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 = 'image',
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 width = adv / unitsPerEm * scaledSize;
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 sizeStyle = useMemo(() => ({
95
- fontSize: size
96
- }), [size]);
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
- accessible: accessible,
101
- accessibilityRole: accessibilityRole,
102
- accessibilityLabel: accessibilityLabel ?? name,
103
- accessibilityElementsHidden: accessibilityElementsHidden,
104
- importantForAccessibility: importantForAccessibility,
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, sizeStyle, {
126
+ style: [styleOverrides, glyphStyle, {
113
127
  color: layerColor
114
128
  }],
115
129
  children: getChar(codepoint)
116
130
  }, i);
117
131
  })
118
132
  });
119
- }, (prev, next) => prev.name === next.name && prev.size === next.size && prev.allowFontScaling === next.allowFontScaling && prev.style === next.style && prev.tintMode === next.tintMode && shallowEqualColor(prev.color, next.color));
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, useMemo } from 'react';
4
- import { shallowEqualColor } from "./utils/shallowEqualColor.js";
5
- import { DEFAULT_ICON_SIZE, resolveGlyphEntry, createCharCache, createLayerColorResolver } from "./utils/glyphRuntime.js";
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 { useDynamicFontStatus } from "./loadDynamicFont.js";
8
- import { jsx as _jsx } from "react/jsx-runtime";
9
- export { shallowEqualColor };
10
- async function loadFontFromDevServer(family) {
11
- if (__DEV__) {
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
- export function createIconSet(glyphMap) {
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
- void loadFontFromDevServer(family);
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 = DEFAULT_ICON_SIZE,
42
+ size,
28
43
  color,
29
44
  tintMode,
45
+ frame,
30
46
  style,
31
47
  accessible,
32
48
  accessibilityLabel,
33
- accessibilityRole = 'image',
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 width = adv / unitsPerEm * size;
41
- const fontFamily = useDynamicFontStatus(family) === 'ready' ? family : fontBasename;
42
- const resolveColor = createLayerColorResolver(color, tintMode, layers);
43
- const containerStyle = useMemo(() => ({
44
- display: 'inline-block',
45
- position: 'relative',
46
- width,
47
- height: size,
48
- lineHeight: 0,
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
- fontWeight: 'normal',
58
- fontStyle: 'normal',
59
- fontSize: size,
60
- lineHeight: 1,
61
- whiteSpace: 'pre'
62
- }), [size, fontFamily]);
63
- const isHidden = accessible === false || accessibilityElementsHidden;
64
- const role = accessibilityRole === 'image' ? 'img' : accessibilityRole;
65
- return /*#__PURE__*/_jsx("span", {
66
- ref: ref,
67
- className: className,
68
- style: containerStyle,
69
- role: isHidden ? undefined : role,
70
- "aria-label": isHidden ? undefined : accessibilityLabel ?? name,
71
- "aria-hidden": isHidden || undefined,
72
- "data-testid": testID,
73
- children: layers.map(([codepoint, srcColor], i) => {
74
- const layerColor = resolveColor(i, srcColor);
75
- return /*#__PURE__*/_jsx("span", {
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
- ...layerBaseStyle,
79
- color: layerColor
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
- }, (prev, next) => prev.name === next.name && prev.size === next.size && prev.style === next.style && prev.className === next.className && prev.tintMode === next.tintMode && shallowEqualColor(prev.color, next.color));
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 = () => Promise.resolve();
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 "./fontIntegrity.js";
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 { getFontStatus, loadDynamicFont } from "./loadDynamicFont.js";
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 (getFontStatus(family) === 'ready') return true;
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 loadDynamicFont(family, {
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, `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.');
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
- issues.clear();
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
+ }
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
 
3
3
  export { createIconSet as createNanoIconSet } from './createNanoIconsSet';
4
- export { addFontIntegrityListener, getFontIntegrityIssues } from "./fontIntegrity.js";
4
+ export { addFontIntegrityListener, getFontIntegrityIssues, useFontIntegrityIssue } from './fontIntegrity';
@@ -3,7 +3,7 @@
3
3
  const createNanoIconSet = (...args) => {
4
4
  const {
5
5
  createIconSet
6
- } = require('./createNanoIconsSet');
6
+ } = require('../module/createNanoIconsSet.web.js');
7
7
  return createIconSet(...args);
8
8
  };
9
9
  const plugin = require('./plugin/src/index').default;