react-native-nano-icons 1.0.0-beta.1 → 1.0.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 +124 -2
- package/android/build.gradle +8 -1
- package/android/src/main/java/com/nanoicons/NanoIconView.kt +53 -4
- package/android/src/main/java/com/nanoicons/NanoIconViewManager.kt +42 -18
- package/android/src/main/jni/CMakeLists.txt +38 -0
- package/android/src/main/jni/RNNanoIconsSpec.h +19 -0
- package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconViewComponentDescriptor.h +11 -0
- package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconViewShadowNode.cpp +46 -0
- package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconViewShadowNode.h +41 -0
- package/ios/NanoIconInlineBaseline.h +4 -0
- package/ios/NanoIconInlineBaseline.mm +190 -0
- package/ios/NanoIconView.h +1 -0
- package/ios/NanoIconView.mm +118 -107
- package/lib/commonjs/cli/build.d.ts +5 -0
- package/lib/commonjs/cli/build.js +37 -15
- package/lib/commonjs/cli/buildSymbols.d.ts +26 -0
- package/lib/commonjs/cli/buildSymbols.js +134 -0
- package/lib/commonjs/cli/config.d.ts +3 -1
- package/lib/commonjs/cli/config.js +3 -3
- package/lib/commonjs/cli/expoConfig.d.ts +3 -0
- package/lib/commonjs/cli/expoConfig.js +17 -6
- package/lib/commonjs/cli/index.d.ts +4 -2
- package/lib/commonjs/cli/index.js +12 -1
- package/lib/commonjs/cli/link.d.ts +15 -0
- package/lib/commonjs/cli/link.js +185 -1
- package/lib/commonjs/metro/fontRebuildWatcher.d.ts +62 -0
- package/lib/commonjs/metro/fontRebuildWatcher.js +174 -0
- package/lib/commonjs/metro/index.d.ts +35 -0
- package/lib/commonjs/metro/index.js +92 -0
- package/lib/commonjs/metro/symbolRebuildWatcher.d.ts +19 -0
- package/lib/commonjs/metro/symbolRebuildWatcher.js +76 -0
- package/lib/commonjs/plugin/src/buildSymbols.d.ts +3 -0
- package/lib/commonjs/plugin/src/buildSymbols.js +18 -0
- package/lib/commonjs/plugin/src/index.d.ts +1 -1
- package/lib/commonjs/plugin/src/index.js +9 -3
- package/lib/commonjs/plugin/src/types.d.ts +34 -2
- package/lib/commonjs/plugin/src/withNanoIconsDrawableLinking.d.ts +8 -0
- package/lib/commonjs/plugin/src/withNanoIconsDrawableLinking.js +29 -0
- package/lib/commonjs/plugin/src/withNanoIconsSymbolLinking.d.ts +8 -0
- package/lib/commonjs/plugin/src/withNanoIconsSymbolLinking.js +37 -0
- package/lib/commonjs/scripts/cli.js +27 -9
- package/lib/commonjs/src/core/font/compile.js +3 -5
- package/lib/commonjs/src/core/font/quadratic.d.ts +1 -0
- package/lib/commonjs/src/core/font/quadratic.js +2 -0
- package/lib/commonjs/src/core/glyph/merge.js +3 -1
- package/lib/commonjs/src/core/glyph/parse.d.ts +1 -0
- package/lib/commonjs/src/core/pathkit/contours.d.ts +1 -0
- package/lib/commonjs/src/core/pathkit/contours.js +18 -0
- package/lib/commonjs/src/core/pathkit/evenodd.js +1 -15
- package/lib/commonjs/src/core/pathkit/winding.d.ts +4 -0
- package/lib/commonjs/src/core/pathkit/winding.js +59 -0
- package/lib/commonjs/src/core/pipeline/config.d.ts +1 -0
- package/lib/commonjs/src/core/pipeline/config.js +6 -0
- package/lib/commonjs/src/core/pipeline/iconPool.d.ts +13 -2
- package/lib/commonjs/src/core/pipeline/iconPool.js +89 -31
- package/lib/commonjs/src/core/pipeline/index.d.ts +2 -0
- package/lib/commonjs/src/core/pipeline/index.js +3 -1
- package/lib/commonjs/src/core/pipeline/prepare.d.ts +1 -0
- package/lib/commonjs/src/core/pipeline/prepare.js +18 -0
- package/lib/commonjs/src/core/pipeline/prepareIcon.d.ts +3 -0
- package/lib/commonjs/src/core/pipeline/prepareIcon.js +11 -8
- package/lib/commonjs/src/core/pipeline/prepareSvg.d.ts +6 -0
- package/lib/commonjs/src/core/pipeline/prepareSvg.js +11 -0
- package/lib/commonjs/src/core/pipeline/prepareSymbol.d.ts +26 -0
- package/lib/commonjs/src/core/pipeline/prepareSymbol.js +79 -0
- package/lib/commonjs/src/core/pipeline/prepareWorker.js +3 -3
- package/lib/commonjs/src/core/pipeline/preparedSvgCache.d.ts +6 -0
- package/lib/commonjs/src/core/pipeline/preparedSvgCache.js +44 -0
- package/lib/commonjs/src/core/pipeline/runFontPipeline.d.ts +5 -0
- package/lib/commonjs/src/core/pipeline/runFontPipeline.js +10 -8
- package/lib/commonjs/src/core/pipeline/runSymbolPipeline.d.ts +54 -0
- package/lib/commonjs/src/core/pipeline/runSymbolPipeline.js +161 -0
- package/lib/commonjs/src/core/symbols/contents.d.ts +2 -0
- package/lib/commonjs/src/core/symbols/contents.js +15 -0
- package/lib/commonjs/src/core/symbols/knockout.d.ts +3 -0
- package/lib/commonjs/src/core/symbols/knockout.js +51 -0
- package/lib/commonjs/src/core/symbols/layers.d.ts +36 -0
- package/lib/commonjs/src/core/symbols/layers.js +182 -0
- package/lib/commonjs/src/core/symbols/template.d.ts +22 -0
- package/lib/commonjs/src/core/symbols/template.js +140 -0
- package/lib/commonjs/src/core/symbols/vectorDrawable.d.ts +11 -0
- package/lib/commonjs/src/core/symbols/vectorDrawable.js +66 -0
- package/lib/commonjs/src/utils/fingerPrint.d.ts +11 -0
- package/lib/commonjs/src/utils/fingerPrint.js +28 -9
- package/lib/commonjs/src/utils/naming.d.ts +10 -0
- package/lib/commonjs/src/utils/naming.js +49 -0
- package/lib/module/createNanoIconsSet.native.js +29 -26
- package/lib/module/createNanoIconsSet.shared.js +3 -2
- package/lib/module/createNanoIconsSet.web.js +17 -5
- package/lib/module/devServerFont.js +30 -0
- package/lib/module/devServerFont.web.js +25 -0
- package/lib/module/loadDynamicFont.js +6 -3
- package/lib/module/specs/NanoIconViewNativeComponent.ts +9 -6
- package/lib/module/symbols/index.android.js +42 -0
- package/lib/module/symbols/index.ios.js +35 -0
- package/lib/module/symbols/index.js +35 -0
- package/lib/module/symbols/index.native.js +12 -0
- package/lib/module/symbols/types.js +1 -0
- package/lib/module/utils/fingerPrint.js +18 -3
- package/lib/module/utils/glyphRuntime.js +36 -2
- package/lib/module/utils/naming.js +46 -0
- package/lib/module/utils/validateLayerColor.js +24 -0
- package/lib/typescript/src/core/glyph/parse.d.ts +1 -0
- package/lib/typescript/src/core/pathkit/contours.d.ts +1 -0
- package/lib/typescript/src/core/pathkit/winding.d.ts +5 -0
- package/lib/typescript/src/core/symbols/contents.d.ts +3 -0
- package/lib/typescript/src/core/symbols/knockout.d.ts +4 -0
- package/lib/typescript/src/core/symbols/layers.d.ts +37 -0
- package/lib/typescript/src/core/symbols/template.d.ts +23 -0
- package/lib/typescript/src/core/symbols/vectorDrawable.d.ts +12 -0
- package/lib/typescript/src/devServerFont.d.ts +4 -0
- package/lib/typescript/src/devServerFont.web.d.ts +4 -0
- package/lib/typescript/src/loadDynamicFont.d.ts +1 -0
- package/lib/typescript/src/specs/NanoIconViewNativeComponent.d.ts +6 -5
- package/lib/typescript/src/symbols/index.android.d.ts +33 -0
- package/lib/typescript/src/symbols/index.d.ts +31 -0
- package/lib/typescript/src/symbols/index.ios.d.ts +31 -0
- package/lib/typescript/src/symbols/index.native.d.ts +8 -0
- package/lib/typescript/src/symbols/types.d.ts +24 -0
- package/lib/typescript/src/types.d.ts +2 -0
- package/lib/typescript/src/utils/fingerPrint.d.ts +11 -0
- package/lib/typescript/src/utils/glyphRuntime.d.ts +3 -1
- package/lib/typescript/src/utils/naming.d.ts +11 -0
- package/lib/typescript/src/utils/validateLayerColor.d.ts +3 -0
- package/metro.js +1 -0
- package/package.json +26 -2
- package/react-native-nano-icons.podspec +4 -1
- package/react-native.config.js +10 -0
- package/src/specs/NanoIconViewNativeComponent.ts +9 -6
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.layerHexColor = layerHexColor;
|
|
4
|
+
exports.layerClass = layerClass;
|
|
5
|
+
exports.buildSymbolTemplate = buildSymbolTemplate;
|
|
6
|
+
const parse_1 = require("../../utils/parse");
|
|
7
|
+
/**
|
|
8
|
+
* Custom SF Symbol template (v3.0) emitter. Geometry (validated against Xcode 26
|
|
9
|
+
* actool): 800×600 canvas, cap band Capline y=76 → Baseline y=146, source
|
|
10
|
+
* columns at x=265/465/665.
|
|
11
|
+
*
|
|
12
|
+
* A variable template must contain all three source groups (actool rejects
|
|
13
|
+
* single-variant templates) -> duplicating the same paths into each — identical
|
|
14
|
+
* topology satisfies the point-correspondence requirement.
|
|
15
|
+
*/
|
|
16
|
+
const CAPLINE_Y = 76;
|
|
17
|
+
const BASELINE_Y = 146;
|
|
18
|
+
const CAP_BAND = BASELINE_Y - CAPLINE_Y; // 70
|
|
19
|
+
const CAP_CENTER = (CAPLINE_Y + BASELINE_Y) / 2; // 111
|
|
20
|
+
// Content box is scaled to this height (= cap band) and centered, so symbols
|
|
21
|
+
// fill their optical box instead of rendering small inside a padded viewBox.
|
|
22
|
+
const GLYPH_HEIGHT = CAP_BAND;
|
|
23
|
+
const VARIANT_CENTERS = [
|
|
24
|
+
['Ultralight', 265],
|
|
25
|
+
['Regular', 465],
|
|
26
|
+
['Black', 665],
|
|
27
|
+
];
|
|
28
|
+
/** Columns are 200 apart — clamp glyph width so variants never overlap. */
|
|
29
|
+
const MAX_GLYPH_WIDTH = 160;
|
|
30
|
+
const H_REFERENCE_PATH = 'M85,145.755 L87.685,145.755 L113.369,79.287 L114.052002,79.287 ' +
|
|
31
|
+
'L114.052002,76 L112.148,76 L85,145.755 Z ' +
|
|
32
|
+
'M95.693,121.536 L130.996,121.536 L130.263,119.313 L96.474,119.313 L95.693,121.536 Z ' +
|
|
33
|
+
'M139.14999,145.755 L141.787,145.755 L114.638,76 L113.466,76 L113.466,79.287 L139.14999,145.755 Z';
|
|
34
|
+
function fmt(n) {
|
|
35
|
+
return Number(n.toFixed(3)).toString();
|
|
36
|
+
}
|
|
37
|
+
// Escape XML text so a filename with &/</> can't break the emitted template.
|
|
38
|
+
function escapeXmlText(s) {
|
|
39
|
+
return s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
40
|
+
}
|
|
41
|
+
function layerHexColor(fill) {
|
|
42
|
+
if (fill === null)
|
|
43
|
+
return '#000000';
|
|
44
|
+
const [r, g, b] = (0, parse_1.parseColor)(fill);
|
|
45
|
+
const h = (v) => Math.max(0, Math.min(255, Math.round(v)))
|
|
46
|
+
.toString(16)
|
|
47
|
+
.padStart(2, '0')
|
|
48
|
+
.toUpperCase();
|
|
49
|
+
return `#${h(r)}${h(g)}${h(b)}`;
|
|
50
|
+
}
|
|
51
|
+
function layerClass(layerIndex) {
|
|
52
|
+
return `monochrome-${layerIndex} multicolor-${layerIndex}:custom`;
|
|
53
|
+
}
|
|
54
|
+
function multicolorStyle(fill) {
|
|
55
|
+
const alpha = fill === null ? 1 : (0, parse_1.parseColor)(fill)[3];
|
|
56
|
+
const opacity = alpha < 1 ? `;opacity:${Number(alpha.toFixed(4))}` : '';
|
|
57
|
+
return `fill:${layerHexColor(fill)}${opacity}`;
|
|
58
|
+
}
|
|
59
|
+
function renderingModeStyles(layers) {
|
|
60
|
+
return layers
|
|
61
|
+
.map((layer, i) => ` .monochrome-${i} {fill:#000000}\n` +
|
|
62
|
+
` .multicolor-${i}:custom {${multicolorStyle(layer.fill)}}`)
|
|
63
|
+
.join('\n');
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Build the template SVG for one symbol. Layers are back→front; every layer
|
|
67
|
+
* gets `monochrome-N multicolor-N:custom` classes, with the layer fills
|
|
68
|
+
* declared in a `<style>` block.
|
|
69
|
+
*/
|
|
70
|
+
function buildSymbolTemplate(opts) {
|
|
71
|
+
const { layers, viewBox, contentBounds, descriptiveName, logger } = opts;
|
|
72
|
+
// Fit the content box, not the padded viewBox; fall back to viewBox.
|
|
73
|
+
const [bx, by, bw, bh] = contentBounds ?? viewBox;
|
|
74
|
+
const safeBw = bw === 0 ? 1 : bw;
|
|
75
|
+
const safeBh = bh === 0 ? 1 : bh;
|
|
76
|
+
// Fit to cap-band height, clamped so wide glyphs don't overlap the next column.
|
|
77
|
+
let scale = GLYPH_HEIGHT / safeBh;
|
|
78
|
+
if (safeBw * scale > MAX_GLYPH_WIDTH) {
|
|
79
|
+
scale = MAX_GLYPH_WIDTH / safeBw;
|
|
80
|
+
logger?.info(` ↔ Wide glyph clamped to ${MAX_GLYPH_WIDTH} template units (aspect ${fmt(safeBw / safeBh)}:1)`);
|
|
81
|
+
}
|
|
82
|
+
const scaledW = safeBw * scale;
|
|
83
|
+
const scaledH = safeBh * scale;
|
|
84
|
+
// Center on the cap-band midline.
|
|
85
|
+
const yOff = CAP_CENTER - scaledH / 2;
|
|
86
|
+
const pathsMarkup = (indent) => layers
|
|
87
|
+
.map((layer, i) => `${indent}<path class="${layerClass(i)}" d="${layer.d}"/>`)
|
|
88
|
+
.join('\n');
|
|
89
|
+
const groups = [];
|
|
90
|
+
const margins = [];
|
|
91
|
+
for (const [name, cx] of VARIANT_CENTERS) {
|
|
92
|
+
const tx = cx - scaledW / 2;
|
|
93
|
+
// Translate into the column + scale into the cap band (handles non-zero origin).
|
|
94
|
+
const e = tx - bx * scale;
|
|
95
|
+
const f = yOff - by * scale;
|
|
96
|
+
groups.push(` <g id="${name}-S" transform="matrix(${fmt(scale)},0,0,${fmt(scale)},${fmt(e)},${fmt(f)})">\n` +
|
|
97
|
+
pathsMarkup(' ') +
|
|
98
|
+
`\n </g>`);
|
|
99
|
+
margins.push(` <path id="left-margin-${name}-S" d="M${fmt(tx)},56 l0,110" />\n` +
|
|
100
|
+
` <path id="right-margin-${name}-S" d="M${fmt(tx + scaledW)},56 l0,110" />`);
|
|
101
|
+
}
|
|
102
|
+
const nameNote = descriptiveName
|
|
103
|
+
? `\n <text id="descriptive-name" fill="#505050" x="785.0" y="560.0" text-anchor="end">Generated from ${escapeXmlText(descriptiveName)}</text>`
|
|
104
|
+
: '';
|
|
105
|
+
return `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
106
|
+
<svg width="800" height="600" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
107
|
+
<style>
|
|
108
|
+
${renderingModeStyles(layers)}
|
|
109
|
+
</style>
|
|
110
|
+
<g id="Notes" font-family="'LucidaGrande', 'Lucida Grande', sans-serif" font-weight="500" font-size="13px">
|
|
111
|
+
<rect x="0" y="0" width="800" height="600" fill="white"/>
|
|
112
|
+
<g font-weight="500" font-size="13px">
|
|
113
|
+
<text x="18px" y="176px">Small</text>
|
|
114
|
+
<text x="18px" y="376px">Medium</text>
|
|
115
|
+
<text x="18px" y="576px">Large</text>
|
|
116
|
+
</g>
|
|
117
|
+
<g font-weight="300" font-size="9px">
|
|
118
|
+
<text x="250px" y="30px">Ultralight</text>
|
|
119
|
+
<text x="450px" y="30px">Regular</text>
|
|
120
|
+
<text x="650px" y="30px">Black</text>${nameNote}
|
|
121
|
+
<text id="template-version" fill="#505050" x="785.0" y="575.0" text-anchor="end">Template v.3.0</text>
|
|
122
|
+
<text fill="#505050" x="785.0" y="590.0" text-anchor="end">Generated by react-native-nano-icons</text>
|
|
123
|
+
</g>
|
|
124
|
+
</g>
|
|
125
|
+
<g id="Guides" stroke="rgb(39,170,225)" stroke-width="0.5px">
|
|
126
|
+
<path id="Capline-S" d="M18,${CAPLINE_Y} l800,0" />
|
|
127
|
+
<path id="H-reference" d="${H_REFERENCE_PATH}" stroke="none" />
|
|
128
|
+
<path id="Baseline-S" d="M18,${BASELINE_Y} l800,0" />
|
|
129
|
+
${margins.join('\n')}
|
|
130
|
+
<path id="Capline-M" d="M18,276 l800,0" />
|
|
131
|
+
<path id="Baseline-M" d="M18,346 l800,0" />
|
|
132
|
+
<path id="Capline-L" d="M18,476 l800,0" />
|
|
133
|
+
<path id="Baseline-L" d="M18,546 l800,0" />
|
|
134
|
+
</g>
|
|
135
|
+
<g id="Symbols">
|
|
136
|
+
${groups.join('\n')}
|
|
137
|
+
</g>
|
|
138
|
+
</svg>
|
|
139
|
+
`;
|
|
140
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SymbolTemplateLayer } from './template';
|
|
2
|
+
/**
|
|
3
|
+
* VectorDrawable XML from z-ordered layers. `contentBounds` (tight `[x,y,w,h]`,
|
|
4
|
+
* defaults to viewBox) sets the viewport so padding doesn't shrink the icon.
|
|
5
|
+
*/
|
|
6
|
+
export declare function buildVectorDrawableXml(opts: {
|
|
7
|
+
layers: SymbolTemplateLayer[];
|
|
8
|
+
viewBox: [number, number, number, number];
|
|
9
|
+
/** Tight content box `[x, y, w, h]`; used instead of the viewBox when given. */
|
|
10
|
+
contentBounds?: [number, number, number, number];
|
|
11
|
+
}): string;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildVectorDrawableXml = buildVectorDrawableXml;
|
|
4
|
+
const parse_1 = require("../../utils/parse");
|
|
5
|
+
/**
|
|
6
|
+
* Android VectorDrawable emitter — the tab-bar counterpart to the iOS
|
|
7
|
+
* `.symbolset`. `android:pathData` takes SVG path syntax verbatim (nonzero
|
|
8
|
+
* winding by default), so prepared layers drop straight in. Each layer keeps
|
|
9
|
+
* its fill; the bar paints every path in its tint when the icon is tinted.
|
|
10
|
+
*
|
|
11
|
+
* VectorDrawable's viewport always starts at (0,0), so a non-zero content origin
|
|
12
|
+
* is absorbed by a translating `<group>`.
|
|
13
|
+
*/
|
|
14
|
+
// Intrinsic size (dp): height fixed to tab-icon size, width follows aspect
|
|
15
|
+
// ratio (capped).
|
|
16
|
+
const ICON_HEIGHT = 24;
|
|
17
|
+
const MAX_WIDTH = ICON_HEIGHT * 3;
|
|
18
|
+
function num(n) {
|
|
19
|
+
return Number(n.toFixed(3)).toString();
|
|
20
|
+
}
|
|
21
|
+
/** [r,g,b] (0–255) → `#rrggbb`. */
|
|
22
|
+
function hexColor(r, g, b) {
|
|
23
|
+
const h = (v) => Math.max(0, Math.min(255, Math.round(v)))
|
|
24
|
+
.toString(16)
|
|
25
|
+
.padStart(2, '0');
|
|
26
|
+
return `#${h(r)}${h(g)}${h(b)}`;
|
|
27
|
+
}
|
|
28
|
+
/** Fill attrs from a source fill (null = default black). */
|
|
29
|
+
function fillAttrs(fill) {
|
|
30
|
+
if (fill === null)
|
|
31
|
+
return 'android:fillColor="#000000"';
|
|
32
|
+
const [r, g, b, a] = (0, parse_1.parseColor)(fill);
|
|
33
|
+
const color = `android:fillColor="${hexColor(r, g, b)}"`;
|
|
34
|
+
return a < 1 ? `${color} android:fillAlpha="${Number(a.toFixed(4))}"` : color;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* VectorDrawable XML from z-ordered layers. `contentBounds` (tight `[x,y,w,h]`,
|
|
38
|
+
* defaults to viewBox) sets the viewport so padding doesn't shrink the icon.
|
|
39
|
+
*/
|
|
40
|
+
function buildVectorDrawableXml(opts) {
|
|
41
|
+
const { layers, viewBox, contentBounds } = opts;
|
|
42
|
+
const [bx, by, bw0, bh0] = contentBounds ?? viewBox;
|
|
43
|
+
const bw = bw0 === 0 ? 1 : bw0;
|
|
44
|
+
const bh = bh0 === 0 ? 1 : bh0;
|
|
45
|
+
// Size by height; width follows aspect ratio, capped at MAX_WIDTH.
|
|
46
|
+
let ch = ICON_HEIGHT;
|
|
47
|
+
let cw = ICON_HEIGHT * (bw / bh);
|
|
48
|
+
if (cw > MAX_WIDTH) {
|
|
49
|
+
cw = MAX_WIDTH;
|
|
50
|
+
ch = MAX_WIDTH * (bh / bw);
|
|
51
|
+
}
|
|
52
|
+
const paths = layers
|
|
53
|
+
.map((layer) => ` <path ${fillAttrs(layer.fill)} android:pathData="${layer.d}"/>`)
|
|
54
|
+
.join('\n');
|
|
55
|
+
// Translate group absorbs the viewport origin (VectorDrawable has none).
|
|
56
|
+
return `<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
|
57
|
+
android:width="${num(cw)}dp"
|
|
58
|
+
android:height="${num(ch)}dp"
|
|
59
|
+
android:viewportWidth="${num(bw)}"
|
|
60
|
+
android:viewportHeight="${num(bh)}">
|
|
61
|
+
<group android:translateX="${num(-bx)}" android:translateY="${num(-by)}">
|
|
62
|
+
${paths}
|
|
63
|
+
</group>
|
|
64
|
+
</vector>
|
|
65
|
+
`;
|
|
66
|
+
}
|
|
@@ -5,4 +5,15 @@ export type FingerprintInputs = {
|
|
|
5
5
|
version: string;
|
|
6
6
|
toolchain: readonly string[];
|
|
7
7
|
};
|
|
8
|
+
export type SymbolFingerprintInputs = {
|
|
9
|
+
prefix: string;
|
|
10
|
+
version: string;
|
|
11
|
+
toolchain: readonly string[];
|
|
12
|
+
};
|
|
13
|
+
export type SvgDirFingerprint = {
|
|
14
|
+
hash: string;
|
|
15
|
+
svgHashByFile: Map<string, string>;
|
|
16
|
+
};
|
|
8
17
|
export declare function getFingerprintSync(dir: string, inputs: FingerprintInputs): string;
|
|
18
|
+
export declare function fingerprintSvgDirSync(dir: string, inputs: FingerprintInputs): SvgDirFingerprint;
|
|
19
|
+
export declare function fingerprintSymbolDirSync(dir: string, inputs: SymbolFingerprintInputs): SvgDirFingerprint;
|
|
@@ -1,27 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getFingerprintSync = getFingerprintSync;
|
|
4
|
+
exports.fingerprintSvgDirSync = fingerprintSvgDirSync;
|
|
5
|
+
exports.fingerprintSymbolDirSync = fingerprintSymbolDirSync;
|
|
4
6
|
const crypto = require('crypto');
|
|
5
7
|
const fs = require('fs');
|
|
6
8
|
const path = require('path');
|
|
7
9
|
function getFingerprintSync(dir, inputs) {
|
|
10
|
+
return fingerprintSvgDirSync(dir, inputs).hash;
|
|
11
|
+
}
|
|
12
|
+
function fingerprintSvgDirSync(dir, inputs) {
|
|
13
|
+
return hashSvgDir(dir, [
|
|
14
|
+
inputs.upm,
|
|
15
|
+
inputs.safeZone,
|
|
16
|
+
inputs.startUnicode,
|
|
17
|
+
inputs.version,
|
|
18
|
+
inputs.toolchain,
|
|
19
|
+
]);
|
|
20
|
+
}
|
|
21
|
+
function fingerprintSymbolDirSync(dir, inputs) {
|
|
22
|
+
return hashSvgDir(dir, [
|
|
23
|
+
'symbol',
|
|
24
|
+
inputs.prefix,
|
|
25
|
+
inputs.version,
|
|
26
|
+
inputs.toolchain,
|
|
27
|
+
]);
|
|
28
|
+
}
|
|
29
|
+
function hashSvgDir(dir, settings) {
|
|
8
30
|
const files = fs
|
|
9
31
|
.readdirSync(dir)
|
|
10
32
|
.filter((f) => f.endsWith('.svg'))
|
|
11
33
|
.sort();
|
|
12
34
|
const hash = crypto.createHash('sha256');
|
|
35
|
+
const svgHashByFile = new Map();
|
|
13
36
|
for (const file of files) {
|
|
14
37
|
const filePath = path.join(dir, file);
|
|
38
|
+
const content = fs.readFileSync(filePath);
|
|
15
39
|
// Hash both path and content
|
|
16
40
|
hash.update(file);
|
|
17
|
-
hash.update(
|
|
41
|
+
hash.update(content);
|
|
42
|
+
svgHashByFile.set(file, crypto.createHash('sha256').update(content).digest('hex'));
|
|
18
43
|
}
|
|
19
|
-
hash.update(JSON.stringify(
|
|
20
|
-
|
|
21
|
-
inputs.safeZone,
|
|
22
|
-
inputs.startUnicode,
|
|
23
|
-
inputs.version,
|
|
24
|
-
inputs.toolchain,
|
|
25
|
-
]));
|
|
26
|
-
return hash.digest('hex');
|
|
44
|
+
hash.update(JSON.stringify(settings));
|
|
45
|
+
return { hash: hash.digest('hex'), svgHashByFile };
|
|
27
46
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resource names must match `[a-z][a-z0-9_]*` — no dots/uppercase.
|
|
3
|
+
* `nano.home` → `nano_home`, `nano.person-walking` → `nano_person_walking`.
|
|
4
|
+
*/
|
|
5
|
+
export declare function toDrawableResourceName(assetName: string): string;
|
|
6
|
+
export declare function toOriginalDrawableResourceName(resourceName: string): string;
|
|
7
|
+
/** "my-tab icons" → "MyTabIcons" — PascalCase base for manifest identifiers. */
|
|
8
|
+
export declare function manifestBaseName(setName: string): string;
|
|
9
|
+
/** Manifest export name, e.g. `MyTabIconsSymbols` / `MyTabIconsDrawables`. */
|
|
10
|
+
export declare function manifestExportName(setName: string, suffix?: string): string;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Shared regexes + helpers for sanitizing asset/symbol names into valid
|
|
3
|
+
// Android resource ids and TypeScript manifest identifiers.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.toDrawableResourceName = toDrawableResourceName;
|
|
6
|
+
exports.toOriginalDrawableResourceName = toOriginalDrawableResourceName;
|
|
7
|
+
exports.manifestBaseName = manifestBaseName;
|
|
8
|
+
exports.manifestExportName = manifestExportName;
|
|
9
|
+
/** Chars illegal in an Android drawable resource name → `_`. */
|
|
10
|
+
const NON_RESOURCE_CHARS = /[^a-z0-9_]+/g;
|
|
11
|
+
/** Leading/trailing underscores to trim. */
|
|
12
|
+
const EDGE_UNDERSCORES = /^_+|_+$/g;
|
|
13
|
+
/** Resource names must start with a lowercase letter. */
|
|
14
|
+
const STARTS_WITH_LOWER = /^[a-z]/;
|
|
15
|
+
/** Word separators in a set name (split → PascalCase parts). */
|
|
16
|
+
const NAME_SEPARATORS = /[^a-zA-Z0-9]+/;
|
|
17
|
+
/** Manifest identifiers must start with a letter. */
|
|
18
|
+
const STARTS_WITH_LETTER = /^[a-zA-Z]/;
|
|
19
|
+
/** Prefix used when a sanitized name would be empty or start with a non-letter. */
|
|
20
|
+
const RESOURCE_FALLBACK_PREFIX = 'nano_';
|
|
21
|
+
/**
|
|
22
|
+
* Resource names must match `[a-z][a-z0-9_]*` — no dots/uppercase.
|
|
23
|
+
* `nano.home` → `nano_home`, `nano.person-walking` → `nano_person_walking`.
|
|
24
|
+
*/
|
|
25
|
+
function toDrawableResourceName(assetName) {
|
|
26
|
+
let name = assetName.toLowerCase().replace(NON_RESOURCE_CHARS, '_');
|
|
27
|
+
name = name.replace(EDGE_UNDERSCORES, '');
|
|
28
|
+
if (name === '' || !STARTS_WITH_LOWER.test(name)) {
|
|
29
|
+
name = `${RESOURCE_FALLBACK_PREFIX}${name}`;
|
|
30
|
+
}
|
|
31
|
+
return name;
|
|
32
|
+
}
|
|
33
|
+
const ORIGINAL_DRAWABLE_SUFFIX = '_original';
|
|
34
|
+
function toOriginalDrawableResourceName(resourceName) {
|
|
35
|
+
return `${resourceName}${ORIGINAL_DRAWABLE_SUFFIX}`;
|
|
36
|
+
}
|
|
37
|
+
/** "my-tab icons" → "MyTabIcons" — PascalCase base for manifest identifiers. */
|
|
38
|
+
function manifestBaseName(setName) {
|
|
39
|
+
const pascal = setName
|
|
40
|
+
.split(NAME_SEPARATORS)
|
|
41
|
+
.filter(Boolean)
|
|
42
|
+
.map((part) => part[0].toUpperCase() + part.slice(1))
|
|
43
|
+
.join('');
|
|
44
|
+
return STARTS_WITH_LETTER.test(pascal) ? pascal : `Set${pascal}`;
|
|
45
|
+
}
|
|
46
|
+
/** Manifest export name, e.g. `MyTabIconsSymbols` / `MyTabIconsDrawables`. */
|
|
47
|
+
function manifestExportName(setName, suffix = 'Symbols') {
|
|
48
|
+
return `${manifestBaseName(setName)}${suffix}`;
|
|
49
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import { memo, useMemo } from 'react';
|
|
4
|
-
import { PixelRatio, UIManager, View
|
|
4
|
+
import { PixelRatio, UIManager, View } from 'react-native';
|
|
5
5
|
import { shallowEqualColor } from "./utils/shallowEqualColor.js";
|
|
6
|
-
import {
|
|
6
|
+
import { validateLayerColor } from "./utils/validateLayerColor.js";
|
|
7
|
+
import { DEFAULT_ICON_SIZE, resolveGlyphEntry, createLayerColorResolver, tintableLayers } from "./utils/glyphRuntime.js";
|
|
7
8
|
import NanoIconViewNative from './specs/NanoIconViewNativeComponent';
|
|
8
9
|
import { createJSIconSet, warnIfLinkingMismatch } from "./createNanoIconsSet.shared.js";
|
|
9
10
|
import { loadDynamicFont, useDynamicFontPending } from "./loadDynamicFont.js";
|
|
@@ -11,17 +12,16 @@ import { checkFontIntegrity, isFontMismatch, reportDynamicFontLoadFailure, repor
|
|
|
11
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
13
|
export { shallowEqualColor };
|
|
13
14
|
const HAS_NATIVE_IMPL = UIManager.hasViewManagerConfig('NanoIconView');
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
function cachedProcessColor(color) {
|
|
19
|
-
let result = processedColorCache.get(color);
|
|
20
|
-
if (result === undefined) {
|
|
21
|
-
result = processColor(color) ?? 0xff000000;
|
|
22
|
-
processedColorCache.set(color, result);
|
|
15
|
+
async function loadFontFromDevServer(family) {
|
|
16
|
+
if (__DEV__) {
|
|
17
|
+
const dev = require('./devServerFont');
|
|
18
|
+
return dev.loadFontFromDevServer(family);
|
|
23
19
|
}
|
|
24
|
-
return
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
async function ensureStaticFont(family) {
|
|
23
|
+
await loadFontFromDevServer(family);
|
|
24
|
+
await checkFontIntegrity(family, 'static');
|
|
25
25
|
}
|
|
26
26
|
export function createIconSet(glyphMap, font) {
|
|
27
27
|
if (!HAS_NATIVE_IMPL) {
|
|
@@ -35,7 +35,8 @@ export function createIconSet(glyphMap, font) {
|
|
|
35
35
|
const managed = glyphMap.m.l === 'd' && font != null;
|
|
36
36
|
const linking = glyphMap.m.l === 'd' ? 'dynamic' : 'static';
|
|
37
37
|
if (managed) {
|
|
38
|
-
void loadDynamicFont(fontFamilyBasename, font).then(() => checkFontIntegrity(fontFamilyBasename, linking), err => {
|
|
38
|
+
void loadDynamicFont(fontFamilyBasename, font).then(() => checkFontIntegrity(fontFamilyBasename, linking), async err => {
|
|
39
|
+
if (await loadFontFromDevServer(fontFamilyBasename)) return;
|
|
39
40
|
if (isFontMismatch(err)) {
|
|
40
41
|
reportFontMismatch(fontFamilyBasename, linking);
|
|
41
42
|
} else {
|
|
@@ -43,11 +44,12 @@ export function createIconSet(glyphMap, font) {
|
|
|
43
44
|
}
|
|
44
45
|
});
|
|
45
46
|
} else if (linking === 'static') {
|
|
46
|
-
void
|
|
47
|
+
void ensureStaticFont(fontFamilyBasename);
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
// Pre-compute per-icon static data (codepoints, default colors) once at set creation
|
|
50
|
-
// Avoids layers.map()
|
|
51
|
+
// Avoids layers.map() per icon mount, and keeps the array identity stable so
|
|
52
|
+
// React Native's prop diff skips re-running processColorArray on re-render.
|
|
51
53
|
const codepointsCache = new Map();
|
|
52
54
|
const defaultColorsCache = new Map();
|
|
53
55
|
function getCodepoints(name, layers) {
|
|
@@ -61,7 +63,7 @@ export function createIconSet(glyphMap, font) {
|
|
|
61
63
|
function getDefaultColors(name, layers) {
|
|
62
64
|
let colors = defaultColorsCache.get(name);
|
|
63
65
|
if (!colors) {
|
|
64
|
-
colors = layers.map(([, srcColor]) =>
|
|
66
|
+
colors = layers.map(([, srcColor], i) => validateLayerColor(srcColor, name, i));
|
|
65
67
|
defaultColorsCache.set(name, colors);
|
|
66
68
|
}
|
|
67
69
|
return colors;
|
|
@@ -70,6 +72,7 @@ export function createIconSet(glyphMap, font) {
|
|
|
70
72
|
name,
|
|
71
73
|
size = DEFAULT_ICON_SIZE,
|
|
72
74
|
color,
|
|
75
|
+
tintMode,
|
|
73
76
|
style,
|
|
74
77
|
allowFontScaling = true,
|
|
75
78
|
accessible,
|
|
@@ -87,14 +90,14 @@ export function createIconSet(glyphMap, font) {
|
|
|
87
90
|
const pending = useDynamicFontPending(managed, fontFamilyBasename);
|
|
88
91
|
const nameStr = name;
|
|
89
92
|
const codepoints = getCodepoints(nameStr, layers);
|
|
90
|
-
const
|
|
93
|
+
const layerColors = useMemo(() => {
|
|
91
94
|
// Fast path: no custom color — use pre-computed defaults
|
|
92
95
|
if (color === undefined || color === null) {
|
|
93
96
|
return getDefaultColors(nameStr, layers);
|
|
94
97
|
}
|
|
95
|
-
const resolveColor = createLayerColorResolver(color);
|
|
96
|
-
return layers.map(([, srcColor], i) =>
|
|
97
|
-
}, [nameStr, color]);
|
|
98
|
+
const resolveColor = createLayerColorResolver(color, tintMode, layers);
|
|
99
|
+
return layers.map(([, srcColor], i) => validateLayerColor(resolveColor(i, srcColor), nameStr, i));
|
|
100
|
+
}, [nameStr, color, tintMode]);
|
|
98
101
|
const nativeStyle = useMemo(() => [{
|
|
99
102
|
width,
|
|
100
103
|
height: scaledSize
|
|
@@ -118,13 +121,13 @@ export function createIconSet(glyphMap, font) {
|
|
|
118
121
|
ref: ref,
|
|
119
122
|
fontFamily: fontFamilyBasename,
|
|
120
123
|
codepoints: codepoints,
|
|
121
|
-
colors:
|
|
122
|
-
|
|
124
|
+
colors: layerColors,
|
|
125
|
+
tintLayers: tintableLayers(layers, tintMode),
|
|
126
|
+
size: size,
|
|
127
|
+
allowFontScaling: allowFontScaling,
|
|
123
128
|
advanceWidth: adv,
|
|
124
129
|
unitsPerEm: unitsPerEm,
|
|
125
|
-
|
|
126
|
-
iconHeight: scaledSize,
|
|
127
|
-
style: nativeStyle,
|
|
130
|
+
style: style,
|
|
128
131
|
accessible: accessible,
|
|
129
132
|
accessibilityRole: accessibilityRole,
|
|
130
133
|
accessibilityLabel: accessibilityLabel ?? name,
|
|
@@ -132,7 +135,7 @@ export function createIconSet(glyphMap, font) {
|
|
|
132
135
|
importantForAccessibility: importantForAccessibility,
|
|
133
136
|
testID: testID
|
|
134
137
|
});
|
|
135
|
-
}, (prev, next) => prev.name === next.name && prev.size === next.size && prev.allowFontScaling === next.allowFontScaling && prev.style === next.style && shallowEqualColor(prev.color, next.color));
|
|
138
|
+
}, (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));
|
|
136
139
|
Icon.displayName = `NanoIcon(${fontFamilyBasename})`;
|
|
137
140
|
const IconComp = Icon;
|
|
138
141
|
IconComp.loadFont = override => glyphMap.m.l === 'd' ? loadDynamicFont(fontFamilyBasename, override ?? font, {
|
|
@@ -69,6 +69,7 @@ export function createJSIconSet(glyphMap, font) {
|
|
|
69
69
|
name,
|
|
70
70
|
size = DEFAULT_ICON_SIZE,
|
|
71
71
|
color,
|
|
72
|
+
tintMode,
|
|
72
73
|
style,
|
|
73
74
|
allowFontScaling = true,
|
|
74
75
|
accessible,
|
|
@@ -84,7 +85,7 @@ export function createJSIconSet(glyphMap, font) {
|
|
|
84
85
|
const scaledSize = size * fontScale;
|
|
85
86
|
const width = adv / unitsPerEm * scaledSize;
|
|
86
87
|
const pending = useDynamicFontPending(managed, fontBasename);
|
|
87
|
-
const resolveColor = createLayerColorResolver(color);
|
|
88
|
+
const resolveColor = createLayerColorResolver(color, tintMode, layers);
|
|
88
89
|
const containerStyle = useMemo(() => [{
|
|
89
90
|
height: scaledSize,
|
|
90
91
|
width,
|
|
@@ -115,7 +116,7 @@ export function createJSIconSet(glyphMap, font) {
|
|
|
115
116
|
}, i);
|
|
116
117
|
})
|
|
117
118
|
});
|
|
118
|
-
}, (prev, next) => prev.name === next.name && prev.size === next.size && prev.allowFontScaling === next.allowFontScaling && prev.style === next.style && shallowEqualColor(prev.color, next.color));
|
|
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));
|
|
119
120
|
Icon.displayName = `NanoIcon(${fontBasename})`;
|
|
120
121
|
const IconComp = Icon;
|
|
121
122
|
IconComp.loadFont = override => glyphMap.m.l === 'd' ? loadDynamicFont(fontBasename, override ?? font, {
|
|
@@ -4,18 +4,29 @@ import { memo, useMemo } from 'react';
|
|
|
4
4
|
import { shallowEqualColor } from "./utils/shallowEqualColor.js";
|
|
5
5
|
import { DEFAULT_ICON_SIZE, resolveGlyphEntry, createCharCache, createLayerColorResolver } from "./utils/glyphRuntime.js";
|
|
6
6
|
import { configuredFontFamily } from "./utils/fontIdentity.js";
|
|
7
|
+
import { useDynamicFontStatus } from "./loadDynamicFont.js";
|
|
7
8
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
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
17
|
|
|
10
18
|
// Web renderer: uses inline <span> elements so icons flow out of the box (display: inline-block keeps width/height)
|
|
11
19
|
export function createIconSet(glyphMap) {
|
|
12
|
-
const
|
|
20
|
+
const family = glyphMap.m.f;
|
|
21
|
+
const fontBasename = configuredFontFamily(family);
|
|
13
22
|
const unitsPerEm = glyphMap.m.u;
|
|
14
23
|
const getChar = createCharCache();
|
|
24
|
+
void loadFontFromDevServer(family);
|
|
15
25
|
const Icon = /*#__PURE__*/memo(({
|
|
16
26
|
name,
|
|
17
27
|
size = DEFAULT_ICON_SIZE,
|
|
18
28
|
color,
|
|
29
|
+
tintMode,
|
|
19
30
|
style,
|
|
20
31
|
accessible,
|
|
21
32
|
accessibilityLabel,
|
|
@@ -27,7 +38,8 @@ export function createIconSet(glyphMap) {
|
|
|
27
38
|
}) => {
|
|
28
39
|
const [adv, layers] = resolveGlyphEntry(glyphMap, name);
|
|
29
40
|
const width = adv / unitsPerEm * size;
|
|
30
|
-
const
|
|
41
|
+
const fontFamily = useDynamicFontStatus(family) === 'ready' ? family : fontBasename;
|
|
42
|
+
const resolveColor = createLayerColorResolver(color, tintMode, layers);
|
|
31
43
|
const containerStyle = useMemo(() => ({
|
|
32
44
|
display: 'inline-block',
|
|
33
45
|
position: 'relative',
|
|
@@ -41,13 +53,13 @@ export function createIconSet(glyphMap) {
|
|
|
41
53
|
position: 'absolute',
|
|
42
54
|
left: 0,
|
|
43
55
|
bottom: 0,
|
|
44
|
-
fontFamily
|
|
56
|
+
fontFamily,
|
|
45
57
|
fontWeight: 'normal',
|
|
46
58
|
fontStyle: 'normal',
|
|
47
59
|
fontSize: size,
|
|
48
60
|
lineHeight: 1,
|
|
49
61
|
whiteSpace: 'pre'
|
|
50
|
-
}), [size]);
|
|
62
|
+
}), [size, fontFamily]);
|
|
51
63
|
const isHidden = accessible === false || accessibilityElementsHidden;
|
|
52
64
|
const role = accessibilityRole === 'image' ? 'img' : accessibilityRole;
|
|
53
65
|
return /*#__PURE__*/_jsx("span", {
|
|
@@ -70,7 +82,7 @@ export function createIconSet(glyphMap) {
|
|
|
70
82
|
}, i);
|
|
71
83
|
})
|
|
72
84
|
});
|
|
73
|
-
}, (prev, next) => prev.name === next.name && prev.size === next.size && prev.style === next.style && prev.className === next.className && shallowEqualColor(prev.color, next.color));
|
|
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));
|
|
74
86
|
Icon.displayName = `NanoIcon(${fontBasename})`;
|
|
75
87
|
|
|
76
88
|
// No-op on web: the host app links the font under the configured family name, nothing to load at runtime.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
4
|
+
import { isFontRegistered } from "./fontIntegrity.js";
|
|
5
|
+
import { loadDynamicFont } from "./loadDynamicFont.js";
|
|
6
|
+
import NanoIconsFontLoader from './nativeFontLoader';
|
|
7
|
+
export const DEV_SERVER_FONT_ROUTE = '/__nanoicons/';
|
|
8
|
+
export function devServerFontUri(family) {
|
|
9
|
+
const scriptURL = TurboModuleRegistry.get('SourceCode')?.getConstants().scriptURL;
|
|
10
|
+
const origin = scriptURL?.match(/^https?:\/\/[^/]+/)?.[0];
|
|
11
|
+
return origin ? `${origin}${DEV_SERVER_FONT_ROUTE}${encodeURIComponent(family)}.ttf` : undefined;
|
|
12
|
+
}
|
|
13
|
+
export async function loadFontFromDevServer(family) {
|
|
14
|
+
if (!NanoIconsFontLoader) return false;
|
|
15
|
+
if (await isFontRegistered(family)) return true;
|
|
16
|
+
const uri = devServerFontUri(family);
|
|
17
|
+
if (!uri) return false;
|
|
18
|
+
try {
|
|
19
|
+
const head = await fetch(uri, {
|
|
20
|
+
method: 'HEAD'
|
|
21
|
+
});
|
|
22
|
+
if (!head.ok) return false;
|
|
23
|
+
await loadDynamicFont(family, {
|
|
24
|
+
uri
|
|
25
|
+
});
|
|
26
|
+
return true;
|
|
27
|
+
} catch {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { getFontStatus, loadDynamicFont } from "./loadDynamicFont.js";
|
|
4
|
+
export const DEV_SERVER_FONT_ROUTE = '/__nanoicons/';
|
|
5
|
+
export function devServerFontUri(family) {
|
|
6
|
+
const origin = globalThis.location?.origin;
|
|
7
|
+
return origin ? `${origin}${DEV_SERVER_FONT_ROUTE}${encodeURIComponent(family)}.ttf` : undefined;
|
|
8
|
+
}
|
|
9
|
+
export async function loadFontFromDevServer(family) {
|
|
10
|
+
if (getFontStatus(family) === 'ready') return true;
|
|
11
|
+
const uri = devServerFontUri(family);
|
|
12
|
+
if (!uri) return false;
|
|
13
|
+
try {
|
|
14
|
+
const head = await fetch(uri, {
|
|
15
|
+
method: 'HEAD'
|
|
16
|
+
});
|
|
17
|
+
if (!head.ok) return false;
|
|
18
|
+
await loadDynamicFont(family, {
|
|
19
|
+
uri
|
|
20
|
+
});
|
|
21
|
+
return true;
|
|
22
|
+
} catch {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -110,11 +110,14 @@ export function loadDynamicFont(family, font, opts) {
|
|
|
110
110
|
* errored, or not managed by us).
|
|
111
111
|
*/
|
|
112
112
|
export function useDynamicFontPending(managed, family) {
|
|
113
|
-
const status =
|
|
113
|
+
const status = useDynamicFontStatus(family);
|
|
114
|
+
return managed && status === 'loading';
|
|
115
|
+
}
|
|
116
|
+
export function useDynamicFontStatus(family) {
|
|
117
|
+
return useSyncExternalStore(cb => {
|
|
114
118
|
listeners.add(cb);
|
|
115
119
|
return () => listeners.delete(cb);
|
|
116
|
-
}, () =>
|
|
117
|
-
return managed && status === 'loading';
|
|
120
|
+
}, () => statusByFamily.get(family), () => undefined);
|
|
118
121
|
}
|
|
119
122
|
|
|
120
123
|
/** Test-only: reset module state between tests. */
|